@dynatrace/strato-components 0.84.12 → 0.84.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/core/components/app-root/AppRoot.css +1 -0
  2. package/core/components/app-root/AppRoot.d.ts +8 -3
  3. package/core/components/app-root/AppRoot.js +116 -1
  4. package/core/components/app-root/AppRoot.sty.js +1 -1
  5. package/core/components/focus-scope/FocusScope.js +81 -1
  6. package/core/contexts/FocusContext.d.ts +1 -1
  7. package/core/contexts/FocusContext.js +28 -1
  8. package/core/hooks/useActiveElement.js +36 -1
  9. package/core/hooks/useCurrentTheme.d.ts +4 -1
  10. package/core/hooks/useCurrentTheme.js +54 -1
  11. package/core/hooks/useFocusContext.js +27 -1
  12. package/core/index.d.ts +1 -0
  13. package/core/index.js +45 -1
  14. package/core/providers/FocusProvider.js +146 -1
  15. package/core/types/data-props.d.ts +1 -0
  16. package/core/types/data-props.js +15 -1
  17. package/core/types/masking-props.d.ts +9 -0
  18. package/core/types/masking-props.js +15 -0
  19. package/core/types/styling-props.d.ts +3 -2
  20. package/core/types/styling-props.js +15 -1
  21. package/core/types/with-children.d.ts +4 -1
  22. package/core/types/with-children.js +15 -1
  23. package/core/utils/focus-management/attempt-focus.js +33 -1
  24. package/core/utils/focus-management/focus-first-descendant.js +35 -1
  25. package/core/utils/focus-management/get-first-focusable-child.js +32 -1
  26. package/core/utils/focus-management/get-last-focusable-child.js +35 -1
  27. package/core/utils/focus-management/is-focusable.js +39 -1
  28. package/core/utils/isBrowser.js +25 -1
  29. package/core/utils/merge-props.js +50 -1
  30. package/esm/core/components/app-root/AppRoot.css +1 -0
  31. package/esm/core/components/app-root/AppRoot.js +92 -1
  32. package/esm/core/components/app-root/AppRoot.js.map +3 -3
  33. package/esm/core/components/app-root/AppRoot.sty.js +1 -1
  34. package/esm/core/components/app-root/AppRoot.sty.js.map +1 -1
  35. package/esm/core/components/focus-scope/FocusScope.js +52 -1
  36. package/esm/core/components/focus-scope/FocusScope.js.map +2 -2
  37. package/esm/core/contexts/FocusContext.js +9 -1
  38. package/esm/core/contexts/FocusContext.js.map +3 -3
  39. package/esm/core/hooks/useActiveElement.js +17 -1
  40. package/esm/core/hooks/useActiveElement.js.map +2 -2
  41. package/esm/core/hooks/useCurrentTheme.js +35 -1
  42. package/esm/core/hooks/useCurrentTheme.js.map +3 -3
  43. package/esm/core/hooks/useFocusContext.js +10 -1
  44. package/esm/core/hooks/useFocusContext.js.map +2 -2
  45. package/esm/core/index.js +32 -1
  46. package/esm/core/index.js.map +3 -3
  47. package/esm/core/providers/FocusProvider.js +117 -1
  48. package/esm/core/providers/FocusProvider.js.map +2 -2
  49. package/esm/core/types/masking-props.js +1 -0
  50. package/esm/core/types/masking-props.js.map +7 -0
  51. package/esm/core/utils/focus-management/attempt-focus.js +14 -1
  52. package/esm/core/utils/focus-management/attempt-focus.js.map +2 -2
  53. package/esm/core/utils/focus-management/focus-first-descendant.js +16 -1
  54. package/esm/core/utils/focus-management/focus-first-descendant.js.map +2 -2
  55. package/esm/core/utils/focus-management/get-first-focusable-child.js +13 -1
  56. package/esm/core/utils/focus-management/get-first-focusable-child.js.map +2 -2
  57. package/esm/core/utils/focus-management/get-last-focusable-child.js +16 -1
  58. package/esm/core/utils/focus-management/get-last-focusable-child.js.map +2 -2
  59. package/esm/core/utils/focus-management/is-focusable.js +20 -1
  60. package/esm/core/utils/focus-management/is-focusable.js.map +2 -2
  61. package/esm/core/utils/isBrowser.js +6 -1
  62. package/esm/core/utils/isBrowser.js.map +2 -2
  63. package/esm/core/utils/merge-props.js +31 -1
  64. package/esm/core/utils/merge-props.js.map +2 -2
  65. package/esm/index.js +1 -1
  66. package/esm/index.js.map +1 -1
  67. package/index.js +17 -1
  68. package/package.json +2 -2
  69. package/testing/custom-render.d.ts +1 -1
  70. package/testing/custom-render.js +62 -1
  71. package/testing/index.js +91 -1
  72. package/testing/mocks/bounding-client-rect-mock.js +36 -1
  73. package/testing/mocks/canvas-mock.js +187 -1
  74. package/testing/mocks/create-mock-element.js +99 -1
  75. package/testing/mocks/create-range-mock.js +47 -1
  76. package/testing/mocks/dom-rect-mock.js +56 -1
  77. package/testing/mocks/fetch-mock.js +38 -1
  78. package/testing/mocks/intersection-observer-mock.js +58 -1
  79. package/testing/mocks/match-media-mock.js +45 -1
  80. package/testing/mocks/offset-height-mock.js +39 -1
  81. package/testing/mocks/offset-width-mock.js +39 -1
  82. package/testing/mocks/pointer-event-mock.js +42 -1
  83. package/testing/mocks/resize-observer-mock.d.ts +1 -1
  84. package/testing/mocks/resize-observer-mock.js +42 -1
  85. package/testing/mocks/screen-size-mock.js +34 -1
  86. package/testing/mocks/scroll-into-view-mock.js +34 -1
  87. package/testing/mocks/scroll-width-mock.js +39 -1
  88. package/testing/mocks/select-mock.js +45 -1
  89. package/testing/mocks/table-virtualization-mock.js +47 -1
  90. package/testing/mocks/text-ellipsis-mock.js +38 -1
  91. package/testing/setup.js +57 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/contexts/FocusContext.tsx"],
4
- "sourcesContent": ["import { createContext } from 'react';\n\nimport { Modality } from '../providers/FocusProvider.js';\n\n/**\n * Defines the contents of the FocusContext.\n * @internal\n */\nexport type FocusContextProps = {\n backgroundInertness?: boolean;\n modality: Modality;\n setBackgroundInertness: (value: boolean) => void;\n};\n\n/**\n * @internal\n *\n * This context keeps all information needed for proper focus management.\n * @param modality - currently used pointer device\n * @param backgroundInertness - if the background (behind overlays) is currently inert (inactive)\n * @param setBackgroundInertness - updates the backgrounds active status\n */\nexport const FocusContext = createContext<FocusContextProps>({\n modality: 'unknown',\n backgroundInertness: undefined,\n setBackgroundInertness: (value) => null,\n});\n"],
5
- "mappings": "AAAA,OAAS,iBAAAA,MAAqB,QAsBvB,MAAMC,EAAeD,EAAiC,CAC3D,SAAU,UACV,oBAAqB,OACrB,uBAAyBE,GAAU,IACrC,CAAC",
6
- "names": ["createContext", "FocusContext", "value"]
4
+ "sourcesContent": ["import { createContext } from 'react';\n\nimport type { Modality } from '../providers/FocusProvider.js';\n\n/**\n * Defines the contents of the FocusContext.\n * @internal\n */\nexport type FocusContextProps = {\n backgroundInertness?: boolean;\n modality: Modality;\n setBackgroundInertness: (value: boolean) => void;\n};\n\n/**\n * @internal\n *\n * This context keeps all information needed for proper focus management.\n * @param modality - currently used pointer device\n * @param backgroundInertness - if the background (behind overlays) is currently inert (inactive)\n * @param setBackgroundInertness - updates the backgrounds active status\n */\nexport const FocusContext = createContext<FocusContextProps>({\n modality: 'unknown',\n backgroundInertness: undefined,\n setBackgroundInertness: (value) => null,\n});\n"],
5
+ "mappings": "AAAA,SAAS,qBAAqB;AAsBvB,MAAM,eAAe,cAAiC;AAAA,EAC3D,UAAU;AAAA,EACV,qBAAqB;AAAA,EACrB,wBAAwB,CAAC,UAAU;AACrC,CAAC;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,18 @@
1
- import{useState as c,useEffect as o}from"react";const u=()=>{const[t,n]=c(document.activeElement),e=s=>{n(document.activeElement)};return o(()=>(document.addEventListener("focusin",e),()=>{document.removeEventListener("focusin",e)}),[]),t};export{u as useActiveElement};
1
+ import { useState, useEffect } from "react";
2
+ const useActiveElement = () => {
3
+ const [active, setActive] = useState(document.activeElement);
4
+ const handleFocusIn = (e) => {
5
+ setActive(document.activeElement);
6
+ };
7
+ useEffect(() => {
8
+ document.addEventListener("focusin", handleFocusIn);
9
+ return () => {
10
+ document.removeEventListener("focusin", handleFocusIn);
11
+ };
12
+ }, []);
13
+ return active;
14
+ };
15
+ export {
16
+ useActiveElement
17
+ };
2
18
  //# sourceMappingURL=useActiveElement.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/hooks/useActiveElement.ts"],
