UNPKG

@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) 20.3 kB
function t(){return t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},t.apply(this,arguments)}const e=(t,e,i)=>{const s=t._listeners;s[e]?s[e].push(i):s[e]=[i]};class i{constructor(){this._listeners={}}on(t,i){return e(this,t,{listener:i}),this}once(t,i){return e(this,t,{listener:i,once:!0}),this}off(t,e){const i=this._listeners[t];if(!i)return this;if(1===i.length&&e===i[0].listener)return this._listeners[t]=null,this;const s=i.findIndex(t=>t.listener===e);return-1!==s&&i.splice(s,1),this}emit(t,...e){const i=this._listeners[t];if(!i)return;let s=!1;i.forEach(t=>{t.listener(e),t.once&&(s=!0)}),s&&(this._listeners[t]=i.filter(t=>!t.once))}removeAllListeners(){return this._listeners={},this}}function s(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(t=>"object"!=typeof t||null===t))}const o=()=>function(t){Object.assign(this,t),this.returnValue=!0,this.preventDefault=()=>{this.returnValue=!1}},n=o(),l=o(),c=o(),r=o(),a=o(),h=o(),d=(t,e)=>"function"==typeof t?t(e):t;function v(t,e){let i,s;function o(e=!1){i&&(e&&s&&t(...s),clearTimeout(i),i=null,s=void 0)}const n=function(...t){s=t,i||(i=setTimeout(()=>o(!0),e))};return n.cancel=()=>o(!1),n.flush=()=>o(!0),n}function u(t,e){const i=e.map(e=>t[e]).filter(t=>void 0!==t);return[...e].sort((t,e)=>e-t).forEach(e=>t.splice(e,1)),i}function f(t,e,i){const s=u(t,e);t.splice(i,0,...s)}function g(t,e,i,s){const o=u(t,e);i.splice(s,0,...o)}function p(t,e){if("camelCase"===e)return t;const i={};return Object.keys(t).forEach(s=>{var o;let n=s;"react"===e?n=`on${null==(o=n[0])?void 0:o.toUpperCase()}${n.slice(1)}`:"lowercase"!==e&&"vue"!==e&&e||(n=n.toLowerCase()),i[n]=t[s]}),i}class S{get activeNumber(){return this._activeNumber}get isActive(){return!1!==this._activeNumber}get hasFocus(){return this.isActive&&this.ctx.hasFocus}get ref(){return this.info.ref}_maybeUpdateActiveNumber(t){var e,i;return this._activeNumber!==t&&(this._activeNumber=t,null==(e=(i=this.info).onStatusChange)||e.call(i,this),!0)}select(t){this.ctx.addBlockToSelection(this,t)}unselect(){this.isActive&&(this.ctx.activeBlocks.delete(this),this.ctx.syncActiveElementStatus())}focus(t){this.isActive||this.select(t),this.ctx.focus()}constructor(t,e,i){this.type="block",this.ctx=void 0,this.ownerSlot=void 0,this.slots=new Set,this.info=void 0,this._activeNumber=!1,this.handlePointerUp=t=>{this.ctx.handleBlockPointerUp(this,t)},this.ctx=t,this.ownerSlot=e,e&&e.items.add(this),this.info=i}get index(){return d(this.info.index,this)}get data(){return d(this.info.data,this)}createSlot(t){return this.ctx.createSlot(t,this)}getDOMEvents(t,e={}){const i={pointerUp:this.handlePointerUp};return e.draggable&&Object.assign(i,this.ctx.dragging.getBlockDOMEventHandlers(this)),p(i,t)}dispose(){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(t=>t.dispose()),this.slots.clear(),this.info=k}}const k={index:()=>{throw new Error("Accessing a disposed block")},data:()=>{throw new Error("Accessing a disposed block")}};function m(t,e){if(!t)return;let i=0;for(const s of t){if(e(s,i))return s;i+=1}}function x(t){if(t)return t[Symbol.iterator]().next().value}const B="webkitRequestAnimationFrame"in window,b=document.createElement("div");b.style.cssText="position:fixed;pointer-events:none;left:0;top:0;background: #FFF; border: 1px solid #000; padding: 4px 8px;transform:translate(-50%, -50%)";class y extends i{constructor(t){super(),this.ctx=void 0,this.draggingBlocks=void 0,this.slotOfDraggingBlocks=void 0,this.isHovering=!1,this.hoveringSlot=void 0,this.hoveringBlock=void 0,this.dropEffect=void 0,this.setHoveringSlot=v(this._originalSetHoveringSlot.bind(this),50),this.ctx=t}dispose(){this.removeAllListeners(),this.setHoveringSlot.cancel()}_originalSetHoveringSlot(t,e){var i;if(t&&"number"!=typeof e)throw new Error("Cannot setHoveringSlot with indexToDrop unknown");if(t===this.hoveringSlot)return void(t&&t.indexToDrop!==e&&(t.indexToDrop=e,null==t.info.onDragHoverStatusChange||t.info.onDragHoverStatusChange(this.ctx),this.emit("hoverChanged",this.ctx)));const s=this.hoveringSlot;(null==(i=this.hoveringBlock)?void 0:i.ownerSlot)!==t&&(this.hoveringBlock=void 0),this.hoveringSlot=t,this.isHovering=!!t,s&&(s.isDragHovering=!1,s.indexToDrop=void 0,null==s.info.onDragHoverStatusChange||s.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)}getBlockDOMEventHandlers(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)}}handleBlockDragStart(t,e){const i=e.dataTransfer;if(!i)return;this.ctx.activeBlocks.has(t)||this.ctx.addBlockToSelection(t,"none");const s=this.ctx.options.serializeForClipboard(this.ctx.dumpSelectedData());if(!s)return;const o=Array.from(this.ctx.activeBlocks),n=new a({type:"blockDragStart",text:s,blocks:o,ctx:this.ctx,currentBlock:t,dataTransfer:i,event:e});if(null==t.info.onDragStart||t.info.onDragStart(n),this.emit("blockDragStart",n),!1===n.returnValue)return;e.stopPropagation(),i.setData("text/plain",n.text),i.setData("x-block-context/uuid",this.ctx.uuid),i.setData(`x-block-context/brand-${this.ctx.brand}`,"true"),o.length>1&&(document.body.appendChild(b),b.style.left=`${e.clientX}px`,b.style.top=`${e.clientY}px`,setTimeout(()=>b.remove(),100),b.textContent=`${o.length} items`,i.setDragImage(b,b.offsetWidth/2,b.offsetHeight/2));const l=this.ctx.slotOfActiveBlocks;this.draggingBlocks=o,this.slotOfDraggingBlocks=l||void 0,l&&(this.setHoveringSlot(l,t.index),this.setHoveringSlot.flush())}handleBlockDragEnd(){this.slotOfDraggingBlocks=void 0,this.draggingBlocks=void 0,this.setHoveringSlot(void 0)}handleBlockDragOver(t){this.hoveringBlock!==t&&t.ownerSlot==this.hoveringSlot&&(this.hoveringBlock=t,this.emit("hoverChanged",this.ctx))}handleBlockDragLeave(t){this.hoveringBlock===t&&(this.hoveringBlock=void 0,this.emit("hoverChanged",this.ctx))}getSlotDOMEventHandlers(t){return{dragOver:e=>{this.handleSlotDragOver(t,e)&&(e.preventDefault(),e.stopPropagation())},dragLeave:e=>{this.handleSlotDragLeave(t),e.preventDefault(),e.stopPropagation()},drop:e=>{this.handleSlotDrop(t,e),e.preventDefault(),e.stopPropagation()}}}handleSlotDragOver(t,e){var i;if(null!=(i=e.dataTransfer)&&i.types.includes("x-block-context/uuid")&&!e.dataTransfer.types.includes(`x-block-context/brand-${this.ctx.brand}`))return!1;const s=this.computeIndexToDrop(t,e);return!1!==s&&(this.setHoveringSlot(t,s),!0)}handleSlotDrop(t,e){const i=this.computeIndexToDrop(t,e);if(!1===i)return;const s=this.dropEffect,o=this.draggingBlocks,n=this.ctx,l=new h({type:"slotBeforeDrop",ctx:n,slot:t,dropEffect:s,dataTransfer:e.dataTransfer,event:e,indexToDrop:i,isDraggingFromCurrentCtx:!!o,draggingBlocks:o});if(this.emit("slotBeforeDrop",l),!1===l.returnValue)return this.setHoveringSlot(void 0),void this.setHoveringSlot.flush();if(this.setHoveringSlot(t,i),this.setHoveringSlot.flush(),o&&"copy"!==s)if(t===n.slotOfActiveBlocks){const e=i-o.filter(t=>t.index<i).length,s=new c({type:"moveInSlot",blocks:o,ctx:n,slot:t,index:e});if(null==t.info.onMoveInSlot||t.info.onMoveInSlot(s),n.emit("moveInSlot",s),!s.returnValue)return;setTimeout(()=>{n.activeSlot=t,n.activeBlocks.clear(),t.items.forEach(t=>{const i=t.index;i>=e&&i<e+o.length&&n.activeBlocks.add(t)}),n.syncActiveElementStatus(),n.focus()},100)}else{const e=i,s=new r({type:"moveBetweenSlots",blocks:o,ctx:n,fromSlot:n.slotOfActiveBlocks,toSlot:t,index:e});if(null==t.info.onMoveToThisSlot||t.info.onMoveToThisSlot(s),n.emit("moveBetweenSlots",s),!s.returnValue)return;setTimeout(()=>{n.activeSlot=t,n.activeBlocks.clear(),t.items.forEach(t=>{const i=t.index;i>=e&&i<e+o.length&&n.activeBlocks.add(t)}),n.syncActiveElementStatus(),n.focus()},100)}else try{const s=this.ctx.options.unserializeForClipboard(e.dataTransfer.getData("text/plain"));n.activeSlot=t,n.activeBlocks.clear(),n.syncActiveElementStatus(),n.pasteWithData(s,i),n.focus()}catch(t){console.error("Failed to drop")}this.setHoveringSlot(void 0)}handleSlotDragLeave(t){this.setHoveringSlot(void 0)}computeIndexToDrop(t,e){var i;let s=e.dataTransfer.dropEffect;if("none"===s&&B&&(s=e.ctrlKey||e.altKey?"copy":"move"),this.dropEffect=s,"copy"!==this.dropEffect&&null!=(i=this.draggingBlocks)&&i.some(e=>t.isDescendantOfBlock(e)))return!1;const o=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!==o&&(void 0===o?null!=(n=null==(l=this.hoveringBlock)?void 0:l.index)?n:function(t,e,i){if(!t)return 0;let s=0,o=0;for(const e of t)o=Math.max(o,e.index+1),s+=1;return o}(t.items):o);var n,l}}class D{constructor(t,e,i){this.type="slot",this.ctx=void 0,this.ownerBlock=void 0,this.items=new Set,this.info=void 0,this.handlePointerUp=t=>{this.ctx.handleSlotPointerUp(this,t)},this._isActive=!1,this.ctx=t,this.ownerBlock=e,e&&e.slots.add(this),this.info=i}createBlock(t){return this.ctx.createBlock(t,this)}get ref(){return this.info.ref}get isActive(){return this._isActive}get hasFocus(){return this.isActive&&this.ctx.hasFocus}_maybeUpdateActive(t){var e,i;return this._isActive!==t&&(this._isActive=t,null==(e=(i=this.info).onStatusChange)||e.call(i,this),!0)}select(){this.ctx.activeSlot=this,this.ctx.activeBlocks=this.ctx.options.multipleSelect?new Set(this.items):this.items.size?new Set([x(this.items)]):new Set,this.ctx.syncActiveElementStatus()}focus(){this.isActive||(this.ctx.activeBlocks.clear(),this.ctx.activeSlot=this,this.ctx.syncActiveElementStatus()),this.ctx.focus()}isDescendantOfBlock(t){let e=this.ownerBlock;for(;e;){var i;if(e===t)return!0;e=null==(i=e.ownerSlot)?void 0:i.ownerBlock}return!1}isDescendantOfSlot(t){var e;let i=null==(e=this.ownerBlock)?void 0:e.ownerSlot;for(;i;){var s;if(i===t)return!0;i=null==(s=i.ownerBlock)?void 0:s.ownerSlot}return!1}getDOMEvents(t,e={}){const i={pointerUp:this.handlePointerUp};return e.draggable&&Object.assign(i,this.ctx.dragging.getSlotDOMEventHandlers(this)),p(i,t)}dispose(){var t;let 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(t=>t.dispose()),this.items.clear(),this.info={}}}const A={brand:"",deactivateHandlersWhenBlur:!0,navigateWithArrowKeys:!0,handleDeleteKey:!0,multipleSelect:!0,serializeForClipboard:t=>JSON.stringify(t),unserializeForClipboard:t=>JSON.parse(t)};class E extends i{constructor(e={}){super(),this.hiddenInput=void 0,this._lastActiveElement=null,this.hasFocus=!1,this.options=void 0,this.brand="",this.uuid=`${Date.now().toString(36)}-${Math.random().toString(36)}`,this.dragging=new y(this),this.activeBlocks=new Set,this.slotOfActiveBlocks=null,this.activeSlot=null,this.lastActiveSlot=null,this.lastActiveBlocks=void 0,this.isFocusingBlock=void 0,this.isFocusingSlot=void 0,this.focusingElement=void 0,this.handleSlotPointerUp=(t,e)=>{(!e||e.eventPhase!==Event.CAPTURING_PHASE)&&this.isFocusingSlot||(this.isFocusingSlot=t,this.focusingElement||(this.focusingElement=null==e?void 0:e.currentTarget))},this.handleBlockPointerUp=(t,e)=>{(!e||e.eventPhase!==Event.CAPTURING_PHASE)&&this.isFocusingBlock||(this.isFocusingBlock=t,this.focusingElement||(this.focusingElement=null==e?void 0:e.currentTarget))},this.handleGlobalPointerUp=t=>{const e=this.isFocusingBlock,i=this.isFocusingSlot,s=this.focusingElement;if(this.isFocusingBlock=void 0,this.isFocusingSlot=void 0,this.focusingElement=void 0,e?(this.activeSlot=i||null,this.addBlockToSelection(e,t)):(this.activeSlot=i||null,this.options.deactivateHandlersWhenBlur&&this.activeBlocks.size>0&&this.activeBlocks.clear()),this.syncActiveElementStatus(),s){const t=null==s.getRootNode?void 0:s.getRootNode();(null==t?void 0:t.activeElement)===s&&this.focus()}},this.options=t({},A,e),this.brand=String(this.options.brand),document.addEventListener("pointerup",this.handleGlobalPointerUp,!1);const i=this.hiddenInput=document.createElement("textarea");i.style.cssText="opacity:0;left:0;top:0;position:fixed;width:2px;height:2px",i.tabIndex=-1,i.inputMode="none",i.ownerDocument.body.appendChild(i);const s=t=>{var e;const i=this.options.serializeForClipboard(this.dumpSelectedData());i&&(t.preventDefault(),null==(e=t.clipboardData)||e.setData("text/plain",i))};i.addEventListener("copy",t=>{s(t)},!1),i.addEventListener("cut",t=>{s(t),this.deleteActiveBlocks()},!1),i.addEventListener("paste",t=>{t.preventDefault();try{var e;const i=null==(e=t.clipboardData)?void 0:e.getData("text/plain");if(!i)return;const s=this.options.unserializeForClipboard(i);this.pasteWithData(s)}catch(t){console.error("Failed to paste!",t)}},!1),i.addEventListener("focus",()=>{var t;this.hasFocus=!0,this.emit("focus",this),this.activeBlocks.forEach(t=>null==t.info.onStatusChange?void 0:t.info.onStatusChange(t)),null==(t=this.activeSlot)||null==t.info.onStatusChange||t.info.onStatusChange(this.activeSlot)},!1),i.addEventListener("blur",()=>{var t;this.hasFocus=!1,this._lastActiveElement=null,this.emit("blur",this),this.activeBlocks.forEach(t=>null==t.info.onStatusChange?void 0:t.info.onStatusChange(t)),null==(t=this.activeSlot)||null==t.info.onStatusChange||t.info.onStatusChange(this.activeSlot)},!1),i.addEventListener("keydown",t=>{const e=this.options;switch(t.code){case"KeyA":var i,s;e.multipleSelect&&(t.ctrlKey||t.metaKey)&&(this.activeBlocks=new Set(Array.from((null==(i=this.slotOfActiveBlocks)?void 0:i.items)||(null==(s=this.activeSlot)?void 0:s.items)||[]).sort((t,e)=>t.index-e.index)),this.syncActiveElementStatus());break;case"ArrowUp":e.navigateWithArrowKeys&&this.activeNextBlock(-1,t.shiftKey||t.ctrlKey||t.metaKey);break;case"ArrowDown":e.navigateWithArrowKeys&&this.activeNextBlock(1,t.shiftKey||t.ctrlKey||t.metaKey);break;case"ArrowLeft":e.navigateWithArrowKeys&&this.activeParentBlock();break;case"ArrowRight":e.navigateWithArrowKeys&&this.activeChildrenBlocks();break;case"Delete":case"Backspace":e.handleDeleteKey&&this.deleteActiveBlocks();break;case"Tab":{const e=this._lastActiveElement;if(e&&"focus"in e){const t=-1===e.tabIndex&&e.querySelector("[tabIndex], button, textarea, input, select, a, [contentEditable]");t&&"focus"in t?t.focus():e.focus()}t.preventDefault()}}},!1)}focus(){document.activeElement!==this.hiddenInput&&(this._lastActiveElement=document.activeElement,this.hiddenInput.focus())}dumpSelectedData(){const t={isIBClipboardData:!0,ibContextBrand:this.brand,ibContextUUID:this.uuid,blocksData:[]};if(this.activeBlocks.forEach(e=>{t.blocksData.push(e.data)}),0!==t.blocksData.length)return t}copy(){this.hiddenInput.focus(),document.execCommand("copy")}pasteWithData(t,e){if(!s(t,this.brand))throw new Error("Need a valid IBClipboardData object");const i=this.activeSlot;if(!i)return;const o=x(this.activeBlocks),l=null!=e?e:i===(null==o?void 0:o.ownerSlot)?o.index:Math.max(0,...Array.from(i.items.values(),t=>1+t.index)),c=new n({type:"paste",ctx:this,data:t,slot:i,index:l});null==i.info.onPaste||i.info.onPaste(c),this.emit("paste",c),!1!==c.returnValue&&setTimeout(()=>{const e=t.blocksData.length+l-1,s=Array.from(i.items).filter(t=>t.index>=l&&t.index<=e);s.length&&(this.activeSlot=i,this.activeBlocks.clear(),s.forEach(t=>this.activeBlocks.add(t)),this.syncActiveElementStatus())},100)}deleteActiveBlocks(){var t;const e=Array.from(this.activeBlocks.values()),i=null==(t=e[0])?void 0:t.ownerSlot;if(!i)return!1;const s=e[0].index,o=Array.from(e,t=>t.index),n=new l({type:"cut",blocks:e,indexes:o,indexesDescending:o.slice().sort((t,e)=>e-t),ctx:this,slot:i});if(null==i.info.onCut||i.info.onCut(n),this.emit("cut",n),n.returnValue){const t=m(i.items,t=>t.index===s);t&&this.addBlockToSelection(t)}return n.returnValue}activeNextBlock(t,e=!1){const i=e&&this.options.multipleSelect;this.focus();let s=!0,o=Array.from(this.activeBlocks);var n;if(!o.length&&(o=Array.from((null==(n=this.activeSlot)?void 0:n.items)||[]),s=!1,!o.length))return;const l=o[0].ownerSlot;let c=o[0].index,r=c,a=o[0],h=a;o.slice(1).forEach(t=>{if(t.ownerSlot!==l)return;const e=t.index;e>c&&(c=e,a=t),e<r&&(r=e,h=t)});const d=t>0?c+t:r+t,v=m(null==l?void 0:l.items,t=>t.index===d);v?(i||this.activeBlocks.clear(),this.activeBlocks.add(v),this.activeSlot=l,this.syncActiveElementStatus()):s?i||(this.activeBlocks.clear(),o.length>1&&this.activeBlocks.add(t>0?a:h),this.syncActiveElementStatus()):(this.activeBlocks.clear(),i?o.forEach(t=>this.activeBlocks.add(t)):this.activeBlocks.add(t>0?h:a),this.syncActiveElementStatus())}activeParentBlock(){var t;const 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()}activeChildrenBlocks(){const t=x(this.activeBlocks),e=x(null==t?void 0:t.slots);if(e){if(this.activeSlot=e,this.activeBlocks.clear(),this.options.multipleSelect)e.items.forEach(t=>this.activeBlocks.add(t));else{const t=x(e.items);t&&this.activeBlocks.add(t)}this.syncActiveElementStatus()}}syncActiveElementStatus(){var t;let e=!1;const i=this.lastActiveBlocks,s=this.lastActiveSlot,o=Array.from(this.activeBlocks),n=(null==(t=o[0])?void 0:t.ownerSlot)||null;var l;o.length>1&&n!==this.activeSlot&&(this.activeSlot=n),!this.activeSlot&&n&&(this.activeSlot=n),o.forEach((t,s)=>{null==i||i.delete(t),e=t._maybeUpdateActiveNumber(s)||e}),null==i||i.forEach(t=>{e=t._maybeUpdateActiveNumber(!1)||e}),this.activeSlot!==s&&(null==s||s._maybeUpdateActive(!1),null==(l=this.activeSlot)||l._maybeUpdateActive(!0),this.lastActiveSlot=this.activeSlot,e=!0),this.lastActiveBlocks=new Set(this.activeBlocks),this.slotOfActiveBlocks=n,e&&this.emit("activeElementChanged",this)}clearSelection(){this.activeBlocks.clear(),this.activeSlot=null,this.syncActiveElementStatus()}addBlockToSelection(t,e){var i;if(e=(i=e)?!0===i?"ctrl":"object"==typeof i?i.ctrlKey||i.metaKey?"ctrl":i.shiftKey?"shift":"none":"ctrl"===i?"ctrl":"shift"===i?"shift":"none":"none",this.options.multipleSelect||(e="none"),"none"===e)this.activeBlocks.clear(),this.activeBlocks.add(t);else{const i=x(this.activeBlocks);if(i&&i.ownerSlot!==t.ownerSlot){const e=[];for(let t=i;t&&t.ownerSlot;)e.push(t.ownerSlot),t=t.ownerSlot.ownerBlock;let s=-1;for(let i=t;i&&i.ownerSlot;i=i.ownerSlot.ownerBlock)if(-1!==(s=e.indexOf(i.ownerSlot))){t=i;break}-1===s?this.activeBlocks.clear():s>0&&(this.activeBlocks=new Set(Array.from(this.activeBlocks,t=>{for(let 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){const e=this.activeSlot,i=t.index;let s=i,o=i;this.activeBlocks.forEach(t=>{const e=t.index;s>e&&(s=e),o<e&&(o=e)}),this.activeBlocks=new Set(Array.from(e.items).filter(t=>{const e=t.index;return e>=s&&e<=o}).sort((t,e)=>t.index-e.index))}this.syncActiveElementStatus()}dispose(){var t;this.dragging.dispose(),null==(t=this.hiddenInput.parentElement)||t.removeChild(this.hiddenInput),document.removeEventListener("pointerup",this.handleGlobalPointerUp,!1)}createBlock(t,e=null){return new S(this,e,t)}createSlot(t,e=null){return new D(this,e,t)}}export{E as BlockContext,S as BlockHandler,i as EventEmitter,a as IBBlockDragStartAction,l as IBCutAction,r as IBMoveBetweenSlotsAction,c as IBMoveInSlotAction,n as IBPasteAction,h as IBSlotBeforeDropAction,D as SlotHandler,s as isIBClipboardData,g as moveItemsBetweenArrays,f as moveItemsInArray,u as removeItems,v as throttle}; //# sourceMappingURL=index.modern.js.map