@react-stately/grid 3.0.0-beta.0 → 3.0.0-nightly-641446f65-240905

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.
@@ -0,0 +1,128 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$de3fdf6493c353d);
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ class $8bb6a9101b052a66$export$de3fdf6493c353d {
18
+ *[Symbol.iterator]() {
19
+ yield* [
20
+ ...this.rows
21
+ ];
22
+ }
23
+ get size() {
24
+ return [
25
+ ...this.rows
26
+ ].length;
27
+ }
28
+ getKeys() {
29
+ return this.keyMap.keys();
30
+ }
31
+ getKeyBefore(key) {
32
+ let node = this.keyMap.get(key);
33
+ return node ? node.prevKey : null;
34
+ }
35
+ getKeyAfter(key) {
36
+ let node = this.keyMap.get(key);
37
+ return node ? node.nextKey : null;
38
+ }
39
+ getFirstKey() {
40
+ var _;
41
+ return (_ = [
42
+ ...this.rows
43
+ ][0]) === null || _ === void 0 ? void 0 : _.key;
44
+ }
45
+ getLastKey() {
46
+ var _rows_;
47
+ let rows = [
48
+ ...this.rows
49
+ ];
50
+ return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
51
+ }
52
+ getItem(key) {
53
+ return this.keyMap.get(key);
54
+ }
55
+ at(idx) {
56
+ const keys = [
57
+ ...this.getKeys()
58
+ ];
59
+ return this.getItem(keys[idx]);
60
+ }
61
+ getChildren(key) {
62
+ let node = this.keyMap.get(key);
63
+ return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
64
+ }
65
+ constructor(opts){
66
+ this.keyMap = new Map();
67
+ this.keyMap = new Map();
68
+ this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
69
+ this.rows = [];
70
+ let visit = (node)=>{
71
+ // If the node is the same object as the previous node for the same key,
72
+ // we can skip this node and its children. We always visit columns though,
73
+ // because we depend on order to build the columns array.
74
+ let prevNode = this.keyMap.get(node.key);
75
+ if (opts.visitNode) node = opts.visitNode(node);
76
+ this.keyMap.set(node.key, node);
77
+ let childKeys = new Set();
78
+ let last;
79
+ for (let child of node.childNodes){
80
+ 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
81
+ child.parentKey = node.key;
82
+ childKeys.add(child.key);
83
+ if (last) {
84
+ last.nextKey = child.key;
85
+ child.prevKey = last.key;
86
+ } else child.prevKey = null;
87
+ visit(child);
88
+ last = child;
89
+ }
90
+ if (last) last.nextKey = null;
91
+ // Remove deleted nodes and their children from the key map
92
+ if (prevNode) {
93
+ for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
94
+ }
95
+ };
96
+ let remove = (node)=>{
97
+ this.keyMap.delete(node.key);
98
+ for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
99
+ };
100
+ let last;
101
+ opts.items.forEach((node, i)=>{
102
+ let rowNode = {
103
+ level: 0,
104
+ key: 'row-' + i,
105
+ type: 'row',
106
+ value: undefined,
107
+ hasChildNodes: true,
108
+ childNodes: [
109
+ ...node.childNodes
110
+ ],
111
+ rendered: undefined,
112
+ textValue: undefined,
113
+ ...node
114
+ };
115
+ if (last) {
116
+ last.nextKey = rowNode.key;
117
+ rowNode.prevKey = last.key;
118
+ } else rowNode.prevKey = null;
119
+ this.rows.push(row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AM,OACjC,OAAO;QAGb;QAEA,IAAI;QACJ,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM;YACxB,IAAI,UAAU;gBACZ,OAAO;gBACP,KAAK,SAAS;gBACd,MAAM;gBACN,OAAO;gBACP,eAAe;gBACf,YAAY;uBAAI,KAAK,UAAU;iBAAC;gBAChC,UAAU;gBACV,WAAW;gBACX,GAAG,IAAI;YACT;YAEA,IAAI,MAAM;gBACR,KAAK,OAAO,GAAG,QAAQ,GAAG;gBAC1B,QAAQ,OAAO,GAAG,KAAK,GAAG;YAC5B,OACE,QAAQ,OAAO,GAAG;YAGpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,OAAO,GAAG;IAEnB;AA8CF","sources":["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\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\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 } as GridNode<T>;\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n });\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"GridCollection.main.js.map"}
@@ -0,0 +1,123 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ class $16805b1b18093c5f$export$de3fdf6493c353d {
12
+ *[Symbol.iterator]() {
13
+ yield* [
14
+ ...this.rows
15
+ ];
16
+ }
17
+ get size() {
18
+ return [
19
+ ...this.rows
20
+ ].length;
21
+ }
22
+ getKeys() {
23
+ return this.keyMap.keys();
24
+ }
25
+ getKeyBefore(key) {
26
+ let node = this.keyMap.get(key);
27
+ return node ? node.prevKey : null;
28
+ }
29
+ getKeyAfter(key) {
30
+ let node = this.keyMap.get(key);
31
+ return node ? node.nextKey : null;
32
+ }
33
+ getFirstKey() {
34
+ var _;
35
+ return (_ = [
36
+ ...this.rows
37
+ ][0]) === null || _ === void 0 ? void 0 : _.key;
38
+ }
39
+ getLastKey() {
40
+ var _rows_;
41
+ let rows = [
42
+ ...this.rows
43
+ ];
44
+ return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
45
+ }
46
+ getItem(key) {
47
+ return this.keyMap.get(key);
48
+ }
49
+ at(idx) {
50
+ const keys = [
51
+ ...this.getKeys()
52
+ ];
53
+ return this.getItem(keys[idx]);
54
+ }
55
+ getChildren(key) {
56
+ let node = this.keyMap.get(key);
57
+ return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
58
+ }
59
+ constructor(opts){
60
+ this.keyMap = new Map();
61
+ this.keyMap = new Map();
62
+ this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
63
+ this.rows = [];
64
+ let visit = (node)=>{
65
+ // If the node is the same object as the previous node for the same key,
66
+ // we can skip this node and its children. We always visit columns though,
67
+ // because we depend on order to build the columns array.
68
+ let prevNode = this.keyMap.get(node.key);
69
+ if (opts.visitNode) node = opts.visitNode(node);
70
+ this.keyMap.set(node.key, node);
71
+ let childKeys = new Set();
72
+ let last;
73
+ for (let child of node.childNodes){
74
+ 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
75
+ child.parentKey = node.key;
76
+ childKeys.add(child.key);
77
+ if (last) {
78
+ last.nextKey = child.key;
79
+ child.prevKey = last.key;
80
+ } else child.prevKey = null;
81
+ visit(child);
82
+ last = child;
83
+ }
84
+ if (last) last.nextKey = null;
85
+ // Remove deleted nodes and their children from the key map
86
+ if (prevNode) {
87
+ for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
88
+ }
89
+ };
90
+ let remove = (node)=>{
91
+ this.keyMap.delete(node.key);
92
+ for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
93
+ };
94
+ let last;
95
+ opts.items.forEach((node, i)=>{
96
+ let rowNode = {
97
+ level: 0,
98
+ key: 'row-' + i,
99
+ type: 'row',
100
+ value: undefined,
101
+ hasChildNodes: true,
102
+ childNodes: [
103
+ ...node.childNodes
104
+ ],
105
+ rendered: undefined,
106
+ textValue: undefined,
107
+ ...node
108
+ };
109
+ if (last) {
110
+ last.nextKey = rowNode.key;
111
+ rowNode.prevKey = last.key;
112
+ } else rowNode.prevKey = null;
113
+ this.rows.push(rowNode);
114
+ visit(rowNode);
115
+ last = rowNode;
116
+ });
117
+ if (last) last.nextKey = null;
118
+ }
119
+ }
120
+
121
+
122
+ export {$16805b1b18093c5f$export$de3fdf6493c353d as GridCollection};
123
+ //# sourceMappingURL=GridCollection.module.js.map
@@ -0,0 +1,123 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ class $16805b1b18093c5f$export$de3fdf6493c353d {
12
+ *[Symbol.iterator]() {
13
+ yield* [
14
+ ...this.rows
15
+ ];
16
+ }
17
+ get size() {
18
+ return [
19
+ ...this.rows
20
+ ].length;
21
+ }
22
+ getKeys() {
23
+ return this.keyMap.keys();
24
+ }
25
+ getKeyBefore(key) {
26
+ let node = this.keyMap.get(key);
27
+ return node ? node.prevKey : null;
28
+ }
29
+ getKeyAfter(key) {
30
+ let node = this.keyMap.get(key);
31
+ return node ? node.nextKey : null;
32
+ }
33
+ getFirstKey() {
34
+ var _;
35
+ return (_ = [
36
+ ...this.rows
37
+ ][0]) === null || _ === void 0 ? void 0 : _.key;
38
+ }
39
+ getLastKey() {
40
+ var _rows_;
41
+ let rows = [
42
+ ...this.rows
43
+ ];
44
+ return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
45
+ }
46
+ getItem(key) {
47
+ return this.keyMap.get(key);
48
+ }
49
+ at(idx) {
50
+ const keys = [
51
+ ...this.getKeys()
52
+ ];
53
+ return this.getItem(keys[idx]);
54
+ }
55
+ getChildren(key) {
56
+ let node = this.keyMap.get(key);
57
+ return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
58
+ }
59
+ constructor(opts){
60
+ this.keyMap = new Map();
61
+ this.keyMap = new Map();
62
+ this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
63
+ this.rows = [];
64
+ let visit = (node)=>{
65
+ // If the node is the same object as the previous node for the same key,
66
+ // we can skip this node and its children. We always visit columns though,
67
+ // because we depend on order to build the columns array.
68
+ let prevNode = this.keyMap.get(node.key);
69
+ if (opts.visitNode) node = opts.visitNode(node);
70
+ this.keyMap.set(node.key, node);
71
+ let childKeys = new Set();
72
+ let last;
73
+ for (let child of node.childNodes){
74
+ 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
75
+ child.parentKey = node.key;
76
+ childKeys.add(child.key);
77
+ if (last) {
78
+ last.nextKey = child.key;
79
+ child.prevKey = last.key;
80
+ } else child.prevKey = null;
81
+ visit(child);
82
+ last = child;
83
+ }
84
+ if (last) last.nextKey = null;
85
+ // Remove deleted nodes and their children from the key map
86
+ if (prevNode) {
87
+ for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
88
+ }
89
+ };
90
+ let remove = (node)=>{
91
+ this.keyMap.delete(node.key);
92
+ for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
93
+ };
94
+ let last;
95
+ opts.items.forEach((node, i)=>{
96
+ let rowNode = {
97
+ level: 0,
98
+ key: 'row-' + i,
99
+ type: 'row',
100
+ value: undefined,
101
+ hasChildNodes: true,
102
+ childNodes: [
103
+ ...node.childNodes
104
+ ],
105
+ rendered: undefined,
106
+ textValue: undefined,
107
+ ...node
108
+ };
109
+ if (last) {
110
+ last.nextKey = rowNode.key;
111
+ rowNode.prevKey = last.key;
112
+ } else rowNode.prevKey = null;
113
+ this.rows.push(rowNode);
114
+ visit(rowNode);
115
+ last = rowNode;
116
+ });
117
+ if (last) last.nextKey = null;
118
+ }
119
+ }
120
+
121
+
122
+ export {$16805b1b18093c5f$export$de3fdf6493c353d as GridCollection};
123
+ //# sourceMappingURL=GridCollection.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CA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AY;uBAAI,KAAK,UAAU;iBAAC;gBAChC,UAAU;gBACV,WAAW;gBACX,GAAG,IAAI;YACT;YAEA,IAAI,MAAM;gBACR,KAAK,OAAO,GAAG,QAAQ,GAAG;gBAC1B,QAAQ,OAAO,GAAG,KAAK,GAAG;YAC5B,OACE,QAAQ,OAAO,GAAG;YAGpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,OAAO,GAAG;IAEnB;AA8CF","sources":["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\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\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 } as GridNode<T>;\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n });\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"GridCollection.module.js.map"}
@@ -0,0 +1,19 @@
1
+ import {useGridState as $62967d126f3aa823$export$4007ac09ff9c68ed} from "./useGridState.mjs";
2
+ import {GridCollection as $16805b1b18093c5f$export$de3fdf6493c353d} from "./GridCollection.mjs";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+
17
+
18
+ export {$62967d126f3aa823$export$4007ac09ff9c68ed as useGridState, $16805b1b18093c5f$export$de3fdf6493c353d as GridCollection};
19
+ //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,71 +1,13 @@
1
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
1
+ var $38009b28e45912ea$exports = require("./useGridState.main.js");
2
+ var $8bb6a9101b052a66$exports = require("./GridCollection.main.js");
2
3
 
3
- var {
4
- SelectionManager,
5
- useMultipleSelectionState
6
- } = require("@react-stately/selection");
7
4
 
8
- var {
9
- useEffect,
10
- useMemo
11
- } = require("react");
12
-
13
- function $parcel$interopDefault(a) {
14
- return a && a.__esModule ? a.default : a;
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
15
7
  }
16
8
 
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);
56
- }
57
- }, [collection, selectionState.focusedKey]);
58
- return {
59
- collection,
60
- disabledKeys,
61
- selectionManager: new SelectionManager(collection, selectionState)
62
- };
63
- }
64
-
65
- exports.useGridState = useGridState;
66
- let $b9f358a1a5a44d4c3a26859$var$_Symbol$iterator;
67
- $b9f358a1a5a44d4c3a26859$var$_Symbol$iterator = Symbol.iterator;
68
-
9
+ $parcel$export(module.exports, "useGridState", () => $38009b28e45912ea$exports.useGridState);
10
+ $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$exports.GridCollection);
69
11
  /*
70
12
  * Copyright 2020 Adobe. All rights reserved.
71
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -76,145 +18,8 @@ $b9f358a1a5a44d4c3a26859$var$_Symbol$iterator = Symbol.iterator;
76
18
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
77
19
  * OF ANY KIND, either express or implied. See the License for the specific language
78
20
  * 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);
97
- }
98
-
99
- this.keyMap.set(node.key, node);
100
- let childKeys = new Set();
101
- let last;
102
-
103
- for (let child of node.childNodes) {
104
- if (child.type === 'cell' && child.parentKey == null) {
105
- // if child is a cell parent key isn't already established by the collection, match child node to parent row
106
- child.parentKey = node.key;
107
- }
108
-
109
- childKeys.add(child.key);
110
-
111
- if (last) {
112
- last.nextKey = child.key;
113
- child.prevKey = last.key;
114
- } else {
115
- child.prevKey = null;
116
- }
117
-
118
- visit(child);
119
- last = child;
120
- }
21
+ */
121
22
 