4
4
  "sourcesContent": ["import { useState, useEffect } from 'react';\n\n/**\n * @internal\n * Hook used for getting the active element.\n * @returns the currently focused element.\n */\nexport const useActiveElement = (): HTMLElement => {\n const [active, setActive] = useState(document.activeElement as HTMLElement);\n\n const handleFocusIn = (e: FocusEvent) => {\n setActive(document.activeElement as HTMLElement);\n };\n\n useEffect(() => {\n document.addEventListener('focusin', handleFocusIn);\n return () => {\n document.removeEventListener('focusin', handleFocusIn);\n };\n }, []);\n\n return active;\n};\n"],
5
- "mappings": "AAAA,OAAS,YAAAA,EAAU,aAAAC,MAAiB,QAO7B,MAAMC,EAAmB,IAAmB,CACjD,KAAM,CAACC,EAAQC,CAAS,EAAIJ,EAAS,SAAS,aAA4B,EAEpEK,EAAiBC,GAAkB,CACvCF,EAAU,SAAS,aAA4B,CACjD,EAEA,OAAAH,EAAU,KACR,SAAS,iBAAiB,UAAWI,CAAa,EAC3C,IAAM,CACX,SAAS,oBAAoB,UAAWA,CAAa,CACvD,GACC,CAAC,CAAC,EAEEF,CACT",
6
- "names": ["useState", "useEffect", "useActiveElement", "active", "setActive", "handleFocusIn", "e"]
5
+ "mappings": "AAAA,SAAS,UAAU,iBAAiB;AAO7B,MAAM,mBAAmB,MAAmB;AACjD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,SAAS,aAA4B;AAE1E,QAAM,gBAAgB,CAAC,MAAkB;AACvC,cAAU,SAAS,aAA4B;AAAA,EACjD;AAEA,YAAU,MAAM;AACd,aAAS,iBAAiB,WAAW,aAAa;AAClD,WAAO,MAAM;AACX,eAAS,oBAAoB,WAAW,aAAa;AAAA,IACvD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,36 @@
1
- import{useEffect as m,useMemo as n,useState as i}from"react";import{getTheme as a}from"@dynatrace-sdk/user-preferences";import{isBrowser as c}from"../utils/isBrowser.js";function g(){const r=n(()=>a(),[]);if(r==="dark"||r==="light")return r;if(!c)return"light";const e=n(()=>window&&window.matchMedia("(prefers-color-scheme: dark)"),[]),[o,h]=i(e.matches?"dark":"light");return m(()=>{const t=()=>{const s=e.matches;h(s?"dark":"light")};return e.addEventListener("change",t),()=>{e.removeEventListener("change",t)}},[e]),o}export{g as useCurrentTheme};
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { getTheme } from "@dynatrace-sdk/user-preferences";
3
+ import { isBrowser } from "../utils/isBrowser.js";
4
+ function useCurrentTheme() {
5
+ const sdkTheme = useMemo(() => {
6
+ return getTheme();
7
+ }, []);
8
+ if (sdkTheme === "dark" || sdkTheme === "light") {
9
+ return sdkTheme;
10
+ }
11
+ if (!isBrowser) {
12
+ return "light";
13
+ }
14
+ const themeQuery = useMemo(
15
+ () => window && window.matchMedia("(prefers-color-scheme: dark)"),
16
+ []
17
+ );
18
+ const [currentTheme, setCurrentTheme] = useState(
19
+ themeQuery.matches ? "dark" : "light"
20
+ );
21
+ useEffect(() => {
22
+ const handlePrefersColorSchemeChange = () => {
23
+ const prefersDark = themeQuery.matches;
24
+ setCurrentTheme(prefersDark ? "dark" : "light");
25
+ };
26
+ themeQuery.addEventListener("change", handlePrefersColorSchemeChange);
27
+ return () => {
28
+ themeQuery.removeEventListener("change", handlePrefersColorSchemeChange);
29
+ };
30
+ }, [themeQuery]);
31
+ return currentTheme;
32
+ }
33
+ export {
34
+ useCurrentTheme
35
+ };
2
36
  //# sourceMappingURL=useCurrentTheme.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/hooks/useCurrentTheme.tsx"],
4
- "sourcesContent": ["import { useEffect, useMemo, useState } from 'react';\n\nimport { getTheme } from '@dynatrace-sdk/user-preferences';\n\nimport { isBrowser } from '../utils/isBrowser.js';\n\n/** Returns the current theme based on sdk-setting or browsers preferred color-scheme */\nexport function useCurrentTheme(): 'light' | 'dark' {\n const sdkTheme = useMemo(() => {\n return getTheme();\n }, []);\n\n if (sdkTheme === 'dark' || sdkTheme === 'light') {\n return sdkTheme;\n }\n\n if (!isBrowser) {\n return 'light';\n }\n\n // suppressing the rules of hooks because the sdkTheme is a constant that cannot\n // change through the applications' lifecycle.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const themeQuery = useMemo(\n () => window && window.matchMedia('(prefers-color-scheme: dark)'),\n [],\n );\n\n // suppressing the rules of hooks because the sdkTheme is a constant that cannot\n // change through the applications' lifecycle.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [currentTheme, setCurrentTheme] = useState<'light' | 'dark'>(\n themeQuery.matches ? 'dark' : 'light',\n );\n\n // suppressing the rules of hooks because the sdkTheme is a constant that cannot\n // change through the applications' lifecycle.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n const handlePrefersColorSchemeChange = () => {\n const prefersDark = themeQuery.matches;\n setCurrentTheme(prefersDark ? 'dark' : 'light');\n };\n\n themeQuery.addEventListener('change', handlePrefersColorSchemeChange);\n return () => {\n themeQuery.removeEventListener('change', handlePrefersColorSchemeChange);\n };\n }, [themeQuery]);\n\n return currentTheme;\n}\n"],
5
- "mappings": "AAAA,OAAS,aAAAA,EAAW,WAAAC,EAAS,YAAAC,MAAgB,QAE7C,OAAS,YAAAC,MAAgB,kCAEzB,OAAS,aAAAC,MAAiB,wBAGnB,SAASC,GAAoC,CAClD,MAAMC,EAAWL,EAAQ,IAChBE,EAAS,EACf,CAAC,CAAC,EAEL,GAAIG,IAAa,QAAUA,IAAa,QACtC,OAAOA,EAGT,GAAI,CAACF,EACH,MAAO,QAMT,MAAMG,EAAaN,EACjB,IAAM,QAAU,OAAO,WAAW,8BAA8B,EAChE,CAAC,CACH,EAKM,CAACO,EAAcC,CAAe,EAAIP,EACtCK,EAAW,QAAU,OAAS,OAChC,EAKA,OAAAP,EAAU,IAAM,CACd,MAAMU,EAAiC,IAAM,CAC3C,MAAMC,EAAcJ,EAAW,QAC/BE,EAAgBE,EAAc,OAAS,OAAO,CAChD,EAEA,OAAAJ,EAAW,iBAAiB,SAAUG,CAA8B,EAC7D,IAAM,CACXH,EAAW,oBAAoB,SAAUG,CAA8B,CACzE,CACF,EAAG,CAACH,CAAU,CAAC,EAERC,CACT",
6
- "names": ["useEffect", "useMemo", "useState", "getTheme", "isBrowser", "useCurrentTheme", "sdkTheme", "themeQuery", "currentTheme", "setCurrentTheme", "handlePrefersColorSchemeChange", "prefersDark"]
4
+ "sourcesContent": ["import { useEffect, useMemo, useState } from 'react';\n\nimport { getTheme } from '@dynatrace-sdk/user-preferences';\n\nimport { isBrowser } from '../utils/isBrowser.js';\n\n/**\n * @public\n * Returns the current theme based on sdk-setting or browsers preferred color-scheme\n */\nexport function useCurrentTheme(): 'light' | 'dark' {\n const sdkTheme = useMemo(() => {\n return getTheme();\n }, []);\n\n if (sdkTheme === 'dark' || sdkTheme === 'light') {\n return sdkTheme;\n }\n\n if (!isBrowser) {\n return 'light';\n }\n\n // suppressing the rules of hooks because the sdkTheme is a constant that cannot\n // change through the applications' lifecycle.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const themeQuery = useMemo(\n () => window && window.matchMedia('(prefers-color-scheme: dark)'),\n [],\n );\n\n // suppressing the rules of hooks because the sdkTheme is a constant that cannot\n // change through the applications' lifecycle.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [currentTheme, setCurrentTheme] = useState<'light' | 'dark'>(\n themeQuery.matches ? 'dark' : 'light',\n );\n\n // suppressing the rules of hooks because the sdkTheme is a constant that cannot\n // change through the applications' lifecycle.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n const handlePrefersColorSchemeChange = () => {\n const prefersDark = themeQuery.matches;\n setCurrentTheme(prefersDark ? 'dark' : 'light');\n };\n\n themeQuery.addEventListener('change', handlePrefersColorSchemeChange);\n return () => {\n themeQuery.removeEventListener('change', handlePrefersColorSchemeChange);\n };\n }, [themeQuery]);\n\n return currentTheme;\n}\n"],
5
+ "mappings": "AAAA,SAAS,WAAW,SAAS,gBAAgB;AAE7C,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAMnB,SAAS,kBAAoC;AAClD,QAAM,WAAW,QAAQ,MAAM;AAC7B,WAAO,SAAS;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,MAAI,aAAa,UAAU,aAAa,SAAS;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAKA,QAAM,aAAa;AAAA,IACjB,MAAM,UAAU,OAAO,WAAW,8BAA8B;AAAA,IAChE,CAAC;AAAA,EACH;AAKA,QAAM,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,WAAW,UAAU,SAAS;AAAA,EAChC;AAKA,YAAU,MAAM;AACd,UAAM,iCAAiC,MAAM;AAC3C,YAAM,cAAc,WAAW;AAC/B,sBAAgB,cAAc,SAAS,OAAO;AAAA,IAChD;AAEA,eAAW,iBAAiB,UAAU,8BAA8B;AACpE,WAAO,MAAM;AACX,iBAAW,oBAAoB,UAAU,8BAA8B;AAAA,IACzE;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO;AACT;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,11 @@
1
- import{useContext as o}from"react";import{FocusContext as t}from"../contexts/FocusContext.js";const s=()=>o(t);export{s as useFocusContext};
1
+ import { useContext } from "react";
2
+ import {
3
+ FocusContext
4
+ } from "../contexts/FocusContext.js";
5
+ const useFocusContext = () => {
6
+ return useContext(FocusContext);
7
+ };
8
+ export {
9
+ useFocusContext
10
+ };
2
11
  //# sourceMappingURL=useFocusContext.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/hooks/useFocusContext.ts"],
