Browse Source

Update content on handleDrop in Droppable

pull/2062/head
Artur Arseniev 7 years ago
parent
commit
b1dea5213c
  1. 23
      src/utils/Droppable.js

23
src/utils/Droppable.js

@ -55,13 +55,13 @@ export default class Droppable {
this.over = 1; this.over = 1;
const utils = em.get('Utils'); const utils = em.get('Utils');
const canvas = em.get('Canvas'); const canvas = em.get('Canvas');
const container = canvas.getBody();
// For security reason I can't read the drag data on dragenter, but // For security reason I can't read the drag data on dragenter, but
// as I need it for the Sorter context I will use `dragContent` or just // as I need it for the Sorter context I will use `dragContent` or just
// any not empty element // any not empty element
const content = em.get('dragContent') || '<br>'; let content = em.get('dragContent') || '<br>';
const container = canvas.getBody(); let dragStop, dragContent;
em.stopDefault(); em.stopDefault();
let dragStop;
if (em.inAbsoluteMode()) { if (em.inAbsoluteMode()) {
const wrapper = em.get('DomComponents').getWrapper(); const wrapper = em.get('DomComponents').getWrapper();
@ -82,6 +82,7 @@ export default class Droppable {
} }
}); });
dragStop = cancel => dragger.stop(ev, { cancel }); dragStop = cancel => dragger.stop(ev, { cancel });
dragContent = cnt => (content = cnt);
} else { } else {
const sorter = new utils.Sorter({ const sorter = new utils.Sorter({
em, em,
@ -104,9 +105,11 @@ export default class Droppable {
cancel && (sorter.moved = 0); cancel && (sorter.moved = 0);
sorter.endMove(); sorter.endMove();
}; };
dragContent = content => sorter.setDropContent(content);
} }
this.dragStop = dragStop; this.dragStop = dragStop;
this.dragContent = dragContent;
em.trigger('canvas:dragenter', dt, content); em.trigger('canvas:dragenter', dt, content);
} }
@ -128,20 +131,12 @@ export default class Droppable {
handleDrop(ev) { handleDrop(ev) {
ev.preventDefault(); ev.preventDefault();
const { sorter } = this; const { dragContent } = this;
const dt = ev.dataTransfer; const dt = ev.dataTransfer;
const content = this.getContentByData(dt).content; const content = this.getContentByData(dt).content;
ev.target.style.border = ''; ev.target.style.border = '';
content && dragContent && dragContent(content);
if (sorter) { this.endDrop(!content, ev);
if (content) {
sorter.setDropContent(content);
} else {
sorter.moved = 0;
}
}
this.endDrop(0, ev);
} }
getContentByData(dataTransfer) { getContentByData(dataTransfer) {

Loading…
Cancel
Save