mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-05 03:19:52 +08:00
1f45cc5dec
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
58 lines
1.7 KiB
TypeScript
58 lines
1.7 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/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;
|
|
},
|
|
});
|