4
4
  "sourcesContent": ["import { useContext } from 'react';\n\nimport {\n type FocusContextProps,\n FocusContext,\n} from '../contexts/FocusContext.js';\n\n/**\n * Internal hook wrapper for accessing the FocusContext.\n * @internal\n */\nexport const useFocusContext = (): FocusContextProps => {\n return useContext(FocusContext);\n};\n"],
5
- "mappings": "AAAA,OAAS,cAAAA,MAAkB,QAE3B,OAEE,gBAAAC,MACK,8BAMA,MAAMC,EAAkB,IACtBF,EAAWC,CAAY",
6
- "names": ["useContext", "FocusContext", "useFocusContext"]
5
+ "mappings": "AAAA,SAAS,kBAAkB;AAE3B;AAAA,EAEE;AAAA,OACK;AAMA,MAAM,kBAAkB,MAAyB;AACtD,SAAO,WAAW,YAAY;AAChC;",
6
+ "names": []
7
7
  }
package/esm/core/index.js CHANGED
@@ -1,2 +1,33 @@
1
- import{AppRoot as s}from"./components/app-root/AppRoot.js";import{FocusScope as r}from"./components/focus-scope/FocusScope.js";import{useCurrentTheme as c}from"./hooks/useCurrentTheme.js";import{useFocusContext as i}from"./hooks/useFocusContext.js";import{FocusProvider as F}from"./providers/FocusProvider.js";import{attemptFocus as n}from"./utils/focus-management/attempt-focus.js";import{focusFirstDescendant as y}from"./utils/focus-management/focus-first-descendant.js";import{getFirstFocusableChild as _}from"./utils/focus-management/get-first-focusable-child.js";import{getLastFocusableChild as C}from"./utils/focus-management/get-last-focusable-child.js";import{isFocusable as T}from"./utils/focus-management/is-focusable.js";import{isBrowser as b}from"./utils/isBrowser.js";import{mergeProps as j}from"./utils/merge-props.js";export{s as AppRoot,F as _FocusProvider,r as _FocusScope,n as _attemptFocus,y as _focusFirstDescendant,_ as _getFirstFocusableChild,C as _getLastFocusableChild,b as _isBrowser,T as _isFocusable,j as _mergeProps,i as _useFocusContext,c as useCurrentTheme};
1
+ import { AppRoot } from "./components/app-root/AppRoot.js";
2
+ import {
3
+ FocusScope
4
+ } from "./components/focus-scope/FocusScope.js";
5
+ import { useCurrentTheme } from "./hooks/useCurrentTheme.js";
6
+ import { useFocusContext } from "./hooks/useFocusContext.js";
7
+ import {
8
+ FocusProvider
9
+ } from "./providers/FocusProvider.js";
10
+ import { attemptFocus } from "./utils/focus-management/attempt-focus.js";
11
+ import { focusFirstDescendant } from "./utils/focus-management/focus-first-descendant.js";
12
+ import { getFirstFocusableChild } from "./utils/focus-management/get-first-focusable-child.js";
13
+ import { getLastFocusableChild } from "./utils/focus-management/get-last-focusable-child.js";
14
+ import { isFocusable } from "./utils/focus-management/is-focusable.js";
15
+ import { isBrowser } from "./utils/isBrowser.js";
16
+ import {
17
+ mergeProps
18
+ } from "./utils/merge-props.js";
19
+ export {
20
+ AppRoot,
21
+ FocusProvider as _FocusProvider,
22
+ FocusScope as _FocusScope,
23
+ attemptFocus as _attemptFocus,
24
+ focusFirstDescendant as _focusFirstDescendant,
25
+ getFirstFocusableChild as _getFirstFocusableChild,
26
+ getLastFocusableChild as _getLastFocusableChild,
27
+ isBrowser as _isBrowser,
28
+ isFocusable as _isFocusable,
29
+ mergeProps as _mergeProps,
30
+ useFocusContext as _useFocusContext,
31
+ useCurrentTheme
32
+ };
2
33
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/index.ts"],
4
- "sourcesContent": ["export { AppRoot, type AppRootProps } from './components/app-root/AppRoot.js';\nexport {\n FocusScope as _FocusScope,\n type FocusScopeProps as _FocusScopeProps,\n} from './components/focus-scope/FocusScope.js';\n\nexport { type FocusContextProps as _FocusContextProps } from './contexts/FocusContext.js';\n\nexport { useCurrentTheme } from './hooks/useCurrentTheme.js';\nexport { useFocusContext as _useFocusContext } from './hooks/useFocusContext.js';\nexport {\n FocusProvider as _FocusProvider,\n type Modality as _Modality,\n} from './providers/FocusProvider.js';\nexport type { DataTestId } from './types/data-props.js';\nexport type { StylingProps } from './types/styling-props.js';\nexport type { WithChildren } from './types/with-children.js';\n\nexport { attemptFocus as _attemptFocus } from './utils/focus-management/attempt-focus.js';\nexport { focusFirstDescendant as _focusFirstDescendant } from './utils/focus-management/focus-first-descendant.js';\nexport { getFirstFocusableChild as _getFirstFocusableChild } from './utils/focus-management/get-first-focusable-child.js';\nexport { getLastFocusableChild as _getLastFocusableChild } from './utils/focus-management/get-last-focusable-child.js';\nexport { isFocusable as _isFocusable } from './utils/focus-management/is-focusable.js';\nexport { isBrowser as _isBrowser } from './utils/isBrowser.js';\nexport {\n mergeProps as _mergeProps,\n type NullToObject as _NullToObject,\n type TupleTypes as _TupleTypes,\n type UnionToIntersection as _UnionToIntersection,\n} from './utils/merge-props.js';\n"],
5
- "mappings": "AAAA,OAAS,WAAAA,MAAkC,mCAC3C,OACgB,cAAdC,MAEK,yCAIP,OAAS,mBAAAC,MAAuB,6BAChC,OAA4B,mBAAnBC,MAA2C,6BACpD,OACmB,iBAAjBC,MAEK,+BAKP,OAAyB,gBAAhBC,MAAqC,4CAC9C,OAAiC,wBAAxBC,MAAqD,qDAC9D,OAAmC,0BAA1BC,MAAyD,wDAClE,OAAkC,yBAAzBC,MAAuD,uDAChE,OAAwB,eAAfC,MAAmC,2CAC5C,OAAsB,aAAbC,MAA+B,uBACxC,OACgB,cAAdC,MAIK",
6
- "names": ["AppRoot", "FocusScope", "useCurrentTheme", "useFocusContext", "FocusProvider", "attemptFocus", "focusFirstDescendant", "getFirstFocusableChild", "getLastFocusableChild", "isFocusable", "isBrowser", "mergeProps"]
4
+ "sourcesContent": ["export { AppRoot, type AppRootProps } from './components/app-root/AppRoot.js';\nexport {\n FocusScope as _FocusScope,\n type FocusScopeProps as _FocusScopeProps,\n} from './components/focus-scope/FocusScope.js';\n\nexport { type FocusContextProps as _FocusContextProps } from './contexts/FocusContext.js';\n\nexport { useCurrentTheme } from './hooks/useCurrentTheme.js';\nexport { useFocusContext as _useFocusContext } from './hooks/useFocusContext.js';\nexport {\n FocusProvider as _FocusProvider,\n type Modality as _Modality,\n} from './providers/FocusProvider.js';\nexport type { MaskingProps } from './types/masking-props.js';\nexport type { DataTestId } from './types/data-props.js';\nexport type { StylingProps } from './types/styling-props.js';\nexport type { WithChildren } from './types/with-children.js';\n\nexport { attemptFocus as _attemptFocus } from './utils/focus-management/attempt-focus.js';\nexport { focusFirstDescendant as _focusFirstDescendant } from './utils/focus-management/focus-first-descendant.js';\nexport { getFirstFocusableChild as _getFirstFocusableChild } from './utils/focus-management/get-first-focusable-child.js';\nexport { getLastFocusableChild as _getLastFocusableChild } from './utils/focus-management/get-last-focusable-child.js';\nexport { isFocusable as _isFocusable } from './utils/focus-management/is-focusable.js';\nexport { isBrowser as _isBrowser } from './utils/isBrowser.js';\nexport {\n mergeProps as _mergeProps,\n type NullToObject as _NullToObject,\n type TupleTypes as _TupleTypes,\n type UnionToIntersection as _UnionToIntersection,\n} from './utils/merge-props.js';\n"],
5
+ "mappings": "AAAA,SAAS,eAAkC;AAC3C;AAAA,EACgB;AAAA,OAET;AAIP,SAAS,uBAAuB;AAChC,SAA4B,uBAAwB;AACpD;AAAA,EACmB;AAAA,OAEZ;AAMP,SAAyB,oBAAqB;AAC9C,SAAiC,4BAA6B;AAC9D,SAAmC,8BAA+B;AAClE,SAAkC,6BAA8B;AAChE,SAAwB,mBAAoB;AAC5C,SAAsB,iBAAkB;AACxC;AAAA,EACgB;AAAA,OAIT;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,118 @@
1
- import i,{useCallback as s,useEffect as l,useState as d}from"react";import{FocusContext as y}from"../contexts/FocusContext.js";import{useFocusContext as m}from"../hooks/useFocusContext.js";import{mergeProps as h}from"../utils/merge-props.js";const k=["Alt","AltGraph","CapsLock","Control","Fn","FnLock","Hyper","Meta","NumLock","OS","ScrollLock","Super","Symbol","SymbolLock"],v={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch",touchend:"touch",wheel:"wheel"},f=["Tab","Esc","Escape"," ","ArrowDown","Down","ArrowUp","Up","ArrowLeft","Left","ArrowRight","Right","End","Home","PageDown","PageUp"],b=({children:u})=>{const[r,a]=d(!1),c=m(),[p,t]=d("unknown"),n=s(o=>{if(k.includes(o.key)){t("pointer");return}(!o.target||f.includes(o.key))&&t("keyboard")},[]),e=s(o=>{switch(v[o.type]){case"touch":case"pen":return t("touch");case"mouse":case"pointer":case"wheel":return t("pointer");default:return"unknown"}},[]);l(()=>(window.addEventListener("pointerdown",e),window.addEventListener("keydown",n,{capture:!0}),window.addEventListener("wheel",e),()=>{window.removeEventListener("pointerdown",e),window.removeEventListener("keydown",n,{capture:!0}),window.removeEventListener("wheel",e)}),[n,e]);const w=r?{inert:"true",tabIndex:-1,"aria-hidden":!0}:{inert:void 0,tabIndex:void 0,"aria-hidden":!1};return i.createElement(y.Provider,{value:{...h(c,{backgroundInertness:r,setBackgroundInertness:a,modality:p})}},i.createElement("div",{...w},u))};b.displayName="FocusProvider";export{b as FocusProvider};
1
+ import React, { useCallback, useEffect, useState } from "react";
2
+ import { FocusContext } from "../contexts/FocusContext.js";
3
+ import { useFocusContext } from "../hooks/useFocusContext.js";
4
+ import { mergeProps } from "../utils/merge-props.js";
5
+ const ignoreMap = [
6
+ "Alt",
7
+ "AltGraph",
8
+ "CapsLock",
9
+ "Control",
10
+ "Fn",
11
+ "FnLock",
12
+ "Hyper",
13
+ "Meta",
14
+ // Command (Mac), in some browsers also Windows-key
15
+ "NumLock",
16
+ "OS",
17
+ // Windows-key
18
+ "ScrollLock",
19
+ "Super",
20
+ // Virtual keyboard key
21
+ "Symbol",
22
+ "SymbolLock"
23
+ ];
24
+ const eventTypeMap = {
25
+ keydown: "keyboard",
26
+ keyup: "keyboard",
27
+ mousedown: "mouse",
28
+ mousemove: "mouse",
29
+ MSPointerDown: "pointer",
30
+ MSPointerMove: "pointer",
31
+ pointerdown: "pointer",
32
+ pointermove: "pointer",
33
+ touchstart: "touch",
34
+ touchend: "touch",
35
+ wheel: "wheel"
36
+ };
37
+ const navigationalKeys = [
38
+ "Tab",
39
+ "Esc",
40
+ "Escape",
41
+ " ",
42
+ "ArrowDown",
43
+ "Down",
44
+ "ArrowUp",
45
+ "Up",
46
+ "ArrowLeft",
47
+ "Left",
48
+ "ArrowRight",
49
+ "Right",
50
+ "End",
51
+ "Home",
52
+ "PageDown",
53
+ "PageUp"
54
+ ];
55
+ const FocusProvider = ({ children }) => {
56
+ const [backgroundInertness, setBackgroundInertness] = useState(false);
57
+ const focusContext = useFocusContext();
58
+ const [modality, setModality] = useState("unknown");
59
+ const setKeyboardInputModality = useCallback((event) => {
60
+ if (ignoreMap.includes(event.key)) {
61
+ setModality("pointer");
62
+ return;
63
+ }
64
+ if (!event.target || navigationalKeys.includes(event.key)) {
65
+ setModality("keyboard");
66
+ }
67
+ }, []);
68
+ const setMouseInputModality = useCallback((event) => {
69
+ switch (eventTypeMap[event.type]) {
70
+ case "touch":
71
+ case "pen":
72
+ return setModality("touch");
73
+ case "mouse":
74
+ case "pointer":
75
+ case "wheel":
76
+ return setModality("pointer");
77
+ default:
78
+ return "unknown";
79
+ }
80
+ }, []);
81
+ useEffect(() => {
82
+ window.addEventListener("pointerdown", setMouseInputModality);
83
+ window.addEventListener("keydown", setKeyboardInputModality, {
84
+ capture: true
85
+ });
86
+ window.addEventListener("wheel", setMouseInputModality);
87
+ return () => {
88
+ window.removeEventListener("pointerdown", setMouseInputModality);
89
+ window.removeEventListener("keydown", setKeyboardInputModality, {
90
+ capture: true
91
+ });
92
+ window.removeEventListener("wheel", setMouseInputModality);
93
+ };
94
+ }, [setKeyboardInputModality, setMouseInputModality]);
95
+ const focusProps = backgroundInertness ? {
96
+ inert: "true",
97
+ tabIndex: -1,
98
+ "aria-hidden": true
99
+ } : { inert: void 0, tabIndex: void 0, "aria-hidden": false };
100
+ return /* @__PURE__ */ React.createElement(
101
+ FocusContext.Provider,
102
+ {
103
+ value: {
104
+ ...mergeProps(focusContext, {
105
+ backgroundInertness,
106
+ setBackgroundInertness,
107
+ modality
108
+ })
109
+ }
110
+ },
111
+ /* @__PURE__ */ React.createElement("div", { ...focusProps }, children)
112
+ );
113
+ };
114
+ FocusProvider["displayName"] = "FocusProvider";
115
+ export {
116
+ FocusProvider
117
+ };
2
118
  //# sourceMappingURL=FocusProvider.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/providers/FocusProvider.tsx"],
4
4
  "sourcesContent": ["import React, { useCallback, useEffect, useState } from 'react';\n\nimport { FocusContext } from '../contexts/FocusContext.js';\nimport { useFocusContext } from '../hooks/useFocusContext.js';\nimport type { WithChildren } from '../types/with-children.js';\nimport { mergeProps } from '../utils/merge-props.js';\n\n// list of modifier keys commonly used in a mouse or keyboard combination,\n// see https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values#modifier_keys.\nconst ignoreMap = [\n 'Alt',\n 'AltGraph',\n 'CapsLock',\n 'Control',\n 'Fn',\n 'FnLock',\n 'Hyper',\n 'Meta', // Command (Mac), in some browsers also Windows-key\n 'NumLock',\n 'OS', // Windows-key\n 'ScrollLock',\n 'Super', // Virtual keyboard key\n 'Symbol',\n 'SymbolLock',\n];\n\n/** Look-up map of all event types and the corresponding modalities. */\nconst eventTypeMap: Record<string, string> = {\n keydown: 'keyboard',\n keyup: 'keyboard',\n mousedown: 'mouse',\n mousemove: 'mouse',\n MSPointerDown: 'pointer',\n MSPointerMove: 'pointer',\n pointerdown: 'pointer',\n pointermove: 'pointer',\n touchstart: 'touch',\n touchend: 'touch',\n wheel: 'wheel',\n};\n\n/**\n * @internal\n * Type defining the modality options for the focus handling.\n */\nexport type Modality = 'keyboard' | 'pointer' | 'touch' | 'unknown';\n\n/**\n * All navigational keys that should be considered keyboard users,\n * see https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values#navigation_keys\n */\nconst navigationalKeys = [\n 'Tab',\n 'Esc',\n 'Escape',\n ' ',\n 'ArrowDown',\n 'Down',\n 'ArrowUp',\n 'Up',\n 'ArrowLeft',\n 'Left',\n 'ArrowRight',\n 'Right',\n 'End',\n 'Home',\n 'PageDown',\n 'PageUp',\n];\n\n/**\n * @internal\n *\n * Provider that can be reused in components for storing the focus context props.\n * Loosely inspired by [what-input-js](https://github.com/ten1seven/what-input/blob/main/src/scripts/what-input.js).\n */\nexport const FocusProvider = ({ children }: WithChildren) => {\n const [backgroundInertness, setBackgroundInertness] = useState(false);\n const focusContext = useFocusContext();\n const [modality, setModality] = useState<Modality>('unknown');\n\n const setKeyboardInputModality = useCallback((event: KeyboardEvent) => {\n if (ignoreMap.includes(event.key)) {\n setModality('pointer');\n return;\n }\n\n if (!event.target || navigationalKeys.includes(event.key)) {\n setModality('keyboard');\n }\n }, []);\n\n const setMouseInputModality = useCallback((event: MouseEvent) => {\n switch (eventTypeMap[event.type]) {\n case 'touch':\n case 'pen':\n return setModality('touch');\n case 'mouse':\n case 'pointer':\n case 'wheel':\n return setModality('pointer');\n default:\n return 'unknown';\n }\n }, []);\n\n useEffect(() => {\n window.addEventListener('pointerdown', setMouseInputModality);\n // we need to rely on the keydown event (already in the capture phase) here so we don't break usages where the event default behavior is prevented or propagation is stopped,\n // which would otherwise get the wrong, initial, modality (unknown); by using the capture phase, we can ensure we set the modality correctly before the other events occur\n window.addEventListener('keydown', setKeyboardInputModality, {\n capture: true,\n });\n window.addEventListener('wheel', setMouseInputModality);\n\n return () => {\n window.removeEventListener('pointerdown', setMouseInputModality);\n window.removeEventListener('keydown', setKeyboardInputModality, {\n capture: true,\n });\n window.removeEventListener('wheel', setMouseInputModality);\n };\n }, [setKeyboardInputModality, setMouseInputModality]);\n\n const focusProps = backgroundInertness\n ? {\n inert: 'true',\n tabIndex: -1,\n 'aria-hidden': true,\n }\n : { inert: undefined, tabIndex: undefined, 'aria-hidden': false };\n\n return (\n <FocusContext.Provider\n value={{\n ...mergeProps(focusContext, {\n backgroundInertness,\n setBackgroundInertness,\n modality,\n }),\n }}\n >\n <div {...focusProps}>{children}</div>\n </FocusContext.Provider>\n );\n};\n\nFocusProvider['displayName'] = 'FocusProvider';\n"],
5
- "mappings": "AAAA,OAAOA,GAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAExD,OAAS,gBAAAC,MAAoB,8BAC7B,OAAS,mBAAAC,MAAuB,8BAEhC,OAAS,cAAAC,MAAkB,0BAI3B,MAAMC,EAAY,CAChB,MACA,WACA,WACA,UACA,KACA,SACA,QACA,OACA,UACA,KACA,aACA,QACA,SACA,YACF,EAGMC,EAAuC,CAC3C,QAAS,WACT,MAAO,WACP,UAAW,QACX,UAAW,QACX,cAAe,UACf,cAAe,UACf,YAAa,UACb,YAAa,UACb,WAAY,QACZ,SAAU,QACV,MAAO,OACT,EAYMC,EAAmB,CACvB,MACA,MACA,SACA,IACA,YACA,OACA,UACA,KACA,YACA,OACA,aACA,QACA,MACA,OACA,WACA,QACF,EAQaC,EAAgB,CAAC,CAAE,SAAAC,CAAS,IAAoB,CAC3D,KAAM,CAACC,EAAqBC,CAAsB,EAAIV,EAAS,EAAK,EAC9DW,EAAeT,EAAgB,EAC/B,CAACU,EAAUC,CAAW,EAAIb,EAAmB,SAAS,EAEtDc,EAA2BhB,EAAaiB,GAAyB,CACrE,GAAIX,EAAU,SAASW,EAAM,GAAG,EAAG,CACjCF,EAAY,SAAS,EACrB,MACF,EAEI,CAACE,EAAM,QAAUT,EAAiB,SAASS,EAAM,GAAG,IACtDF,EAAY,UAAU,CAE1B,EAAG,CAAC,CAAC,EAECG,EAAwBlB,EAAaiB,GAAsB,CAC/D,OAAQV,EAAaU,EAAM,IAAI,EAAG,CAChC,IAAK,QACL,IAAK,MACH,OAAOF,EAAY,OAAO,EAC5B,IAAK,QACL,IAAK,UACL,IAAK,QACH,OAAOA,EAAY,SAAS,EAC9B,QACE,MAAO,SACX,CACF,EAAG,CAAC,CAAC,EAELd,EAAU,KACR,OAAO,iBAAiB,cAAeiB,CAAqB,EAG5D,OAAO,iBAAiB,UAAWF,EAA0B,CAC3D,QAAS,EACX,CAAC,EACD,OAAO,iBAAiB,QAASE,CAAqB,EAE/C,IAAM,CACX,OAAO,oBAAoB,cAAeA,CAAqB,EAC/D,OAAO,oBAAoB,UAAWF,EAA0B,CAC9D,QAAS,EACX,CAAC,EACD,OAAO,oBAAoB,QAASE,CAAqB,CAC3D,GACC,CAACF,EAA0BE,CAAqB,CAAC,EAEpD,MAAMC,EAAaR,EACf,CACE,MAAO,OACP,SAAU,GACV,cAAe,EACjB,EACA,CAAE,MAAO,OAAW,SAAU,OAAW,cAAe,EAAM,EAElE,OACEZ,EAAA,cAACI,EAAa,SAAb,CACC,MAAO,CACL,GAAGE,EAAWQ,EAAc,CAC1B,oBAAAF,EACA,uBAAAC,EACA,SAAAE,CACF,CAAC,CACH,GAEAf,EAAA,cAAC,OAAK,GAAGoB,GAAaT,CAAS,CACjC,CAEJ,EAEAD,EAAc,YAAiB",
6
- "names": ["React", "useCallback", "useEffect", "useState", "FocusContext", "useFocusContext", "mergeProps", "ignoreMap", "eventTypeMap", "navigationalKeys", "FocusProvider", "children", "backgroundInertness", "setBackgroundInertness", "focusContext", "modality", "setModality", "setKeyboardInputModality", "event", "setMouseInputModality", "focusProps"]
5
+ "mappings": "AAAA,OAAO,SAAS,aAAa,WAAW,gBAAgB;AAExD,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAEhC,SAAS,kBAAkB;AAI3B,MAAM,YAAY;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AACF;AAGA,MAAM,eAAuC;AAAA,EAC3C,SAAS;AAAA,EACT,OAAO;AAAA,EACP,WAAW;AAAA,EACX,WAAW;AAAA,EACX,eAAe;AAAA,EACf,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,OAAO;AACT;AAYA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQO,MAAM,gBAAgB,CAAC,EAAE,SAAS,MAAoB;AAC3D,QAAM,CAAC,qBAAqB,sBAAsB,IAAI,SAAS,KAAK;AACpE,QAAM,eAAe,gBAAgB;AACrC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAmB,SAAS;AAE5D,QAAM,2BAA2B,YAAY,CAAC,UAAyB;AACrE,QAAI,UAAU,SAAS,MAAM,GAAG,GAAG;AACjC,kBAAY,SAAS;AACrB;AAAA,IACF;AAEA,QAAI,CAAC,MAAM,UAAU,iBAAiB,SAAS,MAAM,GAAG,GAAG;AACzD,kBAAY,UAAU;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,QAAM,wBAAwB,YAAY,CAAC,UAAsB;AAC/D,YAAQ,aAAa,MAAM,IAAI,GAAG;AAAA,MAChC,KAAK;AAAA,MACL,KAAK;AACH,eAAO,YAAY,OAAO;AAAA,MAC5B,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AACH,eAAO,YAAY,SAAS;AAAA,MAC9B;AACE,eAAO;AAAA,IACX;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,WAAO,iBAAiB,eAAe,qBAAqB;AAG5D,WAAO,iBAAiB,WAAW,0BAA0B;AAAA,MAC3D,SAAS;AAAA,IACX,CAAC;AACD,WAAO,iBAAiB,SAAS,qBAAqB;AAEtD,WAAO,MAAM;AACX,aAAO,oBAAoB,eAAe,qBAAqB;AAC/D,aAAO,oBAAoB,WAAW,0BAA0B;AAAA,QAC9D,SAAS;AAAA,MACX,CAAC;AACD,aAAO,oBAAoB,SAAS,qBAAqB;AAAA,IAC3D;AAAA,EACF,GAAG,CAAC,0BAA0B,qBAAqB,CAAC;AAEpD,QAAM,aAAa,sBACf;AAAA,IACE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,eAAe;AAAA,EACjB,IACA,EAAE,OAAO,QAAW,UAAU,QAAW,eAAe,MAAM;AAElE,SACE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL,GAAG,WAAW,cAAc;AAAA,UAC1B;AAAA,UACA;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAAA;AAAA,IAEA,oCAAC,SAAK,GAAG,cAAa,QAAS;AAAA,EACjC;AAEJ;AAEA,cAAc,aAAa,IAAI;",
6
+ "names": []
7
7
  }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=masking-props.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,2 +1,15 @@
