mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 02:13:00 +08:00
Closes: [BS-3303](https://linear.app/affine-design/issue/BS-3303/改進-pack-attachment-props-流程) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced attachment and image uploads with improved file size validation and clearer notifications. - Upload telemetry tracking added for attachments to monitor upload success or failure. - **Refactor** - Streamlined and unified the process of adding attachments and images, making uploads more reliable and efficient. - Parameter names updated for clarity across attachment and image insertion features. - **Documentation** - Updated API documentation to reflect parameter name changes for consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { SurfaceBlockModel } from '@blocksuite/affine-block-surface';
|
|
import { FileDropConfigExtension } from '@blocksuite/affine-components/drop-indicator';
|
|
import { ImageBlockSchema, MAX_IMAGE_WIDTH } from '@blocksuite/affine-model';
|
|
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
|
import {
|
|
isInsideEdgelessEditor,
|
|
matchModels,
|
|
} from '@blocksuite/affine-shared/utils';
|
|
import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
|
|
|
|
import { addImages, addSiblingImageBlocks } from './utils.js';
|
|
|
|
export const ImageDropOption = FileDropConfigExtension({
|
|
flavour: ImageBlockSchema.model.flavour,
|
|
onDrop: ({ files, targetModel, placement, point, std }) => {
|
|
const imageFiles = files.filter(file => file.type.startsWith('image/'));
|
|
if (!imageFiles.length) return false;
|
|
|
|
if (targetModel && !matchModels(targetModel, [SurfaceBlockModel])) {
|
|
addSiblingImageBlocks(std, imageFiles, targetModel, placement).catch(
|
|
console.error
|
|
);
|
|
return true;
|
|
}
|
|
|
|
if (isInsideEdgelessEditor(std.host)) {
|
|
const gfx = std.get(GfxControllerIdentifier);
|
|
point = gfx.viewport.toViewCoordFromClientCoord(point);
|
|
addImages(std, files, { point, maxWidth: MAX_IMAGE_WIDTH })
|
|
.then(() => {
|
|
std.getOptional(TelemetryProvider)?.track('CanvasElementAdded', {
|
|
control: 'canvas:drop',
|
|
page: 'whiteboard editor',
|
|
module: 'toolbar',
|
|
segment: 'toolbar',
|
|
type: 'image',
|
|
});
|
|
})
|
|
.catch(console.error);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
},
|
|
});
|