@interactjs/actions
Advanced tools
Comparing version 1.9.20 to 1.9.21
import { Interactable } from "../../core/Interactable.js"; | ||
import { Scope } from "../../core/scope.js"; | ||
import * as domUtils from "../../utils/domUtils.js"; | ||
@@ -63,3 +62,3 @@ import extend from "../../utils/extend.js"; | ||
* @param {boolean | object | null} [options] The new options to be set. | ||
* @return {boolean | Interactable} The current setting or this Interactable | ||
* @return {object | Interactable} The current setting or this Interactable | ||
*/ | ||
@@ -282,2 +281,6 @@ | ||
if (events.enter) { | ||
cur.dropzone.fire(events.enter); | ||
} | ||
if (events.move) { | ||
@@ -287,6 +290,2 @@ cur.dropzone.fire(events.move); | ||
if (events.enter) { | ||
cur.dropzone.fire(events.enter); | ||
} | ||
if (events.drop) { | ||
@@ -488,9 +487,7 @@ cur.dropzone.fire(events.drop); | ||
}, | ||
// FIXME proper signal types | ||
'interactions:action-move': onEventCreated, | ||
'interactions:action-end': onEventCreated, | ||
'interactions:after-action-move': function fireDropAfterMove({ | ||
'interactions:after-action-move': ({ | ||
interaction, | ||
iEvent: dragEvent | ||
}, scope) { | ||
}, scope) => { | ||
if (interaction.prepared.name !== 'drag') { | ||
@@ -507,10 +504,12 @@ return; | ||
}, | ||
'interactions:after-action-end': ({ | ||
interaction, | ||
iEvent: dragEvent | ||
}, scope) => { | ||
if (interaction.prepared.name !== 'drag') { | ||
'interactions:action-end': (arg, scope) => { | ||
if (arg.interaction.prepared.name !== 'drag') { | ||
return; | ||
} | ||
const { | ||
interaction, | ||
iEvent: dragEvent | ||
} = arg; | ||
onEventCreated(arg, scope); | ||
fireDropEvents(interaction, interaction.dropState.events); | ||
@@ -517,0 +516,0 @@ scope.fire('actions/drop:end', { |
@@ -1,2 +0,2 @@ | ||
import{Interactable as e}from"../../core/Interactable.min.js";import{Scope as t}from"../../core/scope.min.js";import*as o from"../../utils/domUtils.min.js";import r from"../../utils/extend.min.js";import n from"../../utils/getOriginXY.min.js";import a from"../../utils/is.min.js";import i from"../../utils/normalizeListeners.min.js";import*as p from"../../utils/pointerUtils.min.js";import c from"../drag/plugin.min.js";import{DropEvent as d}from"./DropEvent.min.js";function l(e,t){for(const{dropzone:o,element:r}of e.slice())t.dropzone=o,t.target=r,o.fire(t),t.propagationStopped=t.immediatePropagationStopped=!1}function s(e,t){const r=function({interactables:e},t){const r=[];for(const n of e.list){if(!n.options.drop.enabled)continue;const e=n.options.drop.accept;if(a.element(e)&&e!==t||a.string(e)&&!o.matchesSelector(t,e)||a.func(e)&&!e({dropzone:n,draggableElement:t}))continue;const i=a.string(n.target)?n._context.querySelectorAll(n.target):a.array(n.target)?n.target:[n.target];for(const e of i)e!==t&&r.push({dropzone:n,element:e})}return r}(e,t);for(const e of r)e.rect=e.dropzone.getRect(e.element);return r}function v({dropState:e,interactable:t,element:r},n,a){const i=[];for(const{dropzone:o,element:p,rect:c}of e.activeDrops)i.push(o.dropCheck(n,a,t,r,p,c)?p:null);const p=o.indexOfDeepestElement(i);return e.activeDrops[p]||null}function m(e,t,o){const{dropState:r}=e,n={enter:null,leave:null,activate:null,deactivate:null,move:null,drop:null};return"dragstart"===o.type&&(n.activate=new d(r,o,"dropactivate"),n.activate.target=null,n.activate.dropzone=null),"dragend"===o.type&&(n.deactivate=new d(r,o,"dropdeactivate"),n.deactivate.target=null,n.deactivate.dropzone=null),r.rejected||(r.cur.element!==r.prev.element&&(r.prev.dropzone&&(n.leave=new d(r,o,"dragleave"),o.dragLeave=n.leave.target=r.prev.element,o.prevDropzone=n.leave.dropzone=r.prev.dropzone),r.cur.dropzone&&(n.enter=new d(r,o,"dragenter"),o.dragEnter=r.cur.element,o.dropzone=r.cur.dropzone)),"dragend"===o.type&&r.cur.dropzone&&(n.drop=new d(r,o,"drop"),o.dropzone=r.cur.dropzone,o.relatedTarget=r.cur.element),"dragmove"===o.type&&r.cur.dropzone&&(n.move=new d(r,o,"dropmove"),n.move.dragmove=o,o.dropzone=r.cur.dropzone)),n}function u(e,t){const{dropState:o}=e,{activeDrops:r,cur:n,prev:a}=o;t.leave&&a.dropzone.fire(t.leave),t.move&&n.dropzone.fire(t.move),t.enter&&n.dropzone.fire(t.enter),t.drop&&n.dropzone.fire(t.drop),t.deactivate&&l(r,t.deactivate),o.prev.dropzone=n.dropzone,o.prev.element=n.element}function f({interaction:e,iEvent:t,event:o},r){if("dragmove"!==t.type&&"dragend"!==t.type)return;const{dropState:n}=e;r.dynamicDrop&&(n.activeDrops=s(r,e.element));const a=t,i=v(e,a,o);n.rejected=n.rejected&&!!i&&i.dropzone===n.cur.dropzone&&i.element===n.cur.element,n.cur.dropzone=i&&i.dropzone,n.cur.element=i&&i.element,n.events=m(e,0,a)}const g={id:"actions/drop",install(e){const{actions:t,interactStatic:o,Interactable:d,defaults:l}=e;e.usePlugin(c),d.prototype.dropzone=function(e){return function(e,t){if(a.object(t)){if(e.options.drop.enabled=!1!==t.enabled,t.listeners){const o=i(t.listeners),r=Object.keys(o).reduce((e,t)=>(e[/^(enter|leave)/.test(t)?"drag"+t:/^(activate|deactivate|move)/.test(t)?"drop"+t:t]=o[t],e),{});e.off(e.options.drop.listeners),e.on(r),e.options.drop.listeners=r}return a.func(t.ondrop)&&e.on("drop",t.ondrop),a.func(t.ondropactivate)&&e.on("dropactivate",t.ondropactivate),a.func(t.ondropdeactivate)&&e.on("dropdeactivate",t.ondropdeactivate),a.func(t.ondragenter)&&e.on("dragenter",t.ondragenter),a.func(t.ondragleave)&&e.on("dragleave",t.ondragleave),a.func(t.ondropmove)&&e.on("dropmove",t.ondropmove),/^(pointer|center)$/.test(t.overlap)?e.options.drop.overlap=t.overlap:a.number(t.overlap)&&(e.options.drop.overlap=Math.max(Math.min(1,t.overlap),0)),"accept"in t&&(e.options.drop.accept=t.accept),"checker"in t&&(e.options.drop.checker=t.checker),e}if(a.bool(t))return e.options.drop.enabled=t,e;return e.options.drop}(this,e)},d.prototype.dropCheck=function(e,t,o,r,i,c){return function(e,t,o,r,i,c,d){let l=!1;if(!(d=d||e.getRect(c)))return!!e.options.drop.checker&&e.options.drop.checker(t,o,l,e,c,r,i);const s=e.options.drop.overlap;if("pointer"===s){const e=n(r,i,"drag"),o=p.getPageXY(t);o.x+=e.x,o.y+=e.y;const a=o.x>d.left&&o.x<d.right,c=o.y>d.top&&o.y<d.bottom;l=a&&c}const v=r.getRect(i);if(v&&"center"===s){const e=v.left+v.width/2,t=v.top+v.height/2;l=e>=d.left&&e<=d.right&&t>=d.top&&t<=d.bottom}if(v&&a.number(s)){const e=Math.max(0,Math.min(d.right,v.right)-Math.max(d.left,v.left))*Math.max(0,Math.min(d.bottom,v.bottom)-Math.max(d.top,v.top))/(v.width*v.height);l=e>=s}e.options.drop.checker&&(l=e.options.drop.checker(t,o,l,e,c,r,i));return l}(this,e,t,o,r,i,c)},o.dynamicDrop=t=>a.bool(t)?(e.dynamicDrop=t,o):e.dynamicDrop,r(t.phaselessTypes,{dragenter:!0,dragleave:!0,dropactivate:!0,dropdeactivate:!0,dropmove:!0,drop:!0}),t.methodDict.drop="dropzone",e.dynamicDrop=!1,l.actions.drop=g.defaults},listeners:{"interactions:before-action-start"({interaction:e}){"drag"===e.prepared.name&&(e.dropState={cur:{dropzone:null,element:null},prev:{dropzone:null,element:null},rejected:null,events:null,activeDrops:[]})},"interactions:after-action-start"({interaction:e,event:t,iEvent:o},r){if("drag"!==e.prepared.name)return;const{dropState:n}=e;n.activeDrops=null,n.events=null,n.activeDrops=s(r,e.element),n.events=m(e,0,o),n.events.activate&&(l(n.activeDrops,n.events.activate),r.fire("actions/drop:start",{interaction:e,dragEvent:o}))},"interactions:action-move":f,"interactions:action-end":f,"interactions:after-action-move"({interaction:e,iEvent:t},o){"drag"===e.prepared.name&&(u(e,e.dropState.events),o.fire("actions/drop:move",{interaction:e,dragEvent:t}),e.dropState.events={})},"interactions:after-action-end"({interaction:e,iEvent:t},o){"drag"===e.prepared.name&&(u(e,e.dropState.events),o.fire("actions/drop:end",{interaction:e,dragEvent:t}))},"interactions:stop"({interaction:e}){if("drag"!==e.prepared.name)return;const{dropState:t}=e;t&&(t.activeDrops=null,t.events=null,t.cur.dropzone=null,t.cur.element=null,t.prev.dropzone=null,t.prev.element=null,t.rejected=!1)}},getActiveDrops:s,getDrop:v,getDropEvents:m,fireDropEvents:u,defaults:{enabled:!1,accept:null,overlap:"pointer"}};export default g; | ||
import{Interactable as e}from"../../core/Interactable.min.js";import*as t from"../../utils/domUtils.min.js";import o from"../../utils/extend.min.js";import r from"../../utils/getOriginXY.min.js";import n from"../../utils/is.min.js";import a from"../../utils/normalizeListeners.min.js";import*as i from"../../utils/pointerUtils.min.js";import p from"../drag/plugin.min.js";import{DropEvent as c}from"./DropEvent.min.js";function d(e,t){for(const{dropzone:o,element:r}of e.slice())t.dropzone=o,t.target=r,o.fire(t),t.propagationStopped=t.immediatePropagationStopped=!1}function l(e,o){const r=function({interactables:e},o){const r=[];for(const a of e.list){if(!a.options.drop.enabled)continue;const e=a.options.drop.accept;if(n.element(e)&&e!==o||n.string(e)&&!t.matchesSelector(o,e)||n.func(e)&&!e({dropzone:a,draggableElement:o}))continue;const i=n.string(a.target)?a._context.querySelectorAll(a.target):n.array(a.target)?a.target:[a.target];for(const e of i)e!==o&&r.push({dropzone:a,element:e})}return r}(e,o);for(const e of r)e.rect=e.dropzone.getRect(e.element);return r}function s({dropState:e,interactable:o,element:r},n,a){const i=[];for(const{dropzone:t,element:p,rect:c}of e.activeDrops)i.push(t.dropCheck(n,a,o,r,p,c)?p:null);const p=t.indexOfDeepestElement(i);return e.activeDrops[p]||null}function v(e,t,o){const{dropState:r}=e,n={enter:null,leave:null,activate:null,deactivate:null,move:null,drop:null};return"dragstart"===o.type&&(n.activate=new c(r,o,"dropactivate"),n.activate.target=null,n.activate.dropzone=null),"dragend"===o.type&&(n.deactivate=new c(r,o,"dropdeactivate"),n.deactivate.target=null,n.deactivate.dropzone=null),r.rejected||(r.cur.element!==r.prev.element&&(r.prev.dropzone&&(n.leave=new c(r,o,"dragleave"),o.dragLeave=n.leave.target=r.prev.element,o.prevDropzone=n.leave.dropzone=r.prev.dropzone),r.cur.dropzone&&(n.enter=new c(r,o,"dragenter"),o.dragEnter=r.cur.element,o.dropzone=r.cur.dropzone)),"dragend"===o.type&&r.cur.dropzone&&(n.drop=new c(r,o,"drop"),o.dropzone=r.cur.dropzone,o.relatedTarget=r.cur.element),"dragmove"===o.type&&r.cur.dropzone&&(n.move=new c(r,o,"dropmove"),n.move.dragmove=o,o.dropzone=r.cur.dropzone)),n}function m(e,t){const{dropState:o}=e,{activeDrops:r,cur:n,prev:a}=o;t.leave&&a.dropzone.fire(t.leave),t.enter&&n.dropzone.fire(t.enter),t.move&&n.dropzone.fire(t.move),t.drop&&n.dropzone.fire(t.drop),t.deactivate&&d(r,t.deactivate),o.prev.dropzone=n.dropzone,o.prev.element=n.element}function u({interaction:e,iEvent:t,event:o},r){if("dragmove"!==t.type&&"dragend"!==t.type)return;const{dropState:n}=e;r.dynamicDrop&&(n.activeDrops=l(r,e.element));const a=t,i=s(e,a,o);n.rejected=n.rejected&&!!i&&i.dropzone===n.cur.dropzone&&i.element===n.cur.element,n.cur.dropzone=i&&i.dropzone,n.cur.element=i&&i.element,n.events=v(e,0,a)}const f={id:"actions/drop",install(e){const{actions:t,interactStatic:c,Interactable:d,defaults:l}=e;e.usePlugin(p),d.prototype.dropzone=function(e){return function(e,t){if(n.object(t)){if(e.options.drop.enabled=!1!==t.enabled,t.listeners){const o=a(t.listeners),r=Object.keys(o).reduce((e,t)=>(e[/^(enter|leave)/.test(t)?"drag"+t:/^(activate|deactivate|move)/.test(t)?"drop"+t:t]=o[t],e),{});e.off(e.options.drop.listeners),e.on(r),e.options.drop.listeners=r}return n.func(t.ondrop)&&e.on("drop",t.ondrop),n.func(t.ondropactivate)&&e.on("dropactivate",t.ondropactivate),n.func(t.ondropdeactivate)&&e.on("dropdeactivate",t.ondropdeactivate),n.func(t.ondragenter)&&e.on("dragenter",t.ondragenter),n.func(t.ondragleave)&&e.on("dragleave",t.ondragleave),n.func(t.ondropmove)&&e.on("dropmove",t.ondropmove),/^(pointer|center)$/.test(t.overlap)?e.options.drop.overlap=t.overlap:n.number(t.overlap)&&(e.options.drop.overlap=Math.max(Math.min(1,t.overlap),0)),"accept"in t&&(e.options.drop.accept=t.accept),"checker"in t&&(e.options.drop.checker=t.checker),e}if(n.bool(t))return e.options.drop.enabled=t,e;return e.options.drop}(this,e)},d.prototype.dropCheck=function(e,t,o,a,p,c){return function(e,t,o,a,p,c,d){let l=!1;if(!(d=d||e.getRect(c)))return!!e.options.drop.checker&&e.options.drop.checker(t,o,l,e,c,a,p);const s=e.options.drop.overlap;if("pointer"===s){const e=r(a,p,"drag"),o=i.getPageXY(t);o.x+=e.x,o.y+=e.y;const n=o.x>d.left&&o.x<d.right,c=o.y>d.top&&o.y<d.bottom;l=n&&c}const v=a.getRect(p);if(v&&"center"===s){const e=v.left+v.width/2,t=v.top+v.height/2;l=e>=d.left&&e<=d.right&&t>=d.top&&t<=d.bottom}if(v&&n.number(s)){const e=Math.max(0,Math.min(d.right,v.right)-Math.max(d.left,v.left))*Math.max(0,Math.min(d.bottom,v.bottom)-Math.max(d.top,v.top))/(v.width*v.height);l=e>=s}e.options.drop.checker&&(l=e.options.drop.checker(t,o,l,e,c,a,p));return l}(this,e,t,o,a,p,c)},c.dynamicDrop=t=>n.bool(t)?(e.dynamicDrop=t,c):e.dynamicDrop,o(t.phaselessTypes,{dragenter:!0,dragleave:!0,dropactivate:!0,dropdeactivate:!0,dropmove:!0,drop:!0}),t.methodDict.drop="dropzone",e.dynamicDrop=!1,l.actions.drop=f.defaults},listeners:{"interactions:before-action-start"({interaction:e}){"drag"===e.prepared.name&&(e.dropState={cur:{dropzone:null,element:null},prev:{dropzone:null,element:null},rejected:null,events:null,activeDrops:[]})},"interactions:after-action-start"({interaction:e,event:t,iEvent:o},r){if("drag"!==e.prepared.name)return;const{dropState:n}=e;n.activeDrops=null,n.events=null,n.activeDrops=l(r,e.element),n.events=v(e,0,o),n.events.activate&&(d(n.activeDrops,n.events.activate),r.fire("actions/drop:start",{interaction:e,dragEvent:o}))},"interactions:action-move":u,"interactions:after-action-move"({interaction:e,iEvent:t},o){"drag"===e.prepared.name&&(m(e,e.dropState.events),o.fire("actions/drop:move",{interaction:e,dragEvent:t}),e.dropState.events={})},"interactions:action-end"(e,t){if("drag"!==e.interaction.prepared.name)return;const{interaction:o,iEvent:r}=e;u(e,t),m(o,o.dropState.events),t.fire("actions/drop:end",{interaction:o,dragEvent:r})},"interactions:stop"({interaction:e}){if("drag"!==e.prepared.name)return;const{dropState:t}=e;t&&(t.activeDrops=null,t.events=null,t.cur.dropzone=null,t.cur.element=null,t.prev.dropzone=null,t.prev.element=null,t.rejected=!1)}},getActiveDrops:l,getDrop:s,getDropEvents:v,fireDropEvents:m,defaults:{enabled:!1,accept:null,overlap:"pointer"}};export default f; | ||
//# sourceMappingURL=plugin.min.js.map |
{ | ||
"name": "@interactjs/actions", | ||
"version": "1.9.20", | ||
"version": "1.9.21", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"@interactjs/core": "1.9.20", | ||
"@interactjs/utils": "1.9.20" | ||
"@interactjs/core": "1.9.21", | ||
"@interactjs/utils": "1.9.21" | ||
}, | ||
"optionalDependencies": { | ||
"@interactjs/interact": "1.9.20" | ||
"@interactjs/interact": "1.9.21" | ||
}, | ||
@@ -12,0 +12,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
239150
1335