feat(editor): improve api for store, and add docs (#10941)

This commit is contained in:
Saul-Mirone
2025-03-17 16:30:59 +00:00
parent b0aa2c90fd
commit 3de7d85eea
47 changed files with 1212 additions and 210 deletions

View File

@@ -162,7 +162,7 @@ function addAIChatBlock(
const { doc } = host;
const surfaceBlock = doc
.getStore()
.getAllModels()
.find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) {
return;
@@ -520,7 +520,7 @@ const CREATE_AS_LINKED_DOC = {
const { doc } = host;
const surfaceBlock = doc
.getStore()
.getAllModels()
.find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) {
return false;

View File

@@ -236,7 +236,7 @@ function getEdgelessContentBound(host: EditorHost) {
const elements = (
host.doc
.getStore()
.getAllModels()
.filter(
model =>
model instanceof GfxBlockElementModel &&

View File

@@ -106,7 +106,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
const doc = collection.createDoc({ id: 'doc:home' }).load();
const rootId = doc.addBlock('affine:page', {});
const surfaceId = doc.addBlock('affine:surface', {}, rootId);
const surface = doc.getBlockById(surfaceId) as SurfaceBlockModel;
const surface = doc.getModelById(surfaceId) as SurfaceBlockModel;
doc.resetHistory();
return {

View File

@@ -163,7 +163,7 @@ export class AIChatBlockPeekView extends LitElement {
const { doc } = this.host;
// create a new AI chat block
const surfaceBlock = doc
.getStore()
.getAllModels()
.find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) {
return;

View File

@@ -44,7 +44,7 @@ function processSnapshot(
text: TextSelection,
host: EditorHost
) {
const model = host.doc.getBlockById(snapshot.id);
const model = host.doc.getModelById(snapshot.id);
if (!model) {
return;
}

View File

@@ -21,7 +21,7 @@ export function useReferenceLinkHelper(docCollection: Workspace) {
},
},
] as DeltaInsert<AffineTextAttributes>[]);
const [frame] = page.getBlockByFlavour('affine:note');
const [frame] = page.getModelsByFlavour('affine:note');
frame && page.addBlock('affine:paragraph', { text }, frame.id);
},

View File

@@ -44,12 +44,12 @@ describe('useBlockSuitePagePreview', () => {
{
text: new Text('Hello, world!'),
},
page.getBlockByFlavour('affine:note')[0].id
page.getModelsByFlavour('affine:note')[0].id
);
const hook = renderHook(() => useAtomValue(useBlockSuitePagePreview(page)));
expect(hook.result.current).toBe('Hello, world!');
page.transact(() => {
page.getBlockById(id)!.text!.insert('Test', 0);
page.getModelById(id)!.text!.insert('Test', 0);
});
await new Promise(resolve => setTimeout(resolve, 100));
hook.rerender();
@@ -61,7 +61,7 @@ describe('useBlockSuitePagePreview', () => {
{
text: new Text('First block!'),
},
page.getBlockByFlavour('affine:note')[0].id,
page.getModelsByFlavour('affine:note')[0].id,
0
);
await new Promise(resolve => setTimeout(resolve, 100));