@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.
- package/README.md +14 -0
- package/dist/NOTICE.txt +33 -11
- package/dist/browser/actiongroup/create-action-group.js +2 -1
- package/dist/browser/actiongroup/create-action-group.js.map +1 -1
- package/dist/browser/combobox/create-combo-box.js +2 -2
- package/dist/browser/combobox/create-combo-box.js.map +1 -1
- package/dist/browser/dnd/drag-preview.js +7 -8
- package/dist/browser/dnd/drag-preview.js.map +1 -1
- package/dist/browser/focus/focus-scope.js +2 -2
- package/dist/browser/focus/focus-scope.js.map +1 -1
- package/dist/browser/focus/virtual-focus.d.ts +1 -0
- package/dist/browser/focus/virtual-focus.js +20 -5
- package/dist/browser/focus/virtual-focus.js.map +1 -1
- package/dist/browser/grid/create-grid-cell.js +4 -4
- package/dist/browser/grid/create-grid-cell.js.map +1 -1
- package/dist/browser/gridlist/create-grid-list-item.js +3 -3
- package/dist/browser/gridlist/create-grid-list-item.js.map +1 -1
- package/dist/browser/interactions/create-hover.js +6 -3
- package/dist/browser/interactions/create-hover.js.map +1 -1
- package/dist/browser/interactions/create-press.js +5 -4
- package/dist/browser/interactions/create-press.js.map +1 -1
- package/dist/browser/interactions/utils.js +4 -3
- package/dist/browser/interactions/utils.js.map +1 -1
- package/dist/browser/landmark/create-landmark.js +2 -2
- package/dist/browser/landmark/create-landmark.js.map +1 -1
- package/dist/browser/overlays/aria-hide-outside.js +5 -3
- package/dist/browser/overlays/aria-hide-outside.js.map +1 -1
- package/dist/browser/overlays/calculate-position.js +3 -3
- package/dist/browser/overlays/calculate-position.js.map +1 -1
- package/dist/browser/overlays/create-modal.js +15 -18
- package/dist/browser/overlays/create-modal.js.map +1 -1
- package/dist/browser/overlays/create-prevent-scroll.js +3 -3
- package/dist/browser/overlays/create-prevent-scroll.js.map +1 -1
- package/dist/browser/overlays/overlay.js +7 -8
- package/dist/browser/overlays/overlay.js.map +1 -1
- package/dist/browser/select/create-select.js +1 -1
- package/dist/browser/select/create-select.js.map +1 -1
- package/dist/browser/select/hidden-select.js +61 -64
- package/dist/browser/select/hidden-select.js.map +1 -1
- package/dist/browser/selection/create-selectable-item.js +2 -2
- package/dist/browser/selection/create-selectable-item.js.map +1 -1
- package/dist/browser/selection/create-type-select.js +11 -3
- package/dist/browser/selection/create-type-select.js.map +1 -1
- package/dist/browser/selection/list-keyboard-delegate.js +1 -1
- package/dist/browser/selection/list-keyboard-delegate.js.map +1 -1
- package/dist/browser/tokenfield/create-token-field.js +3 -3
- package/dist/browser/tokenfield/create-token-field.js.map +1 -1
- package/dist/browser/tokenfield/create-token.js +2 -1
- package/dist/browser/tokenfield/create-token.js.map +1 -1
- package/dist/browser/toolbar/create-toolbar.js +2 -2
- package/dist/browser/toolbar/create-toolbar.js.map +1 -1
- package/dist/browser/utils/dom-helpers.d.ts +2 -15
- package/dist/browser/utils/dom-helpers.js +1 -28
- package/dist/browser/utils/dom-helpers.js.map +1 -1
- package/dist/browser/utils/dom-value.js +2 -1
- package/dist/browser/utils/dom-value.js.map +1 -1
- package/dist/browser/utils/get-scroll-parent.js +3 -2
- package/dist/browser/utils/get-scroll-parent.js.map +1 -1
- package/dist/browser/utils/get-scroll-parents.js +2 -1
- package/dist/browser/utils/get-scroll-parents.js.map +1 -1
- package/dist/browser/utils/is-element-visible.js +3 -1
- package/dist/browser/utils/is-element-visible.js.map +1 -1
- package/dist/browser/utils/is-focusable.js +2 -1
- package/dist/browser/utils/is-focusable.js.map +1 -1
- package/dist/browser/utils/shadowdom/dom-functions.d.ts +8 -0
- package/dist/browser/utils/shadowdom/dom-functions.js +26 -7
- package/dist/browser/utils/shadowdom/dom-functions.js.map +1 -1
- package/dist/browser/utils/shadowdom/shadow-tree-walker.js +1 -1
- package/dist/browser/utils/shadowdom/shadow-tree-walker.js.map +1 -1
- package/dist/browser/utils/type-helpers.d.ts +42 -0
- package/dist/browser/utils/type-helpers.js +55 -0
- package/dist/browser/utils/type-helpers.js.map +1 -0
- package/dist/server/actiongroup/create-action-group.js +2 -1
- package/dist/server/actiongroup/create-action-group.js.map +1 -1
- package/dist/server/combobox/create-combo-box.js +2 -2
- package/dist/server/combobox/create-combo-box.js.map +1 -1
- package/dist/server/dnd/drag-preview.js +9 -12
- package/dist/server/dnd/drag-preview.js.map +1 -1
- package/dist/server/focus/focus-scope.js +2 -2
- package/dist/server/focus/focus-scope.js.map +1 -1
- package/dist/server/focus/virtual-focus.js +20 -5
- package/dist/server/focus/virtual-focus.js.map +1 -1
- package/dist/server/grid/create-grid-cell.js +4 -4
- package/dist/server/grid/create-grid-cell.js.map +1 -1
- package/dist/server/gridlist/create-grid-list-item.js +3 -3
- package/dist/server/gridlist/create-grid-list-item.js.map +1 -1
- package/dist/server/interactions/create-hover.js +6 -3
- package/dist/server/interactions/create-hover.js.map +1 -1
- package/dist/server/interactions/create-press.js +5 -4
- package/dist/server/interactions/create-press.js.map +1 -1
- package/dist/server/interactions/utils.js +4 -3
- package/dist/server/interactions/utils.js.map +1 -1
- package/dist/server/landmark/create-landmark.js +2 -2
- package/dist/server/landmark/create-landmark.js.map +1 -1
- package/dist/server/overlays/aria-hide-outside.js +5 -3
- package/dist/server/overlays/aria-hide-outside.js.map +1 -1
- package/dist/server/overlays/calculate-position.js +3 -3
- package/dist/server/overlays/calculate-position.js.map +1 -1
- package/dist/server/overlays/create-modal.js +7 -27
- package/dist/server/overlays/create-modal.js.map +1 -1
- package/dist/server/overlays/create-prevent-scroll.js +3 -3
- package/dist/server/overlays/create-prevent-scroll.js.map +1 -1
- package/dist/server/overlays/overlay.js +8 -18
- package/dist/server/overlays/overlay.js.map +1 -1
- package/dist/server/select/create-select.js +1 -1
- package/dist/server/select/create-select.js.map +1 -1
- package/dist/server/select/hidden-select.js +85 -138
- package/dist/server/select/hidden-select.js.map +1 -1
- package/dist/server/selection/create-selectable-item.js +2 -2
- package/dist/server/selection/create-selectable-item.js.map +1 -1
- package/dist/server/selection/create-type-select.js +11 -3
- package/dist/server/selection/create-type-select.js.map +1 -1
- package/dist/server/selection/list-keyboard-delegate.js +1 -1
- package/dist/server/selection/list-keyboard-delegate.js.map +1 -1
- package/dist/server/tokenfield/create-token-field.js +3 -3
- package/dist/server/tokenfield/create-token-field.js.map +1 -1
- package/dist/server/tokenfield/create-token.js +2 -1
- package/dist/server/tokenfield/create-token.js.map +1 -1
- package/dist/server/toolbar/create-toolbar.js +2 -2
- package/dist/server/toolbar/create-toolbar.js.map +1 -1
- package/dist/server/utils/dom-helpers.js +1 -28
- package/dist/server/utils/dom-helpers.js.map +1 -1
- package/dist/server/utils/dom-value.js +2 -1
- package/dist/server/utils/dom-value.js.map +1 -1
- package/dist/server/utils/get-scroll-parent.js +3 -2
- package/dist/server/utils/get-scroll-parent.js.map +1 -1
- package/dist/server/utils/get-scroll-parents.js +2 -1
- package/dist/server/utils/get-scroll-parents.js.map +1 -1
- package/dist/server/utils/is-element-visible.js +3 -1
- package/dist/server/utils/is-element-visible.js.map +1 -1
- package/dist/server/utils/is-focusable.js +2 -1
- package/dist/server/utils/is-focusable.js.map +1 -1
- package/dist/server/utils/shadowdom/dom-functions.js +26 -7
- package/dist/server/utils/shadowdom/dom-functions.js.map +1 -1
- package/dist/server/utils/shadowdom/shadow-tree-walker.js +1 -1
- package/dist/server/utils/shadowdom/shadow-tree-walker.js.map +1 -1
- package/dist/server/utils/type-helpers.js +55 -0
- package/dist/server/utils/type-helpers.js.map +1 -0
- package/dist/server/virtualizer/scroll-view.js +3 -1
- package/dist/server/virtualizer/scroll-view.js.map +1 -1
- package/package.json +16 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hidden-select.js","names":["<Show\n when={props.state.collection.size <= 300}\n fallback={\n <>\n <For each={values().length ? values() : [null]}>\n {(value, index) => (\n <input\n type={\n selectData.get(props.state)?.validationBehavior === \"native\"\n ? \"text\"\n : \"hidden\"\n }\n ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}\n autocomplete={aria.selectProps.autocomplete}\n name={aria.selectProps.name}\n form={aria.selectProps.form}\n disabled={aria.selectProps.disabled}\n value={isPresent(value) ? String(value) : \"\"}\n style={{ display: \"none\" }}\n required={index() === 0 && aria.selectProps.required}\n />\n )}\n </For>\n </>\n }\n >\n <div {...aria.containerProps} data-testid=\"hidden-select-container\">\n <label>\n {props.label}\n <select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>\n </label>\n </div>\n </Show>","<For each={values().length ? values() : [null]}>\n {(value, index) => (\n <input\n type={\n selectData.get(props.state)?.validationBehavior === \"native\"\n ? \"text\"\n : \"hidden\"\n }\n ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}\n autocomplete={aria.selectProps.autocomplete}\n name={aria.selectProps.name}\n form={aria.selectProps.form}\n disabled={aria.selectProps.disabled}\n value={isPresent(value) ? String(value) : \"\"}\n style={{ display: \"none\" }}\n required={index() === 0 && aria.selectProps.required}\n />\n )}\n </For>","values().length ? values() : [null]","ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}","autocomplete={aria.selectProps.autocomplete}","name={aria.selectProps.name}","form={aria.selectProps.form}","disabled={aria.selectProps.disabled}","value={isPresent(value) ? String(value) : \"\"}","required={index() === 0 && aria.selectProps.required}","<option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>","{props.label}","<label>\n {props.label}\n <select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>\n </label>","ref={(node) => {\n setSelectRef(node);\n }}","<For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>","<Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>","{props.state.collection.getItem(key)?.textValue}","defaultSelected={props.state.selectionManager.isSelected(\n key\n )}","selected={props.state.selectionManager.isSelected(key)}","<option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>","<select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>","{whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}","<div {...aria.containerProps} data-testid=\"hidden-select-container\">\n <label>\n {props.label}\n <select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>\n </label>\n </div>","_$createComponent","_$memo","_$getNextElement","_$setAttribute","_$getNextMarker","_$scope","_$setProperty"],"sources":["../../../src/select/hidden-select.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/select/HiddenSelect.tsx.\n * Modified for Solid Aria: adapted components, imports, and reactive lifecycle 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 {\n SelectionMode,\n SelectState,\n} from \"@solid2-aria/stately/select/create-select-state\";\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport type { JSX } from \"@solidjs/web\";\nimport { createSignal, createMemo, For, merge, Show, untrack } from \"solid-js\";\nimport type { Accessor, Element as SolidElement } from \"solid-js\";\n\nimport { createFormValidation } from \"../form/create-form-validation\";\nimport { createFormReset } from \"../utils/create-form-reset\";\nimport { isPresent } from \"../utils/is-present\";\nimport { whenTruthy } from \"../utils/truthy\";\nimport { createVisuallyHidden } from \"../visually-hidden/visually-hidden\";\nimport { selectData } from \"./create-select\";\n\nexport interface AriaHiddenSelectProps {\n autoComplete?: string;\n label?: SolidElement;\n name?: string;\n form?: string;\n isDisabled?: boolean;\n}\n\nexport interface HiddenSelectProps<\n T,\n M extends SelectionMode = \"single\",\n> extends AriaHiddenSelectProps {\n state: SelectState<T, M>;\n triggerRef: Accessor<FocusableElement | null>;\n}\n\nexport interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {\n selectRef?: Accessor<HTMLSelectElement | HTMLInputElement | null>;\n}\n\nexport interface HiddenSelectAria {\n containerProps: JSX.HTMLAttributes<HTMLDivElement> & {\n \"data-react-aria-prevent-focus\": boolean;\n \"data-a11y-ignore\": string;\n };\n inputProps: JSX.InputHTMLAttributes<HTMLInputElement>;\n selectProps: JSX.SelectHTMLAttributes<HTMLSelectElement>;\n}\n\nexport function createHiddenSelect<T, M extends SelectionMode = \"single\">(\n props: AriaHiddenSelectOptions,\n state: SelectState<T, M>,\n triggerRef: Accessor<FocusableElement | null>\n): HiddenSelectAria {\n const data = () => selectData.get(state);\n\n const hidden = createVisuallyHidden({\n style: { left: 0, position: \"fixed\", top: 0 },\n });\n\n createFormReset(\n () => props.selectRef?.() ?? null,\n () => state.defaultValue,\n state.setValue\n );\n createFormValidation(\n {\n focus: () => triggerRef()?.focus(),\n get validationBehavior() {\n return data()?.validationBehavior;\n },\n },\n state,\n props.selectRef\n );\n\n const onChange: JSX.EventHandler<HTMLSelectElement, Event> = (event) => {\n const element = event.currentTarget;\n\n const value = element.multiple\n ? Array.from(element.selectedOptions, (option) => option.value)\n : element.value;\n\n state.setValue(value);\n };\n\n return {\n containerProps:\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n merge(hidden.visuallyHiddenProps, {\n \"aria-hidden\": \"true\",\n \"data-a11y-ignore\": \"aria-hidden-focus\",\n \"data-react-aria-prevent-focus\": true,\n } satisfies HiddenSelectAria[\"containerProps\"]),\n // oxlint-enable solid/reactivity\n inputProps: { style: { display: \"none\" } },\n selectProps: {\n get autocomplete() {\n return props.autoComplete;\n },\n get disabled() {\n return props.isDisabled ?? data()?.isDisabled;\n },\n get form() {\n return props.form ?? data()?.form;\n },\n get multiple() {\n return state.selectionManager.selectionMode === \"multiple\";\n },\n get name() {\n return props.name ?? data()?.name;\n },\n onChange,\n onInput: onChange,\n get required() {\n return data()?.validationBehavior === \"native\" && data()?.isRequired;\n },\n tabindex: -1,\n get value() {\n const { value } = state;\n\n if (Array.isArray(value)) {\n return value.map(String);\n }\n\n if (isPresent(value)) {\n return String(value);\n }\n\n return \"\";\n },\n },\n };\n}\n\nexport function HiddenSelect<T, M extends SelectionMode = \"single\">(\n props: HiddenSelectProps<T, M>\n): SolidElement {\n const [selectRef, setSelectRef] = createSignal<\n HTMLSelectElement | HTMLInputElement | null\n >(null, { ownedWrite: true });\n\n const aria = createHiddenSelect(\n merge(props, { selectRef }),\n untrack(() => props.state),\n untrack(() => props.triggerRef)\n );\n\n const values = createMemo(() => {\n const { value } = props.state;\n\n return Array.isArray(value) ? value : [value];\n });\n\n return (\n <Show\n when={props.state.collection.size <= 300}\n fallback={\n <>\n <For each={values().length ? values() : [null]}>\n {(value, index) => (\n <input\n type={\n selectData.get(props.state)?.validationBehavior === \"native\"\n ? \"text\"\n : \"hidden\"\n }\n ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}\n autocomplete={aria.selectProps.autocomplete}\n name={aria.selectProps.name}\n form={aria.selectProps.form}\n disabled={aria.selectProps.disabled}\n value={isPresent(value) ? String(value) : \"\"}\n style={{ display: \"none\" }}\n required={index() === 0 && aria.selectProps.required}\n />\n )}\n </For>\n </>\n }\n >\n <div {...aria.containerProps} data-testid=\"hidden-select-container\">\n <label>\n {props.label}\n <select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>\n </label>\n </div>\n </Show>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,mBACd,OACA,OACA,YACkB;CAClB,MAAM,aAAa,WAAW,IAAI,KAAK;CAEvC,MAAM,SAAS,qBAAqB,EAClC,OAAO;EAAE,MAAM;EAAG,UAAU;EAAS,KAAK;CAAE,EAC9C,CAAC;CAED,sBACQ,MAAM,YAAY,KAAK,YACvB,MAAM,cACZ,MAAM,QACR;CACA,qBACE;EACE,aAAa,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,GAAA,KAAA,QAAA;OAAkB,YAAA,QAAA,SAAA,CAAA;OAClB,MAAA,KAAA,KAAAW,YAAA,QAAA,mBAAA,CAEC;OACD,YAAA,QAAA,YAAA,CAAsD;MAJpC,CAAA;MAJtB,OAGEV;KASI;;GAEL,CAAA,GAzBPC,OAAAA,MAqCQ;GArCR,OAAA,OA0BEC,YAAAA;IAAC,OAAA,WACC,WAAW,MAAM,MAAM,WAAW,SAAS,SAAS,MAAM,IAAI,SAE5D,OAAO,CAAC,CAAC,KAAK,iBACZ;KAIC,IAAA,SAAAI,eAAA,OAAA;KAFC,YAAA,QAAA,YAAA,IAAO;KADP,aAAO,UAAU,KAAK,IAAI,OAAO,KAAK,IAAI,KAA1C,QAAA;MAA4C,YAAA,QAAA,SAAA,GAAA;;KAD9C,OAAA;IAIC,EAAA,CAAA,CACF,CACL;GAAC,CAAA,GApCHL,QAAAA,MAqCQ;GAxCZ,mBA0CK;GAxEP,OA8BEE;EA2CI;;AAEV"}
|
|
1
|
+
{"version":3,"file":"hidden-select.js","names":["<Show\n when={props.state.collection.size <= 300}\n fallback={\n <>\n <For each={values().length ? values() : [null]}>\n {(value, index) => (\n <input\n type={\n selectData.get(props.state)?.validationBehavior === \"native\"\n ? \"text\"\n : \"hidden\"\n }\n ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}\n autocomplete={aria.selectProps.autocomplete}\n name={aria.selectProps.name}\n form={aria.selectProps.form}\n disabled={aria.selectProps.disabled}\n value={isPresent(value) ? String(value) : \"\"}\n style={{ display: \"none\" }}\n required={index() === 0 && aria.selectProps.required}\n />\n )}\n </For>\n </>\n }\n >\n <div {...aria.containerProps} data-testid=\"hidden-select-container\">\n <label>\n {props.label}\n <select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>\n </label>\n </div>\n </Show>","<option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>","{props.label}","<label>\n {props.label}\n <select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>\n </label>","ref={(node) => {\n setSelectRef(node);\n }}","<For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>","<Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>","{props.state.collection.getItem(key)?.textValue}","defaultSelected={props.state.selectionManager.isSelected(\n key\n )}","selected={props.state.selectionManager.isSelected(key)}","value={String(key)}","<select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>","{whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}","<For each={values().length ? values() : [null]}>\n {(value, index) => (\n <input\n type={\n selectData.get(props.state)?.validationBehavior === \"native\"\n ? \"text\"\n : \"hidden\"\n }\n ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}\n autocomplete={aria.selectProps.autocomplete}\n name={aria.selectProps.name}\n form={aria.selectProps.form}\n disabled={aria.selectProps.disabled}\n value={isPresent(value) ? String(value) : \"\"}\n style={{ display: \"none\" }}\n required={index() === 0 && aria.selectProps.required}\n />\n )}\n </For>","values().length ? values() : [null]","ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}","autocomplete={aria.selectProps.autocomplete}","name={aria.selectProps.name}","form={aria.selectProps.form}","disabled={aria.selectProps.disabled}","value={isPresent(value) ? String(value) : \"\"}","required={index() === 0 && aria.selectProps.required}","type={\n selectData.get(props.state)?.validationBehavior === \"native\"\n ? \"text\"\n : \"hidden\"\n }","_$memo","_$getNextElement","_$getNextMarker","_$scope","_$createComponent","_$heldRead","_$setProperty","_$setAttribute"],"sources":["../../../src/select/hidden-select.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/select/HiddenSelect.tsx.\n * Modified for Solid Aria: adapted components, imports, and reactive lifecycle 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 {\n SelectionMode,\n SelectState,\n} from \"@solid2-aria/stately/select/create-select-state\";\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport type { JSX } from \"@solidjs/web\";\nimport { createSignal, createMemo, For, merge, Show, untrack } from \"solid-js\";\nimport type { Accessor, Element as SolidElement } from \"solid-js\";\n\nimport { createFormValidation } from \"../form/create-form-validation\";\nimport { createFormReset } from \"../utils/create-form-reset\";\nimport { isPresent } from \"../utils/is-present\";\nimport { whenTruthy } from \"../utils/truthy\";\nimport { createVisuallyHidden } from \"../visually-hidden/visually-hidden\";\nimport { selectData } from \"./create-select\";\n\nexport interface AriaHiddenSelectProps {\n autoComplete?: string;\n label?: SolidElement;\n name?: string;\n form?: string;\n isDisabled?: boolean;\n}\n\nexport interface HiddenSelectProps<\n T,\n M extends SelectionMode = \"single\",\n> extends AriaHiddenSelectProps {\n state: SelectState<T, M>;\n triggerRef: Accessor<FocusableElement | null>;\n}\n\nexport interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {\n selectRef?: Accessor<HTMLSelectElement | HTMLInputElement | null>;\n}\n\nexport interface HiddenSelectAria {\n containerProps: JSX.HTMLAttributes<HTMLDivElement> & {\n \"data-react-aria-prevent-focus\": boolean;\n \"data-a11y-ignore\": string;\n };\n inputProps: JSX.InputHTMLAttributes<HTMLInputElement>;\n selectProps: JSX.SelectHTMLAttributes<HTMLSelectElement>;\n}\n\nexport function createHiddenSelect<T, M extends SelectionMode = \"single\">(\n props: AriaHiddenSelectOptions,\n state: SelectState<T, M>,\n triggerRef: Accessor<FocusableElement | null>\n): HiddenSelectAria {\n const data = () => selectData.get(state);\n\n const hidden = createVisuallyHidden({\n style: { left: 0, position: \"fixed\", top: 0 },\n });\n\n createFormReset(\n () => props.selectRef?.() ?? null,\n () => state.defaultValue,\n state.setValue\n );\n createFormValidation(\n {\n focus: () => triggerRef()?.focus(),\n get validationBehavior() {\n return data()?.validationBehavior;\n },\n },\n state,\n props.selectRef\n );\n\n const onChange: JSX.EventHandler<HTMLSelectElement, Event> = (event) => {\n const element = event.currentTarget;\n\n const value = element.multiple\n ? Array.from(element.selectedOptions, (option) => option.value)\n : element.value;\n\n state.setValue(value);\n };\n\n return {\n containerProps:\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n merge(hidden.visuallyHiddenProps, {\n \"aria-hidden\": \"true\",\n \"data-a11y-ignore\": \"aria-hidden-focus\",\n \"data-react-aria-prevent-focus\": true,\n } satisfies HiddenSelectAria[\"containerProps\"]),\n // oxlint-enable solid/reactivity\n inputProps: { style: { display: \"none\" } },\n selectProps: {\n get autocomplete() {\n return props.autoComplete;\n },\n get disabled() {\n return props.isDisabled ?? data()?.isDisabled;\n },\n get form() {\n return props.form ?? data()?.form;\n },\n get multiple() {\n return state.selectionManager.selectionMode === \"multiple\";\n },\n get name() {\n return props.name ?? data()?.name;\n },\n onChange,\n onInput: onChange,\n get required() {\n return data()?.validationBehavior === \"native\" && data()?.isRequired;\n },\n tabindex: -1,\n get value() {\n const { value } = state;\n\n if (Array.isArray(value)) {\n return value.map(String);\n }\n\n if (isPresent(value)) {\n return String(value);\n }\n\n return \"\";\n },\n },\n };\n}\n\nexport function HiddenSelect<T, M extends SelectionMode = \"single\">(\n props: HiddenSelectProps<T, M>\n): SolidElement {\n const [selectRef, setSelectRef] = createSignal<\n HTMLSelectElement | HTMLInputElement | null\n >(null, { ownedWrite: true });\n\n const aria = createHiddenSelect(\n merge(props, { selectRef }),\n untrack(() => props.state),\n untrack(() => props.triggerRef)\n );\n\n const values = createMemo(() => {\n const { value } = props.state;\n\n return Array.isArray(value) ? value : [value];\n });\n\n return (\n <Show\n when={props.state.collection.size <= 300}\n fallback={\n <>\n <For each={values().length ? values() : [null]}>\n {(value, index) => (\n <input\n type={\n selectData.get(props.state)?.validationBehavior === \"native\"\n ? \"text\"\n : \"hidden\"\n }\n ref={(node) => {\n if (index() === 0) {\n setSelectRef(node);\n }\n }}\n autocomplete={aria.selectProps.autocomplete}\n name={aria.selectProps.name}\n form={aria.selectProps.form}\n disabled={aria.selectProps.disabled}\n value={isPresent(value) ? String(value) : \"\"}\n style={{ display: \"none\" }}\n required={index() === 0 && aria.selectProps.required}\n />\n )}\n </For>\n </>\n }\n >\n <div {...aria.containerProps} data-testid=\"hidden-select-container\">\n <label>\n {props.label}\n <select\n {...aria.selectProps}\n ref={(node) => {\n setSelectRef(node);\n }}\n >\n <option value=\"\" label={\"\\u00A0\"}>\n {\"\\u00A0\"}\n </option>\n <For each={[...props.state.collection.getKeys()]}>\n {(key) => (\n <Show\n when={props.state.collection.getItem(key)?.type === \"item\"}\n >\n <option\n value={String(key)}\n defaultSelected={props.state.selectionManager.isSelected(\n key\n )}\n selected={props.state.selectionManager.isSelected(key)}\n >\n {props.state.collection.getItem(key)?.textValue}\n </option>\n </Show>\n )}\n </For>\n {whenTruthy(\n whenTruthy(props.state.collection.size === 0, () => props.name),\n () =>\n values().map((value) => (\n <option\n value={isPresent(value) ? String(value) : \"\"}\n selected\n defaultSelected\n />\n ))\n )}\n </select>\n </label>\n </div>\n </Show>\n );\n}\n"],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CAAC,CAAC;IAAyB,CAAA,CAAC,CAAD,IAAhB,OAAO,IAAI,CAAC,IAAI;GAAC;GAA9CD,WACI,OAAO,iBACP;IAkBC,IAAA,SAAAW,eAAA,OAAA;IAZC,UAAA;KAAM,QAAA,SAAS;MACb,IAAI,MAAM,MAAM,GACd,aAAa,IAAI;KAErB;IAAC,GAJDT,MAIC;IATD,aAAA;;MACE,GAAA,WAAW,IAAI,MAAM,KAAK,CAAC,EAAE,uBAAuB,WAChD,SACA;MAONC,GAAc,KAAK,YAAY;MAC/BC,GAAM,KAAK,YAAY;MACvBC,GAAM,KAAK,YAAY;MACvBC,GAAU,KAAK,YAAY;MAC3BC,GAAO,UAAU,KAAK,IAAI,OAAO,KAAK,IAAI;MAE1CC,GAAU,MAAM,MAAM,KAAK,KAAK,YAAY;MAhB5CC,GAAAA,SAIA;;IAJA,IAAA,EAAA,GAAA,GAAA,GAAA,GAAA,GAAA,GAAA,GAAA,KAAA,QAAA;KAIA,MAAA,KAAA,KAAAQ,aAAA,QAAA,QAAA,CAAA;KAMA,MAAA,KAAA,KAAAA,aAAA,QAAA,gBAAA,CAA2C;KAC3C,MAAA,KAAA,KAAAA,aAAA,QAAA,QAAA,CAA2B;KAC3B,MAAA,KAAA,KAAAA,aAAA,QAAA,QAAA,CAA2B;KAC3B,MAAA,KAAA,KAAAA,aAAA,QAAA,YAAA,CAAmC;KACnC,CAAA,MAAA,KAAA,KAAA,CAAA,MAAAD,YAAA,QAAA,SAAA,CAA4C;KAE5C,MAAA,KAAA,KAAAC,aAAA,QAAA,YAAA,CAAoD;IAZpD,CAAA;IALF,OAAA;GAkBC,EAAA,CAAA;EAEA,CAAA;CA+CL,CAAA;AAEV"}
|
|
@@ -19,7 +19,7 @@ import { chain } from "../utils/chain.js";
|
|
|
19
19
|
import { createId } from "../utils/create-id.js";
|
|
20
20
|
import { isPresent } from "../utils/is-present.js";
|
|
21
21
|
import { mergeProps } from "../utils/merge-props.js";
|
|
22
|
-
import { getActiveElement, getEventTarget } from "../utils/shadowdom/dom-functions.js";
|
|
22
|
+
import { getActiveElement, getEventTarget, getParentElement } from "../utils/shadowdom/dom-functions.js";
|
|
23
23
|
import { elementOrNull } from "../utils/dom-value.js";
|
|
24
24
|
import { isTabbable } from "../utils/is-focusable.js";
|
|
25
25
|
import { requireValue } from "../utils/require-value.js";
|
|
@@ -222,7 +222,7 @@ function createSelectableItem(options) {
|
|
|
222
222
|
while (el && el !== options.ref()) {
|
|
223
223
|
const elCollection = el.attributes.getNamedItem("data-collection")?.value;
|
|
224
224
|
if (isPresent(elCollection)) return elCollection !== collectionId();
|
|
225
|
-
el = el
|
|
225
|
+
el = getParentElement(el);
|
|
226
226
|
}
|
|
227
227
|
return isTabbable(target);
|
|
228
228
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-selectable-item.js","names":[],"sources":["../../../src/selection/create-selectable-item.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/selection/useSelectableItem.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 { MultipleSelectionManager } from \"@solid2-aria/stately/selection/types\";\nimport type {\n DOMProps,\n FocusableElement,\n Key,\n LongPressEvent,\n PointerType,\n PressEvent,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createMemo, createEffect, merge, untrack } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { moveVirtualFocus } from \"../focus/virtual-focus\";\nimport { createLongPress } from \"../interactions/create-long-press\";\nimport { createPress } from \"../interactions/create-press\";\nimport type { PressHookProps } from \"../interactions/create-press\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport { chain } from \"../utils/chain\";\nimport { createEvent } from \"../utils/create-event\";\nimport { createId } from \"../utils/create-id\";\nimport { elementOrNull } from \"../utils/dom-value\";\nimport { getCollectionNodeProps } from \"../utils/get-collection-node-props\";\nimport { isTabbable } from \"../utils/is-focusable\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isCtrlKeyPressed } from \"../utils/keyboard\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { openLink, createRouter } from \"../utils/open-link\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n getActiveElement,\n getEventTarget,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { getCollectionId, isNonContiguousSelectionModifier } from \"./utils\";\n\nexport interface SelectableItemOptions extends DOMProps {\n UNSTABLE_itemBehavior?: \"action\";\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager;\n /**\n * A unique key for the item.\n */\n key: Key;\n /**\n * Ref to the item.\n */\n ref: Accessor<FocusableElement | null>;\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean;\n /**\n * Whether selection requires the pointer/mouse down and up events to occur on the same target or\n * triggers selection on the target of the pointer/mouse up event.\n */\n allowsDifferentPressOrigin?: boolean;\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean;\n /**\n * Function to focus the item.\n */\n focus?: () => void;\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean;\n /** Whether the item is disabled. */\n isDisabled?: boolean;\n /**\n * Handler that is called when a user performs an action on the item. The exact user event depends\n * on the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void;\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).\n *\n * @default 'action'\n */\n linkBehavior?: \"action\" | \"selection\" | \"override\" | \"none\";\n}\n\nexport interface SelectableItemStates {\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean;\n /** Whether the item is currently selected. */\n isSelected: boolean;\n /** Whether the item is currently focused. */\n isFocused: boolean;\n /**\n * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item\n * may not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n */\n isDisabled: boolean;\n /**\n * Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and\n * `disabledBehavior`.\n */\n allowsSelection: boolean;\n /**\n * Whether the item has an action, dependent on `onAction`, `disabledKeys`,\n * and `disabledBehavior`. It may also change depending on the current selection state\n * of the list (e.g. when selection is primary). This can be used to enable or disable hover\n * styles or other visual indications of interactivity.\n */\n hasAction: boolean;\n}\n\nexport interface SelectableItemAria extends SelectableItemStates {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: DOMAttributes & {\n \"data-collection\"?: string;\n \"data-key\"?: Key;\n };\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function createSelectableItem(\n options: SelectableItemOptions\n): SelectableItemAria {\n const id = createId(() => options.id);\n\n const isDisabled = createMemo(\n () =>\n getTruthyValue(options.isDisabled) ??\n options.selectionManager.isDisabled(options.key)\n );\n\n const router = createRouter();\n\n function selectItem(e: PressEvent | LongPressEvent | PointerEvent): void {\n if (options.selectionManager.selectionMode === \"single\") {\n if (\n options.selectionManager.isSelected(options.key) &&\n !isTruthy(options.selectionManager.disallowEmptySelection)\n ) {\n options.selectionManager.toggleSelection(options.key);\n } else {\n options.selectionManager.replaceSelection(options.key);\n }\n } else if (isTruthy(e) && e.shiftKey) {\n options.selectionManager.extendSelection(options.key);\n } else if (\n options.selectionManager.selectionBehavior === \"toggle\" ||\n (isTruthy(e) &&\n (isCtrlKeyPressed(e) ||\n e.pointerType === \"touch\" ||\n e.pointerType === \"virtual\"))\n ) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n options.selectionManager.toggleSelection(options.key);\n } else {\n options.selectionManager.replaceSelection(options.key);\n }\n }\n\n const onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n const optionsrefElement = options.ref();\n\n if (e.pointerType === \"keyboard\" && isNonContiguousSelectionModifier(e)) {\n options.selectionManager.toggleSelection(options.key);\n } else {\n if (options.selectionManager.selectionMode === \"none\") {\n return;\n }\n\n if (options.selectionManager.isLink(options.key)) {\n if (\n (options.linkBehavior ?? \"action\") === \"selection\" &&\n optionsrefElement\n ) {\n const itemProps = getCollectionNodeProps({\n props: options.selectionManager.getItemProps(options.key),\n });\n\n router.open(\n optionsrefElement,\n e,\n requireValue(itemProps.href, \"Expected link href\"),\n itemProps.routerOptions\n );\n // Always set selected keys back to what they were so that select and combobox close.\n options.selectionManager.setSelectedKeys(\n options.selectionManager.selectedKeys\n );\n\n return;\n } else if (\n (options.linkBehavior ?? \"action\") === \"override\" ||\n (options.linkBehavior ?? \"action\") === \"none\"\n ) {\n return;\n }\n }\n\n selectItem(e);\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n createEffect(\n () => ({\n element: options.ref(),\n focusedKey: options.selectionManager.focusedKey,\n input3: options.selectionManager.childFocusStrategy,\n key: options.key,\n observedIsFocused: options.selectionManager.isFocused,\n shouldUseVirtualFocus: options.shouldUseVirtualFocus,\n }),\n ({\n shouldUseVirtualFocus,\n observedIsFocused,\n focusedKey,\n key,\n element,\n }) => {\n const optionsrefElement = element;\n const isFocused = key === focusedKey;\n\n if (isFocused && observedIsFocused) {\n if (isTruthy(shouldUseVirtualFocus)) {\n moveVirtualFocus(optionsrefElement);\n } else if (options.focus) {\n untrack(options.focus);\n } else if (\n getActiveElement() !== optionsrefElement &&\n optionsrefElement\n ) {\n untrack(() => {\n focusSafely(optionsrefElement);\n });\n }\n }\n },\n { ssrSource: \"client\" }\n );\n\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n const itemProps = createMemo<SelectableItemAria[\"itemProps\"]>(() => {\n if (!isTruthy(options.shouldUseVirtualFocus) && !isDisabled()) {\n return {\n onFocus(e) {\n if (getEventTarget(e) === options.ref()) {\n options.selectionManager.setFocusedKey(options.key);\n }\n },\n tabindex: options.key === options.selectionManager.focusedKey ? 0 : -1,\n };\n }\n\n return isDisabled()\n ? {\n onMouseDown: (e) => {\n e.preventDefault();\n },\n }\n : {};\n });\n\n createEffect(\n () => ({\n focusedKey: options.selectionManager.focusedKey,\n isDisabled: isDisabled(),\n key: options.key,\n selectionManager: options.selectionManager,\n }),\n ({ selectionManager, key, focusedKey, isDisabled: currentIsDisabled }) => {\n if (currentIsDisabled && focusedKey === key) {\n selectionManager.setFocusedKey(null);\n }\n },\n { ssrSource: \"client\" }\n );\n\n // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.\n // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.\n // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.\n // With touch, onAction occurs on single tap, and long press enters selection mode.\n const isLinkOverride = createMemo(\n () =>\n options.selectionManager.isLink(options.key) &&\n (options.linkBehavior ?? \"action\") === \"override\"\n );\n\n const isActionOverride = createMemo(\n () => options.onAction && options.UNSTABLE_itemBehavior === \"action\"\n );\n\n const hasLinkAction = createMemo(\n () =>\n options.selectionManager.isLink(options.key) &&\n (options.linkBehavior ?? \"action\") !== \"selection\" &&\n (options.linkBehavior ?? \"action\") !== \"none\"\n );\n\n const allowsSelection = createMemo(\n () =>\n !isDisabled() &&\n options.selectionManager.canSelectItem(options.key) &&\n !isLinkOverride() &&\n !isTruthy(isActionOverride())\n );\n\n const allowsActions = createMemo(\n () => (!!options.onAction || hasLinkAction()) && !isDisabled()\n );\n\n const hasPrimaryAction = createMemo(\n () =>\n allowsActions() &&\n (options.selectionManager.selectionBehavior === \"replace\"\n ? !allowsSelection()\n : !allowsSelection() || options.selectionManager.isEmpty)\n );\n\n const hasSecondaryAction = createMemo(\n () =>\n allowsActions() &&\n allowsSelection() &&\n options.selectionManager.selectionBehavior === \"replace\"\n );\n\n const hasAction = createMemo(\n () => hasPrimaryAction() || hasSecondaryAction()\n );\n\n let modality: PointerType | null = null;\n\n const longPressEnabled = createMemo(() => hasAction() && allowsSelection());\n\n let longPressEnabledOnPressStart = false;\n let hadPrimaryActionOnPressStart = false;\n\n const collectionItemProps = createMemo(() =>\n getCollectionNodeProps({\n props: options.selectionManager.getItemProps(options.key),\n })\n );\n\n const performAction = (\n e: PressEvent | LongPressEvent | globalThis.MouseEvent\n ) => {\n const optionsrefElement = options.ref();\n\n if (options.onAction) {\n options.onAction();\n optionsrefElement?.dispatchEvent(\n new CustomEvent(\"react-aria-item-action\", { bubbles: true })\n );\n }\n\n if (hasLinkAction() && optionsrefElement) {\n router.open(\n optionsrefElement,\n e,\n requireValue(collectionItemProps().href, \"Expected link href\"),\n collectionItemProps().routerOptions\n );\n }\n };\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n const collectionId = createMemo(() =>\n getCollectionId(options.selectionManager.collection)\n );\n\n const pressOptions = createMemo<PressHookProps>(() => {\n let itemPressProps: PressHookProps = { ref: options.ref };\n\n if (isTruthy(options.shouldSelectOnPressUp)) {\n itemPressProps.onPressStart = (e) => {\n untrack(() => {\n modality = e.pointerType;\n longPressEnabledOnPressStart = longPressEnabled();\n\n if (\n e.pointerType === \"keyboard\" &&\n (!hasAction() || isSelectionKey(e.key))\n ) {\n onSelect(e);\n }\n });\n };\n\n // If allowsDifferentPressOrigin and interacting with mouse, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)\n // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)\n if (isTruthy(options.allowsDifferentPressOrigin)) {\n itemPressProps.onPressUp = hasPrimaryAction()\n ? undefined\n : // oxlint-disable-next-line solid/reactivity -- The returned callback runs in its consumer's scope.\n (e) => {\n if (e.pointerType === \"mouse\" && allowsSelection()) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction()\n ? performAction\n : // oxlint-disable-next-line solid/reactivity -- The returned callback runs in its consumer's scope.\n (e) => {\n if (\n e.pointerType !== \"keyboard\" &&\n e.pointerType !== \"mouse\" &&\n allowsSelection()\n ) {\n onSelect(e);\n }\n };\n } else {\n itemPressProps.onPress = (e) => {\n untrack(() => {\n if (\n hasPrimaryAction() ||\n (hasSecondaryAction() && e.pointerType !== \"mouse\")\n ) {\n if (e.pointerType === \"keyboard\" && !isActionKey(e.key)) {\n return;\n }\n\n performAction(e);\n } else if (e.pointerType !== \"keyboard\" && allowsSelection()) {\n onSelect(e);\n }\n });\n };\n }\n } else {\n itemPressProps.onPressStart = (e) => {\n untrack(() => {\n modality = e.pointerType;\n longPressEnabledOnPressStart = longPressEnabled();\n hadPrimaryActionOnPressStart = hasPrimaryAction();\n\n // Select on mouse down unless there is a primary action which will occur on mouse up.\n // For keyboard, select on key down. If there is an action, the Space key selects on key down,\n // and the Enter key performs onAction on key up.\n if (\n allowsSelection() &&\n ((e.pointerType === \"mouse\" && !hasPrimaryAction()) ||\n (e.pointerType === \"keyboard\" &&\n (!allowsActions() || isSelectionKey(e.key))))\n ) {\n onSelect(e);\n }\n });\n };\n\n itemPressProps.onPress = (e) => {\n untrack(() => {\n // Selection occurs on touch up. Primary actions always occur on pointer up.\n // Both primary and secondary actions occur on Enter key up. The only exception\n // is secondary actions, which occur on double click with a mouse.\n if (\n e.pointerType === \"touch\" ||\n e.pointerType === \"pen\" ||\n e.pointerType === \"virtual\" ||\n (e.pointerType === \"keyboard\" &&\n hasAction() &&\n isActionKey(e.key)) ||\n (e.pointerType === \"mouse\" && hadPrimaryActionOnPressStart)\n ) {\n if (hasAction()) {\n performAction(e);\n } else if (allowsSelection()) {\n onSelect(e);\n }\n }\n });\n };\n }\n\n itemPressProps.preventFocusOnPress = options.shouldUseVirtualFocus;\n\n // When using virtual focus, make sure the focused key gets updated on press.\n if (isTruthy(options.shouldUseVirtualFocus)) {\n itemPressProps = mergeProps(itemPressProps, {\n onPress(e: PressEvent) {\n if (e.pointerType === \"touch\") {\n options.selectionManager.setFocused(true);\n options.selectionManager.setFocusedKey(options.key);\n }\n },\n onPressStart(e: PressEvent) {\n if (e.pointerType !== \"touch\") {\n options.selectionManager.setFocused(true);\n options.selectionManager.setFocusedKey(options.key);\n }\n },\n });\n }\n\n if (isTruthy(collectionItemProps())) {\n if (isTruthy(collectionItemProps().onPressStart)) {\n itemPressProps.onPressStart = chain(\n itemPressProps.onPressStart,\n collectionItemProps().onPressStart\n );\n }\n\n if (isTruthy(collectionItemProps().onPressEnd)) {\n itemPressProps.onPressEnd = chain(\n itemPressProps.onPressEnd,\n collectionItemProps().onPressEnd\n );\n }\n\n if (isTruthy(collectionItemProps().onPressChange)) {\n itemPressProps.onPressChange = chain(\n itemPressProps.onPressChange,\n collectionItemProps().onPressChange\n );\n }\n\n if (isTruthy(collectionItemProps().onPress)) {\n itemPressProps.onPress = chain(\n itemPressProps.onPress,\n collectionItemProps().onPress\n );\n }\n\n if (isTruthy(collectionItemProps().onPressUp)) {\n itemPressProps.onPressUp = chain(\n itemPressProps.onPressUp,\n collectionItemProps().onPressUp\n );\n }\n\n if (isTruthy(collectionItemProps().onClick)) {\n itemPressProps.onClick = chain(\n itemPressProps.onClick,\n collectionItemProps().onClick\n );\n }\n }\n\n return itemPressProps;\n });\n\n const _result0 = createPress(merge(pressOptions));\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n const onDblClick = createMemo(() =>\n hasSecondaryAction()\n ? // oxlint-disable-next-line solid/reactivity -- The returned callback runs in its consumer's scope.\n (e: globalThis.MouseEvent) => {\n if (modality === \"mouse\") {\n e.stopPropagation();\n e.preventDefault();\n performAction(e);\n }\n }\n : undefined\n );\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n const _result1 = createLongPress({\n get isDisabled() {\n return !longPressEnabled();\n },\n onLongPress(e) {\n if (e.pointerType === \"touch\") {\n onSelect(e);\n options.selectionManager.setSelectionBehavior(\"toggle\");\n }\n },\n });\n\n // Prevent native drag and drop on long press if we also select on long press.\n // Once the user is in selection mode, they can long press again to drag.\n // Use a capturing listener to ensure this runs before useDrag, regardless of\n // the order the props get merged.\n const onDragStartCapture = (e: globalThis.DragEvent) => {\n if (modality === \"touch\" && longPressEnabledOnPressStart) {\n e.preventDefault();\n }\n };\n\n createEvent(() => options.ref(), \"dragstart\", onDragStartCapture, {\n capture: true,\n });\n\n // Prevent default on link clicks so that we control exactly\n // when they open (to match selection behavior).\n const onClick =\n (options.linkBehavior ?? \"action\") !== \"none\" &&\n options.selectionManager.isLink(options.key)\n ? (e: globalThis.MouseEvent) => {\n if (!isTruthy(openLink.isOpening)) {\n e.preventDefault();\n }\n }\n : undefined;\n\n const isChildInteraction = (target: Element) => {\n let el: Element | null = target;\n\n while (el && el !== options.ref()) {\n const elCollection = el.attributes.getNamedItem(\"data-collection\")?.value;\n\n if (isPresent(elCollection)) {\n return elCollection !== collectionId();\n }\n\n el = el.parentElement;\n }\n\n return isTabbable(target);\n };\n\n const mergedItemProps = createMemo(() => {\n const result = mergeProps(\n itemProps(),\n allowsSelection() ||\n hasPrimaryAction() ||\n (isTruthy(options.shouldUseVirtualFocus) && !isDisabled())\n ? _result0.pressProps\n : {},\n longPressEnabled() ? _result1.longPressProps : {},\n\n {\n \"data-collection\": collectionId(),\n \"data-key\": options.key,\n id: id(),\n onClick,\n onDblClick: onDblClick(),\n },\n // Prevent DOM focus from moving on mouse down when using virtual focus\n isTruthy(options.shouldUseVirtualFocus)\n ? {\n onMouseDown: (e: globalThis.MouseEvent) => {\n e.preventDefault();\n },\n }\n : undefined\n );\n\n // Guard against presses triggering selection when they happen on interactive children or collection items from different collections\n // will need to trigger selection if the target is itself a collection item belonging to the same collection parent (aka a cell in a row) but\n // not if the target is a child of a different collections aka taggroup in table cell.\n const baseOnPointerDown = result.onPointerDown;\n result.onPointerDown = (e) => {\n untrack(() => {\n const target: Element | null = getEventTarget(e);\n\n if (\n isTruthy(target) &&\n target !== options.ref() &&\n isChildInteraction(target)\n ) {\n e.stopPropagation();\n\n return;\n }\n\n baseOnPointerDown?.(e);\n });\n };\n\n const baseOnMouseDown = result.onMouseDown;\n result.onMouseDown = (e) => {\n untrack(() => {\n const target = elementOrNull(getEventTarget(e));\n\n if (\n isTruthy(target) &&\n target !== options.ref() &&\n isChildInteraction(target)\n ) {\n e.stopPropagation();\n\n return;\n }\n\n baseOnMouseDown?.(e);\n });\n };\n\n return result;\n });\n\n return {\n get allowsSelection() {\n return allowsSelection();\n },\n get hasAction() {\n return hasAction();\n },\n get isDisabled() {\n return isDisabled();\n },\n get isFocused() {\n return (\n options.selectionManager.isFocused &&\n options.selectionManager.focusedKey === options.key\n );\n },\n get isPressed() {\n return _result0.isPressed;\n },\n get isSelected() {\n return options.selectionManager.isSelected(options.key);\n },\n get itemProps() {\n return mergedItemProps();\n },\n };\n}\n\nfunction isActionKey(key: string | undefined) {\n return key === \"Enter\";\n}\n\nfunction isSelectionKey(key: string | undefined) {\n return key === \" \";\n}\n"],"mappings":";;;;;;;;;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jB;AAEA,SAAS,eAAe,KAAyB;CAC/C,OAAO,QAAQ;AACjB"}
|
|
1
|
+
{"version":3,"file":"create-selectable-item.js","names":[],"sources":["../../../src/selection/create-selectable-item.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/selection/useSelectableItem.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 { MultipleSelectionManager } from \"@solid2-aria/stately/selection/types\";\nimport type {\n DOMProps,\n FocusableElement,\n Key,\n LongPressEvent,\n PointerType,\n PressEvent,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createMemo, createEffect, merge, untrack } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { moveVirtualFocus } from \"../focus/virtual-focus\";\nimport { createLongPress } from \"../interactions/create-long-press\";\nimport { createPress } from \"../interactions/create-press\";\nimport type { PressHookProps } from \"../interactions/create-press\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport { chain } from \"../utils/chain\";\nimport { createEvent } from \"../utils/create-event\";\nimport { createId } from \"../utils/create-id\";\nimport { elementOrNull } from \"../utils/dom-value\";\nimport { getCollectionNodeProps } from \"../utils/get-collection-node-props\";\nimport { isTabbable } from \"../utils/is-focusable\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isCtrlKeyPressed } from \"../utils/keyboard\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { openLink, createRouter } from \"../utils/open-link\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n getActiveElement,\n getEventTarget,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { getCollectionId, isNonContiguousSelectionModifier } from \"./utils\";\n\nexport interface SelectableItemOptions extends DOMProps {\n UNSTABLE_itemBehavior?: \"action\";\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager;\n /**\n * A unique key for the item.\n */\n key: Key;\n /**\n * Ref to the item.\n */\n ref: Accessor<FocusableElement | null>;\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean;\n /**\n * Whether selection requires the pointer/mouse down and up events to occur on the same target or\n * triggers selection on the target of the pointer/mouse up event.\n */\n allowsDifferentPressOrigin?: boolean;\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean;\n /**\n * Function to focus the item.\n */\n focus?: () => void;\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean;\n /** Whether the item is disabled. */\n isDisabled?: boolean;\n /**\n * Handler that is called when a user performs an action on the item. The exact user event depends\n * on the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void;\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).\n *\n * @default 'action'\n */\n linkBehavior?: \"action\" | \"selection\" | \"override\" | \"none\";\n}\n\nexport interface SelectableItemStates {\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean;\n /** Whether the item is currently selected. */\n isSelected: boolean;\n /** Whether the item is currently focused. */\n isFocused: boolean;\n /**\n * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item\n * may not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n */\n isDisabled: boolean;\n /**\n * Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and\n * `disabledBehavior`.\n */\n allowsSelection: boolean;\n /**\n * Whether the item has an action, dependent on `onAction`, `disabledKeys`,\n * and `disabledBehavior`. It may also change depending on the current selection state\n * of the list (e.g. when selection is primary). This can be used to enable or disable hover\n * styles or other visual indications of interactivity.\n */\n hasAction: boolean;\n}\n\nexport interface SelectableItemAria extends SelectableItemStates {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: DOMAttributes & {\n \"data-collection\"?: string;\n \"data-key\"?: Key;\n };\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function createSelectableItem(\n options: SelectableItemOptions\n): SelectableItemAria {\n const id = createId(() => options.id);\n\n const isDisabled = createMemo(\n () =>\n getTruthyValue(options.isDisabled) ??\n options.selectionManager.isDisabled(options.key)\n );\n\n const router = createRouter();\n\n function selectItem(e: PressEvent | LongPressEvent | PointerEvent): void {\n if (options.selectionManager.selectionMode === \"single\") {\n if (\n options.selectionManager.isSelected(options.key) &&\n !isTruthy(options.selectionManager.disallowEmptySelection)\n ) {\n options.selectionManager.toggleSelection(options.key);\n } else {\n options.selectionManager.replaceSelection(options.key);\n }\n } else if (isTruthy(e) && e.shiftKey) {\n options.selectionManager.extendSelection(options.key);\n } else if (\n options.selectionManager.selectionBehavior === \"toggle\" ||\n (isTruthy(e) &&\n (isCtrlKeyPressed(e) ||\n e.pointerType === \"touch\" ||\n e.pointerType === \"virtual\"))\n ) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n options.selectionManager.toggleSelection(options.key);\n } else {\n options.selectionManager.replaceSelection(options.key);\n }\n }\n\n const onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n const optionsrefElement = options.ref();\n\n if (e.pointerType === \"keyboard\" && isNonContiguousSelectionModifier(e)) {\n options.selectionManager.toggleSelection(options.key);\n } else {\n if (options.selectionManager.selectionMode === \"none\") {\n return;\n }\n\n if (options.selectionManager.isLink(options.key)) {\n if (\n (options.linkBehavior ?? \"action\") === \"selection\" &&\n optionsrefElement\n ) {\n const itemProps = getCollectionNodeProps({\n props: options.selectionManager.getItemProps(options.key),\n });\n\n router.open(\n optionsrefElement,\n e,\n requireValue(itemProps.href, \"Expected link href\"),\n itemProps.routerOptions\n );\n // Always set selected keys back to what they were so that select and combobox close.\n options.selectionManager.setSelectedKeys(\n options.selectionManager.selectedKeys\n );\n\n return;\n } else if (\n (options.linkBehavior ?? \"action\") === \"override\" ||\n (options.linkBehavior ?? \"action\") === \"none\"\n ) {\n return;\n }\n }\n\n selectItem(e);\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n createEffect(\n () => ({\n element: options.ref(),\n focusedKey: options.selectionManager.focusedKey,\n input3: options.selectionManager.childFocusStrategy,\n key: options.key,\n observedIsFocused: options.selectionManager.isFocused,\n shouldUseVirtualFocus: options.shouldUseVirtualFocus,\n }),\n ({\n shouldUseVirtualFocus,\n observedIsFocused,\n focusedKey,\n key,\n element,\n }) => {\n const optionsrefElement = element;\n const isFocused = key === focusedKey;\n\n if (isFocused && observedIsFocused) {\n if (isTruthy(shouldUseVirtualFocus)) {\n moveVirtualFocus(optionsrefElement);\n } else if (options.focus) {\n untrack(options.focus);\n } else if (\n getActiveElement() !== optionsrefElement &&\n optionsrefElement\n ) {\n untrack(() => {\n focusSafely(optionsrefElement);\n });\n }\n }\n },\n { ssrSource: \"client\" }\n );\n\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n const itemProps = createMemo<SelectableItemAria[\"itemProps\"]>(() => {\n if (!isTruthy(options.shouldUseVirtualFocus) && !isDisabled()) {\n return {\n onFocus(e) {\n if (getEventTarget(e) === options.ref()) {\n options.selectionManager.setFocusedKey(options.key);\n }\n },\n tabindex: options.key === options.selectionManager.focusedKey ? 0 : -1,\n };\n }\n\n return isDisabled()\n ? {\n onMouseDown: (e) => {\n e.preventDefault();\n },\n }\n : {};\n });\n\n createEffect(\n () => ({\n focusedKey: options.selectionManager.focusedKey,\n isDisabled: isDisabled(),\n key: options.key,\n selectionManager: options.selectionManager,\n }),\n ({ selectionManager, key, focusedKey, isDisabled: currentIsDisabled }) => {\n if (currentIsDisabled && focusedKey === key) {\n selectionManager.setFocusedKey(null);\n }\n },\n { ssrSource: \"client\" }\n );\n\n // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.\n // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.\n // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.\n // With touch, onAction occurs on single tap, and long press enters selection mode.\n const isLinkOverride = createMemo(\n () =>\n options.selectionManager.isLink(options.key) &&\n (options.linkBehavior ?? \"action\") === \"override\"\n );\n\n const isActionOverride = createMemo(\n () => options.onAction && options.UNSTABLE_itemBehavior === \"action\"\n );\n\n const hasLinkAction = createMemo(\n () =>\n options.selectionManager.isLink(options.key) &&\n (options.linkBehavior ?? \"action\") !== \"selection\" &&\n (options.linkBehavior ?? \"action\") !== \"none\"\n );\n\n const allowsSelection = createMemo(\n () =>\n !isDisabled() &&\n options.selectionManager.canSelectItem(options.key) &&\n !isLinkOverride() &&\n !isTruthy(isActionOverride())\n );\n\n const allowsActions = createMemo(\n () => (!!options.onAction || hasLinkAction()) && !isDisabled()\n );\n\n const hasPrimaryAction = createMemo(\n () =>\n allowsActions() &&\n (options.selectionManager.selectionBehavior === \"replace\"\n ? !allowsSelection()\n : !allowsSelection() || options.selectionManager.isEmpty)\n );\n\n const hasSecondaryAction = createMemo(\n () =>\n allowsActions() &&\n allowsSelection() &&\n options.selectionManager.selectionBehavior === \"replace\"\n );\n\n const hasAction = createMemo(\n () => hasPrimaryAction() || hasSecondaryAction()\n );\n\n let modality: PointerType | null = null;\n\n const longPressEnabled = createMemo(() => hasAction() && allowsSelection());\n\n let longPressEnabledOnPressStart = false;\n let hadPrimaryActionOnPressStart = false;\n\n const collectionItemProps = createMemo(() =>\n getCollectionNodeProps({\n props: options.selectionManager.getItemProps(options.key),\n })\n );\n\n const performAction = (\n e: PressEvent | LongPressEvent | globalThis.MouseEvent\n ) => {\n const optionsrefElement = options.ref();\n\n if (options.onAction) {\n options.onAction();\n optionsrefElement?.dispatchEvent(\n new CustomEvent(\"react-aria-item-action\", { bubbles: true })\n );\n }\n\n if (hasLinkAction() && optionsrefElement) {\n router.open(\n optionsrefElement,\n e,\n requireValue(collectionItemProps().href, \"Expected link href\"),\n collectionItemProps().routerOptions\n );\n }\n };\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n const collectionId = createMemo(() =>\n getCollectionId(options.selectionManager.collection)\n );\n\n const pressOptions = createMemo<PressHookProps>(() => {\n let itemPressProps: PressHookProps = { ref: options.ref };\n\n if (isTruthy(options.shouldSelectOnPressUp)) {\n itemPressProps.onPressStart = (e) => {\n untrack(() => {\n modality = e.pointerType;\n longPressEnabledOnPressStart = longPressEnabled();\n\n if (\n e.pointerType === \"keyboard\" &&\n (!hasAction() || isSelectionKey(e.key))\n ) {\n onSelect(e);\n }\n });\n };\n\n // If allowsDifferentPressOrigin and interacting with mouse, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)\n // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)\n if (isTruthy(options.allowsDifferentPressOrigin)) {\n itemPressProps.onPressUp = hasPrimaryAction()\n ? undefined\n : // oxlint-disable-next-line solid/reactivity -- The returned callback runs in its consumer's scope.\n (e) => {\n if (e.pointerType === \"mouse\" && allowsSelection()) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction()\n ? performAction\n : // oxlint-disable-next-line solid/reactivity -- The returned callback runs in its consumer's scope.\n (e) => {\n if (\n e.pointerType !== \"keyboard\" &&\n e.pointerType !== \"mouse\" &&\n allowsSelection()\n ) {\n onSelect(e);\n }\n };\n } else {\n itemPressProps.onPress = (e) => {\n untrack(() => {\n if (\n hasPrimaryAction() ||\n (hasSecondaryAction() && e.pointerType !== \"mouse\")\n ) {\n if (e.pointerType === \"keyboard\" && !isActionKey(e.key)) {\n return;\n }\n\n performAction(e);\n } else if (e.pointerType !== \"keyboard\" && allowsSelection()) {\n onSelect(e);\n }\n });\n };\n }\n } else {\n itemPressProps.onPressStart = (e) => {\n untrack(() => {\n modality = e.pointerType;\n longPressEnabledOnPressStart = longPressEnabled();\n hadPrimaryActionOnPressStart = hasPrimaryAction();\n\n // Select on mouse down unless there is a primary action which will occur on mouse up.\n // For keyboard, select on key down. If there is an action, the Space key selects on key down,\n // and the Enter key performs onAction on key up.\n if (\n allowsSelection() &&\n ((e.pointerType === \"mouse\" && !hasPrimaryAction()) ||\n (e.pointerType === \"keyboard\" &&\n (!allowsActions() || isSelectionKey(e.key))))\n ) {\n onSelect(e);\n }\n });\n };\n\n itemPressProps.onPress = (e) => {\n untrack(() => {\n // Selection occurs on touch up. Primary actions always occur on pointer up.\n // Both primary and secondary actions occur on Enter key up. The only exception\n // is secondary actions, which occur on double click with a mouse.\n if (\n e.pointerType === \"touch\" ||\n e.pointerType === \"pen\" ||\n e.pointerType === \"virtual\" ||\n (e.pointerType === \"keyboard\" &&\n hasAction() &&\n isActionKey(e.key)) ||\n (e.pointerType === \"mouse\" && hadPrimaryActionOnPressStart)\n ) {\n if (hasAction()) {\n performAction(e);\n } else if (allowsSelection()) {\n onSelect(e);\n }\n }\n });\n };\n }\n\n itemPressProps.preventFocusOnPress = options.shouldUseVirtualFocus;\n\n // When using virtual focus, make sure the focused key gets updated on press.\n if (isTruthy(options.shouldUseVirtualFocus)) {\n itemPressProps = mergeProps(itemPressProps, {\n onPress(e: PressEvent) {\n if (e.pointerType === \"touch\") {\n options.selectionManager.setFocused(true);\n options.selectionManager.setFocusedKey(options.key);\n }\n },\n onPressStart(e: PressEvent) {\n if (e.pointerType !== \"touch\") {\n options.selectionManager.setFocused(true);\n options.selectionManager.setFocusedKey(options.key);\n }\n },\n });\n }\n\n if (isTruthy(collectionItemProps())) {\n if (isTruthy(collectionItemProps().onPressStart)) {\n itemPressProps.onPressStart = chain(\n itemPressProps.onPressStart,\n collectionItemProps().onPressStart\n );\n }\n\n if (isTruthy(collectionItemProps().onPressEnd)) {\n itemPressProps.onPressEnd = chain(\n itemPressProps.onPressEnd,\n collectionItemProps().onPressEnd\n );\n }\n\n if (isTruthy(collectionItemProps().onPressChange)) {\n itemPressProps.onPressChange = chain(\n itemPressProps.onPressChange,\n collectionItemProps().onPressChange\n );\n }\n\n if (isTruthy(collectionItemProps().onPress)) {\n itemPressProps.onPress = chain(\n itemPressProps.onPress,\n collectionItemProps().onPress\n );\n }\n\n if (isTruthy(collectionItemProps().onPressUp)) {\n itemPressProps.onPressUp = chain(\n itemPressProps.onPressUp,\n collectionItemProps().onPressUp\n );\n }\n\n if (isTruthy(collectionItemProps().onClick)) {\n itemPressProps.onClick = chain(\n itemPressProps.onClick,\n collectionItemProps().onClick\n );\n }\n }\n\n return itemPressProps;\n });\n\n const _result0 = createPress(merge(pressOptions));\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n const onDblClick = createMemo(() =>\n hasSecondaryAction()\n ? // oxlint-disable-next-line solid/reactivity -- The returned callback runs in its consumer's scope.\n (e: globalThis.MouseEvent) => {\n if (modality === \"mouse\") {\n e.stopPropagation();\n e.preventDefault();\n performAction(e);\n }\n }\n : undefined\n );\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n const _result1 = createLongPress({\n get isDisabled() {\n return !longPressEnabled();\n },\n onLongPress(e) {\n if (e.pointerType === \"touch\") {\n onSelect(e);\n options.selectionManager.setSelectionBehavior(\"toggle\");\n }\n },\n });\n\n // Prevent native drag and drop on long press if we also select on long press.\n // Once the user is in selection mode, they can long press again to drag.\n // Use a capturing listener to ensure this runs before useDrag, regardless of\n // the order the props get merged.\n const onDragStartCapture = (e: globalThis.DragEvent) => {\n if (modality === \"touch\" && longPressEnabledOnPressStart) {\n e.preventDefault();\n }\n };\n\n createEvent(() => options.ref(), \"dragstart\", onDragStartCapture, {\n capture: true,\n });\n\n // Prevent default on link clicks so that we control exactly\n // when they open (to match selection behavior).\n const onClick =\n (options.linkBehavior ?? \"action\") !== \"none\" &&\n options.selectionManager.isLink(options.key)\n ? (e: globalThis.MouseEvent) => {\n if (!isTruthy(openLink.isOpening)) {\n e.preventDefault();\n }\n }\n : undefined;\n\n const isChildInteraction = (target: Element) => {\n let el: Element | null = target;\n\n while (el && el !== options.ref()) {\n const elCollection = el.attributes.getNamedItem(\"data-collection\")?.value;\n\n if (isPresent(elCollection)) {\n return elCollection !== collectionId();\n }\n\n el = getParentElement(el);\n }\n\n return isTabbable(target);\n };\n\n const mergedItemProps = createMemo(() => {\n const result = mergeProps(\n itemProps(),\n allowsSelection() ||\n hasPrimaryAction() ||\n (isTruthy(options.shouldUseVirtualFocus) && !isDisabled())\n ? _result0.pressProps\n : {},\n longPressEnabled() ? _result1.longPressProps : {},\n\n {\n \"data-collection\": collectionId(),\n \"data-key\": options.key,\n id: id(),\n onClick,\n onDblClick: onDblClick(),\n },\n // Prevent DOM focus from moving on mouse down when using virtual focus\n isTruthy(options.shouldUseVirtualFocus)\n ? {\n onMouseDown: (e: globalThis.MouseEvent) => {\n e.preventDefault();\n },\n }\n : undefined\n );\n\n // Guard against presses triggering selection when they happen on interactive children or collection items from different collections\n // will need to trigger selection if the target is itself a collection item belonging to the same collection parent (aka a cell in a row) but\n // not if the target is a child of a different collections aka taggroup in table cell.\n const baseOnPointerDown = result.onPointerDown;\n result.onPointerDown = (e) => {\n untrack(() => {\n const target: Element | null = getEventTarget(e);\n\n if (\n isTruthy(target) &&\n target !== options.ref() &&\n isChildInteraction(target)\n ) {\n e.stopPropagation();\n\n return;\n }\n\n baseOnPointerDown?.(e);\n });\n };\n\n const baseOnMouseDown = result.onMouseDown;\n result.onMouseDown = (e) => {\n untrack(() => {\n const target = elementOrNull(getEventTarget(e));\n\n if (\n isTruthy(target) &&\n target !== options.ref() &&\n isChildInteraction(target)\n ) {\n e.stopPropagation();\n\n return;\n }\n\n baseOnMouseDown?.(e);\n });\n };\n\n return result;\n });\n\n return {\n get allowsSelection() {\n return allowsSelection();\n },\n get hasAction() {\n return hasAction();\n },\n get isDisabled() {\n return isDisabled();\n },\n get isFocused() {\n return (\n options.selectionManager.isFocused &&\n options.selectionManager.focusedKey === options.key\n );\n },\n get isPressed() {\n return _result0.isPressed;\n },\n get isSelected() {\n return options.selectionManager.isSelected(options.key);\n },\n get itemProps() {\n return mergedItemProps();\n },\n };\n}\n\nfunction isActionKey(key: string | undefined) {\n return key === \"Enter\";\n}\n\nfunction isSelectionKey(key: string | undefined) {\n return key === \" \";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoJA,SAAgB,qBACd,SACoB;CACpB,MAAM,KAAK,eAAe,QAAQ,EAAE;CAEpC,MAAM,aAAa,iBAEf,eAAe,QAAQ,UAAU,KACjC,QAAQ,iBAAiB,WAAW,QAAQ,GAAG,CACnD;CAEA,MAAM,SAAS,aAAa;CAE5B,SAAS,WAAW,GAAqD;EACvE,IAAI,QAAQ,iBAAiB,kBAAkB,UAAU;GACvD,IACE,QAAQ,iBAAiB,WAAW,QAAQ,GAAG,KAC/C,CAAC,SAAS,QAAQ,iBAAiB,sBAAsB,GAEzD,QAAQ,iBAAiB,gBAAgB,QAAQ,GAAG;QAE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M,KACf,WAAW,QAAQ,IAAI,KACvB,mBAAmB,MAAM,GACzB;KACA,EAAE,gBAAgB;KAElB;IACF;IAEA,oBAAoB,CAAC;GACvB,CAAC;EACH;EAEA,MAAM,kBAAkB,OAAO;EAC/B,OAAO,eAAe,MAAM;GAC1B,cAAc;IACZ,MAAM,SAAS,cAAc,eAAe,CAAC,CAAC;IAE9C,IACE,SAAS,MAAM,KACf,WAAW,QAAQ,IAAI,KACvB,mBAAmB,MAAM,GACzB;KACA,EAAE,gBAAgB;KAElB;IACF;IAEA,kBAAkB,CAAC;GACrB,CAAC;EACH;EAEA,OAAO;CACT,CAAC;CAED,OAAO;EACL,IAAI,kBAAkB;GACpB,OAAO,gBAAgB;EACzB;EACA,IAAI,YAAY;GACd,OAAO,UAAU;EACnB;EACA,IAAI,aAAa;GACf,OAAO,WAAW;EACpB;EACA,IAAI,YAAY;GACd,OACE,QAAQ,iBAAiB,aACzB,QAAQ,iBAAiB,eAAe,QAAQ;EAEpD;EACA,IAAI,YAAY;GACd,OAAO,SAAS;EAClB;EACA,IAAI,aAAa;GACf,OAAO,QAAQ,iBAAiB,WAAW,QAAQ,GAAG;EACxD;EACA,IAAI,YAAY;GACd,OAAO,gBAAgB;EACzB;CACF;AACF;AAEA,SAAS,YAAY,KAAyB;CAC5C,OAAO,QAAQ;AACjB;AAEA,SAAS,eAAe,KAAyB;CAC/C,OAAO,QAAQ;AACjB"}
|
|
@@ -30,6 +30,7 @@ const TYPEAHEAD_DEBOUNCE_WAIT_MS = 1e3;
|
|
|
30
30
|
function createTypeSelect(options, ref) {
|
|
31
31
|
const _result0 = options;
|
|
32
32
|
let search = "";
|
|
33
|
+
let startKey = null;
|
|
33
34
|
let timeout;
|
|
34
35
|
const handleCaptureKeyDown = (e) => {
|
|
35
36
|
if (search.length > 0 && e.key === " ") {
|
|
@@ -37,7 +38,7 @@ function createTypeSelect(options, ref) {
|
|
|
37
38
|
if (!("continuePropagation" in e) || "continuePropagation" in e && !isPropagationStopped(e)) e.stopPropagation();
|
|
38
39
|
search += " ";
|
|
39
40
|
if (typeof _result0.keyboardDelegate.getKeyForSearch === "function") {
|
|
40
|
-
let key = _result0.keyboardDelegate.getKeyForSearch(search,
|
|
41
|
+
let key = _result0.keyboardDelegate.getKeyForSearch(search, startKey);
|
|
41
42
|
key ??= _result0.keyboardDelegate.getKeyForSearch(search);
|
|
42
43
|
if (isPresent(key)) {
|
|
43
44
|
_result0.selectionManager.setFocusedKey(key);
|
|
@@ -47,18 +48,23 @@ function createTypeSelect(options, ref) {
|
|
|
47
48
|
clearTimeout(timeout);
|
|
48
49
|
timeout = setTimeout(() => {
|
|
49
50
|
search = "";
|
|
51
|
+
startKey = null;
|
|
50
52
|
}, TYPEAHEAD_DEBOUNCE_WAIT_MS);
|
|
51
53
|
}
|
|
52
54
|
};
|
|
53
55
|
const onKeyDown = (e) => {
|
|
54
56
|
const character = getStringForKey(e.key);
|
|
55
57
|
if (!character || e.ctrlKey || e.metaKey || e.altKey || !nodeContains(e.currentTarget, getEventTarget(e)) || search.length === 0 && character === " ") return;
|
|
56
|
-
search
|
|
58
|
+
if (search === "" || search === character) {
|
|
59
|
+
search = character;
|
|
60
|
+
startKey = _result0.selectionManager.focusedKey;
|
|
61
|
+
} else search += character;
|
|
57
62
|
if (typeof _result0.keyboardDelegate.getKeyForSearch === "function") {
|
|
58
|
-
let key = _result0.keyboardDelegate.getKeyForSearch(search,
|
|
63
|
+
let key = _result0.keyboardDelegate.getKeyForSearch(search, startKey);
|
|
59
64
|
key ??= _result0.keyboardDelegate.getKeyForSearch(search);
|
|
60
65
|
if (!isPresent(key)) {
|
|
61
66
|
search = "";
|
|
67
|
+
startKey = null;
|
|
62
68
|
clearTimeout(timeout);
|
|
63
69
|
timeout = void 0;
|
|
64
70
|
return;
|
|
@@ -71,11 +77,13 @@ function createTypeSelect(options, ref) {
|
|
|
71
77
|
clearTimeout(timeout);
|
|
72
78
|
timeout = setTimeout(() => {
|
|
73
79
|
search = "";
|
|
80
|
+
startKey = null;
|
|
74
81
|
}, TYPEAHEAD_DEBOUNCE_WAIT_MS);
|
|
75
82
|
};
|
|
76
83
|
createEffect(() => options.isDisabled === true, (disabled) => {
|
|
77
84
|
if (disabled) {
|
|
78
85
|
search = "";
|
|
86
|
+
startKey = null;
|
|
79
87
|
clearTimeout(timeout);
|
|
80
88
|
timeout = void 0;
|
|
81
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-type-select.js","names":[],"sources":["../../../src/selection/create-type-select.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/selection/useTypeSelect.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 { MultipleSelectionManager } from \"@solid2-aria/stately/selection/types\";\nimport type { Key, KeyboardDelegate } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createEffect, onSettled } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type { KeyboardEvent } from \"../types\";\nimport { createEvent } from \"../utils/create-event\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isPropagationStopped } from \"../utils/is-propagation-stopped\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\n// 1 second\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000;\n\nexport interface AriaTypeSelectOptions {\n /** Whether typeahead is disabled. */\n isDisabled?: boolean;\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate: KeyboardDelegate;\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager;\n /**\n * Called when an item is focused by typing.\n */\n onTypeSelect?: (key: Key) => void;\n}\n\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function createTypeSelect(\n options: AriaTypeSelectOptions,\n ref: Accessor<HTMLElement | null>\n): TypeSelectAria {\n const _result0 = options;\n\n let search = \"\";\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n const handleCaptureKeyDown = (e: KeyboardEvent) => {\n // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event\n // since we handle this one in a capture phase, we should ignore it in the bubble phase\n if (search.length > 0 && e.key === \" \") {\n e.preventDefault();\n\n if (\n !(\"continuePropagation\" in e) ||\n (\"continuePropagation\" in e && !isPropagationStopped(e))\n ) {\n e.stopPropagation();\n }\n\n search += \" \";\n\n if (typeof _result0.keyboardDelegate.getKeyForSearch === \"function\") {\n // Use the delegate to find a key to focus.\n // Prioritize items after the
|
|
1
|
+
{"version":3,"file":"create-type-select.js","names":[],"sources":["../../../src/selection/create-type-select.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/selection/useTypeSelect.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 { MultipleSelectionManager } from \"@solid2-aria/stately/selection/types\";\nimport type { Key, KeyboardDelegate } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createEffect, onSettled } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type { KeyboardEvent } from \"../types\";\nimport { createEvent } from \"../utils/create-event\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isPropagationStopped } from \"../utils/is-propagation-stopped\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\n// 1 second\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000;\n\nexport interface AriaTypeSelectOptions {\n /** Whether typeahead is disabled. */\n isDisabled?: boolean;\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate: KeyboardDelegate;\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager;\n /**\n * Called when an item is focused by typing.\n */\n onTypeSelect?: (key: Key) => void;\n}\n\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function createTypeSelect(\n options: AriaTypeSelectOptions,\n ref: Accessor<HTMLElement | null>\n): TypeSelectAria {\n const _result0 = options;\n\n let search = \"\";\n let startKey: Key | null = null;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n const handleCaptureKeyDown = (e: KeyboardEvent) => {\n // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event\n // since we handle this one in a capture phase, we should ignore it in the bubble phase\n if (search.length > 0 && e.key === \" \") {\n e.preventDefault();\n\n if (\n !(\"continuePropagation\" in e) ||\n (\"continuePropagation\" in e && !isPropagationStopped(e))\n ) {\n e.stopPropagation();\n }\n\n search += \" \";\n\n if (typeof _result0.keyboardDelegate.getKeyForSearch === \"function\") {\n // Use the delegate to find a key to focus.\n // Prioritize items after the item focused when the search started, falling back to the whole list.\n let key = _result0.keyboardDelegate.getKeyForSearch(search, startKey);\n\n // If no key found, search from the top.\n key ??= _result0.keyboardDelegate.getKeyForSearch(search);\n\n if (isPresent(key)) {\n _result0.selectionManager.setFocusedKey(key);\n\n if (_result0.onTypeSelect) {\n _result0.onTypeSelect(key);\n }\n }\n }\n\n clearTimeout(timeout);\n timeout = setTimeout(() => {\n search = \"\";\n startKey = null;\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n }\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const character = getStringForKey(e.key);\n\n if (\n !character ||\n e.ctrlKey ||\n e.metaKey ||\n e.altKey ||\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n (search.length === 0 && character === \" \")\n ) {\n return;\n }\n\n // Repeated characters cycle through items, matching native browser behavior.\n if (search === \"\" || search === character) {\n search = character;\n startKey = _result0.selectionManager.focusedKey;\n } else {\n search += character;\n }\n\n if (typeof _result0.keyboardDelegate.getKeyForSearch === \"function\") {\n // Use the delegate to find a key to focus.\n // Prioritize items after the item focused when the search started, falling back to the whole list.\n let key = _result0.keyboardDelegate.getKeyForSearch(search, startKey);\n\n key ??= _result0.keyboardDelegate.getKeyForSearch(search);\n\n if (!isPresent(key)) {\n // if still nothing then the type to select is done and everything is reset\n search = \"\";\n startKey = null;\n clearTimeout(timeout);\n timeout = undefined;\n\n return;\n }\n\n _result0.selectionManager.setFocusedKey(key);\n\n if (_result0.onTypeSelect) {\n _result0.onTypeSelect(key);\n }\n\n e.preventDefault();\n\n if (!(\"continuePropagation\" in e)) {\n e.stopPropagation();\n }\n }\n\n clearTimeout(timeout);\n timeout = setTimeout(() => {\n search = \"\";\n startKey = null;\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n };\n\n createEffect(\n () => options.isDisabled === true,\n (disabled) => {\n if (disabled) {\n search = \"\";\n startKey = null;\n clearTimeout(timeout);\n timeout = undefined;\n }\n }\n );\n\n onSettled(() => () => {\n clearTimeout(timeout);\n });\n\n createEvent(\n ref,\n \"keydown\",\n (event) => {\n if (\n _result0.isDisabled !== true &&\n _result0.keyboardDelegate.getKeyForSearch\n ) {\n handleCaptureKeyDown(event);\n }\n },\n { capture: true }\n );\n\n return {\n get typeSelectProps() {\n // other hooks in order to handle the Spacebar event.\n return {\n get onKeyDown() {\n return _result0.isDisabled !== true &&\n _result0.keyboardDelegate.getKeyForSearch\n ? onKeyDown\n : undefined;\n },\n };\n },\n };\n}\n\nfunction getStringForKey(key: string) {\n // If the key is of length 1, it is an ASCII value.\n // Otherwise, if there are no ASCII characters in the key name,\n // it is a Unicode character.\n // See https://www.w3.org/TR/uievents-key/\n if (key.length === 1 || !/^[A-Z]/iu.test(key)) {\n return key;\n }\n\n return \"\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,6BAA6B;;;;AA6BnC,SAAgB,iBACd,SACA,KACgB;CAChB,MAAM,WAAW;CAEjB,IAAI,SAAS;CACb,IAAI,WAAuB;CAC3B,IAAI;CAEJ,MAAM,wBAAwB,MAAqB;EAGjD,IAAI,OAAO,SAAS,KAAK,EAAE,QAAQ,KAAK;GACtC,EAAE,eAAe;GAEjB,IACE,EAAE,yBAAyB,MAC1B,yBAAyB,KAAK,CAAC,qBAAqB,CAAC,GAEtD,EAAE,gBAAgB;GAGpB,UAAU;GAEV,IAAI,OAAO,SAAS,iBAAiB,oBAAoB,YAAY;IAGnE,IAAI,MAAM,SAAS,iBAAiB,gBAAgB,QAAQ,QAAQ;IAGpE,QAAQ,SAAS,iBAAiB,gBAAgB,MAAM;IAExD,IAAI,UAAU,GAAG,GAAG;KAClB,SAAS,iBAAiB,cAAc,GAAG;KAE3C,IAAI,SAAS,cACX,SAAS,aAAa,GAAG;IAE7B;GACF;GAEA,aAAa,OA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O,SAAS,eAAe,QAC7B,SAAS,iBAAiB,kBACxB,YACA,KAAA;EACN,EACF;CACF,EACF;AACF;AAEA,SAAS,gBAAgB,KAAa;CAKpC,IAAI,IAAI,WAAW,KAAK,CAAC,WAAW,KAAK,GAAG,GAC1C,OAAO;CAGT,OAAO;AACT"}
|
|
@@ -206,7 +206,7 @@ var ListKeyboardDelegate = class ListKeyboardDelegate {
|
|
|
206
206
|
getKeyForSearch(search, fromKey) {
|
|
207
207
|
if (!this.collator) return null;
|
|
208
208
|
const { collection } = this;
|
|
209
|
-
let key =
|
|
209
|
+
let key = isPresent(fromKey) ? this.getNextKey(fromKey) : this.getFirstKey();
|
|
210
210
|
while (isPresent(key)) {
|
|
211
211
|
const item = collection.getItem(key);
|
|
212
212
|
if (!item) return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-keyboard-delegate.js","names":[],"sources":["../../../src/selection/list-keyboard-delegate.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/selection/ListKeyboardDelegate.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 {\n Collection,\n Direction,\n DisabledBehavior,\n Key,\n KeyboardDelegate,\n LayoutDelegate,\n Node,\n Orientation,\n Rect,\n} from \"@solid2-aria/types-shared\";\nimport type { Accessor } from \"solid-js\";\n\nimport { getCollectionNodeProps } from \"../utils/get-collection-node-props\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isScrollable } from \"../utils/is-scrollable\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\nimport { DOMLayoutDelegate } from \"./dom-layout-delegate\";\nimport { getItemElement } from \"./utils\";\n\ninterface KeyboardLayoutDelegate extends LayoutDelegate {\n getKeyRightOf?: (key: Key) => Key | null;\n getKeyLeftOf?: (key: Key) => Key | null;\n}\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>;\n ref: Accessor<HTMLElement | null>;\n collator?: Intl.Collator;\n layout?: \"stack\" | \"grid\";\n orientation?: Orientation;\n direction?: Direction;\n disabledKeys?: Set<Key>;\n disabledBehavior?: DisabledBehavior;\n layoutDelegate?: KeyboardLayoutDelegate;\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private readonly collection: Collection<Node<T>>;\n private readonly disabledKeys: Set<Key>;\n private readonly disabledBehavior: DisabledBehavior;\n private readonly ref: Accessor<HTMLElement | null>;\n private readonly collator: Intl.Collator | undefined;\n private readonly layout: \"stack\" | \"grid\";\n private readonly orientation?: Orientation;\n private readonly direction?: Direction;\n private readonly layoutDelegate: KeyboardLayoutDelegate;\n constructor(\n collection: Collection<Node<T>>,\n disabledKeys: Set<Key>,\n ref: Accessor<HTMLElement | null>,\n collator?: Intl.Collator,\n expandedKeys?: Set<Key>\n );\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(\n ...args:\n | [options: ListKeyboardDelegateOptions<T>]\n | [\n collection: Collection<Node<T>>,\n disabledKeys: Set<Key>,\n ref: Accessor<HTMLElement | null>,\n collator?: Intl.Collator,\n expandedKeys?: Set<Key>,\n ]\n ) {\n if (args.length === 1) {\n const [opts] = args;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = getTruthyValue(opts.disabledKeys) ?? new Set();\n this.disabledBehavior = getTruthyValue(opts.disabledBehavior) ?? \"all\";\n this.orientation = getTruthyValue(opts.orientation) ?? \"vertical\";\n this.direction = opts.direction;\n this.layout = getTruthyValue(opts.layout) ?? \"stack\";\n this.layoutDelegate =\n getTruthyValue(opts.layoutDelegate) ?? new DOMLayoutDelegate(opts.ref);\n } else {\n [this.collection, this.disabledKeys, this.ref, this.collator] = args;\n this.layout = \"stack\";\n this.orientation = \"vertical\";\n this.disabledBehavior = \"all\";\n this.layoutDelegate = new DOMLayoutDelegate(this.ref);\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === \"stack\" && this.orientation === \"vertical\") {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n private isDisabled(item: Node<unknown>) {\n return whenTruthy(\n whenTruthy(\n this.disabledBehavior === \"all\",\n () =>\n getTruthyValue(getCollectionNodeProps(item)?.isDisabled) ??\n this.disabledKeys.has(item.key)\n ),\n () => getCollectionNodeProps(item)?.disabledBehavior !== \"selection\"\n );\n }\n private findNextNonDisabled(\n key: Key | null,\n getNext: (key: Key) => Key | null,\n includeDisabled = false\n ): Key | null {\n let nextKey = key;\n\n while (isPresent(nextKey)) {\n const item = this.collection.getItem(nextKey);\n\n if (\n item?.type === \"item\" &&\n (includeDisabled || !isTruthy(this.isDisabled(item)))\n ) {\n return nextKey;\n }\n\n nextKey = getNext(nextKey);\n }\n\n return null;\n }\n getNextKey(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyAfter(nextKey);\n\n return this.findNextNonDisabled(\n nextKey,\n (keyValue) => this.collection.getKeyAfter(keyValue),\n options?.includeDisabled\n );\n }\n getPreviousKey(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyBefore(nextKey);\n\n return this.findNextNonDisabled(\n nextKey,\n (keyValue2) => this.collection.getKeyBefore(keyValue2),\n options?.includeDisabled\n );\n }\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key | null,\n shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean\n ) {\n let tempKey: Key | null = key;\n let itemRect = this.layoutDelegate.getItemRect(tempKey);\n\n if (!itemRect || tempKey === null || tempKey === undefined) {\n return null;\n }\n\n // Find the item above or below in the same column.\n const prevRect = itemRect;\n\n do {\n tempKey = nextKey(tempKey);\n\n if (!isPresent(tempKey)) {\n break;\n }\n\n itemRect = this.layoutDelegate.getItemRect(tempKey);\n } while (\n itemRect &&\n shouldSkip(prevRect, itemRect) &&\n tempKey !== null &&\n tempKey !== undefined\n );\n\n return tempKey;\n }\n private static isSameRow(prevRect: Rect, itemRect: Rect) {\n return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;\n }\n private static isSameColumn(prevRect: Rect, itemRect: Rect) {\n return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;\n }\n // checks to see if the next/prev key is spatially above/below the current key. If not, that means we are in\n // a reversed column layout and need to adjust appropriately\n // Follow-up: still need to see how this works with virtualizer once there is handling for the reverse layout\n // this felt like a simpler approach then changing getKeyAbove/Below to be purely spatial calculations\n private isReversed(key: Key): boolean {\n const nextKey = this.getNextKey(key);\n const currentEl = getItemElement(this.ref, key);\n\n if (isPresent(nextKey)) {\n const nextEl = getItemElement(this.ref, nextKey);\n\n if (!currentEl || !nextEl) {\n return false;\n }\n\n return (\n currentEl.getBoundingClientRect().top >\n nextEl.getBoundingClientRect().top\n );\n }\n\n const prevKey = this.getPreviousKey(key);\n\n if (isPresent(prevKey)) {\n const prevEl = getItemElement(this.ref, prevKey);\n\n if (!currentEl || !prevEl) {\n return false;\n }\n\n return (\n prevEl.getBoundingClientRect().top >\n currentEl.getBoundingClientRect().top\n );\n }\n\n return false;\n }\n getKeyBelow(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n if (this.layout === \"grid\" && this.orientation === \"vertical\") {\n return this.findKey(\n key,\n (keyValue3) => this.getNextKey(keyValue3, options),\n (prev, item) => ListKeyboardDelegate.isSameRow(prev, item)\n );\n } else if (this.orientation === \"vertical\") {\n return this.isReversed(key)\n ? this.getPreviousKey(key, options)\n : this.getNextKey(key, options);\n }\n\n return this.getNextKey(key, options);\n }\n getKeyAbove(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n if (this.layout === \"grid\" && this.orientation === \"vertical\") {\n return this.findKey(\n key,\n (keyValue4) => this.getPreviousKey(keyValue4, options),\n (prev, item) => ListKeyboardDelegate.isSameRow(prev, item)\n );\n } else if (this.orientation === \"vertical\") {\n return this.isReversed(key)\n ? this.getNextKey(key, options)\n : this.getPreviousKey(key, options);\n }\n\n return this.getPreviousKey(key, options);\n }\n private getNextColumn(\n key: Key,\n right: boolean,\n options?: {\n includeDisabled?: boolean;\n }\n ) {\n return right\n ? this.getPreviousKey(key, options)\n : this.getNextKey(key, options);\n }\n getKeyRightOf?(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n // This is a temporary solution for CardView until we refactor useSelectableCollection.\n // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042\n const layoutDelegateMethod: \"getKeyRightOf\" | \"getKeyLeftOf\" =\n this.direction === \"ltr\" ? \"getKeyRightOf\" : \"getKeyLeftOf\";\n\n const method = this.layoutDelegate[layoutDelegateMethod];\n\n if (method) {\n const nextKey = method.call(this.layoutDelegate, key);\n\n return isPresent(nextKey)\n ? this.findNextNonDisabled(\n nextKey,\n (keyValue5) => method.call(this.layoutDelegate, keyValue5),\n options?.includeDisabled\n )\n : null;\n }\n\n if (this.layout === \"grid\") {\n if (this.orientation === \"vertical\") {\n return this.getNextColumn(key, this.direction === \"rtl\", options);\n }\n\n return this.findKey(\n key,\n (keyValue6) =>\n this.getNextColumn(keyValue6, this.direction === \"rtl\", options),\n (prev, item) => ListKeyboardDelegate.isSameColumn(prev, item)\n );\n } else if (this.orientation === \"horizontal\") {\n return this.getNextColumn(key, this.direction === \"rtl\", options);\n }\n\n return null;\n }\n getKeyLeftOf?(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n const layoutDelegateMethod: \"getKeyRightOf\" | \"getKeyLeftOf\" =\n this.direction === \"ltr\" ? \"getKeyLeftOf\" : \"getKeyRightOf\";\n\n const method = this.layoutDelegate[layoutDelegateMethod];\n\n if (method) {\n const nextKey = method.call(this.layoutDelegate, key);\n\n return isPresent(nextKey)\n ? this.findNextNonDisabled(\n nextKey,\n (keyValue7) => method.call(this.layoutDelegate, keyValue7),\n options?.includeDisabled\n )\n : null;\n }\n\n if (this.layout === \"grid\") {\n if (this.orientation === \"vertical\") {\n return this.getNextColumn(key, this.direction === \"ltr\", options);\n }\n\n return this.findKey(\n key,\n (keyValue8) =>\n this.getNextColumn(keyValue8, this.direction === \"ltr\", options),\n (prev, item) => ListKeyboardDelegate.isSameColumn(prev, item)\n );\n } else if (this.orientation === \"horizontal\") {\n return this.getNextColumn(key, this.direction === \"ltr\", options);\n }\n\n return null;\n }\n getFirstKey(): Key | null {\n const key = this.collection.getFirstKey();\n\n return this.findNextNonDisabled(key, (keyValue9) =>\n this.collection.getKeyAfter(keyValue9)\n );\n }\n getLastKey(): Key | null {\n const key = this.collection.getLastKey();\n\n return this.findNextNonDisabled(key, (keyValue10) =>\n this.collection.getKeyBefore(keyValue10)\n );\n }\n getKeyPageAbove(key: Key): Key | null {\n const menu = this.ref();\n let itemRect = this.layoutDelegate.getItemRect(key);\n\n if (!itemRect) {\n return null;\n }\n\n const reversed = this.isReversed(key);\n\n if (menu && !isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let nextKey: Key | null = key;\n\n if (this.orientation === \"horizontal\") {\n const pageX = Math.max(\n 0,\n itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width\n );\n\n while (\n itemRect &&\n itemRect.x > pageX &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n } else {\n const visibleRect = this.layoutDelegate.getVisibleRect();\n\n // column reverse makes y negative for items so we need to instead do current pos - height instead\n const pageY = reversed\n ? itemRect.y - visibleRect.height\n : Math.max(0, itemRect.y + itemRect.height - visibleRect.height);\n\n while (\n itemRect &&\n itemRect.y > pageY &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n }\n\n return nextKey ?? (reversed ? this.getLastKey() : this.getFirstKey());\n }\n getKeyPageBelow(key: Key): Key | null {\n const menu = this.ref();\n let itemRect = this.layoutDelegate.getItemRect(key);\n\n if (!itemRect) {\n return null;\n }\n\n const reversed = this.isReversed(key);\n\n if (menu && !isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let nextKey: Key | null = key;\n\n if (this.orientation === \"horizontal\") {\n const pageX = Math.min(\n this.layoutDelegate.getContentSize().width,\n itemRect.x - itemRect.width + this.layoutDelegate.getVisibleRect().width\n );\n\n while (\n itemRect &&\n itemRect.x < pageX &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n } else {\n const pageY = Math.min(\n this.layoutDelegate.getContentSize().height,\n itemRect.y -\n itemRect.height +\n this.layoutDelegate.getVisibleRect().height\n );\n\n while (\n itemRect &&\n itemRect.y < pageY &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n }\n\n return nextKey ?? (reversed ? this.getFirstKey() : this.getLastKey());\n }\n getKeyForSearch(search: string, fromKey?: Key): Key | null {\n if (!this.collator) {\n return null;\n }\n\n const { collection } = this;\n let key = getTruthyValue(fromKey) ?? this.getFirstKey();\n\n while (isPresent(key)) {\n const item = collection.getItem(key);\n\n if (!item) {\n return null;\n }\n\n const substring = item.textValue.slice(0, search.length);\n\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getNextKey(key);\n }\n\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsDA,IAAa,uBAAb,MAAa,qBAAoD;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CASA,YACE,GAAG,MASH;EACA,IAAI,KAAK,WAAW,GAAG;GACrB,MAAM,CAAC,QAAQ;GACf,KAAK,aAAa,KAAK;GACvB,KAAK,MAAM,KAAK;GAChB,KAAK,WAAW,KAAK;GACrB,KAAK,eAAe,eAAe,KAAK,YAAY,qBAAK,IAAI,IAAI;GACjE,KAAK,mBAAmB,eAAe,KAAK,gBAAgB,KAAK;GACjE,KAAK,cAAc,eAAe,KAAK,WAAW,KAAK;GACvD,KAAK,YAAY,KAAK;GACtB,KAAK,SAAS,eAAe,KAAK,MAAM,KAAK;GAC7C,KAAK,iBACH,eAAe,KAAK,cAAc,KAAK,IAAI,kBAAkB,KAAK,GAAG;EACzE,OAAO;GACL,CAAC,KAAK,YAAY,KAAK,cAAc,KAAK,KAAK,KAAK,YAAY;GAChE,KAAK,SAAS;GACd,KAAK,cAAc;GACnB,KAAK,mBAAmB;GACxB,KAAK,iBAAiB,IAAI,kBAAkB,KAAK,GAAG;EACtD;EAIA,IAAI,KAAK,WAAW,WAAW,KAAK,gBAAgB,YAAY;GAC9D,KAAK,eAAe,KAAA;GACpB,KAAK,gBAAgB,KAAA;EACvB;CACF;CACA,WAAmB,MAAqB;EACtC,OAAO,WACL,WACE,KAAK,qBAAqB,aAExB,eAAe,uBAAuB,IAAI,CAAC,EAAE,UAAU,KACvD,KAAK,aAAa,IAAI,KAAK,GAAG,CAClC,SACM,uBAAuB,IAAI,CAAC,EAAE,qBAAqB,WAC3D;CACF;CACA,oBACE,KACA,SACA,kBAAkB,OACN;EACZ,IAAI,U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yboard-delegate.js","names":[],"sources":["../../../src/selection/list-keyboard-delegate.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/selection/ListKeyboardDelegate.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 {\n Collection,\n Direction,\n DisabledBehavior,\n Key,\n KeyboardDelegate,\n LayoutDelegate,\n Node,\n Orientation,\n Rect,\n} from \"@solid2-aria/types-shared\";\nimport type { Accessor } from \"solid-js\";\n\nimport { getCollectionNodeProps } from \"../utils/get-collection-node-props\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isScrollable } from \"../utils/is-scrollable\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\nimport { DOMLayoutDelegate } from \"./dom-layout-delegate\";\nimport { getItemElement } from \"./utils\";\n\ninterface KeyboardLayoutDelegate extends LayoutDelegate {\n getKeyRightOf?: (key: Key) => Key | null;\n getKeyLeftOf?: (key: Key) => Key | null;\n}\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>;\n ref: Accessor<HTMLElement | null>;\n collator?: Intl.Collator;\n layout?: \"stack\" | \"grid\";\n orientation?: Orientation;\n direction?: Direction;\n disabledKeys?: Set<Key>;\n disabledBehavior?: DisabledBehavior;\n layoutDelegate?: KeyboardLayoutDelegate;\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private readonly collection: Collection<Node<T>>;\n private readonly disabledKeys: Set<Key>;\n private readonly disabledBehavior: DisabledBehavior;\n private readonly ref: Accessor<HTMLElement | null>;\n private readonly collator: Intl.Collator | undefined;\n private readonly layout: \"stack\" | \"grid\";\n private readonly orientation?: Orientation;\n private readonly direction?: Direction;\n private readonly layoutDelegate: KeyboardLayoutDelegate;\n constructor(\n collection: Collection<Node<T>>,\n disabledKeys: Set<Key>,\n ref: Accessor<HTMLElement | null>,\n collator?: Intl.Collator,\n expandedKeys?: Set<Key>\n );\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(\n ...args:\n | [options: ListKeyboardDelegateOptions<T>]\n | [\n collection: Collection<Node<T>>,\n disabledKeys: Set<Key>,\n ref: Accessor<HTMLElement | null>,\n collator?: Intl.Collator,\n expandedKeys?: Set<Key>,\n ]\n ) {\n if (args.length === 1) {\n const [opts] = args;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = getTruthyValue(opts.disabledKeys) ?? new Set();\n this.disabledBehavior = getTruthyValue(opts.disabledBehavior) ?? \"all\";\n this.orientation = getTruthyValue(opts.orientation) ?? \"vertical\";\n this.direction = opts.direction;\n this.layout = getTruthyValue(opts.layout) ?? \"stack\";\n this.layoutDelegate =\n getTruthyValue(opts.layoutDelegate) ?? new DOMLayoutDelegate(opts.ref);\n } else {\n [this.collection, this.disabledKeys, this.ref, this.collator] = args;\n this.layout = \"stack\";\n this.orientation = \"vertical\";\n this.disabledBehavior = \"all\";\n this.layoutDelegate = new DOMLayoutDelegate(this.ref);\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === \"stack\" && this.orientation === \"vertical\") {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n private isDisabled(item: Node<unknown>) {\n return whenTruthy(\n whenTruthy(\n this.disabledBehavior === \"all\",\n () =>\n getTruthyValue(getCollectionNodeProps(item)?.isDisabled) ??\n this.disabledKeys.has(item.key)\n ),\n () => getCollectionNodeProps(item)?.disabledBehavior !== \"selection\"\n );\n }\n private findNextNonDisabled(\n key: Key | null,\n getNext: (key: Key) => Key | null,\n includeDisabled = false\n ): Key | null {\n let nextKey = key;\n\n while (isPresent(nextKey)) {\n const item = this.collection.getItem(nextKey);\n\n if (\n item?.type === \"item\" &&\n (includeDisabled || !isTruthy(this.isDisabled(item)))\n ) {\n return nextKey;\n }\n\n nextKey = getNext(nextKey);\n }\n\n return null;\n }\n getNextKey(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyAfter(nextKey);\n\n return this.findNextNonDisabled(\n nextKey,\n (keyValue) => this.collection.getKeyAfter(keyValue),\n options?.includeDisabled\n );\n }\n getPreviousKey(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyBefore(nextKey);\n\n return this.findNextNonDisabled(\n nextKey,\n (keyValue2) => this.collection.getKeyBefore(keyValue2),\n options?.includeDisabled\n );\n }\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key | null,\n shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean\n ) {\n let tempKey: Key | null = key;\n let itemRect = this.layoutDelegate.getItemRect(tempKey);\n\n if (!itemRect || tempKey === null || tempKey === undefined) {\n return null;\n }\n\n // Find the item above or below in the same column.\n const prevRect = itemRect;\n\n do {\n tempKey = nextKey(tempKey);\n\n if (!isPresent(tempKey)) {\n break;\n }\n\n itemRect = this.layoutDelegate.getItemRect(tempKey);\n } while (\n itemRect &&\n shouldSkip(prevRect, itemRect) &&\n tempKey !== null &&\n tempKey !== undefined\n );\n\n return tempKey;\n }\n private static isSameRow(prevRect: Rect, itemRect: Rect) {\n return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;\n }\n private static isSameColumn(prevRect: Rect, itemRect: Rect) {\n return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;\n }\n // checks to see if the next/prev key is spatially above/below the current key. If not, that means we are in\n // a reversed column layout and need to adjust appropriately\n // Follow-up: still need to see how this works with virtualizer once there is handling for the reverse layout\n // this felt like a simpler approach then changing getKeyAbove/Below to be purely spatial calculations\n private isReversed(key: Key): boolean {\n const nextKey = this.getNextKey(key);\n const currentEl = getItemElement(this.ref, key);\n\n if (isPresent(nextKey)) {\n const nextEl = getItemElement(this.ref, nextKey);\n\n if (!currentEl || !nextEl) {\n return false;\n }\n\n return (\n currentEl.getBoundingClientRect().top >\n nextEl.getBoundingClientRect().top\n );\n }\n\n const prevKey = this.getPreviousKey(key);\n\n if (isPresent(prevKey)) {\n const prevEl = getItemElement(this.ref, prevKey);\n\n if (!currentEl || !prevEl) {\n return false;\n }\n\n return (\n prevEl.getBoundingClientRect().top >\n currentEl.getBoundingClientRect().top\n );\n }\n\n return false;\n }\n getKeyBelow(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n if (this.layout === \"grid\" && this.orientation === \"vertical\") {\n return this.findKey(\n key,\n (keyValue3) => this.getNextKey(keyValue3, options),\n (prev, item) => ListKeyboardDelegate.isSameRow(prev, item)\n );\n } else if (this.orientation === \"vertical\") {\n return this.isReversed(key)\n ? this.getPreviousKey(key, options)\n : this.getNextKey(key, options);\n }\n\n return this.getNextKey(key, options);\n }\n getKeyAbove(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n if (this.layout === \"grid\" && this.orientation === \"vertical\") {\n return this.findKey(\n key,\n (keyValue4) => this.getPreviousKey(keyValue4, options),\n (prev, item) => ListKeyboardDelegate.isSameRow(prev, item)\n );\n } else if (this.orientation === \"vertical\") {\n return this.isReversed(key)\n ? this.getNextKey(key, options)\n : this.getPreviousKey(key, options);\n }\n\n return this.getPreviousKey(key, options);\n }\n private getNextColumn(\n key: Key,\n right: boolean,\n options?: {\n includeDisabled?: boolean;\n }\n ) {\n return right\n ? this.getPreviousKey(key, options)\n : this.getNextKey(key, options);\n }\n getKeyRightOf?(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n // This is a temporary solution for CardView until we refactor useSelectableCollection.\n // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042\n const layoutDelegateMethod: \"getKeyRightOf\" | \"getKeyLeftOf\" =\n this.direction === \"ltr\" ? \"getKeyRightOf\" : \"getKeyLeftOf\";\n\n const method = this.layoutDelegate[layoutDelegateMethod];\n\n if (method) {\n const nextKey = method.call(this.layoutDelegate, key);\n\n return isPresent(nextKey)\n ? this.findNextNonDisabled(\n nextKey,\n (keyValue5) => method.call(this.layoutDelegate, keyValue5),\n options?.includeDisabled\n )\n : null;\n }\n\n if (this.layout === \"grid\") {\n if (this.orientation === \"vertical\") {\n return this.getNextColumn(key, this.direction === \"rtl\", options);\n }\n\n return this.findKey(\n key,\n (keyValue6) =>\n this.getNextColumn(keyValue6, this.direction === \"rtl\", options),\n (prev, item) => ListKeyboardDelegate.isSameColumn(prev, item)\n );\n } else if (this.orientation === \"horizontal\") {\n return this.getNextColumn(key, this.direction === \"rtl\", options);\n }\n\n return null;\n }\n getKeyLeftOf?(\n key: Key,\n options?: {\n includeDisabled?: boolean;\n }\n ): Key | null {\n const layoutDelegateMethod: \"getKeyRightOf\" | \"getKeyLeftOf\" =\n this.direction === \"ltr\" ? \"getKeyLeftOf\" : \"getKeyRightOf\";\n\n const method = this.layoutDelegate[layoutDelegateMethod];\n\n if (method) {\n const nextKey = method.call(this.layoutDelegate, key);\n\n return isPresent(nextKey)\n ? this.findNextNonDisabled(\n nextKey,\n (keyValue7) => method.call(this.layoutDelegate, keyValue7),\n options?.includeDisabled\n )\n : null;\n }\n\n if (this.layout === \"grid\") {\n if (this.orientation === \"vertical\") {\n return this.getNextColumn(key, this.direction === \"ltr\", options);\n }\n\n return this.findKey(\n key,\n (keyValue8) =>\n this.getNextColumn(keyValue8, this.direction === \"ltr\", options),\n (prev, item) => ListKeyboardDelegate.isSameColumn(prev, item)\n );\n } else if (this.orientation === \"horizontal\") {\n return this.getNextColumn(key, this.direction === \"ltr\", options);\n }\n\n return null;\n }\n getFirstKey(): Key | null {\n const key = this.collection.getFirstKey();\n\n return this.findNextNonDisabled(key, (keyValue9) =>\n this.collection.getKeyAfter(keyValue9)\n );\n }\n getLastKey(): Key | null {\n const key = this.collection.getLastKey();\n\n return this.findNextNonDisabled(key, (keyValue10) =>\n this.collection.getKeyBefore(keyValue10)\n );\n }\n getKeyPageAbove(key: Key): Key | null {\n const menu = this.ref();\n let itemRect = this.layoutDelegate.getItemRect(key);\n\n if (!itemRect) {\n return null;\n }\n\n const reversed = this.isReversed(key);\n\n if (menu && !isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let nextKey: Key | null = key;\n\n if (this.orientation === \"horizontal\") {\n const pageX = Math.max(\n 0,\n itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width\n );\n\n while (\n itemRect &&\n itemRect.x > pageX &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n } else {\n const visibleRect = this.layoutDelegate.getVisibleRect();\n\n // column reverse makes y negative for items so we need to instead do current pos - height instead\n const pageY = reversed\n ? itemRect.y - visibleRect.height\n : Math.max(0, itemRect.y + itemRect.height - visibleRect.height);\n\n while (\n itemRect &&\n itemRect.y > pageY &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n }\n\n return nextKey ?? (reversed ? this.getLastKey() : this.getFirstKey());\n }\n getKeyPageBelow(key: Key): Key | null {\n const menu = this.ref();\n let itemRect = this.layoutDelegate.getItemRect(key);\n\n if (!itemRect) {\n return null;\n }\n\n const reversed = this.isReversed(key);\n\n if (menu && !isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let nextKey: Key | null = key;\n\n if (this.orientation === \"horizontal\") {\n const pageX = Math.min(\n this.layoutDelegate.getContentSize().width,\n itemRect.x - itemRect.width + this.layoutDelegate.getVisibleRect().width\n );\n\n while (\n itemRect &&\n itemRect.x < pageX &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n } else {\n const pageY = Math.min(\n this.layoutDelegate.getContentSize().height,\n itemRect.y -\n itemRect.height +\n this.layoutDelegate.getVisibleRect().height\n );\n\n while (\n itemRect &&\n itemRect.y < pageY &&\n nextKey !== null &&\n nextKey !== undefined\n ) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = isPresent(nextKey)\n ? this.layoutDelegate.getItemRect(nextKey)\n : null;\n }\n }\n\n return nextKey ?? (reversed ? this.getFirstKey() : this.getLastKey());\n }\n getKeyForSearch(search: string, fromKey?: Key): Key | null {\n if (!this.collator) {\n return null;\n }\n\n const { collection } = this;\n\n let key = isPresent(fromKey)\n ? this.getNextKey(fromKey)\n : this.getFirstKey();\n\n while (isPresent(key)) {\n const item = collection.getItem(key);\n\n if (!item) {\n return null;\n }\n\n const substring = item.textValue.slice(0, search.length);\n\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getNextKey(key);\n }\n\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsDA,IAAa,uBAAb,MAAa,qBAAoD;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CASA,YACE,GAAG,MASH;EACA,IAAI,KAAK,WAAW,GAAG;GACrB,MAAM,CAAC,QAAQ;GACf,KAAK,aAAa,KAAK;GACvB,KAAK,MAAM,KAAK;GAChB,KAAK,WAAW,KAAK;GACrB,KAAK,eAAe,eAAe,KAAK,YAAY,qBAAK,IAAI,IAAI;GACjE,KAAK,mBAAmB,eAAe,KAAK,gBAAgB,KA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,SACT,KAAK,eAAe,eAAe,CAAC,CAAC,MACzC;GAEA,OACE,YACA,SAAS,IAAI,SACb,YAAY,QACZ,YAAY,KAAA,GACZ;IACA,UAAU,KAAK,YAAY,OAAO;IAClC,WAAW,UAAU,OAAO,IACxB,KAAK,eAAe,YAAY,OAAO,IACvC;GACN;EACF;EAEA,OAAO,YAAY,WAAW,KAAK,YAAY,IAAI,KAAK,WAAW;CACrE;CACA,gBAAgB,QAAgB,SAA2B;EACzD,IAAI,CAAC,KAAK,UACR,OAAO;EAGT,MAAM,EAAE,eAAe;EAEvB,IAAI,MAAM,UAAU,OAAO,IACvB,KAAK,WAAW,OAAO,IACvB,KAAK,YAAY;EAErB,OAAO,UAAU,GAAG,GAAG;GACrB,MAAM,OAAO,WAAW,QAAQ,GAAG;GAEnC,IAAI,CAAC,MACH,OAAO;GAGT,MAAM,YAAY,KAAK,UAAU,MAAM,GAAG,OAAO,MAAM;GAEvD,IAAI,KAAK,aAAa,KAAK,SAAS,QAAQ,WAAW,MAAM,MAAM,GACjE,OAAO;GAGT,MAAM,KAAK,WAAW,GAAG;EAC3B;EAEA,OAAO;CACT;AACF"}
|
|
@@ -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, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
21
|
+
import { getActiveElement, getParentNode, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
22
22
|
import { requireHTMLElement } from "../utils/dom-value.js";
|
|
23
23
|
import { requireValue } from "../utils/require-value.js";
|
|
24
24
|
import { isMac } from "../utils/platform.js";
|
|
@@ -388,7 +388,7 @@ function getPosition(container, node, offset, isRangeEnd = false) {
|
|
|
388
388
|
offset: 0
|
|
389
389
|
};
|
|
390
390
|
const originalNode = currentNode;
|
|
391
|
-
while (currentNode
|
|
391
|
+
while (getParentNode(currentNode) !== container) currentNode = requireValue(getParentNode(currentNode), "Expected node.parentNode");
|
|
392
392
|
const index = indexOfNode(currentNode);
|
|
393
393
|
if (currentNode.nodeType === Node.ELEMENT_NODE) return getTokenPosition(currentNode, originalNode, currentOffset, isRangeEnd, index);
|
|
394
394
|
return {
|
|
@@ -593,7 +593,7 @@ function getCaretRect(root, range) {
|
|
|
593
593
|
} else if (isPresent(root.firstChild)) {
|
|
594
594
|
let nextSibling = node === root ? null : node.nextSibling;
|
|
595
595
|
while (node && node !== root && !nextSibling) {
|
|
596
|
-
node = node
|
|
596
|
+
node = getParentNode(node);
|
|
597
597
|
nextSibling = node && node !== root ? node.nextSibling : null;
|
|
598
598
|
}
|
|
599
599
|
if (nextSibling?.nodeType === Node.ELEMENT_NODE) rect = requireHTMLElement(nextSibling).getBoundingClientRect();
|