@proyecto-viviana/solidaria 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunk/DragManager.js.map +1 -1
- package/dist/_chunk/DragManager.jsx.map +1 -1
- package/dist/_chunk/actiongroup.js.map +1 -1
- package/dist/_chunk/actiongroup.jsx.map +1 -1
- package/dist/_chunk/datepicker.js +544 -544
- package/dist/_chunk/datepicker.js.map +1 -1
- package/dist/_chunk/datepicker.jsx +544 -544
- package/dist/_chunk/datepicker.jsx.map +1 -1
- package/dist/_chunk/dnd.js.map +1 -1
- package/dist/_chunk/dnd.jsx.map +1 -1
- package/dist/_chunk/select.js +6 -2
- package/dist/_chunk/select.js.map +1 -1
- package/dist/_chunk/select.jsx +6 -2
- package/dist/_chunk/select.jsx.map +1 -1
- package/dist/_chunk/spinbutton.js +34 -34
- package/dist/_chunk/spinbutton.js.map +1 -1
- package/dist/_chunk/spinbutton.jsx +34 -34
- package/dist/_chunk/spinbutton.jsx.map +1 -1
- package/dist/_chunk/table.js.map +1 -1
- package/dist/_chunk/table.jsx.map +1 -1
- package/dist/_chunk/tree.js.map +1 -1
- package/dist/_chunk/tree.jsx.map +1 -1
- package/dist/actiongroup/createActionGroup.d.ts.map +1 -1
- package/dist/datepicker/createDateField.d.ts.map +1 -1
- package/dist/datepicker/createDatePickerGroup.d.ts.map +1 -1
- package/dist/datepicker/createDateSegment.d.ts.map +1 -1
- package/dist/datepicker/createTimeField.d.ts.map +1 -1
- package/dist/datepicker/intl.d.ts.map +1 -1
- package/dist/dnd/DragManager.d.ts.map +1 -1
- package/dist/dnd/createDraggableItem.d.ts.map +1 -1
- package/dist/dnd/createDroppableCollection.d.ts.map +1 -1
- package/dist/select/createSelect.d.ts.map +1 -1
- package/dist/spinbutton/index.d.ts +2 -2
- package/dist/spinbutton/index.d.ts.map +1 -1
- package/dist/table/createTable.d.ts.map +1 -1
- package/dist/table/utils.d.ts.map +1 -1
- package/dist/tree/createTree.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/actiongroup/createActionGroup.ts +1 -4
- package/src/datepicker/createDateField.ts +3 -1
- package/src/datepicker/createDatePickerGroup.ts +8 -4
- package/src/datepicker/createDateSegment.ts +47 -39
- package/src/datepicker/createTimeField.ts +1 -5
- package/src/datepicker/intl.ts +587 -544
- package/src/dnd/DragManager.ts +5 -5
- package/src/dnd/DropTargetKeyboardNavigation.ts +6 -4
- package/src/dnd/createDraggableItem.ts +3 -1
- package/src/dnd/createDroppableCollection.ts +7 -8
- package/src/select/createSelect.ts +19 -16
- package/src/spinbutton/index.ts +2 -10
- package/src/spinbutton/intl.ts +34 -34
- package/src/table/createTable.ts +2 -3
- package/src/table/utils.ts +1 -6
- package/src/tree/createTree.ts +1 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragManager.js","names":[],"sources":["../../src/dnd/utils.ts","../../src/dnd/DragManager.ts"],"sourcesContent":["/**\n * Drag and Drop utilities for solidaria.\n */\n\nimport type {\n DragItem,\n DragType,\n DropItem,\n TextDropItem,\n FileDropItem,\n DirectoryDropItem,\n DropOperation,\n} from \"@proyecto-viviana/solid-stately\";\nimport { DIRECTORY_DRAG_TYPE } from \"@proyecto-viviana/solid-stately\";\nimport { getInteractionModality } from \"../interactions\";\n\n// Native drag types that can be transferred between applications\nexport const NATIVE_DRAG_TYPES: Set<string> = new Set([\"text/plain\", \"text/uri-list\", \"text/html\"]);\n\n// Custom drag type for serializing multiple items\nexport const CUSTOM_DRAG_TYPE = \"application/vnd.solidaria.items+json\";\n\n// Generic type for unknown file types\nexport const GENERIC_TYPE = \"application/octet-stream\";\n\n// Drop operation bit flags\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = (1 << 0) | (1 << 1) | (1 << 2),\n}\n\n// Map from effectAllowed to DROP_OPERATION\nexport const DROP_OPERATION_ALLOWED: Record<string, number> = {\n none: DROP_OPERATION.none,\n copy: DROP_OPERATION.copy,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n link: DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n move: DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all,\n};\n\n// Map from DROP_OPERATION to effectAllowed\nexport const EFFECT_ALLOWED: Record<number, string> = {\n [DROP_OPERATION.none]: \"none\",\n [DROP_OPERATION.move]: \"move\",\n [DROP_OPERATION.copy]: \"copy\",\n [DROP_OPERATION.copy | DROP_OPERATION.move]: \"copyMove\",\n [DROP_OPERATION.link]: \"link\",\n [DROP_OPERATION.link | DROP_OPERATION.move]: \"linkMove\",\n [DROP_OPERATION.copy | DROP_OPERATION.link]: \"copyLink\",\n [DROP_OPERATION.all]: \"all\",\n};\n\n// Map from dropEffect to DropOperation\nexport const DROP_EFFECT_TO_DROP_OPERATION: Record<string, DropOperation> = {\n none: \"cancel\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n// Map from DropOperation to dropEffect\nexport const DROP_OPERATION_TO_DROP_EFFECT: Record<DropOperation, string> = {\n cancel: \"none\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n/**\n * Maps the current interaction modality onto the drag modality used for\n * announcements and descriptions. Mirrors @react-aria/dnd `mapModality`:\n * pointer collapses to virtual, and a virtual modality on a coarse pointer\n * (touch screen reader) becomes touch.\n */\nfunction mapModality(modality: string | null): string {\n if (!modality) {\n modality = \"virtual\";\n }\n\n if (modality === \"pointer\") {\n modality = \"virtual\";\n }\n\n if (\n modality === \"virtual\" &&\n typeof window !== \"undefined\" &&\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(pointer: coarse)\").matches\n ) {\n modality = \"touch\";\n }\n\n return modality;\n}\n\n/**\n * Returns the drag modality ('keyboard' | 'virtual' | 'touch') for the current\n * interaction. Mirrors @react-aria/dnd `getDragModality`.\n */\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\n/**\n * Get the types present in drag items.\n */\nexport function getTypes(items: DragItem[]): Set<string> {\n const types = new Set<string>();\n for (const item of items) {\n for (const type of Object.keys(item)) {\n types.add(type);\n }\n }\n return types;\n}\n\n/**\n * Write drag items to a DataTransfer object.\n */\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n const groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n const customData: object[] = [];\n\n for (const item of items) {\n const types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n const dataByType: Record<string, string> = {};\n for (const type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n const data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (const [type, typeItems] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Join all items of this type with newlines\n const data = typeItems.join(\"\\n\");\n dataTransfer.items.add(data, type);\n } else {\n // Set first item for non-native types\n dataTransfer.items.add(typeItems[0], type);\n }\n }\n\n if (needsCustomData) {\n const data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\n/**\n * Read drop items from a DataTransfer object.\n */\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n const items: DropItem[] = [];\n\n if (!dataTransfer) {\n return items;\n }\n\n // Check for custom drag type first\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n const data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n const parsed = JSON.parse(data);\n for (const item of parsed) {\n items.push({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type]),\n });\n }\n hasCustomType = true;\n } catch {\n // ignore parsing errors\n }\n }\n\n // Fall back to native items\n if (!hasCustomType) {\n const stringItems = new Map<string, string>();\n\n for (const item of dataTransfer.items) {\n if (item.kind === \"string\") {\n const type = item.type || GENERIC_TYPE;\n stringItems.set(type, dataTransfer.getData(item.type));\n } else if (item.kind === \"file\") {\n const file = item.getAsFile();\n if (file) {\n items.push(createFileItem(file));\n }\n }\n }\n\n if (stringItems.size > 0) {\n items.push({\n kind: \"text\",\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type) ?? \"\"),\n });\n }\n }\n\n return items;\n}\n\n/**\n * Create a FileDropItem from a File object.\n */\nfunction createFileItem(file: File): FileDropItem {\n return {\n kind: \"file\",\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => file.text(),\n getFile: () => Promise.resolve(file),\n };\n}\n\n/**\n * DragTypes implementation for checking drag types.\n */\nexport class DragTypesImpl {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n let hasFiles = false;\n\n for (const item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === \"file\") {\n hasFiles = true;\n }\n if (item.type) {\n this.types.add(item.type);\n } else {\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // Safari doesn't expose file types until drop\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes(\"Files\");\n }\n\n has(type: DragType | DragType[]): boolean {\n if (Array.isArray(type)) {\n return type.some((t) => this.has(t));\n }\n\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE)) ||\n type === \"*/*\"\n ) {\n return true;\n }\n\n if (typeof type === \"string\") {\n // Wildcard MIME match, e.g. \"image/*\" accepts \"image/png\".\n if (type.endsWith(\"/*\")) {\n for (const key of this.types) {\n if (key.startsWith(type.slice(0, -2))) {\n return true;\n }\n }\n return false;\n }\n return this.types.has(type);\n }\n\n return false;\n }\n}\n\n/**\n * Check if a drop item is a text item.\n */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === \"text\";\n}\n\n/**\n * Check if a drop item is a file item.\n */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === \"file\";\n}\n\n/**\n * Check if a drop item is a directory item.\n */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === \"directory\";\n}\n\n// Global state for tracking drag operations\nlet globalDropEffect: string | undefined;\nlet globalAllowedDropOperations: number = DROP_OPERATION.none;\n\nexport function setGlobalDropEffect(effect: string | undefined): void {\n globalDropEffect = effect;\n}\n\nexport function getGlobalDropEffect(): string | undefined {\n return globalDropEffect;\n}\n\nexport function setGlobalAllowedDropOperations(ops: number): void {\n globalAllowedDropOperations = ops;\n}\n\nexport function getGlobalAllowedDropOperations(): number {\n return globalAllowedDropOperations;\n}\n","/**\n * Global keyboard/virtual drag session manager.\n *\n * Faithful port of @react-aria/dnd `DragManager` (react-aria 3.50). A single\n * module-level singleton owns the active drag session: it registers drop targets\n * and drop items across every collection on the page, drives Tab/Shift+Tab\n * cycling between them, Enter-to-drop / Escape-to-cancel, and the aria-live\n * announcements — providing the accessible keyboard alternative to native\n * pointer drag and drop.\n *\n * The only framework-specific adaptation from upstream is the reactive\n * subscription: React's `useDragSession` (useState + a subscription Set) becomes\n * a module-level Solid signal exposed through `createDragSession()`. Element refs\n * (upstream `RefObject.current`) become Solid element accessors (`() => el`).\n */\n\nimport { createSignal, type Accessor } from \"solid-js\";\n\nimport { announce } from \"../live-announcer/announce\";\nimport { ariaHideOutside } from \"../overlays/ariaHideOutside\";\nimport type {\n DragEndEvent,\n DragItem,\n DropActivateEvent,\n DropEnterEvent,\n DropEvent,\n DropExitEvent,\n DropItem,\n DropOperation,\n DropTarget as DroppableCollectionTarget,\n} from \"@proyecto-viviana/solid-stately\";\nimport { getActiveElement, getEventTarget, nodeContains } from \"../utils/dom\";\nimport { getDragModality, getTypes } from \"./utils\";\nimport { isVirtualClick, isVirtualPointerEvent } from \"../utils/events\";\nimport type { LocalizedStringFormatter } from \"@internationalized/string\";\n\n/** A Solid element accessor, replacing upstream's `RefObject<T>.current`. */\ntype ElementAccessor = () => HTMLElement | null;\n\nlet dropTargets = new Map<Element, DropTarget>();\nlet dropItems = new Map<Element, DroppableItem>();\nlet dragSession: DragSession | null = null;\n\n// Reactive mirror of `dragSession` for `createDragSession()`. Solid's signal is\n// the notification mechanism, replacing upstream's `subscriptions` Set.\nconst [trackedDragSession, setTrackedDragSession] = createSignal<DragSession | null>(null);\n\ninterface DropTarget {\n element: HTMLElement;\n preventFocusOnDrop?: boolean;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n onDropEnter?: (e: DropEnterEvent, dragTarget: DragTarget) => void;\n onDropExit?: (e: DropExitEvent) => void;\n onDropTargetEnter?: (target: DroppableCollectionTarget | null) => void;\n onDropActivate?: (e: DropActivateEvent, target: DroppableCollectionTarget | null) => void;\n onDrop?: (e: DropEvent, target: DroppableCollectionTarget | null) => void;\n onKeyDown?: (e: KeyboardEvent, dragTarget: DragTarget) => void;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropTarget(target: DropTarget): () => void {\n dropTargets.set(target.element, target);\n dragSession?.updateValidDropTargets();\n return (): void => {\n dropTargets.delete(target.element);\n dragSession?.updateValidDropTargets();\n };\n}\n\ninterface DroppableItem {\n element: HTMLElement;\n target: DroppableCollectionTarget;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropItem(item: DroppableItem): () => void {\n dropItems.set(item.element, item);\n return (): void => {\n dropItems.delete(item.element);\n };\n}\n\ninterface DragTarget {\n element: HTMLElement;\n items: DragItem[];\n allowedDropOperations: DropOperation[];\n onDragEnd?: (e: DragEndEvent) => void;\n}\n\nexport function beginDragging(target: DragTarget, stringFormatter: LocalizedStringFormatter): void {\n if (dragSession) {\n throw new Error(\"Cannot begin dragging while already dragging\");\n }\n\n dragSession = new DragSession(target, stringFormatter);\n setTrackedDragSession(dragSession);\n requestAnimationFrame(() => {\n if (dragSession) {\n dragSession.setup();\n if (getDragModality() === \"keyboard\") {\n dragSession.next();\n }\n }\n });\n}\n\n/** Reactive accessor for the active drag session, or null. */\nexport function createDragSession(): Accessor<DragSession | null> {\n return trackedDragSession;\n}\n\n/** @private */\nexport function isVirtualDragging(): boolean {\n return !!dragSession;\n}\n\nfunction endDragging() {\n dragSession = null;\n setTrackedDragSession(null);\n}\n\nexport function isValidDropTarget(element: Element): boolean {\n for (let target of dropTargets.keys()) {\n if (nodeContains(target, element)) {\n return true;\n }\n }\n\n return false;\n}\n\nconst CANCELED_EVENTS = [\n \"pointerdown\",\n \"pointermove\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointerover\",\n \"pointerout\",\n \"pointerup\",\n \"mousedown\",\n \"mousemove\",\n \"mouseenter\",\n \"mouseleave\",\n \"mouseover\",\n \"mouseout\",\n \"mouseup\",\n \"touchstart\",\n \"touchmove\",\n \"touchend\",\n \"focusin\",\n \"focusout\",\n];\n\nconst CLICK_EVENTS = [\"pointerup\", \"mouseup\", \"touchend\"];\n\nconst MESSAGES = {\n keyboard: \"dragStartedKeyboard\",\n touch: \"dragStartedTouch\",\n virtual: \"dragStartedVirtual\",\n};\n\nclass DragSession {\n dragTarget: DragTarget;\n validDropTargets: DropTarget[] = [];\n currentDropTarget: DropTarget | null = null;\n currentDropItem: DroppableItem | null = null;\n dropOperation: DropOperation | null = null;\n private mutationObserver: MutationObserver | null = null;\n private restoreAriaHidden: (() => void) | null = null;\n private stringFormatter: LocalizedStringFormatter;\n private isVirtualClick: boolean = false;\n private initialFocused: boolean;\n\n constructor(target: DragTarget, stringFormatter: LocalizedStringFormatter) {\n this.dragTarget = target;\n this.stringFormatter = stringFormatter;\n\n this.onKeyDown = this.onKeyDown.bind(this);\n this.onKeyUp = this.onKeyUp.bind(this);\n this.onFocus = this.onFocus.bind(this);\n this.onBlur = this.onBlur.bind(this);\n this.onClick = this.onClick.bind(this);\n this.onPointerDown = this.onPointerDown.bind(this);\n this.cancelEvent = this.cancelEvent.bind(this);\n this.initialFocused = false;\n }\n\n setup(): void {\n document.addEventListener(\"keydown\", this.onKeyDown, true);\n document.addEventListener(\"keyup\", this.onKeyUp, true);\n window.addEventListener(\"focus\", this.onFocus, true);\n window.addEventListener(\"blur\", this.onBlur, true);\n document.addEventListener(\"click\", this.onClick, true);\n document.addEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.addEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver = new MutationObserver(() => this.updateValidDropTargets());\n this.updateValidDropTargets();\n\n announce(this.stringFormatter.format(MESSAGES[getDragModality() as keyof typeof MESSAGES]));\n }\n\n teardown(): void {\n document.removeEventListener(\"keydown\", this.onKeyDown, true);\n document.removeEventListener(\"keyup\", this.onKeyUp, true);\n window.removeEventListener(\"focus\", this.onFocus, true);\n window.removeEventListener(\"blur\", this.onBlur, true);\n document.removeEventListener(\"click\", this.onClick, true);\n document.removeEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.removeEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver?.disconnect();\n this.restoreAriaHidden?.();\n }\n\n onKeyDown(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Escape\") {\n this.cancel();\n return;\n }\n\n if (e.key === \"Tab\" && !(e.metaKey || e.altKey || e.ctrlKey)) {\n if (e.shiftKey) {\n this.previous();\n } else {\n this.next();\n }\n }\n\n if (typeof this.currentDropTarget?.onKeyDown === \"function\") {\n this.currentDropTarget.onKeyDown(e, this.dragTarget);\n }\n }\n\n onKeyUp(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Enter\") {\n if (\n e.altKey ||\n nodeContains(this.getCurrentActivateButton(), getEventTarget<Node>(e))\n ) {\n this.activate(this.currentDropTarget, this.currentDropItem);\n } else {\n this.drop();\n }\n }\n }\n\n getCurrentActivateButton(): HTMLElement | null {\n return (\n this.currentDropItem?.activateButtonRef?.() ??\n this.currentDropTarget?.activateButtonRef?.() ??\n null\n );\n }\n\n onFocus(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n let eventTarget = getEventTarget<HTMLElement>(e);\n if (eventTarget === activateButton) {\n // TODO: canceling this breaks the focus ring. Revisit when we support tabbing.\n this.cancelEvent(e);\n return;\n }\n\n // Prevent focus events, except to the original drag target.\n if (eventTarget !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.\n if (!(eventTarget instanceof HTMLElement) || eventTarget === this.dragTarget.element) {\n return;\n }\n\n let dropTarget =\n this.validDropTargets.find((target) => target.element === eventTarget) ||\n this.validDropTargets.find((target) => nodeContains(target.element, eventTarget));\n\n if (!dropTarget) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n return;\n }\n\n let item = dropItems.get(eventTarget);\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n }\n }\n\n onBlur(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n // Guard activateButton non-null so this doesn't trip on the case where\n // there's no activate button and the focused element loses focus to nothing\n // (browsers and jsdom 26+ both set relatedTarget to null in that case).\n if (activateButton && e.relatedTarget === activateButton) {\n this.cancelEvent(e);\n return;\n }\n\n if (getEventTarget(e) !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // If nothing is gaining focus, or e.relatedTarget is the window/document (JSDOM),\n // restore focus back to the current drop target if any, or the original drag target.\n if (!e.relatedTarget || !(e.relatedTarget instanceof HTMLElement)) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n }\n }\n\n onClick(e: MouseEvent): void {\n this.cancelEvent(e);\n if (isVirtualClick(e) || this.isVirtualClick) {\n let dropElements = dropItems.values();\n let eventTarget = getEventTarget<HTMLElement>(e);\n let item = [...dropElements].find(\n (item) =>\n item.element === eventTarget ||\n nodeContains(item.activateButtonRef?.() ?? null, eventTarget),\n );\n let dropTarget = this.validDropTargets.find((target) =>\n nodeContains(target.element, eventTarget),\n );\n let activateButton = item?.activateButtonRef?.() ?? dropTarget?.activateButtonRef?.() ?? null;\n if (nodeContains(activateButton, eventTarget) && dropTarget) {\n this.activate(dropTarget, item);\n return;\n }\n\n if (getEventTarget(e) === this.dragTarget.element) {\n this.cancel();\n return;\n }\n\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n this.drop(item);\n }\n }\n }\n\n onPointerDown(e: PointerEvent): void {\n // Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires\n // so we can properly perform cancel and drop operations.\n this.cancelEvent(e);\n this.isVirtualClick = isVirtualPointerEvent(e);\n }\n\n cancelEvent(e: Event): void {\n // Allow focusin and focusout on the drag target so focus ring works properly.\n let eventTarget = getEventTarget(e);\n if (\n (e.type === \"focusin\" || e.type === \"focusout\") &&\n (eventTarget === this.dragTarget?.element || eventTarget === this.getCurrentActivateButton())\n ) {\n return;\n }\n\n // Allow default for events that might cancel a click event\n if (!CLICK_EVENTS.includes(e.type)) {\n e.preventDefault();\n }\n\n e.stopPropagation();\n e.stopImmediatePropagation();\n }\n\n updateValidDropTargets(): void {\n if (!this.mutationObserver) {\n return;\n }\n\n this.mutationObserver.disconnect();\n if (this.restoreAriaHidden) {\n this.restoreAriaHidden();\n }\n\n this.validDropTargets = findValidDropTargets(this.dragTarget);\n\n // Shuffle drop target order based on starting drag target.\n if (this.validDropTargets.length > 0) {\n let nearestIndex = this.findNearestDropTarget();\n this.validDropTargets = [\n ...this.validDropTargets.slice(nearestIndex),\n ...this.validDropTargets.slice(0, nearestIndex),\n ];\n }\n\n if (this.currentDropTarget && !this.validDropTargets.includes(this.currentDropTarget)) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n\n // Find valid drop items within collections\n let types = getTypes(this.dragTarget.items);\n let validDropItems = [...dropItems.values()].filter((item) => {\n if (typeof item.getDropOperation === \"function\") {\n return item.getDropOperation(types, this.dragTarget.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n\n // Filter out drop targets that contain valid items. We don't want to stop hiding elements\n // other than the drop items that exist inside the collection.\n let visibleDropTargets = this.validDropTargets.filter(\n (target) => !validDropItems.some((item) => nodeContains(target.element, item.element)),\n );\n\n this.restoreAriaHidden = ariaHideOutside(\n [\n this.dragTarget.element,\n ...validDropItems.flatMap((item) => {\n let button = item.activateButtonRef?.();\n return button ? [item.element, button] : [item.element];\n }),\n ...visibleDropTargets.flatMap((target) => {\n let button = target.activateButtonRef?.();\n return button ? [target.element, button] : [target.element];\n }),\n ],\n { shouldUseInert: true },\n );\n\n this.mutationObserver.observe(document.body, {\n subtree: true,\n attributes: true,\n attributeFilter: [\"aria-hidden\", \"inert\"],\n });\n }\n\n next(): void {\n // TODO: Allow tabbing to the activate button. Revisit once we fix the focus ring.\n // For now, the activate button is reachable by screen readers and ArrowLeft/ArrowRight\n // is usable specifically by Tree. Will need tabbing for other components.\n\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n // If we've reached the end of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === this.validDropTargets.length - 1) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index + 1]);\n }\n }\n\n previous(): void {\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n // If we've reached the start of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === 0) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index - 1]);\n }\n }\n\n findNearestDropTarget(): number {\n let dragTargetRect = this.dragTarget.element.getBoundingClientRect();\n\n let minDistance = Infinity;\n let nearest = -1;\n for (let i = 0; i < this.validDropTargets.length; i++) {\n let dropTarget = this.validDropTargets[i];\n let rect = dropTarget.element.getBoundingClientRect();\n let dx = rect.left - dragTargetRect.left;\n let dy = rect.top - dragTargetRect.top;\n let dist = dx * dx + dy * dy;\n if (dist < minDistance) {\n minDistance = dist;\n nearest = i;\n }\n }\n\n return nearest;\n }\n\n setCurrentDropTarget(dropTarget: DropTarget | null, item?: DroppableItem): void {\n if (dropTarget !== this.currentDropTarget) {\n if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === \"function\") {\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDropExit({\n type: \"dropexit\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n });\n }\n\n this.currentDropTarget = dropTarget;\n\n if (dropTarget) {\n if (typeof dropTarget.onDropEnter === \"function\") {\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropEnter(\n {\n type: \"dropenter\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n this.dragTarget,\n );\n }\n\n if (!item) {\n dropTarget?.element.focus();\n }\n }\n }\n\n if (item != null && item !== this.currentDropItem) {\n if (this.currentDropTarget && typeof this.currentDropTarget.onDropTargetEnter === \"function\") {\n this.currentDropTarget.onDropTargetEnter(item.target);\n }\n item.element.focus();\n this.currentDropItem = item;\n\n // Announce first drop target after drag start announcement finishes.\n // Otherwise, it will never get announced because drag start announcement is assertive.\n if (!this.initialFocused) {\n let label = item?.element.getAttribute(\"aria-label\");\n if (label) {\n announce(label, \"polite\");\n }\n this.initialFocused = true;\n }\n }\n }\n\n end(): void {\n this.teardown();\n endDragging();\n\n if (typeof this.dragTarget.onDragEnd === \"function\") {\n let target =\n this.currentDropTarget && this.dropOperation !== \"cancel\"\n ? this.currentDropTarget\n : this.dragTarget;\n let rect = target.element.getBoundingClientRect();\n this.dragTarget.onDragEnd({\n type: \"dragend\",\n x: rect.x + rect.width / 2,\n y: rect.y + rect.height / 2,\n dropOperation: this.dropOperation || \"cancel\",\n });\n }\n\n if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) {\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n // This corrects state such as whether focus ring should appear.\n // useDroppableCollection handles this itself, so this is only for standalone drop zones.\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n }\n\n this.setCurrentDropTarget(null);\n }\n\n cancel(): void {\n this.setCurrentDropTarget(null);\n this.end();\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.dragTarget.element.focus();\n }\n\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n\n announce(this.stringFormatter.format(\"dropCanceled\"));\n }\n\n drop(item?: DroppableItem): void {\n if (!this.currentDropTarget) {\n this.cancel();\n return;\n }\n\n if (typeof item?.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations);\n } else if (typeof this.currentDropTarget.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = this.currentDropTarget.getDropOperation(\n types,\n this.dragTarget.allowedDropOperations,\n );\n } else {\n // TODO: show menu ??\n this.dropOperation = this.dragTarget.allowedDropOperations[0];\n }\n\n if (typeof this.currentDropTarget.onDrop === \"function\") {\n let items: DropItem[] = this.dragTarget.items.map((item) => ({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type: string) => Promise.resolve(item[type]),\n }));\n\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDrop(\n {\n type: \"drop\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n items,\n dropOperation: this.dropOperation,\n },\n item?.target ?? null,\n );\n }\n\n this.end();\n announce(this.stringFormatter.format(\"dropComplete\"));\n }\n\n activate(dropTarget: DropTarget | null, dropItem: DroppableItem | null | undefined): void {\n if (dropTarget && typeof dropTarget.onDropActivate === \"function\") {\n let target = dropItem?.target ?? null;\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropActivate(\n {\n type: \"dropactivate\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n target,\n );\n }\n }\n}\n\nfunction findValidDropTargets(options: DragTarget): DropTarget[] {\n let types = getTypes(options.items);\n return [...dropTargets.values()].filter((target) => {\n if (target.element.closest('[aria-hidden=\"true\"], [inert]')) {\n return false;\n }\n\n if (typeof target.getDropOperation === \"function\") {\n return target.getDropOperation(types, options.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n}\n\nexport type { DragTarget, DropTarget, DroppableItem, DragSession };\n"],"mappings":";;;;;;;;AAiBA,MAAa,oBAAiC,IAAI,IAAI;CAAC;CAAc;CAAiB;AAAW,CAAC;AAGlG,MAAa,mBAAmB;AAGhC,MAAa,eAAe;AAG5B,IAAY,iBAAL,yBAAA,gBAAA;CACL,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,YAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CAC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CAC/D,IAAI,QAAQ,SAAS,QAAQ,KAAK;CAClC,OAAO,CAAC,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,QAAQ,WAAW;EAClD,IAAI,OAAO,QAAQ,QAAQ,iCAA+B,GACxD,OAAO;EAGT,IAAI,OAAO,OAAO,qBAAqB,YACrC,OAAO,OAAO,iBAAiB,OAAO,QAAQ,qBAAqB,MAAM;EAG3E,OAAO;CACT,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"DragManager.js","names":[],"sources":["../../src/dnd/utils.ts","../../src/dnd/DragManager.ts"],"sourcesContent":["/**\n * Drag and Drop utilities for solidaria.\n */\n\nimport type {\n DragItem,\n DragType,\n DropItem,\n TextDropItem,\n FileDropItem,\n DirectoryDropItem,\n DropOperation,\n} from \"@proyecto-viviana/solid-stately\";\nimport { DIRECTORY_DRAG_TYPE } from \"@proyecto-viviana/solid-stately\";\nimport { getInteractionModality } from \"../interactions\";\n\n// Native drag types that can be transferred between applications\nexport const NATIVE_DRAG_TYPES: Set<string> = new Set([\"text/plain\", \"text/uri-list\", \"text/html\"]);\n\n// Custom drag type for serializing multiple items\nexport const CUSTOM_DRAG_TYPE = \"application/vnd.solidaria.items+json\";\n\n// Generic type for unknown file types\nexport const GENERIC_TYPE = \"application/octet-stream\";\n\n// Drop operation bit flags\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = (1 << 0) | (1 << 1) | (1 << 2),\n}\n\n// Map from effectAllowed to DROP_OPERATION\nexport const DROP_OPERATION_ALLOWED: Record<string, number> = {\n none: DROP_OPERATION.none,\n copy: DROP_OPERATION.copy,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n link: DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n move: DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all,\n};\n\n// Map from DROP_OPERATION to effectAllowed\nexport const EFFECT_ALLOWED: Record<number, string> = {\n [DROP_OPERATION.none]: \"none\",\n [DROP_OPERATION.move]: \"move\",\n [DROP_OPERATION.copy]: \"copy\",\n [DROP_OPERATION.copy | DROP_OPERATION.move]: \"copyMove\",\n [DROP_OPERATION.link]: \"link\",\n [DROP_OPERATION.link | DROP_OPERATION.move]: \"linkMove\",\n [DROP_OPERATION.copy | DROP_OPERATION.link]: \"copyLink\",\n [DROP_OPERATION.all]: \"all\",\n};\n\n// Map from dropEffect to DropOperation\nexport const DROP_EFFECT_TO_DROP_OPERATION: Record<string, DropOperation> = {\n none: \"cancel\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n// Map from DropOperation to dropEffect\nexport const DROP_OPERATION_TO_DROP_EFFECT: Record<DropOperation, string> = {\n cancel: \"none\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n/**\n * Maps the current interaction modality onto the drag modality used for\n * announcements and descriptions. Mirrors @react-aria/dnd `mapModality`:\n * pointer collapses to virtual, and a virtual modality on a coarse pointer\n * (touch screen reader) becomes touch.\n */\nfunction mapModality(modality: string | null): string {\n if (!modality) {\n modality = \"virtual\";\n }\n\n if (modality === \"pointer\") {\n modality = \"virtual\";\n }\n\n if (\n modality === \"virtual\" &&\n typeof window !== \"undefined\" &&\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(pointer: coarse)\").matches\n ) {\n modality = \"touch\";\n }\n\n return modality;\n}\n\n/**\n * Returns the drag modality ('keyboard' | 'virtual' | 'touch') for the current\n * interaction. Mirrors @react-aria/dnd `getDragModality`.\n */\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\n/**\n * Get the types present in drag items.\n */\nexport function getTypes(items: DragItem[]): Set<string> {\n const types = new Set<string>();\n for (const item of items) {\n for (const type of Object.keys(item)) {\n types.add(type);\n }\n }\n return types;\n}\n\n/**\n * Write drag items to a DataTransfer object.\n */\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n const groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n const customData: object[] = [];\n\n for (const item of items) {\n const types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n const dataByType: Record<string, string> = {};\n for (const type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n const data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (const [type, typeItems] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Join all items of this type with newlines\n const data = typeItems.join(\"\\n\");\n dataTransfer.items.add(data, type);\n } else {\n // Set first item for non-native types\n dataTransfer.items.add(typeItems[0], type);\n }\n }\n\n if (needsCustomData) {\n const data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\n/**\n * Read drop items from a DataTransfer object.\n */\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n const items: DropItem[] = [];\n\n if (!dataTransfer) {\n return items;\n }\n\n // Check for custom drag type first\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n const data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n const parsed = JSON.parse(data);\n for (const item of parsed) {\n items.push({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type]),\n });\n }\n hasCustomType = true;\n } catch {\n // ignore parsing errors\n }\n }\n\n // Fall back to native items\n if (!hasCustomType) {\n const stringItems = new Map<string, string>();\n\n for (const item of dataTransfer.items) {\n if (item.kind === \"string\") {\n const type = item.type || GENERIC_TYPE;\n stringItems.set(type, dataTransfer.getData(item.type));\n } else if (item.kind === \"file\") {\n const file = item.getAsFile();\n if (file) {\n items.push(createFileItem(file));\n }\n }\n }\n\n if (stringItems.size > 0) {\n items.push({\n kind: \"text\",\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type) ?? \"\"),\n });\n }\n }\n\n return items;\n}\n\n/**\n * Create a FileDropItem from a File object.\n */\nfunction createFileItem(file: File): FileDropItem {\n return {\n kind: \"file\",\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => file.text(),\n getFile: () => Promise.resolve(file),\n };\n}\n\n/**\n * DragTypes implementation for checking drag types.\n */\nexport class DragTypesImpl {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n let hasFiles = false;\n\n for (const item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === \"file\") {\n hasFiles = true;\n }\n if (item.type) {\n this.types.add(item.type);\n } else {\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // Safari doesn't expose file types until drop\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes(\"Files\");\n }\n\n has(type: DragType | DragType[]): boolean {\n if (Array.isArray(type)) {\n return type.some((t) => this.has(t));\n }\n\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE)) ||\n type === \"*/*\"\n ) {\n return true;\n }\n\n if (typeof type === \"string\") {\n // Wildcard MIME match, e.g. \"image/*\" accepts \"image/png\".\n if (type.endsWith(\"/*\")) {\n for (const key of this.types) {\n if (key.startsWith(type.slice(0, -2))) {\n return true;\n }\n }\n return false;\n }\n return this.types.has(type);\n }\n\n return false;\n }\n}\n\n/**\n * Check if a drop item is a text item.\n */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === \"text\";\n}\n\n/**\n * Check if a drop item is a file item.\n */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === \"file\";\n}\n\n/**\n * Check if a drop item is a directory item.\n */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === \"directory\";\n}\n\n// Global state for tracking drag operations\nlet globalDropEffect: string | undefined;\nlet globalAllowedDropOperations: number = DROP_OPERATION.none;\n\nexport function setGlobalDropEffect(effect: string | undefined): void {\n globalDropEffect = effect;\n}\n\nexport function getGlobalDropEffect(): string | undefined {\n return globalDropEffect;\n}\n\nexport function setGlobalAllowedDropOperations(ops: number): void {\n globalAllowedDropOperations = ops;\n}\n\nexport function getGlobalAllowedDropOperations(): number {\n return globalAllowedDropOperations;\n}\n","/**\n * Global keyboard/virtual drag session manager.\n *\n * Faithful port of @react-aria/dnd `DragManager` (react-aria 3.50). A single\n * module-level singleton owns the active drag session: it registers drop targets\n * and drop items across every collection on the page, drives Tab/Shift+Tab\n * cycling between them, Enter-to-drop / Escape-to-cancel, and the aria-live\n * announcements — providing the accessible keyboard alternative to native\n * pointer drag and drop.\n *\n * The only framework-specific adaptation from upstream is the reactive\n * subscription: React's `useDragSession` (useState + a subscription Set) becomes\n * a module-level Solid signal exposed through `createDragSession()`. Element refs\n * (upstream `RefObject.current`) become Solid element accessors (`() => el`).\n */\n\nimport { createSignal, type Accessor } from \"solid-js\";\n\nimport { announce } from \"../live-announcer/announce\";\nimport { ariaHideOutside } from \"../overlays/ariaHideOutside\";\nimport type {\n DragEndEvent,\n DragItem,\n DropActivateEvent,\n DropEnterEvent,\n DropEvent,\n DropExitEvent,\n DropItem,\n DropOperation,\n DropTarget as DroppableCollectionTarget,\n} from \"@proyecto-viviana/solid-stately\";\nimport { getActiveElement, getEventTarget, nodeContains } from \"../utils/dom\";\nimport { getDragModality, getTypes } from \"./utils\";\nimport { isVirtualClick, isVirtualPointerEvent } from \"../utils/events\";\nimport type { LocalizedStringFormatter } from \"@internationalized/string\";\n\n/** A Solid element accessor, replacing upstream's `RefObject<T>.current`. */\ntype ElementAccessor = () => HTMLElement | null;\n\nlet dropTargets = new Map<Element, DropTarget>();\nlet dropItems = new Map<Element, DroppableItem>();\nlet dragSession: DragSession | null = null;\n\n// Reactive mirror of `dragSession` for `createDragSession()`. Solid's signal is\n// the notification mechanism, replacing upstream's `subscriptions` Set.\nconst [trackedDragSession, setTrackedDragSession] = createSignal<DragSession | null>(null);\n\ninterface DropTarget {\n element: HTMLElement;\n preventFocusOnDrop?: boolean;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n onDropEnter?: (e: DropEnterEvent, dragTarget: DragTarget) => void;\n onDropExit?: (e: DropExitEvent) => void;\n onDropTargetEnter?: (target: DroppableCollectionTarget | null) => void;\n onDropActivate?: (e: DropActivateEvent, target: DroppableCollectionTarget | null) => void;\n onDrop?: (e: DropEvent, target: DroppableCollectionTarget | null) => void;\n onKeyDown?: (e: KeyboardEvent, dragTarget: DragTarget) => void;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropTarget(target: DropTarget): () => void {\n dropTargets.set(target.element, target);\n dragSession?.updateValidDropTargets();\n return (): void => {\n dropTargets.delete(target.element);\n dragSession?.updateValidDropTargets();\n };\n}\n\ninterface DroppableItem {\n element: HTMLElement;\n target: DroppableCollectionTarget;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropItem(item: DroppableItem): () => void {\n dropItems.set(item.element, item);\n return (): void => {\n dropItems.delete(item.element);\n };\n}\n\ninterface DragTarget {\n element: HTMLElement;\n items: DragItem[];\n allowedDropOperations: DropOperation[];\n onDragEnd?: (e: DragEndEvent) => void;\n}\n\nexport function beginDragging(target: DragTarget, stringFormatter: LocalizedStringFormatter): void {\n if (dragSession) {\n throw new Error(\"Cannot begin dragging while already dragging\");\n }\n\n dragSession = new DragSession(target, stringFormatter);\n setTrackedDragSession(dragSession);\n requestAnimationFrame(() => {\n if (dragSession) {\n dragSession.setup();\n if (getDragModality() === \"keyboard\") {\n dragSession.next();\n }\n }\n });\n}\n\n/** Reactive accessor for the active drag session, or null. */\nexport function createDragSession(): Accessor<DragSession | null> {\n return trackedDragSession;\n}\n\n/** @private */\nexport function isVirtualDragging(): boolean {\n return !!dragSession;\n}\n\nfunction endDragging() {\n dragSession = null;\n setTrackedDragSession(null);\n}\n\nexport function isValidDropTarget(element: Element): boolean {\n for (let target of dropTargets.keys()) {\n if (nodeContains(target, element)) {\n return true;\n }\n }\n\n return false;\n}\n\nconst CANCELED_EVENTS = [\n \"pointerdown\",\n \"pointermove\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointerover\",\n \"pointerout\",\n \"pointerup\",\n \"mousedown\",\n \"mousemove\",\n \"mouseenter\",\n \"mouseleave\",\n \"mouseover\",\n \"mouseout\",\n \"mouseup\",\n \"touchstart\",\n \"touchmove\",\n \"touchend\",\n \"focusin\",\n \"focusout\",\n];\n\nconst CLICK_EVENTS = [\"pointerup\", \"mouseup\", \"touchend\"];\n\nconst MESSAGES = {\n keyboard: \"dragStartedKeyboard\",\n touch: \"dragStartedTouch\",\n virtual: \"dragStartedVirtual\",\n};\n\nclass DragSession {\n dragTarget: DragTarget;\n validDropTargets: DropTarget[] = [];\n currentDropTarget: DropTarget | null = null;\n currentDropItem: DroppableItem | null = null;\n dropOperation: DropOperation | null = null;\n private mutationObserver: MutationObserver | null = null;\n private restoreAriaHidden: (() => void) | null = null;\n private stringFormatter: LocalizedStringFormatter;\n private isVirtualClick: boolean = false;\n private initialFocused: boolean;\n\n constructor(target: DragTarget, stringFormatter: LocalizedStringFormatter) {\n this.dragTarget = target;\n this.stringFormatter = stringFormatter;\n\n this.onKeyDown = this.onKeyDown.bind(this);\n this.onKeyUp = this.onKeyUp.bind(this);\n this.onFocus = this.onFocus.bind(this);\n this.onBlur = this.onBlur.bind(this);\n this.onClick = this.onClick.bind(this);\n this.onPointerDown = this.onPointerDown.bind(this);\n this.cancelEvent = this.cancelEvent.bind(this);\n this.initialFocused = false;\n }\n\n setup(): void {\n document.addEventListener(\"keydown\", this.onKeyDown, true);\n document.addEventListener(\"keyup\", this.onKeyUp, true);\n window.addEventListener(\"focus\", this.onFocus, true);\n window.addEventListener(\"blur\", this.onBlur, true);\n document.addEventListener(\"click\", this.onClick, true);\n document.addEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.addEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver = new MutationObserver(() => this.updateValidDropTargets());\n this.updateValidDropTargets();\n\n announce(this.stringFormatter.format(MESSAGES[getDragModality() as keyof typeof MESSAGES]));\n }\n\n teardown(): void {\n document.removeEventListener(\"keydown\", this.onKeyDown, true);\n document.removeEventListener(\"keyup\", this.onKeyUp, true);\n window.removeEventListener(\"focus\", this.onFocus, true);\n window.removeEventListener(\"blur\", this.onBlur, true);\n document.removeEventListener(\"click\", this.onClick, true);\n document.removeEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.removeEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver?.disconnect();\n this.restoreAriaHidden?.();\n }\n\n onKeyDown(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Escape\") {\n this.cancel();\n return;\n }\n\n if (e.key === \"Tab\" && !(e.metaKey || e.altKey || e.ctrlKey)) {\n if (e.shiftKey) {\n this.previous();\n } else {\n this.next();\n }\n }\n\n if (typeof this.currentDropTarget?.onKeyDown === \"function\") {\n this.currentDropTarget.onKeyDown(e, this.dragTarget);\n }\n }\n\n onKeyUp(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Enter\") {\n if (e.altKey || nodeContains(this.getCurrentActivateButton(), getEventTarget<Node>(e))) {\n this.activate(this.currentDropTarget, this.currentDropItem);\n } else {\n this.drop();\n }\n }\n }\n\n getCurrentActivateButton(): HTMLElement | null {\n return (\n this.currentDropItem?.activateButtonRef?.() ??\n this.currentDropTarget?.activateButtonRef?.() ??\n null\n );\n }\n\n onFocus(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n let eventTarget = getEventTarget<HTMLElement>(e);\n if (eventTarget === activateButton) {\n // TODO: canceling this breaks the focus ring. Revisit when we support tabbing.\n this.cancelEvent(e);\n return;\n }\n\n // Prevent focus events, except to the original drag target.\n if (eventTarget !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.\n if (!(eventTarget instanceof HTMLElement) || eventTarget === this.dragTarget.element) {\n return;\n }\n\n let dropTarget =\n this.validDropTargets.find((target) => target.element === eventTarget) ||\n this.validDropTargets.find((target) => nodeContains(target.element, eventTarget));\n\n if (!dropTarget) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n return;\n }\n\n let item = dropItems.get(eventTarget);\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n }\n }\n\n onBlur(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n // Guard activateButton non-null so this doesn't trip on the case where\n // there's no activate button and the focused element loses focus to nothing\n // (browsers and jsdom 26+ both set relatedTarget to null in that case).\n if (activateButton && e.relatedTarget === activateButton) {\n this.cancelEvent(e);\n return;\n }\n\n if (getEventTarget(e) !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // If nothing is gaining focus, or e.relatedTarget is the window/document (JSDOM),\n // restore focus back to the current drop target if any, or the original drag target.\n if (!e.relatedTarget || !(e.relatedTarget instanceof HTMLElement)) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n }\n }\n\n onClick(e: MouseEvent): void {\n this.cancelEvent(e);\n if (isVirtualClick(e) || this.isVirtualClick) {\n let dropElements = dropItems.values();\n let eventTarget = getEventTarget<HTMLElement>(e);\n let item = [...dropElements].find(\n (item) =>\n item.element === eventTarget ||\n nodeContains(item.activateButtonRef?.() ?? null, eventTarget),\n );\n let dropTarget = this.validDropTargets.find((target) =>\n nodeContains(target.element, eventTarget),\n );\n let activateButton = item?.activateButtonRef?.() ?? dropTarget?.activateButtonRef?.() ?? null;\n if (nodeContains(activateButton, eventTarget) && dropTarget) {\n this.activate(dropTarget, item);\n return;\n }\n\n if (getEventTarget(e) === this.dragTarget.element) {\n this.cancel();\n return;\n }\n\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n this.drop(item);\n }\n }\n }\n\n onPointerDown(e: PointerEvent): void {\n // Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires\n // so we can properly perform cancel and drop operations.\n this.cancelEvent(e);\n this.isVirtualClick = isVirtualPointerEvent(e);\n }\n\n cancelEvent(e: Event): void {\n // Allow focusin and focusout on the drag target so focus ring works properly.\n let eventTarget = getEventTarget(e);\n if (\n (e.type === \"focusin\" || e.type === \"focusout\") &&\n (eventTarget === this.dragTarget?.element || eventTarget === this.getCurrentActivateButton())\n ) {\n return;\n }\n\n // Allow default for events that might cancel a click event\n if (!CLICK_EVENTS.includes(e.type)) {\n e.preventDefault();\n }\n\n e.stopPropagation();\n e.stopImmediatePropagation();\n }\n\n updateValidDropTargets(): void {\n if (!this.mutationObserver) {\n return;\n }\n\n this.mutationObserver.disconnect();\n if (this.restoreAriaHidden) {\n this.restoreAriaHidden();\n }\n\n this.validDropTargets = findValidDropTargets(this.dragTarget);\n\n // Shuffle drop target order based on starting drag target.\n if (this.validDropTargets.length > 0) {\n let nearestIndex = this.findNearestDropTarget();\n this.validDropTargets = [\n ...this.validDropTargets.slice(nearestIndex),\n ...this.validDropTargets.slice(0, nearestIndex),\n ];\n }\n\n if (this.currentDropTarget && !this.validDropTargets.includes(this.currentDropTarget)) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n\n // Find valid drop items within collections\n let types = getTypes(this.dragTarget.items);\n let validDropItems = [...dropItems.values()].filter((item) => {\n if (typeof item.getDropOperation === \"function\") {\n return item.getDropOperation(types, this.dragTarget.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n\n // Filter out drop targets that contain valid items. We don't want to stop hiding elements\n // other than the drop items that exist inside the collection.\n let visibleDropTargets = this.validDropTargets.filter(\n (target) => !validDropItems.some((item) => nodeContains(target.element, item.element)),\n );\n\n this.restoreAriaHidden = ariaHideOutside(\n [\n this.dragTarget.element,\n ...validDropItems.flatMap((item) => {\n let button = item.activateButtonRef?.();\n return button ? [item.element, button] : [item.element];\n }),\n ...visibleDropTargets.flatMap((target) => {\n let button = target.activateButtonRef?.();\n return button ? [target.element, button] : [target.element];\n }),\n ],\n { shouldUseInert: true },\n );\n\n this.mutationObserver.observe(document.body, {\n subtree: true,\n attributes: true,\n attributeFilter: [\"aria-hidden\", \"inert\"],\n });\n }\n\n next(): void {\n // TODO: Allow tabbing to the activate button. Revisit once we fix the focus ring.\n // For now, the activate button is reachable by screen readers and ArrowLeft/ArrowRight\n // is usable specifically by Tree. Will need tabbing for other components.\n\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n // If we've reached the end of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === this.validDropTargets.length - 1) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index + 1]);\n }\n }\n\n previous(): void {\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n // If we've reached the start of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === 0) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index - 1]);\n }\n }\n\n findNearestDropTarget(): number {\n let dragTargetRect = this.dragTarget.element.getBoundingClientRect();\n\n let minDistance = Infinity;\n let nearest = -1;\n for (let i = 0; i < this.validDropTargets.length; i++) {\n let dropTarget = this.validDropTargets[i];\n let rect = dropTarget.element.getBoundingClientRect();\n let dx = rect.left - dragTargetRect.left;\n let dy = rect.top - dragTargetRect.top;\n let dist = dx * dx + dy * dy;\n if (dist < minDistance) {\n minDistance = dist;\n nearest = i;\n }\n }\n\n return nearest;\n }\n\n setCurrentDropTarget(dropTarget: DropTarget | null, item?: DroppableItem): void {\n if (dropTarget !== this.currentDropTarget) {\n if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === \"function\") {\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDropExit({\n type: \"dropexit\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n });\n }\n\n this.currentDropTarget = dropTarget;\n\n if (dropTarget) {\n if (typeof dropTarget.onDropEnter === \"function\") {\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropEnter(\n {\n type: \"dropenter\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n this.dragTarget,\n );\n }\n\n if (!item) {\n dropTarget?.element.focus();\n }\n }\n }\n\n if (item != null && item !== this.currentDropItem) {\n if (\n this.currentDropTarget &&\n typeof this.currentDropTarget.onDropTargetEnter === \"function\"\n ) {\n this.currentDropTarget.onDropTargetEnter(item.target);\n }\n item.element.focus();\n this.currentDropItem = item;\n\n // Announce first drop target after drag start announcement finishes.\n // Otherwise, it will never get announced because drag start announcement is assertive.\n if (!this.initialFocused) {\n let label = item?.element.getAttribute(\"aria-label\");\n if (label) {\n announce(label, \"polite\");\n }\n this.initialFocused = true;\n }\n }\n }\n\n end(): void {\n this.teardown();\n endDragging();\n\n if (typeof this.dragTarget.onDragEnd === \"function\") {\n let target =\n this.currentDropTarget && this.dropOperation !== \"cancel\"\n ? this.currentDropTarget\n : this.dragTarget;\n let rect = target.element.getBoundingClientRect();\n this.dragTarget.onDragEnd({\n type: \"dragend\",\n x: rect.x + rect.width / 2,\n y: rect.y + rect.height / 2,\n dropOperation: this.dropOperation || \"cancel\",\n });\n }\n\n if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) {\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n // This corrects state such as whether focus ring should appear.\n // useDroppableCollection handles this itself, so this is only for standalone drop zones.\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n }\n\n this.setCurrentDropTarget(null);\n }\n\n cancel(): void {\n this.setCurrentDropTarget(null);\n this.end();\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.dragTarget.element.focus();\n }\n\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n\n announce(this.stringFormatter.format(\"dropCanceled\"));\n }\n\n drop(item?: DroppableItem): void {\n if (!this.currentDropTarget) {\n this.cancel();\n return;\n }\n\n if (typeof item?.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations);\n } else if (typeof this.currentDropTarget.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = this.currentDropTarget.getDropOperation(\n types,\n this.dragTarget.allowedDropOperations,\n );\n } else {\n // TODO: show menu ??\n this.dropOperation = this.dragTarget.allowedDropOperations[0];\n }\n\n if (typeof this.currentDropTarget.onDrop === \"function\") {\n let items: DropItem[] = this.dragTarget.items.map((item) => ({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type: string) => Promise.resolve(item[type]),\n }));\n\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDrop(\n {\n type: \"drop\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n items,\n dropOperation: this.dropOperation,\n },\n item?.target ?? null,\n );\n }\n\n this.end();\n announce(this.stringFormatter.format(\"dropComplete\"));\n }\n\n activate(dropTarget: DropTarget | null, dropItem: DroppableItem | null | undefined): void {\n if (dropTarget && typeof dropTarget.onDropActivate === \"function\") {\n let target = dropItem?.target ?? null;\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropActivate(\n {\n type: \"dropactivate\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n target,\n );\n }\n }\n}\n\nfunction findValidDropTargets(options: DragTarget): DropTarget[] {\n let types = getTypes(options.items);\n return [...dropTargets.values()].filter((target) => {\n if (target.element.closest('[aria-hidden=\"true\"], [inert]')) {\n return false;\n }\n\n if (typeof target.getDropOperation === \"function\") {\n return target.getDropOperation(types, options.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n}\n\nexport type { DragTarget, DropTarget, DroppableItem, DragSession };\n"],"mappings":";;;;;;;;AAiBA,MAAa,oBAAiC,IAAI,IAAI;CAAC;CAAc;CAAiB;AAAW,CAAC;AAGlG,MAAa,mBAAmB;AAGhC,MAAa,eAAe;AAG5B,IAAY,iBAAL,yBAAA,gBAAA;CACL,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,YAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,SAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAGA,MAAa,yBAAiD;CAC5D,MAAA;CACA,MAAA;CACA,UAAU;CACV,UAAU;CACV,MAAA;CACA,UAAU;CACV,MAAA;CACA,KAAA;CACA,eAAA;AACF;AA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AqB,MAAM;EAG3E,OAAO;CACT,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragManager.jsx","names":[],"sources":["../../src/dnd/utils.ts","../../src/dnd/DragManager.ts"],"sourcesContent":["/**\n * Drag and Drop utilities for solidaria.\n */\n\nimport type {\n DragItem,\n DragType,\n DropItem,\n TextDropItem,\n FileDropItem,\n DirectoryDropItem,\n DropOperation,\n} from \"@proyecto-viviana/solid-stately\";\nimport { DIRECTORY_DRAG_TYPE } from \"@proyecto-viviana/solid-stately\";\nimport { getInteractionModality } from \"../interactions\";\n\n// Native drag types that can be transferred between applications\nexport const NATIVE_DRAG_TYPES: Set<string> = new Set([\"text/plain\", \"text/uri-list\", \"text/html\"]);\n\n// Custom drag type for serializing multiple items\nexport const CUSTOM_DRAG_TYPE = \"application/vnd.solidaria.items+json\";\n\n// Generic type for unknown file types\nexport const GENERIC_TYPE = \"application/octet-stream\";\n\n// Drop operation bit flags\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = (1 << 0) | (1 << 1) | (1 << 2),\n}\n\n// Map from effectAllowed to DROP_OPERATION\nexport const DROP_OPERATION_ALLOWED: Record<string, number> = {\n none: DROP_OPERATION.none,\n copy: DROP_OPERATION.copy,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n link: DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n move: DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all,\n};\n\n// Map from DROP_OPERATION to effectAllowed\nexport const EFFECT_ALLOWED: Record<number, string> = {\n [DROP_OPERATION.none]: \"none\",\n [DROP_OPERATION.move]: \"move\",\n [DROP_OPERATION.copy]: \"copy\",\n [DROP_OPERATION.copy | DROP_OPERATION.move]: \"copyMove\",\n [DROP_OPERATION.link]: \"link\",\n [DROP_OPERATION.link | DROP_OPERATION.move]: \"linkMove\",\n [DROP_OPERATION.copy | DROP_OPERATION.link]: \"copyLink\",\n [DROP_OPERATION.all]: \"all\",\n};\n\n// Map from dropEffect to DropOperation\nexport const DROP_EFFECT_TO_DROP_OPERATION: Record<string, DropOperation> = {\n none: \"cancel\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n// Map from DropOperation to dropEffect\nexport const DROP_OPERATION_TO_DROP_EFFECT: Record<DropOperation, string> = {\n cancel: \"none\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n/**\n * Maps the current interaction modality onto the drag modality used for\n * announcements and descriptions. Mirrors @react-aria/dnd `mapModality`:\n * pointer collapses to virtual, and a virtual modality on a coarse pointer\n * (touch screen reader) becomes touch.\n */\nfunction mapModality(modality: string | null): string {\n if (!modality) {\n modality = \"virtual\";\n }\n\n if (modality === \"pointer\") {\n modality = \"virtual\";\n }\n\n if (\n modality === \"virtual\" &&\n typeof window !== \"undefined\" &&\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(pointer: coarse)\").matches\n ) {\n modality = \"touch\";\n }\n\n return modality;\n}\n\n/**\n * Returns the drag modality ('keyboard' | 'virtual' | 'touch') for the current\n * interaction. Mirrors @react-aria/dnd `getDragModality`.\n */\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\n/**\n * Get the types present in drag items.\n */\nexport function getTypes(items: DragItem[]): Set<string> {\n const types = new Set<string>();\n for (const item of items) {\n for (const type of Object.keys(item)) {\n types.add(type);\n }\n }\n return types;\n}\n\n/**\n * Write drag items to a DataTransfer object.\n */\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n const groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n const customData: object[] = [];\n\n for (const item of items) {\n const types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n const dataByType: Record<string, string> = {};\n for (const type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n const data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (const [type, typeItems] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Join all items of this type with newlines\n const data = typeItems.join(\"\\n\");\n dataTransfer.items.add(data, type);\n } else {\n // Set first item for non-native types\n dataTransfer.items.add(typeItems[0], type);\n }\n }\n\n if (needsCustomData) {\n const data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\n/**\n * Read drop items from a DataTransfer object.\n */\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n const items: DropItem[] = [];\n\n if (!dataTransfer) {\n return items;\n }\n\n // Check for custom drag type first\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n const data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n const parsed = JSON.parse(data);\n for (const item of parsed) {\n items.push({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type]),\n });\n }\n hasCustomType = true;\n } catch {\n // ignore parsing errors\n }\n }\n\n // Fall back to native items\n if (!hasCustomType) {\n const stringItems = new Map<string, string>();\n\n for (const item of dataTransfer.items) {\n if (item.kind === \"string\") {\n const type = item.type || GENERIC_TYPE;\n stringItems.set(type, dataTransfer.getData(item.type));\n } else if (item.kind === \"file\") {\n const file = item.getAsFile();\n if (file) {\n items.push(createFileItem(file));\n }\n }\n }\n\n if (stringItems.size > 0) {\n items.push({\n kind: \"text\",\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type) ?? \"\"),\n });\n }\n }\n\n return items;\n}\n\n/**\n * Create a FileDropItem from a File object.\n */\nfunction createFileItem(file: File): FileDropItem {\n return {\n kind: \"file\",\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => file.text(),\n getFile: () => Promise.resolve(file),\n };\n}\n\n/**\n * DragTypes implementation for checking drag types.\n */\nexport class DragTypesImpl {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n let hasFiles = false;\n\n for (const item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === \"file\") {\n hasFiles = true;\n }\n if (item.type) {\n this.types.add(item.type);\n } else {\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // Safari doesn't expose file types until drop\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes(\"Files\");\n }\n\n has(type: DragType | DragType[]): boolean {\n if (Array.isArray(type)) {\n return type.some((t) => this.has(t));\n }\n\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE)) ||\n type === \"*/*\"\n ) {\n return true;\n }\n\n if (typeof type === \"string\") {\n // Wildcard MIME match, e.g. \"image/*\" accepts \"image/png\".\n if (type.endsWith(\"/*\")) {\n for (const key of this.types) {\n if (key.startsWith(type.slice(0, -2))) {\n return true;\n }\n }\n return false;\n }\n return this.types.has(type);\n }\n\n return false;\n }\n}\n\n/**\n * Check if a drop item is a text item.\n */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === \"text\";\n}\n\n/**\n * Check if a drop item is a file item.\n */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === \"file\";\n}\n\n/**\n * Check if a drop item is a directory item.\n */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === \"directory\";\n}\n\n// Global state for tracking drag operations\nlet globalDropEffect: string | undefined;\nlet globalAllowedDropOperations: number = DROP_OPERATION.none;\n\nexport function setGlobalDropEffect(effect: string | undefined): void {\n globalDropEffect = effect;\n}\n\nexport function getGlobalDropEffect(): string | undefined {\n return globalDropEffect;\n}\n\nexport function setGlobalAllowedDropOperations(ops: number): void {\n globalAllowedDropOperations = ops;\n}\n\nexport function getGlobalAllowedDropOperations(): number {\n return globalAllowedDropOperations;\n}\n","/**\n * Global keyboard/virtual drag session manager.\n *\n * Faithful port of @react-aria/dnd `DragManager` (react-aria 3.50). A single\n * module-level singleton owns the active drag session: it registers drop targets\n * and drop items across every collection on the page, drives Tab/Shift+Tab\n * cycling between them, Enter-to-drop / Escape-to-cancel, and the aria-live\n * announcements — providing the accessible keyboard alternative to native\n * pointer drag and drop.\n *\n * The only framework-specific adaptation from upstream is the reactive\n * subscription: React's `useDragSession` (useState + a subscription Set) becomes\n * a module-level Solid signal exposed through `createDragSession()`. Element refs\n * (upstream `RefObject.current`) become Solid element accessors (`() => el`).\n */\n\nimport { createSignal, type Accessor } from \"solid-js\";\n\nimport { announce } from \"../live-announcer/announce\";\nimport { ariaHideOutside } from \"../overlays/ariaHideOutside\";\nimport type {\n DragEndEvent,\n DragItem,\n DropActivateEvent,\n DropEnterEvent,\n DropEvent,\n DropExitEvent,\n DropItem,\n DropOperation,\n DropTarget as DroppableCollectionTarget,\n} from \"@proyecto-viviana/solid-stately\";\nimport { getActiveElement, getEventTarget, nodeContains } from \"../utils/dom\";\nimport { getDragModality, getTypes } from \"./utils\";\nimport { isVirtualClick, isVirtualPointerEvent } from \"../utils/events\";\nimport type { LocalizedStringFormatter } from \"@internationalized/string\";\n\n/** A Solid element accessor, replacing upstream's `RefObject<T>.current`. */\ntype ElementAccessor = () => HTMLElement | null;\n\nlet dropTargets = new Map<Element, DropTarget>();\nlet dropItems = new Map<Element, DroppableItem>();\nlet dragSession: DragSession | null = null;\n\n// Reactive mirror of `dragSession` for `createDragSession()`. Solid's signal is\n// the notification mechanism, replacing upstream's `subscriptions` Set.\nconst [trackedDragSession, setTrackedDragSession] = createSignal<DragSession | null>(null);\n\ninterface DropTarget {\n element: HTMLElement;\n preventFocusOnDrop?: boolean;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n onDropEnter?: (e: DropEnterEvent, dragTarget: DragTarget) => void;\n onDropExit?: (e: DropExitEvent) => void;\n onDropTargetEnter?: (target: DroppableCollectionTarget | null) => void;\n onDropActivate?: (e: DropActivateEvent, target: DroppableCollectionTarget | null) => void;\n onDrop?: (e: DropEvent, target: DroppableCollectionTarget | null) => void;\n onKeyDown?: (e: KeyboardEvent, dragTarget: DragTarget) => void;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropTarget(target: DropTarget): () => void {\n dropTargets.set(target.element, target);\n dragSession?.updateValidDropTargets();\n return (): void => {\n dropTargets.delete(target.element);\n dragSession?.updateValidDropTargets();\n };\n}\n\ninterface DroppableItem {\n element: HTMLElement;\n target: DroppableCollectionTarget;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropItem(item: DroppableItem): () => void {\n dropItems.set(item.element, item);\n return (): void => {\n dropItems.delete(item.element);\n };\n}\n\ninterface DragTarget {\n element: HTMLElement;\n items: DragItem[];\n allowedDropOperations: DropOperation[];\n onDragEnd?: (e: DragEndEvent) => void;\n}\n\nexport function beginDragging(target: DragTarget, stringFormatter: LocalizedStringFormatter): void {\n if (dragSession) {\n throw new Error(\"Cannot begin dragging while already dragging\");\n }\n\n dragSession = new DragSession(target, stringFormatter);\n setTrackedDragSession(dragSession);\n requestAnimationFrame(() => {\n if (dragSession) {\n dragSession.setup();\n if (getDragModality() === \"keyboard\") {\n dragSession.next();\n }\n }\n });\n}\n\n/** Reactive accessor for the active drag session, or null. */\nexport function createDragSession(): Accessor<DragSession | null> {\n return trackedDragSession;\n}\n\n/** @private */\nexport function isVirtualDragging(): boolean {\n return !!dragSession;\n}\n\nfunction endDragging() {\n dragSession = null;\n setTrackedDragSession(null);\n}\n\nexport function isValidDropTarget(element: Element): boolean {\n for (let target of dropTargets.keys()) {\n if (nodeContains(target, element)) {\n return true;\n }\n }\n\n return false;\n}\n\nconst CANCELED_EVENTS = [\n \"pointerdown\",\n \"pointermove\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointerover\",\n \"pointerout\",\n \"pointerup\",\n \"mousedown\",\n \"mousemove\",\n \"mouseenter\",\n \"mouseleave\",\n \"mouseover\",\n \"mouseout\",\n \"mouseup\",\n \"touchstart\",\n \"touchmove\",\n \"touchend\",\n \"focusin\",\n \"focusout\",\n];\n\nconst CLICK_EVENTS = [\"pointerup\", \"mouseup\", \"touchend\"];\n\nconst MESSAGES = {\n keyboard: \"dragStartedKeyboard\",\n touch: \"dragStartedTouch\",\n virtual: \"dragStartedVirtual\",\n};\n\nclass DragSession {\n dragTarget: DragTarget;\n validDropTargets: DropTarget[] = [];\n currentDropTarget: DropTarget | null = null;\n currentDropItem: DroppableItem | null = null;\n dropOperation: DropOperation | null = null;\n private mutationObserver: MutationObserver | null = null;\n private restoreAriaHidden: (() => void) | null = null;\n private stringFormatter: LocalizedStringFormatter;\n private isVirtualClick: boolean = false;\n private initialFocused: boolean;\n\n constructor(target: DragTarget, stringFormatter: LocalizedStringFormatter) {\n this.dragTarget = target;\n this.stringFormatter = stringFormatter;\n\n this.onKeyDown = this.onKeyDown.bind(this);\n this.onKeyUp = this.onKeyUp.bind(this);\n this.onFocus = this.onFocus.bind(this);\n this.onBlur = this.onBlur.bind(this);\n this.onClick = this.onClick.bind(this);\n this.onPointerDown = this.onPointerDown.bind(this);\n this.cancelEvent = this.cancelEvent.bind(this);\n this.initialFocused = false;\n }\n\n setup(): void {\n document.addEventListener(\"keydown\", this.onKeyDown, true);\n document.addEventListener(\"keyup\", this.onKeyUp, true);\n window.addEventListener(\"focus\", this.onFocus, true);\n window.addEventListener(\"blur\", this.onBlur, true);\n document.addEventListener(\"click\", this.onClick, true);\n document.addEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.addEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver = new MutationObserver(() => this.updateValidDropTargets());\n this.updateValidDropTargets();\n\n announce(this.stringFormatter.format(MESSAGES[getDragModality() as keyof typeof MESSAGES]));\n }\n\n teardown(): void {\n document.removeEventListener(\"keydown\", this.onKeyDown, true);\n document.removeEventListener(\"keyup\", this.onKeyUp, true);\n window.removeEventListener(\"focus\", this.onFocus, true);\n window.removeEventListener(\"blur\", this.onBlur, true);\n document.removeEventListener(\"click\", this.onClick, true);\n document.removeEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.removeEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver?.disconnect();\n this.restoreAriaHidden?.();\n }\n\n onKeyDown(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Escape\") {\n this.cancel();\n return;\n }\n\n if (e.key === \"Tab\" && !(e.metaKey || e.altKey || e.ctrlKey)) {\n if (e.shiftKey) {\n this.previous();\n } else {\n this.next();\n }\n }\n\n if (typeof this.currentDropTarget?.onKeyDown === \"function\") {\n this.currentDropTarget.onKeyDown(e, this.dragTarget);\n }\n }\n\n onKeyUp(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Enter\") {\n if (\n e.altKey ||\n nodeContains(this.getCurrentActivateButton(), getEventTarget<Node>(e))\n ) {\n this.activate(this.currentDropTarget, this.currentDropItem);\n } else {\n this.drop();\n }\n }\n }\n\n getCurrentActivateButton(): HTMLElement | null {\n return (\n this.currentDropItem?.activateButtonRef?.() ??\n this.currentDropTarget?.activateButtonRef?.() ??\n null\n );\n }\n\n onFocus(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n let eventTarget = getEventTarget<HTMLElement>(e);\n if (eventTarget === activateButton) {\n // TODO: canceling this breaks the focus ring. Revisit when we support tabbing.\n this.cancelEvent(e);\n return;\n }\n\n // Prevent focus events, except to the original drag target.\n if (eventTarget !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.\n if (!(eventTarget instanceof HTMLElement) || eventTarget === this.dragTarget.element) {\n return;\n }\n\n let dropTarget =\n this.validDropTargets.find((target) => target.element === eventTarget) ||\n this.validDropTargets.find((target) => nodeContains(target.element, eventTarget));\n\n if (!dropTarget) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n return;\n }\n\n let item = dropItems.get(eventTarget);\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n }\n }\n\n onBlur(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n // Guard activateButton non-null so this doesn't trip on the case where\n // there's no activate button and the focused element loses focus to nothing\n // (browsers and jsdom 26+ both set relatedTarget to null in that case).\n if (activateButton && e.relatedTarget === activateButton) {\n this.cancelEvent(e);\n return;\n }\n\n if (getEventTarget(e) !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // If nothing is gaining focus, or e.relatedTarget is the window/document (JSDOM),\n // restore focus back to the current drop target if any, or the original drag target.\n if (!e.relatedTarget || !(e.relatedTarget instanceof HTMLElement)) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n }\n }\n\n onClick(e: MouseEvent): void {\n this.cancelEvent(e);\n if (isVirtualClick(e) || this.isVirtualClick) {\n let dropElements = dropItems.values();\n let eventTarget = getEventTarget<HTMLElement>(e);\n let item = [...dropElements].find(\n (item) =>\n item.element === eventTarget ||\n nodeContains(item.activateButtonRef?.() ?? null, eventTarget),\n );\n let dropTarget = this.validDropTargets.find((target) =>\n nodeContains(target.element, eventTarget),\n );\n let activateButton = item?.activateButtonRef?.() ?? dropTarget?.activateButtonRef?.() ?? null;\n if (nodeContains(activateButton, eventTarget) && dropTarget) {\n this.activate(dropTarget, item);\n return;\n }\n\n if (getEventTarget(e) === this.dragTarget.element) {\n this.cancel();\n return;\n }\n\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n this.drop(item);\n }\n }\n }\n\n onPointerDown(e: PointerEvent): void {\n // Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires\n // so we can properly perform cancel and drop operations.\n this.cancelEvent(e);\n this.isVirtualClick = isVirtualPointerEvent(e);\n }\n\n cancelEvent(e: Event): void {\n // Allow focusin and focusout on the drag target so focus ring works properly.\n let eventTarget = getEventTarget(e);\n if (\n (e.type === \"focusin\" || e.type === \"focusout\") &&\n (eventTarget === this.dragTarget?.element || eventTarget === this.getCurrentActivateButton())\n ) {\n return;\n }\n\n // Allow default for events that might cancel a click event\n if (!CLICK_EVENTS.includes(e.type)) {\n e.preventDefault();\n }\n\n e.stopPropagation();\n e.stopImmediatePropagation();\n }\n\n updateValidDropTargets(): void {\n if (!this.mutationObserver) {\n return;\n }\n\n this.mutationObserver.disconnect();\n if (this.restoreAriaHidden) {\n this.restoreAriaHidden();\n }\n\n this.validDropTargets = findValidDropTargets(this.dragTarget);\n\n // Shuffle drop target order based on starting drag target.\n if (this.validDropTargets.length > 0) {\n let nearestIndex = this.findNearestDropTarget();\n this.validDropTargets = [\n ...this.validDropTargets.slice(nearestIndex),\n ...this.validDropTargets.slice(0, nearestIndex),\n ];\n }\n\n if (this.currentDropTarget && !this.validDropTargets.includes(this.currentDropTarget)) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n\n // Find valid drop items within collections\n let types = getTypes(this.dragTarget.items);\n let validDropItems = [...dropItems.values()].filter((item) => {\n if (typeof item.getDropOperation === \"function\") {\n return item.getDropOperation(types, this.dragTarget.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n\n // Filter out drop targets that contain valid items. We don't want to stop hiding elements\n // other than the drop items that exist inside the collection.\n let visibleDropTargets = this.validDropTargets.filter(\n (target) => !validDropItems.some((item) => nodeContains(target.element, item.element)),\n );\n\n this.restoreAriaHidden = ariaHideOutside(\n [\n this.dragTarget.element,\n ...validDropItems.flatMap((item) => {\n let button = item.activateButtonRef?.();\n return button ? [item.element, button] : [item.element];\n }),\n ...visibleDropTargets.flatMap((target) => {\n let button = target.activateButtonRef?.();\n return button ? [target.element, button] : [target.element];\n }),\n ],\n { shouldUseInert: true },\n );\n\n this.mutationObserver.observe(document.body, {\n subtree: true,\n attributes: true,\n attributeFilter: [\"aria-hidden\", \"inert\"],\n });\n }\n\n next(): void {\n // TODO: Allow tabbing to the activate button. Revisit once we fix the focus ring.\n // For now, the activate button is reachable by screen readers and ArrowLeft/ArrowRight\n // is usable specifically by Tree. Will need tabbing for other components.\n\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n // If we've reached the end of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === this.validDropTargets.length - 1) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index + 1]);\n }\n }\n\n previous(): void {\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n // If we've reached the start of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === 0) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index - 1]);\n }\n }\n\n findNearestDropTarget(): number {\n let dragTargetRect = this.dragTarget.element.getBoundingClientRect();\n\n let minDistance = Infinity;\n let nearest = -1;\n for (let i = 0; i < this.validDropTargets.length; i++) {\n let dropTarget = this.validDropTargets[i];\n let rect = dropTarget.element.getBoundingClientRect();\n let dx = rect.left - dragTargetRect.left;\n let dy = rect.top - dragTargetRect.top;\n let dist = dx * dx + dy * dy;\n if (dist < minDistance) {\n minDistance = dist;\n nearest = i;\n }\n }\n\n return nearest;\n }\n\n setCurrentDropTarget(dropTarget: DropTarget | null, item?: DroppableItem): void {\n if (dropTarget !== this.currentDropTarget) {\n if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === \"function\") {\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDropExit({\n type: \"dropexit\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n });\n }\n\n this.currentDropTarget = dropTarget;\n\n if (dropTarget) {\n if (typeof dropTarget.onDropEnter === \"function\") {\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropEnter(\n {\n type: \"dropenter\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n this.dragTarget,\n );\n }\n\n if (!item) {\n dropTarget?.element.focus();\n }\n }\n }\n\n if (item != null && item !== this.currentDropItem) {\n if (this.currentDropTarget && typeof this.currentDropTarget.onDropTargetEnter === \"function\") {\n this.currentDropTarget.onDropTargetEnter(item.target);\n }\n item.element.focus();\n this.currentDropItem = item;\n\n // Announce first drop target after drag start announcement finishes.\n // Otherwise, it will never get announced because drag start announcement is assertive.\n if (!this.initialFocused) {\n let label = item?.element.getAttribute(\"aria-label\");\n if (label) {\n announce(label, \"polite\");\n }\n this.initialFocused = true;\n }\n }\n }\n\n end(): void {\n this.teardown();\n endDragging();\n\n if (typeof this.dragTarget.onDragEnd === \"function\") {\n let target =\n this.currentDropTarget && this.dropOperation !== \"cancel\"\n ? this.currentDropTarget\n : this.dragTarget;\n let rect = target.element.getBoundingClientRect();\n this.dragTarget.onDragEnd({\n type: \"dragend\",\n x: rect.x + rect.width / 2,\n y: rect.y + rect.height / 2,\n dropOperation: this.dropOperation || \"cancel\",\n });\n }\n\n if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) {\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n // This corrects state such as whether focus ring should appear.\n // useDroppableCollection handles this itself, so this is only for standalone drop zones.\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n }\n\n this.setCurrentDropTarget(null);\n }\n\n cancel(): void {\n this.setCurrentDropTarget(null);\n this.end();\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.dragTarget.element.focus();\n }\n\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n\n announce(this.stringFormatter.format(\"dropCanceled\"));\n }\n\n drop(item?: DroppableItem): void {\n if (!this.currentDropTarget) {\n this.cancel();\n return;\n }\n\n if (typeof item?.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations);\n } else if (typeof this.currentDropTarget.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = this.currentDropTarget.getDropOperation(\n types,\n this.dragTarget.allowedDropOperations,\n );\n } else {\n // TODO: show menu ??\n this.dropOperation = this.dragTarget.allowedDropOperations[0];\n }\n\n if (typeof this.currentDropTarget.onDrop === \"function\") {\n let items: DropItem[] = this.dragTarget.items.map((item) => ({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type: string) => Promise.resolve(item[type]),\n }));\n\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDrop(\n {\n type: \"drop\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n items,\n dropOperation: this.dropOperation,\n },\n item?.target ?? null,\n );\n }\n\n this.end();\n announce(this.stringFormatter.format(\"dropComplete\"));\n }\n\n activate(dropTarget: DropTarget | null, dropItem: DroppableItem | null | undefined): void {\n if (dropTarget && typeof dropTarget.onDropActivate === \"function\") {\n let target = dropItem?.target ?? null;\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropActivate(\n {\n type: \"dropactivate\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n target,\n );\n }\n }\n}\n\nfunction findValidDropTargets(options: DragTarget): DropTarget[] {\n let types = getTypes(options.items);\n return [...dropTargets.values()].filter((target) => {\n if (target.element.closest('[aria-hidden=\"true\"], [inert]')) {\n return false;\n }\n\n if (typeof target.getDropOperation === \"function\") {\n return target.getDropOperation(types, options.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n}\n\nexport type { DragTarget, DropTarget, DroppableItem, DragSession };\n"],"mappings":";;;;;;;;AAiBA,MAAa,oBAAiC,IAAI,IAAI;CAAC;CAAc;CAAiB;AAAW,CAAC;AAGlG,MAAa,mBAAmB;AAGhC,MAAa,eAAe;AAG5B,IAAY,iBAAL,yBAAA,gBAAA;CACL,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,YAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,SAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAGA,MAAa,yBAAiD;CAC5D,MAAA;CACA,MAAA;CACA,UAAU;CACV,UAAU;CACV,MAAA;CACA,UAAU;CACV,MAAA;CACA,KAAA;CACA,eAAA;AACF;AAGA,MAAa,iBAAyC;MAC7B;MACA;MACA;EACtB,IAA4C;MACtB;EACtB,IAA4C;EAC5C,IAA4C;MACvB;AACxB;AAGA,MAAa,gCAA+D;CAC1E,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR;AAGA,MAAa,gCAA+D;CAC1E,QAAQ;CACR,MAAM;CAC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AAO,KAAK,kBAAkB,WAAW,YAAY;GACvD,IAAI,QAAoB,KAAK,WAAW,MAAM,KAAK,UAAU;IAC3D,MAAM;IACN,OAAO,IAAI,IAAI,OAAO,KAAK,IAAI,CAAC;IAChC,UAAU,SAAiB,QAAQ,QAAQ,KAAK,KAAK;GACvD,EAAE;GAEF,IAAI,OAAO,KAAK,kBAAkB,QAAQ,sBAAsB;GAChE,KAAK,kBAAkB,OACrB;IACE,MAAM;IACN,GAAG,KAAK,OAAO,KAAK,QAAQ;IAC5B,GAAG,KAAK,MAAM,KAAK,SAAS;IAC5B;IACA,eAAe,KAAK;GACtB,GACA,MAAM,UAAU,IAClB;EACF;EAEA,KAAK,IAAI;EACT,SAAS,KAAK,gBAAgB,OAAO,cAAc,CAAC;CACtD;CAEA,SAAS,YAA+B,UAAkD;EACxF,IAAI,cAAc,OAAO,WAAW,mBAAmB,YAAY;GACjE,IAAI,SAAS,UAAU,UAAU;GACjC,IAAI,OAAO,WAAW,QAAQ,sBAAsB;GACpD,WAAW,eACT;IACE,MAAM;IACN,GAAG,KAAK,OAAO,KAAK,QAAQ;IAC5B,GAAG,KAAK,MAAM,KAAK,SAAS;GAC9B,GACA,MACF;EACF;CACF;AACF;AAEA,SAAS,qBAAqB,SAAmC;CAC/D,IAAI,QAAQ,SAAS,QAAQ,KAAK;CAClC,OAAO,CAAC,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,QAAQ,WAAW;EAClD,IAAI,OAAO,QAAQ,QAAQ,iCAA+B,GACxD,OAAO;EAGT,IAAI,OAAO,OAAO,qBAAqB,YACrC,OAAO,OAAO,iBAAiB,OAAO,QAAQ,qBAAqB,MAAM;EAG3E,OAAO;CACT,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"DragManager.jsx","names":[],"sources":["../../src/dnd/utils.ts","../../src/dnd/DragManager.ts"],"sourcesContent":["/**\n * Drag and Drop utilities for solidaria.\n */\n\nimport type {\n DragItem,\n DragType,\n DropItem,\n TextDropItem,\n FileDropItem,\n DirectoryDropItem,\n DropOperation,\n} from \"@proyecto-viviana/solid-stately\";\nimport { DIRECTORY_DRAG_TYPE } from \"@proyecto-viviana/solid-stately\";\nimport { getInteractionModality } from \"../interactions\";\n\n// Native drag types that can be transferred between applications\nexport const NATIVE_DRAG_TYPES: Set<string> = new Set([\"text/plain\", \"text/uri-list\", \"text/html\"]);\n\n// Custom drag type for serializing multiple items\nexport const CUSTOM_DRAG_TYPE = \"application/vnd.solidaria.items+json\";\n\n// Generic type for unknown file types\nexport const GENERIC_TYPE = \"application/octet-stream\";\n\n// Drop operation bit flags\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = (1 << 0) | (1 << 1) | (1 << 2),\n}\n\n// Map from effectAllowed to DROP_OPERATION\nexport const DROP_OPERATION_ALLOWED: Record<string, number> = {\n none: DROP_OPERATION.none,\n copy: DROP_OPERATION.copy,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n link: DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n move: DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all,\n};\n\n// Map from DROP_OPERATION to effectAllowed\nexport const EFFECT_ALLOWED: Record<number, string> = {\n [DROP_OPERATION.none]: \"none\",\n [DROP_OPERATION.move]: \"move\",\n [DROP_OPERATION.copy]: \"copy\",\n [DROP_OPERATION.copy | DROP_OPERATION.move]: \"copyMove\",\n [DROP_OPERATION.link]: \"link\",\n [DROP_OPERATION.link | DROP_OPERATION.move]: \"linkMove\",\n [DROP_OPERATION.copy | DROP_OPERATION.link]: \"copyLink\",\n [DROP_OPERATION.all]: \"all\",\n};\n\n// Map from dropEffect to DropOperation\nexport const DROP_EFFECT_TO_DROP_OPERATION: Record<string, DropOperation> = {\n none: \"cancel\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n// Map from DropOperation to dropEffect\nexport const DROP_OPERATION_TO_DROP_EFFECT: Record<DropOperation, string> = {\n cancel: \"none\",\n link: \"link\",\n copy: \"copy\",\n move: \"move\",\n};\n\n/**\n * Maps the current interaction modality onto the drag modality used for\n * announcements and descriptions. Mirrors @react-aria/dnd `mapModality`:\n * pointer collapses to virtual, and a virtual modality on a coarse pointer\n * (touch screen reader) becomes touch.\n */\nfunction mapModality(modality: string | null): string {\n if (!modality) {\n modality = \"virtual\";\n }\n\n if (modality === \"pointer\") {\n modality = \"virtual\";\n }\n\n if (\n modality === \"virtual\" &&\n typeof window !== \"undefined\" &&\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(pointer: coarse)\").matches\n ) {\n modality = \"touch\";\n }\n\n return modality;\n}\n\n/**\n * Returns the drag modality ('keyboard' | 'virtual' | 'touch') for the current\n * interaction. Mirrors @react-aria/dnd `getDragModality`.\n */\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\n/**\n * Get the types present in drag items.\n */\nexport function getTypes(items: DragItem[]): Set<string> {\n const types = new Set<string>();\n for (const item of items) {\n for (const type of Object.keys(item)) {\n types.add(type);\n }\n }\n return types;\n}\n\n/**\n * Write drag items to a DataTransfer object.\n */\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n const groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n const customData: object[] = [];\n\n for (const item of items) {\n const types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n const dataByType: Record<string, string> = {};\n for (const type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n const data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (const [type, typeItems] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Join all items of this type with newlines\n const data = typeItems.join(\"\\n\");\n dataTransfer.items.add(data, type);\n } else {\n // Set first item for non-native types\n dataTransfer.items.add(typeItems[0], type);\n }\n }\n\n if (needsCustomData) {\n const data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\n/**\n * Read drop items from a DataTransfer object.\n */\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n const items: DropItem[] = [];\n\n if (!dataTransfer) {\n return items;\n }\n\n // Check for custom drag type first\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n const data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n const parsed = JSON.parse(data);\n for (const item of parsed) {\n items.push({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type]),\n });\n }\n hasCustomType = true;\n } catch {\n // ignore parsing errors\n }\n }\n\n // Fall back to native items\n if (!hasCustomType) {\n const stringItems = new Map<string, string>();\n\n for (const item of dataTransfer.items) {\n if (item.kind === \"string\") {\n const type = item.type || GENERIC_TYPE;\n stringItems.set(type, dataTransfer.getData(item.type));\n } else if (item.kind === \"file\") {\n const file = item.getAsFile();\n if (file) {\n items.push(createFileItem(file));\n }\n }\n }\n\n if (stringItems.size > 0) {\n items.push({\n kind: \"text\",\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type) ?? \"\"),\n });\n }\n }\n\n return items;\n}\n\n/**\n * Create a FileDropItem from a File object.\n */\nfunction createFileItem(file: File): FileDropItem {\n return {\n kind: \"file\",\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => file.text(),\n getFile: () => Promise.resolve(file),\n };\n}\n\n/**\n * DragTypes implementation for checking drag types.\n */\nexport class DragTypesImpl {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n let hasFiles = false;\n\n for (const item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === \"file\") {\n hasFiles = true;\n }\n if (item.type) {\n this.types.add(item.type);\n } else {\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // Safari doesn't expose file types until drop\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes(\"Files\");\n }\n\n has(type: DragType | DragType[]): boolean {\n if (Array.isArray(type)) {\n return type.some((t) => this.has(t));\n }\n\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE)) ||\n type === \"*/*\"\n ) {\n return true;\n }\n\n if (typeof type === \"string\") {\n // Wildcard MIME match, e.g. \"image/*\" accepts \"image/png\".\n if (type.endsWith(\"/*\")) {\n for (const key of this.types) {\n if (key.startsWith(type.slice(0, -2))) {\n return true;\n }\n }\n return false;\n }\n return this.types.has(type);\n }\n\n return false;\n }\n}\n\n/**\n * Check if a drop item is a text item.\n */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === \"text\";\n}\n\n/**\n * Check if a drop item is a file item.\n */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === \"file\";\n}\n\n/**\n * Check if a drop item is a directory item.\n */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === \"directory\";\n}\n\n// Global state for tracking drag operations\nlet globalDropEffect: string | undefined;\nlet globalAllowedDropOperations: number = DROP_OPERATION.none;\n\nexport function setGlobalDropEffect(effect: string | undefined): void {\n globalDropEffect = effect;\n}\n\nexport function getGlobalDropEffect(): string | undefined {\n return globalDropEffect;\n}\n\nexport function setGlobalAllowedDropOperations(ops: number): void {\n globalAllowedDropOperations = ops;\n}\n\nexport function getGlobalAllowedDropOperations(): number {\n return globalAllowedDropOperations;\n}\n","/**\n * Global keyboard/virtual drag session manager.\n *\n * Faithful port of @react-aria/dnd `DragManager` (react-aria 3.50). A single\n * module-level singleton owns the active drag session: it registers drop targets\n * and drop items across every collection on the page, drives Tab/Shift+Tab\n * cycling between them, Enter-to-drop / Escape-to-cancel, and the aria-live\n * announcements — providing the accessible keyboard alternative to native\n * pointer drag and drop.\n *\n * The only framework-specific adaptation from upstream is the reactive\n * subscription: React's `useDragSession` (useState + a subscription Set) becomes\n * a module-level Solid signal exposed through `createDragSession()`. Element refs\n * (upstream `RefObject.current`) become Solid element accessors (`() => el`).\n */\n\nimport { createSignal, type Accessor } from \"solid-js\";\n\nimport { announce } from \"../live-announcer/announce\";\nimport { ariaHideOutside } from \"../overlays/ariaHideOutside\";\nimport type {\n DragEndEvent,\n DragItem,\n DropActivateEvent,\n DropEnterEvent,\n DropEvent,\n DropExitEvent,\n DropItem,\n DropOperation,\n DropTarget as DroppableCollectionTarget,\n} from \"@proyecto-viviana/solid-stately\";\nimport { getActiveElement, getEventTarget, nodeContains } from \"../utils/dom\";\nimport { getDragModality, getTypes } from \"./utils\";\nimport { isVirtualClick, isVirtualPointerEvent } from \"../utils/events\";\nimport type { LocalizedStringFormatter } from \"@internationalized/string\";\n\n/** A Solid element accessor, replacing upstream's `RefObject<T>.current`. */\ntype ElementAccessor = () => HTMLElement | null;\n\nlet dropTargets = new Map<Element, DropTarget>();\nlet dropItems = new Map<Element, DroppableItem>();\nlet dragSession: DragSession | null = null;\n\n// Reactive mirror of `dragSession` for `createDragSession()`. Solid's signal is\n// the notification mechanism, replacing upstream's `subscriptions` Set.\nconst [trackedDragSession, setTrackedDragSession] = createSignal<DragSession | null>(null);\n\ninterface DropTarget {\n element: HTMLElement;\n preventFocusOnDrop?: boolean;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n onDropEnter?: (e: DropEnterEvent, dragTarget: DragTarget) => void;\n onDropExit?: (e: DropExitEvent) => void;\n onDropTargetEnter?: (target: DroppableCollectionTarget | null) => void;\n onDropActivate?: (e: DropActivateEvent, target: DroppableCollectionTarget | null) => void;\n onDrop?: (e: DropEvent, target: DroppableCollectionTarget | null) => void;\n onKeyDown?: (e: KeyboardEvent, dragTarget: DragTarget) => void;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropTarget(target: DropTarget): () => void {\n dropTargets.set(target.element, target);\n dragSession?.updateValidDropTargets();\n return (): void => {\n dropTargets.delete(target.element);\n dragSession?.updateValidDropTargets();\n };\n}\n\ninterface DroppableItem {\n element: HTMLElement;\n target: DroppableCollectionTarget;\n getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;\n activateButtonRef?: ElementAccessor;\n}\n\nexport function registerDropItem(item: DroppableItem): () => void {\n dropItems.set(item.element, item);\n return (): void => {\n dropItems.delete(item.element);\n };\n}\n\ninterface DragTarget {\n element: HTMLElement;\n items: DragItem[];\n allowedDropOperations: DropOperation[];\n onDragEnd?: (e: DragEndEvent) => void;\n}\n\nexport function beginDragging(target: DragTarget, stringFormatter: LocalizedStringFormatter): void {\n if (dragSession) {\n throw new Error(\"Cannot begin dragging while already dragging\");\n }\n\n dragSession = new DragSession(target, stringFormatter);\n setTrackedDragSession(dragSession);\n requestAnimationFrame(() => {\n if (dragSession) {\n dragSession.setup();\n if (getDragModality() === \"keyboard\") {\n dragSession.next();\n }\n }\n });\n}\n\n/** Reactive accessor for the active drag session, or null. */\nexport function createDragSession(): Accessor<DragSession | null> {\n return trackedDragSession;\n}\n\n/** @private */\nexport function isVirtualDragging(): boolean {\n return !!dragSession;\n}\n\nfunction endDragging() {\n dragSession = null;\n setTrackedDragSession(null);\n}\n\nexport function isValidDropTarget(element: Element): boolean {\n for (let target of dropTargets.keys()) {\n if (nodeContains(target, element)) {\n return true;\n }\n }\n\n return false;\n}\n\nconst CANCELED_EVENTS = [\n \"pointerdown\",\n \"pointermove\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointerover\",\n \"pointerout\",\n \"pointerup\",\n \"mousedown\",\n \"mousemove\",\n \"mouseenter\",\n \"mouseleave\",\n \"mouseover\",\n \"mouseout\",\n \"mouseup\",\n \"touchstart\",\n \"touchmove\",\n \"touchend\",\n \"focusin\",\n \"focusout\",\n];\n\nconst CLICK_EVENTS = [\"pointerup\", \"mouseup\", \"touchend\"];\n\nconst MESSAGES = {\n keyboard: \"dragStartedKeyboard\",\n touch: \"dragStartedTouch\",\n virtual: \"dragStartedVirtual\",\n};\n\nclass DragSession {\n dragTarget: DragTarget;\n validDropTargets: DropTarget[] = [];\n currentDropTarget: DropTarget | null = null;\n currentDropItem: DroppableItem | null = null;\n dropOperation: DropOperation | null = null;\n private mutationObserver: MutationObserver | null = null;\n private restoreAriaHidden: (() => void) | null = null;\n private stringFormatter: LocalizedStringFormatter;\n private isVirtualClick: boolean = false;\n private initialFocused: boolean;\n\n constructor(target: DragTarget, stringFormatter: LocalizedStringFormatter) {\n this.dragTarget = target;\n this.stringFormatter = stringFormatter;\n\n this.onKeyDown = this.onKeyDown.bind(this);\n this.onKeyUp = this.onKeyUp.bind(this);\n this.onFocus = this.onFocus.bind(this);\n this.onBlur = this.onBlur.bind(this);\n this.onClick = this.onClick.bind(this);\n this.onPointerDown = this.onPointerDown.bind(this);\n this.cancelEvent = this.cancelEvent.bind(this);\n this.initialFocused = false;\n }\n\n setup(): void {\n document.addEventListener(\"keydown\", this.onKeyDown, true);\n document.addEventListener(\"keyup\", this.onKeyUp, true);\n window.addEventListener(\"focus\", this.onFocus, true);\n window.addEventListener(\"blur\", this.onBlur, true);\n document.addEventListener(\"click\", this.onClick, true);\n document.addEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.addEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver = new MutationObserver(() => this.updateValidDropTargets());\n this.updateValidDropTargets();\n\n announce(this.stringFormatter.format(MESSAGES[getDragModality() as keyof typeof MESSAGES]));\n }\n\n teardown(): void {\n document.removeEventListener(\"keydown\", this.onKeyDown, true);\n document.removeEventListener(\"keyup\", this.onKeyUp, true);\n window.removeEventListener(\"focus\", this.onFocus, true);\n window.removeEventListener(\"blur\", this.onBlur, true);\n document.removeEventListener(\"click\", this.onClick, true);\n document.removeEventListener(\"pointerdown\", this.onPointerDown, true);\n\n for (let event of CANCELED_EVENTS) {\n document.removeEventListener(event, this.cancelEvent, true);\n }\n\n this.mutationObserver?.disconnect();\n this.restoreAriaHidden?.();\n }\n\n onKeyDown(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Escape\") {\n this.cancel();\n return;\n }\n\n if (e.key === \"Tab\" && !(e.metaKey || e.altKey || e.ctrlKey)) {\n if (e.shiftKey) {\n this.previous();\n } else {\n this.next();\n }\n }\n\n if (typeof this.currentDropTarget?.onKeyDown === \"function\") {\n this.currentDropTarget.onKeyDown(e, this.dragTarget);\n }\n }\n\n onKeyUp(e: KeyboardEvent): void {\n this.cancelEvent(e);\n\n if (e.key === \"Enter\") {\n if (e.altKey || nodeContains(this.getCurrentActivateButton(), getEventTarget<Node>(e))) {\n this.activate(this.currentDropTarget, this.currentDropItem);\n } else {\n this.drop();\n }\n }\n }\n\n getCurrentActivateButton(): HTMLElement | null {\n return (\n this.currentDropItem?.activateButtonRef?.() ??\n this.currentDropTarget?.activateButtonRef?.() ??\n null\n );\n }\n\n onFocus(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n let eventTarget = getEventTarget<HTMLElement>(e);\n if (eventTarget === activateButton) {\n // TODO: canceling this breaks the focus ring. Revisit when we support tabbing.\n this.cancelEvent(e);\n return;\n }\n\n // Prevent focus events, except to the original drag target.\n if (eventTarget !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.\n if (!(eventTarget instanceof HTMLElement) || eventTarget === this.dragTarget.element) {\n return;\n }\n\n let dropTarget =\n this.validDropTargets.find((target) => target.element === eventTarget) ||\n this.validDropTargets.find((target) => nodeContains(target.element, eventTarget));\n\n if (!dropTarget) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n return;\n }\n\n let item = dropItems.get(eventTarget);\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n }\n }\n\n onBlur(e: FocusEvent): void {\n let activateButton = this.getCurrentActivateButton();\n // Guard activateButton non-null so this doesn't trip on the case where\n // there's no activate button and the focused element loses focus to nothing\n // (browsers and jsdom 26+ both set relatedTarget to null in that case).\n if (activateButton && e.relatedTarget === activateButton) {\n this.cancelEvent(e);\n return;\n }\n\n if (getEventTarget(e) !== this.dragTarget.element) {\n this.cancelEvent(e);\n }\n\n // If nothing is gaining focus, or e.relatedTarget is the window/document (JSDOM),\n // restore focus back to the current drop target if any, or the original drag target.\n if (!e.relatedTarget || !(e.relatedTarget instanceof HTMLElement)) {\n if (this.currentDropTarget) {\n this.currentDropTarget.element.focus();\n } else {\n this.dragTarget.element.focus();\n }\n }\n }\n\n onClick(e: MouseEvent): void {\n this.cancelEvent(e);\n if (isVirtualClick(e) || this.isVirtualClick) {\n let dropElements = dropItems.values();\n let eventTarget = getEventTarget<HTMLElement>(e);\n let item = [...dropElements].find(\n (item) =>\n item.element === eventTarget ||\n nodeContains(item.activateButtonRef?.() ?? null, eventTarget),\n );\n let dropTarget = this.validDropTargets.find((target) =>\n nodeContains(target.element, eventTarget),\n );\n let activateButton = item?.activateButtonRef?.() ?? dropTarget?.activateButtonRef?.() ?? null;\n if (nodeContains(activateButton, eventTarget) && dropTarget) {\n this.activate(dropTarget, item);\n return;\n }\n\n if (getEventTarget(e) === this.dragTarget.element) {\n this.cancel();\n return;\n }\n\n if (dropTarget) {\n this.setCurrentDropTarget(dropTarget, item);\n this.drop(item);\n }\n }\n }\n\n onPointerDown(e: PointerEvent): void {\n // Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires\n // so we can properly perform cancel and drop operations.\n this.cancelEvent(e);\n this.isVirtualClick = isVirtualPointerEvent(e);\n }\n\n cancelEvent(e: Event): void {\n // Allow focusin and focusout on the drag target so focus ring works properly.\n let eventTarget = getEventTarget(e);\n if (\n (e.type === \"focusin\" || e.type === \"focusout\") &&\n (eventTarget === this.dragTarget?.element || eventTarget === this.getCurrentActivateButton())\n ) {\n return;\n }\n\n // Allow default for events that might cancel a click event\n if (!CLICK_EVENTS.includes(e.type)) {\n e.preventDefault();\n }\n\n e.stopPropagation();\n e.stopImmediatePropagation();\n }\n\n updateValidDropTargets(): void {\n if (!this.mutationObserver) {\n return;\n }\n\n this.mutationObserver.disconnect();\n if (this.restoreAriaHidden) {\n this.restoreAriaHidden();\n }\n\n this.validDropTargets = findValidDropTargets(this.dragTarget);\n\n // Shuffle drop target order based on starting drag target.\n if (this.validDropTargets.length > 0) {\n let nearestIndex = this.findNearestDropTarget();\n this.validDropTargets = [\n ...this.validDropTargets.slice(nearestIndex),\n ...this.validDropTargets.slice(0, nearestIndex),\n ];\n }\n\n if (this.currentDropTarget && !this.validDropTargets.includes(this.currentDropTarget)) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n\n // Find valid drop items within collections\n let types = getTypes(this.dragTarget.items);\n let validDropItems = [...dropItems.values()].filter((item) => {\n if (typeof item.getDropOperation === \"function\") {\n return item.getDropOperation(types, this.dragTarget.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n\n // Filter out drop targets that contain valid items. We don't want to stop hiding elements\n // other than the drop items that exist inside the collection.\n let visibleDropTargets = this.validDropTargets.filter(\n (target) => !validDropItems.some((item) => nodeContains(target.element, item.element)),\n );\n\n this.restoreAriaHidden = ariaHideOutside(\n [\n this.dragTarget.element,\n ...validDropItems.flatMap((item) => {\n let button = item.activateButtonRef?.();\n return button ? [item.element, button] : [item.element];\n }),\n ...visibleDropTargets.flatMap((target) => {\n let button = target.activateButtonRef?.();\n return button ? [target.element, button] : [target.element];\n }),\n ],\n { shouldUseInert: true },\n );\n\n this.mutationObserver.observe(document.body, {\n subtree: true,\n attributes: true,\n attributeFilter: [\"aria-hidden\", \"inert\"],\n });\n }\n\n next(): void {\n // TODO: Allow tabbing to the activate button. Revisit once we fix the focus ring.\n // For now, the activate button is reachable by screen readers and ArrowLeft/ArrowRight\n // is usable specifically by Tree. Will need tabbing for other components.\n\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n return;\n }\n\n // If we've reached the end of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === this.validDropTargets.length - 1) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[0]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index + 1]);\n }\n }\n\n previous(): void {\n if (!this.currentDropTarget) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n let index = this.validDropTargets.indexOf(this.currentDropTarget);\n if (index < 0) {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n return;\n }\n\n // If we've reached the start of the valid drop targets, cycle back to the original drag target.\n // This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).\n if (index === 0) {\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.setCurrentDropTarget(null);\n this.dragTarget.element.focus();\n } else {\n this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);\n }\n } else {\n this.setCurrentDropTarget(this.validDropTargets[index - 1]);\n }\n }\n\n findNearestDropTarget(): number {\n let dragTargetRect = this.dragTarget.element.getBoundingClientRect();\n\n let minDistance = Infinity;\n let nearest = -1;\n for (let i = 0; i < this.validDropTargets.length; i++) {\n let dropTarget = this.validDropTargets[i];\n let rect = dropTarget.element.getBoundingClientRect();\n let dx = rect.left - dragTargetRect.left;\n let dy = rect.top - dragTargetRect.top;\n let dist = dx * dx + dy * dy;\n if (dist < minDistance) {\n minDistance = dist;\n nearest = i;\n }\n }\n\n return nearest;\n }\n\n setCurrentDropTarget(dropTarget: DropTarget | null, item?: DroppableItem): void {\n if (dropTarget !== this.currentDropTarget) {\n if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === \"function\") {\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDropExit({\n type: \"dropexit\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n });\n }\n\n this.currentDropTarget = dropTarget;\n\n if (dropTarget) {\n if (typeof dropTarget.onDropEnter === \"function\") {\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropEnter(\n {\n type: \"dropenter\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n this.dragTarget,\n );\n }\n\n if (!item) {\n dropTarget?.element.focus();\n }\n }\n }\n\n if (item != null && item !== this.currentDropItem) {\n if (\n this.currentDropTarget &&\n typeof this.currentDropTarget.onDropTargetEnter === \"function\"\n ) {\n this.currentDropTarget.onDropTargetEnter(item.target);\n }\n item.element.focus();\n this.currentDropItem = item;\n\n // Announce first drop target after drag start announcement finishes.\n // Otherwise, it will never get announced because drag start announcement is assertive.\n if (!this.initialFocused) {\n let label = item?.element.getAttribute(\"aria-label\");\n if (label) {\n announce(label, \"polite\");\n }\n this.initialFocused = true;\n }\n }\n }\n\n end(): void {\n this.teardown();\n endDragging();\n\n if (typeof this.dragTarget.onDragEnd === \"function\") {\n let target =\n this.currentDropTarget && this.dropOperation !== \"cancel\"\n ? this.currentDropTarget\n : this.dragTarget;\n let rect = target.element.getBoundingClientRect();\n this.dragTarget.onDragEnd({\n type: \"dragend\",\n x: rect.x + rect.width / 2,\n y: rect.y + rect.height / 2,\n dropOperation: this.dropOperation || \"cancel\",\n });\n }\n\n if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) {\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n // This corrects state such as whether focus ring should appear.\n // useDroppableCollection handles this itself, so this is only for standalone drop zones.\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n }\n\n this.setCurrentDropTarget(null);\n }\n\n cancel(): void {\n this.setCurrentDropTarget(null);\n this.end();\n if (!this.dragTarget.element.closest('[aria-hidden=\"true\"], [inert]')) {\n this.dragTarget.element.focus();\n }\n\n // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).\n getActiveElement()?.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true }));\n\n announce(this.stringFormatter.format(\"dropCanceled\"));\n }\n\n drop(item?: DroppableItem): void {\n if (!this.currentDropTarget) {\n this.cancel();\n return;\n }\n\n if (typeof item?.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations);\n } else if (typeof this.currentDropTarget.getDropOperation === \"function\") {\n let types = getTypes(this.dragTarget.items);\n this.dropOperation = this.currentDropTarget.getDropOperation(\n types,\n this.dragTarget.allowedDropOperations,\n );\n } else {\n // TODO: show menu ??\n this.dropOperation = this.dragTarget.allowedDropOperations[0];\n }\n\n if (typeof this.currentDropTarget.onDrop === \"function\") {\n let items: DropItem[] = this.dragTarget.items.map((item) => ({\n kind: \"text\",\n types: new Set(Object.keys(item)),\n getText: (type: string) => Promise.resolve(item[type]),\n }));\n\n let rect = this.currentDropTarget.element.getBoundingClientRect();\n this.currentDropTarget.onDrop(\n {\n type: \"drop\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n items,\n dropOperation: this.dropOperation,\n },\n item?.target ?? null,\n );\n }\n\n this.end();\n announce(this.stringFormatter.format(\"dropComplete\"));\n }\n\n activate(dropTarget: DropTarget | null, dropItem: DroppableItem | null | undefined): void {\n if (dropTarget && typeof dropTarget.onDropActivate === \"function\") {\n let target = dropItem?.target ?? null;\n let rect = dropTarget.element.getBoundingClientRect();\n dropTarget.onDropActivate(\n {\n type: \"dropactivate\",\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n },\n target,\n );\n }\n }\n}\n\nfunction findValidDropTargets(options: DragTarget): DropTarget[] {\n let types = getTypes(options.items);\n return [...dropTargets.values()].filter((target) => {\n if (target.element.closest('[aria-hidden=\"true\"], [inert]')) {\n return false;\n }\n\n if (typeof target.getDropOperation === \"function\") {\n return target.getDropOperation(types, options.allowedDropOperations) !== \"cancel\";\n }\n\n return true;\n });\n}\n\nexport type { DragTarget, DropTarget, DroppableItem, DragSession };\n"],"mappings":";;;;;;;;AAiBA,MAAa,oBAAiC,IAAI,IAAI;CAAC;CAAc;CAAiB;AAAW,CAAC;AAGlG,MAAa,mBAAmB;AAGhC,MAAa,eAAe;AAG5B,IAAY,iBAAL,yBAAA,gBAAA;CACL,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,YAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,UAAA,KAAA;CACA,eAAA,eAAA,SAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAGA,MAAa,yBAAiD;CAC5D,MAAA;CACA,MAAA;CACA,UAAU;CACV,UAAU;CACV,MAAA;CACA,UAAU;CACV,MAAA;CACA,KAAA;CACA,eAAA;AACF;AAGA,MAAa,iBAAyC;MAC7B;MACA;MACA;EACtB,IAA4C;MACtB;EACtB,IAA4C;EAC5C,IAA4C;MACvB;AACxB;AAGA,MAAa,gCAA+D;CAC1E,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR;AAGA,MAAa,gCAA+D;CAC1E,QAAQ;CACR,MAAM;CACN,MAAM;CACN,MAAM;AACR;;;;;;;AAQA,SAAS,YAAY,UAAiC;CACpD,IAAI,CAAC,UACH,WAAW;CAGb,IAAI,aAAa,WACf,WAAW;CAGb,IACE,aAAa,aACb,OAAO,WAAW,eAClB,OAAO,OAAO,eAAe,cAC7B,OAAO,WAAW,mBAAmB,CAAC,CAAC,SAEvC,WAAW;CAGb,OA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AQ,sBAAsB;GAChE,KAAK,kBAAkB,OACrB;IACE,MAAM;IACN,GAAG,KAAK,OAAO,KAAK,QAAQ;IAC5B,GAAG,KAAK,MAAM,KAAK,SAAS;IAC5B;IACA,eAAe,KAAK;GACtB,GACA,MAAM,UAAU,IAClB;EACF;EAEA,KAAK,IAAI;EACT,SAAS,KAAK,gBAAgB,OAAO,cAAc,CAAC;CACtD;CAEA,SAAS,YAA+B,UAAkD;EACxF,IAAI,cAAc,OAAO,WAAW,mBAAmB,YAAY;GACjE,IAAI,SAAS,UAAU,UAAU;GACjC,IAAI,OAAO,WAAW,QAAQ,sBAAsB;GACpD,WAAW,eACT;IACE,MAAM;IACN,GAAG,KAAK,OAAO,KAAK,QAAQ;IAC5B,GAAG,KAAK,MAAM,KAAK,SAAS;GAC9B,GACA,MACF;EACF;CACF;AACF;AAEA,SAAS,qBAAqB,SAAmC;CAC/D,IAAI,QAAQ,SAAS,QAAQ,KAAK;CAClC,OAAO,CAAC,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,QAAQ,WAAW;EAClD,IAAI,OAAO,QAAQ,QAAQ,iCAA+B,GACxD,OAAO;EAGT,IAAI,OAAO,OAAO,qBAAqB,YACrC,OAAO,OAAO,iBAAiB,OAAO,QAAQ,qBAAqB,MAAM;EAG3E,OAAO;CACT,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actiongroup.js","names":["mergeProps"],"sources":["../../src/actiongroup/createActionGroup.ts"],"sourcesContent":["import { onCleanup, type JSX, type Accessor } from \"solid-js\";\nimport { createButton } from \"../button\";\nimport {\n filterDOMProps,\n getEventTarget,\n mergeProps,\n nodeContains,\n isFocusable,\n focusSafely,\n} from \"../utils\";\nimport { useLocale } from \"../i18n\";\nimport type { Orientation } from \"../toolbar\";\nimport type { Key, ListState } from \"@proyecto-viviana/solid-stately\";\n\nexport interface AriaActionGroupProps<T = unknown> {\n /** List items (optional, parity with React Aria prop shape). */\n items?: T[];\n /** Whether the whole action group is disabled. */\n isDisabled?: boolean;\n /** Group orientation. */\n orientation?: Orientation;\n /** Accessible label. */\n \"aria-label\"?: string;\n /** Labelled-by id. */\n \"aria-labelledby\"?: string;\n /** Handler called when an item action is triggered. */\n onAction?: (key: Key) => void;\n}\n\nexport interface ActionGroupAria {\n actionGroupProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\nexport interface AriaActionGroupItemProps {\n key: Key;\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\ninterface ActionGroupData {\n onAction?: (key: Key) => void;\n}\n\nconst actionGroupData = new WeakMap<object, ActionGroupData>();\n\nconst GROUP_ROLE_BY_MODE = {\n none: \"toolbar\",\n single: \"radiogroup\",\n multiple: \"toolbar\",\n} as const;\n\nconst ITEM_ROLE_BY_MODE = {\n none: undefined,\n single: \"radio\",\n multiple: \"checkbox\",\n} as const;\n\nfunction isActionGroupDisabled<T>(props: AriaActionGroupProps<T>, state: ListState<T>): boolean {\n if (props.isDisabled) return true;\n const keys = [...state.collection().getKeys()];\n if (keys.length === 0) return true;\n return !keys.some((key) => !state.isDisabled(key));\n}\n\nexport function createActionGroup<T>(\n props: AriaActionGroupProps<T>,\n state: ListState<T>,\n _ref?: Accessor<HTMLElement | null>,\n): ActionGroupAria {\n const locale = useLocale();\n let groupRef: HTMLElement | undefined;\n const applyRoleAttributes = (): void => {\n if (!groupRef) return;\n const selectionMode = state.selectionMode();\n const mappedRole = GROUP_ROLE_BY_MODE[selectionMode];\n const nestedToolbar = Boolean(groupRef.parentElement?.closest('[role=\"toolbar\"]'));\n const role = mappedRole === \"toolbar\" && nestedToolbar ? \"group\" : mappedRole;\n groupRef.setAttribute(\"role\", role);\n if (mappedRole === \"toolbar\" && !nestedToolbar) {\n groupRef.setAttribute(\"aria-orientation\", props.orientation ?? \"horizontal\");\n } else {\n groupRef.removeAttribute(\"aria-orientation\");\n }\n };\n\n const getFocusableItems = (root: HTMLElement): HTMLElement[] => {\n const out: HTMLElement[] = [];\n const pushIfFocusable = (el: Element | null | undefined): void => {\n if (!el || !(el instanceof HTMLElement)) return;\n if (isFocusable(el) && el.getAttribute(\"aria-disabled\") !== \"true\") {\n out.push(el);\n }\n };\n\n pushIfFocusable(root);\n for (const node of root.querySelectorAll(\"*\")) {\n pushIfFocusable(node);\n }\n return out;\n };\n\n const focusRelative = (\n root: HTMLElement,\n direction: \"next\" | \"previous\",\n ): HTMLElement | null => {\n const focusables = getFocusableItems(root);\n if (focusables.length === 0) return null;\n\n const active = root.ownerDocument.activeElement as HTMLElement | null;\n const currentIndex = active ? focusables.indexOf(active) : -1;\n const delta = direction === \"next\" ? 1 : -1;\n const nextIndex =\n currentIndex === -1\n ? direction === \"next\"\n ? 0\n : focusables.length - 1\n : (currentIndex + delta + focusables.length) % focusables.length;\n const next = focusables[nextIndex];\n focusSafely(next);\n return next;\n };\n\n // Mirrors react-aria `useActionGroup.onKeyDown` (3.50.0): only the four arrows\n // are handled and they are ORIENTATION-AGNOSTIC — ArrowRight/ArrowDown always\n // move next, ArrowLeft/ArrowUp always move previous (orientation only drives\n // `aria-orientation`). `flipDirection` swaps ArrowRight/ArrowLeft under RTL for\n // horizontal groups. No Home/End (they fall through to the browser). Focus\n // moves via `focusRelative` → `focusSafely` → the item's own `onFocus`, which\n // sets the focused key — so there is no selection-follows-focus here.\n const onKeyDown: JSX.EventHandler<HTMLElement, KeyboardEvent> = (e) => {\n const root = groupRef;\n if (!root || isActionGroupDisabled(props, state)) return;\n if (!nodeContains(e.currentTarget, getEventTarget(e))) return;\n\n const orientation = props.orientation ?? \"horizontal\";\n const flipDirection = locale().direction === \"rtl\" && orientation === \"horizontal\";\n\n switch (e.key) {\n case \"ArrowRight\":\n case \"ArrowDown\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowRight\" && flipDirection) {\n focusRelative(root, \"previous\");\n } else {\n focusRelative(root, \"next\");\n }\n return;\n }\n case \"ArrowLeft\":\n case \"ArrowUp\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowLeft\" && flipDirection) {\n focusRelative(root, \"next\");\n } else {\n focusRelative(root, \"previous\");\n }\n return;\n }\n }\n };\n\n const actionGroupProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(\n filterDOMProps(props as Record<string, unknown>, { labelable: true }),\n {\n ref: (el: HTMLElement) => {\n groupRef = el;\n applyRoleAttributes();\n queueMicrotask(() => {\n if (!groupRef) return;\n applyRoleAttributes();\n });\n },\n onKeyDown,\n get \"aria-label\"() {\n return props[\"aria-label\"];\n },\n get \"aria-labelledby\"() {\n return props[\"aria-label\"] ? undefined : props[\"aria-labelledby\"];\n },\n get \"aria-disabled\"() {\n return isActionGroupDisabled(props, state) || undefined;\n },\n },\n );\n\n actionGroupData.set(state, {\n get onAction() {\n return props.onAction;\n },\n });\n\n onCleanup(() => {\n actionGroupData.delete(state);\n });\n\n return { actionGroupProps };\n}\n\nexport function createActionGroupItem<T>(\n props: AriaActionGroupItemProps,\n state: ListState<T>,\n): ActionGroupItemAria {\n const button = createButton({\n elementType: \"button\",\n isDisabled: state.isDisabled(props.key),\n onPress: () => {\n state.setFocusedKey(props.key);\n actionGroupData.get(state)?.onAction?.(props.key);\n if (state.selectionMode() !== \"none\") {\n state.select(props.key);\n }\n },\n });\n\n const isFocused = () => props.key === state.focusedKey();\n\n onCleanup(() => {\n if (isFocused()) {\n state.setFocusedKey(null);\n }\n });\n\n const buttonProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(button.buttonProps, {\n get role() {\n return ITEM_ROLE_BY_MODE[state.selectionMode()];\n },\n get \"aria-checked\"() {\n const mode = state.selectionMode();\n if (mode === \"none\") return undefined;\n return state.isSelected(props.key);\n },\n // Mirrors react-aria `useActionGroupItem` (3.50.0): every enabled item is\n // tabbable until focus engages the group, then the roving stop follows the\n // focused key. There is NO single default tab stop and NO selection bias —\n // disabled items are made non-tabbable by their native `disabled` attribute\n // (via createButton), not by this getter.\n get tabIndex() {\n return isFocused() || state.focusedKey() == null ? 0 : -1;\n },\n \"data-key\": String(props.key),\n onFocus: () => {\n state.setFocusedKey(props.key);\n },\n });\n\n return { buttonProps };\n}\n"],"mappings":";;;;;;;AA6CA,MAAM,kCAAkB,IAAI,QAAiC;AAE7D,MAAM,qBAAqB;CACzB,MAAM;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,MAAM,oBAAoB;CACxB,MAAM,KAAA;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,SAAS,sBAAyB,OAAgC,OAA8B;CAC9F,IAAI,MAAM,YAAY,OAAO;CAC7B,MAAM,OAAO,CAAC,GAAG,MAAM,WAAW,CAAC,CAAC,QAAQ,CAAC;CAC7C,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,CAAC,KAAK,MAAM,QAAQ,CAAC,MAAM,WAAW,GAAG,CAAC;AACnD;AAEA,SAAgB,kBACd,OACA,OACA,MACiB;CACjB,MAAM,SAAS,UAAU;CACzB,IAAI;CACJ,MAAM,4BAAkC;EACtC,IAAI,CAAC,UAAU;EAEf,MAAM,aAAa,mBADG,MAAM,cACsB;EAClD,MAAM,gBAAgB,QAAQ,SAAS,eAAe,QAAQ,oBAAkB,CAAC;EACjF,MAAM,OAAO,eAAe,aAAa,gBAAgB,UAAU;EACnE,SAAS,aAAa,QAAQ,IAAI;EAClC,IAAI,eAAe,aAAa,CAAC,eAC/B,SAAS,aAAa,oBAAoB,MAAM,eAAe,YAAY;OAE3E,SAAS,gBAAgB,kBAAkB;CAE/C;CAEA,MAAM,qBAAqB,SAAqC;EAC9D,MAAM,MAAqB,CAAC;EAC5B,MAAM,mBAAmB,OAAyC;GAChE,IAAI,CAAC,MAAM,EAAE,cAAc,cAAc;GACzC,IAAI,YAAY,EAAE,KAAK,GAAG,aAAa,eAAe,MAAM,QAC1D,IAAI,KAAK,EAAE;EAEf;EAEA,gBAAgB,IAAI;EACpB,KAAK,MAAM,QAAQ,KAAK,iBAAiB,GAAG,GAC1C,gBAAg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AM;EACjD;EACA,IAAI,kBAAkB;GACpB,OAAO,sBAAsB,OAAO,KAAK,KAAK,KAAA;EAChD;CACF,CACF;CAEA,gBAAgB,IAAI,OAAO,EACzB,IAAI,WAAW;EACb,OAAO,MAAM;CACf,EACF,CAAC;CAED,gBAAgB;EACd,gBAAgB,OAAO,KAAK;CAC9B,CAAC;CAED,OAAO,EAAE,iBAAiB;AAC5B;AAEA,SAAgB,sBACd,OACA,OACqB;CACrB,MAAM,SAAS,aAAa;EAC1B,aAAa;EACb,YAAY,MAAM,WAAW,MAAM,GAAG;EACtC,eAAe;GACb,MAAM,cAAc,MAAM,GAAG;GAC7B,gBAAgB,IAAI,KAAK,CAAC,EAAE,WAAW,MAAM,GAAG;GAChD,IAAI,MAAM,cAAc,MAAM,QAC5B,MAAM,OAAO,MAAM,GAAG;EAE1B;CACF,CAAC;CAED,MAAM,kBAAkB,MAAM,QAAQ,MAAM,WAAW;CAEvD,gBAAgB;EACd,IAAI,UAAU,GACZ,MAAM,cAAc,IAAI;CAE5B,CAAC;CAyBD,OAAO,EAAE,aAvB4CA,aAAW,OAAO,aAAa;EAClF,IAAI,OAAO;GACT,OAAO,kBAAkB,MAAM,cAAc;EAC/C;EACA,IAAI,iBAAiB;GAEnB,IADa,MAAM,cACZ,MAAM,QAAQ,OAAO,KAAA;GAC5B,OAAO,MAAM,WAAW,MAAM,GAAG;EACnC;EAMA,IAAI,WAAW;GACb,OAAO,UAAU,KAAK,MAAM,WAAW,KAAK,OAAO,IAAI;EACzD;EACA,YAAY,OAAO,MAAM,GAAG;EAC5B,eAAe;GACb,MAAM,cAAc,MAAM,GAAG;EAC/B;CACF,CAEmB,EAAE;AACvB"}
|
|
1
|
+
{"version":3,"file":"actiongroup.js","names":["mergeProps"],"sources":["../../src/actiongroup/createActionGroup.ts"],"sourcesContent":["import { onCleanup, type JSX, type Accessor } from \"solid-js\";\nimport { createButton } from \"../button\";\nimport {\n filterDOMProps,\n getEventTarget,\n mergeProps,\n nodeContains,\n isFocusable,\n focusSafely,\n} from \"../utils\";\nimport { useLocale } from \"../i18n\";\nimport type { Orientation } from \"../toolbar\";\nimport type { Key, ListState } from \"@proyecto-viviana/solid-stately\";\n\nexport interface AriaActionGroupProps<T = unknown> {\n /** List items (optional, parity with React Aria prop shape). */\n items?: T[];\n /** Whether the whole action group is disabled. */\n isDisabled?: boolean;\n /** Group orientation. */\n orientation?: Orientation;\n /** Accessible label. */\n \"aria-label\"?: string;\n /** Labelled-by id. */\n \"aria-labelledby\"?: string;\n /** Handler called when an item action is triggered. */\n onAction?: (key: Key) => void;\n}\n\nexport interface ActionGroupAria {\n actionGroupProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\nexport interface AriaActionGroupItemProps {\n key: Key;\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\ninterface ActionGroupData {\n onAction?: (key: Key) => void;\n}\n\nconst actionGroupData = new WeakMap<object, ActionGroupData>();\n\nconst GROUP_ROLE_BY_MODE = {\n none: \"toolbar\",\n single: \"radiogroup\",\n multiple: \"toolbar\",\n} as const;\n\nconst ITEM_ROLE_BY_MODE = {\n none: undefined,\n single: \"radio\",\n multiple: \"checkbox\",\n} as const;\n\nfunction isActionGroupDisabled<T>(props: AriaActionGroupProps<T>, state: ListState<T>): boolean {\n if (props.isDisabled) return true;\n const keys = [...state.collection().getKeys()];\n if (keys.length === 0) return true;\n return !keys.some((key) => !state.isDisabled(key));\n}\n\nexport function createActionGroup<T>(\n props: AriaActionGroupProps<T>,\n state: ListState<T>,\n _ref?: Accessor<HTMLElement | null>,\n): ActionGroupAria {\n const locale = useLocale();\n let groupRef: HTMLElement | undefined;\n const applyRoleAttributes = (): void => {\n if (!groupRef) return;\n const selectionMode = state.selectionMode();\n const mappedRole = GROUP_ROLE_BY_MODE[selectionMode];\n const nestedToolbar = Boolean(groupRef.parentElement?.closest('[role=\"toolbar\"]'));\n const role = mappedRole === \"toolbar\" && nestedToolbar ? \"group\" : mappedRole;\n groupRef.setAttribute(\"role\", role);\n if (mappedRole === \"toolbar\" && !nestedToolbar) {\n groupRef.setAttribute(\"aria-orientation\", props.orientation ?? \"horizontal\");\n } else {\n groupRef.removeAttribute(\"aria-orientation\");\n }\n };\n\n const getFocusableItems = (root: HTMLElement): HTMLElement[] => {\n const out: HTMLElement[] = [];\n const pushIfFocusable = (el: Element | null | undefined): void => {\n if (!el || !(el instanceof HTMLElement)) return;\n if (isFocusable(el) && el.getAttribute(\"aria-disabled\") !== \"true\") {\n out.push(el);\n }\n };\n\n pushIfFocusable(root);\n for (const node of root.querySelectorAll(\"*\")) {\n pushIfFocusable(node);\n }\n return out;\n };\n\n const focusRelative = (root: HTMLElement, direction: \"next\" | \"previous\"): HTMLElement | null => {\n const focusables = getFocusableItems(root);\n if (focusables.length === 0) return null;\n\n const active = root.ownerDocument.activeElement as HTMLElement | null;\n const currentIndex = active ? focusables.indexOf(active) : -1;\n const delta = direction === \"next\" ? 1 : -1;\n const nextIndex =\n currentIndex === -1\n ? direction === \"next\"\n ? 0\n : focusables.length - 1\n : (currentIndex + delta + focusables.length) % focusables.length;\n const next = focusables[nextIndex];\n focusSafely(next);\n return next;\n };\n\n // Mirrors react-aria `useActionGroup.onKeyDown` (3.50.0): only the four arrows\n // are handled and they are ORIENTATION-AGNOSTIC — ArrowRight/ArrowDown always\n // move next, ArrowLeft/ArrowUp always move previous (orientation only drives\n // `aria-orientation`). `flipDirection` swaps ArrowRight/ArrowLeft under RTL for\n // horizontal groups. No Home/End (they fall through to the browser). Focus\n // moves via `focusRelative` → `focusSafely` → the item's own `onFocus`, which\n // sets the focused key — so there is no selection-follows-focus here.\n const onKeyDown: JSX.EventHandler<HTMLElement, KeyboardEvent> = (e) => {\n const root = groupRef;\n if (!root || isActionGroupDisabled(props, state)) return;\n if (!nodeContains(e.currentTarget, getEventTarget(e))) return;\n\n const orientation = props.orientation ?? \"horizontal\";\n const flipDirection = locale().direction === \"rtl\" && orientation === \"horizontal\";\n\n switch (e.key) {\n case \"ArrowRight\":\n case \"ArrowDown\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowRight\" && flipDirection) {\n focusRelative(root, \"previous\");\n } else {\n focusRelative(root, \"next\");\n }\n return;\n }\n case \"ArrowLeft\":\n case \"ArrowUp\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowLeft\" && flipDirection) {\n focusRelative(root, \"next\");\n } else {\n focusRelative(root, \"previous\");\n }\n return;\n }\n }\n };\n\n const actionGroupProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(\n filterDOMProps(props as Record<string, unknown>, { labelable: true }),\n {\n ref: (el: HTMLElement) => {\n groupRef = el;\n applyRoleAttributes();\n queueMicrotask(() => {\n if (!groupRef) return;\n applyRoleAttributes();\n });\n },\n onKeyDown,\n get \"aria-label\"() {\n return props[\"aria-label\"];\n },\n get \"aria-labelledby\"() {\n return props[\"aria-label\"] ? undefined : props[\"aria-labelledby\"];\n },\n get \"aria-disabled\"() {\n return isActionGroupDisabled(props, state) || undefined;\n },\n },\n );\n\n actionGroupData.set(state, {\n get onAction() {\n return props.onAction;\n },\n });\n\n onCleanup(() => {\n actionGroupData.delete(state);\n });\n\n return { actionGroupProps };\n}\n\nexport function createActionGroupItem<T>(\n props: AriaActionGroupItemProps,\n state: ListState<T>,\n): ActionGroupItemAria {\n const button = createButton({\n elementType: \"button\",\n isDisabled: state.isDisabled(props.key),\n onPress: () => {\n state.setFocusedKey(props.key);\n actionGroupData.get(state)?.onAction?.(props.key);\n if (state.selectionMode() !== \"none\") {\n state.select(props.key);\n }\n },\n });\n\n const isFocused = () => props.key === state.focusedKey();\n\n onCleanup(() => {\n if (isFocused()) {\n state.setFocusedKey(null);\n }\n });\n\n const buttonProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(button.buttonProps, {\n get role() {\n return ITEM_ROLE_BY_MODE[state.selectionMode()];\n },\n get \"aria-checked\"() {\n const mode = state.selectionMode();\n if (mode === \"none\") return undefined;\n return state.isSelected(props.key);\n },\n // Mirrors react-aria `useActionGroupItem` (3.50.0): every enabled item is\n // tabbable until focus engages the group, then the roving stop follows the\n // focused key. There is NO single default tab stop and NO selection bias —\n // disabled items are made non-tabbable by their native `disabled` attribute\n // (via createButton), not by this getter.\n get tabIndex() {\n return isFocused() || state.focusedKey() == null ? 0 : -1;\n },\n \"data-key\": String(props.key),\n onFocus: () => {\n state.setFocusedKey(props.key);\n },\n });\n\n return { buttonProps };\n}\n"],"mappings":";;;;;;;AA6CA,MAAM,kCAAkB,IAAI,QAAiC;AAE7D,MAAM,qBAAqB;CACzB,MAAM;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,MAAM,oBAAoB;CACxB,MAAM,KAAA;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,SAAS,sBAAyB,OAAgC,OAA8B;CAC9F,IAAI,MAAM,YAAY,OAAO;CAC7B,MAAM,OAAO,CAAC,GAAG,MAAM,WAAW,CAAC,CAAC,QAAQ,CAAC;CAC7C,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,CAAC,KAAK,MAAM,QAAQ,CAAC,MAAM,WAAW,GAAG,CAAC;AACnD;AAEA,SAAgB,kBACd,OACA,OACA,MACiB;CACjB,MAAM,SAAS,UAAU;CACzB,IAAI;CACJ,MAAM,4BAAkC;EACtC,IAAI,CAAC,UAAU;EAEf,MAAM,aAAa,mBADG,MAAM,cACsB;EAClD,MAAM,gBAAgB,QAAQ,SAAS,eAAe,QAAQ,oBAAkB,CAAC;EACjF,MAAM,OAAO,eAAe,aAAa,gBAAgB,UAAU;EACnE,SAAS,aAAa,QAAQ,IAAI;EAClC,IAAI,eAAe,aAAa,CAAC,eAC/B,SAAS,aAAa,oBAAoB,MAAM,eAAe,YAAY;OAE3E,SAAS,gBAAgB,kBAAkB;CAE/C;CAEA,MAAM,qBAAqB,SAAqC;EAC9D,MAAM,MAAqB,CAAC;EAC5B,MAAM,mBAAmB,OAAyC;GAChE,IAAI,CAAC,MAAM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|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actiongroup.jsx","names":["mergeProps"],"sources":["../../src/actiongroup/createActionGroup.ts"],"sourcesContent":["import { onCleanup, type JSX, type Accessor } from \"solid-js\";\nimport { createButton } from \"../button\";\nimport {\n filterDOMProps,\n getEventTarget,\n mergeProps,\n nodeContains,\n isFocusable,\n focusSafely,\n} from \"../utils\";\nimport { useLocale } from \"../i18n\";\nimport type { Orientation } from \"../toolbar\";\nimport type { Key, ListState } from \"@proyecto-viviana/solid-stately\";\n\nexport interface AriaActionGroupProps<T = unknown> {\n /** List items (optional, parity with React Aria prop shape). */\n items?: T[];\n /** Whether the whole action group is disabled. */\n isDisabled?: boolean;\n /** Group orientation. */\n orientation?: Orientation;\n /** Accessible label. */\n \"aria-label\"?: string;\n /** Labelled-by id. */\n \"aria-labelledby\"?: string;\n /** Handler called when an item action is triggered. */\n onAction?: (key: Key) => void;\n}\n\nexport interface ActionGroupAria {\n actionGroupProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\nexport interface AriaActionGroupItemProps {\n key: Key;\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\ninterface ActionGroupData {\n onAction?: (key: Key) => void;\n}\n\nconst actionGroupData = new WeakMap<object, ActionGroupData>();\n\nconst GROUP_ROLE_BY_MODE = {\n none: \"toolbar\",\n single: \"radiogroup\",\n multiple: \"toolbar\",\n} as const;\n\nconst ITEM_ROLE_BY_MODE = {\n none: undefined,\n single: \"radio\",\n multiple: \"checkbox\",\n} as const;\n\nfunction isActionGroupDisabled<T>(props: AriaActionGroupProps<T>, state: ListState<T>): boolean {\n if (props.isDisabled) return true;\n const keys = [...state.collection().getKeys()];\n if (keys.length === 0) return true;\n return !keys.some((key) => !state.isDisabled(key));\n}\n\nexport function createActionGroup<T>(\n props: AriaActionGroupProps<T>,\n state: ListState<T>,\n _ref?: Accessor<HTMLElement | null>,\n): ActionGroupAria {\n const locale = useLocale();\n let groupRef: HTMLElement | undefined;\n const applyRoleAttributes = (): void => {\n if (!groupRef) return;\n const selectionMode = state.selectionMode();\n const mappedRole = GROUP_ROLE_BY_MODE[selectionMode];\n const nestedToolbar = Boolean(groupRef.parentElement?.closest('[role=\"toolbar\"]'));\n const role = mappedRole === \"toolbar\" && nestedToolbar ? \"group\" : mappedRole;\n groupRef.setAttribute(\"role\", role);\n if (mappedRole === \"toolbar\" && !nestedToolbar) {\n groupRef.setAttribute(\"aria-orientation\", props.orientation ?? \"horizontal\");\n } else {\n groupRef.removeAttribute(\"aria-orientation\");\n }\n };\n\n const getFocusableItems = (root: HTMLElement): HTMLElement[] => {\n const out: HTMLElement[] = [];\n const pushIfFocusable = (el: Element | null | undefined): void => {\n if (!el || !(el instanceof HTMLElement)) return;\n if (isFocusable(el) && el.getAttribute(\"aria-disabled\") !== \"true\") {\n out.push(el);\n }\n };\n\n pushIfFocusable(root);\n for (const node of root.querySelectorAll(\"*\")) {\n pushIfFocusable(node);\n }\n return out;\n };\n\n const focusRelative = (\n root: HTMLElement,\n direction: \"next\" | \"previous\",\n ): HTMLElement | null => {\n const focusables = getFocusableItems(root);\n if (focusables.length === 0) return null;\n\n const active = root.ownerDocument.activeElement as HTMLElement | null;\n const currentIndex = active ? focusables.indexOf(active) : -1;\n const delta = direction === \"next\" ? 1 : -1;\n const nextIndex =\n currentIndex === -1\n ? direction === \"next\"\n ? 0\n : focusables.length - 1\n : (currentIndex + delta + focusables.length) % focusables.length;\n const next = focusables[nextIndex];\n focusSafely(next);\n return next;\n };\n\n // Mirrors react-aria `useActionGroup.onKeyDown` (3.50.0): only the four arrows\n // are handled and they are ORIENTATION-AGNOSTIC — ArrowRight/ArrowDown always\n // move next, ArrowLeft/ArrowUp always move previous (orientation only drives\n // `aria-orientation`). `flipDirection` swaps ArrowRight/ArrowLeft under RTL for\n // horizontal groups. No Home/End (they fall through to the browser). Focus\n // moves via `focusRelative` → `focusSafely` → the item's own `onFocus`, which\n // sets the focused key — so there is no selection-follows-focus here.\n const onKeyDown: JSX.EventHandler<HTMLElement, KeyboardEvent> = (e) => {\n const root = groupRef;\n if (!root || isActionGroupDisabled(props, state)) return;\n if (!nodeContains(e.currentTarget, getEventTarget(e))) return;\n\n const orientation = props.orientation ?? \"horizontal\";\n const flipDirection = locale().direction === \"rtl\" && orientation === \"horizontal\";\n\n switch (e.key) {\n case \"ArrowRight\":\n case \"ArrowDown\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowRight\" && flipDirection) {\n focusRelative(root, \"previous\");\n } else {\n focusRelative(root, \"next\");\n }\n return;\n }\n case \"ArrowLeft\":\n case \"ArrowUp\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowLeft\" && flipDirection) {\n focusRelative(root, \"next\");\n } else {\n focusRelative(root, \"previous\");\n }\n return;\n }\n }\n };\n\n const actionGroupProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(\n filterDOMProps(props as Record<string, unknown>, { labelable: true }),\n {\n ref: (el: HTMLElement) => {\n groupRef = el;\n applyRoleAttributes();\n queueMicrotask(() => {\n if (!groupRef) return;\n applyRoleAttributes();\n });\n },\n onKeyDown,\n get \"aria-label\"() {\n return props[\"aria-label\"];\n },\n get \"aria-labelledby\"() {\n return props[\"aria-label\"] ? undefined : props[\"aria-labelledby\"];\n },\n get \"aria-disabled\"() {\n return isActionGroupDisabled(props, state) || undefined;\n },\n },\n );\n\n actionGroupData.set(state, {\n get onAction() {\n return props.onAction;\n },\n });\n\n onCleanup(() => {\n actionGroupData.delete(state);\n });\n\n return { actionGroupProps };\n}\n\nexport function createActionGroupItem<T>(\n props: AriaActionGroupItemProps,\n state: ListState<T>,\n): ActionGroupItemAria {\n const button = createButton({\n elementType: \"button\",\n isDisabled: state.isDisabled(props.key),\n onPress: () => {\n state.setFocusedKey(props.key);\n actionGroupData.get(state)?.onAction?.(props.key);\n if (state.selectionMode() !== \"none\") {\n state.select(props.key);\n }\n },\n });\n\n const isFocused = () => props.key === state.focusedKey();\n\n onCleanup(() => {\n if (isFocused()) {\n state.setFocusedKey(null);\n }\n });\n\n const buttonProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(button.buttonProps, {\n get role() {\n return ITEM_ROLE_BY_MODE[state.selectionMode()];\n },\n get \"aria-checked\"() {\n const mode = state.selectionMode();\n if (mode === \"none\") return undefined;\n return state.isSelected(props.key);\n },\n // Mirrors react-aria `useActionGroupItem` (3.50.0): every enabled item is\n // tabbable until focus engages the group, then the roving stop follows the\n // focused key. There is NO single default tab stop and NO selection bias —\n // disabled items are made non-tabbable by their native `disabled` attribute\n // (via createButton), not by this getter.\n get tabIndex() {\n return isFocused() || state.focusedKey() == null ? 0 : -1;\n },\n \"data-key\": String(props.key),\n onFocus: () => {\n state.setFocusedKey(props.key);\n },\n });\n\n return { buttonProps };\n}\n"],"mappings":";;;;;;;AA6CA,MAAM,kCAAkB,IAAI,QAAiC;AAE7D,MAAM,qBAAqB;CACzB,MAAM;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,MAAM,oBAAoB;CACxB,MAAM,KAAA;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,SAAS,sBAAyB,OAAgC,OAA8B;CAC9F,IAAI,MAAM,YAAY,OAAO;CAC7B,MAAM,OAAO,CAAC,GAAG,MAAM,WAAW,CAAC,CAAC,QAAQ,CAAC;CAC7C,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,CAAC,KAAK,MAAM,QAAQ,CAAC,MAAM,WAAW,GAAG,CAAC;AACnD;AAEA,SAAgB,kBACd,OACA,OACA,MACiB;CACjB,MAAM,SAAS,UAAU;CACzB,IAAI;CACJ,MAAM,4BAAkC;EACtC,IAAI,CAAC,UAAU;EAEf,MAAM,aAAa,mBADG,MAAM,cACsB;EAClD,MAAM,gBAAgB,QAAQ,SAAS,eAAe,QAAQ,oBAAkB,CAAC;EACjF,MAAM,OAAO,eAAe,aAAa,gBAAgB,UAAU;EACnE,SAAS,aAAa,QAAQ,IA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AAO,MAAM,WAAW,MAAM,GAAG;EACnC;EAMA,IAAI,WAAW;GACb,OAAO,UAAU,KAAK,MAAM,WAAW,KAAK,OAAO,IAAI;EACzD;EACA,YAAY,OAAO,MAAM,GAAG;EAC5B,eAAe;GACb,MAAM,cAAc,MAAM,GAAG;EAC/B;CACF,CAEmB,EAAE;AACvB"}
|
|
1
|
+
{"version":3,"file":"actiongroup.jsx","names":["mergeProps"],"sources":["../../src/actiongroup/createActionGroup.ts"],"sourcesContent":["import { onCleanup, type JSX, type Accessor } from \"solid-js\";\nimport { createButton } from \"../button\";\nimport {\n filterDOMProps,\n getEventTarget,\n mergeProps,\n nodeContains,\n isFocusable,\n focusSafely,\n} from \"../utils\";\nimport { useLocale } from \"../i18n\";\nimport type { Orientation } from \"../toolbar\";\nimport type { Key, ListState } from \"@proyecto-viviana/solid-stately\";\n\nexport interface AriaActionGroupProps<T = unknown> {\n /** List items (optional, parity with React Aria prop shape). */\n items?: T[];\n /** Whether the whole action group is disabled. */\n isDisabled?: boolean;\n /** Group orientation. */\n orientation?: Orientation;\n /** Accessible label. */\n \"aria-label\"?: string;\n /** Labelled-by id. */\n \"aria-labelledby\"?: string;\n /** Handler called when an item action is triggered. */\n onAction?: (key: Key) => void;\n}\n\nexport interface ActionGroupAria {\n actionGroupProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\nexport interface AriaActionGroupItemProps {\n key: Key;\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: JSX.HTMLAttributes<HTMLElement>;\n}\n\ninterface ActionGroupData {\n onAction?: (key: Key) => void;\n}\n\nconst actionGroupData = new WeakMap<object, ActionGroupData>();\n\nconst GROUP_ROLE_BY_MODE = {\n none: \"toolbar\",\n single: \"radiogroup\",\n multiple: \"toolbar\",\n} as const;\n\nconst ITEM_ROLE_BY_MODE = {\n none: undefined,\n single: \"radio\",\n multiple: \"checkbox\",\n} as const;\n\nfunction isActionGroupDisabled<T>(props: AriaActionGroupProps<T>, state: ListState<T>): boolean {\n if (props.isDisabled) return true;\n const keys = [...state.collection().getKeys()];\n if (keys.length === 0) return true;\n return !keys.some((key) => !state.isDisabled(key));\n}\n\nexport function createActionGroup<T>(\n props: AriaActionGroupProps<T>,\n state: ListState<T>,\n _ref?: Accessor<HTMLElement | null>,\n): ActionGroupAria {\n const locale = useLocale();\n let groupRef: HTMLElement | undefined;\n const applyRoleAttributes = (): void => {\n if (!groupRef) return;\n const selectionMode = state.selectionMode();\n const mappedRole = GROUP_ROLE_BY_MODE[selectionMode];\n const nestedToolbar = Boolean(groupRef.parentElement?.closest('[role=\"toolbar\"]'));\n const role = mappedRole === \"toolbar\" && nestedToolbar ? \"group\" : mappedRole;\n groupRef.setAttribute(\"role\", role);\n if (mappedRole === \"toolbar\" && !nestedToolbar) {\n groupRef.setAttribute(\"aria-orientation\", props.orientation ?? \"horizontal\");\n } else {\n groupRef.removeAttribute(\"aria-orientation\");\n }\n };\n\n const getFocusableItems = (root: HTMLElement): HTMLElement[] => {\n const out: HTMLElement[] = [];\n const pushIfFocusable = (el: Element | null | undefined): void => {\n if (!el || !(el instanceof HTMLElement)) return;\n if (isFocusable(el) && el.getAttribute(\"aria-disabled\") !== \"true\") {\n out.push(el);\n }\n };\n\n pushIfFocusable(root);\n for (const node of root.querySelectorAll(\"*\")) {\n pushIfFocusable(node);\n }\n return out;\n };\n\n const focusRelative = (root: HTMLElement, direction: \"next\" | \"previous\"): HTMLElement | null => {\n const focusables = getFocusableItems(root);\n if (focusables.length === 0) return null;\n\n const active = root.ownerDocument.activeElement as HTMLElement | null;\n const currentIndex = active ? focusables.indexOf(active) : -1;\n const delta = direction === \"next\" ? 1 : -1;\n const nextIndex =\n currentIndex === -1\n ? direction === \"next\"\n ? 0\n : focusables.length - 1\n : (currentIndex + delta + focusables.length) % focusables.length;\n const next = focusables[nextIndex];\n focusSafely(next);\n return next;\n };\n\n // Mirrors react-aria `useActionGroup.onKeyDown` (3.50.0): only the four arrows\n // are handled and they are ORIENTATION-AGNOSTIC — ArrowRight/ArrowDown always\n // move next, ArrowLeft/ArrowUp always move previous (orientation only drives\n // `aria-orientation`). `flipDirection` swaps ArrowRight/ArrowLeft under RTL for\n // horizontal groups. No Home/End (they fall through to the browser). Focus\n // moves via `focusRelative` → `focusSafely` → the item's own `onFocus`, which\n // sets the focused key — so there is no selection-follows-focus here.\n const onKeyDown: JSX.EventHandler<HTMLElement, KeyboardEvent> = (e) => {\n const root = groupRef;\n if (!root || isActionGroupDisabled(props, state)) return;\n if (!nodeContains(e.currentTarget, getEventTarget(e))) return;\n\n const orientation = props.orientation ?? \"horizontal\";\n const flipDirection = locale().direction === \"rtl\" && orientation === \"horizontal\";\n\n switch (e.key) {\n case \"ArrowRight\":\n case \"ArrowDown\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowRight\" && flipDirection) {\n focusRelative(root, \"previous\");\n } else {\n focusRelative(root, \"next\");\n }\n return;\n }\n case \"ArrowLeft\":\n case \"ArrowUp\": {\n e.preventDefault();\n e.stopPropagation();\n if (e.key === \"ArrowLeft\" && flipDirection) {\n focusRelative(root, \"next\");\n } else {\n focusRelative(root, \"previous\");\n }\n return;\n }\n }\n };\n\n const actionGroupProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(\n filterDOMProps(props as Record<string, unknown>, { labelable: true }),\n {\n ref: (el: HTMLElement) => {\n groupRef = el;\n applyRoleAttributes();\n queueMicrotask(() => {\n if (!groupRef) return;\n applyRoleAttributes();\n });\n },\n onKeyDown,\n get \"aria-label\"() {\n return props[\"aria-label\"];\n },\n get \"aria-labelledby\"() {\n return props[\"aria-label\"] ? undefined : props[\"aria-labelledby\"];\n },\n get \"aria-disabled\"() {\n return isActionGroupDisabled(props, state) || undefined;\n },\n },\n );\n\n actionGroupData.set(state, {\n get onAction() {\n return props.onAction;\n },\n });\n\n onCleanup(() => {\n actionGroupData.delete(state);\n });\n\n return { actionGroupProps };\n}\n\nexport function createActionGroupItem<T>(\n props: AriaActionGroupItemProps,\n state: ListState<T>,\n): ActionGroupItemAria {\n const button = createButton({\n elementType: \"button\",\n isDisabled: state.isDisabled(props.key),\n onPress: () => {\n state.setFocusedKey(props.key);\n actionGroupData.get(state)?.onAction?.(props.key);\n if (state.selectionMode() !== \"none\") {\n state.select(props.key);\n }\n },\n });\n\n const isFocused = () => props.key === state.focusedKey();\n\n onCleanup(() => {\n if (isFocused()) {\n state.setFocusedKey(null);\n }\n });\n\n const buttonProps: JSX.HTMLAttributes<HTMLElement> = mergeProps(button.buttonProps, {\n get role() {\n return ITEM_ROLE_BY_MODE[state.selectionMode()];\n },\n get \"aria-checked\"() {\n const mode = state.selectionMode();\n if (mode === \"none\") return undefined;\n return state.isSelected(props.key);\n },\n // Mirrors react-aria `useActionGroupItem` (3.50.0): every enabled item is\n // tabbable until focus engages the group, then the roving stop follows the\n // focused key. There is NO single default tab stop and NO selection bias —\n // disabled items are made non-tabbable by their native `disabled` attribute\n // (via createButton), not by this getter.\n get tabIndex() {\n return isFocused() || state.focusedKey() == null ? 0 : -1;\n },\n \"data-key\": String(props.key),\n onFocus: () => {\n state.setFocusedKey(props.key);\n },\n });\n\n return { buttonProps };\n}\n"],"mappings":";;;;;;;AA6CA,MAAM,kCAAkB,IAAI,QAAiC;AAE7D,MAAM,qBAAqB;CACzB,MAAM;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,MAAM,oBAAoB;CACxB,MAAM,KAAA;CACN,QAAQ;CACR,UAAU;AACZ;AAEA,SAAS,sBAAyB,OAAgC,OAA8B;CAC9F,IAAI,MAAM,YAAY,OAAO;CAC7B,MAAM,OAAO,CAAC,GAAG,MAAM,WAAW,CAAC,CAAC,QAAQ,CAAC;CAC7C,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,CAAC,KAAK,MAAM,QAAQ,CAAC,MAAM,WAAW,GAAG,CAAC;AACnD;AAEA,SAAgB,kBACd,OACA,OACA,MACiB;CACjB,MAAM,SAAS,UAAU;CACzB,IAAI;CACJ,MAAM,4BAAkC;EACtC,I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