@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
package/dist/module.js CHANGED
@@ -1,445 +1,14 @@
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
- import $1BfjW$react, {useState as $1BfjW$useState, useMemo as $1BfjW$useMemo, useCallback as $1BfjW$useCallback} from "react";
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";
6
-
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
- */ /*
18
- * Copyright 2022 Adobe. All rights reserved.
19
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
20
- * you may not use this file except in compliance with the License. You may obtain a copy
21
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
22
- *
23
- * Unless required by applicable law or agreed to in writing, software distributed under
24
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
25
- * OF ANY KIND, either express or implied. See the License for the specific language
26
- * governing permissions and limitations under the License.
27
- */ /*
28
- * Copyright 2022 Adobe. All rights reserved.
29
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
30
- * you may not use this file except in compliance with the License. You may obtain a copy
31
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
32
- *
33
- * Unless required by applicable law or agreed to in writing, software distributed under
34
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
35
- * OF ANY KIND, either express or implied. See the License for the specific language
36
- * governing permissions and limitations under the License.
37
- */ /*
38
- * Copyright 2022 Adobe. All rights reserved.
39
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
40
- * you may not use this file except in compliance with the License. You may obtain a copy
41
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
42
- *
43
- * Unless required by applicable law or agreed to in writing, software distributed under
44
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
45
- * OF ANY KIND, either express or implied. See the License for the specific language
46
- * governing permissions and limitations under the License.
47
- */ function $6818b1c4fc67028d$export$1994a077b98ee0d5(width) {
48
- return width != null && (!isNaN(width) || String(width).match(/^(\d+)(?=%$)/) !== null);
49
- }
50
- function $6818b1c4fc67028d$export$9078bad4c3934604(width) {
51
- if (!width) return 1;
52
- let match = width.match(/^(.+)(?=fr$)/);
53
- // if width is the incorrect format, just default it to a 1fr
54
- if (!match) {
55
- console.warn(`width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`, "defaulting to '1fr'");
56
- return 1;
57
- }
58
- return parseFloat(match[0]);
59
- }
60
- function $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, tableWidth) {
61
- if (typeof width === "string") {
62
- let match = width.match(/^(\d+)(?=%$)/);
63
- if (!match) throw new Error("Only percentages or numbers are supported for static column widths");
64
- return tableWidth * (parseFloat(match[0]) / 100);
65
- }
66
- return width;
67
- }
68
- function $6818b1c4fc67028d$export$59185c62a7544aa0(maxWidth, tableWidth) {
69
- return maxWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
70
- }
71
- function $6818b1c4fc67028d$export$f556054ce4358701(minWidth, tableWidth) {
72
- return minWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
73
- }
74
- function $6818b1c4fc67028d$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
75
- let hasNonFrozenItems = false;
76
- let flexItems = columns.map((column, index)=>{
77
- var _column_width, _ref, _ref1;
78
- let width = changedColumns.get(column.key) != null ? changedColumns.get(column.key) : (_ref1 = (_ref = (_column_width = column.width) !== null && _column_width !== void 0 ? _column_width : column.defaultWidth) !== null && _ref !== void 0 ? _ref : getDefaultWidth === null || getDefaultWidth === void 0 ? void 0 : getDefaultWidth(index)) !== null && _ref1 !== void 0 ? _ref1 : "1fr";
79
- let frozen = false;
80
- let baseSize = 0;
81
- let flex = 0;
82
- let targetMainSize = null;
83
- if ($6818b1c4fc67028d$export$1994a077b98ee0d5(width)) {
84
- baseSize = $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, availableWidth);
85
- frozen = true;
86
- } else {
87
- flex = $6818b1c4fc67028d$export$9078bad4c3934604(width);
88
- if (flex <= 0) frozen = true;
89
- }
90
- var _column_minWidth, _ref2;
91
- let min = $6818b1c4fc67028d$export$f556054ce4358701((_ref2 = (_column_minWidth = column.minWidth) !== null && _column_minWidth !== void 0 ? _column_minWidth : getDefaultMinWidth === null || getDefaultMinWidth === void 0 ? void 0 : getDefaultMinWidth(index)) !== null && _ref2 !== void 0 ? _ref2 : 0, availableWidth);
92
- let max = $6818b1c4fc67028d$export$59185c62a7544aa0(column.maxWidth, availableWidth);
93
- let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
94
- // 9.7.1
95
- // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.
96
- // 9.7.2
97
- if (frozen) targetMainSize = hypotheticalMainSize;
98
- else if (baseSize > hypotheticalMainSize) {
99
- frozen = true;
100
- targetMainSize = hypotheticalMainSize;
101
- }
102
- // 9.7.3
103
- if (!frozen) hasNonFrozenItems = true;
104
- return {
105
- frozen: frozen,
106
- baseSize: baseSize,
107
- hypotheticalMainSize: hypotheticalMainSize,
108
- min: min,
109
- max: max,
110
- flex: flex,
111
- targetMainSize: targetMainSize,
112
- violation: 0
113
- };
114
- });
115
- // 9.7.4
116
- // 9.7.4.a
117
- while(hasNonFrozenItems){
118
- // 9.7.4.b
119
- /**
120
- * Calculate the remaining free space as for initial free space,
121
- * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is
122
- * less than one, multiply the initial free space by this sum (of flex factors).
123
- * If the magnitude of this value is less than the magnitude of
124
- * the remaining free space, use this as the remaining free space.
125
- */ let usedWidth = 0;
126
- let flexFactors = 0;
127
- flexItems.forEach((item)=>{
128
- if (item.frozen) usedWidth += item.targetMainSize;
129
- else {
130
- usedWidth += item.baseSize;
131
- flexFactors += item.flex;
132
- }
133
- });
134
- let remainingFreeSpace = availableWidth - usedWidth;
135
- // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0
136
- // so no need to check for flexFactors < 1
137
- // 9.7.4.c
138
- /**
139
- * If the remaining free space is zero
140
- * - Do nothing.
141
- * Else // remember, we're always in grow mode
142
- * - Find the ratio of the item’s flex grow factor to the
143
- * sum of the flex grow factors of all unfrozen items on
144
- * the line. Set the item’s target main size to its flex
145
- * base size plus a fraction of the remaining free space
146
- * proportional to the ratio.
147
- */ if (remainingFreeSpace > 0) flexItems.forEach((item)=>{
148
- if (!item.frozen) {
149
- let ratio = item.flex / flexFactors;
150
- item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
151
- }
152
- });
153
- // 9.7.4.d
154
- /**
155
- * Fix min/max violations. Clamp each non-frozen item’s
156
- * target main size by its used min and max main sizes
157
- * and floor its content-box size at zero. If the item’s
158
- * target main size was made smaller by this, it’s a max
159
- * violation. If the item’s target main size was made
160
- * larger by this, it’s a min violation.
161
- */ let totalViolation = 0;
162
- flexItems.forEach((item)=>{
163
- item.violation = 0;
164
- if (!item.frozen) {
165
- let { min: min, max: max, targetMainSize: targetMainSize } = item;
166
- item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
167
- item.violation = item.targetMainSize - targetMainSize;
168
- totalViolation += item.violation;
169
- }
170
- });
171
- // 9.7.4.e
172
- /**
173
- * Freeze over-flexed items. The total violation is the
174
- * sum of the adjustments from the previous step
175
- * ∑(clamped size - unclamped size). If the total violation is:
176
- * Zero
177
- * - Freeze all items.
178
- *
179
- * Positive
180
- * - Freeze all the items with min violations.
181
- *
182
- * Negative
183
- * - Freeze all the items with max violations.
184
- */ hasNonFrozenItems = false;
185
- flexItems.forEach((item)=>{
186
- if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
187
- else if (!item.frozen) hasNonFrozenItems = true;
188
- });
189
- }
190
- return $6818b1c4fc67028d$var$cascadeRounding(flexItems);
191
- }
192
- function $6818b1c4fc67028d$var$cascadeRounding(flexItems) {
193
- /*
194
- Given an array of floats that sum to an integer, this rounds the floats
195
- and returns an array of integers with the same sum.
196
- */ let fpTotal = 0;
197
- let intTotal = 0;
198
- let roundedArray = [];
199
- flexItems.forEach(function(item) {
200
- let float = item.targetMainSize;
201
- let integer = Math.round(float + fpTotal) - intTotal;
202
- fpTotal += float;
203
- intTotal += integer;
204
- roundedArray.push(integer);
205
- });
206
- return roundedArray;
207
- }
208
-
209
-
210
- class $a9e7ae544a4e41dd$export$7ff77a162970b30e {
211
- /** Takes an array of columns and splits it into 2 maps of columns with controlled and columns with uncontrolled widths. */ splitColumnsIntoControlledAndUncontrolled(columns) {
212
- return columns.reduce((acc, col)=>{
213
- if (col.props.width != null) acc[0].set(col.key, col);
214
- else acc[1].set(col.key, col);
215
- return acc;
216
- }, [
217
- new Map(),
218
- new Map()
219
- ]);
220
- }
221
- /** Takes uncontrolled and controlled widths and joins them into a single Map. */ recombineColumns(columns, uncontrolledWidths, uncontrolledColumns, controlledColumns) {
222
- return new Map(columns.map((col)=>{
223
- if (uncontrolledColumns.has(col.key)) return [
224
- col.key,
225
- uncontrolledWidths.get(col.key)
226
- ];
227
- else return [
228
- col.key,
229
- controlledColumns.get(col.key).props.width
230
- ];
231
- }));
232
- }
233
- /** Used to make an initial Map of the uncontrolled widths based on default widths. */ getInitialUncontrolledWidths(uncontrolledColumns) {
234
- return new Map(Array.from(uncontrolledColumns).map(([key, col])=>{
235
- var _this_getDefaultWidth, _this;
236
- var _col_props_defaultWidth, _ref;
237
- return [
238
- key,
239
- (_ref = (_col_props_defaultWidth = col.props.defaultWidth) !== null && _col_props_defaultWidth !== void 0 ? _col_props_defaultWidth : (_this_getDefaultWidth = (_this = this).getDefaultWidth) === null || _this_getDefaultWidth === void 0 ? void 0 : _this_getDefaultWidth.call(_this, col)) !== null && _ref !== void 0 ? _ref : "1fr"
240
- ];
241
- }));
242
- }
243
- getColumnWidth(key) {
244
- var _this_columnWidths_get;
245
- return (_this_columnWidths_get = this.columnWidths.get(key)) !== null && _this_columnWidths_get !== void 0 ? _this_columnWidths_get : 0;
246
- }
247
- getColumnMinWidth(key) {
248
- var _this_columnMinWidths_get;
249
- return (_this_columnMinWidths_get = this.columnMinWidths.get(key)) !== null && _this_columnMinWidths_get !== void 0 ? _this_columnMinWidths_get : 0;
250
- }
251
- getColumnMaxWidth(key) {
252
- var _this_columnMaxWidths_get;
253
- return (_this_columnMaxWidths_get = this.columnMaxWidths.get(key)) !== null && _this_columnMaxWidths_get !== void 0 ? _this_columnMaxWidths_get : 0;
254
- }
255
- resizeColumnWidth(tableWidth, collection, controlledWidths, uncontrolledWidths, col = null, width) {
256
- let prevColumnWidths = this.columnWidths;
257
- // resizing a column
258
- let resizeIndex = Infinity;
259
- let resizingChanged = new Map([
260
- ...controlledWidths,
261
- ...uncontrolledWidths
262
- ]);
263
- let percentKeys = new Map();
264
- let frKeysToTheRight = new Map();
265
- let minWidths = new Map();
266
- // freeze columns to the left to their previous pixel value
267
- collection.columns.forEach((column, i)=>{
268
- var _column_props_width_endsWith, _column_props_width;
269
- let frKey;
270
- let frValue;
271
- minWidths.set(column.key, this.getDefaultMinWidth(collection.columns[i]));
272
- if (col !== column.key && !column.props.width && !(0, $6818b1c4fc67028d$export$1994a077b98ee0d5)(uncontrolledWidths.get(column.key))) {
273
- // uncontrolled don't have props.width for us, so instead get from our state
274
- frKey = column.key;
275
- frValue = (0, $6818b1c4fc67028d$export$9078bad4c3934604)(uncontrolledWidths.get(column.key));
276
- } else if (col !== column.key && !(0, $6818b1c4fc67028d$export$1994a077b98ee0d5)(column.props.width) && !uncontrolledWidths.get(column.key)) {
277
- // controlledWidths will be the same in the collection
278
- frKey = column.key;
279
- frValue = (0, $6818b1c4fc67028d$export$9078bad4c3934604)(column.props.width);
280
- } else if (col !== column.key && ((_column_props_width = column.props.width) === null || _column_props_width === void 0 ? void 0 : (_column_props_width_endsWith = _column_props_width.endsWith) === null || _column_props_width_endsWith === void 0 ? void 0 : _column_props_width_endsWith.call(_column_props_width, "%"))) percentKeys.set(column.key, column.props.width);
281
- // don't freeze columns to the right of the resizing one
282
- if (resizeIndex < i) {
283
- if (frKey) frKeysToTheRight.set(frKey, frValue);
284
- return;
285
- }
286
- // we already know the new size of the resizing column
287
- if (column.key === col) {
288
- resizeIndex = i;
289
- resizingChanged.set(column.key, Math.floor(width));
290
- return;
291
- }
292
- // freeze column to previous value
293
- resizingChanged.set(column.key, prevColumnWidths.get(column.key));
294
- });
295
- // predict pixels sizes for all columns based on resize
296
- let columnWidths = (0, $6818b1c4fc67028d$export$55d50dc687385491)(tableWidth, collection.columns.map((col)=>({
297
- ...col.props,
298
- key: col.key
299
- })), resizingChanged, (i)=>this.getDefaultWidth(collection.columns[i]), (i)=>this.getDefaultMinWidth(collection.columns[i]));
300
- // set all new column widths for onResize event
301
- // columns going in will be the same order as the columns coming out
302
- let newWidths = new Map();
303
- // set all column widths based on calculateColumnSize
304
- columnWidths.forEach((width, index)=>{
305
- let key = collection.columns[index].key;
306
- newWidths.set(key, width);
307
- });
308
- // add FR's back as they were to columns to the right
309
- Array.from(frKeysToTheRight).forEach(([key])=>{
310
- newWidths.set(key, `${frKeysToTheRight.get(key)}fr`);
311
- });
312
- // put back in percents
313
- Array.from(percentKeys).forEach(([key, width])=>{
314
- // resizing locks a column to a px width
315
- if (key === col) return;
316
- newWidths.set(key, width);
317
- });
318
- return newWidths;
319
- }
320
- buildColumnWidths(tableWidth, collection, widths) {
321
- this.columnWidths = new Map();
322
- this.columnMinWidths = new Map();
323
- this.columnMaxWidths = new Map();
324
- // initial layout or table/window resizing
325
- let columnWidths = (0, $6818b1c4fc67028d$export$55d50dc687385491)(tableWidth, collection.columns.map((col)=>({
326
- ...col.props,
327
- key: col.key
328
- })), widths, (i)=>this.getDefaultWidth(collection.columns[i]), (i)=>this.getDefaultMinWidth(collection.columns[i]));
329
- // columns going in will be the same order as the columns coming out
330
- columnWidths.forEach((width, index)=>{
331
- let key = collection.columns[index].key;
332
- let column = collection.columns[index];
333
- this.columnWidths.set(key, width);
334
- var _column_props_minWidth;
335
- this.columnMinWidths.set(key, (0, $6818b1c4fc67028d$export$f556054ce4358701)((_column_props_minWidth = column.props.minWidth) !== null && _column_props_minWidth !== void 0 ? _column_props_minWidth : this.getDefaultMinWidth(column), tableWidth));
336
- this.columnMaxWidths.set(key, (0, $6818b1c4fc67028d$export$59185c62a7544aa0)(column.props.maxWidth, tableWidth));
337
- });
338
- return this.columnWidths;
339
- }
340
- constructor(options){
341
- this.columnWidths = new Map();
342
- this.columnMinWidths = new Map();
343
- this.columnMaxWidths = new Map();
344
- var _options_getDefaultWidth;
345
- this.getDefaultWidth = (_options_getDefaultWidth = options === null || options === void 0 ? void 0 : options.getDefaultWidth) !== null && _options_getDefaultWidth !== void 0 ? _options_getDefaultWidth : ()=>"1fr";
346
- var _options_getDefaultMinWidth;
347
- this.getDefaultMinWidth = (_options_getDefaultMinWidth = options === null || options === void 0 ? void 0 : options.getDefaultMinWidth) !== null && _options_getDefaultMinWidth !== void 0 ? _options_getDefaultMinWidth : ()=>75;
348
- }
349
- }
350
-
351
-
352
-
353
- function $292bc4e09cd0eb62$export$cb895dcf85db1319(props, state) {
354
- let { getDefaultWidth: getDefaultWidth, getDefaultMinWidth: getDefaultMinWidth, tableWidth: tableWidth = 0 } = props;
355
- let [resizingColumn, setResizingColumn] = (0, $1BfjW$useState)(null);
356
- let columnLayout = (0, $1BfjW$useMemo)(()=>new (0, $a9e7ae544a4e41dd$export$7ff77a162970b30e)({
357
- getDefaultWidth: getDefaultWidth,
358
- getDefaultMinWidth: getDefaultMinWidth
359
- }), [
360
- getDefaultWidth,
361
- getDefaultMinWidth
362
- ]);
363
- let [controlledColumns, uncontrolledColumns] = (0, $1BfjW$useMemo)(()=>columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns), [
364
- state.collection.columns,
365
- columnLayout
366
- ]);
367
- // uncontrolled column widths
368
- let [uncontrolledWidths, setUncontrolledWidths] = (0, $1BfjW$useState)(()=>columnLayout.getInitialUncontrolledWidths(uncontrolledColumns));
369
- // Update uncontrolled widths if the columns changed.
370
- let [lastColumns, setLastColumns] = (0, $1BfjW$useState)(state.collection.columns);
371
- if (state.collection.columns !== lastColumns) {
372
- if (state.collection.columns.length !== lastColumns.length || state.collection.columns.some((c, i)=>c.key !== lastColumns[i].key)) {
373
- let newUncontrolledWidths = columnLayout.getInitialUncontrolledWidths(uncontrolledColumns);
374
- setUncontrolledWidths(newUncontrolledWidths);
375
- }
376
- setLastColumns(state.collection.columns);
377
- }
378
- // combine columns back into one map that maintains same order as the columns
379
- let colWidths = (0, $1BfjW$useMemo)(()=>columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns), [
380
- state.collection.columns,
381
- uncontrolledWidths,
382
- uncontrolledColumns,
383
- controlledColumns,
384
- columnLayout
385
- ]);
386
- let startResize = (0, $1BfjW$useCallback)((key)=>{
387
- setResizingColumn(key);
388
- }, [
389
- setResizingColumn
390
- ]);
391
- let updateResizedColumns = (0, $1BfjW$useCallback)((key, width)=>{
392
- let newControlled = new Map(Array.from(controlledColumns).map(([key, entry])=>[
393
- key,
394
- entry.props.width
395
- ]));
396
- let newSizes = columnLayout.resizeColumnWidth(tableWidth, state.collection, newControlled, uncontrolledWidths, key, width);
397
- let map = new Map(Array.from(uncontrolledColumns).map(([key])=>[
398
- key,
399
- newSizes.get(key)
400
- ]));
401
- map.set(key, width);
402
- setUncontrolledWidths(map);
403
- return newSizes;
404
- }, [
405
- controlledColumns,
406
- uncontrolledColumns,
407
- setUncontrolledWidths,
408
- tableWidth,
409
- columnLayout,
410
- state.collection,
411
- uncontrolledWidths
412
- ]);
413
- let endResize = (0, $1BfjW$useCallback)(()=>{
414
- setResizingColumn(null);
415
- }, [
416
- setResizingColumn
417
- ]);
418
- (0, $1BfjW$useMemo)(()=>columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths), [
419
- tableWidth,
420
- state.collection,
421
- colWidths,
422
- columnLayout
423
- ]);
424
- return (0, $1BfjW$useMemo)(()=>({
425
- resizingColumn: resizingColumn,
426
- updateResizedColumns: updateResizedColumns,
427
- startResize: startResize,
428
- endResize: endResize,
429
- getColumnWidth: (key)=>columnLayout.getColumnWidth(key),
430
- getColumnMinWidth: (key)=>columnLayout.getColumnMinWidth(key),
431
- getColumnMaxWidth: (key)=>columnLayout.getColumnMaxWidth(key),
432
- tableState: state
433
- }), [
434
- columnLayout,
435
- resizingColumn,
436
- updateResizedColumns,
437
- startResize,
438
- endResize,
439
- state
440
- ]);
441
- }
442
-
1
+ import {useTableColumnResizeState as $292bc4e09cd0eb62$export$cb895dcf85db1319} from "./useTableColumnResizeState.module.js";
2
+ import {useTableState as $4a0dd036d492cee4$export$907bcc6c48325fd6} from "./useTableState.module.js";
3
+ import {TableHeader as $312ae3b56a94a86e$export$f850895b287ef28e} from "./TableHeader.module.js";
4
+ import {TableBody as $4ae5314bf50db1a3$export$76ccd210b9029917} from "./TableBody.module.js";
5
+ import {Column as $1cd244557c2f97d5$export$816b5d811295e6bc} from "./Column.module.js";
6
+ import {Row as $70d70eb16ea48428$export$b59bdbef9ce70de2} from "./Row.module.js";
7
+ import {Cell as $941d1d9a6a28982a$export$f6f0c3fe4ec306ea} from "./Cell.module.js";
8
+ import {buildHeaderRows as $788781baa30117fa$export$7c127db850d4e81e, TableCollection as $788781baa30117fa$export$596e1b2e2cf93690} from "./TableCollection.module.js";
9
+ import {TableColumnLayout as $a9e7ae544a4e41dd$export$7ff77a162970b30e} from "./TableColumnLayout.module.js";
10
+ import {UNSTABLE_useTreeGridState as $ee65a0057fd99531$export$34dfa8a1622185a4} from "./useTreeGridState.module.js";
11
+ import {Section as $6555104ff085bef4$re_export$Section} from "@react-stately/collections";
443
12
 
