mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 17:46:18 +08:00
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { SurfaceBlockModel } from '@blocksuite/affine-block-surface';
|
|
import { FileDropConfigExtension } from '@blocksuite/affine-components/drop-indicator';
|
|
import { AttachmentBlockSchema } from '@blocksuite/affine-model';
|
|
import {
|
|
FileSizeLimitService,
|
|
TelemetryProvider,
|
|
} from '@blocksuite/affine-shared/services';
|
|
import {
|
|
isInsideEdgelessEditor,
|
|
matchModels,
|
|
} from '@blocksuite/affine-shared/utils';
|
|
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
|
|
|
import { addAttachments, addSiblingAttachmentBlocks } from './utils.js';
|
|
|
|
export const AttachmentDropOption = FileDropConfigExtension({
|
|
flavour: AttachmentBlockSchema.model.flavour,
|
|
onDrop: ({ files, targetModel, placement, point, std }) => {
|
|
// generic attachment block for all files except images
|
|
const attachmentFiles = files.filter(
|
|
file => !file.type.startsWith('image/')
|
|
);
|
|
if (!attachmentFiles.length) return false;
|
|
|
|
const maxFileSize = std.store.get(FileSizeLimitService).maxFileSize;
|
|
|
|
if (targetModel && !matchModels(targetModel, [SurfaceBlockModel])) {
|
|
addSiblingAttachmentBlocks(
|
|
std.host,
|
|
attachmentFiles,
|
|
maxFileSize,
|
|
targetModel,
|
|
placement
|
|
).catch(console.error);
|
|
|
|
return true;
|
|
}
|
|
|
|
if (isInsideEdgelessEditor(std.host)) {
|
|
const gfx = std.get(GfxControllerIdentifier);
|
|
point = gfx.viewport.toViewCoordFromClientCoord(point);
|
|
addAttachments(std, attachmentFiles, point).catch(console.error);
|
|
|
|
std.getOptional(TelemetryProvider)?.track('CanvasElementAdded', {
|
|
control: 'canvas:drop',
|
|
page: 'whiteboard editor',
|
|
module: 'toolbar',
|
|
segment: 'toolbar',
|
|
type: 'attachment',
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
},
|
|
});
|