@react-stately/table 3.11.7-nightly.4552 → 3.11.7-nightly.4558

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.
Files changed (62) hide show
  1. package/dist/Cell.main.js +38 -0
  2. package/dist/Cell.main.js.map +1 -0
  3. package/dist/Cell.mjs +33 -0
  4. package/dist/Cell.module.js +33 -0
  5. package/dist/Cell.module.js.map +1 -0
  6. package/dist/Column.main.js +75 -0
  7. package/dist/Column.main.js.map +1 -0
  8. package/dist/Column.mjs +66 -0
  9. package/dist/Column.module.js +66 -0
  10. package/dist/Column.module.js.map +1 -0
  11. package/dist/Row.main.js +97 -0
  12. package/dist/Row.main.js.map +1 -0
  13. package/dist/Row.mjs +88 -0
  14. package/dist/Row.module.js +88 -0
  15. package/dist/Row.module.js.map +1 -0
  16. package/dist/TableBody.main.js +61 -0
  17. package/dist/TableBody.main.js.map +1 -0
  18. package/dist/TableBody.mjs +52 -0
  19. package/dist/TableBody.module.js +52 -0
  20. package/dist/TableBody.module.js.map +1 -0
  21. package/dist/TableCollection.main.js +284 -0
  22. package/dist/TableCollection.main.js.map +1 -0
  23. package/dist/TableCollection.mjs +278 -0
  24. package/dist/TableCollection.module.js +278 -0
  25. package/dist/TableCollection.module.js.map +1 -0
  26. package/dist/TableColumnLayout.main.js +162 -0
  27. package/dist/TableColumnLayout.main.js.map +1 -0
  28. package/dist/TableColumnLayout.mjs +157 -0
  29. package/dist/TableColumnLayout.module.js +157 -0
  30. package/dist/TableColumnLayout.module.js.map +1 -0
  31. package/dist/TableHeader.main.js +56 -0
  32. package/dist/TableHeader.main.js.map +1 -0
  33. package/dist/TableHeader.mjs +47 -0
  34. package/dist/TableHeader.module.js +47 -0
  35. package/dist/TableHeader.module.js.map +1 -0
  36. package/dist/TableUtils.main.js +184 -0
  37. package/dist/TableUtils.main.js.map +1 -0
  38. package/dist/TableUtils.mjs +175 -0
  39. package/dist/TableUtils.module.js +175 -0
  40. package/dist/TableUtils.module.js.map +1 -0
  41. package/dist/import.mjs +11 -1216
  42. package/dist/main.js +21 -1230
  43. package/dist/main.js.map +1 -1
  44. package/dist/module.js +11 -1216
  45. package/dist/module.js.map +1 -1
  46. package/dist/types.d.ts +1 -1
  47. package/dist/useTableColumnResizeState.main.js +113 -0
  48. package/dist/useTableColumnResizeState.main.js.map +1 -0
  49. package/dist/useTableColumnResizeState.mjs +108 -0
  50. package/dist/useTableColumnResizeState.module.js +108 -0
  51. package/dist/useTableColumnResizeState.module.js.map +1 -0
  52. package/dist/useTableState.main.js +71 -0
  53. package/dist/useTableState.main.js.map +1 -0
  54. package/dist/useTableState.mjs +66 -0
  55. package/dist/useTableState.module.js +66 -0
  56. package/dist/useTableState.module.js.map +1 -0
  57. package/dist/useTreeGridState.main.js +207 -0
  58. package/dist/useTreeGridState.main.js.map +1 -0
  59. package/dist/useTreeGridState.mjs +202 -0
  60. package/dist/useTreeGridState.module.js +202 -0
  61. package/dist/useTreeGridState.module.js.map +1 -0
  62. package/package.json +10 -10
