@react-aria/utils 3.33.0 → 3.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/dist/import.mjs +47 -43
  2. package/dist/main.js +120 -114
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +47 -43
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +45 -0
  7. package/package.json +15 -15
  8. package/src/index.ts +45 -43
  9. package/dist/DOMFunctions.main.js +0 -44
  10. package/dist/DOMFunctions.main.js.map +0 -1
  11. package/dist/DOMFunctions.mjs +0 -37
  12. package/dist/DOMFunctions.module.js +0 -37
  13. package/dist/DOMFunctions.module.js.map +0 -1
  14. package/dist/ShadowTreeWalker.main.js +0 -200
  15. package/dist/ShadowTreeWalker.main.js.map +0 -1
  16. package/dist/ShadowTreeWalker.mjs +0 -194
  17. package/dist/ShadowTreeWalker.module.js +0 -194
  18. package/dist/ShadowTreeWalker.module.js.map +0 -1
  19. package/dist/animation.main.js +0 -97
  20. package/dist/animation.main.js.map +0 -1
  21. package/dist/animation.mjs +0 -91
  22. package/dist/animation.module.js +0 -91
  23. package/dist/animation.module.js.map +0 -1
  24. package/dist/chain.main.js +0 -26
  25. package/dist/chain.main.js.map +0 -1
  26. package/dist/chain.mjs +0 -21
  27. package/dist/chain.module.js +0 -21
  28. package/dist/chain.module.js.map +0 -1
  29. package/dist/constants.main.js +0 -23
  30. package/dist/constants.main.js.map +0 -1
  31. package/dist/constants.mjs +0 -17
  32. package/dist/constants.module.js +0 -17
  33. package/dist/constants.module.js.map +0 -1
  34. package/dist/domHelpers.main.js +0 -28
  35. package/dist/domHelpers.main.js.map +0 -1
  36. package/dist/domHelpers.mjs +0 -21
  37. package/dist/domHelpers.module.js +0 -21
  38. package/dist/domHelpers.module.js.map +0 -1
  39. package/dist/filterDOMProps.main.js +0 -88
  40. package/dist/filterDOMProps.main.js.map +0 -1
  41. package/dist/filterDOMProps.mjs +0 -83
  42. package/dist/filterDOMProps.module.js +0 -83
  43. package/dist/filterDOMProps.module.js.map +0 -1
  44. package/dist/focusWithoutScrolling.main.js +0 -72
  45. package/dist/focusWithoutScrolling.main.js.map +0 -1
  46. package/dist/focusWithoutScrolling.mjs +0 -67
  47. package/dist/focusWithoutScrolling.module.js +0 -67
  48. package/dist/focusWithoutScrolling.module.js.map +0 -1
  49. package/dist/getOffset.main.js +0 -24
  50. package/dist/getOffset.main.js.map +0 -1
  51. package/dist/getOffset.mjs +0 -19
  52. package/dist/getOffset.module.js +0 -19
  53. package/dist/getOffset.module.js.map +0 -1
  54. package/dist/getScrollParent.main.js +0 -28
  55. package/dist/getScrollParent.main.js.map +0 -1
  56. package/dist/getScrollParent.mjs +0 -23
  57. package/dist/getScrollParent.module.js +0 -23
  58. package/dist/getScrollParent.module.js.map +0 -1
  59. package/dist/getScrollParents.main.js +0 -30
  60. package/dist/getScrollParents.main.js.map +0 -1
  61. package/dist/getScrollParents.mjs +0 -25
  62. package/dist/getScrollParents.module.js +0 -25
  63. package/dist/getScrollParents.module.js.map +0 -1
  64. package/dist/inertValue.main.js +0 -19
  65. package/dist/inertValue.main.js.map +0 -1
  66. package/dist/inertValue.mjs +0 -14
  67. package/dist/inertValue.module.js +0 -14
  68. package/dist/inertValue.module.js.map +0 -1
  69. package/dist/isElementVisible.main.js +0 -45
  70. package/dist/isElementVisible.main.js.map +0 -1
  71. package/dist/isElementVisible.mjs +0 -40
  72. package/dist/isElementVisible.module.js +0 -40
  73. package/dist/isElementVisible.module.js.map +0 -1
  74. package/dist/isFocusable.main.js +0 -56
  75. package/dist/isFocusable.main.js.map +0 -1
  76. package/dist/isFocusable.mjs +0 -50
  77. package/dist/isFocusable.module.js +0 -50
  78. package/dist/isFocusable.module.js.map +0 -1
  79. package/dist/isScrollable.main.js +0 -26
  80. package/dist/isScrollable.main.js.map +0 -1
  81. package/dist/isScrollable.mjs +0 -21
  82. package/dist/isScrollable.module.js +0 -21
  83. package/dist/isScrollable.module.js.map +0 -1
  84. package/dist/isVirtualEvent.main.js +0 -41
  85. package/dist/isVirtualEvent.main.js.map +0 -1
  86. package/dist/isVirtualEvent.mjs +0 -35
  87. package/dist/isVirtualEvent.module.js +0 -35
  88. package/dist/isVirtualEvent.module.js.map +0 -1
  89. package/dist/keyboard.main.js +0 -42
  90. package/dist/keyboard.main.js.map +0 -1
  91. package/dist/keyboard.mjs +0 -36
  92. package/dist/keyboard.module.js +0 -36
  93. package/dist/keyboard.module.js.map +0 -1
  94. package/dist/mergeProps.main.js +0 -54
  95. package/dist/mergeProps.main.js.map +0 -1
  96. package/dist/mergeProps.mjs +0 -45
  97. package/dist/mergeProps.module.js +0 -45
  98. package/dist/mergeProps.module.js.map +0 -1
  99. package/dist/mergeRefs.main.js +0 -40
  100. package/dist/mergeRefs.main.js.map +0 -1
  101. package/dist/mergeRefs.mjs +0 -35
  102. package/dist/mergeRefs.module.js +0 -35
  103. package/dist/mergeRefs.module.js.map +0 -1
  104. package/dist/openLink.main.js +0 -169
  105. package/dist/openLink.main.js.map +0 -1
  106. package/dist/openLink.mjs +0 -153
  107. package/dist/openLink.module.js +0 -153
  108. package/dist/openLink.module.js.map +0 -1
  109. package/dist/platform.main.js +0 -73
  110. package/dist/platform.main.js.map +0 -1
  111. package/dist/platform.mjs +0 -60
  112. package/dist/platform.module.js +0 -60
  113. package/dist/platform.module.js.map +0 -1
  114. package/dist/runAfterTransition.main.js +0 -92
  115. package/dist/runAfterTransition.main.js.map +0 -1
  116. package/dist/runAfterTransition.mjs +0 -87
  117. package/dist/runAfterTransition.module.js +0 -87
  118. package/dist/runAfterTransition.module.js.map +0 -1
  119. package/dist/scrollIntoView.main.js +0 -105
  120. package/dist/scrollIntoView.main.js.map +0 -1
  121. package/dist/scrollIntoView.mjs +0 -99
  122. package/dist/scrollIntoView.module.js +0 -99
  123. package/dist/scrollIntoView.module.js.map +0 -1
  124. package/dist/types.d.ts +0 -286
  125. package/dist/types.d.ts.map +0 -1
  126. package/dist/useDeepMemo.main.js +0 -30
  127. package/dist/useDeepMemo.main.js.map +0 -1
  128. package/dist/useDeepMemo.mjs +0 -25
  129. package/dist/useDeepMemo.module.js +0 -25
  130. package/dist/useDeepMemo.module.js.map +0 -1
  131. package/dist/useDescription.main.js +0 -59
  132. package/dist/useDescription.main.js.map +0 -1
  133. package/dist/useDescription.mjs +0 -54
  134. package/dist/useDescription.module.js +0 -54
  135. package/dist/useDescription.module.js.map +0 -1
  136. package/dist/useDrag1D.main.js +0 -141
  137. package/dist/useDrag1D.main.js.map +0 -1
  138. package/dist/useDrag1D.mjs +0 -136
  139. package/dist/useDrag1D.module.js +0 -136
  140. package/dist/useDrag1D.module.js.map +0 -1
  141. package/dist/useEffectEvent.main.js +0 -45
  142. package/dist/useEffectEvent.main.js.map +0 -1
  143. package/dist/useEffectEvent.mjs +0 -36
  144. package/dist/useEffectEvent.module.js +0 -36
  145. package/dist/useEffectEvent.module.js.map +0 -1
  146. package/dist/useEvent.main.js +0 -41
  147. package/dist/useEvent.main.js.map +0 -1
  148. package/dist/useEvent.mjs +0 -36
  149. package/dist/useEvent.module.js +0 -36
  150. package/dist/useEvent.module.js.map +0 -1
  151. package/dist/useFormReset.main.js +0 -39
  152. package/dist/useFormReset.main.js.map +0 -1
  153. package/dist/useFormReset.mjs +0 -34
  154. package/dist/useFormReset.module.js +0 -34
  155. package/dist/useFormReset.module.js.map +0 -1
  156. package/dist/useGlobalListeners.main.js +0 -62
  157. package/dist/useGlobalListeners.main.js.map +0 -1
  158. package/dist/useGlobalListeners.mjs +0 -57
  159. package/dist/useGlobalListeners.module.js +0 -57
  160. package/dist/useGlobalListeners.module.js.map +0 -1
  161. package/dist/useId.main.js +0 -108
  162. package/dist/useId.main.js.map +0 -1
  163. package/dist/useId.mjs +0 -101
  164. package/dist/useId.module.js +0 -101
  165. package/dist/useId.module.js.map +0 -1
  166. package/dist/useLabels.main.js +0 -44
  167. package/dist/useLabels.main.js.map +0 -1
  168. package/dist/useLabels.mjs +0 -39
  169. package/dist/useLabels.module.js +0 -39
  170. package/dist/useLabels.module.js.map +0 -1
  171. package/dist/useLayoutEffect.main.js +0 -27
  172. package/dist/useLayoutEffect.main.js.map +0 -1
  173. package/dist/useLayoutEffect.mjs +0 -18
  174. package/dist/useLayoutEffect.module.js +0 -18
  175. package/dist/useLayoutEffect.module.js.map +0 -1
  176. package/dist/useLoadMore.main.js +0 -73
  177. package/dist/useLoadMore.main.js.map +0 -1
  178. package/dist/useLoadMore.mjs +0 -68
  179. package/dist/useLoadMore.module.js +0 -68
  180. package/dist/useLoadMore.module.js.map +0 -1
  181. package/dist/useLoadMoreSentinel.main.js +0 -58
  182. package/dist/useLoadMoreSentinel.main.js.map +0 -1
  183. package/dist/useLoadMoreSentinel.mjs +0 -53
  184. package/dist/useLoadMoreSentinel.module.js +0 -53
  185. package/dist/useLoadMoreSentinel.module.js.map +0 -1
  186. package/dist/useObjectRef.main.js +0 -58
  187. package/dist/useObjectRef.main.js.map +0 -1
  188. package/dist/useObjectRef.mjs +0 -53
  189. package/dist/useObjectRef.module.js +0 -53
  190. package/dist/useObjectRef.module.js.map +0 -1
  191. package/dist/useResizeObserver.main.js +0 -47
  192. package/dist/useResizeObserver.main.js.map +0 -1
  193. package/dist/useResizeObserver.mjs +0 -42
  194. package/dist/useResizeObserver.module.js +0 -42
  195. package/dist/useResizeObserver.module.js.map +0 -1
  196. package/dist/useSyncRef.main.js +0 -32
  197. package/dist/useSyncRef.main.js.map +0 -1
  198. package/dist/useSyncRef.mjs +0 -27
  199. package/dist/useSyncRef.module.js +0 -27
  200. package/dist/useSyncRef.module.js.map +0 -1
  201. package/dist/useUpdateEffect.main.js +0 -42
  202. package/dist/useUpdateEffect.main.js.map +0 -1
  203. package/dist/useUpdateEffect.mjs +0 -37
  204. package/dist/useUpdateEffect.module.js +0 -37
  205. package/dist/useUpdateEffect.module.js.map +0 -1
  206. package/dist/useUpdateLayoutEffect.main.js +0 -40
  207. package/dist/useUpdateLayoutEffect.main.js.map +0 -1
  208. package/dist/useUpdateLayoutEffect.mjs +0 -35
  209. package/dist/useUpdateLayoutEffect.module.js +0 -35
  210. package/dist/useUpdateLayoutEffect.module.js.map +0 -1
  211. package/dist/useValueEffect.main.js +0 -63
  212. package/dist/useValueEffect.main.js.map +0 -1
  213. package/dist/useValueEffect.mjs +0 -58
  214. package/dist/useValueEffect.module.js +0 -58
  215. package/dist/useValueEffect.module.js.map +0 -1
  216. package/dist/useViewportSize.main.js +0 -79
  217. package/dist/useViewportSize.main.js.map +0 -1
  218. package/dist/useViewportSize.mjs +0 -74
  219. package/dist/useViewportSize.module.js +0 -74
  220. package/dist/useViewportSize.module.js.map +0 -1
  221. package/src/animation.ts +0 -103
  222. package/src/chain.ts +0 -24
  223. package/src/constants.ts +0 -15
  224. package/src/domHelpers.ts +0 -33
  225. package/src/filterDOMProps.ts +0 -127
  226. package/src/focusWithoutScrolling.ts +0 -96
  227. package/src/getOffset.ts +0 -21
  228. package/src/getScrollParent.ts +0 -27
  229. package/src/getScrollParents.ts +0 -26
  230. package/src/inertValue.ts +0 -11
  231. package/src/isElementVisible.ts +0 -75
  232. package/src/isFocusable.ts +0 -56
  233. package/src/isScrollable.ts +0 -25
  234. package/src/isVirtualEvent.ts +0 -58
  235. package/src/keyboard.tsx +0 -48
  236. package/src/mergeProps.ts +0 -77
  237. package/src/mergeRefs.ts +0 -52
  238. package/src/openLink.tsx +0 -201
  239. package/src/platform.ts +0 -78
  240. package/src/runAfterTransition.ts +0 -121
  241. package/src/scrollIntoView.ts +0 -129
  242. package/src/shadowdom/DOMFunctions.ts +0 -71
  243. package/src/shadowdom/ShadowTreeWalker.ts +0 -319
  244. package/src/useDeepMemo.ts +0 -27
  245. package/src/useDescription.ts +0 -56
  246. package/src/useDrag1D.ts +0 -191
  247. package/src/useEffectEvent.ts +0 -30
  248. package/src/useEvent.ts +0 -37
  249. package/src/useFormReset.ts +0 -36
  250. package/src/useGlobalListeners.ts +0 -52
  251. package/src/useId.ts +0 -129
  252. package/src/useLabels.ts +0 -48
  253. package/src/useLayoutEffect.ts +0 -20
  254. package/src/useLoadMore.ts +0 -82
  255. package/src/useLoadMoreSentinel.ts +0 -63
  256. package/src/useObjectRef.ts +0 -69
  257. package/src/useResizeObserver.ts +0 -52
  258. package/src/useSyncRef.ts +0 -33
  259. package/src/useUpdateEffect.ts +0 -39
  260. package/src/useUpdateLayoutEffect.ts +0 -37
  261. package/src/useValueEffect.ts +0 -68
  262. package/src/useViewportSize.ts +0 -96
