diff --git a/blocksuite/affine/block-attachment/src/utils.ts b/blocksuite/affine/block-attachment/src/utils.ts index defd2e4206..85a7c74fdf 100644 --- a/blocksuite/affine/block-attachment/src/utils.ts +++ b/blocksuite/affine/block-attachment/src/utils.ts @@ -215,7 +215,8 @@ export async function addSiblingAttachmentBlocks( files: File[], maxFileSize: number, targetModel: BlockModel, - place: 'before' | 'after' = 'after' + place: 'before' | 'after' = 'after', + isEmbed?: boolean ) { if (!files.length) { return; @@ -245,6 +246,7 @@ export async function addSiblingAttachmentBlocks( name: file.name, size: file.size, type: types[index], + embed: isEmbed, })); const blockIds = doc.addSiblingBlocks( diff --git a/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts b/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts index 3d0d3efae8..0aeb6125ec 100644 --- a/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts +++ b/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts @@ -62,6 +62,7 @@ import { viewPresets } from '@blocksuite/data-view/view-presets'; import { assertType } from '@blocksuite/global/utils'; import { DualLinkIcon, + ExportToPdfIcon, GroupingIcon, TableIcon, TeXIcon, @@ -345,6 +346,31 @@ export const defaultSlashMenuConfig: SlashMenuConfig = { tryRemoveEmptyLine(model); }, }, + { + name: 'PDF', + description: 'Upload a PDF to document.', + icon: ExportToPdfIcon({ width: '20', height: '20' }), + tooltip: slashMenuToolTips['PDF'], + showWhen: ({ model }) => + model.doc.schema.flavourSchemaMap.has('affine:attachment'), + action: async ({ rootComponent, model }) => { + const file = await openFileOrFiles(); + if (!file) return; + + const maxFileSize = + rootComponent.std.store.get(FileSizeLimitService).maxFileSize; + + await addSiblingAttachmentBlocks( + rootComponent.host, + [file], + maxFileSize, + model, + 'after', + true + ); + tryRemoveEmptyLine(model); + }, + }, { name: 'YouTube', description: 'Embed a YouTube video.', diff --git a/blocksuite/blocks/src/root-block/widgets/slash-menu/tooltips/index.ts b/blocksuite/blocks/src/root-block/widgets/slash-menu/tooltips/index.ts index 834d8b9840..c1b7e795e4 100644 --- a/blocksuite/blocks/src/root-block/widgets/slash-menu/tooltips/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/slash-menu/tooltips/index.ts @@ -26,6 +26,7 @@ import { MoveUpTooltip } from './move-up.js'; import { NewDocTooltip } from './new-doc.js'; import { NowTooltip } from './now.js'; import { NumberedListTooltip } from './numbered-list.js'; +import { PDFTooltip } from './pdf.js'; import { PhotoTooltip } from './photo.js'; import { QuoteTooltip } from './quote.js'; import { StrikethroughTooltip } from './strikethrough.js'; @@ -150,6 +151,11 @@ export const slashMenuToolTips: Record = { caption: 'Attachment', }, + PDF: { + figure: PDFTooltip, + caption: 'PDF', + }, + Github: { figure: GithubRepoTooltip, caption: 'GitHub Repo', diff --git a/blocksuite/blocks/src/root-block/widgets/slash-menu/tooltips/pdf.ts b/blocksuite/blocks/src/root-block/widgets/slash-menu/tooltips/pdf.ts new file mode 100644 index 0000000000..3f37191846 --- /dev/null +++ b/blocksuite/blocks/src/root-block/widgets/slash-menu/tooltips/pdf.ts @@ -0,0 +1,36 @@ +import { html } from 'lit'; +// prettier-ignore +export const PDFTooltip = html` + + + + + + + + + + + + + + + +Rickroll.pdf + +Upload a pdf to document. + + + + + + + + + + + + + + +`; diff --git a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/can-insert-attachment-from-slash-menu.json b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/can-insert-attachment-from-slash-menu.json index bb3fac3be0..123e7a07c0 100644 --- a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/can-insert-attachment-from-slash-menu.json +++ b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/can-insert-attachment-from-slash-menu.json @@ -44,13 +44,13 @@ "name": "test-card-1.png", "size": 45801, "type": "image/png", - "embed": false, "style": "horizontalThin", "index": "a0", "xywh": "[0,0,0,0]", "lockedBySelf": false, "rotate": 0, - "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=" + "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=", + "embed": false }, "children": [] } diff --git a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-1.json b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-1.json index bb3fac3be0..123e7a07c0 100644 --- a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-1.json +++ b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-1.json @@ -44,13 +44,13 @@ "name": "test-card-1.png", "size": 45801, "type": "image/png", - "embed": false, "style": "horizontalThin", "index": "a0", "xywh": "[0,0,0,0]", "lockedBySelf": false, "rotate": 0, - "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=" + "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=", + "embed": false }, "children": [] } diff --git a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-3.json b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-3.json index bb3fac3be0..1db30ca3bc 100644 --- a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-3.json +++ b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/should-undo-redo-works-for-attachment-3.json @@ -44,12 +44,12 @@ "name": "test-card-1.png", "size": 45801, "type": "image/png", - "embed": false, "style": "horizontalThin", "index": "a0", "xywh": "[0,0,0,0]", "lockedBySelf": false, "rotate": 0, + "embed": false, "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=" }, "children": [] diff --git a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-1.json b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-1.json index bb3fac3be0..123e7a07c0 100644 --- a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-1.json +++ b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-1.json @@ -44,13 +44,13 @@ "name": "test-card-1.png", "size": 45801, "type": "image/png", - "embed": false, "style": "horizontalThin", "index": "a0", "xywh": "[0,0,0,0]", "lockedBySelf": false, "rotate": 0, - "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=" + "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=", + "embed": false }, "children": [] } diff --git a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-2.json b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-2.json index 10f23da147..6201b4b029 100644 --- a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-2.json +++ b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-2.json @@ -44,13 +44,13 @@ "name": "test-card-1.png", "size": 45801, "type": "image/png", - "embed": false, "style": "horizontalThin", "index": "a0", "xywh": "[0,0,0,0]", "lockedBySelf": false, "rotate": 0, - "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=" + "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=", + "embed": false }, "children": [] }, diff --git a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-3.json b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-3.json index 6f8cf6c9e3..dbc9bf4e49 100644 --- a/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-3.json +++ b/blocksuite/tests-legacy/snapshots/attachment.spec.ts/support-dragging-attachment-block-directly-3.json @@ -82,13 +82,13 @@ "name": "test-card-1.png", "size": 45801, "type": "image/png", - "embed": false, "style": "horizontalThin", "index": "a0", "xywh": "[0,0,0,0]", "lockedBySelf": false, "rotate": 0, - "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=" + "sourceId": "ejImogf-Tb7AuKY-v94uz1zuOJbClqK-tWBxVr_ksGA=", + "embed": false }, "children": [] },