@react-stately/table 3.10.1-nightly.4028 → 3.10.1-nightly.4036

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/import.mjs CHANGED
@@ -1,6 +1,8 @@
1
- import {Section as $6555104ff085bef4$re_export$Section, useCollection as $1BfjW$useCollection, getFirstItem as $1BfjW$getFirstItem, getLastItem as $1BfjW$getLastItem} from "@react-stately/collections";
1
+ import {Section as $6555104ff085bef4$re_export$Section, useCollection as $1BfjW$useCollection, getFirstItem as $1BfjW$getFirstItem, getLastItem as $1BfjW$getLastItem, CollectionBuilder as $1BfjW$CollectionBuilder} from "@react-stately/collections";
2
2
  import $1BfjW$react, {useState as $1BfjW$useState, useMemo as $1BfjW$useMemo, useCallback as $1BfjW$useCallback} from "react";
3
3
  import {useGridState as $1BfjW$useGridState, GridCollection as $1BfjW$GridCollection} from "@react-stately/grid";
4
+ import {tableNestedRows as $1BfjW$tableNestedRows} from "@react-stately/flags";
5
+ import {useControlledState as $1BfjW$useControlledState} from "@react-stately/utils";
4
6
 
5
7
  /*
6
8
  * Copyright 2020 Adobe. All rights reserved.
@@ -929,7 +931,7 @@ function $70d70eb16ea48428$var$Row(props) {
929
931
  return null;
930
932
  }
931
933
  $70d70eb16ea48428$var$Row.getCollectionNode = function* getCollectionNode(props, context) {
932
- let { children: children , textValue: textValue } = props;
934
+ let { children: children , textValue: textValue , UNSTABLE_childItems: UNSTABLE_childItems } = props;
933
935
  yield {
934
936
  type: "item",
935
937
  props: props,
@@ -952,21 +954,36 @@ $70d70eb16ea48428$var$Row.getCollectionNode = function* getCollectionNode(props,
952
954
  isSelectionCell: true
953
955
  }
954
956
  };
955
- if (typeof children === "function") for (let column of context.columns)yield {
956
- type: "cell",
957
- element: children(column.key),
958
- key: column.key // this is combined with the row key by CollectionBuilder
959
- };
960
- else {
957
+ if (typeof children === "function") {
958
+ for (let column of context.columns)yield {
959
+ type: "cell",
960
+ element: children(column.key),
961
+ key: column.key // this is combined with the row key by CollectionBuilder
962
+ };
963
+ if (UNSTABLE_childItems) for (let child of UNSTABLE_childItems)// Note: in order to reuse the render function of TableBody for our child rows, we just need to yield a type and a value here. CollectionBuilder will then look up
964
+ // the parent renderer and use that to build the full node of this child row, using the value provided here to generate the cells
965
+ yield {
966
+ type: "item",
967
+ value: child
968
+ };
969
+ } else {
961
970
  let cells = [];
962
- (0, $1BfjW$react).Children.forEach(children, (cell)=>{
963
- cells.push({
971
+ let childRows = [];
972
+ (0, $1BfjW$react).Children.forEach(children, (node)=>{
973
+ if (node.type === $70d70eb16ea48428$var$Row) {
974
+ if (cells.length < context.columns.length) throw new Error("All of a Row's child Cells must be positioned before any child Rows.");
975
+ childRows.push({
976
+ type: "item",
977
+ element: node
978
+ });
979
+ } else cells.push({
964
980
  type: "cell",
965
- element: cell
981
+ element: node
966
982
  });
967
983
  });
968
984
  if (cells.length !== context.columns.length) throw new Error(`Cell count must match column count. Found ${cells.length} cells and ${context.columns.length} columns.`);
969
985
  yield* cells;
986
+ yield* childRows;
970
987
  }
971
988
  },
972
989
  shouldInvalidate (newContext) {
@@ -1017,7 +1034,200 @@ let $941d1d9a6a28982a$export$f6f0c3fe4ec306ea = $941d1d9a6a28982a$var$Cell;
1017
1034
 
1018
1035
 
1019
1036
 
1037
+ /*
1038
+ * Copyright 2023 Adobe. All rights reserved.
1039
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1040
+ * you may not use this file except in compliance with the License. You may obtain a copy
1041
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1042
+ *
1043
+ * Unless required by applicable law or agreed to in writing, software distributed under
1044
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1045
+ * OF ANY KIND, either express or implied. See the License for the specific language
1046
+ * governing permissions and limitations under the License.
1047
+ */
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+ function $ee65a0057fd99531$export$34dfa8a1622185a4(props) {
1054
+ let { selectionMode: selectionMode = "none" , showSelectionCheckboxes: showSelectionCheckboxes , showDragButtons: showDragButtons , UNSTABLE_expandedKeys: propExpandedKeys , UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys , UNSTABLE_onExpandedChange: UNSTABLE_onExpandedChange , children: children } = props;
1055
+ if (!(0, $1BfjW$tableNestedRows)()) throw new Error("Feature flag for table nested rows must be enabled to use useTreeGridState.");
1056
+ let [expandedKeys, setExpandedKeys] = (0, $1BfjW$useControlledState)(propExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propExpandedKeys) : undefined, propDefaultExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propDefaultExpandedKeys) : new Set(), UNSTABLE_onExpandedChange);
1057
+ let context = (0, $1BfjW$useMemo)(()=>({
1058
+ showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
1059
+ showDragButtons: showDragButtons,
1060
+ selectionMode: selectionMode,
1061
+ columns: []
1062
+ }), [
1063
+ children,
1064
+ showSelectionCheckboxes,
1065
+ selectionMode,
1066
+ showDragButtons
1067
+ ]);
1068
+ let builder = (0, $1BfjW$useMemo)(()=>new (0, $1BfjW$CollectionBuilder)(), []);
1069
+ let nodes = (0, $1BfjW$useMemo)(()=>builder.build({
1070
+ children: children
1071
+ }, context), [
1072
+ builder,
1073
+ children,
1074
+ context
1075
+ ]);
1076
+ let treeGridCollection = (0, $1BfjW$useMemo)(()=>{
1077
+ return $ee65a0057fd99531$var$generateTreeGridCollection(nodes, {
1078
+ showSelectionCheckboxes: showSelectionCheckboxes,
1079
+ showDragButtons: showDragButtons,
1080
+ expandedKeys: expandedKeys
1081
+ });
1082
+ }, [
1083
+ nodes,
1084
+ showSelectionCheckboxes,
1085
+ showDragButtons,
1086
+ expandedKeys
1087
+ ]);
1088
+ let onToggle = (key)=>{
1089
+ setExpandedKeys($ee65a0057fd99531$var$toggleKey(expandedKeys, key, treeGridCollection));
1090
+ };
1091
+ let collection = (0, $1BfjW$useMemo)(()=>{
1092
+ return new (0, $788781baa30117fa$export$596e1b2e2cf93690)(treeGridCollection.tableNodes, null, context);
1093
+ }, [
1094
+ context,
1095
+ treeGridCollection.tableNodes
1096
+ ]);
1097
+ let tableState = (0, $4a0dd036d492cee4$export$907bcc6c48325fd6)({
1098
+ ...props,
1099
+ collection: collection
1100
+ });
1101
+ return {
1102
+ ...tableState,
1103
+ keyMap: treeGridCollection.keyMap,
1104
+ userColumnCount: treeGridCollection.userColumnCount,
1105
+ expandedKeys: expandedKeys,
1106
+ toggleKey: onToggle
1107
+ };
1108
+ }
1109
+ function $ee65a0057fd99531$var$toggleKey(currentExpandedKeys, key, collection) {
1110
+ let updatedExpandedKeys;
1111
+ if (currentExpandedKeys === "all") {
1112
+ updatedExpandedKeys = new Set(collection.flattenedRows.filter((row)=>row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map((row)=>row.key));
1113
+ updatedExpandedKeys.delete(key);
1114
+ } else {
1115
+ updatedExpandedKeys = new Set(currentExpandedKeys);
1116
+ if (updatedExpandedKeys.has(key)) updatedExpandedKeys.delete(key);
1117
+ else updatedExpandedKeys.add(key);
1118
+ }
1119
+ return updatedExpandedKeys;
1120
+ }
1121
+ function $ee65a0057fd99531$var$convertExpanded(expanded) {
1122
+ if (!expanded) return new Set();
1123
+ return expanded === "all" ? "all" : new Set(expanded);
1124
+ }
1125
+ function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
1126
+ let { expandedKeys: expandedKeys = new Set() } = opts;
1127
+ let body;
1128
+ let flattenedRows = [];
1129
+ let columnCount = 0;
1130
+ let userColumnCount = 0;
1131
+ let originalColumns = [];
1132
+ let keyMap = new Map();
1133
+ if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) columnCount++;
1134
+ if (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) columnCount++;
1135
+ let topLevelRows = [];
1136
+ let visit = (node)=>{
1137
+ switch(node.type){
1138
+ case "body":
1139
+ body = node;
1140
+ keyMap.set(body.key, body);
1141
+ break;
1142
+ case "column":
1143
+ if (!node.hasChildNodes) userColumnCount++;
1144
+ break;
1145
+ case "item":
1146
+ topLevelRows.push(node);
1147
+ return;
1148
+ }
1149
+ for (let child of node.childNodes)visit(child);
1150
+ };
1151
+ for (let node of nodes){
1152
+ if (node.type === "column") originalColumns.push(node);
1153
+ visit(node);
1154
+ }
1155
+ columnCount += userColumnCount;
1156
+ // 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
1157
+ let globalRowCount = 0;
1158
+ let visitNode = (node, i)=>{
1159
+ // Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided
1160
+ // to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure
1161
+ // values automatically calculated via CollectionBuilder
1162
+ if (node.type === "item") {
1163
+ let childNodes = [];
1164
+ for (let child of node.childNodes)if (child.type === "cell") {
1165
+ let cellClone = {
1166
+ ...child
1167
+ };
1168
+ if (cellClone.index + 1 === columnCount) cellClone.nextKey = null;
1169
+ childNodes.push({
1170
+ ...cellClone
1171
+ });
1172
+ }
1173
+ let clone = {
1174
+ ...node,
1175
+ childNodes: childNodes,
1176
+ parentKey: body.key,
1177
+ level: 1,
1178
+ index: globalRowCount++
1179
+ };
1180
+ flattenedRows.push(clone);
1181
+ }
1182
+ let newProps = {};
1183
+ // Assign indexOfType to cells and rows for aria-posinset
1184
+ if (node.type !== "placeholder" && node.type !== "column") newProps["indexOfType"] = i;
1185
+ // Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes
1186
+ // via .childNodes returns the same object as the one found via keyMap look up
1187
+ Object.assign(node, newProps);
1188
+ keyMap.set(node.key, node);
1189
+ let lastNode;
1190
+ let rowIndex = 0;
1191
+ for (let child of node.childNodes)if (!(child.type === "item" && expandedKeys !== "all" && !expandedKeys.has(node.key))) {
1192
+ 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
1193
+ child.parentKey = node.key;
1194
+ if (lastNode) {
1195
+ lastNode.nextKey = child.key;
1196
+ child.prevKey = lastNode.key;
1197
+ } else child.prevKey = null;
1198
+ if (child.type === "item") visitNode(child, rowIndex++);
1199
+ else // We enforce that the cells come before rows so can just reuse cell index
1200
+ visitNode(child, child.index);
1201
+ lastNode = child;
1202
+ }
1203
+ if (lastNode) lastNode.nextKey = null;
1204
+ };
1205
+ let last;
1206
+ topLevelRows.forEach((node, i)=>{
1207
+ visitNode(node, i);
1208
+ if (last) {
1209
+ last.nextKey = node.key;
1210
+ node.prevKey = last.key;
1211
+ } else node.prevKey = null;
1212
+ last = node;
1213
+ });
1214
+ if (last) last.nextKey = null;
1215
+ return {
1216
+ keyMap: keyMap,
1217
+ userColumnCount: userColumnCount,
1218
+ flattenedRows: flattenedRows,
1219
+ tableNodes: [
1220
+ ...originalColumns,
1221
+ {
1222
+ ...body,
1223
+ childNodes: flattenedRows
1224
+ }
1225
+ ]
1226
+ };
1227
+ }
1228
+
1229
+
1020
1230
 
