refactor(editor): reduce dependency to doc collection (#9492)

This commit is contained in:
Saul-Mirone
2025-01-03 01:59:25 +00:00
parent eb15b3cb39
commit 8b6c81f76d
70 changed files with 185 additions and 210 deletions
@@ -20,8 +20,8 @@ import {
noop,
pick,
} from '@blocksuite/global/utils';
import { DocCollection, type Y } from '@blocksuite/store';
import { generateKeyBetween } from 'fractional-indexing';
import * as Y from 'yjs';
import { z } from 'zod';
import { ConnectorMode } from '../../consts/connector.js';
@@ -183,9 +183,9 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
if (
props.children &&
!isNodeType(props.children as Record<string, unknown>) &&
!(props.children instanceof DocCollection.Y.Map)
!(props.children instanceof Y.Map)
) {
const children: Y.Map<NodeDetail> = new DocCollection.Y.Map();
const children: Y.Map<NodeDetail> = new Y.Map();
keys(props.children).forEach(key => {
const detail = pick<Record<string, unknown>, keyof NodeDetail>(
@@ -284,9 +284,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
throw new Error(`Parent node ${parent} not found`);
}
props['text'] = new DocCollection.Y.Text(
(props['text'] as string) ?? 'New node'
);
props['text'] = new Y.Text((props['text'] as string) ?? 'New node');
const type = (props.type as string) ?? 'shape';
let id: string;
@@ -919,12 +917,12 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
}
@convert((initialValue, instance) => {
if (!(initialValue instanceof DocCollection.Y.Map)) {
if (!(initialValue instanceof Y.Map)) {
nodeSchema.parse(initialValue);
assertType<NodeType>(initialValue);
const map: Y.Map<NodeDetail> = new DocCollection.Y.Map();
const map: Y.Map<NodeDetail> = new Y.Map();
const surface = instance.surface;
const doc = surface.doc;
const recursive = (
@@ -967,7 +965,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
// since this model package is imported by playwright
@observe(observeChildren)
@field()
accessor children: Y.Map<NodeDetail> = new DocCollection.Y.Map();
accessor children: Y.Map<NodeDetail> = new Y.Map();
@watch(watchLayoutType)
@field()