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
@@ -6,8 +6,8 @@ import {
NoteDisplayMode,
} from '@blocksuite/blocks';
import { assertExists } from '@blocksuite/global/utils';
import { DocCollection } from '@blocksuite/store';
import { beforeEach, describe, expect, test } from 'vitest';
import * as Y from 'yjs';
import { wait } from '../utils/common.js';
import { addNote, getDocRootBlock } from '../utils/edgeless.js';
@@ -24,7 +24,7 @@ describe('group', () => {
});
test('group with no children will be removed automatically', () => {
const map = new DocCollection.Y.Map<boolean>();
const map = new Y.Map<boolean>();
const ids = Array.from({ length: 2 })
.map(() => {
const id = service.crud.addElement('shape', {
@@ -62,7 +62,7 @@ describe('group', () => {
});
test('remove group should remove its children at the same time', () => {
const map = new DocCollection.Y.Map<boolean>();
const map = new Y.Map<boolean>();
const doc = service.doc;
const noteId = addNote(doc);
const shapeId = service.crud.addElement('shape', {
@@ -112,7 +112,7 @@ describe('group', () => {
collapsedHeight: 100,
},
});
const children = new DocCollection.Y.Map<boolean>();
const children = new Y.Map<boolean>();
children.set(shape1, true);
children.set(shape2, true);
@@ -187,7 +187,7 @@ describe('group', () => {
});
test('empty group should have all zero xywh', () => {
const map = new DocCollection.Y.Map<boolean>();
const map = new Y.Map<boolean>();
const groupId = service.crud.addElement('group', { children: map });
assertExists(groupId);
const group = service.crud.getElementById(groupId) as GroupElementModel;
@@ -201,7 +201,7 @@ describe('group', () => {
test('descendant of group should not contain itself', () => {
const groupIds = [1, 2, 3].map(_ => {
return service.crud.addElement('group', {
children: new DocCollection.Y.Map<boolean>(),
children: new Y.Map<boolean>(),
}) as string;
});
const groups = groupIds.map(
@@ -5,8 +5,9 @@ import type {
GroupElementModel,
NoteBlockModel,
} from '@blocksuite/blocks';
import { type BlockModel, type Doc, DocCollection } from '@blocksuite/store';
import { type BlockModel, type Doc } from '@blocksuite/store';
import { beforeEach, describe, expect, test } from 'vitest';
import * as Y from 'yjs';
import { wait } from '../utils/common.js';
import {
@@ -409,7 +410,7 @@ describe('group related functionality', () => {
service: EdgelessRootBlockComponent['service'],
childIds: string[]
) => {
const children = new DocCollection.Y.Map<boolean>();
const children = new Y.Map<boolean>();
childIds.forEach(id => children.set(id, true));
return service.crud.addElement('group', {
@@ -574,7 +575,7 @@ describe('compare function', () => {
childIds: string[]
// eslint-disable-next-line sonarjs/no-identical-functions
) => {
const children = new DocCollection.Y.Map<boolean>();
const children = new Y.Map<boolean>();
childIds.forEach(id => children.set(id, true));
return service.crud.addElement('group', {