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