@react-stately/grid 3.1.1-nightly.3036 → 3.1.1-nightly.3047
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 +162 -209
- package/dist/main.js.map +1 -1
- package/dist/module.js +148 -196
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/main.js
CHANGED
|
@@ -1,225 +1,178 @@
|
|
|
1
|
-
var
|
|
1
|
+
var $3Qct6$react = require("react");
|
|
2
|
+
var $3Qct6$reactstatelyselection = require("@react-stately/selection");
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var {
|
|
9
|
-
useEffect,
|
|
10
|
-
useMemo
|
|
11
|
-
} = require("react");
|
|
12
|
-
|
|
13
|
-
function $parcel$interopDefault(a) {
|
|
14
|
-
return a && a.__esModule ? a.default : a;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.
|
|
19
|
-
*/
|
|
20
|
-
function useGridState(props) {
|
|
21
|
-
let {
|
|
22
|
-
collection,
|
|
23
|
-
focusMode
|
|
24
|
-
} = props;
|
|
25
|
-
let selectionState = useMultipleSelectionState(props);
|
|
26
|
-
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
|
|
27
|
-
let setFocusedKey = selectionState.setFocusedKey;
|
|
28
|
-
|
|
29
|
-
selectionState.setFocusedKey = (key, child) => {
|
|
30
|
-
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
31
|
-
if (focusMode === 'cell' && key != null) {
|
|
32
|
-
let item = collection.getItem(key);
|
|
33
|
-
|
|
34
|
-
if ((item == null ? void 0 : item.type) === 'item') {
|
|
35
|
-
let children = [...item.childNodes];
|
|
36
|
-
|
|
37
|
-
if (child === 'last') {
|
|
38
|
-
var _children;
|
|
39
|
-
|
|
40
|
-
key = (_children = children[children.length - 1]) == null ? void 0 : _children.key;
|
|
41
|
-
} else {
|
|
42
|
-
var _children$;
|
|
43
|
-
|
|
44
|
-
key = (_children$ = children[0]) == null ? void 0 : _children$.key;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setFocusedKey(key, child);
|
|
50
|
-
}; // Reset focused key if that item is deleted from the collection.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
|
|
55
|
-
selectionState.setFocusedKey(null);
|
|
4
|
+
function $parcel$exportWildcard(dest, source) {
|
|
5
|
+
Object.keys(source).forEach(function(key) {
|
|
6
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
7
|
+
return;
|
|
56
8
|
}
|
|
57
|
-
}, [collection, selectionState.focusedKey]);
|
|
58
|
-
return {
|
|
59
|
-
collection,
|
|
60
|
-
disabledKeys,
|
|
61
|
-
selectionManager: new SelectionManager(collection, selectionState)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
9
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/*
|
|
70
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
71
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
72
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
73
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
74
|
-
*
|
|
75
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
76
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
77
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
78
|
-
* governing permissions and limitations under the License.
|
|
79
|
-
*/
|
|
80
|
-
class GridCollection {
|
|
81
|
-
constructor(opts) {
|
|
82
|
-
this.keyMap = new Map();
|
|
83
|
-
this.columnCount = void 0;
|
|
84
|
-
this.rows = void 0;
|
|
85
|
-
this.keyMap = new Map();
|
|
86
|
-
this.columnCount = opts == null ? void 0 : opts.columnCount;
|
|
87
|
-
this.rows = [];
|
|
88
|
-
|
|
89
|
-
let visit = node => {
|
|
90
|
-
// If the node is the same object as the previous node for the same key,
|
|
91
|
-
// we can skip this node and its children. We always visit columns though,
|
|
92
|
-
// because we depend on order to build the columns array.
|
|
93
|
-
let prevNode = this.keyMap.get(node.key);
|
|
94
|
-
|
|
95
|
-
if (opts.visitNode) {
|
|
96
|
-
node = opts.visitNode(node);
|
|
10
|
+
Object.defineProperty(dest, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return source[key];
|
|
97
14
|
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
98
17
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
for (let child of prevNode.childNodes) {
|
|
129
|
-
if (!childKeys.has(child.key)) {
|
|
130
|
-
remove(child);
|
|
131
|
-
}
|
|
18
|
+
return dest;
|
|
19
|
+
}
|
|
20
|
+
function $parcel$export(e, n, v, s) {
|
|
21
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
22
|
+
}
|
|
23
|
+
var $805edb38a3079ec2$exports = {};
|
|
24
|
+
|
|
25
|
+
$parcel$export($805edb38a3079ec2$exports, "useGridState", () => $805edb38a3079ec2$export$4007ac09ff9c68ed);
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function $805edb38a3079ec2$export$4007ac09ff9c68ed(props) {
|
|
29
|
+
let { collection: collection , focusMode: focusMode } = props;
|
|
30
|
+
let selectionState = $3Qct6$reactstatelyselection.useMultipleSelectionState(props);
|
|
31
|
+
let disabledKeys = $3Qct6$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
|
|
32
|
+
, [
|
|
33
|
+
props.disabledKeys
|
|
34
|
+
]);
|
|
35
|
+
let setFocusedKey = selectionState.setFocusedKey;
|
|
36
|
+
selectionState.setFocusedKey = (key, child)=>{
|
|
37
|
+
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
38
|
+
if (focusMode === 'cell' && key != null) {
|
|
39
|
+
let item = collection.getItem(key);
|
|
40
|
+
if (item?.type === 'item') {
|
|
41
|
+
let children = [
|
|
42
|
+
...item.childNodes
|
|
43
|
+
];
|
|
44
|
+
if (child === 'last') key = children[children.length - 1]?.key;
|
|
45
|
+
else key = children[0]?.key;
|
|
46
|
+
}
|
|
132
47
|
}
|
|
133
|
-
|
|
48
|
+
setFocusedKey(key, child);
|
|
134
49
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
50
|
+
// Reset focused key if that item is deleted from the collection.
|
|
51
|
+
$3Qct6$react.useEffect(()=>{
|
|
52
|
+
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
53
|
+
}, [
|
|
54
|
+
collection,
|
|
55
|
+
selectionState.focusedKey
|
|
56
|
+
]);
|
|
57
|
+
return {
|
|
58
|
+
collection: collection,
|
|
59
|
+
disabledKeys: disabledKeys,
|
|
60
|
+
selectionManager: new $3Qct6$reactstatelyselection.SelectionManager(collection, selectionState)
|
|
144
61
|
};
|
|
62
|
+
}
|
|
145
63
|
|
|
146
|
-
let last;
|
|
147
|
-
opts.items.forEach((node, i) => {
|
|
148
|
-
let rowNode = _babelRuntimeHelpersExtends({
|
|
149
|
-
level: 0,
|
|
150
|
-
key: 'row-' + i,
|
|
151
|
-
type: 'row',
|
|
152
|
-
value: undefined,
|
|
153
|
-
hasChildNodes: true,
|
|
154
|
-
childNodes: [...node.childNodes],
|
|
155
|
-
rendered: undefined,
|
|
156
|
-
textValue: undefined
|
|
157
|
-
}, node, {
|
|
158
|
-
index: i
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
if (last) {
|
|
162
|
-
last.nextKey = rowNode.key;
|
|
163
|
-
rowNode.prevKey = last.key;
|
|
164
|
-
} else {
|
|
165
|
-
rowNode.prevKey = null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.rows.push(rowNode);
|
|
169
|
-
visit(rowNode);
|
|
170
|
-
last = rowNode;
|
|
171
|
-
});
|
|
172
64
|
|
|
173
|
-
|
|
174
|
-
|
|
65
|
+
var $ca89265eb29da87b$exports = {};
|
|
66
|
+
|
|
67
|
+
$parcel$export($ca89265eb29da87b$exports, "GridCollection", () => $ca89265eb29da87b$export$de3fdf6493c353d);
|
|
68
|
+
class $ca89265eb29da87b$export$de3fdf6493c353d {
|
|
69
|
+
constructor(opts){
|
|
70
|
+
this.keyMap = new Map();
|
|
71
|
+
this.keyMap = new Map();
|
|
72
|
+
this.columnCount = opts?.columnCount;
|
|
73
|
+
this.rows = [];
|
|
74
|
+
let visit = (node)=>{
|
|
75
|
+
// If the node is the same object as the previous node for the same key,
|
|
76
|
+
// we can skip this node and its children. We always visit columns though,
|
|
77
|
+
// because we depend on order to build the columns array.
|
|
78
|
+
let prevNode = this.keyMap.get(node.key);
|
|
79
|
+
if (opts.visitNode) node = opts.visitNode(node);
|
|
80
|
+
this.keyMap.set(node.key, node);
|
|
81
|
+
let childKeys = new Set();
|
|
82
|
+
let last;
|
|
83
|
+
for (let child of node.childNodes){
|
|
84
|
+
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
|
|
85
|
+
child.parentKey = node.key;
|
|
86
|
+
childKeys.add(child.key);
|
|
87
|
+
if (last) {
|
|
88
|
+
last.nextKey = child.key;
|
|
89
|
+
child.prevKey = last.key;
|
|
90
|
+
} else child.prevKey = null;
|
|
91
|
+
visit(child);
|
|
92
|
+
last = child;
|
|
93
|
+
}
|
|
94
|
+
if (last) last.nextKey = null;
|
|
95
|
+
// Remove deleted nodes and their children from the key map
|
|
96
|
+
if (prevNode) {
|
|
97
|
+
for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
let remove = (node)=>{
|
|
101
|
+
this.keyMap.delete(node.key);
|
|
102
|
+
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
103
|
+
};
|
|
104
|
+
let last1;
|
|
105
|
+
opts.items.forEach((node, i)=>{
|
|
106
|
+
let rowNode = {
|
|
107
|
+
level: 0,
|
|
108
|
+
key: 'row-' + i,
|
|
109
|
+
type: 'row',
|
|
110
|
+
value: undefined,
|
|
111
|
+
hasChildNodes: true,
|
|
112
|
+
childNodes: [
|
|
113
|
+
...node.childNodes
|
|
114
|
+
],
|
|
115
|
+
rendered: undefined,
|
|
116
|
+
textValue: undefined,
|
|
117
|
+
...node,
|
|
118
|
+
index: i
|
|
119
|
+
};
|
|
120
|
+
if (last1) {
|
|
121
|
+
last1.nextKey = rowNode.key;
|
|
122
|
+
rowNode.prevKey = last1.key;
|
|
123
|
+
} else rowNode.prevKey = null;
|
|
124
|
+
this.rows.push(rowNode);
|
|
125
|
+
visit(rowNode);
|
|
126
|
+
last1 = rowNode;
|
|
127
|
+
});
|
|
128
|
+
if (last1) last1.nextKey = null;
|
|
175
129
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
+
}
|
|
212
172
|
|
|
213
|
-
getItem(key) {
|
|
214
|
-
return this.keyMap.get(key);
|
|
215
|
-
}
|
|
216
173
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return this.getItem(keys[idx]);
|
|
220
|
-
}
|
|
174
|
+
$parcel$exportWildcard(module.exports, $805edb38a3079ec2$exports);
|
|
175
|
+
$parcel$exportWildcard(module.exports, $ca89265eb29da87b$exports);
|
|
221
176
|
|
|
222
|
-
}
|
|
223
177
|
|
|
224
|
-
exports.GridCollection = GridCollection;
|
|
225
178
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;ACgBD;;;AAGO,SAASG,YAAT,CAAqEC,KAArE,EAAqH;AAC1H,MAAI;AAACC,IAAAA,UAAD;AAAaC,IAAAA;AAAb,MAA0BF,KAA9B;AACA,MAAIG,cAAc,GAAGC,yBAAyB,CAACJ,KAAD,CAA9C;AACA,MAAIK,YAAY,GAAGC,OAAO,CAAC,MACvBN,KAAK,CAACK,YAAN,GAAqB,IAAIE,GAAJ,CAAQP,KAAK,CAACK,YAAd,CAArB,GAAmD,IAAIE,GAAJ,EAD7B,EAEtB,CAACP,KAAK,CAACK,YAAP,CAFsB,CAA1B;AAIA,MAAIG,aAAa,GAAGL,cAAc,CAACK,aAAnC;;AACAL,EAAAA,cAAc,CAACK,aAAf,GAA+B,CAACC,GAAD,EAAMC,KAAN,KAAgB;AAC7C;AACA,QAAIR,SAAS,KAAK,MAAd,IAAwBO,GAAG,IAAI,IAAnC,EAAyC;AACvC,UAAIE,IAAI,GAAGV,UAAU,CAACW,OAAX,CAAmBH,GAAnB,CAAX;;AACA,UAAI,CAAAE,IAAI,QAAJ,YA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AI,CAACM,GAAD,CAAjB,CAAP;AACD;;AAvI0D","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-stately/grid/src/useGridState.ts","./packages/@react-stately/grid/src/GridCollection.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\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":["$parcel$interopDefault","a","__esModule","default","useGridState","props","collection","focusMode","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","setFocusedKey","key","child","item","getItem","type","children","childNodes","length","useEffect","focusedKey","selectionManager","SelectionManager","Symbol","iterator","GridCollection","constructor","opts","keyMap","Map","columnCount","rows","visit","node","prevNode","get","visitNode","set","childKeys","last","parentKey","add","nextKey","prevKey","has","remove","delete","items","forEach","i","rowNode","level","value","undefined","hasChildNodes","rendered","textValue","index","push","size","getKeys","keys","getKeyBefore","getKeyAfter","getFirstKey","getLastKey","at","idx"],"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,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,Q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C,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;QAC9B,MAAM,CAAC,IAAI,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"}
|
package/dist/module.js
CHANGED
|
@@ -1,209 +1,161 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { useEffect, useMemo } from "react";
|
|
1
|
+
import {useMemo as $be5ec$useMemo, useEffect as $be5ec$useEffect} from "react";
|
|
2
|
+
import {useMultipleSelectionState as $be5ec$useMultipleSelectionState, SelectionManager as $be5ec$SelectionManager} from "@react-stately/selection";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export function useGridState(props) {
|
|
9
|
-
let {
|
|
10
|
-
collection,
|
|
11
|
-
focusMode
|
|
12
|
-
} = props;
|
|
13
|
-
let selectionState = useMultipleSelectionState(props);
|
|
14
|
-
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
|
|
15
|
-
let setFocusedKey = selectionState.setFocusedKey;
|
|
16
|
-
|
|
17
|
-
selectionState.setFocusedKey = (key, child) => {
|
|
18
|
-
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
19
|
-
if (focusMode === 'cell' && key != null) {
|
|
20
|
-
let item = collection.getItem(key);
|
|
21
|
-
|
|
22
|
-
if ((item == null ? void 0 : item.type) === 'item') {
|
|
23
|
-
let children = [...item.childNodes];
|
|
24
|
-
|
|
25
|
-
if (child === 'last') {
|
|
26
|
-
var _children;
|
|
27
|
-
|
|
28
|
-
key = (_children = children[children.length - 1]) == null ? void 0 : _children.key;
|
|
29
|
-
} else {
|
|
30
|
-
var _children$;
|
|
31
|
-
|
|
32
|
-
key = (_children$ = children[0]) == null ? void 0 : _children$.key;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
setFocusedKey(key, child);
|
|
38
|
-
}; // Reset focused key if that item is deleted from the collection.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
|
|
43
|
-
selectionState.setFocusedKey(null);
|
|
44
|
-
}
|
|
45
|
-
}, [collection, selectionState.focusedKey]);
|
|
46
|
-
return {
|
|
47
|
-
collection,
|
|
48
|
-
disabledKeys,
|
|
49
|
-
selectionManager: new SelectionManager(collection, selectionState)
|
|
50
|
-
};
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
51
6
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// If the node is the same object as the previous node for the same key,
|
|
77
|
-
// we can skip this node and its children. We always visit columns though,
|
|
78
|
-
// because we depend on order to build the columns array.
|
|
79
|
-
let prevNode = this.keyMap.get(node.key);
|
|
80
|
-
|
|
81
|
-
if (opts.visitNode) {
|
|
82
|
-
node = opts.visitNode(node);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.keyMap.set(node.key, node);
|
|
86
|
-
let childKeys = new Set();
|
|
87
|
-
let last;
|
|
88
|
-
|
|
89
|
-
for (let child of node.childNodes) {
|
|
90
|
-
if (child.type === 'cell' && child.parentKey == null) {
|
|
91
|
-
// if child is a cell parent key isn't already established by the collection, match child node to parent row
|
|
92
|
-
child.parentKey = node.key;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
childKeys.add(child.key);
|
|
96
|
-
|
|
97
|
-
if (last) {
|
|
98
|
-
last.nextKey = child.key;
|
|
99
|
-
child.prevKey = last.key;
|
|
100
|
-
} else {
|
|
101
|
-
child.prevKey = null;
|
|
7
|
+
var $c40bc2996decec31$exports = {};
|
|
8
|
+
|
|
9
|
+
$parcel$export($c40bc2996decec31$exports, "useGridState", () => $c40bc2996decec31$export$4007ac09ff9c68ed);
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
function $c40bc2996decec31$export$4007ac09ff9c68ed(props) {
|
|
13
|
+
let { collection: collection , focusMode: focusMode } = props;
|
|
14
|
+
let selectionState = $be5ec$useMultipleSelectionState(props);
|
|
15
|
+
let disabledKeys = $be5ec$useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
|
|
16
|
+
, [
|
|
17
|
+
props.disabledKeys
|
|
18
|
+
]);
|
|
19
|
+
let setFocusedKey = selectionState.setFocusedKey;
|
|
20
|
+
selectionState.setFocusedKey = (key, child)=>{
|
|
21
|
+
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
22
|
+
if (focusMode === 'cell' && key != null) {
|
|
23
|
+
let item = collection.getItem(key);
|
|
24
|
+
if (item?.type === 'item') {
|
|
25
|
+
let children = [
|
|
26
|
+
...item.childNodes
|
|
27
|
+
];
|
|
28
|
+
if (child === 'last') key = children[children.length - 1]?.key;
|
|
29
|
+
else key = children[0]?.key;
|
|
30
|
+
}
|
|
102
31
|
}
|
|
103
|
-
|
|
104
|
-
visit(child);
|
|
105
|
-
last = child;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (last) {
|
|
109
|
-
last.nextKey = null;
|
|
110
|
-
} // Remove deleted nodes and their children from the key map
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (prevNode) {
|
|
114
|
-
for (let child of prevNode.childNodes) {
|
|
115
|
-
if (!childKeys.has(child.key)) {
|
|
116
|
-
remove(child);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
32
|
+
setFocusedKey(key, child);
|
|
120
33
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
34
|
+
// Reset focused key if that item is deleted from the collection.
|
|
35
|
+
$be5ec$useEffect(()=>{
|
|
36
|
+
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
37
|
+
}, [
|
|
38
|
+
collection,
|
|
39
|
+
selectionState.focusedKey
|
|
40
|
+
]);
|
|
41
|
+
return {
|
|
42
|
+
collection: collection,
|
|
43
|
+
disabledKeys: disabledKeys,
|
|
44
|
+
selectionManager: new $be5ec$SelectionManager(collection, selectionState)
|
|
130
45
|
};
|
|
46
|
+
}
|
|
131
47
|
|
|
132
|
-
let last;
|
|
133
|
-
opts.items.forEach((node, i) => {
|
|
134
|
-
let rowNode = _babelRuntimeHelpersEsmExtends({
|
|
135
|
-
level: 0,
|
|
136
|
-
key: 'row-' + i,
|
|
137
|
-
type: 'row',
|
|
138
|
-
value: undefined,
|
|
139
|
-
hasChildNodes: true,
|
|
140
|
-
childNodes: [...node.childNodes],
|
|
141
|
-
rendered: undefined,
|
|
142
|
-
textValue: undefined
|
|
143
|
-
}, node, {
|
|
144
|
-
index: i
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
if (last) {
|
|
148
|
-
last.nextKey = rowNode.key;
|
|
149
|
-
rowNode.prevKey = last.key;
|
|
150
|
-
} else {
|
|
151
|
-
rowNode.prevKey = null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
this.rows.push(rowNode);
|
|
155
|
-
visit(rowNode);
|
|
156
|
-
last = rowNode;
|
|
157
|
-
});
|
|
158
48
|
|
|
159
|
-
|
|
160
|
-
|
|
49
|
+
var $8c07656437c834f0$exports = {};
|
|
50
|
+
|
|
51
|
+
$parcel$export($8c07656437c834f0$exports, "GridCollection", () => $8c07656437c834f0$export$de3fdf6493c353d);
|
|
52
|
+
class $8c07656437c834f0$export$de3fdf6493c353d {
|
|
53
|
+
constructor(opts){
|
|
54
|
+
this.keyMap = new Map();
|
|
55
|
+
this.keyMap = new Map();
|
|
56
|
+
this.columnCount = opts?.columnCount;
|
|
57
|
+
this.rows = [];
|
|
58
|
+
let visit = (node)=>{
|
|
59
|
+
// If the node is the same object as the previous node for the same key,
|
|
60
|
+
// we can skip this node and its children. We always visit columns though,
|
|
61
|
+
// because we depend on order to build the columns array.
|
|
62
|
+
let prevNode = this.keyMap.get(node.key);
|
|
63
|
+
if (opts.visitNode) node = opts.visitNode(node);
|
|
64
|
+
this.keyMap.set(node.key, node);
|
|
65
|
+
let childKeys = new Set();
|
|
66
|
+
let last;
|
|
67
|
+
for (let child of node.childNodes){
|
|
68
|
+
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
|
|
69
|
+
child.parentKey = node.key;
|
|
70
|
+
childKeys.add(child.key);
|
|
71
|
+
if (last) {
|
|
72
|
+
last.nextKey = child.key;
|
|
73
|
+
child.prevKey = last.key;
|
|
74
|
+
} else child.prevKey = null;
|
|
75
|
+
visit(child);
|
|
76
|
+
last = child;
|
|
77
|
+
}
|
|
78
|
+
if (last) last.nextKey = null;
|
|
79
|
+
// Remove deleted nodes and their children from the key map
|
|
80
|
+
if (prevNode) {
|
|
81
|
+
for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
let remove = (node)=>{
|
|
85
|
+
this.keyMap.delete(node.key);
|
|
86
|
+
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
87
|
+
};
|
|
88
|
+
let last1;
|
|
89
|
+
opts.items.forEach((node, i)=>{
|
|
90
|
+
let rowNode = {
|
|
91
|
+
level: 0,
|
|
92
|
+
key: 'row-' + i,
|
|
93
|
+
type: 'row',
|
|
94
|
+
value: undefined,
|
|
95
|
+
hasChildNodes: true,
|
|
96
|
+
childNodes: [
|
|
97
|
+
...node.childNodes
|
|
98
|
+
],
|
|
99
|
+
rendered: undefined,
|
|
100
|
+
textValue: undefined,
|
|
101
|
+
...node,
|
|
102
|
+
index: i
|
|
103
|
+
};
|
|
104
|
+
if (last1) {
|
|
105
|
+
last1.nextKey = rowNode.key;
|
|
106
|
+
rowNode.prevKey = last1.key;
|
|
107
|
+
} else rowNode.prevKey = null;
|
|
108
|
+
this.rows.push(rowNode);
|
|
109
|
+
visit(rowNode);
|
|
110
|
+
last1 = rowNode;
|
|
111
|
+
});
|
|
112
|
+
if (last1) last1.nextKey = null;
|
|
161
113
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
+
}
|
|
194
156
|
|
|
195
|
-
let rows = [...this.rows];
|
|
196
|
-
return (_rows = rows[rows.length - 1]) == null ? void 0 : _rows.key;
|
|
197
|
-
}
|
|
198
157
|
|
|
199
|
-
getItem(key) {
|
|
200
|
-
return this.keyMap.get(key);
|
|
201
|
-
}
|
|
202
158
|
|
|
203
|
-
at(idx) {
|
|
204
|
-
const keys = [...this.getKeys()];
|
|
205
|
-
return this.getItem(keys[idx]);
|
|
206
|
-
}
|
|
207
159
|
|
|
208
|
-
}
|
|
160
|
+
export {$c40bc2996decec31$export$4007ac09ff9c68ed as useGridState, $8c07656437c834f0$export$de3fdf6493c353d as GridCollection};
|
|
209
161
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
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ACpB,QAAIsB,IAAI,GAAG,KAAKL,MAAL,CAAYO,GAAZ,CAAgBxB,GAAhB,CAAX;AACA,WAAOsB,IAAI,GAAGA,IAAI,CAACS,OAAR,GAAkB,IAA7B;AACD;;AAEDsB,EAAAA,WAAW,GAAG;AAAA;;AACZ,gBAAO,CAAC,GAAG,KAAKjC,IAAT,EAAe,CAAf,CAAP,qBAAO,EAAmBpB,GAA1B;AACD;;AAEDsD,EAAAA,UAAU,GAAG;AAAA;;AACX,QAAIlC,IAAI,GAAG,CAAC,GAAG,KAAKA,IAAT,CAAX;AACA,oBAAOA,IAAI,CAACA,IAAI,CAACb,MAAL,GAAc,CAAf,CAAX,qBAAO,MAAuBP,GAA9B;AACD;;AAEDG,EAAAA,OAAO,CAACH,GAAD,EAAW;AAChB,WAAO,KAAKiB,MAAL,CAAYO,GAAZ,CAAgBxB,GAAhB,CAAP;AACD;;AAEDuD,EAAAA,EAAE,CAACC,GAAD,EAAc;AACd,UAAMN,IAAI,GAAG,CAAC,GAAG,KAAKD,OAAL,EAAJ,CAAb;AACA,WAAO,KAAK9C,OAAL,CAAa+C,IAAI,CAACM,GAAD,CAAjB,CAAP;AACD;;AAvI0D","sources":["./packages/@react-stately/grid/src/useGridState.ts","./packages/@react-stately/grid/src/GridCollection.ts"],"sourcesContent":["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":["useGridState","props","collection","focusMode","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","setFocusedKey","key","child","item","getItem","type","children","childNodes","length","useEffect","focusedKey","selectionManager","SelectionManager","Symbol","iterator","GridCollection","constructor","opts","keyMap","Map","columnCount","rows","visit","node","prevNode","get","visitNode","set","childKeys","last","parentKey","add","nextKey","prevKey","has","remove","delete","items","forEach","i","rowNode","level","value","undefined","hasChildNodes","rendered","textValue","index","push","size","getKeys","keys","getKeyBefore","getKeyAfter","getFirstKey","getLastKey","at","idx"],"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,EAAE,IAAI,EAAE,IAAI,KAAK,CAAM,OAAE,CAAC;gBAC1B,GA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AC9B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI;IACnC,CAAC;IAED,WAAW,CAAC,GAAQ,EAAE,CAAC;QACrB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;QAC9B,MAAM,CAAC,IAAI,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":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -29,11 +29,11 @@ export class GridCollection<T> implements _GridCollection1<T> {
|
|
|
29
29
|
constructor(opts?: GridCollectionOptions<T>);
|
|
30
30
|
[Symbol.iterator](): Generator<GridNode<T>, void, undefined>;
|
|
31
31
|
get size(): number;
|
|
32
|
-
getKeys(): IterableIterator<
|
|
33
|
-
getKeyBefore(key: Key):
|
|
34
|
-
getKeyAfter(key: Key):
|
|
35
|
-
getFirstKey():
|
|
36
|
-
getLastKey():
|
|
32
|
+
getKeys(): IterableIterator<Key>;
|
|
33
|
+
getKeyBefore(key: Key): Key;
|
|
34
|
+
getKeyAfter(key: Key): Key;
|
|
35
|
+
getFirstKey(): Key;
|
|
36
|
+
getLastKey(): Key;
|
|
37
37
|
getItem(key: Key): GridNode<T>;
|
|
38
38
|
at(idx: number): GridNode<T>;
|
|
39
39
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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pB,WAAW;IAIX,UAAU;IAKV,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;CAIf","sources":["packages/@react-stately/grid/src/packages/@react-stately/grid/src/useGridState.ts","packages/@react-stately/grid/src/packages/@react-stately/grid/src/GridCollection.ts","packages/@react-stately/grid/src/packages/@react-stately/grid/src/index.ts","packages/@react-stately/grid/src/index.ts"],"sourcesContent":[null,null,null,"/*\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"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/grid",
|
|
3
|
-
"version": "3.1.1-nightly.
|
|
3
|
+
"version": "3.1.1-nightly.3047+87960ad25",
|
|
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.0.0-nightly.
|
|
22
|
-
"@react-types/grid": "3.0.1-nightly.
|
|
23
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
21
|
+
"@react-stately/selection": "3.0.0-nightly.1356+87960ad25",
|
|
22
|
+
"@react-types/grid": "3.0.1-nightly.3047+87960ad25",
|
|
23
|
+
"@react-types/shared": "3.0.0-nightly.1356+87960ad25"
|
|
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": "
|
|
31
|
+
"gitHead": "87960ad25c26bc4cd6af506bb5e7e0f06621556c"
|
|
32
32
|
}
|