@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
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
import { isTruthy } from "../utils/truthy.js";
|
|
18
18
|
import { requireValue } from "../utils/require-value.js";
|
|
19
19
|
import { createUNSAFE_PortalContext } from "./portal-provider.js";
|
|
20
|
-
import { Portal, createComponent, getNextElement, mergeProps, runHydrationEvents, spread, template } from "@solidjs/web";
|
|
21
|
-
import {
|
|
20
|
+
import { Portal, createComponent, getNextElement, memo, mergeProps, runHydrationEvents, spread, template } from "@solidjs/web";
|
|
21
|
+
import { createContext, createEffect, createMemo, createSignal, omit, onSettled, useContext } from "solid-js";
|
|
22
22
|
// src/overlays/create-modal.tsx
|
|
23
23
|
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
24
24
|
const Context = createContext(null);
|
|
@@ -79,22 +79,19 @@ function OverlayContainer(props) {
|
|
|
79
79
|
createEffect(container, (element) => {
|
|
80
80
|
if (element?.closest("[data-overlay-container]")) throw new Error("An OverlayContainer must not be inside another container. Please change the portalContainer prop.");
|
|
81
81
|
}, { ssrSource: "client" });
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
return container();
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
82
|
+
return memo(() => {
|
|
83
|
+
return memo(() => {
|
|
84
|
+
return !!container();
|
|
85
|
+
})() ? createComponent(Portal, {
|
|
86
|
+
get mount() {
|
|
87
|
+
return requireValue(container(), "Expected container()");
|
|
88
|
+
},
|
|
89
|
+
get children() {
|
|
90
|
+
return createComponent(OverlayProvider, mergeProps(() => {
|
|
91
|
+
return omit(props, "portalContainer");
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
}) : void 0;
|
|
98
95
|
});
|
|
99
96
|
}
|
|
100
97
|
function createModal(options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-modal.js","names":["<Context value={context}>{props.children}</Context>","value={context}","<div data-overlay-container {...props} {...aria.modalProviderProps} />","<ModalProvider>\n <OverlayContainerDOM {...props} />\n </ModalProvider>","<OverlayContainerDOM {...props} />","<Show when={container()}>\n <Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>\n </Show>","<Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>","<OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />","_$createComponent","_$getNextElement","_$mergeProps"],"sources":["../../../src/overlays/create-modal.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/overlays/useModal.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 { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { Portal } from \"@solidjs/web\";\nimport {\n createContext,\n createEffect,\n createMemo,\n createSignal,\n onSettled,\n omit,\n useContext,\n Show,\n} from \"solid-js\";\nimport type { Element as SolidElement } from \"solid-js\";\n\nimport type { AriaAttributes } from \"../types\";\nimport { requireValue } from \"../utils/require-value\";\nimport { isTruthy } from \"../utils/truthy\";\nimport { createUNSAFE_PortalContext } from \"./portal-provider\";\n\nexport interface ModalProviderProps extends DOMAttributes {\n children?: SolidElement;\n}\n\ninterface ModalContextValue {\n parent: ModalContextValue | null;\n modalCount: number;\n addModal: () => void;\n removeModal: () => void;\n}\n\nconst Context = createContext<ModalContextValue | null>(null);\n\nexport function ModalProvider(props: ModalProviderProps): SolidElement {\n const parent = useContext(Context);\n const [modalCount, setModalCount] = createSignal(0);\n\n const context = {\n addModal() {\n setModalCount((count) => count + 1);\n parent?.addModal();\n },\n get modalCount() {\n return modalCount();\n },\n parent,\n removeModal() {\n setModalCount((count) => count - 1);\n parent?.removeModal();\n },\n };\n\n return <Context value={context}>{props.children}</Context>;\n}\n\nexport interface ModalProviderAria {\n modalProviderProps: AriaAttributes;\n}\n\nexport function createModalProvider(): ModalProviderAria {\n const context = useContext(Context);\n\n return {\n modalProviderProps: {\n get \"aria-hidden\"() {\n return context && context.modalCount > 0 ? \"true\" : undefined;\n },\n },\n };\n}\n\nfunction OverlayContainerDOM(props: ModalProviderProps): SolidElement {\n const aria = createModalProvider();\n\n return <div data-overlay-container {...props} {...aria.modalProviderProps} />;\n}\n\nexport function OverlayProvider(props: ModalProviderProps): SolidElement {\n return (\n <ModalProvider>\n <OverlayContainerDOM {...props} />\n </ModalProvider>\n );\n}\n\nexport interface OverlayContainerProps extends ModalProviderProps {\n portalContainer?: Element;\n}\n\nexport function OverlayContainer(props: OverlayContainerProps): SolidElement {\n const [mounted, setMounted] = createSignal(false);\n onSettled(() => {\n setMounted(true);\n });\n const portal = createUNSAFE_PortalContext();\n\n const container = createMemo(\n () =>\n props.portalContainer ??\n portal.getContainer?.() ??\n (mounted() ? document.body : null)\n );\n\n createEffect(\n container,\n (element) => {\n if (element?.closest(\"[data-overlay-container]\")) {\n throw new Error(\n \"An OverlayContainer must not be inside another container. Please change the portalContainer prop.\"\n );\n }\n },\n { ssrSource: \"client\" }\n );\n\n return (\n <Show when={container()}>\n <Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>\n </Show>\n );\n}\n\ninterface ModalAriaProps extends DOMAttributes {\n \"data-ismodal\": boolean;\n}\n\nexport interface AriaModalOptions {\n isDisabled?: boolean;\n}\n\nexport interface ModalAria {\n modalProps: ModalAriaProps;\n}\n\nexport function createModal(options: AriaModalOptions = {}): ModalAria {\n const context = useContext(Context);\n\n if (!context) {\n throw new Error(\"Modal is not contained within a provider\");\n }\n\n createEffect(\n () => options.isDisabled,\n (disabled): undefined | (() => void) => {\n if (isTruthy(disabled) || !context.parent) {\n return undefined;\n }\n\n context.parent.addModal();\n\n return () => context.parent?.removeModal();\n },\n { ssrSource: \"client\" }\n );\n\n return {\n modalProps: {\n get \"data-ismodal\"() {\n return !isTruthy(options.isDisabled);\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,UAAU,cAAwC,IAAI;AAE5D,SAAgB,cAAc,OAAyC;CACrE,MAAM,SAAS,WAAW,OAAO;CACjC,MAAM,CAAC,YAAY,iBAAiB,aAAa,CAAC;CAiBlD,OAAOA,gBAAAA,SAAAA;EAASC,OAAO;GAdrB,WAAW;IACT,eAAe,UAAU,QAAQ,CAAC;IAClC,QAAQ,SAAS;GACnB;GACA,IAAI,aAAa;IACf,OAAO,WAAW;GACpB;GACA;GACA,cAAc;IACZ,eAAe,UAAU,QAAQ,CAAC;IAClC,QAAQ,YAAY;GACtB;EAGqB;EAAhB,IAAA,WAAA;GAA0B,OAAA,MAAM;EAAkB;;AAC3D;AAMA,SAAgB,sBAAyC;CACvD,MAAM,UAAU,WAAW,OAAO;CAElC,OAAO,EACL,oBAAoB,EAClB,IAAI,gBAAgB;EAClB,OAAO,WAAW,QAAQ,aAAa,IAAI,SAAS,KAAA;CACtD,EACF,EACF;AACF;AAEA,SAAS,oBAAoB,OAAyC;CACpE,MAAM,OAAO,oBAAoB;CAE1B,IAAA,OAAAQ,eAAA,MAAqE;;EAAzC,EAAvB,0BAAA,KAAgC;EAAL;QAAO;GAAI,OAAA,KAAK;EAAkB;;CAAlE,mBAAqE;CAA5E,OAAOP;AACT;AAEA,SAAgB,gBAAgB,OAAyC;CACvE,OACEC,gBAAAA,eAAAA,EAAAA,IAAAA,WAAAA;EACEC,OAAAA,gBAAAA,qBAAyB,KAAQ;CACpB,EAAA,CAAA;AAEnB;AAMA,SAAgB,iBAAiB,OAA4C;CAC3E,MAAM,CAAC,SAAS,cAAc,aAAa,KAAK;CAChD,gBAAgB;EACd,WAAW,IAAI;CACjB,CAAC;CACD,MAAM,SAAS,2BAA2B;CAE1C,MAAM,YAAY,iBAEd,MAAM,mBACN,OAAO,eAAe,MACrB,QAAQ,IAAI,SAAS,OAAO,KACjC;CAEA,aACE,YACC,YAAY;EACX,IAAI,SAAS,QAAQ,0BAA0B,GAC7C,MAAM,IAAI,MACR,mGACF;CAEJ,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OACEC,
|
|
1
|
+
{"version":3,"file":"create-modal.js","names":["<Context value={context}>{props.children}</Context>","value={context}","<div data-overlay-container {...props} {...aria.modalProviderProps} />","<ModalProvider>\n <OverlayContainerDOM {...props} />\n </ModalProvider>","<OverlayContainerDOM {...props} />","<Show when={container()}>\n <Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>\n </Show>","<Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>","<OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />","_$createComponent","_$getNextElement","_$memo","_$mergeProps"],"sources":["../../../src/overlays/create-modal.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/overlays/useModal.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 { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { Portal } from \"@solidjs/web\";\nimport {\n createContext,\n createEffect,\n createMemo,\n createSignal,\n onSettled,\n omit,\n useContext,\n Show,\n} from \"solid-js\";\nimport type { Element as SolidElement } from \"solid-js\";\n\nimport type { AriaAttributes } from \"../types\";\nimport { requireValue } from \"../utils/require-value\";\nimport { isTruthy } from \"../utils/truthy\";\nimport { createUNSAFE_PortalContext } from \"./portal-provider\";\n\nexport interface ModalProviderProps extends DOMAttributes {\n children?: SolidElement;\n}\n\ninterface ModalContextValue {\n parent: ModalContextValue | null;\n modalCount: number;\n addModal: () => void;\n removeModal: () => void;\n}\n\nconst Context = createContext<ModalContextValue | null>(null);\n\nexport function ModalProvider(props: ModalProviderProps): SolidElement {\n const parent = useContext(Context);\n const [modalCount, setModalCount] = createSignal(0);\n\n const context = {\n addModal() {\n setModalCount((count) => count + 1);\n parent?.addModal();\n },\n get modalCount() {\n return modalCount();\n },\n parent,\n removeModal() {\n setModalCount((count) => count - 1);\n parent?.removeModal();\n },\n };\n\n return <Context value={context}>{props.children}</Context>;\n}\n\nexport interface ModalProviderAria {\n modalProviderProps: AriaAttributes;\n}\n\nexport function createModalProvider(): ModalProviderAria {\n const context = useContext(Context);\n\n return {\n modalProviderProps: {\n get \"aria-hidden\"() {\n return context && context.modalCount > 0 ? \"true\" : undefined;\n },\n },\n };\n}\n\nfunction OverlayContainerDOM(props: ModalProviderProps): SolidElement {\n const aria = createModalProvider();\n\n return <div data-overlay-container {...props} {...aria.modalProviderProps} />;\n}\n\nexport function OverlayProvider(props: ModalProviderProps): SolidElement {\n return (\n <ModalProvider>\n <OverlayContainerDOM {...props} />\n </ModalProvider>\n );\n}\n\nexport interface OverlayContainerProps extends ModalProviderProps {\n portalContainer?: Element;\n}\n\nexport function OverlayContainer(props: OverlayContainerProps): SolidElement {\n const [mounted, setMounted] = createSignal(false);\n onSettled(() => {\n setMounted(true);\n });\n const portal = createUNSAFE_PortalContext();\n\n const container = createMemo(\n () =>\n props.portalContainer ??\n portal.getContainer?.() ??\n (mounted() ? document.body : null)\n );\n\n createEffect(\n container,\n (element) => {\n if (element?.closest(\"[data-overlay-container]\")) {\n throw new Error(\n \"An OverlayContainer must not be inside another container. Please change the portalContainer prop.\"\n );\n }\n },\n { ssrSource: \"client\" }\n );\n\n return (\n <Show when={container()}>\n <Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>\n </Show>\n );\n}\n\ninterface ModalAriaProps extends DOMAttributes {\n \"data-ismodal\": boolean;\n}\n\nexport interface AriaModalOptions {\n isDisabled?: boolean;\n}\n\nexport interface ModalAria {\n modalProps: ModalAriaProps;\n}\n\nexport function createModal(options: AriaModalOptions = {}): ModalAria {\n const context = useContext(Context);\n\n if (!context) {\n throw new Error(\"Modal is not contained within a provider\");\n }\n\n createEffect(\n () => options.isDisabled,\n (disabled): undefined | (() => void) => {\n if (isTruthy(disabled) || !context.parent) {\n return undefined;\n }\n\n context.parent.addModal();\n\n return () => context.parent?.removeModal();\n },\n { ssr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Ae,MACrB,QAAQ,IAAI,SAAS,OAAO,KACjC;CAEA,aACE,YACC,YAAY;EACX,IAAI,SAAS,QAAQ,0BAA0B,GAC7C,MAAM,IAAI,MACR,mGACF;CAEJ,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OACEC,WAAAA;;GAAY,OAAA,CAAA,CAAA,UAAU;EAUhB,CAAA,CAAC,CAAD,IATJC,gBAAAA,QAAAA;GAAQ,IAAA,QAAA;IAAO,OAAA,aAAa,UAAU,GAAG,sBAAsB;GAAC;GAAhE,IAAA,WAAA;IACEC,OAAAA,gBAAAA,iBAAAA,iBACE;KAEK,OAAA,KAAK,OAAO,iBAAiB;IAElC,CACD,CAAA;GACK;EATV,CAAA,IAAA,KAAA;CAUM,CAAA;AAEV;AAcA,SAAgB,YAAY,UAA4B,CAAC,GAAc;CACrE,MAAM,UAAU,WAAW,OAAO;CAElC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,0CAA0C;CAG5D,mBACQ,QAAQ,aACb,aAAuC;EACtC,IAAI,SAAS,QAAQ,KAAK,CAAC,QAAQ,QACjC;EAGF,QAAQ,OAAO,SAAS;EAExB,aAAa,QAAQ,QAAQ,YAAY;CAC3C,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO,EACL,YAAY,EACV,IAAI,iBAAiB;EACnB,OAAO,CAAC,SAAS,QAAQ,UAAU;CACrC,EACF,EACF;AACF"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { getTruthyValue, isTruthy, whenTruthy } from "../utils/truthy.js";
|
|
18
18
|
import { chain } from "../utils/chain.js";
|
|
19
19
|
import { addEvent, setStyle } from "../utils/dom-helpers.js";
|
|
20
|
-
import { getActiveElement, getEventTarget } from "../utils/shadowdom/dom-functions.js";
|
|
20
|
+
import { getActiveElement, getEventTarget, getParentElement } from "../utils/shadowdom/dom-functions.js";
|
|
21
21
|
import { htmlElementOrNull, requireElement, requireHTMLElement } from "../utils/dom-value.js";
|
|
22
22
|
import { requireValue } from "../utils/require-value.js";
|
|
23
23
|
import { isIOS, isWebKit } from "../utils/platform.js";
|
|
@@ -104,7 +104,7 @@ const onBlur = (e) => {
|
|
|
104
104
|
const target = requireHTMLElement(getEventTarget(e));
|
|
105
105
|
const relatedTarget = htmlElementOrNull(e.relatedTarget);
|
|
106
106
|
if (relatedTarget && willOpenKeyboard(relatedTarget)) relatedTarget.focus();
|
|
107
|
-
else if (!relatedTarget) htmlElementOrNull(target
|
|
107
|
+
else if (!relatedTarget) htmlElementOrNull(getParentElement(target)?.closest("[tabindex]"))?.focus({ preventScroll: true });
|
|
108
108
|
};
|
|
109
109
|
function handleBlur() {
|
|
110
110
|
return addEvent(document, "blur", onBlur, true);
|
|
@@ -156,7 +156,7 @@ function scrollIntoView(target) {
|
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
nextTarget = scrollable
|
|
159
|
+
nextTarget = getParentElement(scrollable);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
export { createPreventScroll };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-prevent-scroll.js","names":[],"sources":["../../../src/overlays/create-prevent-scroll.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/overlays/usePreventScroll.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 { createEffect } from \"solid-js\";\n\nimport { chain } from \"../utils/chain\";\nimport { addEvent, setStyle } from \"../utils/dom-helpers\";\nimport {\n htmlElementOrNull,\n requireElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isScrollable } from \"../utils/is-scrollable\";\nimport { supportsKeyboard, willOpenKeyboard } from \"../utils/keyboard\";\nimport { isIOS, isWebKit } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n runAfterKeyboard,\n runAfterKeyboardTransition,\n} from \"../utils/run-after-keyboard\";\nimport {\n getActiveElement,\n getEventTarget,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n /**\n * Whether to override the `focus()` method so it does not scroll the page.\n * This is temporary and will be removed after fully testing all overlays.\n *\n * @private\n */\n UNSTABLE_overrideFocus?: boolean;\n}\n\nconst visualViewport = typeof document !== \"undefined\" && window.visualViewport;\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: (() => void) | undefined;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function createPreventScroll(options: PreventScrollOptions = {}): void {\n createEffect(\n () => ({\n disabled: options.isDisabled,\n overrideFocus: options.UNSTABLE_overrideFocus,\n }),\n ({\n disabled,\n overrideFocus: shouldOverrideFocus,\n }): undefined | (() => void) => {\n if (isTruthy(disabled)) {\n return undefined;\n }\n\n preventScrollCount += 1;\n\n if (preventScrollCount === 1) {\n restore =\n isIOS() && isWebKit()\n ? preventScrollMobileWebKit()\n : preventScrollStandard(shouldOverrideFocus);\n }\n\n return () => {\n preventScrollCount -= 1;\n\n if (preventScrollCount === 0) {\n restore?.();\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard(UNSTABLE_overrideFocus?: boolean) {\n const scrollbarWidth =\n window.innerWidth - document.documentElement.clientWidth;\n\n return chain(\n scrollbarWidth > 0 &&\n // Use scrollbar-gutter when supported because it also works for fixed positioned elements.\n (\"scrollbarGutter\" in document.documentElement.style\n ? setStyle(document.documentElement, \"scrollbar-gutter\", \"stable\")\n : setStyle(\n document.documentElement,\n \"padding-right\",\n `${scrollbarWidth}px`\n )),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n whenTruthy(UNSTABLE_overrideFocus, () => overrideFocus()),\n whenTruthy(\n whenTruthy(UNSTABLE_overrideFocus, () => supportsKeyboard()),\n () => handleBlur()\n )\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch\n// zooming or when an element contains text selection, which may allow scrolling in some cases.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\nfunction preventScrollMobileWebKit() {\n // Set overflow hidden so scrollIntoViewport() (useSelectableCollection) sees isScrollPrevented and\n // scrolls only scroll parents instead of calling native scrollIntoView() which moves the window.\n const restoreOverflow = setStyle(\n document.documentElement,\n \"overflow\",\n \"hidden\"\n );\n\n let scrollable: Element;\n let allowTouchMove = false;\n\n const onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n const target = requireElement(getEventTarget(e));\n scrollable = isScrollable(target, true)\n ? target\n : getScrollParent(target, true);\n allowTouchMove = false;\n\n // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.\n const selection = requireValue(\n target.ownerDocument.defaultView,\n \"Expected target.ownerDocument.defaultView\"\n ).getSelection();\n\n if (\n selection &&\n !selection.isCollapsed &&\n selection.containsNode(target, true)\n ) {\n allowTouchMove = true;\n }\n\n // If this is a range input, allow touch move to allow user to adjust the slider value\n if (\n e\n .composedPath()\n .some((el) => el instanceof HTMLInputElement && el.type === \"range\")\n ) {\n allowTouchMove = true;\n }\n\n // If this is a focused input element with a selected range, allow user to drag the selection handles.\n if (\n \"selectionStart\" in target &&\n \"selectionEnd\" in target &&\n typeof target.selectionStart === \"number\" &&\n typeof target.selectionEnd === \"number\" &&\n target.selectionStart < target.selectionEnd &&\n target.ownerDocument.activeElement === target\n ) {\n allowTouchMove = true;\n }\n };\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.\n const style = document.createElement(\"style\");\n const nonce = getNonce();\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n style.textContent = `\n@layer {\n * {\n overscroll-behavior: contain;\n }\n}`.trim();\n document.head.prepend(style);\n\n const onTouchMove = (e: TouchEvent) => {\n // Allow pinch-zooming.\n if (e.touches.length === 2 || allowTouchMove) {\n return;\n }\n\n // Prevent scrolling the window.\n if (\n !isTruthy(scrollable) ||\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (\n scrollable.scrollHeight === scrollable.clientHeight &&\n scrollable.scrollWidth === scrollable.clientWidth\n ) {\n e.preventDefault();\n }\n };\n\n const restoreFocus = overrideFocus();\n\n const removeEvents = chain(\n addEvent(document, \"touchstart\", onTouchStart, {\n capture: true,\n passive: false,\n }),\n addEvent(document, \"touchmove\", onTouchMove, {\n capture: true,\n passive: false,\n }),\n handleBlur()\n );\n\n return () => {\n restoreOverflow();\n removeEvents();\n style.remove();\n restoreFocus();\n };\n}\n\nconst onBlur = (e: FocusEvent) => {\n const target = requireHTMLElement(getEventTarget(e));\n const relatedTarget = htmlElementOrNull(e.relatedTarget);\n\n if (relatedTarget && willOpenKeyboard(relatedTarget)) {\n // Re-focus programmatically to have the override below perform the scroll.\n relatedTarget.focus();\n } else if (!relatedTarget) {\n // When tapping the Done button on the keyboard, focus moves to the body.\n // FocusScope will then restore focus back to the input. Later when tapping\n // the same input again, it is already focused, so no blur event will fire,\n // resulting in the flow above never running and Safari's native scrolling occurring.\n // Instead, move focus to the parent focusable element (e.g. the dialog).\n const focusable = htmlElementOrNull(\n target.parentElement?.closest(\"[tabindex]\")\n );\n\n focusable?.focus({ preventScroll: true });\n }\n};\n\nfunction handleBlur() {\n return addEvent(document, \"blur\", onBlur, true);\n}\n\nfunction overrideFocus() {\n // Override programmatic focus to scroll into view without scrolling the whole page.\n // oxlint-disable-next-line typescript/unbound-method -- Preserve the original method identity and invoke it with an explicit receiver.\n const { focus } = HTMLElement.prototype;\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value(opts?: FocusOptions) {\n // Focus the element without scrolling the page.\n focus.call(this, { ...opts, preventScroll: true });\n\n if (!opts || !isTruthy(opts.preventScroll)) {\n const scroll = () => {\n const activeElement = getActiveElement();\n\n if (activeElement === this) {\n scrollIntoView(requireElement(this));\n }\n };\n\n runAfterKeyboard((isOpen) => {\n if (isOpen) {\n scroll();\n } else {\n runAfterKeyboardTransition(scroll);\n }\n });\n }\n },\n writable: true,\n });\n\n return () => {\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value: focus,\n writable: true,\n });\n };\n}\n\nfunction scrollIntoView(target: Element) {\n const root =\n getTruthyValue(document.scrollingElement) ?? document.documentElement;\n\n let nextTarget: Element | null = target;\n\n while (nextTarget && nextTarget !== root && nextTarget.isConnected) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n const scrollable = getScrollParent(nextTarget);\n\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== nextTarget\n ) {\n const scrollableRect = scrollable.getBoundingClientRect();\n const targetRect = nextTarget.getBoundingClientRect();\n\n if (\n targetRect.top < scrollableRect.top ||\n targetRect.bottom > scrollableRect.top + nextTarget.clientHeight\n ) {\n let { bottom } = scrollableRect;\n\n if (isTruthy(visualViewport)) {\n bottom = Math.min(\n bottom,\n visualViewport.offsetTop + visualViewport.height\n );\n }\n\n // Center within the viewport.\n const adjustment =\n targetRect.top -\n scrollableRect.top -\n ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);\n\n scrollable.scrollTo({\n behavior: \"smooth\",\n // Clamp to the valid range to prevent over-scrolling.\n top: Math.max(\n 0,\n Math.min(\n scrollable.scrollHeight - scrollable.clientHeight,\n scrollable.scrollTop + adjustment\n )\n ),\n });\n }\n }\n\n nextTarget = scrollable.parentElement;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAM,iBAAiB,OAAO,aAAa,eAAe,OAAO;AAGjE,IAAI,qBAAqB;AACzB,IAAI;;;;;;AAOJ,SAAgB,oBAAoB,UAAgC,CAAC,GAAS;CAC5E,oBACS;EACL,UAAU,QAAQ;EAClB,eAAe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AAM,KAAK,MAAM;IAAE,GAAG;IAAM,eAAe;GAAK,CAAC;GAEjD,IAAI,CAAC,QAAQ,CAAC,SAAS,KAAK,aAAa,GAAG;IAC1C,MAAM,eAAe;KAGnB,IAFsB,iBAEN,MAAM,MACpB,eAAe,eAAe,IAAI,CAAC;IAEvC;IAEA,kBAAkB,WAAW;KAC3B,IAAI,QACF,OAAO;UAEP,2BAA2B,MAAM;IAErC,CAAC;GACH;EACF;EACA,UAAU;CACZ,CAAC;CAED,aAAa;EACX,QAAQ,eAAe,YAAY,WAAW,SAAS;GACrD,cAAc;GACd,OAAO;GACP,UAAU;EACZ,CAAC;CACH;AACF;AAEA,SAAS,eAAe,QAAiB;CACvC,MAAM,OACJ,eAAe,SAAS,gBAAgB,KAAK,SAAS;CAExD,IAAI,aAA6B;CAEjC,OAAO,cAAc,eAAe,QAAQ,WAAW,aAAa;EAElE,MAAM,aAAa,gBAAgB,UAAU;EAE7C,IACE,eAAe,SAAS,mBACxB,eAAe,SAAS,QACxB,eAAe,YACf;GACA,MAAM,iBAAiB,WAAW,sBAAsB;GACxD,MAAM,aAAa,WAAW,sBAAsB;GAEpD,IACE,WAAW,MAAM,eAAe,OAChC,WAAW,SAAS,eAAe,MAAM,WAAW,cACpD;IACA,IAAI,EAAE,WAAW;IAEjB,IAAI,SAAS,cAAc,GACzB,SAAS,KAAK,IACZ,QACA,eAAe,YAAY,eAAe,MAC5C;IAIF,MAAM,aACJ,WAAW,MACX,eAAe,QACb,SAAS,eAAe,OAAO,IAAI,WAAW,SAAS;IAE3D,WAAW,SAAS;KAClB,UAAU;KAEV,KAAK,KAAK,IACR,GACA,KAAK,IACH,WAAW,eAAe,WAAW,cACrC,WAAW,YAAY,UACzB,CACF;IACF,CAAC;GACH;EACF;EAEA,aAAa,WAAW;CAC1B;AACF"}
|
|
1
|
+
{"version":3,"file":"create-prevent-scroll.js","names":[],"sources":["../../../src/overlays/create-prevent-scroll.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/overlays/usePreventScroll.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 { createEffect } from \"solid-js\";\n\nimport { chain } from \"../utils/chain\";\nimport { addEvent, setStyle } from \"../utils/dom-helpers\";\nimport {\n htmlElementOrNull,\n requireElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isScrollable } from \"../utils/is-scrollable\";\nimport { supportsKeyboard, willOpenKeyboard } from \"../utils/keyboard\";\nimport { isIOS, isWebKit } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n runAfterKeyboard,\n runAfterKeyboardTransition,\n} from \"../utils/run-after-keyboard\";\nimport {\n getActiveElement,\n getEventTarget,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n /**\n * Whether to override the `focus()` method so it does not scroll the page.\n * This is temporary and will be removed after fully testing all overlays.\n *\n * @private\n */\n UNSTABLE_overrideFocus?: boolean;\n}\n\nconst visualViewport = typeof document !== \"undefined\" && window.visualViewport;\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: (() => void) | undefined;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function createPreventScroll(options: PreventScrollOptions = {}): void {\n createEffect(\n () => ({\n disabled: options.isDisabled,\n overrideFocus: options.UNSTABLE_overrideFocus,\n }),\n ({\n disabled,\n overrideFocus: shouldOverrideFocus,\n }): undefined | (() => void) => {\n if (isTruthy(disabled)) {\n return undefined;\n }\n\n preventScrollCount += 1;\n\n if (preventScrollCount === 1) {\n restore =\n isIOS() && isWebKit()\n ? preventScrollMobileWebKit()\n : preventScrollStandard(shouldOverrideFocus);\n }\n\n return () => {\n preventScrollCount -= 1;\n\n if (preventScrollCount === 0) {\n restore?.();\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard(UNSTABLE_overrideFocus?: boolean) {\n const scrollbarWidth =\n window.innerWidth - document.documentElement.clientWidth;\n\n return chain(\n scrollbarWidth > 0 &&\n // Use scrollbar-gutter when supported because it also works for fixed positioned elements.\n (\"scrollbarGutter\" in document.documentElement.style\n ? setStyle(document.documentElement, \"scrollbar-gutter\", \"stable\")\n : setStyle(\n document.documentElement,\n \"padding-right\",\n `${scrollbarWidth}px`\n )),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n whenTruthy(UNSTABLE_overrideFocus, () => overrideFocus()),\n whenTruthy(\n whenTruthy(UNSTABLE_overrideFocus, () => supportsKeyboard()),\n () => handleBlur()\n )\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch\n// zooming or when an element contains text selection, which may allow scrolling in some cases.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\nfunction preventScrollMobileWebKit() {\n // Set overflow hidden so scrollIntoViewport() (useSelectableCollection) sees isScrollPrevented and\n // scrolls only scroll parents instead of calling native scrollIntoView() which moves the window.\n const restoreOverflow = setStyle(\n document.documentElement,\n \"overflow\",\n \"hidden\"\n );\n\n let scrollable: Element;\n let allowTouchMove = false;\n\n const onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n const target = requireElement(getEventTarget(e));\n scrollable = isScrollable(target, true)\n ? target\n : getScrollParent(target, true);\n allowTouchMove = false;\n\n // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.\n const selection = requireValue(\n target.ownerDocument.defaultView,\n \"Expected target.ownerDocument.defaultView\"\n ).getSelection();\n\n if (\n selection &&\n !selection.isCollapsed &&\n selection.containsNode(target, true)\n ) {\n allowTouchMove = true;\n }\n\n // If this is a range input, allow touch move to allow user to adjust the slider value\n if (\n e\n .composedPath()\n .some((el) => el instanceof HTMLInputElement && el.type === \"range\")\n ) {\n allowTouchMove = true;\n }\n\n // If this is a focused input element with a selected range, allow user to drag the selection handles.\n if (\n \"selectionStart\" in target &&\n \"selectionEnd\" in target &&\n typeof target.selectionStart === \"number\" &&\n typeof target.selectionEnd === \"number\" &&\n target.selectionStart < target.selectionEnd &&\n target.ownerDocument.activeElement === target\n ) {\n allowTouchMove = true;\n }\n };\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.\n const style = document.createElement(\"style\");\n const nonce = getNonce();\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n style.textContent = `\n@layer {\n * {\n overscroll-behavior: contain;\n }\n}`.trim();\n document.head.prepend(style);\n\n const onTouchMove = (e: TouchEvent) => {\n // Allow pinch-zooming.\n if (e.touches.length === 2 || allowTouchMove) {\n return;\n }\n\n // Prevent scrolling the window.\n if (\n !isTruthy(scrollable) ||\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (\n scrollable.scrollHeight === scrollable.clientHeight &&\n scrollable.scrollWidth === scrollable.clientWidth\n ) {\n e.preventDefault();\n }\n };\n\n const restoreFocus = overrideFocus();\n\n const removeEvents = chain(\n addEvent(document, \"touchstart\", onTouchStart, {\n capture: true,\n passive: false,\n }),\n addEvent(document, \"touchmove\", onTouchMove, {\n capture: true,\n passive: false,\n }),\n handleBlur()\n );\n\n return () => {\n restoreOverflow();\n removeEvents();\n style.remove();\n restoreFocus();\n };\n}\n\nconst onBlur = (e: FocusEvent) => {\n const target = requireHTMLElement(getEventTarget(e));\n const relatedTarget = htmlElementOrNull(e.relatedTarget);\n\n if (relatedTarget && willOpenKeyboard(relatedTarget)) {\n // Re-focus programmatically to have the override below perform the scroll.\n relatedTarget.focus();\n } else if (!relatedTarget) {\n // When tapping the Done button on the keyboard, focus moves to the body.\n // FocusScope will then restore focus back to the input. Later when tapping\n // the same input again, it is already focused, so no blur event will fire,\n // resulting in the flow above never running and Safari's native scrolling occurring.\n // Instead, move focus to the parent focusable element (e.g. the dialog).\n const focusable = htmlElementOrNull(\n getParentElement(target)?.closest(\"[tabindex]\")\n );\n\n focusable?.focus({ preventScroll: true });\n }\n};\n\nfunction handleBlur() {\n return addEvent(document, \"blur\", onBlur, true);\n}\n\nfunction overrideFocus() {\n // Override programmatic focus to scroll into view without scrolling the whole page.\n // oxlint-disable-next-line typescript/unbound-method -- Preserve the original method identity and invoke it with an explicit receiver.\n const { focus } = HTMLElement.prototype;\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value(opts?: FocusOptions) {\n // Focus the element without scrolling the page.\n focus.call(this, { ...opts, preventScroll: true });\n\n if (!opts || !isTruthy(opts.preventScroll)) {\n const scroll = () => {\n const activeElement = getActiveElement();\n\n if (activeElement === this) {\n scrollIntoView(requireElement(this));\n }\n };\n\n runAfterKeyboard((isOpen) => {\n if (isOpen) {\n scroll();\n } else {\n runAfterKeyboardTransition(scroll);\n }\n });\n }\n },\n writable: true,\n });\n\n return () => {\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value: focus,\n writable: true,\n });\n };\n}\n\nfunction scrollIntoView(target: Element) {\n const root =\n getTruthyValue(document.scrollingElement) ?? document.documentElement;\n\n let nextTarget: Element | null = target;\n\n while (nextTarget && nextTarget !== root && nextTarget.isConnected) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n const scrollable = getScrollParent(nextTarget);\n\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== nextTarget\n ) {\n const scrollableRect = scrollable.getBoundingClientRect();\n const targetRect = nextTarget.getBoundingClientRect();\n\n if (\n targetRect.top < scrollableRect.top ||\n targetRect.bottom > scrollableRect.top + nextTarget.clientHeight\n ) {\n let { bottom } = scrollableRect;\n\n if (isTruthy(visualViewport)) {\n bottom = Math.min(\n bottom,\n visualViewport.offsetTop + visualViewport.height\n );\n }\n\n // Center within the viewport.\n const adjustment =\n targetRect.top -\n scrollableRect.top -\n ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);\n\n scrollable.scrollTo({\n behavior: \"smooth\",\n // Clamp to the valid range to prevent over-scrolling.\n top: Math.max(\n 0,\n Math.min(\n scrollable.scrollHeight - scrollable.clientHeight,\n scrollable.scrollTop + adjustment\n )\n ),\n });\n }\n }\n\n nextTarget = getParentElement(scrollable);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,iBAAiB,OAAO,aAAa,eAAe,OAAO;AAGjE,IAAI,qBAAqB;AACzB,IAAI;;;;;;AAOJ,SAAgB,oBAAoB,UAAgC,CAAC,GAAS;CAC5E,oBACS;EACL,UAAU,QAAQ;EAClB,eAAe,QAAQ;CACzB,KACC,EACC,UACA,eAAe,0BACe;EAC9B,IAAI,SAAS,QAAQ,GACnB;EAGF,sBAAsB;EAEtB,IAAI,uBAAuB,GACzB,UACE,MAAM,KAAK,SAAS,IAChB,0BAA0B,IAC1B,sBAAsB,mBAAmB;EAGjD,aAAa;GACX,sBAAsB;GAEtB,IAAI,uBAAuB,GACzB,UAAU;EAEd;CACF,GACA,EAAE,WAAW,SAAS,CACxB;AACF;AAIA,SAAS,sBAAsB,wBAAkC;CAC/D,MAAM,iBACJ,OAAO,aAAa,SAAS,gBAAgB;CAE/C,OAAO,MACL,iBAAiB,MAEd,qBAAqB,SAAS,gBAAgB,QAC3C,SAAS,SAAS,iBAAiB,oBAAoB,QAAQ,IAC/D,SACE,SAAS,iBACT,iBACA,GAAG,eAAe,GACpB,IACN,SAAS,SAAS,iBAAiB,YAAY,QAAQ,GACvD,WAAW,8BAA8B,cAAc,CAAC,GACxD,WACE,WAAW,8BAA8B,iBAAiB,CAAC,SACrD,WAAW,CACnB,CACF;AACF;AAsBA,SAAS,4BAA4B;CAGnC,MAAM,kBAAkB,SACtB,SAAS,iBACT,YACA,QACF;CAEA,IAAI;CACJ,IAAI,iBAAiB;CAEr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AChC,WAAW,SAAS,eAAe,MAAM,WAAW,cACpD;IACA,IAAI,EAAE,WAAW;IAEjB,IAAI,SAAS,cAAc,GACzB,SAAS,KAAK,IACZ,QACA,eAAe,YAAY,eAAe,MAC5C;IAIF,MAAM,aACJ,WAAW,MACX,eAAe,QACb,SAAS,eAAe,OAAO,IAAI,WAAW,SAAS;IAE3D,WAAW,SAAS;KAClB,UAAU;KAEV,KAAK,KAAK,IACR,GACA,KAAK,IACH,WAAW,eAAe,WAAW,cACrC,WAAW,YAAY,UACzB,CACF;IACF,CAAC;GACH;EACF;EAEA,aAAa,iBAAiB,UAAU;CAC1C;AACF"}
|
|
@@ -20,7 +20,7 @@ import { FocusScope } from "../focus/focus-scope.js";
|
|
|
20
20
|
import { ClearPressResponder } from "../interactions/press-responder.js";
|
|
21
21
|
import { createUNSAFE_PortalContext } from "./portal-provider.js";
|
|
22
22
|
import { Portal, createComponent, memo } from "@solidjs/web";
|
|
23
|
-
import {
|
|
23
|
+
import { createContext, createMemo, createSignal, onSettled, useContext } from "solid-js";
|
|
24
24
|
// src/overlays/overlay.tsx
|
|
25
25
|
const OverlayContext = createContext(null);
|
|
26
26
|
function Overlay(props) {
|
|
@@ -37,13 +37,12 @@ function Overlay(props) {
|
|
|
37
37
|
setContain
|
|
38
38
|
};
|
|
39
39
|
const container = createMemo(() => props.portalContainer ?? portal.getContainer?.() ?? (mounted() ? document.body : null));
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
return container();
|
|
43
|
-
},
|
|
44
|
-
children: (mount) => createComponent(Portal, {
|
|
40
|
+
return memo(() => {
|
|
41
|
+
return memo(() => {
|
|
42
|
+
return !!container();
|
|
43
|
+
})() ? createComponent(Portal, {
|
|
45
44
|
get mount() {
|
|
46
|
-
return
|
|
45
|
+
return container();
|
|
47
46
|
},
|
|
48
47
|
get children() {
|
|
49
48
|
return createComponent(OverlayContext, {
|
|
@@ -70,7 +69,7 @@ function Overlay(props) {
|
|
|
70
69
|
}
|
|
71
70
|
});
|
|
72
71
|
}
|
|
73
|
-
})
|
|
72
|
+
}) : void 0;
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
function createOverlayFocusContain() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.js","names":["<Show when={container()}>\n {(mount) => (\n <Portal mount={mount()}>\n <OverlayContext value={value}>\n <ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>\n </OverlayContext>\n </Portal>\n )}\n </Show>","<Portal mount={mount()}>\n <OverlayContext value={value}>\n <ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>\n </OverlayContext>\n </Portal>","<OverlayContext value={value}>\n <ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>\n </OverlayContext>","<ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>","<FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>","value={null}","{isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}","<FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>","_$
|
|
1
|
+
{"version":3,"file":"overlay.js","names":["<Show when={container()}>\n {(mount) => (\n <Portal mount={mount()}>\n <OverlayContext value={value}>\n <ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>\n </OverlayContext>\n </Portal>\n )}\n </Show>","<Portal mount={mount()}>\n <OverlayContext value={value}>\n <ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>\n </OverlayContext>\n </Portal>","<OverlayContext value={value}>\n <ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>\n </OverlayContext>","<ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>","<FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>","value={null}","{isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}","<FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>","_$memo","_$createComponent"],"sources":["../../../src/overlays/overlay.tsx"],"sourcesContent":["/*\n * Copyright 2022 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/overlays/Overlay.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 { Portal } from \"@solidjs/web\";\nimport {\n createContext,\n createMemo,\n createSignal,\n onSettled,\n Show,\n useContext,\n} from \"solid-js\";\nimport type { Element as SolidElement, Setter } from \"solid-js\";\n\nimport { FocusScope } from \"../focus/focus-scope\";\nimport { FocusableContext } from \"../interactions/create-focusable\";\nimport { ClearPressResponder } from \"../interactions/press-responder\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\nimport { createUNSAFE_PortalContext } from \"./portal-provider\";\n\nexport interface OverlayProps {\n portalContainer?: Element;\n children?: SolidElement;\n disableFocusManagement?: boolean;\n shouldContainFocus?: boolean;\n isExiting?: boolean;\n}\n\nexport const OverlayContext = createContext<{\n contain: boolean;\n setContain: Setter<boolean>;\n} | null>(null);\n\nexport function Overlay(props: OverlayProps): SolidElement {\n const [mounted, setMounted] = createSignal(false);\n onSettled(() => {\n setMounted(true);\n });\n const portal = createUNSAFE_PortalContext();\n const [contain, setContain] = createSignal(false);\n\n const value = {\n get contain() {\n return contain();\n },\n setContain,\n };\n\n const container = createMemo(\n () =>\n props.portalContainer ??\n portal.getContainer?.() ??\n (mounted() ? document.body : null)\n );\n\n return (\n <Show when={container()}>\n {(mount) => (\n <Portal mount={mount()}>\n <OverlayContext value={value}>\n <ClearPressResponder>\n <FocusableContext value={null}>\n {isTruthy(props.disableFocusManagement) ? (\n props.children\n ) : (\n <FocusScope\n restoreFocus\n contain={whenTruthy(\n getTruthyValue(props.shouldContainFocus) ?? contain(),\n () => !isTruthy(props.isExiting)\n )}\n >\n {props.children}\n </FocusScope>\n )}\n </FocusableContext>\n </ClearPressResponder>\n </OverlayContext>\n </Portal>\n )}\n </Show>\n );\n}\n\nexport function createOverlayFocusContain(): void {\n const context = useContext(OverlayContext);\n onSettled(() => {\n context?.setContain(true);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,iBAAiB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} 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 { isNode } from "../utils/
|
|
22
|
+
import { isNode } from "../utils/type-helpers.js";
|
|
23
23
|
import { nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
24
24
|
import { createKeyboard } from "../interactions/create-keyboard.js";
|
|
25
25
|
import { setInteractionModality } from "../interactions/create-focus-visible.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-select.js","names":[],"sources":["../../../src/select/create-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/select/useSelect.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 SelectionMode,\n SelectProps,\n SelectState,\n} from \"@solid2-aria/stately/select/create-select-state\";\nimport type {\n AriaLabelingProps,\n DOMProps,\n FocusableDOMProps,\n KeyboardDelegate,\n ValidationResult,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { merge, omit, createMemo } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type { AriaButtonProps } from \"../button/create-button\";\nimport { createCollator } from \"../i18n/create-collator\";\nimport { setInteractionModality } from \"../interactions/create-focus-visible\";\nimport { createKeyboard } from \"../interactions/create-keyboard\";\nimport { createField } from \"../label/create-field\";\nimport type { AriaListBoxOptions } from \"../listbox/create-list-box\";\nimport { createMenuTrigger } from \"../menu/create-menu-trigger\";\nimport { createTypeSelect } from \"../selection/create-type-select\";\nimport { ListKeyboardDelegate } from \"../selection/list-keyboard-delegate\";\nimport type { FocusEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { chain } from \"../utils/chain\";\nimport { createId } from \"../utils/create-id\";\nimport { isNode } from \"../utils/dom-helpers\";\nimport { filterDOMProps } from \"../utils/filter-dom-props\";\nimport { isPresent } from \"../utils/is-present\";\nimport { getLegacyOption } from \"../utils/legacy-option\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport type { HiddenSelectProps } from \"./hidden-select\";\n\nexport interface AriaSelectProps<T, M extends SelectionMode = \"single\">\n extends\n SelectProps<T, M>,\n DOMProps,\n AriaLabelingProps,\n Omit<FocusableDOMProps, \"excludeFromTabOrder\"> {\n /**\n * Describes the type of autocomplete functionality the input should provide if any. See\n * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).\n */\n autoComplete?: string;\n /**\n * The name of the input, used when submitting an HTML form.\n */\n name?: string;\n /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).\n */\n form?: string;\n}\n\nexport interface AriaSelectOptions<\n T,\n M extends SelectionMode = \"single\",\n> extends Omit<AriaSelectProps<T, M>, \"children\"> {\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate;\n}\n\nexport interface SelectAria<\n T,\n M extends SelectionMode = \"single\",\n> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes;\n /** Props for the popup trigger element. */\n triggerProps: AriaButtonProps;\n /** Props for the element representing the selected value. */\n valueProps: DOMAttributes;\n /** Props for the popup. */\n menuProps: AriaListBoxOptions<T>;\n /** Props for the select's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the select's error message element, if any. */\n errorMessageProps: DOMAttributes;\n /** Props for the hidden select element. */\n hiddenSelectProps: HiddenSelectProps<T, M>;\n}\n\ninterface SelectData {\n isDisabled?: boolean;\n isRequired?: boolean;\n name?: string;\n form?: string;\n validationBehavior?: \"aria\" | \"native\";\n}\n\ntype SelectDataOwner = Pick<SelectState<unknown>, \"selectionManager\">;\n\nexport const selectData = new WeakMap<SelectDataOwner, SelectData>();\n\n/**\n * Provides the behavior and accessibility implementation for a select component.\n * A select displays a collapsible list of options and allows a user to select one of them.\n *\n * @param props - Props for the select.\n * @param state - State for the select, as returned by `useListState`.\n */\nexport function createSelect<T, M extends SelectionMode = \"single\">(\n props: AriaSelectOptions<T, M>,\n state: SelectState<T, M>,\n ref: Accessor<HTMLElement | null>\n): SelectAria<T, M> {\n const _result0 = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n const collator = createCollator({\n get sensitivity(): \"base\" {\n return \"base\";\n },\n get usage(): \"search\" {\n return \"search\";\n },\n });\n\n const delegate = createMemo(\n () =>\n getTruthyValue(_result0.keyboardDelegate) ??\n new ListKeyboardDelegate(\n state.collection,\n state.disabledKeys,\n ref,\n collator\n )\n );\n\n const _result1 = createMenuTrigger<T>(\n {\n get isDisabled() {\n return _result0.isDisabled;\n },\n get type(): \"listbox\" {\n return \"listbox\";\n },\n },\n state,\n ref\n );\n\n const _result2 = createKeyboard({\n get allowRepeats(): true {\n return true;\n },\n get onKeyDown() {\n return props.onKeyDown;\n },\n get onKeyUp() {\n return props.onKeyUp;\n },\n get shortcuts() {\n return {\n ArrowLeft: (): undefined | false => {\n if (state.selectionManager.selectionMode === \"multiple\") {\n return false;\n }\n\n const selectedKey = getLegacyOption(state, \"selectedKey\");\n\n const key = isPresent(selectedKey)\n ? delegate().getKeyAbove?.(selectedKey)\n : delegate().getFirstKey?.();\n\n if (isPresent(key)) {\n getLegacyOption(state, \"setSelectedKey\").call(state, key);\n }\n\n return undefined;\n },\n ArrowRight: (): undefined | false => {\n if (state.selectionManager.selectionMode === \"multiple\") {\n return false;\n }\n\n const selectedKey = getLegacyOption(state, \"selectedKey\");\n\n const key = isPresent(selectedKey)\n ? delegate().getKeyBelow?.(selectedKey)\n : delegate().getFirstKey?.();\n\n if (isPresent(key)) {\n getLegacyOption(state, \"setSelectedKey\").call(state, key);\n }\n\n return undefined;\n },\n };\n },\n });\n\n const { typeSelectProps } = createTypeSelect(\n {\n get isDisabled() {\n return state.selectionManager.selectionMode === \"multiple\";\n },\n get keyboardDelegate() {\n return delegate();\n },\n onTypeSelect(key) {\n getLegacyOption(state, \"setSelectedKey\").call(state, key);\n },\n get selectionManager() {\n return state.selectionManager;\n },\n },\n ref\n );\n\n const _result4 = createField(\n merge(props, {\n get errorMessage() {\n return (\n getTruthyValue(props.errorMessage) ??\n state.displayValidation.validationErrors\n );\n },\n get isInvalid() {\n return state.displayValidation.isInvalid;\n },\n get labelElementType(): \"span\" {\n return \"span\";\n },\n })\n );\n\n const domProps = createMemo(() => filterDOMProps(props, { labelable: true }));\n\n const triggerProps = createMemo(() =>\n mergeProps(\n state.selectionManager.selectionMode === \"multiple\"\n ? {}\n : typeSelectProps,\n _result1.menuTriggerProps,\n _result4.fieldProps\n )\n );\n\n const valueId = createId();\n selectData.set(state, {\n get form() {\n return props.form;\n },\n get isDisabled() {\n return props.isDisabled;\n },\n get isRequired() {\n return props.isRequired;\n },\n get name() {\n return props.name;\n },\n get validationBehavior() {\n return props.validationBehavior ?? \"aria\";\n },\n });\n\n return {\n get descriptionProps() {\n return _result4.descriptionProps;\n },\n get errorMessageProps() {\n return _result4.errorMessageProps;\n },\n get hiddenSelectProps() {\n return {\n get form() {\n return _result0.form;\n },\n get isDisabled() {\n return _result0.isDisabled;\n },\n get label() {\n return props.label;\n },\n get name() {\n return _result0.name;\n },\n get state() {\n return state;\n },\n get triggerRef() {\n return ref;\n },\n };\n },\n get isInvalid() {\n return state.displayValidation.isInvalid;\n },\n get labelProps() {\n return merge(_result4.labelProps, {\n onClick: () => {\n if (!isTruthy(props.isDisabled)) {\n ref()?.focus();\n // Show the focus ring so the user knows where focus went\n setInteractionModality(\"keyboard\");\n }\n },\n });\n },\n get menuProps() {\n return merge(omit(_result1.menuProps, \"onAction\"), {\n get \"aria-labelledby\"() {\n return ariaValue(\n ariaValue(\n [\n _result4.fieldProps[\"aria-labelledby\"],\n isTruthy(triggerProps()[\"aria-label\"]) &&\n !isTruthy(_result4.fieldProps[\"aria-labelledby\"])\n ? triggerProps().id\n : null,\n ]\n .filter(Boolean)\n .join(\" \")\n )\n );\n },\n get autoFocus() {\n return getTruthyValue(state.focusStrategy) ?? true;\n },\n get disallowEmptySelection(): true {\n return true;\n },\n get linkBehavior(): \"selection\" {\n return \"selection\";\n },\n onAction: undefined,\n onFocusOut: (e: FocusEvent) => {\n if (\n isNode(e.relatedTarget) &&\n nodeContains(e.currentTarget, e.relatedTarget)\n ) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n },\n get shouldFocusOnHover(): true {\n return true;\n },\n get shouldSelectOnPressUp(): true {\n return true;\n },\n });\n },\n get triggerProps() {\n return mergeProps(domProps(), {\n ...triggerProps(),\n \"aria-labelledby\": ariaValue(\n [\n valueId(),\n triggerProps()[\"aria-labelledby\"],\n isTruthy(triggerProps()[\"aria-label\"]) &&\n !isTruthy(triggerProps()[\"aria-labelledby\"])\n ? triggerProps().id\n : null,\n ]\n .filter(Boolean)\n .join(\" \")\n ),\n isDisabled: _result0.isDisabled,\n onBlur(e: FocusEvent) {\n if (state.isOpen) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n },\n onFocus(e: FocusEvent) {\n if (state.isFocused) {\n return;\n }\n\n if (props.onFocus) {\n props.onFocus(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(true);\n }\n\n state.setFocused(true);\n },\n onKeyDown: chain(\n triggerProps().onKeyDown,\n _result2.keyboardProps.onKeyDown\n ),\n onKeyUp: _result2.keyboardProps.onKeyUp,\n });\n },\n get validationDetails() {\n return state.displayValidation.validationDetails;\n },\n get validationErrors() {\n return state.displayValidation.validationErrors;\n },\n get valueProps() {\n return {\n get id() {\n return valueId();\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA,MAAa,6BAAa,IAAI,QAAqC;;;;;;;;AASnE,SAAgB,aACd,OACA,OACA,KACkB;CAClB,MAAM,WAAW;CAIjB,MAAM,WAAW,eAAe;EAC9B,IAAI,cAAsB;GACxB,OAAO;EACT;EACA,IAAI,QAAkB;GACpB,OAAO;EACT;CACF,CAAC;CAED,MAAM,WAAW,iBAEb,eAAe,SAAS,gBAAgB,KACxC,IAAI,qBACF,MAAM,YACN,MAAM,cACN,KACA,QACF,CACJ;CAEA,MAAM,WAAW,kBACf;EACE,IAAI,aAAa;GACf,OAAO,SAAS;EAClB;EACA,IAAI,OAAkB;GACpB,OAAO;EACT;CACF,GACA,OACA,GACF;CAEA,MAAM,WAAW,eAAe;EAC9B,IAAI,eAAqB;GACvB,OAAO;EACT;EACA,IAAI,YAAY;GACd,OAAO,MAAM;EACf;EACA,IAAI,UAAU;GACZ,OAAO,MAAM;EACf;EACA,IAAI,YAAY;GACd,OAAO;IACL,iBAAoC;KAClC,IAAI,MAAM,iBAAiB,kBAAkB,YAC3C,OAAO;KAGT,MAAM,cAAc,gBAAgB,OAAO,aAAa;KAExD,MAAM,MAAM,UAAU,WAAW,IAC7B,SAAS,CAAC,CAAC,cAAc,WAAW,IACpC,SAAS,CAAC,CAAC,cAAc;KAE7B,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AAO,CAAC;KAGhB,IAAI,MAAM,eACR,MAAM,cAAc,KAAK;KAG3B,MAAM,WAAW,KAAK;IACxB;IACA,IAAI,qBAA2B;KAC7B,OAAO;IACT;IACA,IAAI,wBAA8B;KAChC,OAAO;IACT;GACF,CAAC;EACH;EACA,IAAI,eAAe;GACjB,OAAO,WAAW,SAAS,GAAG;IAC5B,GAAG,aAAa;IAChB,mBAAmB,UACjB;KACE,QAAQ;KACR,aAAa,CAAC,CAAC;KACf,SAAS,aAAa,CAAC,CAAC,aAAa,KACrC,CAAC,SAAS,aAAa,CAAC,CAAC,kBAAkB,IACvC,aAAa,CAAC,CAAC,KACf;IACN,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,CACb;IACA,YAAY,SAAS;IACrB,OAAO,GAAe;KACpB,IAAI,MAAM,QACR;KAGF,IAAI,MAAM,QACR,MAAM,OAAO,CAAC;KAGhB,IAAI,MAAM,eACR,MAAM,cAAc,KAAK;KAG3B,MAAM,WAAW,KAAK;IACxB;IACA,QAAQ,GAAe;KACrB,IAAI,MAAM,WACR;KAGF,IAAI,MAAM,SACR,MAAM,QAAQ,CAAC;KAGjB,IAAI,MAAM,eACR,MAAM,cAAc,IAAI;KAG1B,MAAM,WAAW,IAAI;IACvB;IACA,WAAW,MACT,aAAa,CAAC,CAAC,WACf,SAAS,cAAc,SACzB;IACA,SAAS,SAAS,cAAc;GAClC,CAAC;EACH;EACA,IAAI,oBAAoB;GACtB,OAAO,MAAM,kBAAkB;EACjC;EACA,IAAI,mBAAmB;GACrB,OAAO,MAAM,kBAAkB;EACjC;EACA,IAAI,aAAa;GACf,OAAO,EACL,IAAI,KAAK;IACP,OAAO,QAAQ;GACjB,EACF;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"create-select.js","names":[],"sources":["../../../src/select/create-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/select/useSelect.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 SelectionMode,\n SelectProps,\n SelectState,\n} from \"@solid2-aria/stately/select/create-select-state\";\nimport type {\n AriaLabelingProps,\n DOMProps,\n FocusableDOMProps,\n KeyboardDelegate,\n ValidationResult,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { merge, omit, createMemo } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type { AriaButtonProps } from \"../button/create-button\";\nimport { createCollator } from \"../i18n/create-collator\";\nimport { setInteractionModality } from \"../interactions/create-focus-visible\";\nimport { createKeyboard } from \"../interactions/create-keyboard\";\nimport { createField } from \"../label/create-field\";\nimport type { AriaListBoxOptions } from \"../listbox/create-list-box\";\nimport { createMenuTrigger } from \"../menu/create-menu-trigger\";\nimport { createTypeSelect } from \"../selection/create-type-select\";\nimport { ListKeyboardDelegate } from \"../selection/list-keyboard-delegate\";\nimport type { FocusEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { chain } from \"../utils/chain\";\nimport { createId } from \"../utils/create-id\";\nimport { filterDOMProps } from \"../utils/filter-dom-props\";\nimport { isPresent } from \"../utils/is-present\";\nimport { getLegacyOption } from \"../utils/legacy-option\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { isNode } from \"../utils/type-helpers\";\nimport type { HiddenSelectProps } from \"./hidden-select\";\n\nexport interface AriaSelectProps<T, M extends SelectionMode = \"single\">\n extends\n SelectProps<T, M>,\n DOMProps,\n AriaLabelingProps,\n Omit<FocusableDOMProps, \"excludeFromTabOrder\"> {\n /**\n * Describes the type of autocomplete functionality the input should provide if any. See\n * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).\n */\n autoComplete?: string;\n /**\n * The name of the input, used when submitting an HTML form.\n */\n name?: string;\n /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).\n */\n form?: string;\n}\n\nexport interface AriaSelectOptions<\n T,\n M extends SelectionMode = \"single\",\n> extends Omit<AriaSelectProps<T, M>, \"children\"> {\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate;\n}\n\nexport interface SelectAria<\n T,\n M extends SelectionMode = \"single\",\n> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes;\n /** Props for the popup trigger element. */\n triggerProps: AriaButtonProps;\n /** Props for the element representing the selected value. */\n valueProps: DOMAttributes;\n /** Props for the popup. */\n menuProps: AriaListBoxOptions<T>;\n /** Props for the select's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the select's error message element, if any. */\n errorMessageProps: DOMAttributes;\n /** Props for the hidden select element. */\n hiddenSelectProps: HiddenSelectProps<T, M>;\n}\n\ninterface SelectData {\n isDisabled?: boolean;\n isRequired?: boolean;\n name?: string;\n form?: string;\n validationBehavior?: \"aria\" | \"native\";\n}\n\ntype SelectDataOwner = Pick<SelectState<unknown>, \"selectionManager\">;\n\nexport const selectData = new WeakMap<SelectDataOwner, SelectData>();\n\n/**\n * Provides the behavior and accessibility implementation for a select component.\n * A select displays a collapsible list of options and allows a user to select one of them.\n *\n * @param props - Props for the select.\n * @param state - State for the select, as returned by `useListState`.\n */\nexport function createSelect<T, M extends SelectionMode = \"single\">(\n props: AriaSelectOptions<T, M>,\n state: SelectState<T, M>,\n ref: Accessor<HTMLElement | null>\n): SelectAria<T, M> {\n const _result0 = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n const collator = createCollator({\n get sensitivity(): \"base\" {\n return \"base\";\n },\n get usage(): \"search\" {\n return \"search\";\n },\n });\n\n const delegate = createMemo(\n () =>\n getTruthyValue(_result0.keyboardDelegate) ??\n new ListKeyboardDelegate(\n state.collection,\n state.disabledKeys,\n ref,\n collator\n )\n );\n\n const _result1 = createMenuTrigger<T>(\n {\n get isDisabled() {\n return _result0.isDisabled;\n },\n get type(): \"listbox\" {\n return \"listbox\";\n },\n },\n state,\n ref\n );\n\n const _result2 = createKeyboard({\n get allowRepeats(): true {\n return true;\n },\n get onKeyDown() {\n return props.onKeyDown;\n },\n get onKeyUp() {\n return props.onKeyUp;\n },\n get shortcuts() {\n return {\n ArrowLeft: (): undefined | false => {\n if (state.selectionManager.selectionMode === \"multiple\") {\n return false;\n }\n\n const selectedKey = getLegacyOption(state, \"selectedKey\");\n\n const key = isPresent(selectedKey)\n ? delegate().getKeyAbove?.(selectedKey)\n : delegate().getFirstKey?.();\n\n if (isPresent(key)) {\n getLegacyOption(state, \"setSelectedKey\").call(state, key);\n }\n\n return undefined;\n },\n ArrowRight: (): undefined | false => {\n if (state.selectionManager.selectionMode === \"multiple\") {\n return false;\n }\n\n const selectedKey = getLegacyOption(state, \"selectedKey\");\n\n const key = isPresent(selectedKey)\n ? delegate().getKeyBelow?.(selectedKey)\n : delegate().getFirstKey?.();\n\n if (isPresent(key)) {\n getLegacyOption(state, \"setSelectedKey\").call(state, key);\n }\n\n return undefined;\n },\n };\n },\n });\n\n const { typeSelectProps } = createTypeSelect(\n {\n get isDisabled() {\n return state.selectionManager.selectionMode === \"multiple\";\n },\n get keyboardDelegate() {\n return delegate();\n },\n onTypeSelect(key) {\n getLegacyOption(state, \"setSelectedKey\").call(state, key);\n },\n get selectionManager() {\n return state.selectionManager;\n },\n },\n ref\n );\n\n const _result4 = createField(\n merge(props, {\n get errorMessage() {\n return (\n getTruthyValue(props.errorMessage) ??\n state.displayValidation.validationErrors\n );\n },\n get isInvalid() {\n return state.displayValidation.isInvalid;\n },\n get labelElementType(): \"span\" {\n return \"span\";\n },\n })\n );\n\n const domProps = createMemo(() => filterDOMProps(props, { labelable: true }));\n\n const triggerProps = createMemo(() =>\n mergeProps(\n state.selectionManager.selectionMode === \"multiple\"\n ? {}\n : typeSelectProps,\n _result1.menuTriggerProps,\n _result4.fieldProps\n )\n );\n\n const valueId = createId();\n selectData.set(state, {\n get form() {\n return props.form;\n },\n get isDisabled() {\n return props.isDisabled;\n },\n get isRequired() {\n return props.isRequired;\n },\n get name() {\n return props.name;\n },\n get validationBehavior() {\n return props.validationBehavior ?? \"aria\";\n },\n });\n\n return {\n get descriptionProps() {\n return _result4.descriptionProps;\n },\n get errorMessageProps() {\n return _result4.errorMessageProps;\n },\n get hiddenSelectProps() {\n return {\n get form() {\n return _result0.form;\n },\n get isDisabled() {\n return _result0.isDisabled;\n },\n get label() {\n return props.label;\n },\n get name() {\n return _result0.name;\n },\n get state() {\n return state;\n },\n get triggerRef() {\n return ref;\n },\n };\n },\n get isInvalid() {\n return state.displayValidation.isInvalid;\n },\n get labelProps() {\n return merge(_result4.labelProps, {\n onClick: () => {\n if (!isTruthy(props.isDisabled)) {\n ref()?.focus();\n // Show the focus ring so the user knows where focus went\n setInteractionModality(\"keyboard\");\n }\n },\n });\n },\n get menuProps() {\n return merge(omit(_result1.menuProps, \"onAction\"), {\n get \"aria-labelledby\"() {\n return ariaValue(\n ariaValue(\n [\n _result4.fieldProps[\"aria-labelledby\"],\n isTruthy(triggerProps()[\"aria-label\"]) &&\n !isTruthy(_result4.fieldProps[\"aria-labelledby\"])\n ? triggerProps().id\n : null,\n ]\n .filter(Boolean)\n .join(\" \")\n )\n );\n },\n get autoFocus() {\n return getTruthyValue(state.focusStrategy) ?? true;\n },\n get disallowEmptySelection(): true {\n return true;\n },\n get linkBehavior(): \"selection\" {\n return \"selection\";\n },\n onAction: undefined,\n onFocusOut: (e: FocusEvent) => {\n if (\n isNode(e.relatedTarget) &&\n nodeContains(e.currentTarget, e.relatedTarget)\n ) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n },\n get shouldFocusOnHover(): true {\n return true;\n },\n get shouldSelectOnPressUp(): true {\n return true;\n },\n });\n },\n get triggerProps() {\n return mergeProps(domProps(), {\n ...triggerProps(),\n \"aria-labelledby\": ariaValue(\n [\n valueId(),\n triggerProps()[\"aria-labelledby\"],\n isTruthy(triggerProps()[\"aria-label\"]) &&\n !isTruthy(triggerProps()[\"aria-labelledby\"])\n ? triggerProps().id\n : null,\n ]\n .filter(Boolean)\n .join(\" \")\n ),\n isDisabled: _result0.isDisabled,\n onBlur(e: FocusEvent) {\n if (state.isOpen) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n },\n onFocus(e: FocusEvent) {\n if (state.isFocused) {\n return;\n }\n\n if (props.onFocus) {\n props.onFocus(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(true);\n }\n\n state.setFocused(true);\n },\n onKeyDown: chain(\n triggerProps().onKeyDown,\n _result2.keyboardProps.onKeyDown\n ),\n onKeyUp: _result2.keyboardProps.onKeyUp,\n });\n },\n get validationDetails() {\n return state.displayValidation.validationDetails;\n },\n get validationErrors() {\n return state.displayValidation.validationErrors;\n },\n get valueProps() {\n return {\n get id() {\n return valueId();\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA,MAAa,6BAAa,IAAI,QAA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AAS;IACrB,OAAO,GAAe;KACpB,IAAI,MAAM,QACR;KAGF,IAAI,MAAM,QACR,MAAM,OAAO,CAAC;KAGhB,IAAI,MAAM,eACR,MAAM,cAAc,KAAK;KAG3B,MAAM,WAAW,KAAK;IACxB;IACA,QAAQ,GAAe;KACrB,IAAI,MAAM,WACR;KAGF,IAAI,MAAM,SACR,MAAM,QAAQ,CAAC;KAGjB,IAAI,MAAM,eACR,MAAM,cAAc,IAAI;KAG1B,MAAM,WAAW,IAAI;IACvB;IACA,WAAW,MACT,aAAa,CAAC,CAAC,WACf,SAAS,cAAc,SACzB;IACA,SAAS,SAAS,cAAc;GAClC,CAAC;EACH;EACA,IAAI,oBAAoB;GACtB,OAAO,MAAM,kBAAkB;EACjC;EACA,IAAI,mBAAmB;GACrB,OAAO,MAAM,kBAAkB;EACjC;EACA,IAAI,aAAa;GACf,OAAO,EACL,IAAI,KAAK;IACP,OAAO,QAAQ;GACjB,EACF;EACF;CACF;AACF"}
|
|
@@ -20,13 +20,13 @@ import { createFormValidation } from "../form/create-form-validation.js";
|
|
|
20
20
|
import { createFormReset } from "../utils/create-form-reset.js";
|
|
21
21
|
import { createVisuallyHidden } from "../visually-hidden/visually-hidden.js";
|
|
22
22
|
import { selectData } from "./create-select.js";
|
|
23
|
-
import { createComponent, effect, getNextElement, getNextMarker, insert, memo, ref, runHydrationEvents, scope, setAttribute, setProperty, spread, template } from "@solidjs/web";
|
|
24
|
-
import { For,
|
|
23
|
+
import { createComponent, effect, getNextElement, getNextMarker, heldRead, insert, memo, ref, runHydrationEvents, scope, setAttribute, setProperty, spread, template } from "@solidjs/web";
|
|
24
|
+
import { For, createMemo, createSignal, merge, untrack } from "solid-js";
|
|
25
25
|
// src/select/hidden-select.tsx
|
|
26
26
|
var _tmpl$ = /* @__PURE__ */ template(`<div><label><!$><!/><select><option value label= > </option><!$><!/><!$><!/>`);
|
|
27
|
-
var _tmpl$2 = /* @__PURE__ */ template(`<
|
|
28
|
-
var _tmpl$3 = /* @__PURE__ */ template(`<option>`);
|
|
29
|
-
var _tmpl$4 = /* @__PURE__ */ template(`<
|
|
27
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<option>`);
|
|
28
|
+
var _tmpl$3 = /* @__PURE__ */ template(`<option selected>`);
|
|
29
|
+
var _tmpl$4 = /* @__PURE__ */ template(`<input style=display:none>`);
|
|
30
30
|
function createHiddenSelect(props, state, triggerRef) {
|
|
31
31
|
const data = () => selectData.get(state);
|
|
32
32
|
const hidden = createVisuallyHidden({ style: {
|
|
@@ -91,48 +91,10 @@ function HiddenSelect(props) {
|
|
|
91
91
|
const { value } = props.state;
|
|
92
92
|
return Array.isArray(value) ? value : [value];
|
|
93
93
|
});
|
|
94
|
-
return
|
|
95
|
-
|
|
94
|
+
return memo(() => {
|
|
95
|
+
return memo(() => {
|
|
96
96
|
return props.state.collection.size <= 300;
|
|
97
|
-
}
|
|
98
|
-
get fallback() {
|
|
99
|
-
return createComponent(For, {
|
|
100
|
-
get each() {
|
|
101
|
-
return memo(() => {
|
|
102
|
-
return !!values().length;
|
|
103
|
-
})() ? values() : [null];
|
|
104
|
-
},
|
|
105
|
-
children: (value, index) => (() => {
|
|
106
|
-
var _el$14 = getNextElement(_tmpl$2);
|
|
107
|
-
ref(() => {
|
|
108
|
-
return (node) => {
|
|
109
|
-
if (index() === 0) setSelectRef(node);
|
|
110
|
-
};
|
|
111
|
-
}, _el$14);
|
|
112
|
-
effect(() => {
|
|
113
|
-
return {
|
|
114
|
-
e: selectData.get(props.state)?.validationBehavior === "native" ? "text" : "hidden",
|
|
115
|
-
t: aria.selectProps.autocomplete,
|
|
116
|
-
a: aria.selectProps.name,
|
|
117
|
-
o: aria.selectProps.form,
|
|
118
|
-
i: aria.selectProps.disabled,
|
|
119
|
-
n: isPresent(value) ? String(value) : "",
|
|
120
|
-
s: index() === 0 && aria.selectProps.required
|
|
121
|
-
};
|
|
122
|
-
}, ({ e, t, a, o, i, n, s }, _p$) => {
|
|
123
|
-
e !== _p$?.e && setAttribute(_el$14, "type", e);
|
|
124
|
-
t !== _p$?.t && setAttribute(_el$14, "autocomplete", t);
|
|
125
|
-
a !== _p$?.a && setAttribute(_el$14, "name", a);
|
|
126
|
-
o !== _p$?.o && setAttribute(_el$14, "form", o);
|
|
127
|
-
i !== _p$?.i && setAttribute(_el$14, "disabled", i);
|
|
128
|
-
setProperty(_el$14, "value", n);
|
|
129
|
-
s !== _p$?.s && setAttribute(_el$14, "required", s);
|
|
130
|
-
});
|
|
131
|
-
return _el$14;
|
|
132
|
-
})()
|
|
133
|
-
});
|
|
134
|
-
},
|
|
135
|
-
get children() {
|
|
97
|
+
})() ? (() => {
|
|
136
98
|
var _el$ = getNextElement(_tmpl$);
|
|
137
99
|
var _el$2 = _el$.firstChild;
|
|
138
100
|
var _el$3 = _el$2.firstChild;
|
|
@@ -160,43 +122,78 @@ function HiddenSelect(props) {
|
|
|
160
122
|
get each() {
|
|
161
123
|
return [...props.state.collection.getKeys()];
|
|
162
124
|
},
|
|
163
|
-
children: (key) =>
|
|
164
|
-
|
|
125
|
+
children: (key) => memo(() => {
|
|
126
|
+
return memo(() => {
|
|
165
127
|
return props.state.collection.getItem(key)?.type === "item";
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
insert(_el$15, scope(() => {
|
|
128
|
+
})() ? (() => {
|
|
129
|
+
var _el$14 = getNextElement(_tmpl$2);
|
|
130
|
+
insert(_el$14, scope(() => {
|
|
170
131
|
return props.state.collection.getItem(key)?.textValue;
|
|
171
132
|
}));
|
|
172
133
|
effect(() => {
|
|
173
134
|
return {
|
|
174
135
|
e: String(key),
|
|
175
136
|
t: props.state.selectionManager.isSelected(key),
|
|
176
|
-
a: props.state.selectionManager.isSelected(key)
|
|
137
|
+
a: props.state.selectionManager.isSelected(key),
|
|
138
|
+
o: heldRead()
|
|
177
139
|
};
|
|
178
|
-
}, ({ e, t, a }, _p$) => {
|
|
179
|
-
setProperty(_el$
|
|
180
|
-
t !== _p$?.t && setProperty(_el$
|
|
181
|
-
setProperty(_el$
|
|
140
|
+
}, ({ e, t, a, o }, _p$) => {
|
|
141
|
+
(e !== _p$?.e || !o) && setProperty(_el$14, "value", e);
|
|
142
|
+
t !== _p$?.t && setProperty(_el$14, "defaultSelected", t);
|
|
143
|
+
(a !== _p$?.a || !o) && setProperty(_el$14, "selected", a);
|
|
182
144
|
});
|
|
183
|
-
return _el$
|
|
184
|
-
}
|
|
145
|
+
return _el$14;
|
|
146
|
+
})() : void 0;
|
|
185
147
|
})
|
|
186
148
|
}), _el$9, _el$10);
|
|
187
149
|
insert(_el$6, scope(() => {
|
|
188
150
|
return whenTruthy(whenTruthy(props.state.collection.size === 0, () => props.name), () => values().map((value) => (() => {
|
|
189
|
-
var _el$
|
|
190
|
-
setProperty(_el$
|
|
151
|
+
var _el$15 = getNextElement(_tmpl$3);
|
|
152
|
+
setProperty(_el$15, "selected", true);
|
|
191
153
|
effect(() => isPresent(value) ? String(value) : "", (_v$) => {
|
|
192
|
-
setProperty(_el$
|
|
154
|
+
setProperty(_el$15, "value", _v$);
|
|
193
155
|
});
|
|
194
|
-
return _el$
|
|
156
|
+
return _el$15;
|
|
195
157
|
})()));
|
|
196
158
|
}), _el$12, _el$13);
|
|
197
159
|
runHydrationEvents();
|
|
198
160
|
return _el$;
|
|
199
|
-
}
|
|
161
|
+
})() : createComponent(For, {
|
|
162
|
+
get each() {
|
|
163
|
+
return memo(() => {
|
|
164
|
+
return !!values().length;
|
|
165
|
+
})() ? values() : [null];
|
|
166
|
+
},
|
|
167
|
+
children: (value, index) => (() => {
|
|
168
|
+
var _el$16 = getNextElement(_tmpl$4);
|
|
169
|
+
ref(() => {
|
|
170
|
+
return (node) => {
|
|
171
|
+
if (index() === 0) setSelectRef(node);
|
|
172
|
+
};
|
|
173
|
+
}, _el$16);
|
|
174
|
+
effect(() => {
|
|
175
|
+
return {
|
|
176
|
+
e: selectData.get(props.state)?.validationBehavior === "native" ? "text" : "hidden",
|
|
177
|
+
t: aria.selectProps.autocomplete,
|
|
178
|
+
a: aria.selectProps.name,
|
|
179
|
+
o: aria.selectProps.form,
|
|
180
|
+
i: aria.selectProps.disabled,
|
|
181
|
+
n: isPresent(value) ? String(value) : "",
|
|
182
|
+
s: index() === 0 && aria.selectProps.required,
|
|
183
|
+
h: heldRead()
|
|
184
|
+
};
|
|
185
|
+
}, ({ e, t, a, o, i, n, s, h }, _p$) => {
|
|
186
|
+
e !== _p$?.e && setAttribute(_el$16, "type", e);
|
|
187
|
+
t !== _p$?.t && setAttribute(_el$16, "autocomplete", t);
|
|
188
|
+
a !== _p$?.a && setAttribute(_el$16, "name", a);
|
|
189
|
+
o !== _p$?.o && setAttribute(_el$16, "form", o);
|
|
190
|
+
i !== _p$?.i && setAttribute(_el$16, "disabled", i);
|
|
191
|
+
(n !== _p$?.n || !h) && setProperty(_el$16, "value", n);
|
|
192
|
+
s !== _p$?.s && setAttribute(_el$16, "required", s);
|
|
193
|
+
});
|
|
194
|
+
return _el$16;
|
|
195
|
+
})()
|
|
196
|
+
});
|
|
200
197
|
});
|
|
201
198
|
}
|
|
202
199
|
export { HiddenSelect, createHiddenSelect };
|