@react-aria/gridlist 3.9.5 → 3.10.1

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.
@@ -1 +1 @@
1
- {"mappings":";;;;;AC+BA,+BAA+B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,iBAAiB;IAC5E;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAC9B,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED,mCAAmC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,iBAAiB;IACzF;;;;OAIG;IACH,0BAA0B,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;CAC7C;AAED,qCAAqC,CAAC,CAAE,SAAQ,IAAI,CAAC,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC;IACpF,+CAA+C;IAC/C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;CACnD;AAED;IACE,kCAAkC;IAClC,SAAS,EAAE,aAAa,CAAA;CACzB;AAED;;;;;;GAMG;AACH,4BAA4B,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,YAAY,CA8DnI;ACjID;IACE,8GAA8G;IAC9G,IAAI,EAAE,KAAO,OAAO,CAAC,CAAC;IACtB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,wEAAwE;IACxE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,iCAAkC,SAAQ,oBAAoB;IAC5D,sCAAsC;IACtC,QAAQ,EAAE,aAAa,CAAC;IACxB,2DAA2D;IAC3D,aAAa,EAAE,aAAa,CAAC;IAC7B,2DAA2D;IAC3D,gBAAgB,EAAE,aAAa,CAAA;CAChC;AAaD;;;;;GAKG;AACH,gCAAgC,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAmOhK;AC9QD;;;;GAIG;AACH,6CAA6C,CAAC,EAAE,KAAK,EAAE,8BAA8B,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,yBAAyB,CAUrI;ACbD,YAAY,EAAC,8BAA8B,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAC","sources":["packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/utils.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridList.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridListItem.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridListSelectionCheckbox.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/index.ts","packages/@react-aria/gridlist/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useGridList} from './useGridList';\nexport {useGridListItem} from './useGridListItem';\nexport {useGridListSelectionCheckbox} from './useGridListSelectionCheckbox';\n\nexport type {AriaGridListOptions, AriaGridListProps, GridListAria, GridListProps} from './useGridList';\nexport type {AriaGridListItemOptions, GridListItemAria} from './useGridListItem';\nexport type {AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria} from '@react-aria/grid';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;;AC+BA,+BAA+B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,iBAAiB;IAC5E;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAC9B,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED,mCAAmC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,iBAAiB;IACzF;;;;OAIG;IACH,0BAA0B,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;CAC7C;AAED,qCAAqC,CAAC,CAAE,SAAQ,IAAI,CAAC,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC;IACpF,+CAA+C;IAC/C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;CACnD;AAED;IACE,kCAAkC;IAClC,SAAS,EAAE,aAAa,CAAA;CACzB;AAED;;;;;;GAMG;AACH,4BAA4B,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,YAAY,CA8DnI;ACjID;IACE,8GAA8G;IAC9G,IAAI,EAAE,KAAO,OAAO,CAAC,CAAC;IACtB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,wEAAwE;IACxE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,iCAAkC,SAAQ,oBAAoB;IAC5D,sCAAsC;IACtC,QAAQ,EAAE,aAAa,CAAC;IACxB,2DAA2D;IAC3D,aAAa,EAAE,aAAa,CAAC;IAC7B,2DAA2D;IAC3D,gBAAgB,EAAE,aAAa,CAAA;CAChC;AAaD;;;;;GAKG;AACH,gCAAgC,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,gBAAgB,CA8OhK;ACzRD;;;;GAIG;AACH,6CAA6C,CAAC,EAAE,KAAK,EAAE,8BAA8B,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,yBAAyB,CAUrI;ACbD,YAAY,EAAC,8BAA8B,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAC","sources":["packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/utils.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridList.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridListItem.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridListSelectionCheckbox.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/index.ts","packages/@react-aria/gridlist/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useGridList} from './useGridList';\nexport {useGridListItem} from './useGridListItem';\nexport {useGridListSelectionCheckbox} from './useGridListSelectionCheckbox';\n\nexport type {AriaGridListOptions, AriaGridListProps, GridListAria, GridListProps} from './useGridList';\nexport type {AriaGridListItemOptions, GridListItemAria} from './useGridListItem';\nexport type {AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria} from '@react-aria/grid';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -56,26 +56,39 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
56
56
  var _ref_current;
57
57
  // Don't shift focus to the row if the active element is a element within the row already
58
58
  // (e.g. clicking on a row button)
59
- 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, $911qM$reactariafocus.focusSafely)(ref.current);
59
+ if (ref.current !== null && (keyWhenFocused.current != null && node.key !== keyWhenFocused.current || !((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.contains(document.activeElement)))) (0, $911qM$reactariafocus.focusSafely)(ref.current);
60
60
  };
61
61
  let treeGridRowProps = {};
62
62
  let hasChildRows;
63
63
  let hasLink = state.selectionManager.isLink(node.key);
64
64
  if (node != null && 'expandedKeys' in state) {
65
+ var _state_collection_getChildren, _state_collection, _filter_at;
65
66
  // 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
66
67
  // true...
68
+ let children = (_state_collection_getChildren = (_state_collection = state.collection).getChildren) === null || _state_collection_getChildren === void 0 ? void 0 : _state_collection_getChildren.call(_state_collection, node.key);
67
69
  hasChildRows = [
68
- ...state.collection.getChildren(node.key)
70
+ ...children !== null && children !== void 0 ? children : []
69
71
  ].length > 1;
70
72
  if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) onAction = ()=>state.toggleKey(node.key);
71
73
  let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;
74
+ let setSize = 1;
75
+ var _filter_at_index;
76
+ if (node.level > 0 && (node === null || node === void 0 ? void 0 : node.parentKey) != null) {
77
+ let parent = state.collection.getItem(node.parentKey);
78
+ if (parent) {
79
+ var _state_collection_getChildren1, _state_collection1;
80
+ // siblings must exist because our original node exists, same with lastItem
81
+ let siblings = (_state_collection_getChildren1 = (_state_collection1 = state.collection).getChildren) === null || _state_collection_getChildren1 === void 0 ? void 0 : _state_collection_getChildren1.call(_state_collection1, parent.key);
82
+ setSize = (0, $911qM$reactstatelycollections.getLastItem)(siblings).index + 1;
83
+ }
84
+ } else setSize = ((_filter_at_index = (_filter_at = [
85
+ ...state.collection
86
+ ].filter((row)=>row.level === 0).at(-1)) === null || _filter_at === void 0 ? void 0 : _filter_at.index) !== null && _filter_at_index !== void 0 ? _filter_at_index : 0) + 1;
72
87
  treeGridRowProps = {
73
88
  'aria-expanded': isExpanded,
74
89
  'aria-level': node.level + 1,
75
90
  'aria-posinset': (node === null || node === void 0 ? void 0 : node.index) + 1,
76
- 'aria-setsize': node.level > 0 ? (0, $911qM$reactstatelycollections.getLastItem)(state.collection.getChildren(node === null || node === void 0 ? void 0 : node.parentKey)).index + 1 : [
77
- ...state.collection
78
- ].filter((row)=>row.level === 0).at(-1).index + 1
91
+ 'aria-setsize': setSize
79
92
  };
80
93
  }
81
94
  let { itemProps: itemProps, ...itemStates } = (0, $911qM$reactariaselection.useSelectableItem)({
@@ -89,7 +102,7 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
89
102
  linkBehavior: linkBehavior
90
103
  });
91
104
  let onKeyDown = (e)=>{
92
- if (!e.currentTarget.contains(e.target)) return;
105
+ if (!e.currentTarget.contains(e.target) || !ref.current || !document.activeElement) return;
93
106
  let walker = (0, $911qM$reactariafocus.getFocusableTreeWalker)(ref.current);
94
107
  walker.currentNode = document.activeElement;
95
108
  if ('expandedKeys' in state && document.activeElement === ref.current) {
@@ -174,9 +187,10 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
174
187
  // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still
175
188
  // bubbles and gets handled by useSelectableCollection.
176
189
  if (!e.altKey && ref.current.contains(e.target)) {
190
+ var _ref_current_parentElement;
177
191
  e.stopPropagation();
178
192
  e.preventDefault();
179
- ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
193
+ (_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
180
194
  }
181
195
  break;
182
196
  case 'Tab':
@@ -245,8 +259,8 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
245
259
  };
246
260
  }
247
261
  function $f7116f5928c03f32$var$last(walker) {
248
- let next;
249
- let last;
262
+ let next = null;
263
+ let last = null;
250
264
  do {
251
265
  last = walker.lastChild();
252
266
  if (last) next = last;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAuDpH,aAA6B;IAtDrD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,yBACb,qBAAqB,EACtB,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,EAAC,GAAG,CAAA,GAAA,iCAAM,EAAE,GAAG,CAAC;IACvE,IAAI,gBAAgB,CAAA,G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G,qBAAqB,CAAC;IAC7D,gEAAgE;IAChE,uBAAuB;IACvB,kBAAkB;IAClB,uEAAuE;IACvE,wBAAwB;IACxB,sEAAsE;IACtE,4BAA4B;IAC5B,QAAQ;IACR,IAAI;IAEJ,IAAI,WAA0B,CAAA,GAAA,gCAAS,EAAE,WAAW,WAAW;QAC7D,MAAM;QACN,kBAAkB;iBAClB;QACA,6FAA6F;QAC7F,cAAc,KAAK,SAAS,IAAI;QAChC,iBAAiB,MAAM,gBAAgB,CAAC,aAAa,CAAC,KAAK,GAAG,IAAI,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI;QAChH,iBAAiB,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK;QAChE,mBAAmB,iBAAiB,KAAK,SAAS,GAAG,CAAC,EAAE,CAAA,GAAA,kCAAO,EAAE,OAAO,KAAK,GAAG,EAAE,CAAC,EAAE,cAAc,CAAC,GAAG;QACvG,IAAI,CAAA,GAAA,kCAAO,EAAE,OAAO,KAAK,GAAG;IAC9B;IAEA,IAAI,eACF,QAAQ,CAAC,gBAAgB,GAAG,KAAK,KAAK,GAAG;IAG3C,IAAI,gBAAgB;QAClB,MAAM;QACN,iBAAiB;IACnB;IAEA,2FAA2F;IAC3F,OAAO;QACL,UAAU;YAAC,GAAG,CAAA,GAAA,gCAAS,EAAE,UAAU,iBAAiB;QAAA;uBACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI;IACJ,IAAI;IACJ,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, getScrollParent, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\n node: RSNode<unknown>,\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes,\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes,\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes\n}\n\nconst EXPANSION_KEYS = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state);\n let descriptionId = useSlotId();\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused = useRef(null);\n let focus = () => {\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement)\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // 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\n // true...\n hasChildRows = [...state.collection.getChildren(node.key)].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': node.level > 0 ?\n (getLastItem(state.collection.getChildren(node?.parentKey))).index + 1 :\n [...state.collection].filter(row => row.level === 0).at(-1).index + 1\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element)) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n case 'Tab': {\n if (keyboardNavigationBehavior === 'tab') {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = document.activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\n // TODO: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAkEpH,aAA6B;IAjErD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,yBACb,qBAAqB,EACtB,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,EAAC,GAAG,CAAA,GAAA,iCAAM,EAAE,GAAG,CAAC;IACvE,IAAI,gBAAgB,CAAA,GAAA,+BAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,mBAAK,EAAc;IACxC,IAAI,QAAQ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2F;IAC3F,OAAO;QACL,UAAU;YAAC,GAAG,CAAA,GAAA,gCAAS,EAAE,UAAU,iBAAiB;QAAA;uBACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI,OAAgC;IACpC,IAAI,OAAgC;IACpC,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, getScrollParent, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\n node: RSNode<unknown>,\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes,\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes,\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes\n}\n\nconst EXPANSION_KEYS = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state)!;\n let descriptionId = useSlotId();\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused = useRef<Key | null>(null);\n let focus = () => {\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n ref.current !== null &&\n ((keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement))\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // 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\n // true...\n let children = state.collection.getChildren?.(node.key);\n hasChildRows = [...(children ?? [])].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n let setSize = 1;\n if (node.level > 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists, same with lastItem\n let siblings = state.collection.getChildren?.(parent.key)!;\n setSize = getLastItem(siblings)!.index + 1;\n }\n } else {\n setSize = ([...state.collection].filter(row => row.level === 0).at(-1)?.index ?? 0) + 1;\n }\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n case 'Tab': {\n if (keyboardNavigationBehavior === 'tab') {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = document.activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\n // TODO: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.main.js.map"}
@@ -50,26 +50,39 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
50
50
  var _ref_current;
51
51
  // Don't shift focus to the row if the active element is a element within the row already
52
52
  // (e.g. clicking on a row button)
53
- 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, $lxFUG$focusSafely)(ref.current);
53
+ if (ref.current !== null && (keyWhenFocused.current != null && node.key !== keyWhenFocused.current || !((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.contains(document.activeElement)))) (0, $lxFUG$focusSafely)(ref.current);
54
54
  };
55
55
  let treeGridRowProps = {};
56
56
  let hasChildRows;
57
57
  let hasLink = state.selectionManager.isLink(node.key);
58
58
  if (node != null && 'expandedKeys' in state) {
59
+ var _state_collection_getChildren, _state_collection, _filter_at;
59
60
  // 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
60
61
  // true...
62
+ let children = (_state_collection_getChildren = (_state_collection = state.collection).getChildren) === null || _state_collection_getChildren === void 0 ? void 0 : _state_collection_getChildren.call(_state_collection, node.key);
61
63
  hasChildRows = [
62
- ...state.collection.getChildren(node.key)
64
+ ...children !== null && children !== void 0 ? children : []
63
65
  ].length > 1;
64
66
  if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) onAction = ()=>state.toggleKey(node.key);
65
67
  let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;
68
+ let setSize = 1;
69
+ var _filter_at_index;
70
+ if (node.level > 0 && (node === null || node === void 0 ? void 0 : node.parentKey) != null) {
71
+ let parent = state.collection.getItem(node.parentKey);
72
+ if (parent) {
73
+ var _state_collection_getChildren1, _state_collection1;
74
+ // siblings must exist because our original node exists, same with lastItem
75
+ let siblings = (_state_collection_getChildren1 = (_state_collection1 = state.collection).getChildren) === null || _state_collection_getChildren1 === void 0 ? void 0 : _state_collection_getChildren1.call(_state_collection1, parent.key);
76
+ setSize = (0, $lxFUG$getLastItem)(siblings).index + 1;
77
+ }
78
+ } else setSize = ((_filter_at_index = (_filter_at = [
79
+ ...state.collection
80
+ ].filter((row)=>row.level === 0).at(-1)) === null || _filter_at === void 0 ? void 0 : _filter_at.index) !== null && _filter_at_index !== void 0 ? _filter_at_index : 0) + 1;
66
81
  treeGridRowProps = {
67
82
  'aria-expanded': isExpanded,
68
83
  'aria-level': node.level + 1,
69
84
  'aria-posinset': (node === null || node === void 0 ? void 0 : node.index) + 1,
70
- 'aria-setsize': node.level > 0 ? (0, $lxFUG$getLastItem)(state.collection.getChildren(node === null || node === void 0 ? void 0 : node.parentKey)).index + 1 : [
71
- ...state.collection
72
- ].filter((row)=>row.level === 0).at(-1).index + 1
85
+ 'aria-setsize': setSize
73
86
  };
74
87
  }