1
- import{isFocusable as r}from"./is-focusable.js";const o=t=>{if(!r(t))return!1;try{t.focus({preventScroll:!0})}catch{}return document.activeElement===t};export{o as attemptFocus};
1
+ import { isFocusable } from "./is-focusable.js";
2
+ const attemptFocus = (element) => {
3
+ if (!isFocusable(element)) {
4
+ return false;
5
+ }
6
+ try {
7
+ element.focus({ preventScroll: true });
8
+ } catch (e) {
9
+ }
10
+ return document.activeElement === element;
11
+ };
12
+ export {
13
+ attemptFocus
14
+ };
2
15
  //# sourceMappingURL=attempt-focus.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/core/utils/focus-management/attempt-focus.ts"],
4
4
  "sourcesContent": ["import { isFocusable } from './is-focusable.js';\n\n/**\n * @internal\n *\n * Set Attempt to set focus on the current node.\n * @param element - The node to attempt to focus on.\n * @returns - true if element is focused.\n */\nexport const attemptFocus = (element: HTMLElement) => {\n if (!isFocusable(element)) {\n return false;\n }\n\n try {\n element.focus({ preventScroll: true });\n } catch (e) {\n // continue regardless of error\n }\n\n return document.activeElement === element;\n};\n"],
5
- "mappings": "AAAA,OAAS,eAAAA,MAAmB,oBASrB,MAAMC,EAAgBC,GAAyB,CACpD,GAAI,CAACF,EAAYE,CAAO,EACtB,MAAO,GAGT,GAAI,CACFA,EAAQ,MAAM,CAAE,cAAe,EAAK,CAAC,CACvC,MAAY,CAEZ,CAEA,OAAO,SAAS,gBAAkBA,CACpC",
6
- "names": ["isFocusable", "attemptFocus", "element"]
5
+ "mappings": "AAAA,SAAS,mBAAmB;AASrB,MAAM,eAAe,CAAC,YAAyB;AACpD,MAAI,CAAC,YAAY,OAAO,GAAG;AACzB,WAAO;AAAA,EACT;AAEA,MAAI;AACF,YAAQ,MAAM,EAAE,eAAe,KAAK,CAAC;AAAA,EACvC,SAAS,GAAG;AAAA,EAEZ;AAEA,SAAO,SAAS,kBAAkB;AACpC;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,17 @@
1
- import{attemptFocus as n}from"./attempt-focus.js";const l=t=>{if(!t)return!1;for(let r=0;r<t.children.length;r++){const e=t.children[r];if(n(e)||l(e))return!0}return!1};export{l as focusFirstDescendant};
1
+ import { attemptFocus } from "./attempt-focus.js";
2
+ const focusFirstDescendant = (element) => {
3
+ if (!element) {
4
+ return false;
5
+ }
6
+ for (let i = 0; i < element.children.length; i++) {
7
+ const child = element.children[i];
8
+ if (attemptFocus(child) || focusFirstDescendant(child)) {
9
+ return true;
10
+ }
11
+ }
12
+ return false;
13
+ };
14
+ export {
15
+ focusFirstDescendant
16
+ };
2
17
  //# sourceMappingURL=focus-first-descendant.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/core/utils/focus-management/focus-first-descendant.ts"],
