@lyonbot/interactive-blocks
Version:
Make interactive selectable, drag-and-drop, copy-and-paste ready, Block and Slot components easily! Works with Vue, React and any MV* framework.
3 lines (2 loc) • 23.3 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).InteractiveBlocks={})}(this,function(t){function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},i.apply(this,arguments)}function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function s(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function a(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return c(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l=function(t,e,n){var i=t._listeners;i[e]?i[e].push(n):i[e]=[n]},u=function(){function t(){this._listeners={}}var e=t.prototype;return e.on=function(t,e){return l(this,t,{listener:e}),this},e.once=function(t,e){return l(this,t,{listener:e,once:!0}),this},e.off=function(t,e){var n=this._listeners[t];if(!n)return this;if(1===n.length&&e===n[0].listener)return this._listeners[t]=null,this;var i=n.findIndex(function(t){return t.listener===e});return-1!==i&&n.splice(i,1),this},e.emit=function(t){var e=arguments,n=this._listeners[t];if(n){var i=!1;n.forEach(function(t){t.listener([].slice.call(e,1)),t.once&&(i=!0)}),i&&(this._listeners[t]=n.filter(function(t){return!t.once}))}},e.removeAllListeners=function(){return this._listeners={},this},t}();function h(t,e){return!("object"!=typeof t||!t||!0!==t.isIBClipboardData||"string"==typeof e&&e!==t.ibContextBrand||"string"!=typeof t.ibContextBrand||"ibContextUUID"in t&&"string"!=typeof t.ibContextUUID||!Array.isArray(t.blocksData)||t.blocksData.some(function(t){return"object"!=typeof t||null===t}))}var v=function(){return function(t){var e=this;Object.assign(this,t),this.returnValue=!0,this.preventDefault=function(){e.returnValue=!1}}},f=v(),d=v(),p=v(),g=v(),S=v(),m=v(),k=function(t,e){return"function"==typeof t?t(e):t};function B(t,e){var n,i;function o(e){void 0===e&&(e=!1),n&&(e&&i&&t.apply(void 0,i),clearTimeout(n),n=null,i=void 0)}var r=function(){i=[].slice.call(arguments),n||(n=setTimeout(function(){return o(!0)},e))};return r.cancel=function(){return o(!1)},r.flush=function(){return o(!0)},r}function x(t,e){var n=e.map(function(e){return t[e]}).filter(function(t){return void 0!==t});return[].concat(e).sort(function(t,e){return e-t}).forEach(function(e){return t.splice(e,1)}),n}function y(t,e){if("camelCase"===e)return t;var n={};return Object.keys(t).forEach(function(i){var o,r=i;"react"===e?r="on"+(null==(o=r[0])?void 0:o.toUpperCase())+r.slice(1):"lowercase"!==e&&"vue"!==e&&e||(r=r.toLowerCase()),n[r]=t[i]}),n}var b=function(){var t=e.prototype;function e(t,e,n){var i=this;this.type="block",this.ctx=void 0,this.ownerSlot=void 0,this.slots=new Set,this.info=void 0,this._activeNumber=!1,this.handlePointerUp=function(t){i.ctx.handleBlockPointerUp(i,t)},this.ctx=t,this.ownerSlot=e,e&&e.items.add(this),this.info=n}return t._maybeUpdateActiveNumber=function(t){var e,n;return this._activeNumber!==t&&(this._activeNumber=t,null==(e=(n=this.info).onStatusChange)||e.call(n,this),!0)},t.select=function(t){this.ctx.addBlockToSelection(this,t)},t.unselect=function(){this.isActive&&(this.ctx.activeBlocks.delete(this),this.ctx.syncActiveElementStatus())},t.focus=function(t){this.isActive||this.select(t),this.ctx.focus()},t.createSlot=function(t){return this.ctx.createSlot(t,this)},t.getDOMEvents=function(t,e){void 0===e&&(e={});var n={pointerUp:this.handlePointerUp};return e.draggable&&Object.assign(n,this.ctx.dragging.getBlockDOMEventHandlers(this)),y(n,t)},t.dispose=function(){var t;this.ctx.activeBlocks.has(this)&&(this.ctx.activeBlocks.delete(this),this.ctx.syncActiveElementStatus()),null==(t=this.ownerSlot)||t.items.delete(this),this.slots.forEach(function(t){return t.dispose()}),this.slots.clear(),this.info=A},n(e,[{key:"activeNumber",get:function(){return this._activeNumber}},{key:"isActive",get:function(){return!1!==this._activeNumber}},{key:"hasFocus",get:function(){return this.isActive&&this.ctx.hasFocus}},{key:"ref",get:function(){return this.info.ref}},{key:"index",get:function(){return k(this.info.index,this)}},{key:"data",get:function(){return k(this.info.data,this)}}]),e}(),A={index:function(){throw new Error("Accessing a disposed block")},data:function(){throw new Error("Accessing a disposed block")}};function D(t,e){if(t)for(var n,i=0,o=a(t);!(n=o()).done;){var r=n.value;if(e(r,i))return r;i+=1}}function w(t){if(t)return t[Symbol.iterator]().next().value}var E="webkitRequestAnimationFrame"in window,C="x-block-context/uuid",T=document.createElement("div");T.style.cssText="position:fixed;pointer-events:none;left:0;top:0;background: #FFF; border: 1px solid #000; padding: 4px 8px;transform:translate(-50%, -50%)";var I=function(t){function e(e){var n;return(n=t.call(this)||this).ctx=void 0,n.draggingBlocks=void 0,n.slotOfDraggingBlocks=void 0,n.isHovering=!1,n.hoveringSlot=void 0,n.hoveringBlock=void 0,n.dropEffect=void 0,n.setHoveringSlot=B(n._originalSetHoveringSlot.bind(s(n)),50),n.ctx=e,n}o(e,t);var n=e.prototype;return n.dispose=function(){this.removeAllListeners(),this.setHoveringSlot.cancel()},n._originalSetHoveringSlot=function(t,e){var n;if(t&&"number"!=typeof e)throw new Error("Cannot setHoveringSlot with indexToDrop unknown");if(t!==this.hoveringSlot){var i=this.hoveringSlot;(null==(n=this.hoveringBlock)?void 0:n.ownerSlot)!==t&&(this.hoveringBlock=void 0),this.hoveringSlot=t,this.isHovering=!!t,i&&(i.isDragHovering=!1,i.indexToDrop=void 0,null==i.info.onDragHoverStatusChange||i.info.onDragHoverStatusChange(this.ctx)),t&&(t.isDragHovering=!0,t.indexToDrop=e,null==t.info.onDragHoverStatusChange||t.info.onDragHoverStatusChange(this.ctx)),this.emit("hoverChanged",this.ctx)}else t&&t.indexToDrop!==e&&(t.indexToDrop=e,null==t.info.onDragHoverStatusChange||t.info.onDragHoverStatusChange(this.ctx),this.emit("hoverChanged",this.ctx))},n.getBlockDOMEventHandlers=function(t){return{dragStart:this.handleBlockDragStart.bind(this,t),dragEnd:this.handleBlockDragEnd.bind(this,t),dragOver:this.handleBlockDragOver.bind(this,t),dragLeave:this.handleBlockDragLeave.bind(this,t)}},n.handleBlockDragStart=function(t,e){var n=e.dataTransfer;if(n){this.ctx.activeBlocks.has(t)||this.ctx.addBlockToSelection(t,"none");var i=this.ctx.options.serializeForClipboard(this.ctx.dumpSelectedData());if(i){var o=Array.from(this.ctx.activeBlocks),r=new S({type:"blockDragStart",text:i,blocks:o,ctx:this.ctx,currentBlock:t,dataTransfer:n,event:e});if(null==t.info.onDragStart||t.info.onDragStart(r),this.emit("blockDragStart",r),!1!==r.returnValue){e.stopPropagation(),n.setData("text/plain",r.text),n.setData(C,this.ctx.uuid),n.setData("x-block-context/brand-"+this.ctx.brand,"true"),o.length>1&&(document.body.appendChild(T),T.style.left=e.clientX+"px",T.style.top=e.clientY+"px",setTimeout(function(){return T.remove()},100),T.textContent=o.length+" items",n.setDragImage(T,T.offsetWidth/2,T.offsetHeight/2));var s=this.ctx.slotOfActiveBlocks;this.draggingBlocks=o,this.slotOfDraggingBlocks=s||void 0,s&&(this.setHoveringSlot(s,t.index),this.setHoveringSlot.flush())}}}},n.handleBlockDragEnd=function(){this.slotOfDraggingBlocks=void 0,this.draggingBlocks=void 0,this.setHoveringSlot(void 0)},n.handleBlockDragOver=function(t){this.hoveringBlock!==t&&t.ownerSlot==this.hoveringSlot&&(this.hoveringBlock=t,this.emit("hoverChanged",this.ctx))},n.handleBlockDragLeave=function(t){this.hoveringBlock===t&&(this.hoveringBlock=void 0,this.emit("hoverChanged",this.ctx))},n.getSlotDOMEventHandlers=function(t){var e=this;return{dragOver:function(n){e.handleSlotDragOver(t,n)&&(n.preventDefault(),n.stopPropagation())},dragLeave:function(n){e.handleSlotDragLeave(t),n.preventDefault(),n.stopPropagation()},drop:function(n){e.handleSlotDrop(t,n),n.preventDefault(),n.stopPropagation()}}},n.handleSlotDragOver=function(t,e){var n;if(null!=(n=e.dataTransfer)&&n.types.includes(C)&&!e.dataTransfer.types.includes("x-block-context/brand-"+this.ctx.brand))return!1;var i=this.computeIndexToDrop(t,e);return!1!==i&&(this.setHoveringSlot(t,i),!0)},n.handleSlotDrop=function(t,e){var n=this.computeIndexToDrop(t,e);if(!1!==n){var i=this.dropEffect,o=this.draggingBlocks,r=this.ctx,s=new m({type:"slotBeforeDrop",ctx:r,slot:t,dropEffect:i,dataTransfer:e.dataTransfer,event:e,indexToDrop:n,isDraggingFromCurrentCtx:!!o,draggingBlocks:o});if(this.emit("slotBeforeDrop",s),!1===s.returnValue)return this.setHoveringSlot(void 0),void this.setHoveringSlot.flush();if(this.setHoveringSlot(t,n),this.setHoveringSlot.flush(),o&&"copy"!==i)if(t===r.slotOfActiveBlocks){var c=n-o.filter(function(t){return t.index<n}).length,a=new p({type:"moveInSlot",blocks:o,ctx:r,slot:t,index:c});if(null==t.info.onMoveInSlot||t.info.onMoveInSlot(a),r.emit("moveInSlot",a),!a.returnValue)return;setTimeout(function(){r.activeSlot=t,r.activeBlocks.clear(),t.items.forEach(function(t){var e=t.index;e>=c&&e<c+o.length&&r.activeBlocks.add(t)}),r.syncActiveElementStatus(),r.focus()},100)}else{var l=n,u=new g({type:"moveBetweenSlots",blocks:o,ctx:r,fromSlot:r.slotOfActiveBlocks,toSlot:t,index:l});if(null==t.info.onMoveToThisSlot||t.info.onMoveToThisSlot(u),r.emit("moveBetweenSlots",u),!u.returnValue)return;setTimeout(function(){r.activeSlot=t,r.activeBlocks.clear(),t.items.forEach(function(t){var e=t.index;e>=l&&e<l+o.length&&r.activeBlocks.add(t)}),r.syncActiveElementStatus(),r.focus()},100)}else try{var h=this.ctx.options.unserializeForClipboard(e.dataTransfer.getData("text/plain"));r.activeSlot=t,r.activeBlocks.clear(),r.syncActiveElementStatus(),r.pasteWithData(h,n),r.focus()}catch(t){console.error("Failed to drop")}this.setHoveringSlot(void 0)}},n.handleSlotDragLeave=function(t){this.setHoveringSlot(void 0)},n.computeIndexToDrop=function(t,e){var n,i=e.dataTransfer.dropEffect;if("none"===i&&E&&(i=e.ctrlKey||e.altKey?"copy":"move"),this.dropEffect=i,"copy"!==this.dropEffect&&null!=(n=this.draggingBlocks)&&n.some(function(e){return t.isDescendantOfBlock(e)}))return!1;var o,r,s=null==t.info.computeIndexToDrop?void 0:t.info.computeIndexToDrop({ctx:this.ctx,slot:t,isDraggingFromCurrentCtx:!!this.draggingBlocks,draggingBlocks:this.draggingBlocks,dataTransfer:e.dataTransfer,dropEffect:this.dropEffect,currentTarget:e.currentTarget,clientX:e.clientX,clientY:e.clientY,offsetX:e.offsetX,offsetY:e.offsetY});return!1!==s&&(void 0===s?null!=(o=null==(r=this.hoveringBlock)?void 0:r.index)?o:function(t,e,n){if(!t)return 0;for(var i,o=0,r=a(t);!(i=r()).done;)o=Math.max(o,i.value.index+1);return o}(t.items):s)},e}(u),O=function(){function t(t,e,n){var i=this;this.type="slot",this.ctx=void 0,this.ownerBlock=void 0,this.items=new Set,this.info=void 0,this.handlePointerUp=function(t){i.ctx.handleSlotPointerUp(i,t)},this._isActive=!1,this.ctx=t,this.ownerBlock=e,e&&e.slots.add(this),this.info=n}var e=t.prototype;return e.createBlock=function(t){return this.ctx.createBlock(t,this)},e._maybeUpdateActive=function(t){var e,n;return this._isActive!==t&&(this._isActive=t,null==(e=(n=this.info).onStatusChange)||e.call(n,this),!0)},e.select=function(){this.ctx.activeSlot=this,this.ctx.activeBlocks=this.ctx.options.multipleSelect?new Set(this.items):this.items.size?new Set([w(this.items)]):new Set,this.ctx.syncActiveElementStatus()},e.focus=function(){this.isActive||(this.ctx.activeBlocks.clear(),this.ctx.activeSlot=this,this.ctx.syncActiveElementStatus()),this.ctx.focus()},e.isDescendantOfBlock=function(t){for(var e=this.ownerBlock;e;){var n;if(e===t)return!0;e=null==(n=e.ownerSlot)?void 0:n.ownerBlock}return!1},e.isDescendantOfSlot=function(t){for(var e,n=null==(e=this.ownerBlock)?void 0:e.ownerSlot;n;){var i;if(n===t)return!0;n=null==(i=n.ownerBlock)?void 0:i.ownerSlot}return!1},e.getDOMEvents=function(t,e){void 0===e&&(e={});var n={pointerUp:this.handlePointerUp};return e.draggable&&Object.assign(n,this.ctx.dragging.getSlotDOMEventHandlers(this)),y(n,t)},e.dispose=function(){var t,e=!1;this.ctx.slotOfActiveBlocks===this&&(this.ctx.activeBlocks.clear(),e=!0),this.ctx.activeSlot===this&&(this.ctx.activeSlot=null,e=!0),e&&this.ctx.syncActiveElementStatus(),null==(t=this.ownerBlock)||t.slots.delete(this),this.items.forEach(function(t){return t.dispose()}),this.items.clear(),this.info={}},n(t,[{key:"ref",get:function(){return this.info.ref}},{key:"isActive",get:function(){return this._isActive}},{key:"hasFocus",get:function(){return this.isActive&&this.ctx.hasFocus}}]),t}(),H={brand:"",deactivateHandlersWhenBlur:!0,navigateWithArrowKeys:!0,handleDeleteKey:!0,multipleSelect:!0,serializeForClipboard:function(t){return JSON.stringify(t)},unserializeForClipboard:function(t){return JSON.parse(t)}};t.BlockContext=function(t){function e(e){var n;void 0===e&&(e={}),(n=t.call(this)||this).hiddenInput=void 0,n._lastActiveElement=null,n.hasFocus=!1,n.options=void 0,n.brand="",n.uuid=Date.now().toString(36)+"-"+Math.random().toString(36),n.dragging=new I(s(n)),n.activeBlocks=new Set,n.slotOfActiveBlocks=null,n.activeSlot=null,n.lastActiveSlot=null,n.lastActiveBlocks=void 0,n.isFocusingBlock=void 0,n.isFocusingSlot=void 0,n.focusingElement=void 0,n.handleSlotPointerUp=function(t,e){(!e||e.eventPhase!==Event.CAPTURING_PHASE)&&n.isFocusingSlot||(n.isFocusingSlot=t,n.focusingElement||(n.focusingElement=null==e?void 0:e.currentTarget))},n.handleBlockPointerUp=function(t,e){(!e||e.eventPhase!==Event.CAPTURING_PHASE)&&n.isFocusingBlock||(n.isFocusingBlock=t,n.focusingElement||(n.focusingElement=null==e?void 0:e.currentTarget))},n.handleGlobalPointerUp=function(t){var e=n.isFocusingBlock,i=n.isFocusingSlot,o=n.focusingElement;if(n.isFocusingBlock=void 0,n.isFocusingSlot=void 0,n.focusingElement=void 0,e?(n.activeSlot=i||null,n.addBlockToSelection(e,t)):(n.activeSlot=i||null,n.options.deactivateHandlersWhenBlur&&n.activeBlocks.size>0&&n.activeBlocks.clear()),n.syncActiveElementStatus(),o){var r=null==o.getRootNode?void 0:o.getRootNode();(null==r?void 0:r.activeElement)===o&&n.focus()}},n.options=i({},H,e),n.brand=String(n.options.brand),document.addEventListener("pointerup",n.handleGlobalPointerUp,!1);var o=n.hiddenInput=document.createElement("textarea");o.style.cssText="opacity:0;left:0;top:0;position:fixed;width:2px;height:2px",o.tabIndex=-1,o.inputMode="none",o.ownerDocument.body.appendChild(o);var r=function(t){var e,i=n.options.serializeForClipboard(n.dumpSelectedData());i&&(t.preventDefault(),null==(e=t.clipboardData)||e.setData("text/plain",i))};return o.addEventListener("copy",function(t){r(t)},!1),o.addEventListener("cut",function(t){r(t),n.deleteActiveBlocks()},!1),o.addEventListener("paste",function(t){t.preventDefault();try{var e,i=null==(e=t.clipboardData)?void 0:e.getData("text/plain");if(!i)return;var o=n.options.unserializeForClipboard(i);n.pasteWithData(o)}catch(t){console.error("Failed to paste!",t)}},!1),o.addEventListener("focus",function(){var t;n.hasFocus=!0,n.emit("focus",s(n)),n.activeBlocks.forEach(function(t){return null==t.info.onStatusChange?void 0:t.info.onStatusChange(t)}),null==(t=n.activeSlot)||null==t.info.onStatusChange||t.info.onStatusChange(n.activeSlot)},!1),o.addEventListener("blur",function(){var t;n.hasFocus=!1,n._lastActiveElement=null,n.emit("blur",s(n)),n.activeBlocks.forEach(function(t){return null==t.info.onStatusChange?void 0:t.info.onStatusChange(t)}),null==(t=n.activeSlot)||null==t.info.onStatusChange||t.info.onStatusChange(n.activeSlot)},!1),o.addEventListener("keydown",function(t){var e=n.options;switch(t.code){case"KeyA":var i,o;e.multipleSelect&&(t.ctrlKey||t.metaKey)&&(n.activeBlocks=new Set(Array.from((null==(i=n.slotOfActiveBlocks)?void 0:i.items)||(null==(o=n.activeSlot)?void 0:o.items)||[]).sort(function(t,e){return t.index-e.index})),n.syncActiveElementStatus());break;case"ArrowUp":e.navigateWithArrowKeys&&n.activeNextBlock(-1,t.shiftKey||t.ctrlKey||t.metaKey);break;case"ArrowDown":e.navigateWithArrowKeys&&n.activeNextBlock(1,t.shiftKey||t.ctrlKey||t.metaKey);break;case"ArrowLeft":e.navigateWithArrowKeys&&n.activeParentBlock();break;case"ArrowRight":e.navigateWithArrowKeys&&n.activeChildrenBlocks();break;case"Delete":case"Backspace":e.handleDeleteKey&&n.deleteActiveBlocks();break;case"Tab":var r=n._lastActiveElement;if(r&&"focus"in r){var s=-1===r.tabIndex&&r.querySelector("[tabIndex], button, textarea, input, select, a, [contentEditable]");s&&"focus"in s?s.focus():r.focus()}t.preventDefault()}},!1),n}o(e,t);var n=e.prototype;return n.focus=function(){document.activeElement!==this.hiddenInput&&(this._lastActiveElement=document.activeElement,this.hiddenInput.focus())},n.dumpSelectedData=function(){var t={isIBClipboardData:!0,ibContextBrand:this.brand,ibContextUUID:this.uuid,blocksData:[]};if(this.activeBlocks.forEach(function(e){t.blocksData.push(e.data)}),0!==t.blocksData.length)return t},n.copy=function(){this.hiddenInput.focus(),document.execCommand("copy")},n.pasteWithData=function(t,e){var n=this;if(!h(t,this.brand))throw new Error("Need a valid IBClipboardData object");var i=this.activeSlot;if(i){var o=w(this.activeBlocks),r=null!=e?e:i===(null==o?void 0:o.ownerSlot)?o.index:Math.max.apply(Math,[0].concat(Array.from(i.items.values(),function(t){return 1+t.index}))),s=new f({type:"paste",ctx:this,data:t,slot:i,index:r});null==i.info.onPaste||i.info.onPaste(s),this.emit("paste",s),!1!==s.returnValue&&setTimeout(function(){var e=t.blocksData.length+r-1,o=Array.from(i.items).filter(function(t){return t.index>=r&&t.index<=e});o.length&&(n.activeSlot=i,n.activeBlocks.clear(),o.forEach(function(t){return n.activeBlocks.add(t)}),n.syncActiveElementStatus())},100)}},n.deleteActiveBlocks=function(){var t,e=Array.from(this.activeBlocks.values()),n=null==(t=e[0])?void 0:t.ownerSlot;if(!n)return!1;var i=e[0].index,o=Array.from(e,function(t){return t.index}),r=new d({type:"cut",blocks:e,indexes:o,indexesDescending:o.slice().sort(function(t,e){return e-t}),ctx:this,slot:n});if(null==n.info.onCut||n.info.onCut(r),this.emit("cut",r),r.returnValue){var s=D(n.items,function(t){return t.index===i});s&&this.addBlockToSelection(s)}return r.returnValue},n.activeNextBlock=function(t,e){var n=this;void 0===e&&(e=!1);var i=e&&this.options.multipleSelect;this.focus();var o,r=!0,s=Array.from(this.activeBlocks);if(s.length||(r=!1,(s=Array.from((null==(o=this.activeSlot)?void 0:o.items)||[])).length)){var c=s[0].ownerSlot,a=s[0].index,l=a,u=s[0],h=u;s.slice(1).forEach(function(t){if(t.ownerSlot===c){var e=t.index;e>a&&(a=e,u=t),e<l&&(l=e,h=t)}});var v=t>0?a+t:l+t,f=D(null==c?void 0:c.items,function(t){return t.index===v});f?(i||this.activeBlocks.clear(),this.activeBlocks.add(f),this.activeSlot=c,this.syncActiveElementStatus()):r?i||(this.activeBlocks.clear(),s.length>1&&this.activeBlocks.add(t>0?u:h),this.syncActiveElementStatus()):(this.activeBlocks.clear(),i?s.forEach(function(t){return n.activeBlocks.add(t)}):this.activeBlocks.add(t>0?h:u),this.syncActiveElementStatus())}},n.activeParentBlock=function(){var t,e=null==(t=this.activeSlot)?void 0:t.ownerBlock;this.activeSlot=(null==e?void 0:e.ownerSlot)||null,this.activeBlocks.clear(),e&&this.activeBlocks.add(e),this.syncActiveElementStatus()},n.activeChildrenBlocks=function(){var t=this,e=w(this.activeBlocks),n=w(null==e?void 0:e.slots);if(n){if(this.activeSlot=n,this.activeBlocks.clear(),this.options.multipleSelect)n.items.forEach(function(e){return t.activeBlocks.add(e)});else{var i=w(n.items);i&&this.activeBlocks.add(i)}this.syncActiveElementStatus()}},n.syncActiveElementStatus=function(){var t,e,n=!1,i=this.lastActiveBlocks,o=this.lastActiveSlot,r=Array.from(this.activeBlocks),s=(null==(t=r[0])?void 0:t.ownerSlot)||null;r.length>1&&s!==this.activeSlot&&(this.activeSlot=s),!this.activeSlot&&s&&(this.activeSlot=s),r.forEach(function(t,e){null==i||i.delete(t),n=t._maybeUpdateActiveNumber(e)||n}),null==i||i.forEach(function(t){n=t._maybeUpdateActiveNumber(!1)||n}),this.activeSlot!==o&&(null==o||o._maybeUpdateActive(!1),null==(e=this.activeSlot)||e._maybeUpdateActive(!0),this.lastActiveSlot=this.activeSlot,n=!0),this.lastActiveBlocks=new Set(this.activeBlocks),this.slotOfActiveBlocks=s,n&&this.emit("activeElementChanged",this)},n.clearSelection=function(){this.activeBlocks.clear(),this.activeSlot=null,this.syncActiveElementStatus()},n.addBlockToSelection=function(t,e){var n;if(e=(n=e)?!0===n?"ctrl":"object"==typeof n?n.ctrlKey||n.metaKey?"ctrl":n.shiftKey?"shift":"none":"ctrl"===n?"ctrl":"shift"===n?"shift":"none":"none",this.options.multipleSelect||(e="none"),"none"===e)this.activeBlocks.clear(),this.activeBlocks.add(t);else{var i=w(this.activeBlocks);if(i&&i.ownerSlot!==t.ownerSlot){for(var o=[],r=i;r&&r.ownerSlot;)o.push(r.ownerSlot),r=r.ownerSlot.ownerBlock;for(var s=-1,c=t;c&&c.ownerSlot;c=c.ownerSlot.ownerBlock)if(-1!==(s=o.indexOf(c.ownerSlot))){t=c;break}-1===s?this.activeBlocks.clear():s>0&&(this.activeBlocks=new Set(Array.from(this.activeBlocks,function(t){for(var e=s;e>0;e--,t=t.ownerSlot.ownerBlock);return t})))}this.activeSlot=t.ownerSlot||null,this.activeSlot||(e="ctrl")}if("ctrl"===e&&(this.activeBlocks.has(t)?this.activeBlocks.delete(t):this.activeBlocks.add(t)),"shift"===e){var a=this.activeSlot,l=t.index,u=l,h=l;this.activeBlocks.forEach(function(t){var e=t.index;u>e&&(u=e),h<e&&(h=e)}),this.activeBlocks=new Set(Array.from(a.items).filter(function(t){var e=t.index;return e>=u&&e<=h}).sort(function(t,e){return t.index-e.index}))}this.syncActiveElementStatus()},n.dispose=function(){var t;this.dragging.dispose(),null==(t=this.hiddenInput.parentElement)||t.removeChild(this.hiddenInput),document.removeEventListener("pointerup",this.handleGlobalPointerUp,!1)},n.createBlock=function(t,e){return void 0===e&&(e=null),new b(this,e,t)},n.createSlot=function(t,e){return void 0===e&&(e=null),new O(this,e,t)},e}(u),t.BlockHandler=b,t.EventEmitter=u,t.IBBlockDragStartAction=S,t.IBCutAction=d,t.IBMoveBetweenSlotsAction=g,t.IBMoveInSlotAction=p,t.IBPasteAction=f,t.IBSlotBeforeDropAction=m,t.SlotHandler=O,t.isIBClipboardData=h,t.moveItemsBetweenArrays=function(t,e,n,i){var o=x(t,e);n.splice.apply(n,[i,0].concat(o))},t.moveItemsInArray=function(t,e,n){var i=x(t,e);t.splice.apply(t,[n,0].concat(i))},t.removeItems=x,t.throttle=B});
//# sourceMappingURL=index.umd.js.map