@@ -0,0 +1,202 @@
1
+ import {TableCollection as $788781baa30117fa$export$596e1b2e2cf93690} from "./TableCollection.mjs";
2
+ import {useTableState as $4a0dd036d492cee4$export$907bcc6c48325fd6} from "./useTableState.mjs";
3
+ import {CollectionBuilder as $2Mvwf$CollectionBuilder} from "@react-stately/collections";
4
+ import {useMemo as $2Mvwf$useMemo} from "react";
5
+ import {tableNestedRows as $2Mvwf$tableNestedRows} from "@react-stately/flags";
6
+ import {useControlledState as $2Mvwf$useControlledState} from "@react-stately/utils";
7
+
8
+ /*
9
+ * Copyright 2023 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ function $ee65a0057fd99531$export$34dfa8a1622185a4(props) {
25
+ let { selectionMode: selectionMode = "none", showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons, UNSTABLE_expandedKeys: propExpandedKeys, UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys, UNSTABLE_onExpandedChange: UNSTABLE_onExpandedChange, children: children } = props;
26
+ if (!(0, $2Mvwf$tableNestedRows)()) throw new Error("Feature flag for table nested rows must be enabled to use useTreeGridState.");
27
+ let [expandedKeys, setExpandedKeys] = (0, $2Mvwf$useControlledState)(propExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propExpandedKeys) : undefined, propDefaultExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propDefaultExpandedKeys) : new Set(), UNSTABLE_onExpandedChange);
28
+ let context = (0, $2Mvwf$useMemo)(()=>({
29
+ showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
30
+ showDragButtons: showDragButtons,
31
+ selectionMode: selectionMode,
32
+ columns: []
33
+ }), [
34
+ children,
35
+ showSelectionCheckboxes,
36
+ selectionMode,
37
+ showDragButtons
38
+ ]);
39
+ let builder = (0, $2Mvwf$useMemo)(()=>new (0, $2Mvwf$CollectionBuilder)(), []);
40
+ let nodes = (0, $2Mvwf$useMemo)(()=>builder.build({
41
+ children: children
42
+ }, context), [
43
+ builder,
44
+ children,
45
+ context
46
+ ]);
47
+ let treeGridCollection = (0, $2Mvwf$useMemo)(()=>{
48
+ return $ee65a0057fd99531$var$generateTreeGridCollection(nodes, {
49
+ showSelectionCheckboxes: showSelectionCheckboxes,
50
+ showDragButtons: showDragButtons,
51
+ expandedKeys: expandedKeys
52
+ });
53
+ }, [
54
+ nodes,
55
+ showSelectionCheckboxes,
56
+ showDragButtons,
57
+ expandedKeys
58
+ ]);
59
+ let onToggle = (key)=>{
60
+ setExpandedKeys($ee65a0057fd99531$var$toggleKey(expandedKeys, key, treeGridCollection));
61
+ };
62
+ let collection = (0, $2Mvwf$useMemo)(()=>{
63
+ return new (0, $788781baa30117fa$export$596e1b2e2cf93690)(treeGridCollection.tableNodes, null, context);
64
+ }, [
65
+ context,
66
+ treeGridCollection.tableNodes
67
+ ]);
68
+ let tableState = (0, $4a0dd036d492cee4$export$907bcc6c48325fd6)({
69
+ ...props,
70
+ collection: collection
71
+ });
72
+ return {
73
+ ...tableState,
74
+ keyMap: treeGridCollection.keyMap,
75
+ userColumnCount: treeGridCollection.userColumnCount,
76
+ expandedKeys: expandedKeys,
77
+ toggleKey: onToggle
78
+ };
79
+ }
80
+ function $ee65a0057fd99531$var$toggleKey(currentExpandedKeys, key, collection) {
81
+ let updatedExpandedKeys;
82
+ if (currentExpandedKeys === "all") {
83
+ updatedExpandedKeys = new Set(collection.flattenedRows.filter((row)=>row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map((row)=>row.key));
84
+ updatedExpandedKeys.delete(key);
85
+ } else {
86
+ updatedExpandedKeys = new Set(currentExpandedKeys);
87
+ if (updatedExpandedKeys.has(key)) updatedExpandedKeys.delete(key);
88
+ else updatedExpandedKeys.add(key);
89
+ }
90
+ return updatedExpandedKeys;
91
+ }
92
+ function $ee65a0057fd99531$var$convertExpanded(expanded) {
93
+ if (!expanded) return new Set();
94
+ return expanded === "all" ? "all" : new Set(expanded);
95
+ }
96
+ function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
97
+ let { expandedKeys: expandedKeys = new Set() } = opts;
98
+ let body;
99
+ let flattenedRows = [];
100
+ let columnCount = 0;
101
+ let userColumnCount = 0;
102
+ let originalColumns = [];
103
+ let keyMap = new Map();
104
+ if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) columnCount++;
105
+ if (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) columnCount++;
106
+ let topLevelRows = [];
107
+ let visit = (node)=>{
108
+ switch(node.type){
109
+ case "body":
110
+ body = node;
111
+ keyMap.set(body.key, body);
112
+ break;
113
+ case "column":
114
+ if (!node.hasChildNodes) userColumnCount++;
115
+ break;
116
+ case "item":
117
+ topLevelRows.push(node);
118
+ return;
119
+ }
120
+ for (let child of node.childNodes)visit(child);
121
+ };
122
+ for (let node of nodes){
123
+ if (node.type === "column") originalColumns.push(node);
124
+ visit(node);
125
+ }
126
+ columnCount += userColumnCount;
127
+ // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume
128
+ let globalRowCount = 0;
129
+ let visitNode = (node, i)=>{
130
+ // Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided
131
+ // to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure
132
+ // values automatically calculated via CollectionBuilder
133
+ if (node.type === "item") {
134
+ let childNodes = [];
135
+ for (let child of node.childNodes)if (child.type === "cell") {
136
+ let cellClone = {
137
+ ...child
138
+ };
139
+ if (cellClone.index + 1 === columnCount) cellClone.nextKey = null;
140
+ childNodes.push({
141
+ ...cellClone
142
+ });
143
+ }
144
+ let clone = {
145
+ ...node,
146
+ childNodes: childNodes,
147
+ parentKey: body.key,
148
+ level: 1,
149
+ index: globalRowCount++
150
+ };
151
+ flattenedRows.push(clone);
152
+ }
153
+ let newProps = {};
154
+ // Assign indexOfType to cells and rows for aria-posinset
155
+ if (node.type !== "placeholder" && node.type !== "column") newProps["indexOfType"] = i;
156
+ // Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes
157
+ // via .childNodes returns the same object as the one found via keyMap look up
158
+ Object.assign(node, newProps);
159
+ keyMap.set(node.key, node);
160
+ let lastNode;
161
+ let rowIndex = 0;
162
+ for (let child of node.childNodes)if (!(child.type === "item" && expandedKeys !== "all" && !expandedKeys.has(node.key))) {
163
+ if (child.parentKey == null) // if child is a cell/expanded row/column and the parent key isn't already established by the collection, match child node to parent row
164
+ child.parentKey = node.key;
165
+ if (lastNode) {
166
+ lastNode.nextKey = child.key;
167
+ child.prevKey = lastNode.key;
168
+ } else child.prevKey = null;
169
+ if (child.type === "item") visitNode(child, rowIndex++);
170
+ else // We enforce that the cells come before rows so can just reuse cell index
171
+ visitNode(child, child.index);
172
+ lastNode = child;
173
+ }
174
+ if (lastNode) lastNode.nextKey = null;
175
+ };
176
+ let last;
177
+ topLevelRows.forEach((node, i)=>{
178
+ visitNode(node, i);
179
+ if (last) {
180
+ last.nextKey = node.key;
181
+ node.prevKey = last.key;
182
+ } else node.prevKey = null;
183
+ last = node;
184
+ });
185
+ if (last) last.nextKey = null;
186
+ return {
187
+ keyMap: keyMap,
188
+ userColumnCount: userColumnCount,
189
+ flattenedRows: flattenedRows,
190
+ tableNodes: [
191
+ ...originalColumns,
192
+ {
193
+ ...body,
194
+ childNodes: flattenedRows
195
+ }
196
+ ]
197
+ };
198
+ }
199
+
200
+
201
+ export {$ee65a0057fd99531$export$34dfa8a1622185a4 as UNSTABLE_useTreeGridState};
202
+ //# sourceMappingURL=useTreeGridState.mjs.map
@@ -0,0 +1,202 @@
1
+ import {TableCollection as $788781baa30117fa$export$596e1b2e2cf93690} from "./TableCollection.module.js";
2
+ import {useTableState as $4a0dd036d492cee4$export$907bcc6c48325fd6} from "./useTableState.module.js";
3
+ import {CollectionBuilder as $2Mvwf$CollectionBuilder} from "@react-stately/collections";
4
+ import {useMemo as $2Mvwf$useMemo} from "react";
5
+ import {tableNestedRows as $2Mvwf$tableNestedRows} from "@react-stately/flags";
6
+ import {useControlledState as $2Mvwf$useControlledState} from "@react-stately/utils";
7
+
8
+ /*
9
+ * Copyright 2023 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ function $ee65a0057fd99531$export$34dfa8a1622185a4(props) {
25
+ let { selectionMode: selectionMode = "none", showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons, UNSTABLE_expandedKeys: propExpandedKeys, UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys, UNSTABLE_onExpandedChange: UNSTABLE_onExpandedChange, children: children } = props;
26
+ if (!(0, $2Mvwf$tableNestedRows)()) throw new Error("Feature flag for table nested rows must be enabled to use useTreeGridState.");
27
+ let [expandedKeys, setExpandedKeys] = (0, $2Mvwf$useControlledState)(propExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propExpandedKeys) : undefined, propDefaultExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propDefaultExpandedKeys) : new Set(), UNSTABLE_onExpandedChange);
28
+ let context = (0, $2Mvwf$useMemo)(()=>({
29
+ showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
30
+ showDragButtons: showDragButtons,
31
+ selectionMode: selectionMode,
32
+ columns: []
33
+ }), [
34
+ children,
35
+ showSelectionCheckboxes,
36
+ selectionMode,
37
+ showDragButtons
38
+ ]);
39
+ let builder = (0, $2Mvwf$useMemo)(()=>new (0, $2Mvwf$CollectionBuilder)(), []);
40
+ let nodes = (0, $2Mvwf$useMemo)(()=>builder.build({
41
+ children: children
42
+ }, context), [
43
+ builder,
44
+ children,
45
+ context
46
+ ]);
47
+ let treeGridCollection = (0, $2Mvwf$useMemo)(()=>{
48
+ return $ee65a0057fd99531$var$generateTreeGridCollection(nodes, {
49
+ showSelectionCheckboxes: showSelectionCheckboxes,
50
+ showDragButtons: showDragButtons,
51
+ expandedKeys: expandedKeys
52
+ });
53
+ }, [
54
+ nodes,
55
+ showSelectionCheckboxes,
56
+ showDragButtons,
57
+ expandedKeys
58
+ ]);
59
+ let onToggle = (key)=>{
60
+ setExpandedKeys($ee65a0057fd99531$var$toggleKey(expandedKeys, key, treeGridCollection));
61
+ };
62
+ let collection = (0, $2Mvwf$useMemo)(()=>{
63
+ return new (0, $788781baa30117fa$export$596e1b2e2cf93690)(treeGridCollection.tableNodes, null, context);
64
+ }, [
65
+ context,
66
+ treeGridCollection.tableNodes
67
+ ]);
68
+ let tableState = (0, $4a0dd036d492cee4$export$907bcc6c48325fd6)({
69
+ ...props,
70
+ collection: collection
71
+ });
72
+ return {
73
+ ...tableState,
74
+ keyMap: treeGridCollection.keyMap,
75
+ userColumnCount: treeGridCollection.userColumnCount,
76
+ expandedKeys: expandedKeys,
77
+ toggleKey: onToggle
78
+ };
79
+ }
80
+ function $ee65a0057fd99531$var$toggleKey(currentExpandedKeys, key, collection) {
81
+ let updatedExpandedKeys;
82
+ if (currentExpandedKeys === "all") {
83
+ updatedExpandedKeys = new Set(collection.flattenedRows.filter((row)=>row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map((row)=>row.key));
84
+ updatedExpandedKeys.delete(key);
85
+ } else {
86
+ updatedExpandedKeys = new Set(currentExpandedKeys);
87
+ if (updatedExpandedKeys.has(key)) updatedExpandedKeys.delete(key);
88
+ else updatedExpandedKeys.add(key);
89
+ }
90
+ return updatedExpandedKeys;
91
+ }
92
+ function $ee65a0057fd99531$var$convertExpanded(expanded) {
93
+ if (!expanded) return new Set();
94
+ return expanded === "all" ? "all" : new Set(expanded);
95
+ }
96
+ function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
97
+ let { expandedKeys: expandedKeys = new Set() } = opts;
98
+ let body;
99
+ let flattenedRows = [];
100
+ let columnCount = 0;
101
+ let userColumnCount = 0;
102
+ let originalColumns = [];
103
+ let keyMap = new Map();
104
+ if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) columnCount++;
105
+ if (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) columnCount++;
106
+ let topLevelRows = [];
107
+ let visit = (node)=>{
108
+ switch(node.type){
109
+ case "body":
110
+ body = node;
111
+ keyMap.set(body.key, body);
112
+ break;
113
+ case "column":
114
+ if (!node.hasChildNodes) userColumnCount++;
115
+ break;
116
+ case "item":
117
+ topLevelRows.push(node);
118
+ return;
119
+ }
120
+ for (let child of node.childNodes)visit(child);
121
+ };
122
+ for (let node of nodes){
123
+ if (node.type === "column") originalColumns.push(node);
124
+ visit(node);
125
+ }
126
+ columnCount += userColumnCount;
127
+ // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume
128
+ let globalRowCount = 0;
129
+ let visitNode = (node, i)=>{
130
+ // Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided
131
+ // to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure
132
+ // values automatically calculated via CollectionBuilder
133
+ if (node.type === "item") {
134
+ let childNodes = [];
135
+ for (let child of node.childNodes)if (child.type === "cell") {
136
+ let cellClone = {
137
+ ...child
138
+ };
139
+ if (cellClone.index + 1 === columnCount) cellClone.nextKey = null;
140
+ childNodes.push({
141
+ ...cellClone
142
+ });
143
+ }
144
+ let clone = {
145
+ ...node,
146
+ childNodes: childNodes,
147
+ parentKey: body.key,
148
+ level: 1,
149
+ index: globalRowCount++
150
+ };
151
+ flattenedRows.push(clone);
152
+ }
153
+ let newProps = {};
154
+ // Assign indexOfType to cells and rows for aria-posinset
155
+ if (node.type !== "placeholder" && node.type !== "column") newProps["indexOfType"] = i;
156
+ // Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes
157
+ // via .childNodes returns the same object as the one found via keyMap look up
158
+ Object.assign(node, newProps);
159
+ keyMap.set(node.key, node);
160
+ let lastNode;
161
+ let rowIndex = 0;
162
+ for (let child of node.childNodes)if (!(child.type === "item" && expandedKeys !== "all" && !expandedKeys.has(node.key))) {
163
+ if (child.parentKey == null) // if child is a cell/expanded row/column and the parent key isn't already established by the collection, match child node to parent row
164
+ child.parentKey = node.key;
165
+ if (lastNode) {
166
+ lastNode.nextKey = child.key;
167
+ child.prevKey = lastNode.key;
168
+ } else child.prevKey = null;
169
+ if (child.type === "item") visitNode(child, rowIndex++);
170
+ else // We enforce that the cells come before rows so can just reuse cell index
171
+ visitNode(child, child.index);
172
+ lastNode = child;
173
+ }
174
+ if (lastNode) lastNode.nextKey = null;
175
+ };
176
+ let last;
177
+ topLevelRows.forEach((node, i)=>{
178
+ visitNode(node, i);
179
+ if (last) {
180
+ last.nextKey = node.key;
181
+ node.prevKey = last.key;
182
+ } else node.prevKey = null;
183
+ last = node;
184
+ });
185
+ if (last) last.nextKey = null;
186
+ return {
187
+ keyMap: keyMap,
188
+ userColumnCount: userColumnCount,
189
+ flattenedRows: flattenedRows,
190
+ tableNodes: [
191
+ ...originalColumns,
192
+ {
193
+ ...body,
194
+ childNodes: flattenedRows
195
+ }
196
+ ]
197
+ };
198
+ }
199
+
200
+
201
+ export {$ee65a0057fd99531$export$34dfa8a1622185a4 as UNSTABLE_useTreeGridState};
202
+ //# sourceMappingURL=useTreeGridState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAA4C,KAA4B;IACtF,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC,CAAA,GAAA,sBAAc,KACjB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yBAAiB,EACrD,mBAAmB,sCAAgB,oBAAoB,WACvD,0BAA0B,sCAAgB,2BAA2B,IAAI,OACzE;IAGF,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;YAC3B,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QAEb,CAAA,GAAI;QAAC;QA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A;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAE,YAAY;YAAa;SAAE;IACxE;AACF","sources":["packages/@react-stately/table/src/useTreeGridState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {CollectionBuilder} from '@react-stately/collections';\nimport {GridNode} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\nimport {ReactElement, useMemo} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {tableNestedRows} from '@react-stately/flags';\nimport {TableState, TableStateProps, useTableState} from './useTableState';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeGridState<T> extends TableState<T> {\n /** A set of keys for items that are expanded. */\n expandedKeys: 'all' | Set<Key>,\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void,\n /** The key map containing nodes representing the collection's tree grid structure. */\n keyMap: Map<Key, GridNode<T>>,\n /** The number of leaf columns provided by the user. */\n userColumnCount: number\n}\n\nexport interface TreeGridStateProps<T> extends Omit<TableStateProps<T>, 'collection'> {\n /** The currently expanded keys in the collection (controlled). */\n UNSTABLE_expandedKeys?: 'all' | Iterable<Key>,\n /** The initial expanded keys in the collection (uncontrolled). */\n UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>,\n /** Handler that is called when items are expanded or collapsed. */\n UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any\n}\n\n/**\n * Provides state management for a tree grid component. Handles building a collection\n * of columns and rows from props. In addition, it tracks and manages expanded rows, row selection, and sort order changes.\n */\nexport function UNSTABLE_useTreeGridState<T extends object>(props: TreeGridStateProps<T>): TreeGridState<T> {\n let {\n selectionMode = 'none',\n showSelectionCheckboxes,\n showDragButtons,\n UNSTABLE_expandedKeys: propExpandedKeys,\n UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys,\n UNSTABLE_onExpandedChange,\n children\n } = props;\n\n if (!tableNestedRows()) {\n throw new Error('Feature flag for table nested rows must be enabled to use useTreeGridState.');\n }\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n propExpandedKeys ? convertExpanded(propExpandedKeys) : undefined,\n propDefaultExpandedKeys ? convertExpanded(propDefaultExpandedKeys) : new Set(),\n UNSTABLE_onExpandedChange\n );\n\n let context = useMemo(() => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [children, showSelectionCheckboxes, selectionMode, showDragButtons]);\n\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let nodes = useMemo(() => builder.build({children: children as ReactElement[]}, context), [builder, children, context]);\n let treeGridCollection = useMemo(() => {\n return generateTreeGridCollection<T>(nodes, {showSelectionCheckboxes, showDragButtons, expandedKeys});\n }, [nodes, showSelectionCheckboxes, showDragButtons, expandedKeys]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key, treeGridCollection));\n };\n\n let collection = useMemo(() => {\n return new TableCollection(treeGridCollection.tableNodes, null, context);\n }, [context, treeGridCollection.tableNodes]);\n\n let tableState = useTableState({...props, collection});\n return {\n ...tableState,\n keyMap: treeGridCollection.keyMap,\n userColumnCount: treeGridCollection.userColumnCount,\n expandedKeys,\n toggleKey: onToggle\n };\n}\n\nfunction toggleKey<T>(currentExpandedKeys: 'all' | Set<Key>, key: Key, collection: TreeGridCollection<T>): Set<Key> {\n let updatedExpandedKeys: Set<Key>;\n if (currentExpandedKeys === 'all') {\n updatedExpandedKeys = new Set(collection.flattenedRows.filter(row => row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map(row => row.key));\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys = new Set(currentExpandedKeys);\n if (updatedExpandedKeys.has(key)) {\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys.add(key);\n }\n }\n\n return updatedExpandedKeys;\n}\n\nfunction convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {\n if (!expanded) {\n return new Set<Key>();\n }\n\n return expanded === 'all'\n ? 'all'\n : new Set(expanded);\n}\n\ninterface TreeGridCollectionOptions {\n showSelectionCheckboxes?: boolean,\n showDragButtons?: boolean,\n expandedKeys: 'all' | Set<Key>\n}\n\ninterface TreeGridCollection<T> {\n keyMap: Map<Key, GridNode<T>>,\n tableNodes: GridNode<T>[],\n flattenedRows: GridNode<T>[],\n userColumnCount: number\n}\nfunction generateTreeGridCollection<T>(nodes, opts: TreeGridCollectionOptions): TreeGridCollection<T> {\n let {\n expandedKeys = new Set()\n } = opts;\n\n let body: GridNode<T>;\n let flattenedRows = [];\n let columnCount = 0;\n let userColumnCount = 0;\n let originalColumns = [];\n let keyMap = new Map();\n\n if (opts?.showSelectionCheckboxes) {\n columnCount++;\n }\n\n if (opts?.showDragButtons) {\n columnCount++;\n }\n\n let topLevelRows = [];\n let visit = (node: GridNode<T>) => {\n switch (node.type) {\n case 'body':\n body = node;\n keyMap.set(body.key, body);\n break;\n case 'column':\n if (!node.hasChildNodes) {\n userColumnCount++;\n }\n break;\n case 'item':\n topLevelRows.push(node);\n return;\n }\n\n for (let child of node.childNodes) {\n visit(child);\n }\n };\n\n for (let node of nodes) {\n if (node.type === 'column') {\n originalColumns.push(node);\n }\n visit(node);\n }\n columnCount += userColumnCount;\n\n // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume\n let globalRowCount = 0;\n let visitNode = (node: GridNode<T>, i?: number) => {\n // Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided\n // to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure\n // values automatically calculated via CollectionBuilder\n if (node.type === 'item') {\n let childNodes = [];\n for (let child of node.childNodes) {\n if (child.type === 'cell') {\n let cellClone = {...child};\n if (cellClone.index + 1 === columnCount) {\n cellClone.nextKey = null;\n }\n childNodes.push({...cellClone});\n }\n }\n let clone = {...node, childNodes: childNodes, parentKey: body.key, level: 1, index: globalRowCount++};\n flattenedRows.push(clone);\n }\n\n let newProps = {};\n\n // Assign indexOfType to cells and rows for aria-posinset\n if (node.type !== 'placeholder' && node.type !== 'column') {\n newProps['indexOfType'] = i;\n }\n\n // Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes\n // via .childNodes returns the same object as the one found via keyMap look up\n Object.assign(node, newProps);\n keyMap.set(node.key, node);\n\n let lastNode: GridNode<T>;\n let rowIndex = 0;\n for (let child of node.childNodes) {\n if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {\n if (child.parentKey == null) {\n // if child is a cell/expanded row/column and the parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n\n if (lastNode) {\n lastNode.nextKey = child.key;\n child.prevKey = lastNode.key;\n } else {\n child.prevKey = null;\n }\n\n if (child.type === 'item') {\n visitNode(child, rowIndex++);\n } else {\n // We enforce that the cells come before rows so can just reuse cell index\n visitNode(child, child.index);\n }\n\n lastNode = child;\n }\n }\n\n if (lastNode) {\n lastNode.nextKey = null;\n }\n };\n\n let last: GridNode<T>;\n topLevelRows.forEach((node: GridNode<T>, i) => {\n visitNode(node as GridNode<T>, i);\n\n if (last) {\n last.nextKey = node.key;\n node.prevKey = last.key;\n } else {\n node.prevKey = null;\n }\n\n last = node;\n });\n\n if (last) {\n last.nextKey = null;\n }\n\n return {\n keyMap,\n userColumnCount,\n flattenedRows,\n tableNodes: [...originalColumns, {...body, childNodes: flattenedRows}]\n };\n}\n"],"names":[],"version":3,"file":"useTreeGridState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/table",
3
- "version": "3.11.7-nightly.4552+64ed13090",
3
+ "version": "3.11.7-nightly.4558+c5e4b3701",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,14 +22,14 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/collections": "3.0.0-nightly.2840+64ed13090",
26
- "@react-stately/flags": "3.0.2-nightly.4552+64ed13090",
27
- "@react-stately/grid": "3.8.6-nightly.4552+64ed13090",
28
- "@react-stately/selection": "3.0.0-nightly.2840+64ed13090",
29
- "@react-stately/utils": "3.0.0-nightly.2840+64ed13090",
30
- "@react-types/grid": "3.2.5-nightly.4552+64ed13090",
31
- "@react-types/shared": "3.0.0-nightly.2840+64ed13090",
32
- "@react-types/table": "3.9.4-nightly.4552+64ed13090",
25
+ "@react-stately/collections": "3.0.0-nightly.2846+c5e4b3701",
26
+ "@react-stately/flags": "3.0.2-nightly.4558+c5e4b3701",
27
+ "@react-stately/grid": "3.8.6-nightly.4558+c5e4b3701",
28
+ "@react-stately/selection": "3.0.0-nightly.2846+c5e4b3701",
29
+ "@react-stately/utils": "3.0.0-nightly.2846+c5e4b3701",
30
+ "@react-types/grid": "3.2.5-nightly.4558+c5e4b3701",
31
+ "@react-types/shared": "3.0.0-nightly.2846+c5e4b3701",
32
+ "@react-types/table": "3.9.4-nightly.4558+c5e4b3701",
33
33
  "@swc/helpers": "^0.5.0"
34
34
  },
35
35
  "peerDependencies": {
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "64ed13090ce77cc0e4cb4cd5602e75f655bff6bb"
41
+ "gitHead": "c5e4b3701fdb89eb551f1b3697ac253f06ef68fa"
42
42
  }