444
13
  /*
445
14
  * Copyright 2020 Adobe. All rights reserved.
@@ -453,787 +22,13 @@ function $292bc4e09cd0eb62$export$cb895dcf85db1319(props, state) {
453
22
  * governing permissions and limitations under the License.
454
23
  */
455
24
 
456
- /*
457
- * Copyright 2020 Adobe. All rights reserved.
458
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
459
- * you may not use this file except in compliance with the License. You may obtain a copy
460
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
461
- *
462
- * Unless required by applicable law or agreed to in writing, software distributed under
463
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
464
- * OF ANY KIND, either express or implied. See the License for the specific language
465
- * governing permissions and limitations under the License.
466
- */
467
-
468
- const $788781baa30117fa$var$ROW_HEADER_COLUMN_KEY = "row-header-column-" + Math.random().toString(36).slice(2);
469
- let $788781baa30117fa$var$ROW_HEADER_COLUMN_KEY_DRAG = "row-header-column-" + Math.random().toString(36).slice(2);
470
- while($788781baa30117fa$var$ROW_HEADER_COLUMN_KEY === $788781baa30117fa$var$ROW_HEADER_COLUMN_KEY_DRAG)$788781baa30117fa$var$ROW_HEADER_COLUMN_KEY_DRAG = "row-header-column-" + Math.random().toString(36).slice(2);
471
- function $788781baa30117fa$export$7c127db850d4e81e(keyMap, columnNodes) {
472
- if (columnNodes.length === 0) return [];
473
- let columns = [];
474
- let seen = new Map();
475
- for (let column of columnNodes){
476
- let parentKey = column.parentKey;
477
- let col = [
478
- column
479
- ];
480
- while(parentKey){
481
- let parent = keyMap.get(parentKey);
482
- if (!parent) break;
483
- // If we've already seen this parent, than it is shared
484
- // with a previous column. If the current column is taller
485
- // than the previous column, than we need to shift the parent
486
- // in the previous column so it's level with the current column.
487
- if (seen.has(parent)) {
488
- parent.colspan++;
489
- let { column: column, index: index } = seen.get(parent);
490
- if (index > col.length) break;
491
- for(let i = index; i < col.length; i++)column.splice(i, 0, null);
492
- // Adjust shifted indices
493
- for(let i = col.length; i < column.length; i++)// eslint-disable-next-line max-depth
494
- if (column[i] && seen.has(column[i])) seen.get(column[i]).index = i;
495
- } else {
496
- parent.colspan = 1;
497
- col.push(parent);
498
- seen.set(parent, {
499
- column: col,
500
- index: col.length - 1
501
- });
502
- }
503
- parentKey = parent.parentKey;
504
- }
505
- columns.push(col);
506
- column.index = columns.length - 1;
507
- }
508
- let maxLength = Math.max(...columns.map((c)=>c.length));
509
- let headerRows = Array(maxLength).fill(0).map(()=>[]);
510
- // Convert columns into rows.
511
- let colIndex = 0;
512
- for (let column of columns){
513
- let i = maxLength - 1;
514
- for (let item of column){
515
- if (item) {
516
- // Fill the space up until the current column with a placeholder
517
- let row = headerRows[i];
518
- let rowLength = row.reduce((p, c)=>p + c.colspan, 0);
519
- if (rowLength < colIndex) {
520
- let placeholder = {
521
- type: "placeholder",
522
- key: "placeholder-" + item.key,
523
- colspan: colIndex - rowLength,
524
- index: rowLength,
525
- value: null,
526
- rendered: null,
527
- level: i,
528
- hasChildNodes: false,
529
- childNodes: [],
530
- textValue: null
531
- };
532
- // eslint-disable-next-line max-depth
533
- if (row.length > 0) {
534
- row[row.length - 1].nextKey = placeholder.key;
535
- placeholder.prevKey = row[row.length - 1].key;
536
- }
537
- row.push(placeholder);
538
- }
539
- if (row.length > 0) {
540
- row[row.length - 1].nextKey = item.key;
541
- item.prevKey = row[row.length - 1].key;
542
- }
543
- item.level = i;
544
- item.colIndex = colIndex;
545
- row.push(item);
546
- }
547
- i--;
548
- }
549
- colIndex++;
550
- }
551
- // Add placeholders at the end of each row that is shorter than the maximum
552
- let i = 0;
553
- for (let row of headerRows){
554
- let rowLength = row.reduce((p, c)=>p + c.colspan, 0);
555
- if (rowLength < columnNodes.length) {
556
- let placeholder = {
557
- type: "placeholder",
558
- key: "placeholder-" + row[row.length - 1].key,
559
- colspan: columnNodes.length - rowLength,
560
- index: rowLength,
561
- value: null,
562
- rendered: null,
563
- level: i,
564
- hasChildNodes: false,
565
- childNodes: [],
566
- textValue: null,
567
- prevKey: row[row.length - 1].key
568
- };
569
- row.push(placeholder);
570
- }
571
- i++;
572
- }
573
- return headerRows.map((childNodes, index)=>{
574
- let row = {
575
- type: "headerrow",
576
- key: "headerrow-" + index,
577
- index: index,
578
- value: null,
579
- rendered: null,
580
- level: 0,
581
- hasChildNodes: true,
582
- childNodes: childNodes,
583
- textValue: null
584
- };
585
- return row;
586
- });
587
- }
588
- class $788781baa30117fa$export$596e1b2e2cf93690 extends (0, $1BfjW$GridCollection) {
589
- *[Symbol.iterator]() {
590
- yield* this.body.childNodes;
591
- }
592
- get size() {
593
- return this._size;
594
- }
595
- getKeys() {
596
- return this.keyMap.keys();
597
- }
598
- getKeyBefore(key) {
599
- let node = this.keyMap.get(key);
600
- return node ? node.prevKey : null;
601
- }
602
- getKeyAfter(key) {
603
- let node = this.keyMap.get(key);
604
- return node ? node.nextKey : null;
605
- }
606
- getFirstKey() {
607
- var _getFirstItem;
608
- return (_getFirstItem = (0, $1BfjW$getFirstItem)(this.body.childNodes)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
609
- }
610
- getLastKey() {
611
- var _getLastItem;
612
- return (_getLastItem = (0, $1BfjW$getLastItem)(this.body.childNodes)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key;
613
- }
614
- getItem(key) {
615
- return this.keyMap.get(key);
616
- }
617
- at(idx) {
618
- const keys = [
619
- ...this.getKeys()
620
- ];
621
- return this.getItem(keys[idx]);
622
- }
623
- getTextValue(key) {
624
- let row = this.getItem(key);
625
- if (!row) return "";
626
- // If the row has a textValue, use that.
627
- if (row.textValue) return row.textValue;
628
- // Otherwise combine the text of each of the row header columns.
629
- let rowHeaderColumnKeys = this.rowHeaderColumnKeys;
630
- if (rowHeaderColumnKeys) {
631
- let text = [];
632
- for (let cell of row.childNodes){
633
- let column = this.columns[cell.index];
634
- if (rowHeaderColumnKeys.has(column.key) && cell.textValue) text.push(cell.textValue);
635
- if (text.length === rowHeaderColumnKeys.size) break;
636
- }
637
- return text.join(" ");
638
- }
639
- return "";
640
- }
641
- constructor(nodes, prev, opts){
642
- let rowHeaderColumnKeys = new Set();
643
- let body;
644
- let columns = [];
645
- // Add cell for selection checkboxes if needed.
646
- if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) {
647
- let rowHeaderColumn = {
648
- type: "column",
649
- key: $788781baa30117fa$var$ROW_HEADER_COLUMN_KEY,
650
- value: null,
651
- textValue: "",
652
- level: 0,
653
- index: (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) ? 1 : 0,
654
- hasChildNodes: false,
655
- rendered: null,
656
- childNodes: [],
657
- props: {
658
- isSelectionCell: true
659
- }
660
- };
661
- columns.unshift(rowHeaderColumn);
662
- }
663
- // Add cell for drag buttons if needed.
664
- if (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) {
665
- let rowHeaderColumn = {
666
- type: "column",
667
- key: $788781baa30117fa$var$ROW_HEADER_COLUMN_KEY_DRAG,
668
- value: null,
669
- textValue: "",
670
- level: 0,
671
- index: 0,
672
- hasChildNodes: false,
673
- rendered: null,
674
- childNodes: [],
675
- props: {
676
- isDragButtonCell: true
677
- }
678
- };
679
- columns.unshift(rowHeaderColumn);
680
- }
681
- let rows = [];
682
- let columnKeyMap = new Map();
683
- let visit = (node)=>{
684
- switch(node.type){
685
- case "body":
686
- body = node;
687
- break;
688
- case "column":
689
- columnKeyMap.set(node.key, node);
690
- if (!node.hasChildNodes) {
691
- columns.push(node);
692
- if (node.props.isRowHeader) rowHeaderColumnKeys.add(node.key);
693
- }
694
- break;
695
- case "item":
696
- rows.push(node);
697
- return; // do not go into childNodes
698
- }
699
- for (let child of node.childNodes)visit(child);
700
- };
701
- for (let node of nodes)visit(node);
702
- let headerRows = $788781baa30117fa$export$7c127db850d4e81e(columnKeyMap, columns);
703
- headerRows.forEach((row, i)=>rows.splice(i, 0, row));
704
- super({
705
- columnCount: columns.length,
706
- items: rows,
707
- visitNode: (node)=>{
708
- node.column = columns[node.index];
709
- return node;
710
- }
711
- });
712
- this._size = 0;
713
- this.columns = columns;
714
- this.rowHeaderColumnKeys = rowHeaderColumnKeys;
715
- this.body = body;
716
- this.headerRows = headerRows;
717
- this._size = [
718
- ...body.childNodes
719
- ].length;
720
- // Default row header column to the first one.
721
- if (this.rowHeaderColumnKeys.size === 0) this.rowHeaderColumnKeys.add(this.columns.find((column)=>{
722
- var _column_props, _column_props1;
723
- return !((_column_props = column.props) === null || _column_props === void 0 ? void 0 : _column_props.isDragButtonCell) && !((_column_props1 = column.props) === null || _column_props1 === void 0 ? void 0 : _column_props1.isSelectionCell);
724
- }).key);
725
- }
726
- }
727
-
728
-
729
25
 
730
- const $4a0dd036d492cee4$var$OPPOSITE_SORT_DIRECTION = {
731
- ascending: "descending",
732
- descending: "ascending"
733
- };
734
- function $4a0dd036d492cee4$export$907bcc6c48325fd6(props) {
735
- let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = (0, $1BfjW$useState)(false);
736
- let { selectionMode: selectionMode = "none", showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons } = props;
737
- let context = (0, $1BfjW$useMemo)(()=>({
738
- showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
739
- showDragButtons: showDragButtons,
740
- selectionMode: selectionMode,
741
- columns: []
742
- }), [
743
- props.children,
744
- showSelectionCheckboxes,
745
- selectionMode,
746
- showDragButtons
747
- ]);
748
- let collection = (0, $1BfjW$useCollection)(props, (0, $1BfjW$useCallback)((nodes)=>new (0, $788781baa30117fa$export$596e1b2e2cf93690)(nodes, null, context), [
749
- context
750
- ]), context);
751
- let { disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $1BfjW$useGridState)({
752
- ...props,
753
- collection: collection,
754
- disabledBehavior: props.disabledBehavior || "selection"
755
- });
756
- return {
757
- collection: collection,
758
- disabledKeys: disabledKeys,
759
- selectionManager: selectionManager,
760
- showSelectionCheckboxes: props.showSelectionCheckboxes || false,
761
- sortDescriptor: props.sortDescriptor,
762
- isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
763
- setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
764
- sort (columnKey, direction) {
765
- var _props_sortDescriptor;
766
- props.onSortChange({
767
- column: columnKey,
768
- direction: direction !== null && direction !== void 0 ? direction : ((_props_sortDescriptor = props.sortDescriptor) === null || _props_sortDescriptor === void 0 ? void 0 : _props_sortDescriptor.column) === columnKey ? $4a0dd036d492cee4$var$OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction] : "ascending"
769
- });
770
- }
771
- };
772
- }
773
26
 
