mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 21:41:52 +08:00
refactor(editor): query methods in edgeless api (#9407)
This commit is contained in:
@@ -121,7 +121,7 @@ describe('group', () => {
|
||||
const groupId = service.crud.addElement('group', { children });
|
||||
assertExists(groupId);
|
||||
|
||||
const group = service.getElementById(groupId) as GroupElementModel;
|
||||
const group = service.crud.getElementById(groupId) as GroupElementModel;
|
||||
const assertInitial = () => {
|
||||
expect(group.x).toBe(0);
|
||||
expect(group.y).toBe(0);
|
||||
@@ -190,7 +190,7 @@ describe('group', () => {
|
||||
const map = new DocCollection.Y.Map<boolean>();
|
||||
const groupId = service.crud.addElement('group', { children: map });
|
||||
assertExists(groupId);
|
||||
const group = service.getElementById(groupId) as GroupElementModel;
|
||||
const group = service.crud.getElementById(groupId) as GroupElementModel;
|
||||
|
||||
expect(group.x).toBe(0);
|
||||
expect(group.y).toBe(0);
|
||||
@@ -205,7 +205,7 @@ describe('group', () => {
|
||||
}) as string;
|
||||
});
|
||||
const groups = groupIds.map(
|
||||
id => service.getElementById(id) as GroupElementModel
|
||||
id => service.crud.getElementById(id) as GroupElementModel
|
||||
);
|
||||
|
||||
groups.forEach(group => {
|
||||
@@ -255,7 +255,7 @@ describe('mindmap', () => {
|
||||
const mindmapId = service.crud.addElement('mindmap', { children: tree });
|
||||
assertExists(mindmapId);
|
||||
const mindmap = () =>
|
||||
service.getElementById(mindmapId) as MindmapElementModel;
|
||||
service.crud.getElementById(mindmapId) as MindmapElementModel;
|
||||
|
||||
expect(service.surface.elementModels.length).toBe(6);
|
||||
doc.captureSync();
|
||||
@@ -306,7 +306,7 @@ describe('mindmap', () => {
|
||||
});
|
||||
assertExists(mindmapId);
|
||||
const mindmap = () =>
|
||||
service.getElementById(mindmapId) as MindmapElementModel;
|
||||
service.crud.getElementById(mindmapId) as MindmapElementModel;
|
||||
|
||||
doc.captureSync();
|
||||
await wait();
|
||||
@@ -351,7 +351,7 @@ describe('mindmap', () => {
|
||||
});
|
||||
assertExists(mindmapId);
|
||||
const mindmap = () =>
|
||||
service.getElementById(mindmapId) as MindmapElementModel;
|
||||
service.crud.getElementById(mindmapId) as MindmapElementModel;
|
||||
|
||||
doc.captureSync();
|
||||
await wait();
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('apply last props', () => {
|
||||
shapeType: ShapeType.Rect,
|
||||
});
|
||||
assertExists(rectId);
|
||||
const rectShape = service.getElementById(rectId) as ShapeElementModel;
|
||||
const rectShape = service.crud.getElementById(rectId) as ShapeElementModel;
|
||||
expect(rectShape.fillColor).toBe(ShapeFillColor.Yellow);
|
||||
service.crud.updateElement(rectId, {
|
||||
fillColor: ShapeFillColor.Orange,
|
||||
@@ -65,7 +65,9 @@ describe('apply last props', () => {
|
||||
shapeType: ShapeType.Diamond,
|
||||
});
|
||||
assertExists(diamondId);
|
||||
const diamondShape = service.getElementById(diamondId) as ShapeElementModel;
|
||||
const diamondShape = service.crud.getElementById(
|
||||
diamondId
|
||||
) as ShapeElementModel;
|
||||
expect(diamondShape.fillColor).toBe(ShapeFillColor.Yellow);
|
||||
service.crud.updateElement(diamondId, {
|
||||
fillColor: ShapeFillColor.Blue,
|
||||
@@ -81,7 +83,7 @@ describe('apply last props', () => {
|
||||
radius: 0.1,
|
||||
});
|
||||
assertExists(roundedRectId);
|
||||
const roundedRectShape = service.getElementById(
|
||||
const roundedRectShape = service.crud.getElementById(
|
||||
roundedRectId
|
||||
) as ShapeElementModel;
|
||||
expect(roundedRectShape.fillColor).toBe(ShapeFillColor.Yellow);
|
||||
@@ -97,14 +99,16 @@ describe('apply last props', () => {
|
||||
shapeType: ShapeType.Rect,
|
||||
});
|
||||
assertExists(rectId2);
|
||||
const rectShape2 = service.getElementById(rectId2) as ShapeElementModel;
|
||||
const rectShape2 = service.crud.getElementById(
|
||||
rectId2
|
||||
) as ShapeElementModel;
|
||||
expect(rectShape2.fillColor).toBe(ShapeFillColor.Orange);
|
||||
|
||||
const diamondId2 = service.crud.addElement('shape', {
|
||||
shapeType: ShapeType.Diamond,
|
||||
});
|
||||
assertExists(diamondId2);
|
||||
const diamondShape2 = service.getElementById(
|
||||
const diamondShape2 = service.crud.getElementById(
|
||||
diamondId2
|
||||
) as ShapeElementModel;
|
||||
expect(diamondShape2.fillColor).toBe(ShapeFillColor.Blue);
|
||||
@@ -114,7 +118,7 @@ describe('apply last props', () => {
|
||||
radius: 0.1,
|
||||
});
|
||||
assertExists(roundedRectId2);
|
||||
const roundedRectShape2 = service.getElementById(
|
||||
const roundedRectShape2 = service.crud.getElementById(
|
||||
roundedRectId2
|
||||
) as ShapeElementModel;
|
||||
expect(roundedRectShape2.fillColor).toBe(ShapeFillColor.Green);
|
||||
@@ -123,7 +127,7 @@ describe('apply last props', () => {
|
||||
test('connector', () => {
|
||||
const id = service.crud.addElement('connector', { mode: 0 });
|
||||
assertExists(id);
|
||||
const connector = service.getElementById(id) as ConnectorElementModel;
|
||||
const connector = service.crud.getElementById(id) as ConnectorElementModel;
|
||||
expect(connector.stroke).toBe(LineColor.Grey);
|
||||
expect(connector.strokeWidth).toBe(2);
|
||||
expect(connector.strokeStyle).toBe('solid');
|
||||
@@ -133,7 +137,9 @@ describe('apply last props', () => {
|
||||
|
||||
const id2 = service.crud.addElement('connector', { mode: 1 });
|
||||
assertExists(id2);
|
||||
const connector2 = service.getElementById(id2) as ConnectorElementModel;
|
||||
const connector2 = service.crud.getElementById(
|
||||
id2
|
||||
) as ConnectorElementModel;
|
||||
expect(connector2.strokeWidth).toBe(10);
|
||||
service.crud.updateElement(id2, {
|
||||
labelStyle: {
|
||||
@@ -144,7 +150,9 @@ describe('apply last props', () => {
|
||||
|
||||
const id3 = service.crud.addElement('connector', { mode: 1 });
|
||||
assertExists(id3);
|
||||
const connector3 = service.getElementById(id3) as ConnectorElementModel;
|
||||
const connector3 = service.crud.getElementById(
|
||||
id3
|
||||
) as ConnectorElementModel;
|
||||
expect(connector3.strokeWidth).toBe(10);
|
||||
expect(connector3.labelStyle.color).toBe(LineColor.Magenta);
|
||||
expect(connector3.labelStyle.fontFamily).toBe(FontFamily.Kalam);
|
||||
@@ -153,14 +161,14 @@ describe('apply last props', () => {
|
||||
test('brush', () => {
|
||||
const id = service.crud.addElement('brush', {});
|
||||
assertExists(id);
|
||||
const brush = service.getElementById(id) as BrushElementModel;
|
||||
const brush = service.crud.getElementById(id) as BrushElementModel;
|
||||
expect(brush.color).toEqual({
|
||||
dark: LineColor.White,
|
||||
light: LineColor.Black,
|
||||
});
|
||||
expect(brush.lineWidth).toBe(4);
|
||||
service.crud.updateElement(id, { lineWidth: 10 });
|
||||
const secondBrush = service.getElementById(
|
||||
const secondBrush = service.crud.getElementById(
|
||||
service.crud.addElement('brush', {}) as string
|
||||
) as BrushElementModel;
|
||||
expect(secondBrush.lineWidth).toBe(10);
|
||||
@@ -169,10 +177,10 @@ describe('apply last props', () => {
|
||||
test('text', () => {
|
||||
const id = service.crud.addElement('text', {});
|
||||
assertExists(id);
|
||||
const text = service.getElementById(id) as TextElementModel;
|
||||
const text = service.crud.getElementById(id) as TextElementModel;
|
||||
expect(text.fontSize).toBe(24);
|
||||
service.crud.updateElement(id, { fontSize: 36 });
|
||||
const secondText = service.getElementById(
|
||||
const secondText = service.crud.getElementById(
|
||||
service.crud.addElement('text', {}) as string
|
||||
) as TextElementModel;
|
||||
expect(secondText.fontSize).toBe(36);
|
||||
@@ -181,7 +189,7 @@ describe('apply last props', () => {
|
||||
test('mindmap', () => {
|
||||
const id = service.crud.addElement('mindmap', {});
|
||||
assertExists(id);
|
||||
const mindmap = service.getElementById(id) as MindmapElementModel;
|
||||
const mindmap = service.crud.getElementById(id) as MindmapElementModel;
|
||||
expect(mindmap.layoutType).toBe(LayoutType.RIGHT);
|
||||
expect(mindmap.style).toBe(MindmapStyle.ONE);
|
||||
service.crud.updateElement(id, {
|
||||
@@ -191,7 +199,7 @@ describe('apply last props', () => {
|
||||
|
||||
const id2 = service.crud.addElement('mindmap', {});
|
||||
assertExists(id2);
|
||||
const mindmap2 = service.getElementById(id2) as MindmapElementModel;
|
||||
const mindmap2 = service.crud.getElementById(id2) as MindmapElementModel;
|
||||
expect(mindmap2.layoutType).toBe(LayoutType.BALANCE);
|
||||
expect(mindmap2.style).toBe(MindmapStyle.THREE);
|
||||
});
|
||||
@@ -200,7 +208,7 @@ describe('apply last props', () => {
|
||||
const surface = getSurfaceBlock(doc);
|
||||
const id = service.crud.addBlock('affine:edgeless-text', {}, surface!.id);
|
||||
assertExists(id);
|
||||
const text = service.getElementById(id) as EdgelessTextBlockModel;
|
||||
const text = service.crud.getElementById(id) as EdgelessTextBlockModel;
|
||||
expect(text.color).toBe(DEFAULT_TEXT_COLOR);
|
||||
expect(text.fontFamily).toBe(FontFamily.Inter);
|
||||
service.crud.updateElement(id, {
|
||||
@@ -210,7 +218,7 @@ describe('apply last props', () => {
|
||||
|
||||
const id2 = service.crud.addBlock('affine:edgeless-text', {}, surface!.id);
|
||||
assertExists(id2);
|
||||
const text2 = service.getElementById(id2) as EdgelessTextBlockModel;
|
||||
const text2 = service.crud.getElementById(id2) as EdgelessTextBlockModel;
|
||||
expect(text2.color).toBe(LineColor.Green);
|
||||
expect(text2.fontFamily).toBe(FontFamily.OrelegaOne);
|
||||
});
|
||||
@@ -218,7 +226,7 @@ describe('apply last props', () => {
|
||||
test('note', () => {
|
||||
const id = service.crud.addBlock('affine:note', {}, doc.root!.id);
|
||||
assertExists(id);
|
||||
const note = service.getElementById(id) as NoteBlockModel;
|
||||
const note = service.crud.getElementById(id) as NoteBlockModel;
|
||||
expect(note.background).toBe(DEFAULT_NOTE_BACKGROUND_COLOR);
|
||||
expect(note.edgeless.style.shadowType).toBe(DEFAULT_NOTE_SHADOW);
|
||||
service.crud.updateElement(id, {
|
||||
@@ -232,7 +240,7 @@ describe('apply last props', () => {
|
||||
|
||||
const id2 = service.crud.addBlock('affine:note', {}, doc.root!.id);
|
||||
assertExists(id2);
|
||||
const note2 = service.getElementById(id2) as NoteBlockModel;
|
||||
const note2 = service.crud.getElementById(id2) as NoteBlockModel;
|
||||
expect(note2.background).toBe(NoteBackgroundColor.Purple);
|
||||
expect(note2.edgeless.style.shadowType).toBe(NoteShadow.Film);
|
||||
});
|
||||
@@ -241,7 +249,7 @@ describe('apply last props', () => {
|
||||
const surface = getSurfaceBlock(doc);
|
||||
const id = service.crud.addBlock('affine:frame', {}, surface!.id);
|
||||
assertExists(id);
|
||||
const note = service.getElementById(id) as FrameBlockModel;
|
||||
const note = service.crud.getElementById(id) as FrameBlockModel;
|
||||
expect(note.background).toBe('--affine-palette-transparent');
|
||||
service.crud.updateElement(id, {
|
||||
background: FrameBackgroundColor.Purple,
|
||||
@@ -249,7 +257,7 @@ describe('apply last props', () => {
|
||||
|
||||
const id2 = service.crud.addBlock('affine:frame', {}, surface!.id);
|
||||
assertExists(id2);
|
||||
const frame2 = service.getElementById(id2) as FrameBlockModel;
|
||||
const frame2 = service.crud.getElementById(id2) as FrameBlockModel;
|
||||
expect(frame2.background).toBe(FrameBackgroundColor.Purple);
|
||||
service.crud.updateElement(id2, {
|
||||
background: { normal: '#def4e740' },
|
||||
@@ -257,7 +265,7 @@ describe('apply last props', () => {
|
||||
|
||||
const id3 = service.crud.addBlock('affine:frame', {}, surface!.id);
|
||||
assertExists(id3);
|
||||
const frame3 = service.getElementById(id3) as FrameBlockModel;
|
||||
const frame3 = service.crud.getElementById(id3) as FrameBlockModel;
|
||||
expect(frame3.background).toEqual({ normal: '#def4e740' });
|
||||
service.crud.updateElement(id3, {
|
||||
background: { light: '#a381aa23', dark: '#6e907452' },
|
||||
@@ -265,7 +273,7 @@ describe('apply last props', () => {
|
||||
|
||||
const id4 = service.crud.addBlock('affine:frame', {}, surface!.id);
|
||||
assertExists(id4);
|
||||
const frame4 = service.getElementById(id4) as FrameBlockModel;
|
||||
const frame4 = service.crud.getElementById(id4) as FrameBlockModel;
|
||||
expect(frame4.background).toEqual({
|
||||
light: '#a381aa23',
|
||||
dark: '#6e907452',
|
||||
|
||||
@@ -91,7 +91,7 @@ test('change element should update layer automatically', async () => {
|
||||
|
||||
service.crud.updateElement(id, {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(id)!,
|
||||
service.crud.getElementById(id)!,
|
||||
'forward'
|
||||
),
|
||||
});
|
||||
@@ -101,7 +101,7 @@ test('change element should update layer automatically', async () => {
|
||||
|
||||
service.crud.updateElement(canvasElId!, {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(canvasElId!)!,
|
||||
service.crud.getElementById(canvasElId!)!,
|
||||
'forward'
|
||||
),
|
||||
});
|
||||
@@ -160,7 +160,7 @@ test('a new layer should be created in canvasLayers prop when the topmost layer
|
||||
test('layer zindex should update correctly when elements changed', async () => {
|
||||
addNote(doc);
|
||||
const noteId = addNote(doc);
|
||||
const note = service.getElementById(noteId);
|
||||
const note = service.crud.getElementById(noteId);
|
||||
addNote(doc);
|
||||
service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
@@ -168,7 +168,7 @@ test('layer zindex should update correctly when elements changed', async () => {
|
||||
const topShapeId = service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
});
|
||||
const topShape = service.getElementById(topShapeId!)!;
|
||||
const topShape = service.crud.getElementById(topShapeId!)!;
|
||||
|
||||
await wait();
|
||||
|
||||
@@ -238,8 +238,8 @@ test('blocks should rerender when their z-index changed', async () => {
|
||||
service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
index: CommonUtils.generateKeyBetween(
|
||||
service.getElementById(blocks[1])!.index,
|
||||
service.getElementById(blocks[2])!.index
|
||||
service.crud.getElementById(blocks[1])!.index,
|
||||
service.crud.getElementById(blocks[2])!.index
|
||||
),
|
||||
});
|
||||
|
||||
@@ -266,19 +266,19 @@ describe('layer reorder functionality', () => {
|
||||
test('forward', async () => {
|
||||
service.crud.updateElement(ids[0], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[0])!,
|
||||
service.crud.getElementById(ids[0])!,
|
||||
'forward'
|
||||
),
|
||||
});
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[0]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[0]) as any)
|
||||
)
|
||||
).toBe(1);
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[1]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[1]) as any)
|
||||
)
|
||||
).toBe(0);
|
||||
|
||||
@@ -286,19 +286,19 @@ describe('layer reorder functionality', () => {
|
||||
|
||||
service.crud.updateElement(ids[1], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[1])!,
|
||||
service.crud.getElementById(ids[1])!,
|
||||
'forward'
|
||||
),
|
||||
});
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[0]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[0]) as any)
|
||||
)
|
||||
).toBe(0);
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[1]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[1]) as any)
|
||||
)
|
||||
).toBe(1);
|
||||
});
|
||||
@@ -306,7 +306,7 @@ describe('layer reorder functionality', () => {
|
||||
test('front', async () => {
|
||||
service.crud.updateElement(ids[0], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[0])!,
|
||||
service.crud.getElementById(ids[0])!,
|
||||
'front'
|
||||
),
|
||||
});
|
||||
@@ -315,20 +315,20 @@ describe('layer reorder functionality', () => {
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[0]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[0]) as any)
|
||||
)
|
||||
).toBe(3);
|
||||
|
||||
service.crud.updateElement(ids[1], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[1])!,
|
||||
service.crud.getElementById(ids[1])!,
|
||||
'front'
|
||||
),
|
||||
});
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[1]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[1]) as any)
|
||||
)
|
||||
).toBe(3);
|
||||
});
|
||||
@@ -336,19 +336,19 @@ describe('layer reorder functionality', () => {
|
||||
test('backward', async () => {
|
||||
service.crud.updateElement(ids[3], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[3])!,
|
||||
service.crud.getElementById(ids[3])!,
|
||||
'backward'
|
||||
),
|
||||
});
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[3]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[3]) as any)
|
||||
)
|
||||
).toBe(1);
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[2]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[2]) as any)
|
||||
)
|
||||
).toBe(2);
|
||||
|
||||
@@ -356,19 +356,19 @@ describe('layer reorder functionality', () => {
|
||||
|
||||
service.crud.updateElement(ids[2], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[2])!,
|
||||
service.crud.getElementById(ids[2])!,
|
||||
'backward'
|
||||
),
|
||||
});
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[3]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[3]) as any)
|
||||
)
|
||||
).toBe(3);
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[2]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[2]) as any)
|
||||
)
|
||||
).toBe(2);
|
||||
});
|
||||
@@ -376,14 +376,14 @@ describe('layer reorder functionality', () => {
|
||||
test('back', async () => {
|
||||
service.crud.updateElement(ids[3], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[3])!,
|
||||
service.crud.getElementById(ids[3])!,
|
||||
'back'
|
||||
),
|
||||
});
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[3]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[3]) as any)
|
||||
)
|
||||
).toBe(0);
|
||||
|
||||
@@ -391,14 +391,14 @@ describe('layer reorder functionality', () => {
|
||||
|
||||
service.crud.updateElement(ids[2], {
|
||||
index: service.layer.getReorderedIndex(
|
||||
service.getElementById(ids[2])!,
|
||||
service.crud.getElementById(ids[2])!,
|
||||
'back'
|
||||
),
|
||||
});
|
||||
|
||||
expect(
|
||||
service.layer.layers.findIndex(layer =>
|
||||
layer.set.has(service.getElementById(ids[2]) as any)
|
||||
layer.set.has(service.crud.getElementById(ids[2]) as any)
|
||||
)
|
||||
).toBe(0);
|
||||
});
|
||||
@@ -507,7 +507,7 @@ describe('group related functionality', () => {
|
||||
service,
|
||||
elements.filter((_, idx) => idx !== 1 && idx !== 3)
|
||||
)!;
|
||||
const group = service.getElementById(groupId)!;
|
||||
const group = service.crud.getElementById(groupId)!;
|
||||
|
||||
expect(service.layer.layers.length).toBe(2);
|
||||
|
||||
@@ -538,7 +538,7 @@ describe('group related functionality', () => {
|
||||
})!,
|
||||
];
|
||||
service.doc.captureSync();
|
||||
const elements = elementIds.map(id => service.getElementById(id)!);
|
||||
const elements = elementIds.map(id => service.crud.getElementById(id)!);
|
||||
|
||||
const isKeptRelativeOrder = () => {
|
||||
return elements.every((element, idx) => {
|
||||
@@ -552,7 +552,7 @@ describe('group related functionality', () => {
|
||||
const groupId = createGroup(edgeless.service, elementIds)!;
|
||||
expect(isKeptRelativeOrder()).toBeTruthy();
|
||||
|
||||
service.ungroup(service.getElementById(groupId) as GroupElementModel);
|
||||
service.ungroup(service.crud.getElementById(groupId) as GroupElementModel);
|
||||
expect(isKeptRelativeOrder()).toBeTruthy();
|
||||
|
||||
service.doc.undo();
|
||||
@@ -586,15 +586,15 @@ describe('compare function', () => {
|
||||
const shapeId = service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
})!;
|
||||
const shapeEl = service.getElementById(shapeId)!;
|
||||
const shapeEl = service.crud.getElementById(shapeId)!;
|
||||
expect(service.layer.compare(shapeEl, shapeEl)).toBe(SORT_ORDER.SAME);
|
||||
|
||||
const groupId = createGroup(service, [shapeId])!;
|
||||
const groupEl = service.getElementById(groupId)!;
|
||||
const groupEl = service.crud.getElementById(groupId)!;
|
||||
expect(service.layer.compare(groupEl, groupEl)).toBe(SORT_ORDER.SAME);
|
||||
|
||||
const noteId = addNote(doc);
|
||||
const note = service.getElementById(noteId)! as NoteBlockModel;
|
||||
const note = service.crud.getElementById(noteId)! as NoteBlockModel;
|
||||
expect(service.layer.compare(note, note)).toBe(SORT_ORDER.SAME);
|
||||
});
|
||||
|
||||
@@ -602,11 +602,11 @@ describe('compare function', () => {
|
||||
const shapeId = service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
})!;
|
||||
const shapeEl = service.getElementById(shapeId)!;
|
||||
const shapeEl = service.crud.getElementById(shapeId)!;
|
||||
const noteId = addNote(doc);
|
||||
const note = service.getElementById(noteId)! as NoteBlockModel;
|
||||
const note = service.crud.getElementById(noteId)! as NoteBlockModel;
|
||||
const groupId = createGroup(service, [shapeId, noteId])!;
|
||||
const groupEl = service.getElementById(groupId)!;
|
||||
const groupEl = service.crud.getElementById(groupId)!;
|
||||
|
||||
expect(service.layer.compare(groupEl, shapeEl)).toBe(SORT_ORDER.BEFORE);
|
||||
expect(service.layer.compare(shapeEl, groupEl)).toBe(SORT_ORDER.AFTER);
|
||||
@@ -618,16 +618,16 @@ describe('compare function', () => {
|
||||
const shape1Id = service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
})!;
|
||||
const shape1 = service.getElementById(shape1Id)!;
|
||||
const shape1 = service.crud.getElementById(shape1Id)!;
|
||||
const shape2Id = service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
})!;
|
||||
const shape2 = service.getElementById(shape2Id)!;
|
||||
const shape2 = service.crud.getElementById(shape2Id)!;
|
||||
const note1Id = addNote(doc);
|
||||
|
||||
const note1 = service.getElementById(note1Id)! as NoteBlockModel;
|
||||
const note1 = service.crud.getElementById(note1Id)! as NoteBlockModel;
|
||||
const note2Id = addNote(doc);
|
||||
const note2 = service.getElementById(note2Id)! as NoteBlockModel;
|
||||
const note2 = service.crud.getElementById(note2Id)! as NoteBlockModel;
|
||||
|
||||
expect(service.layer.compare(shape1, shape2)).toBe(SORT_ORDER.BEFORE);
|
||||
expect(service.layer.compare(shape2, shape1)).toBe(SORT_ORDER.AFTER);
|
||||
@@ -659,12 +659,12 @@ describe('compare function', () => {
|
||||
])!;
|
||||
const group2Id = createGroup(service, [group1Id])!;
|
||||
|
||||
const shape1 = service.getElementById(shape1Id)!;
|
||||
const shape2 = service.getElementById(shape2Id)!;
|
||||
const note1 = service.getElementById(note1Id)! as NoteBlockModel;
|
||||
const note2 = service.getElementById(note2Id)! as NoteBlockModel;
|
||||
const group1 = service.getElementById(group1Id)!;
|
||||
const group2 = service.getElementById(group2Id)!;
|
||||
const shape1 = service.crud.getElementById(shape1Id)!;
|
||||
const shape2 = service.crud.getElementById(shape2Id)!;
|
||||
const note1 = service.crud.getElementById(note1Id)! as NoteBlockModel;
|
||||
const note2 = service.crud.getElementById(note2Id)! as NoteBlockModel;
|
||||
const group1 = service.crud.getElementById(group1Id)!;
|
||||
const group2 = service.crud.getElementById(group2Id)!;
|
||||
|
||||
// assert nested group to group
|
||||
expect(service.layer.compare(group2, group1)).toBe(SORT_ORDER.BEFORE);
|
||||
@@ -695,9 +695,9 @@ describe('compare function', () => {
|
||||
const groupAId = createGroup(service, [
|
||||
createGroup(service, [groupAShapeId, groupANoteId])!,
|
||||
])!;
|
||||
const groupAShape = service.getElementById(groupAShapeId)!;
|
||||
const groupANote = service.getElementById(groupANoteId)!;
|
||||
const groupA = service.getElementById(groupAId)!;
|
||||
const groupAShape = service.crud.getElementById(groupAShapeId)!;
|
||||
const groupANote = service.crud.getElementById(groupANoteId)!;
|
||||
const groupA = service.crud.getElementById(groupAId)!;
|
||||
|
||||
const groupBShapeId = service.crud.addElement('shape', {
|
||||
shapeType: 'rect',
|
||||
@@ -706,9 +706,9 @@ describe('compare function', () => {
|
||||
const groupBId = createGroup(service, [
|
||||
createGroup(service, [groupBShapeId, groupBNoteId])!,
|
||||
])!;
|
||||
const groupBShape = service.getElementById(groupBShapeId)!;
|
||||
const groupBNote = service.getElementById(groupBNoteId)!;
|
||||
const groupB = service.getElementById(groupBId)!;
|
||||
const groupBShape = service.crud.getElementById(groupBShapeId)!;
|
||||
const groupBNote = service.crud.getElementById(groupBNoteId)!;
|
||||
const groupB = service.crud.getElementById(groupBId)!;
|
||||
|
||||
expect(service.layer.compare(groupAShape, groupBShape)).toBe(
|
||||
SORT_ORDER.BEFORE
|
||||
@@ -860,10 +860,10 @@ describe('index generator', () => {
|
||||
})!;
|
||||
const noteId = addNote(doc);
|
||||
|
||||
preinsertedShape = service.getElementById(
|
||||
preinsertedShape = service.crud.getElementById(
|
||||
shapeId
|
||||
)! as BlockSuite.SurfaceElementModel;
|
||||
preinsertedNote = service.getElementById(noteId)! as NoteBlockModel;
|
||||
preinsertedNote = service.crud.getElementById(noteId)! as NoteBlockModel;
|
||||
});
|
||||
|
||||
test('generator should remember the index it generated', () => {
|
||||
|
||||
@@ -211,7 +211,7 @@ describe('basic', () => {
|
||||
|
||||
const edgeless = surfaceRef.previewEditor!.std.get(EdgelessRootService);
|
||||
|
||||
const group = edgeless.getElementById(groupId)!;
|
||||
const group = edgeless.crud.getElementById(groupId)!;
|
||||
|
||||
expect(edgeless.viewport.isInViewport(group.elementBound)).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('default tool', () => {
|
||||
drag(edgeless.host, { x: 0, y: 50 }, { x: 0, y: 150 });
|
||||
await wait();
|
||||
|
||||
const element = service.getElementById(id!)!;
|
||||
const element = service.crud.getElementById(id!)!;
|
||||
expect(element.xywh).toEqual(`[0,100,100,100]`);
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('default tool', () => {
|
||||
drag(edgeless.host, { x: 50, y: 50 }, { x: 150, y: 150 });
|
||||
await wait();
|
||||
|
||||
const element = service.getElementById(noteId)!;
|
||||
const element = service.crud.getElementById(noteId)!;
|
||||
const [x, y] = JSON.parse(element.xywh);
|
||||
|
||||
expect(x).toEqual(100);
|
||||
|
||||
Reference in New Issue
Block a user