4
4
  "sourcesContent": ["import { attemptFocus } from './attempt-focus.js';\n\n/**\n * @internal\n *\n * Set focus on descendant nodes until the first focusable element is found.\n * @param element - DOM node for which to find the first focusable descendant.\n * @returns true if a focusable element is found and focus is set.\n */\nexport const focusFirstDescendant = (element: HTMLElement | null) => {\n if (!element) {\n return false;\n }\n\n for (let i = 0; i < element.children.length; i++) {\n const child = element.children[i] as HTMLElement;\n if (attemptFocus(child) || focusFirstDescendant(child)) {\n return true;\n }\n }\n\n return false;\n};\n"],
5
- "mappings": "AAAA,OAAS,gBAAAA,MAAoB,qBAStB,MAAMC,EAAwBC,GAAgC,CACnE,GAAI,CAACA,EACH,MAAO,GAGT,QAASC,EAAI,EAAGA,EAAID,EAAQ,SAAS,OAAQC,IAAK,CAChD,MAAMC,EAAQF,EAAQ,SAASC,CAAC,EAChC,GAAIH,EAAaI,CAAK,GAAKH,EAAqBG,CAAK,EACnD,MAAO,EAEX,CAEA,MAAO,EACT",
6
- "names": ["attemptFocus", "focusFirstDescendant", "element", "i", "child"]
5
+ "mappings": "AAAA,SAAS,oBAAoB;AAStB,MAAM,uBAAuB,CAAC,YAAgC;AACnE,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,QAAQ,SAAS,QAAQ,KAAK;AAChD,UAAM,QAAQ,QAAQ,SAAS,CAAC;AAChC,QAAI,aAAa,KAAK,KAAK,qBAAqB,KAAK,GAAG;AACtD,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,14 @@
1
- import{isFocusable as t}from"./is-focusable.js";function n(r){const e=document.createTreeWalker(r);for(;e.nextNode();)if(t(e.currentNode))return e.currentNode;return null}export{n as getFirstFocusableChild};
1
+ import { isFocusable } from "./is-focusable.js";
2
+ function getFirstFocusableChild(container) {
3
+ const treeWalker = document.createTreeWalker(container);
4
+ while (treeWalker.nextNode()) {
5
+ if (isFocusable(treeWalker.currentNode)) {
6
+ return treeWalker.currentNode;
7
+ }
8
+ }
9
+ return null;
10
+ }
11
+ export {
12
+ getFirstFocusableChild
13
+ };
2
14
  //# sourceMappingURL=get-first-focusable-child.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/core/utils/focus-management/get-first-focusable-child.ts"],
