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(dnd): add configurable dataTransferProperty to droppable #213

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 6 additions & 5 deletions src/utils/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ const retval = (fn, ...args) => {
return true;
};

const getDataTransfer = (ev, type) => {
const getDataTransfer = (ev, type, dataTransferProperty) => {
let files = [];
let data;

if (ev.dataTransfer) {
files = ev.dataTransfer.files
? Array.from(ev.dataTransfer.files)
files = ev.dataTransfer[dataTransferProperty]
? Array.from(ev.dataTransfer[dataTransferProperty])
: [];

try {
Expand Down Expand Up @@ -200,9 +200,10 @@ export const draggable = (el, options = {}) => {
* @return {DroppableInstance}
*/
export const droppable = (el, options = {}) => {
const {strict, type, effect, ondragenter, ondragover, ondragleave, ondrop} = {
const {strict, type, effect, dataTransferProperty, ondragenter, ondragover, ondragleave, ondrop} = {
type: 'application/json',
effect: 'move',
dataTransferProperty: 'files',
ondragenter: () => true,
ondragover: () => true,
ondragleave: () => true,
Expand Down Expand Up @@ -241,7 +242,7 @@ export const droppable = (el, options = {}) => {
return false;
}

const {files, data} = getDataTransfer(ev, type);
const {files, data} = getDataTransfer(ev, type, dataTransferProperty);

ev.stopPropagation();
ev.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions src/utils/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const createAttributes = attrs => ({
shadowDOM: false,
clamp: true,
droppable: true,
droppableDataTransferProperty: 'files',
andersevenrud marked this conversation as resolved.
Show resolved Hide resolved
mediaQueries: {
small: 'screen and (max-width: 640px)',
medium: 'screen and (min-width: 640px) and (max-width: 1024px)',
Expand Down
3 changes: 2 additions & 1 deletion src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ export default class Window extends EventEmitter {
ondragenter: (...args) => this.emit('dragenter', ...args, this),
ondragover: (...args) => this.emit('dragover', ...args, this),
ondragleave: (...args) => this.emit('dragleave', ...args, this),
ondrop: (...args) => this.emit('drop', ...args, this)
ondrop: (...args) => this.emit('drop', ...args, this),
dataTransferProperty: this.attributes.droppableDataTransferProperty,
});

this.on('destroy', () => d.destroy());
Expand Down
Loading