122
- if (last) {
123
- last.nextKey = null;
124
- } // Remove deleted nodes and their children from the key map
125
23
 
126
24
 
127
- if (prevNode) {
128
- for (let child of prevNode.childNodes) {
129
- if (!childKeys.has(child.key)) {
130
- remove(child);
131
- }
132
- }
133
- }
134
- };
135
-
136
- let remove = node => {
137
- this.keyMap.delete(node.key);
138
-
139
- for (let child of node.childNodes) {
140
- if (this.keyMap.get(child.key) === child) {
141
- remove(child);
142
- }
143
- }
144
- };
145
-
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
-
173
- if (last) {
174
- last.nextKey = null;
175
- }
176
- }
177
-
178
- *[$b9f358a1a5a44d4c3a26859$var$_Symbol$iterator]() {
179
- yield* [...this.rows];
180
- }
181
-
182
- get size() {
183
- return [...this.rows].length;
184
- }
185
-
186
- getKeys() {
187
- return this.keyMap.keys();
188
- }
189
-
190
- getKeyBefore(key) {
191
- let node = this.keyMap.get(key);
192
- return node ? node.prevKey : null;
193
- }
194
-
195
- getKeyAfter(key) {
196
- let node = this.keyMap.get(key);
197
- return node ? node.nextKey : null;
198
- }
199
-
200
- getFirstKey() {
201
- var _;
202
-
203
- return (_ = [...this.rows][0]) == null ? void 0 : _.key;
204
- }
205
-
206
- getLastKey() {
207
- var _rows;
208
-
209
- let rows = [...this.rows];
210
- return (_rows = rows[rows.length - 1]) == null ? void 0 : _rows.key;
211
- }
212
-
213
- getItem(key) {
214
- return this.keyMap.get(key);
215
- }
216
-
217
- }
218
-
219
- exports.GridCollection = GridCollection;
220
25
  //# sourceMappingURL=main.js.map