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