fix(editor): missing edgeless crud piece (#9347)

This commit is contained in:
Mirone
2024-12-26 19:06:06 +08:00
committed by GitHub
parent 6d5733fca9
commit 37747369bc
3 changed files with 24 additions and 21 deletions
@@ -1,10 +1,14 @@
import { SurfaceBlockComponent } from '@blocksuite/affine-block-surface'; import {
EdgelessCRUDIdentifier,
SurfaceBlockComponent,
} from '@blocksuite/affine-block-surface';
import type { EmbedCardStyle } from '@blocksuite/affine-model'; import type { EmbedCardStyle } from '@blocksuite/affine-model';
import { import {
EMBED_CARD_HEIGHT, EMBED_CARD_HEIGHT,
EMBED_CARD_WIDTH, EMBED_CARD_WIDTH,
} from '@blocksuite/affine-shared/consts'; } from '@blocksuite/affine-shared/consts';
import type { BlockStdScope } from '@blocksuite/block-std'; import type { BlockStdScope } from '@blocksuite/block-std';
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
import { Bound, Vec } from '@blocksuite/global/utils'; import { Bound, Vec } from '@blocksuite/global/utils';
interface EmbedCardProperties { interface EmbedCardProperties {
@@ -46,14 +50,14 @@ export function insertEmbedCard(
const edgelessRoot = std.view.getBlock(rootId); const edgelessRoot = std.view.getBlock(rootId);
if (!edgelessRoot) return; if (!edgelessRoot) return;
// @ts-expect-error TODO: fix after edgeless refactor const gfx = std.get(GfxControllerIdentifier);
edgelessRoot.service.viewport.smoothZoom(1); const crud = std.get(EdgelessCRUDIdentifier);
// @ts-expect-error TODO: fix after edgeless refactor
const surfaceBlock = edgelessRoot.surface; gfx.viewport.smoothZoom(1);
const surfaceBlock = gfx.surfaceComponent;
if (!(surfaceBlock instanceof SurfaceBlockComponent)) return; if (!(surfaceBlock instanceof SurfaceBlockComponent)) return;
const center = Vec.toVec(surfaceBlock.renderer.viewport.center); const center = Vec.toVec(surfaceBlock.renderer.viewport.center);
// @ts-expect-error TODO: fix after edgeless refactor const cardId = crud.addBlock(
const cardId = edgelessRoot.service.addBlock(
flavour, flavour,
{ {
...props, ...props,
@@ -67,8 +71,7 @@ export function insertEmbedCard(
surfaceBlock.model surfaceBlock.model
); );
// @ts-expect-error TODO: fix after edgeless refactor gfx.selection.set({
edgelessRoot.service.selection.set({
elements: [cardId], elements: [cardId],
editing: false, editing: false,
}); });
@@ -1,3 +1,4 @@
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
import { import {
EMBED_CARD_HEIGHT, EMBED_CARD_HEIGHT,
EMBED_CARD_WIDTH, EMBED_CARD_WIDTH,
@@ -33,16 +34,16 @@ export class EmbedEdgelessLinkedDocBlockComponent extends toEdgelessEmbedBlock(
return; return;
} }
// @ts-expect-error TODO: fix after edgeless refactor const { addBlock } = this.std.get(EdgelessCRUDIdentifier);
const newId = edgelessService.addBlock( const surface = this.gfx.surface ?? undefined;
const newId = addBlock(
'affine:embed-synced-doc', 'affine:embed-synced-doc',
{ {
xywh: bound.serialize(), xywh: bound.serialize(),
caption, caption,
...cloneReferenceInfoWithoutAliases(this.referenceInfo$.peek()), ...cloneReferenceInfoWithoutAliases(this.referenceInfo$.peek()),
}, },
// @ts-expect-error TODO: fix after edgeless refactor surface
edgelessService.surface
); );
this.std.command.exec('reassociateConnectors', { this.std.command.exec('reassociateConnectors', {
@@ -50,8 +51,7 @@ export class EmbedEdgelessLinkedDocBlockComponent extends toEdgelessEmbedBlock(
newId, newId,
}); });
// @ts-expect-error TODO: fix after edgeless refactor this.gfx.selection.set({
edgelessService.selection.set({
editing: false, editing: false,
elements: [newId], elements: [newId],
}); });
@@ -1,3 +1,4 @@
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
import type { AliasInfo } from '@blocksuite/affine-model'; import type { AliasInfo } from '@blocksuite/affine-model';
import { import {
EMBED_CARD_HEIGHT, EMBED_CARD_HEIGHT,
@@ -127,8 +128,9 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
return; return;
} }
// @ts-expect-error TODO: fix after edgeless refactor const { addBlock } = this.std.get(EdgelessCRUDIdentifier);
const newId = edgelessService.addBlock( const surface = this.gfx.surface ?? undefined;
const newId = addBlock(
'affine:embed-linked-doc', 'affine:embed-linked-doc',
{ {
xywh: bound.serialize(), xywh: bound.serialize(),
@@ -137,8 +139,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
...this.referenceInfo, ...this.referenceInfo,
...aliasInfo, ...aliasInfo,
}, },
// @ts-expect-error TODO: fix after edgeless refactor surface
edgelessService.surface
); );
this.std.command.exec('reassociateConnectors', { this.std.command.exec('reassociateConnectors', {
@@ -146,8 +147,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
newId, newId,
}); });
// @ts-expect-error TODO: fix after edgeless refactor this.gfx.selection.set({
edgelessService.selection.set({
editing: false, editing: false,
elements: [newId], elements: [newId],
}); });