@solid2-aria/core 0.0.1 → 0.1.0

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.
Files changed (141) hide show
  1. package/README.md +14 -0
  2. package/dist/NOTICE.txt +33 -11
  3. package/dist/browser/actiongroup/create-action-group.js +2 -1
  4. package/dist/browser/actiongroup/create-action-group.js.map +1 -1
  5. package/dist/browser/combobox/create-combo-box.js +2 -2
  6. package/dist/browser/combobox/create-combo-box.js.map +1 -1
  7. package/dist/browser/dnd/drag-preview.js +7 -8
  8. package/dist/browser/dnd/drag-preview.js.map +1 -1
  9. package/dist/browser/focus/focus-scope.js +2 -2
  10. package/dist/browser/focus/focus-scope.js.map +1 -1
  11. package/dist/browser/focus/virtual-focus.d.ts +1 -0
  12. package/dist/browser/focus/virtual-focus.js +20 -5
  13. package/dist/browser/focus/virtual-focus.js.map +1 -1
  14. package/dist/browser/grid/create-grid-cell.js +4 -4
  15. package/dist/browser/grid/create-grid-cell.js.map +1 -1
  16. package/dist/browser/gridlist/create-grid-list-item.js +3 -3
  17. package/dist/browser/gridlist/create-grid-list-item.js.map +1 -1
  18. package/dist/browser/interactions/create-hover.js +6 -3
  19. package/dist/browser/interactions/create-hover.js.map +1 -1
  20. package/dist/browser/interactions/create-press.js +5 -4
  21. package/dist/browser/interactions/create-press.js.map +1 -1
  22. package/dist/browser/interactions/utils.js +4 -3
  23. package/dist/browser/interactions/utils.js.map +1 -1
  24. package/dist/browser/landmark/create-landmark.js +2 -2
  25. package/dist/browser/landmark/create-landmark.js.map +1 -1
  26. package/dist/browser/overlays/aria-hide-outside.js +5 -3
  27. package/dist/browser/overlays/aria-hide-outside.js.map +1 -1
  28. package/dist/browser/overlays/calculate-position.js +3 -3
  29. package/dist/browser/overlays/calculate-position.js.map +1 -1
  30. package/dist/browser/overlays/create-modal.js +15 -18
  31. package/dist/browser/overlays/create-modal.js.map +1 -1
  32. package/dist/browser/overlays/create-prevent-scroll.js +3 -3
  33. package/dist/browser/overlays/create-prevent-scroll.js.map +1 -1
  34. package/dist/browser/overlays/overlay.js +7 -8
  35. package/dist/browser/overlays/overlay.js.map +1 -1
  36. package/dist/browser/select/create-select.js +1 -1
  37. package/dist/browser/select/create-select.js.map +1 -1
  38. package/dist/browser/select/hidden-select.js +61 -64
  39. package/dist/browser/select/hidden-select.js.map +1 -1
  40. package/dist/browser/selection/create-selectable-item.js +2 -2
  41. package/dist/browser/selection/create-selectable-item.js.map +1 -1
  42. package/dist/browser/selection/create-type-select.js +11 -3
  43. package/dist/browser/selection/create-type-select.js.map +1 -1
  44. package/dist/browser/selection/list-keyboard-delegate.js +1 -1
  45. package/dist/browser/selection/list-keyboard-delegate.js.map +1 -1
  46. package/dist/browser/tokenfield/create-token-field.js +3 -3
  47. package/dist/browser/tokenfield/create-token-field.js.map +1 -1
  48. package/dist/browser/tokenfield/create-token.js +2 -1
  49. package/dist/browser/tokenfield/create-token.js.map +1 -1
  50. package/dist/browser/toolbar/create-toolbar.js +2 -2
  51. package/dist/browser/toolbar/create-toolbar.js.map +1 -1
  52. package/dist/browser/utils/dom-helpers.d.ts +2 -15
  53. package/dist/browser/utils/dom-helpers.js +1 -28
  54. package/dist/browser/utils/dom-helpers.js.map +1 -1
  55. package/dist/browser/utils/dom-value.js +2 -1
  56. package/dist/browser/utils/dom-value.js.map +1 -1
  57. package/dist/browser/utils/get-scroll-parent.js +3 -2
  58. package/dist/browser/utils/get-scroll-parent.js.map +1 -1
  59. package/dist/browser/utils/get-scroll-parents.js +2 -1
  60. package/dist/browser/utils/get-scroll-parents.js.map +1 -1
  61. package/dist/browser/utils/is-element-visible.js +3 -1
  62. package/dist/browser/utils/is-element-visible.js.map +1 -1
  63. package/dist/browser/utils/is-focusable.js +2 -1
  64. package/dist/browser/utils/is-focusable.js.map +1 -1
  65. package/dist/browser/utils/shadowdom/dom-functions.d.ts +8 -0
  66. package/dist/browser/utils/shadowdom/dom-functions.js +26 -7
  67. package/dist/browser/utils/shadowdom/dom-functions.js.map +1 -1
  68. package/dist/browser/utils/shadowdom/shadow-tree-walker.js +1 -1
  69. package/dist/browser/utils/shadowdom/shadow-tree-walker.js.map +1 -1
  70. package/dist/browser/utils/type-helpers.d.ts +42 -0
  71. package/dist/browser/utils/type-helpers.js +55 -0
  72. package/dist/browser/utils/type-helpers.js.map +1 -0
  73. package/dist/server/actiongroup/create-action-group.js +2 -1
  74. package/dist/server/actiongroup/create-action-group.js.map +1 -1
  75. package/dist/server/combobox/create-combo-box.js +2 -2
  76. package/dist/server/combobox/create-combo-box.js.map +1 -1
  77. package/dist/server/dnd/drag-preview.js +9 -12
  78. package/dist/server/dnd/drag-preview.js.map +1 -1
  79. package/dist/server/focus/focus-scope.js +2 -2
  80. package/dist/server/focus/focus-scope.js.map +1 -1
  81. package/dist/server/focus/virtual-focus.js +20 -5
  82. package/dist/server/focus/virtual-focus.js.map +1 -1
  83. package/dist/server/grid/create-grid-cell.js +4 -4
  84. package/dist/server/grid/create-grid-cell.js.map +1 -1
  85. package/dist/server/gridlist/create-grid-list-item.js +3 -3
  86. package/dist/server/gridlist/create-grid-list-item.js.map +1 -1
  87. package/dist/server/interactions/create-hover.js +6 -3
  88. package/dist/server/interactions/create-hover.js.map +1 -1
  89. package/dist/server/interactions/create-press.js +5 -4
  90. package/dist/server/interactions/create-press.js.map +1 -1
  91. package/dist/server/interactions/utils.js +4 -3
  92. package/dist/server/interactions/utils.js.map +1 -1
  93. package/dist/server/landmark/create-landmark.js +2 -2
  94. package/dist/server/landmark/create-landmark.js.map +1 -1
  95. package/dist/server/overlays/aria-hide-outside.js +5 -3
  96. package/dist/server/overlays/aria-hide-outside.js.map +1 -1
  97. package/dist/server/overlays/calculate-position.js +3 -3
  98. package/dist/server/overlays/calculate-position.js.map +1 -1
  99. package/dist/server/overlays/create-modal.js +7 -27
  100. package/dist/server/overlays/create-modal.js.map +1 -1
  101. package/dist/server/overlays/create-prevent-scroll.js +3 -3
  102. package/dist/server/overlays/create-prevent-scroll.js.map +1 -1
  103. package/dist/server/overlays/overlay.js +8 -18
  104. package/dist/server/overlays/overlay.js.map +1 -1
  105. package/dist/server/select/create-select.js +1 -1
  106. package/dist/server/select/create-select.js.map +1 -1
  107. package/dist/server/select/hidden-select.js +85 -138
  108. package/dist/server/select/hidden-select.js.map +1 -1
  109. package/dist/server/selection/create-selectable-item.js +2 -2
  110. package/dist/server/selection/create-selectable-item.js.map +1 -1
  111. package/dist/server/selection/create-type-select.js +11 -3
  112. package/dist/server/selection/create-type-select.js.map +1 -1
  113. package/dist/server/selection/list-keyboard-delegate.js +1 -1
  114. package/dist/server/selection/list-keyboard-delegate.js.map +1 -1
  115. package/dist/server/tokenfield/create-token-field.js +3 -3
  116. package/dist/server/tokenfield/create-token-field.js.map +1 -1
  117. package/dist/server/tokenfield/create-token.js +2 -1
  118. package/dist/server/tokenfield/create-token.js.map +1 -1
  119. package/dist/server/toolbar/create-toolbar.js +2 -2
  120. package/dist/server/toolbar/create-toolbar.js.map +1 -1
  121. package/dist/server/utils/dom-helpers.js +1 -28
  122. package/dist/server/utils/dom-helpers.js.map +1 -1
  123. package/dist/server/utils/dom-value.js +2 -1
  124. package/dist/server/utils/dom-value.js.map +1 -1
  125. package/dist/server/utils/get-scroll-parent.js +3 -2
  126. package/dist/server/utils/get-scroll-parent.js.map +1 -1
  127. package/dist/server/utils/get-scroll-parents.js +2 -1
  128. package/dist/server/utils/get-scroll-parents.js.map +1 -1
  129. package/dist/server/utils/is-element-visible.js +3 -1
  130. package/dist/server/utils/is-element-visible.js.map +1 -1
  131. package/dist/server/utils/is-focusable.js +2 -1
  132. package/dist/server/utils/is-focusable.js.map +1 -1
  133. package/dist/server/utils/shadowdom/dom-functions.js +26 -7
  134. package/dist/server/utils/shadowdom/dom-functions.js.map +1 -1
  135. package/dist/server/utils/shadowdom/shadow-tree-walker.js +1 -1
  136. package/dist/server/utils/shadowdom/shadow-tree-walker.js.map +1 -1
  137. package/dist/server/utils/type-helpers.js +55 -0
  138. package/dist/server/utils/type-helpers.js.map +1 -0
  139. package/dist/server/virtualizer/scroll-view.js +3 -1
  140. package/dist/server/virtualizer/scroll-view.js.map +1 -1
  141. package/package.json +16 -10
