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
@@ -1091,7 +1091,7 @@ export class EdgelessClipboardController extends PageClipboard {
const newSelected = [
...canvasElementIds,
...blockIds.filter(id => {
return isTopLevelBlock(this.doc.getBlockById(id));
return isTopLevelBlock(this.doc.getModelById(id));
}),
];
@@ -380,7 +380,7 @@ export class EdgelessAutoComplete extends WithDisposable(LitElement) {
this.edgeless
);
} else {
const model = doc.getBlockById(id);
const model = doc.getModelById(id);
if (!model) {
return;
}
@@ -182,7 +182,7 @@ export class NoteSlicer extends WidgetComponent<
doc.root?.id
);
doc.moveBlocks(resetBlocks, doc.getBlockById(newNoteId) as NoteBlockModel);
doc.moveBlocks(resetBlocks, doc.getModelById(newNoteId) as NoteBlockModel);
this._activeSlicerIndex = 0;
this._selection.set({
@@ -188,7 +188,7 @@ export class TemplateJob {
if (isMergeBlock) {
this._mergeProps(
json,
this.model.doc.getBlockById(
this.model.doc.getModelById(
this._getMergeBlockId(json)
) as BlockModel
);
@@ -191,7 +191,7 @@ export class PageRootBlockComponent extends BlockComponent<
const { doc } = this;
const noteId = doc.addBlock('affine:note', {}, doc.root?.id);
return doc.getBlockById(noteId) as NoteBlockModel;
return doc.getModelById(noteId) as NoteBlockModel;
}
private _getDefaultNoteBlock() {
@@ -262,7 +262,7 @@ export class PageRootBlockComponent extends BlockComponent<
);
if (!sel) return;
let model: BlockModel | null = null;
let current = this.doc.getBlockById(sel.blockId);
let current = this.doc.getModelById(sel.blockId);
while (current && !model) {
if (current.flavour === 'affine:note') {
model = current;
@@ -280,7 +280,7 @@ export class PageRootBlockComponent extends BlockComponent<
}
return;
}
const notes = this.doc.getBlockByFlavour('affine:note');
const notes = this.doc.getModelsByFlavour('affine:note');
const index = notes.indexOf(prevNote);
if (index !== 0) return;