@react-aria/utils 3.0.0-nightly-641446f65-240905

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 (202) hide show
  1. package/README.md +3 -0
  2. package/dist/chain.main.js +26 -0
  3. package/dist/chain.main.js.map +1 -0
  4. package/dist/chain.mjs +21 -0
  5. package/dist/chain.module.js +21 -0
  6. package/dist/chain.module.js.map +1 -0
  7. package/dist/domHelpers.main.js +19 -0
  8. package/dist/domHelpers.main.js.map +1 -0
  9. package/dist/domHelpers.mjs +13 -0
  10. package/dist/domHelpers.module.js +13 -0
  11. package/dist/domHelpers.module.js.map +1 -0
  12. package/dist/filterDOMProps.main.js +45 -0
  13. package/dist/filterDOMProps.main.js.map +1 -0
  14. package/dist/filterDOMProps.mjs +40 -0
  15. package/dist/filterDOMProps.module.js +40 -0
  16. package/dist/filterDOMProps.module.js.map +1 -0
  17. package/dist/focusWithoutScrolling.main.js +72 -0
  18. package/dist/focusWithoutScrolling.main.js.map +1 -0
  19. package/dist/focusWithoutScrolling.mjs +67 -0
  20. package/dist/focusWithoutScrolling.module.js +67 -0
  21. package/dist/focusWithoutScrolling.module.js.map +1 -0
  22. package/dist/getOffset.main.js +24 -0
  23. package/dist/getOffset.main.js.map +1 -0
  24. package/dist/getOffset.mjs +19 -0
  25. package/dist/getOffset.module.js +19 -0
  26. package/dist/getOffset.module.js.map +1 -0
  27. package/dist/getScrollParent.main.js +28 -0
  28. package/dist/getScrollParent.main.js.map +1 -0
  29. package/dist/getScrollParent.mjs +23 -0
  30. package/dist/getScrollParent.module.js +23 -0
  31. package/dist/getScrollParent.module.js.map +1 -0
  32. package/dist/getScrollParents.main.js +30 -0
  33. package/dist/getScrollParents.main.js.map +1 -0
  34. package/dist/getScrollParents.mjs +25 -0
  35. package/dist/getScrollParents.module.js +25 -0
  36. package/dist/getScrollParents.module.js.map +1 -0
  37. package/dist/import.mjs +81 -0
  38. package/dist/isScrollable.main.js +25 -0
  39. package/dist/isScrollable.main.js.map +1 -0
  40. package/dist/isScrollable.mjs +20 -0
  41. package/dist/isScrollable.module.js +20 -0
  42. package/dist/isScrollable.module.js.map +1 -0
  43. package/dist/isVirtualEvent.main.js +41 -0
  44. package/dist/isVirtualEvent.main.js.map +1 -0
  45. package/dist/isVirtualEvent.mjs +35 -0
  46. package/dist/isVirtualEvent.module.js +35 -0
  47. package/dist/isVirtualEvent.module.js.map +1 -0
  48. package/dist/main.js +138 -0
  49. package/dist/main.js.map +1 -0
  50. package/dist/mergeProps.main.js +51 -0
  51. package/dist/mergeProps.main.js.map +1 -0
  52. package/dist/mergeProps.mjs +42 -0
  53. package/dist/mergeProps.module.js +42 -0
  54. package/dist/mergeProps.module.js.map +1 -0
  55. package/dist/mergeRefs.main.js +28 -0
  56. package/dist/mergeRefs.main.js.map +1 -0
  57. package/dist/mergeRefs.mjs +23 -0
  58. package/dist/mergeRefs.module.js +23 -0
  59. package/dist/mergeRefs.module.js.map +1 -0
  60. package/dist/module.js +81 -0
  61. package/dist/module.js.map +1 -0
  62. package/dist/openLink.main.js +155 -0
  63. package/dist/openLink.main.js.map +1 -0
  64. package/dist/openLink.mjs +140 -0
  65. package/dist/openLink.module.js +140 -0
  66. package/dist/openLink.module.js.map +1 -0
  67. package/dist/platform.main.js +71 -0
  68. package/dist/platform.main.js.map +1 -0
  69. package/dist/platform.mjs +58 -0
  70. package/dist/platform.module.js +58 -0
  71. package/dist/platform.module.js.map +1 -0
  72. package/dist/runAfterTransition.main.js +82 -0
  73. package/dist/runAfterTransition.main.js.map +1 -0
  74. package/dist/runAfterTransition.mjs +77 -0
  75. package/dist/runAfterTransition.module.js +77 -0
  76. package/dist/runAfterTransition.module.js.map +1 -0
  77. package/dist/scrollIntoView.main.js +96 -0
  78. package/dist/scrollIntoView.main.js.map +1 -0
  79. package/dist/scrollIntoView.mjs +90 -0
  80. package/dist/scrollIntoView.module.js +90 -0
  81. package/dist/scrollIntoView.module.js.map +1 -0
  82. package/dist/types.d.ts +229 -0
  83. package/dist/types.d.ts.map +1 -0
  84. package/dist/useDeepMemo.main.js +30 -0
  85. package/dist/useDeepMemo.main.js.map +1 -0
  86. package/dist/useDeepMemo.mjs +25 -0
  87. package/dist/useDeepMemo.module.js +25 -0
  88. package/dist/useDeepMemo.module.js.map +1 -0
  89. package/dist/useDescription.main.js +59 -0
  90. package/dist/useDescription.main.js.map +1 -0
  91. package/dist/useDescription.mjs +54 -0
  92. package/dist/useDescription.module.js +54 -0
  93. package/dist/useDescription.module.js.map +1 -0
  94. package/dist/useDrag1D.main.js +139 -0
  95. package/dist/useDrag1D.main.js.map +1 -0
  96. package/dist/useDrag1D.mjs +134 -0
  97. package/dist/useDrag1D.module.js +134 -0
  98. package/dist/useDrag1D.module.js.map +1 -0
  99. package/dist/useEffectEvent.main.js +37 -0
  100. package/dist/useEffectEvent.main.js.map +1 -0
  101. package/dist/useEffectEvent.mjs +32 -0
  102. package/dist/useEffectEvent.module.js +32 -0
  103. package/dist/useEffectEvent.module.js.map +1 -0
  104. package/dist/useEvent.main.js +42 -0
  105. package/dist/useEvent.main.js.map +1 -0
  106. package/dist/useEvent.mjs +37 -0
  107. package/dist/useEvent.module.js +37 -0
  108. package/dist/useEvent.module.js.map +1 -0
  109. package/dist/useFormReset.main.js +41 -0
  110. package/dist/useFormReset.main.js.map +1 -0
  111. package/dist/useFormReset.mjs +36 -0
  112. package/dist/useFormReset.module.js +36 -0
  113. package/dist/useFormReset.module.js.map +1 -0
  114. package/dist/useGlobalListeners.main.js +63 -0
  115. package/dist/useGlobalListeners.main.js.map +1 -0
  116. package/dist/useGlobalListeners.mjs +58 -0
  117. package/dist/useGlobalListeners.module.js +58 -0
  118. package/dist/useGlobalListeners.module.js.map +1 -0
  119. package/dist/useId.main.js +93 -0
  120. package/dist/useId.main.js.map +1 -0
  121. package/dist/useId.mjs +86 -0
  122. package/dist/useId.module.js +86 -0
  123. package/dist/useId.module.js.map +1 -0
  124. package/dist/useLabels.main.js +44 -0
  125. package/dist/useLabels.main.js.map +1 -0
  126. package/dist/useLabels.mjs +39 -0
  127. package/dist/useLabels.module.js +39 -0
  128. package/dist/useLabels.module.js.map +1 -0
  129. package/dist/useLayoutEffect.main.js +27 -0
  130. package/dist/useLayoutEffect.main.js.map +1 -0
  131. package/dist/useLayoutEffect.mjs +18 -0
  132. package/dist/useLayoutEffect.module.js +18 -0
  133. package/dist/useLayoutEffect.module.js.map +1 -0
  134. package/dist/useLoadMore.main.js +72 -0
  135. package/dist/useLoadMore.main.js.map +1 -0
  136. package/dist/useLoadMore.mjs +67 -0
  137. package/dist/useLoadMore.module.js +67 -0
  138. package/dist/useLoadMore.module.js.map +1 -0
  139. package/dist/useObjectRef.main.js +37 -0
  140. package/dist/useObjectRef.main.js.map +1 -0
  141. package/dist/useObjectRef.mjs +32 -0
  142. package/dist/useObjectRef.module.js +32 -0
  143. package/dist/useObjectRef.module.js.map +1 -0
  144. package/dist/useResizeObserver.main.js +43 -0
  145. package/dist/useResizeObserver.main.js.map +1 -0
  146. package/dist/useResizeObserver.mjs +38 -0
  147. package/dist/useResizeObserver.module.js +38 -0
  148. package/dist/useResizeObserver.module.js.map +1 -0
  149. package/dist/useSyncRef.main.js +32 -0
  150. package/dist/useSyncRef.main.js.map +1 -0
  151. package/dist/useSyncRef.mjs +27 -0
  152. package/dist/useSyncRef.module.js +27 -0
  153. package/dist/useSyncRef.module.js.map +1 -0
  154. package/dist/useUpdateEffect.main.js +38 -0
  155. package/dist/useUpdateEffect.main.js.map +1 -0
  156. package/dist/useUpdateEffect.mjs +33 -0
  157. package/dist/useUpdateEffect.module.js +33 -0
  158. package/dist/useUpdateEffect.module.js.map +1 -0
  159. package/dist/useValueEffect.main.js +58 -0
  160. package/dist/useValueEffect.main.js.map +1 -0
  161. package/dist/useValueEffect.mjs +53 -0
  162. package/dist/useValueEffect.module.js +53 -0
  163. package/dist/useValueEffect.module.js.map +1 -0
  164. package/dist/useViewportSize.main.js +56 -0
  165. package/dist/useViewportSize.main.js.map +1 -0
  166. package/dist/useViewportSize.mjs +51 -0
  167. package/dist/useViewportSize.module.js +51 -0
  168. package/dist/useViewportSize.module.js.map +1 -0
  169. package/package.json +38 -0
  170. package/src/chain.ts +24 -0
  171. package/src/domHelpers.ts +14 -0
  172. package/src/filterDOMProps.ts +76 -0
  173. package/src/focusWithoutScrolling.ts +96 -0
  174. package/src/getOffset.ts +19 -0
  175. package/src/getScrollParent.ts +27 -0
  176. package/src/getScrollParents.ts +26 -0
  177. package/src/index.ts +44 -0
  178. package/src/isScrollable.ts +22 -0
  179. package/src/isVirtualEvent.ts +58 -0
  180. package/src/mergeProps.ts +75 -0
  181. package/src/mergeRefs.ts +32 -0
  182. package/src/openLink.tsx +183 -0
  183. package/src/platform.ts +79 -0
  184. package/src/runAfterTransition.ts +105 -0
  185. package/src/scrollIntoView.ts +109 -0
  186. package/src/useDeepMemo.ts +27 -0
  187. package/src/useDescription.ts +56 -0
  188. package/src/useDrag1D.ts +190 -0
  189. package/src/useEffectEvent.ts +26 -0
  190. package/src/useEvent.ts +37 -0
  191. package/src/useFormReset.ts +36 -0
  192. package/src/useGlobalListeners.ts +51 -0
  193. package/src/useId.ts +108 -0
  194. package/src/useLabels.ts +48 -0
  195. package/src/useLayoutEffect.ts +20 -0
  196. package/src/useLoadMore.ts +82 -0
  197. package/src/useObjectRef.ts +39 -0
  198. package/src/useResizeObserver.ts +48 -0
  199. package/src/useSyncRef.ts +33 -0
  200. package/src/useUpdateEffect.ts +36 -0
  201. package/src/useValueEffect.ts +64 -0
  202. package/src/useViewportSize.ts +63 -0
