mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat(editor): improve api for store, and add docs (#10941)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)[] = [];
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user