diff --git a/dist/index.cjs b/dist/index.cjs index ce8ebc5e..ff658dd8 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -1249,11 +1249,6 @@ function copyNodeStyle(sourceNode, targetNode, omitKeys = false) { computedStyle.getPropertyPriority(key) ); } - for (const child of Array.from(sourceNode.children)) { - if (!isNode(child)) continue; - const targetChild = targetNode.children[Array.from(sourceNode.children).indexOf(child)]; - copyNodeStyle(child, targetChild, omitKeys); - } } function handleRootDragover(e) { if (!isDragState(state)) return; @@ -2368,7 +2363,9 @@ function initSynthDrag(node, parent, e, _state, draggedNodes2) { }); } else { if (!config.multiDrag || draggedNodes2.length === 1) { + console.log("boom"); dragImage = node.el.cloneNode(true); + copyNodeStyle(node.el, dragImage); dragImage.id = "dnd-dragged-node-clone"; display = dragImage.style.display; dragImage.setAttribute("popover", "manual"); @@ -2383,22 +2380,27 @@ function initSynthDrag(node, parent, e, _state, draggedNodes2) { }); } else { const wrapper = document.createElement("div"); - wrapper.setAttribute("popover", ""); + console.log("getting here"); + wrapper.setAttribute("popover", "manual"); for (const node2 of draggedNodes2) { const clonedNode = node2.el.cloneNode(true); + copyNodeStyle(node2.el, clonedNode); clonedNode.style.pointerEvents = "none"; wrapper.append(clonedNode); } - Object.assign(wrapper.style, { + display = wrapper.style.display; + wrapper.id = "dnd-dragged-node-clone"; + dragImage = wrapper; + Object.assign(dragImage.style, { display: "flex", flexDirection: "column", - left: "-9999px", position: "absolute", + overflow: "hidden", + margin: 0, + padding: 0, pointerEvents: "none", zIndex: 9999 }); - wrapper.id = "dnd-dragged-node-clone"; - dragImage = wrapper; } } dragImage.style.position = "absolute"; diff --git a/dist/index.cjs.map b/dist/index.cjs.map index 9f4d729e..7880324f 100644 --- a/dist/index.cjs.map +++ b/dist/index.cjs.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/plugins/animations/index.ts","../src/plugins/insert/index.ts","../src/plugins/drop-or-swap/index.ts"],"sourcesContent":["import type {\n DNDPlugin,\n DragAndDrop,\n DragState,\n DragStateProps,\n Node,\n NodeData,\n NodeDragEventData,\n NodeEventData,\n NodePointerEventData,\n NodeRecord,\n NodeTargetData,\n NodesData,\n ParentConfig,\n ParentData,\n ParentEventData,\n ParentTargetData,\n ParentsData,\n PointeroverNodeEvent,\n PointeroverParentEvent,\n SetupNodeData,\n TearDownNodeData,\n BaseDragState,\n SynthDragState,\n ParentKeydownEventData,\n SynthDragStateProps,\n ParentRecord,\n EventHandlers,\n NodeFromPoint,\n ParentFromPoint,\n ParentDragEventData,\n} from \"./types\";\n\nimport {\n pd,\n sp,\n on,\n emit,\n createEmitter,\n eq,\n splitClass,\n eventCoordinates,\n} from \"./utils\";\n\nexport * from \"./types\";\nexport { animations } from \"./plugins/animations\";\nexport { insert } from \"./plugins/insert\";\nexport { dropOrSwap } from \"./plugins/drop-or-swap\";\n\n/**\n * Check to see if code is running in a browser.\n */\nexport const isBrowser = typeof window !== \"undefined\";\n\n/**\n * Parents or \"lists\" are the containers that nodes or \"draggable items\" can be\n * dragged from and into.\n *\n * @type {WeakMap>}\n */\nexport const parents: ParentsData = new WeakMap<\n HTMLElement,\n ParentData\n>();\n\n/**\n * Nodes are the draggable items and the direct descendants of the parents.\n *\n * @type {WeakMap>}\n */\nexport const nodes: NodesData = new WeakMap>();\n\n/**\n * Function to check if touch support is enabled.\n *\n * @returns {boolean}\n */\nfunction checkTouchSupport() {\n if (!isBrowser) return false;\n\n return \"ontouchstart\" in window || navigator.maxTouchPoints > 0;\n}\n\n/**\n * The base drag state.\n *\n * @type {BaseDragState}\n */\nconst baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n currentTargetValue: undefined,\n on,\n emit,\n newActiveDescendant: undefined,\n originalZIndex: undefined,\n pointerSelection: false,\n preventEnter: false,\n rootUserSelect: undefined,\n nodePointerdown: undefined,\n longPress: false,\n scrolling: false,\n longPressTimeout: undefined,\n remapJustFinished: false,\n selectedNodes: [],\n selectedParent: undefined,\n preventSynthDrag: false,\n pointerDown: undefined,\n};\n\n/**\n * The state of the drag and drop.\n *\n * @type {BaseDragState}\n */\nexport let state: BaseDragState = baseDragState;\n\n/**\n * Variable to check if the drop has occurred.\n */\nlet dropped = false;\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\n/**\n * Abort controller for the window.\n */\nlet windowController: AbortController | undefined;\n\n/**\n * Timeout for the scroll.\n */\nlet scrollTimeout: ReturnType;\n\n/**\n * Variable to check if the device is touch.\n */\nlet touchDevice: boolean = false;\n\nexport function resetState() {\n const baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n on,\n emit,\n currentTargetValue: undefined,\n originalZIndex: undefined,\n pointerId: undefined,\n preventEnter: false,\n remapJustFinished: false,\n selectedNodes: [],\n nodePointerdown: undefined,\n rootUserSelect: undefined,\n preventSynthDrag: false,\n scrolling: false,\n selectedParent: undefined,\n pointerSelection: false,\n synthScrollDirection: undefined,\n draggedNodeDisplay: undefined,\n synthDragScrolling: false,\n longPress: false,\n pointerDown: undefined,\n longPressTimeout: undefined,\n };\n\n state = { ...baseDragState } as BaseDragState;\n}\n\n/**\n * @param {DragStateProps} dragStateProps - Attributes to update state with.\n *\n * @mutation - Updates state with node values.\n *\n * @returns void\n */\nexport function setDragState(\n dragStateProps: (SynthDragStateProps & DragStateProps) | DragStateProps\n): DragState | SynthDragState {\n Object.assign(state, dragStateProps);\n\n dragStateProps.initialParent.data.emit(\"dragStarted\", state);\n\n dropped = false;\n\n state.emit(\"dragStarted\", state);\n\n return state as DragState | SynthDragState;\n}\n\n/**\n *\n */\nfunction handleRootPointerdown(_e: PointerEvent) {\n if (state.activeState) setActive(state.activeState.parent, undefined, state);\n\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = state.activeState = undefined;\n}\n\nfunction handleRootPointerup(e: PointerEvent) {\n pd(e);\n\n state.pointerDown = undefined;\n\n if (!isSynthDragState(state)) return;\n\n const config = state.currentParent.data.config;\n\n if (isSynthDragState(state)) config.handleEnd(state);\n}\n\n/**\n * Handles the keydown event on the root element.\n *\n * @param {KeyboardEvent} e - The keyboard event.\n */\nfunction handleRootKeydown(e: KeyboardEvent) {\n if (e.key === \"Escape\") {\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n if (state.activeState)\n setActive(state.activeState.parent, undefined, state);\n\n state.selectedState = state.activeState = undefined;\n }\n}\n\nfunction handleRootDrop(_e: DragEvent) {}\n\nexport function copyNodeStyle(\n sourceNode: HTMLElement,\n targetNode: HTMLElement,\n omitKeys = false\n) {\n const computedStyle = window.getComputedStyle(sourceNode);\n\n const omittedKeys = [\n \"position\",\n \"z-index\",\n \"top\",\n \"left\",\n \"x\",\n \"pointer-events\",\n \"y\",\n \"transform-origin\",\n \"filter\",\n \"-webkit-text-fill-color\",\n ];\n\n for (const key of Array.from(computedStyle)) {\n if (omitKeys === false && key && omittedKeys.includes(key)) continue;\n\n targetNode.style.setProperty(\n key,\n computedStyle.getPropertyValue(key),\n computedStyle.getPropertyPriority(key)\n );\n }\n\n for (const child of Array.from(sourceNode.children)) {\n if (!isNode(child)) continue;\n\n const targetChild = targetNode.children[\n Array.from(sourceNode.children).indexOf(child)\n ] as Node;\n\n copyNodeStyle(child, targetChild, omitKeys);\n }\n}\n\n/**\n * If we are currently dragging, then let's prevent default on dragover to avoid\n * the default behavior of the browser on drop.\n */\nfunction handleRootDragover(e: DragEvent) {\n if (!isDragState(state)) return;\n\n pd(e);\n}\n\nfunction handleRootPointermove(e: PointerEvent) {\n if (!state.pointerDown) return;\n\n //pd(e);\n\n const config = state.pointerDown.parent.data.config;\n\n if (\n !isSynthDragState(state) &&\n (touchDevice || (!touchDevice && !config.nativeDrag))\n ) {\n if (config.longPress && !state.longPress) {\n clearTimeout(state.longPressTimeout);\n\n state.longPress = false;\n\n return;\n }\n\n const nodes = config.draggedNodes(state.pointerDown);\n\n config.dragstartClasses(state.pointerDown.node, nodes, config, true);\n\n const synthDragState = initSynthDrag(\n state.pointerDown.node,\n state.pointerDown.parent,\n e,\n state,\n nodes\n );\n\n state.rootUserSelect = window.getComputedStyle(\n document.documentElement\n ).userSelect;\n\n document.body.style.userSelect = \"none\";\n\n synthMove(e, synthDragState);\n } else if (isSynthDragState(state)) {\n synthMove(e, state);\n }\n}\n\n/**\n * Initializes the drag and drop functionality for a given parent.\n *\n * @param {DragAndDrop} dragAndDrop - The drag and drop configuration.\n *\n * @returns void\n */\nexport function dragAndDrop({\n parent,\n getValues,\n setValues,\n config = {},\n}: DragAndDrop): void {\n if (!isBrowser) return;\n\n touchDevice = checkTouchSupport();\n\n if (!documentController) {\n documentController = addEvents(document, {\n dragover: handleRootDragover,\n pointerdown: handleRootPointerdown,\n pointerup: handleRootPointerup,\n keydown: handleRootKeydown,\n drop: handleRootDrop,\n pointermove: handleRootPointermove,\n pointercancel: nodeEventData(config.handlePointercancel),\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n });\n\n const liveRegion = document.createElement(\"div\");\n\n setAttrs(liveRegion, {\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-dnd-live-region\": \"true\",\n });\n\n Object.assign(liveRegion.style, {\n position: \"absolute\",\n top: \"0px\",\n left: \"-9999px\",\n width: \"1px\",\n height: \"1px\",\n padding: \"0\",\n overflow: \"hidden\",\n clip: \"rect(0, 0, 0, 0)\",\n whiteSpace: \"nowrap\",\n border: \"0\",\n });\n\n document.body.appendChild(liveRegion);\n }\n\n if (!windowController)\n windowController = addEvents(window, {\n resize: () => {\n touchDevice = checkTouchSupport();\n },\n });\n\n tearDown(parent);\n\n const [emit, on] = createEmitter();\n\n const parentData: ParentData = {\n getValues,\n setValues,\n config: {\n dragDropEffect: config.dragDropEffect ?? \"move\",\n dragEffectAllowed: config.dragEffectAllowed ?? \"move\",\n draggedNodes,\n dragstartClasses,\n deepCopyStyles: config.deepCopyStyles ?? false,\n handleNodeKeydown,\n handleParentKeydown,\n handleDragstart,\n handleNodeDragover,\n handleParentDragover,\n handleNodeDrop,\n handlePointercancel,\n handleEnd,\n handleDragend,\n handleParentFocus,\n handleNodePointerup,\n handleNodePointerover,\n handleParentPointerover,\n handleParentScroll,\n handleNodePointerdown,\n handleNodeDragenter,\n handleNodeDragleave,\n handleParentDrop,\n multiDrag: config.multiDrag ?? false,\n nativeDrag: config.nativeDrag ?? true,\n performSort,\n performTransfer,\n root: config.root ?? document,\n setupNode,\n setupNodeRemap,\n reapplyDragClasses,\n tearDownNode,\n tearDownNodeRemap,\n remapFinished,\n threshold: {\n horizontal: 0,\n vertical: 0,\n },\n ...config,\n },\n enabledNodes: [],\n abortControllers: {},\n privateClasses: [],\n on,\n emit,\n };\n\n const nodesObserver = new MutationObserver(nodesMutated);\n\n nodesObserver.observe(parent, { childList: true });\n\n parents.set(parent, parentData);\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.setup?.();\n });\n\n setup(parent, parentData);\n\n remapNodes(parent, true);\n}\n\nexport function dragStateProps(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent | DragEvent,\n draggedNodes: Array>,\n offsetX?: number,\n offsetY?: number\n): DragStateProps {\n const { x, y } = eventCoordinates(e);\n\n const rect = node.el.getBoundingClientRect();\n\n return {\n affectedNodes: [],\n ascendingDirection: false,\n clonedDraggedEls: [],\n coordinates: {\n x,\n y,\n },\n draggedNode: {\n el: node.el,\n data: node.data,\n },\n draggedNodes,\n incomingDirection: undefined,\n initialIndex: node.data.index,\n initialParent: {\n el: parent.el,\n data: parent.data,\n },\n currentParent: {\n el: parent.el,\n data: parent.data,\n },\n longPress: parent.data.config.longPress ?? false,\n longPressTimeout: undefined,\n currentTargetValue: node.data.value,\n scrollEls: [],\n // Need to account for if the explicity offset is positive or negative\n startLeft: offsetX ? offsetX : x - rect.left,\n startTop: offsetY ? offsetY : y - rect.top,\n targetIndex: node.data.index,\n transferred: false,\n };\n}\n\nexport function performSort({\n parent,\n draggedNodes,\n targetNodes,\n}: {\n parent: ParentRecord;\n draggedNodes: Array>;\n targetNodes: Array>;\n}) {\n remapNodes(parent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const targetParentValues = parentValues(parent.el, parent.data);\n\n const originalIndex = draggedNodes[0].data.index;\n\n const enabledNodes = [...parent.data.enabledNodes];\n\n const newParentValues = [\n ...targetParentValues.filter((x) => !draggedValues.some((y) => eq(x, y))),\n ];\n newParentValues.splice(targetNodes[0].data.index, 0, ...draggedValues);\n\n if (\"draggedNode\" in state)\n state.currentTargetValue = targetNodes[0].data.value;\n\n setParentValues(parent.el, parent.data, [...newParentValues]);\n\n if (parent.data.config.onSort)\n parent.data.config.onSort({\n parent: {\n el: parent.el,\n data: parent.data,\n } as ParentRecord,\n previousValues: [...targetParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...parent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: draggedNodes,\n previousPosition: originalIndex,\n position: targetNodes[0].data.index,\n targetNodes,\n state,\n });\n}\n\n/**\n * This function sets the active node as well as removing any classes or\n * attribute set.\n *\n * @param {ParentEventData} data - The parent event data.\n * @param {NodeRecord} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction setActive(\n parent: ParentRecord,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState\n) {\n const activeDescendantClass = parent.data.config.activeDescendantClass;\n\n if (state.activeState) {\n {\n removeClass([state.activeState.node.el], activeDescendantClass);\n\n if (state.activeState.parent.el !== parent.el)\n state.activeState.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n }\n }\n\n if (!newActiveNode) {\n state.activeState?.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n\n state.activeState = undefined;\n\n return;\n }\n\n state.activeState = {\n node: newActiveNode,\n parent,\n };\n\n addNodeClass([newActiveNode.el], activeDescendantClass);\n\n state.activeState.parent.el.setAttribute(\n \"aria-activedescendant\",\n state.activeState.node.el.id\n );\n}\n\n/**\n * This function deselects the nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {Array>} nodes - The nodes to deselect.\n * @param {ParentRecord} parent - The parent record.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction deselect(\n nodes: Array>,\n parent: ParentRecord,\n state: BaseDragState\n) {\n const selectedClass = parent.data.config.selectedClass;\n\n if (!state.selectedState) return;\n\n const iterativeNodes = Array.from(nodes);\n\n removeClass(\n nodes.map((x) => x.el),\n selectedClass\n );\n\n for (const node of iterativeNodes) {\n node.el.setAttribute(\"aria-selected\", \"false\");\n\n const index = state.selectedState.nodes.findIndex((x) => x.el === node.el);\n\n if (index === -1) continue;\n\n state.selectedState.nodes.splice(index, 1);\n }\n\n clearLiveRegion(parent);\n}\n\n/**\n * This function sets the selected nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {ParentRecord} parent - The parent record.\n * @param {Array>} selectedNodes - The nodes to select.\n * @param {NodeRecord | undefined} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n * @param {boolean} pointerdown - Whether the pointerdown event was triggered.\n */\nfunction setSelected(\n parent: ParentRecord,\n selectedNodes: Array>,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState,\n pointerdown = false\n) {\n state.pointerSelection = pointerdown;\n\n for (const node of selectedNodes) {\n node.el.setAttribute(\"aria-selected\", \"true\");\n\n addNodeClass([node.el], parent.data.config.selectedClass, true);\n }\n\n state.selectedState = {\n nodes: selectedNodes,\n parent,\n };\n\n const selectedItems = selectedNodes.map((x) =>\n x.el.getAttribute(\"aria-label\")\n );\n\n if (selectedItems.length === 0) {\n state.selectedState = undefined;\n\n clearLiveRegion(parent);\n\n return;\n }\n\n setActive(parent, newActiveNode, state);\n\n updateLiveRegion(\n parent,\n `${selectedItems.join(\n \", \"\n )} ready for dragging. Use arrow keys to navigate. Press enter to drop ${selectedItems.join(\n \", \"\n )}.`\n );\n}\n\nfunction updateLiveRegion(parent: ParentRecord, message: string) {\n const liveRegion = document.querySelector('[data-dnd-live-region=\"true\"]');\n\n if (!liveRegion) return;\n\n liveRegion.id = parent.el.id + \"-live-region\";\n\n liveRegion.textContent = message;\n}\n\nfunction clearLiveRegion(parent: ParentRecord) {\n const liveRegion = document.getElementById(parent.el.id + \"-live-region\");\n\n if (!liveRegion) return;\n\n liveRegion.textContent = \"\";\n}\n\nexport function handleParentFocus(\n data: ParentEventData,\n state: BaseDragState | DragState | SynthDragState\n) {\n const firstEnabledNode = data.targetData.parent.data.enabledNodes[0];\n\n if (!firstEnabledNode) return;\n\n if (\n state.selectedState &&\n state.selectedState.parent.el !== data.targetData.parent.el\n ) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n } else if (!state.selectedState) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n }\n}\n\n/**\n * Perform the transfer of the nodes.\n *\n * @param data - The transfer data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function performTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n initialIndex,\n targetNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n initialIndex: number;\n state: BaseDragState | DragState | SynthDragState;\n targetNodes: Array>;\n}) {\n remapNodes(initialParent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const currentParentValues = [\n ...parentValues(currentParent.el, currentParent.data).filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n const targetParentValues = parentValues(targetParent.el, targetParent.data);\n\n const reset =\n initialParent.el === targetParent.el &&\n targetParent.data.config.sortable === false;\n\n let targetIndex: number;\n\n if (targetNodes.length) {\n if (reset) {\n targetIndex = initialIndex;\n } else if (targetParent.data.config.sortable === false) {\n targetIndex = targetParent.data.enabledNodes.length;\n } else {\n targetIndex = targetNodes[0].data.index;\n }\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n } else {\n targetIndex = reset ? initialIndex : targetParent.data.enabledNodes.length;\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n }\n\n setParentValues(currentParent.el, currentParent.data, currentParentValues);\n\n setParentValues(targetParent.el, targetParent.data, targetParentValues);\n\n if (targetParent.data.config.onTransfer) {\n targetParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes,\n });\n }\n\n if (currentParent.data.config.onTransfer) {\n currentParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes: targetNodes ? targetNodes : [],\n });\n }\n}\n\n/**\n * Get the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns The values of the parent.\n */\nexport function parentValues(\n parent: HTMLElement,\n parentData: ParentData\n): Array {\n return [...parentData.getValues(parent)];\n}\n\n/**\n * Set the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n * @param values - The values to set.\n *\n * @returns void\n */\nexport function setParentValues(\n parent: HTMLElement,\n parentData: ParentData,\n values: Array\n): void {\n parentData.setValues(values, parent);\n}\n\n/**\n * Get the values of the dragged nodes.\n *\n * @param state - The drag state.\n *\n * @returns The values of the dragged nodes.\n */\nexport function dragValues(state: DragState): Array {\n return [...state.draggedNodes.map((x) => x.data.value)];\n}\n\n/**\n * Utility function to update parent config.\n *\n * @param parent - The parent element.\n * @param config - The config to update.\n *\n * @returns void\n */\nexport function updateConfig(\n parent: HTMLElement,\n config: Partial>\n) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parents.set(parent, {\n ...parentData,\n config: { ...parentData.config, ...config },\n });\n\n dragAndDrop({\n parent,\n getValues: parentData.getValues,\n setValues: parentData.setValues,\n config,\n });\n}\n\n/**\n * Handle the parent drop event.\n *\n * @param data - The parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDrop(\n data: ParentEventData,\n state: DragState\n) {\n sp(data.e);\n\n dropped = true;\n\n const handleEnd = state.initialParent.data.config.handleEnd;\n\n handleEnd(state);\n}\n\n/**\n * Tear down the parent.\n *\n * @param parent - The parent element.\n *\n * @returns void\n */\nexport function tearDown(parent: HTMLElement) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n if (parentData.abortControllers.mainParent)\n parentData.abortControllers.mainParent.abort();\n}\n\n/**\n * Check if the state is a drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a drag state.\n */\nexport function isDragState(\n state: BaseDragState\n): state is DragState | SynthDragState {\n return \"draggedNode\" in state && !!state.draggedNode;\n}\n\n/**\n * Check if the state is a synth drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a synth drag state.\n */\nexport function isSynthDragState(\n state: BaseDragState\n): state is SynthDragState {\n return \"synthDragging\" in state && !!state.synthDragging;\n}\n\n/**\n * Setup the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction setup(parent: HTMLElement, parentData: ParentData): void {\n parentData.abortControllers.mainParent = addEvents(parent, {\n keydown: parentEventData(parentData.config.handleParentKeydown),\n dragover: parentEventData(parentData.config.handleParentDragover),\n handleParentPointerover: parentData.config.handleParentPointerover,\n scroll: parentEventData(parentData.config.handleParentScroll),\n drop: parentEventData(parentData.config.handleParentDrop),\n hasNestedParent: (e: CustomEvent) => {\n const parent = parents.get(e.target as HTMLElement);\n\n if (!parent) return;\n\n parent.nestedParent = e.detail.parent;\n },\n focus: parentEventData(parentData.config.handleParentFocus),\n });\n\n if (\n parentData.config.externalDragHandle &&\n parentData.config.externalDragHandle.el &&\n parentData.config.externalDragHandle.callback\n ) {\n parentData.abortControllers.externalDragHandle = addEvents(\n parentData.config.externalDragHandle.el,\n {\n pointerdown: (_e: PointerEvent) => {\n if (\n !parentData.config.externalDragHandle ||\n !parentData.config.externalDragHandle.callback\n )\n return;\n\n const draggableItem = parentData.config.externalDragHandle.callback();\n\n if (!isNode(draggableItem)) {\n console.warn(\n \"No draggable item found from external drag handle callback\"\n );\n\n return;\n }\n\n const nodeData = nodes.get(draggableItem);\n\n if (!nodeData) return;\n\n const parentNode = draggableItem.parentNode;\n\n if (!(parentNode instanceof HTMLElement)) return;\n\n const parent = parents.get(parentNode);\n\n if (!parent) return;\n\n state.pointerDown = {\n parent: {\n el: parentNode,\n data: parent,\n },\n node: {\n el: draggableItem,\n data: nodeData,\n },\n };\n\n draggableItem.draggable = true;\n },\n }\n );\n }\n\n if (parent.id)\n setAttrs(parent, {\n role: \"listbox\",\n tabindex: \"0\",\n \"aria-multiselectable\": parentData.config.multiDrag ? \"true\" : \"false\",\n \"aria-activedescendant\": \"\",\n \"aria-describedby\": parent.id + \"-live-region\",\n });\n}\n\n/**\n * Set the attributes of the element.\n *\n * @param el - The element.\n * @param attrs - The attributes to set.\n *\n * @returns void\n */\nexport function setAttrs(el: HTMLElement, attrs: Record) {\n for (const key in attrs) el.setAttribute(key, attrs[key]);\n}\n\n/**\n * Setup the node.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNode(data: SetupNodeData) {\n const config = data.parent.data.config;\n\n data.node.data.abortControllers.mainNode = addEvents(data.node.el, {\n keydown: nodeEventData(config.handleNodeKeydown),\n dragstart: nodeEventData(config.handleDragstart),\n dragover: nodeEventData(config.handleNodeDragover),\n dragenter: nodeEventData(config.handleNodeDragenter),\n dragleave: nodeEventData(config.handleNodeDragleave),\n dragend: nodeEventData(config.handleDragend),\n drop: nodeEventData(config.handleNodeDrop),\n pointerup: nodeEventData(config.handleNodePointerup),\n pointercancel: nodeEventData(config.handlePointercancel),\n\n pointerdown: nodeEventData(config.handleNodePointerdown),\n handleNodePointerover: config.handleNodePointerover,\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n contextmenu: (e: Event) => {\n if (touchDevice) pd(e);\n },\n });\n\n data.node.el.setAttribute(\"role\", \"option\");\n\n data.node.el.setAttribute(\"aria-selected\", \"false\");\n\n config.reapplyDragClasses(data.node.el, data.parent.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNode?.(data);\n });\n}\n\n/**\n * Setup the node remap.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNodeRemap(data: SetupNodeData) {\n nodes.set(data.node.el, data.node.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNodeRemap?.(data);\n });\n}\n\n/**\n * Reapply the drag classes to the node.\n *\n * @param node - The node.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction reapplyDragClasses(node: Node, parentData: ParentData) {\n if (!isDragState(state)) return;\n\n const dropZoneClass = isSynthDragState(state)\n ? parentData.config.synthDropZoneClass\n : parentData.config.dropZoneClass;\n\n if (state.draggedNode.el !== node) return;\n\n addNodeClass([node], dropZoneClass, true);\n}\n\n/**\n * Tear down the node remap.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNodeRemap(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNodeRemap?.(data);\n });\n}\n\n/**\n * Tear down the node.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNode(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNode?.(data);\n });\n\n data.node.el.draggable = false;\n\n if (data.node.data?.abortControllers?.mainNode)\n data.node.data?.abortControllers?.mainNode.abort();\n}\n\n/**\n * Called when the nodes of a given parent element are mutated.\n *\n * @param mutationList - The list of mutations.\n *\n * @returns void\n *\n * @internal\n */\nfunction nodesMutated(mutationList: MutationRecord[]) {\n // TODO: This could be better, but using it as a way to ignore comments and text\n if (\n mutationList.length === 1 &&\n mutationList[0].addedNodes.length === 1 &&\n !(mutationList[0].addedNodes[0] instanceof HTMLElement)\n )\n return;\n\n const parentEl = mutationList[0].target;\n\n if (!(parentEl instanceof HTMLElement)) return;\n\n const allSelectedAndActiveNodes = document.querySelectorAll(\n `[aria-selected=\"true\"]`\n );\n\n const parentData = parents.get(parentEl);\n\n if (!parentData) return;\n\n for (let x = 0; x < allSelectedAndActiveNodes.length; x++) {\n const node = allSelectedAndActiveNodes[x];\n\n node.setAttribute(\"aria-selected\", \"false\");\n\n removeClass([node], parentData.config.selectedClass);\n }\n\n remapNodes(parentEl);\n}\n\n/**\n * Remaps the data of the parent element's children.\n *\n * @param parent - The parent element.\n *\n * @returns void\n *\n * @internal\n */\nexport function remapNodes(parent: HTMLElement, force?: boolean) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parentData.privateClasses = Array.from(parent.classList);\n\n const enabledNodes: Array = [];\n\n const config = parentData.config;\n\n for (let x = 0; x < parent.children.length; x++) {\n const node = parent.children[x];\n\n if (!isNode(node) || node.id === \"dnd-dragged-node-clone\") continue;\n\n const nodeData = nodes.get(node);\n\n // Only tear down the node if we have explicitly called dragAndDrop\n if (force || !nodeData)\n config.tearDownNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n if (config.disabled) continue;\n\n if (!config.draggable || (config.draggable && config.draggable(node))) {\n enabledNodes.push(node);\n }\n }\n\n if (\n enabledNodes.length !== parentData.getValues(parent).length &&\n !config.disabled\n ) {\n console.warn(\n \"The number of draggable items defined in the parent element does not match the number of values. This may cause unexpected behavior.\"\n );\n\n return;\n }\n\n const values = parentData.getValues(parent);\n\n const enabledNodeRecords: Array> = [];\n\n for (let x = 0; x < enabledNodes.length; x++) {\n const node = enabledNodes[x];\n\n const prevNodeData = nodes.get(node);\n\n if (config.draggableValue && !config.draggableValue(values[x])) continue;\n\n const nodeData = Object.assign(\n prevNodeData ?? {\n privateClasses: [],\n abortControllers: {},\n },\n {\n value: values[x],\n index: x,\n }\n );\n\n if (\n !isDragState(state) &&\n state.newActiveDescendant &&\n eq(state.newActiveDescendant.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n !isDragState(state) &&\n state.activeState &&\n eq(state.activeState.node.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n isDragState(state) &&\n eq(state.draggedNode.data.value, nodeData.value)\n ) {\n state.draggedNode.data = nodeData;\n\n state.draggedNode.el = node;\n\n const draggedNode = state.draggedNodes.find(\n (x) => x.data.value === nodeData.value\n );\n\n if (draggedNode) draggedNode.el = node;\n }\n\n enabledNodeRecords.push({\n el: node,\n data: nodeData,\n });\n\n if (force || !prevNodeData)\n config.setupNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n setupNodeRemap({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n }\n\n parents.set(parent, { ...parentData, enabledNodes: enabledNodeRecords });\n\n config.remapFinished(parentData);\n\n parentData.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.remapFinished?.();\n });\n}\n\n/**\n * Set the remap just finished flag.\n *\n * @returns void\n */\nexport function remapFinished() {\n state.remapJustFinished = true;\n\n if (\"draggedNode\" in state) state.affectedNodes = [];\n}\n\n/**\n * Validate the drag start.\n *\n * @param data - The node event data.\n *\n * @returns Whether the drag start is valid.\n */\nexport function validateDragstart(data: NodeEventData): boolean {\n return !!data.targetData.parent.data.config.nativeDrag;\n}\n\n/**\n * Get the dragged nodes.\n *\n * @param pointerDown - The pointer down data.\n *\n * @returns The dragged nodes.\n */\nfunction draggedNodes(pointerDown: {\n parent: ParentRecord;\n node: NodeRecord;\n}): Array> {\n if (!pointerDown.parent.data.config.multiDrag) {\n return [pointerDown.node];\n } else if (state.selectedState) {\n return [\n pointerDown.node,\n ...(state.selectedState?.nodes.filter(\n (x) => x.el !== pointerDown.node.el\n ) as Array>),\n ];\n }\n\n return [];\n}\n\n/**\n * Handle the parent scroll.\n *\n * @param data - The parent event data.\n *\n * @returns void\n */\nfunction handleParentScroll(_data: ParentEventData) {\n if (!isDragState(state)) return;\n\n state.emit(\"scrollStarted\", state);\n\n if (isSynthDragState(state)) return;\n\n state.preventEnter = true;\n\n if (scrollTimeout) clearTimeout(scrollTimeout);\n\n scrollTimeout = setTimeout(() => {\n state.preventEnter = false;\n\n state.emit(\"scrollEnded\", state);\n }, 100);\n}\n\n/**\n * Responsible for assigning dragstart classes to the dragged nodes.\n */\nexport function handleDragstart(\n data: NodeDragEventData,\n _state: BaseDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (\n !config.nativeDrag ||\n !validateDragstart(data) ||\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config,\n })\n ) {\n pd(data.e);\n\n return;\n }\n\n const nodes = config.draggedNodes({\n parent: data.targetData.parent,\n node: data.targetData.node,\n });\n\n config.dragstartClasses(data.targetData.node, nodes, config);\n\n const dragState = initDrag(data, nodes);\n\n if (config.onDragstart)\n config.onDragstart({\n parent: data.targetData.parent,\n values: parentValues(\n data.targetData.parent.el,\n data.targetData.parent.data\n ),\n draggedNode: dragState.draggedNode,\n draggedNodes: dragState.draggedNodes,\n position: dragState.initialIndex,\n state: dragState,\n });\n}\n\nexport function handleNodePointerdown(\n data: NodePointerEventData,\n state: BaseDragState\n) {\n sp(data.e);\n\n if (\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config: data.targetData.parent.data.config,\n })\n )\n return;\n\n state.pointerDown = {\n parent: data.targetData.parent,\n node: data.targetData.node,\n };\n\n data.targetData.node.el.draggable = true;\n\n handleLongPress(data, state, data.targetData.node);\n\n const parentData = data.targetData.parent.data;\n\n let selectedNodes = [data.targetData.node];\n\n const commandKey = data.e.ctrlKey || data.e.metaKey;\n const shiftKey = data.e.shiftKey;\n\n const targetNode = data.targetData.node;\n\n if (commandKey && parentData.config.multiDrag) {\n if (state.selectedState) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === targetNode.el\n );\n\n if (idx === -1) {\n selectedNodes = [...state.selectedState.nodes, targetNode];\n } else {\n selectedNodes = state.selectedState.nodes.filter(\n (x) => x.el !== targetNode.el\n );\n }\n } else {\n selectedNodes = [targetNode];\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (shiftKey && parentData.config.multiDrag) {\n const nodes = data.targetData.parent.data.enabledNodes;\n\n if (state.selectedState && state.activeState) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = undefined;\n\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n } else {\n const [minIndex, maxIndex] =\n state.activeState.node.data.index < data.targetData.node.data.index\n ? [\n state.activeState.node.data.index,\n data.targetData.node.data.index,\n ]\n : [\n data.targetData.node.data.index,\n state.activeState.node.data.index,\n ];\n\n selectedNodes = nodes.slice(minIndex, maxIndex + 1);\n }\n } else {\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (state.selectedState?.nodes?.length) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === data.targetData.node.el\n );\n\n if (idx === -1) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n } else if (parentData.config.multiDrag && touchDevice) {\n selectedNodes.push(...state.selectedState.nodes);\n } else {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n }\n } else {\n setSelected(\n data.targetData.parent,\n [data.targetData.node],\n data.targetData.node,\n state,\n true\n );\n }\n}\n\n/**\n * Add dragstart classes to the nodes.\n *\n * @param node - The node.\n * @param nodes - The nodes.\n * @param config - The parent config.\n * @param isSynth - Whether the drag is synthetic.\n *\n * @returns void\n */\nexport function dragstartClasses(\n _node: NodeRecord,\n nodes: Array>,\n config: ParentConfig,\n isSynth = false\n) {\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n setTimeout(() => {\n removeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDragPlaceholderClass : config.dragPlaceholderClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDropZoneClass : config.dropZoneClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.activeDescendantClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.selectedClass\n );\n });\n}\n\n/**\n * Initialize the drag state.\n *\n * @param data - The node drag event data.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The drag state.\n */\nexport function initDrag(\n data: NodeDragEventData,\n draggedNodes: Array>\n): DragState {\n sp(data.e);\n\n const dragState = setDragState(\n dragStateProps(\n data.targetData.node,\n data.targetData.parent,\n data.e,\n draggedNodes\n )\n );\n\n if (data.e.dataTransfer) {\n const config = data.targetData.parent.data.config;\n\n data.e.dataTransfer.dropEffect = config.dragDropEffect;\n\n data.e.dataTransfer.effectAllowed = config.dragEffectAllowed;\n\n let dragImage: HTMLElement | undefined;\n\n if (config.dragImage) {\n dragImage = config.dragImage(data, draggedNodes);\n } else {\n if (!config.multiDrag) {\n data.e.dataTransfer.setDragImage(\n data.targetData.node.el,\n data.e.offsetX,\n data.e.offsetY\n );\n\n const originalZIndex = data.targetData.node.el.style.zIndex;\n\n dragState.originalZIndex = originalZIndex;\n\n data.targetData.node.el.style.zIndex = \"9999\";\n\n return dragState;\n } else {\n const wrapper = document.createElement(\"div\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n clonedNode.style.pointerEvents = \"none\";\n\n clonedNode.id = node.el.id + \"-clone\";\n\n wrapper.append(clonedNode);\n }\n\n const { width } = draggedNodes[0].el.getBoundingClientRect();\n\n Object.assign(wrapper.style, {\n display: \"flex\",\n flexDirection: \"column\",\n width: `${width}px`,\n position: \"absolute\",\n pointerEvents: \"none\",\n zIndex: \"9999\",\n left: \"-9999px\",\n });\n\n dragImage = wrapper;\n }\n\n document.body.appendChild(dragImage);\n }\n\n data.e.dataTransfer.setDragImage(dragImage, data.e.offsetX, data.e.offsetY);\n\n setTimeout(() => {\n dragImage?.remove();\n });\n }\n\n return dragState;\n}\n\nexport function validateDragHandle({\n x,\n y,\n node,\n config,\n}: {\n x: number;\n y: number;\n node: NodeRecord;\n config: ParentConfig;\n}): boolean {\n if (config.externalDragHandle) return false;\n\n if (!config.dragHandle) return true;\n\n const dragHandles = node.el.querySelectorAll(config.dragHandle);\n\n if (!dragHandles) return false;\n\n const elFromPoint = config.root.elementFromPoint(x, y);\n\n if (!elFromPoint) return false;\n\n for (const handle of Array.from(dragHandles))\n if (elFromPoint === handle || handle.contains(elFromPoint)) return true;\n\n return false;\n}\n\nexport function handleClickNode(_data: NodeEventData) {}\n\nexport function handleClickParent(_data: ParentEventData) {}\n\nexport function handleNodeKeydown(_data: NodeEventData) {}\n\nexport function handleParentKeydown(\n data: ParentKeydownEventData,\n state: BaseDragState\n) {\n const activeDescendant = state.activeState?.node;\n\n if (!activeDescendant) return;\n\n const parentData = data.targetData.parent.data;\n\n const enabledNodes = parentData.enabledNodes;\n\n if (!(data.e.target instanceof HTMLElement)) return;\n const index = enabledNodes.findIndex((x) => x.el === activeDescendant.el);\n\n if (index === -1) return;\n\n if (\n [\"ArrowDown\", \"ArrowUp\", \"ArrowRight\", \"ArrowLeft\"].includes(data.e.key)\n ) {\n pd(data.e);\n\n const nextIndex =\n data.e.key === \"ArrowDown\" || data.e.key === \"ArrowRight\"\n ? index + 1\n : index - 1;\n\n if (nextIndex < 0 || nextIndex >= enabledNodes.length) return;\n\n const nextNode = enabledNodes[nextIndex];\n\n setActive(data.targetData.parent, nextNode, state);\n } else if (data.e.key === \" \") {\n pd(data.e);\n\n state.selectedState && state.selectedState.nodes.includes(activeDescendant)\n ? setSelected(\n data.targetData.parent,\n state.selectedState.nodes.filter((x) => x.el !== activeDescendant.el),\n activeDescendant,\n state\n )\n : setSelected(\n data.targetData.parent,\n [activeDescendant],\n activeDescendant,\n state\n );\n } else if (data.e.key === \"Enter\" && state.selectedState) {\n if (\n state.selectedState.parent.el === data.targetData.parent.el &&\n state.activeState\n ) {\n if (state.selectedState.nodes[0].el === state.activeState.node.el) {\n updateLiveRegion(data.targetData.parent, \"Cannot drop item on itself\");\n\n return;\n }\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n parentData.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.selectedState.nodes,\n targetNodes: [state.activeState.node],\n });\n\n deselect([], data.targetData.parent, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n } else if (\n state.activeState &&\n state.selectedState.parent.el !== data.targetData.parent.el &&\n validateTransfer({\n currentParent: data.targetData.parent,\n targetParent: state.selectedState.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n state,\n })\n ) {\n parentData.config.performTransfer({\n currentParent: state.selectedState.parent,\n targetParent: data.targetData.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n initialIndex: state.selectedState.nodes[0].data.index,\n state,\n targetNodes: [state.activeState.node],\n });\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n setSelected(data.targetData.parent, [], undefined, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n }\n }\n}\n\n/**\n * Prevent the sort on scroll.\n *\n * @returns A function to prevent the sort on scroll.\n */\nexport function preventSortOnScroll() {\n let scrollTimeout: ReturnType;\n\n return () => {\n clearTimeout(scrollTimeout);\n\n if (state) state.preventEnter = true;\n\n scrollTimeout = setTimeout(() => {\n if (state) state.preventEnter = false;\n }, 100);\n };\n}\n\n/**\n * Handle the node pointer over.\n *\n * @param e - The node pointer over event.\n *\n * @returns void\n */\nexport function handleNodePointerover(e: PointeroverNodeEvent) {\n if (e.detail.targetData.parent.el === e.detail.state.currentParent.el)\n sort(e.detail, e.detail.state);\n else transfer(e.detail, e.detail.state);\n}\n\n/**\n * Handle the node drop.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDrop(\n data: NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n sp(data.e);\n\n dropped = true;\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleDragend(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the pointer cancel.\n *\n * @param data - The node event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handlePointercancel(\n data: NodeEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isSynthDragState(state)) return;\n pd(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n const config = parents.get(state.initialParent.el)?.config;\n\n if (config?.onDragend) {\n config.onDragend({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n }\n\n config?.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleEnd(state: DragState | SynthDragState) {\n if (state.draggedNode) state.draggedNode.el.draggable = false;\n\n document.body.style.userSelect = state.rootUserSelect || \"\";\n\n if (isSynthDragState(state)) {\n document.documentElement.style.overscrollBehavior =\n state.rootOverScrollBehavior || \"\";\n\n document.documentElement.style.touchAction = state.rootTouchAction || \"\";\n }\n\n if (isSynthDragState(state)) cancelSynthScroll(state);\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n const config = parents.get(state.initialParent.el)?.config;\n\n const isSynth = isSynthDragState(state);\n\n const dropZoneClass = isSynth\n ? config?.synthDropZoneClass\n : config?.dropZoneClass;\n\n if (state.originalZIndex !== undefined)\n state.draggedNode.el.style.zIndex = state.originalZIndex;\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n dropZoneClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n state.initialParent.data?.config?.longPressClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n isSynth\n ? state.initialParent.data.config.synthDragPlaceholderClass\n : state.initialParent.data?.config?.dragPlaceholderClass\n );\n\n if (isSynth) state.clonedDraggedNode.remove();\n\n deselect(state.draggedNodes, state.currentParent, state);\n\n setActive(state.currentParent, undefined, state);\n\n resetState();\n\n state.selectedState = undefined;\n\n config?.onDragend?.({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n\n state.emit(\"dragEnded\", state);\n}\n\n/**\n * Handle the node pointer up.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodePointerup(\n data: NodePointerEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n sp(data.e);\n\n state.pointerDown = undefined;\n if (!state.pointerSelection && state.selectedState)\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n\n const config = data.targetData.parent.data.config;\n\n state.pointerSelection = false;\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n removeClass(\n data.targetData.parent.data.enabledNodes.map((x) => x.el),\n config.longPressClass\n );\n\n if (!isDragState(state)) return;\n\n config.handleEnd(state as DragState | SynthDragState);\n}\n\n/**\n * Initialize the synth drag.\n *\n * @param node - The node.\n * @param parent - The parent.\n * @param e - The pointer event.\n * @param _state - The drag state.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The synth drag state.\n */\nfunction initSynthDrag(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent,\n _state: BaseDragState,\n draggedNodes: Array>\n): SynthDragState {\n const config = parent.data.config;\n\n let dragImage: HTMLElement | undefined;\n\n let display = node.el.style.display;\n\n let result = undefined;\n\n if (config.synthDragImage) {\n result = config.synthDragImage(node, parent, e, draggedNodes);\n\n dragImage = result.dragImage;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n zIndex: 9999,\n pointerEvents: \"none\",\n margin: 0,\n overflow: \"hidden\",\n display: \"none\",\n });\n } else {\n if (!config.multiDrag || draggedNodes.length === 1) {\n dragImage = node.el.cloneNode(true) as HTMLElement;\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n height: node.el.getBoundingClientRect().height + \"px\",\n width: node.el.getBoundingClientRect().width + \"px\",\n overflow: \"hidden\",\n margin: 0,\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n } else {\n const wrapper = document.createElement(\"div\");\n\n wrapper.setAttribute(\"popover\", \"\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n clonedNode.style.pointerEvents = \"none\";\n\n wrapper.append(clonedNode);\n }\n\n Object.assign(wrapper.style, {\n display: \"flex\",\n flexDirection: \"column\",\n left: \"-9999px\",\n position: \"absolute\",\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n\n wrapper.id = \"dnd-dragged-node-clone\";\n\n dragImage = wrapper;\n }\n }\n\n dragImage.style.position = \"absolute\";\n\n parent.el.appendChild(dragImage);\n\n dragImage.showPopover();\n\n const synthDragStateProps = {\n clonedDraggedEls: [],\n clonedDraggedNode: dragImage,\n draggedNodeDisplay: display,\n synthDragScrolling: false,\n synthDragging: true,\n rootScrollWidth: document.scrollingElement?.scrollWidth,\n rootScrollHeight: document.scrollingElement?.scrollHeight,\n rootOverScrollBehavior: document.documentElement.style.overscrollBehavior,\n rootTouchAction: document.documentElement.style.touchAction,\n };\n\n document.documentElement.style.overscrollBehavior = \"none\";\n\n document.documentElement.style.touchAction = \"none\";\n\n const synthDragState = setDragState({\n ...dragStateProps(\n node,\n parent,\n e,\n draggedNodes,\n result?.offsetX,\n result?.offsetY\n ),\n ...synthDragStateProps,\n }) as SynthDragState;\n\n synthDragState.clonedDraggedNode.style.display =\n synthDragState.draggedNodeDisplay || \"\";\n\n return synthDragState;\n}\n\n/**\n * Handle the long press.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n * @param node - The node.\n *\n * @returns void\n */\nexport function handleLongPress(\n data: NodePointerEventData,\n state: BaseDragState,\n node: NodeRecord\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.longPress) return;\n\n state.longPressTimeout = setTimeout(() => {\n if (!state) return;\n\n state.longPress = true;\n\n if (config.longPressClass && data.e.cancelable)\n addNodeClass([node.el], config.longPressClass);\n\n pd(data.e);\n }, config.longPressDuration || 200);\n}\n\nfunction pointermoveClasses(\n state: SynthDragState,\n config: ParentConfig\n) {\n if (config.longPressClass)\n removeClass(\n state.draggedNodes.map((x) => x.el),\n config?.longPressClass\n );\n}\n\nfunction cancelSynthScroll(\n state: SynthDragState,\n cancelX = true,\n cancelY = true\n) {\n if (cancelX && state.animationFrameIdX !== undefined) {\n cancelAnimationFrame(state.animationFrameIdX);\n\n state.animationFrameIdX = undefined;\n }\n\n if (cancelY && state.animationFrameIdY !== undefined) {\n cancelAnimationFrame(state.animationFrameIdY);\n\n state.animationFrameIdY = undefined;\n }\n\n if (!state.animationFrameIdX && !state.animationFrameIdY) {\n state.preventEnter = false;\n }\n}\n\nfunction moveNode(\n e: PointerEvent,\n state: SynthDragState,\n scrollX = 0,\n scrollY = 0\n) {\n const { x, y } = eventCoordinates(e);\n\n state.coordinates.y = y;\n state.coordinates.x = x;\n\n const startLeft = state.startLeft ?? 0;\n const startTop = state.startTop ?? 0;\n\n // Calculate the translation values\n const translateX = x - startLeft + window.scrollX;\n const translateY = y - startTop + window.scrollY;\n\n // Apply the transform using translate\n state.clonedDraggedNode.style.transform = `translate(${\n translateX + scrollX\n }px, ${translateY + scrollY}px)`;\n\n if (e.cancelable) pd(e);\n\n pointermoveClasses(state, state.initialParent.data.config);\n}\n\n/**\n * Handle the synth move.\n *\n * @param e - The pointer event.\n * @param state - The synth drag state.\n *\n * @returns void\n */\nexport function synthMove(e: PointerEvent, state: SynthDragState) {\n moveNode(e, state);\n\n const coordinates = eventCoordinates(e);\n\n handleSynthScroll(coordinates, e, state);\n\n const elFromPoint = getElFromPoint(coordinates);\n\n if (!elFromPoint) {\n document.dispatchEvent(\n new CustomEvent(\"handleRootPointerover\", {\n detail: {\n e,\n state,\n },\n })\n );\n\n return;\n }\n const pointerMoveEventData = {\n e,\n targetData: elFromPoint,\n state,\n };\n\n if (\"node\" in elFromPoint) {\n elFromPoint.node.el.dispatchEvent(\n new CustomEvent(\"handleNodePointerover\", {\n detail: pointerMoveEventData,\n })\n );\n } else {\n elFromPoint.parent.el.dispatchEvent(\n new CustomEvent(\"handleParentPointerover\", {\n detail: pointerMoveEventData,\n })\n );\n }\n}\n\n/**\n * Handle the node drag over.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n const { x, y } = eventCoordinates(data.e);\n\n state.coordinates.y = y;\n\n state.coordinates.x = x;\n\n pd(data.e);\n\n sp(data.e);\n\n data.targetData.parent.el === state.currentParent?.el\n ? sort(data, state)\n : transfer(data, state);\n}\n\n/**\n * Handle the parent drag over.\n *\n * @param data - The parent drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n Object.assign(eventCoordinates(data.e));\n\n transfer(data, state);\n}\n\n/**\n * Handle the parent pointer over.\n *\n * @param e - The parent pointer over event.\n *\n * @returns void\n */\nexport function handleParentPointerover(e: PointeroverParentEvent) {\n if (e.detail.targetData.parent.el !== e.detail.state.currentParent.el)\n transfer(e.detail, e.detail.state);\n}\n\n/**\n * Validate the transfer.\n *\n * @param data - The transfer data.\n *\n * @returns Whether the transfer is valid.\n */\nexport function validateTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n state: BaseDragState;\n}) {\n if (targetParent.el === currentParent.el) return false;\n\n const targetConfig = targetParent.data.config;\n\n if (draggedNodes[0].el.contains(targetParent.el)) return false;\n\n if (targetConfig.dropZone === false) return false;\n\n const initialParentConfig = initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n targetParent,\n initialParent,\n currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Handle the node drag enter.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragenter(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Handle the node drag leave.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragleave(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Validate the sort.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n * @param x - The x coordinate.\n * @param y - The y coordinate.\n *\n * @returns Whether the sort is valid.\n */\nexport function validateSort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState,\n x: number,\n y: number\n): boolean {\n if (\n state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.targetData.node.data.value)\n ) {\n return false;\n }\n\n if (state.remapJustFinished) {\n state.remapJustFinished = false;\n\n if (\n data.targetData.node.data.value === state.currentTargetValue ||\n state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)\n ) {\n state.currentTargetValue = data.targetData.node.data.value;\n }\n\n return false;\n }\n\n if (state.preventEnter) return false;\n\n if (state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)) {\n state.currentTargetValue = undefined;\n\n return false;\n }\n\n if (data.targetData.node.data.value === state.currentTargetValue)\n return false;\n\n if (\n data.targetData.parent.el !== state.currentParent?.el ||\n data.targetData.parent.data.config.sortable === false\n )\n return false;\n\n if (data.targetData.node.el.contains(state.draggedNodes[0].el)) return false;\n\n const targetRect = data.targetData.node.el.getBoundingClientRect();\n\n const dragRect = state.draggedNode.el.getBoundingClientRect();\n\n const yDiff = targetRect.y - dragRect.y;\n\n const xDiff = targetRect.x - dragRect.x;\n\n let incomingDirection: \"above\" | \"below\" | \"left\" | \"right\";\n\n if (Math.abs(yDiff) > Math.abs(xDiff)) {\n incomingDirection = yDiff > 0 ? \"above\" : \"below\";\n } else {\n incomingDirection = xDiff > 0 ? \"left\" : \"right\";\n }\n\n const threshold = state.currentParent.data.config.threshold;\n\n switch (incomingDirection) {\n case \"left\":\n if (x > targetRect.x + targetRect.width * threshold.horizontal) {\n state.incomingDirection = \"left\";\n\n return true;\n }\n break;\n\n case \"right\":\n if (x < targetRect.x + targetRect.width * (1 - threshold.horizontal)) {\n state.incomingDirection = \"right\";\n\n return true;\n }\n break;\n\n case \"above\":\n if (y > targetRect.y + targetRect.height * threshold.vertical) {\n state.incomingDirection = \"above\";\n\n return true;\n }\n break;\n\n case \"below\":\n if (y < targetRect.y + targetRect.height * (1 - threshold.vertical)) {\n state.incomingDirection = \"below\";\n\n return true;\n }\n break;\n\n default:\n break;\n }\n\n return false;\n}\n\n/**\n * Sort the nodes.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function sort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState\n) {\n const { x, y } = eventCoordinates(data.e);\n\n if (!validateSort(data, state, x, y)) return;\n\n const range =\n state.draggedNode.data.index > data.targetData.node.data.index\n ? [data.targetData.node.data.index, state.draggedNode.data.index]\n : [state.draggedNode.data.index, data.targetData.node.data.index];\n\n state.targetIndex = data.targetData.node.data.index;\n\n state.affectedNodes = data.targetData.parent.data.enabledNodes.filter(\n (node) => {\n return (\n range[0] <= node.data.index &&\n node.data.index <= range[1] &&\n node.el !== state.draggedNode.el\n );\n }\n );\n\n data.targetData.parent.data.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.draggedNodes,\n targetNodes: [data.targetData.node],\n });\n}\n\n/**\n * Event listener used for all nodes.\n *\n * @param e - The event.\n *\n */\nexport function nodeEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function nodeTargetData(node: Node): NodeTargetData | undefined {\n const nodeData = nodes.get(node);\n\n if (!nodeData) return;\n\n const parentData = parents.get(node.parentNode);\n\n if (!parentData) return;\n\n return {\n node: {\n el: node,\n data: nodeData,\n },\n parent: {\n el: node.parentNode,\n data: parentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = nodeTargetData(e.currentTarget as Node);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\n/**\n * Transfer the nodes.\n *\n * @param data - The node event data or parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function transfer(\n data: NodeEventData | ParentEventData,\n state: DragState\n): void {\n if (\n !validateTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent as any,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n state,\n })\n )\n return;\n\n data.targetData.parent.data.config.performTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n initialIndex: state.initialIndex,\n state,\n targetNodes: \"node\" in data.targetData ? [data.targetData.node] : [],\n });\n\n state.currentParent = data.targetData.parent;\n\n state.transferred = true;\n}\n\n/**\n * Event listener used for all parents.\n *\n * @param callback - The callback.\n *\n * @returns A function to get the parent event data.\n */\nexport function parentEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function parentTargetData(\n parent: HTMLElement\n ): ParentTargetData | undefined {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: parent,\n data: parentData as ParentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = parentTargetData(e.currentTarget as HTMLElement);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\nexport function addNodeClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function nodeSetter(node: Node, nodeData: NodeData) {\n nodes.set(node, nodeData);\n }\n\n for (const el of els) {\n const nodeData = nodes.get(el as Node);\n\n const newData = addClass(el, className, nodeData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n nodeSetter(el as Node, newData as NodeData);\n }\n}\n\n/**\n * Add class to the parent.\n *\n * @param els - The parents.\n * @param className - The class name.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addParentClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function parentSetter(parent: HTMLElement, parentData: ParentData) {\n parents.set(parent, parentData);\n }\n\n for (const el of els) {\n const parentData = parents.get(el);\n\n const newData = addClass(el, className, parentData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n parentSetter(el, newData as ParentData);\n }\n}\n\n/**\n * Add class to the node.\n *\n * @param el - The node.\n * @param className - The class name.\n * @param data - The node data.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addClass(\n el: Node | HTMLElement | Element,\n className: string | undefined,\n data: NodeData | ParentData | undefined,\n omitAppendPrivateClass = false\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n if (classNames.includes(\"longPress\")) return;\n\n if (!data) {\n el.classList.add(...classNames);\n\n return;\n }\n\n const privateClasses = [];\n\n for (const className of classNames) {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n } else if (\n el.classList.contains(className) &&\n omitAppendPrivateClass === false\n ) {\n privateClasses.push(className);\n }\n }\n\n data.privateClasses = privateClasses;\n\n return data;\n}\n\n/**\n * Remove class from the nodes.\n *\n * @param els - The nodes.\n * @param className - The class name.\n *\n * @returns void\n */\nexport function removeClass(\n els: Array,\n className: string | undefined\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n for (const node of els) {\n if (!isNode(node)) {\n node.classList.remove(...classNames);\n continue;\n }\n\n const nodeData = nodes.get(node) || parents.get(node);\n\n if (!nodeData) continue;\n\n for (const className of classNames) {\n if (!nodeData.privateClasses.includes(className)) {\n node.classList.remove(className);\n }\n }\n }\n}\n\nfunction isScrollX(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect,\n state: SynthDragState\n): { left: boolean; right: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n const canScrollLeft = el.scrollLeft > 0;\n const canScrollRight =\n el.scrollLeft + window.innerWidth < (state.rootScrollWidth || 0);\n\n return {\n right: canScrollRight && e.clientX > el.clientWidth * (1 - threshold),\n left: canScrollLeft && e.clientX < el.clientWidth * threshold,\n };\n }\n\n if (\n (style.overflowX === \"auto\" || style.overflowX === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollWidth = el.scrollWidth;\n const offsetWidth = el.offsetWidth;\n const scrollLeft = el.scrollLeft;\n\n return {\n right:\n e.clientX > rect.left + offsetWidth * (1 - threshold) &&\n scrollLeft < scrollWidth - offsetWidth,\n left: e.clientX < rect.left + offsetWidth * threshold && scrollLeft > 0,\n };\n }\n\n return {\n right: false,\n left: false,\n };\n}\n\nfunction isScrollY(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect\n): { up: boolean; down: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n return {\n down: e.clientY > el.clientHeight * (1 - threshold),\n up: e.clientY < el.clientHeight * threshold,\n };\n }\n\n if (\n (style.overflowY === \"auto\" || style.overflowY === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollHeight = el.scrollHeight;\n const offsetHeight = el.offsetHeight;\n const scrollTop = el.scrollTop;\n\n return {\n down:\n e.clientY > rect.top + offsetHeight * (1 - threshold) &&\n scrollTop < scrollHeight - offsetHeight,\n up: e.clientY < rect.top + offsetHeight * threshold && scrollTop > 0,\n };\n }\n\n return {\n down: false,\n up: false,\n };\n}\n\nfunction scrollX(\n el: HTMLElement,\n e: PointerEvent,\n state: SynthDragState,\n right = true\n) {\n state.preventEnter = true;\n\n const incr = right ? 5 : -5;\n\n function scroll(el: HTMLElement) {\n el.scrollBy({ left: incr });\n\n moveNode(e, state, incr, 0);\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n }\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n}\n\nfunction scrollY(\n el: Element,\n e: PointerEvent,\n state: SynthDragState,\n up = true\n) {\n state.preventEnter = true;\n\n const incr = up ? -5 : 5;\n\n function scroll() {\n el.scrollBy({ top: incr });\n\n moveNode(e, state, 0, incr);\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n }\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n}\n\n/**\n * Handle the synth scroll.\n *\n * @param coordinates - The coordinates.\n * @param e - The event.\n * @param state - The state.\n *\n * @returns void\n */\nfunction handleSynthScroll(\n coordinates: { x: number; y: number },\n e: PointerEvent,\n state: SynthDragState\n) {\n cancelSynthScroll(state);\n\n const scrollables: Record<\"x\" | \"y\", HTMLElement | null> = {\n x: null,\n y: null,\n };\n\n const els = document.elementsFromPoint(coordinates.x, coordinates.y);\n\n for (const el of els) {\n if (scrollables.x && scrollables.y) break;\n\n if (!(el instanceof HTMLElement)) continue;\n\n const rect = el.getBoundingClientRect();\n\n const style = window.getComputedStyle(el);\n\n if (!scrollables.x) {\n const { left, right } = isScrollX(el, e, style, rect, state);\n\n if (left || right) {\n scrollables.x = el;\n\n scrollX(el, e, state, right);\n }\n }\n\n if (!scrollables.y) {\n const { up, down } = isScrollY(el, e, style, rect);\n\n if (up || down) {\n scrollables.y = el;\n\n scrollY(el, e, state, up);\n }\n }\n }\n}\n\nexport function getElFromPoint(coordinates: {\n x: number;\n y: number;\n}): NodeFromPoint | ParentFromPoint | undefined {\n let target = document.elementFromPoint(coordinates.x, coordinates.y);\n\n if (!isNode(target)) return;\n\n let isParent;\n\n let invalidEl = true;\n\n while (target && invalidEl) {\n if (nodes.has(target as Node) || parents.has(target as HTMLElement)) {\n invalidEl = false;\n\n isParent = parents.has(target as HTMLElement);\n\n break;\n }\n\n target = target.parentNode as Node;\n }\n\n if (!isParent) {\n const targetNodeData = nodes.get(target as Node);\n\n if (!targetNodeData) return;\n\n const targetParentData = parents.get(target.parentNode as Node);\n\n if (!targetParentData) return;\n\n return {\n node: {\n el: target as Node,\n data: targetNodeData,\n },\n parent: {\n el: target.parentNode as Node,\n data: targetParentData as ParentData,\n },\n };\n } else {\n const parentData = parents.get(target as HTMLElement);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: target as HTMLElement,\n data: parentData as ParentData,\n },\n };\n }\n}\n\n/**\n * Checks to see that a given element and its parent node is instance of\n * HTMLElement.\n *\n * @param {unknown} el - The element to check.\n *\n * @returns {boolean} - Whether or not provided element is of type Node.\n */\nexport function isNode(el: unknown): el is Node {\n return el instanceof HTMLElement && el.parentNode instanceof HTMLElement;\n}\n\n/**\n * Takes a given el and event handlers, assigns them, and returns the used abort\n * controller.\n *\n * @param el - The element to add the event listeners to.\n * @param events - The events to add to the element.\n * @returns - The abort controller used for the event listeners.\n */\nexport function addEvents(\n el: Document | ShadowRoot | Node | HTMLElement | Window,\n events: EventHandlers | any\n): AbortController {\n const abortController = new AbortController();\n\n for (const eventName in events) {\n const handler = events[eventName];\n\n el.addEventListener(eventName, handler, {\n signal: abortController.signal,\n passive: false,\n });\n }\n\n return abortController;\n}\n","/**\n * Function to prevent default behavior of an event.\n *\n * @param {Event} e - The event to prevent default behavior of.\n */\nexport function pd(e: Event) {\n e.preventDefault();\n}\n\n/**\n * Function to stop propagation of an event.\n *\n * @param {Event} e - The event to stop propagation of.\n */\nexport function sp(e: Event) {\n e.stopPropagation();\n}\n\nexport function rect(el: HTMLElement) {\n return el.getBoundingClientRect();\n}\n\n/**\n * Function to create an emitter.\n *\n * @returns {[Function, Function]} A tuple containing emit and on functions\n */\nexport function createEmitter() {\n const callbacks = new Map void>>();\n\n const emit = function (eventName: string, data: T) {\n if (!callbacks.get(eventName)) return;\n callbacks.get(eventName)!.forEach((cb) => {\n cb(data);\n });\n };\n\n const on = function (eventName: string, callback: (data: T) => void) {\n const cbs = callbacks.get(eventName) ?? [];\n\n cbs.push(callback);\n\n callbacks.set(eventName, cbs);\n };\n\n return [emit, on] as const;\n}\n\n/**\n * The emit and on functions for drag and drop.\n *\n * @type {[Function, Function]}\n */\nexport const [emit, on] = createEmitter();\n\n/**\n * A regular expression to test for a valid date string.\n *\n * @param x - A RegExp to compare.\n * @param y - A RegExp to compare.\n * @public\n */\nexport function eqRegExp(x: RegExp, y: RegExp): boolean {\n return (\n x.source === y.source &&\n x.flags.split(\"\").sort().join(\"\") === y.flags.split(\"\").sort().join(\"\")\n );\n}\n\n/**\n * Compare two values for equality, optionally at depth.\n *\n * @param valA - First value.\n * @param valB - Second value.\n * @param deep - If it will compare deeply if it's an object.\n * @param explicit - An array of keys to explicity check.\n *\n * @returns `boolean`\n *\n * @public\n */\nexport function eq(\n valA: unknown,\n valB: unknown,\n deep = true,\n explicit: string[] = [\"__key\"]\n): boolean {\n if (valA === valB) return true;\n\n if (\n typeof valB === \"object\" &&\n typeof valA === \"object\" &&\n valA !== null &&\n valB !== null\n ) {\n if (valA instanceof Map) return false;\n if (valA instanceof Set) return false;\n if (valA instanceof Date && valB instanceof Date)\n return valA.getTime() === valB.getTime();\n if (valA instanceof RegExp && valB instanceof RegExp)\n return eqRegExp(valA, valB);\n if (valA === null || valB === null) return false;\n\n const objA = valA as Record;\n const objB = valB as Record;\n\n if (Object.keys(objA).length !== Object.keys(objB).length) return false;\n\n for (const k of explicit) {\n if ((k in objA || k in objB) && objA[k] !== objB[k]) return false;\n }\n\n for (const key in objA) {\n if (!(key in objB)) return false;\n if (objA[key] !== objB[key] && !deep) return false;\n if (deep && !eq(objA[key], objB[key], deep, explicit)) return false;\n }\n return true;\n }\n return false;\n}\n\n///**\n// * Throttle a function.\n// *\n// * @param callback - The callback function to throttle.\n// * @param limit - The minimum time in milliseconds between function calls.\n// *\n// * @returns A throttled version of the callback function.\n// */\n//export function throttle(\n// callback: (...args: Args) => Return,\n// limit: number\n//): (...args: Args) => void {\n// let wait = false;\n// return function (...args: Args) {\n// if (!wait) {\n// callback.apply(null, args);\n// wait = true;\n// setTimeout(function () {\n// wait = false;\n// }, limit);\n// }\n// };\n//}\n\n/**\n * Split a class name into an array of class names.\n *\n * @param className - The class name to split.\n *\n * @returns An array of class names.\n */\nexport function splitClass(className: string): Array {\n return className.split(\" \").filter((x) => x);\n}\n\nexport function getRealCoords(el: HTMLElement): {\n top: number;\n bottom: number;\n left: number;\n right: number;\n height: number;\n width: number;\n} {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nexport function eventCoordinates(data: DragEvent | PointerEvent) {\n return { x: data.clientX, y: data.clientY };\n}\n","import type { SetupNodeData, Node } from \"../../types\";\nimport type { AnimationsConfig } from \"./types\";\nimport { state, parents, isDragState } from \"../../index\";\n\nexport function animations(animationsConfig: Partial = {}) {\n const slideUp = [\n {\n transform: `translateY(${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideDown = [\n {\n transform: `translateY(-${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideLeft = [\n {\n transform: `translateX(${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n\n const slideRight = [\n {\n transform: `translateX(-${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n setup() {\n if (document.head.querySelector(\"[data-drag-and-drop]\")) return;\n },\n\n setupNodeRemap(data: SetupNodeData) {\n if (!isDragState(state)) return;\n\n const duration = animationsConfig.duration || 150;\n\n if (data.node.data.value === state.draggedNode.data.value) {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideRight, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n }\n\n return;\n }\n\n if (\n !state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.node.data.value)\n )\n return;\n\n const nodeRect = data.node.el.getBoundingClientRect();\n\n const nodeIndex = state.affectedNodes.findIndex(\n (x) => x.data.value === data.node.data.value\n );\n\n const draggedNodeIndex = state.draggedNode.data.index;\n\n const ascendingDirection = draggedNodeIndex >= state.targetIndex;\n\n let adjacentNode;\n\n if (ascendingDirection) {\n adjacentNode = state.affectedNodes[nodeIndex + 1]\n ? state.affectedNodes[nodeIndex + 1]\n : state.affectedNodes[nodeIndex - 1];\n } else {\n adjacentNode = state.affectedNodes[nodeIndex - 1]\n ? state.affectedNodes[nodeIndex - 1]\n : state.affectedNodes[nodeIndex + 1];\n }\n\n if (adjacentNode) {\n const xDiff = Math.abs(\n nodeRect.x - adjacentNode.el.getBoundingClientRect().x\n );\n\n const yDiff = Math.abs(\n nodeRect.y - adjacentNode.el.getBoundingClientRect().y\n );\n\n if (xDiff > yDiff && ascendingDirection) {\n animate(data.node.el, slideRight, duration);\n } else if (xDiff > yDiff && !ascendingDirection) {\n animate(data.node.el, slideLeft, duration);\n }\n } else {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideRight, duration);\n\n break;\n }\n }\n },\n };\n };\n}\n\nfunction animate(\n node: Node,\n animation: Keyframe[] | PropertyIndexedKeyframes,\n duration: number\n) {\n if (!state) return;\n\n state.preventEnter = true;\n\n node.animate(animation, {\n duration: duration,\n easing: \"ease-in-out\",\n });\n\n setTimeout(() => {\n if (!state) return;\n\n state.preventEnter = false;\n }, duration);\n}\n","import type { InsertConfig } from \"../../types\";\nimport type {\n DragState,\n NodeDragEventData,\n NodeRecord,\n ParentEventData,\n PointeroverParentEvent,\n ParentRecord,\n SynthDragState,\n InsertEvent,\n BaseDragState,\n InsertState,\n Coordinates,\n} from \"../../types\";\n\nimport {\n parents,\n parentValues,\n setParentValues,\n state,\n addParentClass,\n isDragState,\n isSynthDragState,\n removeClass,\n addEvents,\n remapNodes,\n} from \"../../index\";\n\nimport { eq, pd, eventCoordinates } from \"../../utils\";\n\nexport const insertState: InsertState = {\n draggedOverNodes: [],\n draggedOverParent: null,\n targetIndex: 0,\n ascending: false,\n insertPoint: null,\n dragging: false,\n};\n\nlet documentController: AbortController | undefined;\n\n// WIP: This is a work in progress and not yet fully functional\nexport function insert(insertConfig: InsertConfig) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const insertParentConfig = {\n ...parentData.config,\n insertConfig,\n };\n\n return {\n teardown() {\n if (parentData.abortControllers.root) {\n parentData.abortControllers.root.abort();\n }\n },\n setup() {\n insertParentConfig.handleNodeDragover =\n insertConfig.handleNodeDragover || handleNodeDragover;\n\n insertParentConfig.handleParentPointerover =\n insertConfig.handleParentPointerover || handleParentPointerover;\n\n insertParentConfig.handleNodePointerover =\n insertConfig.handleNodePointerover || handleParentPointerover;\n\n insertParentConfig.handleParentDragover =\n insertConfig.handleParentDragover || handleParentDragover;\n\n const originalHandleend = insertParentConfig.handleEnd;\n\n insertParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: checkPosition,\n pointermove: checkPosition,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = insertParentConfig;\n\n state.on(\"dragStarted\", () => {\n defineRanges(parent);\n });\n\n state.on(\"scrollStarted\", () => {\n if (insertState.insertPoint)\n insertState.insertPoint.el.style.display = \"none\";\n });\n\n state.on(\"scrollEnded\", () => {\n defineRanges(parent);\n });\n\n const firstScrollableParent = findFirstOverflowingParent(parent);\n\n if (firstScrollableParent) {\n firstScrollableParent.addEventListener(\n \"scroll\",\n defineRanges.bind(null, parent)\n );\n }\n\n window.addEventListener(\"resize\", defineRanges.bind(null, parent));\n },\n };\n };\n}\n\nfunction findFirstOverflowingParent(element: HTMLElement): HTMLElement | null {\n let parent = element.parentElement;\n\n while (parent) {\n const { overflow, overflowY, overflowX } = getComputedStyle(parent);\n\n // Check if the overflow property is set to scroll, auto, or hidden (anything other than visible)\n const isOverflowSet =\n overflow !== \"visible\" ||\n overflowY !== \"visible\" ||\n overflowX !== \"visible\";\n\n // Check if there is actual overflow (scrolling)\n const isOverflowing =\n parent.scrollHeight > parent.clientHeight ||\n parent.scrollWidth > parent.clientWidth;\n const hasScrollPosition = parent.scrollTop > 0 || parent.scrollLeft > 0;\n\n if (isOverflowSet && (isOverflowing || hasScrollPosition)) {\n return parent;\n }\n\n parent = parent.parentElement;\n }\n\n return null; // No overflowing parent found\n}\n\nfunction checkPosition(e: DragEvent | PointerEvent) {\n if (!isDragState(state)) return;\n\n const el = document.elementFromPoint(e.clientX, e.clientY);\n\n if (!(el instanceof HTMLElement)) return;\n\n if (!parents.has(el)) {\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint?.el === el) return;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n if (insertState.draggedOverParent) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n\n state.currentParent = state.initialParent;\n }\n}\n\ninterface Range {\n x: [number, number];\n y: [number, number];\n vertical: boolean;\n}\n\nfunction createVerticalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean\n): Range {\n const center = nodeCoords.top + nodeCoords.height / 2;\n\n if (!otherCoords) {\n const offset = nodeCoords.height / 2 + 10;\n return {\n y: isAscending ? [center, center + offset] : [center - offset, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n }\n\n const otherEdge = isAscending ? otherCoords.top : otherCoords.bottom;\n const nodeEdge = isAscending ? nodeCoords.bottom : nodeCoords.top;\n const midpoint = nodeEdge + Math.abs(nodeEdge - otherEdge) / 2;\n\n return {\n y: isAscending ? [center, midpoint] : [midpoint, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n}\n\nfunction createHorizontalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean,\n lastInRow = false\n): Range {\n const center = nodeCoords.left + nodeCoords.width / 2;\n\n if (!otherCoords) {\n if (isAscending) {\n return {\n x: [center, center + nodeCoords.width],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [nodeCoords.left - 10, center],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n }\n\n if (isAscending && lastInRow) {\n return {\n x: [center, nodeCoords.right + 10],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n\n if (isAscending) {\n const nextNodeCenter = otherCoords.left + otherCoords.width / 2;\n return {\n x: [center, center + Math.abs(center - nextNodeCenter) / 2],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [\n otherCoords.right + Math.abs(otherCoords.right - nodeCoords.left) / 2,\n center,\n ],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n}\n\nfunction getRealCoords(el: HTMLElement): Coordinates {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nfunction defineRanges(parent: HTMLElement) {\n if (!isDragState(state)) return;\n\n const parentData = parents.get(parent);\n if (!parentData) return;\n\n const enabledNodes = parentData.enabledNodes;\n\n enabledNodes.forEach((node, index) => {\n node.data.range = {};\n\n const prevNode = enabledNodes[index - 1];\n const nextNode = enabledNodes[index + 1];\n const nodeCoords = getRealCoords(node.el);\n const prevNodeCoords = prevNode ? getRealCoords(prevNode.el) : undefined;\n const nextNodeCoords = nextNode ? getRealCoords(nextNode.el) : undefined;\n\n const aboveOrBelowPrevious =\n prevNodeCoords &&\n (nodeCoords.top > prevNodeCoords.bottom ||\n nodeCoords.bottom < prevNodeCoords.top);\n\n const aboveOrBelowAfter =\n nextNodeCoords &&\n (nodeCoords.top > nextNodeCoords.bottom ||\n nodeCoords.bottom < nextNodeCoords.top);\n\n const fullishWidth =\n parent.getBoundingClientRect().width * 0.8 < nodeCoords.width;\n\n if (fullishWidth) {\n node.data.range.ascending = createVerticalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createVerticalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowAfter && !aboveOrBelowPrevious) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (!aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowPrevious && !nextNodeCoords) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n undefined,\n true\n );\n } else if (aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n undefined,\n false\n );\n }\n });\n}\n\nexport function handleNodeDragover(data: NodeDragEventData) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n data.e.preventDefault();\n}\n\nfunction processParentDragEvent(\n e: DragEvent | PointerEvent,\n targetData: ParentEventData[\"targetData\"],\n state: DragState,\n isNativeDrag: boolean\n) {\n const config = targetData.parent.data.config;\n\n if (!isNativeDrag && config.nativeDrag) return;\n\n pd(e);\n\n if (isNativeDrag) pd(e);\n\n const { x, y } = eventCoordinates(e);\n\n // Calculate global coordinates\n const clientX = x;\n const clientY = y;\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n state.coordinates.x = clientX + scrollLeft;\n state.coordinates.y = clientY + scrollTop;\n\n const nestedParent = targetData.parent.data.nestedParent;\n\n let realTargetParent = targetData.parent;\n\n if (nestedParent) {\n const rect = nestedParent.el.getBoundingClientRect();\n\n if (state.coordinates.y > rect.top && state.coordinates.y < rect.bottom)\n realTargetParent = nestedParent;\n }\n\n if (realTargetParent.el === state.currentParent?.el) {\n moveBetween(realTargetParent, state);\n } else {\n moveOutside(realTargetParent, state);\n }\n\n state.currentParent = realTargetParent;\n}\n\nexport function handleParentDragover(\n data: ParentEventData,\n state: DragState\n) {\n processParentDragEvent(data.e as DragEvent, data.targetData, state, true);\n}\n\nexport function handleParentPointerover(data: PointeroverParentEvent) {\n const { detail } = data;\n\n const { state, targetData } = detail;\n\n if (state.scrolling) return;\n\n processParentDragEvent(detail.e, targetData, state, false);\n}\n\nexport function moveBetween(data: ParentRecord, state: DragState) {\n if (data.data.config.sortable === false) return;\n\n if (\n data.el === insertState.draggedOverParent?.el &&\n insertState.draggedOverParent.data.getValues(data.el).length === 0\n ) {\n return;\n } else if (insertState.draggedOverParent?.el) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n insertState.draggedOverParent = null;\n }\n\n const foundRange = findClosest(data.data.enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n}\n\nfunction moveOutside(data: ParentRecord, state: DragState) {\n if (data.el === state.currentParent.el) return false;\n\n const targetConfig = data.data.config;\n\n if (state.draggedNode.el.contains(data.el)) return false;\n\n if (targetConfig.dropZone === false) return;\n\n const initialParentConfig = state.initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n data,\n state.initialParent,\n state.currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n const values = data.data.getValues(data.el);\n\n if (!values.length) {\n addParentClass([data.el], targetConfig.dropZoneClass);\n\n insertState.draggedOverParent = data as ParentRecord;\n\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n } else {\n removeClass([state.currentParent.el], targetConfig.dropZoneClass);\n\n const enabledNodes = data.data.enabledNodes;\n\n const foundRange = findClosest(enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n }\n}\n\nfunction findClosest(enabledNodes: NodeRecord[], state: DragState) {\n let foundRange: [NodeRecord, string] | null = null;\n\n for (let x = 0; x < enabledNodes.length; x++) {\n if (!state || !enabledNodes[x].data.range) continue;\n\n if (enabledNodes[x].data.range!.ascending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.ascending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.ascending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.ascending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.ascending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"ascending\"];\n\n return foundRange;\n }\n }\n\n if (enabledNodes[x].data.range!.descending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.descending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.descending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.descending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.descending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"descending\"];\n\n return foundRange;\n }\n }\n }\n}\n\nfunction createInsertPoint(\n parent: ParentRecord,\n insertState: InsertState\n) {\n const insertPoint = parent.data.config.insertConfig?.insertPoint({\n el: parent.el,\n data: parent.data,\n });\n\n if (!insertPoint)\n throw new Error(\"Insert point not found\", { cause: parent });\n\n insertState.insertPoint = {\n parent,\n el: insertPoint,\n };\n\n document.body.appendChild(insertPoint);\n\n Object.assign(insertPoint, {\n position: \"absolute\",\n display: \"none\",\n });\n}\n\nfunction removeInsertPoint(insertState: InsertState) {\n if (insertState.insertPoint?.el) insertState.insertPoint.el.remove();\n\n insertState.insertPoint = null;\n}\n\nfunction positioninsertPoint(\n parent: ParentRecord,\n position: { x: number[]; y: number[]; vertical: boolean },\n ascending: boolean,\n node: NodeRecord,\n insertState: InsertState\n) {\n if (insertState.insertPoint?.el !== parent.el) {\n removeInsertPoint(insertState);\n\n createInsertPoint(parent, insertState);\n }\n\n insertState.draggedOverNodes = [node];\n\n if (!insertState.insertPoint) return;\n\n if (position.vertical) {\n const topPosition =\n position.y[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().height / 2;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${topPosition}px`,\n left: `${position.x[0]}px`,\n right: `${position.x[1]}px`,\n height: \"4px\",\n width: `${position.x[1] - position.x[0]}px`,\n });\n } else {\n const leftPosition =\n position.x[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().width / 2;\n insertState.insertPoint.el.style.left = `${leftPosition}px`;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${position.y[0]}px`,\n bottom: `${position.y[1]}px`,\n width: \"4px\",\n height: `${position.y[1] - position.y[0]}px`,\n });\n }\n\n insertState.targetIndex = node.data.index;\n\n insertState.ascending = ascending;\n\n insertState.insertPoint.el.style.display = \"block\";\n}\n\nexport function handleParentDrop(_data: NodeDragEventData) {}\n\n/**\n * Performs the actual insertion of the dragged nodes into the target parent.\n *\n * @param state - The current drag state.\n */\nexport function handleEnd(\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isDragState(state)) return;\n\n const insertPoint = insertState.insertPoint;\n\n if (!insertState.draggedOverParent) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const transferred = state.initialParent.el !== state.currentParent.el;\n\n remapNodes(state.initialParent.el);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const enabledNodes = [...state.initialParent.data.enabledNodes];\n\n const originalIndex = state.draggedNodes[0].data.index;\n\n const targetIndex = insertState.targetIndex;\n\n if (\n !transferred &&\n insertState.draggedOverNodes[0] &&\n insertState.draggedOverNodes[0].el !== state.draggedNodes[0].el\n ) {\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n let index = insertState.draggedOverNodes[0].data.index;\n\n if (\n insertState.targetIndex > state.draggedNodes[0].data.index &&\n !insertState.ascending\n ) {\n index--;\n } else if (\n insertState.targetIndex < state.draggedNodes[0].data.index &&\n insertState.ascending\n ) {\n index++;\n }\n\n newParentValues.splice(index, 0, ...draggedValues);\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n if (state.initialParent.data.config.onSort) {\n const sortEventData = {\n parent: {\n el: state.initialParent.el,\n data: state.initialParent.data,\n } as ParentRecord,\n previousValues: [...draggedParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...state.initialParent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes,\n previousPosition: originalIndex,\n position: index,\n state: state as DragState,\n };\n\n state.initialParent.data.config.onSort(sortEventData);\n }\n } else if (transferred && insertState.draggedOverNodes.length) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n // For the time being, we will not be remoing the value of the original dragged parent.\n let index = insertState.draggedOverNodes[0].data.index || 0;\n\n if (insertState.ascending) index++;\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n targetIndex: index,\n })\n : draggedValues;\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n if (state.currentParent.el.contains(state.initialParent.el)) {\n // Update initial parent values first\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n // Now get the target parent values.\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n } else {\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n }\n\n const data = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n targetIndex,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.onTransfer)\n state.initialParent.data.config.onTransfer(data);\n if (state.currentParent.data.config.onTransfer)\n state.currentParent.data.config.onTransfer(data);\n }\n } else if (insertState.draggedOverParent) {\n if (state.currentParent.el.contains(state.initialParent.el)) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n } else {\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n }\n\n const data: InsertEvent = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.insertConfig?.insertEvent)\n state.initialParent.data.config.insertConfig.insertEvent(data);\n if (state.currentParent.data.config.insertConfig?.insertEvent)\n state.currentParent.data.config.insertConfig.insertEvent(data);\n\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n const dropZoneClass = isSynthDragState(state)\n ? state.initialParent.data.config.synthDropZoneClass\n : state.initialParent.data.config.dropZoneClass;\n\n removeClass(\n insertState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const dragPlaceholderClass =\n state.initialParent.data.config.dragPlaceholderClass;\n\n removeClass(\n state.draggedNodes.map((node) => node.el),\n dragPlaceholderClass\n );\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n}\n","import type {\n DropSwapConfig,\n NodeDragEventData,\n DragState,\n SynthDragState,\n NodeRecord,\n PointeroverNodeEvent,\n ParentDragEventData,\n PointeroverParentEvent,\n DropSwapState,\n} from \"../../types\";\nimport {\n parents,\n parentValues,\n setParentValues,\n addNodeClass,\n isSynthDragState,\n removeClass,\n addClass,\n state,\n addEvents,\n isDragState,\n} from \"../../index\";\n\nexport const dropSwapState: DropSwapState = {\n draggedOverNodes: Array>(),\n initialDraggedIndex: undefined,\n transferred: false,\n dragging: false,\n};\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\nexport function dropOrSwap(dropSwapConfig: DropSwapConfig = {}) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const dropSwapParentConfig = {\n ...parentData.config,\n dropSwapConfig,\n };\n\n return {\n setup() {\n dropSwapParentConfig.handleNodeDragover =\n dropSwapConfig.handleNodeDragover || handleNodeDragover;\n\n dropSwapParentConfig.handleParentDragover =\n dropSwapConfig.handleParentDragover || handleParentDragover;\n\n dropSwapParentConfig.handleNodePointerover =\n dropSwapConfig.handleNodePointerover || handleNodePointerover;\n\n dropSwapParentConfig.handleParentPointerover =\n dropSwapConfig.handleParentPointerover || handeParentPointerover;\n\n const originalHandleend = dropSwapParentConfig.handleEnd;\n\n dropSwapParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: rootDragover,\n handleRootPointerover: rootPointerover,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = dropSwapParentConfig;\n },\n };\n };\n}\n\nfunction rootDragover(_e: DragEvent) {\n if (!isDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.dropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction rootPointerover(_e: CustomEvent) {\n if (!isSynthDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.synthDropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction updateDraggedOverNodes(\n data: PointeroverNodeEvent | NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const targetData =\n \"detail\" in data ? data.detail.targetData : data.targetData;\n\n const config = targetData.parent.data.config;\n\n const dropZoneClass = isSynthDragState(state)\n ? config.synthDropZoneClass\n : config.dropZoneClass;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const enabledNodes = targetData.parent.data.enabledNodes;\n\n if (!enabledNodes) return;\n\n dropSwapState.draggedOverNodes = enabledNodes.slice(\n targetData.node.data.index,\n targetData.node.data.index + state.draggedNodes.length\n );\n\n addNodeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass,\n true\n );\n\n state.currentTargetValue = targetData.node.data.value;\n\n state.currentParent = targetData.parent;\n\n addClass(\n state.currentParent.el,\n isSynthDragState(state)\n ? config.synthDropZoneParentClass\n : config.dropZoneParentClass,\n state.currentParent.data,\n true\n );\n}\n\nfunction handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n updateDraggedOverNodes(data, state);\n}\n\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n const currentConfig = state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.dropZoneClass\n );\n\n removeClass([state.currentParent.el], currentConfig.dropZoneParentClass);\n\n const config = data.targetData.parent.data.config;\n\n addClass(\n data.targetData.parent.el,\n config.dropZoneParentClass,\n data.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n state.currentParent = data.targetData.parent;\n}\n\nexport function handeParentPointerover(data: PointeroverParentEvent) {\n const currentConfig = data.detail.state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.synthDropZoneClass\n );\n\n removeClass(\n [data.detail.state.currentParent.el],\n currentConfig.synthDropZoneParentClass\n );\n\n const config = data.detail.targetData.parent.data.config;\n\n addClass(\n data.detail.targetData.parent.el,\n config.synthDropZoneParentClass,\n data.detail.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n data.detail.state.currentParent = data.detail.targetData.parent;\n}\n\nfunction handleNodePointerover(data: PointeroverNodeEvent) {\n if (!isSynthDragState(data.detail.state)) return;\n\n updateDraggedOverNodes(data, data.detail.state);\n}\n\nfunction swapElements(\n arr1: T[],\n arr2: T[] | null,\n index1: number | number[],\n index2: number\n): T[] | [T[], T[]] {\n const indices1 = Array.isArray(index1) ? index1 : [index1];\n\n if (arr2 === null) {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr1[index2];\n\n arr1.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return arr1.filter((el) => el !== undefined);\n } else {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr2[index2];\n\n arr2.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return [arr1.filter((el) => el !== undefined), arr2];\n }\n}\n\nfunction handleEnd(state: DragState | SynthDragState) {\n const isSynth = isSynthDragState(state);\n\n removeClass(\n [state.currentParent.el],\n isSynth\n ? state.currentParent.data.config.synthDropZoneParentClass\n : state.currentParent.data.config.dropZoneParentClass\n );\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n isSynth\n ? state.currentParent.data.config.synthDropZoneClass\n : state.currentParent.data.config.dropZoneClass\n );\n\n const values = parentValues(state.currentParent.el, state.currentParent.data);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const newValues = values.filter((x) => !draggedValues.includes(x));\n\n const targetIndex = dropSwapState.draggedOverNodes[0]?.data.index;\n\n const draggedIndex = state.draggedNodes[0].data.index;\n\n const initialParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n if (targetIndex === undefined) {\n if (state.initialParent.el === state.currentParent.el) return;\n\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n values.concat(draggedValues)\n );\n\n return;\n }\n\n let swap = false;\n\n const shouldSwap = state.initialParent.data.config.dropSwapConfig?.shouldSwap;\n\n if (shouldSwap)\n swap = shouldSwap({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: dropSwapState.draggedOverNodes as NodeRecord[],\n state,\n });\n\n if (state.initialParent.el === state.currentParent.el) {\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n swap ? swapElements(values, null, draggedIndex, targetIndex) : newValues\n );\n } else {\n if (swap) {\n const res = swapElements(\n initialParentValues,\n newValues,\n state.initialIndex,\n targetIndex\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n res[0] as T[]\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n res[1] as T[]\n );\n } else {\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n newValues\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAAA;AAAA,EAAA;AAAA,4BAAAC;AAAA,EAAA;AAAA;AAAA;AAAA,+BAAAC;AAAA,EAAA;AAAA,8BAAAC;AAAA,EAAA;AAAA;AAAA;AAAA,iCAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,SAAS,GAAG,GAAU;AAC3B,IAAE,eAAe;AACnB;AAOO,SAAS,GAAG,GAAU;AAC3B,IAAE,gBAAgB;AACpB;AAWO,SAAS,gBAAmB;AACjC,QAAM,YAAY,oBAAI,IAAsC;AAE5D,QAAMC,QAAO,SAAU,WAAmB,MAAS;AACjD,QAAI,CAAC,UAAU,IAAI,SAAS,EAAG;AAC/B,cAAU,IAAI,SAAS,EAAG,QAAQ,CAAC,OAAO;AACxC,SAAG,IAAI;AAAA,IACT,CAAC;AAAA,EACH;AAEA,QAAMC,MAAK,SAAU,WAAmB,UAA6B;AACnE,UAAM,MAAM,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,UAAU;AACb,UAAM,iBAAiB,MAAM,IAAI,MAAc;AAE/C,QAAI,CAAC,eAAgB;AAErB,UAAM,mBAAmB,QAAQ,IAAI,OAAO,UAAkB;AAE9D,QAAI,CAAC,iBAAkB;AAEvB,WAAO;AAAA,MACL,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,MACA,QAAQ;AAAA,QACN,IAAI,OAAO;AAAA,QACX,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,OAAO;AACL,UAAM,aAAa,QAAQ,IAAI,MAAqB;AAEpD,QAAI,CAAC,WAAY;AAEjB,WAAO;AAAA,MACL,QAAQ;AAAA,QACN,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AAUO,SAAS,OAAO,IAAyB;AAC9C,SAAO,cAAc,eAAe,GAAG,sBAAsB;AAC/D;AAUO,SAAS,UACd,IACA,QACiB;AACjB,QAAM,kBAAkB,IAAI,gBAAgB;AAE5C,aAAW,aAAa,QAAQ;AAC9B,UAAM,UAAU,OAAO,SAAS;AAEhC,OAAG,iBAAiB,WAAW,SAAS;AAAA,MACtC,QAAQ,gBAAgB;AAAA,MACxB,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":["handleEnd","handleNodeDragover","handleNodePointerover","handleParentDragover","handleParentPointerover","emit","on","state","insertState","state","draggedParentValues","documentController","handleNodeDragover","handleParentDragover","state","handleEnd","documentController","baseDragState","dragStateProps","nodes","emit","on","handleNodeDragover","handleParentDragover","handleEnd","handleNodePointerover","handleParentPointerover","draggedNodes","state","parent","x","scrollTimeout","node","scrollX","scrollY","className","el"]} \ No newline at end of file +{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/plugins/animations/index.ts","../src/plugins/insert/index.ts","../src/plugins/drop-or-swap/index.ts"],"sourcesContent":["import type {\n DNDPlugin,\n DragAndDrop,\n DragState,\n DragStateProps,\n Node,\n NodeData,\n NodeDragEventData,\n NodeEventData,\n NodePointerEventData,\n NodeRecord,\n NodeTargetData,\n NodesData,\n ParentConfig,\n ParentData,\n ParentEventData,\n ParentTargetData,\n ParentsData,\n PointeroverNodeEvent,\n PointeroverParentEvent,\n SetupNodeData,\n TearDownNodeData,\n BaseDragState,\n SynthDragState,\n ParentKeydownEventData,\n SynthDragStateProps,\n ParentRecord,\n EventHandlers,\n NodeFromPoint,\n ParentFromPoint,\n ParentDragEventData,\n} from \"./types\";\n\nimport {\n pd,\n sp,\n on,\n emit,\n createEmitter,\n eq,\n splitClass,\n eventCoordinates,\n} from \"./utils\";\n\nexport * from \"./types\";\nexport { animations } from \"./plugins/animations\";\nexport { insert } from \"./plugins/insert\";\nexport { dropOrSwap } from \"./plugins/drop-or-swap\";\n\n/**\n * Check to see if code is running in a browser.\n */\nexport const isBrowser = typeof window !== \"undefined\";\n\n/**\n * Parents or \"lists\" are the containers that nodes or \"draggable items\" can be\n * dragged from and into.\n *\n * @type {WeakMap>}\n */\nexport const parents: ParentsData = new WeakMap<\n HTMLElement,\n ParentData\n>();\n\n/**\n * Nodes are the draggable items and the direct descendants of the parents.\n *\n * @type {WeakMap>}\n */\nexport const nodes: NodesData = new WeakMap>();\n\n/**\n * Function to check if touch support is enabled.\n *\n * @returns {boolean}\n */\nfunction checkTouchSupport() {\n if (!isBrowser) return false;\n\n return \"ontouchstart\" in window || navigator.maxTouchPoints > 0;\n}\n\n/**\n * The base drag state.\n *\n * @type {BaseDragState}\n */\nconst baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n currentTargetValue: undefined,\n on,\n emit,\n newActiveDescendant: undefined,\n originalZIndex: undefined,\n pointerSelection: false,\n preventEnter: false,\n rootUserSelect: undefined,\n nodePointerdown: undefined,\n longPress: false,\n scrolling: false,\n longPressTimeout: undefined,\n remapJustFinished: false,\n selectedNodes: [],\n selectedParent: undefined,\n preventSynthDrag: false,\n pointerDown: undefined,\n};\n\n/**\n * The state of the drag and drop.\n *\n * @type {BaseDragState}\n */\nexport let state: BaseDragState = baseDragState;\n\n/**\n * Variable to check if the drop has occurred.\n */\nlet dropped = false;\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\n/**\n * Abort controller for the window.\n */\nlet windowController: AbortController | undefined;\n\n/**\n * Timeout for the scroll.\n */\nlet scrollTimeout: ReturnType;\n\n/**\n * Variable to check if the device is touch.\n */\nlet touchDevice: boolean = false;\n\nexport function resetState() {\n const baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n on,\n emit,\n currentTargetValue: undefined,\n originalZIndex: undefined,\n pointerId: undefined,\n preventEnter: false,\n remapJustFinished: false,\n selectedNodes: [],\n nodePointerdown: undefined,\n rootUserSelect: undefined,\n preventSynthDrag: false,\n scrolling: false,\n selectedParent: undefined,\n pointerSelection: false,\n synthScrollDirection: undefined,\n draggedNodeDisplay: undefined,\n synthDragScrolling: false,\n longPress: false,\n pointerDown: undefined,\n longPressTimeout: undefined,\n };\n\n state = { ...baseDragState } as BaseDragState;\n}\n\n/**\n * @param {DragStateProps} dragStateProps - Attributes to update state with.\n *\n * @mutation - Updates state with node values.\n *\n * @returns void\n */\nexport function setDragState(\n dragStateProps: (SynthDragStateProps & DragStateProps) | DragStateProps\n): DragState | SynthDragState {\n Object.assign(state, dragStateProps);\n\n dragStateProps.initialParent.data.emit(\"dragStarted\", state);\n\n dropped = false;\n\n state.emit(\"dragStarted\", state);\n\n return state as DragState | SynthDragState;\n}\n\n/**\n *\n */\nfunction handleRootPointerdown(_e: PointerEvent) {\n if (state.activeState) setActive(state.activeState.parent, undefined, state);\n\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = state.activeState = undefined;\n}\n\nfunction handleRootPointerup(e: PointerEvent) {\n pd(e);\n\n state.pointerDown = undefined;\n\n if (!isSynthDragState(state)) return;\n\n const config = state.currentParent.data.config;\n\n if (isSynthDragState(state)) config.handleEnd(state);\n}\n\n/**\n * Handles the keydown event on the root element.\n *\n * @param {KeyboardEvent} e - The keyboard event.\n */\nfunction handleRootKeydown(e: KeyboardEvent) {\n if (e.key === \"Escape\") {\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n if (state.activeState)\n setActive(state.activeState.parent, undefined, state);\n\n state.selectedState = state.activeState = undefined;\n }\n}\n\nfunction handleRootDrop(_e: DragEvent) {}\n\nexport function copyNodeStyle(\n sourceNode: HTMLElement,\n targetNode: HTMLElement,\n omitKeys = false\n) {\n const computedStyle = window.getComputedStyle(sourceNode);\n\n const omittedKeys = [\n \"position\",\n \"z-index\",\n \"top\",\n \"left\",\n \"x\",\n \"pointer-events\",\n \"y\",\n \"transform-origin\",\n \"filter\",\n \"-webkit-text-fill-color\",\n ];\n\n for (const key of Array.from(computedStyle)) {\n if (omitKeys === false && key && omittedKeys.includes(key)) continue;\n\n targetNode.style.setProperty(\n key,\n computedStyle.getPropertyValue(key),\n computedStyle.getPropertyPriority(key)\n );\n }\n}\n\n/**\n * If we are currently dragging, then let's prevent default on dragover to avoid\n * the default behavior of the browser on drop.\n */\nfunction handleRootDragover(e: DragEvent) {\n if (!isDragState(state)) return;\n\n pd(e);\n}\n\nfunction handleRootPointermove(e: PointerEvent) {\n if (!state.pointerDown) return;\n\n //pd(e);\n\n const config = state.pointerDown.parent.data.config;\n\n if (\n !isSynthDragState(state) &&\n (touchDevice || (!touchDevice && !config.nativeDrag))\n ) {\n if (config.longPress && !state.longPress) {\n clearTimeout(state.longPressTimeout);\n\n state.longPress = false;\n\n return;\n }\n\n const nodes = config.draggedNodes(state.pointerDown);\n\n config.dragstartClasses(state.pointerDown.node, nodes, config, true);\n\n const synthDragState = initSynthDrag(\n state.pointerDown.node,\n state.pointerDown.parent,\n e,\n state,\n nodes\n );\n\n state.rootUserSelect = window.getComputedStyle(\n document.documentElement\n ).userSelect;\n\n document.body.style.userSelect = \"none\";\n\n synthMove(e, synthDragState);\n } else if (isSynthDragState(state)) {\n synthMove(e, state);\n }\n}\n\n/**\n * Initializes the drag and drop functionality for a given parent.\n *\n * @param {DragAndDrop} dragAndDrop - The drag and drop configuration.\n *\n * @returns void\n */\nexport function dragAndDrop({\n parent,\n getValues,\n setValues,\n config = {},\n}: DragAndDrop): void {\n if (!isBrowser) return;\n\n touchDevice = checkTouchSupport();\n\n if (!documentController) {\n documentController = addEvents(document, {\n dragover: handleRootDragover,\n pointerdown: handleRootPointerdown,\n pointerup: handleRootPointerup,\n keydown: handleRootKeydown,\n drop: handleRootDrop,\n pointermove: handleRootPointermove,\n pointercancel: nodeEventData(config.handlePointercancel),\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n });\n\n const liveRegion = document.createElement(\"div\");\n\n setAttrs(liveRegion, {\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-dnd-live-region\": \"true\",\n });\n\n Object.assign(liveRegion.style, {\n position: \"absolute\",\n top: \"0px\",\n left: \"-9999px\",\n width: \"1px\",\n height: \"1px\",\n padding: \"0\",\n overflow: \"hidden\",\n clip: \"rect(0, 0, 0, 0)\",\n whiteSpace: \"nowrap\",\n border: \"0\",\n });\n\n document.body.appendChild(liveRegion);\n }\n\n if (!windowController)\n windowController = addEvents(window, {\n resize: () => {\n touchDevice = checkTouchSupport();\n },\n });\n\n tearDown(parent);\n\n const [emit, on] = createEmitter();\n\n const parentData: ParentData = {\n getValues,\n setValues,\n config: {\n dragDropEffect: config.dragDropEffect ?? \"move\",\n dragEffectAllowed: config.dragEffectAllowed ?? \"move\",\n draggedNodes,\n dragstartClasses,\n deepCopyStyles: config.deepCopyStyles ?? false,\n handleNodeKeydown,\n handleParentKeydown,\n handleDragstart,\n handleNodeDragover,\n handleParentDragover,\n handleNodeDrop,\n handlePointercancel,\n handleEnd,\n handleDragend,\n handleParentFocus,\n handleNodePointerup,\n handleNodePointerover,\n handleParentPointerover,\n handleParentScroll,\n handleNodePointerdown,\n handleNodeDragenter,\n handleNodeDragleave,\n handleParentDrop,\n multiDrag: config.multiDrag ?? false,\n nativeDrag: config.nativeDrag ?? true,\n performSort,\n performTransfer,\n root: config.root ?? document,\n setupNode,\n setupNodeRemap,\n reapplyDragClasses,\n tearDownNode,\n tearDownNodeRemap,\n remapFinished,\n threshold: {\n horizontal: 0,\n vertical: 0,\n },\n ...config,\n },\n enabledNodes: [],\n abortControllers: {},\n privateClasses: [],\n on,\n emit,\n };\n\n const nodesObserver = new MutationObserver(nodesMutated);\n\n nodesObserver.observe(parent, { childList: true });\n\n parents.set(parent, parentData);\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.setup?.();\n });\n\n setup(parent, parentData);\n\n remapNodes(parent, true);\n}\n\nexport function dragStateProps(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent | DragEvent,\n draggedNodes: Array>,\n offsetX?: number,\n offsetY?: number\n): DragStateProps {\n const { x, y } = eventCoordinates(e);\n\n const rect = node.el.getBoundingClientRect();\n\n return {\n affectedNodes: [],\n ascendingDirection: false,\n clonedDraggedEls: [],\n coordinates: {\n x,\n y,\n },\n draggedNode: {\n el: node.el,\n data: node.data,\n },\n draggedNodes,\n incomingDirection: undefined,\n initialIndex: node.data.index,\n initialParent: {\n el: parent.el,\n data: parent.data,\n },\n currentParent: {\n el: parent.el,\n data: parent.data,\n },\n longPress: parent.data.config.longPress ?? false,\n longPressTimeout: undefined,\n currentTargetValue: node.data.value,\n scrollEls: [],\n // Need to account for if the explicity offset is positive or negative\n startLeft: offsetX ? offsetX : x - rect.left,\n startTop: offsetY ? offsetY : y - rect.top,\n targetIndex: node.data.index,\n transferred: false,\n };\n}\n\nexport function performSort({\n parent,\n draggedNodes,\n targetNodes,\n}: {\n parent: ParentRecord;\n draggedNodes: Array>;\n targetNodes: Array>;\n}) {\n remapNodes(parent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const targetParentValues = parentValues(parent.el, parent.data);\n\n const originalIndex = draggedNodes[0].data.index;\n\n const enabledNodes = [...parent.data.enabledNodes];\n\n const newParentValues = [\n ...targetParentValues.filter((x) => !draggedValues.some((y) => eq(x, y))),\n ];\n newParentValues.splice(targetNodes[0].data.index, 0, ...draggedValues);\n\n if (\"draggedNode\" in state)\n state.currentTargetValue = targetNodes[0].data.value;\n\n setParentValues(parent.el, parent.data, [...newParentValues]);\n\n if (parent.data.config.onSort)\n parent.data.config.onSort({\n parent: {\n el: parent.el,\n data: parent.data,\n } as ParentRecord,\n previousValues: [...targetParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...parent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: draggedNodes,\n previousPosition: originalIndex,\n position: targetNodes[0].data.index,\n targetNodes,\n state,\n });\n}\n\n/**\n * This function sets the active node as well as removing any classes or\n * attribute set.\n *\n * @param {ParentEventData} data - The parent event data.\n * @param {NodeRecord} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction setActive(\n parent: ParentRecord,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState\n) {\n const activeDescendantClass = parent.data.config.activeDescendantClass;\n\n if (state.activeState) {\n {\n removeClass([state.activeState.node.el], activeDescendantClass);\n\n if (state.activeState.parent.el !== parent.el)\n state.activeState.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n }\n }\n\n if (!newActiveNode) {\n state.activeState?.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n\n state.activeState = undefined;\n\n return;\n }\n\n state.activeState = {\n node: newActiveNode,\n parent,\n };\n\n addNodeClass([newActiveNode.el], activeDescendantClass);\n\n state.activeState.parent.el.setAttribute(\n \"aria-activedescendant\",\n state.activeState.node.el.id\n );\n}\n\n/**\n * This function deselects the nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {Array>} nodes - The nodes to deselect.\n * @param {ParentRecord} parent - The parent record.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction deselect(\n nodes: Array>,\n parent: ParentRecord,\n state: BaseDragState\n) {\n const selectedClass = parent.data.config.selectedClass;\n\n if (!state.selectedState) return;\n\n const iterativeNodes = Array.from(nodes);\n\n removeClass(\n nodes.map((x) => x.el),\n selectedClass\n );\n\n for (const node of iterativeNodes) {\n node.el.setAttribute(\"aria-selected\", \"false\");\n\n const index = state.selectedState.nodes.findIndex((x) => x.el === node.el);\n\n if (index === -1) continue;\n\n state.selectedState.nodes.splice(index, 1);\n }\n\n clearLiveRegion(parent);\n}\n\n/**\n * This function sets the selected nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {ParentRecord} parent - The parent record.\n * @param {Array>} selectedNodes - The nodes to select.\n * @param {NodeRecord | undefined} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n * @param {boolean} pointerdown - Whether the pointerdown event was triggered.\n */\nfunction setSelected(\n parent: ParentRecord,\n selectedNodes: Array>,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState,\n pointerdown = false\n) {\n state.pointerSelection = pointerdown;\n\n for (const node of selectedNodes) {\n node.el.setAttribute(\"aria-selected\", \"true\");\n\n addNodeClass([node.el], parent.data.config.selectedClass, true);\n }\n\n state.selectedState = {\n nodes: selectedNodes,\n parent,\n };\n\n const selectedItems = selectedNodes.map((x) =>\n x.el.getAttribute(\"aria-label\")\n );\n\n if (selectedItems.length === 0) {\n state.selectedState = undefined;\n\n clearLiveRegion(parent);\n\n return;\n }\n\n setActive(parent, newActiveNode, state);\n\n updateLiveRegion(\n parent,\n `${selectedItems.join(\n \", \"\n )} ready for dragging. Use arrow keys to navigate. Press enter to drop ${selectedItems.join(\n \", \"\n )}.`\n );\n}\n\nfunction updateLiveRegion(parent: ParentRecord, message: string) {\n const liveRegion = document.querySelector('[data-dnd-live-region=\"true\"]');\n\n if (!liveRegion) return;\n\n liveRegion.id = parent.el.id + \"-live-region\";\n\n liveRegion.textContent = message;\n}\n\nfunction clearLiveRegion(parent: ParentRecord) {\n const liveRegion = document.getElementById(parent.el.id + \"-live-region\");\n\n if (!liveRegion) return;\n\n liveRegion.textContent = \"\";\n}\n\nexport function handleParentFocus(\n data: ParentEventData,\n state: BaseDragState | DragState | SynthDragState\n) {\n const firstEnabledNode = data.targetData.parent.data.enabledNodes[0];\n\n if (!firstEnabledNode) return;\n\n if (\n state.selectedState &&\n state.selectedState.parent.el !== data.targetData.parent.el\n ) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n } else if (!state.selectedState) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n }\n}\n\n/**\n * Perform the transfer of the nodes.\n *\n * @param data - The transfer data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function performTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n initialIndex,\n targetNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n initialIndex: number;\n state: BaseDragState | DragState | SynthDragState;\n targetNodes: Array>;\n}) {\n remapNodes(initialParent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const currentParentValues = [\n ...parentValues(currentParent.el, currentParent.data).filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n const targetParentValues = parentValues(targetParent.el, targetParent.data);\n\n const reset =\n initialParent.el === targetParent.el &&\n targetParent.data.config.sortable === false;\n\n let targetIndex: number;\n\n if (targetNodes.length) {\n if (reset) {\n targetIndex = initialIndex;\n } else if (targetParent.data.config.sortable === false) {\n targetIndex = targetParent.data.enabledNodes.length;\n } else {\n targetIndex = targetNodes[0].data.index;\n }\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n } else {\n targetIndex = reset ? initialIndex : targetParent.data.enabledNodes.length;\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n }\n\n setParentValues(currentParent.el, currentParent.data, currentParentValues);\n\n setParentValues(targetParent.el, targetParent.data, targetParentValues);\n\n if (targetParent.data.config.onTransfer) {\n targetParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes,\n });\n }\n\n if (currentParent.data.config.onTransfer) {\n currentParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes: targetNodes ? targetNodes : [],\n });\n }\n}\n\n/**\n * Get the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns The values of the parent.\n */\nexport function parentValues(\n parent: HTMLElement,\n parentData: ParentData\n): Array {\n return [...parentData.getValues(parent)];\n}\n\n/**\n * Set the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n * @param values - The values to set.\n *\n * @returns void\n */\nexport function setParentValues(\n parent: HTMLElement,\n parentData: ParentData,\n values: Array\n): void {\n parentData.setValues(values, parent);\n}\n\n/**\n * Get the values of the dragged nodes.\n *\n * @param state - The drag state.\n *\n * @returns The values of the dragged nodes.\n */\nexport function dragValues(state: DragState): Array {\n return [...state.draggedNodes.map((x) => x.data.value)];\n}\n\n/**\n * Utility function to update parent config.\n *\n * @param parent - The parent element.\n * @param config - The config to update.\n *\n * @returns void\n */\nexport function updateConfig(\n parent: HTMLElement,\n config: Partial>\n) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parents.set(parent, {\n ...parentData,\n config: { ...parentData.config, ...config },\n });\n\n dragAndDrop({\n parent,\n getValues: parentData.getValues,\n setValues: parentData.setValues,\n config,\n });\n}\n\n/**\n * Handle the parent drop event.\n *\n * @param data - The parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDrop(\n data: ParentEventData,\n state: DragState\n) {\n sp(data.e);\n\n dropped = true;\n\n const handleEnd = state.initialParent.data.config.handleEnd;\n\n handleEnd(state);\n}\n\n/**\n * Tear down the parent.\n *\n * @param parent - The parent element.\n *\n * @returns void\n */\nexport function tearDown(parent: HTMLElement) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n if (parentData.abortControllers.mainParent)\n parentData.abortControllers.mainParent.abort();\n}\n\n/**\n * Check if the state is a drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a drag state.\n */\nexport function isDragState(\n state: BaseDragState\n): state is DragState | SynthDragState {\n return \"draggedNode\" in state && !!state.draggedNode;\n}\n\n/**\n * Check if the state is a synth drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a synth drag state.\n */\nexport function isSynthDragState(\n state: BaseDragState\n): state is SynthDragState {\n return \"synthDragging\" in state && !!state.synthDragging;\n}\n\n/**\n * Setup the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction setup(parent: HTMLElement, parentData: ParentData): void {\n parentData.abortControllers.mainParent = addEvents(parent, {\n keydown: parentEventData(parentData.config.handleParentKeydown),\n dragover: parentEventData(parentData.config.handleParentDragover),\n handleParentPointerover: parentData.config.handleParentPointerover,\n scroll: parentEventData(parentData.config.handleParentScroll),\n drop: parentEventData(parentData.config.handleParentDrop),\n hasNestedParent: (e: CustomEvent) => {\n const parent = parents.get(e.target as HTMLElement);\n\n if (!parent) return;\n\n parent.nestedParent = e.detail.parent;\n },\n focus: parentEventData(parentData.config.handleParentFocus),\n });\n\n if (\n parentData.config.externalDragHandle &&\n parentData.config.externalDragHandle.el &&\n parentData.config.externalDragHandle.callback\n ) {\n parentData.abortControllers.externalDragHandle = addEvents(\n parentData.config.externalDragHandle.el,\n {\n pointerdown: (_e: PointerEvent) => {\n if (\n !parentData.config.externalDragHandle ||\n !parentData.config.externalDragHandle.callback\n )\n return;\n\n const draggableItem = parentData.config.externalDragHandle.callback();\n\n if (!isNode(draggableItem)) {\n console.warn(\n \"No draggable item found from external drag handle callback\"\n );\n\n return;\n }\n\n const nodeData = nodes.get(draggableItem);\n\n if (!nodeData) return;\n\n const parentNode = draggableItem.parentNode;\n\n if (!(parentNode instanceof HTMLElement)) return;\n\n const parent = parents.get(parentNode);\n\n if (!parent) return;\n\n state.pointerDown = {\n parent: {\n el: parentNode,\n data: parent,\n },\n node: {\n el: draggableItem,\n data: nodeData,\n },\n };\n\n draggableItem.draggable = true;\n },\n }\n );\n }\n\n if (parent.id)\n setAttrs(parent, {\n role: \"listbox\",\n tabindex: \"0\",\n \"aria-multiselectable\": parentData.config.multiDrag ? \"true\" : \"false\",\n \"aria-activedescendant\": \"\",\n \"aria-describedby\": parent.id + \"-live-region\",\n });\n}\n\n/**\n * Set the attributes of the element.\n *\n * @param el - The element.\n * @param attrs - The attributes to set.\n *\n * @returns void\n */\nexport function setAttrs(el: HTMLElement, attrs: Record) {\n for (const key in attrs) el.setAttribute(key, attrs[key]);\n}\n\n/**\n * Setup the node.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNode(data: SetupNodeData) {\n const config = data.parent.data.config;\n\n data.node.data.abortControllers.mainNode = addEvents(data.node.el, {\n keydown: nodeEventData(config.handleNodeKeydown),\n dragstart: nodeEventData(config.handleDragstart),\n dragover: nodeEventData(config.handleNodeDragover),\n dragenter: nodeEventData(config.handleNodeDragenter),\n dragleave: nodeEventData(config.handleNodeDragleave),\n dragend: nodeEventData(config.handleDragend),\n drop: nodeEventData(config.handleNodeDrop),\n pointerup: nodeEventData(config.handleNodePointerup),\n pointercancel: nodeEventData(config.handlePointercancel),\n\n pointerdown: nodeEventData(config.handleNodePointerdown),\n handleNodePointerover: config.handleNodePointerover,\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n contextmenu: (e: Event) => {\n if (touchDevice) pd(e);\n },\n });\n\n data.node.el.setAttribute(\"role\", \"option\");\n\n data.node.el.setAttribute(\"aria-selected\", \"false\");\n\n config.reapplyDragClasses(data.node.el, data.parent.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNode?.(data);\n });\n}\n\n/**\n * Setup the node remap.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNodeRemap(data: SetupNodeData) {\n nodes.set(data.node.el, data.node.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNodeRemap?.(data);\n });\n}\n\n/**\n * Reapply the drag classes to the node.\n *\n * @param node - The node.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction reapplyDragClasses(node: Node, parentData: ParentData) {\n if (!isDragState(state)) return;\n\n const dropZoneClass = isSynthDragState(state)\n ? parentData.config.synthDropZoneClass\n : parentData.config.dropZoneClass;\n\n if (state.draggedNode.el !== node) return;\n\n addNodeClass([node], dropZoneClass, true);\n}\n\n/**\n * Tear down the node remap.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNodeRemap(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNodeRemap?.(data);\n });\n}\n\n/**\n * Tear down the node.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNode(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNode?.(data);\n });\n\n data.node.el.draggable = false;\n\n if (data.node.data?.abortControllers?.mainNode)\n data.node.data?.abortControllers?.mainNode.abort();\n}\n\n/**\n * Called when the nodes of a given parent element are mutated.\n *\n * @param mutationList - The list of mutations.\n *\n * @returns void\n *\n * @internal\n */\nfunction nodesMutated(mutationList: MutationRecord[]) {\n // TODO: This could be better, but using it as a way to ignore comments and text\n if (\n mutationList.length === 1 &&\n mutationList[0].addedNodes.length === 1 &&\n !(mutationList[0].addedNodes[0] instanceof HTMLElement)\n )\n return;\n\n const parentEl = mutationList[0].target;\n\n if (!(parentEl instanceof HTMLElement)) return;\n\n const allSelectedAndActiveNodes = document.querySelectorAll(\n `[aria-selected=\"true\"]`\n );\n\n const parentData = parents.get(parentEl);\n\n if (!parentData) return;\n\n for (let x = 0; x < allSelectedAndActiveNodes.length; x++) {\n const node = allSelectedAndActiveNodes[x];\n\n node.setAttribute(\"aria-selected\", \"false\");\n\n removeClass([node], parentData.config.selectedClass);\n }\n\n remapNodes(parentEl);\n}\n\n/**\n * Remaps the data of the parent element's children.\n *\n * @param parent - The parent element.\n *\n * @returns void\n *\n * @internal\n */\nexport function remapNodes(parent: HTMLElement, force?: boolean) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parentData.privateClasses = Array.from(parent.classList);\n\n const enabledNodes: Array = [];\n\n const config = parentData.config;\n\n for (let x = 0; x < parent.children.length; x++) {\n const node = parent.children[x];\n\n if (!isNode(node) || node.id === \"dnd-dragged-node-clone\") continue;\n\n const nodeData = nodes.get(node);\n\n // Only tear down the node if we have explicitly called dragAndDrop\n if (force || !nodeData)\n config.tearDownNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n if (config.disabled) continue;\n\n if (!config.draggable || (config.draggable && config.draggable(node))) {\n enabledNodes.push(node);\n }\n }\n\n if (\n enabledNodes.length !== parentData.getValues(parent).length &&\n !config.disabled\n ) {\n console.warn(\n \"The number of draggable items defined in the parent element does not match the number of values. This may cause unexpected behavior.\"\n );\n\n return;\n }\n\n const values = parentData.getValues(parent);\n\n const enabledNodeRecords: Array> = [];\n\n for (let x = 0; x < enabledNodes.length; x++) {\n const node = enabledNodes[x];\n\n const prevNodeData = nodes.get(node);\n\n if (config.draggableValue && !config.draggableValue(values[x])) continue;\n\n const nodeData = Object.assign(\n prevNodeData ?? {\n privateClasses: [],\n abortControllers: {},\n },\n {\n value: values[x],\n index: x,\n }\n );\n\n if (\n !isDragState(state) &&\n state.newActiveDescendant &&\n eq(state.newActiveDescendant.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n !isDragState(state) &&\n state.activeState &&\n eq(state.activeState.node.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n isDragState(state) &&\n eq(state.draggedNode.data.value, nodeData.value)\n ) {\n state.draggedNode.data = nodeData;\n\n state.draggedNode.el = node;\n\n const draggedNode = state.draggedNodes.find(\n (x) => x.data.value === nodeData.value\n );\n\n if (draggedNode) draggedNode.el = node;\n }\n\n enabledNodeRecords.push({\n el: node,\n data: nodeData,\n });\n\n if (force || !prevNodeData)\n config.setupNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n setupNodeRemap({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n }\n\n parents.set(parent, { ...parentData, enabledNodes: enabledNodeRecords });\n\n config.remapFinished(parentData);\n\n parentData.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.remapFinished?.();\n });\n}\n\n/**\n * Set the remap just finished flag.\n *\n * @returns void\n */\nexport function remapFinished() {\n state.remapJustFinished = true;\n\n if (\"draggedNode\" in state) state.affectedNodes = [];\n}\n\n/**\n * Validate the drag start.\n *\n * @param data - The node event data.\n *\n * @returns Whether the drag start is valid.\n */\nexport function validateDragstart(data: NodeEventData): boolean {\n return !!data.targetData.parent.data.config.nativeDrag;\n}\n\n/**\n * Get the dragged nodes.\n *\n * @param pointerDown - The pointer down data.\n *\n * @returns The dragged nodes.\n */\nfunction draggedNodes(pointerDown: {\n parent: ParentRecord;\n node: NodeRecord;\n}): Array> {\n if (!pointerDown.parent.data.config.multiDrag) {\n return [pointerDown.node];\n } else if (state.selectedState) {\n return [\n pointerDown.node,\n ...(state.selectedState?.nodes.filter(\n (x) => x.el !== pointerDown.node.el\n ) as Array>),\n ];\n }\n\n return [];\n}\n\n/**\n * Handle the parent scroll.\n *\n * @param data - The parent event data.\n *\n * @returns void\n */\nfunction handleParentScroll(_data: ParentEventData) {\n if (!isDragState(state)) return;\n\n state.emit(\"scrollStarted\", state);\n\n if (isSynthDragState(state)) return;\n\n state.preventEnter = true;\n\n if (scrollTimeout) clearTimeout(scrollTimeout);\n\n scrollTimeout = setTimeout(() => {\n state.preventEnter = false;\n\n state.emit(\"scrollEnded\", state);\n }, 100);\n}\n\n/**\n * Responsible for assigning dragstart classes to the dragged nodes.\n */\nexport function handleDragstart(\n data: NodeDragEventData,\n _state: BaseDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (\n !config.nativeDrag ||\n !validateDragstart(data) ||\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config,\n })\n ) {\n pd(data.e);\n\n return;\n }\n\n const nodes = config.draggedNodes({\n parent: data.targetData.parent,\n node: data.targetData.node,\n });\n\n config.dragstartClasses(data.targetData.node, nodes, config);\n\n const dragState = initDrag(data, nodes);\n\n if (config.onDragstart)\n config.onDragstart({\n parent: data.targetData.parent,\n values: parentValues(\n data.targetData.parent.el,\n data.targetData.parent.data\n ),\n draggedNode: dragState.draggedNode,\n draggedNodes: dragState.draggedNodes,\n position: dragState.initialIndex,\n state: dragState,\n });\n}\n\nexport function handleNodePointerdown(\n data: NodePointerEventData,\n state: BaseDragState\n) {\n sp(data.e);\n\n if (\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config: data.targetData.parent.data.config,\n })\n )\n return;\n\n state.pointerDown = {\n parent: data.targetData.parent,\n node: data.targetData.node,\n };\n\n data.targetData.node.el.draggable = true;\n\n handleLongPress(data, state, data.targetData.node);\n\n const parentData = data.targetData.parent.data;\n\n let selectedNodes = [data.targetData.node];\n\n const commandKey = data.e.ctrlKey || data.e.metaKey;\n const shiftKey = data.e.shiftKey;\n\n const targetNode = data.targetData.node;\n\n if (commandKey && parentData.config.multiDrag) {\n if (state.selectedState) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === targetNode.el\n );\n\n if (idx === -1) {\n selectedNodes = [...state.selectedState.nodes, targetNode];\n } else {\n selectedNodes = state.selectedState.nodes.filter(\n (x) => x.el !== targetNode.el\n );\n }\n } else {\n selectedNodes = [targetNode];\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (shiftKey && parentData.config.multiDrag) {\n const nodes = data.targetData.parent.data.enabledNodes;\n\n if (state.selectedState && state.activeState) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = undefined;\n\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n } else {\n const [minIndex, maxIndex] =\n state.activeState.node.data.index < data.targetData.node.data.index\n ? [\n state.activeState.node.data.index,\n data.targetData.node.data.index,\n ]\n : [\n data.targetData.node.data.index,\n state.activeState.node.data.index,\n ];\n\n selectedNodes = nodes.slice(minIndex, maxIndex + 1);\n }\n } else {\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (state.selectedState?.nodes?.length) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === data.targetData.node.el\n );\n\n if (idx === -1) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n } else if (parentData.config.multiDrag && touchDevice) {\n selectedNodes.push(...state.selectedState.nodes);\n } else {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n }\n } else {\n setSelected(\n data.targetData.parent,\n [data.targetData.node],\n data.targetData.node,\n state,\n true\n );\n }\n}\n\n/**\n * Add dragstart classes to the nodes.\n *\n * @param node - The node.\n * @param nodes - The nodes.\n * @param config - The parent config.\n * @param isSynth - Whether the drag is synthetic.\n *\n * @returns void\n */\nexport function dragstartClasses(\n _node: NodeRecord,\n nodes: Array>,\n config: ParentConfig,\n isSynth = false\n) {\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n setTimeout(() => {\n removeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDragPlaceholderClass : config.dragPlaceholderClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDropZoneClass : config.dropZoneClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.activeDescendantClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.selectedClass\n );\n });\n}\n\n/**\n * Initialize the drag state.\n *\n * @param data - The node drag event data.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The drag state.\n */\nexport function initDrag(\n data: NodeDragEventData,\n draggedNodes: Array>\n): DragState {\n sp(data.e);\n\n const dragState = setDragState(\n dragStateProps(\n data.targetData.node,\n data.targetData.parent,\n data.e,\n draggedNodes\n )\n );\n\n if (data.e.dataTransfer) {\n const config = data.targetData.parent.data.config;\n\n data.e.dataTransfer.dropEffect = config.dragDropEffect;\n\n data.e.dataTransfer.effectAllowed = config.dragEffectAllowed;\n\n let dragImage: HTMLElement | undefined;\n\n if (config.dragImage) {\n dragImage = config.dragImage(data, draggedNodes);\n } else {\n if (!config.multiDrag) {\n data.e.dataTransfer.setDragImage(\n data.targetData.node.el,\n data.e.offsetX,\n data.e.offsetY\n );\n\n const originalZIndex = data.targetData.node.el.style.zIndex;\n\n dragState.originalZIndex = originalZIndex;\n\n data.targetData.node.el.style.zIndex = \"9999\";\n\n return dragState;\n } else {\n const wrapper = document.createElement(\"div\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n clonedNode.style.pointerEvents = \"none\";\n\n clonedNode.id = node.el.id + \"-clone\";\n\n wrapper.append(clonedNode);\n }\n\n const { width } = draggedNodes[0].el.getBoundingClientRect();\n\n Object.assign(wrapper.style, {\n display: \"flex\",\n flexDirection: \"column\",\n width: `${width}px`,\n position: \"absolute\",\n pointerEvents: \"none\",\n zIndex: \"9999\",\n left: \"-9999px\",\n });\n\n dragImage = wrapper;\n }\n\n document.body.appendChild(dragImage);\n }\n\n data.e.dataTransfer.setDragImage(dragImage, data.e.offsetX, data.e.offsetY);\n\n setTimeout(() => {\n dragImage?.remove();\n });\n }\n\n return dragState;\n}\n\nexport function validateDragHandle({\n x,\n y,\n node,\n config,\n}: {\n x: number;\n y: number;\n node: NodeRecord;\n config: ParentConfig;\n}): boolean {\n if (config.externalDragHandle) return false;\n\n if (!config.dragHandle) return true;\n\n const dragHandles = node.el.querySelectorAll(config.dragHandle);\n\n if (!dragHandles) return false;\n\n const elFromPoint = config.root.elementFromPoint(x, y);\n\n if (!elFromPoint) return false;\n\n for (const handle of Array.from(dragHandles))\n if (elFromPoint === handle || handle.contains(elFromPoint)) return true;\n\n return false;\n}\n\nexport function handleClickNode(_data: NodeEventData) {}\n\nexport function handleClickParent(_data: ParentEventData) {}\n\nexport function handleNodeKeydown(_data: NodeEventData) {}\n\nexport function handleParentKeydown(\n data: ParentKeydownEventData,\n state: BaseDragState\n) {\n const activeDescendant = state.activeState?.node;\n\n if (!activeDescendant) return;\n\n const parentData = data.targetData.parent.data;\n\n const enabledNodes = parentData.enabledNodes;\n\n if (!(data.e.target instanceof HTMLElement)) return;\n const index = enabledNodes.findIndex((x) => x.el === activeDescendant.el);\n\n if (index === -1) return;\n\n if (\n [\"ArrowDown\", \"ArrowUp\", \"ArrowRight\", \"ArrowLeft\"].includes(data.e.key)\n ) {\n pd(data.e);\n\n const nextIndex =\n data.e.key === \"ArrowDown\" || data.e.key === \"ArrowRight\"\n ? index + 1\n : index - 1;\n\n if (nextIndex < 0 || nextIndex >= enabledNodes.length) return;\n\n const nextNode = enabledNodes[nextIndex];\n\n setActive(data.targetData.parent, nextNode, state);\n } else if (data.e.key === \" \") {\n pd(data.e);\n\n state.selectedState && state.selectedState.nodes.includes(activeDescendant)\n ? setSelected(\n data.targetData.parent,\n state.selectedState.nodes.filter((x) => x.el !== activeDescendant.el),\n activeDescendant,\n state\n )\n : setSelected(\n data.targetData.parent,\n [activeDescendant],\n activeDescendant,\n state\n );\n } else if (data.e.key === \"Enter\" && state.selectedState) {\n if (\n state.selectedState.parent.el === data.targetData.parent.el &&\n state.activeState\n ) {\n if (state.selectedState.nodes[0].el === state.activeState.node.el) {\n updateLiveRegion(data.targetData.parent, \"Cannot drop item on itself\");\n\n return;\n }\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n parentData.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.selectedState.nodes,\n targetNodes: [state.activeState.node],\n });\n\n deselect([], data.targetData.parent, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n } else if (\n state.activeState &&\n state.selectedState.parent.el !== data.targetData.parent.el &&\n validateTransfer({\n currentParent: data.targetData.parent,\n targetParent: state.selectedState.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n state,\n })\n ) {\n parentData.config.performTransfer({\n currentParent: state.selectedState.parent,\n targetParent: data.targetData.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n initialIndex: state.selectedState.nodes[0].data.index,\n state,\n targetNodes: [state.activeState.node],\n });\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n setSelected(data.targetData.parent, [], undefined, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n }\n }\n}\n\n/**\n * Prevent the sort on scroll.\n *\n * @returns A function to prevent the sort on scroll.\n */\nexport function preventSortOnScroll() {\n let scrollTimeout: ReturnType;\n\n return () => {\n clearTimeout(scrollTimeout);\n\n if (state) state.preventEnter = true;\n\n scrollTimeout = setTimeout(() => {\n if (state) state.preventEnter = false;\n }, 100);\n };\n}\n\n/**\n * Handle the node pointer over.\n *\n * @param e - The node pointer over event.\n *\n * @returns void\n */\nexport function handleNodePointerover(e: PointeroverNodeEvent) {\n if (e.detail.targetData.parent.el === e.detail.state.currentParent.el)\n sort(e.detail, e.detail.state);\n else transfer(e.detail, e.detail.state);\n}\n\n/**\n * Handle the node drop.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDrop(\n data: NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n sp(data.e);\n\n dropped = true;\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleDragend(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the pointer cancel.\n *\n * @param data - The node event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handlePointercancel(\n data: NodeEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isSynthDragState(state)) return;\n pd(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n const config = parents.get(state.initialParent.el)?.config;\n\n if (config?.onDragend) {\n config.onDragend({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n }\n\n config?.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleEnd(state: DragState | SynthDragState) {\n if (state.draggedNode) state.draggedNode.el.draggable = false;\n\n document.body.style.userSelect = state.rootUserSelect || \"\";\n\n if (isSynthDragState(state)) {\n document.documentElement.style.overscrollBehavior =\n state.rootOverScrollBehavior || \"\";\n\n document.documentElement.style.touchAction = state.rootTouchAction || \"\";\n }\n\n if (isSynthDragState(state)) cancelSynthScroll(state);\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n const config = parents.get(state.initialParent.el)?.config;\n\n const isSynth = isSynthDragState(state);\n\n const dropZoneClass = isSynth\n ? config?.synthDropZoneClass\n : config?.dropZoneClass;\n\n if (state.originalZIndex !== undefined)\n state.draggedNode.el.style.zIndex = state.originalZIndex;\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n dropZoneClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n state.initialParent.data?.config?.longPressClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n isSynth\n ? state.initialParent.data.config.synthDragPlaceholderClass\n : state.initialParent.data?.config?.dragPlaceholderClass\n );\n\n if (isSynth) state.clonedDraggedNode.remove();\n\n deselect(state.draggedNodes, state.currentParent, state);\n\n setActive(state.currentParent, undefined, state);\n\n resetState();\n\n state.selectedState = undefined;\n\n config?.onDragend?.({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n\n state.emit(\"dragEnded\", state);\n}\n\n/**\n * Handle the node pointer up.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodePointerup(\n data: NodePointerEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n sp(data.e);\n\n state.pointerDown = undefined;\n if (!state.pointerSelection && state.selectedState)\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n\n const config = data.targetData.parent.data.config;\n\n state.pointerSelection = false;\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n removeClass(\n data.targetData.parent.data.enabledNodes.map((x) => x.el),\n config.longPressClass\n );\n\n if (!isDragState(state)) return;\n\n config.handleEnd(state as DragState | SynthDragState);\n}\n\n/**\n * Initialize the synth drag.\n *\n * @param node - The node.\n * @param parent - The parent.\n * @param e - The pointer event.\n * @param _state - The drag state.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The synth drag state.\n */\nfunction initSynthDrag(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent,\n _state: BaseDragState,\n draggedNodes: Array>\n): SynthDragState {\n const config = parent.data.config;\n\n let dragImage: HTMLElement | undefined;\n\n let display = node.el.style.display;\n\n let result = undefined;\n\n if (config.synthDragImage) {\n result = config.synthDragImage(node, parent, e, draggedNodes);\n\n dragImage = result.dragImage;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n zIndex: 9999,\n pointerEvents: \"none\",\n margin: 0,\n overflow: \"hidden\",\n display: \"none\",\n });\n } else {\n if (!config.multiDrag || draggedNodes.length === 1) {\n console.log(\"boom\");\n dragImage = node.el.cloneNode(true) as HTMLElement;\n\n copyNodeStyle(node.el, dragImage);\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n height: node.el.getBoundingClientRect().height + \"px\",\n width: node.el.getBoundingClientRect().width + \"px\",\n overflow: \"hidden\",\n margin: 0,\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n } else {\n const wrapper = document.createElement(\"div\");\n console.log(\"getting here\");\n\n wrapper.setAttribute(\"popover\", \"manual\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n copyNodeStyle(node.el, clonedNode);\n\n clonedNode.style.pointerEvents = \"none\";\n\n wrapper.append(clonedNode);\n }\n\n display = wrapper.style.display;\n\n wrapper.id = \"dnd-dragged-node-clone\";\n\n dragImage = wrapper;\n\n Object.assign(dragImage.style, {\n display: \"flex\",\n flexDirection: \"column\",\n position: \"absolute\",\n overflow: \"hidden\",\n margin: 0,\n padding: 0,\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n }\n }\n\n dragImage.style.position = \"absolute\";\n\n parent.el.appendChild(dragImage);\n\n dragImage.showPopover();\n\n const synthDragStateProps = {\n clonedDraggedEls: [],\n clonedDraggedNode: dragImage,\n draggedNodeDisplay: display,\n synthDragScrolling: false,\n synthDragging: true,\n rootScrollWidth: document.scrollingElement?.scrollWidth,\n rootScrollHeight: document.scrollingElement?.scrollHeight,\n rootOverScrollBehavior: document.documentElement.style.overscrollBehavior,\n rootTouchAction: document.documentElement.style.touchAction,\n };\n\n document.documentElement.style.overscrollBehavior = \"none\";\n\n document.documentElement.style.touchAction = \"none\";\n\n const synthDragState = setDragState({\n ...dragStateProps(\n node,\n parent,\n e,\n draggedNodes,\n result?.offsetX,\n result?.offsetY\n ),\n ...synthDragStateProps,\n }) as SynthDragState;\n\n synthDragState.clonedDraggedNode.style.display =\n synthDragState.draggedNodeDisplay || \"\";\n\n return synthDragState;\n}\n\n/**\n * Handle the long press.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n * @param node - The node.\n *\n * @returns void\n */\nexport function handleLongPress(\n data: NodePointerEventData,\n state: BaseDragState,\n node: NodeRecord\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.longPress) return;\n\n state.longPressTimeout = setTimeout(() => {\n if (!state) return;\n\n state.longPress = true;\n\n if (config.longPressClass && data.e.cancelable)\n addNodeClass([node.el], config.longPressClass);\n\n pd(data.e);\n }, config.longPressDuration || 200);\n}\n\nfunction pointermoveClasses(\n state: SynthDragState,\n config: ParentConfig\n) {\n if (config.longPressClass)\n removeClass(\n state.draggedNodes.map((x) => x.el),\n config?.longPressClass\n );\n}\n\nfunction cancelSynthScroll(\n state: SynthDragState,\n cancelX = true,\n cancelY = true\n) {\n if (cancelX && state.animationFrameIdX !== undefined) {\n cancelAnimationFrame(state.animationFrameIdX);\n\n state.animationFrameIdX = undefined;\n }\n\n if (cancelY && state.animationFrameIdY !== undefined) {\n cancelAnimationFrame(state.animationFrameIdY);\n\n state.animationFrameIdY = undefined;\n }\n\n if (!state.animationFrameIdX && !state.animationFrameIdY) {\n state.preventEnter = false;\n }\n}\n\nfunction moveNode(\n e: PointerEvent,\n state: SynthDragState,\n scrollX = 0,\n scrollY = 0\n) {\n const { x, y } = eventCoordinates(e);\n\n state.coordinates.y = y;\n state.coordinates.x = x;\n\n const startLeft = state.startLeft ?? 0;\n const startTop = state.startTop ?? 0;\n\n // Calculate the translation values\n const translateX = x - startLeft + window.scrollX;\n const translateY = y - startTop + window.scrollY;\n\n // Apply the transform using translate\n state.clonedDraggedNode.style.transform = `translate(${\n translateX + scrollX\n }px, ${translateY + scrollY}px)`;\n\n if (e.cancelable) pd(e);\n\n pointermoveClasses(state, state.initialParent.data.config);\n}\n\n/**\n * Handle the synth move.\n *\n * @param e - The pointer event.\n * @param state - The synth drag state.\n *\n * @returns void\n */\nexport function synthMove(e: PointerEvent, state: SynthDragState) {\n moveNode(e, state);\n\n const coordinates = eventCoordinates(e);\n\n handleSynthScroll(coordinates, e, state);\n\n const elFromPoint = getElFromPoint(coordinates);\n\n if (!elFromPoint) {\n document.dispatchEvent(\n new CustomEvent(\"handleRootPointerover\", {\n detail: {\n e,\n state,\n },\n })\n );\n\n return;\n }\n const pointerMoveEventData = {\n e,\n targetData: elFromPoint,\n state,\n };\n\n if (\"node\" in elFromPoint) {\n elFromPoint.node.el.dispatchEvent(\n new CustomEvent(\"handleNodePointerover\", {\n detail: pointerMoveEventData,\n })\n );\n } else {\n elFromPoint.parent.el.dispatchEvent(\n new CustomEvent(\"handleParentPointerover\", {\n detail: pointerMoveEventData,\n })\n );\n }\n}\n\n/**\n * Handle the node drag over.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n const { x, y } = eventCoordinates(data.e);\n\n state.coordinates.y = y;\n\n state.coordinates.x = x;\n\n pd(data.e);\n\n sp(data.e);\n\n data.targetData.parent.el === state.currentParent?.el\n ? sort(data, state)\n : transfer(data, state);\n}\n\n/**\n * Handle the parent drag over.\n *\n * @param data - The parent drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n Object.assign(eventCoordinates(data.e));\n\n transfer(data, state);\n}\n\n/**\n * Handle the parent pointer over.\n *\n * @param e - The parent pointer over event.\n *\n * @returns void\n */\nexport function handleParentPointerover(e: PointeroverParentEvent) {\n if (e.detail.targetData.parent.el !== e.detail.state.currentParent.el)\n transfer(e.detail, e.detail.state);\n}\n\n/**\n * Validate the transfer.\n *\n * @param data - The transfer data.\n *\n * @returns Whether the transfer is valid.\n */\nexport function validateTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n state: BaseDragState;\n}) {\n if (targetParent.el === currentParent.el) return false;\n\n const targetConfig = targetParent.data.config;\n\n if (draggedNodes[0].el.contains(targetParent.el)) return false;\n\n if (targetConfig.dropZone === false) return false;\n\n const initialParentConfig = initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n targetParent,\n initialParent,\n currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Handle the node drag enter.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragenter(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Handle the node drag leave.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragleave(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Validate the sort.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n * @param x - The x coordinate.\n * @param y - The y coordinate.\n *\n * @returns Whether the sort is valid.\n */\nexport function validateSort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState,\n x: number,\n y: number\n): boolean {\n if (\n state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.targetData.node.data.value)\n ) {\n return false;\n }\n\n if (state.remapJustFinished) {\n state.remapJustFinished = false;\n\n if (\n data.targetData.node.data.value === state.currentTargetValue ||\n state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)\n ) {\n state.currentTargetValue = data.targetData.node.data.value;\n }\n\n return false;\n }\n\n if (state.preventEnter) return false;\n\n if (state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)) {\n state.currentTargetValue = undefined;\n\n return false;\n }\n\n if (data.targetData.node.data.value === state.currentTargetValue)\n return false;\n\n if (\n data.targetData.parent.el !== state.currentParent?.el ||\n data.targetData.parent.data.config.sortable === false\n )\n return false;\n\n if (data.targetData.node.el.contains(state.draggedNodes[0].el)) return false;\n\n const targetRect = data.targetData.node.el.getBoundingClientRect();\n\n const dragRect = state.draggedNode.el.getBoundingClientRect();\n\n const yDiff = targetRect.y - dragRect.y;\n\n const xDiff = targetRect.x - dragRect.x;\n\n let incomingDirection: \"above\" | \"below\" | \"left\" | \"right\";\n\n if (Math.abs(yDiff) > Math.abs(xDiff)) {\n incomingDirection = yDiff > 0 ? \"above\" : \"below\";\n } else {\n incomingDirection = xDiff > 0 ? \"left\" : \"right\";\n }\n\n const threshold = state.currentParent.data.config.threshold;\n\n switch (incomingDirection) {\n case \"left\":\n if (x > targetRect.x + targetRect.width * threshold.horizontal) {\n state.incomingDirection = \"left\";\n\n return true;\n }\n break;\n\n case \"right\":\n if (x < targetRect.x + targetRect.width * (1 - threshold.horizontal)) {\n state.incomingDirection = \"right\";\n\n return true;\n }\n break;\n\n case \"above\":\n if (y > targetRect.y + targetRect.height * threshold.vertical) {\n state.incomingDirection = \"above\";\n\n return true;\n }\n break;\n\n case \"below\":\n if (y < targetRect.y + targetRect.height * (1 - threshold.vertical)) {\n state.incomingDirection = \"below\";\n\n return true;\n }\n break;\n\n default:\n break;\n }\n\n return false;\n}\n\n/**\n * Sort the nodes.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function sort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState\n) {\n const { x, y } = eventCoordinates(data.e);\n\n if (!validateSort(data, state, x, y)) return;\n\n const range =\n state.draggedNode.data.index > data.targetData.node.data.index\n ? [data.targetData.node.data.index, state.draggedNode.data.index]\n : [state.draggedNode.data.index, data.targetData.node.data.index];\n\n state.targetIndex = data.targetData.node.data.index;\n\n state.affectedNodes = data.targetData.parent.data.enabledNodes.filter(\n (node) => {\n return (\n range[0] <= node.data.index &&\n node.data.index <= range[1] &&\n node.el !== state.draggedNode.el\n );\n }\n );\n\n data.targetData.parent.data.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.draggedNodes,\n targetNodes: [data.targetData.node],\n });\n}\n\n/**\n * Event listener used for all nodes.\n *\n * @param e - The event.\n *\n */\nexport function nodeEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function nodeTargetData(node: Node): NodeTargetData | undefined {\n const nodeData = nodes.get(node);\n\n if (!nodeData) return;\n\n const parentData = parents.get(node.parentNode);\n\n if (!parentData) return;\n\n return {\n node: {\n el: node,\n data: nodeData,\n },\n parent: {\n el: node.parentNode,\n data: parentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = nodeTargetData(e.currentTarget as Node);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\n/**\n * Transfer the nodes.\n *\n * @param data - The node event data or parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function transfer(\n data: NodeEventData | ParentEventData,\n state: DragState\n): void {\n if (\n !validateTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent as any,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n state,\n })\n )\n return;\n\n data.targetData.parent.data.config.performTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n initialIndex: state.initialIndex,\n state,\n targetNodes: \"node\" in data.targetData ? [data.targetData.node] : [],\n });\n\n state.currentParent = data.targetData.parent;\n\n state.transferred = true;\n}\n\n/**\n * Event listener used for all parents.\n *\n * @param callback - The callback.\n *\n * @returns A function to get the parent event data.\n */\nexport function parentEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function parentTargetData(\n parent: HTMLElement\n ): ParentTargetData | undefined {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: parent,\n data: parentData as ParentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = parentTargetData(e.currentTarget as HTMLElement);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\n/**\n * Add class to the node.\n *\n * @param els - The nodes.\n * @param className - The class name.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addNodeClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function nodeSetter(node: Node, nodeData: NodeData) {\n nodes.set(node, nodeData);\n }\n\n for (const el of els) {\n const nodeData = nodes.get(el as Node);\n\n const newData = addClass(el, className, nodeData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n nodeSetter(el as Node, newData as NodeData);\n }\n}\n\n/**\n * Add class to the parent.\n *\n * @param els - The parents.\n * @param className - The class name.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addParentClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function parentSetter(parent: HTMLElement, parentData: ParentData) {\n parents.set(parent, parentData);\n }\n\n for (const el of els) {\n const parentData = parents.get(el);\n\n const newData = addClass(el, className, parentData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n parentSetter(el, newData as ParentData);\n }\n}\n\n/**\n * Add class to the node.\n *\n * @param el - The node.\n * @param className - The class name.\n * @param data - The node data.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addClass(\n el: Node | HTMLElement | Element,\n className: string | undefined,\n data: NodeData | ParentData | undefined,\n omitAppendPrivateClass = false\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n if (classNames.includes(\"longPress\")) return;\n\n if (!data) {\n el.classList.add(...classNames);\n\n return;\n }\n\n const privateClasses = [];\n\n for (const className of classNames) {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n } else if (\n el.classList.contains(className) &&\n omitAppendPrivateClass === false\n ) {\n privateClasses.push(className);\n }\n }\n\n data.privateClasses = privateClasses;\n\n return data;\n}\n\n/**\n * Remove class from the nodes.\n *\n * @param els - The nodes.\n * @param className - The class name.\n *\n * @returns void\n */\nexport function removeClass(\n els: Array,\n className: string | undefined\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n for (const node of els) {\n if (!isNode(node)) {\n node.classList.remove(...classNames);\n continue;\n }\n\n const nodeData = nodes.get(node) || parents.get(node);\n\n if (!nodeData) continue;\n\n for (const className of classNames) {\n if (!nodeData.privateClasses.includes(className)) {\n node.classList.remove(className);\n }\n }\n }\n}\n\n/**\n * Check if the element is scrollable on the x axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param style - The style.\n * @param rect - The rect.\n * @param state - The state.\n *\n * @returns void\n */\nfunction isScrollX(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect,\n state: SynthDragState\n): { left: boolean; right: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n const canScrollLeft = el.scrollLeft > 0;\n const canScrollRight =\n el.scrollLeft + window.innerWidth < (state.rootScrollWidth || 0);\n\n return {\n right: canScrollRight && e.clientX > el.clientWidth * (1 - threshold),\n left: canScrollLeft && e.clientX < el.clientWidth * threshold,\n };\n }\n\n if (\n (style.overflowX === \"auto\" || style.overflowX === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollWidth = el.scrollWidth;\n const offsetWidth = el.offsetWidth;\n const scrollLeft = el.scrollLeft;\n\n return {\n right:\n e.clientX > rect.left + offsetWidth * (1 - threshold) &&\n scrollLeft < scrollWidth - offsetWidth,\n left: e.clientX < rect.left + offsetWidth * threshold && scrollLeft > 0,\n };\n }\n\n return {\n right: false,\n left: false,\n };\n}\n\n/**\n * Check if the element is scrollable on the y axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param style - The style.\n * @param rect - The rect.\n *\n * @returns void\n */\nfunction isScrollY(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect\n): { up: boolean; down: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n return {\n down: e.clientY > el.clientHeight * (1 - threshold),\n up: e.clientY < el.clientHeight * threshold,\n };\n }\n\n if (\n (style.overflowY === \"auto\" || style.overflowY === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollHeight = el.scrollHeight;\n const offsetHeight = el.offsetHeight;\n const scrollTop = el.scrollTop;\n\n return {\n down:\n e.clientY > rect.top + offsetHeight * (1 - threshold) &&\n scrollTop < scrollHeight - offsetHeight,\n up: e.clientY < rect.top + offsetHeight * threshold && scrollTop > 0,\n };\n }\n\n return {\n down: false,\n up: false,\n };\n}\n\n/**\n * Scroll the element on the x axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param state - The state.\n * @param right - Whether to scroll right.\n *\n * @returns void\n */\nfunction scrollX(\n el: HTMLElement,\n e: PointerEvent,\n state: SynthDragState,\n right = true\n) {\n state.preventEnter = true;\n\n const incr = right ? 5 : -5;\n\n function scroll(el: HTMLElement) {\n el.scrollBy({ left: incr });\n\n moveNode(e, state, incr, 0);\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n }\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n}\n\n/**\n * Scroll the element on the y axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param state - The state.\n * @param up - Whether to scroll up.\n *\n * @returns void\n */\nfunction scrollY(\n el: Element,\n e: PointerEvent,\n state: SynthDragState,\n up = true\n) {\n state.preventEnter = true;\n\n const incr = up ? -5 : 5;\n\n function scroll() {\n el.scrollBy({ top: incr });\n\n moveNode(e, state, 0, incr);\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n }\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n}\n\n/**\n * Handle the synth scroll.\n *\n * @param coordinates - The coordinates.\n * @param e - The event.\n * @param state - The state.\n *\n * @returns void\n */\nfunction handleSynthScroll(\n coordinates: { x: number; y: number },\n e: PointerEvent,\n state: SynthDragState\n) {\n cancelSynthScroll(state);\n\n const scrollables: Record<\"x\" | \"y\", HTMLElement | null> = {\n x: null,\n y: null,\n };\n\n const els = document.elementsFromPoint(coordinates.x, coordinates.y);\n\n for (const el of els) {\n if (scrollables.x && scrollables.y) break;\n\n if (!(el instanceof HTMLElement)) continue;\n\n const rect = el.getBoundingClientRect();\n\n const style = window.getComputedStyle(el);\n\n if (!scrollables.x) {\n const { left, right } = isScrollX(el, e, style, rect, state);\n\n if (left || right) {\n scrollables.x = el;\n\n scrollX(el, e, state, right);\n }\n }\n\n if (!scrollables.y) {\n const { up, down } = isScrollY(el, e, style, rect);\n\n if (up || down) {\n scrollables.y = el;\n\n scrollY(el, e, state, up);\n }\n }\n }\n}\n\nexport function getElFromPoint(coordinates: {\n x: number;\n y: number;\n}): NodeFromPoint | ParentFromPoint | undefined {\n let target = document.elementFromPoint(coordinates.x, coordinates.y);\n\n if (!isNode(target)) return;\n\n let isParent;\n\n let invalidEl = true;\n\n while (target && invalidEl) {\n if (nodes.has(target as Node) || parents.has(target as HTMLElement)) {\n invalidEl = false;\n\n isParent = parents.has(target as HTMLElement);\n\n break;\n }\n\n target = target.parentNode as Node;\n }\n\n if (!isParent) {\n const targetNodeData = nodes.get(target as Node);\n\n if (!targetNodeData) return;\n\n const targetParentData = parents.get(target.parentNode as Node);\n\n if (!targetParentData) return;\n\n return {\n node: {\n el: target as Node,\n data: targetNodeData,\n },\n parent: {\n el: target.parentNode as Node,\n data: targetParentData as ParentData,\n },\n };\n } else {\n const parentData = parents.get(target as HTMLElement);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: target as HTMLElement,\n data: parentData as ParentData,\n },\n };\n }\n}\n\n/**\n * Checks to see that a given element and its parent node is instance of\n * HTMLElement.\n *\n * @param {unknown} el - The element to check.\n *\n * @returns {boolean} - Whether or not provided element is of type Node.\n */\nexport function isNode(el: unknown): el is Node {\n return el instanceof HTMLElement && el.parentNode instanceof HTMLElement;\n}\n\n/**\n * Takes a given el and event handlers, assigns them, and returns the used abort\n * controller.\n *\n * @param el - The element to add the event listeners to.\n * @param events - The events to add to the element.\n * @returns - The abort controller used for the event listeners.\n */\nexport function addEvents(\n el: Document | ShadowRoot | Node | HTMLElement | Window,\n events: EventHandlers | any\n): AbortController {\n const abortController = new AbortController();\n\n for (const eventName in events) {\n const handler = events[eventName];\n\n el.addEventListener(eventName, handler, {\n signal: abortController.signal,\n passive: false,\n });\n }\n\n return abortController;\n}\n","/**\n * Function to prevent default behavior of an event.\n *\n * @param {Event} e - The event to prevent default behavior of.\n */\nexport function pd(e: Event) {\n e.preventDefault();\n}\n\n/**\n * Function to stop propagation of an event.\n *\n * @param {Event} e - The event to stop propagation of.\n */\nexport function sp(e: Event) {\n e.stopPropagation();\n}\n\nexport function rect(el: HTMLElement) {\n return el.getBoundingClientRect();\n}\n\n/**\n * Function to create an emitter.\n *\n * @returns {[Function, Function]} A tuple containing emit and on functions\n */\nexport function createEmitter() {\n const callbacks = new Map void>>();\n\n const emit = function (eventName: string, data: T) {\n if (!callbacks.get(eventName)) return;\n callbacks.get(eventName)!.forEach((cb) => {\n cb(data);\n });\n };\n\n const on = function (eventName: string, callback: (data: T) => void) {\n const cbs = callbacks.get(eventName) ?? [];\n\n cbs.push(callback);\n\n callbacks.set(eventName, cbs);\n };\n\n return [emit, on] as const;\n}\n\n/**\n * The emit and on functions for drag and drop.\n *\n * @type {[Function, Function]}\n */\nexport const [emit, on] = createEmitter();\n\n/**\n * A regular expression to test for a valid date string.\n *\n * @param x - A RegExp to compare.\n * @param y - A RegExp to compare.\n * @public\n */\nexport function eqRegExp(x: RegExp, y: RegExp): boolean {\n return (\n x.source === y.source &&\n x.flags.split(\"\").sort().join(\"\") === y.flags.split(\"\").sort().join(\"\")\n );\n}\n\n/**\n * Compare two values for equality, optionally at depth.\n *\n * @param valA - First value.\n * @param valB - Second value.\n * @param deep - If it will compare deeply if it's an object.\n * @param explicit - An array of keys to explicity check.\n *\n * @returns `boolean`\n *\n * @public\n */\nexport function eq(\n valA: unknown,\n valB: unknown,\n deep = true,\n explicit: string[] = [\"__key\"]\n): boolean {\n if (valA === valB) return true;\n\n if (\n typeof valB === \"object\" &&\n typeof valA === \"object\" &&\n valA !== null &&\n valB !== null\n ) {\n if (valA instanceof Map) return false;\n if (valA instanceof Set) return false;\n if (valA instanceof Date && valB instanceof Date)\n return valA.getTime() === valB.getTime();\n if (valA instanceof RegExp && valB instanceof RegExp)\n return eqRegExp(valA, valB);\n if (valA === null || valB === null) return false;\n\n const objA = valA as Record;\n const objB = valB as Record;\n\n if (Object.keys(objA).length !== Object.keys(objB).length) return false;\n\n for (const k of explicit) {\n if ((k in objA || k in objB) && objA[k] !== objB[k]) return false;\n }\n\n for (const key in objA) {\n if (!(key in objB)) return false;\n if (objA[key] !== objB[key] && !deep) return false;\n if (deep && !eq(objA[key], objB[key], deep, explicit)) return false;\n }\n return true;\n }\n return false;\n}\n\n///**\n// * Throttle a function.\n// *\n// * @param callback - The callback function to throttle.\n// * @param limit - The minimum time in milliseconds between function calls.\n// *\n// * @returns A throttled version of the callback function.\n// */\n//export function throttle(\n// callback: (...args: Args) => Return,\n// limit: number\n//): (...args: Args) => void {\n// let wait = false;\n// return function (...args: Args) {\n// if (!wait) {\n// callback.apply(null, args);\n// wait = true;\n// setTimeout(function () {\n// wait = false;\n// }, limit);\n// }\n// };\n//}\n\n/**\n * Split a class name into an array of class names.\n *\n * @param className - The class name to split.\n *\n * @returns An array of class names.\n */\nexport function splitClass(className: string): Array {\n return className.split(\" \").filter((x) => x);\n}\n\nexport function getRealCoords(el: HTMLElement): {\n top: number;\n bottom: number;\n left: number;\n right: number;\n height: number;\n width: number;\n} {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nexport function eventCoordinates(data: DragEvent | PointerEvent) {\n return { x: data.clientX, y: data.clientY };\n}\n","import type { SetupNodeData, Node } from \"../../types\";\nimport type { AnimationsConfig } from \"./types\";\nimport { state, parents, isDragState } from \"../../index\";\n\nexport function animations(animationsConfig: Partial = {}) {\n const slideUp = [\n {\n transform: `translateY(${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideDown = [\n {\n transform: `translateY(-${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideLeft = [\n {\n transform: `translateX(${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n\n const slideRight = [\n {\n transform: `translateX(-${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n setup() {\n if (document.head.querySelector(\"[data-drag-and-drop]\")) return;\n },\n\n setupNodeRemap(data: SetupNodeData) {\n if (!isDragState(state)) return;\n\n const duration = animationsConfig.duration || 150;\n\n if (data.node.data.value === state.draggedNode.data.value) {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideRight, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n }\n\n return;\n }\n\n if (\n !state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.node.data.value)\n )\n return;\n\n const nodeRect = data.node.el.getBoundingClientRect();\n\n const nodeIndex = state.affectedNodes.findIndex(\n (x) => x.data.value === data.node.data.value\n );\n\n const draggedNodeIndex = state.draggedNode.data.index;\n\n const ascendingDirection = draggedNodeIndex >= state.targetIndex;\n\n let adjacentNode;\n\n if (ascendingDirection) {\n adjacentNode = state.affectedNodes[nodeIndex + 1]\n ? state.affectedNodes[nodeIndex + 1]\n : state.affectedNodes[nodeIndex - 1];\n } else {\n adjacentNode = state.affectedNodes[nodeIndex - 1]\n ? state.affectedNodes[nodeIndex - 1]\n : state.affectedNodes[nodeIndex + 1];\n }\n\n if (adjacentNode) {\n const xDiff = Math.abs(\n nodeRect.x - adjacentNode.el.getBoundingClientRect().x\n );\n\n const yDiff = Math.abs(\n nodeRect.y - adjacentNode.el.getBoundingClientRect().y\n );\n\n if (xDiff > yDiff && ascendingDirection) {\n animate(data.node.el, slideRight, duration);\n } else if (xDiff > yDiff && !ascendingDirection) {\n animate(data.node.el, slideLeft, duration);\n }\n } else {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideRight, duration);\n\n break;\n }\n }\n },\n };\n };\n}\n\nfunction animate(\n node: Node,\n animation: Keyframe[] | PropertyIndexedKeyframes,\n duration: number\n) {\n if (!state) return;\n\n state.preventEnter = true;\n\n node.animate(animation, {\n duration: duration,\n easing: \"ease-in-out\",\n });\n\n setTimeout(() => {\n if (!state) return;\n\n state.preventEnter = false;\n }, duration);\n}\n","import type { InsertConfig } from \"../../types\";\nimport type {\n DragState,\n NodeDragEventData,\n NodeRecord,\n ParentEventData,\n PointeroverParentEvent,\n ParentRecord,\n SynthDragState,\n InsertEvent,\n BaseDragState,\n InsertState,\n Coordinates,\n} from \"../../types\";\n\nimport {\n parents,\n parentValues,\n setParentValues,\n state,\n addParentClass,\n isDragState,\n isSynthDragState,\n removeClass,\n addEvents,\n remapNodes,\n} from \"../../index\";\n\nimport { eq, pd, eventCoordinates } from \"../../utils\";\n\nexport const insertState: InsertState = {\n draggedOverNodes: [],\n draggedOverParent: null,\n targetIndex: 0,\n ascending: false,\n insertPoint: null,\n dragging: false,\n};\n\nlet documentController: AbortController | undefined;\n\n// WIP: This is a work in progress and not yet fully functional\nexport function insert(insertConfig: InsertConfig) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const insertParentConfig = {\n ...parentData.config,\n insertConfig,\n };\n\n return {\n teardown() {\n if (parentData.abortControllers.root) {\n parentData.abortControllers.root.abort();\n }\n },\n setup() {\n insertParentConfig.handleNodeDragover =\n insertConfig.handleNodeDragover || handleNodeDragover;\n\n insertParentConfig.handleParentPointerover =\n insertConfig.handleParentPointerover || handleParentPointerover;\n\n insertParentConfig.handleNodePointerover =\n insertConfig.handleNodePointerover || handleParentPointerover;\n\n insertParentConfig.handleParentDragover =\n insertConfig.handleParentDragover || handleParentDragover;\n\n const originalHandleend = insertParentConfig.handleEnd;\n\n insertParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: checkPosition,\n pointermove: checkPosition,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = insertParentConfig;\n\n state.on(\"dragStarted\", () => {\n defineRanges(parent);\n });\n\n state.on(\"scrollStarted\", () => {\n if (insertState.insertPoint)\n insertState.insertPoint.el.style.display = \"none\";\n });\n\n state.on(\"scrollEnded\", () => {\n defineRanges(parent);\n });\n\n const firstScrollableParent = findFirstOverflowingParent(parent);\n\n if (firstScrollableParent) {\n firstScrollableParent.addEventListener(\n \"scroll\",\n defineRanges.bind(null, parent)\n );\n }\n\n window.addEventListener(\"resize\", defineRanges.bind(null, parent));\n },\n };\n };\n}\n\nfunction findFirstOverflowingParent(element: HTMLElement): HTMLElement | null {\n let parent = element.parentElement;\n\n while (parent) {\n const { overflow, overflowY, overflowX } = getComputedStyle(parent);\n\n // Check if the overflow property is set to scroll, auto, or hidden (anything other than visible)\n const isOverflowSet =\n overflow !== \"visible\" ||\n overflowY !== \"visible\" ||\n overflowX !== \"visible\";\n\n // Check if there is actual overflow (scrolling)\n const isOverflowing =\n parent.scrollHeight > parent.clientHeight ||\n parent.scrollWidth > parent.clientWidth;\n const hasScrollPosition = parent.scrollTop > 0 || parent.scrollLeft > 0;\n\n if (isOverflowSet && (isOverflowing || hasScrollPosition)) {\n return parent;\n }\n\n parent = parent.parentElement;\n }\n\n return null; // No overflowing parent found\n}\n\nfunction checkPosition(e: DragEvent | PointerEvent) {\n if (!isDragState(state)) return;\n\n const el = document.elementFromPoint(e.clientX, e.clientY);\n\n if (!(el instanceof HTMLElement)) return;\n\n if (!parents.has(el)) {\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint?.el === el) return;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n if (insertState.draggedOverParent) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n\n state.currentParent = state.initialParent;\n }\n}\n\ninterface Range {\n x: [number, number];\n y: [number, number];\n vertical: boolean;\n}\n\nfunction createVerticalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean\n): Range {\n const center = nodeCoords.top + nodeCoords.height / 2;\n\n if (!otherCoords) {\n const offset = nodeCoords.height / 2 + 10;\n return {\n y: isAscending ? [center, center + offset] : [center - offset, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n }\n\n const otherEdge = isAscending ? otherCoords.top : otherCoords.bottom;\n const nodeEdge = isAscending ? nodeCoords.bottom : nodeCoords.top;\n const midpoint = nodeEdge + Math.abs(nodeEdge - otherEdge) / 2;\n\n return {\n y: isAscending ? [center, midpoint] : [midpoint, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n}\n\nfunction createHorizontalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean,\n lastInRow = false\n): Range {\n const center = nodeCoords.left + nodeCoords.width / 2;\n\n if (!otherCoords) {\n if (isAscending) {\n return {\n x: [center, center + nodeCoords.width],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [nodeCoords.left - 10, center],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n }\n\n if (isAscending && lastInRow) {\n return {\n x: [center, nodeCoords.right + 10],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n\n if (isAscending) {\n const nextNodeCenter = otherCoords.left + otherCoords.width / 2;\n return {\n x: [center, center + Math.abs(center - nextNodeCenter) / 2],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [\n otherCoords.right + Math.abs(otherCoords.right - nodeCoords.left) / 2,\n center,\n ],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n}\n\nfunction getRealCoords(el: HTMLElement): Coordinates {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nfunction defineRanges(parent: HTMLElement) {\n if (!isDragState(state)) return;\n\n const parentData = parents.get(parent);\n if (!parentData) return;\n\n const enabledNodes = parentData.enabledNodes;\n\n enabledNodes.forEach((node, index) => {\n node.data.range = {};\n\n const prevNode = enabledNodes[index - 1];\n const nextNode = enabledNodes[index + 1];\n const nodeCoords = getRealCoords(node.el);\n const prevNodeCoords = prevNode ? getRealCoords(prevNode.el) : undefined;\n const nextNodeCoords = nextNode ? getRealCoords(nextNode.el) : undefined;\n\n const aboveOrBelowPrevious =\n prevNodeCoords &&\n (nodeCoords.top > prevNodeCoords.bottom ||\n nodeCoords.bottom < prevNodeCoords.top);\n\n const aboveOrBelowAfter =\n nextNodeCoords &&\n (nodeCoords.top > nextNodeCoords.bottom ||\n nodeCoords.bottom < nextNodeCoords.top);\n\n const fullishWidth =\n parent.getBoundingClientRect().width * 0.8 < nodeCoords.width;\n\n if (fullishWidth) {\n node.data.range.ascending = createVerticalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createVerticalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowAfter && !aboveOrBelowPrevious) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (!aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowPrevious && !nextNodeCoords) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n undefined,\n true\n );\n } else if (aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n undefined,\n false\n );\n }\n });\n}\n\nexport function handleNodeDragover(data: NodeDragEventData) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n data.e.preventDefault();\n}\n\nfunction processParentDragEvent(\n e: DragEvent | PointerEvent,\n targetData: ParentEventData[\"targetData\"],\n state: DragState,\n isNativeDrag: boolean\n) {\n const config = targetData.parent.data.config;\n\n if (!isNativeDrag && config.nativeDrag) return;\n\n pd(e);\n\n if (isNativeDrag) pd(e);\n\n const { x, y } = eventCoordinates(e);\n\n // Calculate global coordinates\n const clientX = x;\n const clientY = y;\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n state.coordinates.x = clientX + scrollLeft;\n state.coordinates.y = clientY + scrollTop;\n\n const nestedParent = targetData.parent.data.nestedParent;\n\n let realTargetParent = targetData.parent;\n\n if (nestedParent) {\n const rect = nestedParent.el.getBoundingClientRect();\n\n if (state.coordinates.y > rect.top && state.coordinates.y < rect.bottom)\n realTargetParent = nestedParent;\n }\n\n if (realTargetParent.el === state.currentParent?.el) {\n moveBetween(realTargetParent, state);\n } else {\n moveOutside(realTargetParent, state);\n }\n\n state.currentParent = realTargetParent;\n}\n\nexport function handleParentDragover(\n data: ParentEventData,\n state: DragState\n) {\n processParentDragEvent(data.e as DragEvent, data.targetData, state, true);\n}\n\nexport function handleParentPointerover(data: PointeroverParentEvent) {\n const { detail } = data;\n\n const { state, targetData } = detail;\n\n if (state.scrolling) return;\n\n processParentDragEvent(detail.e, targetData, state, false);\n}\n\nexport function moveBetween(data: ParentRecord, state: DragState) {\n if (data.data.config.sortable === false) return;\n\n if (\n data.el === insertState.draggedOverParent?.el &&\n insertState.draggedOverParent.data.getValues(data.el).length === 0\n ) {\n return;\n } else if (insertState.draggedOverParent?.el) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n insertState.draggedOverParent = null;\n }\n\n const foundRange = findClosest(data.data.enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n}\n\nfunction moveOutside(data: ParentRecord, state: DragState) {\n if (data.el === state.currentParent.el) return false;\n\n const targetConfig = data.data.config;\n\n if (state.draggedNode.el.contains(data.el)) return false;\n\n if (targetConfig.dropZone === false) return;\n\n const initialParentConfig = state.initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n data,\n state.initialParent,\n state.currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n const values = data.data.getValues(data.el);\n\n if (!values.length) {\n addParentClass([data.el], targetConfig.dropZoneClass);\n\n insertState.draggedOverParent = data as ParentRecord;\n\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n } else {\n removeClass([state.currentParent.el], targetConfig.dropZoneClass);\n\n const enabledNodes = data.data.enabledNodes;\n\n const foundRange = findClosest(enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n }\n}\n\nfunction findClosest(enabledNodes: NodeRecord[], state: DragState) {\n let foundRange: [NodeRecord, string] | null = null;\n\n for (let x = 0; x < enabledNodes.length; x++) {\n if (!state || !enabledNodes[x].data.range) continue;\n\n if (enabledNodes[x].data.range!.ascending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.ascending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.ascending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.ascending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.ascending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"ascending\"];\n\n return foundRange;\n }\n }\n\n if (enabledNodes[x].data.range!.descending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.descending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.descending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.descending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.descending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"descending\"];\n\n return foundRange;\n }\n }\n }\n}\n\nfunction createInsertPoint(\n parent: ParentRecord,\n insertState: InsertState\n) {\n const insertPoint = parent.data.config.insertConfig?.insertPoint({\n el: parent.el,\n data: parent.data,\n });\n\n if (!insertPoint)\n throw new Error(\"Insert point not found\", { cause: parent });\n\n insertState.insertPoint = {\n parent,\n el: insertPoint,\n };\n\n document.body.appendChild(insertPoint);\n\n Object.assign(insertPoint, {\n position: \"absolute\",\n display: \"none\",\n });\n}\n\nfunction removeInsertPoint(insertState: InsertState) {\n if (insertState.insertPoint?.el) insertState.insertPoint.el.remove();\n\n insertState.insertPoint = null;\n}\n\nfunction positioninsertPoint(\n parent: ParentRecord,\n position: { x: number[]; y: number[]; vertical: boolean },\n ascending: boolean,\n node: NodeRecord,\n insertState: InsertState\n) {\n if (insertState.insertPoint?.el !== parent.el) {\n removeInsertPoint(insertState);\n\n createInsertPoint(parent, insertState);\n }\n\n insertState.draggedOverNodes = [node];\n\n if (!insertState.insertPoint) return;\n\n if (position.vertical) {\n const topPosition =\n position.y[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().height / 2;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${topPosition}px`,\n left: `${position.x[0]}px`,\n right: `${position.x[1]}px`,\n height: \"4px\",\n width: `${position.x[1] - position.x[0]}px`,\n });\n } else {\n const leftPosition =\n position.x[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().width / 2;\n insertState.insertPoint.el.style.left = `${leftPosition}px`;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${position.y[0]}px`,\n bottom: `${position.y[1]}px`,\n width: \"4px\",\n height: `${position.y[1] - position.y[0]}px`,\n });\n }\n\n insertState.targetIndex = node.data.index;\n\n insertState.ascending = ascending;\n\n insertState.insertPoint.el.style.display = \"block\";\n}\n\nexport function handleParentDrop(_data: NodeDragEventData) {}\n\n/**\n * Performs the actual insertion of the dragged nodes into the target parent.\n *\n * @param state - The current drag state.\n */\nexport function handleEnd(\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isDragState(state)) return;\n\n const insertPoint = insertState.insertPoint;\n\n if (!insertState.draggedOverParent) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const transferred = state.initialParent.el !== state.currentParent.el;\n\n remapNodes(state.initialParent.el);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const enabledNodes = [...state.initialParent.data.enabledNodes];\n\n const originalIndex = state.draggedNodes[0].data.index;\n\n const targetIndex = insertState.targetIndex;\n\n if (\n !transferred &&\n insertState.draggedOverNodes[0] &&\n insertState.draggedOverNodes[0].el !== state.draggedNodes[0].el\n ) {\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n let index = insertState.draggedOverNodes[0].data.index;\n\n if (\n insertState.targetIndex > state.draggedNodes[0].data.index &&\n !insertState.ascending\n ) {\n index--;\n } else if (\n insertState.targetIndex < state.draggedNodes[0].data.index &&\n insertState.ascending\n ) {\n index++;\n }\n\n newParentValues.splice(index, 0, ...draggedValues);\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n if (state.initialParent.data.config.onSort) {\n const sortEventData = {\n parent: {\n el: state.initialParent.el,\n data: state.initialParent.data,\n } as ParentRecord,\n previousValues: [...draggedParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...state.initialParent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes,\n previousPosition: originalIndex,\n position: index,\n state: state as DragState,\n };\n\n state.initialParent.data.config.onSort(sortEventData);\n }\n } else if (transferred && insertState.draggedOverNodes.length) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n // For the time being, we will not be remoing the value of the original dragged parent.\n let index = insertState.draggedOverNodes[0].data.index || 0;\n\n if (insertState.ascending) index++;\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n targetIndex: index,\n })\n : draggedValues;\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n if (state.currentParent.el.contains(state.initialParent.el)) {\n // Update initial parent values first\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n // Now get the target parent values.\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n } else {\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n }\n\n const data = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n targetIndex,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.onTransfer)\n state.initialParent.data.config.onTransfer(data);\n if (state.currentParent.data.config.onTransfer)\n state.currentParent.data.config.onTransfer(data);\n }\n } else if (insertState.draggedOverParent) {\n if (state.currentParent.el.contains(state.initialParent.el)) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n } else {\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n }\n\n const data: InsertEvent = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.insertConfig?.insertEvent)\n state.initialParent.data.config.insertConfig.insertEvent(data);\n if (state.currentParent.data.config.insertConfig?.insertEvent)\n state.currentParent.data.config.insertConfig.insertEvent(data);\n\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n const dropZoneClass = isSynthDragState(state)\n ? state.initialParent.data.config.synthDropZoneClass\n : state.initialParent.data.config.dropZoneClass;\n\n removeClass(\n insertState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const dragPlaceholderClass =\n state.initialParent.data.config.dragPlaceholderClass;\n\n removeClass(\n state.draggedNodes.map((node) => node.el),\n dragPlaceholderClass\n );\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n}\n","import type {\n DropSwapConfig,\n NodeDragEventData,\n DragState,\n SynthDragState,\n NodeRecord,\n PointeroverNodeEvent,\n ParentDragEventData,\n PointeroverParentEvent,\n DropSwapState,\n} from \"../../types\";\nimport {\n parents,\n parentValues,\n setParentValues,\n addNodeClass,\n isSynthDragState,\n removeClass,\n addClass,\n state,\n addEvents,\n isDragState,\n} from \"../../index\";\n\nexport const dropSwapState: DropSwapState = {\n draggedOverNodes: Array>(),\n initialDraggedIndex: undefined,\n transferred: false,\n dragging: false,\n};\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\nexport function dropOrSwap(dropSwapConfig: DropSwapConfig = {}) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const dropSwapParentConfig = {\n ...parentData.config,\n dropSwapConfig,\n };\n\n return {\n setup() {\n dropSwapParentConfig.handleNodeDragover =\n dropSwapConfig.handleNodeDragover || handleNodeDragover;\n\n dropSwapParentConfig.handleParentDragover =\n dropSwapConfig.handleParentDragover || handleParentDragover;\n\n dropSwapParentConfig.handleNodePointerover =\n dropSwapConfig.handleNodePointerover || handleNodePointerover;\n\n dropSwapParentConfig.handleParentPointerover =\n dropSwapConfig.handleParentPointerover || handeParentPointerover;\n\n const originalHandleend = dropSwapParentConfig.handleEnd;\n\n dropSwapParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: rootDragover,\n handleRootPointerover: rootPointerover,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = dropSwapParentConfig;\n },\n };\n };\n}\n\nfunction rootDragover(_e: DragEvent) {\n if (!isDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.dropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction rootPointerover(_e: CustomEvent) {\n if (!isSynthDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.synthDropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction updateDraggedOverNodes(\n data: PointeroverNodeEvent | NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const targetData =\n \"detail\" in data ? data.detail.targetData : data.targetData;\n\n const config = targetData.parent.data.config;\n\n const dropZoneClass = isSynthDragState(state)\n ? config.synthDropZoneClass\n : config.dropZoneClass;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const enabledNodes = targetData.parent.data.enabledNodes;\n\n if (!enabledNodes) return;\n\n dropSwapState.draggedOverNodes = enabledNodes.slice(\n targetData.node.data.index,\n targetData.node.data.index + state.draggedNodes.length\n );\n\n addNodeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass,\n true\n );\n\n state.currentTargetValue = targetData.node.data.value;\n\n state.currentParent = targetData.parent;\n\n addClass(\n state.currentParent.el,\n isSynthDragState(state)\n ? config.synthDropZoneParentClass\n : config.dropZoneParentClass,\n state.currentParent.data,\n true\n );\n}\n\nfunction handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n updateDraggedOverNodes(data, state);\n}\n\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n const currentConfig = state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.dropZoneClass\n );\n\n removeClass([state.currentParent.el], currentConfig.dropZoneParentClass);\n\n const config = data.targetData.parent.data.config;\n\n addClass(\n data.targetData.parent.el,\n config.dropZoneParentClass,\n data.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n state.currentParent = data.targetData.parent;\n}\n\nexport function handeParentPointerover(data: PointeroverParentEvent) {\n const currentConfig = data.detail.state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.synthDropZoneClass\n );\n\n removeClass(\n [data.detail.state.currentParent.el],\n currentConfig.synthDropZoneParentClass\n );\n\n const config = data.detail.targetData.parent.data.config;\n\n addClass(\n data.detail.targetData.parent.el,\n config.synthDropZoneParentClass,\n data.detail.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n data.detail.state.currentParent = data.detail.targetData.parent;\n}\n\nfunction handleNodePointerover(data: PointeroverNodeEvent) {\n if (!isSynthDragState(data.detail.state)) return;\n\n updateDraggedOverNodes(data, data.detail.state);\n}\n\nfunction swapElements(\n arr1: T[],\n arr2: T[] | null,\n index1: number | number[],\n index2: number\n): T[] | [T[], T[]] {\n const indices1 = Array.isArray(index1) ? index1 : [index1];\n\n if (arr2 === null) {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr1[index2];\n\n arr1.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return arr1.filter((el) => el !== undefined);\n } else {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr2[index2];\n\n arr2.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return [arr1.filter((el) => el !== undefined), arr2];\n }\n}\n\nfunction handleEnd(state: DragState | SynthDragState) {\n const isSynth = isSynthDragState(state);\n\n removeClass(\n [state.currentParent.el],\n isSynth\n ? state.currentParent.data.config.synthDropZoneParentClass\n : state.currentParent.data.config.dropZoneParentClass\n );\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n isSynth\n ? state.currentParent.data.config.synthDropZoneClass\n : state.currentParent.data.config.dropZoneClass\n );\n\n const values = parentValues(state.currentParent.el, state.currentParent.data);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const newValues = values.filter((x) => !draggedValues.includes(x));\n\n const targetIndex = dropSwapState.draggedOverNodes[0]?.data.index;\n\n const draggedIndex = state.draggedNodes[0].data.index;\n\n const initialParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n if (targetIndex === undefined) {\n if (state.initialParent.el === state.currentParent.el) return;\n\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n values.concat(draggedValues)\n );\n\n return;\n }\n\n let swap = false;\n\n const shouldSwap = state.initialParent.data.config.dropSwapConfig?.shouldSwap;\n\n if (shouldSwap)\n swap = shouldSwap({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: dropSwapState.draggedOverNodes as NodeRecord[],\n state,\n });\n\n if (state.initialParent.el === state.currentParent.el) {\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n swap ? swapElements(values, null, draggedIndex, targetIndex) : newValues\n );\n } else {\n if (swap) {\n const res = swapElements(\n initialParentValues,\n newValues,\n state.initialIndex,\n targetIndex\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n res[0] as T[]\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n res[1] as T[]\n );\n } else {\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n newValues\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAAA;AAAA,EAAA;AAAA,4BAAAC;AAAA,EAAA;AAAA;AAAA;AAAA,+BAAAC;AAAA,EAAA;AAAA,8BAAAC;AAAA,EAAA;AAAA;AAAA;AAAA,iCAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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entDragover","handleParentPointerover","emit","on","state","insertState","state","draggedParentValues","documentController","handleNodeDragover","handleParentDragover","state","handleEnd","documentController","baseDragState","dragStateProps","nodes","emit","on","handleNodeDragover","handleParentDragover","handleEnd","handleNodePointerover","handleParentPointerover","draggedNodes","state","parent","x","scrollTimeout","node","scrollX","scrollY","className","el"]} \ No newline at end of file diff --git a/dist/index.d.cts b/dist/index.d.cts index 2548e4af..d04ae73f 100644 --- a/dist/index.d.cts +++ b/dist/index.d.cts @@ -1323,6 +1323,15 @@ declare function transfer(data: NodeEventData | ParentEventData, state: * @returns A function to get the parent event data. */ declare function parentEventData(callback: any): (e: Event) => NodeEventData | undefined; +/** + * Add class to the node. + * + * @param els - The nodes. + * @param className - The class name. + * @param omitAppendPrivateClass - Whether to omit append private class. + * + * @returns void + */ declare function addNodeClass(els: Array, className: string | undefined, omitAppendPrivateClass?: boolean): void; /** * Add class to the parent. diff --git a/dist/index.d.ts b/dist/index.d.ts index 2548e4af..d04ae73f 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1323,6 +1323,15 @@ declare function transfer(data: NodeEventData | ParentEventData, state: * @returns A function to get the parent event data. */ declare function parentEventData(callback: any): (e: Event) => NodeEventData | undefined; +/** + * Add class to the node. + * + * @param els - The nodes. + * @param className - The class name. + * @param omitAppendPrivateClass - Whether to omit append private class. + * + * @returns void + */ declare function addNodeClass(els: Array, className: string | undefined, omitAppendPrivateClass?: boolean): void; /** * Add class to the parent. diff --git a/dist/index.mjs b/dist/index.mjs index 77ade232..18ba4c64 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1159,11 +1159,6 @@ function copyNodeStyle(sourceNode, targetNode, omitKeys = false) { computedStyle.getPropertyPriority(key) ); } - for (const child of Array.from(sourceNode.children)) { - if (!isNode(child)) continue; - const targetChild = targetNode.children[Array.from(sourceNode.children).indexOf(child)]; - copyNodeStyle(child, targetChild, omitKeys); - } } function handleRootDragover(e) { if (!isDragState(state)) return; @@ -2278,7 +2273,9 @@ function initSynthDrag(node, parent, e, _state, draggedNodes2) { }); } else { if (!config.multiDrag || draggedNodes2.length === 1) { + console.log("boom"); dragImage = node.el.cloneNode(true); + copyNodeStyle(node.el, dragImage); dragImage.id = "dnd-dragged-node-clone"; display = dragImage.style.display; dragImage.setAttribute("popover", "manual"); @@ -2293,22 +2290,27 @@ function initSynthDrag(node, parent, e, _state, draggedNodes2) { }); } else { const wrapper = document.createElement("div"); - wrapper.setAttribute("popover", ""); + console.log("getting here"); + wrapper.setAttribute("popover", "manual"); for (const node2 of draggedNodes2) { const clonedNode = node2.el.cloneNode(true); + copyNodeStyle(node2.el, clonedNode); clonedNode.style.pointerEvents = "none"; wrapper.append(clonedNode); } - Object.assign(wrapper.style, { + display = wrapper.style.display; + wrapper.id = "dnd-dragged-node-clone"; + dragImage = wrapper; + Object.assign(dragImage.style, { display: "flex", flexDirection: "column", - left: "-9999px", position: "absolute", + overflow: "hidden", + margin: 0, + padding: 0, pointerEvents: "none", zIndex: 9999 }); - wrapper.id = "dnd-dragged-node-clone"; - dragImage = wrapper; } } dragImage.style.position = "absolute"; diff --git a/dist/index.mjs.map b/dist/index.mjs.map index 3cc9cf00..dc760ccc 100644 --- a/dist/index.mjs.map +++ b/dist/index.mjs.map @@ -1 +1 @@ -{"version":3,"sources":["../src/utils.ts","../src/plugins/animations/index.ts","../src/plugins/insert/index.ts","../src/plugins/drop-or-swap/index.ts","../src/index.ts"],"sourcesContent":["/**\n * Function to prevent default behavior of an event.\n *\n * @param {Event} e - The event to prevent default behavior of.\n */\nexport function pd(e: Event) {\n e.preventDefault();\n}\n\n/**\n * Function to stop propagation of an event.\n *\n * @param {Event} e - The event to stop propagation of.\n */\nexport function sp(e: Event) {\n e.stopPropagation();\n}\n\nexport function rect(el: HTMLElement) {\n return el.getBoundingClientRect();\n}\n\n/**\n * Function to create an emitter.\n *\n * @returns {[Function, Function]} A tuple containing emit and on functions\n */\nexport function createEmitter() {\n const callbacks = new Map void>>();\n\n const emit = function (eventName: string, data: T) {\n if (!callbacks.get(eventName)) return;\n callbacks.get(eventName)!.forEach((cb) => {\n cb(data);\n });\n };\n\n const on = function (eventName: string, callback: (data: T) => void) {\n const cbs = callbacks.get(eventName) ?? [];\n\n cbs.push(callback);\n\n callbacks.set(eventName, cbs);\n };\n\n return [emit, on] as const;\n}\n\n/**\n * The emit and on functions for drag and drop.\n *\n * @type {[Function, Function]}\n */\nexport const [emit, on] = createEmitter();\n\n/**\n * A regular expression to test for a valid date string.\n *\n * @param x - A RegExp to compare.\n * @param y - A RegExp to compare.\n * @public\n */\nexport function eqRegExp(x: RegExp, y: RegExp): boolean {\n return (\n x.source === y.source &&\n x.flags.split(\"\").sort().join(\"\") === y.flags.split(\"\").sort().join(\"\")\n );\n}\n\n/**\n * Compare two values for equality, optionally at depth.\n *\n * @param valA - First value.\n * @param valB - Second value.\n * @param deep - If it will compare deeply if it's an object.\n * @param explicit - An array of keys to explicity check.\n *\n * @returns `boolean`\n *\n * @public\n */\nexport function eq(\n valA: unknown,\n valB: unknown,\n deep = true,\n explicit: string[] = [\"__key\"]\n): boolean {\n if (valA === valB) return true;\n\n if (\n typeof valB === \"object\" &&\n typeof valA === \"object\" &&\n valA !== null &&\n valB !== null\n ) {\n if (valA instanceof Map) return false;\n if (valA instanceof Set) return false;\n if (valA instanceof Date && valB instanceof Date)\n return valA.getTime() === valB.getTime();\n if (valA instanceof RegExp && valB instanceof RegExp)\n return eqRegExp(valA, valB);\n if (valA === null || valB === null) return false;\n\n const objA = valA as Record;\n const objB = valB as Record;\n\n if (Object.keys(objA).length !== Object.keys(objB).length) return false;\n\n for (const k of explicit) {\n if ((k in objA || k in objB) && objA[k] !== objB[k]) return false;\n }\n\n for (const key in objA) {\n if (!(key in objB)) return false;\n if (objA[key] !== objB[key] && !deep) return false;\n if (deep && !eq(objA[key], objB[key], deep, explicit)) return false;\n }\n return true;\n }\n return false;\n}\n\n///**\n// * Throttle a function.\n// *\n// * @param callback - The callback function to throttle.\n// * @param limit - The minimum time in milliseconds between function calls.\n// *\n// * @returns A throttled version of the callback function.\n// */\n//export function throttle(\n// callback: (...args: Args) => Return,\n// limit: number\n//): (...args: Args) => void {\n// let wait = false;\n// return function (...args: Args) {\n// if (!wait) {\n// callback.apply(null, args);\n// wait = true;\n// setTimeout(function () {\n// wait = false;\n// }, limit);\n// }\n// };\n//}\n\n/**\n * Split a class name into an array of class names.\n *\n * @param className - The class name to split.\n *\n * @returns An array of class names.\n */\nexport function splitClass(className: string): Array {\n return className.split(\" \").filter((x) => x);\n}\n\nexport function getRealCoords(el: HTMLElement): {\n top: number;\n bottom: number;\n left: number;\n right: number;\n height: number;\n width: number;\n} {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nexport function eventCoordinates(data: DragEvent | PointerEvent) {\n return { x: data.clientX, y: data.clientY };\n}\n","import type { SetupNodeData, Node } from \"../../types\";\nimport type { AnimationsConfig } from \"./types\";\nimport { state, parents, isDragState } from \"../../index\";\n\nexport function animations(animationsConfig: Partial = {}) {\n const slideUp = [\n {\n transform: `translateY(${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideDown = [\n {\n transform: `translateY(-${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideLeft = [\n {\n transform: `translateX(${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n\n const slideRight = [\n {\n transform: `translateX(-${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n setup() {\n if (document.head.querySelector(\"[data-drag-and-drop]\")) return;\n },\n\n setupNodeRemap(data: SetupNodeData) {\n if (!isDragState(state)) return;\n\n const duration = animationsConfig.duration || 150;\n\n if (data.node.data.value === state.draggedNode.data.value) {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideRight, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n }\n\n return;\n }\n\n if (\n !state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.node.data.value)\n )\n return;\n\n const nodeRect = data.node.el.getBoundingClientRect();\n\n const nodeIndex = state.affectedNodes.findIndex(\n (x) => x.data.value === data.node.data.value\n );\n\n const draggedNodeIndex = state.draggedNode.data.index;\n\n const ascendingDirection = draggedNodeIndex >= state.targetIndex;\n\n let adjacentNode;\n\n if (ascendingDirection) {\n adjacentNode = state.affectedNodes[nodeIndex + 1]\n ? state.affectedNodes[nodeIndex + 1]\n : state.affectedNodes[nodeIndex - 1];\n } else {\n adjacentNode = state.affectedNodes[nodeIndex - 1]\n ? state.affectedNodes[nodeIndex - 1]\n : state.affectedNodes[nodeIndex + 1];\n }\n\n if (adjacentNode) {\n const xDiff = Math.abs(\n nodeRect.x - adjacentNode.el.getBoundingClientRect().x\n );\n\n const yDiff = Math.abs(\n nodeRect.y - adjacentNode.el.getBoundingClientRect().y\n );\n\n if (xDiff > yDiff && ascendingDirection) {\n animate(data.node.el, slideRight, duration);\n } else if (xDiff > yDiff && !ascendingDirection) {\n animate(data.node.el, slideLeft, duration);\n }\n } else {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideRight, duration);\n\n break;\n }\n }\n },\n };\n };\n}\n\nfunction animate(\n node: Node,\n animation: Keyframe[] | PropertyIndexedKeyframes,\n duration: number\n) {\n if (!state) return;\n\n state.preventEnter = true;\n\n node.animate(animation, {\n duration: duration,\n easing: \"ease-in-out\",\n });\n\n setTimeout(() => {\n if (!state) return;\n\n state.preventEnter = false;\n }, duration);\n}\n","import type { InsertConfig } from \"../../types\";\nimport type {\n DragState,\n NodeDragEventData,\n NodeRecord,\n ParentEventData,\n PointeroverParentEvent,\n ParentRecord,\n SynthDragState,\n InsertEvent,\n BaseDragState,\n InsertState,\n Coordinates,\n} from \"../../types\";\n\nimport {\n parents,\n parentValues,\n setParentValues,\n state,\n addParentClass,\n isDragState,\n isSynthDragState,\n removeClass,\n addEvents,\n remapNodes,\n} from \"../../index\";\n\nimport { eq, pd, eventCoordinates } from \"../../utils\";\n\nexport const insertState: InsertState = {\n draggedOverNodes: [],\n draggedOverParent: null,\n targetIndex: 0,\n ascending: false,\n insertPoint: null,\n dragging: false,\n};\n\nlet documentController: AbortController | undefined;\n\n// WIP: This is a work in progress and not yet fully functional\nexport function insert(insertConfig: InsertConfig) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const insertParentConfig = {\n ...parentData.config,\n insertConfig,\n };\n\n return {\n teardown() {\n if (parentData.abortControllers.root) {\n parentData.abortControllers.root.abort();\n }\n },\n setup() {\n insertParentConfig.handleNodeDragover =\n insertConfig.handleNodeDragover || handleNodeDragover;\n\n insertParentConfig.handleParentPointerover =\n insertConfig.handleParentPointerover || handleParentPointerover;\n\n insertParentConfig.handleNodePointerover =\n insertConfig.handleNodePointerover || handleParentPointerover;\n\n insertParentConfig.handleParentDragover =\n insertConfig.handleParentDragover || handleParentDragover;\n\n const originalHandleend = insertParentConfig.handleEnd;\n\n insertParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: checkPosition,\n pointermove: checkPosition,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = insertParentConfig;\n\n state.on(\"dragStarted\", () => {\n defineRanges(parent);\n });\n\n state.on(\"scrollStarted\", () => {\n if (insertState.insertPoint)\n insertState.insertPoint.el.style.display = \"none\";\n });\n\n state.on(\"scrollEnded\", () => {\n defineRanges(parent);\n });\n\n const firstScrollableParent = findFirstOverflowingParent(parent);\n\n if (firstScrollableParent) {\n firstScrollableParent.addEventListener(\n \"scroll\",\n defineRanges.bind(null, parent)\n );\n }\n\n window.addEventListener(\"resize\", defineRanges.bind(null, parent));\n },\n };\n };\n}\n\nfunction findFirstOverflowingParent(element: HTMLElement): HTMLElement | null {\n let parent = element.parentElement;\n\n while (parent) {\n const { overflow, overflowY, overflowX } = getComputedStyle(parent);\n\n // Check if the overflow property is set to scroll, auto, or hidden (anything other than visible)\n const isOverflowSet =\n overflow !== \"visible\" ||\n overflowY !== \"visible\" ||\n overflowX !== \"visible\";\n\n // Check if there is actual overflow (scrolling)\n const isOverflowing =\n parent.scrollHeight > parent.clientHeight ||\n parent.scrollWidth > parent.clientWidth;\n const hasScrollPosition = parent.scrollTop > 0 || parent.scrollLeft > 0;\n\n if (isOverflowSet && (isOverflowing || hasScrollPosition)) {\n return parent;\n }\n\n parent = parent.parentElement;\n }\n\n return null; // No overflowing parent found\n}\n\nfunction checkPosition(e: DragEvent | PointerEvent) {\n if (!isDragState(state)) return;\n\n const el = document.elementFromPoint(e.clientX, e.clientY);\n\n if (!(el instanceof HTMLElement)) return;\n\n if (!parents.has(el)) {\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint?.el === el) return;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n if (insertState.draggedOverParent) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n\n state.currentParent = state.initialParent;\n }\n}\n\ninterface Range {\n x: [number, number];\n y: [number, number];\n vertical: boolean;\n}\n\nfunction createVerticalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean\n): Range {\n const center = nodeCoords.top + nodeCoords.height / 2;\n\n if (!otherCoords) {\n const offset = nodeCoords.height / 2 + 10;\n return {\n y: isAscending ? [center, center + offset] : [center - offset, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n }\n\n const otherEdge = isAscending ? otherCoords.top : otherCoords.bottom;\n const nodeEdge = isAscending ? nodeCoords.bottom : nodeCoords.top;\n const midpoint = nodeEdge + Math.abs(nodeEdge - otherEdge) / 2;\n\n return {\n y: isAscending ? [center, midpoint] : [midpoint, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n}\n\nfunction createHorizontalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean,\n lastInRow = false\n): Range {\n const center = nodeCoords.left + nodeCoords.width / 2;\n\n if (!otherCoords) {\n if (isAscending) {\n return {\n x: [center, center + nodeCoords.width],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [nodeCoords.left - 10, center],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n }\n\n if (isAscending && lastInRow) {\n return {\n x: [center, nodeCoords.right + 10],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n\n if (isAscending) {\n const nextNodeCenter = otherCoords.left + otherCoords.width / 2;\n return {\n x: [center, center + Math.abs(center - nextNodeCenter) / 2],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [\n otherCoords.right + Math.abs(otherCoords.right - nodeCoords.left) / 2,\n center,\n ],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n}\n\nfunction getRealCoords(el: HTMLElement): Coordinates {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nfunction defineRanges(parent: HTMLElement) {\n if (!isDragState(state)) return;\n\n const parentData = parents.get(parent);\n if (!parentData) return;\n\n const enabledNodes = parentData.enabledNodes;\n\n enabledNodes.forEach((node, index) => {\n node.data.range = {};\n\n const prevNode = enabledNodes[index - 1];\n const nextNode = enabledNodes[index + 1];\n const nodeCoords = getRealCoords(node.el);\n const prevNodeCoords = prevNode ? getRealCoords(prevNode.el) : undefined;\n const nextNodeCoords = nextNode ? getRealCoords(nextNode.el) : undefined;\n\n const aboveOrBelowPrevious =\n prevNodeCoords &&\n (nodeCoords.top > prevNodeCoords.bottom ||\n nodeCoords.bottom < prevNodeCoords.top);\n\n const aboveOrBelowAfter =\n nextNodeCoords &&\n (nodeCoords.top > nextNodeCoords.bottom ||\n nodeCoords.bottom < nextNodeCoords.top);\n\n const fullishWidth =\n parent.getBoundingClientRect().width * 0.8 < nodeCoords.width;\n\n if (fullishWidth) {\n node.data.range.ascending = createVerticalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createVerticalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowAfter && !aboveOrBelowPrevious) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (!aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowPrevious && !nextNodeCoords) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n undefined,\n true\n );\n } else if (aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n undefined,\n false\n );\n }\n });\n}\n\nexport function handleNodeDragover(data: NodeDragEventData) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n data.e.preventDefault();\n}\n\nfunction processParentDragEvent(\n e: DragEvent | PointerEvent,\n targetData: ParentEventData[\"targetData\"],\n state: DragState,\n isNativeDrag: boolean\n) {\n const config = targetData.parent.data.config;\n\n if (!isNativeDrag && config.nativeDrag) return;\n\n pd(e);\n\n if (isNativeDrag) pd(e);\n\n const { x, y } = eventCoordinates(e);\n\n // Calculate global coordinates\n const clientX = x;\n const clientY = y;\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n state.coordinates.x = clientX + scrollLeft;\n state.coordinates.y = clientY + scrollTop;\n\n const nestedParent = targetData.parent.data.nestedParent;\n\n let realTargetParent = targetData.parent;\n\n if (nestedParent) {\n const rect = nestedParent.el.getBoundingClientRect();\n\n if (state.coordinates.y > rect.top && state.coordinates.y < rect.bottom)\n realTargetParent = nestedParent;\n }\n\n if (realTargetParent.el === state.currentParent?.el) {\n moveBetween(realTargetParent, state);\n } else {\n moveOutside(realTargetParent, state);\n }\n\n state.currentParent = realTargetParent;\n}\n\nexport function handleParentDragover(\n data: ParentEventData,\n state: DragState\n) {\n processParentDragEvent(data.e as DragEvent, data.targetData, state, true);\n}\n\nexport function handleParentPointerover(data: PointeroverParentEvent) {\n const { detail } = data;\n\n const { state, targetData } = detail;\n\n if (state.scrolling) return;\n\n processParentDragEvent(detail.e, targetData, state, false);\n}\n\nexport function moveBetween(data: ParentRecord, state: DragState) {\n if (data.data.config.sortable === false) return;\n\n if (\n data.el === insertState.draggedOverParent?.el &&\n insertState.draggedOverParent.data.getValues(data.el).length === 0\n ) {\n return;\n } else if (insertState.draggedOverParent?.el) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n insertState.draggedOverParent = null;\n }\n\n const foundRange = findClosest(data.data.enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n}\n\nfunction moveOutside(data: ParentRecord, state: DragState) {\n if (data.el === state.currentParent.el) return false;\n\n const targetConfig = data.data.config;\n\n if (state.draggedNode.el.contains(data.el)) return false;\n\n if (targetConfig.dropZone === false) return;\n\n const initialParentConfig = state.initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n data,\n state.initialParent,\n state.currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n const values = data.data.getValues(data.el);\n\n if (!values.length) {\n addParentClass([data.el], targetConfig.dropZoneClass);\n\n insertState.draggedOverParent = data as ParentRecord;\n\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n } else {\n removeClass([state.currentParent.el], targetConfig.dropZoneClass);\n\n const enabledNodes = data.data.enabledNodes;\n\n const foundRange = findClosest(enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n }\n}\n\nfunction findClosest(enabledNodes: NodeRecord[], state: DragState) {\n let foundRange: [NodeRecord, string] | null = null;\n\n for (let x = 0; x < enabledNodes.length; x++) {\n if (!state || !enabledNodes[x].data.range) continue;\n\n if (enabledNodes[x].data.range!.ascending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.ascending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.ascending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.ascending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.ascending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"ascending\"];\n\n return foundRange;\n }\n }\n\n if (enabledNodes[x].data.range!.descending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.descending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.descending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.descending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.descending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"descending\"];\n\n return foundRange;\n }\n }\n }\n}\n\nfunction createInsertPoint(\n parent: ParentRecord,\n insertState: InsertState\n) {\n const insertPoint = parent.data.config.insertConfig?.insertPoint({\n el: parent.el,\n data: parent.data,\n });\n\n if (!insertPoint)\n throw new Error(\"Insert point not found\", { cause: parent });\n\n insertState.insertPoint = {\n parent,\n el: insertPoint,\n };\n\n document.body.appendChild(insertPoint);\n\n Object.assign(insertPoint, {\n position: \"absolute\",\n display: \"none\",\n });\n}\n\nfunction removeInsertPoint(insertState: InsertState) {\n if (insertState.insertPoint?.el) insertState.insertPoint.el.remove();\n\n insertState.insertPoint = null;\n}\n\nfunction positioninsertPoint(\n parent: ParentRecord,\n position: { x: number[]; y: number[]; vertical: boolean },\n ascending: boolean,\n node: NodeRecord,\n insertState: InsertState\n) {\n if (insertState.insertPoint?.el !== parent.el) {\n removeInsertPoint(insertState);\n\n createInsertPoint(parent, insertState);\n }\n\n insertState.draggedOverNodes = [node];\n\n if (!insertState.insertPoint) return;\n\n if (position.vertical) {\n const topPosition =\n position.y[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().height / 2;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${topPosition}px`,\n left: `${position.x[0]}px`,\n right: `${position.x[1]}px`,\n height: \"4px\",\n width: `${position.x[1] - position.x[0]}px`,\n });\n } else {\n const leftPosition =\n position.x[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().width / 2;\n insertState.insertPoint.el.style.left = `${leftPosition}px`;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${position.y[0]}px`,\n bottom: `${position.y[1]}px`,\n width: \"4px\",\n height: `${position.y[1] - position.y[0]}px`,\n });\n }\n\n insertState.targetIndex = node.data.index;\n\n insertState.ascending = ascending;\n\n insertState.insertPoint.el.style.display = \"block\";\n}\n\nexport function handleParentDrop(_data: NodeDragEventData) {}\n\n/**\n * Performs the actual insertion of the dragged nodes into the target parent.\n *\n * @param state - The current drag state.\n */\nexport function handleEnd(\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isDragState(state)) return;\n\n const insertPoint = insertState.insertPoint;\n\n if (!insertState.draggedOverParent) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const transferred = state.initialParent.el !== state.currentParent.el;\n\n remapNodes(state.initialParent.el);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const enabledNodes = [...state.initialParent.data.enabledNodes];\n\n const originalIndex = state.draggedNodes[0].data.index;\n\n const targetIndex = insertState.targetIndex;\n\n if (\n !transferred &&\n insertState.draggedOverNodes[0] &&\n insertState.draggedOverNodes[0].el !== state.draggedNodes[0].el\n ) {\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n let index = insertState.draggedOverNodes[0].data.index;\n\n if (\n insertState.targetIndex > state.draggedNodes[0].data.index &&\n !insertState.ascending\n ) {\n index--;\n } else if (\n insertState.targetIndex < state.draggedNodes[0].data.index &&\n insertState.ascending\n ) {\n index++;\n }\n\n newParentValues.splice(index, 0, ...draggedValues);\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n if (state.initialParent.data.config.onSort) {\n const sortEventData = {\n parent: {\n el: state.initialParent.el,\n data: state.initialParent.data,\n } as ParentRecord,\n previousValues: [...draggedParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...state.initialParent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes,\n previousPosition: originalIndex,\n position: index,\n state: state as DragState,\n };\n\n state.initialParent.data.config.onSort(sortEventData);\n }\n } else if (transferred && insertState.draggedOverNodes.length) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n // For the time being, we will not be remoing the value of the original dragged parent.\n let index = insertState.draggedOverNodes[0].data.index || 0;\n\n if (insertState.ascending) index++;\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n targetIndex: index,\n })\n : draggedValues;\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n if (state.currentParent.el.contains(state.initialParent.el)) {\n // Update initial parent values first\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n // Now get the target parent values.\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n } else {\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n }\n\n const data = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n targetIndex,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.onTransfer)\n state.initialParent.data.config.onTransfer(data);\n if (state.currentParent.data.config.onTransfer)\n state.currentParent.data.config.onTransfer(data);\n }\n } else if (insertState.draggedOverParent) {\n if (state.currentParent.el.contains(state.initialParent.el)) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n } else {\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n }\n\n const data: InsertEvent = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.insertConfig?.insertEvent)\n state.initialParent.data.config.insertConfig.insertEvent(data);\n if (state.currentParent.data.config.insertConfig?.insertEvent)\n state.currentParent.data.config.insertConfig.insertEvent(data);\n\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n const dropZoneClass = isSynthDragState(state)\n ? state.initialParent.data.config.synthDropZoneClass\n : state.initialParent.data.config.dropZoneClass;\n\n removeClass(\n insertState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const dragPlaceholderClass =\n state.initialParent.data.config.dragPlaceholderClass;\n\n removeClass(\n state.draggedNodes.map((node) => node.el),\n dragPlaceholderClass\n );\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n}\n","import type {\n DropSwapConfig,\n NodeDragEventData,\n DragState,\n SynthDragState,\n NodeRecord,\n PointeroverNodeEvent,\n ParentDragEventData,\n PointeroverParentEvent,\n DropSwapState,\n} from \"../../types\";\nimport {\n parents,\n parentValues,\n setParentValues,\n addNodeClass,\n isSynthDragState,\n removeClass,\n addClass,\n state,\n addEvents,\n isDragState,\n} from \"../../index\";\n\nexport const dropSwapState: DropSwapState = {\n draggedOverNodes: Array>(),\n initialDraggedIndex: undefined,\n transferred: false,\n dragging: false,\n};\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\nexport function dropOrSwap(dropSwapConfig: DropSwapConfig = {}) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const dropSwapParentConfig = {\n ...parentData.config,\n dropSwapConfig,\n };\n\n return {\n setup() {\n dropSwapParentConfig.handleNodeDragover =\n dropSwapConfig.handleNodeDragover || handleNodeDragover;\n\n dropSwapParentConfig.handleParentDragover =\n dropSwapConfig.handleParentDragover || handleParentDragover;\n\n dropSwapParentConfig.handleNodePointerover =\n dropSwapConfig.handleNodePointerover || handleNodePointerover;\n\n dropSwapParentConfig.handleParentPointerover =\n dropSwapConfig.handleParentPointerover || handeParentPointerover;\n\n const originalHandleend = dropSwapParentConfig.handleEnd;\n\n dropSwapParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: rootDragover,\n handleRootPointerover: rootPointerover,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = dropSwapParentConfig;\n },\n };\n };\n}\n\nfunction rootDragover(_e: DragEvent) {\n if (!isDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.dropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction rootPointerover(_e: CustomEvent) {\n if (!isSynthDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.synthDropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction updateDraggedOverNodes(\n data: PointeroverNodeEvent | NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const targetData =\n \"detail\" in data ? data.detail.targetData : data.targetData;\n\n const config = targetData.parent.data.config;\n\n const dropZoneClass = isSynthDragState(state)\n ? config.synthDropZoneClass\n : config.dropZoneClass;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const enabledNodes = targetData.parent.data.enabledNodes;\n\n if (!enabledNodes) return;\n\n dropSwapState.draggedOverNodes = enabledNodes.slice(\n targetData.node.data.index,\n targetData.node.data.index + state.draggedNodes.length\n );\n\n addNodeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass,\n true\n );\n\n state.currentTargetValue = targetData.node.data.value;\n\n state.currentParent = targetData.parent;\n\n addClass(\n state.currentParent.el,\n isSynthDragState(state)\n ? config.synthDropZoneParentClass\n : config.dropZoneParentClass,\n state.currentParent.data,\n true\n );\n}\n\nfunction handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n updateDraggedOverNodes(data, state);\n}\n\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n const currentConfig = state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.dropZoneClass\n );\n\n removeClass([state.currentParent.el], currentConfig.dropZoneParentClass);\n\n const config = data.targetData.parent.data.config;\n\n addClass(\n data.targetData.parent.el,\n config.dropZoneParentClass,\n data.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n state.currentParent = data.targetData.parent;\n}\n\nexport function handeParentPointerover(data: PointeroverParentEvent) {\n const currentConfig = data.detail.state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.synthDropZoneClass\n );\n\n removeClass(\n [data.detail.state.currentParent.el],\n currentConfig.synthDropZoneParentClass\n );\n\n const config = data.detail.targetData.parent.data.config;\n\n addClass(\n data.detail.targetData.parent.el,\n config.synthDropZoneParentClass,\n data.detail.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n data.detail.state.currentParent = data.detail.targetData.parent;\n}\n\nfunction handleNodePointerover(data: PointeroverNodeEvent) {\n if (!isSynthDragState(data.detail.state)) return;\n\n updateDraggedOverNodes(data, data.detail.state);\n}\n\nfunction swapElements(\n arr1: T[],\n arr2: T[] | null,\n index1: number | number[],\n index2: number\n): T[] | [T[], T[]] {\n const indices1 = Array.isArray(index1) ? index1 : [index1];\n\n if (arr2 === null) {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr1[index2];\n\n arr1.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return arr1.filter((el) => el !== undefined);\n } else {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr2[index2];\n\n arr2.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return [arr1.filter((el) => el !== undefined), arr2];\n }\n}\n\nfunction handleEnd(state: DragState | SynthDragState) {\n const isSynth = isSynthDragState(state);\n\n removeClass(\n [state.currentParent.el],\n isSynth\n ? state.currentParent.data.config.synthDropZoneParentClass\n : state.currentParent.data.config.dropZoneParentClass\n );\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n isSynth\n ? state.currentParent.data.config.synthDropZoneClass\n : state.currentParent.data.config.dropZoneClass\n );\n\n const values = parentValues(state.currentParent.el, state.currentParent.data);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const newValues = values.filter((x) => !draggedValues.includes(x));\n\n const targetIndex = dropSwapState.draggedOverNodes[0]?.data.index;\n\n const draggedIndex = state.draggedNodes[0].data.index;\n\n const initialParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n if (targetIndex === undefined) {\n if (state.initialParent.el === state.currentParent.el) return;\n\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n values.concat(draggedValues)\n );\n\n return;\n }\n\n let swap = false;\n\n const shouldSwap = state.initialParent.data.config.dropSwapConfig?.shouldSwap;\n\n if (shouldSwap)\n swap = shouldSwap({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: dropSwapState.draggedOverNodes as NodeRecord[],\n state,\n });\n\n if (state.initialParent.el === state.currentParent.el) {\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n swap ? swapElements(values, null, draggedIndex, targetIndex) : newValues\n );\n } else {\n if (swap) {\n const res = swapElements(\n initialParentValues,\n newValues,\n state.initialIndex,\n targetIndex\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n res[0] as T[]\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n res[1] as T[]\n );\n } else {\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n newValues\n );\n }\n }\n}\n","import type {\n DNDPlugin,\n DragAndDrop,\n DragState,\n DragStateProps,\n Node,\n NodeData,\n NodeDragEventData,\n NodeEventData,\n NodePointerEventData,\n NodeRecord,\n NodeTargetData,\n NodesData,\n ParentConfig,\n ParentData,\n ParentEventData,\n ParentTargetData,\n ParentsData,\n PointeroverNodeEvent,\n PointeroverParentEvent,\n SetupNodeData,\n TearDownNodeData,\n BaseDragState,\n SynthDragState,\n ParentKeydownEventData,\n SynthDragStateProps,\n ParentRecord,\n EventHandlers,\n NodeFromPoint,\n ParentFromPoint,\n ParentDragEventData,\n} from \"./types\";\n\nimport {\n pd,\n sp,\n on,\n emit,\n createEmitter,\n eq,\n splitClass,\n eventCoordinates,\n} from \"./utils\";\n\nexport * from \"./types\";\nexport { animations } from \"./plugins/animations\";\nexport { insert } from \"./plugins/insert\";\nexport { dropOrSwap } from \"./plugins/drop-or-swap\";\n\n/**\n * Check to see if code is running in a browser.\n */\nexport const isBrowser = typeof window !== \"undefined\";\n\n/**\n * Parents or \"lists\" are the containers that nodes or \"draggable items\" can be\n * dragged from and into.\n *\n * @type {WeakMap>}\n */\nexport const parents: ParentsData = new WeakMap<\n HTMLElement,\n ParentData\n>();\n\n/**\n * Nodes are the draggable items and the direct descendants of the parents.\n *\n * @type {WeakMap>}\n */\nexport const nodes: NodesData = new WeakMap>();\n\n/**\n * Function to check if touch support is enabled.\n *\n * @returns {boolean}\n */\nfunction checkTouchSupport() {\n if (!isBrowser) return false;\n\n return \"ontouchstart\" in window || navigator.maxTouchPoints > 0;\n}\n\n/**\n * The base drag state.\n *\n * @type {BaseDragState}\n */\nconst baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n currentTargetValue: undefined,\n on,\n emit,\n newActiveDescendant: undefined,\n originalZIndex: undefined,\n pointerSelection: false,\n preventEnter: false,\n rootUserSelect: undefined,\n nodePointerdown: undefined,\n longPress: false,\n scrolling: false,\n longPressTimeout: undefined,\n remapJustFinished: false,\n selectedNodes: [],\n selectedParent: undefined,\n preventSynthDrag: false,\n pointerDown: undefined,\n};\n\n/**\n * The state of the drag and drop.\n *\n * @type {BaseDragState}\n */\nexport let state: BaseDragState = baseDragState;\n\n/**\n * Variable to check if the drop has occurred.\n */\nlet dropped = false;\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\n/**\n * Abort controller for the window.\n */\nlet windowController: AbortController | undefined;\n\n/**\n * Timeout for the scroll.\n */\nlet scrollTimeout: ReturnType;\n\n/**\n * Variable to check if the device is touch.\n */\nlet touchDevice: boolean = false;\n\nexport function resetState() {\n const baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n on,\n emit,\n currentTargetValue: undefined,\n originalZIndex: undefined,\n pointerId: undefined,\n preventEnter: false,\n remapJustFinished: false,\n selectedNodes: [],\n nodePointerdown: undefined,\n rootUserSelect: undefined,\n preventSynthDrag: false,\n scrolling: false,\n selectedParent: undefined,\n pointerSelection: false,\n synthScrollDirection: undefined,\n draggedNodeDisplay: undefined,\n synthDragScrolling: false,\n longPress: false,\n pointerDown: undefined,\n longPressTimeout: undefined,\n };\n\n state = { ...baseDragState } as BaseDragState;\n}\n\n/**\n * @param {DragStateProps} dragStateProps - Attributes to update state with.\n *\n * @mutation - Updates state with node values.\n *\n * @returns void\n */\nexport function setDragState(\n dragStateProps: (SynthDragStateProps & DragStateProps) | DragStateProps\n): DragState | SynthDragState {\n Object.assign(state, dragStateProps);\n\n dragStateProps.initialParent.data.emit(\"dragStarted\", state);\n\n dropped = false;\n\n state.emit(\"dragStarted\", state);\n\n return state as DragState | SynthDragState;\n}\n\n/**\n *\n */\nfunction handleRootPointerdown(_e: PointerEvent) {\n if (state.activeState) setActive(state.activeState.parent, undefined, state);\n\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = state.activeState = undefined;\n}\n\nfunction handleRootPointerup(e: PointerEvent) {\n pd(e);\n\n state.pointerDown = undefined;\n\n if (!isSynthDragState(state)) return;\n\n const config = state.currentParent.data.config;\n\n if (isSynthDragState(state)) config.handleEnd(state);\n}\n\n/**\n * Handles the keydown event on the root element.\n *\n * @param {KeyboardEvent} e - The keyboard event.\n */\nfunction handleRootKeydown(e: KeyboardEvent) {\n if (e.key === \"Escape\") {\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n if (state.activeState)\n setActive(state.activeState.parent, undefined, state);\n\n state.selectedState = state.activeState = undefined;\n }\n}\n\nfunction handleRootDrop(_e: DragEvent) {}\n\nexport function copyNodeStyle(\n sourceNode: HTMLElement,\n targetNode: HTMLElement,\n omitKeys = false\n) {\n const computedStyle = window.getComputedStyle(sourceNode);\n\n const omittedKeys = [\n \"position\",\n \"z-index\",\n \"top\",\n \"left\",\n \"x\",\n \"pointer-events\",\n \"y\",\n \"transform-origin\",\n \"filter\",\n \"-webkit-text-fill-color\",\n ];\n\n for (const key of Array.from(computedStyle)) {\n if (omitKeys === false && key && omittedKeys.includes(key)) continue;\n\n targetNode.style.setProperty(\n key,\n computedStyle.getPropertyValue(key),\n computedStyle.getPropertyPriority(key)\n );\n }\n\n for (const child of Array.from(sourceNode.children)) {\n if (!isNode(child)) continue;\n\n const targetChild = targetNode.children[\n Array.from(sourceNode.children).indexOf(child)\n ] as Node;\n\n copyNodeStyle(child, targetChild, omitKeys);\n }\n}\n\n/**\n * If we are currently dragging, then let's prevent default on dragover to avoid\n * the default behavior of the browser on drop.\n */\nfunction handleRootDragover(e: DragEvent) {\n if (!isDragState(state)) return;\n\n pd(e);\n}\n\nfunction handleRootPointermove(e: PointerEvent) {\n if (!state.pointerDown) return;\n\n //pd(e);\n\n const config = state.pointerDown.parent.data.config;\n\n if (\n !isSynthDragState(state) &&\n (touchDevice || (!touchDevice && !config.nativeDrag))\n ) {\n if (config.longPress && !state.longPress) {\n clearTimeout(state.longPressTimeout);\n\n state.longPress = false;\n\n return;\n }\n\n const nodes = config.draggedNodes(state.pointerDown);\n\n config.dragstartClasses(state.pointerDown.node, nodes, config, true);\n\n const synthDragState = initSynthDrag(\n state.pointerDown.node,\n state.pointerDown.parent,\n e,\n state,\n nodes\n );\n\n state.rootUserSelect = window.getComputedStyle(\n document.documentElement\n ).userSelect;\n\n document.body.style.userSelect = \"none\";\n\n synthMove(e, synthDragState);\n } else if (isSynthDragState(state)) {\n synthMove(e, state);\n }\n}\n\n/**\n * Initializes the drag and drop functionality for a given parent.\n *\n * @param {DragAndDrop} dragAndDrop - The drag and drop configuration.\n *\n * @returns void\n */\nexport function dragAndDrop({\n parent,\n getValues,\n setValues,\n config = {},\n}: DragAndDrop): void {\n if (!isBrowser) return;\n\n touchDevice = checkTouchSupport();\n\n if (!documentController) {\n documentController = addEvents(document, {\n dragover: handleRootDragover,\n pointerdown: handleRootPointerdown,\n pointerup: handleRootPointerup,\n keydown: handleRootKeydown,\n drop: handleRootDrop,\n pointermove: handleRootPointermove,\n pointercancel: nodeEventData(config.handlePointercancel),\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n });\n\n const liveRegion = document.createElement(\"div\");\n\n setAttrs(liveRegion, {\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-dnd-live-region\": \"true\",\n });\n\n Object.assign(liveRegion.style, {\n position: \"absolute\",\n top: \"0px\",\n left: \"-9999px\",\n width: \"1px\",\n height: \"1px\",\n padding: \"0\",\n overflow: \"hidden\",\n clip: \"rect(0, 0, 0, 0)\",\n whiteSpace: \"nowrap\",\n border: \"0\",\n });\n\n document.body.appendChild(liveRegion);\n }\n\n if (!windowController)\n windowController = addEvents(window, {\n resize: () => {\n touchDevice = checkTouchSupport();\n },\n });\n\n tearDown(parent);\n\n const [emit, on] = createEmitter();\n\n const parentData: ParentData = {\n getValues,\n setValues,\n config: {\n dragDropEffect: config.dragDropEffect ?? \"move\",\n dragEffectAllowed: config.dragEffectAllowed ?? \"move\",\n draggedNodes,\n dragstartClasses,\n deepCopyStyles: config.deepCopyStyles ?? false,\n handleNodeKeydown,\n handleParentKeydown,\n handleDragstart,\n handleNodeDragover,\n handleParentDragover,\n handleNodeDrop,\n handlePointercancel,\n handleEnd,\n handleDragend,\n handleParentFocus,\n handleNodePointerup,\n handleNodePointerover,\n handleParentPointerover,\n handleParentScroll,\n handleNodePointerdown,\n handleNodeDragenter,\n handleNodeDragleave,\n handleParentDrop,\n multiDrag: config.multiDrag ?? false,\n nativeDrag: config.nativeDrag ?? true,\n performSort,\n performTransfer,\n root: config.root ?? document,\n setupNode,\n setupNodeRemap,\n reapplyDragClasses,\n tearDownNode,\n tearDownNodeRemap,\n remapFinished,\n threshold: {\n horizontal: 0,\n vertical: 0,\n },\n ...config,\n },\n enabledNodes: [],\n abortControllers: {},\n privateClasses: [],\n on,\n emit,\n };\n\n const nodesObserver = new MutationObserver(nodesMutated);\n\n nodesObserver.observe(parent, { childList: true });\n\n parents.set(parent, parentData);\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.setup?.();\n });\n\n setup(parent, parentData);\n\n remapNodes(parent, true);\n}\n\nexport function dragStateProps(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent | DragEvent,\n draggedNodes: Array>,\n offsetX?: number,\n offsetY?: number\n): DragStateProps {\n const { x, y } = eventCoordinates(e);\n\n const rect = node.el.getBoundingClientRect();\n\n return {\n affectedNodes: [],\n ascendingDirection: false,\n clonedDraggedEls: [],\n coordinates: {\n x,\n y,\n },\n draggedNode: {\n el: node.el,\n data: node.data,\n },\n draggedNodes,\n incomingDirection: undefined,\n initialIndex: node.data.index,\n initialParent: {\n el: parent.el,\n data: parent.data,\n },\n currentParent: {\n el: parent.el,\n data: parent.data,\n },\n longPress: parent.data.config.longPress ?? false,\n longPressTimeout: undefined,\n currentTargetValue: node.data.value,\n scrollEls: [],\n // Need to account for if the explicity offset is positive or negative\n startLeft: offsetX ? offsetX : x - rect.left,\n startTop: offsetY ? offsetY : y - rect.top,\n targetIndex: node.data.index,\n transferred: false,\n };\n}\n\nexport function performSort({\n parent,\n draggedNodes,\n targetNodes,\n}: {\n parent: ParentRecord;\n draggedNodes: Array>;\n targetNodes: Array>;\n}) {\n remapNodes(parent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const targetParentValues = parentValues(parent.el, parent.data);\n\n const originalIndex = draggedNodes[0].data.index;\n\n const enabledNodes = [...parent.data.enabledNodes];\n\n const newParentValues = [\n ...targetParentValues.filter((x) => !draggedValues.some((y) => eq(x, y))),\n ];\n newParentValues.splice(targetNodes[0].data.index, 0, ...draggedValues);\n\n if (\"draggedNode\" in state)\n state.currentTargetValue = targetNodes[0].data.value;\n\n setParentValues(parent.el, parent.data, [...newParentValues]);\n\n if (parent.data.config.onSort)\n parent.data.config.onSort({\n parent: {\n el: parent.el,\n data: parent.data,\n } as ParentRecord,\n previousValues: [...targetParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...parent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: draggedNodes,\n previousPosition: originalIndex,\n position: targetNodes[0].data.index,\n targetNodes,\n state,\n });\n}\n\n/**\n * This function sets the active node as well as removing any classes or\n * attribute set.\n *\n * @param {ParentEventData} data - The parent event data.\n * @param {NodeRecord} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction setActive(\n parent: ParentRecord,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState\n) {\n const activeDescendantClass = parent.data.config.activeDescendantClass;\n\n if (state.activeState) {\n {\n removeClass([state.activeState.node.el], activeDescendantClass);\n\n if (state.activeState.parent.el !== parent.el)\n state.activeState.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n }\n }\n\n if (!newActiveNode) {\n state.activeState?.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n\n state.activeState = undefined;\n\n return;\n }\n\n state.activeState = {\n node: newActiveNode,\n parent,\n };\n\n addNodeClass([newActiveNode.el], activeDescendantClass);\n\n state.activeState.parent.el.setAttribute(\n \"aria-activedescendant\",\n state.activeState.node.el.id\n );\n}\n\n/**\n * This function deselects the nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {Array>} nodes - The nodes to deselect.\n * @param {ParentRecord} parent - The parent record.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction deselect(\n nodes: Array>,\n parent: ParentRecord,\n state: BaseDragState\n) {\n const selectedClass = parent.data.config.selectedClass;\n\n if (!state.selectedState) return;\n\n const iterativeNodes = Array.from(nodes);\n\n removeClass(\n nodes.map((x) => x.el),\n selectedClass\n );\n\n for (const node of iterativeNodes) {\n node.el.setAttribute(\"aria-selected\", \"false\");\n\n const index = state.selectedState.nodes.findIndex((x) => x.el === node.el);\n\n if (index === -1) continue;\n\n state.selectedState.nodes.splice(index, 1);\n }\n\n clearLiveRegion(parent);\n}\n\n/**\n * This function sets the selected nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {ParentRecord} parent - The parent record.\n * @param {Array>} selectedNodes - The nodes to select.\n * @param {NodeRecord | undefined} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n * @param {boolean} pointerdown - Whether the pointerdown event was triggered.\n */\nfunction setSelected(\n parent: ParentRecord,\n selectedNodes: Array>,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState,\n pointerdown = false\n) {\n state.pointerSelection = pointerdown;\n\n for (const node of selectedNodes) {\n node.el.setAttribute(\"aria-selected\", \"true\");\n\n addNodeClass([node.el], parent.data.config.selectedClass, true);\n }\n\n state.selectedState = {\n nodes: selectedNodes,\n parent,\n };\n\n const selectedItems = selectedNodes.map((x) =>\n x.el.getAttribute(\"aria-label\")\n );\n\n if (selectedItems.length === 0) {\n state.selectedState = undefined;\n\n clearLiveRegion(parent);\n\n return;\n }\n\n setActive(parent, newActiveNode, state);\n\n updateLiveRegion(\n parent,\n `${selectedItems.join(\n \", \"\n )} ready for dragging. Use arrow keys to navigate. Press enter to drop ${selectedItems.join(\n \", \"\n )}.`\n );\n}\n\nfunction updateLiveRegion(parent: ParentRecord, message: string) {\n const liveRegion = document.querySelector('[data-dnd-live-region=\"true\"]');\n\n if (!liveRegion) return;\n\n liveRegion.id = parent.el.id + \"-live-region\";\n\n liveRegion.textContent = message;\n}\n\nfunction clearLiveRegion(parent: ParentRecord) {\n const liveRegion = document.getElementById(parent.el.id + \"-live-region\");\n\n if (!liveRegion) return;\n\n liveRegion.textContent = \"\";\n}\n\nexport function handleParentFocus(\n data: ParentEventData,\n state: BaseDragState | DragState | SynthDragState\n) {\n const firstEnabledNode = data.targetData.parent.data.enabledNodes[0];\n\n if (!firstEnabledNode) return;\n\n if (\n state.selectedState &&\n state.selectedState.parent.el !== data.targetData.parent.el\n ) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n } else if (!state.selectedState) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n }\n}\n\n/**\n * Perform the transfer of the nodes.\n *\n * @param data - The transfer data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function performTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n initialIndex,\n targetNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n initialIndex: number;\n state: BaseDragState | DragState | SynthDragState;\n targetNodes: Array>;\n}) {\n remapNodes(initialParent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const currentParentValues = [\n ...parentValues(currentParent.el, currentParent.data).filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n const targetParentValues = parentValues(targetParent.el, targetParent.data);\n\n const reset =\n initialParent.el === targetParent.el &&\n targetParent.data.config.sortable === false;\n\n let targetIndex: number;\n\n if (targetNodes.length) {\n if (reset) {\n targetIndex = initialIndex;\n } else if (targetParent.data.config.sortable === false) {\n targetIndex = targetParent.data.enabledNodes.length;\n } else {\n targetIndex = targetNodes[0].data.index;\n }\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n } else {\n targetIndex = reset ? initialIndex : targetParent.data.enabledNodes.length;\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n }\n\n setParentValues(currentParent.el, currentParent.data, currentParentValues);\n\n setParentValues(targetParent.el, targetParent.data, targetParentValues);\n\n if (targetParent.data.config.onTransfer) {\n targetParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes,\n });\n }\n\n if (currentParent.data.config.onTransfer) {\n currentParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes: targetNodes ? targetNodes : [],\n });\n }\n}\n\n/**\n * Get the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns The values of the parent.\n */\nexport function parentValues(\n parent: HTMLElement,\n parentData: ParentData\n): Array {\n return [...parentData.getValues(parent)];\n}\n\n/**\n * Set the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n * @param values - The values to set.\n *\n * @returns void\n */\nexport function setParentValues(\n parent: HTMLElement,\n parentData: ParentData,\n values: Array\n): void {\n parentData.setValues(values, parent);\n}\n\n/**\n * Get the values of the dragged nodes.\n *\n * @param state - The drag state.\n *\n * @returns The values of the dragged nodes.\n */\nexport function dragValues(state: DragState): Array {\n return [...state.draggedNodes.map((x) => x.data.value)];\n}\n\n/**\n * Utility function to update parent config.\n *\n * @param parent - The parent element.\n * @param config - The config to update.\n *\n * @returns void\n */\nexport function updateConfig(\n parent: HTMLElement,\n config: Partial>\n) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parents.set(parent, {\n ...parentData,\n config: { ...parentData.config, ...config },\n });\n\n dragAndDrop({\n parent,\n getValues: parentData.getValues,\n setValues: parentData.setValues,\n config,\n });\n}\n\n/**\n * Handle the parent drop event.\n *\n * @param data - The parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDrop(\n data: ParentEventData,\n state: DragState\n) {\n sp(data.e);\n\n dropped = true;\n\n const handleEnd = state.initialParent.data.config.handleEnd;\n\n handleEnd(state);\n}\n\n/**\n * Tear down the parent.\n *\n * @param parent - The parent element.\n *\n * @returns void\n */\nexport function tearDown(parent: HTMLElement) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n if (parentData.abortControllers.mainParent)\n parentData.abortControllers.mainParent.abort();\n}\n\n/**\n * Check if the state is a drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a drag state.\n */\nexport function isDragState(\n state: BaseDragState\n): state is DragState | SynthDragState {\n return \"draggedNode\" in state && !!state.draggedNode;\n}\n\n/**\n * Check if the state is a synth drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a synth drag state.\n */\nexport function isSynthDragState(\n state: BaseDragState\n): state is SynthDragState {\n return \"synthDragging\" in state && !!state.synthDragging;\n}\n\n/**\n * Setup the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction setup(parent: HTMLElement, parentData: ParentData): void {\n parentData.abortControllers.mainParent = addEvents(parent, {\n keydown: parentEventData(parentData.config.handleParentKeydown),\n dragover: parentEventData(parentData.config.handleParentDragover),\n handleParentPointerover: parentData.config.handleParentPointerover,\n scroll: parentEventData(parentData.config.handleParentScroll),\n drop: parentEventData(parentData.config.handleParentDrop),\n hasNestedParent: (e: CustomEvent) => {\n const parent = parents.get(e.target as HTMLElement);\n\n if (!parent) return;\n\n parent.nestedParent = e.detail.parent;\n },\n focus: parentEventData(parentData.config.handleParentFocus),\n });\n\n if (\n parentData.config.externalDragHandle &&\n parentData.config.externalDragHandle.el &&\n parentData.config.externalDragHandle.callback\n ) {\n parentData.abortControllers.externalDragHandle = addEvents(\n parentData.config.externalDragHandle.el,\n {\n pointerdown: (_e: PointerEvent) => {\n if (\n !parentData.config.externalDragHandle ||\n !parentData.config.externalDragHandle.callback\n )\n return;\n\n const draggableItem = parentData.config.externalDragHandle.callback();\n\n if (!isNode(draggableItem)) {\n console.warn(\n \"No draggable item found from external drag handle callback\"\n );\n\n return;\n }\n\n const nodeData = nodes.get(draggableItem);\n\n if (!nodeData) return;\n\n const parentNode = draggableItem.parentNode;\n\n if (!(parentNode instanceof HTMLElement)) return;\n\n const parent = parents.get(parentNode);\n\n if (!parent) return;\n\n state.pointerDown = {\n parent: {\n el: parentNode,\n data: parent,\n },\n node: {\n el: draggableItem,\n data: nodeData,\n },\n };\n\n draggableItem.draggable = true;\n },\n }\n );\n }\n\n if (parent.id)\n setAttrs(parent, {\n role: \"listbox\",\n tabindex: \"0\",\n \"aria-multiselectable\": parentData.config.multiDrag ? \"true\" : \"false\",\n \"aria-activedescendant\": \"\",\n \"aria-describedby\": parent.id + \"-live-region\",\n });\n}\n\n/**\n * Set the attributes of the element.\n *\n * @param el - The element.\n * @param attrs - The attributes to set.\n *\n * @returns void\n */\nexport function setAttrs(el: HTMLElement, attrs: Record) {\n for (const key in attrs) el.setAttribute(key, attrs[key]);\n}\n\n/**\n * Setup the node.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNode(data: SetupNodeData) {\n const config = data.parent.data.config;\n\n data.node.data.abortControllers.mainNode = addEvents(data.node.el, {\n keydown: nodeEventData(config.handleNodeKeydown),\n dragstart: nodeEventData(config.handleDragstart),\n dragover: nodeEventData(config.handleNodeDragover),\n dragenter: nodeEventData(config.handleNodeDragenter),\n dragleave: nodeEventData(config.handleNodeDragleave),\n dragend: nodeEventData(config.handleDragend),\n drop: nodeEventData(config.handleNodeDrop),\n pointerup: nodeEventData(config.handleNodePointerup),\n pointercancel: nodeEventData(config.handlePointercancel),\n\n pointerdown: nodeEventData(config.handleNodePointerdown),\n handleNodePointerover: config.handleNodePointerover,\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n contextmenu: (e: Event) => {\n if (touchDevice) pd(e);\n },\n });\n\n data.node.el.setAttribute(\"role\", \"option\");\n\n data.node.el.setAttribute(\"aria-selected\", \"false\");\n\n config.reapplyDragClasses(data.node.el, data.parent.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNode?.(data);\n });\n}\n\n/**\n * Setup the node remap.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNodeRemap(data: SetupNodeData) {\n nodes.set(data.node.el, data.node.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNodeRemap?.(data);\n });\n}\n\n/**\n * Reapply the drag classes to the node.\n *\n * @param node - The node.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction reapplyDragClasses(node: Node, parentData: ParentData) {\n if (!isDragState(state)) return;\n\n const dropZoneClass = isSynthDragState(state)\n ? parentData.config.synthDropZoneClass\n : parentData.config.dropZoneClass;\n\n if (state.draggedNode.el !== node) return;\n\n addNodeClass([node], dropZoneClass, true);\n}\n\n/**\n * Tear down the node remap.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNodeRemap(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNodeRemap?.(data);\n });\n}\n\n/**\n * Tear down the node.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNode(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNode?.(data);\n });\n\n data.node.el.draggable = false;\n\n if (data.node.data?.abortControllers?.mainNode)\n data.node.data?.abortControllers?.mainNode.abort();\n}\n\n/**\n * Called when the nodes of a given parent element are mutated.\n *\n * @param mutationList - The list of mutations.\n *\n * @returns void\n *\n * @internal\n */\nfunction nodesMutated(mutationList: MutationRecord[]) {\n // TODO: This could be better, but using it as a way to ignore comments and text\n if (\n mutationList.length === 1 &&\n mutationList[0].addedNodes.length === 1 &&\n !(mutationList[0].addedNodes[0] instanceof HTMLElement)\n )\n return;\n\n const parentEl = mutationList[0].target;\n\n if (!(parentEl instanceof HTMLElement)) return;\n\n const allSelectedAndActiveNodes = document.querySelectorAll(\n `[aria-selected=\"true\"]`\n );\n\n const parentData = parents.get(parentEl);\n\n if (!parentData) return;\n\n for (let x = 0; x < allSelectedAndActiveNodes.length; x++) {\n const node = allSelectedAndActiveNodes[x];\n\n node.setAttribute(\"aria-selected\", \"false\");\n\n removeClass([node], parentData.config.selectedClass);\n }\n\n remapNodes(parentEl);\n}\n\n/**\n * Remaps the data of the parent element's children.\n *\n * @param parent - The parent element.\n *\n * @returns void\n *\n * @internal\n */\nexport function remapNodes(parent: HTMLElement, force?: boolean) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parentData.privateClasses = Array.from(parent.classList);\n\n const enabledNodes: Array = [];\n\n const config = parentData.config;\n\n for (let x = 0; x < parent.children.length; x++) {\n const node = parent.children[x];\n\n if (!isNode(node) || node.id === \"dnd-dragged-node-clone\") continue;\n\n const nodeData = nodes.get(node);\n\n // Only tear down the node if we have explicitly called dragAndDrop\n if (force || !nodeData)\n config.tearDownNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n if (config.disabled) continue;\n\n if (!config.draggable || (config.draggable && config.draggable(node))) {\n enabledNodes.push(node);\n }\n }\n\n if (\n enabledNodes.length !== parentData.getValues(parent).length &&\n !config.disabled\n ) {\n console.warn(\n \"The number of draggable items defined in the parent element does not match the number of values. This may cause unexpected behavior.\"\n );\n\n return;\n }\n\n const values = parentData.getValues(parent);\n\n const enabledNodeRecords: Array> = [];\n\n for (let x = 0; x < enabledNodes.length; x++) {\n const node = enabledNodes[x];\n\n const prevNodeData = nodes.get(node);\n\n if (config.draggableValue && !config.draggableValue(values[x])) continue;\n\n const nodeData = Object.assign(\n prevNodeData ?? {\n privateClasses: [],\n abortControllers: {},\n },\n {\n value: values[x],\n index: x,\n }\n );\n\n if (\n !isDragState(state) &&\n state.newActiveDescendant &&\n eq(state.newActiveDescendant.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n !isDragState(state) &&\n state.activeState &&\n eq(state.activeState.node.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n isDragState(state) &&\n eq(state.draggedNode.data.value, nodeData.value)\n ) {\n state.draggedNode.data = nodeData;\n\n state.draggedNode.el = node;\n\n const draggedNode = state.draggedNodes.find(\n (x) => x.data.value === nodeData.value\n );\n\n if (draggedNode) draggedNode.el = node;\n }\n\n enabledNodeRecords.push({\n el: node,\n data: nodeData,\n });\n\n if (force || !prevNodeData)\n config.setupNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n setupNodeRemap({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n }\n\n parents.set(parent, { ...parentData, enabledNodes: enabledNodeRecords });\n\n config.remapFinished(parentData);\n\n parentData.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.remapFinished?.();\n });\n}\n\n/**\n * Set the remap just finished flag.\n *\n * @returns void\n */\nexport function remapFinished() {\n state.remapJustFinished = true;\n\n if (\"draggedNode\" in state) state.affectedNodes = [];\n}\n\n/**\n * Validate the drag start.\n *\n * @param data - The node event data.\n *\n * @returns Whether the drag start is valid.\n */\nexport function validateDragstart(data: NodeEventData): boolean {\n return !!data.targetData.parent.data.config.nativeDrag;\n}\n\n/**\n * Get the dragged nodes.\n *\n * @param pointerDown - The pointer down data.\n *\n * @returns The dragged nodes.\n */\nfunction draggedNodes(pointerDown: {\n parent: ParentRecord;\n node: NodeRecord;\n}): Array> {\n if (!pointerDown.parent.data.config.multiDrag) {\n return [pointerDown.node];\n } else if (state.selectedState) {\n return [\n pointerDown.node,\n ...(state.selectedState?.nodes.filter(\n (x) => x.el !== pointerDown.node.el\n ) as Array>),\n ];\n }\n\n return [];\n}\n\n/**\n * Handle the parent scroll.\n *\n * @param data - The parent event data.\n *\n * @returns void\n */\nfunction handleParentScroll(_data: ParentEventData) {\n if (!isDragState(state)) return;\n\n state.emit(\"scrollStarted\", state);\n\n if (isSynthDragState(state)) return;\n\n state.preventEnter = true;\n\n if (scrollTimeout) clearTimeout(scrollTimeout);\n\n scrollTimeout = setTimeout(() => {\n state.preventEnter = false;\n\n state.emit(\"scrollEnded\", state);\n }, 100);\n}\n\n/**\n * Responsible for assigning dragstart classes to the dragged nodes.\n */\nexport function handleDragstart(\n data: NodeDragEventData,\n _state: BaseDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (\n !config.nativeDrag ||\n !validateDragstart(data) ||\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config,\n })\n ) {\n pd(data.e);\n\n return;\n }\n\n const nodes = config.draggedNodes({\n parent: data.targetData.parent,\n node: data.targetData.node,\n });\n\n config.dragstartClasses(data.targetData.node, nodes, config);\n\n const dragState = initDrag(data, nodes);\n\n if (config.onDragstart)\n config.onDragstart({\n parent: data.targetData.parent,\n values: parentValues(\n data.targetData.parent.el,\n data.targetData.parent.data\n ),\n draggedNode: dragState.draggedNode,\n draggedNodes: dragState.draggedNodes,\n position: dragState.initialIndex,\n state: dragState,\n });\n}\n\nexport function handleNodePointerdown(\n data: NodePointerEventData,\n state: BaseDragState\n) {\n sp(data.e);\n\n if (\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config: data.targetData.parent.data.config,\n })\n )\n return;\n\n state.pointerDown = {\n parent: data.targetData.parent,\n node: data.targetData.node,\n };\n\n data.targetData.node.el.draggable = true;\n\n handleLongPress(data, state, data.targetData.node);\n\n const parentData = data.targetData.parent.data;\n\n let selectedNodes = [data.targetData.node];\n\n const commandKey = data.e.ctrlKey || data.e.metaKey;\n const shiftKey = data.e.shiftKey;\n\n const targetNode = data.targetData.node;\n\n if (commandKey && parentData.config.multiDrag) {\n if (state.selectedState) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === targetNode.el\n );\n\n if (idx === -1) {\n selectedNodes = [...state.selectedState.nodes, targetNode];\n } else {\n selectedNodes = state.selectedState.nodes.filter(\n (x) => x.el !== targetNode.el\n );\n }\n } else {\n selectedNodes = [targetNode];\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (shiftKey && parentData.config.multiDrag) {\n const nodes = data.targetData.parent.data.enabledNodes;\n\n if (state.selectedState && state.activeState) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = undefined;\n\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n } else {\n const [minIndex, maxIndex] =\n state.activeState.node.data.index < data.targetData.node.data.index\n ? [\n state.activeState.node.data.index,\n data.targetData.node.data.index,\n ]\n : [\n data.targetData.node.data.index,\n state.activeState.node.data.index,\n ];\n\n selectedNodes = nodes.slice(minIndex, maxIndex + 1);\n }\n } else {\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (state.selectedState?.nodes?.length) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === data.targetData.node.el\n );\n\n if (idx === -1) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n } else if (parentData.config.multiDrag && touchDevice) {\n selectedNodes.push(...state.selectedState.nodes);\n } else {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n }\n } else {\n setSelected(\n data.targetData.parent,\n [data.targetData.node],\n data.targetData.node,\n state,\n true\n );\n }\n}\n\n/**\n * Add dragstart classes to the nodes.\n *\n * @param node - The node.\n * @param nodes - The nodes.\n * @param config - The parent config.\n * @param isSynth - Whether the drag is synthetic.\n *\n * @returns void\n */\nexport function dragstartClasses(\n _node: NodeRecord,\n nodes: Array>,\n config: ParentConfig,\n isSynth = false\n) {\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n setTimeout(() => {\n removeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDragPlaceholderClass : config.dragPlaceholderClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDropZoneClass : config.dropZoneClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.activeDescendantClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.selectedClass\n );\n });\n}\n\n/**\n * Initialize the drag state.\n *\n * @param data - The node drag event data.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The drag state.\n */\nexport function initDrag(\n data: NodeDragEventData,\n draggedNodes: Array>\n): DragState {\n sp(data.e);\n\n const dragState = setDragState(\n dragStateProps(\n data.targetData.node,\n data.targetData.parent,\n data.e,\n draggedNodes\n )\n );\n\n if (data.e.dataTransfer) {\n const config = data.targetData.parent.data.config;\n\n data.e.dataTransfer.dropEffect = config.dragDropEffect;\n\n data.e.dataTransfer.effectAllowed = config.dragEffectAllowed;\n\n let dragImage: HTMLElement | undefined;\n\n if (config.dragImage) {\n dragImage = config.dragImage(data, draggedNodes);\n } else {\n if (!config.multiDrag) {\n data.e.dataTransfer.setDragImage(\n data.targetData.node.el,\n data.e.offsetX,\n data.e.offsetY\n );\n\n const originalZIndex = data.targetData.node.el.style.zIndex;\n\n dragState.originalZIndex = originalZIndex;\n\n data.targetData.node.el.style.zIndex = \"9999\";\n\n return dragState;\n } else {\n const wrapper = document.createElement(\"div\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n clonedNode.style.pointerEvents = \"none\";\n\n clonedNode.id = node.el.id + \"-clone\";\n\n wrapper.append(clonedNode);\n }\n\n const { width } = draggedNodes[0].el.getBoundingClientRect();\n\n Object.assign(wrapper.style, {\n display: \"flex\",\n flexDirection: \"column\",\n width: `${width}px`,\n position: \"absolute\",\n pointerEvents: \"none\",\n zIndex: \"9999\",\n left: \"-9999px\",\n });\n\n dragImage = wrapper;\n }\n\n document.body.appendChild(dragImage);\n }\n\n data.e.dataTransfer.setDragImage(dragImage, data.e.offsetX, data.e.offsetY);\n\n setTimeout(() => {\n dragImage?.remove();\n });\n }\n\n return dragState;\n}\n\nexport function validateDragHandle({\n x,\n y,\n node,\n config,\n}: {\n x: number;\n y: number;\n node: NodeRecord;\n config: ParentConfig;\n}): boolean {\n if (config.externalDragHandle) return false;\n\n if (!config.dragHandle) return true;\n\n const dragHandles = node.el.querySelectorAll(config.dragHandle);\n\n if (!dragHandles) return false;\n\n const elFromPoint = config.root.elementFromPoint(x, y);\n\n if (!elFromPoint) return false;\n\n for (const handle of Array.from(dragHandles))\n if (elFromPoint === handle || handle.contains(elFromPoint)) return true;\n\n return false;\n}\n\nexport function handleClickNode(_data: NodeEventData) {}\n\nexport function handleClickParent(_data: ParentEventData) {}\n\nexport function handleNodeKeydown(_data: NodeEventData) {}\n\nexport function handleParentKeydown(\n data: ParentKeydownEventData,\n state: BaseDragState\n) {\n const activeDescendant = state.activeState?.node;\n\n if (!activeDescendant) return;\n\n const parentData = data.targetData.parent.data;\n\n const enabledNodes = parentData.enabledNodes;\n\n if (!(data.e.target instanceof HTMLElement)) return;\n const index = enabledNodes.findIndex((x) => x.el === activeDescendant.el);\n\n if (index === -1) return;\n\n if (\n [\"ArrowDown\", \"ArrowUp\", \"ArrowRight\", \"ArrowLeft\"].includes(data.e.key)\n ) {\n pd(data.e);\n\n const nextIndex =\n data.e.key === \"ArrowDown\" || data.e.key === \"ArrowRight\"\n ? index + 1\n : index - 1;\n\n if (nextIndex < 0 || nextIndex >= enabledNodes.length) return;\n\n const nextNode = enabledNodes[nextIndex];\n\n setActive(data.targetData.parent, nextNode, state);\n } else if (data.e.key === \" \") {\n pd(data.e);\n\n state.selectedState && state.selectedState.nodes.includes(activeDescendant)\n ? setSelected(\n data.targetData.parent,\n state.selectedState.nodes.filter((x) => x.el !== activeDescendant.el),\n activeDescendant,\n state\n )\n : setSelected(\n data.targetData.parent,\n [activeDescendant],\n activeDescendant,\n state\n );\n } else if (data.e.key === \"Enter\" && state.selectedState) {\n if (\n state.selectedState.parent.el === data.targetData.parent.el &&\n state.activeState\n ) {\n if (state.selectedState.nodes[0].el === state.activeState.node.el) {\n updateLiveRegion(data.targetData.parent, \"Cannot drop item on itself\");\n\n return;\n }\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n parentData.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.selectedState.nodes,\n targetNodes: [state.activeState.node],\n });\n\n deselect([], data.targetData.parent, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n } else if (\n state.activeState &&\n state.selectedState.parent.el !== data.targetData.parent.el &&\n validateTransfer({\n currentParent: data.targetData.parent,\n targetParent: state.selectedState.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n state,\n })\n ) {\n parentData.config.performTransfer({\n currentParent: state.selectedState.parent,\n targetParent: data.targetData.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n initialIndex: state.selectedState.nodes[0].data.index,\n state,\n targetNodes: [state.activeState.node],\n });\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n setSelected(data.targetData.parent, [], undefined, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n }\n }\n}\n\n/**\n * Prevent the sort on scroll.\n *\n * @returns A function to prevent the sort on scroll.\n */\nexport function preventSortOnScroll() {\n let scrollTimeout: ReturnType;\n\n return () => {\n clearTimeout(scrollTimeout);\n\n if (state) state.preventEnter = true;\n\n scrollTimeout = setTimeout(() => {\n if (state) state.preventEnter = false;\n }, 100);\n };\n}\n\n/**\n * Handle the node pointer over.\n *\n * @param e - The node pointer over event.\n *\n * @returns void\n */\nexport function handleNodePointerover(e: PointeroverNodeEvent) {\n if (e.detail.targetData.parent.el === e.detail.state.currentParent.el)\n sort(e.detail, e.detail.state);\n else transfer(e.detail, e.detail.state);\n}\n\n/**\n * Handle the node drop.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDrop(\n data: NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n sp(data.e);\n\n dropped = true;\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleDragend(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the pointer cancel.\n *\n * @param data - The node event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handlePointercancel(\n data: NodeEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isSynthDragState(state)) return;\n pd(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n const config = parents.get(state.initialParent.el)?.config;\n\n if (config?.onDragend) {\n config.onDragend({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n }\n\n config?.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleEnd(state: DragState | SynthDragState) {\n if (state.draggedNode) state.draggedNode.el.draggable = false;\n\n document.body.style.userSelect = state.rootUserSelect || \"\";\n\n if (isSynthDragState(state)) {\n document.documentElement.style.overscrollBehavior =\n state.rootOverScrollBehavior || \"\";\n\n document.documentElement.style.touchAction = state.rootTouchAction || \"\";\n }\n\n if (isSynthDragState(state)) cancelSynthScroll(state);\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n const config = parents.get(state.initialParent.el)?.config;\n\n const isSynth = isSynthDragState(state);\n\n const dropZoneClass = isSynth\n ? config?.synthDropZoneClass\n : config?.dropZoneClass;\n\n if (state.originalZIndex !== undefined)\n state.draggedNode.el.style.zIndex = state.originalZIndex;\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n dropZoneClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n state.initialParent.data?.config?.longPressClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n isSynth\n ? state.initialParent.data.config.synthDragPlaceholderClass\n : state.initialParent.data?.config?.dragPlaceholderClass\n );\n\n if (isSynth) state.clonedDraggedNode.remove();\n\n deselect(state.draggedNodes, state.currentParent, state);\n\n setActive(state.currentParent, undefined, state);\n\n resetState();\n\n state.selectedState = undefined;\n\n config?.onDragend?.({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n\n state.emit(\"dragEnded\", state);\n}\n\n/**\n * Handle the node pointer up.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodePointerup(\n data: NodePointerEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n sp(data.e);\n\n state.pointerDown = undefined;\n if (!state.pointerSelection && state.selectedState)\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n\n const config = data.targetData.parent.data.config;\n\n state.pointerSelection = false;\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n removeClass(\n data.targetData.parent.data.enabledNodes.map((x) => x.el),\n config.longPressClass\n );\n\n if (!isDragState(state)) return;\n\n config.handleEnd(state as DragState | SynthDragState);\n}\n\n/**\n * Initialize the synth drag.\n *\n * @param node - The node.\n * @param parent - The parent.\n * @param e - The pointer event.\n * @param _state - The drag state.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The synth drag state.\n */\nfunction initSynthDrag(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent,\n _state: BaseDragState,\n draggedNodes: Array>\n): SynthDragState {\n const config = parent.data.config;\n\n let dragImage: HTMLElement | undefined;\n\n let display = node.el.style.display;\n\n let result = undefined;\n\n if (config.synthDragImage) {\n result = config.synthDragImage(node, parent, e, draggedNodes);\n\n dragImage = result.dragImage;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n zIndex: 9999,\n pointerEvents: \"none\",\n margin: 0,\n overflow: \"hidden\",\n display: \"none\",\n });\n } else {\n if (!config.multiDrag || draggedNodes.length === 1) {\n dragImage = node.el.cloneNode(true) as HTMLElement;\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n height: node.el.getBoundingClientRect().height + \"px\",\n width: node.el.getBoundingClientRect().width + \"px\",\n overflow: \"hidden\",\n margin: 0,\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n } else {\n const wrapper = document.createElement(\"div\");\n\n wrapper.setAttribute(\"popover\", \"\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n clonedNode.style.pointerEvents = \"none\";\n\n wrapper.append(clonedNode);\n }\n\n Object.assign(wrapper.style, {\n display: \"flex\",\n flexDirection: \"column\",\n left: \"-9999px\",\n position: \"absolute\",\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n\n wrapper.id = \"dnd-dragged-node-clone\";\n\n dragImage = wrapper;\n }\n }\n\n dragImage.style.position = \"absolute\";\n\n parent.el.appendChild(dragImage);\n\n dragImage.showPopover();\n\n const synthDragStateProps = {\n clonedDraggedEls: [],\n clonedDraggedNode: dragImage,\n draggedNodeDisplay: display,\n synthDragScrolling: false,\n synthDragging: true,\n rootScrollWidth: document.scrollingElement?.scrollWidth,\n rootScrollHeight: document.scrollingElement?.scrollHeight,\n rootOverScrollBehavior: document.documentElement.style.overscrollBehavior,\n rootTouchAction: document.documentElement.style.touchAction,\n };\n\n document.documentElement.style.overscrollBehavior = \"none\";\n\n document.documentElement.style.touchAction = \"none\";\n\n const synthDragState = setDragState({\n ...dragStateProps(\n node,\n parent,\n e,\n draggedNodes,\n result?.offsetX,\n result?.offsetY\n ),\n ...synthDragStateProps,\n }) as SynthDragState;\n\n synthDragState.clonedDraggedNode.style.display =\n synthDragState.draggedNodeDisplay || \"\";\n\n return synthDragState;\n}\n\n/**\n * Handle the long press.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n * @param node - The node.\n *\n * @returns void\n */\nexport function handleLongPress(\n data: NodePointerEventData,\n state: BaseDragState,\n node: NodeRecord\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.longPress) return;\n\n state.longPressTimeout = setTimeout(() => {\n if (!state) return;\n\n state.longPress = true;\n\n if (config.longPressClass && data.e.cancelable)\n addNodeClass([node.el], config.longPressClass);\n\n pd(data.e);\n }, config.longPressDuration || 200);\n}\n\nfunction pointermoveClasses(\n state: SynthDragState,\n config: ParentConfig\n) {\n if (config.longPressClass)\n removeClass(\n state.draggedNodes.map((x) => x.el),\n config?.longPressClass\n );\n}\n\nfunction cancelSynthScroll(\n state: SynthDragState,\n cancelX = true,\n cancelY = true\n) {\n if (cancelX && state.animationFrameIdX !== undefined) {\n cancelAnimationFrame(state.animationFrameIdX);\n\n state.animationFrameIdX = undefined;\n }\n\n if (cancelY && state.animationFrameIdY !== undefined) {\n cancelAnimationFrame(state.animationFrameIdY);\n\n state.animationFrameIdY = undefined;\n }\n\n if (!state.animationFrameIdX && !state.animationFrameIdY) {\n state.preventEnter = false;\n }\n}\n\nfunction moveNode(\n e: PointerEvent,\n state: SynthDragState,\n scrollX = 0,\n scrollY = 0\n) {\n const { x, y } = eventCoordinates(e);\n\n state.coordinates.y = y;\n state.coordinates.x = x;\n\n const startLeft = state.startLeft ?? 0;\n const startTop = state.startTop ?? 0;\n\n // Calculate the translation values\n const translateX = x - startLeft + window.scrollX;\n const translateY = y - startTop + window.scrollY;\n\n // Apply the transform using translate\n state.clonedDraggedNode.style.transform = `translate(${\n translateX + scrollX\n }px, ${translateY + scrollY}px)`;\n\n if (e.cancelable) pd(e);\n\n pointermoveClasses(state, state.initialParent.data.config);\n}\n\n/**\n * Handle the synth move.\n *\n * @param e - The pointer event.\n * @param state - The synth drag state.\n *\n * @returns void\n */\nexport function synthMove(e: PointerEvent, state: SynthDragState) {\n moveNode(e, state);\n\n const coordinates = eventCoordinates(e);\n\n handleSynthScroll(coordinates, e, state);\n\n const elFromPoint = getElFromPoint(coordinates);\n\n if (!elFromPoint) {\n document.dispatchEvent(\n new CustomEvent(\"handleRootPointerover\", {\n detail: {\n e,\n state,\n },\n })\n );\n\n return;\n }\n const pointerMoveEventData = {\n e,\n targetData: elFromPoint,\n state,\n };\n\n if (\"node\" in elFromPoint) {\n elFromPoint.node.el.dispatchEvent(\n new CustomEvent(\"handleNodePointerover\", {\n detail: pointerMoveEventData,\n })\n );\n } else {\n elFromPoint.parent.el.dispatchEvent(\n new CustomEvent(\"handleParentPointerover\", {\n detail: pointerMoveEventData,\n })\n );\n }\n}\n\n/**\n * Handle the node drag over.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n const { x, y } = eventCoordinates(data.e);\n\n state.coordinates.y = y;\n\n state.coordinates.x = x;\n\n pd(data.e);\n\n sp(data.e);\n\n data.targetData.parent.el === state.currentParent?.el\n ? sort(data, state)\n : transfer(data, state);\n}\n\n/**\n * Handle the parent drag over.\n *\n * @param data - The parent drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n Object.assign(eventCoordinates(data.e));\n\n transfer(data, state);\n}\n\n/**\n * Handle the parent pointer over.\n *\n * @param e - The parent pointer over event.\n *\n * @returns void\n */\nexport function handleParentPointerover(e: PointeroverParentEvent) {\n if (e.detail.targetData.parent.el !== e.detail.state.currentParent.el)\n transfer(e.detail, e.detail.state);\n}\n\n/**\n * Validate the transfer.\n *\n * @param data - The transfer data.\n *\n * @returns Whether the transfer is valid.\n */\nexport function validateTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n state: BaseDragState;\n}) {\n if (targetParent.el === currentParent.el) return false;\n\n const targetConfig = targetParent.data.config;\n\n if (draggedNodes[0].el.contains(targetParent.el)) return false;\n\n if (targetConfig.dropZone === false) return false;\n\n const initialParentConfig = initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n targetParent,\n initialParent,\n currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Handle the node drag enter.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragenter(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Handle the node drag leave.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragleave(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Validate the sort.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n * @param x - The x coordinate.\n * @param y - The y coordinate.\n *\n * @returns Whether the sort is valid.\n */\nexport function validateSort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState,\n x: number,\n y: number\n): boolean {\n if (\n state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.targetData.node.data.value)\n ) {\n return false;\n }\n\n if (state.remapJustFinished) {\n state.remapJustFinished = false;\n\n if (\n data.targetData.node.data.value === state.currentTargetValue ||\n state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)\n ) {\n state.currentTargetValue = data.targetData.node.data.value;\n }\n\n return false;\n }\n\n if (state.preventEnter) return false;\n\n if (state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)) {\n state.currentTargetValue = undefined;\n\n return false;\n }\n\n if (data.targetData.node.data.value === state.currentTargetValue)\n return false;\n\n if (\n data.targetData.parent.el !== state.currentParent?.el ||\n data.targetData.parent.data.config.sortable === false\n )\n return false;\n\n if (data.targetData.node.el.contains(state.draggedNodes[0].el)) return false;\n\n const targetRect = data.targetData.node.el.getBoundingClientRect();\n\n const dragRect = state.draggedNode.el.getBoundingClientRect();\n\n const yDiff = targetRect.y - dragRect.y;\n\n const xDiff = targetRect.x - dragRect.x;\n\n let incomingDirection: \"above\" | \"below\" | \"left\" | \"right\";\n\n if (Math.abs(yDiff) > Math.abs(xDiff)) {\n incomingDirection = yDiff > 0 ? \"above\" : \"below\";\n } else {\n incomingDirection = xDiff > 0 ? \"left\" : \"right\";\n }\n\n const threshold = state.currentParent.data.config.threshold;\n\n switch (incomingDirection) {\n case \"left\":\n if (x > targetRect.x + targetRect.width * threshold.horizontal) {\n state.incomingDirection = \"left\";\n\n return true;\n }\n break;\n\n case \"right\":\n if (x < targetRect.x + targetRect.width * (1 - threshold.horizontal)) {\n state.incomingDirection = \"right\";\n\n return true;\n }\n break;\n\n case \"above\":\n if (y > targetRect.y + targetRect.height * threshold.vertical) {\n state.incomingDirection = \"above\";\n\n return true;\n }\n break;\n\n case \"below\":\n if (y < targetRect.y + targetRect.height * (1 - threshold.vertical)) {\n state.incomingDirection = \"below\";\n\n return true;\n }\n break;\n\n default:\n break;\n }\n\n return false;\n}\n\n/**\n * Sort the nodes.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function sort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState\n) {\n const { x, y } = eventCoordinates(data.e);\n\n if (!validateSort(data, state, x, y)) return;\n\n const range =\n state.draggedNode.data.index > data.targetData.node.data.index\n ? [data.targetData.node.data.index, state.draggedNode.data.index]\n : [state.draggedNode.data.index, data.targetData.node.data.index];\n\n state.targetIndex = data.targetData.node.data.index;\n\n state.affectedNodes = data.targetData.parent.data.enabledNodes.filter(\n (node) => {\n return (\n range[0] <= node.data.index &&\n node.data.index <= range[1] &&\n node.el !== state.draggedNode.el\n );\n }\n );\n\n data.targetData.parent.data.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.draggedNodes,\n targetNodes: [data.targetData.node],\n });\n}\n\n/**\n * Event listener used for all nodes.\n *\n * @param e - The event.\n *\n */\nexport function nodeEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function nodeTargetData(node: Node): NodeTargetData | undefined {\n const nodeData = nodes.get(node);\n\n if (!nodeData) return;\n\n const parentData = parents.get(node.parentNode);\n\n if (!parentData) return;\n\n return {\n node: {\n el: node,\n data: nodeData,\n },\n parent: {\n el: node.parentNode,\n data: parentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = nodeTargetData(e.currentTarget as Node);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\n/**\n * Transfer the nodes.\n *\n * @param data - The node event data or parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function transfer(\n data: NodeEventData | ParentEventData,\n state: DragState\n): void {\n if (\n !validateTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent as any,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n state,\n })\n )\n return;\n\n data.targetData.parent.data.config.performTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n initialIndex: state.initialIndex,\n state,\n targetNodes: \"node\" in data.targetData ? [data.targetData.node] : [],\n });\n\n state.currentParent = data.targetData.parent;\n\n state.transferred = true;\n}\n\n/**\n * Event listener used for all parents.\n *\n * @param callback - The callback.\n *\n * @returns A function to get the parent event data.\n */\nexport function parentEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function parentTargetData(\n parent: HTMLElement\n ): ParentTargetData | undefined {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: parent,\n data: parentData as ParentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = parentTargetData(e.currentTarget as HTMLElement);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\nexport function addNodeClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function nodeSetter(node: Node, nodeData: NodeData) {\n nodes.set(node, nodeData);\n }\n\n for (const el of els) {\n const nodeData = nodes.get(el as Node);\n\n const newData = addClass(el, className, nodeData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n nodeSetter(el as Node, newData as NodeData);\n }\n}\n\n/**\n * Add class to the parent.\n *\n * @param els - The parents.\n * @param className - The class name.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addParentClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function parentSetter(parent: HTMLElement, parentData: ParentData) {\n parents.set(parent, parentData);\n }\n\n for (const el of els) {\n const parentData = parents.get(el);\n\n const newData = addClass(el, className, parentData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n parentSetter(el, newData as ParentData);\n }\n}\n\n/**\n * Add class to the node.\n *\n * @param el - The node.\n * @param className - The class name.\n * @param data - The node data.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addClass(\n el: Node | HTMLElement | Element,\n className: string | undefined,\n data: NodeData | ParentData | undefined,\n omitAppendPrivateClass = false\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n if (classNames.includes(\"longPress\")) return;\n\n if (!data) {\n el.classList.add(...classNames);\n\n return;\n }\n\n const privateClasses = [];\n\n for (const className of classNames) {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n } else if (\n el.classList.contains(className) &&\n omitAppendPrivateClass === false\n ) {\n privateClasses.push(className);\n }\n }\n\n data.privateClasses = privateClasses;\n\n return data;\n}\n\n/**\n * Remove class from the nodes.\n *\n * @param els - The nodes.\n * @param className - The class name.\n *\n * @returns void\n */\nexport function removeClass(\n els: Array,\n className: string | undefined\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n for (const node of els) {\n if (!isNode(node)) {\n node.classList.remove(...classNames);\n continue;\n }\n\n const nodeData = nodes.get(node) || parents.get(node);\n\n if (!nodeData) continue;\n\n for (const className of classNames) {\n if (!nodeData.privateClasses.includes(className)) {\n node.classList.remove(className);\n }\n }\n }\n}\n\nfunction isScrollX(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect,\n state: SynthDragState\n): { left: boolean; right: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n const canScrollLeft = el.scrollLeft > 0;\n const canScrollRight =\n el.scrollLeft + window.innerWidth < (state.rootScrollWidth || 0);\n\n return {\n right: canScrollRight && e.clientX > el.clientWidth * (1 - threshold),\n left: canScrollLeft && e.clientX < el.clientWidth * threshold,\n };\n }\n\n if (\n (style.overflowX === \"auto\" || style.overflowX === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollWidth = el.scrollWidth;\n const offsetWidth = el.offsetWidth;\n const scrollLeft = el.scrollLeft;\n\n return {\n right:\n e.clientX > rect.left + offsetWidth * (1 - threshold) &&\n scrollLeft < scrollWidth - offsetWidth,\n left: e.clientX < rect.left + offsetWidth * threshold && scrollLeft > 0,\n };\n }\n\n return {\n right: false,\n left: false,\n };\n}\n\nfunction isScrollY(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect\n): { up: boolean; down: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n return {\n down: e.clientY > el.clientHeight * (1 - threshold),\n up: e.clientY < el.clientHeight * threshold,\n };\n }\n\n if (\n (style.overflowY === \"auto\" || style.overflowY === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollHeight = el.scrollHeight;\n const offsetHeight = el.offsetHeight;\n const scrollTop = el.scrollTop;\n\n return {\n down:\n e.clientY > rect.top + offsetHeight * (1 - threshold) &&\n scrollTop < scrollHeight - offsetHeight,\n up: e.clientY < rect.top + offsetHeight * threshold && scrollTop > 0,\n };\n }\n\n return {\n down: false,\n up: false,\n };\n}\n\nfunction scrollX(\n el: HTMLElement,\n e: PointerEvent,\n state: SynthDragState,\n right = true\n) {\n state.preventEnter = true;\n\n const incr = right ? 5 : -5;\n\n function scroll(el: HTMLElement) {\n el.scrollBy({ left: incr });\n\n moveNode(e, state, incr, 0);\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n }\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n}\n\nfunction scrollY(\n el: Element,\n e: PointerEvent,\n state: SynthDragState,\n up = true\n) {\n state.preventEnter = true;\n\n const incr = up ? -5 : 5;\n\n function scroll() {\n el.scrollBy({ top: incr });\n\n moveNode(e, state, 0, incr);\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n }\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n}\n\n/**\n * Handle the synth scroll.\n *\n * @param coordinates - The coordinates.\n * @param e - The event.\n * @param state - The state.\n *\n * @returns void\n */\nfunction handleSynthScroll(\n coordinates: { x: number; y: number },\n e: PointerEvent,\n state: SynthDragState\n) {\n cancelSynthScroll(state);\n\n const scrollables: Record<\"x\" | \"y\", HTMLElement | null> = {\n x: null,\n y: null,\n };\n\n const els = document.elementsFromPoint(coordinates.x, coordinates.y);\n\n for (const el of els) {\n if (scrollables.x && scrollables.y) break;\n\n if (!(el instanceof HTMLElement)) continue;\n\n const rect = el.getBoundingClientRect();\n\n const style = window.getComputedStyle(el);\n\n if (!scrollables.x) {\n const { left, right } = isScrollX(el, e, style, rect, state);\n\n if (left || right) {\n scrollables.x = el;\n\n scrollX(el, e, state, right);\n }\n }\n\n if (!scrollables.y) {\n const { up, down } = isScrollY(el, e, style, rect);\n\n if (up || down) {\n scrollables.y = el;\n\n scrollY(el, e, state, up);\n }\n }\n }\n}\n\nexport function getElFromPoint(coordinates: {\n x: number;\n y: number;\n}): NodeFromPoint | ParentFromPoint | undefined {\n let target = document.elementFromPoint(coordinates.x, coordinates.y);\n\n if (!isNode(target)) return;\n\n let isParent;\n\n let invalidEl = true;\n\n while (target && invalidEl) {\n if (nodes.has(target as Node) || parents.has(target as HTMLElement)) {\n invalidEl = false;\n\n isParent = parents.has(target as HTMLElement);\n\n break;\n }\n\n target = target.parentNode as Node;\n }\n\n if (!isParent) {\n const targetNodeData = nodes.get(target as Node);\n\n if (!targetNodeData) return;\n\n const targetParentData = parents.get(target.parentNode as Node);\n\n if (!targetParentData) return;\n\n return {\n node: {\n el: target as Node,\n data: targetNodeData,\n },\n parent: {\n el: target.parentNode as Node,\n data: targetParentData as ParentData,\n },\n };\n } else {\n const parentData = parents.get(target as HTMLElement);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: target as HTMLElement,\n data: parentData as ParentData,\n },\n };\n }\n}\n\n/**\n * Checks to see that a given element and its parent node is instance of\n * HTMLElement.\n *\n * @param {unknown} el - The element to check.\n *\n * @returns {boolean} - Whether or not provided element is of type Node.\n */\nexport function isNode(el: unknown): el is Node {\n return el instanceof HTMLElement && el.parentNode instanceof HTMLElement;\n}\n\n/**\n * Takes a given el and event handlers, assigns them, and returns the used abort\n * controller.\n *\n * @param el - The element to add the event listeners to.\n * @param events - The events to add to the element.\n * @returns - The abort controller used for the event listeners.\n */\nexport function addEvents(\n el: Document | ShadowRoot | Node | HTMLElement | Window,\n events: EventHandlers | any\n): AbortController {\n const abortController = new AbortController();\n\n for (const eventName in events) {\n const handler = events[eventName];\n\n el.addEventListener(eventName, handler, {\n signal: abortController.signal,\n passive: false,\n });\n }\n\n return abortController;\n}\n"],"m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NodeDragover","handleParentDragover","state","handleEnd","documentController","baseDragState","dragStateProps","nodes","emit","on","handleNodeDragover","handleParentDragover","handleEnd","handleNodePointerover","handleParentPointerover","draggedNodes","state","parent","x","scrollTimeout","node","scrollX","scrollY","className","el"]} \ No newline at end of file +{"version":3,"sources":["../src/utils.ts","../src/plugins/animations/index.ts","../src/plugins/insert/index.ts","../src/plugins/drop-or-swap/index.ts","../src/index.ts"],"sourcesContent":["/**\n * Function to prevent default behavior of an event.\n *\n * @param {Event} e - The event to prevent default behavior of.\n */\nexport function pd(e: Event) {\n e.preventDefault();\n}\n\n/**\n * Function to stop propagation of an event.\n *\n * @param {Event} e - The event to stop propagation of.\n */\nexport function sp(e: Event) {\n e.stopPropagation();\n}\n\nexport function rect(el: HTMLElement) {\n return el.getBoundingClientRect();\n}\n\n/**\n * Function to create an emitter.\n *\n * @returns {[Function, Function]} A tuple containing emit and on functions\n */\nexport function createEmitter() {\n const callbacks = new Map void>>();\n\n const emit = function (eventName: string, data: T) {\n if (!callbacks.get(eventName)) return;\n callbacks.get(eventName)!.forEach((cb) => {\n cb(data);\n });\n };\n\n const on = function (eventName: string, callback: (data: T) => void) {\n const cbs = callbacks.get(eventName) ?? [];\n\n cbs.push(callback);\n\n callbacks.set(eventName, cbs);\n };\n\n return [emit, on] as const;\n}\n\n/**\n * The emit and on functions for drag and drop.\n *\n * @type {[Function, Function]}\n */\nexport const [emit, on] = createEmitter();\n\n/**\n * A regular expression to test for a valid date string.\n *\n * @param x - A RegExp to compare.\n * @param y - A RegExp to compare.\n * @public\n */\nexport function eqRegExp(x: RegExp, y: RegExp): boolean {\n return (\n x.source === y.source &&\n x.flags.split(\"\").sort().join(\"\") === y.flags.split(\"\").sort().join(\"\")\n );\n}\n\n/**\n * Compare two values for equality, optionally at depth.\n *\n * @param valA - First value.\n * @param valB - Second value.\n * @param deep - If it will compare deeply if it's an object.\n * @param explicit - An array of keys to explicity check.\n *\n * @returns `boolean`\n *\n * @public\n */\nexport function eq(\n valA: unknown,\n valB: unknown,\n deep = true,\n explicit: string[] = [\"__key\"]\n): boolean {\n if (valA === valB) return true;\n\n if (\n typeof valB === \"object\" &&\n typeof valA === \"object\" &&\n valA !== null &&\n valB !== null\n ) {\n if (valA instanceof Map) return false;\n if (valA instanceof Set) return false;\n if (valA instanceof Date && valB instanceof Date)\n return valA.getTime() === valB.getTime();\n if (valA instanceof RegExp && valB instanceof RegExp)\n return eqRegExp(valA, valB);\n if (valA === null || valB === null) return false;\n\n const objA = valA as Record;\n const objB = valB as Record;\n\n if (Object.keys(objA).length !== Object.keys(objB).length) return false;\n\n for (const k of explicit) {\n if ((k in objA || k in objB) && objA[k] !== objB[k]) return false;\n }\n\n for (const key in objA) {\n if (!(key in objB)) return false;\n if (objA[key] !== objB[key] && !deep) return false;\n if (deep && !eq(objA[key], objB[key], deep, explicit)) return false;\n }\n return true;\n }\n return false;\n}\n\n///**\n// * Throttle a function.\n// *\n// * @param callback - The callback function to throttle.\n// * @param limit - The minimum time in milliseconds between function calls.\n// *\n// * @returns A throttled version of the callback function.\n// */\n//export function throttle(\n// callback: (...args: Args) => Return,\n// limit: number\n//): (...args: Args) => void {\n// let wait = false;\n// return function (...args: Args) {\n// if (!wait) {\n// callback.apply(null, args);\n// wait = true;\n// setTimeout(function () {\n// wait = false;\n// }, limit);\n// }\n// };\n//}\n\n/**\n * Split a class name into an array of class names.\n *\n * @param className - The class name to split.\n *\n * @returns An array of class names.\n */\nexport function splitClass(className: string): Array {\n return className.split(\" \").filter((x) => x);\n}\n\nexport function getRealCoords(el: HTMLElement): {\n top: number;\n bottom: number;\n left: number;\n right: number;\n height: number;\n width: number;\n} {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nexport function eventCoordinates(data: DragEvent | PointerEvent) {\n return { x: data.clientX, y: data.clientY };\n}\n","import type { SetupNodeData, Node } from \"../../types\";\nimport type { AnimationsConfig } from \"./types\";\nimport { state, parents, isDragState } from \"../../index\";\n\nexport function animations(animationsConfig: Partial = {}) {\n const slideUp = [\n {\n transform: `translateY(${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideDown = [\n {\n transform: `translateY(-${animationsConfig.yScale || 50}%)`,\n },\n {\n transform: `translateY(${animationsConfig.yScale || 0}%)`,\n },\n ];\n\n const slideLeft = [\n {\n transform: `translateX(${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n\n const slideRight = [\n {\n transform: `translateX(-${animationsConfig.xScale || 50}%)`,\n },\n {\n transform: `translateX(${animationsConfig.xScale || 0}%)`,\n },\n ];\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n setup() {\n if (document.head.querySelector(\"[data-drag-and-drop]\")) return;\n },\n\n setupNodeRemap(data: SetupNodeData) {\n if (!isDragState(state)) return;\n\n const duration = animationsConfig.duration || 150;\n\n if (data.node.data.value === state.draggedNode.data.value) {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideRight, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n }\n\n return;\n }\n\n if (\n !state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.node.data.value)\n )\n return;\n\n const nodeRect = data.node.el.getBoundingClientRect();\n\n const nodeIndex = state.affectedNodes.findIndex(\n (x) => x.data.value === data.node.data.value\n );\n\n const draggedNodeIndex = state.draggedNode.data.index;\n\n const ascendingDirection = draggedNodeIndex >= state.targetIndex;\n\n let adjacentNode;\n\n if (ascendingDirection) {\n adjacentNode = state.affectedNodes[nodeIndex + 1]\n ? state.affectedNodes[nodeIndex + 1]\n : state.affectedNodes[nodeIndex - 1];\n } else {\n adjacentNode = state.affectedNodes[nodeIndex - 1]\n ? state.affectedNodes[nodeIndex - 1]\n : state.affectedNodes[nodeIndex + 1];\n }\n\n if (adjacentNode) {\n const xDiff = Math.abs(\n nodeRect.x - adjacentNode.el.getBoundingClientRect().x\n );\n\n const yDiff = Math.abs(\n nodeRect.y - adjacentNode.el.getBoundingClientRect().y\n );\n\n if (xDiff > yDiff && ascendingDirection) {\n animate(data.node.el, slideRight, duration);\n } else if (xDiff > yDiff && !ascendingDirection) {\n animate(data.node.el, slideLeft, duration);\n }\n } else {\n switch (state.incomingDirection) {\n case \"below\":\n animate(data.node.el, slideDown, duration);\n\n break;\n case \"above\":\n animate(data.node.el, slideUp, duration);\n\n break;\n case \"left\":\n animate(data.node.el, slideLeft, duration);\n\n break;\n case \"right\":\n animate(data.node.el, slideRight, duration);\n\n break;\n }\n }\n },\n };\n };\n}\n\nfunction animate(\n node: Node,\n animation: Keyframe[] | PropertyIndexedKeyframes,\n duration: number\n) {\n if (!state) return;\n\n state.preventEnter = true;\n\n node.animate(animation, {\n duration: duration,\n easing: \"ease-in-out\",\n });\n\n setTimeout(() => {\n if (!state) return;\n\n state.preventEnter = false;\n }, duration);\n}\n","import type { InsertConfig } from \"../../types\";\nimport type {\n DragState,\n NodeDragEventData,\n NodeRecord,\n ParentEventData,\n PointeroverParentEvent,\n ParentRecord,\n SynthDragState,\n InsertEvent,\n BaseDragState,\n InsertState,\n Coordinates,\n} from \"../../types\";\n\nimport {\n parents,\n parentValues,\n setParentValues,\n state,\n addParentClass,\n isDragState,\n isSynthDragState,\n removeClass,\n addEvents,\n remapNodes,\n} from \"../../index\";\n\nimport { eq, pd, eventCoordinates } from \"../../utils\";\n\nexport const insertState: InsertState = {\n draggedOverNodes: [],\n draggedOverParent: null,\n targetIndex: 0,\n ascending: false,\n insertPoint: null,\n dragging: false,\n};\n\nlet documentController: AbortController | undefined;\n\n// WIP: This is a work in progress and not yet fully functional\nexport function insert(insertConfig: InsertConfig) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const insertParentConfig = {\n ...parentData.config,\n insertConfig,\n };\n\n return {\n teardown() {\n if (parentData.abortControllers.root) {\n parentData.abortControllers.root.abort();\n }\n },\n setup() {\n insertParentConfig.handleNodeDragover =\n insertConfig.handleNodeDragover || handleNodeDragover;\n\n insertParentConfig.handleParentPointerover =\n insertConfig.handleParentPointerover || handleParentPointerover;\n\n insertParentConfig.handleNodePointerover =\n insertConfig.handleNodePointerover || handleParentPointerover;\n\n insertParentConfig.handleParentDragover =\n insertConfig.handleParentDragover || handleParentDragover;\n\n const originalHandleend = insertParentConfig.handleEnd;\n\n insertParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: checkPosition,\n pointermove: checkPosition,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = insertParentConfig;\n\n state.on(\"dragStarted\", () => {\n defineRanges(parent);\n });\n\n state.on(\"scrollStarted\", () => {\n if (insertState.insertPoint)\n insertState.insertPoint.el.style.display = \"none\";\n });\n\n state.on(\"scrollEnded\", () => {\n defineRanges(parent);\n });\n\n const firstScrollableParent = findFirstOverflowingParent(parent);\n\n if (firstScrollableParent) {\n firstScrollableParent.addEventListener(\n \"scroll\",\n defineRanges.bind(null, parent)\n );\n }\n\n window.addEventListener(\"resize\", defineRanges.bind(null, parent));\n },\n };\n };\n}\n\nfunction findFirstOverflowingParent(element: HTMLElement): HTMLElement | null {\n let parent = element.parentElement;\n\n while (parent) {\n const { overflow, overflowY, overflowX } = getComputedStyle(parent);\n\n // Check if the overflow property is set to scroll, auto, or hidden (anything other than visible)\n const isOverflowSet =\n overflow !== \"visible\" ||\n overflowY !== \"visible\" ||\n overflowX !== \"visible\";\n\n // Check if there is actual overflow (scrolling)\n const isOverflowing =\n parent.scrollHeight > parent.clientHeight ||\n parent.scrollWidth > parent.clientWidth;\n const hasScrollPosition = parent.scrollTop > 0 || parent.scrollLeft > 0;\n\n if (isOverflowSet && (isOverflowing || hasScrollPosition)) {\n return parent;\n }\n\n parent = parent.parentElement;\n }\n\n return null; // No overflowing parent found\n}\n\nfunction checkPosition(e: DragEvent | PointerEvent) {\n if (!isDragState(state)) return;\n\n const el = document.elementFromPoint(e.clientX, e.clientY);\n\n if (!(el instanceof HTMLElement)) return;\n\n if (!parents.has(el)) {\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint?.el === el) return;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n if (insertState.draggedOverParent) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n\n state.currentParent = state.initialParent;\n }\n}\n\ninterface Range {\n x: [number, number];\n y: [number, number];\n vertical: boolean;\n}\n\nfunction createVerticalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean\n): Range {\n const center = nodeCoords.top + nodeCoords.height / 2;\n\n if (!otherCoords) {\n const offset = nodeCoords.height / 2 + 10;\n return {\n y: isAscending ? [center, center + offset] : [center - offset, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n }\n\n const otherEdge = isAscending ? otherCoords.top : otherCoords.bottom;\n const nodeEdge = isAscending ? nodeCoords.bottom : nodeCoords.top;\n const midpoint = nodeEdge + Math.abs(nodeEdge - otherEdge) / 2;\n\n return {\n y: isAscending ? [center, midpoint] : [midpoint, center],\n x: [nodeCoords.left, nodeCoords.right],\n vertical: true,\n };\n}\n\nfunction createHorizontalRange(\n nodeCoords: Coordinates,\n otherCoords: Coordinates | undefined,\n isAscending: boolean,\n lastInRow = false\n): Range {\n const center = nodeCoords.left + nodeCoords.width / 2;\n\n if (!otherCoords) {\n if (isAscending) {\n return {\n x: [center, center + nodeCoords.width],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [nodeCoords.left - 10, center],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n }\n\n if (isAscending && lastInRow) {\n return {\n x: [center, nodeCoords.right + 10],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n\n if (isAscending) {\n const nextNodeCenter = otherCoords.left + otherCoords.width / 2;\n return {\n x: [center, center + Math.abs(center - nextNodeCenter) / 2],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n } else {\n return {\n x: [\n otherCoords.right + Math.abs(otherCoords.right - nodeCoords.left) / 2,\n center,\n ],\n y: [nodeCoords.top, nodeCoords.bottom],\n vertical: false,\n };\n }\n}\n\nfunction getRealCoords(el: HTMLElement): Coordinates {\n const { top, bottom, left, right, height, width } =\n el.getBoundingClientRect();\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n return {\n top: top + scrollTop,\n bottom: bottom + scrollTop,\n left: left + scrollLeft,\n right: right + scrollLeft,\n height,\n width,\n };\n}\n\nfunction defineRanges(parent: HTMLElement) {\n if (!isDragState(state)) return;\n\n const parentData = parents.get(parent);\n if (!parentData) return;\n\n const enabledNodes = parentData.enabledNodes;\n\n enabledNodes.forEach((node, index) => {\n node.data.range = {};\n\n const prevNode = enabledNodes[index - 1];\n const nextNode = enabledNodes[index + 1];\n const nodeCoords = getRealCoords(node.el);\n const prevNodeCoords = prevNode ? getRealCoords(prevNode.el) : undefined;\n const nextNodeCoords = nextNode ? getRealCoords(nextNode.el) : undefined;\n\n const aboveOrBelowPrevious =\n prevNodeCoords &&\n (nodeCoords.top > prevNodeCoords.bottom ||\n nodeCoords.bottom < prevNodeCoords.top);\n\n const aboveOrBelowAfter =\n nextNodeCoords &&\n (nodeCoords.top > nextNodeCoords.bottom ||\n nodeCoords.bottom < nextNodeCoords.top);\n\n const fullishWidth =\n parent.getBoundingClientRect().width * 0.8 < nodeCoords.width;\n\n if (fullishWidth) {\n node.data.range.ascending = createVerticalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createVerticalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowAfter && !aboveOrBelowPrevious) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (!aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n prevNodeCoords,\n false\n );\n } else if (aboveOrBelowPrevious && !nextNodeCoords) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n undefined,\n true\n );\n } else if (aboveOrBelowPrevious && !aboveOrBelowAfter) {\n node.data.range.ascending = createHorizontalRange(\n nodeCoords,\n nextNodeCoords,\n true\n );\n node.data.range.descending = createHorizontalRange(\n nodeCoords,\n undefined,\n false\n );\n }\n });\n}\n\nexport function handleNodeDragover(data: NodeDragEventData) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n data.e.preventDefault();\n}\n\nfunction processParentDragEvent(\n e: DragEvent | PointerEvent,\n targetData: ParentEventData[\"targetData\"],\n state: DragState,\n isNativeDrag: boolean\n) {\n const config = targetData.parent.data.config;\n\n if (!isNativeDrag && config.nativeDrag) return;\n\n pd(e);\n\n if (isNativeDrag) pd(e);\n\n const { x, y } = eventCoordinates(e);\n\n // Calculate global coordinates\n const clientX = x;\n const clientY = y;\n\n const scrollLeft = window.scrollX || document.documentElement.scrollLeft;\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n\n state.coordinates.x = clientX + scrollLeft;\n state.coordinates.y = clientY + scrollTop;\n\n const nestedParent = targetData.parent.data.nestedParent;\n\n let realTargetParent = targetData.parent;\n\n if (nestedParent) {\n const rect = nestedParent.el.getBoundingClientRect();\n\n if (state.coordinates.y > rect.top && state.coordinates.y < rect.bottom)\n realTargetParent = nestedParent;\n }\n\n if (realTargetParent.el === state.currentParent?.el) {\n moveBetween(realTargetParent, state);\n } else {\n moveOutside(realTargetParent, state);\n }\n\n state.currentParent = realTargetParent;\n}\n\nexport function handleParentDragover(\n data: ParentEventData,\n state: DragState\n) {\n processParentDragEvent(data.e as DragEvent, data.targetData, state, true);\n}\n\nexport function handleParentPointerover(data: PointeroverParentEvent) {\n const { detail } = data;\n\n const { state, targetData } = detail;\n\n if (state.scrolling) return;\n\n processParentDragEvent(detail.e, targetData, state, false);\n}\n\nexport function moveBetween(data: ParentRecord, state: DragState) {\n if (data.data.config.sortable === false) return;\n\n if (\n data.el === insertState.draggedOverParent?.el &&\n insertState.draggedOverParent.data.getValues(data.el).length === 0\n ) {\n return;\n } else if (insertState.draggedOverParent?.el) {\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n insertState.draggedOverParent = null;\n }\n\n const foundRange = findClosest(data.data.enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n}\n\nfunction moveOutside(data: ParentRecord, state: DragState) {\n if (data.el === state.currentParent.el) return false;\n\n const targetConfig = data.data.config;\n\n if (state.draggedNode.el.contains(data.el)) return false;\n\n if (targetConfig.dropZone === false) return;\n\n const initialParentConfig = state.initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n data,\n state.initialParent,\n state.currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n const values = data.data.getValues(data.el);\n\n if (!values.length) {\n addParentClass([data.el], targetConfig.dropZoneClass);\n\n insertState.draggedOverParent = data as ParentRecord;\n\n const insertPoint = insertState.insertPoint;\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n } else {\n removeClass([state.currentParent.el], targetConfig.dropZoneClass);\n\n const enabledNodes = data.data.enabledNodes;\n\n const foundRange = findClosest(enabledNodes, state);\n\n if (!foundRange) return;\n\n const key = foundRange[1] as \"ascending\" | \"descending\";\n\n if (foundRange) {\n const position = foundRange[0].data.range\n ? foundRange[0].data.range[key]\n : undefined;\n\n if (position)\n positioninsertPoint(\n data,\n position,\n foundRange[1] === \"ascending\",\n foundRange[0],\n insertState as InsertState\n );\n }\n }\n}\n\nfunction findClosest(enabledNodes: NodeRecord[], state: DragState) {\n let foundRange: [NodeRecord, string] | null = null;\n\n for (let x = 0; x < enabledNodes.length; x++) {\n if (!state || !enabledNodes[x].data.range) continue;\n\n if (enabledNodes[x].data.range!.ascending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.ascending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.ascending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.ascending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.ascending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"ascending\"];\n\n return foundRange;\n }\n }\n\n if (enabledNodes[x].data.range!.descending) {\n if (\n state.coordinates.y > enabledNodes[x].data.range!.descending!.y[0] &&\n state.coordinates.y < enabledNodes[x].data.range!.descending!.y[1] &&\n state.coordinates.x > enabledNodes[x].data.range!.descending!.x[0] &&\n state.coordinates.x < enabledNodes[x].data.range!.descending!.x[1]\n ) {\n foundRange = [enabledNodes[x], \"descending\"];\n\n return foundRange;\n }\n }\n }\n}\n\nfunction createInsertPoint(\n parent: ParentRecord,\n insertState: InsertState\n) {\n const insertPoint = parent.data.config.insertConfig?.insertPoint({\n el: parent.el,\n data: parent.data,\n });\n\n if (!insertPoint)\n throw new Error(\"Insert point not found\", { cause: parent });\n\n insertState.insertPoint = {\n parent,\n el: insertPoint,\n };\n\n document.body.appendChild(insertPoint);\n\n Object.assign(insertPoint, {\n position: \"absolute\",\n display: \"none\",\n });\n}\n\nfunction removeInsertPoint(insertState: InsertState) {\n if (insertState.insertPoint?.el) insertState.insertPoint.el.remove();\n\n insertState.insertPoint = null;\n}\n\nfunction positioninsertPoint(\n parent: ParentRecord,\n position: { x: number[]; y: number[]; vertical: boolean },\n ascending: boolean,\n node: NodeRecord,\n insertState: InsertState\n) {\n if (insertState.insertPoint?.el !== parent.el) {\n removeInsertPoint(insertState);\n\n createInsertPoint(parent, insertState);\n }\n\n insertState.draggedOverNodes = [node];\n\n if (!insertState.insertPoint) return;\n\n if (position.vertical) {\n const topPosition =\n position.y[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().height / 2;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${topPosition}px`,\n left: `${position.x[0]}px`,\n right: `${position.x[1]}px`,\n height: \"4px\",\n width: `${position.x[1] - position.x[0]}px`,\n });\n } else {\n const leftPosition =\n position.x[ascending ? 1 : 0] -\n insertState.insertPoint.el.getBoundingClientRect().width / 2;\n insertState.insertPoint.el.style.left = `${leftPosition}px`;\n\n Object.assign(insertState.insertPoint.el.style, {\n top: `${position.y[0]}px`,\n bottom: `${position.y[1]}px`,\n width: \"4px\",\n height: `${position.y[1] - position.y[0]}px`,\n });\n }\n\n insertState.targetIndex = node.data.index;\n\n insertState.ascending = ascending;\n\n insertState.insertPoint.el.style.display = \"block\";\n}\n\nexport function handleParentDrop(_data: NodeDragEventData) {}\n\n/**\n * Performs the actual insertion of the dragged nodes into the target parent.\n *\n * @param state - The current drag state.\n */\nexport function handleEnd(\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isDragState(state)) return;\n\n const insertPoint = insertState.insertPoint;\n\n if (!insertState.draggedOverParent) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const transferred = state.initialParent.el !== state.currentParent.el;\n\n remapNodes(state.initialParent.el);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const enabledNodes = [...state.initialParent.data.enabledNodes];\n\n const originalIndex = state.draggedNodes[0].data.index;\n\n const targetIndex = insertState.targetIndex;\n\n if (\n !transferred &&\n insertState.draggedOverNodes[0] &&\n insertState.draggedOverNodes[0].el !== state.draggedNodes[0].el\n ) {\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n let index = insertState.draggedOverNodes[0].data.index;\n\n if (\n insertState.targetIndex > state.draggedNodes[0].data.index &&\n !insertState.ascending\n ) {\n index--;\n } else if (\n insertState.targetIndex < state.draggedNodes[0].data.index &&\n insertState.ascending\n ) {\n index++;\n }\n\n newParentValues.splice(index, 0, ...draggedValues);\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n if (state.initialParent.data.config.onSort) {\n const sortEventData = {\n parent: {\n el: state.initialParent.el,\n data: state.initialParent.data,\n } as ParentRecord,\n previousValues: [...draggedParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...state.initialParent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes,\n previousPosition: originalIndex,\n position: index,\n state: state as DragState,\n };\n\n state.initialParent.data.config.onSort(sortEventData);\n }\n } else if (transferred && insertState.draggedOverNodes.length) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n // For the time being, we will not be remoing the value of the original dragged parent.\n let index = insertState.draggedOverNodes[0].data.index || 0;\n\n if (insertState.ascending) index++;\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n targetIndex: index,\n })\n : draggedValues;\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n if (state.currentParent.el.contains(state.initialParent.el)) {\n // Update initial parent values first\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n // Now get the target parent values.\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n } else {\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const targetParentValues = parentValues(\n state.currentParent.el,\n state.currentParent.data\n );\n\n targetParentValues.splice(index, 0, ...insertValues);\n\n setParentValues(state.currentParent.el, state.currentParent.data, [\n ...targetParentValues,\n ]);\n }\n\n const data = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n targetIndex,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.onTransfer)\n state.initialParent.data.config.onTransfer(data);\n if (state.currentParent.data.config.onTransfer)\n state.currentParent.data.config.onTransfer(data);\n }\n } else if (insertState.draggedOverParent) {\n if (state.currentParent.el.contains(state.initialParent.el)) {\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n } else {\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const draggedOverParentValues = parentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data\n );\n\n const insertValues = state.initialParent.data.config.insertConfig\n ?.dynamicValues\n ? state.initialParent.data.config.insertConfig.dynamicValues({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n })\n : draggedValues;\n\n draggedOverParentValues.push(...insertValues);\n\n setParentValues(\n insertState.draggedOverParent.el,\n insertState.draggedOverParent.data,\n [...draggedOverParentValues]\n );\n\n const draggedParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n const newParentValues = [\n ...draggedParentValues.filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n setParentValues(state.initialParent.el, state.initialParent.data, [\n ...newParentValues,\n ]);\n }\n\n const data: InsertEvent = {\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: insertState.draggedOverNodes as NodeRecord[],\n state,\n };\n\n if (state.initialParent.data.config.insertConfig?.insertEvent)\n state.initialParent.data.config.insertConfig.insertEvent(data);\n if (state.currentParent.data.config.insertConfig?.insertEvent)\n state.currentParent.data.config.insertConfig.insertEvent(data);\n\n removeClass(\n [insertState.draggedOverParent.el],\n insertState.draggedOverParent.data.config.dropZoneClass\n );\n }\n\n if (insertPoint) insertPoint.el.style.display = \"none\";\n\n const dropZoneClass = isSynthDragState(state)\n ? state.initialParent.data.config.synthDropZoneClass\n : state.initialParent.data.config.dropZoneClass;\n\n removeClass(\n insertState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const dragPlaceholderClass =\n state.initialParent.data.config.dragPlaceholderClass;\n\n removeClass(\n state.draggedNodes.map((node) => node.el),\n dragPlaceholderClass\n );\n\n insertState.draggedOverNodes = [];\n\n insertState.draggedOverParent = null;\n}\n","import type {\n DropSwapConfig,\n NodeDragEventData,\n DragState,\n SynthDragState,\n NodeRecord,\n PointeroverNodeEvent,\n ParentDragEventData,\n PointeroverParentEvent,\n DropSwapState,\n} from \"../../types\";\nimport {\n parents,\n parentValues,\n setParentValues,\n addNodeClass,\n isSynthDragState,\n removeClass,\n addClass,\n state,\n addEvents,\n isDragState,\n} from \"../../index\";\n\nexport const dropSwapState: DropSwapState = {\n draggedOverNodes: Array>(),\n initialDraggedIndex: undefined,\n transferred: false,\n dragging: false,\n};\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\nexport function dropOrSwap(dropSwapConfig: DropSwapConfig = {}) {\n return (parent: HTMLElement) => {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n const dropSwapParentConfig = {\n ...parentData.config,\n dropSwapConfig,\n };\n\n return {\n setup() {\n dropSwapParentConfig.handleNodeDragover =\n dropSwapConfig.handleNodeDragover || handleNodeDragover;\n\n dropSwapParentConfig.handleParentDragover =\n dropSwapConfig.handleParentDragover || handleParentDragover;\n\n dropSwapParentConfig.handleNodePointerover =\n dropSwapConfig.handleNodePointerover || handleNodePointerover;\n\n dropSwapParentConfig.handleParentPointerover =\n dropSwapConfig.handleParentPointerover || handeParentPointerover;\n\n const originalHandleend = dropSwapParentConfig.handleEnd;\n\n dropSwapParentConfig.handleEnd = (\n state: DragState | SynthDragState\n ) => {\n handleEnd(state);\n\n originalHandleend(state);\n };\n\n parentData.on(\"dragStarted\", () => {\n documentController = addEvents(document, {\n dragover: rootDragover,\n handleRootPointerover: rootPointerover,\n });\n });\n\n parentData.on(\"dragEnded\", () => {\n documentController?.abort();\n });\n\n parentData.config = dropSwapParentConfig;\n },\n };\n };\n}\n\nfunction rootDragover(_e: DragEvent) {\n if (!isDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.dropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction rootPointerover(_e: CustomEvent) {\n if (!isSynthDragState(state)) return;\n\n removeClass(\n [state.currentParent.el],\n state.currentParent.data.config.synthDropZoneParentClass\n );\n\n state.currentParent = state.initialParent;\n}\n\nfunction updateDraggedOverNodes(\n data: PointeroverNodeEvent | NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const targetData =\n \"detail\" in data ? data.detail.targetData : data.targetData;\n\n const config = targetData.parent.data.config;\n\n const dropZoneClass = isSynthDragState(state)\n ? config.synthDropZoneClass\n : config.dropZoneClass;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass\n );\n\n const enabledNodes = targetData.parent.data.enabledNodes;\n\n if (!enabledNodes) return;\n\n dropSwapState.draggedOverNodes = enabledNodes.slice(\n targetData.node.data.index,\n targetData.node.data.index + state.draggedNodes.length\n );\n\n addNodeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n dropZoneClass,\n true\n );\n\n state.currentTargetValue = targetData.node.data.value;\n\n state.currentParent = targetData.parent;\n\n addClass(\n state.currentParent.el,\n isSynthDragState(state)\n ? config.synthDropZoneParentClass\n : config.dropZoneParentClass,\n state.currentParent.data,\n true\n );\n}\n\nfunction handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n updateDraggedOverNodes(data, state);\n}\n\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n data.e.preventDefault();\n\n data.e.stopPropagation();\n\n const currentConfig = state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.dropZoneClass\n );\n\n removeClass([state.currentParent.el], currentConfig.dropZoneParentClass);\n\n const config = data.targetData.parent.data.config;\n\n addClass(\n data.targetData.parent.el,\n config.dropZoneParentClass,\n data.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n state.currentParent = data.targetData.parent;\n}\n\nexport function handeParentPointerover(data: PointeroverParentEvent) {\n const currentConfig = data.detail.state.currentParent.data.config;\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n currentConfig.synthDropZoneClass\n );\n\n removeClass(\n [data.detail.state.currentParent.el],\n currentConfig.synthDropZoneParentClass\n );\n\n const config = data.detail.targetData.parent.data.config;\n\n addClass(\n data.detail.targetData.parent.el,\n config.synthDropZoneParentClass,\n data.detail.targetData.parent.data,\n true\n );\n\n dropSwapState.draggedOverNodes = [];\n\n data.detail.state.currentParent = data.detail.targetData.parent;\n}\n\nfunction handleNodePointerover(data: PointeroverNodeEvent) {\n if (!isSynthDragState(data.detail.state)) return;\n\n updateDraggedOverNodes(data, data.detail.state);\n}\n\nfunction swapElements(\n arr1: T[],\n arr2: T[] | null,\n index1: number | number[],\n index2: number\n): T[] | [T[], T[]] {\n const indices1 = Array.isArray(index1) ? index1 : [index1];\n\n if (arr2 === null) {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr1[index2];\n\n arr1.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return arr1.filter((el) => el !== undefined);\n } else {\n const elementsFromArr1 = indices1.map((i) => arr1[i]);\n\n const elementFromArr2 = arr2[index2];\n\n arr2.splice(index2, 1, ...elementsFromArr1);\n\n indices1.forEach((i, idx) => {\n arr1[i] = idx === 0 ? elementFromArr2 : (undefined as unknown as T);\n });\n\n return [arr1.filter((el) => el !== undefined), arr2];\n }\n}\n\nfunction handleEnd(state: DragState | SynthDragState) {\n const isSynth = isSynthDragState(state);\n\n removeClass(\n [state.currentParent.el],\n isSynth\n ? state.currentParent.data.config.synthDropZoneParentClass\n : state.currentParent.data.config.dropZoneParentClass\n );\n\n removeClass(\n dropSwapState.draggedOverNodes.map((node) => node.el),\n isSynth\n ? state.currentParent.data.config.synthDropZoneClass\n : state.currentParent.data.config.dropZoneClass\n );\n\n const values = parentValues(state.currentParent.el, state.currentParent.data);\n\n const draggedValues = state.draggedNodes.map((node) => node.data.value);\n\n const newValues = values.filter((x) => !draggedValues.includes(x));\n\n const targetIndex = dropSwapState.draggedOverNodes[0]?.data.index;\n\n const draggedIndex = state.draggedNodes[0].data.index;\n\n const initialParentValues = parentValues(\n state.initialParent.el,\n state.initialParent.data\n );\n\n if (targetIndex === undefined) {\n if (state.initialParent.el === state.currentParent.el) return;\n\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n values.concat(draggedValues)\n );\n\n return;\n }\n\n let swap = false;\n\n const shouldSwap = state.initialParent.data.config.dropSwapConfig?.shouldSwap;\n\n if (shouldSwap)\n swap = shouldSwap({\n sourceParent: state.initialParent,\n targetParent: state.currentParent,\n draggedNodes: state.draggedNodes,\n targetNodes: dropSwapState.draggedOverNodes as NodeRecord[],\n state,\n });\n\n if (state.initialParent.el === state.currentParent.el) {\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n swap ? swapElements(values, null, draggedIndex, targetIndex) : newValues\n );\n } else {\n if (swap) {\n const res = swapElements(\n initialParentValues,\n newValues,\n state.initialIndex,\n targetIndex\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n res[0] as T[]\n );\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n res[1] as T[]\n );\n } else {\n const newInitialValues = initialParentValues.filter(\n (x) => !draggedValues.includes(x)\n );\n\n setParentValues(\n state.initialParent.el,\n state.initialParent.data,\n newInitialValues\n );\n\n newValues.splice(targetIndex, 0, ...draggedValues);\n\n setParentValues(\n state.currentParent.el,\n state.currentParent.data,\n newValues\n );\n }\n }\n}\n","import type {\n DNDPlugin,\n DragAndDrop,\n DragState,\n DragStateProps,\n Node,\n NodeData,\n NodeDragEventData,\n NodeEventData,\n NodePointerEventData,\n NodeRecord,\n NodeTargetData,\n NodesData,\n ParentConfig,\n ParentData,\n ParentEventData,\n ParentTargetData,\n ParentsData,\n PointeroverNodeEvent,\n PointeroverParentEvent,\n SetupNodeData,\n TearDownNodeData,\n BaseDragState,\n SynthDragState,\n ParentKeydownEventData,\n SynthDragStateProps,\n ParentRecord,\n EventHandlers,\n NodeFromPoint,\n ParentFromPoint,\n ParentDragEventData,\n} from \"./types\";\n\nimport {\n pd,\n sp,\n on,\n emit,\n createEmitter,\n eq,\n splitClass,\n eventCoordinates,\n} from \"./utils\";\n\nexport * from \"./types\";\nexport { animations } from \"./plugins/animations\";\nexport { insert } from \"./plugins/insert\";\nexport { dropOrSwap } from \"./plugins/drop-or-swap\";\n\n/**\n * Check to see if code is running in a browser.\n */\nexport const isBrowser = typeof window !== \"undefined\";\n\n/**\n * Parents or \"lists\" are the containers that nodes or \"draggable items\" can be\n * dragged from and into.\n *\n * @type {WeakMap>}\n */\nexport const parents: ParentsData = new WeakMap<\n HTMLElement,\n ParentData\n>();\n\n/**\n * Nodes are the draggable items and the direct descendants of the parents.\n *\n * @type {WeakMap>}\n */\nexport const nodes: NodesData = new WeakMap>();\n\n/**\n * Function to check if touch support is enabled.\n *\n * @returns {boolean}\n */\nfunction checkTouchSupport() {\n if (!isBrowser) return false;\n\n return \"ontouchstart\" in window || navigator.maxTouchPoints > 0;\n}\n\n/**\n * The base drag state.\n *\n * @type {BaseDragState}\n */\nconst baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n currentTargetValue: undefined,\n on,\n emit,\n newActiveDescendant: undefined,\n originalZIndex: undefined,\n pointerSelection: false,\n preventEnter: false,\n rootUserSelect: undefined,\n nodePointerdown: undefined,\n longPress: false,\n scrolling: false,\n longPressTimeout: undefined,\n remapJustFinished: false,\n selectedNodes: [],\n selectedParent: undefined,\n preventSynthDrag: false,\n pointerDown: undefined,\n};\n\n/**\n * The state of the drag and drop.\n *\n * @type {BaseDragState}\n */\nexport let state: BaseDragState = baseDragState;\n\n/**\n * Variable to check if the drop has occurred.\n */\nlet dropped = false;\n\n/**\n * Abort controller for the document.\n */\nlet documentController: AbortController | undefined;\n\n/**\n * Abort controller for the window.\n */\nlet windowController: AbortController | undefined;\n\n/**\n * Timeout for the scroll.\n */\nlet scrollTimeout: ReturnType;\n\n/**\n * Variable to check if the device is touch.\n */\nlet touchDevice: boolean = false;\n\nexport function resetState() {\n const baseDragState = {\n activeDescendant: undefined,\n affectedNodes: [],\n coordinates: {\n x: 0,\n y: 0,\n },\n on,\n emit,\n currentTargetValue: undefined,\n originalZIndex: undefined,\n pointerId: undefined,\n preventEnter: false,\n remapJustFinished: false,\n selectedNodes: [],\n nodePointerdown: undefined,\n rootUserSelect: undefined,\n preventSynthDrag: false,\n scrolling: false,\n selectedParent: undefined,\n pointerSelection: false,\n synthScrollDirection: undefined,\n draggedNodeDisplay: undefined,\n synthDragScrolling: false,\n longPress: false,\n pointerDown: undefined,\n longPressTimeout: undefined,\n };\n\n state = { ...baseDragState } as BaseDragState;\n}\n\n/**\n * @param {DragStateProps} dragStateProps - Attributes to update state with.\n *\n * @mutation - Updates state with node values.\n *\n * @returns void\n */\nexport function setDragState(\n dragStateProps: (SynthDragStateProps & DragStateProps) | DragStateProps\n): DragState | SynthDragState {\n Object.assign(state, dragStateProps);\n\n dragStateProps.initialParent.data.emit(\"dragStarted\", state);\n\n dropped = false;\n\n state.emit(\"dragStarted\", state);\n\n return state as DragState | SynthDragState;\n}\n\n/**\n *\n */\nfunction handleRootPointerdown(_e: PointerEvent) {\n if (state.activeState) setActive(state.activeState.parent, undefined, state);\n\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = state.activeState = undefined;\n}\n\nfunction handleRootPointerup(e: PointerEvent) {\n pd(e);\n\n state.pointerDown = undefined;\n\n if (!isSynthDragState(state)) return;\n\n const config = state.currentParent.data.config;\n\n if (isSynthDragState(state)) config.handleEnd(state);\n}\n\n/**\n * Handles the keydown event on the root element.\n *\n * @param {KeyboardEvent} e - The keyboard event.\n */\nfunction handleRootKeydown(e: KeyboardEvent) {\n if (e.key === \"Escape\") {\n if (state.selectedState)\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n if (state.activeState)\n setActive(state.activeState.parent, undefined, state);\n\n state.selectedState = state.activeState = undefined;\n }\n}\n\nfunction handleRootDrop(_e: DragEvent) {}\n\nexport function copyNodeStyle(\n sourceNode: HTMLElement,\n targetNode: HTMLElement,\n omitKeys = false\n) {\n const computedStyle = window.getComputedStyle(sourceNode);\n\n const omittedKeys = [\n \"position\",\n \"z-index\",\n \"top\",\n \"left\",\n \"x\",\n \"pointer-events\",\n \"y\",\n \"transform-origin\",\n \"filter\",\n \"-webkit-text-fill-color\",\n ];\n\n for (const key of Array.from(computedStyle)) {\n if (omitKeys === false && key && omittedKeys.includes(key)) continue;\n\n targetNode.style.setProperty(\n key,\n computedStyle.getPropertyValue(key),\n computedStyle.getPropertyPriority(key)\n );\n }\n}\n\n/**\n * If we are currently dragging, then let's prevent default on dragover to avoid\n * the default behavior of the browser on drop.\n */\nfunction handleRootDragover(e: DragEvent) {\n if (!isDragState(state)) return;\n\n pd(e);\n}\n\nfunction handleRootPointermove(e: PointerEvent) {\n if (!state.pointerDown) return;\n\n //pd(e);\n\n const config = state.pointerDown.parent.data.config;\n\n if (\n !isSynthDragState(state) &&\n (touchDevice || (!touchDevice && !config.nativeDrag))\n ) {\n if (config.longPress && !state.longPress) {\n clearTimeout(state.longPressTimeout);\n\n state.longPress = false;\n\n return;\n }\n\n const nodes = config.draggedNodes(state.pointerDown);\n\n config.dragstartClasses(state.pointerDown.node, nodes, config, true);\n\n const synthDragState = initSynthDrag(\n state.pointerDown.node,\n state.pointerDown.parent,\n e,\n state,\n nodes\n );\n\n state.rootUserSelect = window.getComputedStyle(\n document.documentElement\n ).userSelect;\n\n document.body.style.userSelect = \"none\";\n\n synthMove(e, synthDragState);\n } else if (isSynthDragState(state)) {\n synthMove(e, state);\n }\n}\n\n/**\n * Initializes the drag and drop functionality for a given parent.\n *\n * @param {DragAndDrop} dragAndDrop - The drag and drop configuration.\n *\n * @returns void\n */\nexport function dragAndDrop({\n parent,\n getValues,\n setValues,\n config = {},\n}: DragAndDrop): void {\n if (!isBrowser) return;\n\n touchDevice = checkTouchSupport();\n\n if (!documentController) {\n documentController = addEvents(document, {\n dragover: handleRootDragover,\n pointerdown: handleRootPointerdown,\n pointerup: handleRootPointerup,\n keydown: handleRootKeydown,\n drop: handleRootDrop,\n pointermove: handleRootPointermove,\n pointercancel: nodeEventData(config.handlePointercancel),\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n });\n\n const liveRegion = document.createElement(\"div\");\n\n setAttrs(liveRegion, {\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-dnd-live-region\": \"true\",\n });\n\n Object.assign(liveRegion.style, {\n position: \"absolute\",\n top: \"0px\",\n left: \"-9999px\",\n width: \"1px\",\n height: \"1px\",\n padding: \"0\",\n overflow: \"hidden\",\n clip: \"rect(0, 0, 0, 0)\",\n whiteSpace: \"nowrap\",\n border: \"0\",\n });\n\n document.body.appendChild(liveRegion);\n }\n\n if (!windowController)\n windowController = addEvents(window, {\n resize: () => {\n touchDevice = checkTouchSupport();\n },\n });\n\n tearDown(parent);\n\n const [emit, on] = createEmitter();\n\n const parentData: ParentData = {\n getValues,\n setValues,\n config: {\n dragDropEffect: config.dragDropEffect ?? \"move\",\n dragEffectAllowed: config.dragEffectAllowed ?? \"move\",\n draggedNodes,\n dragstartClasses,\n deepCopyStyles: config.deepCopyStyles ?? false,\n handleNodeKeydown,\n handleParentKeydown,\n handleDragstart,\n handleNodeDragover,\n handleParentDragover,\n handleNodeDrop,\n handlePointercancel,\n handleEnd,\n handleDragend,\n handleParentFocus,\n handleNodePointerup,\n handleNodePointerover,\n handleParentPointerover,\n handleParentScroll,\n handleNodePointerdown,\n handleNodeDragenter,\n handleNodeDragleave,\n handleParentDrop,\n multiDrag: config.multiDrag ?? false,\n nativeDrag: config.nativeDrag ?? true,\n performSort,\n performTransfer,\n root: config.root ?? document,\n setupNode,\n setupNodeRemap,\n reapplyDragClasses,\n tearDownNode,\n tearDownNodeRemap,\n remapFinished,\n threshold: {\n horizontal: 0,\n vertical: 0,\n },\n ...config,\n },\n enabledNodes: [],\n abortControllers: {},\n privateClasses: [],\n on,\n emit,\n };\n\n const nodesObserver = new MutationObserver(nodesMutated);\n\n nodesObserver.observe(parent, { childList: true });\n\n parents.set(parent, parentData);\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin) => {\n plugin(parent)?.tearDown?.();\n });\n\n config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.setup?.();\n });\n\n setup(parent, parentData);\n\n remapNodes(parent, true);\n}\n\nexport function dragStateProps(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent | DragEvent,\n draggedNodes: Array>,\n offsetX?: number,\n offsetY?: number\n): DragStateProps {\n const { x, y } = eventCoordinates(e);\n\n const rect = node.el.getBoundingClientRect();\n\n return {\n affectedNodes: [],\n ascendingDirection: false,\n clonedDraggedEls: [],\n coordinates: {\n x,\n y,\n },\n draggedNode: {\n el: node.el,\n data: node.data,\n },\n draggedNodes,\n incomingDirection: undefined,\n initialIndex: node.data.index,\n initialParent: {\n el: parent.el,\n data: parent.data,\n },\n currentParent: {\n el: parent.el,\n data: parent.data,\n },\n longPress: parent.data.config.longPress ?? false,\n longPressTimeout: undefined,\n currentTargetValue: node.data.value,\n scrollEls: [],\n // Need to account for if the explicity offset is positive or negative\n startLeft: offsetX ? offsetX : x - rect.left,\n startTop: offsetY ? offsetY : y - rect.top,\n targetIndex: node.data.index,\n transferred: false,\n };\n}\n\nexport function performSort({\n parent,\n draggedNodes,\n targetNodes,\n}: {\n parent: ParentRecord;\n draggedNodes: Array>;\n targetNodes: Array>;\n}) {\n remapNodes(parent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const targetParentValues = parentValues(parent.el, parent.data);\n\n const originalIndex = draggedNodes[0].data.index;\n\n const enabledNodes = [...parent.data.enabledNodes];\n\n const newParentValues = [\n ...targetParentValues.filter((x) => !draggedValues.some((y) => eq(x, y))),\n ];\n newParentValues.splice(targetNodes[0].data.index, 0, ...draggedValues);\n\n if (\"draggedNode\" in state)\n state.currentTargetValue = targetNodes[0].data.value;\n\n setParentValues(parent.el, parent.data, [...newParentValues]);\n\n if (parent.data.config.onSort)\n parent.data.config.onSort({\n parent: {\n el: parent.el,\n data: parent.data,\n } as ParentRecord,\n previousValues: [...targetParentValues],\n previousNodes: [...enabledNodes],\n nodes: [...parent.data.enabledNodes],\n values: [...newParentValues],\n draggedNodes: draggedNodes,\n previousPosition: originalIndex,\n position: targetNodes[0].data.index,\n targetNodes,\n state,\n });\n}\n\n/**\n * This function sets the active node as well as removing any classes or\n * attribute set.\n *\n * @param {ParentEventData} data - The parent event data.\n * @param {NodeRecord} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction setActive(\n parent: ParentRecord,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState\n) {\n const activeDescendantClass = parent.data.config.activeDescendantClass;\n\n if (state.activeState) {\n {\n removeClass([state.activeState.node.el], activeDescendantClass);\n\n if (state.activeState.parent.el !== parent.el)\n state.activeState.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n }\n }\n\n if (!newActiveNode) {\n state.activeState?.parent.el.setAttribute(\"aria-activedescendant\", \"\");\n\n state.activeState = undefined;\n\n return;\n }\n\n state.activeState = {\n node: newActiveNode,\n parent,\n };\n\n addNodeClass([newActiveNode.el], activeDescendantClass);\n\n state.activeState.parent.el.setAttribute(\n \"aria-activedescendant\",\n state.activeState.node.el.id\n );\n}\n\n/**\n * This function deselects the nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {Array>} nodes - The nodes to deselect.\n * @param {ParentRecord} parent - The parent record.\n * @param {BaseDragState} state - The current drag state.\n */\nfunction deselect(\n nodes: Array>,\n parent: ParentRecord,\n state: BaseDragState\n) {\n const selectedClass = parent.data.config.selectedClass;\n\n if (!state.selectedState) return;\n\n const iterativeNodes = Array.from(nodes);\n\n removeClass(\n nodes.map((x) => x.el),\n selectedClass\n );\n\n for (const node of iterativeNodes) {\n node.el.setAttribute(\"aria-selected\", \"false\");\n\n const index = state.selectedState.nodes.findIndex((x) => x.el === node.el);\n\n if (index === -1) continue;\n\n state.selectedState.nodes.splice(index, 1);\n }\n\n clearLiveRegion(parent);\n}\n\n/**\n * This function sets the selected nodes. This will clean the prior selected state\n * as well as removing any classes or attributes set.\n *\n * @param {ParentRecord} parent - The parent record.\n * @param {Array>} selectedNodes - The nodes to select.\n * @param {NodeRecord | undefined} newActiveNode - The new active node.\n * @param {BaseDragState} state - The current drag state.\n * @param {boolean} pointerdown - Whether the pointerdown event was triggered.\n */\nfunction setSelected(\n parent: ParentRecord,\n selectedNodes: Array>,\n newActiveNode: NodeRecord | undefined,\n state: BaseDragState,\n pointerdown = false\n) {\n state.pointerSelection = pointerdown;\n\n for (const node of selectedNodes) {\n node.el.setAttribute(\"aria-selected\", \"true\");\n\n addNodeClass([node.el], parent.data.config.selectedClass, true);\n }\n\n state.selectedState = {\n nodes: selectedNodes,\n parent,\n };\n\n const selectedItems = selectedNodes.map((x) =>\n x.el.getAttribute(\"aria-label\")\n );\n\n if (selectedItems.length === 0) {\n state.selectedState = undefined;\n\n clearLiveRegion(parent);\n\n return;\n }\n\n setActive(parent, newActiveNode, state);\n\n updateLiveRegion(\n parent,\n `${selectedItems.join(\n \", \"\n )} ready for dragging. Use arrow keys to navigate. Press enter to drop ${selectedItems.join(\n \", \"\n )}.`\n );\n}\n\nfunction updateLiveRegion(parent: ParentRecord, message: string) {\n const liveRegion = document.querySelector('[data-dnd-live-region=\"true\"]');\n\n if (!liveRegion) return;\n\n liveRegion.id = parent.el.id + \"-live-region\";\n\n liveRegion.textContent = message;\n}\n\nfunction clearLiveRegion(parent: ParentRecord) {\n const liveRegion = document.getElementById(parent.el.id + \"-live-region\");\n\n if (!liveRegion) return;\n\n liveRegion.textContent = \"\";\n}\n\nexport function handleParentFocus(\n data: ParentEventData,\n state: BaseDragState | DragState | SynthDragState\n) {\n const firstEnabledNode = data.targetData.parent.data.enabledNodes[0];\n\n if (!firstEnabledNode) return;\n\n if (\n state.selectedState &&\n state.selectedState.parent.el !== data.targetData.parent.el\n ) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n } else if (!state.selectedState) {\n setActive(data.targetData.parent, firstEnabledNode, state);\n }\n}\n\n/**\n * Perform the transfer of the nodes.\n *\n * @param data - The transfer data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function performTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n initialIndex,\n targetNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n initialIndex: number;\n state: BaseDragState | DragState | SynthDragState;\n targetNodes: Array>;\n}) {\n remapNodes(initialParent.el);\n\n const draggedValues = draggedNodes.map((x) => x.data.value);\n\n const currentParentValues = [\n ...parentValues(currentParent.el, currentParent.data).filter(\n (x) => !draggedValues.some((y) => eq(x, y))\n ),\n ];\n\n const targetParentValues = parentValues(targetParent.el, targetParent.data);\n\n const reset =\n initialParent.el === targetParent.el &&\n targetParent.data.config.sortable === false;\n\n let targetIndex: number;\n\n if (targetNodes.length) {\n if (reset) {\n targetIndex = initialIndex;\n } else if (targetParent.data.config.sortable === false) {\n targetIndex = targetParent.data.enabledNodes.length;\n } else {\n targetIndex = targetNodes[0].data.index;\n }\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n } else {\n targetIndex = reset ? initialIndex : targetParent.data.enabledNodes.length;\n\n targetParentValues.splice(targetIndex, 0, ...draggedValues);\n }\n\n setParentValues(currentParent.el, currentParent.data, currentParentValues);\n\n setParentValues(targetParent.el, targetParent.data, targetParentValues);\n\n if (targetParent.data.config.onTransfer) {\n targetParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes,\n });\n }\n\n if (currentParent.data.config.onTransfer) {\n currentParent.data.config.onTransfer({\n sourceParent: currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n targetIndex,\n state,\n targetNodes: targetNodes ? targetNodes : [],\n });\n }\n}\n\n/**\n * Get the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns The values of the parent.\n */\nexport function parentValues(\n parent: HTMLElement,\n parentData: ParentData\n): Array {\n return [...parentData.getValues(parent)];\n}\n\n/**\n * Set the values of the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n * @param values - The values to set.\n *\n * @returns void\n */\nexport function setParentValues(\n parent: HTMLElement,\n parentData: ParentData,\n values: Array\n): void {\n parentData.setValues(values, parent);\n}\n\n/**\n * Get the values of the dragged nodes.\n *\n * @param state - The drag state.\n *\n * @returns The values of the dragged nodes.\n */\nexport function dragValues(state: DragState): Array {\n return [...state.draggedNodes.map((x) => x.data.value)];\n}\n\n/**\n * Utility function to update parent config.\n *\n * @param parent - The parent element.\n * @param config - The config to update.\n *\n * @returns void\n */\nexport function updateConfig(\n parent: HTMLElement,\n config: Partial>\n) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parents.set(parent, {\n ...parentData,\n config: { ...parentData.config, ...config },\n });\n\n dragAndDrop({\n parent,\n getValues: parentData.getValues,\n setValues: parentData.setValues,\n config,\n });\n}\n\n/**\n * Handle the parent drop event.\n *\n * @param data - The parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDrop(\n data: ParentEventData,\n state: DragState\n) {\n sp(data.e);\n\n dropped = true;\n\n const handleEnd = state.initialParent.data.config.handleEnd;\n\n handleEnd(state);\n}\n\n/**\n * Tear down the parent.\n *\n * @param parent - The parent element.\n *\n * @returns void\n */\nexport function tearDown(parent: HTMLElement) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n if (parentData.abortControllers.mainParent)\n parentData.abortControllers.mainParent.abort();\n}\n\n/**\n * Check if the state is a drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a drag state.\n */\nexport function isDragState(\n state: BaseDragState\n): state is DragState | SynthDragState {\n return \"draggedNode\" in state && !!state.draggedNode;\n}\n\n/**\n * Check if the state is a synth drag state.\n *\n * @param state - The state to check.\n *\n * @returns Whether the state is a synth drag state.\n */\nexport function isSynthDragState(\n state: BaseDragState\n): state is SynthDragState {\n return \"synthDragging\" in state && !!state.synthDragging;\n}\n\n/**\n * Setup the parent.\n *\n * @param parent - The parent element.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction setup(parent: HTMLElement, parentData: ParentData): void {\n parentData.abortControllers.mainParent = addEvents(parent, {\n keydown: parentEventData(parentData.config.handleParentKeydown),\n dragover: parentEventData(parentData.config.handleParentDragover),\n handleParentPointerover: parentData.config.handleParentPointerover,\n scroll: parentEventData(parentData.config.handleParentScroll),\n drop: parentEventData(parentData.config.handleParentDrop),\n hasNestedParent: (e: CustomEvent) => {\n const parent = parents.get(e.target as HTMLElement);\n\n if (!parent) return;\n\n parent.nestedParent = e.detail.parent;\n },\n focus: parentEventData(parentData.config.handleParentFocus),\n });\n\n if (\n parentData.config.externalDragHandle &&\n parentData.config.externalDragHandle.el &&\n parentData.config.externalDragHandle.callback\n ) {\n parentData.abortControllers.externalDragHandle = addEvents(\n parentData.config.externalDragHandle.el,\n {\n pointerdown: (_e: PointerEvent) => {\n if (\n !parentData.config.externalDragHandle ||\n !parentData.config.externalDragHandle.callback\n )\n return;\n\n const draggableItem = parentData.config.externalDragHandle.callback();\n\n if (!isNode(draggableItem)) {\n console.warn(\n \"No draggable item found from external drag handle callback\"\n );\n\n return;\n }\n\n const nodeData = nodes.get(draggableItem);\n\n if (!nodeData) return;\n\n const parentNode = draggableItem.parentNode;\n\n if (!(parentNode instanceof HTMLElement)) return;\n\n const parent = parents.get(parentNode);\n\n if (!parent) return;\n\n state.pointerDown = {\n parent: {\n el: parentNode,\n data: parent,\n },\n node: {\n el: draggableItem,\n data: nodeData,\n },\n };\n\n draggableItem.draggable = true;\n },\n }\n );\n }\n\n if (parent.id)\n setAttrs(parent, {\n role: \"listbox\",\n tabindex: \"0\",\n \"aria-multiselectable\": parentData.config.multiDrag ? \"true\" : \"false\",\n \"aria-activedescendant\": \"\",\n \"aria-describedby\": parent.id + \"-live-region\",\n });\n}\n\n/**\n * Set the attributes of the element.\n *\n * @param el - The element.\n * @param attrs - The attributes to set.\n *\n * @returns void\n */\nexport function setAttrs(el: HTMLElement, attrs: Record) {\n for (const key in attrs) el.setAttribute(key, attrs[key]);\n}\n\n/**\n * Setup the node.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNode(data: SetupNodeData) {\n const config = data.parent.data.config;\n\n data.node.data.abortControllers.mainNode = addEvents(data.node.el, {\n keydown: nodeEventData(config.handleNodeKeydown),\n dragstart: nodeEventData(config.handleDragstart),\n dragover: nodeEventData(config.handleNodeDragover),\n dragenter: nodeEventData(config.handleNodeDragenter),\n dragleave: nodeEventData(config.handleNodeDragleave),\n dragend: nodeEventData(config.handleDragend),\n drop: nodeEventData(config.handleNodeDrop),\n pointerup: nodeEventData(config.handleNodePointerup),\n pointercancel: nodeEventData(config.handlePointercancel),\n\n pointerdown: nodeEventData(config.handleNodePointerdown),\n handleNodePointerover: config.handleNodePointerover,\n touchmove: (e: TouchEvent) => {\n if (isDragState(state) && e.cancelable) pd(e);\n },\n contextmenu: (e: Event) => {\n if (touchDevice) pd(e);\n },\n });\n\n data.node.el.setAttribute(\"role\", \"option\");\n\n data.node.el.setAttribute(\"aria-selected\", \"false\");\n\n config.reapplyDragClasses(data.node.el, data.parent.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNode?.(data);\n });\n}\n\n/**\n * Setup the node remap.\n *\n * @param data - The setup node data.\n *\n * @returns void\n */\nexport function setupNodeRemap(data: SetupNodeData) {\n nodes.set(data.node.el, data.node.data);\n\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.setupNodeRemap?.(data);\n });\n}\n\n/**\n * Reapply the drag classes to the node.\n *\n * @param node - The node.\n * @param parentData - The parent data.\n *\n * @returns void\n */\nfunction reapplyDragClasses(node: Node, parentData: ParentData) {\n if (!isDragState(state)) return;\n\n const dropZoneClass = isSynthDragState(state)\n ? parentData.config.synthDropZoneClass\n : parentData.config.dropZoneClass;\n\n if (state.draggedNode.el !== node) return;\n\n addNodeClass([node], dropZoneClass, true);\n}\n\n/**\n * Tear down the node remap.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNodeRemap(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNodeRemap?.(data);\n });\n}\n\n/**\n * Tear down the node.\n *\n * @param data - The tear down node data.\n *\n * @returns void\n */\nexport function tearDownNode(data: TearDownNodeData) {\n data.parent.data.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(data.parent.el)?.tearDownNode?.(data);\n });\n\n data.node.el.draggable = false;\n\n if (data.node.data?.abortControllers?.mainNode)\n data.node.data?.abortControllers?.mainNode.abort();\n}\n\n/**\n * Called when the nodes of a given parent element are mutated.\n *\n * @param mutationList - The list of mutations.\n *\n * @returns void\n *\n * @internal\n */\nfunction nodesMutated(mutationList: MutationRecord[]) {\n // TODO: This could be better, but using it as a way to ignore comments and text\n if (\n mutationList.length === 1 &&\n mutationList[0].addedNodes.length === 1 &&\n !(mutationList[0].addedNodes[0] instanceof HTMLElement)\n )\n return;\n\n const parentEl = mutationList[0].target;\n\n if (!(parentEl instanceof HTMLElement)) return;\n\n const allSelectedAndActiveNodes = document.querySelectorAll(\n `[aria-selected=\"true\"]`\n );\n\n const parentData = parents.get(parentEl);\n\n if (!parentData) return;\n\n for (let x = 0; x < allSelectedAndActiveNodes.length; x++) {\n const node = allSelectedAndActiveNodes[x];\n\n node.setAttribute(\"aria-selected\", \"false\");\n\n removeClass([node], parentData.config.selectedClass);\n }\n\n remapNodes(parentEl);\n}\n\n/**\n * Remaps the data of the parent element's children.\n *\n * @param parent - The parent element.\n *\n * @returns void\n *\n * @internal\n */\nexport function remapNodes(parent: HTMLElement, force?: boolean) {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n parentData.privateClasses = Array.from(parent.classList);\n\n const enabledNodes: Array = [];\n\n const config = parentData.config;\n\n for (let x = 0; x < parent.children.length; x++) {\n const node = parent.children[x];\n\n if (!isNode(node) || node.id === \"dnd-dragged-node-clone\") continue;\n\n const nodeData = nodes.get(node);\n\n // Only tear down the node if we have explicitly called dragAndDrop\n if (force || !nodeData)\n config.tearDownNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n if (config.disabled) continue;\n\n if (!config.draggable || (config.draggable && config.draggable(node))) {\n enabledNodes.push(node);\n }\n }\n\n if (\n enabledNodes.length !== parentData.getValues(parent).length &&\n !config.disabled\n ) {\n console.warn(\n \"The number of draggable items defined in the parent element does not match the number of values. This may cause unexpected behavior.\"\n );\n\n return;\n }\n\n const values = parentData.getValues(parent);\n\n const enabledNodeRecords: Array> = [];\n\n for (let x = 0; x < enabledNodes.length; x++) {\n const node = enabledNodes[x];\n\n const prevNodeData = nodes.get(node);\n\n if (config.draggableValue && !config.draggableValue(values[x])) continue;\n\n const nodeData = Object.assign(\n prevNodeData ?? {\n privateClasses: [],\n abortControllers: {},\n },\n {\n value: values[x],\n index: x,\n }\n );\n\n if (\n !isDragState(state) &&\n state.newActiveDescendant &&\n eq(state.newActiveDescendant.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n !isDragState(state) &&\n state.activeState &&\n eq(state.activeState.node.data.value, nodeData.value)\n ) {\n setActive(\n {\n data: parentData,\n el: parent,\n },\n {\n el: node,\n data: nodeData,\n },\n state\n );\n }\n\n if (\n isDragState(state) &&\n eq(state.draggedNode.data.value, nodeData.value)\n ) {\n state.draggedNode.data = nodeData;\n\n state.draggedNode.el = node;\n\n const draggedNode = state.draggedNodes.find(\n (x) => x.data.value === nodeData.value\n );\n\n if (draggedNode) draggedNode.el = node;\n }\n\n enabledNodeRecords.push({\n el: node,\n data: nodeData,\n });\n\n if (force || !prevNodeData)\n config.setupNode({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n\n setupNodeRemap({\n parent: {\n el: parent,\n data: parentData,\n },\n node: {\n el: node,\n data: nodeData,\n },\n });\n }\n\n parents.set(parent, { ...parentData, enabledNodes: enabledNodeRecords });\n\n config.remapFinished(parentData);\n\n parentData.config.plugins?.forEach((plugin: DNDPlugin) => {\n plugin(parent)?.remapFinished?.();\n });\n}\n\n/**\n * Set the remap just finished flag.\n *\n * @returns void\n */\nexport function remapFinished() {\n state.remapJustFinished = true;\n\n if (\"draggedNode\" in state) state.affectedNodes = [];\n}\n\n/**\n * Validate the drag start.\n *\n * @param data - The node event data.\n *\n * @returns Whether the drag start is valid.\n */\nexport function validateDragstart(data: NodeEventData): boolean {\n return !!data.targetData.parent.data.config.nativeDrag;\n}\n\n/**\n * Get the dragged nodes.\n *\n * @param pointerDown - The pointer down data.\n *\n * @returns The dragged nodes.\n */\nfunction draggedNodes(pointerDown: {\n parent: ParentRecord;\n node: NodeRecord;\n}): Array> {\n if (!pointerDown.parent.data.config.multiDrag) {\n return [pointerDown.node];\n } else if (state.selectedState) {\n return [\n pointerDown.node,\n ...(state.selectedState?.nodes.filter(\n (x) => x.el !== pointerDown.node.el\n ) as Array>),\n ];\n }\n\n return [];\n}\n\n/**\n * Handle the parent scroll.\n *\n * @param data - The parent event data.\n *\n * @returns void\n */\nfunction handleParentScroll(_data: ParentEventData) {\n if (!isDragState(state)) return;\n\n state.emit(\"scrollStarted\", state);\n\n if (isSynthDragState(state)) return;\n\n state.preventEnter = true;\n\n if (scrollTimeout) clearTimeout(scrollTimeout);\n\n scrollTimeout = setTimeout(() => {\n state.preventEnter = false;\n\n state.emit(\"scrollEnded\", state);\n }, 100);\n}\n\n/**\n * Responsible for assigning dragstart classes to the dragged nodes.\n */\nexport function handleDragstart(\n data: NodeDragEventData,\n _state: BaseDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (\n !config.nativeDrag ||\n !validateDragstart(data) ||\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config,\n })\n ) {\n pd(data.e);\n\n return;\n }\n\n const nodes = config.draggedNodes({\n parent: data.targetData.parent,\n node: data.targetData.node,\n });\n\n config.dragstartClasses(data.targetData.node, nodes, config);\n\n const dragState = initDrag(data, nodes);\n\n if (config.onDragstart)\n config.onDragstart({\n parent: data.targetData.parent,\n values: parentValues(\n data.targetData.parent.el,\n data.targetData.parent.data\n ),\n draggedNode: dragState.draggedNode,\n draggedNodes: dragState.draggedNodes,\n position: dragState.initialIndex,\n state: dragState,\n });\n}\n\nexport function handleNodePointerdown(\n data: NodePointerEventData,\n state: BaseDragState\n) {\n sp(data.e);\n\n if (\n !validateDragHandle({\n x: data.e.clientX,\n y: data.e.clientY,\n node: data.targetData.node,\n config: data.targetData.parent.data.config,\n })\n )\n return;\n\n state.pointerDown = {\n parent: data.targetData.parent,\n node: data.targetData.node,\n };\n\n data.targetData.node.el.draggable = true;\n\n handleLongPress(data, state, data.targetData.node);\n\n const parentData = data.targetData.parent.data;\n\n let selectedNodes = [data.targetData.node];\n\n const commandKey = data.e.ctrlKey || data.e.metaKey;\n const shiftKey = data.e.shiftKey;\n\n const targetNode = data.targetData.node;\n\n if (commandKey && parentData.config.multiDrag) {\n if (state.selectedState) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === targetNode.el\n );\n\n if (idx === -1) {\n selectedNodes = [...state.selectedState.nodes, targetNode];\n } else {\n selectedNodes = state.selectedState.nodes.filter(\n (x) => x.el !== targetNode.el\n );\n }\n } else {\n selectedNodes = [targetNode];\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (shiftKey && parentData.config.multiDrag) {\n const nodes = data.targetData.parent.data.enabledNodes;\n\n if (state.selectedState && state.activeState) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, state.selectedState.parent, state);\n\n state.selectedState = undefined;\n\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n } else {\n const [minIndex, maxIndex] =\n state.activeState.node.data.index < data.targetData.node.data.index\n ? [\n state.activeState.node.data.index,\n data.targetData.node.data.index,\n ]\n : [\n data.targetData.node.data.index,\n state.activeState.node.data.index,\n ];\n\n selectedNodes = nodes.slice(minIndex, maxIndex + 1);\n }\n } else {\n for (let x = 0; x <= targetNode.data.index; x++)\n selectedNodes.push(nodes[x]);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n\n return;\n }\n\n if (state.selectedState?.nodes?.length) {\n const idx = state.selectedState.nodes.findIndex(\n (x) => x.el === data.targetData.node.el\n );\n\n if (idx === -1) {\n if (state.selectedState.parent.el !== data.targetData.parent.el) {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n } else if (parentData.config.multiDrag && touchDevice) {\n selectedNodes.push(...state.selectedState.nodes);\n } else {\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n }\n\n setSelected(\n data.targetData.parent,\n selectedNodes,\n data.targetData.node,\n state,\n true\n );\n }\n } else {\n setSelected(\n data.targetData.parent,\n [data.targetData.node],\n data.targetData.node,\n state,\n true\n );\n }\n}\n\n/**\n * Add dragstart classes to the nodes.\n *\n * @param node - The node.\n * @param nodes - The nodes.\n * @param config - The parent config.\n * @param isSynth - Whether the drag is synthetic.\n *\n * @returns void\n */\nexport function dragstartClasses(\n _node: NodeRecord,\n nodes: Array>,\n config: ParentConfig,\n isSynth = false\n) {\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n setTimeout(() => {\n removeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDraggingClass : config.draggingClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDragPlaceholderClass : config.dragPlaceholderClass\n );\n\n addNodeClass(\n nodes.map((x) => x.el),\n isSynth ? config.synthDropZoneClass : config.dropZoneClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.activeDescendantClass\n );\n\n removeClass(\n nodes.map((x) => x.el),\n config.selectedClass\n );\n });\n}\n\n/**\n * Initialize the drag state.\n *\n * @param data - The node drag event data.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The drag state.\n */\nexport function initDrag(\n data: NodeDragEventData,\n draggedNodes: Array>\n): DragState {\n sp(data.e);\n\n const dragState = setDragState(\n dragStateProps(\n data.targetData.node,\n data.targetData.parent,\n data.e,\n draggedNodes\n )\n );\n\n if (data.e.dataTransfer) {\n const config = data.targetData.parent.data.config;\n\n data.e.dataTransfer.dropEffect = config.dragDropEffect;\n\n data.e.dataTransfer.effectAllowed = config.dragEffectAllowed;\n\n let dragImage: HTMLElement | undefined;\n\n if (config.dragImage) {\n dragImage = config.dragImage(data, draggedNodes);\n } else {\n if (!config.multiDrag) {\n data.e.dataTransfer.setDragImage(\n data.targetData.node.el,\n data.e.offsetX,\n data.e.offsetY\n );\n\n const originalZIndex = data.targetData.node.el.style.zIndex;\n\n dragState.originalZIndex = originalZIndex;\n\n data.targetData.node.el.style.zIndex = \"9999\";\n\n return dragState;\n } else {\n const wrapper = document.createElement(\"div\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n clonedNode.style.pointerEvents = \"none\";\n\n clonedNode.id = node.el.id + \"-clone\";\n\n wrapper.append(clonedNode);\n }\n\n const { width } = draggedNodes[0].el.getBoundingClientRect();\n\n Object.assign(wrapper.style, {\n display: \"flex\",\n flexDirection: \"column\",\n width: `${width}px`,\n position: \"absolute\",\n pointerEvents: \"none\",\n zIndex: \"9999\",\n left: \"-9999px\",\n });\n\n dragImage = wrapper;\n }\n\n document.body.appendChild(dragImage);\n }\n\n data.e.dataTransfer.setDragImage(dragImage, data.e.offsetX, data.e.offsetY);\n\n setTimeout(() => {\n dragImage?.remove();\n });\n }\n\n return dragState;\n}\n\nexport function validateDragHandle({\n x,\n y,\n node,\n config,\n}: {\n x: number;\n y: number;\n node: NodeRecord;\n config: ParentConfig;\n}): boolean {\n if (config.externalDragHandle) return false;\n\n if (!config.dragHandle) return true;\n\n const dragHandles = node.el.querySelectorAll(config.dragHandle);\n\n if (!dragHandles) return false;\n\n const elFromPoint = config.root.elementFromPoint(x, y);\n\n if (!elFromPoint) return false;\n\n for (const handle of Array.from(dragHandles))\n if (elFromPoint === handle || handle.contains(elFromPoint)) return true;\n\n return false;\n}\n\nexport function handleClickNode(_data: NodeEventData) {}\n\nexport function handleClickParent(_data: ParentEventData) {}\n\nexport function handleNodeKeydown(_data: NodeEventData) {}\n\nexport function handleParentKeydown(\n data: ParentKeydownEventData,\n state: BaseDragState\n) {\n const activeDescendant = state.activeState?.node;\n\n if (!activeDescendant) return;\n\n const parentData = data.targetData.parent.data;\n\n const enabledNodes = parentData.enabledNodes;\n\n if (!(data.e.target instanceof HTMLElement)) return;\n const index = enabledNodes.findIndex((x) => x.el === activeDescendant.el);\n\n if (index === -1) return;\n\n if (\n [\"ArrowDown\", \"ArrowUp\", \"ArrowRight\", \"ArrowLeft\"].includes(data.e.key)\n ) {\n pd(data.e);\n\n const nextIndex =\n data.e.key === \"ArrowDown\" || data.e.key === \"ArrowRight\"\n ? index + 1\n : index - 1;\n\n if (nextIndex < 0 || nextIndex >= enabledNodes.length) return;\n\n const nextNode = enabledNodes[nextIndex];\n\n setActive(data.targetData.parent, nextNode, state);\n } else if (data.e.key === \" \") {\n pd(data.e);\n\n state.selectedState && state.selectedState.nodes.includes(activeDescendant)\n ? setSelected(\n data.targetData.parent,\n state.selectedState.nodes.filter((x) => x.el !== activeDescendant.el),\n activeDescendant,\n state\n )\n : setSelected(\n data.targetData.parent,\n [activeDescendant],\n activeDescendant,\n state\n );\n } else if (data.e.key === \"Enter\" && state.selectedState) {\n if (\n state.selectedState.parent.el === data.targetData.parent.el &&\n state.activeState\n ) {\n if (state.selectedState.nodes[0].el === state.activeState.node.el) {\n updateLiveRegion(data.targetData.parent, \"Cannot drop item on itself\");\n\n return;\n }\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n parentData.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.selectedState.nodes,\n targetNodes: [state.activeState.node],\n });\n\n deselect([], data.targetData.parent, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n } else if (\n state.activeState &&\n state.selectedState.parent.el !== data.targetData.parent.el &&\n validateTransfer({\n currentParent: data.targetData.parent,\n targetParent: state.selectedState.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n state,\n })\n ) {\n parentData.config.performTransfer({\n currentParent: state.selectedState.parent,\n targetParent: data.targetData.parent,\n initialParent: state.selectedState.parent,\n draggedNodes: state.selectedState.nodes,\n initialIndex: state.selectedState.nodes[0].data.index,\n state,\n targetNodes: [state.activeState.node],\n });\n\n state.newActiveDescendant = state.selectedState.nodes[0];\n\n setSelected(data.targetData.parent, [], undefined, state);\n\n updateLiveRegion(data.targetData.parent, \"Drop successful\");\n }\n }\n}\n\n/**\n * Prevent the sort on scroll.\n *\n * @returns A function to prevent the sort on scroll.\n */\nexport function preventSortOnScroll() {\n let scrollTimeout: ReturnType;\n\n return () => {\n clearTimeout(scrollTimeout);\n\n if (state) state.preventEnter = true;\n\n scrollTimeout = setTimeout(() => {\n if (state) state.preventEnter = false;\n }, 100);\n };\n}\n\n/**\n * Handle the node pointer over.\n *\n * @param e - The node pointer over event.\n *\n * @returns void\n */\nexport function handleNodePointerover(e: PointeroverNodeEvent) {\n if (e.detail.targetData.parent.el === e.detail.state.currentParent.el)\n sort(e.detail, e.detail.state);\n else transfer(e.detail, e.detail.state);\n}\n\n/**\n * Handle the node drop.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDrop(\n data: NodeDragEventData,\n state: DragState | SynthDragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n sp(data.e);\n\n dropped = true;\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleDragend(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n config.handleEnd(state);\n}\n\n/**\n * Handle the pointer cancel.\n *\n * @param data - The node event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handlePointercancel(\n data: NodeEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n if (!isSynthDragState(state)) return;\n pd(data.e);\n\n if (dropped) {\n dropped = false;\n\n return;\n }\n\n const config = parents.get(state.initialParent.el)?.config;\n\n if (config?.onDragend) {\n config.onDragend({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n }\n\n config?.handleEnd(state);\n}\n\n/**\n * Handle the drag end.\n *\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleEnd(state: DragState | SynthDragState) {\n if (state.draggedNode) state.draggedNode.el.draggable = false;\n\n document.body.style.userSelect = state.rootUserSelect || \"\";\n\n if (isSynthDragState(state)) {\n document.documentElement.style.overscrollBehavior =\n state.rootOverScrollBehavior || \"\";\n\n document.documentElement.style.touchAction = state.rootTouchAction || \"\";\n }\n\n if (isSynthDragState(state)) cancelSynthScroll(state);\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n const config = parents.get(state.initialParent.el)?.config;\n\n const isSynth = isSynthDragState(state);\n\n const dropZoneClass = isSynth\n ? config?.synthDropZoneClass\n : config?.dropZoneClass;\n\n if (state.originalZIndex !== undefined)\n state.draggedNode.el.style.zIndex = state.originalZIndex;\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n dropZoneClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n state.initialParent.data?.config?.longPressClass\n );\n\n removeClass(\n state.draggedNodes.map((x) => x.el),\n isSynth\n ? state.initialParent.data.config.synthDragPlaceholderClass\n : state.initialParent.data?.config?.dragPlaceholderClass\n );\n\n if (isSynth) state.clonedDraggedNode.remove();\n\n deselect(state.draggedNodes, state.currentParent, state);\n\n setActive(state.currentParent, undefined, state);\n\n resetState();\n\n state.selectedState = undefined;\n\n config?.onDragend?.({\n parent: state.currentParent,\n values: parentValues(state.currentParent.el, state.currentParent.data),\n draggedNode: state.draggedNode,\n draggedNodes: state.draggedNodes,\n state,\n });\n\n state.emit(\"dragEnded\", state);\n}\n\n/**\n * Handle the node pointer up.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodePointerup(\n data: NodePointerEventData,\n state: DragState | SynthDragState | BaseDragState\n) {\n sp(data.e);\n\n state.pointerDown = undefined;\n if (!state.pointerSelection && state.selectedState)\n deselect(state.selectedState.nodes, data.targetData.parent, state);\n\n const config = data.targetData.parent.data.config;\n\n state.pointerSelection = false;\n\n if (\"longPressTimeout\" in state && state.longPressTimeout)\n clearTimeout(state.longPressTimeout);\n\n removeClass(\n data.targetData.parent.data.enabledNodes.map((x) => x.el),\n config.longPressClass\n );\n\n if (!isDragState(state)) return;\n\n config.handleEnd(state as DragState | SynthDragState);\n}\n\n/**\n * Initialize the synth drag.\n *\n * @param node - The node.\n * @param parent - The parent.\n * @param e - The pointer event.\n * @param _state - The drag state.\n * @param draggedNodes - The dragged nodes.\n *\n * @returns The synth drag state.\n */\nfunction initSynthDrag(\n node: NodeRecord,\n parent: ParentRecord,\n e: PointerEvent,\n _state: BaseDragState,\n draggedNodes: Array>\n): SynthDragState {\n const config = parent.data.config;\n\n let dragImage: HTMLElement | undefined;\n\n let display = node.el.style.display;\n\n let result = undefined;\n\n if (config.synthDragImage) {\n result = config.synthDragImage(node, parent, e, draggedNodes);\n\n dragImage = result.dragImage;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n zIndex: 9999,\n pointerEvents: \"none\",\n margin: 0,\n overflow: \"hidden\",\n display: \"none\",\n });\n } else {\n if (!config.multiDrag || draggedNodes.length === 1) {\n console.log(\"boom\");\n dragImage = node.el.cloneNode(true) as HTMLElement;\n\n copyNodeStyle(node.el, dragImage);\n\n dragImage.id = \"dnd-dragged-node-clone\";\n\n display = dragImage.style.display;\n\n dragImage.setAttribute(\"popover\", \"manual\");\n\n Object.assign(dragImage.style, {\n position: \"absolute\",\n height: node.el.getBoundingClientRect().height + \"px\",\n width: node.el.getBoundingClientRect().width + \"px\",\n overflow: \"hidden\",\n margin: 0,\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n } else {\n const wrapper = document.createElement(\"div\");\n console.log(\"getting here\");\n\n wrapper.setAttribute(\"popover\", \"manual\");\n\n for (const node of draggedNodes) {\n const clonedNode = node.el.cloneNode(true) as HTMLElement;\n\n copyNodeStyle(node.el, clonedNode);\n\n clonedNode.style.pointerEvents = \"none\";\n\n wrapper.append(clonedNode);\n }\n\n display = wrapper.style.display;\n\n wrapper.id = \"dnd-dragged-node-clone\";\n\n dragImage = wrapper;\n\n Object.assign(dragImage.style, {\n display: \"flex\",\n flexDirection: \"column\",\n position: \"absolute\",\n overflow: \"hidden\",\n margin: 0,\n padding: 0,\n pointerEvents: \"none\",\n zIndex: 9999,\n });\n }\n }\n\n dragImage.style.position = \"absolute\";\n\n parent.el.appendChild(dragImage);\n\n dragImage.showPopover();\n\n const synthDragStateProps = {\n clonedDraggedEls: [],\n clonedDraggedNode: dragImage,\n draggedNodeDisplay: display,\n synthDragScrolling: false,\n synthDragging: true,\n rootScrollWidth: document.scrollingElement?.scrollWidth,\n rootScrollHeight: document.scrollingElement?.scrollHeight,\n rootOverScrollBehavior: document.documentElement.style.overscrollBehavior,\n rootTouchAction: document.documentElement.style.touchAction,\n };\n\n document.documentElement.style.overscrollBehavior = \"none\";\n\n document.documentElement.style.touchAction = \"none\";\n\n const synthDragState = setDragState({\n ...dragStateProps(\n node,\n parent,\n e,\n draggedNodes,\n result?.offsetX,\n result?.offsetY\n ),\n ...synthDragStateProps,\n }) as SynthDragState;\n\n synthDragState.clonedDraggedNode.style.display =\n synthDragState.draggedNodeDisplay || \"\";\n\n return synthDragState;\n}\n\n/**\n * Handle the long press.\n *\n * @param data - The node pointer event data.\n * @param state - The drag state.\n * @param node - The node.\n *\n * @returns void\n */\nexport function handleLongPress(\n data: NodePointerEventData,\n state: BaseDragState,\n node: NodeRecord\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.longPress) return;\n\n state.longPressTimeout = setTimeout(() => {\n if (!state) return;\n\n state.longPress = true;\n\n if (config.longPressClass && data.e.cancelable)\n addNodeClass([node.el], config.longPressClass);\n\n pd(data.e);\n }, config.longPressDuration || 200);\n}\n\nfunction pointermoveClasses(\n state: SynthDragState,\n config: ParentConfig\n) {\n if (config.longPressClass)\n removeClass(\n state.draggedNodes.map((x) => x.el),\n config?.longPressClass\n );\n}\n\nfunction cancelSynthScroll(\n state: SynthDragState,\n cancelX = true,\n cancelY = true\n) {\n if (cancelX && state.animationFrameIdX !== undefined) {\n cancelAnimationFrame(state.animationFrameIdX);\n\n state.animationFrameIdX = undefined;\n }\n\n if (cancelY && state.animationFrameIdY !== undefined) {\n cancelAnimationFrame(state.animationFrameIdY);\n\n state.animationFrameIdY = undefined;\n }\n\n if (!state.animationFrameIdX && !state.animationFrameIdY) {\n state.preventEnter = false;\n }\n}\n\nfunction moveNode(\n e: PointerEvent,\n state: SynthDragState,\n scrollX = 0,\n scrollY = 0\n) {\n const { x, y } = eventCoordinates(e);\n\n state.coordinates.y = y;\n state.coordinates.x = x;\n\n const startLeft = state.startLeft ?? 0;\n const startTop = state.startTop ?? 0;\n\n // Calculate the translation values\n const translateX = x - startLeft + window.scrollX;\n const translateY = y - startTop + window.scrollY;\n\n // Apply the transform using translate\n state.clonedDraggedNode.style.transform = `translate(${\n translateX + scrollX\n }px, ${translateY + scrollY}px)`;\n\n if (e.cancelable) pd(e);\n\n pointermoveClasses(state, state.initialParent.data.config);\n}\n\n/**\n * Handle the synth move.\n *\n * @param e - The pointer event.\n * @param state - The synth drag state.\n *\n * @returns void\n */\nexport function synthMove(e: PointerEvent, state: SynthDragState) {\n moveNode(e, state);\n\n const coordinates = eventCoordinates(e);\n\n handleSynthScroll(coordinates, e, state);\n\n const elFromPoint = getElFromPoint(coordinates);\n\n if (!elFromPoint) {\n document.dispatchEvent(\n new CustomEvent(\"handleRootPointerover\", {\n detail: {\n e,\n state,\n },\n })\n );\n\n return;\n }\n const pointerMoveEventData = {\n e,\n targetData: elFromPoint,\n state,\n };\n\n if (\"node\" in elFromPoint) {\n elFromPoint.node.el.dispatchEvent(\n new CustomEvent(\"handleNodePointerover\", {\n detail: pointerMoveEventData,\n })\n );\n } else {\n elFromPoint.parent.el.dispatchEvent(\n new CustomEvent(\"handleParentPointerover\", {\n detail: pointerMoveEventData,\n })\n );\n }\n}\n\n/**\n * Handle the node drag over.\n *\n * @param data - The node drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleNodeDragover(\n data: NodeDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n const { x, y } = eventCoordinates(data.e);\n\n state.coordinates.y = y;\n\n state.coordinates.x = x;\n\n pd(data.e);\n\n sp(data.e);\n\n data.targetData.parent.el === state.currentParent?.el\n ? sort(data, state)\n : transfer(data, state);\n}\n\n/**\n * Handle the parent drag over.\n *\n * @param data - The parent drag event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function handleParentDragover(\n data: ParentDragEventData,\n state: DragState\n) {\n const config = data.targetData.parent.data.config;\n\n if (!config.nativeDrag) return;\n\n pd(data.e);\n\n sp(data.e);\n\n Object.assign(eventCoordinates(data.e));\n\n transfer(data, state);\n}\n\n/**\n * Handle the parent pointer over.\n *\n * @param e - The parent pointer over event.\n *\n * @returns void\n */\nexport function handleParentPointerover(e: PointeroverParentEvent) {\n if (e.detail.targetData.parent.el !== e.detail.state.currentParent.el)\n transfer(e.detail, e.detail.state);\n}\n\n/**\n * Validate the transfer.\n *\n * @param data - The transfer data.\n *\n * @returns Whether the transfer is valid.\n */\nexport function validateTransfer({\n currentParent,\n targetParent,\n initialParent,\n draggedNodes,\n state,\n}: {\n currentParent: ParentRecord;\n targetParent: ParentRecord;\n initialParent: ParentRecord;\n draggedNodes: Array>;\n state: BaseDragState;\n}) {\n if (targetParent.el === currentParent.el) return false;\n\n const targetConfig = targetParent.data.config;\n\n if (draggedNodes[0].el.contains(targetParent.el)) return false;\n\n if (targetConfig.dropZone === false) return false;\n\n const initialParentConfig = initialParent.data.config;\n\n if (targetConfig.accepts) {\n return targetConfig.accepts(\n targetParent,\n initialParent,\n currentParent,\n state\n );\n } else if (\n !targetConfig.group ||\n targetConfig.group !== initialParentConfig.group\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Handle the node drag enter.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragenter(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Handle the node drag leave.\n *\n * @param data - The node drag event data.\n * @param _state - The drag state.\n *\n * @returns void\n */\nfunction handleNodeDragleave(\n data: NodeDragEventData,\n _state: DragState\n) {\n pd(data.e);\n}\n\n/**\n * Validate the sort.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n * @param x - The x coordinate.\n * @param y - The y coordinate.\n *\n * @returns Whether the sort is valid.\n */\nexport function validateSort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState,\n x: number,\n y: number\n): boolean {\n if (\n state.affectedNodes\n .map((x) => x.data.value)\n .includes(data.targetData.node.data.value)\n ) {\n return false;\n }\n\n if (state.remapJustFinished) {\n state.remapJustFinished = false;\n\n if (\n data.targetData.node.data.value === state.currentTargetValue ||\n state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)\n ) {\n state.currentTargetValue = data.targetData.node.data.value;\n }\n\n return false;\n }\n\n if (state.preventEnter) return false;\n\n if (state.draggedNodes.map((x) => x.el).includes(data.targetData.node.el)) {\n state.currentTargetValue = undefined;\n\n return false;\n }\n\n if (data.targetData.node.data.value === state.currentTargetValue)\n return false;\n\n if (\n data.targetData.parent.el !== state.currentParent?.el ||\n data.targetData.parent.data.config.sortable === false\n )\n return false;\n\n if (data.targetData.node.el.contains(state.draggedNodes[0].el)) return false;\n\n const targetRect = data.targetData.node.el.getBoundingClientRect();\n\n const dragRect = state.draggedNode.el.getBoundingClientRect();\n\n const yDiff = targetRect.y - dragRect.y;\n\n const xDiff = targetRect.x - dragRect.x;\n\n let incomingDirection: \"above\" | \"below\" | \"left\" | \"right\";\n\n if (Math.abs(yDiff) > Math.abs(xDiff)) {\n incomingDirection = yDiff > 0 ? \"above\" : \"below\";\n } else {\n incomingDirection = xDiff > 0 ? \"left\" : \"right\";\n }\n\n const threshold = state.currentParent.data.config.threshold;\n\n switch (incomingDirection) {\n case \"left\":\n if (x > targetRect.x + targetRect.width * threshold.horizontal) {\n state.incomingDirection = \"left\";\n\n return true;\n }\n break;\n\n case \"right\":\n if (x < targetRect.x + targetRect.width * (1 - threshold.horizontal)) {\n state.incomingDirection = \"right\";\n\n return true;\n }\n break;\n\n case \"above\":\n if (y > targetRect.y + targetRect.height * threshold.vertical) {\n state.incomingDirection = \"above\";\n\n return true;\n }\n break;\n\n case \"below\":\n if (y < targetRect.y + targetRect.height * (1 - threshold.vertical)) {\n state.incomingDirection = \"below\";\n\n return true;\n }\n break;\n\n default:\n break;\n }\n\n return false;\n}\n\n/**\n * Sort the nodes.\n *\n * @param data - The node drag event data or node pointer event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function sort(\n data: NodeDragEventData | NodePointerEventData,\n state: DragState\n) {\n const { x, y } = eventCoordinates(data.e);\n\n if (!validateSort(data, state, x, y)) return;\n\n const range =\n state.draggedNode.data.index > data.targetData.node.data.index\n ? [data.targetData.node.data.index, state.draggedNode.data.index]\n : [state.draggedNode.data.index, data.targetData.node.data.index];\n\n state.targetIndex = data.targetData.node.data.index;\n\n state.affectedNodes = data.targetData.parent.data.enabledNodes.filter(\n (node) => {\n return (\n range[0] <= node.data.index &&\n node.data.index <= range[1] &&\n node.el !== state.draggedNode.el\n );\n }\n );\n\n data.targetData.parent.data.config.performSort({\n parent: data.targetData.parent,\n draggedNodes: state.draggedNodes,\n targetNodes: [data.targetData.node],\n });\n}\n\n/**\n * Event listener used for all nodes.\n *\n * @param e - The event.\n *\n */\nexport function nodeEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function nodeTargetData(node: Node): NodeTargetData | undefined {\n const nodeData = nodes.get(node);\n\n if (!nodeData) return;\n\n const parentData = parents.get(node.parentNode);\n\n if (!parentData) return;\n\n return {\n node: {\n el: node,\n data: nodeData,\n },\n parent: {\n el: node.parentNode,\n data: parentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = nodeTargetData(e.currentTarget as Node);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\n/**\n * Transfer the nodes.\n *\n * @param data - The node event data or parent event data.\n * @param state - The drag state.\n *\n * @returns void\n */\nexport function transfer(\n data: NodeEventData | ParentEventData,\n state: DragState\n): void {\n if (\n !validateTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent as any,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n state,\n })\n )\n return;\n\n data.targetData.parent.data.config.performTransfer({\n currentParent: state.currentParent,\n targetParent: data.targetData.parent,\n initialParent: state.initialParent,\n draggedNodes: state.draggedNodes,\n initialIndex: state.initialIndex,\n state,\n targetNodes: \"node\" in data.targetData ? [data.targetData.node] : [],\n });\n\n state.currentParent = data.targetData.parent;\n\n state.transferred = true;\n}\n\n/**\n * Event listener used for all parents.\n *\n * @param callback - The callback.\n *\n * @returns A function to get the parent event data.\n */\nexport function parentEventData(\n callback: any\n): (e: Event) => NodeEventData | undefined {\n function parentTargetData(\n parent: HTMLElement\n ): ParentTargetData | undefined {\n const parentData = parents.get(parent);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: parent,\n data: parentData as ParentData,\n },\n };\n }\n\n return (e: Event) => {\n const targetData = parentTargetData(e.currentTarget as HTMLElement);\n\n if (!targetData) return;\n\n return callback(\n {\n e,\n targetData,\n },\n state\n );\n };\n}\n\n/**\n * Add class to the node.\n *\n * @param els - The nodes.\n * @param className - The class name.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addNodeClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function nodeSetter(node: Node, nodeData: NodeData) {\n nodes.set(node, nodeData);\n }\n\n for (const el of els) {\n const nodeData = nodes.get(el as Node);\n\n const newData = addClass(el, className, nodeData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n nodeSetter(el as Node, newData as NodeData);\n }\n}\n\n/**\n * Add class to the parent.\n *\n * @param els - The parents.\n * @param className - The class name.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addParentClass(\n els: Array,\n className: string | undefined,\n omitAppendPrivateClass = false\n) {\n function parentSetter(parent: HTMLElement, parentData: ParentData) {\n parents.set(parent, parentData);\n }\n\n for (const el of els) {\n const parentData = parents.get(el);\n\n const newData = addClass(el, className, parentData, omitAppendPrivateClass);\n\n if (!newData) continue;\n\n parentSetter(el, newData as ParentData);\n }\n}\n\n/**\n * Add class to the node.\n *\n * @param el - The node.\n * @param className - The class name.\n * @param data - The node data.\n * @param omitAppendPrivateClass - Whether to omit append private class.\n *\n * @returns void\n */\nexport function addClass(\n el: Node | HTMLElement | Element,\n className: string | undefined,\n data: NodeData | ParentData | undefined,\n omitAppendPrivateClass = false\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n if (classNames.includes(\"longPress\")) return;\n\n if (!data) {\n el.classList.add(...classNames);\n\n return;\n }\n\n const privateClasses = [];\n\n for (const className of classNames) {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n } else if (\n el.classList.contains(className) &&\n omitAppendPrivateClass === false\n ) {\n privateClasses.push(className);\n }\n }\n\n data.privateClasses = privateClasses;\n\n return data;\n}\n\n/**\n * Remove class from the nodes.\n *\n * @param els - The nodes.\n * @param className - The class name.\n *\n * @returns void\n */\nexport function removeClass(\n els: Array,\n className: string | undefined\n) {\n if (!className) return;\n\n const classNames = splitClass(className);\n\n if (!classNames.length) return;\n\n for (const node of els) {\n if (!isNode(node)) {\n node.classList.remove(...classNames);\n continue;\n }\n\n const nodeData = nodes.get(node) || parents.get(node);\n\n if (!nodeData) continue;\n\n for (const className of classNames) {\n if (!nodeData.privateClasses.includes(className)) {\n node.classList.remove(className);\n }\n }\n }\n}\n\n/**\n * Check if the element is scrollable on the x axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param style - The style.\n * @param rect - The rect.\n * @param state - The state.\n *\n * @returns void\n */\nfunction isScrollX(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect,\n state: SynthDragState\n): { left: boolean; right: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n const canScrollLeft = el.scrollLeft > 0;\n const canScrollRight =\n el.scrollLeft + window.innerWidth < (state.rootScrollWidth || 0);\n\n return {\n right: canScrollRight && e.clientX > el.clientWidth * (1 - threshold),\n left: canScrollLeft && e.clientX < el.clientWidth * threshold,\n };\n }\n\n if (\n (style.overflowX === \"auto\" || style.overflowX === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollWidth = el.scrollWidth;\n const offsetWidth = el.offsetWidth;\n const scrollLeft = el.scrollLeft;\n\n return {\n right:\n e.clientX > rect.left + offsetWidth * (1 - threshold) &&\n scrollLeft < scrollWidth - offsetWidth,\n left: e.clientX < rect.left + offsetWidth * threshold && scrollLeft > 0,\n };\n }\n\n return {\n right: false,\n left: false,\n };\n}\n\n/**\n * Check if the element is scrollable on the y axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param style - The style.\n * @param rect - The rect.\n *\n * @returns void\n */\nfunction isScrollY(\n el: HTMLElement,\n e: PointerEvent,\n style: CSSStyleDeclaration,\n rect: DOMRect\n): { up: boolean; down: boolean } {\n const threshold = 0.1;\n\n if (el === document.scrollingElement) {\n return {\n down: e.clientY > el.clientHeight * (1 - threshold),\n up: e.clientY < el.clientHeight * threshold,\n };\n }\n\n if (\n (style.overflowY === \"auto\" || style.overflowY === \"scroll\") &&\n el !== document.body &&\n el !== document.documentElement\n ) {\n const scrollHeight = el.scrollHeight;\n const offsetHeight = el.offsetHeight;\n const scrollTop = el.scrollTop;\n\n return {\n down:\n e.clientY > rect.top + offsetHeight * (1 - threshold) &&\n scrollTop < scrollHeight - offsetHeight,\n up: e.clientY < rect.top + offsetHeight * threshold && scrollTop > 0,\n };\n }\n\n return {\n down: false,\n up: false,\n };\n}\n\n/**\n * Scroll the element on the x axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param state - The state.\n * @param right - Whether to scroll right.\n *\n * @returns void\n */\nfunction scrollX(\n el: HTMLElement,\n e: PointerEvent,\n state: SynthDragState,\n right = true\n) {\n state.preventEnter = true;\n\n const incr = right ? 5 : -5;\n\n function scroll(el: HTMLElement) {\n el.scrollBy({ left: incr });\n\n moveNode(e, state, incr, 0);\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n }\n\n state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el));\n}\n\n/**\n * Scroll the element on the y axis.\n *\n * @param el - The element.\n * @param e - The event.\n * @param state - The state.\n * @param up - Whether to scroll up.\n *\n * @returns void\n */\nfunction scrollY(\n el: Element,\n e: PointerEvent,\n state: SynthDragState,\n up = true\n) {\n state.preventEnter = true;\n\n const incr = up ? -5 : 5;\n\n function scroll() {\n el.scrollBy({ top: incr });\n\n moveNode(e, state, 0, incr);\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n }\n\n state.animationFrameIdY = requestAnimationFrame(scroll);\n}\n\n/**\n * Handle the synth scroll.\n *\n * @param coordinates - The coordinates.\n * @param e - The event.\n * @param state - The state.\n *\n * @returns void\n */\nfunction handleSynthScroll(\n coordinates: { x: number; y: number },\n e: PointerEvent,\n state: SynthDragState\n) {\n cancelSynthScroll(state);\n\n const scrollables: Record<\"x\" | \"y\", HTMLElement | null> = {\n x: null,\n y: null,\n };\n\n const els = document.elementsFromPoint(coordinates.x, coordinates.y);\n\n for (const el of els) {\n if (scrollables.x && scrollables.y) break;\n\n if (!(el instanceof HTMLElement)) continue;\n\n const rect = el.getBoundingClientRect();\n\n const style = window.getComputedStyle(el);\n\n if (!scrollables.x) {\n const { left, right } = isScrollX(el, e, style, rect, state);\n\n if (left || right) {\n scrollables.x = el;\n\n scrollX(el, e, state, right);\n }\n }\n\n if (!scrollables.y) {\n const { up, down } = isScrollY(el, e, style, rect);\n\n if (up || down) {\n scrollables.y = el;\n\n scrollY(el, e, state, up);\n }\n }\n }\n}\n\nexport function getElFromPoint(coordinates: {\n x: number;\n y: number;\n}): NodeFromPoint | ParentFromPoint | undefined {\n let target = document.elementFromPoint(coordinates.x, coordinates.y);\n\n if (!isNode(target)) return;\n\n let isParent;\n\n let invalidEl = true;\n\n while (target && invalidEl) {\n if (nodes.has(target as Node) || parents.has(target as HTMLElement)) {\n invalidEl = false;\n\n isParent = parents.has(target as HTMLElement);\n\n break;\n }\n\n target = target.parentNode as Node;\n }\n\n if (!isParent) {\n const targetNodeData = nodes.get(target as Node);\n\n if (!targetNodeData) return;\n\n const targetParentData = parents.get(target.parentNode as Node);\n\n if (!targetParentData) return;\n\n return {\n node: {\n el: target as Node,\n data: targetNodeData,\n },\n parent: {\n el: target.parentNode as Node,\n data: targetParentData as ParentData,\n },\n };\n } else {\n const parentData = parents.get(target as HTMLElement);\n\n if (!parentData) return;\n\n return {\n parent: {\n el: target as HTMLElement,\n data: parentData as ParentData,\n },\n };\n }\n}\n\n/**\n * Checks to see that a given element and its parent node is instance of\n * HTMLElement.\n *\n * @param {unknown} el - The element to check.\n *\n * @returns {boolean} - Whether or not provided element is of type Node.\n */\nexport function isNode(el: unknown): el is Node {\n return el instanceof HTMLElement && el.parentNode instanceof HTMLElement;\n}\n\n/**\n * Takes a given el and event handlers, assigns them, and returns the used abort\n * controller.\n *\n * @param el - The element to add the event listeners to.\n * @param events - The events to add to the element.\n * @returns - The abort controller used for the event listeners.\n */\nexport function addEvents(\n el: Document | ShadowRoot | Node | HTMLElement | Window,\n events: EventHandlers | any\n): AbortController {\n const abortController = new AbortController();\n\n for (const eventName in events) {\n const handler = events[eventName];\n\n el.addEventListener(eventName, handler, {\n signal: abortController.signal,\n passive: false,\n });\n }\n\n return abortController;\n}\n"],"mappings":";AAKO,SAAS,GAAG,GAAU;AAC3B,IAAE,eAAe;AACnB;AAOO,SAAS,GAAG,GAAU;AAC3B,IAAE,gBAAgB;AACpB;AAWO,SAAS,gBAAmB;AACjC,QAA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I;AAEJ,MAAI,YAAY;AAEhB,SAAO,UAAU,WAAW;AAC1B,QAAI,MAAM,IAAI,MAAc,KAAK,QAAQ,IAAI,MAAqB,GAAG;AACnE,kBAAY;AAEZ,iBAAW,QAAQ,IAAI,MAAqB;AAE5C;AAAA,IACF;AAEA,aAAS,OAAO;AAAA,EAClB;AAEA,MAAI,CAAC,UAAU;AACb,UAAM,iBAAiB,MAAM,IAAI,MAAc;AAE/C,QAAI,CAAC,eAAgB;AAErB,UAAM,mBAAmB,QAAQ,IAAI,OAAO,UAAkB;AAE9D,QAAI,CAAC,iBAAkB;AAEvB,WAAO;AAAA,MACL,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,MACA,QAAQ;AAAA,QACN,IAAI,OAAO;AAAA,QACX,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,OAAO;AACL,UAAM,aAAa,QAAQ,IAAI,MAAqB;AAEpD,QAAI,CAAC,WAAY;AAEjB,WAAO;AAAA,MACL,QAAQ;AAAA,QACN,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AAUO,SAAS,OAAO,IAAyB;AAC9C,SAAO,cAAc,eAAe,GAAG,sBAAsB;AAC/D;AAUO,SAAS,UACd,IACA,QACiB;AACjB,QAAM,kBAAkB,IAAI,gBAAgB;AAE5C,aAAW,aAAa,QAAQ;AAC9B,UAAM,UAAU,OAAO,SAAS;AAEhC,OAAG,iBAAiB,WAAW,SAAS;AAAA,MACtC,QAAQ,gBAAgB;AAAA,MACxB,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":["emit","on","state","insertState","state","draggedParentValues","documentController","handleNodeDragover","handleParentDragover","state","handleEnd","documentController","baseDragState","dragStateProps","nodes","emit","on","handleNodeDragover","handleParentDragover","handleEnd","handleNodePointerover","handleParentPointerover","draggedNodes","state","parent","x","scrollTimeout","node","scrollX","scrollY","className","el"]} \ No newline at end of file diff --git a/docs/components/TheHero.vue b/docs/components/TheHero.vue index 4610cc98..d3c2a72c 100644 --- a/docs/components/TheHero.vue +++ b/docs/components/TheHero.vue @@ -42,8 +42,9 @@ const features = ref([ dragAndDrop({ parent: dragList, values: features, - draggingClass: "[&>.card]:-rotate-2 before:-rotate-2", dropZoneClass: "blur-[2px] opacity-60", + synthDropZoneClass: "blur-[2px] opacity-60", + synthDraggingClass: "rounded-md", }); function toggleFrameworkList(setting: boolean) { @@ -340,17 +341,10 @@ onMounted(() => { m-2 cursor-grab active:cursor-grabbing - active:shadow-xl active:select-none - before:absolute - before:z-[-1] - before:bg-pink-500 - before:top-[3px] - before:-left-[3px] - before:w-full - before:h-full - before:rounded-md + + dark:before:bg-pink-400 `" @@ -365,8 +359,6 @@ onMounted(() => { grow w-full bg-white - border-t - border-r border-sky-500 text-center diff --git a/docs/examples/ToDos.vue b/docs/examples/ToDos.vue index e4852739..3dfc48cc 100644 --- a/docs/examples/ToDos.vue +++ b/docs/examples/ToDos.vue @@ -60,6 +60,10 @@ const todoConfig = { })(), dropZoneClass: !props.insert ? "!bg-lime-200" : undefined, dropZoneParentClass: !props.insert ? "!border-4 border-lime-300" : undefined, + synthDropZoneClass: !props.insert ? "!bg-lime-200" : undefined, + synthDropZoneParentClass: !props.insert + ? "!border-4 border-lime-300" + : undefined, }; const doneConfig = { @@ -94,6 +98,10 @@ const doneConfig = { })(), dropZoneClass: !props.insert ? "!bg-lime-200" : undefined, dropZoneParentClass: !props.insert ? "!border-4 border-lime-300" : undefined, + synthDropZoneClass: !props.insert ? "!bg-lime-200" : undefined, + synthDropZoneParentClass: !props.insert + ? "!border-4 border-lime-300" + : undefined, }; const [todoList, todos] = useDragAndDrop( diff --git a/docs/examples/draggable/demo.vue b/docs/examples/draggable/demo.vue index 191017bb..62114387 100644 --- a/docs/examples/draggable/demo.vue +++ b/docs/examples/draggable/demo.vue @@ -15,6 +15,8 @@ dragAndDrop({ parent: dragList, values: tapes, dropZoneClass: "saturate-0 opacity-20", + synthDropZoneClass: "saturate-0 opacity-20", + synthDraggingClass: "bg-transparent", draggable: (el: HTMLElement) => { return el.id !== "no-drag"; }, diff --git a/docs/examples/sorting/demo.vue b/docs/examples/sorting/demo.vue index 28f482b8..cd35fd5e 100644 --- a/docs/examples/sorting/demo.vue +++ b/docs/examples/sorting/demo.vue @@ -14,6 +14,8 @@ dragAndDrop({ parent: dragList, values: tapes, dropZoneClass: "saturate-0 opacity-20", + synthDropZoneClass: "saturate-0 opacity-20", + synthDraggingClass: "bg-transparent", }); diff --git a/docs/examples/update-config/demo.vue b/docs/examples/update-config/demo.vue index 491b0e61..6238dfbe 100644 --- a/docs/examples/update-config/demo.vue +++ b/docs/examples/update-config/demo.vue @@ -3,14 +3,21 @@ import { useDragAndDrop } from "../../../src/vue/index"; const disabled = ref(false); -const [parentRef, values, updateConfig] = useDragAndDrop([ - "Depeche Mode", - "Duran Duran", - "Pet", - "Kraftwerk", - "Tears for Fears", - "Spandau Ballet", -]); +const [parentRef, values, updateConfig] = useDragAndDrop( + [ + "Depeche Mode", + "Duran Duran", + "Pet", + "Kraftwerk", + "Tears for Fears", + "Spandau Ballet", + ], + { + dropZoneClass: "saturate-0 opacity-20", + synthDropZoneClass: "saturate-0 opacity-20", + synthDraggingClass: "bg-transparent", + } +); function toggleDisabled() { disabled.value = !disabled.value; diff --git a/docs/nuxt.config.ts b/docs/nuxt.config.ts index 37a0fac7..2ad75dba 100644 --- a/docs/nuxt.config.ts +++ b/docs/nuxt.config.ts @@ -19,7 +19,7 @@ export default defineNuxtConfig({ css: ["@/assets/css/main.css"], experimental: { - componentIslands: true, + componentIslands: false, }, runtimeConfig: { diff --git a/src/index.ts b/src/index.ts index 9ed7499d..944e1684 100644 --- a/src/index.ts +++ b/src/index.ts @@ -270,16 +270,6 @@ export function copyNodeStyle( computedStyle.getPropertyPriority(key) ); } - - for (const child of Array.from(sourceNode.children)) { - if (!isNode(child)) continue; - - const targetChild = targetNode.children[ - Array.from(sourceNode.children).indexOf(child) - ] as Node; - - copyNodeStyle(child, targetChild, omitKeys); - } } /** @@ -2187,8 +2177,11 @@ function initSynthDrag( }); } else { if (!config.multiDrag || draggedNodes.length === 1) { + console.log("boom"); dragImage = node.el.cloneNode(true) as HTMLElement; + copyNodeStyle(node.el, dragImage); + dragImage.id = "dnd-dragged-node-clone"; display = dragImage.style.display; @@ -2206,29 +2199,36 @@ function initSynthDrag( }); } else { const wrapper = document.createElement("div"); + console.log("getting here"); - wrapper.setAttribute("popover", ""); + wrapper.setAttribute("popover", "manual"); for (const node of draggedNodes) { const clonedNode = node.el.cloneNode(true) as HTMLElement; + copyNodeStyle(node.el, clonedNode); + clonedNode.style.pointerEvents = "none"; wrapper.append(clonedNode); } - Object.assign(wrapper.style, { + display = wrapper.style.display; + + wrapper.id = "dnd-dragged-node-clone"; + + dragImage = wrapper; + + Object.assign(dragImage.style, { display: "flex", flexDirection: "column", - left: "-9999px", position: "absolute", + overflow: "hidden", + margin: 0, + padding: 0, pointerEvents: "none", zIndex: 9999, }); - - wrapper.id = "dnd-dragged-node-clone"; - - dragImage = wrapper; } } @@ -2835,6 +2835,15 @@ export function parentEventData( }; } +/** + * Add class to the node. + * + * @param els - The nodes. + * @param className - The class name. + * @param omitAppendPrivateClass - Whether to omit append private class. + * + * @returns void + */ export function addNodeClass( els: Array, className: string | undefined, @@ -2968,6 +2977,17 @@ export function removeClass( } } +/** + * Check if the element is scrollable on the x axis. + * + * @param el - The element. + * @param e - The event. + * @param style - The style. + * @param rect - The rect. + * @param state - The state. + * + * @returns void + */ function isScrollX( el: HTMLElement, e: PointerEvent, @@ -3011,6 +3031,16 @@ function isScrollX( }; } +/** + * Check if the element is scrollable on the y axis. + * + * @param el - The element. + * @param e - The event. + * @param style - The style. + * @param rect - The rect. + * + * @returns void + */ function isScrollY( el: HTMLElement, e: PointerEvent, @@ -3049,6 +3079,16 @@ function isScrollY( }; } +/** + * Scroll the element on the x axis. + * + * @param el - The element. + * @param e - The event. + * @param state - The state. + * @param right - Whether to scroll right. + * + * @returns void + */ function scrollX( el: HTMLElement, e: PointerEvent, @@ -3070,6 +3110,16 @@ function scrollX( state.animationFrameIdX = requestAnimationFrame(scroll.bind(null, el)); } +/** + * Scroll the element on the y axis. + * + * @param el - The element. + * @param e - The event. + * @param state - The state. + * @param up - Whether to scroll up. + * + * @returns void + */ function scrollY( el: Element, e: PointerEvent, diff --git a/tests/pages/multi-drag/index.vue b/tests/pages/multi-drag/index.vue index 3b97f116..c291ee4d 100644 --- a/tests/pages/multi-drag/index.vue +++ b/tests/pages/multi-drag/index.vue @@ -48,21 +48,6 @@ const [parent, values] = useDragAndDrop(["Apple", "Banana", "Orange"], { margin: 5px 0; list-style-type: none; } - -.item.hover { - position: relative; -} - -.item.hover::before { - content: ""; - position: absolute; - bottom: -5px; - left: 0; - width: 100%; - height: 2px; - background-color: green; -} - .list { list-style-type: none; padding: 0; @@ -80,7 +65,6 @@ const [parent, values] = useDragAndDrop(["Apple", "Banana", "Orange"], { text-align: center; background-color: #f9f9f9; box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1); - transition: transform 0.2s; width: 400px; height: 50px; }