774
27
 
775
- /*
776
- * Copyright 2020 Adobe. All rights reserved.
777
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
778
- * you may not use this file except in compliance with the License. You may obtain a copy
779
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
780
- *
781
- * Unless required by applicable law or agreed to in writing, software distributed under
782
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
783
- * OF ANY KIND, either express or implied. See the License for the specific language
784
- * governing permissions and limitations under the License.
785
- */
786
- function $312ae3b56a94a86e$var$TableHeader(props) {
787
- return null;
788
- }
789
- $312ae3b56a94a86e$var$TableHeader.getCollectionNode = function* getCollectionNode(props, context) {
790
- let { children: children, columns: columns } = props;
791
- // Clear columns so they aren't double added in strict mode.
792
- context.columns = [];
793
- if (typeof children === "function") {
794
- if (!columns) throw new Error("props.children was a function but props.columns is missing");
795
- for (let column of columns)yield {
796
- type: "column",
797
- value: column,
798
- renderer: children
799
- };
800
- } else {
801
- let columns = [];
802
- (0, $1BfjW$react).Children.forEach(children, (column)=>{
803
- columns.push({
804
- type: "column",
805
- element: column
806
- });
807
- });
808
- yield* columns;
809
- }
810
- };
811
- /**
812
- * A TableHeader is a container for the Column elements in a Table. Columns can be statically defined
813
- * as children, or generated dynamically using a function based on the data passed to the `columns` prop.
814
- */ // We don't want getCollectionNode to show up in the type definition
815
- let $312ae3b56a94a86e$export$f850895b287ef28e = $312ae3b56a94a86e$var$TableHeader;
816
-
817
-
818
- /*
819
- * Copyright 2020 Adobe. All rights reserved.
820
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
821
- * you may not use this file except in compliance with the License. You may obtain a copy
822
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
823
- *
824
- * Unless required by applicable law or agreed to in writing, software distributed under
825
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
826
- * OF ANY KIND, either express or implied. See the License for the specific language
827
- * governing permissions and limitations under the License.
828
- */
829
- function $4ae5314bf50db1a3$var$TableBody(props) {
830
- return null;
831
- }
832
- $4ae5314bf50db1a3$var$TableBody.getCollectionNode = function* getCollectionNode(props) {
833
- let { children: children, items: items } = props;
834
- yield {
835
- type: "body",
836
- hasChildNodes: true,
837
- props: props,
838
- *childNodes () {
839
- if (typeof children === "function") {
840
- if (!items) throw new Error("props.children was a function but props.items is missing");
841
- for (let item of items)yield {
842
- type: "item",
843
- value: item,
844
- renderer: children
845
- };
846
- } else {
847
- let items = [];
848
- (0, $1BfjW$react).Children.forEach(children, (item)=>{
849
- items.push({
850
- type: "item",
851
- element: item
852
- });
853
- });
854
- yield* items;
855
- }
856
- }
857
- };
858
- };
859
- /**
860
- * A TableBody is a container for the Row elements of a Table. Rows can be statically defined
861
- * as children, or generated dynamically using a function based on the data passed to the `items` prop.
862
- */ // We don't want getCollectionNode to show up in the type definition
863
- let $4ae5314bf50db1a3$export$76ccd210b9029917 = $4ae5314bf50db1a3$var$TableBody;
864
-
865
-
866
- /*
867
- * Copyright 2020 Adobe. All rights reserved.
868
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
869
- * you may not use this file except in compliance with the License. You may obtain a copy
870
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
871
- *
872
- * Unless required by applicable law or agreed to in writing, software distributed under
873
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
874
- * OF ANY KIND, either express or implied. See the License for the specific language
875
- * governing permissions and limitations under the License.
876
- */
877
- function $1cd244557c2f97d5$var$Column(props) {
878
- return null;
879
- }
880
- $1cd244557c2f97d5$var$Column.getCollectionNode = function* getCollectionNode(props, context) {
881
- let { title: title, children: children, childColumns: childColumns } = props;
882
- let rendered = title || children;
883
- let textValue = props.textValue || (typeof rendered === "string" ? rendered : "") || props["aria-label"];
884
- let fullNodes = yield {
885
- type: "column",
886
- hasChildNodes: !!childColumns || title && (0, $1BfjW$react).Children.count(children) > 0,
887
- rendered: rendered,
888
- textValue: textValue,
889
- props: props,
890
- *childNodes () {
891
- if (childColumns) for (let child of childColumns)yield {
892
- type: "column",
893
- value: child
894
- };
895
- else if (title) {
896
- let childColumns = [];
897
- (0, $1BfjW$react).Children.forEach(children, (child)=>{
898
- childColumns.push({
899
- type: "column",
900
- element: child
901
- });
902
- });
903
- yield* childColumns;
904
- }
905
- },
906
- shouldInvalidate (newContext) {
907
- // This is a bit of a hack, but it works.
908
- // If this method is called, then there's a cached version of this node available.
909
- // But, we need to keep the list of columns in the new context up to date.
910
- updateContext(newContext);
911
- return false;
912
- }
913
- };
914
- let updateContext = (context)=>{
915
- // register leaf columns on the context so that <Row> can access them
916
- for (let node of fullNodes)if (!node.hasChildNodes) context.columns.push(node);
917
- };
918
- updateContext(context);
919
- };
920
- /**
921
- * A Column represents a field of each item within a Table. Columns may also contain nested
922
- * Column elements to represent column groups. Nested columns can be statically defined as
923
- * children, or dynamically generated using a function based on the `childColumns` prop.
924
- */ // We don't want getCollectionNode to show up in the type definition
925
- let $1cd244557c2f97d5$export$816b5d811295e6bc = $1cd244557c2f97d5$var$Column;
926
-
927
-
928
- /*
929
- * Copyright 2020 Adobe. All rights reserved.
930
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
931
- * you may not use this file except in compliance with the License. You may obtain a copy
932
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
933
- *
934
- * Unless required by applicable law or agreed to in writing, software distributed under
935
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
936
- * OF ANY KIND, either express or implied. See the License for the specific language
937
- * governing permissions and limitations under the License.
938
- */
939
- function $70d70eb16ea48428$var$Row(props) {
940
- return null;
941
- }
942
- $70d70eb16ea48428$var$Row.getCollectionNode = function* getCollectionNode(props, context) {
943
- let { children: children, textValue: textValue, UNSTABLE_childItems: UNSTABLE_childItems } = props;
944
- yield {
945
- type: "item",
946
- props: props,
947
- textValue: textValue,
948
- "aria-label": props["aria-label"],
949
- hasChildNodes: true,
950
- *childNodes () {
951
- // Process cells first
952
- if (context.showDragButtons) yield {
953
- type: "cell",
954
- key: "header-drag",
955
- props: {
956
- isDragButtonCell: true
957
- }
958
- };
959
- if (context.showSelectionCheckboxes && context.selectionMode !== "none") yield {
960
- type: "cell",
961
- key: "header",
962
- props: {
963
- isSelectionCell: true
964
- }
965
- };
966
- if (typeof children === "function") {
967
- for (let column of context.columns)yield {
968
- type: "cell",
969
- element: children(column.key),
970
- key: column.key // this is combined with the row key by CollectionBuilder
971
- };
972
- 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
973
- // the parent renderer and use that to build the full node of this child row, using the value provided here to generate the cells
974
- yield {
975
- type: "item",
976
- value: child
977
- };
978
- } else {
979
- let cells = [];
980
- let childRows = [];
981
- (0, $1BfjW$react).Children.forEach(children, (node)=>{
982
- if (node.type === $70d70eb16ea48428$var$Row) {
983
- if (cells.length < context.columns.length) throw new Error("All of a Row's child Cells must be positioned before any child Rows.");
984
- childRows.push({
985
- type: "item",
986
- element: node
987
- });
988
- } else cells.push({
989
- type: "cell",
990
- element: node
991
- });
992
- });
993
- if (cells.length !== context.columns.length) throw new Error(`Cell count must match column count. Found ${cells.length} cells and ${context.columns.length} columns.`);
994
- yield* cells;
995
- yield* childRows;
996
- }
997
- },
998
- shouldInvalidate (newContext) {
999
- // Invalidate all rows if the columns changed.
1000
- return newContext.columns.length !== context.columns.length || newContext.columns.some((c, i)=>c.key !== context.columns[i].key) || newContext.showSelectionCheckboxes !== context.showSelectionCheckboxes || newContext.showDragButtons !== context.showDragButtons || newContext.selectionMode !== context.selectionMode;
1001
- }
1002
- };
1003
- };
1004
- /**
1005
- * A Row represents a single item in a Table and contains Cell elements for each column.
1006
- * Cells can be statically defined as children, or generated dynamically using a function
1007
- * based on the columns defined in the TableHeader.
1008
- */ // We don't want getCollectionNode to show up in the type definition
1009
- let $70d70eb16ea48428$export$b59bdbef9ce70de2 = $70d70eb16ea48428$var$Row;
1010
-
1011
-
1012
- /*
1013
- * Copyright 2020 Adobe. All rights reserved.
1014
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1015
- * you may not use this file except in compliance with the License. You may obtain a copy
1016
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
1017
- *
1018
- * Unless required by applicable law or agreed to in writing, software distributed under
1019
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1020
- * OF ANY KIND, either express or implied. See the License for the specific language
1021
- * governing permissions and limitations under the License.
1022
- */ function $941d1d9a6a28982a$var$Cell(props) {
1023
- return null;
1024
- }
1025
- $941d1d9a6a28982a$var$Cell.getCollectionNode = function* getCollectionNode(props) {
1026
- let { children: children } = props;
1027
- let textValue = props.textValue || (typeof children === "string" ? children : "") || props["aria-label"] || "";
1028
- yield {
1029
- type: "cell",
1030
- props: props,
1031
- rendered: children,
1032
- textValue: textValue,
1033
- "aria-label": props["aria-label"],
1034
- hasChildNodes: false
1035
- };
1036
- };
1037
- /**
1038
- * A Cell represents the value of a single Column within a Table Row.
1039
- */ // We don't want getCollectionNode to show up in the type definition
1040
- let $941d1d9a6a28982a$export$f6f0c3fe4ec306ea = $941d1d9a6a28982a$var$Cell;
1041
-
1042
-
1043
-
1044
-
1045
-
1046
- /*
1047
- * Copyright 2023 Adobe. All rights reserved.
1048
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1049
- * you may not use this file except in compliance with the License. You may obtain a copy
1050
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
1051
- *
1052
- * Unless required by applicable law or agreed to in writing, software distributed under
1053
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1054
- * OF ANY KIND, either express or implied. See the License for the specific language
1055
- * governing permissions and limitations under the License.
1056
- */
1057
-
1058
28
 
