@react-aria/gridlist 3.7.6-nightly.4555 → 3.7.6-nightly.4558

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,23 +1,8 @@
1
- import {useId as $13Gtr$useId, filterDOMProps as $13Gtr$filterDOMProps, mergeProps as $13Gtr$mergeProps, useSlotId as $13Gtr$useSlotId, chain as $13Gtr$chain, scrollIntoViewport as $13Gtr$scrollIntoViewport, getScrollParent as $13Gtr$getScrollParent, getSyntheticLinkProps as $13Gtr$getSyntheticLinkProps} from "@react-aria/utils";
2
- import {useHighlightSelectionDescription as $13Gtr$useHighlightSelectionDescription, useGridSelectionAnnouncement as $13Gtr$useGridSelectionAnnouncement, useGridSelectionCheckbox as $13Gtr$useGridSelectionCheckbox} from "@react-aria/grid";
3
- import {useHasTabbableChild as $13Gtr$useHasTabbableChild, focusSafely as $13Gtr$focusSafely, getFocusableTreeWalker as $13Gtr$getFocusableTreeWalker} from "@react-aria/focus";
4
- import {useSelectableList as $13Gtr$useSelectableList, useSelectableItem as $13Gtr$useSelectableItem} from "@react-aria/selection";
5
- import {getLastItem as $13Gtr$getLastItem} from "@react-stately/collections";
6
- import {useRef as $13Gtr$useRef} from "react";
7
- import {isFocusVisible as $13Gtr$isFocusVisible} from "@react-aria/interactions";
8
- import {useLocale as $13Gtr$useLocale} from "@react-aria/i18n";
1
+ import {useGridList as $f47efb0c3a859cf2$export$664f9155035607eb} from "./useGridList.mjs";
2
+ import {useGridListItem as $4e8b0456ef72939f$export$9610e69494fadfd2} from "./useGridListItem.mjs";
3
+ import {useGridListSelectionCheckbox as $e52ffc04a4adbd52$export$e29f2573fabbf7b9} from "./useGridListSelectionCheckbox.mjs";
9
4
 
10
5
  /*
11
- * Copyright 2022 Adobe. All rights reserved.
12
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License. You may obtain a copy
14
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software distributed under
17
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
- * OF ANY KIND, either express or implied. See the License for the specific language
19
- * governing permissions and limitations under the License.
20
- */ /*
21
6
  * Copyright 2022 Adobe. All rights reserved.
22
7
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
23
8
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -28,321 +13,6 @@ import {useLocale as $13Gtr$useLocale} from "@react-aria/i18n";
28
13
  * OF ANY KIND, either express or implied. See the License for the specific language
29
14
  * governing permissions and limitations under the License.
30
15
  */
