@react-stately/grid 3.6.2-nightly.3940 → 3.6.2-nightly.3960
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/package.json +6 -6
- package/src/useGridState.ts +1 -1
package/dist/import.mjs
CHANGED
|
@@ -52,7 +52,7 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
52
52
|
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
53
53
|
let newRow;
|
|
54
54
|
while(index >= 0){
|
|
55
|
-
if (!selectionManager.isDisabled(rows[index].key)) {
|
|
55
|
+
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== "headerrow") {
|
|
56
56
|
newRow = rows[index];
|
|
57
57
|
break;
|
|
58
58
|
}
|
package/dist/main.js
CHANGED
|
@@ -61,7 +61,7 @@ function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
|
|
|
61
61
|
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
62
62
|
let newRow;
|
|
63
63
|
while(index >= 0){
|
|
64
|
-
if (!selectionManager.isDisabled(rows[index].key)) {
|
|
64
|
+
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== "headerrow") {
|
|
65
65
|
newRow = rows[index];
|
|
66
66
|
break;
|
|
67
67
|
}
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;AAwBO,SAAS,0CAA4D,KAA6B,EAAmB;IAC1H,IAAI,cAAC,WAAU,aAAE,UAAS,EAAC,GAAG;IAC9B,IAAI,iBAAiB,CAAA,GAAA,sDAAwB,EAAE;IAC/C,IAAI,eAAe,CA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,MAAM;gBACN,OAAO;gBACP,eAAe,IAAI;gBACnB,YAAY;uBAAI,KAAK,UAAU;iBAAC;gBAChC,UAAU;gBACV,WAAW;gBACX,GAAG,IAAI;gBACP,OAAO;YACT;YAEA,IAAI,MAAM;gBACR,KAAK,OAAO,GAAG,QAAQ,GAAG;gBAC1B,QAAQ,OAAO,GAAG,KAAK,GAAG;YAC5B,OACE,QAAQ,OAAO,GAAG,IAAI;YAGxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,OAAO,GAAG,IAAI;IAEvB;AA8CF;","sources":["packages/@react-stately/grid/src/index.ts","packages/@react-stately/grid/src/useGridState.ts","packages/@react-stately/grid/src/GridCollection.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\nexport {useGridState} from './useGridState';\nexport {GridCollection} from './GridCollection';\n\nexport type {GridStateOptions, GridState} from './useGridState';\n","import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {Key, useEffect, useMemo, useRef} from 'react';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\n\nexport interface GridState<T, C extends GridCollection<T>> {\n collection: C,\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean\n}\n\nexport interface GridStateOptions<T, C extends GridCollection<T>> extends MultipleSelectionStateProps {\n collection: C,\n disabledKeys?: Iterable<Key>,\n focusMode?: 'row' | 'cell'\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> {\n let {collection, focusMode} = props;\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key;\n } else {\n key = getFirstItem(children)?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?\n cachedCollection.current.getItem(node.parentKey) :\n node;\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(parentNode.index - diff + 1, 0) :\n parentNode.index\n ),\n rows.length - 1);\n let newRow:GridNode<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key)) {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes &&\n parentNode !== node &&\n node.index < childNodes.length ?\n childNodes[node.index].key :\n newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n","/*\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 */\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from 'react';\n\n\ninterface GridCollectionOptions<T> {\n columnCount: number,\n items: GridRow<T>[],\n visitNode?: (cell: GridNode<T>) => GridNode<T>\n}\n\nexport class GridCollection<T> implements IGridCollection<T> {\n keyMap: Map<Key, GridNode<T>> = new Map();\n columnCount: number;\n rows: GridNode<T>[];\n\n constructor(opts?: GridCollectionOptions<T>) {\n this.keyMap = new Map();\n this.columnCount = opts?.columnCount;\n this.rows = [];\n\n let visit = (node: GridNode<T>) => {\n // If the node is the same object as the previous node for the same key,\n // we can skip this node and its children. We always visit columns though,\n // because we depend on order to build the columns array.\n let prevNode = this.keyMap.get(node.key);\n if (opts.visitNode) {\n node = opts.visitNode(node);\n }\n\n this.keyMap.set(node.key, node);\n\n let childKeys = new Set();\n let last: GridNode<T>;\n for (let child of node.childNodes) {\n if (child.type === 'cell' && child.parentKey == null) {\n // if child is a cell parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n childKeys.add(child.key);\n\n if (last) {\n last.nextKey = child.key;\n child.prevKey = last.key;\n } else {\n child.prevKey = null;\n }\n\n visit(child);\n last = child;\n }\n\n if (last) {\n last.nextKey = null;\n }\n\n // Remove deleted nodes and their children from the key map\n if (prevNode) {\n for (let child of prevNode.childNodes) {\n if (!childKeys.has(child.key)) {\n remove(child);\n }\n }\n }\n };\n\n let remove = (node: GridNode<T>) => {\n this.keyMap.delete(node.key);\n for (let child of node.childNodes) {\n if (this.keyMap.get(child.key) === child) {\n remove(child);\n }\n }\n };\n\n let last: GridNode<T>;\n opts.items.forEach((node, i) => {\n let rowNode = {\n level: 0,\n key: 'row-' + i,\n type: 'row',\n value: undefined,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: undefined,\n textValue: undefined,\n ...node,\n index: i\n } as GridNode<T>;\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n });\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;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AK,IAAI,SAAS,KAAK,UAAU,CAC/B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,OACjC,OAAO;QAGb;QAEA,IAAI;QACJ,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,IAAM;YAC9B,IAAI,UAAU;gBACZ,OAAO;gBACP,KAAK,SAAS;gBACd,MAAM;gBACN,OAAO;gBACP,eAAe,IAAI;gBACnB,YAAY;uBAAI,KAAK,UAAU;iBAAC;gBAChC,UAAU;gBACV,WAAW;gBACX,GAAG,IAAI;gBACP,OAAO;YACT;YAEA,IAAI,MAAM;gBACR,KAAK,OAAO,GAAG,QAAQ,GAAG;gBAC1B,QAAQ,OAAO,GAAG,KAAK,GAAG;YAC5B,OACE,QAAQ,OAAO,GAAG,IAAI;YAGxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,OAAO,GAAG,IAAI;IAEvB;AA8CF;","sources":["packages/@react-stately/grid/src/index.ts","packages/@react-stately/grid/src/useGridState.ts","packages/@react-stately/grid/src/GridCollection.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\nexport {useGridState} from './useGridState';\nexport {GridCollection} from './GridCollection';\n\nexport type {GridStateOptions, GridState} from './useGridState';\n","import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {Key, useEffect, useMemo, useRef} from 'react';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\n\nexport interface GridState<T, C extends GridCollection<T>> {\n collection: C,\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean\n}\n\nexport interface GridStateOptions<T, C extends GridCollection<T>> extends MultipleSelectionStateProps {\n collection: C,\n disabledKeys?: Iterable<Key>,\n focusMode?: 'row' | 'cell'\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> {\n let {collection, focusMode} = props;\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key;\n } else {\n key = getFirstItem(children)?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?\n cachedCollection.current.getItem(node.parentKey) :\n node;\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(parentNode.index - diff + 1, 0) :\n parentNode.index\n ),\n rows.length - 1);\n let newRow:GridNode<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes &&\n parentNode !== node &&\n node.index < childNodes.length ?\n childNodes[node.index].key :\n newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n","/*\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 */\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from 'react';\n\n\ninterface GridCollectionOptions<T> {\n columnCount: number,\n items: GridRow<T>[],\n visitNode?: (cell: GridNode<T>) => GridNode<T>\n}\n\nexport class GridCollection<T> implements IGridCollection<T> {\n keyMap: Map<Key, GridNode<T>> = new Map();\n columnCount: number;\n rows: GridNode<T>[];\n\n constructor(opts?: GridCollectionOptions<T>) {\n this.keyMap = new Map();\n this.columnCount = opts?.columnCount;\n this.rows = [];\n\n let visit = (node: GridNode<T>) => {\n // If the node is the same object as the previous node for the same key,\n // we can skip this node and its children. We always visit columns though,\n // because we depend on order to build the columns array.\n let prevNode = this.keyMap.get(node.key);\n if (opts.visitNode) {\n node = opts.visitNode(node);\n }\n\n this.keyMap.set(node.key, node);\n\n let childKeys = new Set();\n let last: GridNode<T>;\n for (let child of node.childNodes) {\n if (child.type === 'cell' && child.parentKey == null) {\n // if child is a cell parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n childKeys.add(child.key);\n\n if (last) {\n last.nextKey = child.key;\n child.prevKey = last.key;\n } else {\n child.prevKey = null;\n }\n\n visit(child);\n last = child;\n }\n\n if (last) {\n last.nextKey = null;\n }\n\n // Remove deleted nodes and their children from the key map\n if (prevNode) {\n for (let child of prevNode.childNodes) {\n if (!childKeys.has(child.key)) {\n remove(child);\n }\n }\n }\n };\n\n let remove = (node: GridNode<T>) => {\n this.keyMap.delete(node.key);\n for (let child of node.childNodes) {\n if (this.keyMap.get(child.key) === child) {\n remove(child);\n }\n }\n };\n\n let last: GridNode<T>;\n opts.items.forEach((node, i) => {\n let rowNode = {\n level: 0,\n key: 'row-' + i,\n type: 'row',\n value: undefined,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: undefined,\n textValue: undefined,\n ...node,\n index: i\n } as GridNode<T>;\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n });\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -52,7 +52,7 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
52
52
|
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
53
53
|
let newRow;
|
|
54
54
|
while(index >= 0){
|
|
55
|
-
if (!selectionManager.isDisabled(rows[index].key)) {
|
|
55
|
+
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== "headerrow") {
|
|
56
56
|
newRow = rows[index];
|
|
57
57
|
break;
|
|
58
58
|
}
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;AAwBO,SAAS,0CAA4D,KAA6B,EAAmB;IAC1H,IAAI,cAAC,WAAU,aAAE,UAAS,EAAC,GAAG;IAC9B,IAAI,iBAAiB,CAAA,GAAA,gCAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,cAAO,AAAD,EAAE,IACvB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,KAAU,EACjE;QAAC,MAAM,YAAY;KAAC;IAExB,IAAI,gBAAgB,eAAe,aAAa;IAChD,eAAe,aAAa,GAAG,CAAC,KAAK,QAAU;QAC7C,2EAA2E;QAC3E,IAAI,cAAc,UAAU,OAAO,IAAI,EAAE;YACvC,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,IAAI,AAAD,MAAM,QAAQ;oBAGjB,cAEA;gBAJR,IAAI,W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ages/@react-stately/grid/src/index.ts","packages/@react-stately/grid/src/useGridState.ts","packages/@react-stately/grid/src/GridCollection.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\nexport {useGridState} from './useGridState';\nexport {GridCollection} from './GridCollection';\n\nexport type {GridStateOptions, GridState} from './useGridState';\n","import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {Key, useEffect, useMemo, useRef} from 'react';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\n\nexport interface GridState<T, C extends GridCollection<T>> {\n collection: C,\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean\n}\n\nexport interface GridStateOptions<T, C extends GridCollection<T>> extends MultipleSelectionStateProps {\n collection: C,\n disabledKeys?: Iterable<Key>,\n focusMode?: 'row' | 'cell'\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> {\n let {collection, focusMode} = props;\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key;\n } else {\n key = getFirstItem(children)?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?\n cachedCollection.current.getItem(node.parentKey) :\n node;\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(parentNode.index - diff + 1, 0) :\n parentNode.index\n ),\n rows.length - 1);\n let newRow:GridNode<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key)) {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes &&\n parentNode !== node &&\n node.index < childNodes.length ?\n childNodes[node.index].key :\n newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n","/*\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 */\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from 'react';\n\n\ninterface GridCollectionOptions<T> {\n columnCount: number,\n items: GridRow<T>[],\n visitNode?: (cell: GridNode<T>) => GridNode<T>\n}\n\nexport class GridCollection<T> implements IGridCollection<T> {\n keyMap: Map<Key, GridNode<T>> = new Map();\n columnCount: number;\n rows: GridNode<T>[];\n\n constructor(opts?: GridCollectionOptions<T>) {\n this.keyMap = new Map();\n this.columnCount = opts?.columnCount;\n this.rows = [];\n\n let visit = (node: GridNode<T>) => {\n // If the node is the same object as the previous node for the same key,\n // we can skip this node and its children. We always visit columns though,\n // because we depend on order to build the columns array.\n let prevNode = this.keyMap.get(node.key);\n if (opts.visitNode) {\n node = opts.visitNode(node);\n }\n\n this.keyMap.set(node.key, node);\n\n let childKeys = new Set();\n let last: GridNode<T>;\n for (let child of node.childNodes) {\n if (child.type === 'cell' && child.parentKey == null) {\n // if child is a cell parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n childKeys.add(child.key);\n\n if (last) {\n last.nextKey = child.key;\n child.prevKey = last.key;\n } else {\n child.prevKey = null;\n }\n\n visit(child);\n last = child;\n }\n\n if (last) {\n last.nextKey = null;\n }\n\n // Remove deleted nodes and their children from the key map\n if (prevNode) {\n for (let child of prevNode.childNodes) {\n if (!childKeys.has(child.key)) {\n remove(child);\n }\n }\n }\n };\n\n let remove = (node: GridNode<T>) => {\n this.keyMap.delete(node.key);\n for (let child of node.childNodes) {\n if (this.keyMap.get(child.key) === child) {\n remove(child);\n }\n }\n };\n\n let last: GridNode<T>;\n opts.items.forEach((node, i) => {\n let rowNode = {\n level: 0,\n key: 'row-' + i,\n type: 'row',\n value: undefined,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: undefined,\n textValue: undefined,\n ...node,\n index: i\n } as GridNode<T>;\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n });\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;AAwBO,SAAS,0CAA4D,KAA6B,EAAmB;IAC1H,IAAI,cAAC,WAAU,aAAE,UAAS,EAAC,GAAG;IAC9B,IAAI,iBAAiB,CAAA,GAAA,gCAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,cAAO,AAAD,EAAE,IACvB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,KAAU,EACjE;QAAC,MAAM,YAAY;KAAC;IAExB,IAAI,gBAAgB,eAAe,aAAa;IAChD,eAAe,aAAa,GAAG,CAAC,KAAK,QAAU;QAC7C,2EAA2E;QAC3E,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Q,GAAG;gBAC1B,QAAQ,OAAO,GAAG,KAAK,GAAG;YAC5B,OACE,QAAQ,OAAO,GAAG,IAAI;YAGxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,OAAO,GAAG,IAAI;IAEvB;AA8CF;","sources":["packages/@react-stately/grid/src/index.ts","packages/@react-stately/grid/src/useGridState.ts","packages/@react-stately/grid/src/GridCollection.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\nexport {useGridState} from './useGridState';\nexport {GridCollection} from './GridCollection';\n\nexport type {GridStateOptions, GridState} from './useGridState';\n","import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {Key, useEffect, useMemo, useRef} from 'react';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\n\nexport interface GridState<T, C extends GridCollection<T>> {\n collection: C,\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean\n}\n\nexport interface GridStateOptions<T, C extends GridCollection<T>> extends MultipleSelectionStateProps {\n collection: C,\n disabledKeys?: Iterable<Key>,\n focusMode?: 'row' | 'cell'\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> {\n let {collection, focusMode} = props;\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key;\n } else {\n key = getFirstItem(children)?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?\n cachedCollection.current.getItem(node.parentKey) :\n node;\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(parentNode.index - diff + 1, 0) :\n parentNode.index\n ),\n rows.length - 1);\n let newRow:GridNode<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes &&\n parentNode !== node &&\n node.index < childNodes.length ?\n childNodes[node.index].key :\n newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n","/*\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 */\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from 'react';\n\n\ninterface GridCollectionOptions<T> {\n columnCount: number,\n items: GridRow<T>[],\n visitNode?: (cell: GridNode<T>) => GridNode<T>\n}\n\nexport class GridCollection<T> implements IGridCollection<T> {\n keyMap: Map<Key, GridNode<T>> = new Map();\n columnCount: number;\n rows: GridNode<T>[];\n\n constructor(opts?: GridCollectionOptions<T>) {\n this.keyMap = new Map();\n this.columnCount = opts?.columnCount;\n this.rows = [];\n\n let visit = (node: GridNode<T>) => {\n // If the node is the same object as the previous node for the same key,\n // we can skip this node and its children. We always visit columns though,\n // because we depend on order to build the columns array.\n let prevNode = this.keyMap.get(node.key);\n if (opts.visitNode) {\n node = opts.visitNode(node);\n }\n\n this.keyMap.set(node.key, node);\n\n let childKeys = new Set();\n let last: GridNode<T>;\n for (let child of node.childNodes) {\n if (child.type === 'cell' && child.parentKey == null) {\n // if child is a cell parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n childKeys.add(child.key);\n\n if (last) {\n last.nextKey = child.key;\n child.prevKey = last.key;\n } else {\n child.prevKey = null;\n }\n\n visit(child);\n last = child;\n }\n\n if (last) {\n last.nextKey = null;\n }\n\n // Remove deleted nodes and their children from the key map\n if (prevNode) {\n for (let child of prevNode.childNodes) {\n if (!childKeys.has(child.key)) {\n remove(child);\n }\n }\n }\n };\n\n let remove = (node: GridNode<T>) => {\n this.keyMap.delete(node.key);\n for (let child of node.childNodes) {\n if (this.keyMap.get(child.key) === child) {\n remove(child);\n }\n }\n };\n\n let last: GridNode<T>;\n opts.items.forEach((node, i) => {\n let rowNode = {\n level: 0,\n key: 'row-' + i,\n type: 'row',\n value: undefined,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: undefined,\n textValue: undefined,\n ...node,\n index: i\n } as GridNode<T>;\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n });\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/grid",
|
|
3
|
-
"version": "3.6.2-nightly.
|
|
3
|
+
"version": "3.6.2-nightly.3960+16f72e9fb",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/collections": "3.0.0-nightly.
|
|
26
|
-
"@react-stately/selection": "3.0.0-nightly.
|
|
27
|
-
"@react-types/grid": "3.1.9-nightly.
|
|
28
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
25
|
+
"@react-stately/collections": "3.0.0-nightly.2258+16f72e9fb",
|
|
26
|
+
"@react-stately/selection": "3.0.0-nightly.2258+16f72e9fb",
|
|
27
|
+
"@react-types/grid": "3.1.9-nightly.3960+16f72e9fb",
|
|
28
|
+
"@react-types/shared": "3.0.0-nightly.2258+16f72e9fb",
|
|
29
29
|
"@swc/helpers": "^0.4.14"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "16f72e9fbfc28adf104c3cb7557f1d3cab617960"
|
|
38
38
|
}
|
package/src/useGridState.ts
CHANGED
|
@@ -73,7 +73,7 @@ export function useGridState<T extends object, C extends GridCollection<T>>(prop
|
|
|
73
73
|
rows.length - 1);
|
|
74
74
|
let newRow:GridNode<T>;
|
|
75
75
|
while (index >= 0) {
|
|
76
|
-
if (!selectionManager.isDisabled(rows[index].key)) {
|
|
76
|
+
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
77
77
|
newRow = rows[index];
|
|
78
78
|
break;
|
|
79
79
|
}
|