From 6074584127bd1dc6ffaf8be182c6001cb78e75fd Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 2 Feb 2020 23:08:03 +0100 Subject: [PATCH] Trigger component:drag event in all DragModes --- src/commands/index.js | 2 ++ src/commands/view/ComponentDrag.js | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/commands/index.js b/src/commands/index.js index 0e9fa6ff5..1b6b3c5b1 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -162,6 +162,8 @@ export default () => { guidesInfo: 1, mode, target: sel, + onStart, + onDrag, onEnd, event }); diff --git a/src/commands/view/ComponentDrag.js b/src/commands/view/ComponentDrag.js index 3ccbcd8d9..3a89baf54 100644 --- a/src/commands/view/ComponentDrag.js +++ b/src/commands/view/ComponentDrag.js @@ -299,12 +299,22 @@ export default { target.addStyle(style, { avoidStore: !end }); }, + _getDragData() { + const { target } = this; + return { + target, + parent: target.parent(), + index: target.index() + }; + }, + onStart() { const { target, editor, isTran, opts } = this; - const { center } = opts; + const { center, onStart } = opts; const { Canvas } = editor; const style = target.getStyle(); const position = 'absolute'; + onStart && onStart(this._getDragData()); if (isTran) return; if (style.position !== position) { @@ -334,13 +344,13 @@ export default { opts.debug && guidesTarget.forEach(item => this.renderGuide(item)); opts.guidesInfo && this.renderGuideInfo(guidesTarget.filter(item => item.active)); - onDrag && onDrag(...args); + onDrag && onDrag(this._getDragData()); }, - onEnd(...args) { + onEnd(ev, dragger, opt = {}) { const { editor, opts, id } = this; const { onEnd } = opts; - onEnd && onEnd(...args); + onEnd && onEnd(ev, opt, { event: ev, ...opt, ...this._getDragData() }); editor.stopCommand(id); this.hideGuidesInfo(); this.em.trigger(`${evName}:end`, this.getEventOpts());