diff --git a/lib/ds.min.js b/src/lib/ds.min.js similarity index 99% rename from lib/ds.min.js rename to src/lib/ds.min.js index 75dba6f..e620a2a 100644 --- a/lib/ds.min.js +++ b/src/lib/ds.min.js @@ -1 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DragSelect=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:0;return{left:e.x,top:e.y,right:e.x,bottom:e.y,width:t,height:t}},D=function(){var e,t,n,r;return{y:(null===(e=document.body)||void 0===e?void 0:e.scrollTop)||(null===(t=document.documentElement)||void 0===t?void 0:t.scrollTop)||0,x:(null===(n=document.body)||void 0===n?void 0:n.scrollLeft)||(null===(r=document.documentElement)||void 0===r?void 0:r.scrollLeft)||0}},P=function(e){return!e||e instanceof Document?D():{x:e.scrollLeft>=0?e.scrollLeft:D().x,y:e.scrollTop>=0?e.scrollTop:D().y}},E=function(e){var t=e.elementRect,n=e.containerRect,r=e.tolerance,i=void 0===r?{x:0,y:0}:r,o=[];return t.top-i.yn.bottom&&o.push("bottom"),t.right+i.y>n.right&&o.push("right"),o},w=function(e){var t={x:0,y:0},n=window.getComputedStyle(e);if(!n.transform||"none"===n.transform)return t;if(n.transform.indexOf("3d")>=0){var r=n.transform.trim().match(/matrix3d\((.*?)\)/);if(r&&r.length){var i,o=null===(i=r[1])||void 0===i?void 0:i.split(",");t.x=parseInt(o[12])||0,t.y=parseInt(o[13])||0}return t}var s=n.transform.trim().match(/matrix\((.*?)\)/);if(s&&s.length){var a,l=null===(a=s[1])||void 0===a?void 0:a.split(",");t.x=parseInt(l[4])||0,t.y=parseInt(l[5])||0}return t},k=function(e,t){return t?function(e){var t=e.style.transform;if(!t||t.indexOf("translate")<0)return w(e);var n={x:0,y:0},r=t.trim().match(/translate[3dD]*?\(.*?\)/);if(r){var i,o=null===(i=r[0])||void 0===i?void 0:i.split("(");if(o){var s,a=null===(s=o[1])||void 0===s?void 0:s.split(",");n.x=parseInt(a[0])||0,n.y=parseInt(a[1])||0}}return n.x||n.x?n:w(e)}(e):function(e){var t=e.style,n={x:parseInt(t.left)||0,y:parseInt(t.top)||0};if(!n.x&&!n.x){var r=window.getComputedStyle(e);return{x:parseInt(r.left)||0,y:parseInt(r.top)||0}}return n}(e)},x=function(e){var t=e.computedStyle,n=e.node,r=t.position;n instanceof HTMLDocument||("absolute"===r||"relative"===r||"fixed"===r)||(n.style.position="relative")},I=function(e,t){return e.leftt.left&&e.topt.top},A=function(e){var t=e.element,n=e.posDirection,r=e.containerRect,i=e.useTransform,o=k(t,i),s=b(o,"+",n);L(t,s,i);var a=t.getBoundingClientRect();!function(e){var t=e.element,n=e.edges,r=e.elementRect,i=e.containerRect,o=e.elementPos,s=e.useTransform;n.includes("top")&&L(t,{y:o.y+i.top-r.top,x:o.x},s),n.includes("left")&&L(t,{y:o.y,x:o.x+i.left-r.left},s),n.includes("bottom")&&L(t,{y:o.y+i.bottom-r.bottom,x:o.x},s),n.includes("right")&&L(t,{y:o.y,x:o.x+i.right-r.right},s)}({element:t,edges:E({elementRect:a,containerRect:r}),elementRect:a,containerRect:r,elementPos:s,useTransform:i})},L=function(e,t,n){if(n){var r=e.style.transform;e.style.transform="translate3d(".concat(t.x,"px,").concat(t.y,"px,1px) ").concat(r.replace(/translate.*?\)/g,""))}else e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px");return e},C=function(e){for(var t=e.subscribe,n=e.publish,o=e.Interaction,s=e.SelectedSet,a=function(){var e=p(c[l],2),a=e[0],u=e[1];["pre",!1].forEach((function(e){return t(e?"".concat(a,":").concat(e):a,(function(t){return u.forEach((function(a){return(!a.condition||a.condition(t))&&n(e?"".concat(e).concat(a.name):a.name,function(e){for(var t=1;t0,s=t.includes("bottom")&&i.scrollTop0,l=t.includes("right")&&i.scrollLeft1&&void 0!==arguments[1]?arguments[1]:0,i=null===(n=t[r])||void 0===n?void 0:n.parentNode;return i?(t.push(i),e(t,++r)):t}([this.HTMLNode]),this._parentNodes}}]),t}(),M=function(){function t(n){var i=this,o=n.DS,s=n.dragKeys,a=n.draggability,l=n.keyboardDrag,c=n.keyboardDragSpeed,u=n.useTransform,d=n.zoom;e(this,t),r(this,"_useTransform",void 0),r(this,"_prevCursorPos",void 0),r(this,"_prevScrollPos",void 0),r(this,"_elements",[]),r(this,"_draggability",void 0),r(this,"_dragKeys",void 0),r(this,"_dragKeysFlat",void 0),r(this,"_keyboardDrag",void 0),r(this,"_keyboardDragSpeed",void 0),r(this,"_zoom",void 0),r(this,"keyboardDrag",(function(e){var t=e.event,n=e.key;if(i._keyboardDrag&&i._dragKeysFlat.includes(n)&&i.DS.SelectedSet.size&&i._draggability&&!i.DS.continue){var r={event:t,isDragging:!0,isDraggingKeyboard:!0};i.DS.publish(["Interaction:start:pre","Interaction:start"],r),i._elements=i.DS.getSelection(),i.handleZIndex(!0);var o=function(e){var t=e.shiftKey,n=e.keyboardDragSpeed,r=e.zoom,i=e.key,o=e.dragKeys,s=e.scrollDiff,a=e.canScroll,l=e.scrollCallback,c={x:0,y:0},u=t?4*n*r:n*r;return o.left.includes(i)&&(c.x=s.x||-u,t||s.x||!a||l(["left"],n)),o.right.includes(i)&&(c.x=s.x||u,t||s.x||!a||l(["right"],n)),o.up.includes(i)&&(c.y=s.y||-u,t||s.y||!a||l(["top"],n)),o.down.includes(i)&&(c.y=s.y||u,t||s.y||!a||l(["bottom"],n)),c}({shiftKey:i.DS.stores.KeyStore.currentValues.includes("shift"),keyboardDragSpeed:i._keyboardDragSpeed,zoom:i._zoom,key:n,scrollCallback:i.DS.Area.scroll,scrollDiff:i._scrollDiff,canScroll:i.DS.stores.ScrollStore.canScroll,dragKeys:i._dragKeys});i._elements.forEach((function(e){return A({element:e,posDirection:o,containerRect:i.DS.SelectorArea.rect,useTransform:i._useTransform})})),i.DS.publish(["Interaction:update:pre","Interaction:update"],r)}})),r(this,"keyboardEnd",(function(e){var t=e.event,n=e.key;if(i._keyboardDrag&&i._dragKeysFlat.includes(n)&&i.DS.SelectedSet.size&&i._draggability){var r={event:t,isDragging:i._draggability,isDraggingKeyboard:!0};i.DS.publish(["Interaction:end:pre","Interaction:end"],r)}})),r(this,"start",(function(e){var t=e.isDragging,n=e.isDraggingKeyboard;t&&!n&&(i._prevCursorPos=null,i._prevScrollPos=null,i._elements=i.DS.getSelection(),i.handleZIndex(!0))})),r(this,"stop",(function(e){null!=e&&e.isKeyboard||(i._prevCursorPos=null,i._prevScrollPos=null,i.handleZIndex(!1),i._elements=[])})),r(this,"update",(function(e){var t=e.isDragging,n=e.isDraggingKeyboard;if(t&&i._elements.length&&!n&&!i.DS.continue){var r=b(i._cursorDiff,"+",i._scrollDiff);i._elements.forEach((function(e){return A({element:e,posDirection:r,containerRect:i.DS.SelectorArea.rect,useTransform:i._useTransform})}))}})),r(this,"handleZIndex",(function(e){i._elements.forEach((function(t){return t.style.zIndex="".concat((parseInt(t.style.zIndex)||0)+e?9999:-9998)}))})),this.DS=o,this._useTransform=u,this._keyboardDragSpeed=c,this._keyboardDrag=l,this._zoom=d,this._draggability=a,this._dragKeys={up:s.up.map((function(e){return e.toLowerCase()})),down:s.down.map((function(e){return e.toLowerCase()})),left:s.left.map((function(e){return e.toLowerCase()})),right:s.right.map((function(e){return e.toLowerCase()}))},this._dragKeysFlat=[].concat(S(this._dragKeys.up),S(this._dragKeys.down),S(this._dragKeys.left),S(this._dragKeys.right)),this.DS.subscribe("Interaction:start",this.start),this.DS.subscribe("Interaction:end",this.stop),this.DS.subscribe("Interaction:update",this.update),this.DS.subscribe("KeyStore:down",this.keyboardDrag),this.DS.subscribe("KeyStore:up",this.keyboardEnd)}return n(t,[{key:"_cursorDiff",get:function(){var e=this.DS.stores.PointerStore.currentVal,t=this._prevCursorPos?b(e,"-",this._prevCursorPos):{x:0,y:0};return this._prevCursorPos=e,t}},{key:"_scrollDiff",get:function(){var e=this.DS.stores.ScrollStore.currentVal,t=this._prevScrollPos?b(e,"-",this._prevScrollPos):{x:0,y:0};return this._prevScrollPos=e,t}}]),t}(),K=function(){function t(n){var i=this,o=n.DS,s=n.areaElement,a=n.draggability,l=n.immediateDrag,c=n.selectableClass,u=n.usePointerEvents;e(this,t),r(this,"_areaElement",void 0),r(this,"_draggability",void 0),r(this,"_immediateDrag",void 0),r(this,"_selectableClass",void 0),r(this,"_usePointerEvents",void 0),r(this,"isInteracting",void 0),r(this,"isDragging",void 0),r(this,"init",(function(){return i.DS.publish("Interaction:init:pre",{})})),r(this,"_init",(function(){i.stop(),i._usePointerEvents?i._areaElement.addEventListener("pointerdown",i.start,{passive:!1}):i._areaElement.addEventListener("mousedown",i.start),i._areaElement.addEventListener("touchstart",i.start,{passive:!1}),i.DS.publish("Interaction:init",{})})),r(this,"start",(function(e){return i.DS.publish("Interaction:start:pre",{event:e,isDragging:i.isDragging})})),r(this,"_start",(function(e){"touchstart"===e.type&&e.preventDefault(),i._canInteract(e)&&(i.isInteracting=!0,i.isDragging=i.isDragEvent(e),i.DS.publish("Interaction:start",{event:e,isDragging:i.isDragging}),i._usePointerEvents?(document.addEventListener("pointerup",i.reset),document.addEventListener("pointercancel",i.reset)):document.addEventListener("mouseup",i.reset),document.addEventListener("touchend",i.reset))})),r(this,"isDragEvent",(function(e){var t=e.target.closest(".".concat(i._selectableClass));return!(!i._draggability||i.DS.stores.KeyStore.isMultiSelectKeyPressed(e)||!t)&&(i._immediateDrag&&(i.DS.SelectedSet.size?i.DS.SelectedSet.has(t)||(i.DS.SelectedSet.clear(),i.DS.SelectedSet.add(t)):i.DS.SelectedSet.add(t)),!!i.DS.SelectedSet.has(t))})),r(this,"onClick",(function(e){var t=e.event;if(i._canInteract(t)&&!(t.detail>0)){var n=i.DS,r=n.stores,o=r.PointerStore,s=r.KeyStore,a=n.SelectableSet,l=n.SelectedSet;o.start(t);var c=t.target;a.has(c)&&(s.isMultiSelectKeyPressed(t)||l.clear(),l.toggle(c),i.reset())}})),r(this,"stop",(function(){i.isInteracting=!1,i.isDragging=!1,i._usePointerEvents?(i._areaElement.removeEventListener("pointerdown",i.start,{passive:!1}),document.removeEventListener("pointerup",i.reset),document.removeEventListener("pointercancel",i.reset)):(i._areaElement.removeEventListener("mousedown",i.start),document.removeEventListener("mouseup",i.reset)),i._areaElement.removeEventListener("touchstart",i.start,{passive:!1}),document.removeEventListener("touchend",i.reset)})),r(this,"update",(function(e){var t=e.event,n=e.scroll_directions,r=e.scroll_multiplier;i.isInteracting&&i.DS.publish(["Interaction:update:pre","Interaction:update"],{event:t,scroll_directions:n,scroll_multiplier:r,isDragging:i.isDragging})})),r(this,"reset",(function(e){return i.DS.publish("Interaction:end:pre",{event:e,isDragging:i.isDragging})})),r(this,"_reset",(function(e){var t=i.isDragging;i.stop(),i.init(),i.DS.publish("Interaction:end",{event:e,isDragging:t})})),this._areaElement=s,this._draggability=a,this._immediateDrag=l,this._selectableClass=c,this._usePointerEvents=u,this.DS=o,this.DS.subscribe("PointerStore:updated",this.update),this.DS.subscribe("Selectable:click",this.onClick),this.DS.subscribe("Selectable:pointer",(function(e){var t=e.event;return i.start(t)})),this.DS.subscribe("Interaction:start:pre",(function(e){var t=e.event;return i._start(t)})),this.DS.subscribe("Interaction:init:pre",this._init),this.DS.subscribe("Interaction:end:pre",(function(e){var t=e.event;return i._reset(t)})),this.DS.subscribe("Area:scroll",this.update)}return n(t,[{key:"_canInteract",value:function(e){var t=0===e.clientX&&0===e.clientY&&0===e.detail&&e.target;return!(2===e.button||this.isInteracting||e.target&&!this.DS.SelectorArea.isInside(e.target)||!t&&!this.DS.SelectorArea.isClicked(e))}}]),t}(),O=function t(n){var i=this,o=n.DS;e(this,t),r(this,"subscribers",{}),r(this,"subscribe",(function(e,t){return Array.isArray(i.subscribers[e])||(i.subscribers[e]=[]),i.subscribers[e].push(t),i.subscribers[e].length-1})),r(this,"unsubscribe",(function(e,t,n){n>=0?i.subscribers[e].splice(n,1):t&&(i.subscribers[e]=i.subscribers[e].filter((function(e){return e!==t})))})),r(this,"publish",(function(e,t){Array.isArray(e)?e.forEach((function(e){return i._publish(e,t)})):i._publish(e,t)})),r(this,"_publish",(function(e,t){var n=i.subscribers[e];Array.isArray(n)&&(e.includes(":pre")?i._handlePrePublish(n,t):i._handlePublish(n,t))})),r(this,"_handlePublish",(function(e,t){for(var n=0,r=e.length;nn.x-t.x?(i.left=n.x-t.x,i.width=r.x-n.x+t.x):(i.left=r.x,i.width=n.x-r.x-t.x),r.y>n.y-t.y?(i.top=n.y-t.y,i.height=r.y-n.y+t.y):(i.top=r.y,i.height=n.y-r.y-t.y),i}({scrollAmount:n.scrollAmount,initialPointerPos:r.initialValArea,pointerPos:r.currentValArea});V(i.HTMLNode,o),i._rect=null}})),this.DS=o,this.HTMLNode=s||function(e){var t=document.createElement("div");return t.style.position="absolute",e||(t.style.background="rgba(0, 0, 255, 0.1)",t.style.border="1px solid rgba(0, 0, 255, 0.45)",t.style.display="none",t.style.pointerEvents="none"),t}(l),this.HTMLNode.classList.add(a),this.DS.subscribe("Interaction:start",this.start),this.DS.subscribe("Interaction:update",this.update),this.DS.subscribe("Interaction:end",this.stop)}return n(t,[{key:"rect",get:function(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}]),t}(),B=function(){function t(n){var i=this,o=n.DS,s=n.selectorAreaClass,a=n.autoScrollSpeed,l=n.overflowTolerance;e(this,t),r(this,"_autoScrollSpeed",void 0),r(this,"_scrollInterval",void 0),r(this,"_rect",void 0),r(this,"currentEdges",[]),r(this,"_overflowTolerance",void 0),r(this,"start",(function(){return i.applyElements("append")})),r(this,"applyElements",(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"append",t=document.body?"body":"documentElement",n="".concat(e,"Child");i.HTMLNode[n](i.DS.Selector.HTMLNode),document[t][n](i.HTMLNode)})),r(this,"updatePos",(function(){i._rect=null;var e=i.DS.Area.rect,t=i.DS.Area.computedBorder,n=i.HTMLNode.style,r="".concat(e.top+t.top,"px"),o="".concat(e.left+t.left,"px"),s="".concat(e.width,"px"),a="".concat(e.height,"px");n.top!==r&&(n.top=r),n.left!==o&&(n.left=o),n.width!==s&&(n.width=s),n.height!==a&&(n.height=a)})),r(this,"stop",(function(e){i.stopAutoScroll(),e&&i.applyElements("remove")})),r(this,"startAutoScroll",(function(){i.currentEdges=[],i._scrollInterval=setInterval((function(){return i.handleAutoScroll()}),16)})),r(this,"handleAutoScroll",(function(){if(!i.DS.continue){var e=i.DS,t=e.stores.PointerStore,n=e.Area;i.currentEdges=E({elementRect:_(t.currentVal),containerRect:i.rect,tolerance:i._overflowTolerance}),i.currentEdges.length&&n.scroll(i.currentEdges,i._autoScrollSpeed)}})),r(this,"stopAutoScroll",(function(){i.currentEdges=[],clearInterval(i._scrollInterval)})),r(this,"isInside",(function(e,t){return!(!i.DS.Area.HTMLNode.contains(e)||!i.DS.stores.ScrollStore.canScroll)||I(i.rect,t||e.getBoundingClientRect())})),this._autoScrollSpeed=a,this._overflowTolerance=l,this.DS=o,this.HTMLNode=function(e){var t=document.createElement("div");return t.style.position="fixed",t.style.overflow="hidden",t.style.pointerEvents="none",t.style.zIndex="999999999999999999",t.classList.add(e),t}(s),this.DS.subscribe("Area:modified",this.updatePos),this.DS.subscribe("Interaction:init",this.start),this.DS.subscribe("Interaction:start",this.startAutoScroll),this.DS.subscribe("Interaction:end",(function(){i.updatePos(),i.stopAutoScroll()}))}return n(t,[{key:"isClicked",value:function(e){var t=this.DS.stores.PointerStore,n=e?t.getPointerPosition(e):t.initialVal;return I({left:n.x,top:n.y,right:n.x,bottom:n.y},this.rect)}},{key:"rect",get:function(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}]),t}(),U=function(){function t(n){var i=this,o=n.DS,s=n.multiSelectKeys,a=n.multiSelectMode;e(this,t),r(this,"_multiSelectMode",void 0),r(this,"_multiSelectKeys",void 0),r(this,"_currentValues",new Set),r(this,"_keyMapping",{control:"ctrlKey",shift:"shiftKey",meta:"metaKey"}),r(this,"init",(function(){document.addEventListener("keydown",i.keydown),document.addEventListener("keyup",i.keyup),window.addEventListener("blur",i.reset)})),r(this,"keydown",(function(e){var t=e.key.toLowerCase();i.DS.publish("KeyStore:down:pre",{event:e,key:t}),i._currentValues.add(t),i.DS.publish("KeyStore:down",{event:e,key:t})})),r(this,"keyup",(function(e){var t=e.key.toLowerCase();i.DS.publish("KeyStore:up:pre",{event:e,key:t}),i._currentValues.delete(t),i.DS.publish("KeyStore:up",{event:e,key:t})})),r(this,"stop",(function(){document.removeEventListener("keydown",i.keydown),document.removeEventListener("keyup",i.reset),window.removeEventListener("blur",i.reset),i.reset()})),r(this,"reset",(function(){return i._currentValues.clear()})),this.DS=o,this._multiSelectMode=a,this._multiSelectKeys=s.map((function(e){var t={ctrlKey:"Control",shiftKey:"Shift",metaKey:"Meta"}[e];return t?(console.warn("[DragSelect] ".concat(e,' is deprecated. Use "').concat(t,'" instead. Act Now!. See docs for more info')),t.toLowerCase()):e.toLowerCase()})),this.DS.subscribe("Interaction:init",this.init)}return n(t,[{key:"isMultiSelectKeyPressed",value:function(e){var t=this;return!!this._multiSelectMode||(!!this.currentValues.some((function(e){return t._multiSelectKeys.includes(e)}))||!(!e||!this._multiSelectKeys.some((function(n){return e[t._keyMapping[n]]}))))}},{key:"currentValues",get:function(){return Array.from(this._currentValues.values())}}]),t}(),W=function(){function t(n){var i=this,o=n.DS,s=n.usePointerEvents,a=void 0!==s&&s;e(this,t),r(this,"_isMouseInteraction",!1),r(this,"_initialValArea",void 0),r(this,"_currentValArea",void 0),r(this,"_lastValArea",void 0),r(this,"_initialVal",void 0),r(this,"_currentVal",void 0),r(this,"_lastVal",void 0),r(this,"_lastTouch",void 0),r(this,"_usePointerEvents",void 0),r(this,"init",(function(){i._usePointerEvents?document.addEventListener("pointermove",i.update,{passive:!1}):document.addEventListener("mousemove",i.update),document.addEventListener("touchmove",i.update,{passive:!1})})),r(this,"getPointerPosition",(function(e){return function(e){var t=e.event;return{x:t.clientX,y:t.clientY}}({event:i._normalizedEvent(e)})})),r(this,"update",(function(e){e&&(i.DS.publish("PointerStore:updated:pre",{event:e}),i.currentVal=i.getPointerPosition(e),i._isMouseInteraction&&i.DS.publish("PointerStore:updated",{event:e}))})),r(this,"stop",(function(){i._usePointerEvents?document.removeEventListener("pointermove",i.update,{passive:!1}):document.removeEventListener("mousemove",i.update),document.removeEventListener("touchmove",i.update,{passive:!1}),setTimeout((function(){return i._isMouseInteraction=!1}),100)})),r(this,"reset",(function(e){e&&(i.currentVal=i.lastVal=i.getPointerPosition(e),i.stop(),i.init())})),this.DS=o,this._usePointerEvents=a,this.DS.subscribe("Interaction:init",this.init),this.DS.subscribe("Interaction:start",(function(e){var t=e.event;return i.start(t)})),this.DS.subscribe("Interaction:end",(function(e){var t=e.event;return i.reset(t)}))}return n(t,[{key:"start",value:function(e){e&&(this._isMouseInteraction=!0,this.currentVal=this.initialVal=this.getPointerPosition(e))}},{key:"_normalizedEvent",value:function(e){return"touches"in e&&"touchend"!==e.type&&(this._lastTouch=e),"touches"in e?this._lastTouch.touches[0]:e}},{key:"initialValArea",get:function(){return this._initialValArea?this._initialValArea:{x:0,y:0}}},{key:"currentValArea",get:function(){return this._currentValArea?this._currentValArea:{x:0,y:0}}},{key:"lastValArea",get:function(){return this._lastValArea?this._lastValArea:{x:0,y:0}}},{key:"initialVal",get:function(){return this._initialVal?this._initialVal:{x:0,y:0}},set:function(e){this._initialVal=e,this._initialValArea=e&&b(e,"-",b(y(this.DS.Area.rect),"+",y(this.DS.Area.computedBorder)))}},{key:"currentVal",get:function(){return this._currentVal?this._currentVal:{x:0,y:0}},set:function(e){this._currentVal=e,this._currentValArea=e&&b(e,"-",b(y(this.DS.Area.rect),"+",y(this.DS.Area.computedBorder)))}},{key:"lastVal",get:function(){return this._lastVal?this._lastVal:{x:0,y:0}},set:function(e){this._lastVal=e,this._lastValArea=e&&b(e,"-",b(y(this.DS.Area.rect),"+",y(this.DS.Area.computedBorder)))}}]),t}(),F=function(){function t(n){var i=this,o=n.DS,s=n.areaElement,a=n.zoom;e(this,t),r(this,"_initialVal",void 0),r(this,"_currentVal",void 0),r(this,"_areaElement",void 0),r(this,"_canScroll",void 0),r(this,"init",(function(){return i._areaElement.addEventListener("scroll",i.update)})),r(this,"start",(function(){i._currentVal=i._initialVal=P(i._areaElement),i._areaElement.addEventListener("scroll",i.update)})),r(this,"update",(function(){return i._currentVal=P(i._areaElement)})),r(this,"stop",(function(){i._areaElement.removeEventListener("scroll",i.update),i._initialVal={x:0,y:0},i._canScroll=null})),r(this,"reset",(function(){i.stop(),i.start()})),this._areaElement=s,this.DS=o,this.zoom=a,this.DS.subscribe("Interaction:init",this.init),this.DS.subscribe("Interaction:start",(function(){return i.start()})),this.DS.subscribe("Interaction:end",(function(){return i.reset()}))}return n(t,[{key:"canScroll",get:function(){return"boolean"==typeof this._canScroll?this._canScroll:this._canScroll=(e=this._areaElement,!!((t=P(e)).x||t.y||(e instanceof HTMLDocument?e.body?e.body.scrollTop=1:e.documentElement.scrollTop=1:e.scrollTop=1)));var e,t}},{key:"scrollAmount",get:function(){var e,t=b(this.currentVal,"-",this.initialVal),n={x:e=this.zoom,y:e},r=b(b(t,"*",n),"-",t);return{x:t.x+r.x,y:t.y+r.y}}},{key:"initialVal",get:function(){return this._initialVal?this._initialVal:{x:0,y:0}}},{key:"currentVal",get:function(){return this._currentVal||(this._currentVal=P(this._areaElement)),this._currentVal}}]),t}(),Z=function(){function t(n){var i=this,o=n.area,s=void 0===o?document:o,a=n.selectables,l=void 0===a?[]:a,c=n.autoScrollSpeed,u=void 0===c?5:c,d=n.overflowTolerance,h=void 0===d?{x:25,y:25}:d,f=n.zoom,v=void 0===f?1:f,p=n.customStyles,S=void 0!==p&&p,m=n.multiSelectMode,g=void 0!==m&&m,b=n.multiSelectToggling,y=void 0===b||b,_=n.multiSelectKeys,D=void 0===_?["Control","Shift","Meta"]:_,P=n.selector,E=void 0===P?void 0:P,w=n.draggability,k=void 0===w||w,x=n.immediateDrag,I=void 0===x||x,A=n.keyboardDrag,L=void 0===A||A,T=n.dragKeys,V=n.keyboardDragSpeed,Z=void 0===V?10:V,X=n.useTransform,Y=void 0===X||X,G=n.hoverClass,$=void 0===G?"ds-hover":G,q=n.selectableClass,J=void 0===q?"ds-selectable":q,Q=n.selectedClass,ee=void 0===Q?"ds-selected":Q,te=n.selectorClass,ne=void 0===te?"ds-selector":te,re=n.selectorAreaClass,ie=void 0===re?"ds-selector-area":re,oe=n.callback,se=n.onDragMove,ae=n.onDragStartBegin,le=n.onDragStart,ce=n.onElementSelect,ue=n.onElementUnselect,de=n.usePointerEvents,he=void 0!==de&&de;e(this,t),r(this,"continue",!1),r(this,"start",(function(){i.stopped=!1,i.Interaction.init()})),r(this,"break",(function(){return i.continue=!0})),r(this,"getSelection",(function(){return i.SelectedSet.elements})),r(this,"getSelectables",(function(){return i.SelectableSet.elements})),r(this,"getInitialCursorPosition",(function(){return i.stores.PointerStore.initialVal})),r(this,"getCurrentCursorPosition",(function(){return i.stores.PointerStore.currentVal})),r(this,"getPreviousCursorPosition",(function(){return i.stores.PointerStore.lastVal})),r(this,"getInitialCursorPositionArea",(function(){return i.stores.PointerStore.initialValArea})),r(this,"getCurrentCursorPositionArea",(function(){return i.stores.PointerStore.currentValArea})),r(this,"getPreviousCursorPositionArea",(function(){return i.stores.PointerStore.lastValArea})),r(this,"isMultiSelect",(function(e){return i.stores.KeyStore.isMultiSelectKeyPressed(e)})),r(this,"isDragging",(function(){return i.Interaction.isDragging})),this.PubSub=new O({DS:this}),this.subscribe=this.PubSub.subscribe,this.unsubscribe=this.PubSub.unsubscribe,this.publish=this.PubSub.publish,this._callbacksTemp({callback:oe,onDragMove:se,onDragStart:le,onDragStartBegin:ae,onElementSelect:ce,onElementUnselect:ue}),this.stores={PointerStore:new W({DS:this,usePointerEvents:he}),ScrollStore:new F({DS:this,areaElement:s,zoom:v}),KeyStore:new U({DS:this,multiSelectKeys:D,multiSelectMode:g})},this.Area=new N({area:s,PS:this.PubSub,zoom:v}),this.Selector=new R({DS:this,selector:E,selectorClass:ne,customStyles:S}),this.SelectorArea=new B({DS:this,selectorAreaClass:ie,autoScrollSpeed:u,overflowTolerance:h}),this.SelectableSet=new j({elements:l,DS:this,className:J,hoverClassName:$,useTransform:Y,draggability:k,usePointerEvents:he}),this.SelectedSet=new z({DS:this,className:ee}),this.Selection=new H({DS:this,hoverClassName:$,multiSelectToggling:y}),this.Drag=new M({DS:this,draggability:k,useTransform:Y,keyboardDrag:L,dragKeys:Object.assign({up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},T),zoom:v,keyboardDragSpeed:Z}),this.Interaction=new K({areaElement:s,DS:this,draggability:k,immediateDrag:I,selectableClass:J,usePointerEvents:he}),C({subscribe:this.subscribe,publish:this.publish,SelectedSet:this.SelectedSet,Interaction:this.Interaction}),this.subscribe("Interaction:end",(function(){return i.continue=!1})),this.start()}return n(t,[{key:"_callbacksTemp",value:function(e){var t=e.callback,n=e.onDragMove,r=e.onDragStart,i=e.onDragStartBegin,o=e.onElementSelect,s=e.onElementUnselect,a=function(e,t){return console.warn("[DragSelect] ".concat(e,' is deprecated. Use DragSelect.subscribe("').concat(t,'", (callbackObject) => {}) instead. Act Now! See docs for more info'))};t&&(a("callback","callback"),this.subscribe("callback",(function(e){var n=e.items,r=(e.item,e.event);return t(n,r)}))),n&&(a("onDragMove","dragmove"),this.subscribe("dragmove",(function(e){e.items,e.item;var t=e.event;return n(t)}))),r&&(a("onDragStart","dragstart"),this.subscribe("dragstart",(function(e){e.items,e.item;var t=e.event;return r(t)}))),i&&(a("onDragStartBegin","dragstart"),this.subscribe("dragstart",(function(e){e.items,e.item;var t=e.event;return i(t)}))),o&&(a("onElementSelect","elementselect"),this.subscribe("elementselect",(function(e){e.items;var t=e.item,n=e.event;return o(t,n)}))),s&&(a("onElementUnselect","elementunselect"),this.subscribe("elementunselect",(function(e){e.items;var t=e.item,n=e.event;return s(t,n)})))}},{key:"stop",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];n&&this.publish("callback",{items:this.getSelection()}),this.Interaction.stop(),this.Area.stop(),this.Drag.stop(),this.Selector.stop(),this.SelectorArea.stop(e),this.stores.KeyStore.stop(),this.stores.PointerStore.stop(),this.stores.ScrollStore.stop(),e&&this.SelectableSet.clear(),t&&this.SelectedSet.clear(),this.stopped=!0}},{key:"addSelection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.SelectedSet.addAll(T(e)),n||this.addSelectables(e),t&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"removeSelection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.SelectedSet.deleteAll(T(e)),n&&this.removeSelectables(e),t&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"toggleSelection",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return T(e).forEach((function(i){return t.SelectedSet.has(i)?t.removeSelection(e,n,r):t.addSelection(e,n,r)})),n&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"setSelection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.clearSelection(),this.addSelection(e,t,n),this.getSelection()}},{key:"clearSelection",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.SelectedSet.clear(),e&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"addSelectables",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=T(e);return this.SelectableSet.addAll(n),t&&this.SelectedSet.addAll(n),e}},{key:"setSelectables",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.removeSelectables(e,t),this.addSelectables(e,n)}},{key:"removeSelectables",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.SelectableSet.deleteAll(T(e)),t&&this.removeSelection(e),e}},{key:"getCursorPositionDifference",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];console.warn("[DragSelect] Using .getCursorPositionDifference is deprecated. Calculate yourself instead. i.e. `.getCurrentCursorPosition().x - .getInitialCursorPosition().x`");var n=t?this.getCurrentCursorPositionArea():this.getCurrentCursorPosition(),r=e?t?this.getPreviousCursorPositionArea():this.getPreviousCursorPosition():t?this.getInitialCursorPositionArea():this.getInitialCursorPosition();return b(n,"-",r)}}]),t}();return Z})); \ No newline at end of file +/* eslint-disable */ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DragSelect=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:0;return{left:e.x,top:e.y,right:e.x,bottom:e.y,width:t,height:t}},D=function(){var e,t,n,r;return{y:(null===(e=document.body)||void 0===e?void 0:e.scrollTop)||(null===(t=document.documentElement)||void 0===t?void 0:t.scrollTop)||0,x:(null===(n=document.body)||void 0===n?void 0:n.scrollLeft)||(null===(r=document.documentElement)||void 0===r?void 0:r.scrollLeft)||0}},P=function(e){return!e||e instanceof Document?D():{x:e.scrollLeft>=0?e.scrollLeft:D().x,y:e.scrollTop>=0?e.scrollTop:D().y}},E=function(e){var t=e.elementRect,n=e.containerRect,r=e.tolerance,i=void 0===r?{x:0,y:0}:r,o=[];return t.top-i.yn.bottom&&o.push("bottom"),t.right+i.y>n.right&&o.push("right"),o},w=function(e){var t={x:0,y:0},n=window.getComputedStyle(e);if(!n.transform||"none"===n.transform)return t;if(n.transform.indexOf("3d")>=0){var r=n.transform.trim().match(/matrix3d\((.*?)\)/);if(r&&r.length){var i,o=null===(i=r[1])||void 0===i?void 0:i.split(",");t.x=parseInt(o[12])||0,t.y=parseInt(o[13])||0}return t}var s=n.transform.trim().match(/matrix\((.*?)\)/);if(s&&s.length){var a,l=null===(a=s[1])||void 0===a?void 0:a.split(",");t.x=parseInt(l[4])||0,t.y=parseInt(l[5])||0}return t},k=function(e,t){return t?function(e){var t=e.style.transform;if(!t||t.indexOf("translate")<0)return w(e);var n={x:0,y:0},r=t.trim().match(/translate[3dD]*?\(.*?\)/);if(r){var i,o=null===(i=r[0])||void 0===i?void 0:i.split("(");if(o){var s,a=null===(s=o[1])||void 0===s?void 0:s.split(",");n.x=parseInt(a[0])||0,n.y=parseInt(a[1])||0}}return n.x||n.x?n:w(e)}(e):function(e){var t=e.style,n={x:parseInt(t.left)||0,y:parseInt(t.top)||0};if(!n.x&&!n.x){var r=window.getComputedStyle(e);return{x:parseInt(r.left)||0,y:parseInt(r.top)||0}}return n}(e)},x=function(e){var t=e.computedStyle,n=e.node,r=t.position;n instanceof HTMLDocument||("absolute"===r||"relative"===r||"fixed"===r)||(n.style.position="relative")},I=function(e,t){return e.leftt.left&&e.topt.top},A=function(e){var t=e.element,n=e.posDirection,r=e.containerRect,i=e.useTransform,o=k(t,i),s=b(o,"+",n);L(t,s,i);var a=t.getBoundingClientRect();!function(e){var t=e.element,n=e.edges,r=e.elementRect,i=e.containerRect,o=e.elementPos,s=e.useTransform;n.includes("top")&&L(t,{y:o.y+i.top-r.top,x:o.x},s),n.includes("left")&&L(t,{y:o.y,x:o.x+i.left-r.left},s),n.includes("bottom")&&L(t,{y:o.y+i.bottom-r.bottom,x:o.x},s),n.includes("right")&&L(t,{y:o.y,x:o.x+i.right-r.right},s)}({element:t,edges:E({elementRect:a,containerRect:r}),elementRect:a,containerRect:r,elementPos:s,useTransform:i})},L=function(e,t,n){if(n){var r=e.style.transform;e.style.transform="translate3d(".concat(t.x,"px,").concat(t.y,"px,1px) ").concat(r.replace(/translate.*?\)/g,""))}else e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px");return e},C=function(e){for(var t=e.subscribe,n=e.publish,o=e.Interaction,s=e.SelectedSet,a=function(){var e=p(c[l],2),a=e[0],u=e[1];["pre",!1].forEach((function(e){return t(e?"".concat(a,":").concat(e):a,(function(t){return u.forEach((function(a){return(!a.condition||a.condition(t))&&n(e?"".concat(e).concat(a.name):a.name,function(e){for(var t=1;t0,s=t.includes("bottom")&&i.scrollTop0,l=t.includes("right")&&i.scrollLeft1&&void 0!==arguments[1]?arguments[1]:0,i=null===(n=t[r])||void 0===n?void 0:n.parentNode;return i?(t.push(i),e(t,++r)):t}([this.HTMLNode]),this._parentNodes}}]),t}(),M=function(){function t(n){var i=this,o=n.DS,s=n.dragKeys,a=n.draggability,l=n.keyboardDrag,c=n.keyboardDragSpeed,u=n.useTransform,d=n.zoom;e(this,t),r(this,"_useTransform",void 0),r(this,"_prevCursorPos",void 0),r(this,"_prevScrollPos",void 0),r(this,"_elements",[]),r(this,"_draggability",void 0),r(this,"_dragKeys",void 0),r(this,"_dragKeysFlat",void 0),r(this,"_keyboardDrag",void 0),r(this,"_keyboardDragSpeed",void 0),r(this,"_zoom",void 0),r(this,"keyboardDrag",(function(e){var t=e.event,n=e.key;if(i._keyboardDrag&&i._dragKeysFlat.includes(n)&&i.DS.SelectedSet.size&&i._draggability&&!i.DS.continue){var r={event:t,isDragging:!0,isDraggingKeyboard:!0};i.DS.publish(["Interaction:start:pre","Interaction:start"],r),i._elements=i.DS.getSelection(),i.handleZIndex(!0);var o=function(e){var t=e.shiftKey,n=e.keyboardDragSpeed,r=e.zoom,i=e.key,o=e.dragKeys,s=e.scrollDiff,a=e.canScroll,l=e.scrollCallback,c={x:0,y:0},u=t?4*n*r:n*r;return o.left.includes(i)&&(c.x=s.x||-u,t||s.x||!a||l(["left"],n)),o.right.includes(i)&&(c.x=s.x||u,t||s.x||!a||l(["right"],n)),o.up.includes(i)&&(c.y=s.y||-u,t||s.y||!a||l(["top"],n)),o.down.includes(i)&&(c.y=s.y||u,t||s.y||!a||l(["bottom"],n)),c}({shiftKey:i.DS.stores.KeyStore.currentValues.includes("shift"),keyboardDragSpeed:i._keyboardDragSpeed,zoom:i._zoom,key:n,scrollCallback:i.DS.Area.scroll,scrollDiff:i._scrollDiff,canScroll:i.DS.stores.ScrollStore.canScroll,dragKeys:i._dragKeys});i._elements.forEach((function(e){return A({element:e,posDirection:o,containerRect:i.DS.SelectorArea.rect,useTransform:i._useTransform})})),i.DS.publish(["Interaction:update:pre","Interaction:update"],r)}})),r(this,"keyboardEnd",(function(e){var t=e.event,n=e.key;if(i._keyboardDrag&&i._dragKeysFlat.includes(n)&&i.DS.SelectedSet.size&&i._draggability){var r={event:t,isDragging:i._draggability,isDraggingKeyboard:!0};i.DS.publish(["Interaction:end:pre","Interaction:end"],r)}})),r(this,"start",(function(e){var t=e.isDragging,n=e.isDraggingKeyboard;t&&!n&&(i._prevCursorPos=null,i._prevScrollPos=null,i._elements=i.DS.getSelection(),i.handleZIndex(!0))})),r(this,"stop",(function(e){null!=e&&e.isKeyboard||(i._prevCursorPos=null,i._prevScrollPos=null,i.handleZIndex(!1),i._elements=[])})),r(this,"update",(function(e){var t=e.isDragging,n=e.isDraggingKeyboard;if(t&&i._elements.length&&!n&&!i.DS.continue){var r=b(i._cursorDiff,"+",i._scrollDiff);i._elements.forEach((function(e){return A({element:e,posDirection:r,containerRect:i.DS.SelectorArea.rect,useTransform:i._useTransform})}))}})),r(this,"handleZIndex",(function(e){i._elements.forEach((function(t){return t.style.zIndex="".concat((parseInt(t.style.zIndex)||0)+e?9999:-9998)}))})),this.DS=o,this._useTransform=u,this._keyboardDragSpeed=c,this._keyboardDrag=l,this._zoom=d,this._draggability=a,this._dragKeys={up:s.up.map((function(e){return e.toLowerCase()})),down:s.down.map((function(e){return e.toLowerCase()})),left:s.left.map((function(e){return e.toLowerCase()})),right:s.right.map((function(e){return e.toLowerCase()}))},this._dragKeysFlat=[].concat(S(this._dragKeys.up),S(this._dragKeys.down),S(this._dragKeys.left),S(this._dragKeys.right)),this.DS.subscribe("Interaction:start",this.start),this.DS.subscribe("Interaction:end",this.stop),this.DS.subscribe("Interaction:update",this.update),this.DS.subscribe("KeyStore:down",this.keyboardDrag),this.DS.subscribe("KeyStore:up",this.keyboardEnd)}return n(t,[{key:"_cursorDiff",get:function(){var e=this.DS.stores.PointerStore.currentVal,t=this._prevCursorPos?b(e,"-",this._prevCursorPos):{x:0,y:0};return this._prevCursorPos=e,t}},{key:"_scrollDiff",get:function(){var e=this.DS.stores.ScrollStore.currentVal,t=this._prevScrollPos?b(e,"-",this._prevScrollPos):{x:0,y:0};return this._prevScrollPos=e,t}}]),t}(),K=function(){function t(n){var i=this,o=n.DS,s=n.areaElement,a=n.draggability,l=n.immediateDrag,c=n.selectableClass,u=n.usePointerEvents;e(this,t),r(this,"_areaElement",void 0),r(this,"_draggability",void 0),r(this,"_immediateDrag",void 0),r(this,"_selectableClass",void 0),r(this,"_usePointerEvents",void 0),r(this,"isInteracting",void 0),r(this,"isDragging",void 0),r(this,"init",(function(){return i.DS.publish("Interaction:init:pre",{})})),r(this,"_init",(function(){i.stop(),i._usePointerEvents?i._areaElement.addEventListener("pointerdown",i.start,{passive:!1}):i._areaElement.addEventListener("mousedown",i.start),i._areaElement.addEventListener("touchstart",i.start,{passive:!1}),i.DS.publish("Interaction:init",{})})),r(this,"start",(function(e){return i.DS.publish("Interaction:start:pre",{event:e,isDragging:i.isDragging})})),r(this,"_start",(function(e){"touchstart"===e.type&&e.preventDefault(),i._canInteract(e)&&(i.isInteracting=!0,i.isDragging=i.isDragEvent(e),i.DS.publish("Interaction:start",{event:e,isDragging:i.isDragging}),i._usePointerEvents?(document.addEventListener("pointerup",i.reset),document.addEventListener("pointercancel",i.reset)):document.addEventListener("mouseup",i.reset),document.addEventListener("touchend",i.reset))})),r(this,"isDragEvent",(function(e){var t=e.target.closest(".".concat(i._selectableClass));return!(!i._draggability||i.DS.stores.KeyStore.isMultiSelectKeyPressed(e)||!t)&&(i._immediateDrag&&(i.DS.SelectedSet.size?i.DS.SelectedSet.has(t)||(i.DS.SelectedSet.clear(),i.DS.SelectedSet.add(t)):i.DS.SelectedSet.add(t)),!!i.DS.SelectedSet.has(t))})),r(this,"onClick",(function(e){var t=e.event;if(i._canInteract(t)&&!(t.detail>0)){var n=i.DS,r=n.stores,o=r.PointerStore,s=r.KeyStore,a=n.SelectableSet,l=n.SelectedSet;o.start(t);var c=t.target;a.has(c)&&(s.isMultiSelectKeyPressed(t)||l.clear(),l.toggle(c),i.reset())}})),r(this,"stop",(function(){i.isInteracting=!1,i.isDragging=!1,i._usePointerEvents?(i._areaElement.removeEventListener("pointerdown",i.start,{passive:!1}),document.removeEventListener("pointerup",i.reset),document.removeEventListener("pointercancel",i.reset)):(i._areaElement.removeEventListener("mousedown",i.start),document.removeEventListener("mouseup",i.reset)),i._areaElement.removeEventListener("touchstart",i.start,{passive:!1}),document.removeEventListener("touchend",i.reset)})),r(this,"update",(function(e){var t=e.event,n=e.scroll_directions,r=e.scroll_multiplier;i.isInteracting&&i.DS.publish(["Interaction:update:pre","Interaction:update"],{event:t,scroll_directions:n,scroll_multiplier:r,isDragging:i.isDragging})})),r(this,"reset",(function(e){return i.DS.publish("Interaction:end:pre",{event:e,isDragging:i.isDragging})})),r(this,"_reset",(function(e){var t=i.isDragging;i.stop(),i.init(),i.DS.publish("Interaction:end",{event:e,isDragging:t})})),this._areaElement=s,this._draggability=a,this._immediateDrag=l,this._selectableClass=c,this._usePointerEvents=u,this.DS=o,this.DS.subscribe("PointerStore:updated",this.update),this.DS.subscribe("Selectable:click",this.onClick),this.DS.subscribe("Selectable:pointer",(function(e){var t=e.event;return i.start(t)})),this.DS.subscribe("Interaction:start:pre",(function(e){var t=e.event;return i._start(t)})),this.DS.subscribe("Interaction:init:pre",this._init),this.DS.subscribe("Interaction:end:pre",(function(e){var t=e.event;return i._reset(t)})),this.DS.subscribe("Area:scroll",this.update)}return n(t,[{key:"_canInteract",value:function(e){var t=0===e.clientX&&0===e.clientY&&0===e.detail&&e.target;return!(2===e.button||this.isInteracting||e.target&&!this.DS.SelectorArea.isInside(e.target)||!t&&!this.DS.SelectorArea.isClicked(e))}}]),t}(),O=function t(n){var i=this,o=n.DS;e(this,t),r(this,"subscribers",{}),r(this,"subscribe",(function(e,t){return Array.isArray(i.subscribers[e])||(i.subscribers[e]=[]),i.subscribers[e].push(t),i.subscribers[e].length-1})),r(this,"unsubscribe",(function(e,t,n){n>=0?i.subscribers[e].splice(n,1):t&&(i.subscribers[e]=i.subscribers[e].filter((function(e){return e!==t})))})),r(this,"publish",(function(e,t){Array.isArray(e)?e.forEach((function(e){return i._publish(e,t)})):i._publish(e,t)})),r(this,"_publish",(function(e,t){var n=i.subscribers[e];Array.isArray(n)&&(e.includes(":pre")?i._handlePrePublish(n,t):i._handlePublish(n,t))})),r(this,"_handlePublish",(function(e,t){for(var n=0,r=e.length;nn.x-t.x?(i.left=n.x-t.x,i.width=r.x-n.x+t.x):(i.left=r.x,i.width=n.x-r.x-t.x),r.y>n.y-t.y?(i.top=n.y-t.y,i.height=r.y-n.y+t.y):(i.top=r.y,i.height=n.y-r.y-t.y),i}({scrollAmount:n.scrollAmount,initialPointerPos:r.initialValArea,pointerPos:r.currentValArea});V(i.HTMLNode,o),i._rect=null}})),this.DS=o,this.HTMLNode=s||function(e){var t=document.createElement("div");return t.style.position="absolute",e||(t.style.background="rgba(0, 0, 255, 0.1)",t.style.border="1px solid rgba(0, 0, 255, 0.45)",t.style.display="none",t.style.pointerEvents="none"),t}(l),this.HTMLNode.classList.add(a),this.DS.subscribe("Interaction:start",this.start),this.DS.subscribe("Interaction:update",this.update),this.DS.subscribe("Interaction:end",this.stop)}return n(t,[{key:"rect",get:function(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}]),t}(),B=function(){function t(n){var i=this,o=n.DS,s=n.selectorAreaClass,a=n.autoScrollSpeed,l=n.overflowTolerance;e(this,t),r(this,"_autoScrollSpeed",void 0),r(this,"_scrollInterval",void 0),r(this,"_rect",void 0),r(this,"currentEdges",[]),r(this,"_overflowTolerance",void 0),r(this,"start",(function(){return i.applyElements("append")})),r(this,"applyElements",(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"append",t=document.body?"body":"documentElement",n="".concat(e,"Child");i.HTMLNode[n](i.DS.Selector.HTMLNode),document[t][n](i.HTMLNode)})),r(this,"updatePos",(function(){i._rect=null;var e=i.DS.Area.rect,t=i.DS.Area.computedBorder,n=i.HTMLNode.style,r="".concat(e.top+t.top,"px"),o="".concat(e.left+t.left,"px"),s="".concat(e.width,"px"),a="".concat(e.height,"px");n.top!==r&&(n.top=r),n.left!==o&&(n.left=o),n.width!==s&&(n.width=s),n.height!==a&&(n.height=a)})),r(this,"stop",(function(e){i.stopAutoScroll(),e&&i.applyElements("remove")})),r(this,"startAutoScroll",(function(){i.currentEdges=[],i._scrollInterval=setInterval((function(){return i.handleAutoScroll()}),16)})),r(this,"handleAutoScroll",(function(){if(!i.DS.continue){var e=i.DS,t=e.stores.PointerStore,n=e.Area;i.currentEdges=E({elementRect:_(t.currentVal),containerRect:i.rect,tolerance:i._overflowTolerance}),i.currentEdges.length&&n.scroll(i.currentEdges,i._autoScrollSpeed)}})),r(this,"stopAutoScroll",(function(){i.currentEdges=[],clearInterval(i._scrollInterval)})),r(this,"isInside",(function(e,t){return!(!i.DS.Area.HTMLNode.contains(e)||!i.DS.stores.ScrollStore.canScroll)||I(i.rect,t||e.getBoundingClientRect())})),this._autoScrollSpeed=a,this._overflowTolerance=l,this.DS=o,this.HTMLNode=function(e){var t=document.createElement("div");return t.style.position="fixed",t.style.overflow="hidden",t.style.pointerEvents="none",t.style.zIndex="999999999999999999",t.classList.add(e),t}(s),this.DS.subscribe("Area:modified",this.updatePos),this.DS.subscribe("Interaction:init",this.start),this.DS.subscribe("Interaction:start",this.startAutoScroll),this.DS.subscribe("Interaction:end",(function(){i.updatePos(),i.stopAutoScroll()}))}return n(t,[{key:"isClicked",value:function(e){var t=this.DS.stores.PointerStore,n=e?t.getPointerPosition(e):t.initialVal;return I({left:n.x,top:n.y,right:n.x,bottom:n.y},this.rect)}},{key:"rect",get:function(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}]),t}(),U=function(){function t(n){var i=this,o=n.DS,s=n.multiSelectKeys,a=n.multiSelectMode;e(this,t),r(this,"_multiSelectMode",void 0),r(this,"_multiSelectKeys",void 0),r(this,"_currentValues",new Set),r(this,"_keyMapping",{control:"ctrlKey",shift:"shiftKey",meta:"metaKey"}),r(this,"init",(function(){document.addEventListener("keydown",i.keydown),document.addEventListener("keyup",i.keyup),window.addEventListener("blur",i.reset)})),r(this,"keydown",(function(e){var t=e.key.toLowerCase();i.DS.publish("KeyStore:down:pre",{event:e,key:t}),i._currentValues.add(t),i.DS.publish("KeyStore:down",{event:e,key:t})})),r(this,"keyup",(function(e){var t=e.key.toLowerCase();i.DS.publish("KeyStore:up:pre",{event:e,key:t}),i._currentValues.delete(t),i.DS.publish("KeyStore:up",{event:e,key:t})})),r(this,"stop",(function(){document.removeEventListener("keydown",i.keydown),document.removeEventListener("keyup",i.reset),window.removeEventListener("blur",i.reset),i.reset()})),r(this,"reset",(function(){return i._currentValues.clear()})),this.DS=o,this._multiSelectMode=a,this._multiSelectKeys=s.map((function(e){var t={ctrlKey:"Control",shiftKey:"Shift",metaKey:"Meta"}[e];return t?(console.warn("[DragSelect] ".concat(e,' is deprecated. Use "').concat(t,'" instead. Act Now!. See docs for more info')),t.toLowerCase()):e.toLowerCase()})),this.DS.subscribe("Interaction:init",this.init)}return n(t,[{key:"isMultiSelectKeyPressed",value:function(e){var t=this;return!!this._multiSelectMode||(!!this.currentValues.some((function(e){return t._multiSelectKeys.includes(e)}))||!(!e||!this._multiSelectKeys.some((function(n){return e[t._keyMapping[n]]}))))}},{key:"currentValues",get:function(){return Array.from(this._currentValues.values())}}]),t}(),W=function(){function t(n){var i=this,o=n.DS,s=n.usePointerEvents,a=void 0!==s&&s;e(this,t),r(this,"_isMouseInteraction",!1),r(this,"_initialValArea",void 0),r(this,"_currentValArea",void 0),r(this,"_lastValArea",void 0),r(this,"_initialVal",void 0),r(this,"_currentVal",void 0),r(this,"_lastVal",void 0),r(this,"_lastTouch",void 0),r(this,"_usePointerEvents",void 0),r(this,"init",(function(){i._usePointerEvents?document.addEventListener("pointermove",i.update,{passive:!1}):document.addEventListener("mousemove",i.update),document.addEventListener("touchmove",i.update,{passive:!1})})),r(this,"getPointerPosition",(function(e){return function(e){var t=e.event;return{x:t.clientX,y:t.clientY}}({event:i._normalizedEvent(e)})})),r(this,"update",(function(e){e&&(i.DS.publish("PointerStore:updated:pre",{event:e}),i.currentVal=i.getPointerPosition(e),i._isMouseInteraction&&i.DS.publish("PointerStore:updated",{event:e}))})),r(this,"stop",(function(){i._usePointerEvents?document.removeEventListener("pointermove",i.update,{passive:!1}):document.removeEventListener("mousemove",i.update),document.removeEventListener("touchmove",i.update,{passive:!1}),setTimeout((function(){return i._isMouseInteraction=!1}),100)})),r(this,"reset",(function(e){e&&(i.currentVal=i.lastVal=i.getPointerPosition(e),i.stop(),i.init())})),this.DS=o,this._usePointerEvents=a,this.DS.subscribe("Interaction:init",this.init),this.DS.subscribe("Interaction:start",(function(e){var t=e.event;return i.start(t)})),this.DS.subscribe("Interaction:end",(function(e){var t=e.event;return i.reset(t)}))}return n(t,[{key:"start",value:function(e){e&&(this._isMouseInteraction=!0,this.currentVal=this.initialVal=this.getPointerPosition(e))}},{key:"_normalizedEvent",value:function(e){return"touches"in e&&"touchend"!==e.type&&(this._lastTouch=e),"touches"in e?this._lastTouch.touches[0]:e}},{key:"initialValArea",get:function(){return this._initialValArea?this._initialValArea:{x:0,y:0}}},{key:"currentValArea",get:function(){return this._currentValArea?this._currentValArea:{x:0,y:0}}},{key:"lastValArea",get:function(){return this._lastValArea?this._lastValArea:{x:0,y:0}}},{key:"initialVal",get:function(){return this._initialVal?this._initialVal:{x:0,y:0}},set:function(e){this._initialVal=e,this._initialValArea=e&&b(e,"-",b(y(this.DS.Area.rect),"+",y(this.DS.Area.computedBorder)))}},{key:"currentVal",get:function(){return this._currentVal?this._currentVal:{x:0,y:0}},set:function(e){this._currentVal=e,this._currentValArea=e&&b(e,"-",b(y(this.DS.Area.rect),"+",y(this.DS.Area.computedBorder)))}},{key:"lastVal",get:function(){return this._lastVal?this._lastVal:{x:0,y:0}},set:function(e){this._lastVal=e,this._lastValArea=e&&b(e,"-",b(y(this.DS.Area.rect),"+",y(this.DS.Area.computedBorder)))}}]),t}(),F=function(){function t(n){var i=this,o=n.DS,s=n.areaElement,a=n.zoom;e(this,t),r(this,"_initialVal",void 0),r(this,"_currentVal",void 0),r(this,"_areaElement",void 0),r(this,"_canScroll",void 0),r(this,"init",(function(){return i._areaElement.addEventListener("scroll",i.update)})),r(this,"start",(function(){i._currentVal=i._initialVal=P(i._areaElement),i._areaElement.addEventListener("scroll",i.update)})),r(this,"update",(function(){return i._currentVal=P(i._areaElement)})),r(this,"stop",(function(){i._areaElement.removeEventListener("scroll",i.update),i._initialVal={x:0,y:0},i._canScroll=null})),r(this,"reset",(function(){i.stop(),i.start()})),this._areaElement=s,this.DS=o,this.zoom=a,this.DS.subscribe("Interaction:init",this.init),this.DS.subscribe("Interaction:start",(function(){return i.start()})),this.DS.subscribe("Interaction:end",(function(){return i.reset()}))}return n(t,[{key:"canScroll",get:function(){return"boolean"==typeof this._canScroll?this._canScroll:this._canScroll=(e=this._areaElement,!!((t=P(e)).x||t.y||(e instanceof HTMLDocument?e.body?e.body.scrollTop=1:e.documentElement.scrollTop=1:e.scrollTop=1)));var e,t}},{key:"scrollAmount",get:function(){var e,t=b(this.currentVal,"-",this.initialVal),n={x:e=this.zoom,y:e},r=b(b(t,"*",n),"-",t);return{x:t.x+r.x,y:t.y+r.y}}},{key:"initialVal",get:function(){return this._initialVal?this._initialVal:{x:0,y:0}}},{key:"currentVal",get:function(){return this._currentVal||(this._currentVal=P(this._areaElement)),this._currentVal}}]),t}(),Z=function(){function t(n){var i=this,o=n.area,s=void 0===o?document:o,a=n.selectables,l=void 0===a?[]:a,c=n.autoScrollSpeed,u=void 0===c?5:c,d=n.overflowTolerance,h=void 0===d?{x:25,y:25}:d,f=n.zoom,v=void 0===f?1:f,p=n.customStyles,S=void 0!==p&&p,m=n.multiSelectMode,g=void 0!==m&&m,b=n.multiSelectToggling,y=void 0===b||b,_=n.multiSelectKeys,D=void 0===_?["Control","Shift","Meta"]:_,P=n.selector,E=void 0===P?void 0:P,w=n.draggability,k=void 0===w||w,x=n.immediateDrag,I=void 0===x||x,A=n.keyboardDrag,L=void 0===A||A,T=n.dragKeys,V=n.keyboardDragSpeed,Z=void 0===V?10:V,X=n.useTransform,Y=void 0===X||X,G=n.hoverClass,$=void 0===G?"ds-hover":G,q=n.selectableClass,J=void 0===q?"ds-selectable":q,Q=n.selectedClass,ee=void 0===Q?"ds-selected":Q,te=n.selectorClass,ne=void 0===te?"ds-selector":te,re=n.selectorAreaClass,ie=void 0===re?"ds-selector-area":re,oe=n.callback,se=n.onDragMove,ae=n.onDragStartBegin,le=n.onDragStart,ce=n.onElementSelect,ue=n.onElementUnselect,de=n.usePointerEvents,he=void 0!==de&&de;e(this,t),r(this,"continue",!1),r(this,"start",(function(){i.stopped=!1,i.Interaction.init()})),r(this,"break",(function(){return i.continue=!0})),r(this,"getSelection",(function(){return i.SelectedSet.elements})),r(this,"getSelectables",(function(){return i.SelectableSet.elements})),r(this,"getInitialCursorPosition",(function(){return i.stores.PointerStore.initialVal})),r(this,"getCurrentCursorPosition",(function(){return i.stores.PointerStore.currentVal})),r(this,"getPreviousCursorPosition",(function(){return i.stores.PointerStore.lastVal})),r(this,"getInitialCursorPositionArea",(function(){return i.stores.PointerStore.initialValArea})),r(this,"getCurrentCursorPositionArea",(function(){return i.stores.PointerStore.currentValArea})),r(this,"getPreviousCursorPositionArea",(function(){return i.stores.PointerStore.lastValArea})),r(this,"isMultiSelect",(function(e){return i.stores.KeyStore.isMultiSelectKeyPressed(e)})),r(this,"isDragging",(function(){return i.Interaction.isDragging})),this.PubSub=new O({DS:this}),this.subscribe=this.PubSub.subscribe,this.unsubscribe=this.PubSub.unsubscribe,this.publish=this.PubSub.publish,this._callbacksTemp({callback:oe,onDragMove:se,onDragStart:le,onDragStartBegin:ae,onElementSelect:ce,onElementUnselect:ue}),this.stores={PointerStore:new W({DS:this,usePointerEvents:he}),ScrollStore:new F({DS:this,areaElement:s,zoom:v}),KeyStore:new U({DS:this,multiSelectKeys:D,multiSelectMode:g})},this.Area=new N({area:s,PS:this.PubSub,zoom:v}),this.Selector=new R({DS:this,selector:E,selectorClass:ne,customStyles:S}),this.SelectorArea=new B({DS:this,selectorAreaClass:ie,autoScrollSpeed:u,overflowTolerance:h}),this.SelectableSet=new j({elements:l,DS:this,className:J,hoverClassName:$,useTransform:Y,draggability:k,usePointerEvents:he}),this.SelectedSet=new z({DS:this,className:ee}),this.Selection=new H({DS:this,hoverClassName:$,multiSelectToggling:y}),this.Drag=new M({DS:this,draggability:k,useTransform:Y,keyboardDrag:L,dragKeys:Object.assign({up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},T),zoom:v,keyboardDragSpeed:Z}),this.Interaction=new K({areaElement:s,DS:this,draggability:k,immediateDrag:I,selectableClass:J,usePointerEvents:he}),C({subscribe:this.subscribe,publish:this.publish,SelectedSet:this.SelectedSet,Interaction:this.Interaction}),this.subscribe("Interaction:end",(function(){return i.continue=!1})),this.start()}return n(t,[{key:"_callbacksTemp",value:function(e){var t=e.callback,n=e.onDragMove,r=e.onDragStart,i=e.onDragStartBegin,o=e.onElementSelect,s=e.onElementUnselect,a=function(e,t){return console.warn("[DragSelect] ".concat(e,' is deprecated. Use DragSelect.subscribe("').concat(t,'", (callbackObject) => {}) instead. Act Now! See docs for more info'))};t&&(a("callback","callback"),this.subscribe("callback",(function(e){var n=e.items,r=(e.item,e.event);return t(n,r)}))),n&&(a("onDragMove","dragmove"),this.subscribe("dragmove",(function(e){e.items,e.item;var t=e.event;return n(t)}))),r&&(a("onDragStart","dragstart"),this.subscribe("dragstart",(function(e){e.items,e.item;var t=e.event;return r(t)}))),i&&(a("onDragStartBegin","dragstart"),this.subscribe("dragstart",(function(e){e.items,e.item;var t=e.event;return i(t)}))),o&&(a("onElementSelect","elementselect"),this.subscribe("elementselect",(function(e){e.items;var t=e.item,n=e.event;return o(t,n)}))),s&&(a("onElementUnselect","elementunselect"),this.subscribe("elementunselect",(function(e){e.items;var t=e.item,n=e.event;return s(t,n)})))}},{key:"stop",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];n&&this.publish("callback",{items:this.getSelection()}),this.Interaction.stop(),this.Area.stop(),this.Drag.stop(),this.Selector.stop(),this.SelectorArea.stop(e),this.stores.KeyStore.stop(),this.stores.PointerStore.stop(),this.stores.ScrollStore.stop(),e&&this.SelectableSet.clear(),t&&this.SelectedSet.clear(),this.stopped=!0}},{key:"addSelection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.SelectedSet.addAll(T(e)),n||this.addSelectables(e),t&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"removeSelection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.SelectedSet.deleteAll(T(e)),n&&this.removeSelectables(e),t&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"toggleSelection",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return T(e).forEach((function(i){return t.SelectedSet.has(i)?t.removeSelection(e,n,r):t.addSelection(e,n,r)})),n&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"setSelection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.clearSelection(),this.addSelection(e,t,n),this.getSelection()}},{key:"clearSelection",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.SelectedSet.clear(),e&&this.PubSub.publish("callback",{items:this.getSelection()}),this.getSelection()}},{key:"addSelectables",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=T(e);return this.SelectableSet.addAll(n),t&&this.SelectedSet.addAll(n),e}},{key:"setSelectables",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.removeSelectables(e,t),this.addSelectables(e,n)}},{key:"removeSelectables",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.SelectableSet.deleteAll(T(e)),t&&this.removeSelection(e),e}},{key:"getCursorPositionDifference",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];console.warn("[DragSelect] Using .getCursorPositionDifference is deprecated. Calculate yourself instead. i.e. `.getCurrentCursorPosition().x - .getInitialCursorPosition().x`");var n=t?this.getCurrentCursorPositionArea():this.getCurrentCursorPosition(),r=e?t?this.getPreviousCursorPositionArea():this.getPreviousCursorPosition():t?this.getInitialCursorPositionArea():this.getInitialCursorPosition();return b(n,"-",r)}}]),t}();return Z})); diff --git a/src/multiselect_controls.js b/src/multiselect_controls.js index 698ace9..c256fbb 100644 --- a/src/multiselect_controls.js +++ b/src/multiselect_controls.js @@ -11,7 +11,7 @@ import * as Blockly from 'blockly/core'; -import DragSelect from '../lib/ds.min'; +import DragSelect from './lib/ds.min'; import {blockSelectionWeakMap, inMultipleSelectionModeWeakMap} from './global'; /** @@ -277,8 +277,7 @@ export class MultiselectControls { */ updateBlocks_(block) { if (block && - block.isDeletable() && - block.isMovable()) { + (block.isDeletable() || block.isMovable())) { if (this.blockSelection.has(block.id)) { this.blockSelection.delete(block.id); this.justUnselectedBlock_ = block;