31
- /*
32
- * Copyright 2020 Adobe. All rights reserved.
33
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
34
- * you may not use this file except in compliance with the License. You may obtain a copy
35
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
36
- *
37
- * Unless required by applicable law or agreed to in writing, software distributed under
38
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
39
- * OF ANY KIND, either express or implied. See the License for the specific language
40
- * governing permissions and limitations under the License.
41
- */ const $ce9b18daab526bbd$export$5b9bb410392e3991 = new WeakMap();
42
- function $ce9b18daab526bbd$export$f45c25170b9a99c2(state, key) {
43
- let { id: id } = $ce9b18daab526bbd$export$5b9bb410392e3991.get(state);
44
- if (!id) throw new Error("Unknown list");
45
- return `${id}-${$ce9b18daab526bbd$export$e0c709538cb8ae18(key)}`;
46
- }
47
- function $ce9b18daab526bbd$export$e0c709538cb8ae18(key) {
48
- if (typeof key === "string") return key.replace(/\s*/g, "");
49
- return "" + key;
50
- }
51
-
52
-
53
-
54
-
55
-
56
- function $f47efb0c3a859cf2$export$664f9155035607eb(props, state, ref) {
57
- let { isVirtualized: isVirtualized, keyboardDelegate: keyboardDelegate, onAction: onAction, linkBehavior: linkBehavior = "action" } = props;
58
- if (!props["aria-label"] && !props["aria-labelledby"]) console.warn("An aria-label or aria-labelledby prop is required for accessibility.");
59
- let { listProps: listProps } = (0, $13Gtr$useSelectableList)({
60
- selectionManager: state.selectionManager,
61
- collection: state.collection,
62
- disabledKeys: state.disabledKeys,
63
- ref: ref,
64
- keyboardDelegate: keyboardDelegate,
65
- isVirtualized: isVirtualized,
66
- selectOnFocus: state.selectionManager.selectionBehavior === "replace",
67
- shouldFocusWrap: props.shouldFocusWrap,
68
- linkBehavior: linkBehavior
69
- });
70
- let id = (0, $13Gtr$useId)(props.id);
71
- (0, $ce9b18daab526bbd$export$5b9bb410392e3991).set(state, {
72
- id: id,
73
- onAction: onAction,
74
- linkBehavior: linkBehavior
75
- });
76
- let descriptionProps = (0, $13Gtr$useHighlightSelectionDescription)({
77
- selectionManager: state.selectionManager,
78
- hasItemActions: !!onAction
79
- });
80
- let hasTabbableChild = (0, $13Gtr$useHasTabbableChild)(ref, {
81
- isDisabled: state.collection.size !== 0
82
- });
83
- let domProps = (0, $13Gtr$filterDOMProps)(props, {
84
- labelable: true
85
- });
86
- let gridProps = (0, $13Gtr$mergeProps)(domProps, {
87
- role: "grid",
88
- id: id,
89
- "aria-multiselectable": state.selectionManager.selectionMode === "multiple" ? "true" : undefined
90
- }, // If collection is empty, make sure the grid is tabbable unless there is a child tabbable element.
91
- state.collection.size === 0 ? {
92
- tabIndex: hasTabbableChild ? -1 : 0
93
- } : listProps, descriptionProps);
94
- if (isVirtualized) {
95
- gridProps["aria-rowcount"] = state.collection.size;
96
- gridProps["aria-colcount"] = 1;
97
- }
98
- (0, $13Gtr$useGridSelectionAnnouncement)({}, state);
99
- return {
100
- gridProps: gridProps
101
- };
102
- }
103
-
104
-
105
- /*
106
- * Copyright 2022 Adobe. All rights reserved.
107
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
108
- * you may not use this file except in compliance with the License. You may obtain a copy
109
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
110
- *
111
- * Unless required by applicable law or agreed to in writing, software distributed under
112
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
113
- * OF ANY KIND, either express or implied. See the License for the specific language
114
- * governing permissions and limitations under the License.
115
- */
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
- const $4e8b0456ef72939f$var$EXPANSION_KEYS = {
124
- "expand": {
125
- ltr: "ArrowRight",
126
- rtl: "ArrowLeft"
127
- },
128
- "collapse": {
129
- ltr: "ArrowLeft",
130
- rtl: "ArrowRight"
131
- }
132
- };
133
- function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
134
- var _node_props, _node_props1;
135
- // Copied from useGridCell + some modifications to make it not so grid specific
136
- let { node: node, isVirtualized: isVirtualized, shouldSelectOnPressUp: shouldSelectOnPressUp } = props;
137
- let { direction: direction } = (0, $13Gtr$useLocale)();
138
- let { onAction: onAction, linkBehavior: linkBehavior } = (0, $ce9b18daab526bbd$export$5b9bb410392e3991).get(state);
139
- let descriptionId = (0, $13Gtr$useSlotId)();
140
- // We need to track the key of the item at the time it was last focused so that we force
141
- // focus to go to the item when the DOM node is reused for a different item in a virtualizer.
142
- let keyWhenFocused = (0, $13Gtr$useRef)(null);
143
- let focus = ()=>{
144
- var _ref_current;
145
- // Don't shift focus to the row if the active element is a element within the row already
146
- // (e.g. clicking on a row button)
147
- if (keyWhenFocused.current != null && node.key !== keyWhenFocused.current || !((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.contains(document.activeElement))) (0, $13Gtr$focusSafely)(ref.current);
148
- };
149
- let treeGridRowProps = {};
150
- let hasChildRows;
151
- let hasLink = state.selectionManager.isLink(node.key);
152
- if (node != null && "expandedKeys" in state) {
153
- // TODO: ideally node.hasChildNodes would be a way to tell if a row has child nodes, but the row's contents make it so that value is always
154
- // true...
155
- hasChildRows = [
156
- ...state.collection.getChildren(node.key)
157
- ].length > 1;
158
- if (onAction == null && !hasLink && state.selectionManager.selectionMode === "none" && hasChildRows) onAction = ()=>state.toggleKey(node.key);
159
- let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;
160
- treeGridRowProps = {
161
- "aria-expanded": isExpanded,
162
- "aria-level": node.level + 1,
163
- "aria-posinset": (node === null || node === void 0 ? void 0 : node.index) + 1,
164
- "aria-setsize": node.level > 0 ? (0, $13Gtr$getLastItem)(state.collection.getChildren(node === null || node === void 0 ? void 0 : node.parentKey)).index + 1 : [
165
- ...state.collection
166
- ].filter((row)=>row.level === 0).at(-1).index + 1
167
- };
168
- }
169
- let { itemProps: itemProps, ...itemStates } = (0, $13Gtr$useSelectableItem)({
170
- selectionManager: state.selectionManager,
171
- key: node.key,
172
- ref: ref,
173
- isVirtualized: isVirtualized,
174
- shouldSelectOnPressUp: shouldSelectOnPressUp,
175
- onAction: onAction || ((_node_props = node.props) === null || _node_props === void 0 ? void 0 : _node_props.onAction) ? (0, $13Gtr$chain)((_node_props1 = node.props) === null || _node_props1 === void 0 ? void 0 : _node_props1.onAction, onAction ? ()=>onAction(node.key) : undefined) : undefined,
176
- focus: focus,
177
- linkBehavior: linkBehavior
178
- });
179
- let onKeyDown = (e)=>{
180
- if (!e.currentTarget.contains(e.target)) return;
181
- let walker = (0, $13Gtr$getFocusableTreeWalker)(ref.current);
182
- walker.currentNode = document.activeElement;
183
- if ("expandedKeys" in state && document.activeElement === ref.current) {
184
- if (e.key === $4e8b0456ef72939f$var$EXPANSION_KEYS["expand"][direction] && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {
185
- state.toggleKey(node.key);
186
- e.stopPropagation();
187
- return;
188
- } else if (e.key === $4e8b0456ef72939f$var$EXPANSION_KEYS["collapse"][direction] && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {
189
- state.toggleKey(node.key);
190
- e.stopPropagation();
191
- return;
192
- }
193
- }
194
- switch(e.key){
195
- case "ArrowLeft":
196
- {
197
- // Find the next focusable element within the row.
198
- let focusable = direction === "rtl" ? walker.nextNode() : walker.previousNode();
199
- if (focusable) {
200
- e.preventDefault();
201
- e.stopPropagation();
202
- (0, $13Gtr$focusSafely)(focusable);
203
- (0, $13Gtr$scrollIntoViewport)(focusable, {
204
- containingElement: (0, $13Gtr$getScrollParent)(ref.current)
205
- });
206
- } else {
207
- // If there is no next focusable child, then return focus back to the row
208
- e.preventDefault();
209
- e.stopPropagation();
210
- if (direction === "rtl") {
211
- (0, $13Gtr$focusSafely)(ref.current);
212
- (0, $13Gtr$scrollIntoViewport)(ref.current, {
213
- containingElement: (0, $13Gtr$getScrollParent)(ref.current)
214
- });
215
- } else {
216
- walker.currentNode = ref.current;
217
- let lastElement = $4e8b0456ef72939f$var$last(walker);
218
- if (lastElement) {
219
- (0, $13Gtr$focusSafely)(lastElement);
220
- (0, $13Gtr$scrollIntoViewport)(lastElement, {
221
- containingElement: (0, $13Gtr$getScrollParent)(ref.current)
222
- });
223
- }
224
- }
225
- }
226
- break;
227
- }
228
- case "ArrowRight":
229
- {
230
- let focusable = direction === "rtl" ? walker.previousNode() : walker.nextNode();
231
- if (focusable) {
232
- e.preventDefault();
233
- e.stopPropagation();
234
- (0, $13Gtr$focusSafely)(focusable);
235
- (0, $13Gtr$scrollIntoViewport)(focusable, {
236
- containingElement: (0, $13Gtr$getScrollParent)(ref.current)
237
- });
238
- } else {
239
- e.preventDefault();
240
- e.stopPropagation();
241
- if (direction === "ltr") {
242
- (0, $13Gtr$focusSafely)(ref.current);
243
- (0, $13Gtr$scrollIntoViewport)(ref.current, {
244
- containingElement: (0, $13Gtr$getScrollParent)(ref.current)
245
- });
246
- } else {
247
- walker.currentNode = ref.current;
248
- let lastElement = $4e8b0456ef72939f$var$last(walker);
249
- if (lastElement) {
250
- (0, $13Gtr$focusSafely)(lastElement);
251
- (0, $13Gtr$scrollIntoViewport)(lastElement, {
252
- containingElement: (0, $13Gtr$getScrollParent)(ref.current)
253
- });
254
- }
255
- }
256
- }
257
- break;
258
- }
259
- case "ArrowUp":
260
- case "ArrowDown":
261
- // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate
262
- // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still
263
- // bubbles and gets handled by useSelectableCollection.
264
- if (!e.altKey && ref.current.contains(e.target)) {
265
- e.stopPropagation();
266
- e.preventDefault();
267
- ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
268
- }
269
- break;
270
- }
271
- };
272
- let onFocus = (e)=>{
273
- keyWhenFocused.current = node.key;
274
- if (e.target !== ref.current) {
275
- // useSelectableItem only handles setting the focused key when
276
- // the focused element is the row itself. We also want to
277
- // set the focused key when a child element receives focus.
278
- // If focus is currently visible (e.g. the user is navigating with the keyboard),
279
- // then skip this. We want to restore focus to the previously focused row
280
- // in that case since the list should act like a single tab stop.
281
- if (!(0, $13Gtr$isFocusVisible)()) state.selectionManager.setFocusedKey(node.key);
282
- return;
283
- }
284
- };
285
- let linkProps = itemStates.hasAction ? (0, $13Gtr$getSyntheticLinkProps)(node.props) : {};
286
- let rowProps = (0, $13Gtr$mergeProps)(itemProps, linkProps, {
287
- role: "row",
288
- onKeyDownCapture: onKeyDown,
289
- onFocus: onFocus,
290
- "aria-label": node.textValue || undefined,
291
- "aria-selected": state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,
292
- "aria-disabled": state.selectionManager.isDisabled(node.key) || undefined,
293
- "aria-labelledby": descriptionId && node.textValue ? `${(0, $ce9b18daab526bbd$export$f45c25170b9a99c2)(state, node.key)} ${descriptionId}` : undefined,
294
- id: (0, $ce9b18daab526bbd$export$f45c25170b9a99c2)(state, node.key)
295
- });
296
- if (isVirtualized) rowProps["aria-rowindex"] = node.index + 1;
297
- let gridCellProps = {
298
- role: "gridcell",
299
- "aria-colindex": 1
300
- };
301
- // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?
302
- return {
303
- rowProps: {
304
- ...(0, $13Gtr$mergeProps)(rowProps, treeGridRowProps)
305
- },
306
- gridCellProps: gridCellProps,
307
- descriptionProps: {
308
- id: descriptionId
309
- },
310
- ...itemStates
311
- };
312
- }
313
- function $4e8b0456ef72939f$var$last(walker) {
314
- let next;
315
- let last;
316
- do {
317
- last = walker.lastChild();
318
- if (last) next = last;
319
- }while (last);
320
- return next;
321
- }
322
-
323
-
324
- /*
325
- * Copyright 2022 Adobe. All rights reserved.
326
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
327
- * you may not use this file except in compliance with the License. You may obtain a copy
328
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
329
- *
330
- * Unless required by applicable law or agreed to in writing, software distributed under
331
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
332
- * OF ANY KIND, either express or implied. See the License for the specific language
333
- * governing permissions and limitations under the License.
334
- */
335
-
336
- function $e52ffc04a4adbd52$export$e29f2573fabbf7b9(props, state) {
337
- let { key: key } = props;
338
- const { checkboxProps: checkboxProps } = (0, $13Gtr$useGridSelectionCheckbox)(props, state);
339
- return {
340
- checkboxProps: {
341
- ...checkboxProps,
342
- "aria-labelledby": `${checkboxProps.id} ${(0, $ce9b18daab526bbd$export$f45c25170b9a99c2)(state, key)}`
343
- }
344
- };
345
- }
346
16
 
347
17
 
348
18