1021
1231
 
1022
- export {$292bc4e09cd0eb62$export$cb895dcf85db1319 as useTableColumnResizeState, $4a0dd036d492cee4$export$907bcc6c48325fd6 as useTableState, $312ae3b56a94a86e$export$f850895b287ef28e as TableHeader, $4ae5314bf50db1a3$export$76ccd210b9029917 as TableBody, $1cd244557c2f97d5$export$816b5d811295e6bc as Column, $70d70eb16ea48428$export$b59bdbef9ce70de2 as Row, $941d1d9a6a28982a$export$f6f0c3fe4ec306ea as Cell, $6555104ff085bef4$re_export$Section as Section, $788781baa30117fa$export$596e1b2e2cf93690 as TableCollection, $788781baa30117fa$export$7c127db850d4e81e as buildHeaderRows, $a9e7ae544a4e41dd$export$7ff77a162970b30e as TableColumnLayout};
1232
+ export {$292bc4e09cd0eb62$export$cb895dcf85db1319 as useTableColumnResizeState, $4a0dd036d492cee4$export$907bcc6c48325fd6 as useTableState, $312ae3b56a94a86e$export$f850895b287ef28e as TableHeader, $4ae5314bf50db1a3$export$76ccd210b9029917 as TableBody, $1cd244557c2f97d5$export$816b5d811295e6bc as Column, $70d70eb16ea48428$export$b59bdbef9ce70de2 as Row, $941d1d9a6a28982a$export$f6f0c3fe4ec306ea as Cell, $6555104ff085bef4$re_export$Section as Section, $788781baa30117fa$export$596e1b2e2cf93690 as TableCollection, $788781baa30117fa$export$7c127db850d4e81e as buildHeaderRows, $a9e7ae544a4e41dd$export$7ff77a162970b30e as TableColumnLayout, $ee65a0057fd99531$export$34dfa8a1622185a4 as UNSTABLE_useTreeGridState};
1023
1233
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,6 +1,8 @@
1
1
  var $56JBj$reactstatelycollections = require("@react-stately/collections");