@@ -1 +1 @@
1
- {"version":3,"file":"focus-scope.js","names":["<FocusContext value={value}>{props.children}</FocusContext>","ref={(element) => {\n setStartRef(element);\n }}","{content()}","ref={(element) => {\n setEndRef(element);\n }}","resolveChildren","_$createComponent","_$getNextElement","_$memo"],"sources":["../../../src/focus/focus-scope.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/focus/FocusScope.tsx.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; resolve scoped children once under their focus context for rendering and focus tracking.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport {\n createMemo,\n untrack,\n children as resolveChildren,\n createContext,\n onSettled,\n useContext,\n createEffect,\n createSignal,\n} from \"solid-js\";\nimport type { Accessor, Element as SolidElement } from \"solid-js\";\n\nimport { getInteractionModality } from \"../interactions/create-focus-visible\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport type { JSX } from \"../types\";\nimport { getOwnerDocument, getOwnerWindow } from \"../utils/dom-helpers\";\nimport {\n focusableElementOrNull,\n requireElement,\n requireFocusableElement,\n requireHTMLInputElement,\n} from \"../utils/dom-value\";\nimport { isFocusable, isTabbable } from \"../utils/is-focusable\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isAndroid, isChrome } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n getActiveElement,\n getEventTarget,\n nodeContains,\n} from \"../utils/shadowdom/dom-functions\";\nimport type { ShadowTreeWalker } from \"../utils/shadowdom/shadow-tree-walker\";\nimport { createShadowTreeWalker } from \"../utils/shadowdom/shadow-tree-walker\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\n\nclass Tree {\n root: TreeNode;\n private readonly fastMap = new Map<ScopeRef, TreeNode>();\n constructor() {\n this.root = new TreeNode({ scopeRef: null });\n this.fastMap.set(null, this.root);\n }\n get size(): number {\n return this.fastMap.size;\n }\n getTreeNode(data: ScopeRef): TreeNode | undefined {\n return this.fastMap.get(data);\n }\n addTreeNode(\n scopeRef: ScopeRef,\n parent: ScopeRef,\n nodeToRestore?: FocusableElement\n ): void {\n const parentNode = this.fastMap.get(parent ?? null);\n\n if (!parentNode) {\n return;\n }\n\n const node = new TreeNode({ scopeRef });\n parentNode.addChild(node);\n node.parent = parentNode;\n this.fastMap.set(scopeRef, node);\n\n if (nodeToRestore) {\n node.nodeToRestore = nodeToRestore;\n }\n }\n addNode(node: TreeNode): void {\n this.fastMap.set(node.scopeRef, node);\n }\n removeTreeNode(scopeRef: ScopeRef): void {\n // never remove the root\n if (scopeRef === null) {\n return;\n }\n\n const node = this.fastMap.get(scopeRef);\n\n if (!node) {\n return;\n }\n\n const parentNode = node.parent;\n\n // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing\n // if we are, then replace the siblings restore with the restore from the scope we're removing\n for (const current of this.traverse()) {\n if (\n current !== node &&\n node.nodeToRestore &&\n current.nodeToRestore &&\n node.scopeRef &&\n node.scopeRef() &&\n isElementInScope(current.nodeToRestore, node.scopeRef())\n ) {\n current.nodeToRestore = node.nodeToRestore;\n }\n }\n\n const { children } = node;\n\n if (parentNode) {\n // oxlint-disable-next-line unicorn/prefer-dom-node-remove -- Collection and focus-tree nodes implement their own parent/child protocol.\n parentNode.removeChild(node);\n\n if (children.size > 0) {\n for (const child of children) {\n whenTruthy(parentNode, (truthyValue0) => {\n truthyValue0.addChild(child);\n });\n }\n }\n }\n\n this.fastMap.delete(node.scopeRef);\n }\n // Pre Order Depth First\n *traverse(node: TreeNode = this.root): Generator<TreeNode> {\n if (isPresent(node.scopeRef)) {\n yield node;\n }\n\n if (node.children.size > 0) {\n for (const child of node.children) {\n yield* this.traverse(child);\n }\n }\n }\n clone(): Tree {\n const newTree = new Tree();\n\n for (const node of this.traverse()) {\n newTree.addTreeNode(\n node.scopeRef,\n node.parent?.scopeRef ?? null,\n node.nodeToRestore\n );\n }\n\n return newTree;\n }\n}\n\nclass TreeNode {\n public scopeRef: ScopeRef;\n public nodeToRestore?: FocusableElement;\n public parent?: TreeNode;\n public children = new Set<TreeNode>();\n public contain = false;\n constructor(props: { scopeRef: ScopeRef }) {\n this.scopeRef = untrack(() => props.scopeRef);\n }\n addChild(node: TreeNode): void {\n this.children.add(node);\n node.parent = this;\n }\n removeChild(node: TreeNode): void {\n this.children.delete(node);\n node.parent = undefined;\n }\n}\n\nexport const focusScopeTree: Tree = new Tree();\n\nexport interface FocusScopeProps {\n /** The contents of the focus scope. */\n children: SolidElement;\n /**\n * Whether to contain focus inside the scope, so users cannot\n * move focus outside, for example in a modal dialog.\n */\n contain?: boolean;\n /**\n * Whether to restore focus back to the element that was focused\n * when the focus scope mounted, after the focus scope unmounts.\n */\n restoreFocus?: boolean;\n /** Whether to auto focus the first focusable element in the focus scope on mount. */\n autoFocus?: boolean;\n}\n\nexport interface FocusManagerOptions {\n /** The element to start searching from. The currently focused element by default. */\n from?: Element;\n /** Whether to only include tabbable elements, or all focusable elements. */\n tabbable?: boolean;\n /** Whether focus should wrap around when it reaches the end of the scope. */\n wrap?: boolean;\n /** A callback that determines whether the given element is focused. */\n accept?: (node: Element) => boolean;\n}\n\nexport interface FocusManager {\n /** Moves focus to the next focusable or tabbable element in the focus scope. */\n focusNext: (opts?: FocusManagerOptions) => FocusableElement | null;\n /** Moves focus to the previous focusable or tabbable element in the focus scope. */\n focusPrevious: (opts?: FocusManagerOptions) => FocusableElement | null;\n /** Moves focus to the first focusable or tabbable element in the focus scope. */\n focusFirst: (opts?: FocusManagerOptions) => FocusableElement | null;\n /** Moves focus to the last focusable or tabbable element in the focus scope. */\n focusLast: (opts?: FocusManagerOptions) => FocusableElement | null;\n}\n\ntype ScopeRef = Accessor<Element[] | null> | null;\n\ninterface IFocusContext {\n focusManager: FocusManager;\n parentNode: TreeNode | null;\n}\n\nconst FocusContext = createContext<IFocusContext | null>(null);\nconst RESTORE_FOCUS_EVENT = \"react-aria-focus-scope-restore\";\nlet activeScope: ScopeRef = null;\n\n/**\n * A FocusScope manages focus for its descendants. It supports containing focus inside\n * the scope, restoring focus to the previously focused element on unmount, and auto\n * focusing children on mount. It also acts as a container for a programmatic focus\n * management interface that can be used to move focus forward and back in response\n * to user events.\n */\nconst stopPropagation = (event: Event) => {\n event.stopPropagation();\n};\n\nexport function FocusScope(props: FocusScopeProps): JSX.Element {\n const [startRef, setStartRef] = createSignal<HTMLSpanElement | null>(null, {\n ownedWrite: true,\n });\n\n const [endRef, setEndRef] = createSignal<HTMLSpanElement | null>(null, {\n ownedWrite: true,\n });\n\n const [scopeRef, setScopeRef] = createSignal<Element[]>([], {\n ownedWrite: true,\n });\n\n const parentNode = useContext(FocusContext)?.parentNode;\n const node = new TreeNode({ scopeRef });\n const focusManager = createFocusManagerForScope(scopeRef);\n const value = { focusManager, parentNode: node };\n\n const content = resolveChildren(() => (\n <FocusContext value={value}>{props.children}</FocusContext>\n ));\n\n onSettled(() => {\n let parent = getTruthyValue(parentNode) ?? focusScopeTree.root;\n\n if (\n focusScopeTree.getTreeNode(parent.scopeRef) &&\n activeScope &&\n !isAncestorScope(activeScope, parent.scopeRef)\n ) {\n parent = focusScopeTree.getTreeNode(activeScope) ?? parent;\n }\n\n parent.addChild(node);\n focusScopeTree.addNode(node);\n\n return () => {\n const parentScope =\n focusScopeTree.getTreeNode(scopeRef)?.parent?.scopeRef ?? null;\n\n if (\n (scopeRef === activeScope || isAncestorScope(scopeRef, activeScope)) &&\n (!parentScope || focusScopeTree.getTreeNode(parentScope))\n ) {\n activeScope = parentScope;\n }\n\n focusScopeTree.removeTreeNode(scopeRef);\n };\n });\n createEffect(\n () => props.contain,\n (contain) => {\n node.contain = isTruthy(contain);\n },\n { ssrSource: \"client\" }\n );\n\n createEffect(\n () => ({ content: content(), end: endRef(), start: startRef() }),\n ({ start, end }): undefined | (() => void) => {\n if (!start || !end) {\n return undefined;\n }\n\n let element = start.nextSibling;\n const nodes: Element[] = [];\n\n while (element && element !== end) {\n if (element instanceof Element) {\n nodes.push(element);\n element.addEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n }\n\n element = element.nextSibling;\n }\n\n setScopeRef(nodes);\n\n return () => {\n for (const elementValue of nodes) {\n elementValue.removeEventListener(\n RESTORE_FOCUS_EVENT,\n stopPropagation\n );\n }\n };\n },\n { ssrSource: \"client\" }\n );\n createActiveScopeTracker(\n scopeRef,\n () => props.restoreFocus,\n () => props.contain\n );\n createFocusContainment(scopeRef, () => props.contain);\n createRestoreFocus(\n scopeRef,\n () => props.restoreFocus,\n () => props.contain\n );\n createAutoFocus(scopeRef, () => props.autoFocus);\n createEffect(\n scopeRef,\n (scopeNodes) => {\n const activeElement = getActiveElement(getOwnerDocument(scopeNodes[0]));\n\n if (isElementInScope(activeElement, scopeNodes)) {\n let scope: TreeNode | null = null;\n\n for (const child of focusScopeTree.traverse()) {\n if (\n child.scopeRef &&\n isElementInScope(activeElement, untrack(child.scopeRef))\n ) {\n scope = child;\n }\n }\n\n if (scope && scope === focusScopeTree.getTreeNode(scopeRef)) {\n activeScope = scope.scopeRef;\n }\n }\n },\n { ssrSource: \"client\" }\n );\n\n return (\n <>\n <span\n data-focus-scope-start\n hidden\n ref={(element) => {\n setStartRef(element);\n }}\n />\n {content()}\n <span\n data-focus-scope-end\n hidden\n ref={(element) => {\n setEndRef(element);\n }}\n />\n </>\n );\n}\n\n/**\n * Returns a FocusManager interface for the parent FocusScope.\n * A FocusManager can be used to programmatically move focus within\n * a FocusScope, e.g. in response to user events like keyboard navigation.\n */\nexport function createFocusScopeManager(): FocusManager | undefined {\n return useContext(FocusContext)?.focusManager;\n}\n\nfunction createFocusManagerForScope(\n scopeRef: Accessor<Element[] | null>\n): FocusManager {\n return {\n focusFirst(opts = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { tabbable, accept } = opts;\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = requireValue(\n requireValue(scope[0], \"Expected a present traversal value\")\n .previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n const nextNode = focusableElementOrNull(walker.nextNode());\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusLast(opts = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { tabbable, accept } = opts;\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = requireValue(\n requireValue(scope.at(-1), \"Expected a present traversal value\")\n .nextElementSibling,\n \"Expected scope.at(-1)!.nextElementSibling\"\n );\n const previousNode = focusableElementOrNull(walker.previousNode());\n\n if (isTruthy(previousNode)) {\n focusElement(previousNode, true);\n }\n\n return previousNode;\n },\n focusNext(opts: FocusManagerOptions = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { from, tabbable, wrap, accept } = opts;\n\n const node =\n getTruthyValue(from) ??\n requireValue(\n getActiveElement(getOwnerDocument(scope[0] ?? undefined)),\n \"Expected getActiveElement(getOwnerDocument(scope[0]! ?? undefined))\"\n );\n\n const sentinel = requireValue(\n requireValue(scope[0], \"Expected a present traversal value\")\n .previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let nextNode = focusableElementOrNull(walker.nextNode());\n\n if (!isTruthy(nextNode) && isTruthy(wrap)) {\n walker.currentNode = sentinel;\n nextNode = focusableElementOrNull(walker.nextNode());\n }\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { from, tabbable, wrap, accept } = opts;\n\n const node =\n getTruthyValue(from) ??\n requireValue(\n getActiveElement(getOwnerDocument(scope[0] ?? undefined)),\n \"Expected getActiveElement(getOwnerDocument(scope[0]! ?? undefined))\"\n );\n\n const sentinel = requireValue(\n requireValue(scope.at(-1), \"Expected a present traversal value\")\n .nextElementSibling,\n \"Expected scope[scope.length - 1]!.nextElementSibling\"\n );\n\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let previousNode = focusableElementOrNull(walker.previousNode());\n\n if (!isTruthy(previousNode) && isTruthy(wrap)) {\n walker.currentNode = sentinel;\n previousNode = focusableElementOrNull(walker.previousNode());\n }\n\n if (isTruthy(previousNode)) {\n focusElement(previousNode, true);\n }\n\n return previousNode;\n },\n };\n}\n\nfunction getScopeRoot(scope: Element[]) {\n return requireValue(\n requireValue(scope[0], \"Expected a present traversal value\").parentElement,\n \"Expected scope[0]!.parentElement\"\n );\n}\n\nfunction shouldContainFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.contain) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return true;\n}\n\nfunction getRadiosInGroup(element: HTMLInputElement): HTMLInputElement[] {\n if (!element.form) {\n // Radio buttons outside a form - query the document\n return [\n ...getOwnerDocument(element).querySelectorAll<HTMLInputElement>(\n `input[type=\"radio\"][name=\"${CSS.escape(element.name)}\"]`\n ),\n ].filter((radio) => !radio.form);\n }\n\n // namedItem returns RadioNodeList (iterable) for 2+ elements, but a single Element for exactly 1.\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormControlsCollection/namedItem\n const radioList = element.form.elements.namedItem(element.name);\n const ownerWindow = getOwnerWindow(element);\n\n if (radioList instanceof ownerWindow.RadioNodeList) {\n return [...radioList].filter(\n (el): el is HTMLInputElement => el instanceof ownerWindow.HTMLInputElement\n );\n }\n\n if (radioList instanceof ownerWindow.HTMLInputElement) {\n return [radioList];\n }\n\n return [];\n}\n\nfunction isTabbableRadio(element: HTMLInputElement): boolean {\n if (element.checked) {\n return true;\n }\n\n const radios = getRadiosInGroup(element);\n\n return radios.length > 0 && !radios.some((radio) => radio.checked);\n}\n\nfunction createFocusContainment(\n scopeRef: Accessor<Element[] | null>,\n contain: () => boolean | undefined\n) {\n let focusedNode: FocusableElement | undefined;\n\n let raf: ReturnType<typeof requestAnimationFrame> | undefined;\n\n createEffect(\n () => ({ contain: contain(), scope: scopeRef() }),\n ({ scope, contain: shouldContain }): undefined | (() => void) => {\n if (scope === null || scope.length === 0) {\n return undefined;\n }\n\n if (!isTruthy(shouldContain)) {\n // if contain() was changed, then we should cancel any ongoing waits to pull focus back into containment\n if (raf !== undefined) {\n cancelAnimationFrame(raf);\n raf = undefined;\n }\n\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(\n requireValue(scope[0], \"Expected first scope element\")\n );\n\n // Handle the Tab key to contain() focus within the scope\n const onKeyDown = (e: KeyboardEvent) => {\n if (!isRestoreFocusTab(e, scopeRef)) {\n return;\n }\n\n const focusedElement = getActiveElement(ownerDocument);\n const scopeValue = scopeRef();\n\n if (!scopeValue || !isElementInScope(focusedElement, scopeValue)) {\n return;\n }\n\n const scopeRoot = getScopeRoot(scopeValue);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { tabbable: true },\n scopeValue\n );\n\n if (!focusedElement) {\n return;\n }\n\n walker.currentNode = focusedElement;\n\n let nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n\n if (!isTruthy(nextElement)) {\n walker.currentNode = e.shiftKey\n ? requireValue(\n requireValue(\n scopeValue.at(-1),\n \"Expected a present traversal value\"\n ).nextElementSibling,\n \"Expected scope.at(-1)!.nextElementSibling\"\n )\n : requireValue(\n requireValue(\n scopeValue[0],\n \"Expected a present traversal value\"\n ).previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n }\n\n e.preventDefault();\n\n if (isTruthy(nextElement)) {\n focusElement(nextElement, true);\n\n if (\n nextElement instanceof getOwnerWindow(nextElement).HTMLInputElement\n ) {\n nextElement.select();\n }\n }\n };\n\n const onFocus: EventListener = (e) => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if (\n (!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(requireElement(getEventTarget(e)), scope)\n ) {\n activeScope = scopeRef;\n focusedNode = requireFocusableElement(getEventTarget(e));\n } else if (\n shouldContainFocus(scopeRef) &&\n !isElementInChildScope(requireElement(getEventTarget(e)), scopeRef)\n ) {\n // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),\n // restore focus to the previously focused node or the first tabbable element in the active scope.\n if (focusedNode) {\n focusElement(focusedNode);\n } else {\n const activeNodes = activeScope?.();\n\n if (activeNodes) {\n focusFirstInScope(activeNodes);\n }\n }\n } else if (shouldContainFocus(scopeRef)) {\n focusedNode = requireFocusableElement(getEventTarget(e));\n }\n };\n\n const onBlur: EventListener = (e) => {\n // Firefox doesn't shift focus back to the Dialog properly without this\n if (raf !== undefined) {\n cancelAnimationFrame(raf);\n }\n\n raf = requestAnimationFrame(() => {\n // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor\n // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.\n // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.\n const modality = getInteractionModality();\n\n const shouldSkipFocusRestore =\n (modality === \"virtual\" || modality === null) &&\n isAndroid() &&\n isChrome();\n\n // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe\n const activeElement = getActiveElement(ownerDocument);\n\n if (\n !shouldSkipFocusRestore &&\n activeElement &&\n shouldContainFocus(scopeRef) &&\n !isElementInChildScope(activeElement, scopeRef)\n ) {\n activeScope = scopeRef;\n const target = requireFocusableElement(getEventTarget(e));\n\n if (isTruthy(target) && target.isConnected) {\n focusedNode = target;\n focusElement(focusedNode);\n } else {\n const activeNodes = activeScope();\n\n if (activeNodes) {\n focusFirstInScope(activeNodes);\n }\n }\n }\n });\n };\n\n ownerDocument.addEventListener(\"keydown\", onKeyDown, false);\n ownerDocument.addEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusin\", onFocus, false);\n }\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusout\", onBlur, false);\n }\n\n return () => {\n ownerDocument.removeEventListener(\"keydown\", onKeyDown, false);\n ownerDocument.removeEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusin\", onFocus, false);\n }\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusout\", onBlur, false);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n onSettled(() => () => {\n if (raf !== undefined) {\n cancelAnimationFrame(raf);\n }\n });\n}\n\nfunction isElementInAnyScope(element: Element) {\n return isElementInChildScope(element);\n}\n\nfunction isElementInScope(element?: Element | null, scope?: Element[] | null) {\n if (!element) {\n return false;\n }\n\n if (!scope) {\n return false;\n }\n\n return scope.some((node) => nodeContains(node, element));\n}\n\nfunction isElementInChildScope(element: Element, scope: ScopeRef = null) {\n // If the element is within a top layer element (e.g. toasts), always allow moving focus there.\n if (\n element instanceof Element &&\n element.closest(\"[data-react-aria-top-layer]\")\n ) {\n return true;\n }\n\n // node.contains in isElementInScope covers child scopes that are also DOM children,\n // but does not cover child scopes in portals.\n for (const { scopeRef: s } of focusScopeTree.traverse(\n focusScopeTree.getTreeNode(scope)\n )) {\n if (s && isElementInScope(element, untrack(s))) {\n return true;\n }\n }\n\n return false;\n}\n\n/** @private */\nexport function isElementInChildOfActiveScope(element: Element): boolean {\n return isElementInChildScope(element, activeScope);\n}\n\nfunction isAncestorScope(ancestor: ScopeRef, scope: ScopeRef) {\n let parent = focusScopeTree.getTreeNode(scope)?.parent;\n\n while (parent) {\n if (parent.scopeRef === ancestor) {\n return true;\n }\n\n ({ parent } = parent);\n }\n\n return false;\n}\n\nfunction focusElement(element: FocusableElement | null, scroll = false) {\n if (isPresent(element) && !scroll) {\n try {\n focusSafely(element);\n } catch {\n // ignore\n }\n } else if (isPresent(element)) {\n try {\n element.focus();\n } catch {\n // ignore\n }\n }\n}\n\nfunction getFirstInScope(\n scope: Element[],\n tabbable = true\n): FocusableElement | null {\n const sentinel = requireValue(\n requireValue(scope[0], \"Expected a present traversal value\")\n .previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, { tabbable }, scope);\n walker.currentNode = sentinel;\n let nextNode = walker.nextNode();\n\n // If the scope does not contain a tabbable element, use the first focusable element.\n if (tabbable && !nextNode) {\n scopeRoot = getScopeRoot(scope);\n walker = getFocusableTreeWalker(scopeRoot, { tabbable: false }, scope);\n walker.currentNode = sentinel;\n nextNode = walker.nextNode();\n }\n\n // TreeWalker.nextNode() returns null when the scope contains no focusable element.\n return focusableElementOrNull(nextNode);\n}\n\nfunction focusFirstInScope(scope: Element[], tabbable = true) {\n focusElement(getFirstInScope(scope, tabbable));\n}\n\nfunction createAutoFocus(\n scopeRef: Accessor<Element[] | null>,\n autoFocus: () => boolean | undefined\n) {\n let pendingAutoFocus = untrack(autoFocus);\n createEffect(\n scopeRef,\n (scope) => {\n if (!isTruthy(pendingAutoFocus) || scope === null || scope.length === 0) {\n return;\n }\n\n pendingAutoFocus = false;\n activeScope = scopeRef;\n const ownerDocument = getOwnerDocument(scope[0]);\n\n if (!isElementInScope(getActiveElement(ownerDocument), scope)) {\n focusFirstInScope(scope);\n }\n },\n { ssrSource: \"client\" }\n );\n}\n\nfunction createActiveScopeTracker(\n scopeRef: Accessor<Element[] | null>,\n restore: () => boolean | undefined,\n contain: () => boolean | undefined\n) {\n // Track active scopes that do not contain or restore focus.\n createEffect(\n () => ({ contain: contain(), restore: restore(), scope: scopeRef() }),\n ({\n scope,\n restore: shouldRestore,\n contain: shouldContain,\n }): undefined | (() => void) => {\n if (\n scope === null ||\n scope.length === 0 ||\n isTruthy(shouldRestore) ||\n isTruthy(shouldContain)\n ) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(\n requireValue(scope[0], \"Expected first scope element\")\n );\n\n const onFocus = (e: Event) => {\n const target = requireElement(getEventTarget(e));\n\n if (isElementInScope(target, scope)) {\n activeScope = scopeRef;\n } else if (!isElementInAnyScope(target)) {\n activeScope = null;\n }\n };\n\n ownerDocument.addEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusin\", onFocus, false);\n }\n\n return () => {\n ownerDocument.removeEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusin\", onFocus, false);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\nfunction shouldRestoreFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.nodeToRestore) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return scope?.scopeRef === scopeRef;\n}\n\nfunction createRestoreFocus(\n scopeRef: Accessor<Element[] | null>,\n restoreFocus: () => boolean | undefined,\n contain: () => boolean | undefined\n) {\n // Capture focus before scoped children can autofocus.\n const initialFocusTarget = untrack(() =>\n typeof document === \"undefined\"\n ? null\n : focusableElementOrNull(\n getActiveElement(getOwnerDocument(scopeRef()?.[0]))\n )\n );\n\n const scopeReady = createMemo(() => (scopeRef()?.length ?? 0) > 0);\n\n // restoring scopes should all track if they are active regardless of contain(), but contain() already tracks it plus logic to contain() the focus\n // restoring-non-containing scopes should only care if they become active so they can perform the restore\n createEffect(\n () => ({ contain: contain(), restore: restoreFocus(), scope: scopeRef() }),\n ({\n scope,\n restore: shouldRestore,\n contain: shouldContain,\n }): undefined | (() => void) => {\n if (scope === null || scope.length === 0) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(\n requireValue(scope[0], \"Expected first scope element\")\n );\n\n if (!isTruthy(shouldRestore) || isTruthy(shouldContain)) {\n return undefined;\n }\n\n const onFocus = () => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if (\n (!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(getActiveElement(ownerDocument), scope)\n ) {\n activeScope = scopeRef;\n }\n };\n\n ownerDocument.addEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusin\", onFocus, false);\n }\n\n return () => {\n ownerDocument.removeEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusin\", onFocus, false);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ contain: contain(), restore: restoreFocus(), scope: scopeRef() }),\n ({\n scope,\n restore: shouldRestore,\n contain: shouldContain,\n }): undefined | (() => void) => {\n if (scope === null || scope.length === 0) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(scope[0]);\n\n if (!isTruthy(shouldRestore)) {\n return undefined;\n }\n\n // Handle the Tab key so that tabbing out of the scope goes to the next element\n // after the node that had focus when the scope mounted. This is important when\n // using portals for overlays, so that focus goes to the expected element when\n // tabbing out of the overlay.\n const onKeyDown = (e: KeyboardEvent) => {\n if (!isRestoreFocusTab(e, scopeRef)) {\n return;\n }\n\n const focusedElement = focusableElementOrNull(\n ownerDocument.activeElement\n );\n\n if (\n focusedElement === null ||\n !isElementInChildScope(focusedElement, scopeRef) ||\n !shouldRestoreFocus(scopeRef)\n ) {\n return;\n }\n\n const treeNode = focusScopeTree.getTreeNode(scopeRef);\n\n if (!treeNode) {\n return;\n }\n\n let { nodeToRestore } = treeNode;\n\n // Create a DOM tree walker that matches all tabbable elements\n const walker = getFocusableTreeWalker(ownerDocument.body, {\n tabbable: true,\n });\n\n // Find the next tabbable element after the currently focused element\n walker.currentNode = focusedElement;\n\n let nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n\n if (\n !nodeToRestore ||\n !nodeToRestore.isConnected ||\n nodeToRestore === ownerDocument.body\n ) {\n nodeToRestore = undefined;\n treeNode.nodeToRestore = undefined;\n }\n\n // If there is no next element, or it is outside the current scope, move focus to the\n // next element after the node to restore to instead.\n if (\n (!isTruthy(nextElement) ||\n !isElementInChildScope(nextElement, scopeRef)) &&\n nodeToRestore\n ) {\n walker.currentNode = nodeToRestore;\n\n // Skip over elements within the scope, in case the scope immediately follows the node to restore.\n do {\n nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n } while (\n nextElement !== null &&\n isElementInChildScope(nextElement, scopeRef)\n );\n\n e.preventDefault();\n e.stopPropagation();\n\n if (isTruthy(nextElement)) {\n focusElement(nextElement, true);\n } else if (isElementInAnyScope(nodeToRestore)) {\n focusElement(nodeToRestore, true);\n } else {\n focusedElement.blur();\n }\n }\n };\n\n if (!isTruthy(shouldContain)) {\n ownerDocument.addEventListener(\"keydown\", onKeyDown, true);\n }\n\n return () => {\n if (!isTruthy(shouldContain)) {\n ownerDocument.removeEventListener(\"keydown\", onKeyDown, true);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ ready: scopeReady(), restore: restoreFocus() }),\n ({ ready, restore: shouldRestore }): undefined | (() => void) => {\n if (!ready || !isTruthy(shouldRestore)) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(untrack(scopeRef)?.[0]);\n\n if (!isTruthy(shouldRestore)) {\n return undefined;\n }\n\n const treeNode = focusScopeTree.getTreeNode(scopeRef);\n\n if (!treeNode) {\n return undefined;\n }\n\n treeNode.nodeToRestore = initialFocusTarget ?? undefined;\n\n return () => {\n const treeNodeValue = focusScopeTree.getTreeNode(scopeRef);\n\n if (!treeNodeValue) {\n return;\n }\n\n const { nodeToRestore } = treeNodeValue;\n // if we already lost focus to the body and this was the active scope, then we should attempt to restore\n const activeElement = getActiveElement(ownerDocument);\n\n if (\n isTruthy(untrack(restoreFocus)) &&\n nodeToRestore &&\n ((activeElement && isElementInChildScope(activeElement, scopeRef)) ||\n (activeElement === ownerDocument.body &&\n shouldRestoreFocus(scopeRef)))\n ) {\n // freeze the focusScopeTree so it persists after the raf, otherwise during unmount nodes are removed from it\n const clonedTree = focusScopeTree.clone();\n requestAnimationFrame(() => {\n // Only restore focus if we've lost focus to the body, the alternative is that focus has been purposefully moved elsewhere\n if (ownerDocument.activeElement === ownerDocument.body) {\n // look up the tree starting with our scope to find a nodeToRestore still in the DOM\n let treeNodeValue2 = clonedTree.getTreeNode(scopeRef);\n\n while (treeNodeValue2) {\n if (\n treeNodeValue2.nodeToRestore &&\n treeNodeValue2.nodeToRestore.isConnected\n ) {\n restoreFocusToElement(treeNodeValue2.nodeToRestore);\n\n return;\n }\n\n treeNodeValue2 = treeNodeValue2.parent;\n }\n\n // If no nodeToRestore was found, focus the first element in the nearest\n // ancestor scope that is still in the tree.\n treeNodeValue2 = clonedTree.getTreeNode(scopeRef);\n\n while (treeNodeValue2) {\n const scopeNodes = treeNodeValue2.scopeRef?.();\n\n if (\n scopeNodes &&\n focusScopeTree.getTreeNode(treeNodeValue2.scopeRef)\n ) {\n const node = getFirstInScope(scopeNodes, true);\n\n // The scope may have nothing focusable in it, e.g. if its focusable\n // content was removed or hidden. Keep walking up in that case.\n if (node) {\n restoreFocusToElement(node);\n\n return;\n }\n }\n\n treeNodeValue2 = treeNodeValue2.parent;\n }\n }\n });\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\nfunction restoreFocusToElement(node: FocusableElement) {\n // Dispatch a custom event that parent elements can intercept to customize focus restoration.\n // For example, virtualized collection components reuse DOM elements, so the original element\n // might still exist in the DOM but representing a different item.\n if (\n node.dispatchEvent(\n new CustomEvent(RESTORE_FOCUS_EVENT, { bubbles: true, cancelable: true })\n )\n ) {\n focusElement(node);\n }\n}\n\n/**\n * Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}\n * that matches all focusable/tabbable elements.\n */\nexport function getFocusableTreeWalker(\n root: Element,\n opts?: FocusManagerOptions,\n scope?: Element[]\n): ShadowTreeWalker | TreeWalker {\n const filter = isTruthy(opts?.tabbable) ? isTabbable : isFocusable;\n // Ensure that root is an Element or fall back appropriately\n const rootElement = root?.nodeType === Node.ELEMENT_NODE ? root : null;\n // Determine the document to use\n const doc = getOwnerDocument(rootElement);\n\n // Create a TreeWalker, ensuring the root is an Element or Document\n const walker = createShadowTreeWalker(\n doc,\n getTruthyValue(root) ?? doc,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode(node) {\n // Skip nodes inside the starting node.\n if (nodeContains(opts?.from, node)) {\n return NodeFilter.FILTER_REJECT;\n }\n\n if (\n isTruthy(opts?.tabbable) &&\n requireElement(node).tagName === \"INPUT\" &&\n requireHTMLInputElement(node).getAttribute(\"type\") === \"radio\"\n ) {\n // If the radio is in a form, we can get all the other radios by name\n if (!isTabbableRadio(requireHTMLInputElement(node))) {\n return NodeFilter.FILTER_REJECT;\n }\n\n // If the radio is in the same group as the current node and none are selected, we can skip it\n if (\n requireElement(walker.currentNode).tagName === \"INPUT\" &&\n requireHTMLInputElement(walker.currentNode).type === \"radio\" &&\n requireHTMLInputElement(walker.currentNode).name ===\n requireHTMLInputElement(node).name\n ) {\n return NodeFilter.FILTER_REJECT;\n }\n }\n\n if (\n filter(requireElement(node)) &&\n (!scope || isElementInScope(requireElement(node), scope)) &&\n (!opts?.accept || opts.accept(requireElement(node)))\n ) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n },\n }\n );\n\n if (opts?.from) {\n walker.currentNode = opts.from;\n }\n\n return walker;\n}\n\n/**\n * Creates a FocusManager object that can be used to move focus within an element.\n */\nexport function createFocusManager(\n ref: Accessor<Element | null>,\n defaultOptions: FocusManagerOptions = {}\n): FocusManager {\n return {\n focusFirst(opts = defaultOptions) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n tabbable = defaultOptions.tabbable,\n accept = defaultOptions.accept,\n } = opts;\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n const nextNode = focusableElementOrNull(walker.nextNode());\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusLast(opts = defaultOptions) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n tabbable = defaultOptions.tabbable,\n accept = defaultOptions.accept,\n } = opts;\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n const next = last(walker);\n\n if (next) {\n focusElement(next, true);\n }\n\n return next ?? null;\n },\n focusNext(opts: FocusManagerOptions = {}) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n from,\n tabbable = defaultOptions.tabbable,\n wrap = defaultOptions.wrap,\n accept = defaultOptions.accept,\n } = opts;\n\n const node =\n getTruthyValue(from) ?? getActiveElement(getOwnerDocument(root));\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n\n if (nodeContains(root, node)) {\n walker.currentNode = requireValue(node, \"Expected node\");\n }\n\n let nextNode = focusableElementOrNull(walker.nextNode());\n\n if (!isTruthy(nextNode) && isTruthy(wrap)) {\n walker.currentNode = root;\n nextNode = focusableElementOrNull(walker.nextNode());\n }\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = defaultOptions) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n from,\n tabbable = defaultOptions.tabbable,\n wrap = defaultOptions.wrap,\n accept = defaultOptions.accept,\n } = opts;\n\n const node =\n getTruthyValue(from) ?? getActiveElement(getOwnerDocument(root));\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n\n if (nodeContains(root, node)) {\n walker.currentNode = requireValue(node, \"Expected node\");\n } else {\n const next = last(walker);\n\n if (next) {\n focusElement(next, true);\n }\n\n return next ?? null;\n }\n\n let previousNode = focusableElementOrNull(walker.previousNode());\n\n if (!isTruthy(previousNode) && isTruthy(wrap)) {\n walker.currentNode = root;\n const lastNode = last(walker);\n\n if (!lastNode) {\n // couldn't wrap\n return null;\n }\n\n previousNode = lastNode;\n }\n\n if (isTruthy(previousNode)) {\n focusElement(previousNode, true);\n }\n\n return previousNode ?? null;\n },\n };\n}\n\nfunction last(walker: ShadowTreeWalker | TreeWalker) {\n let next;\n let lastValue: FocusableElement | null;\n\n do {\n lastValue = focusableElementOrNull(walker.lastChild());\n\n if (isTruthy(lastValue)) {\n next = lastValue;\n }\n } while (isTruthy(lastValue));\n\n return next;\n}\n\nfunction isRestoreFocusTab(\n e: KeyboardEvent,\n scopeRef: Accessor<Element[] | null>\n): boolean {\n return (\n e.key === \"Tab\" &&\n !e.altKey &&\n !e.ctrlKey &&\n !e.metaKey &&\n shouldContainFocus(scopeRef) &&\n !e.isComposing\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAM,OAAN,MAAM,KAAK;CACT;CACA,0BAA2B,IAAI,IAAwB;CACvD,cAAc;EACZ,KAAK,OAAO,IAAI,SAAS,EAAE,UAAU,KAAK,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IAAI,CAAC,MACH,OAAO;GAGT,MAAM,EACJ,MACA,WAAW,eAAe,UAC1B,OAAO,eAAe,MACtB,SAAS,eAAe,WACtB;GAEJ,MAAM,OACJ,eAAe,IAAI,KAAK,iBAAiB,iBAAiB,IAAI,CAAC;GAEjE,MAAM,SAAS,uBAAuB,MAAM;IAAE;IAAQ;GAAS,CAAC;GAEhE,IAAI,aAAa,MAAM,IAAI,GACzB,OAAO,cAAc,aAAa,MAAM,eAAe;QAClD;IACL,MAAM,OAAO,KAAK,MAAM;IAExB,IAAI,MACF,aAAa,MAAM,IAAI;IAGzB,OAAO,QAAQ;GACjB;GAEA,IAAI,eAAe,uBAAuB,OAAO,aAAa,CAAC;GAE/D,IAAI,CAAC,SAAS,YAAY,KAAK,SAAS,IAAI,GAAG;IAC7C,OAAO,cAAc;IACrB,MAAM,WAAW,KAAK,MAAM;IAE5B,IAAI,CAAC,UAEH,OAAO;IAGT,eAAe;GACjB;GAEA,IAAI,SAAS,YAAY,GACvB,aAAa,cAAc,IAAI;GAGjC,OAAO,gBAAgB;EACzB;CACF;AACF;AAEA,SAAS,KAAK,QAAuC;CACnD,IAAI;CACJ,IAAI;CAEJ,GAAG;EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,SAAS,SAAS,GACpB,OAAO;CAEX,SAAS,SAAS,SAAS;CAE3B,OAAO;AACT;AAEA,SAAS,kBACP,GACA,UACS;CACT,OACE,EAAE,QAAQ,SACV,CAAC,EAAE,UACH,CAAC,EAAE,WACH,CAAC,EAAE,WACH,mBAAmB,QAAQ,KAC3B,CAAC,EAAE;AAEP"}
1
+ {"version":3,"file":"focus-scope.js","names":["<FocusContext value={value}>{props.children}</FocusContext>","ref={(element) => {\n setStartRef(element);\n }}","{content()}","ref={(element) => {\n setEndRef(element);\n }}","resolveChildren","_$createComponent","_$getNextElement","_$memo"],"sources":["../../../src/focus/focus-scope.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/focus/FocusScope.tsx.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; resolve scoped children once under their focus context for rendering and focus tracking.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport {\n createMemo,\n untrack,\n children as resolveChildren,\n createContext,\n onSettled,\n useContext,\n createEffect,\n createSignal,\n} from \"solid-js\";\nimport type { Accessor, Element as SolidElement } from \"solid-js\";\n\nimport { getInteractionModality } from \"../interactions/create-focus-visible\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport type { JSX } from \"../types\";\nimport { getOwnerDocument, getOwnerWindow } from \"../utils/dom-helpers\";\nimport {\n focusableElementOrNull,\n requireElement,\n requireFocusableElement,\n requireHTMLInputElement,\n} from \"../utils/dom-value\";\nimport { isFocusable, isTabbable } from \"../utils/is-focusable\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isAndroid, isChrome } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n getActiveElement,\n getEventTarget,\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport type { ShadowTreeWalker } from \"../utils/shadowdom/shadow-tree-walker\";\nimport { createShadowTreeWalker } from \"../utils/shadowdom/shadow-tree-walker\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\n\nclass Tree {\n root: TreeNode;\n private readonly fastMap = new Map<ScopeRef, TreeNode>();\n constructor() {\n this.root = new TreeNode({ scopeRef: null });\n this.fastMap.set(null, this.root);\n }\n get size(): number {\n return this.fastMap.size;\n }\n getTreeNode(data: ScopeRef): TreeNode | undefined {\n return this.fastMap.get(data);\n }\n addTreeNode(\n scopeRef: ScopeRef,\n parent: ScopeRef,\n nodeToRestore?: FocusableElement\n ): void {\n const parentNode = this.fastMap.get(parent ?? null);\n\n if (!parentNode) {\n return;\n }\n\n const node = new TreeNode({ scopeRef });\n parentNode.addChild(node);\n node.parent = parentNode;\n this.fastMap.set(scopeRef, node);\n\n if (nodeToRestore) {\n node.nodeToRestore = nodeToRestore;\n }\n }\n addNode(node: TreeNode): void {\n this.fastMap.set(node.scopeRef, node);\n }\n removeTreeNode(scopeRef: ScopeRef): void {\n // never remove the root\n if (scopeRef === null) {\n return;\n }\n\n const node = this.fastMap.get(scopeRef);\n\n if (!node) {\n return;\n }\n\n const parentNode = node.parent;\n\n // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing\n // if we are, then replace the siblings restore with the restore from the scope we're removing\n for (const current of this.traverse()) {\n if (\n current !== node &&\n node.nodeToRestore &&\n current.nodeToRestore &&\n node.scopeRef &&\n node.scopeRef() &&\n isElementInScope(current.nodeToRestore, node.scopeRef())\n ) {\n current.nodeToRestore = node.nodeToRestore;\n }\n }\n\n const { children } = node;\n\n if (parentNode) {\n // oxlint-disable-next-line unicorn/prefer-dom-node-remove -- Collection and focus-tree nodes implement their own parent/child protocol.\n parentNode.removeChild(node);\n\n if (children.size > 0) {\n for (const child of children) {\n whenTruthy(parentNode, (truthyValue0) => {\n truthyValue0.addChild(child);\n });\n }\n }\n }\n\n this.fastMap.delete(node.scopeRef);\n }\n // Pre Order Depth First\n *traverse(node: TreeNode = this.root): Generator<TreeNode> {\n if (isPresent(node.scopeRef)) {\n yield node;\n }\n\n if (node.children.size > 0) {\n for (const child of node.children) {\n yield* this.traverse(child);\n }\n }\n }\n clone(): Tree {\n const newTree = new Tree();\n\n for (const node of this.traverse()) {\n newTree.addTreeNode(\n node.scopeRef,\n node.parent?.scopeRef ?? null,\n node.nodeToRestore\n );\n }\n\n return newTree;\n }\n}\n\nclass TreeNode {\n public scopeRef: ScopeRef;\n public nodeToRestore?: FocusableElement;\n public parent?: TreeNode;\n public children = new Set<TreeNode>();\n public contain = false;\n constructor(props: { scopeRef: ScopeRef }) {\n this.scopeRef = untrack(() => props.scopeRef);\n }\n addChild(node: TreeNode): void {\n this.children.add(node);\n node.parent = this;\n }\n removeChild(node: TreeNode): void {\n this.children.delete(node);\n node.parent = undefined;\n }\n}\n\nexport const focusScopeTree: Tree = new Tree();\n\nexport interface FocusScopeProps {\n /** The contents of the focus scope. */\n children: SolidElement;\n /**\n * Whether to contain focus inside the scope, so users cannot\n * move focus outside, for example in a modal dialog.\n */\n contain?: boolean;\n /**\n * Whether to restore focus back to the element that was focused\n * when the focus scope mounted, after the focus scope unmounts.\n */\n restoreFocus?: boolean;\n /** Whether to auto focus the first focusable element in the focus scope on mount. */\n autoFocus?: boolean;\n}\n\nexport interface FocusManagerOptions {\n /** The element to start searching from. The currently focused element by default. */\n from?: Element;\n /** Whether to only include tabbable elements, or all focusable elements. */\n tabbable?: boolean;\n /** Whether focus should wrap around when it reaches the end of the scope. */\n wrap?: boolean;\n /** A callback that determines whether the given element is focused. */\n accept?: (node: Element) => boolean;\n}\n\nexport interface FocusManager {\n /** Moves focus to the next focusable or tabbable element in the focus scope. */\n focusNext: (opts?: FocusManagerOptions) => FocusableElement | null;\n /** Moves focus to the previous focusable or tabbable element in the focus scope. */\n focusPrevious: (opts?: FocusManagerOptions) => FocusableElement | null;\n /** Moves focus to the first focusable or tabbable element in the focus scope. */\n focusFirst: (opts?: FocusManagerOptions) => FocusableElement | null;\n /** Moves focus to the last focusable or tabbable element in the focus scope. */\n focusLast: (opts?: FocusManagerOptions) => FocusableElement | null;\n}\n\ntype ScopeRef = Accessor<Element[] | null> | null;\n\ninterface IFocusContext {\n focusManager: FocusManager;\n parentNode: TreeNode | null;\n}\n\nconst FocusContext = createContext<IFocusContext | null>(null);\nconst RESTORE_FOCUS_EVENT = \"react-aria-focus-scope-restore\";\nlet activeScope: ScopeRef = null;\n\n/**\n * A FocusScope manages focus for its descendants. It supports containing focus inside\n * the scope, restoring focus to the previously focused element on unmount, and auto\n * focusing children on mount. It also acts as a container for a programmatic focus\n * management interface that can be used to move focus forward and back in response\n * to user events.\n */\nconst stopPropagation = (event: Event) => {\n event.stopPropagation();\n};\n\nexport function FocusScope(props: FocusScopeProps): JSX.Element {\n const [startRef, setStartRef] = createSignal<HTMLSpanElement | null>(null, {\n ownedWrite: true,\n });\n\n const [endRef, setEndRef] = createSignal<HTMLSpanElement | null>(null, {\n ownedWrite: true,\n });\n\n const [scopeRef, setScopeRef] = createSignal<Element[]>([], {\n ownedWrite: true,\n });\n\n const parentNode = useContext(FocusContext)?.parentNode;\n const node = new TreeNode({ scopeRef });\n const focusManager = createFocusManagerForScope(scopeRef);\n const value = { focusManager, parentNode: node };\n\n const content = resolveChildren(() => (\n <FocusContext value={value}>{props.children}</FocusContext>\n ));\n\n onSettled(() => {\n let parent = getTruthyValue(parentNode) ?? focusScopeTree.root;\n\n if (\n focusScopeTree.getTreeNode(parent.scopeRef) &&\n activeScope &&\n !isAncestorScope(activeScope, parent.scopeRef)\n ) {\n parent = focusScopeTree.getTreeNode(activeScope) ?? parent;\n }\n\n parent.addChild(node);\n focusScopeTree.addNode(node);\n\n return () => {\n const parentScope =\n focusScopeTree.getTreeNode(scopeRef)?.parent?.scopeRef ?? null;\n\n if (\n (scopeRef === activeScope || isAncestorScope(scopeRef, activeScope)) &&\n (!parentScope || focusScopeTree.getTreeNode(parentScope))\n ) {\n activeScope = parentScope;\n }\n\n focusScopeTree.removeTreeNode(scopeRef);\n };\n });\n createEffect(\n () => props.contain,\n (contain) => {\n node.contain = isTruthy(contain);\n },\n { ssrSource: \"client\" }\n );\n\n createEffect(\n () => ({ content: content(), end: endRef(), start: startRef() }),\n ({ start, end }): undefined | (() => void) => {\n if (!start || !end) {\n return undefined;\n }\n\n let element = start.nextSibling;\n const nodes: Element[] = [];\n\n while (element && element !== end) {\n if (element instanceof Element) {\n nodes.push(element);\n element.addEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n }\n\n element = element.nextSibling;\n }\n\n setScopeRef(nodes);\n\n return () => {\n for (const elementValue of nodes) {\n elementValue.removeEventListener(\n RESTORE_FOCUS_EVENT,\n stopPropagation\n );\n }\n };\n },\n { ssrSource: \"client\" }\n );\n createActiveScopeTracker(\n scopeRef,\n () => props.restoreFocus,\n () => props.contain\n );\n createFocusContainment(scopeRef, () => props.contain);\n createRestoreFocus(\n scopeRef,\n () => props.restoreFocus,\n () => props.contain\n );\n createAutoFocus(scopeRef, () => props.autoFocus);\n createEffect(\n scopeRef,\n (scopeNodes) => {\n const activeElement = getActiveElement(getOwnerDocument(scopeNodes[0]));\n\n if (isElementInScope(activeElement, scopeNodes)) {\n let scope: TreeNode | null = null;\n\n for (const child of focusScopeTree.traverse()) {\n if (\n child.scopeRef &&\n isElementInScope(activeElement, untrack(child.scopeRef))\n ) {\n scope = child;\n }\n }\n\n if (scope && scope === focusScopeTree.getTreeNode(scopeRef)) {\n activeScope = scope.scopeRef;\n }\n }\n },\n { ssrSource: \"client\" }\n );\n\n return (\n <>\n <span\n data-focus-scope-start\n hidden\n ref={(element) => {\n setStartRef(element);\n }}\n />\n {content()}\n <span\n data-focus-scope-end\n hidden\n ref={(element) => {\n setEndRef(element);\n }}\n />\n </>\n );\n}\n\n/**\n * Returns a FocusManager interface for the parent FocusScope.\n * A FocusManager can be used to programmatically move focus within\n * a FocusScope, e.g. in response to user events like keyboard navigation.\n */\nexport function createFocusScopeManager(): FocusManager | undefined {\n return useContext(FocusContext)?.focusManager;\n}\n\nfunction createFocusManagerForScope(\n scopeRef: Accessor<Element[] | null>\n): FocusManager {\n return {\n focusFirst(opts = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { tabbable, accept } = opts;\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = requireValue(\n requireValue(scope[0], \"Expected a present traversal value\")\n .previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n const nextNode = focusableElementOrNull(walker.nextNode());\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusLast(opts = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { tabbable, accept } = opts;\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = requireValue(\n requireValue(scope.at(-1), \"Expected a present traversal value\")\n .nextElementSibling,\n \"Expected scope.at(-1)!.nextElementSibling\"\n );\n const previousNode = focusableElementOrNull(walker.previousNode());\n\n if (isTruthy(previousNode)) {\n focusElement(previousNode, true);\n }\n\n return previousNode;\n },\n focusNext(opts: FocusManagerOptions = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { from, tabbable, wrap, accept } = opts;\n\n const node =\n getTruthyValue(from) ??\n requireValue(\n getActiveElement(getOwnerDocument(scope[0] ?? undefined)),\n \"Expected getActiveElement(getOwnerDocument(scope[0]! ?? undefined))\"\n );\n\n const sentinel = requireValue(\n requireValue(scope[0], \"Expected a present traversal value\")\n .previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let nextNode = focusableElementOrNull(walker.nextNode());\n\n if (!isTruthy(nextNode) && isTruthy(wrap)) {\n walker.currentNode = sentinel;\n nextNode = focusableElementOrNull(walker.nextNode());\n }\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = {}) {\n const scope = requireValue(scopeRef(), \"Expected focus scope nodes\");\n const { from, tabbable, wrap, accept } = opts;\n\n const node =\n getTruthyValue(from) ??\n requireValue(\n getActiveElement(getOwnerDocument(scope[0] ?? undefined)),\n \"Expected getActiveElement(getOwnerDocument(scope[0]! ?? undefined))\"\n );\n\n const sentinel = requireValue(\n requireValue(scope.at(-1), \"Expected a present traversal value\")\n .nextElementSibling,\n \"Expected scope[scope.length - 1]!.nextElementSibling\"\n );\n\n const scopeRoot = getScopeRoot(scope);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { accept, tabbable },\n scope\n );\n\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let previousNode = focusableElementOrNull(walker.previousNode());\n\n if (!isTruthy(previousNode) && isTruthy(wrap)) {\n walker.currentNode = sentinel;\n previousNode = focusableElementOrNull(walker.previousNode());\n }\n\n if (isTruthy(previousNode)) {\n focusElement(previousNode, true);\n }\n\n return previousNode;\n },\n };\n}\n\nfunction getScopeRoot(scope: Element[]) {\n return requireValue(\n getParentElement(scope[0]),\n \"Expected scope[0]!.parentElement\"\n );\n}\n\nfunction shouldContainFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.contain) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return true;\n}\n\nfunction getRadiosInGroup(element: HTMLInputElement): HTMLInputElement[] {\n if (!element.form) {\n // Radio buttons outside a form - query the document\n return [\n ...getOwnerDocument(element).querySelectorAll<HTMLInputElement>(\n `input[type=\"radio\"][name=\"${CSS.escape(element.name)}\"]`\n ),\n ].filter((radio) => !radio.form);\n }\n\n // namedItem returns RadioNodeList (iterable) for 2+ elements, but a single Element for exactly 1.\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormControlsCollection/namedItem\n const radioList = element.form.elements.namedItem(element.name);\n const ownerWindow = getOwnerWindow(element);\n\n if (radioList instanceof ownerWindow.RadioNodeList) {\n return [...radioList].filter(\n (el): el is HTMLInputElement => el instanceof ownerWindow.HTMLInputElement\n );\n }\n\n if (radioList instanceof ownerWindow.HTMLInputElement) {\n return [radioList];\n }\n\n return [];\n}\n\nfunction isTabbableRadio(element: HTMLInputElement): boolean {\n if (element.checked) {\n return true;\n }\n\n const radios = getRadiosInGroup(element);\n\n return radios.length > 0 && !radios.some((radio) => radio.checked);\n}\n\nfunction createFocusContainment(\n scopeRef: Accessor<Element[] | null>,\n contain: () => boolean | undefined\n) {\n let focusedNode: FocusableElement | undefined;\n\n let raf: ReturnType<typeof requestAnimationFrame> | undefined;\n\n createEffect(\n () => ({ contain: contain(), scope: scopeRef() }),\n ({ scope, contain: shouldContain }): undefined | (() => void) => {\n if (scope === null || scope.length === 0) {\n return undefined;\n }\n\n if (!isTruthy(shouldContain)) {\n // if contain() was changed, then we should cancel any ongoing waits to pull focus back into containment\n if (raf !== undefined) {\n cancelAnimationFrame(raf);\n raf = undefined;\n }\n\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(\n requireValue(scope[0], \"Expected first scope element\")\n );\n\n // Handle the Tab key to contain() focus within the scope\n const onKeyDown = (e: KeyboardEvent) => {\n if (!isRestoreFocusTab(e, scopeRef)) {\n return;\n }\n\n const focusedElement = getActiveElement(ownerDocument);\n const scopeValue = scopeRef();\n\n if (!scopeValue || !isElementInScope(focusedElement, scopeValue)) {\n return;\n }\n\n const scopeRoot = getScopeRoot(scopeValue);\n\n const walker = getFocusableTreeWalker(\n scopeRoot,\n { tabbable: true },\n scopeValue\n );\n\n if (!focusedElement) {\n return;\n }\n\n walker.currentNode = focusedElement;\n\n let nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n\n if (!isTruthy(nextElement)) {\n walker.currentNode = e.shiftKey\n ? requireValue(\n requireValue(\n scopeValue.at(-1),\n \"Expected a present traversal value\"\n ).nextElementSibling,\n \"Expected scope.at(-1)!.nextElementSibling\"\n )\n : requireValue(\n requireValue(\n scopeValue[0],\n \"Expected a present traversal value\"\n ).previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n }\n\n e.preventDefault();\n\n if (isTruthy(nextElement)) {\n focusElement(nextElement, true);\n\n if (\n nextElement instanceof getOwnerWindow(nextElement).HTMLInputElement\n ) {\n nextElement.select();\n }\n }\n };\n\n const onFocus: EventListener = (e) => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if (\n (!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(requireElement(getEventTarget(e)), scope)\n ) {\n activeScope = scopeRef;\n focusedNode = requireFocusableElement(getEventTarget(e));\n } else if (\n shouldContainFocus(scopeRef) &&\n !isElementInChildScope(requireElement(getEventTarget(e)), scopeRef)\n ) {\n // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),\n // restore focus to the previously focused node or the first tabbable element in the active scope.\n if (focusedNode) {\n focusElement(focusedNode);\n } else {\n const activeNodes = activeScope?.();\n\n if (activeNodes) {\n focusFirstInScope(activeNodes);\n }\n }\n } else if (shouldContainFocus(scopeRef)) {\n focusedNode = requireFocusableElement(getEventTarget(e));\n }\n };\n\n const onBlur: EventListener = (e) => {\n // Firefox doesn't shift focus back to the Dialog properly without this\n if (raf !== undefined) {\n cancelAnimationFrame(raf);\n }\n\n raf = requestAnimationFrame(() => {\n // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor\n // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.\n // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.\n const modality = getInteractionModality();\n\n const shouldSkipFocusRestore =\n (modality === \"virtual\" || modality === null) &&\n isAndroid() &&\n isChrome();\n\n // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe\n const activeElement = getActiveElement(ownerDocument);\n\n if (\n !shouldSkipFocusRestore &&\n activeElement &&\n shouldContainFocus(scopeRef) &&\n !isElementInChildScope(activeElement, scopeRef)\n ) {\n activeScope = scopeRef;\n const target = requireFocusableElement(getEventTarget(e));\n\n if (isTruthy(target) && target.isConnected) {\n focusedNode = target;\n focusElement(focusedNode);\n } else {\n const activeNodes = activeScope();\n\n if (activeNodes) {\n focusFirstInScope(activeNodes);\n }\n }\n }\n });\n };\n\n ownerDocument.addEventListener(\"keydown\", onKeyDown, false);\n ownerDocument.addEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusin\", onFocus, false);\n }\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusout\", onBlur, false);\n }\n\n return () => {\n ownerDocument.removeEventListener(\"keydown\", onKeyDown, false);\n ownerDocument.removeEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusin\", onFocus, false);\n }\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusout\", onBlur, false);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n onSettled(() => () => {\n if (raf !== undefined) {\n cancelAnimationFrame(raf);\n }\n });\n}\n\nfunction isElementInAnyScope(element: Element) {\n return isElementInChildScope(element);\n}\n\nfunction isElementInScope(element?: Element | null, scope?: Element[] | null) {\n if (!element) {\n return false;\n }\n\n if (!scope) {\n return false;\n }\n\n return scope.some((node) => nodeContains(node, element));\n}\n\nfunction isElementInChildScope(element: Element, scope: ScopeRef = null) {\n // If the element is within a top layer element (e.g. toasts), always allow moving focus there.\n if (\n element instanceof Element &&\n element.closest(\"[data-react-aria-top-layer]\")\n ) {\n return true;\n }\n\n // node.contains in isElementInScope covers child scopes that are also DOM children,\n // but does not cover child scopes in portals.\n for (const { scopeRef: s } of focusScopeTree.traverse(\n focusScopeTree.getTreeNode(scope)\n )) {\n if (s && isElementInScope(element, untrack(s))) {\n return true;\n }\n }\n\n return false;\n}\n\n/** @private */\nexport function isElementInChildOfActiveScope(element: Element): boolean {\n return isElementInChildScope(element, activeScope);\n}\n\nfunction isAncestorScope(ancestor: ScopeRef, scope: ScopeRef) {\n let parent = focusScopeTree.getTreeNode(scope)?.parent;\n\n while (parent) {\n if (parent.scopeRef === ancestor) {\n return true;\n }\n\n ({ parent } = parent);\n }\n\n return false;\n}\n\nfunction focusElement(element: FocusableElement | null, scroll = false) {\n if (isPresent(element) && !scroll) {\n try {\n focusSafely(element);\n } catch {\n // ignore\n }\n } else if (isPresent(element)) {\n try {\n element.focus();\n } catch {\n // ignore\n }\n }\n}\n\nfunction getFirstInScope(\n scope: Element[],\n tabbable = true\n): FocusableElement | null {\n const sentinel = requireValue(\n requireValue(scope[0], \"Expected a present traversal value\")\n .previousElementSibling,\n \"Expected scope[0]!.previousElementSibling\"\n );\n\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, { tabbable }, scope);\n walker.currentNode = sentinel;\n let nextNode = walker.nextNode();\n\n // If the scope does not contain a tabbable element, use the first focusable element.\n if (tabbable && !nextNode) {\n scopeRoot = getScopeRoot(scope);\n walker = getFocusableTreeWalker(scopeRoot, { tabbable: false }, scope);\n walker.currentNode = sentinel;\n nextNode = walker.nextNode();\n }\n\n // TreeWalker.nextNode() returns null when the scope contains no focusable element.\n return focusableElementOrNull(nextNode);\n}\n\nfunction focusFirstInScope(scope: Element[], tabbable = true) {\n focusElement(getFirstInScope(scope, tabbable));\n}\n\nfunction createAutoFocus(\n scopeRef: Accessor<Element[] | null>,\n autoFocus: () => boolean | undefined\n) {\n let pendingAutoFocus = untrack(autoFocus);\n createEffect(\n scopeRef,\n (scope) => {\n if (!isTruthy(pendingAutoFocus) || scope === null || scope.length === 0) {\n return;\n }\n\n pendingAutoFocus = false;\n activeScope = scopeRef;\n const ownerDocument = getOwnerDocument(scope[0]);\n\n if (!isElementInScope(getActiveElement(ownerDocument), scope)) {\n focusFirstInScope(scope);\n }\n },\n { ssrSource: \"client\" }\n );\n}\n\nfunction createActiveScopeTracker(\n scopeRef: Accessor<Element[] | null>,\n restore: () => boolean | undefined,\n contain: () => boolean | undefined\n) {\n // Track active scopes that do not contain or restore focus.\n createEffect(\n () => ({ contain: contain(), restore: restore(), scope: scopeRef() }),\n ({\n scope,\n restore: shouldRestore,\n contain: shouldContain,\n }): undefined | (() => void) => {\n if (\n scope === null ||\n scope.length === 0 ||\n isTruthy(shouldRestore) ||\n isTruthy(shouldContain)\n ) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(\n requireValue(scope[0], \"Expected first scope element\")\n );\n\n const onFocus = (e: Event) => {\n const target = requireElement(getEventTarget(e));\n\n if (isElementInScope(target, scope)) {\n activeScope = scopeRef;\n } else if (!isElementInAnyScope(target)) {\n activeScope = null;\n }\n };\n\n ownerDocument.addEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusin\", onFocus, false);\n }\n\n return () => {\n ownerDocument.removeEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusin\", onFocus, false);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\nfunction shouldRestoreFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.nodeToRestore) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return scope?.scopeRef === scopeRef;\n}\n\nfunction createRestoreFocus(\n scopeRef: Accessor<Element[] | null>,\n restoreFocus: () => boolean | undefined,\n contain: () => boolean | undefined\n) {\n // Capture focus before scoped children can autofocus.\n const initialFocusTarget = untrack(() =>\n typeof document === \"undefined\"\n ? null\n : focusableElementOrNull(\n getActiveElement(getOwnerDocument(scopeRef()?.[0]))\n )\n );\n\n const scopeReady = createMemo(() => (scopeRef()?.length ?? 0) > 0);\n\n // restoring scopes should all track if they are active regardless of contain(), but contain() already tracks it plus logic to contain() the focus\n // restoring-non-containing scopes should only care if they become active so they can perform the restore\n createEffect(\n () => ({ contain: contain(), restore: restoreFocus(), scope: scopeRef() }),\n ({\n scope,\n restore: shouldRestore,\n contain: shouldContain,\n }): undefined | (() => void) => {\n if (scope === null || scope.length === 0) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(\n requireValue(scope[0], \"Expected first scope element\")\n );\n\n if (!isTruthy(shouldRestore) || isTruthy(shouldContain)) {\n return undefined;\n }\n\n const onFocus = () => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if (\n (!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(getActiveElement(ownerDocument), scope)\n ) {\n activeScope = scopeRef;\n }\n };\n\n ownerDocument.addEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.addEventListener(\"focusin\", onFocus, false);\n }\n\n return () => {\n ownerDocument.removeEventListener(\"focusin\", onFocus, false);\n\n for (const element of scope ?? []) {\n element.removeEventListener(\"focusin\", onFocus, false);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ contain: contain(), restore: restoreFocus(), scope: scopeRef() }),\n ({\n scope,\n restore: shouldRestore,\n contain: shouldContain,\n }): undefined | (() => void) => {\n if (scope === null || scope.length === 0) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(scope[0]);\n\n if (!isTruthy(shouldRestore)) {\n return undefined;\n }\n\n // Handle the Tab key so that tabbing out of the scope goes to the next element\n // after the node that had focus when the scope mounted. This is important when\n // using portals for overlays, so that focus goes to the expected element when\n // tabbing out of the overlay.\n const onKeyDown = (e: KeyboardEvent) => {\n if (!isRestoreFocusTab(e, scopeRef)) {\n return;\n }\n\n const focusedElement = focusableElementOrNull(\n ownerDocument.activeElement\n );\n\n if (\n focusedElement === null ||\n !isElementInChildScope(focusedElement, scopeRef) ||\n !shouldRestoreFocus(scopeRef)\n ) {\n return;\n }\n\n const treeNode = focusScopeTree.getTreeNode(scopeRef);\n\n if (!treeNode) {\n return;\n }\n\n let { nodeToRestore } = treeNode;\n\n // Create a DOM tree walker that matches all tabbable elements\n const walker = getFocusableTreeWalker(ownerDocument.body, {\n tabbable: true,\n });\n\n // Find the next tabbable element after the currently focused element\n walker.currentNode = focusedElement;\n\n let nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n\n if (\n !nodeToRestore ||\n !nodeToRestore.isConnected ||\n nodeToRestore === ownerDocument.body\n ) {\n nodeToRestore = undefined;\n treeNode.nodeToRestore = undefined;\n }\n\n // If there is no next element, or it is outside the current scope, move focus to the\n // next element after the node to restore to instead.\n if (\n (!isTruthy(nextElement) ||\n !isElementInChildScope(nextElement, scopeRef)) &&\n nodeToRestore\n ) {\n walker.currentNode = nodeToRestore;\n\n // Skip over elements within the scope, in case the scope immediately follows the node to restore.\n do {\n nextElement = focusableElementOrNull(\n e.shiftKey ? walker.previousNode() : walker.nextNode()\n );\n } while (\n nextElement !== null &&\n isElementInChildScope(nextElement, scopeRef)\n );\n\n e.preventDefault();\n e.stopPropagation();\n\n if (isTruthy(nextElement)) {\n focusElement(nextElement, true);\n } else if (isElementInAnyScope(nodeToRestore)) {\n focusElement(nodeToRestore, true);\n } else {\n focusedElement.blur();\n }\n }\n };\n\n if (!isTruthy(shouldContain)) {\n ownerDocument.addEventListener(\"keydown\", onKeyDown, true);\n }\n\n return () => {\n if (!isTruthy(shouldContain)) {\n ownerDocument.removeEventListener(\"keydown\", onKeyDown, true);\n }\n };\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ ready: scopeReady(), restore: restoreFocus() }),\n ({ ready, restore: shouldRestore }): undefined | (() => void) => {\n if (!ready || !isTruthy(shouldRestore)) {\n return undefined;\n }\n\n const ownerDocument = getOwnerDocument(untrack(scopeRef)?.[0]);\n\n if (!isTruthy(shouldRestore)) {\n return undefined;\n }\n\n const treeNode = focusScopeTree.getTreeNode(scopeRef);\n\n if (!treeNode) {\n return undefined;\n }\n\n treeNode.nodeToRestore = initialFocusTarget ?? undefined;\n\n return () => {\n const treeNodeValue = focusScopeTree.getTreeNode(scopeRef);\n\n if (!treeNodeValue) {\n return;\n }\n\n const { nodeToRestore } = treeNodeValue;\n // if we already lost focus to the body and this was the active scope, then we should attempt to restore\n const activeElement = getActiveElement(ownerDocument);\n\n if (\n isTruthy(untrack(restoreFocus)) &&\n nodeToRestore &&\n ((activeElement && isElementInChildScope(activeElement, scopeRef)) ||\n (activeElement === ownerDocument.body &&\n shouldRestoreFocus(scopeRef)))\n ) {\n // freeze the focusScopeTree so it persists after the raf, otherwise during unmount nodes are removed from it\n const clonedTree = focusScopeTree.clone();\n requestAnimationFrame(() => {\n // Only restore focus if we've lost focus to the body, the alternative is that focus has been purposefully moved elsewhere\n if (ownerDocument.activeElement === ownerDocument.body) {\n // look up the tree starting with our scope to find a nodeToRestore still in the DOM\n let treeNodeValue2 = clonedTree.getTreeNode(scopeRef);\n\n while (treeNodeValue2) {\n if (\n treeNodeValue2.nodeToRestore &&\n treeNodeValue2.nodeToRestore.isConnected\n ) {\n restoreFocusToElement(treeNodeValue2.nodeToRestore);\n\n return;\n }\n\n treeNodeValue2 = treeNodeValue2.parent;\n }\n\n // If no nodeToRestore was found, focus the first element in the nearest\n // ancestor scope that is still in the tree.\n treeNodeValue2 = clonedTree.getTreeNode(scopeRef);\n\n while (treeNodeValue2) {\n const scopeNodes = treeNodeValue2.scopeRef?.();\n\n if (\n scopeNodes &&\n focusScopeTree.getTreeNode(treeNodeValue2.scopeRef)\n ) {\n const node = getFirstInScope(scopeNodes, true);\n\n // The scope may have nothing focusable in it, e.g. if its focusable\n // content was removed or hidden. Keep walking up in that case.\n if (node) {\n restoreFocusToElement(node);\n\n return;\n }\n }\n\n treeNodeValue2 = treeNodeValue2.parent;\n }\n }\n });\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\nfunction restoreFocusToElement(node: FocusableElement) {\n // Dispatch a custom event that parent elements can intercept to customize focus restoration.\n // For example, virtualized collection components reuse DOM elements, so the original element\n // might still exist in the DOM but representing a different item.\n if (\n node.dispatchEvent(\n new CustomEvent(RESTORE_FOCUS_EVENT, { bubbles: true, cancelable: true })\n )\n ) {\n focusElement(node);\n }\n}\n\n/**\n * Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}\n * that matches all focusable/tabbable elements.\n */\nexport function getFocusableTreeWalker(\n root: Element,\n opts?: FocusManagerOptions,\n scope?: Element[]\n): ShadowTreeWalker | TreeWalker {\n const filter = isTruthy(opts?.tabbable) ? isTabbable : isFocusable;\n // Ensure that root is an Element or fall back appropriately\n const rootElement = root?.nodeType === Node.ELEMENT_NODE ? root : null;\n // Determine the document to use\n const doc = getOwnerDocument(rootElement);\n\n // Create a TreeWalker, ensuring the root is an Element or Document\n const walker = createShadowTreeWalker(\n doc,\n getTruthyValue(root) ?? doc,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode(node) {\n // Skip nodes inside the starting node.\n if (nodeContains(opts?.from, node)) {\n return NodeFilter.FILTER_REJECT;\n }\n\n if (\n isTruthy(opts?.tabbable) &&\n requireElement(node).tagName === \"INPUT\" &&\n requireHTMLInputElement(node).getAttribute(\"type\") === \"radio\"\n ) {\n // If the radio is in a form, we can get all the other radios by name\n if (!isTabbableRadio(requireHTMLInputElement(node))) {\n return NodeFilter.FILTER_REJECT;\n }\n\n // If the radio is in the same group as the current node and none are selected, we can skip it\n if (\n requireElement(walker.currentNode).tagName === \"INPUT\" &&\n requireHTMLInputElement(walker.currentNode).type === \"radio\" &&\n requireHTMLInputElement(walker.currentNode).name ===\n requireHTMLInputElement(node).name\n ) {\n return NodeFilter.FILTER_REJECT;\n }\n }\n\n if (\n filter(requireElement(node)) &&\n (!scope || isElementInScope(requireElement(node), scope)) &&\n (!opts?.accept || opts.accept(requireElement(node)))\n ) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n },\n }\n );\n\n if (opts?.from) {\n walker.currentNode = opts.from;\n }\n\n return walker;\n}\n\n/**\n * Creates a FocusManager object that can be used to move focus within an element.\n */\nexport function createFocusManager(\n ref: Accessor<Element | null>,\n defaultOptions: FocusManagerOptions = {}\n): FocusManager {\n return {\n focusFirst(opts = defaultOptions) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n tabbable = defaultOptions.tabbable,\n accept = defaultOptions.accept,\n } = opts;\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n const nextNode = focusableElementOrNull(walker.nextNode());\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusLast(opts = defaultOptions) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n tabbable = defaultOptions.tabbable,\n accept = defaultOptions.accept,\n } = opts;\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n const next = last(walker);\n\n if (next) {\n focusElement(next, true);\n }\n\n return next ?? null;\n },\n focusNext(opts: FocusManagerOptions = {}) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n from,\n tabbable = defaultOptions.tabbable,\n wrap = defaultOptions.wrap,\n accept = defaultOptions.accept,\n } = opts;\n\n const node =\n getTruthyValue(from) ?? getActiveElement(getOwnerDocument(root));\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n\n if (nodeContains(root, node)) {\n walker.currentNode = requireValue(node, \"Expected node\");\n }\n\n let nextNode = focusableElementOrNull(walker.nextNode());\n\n if (!isTruthy(nextNode) && isTruthy(wrap)) {\n walker.currentNode = root;\n nextNode = focusableElementOrNull(walker.nextNode());\n }\n\n if (isTruthy(nextNode)) {\n focusElement(nextNode, true);\n }\n\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = defaultOptions) {\n const root = ref();\n\n if (!root) {\n return null;\n }\n\n const {\n from,\n tabbable = defaultOptions.tabbable,\n wrap = defaultOptions.wrap,\n accept = defaultOptions.accept,\n } = opts;\n\n const node =\n getTruthyValue(from) ?? getActiveElement(getOwnerDocument(root));\n\n const walker = getFocusableTreeWalker(root, { accept, tabbable });\n\n if (nodeContains(root, node)) {\n walker.currentNode = requireValue(node, \"Expected node\");\n } else {\n const next = last(walker);\n\n if (next) {\n focusElement(next, true);\n }\n\n return next ?? null;\n }\n\n let previousNode = focusableElementOrNull(walker.previousNode());\n\n if (!isTruthy(previousNode) && isTruthy(wrap)) {\n walker.currentNode = root;\n const lastNode = last(walker);\n\n if (!lastNode) {\n // couldn't wrap\n return null;\n }\n\n previousNode = lastNode;\n }\n\n if (isTruthy(previousNode)) {\n focusElement(previousNode, true);\n }\n\n return previousNode ?? null;\n },\n };\n}\n\nfunction last(walker: ShadowTreeWalker | TreeWalker) {\n let next;\n let lastValue: FocusableElement | null;\n\n do {\n lastValue = focusableElementOrNull(walker.lastChild());\n\n if (isTruthy(lastValue)) {\n next = lastValue;\n }\n } while (isTruthy(lastValue));\n\n return next;\n}\n\nfunction isRestoreFocusTab(\n e: KeyboardEvent,\n scopeRef: Accessor<Element[] | null>\n): boolean {\n return (\n e.key === \"Tab\" &&\n !e.altKey &&\n !e.ctrlKey &&\n !e.metaKey &&\n shouldContainFocus(scopeRef) &&\n !e.isComposing\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,IAAM,OAAN,MAAM,KAAK;CACT;CACA,0BAA2B,IAAI,IAAwB;CACvD,cAAc;EACZ,KAAK,OAAO,IAAI,SAAS,EAAE,UAAU,KAAK,CAAC;EAC3C,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;CAClC;CACA,IAAI,OAAe;EACjB,OAAO,KAAK,QAAQ;CACtB;CACA,YAAY,MAAsC;EAChD,OAAO,KAAK,QAAQ,IAAI,IAAI;CAC9B;CACA,YACE,UACA,QACA,eACM;EACN,MAAM,aAAa,KAAK,QAAQ,IAAI,UAAU,IAAI;EAElD,IAAI,CAAC,YACH;EAGF,MAAM,OAAO,IAAI,SAAS,EAAE,SAAS,CAAC;EACtC,WAAW,SAAS,IAAI;EACxB,KAAK,SAAS;EACd,KAAK,Q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GACjB;GAEA,IAAI,eAAe,uBAAuB,OAAO,aAAa,CAAC;GAE/D,IAAI,CAAC,SAAS,YAAY,KAAK,SAAS,IAAI,GAAG;IAC7C,OAAO,cAAc;IACrB,MAAM,WAAW,KAAK,MAAM;IAE5B,IAAI,CAAC,UAEH,OAAO;IAGT,eAAe;GACjB;GAEA,IAAI,SAAS,YAAY,GACvB,aAAa,cAAc,IAAI;GAGjC,OAAO,gBAAgB;EACzB;CACF;AACF;AAEA,SAAS,KAAK,QAAuC;CACnD,IAAI;CACJ,IAAI;CAEJ,GAAG;EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,SAAS,SAAS,GACpB,OAAO;CAEX,SAAS,SAAS,SAAS;CAE3B,OAAO;AACT;AAEA,SAAS,kBACP,GACA,UACS;CACT,OACE,EAAE,QAAQ,SACV,CAAC,EAAE,UACH,CAAC,EAAE,WACH,CAAC,EAAE,WACH,mBAAmB,QAAQ,KAC3B,CAAC,EAAE;AAEP"}
@@ -7,4 +7,5 @@ export declare function moveVirtualFocus(to: Element | null): void;
7
7
  export declare function dispatchVirtualBlur(from: Element, to: Element | null): void;
8
8
  export declare function dispatchVirtualFocus(to: Element, from: Element | null): void;
9
9
  export declare function getVirtuallyFocusedElement(document: Document): Element | null;
10
+ export declare function getOriginalRelatedTarget(event: FocusEvent): EventTarget | null;
10
11
  //# sourceMappingURL=virtual-focus.d.ts.map
@@ -7,6 +7,7 @@ import { getTruthyValue, isTruthy } from "../utils/truthy.js";
7
7
  import { getOwnerDocument } from "../utils/dom-helpers.js";
8
8
  import { getActiveElement } from "../utils/shadowdom/dom-functions.js";
9
9
  import { untrack } from "solid-js";
10
+ import { shadowDOM } from "@solid2-aria/stately/flags/flags";
10
11
  // src/focus/virtual-focus.ts
11
12
  function moveVirtualFocus(to) {
12
13
  const from = getVirtuallyFocusedElement(getOwnerDocument(to));
@@ -17,8 +18,8 @@ function moveVirtualFocus(to) {
17
18
  }
18
19
  function dispatchVirtualBlur(from, to) {
19
20
  untrack(() => {
20
- from.dispatchEvent(new FocusEvent("blur", { relatedTarget: to }));
21
- from.dispatchEvent(new FocusEvent("focusout", {
21
+ from.dispatchEvent(createFocusEvent("blur", { relatedTarget: to }));
22
+ from.dispatchEvent(createFocusEvent("focusout", {
22
23
  bubbles: true,
23
24
  relatedTarget: to
24
25
  }));
@@ -26,8 +27,8 @@ function dispatchVirtualBlur(from, to) {
26
27
  }
27
28
  function dispatchVirtualFocus(to, from) {
28
29
  untrack(() => {
29
- to.dispatchEvent(new FocusEvent("focus", { relatedTarget: from }));
30
- to.dispatchEvent(new FocusEvent("focusin", {
30
+ to.dispatchEvent(createFocusEvent("focus", { relatedTarget: from }));
31
+ to.dispatchEvent(createFocusEvent("focusin", {
31
32
  bubbles: true,
32
33
  relatedTarget: from
33
34
  }));
@@ -39,6 +40,20 @@ function getVirtuallyFocusedElement(document) {
39
40
  if (isTruthy(activeDescendant)) return getTruthyValue(document.querySelector(`#${activeDescendant}`)) ?? activeElement;
40
41
  return activeElement;
41
42
  }
42
- export { dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus };
43
+ let originalRelatedTargetMap = null;
44
+ function createFocusEvent(type, eventInitDict) {
45
+ const event = new FocusEvent(type, eventInitDict);
46
+ if (shadowDOM()) {
47
+ originalRelatedTargetMap ??= /* @__PURE__ */ new WeakMap();
48
+ const { relatedTarget } = event;
49
+ if (relatedTarget !== null) originalRelatedTargetMap.set(event, relatedTarget);
50
+ }
51
+ return event;
52
+ }
53
+ function getOriginalRelatedTarget(event) {
54
+ if (!shadowDOM()) return event.relatedTarget;
55
+ return originalRelatedTargetMap?.get(event) ?? event.relatedTarget;
56
+ }
57
+ export { dispatchVirtualBlur, dispatchVirtualFocus, getOriginalRelatedTarget, getVirtuallyFocusedElement, moveVirtualFocus };
43
58
 
44
59
  //# sourceMappingURL=virtual-focus.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtual-focus.js","names":[],"sources":["../../../src/focus/virtual-focus.ts"],"sourcesContent":["/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/focus/virtualFocus.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; dispatch virtual focus events outside reactive tracking so handlers observe event-time state.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { untrack } from \"solid-js\";\n\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { getActiveElement } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport function moveVirtualFocus(to: Element | null): void {\n const from = getVirtuallyFocusedElement(getOwnerDocument(to));\n\n if (from !== to) {\n if (from) {\n dispatchVirtualBlur(from, to);\n }\n\n if (to) {\n dispatchVirtualFocus(to, from);\n }\n }\n}\n\nexport function dispatchVirtualBlur(from: Element, to: Element | null): void {\n untrack(() => {\n from.dispatchEvent(new FocusEvent(\"blur\", { relatedTarget: to }));\n from.dispatchEvent(\n new FocusEvent(\"focusout\", { bubbles: true, relatedTarget: to })\n );\n });\n}\n\nexport function dispatchVirtualFocus(to: Element, from: Element | null): void {\n untrack(() => {\n to.dispatchEvent(new FocusEvent(\"focus\", { relatedTarget: from }));\n to.dispatchEvent(\n new FocusEvent(\"focusin\", { bubbles: true, relatedTarget: from })\n );\n });\n}\n\nexport function getVirtuallyFocusedElement(document: Document): Element | null {\n const activeElement = getActiveElement(document);\n const activeDescendant = activeElement?.getAttribute(\"aria-activedescendant\");\n\n if (isTruthy(activeDescendant)) {\n return (\n getTruthyValue(document.querySelector(`#${activeDescendant}`)) ??\n activeElement\n );\n }\n\n return activeElement;\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,iBAAiB,IAA0B;CACzD,MAAM,OAAO,2BAA2B,iBAAiB,EAAE,CAAC;CAE5D,IAAI,SAAS,IAAI;EACf,IAAI,MACF,oBAAoB,MAAM,EAAE;EAG9B,IAAI,IACF,qBAAqB,IAAI,IAAI;CAEjC;AACF;AAEA,SAAgB,oBAAoB,MAAe,IAA0B;CAC3E,cAAc;EACZ,KAAK,cAAc,IAAI,WAAW,QAAQ,EAAE,eAAe,GAAG,CAAC,CAAC;EAChE,KAAK,cACH,IAAI,WAAW,YAAY;GAAE,SAAS;GAAM,eAAe;EAAG,CAAC,CACjE;CACF,CAAC;AACH;AAEA,SAAgB,qBAAqB,IAAa,MAA4B;CAC5E,cAAc;EACZ,GAAG,cAAc,IAAI,WAAW,SAAS,EAAE,eAAe,KAAK,CAAC,CAAC;EACjE,GAAG,cACD,IAAI,WAAW,WAAW;GAAE,SAAS;GAAM,eAAe;EAAK,CAAC,CAClE;CACF,CAAC;AACH;AAEA,SAAgB,2BAA2B,UAAoC;CAC7E,MAAM,gBAAgB,iBAAiB,QAAQ;CAC/C,MAAM,mBAAmB,eAAe,aAAa,uBAAuB;CAE5E,IAAI,SAAS,gBAAgB,GAC3B,OACE,eAAe,SAAS,cAAc,IAAI,kBAAkB,CAAC,KAC7D;CAIJ,OAAO;AACT"}
1
+ {"version":3,"file":"virtual-focus.js","names":[],"sources":["../../../src/focus/virtual-focus.ts"],"sourcesContent":["/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/focus/virtualFocus.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; dispatch virtual focus events outside reactive tracking so handlers observe event-time state.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { shadowDOM } from \"@solid2-aria/stately/flags/flags\";\nimport { untrack } from \"solid-js\";\n\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { getActiveElement } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport function moveVirtualFocus(to: Element | null): void {\n const from = getVirtuallyFocusedElement(getOwnerDocument(to));\n\n if (from !== to) {\n if (from) {\n dispatchVirtualBlur(from, to);\n }\n\n if (to) {\n dispatchVirtualFocus(to, from);\n }\n }\n}\n\nexport function dispatchVirtualBlur(from: Element, to: Element | null): void {\n untrack(() => {\n from.dispatchEvent(createFocusEvent(\"blur\", { relatedTarget: to }));\n from.dispatchEvent(\n createFocusEvent(\"focusout\", { bubbles: true, relatedTarget: to })\n );\n });\n}\n\nexport function dispatchVirtualFocus(to: Element, from: Element | null): void {\n untrack(() => {\n to.dispatchEvent(createFocusEvent(\"focus\", { relatedTarget: from }));\n to.dispatchEvent(\n createFocusEvent(\"focusin\", { bubbles: true, relatedTarget: from })\n );\n });\n}\n\nexport function getVirtuallyFocusedElement(document: Document): Element | null {\n const activeElement = getActiveElement(document);\n const activeDescendant = activeElement?.getAttribute(\"aria-activedescendant\");\n\n if (isTruthy(activeDescendant)) {\n return (\n getTruthyValue(document.querySelector(`#${activeDescendant}`)) ??\n activeElement\n );\n }\n\n return activeElement;\n}\n\nlet originalRelatedTargetMap: WeakMap<FocusEvent, EventTarget> | null = null;\n\nfunction createFocusEvent(type: string, eventInitDict?: FocusEventInit) {\n const event = new FocusEvent(type, eventInitDict);\n\n if (shadowDOM()) {\n originalRelatedTargetMap ??= new WeakMap();\n const { relatedTarget } = event;\n\n if (relatedTarget !== null) {\n originalRelatedTargetMap.set(event, relatedTarget);\n }\n }\n\n return event;\n}\n\nexport function getOriginalRelatedTarget(\n event: FocusEvent\n): EventTarget | null {\n if (!shadowDOM()) {\n return event.relatedTarget;\n }\n\n return originalRelatedTargetMap?.get(event) ?? event.relatedTarget;\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,iBAAiB,IAA0B;CACzD,MAAM,OAAO,2BAA2B,iBAAiB,EAAE,CAAC;CAE5D,IAAI,SAAS,IAAI;EACf,IAAI,MACF,oBAAoB,MAAM,EAAE;EAG9B,IAAI,IACF,qBAAqB,IAAI,IAAI;CAEjC;AACF;AAEA,SAAgB,oBAAoB,MAAe,IAA0B;CAC3E,cAAc;EACZ,KAAK,cAAc,iBAAiB,QAAQ,EAAE,eAAe,GAAG,CAAC,CAAC;EAClE,KAAK,cACH,iBAAiB,YAAY;GAAE,SAAS;GAAM,eAAe;EAAG,CAAC,CACnE;CACF,CAAC;AACH;AAEA,SAAgB,qBAAqB,IAAa,MAA4B;CAC5E,cAAc;EACZ,GAAG,cAAc,iBAAiB,SAAS,EAAE,eAAe,KAAK,CAAC,CAAC;EACnE,GAAG,cACD,iBAAiB,WAAW;GAAE,SAAS;GAAM,eAAe;EAAK,CAAC,CACpE;CACF,CAAC;AACH;AAEA,SAAgB,2BAA2B,UAAoC;CAC7E,MAAM,gBAAgB,iBAAiB,QAAQ;CAC/C,MAAM,mBAAmB,eAAe,aAAa,uBAAuB;CAE5E,IAAI,SAAS,gBAAgB,GAC3B,OACE,eAAe,SAAS,cAAc,IAAI,kBAAkB,CAAC,KAC7D;CAIJ,OAAO;AACT;AAEA,IAAI,2BAAoE;AAExE,SAAS,iBAAiB,MAAc,eAAgC;CACtE,MAAM,QAAQ,IAAI,WAAW,MAAM,aAAa;CAEhD,IAAI,UAAU,GAAG;EACf,6CAA6B,IAAI,QAAQ;EACzC,MAAM,EAAE,kBAAkB;EAE1B,IAAI,kBAAkB,MACpB,yBAAyB,IAAI,OAAO,aAAa;CAErD;CAEA,OAAO;AACT;AAEA,SAAgB,yBACd,OACoB;CACpB,IAAI,CAAC,UAAU,GACb,OAAO,MAAM;CAGf,OAAO,0BAA0B,IAAI,KAAK,KAAK,MAAM;AACvD"}
@@ -18,7 +18,7 @@ import { isTruthy } from "../utils/truthy.js";
18
18
  import { isPresent } from "../utils/is-present.js";
19
19
  import { mergeProps } from "../utils/merge-props.js";
20
20
  import { getOwnerDocument } from "../utils/dom-helpers.js";
21
- import { getActiveElement, getEventTarget, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
21
+ import { getActiveElement, getEventTarget, getParentElement, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
22
22
  import { elementOrNull, focusableElementOrNull, requireFocusableElement } from "../utils/dom-value.js";
23
23
  import { requireValue } from "../utils/require-value.js";
24
24
  import { isFocusVisible } from "../interactions/create-focus-visible.js";
@@ -107,7 +107,7 @@ function createGridCell(props, state, ref) {
107
107
  scrollIntoViewport(focusable, { containingElement: getScrollParent(cell) });
108
108
  } else {
109
109
  if (_result2.keyboardDelegate.getKeyLeftOf?.(_result0.node.key) !== _result0.node.key) {
110
- cell.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));
110
+ getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));
111
111
  return;
112
112
  }
113
113
  if (focusMode() === "cell" && _result1.direction === "rtl") {
@@ -133,7 +133,7 @@ function createGridCell(props, state, ref) {
133
133
  scrollIntoViewport(focusable, { containingElement: getScrollParent(cell) });
134
134
  } else {
135
135
  if (_result2.keyboardDelegate.getKeyRightOf?.(_result0.node.key) !== _result0.node.key) {
136
- cell.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));
136
+ getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));
137
137
  return;
138
138
  }
139
139
  if (focusMode() === "cell" && _result1.direction === "ltr") {
@@ -166,7 +166,7 @@ function createGridCell(props, state, ref) {
166
166
  case "ArrowDown": if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {
167
167
  e.stopPropagation();
168
168
  e.preventDefault();
169
- refElement.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));
169
+ getParentElement(refElement)?.dispatchEvent(new KeyboardEvent(e.type, e));
170
170
  }
171
171
  }
172
172
  };
@@ -1 +1 @@
1
- {"version":3,"file":"create-grid-cell.js","names":[],"sources":["../../../src/grid/create-grid-cell.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/grid/useGridCell.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { GridState } from \"@solid2-aria/stately/grid/create-grid-state\";\nimport type {\n IGridCollection as GridCollection,\n GridNode,\n} from \"@solid2-aria/stately/grid/grid-collection\";\nimport type { FocusableElement, Key } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createMemo } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { getFocusableTreeWalker } from \"../focus/focus-scope\";\nimport { createLocale } from \"../i18n/i18n-provider\";\nimport { isFocusVisible } from \"../interactions/create-focus-visible\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport { createSelectableItem } from \"../selection/create-selectable-item\";\nimport type { KeyboardEvent as DOMKeyboardEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { createEvent } from \"../utils/create-event\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport {\n elementOrNull,\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isPresent } from \"../utils/is-present\";\nimport { getLegacyOption } from \"../utils/legacy-option\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { requireValue } from \"../utils/require-value\";\nimport { scrollIntoViewport } from \"../utils/scroll-into-view\";\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains,\n} from \"../utils/shadowdom/dom-functions\";\nimport { isTruthy } from \"../utils/truthy\";\nimport { gridMap } from \"./utils\";\n\nexport interface GridCellProps {\n /**\n * An object representing the grid cell. Contains all the relevant information that makes up the\n * grid cell.\n */\n node: GridNode<unknown>;\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /**\n * Whether the cell or its first focusable child element should be focused when the grid cell is\n * focused. Defaults to 'child' in arrow keyboard navigation mode and 'cell' in\n * tab keyboard navigation mode.\n */\n focusMode?: \"child\" | \"cell\";\n /**\n * Whether the cell should support arrow key navigation even when the containing collection uses\n * tab keyboard navigation. Allows users to navigate between rows and cells with arrow keys while\n * focus is on an interactive child element within the cell.\n */\n allowsArrowNavigation?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Indicates how many columns the data cell spans. */\n colSpan?: number;\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n *\n * @deprecated\n */\n onAction?: () => void;\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes;\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n *\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function createGridCell<T, C extends GridCollection<T>>(\n props: GridCellProps,\n state: GridState<T, C>,\n ref: Accessor<FocusableElement | null>\n): GridCellAria {\n const _result0 = props;\n const _result1 = createLocale();\n\n const _result2 = requireValue(\n gridMap.get(state),\n \"Expected gridMap.get(state)\"\n );\n\n const focusMode = createMemo(\n () =>\n _result0.focusMode ??\n (_result2.keyboardNavigationBehavior === \"tab\" ? \"cell\" : \"child\")\n );\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused: Key | null = null;\n // Tracks the specific focusable child that was last focused within this cell.\n let lastFocusedChild: FocusableElement | null = null;\n\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n const focus = () => {\n const refElement = ref();\n\n if (refElement) {\n const treeWalker = getFocusableTreeWalker(refElement);\n\n if (focusMode() === \"child\") {\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (isFocusWithin(refElement) && refElement !== activeElement) {\n return;\n }\n\n const ownerDocument = getOwnerDocument(refElement);\n\n const shouldRestoreToLastFocused =\n !activeElement ||\n activeElement === ownerDocument.body ||\n activeElement === refElement;\n\n if (shouldRestoreToLastFocused) {\n const lastChild = lastFocusedChild;\n\n if (\n lastChild &&\n keyWhenFocused === _result0.node.key &&\n nodeContains(refElement, lastChild)\n ) {\n focusSafely(lastChild);\n\n return;\n }\n }\n\n const focusable =\n state.selectionManager.childFocusStrategy === \"last\"\n ? last(treeWalker)\n : focusableElementOrNull(treeWalker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n\n return;\n }\n }\n\n if (\n (isPresent(keyWhenFocused) && _result0.node.key !== keyWhenFocused) ||\n !isFocusWithin(refElement)\n ) {\n focusSafely(refElement);\n }\n }\n };\n\n const _result3 = createSelectableItem({\n get focus() {\n return focus;\n },\n get isDisabled() {\n return state.collection.size === 0;\n },\n get isVirtualized() {\n return _result0.isVirtualized;\n },\n get key() {\n return _result0.node.key;\n },\n get onAction() {\n return _result2.actions.onCellAction\n ? () => _result2.actions.onCellAction?.(_result0.node.key)\n : getLegacyOption(_result0, \"onAction\");\n },\n get ref() {\n return ref;\n },\n get selectionManager() {\n return state.selectionManager;\n },\n get shouldSelectOnPressUp() {\n return _result0.shouldSelectOnPressUp;\n },\n });\n\n function focusLeftInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.nextNode())\n : focusableElementOrNull(walker.previousNode());\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n const prev = _result2.keyboardDelegate.getKeyLeftOf?.(_result0.node.key);\n\n if (prev !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n cell.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"rtl\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.firstChild())\n : last(walker);\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n function focusRightInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.previousNode())\n : focusableElementOrNull(walker.nextNode());\n\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n const next = _result2.keyboardDelegate.getKeyRightOf?.(_result0.node.key);\n\n if (next !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n cell.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"ltr\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? last(walker)\n : focusableElementOrNull(walker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n const handleCaptureKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n const walker = getFocusableTreeWalker(refElement);\n walker.currentNode = activeElement;\n\n switch (e.key) {\n case \"ArrowLeft\": {\n focusLeftInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowRight\": {\n focusRightInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowUp\":\n case \"ArrowDown\": {\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {\n e.stopPropagation();\n e.preventDefault();\n refElement.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n createEvent(\n ref,\n \"keydown\",\n (event) => {\n if (\n _result2.keyboardNavigationBehavior !== \"tab\" ||\n isTruthy(_result0.allowsArrowNavigation)\n ) {\n handleCaptureKeyDown(event);\n }\n },\n { capture: true }\n );\n\n const onKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n if (\n _result2.keyboardNavigationBehavior === \"tab\" &&\n getEventTarget(e) !== refElement &&\n e.key !== \"Tab\"\n ) {\n e.stopPropagation();\n\n return;\n }\n\n switch (e.key) {\n case \"Tab\": {\n if (_result2.keyboardNavigationBehavior === \"tab\") {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n const walker = getFocusableTreeWalker(refElement, {\n tabbable: true,\n });\n\n walker.currentNode = activeElement;\n const next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n\n if (next) {\n e.stopPropagation();\n }\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\n const onFocus = (e: FocusEvent) => {\n keyWhenFocused = _result0.node.key;\n\n if (getEventTarget(e) !== ref()) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the gridcell itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row/cell\n // in that case since the table should act like a single tab stop.\n const target = requireFocusableElement(getEventTarget(e));\n\n if (ref() && nodeContains(ref(), target)) {\n lastFocusedChild = target;\n }\n\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(_result0.node.key);\n }\n\n return;\n }\n\n // if focus goes back to cell from child, make sure we don't refocus the cell if we are in focusMode=child\n // since that would be a focus trap\n if (\n focusMode() === \"child\" &&\n e.relatedTarget &&\n nodeContains(ref(), elementOrNull(e.relatedTarget))\n ) {\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (\n focusMode() === \"child\" &&\n getActiveElement(getOwnerDocument(ref())) === ref()\n ) {\n focus();\n }\n });\n };\n\n const gridCellProps = createMemo(() => {\n const result = mergeProps(_result3.itemProps, {\n \"aria-colindex\": ariaValue(\n isPresent(_result0.node.colIndex)\n ? _result0.node.colIndex + 1\n : undefined\n // aria-colindex is 1-based\n ),\n \"aria-colspan\": ariaValue(_result0.node.colSpan),\n colspan: isTruthy(_result0.isVirtualized)\n ? undefined\n : _result0.node.colSpan,\n onFocus,\n onKeyDown:\n _result2.keyboardNavigationBehavior === \"tab\" ? onKeyDown : undefined,\n role: \"gridcell\",\n\n // make sure shift tabbing from a child of a cell doesnt move focus back to cell if focusMode=\"child\" and in tab nav\n // consistent with arrow nav and focusMode=\"child\" since you can't go back to the cell there either\n });\n\n if (\n focusMode() === \"child\" &&\n _result2.keyboardNavigationBehavior === \"tab\"\n ) {\n result.tabindex = -1;\n }\n\n if (isTruthy(_result0.isVirtualized)) {\n result[\"aria-colindex\"] =\n // aria-colindex is 1-based\n (_result0.node.colIndex ?? _result0.node.index) + 1;\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (\n isTruthy(_result0.shouldSelectOnPressUp) &&\n result.tabindex !== null &&\n result.tabindex !== undefined &&\n !isPresent(result.onPointerDown)\n ) {\n result.onPointerDown = (e) => {\n const el = e.currentTarget;\n const tabindex = el.getAttribute(\"tabindex\");\n el.removeAttribute(\"tabindex\");\n requestAnimationFrame(() => {\n if (isPresent(tabindex)) {\n el.setAttribute(\"tabindex\", tabindex);\n }\n });\n };\n }\n\n return result;\n });\n\n return {\n get gridCellProps() {\n return gridCellProps();\n },\n get isPressed() {\n return _result3.isPressed;\n },\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let lastValue: FocusableElement | null = null;\n\n do {\n lastValue = focusableElementOrNull(walker.lastChild());\n\n if (lastValue) {\n next = lastValue;\n }\n } while (lastValue);\n\n return next;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsG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AS,KAAK,OAAO;GAC/C,SAAS,SAAS,SAAS,aAAa,IACpC,KAAA,IACA,SAAS,KAAK;GAClB;GACA,WACE,SAAS,+BAA+B,QAAQ,YAAY,KAAA;GAC9D,MAAM;EAIR,CAAC;EAED,IACE,UAAU,MAAM,WAChB,SAAS,+BAA+B,OAExC,OAAO,WAAW;EAGpB,IAAI,SAAS,SAAS,aAAa,GACjC,OAAO,oBAEJ,SAAS,KAAK,YAAY,SAAS,KAAK,SAAS;EAOtD,IACE,SAAS,SAAS,qBAAqB,KACvC,OAAO,aAAa,QACpB,OAAO,aAAa,KAAA,KACpB,CAAC,UAAU,OAAO,aAAa,GAE/B,OAAO,iBAAiB,MAAM;GAC5B,MAAM,KAAK,EAAE;GACb,MAAM,WAAW,GAAG,aAAa,UAAU;GAC3C,GAAG,gBAAgB,UAAU;GAC7B,4BAA4B;IAC1B,IAAI,UAAU,QAAQ,GACpB,GAAG,aAAa,YAAY,QAAQ;GAExC,CAAC;EACH;EAGF,OAAO;CACT,CAAC;CAED,OAAO;EACL,IAAI,gBAAgB;GAClB,OAAO,cAAc;EACvB;EACA,IAAI,YAAY;GACd,OAAO,SAAS;EAClB;CACF;AACF;AAEA,SAAS,KAAK,QAAoB;CAChC,IAAI,OAAgC;CACpC,IAAI,YAAqC;CAEzC,GAAG;EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,WACF,OAAO;CAEX,SAAS;CAET,OAAO;AACT"}
1
+ {"version":3,"file":"create-grid-cell.js","names":[],"sources":["../../../src/grid/create-grid-cell.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/grid/useGridCell.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { GridState } from \"@solid2-aria/stately/grid/create-grid-state\";\nimport type {\n IGridCollection as GridCollection,\n GridNode,\n} from \"@solid2-aria/stately/grid/grid-collection\";\nimport type { FocusableElement, Key } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createMemo } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { getFocusableTreeWalker } from \"../focus/focus-scope\";\nimport { createLocale } from \"../i18n/i18n-provider\";\nimport { isFocusVisible } from \"../interactions/create-focus-visible\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport { createSelectableItem } from \"../selection/create-selectable-item\";\nimport type { KeyboardEvent as DOMKeyboardEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { createEvent } from \"../utils/create-event\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport {\n elementOrNull,\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isPresent } from \"../utils/is-present\";\nimport { getLegacyOption } from \"../utils/legacy-option\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { requireValue } from \"../utils/require-value\";\nimport { scrollIntoViewport } from \"../utils/scroll-into-view\";\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { isTruthy } from \"../utils/truthy\";\nimport { gridMap } from \"./utils\";\n\nexport interface GridCellProps {\n /**\n * An object representing the grid cell. Contains all the relevant information that makes up the\n * grid cell.\n */\n node: GridNode<unknown>;\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /**\n * Whether the cell or its first focusable child element should be focused when the grid cell is\n * focused. Defaults to 'child' in arrow keyboard navigation mode and 'cell' in\n * tab keyboard navigation mode.\n */\n focusMode?: \"child\" | \"cell\";\n /**\n * Whether the cell should support arrow key navigation even when the containing collection uses\n * tab keyboard navigation. Allows users to navigate between rows and cells with arrow keys while\n * focus is on an interactive child element within the cell.\n */\n allowsArrowNavigation?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Indicates how many columns the data cell spans. */\n colSpan?: number;\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n *\n * @deprecated\n */\n onAction?: () => void;\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes;\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n *\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function createGridCell<T, C extends GridCollection<T>>(\n props: GridCellProps,\n state: GridState<T, C>,\n ref: Accessor<FocusableElement | null>\n): GridCellAria {\n const _result0 = props;\n const _result1 = createLocale();\n\n const _result2 = requireValue(\n gridMap.get(state),\n \"Expected gridMap.get(state)\"\n );\n\n const focusMode = createMemo(\n () =>\n _result0.focusMode ??\n (_result2.keyboardNavigationBehavior === \"tab\" ? \"cell\" : \"child\")\n );\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused: Key | null = null;\n // Tracks the specific focusable child that was last focused within this cell.\n let lastFocusedChild: FocusableElement | null = null;\n\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n const focus = () => {\n const refElement = ref();\n\n if (refElement) {\n const treeWalker = getFocusableTreeWalker(refElement);\n\n if (focusMode() === \"child\") {\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (isFocusWithin(refElement) && refElement !== activeElement) {\n return;\n }\n\n const ownerDocument = getOwnerDocument(refElement);\n\n const shouldRestoreToLastFocused =\n !activeElement ||\n activeElement === ownerDocument.body ||\n activeElement === refElement;\n\n if (shouldRestoreToLastFocused) {\n const lastChild = lastFocusedChild;\n\n if (\n lastChild &&\n keyWhenFocused === _result0.node.key &&\n nodeContains(refElement, lastChild)\n ) {\n focusSafely(lastChild);\n\n return;\n }\n }\n\n const focusable =\n state.selectionManager.childFocusStrategy === \"last\"\n ? last(treeWalker)\n : focusableElementOrNull(treeWalker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n\n return;\n }\n }\n\n if (\n (isPresent(keyWhenFocused) && _result0.node.key !== keyWhenFocused) ||\n !isFocusWithin(refElement)\n ) {\n focusSafely(refElement);\n }\n }\n };\n\n const _result3 = createSelectableItem({\n get focus() {\n return focus;\n },\n get isDisabled() {\n return state.collection.size === 0;\n },\n get isVirtualized() {\n return _result0.isVirtualized;\n },\n get key() {\n return _result0.node.key;\n },\n get onAction() {\n return _result2.actions.onCellAction\n ? () => _result2.actions.onCellAction?.(_result0.node.key)\n : getLegacyOption(_result0, \"onAction\");\n },\n get ref() {\n return ref;\n },\n get selectionManager() {\n return state.selectionManager;\n },\n get shouldSelectOnPressUp() {\n return _result0.shouldSelectOnPressUp;\n },\n });\n\n function focusLeftInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.nextNode())\n : focusableElementOrNull(walker.previousNode());\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n const prev = _result2.keyboardDelegate.getKeyLeftOf?.(_result0.node.key);\n\n if (prev !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"rtl\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.firstChild())\n : last(walker);\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n function focusRightInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.previousNode())\n : focusableElementOrNull(walker.nextNode());\n\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n const next = _result2.keyboardDelegate.getKeyRightOf?.(_result0.node.key);\n\n if (next !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"ltr\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? last(walker)\n : focusableElementOrNull(walker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n const handleCaptureKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n const walker = getFocusableTreeWalker(refElement);\n walker.currentNode = activeElement;\n\n switch (e.key) {\n case \"ArrowLeft\": {\n focusLeftInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowRight\": {\n focusRightInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowUp\":\n case \"ArrowDown\": {\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {\n e.stopPropagation();\n e.preventDefault();\n getParentElement(refElement)?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n createEvent(\n ref,\n \"keydown\",\n (event) => {\n if (\n _result2.keyboardNavigationBehavior !== \"tab\" ||\n isTruthy(_result0.allowsArrowNavigation)\n ) {\n handleCaptureKeyDown(event);\n }\n },\n { capture: true }\n );\n\n const onKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n if (\n _result2.keyboardNavigationBehavior === \"tab\" &&\n getEventTarget(e) !== refElement &&\n e.key !== \"Tab\"\n ) {\n e.stopPropagation();\n\n return;\n }\n\n switch (e.key) {\n case \"Tab\": {\n if (_result2.keyboardNavigationBehavior === \"tab\") {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n const walker = getFocusableTreeWalker(refElement, {\n tabbable: true,\n });\n\n walker.currentNode = activeElement;\n const next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n\n if (next) {\n e.stopPropagation();\n }\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\n const onFocus = (e: FocusEvent) => {\n keyWhenFocused = _result0.node.key;\n\n if (getEventTarget(e) !== ref()) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the gridcell itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row/cell\n // in that case since the table should act like a single tab stop.\n const target = requireFocusableElement(getEventTarget(e));\n\n if (ref() && nodeContains(ref(), target)) {\n lastFocusedChild = target;\n }\n\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(_result0.node.key);\n }\n\n return;\n }\n\n // if focus goes back to cell from child, make sure we don't refocus the cell if we are in focusMode=child\n // since that would be a focus trap\n if (\n focusMode() === \"child\" &&\n e.relatedTarget &&\n nodeContains(ref(), elementOrNull(e.relatedTarget))\n ) {\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (\n focusMode() === \"child\" &&\n getActiveElement(getOwnerDocument(ref())) === ref()\n ) {\n focus();\n }\n });\n };\n\n const gridCellProps = createMemo(() => {\n const result = mergeProps(_result3.itemProps, {\n \"aria-colindex\": ariaValue(\n isPresent(_result0.node.colIndex)\n ? _result0.node.colIndex + 1\n : undefined\n // aria-colindex is 1-based\n ),\n \"aria-colspan\": ariaValue(_result0.node.colSpan),\n colspan: isTruthy(_result0.isVirtualized)\n ? undefined\n : _result0.node.colSpan,\n onFocus,\n onKeyDown:\n _result2.keyboardNavigationBehavior === \"tab\" ? onKeyDown : undefined,\n role: \"gridcell\",\n\n // make sure shift tabbing from a child of a cell doesnt move focus back to cell if focusMode=\"child\" and in tab nav\n // consistent with arrow nav and focusMode=\"child\" since you can't go back to the cell there either\n });\n\n if (\n focusMode() === \"child\" &&\n _result2.keyboardNavigationBehavior === \"tab\"\n ) {\n result.tabindex = -1;\n }\n\n if (isTruthy(_result0.isVirtualized)) {\n result[\"aria-colindex\"] =\n // aria-colindex is 1-based\n (_result0.node.colIndex ?? _result0.node.index) + 1;\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (\n isTruthy(_result0.shouldSelectOnPressUp) &&\n result.tabindex !== null &&\n result.tabindex !== undefined &&\n !isPresent(result.onPointerDown)\n ) {\n result.onPointerDown = (e) => {\n const el = e.currentTarget;\n const tabindex = el.getAttribute(\"tabindex\");\n el.removeAttribute(\"tabindex\");\n requestAnimationFrame(() => {\n if (isPresent(tabindex)) {\n el.setAttribute(\"tabindex\", tabindex);\n }\n });\n };\n }\n\n return result;\n });\n\n return {\n get gridCellProps() {\n return gridCellProps();\n },\n get isPressed() {\n return _result3.isPressed;\n },\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let lastValue: FocusableElement | null = null;\n\n do {\n lastValue = focusableElementOrNull(walker.lastChild());\n\n if (lastValue) {\n next = lastValue;\n }\n } while (lastValue);\n\n return next;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,eACd,OAC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EN;GACA,gBAAgB,UAAU,SAAS,KAAK,OAAO;GAC/C,SAAS,SAAS,SAAS,aAAa,IACpC,KAAA,IACA,SAAS,KAAK;GAClB;GACA,WACE,SAAS,+BAA+B,QAAQ,YAAY,KAAA;GAC9D,MAAM;EAIR,CAAC;EAED,IACE,UAAU,MAAM,WAChB,SAAS,+BAA+B,OAExC,OAAO,WAAW;EAGpB,IAAI,SAAS,SAAS,aAAa,GACjC,OAAO,oBAEJ,SAAS,KAAK,YAAY,SAAS,KAAK,SAAS;EAOtD,IACE,SAAS,SAAS,qBAAqB,KACvC,OAAO,aAAa,QACpB,OAAO,aAAa,KAAA,KACpB,CAAC,UAAU,OAAO,aAAa,GAE/B,OAAO,iBAAiB,MAAM;GAC5B,MAAM,KAAK,EAAE;GACb,MAAM,WAAW,GAAG,aAAa,UAAU;GAC3C,GAAG,gBAAgB,UAAU;GAC7B,4BAA4B;IAC1B,IAAI,UAAU,QAAQ,GACpB,GAAG,aAAa,YAAY,QAAQ;GAExC,CAAC;EACH;EAGF,OAAO;CACT,CAAC;CAED,OAAO;EACL,IAAI,gBAAgB;GAClB,OAAO,cAAc;EACvB;EACA,IAAI,YAAY;GACd,OAAO,SAAS;EAClB;CACF;AACF;AAEA,SAAS,KAAK,QAAoB;CAChC,IAAI,OAAgC;CACpC,IAAI,YAAqC;CAEzC,GAAG;EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,WACF,OAAO;CAEX,SAAS;CAET,OAAO;AACT"}
@@ -20,7 +20,7 @@ import { createSlotId } from "../utils/create-id.js";
20
20
  import { isPresent } from "../utils/is-present.js";
21
21
  import { mergeProps } from "../utils/merge-props.js";
22
22
  import { getOwnerDocument } from "../utils/dom-helpers.js";
23
- import { getActiveElement, getEventTarget, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
23
+ import { getActiveElement, getEventTarget, getParentElement, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
24
24
  import { elementOrNull, focusableElementOrNull } from "../utils/dom-value.js";
25
25
  import { requireValue } from "../utils/require-value.js";
26
26
  import { isPropagationStopped } from "../utils/is-propagation-stopped.js";
@@ -178,7 +178,7 @@ function createGridListItem(props, state, ref) {
178
178
  case "ArrowDown": if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {
179
179
  e.stopPropagation();
180
180
  e.preventDefault();
181
- refElement.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));
181
+ getParentElement(refElement)?.dispatchEvent(new KeyboardEvent(e.type, e));
182
182
  }
183
183
  }
184
184
  };
@@ -224,7 +224,7 @@ function createGridListItem(props, state, ref) {
224
224
  "aria-labelledby": ariaValue(isTruthy(descriptionId()) && (isTruthy(_result0.node["aria-label"]) || _result0.node.textValue) ? `${getRowId(state, _result0.node.key)} ${descriptionId()}` : void 0),
225
225
  "aria-selected": ariaValue(state.selectionManager.canSelectItem(_result0.node.key) ? state.selectionManager.isSelected(_result0.node.key) : void 0),
226
226
  id: getRowId(state, _result0.node.key),
227
- onFocus,
227
+ onFocusIn: onFocus,
228
228
  role: "row"
229
229
  });
230
230
  if ((_result0.focusMode ?? "row") === "child" && isTruthy(_result0.allowsArrowNavigation) && listData.keyboardNavigationBehavior === "tab") result.tabindex = -1;