Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(blocks): file drop manager supports files from other apps #7013

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions packages/blocks/src/_common/components/file-drop-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ export class FileDropManager {
onDragOver = (event: DragEvent) => {
event.preventDefault();

// allow only external drag-and-drop files
const effectAllowed = event.dataTransfer?.effectAllowed ?? 'none';
if (effectAllowed !== 'all') {
return;
}
const dataTransfer = event.dataTransfer;
if (!dataTransfer) return;

const effectAllowed = dataTransfer.effectAllowed;
if (effectAllowed === 'none') return;

const { clientX, clientY } = event;
const point = new Point(clientX, clientY);
Expand Down Expand Up @@ -149,26 +149,20 @@ export class FileDropManager {
this._indicator.rect = null;

const { onDrop } = this._fileDropOptions;
if (!onDrop) {
return;
}
if (!onDrop) return;

event.preventDefault();
const dataTransfer = event.dataTransfer;
if (!dataTransfer) return;

// allow only external drag-and-drop files
const effectAllowed = event.dataTransfer?.effectAllowed ?? 'none';
if (effectAllowed !== 'all') {
return;
}
const effectAllowed = dataTransfer.effectAllowed;
if (effectAllowed === 'none') return;

const droppedFiles = event.dataTransfer?.files;
if (!droppedFiles || !droppedFiles.length) {
return;
}
const droppedFiles = dataTransfer.files;
if (!droppedFiles || !droppedFiles.length) return;

const targetModel = this.targetModel;
const place = this.type;
event.preventDefault();

const { targetModel, type: place } = this;
const { clientX, clientY } = event;

onDrop({
Expand Down
Loading