4
4
  "sourcesContent": ["import { isFocusable } from './is-focusable.js';\n\n/**\n * @internal\n *\n * If you need access to the first focusable descendant of a container, you can use\n * `getFirstFocusableChild`. The function uses the\n * https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker to\n * iterate over the children of the container and returns either a `Node` if a\n * focusable element is found, or `null`.\n */\nexport function getFirstFocusableChild(\n container: HTMLElement | Node,\n): Node | null {\n const treeWalker = document.createTreeWalker(container);\n\n // Iterate over all the nodes inside the container and return the current node if it is focusable.\n while (treeWalker.nextNode()) {\n if (isFocusable(treeWalker.currentNode)) {\n return treeWalker.currentNode;\n }\n }\n\n return null;\n}\n"],
5
- "mappings": "AAAA,OAAS,eAAAA,MAAmB,oBAWrB,SAASC,EACdC,EACa,CACb,MAAMC,EAAa,SAAS,iBAAiBD,CAAS,EAGtD,KAAOC,EAAW,SAAS,GACzB,GAAIH,EAAYG,EAAW,WAAW,EACpC,OAAOA,EAAW,YAItB,OAAO,IACT",
6
- "names": ["isFocusable", "getFirstFocusableChild", "container", "treeWalker"]
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAWrB,SAAS,uBACd,WACa;AACb,QAAM,aAAa,SAAS,iBAAiB,SAAS;AAGtD,SAAO,WAAW,SAAS,GAAG;AAC5B,QAAI,YAAY,WAAW,WAAW,GAAG;AACvC,aAAO,WAAW;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,17 @@
1
- import{isFocusable as l}from"./is-focusable.js";function o(r){const e=document.createTreeWalker(r);for(;e.lastChild();)e.lastChild();do if(l(e.currentNode))return e.currentNode;while(e.previousNode());return null}export{o as getLastFocusableChild};
1
+ import { isFocusable } from "./is-focusable.js";
2
+ function getLastFocusableChild(container) {
3
+ const treeWalker = document.createTreeWalker(container);
4
+ while (treeWalker.lastChild()) {
5
+ treeWalker.lastChild();
6
+ }
7
+ do {
8
+ if (isFocusable(treeWalker.currentNode)) {
9
+ return treeWalker.currentNode;
10
+ }
11
+ } while (treeWalker.previousNode());
12
+ return null;
13
+ }
14
+ export {
15
+ getLastFocusableChild
16
+ };
2
17
  //# sourceMappingURL=get-last-focusable-child.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/core/utils/focus-management/get-last-focusable-child.ts"],
