@react-stately/grid 3.1.1 → 3.1.3-nightly.3120

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,5 @@
1
- var $9dDAS$react = require("react");
2
- var $9dDAS$reactstatelyselection = require("@react-stately/selection");
1
+ var $82f7L$react = require("react");
2
+ var $82f7L$reactstatelyselection = require("@react-stately/selection");
3
3
 
4
4
  function $parcel$exportWildcard(dest, source) {
5
5
  Object.keys(source).forEach(function(key) {
@@ -20,15 +20,15 @@ function $parcel$exportWildcard(dest, source) {
20
20
  function $parcel$export(e, n, v, s) {
21
21
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
22
22
  }
23
- var $f006fc0f1baf15bf$exports = {};
23
+ var $38009b28e45912ea$exports = {};
24
24
 
25
- $parcel$export($f006fc0f1baf15bf$exports, "useGridState", () => $f006fc0f1baf15bf$export$4007ac09ff9c68ed);
25
+ $parcel$export($38009b28e45912ea$exports, "useGridState", () => $38009b28e45912ea$export$4007ac09ff9c68ed);
26
26
 
27
27
 
28
- function $f006fc0f1baf15bf$export$4007ac09ff9c68ed(props) {
28
+ function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
29
29
  let { collection: collection , focusMode: focusMode } = props;
30
- let selectionState = $9dDAS$reactstatelyselection.useMultipleSelectionState(props);
31
- let disabledKeys = $9dDAS$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
30
+ let selectionState = $82f7L$reactstatelyselection.useMultipleSelectionState(props);
31
+ let disabledKeys = $82f7L$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
32
32
  , [
33
33
  props.disabledKeys
34
34
  ]);
@@ -37,18 +37,19 @@ function $f006fc0f1baf15bf$export$4007ac09ff9c68ed(props) {
37
37
  // If focusMode is cell and an item is focused, focus a child cell instead.
38
38
  if (focusMode === 'cell' && key != null) {
39
39
  let item = collection.getItem(key);
40
- if (item?.type === 'item') {
40
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
41
+ var ref, ref1;
41
42
  let children = [
42
43
  ...item.childNodes
43
44
  ];
44
- if (child === 'last') key = children[children.length - 1]?.key;
45
- else key = children[0]?.key;
45
+ if (child === 'last') key = (ref = children[children.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
46
+ else key = (ref1 = children[0]) === null || ref1 === void 0 ? void 0 : ref1.key;
46
47
  }
47
48
  }
48
49
  setFocusedKey(key, child);
49
50
  };
50
51
  // Reset focused key if that item is deleted from the collection.
51
- $9dDAS$react.useEffect(()=>{
52
+ $82f7L$react.useEffect(()=>{
52
53
  if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
53
54
  }, [
54
55
  collection,
@@ -57,19 +58,63 @@ function $f006fc0f1baf15bf$export$4007ac09ff9c68ed(props) {
57
58
  return {
58
59
  collection: collection,
59
60
  disabledKeys: disabledKeys,
60
- selectionManager: new $9dDAS$reactstatelyselection.SelectionManager(collection, selectionState)
61
+ selectionManager: new $82f7L$reactstatelyselection.SelectionManager(collection, selectionState)
61
62
  };
62
63
  }
63
64
 
64
65
 
65
- var $cc5af59c8f5add0a$exports = {};
66
+ var $8bb6a9101b052a66$exports = {};
66
67
 
67
- $parcel$export($cc5af59c8f5add0a$exports, "GridCollection", () => $cc5af59c8f5add0a$export$de3fdf6493c353d);
68
- class $cc5af59c8f5add0a$export$de3fdf6493c353d {
68
+ $parcel$export($8bb6a9101b052a66$exports, "GridCollection", () => $8bb6a9101b052a66$export$de3fdf6493c353d);
69
+ var tmp = Symbol.iterator;
70
+ class $8bb6a9101b052a66$export$de3fdf6493c353d {
71
+ *[tmp]() {
72
+ yield* [
73
+ ...this.rows
74
+ ];
75
+ }
76
+ get size() {
77
+ return [
78
+ ...this.rows
79
+ ].length;
80
+ }
81
+ getKeys() {
82
+ return this.keyMap.keys();
83
+ }
84
+ getKeyBefore(key) {
85
+ let node = this.keyMap.get(key);
86
+ return node ? node.prevKey : null;
87
+ }
88
+ getKeyAfter(key) {
89
+ let node = this.keyMap.get(key);
90
+ return node ? node.nextKey : null;
91
+ }
92
+ getFirstKey() {
93
+ var ref;
94
+ return (ref = [
95
+ ...this.rows
96
+ ][0]) === null || ref === void 0 ? void 0 : ref.key;
97
+ }
98
+ getLastKey() {
99
+ var ref;
100
+ let rows = [
101
+ ...this.rows
102
+ ];
103
+ return (ref = rows[rows.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
104
+ }
105
+ getItem(key) {
106
+ return this.keyMap.get(key);
107
+ }
108
+ at(idx) {
109
+ const keys = [
110
+ ...this.getKeys()
111
+ ];
112
+ return this.getItem(keys[idx]);
113
+ }
69
114
  constructor(opts){
70
115
  this.keyMap = new Map();
71
116
  this.keyMap = new Map();
72
- this.columnCount = opts?.columnCount;
117
+ this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
73
118
  this.rows = [];
74
119
  let visit = (node)=>{
75
120
  // If the node is the same object as the previous node for the same key,
@@ -127,52 +172,11 @@ class $cc5af59c8f5add0a$export$de3fdf6493c353d {
127
172
  });
128
173
  if (last1) last1.nextKey = null;
129
174
  }
130
- *[Symbol.iterator]() {
131
- yield* [
132
- ...this.rows
133
- ];
134
- }
135
- get size() {
136
- return [
137
- ...this.rows
138
- ].length;
139
- }
140
- getKeys() {
141
- return this.keyMap.keys();
142
- }
143
- getKeyBefore(key) {
144
- let node = this.keyMap.get(key);
145
- return node ? node.prevKey : null;
146
- }
147
- getKeyAfter(key) {
148
- let node = this.keyMap.get(key);
149
- return node ? node.nextKey : null;
150
- }
151
- getFirstKey() {
152
- return [
153
- ...this.rows
154
- ][0]?.key;
155
- }
156
- getLastKey() {
157
- let rows = [
158
- ...this.rows
159
- ];
160
- return rows[rows.length - 1]?.key;
161
- }
162
- getItem(key) {
163
- return this.keyMap.get(key);
164
- }
165
- at(idx) {
166
- const keys = [
167
- ...this.getKeys()
168
- ];
169
- return this.getItem(keys[idx]);
170
- }
171
175
  }
172
176
 
173
177
 
174
- $parcel$exportWildcard(module.exports, $f006fc0f1baf15bf$exports);
175
- $parcel$exportWildcard(module.exports, $cc5af59c8f5add0a$exports);
178
+ $parcel$exportWildcard(module.exports, $38009b28e45912ea$exports);
179
+ $parcel$exportWildcard(module.exports, $8bb6a9101b052a66$exports);
176
180
 
177
181
 
178
182
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;SCqBgB,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,EAAE,IAAI,EAAE,IAAI,KAAK,CAAM,OAAE,CAAC;gBAC1B,GAAG,CAAC,QAAQ,GAAG,CAAC;uBAAG,IAAI,CAAC,UAAU;gBAAA,CAAC;gBACnC,EAAE,EAAE,KAAK,KAAK,CAAM,OAClB,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG;qBAExC,GAAG,GAAG,QAAQ,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GAAG,IAAI,CAAC,OAAO,GAAG,IAAI;IACnC,CAAC;IAED,WAAW,GAAG,CAAC;QACb,MAAM,CAAC,CAAC;eAAG,IAAI,CAAC,IAAI;QAAA,CAAC,CAAC,CAAC,GAAG,GAAG;IAC/B,CAAC;IAED,UAAU,GAAG,CAAC;QACZ,GAAG,CAAC,IAAI,GAAG,CAAC;eAAG,IAAI,CAAC,IAAI;QAAA,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG;IACnC,CAAC;IAED,OAAO,CAAC,GAAQ,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;IAC5B,CAAC;IAED,EAAE,CAAC,GAAW,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,GAAG,CAAC;eAAG,IAAI,CAAC,OAAO;QAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG;IAC9B,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 * from './useGridState';\nexport * from './GridCollection';\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}\n\ninterface 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.focusedKey]);\n\n return {\n collection,\n disabledKeys,\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"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;SCqBgB,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,CAAM,OAAE,CAAC;oBAGl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AAC,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 * from './useGridState';\nexport * from './GridCollection';\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}\n\ninterface 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.focusedKey]);\n\n return {\n collection,\n disabledKeys,\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.js CHANGED
@@ -1,18 +1,18 @@
1
- import {useMemo as $abCyH$useMemo, useEffect as $abCyH$useEffect} from "react";
2
- import {useMultipleSelectionState as $abCyH$useMultipleSelectionState, SelectionManager as $abCyH$SelectionManager} from "@react-stately/selection";
1
+ import {useMemo as $cAn5f$useMemo, useEffect as $cAn5f$useEffect} from "react";
2
+ import {useMultipleSelectionState as $cAn5f$useMultipleSelectionState, SelectionManager as $cAn5f$SelectionManager} from "@react-stately/selection";
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
- var $05a366206de7039b$exports = {};
7
+ var $62967d126f3aa823$exports = {};
8
8
 
9
- $parcel$export($05a366206de7039b$exports, "useGridState", () => $05a366206de7039b$export$4007ac09ff9c68ed);
9
+ $parcel$export($62967d126f3aa823$exports, "useGridState", () => $62967d126f3aa823$export$4007ac09ff9c68ed);
10
10
 
11
11
 
12
- function $05a366206de7039b$export$4007ac09ff9c68ed(props) {
12
+ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
13
13
  let { collection: collection , focusMode: focusMode } = props;
14
- let selectionState = $abCyH$useMultipleSelectionState(props);
15
- let disabledKeys = $abCyH$useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
14
+ let selectionState = $cAn5f$useMultipleSelectionState(props);
15
+ let disabledKeys = $cAn5f$useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
16
16
  , [
17
17
  props.disabledKeys
18
18
  ]);
@@ -21,18 +21,19 @@ function $05a366206de7039b$export$4007ac09ff9c68ed(props) {
21
21
  // If focusMode is cell and an item is focused, focus a child cell instead.
22
22
  if (focusMode === 'cell' && key != null) {
23
23
  let item = collection.getItem(key);
24
- if (item?.type === 'item') {
24
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
25
+ var ref, ref1;
25
26
  let children = [
26
27
  ...item.childNodes
27
28
  ];
28
- if (child === 'last') key = children[children.length - 1]?.key;
29
- else key = children[0]?.key;
29
+ if (child === 'last') key = (ref = children[children.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
30
+ else key = (ref1 = children[0]) === null || ref1 === void 0 ? void 0 : ref1.key;
30
31
  }
31
32
  }
32
33
  setFocusedKey(key, child);
33
34
  };
34
35
  // Reset focused key if that item is deleted from the collection.
35
- $abCyH$useEffect(()=>{
36
+ $cAn5f$useEffect(()=>{
36
37
  if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
37
38
  }, [
38
39
  collection,
@@ -41,19 +42,63 @@ function $05a366206de7039b$export$4007ac09ff9c68ed(props) {
41
42
  return {
42
43
  collection: collection,
43
44
  disabledKeys: disabledKeys,
44
- selectionManager: new $abCyH$SelectionManager(collection, selectionState)
45
+ selectionManager: new $cAn5f$SelectionManager(collection, selectionState)
45
46
  };
46
47
  }
47
48
 
48
49
 
49
- var $23af2f3582920ab1$exports = {};
50
+ var $16805b1b18093c5f$exports = {};
50
51
 
51
- $parcel$export($23af2f3582920ab1$exports, "GridCollection", () => $23af2f3582920ab1$export$de3fdf6493c353d);
52
- class $23af2f3582920ab1$export$de3fdf6493c353d {
52
+ $parcel$export($16805b1b18093c5f$exports, "GridCollection", () => $16805b1b18093c5f$export$de3fdf6493c353d);
53
+ var tmp = Symbol.iterator;
54
+ class $16805b1b18093c5f$export$de3fdf6493c353d {
55
+ *[tmp]() {
56
+ yield* [
57
+ ...this.rows
58
+ ];
59
+ }
60
+ get size() {
61
+ return [
62
+ ...this.rows
63
+ ].length;
64
+ }
65
+ getKeys() {
66
+ return this.keyMap.keys();
67
+ }
68
+ getKeyBefore(key) {
69
+ let node = this.keyMap.get(key);
70
+ return node ? node.prevKey : null;
71
+ }
72
+ getKeyAfter(key) {
73
+ let node = this.keyMap.get(key);
74
+ return node ? node.nextKey : null;
75
+ }
76
+ getFirstKey() {
77
+ var ref;
78
+ return (ref = [
79
+ ...this.rows
80
+ ][0]) === null || ref === void 0 ? void 0 : ref.key;
81
+ }
82
+ getLastKey() {
83
+ var ref;
84
+ let rows = [
85
+ ...this.rows
86
+ ];
87
+ return (ref = rows[rows.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
88
+ }
89
+ getItem(key) {
90
+ return this.keyMap.get(key);
91
+ }
92
+ at(idx) {
93
+ const keys = [
94
+ ...this.getKeys()
95
+ ];
96
+ return this.getItem(keys[idx]);
97
+ }
53
98
  constructor(opts){
54
99
  this.keyMap = new Map();
55
100
  this.keyMap = new Map();
56
- this.columnCount = opts?.columnCount;
101
+ this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
57
102
  this.rows = [];
58
103
  let visit = (node)=>{
59
104
  // If the node is the same object as the previous node for the same key,
@@ -111,51 +156,10 @@ class $23af2f3582920ab1$export$de3fdf6493c353d {
111
156
  });
112
157
  if (last1) last1.nextKey = null;
113
158
  }
114
- *[Symbol.iterator]() {
115
- yield* [
116
- ...this.rows
117
- ];
118
- }
119
- get size() {
120
- return [
121
- ...this.rows
122
- ].length;
123
- }
124
- getKeys() {
125
- return this.keyMap.keys();
126
- }
127
- getKeyBefore(key) {
128
- let node = this.keyMap.get(key);
129
- return node ? node.prevKey : null;
130
- }
131
- getKeyAfter(key) {
132
- let node = this.keyMap.get(key);
133
- return node ? node.nextKey : null;
134
- }
135
- getFirstKey() {
136
- return [
137
- ...this.rows
138
- ][0]?.key;
139
- }
140
- getLastKey() {
141
- let rows = [
142
- ...this.rows
143
- ];
144
- return rows[rows.length - 1]?.key;
145
- }
146
- getItem(key) {
147
- return this.keyMap.get(key);
148
- }
149
- at(idx) {
150
- const keys = [
151
- ...this.getKeys()
152
- ];
153
- return this.getItem(keys[idx]);
154
- }
155
159
  }
156
160
 
157
161
 
158
162
 
159
163
 
160
- export {$05a366206de7039b$export$4007ac09ff9c68ed as useGridState, $23af2f3582920ab1$export$de3fdf6493c353d as GridCollection};
164
+ export {$62967d126f3aa823$export$4007ac09ff9c68ed as useGridState, $16805b1b18093c5f$export$de3fdf6493c353d as GridCollection};
161
165
  //# sourceMappingURL=module.js.map
@@ -1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C,MAAM,GAAG,CAAC,GAAG,GAAG;IACnC,CAAC;IAED,OAAO,CAAC,GAAQ,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;IAC5B,CAAC;IAED,EAAE,CAAC,GAAW,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,GAAG,CAAC;eAAG,IAAI,CAAC,OAAO;QAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG;IAC9B,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 * from './useGridState';\nexport * from './GridCollection';\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}\n\ninterface 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.focusedKey]);\n\n return {\n collection,\n disabledKeys,\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.js.map"}
1
+ {"mappings":";;;;;;;;;;;SCqBgB,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;oBAGlB,GAA6B,EAE7B,IAAW;gBAJnB,GAAG,CAAC,QAAQ,GAAG,CAAC;uBAAG,IAAI,CAAC,UAAU;gBAAA,CAAC;gBACnC,EAAE,EAAE,KAAK,KAAK,CAAM,OAClB,GAAG,IAAG,GAA6B,GAA7B,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,eAA5B,GAA6B,KAA7B,IAAI,CAAJ,CAAkC,GAAlC,IAAI,CAAJ,CAAkC,GAAlC,GAA6B,CAAE,GAAG;qBAExC,GAA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AiB,GAAK,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;YAC3B,GAAG,EAAE,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,CAC/B,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,KAAK,EACtC,MAAM,CAAC,KAAK;QAGlB,CAAC;QAED,GAAG,CAAC,KAAI;QACR,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,GAAK,CAAC;YAC/B,GAAG,CAAC,OAAO,GAAG,CAAC;gBACb,KAAK,EAAE,CAAC;gBACR,GAAG,EAAE,CAAM,QAAG,CAAC;gBACf,IAAI,EAAE,CAAK;gBACX,KAAK,EAAE,SAAS;gBAChB,aAAa,EAAE,IAAI;gBACnB,UAAU,EAAE,CAAC;uBAAG,IAAI,CAAC,UAAU;gBAAA,CAAC;gBAChC,QAAQ,EAAE,SAAS;gBACnB,SAAS,EAAE,SAAS;mBACjB,IAAI;gBACP,KAAK,EAAE,CAAC;YACV,CAAC;YAED,EAAE,EAAE,KAAI,EAAE,CAAC;gBACT,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG;gBAC1B,OAAO,CAAC,OAAO,GAAG,KAAI,CAAC,GAAG;YAC5B,CAAC,MACC,OAAO,CAAC,OAAO,GAAG,IAAI;YAGxB,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 * from './useGridState';\nexport * from './GridCollection';\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}\n\ninterface 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.focusedKey]);\n\n return {\n collection,\n disabledKeys,\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.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/grid",
3
- "version": "3.1.1",
3
+ "version": "3.1.3-nightly.3120+1aa66e6e7",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-stately/selection": "^3.9.1",
22
- "@react-types/grid": "^3.0.1",
23
- "@react-types/shared": "^3.11.0"
21
+ "@react-stately/selection": "3.0.0-nightly.1424+1aa66e6e7",
22
+ "@react-types/grid": "3.0.3-nightly.3120+1aa66e6e7",
23
+ "@react-types/shared": "3.0.0-nightly.1424+1aa66e6e7"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -28,5 +28,5 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "54c2366c4f31bd4bf619126131cd583c12972acc"
31
+ "gitHead": "1aa66e6e75e2da014f44177686c3332cd625fb9f"
32
32
  }