@@ -0,0 +1,51 @@
1
+ import {useState as $fuDHA$useState, useEffect as $fuDHA$useEffect} from "react";
2
+ import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ // @ts-ignore
17
+ let $5df64b3807dc15ee$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
18
+ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
19
+ let isSSR = (0, $fuDHA$useIsSSR)();
20
+ let [size, setSize] = (0, $fuDHA$useState)(()=>isSSR ? {
21
+ width: 0,
22
+ height: 0
23
+ } : $5df64b3807dc15ee$var$getViewportSize());
24
+ (0, $fuDHA$useEffect)(()=>{
25
+ // Use visualViewport api to track available height even on iOS virtual keyboard opening
26
+ let onResize = ()=>{
27
+ setSize((size)=>{
28
+ let newSize = $5df64b3807dc15ee$var$getViewportSize();
29
+ if (newSize.width === size.width && newSize.height === size.height) return size;
30
+ return newSize;
31
+ });
32
+ };
33
+ if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
34
+ else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
35
+ return ()=>{
36
+ if (!$5df64b3807dc15ee$var$visualViewport) window.removeEventListener('resize', onResize);
37
+ else $5df64b3807dc15ee$var$visualViewport.removeEventListener('resize', onResize);
38
+ };
39
+ }, []);
40
+ return size;
41
+ }
42
+ function $5df64b3807dc15ee$var$getViewportSize() {
43
+ return {
44
+ width: $5df64b3807dc15ee$var$visualViewport && ($5df64b3807dc15ee$var$visualViewport === null || $5df64b3807dc15ee$var$visualViewport === void 0 ? void 0 : $5df64b3807dc15ee$var$visualViewport.width) || window.innerWidth,
45
+ height: $5df64b3807dc15ee$var$visualViewport && ($5df64b3807dc15ee$var$visualViewport === null || $5df64b3807dc15ee$var$visualViewport === void 0 ? void 0 : $5df64b3807dc15ee$var$visualViewport.height) || window.innerHeight
46
+ };
47
+ }
48
+
49
+
50
+ export {$5df64b3807dc15ee$export$d699905dd57c73ca as useViewportSize};
51
+ //# sourceMappingURL=useViewportSize.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAUD,aAAa;AACb,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAEtE,SAAS;IACd,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,eAAO,EAAE,IAAM,QAAQ;YAAC,OAAO;YAAG,QAAQ;QAAC,IAAI;IAErE,CAAA,GAAA,gBAAQ,EAAE;QACR,wFAAwF;QACxF,IAAI,WAAW;YACb,QAAQ,CAAA;gBACN,IAAI,UAAU;gBACd,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA,SAAS;IACP,OAAO;QACL,OAAO,AAAC,yCAAkB,iDAAA,2DAAA,qCAAgB,KAAK,KAAK,OAAO,UAAU;QACrE,QAAQ,AAAC,yCAAkB,iDAAA,2DAAA,qCAAgB,MAAM,KAAK,OAAO,WAAW;IAC1E;AACF","sources":["packages/@react-aria/utils/src/useViewportSize.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\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\n\ninterface ViewportSize {\n width: number,\n height: number\n}\n\n// @ts-ignore\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n let isSSR = useIsSSR();\n let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n useEffect(() => {\n // Use visualViewport api to track available height even on iOS virtual keyboard opening\n let onResize = () => {\n setSize(size => {\n let newSize = getViewportSize();\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n };\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n if (!visualViewport) {\n window.removeEventListener('resize', onResize);\n } else {\n visualViewport.removeEventListener('resize', onResize);\n }\n };\n }, []);\n\n return size;\n}\n\nfunction getViewportSize(): ViewportSize {\n return {\n width: (visualViewport && visualViewport?.width) || window.innerWidth,\n height: (visualViewport && visualViewport?.height) || window.innerHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.module.js.map"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@react-aria/utils",
3
+ "version": "3.0.0-nightly-641446f65-240905",
4
+ "description": "Spectrum UI components in React",
5
+ "license": "Apache-2.0",
6
+ "main": "dist/main.js",
7
+ "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
13
+ "types": "dist/types.d.ts",
14
+ "source": "src/index.ts",
15
+ "files": [
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "sideEffects": false,
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/adobe/react-spectrum"
23
+ },
24
+ "dependencies": {
25
+ "@react-aria/ssr": "^3.0.0-nightly-641446f65-240905",
26
+ "@react-stately/utils": "^3.0.0-nightly-641446f65-240905",
27
+ "@react-types/shared": "^3.0.0-nightly-641446f65-240905",
28
+ "@swc/helpers": "^0.5.0",
29
+ "clsx": "^2.0.0"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "stableVersion": "3.25.2"
38
+ }
package/src/chain.ts ADDED
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /**
14
+ * Calls all functions in the order they were chained with the same arguments.
15
+ */
16
+ export function chain(...callbacks: any[]): (...args: any[]) => void {
17
+ return (...args: any[]) => {
18
+ for (let callback of callbacks) {
19
+ if (typeof callback === 'function') {
20
+ callback(...args);
21
+ }
22
+ }
23
+ };
24
+ }
@@ -0,0 +1,14 @@
1
+ export const getOwnerDocument = (el: Element | null | undefined): Document => {
2
+ return el?.ownerDocument ?? document;
3
+ };
4
+
5
+ export const getOwnerWindow = (
6
+ el: (Window & typeof global) | Element | null | undefined
7
+ ): Window & typeof global => {
8
+ if (el && 'window' in el && el.window === el) {
9
+ return el;
10
+ }
11
+
12
+ const doc = getOwnerDocument(el as Element | null | undefined);
13
+ return doc.defaultView || window;
14
+ };
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {AriaLabelingProps, DOMProps, LinkDOMProps} from '@react-types/shared';
14
+
15
+ const DOMPropNames = new Set([
16
+ 'id'
17
+ ]);
18
+
19
+ const labelablePropNames = new Set([
20
+ 'aria-label',
21
+ 'aria-labelledby',
22
+ 'aria-describedby',
23
+ 'aria-details'
24
+ ]);
25
+
26
+ // See LinkDOMProps in dom.d.ts.
27
+ const linkPropNames = new Set([
28
+ 'href',
29
+ 'hrefLang',
30
+ 'target',
31
+ 'rel',
32
+ 'download',
33
+ 'ping',
34
+ 'referrerPolicy'
35
+ ]);
36
+
37
+ interface Options {
38
+ /**
39
+ * If labelling associated aria properties should be included in the filter.
40
+ */
41
+ labelable?: boolean,
42
+ /** Whether the element is a link and should include DOM props for <a> elements. */
43
+ isLink?: boolean,
44
+ /**
45
+ * A Set of other property names that should be included in the filter.
46
+ */
47
+ propNames?: Set<string>
48
+ }
49
+
50
+ const propRe = /^(data-.*)$/;
51
+
52
+ /**
53
+ * Filters out all props that aren't valid DOM props or defined via override prop obj.
54
+ * @param props - The component props to be filtered.
55
+ * @param opts - Props to override.
56
+ */
57
+ export function filterDOMProps(props: DOMProps & AriaLabelingProps & LinkDOMProps, opts: Options = {}): DOMProps & AriaLabelingProps {
58
+ let {labelable, isLink, propNames} = opts;
59
+ let filteredProps = {};
60
+
61
+ for (const prop in props) {
62
+ if (
63
+ Object.prototype.hasOwnProperty.call(props, prop) && (
64
+ DOMPropNames.has(prop) ||
65
+ (labelable && labelablePropNames.has(prop)) ||
66
+ (isLink && linkPropNames.has(prop)) ||
67
+ propNames?.has(prop) ||
68
+ propRe.test(prop)
69
+ )
70
+ ) {
71
+ filteredProps[prop] = props[prop];
72
+ }
73
+ }
74
+
75
+ return filteredProps;
76
+ }
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {FocusableElement} from '@react-types/shared';
14
+
15
+ // This is a polyfill for element.focus({preventScroll: true});
16
+ // Currently necessary for Safari and old Edge:
17
+ // https://caniuse.com/#feat=mdn-api_htmlelement_focus_preventscroll_option
18
+ // See https://bugs.webkit.org/show_bug.cgi?id=178583
19
+ //
20
+
21
+ // Original licensing for the following methods can be found in the
22
+ // NOTICE file in the root directory of this source tree.
23
+ // See https://github.com/calvellido/focus-options-polyfill
24
+
25
+ interface ScrollableElement {
26
+ element: HTMLElement,
27
+ scrollTop: number,
28
+ scrollLeft: number
29
+ }
30
+
31
+ export function focusWithoutScrolling(element: FocusableElement) {
32
+ if (supportsPreventScroll()) {
33
+ element.focus({preventScroll: true});
34
+ } else {
35
+ let scrollableElements = getScrollableElements(element);
36
+ element.focus();
37
+ restoreScrollPosition(scrollableElements);
38
+ }
39
+ }
40
+
41
+ let supportsPreventScrollCached: boolean | null = null;
42
+ function supportsPreventScroll() {
43
+ if (supportsPreventScrollCached == null) {
44
+ supportsPreventScrollCached = false;
45
+ try {
46
+ let focusElem = document.createElement('div');
47
+ focusElem.focus({
48
+ get preventScroll() {
49
+ supportsPreventScrollCached = true;
50
+ return true;
51
+ }
52
+ });
53
+ } catch (e) {
54
+ // Ignore
55
+ }
56
+ }
57
+
58
+ return supportsPreventScrollCached;
59
+ }
60
+
61
+ function getScrollableElements(element: FocusableElement): ScrollableElement[] {
62
+ let parent = element.parentNode;
63
+ let scrollableElements: ScrollableElement[] = [];
64
+ let rootScrollingElement = document.scrollingElement || document.documentElement;
65
+
66
+ while (parent instanceof HTMLElement && parent !== rootScrollingElement) {
67
+ if (
68
+ parent.offsetHeight < parent.scrollHeight ||
69
+ parent.offsetWidth < parent.scrollWidth
70
+ ) {
71
+ scrollableElements.push({
72
+ element: parent,
73
+ scrollTop: parent.scrollTop,
74
+ scrollLeft: parent.scrollLeft
75
+ });
76
+ }
77
+ parent = parent.parentNode;
78
+ }
79
+
80
+ if (rootScrollingElement instanceof HTMLElement) {
81
+ scrollableElements.push({
82
+ element: rootScrollingElement,
83
+ scrollTop: rootScrollingElement.scrollTop,
84
+ scrollLeft: rootScrollingElement.scrollLeft
85
+ });
86
+ }
87
+
88
+ return scrollableElements;
89
+ }
90
+
91
+ function restoreScrollPosition(scrollableElements: ScrollableElement[]) {
92
+ for (let {element, scrollTop, scrollLeft} of scrollableElements) {
93
+ element.scrollTop = scrollTop;
94
+ element.scrollLeft = scrollLeft;
95
+ }
96
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ export function getOffset(element, reverse, orientation = 'horizontal') {
14
+ let rect = element.getBoundingClientRect();
15
+ if (reverse) {
16
+ return orientation === 'horizontal' ? rect.right : rect.bottom;
17
+ }
18
+ return orientation === 'horizontal' ? rect.left : rect.top;
19
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {isScrollable} from './isScrollable';
14
+
15
+ export function getScrollParent(node: Element, checkForOverflow?: boolean): Element {
16
+ let scrollableNode: Element | null = node;
17
+ if (isScrollable(scrollableNode, checkForOverflow)) {
18
+ scrollableNode = scrollableNode.parentElement;
19
+ }
20
+
21
+ while (scrollableNode && !isScrollable(scrollableNode, checkForOverflow)) {
22
+ scrollableNode = scrollableNode.parentElement;
23
+ }
24
+
25
+ return scrollableNode || document.scrollingElement || document.documentElement;
26
+ }
27
+
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright 2024 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {isScrollable} from './isScrollable';
14
+
15
+ export function getScrollParents(node: Element, checkForOverflow?: boolean): Element[] {
16
+ const scrollParents: Element[] = [];
17
+
18
+ while (node && node !== document.documentElement) {
19
+ if (isScrollable(node, checkForOverflow)) {
20
+ scrollParents.push(node);
21
+ }
22
+ node = node.parentElement as Element;
23
+ }
24
+
25
+ return scrollParents;
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ export {useId, mergeIds, useSlotId} from './useId';
13
+ export {chain} from './chain';
14
+ export {getOwnerDocument, getOwnerWindow} from './domHelpers';
15
+ export {mergeProps} from './mergeProps';
16
+ export {mergeRefs} from './mergeRefs';
17
+ export {filterDOMProps} from './filterDOMProps';
18
+ export {focusWithoutScrolling} from './focusWithoutScrolling';
19
+ export {getOffset} from './getOffset';
20
+ export {openLink, getSyntheticLinkProps, useSyntheticLinkProps, RouterProvider, shouldClientNavigate, useRouter, useLinkProps} from './openLink';
21
+ export {runAfterTransition} from './runAfterTransition';
22
+ export {useDrag1D} from './useDrag1D';
23
+ export {useGlobalListeners} from './useGlobalListeners';
24
+ export {useLabels} from './useLabels';
25
+ export {useObjectRef} from './useObjectRef';
26
+ export {useUpdateEffect} from './useUpdateEffect';
27
+ export {useLayoutEffect} from './useLayoutEffect';
28
+ export {useResizeObserver} from './useResizeObserver';
29
+ export {useSyncRef} from './useSyncRef';
30
+ export {getScrollParent} from './getScrollParent';
31
+ export {getScrollParents} from './getScrollParents';
32
+ export {isScrollable} from './isScrollable';
33
+ export {useViewportSize} from './useViewportSize';
34
+ export {useDescription} from './useDescription';
35
+ export {isMac, isIPhone, isIPad, isIOS, isAppleDevice, isWebKit, isChrome, isAndroid, isFirefox} from './platform';
36
+ export {useEvent} from './useEvent';
37
+ export {useValueEffect} from './useValueEffect';
38
+ export {scrollIntoView, scrollIntoViewport} from './scrollIntoView';
39
+ export {clamp, snapValueToStep} from '@react-stately/utils';
40
+ export {isVirtualClick, isVirtualPointerEvent} from './isVirtualEvent';
41
+ export {useEffectEvent} from './useEffectEvent';
42
+ export {useDeepMemo} from './useDeepMemo';
43
+ export {useFormReset} from './useFormReset';
44
+ export {useLoadMore} from './useLoadMore';
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2024 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ export function isScrollable(node: Element, checkForOverflow?: boolean): boolean {
14
+ let style = window.getComputedStyle(node);
15
+ let isScrollable = /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
16
+
17
+ if (isScrollable && checkForOverflow) {
18
+ isScrollable = node.scrollHeight !== node.clientHeight || node.scrollWidth !== node.clientWidth;
19
+ }
20
+
21
+ return isScrollable;
22
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {isAndroid} from './platform';
14
+
15
+ // Original licensing for the following method can be found in the
16
+ // NOTICE file in the root directory of this source tree.
17
+ // See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
18
+
19
+ // Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
20
+ // click event. This is a method of inferring such clicks. Every browser except
21
+ // IE 11 only sets a zero value of "detail" for click events that are "virtual".
22
+ // However, IE 11 uses a zero value for all click events. For IE 11 we rely on
23
+ // the quirk that it produces click events that are of type PointerEvent, and
24
+ // where only the "virtual" click lacks a pointerType field.
25
+
26
+ export function isVirtualClick(event: MouseEvent | PointerEvent): boolean {
27
+ // JAWS/NVDA with Firefox.
28
+ if ((event as any).mozInputSource === 0 && event.isTrusted) {
29
+ return true;
30
+ }
31
+
32
+ // Android TalkBack's detail value varies depending on the event listener providing the event so we have specific logic here instead
33
+ // If pointerType is defined, event is from a click listener. For events from mousedown listener, detail === 0 is a sufficient check
34
+ // to detect TalkBack virtual clicks.
35
+ if (isAndroid() && (event as PointerEvent).pointerType) {
36
+ return event.type === 'click' && event.buttons === 1;
37
+ }
38
+
39
+ return event.detail === 0 && !(event as PointerEvent).pointerType;
40
+ }
41
+
42
+ export function isVirtualPointerEvent(event: PointerEvent) {
43
+ // If the pointer size is zero, then we assume it's from a screen reader.
44
+ // Android TalkBack double tap will sometimes return a event with width and height of 1
45
+ // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
46
+ // Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
47
+ // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
48
+ // Talkback double tap from Windows Firefox touch screen press
49
+ return (
50
+ (!isAndroid() && event.width === 0 && event.height === 0) ||
51
+ (event.width === 1 &&
52
+ event.height === 1 &&
53
+ event.pressure === 0 &&
54
+ event.detail === 0 &&
55
+ event.pointerType === 'mouse'
56
+ )
57
+ );
58
+ }
@@ -0,0 +1,75 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {chain} from './chain';
14
+ import clsx from 'clsx';
15
+ import {mergeIds} from './useId';
16
+
17
+ interface Props {
18
+ [key: string]: any
19
+ }
20
+
21
+ type PropsArg = Props | null | undefined;
22
+
23
+ // taken from: https://stackoverflow.com/questions/51603250/typescript-3-parameter-list-intersection-type/51604379#51604379
24
+ type TupleTypes<T> = { [P in keyof T]: T[P] } extends { [key: number]: infer V } ? NullToObject<V> : never;
25
+ type NullToObject<T> = T extends (null | undefined) ? {} : T;
26
+ // eslint-disable-next-line no-undef, @typescript-eslint/no-unused-vars
27
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
28
+
29
+ /**
30
+ * Merges multiple props objects together. Event handlers are chained,
31
+ * classNames are combined, and ids are deduplicated - different ids
32
+ * will trigger a side-effect and re-render components hooked up with `useId`.
33
+ * For all other props, the last prop object overrides all previous ones.
34
+ * @param args - Multiple sets of props to merge together.
35
+ */
36
+ export function mergeProps<T extends PropsArg[]>(...args: T): UnionToIntersection<TupleTypes<T>> {
37
+ // Start with a base clone of the first argument. This is a lot faster than starting
38
+ // with an empty object and adding properties as we go.
39
+ let result: Props = {...args[0]};
40
+ for (let i = 1; i < args.length; i++) {
41
+ let props = args[i];
42
+ for (let key in props) {
43
+ let a = result[key];
44
+ let b = props[key];
45
+
46
+ // Chain events
47
+ if (
48
+ typeof a === 'function' &&
49
+ typeof b === 'function' &&
50
+ // This is a lot faster than a regex.
51
+ key[0] === 'o' &&
52
+ key[1] === 'n' &&
53
+ key.charCodeAt(2) >= /* 'A' */ 65 &&
54
+ key.charCodeAt(2) <= /* 'Z' */ 90
55
+ ) {
56
+ result[key] = chain(a, b);
57
+
58
+ // Merge classnames, sometimes classNames are empty string which eval to false, so we just need to do a type check
59
+ } else if (
60
+ (key === 'className' || key === 'UNSAFE_className') &&
61
+ typeof a === 'string' &&
62
+ typeof b === 'string'
63
+ ) {
64
+ result[key] = clsx(a, b);
65
+ } else if (key === 'id' && a && b) {
66
+ result.id = mergeIds(a, b);
67
+ // Override others
68
+ } else {
69
+ result[key] = b !== undefined ? b : a;
70
+ }
71
+ }
72
+ }
73
+
74
+ return result as UnionToIntersection<TupleTypes<T>>;
75
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {ForwardedRef, MutableRefObject} from 'react';
14
+
15
+ /**
16
+ * Merges multiple refs into one. Works with either callback or object refs.
17
+ */
18
+ export function mergeRefs<T>(...refs: Array<ForwardedRef<T> | MutableRefObject<T> | null | undefined>): ForwardedRef<T> {
19
+ if (refs.length === 1 && refs[0]) {
20
+ return refs[0];
21
+ }
22
+
23
+ return (value: T | null) => {
24
+ for (let ref of refs) {
25
+ if (typeof ref === 'function') {
26
+ ref(value);
27
+ } else if (ref != null) {
28
+ ref.current = value;
29
+ }
30
+ }
31
+ };
32
+ }