@react-stately/grid 3.6.2-nightly.3960 → 3.6.2-nightly.3966

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import {getChildNodes as $cAn5f$getChildNodes, getLastItem as $cAn5f$getLastItem, getFirstItem as $cAn5f$getFirstItem} from "@react-stately/collections";
2
2
  import {useMemo as $cAn5f$useMemo, useRef as $cAn5f$useRef, useEffect as $cAn5f$useEffect} from "react";
3
3
  import {useMultipleSelectionState as $cAn5f$useMultipleSelectionState, SelectionManager as $cAn5f$SelectionManager} from "@react-stately/selection";
4
- import $cAn5f$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
5
4
 
6
5
  /*
7
6
  * Copyright 2020 Adobe. All rights reserved.
@@ -97,10 +96,8 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
97
96
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
98
97
  * OF ANY KIND, either express or implied. See the License for the specific language
99
98
  * governing permissions and limitations under the License.
100
- */
101
- let $16805b1b18093c5f$var$_Symbol_iterator = Symbol.iterator;
102
- class $16805b1b18093c5f$export$de3fdf6493c353d {
103
- *[$16805b1b18093c5f$var$_Symbol_iterator]() {
99
+ */ class $16805b1b18093c5f$export$de3fdf6493c353d {
100
+ *[Symbol.iterator]() {
104
101
  yield* [
105
102
  ...this.rows
106
103
  ];
@@ -148,7 +145,7 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
148
145
  return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
149
146
  }
150
147
  constructor(opts){
151
- (0, $cAn5f$swchelperssrc_define_propertymjs)(this, "keyMap", new Map());
148
+ this.keyMap = new Map();
152
149
  this.keyMap = new Map();
153
150
  this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
154
151
  this.rows = [];
@@ -175,7 +172,7 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
175
172
  if (last) last.nextKey = null;
176
173
  // Remove deleted nodes and their children from the key map
177
174
  if (prevNode) {
178
- for (let child1 of prevNode.childNodes)if (!childKeys.has(child1.key)) remove(child1);
175
+ for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
179
176
  }
180
177
  };
181
178
  let remove = (node)=>{
package/dist/main.js CHANGED
@@ -1,14 +1,10 @@
1
1
  var $82f7L$reactstatelycollections = require("@react-stately/collections");
2
2
  var $82f7L$react = require("react");
3
3
  var $82f7L$reactstatelyselection = require("@react-stately/selection");
4
- var $82f7L$swchelperslib_define_propertyjs = require("@swc/helpers/lib/_define_property.js");
5
4
 
6
5
  function $parcel$export(e, n, v, s) {
7
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
7
  }
9
- function $parcel$interopDefault(a) {
10
- return a && a.__esModule ? a.default : a;
11
- }
12
8
 
13
9
  $parcel$export(module.exports, "useGridState", () => $38009b28e45912ea$export$4007ac09ff9c68ed);
14
10
  $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$de3fdf6493c353d);
@@ -106,10 +102,8 @@ function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
106
102
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
107
103
  * OF ANY KIND, either express or implied. See the License for the specific language
108
104
  * governing permissions and limitations under the License.
109
- */
110
- let $8bb6a9101b052a66$var$_Symbol_iterator = Symbol.iterator;
111
- class $8bb6a9101b052a66$export$de3fdf6493c353d {
112
- *[$8bb6a9101b052a66$var$_Symbol_iterator]() {
105
+ */ class $8bb6a9101b052a66$export$de3fdf6493c353d {
106
+ *[Symbol.iterator]() {
113
107
  yield* [
114
108
  ...this.rows
115
109
  ];
@@ -157,7 +151,7 @@ class $8bb6a9101b052a66$export$de3fdf6493c353d {
157
151
  return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
158
152
  }
159
153
  constructor(opts){
160
- (0, ($parcel$interopDefault($82f7L$swchelperslib_define_propertyjs)))(this, "keyMap", new Map());
154
+ this.keyMap = new Map();
161
155
  this.keyMap = new Map();
162
156
  this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
163
157
  this.rows = [];
@@ -184,7 +178,7 @@ class $8bb6a9101b052a66$export$de3fdf6493c353d {
184
178
  if (last) last.nextKey = null;
185
179
  // Remove deleted nodes and their children from the key map
186
180
  if (prevNode) {
187
- for (let child1 of prevNode.childNodes)if (!childKeys.has(child1.key)) remove(child1);
181
+ for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
188
182
  }
189
183
  };
190
184
  let remove = (node)=>{
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,CAAA,GAAA,oBAAO,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,WAAW,CAAA,GAAA,4CAAY,EAAE,MAAM;gBACnC,IAAI,UAAU,QACZ,MAAM,CAAA,eAAA,CAAA,GAAA,0CAAW,AAAD,EAAE,uBAAZ,0BAAA,KAAA,IAAA,aAAuB,GAAG;qBAEhC,MAAM,CAAA,gB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AC,MAAM,GAAG;gBAEvB,IAAI,MAAM;oBACR,KAAK,OAAO,GAAG,MAAM,GAAG;oBACxB,MAAM,OAAO,GAAG,KAAK,GAAG;gBAC1B,OACE,MAAM,OAAO,GAAG,IAAI;gBAGtB,MAAM;gBACN,OAAO;YACT;YAEA,IAAI,MACF,KAAK,OAAO,GAAG,IAAI;YAGrB,2DAA2D;YAC3D,IAAI,UAAU;gBACZ,KAAK,IAAI,UAAS,SAAS,UAAU,CACnC,IAAI,CAAC,UAAU,GAAG,CAAC,OAAM,GAAG,GAC1B,OAAO;YAGb,CAAC;QACH;QAEA,IAAI,SAAS,CAAC,OAAsB;YAClC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG;YAC3B,KAAK,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"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;;ACwBO,SAAS,0CAA4D,KAA6B;IACvG,IAAI,cAAC,WAAU,aAAE,UAAS,EAAC,GAAG;IAC9B,IAAI,iBAAiB,CAAA,GAAA,sDAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IACvB,MAAM,eAAe,IAAI,IAAI,MAAM,gBAAgB,IAAI,OACvD;QAAC,MAAM;KAAa;IAExB,IAAI,gBAAgB,eAAe;IACnC,eAAe,gBAAgB,CAAC,KAAK;QACnC,2EAA2E;QAC3E,IAAI,cAAc,UAAU,OAAO,MAAM;YACvC,IAAI,OAAO,WAAW,QAAQ;YAC9B,IAAI,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,IAAG,MAAM,QAAQ;oBAGjB,cAEA;gBAJR,IAAI,WAAW,CAA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C,MAAM;YACxB,IAAI,UAAU;gBACZ,OAAO;gBACP,KAAK,SAAS;gBACd,MAAM;gBACN,OAAO;gBACP,eAAe;gBACf,YAAY;uBAAI,KAAK;iBAAW;gBAChC,UAAU;gBACV,WAAW;gBACX,GAAG,IAAI;gBACP,OAAO;YACT;YAEA,IAAI,MAAM;gBACR,KAAK,UAAU,QAAQ;gBACvB,QAAQ,UAAU,KAAK;YACzB,OACE,QAAQ,UAAU;YAGpB,IAAI,CAAC,KAAK,KAAK;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,UAAU;IAEnB;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
@@ -1,7 +1,6 @@
1
1
  import {getChildNodes as $cAn5f$getChildNodes, getLastItem as $cAn5f$getLastItem, getFirstItem as $cAn5f$getFirstItem} from "@react-stately/collections";
2
2
  import {useMemo as $cAn5f$useMemo, useRef as $cAn5f$useRef, useEffect as $cAn5f$useEffect} from "react";
3
3
  import {useMultipleSelectionState as $cAn5f$useMultipleSelectionState, SelectionManager as $cAn5f$SelectionManager} from "@react-stately/selection";
4
- import $cAn5f$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
5
4
 
6
5
  /*
7
6
  * Copyright 2020 Adobe. All rights reserved.
@@ -97,10 +96,8 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
97
96
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
98
97
  * OF ANY KIND, either express or implied. See the License for the specific language
99
98
  * governing permissions and limitations under the License.
100
- */
101
- let $16805b1b18093c5f$var$_Symbol_iterator = Symbol.iterator;
102
- class $16805b1b18093c5f$export$de3fdf6493c353d {
103
- *[$16805b1b18093c5f$var$_Symbol_iterator]() {
99
+ */ class $16805b1b18093c5f$export$de3fdf6493c353d {
100
+ *[Symbol.iterator]() {
104
101
  yield* [
105
102
  ...this.rows
106
103
  ];
@@ -148,7 +145,7 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
148
145
  return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
149
146
  }
150
147
  constructor(opts){
151
- (0, $cAn5f$swchelperssrc_define_propertymjs)(this, "keyMap", new Map());
148
+ this.keyMap = new Map();
152
149
  this.keyMap = new Map();
153
150
  this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
154
151
  this.rows = [];
@@ -175,7 +172,7 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
175
172
  if (last) last.nextKey = null;
176
173
  // Remove deleted nodes and their children from the key map
177
174
  if (prevNode) {
178
- for (let child1 of prevNode.childNodes)if (!childKeys.has(child1.key)) remove(child1);
175
+ for (let child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,IAAI,SAAS,CAAC,OAAsB;YAClC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG;YAC3B,KAAK,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":"module.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;;;;ACwBO,SAAS,0CAA4D,KAA6B;IACvG,IAAI,cAAC,WAAU,aAAE,UAAS,EAAC,GAAG;IAC9B,IAAI,iBAAiB,CAAA,GAAA,gCAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IACvB,MAAM,eAAe,IAAI,IAAI,MAAM,gBAAgB,IAAI,OACvD;QAAC,MAAM;KAAa;IAExB,IAAI,gBAAgB,eAAe;IACnC,eAAe,gBAAgB,CAAC,KAAK;QACnC,2EAA2E;QAC3E,IAAI,cAAc,UAAU,OAAO,MAAM;YACvC,IAAI,OAAO,WAAW,QAAQ;YAC9B,IAAI,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,IAAG,MAAM,QAAQ;oBAGjB,cAEA;gBAJR,IAAI,WAAW,CAAA,GAAA,oBAAY,EAAE,MAAM;gBACnC,IAAI,UAAU,QACZ,MAAM,CAAA,eAAA,CAAA,GAAA,kBAAU,EAAE,uBAAZ,0BAAA,KAAA,IAAA,aAAuB;qBAE7B,MAAM,CAAA,gBAAA,CAAA,GAAA,mBAAW,EAAE,uBAAb,2BAAA,KAAA,IAAA,cAAwB;YAElC;QACF;QAEA,cAAc,KAAK;IACrB;IAEA,IAAI,mBAAmB,CAAA,GAAA,cAAM,EAAE,IAC7B,IAAI,CAAA,GAAA,uBAAe,EAAE,YAAY,iBAC/B;QAAC;QAAY;KAAe;IAGhC,iEAAiE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ources":["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.3960+16f72e9fb",
3
+ "version": "3.6.2-nightly.3966+a30e1bf81",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,11 +22,11 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
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
- "@swc/helpers": "^0.4.14"
25
+ "@react-stately/collections": "3.0.0-nightly.2264+a30e1bf81",
26
+ "@react-stately/selection": "3.0.0-nightly.2264+a30e1bf81",
27
+ "@react-types/grid": "3.1.9-nightly.3966+a30e1bf81",
28
+ "@react-types/shared": "3.0.0-nightly.2264+a30e1bf81",
29
+ "@swc/helpers": "^0.5.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "16f72e9fbfc28adf104c3cb7557f1d3cab617960"
37
+ "gitHead": "a30e1bf810e03f4a4457c788c1a1315423567e96"
38
38
  }