mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 20:41:50 +08:00
c43e1bcc4e
<!-- 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 -->
59 lines
1.7 KiB
TypeScript
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);
|
|
},
|
|
},
|
|
],
|
|
};
|