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

@@ -492,7 +492,7 @@ export class LayerManager extends GfxExtension {
private _reset() {
const elements = (
this._doc
.getStore()
.getAllModels()
.filter(
model =>
model instanceof GfxBlockElementModel &&
@@ -798,7 +798,7 @@ export class LayerManager extends GfxExtension {
this._disposable.add(
store.slots.blockUpdated.subscribe(payload => {
if (payload.type === 'add') {
const block = store.getBlockById(payload.id)!;
const block = store.getModelById(payload.id)!;
if (
block instanceof GfxBlockElementModel &&
@@ -810,7 +810,7 @@ export class LayerManager extends GfxExtension {
}
}
if (payload.type === 'update') {
const block = store.getBlockById(payload.id)!;
const block = store.getModelById(payload.id)!;
if (
(payload.props.key === 'index' ||
@@ -825,7 +825,7 @@ export class LayerManager extends GfxExtension {
}
}
if (payload.type === 'delete') {
const block = store.getBlockById(payload.id);
const block = store.getModelById(payload.id);
if (block instanceof GfxBlockElementModel) {
this.delete(block as GfxBlockElementModel);

View File

@@ -396,7 +396,7 @@ export abstract class GfxGroupLikeElementModel<
for (const key of this.childIds) {
const element =
this.surface.getElementById(key) ||
(this.surface.doc.getBlockById(key) as GfxBlockElementModel);
(this.surface.doc.getModelById(key) as GfxBlockElementModel);
element && elements.push(element);
}

View File

@@ -316,7 +316,7 @@ export class GfxSelectionManager extends GfxExtension {
}
const { blocks = [], elements = [] } = groupBy(selection.elements, id => {
return this.std.store.getBlockById(id) ? 'blocks' : 'elements';
return this.std.store.getModelById(id) ? 'blocks' : 'elements';
});
let instances: (SurfaceSelection | CursorSelection)[] = [];

View File

@@ -236,7 +236,7 @@ export class RangeBinding {
return;
}
const model = this.host.doc.getBlockById(textSelection.blockId);
const model = this.host.doc.getModelById(textSelection.blockId);
// If the model is not found, the selection maybe in another editor
if (!model) return;

View File

@@ -109,7 +109,7 @@ export class BlockComponent<
if (this._model) {
return this._model;
}
const model = this.doc.getBlockById<Model>(this.blockId);
const model = this.doc.getModelById<Model>(this.blockId);
if (!model) {
throw new BlockSuiteError(
ErrorCode.MissingViewModelError,