1059
29
 
1060
30
 
1061
31
 
1062
- function $ee65a0057fd99531$export$34dfa8a1622185a4(props) {
1063
- let { selectionMode: selectionMode = "none", showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons, UNSTABLE_expandedKeys: propExpandedKeys, UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys, UNSTABLE_onExpandedChange: UNSTABLE_onExpandedChange, children: children } = props;
1064
- if (!(0, $1BfjW$tableNestedRows)()) throw new Error("Feature flag for table nested rows must be enabled to use useTreeGridState.");
1065
- let [expandedKeys, setExpandedKeys] = (0, $1BfjW$useControlledState)(propExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propExpandedKeys) : undefined, propDefaultExpandedKeys ? $ee65a0057fd99531$var$convertExpanded(propDefaultExpandedKeys) : new Set(), UNSTABLE_onExpandedChange);
1066
- let context = (0, $1BfjW$useMemo)(()=>({
1067
- showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
1068
- showDragButtons: showDragButtons,
1069
- selectionMode: selectionMode,
1070
- columns: []
1071
- }), [
1072
- children,
1073
- showSelectionCheckboxes,
1074
- selectionMode,
1075
- showDragButtons
1076
- ]);
1077
- let builder = (0, $1BfjW$useMemo)(()=>new (0, $1BfjW$CollectionBuilder)(), []);
1078
- let nodes = (0, $1BfjW$useMemo)(()=>builder.build({
1079
- children: children
1080
- }, context), [
1081
- builder,
1082
- children,
1083
- context
1084
- ]);
1085
- let treeGridCollection = (0, $1BfjW$useMemo)(()=>{
1086
- return $ee65a0057fd99531$var$generateTreeGridCollection(nodes, {
1087
- showSelectionCheckboxes: showSelectionCheckboxes,
1088
- showDragButtons: showDragButtons,
1089
- expandedKeys: expandedKeys
1090
- });
1091
- }, [
1092
- nodes,
1093
- showSelectionCheckboxes,
1094
- showDragButtons,
1095
- expandedKeys
1096
- ]);
1097
- let onToggle = (key)=>{
1098
- setExpandedKeys($ee65a0057fd99531$var$toggleKey(expandedKeys, key, treeGridCollection));
1099
- };
1100
- let collection = (0, $1BfjW$useMemo)(()=>{
1101
- return new (0, $788781baa30117fa$export$596e1b2e2cf93690)(treeGridCollection.tableNodes, null, context);
1102
- }, [
1103
- context,
1104
- treeGridCollection.tableNodes
1105
- ]);
1106
- let tableState = (0, $4a0dd036d492cee4$export$907bcc6c48325fd6)({
1107
- ...props,
1108
- collection: collection
1109
- });
1110
- return {
1111
- ...tableState,
1112
- keyMap: treeGridCollection.keyMap,
1113
- userColumnCount: treeGridCollection.userColumnCount,
1114
- expandedKeys: expandedKeys,
1115
- toggleKey: onToggle
1116
- };
1117
- }
1118
- function $ee65a0057fd99531$var$toggleKey(currentExpandedKeys, key, collection) {
1119
- let updatedExpandedKeys;
1120
- if (currentExpandedKeys === "all") {
1121
- updatedExpandedKeys = new Set(collection.flattenedRows.filter((row)=>row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map((row)=>row.key));
1122
- updatedExpandedKeys.delete(key);
1123
- } else {
1124
- updatedExpandedKeys = new Set(currentExpandedKeys);
1125
- if (updatedExpandedKeys.has(key)) updatedExpandedKeys.delete(key);
1126
- else updatedExpandedKeys.add(key);
1127
- }
1128
- return updatedExpandedKeys;
1129
- }
1130
- function $ee65a0057fd99531$var$convertExpanded(expanded) {
1131
- if (!expanded) return new Set();
1132
- return expanded === "all" ? "all" : new Set(expanded);
1133
- }
1134
- function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
1135
- let { expandedKeys: expandedKeys = new Set() } = opts;
1136
- let body;
1137
- let flattenedRows = [];
1138
- let columnCount = 0;
1139
- let userColumnCount = 0;
1140
- let originalColumns = [];
1141
- let keyMap = new Map();
1142
- if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) columnCount++;
1143
- if (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) columnCount++;
1144
- let topLevelRows = [];
1145
- let visit = (node)=>{
1146
- switch(node.type){
1147
- case "body":
1148
- body = node;
1149
- keyMap.set(body.key, body);
1150
- break;
1151
- case "column":
1152
- if (!node.hasChildNodes) userColumnCount++;
1153
- break;
1154
- case "item":
1155
- topLevelRows.push(node);
1156
- return;
1157
- }
1158
- for (let child of node.childNodes)visit(child);
1159
- };
1160
- for (let node of nodes){
1161
- if (node.type === "column") originalColumns.push(node);
1162
- visit(node);
1163
- }
1164
- columnCount += userColumnCount;
1165
- // 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
1166
- let globalRowCount = 0;
1167
- let visitNode = (node, i)=>{
1168
- // Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided
1169
- // to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure
1170
- // values automatically calculated via CollectionBuilder
1171
- if (node.type === "item") {
1172
- let childNodes = [];
1173
- for (let child of node.childNodes)if (child.type === "cell") {
1174
- let cellClone = {
1175
- ...child
1176
- };
1177
- if (cellClone.index + 1 === columnCount) cellClone.nextKey = null;
1178
- childNodes.push({
1179
- ...cellClone
1180
- });
1181
- }
1182
- let clone = {
1183
- ...node,
1184
- childNodes: childNodes,
1185
- parentKey: body.key,
1186
- level: 1,
1187
- index: globalRowCount++
1188
- };
1189
- flattenedRows.push(clone);
1190
- }
1191
- let newProps = {};
1192
- // Assign indexOfType to cells and rows for aria-posinset
1193
- if (node.type !== "placeholder" && node.type !== "column") newProps["indexOfType"] = i;
1194
- // Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes
1195
- // via .childNodes returns the same object as the one found via keyMap look up
1196
- Object.assign(node, newProps);
1197
- keyMap.set(node.key, node);
1198
- let lastNode;
1199
- let rowIndex = 0;
1200
- for (let child of node.childNodes)if (!(child.type === "item" && expandedKeys !== "all" && !expandedKeys.has(node.key))) {
1201
- 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
1202
- child.parentKey = node.key;
1203
- if (lastNode) {
1204
- lastNode.nextKey = child.key;
1205
- child.prevKey = lastNode.key;
1206
- } else child.prevKey = null;
1207
- if (child.type === "item") visitNode(child, rowIndex++);
1208
- else // We enforce that the cells come before rows so can just reuse cell index
1209
- visitNode(child, child.index);
1210
- lastNode = child;
1211
- }
1212
- if (lastNode) lastNode.nextKey = null;
1213
- };
1214
- let last;
1215
- topLevelRows.forEach((node, i)=>{
1216
- visitNode(node, i);
1217
- if (last) {
1218
- last.nextKey = node.key;
1219
- node.prevKey = last.key;
1220
- } else node.prevKey = null;
1221
- last = node;
1222
- });
1223
- if (last) last.nextKey = null;
1224
- return {
1225
- keyMap: keyMap,
1226
- userColumnCount: userColumnCount,
1227
- flattenedRows: flattenedRows,
1228
- tableNodes: [
1229
- ...originalColumns,
1230
- {
1231
- ...body,
1232
- childNodes: flattenedRows
1233
- }
1234
- ]
1235
- };
1236
- }
1237
32
 
1238
33
 
1239
34