@react-stately/grid 3.4.2-nightly.3598 → 3.4.2-nightly.3600

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/main.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var $82f7L$react = require("react");
2
2
  var $82f7L$reactstatelyselection = require("@react-stately/selection");
3
+ require("@swc/helpers/lib/_define_property.js");
3
4
 
4
5
  function $parcel$export(e, n, v, s) {
5
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
@@ -7,33 +8,42 @@ function $parcel$export(e, n, v, s) {
7
8
 
8
9
  $parcel$export(module.exports, "useGridState", () => $38009b28e45912ea$export$4007ac09ff9c68ed);
9
10
  $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$de3fdf6493c353d);
10
-
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
11
22
 
12
23
  function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
13
24
  let { collection: collection , focusMode: focusMode } = props;
14
- let selectionState = $82f7L$reactstatelyselection.useMultipleSelectionState(props);
15
- let disabledKeys = $82f7L$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
16
- , [
25
+ let selectionState = (0, $82f7L$reactstatelyselection.useMultipleSelectionState)(props);
26
+ let disabledKeys = (0, $82f7L$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
17
27
  props.disabledKeys
18
28
  ]);
19
29
  let setFocusedKey = selectionState.setFocusedKey;
20
30
  selectionState.setFocusedKey = (key, child)=>{
21
31
  // If focusMode is cell and an item is focused, focus a child cell instead.
22
- if (focusMode === 'cell' && key != null) {
32
+ if (focusMode === "cell" && key != null) {
23
33
  let item = collection.getItem(key);
24
- if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
34
+ if ((item === null || item === void 0 ? void 0 : item.type) === "item") {
25
35
  var ref, ref1;
26
36
  let children = [
27
37
  ...item.childNodes
28
38
  ];
29
- if (child === 'last') key = (ref = children[children.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
39
+ if (child === "last") key = (ref = children[children.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
30
40
  else key = (ref1 = children[0]) === null || ref1 === void 0 ? void 0 : ref1.key;
31
41
  }
32
42
  }
33
43
  setFocusedKey(key, child);
34
44
  };
35
45
  // Reset focused key if that item is deleted from the collection.
36
- $82f7L$react.useEffect(()=>{
46
+ (0, $82f7L$react.useEffect)(()=>{
37
47
  if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
38
48
  }, [
39
49
  collection,
@@ -43,14 +53,25 @@ function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
43
53
  collection: collection,
44
54
  disabledKeys: disabledKeys,
45
55
  isKeyboardNavigationDisabled: false,
46
- selectionManager: new $82f7L$reactstatelyselection.SelectionManager(collection, selectionState)
56
+ selectionManager: new (0, $82f7L$reactstatelyselection.SelectionManager)(collection, selectionState)
47
57
  };
48
58
  }
49
59
 
50
60
 
51
- var tmp = Symbol.iterator;
61
+ /*
62
+ * Copyright 2020 Adobe. All rights reserved.
63
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
64
+ * you may not use this file except in compliance with the License. You may obtain a copy
65
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
66
+ *
67
+ * Unless required by applicable law or agreed to in writing, software distributed under
68
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
69
+ * OF ANY KIND, either express or implied. See the License for the specific language
70
+ * governing permissions and limitations under the License.
71
+ */
72
+ let $8bb6a9101b052a66$var$_iterator = Symbol.iterator;
52
73
  class $8bb6a9101b052a66$export$de3fdf6493c353d {
53
- *[tmp]() {
74
+ *[$8bb6a9101b052a66$var$_iterator]() {
54
75
  yield* [
55
76
  ...this.rows
56
77
  ];
@@ -94,7 +115,7 @@ class $8bb6a9101b052a66$export$de3fdf6493c353d {
94
115
  return this.getItem(keys[idx]);
95
116
  }
96
117
  constructor(opts){
97
- this.keyMap = new Map();
118
+ (0, $8bb6a9101b052a66$import$d76420afe0f7f8c4$2e2bcd8739ae039)(this, "keyMap", new Map());
98
119
  this.keyMap = new Map();
99
120
  this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
100
121
  this.rows = [];
@@ -108,7 +129,7 @@ class $8bb6a9101b052a66$export$de3fdf6493c353d {
108
129
  let childKeys = new Set();
109
130
  let last;
110
131
  for (let child of node.childNodes){
111
- if (child.type === 'cell' && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
132
+ if (child.type === "cell" && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
112
133
  child.parentKey = node.key;
113
134
  childKeys.add(child.key);
114
135
  if (last) {
@@ -121,19 +142,19 @@ class $8bb6a9101b052a66$export$de3fdf6493c353d {
121
142
  if (last) last.nextKey = null;
122
143
  // Remove deleted nodes and their children from the key map
123
144
  if (prevNode) {
124
- for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
145
+ for (let child1 of prevNode.childNodes)if (!childKeys.has(child1.key)) remove(child1);
125
146
  }
126
147
  };
127
148
  let remove = (node)=>{
128
149
  this.keyMap.delete(node.key);
129
150
  for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
130
151
  };
131
- let last1;
152
+ let last;
132
153
  opts.items.forEach((node, i)=>{
133
154
  let rowNode = {
134
155
  level: 0,
135
- key: 'row-' + i,
136
- type: 'row',
156
+ key: "row-" + i,
157
+ type: "row",
137
158
  value: undefined,
138
159
  hasChildNodes: true,
139
160
  childNodes: [
@@ -144,15 +165,15 @@ class $8bb6a9101b052a66$export$de3fdf6493c353d {
144
165
  ...node,
145
166
  index: i
146
167
  };
147
- if (last1) {
148
- last1.nextKey = rowNode.key;
149
- rowNode.prevKey = last1.key;
168
+ if (last) {
169
+ last.nextKey = rowNode.key;
170
+ rowNode.prevKey = last.key;
150
171
  } else rowNode.prevKey = null;
151
172
  this.rows.push(rowNode);
152
173
  visit(rowNode);
153
- last1 = rowNode;
174
+ last = rowNode;
154
175
  });
155
- if (last1) last1.nextKey = null;
176
+ if (last) last.nextKey = null;
156
177
  }
157
178
  }
158
179
 
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;SCuBgB,yCAAY,CAAgD,KAA6B,EAAmB,CAAC;IAC3H,GAAG,CAAC,CAAC,aAAA,UAAU,cAAE,SAAS,EAAA,CAAC,GAAG,KAAK;IACnC,GAAG,CAAC,cAAc,GAAG,sDAAyB,CAAC,KAAK;IACpD,GAAG,CAAC,YAAY,GAAG,oBAAO,KACtB,KAAK,CAAC,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,GAAG,CAAC,GAAG;MAC1D,CAAC;QAAA,KAAK,CAAC,YAAY;IAAA,CAAC;IAExB,GAAG,CAAC,aAAa,GAAG,cAAc,CAAC,aAAa;IAChD,cAAc,CAAC,aAAa,IAAI,GAAG,EAAE,KAAK,GAAK,CAAC;QAC9C,EAA2E,AAA3E,yEAA2E;QAC3E,EAAE,EAAE,SAAS,KAAK,CAAM,SAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACxC,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG;YACjC,EAAE,GAAE,IAAI,aAAJ,IAAI,KAAJ,IAAI,CAAJ,CAAU,GAAV,IAAI,CAAJ,CAAU,GAAV,IAAI,CAAE,IAAI,MAAK,CA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,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO;YACtB,KAAK,CAAC,OAAO;YAEb,KAAI,GAAG,OAAO;QAChB,CAAC;QAED,EAAE,EAAE,KAAI,EACN,KAAI,CAAC,OAAO,GAAG,IAAI;IAEvB,CAAC;;;","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 {GridCollection} from '@react-types/grid';\nimport {Key, useEffect, useMemo} 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 = [...item.childNodes];\n if (child === 'last') {\n key = children[children.length - 1]?.key;\n } else {\n key = children[0]?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager: new SelectionManager(collection, selectionState)\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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ACZ,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;AAyCF;","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 {GridCollection} from '@react-types/grid';\nimport {Key, useEffect, useMemo} 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 = [...item.childNodes];\n if (child === 'last') {\n key = children[children.length - 1]?.key;\n } else {\n key = children[0]?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager: new SelectionManager(collection, selectionState)\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"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.mjs CHANGED
@@ -1,33 +1,43 @@
1
1
  import {useMemo as $cAn5f$useMemo, useEffect as $cAn5f$useEffect} from "react";
2
2
  import {useMultipleSelectionState as $cAn5f$useMultipleSelectionState, SelectionManager as $cAn5f$SelectionManager} from "@react-stately/selection";
3
+ import $cAn5f$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
3
4
 
4
-
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
5
16
 
6
17
  function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
7
18
  let { collection: collection , focusMode: focusMode } = props;
8
- let selectionState = $cAn5f$useMultipleSelectionState(props);
9
- let disabledKeys = $cAn5f$useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
10
- , [
19
+ let selectionState = (0, $cAn5f$useMultipleSelectionState)(props);
20
+ let disabledKeys = (0, $cAn5f$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
11
21
  props.disabledKeys
12
22
  ]);
13
23
  let setFocusedKey = selectionState.setFocusedKey;
14
24
  selectionState.setFocusedKey = (key, child)=>{
15
25
  // If focusMode is cell and an item is focused, focus a child cell instead.
16
- if (focusMode === 'cell' && key != null) {
26
+ if (focusMode === "cell" && key != null) {
17
27
  let item = collection.getItem(key);
18
- if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
28
+ if ((item === null || item === void 0 ? void 0 : item.type) === "item") {
19
29
  var ref, ref1;
20
30
  let children = [
21
31
  ...item.childNodes
22
32
  ];
23
- if (child === 'last') key = (ref = children[children.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
33
+ if (child === "last") key = (ref = children[children.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
24
34
  else key = (ref1 = children[0]) === null || ref1 === void 0 ? void 0 : ref1.key;
25
35
  }
26
36
  }
27
37
  setFocusedKey(key, child);
28
38
  };
29
39
  // Reset focused key if that item is deleted from the collection.
30
- $cAn5f$useEffect(()=>{
40
+ (0, $cAn5f$useEffect)(()=>{
31
41
  if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
32
42
  }, [
33
43
  collection,
@@ -37,14 +47,25 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
37
47
  collection: collection,
38
48
  disabledKeys: disabledKeys,
39
49
  isKeyboardNavigationDisabled: false,
40
- selectionManager: new $cAn5f$SelectionManager(collection, selectionState)
50
+ selectionManager: new (0, $cAn5f$SelectionManager)(collection, selectionState)
41
51
  };
42
52
  }
43
53
 
44
54
 
45
- var tmp = Symbol.iterator;
55
+ /*
56
+ * Copyright 2020 Adobe. All rights reserved.
57
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
58
+ * you may not use this file except in compliance with the License. You may obtain a copy
59
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
60
+ *
61
+ * Unless required by applicable law or agreed to in writing, software distributed under
62
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
63
+ * OF ANY KIND, either express or implied. See the License for the specific language
64
+ * governing permissions and limitations under the License.
65
+ */
66
+ let $16805b1b18093c5f$var$_iterator = Symbol.iterator;
46
67
  class $16805b1b18093c5f$export$de3fdf6493c353d {
47
- *[tmp]() {
68
+ *[$16805b1b18093c5f$var$_iterator]() {
48
69
  yield* [
49
70
  ...this.rows
50
71
  ];
@@ -88,7 +109,7 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
88
109
  return this.getItem(keys[idx]);
89
110
  }
90
111
  constructor(opts){
91
- this.keyMap = new Map();
112
+ (0, $cAn5f$swchelperssrc_define_propertymjs)(this, "keyMap", new Map());
92
113
  this.keyMap = new Map();
93
114
  this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
94
115
  this.rows = [];
@@ -102,7 +123,7 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
102
123
  let childKeys = new Set();
103
124
  let last;
104
125
  for (let child of node.childNodes){
105
- if (child.type === 'cell' && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
126
+ if (child.type === "cell" && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
106
127
  child.parentKey = node.key;
107
128
  childKeys.add(child.key);
108
129
  if (last) {
@@ -115,19 +136,19 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
115
136
  if (last) last.nextKey = null;
116
137
  // Remove deleted nodes and their children from the key map
117
138
  if (prevNode) {
118
- for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
139
+ for (let child1 of prevNode.childNodes)if (!childKeys.has(child1.key)) remove(child1);
119
140
  }
120
141
  };
121
142
  let remove = (node)=>{
122
143
  this.keyMap.delete(node.key);
123
144
  for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
124
145
  };
125
- let last1;
146
+ let last;
126
147
  opts.items.forEach((node, i)=>{
127
148
  let rowNode = {
128
149
  level: 0,
129
- key: 'row-' + i,
130
- type: 'row',
150
+ key: "row-" + i,
151
+ type: "row",
131
152
  value: undefined,
132
153
  hasChildNodes: true,
133
154
  childNodes: [
@@ -138,15 +159,15 @@ class $16805b1b18093c5f$export$de3fdf6493c353d {
138
159
  ...node,
139
160
  index: i
140
161
  };
141
- if (last1) {
142
- last1.nextKey = rowNode.key;
143
- rowNode.prevKey = last1.key;
162
+ if (last) {
163
+ last.nextKey = rowNode.key;
164
+ rowNode.prevKey = last.key;
144
165
  } else rowNode.prevKey = null;
145
166
  this.rows.push(rowNode);
146
167
  visit(rowNode);
147
- last1 = rowNode;
168
+ last = rowNode;
148
169
  });
149
- if (last1) last1.nextKey = null;
170
+ if (last) last.nextKey = null;
150
171
  }
151
172
  }
152
173
 
@@ -1 +1 @@
1
- {"mappings":";;;;;SCuBgB,yCAAY,CAAgD,KAA6B,EAAmB,CAAC;IAC3H,GAAG,CAAC,CAAC,aAAA,UAAU,cAAE,SAAS,EAAA,CAAC,GAAG,KAAK;IACnC,GAAG,CAAC,cAAc,GAAG,gCAAyB,CAAC,KAAK;IACpD,GAAG,CAAC,YAAY,GAAG,cAAO,KACtB,KAAK,CAAC,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,GAAG,CAAC,GAAG;MAC1D,CAAC;QAAA,KAAK,CAAC,YAAY;IAAA,CAAC;IAExB,GAAG,CAAC,aAAa,GAAG,cAAc,CAAC,aAAa;IAChD,cAAc,CAAC,aAAa,IAAI,GAAG,EAAE,KAAK,GAAK,CAAC;QAC9C,EAA2E,AAA3E,yEAA2E;QAC3E,EAAE,EAAE,SAAS,KAAK,CAAM,SAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACxC,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG;YACjC,EAAE,GAAE,IAAI,aAAJ,IAAI,KAAJ,IAAI,CAAJ,CAAU,GAAV,IAAI,CAAJ,CAAU,GAAV,IAAI,CAAE,IAAI,MAAK,CAAM,OAAE,CAAC;oBAG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AAC,IAAI,CAAC,OAAO;YACtB,KAAK,CAAC,OAAO;YAEb,KAAI,GAAG,OAAO;QAChB,CAAC;QAED,EAAE,EAAE,KAAI,EACN,KAAI,CAAC,OAAO,GAAG,IAAI;IAEvB,CAAC;;;","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 {GridCollection} from '@react-types/grid';\nimport {Key, useEffect, useMemo} 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 = [...item.childNodes];\n if (child === 'last') {\n key = children[children.length - 1]?.key;\n } else {\n key = children[0]?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager: new SelectionManager(collection, selectionState)\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)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S;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;AAyCF;","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 {GridCollection} from '@react-types/grid';\nimport {Key, useEffect, useMemo} 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 = [...item.childNodes];\n if (child === 'last') {\n key = children[children.length - 1]?.key;\n } else {\n key = children[0]?.key;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager: new SelectionManager(collection, selectionState)\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"],"names":[],"version":3,"file":"module.mjs.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/grid",
3
- "version": "3.4.2-nightly.3598+810579b67",
3
+ "version": "3.4.2-nightly.3600+bfce84fee",
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
- "@babel/runtime": "^7.6.2",
26
- "@react-stately/selection": "3.0.0-nightly.1898+810579b67",
27
- "@react-types/grid": "3.1.6-nightly.3598+810579b67",
28
- "@react-types/shared": "3.0.0-nightly.1898+810579b67"
25
+ "@react-stately/selection": "3.0.0-nightly.1900+bfce84fee",
26
+ "@react-types/grid": "3.1.6-nightly.3600+bfce84fee",
27
+ "@react-types/shared": "3.0.0-nightly.1900+bfce84fee",
28
+ "@swc/helpers": "^0.4.14"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
@@ -33,5 +33,5 @@
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "810579b671791f1593108f62cdc1893de3a220e3"
36
+ "gitHead": "bfce84fee12a027d9cbc38b43e1747e3e4b4b169"
37
37
  }