Files
AFFiNE-Mirror/blocksuite/affine/blocks/attachment/src/configs/slash-menu.ts
T
fundon c43e1bcc4e refactor(editor): split openFileOrFiles into openSingleFileWith and openFilesWith (#12523)
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Improved file selection dialogs for attachments, imports, and uploads, allowing for more consistent and streamlined file picking across the app.

- **Bug Fixes**
	- Resolved inconsistencies when selecting single or multiple files, ensuring a smoother user experience during file import and upload.

- **Refactor**
	- Unified and simplified file selection logic throughout the app for better reliability and maintainability.
	- Standardized import functions to uniformly handle arrays of files, enhancing consistency in file processing.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-28 03:06:33 +00:00

59 lines
1.7 KiB
TypeScript

import { openSingleFileWith } from '@blocksuite/affine-shared/utils';
import { type SlashMenuConfig } from '@blocksuite/affine-widget-slash-menu';
import { ExportToPdfIcon, FileIcon } from '@blocksuite/icons/lit';
import { addSiblingAttachmentBlocks } from '../utils';
import { AttachmentTooltip, PDFTooltip } from './tooltips';
export const attachmentSlashMenuConfig: SlashMenuConfig = {
items: [
{
name: 'Attachment',
description: 'Attach a file to document.',
icon: FileIcon(),
tooltip: {
figure: AttachmentTooltip,
caption: 'Attachment',
},
searchAlias: ['file'],
group: '4_Content & Media@3',
when: ({ model }) =>
model.store.schema.flavourSchemaMap.has('affine:attachment'),
action: ({ std, model }) => {
(async () => {
const file = await openSingleFileWith();
if (!file) return;
await addSiblingAttachmentBlocks(std, [file], model);
if (model.text?.length === 0) {
std.store.deleteBlock(model);
}
})().catch(console.error);
},
},
{
name: 'PDF',
description: 'Upload a PDF to document.',
icon: ExportToPdfIcon(),
tooltip: {
figure: PDFTooltip,
caption: 'PDF',
},
group: '4_Content & Media@4',
when: ({ model }) =>
model.store.schema.flavourSchemaMap.has('affine:attachment'),
action: ({ std, model }) => {
(async () => {
const file = await openSingleFileWith();
if (!file) return;
await addSiblingAttachmentBlocks(std, [file], model);
if (model.text?.length === 0) {
std.store.deleteBlock(model);
}
})().catch(console.error);
},
},
],
};