4
4
  "sourcesContent": ["import { isFocusable } from './is-focusable.js';\n\n/**\n * @internal\n *\n * If you need access to the last focusable descendant of a container, you can use\n * `getLastFocusableChild`. The function uses the\n * https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker to\n * iterate over the children of the container and returns either a `Node` if a\n * focusable element is found, or `null`.\n */\nexport function getLastFocusableChild(container: HTMLElement): Node | null {\n const treeWalker = document.createTreeWalker(container);\n\n // Move the current node to the last node of the container.\n while (treeWalker.lastChild()) {\n treeWalker.lastChild();\n }\n\n // Iterate backwards over all the nodes inside the container and return the current node if it is focusable.\n do {\n if (isFocusable(treeWalker.currentNode)) {\n return treeWalker.currentNode;\n }\n } while (treeWalker.previousNode());\n\n return null;\n}\n"],
5
- "mappings": "AAAA,OAAS,eAAAA,MAAmB,oBAWrB,SAASC,EAAsBC,EAAqC,CACzE,MAAMC,EAAa,SAAS,iBAAiBD,CAAS,EAGtD,KAAOC,EAAW,UAAU,GAC1BA,EAAW,UAAU,EAIvB,EACE,IAAIH,EAAYG,EAAW,WAAW,EACpC,OAAOA,EAAW,kBAEbA,EAAW,aAAa,GAEjC,OAAO,IACT",
6
- "names": ["isFocusable", "getLastFocusableChild", "container", "treeWalker"]
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAWrB,SAAS,sBAAsB,WAAqC;AACzE,QAAM,aAAa,SAAS,iBAAiB,SAAS;AAGtD,SAAO,WAAW,UAAU,GAAG;AAC7B,eAAW,UAAU;AAAA,EACvB;AAGA,KAAG;AACD,QAAI,YAAY,WAAW,WAAW,GAAG;AACvC,aAAO,WAAW;AAAA,IACpB;AAAA,EACF,SAAS,WAAW,aAAa;AAEjC,SAAO;AACT;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,21 @@
1
- function r(a){if(a.tabIndex<0||a.disabled)return!1;switch(a.nodeName){case"A":return!!a.href;case"INPUT":return a.type!=="hidden";case"BUTTON":case"SELECT":case"TEXTAREA":return!0;default:return a.tabIndex>=0}}export{r as isFocusable};
1
+ function isFocusable(element) {
2
+ if (element.tabIndex < 0 || element.disabled) {
3
+ return false;
4
+ }
5
+ switch (element.nodeName) {
6
+ case "A":
7
+ return !!element.href;
8
+ case "INPUT":
9
+ return element.type !== "hidden";
10
+ case "BUTTON":
11
+ case "SELECT":
12
+ case "TEXTAREA":
13
+ return true;
14
+ default:
15
+ return element.tabIndex >= 0;
16
+ }
17
+ }
18
+ export {
19
+ isFocusable
20
+ };
2
21
  //# sourceMappingURL=is-focusable.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/core/utils/focus-management/is-focusable.ts"],
4
4
  "sourcesContent": ["/**\n * @internal\n *\n * Use the `isFocusable` utility function to check whether an element can receive\n * focus.\n */\nexport function isFocusable(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n element: any,\n) {\n if (element.tabIndex < 0 || element.disabled) {\n return false;\n }\n\n switch (element.nodeName) {\n case 'A':\n return !!element.href;\n case 'INPUT':\n return element.type !== 'hidden';\n case 'BUTTON':\n case 'SELECT':\n case 'TEXTAREA':\n return true;\n default:\n return element.tabIndex >= 0;\n }\n}\n"],