2
2
  var $56JBj$react = require("react");
3
3
  var $56JBj$reactstatelygrid = require("@react-stately/grid");
4
+ var $56JBj$reactstatelyflags = require("@react-stately/flags");
5
+ var $56JBj$reactstatelyutils = require("@react-stately/utils");
4
6
 
5
7
  function $parcel$export(e, n, v, s) {
6
8
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
@@ -20,6 +22,7 @@ $parcel$export(module.exports, "Section", () => $56JBj$reactstatelycollections.S
20
22
  $parcel$export(module.exports, "TableCollection", () => $7f5a58334d8866a5$export$596e1b2e2cf93690);
21
23
  $parcel$export(module.exports, "buildHeaderRows", () => $7f5a58334d8866a5$export$7c127db850d4e81e);
22
24
  $parcel$export(module.exports, "TableColumnLayout", () => $2240a72410c17d51$export$7ff77a162970b30e);
25
+ $parcel$export(module.exports, "UNSTABLE_useTreeGridState", () => $ed4e0b68b470dcfd$export$34dfa8a1622185a4);
23
26
  /*
24
27
  * Copyright 2020 Adobe. All rights reserved.
25
28
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -947,7 +950,7 @@ function $9ec6912e32cc0d81$var$Row(props) {
947
950
  return null;
948
951
  }
949
952
  $9ec6912e32cc0d81$var$Row.getCollectionNode = function* getCollectionNode(props, context) {
950
- let { children: children , textValue: textValue } = props;
953
+ let { children: children , textValue: textValue , UNSTABLE_childItems: UNSTABLE_childItems } = props;
951
954
  yield {
952
955
  type: "item",
953
956
  props: props,
@@ -970,21 +973,36 @@ $9ec6912e32cc0d81$var$Row.getCollectionNode = function* getCollectionNode(props,
970
973
  isSelectionCell: true
971
974
  }
972
975
  };
973
- if (typeof children === "function") for (let column of context.columns)yield {
974
- type: "cell",
975
- element: children(column.key),
976
- key: column.key // this is combined with the row key by CollectionBuilder
977
- };
978
- else {
976
+ if (typeof children === "function") {
977
+ for (let column of context.columns)yield {
978
+ type: "cell",
979
+ element: children(column.key),
980
+ key: column.key // this is combined with the row key by CollectionBuilder
981
+ };
982
+ if (UNSTABLE_childItems) for (let child of UNSTABLE_childItems)// Note: in order to reuse the render function of TableBody for our child rows, we just need to yield a type and a value here. CollectionBuilder will then look up
983
+ // the parent renderer and use that to build the full node of this child row, using the value provided here to generate the cells
984
+ yield {
985
+ type: "item",
986
+ value: child
987
+ };
988
+ } else {
979
989
  let cells = [];
980
- (0, ($parcel$interopDefault($56JBj$react))).Children.forEach(children, (cell)=>{
981
- cells.push({
990
+ let childRows = [];
991
+ (0, ($parcel$interopDefault($56JBj$react))).Children.forEach(children, (node)=>{
992
+ if (node.type === $9ec6912e32cc0d81$var$Row) {
993
+ if (cells.length < context.columns.length) throw new Error("All of a Row's child Cells must be positioned before any child Rows.");
994
+ childRows.push({
995
+ type: "item",
996
+ element: node
997
+ });
998
+ } else cells.push({
982
999
  type: "cell",
983
- element: cell
1000
+ element: node
984
1001
  });
985
1002
  });
986
1003
  if (cells.length !== context.columns.length) throw new Error(`Cell count must match column count. Found ${cells.length} cells and ${context.columns.length} columns.`);
987
1004
  yield* cells;
1005
+ yield* childRows;
988
1006
  }
989
1007
  },
990
1008
  shouldInvalidate (newContext) {
@@ -1035,6 +1053,199 @@ let $ad4ab0a21c733e1f$export$f6f0c3fe4ec306ea = $ad4ab0a21c733e1f$var$Cell;
1035
1053
 
1036
1054
 
1037
1055
 
1056
+ /*
1057
+ * Copyright 2023 Adobe. All rights reserved.
1058
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1059
+ * you may not use this file except in compliance with the License. You may obtain a copy
1060
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1061
+ *
1062
+ * Unless required by applicable law or agreed to in writing, software distributed under
1063
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1064
+ * OF ANY KIND, either express or implied. See the License for the specific language
1065
+ * governing permissions and limitations under the License.
1066
+ */
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+ function $ed4e0b68b470dcfd$export$34dfa8a1622185a4(props) {
1073
+ let { selectionMode: selectionMode = "none" , showSelectionCheckboxes: showSelectionCheckboxes , showDragButtons: showDragButtons , UNSTABLE_expandedKeys: propExpandedKeys , UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys , UNSTABLE_onExpandedChange: UNSTABLE_onExpandedChange , children: children } = props;
1074
+ if (!(0, $56JBj$reactstatelyflags.tableNestedRows)()) throw new Error("Feature flag for table nested rows must be enabled to use useTreeGridState.");
1075
+ let [expandedKeys, setExpandedKeys] = (0, $56JBj$reactstatelyutils.useControlledState)(propExpandedKeys ? $ed4e0b68b470dcfd$var$convertExpanded(propExpandedKeys) : undefined, propDefaultExpandedKeys ? $ed4e0b68b470dcfd$var$convertExpanded(propDefaultExpandedKeys) : new Set(), UNSTABLE_onExpandedChange);
1076
+ let context = (0, $56JBj$react.useMemo)(()=>({
1077
+ showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
1078
+ showDragButtons: showDragButtons,
1079
+ selectionMode: selectionMode,
1080
+ columns: []
1081
+ }), [
1082
+ children,
1083
+ showSelectionCheckboxes,
1084
+ selectionMode,
1085
+ showDragButtons
1086
+ ]);
1087
+ let builder = (0, $56JBj$react.useMemo)(()=>new (0, $56JBj$reactstatelycollections.CollectionBuilder)(), []);
1088
+ let nodes = (0, $56JBj$react.useMemo)(()=>builder.build({
1089
+ children: children
1090
+ }, context), [
1091
+ builder,
1092
+ children,
1093
+ context
1094
+ ]);
1095
+ let treeGridCollection = (0, $56JBj$react.useMemo)(()=>{
1096
+ return $ed4e0b68b470dcfd$var$generateTreeGridCollection(nodes, {
1097
+ showSelectionCheckboxes: showSelectionCheckboxes,
1098
+ showDragButtons: showDragButtons,
1099
+ expandedKeys: expandedKeys
1100
+ });
1101
+ }, [
1102
+ nodes,
1103
+ showSelectionCheckboxes,
1104
+ showDragButtons,
1105
+ expandedKeys
1106
+ ]);
1107
+ let onToggle = (key)=>{
1108
+ setExpandedKeys($ed4e0b68b470dcfd$var$toggleKey(expandedKeys, key, treeGridCollection));
1109
+ };
1110
+ let collection = (0, $56JBj$react.useMemo)(()=>{
1111
+ return new (0, $7f5a58334d8866a5$export$596e1b2e2cf93690)(treeGridCollection.tableNodes, null, context);
1112
+ }, [
1113
+ context,
1114
+ treeGridCollection.tableNodes
1115
+ ]);
1116
+ let tableState = (0, $e3f7784147dde23d$export$907bcc6c48325fd6)({
1117
+ ...props,
1118
+ collection: collection
1119
+ });
1120
+ return {
1121
+ ...tableState,
1122
+ keyMap: treeGridCollection.keyMap,
1123
+ userColumnCount: treeGridCollection.userColumnCount,
1124
+ expandedKeys: expandedKeys,
1125
+ toggleKey: onToggle
1126
+ };
1127
+ }
1128
+ function $ed4e0b68b470dcfd$var$toggleKey(currentExpandedKeys, key, collection) {
1129
+ let updatedExpandedKeys;
1130
+ if (currentExpandedKeys === "all") {
1131
+ updatedExpandedKeys = new Set(collection.flattenedRows.filter((row)=>row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map((row)=>row.key));
1132
+ updatedExpandedKeys.delete(key);
1133
+ } else {
1134
+ updatedExpandedKeys = new Set(currentExpandedKeys);
1135
+ if (updatedExpandedKeys.has(key)) updatedExpandedKeys.delete(key);
1136
+ else updatedExpandedKeys.add(key);
1137
+ }
1138
+ return updatedExpandedKeys;
1139
+ }
1140
+ function $ed4e0b68b470dcfd$var$convertExpanded(expanded) {
1141
+ if (!expanded) return new Set();
1142
+ return expanded === "all" ? "all" : new Set(expanded);
1143
+ }
1144
+ function $ed4e0b68b470dcfd$var$generateTreeGridCollection(nodes, opts) {
1145
+ let { expandedKeys: expandedKeys = new Set() } = opts;
1146
+ let body;
1147
+ let flattenedRows = [];
1148
+ let columnCount = 0;
1149
+ let userColumnCount = 0;
1150
+ let originalColumns = [];
1151
+ let keyMap = new Map();
1152
+ if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) columnCount++;
1153
+ if (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) columnCount++;
1154
+ let topLevelRows = [];
1155
+ let visit = (node)=>{
1156
+ switch(node.type){
1157
+ case "body":
1158
+ body = node;
1159
+ keyMap.set(body.key, body);
1160
+ break;
1161
+ case "column":
1162
+ if (!node.hasChildNodes) userColumnCount++;
1163
+ break;
1164
+ case "item":
1165
+ topLevelRows.push(node);
1166
+ return;
1167
+ }
1168
+ for (let child of node.childNodes)visit(child);
1169
+ };
1170
+ for (let node of nodes){
1171
+ if (node.type === "column") originalColumns.push(node);
1172
+ visit(node);
1173
+ }
1174
+ columnCount += userColumnCount;
1175
+ // 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
1176
+ let globalRowCount = 0;
1177
+ let visitNode = (node, i)=>{
1178
+ // Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided
1179
+ // to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure
1180
+ // values automatically calculated via CollectionBuilder
1181
+ if (node.type === "item") {
1182
+ let childNodes = [];
1183
+ for (let child of node.childNodes)if (child.type === "cell") {
1184
+ let cellClone = {
1185
+ ...child
1186
+ };
1187
+ if (cellClone.index + 1 === columnCount) cellClone.nextKey = null;
1188
+ childNodes.push({
1189
+ ...cellClone
1190
+ });
1191
+ }
1192
+ let clone = {
1193
+ ...node,
1194
+ childNodes: childNodes,
1195
+ parentKey: body.key,
1196
+ level: 1,
1197
+ index: globalRowCount++
1198
+ };
1199
+ flattenedRows.push(clone);
1200
+ }
1201
+ let newProps = {};
1202
+ // Assign indexOfType to cells and rows for aria-posinset
1203
+ if (node.type !== "placeholder" && node.type !== "column") newProps["indexOfType"] = i;
1204
+ // Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes
1205
+ // via .childNodes returns the same object as the one found via keyMap look up
1206
+ Object.assign(node, newProps);
1207
+ keyMap.set(node.key, node);
1208
+ let lastNode;
1209
+ let rowIndex = 0;
1210
+ for (let child of node.childNodes)if (!(child.type === "item" && expandedKeys !== "all" && !expandedKeys.has(node.key))) {
1211
+ 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
1212
+ child.parentKey = node.key;
1213
+ if (lastNode) {
1214
+ lastNode.nextKey = child.key;
1215
+ child.prevKey = lastNode.key;
1216
+ } else child.prevKey = null;
1217
+ if (child.type === "item") visitNode(child, rowIndex++);
1218
+ else // We enforce that the cells come before rows so can just reuse cell index
1219
+ visitNode(child, child.index);
1220
+ lastNode = child;
1221
+ }
1222
+ if (lastNode) lastNode.nextKey = null;
1223
+ };
1224
+ let last;
1225
+ topLevelRows.forEach((node, i)=>{
1226
+ visitNode(node, i);
1227
+ if (last) {
1228
+ last.nextKey = node.key;
1229
+ node.prevKey = last.key;
1230
+ } else node.prevKey = null;
1231
+ last = node;
1232
+ });
1233
+ if (last) last.nextKey = null;
1234
+ return {
1235
+ keyMap: keyMap,
1236
+ userColumnCount: userColumnCount,
1237
+ flattenedRows: flattenedRows,
1238
+ tableNodes: [
1239
+ ...originalColumns,
1240
+ {
1241
+ ...body,
1242
+ childNodes: flattenedRows
1243
+ }
1244
+ ]
1245
+ };
1246
+ }
1247
+
1248
+
1038
1249
 
1039
1250
 
1040
1251
  //# sourceMappingURL=main.js.map