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

View File

@@ -1,4 +1,4 @@
import type { Y } from '@blocksuite/store';
import type * as Y from 'yjs';
import type { GfxPrimitiveElementModel } from '../element-model.js';
import { getObjectPropMeta, setObjectPropMeta } from './common.js';

View File

@@ -16,8 +16,8 @@ import {
Slot,
type XYWH,
} from '@blocksuite/global/utils';
import { DocCollection, type Y } from '@blocksuite/store';
import { createMutex } from 'lib0/mutex';
import * as Y from 'yjs';
import {
descendantElementsImpl,
@@ -538,7 +538,7 @@ export function syncElementFromY(
if (type.action === 'update' || type.action === 'add') {
const value = model.yMap.get(key);
if (value instanceof DocCollection.Y.Text) {
if (value instanceof Y.Text) {
disposables[key]?.();
disposables[key] = watchText(key, value, callback);
}
@@ -560,7 +560,7 @@ export function syncElementFromY(
};
Array.from(model.yMap.entries()).forEach(([key, value]) => {
if (value instanceof DocCollection.Y.Text) {
if (value instanceof Y.Text) {
disposables[key] = watchText(key, value, callback);
}

View File

@@ -1,6 +1,7 @@
import { assertType, type Constructor, Slot } from '@blocksuite/global/utils';
import type { Boxed, Y } from '@blocksuite/store';
import { BlockModel, DocCollection, nanoid } from '@blocksuite/store';
import type { Boxed } from '@blocksuite/store';
import { BlockModel, nanoid } from '@blocksuite/store';
import * as Y from 'yjs';
import {
type GfxGroupCompatibleInterface,
@@ -124,7 +125,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
throw new Error('Cannot find id in props');
}
const yMap = new DocCollection.Y.Map();
const yMap = new Y.Map();
const elementModel = this._createElementFromYMap(
type as string,
id as string,