5
- "mappings": "AAMO,SAASA,EAEdC,EACA,CACA,GAAIA,EAAQ,SAAW,GAAKA,EAAQ,SAClC,MAAO,GAGT,OAAQA,EAAQ,SAAU,CACxB,IAAK,IACH,MAAO,CAAC,CAACA,EAAQ,KACnB,IAAK,QACH,OAAOA,EAAQ,OAAS,SAC1B,IAAK,SACL,IAAK,SACL,IAAK,WACH,MAAO,GACT,QACE,OAAOA,EAAQ,UAAY,CAC/B,CACF",
6
- "names": ["isFocusable", "element"]
5
+ "mappings": "AAMO,SAAS,YAEd,SACA;AACA,MAAI,QAAQ,WAAW,KAAK,QAAQ,UAAU;AAC5C,WAAO;AAAA,EACT;AAEA,UAAQ,QAAQ,UAAU;AAAA,IACxB,KAAK;AACH,aAAO,CAAC,CAAC,QAAQ;AAAA,IACnB,KAAK;AACH,aAAO,QAAQ,SAAS;AAAA,IAC1B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO,QAAQ,YAAY;AAAA,EAC/B;AACF;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,7 @@
1
- const e=!!(typeof window<"u"&&window.document&&window.document.createElement);export{e as isBrowser};
1
+ const isBrowser = (() => {
2
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
3
+ })();
4
+ export {
5
+ isBrowser
6
+ };
2
7
  //# sourceMappingURL=isBrowser.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/utils/isBrowser.ts"],
4
4
  "sourcesContent": ["/**\n * @internal\n *\n * Whether the code is currently executed in a browser\n * @see https://github.com/chakra-ui/chakra-ui/blob/main/packages/utils/src/dom.ts\n */\nexport const isBrowser = (() => {\n return !!(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n );\n})();\n"],
5
- "mappings": "AAMO,MAAMA,EACJ,CAAC,EACN,OAAO,OAAW,KAClB,OAAO,UACP,OAAO,SAAS",
6
- "names": ["isBrowser"]
5
+ "mappings": "AAMO,MAAM,aAAa,MAAM;AAC9B,SAAO,CAAC,EACN,OAAO,WAAW,eAClB,OAAO,YACP,OAAO,SAAS;AAEpB,GAAG;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,32 @@
1
- function c(...t){return(...n)=>{for(const o of t)typeof o=="function"&&o(...n)}}function T(...t){const n={...t[0]};for(let o=1;o<t.length;o++){const s=t[o];for(const e in s){const r=n[e],i=s[e];typeof r=="function"&&typeof i=="function"&&e[0]==="o"&&e[1]==="n"&&e.charCodeAt(2)>=65&&e.charCodeAt(2)<=90?n[e]=c(r,i):n[e]=i!==void 0?i:r}}return n}export{T as mergeProps};
1
+ function chain(...callbacks) {
2
+ return (...args) => {
3
+ for (const callback of callbacks) {
4
+ if (typeof callback === "function") {
5
+ callback(...args);
6
+ }
7
+ }
8
+ };
9
+ }
10
+ function mergeProps(...args) {
11
+ const result = { ...args[0] };
12
+ for (let i = 1; i < args.length; i++) {
13
+ const props = args[i];
14
+ for (const key in props) {
15
+ const a = result[key];
16
+ const b = props[key];
17
+ if (typeof a === "function" && typeof b === "function" && // This is a lot faster than a regex.
18
+ key[0] === "o" && key[1] === "n" && key.charCodeAt(2) >= /* 'A' */
19
+ 65 && key.charCodeAt(2) <= /* 'Z' */
20
+ 90) {
21
+ result[key] = chain(a, b);
22
+ } else {
23
+ result[key] = b !== void 0 ? b : a;
24
+ }
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ export {
30
+ mergeProps
31
+ };
2
32
  //# sourceMappingURL=merge-props.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/utils/merge-props.ts"],
4
4
  "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Calls all functions in the order they were chained with the same arguments.\n */\nfunction chain(...callbacks: any[]): (...args: any[]) => void {\n return (...args: any[]) => {\n for (const callback of callbacks) {\n if (typeof callback === 'function') {\n callback(...args);\n }\n }\n };\n}\n\n// taken from: https://stackoverflow.com/questions/51603250/typescript-3-parameter-list-intersection-type/51604379#51604379\n/**\n * @internal\n * Internal helper mapper type for mergeProps\n */\nexport type TupleTypes<T> = { [P in keyof T]: T[P] } extends {\n [key: number]: infer V;\n}\n ? NullToObject<V>\n : never;\n\n/**\n * @internal\n * Internal helper mapper type for mergeProps\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type NullToObject<T> = T extends null | undefined ? {} : T;\n\n/**\n * @internal\n * Internal helper mapper type for mergeProps\n */\n// eslint-disable-next-line no-undef, @typescript-eslint/no-unused-vars\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * @internal\n *\n * Merges multiple props objects together. Event handlers are chained,\n * classNames are combined, and ids are deduplicated - different ids\n * will trigger a side-effect and re-render components hooked up with `useId`.\n * For all other props, the last prop object overrides all previous ones.\n * @param args - Multiple sets of props to merge together.\n */\nexport function mergeProps<\n T extends (\n | {\n [key: string]: any;\n }\n | null\n | undefined\n )[],\n>(...args: T): UnionToIntersection<TupleTypes<T>> {\n // Start with a base clone of the first argument. This is a lot faster than starting\n // with an empty object and adding properties as we go.\n const result = { ...args[0] };\n for (let i = 1; i < args.length; i++) {\n const props = args[i];\n for (const key in props) {\n const a = result[key];\n const b = props[key];\n\n // Chain events\n if (\n typeof a === 'function' &&\n typeof b === 'function' &&\n // This is a lot faster than a regex.\n key[0] === 'o' &&\n key[1] === 'n' &&\n key.charCodeAt(2) >= /* 'A' */ 65 &&\n key.charCodeAt(2) <= /* 'Z' */ 90\n ) {\n result[key] = chain(a, b);\n } else {\n result[key] = b !== undefined ? b : a;\n }\n }\n }\n\n return result as UnionToIntersection<TupleTypes<T>>;\n}\n"],
5
- "mappings": "AAKA,SAASA,KAASC,EAA4C,CAC5D,MAAO,IAAIC,IAAgB,CACzB,UAAWC,KAAYF,EACjB,OAAOE,GAAa,YACtBA,EAAS,GAAGD,CAAI,CAGtB,CACF,CAwCO,SAASE,KAQXF,EAA6C,CAGhD,MAAMG,EAAS,CAAE,GAAGH,EAAK,CAAC,CAAE,EAC5B,QAASI,EAAI,EAAGA,EAAIJ,EAAK,OAAQI,IAAK,CACpC,MAAMC,EAAQL,EAAKI,CAAC,EACpB,UAAWE,KAAOD,EAAO,CACvB,MAAME,EAAIJ,EAAOG,CAAG,EACdE,EAAIH,EAAMC,CAAG,EAIjB,OAAOC,GAAM,YACb,OAAOC,GAAM,YAEbF,EAAI,CAAC,IAAM,KACXA,EAAI,CAAC,IAAM,KACXA,EAAI,WAAW,CAAC,GAAe,IAC/BA,EAAI,WAAW,CAAC,GAAe,GAE/BH,EAAOG,CAAG,EAAIR,EAAMS,EAAGC,CAAC,EAExBL,EAAOG,CAAG,EAAIE,IAAM,OAAYA,EAAID,CAExC,CACF,CAEA,OAAOJ,CACT",
6
- "names": ["chain", "callbacks", "args", "callback", "mergeProps", "result", "i", "props", "key", "a", "b"]
5
+ "mappings": "AAKA,SAAS,SAAS,WAA4C;AAC5D,SAAO,IAAI,SAAgB;AACzB,eAAW,YAAY,WAAW;AAChC,UAAI,OAAO,aAAa,YAAY;AAClC,iBAAS,GAAG,IAAI;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACF;AAwCO,SAAS,cAQX,MAA6C;AAGhD,QAAM,SAAS,EAAE,GAAG,KAAK,CAAC,EAAE;AAC5B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,QAAQ,KAAK,CAAC;AACpB,eAAW,OAAO,OAAO;AACvB,YAAM,IAAI,OAAO,GAAG;AACpB,YAAM,IAAI,MAAM,GAAG;AAGnB,UACE,OAAO,MAAM,cACb,OAAO,MAAM;AAAA,MAEb,IAAI,CAAC,MAAM,OACX,IAAI,CAAC,MAAM,OACX,IAAI,WAAW,CAAC;AAAA,MAAe,MAC/B,IAAI,WAAW,CAAC;AAAA,MAAe,IAC/B;AACA,eAAO,GAAG,IAAI,MAAM,GAAG,CAAC;AAAA,MAC1B,OAAO;AACL,eAAO,GAAG,IAAI,MAAM,SAAY,IAAI;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
7
  }
package/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export*from"./core/index.js";
1
+ export * from "./core/index.js";
2
2
  //# sourceMappingURL=index.js.map