@@ -1,319 +0,0 @@
1
- // https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/ShadowTreeWalker.ts
2
-
3
- import {nodeContains} from './DOMFunctions';
4
- import {shadowDOM} from '@react-stately/flags';
5
-
6
- export class ShadowTreeWalker implements TreeWalker {
7
- public readonly filter: NodeFilter | null;
8
- public readonly root: Node;
9
- public readonly whatToShow: number;
10
-
11
- private _doc: Document;
12
- private _walkerStack: Array<TreeWalker> = [];
13
- private _currentNode: Node;
14
- private _currentSetFor: Set<TreeWalker> = new Set();
15
-
16
- constructor(
17
- doc: Document,
18
- root: Node,
19
- whatToShow?: number,
20
- filter?: NodeFilter | null
21
- ) {
22
- this._doc = doc;
23
- this.root = root;
24
- this.filter = filter ?? null;
25
- this.whatToShow = whatToShow ?? NodeFilter.SHOW_ALL;
26
- this._currentNode = root;
27
-
28
- this._walkerStack.unshift(
29
- doc.createTreeWalker(root, whatToShow, this._acceptNode)
30
- );
31
-
32
- const shadowRoot = (root as Element).shadowRoot;
33
-
34
- if (shadowRoot) {
35
- const walker = this._doc.createTreeWalker(
36
- shadowRoot,
37
- this.whatToShow,
38
- {acceptNode: this._acceptNode}
39
- );
40
-
41
- this._walkerStack.unshift(walker);
42
- }
43
- }
44
-
45
- private _acceptNode = (node: Node): number => {
46
- if (node.nodeType === Node.ELEMENT_NODE) {
47
- const shadowRoot = (node as Element).shadowRoot;
48
-
49
- if (shadowRoot) {
50
- const walker = this._doc.createTreeWalker(
51
- shadowRoot,
52
- this.whatToShow,
53
- {acceptNode: this._acceptNode}
54
- );
55
-
56
- this._walkerStack.unshift(walker);
57
-
58
- return NodeFilter.FILTER_ACCEPT;
59
- } else {
60
- if (typeof this.filter === 'function') {
61
- return this.filter(node);
62
- } else if (this.filter?.acceptNode) {
63
- return this.filter.acceptNode(node);
64
- } else if (this.filter === null) {
65
- return NodeFilter.FILTER_ACCEPT;
66
- }
67
- }
68
- }
69
-
70
- return NodeFilter.FILTER_SKIP;
71
- };
72
-
73
- public get currentNode(): Node {
74
- return this._currentNode;
75
- }
76
-
77
- public set currentNode(node: Node) {
78
- if (!nodeContains(this.root, node)) {
79
- throw new Error(
80
- 'Cannot set currentNode to a node that is not contained by the root node.'
81
- );
82
- }
83
-
84
- const walkers: TreeWalker[] = [];
85
- let curNode: Node | null | undefined = node;
86
- let currentWalkerCurrentNode = node;
87
-
88
- this._currentNode = node;
89
-
90
- while (curNode && curNode !== this.root) {
91
- if (curNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
92
- const shadowRoot = curNode as ShadowRoot;
93
-
94
- const walker = this._doc.createTreeWalker(
95
- shadowRoot,
96
- this.whatToShow,
97
- {acceptNode: this._acceptNode}
98
- );
99
-
100
- walkers.push(walker);
101
-
102
- walker.currentNode = currentWalkerCurrentNode;
103
-
104
- this._currentSetFor.add(walker);
105
-
106
- curNode = currentWalkerCurrentNode = shadowRoot.host;
107
- } else {
108
- curNode = curNode.parentNode;
109
- }
110
- }
111
-
112
- const walker = this._doc.createTreeWalker(
113
- this.root,
114
- this.whatToShow,
115
- {acceptNode: this._acceptNode}
116
- );
117
-
118
- walkers.push(walker);
119
-
120
- walker.currentNode = currentWalkerCurrentNode;
121
-
122
- this._currentSetFor.add(walker);
123
-
124
- this._walkerStack = walkers;
125
- }
126
-
127
- public get doc(): Document {
128
- return this._doc;
129
- }
130
-
131
- public firstChild(): Node | null {
132
- let currentNode = this.currentNode;
133
- let newNode = this.nextNode();
134
- if (!nodeContains(currentNode, newNode)) {
135
- this.currentNode = currentNode;
136
- return null;
137
- }
138
- if (newNode) {
139
- this.currentNode = newNode;
140
- }
141
- return newNode;
142
- }
143
-
144
- public lastChild(): Node | null {
145
- let walker = this._walkerStack[0];
146
- let newNode = walker.lastChild();
147
- if (newNode) {
148
- this.currentNode = newNode;
149
- }
150
- return newNode;
151
- }
152
-
153
- public nextNode(): Node | null {
154
- const nextNode = this._walkerStack[0].nextNode();
155
-
156
- if (nextNode) {
157
- const shadowRoot = (nextNode as Element).shadowRoot;
158
-
159
- if (shadowRoot) {
160
- let nodeResult: number | undefined;
161
-
162
- if (typeof this.filter === 'function') {
163
- nodeResult = this.filter(nextNode);
164
- } else if (this.filter?.acceptNode) {
165
- nodeResult = this.filter.acceptNode(nextNode);
166
- }
167
-
168
- if (nodeResult === NodeFilter.FILTER_ACCEPT) {
169
- this.currentNode = nextNode;
170
- return nextNode;
171
- }
172
-
173
- // _acceptNode should have added new walker for this shadow,
174
- // go in recursively.
175
- let newNode = this.nextNode();
176
- if (newNode) {
177
- this.currentNode = newNode;
178
- }
179
- return newNode;
180
- }
181
-
182
- if (nextNode) {
183
- this.currentNode = nextNode;
184
- }
185
- return nextNode;
186
- } else {
187
- if (this._walkerStack.length > 1) {
188
- this._walkerStack.shift();
189
-
190
- let newNode = this.nextNode();
191
- if (newNode) {
192
- this.currentNode = newNode;
193
- }
194
- return newNode;
195
- } else {
196
- return null;
197
- }
198
- }
199
- }
200
-
201
- public previousNode(): Node | null {
202
- const currentWalker = this._walkerStack[0];
203
-
204
- if (currentWalker.currentNode === currentWalker.root) {
205
- if (this._currentSetFor.has(currentWalker)) {
206
- this._currentSetFor.delete(currentWalker);
207
-
208
- if (this._walkerStack.length > 1) {
209
- this._walkerStack.shift();
210
- let newNode = this.previousNode();
211
- if (newNode) {
212
- this.currentNode = newNode;
213
- }
214
- return newNode;
215
- } else {
216
- return null;
217
- }
218
- }
219
-
220
- return null;
221
- }
222
-
223
- const previousNode = currentWalker.previousNode();
224
-
225
- if (previousNode) {
226
- const shadowRoot = (previousNode as Element).shadowRoot;
227
-
228
- if (shadowRoot) {
229
- let nodeResult: number | undefined;
230
-
231
- if (typeof this.filter === 'function') {
232
- nodeResult = this.filter(previousNode);
233
- } else if (this.filter?.acceptNode) {
234
- nodeResult = this.filter.acceptNode(previousNode);
235
- }
236
-
237
- if (nodeResult === NodeFilter.FILTER_ACCEPT) {
238
- if (previousNode) {
239
- this.currentNode = previousNode;
240
- }
241
- return previousNode;
242
- }
243
-
244
- // _acceptNode should have added new walker for this shadow,
245
- // go in recursively.
246
- let newNode = this.lastChild();
247
- if (newNode) {
248
- this.currentNode = newNode;
249
- }
250
- return newNode;
251
- }
252
-
253
- if (previousNode) {
254
- this.currentNode = previousNode;
255
- }
256
- return previousNode;
257
- } else {
258
- if (this._walkerStack.length > 1) {
259
- this._walkerStack.shift();
260
-
261
- let newNode = this.previousNode();
262
- if (newNode) {
263
- this.currentNode = newNode;
264
- }
265
- return newNode;
266
- } else {
267
- return null;
268
- }
269
- }
270
- }
271
-
272
- /**
273
- * @deprecated
274
- */
275
- public nextSibling(): Node | null {
276
- // if (__DEV__) {
277
- // throw new Error("Method not implemented.");
278
- // }
279
-
280
- return null;
281
- }
282
-
283
- /**
284
- * @deprecated
285
- */
286
- public previousSibling(): Node | null {
287
- // if (__DEV__) {
288
- // throw new Error("Method not implemented.");
289
- // }
290
-
291
- return null;
292
- }
293
-
294
- /**
295
- * @deprecated
296
- */
297
- public parentNode(): Node | null {
298
- // if (__DEV__) {
299
- // throw new Error("Method not implemented.");
300
- // }
301
-
302
- return null;
303
- }
304
- }
305
-
306
- /**
307
- * ShadowDOM safe version of document.createTreeWalker.
308
- */
309
- export function createShadowTreeWalker(
310
- doc: Document,
311
- root: Node,
312
- whatToShow?: number,
313
- filter?: NodeFilter | null
314
- ): TreeWalker {
315
- if (shadowDOM()) {
316
- return new ShadowTreeWalker(doc, root, whatToShow, filter);
317
- }
318
- return doc.createTreeWalker(root, whatToShow, filter);
319
- }
@@ -1,27 +0,0 @@
1
- /*
2
- * Copyright 2023 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
- /* eslint-disable rulesdir/pure-render */
14
-
15
- import {useRef} from 'react';
16
-
17
- export function useDeepMemo<T>(value: T, isEqual: (a: T, b: T) => boolean): T {
18
- // Using a ref during render is ok here because it's only an optimization – both values are equivalent.
19
- // If a render is thrown away, it'll still work the same no matter if the next render is the same or not.
20
- let lastValue = useRef<T | null>(null);
21
- if (value && lastValue.current && isEqual(value, lastValue.current)) {
22
- value = lastValue.current;
23
- }
24
-
25
- lastValue.current = value;
26
- return value;
27
- }
@@ -1,56 +0,0 @@
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} from '@react-types/shared';
14
- import {useLayoutEffect} from './useLayoutEffect';
15
- import {useState} from 'react';
16
-
17
- let descriptionId = 0;
18
- const descriptionNodes = new Map<string, {refCount: number, element: Element}>();
19
-
20
- export function useDescription(description?: string): AriaLabelingProps {
21
- let [id, setId] = useState<string | undefined>();
22
-
23
- useLayoutEffect(() => {
24
- if (!description) {
25
- return;
26
- }
27
-
28
- let desc = descriptionNodes.get(description);
29
- if (!desc) {
30
- let id = `react-aria-description-${descriptionId++}`;
31
- setId(id);
32
-
33
- let node = document.createElement('div');
34
- node.id = id;
35
- node.style.display = 'none';
36
- node.textContent = description;
37
- document.body.appendChild(node);
38
- desc = {refCount: 0, element: node};
39
- descriptionNodes.set(description, desc);
40
- } else {
41
- setId(desc.element.id);
42
- }
43
-
44
- desc.refCount++;
45
- return () => {
46
- if (desc && --desc.refCount === 0) {
47
- desc.element.remove();
48
- descriptionNodes.delete(description);
49
- }
50
- };
51
- }, [description]);
52
-
53
- return {
54
- 'aria-describedby': description ? id : undefined
55
- };
56
- }
package/src/useDrag1D.ts DELETED
@@ -1,191 +0,0 @@
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
- /* eslint-disable rulesdir/pure-render */
14
-
15
- import {getOffset} from './getOffset';
16
- import {nodeContains} from './shadowdom/DOMFunctions';
17
- import {Orientation} from '@react-types/shared';
18
- import React, {HTMLAttributes, MutableRefObject, useRef} from 'react';
19
-
20
- interface UseDrag1DProps {
21
- containerRef: MutableRefObject<HTMLElement>,
22
- reverse?: boolean,
23
- orientation?: Orientation,
24
- onHover?: (hovered: boolean) => void,
25
- onDrag?: (dragging: boolean) => void,
26
- onPositionChange?: (position: number) => void,
27
- onIncrement?: () => void,
28
- onDecrement?: () => void,
29
- onIncrementToMax?: () => void,
30
- onDecrementToMin?: () => void,
31
- onCollapseToggle?: () => void
32
- }
33
-
34
- // Keep track of elements that we are currently handling dragging for via useDrag1D.
35
- // If there's an ancestor and a descendant both using useDrag1D(), and the user starts
36
- // dragging the descendant, we don't want useDrag1D events to fire for the ancestor.
37
- const draggingElements: HTMLElement[] = [];
38
-
39
- // created for splitview, this should be reusable for things like sliders/dials
40
- // It also handles keyboard events on the target allowing for increment/decrement by a given stepsize as well as minifying/maximizing and toggling between minified and previous size
41
- // It can also take a 'reverse' param to say if we should measure from the right/bottom instead of the top/left
42
- // It can also handle either a vertical or horizontal movement, but not both at the same time
43
-
44
- export function useDrag1D(props: UseDrag1DProps): HTMLAttributes<HTMLElement> {
45
- console.warn('useDrag1D is deprecated, please use `useMove` instead https://react-spectrum.adobe.com/react-aria/useMove.html');
46
- let {containerRef, reverse, orientation, onHover, onDrag, onPositionChange, onIncrement, onDecrement, onIncrementToMax, onDecrementToMin, onCollapseToggle} = props;
47
- let getPosition = (e) => orientation === 'horizontal' ? e.clientX : e.clientY;
48
- let getNextOffset = (e: MouseEvent) => {
49
- let containerOffset = getOffset(containerRef.current, reverse, orientation);
50
- let mouseOffset = getPosition(e);
51
- let nextOffset = reverse ? containerOffset - mouseOffset : mouseOffset - containerOffset;
52
- return nextOffset;
53
- };
54
- let dragging = useRef(false);
55
- let prevPosition = useRef(0);
56
-
57
- // Keep track of the current handlers in a ref so that the events can access them.
58
- let handlers = useRef({onPositionChange, onDrag});
59
- handlers.current.onDrag = onDrag;
60
- handlers.current.onPositionChange = onPositionChange;
61
-
62
- let onMouseDragged = (e: MouseEvent) => {
63
- e.preventDefault();
64
- let nextOffset = getNextOffset(e);
65
- if (!dragging.current) {
66
- dragging.current = true;
67
- if (handlers.current.onDrag) {
68
- handlers.current.onDrag(true);
69
- }
70
- if (handlers.current.onPositionChange) {
71
- handlers.current.onPositionChange(nextOffset);
72
- }
73
- }
74
- if (prevPosition.current === nextOffset) {
75
- return;
76
- }
77
- prevPosition.current = nextOffset;
78
- if (onPositionChange) {
79
- onPositionChange(nextOffset);
80
- }
81
- };
82
-
83
- let onMouseUp = (e: MouseEvent) => {
84
- const target = e.target as HTMLElement;
85
- dragging.current = false;
86
- let nextOffset = getNextOffset(e);
87
- if (handlers.current.onDrag) {
88
- handlers.current.onDrag(false);
89
- }
90
- if (handlers.current.onPositionChange) {
91
- handlers.current.onPositionChange(nextOffset);
92
- }
93
-
94
- draggingElements.splice(draggingElements.indexOf(target), 1);
95
- window.removeEventListener('mouseup', onMouseUp, false);
96
- window.removeEventListener('mousemove', onMouseDragged, false);
97
- };
98
-
99
- let onMouseDown = (e: React.MouseEvent<HTMLElement>) => {
100
- const target = e.currentTarget;
101
- // If we're already handling dragging on a descendant with useDrag1D, then
102
- // we don't want to handle the drag motion on this target as well.
103
- if (draggingElements.some(elt => nodeContains(target, elt))) {
104
- return;
105
- }
106
- draggingElements.push(target);
107
- window.addEventListener('mousemove', onMouseDragged, false);
108
- window.addEventListener('mouseup', onMouseUp, false);
109
- };
110
-
111
- let onMouseEnter = () => {
112
- if (onHover) {
113
- onHover(true);
114
- }
115
- };
116
-
117
- let onMouseOut = () => {
118
- if (onHover) {
119
- onHover(false);
120
- }
121
- };
122
-
123
- let onKeyDown = (e) => {
124
- switch (e.key) {
125
- case 'Left':
126
- case 'ArrowLeft':
127
- if (orientation === 'horizontal') {
128
- e.preventDefault();
129
- if (onDecrement && !reverse) {
130
- onDecrement();
131
- } else if (onIncrement && reverse) {
132
- onIncrement();
133
- }
134
- }
135
- break;
136
- case 'Up':
137
- case 'ArrowUp':
138
- if (orientation === 'vertical') {
139
- e.preventDefault();
140
- if (onDecrement && !reverse) {
141
- onDecrement();
142
- } else if (onIncrement && reverse) {
143
- onIncrement();
144
- }
145
- }
146
- break;
147
- case 'Right':
148
- case 'ArrowRight':
149
- if (orientation === 'horizontal') {
150
- e.preventDefault();
151
- if (onIncrement && !reverse) {
152
- onIncrement();
153
- } else if (onDecrement && reverse) {
154
- onDecrement();
155
- }
156
- }
157
- break;
158
- case 'Down':
159
- case 'ArrowDown':
160
- if (orientation === 'vertical') {
161
- e.preventDefault();
162
- if (onIncrement && !reverse) {
163
- onIncrement();
164
- } else if (onDecrement && reverse) {
165
- onDecrement();
166
- }
167
- }
168
- break;
169
- case 'Home':
170
- e.preventDefault();
171
- if (onDecrementToMin) {
172
- onDecrementToMin();
173
- }
174
- break;
175
- case 'End':
176
- e.preventDefault();
177
- if (onIncrementToMax) {
178
- onIncrementToMax();
179
- }
180
- break;
181
- case 'Enter':
182
- e.preventDefault();
183
- if (onCollapseToggle) {
184
- onCollapseToggle();
185
- }
186
- break;
187
- }
188
- };
189
-
190
- return {onMouseDown, onMouseEnter, onMouseOut, onKeyDown};
191
- }
@@ -1,30 +0,0 @@
1
- /*
2
- * Copyright 2023 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 React, {useCallback, useRef} from 'react';
14
- import {useLayoutEffect} from './useLayoutEffect';
15
-
16
- // Use the earliest effect type possible. useInsertionEffect runs during the mutation phase,
17
- // before all layout effects, but is available only in React 18 and later.
18
- const useEarlyEffect = React['useInsertionEffect'] ?? useLayoutEffect;
19
-
20
- export function useEffectEvent<T extends Function>(fn?: T): T {
21
- const ref = useRef<T | null | undefined>(null);
22
- useEarlyEffect(() => {
23
- ref.current = fn;
24
- }, [fn]);
25
- // @ts-ignore
26
- return useCallback<T>((...args) => {
27
- const f = ref.current!;
28
- return f?.(...args);
29
- }, []);
30
- }
package/src/useEvent.ts DELETED
@@ -1,37 +0,0 @@
1
- /*
2
- * Copyright 2021 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 {RefObject} from '@react-types/shared';
14
- import {useEffect} from 'react';
15
- import {useEffectEvent} from './useEffectEvent';
16
-
17
- export function useEvent<K extends keyof GlobalEventHandlersEventMap>(
18
- ref: RefObject<EventTarget | null>,
19
- event: K | (string & {}),
20
- handler?: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,
21
- options?: boolean | AddEventListenerOptions
22
- ): void {
23
- let handleEvent = useEffectEvent(handler);
24
- let isDisabled = handler == null;
25
-
26
- useEffect(() => {
27
- if (isDisabled || !ref.current) {
28
- return;
29
- }
30
-
31
- let element = ref.current;
32
- element.addEventListener(event, handleEvent as EventListener, options);
33
- return () => {
34
- element.removeEventListener(event, handleEvent as EventListener, options);
35
- };
36
- }, [ref, event, options, isDisabled]);
37
- }
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright 2023 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 {RefObject} from '@react-types/shared';
14
- import {useEffect} from 'react';
15
- import {useEffectEvent} from './useEffectEvent';
16
-
17
- export function useFormReset<T>(
18
- ref: RefObject<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null> | undefined,
19
- initialValue: T,
20
- onReset: (value: T) => void
21
- ): void {
22
- let handleReset = useEffectEvent(() => {
23
- if (onReset) {
24
- onReset(initialValue);
25
- }
26
- });
27
-
28
- useEffect(() => {
29
- let form = ref?.current?.form;
30
-
31
- form?.addEventListener('reset', handleReset);
32
- return () => {
33
- form?.removeEventListener('reset', handleReset);
34
- };
35
- }, [ref]);
36
- }