75
88
  let { itemProps: itemProps, ...itemStates } = (0, $lxFUG$useSelectableItem)({
@@ -83,7 +96,7 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
83
96
  linkBehavior: linkBehavior
84
97
  });
85
98
  let onKeyDown = (e)=>{
86
- if (!e.currentTarget.contains(e.target)) return;
99
+ if (!e.currentTarget.contains(e.target) || !ref.current || !document.activeElement) return;
87
100
  let walker = (0, $lxFUG$getFocusableTreeWalker)(ref.current);
88
101
  walker.currentNode = document.activeElement;
89
102
  if ('expandedKeys' in state && document.activeElement === ref.current) {
@@ -168,9 +181,10 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
168
181
  // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still
169
182
  // bubbles and gets handled by useSelectableCollection.
170
183
  if (!e.altKey && ref.current.contains(e.target)) {
184
+ var _ref_current_parentElement;
171
185
  e.stopPropagation();
172
186
  e.preventDefault();
173
- ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
187
+ (_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
174
188
  }
175
189
  break;
176
190
  case 'Tab':
@@ -239,8 +253,8 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
239
253
  };
240
254
  }
241
255
  function $4e8b0456ef72939f$var$last(walker) {
242
- let next;
243
- let last;
256
+ let next = null;
257
+ let last = null;
244
258
  do {
245
259
  last = walker.lastChild();
246
260
  if (last) next = last;
@@ -50,26 +50,39 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
50
50
  var _ref_current;
51
51
  // Don't shift focus to the row if the active element is a element within the row already
52
52
  // (e.g. clicking on a row button)
53
- 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, $lxFUG$focusSafely)(ref.current);
53
+ if (ref.current !== null && (keyWhenFocused.current != null && node.key !== keyWhenFocused.current || !((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.contains(document.activeElement)))) (0, $lxFUG$focusSafely)(ref.current);
54
54
  };
55
55
  let treeGridRowProps = {};
56
56
  let hasChildRows;
57
57
  let hasLink = state.selectionManager.isLink(node.key);
58
58
  if (node != null && 'expandedKeys' in state) {
59
+ var _state_collection_getChildren, _state_collection, _filter_at;
59
60
  // 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
60
61
  // true...
62
+ let children = (_state_collection_getChildren = (_state_collection = state.collection).getChildren) === null || _state_collection_getChildren === void 0 ? void 0 : _state_collection_getChildren.call(_state_collection, node.key);
61
63
  hasChildRows = [
62
- ...state.collection.getChildren(node.key)
64
+ ...children !== null && children !== void 0 ? children : []
63
65
  ].length > 1;
64
66
  if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) onAction = ()=>state.toggleKey(node.key);
65
67
  let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;
68
+ let setSize = 1;
69
+ var _filter_at_index;
70
+ if (node.level > 0 && (node === null || node === void 0 ? void 0 : node.parentKey) != null) {
71
+ let parent = state.collection.getItem(node.parentKey);
72
+ if (parent) {
73
+ var _state_collection_getChildren1, _state_collection1;
74
+ // siblings must exist because our original node exists, same with lastItem
75
+ let siblings = (_state_collection_getChildren1 = (_state_collection1 = state.collection).getChildren) === null || _state_collection_getChildren1 === void 0 ? void 0 : _state_collection_getChildren1.call(_state_collection1, parent.key);
76
+ setSize = (0, $lxFUG$getLastItem)(siblings).index + 1;
77
+ }
78
+ } else setSize = ((_filter_at_index = (_filter_at = [
79
+ ...state.collection
80
+ ].filter((row)=>row.level === 0).at(-1)) === null || _filter_at === void 0 ? void 0 : _filter_at.index) !== null && _filter_at_index !== void 0 ? _filter_at_index : 0) + 1;
66
81
  treeGridRowProps = {
67
82
  'aria-expanded': isExpanded,
68
83
  'aria-level': node.level + 1,
69
84
  'aria-posinset': (node === null || node === void 0 ? void 0 : node.index) + 1,
70
- 'aria-setsize': node.level > 0 ? (0, $lxFUG$getLastItem)(state.collection.getChildren(node === null || node === void 0 ? void 0 : node.parentKey)).index + 1 : [
71
- ...state.collection
72
- ].filter((row)=>row.level === 0).at(-1).index + 1
85
+ 'aria-setsize': setSize
73
86
  };
74
87
  }
75
88
  let { itemProps: itemProps, ...itemStates } = (0, $lxFUG$useSelectableItem)({
@@ -83,7 +96,7 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
83
96
  linkBehavior: linkBehavior
84
97
  });
85
98
  let onKeyDown = (e)=>{
86
- if (!e.currentTarget.contains(e.target)) return;
99
+ if (!e.currentTarget.contains(e.target) || !ref.current || !document.activeElement) return;
87
100
  let walker = (0, $lxFUG$getFocusableTreeWalker)(ref.current);
88
101
  walker.currentNode = document.activeElement;
89
102
  if ('expandedKeys' in state && document.activeElement === ref.current) {
@@ -168,9 +181,10 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
168
181
  // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still
169
182
  // bubbles and gets handled by useSelectableCollection.
170
183
  if (!e.altKey && ref.current.contains(e.target)) {
184
+ var _ref_current_parentElement;
171
185
  e.stopPropagation();
172
186
  e.preventDefault();
173
- ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
187
+ (_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
174
188
  }
175
189
  break;
176
190
  case 'Tab':
@@ -239,8 +253,8 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
239
253
  };
240
254
  }
241
255
  function $4e8b0456ef72939f$var$last(walker) {
242
- let next;
243
- let last;
256
+ let next = null;
257
+ let last = null;
244
258
  do {
245
259
  last = walker.lastChild();
246
260
  if (last) next = last;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAuDpH,aAA6B;IAtDrD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,yBACb,qBAAqB,EACtB,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC;IACvE,IAAI,gBAAgB,CAAA,GAAA,gBAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA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vE,wBAAwB;IACxB,sEAAsE;IACtE,4BAA4B;IAC5B,QAAQ;IACR,IAAI;IAEJ,IAAI,WAA0B,CAAA,GAAA,iBAAS,EAAE,WAAW,WAAW;QAC7D,MAAM;QACN,kBAAkB;iBAClB;QACA,6FAA6F;QAC7F,cAAc,KAAK,SAAS,IAAI;QAChC,iBAAiB,MAAM,gBAAgB,CAAC,aAAa,CAAC,KAAK,GAAG,IAAI,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI;QAChH,iBAAiB,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK;QAChE,mBAAmB,iBAAiB,KAAK,SAAS,GAAG,CAAC,EAAE,CAAA,GAAA,yCAAO,EAAE,OAAO,KAAK,GAAG,EAAE,CAAC,EAAE,cAAc,CAAC,GAAG;QACvG,IAAI,CAAA,GAAA,yCAAO,EAAE,OAAO,KAAK,GAAG;IAC9B;IAEA,IAAI,eACF,QAAQ,CAAC,gBAAgB,GAAG,KAAK,KAAK,GAAG;IAG3C,IAAI,gBAAgB;QAClB,MAAM;QACN,iBAAiB;IACnB;IAEA,2FAA2F;IAC3F,OAAO;QACL,UAAU;YAAC,GAAG,CAAA,GAAA,iBAAS,EAAE,UAAU,iBAAiB;QAAA;uBACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI;IACJ,IAAI;IACJ,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, getScrollParent, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\n node: RSNode<unknown>,\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes,\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes,\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes\n}\n\nconst EXPANSION_KEYS = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state);\n let descriptionId = useSlotId();\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused = useRef(null);\n let focus = () => {\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement)\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // 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\n // true...\n hasChildRows = [...state.collection.getChildren(node.key)].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': node.level > 0 ?\n (getLastItem(state.collection.getChildren(node?.parentKey))).index + 1 :\n [...state.collection].filter(row => row.level === 0).at(-1).index + 1\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element)) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n case 'Tab': {\n if (keyboardNavigationBehavior === 'tab') {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = document.activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\n // TODO: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.module.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAkEpH,aAA6B;IAjErD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,yBACb,qBAAqB,EACtB,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC;IACvE,IAAI,gBAAgB,CAAA,GAAA,gBAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,aAAK,EAAc;IACxC,IAAI,QAAQ;YAMP;QALH,yFAAyF;QACzF,kCAAkC;QAClC,IACE,IAAI,OAAO,KAAK,QACf,CAAA,AAAC,eAAe,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ACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI,OAAgC;IACpC,IAAI,OAAgC;IACpC,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, getScrollParent, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\n node: RSNode<unknown>,\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes,\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes,\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes\n}\n\nconst EXPANSION_KEYS = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state)!;\n let descriptionId = useSlotId();\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused = useRef<Key | null>(null);\n let focus = () => {\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n ref.current !== null &&\n ((keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement))\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // 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\n // true...\n let children = state.collection.getChildren?.(node.key);\n hasChildRows = [...(children ?? [])].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n let setSize = 1;\n if (node.level > 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists, same with lastItem\n let siblings = state.collection.getChildren?.(parent.key)!;\n setSize = getLastItem(siblings)!.index + 1;\n }\n } else {\n setSize = ([...state.collection].filter(row => row.level === 0).at(-1)?.index ?? 0) + 1;\n }\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n case 'Tab': {\n if (keyboardNavigationBehavior === 'tab') {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = document.activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\n // TODO: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAgC,KAAqC,EAAE,KAAmB;IACxG,IAAI,OAAC,GAAG,EAAC,GAAG;IACZ,MAAM,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,6CAAuB,EAAE,OAAO;IAExD,OAAO;QACL,eAAe;YACb,GAAG,aAAa;YAChB,mBAAmB,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,EAAE,CAAA,GAAA,kCAAO,EAAE,OAAO,KAAK,CAAC;QAClE;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridListSelectionCheckbox.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria, useGridSelectionCheckbox} from '@react-aria/grid';\nimport {getRowId} from './utils';\nimport type {ListState} from '@react-stately/list';\n\n/**\n * Provides the behavior and accessibility implementation for a selection checkbox in a grid list.\n * @param props - Props for the selection checkbox.\n * @param state - State of the list, as returned by `useListState`.\n */\nexport function useGridListSelectionCheckbox<T>(props: AriaGridSelectionCheckboxProps, state: ListState<T>): GridSelectionCheckboxAria {\n let {key} = props;\n const {checkboxProps} = useGridSelectionCheckbox(props, state as any);\n\n return {\n checkboxProps: {\n ...checkboxProps,\n 'aria-labelledby': `${checkboxProps.id} ${getRowId(state, key)}`\n }\n };\n}\n"],"names":[],"version":3,"file":"useGridListSelectionCheckbox.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAgC,KAAqC,EAAE,KAAmB;IACxG,IAAI,OAAC,GAAG,EAAC,GAAG;IACZ,MAAM,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,6CAAuB,EAAE,OAAO;IAExD,OAAO;QACL,eAAe;YACb,GAAG,aAAa;YAChB,mBAAmB,GAAG,cAAc,EAAE,CAAC,CAAC,EAAE,CAAA,GAAA,kCAAO,EAAE,OAAO,MAAM;QAClE;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridListSelectionCheckbox.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria, useGridSelectionCheckbox} from '@react-aria/grid';\nimport {getRowId} from './utils';\nimport type {ListState} from '@react-stately/list';\n\n/**\n * Provides the behavior and accessibility implementation for a selection checkbox in a grid list.\n * @param props - Props for the selection checkbox.\n * @param state - State of the list, as returned by `useListState`.\n */\nexport function useGridListSelectionCheckbox<T>(props: AriaGridSelectionCheckboxProps, state: ListState<T>): GridSelectionCheckboxAria {\n let {key} = props;\n const {checkboxProps} = useGridSelectionCheckbox(props, state as any);\n\n return {\n checkboxProps: {\n ...checkboxProps,\n 'aria-labelledby': `${checkboxProps.id} ${getRowId(state, key)}`\n }\n };\n}\n"],"names":[],"version":3,"file":"useGridListSelectionCheckbox.main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAgC,KAAqC,EAAE,KAAmB;IACxG,IAAI,OAAC,GAAG,EAAC,GAAG;IACZ,MAAM,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,+BAAuB,EAAE,OAAO;IAExD,OAAO;QACL,eAAe;YACb,GAAG,aAAa;YAChB,mBAAmB,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,EAAE,CAAA,GAAA,yCAAO,EAAE,OAAO,KAAK,CAAC;QAClE;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridListSelectionCheckbox.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria, useGridSelectionCheckbox} from '@react-aria/grid';\nimport {getRowId} from './utils';\nimport type {ListState} from '@react-stately/list';\n\n/**\n * Provides the behavior and accessibility implementation for a selection checkbox in a grid list.\n * @param props - Props for the selection checkbox.\n * @param state - State of the list, as returned by `useListState`.\n */\nexport function useGridListSelectionCheckbox<T>(props: AriaGridSelectionCheckboxProps, state: ListState<T>): GridSelectionCheckboxAria {\n let {key} = props;\n const {checkboxProps} = useGridSelectionCheckbox(props, state as any);\n\n return {\n checkboxProps: {\n ...checkboxProps,\n 'aria-labelledby': `${checkboxProps.id} ${getRowId(state, key)}`\n }\n };\n}\n"],"names":[],"version":3,"file":"useGridListSelectionCheckbox.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAgC,KAAqC,EAAE,KAAmB;IACxG,IAAI,OAAC,GAAG,EAAC,GAAG;IACZ,MAAM,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,+BAAuB,EAAE,OAAO;IAExD,OAAO;QACL,eAAe;YACb,GAAG,aAAa;YAChB,mBAAmB,GAAG,cAAc,EAAE,CAAC,CAAC,EAAE,CAAA,GAAA,yCAAO,EAAE,OAAO,MAAM;QAClE;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridListSelectionCheckbox.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria, useGridSelectionCheckbox} from '@react-aria/grid';\nimport {getRowId} from './utils';\nimport type {ListState} from '@react-stately/list';\n\n/**\n * Provides the behavior and accessibility implementation for a selection checkbox in a grid list.\n * @param props - Props for the selection checkbox.\n * @param state - State of the list, as returned by `useListState`.\n */\nexport function useGridListSelectionCheckbox<T>(props: AriaGridSelectionCheckboxProps, state: ListState<T>): GridSelectionCheckboxAria {\n let {key} = props;\n const {checkboxProps} = useGridSelectionCheckbox(props, state as any);\n\n return {\n checkboxProps: {\n ...checkboxProps,\n 'aria-labelledby': `${checkboxProps.id} ${getRowId(state, key)}`\n }\n };\n}\n"],"names":[],"version":3,"file":"useGridListSelectionCheckbox.module.js.map"}
@@ -17,7 +17,8 @@ $parcel$export(module.exports, "getRowId", () => $7db02799adae605d$export$f45c25
17
17
  * governing permissions and limitations under the License.
18
18
  */ const $7db02799adae605d$export$5b9bb410392e3991 = new WeakMap();
19
19
  function $7db02799adae605d$export$f45c25170b9a99c2(state, key) {
20
- let { id: id } = $7db02799adae605d$export$5b9bb410392e3991.get(state);
20
+ var _listMap_get;
21
+ let { id: id } = (_listMap_get = $7db02799adae605d$export$5b9bb410392e3991.get(state)) !== null && _listMap_get !== void 0 ? _listMap_get : {};
21
22
  if (!id) throw new Error('Unknown list');
22
23
  return `${id}-${$7db02799adae605d$export$e0c709538cb8ae18(key)}`;
23
24
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAcM,MAAM,4CAAU,IAAI;AAEpB,SAAS,0CAAY,KAAmB,EAAE,GAAQ;IACvD,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAQ,GAAG,CAAC;IACvB,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,0CAAa,KAAK,CAAC;AACrC;AAEO,SAAS,0CAAa,GAAQ;IACnC,IAAI,OAAO,QAAQ,UACjB,OAAO,IAAI,OAAO,CAAC,QAAQ;IAG7B,OAAO,KAAK;AACd","sources":["packages/@react-aria/gridlist/src/utils.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 {Key} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\n\ninterface ListMapShared {\n id: string,\n onAction: (key: Key) => void,\n linkBehavior?: 'action' | 'selection' | 'override',\n keyboardNavigationBehavior: 'arrow' | 'tab'\n}\n\n// Used to share:\n// id of the list and onAction between useList, useListItem, and useListSelectionCheckbox\nexport const listMap = new WeakMap<ListState<unknown>, ListMapShared>();\n\nexport function getRowId<T>(state: ListState<T>, key: Key) {\n let {id} = listMap.get(state);\n if (!id) {\n throw new Error('Unknown list');\n }\n\n return `${id}-${normalizeKey(key)}`;\n}\n\nexport function normalizeKey(key: Key): string {\n if (typeof key === 'string') {\n return key.replace(/\\s*/g, '');\n }\n\n return '' + key;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAcM,MAAM,4CAAU,IAAI;AAEpB,SAAS,0CAAY,KAAmB,EAAE,GAAQ;QAC5C;IAAX,IAAI,MAAC,EAAE,EAAC,GAAG,CAAA,eAAA,0CAAQ,GAAG,CAAC,oBAAZ,0BAAA,eAAsB,CAAC;IAClC,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO,GAAG,GAAG,CAAC,EAAE,0CAAa,MAAM;AACrC;AAEO,SAAS,0CAAa,GAAQ;IACnC,IAAI,OAAO,QAAQ,UACjB,OAAO,IAAI,OAAO,CAAC,QAAQ;IAG7B,OAAO,KAAK;AACd","sources":["packages/@react-aria/gridlist/src/utils.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 {Key} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\n\ninterface ListMapShared {\n id: string,\n onAction?: (key: Key) => void,\n linkBehavior?: 'action' | 'selection' | 'override',\n keyboardNavigationBehavior: 'arrow' | 'tab'\n}\n\n// Used to share:\n// id of the list and onAction between useList, useListItem, and useListSelectionCheckbox\nexport const listMap = new WeakMap<ListState<unknown>, ListMapShared>();\n\nexport function getRowId<T>(state: ListState<T>, key: Key) {\n let {id} = listMap.get(state) ?? {};\n if (!id) {\n throw new Error('Unknown list');\n }\n\n return `${id}-${normalizeKey(key)}`;\n}\n\nexport function normalizeKey(key: Key): string {\n if (typeof key === 'string') {\n return key.replace(/\\s*/g, '');\n }\n\n return '' + key;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
package/dist/utils.mjs CHANGED
@@ -10,7 +10,8 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */ const $ce9b18daab526bbd$export$5b9bb410392e3991 = new WeakMap();
12
12
  function $ce9b18daab526bbd$export$f45c25170b9a99c2(state, key) {
13
- let { id: id } = $ce9b18daab526bbd$export$5b9bb410392e3991.get(state);
13
+ var _listMap_get;
14
+ let { id: id } = (_listMap_get = $ce9b18daab526bbd$export$5b9bb410392e3991.get(state)) !== null && _listMap_get !== void 0 ? _listMap_get : {};
14
15
  if (!id) throw new Error('Unknown list');
15
16
  return `${id}-${$ce9b18daab526bbd$export$e0c709538cb8ae18(key)}`;
16
17
  }
@@ -10,7 +10,8 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */ const $ce9b18daab526bbd$export$5b9bb410392e3991 = new WeakMap();
12
12
  function $ce9b18daab526bbd$export$f45c25170b9a99c2(state, key) {
13
- let { id: id } = $ce9b18daab526bbd$export$5b9bb410392e3991.get(state);
13
+ var _listMap_get;
14
+ let { id: id } = (_listMap_get = $ce9b18daab526bbd$export$5b9bb410392e3991.get(state)) !== null && _listMap_get !== void 0 ? _listMap_get : {};
14
15
  if (!id) throw new Error('Unknown list');
15
16
  return `${id}-${$ce9b18daab526bbd$export$e0c709538cb8ae18(key)}`;
16
17
  }
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAcM,MAAM,4CAAU,IAAI;AAEpB,SAAS,0CAAY,KAAmB,EAAE,GAAQ;IACvD,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAQ,GAAG,CAAC;IACvB,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,0CAAa,KAAK,CAAC;AACrC;AAEO,SAAS,0CAAa,GAAQ;IACnC,IAAI,OAAO,QAAQ,UACjB,OAAO,IAAI,OAAO,CAAC,QAAQ;IAG7B,OAAO,KAAK;AACd","sources":["packages/@react-aria/gridlist/src/utils.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 {Key} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\n\ninterface ListMapShared {\n id: string,\n onAction: (key: Key) => void,\n linkBehavior?: 'action' | 'selection' | 'override',\n keyboardNavigationBehavior: 'arrow' | 'tab'\n}\n\n// Used to share:\n// id of the list and onAction between useList, useListItem, and useListSelectionCheckbox\nexport const listMap = new WeakMap<ListState<unknown>, ListMapShared>();\n\nexport function getRowId<T>(state: ListState<T>, key: Key) {\n let {id} = listMap.get(state);\n if (!id) {\n throw new Error('Unknown list');\n }\n\n return `${id}-${normalizeKey(key)}`;\n}\n\nexport function normalizeKey(key: Key): string {\n if (typeof key === 'string') {\n return key.replace(/\\s*/g, '');\n }\n\n return '' + key;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAcM,MAAM,4CAAU,IAAI;AAEpB,SAAS,0CAAY,KAAmB,EAAE,GAAQ;QAC5C;IAAX,IAAI,MAAC,EAAE,EAAC,GAAG,CAAA,eAAA,0CAAQ,GAAG,CAAC,oBAAZ,0BAAA,eAAsB,CAAC;IAClC,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO,GAAG,GAAG,CAAC,EAAE,0CAAa,MAAM;AACrC;AAEO,SAAS,0CAAa,GAAQ;IACnC,IAAI,OAAO,QAAQ,UACjB,OAAO,IAAI,OAAO,CAAC,QAAQ;IAG7B,OAAO,KAAK;AACd","sources":["packages/@react-aria/gridlist/src/utils.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 {Key} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\n\ninterface ListMapShared {\n id: string,\n onAction?: (key: Key) => void,\n linkBehavior?: 'action' | 'selection' | 'override',\n keyboardNavigationBehavior: 'arrow' | 'tab'\n}\n\n// Used to share:\n// id of the list and onAction between useList, useListItem, and useListSelectionCheckbox\nexport const listMap = new WeakMap<ListState<unknown>, ListMapShared>();\n\nexport function getRowId<T>(state: ListState<T>, key: Key) {\n let {id} = listMap.get(state) ?? {};\n if (!id) {\n throw new Error('Unknown list');\n }\n\n return `${id}-${normalizeKey(key)}`;\n}\n\nexport function normalizeKey(key: Key): string {\n if (typeof key === 'string') {\n return key.replace(/\\s*/g, '');\n }\n\n return '' + key;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/gridlist",
3
- "version": "3.9.5",
3
+ "version": "3.10.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,24 +22,24 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.18.4",
26
- "@react-aria/grid": "^3.10.5",
27
- "@react-aria/i18n": "^3.12.3",
28
- "@react-aria/interactions": "^3.22.4",
29
- "@react-aria/selection": "^3.20.1",
30
- "@react-aria/utils": "^3.25.3",
31
- "@react-stately/collections": "^3.11.0",
32
- "@react-stately/list": "^3.11.0",
33
- "@react-stately/tree": "^3.8.5",
34
- "@react-types/shared": "^3.25.0",
25
+ "@react-aria/focus": "^3.19.1",
26
+ "@react-aria/grid": "^3.11.1",
27
+ "@react-aria/i18n": "^3.12.5",
28
+ "@react-aria/interactions": "^3.23.0",
29
+ "@react-aria/selection": "^3.22.0",
30
+ "@react-aria/utils": "^3.27.0",
31
+ "@react-stately/collections": "^3.12.1",
32
+ "@react-stately/list": "^3.11.2",
33
+ "@react-stately/tree": "^3.8.7",
34
+ "@react-types/shared": "^3.27.0",
35
35
  "@swc/helpers": "^0.5.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
39
- "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
38
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
39
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "8e0a28d188cdbdbd2b32296fa034b1b02ddde229"
44
+ "gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
45
45
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {chain, getScrollParent, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';
14
- import {DOMAttributes, FocusableElement, RefObject, Node as RSNode} from '@react-types/shared';
14
+ import {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared';
15
15
  import {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';
16
16
  import {getLastItem} from '@react-stately/collections';
17
17
  import {getRowId, listMap} from './utils';
@@ -67,18 +67,19 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
67
67
 
68
68
  // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');
69
69
  let {direction} = useLocale();
70
- let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state);
70
+ let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state)!;
71
71
  let descriptionId = useSlotId();
72
72
 
73
73
  // We need to track the key of the item at the time it was last focused so that we force
74
74
  // focus to go to the item when the DOM node is reused for a different item in a virtualizer.
75
- let keyWhenFocused = useRef(null);
75
+ let keyWhenFocused = useRef<Key | null>(null);
76
76
  let focus = () => {
77
77
  // Don't shift focus to the row if the active element is a element within the row already
78
78
  // (e.g. clicking on a row button)
79
79
  if (
80
- (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||
81
- !ref.current?.contains(document.activeElement)
80
+ ref.current !== null &&
81
+ ((keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||
82
+ !ref.current?.contains(document.activeElement))
82
83
  ) {
83
84
  focusSafely(ref.current);
84
85
  }
@@ -90,19 +91,29 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
90
91
  if (node != null && 'expandedKeys' in state) {
91
92
  // 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
92
93
  // true...
93
- hasChildRows = [...state.collection.getChildren(node.key)].length > 1;
94
+ let children = state.collection.getChildren?.(node.key);
95
+ hasChildRows = [...(children ?? [])].length > 1;
94
96
  if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {
95
97
  onAction = () => state.toggleKey(node.key);
96
98
  }
97
99
 
98
100
  let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;
101
+ let setSize = 1;
102
+ if (node.level > 0 && node?.parentKey != null) {
103
+ let parent = state.collection.getItem(node.parentKey);
104
+ if (parent) {
105
+ // siblings must exist because our original node exists, same with lastItem
106
+ let siblings = state.collection.getChildren?.(parent.key)!;
107
+ setSize = getLastItem(siblings)!.index + 1;
108
+ }
109
+ } else {
110
+ setSize = ([...state.collection].filter(row => row.level === 0).at(-1)?.index ?? 0) + 1;
111
+ }
99
112
  treeGridRowProps = {
100
113
  'aria-expanded': isExpanded,
101
114
  'aria-level': node.level + 1,
102
115
  'aria-posinset': node?.index + 1,
103
- 'aria-setsize': node.level > 0 ?
104
- (getLastItem(state.collection.getChildren(node?.parentKey))).index + 1 :
105
- [...state.collection].filter(row => row.level === 0).at(-1).index + 1
116
+ 'aria-setsize': setSize
106
117
  };
107
118
  }
108
119
 
@@ -118,7 +129,7 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
118
129
  });
119
130
 
120
131
  let onKeyDown = (e: ReactKeyboardEvent) => {
121
- if (!e.currentTarget.contains(e.target as Element)) {
132
+ if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {
122
133
  return;
123
134
  }
124
135
 
@@ -206,7 +217,7 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
206
217
  if (!e.altKey && ref.current.contains(e.target as Element)) {
207
218
  e.stopPropagation();
208
219
  e.preventDefault();
209
- ref.current.parentElement.dispatchEvent(
220
+ ref.current.parentElement?.dispatchEvent(
210
221
  new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)
211
222
  );
212
223
  }
@@ -287,10 +298,10 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
287
298
  }
288
299
 
289
300
  function last(walker: TreeWalker) {
290
- let next: FocusableElement;
291
- let last: FocusableElement;
301
+ let next: FocusableElement | null = null;
302
+ let last: FocusableElement | null = null;
292
303
  do {
293
- last = walker.lastChild() as FocusableElement;
304
+ last = walker.lastChild() as FocusableElement | null;
294
305
  if (last) {
295
306
  next = last;
296
307
  }
package/src/utils.ts CHANGED
@@ -15,7 +15,7 @@ import type {ListState} from '@react-stately/list';
15
15
 
16
16
  interface ListMapShared {
17
17
  id: string,
18
- onAction: (key: Key) => void,
18
+ onAction?: (key: Key) => void,
19
19
  linkBehavior?: 'action' | 'selection' | 'override',
20
20
  keyboardNavigationBehavior: 'arrow' | 'tab'
21
21
  }
@@ -25,7 +25,7 @@ interface ListMapShared {
25
25
  export const listMap = new WeakMap<ListState<unknown>, ListMapShared>();
26
26
 
27
27
  export function getRowId<T>(state: ListState<T>, key: Key) {
28
- let {id} = listMap.get(state);
28
+ let {id} = listMap.get(state) ?? {};
29
29
  if (!id) {
30
30
  throw new Error('Unknown list');
31
31
  }