@react-aria/grid 3.11.1 → 3.12.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.
- package/dist/GridKeyboardDelegate.main.js +19 -10
- package/dist/GridKeyboardDelegate.main.js.map +1 -1
- package/dist/GridKeyboardDelegate.mjs +20 -11
- package/dist/GridKeyboardDelegate.module.js +20 -11
- package/dist/GridKeyboardDelegate.module.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useGrid.main.js +3 -2
- package/dist/useGrid.main.js.map +1 -1
- package/dist/useGrid.mjs +3 -2
- package/dist/useGrid.module.js +3 -2
- package/dist/useGrid.module.js.map +1 -1
- package/dist/useGridCell.main.js +12 -9
- package/dist/useGridCell.main.js.map +1 -1
- package/dist/useGridCell.mjs +5 -2
- package/dist/useGridCell.module.js +5 -2
- package/dist/useGridCell.module.js.map +1 -1
- package/dist/useGridSelectionAnnouncement.main.js +13 -4
- package/dist/useGridSelectionAnnouncement.main.js.map +1 -1
- package/dist/useGridSelectionAnnouncement.mjs +13 -4
- package/dist/useGridSelectionAnnouncement.module.js +13 -4
- package/dist/useGridSelectionAnnouncement.module.js.map +1 -1
- package/package.json +13 -13
- package/src/GridKeyboardDelegate.ts +34 -11
- package/src/useGrid.ts +8 -1
- package/src/useGridCell.ts +7 -2
- package/src/useGridSelectionAnnouncement.ts +14 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;AA4DM,SAAS,0CAAW,KAAgB,EAAE,KAAsC,EAAE,GAAkC;IACrH,IAAI,iBACF,aAAa,qBACb,iBAAiB,oBACjB,gBAAgB,aAChB,SAAS,aACT,SAAS,cACT,UAAU,eACV,WAAW,gBACX,YAAY,EACb,GAAG;IACJ,IAAI,EAAC,kBAAkB,O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B;QACF;QAEA,gEAAgE;QAChE,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GACpC;QAGF,QAAQ,UAAU,CAAC;IACrB,GAAG;QAAC;KAAQ;IAEZ,qFAAqF;IACrF,IAAI,sBAAsB,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;YACvC,QAAQ,gBAAgB,MAAM;qBAC9B;QACF,CAAA,GAAI;QAAC;QAAS,gBAAgB,MAAM;KAAC;IAErC,IAAI,mBAAmB,CAAA,GAAA,0BAAkB,EAAE,KAAK;QAC9C,YAAY,MAAM,UAAU,CAAC,IAAI,KAAK;IACxC;IAEA,IAAI,YAA2B,CAAA,GAAA,iBAAS,EACtC,UACA;QACE,MAAM;YACN;QACA,wBAAwB,QAAQ,aAAa,KAAK,aAAa,SAAS;IAC1E,GACA,MAAM,4BAA4B,GAAG,sBAAsB,iBAE3D,AADA,mGAAmG;IAClG,MAAM,UAAU,CAAC,IAAI,KAAK,KAAK;QAAC,UAAU,mBAAmB,KAAK;IAAC,KAAM,WAC1E;IAGF,IAAI,eAAe;QACjB,SAAS,CAAC,gBAAgB,GAAG,MAAM,UAAU,CAAC,IAAI;QAClD,SAAS,CAAC,gBAAgB,GAAG,MAAM,UAAU,CAAC,WAAW;IAC3D;IAEA,CAAA,GAAA,yCAA2B,EAAE;oBAAC;IAAU,GAAG;IAC3C,OAAO;mBACL;IACF;AACF","sources":["packages/@react-aria/grid/src/useGrid.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 {AriaLabelingProps, DOMAttributes, DOMProps, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {GridCollection} from '@react-types/grid';\nimport {GridKeyboardDelegate} from './GridKeyboardDelegate';\nimport {gridMap} from './utils';\nimport {GridState} from '@react-stately/grid';\nimport {useCallback, useMemo} from 'react';\nimport {useCollator, useLocale} from '@react-aria/i18n';\nimport {useGridSelectionAnnouncement} from './useGridSelectionAnnouncement';\nimport {useHasTabbableChild} from '@react-aria/focus';\nimport {useHighlightSelectionDescription} from './useHighlightSelectionDescription';\nimport {useSelectableCollection} from '@react-aria/selection';\n\nexport interface GridProps extends DOMProps, AriaLabelingProps {\n /** Whether the grid uses virtual scrolling. */\n isVirtualized?: boolean,\n /**\n * Whether typeahead navigation is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * Whether initial grid focus should be placed on the grid row or grid cell.\n * @default 'row'\n */\n focusMode?: 'row' | 'cell',\n /**\n * A function that returns the text that should be announced by assistive technology when a row is added or removed from selection.\n * @default (key) => state.collection.getItem(key)?.textValue\n */\n getRowText?: (key: Key) => string,\n /**\n * The ref attached to the scrollable body. Used to provided automatic scrolling on item focus for non-virtualized grids.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /** Handler that is called when a user performs an action on the row. */\n onRowAction?: (key: Key) => void,\n /** Handler that is called when a user performs an action on the cell. */\n onCellAction?: (key: Key) => void\n}\n\nexport interface GridAria {\n /** Props for the grid element. */\n gridProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a grid component.\n * A grid displays data in one or more rows and columns and enables a user to navigate its contents via directional navigation keys.\n * @param props - Props for the grid.\n * @param state - State for the grid, as returned by `useGridState`.\n * @param ref - The ref attached to the grid element.\n */\nexport function useGrid<T>(props: GridProps, state: GridState<T, GridCollection<T>>, ref: RefObject<HTMLElement | null>): GridAria {\n let {\n isVirtualized,\n disallowTypeAhead,\n keyboardDelegate,\n focusMode,\n scrollRef,\n getRowText,\n onRowAction,\n onCellAction\n } = props;\n let {selectionManager: manager} = state;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n let collator = useCollator({usage: 'search', sensitivity: 'base'});\n let {direction} = useLocale();\n let disabledBehavior = state.selectionManager.disabledBehavior;\n let delegate = useMemo(() => keyboardDelegate || new GridKeyboardDelegate({\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n disabledBehavior,\n ref,\n direction,\n collator,\n focusMode\n }), [keyboardDelegate, state.collection, state.disabledKeys, disabledBehavior, ref, direction, collator, focusMode]);\n\n let {collectionProps} = useSelectableCollection({\n ref,\n selectionManager: manager,\n keyboardDelegate: delegate,\n isVirtualized,\n scrollRef,\n disallowTypeAhead\n });\n\n let id = useId(props.id);\n gridMap.set(state, {keyboardDelegate: delegate, actions: {onRowAction, onCellAction}});\n\n let descriptionProps = useHighlightSelectionDescription({\n selectionManager: manager,\n hasItemActions: !!(onRowAction || onCellAction)\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n let onFocus = useCallback((e) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n }, [manager]);\n\n // Continue to track collection focused state even if keyboard navigation is disabled\n let navDisabledHandlers = useMemo(() => ({\n onBlur: collectionProps.onBlur,\n onFocus\n }), [onFocus, collectionProps.onBlur]);\n\n let hasTabbableChild = useHasTabbableChild(ref, {\n isDisabled: state.collection.size !== 0\n });\n\n let gridProps: DOMAttributes = mergeProps(\n domProps,\n {\n role: 'grid',\n id,\n 'aria-multiselectable': manager.selectionMode === 'multiple' ? 'true' : undefined\n },\n state.isKeyboardNavigationDisabled ? navDisabledHandlers : collectionProps,\n // If collection is empty, make sure the grid is tabbable unless there is a child tabbable element.\n (state.collection.size === 0 && {tabIndex: hasTabbableChild ? -1 : 0}) || undefined,\n descriptionProps\n );\n\n if (isVirtualized) {\n gridProps['aria-rowcount'] = state.collection.size;\n gridProps['aria-colcount'] = state.collection.columnCount;\n }\n\n useGridSelectionAnnouncement({getRowText}, state);\n return {\n gridProps\n };\n}\n"],"names":[],"version":3,"file":"useGrid.module.js.map"}
|
package/dist/useGridCell.main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var $8ee34951196858d0$exports = require("./utils.main.js");
|
|
2
|
+
var $9yLAi$reactariainteractions = require("@react-aria/interactions");
|
|
2
3
|
var $9yLAi$reactariafocus = require("@react-aria/focus");
|
|
3
4
|
var $9yLAi$reactariautils = require("@react-aria/utils");
|
|
4
|
-
var $9yLAi$reactariainteractions = require("@react-aria/interactions");
|
|
5
5
|
var $9yLAi$react = require("react");
|
|
6
6
|
var $9yLAi$reactariai18n = require("@react-aria/i18n");
|
|
7
7
|
var $9yLAi$reactariaselection = require("@react-aria/selection");
|
|
@@ -46,11 +46,11 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
46
46
|
if (ref.current.contains(document.activeElement) && ref.current !== document.activeElement) return;
|
|
47
47
|
let focusable = state.selectionManager.childFocusStrategy === 'last' ? $cf2021be63b01ef4$var$last(treeWalker) : treeWalker.firstChild();
|
|
48
48
|
if (focusable) {
|
|
49
|
-
(0, $9yLAi$
|
|
49
|
+
(0, $9yLAi$reactariainteractions.focusSafely)(focusable);
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
if (keyWhenFocused.current != null && node.key !== keyWhenFocused.current || !ref.current.contains(document.activeElement)) (0, $9yLAi$
|
|
53
|
+
if (keyWhenFocused.current != null && node.key !== keyWhenFocused.current || !ref.current.contains(document.activeElement)) (0, $9yLAi$reactariainteractions.focusSafely)(ref.current);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
let { itemProps: itemProps, isPressed: isPressed } = (0, $9yLAi$reactariaselection.useSelectableItem)({
|
|
@@ -77,7 +77,7 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
77
77
|
e.preventDefault();
|
|
78
78
|
e.stopPropagation();
|
|
79
79
|
if (focusable) {
|
|
80
|
-
(0, $9yLAi$
|
|
80
|
+
(0, $9yLAi$reactariainteractions.focusSafely)(focusable);
|
|
81
81
|
(0, $9yLAi$reactariautils.scrollIntoViewport)(focusable, {
|
|
82
82
|
containingElement: (0, $9yLAi$reactariautils.getScrollParent)(ref.current)
|
|
83
83
|
});
|
|
@@ -98,7 +98,7 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
100
|
if (focusMode === 'cell' && direction === 'rtl') {
|
|
101
|
-
(0, $9yLAi$
|
|
101
|
+
(0, $9yLAi$reactariainteractions.focusSafely)(ref.current);
|
|
102
102
|
(0, $9yLAi$reactariautils.scrollIntoViewport)(ref.current, {
|
|
103
103
|
containingElement: (0, $9yLAi$reactariautils.getScrollParent)(ref.current)
|
|
104
104
|
});
|
|
@@ -106,7 +106,7 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
106
106
|
walker.currentNode = ref.current;
|
|
107
107
|
focusable = direction === 'rtl' ? walker.firstChild() : $cf2021be63b01ef4$var$last(walker);
|
|
108
108
|
if (focusable) {
|
|
109
|
-
(0, $9yLAi$
|
|
109
|
+
(0, $9yLAi$reactariainteractions.focusSafely)(focusable);
|
|
110
110
|
(0, $9yLAi$reactariautils.scrollIntoViewport)(focusable, {
|
|
111
111
|
containingElement: (0, $9yLAi$reactariautils.getScrollParent)(ref.current)
|
|
112
112
|
});
|
|
@@ -122,7 +122,7 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
122
122
|
e.preventDefault();
|
|
123
123
|
e.stopPropagation();
|
|
124
124
|
if (focusable) {
|
|
125
|
-
(0, $9yLAi$
|
|
125
|
+
(0, $9yLAi$reactariainteractions.focusSafely)(focusable);
|
|
126
126
|
(0, $9yLAi$reactariautils.scrollIntoViewport)(focusable, {
|
|
127
127
|
containingElement: (0, $9yLAi$reactariautils.getScrollParent)(ref.current)
|
|
128
128
|
});
|
|
@@ -138,7 +138,7 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
138
138
|
break;
|
|
139
139
|
}
|
|
140
140
|
if (focusMode === 'cell' && direction === 'ltr') {
|
|
141
|
-
(0, $9yLAi$
|
|
141
|
+
(0, $9yLAi$reactariainteractions.focusSafely)(ref.current);
|
|
142
142
|
(0, $9yLAi$reactariautils.scrollIntoViewport)(ref.current, {
|
|
143
143
|
containingElement: (0, $9yLAi$reactariautils.getScrollParent)(ref.current)
|
|
144
144
|
});
|
|
@@ -146,7 +146,7 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
146
146
|
walker.currentNode = ref.current;
|
|
147
147
|
focusable = direction === 'rtl' ? $cf2021be63b01ef4$var$last(walker) : walker.firstChild();
|
|
148
148
|
if (focusable) {
|
|
149
|
-
(0, $9yLAi$
|
|
149
|
+
(0, $9yLAi$reactariainteractions.focusSafely)(focusable);
|
|
150
150
|
(0, $9yLAi$reactariautils.scrollIntoViewport)(focusable, {
|
|
151
151
|
containingElement: (0, $9yLAi$reactariautils.getScrollParent)(ref.current)
|
|
152
152
|
});
|
|
@@ -192,6 +192,9 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
192
192
|
let gridCellProps = (0, $9yLAi$reactariautils.mergeProps)(itemProps, {
|
|
193
193
|
role: 'gridcell',
|
|
194
194
|
onKeyDownCapture: onKeyDownCapture,
|
|
195
|
+
'aria-colspan': node.colSpan,
|
|
196
|
+
'aria-colindex': node.colIndex != null ? node.colIndex + 1 : undefined,
|
|
197
|
+
colSpan: isVirtualized ? undefined : node.colSpan,
|
|
195
198
|
onFocus: onFocus
|
|
196
199
|
});
|
|
197
200
|
var _node_colIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA0CM,SAAS,0CAA4C,KAAoB,EAAE,KAAsB,EAAE,GAAuC;IAC/I,IAAI,QACF,IAAI,iBACJ,aAAa,aACb,YAAY,gCACZ,qBAAqB,YACrB,QAAQ,EACT,GAAG;IAEJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,oBAAC,gBAAgB,EAAE,SAAS,gBAAC,YAAY,EAAC,EAAC,GAAG,CAAA,GAAA,iCAAM,EAAE,GAAG,CAAC;IAE9D,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,mBAAK,EAAc;IAExC,4DAA4D;IAC5D,uDAAuD;IACvD,IAAI,QAAQ;QACV,IAAI,IAAI,OAAO,EAAE;YACf,IAAI,aAAa,CAAA,GAAA,4CAAqB,EAAE,IAAI,OAAO;YACnD,IAAI,cAAc,SAAS;gBACzB,iGAAiG;gBACjG,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,aAAa,KAAK,IAAI,OAAO,KAAK,SAAS,aAAa,EACxF;gBAGF,IAAI,YAAY,MAAM,gBAAgB,CAAC,kBAAkB,KAAK,SAC1D,2BAAK,cACL,WAAW,UAAU;gBACzB,IAAI,WAAW;oBACb,CAAA,GAAA,iCAAU,EAAE;oBACZ;gBACF;YACF;YAEA,IACE,AAAC,eAAe,OAAO,IAAI,QAAQ,KAAK,GAAG,KAAK,eAAe,OAAO,IACtE,CAAC,IAAI,OAA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FAAmF;QACnF,mEAAmE;QACnE,sBAAsB;YACpB,IAAI,cAAc,WAAW,SAAS,aAAa,KAAK,IAAI,OAAO,EACjE;QAEJ;IACF;IAEA,IAAI,gBAA+B,CAAA,GAAA,gCAAS,EAAE,WAAW;QACvD,MAAM;0BACN;iBACA;IACF;QAGoC;IADpC,IAAI,eACF,aAAa,CAAC,gBAAgB,GAAG,AAAC,CAAA,CAAA,iBAAA,KAAK,QAAQ,cAAb,4BAAA,iBAAiB,KAAK,KAAK,AAAD,IAAK,GAAG,2BAA2B;IAGjG,kGAAkG;IAClG,+FAA+F;IAC/F,2FAA2F;IAC3F,4EAA4E;IAC5E,IAAI,yBAAyB,cAAc,QAAQ,IAAI,QAAQ,cAAc,aAAa,IAAI,MAC5F,cAAc,aAAa,GAAG,CAAC;QAC7B,IAAI,KAAK,EAAE,aAAa;QACxB,IAAI,WAAW,GAAG,YAAY,CAAC;QAC/B,GAAG,eAAe,CAAC;QACnB,sBAAsB;YACpB,IAAI,YAAY,MACd,GAAG,YAAY,CAAC,YAAY;QAEhC;IACF;IAGF,OAAO;uBACL;mBACA;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/grid/src/useGridCell.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 {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getScrollParent, mergeProps, scrollIntoViewport} from '@react-aria/utils';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {gridMap} from './utils';\nimport {GridState} from '@react-stately/grid';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport {KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSelectableItem} from '@react-aria/selection';\n\nexport interface GridCellProps {\n /** An object representing the grid cell. Contains all the relevant information that makes up the grid cell. */\n node: GridNode<unknown>,\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether the cell or its first focusable child element should be focused when the grid cell is focused. */\n focusMode?: 'child' | 'cell',\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean,\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n * @deprecated\n **/\n onAction?: () => void\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes,\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps, state: GridState<T, C>, ref: RefObject<FocusableElement | null>): GridCellAria {\n let {\n node,\n isVirtualized,\n focusMode = 'child',\n shouldSelectOnPressUp,\n onAction\n } = props;\n\n let {direction} = useLocale();\n let {keyboardDelegate, actions: {onCellAction}} = gridMap.get(state)!;\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\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n let focus = () => {\n if (ref.current) {\n let treeWalker = getFocusableTreeWalker(ref.current);\n if (focusMode === 'child') {\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (ref.current.contains(document.activeElement) && ref.current !== document.activeElement) {\n return;\n }\n\n let focusable = state.selectionManager.childFocusStrategy === 'last'\n ? last(treeWalker)\n : treeWalker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n return;\n }\n }\n\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\n let {itemProps, isPressed} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n focus,\n shouldSelectOnPressUp,\n onAction: onCellAction ? () => onCellAction(node.key) : onAction,\n isDisabled: state.collection.size === 0\n });\n\n let onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || state.isKeyboardNavigationDisabled || !ref.current || !document.activeElement) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n switch (e.key) {\n case 'ArrowLeft': {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n let prev = keyboardDelegate.getKeyLeftOf?.(node.key);\n if (prev !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? walker.firstChild() as FocusableElement\n : last(walker);\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n let next = keyboardDelegate.getKeyRightOf?.(node.key);\n if (next !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? last(walker)\n : walker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell 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 }\n };\n\n // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\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 gridcell 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/cell\n // in that case since the table should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagatating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (focusMode === 'child' && document.activeElement === ref.current) {\n focus();\n }\n });\n };\n\n let gridCellProps: DOMAttributes = mergeProps(itemProps, {\n role: 'gridcell',\n onKeyDownCapture,\n onFocus\n });\n\n if (isVirtualized) {\n gridCellProps['aria-colindex'] = (node.colIndex ?? node.index) + 1; // aria-colindex is 1-based\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (shouldSelectOnPressUp && gridCellProps.tabIndex != null && gridCellProps.onPointerDown == null) {\n gridCellProps.onPointerDown = (e) => {\n let el = e.currentTarget;\n let tabindex = el.getAttribute('tabindex');\n el.removeAttribute('tabindex');\n requestAnimationFrame(() => {\n if (tabindex != null) {\n el.setAttribute('tabindex', tabindex);\n }\n });\n };\n }\n\n return {\n gridCellProps,\n isPressed\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;\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BAAgB,KAAK,OAAO;QAC5B,iBAAiB,KAAK,QAAQ,IAAI,OAAO,KAAK,QAAQ,GAAG,IAAI;QAC7D,SAAS,gBAAgB,YAAY,KAAK,OAAO;iBACjD;IACF;QAGoC;IADpC,IAAI,eACF,aAAa,CAAC,gBAAgB,GAAG,AAAC,CAAA,CAAA,iBAAA,KAAK,QAAQ,cAAb,4BAAA,iBAAiB,KAAK,KAAK,AAAD,IAAK,GAAG,2BAA2B;IAGjG,kGAAkG;IAClG,+FAA+F;IAC/F,2FAA2F;IAC3F,4EAA4E;IAC5E,IAAI,yBAAyB,cAAc,QAAQ,IAAI,QAAQ,cAAc,aAAa,IAAI,MAC5F,cAAc,aAAa,GAAG,CAAC;QAC7B,IAAI,KAAK,EAAE,aAAa;QACxB,IAAI,WAAW,GAAG,YAAY,CAAC;QAC/B,GAAG,eAAe,CAAC;QACnB,sBAAsB;YACpB,IAAI,YAAY,MACd,GAAG,YAAY,CAAC,YAAY;QAEhC;IACF;IAGF,OAAO;uBACL;mBACA;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/grid/src/useGridCell.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 {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {focusSafely, isFocusVisible} from '@react-aria/interactions';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {getScrollParent, mergeProps, scrollIntoViewport} from '@react-aria/utils';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {gridMap} from './utils';\nimport {GridState} from '@react-stately/grid';\nimport {KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSelectableItem} from '@react-aria/selection';\n\nexport interface GridCellProps {\n /** An object representing the grid cell. Contains all the relevant information that makes up the grid cell. */\n node: GridNode<unknown>,\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether the cell or its first focusable child element should be focused when the grid cell is focused. */\n focusMode?: 'child' | 'cell',\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean,\n /** Indicates how many columns the data cell spans. */\n colSpan?: number,\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n * @deprecated\n **/\n onAction?: () => void\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes,\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps, state: GridState<T, C>, ref: RefObject<FocusableElement | null>): GridCellAria {\n let {\n node,\n isVirtualized,\n focusMode = 'child',\n shouldSelectOnPressUp,\n onAction\n } = props;\n\n let {direction} = useLocale();\n let {keyboardDelegate, actions: {onCellAction}} = gridMap.get(state)!;\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\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n let focus = () => {\n if (ref.current) {\n let treeWalker = getFocusableTreeWalker(ref.current);\n if (focusMode === 'child') {\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (ref.current.contains(document.activeElement) && ref.current !== document.activeElement) {\n return;\n }\n\n let focusable = state.selectionManager.childFocusStrategy === 'last'\n ? last(treeWalker)\n : treeWalker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n return;\n }\n }\n\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\n let {itemProps, isPressed} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n focus,\n shouldSelectOnPressUp,\n onAction: onCellAction ? () => onCellAction(node.key) : onAction,\n isDisabled: state.collection.size === 0\n });\n\n let onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || state.isKeyboardNavigationDisabled || !ref.current || !document.activeElement) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n switch (e.key) {\n case 'ArrowLeft': {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n let prev = keyboardDelegate.getKeyLeftOf?.(node.key);\n if (prev !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? walker.firstChild() as FocusableElement\n : last(walker);\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n let next = keyboardDelegate.getKeyRightOf?.(node.key);\n if (next !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? last(walker)\n : walker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell 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 }\n };\n\n // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\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 gridcell 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/cell\n // in that case since the table should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagatating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (focusMode === 'child' && document.activeElement === ref.current) {\n focus();\n }\n });\n };\n\n let gridCellProps: DOMAttributes = mergeProps(itemProps, {\n role: 'gridcell',\n onKeyDownCapture,\n 'aria-colspan': node.colSpan,\n 'aria-colindex': node.colIndex != null ? node.colIndex + 1 : undefined, // aria-colindex is 1-based\n colSpan: isVirtualized ? undefined : node.colSpan,\n onFocus\n });\n\n if (isVirtualized) {\n gridCellProps['aria-colindex'] = (node.colIndex ?? node.index) + 1; // aria-colindex is 1-based\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (shouldSelectOnPressUp && gridCellProps.tabIndex != null && gridCellProps.onPointerDown == null) {\n gridCellProps.onPointerDown = (e) => {\n let el = e.currentTarget;\n let tabindex = el.getAttribute('tabindex');\n el.removeAttribute('tabindex');\n requestAnimationFrame(() => {\n if (tabindex != null) {\n el.setAttribute('tabindex', tabindex);\n }\n });\n };\n }\n\n return {\n gridCellProps,\n isPressed\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":"useGridCell.main.js.map"}
|
package/dist/useGridCell.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {gridMap as $1af922eb41e03c8f$export$e6235c0d09b995d0} from "./utils.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import {focusSafely as $j4Qbl$focusSafely, isFocusVisible as $j4Qbl$isFocusVisible} from "@react-aria/interactions";
|
|
3
|
+
import {getFocusableTreeWalker as $j4Qbl$getFocusableTreeWalker} from "@react-aria/focus";
|
|
3
4
|
import {scrollIntoViewport as $j4Qbl$scrollIntoViewport, getScrollParent as $j4Qbl$getScrollParent, mergeProps as $j4Qbl$mergeProps} from "@react-aria/utils";
|
|
4
|
-
import {isFocusVisible as $j4Qbl$isFocusVisible} from "@react-aria/interactions";
|
|
5
5
|
import {useRef as $j4Qbl$useRef} from "react";
|
|
6
6
|
import {useLocale as $j4Qbl$useLocale} from "@react-aria/i18n";
|
|
7
7
|
import {useSelectableItem as $j4Qbl$useSelectableItem} from "@react-aria/selection";
|
|
@@ -186,6 +186,9 @@ function $ab90dcbc1b5466d0$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
186
186
|
let gridCellProps = (0, $j4Qbl$mergeProps)(itemProps, {
|
|
187
187
|
role: 'gridcell',
|
|
188
188
|
onKeyDownCapture: onKeyDownCapture,
|
|
189
|
+
'aria-colspan': node.colSpan,
|
|
190
|
+
'aria-colindex': node.colIndex != null ? node.colIndex + 1 : undefined,
|
|
191
|
+
colSpan: isVirtualized ? undefined : node.colSpan,
|
|
189
192
|
onFocus: onFocus
|
|
190
193
|
});
|
|
191
194
|
var _node_colIndex;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {gridMap as $1af922eb41e03c8f$export$e6235c0d09b995d0} from "./utils.module.js";
|
|
2
|
-
import {
|
|
2
|
+
import {focusSafely as $j4Qbl$focusSafely, isFocusVisible as $j4Qbl$isFocusVisible} from "@react-aria/interactions";
|
|
3
|
+
import {getFocusableTreeWalker as $j4Qbl$getFocusableTreeWalker} from "@react-aria/focus";
|
|
3
4
|
import {scrollIntoViewport as $j4Qbl$scrollIntoViewport, getScrollParent as $j4Qbl$getScrollParent, mergeProps as $j4Qbl$mergeProps} from "@react-aria/utils";
|
|
4
|
-
import {isFocusVisible as $j4Qbl$isFocusVisible} from "@react-aria/interactions";
|
|
5
5
|
import {useRef as $j4Qbl$useRef} from "react";
|
|
6
6
|
import {useLocale as $j4Qbl$useLocale} from "@react-aria/i18n";
|
|
7
7
|
import {useSelectableItem as $j4Qbl$useSelectableItem} from "@react-aria/selection";
|
|
@@ -186,6 +186,9 @@ function $ab90dcbc1b5466d0$export$c7e10bfc0c59f67c(props, state, ref) {
|
|
|
186
186
|
let gridCellProps = (0, $j4Qbl$mergeProps)(itemProps, {
|
|
187
187
|
role: 'gridcell',
|
|
188
188
|
onKeyDownCapture: onKeyDownCapture,
|
|
189
|
+
'aria-colspan': node.colSpan,
|
|
190
|
+
'aria-colindex': node.colIndex != null ? node.colIndex + 1 : undefined,
|
|
191
|
+
colSpan: isVirtualized ? undefined : node.colSpan,
|
|
189
192
|
onFocus: onFocus
|
|
190
193
|
});
|
|
191
194
|
var _node_colIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA0CM,SAAS,0CAA4C,KAAoB,EAAE,KAAsB,EAAE,GAAuC;IAC/I,IAAI,QACF,IAAI,iBACJ,aAAa,aACb,YAAY,gCACZ,qBAAqB,YACrB,QAAQ,EACT,GAAG;IAEJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,oBAAC,gBAAgB,EAAE,SAAS,gBAAC,YAAY,EAAC,EAAC,GAAG,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AsB;YACpB,IAAI,YAAY,MACd,GAAG,YAAY,CAAC,YAAY;QAEhC;IACF;IAGF,OAAO;uBACL;mBACA;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/grid/src/useGridCell.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 {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getScrollParent, mergeProps, scrollIntoViewport} from '@react-aria/utils';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {gridMap} from './utils';\nimport {GridState} from '@react-stately/grid';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport {KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSelectableItem} from '@react-aria/selection';\n\nexport interface GridCellProps {\n /** An object representing the grid cell. Contains all the relevant information that makes up the grid cell. */\n node: GridNode<unknown>,\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether the cell or its first focusable child element should be focused when the grid cell is focused. */\n focusMode?: 'child' | 'cell',\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean,\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n * @deprecated\n **/\n onAction?: () => void\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes,\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps, state: GridState<T, C>, ref: RefObject<FocusableElement | null>): GridCellAria {\n let {\n node,\n isVirtualized,\n focusMode = 'child',\n shouldSelectOnPressUp,\n onAction\n } = props;\n\n let {direction} = useLocale();\n let {keyboardDelegate, actions: {onCellAction}} = gridMap.get(state)!;\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\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n let focus = () => {\n if (ref.current) {\n let treeWalker = getFocusableTreeWalker(ref.current);\n if (focusMode === 'child') {\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (ref.current.contains(document.activeElement) && ref.current !== document.activeElement) {\n return;\n }\n\n let focusable = state.selectionManager.childFocusStrategy === 'last'\n ? last(treeWalker)\n : treeWalker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n return;\n }\n }\n\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\n let {itemProps, isPressed} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n focus,\n shouldSelectOnPressUp,\n onAction: onCellAction ? () => onCellAction(node.key) : onAction,\n isDisabled: state.collection.size === 0\n });\n\n let onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || state.isKeyboardNavigationDisabled || !ref.current || !document.activeElement) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n switch (e.key) {\n case 'ArrowLeft': {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n let prev = keyboardDelegate.getKeyLeftOf?.(node.key);\n if (prev !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? walker.firstChild() as FocusableElement\n : last(walker);\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n let next = keyboardDelegate.getKeyRightOf?.(node.key);\n if (next !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? last(walker)\n : walker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell 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 }\n };\n\n // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\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 gridcell 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/cell\n // in that case since the table should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagatating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (focusMode === 'child' && document.activeElement === ref.current) {\n focus();\n }\n });\n };\n\n let gridCellProps: DOMAttributes = mergeProps(itemProps, {\n role: 'gridcell',\n onKeyDownCapture,\n onFocus\n });\n\n if (isVirtualized) {\n gridCellProps['aria-colindex'] = (node.colIndex ?? node.index) + 1; // aria-colindex is 1-based\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (shouldSelectOnPressUp && gridCellProps.tabIndex != null && gridCellProps.onPointerDown == null) {\n gridCellProps.onPointerDown = (e) => {\n let el = e.currentTarget;\n let tabindex = el.getAttribute('tabindex');\n el.removeAttribute('tabindex');\n requestAnimationFrame(() => {\n if (tabindex != null) {\n el.setAttribute('tabindex', tabindex);\n }\n });\n };\n }\n\n return {\n gridCellProps,\n isPressed\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":"useGridCell.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA4CM,SAAS,0CAA4C,KAAoB,EAAE,KAAsB,EAAE,GAAuC;IAC/I,IAAI,QACF,IAAI,iBACJ,aAAa,aACb,YAAY,gCACZ,qBAAqB,YACrB,QAAQ,EACT,GAAG;IAEJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,oBAAC,gBAAgB,EAAE,SAAS,gBAAC,YAAY,EAAC,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC;IAE9D,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,aAAK,EAAc;IAExC,4DAA4D;IAC5D,uDAAuD;IACvD,IAAI,QAAQ;QACV,IAAI,IAAI,OAAO,EAAE;Y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ACF;IAGF,OAAO;uBACL;mBACA;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/grid/src/useGridCell.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 {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {focusSafely, isFocusVisible} from '@react-aria/interactions';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {getScrollParent, mergeProps, scrollIntoViewport} from '@react-aria/utils';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {gridMap} from './utils';\nimport {GridState} from '@react-stately/grid';\nimport {KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSelectableItem} from '@react-aria/selection';\n\nexport interface GridCellProps {\n /** An object representing the grid cell. Contains all the relevant information that makes up the grid cell. */\n node: GridNode<unknown>,\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean,\n /** Whether the cell or its first focusable child element should be focused when the grid cell is focused. */\n focusMode?: 'child' | 'cell',\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean,\n /** Indicates how many columns the data cell spans. */\n colSpan?: number,\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n * @deprecated\n **/\n onAction?: () => void\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes,\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps, state: GridState<T, C>, ref: RefObject<FocusableElement | null>): GridCellAria {\n let {\n node,\n isVirtualized,\n focusMode = 'child',\n shouldSelectOnPressUp,\n onAction\n } = props;\n\n let {direction} = useLocale();\n let {keyboardDelegate, actions: {onCellAction}} = gridMap.get(state)!;\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\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n let focus = () => {\n if (ref.current) {\n let treeWalker = getFocusableTreeWalker(ref.current);\n if (focusMode === 'child') {\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (ref.current.contains(document.activeElement) && ref.current !== document.activeElement) {\n return;\n }\n\n let focusable = state.selectionManager.childFocusStrategy === 'last'\n ? last(treeWalker)\n : treeWalker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n return;\n }\n }\n\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\n let {itemProps, isPressed} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n focus,\n shouldSelectOnPressUp,\n onAction: onCellAction ? () => onCellAction(node.key) : onAction,\n isDisabled: state.collection.size === 0\n });\n\n let onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || state.isKeyboardNavigationDisabled || !ref.current || !document.activeElement) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n switch (e.key) {\n case 'ArrowLeft': {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n let prev = keyboardDelegate.getKeyLeftOf?.(node.key);\n if (prev !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? walker.firstChild() as FocusableElement\n : last(walker);\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n let focusable: FocusableElement | null = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusMode === 'child' && focusable === ref.current) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n let next = keyboardDelegate.getKeyRightOf?.(node.key);\n if (next !== node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n break;\n }\n\n if (focusMode === 'cell' && direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n focusable = direction === 'rtl'\n ? last(walker)\n : walker.firstChild() as FocusableElement;\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell 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 }\n };\n\n // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\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 gridcell 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/cell\n // in that case since the table should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagatating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (focusMode === 'child' && document.activeElement === ref.current) {\n focus();\n }\n });\n };\n\n let gridCellProps: DOMAttributes = mergeProps(itemProps, {\n role: 'gridcell',\n onKeyDownCapture,\n 'aria-colspan': node.colSpan,\n 'aria-colindex': node.colIndex != null ? node.colIndex + 1 : undefined, // aria-colindex is 1-based\n colSpan: isVirtualized ? undefined : node.colSpan,\n onFocus\n });\n\n if (isVirtualized) {\n gridCellProps['aria-colindex'] = (node.colIndex ?? node.index) + 1; // aria-colindex is 1-based\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (shouldSelectOnPressUp && gridCellProps.tabIndex != null && gridCellProps.onPointerDown == null) {\n gridCellProps.onPointerDown = (e) => {\n let el = e.currentTarget;\n let tabindex = el.getAttribute('tabindex');\n el.removeAttribute('tabindex');\n requestAnimationFrame(() => {\n if (tabindex != null) {\n el.setAttribute('tabindex', tabindex);\n }\n });\n };\n }\n\n return {\n gridCellProps,\n isPressed\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":"useGridCell.module.js.map"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var $085250522aa37816$exports = require("./intlStrings.main.js");
|
|
2
2
|
var $iMOYA$reactarialiveannouncer = require("@react-aria/live-announcer");
|
|
3
|
+
var $iMOYA$reactariautils = require("@react-aria/utils");
|
|
3
4
|
var $iMOYA$reactariai18n = require("@react-aria/i18n");
|
|
4
5
|
var $iMOYA$react = require("react");
|
|
5
|
-
var $iMOYA$reactariautils = require("@react-aria/utils");
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
function $parcel$interopDefault(a) {
|
|
@@ -40,9 +40,9 @@ function $1eb174acfe8a0f16$export$137e594ef3218a10(props, state) {
|
|
|
40
40
|
// We do this using an ARIA live region.
|
|
41
41
|
let selection = state.selectionManager.rawSelection;
|
|
42
42
|
let lastSelection = (0, $iMOYA$react.useRef)(selection);
|
|
43
|
-
(0, $iMOYA$reactariautils.
|
|
43
|
+
let announceSelectionChange = (0, $iMOYA$reactariautils.useEffectEvent)(()=>{
|
|
44
44
|
var _lastSelection_current;
|
|
45
|
-
if (!state.selectionManager.isFocused) {
|
|
45
|
+
if (!state.selectionManager.isFocused || selection === lastSelection.current) {
|
|
46
46
|
lastSelection.current = selection;
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
@@ -79,8 +79,17 @@ function $1eb174acfe8a0f16$export$137e594ef3218a10(props, state) {
|
|
|
79
79
|
}
|
|
80
80
|
if (messages.length > 0) (0, $iMOYA$reactarialiveannouncer.announce)(messages.join(' '));
|
|
81
81
|
lastSelection.current = selection;
|
|
82
|
+
});
|
|
83
|
+
(0, $iMOYA$reactariautils.useUpdateEffect)(()=>{
|
|
84
|
+
if (state.selectionManager.isFocused) announceSelectionChange();
|
|
85
|
+
else {
|
|
86
|
+
// Wait a frame in case the collection is about to become focused (e.g. on mouse down).
|
|
87
|
+
let raf = requestAnimationFrame(announceSelectionChange);
|
|
88
|
+
return ()=>cancelAnimationFrame(raf);
|
|
89
|
+
}
|
|
82
90
|
}, [
|
|
83
|
-
selection
|
|
91
|
+
selection,
|
|
92
|
+
state.selectionManager.isFocused
|
|
84
93
|
]);
|
|
85
94
|
}
|
|
86
95
|
function $1eb174acfe8a0f16$var$diffSelection(a, b) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA4BM,SAAS,0CAAgC,KAAqC,EAAE,KAA4B;IACjH,IAAI,cACF,aAAa,CAAC;YAAQ,gCAAA,mBAAwC;YAAxC;eAAA,CAAA,mCAAA,iCAAA,CAAA,oBAAA,MAAM,UAAU,EAAC,YAAY,cAA7B,qDAAA,oCAAA,mBAAgC,kBAAhC,6CAAA,mCAAwC,4BA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AAG,GACpB,CAAA,GAAA,sCAAO,EAAE,SAAS,IAAI,CAAC;QAGzB,cAAc,OAAO,GAAG;IAC1B;IAEA,CAAA,GAAA,qCAAc,EAAE;QACd,IAAI,MAAM,gBAAgB,CAAC,SAAS,EAClC;aACK;YACL,uFAAuF;YACvF,IAAI,MAAM,sBAAsB;YAChC,OAAO,IAAM,qBAAqB;QACpC;IACF,GAAG;QAAC;QAAW,MAAM,gBAAgB,CAAC,SAAS;KAAC;AAClD;AAEA,SAAS,oCAAc,CAAY,EAAE,CAAY;IAC/C,IAAI,MAAM,IAAI;IACd,IAAI,MAAM,SAAS,MAAM,OACvB,OAAO;IAGT,KAAK,IAAI,OAAO,EAAE,IAAI,GACpB,IAAI,CAAC,EAAE,GAAG,CAAC,MACT,IAAI,GAAG,CAAC;IAIZ,OAAO;AACT","sources":["packages/@react-aria/grid/src/useGridSelectionAnnouncement.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 {announce} from '@react-aria/live-announcer';\nimport {Collection, Key, Node, Selection} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {SelectionManager} from '@react-stately/selection';\nimport {useEffectEvent, useUpdateEffect} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useRef} from 'react';\n\nexport interface GridSelectionAnnouncementProps {\n /**\n * A function that returns the text that should be announced by assistive technology when a row is added or removed from selection.\n * @default (key) => state.collection.getItem(key)?.textValue\n */\n getRowText?: (key: Key) => string\n}\n\ninterface GridSelectionState<T> {\n /** A collection of items in the grid. */\n collection: Collection<Node<T>>,\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager\n}\n\nexport function useGridSelectionAnnouncement<T>(props: GridSelectionAnnouncementProps, state: GridSelectionState<T>) {\n let {\n getRowText = (key) => state.collection.getTextValue?.(key) ?? state.collection.getItem(key)?.textValue\n } = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/grid');\n\n // Many screen readers do not announce when items in a grid are selected/deselected.\n // We do this using an ARIA live region.\n let selection = state.selectionManager.rawSelection;\n let lastSelection = useRef(selection);\n let announceSelectionChange = useEffectEvent(() => {\n if (!state.selectionManager.isFocused || selection === lastSelection.current) {\n lastSelection.current = selection;\n\n return;\n }\n\n let addedKeys = diffSelection(selection, lastSelection.current);\n let removedKeys = diffSelection(lastSelection.current, selection);\n\n // If adding or removing a single row from the selection, announce the name of that item.\n let isReplace = state.selectionManager.selectionBehavior === 'replace';\n let messages: string[] = [];\n\n if ((state.selectionManager.selectedKeys.size === 1 && isReplace)) {\n if (state.collection.getItem(state.selectionManager.selectedKeys.keys().next().value)) {\n let currentSelectionText = getRowText(state.selectionManager.selectedKeys.keys().next().value);\n if (currentSelectionText) {\n messages.push(stringFormatter.format('selectedItem', {item: currentSelectionText}));\n }\n }\n } else if (addedKeys.size === 1 && removedKeys.size === 0) {\n let addedText = getRowText(addedKeys.keys().next().value);\n if (addedText) {\n messages.push(stringFormatter.format('selectedItem', {item: addedText}));\n }\n } else if (removedKeys.size === 1 && addedKeys.size === 0) {\n if (state.collection.getItem(removedKeys.keys().next().value)) {\n let removedText = getRowText(removedKeys.keys().next().value);\n if (removedText) {\n messages.push(stringFormatter.format('deselectedItem', {item: removedText}));\n }\n }\n }\n\n // Announce how many items are selected, except when selecting the first item.\n if (state.selectionManager.selectionMode === 'multiple') {\n if (messages.length === 0 || selection === 'all' || selection.size > 1 || lastSelection.current === 'all' || lastSelection.current?.size > 1) {\n messages.push(selection === 'all'\n ? stringFormatter.format('selectedAll')\n : stringFormatter.format('selectedCount', {count: selection.size})\n );\n }\n }\n\n if (messages.length > 0) {\n announce(messages.join(' '));\n }\n\n lastSelection.current = selection;\n });\n\n useUpdateEffect(() => {\n if (state.selectionManager.isFocused) {\n announceSelectionChange();\n } else {\n // Wait a frame in case the collection is about to become focused (e.g. on mouse down).\n let raf = requestAnimationFrame(announceSelectionChange);\n return () => cancelAnimationFrame(raf);\n }\n }, [selection, state.selectionManager.isFocused]);\n}\n\nfunction diffSelection(a: Selection, b: Selection): Set<Key> {\n let res = new Set<Key>();\n if (a === 'all' || b === 'all') {\n return res;\n }\n\n for (let key of a.keys()) {\n if (!b.has(key)) {\n res.add(key);\n }\n }\n\n return res;\n}\n"],"names":[],"version":3,"file":"useGridSelectionAnnouncement.main.js.map"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import $4stjr$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
2
|
import {announce as $4stjr$announce} from "@react-aria/live-announcer";
|
|
3
|
+
import {useEffectEvent as $4stjr$useEffectEvent, useUpdateEffect as $4stjr$useUpdateEffect} from "@react-aria/utils";
|
|
3
4
|
import {useLocalizedStringFormatter as $4stjr$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
4
5
|
import {useRef as $4stjr$useRef} from "react";
|
|
5
|
-
import {useUpdateEffect as $4stjr$useUpdateEffect} from "@react-aria/utils";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
function $parcel$interopDefault(a) {
|
|
@@ -34,9 +34,9 @@ function $92599c3fd427b763$export$137e594ef3218a10(props, state) {
|
|
|
34
34
|
// We do this using an ARIA live region.
|
|
35
35
|
let selection = state.selectionManager.rawSelection;
|
|
36
36
|
let lastSelection = (0, $4stjr$useRef)(selection);
|
|
37
|
-
(0, $4stjr$
|
|
37
|
+
let announceSelectionChange = (0, $4stjr$useEffectEvent)(()=>{
|
|
38
38
|
var _lastSelection_current;
|
|
39
|
-
if (!state.selectionManager.isFocused) {
|
|
39
|
+
if (!state.selectionManager.isFocused || selection === lastSelection.current) {
|
|
40
40
|
lastSelection.current = selection;
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -73,8 +73,17 @@ function $92599c3fd427b763$export$137e594ef3218a10(props, state) {
|
|
|
73
73
|
}
|
|
74
74
|
if (messages.length > 0) (0, $4stjr$announce)(messages.join(' '));
|
|
75
75
|
lastSelection.current = selection;
|
|
76
|
+
});
|
|
77
|
+
(0, $4stjr$useUpdateEffect)(()=>{
|
|
78
|
+
if (state.selectionManager.isFocused) announceSelectionChange();
|
|
79
|
+
else {
|
|
80
|
+
// Wait a frame in case the collection is about to become focused (e.g. on mouse down).
|
|
81
|
+
let raf = requestAnimationFrame(announceSelectionChange);
|
|
82
|
+
return ()=>cancelAnimationFrame(raf);
|
|
83
|
+
}
|
|
76
84
|
}, [
|
|
77
|
-
selection
|
|
85
|
+
selection,
|
|
86
|
+
state.selectionManager.isFocused
|
|
78
87
|
]);
|
|
79
88
|
}
|
|
80
89
|
function $92599c3fd427b763$var$diffSelection(a, b) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import $4stjr$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
2
|
import {announce as $4stjr$announce} from "@react-aria/live-announcer";
|
|
3
|
+
import {useEffectEvent as $4stjr$useEffectEvent, useUpdateEffect as $4stjr$useUpdateEffect} from "@react-aria/utils";
|
|
3
4
|
import {useLocalizedStringFormatter as $4stjr$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
4
5
|
import {useRef as $4stjr$useRef} from "react";
|
|
5
|
-
import {useUpdateEffect as $4stjr$useUpdateEffect} from "@react-aria/utils";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
function $parcel$interopDefault(a) {
|
|
@@ -34,9 +34,9 @@ function $92599c3fd427b763$export$137e594ef3218a10(props, state) {
|
|
|
34
34
|
// We do this using an ARIA live region.
|
|
35
35
|
let selection = state.selectionManager.rawSelection;
|
|
36
36
|
let lastSelection = (0, $4stjr$useRef)(selection);
|
|
37
|
-
(0, $4stjr$
|
|
37
|
+
let announceSelectionChange = (0, $4stjr$useEffectEvent)(()=>{
|
|
38
38
|
var _lastSelection_current;
|
|
39
|
-
if (!state.selectionManager.isFocused) {
|
|
39
|
+
if (!state.selectionManager.isFocused || selection === lastSelection.current) {
|
|
40
40
|
lastSelection.current = selection;
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -73,8 +73,17 @@ function $92599c3fd427b763$export$137e594ef3218a10(props, state) {
|
|
|
73
73
|
}
|
|
74
74
|
if (messages.length > 0) (0, $4stjr$announce)(messages.join(' '));
|
|
75
75
|
lastSelection.current = selection;
|
|
76
|
+
});
|
|
77
|
+
(0, $4stjr$useUpdateEffect)(()=>{
|
|
78
|
+
if (state.selectionManager.isFocused) announceSelectionChange();
|
|
79
|
+
else {
|
|
80
|
+
// Wait a frame in case the collection is about to become focused (e.g. on mouse down).
|
|
81
|
+
let raf = requestAnimationFrame(announceSelectionChange);
|
|
82
|
+
return ()=>cancelAnimationFrame(raf);
|
|
83
|
+
}
|
|
76
84
|
}, [
|
|
77
|
-
selection
|
|
85
|
+
selection,
|
|
86
|
+
state.selectionManager.isFocused
|
|
78
87
|
]);
|
|
79
88
|
}
|
|
80
89
|
function $92599c3fd427b763$var$diffSelection(a, b) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA4BM,SAAS,0CAAgC,KAAqC,EAAE,KAA4B;IACjH,IAAI,cACF,aAAa,CAAC;YAAQ,gCAAA,mBAAwC;YAAxC;eAAA,CAAA,mCAAA,iCAAA,CAAA,oBAAA,MAAM,UAAU,EAAC,YAAY,cAA7B,qDAAA,oCAAA,mBAAgC,kBAAhC,6CAAA,mCAAwC,4BAAA,MAAM,UAAU,CAAC,OAAO,CAAC,kBAAzB,gDAAA,0BAA+B,SAAS;OACvG,GAAG;IACJ,IAAI,kBAAkB,CAA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,EAAE;QACd,IAAI,MAAM,gBAAgB,CAAC,SAAS,EAClC;aACK;YACL,uFAAuF;YACvF,IAAI,MAAM,sBAAsB;YAChC,OAAO,IAAM,qBAAqB;QACpC;IACF,GAAG;QAAC;QAAW,MAAM,gBAAgB,CAAC,SAAS;KAAC;AAClD;AAEA,SAAS,oCAAc,CAAY,EAAE,CAAY;IAC/C,IAAI,MAAM,IAAI;IACd,IAAI,MAAM,SAAS,MAAM,OACvB,OAAO;IAGT,KAAK,IAAI,OAAO,EAAE,IAAI,GACpB,IAAI,CAAC,EAAE,GAAG,CAAC,MACT,IAAI,GAAG,CAAC;IAIZ,OAAO;AACT","sources":["packages/@react-aria/grid/src/useGridSelectionAnnouncement.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 {announce} from '@react-aria/live-announcer';\nimport {Collection, Key, Node, Selection} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {SelectionManager} from '@react-stately/selection';\nimport {useEffectEvent, useUpdateEffect} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useRef} from 'react';\n\nexport interface GridSelectionAnnouncementProps {\n /**\n * A function that returns the text that should be announced by assistive technology when a row is added or removed from selection.\n * @default (key) => state.collection.getItem(key)?.textValue\n */\n getRowText?: (key: Key) => string\n}\n\ninterface GridSelectionState<T> {\n /** A collection of items in the grid. */\n collection: Collection<Node<T>>,\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager\n}\n\nexport function useGridSelectionAnnouncement<T>(props: GridSelectionAnnouncementProps, state: GridSelectionState<T>) {\n let {\n getRowText = (key) => state.collection.getTextValue?.(key) ?? state.collection.getItem(key)?.textValue\n } = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/grid');\n\n // Many screen readers do not announce when items in a grid are selected/deselected.\n // We do this using an ARIA live region.\n let selection = state.selectionManager.rawSelection;\n let lastSelection = useRef(selection);\n let announceSelectionChange = useEffectEvent(() => {\n if (!state.selectionManager.isFocused || selection === lastSelection.current) {\n lastSelection.current = selection;\n\n return;\n }\n\n let addedKeys = diffSelection(selection, lastSelection.current);\n let removedKeys = diffSelection(lastSelection.current, selection);\n\n // If adding or removing a single row from the selection, announce the name of that item.\n let isReplace = state.selectionManager.selectionBehavior === 'replace';\n let messages: string[] = [];\n\n if ((state.selectionManager.selectedKeys.size === 1 && isReplace)) {\n if (state.collection.getItem(state.selectionManager.selectedKeys.keys().next().value)) {\n let currentSelectionText = getRowText(state.selectionManager.selectedKeys.keys().next().value);\n if (currentSelectionText) {\n messages.push(stringFormatter.format('selectedItem', {item: currentSelectionText}));\n }\n }\n } else if (addedKeys.size === 1 && removedKeys.size === 0) {\n let addedText = getRowText(addedKeys.keys().next().value);\n if (addedText) {\n messages.push(stringFormatter.format('selectedItem', {item: addedText}));\n }\n } else if (removedKeys.size === 1 && addedKeys.size === 0) {\n if (state.collection.getItem(removedKeys.keys().next().value)) {\n let removedText = getRowText(removedKeys.keys().next().value);\n if (removedText) {\n messages.push(stringFormatter.format('deselectedItem', {item: removedText}));\n }\n }\n }\n\n // Announce how many items are selected, except when selecting the first item.\n if (state.selectionManager.selectionMode === 'multiple') {\n if (messages.length === 0 || selection === 'all' || selection.size > 1 || lastSelection.current === 'all' || lastSelection.current?.size > 1) {\n messages.push(selection === 'all'\n ? stringFormatter.format('selectedAll')\n : stringFormatter.format('selectedCount', {count: selection.size})\n );\n }\n }\n\n if (messages.length > 0) {\n announce(messages.join(' '));\n }\n\n lastSelection.current = selection;\n });\n\n useUpdateEffect(() => {\n if (state.selectionManager.isFocused) {\n announceSelectionChange();\n } else {\n // Wait a frame in case the collection is about to become focused (e.g. on mouse down).\n let raf = requestAnimationFrame(announceSelectionChange);\n return () => cancelAnimationFrame(raf);\n }\n }, [selection, state.selectionManager.isFocused]);\n}\n\nfunction diffSelection(a: Selection, b: Selection): Set<Key> {\n let res = new Set<Key>();\n if (a === 'all' || b === 'all') {\n return res;\n }\n\n for (let key of a.keys()) {\n if (!b.has(key)) {\n res.add(key);\n }\n }\n\n return res;\n}\n"],"names":[],"version":3,"file":"useGridSelectionAnnouncement.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/grid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "^3.
|
|
26
|
-
"@react-aria/i18n": "^3.12.
|
|
27
|
-
"@react-aria/interactions": "^3.
|
|
25
|
+
"@react-aria/focus": "^3.20.1",
|
|
26
|
+
"@react-aria/i18n": "^3.12.7",
|
|
27
|
+
"@react-aria/interactions": "^3.24.1",
|
|
28
28
|
"@react-aria/live-announcer": "^3.4.1",
|
|
29
|
-
"@react-aria/selection": "^3.
|
|
30
|
-
"@react-aria/utils": "^3.
|
|
31
|
-
"@react-stately/collections": "^3.12.
|
|
32
|
-
"@react-stately/grid": "^3.
|
|
33
|
-
"@react-stately/selection": "^3.
|
|
34
|
-
"@react-types/checkbox": "^3.9.
|
|
35
|
-
"@react-types/grid": "^3.
|
|
36
|
-
"@react-types/shared": "^3.
|
|
29
|
+
"@react-aria/selection": "^3.23.1",
|
|
30
|
+
"@react-aria/utils": "^3.28.1",
|
|
31
|
+
"@react-stately/collections": "^3.12.2",
|
|
32
|
+
"@react-stately/grid": "^3.11.0",
|
|
33
|
+
"@react-stately/selection": "^3.20.0",
|
|
34
|
+
"@react-types/checkbox": "^3.9.2",
|
|
35
|
+
"@react-types/grid": "^3.3.0",
|
|
36
|
+
"@react-types/shared": "^3.28.0",
|
|
37
37
|
"@swc/helpers": "^0.5.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "9c4ebbc0c1972cc880febc29de995ca58caa3ba4"
|
|
47
47
|
}
|