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

@@ -129,7 +129,7 @@ export class EdgelessCRUDExtension extends Extension {
return;
}
const block = this.std.store.getBlockById(id);
const block = this.std.store.getModelById(id);
if (block) {
const key = getLastPropsKey(block.flavour, {
...block.yBlock.toJSON(),
@@ -145,7 +145,7 @@ export class EdgelessCRUDExtension extends Extension {
if (!surface) {
return null;
}
const el = surface.getElementById(id) ?? this.std.store.getBlockById(id);
const el = surface.getElementById(id) ?? this.std.store.getModelById(id);
return el as GfxModel | null;
}

View File

@@ -602,7 +602,7 @@ function getNotesInFrameBound(
): NoteBlockModel[] {
const bound = Bound.deserialize(frame.xywh);
return (doc.getBlockByFlavour('affine:note') as NoteBlockModel[]).filter(
return (doc.getModelsByFlavour('affine:note') as NoteBlockModel[]).filter(
ele => {
const xywh = Bound.deserialize(ele.xywh);

View File

@@ -32,7 +32,7 @@ export function mindmap(
const { connector, outdated } = result;
const elementGetter = (id: string) =>
model.surface.getElementById(id) ??
(model.surface.doc.getBlockById(id) as GfxModel);
(model.surface.doc.getModelById(id) as GfxModel);
if (outdated) {
ConnectorPathGenerator.updatePath(connector, null, elementGetter);

View File

@@ -25,7 +25,7 @@ export class SurfaceBlockService extends BlockService {
const disposable = this.doc.slots.blockUpdated.subscribe(payload => {
if (payload.flavour === 'affine:surface') {
disposable.unsubscribe();
const surface = this.doc.getBlockById(
const surface = this.doc.getModelById(
payload.id
) as SurfaceBlockModel | null;
if (!surface) return;

View File

@@ -100,7 +100,7 @@ export function addNote(
noteId
);
if (options.collapse && height > NOTE_MIN_HEIGHT) {
const note = doc.getBlockById(noteId) as NoteBlockModel;
const note = doc.getModelById(noteId) as NoteBlockModel;
doc.updateBlock(note, () => {
note.props.edgeless.collapse = true;
note.props.edgeless.collapsedHeight = height;

View File

@@ -8,9 +8,9 @@ export const connectorWatcher: SurfaceMiddleware = (
surface: SurfaceBlockModel
) => {
const hasElementById = (id: string) =>
surface.hasElementById(id) || surface.doc.hasBlockById(id);
surface.hasElementById(id) || surface.doc.hasBlock(id);
const elementGetter = (id: string) =>
surface.getElementById(id) ?? (surface.doc.getBlockById(id) as GfxModel);
surface.getElementById(id) ?? (surface.doc.getModelById(id) as GfxModel);
const updateConnectorPath = (connector: ConnectorElementModel) => {
if (
((connector.source?.id && hasElementById(connector.source.id)) ||