refactor(editor): improve edgeless clipboard config (#11472)

This commit is contained in:
Saul-Mirone
2025-04-05 03:48:26 +00:00
parent 96e860caf3
commit 0fbca31c27
30 changed files with 492 additions and 451 deletions

View File

@@ -0,0 +1,25 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedFigmaConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-figma';
override createBlock(figmaEmbed: BlockSnapshot): string | null {
if (!this.surface) return null;
const { xywh, style, url, caption, title, description } = figmaEmbed.props;
const embedFigmaId = this.crud.addBlock(
'affine:embed-figma',
{
xywh,
style,
url,
caption,
title,
description,
},
this.surface.model.id
);
return embedFigmaId;
}
}

View File

@@ -1,4 +1,5 @@
export * from './adapters/index.js';
export * from './edgeless-clipboard-config';
export * from './embed-figma-block.js';
export * from './embed-figma-model.js';
export * from './embed-figma-spec.js';

View File

@@ -0,0 +1,51 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedGithubConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-github';
override createBlock(githubEmbed: BlockSnapshot): string | null {
if (!this.surface) return null;
const {
xywh,
style,
owner,
repo,
githubType,
githubId,
url,
caption,
image,
status,
statusReason,
title,
description,
createdAt,
assignees,
} = githubEmbed.props;
const embedGithubId = this.crud.addBlock(
'affine:embed-github',
{
xywh,
style,
owner,
repo,
githubType,
githubId,
url,
caption,
image,
status,
statusReason,
title,
description,
createdAt,
assignees,
},
this.surface.model.id
);
return embedGithubId;
}
}

View File

@@ -1,4 +1,5 @@
export * from './adapters/index.js';
export * from './edgeless-clipboard-config';
export * from './embed-github-block.js';
export * from './embed-github-service.js';
export * from './embed-github-spec.js';

View File

@@ -0,0 +1,24 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedHtmlConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-html';
override createBlock(htmlEmbed: BlockSnapshot): string | null {
if (!this.surface) return null;
const { xywh, style, caption, html, design } = htmlEmbed.props;
const embedHtmlId = this.crud.addBlock(
'affine:embed-html',
{
xywh,
style,
caption,
html,
design,
},
this.surface.model.id
);
return embedHtmlId;
}
}

View File

@@ -1,3 +1,4 @@
export * from './edgeless-clipboard-config';
export * from './embed-html-block.js';
export * from './embed-html-spec.js';
export {

View File

@@ -0,0 +1,37 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedIframeConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-iframe';
override createBlock(embedIframe: BlockSnapshot): string | null {
if (!this.surface) return null;
const {
xywh,
caption,
url,
title,
description,
iframeUrl,
scale,
width,
height,
} = embedIframe.props;
return this.crud.addBlock(
'affine:embed-iframe',
{
url,
iframeUrl,
xywh,
caption,
title,
description,
scale,
width,
height,
},
this.surface.model.id
);
}
}

View File

@@ -5,6 +5,7 @@ export {
EMBED_IFRAME_DEFAULT_HEIGHT_IN_SURFACE,
EMBED_IFRAME_DEFAULT_WIDTH_IN_SURFACE,
} from './consts';
export * from './edgeless-clipboard-config';
export * from './embed-iframe-block';
export * from './embed-iframe-spec';
export { canEmbedAsIframe } from './utils';

View File

@@ -0,0 +1,31 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { ReferenceInfoSchema } from '@blocksuite/affine-model';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedLinkedDocConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-linked-doc';
override createBlock(linkedDocEmbed: BlockSnapshot): string | null {
if (!this.surface) return null;
const { xywh, style, caption, pageId, params, title, description } =
linkedDocEmbed.props;
const referenceInfo = ReferenceInfoSchema.parse({
pageId,
params,
title,
description,
});
return this.crud.addBlock(
'affine:embed-linked-doc',
{
xywh,
style,
caption,
...referenceInfo,
},
this.surface.model.id
);
}
}

View File

@@ -1,5 +1,6 @@
export * from './adapters';
export * from './commands';
export { LinkedDocSlashMenuConfigIdentifier } from './configs/slash-menu';
export * from './edgeless-clipboard-config';
export * from './embed-linked-doc-block';
export * from './embed-linked-doc-spec';

View File

@@ -0,0 +1,28 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedLoomConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-loom';
override createBlock(loomEmbed: BlockSnapshot): string | null {
if (!this.surface) return null;
const { xywh, style, url, caption, videoId, image, title, description } =
loomEmbed.props;
const embedLoomId = this.crud.addBlock(
'affine:embed-loom',
{
xywh,
style,
url,
caption,
videoId,
image,
title,
description,
},
this.surface.model.id
);
return embedLoomId;
}
}

View File

@@ -1,4 +1,5 @@
export * from './adapters/index.js';
export * from './edgeless-clipboard-config';
export * from './embed-loom-block.js';
export * from './embed-loom-model.js';
export * from './embed-loom-service.js';

View File

@@ -0,0 +1,27 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { ReferenceInfoSchema } from '@blocksuite/affine-model';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedSyncedDocConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-synced-doc';
override createBlock(syncedDocEmbed: BlockSnapshot): string | null {
if (!this.surface) return null;
const { xywh, style, caption, scale, pageId, params } =
syncedDocEmbed.props;
const referenceInfo = ReferenceInfoSchema.parse({ pageId, params });
return this.crud.addBlock(
'affine:embed-synced-doc',
{
xywh,
style,
caption,
scale,
...referenceInfo,
},
this.surface.model.id
);
}
}

View File

@@ -1,4 +1,5 @@
export * from './adapters/index.js';
export * from './edgeless-clipboard-config';
export * from './embed-synced-doc-block.js';
export * from './embed-synced-doc-spec.js';
export { SYNCED_MIN_HEIGHT, SYNCED_MIN_WIDTH } from './styles.js';

View File

@@ -0,0 +1,42 @@
import { EdgelessClipboardConfig } from '@blocksuite/affine-block-surface';
import { type BlockSnapshot } from '@blocksuite/store';
export class EdgelessClipboardEmbedYoutubeConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:embed-youtube';
override createBlock(youtubeEmbed: BlockSnapshot): string | null {
if (!this.surface) return null;
const {
xywh,
style,
url,
caption,
videoId,
image,
title,
description,
creator,
creatorUrl,
creatorImage,
} = youtubeEmbed.props;
const embedYoutubeId = this.crud.addBlock(
'affine:embed-youtube',
{
xywh,
style,
url,
caption,
videoId,
image,
title,
description,
creator,
creatorUrl,
creatorImage,
},
this.surface.model.id
);
return embedYoutubeId;
}
}

View File

@@ -1,4 +1,5 @@
export * from './adapters/index.js';
export * from './edgeless-clipboard-config';
export * from './embed-youtube-block.js';
export * from './embed-youtube-model.js';
export * from './embed-youtube-service.js';