@react-stately/table 3.7.1-nightly.3698 → 3.7.1-nightly.3709

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,975 @@
1
+ import {Section as $6555104ff085bef4$re_export$Section, useCollection as $1BfjW$useCollection} from "@react-stately/collections";
2
+ import $1BfjW$react, {useState as $1BfjW$useState, useMemo as $1BfjW$useMemo, useCallback as $1BfjW$useCallback} from "react";
3
+ import $1BfjW$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
4
+ import {useGridState as $1BfjW$useGridState, GridCollection as $1BfjW$GridCollection} from "@react-stately/grid";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */ /*
17
+ * Copyright 2022 Adobe. All rights reserved.
18
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License. You may obtain a copy
20
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software distributed under
23
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
24
+ * OF ANY KIND, either express or implied. See the License for the specific language
25
+ * governing permissions and limitations under the License.
26
+ */
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
+ /*
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
+ */ function $6818b1c4fc67028d$export$1994a077b98ee0d5(width) {
49
+ return width != null && (!isNaN(width) || String(width).match(/^(\d+)(?=%$)/) !== null);
50
+ }
51
+ function $6818b1c4fc67028d$export$9078bad4c3934604(width) {
52
+ if (!width) return 1;
53
+ let match = width.match(/^(.+)(?=fr$)/);
54
+ // if width is the incorrect format, just default it to a 1fr
55
+ if (!match) {
56
+ 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'");
57
+ return 1;
58
+ }
59
+ return parseFloat(match[0]);
60
+ }
61
+ function $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, tableWidth) {
62
+ if (typeof width === "string") {
63
+ let match = width.match(/^(\d+)(?=%$)/);
64
+ if (!match) throw new Error("Only percentages or numbers are supported for static column widths");
65
+ return tableWidth * (parseFloat(match[0]) / 100);
66
+ }
67
+ return width;
68
+ }
69
+ function $6818b1c4fc67028d$export$59185c62a7544aa0(maxWidth, tableWidth) {
70
+ return maxWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
71
+ }
72
+ function $6818b1c4fc67028d$export$f556054ce4358701(minWidth, tableWidth) {
73
+ return minWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
74
+ }
75
+ function $6818b1c4fc67028d$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
76
+ let hasNonFrozenItems = false;
77
+ let flexItems = columns.map((column, index)=>{
78
+ var _column_width, _ref, _ref1;
79
+ 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";
80
+ let frozen = false;
81
+ let baseSize = 0;
82
+ let flex = 0;
83
+ let targetMainSize = null;
84
+ if ($6818b1c4fc67028d$export$1994a077b98ee0d5(width)) {
85
+ baseSize = $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, availableWidth);
86
+ frozen = true;
87
+ } else {
88
+ flex = $6818b1c4fc67028d$export$9078bad4c3934604(width);
89
+ if (flex <= 0) frozen = true;
90
+ }
91
+ var _column_minWidth, _ref2;
92
+ 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);
93
+ let max = $6818b1c4fc67028d$export$59185c62a7544aa0(column.maxWidth, availableWidth);
94
+ let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
95
+ // 9.7.1
96
+ // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.
97
+ // 9.7.2
98
+ if (frozen) targetMainSize = hypotheticalMainSize;
99
+ else if (baseSize > hypotheticalMainSize) {
100
+ frozen = true;
101
+ targetMainSize = hypotheticalMainSize;
102
+ }
103
+ // 9.7.3
104
+ if (!frozen) hasNonFrozenItems = true;
105
+ return {
106
+ frozen: frozen,
107
+ baseSize: baseSize,
108
+ hypotheticalMainSize: hypotheticalMainSize,
109
+ min: min,
110
+ max: max,
111
+ flex: flex,
112
+ targetMainSize: targetMainSize,
113
+ violation: 0
114
+ };
115
+ });
116
+ // 9.7.4
117
+ // 9.7.4.a
118
+ while(hasNonFrozenItems){
119
+ // 9.7.4.b
120
+ /**
121
+ * Calculate the remaining free space as for initial free space,
122
+ * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is
123
+ * less than one, multiply the initial free space by this sum (of flex factors).
124
+ * If the magnitude of this value is less than the magnitude of
125
+ * the remaining free space, use this as the remaining free space.
126
+ */ let usedWidth = 0;
127
+ let flexFactors = 0;
128
+ flexItems.forEach((item)=>{
129
+ if (item.frozen) usedWidth += item.targetMainSize;
130
+ else {
131
+ usedWidth += item.baseSize;
132
+ flexFactors += item.flex;
133
+ }
134
+ });
135
+ let remainingFreeSpace = availableWidth - usedWidth;
136
+ // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0
137
+ // so no need to check for flexFactors < 1
138
+ // 9.7.4.c
139
+ /**
140
+ * If the remaining free space is zero
141
+ * - Do nothing.
142
+ * Else // remember, we're always in grow mode
143
+ * - Find the ratio of the item’s flex grow factor to the
144
+ * sum of the flex grow factors of all unfrozen items on
145
+ * the line. Set the item’s target main size to its flex
146
+ * base size plus a fraction of the remaining free space
147
+ * proportional to the ratio.
148
+ */ if (remainingFreeSpace > 0) flexItems.forEach((item)=>{
149
+ if (!item.frozen) {
150
+ let ratio = item.flex / flexFactors;
151
+ item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
152
+ }
153
+ });
154
+ // 9.7.4.d
155
+ /**
156
+ * Fix min/max violations. Clamp each non-frozen item’s
157
+ * target main size by its used min and max main sizes
158
+ * and floor its content-box size at zero. If the item’s
159
+ * target main size was made smaller by this, it’s a max
160
+ * violation. If the item’s target main size was made
161
+ * larger by this, it’s a min violation.
162
+ */ let totalViolation = 0;
163
+ flexItems.forEach((item)=>{
164
+ item.violation = 0;
165
+ if (!item.frozen) {
166
+ let { min: min , max: max , targetMainSize: targetMainSize } = item;
167
+ item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
168
+ item.violation = item.targetMainSize - targetMainSize;
169
+ totalViolation += item.violation;
170
+ }
171
+ });
172
+ // 9.7.4.e
173
+ /**
174
+ * Freeze over-flexed items. The total violation is the
175
+ * sum of the adjustments from the previous step
176
+ * ∑(clamped size - unclamped size). If the total violation is:
177
+ * Zero
178
+ * - Freeze all items.
179
+ *
180
+ * Positive
181
+ * - Freeze all the items with min violations.
182
+ *
183
+ * Negative
184
+ * - Freeze all the items with max violations.
185
+ */ hasNonFrozenItems = false;
186
+ flexItems.forEach((item)=>{
187
+ if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
188
+ else if (!item.frozen) hasNonFrozenItems = true;
189
+ });
190
+ }
191
+ return $6818b1c4fc67028d$var$cascadeRounding(flexItems);
192
+ }
193
+ function $6818b1c4fc67028d$var$cascadeRounding(flexItems) {
194
+ /*
195
+ Given an array of floats that sum to an integer, this rounds the floats
196
+ and returns an array of integers with the same sum.
197
+ */ let fpTotal = 0;
198
+ let intTotal = 0;
199
+ let roundedArray = [];
200
+ flexItems.forEach(function(item) {
201
+ let float = item.targetMainSize;
202
+ let integer = Math.round(float + fpTotal) - intTotal;
203
+ fpTotal += float;
204
+ intTotal += integer;
205
+ roundedArray.push(integer);
206
+ });
207
+ return roundedArray;
208
+ }
209
+
210
+
211
+ class $a9e7ae544a4e41dd$export$7ff77a162970b30e {
212
+ /** Takes an array of columns and splits it into 2 maps of columns with controlled and columns with uncontrolled widths. */ splitColumnsIntoControlledAndUncontrolled(columns) {
213
+ return columns.reduce((acc, col)=>{
214
+ if (col.props.width != null) acc[0].set(col.key, col);
215
+ else acc[1].set(col.key, col);
216
+ return acc;
217
+ }, [
218
+ new Map(),
219
+ new Map()
220
+ ]);
221
+ }
222
+ /** Takes uncontrolled and controlled widths and joins them into a single Map. */ recombineColumns(columns, uncontrolledWidths, uncontrolledColumns, controlledColumns) {
223
+ return new Map(columns.map((col)=>{
224
+ if (uncontrolledColumns.has(col.key)) return [
225
+ col.key,
226
+ uncontrolledWidths.get(col.key)
227
+ ];
228
+ else return [
229
+ col.key,
230
+ controlledColumns.get(col.key).props.width
231
+ ];
232
+ }));
233
+ }
234
+ /** Used to make an initial Map of the uncontrolled widths based on default widths. */ getInitialUncontrolledWidths(uncontrolledColumns) {
235
+ var _col_props_defaultWidth, _ref;
236
+ return new Map(Array.from(uncontrolledColumns).map(([key, col])=>{
237
+ var _this, _this_getDefaultWidth;
238
+ return [
239
+ key,
240
+ (_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"
241
+ ];
242
+ }));
243
+ }
244
+ getColumnWidth(key) {
245
+ var _this_columnWidths_get;
246
+ return (_this_columnWidths_get = this.columnWidths.get(key)) !== null && _this_columnWidths_get !== void 0 ? _this_columnWidths_get : 0;
247
+ }
248
+ getColumnMinWidth(key) {
249
+ return this.columnMinWidths.get(key);
250
+ }
251
+ getColumnMaxWidth(key) {
252
+ return this.columnMaxWidths.get(key);
253
+ }
254
+ resizeColumnWidth(tableWidth, collection, controlledWidths, uncontrolledWidths, col = null, width) {
255
+ let prevColumnWidths = this.columnWidths;
256
+ // resizing a column
257
+ let resizeIndex = Infinity;
258
+ let resizingChanged = new Map([
259
+ ...controlledWidths,
260
+ ...uncontrolledWidths
261
+ ]);
262
+ let percentKeys = new Map();
263
+ let frKeysToTheRight = new Map();
264
+ let minWidths = new Map();
265
+ // freeze columns to the left to their previous pixel value
266
+ collection.columns.forEach((column, i)=>{
267
+ var _column_column_props_width, _column_column_props_width_endsWith;
268
+ let frKey;
269
+ let frValue;
270
+ minWidths.set(column.key, this.getDefaultMinWidth(collection.columns[i]));
271
+ if (col !== column.key && !column.column.props.width && !(0, $6818b1c4fc67028d$export$1994a077b98ee0d5)(uncontrolledWidths.get(column.key))) {
272
+ // uncontrolled don't have props.width for us, so instead get from our state
273
+ frKey = column.key;
274
+ frValue = (0, $6818b1c4fc67028d$export$9078bad4c3934604)(uncontrolledWidths.get(column.key));
275
+ } else if (col !== column.key && !(0, $6818b1c4fc67028d$export$1994a077b98ee0d5)(column.column.props.width) && !uncontrolledWidths.get(column.key)) {
276
+ // controlledWidths will be the same in the collection
277
+ frKey = column.key;
278
+ frValue = (0, $6818b1c4fc67028d$export$9078bad4c3934604)(column.column.props.width);
279
+ } else if (col !== column.key && ((_column_column_props_width = column.column.props.width) === null || _column_column_props_width === void 0 ? void 0 : (_column_column_props_width_endsWith = _column_column_props_width.endsWith) === null || _column_column_props_width_endsWith === void 0 ? void 0 : _column_column_props_width_endsWith.call(_column_column_props_width, "%"))) percentKeys.set(column.key, column.column.props.width);
280
+ // don't freeze columns to the right of the resizing one
281
+ if (resizeIndex < i) {
282
+ if (frKey) frKeysToTheRight.set(frKey, frValue);
283
+ return;
284
+ }
285
+ // we already know the new size of the resizing column
286
+ if (column.key === col) {
287
+ resizeIndex = i;
288
+ resizingChanged.set(column.key, Math.floor(width));
289
+ return;
290
+ }
291
+ // freeze column to previous value
292
+ resizingChanged.set(column.key, prevColumnWidths.get(column.key));
293
+ });
294
+ // predict pixels sizes for all columns based on resize
295
+ let columnWidths = (0, $6818b1c4fc67028d$export$55d50dc687385491)(tableWidth, collection.columns.map((col)=>({
296
+ ...col.column.props,
297
+ key: col.key
298
+ })), resizingChanged, (i)=>this.getDefaultWidth(collection.columns[i]), (i)=>this.getDefaultMinWidth(collection.columns[i]));
299
+ // set all new column widths for onResize event
300
+ // columns going in will be the same order as the columns coming out
301
+ let newWidths = new Map();
302
+ // set all column widths based on calculateColumnSize
303
+ columnWidths.forEach((width, index)=>{
304
+ let key = collection.columns[index].key;
305
+ newWidths.set(key, width);
306
+ });
307
+ // add FR's back as they were to columns to the right
308
+ Array.from(frKeysToTheRight).forEach(([key])=>{
309
+ newWidths.set(key, `${frKeysToTheRight.get(key)}fr`);
310
+ });
311
+ // put back in percents
312
+ Array.from(percentKeys).forEach(([key, width])=>{
313
+ // resizing locks a column to a px width
314
+ if (key === col) return;
315
+ newWidths.set(key, width);
316
+ });
317
+ return newWidths;
318
+ }
319
+ buildColumnWidths(tableWidth, collection, widths) {
320
+ this.columnWidths = new Map();
321
+ this.columnMinWidths = new Map();
322
+ this.columnMaxWidths = new Map();
323
+ // initial layout or table/window resizing
324
+ let columnWidths = (0, $6818b1c4fc67028d$export$55d50dc687385491)(tableWidth, collection.columns.map((col)=>({
325
+ ...col.column.props,
326
+ key: col.key
327
+ })), widths, (i)=>this.getDefaultWidth(collection.columns[i]), (i)=>this.getDefaultMinWidth(collection.columns[i]));
328
+ // columns going in will be the same order as the columns coming out
329
+ columnWidths.forEach((width, index)=>{
330
+ let key = collection.columns[index].key;
331
+ let column = collection.columns[index];
332
+ this.columnWidths.set(key, width);
333
+ var _column_column_props_minWidth;
334
+ this.columnMinWidths.set(key, (0, $6818b1c4fc67028d$export$f556054ce4358701)((_column_column_props_minWidth = column.column.props.minWidth) !== null && _column_column_props_minWidth !== void 0 ? _column_column_props_minWidth : this.getDefaultMinWidth(column), tableWidth));
335
+ this.columnMaxWidths.set(key, (0, $6818b1c4fc67028d$export$59185c62a7544aa0)(column.column.props.maxWidth, tableWidth));
336
+ });
337
+ return this.columnWidths;
338
+ }
339
+ constructor(options){
340
+ (0, $1BfjW$swchelperssrc_define_propertymjs)(this, "columnWidths", new Map());
341
+ (0, $1BfjW$swchelperssrc_define_propertymjs)(this, "columnMinWidths", new Map());
342
+ (0, $1BfjW$swchelperssrc_define_propertymjs)(this, "columnMaxWidths", new Map());
343
+ var _options_getDefaultWidth;
344
+ this.getDefaultWidth = (_options_getDefaultWidth = options === null || options === void 0 ? void 0 : options.getDefaultWidth) !== null && _options_getDefaultWidth !== void 0 ? _options_getDefaultWidth : ()=>"1fr";
345
+ var _options_getDefaultMinWidth;
346
+ this.getDefaultMinWidth = (_options_getDefaultMinWidth = options === null || options === void 0 ? void 0 : options.getDefaultMinWidth) !== null && _options_getDefaultMinWidth !== void 0 ? _options_getDefaultMinWidth : ()=>0;
347
+ }
348
+ }
349
+
350
+
351
+ function $292bc4e09cd0eb62$export$cb895dcf85db1319(props, state) {
352
+ let { getDefaultWidth: getDefaultWidth , getDefaultMinWidth: getDefaultMinWidth , tableWidth: tableWidth = 0 } = props;
353
+ let [resizingColumn, setResizingColumn] = (0, $1BfjW$useState)(null);
354
+ let columnLayout = (0, $1BfjW$useMemo)(()=>new (0, $a9e7ae544a4e41dd$export$7ff77a162970b30e)({
355
+ getDefaultWidth: getDefaultWidth,
356
+ getDefaultMinWidth: getDefaultMinWidth
357
+ }), [
358
+ getDefaultWidth,
359
+ getDefaultMinWidth
360
+ ]);
361
+ let [controlledColumns, uncontrolledColumns] = (0, $1BfjW$useMemo)(()=>columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns), [
362
+ state.collection.columns,
363
+ columnLayout
364
+ ]);
365
+ // uncontrolled column widths
366
+ let [uncontrolledWidths, setUncontrolledWidths] = (0, $1BfjW$useState)(()=>columnLayout.getInitialUncontrolledWidths(uncontrolledColumns));
367
+ // combine columns back into one map that maintains same order as the columns
368
+ let colWidths = (0, $1BfjW$useMemo)(()=>columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns), [
369
+ state.collection.columns,
370
+ uncontrolledWidths,
371
+ uncontrolledColumns,
372
+ controlledColumns,
373
+ columnLayout
374
+ ]);
375
+ let startResize = (0, $1BfjW$useCallback)((key)=>{
376
+ setResizingColumn(key);
377
+ }, [
378
+ setResizingColumn
379
+ ]);
380
+ let updateResizedColumns = (0, $1BfjW$useCallback)((key, width)=>{
381
+ let newControlled = new Map(Array.from(controlledColumns).map(([key, entry])=>[
382
+ key,
383
+ entry.props.width
384
+ ]));
385
+ let newSizes = columnLayout.resizeColumnWidth(tableWidth, state.collection, newControlled, uncontrolledWidths, key, width);
386
+ let map = new Map(Array.from(uncontrolledColumns).map(([key])=>[
387
+ key,
388
+ newSizes.get(key)
389
+ ]));
390
+ map.set(key, width);
391
+ setUncontrolledWidths(map);
392
+ return newSizes;
393
+ }, [
394
+ controlledColumns,
395
+ uncontrolledColumns,
396
+ setUncontrolledWidths,
397
+ tableWidth,
398
+ columnLayout,
399
+ state.collection,
400
+ uncontrolledWidths
401
+ ]);
402
+ let endResize = (0, $1BfjW$useCallback)(()=>{
403
+ setResizingColumn(null);
404
+ }, [
405
+ setResizingColumn
406
+ ]);
407
+ let columnWidths = (0, $1BfjW$useMemo)(()=>columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths), [
408
+ tableWidth,
409
+ state.collection,
410
+ colWidths,
411
+ columnLayout
412
+ ]);
413
+ return (0, $1BfjW$useMemo)(()=>({
414
+ resizingColumn: resizingColumn,
415
+ updateResizedColumns: updateResizedColumns,
416
+ startResize: startResize,
417
+ endResize: endResize,
418
+ getColumnWidth: (key)=>columnLayout.getColumnWidth(key),
419
+ getColumnMinWidth: (key)=>columnLayout.getColumnMinWidth(key),
420
+ getColumnMaxWidth: (key)=>columnLayout.getColumnMaxWidth(key),
421
+ widths: columnWidths,
422
+ tableState: state
423
+ }), [
424
+ columnLayout,
425
+ resizingColumn,
426
+ updateResizedColumns,
427
+ startResize,
428
+ endResize,
429
+ columnWidths,
430
+ state
431
+ ]);
432
+ }
433
+
434
+
435
+ /*
436
+ * Copyright 2020 Adobe. All rights reserved.
437
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
438
+ * you may not use this file except in compliance with the License. You may obtain a copy
439
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
440
+ *
441
+ * Unless required by applicable law or agreed to in writing, software distributed under
442
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
443
+ * OF ANY KIND, either express or implied. See the License for the specific language
444
+ * governing permissions and limitations under the License.
445
+ */
446
+
447
+ /*
448
+ * Copyright 2020 Adobe. All rights reserved.
449
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
450
+ * you may not use this file except in compliance with the License. You may obtain a copy
451
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
452
+ *
453
+ * Unless required by applicable law or agreed to in writing, software distributed under
454
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
455
+ * OF ANY KIND, either express or implied. See the License for the specific language
456
+ * governing permissions and limitations under the License.
457
+ */
458
+
459
+ const $788781baa30117fa$var$ROW_HEADER_COLUMN_KEY = "row-header-column-" + Math.random().toString(36).slice(2);
460
+ function $788781baa30117fa$var$buildHeaderRows(keyMap, columnNodes) {
461
+ let columns = [];
462
+ let seen = new Map();
463
+ for (let column of columnNodes){
464
+ let parentKey = column.parentKey;
465
+ let col = [
466
+ column
467
+ ];
468
+ while(parentKey){
469
+ let parent = keyMap.get(parentKey);
470
+ // If we've already seen this parent, than it is shared
471
+ // with a previous column. If the current column is taller
472
+ // than the previous column, than we need to shift the parent
473
+ // in the previous column so it's level with the current column.
474
+ if (seen.has(parent)) {
475
+ parent.colspan++;
476
+ let { column: column1 , index: index } = seen.get(parent);
477
+ if (index > col.length) break;
478
+ for(let i = index; i < col.length; i++)column1.splice(i, 0, null);
479
+ // Adjust shifted indices
480
+ for(let i1 = col.length; i1 < column1.length; i1++)// eslint-disable-next-line max-depth
481
+ if (column1[i1] && seen.has(column1[i1])) seen.get(column1[i1]).index = i1;
482
+ } else {
483
+ parent.colspan = 1;
484
+ col.push(parent);
485
+ seen.set(parent, {
486
+ column: col,
487
+ index: col.length - 1
488
+ });
489
+ }
490
+ parentKey = parent.parentKey;
491
+ }
492
+ columns.push(col);
493
+ column.index = columns.length - 1;
494
+ }
495
+ let maxLength = Math.max(...columns.map((c)=>c.length));
496
+ let headerRows = Array(maxLength).fill(0).map(()=>[]);
497
+ // Convert columns into rows.
498
+ let colIndex = 0;
499
+ for (let column2 of columns){
500
+ let i2 = maxLength - 1;
501
+ for (let item of column2){
502
+ if (item) {
503
+ // Fill the space up until the current column with a placeholder
504
+ let row = headerRows[i2];
505
+ let rowLength = row.reduce((p, c)=>p + c.colspan, 0);
506
+ if (rowLength < colIndex) {
507
+ let placeholder = {
508
+ type: "placeholder",
509
+ key: "placeholder-" + item.key,
510
+ colspan: colIndex - rowLength,
511
+ index: rowLength,
512
+ value: null,
513
+ rendered: null,
514
+ level: i2,
515
+ hasChildNodes: false,
516
+ childNodes: [],
517
+ textValue: null
518
+ };
519
+ // eslint-disable-next-line max-depth
520
+ if (row.length > 0) {
521
+ row[row.length - 1].nextKey = placeholder.key;
522
+ placeholder.prevKey = row[row.length - 1].key;
523
+ }
524
+ row.push(placeholder);
525
+ }
526
+ if (row.length > 0) {
527
+ row[row.length - 1].nextKey = item.key;
528
+ item.prevKey = row[row.length - 1].key;
529
+ }
530
+ item.level = i2;
531
+ item.colIndex = colIndex;
532
+ row.push(item);
533
+ }
534
+ i2--;
535
+ }
536
+ colIndex++;
537
+ }
538
+ // Add placeholders at the end of each row that is shorter than the maximum
539
+ let i3 = 0;
540
+ for (let row1 of headerRows){
541
+ let rowLength1 = row1.reduce((p, c)=>p + c.colspan, 0);
542
+ if (rowLength1 < columnNodes.length) {
543
+ let placeholder1 = {
544
+ type: "placeholder",
545
+ key: "placeholder-" + row1[row1.length - 1].key,
546
+ colspan: columnNodes.length - rowLength1,
547
+ index: rowLength1,
548
+ value: null,
549
+ rendered: null,
550
+ level: i3,
551
+ hasChildNodes: false,
552
+ childNodes: [],
553
+ textValue: null,
554
+ prevKey: row1[row1.length - 1].key
555
+ };
556
+ row1.push(placeholder1);
557
+ }
558
+ i3++;
559
+ }
560
+ return headerRows.map((childNodes, index)=>{
561
+ let row = {
562
+ type: "headerrow",
563
+ key: "headerrow-" + index,
564
+ index: index,
565
+ value: null,
566
+ rendered: null,
567
+ level: 0,
568
+ hasChildNodes: true,
569
+ childNodes: childNodes,
570
+ textValue: null
571
+ };
572
+ return row;
573
+ });
574
+ }
575
+ let $788781baa30117fa$var$_Symbol_iterator = Symbol.iterator;
576
+ class $788781baa30117fa$export$596e1b2e2cf93690 extends (0, $1BfjW$GridCollection) {
577
+ *[$788781baa30117fa$var$_Symbol_iterator]() {
578
+ yield* this.body.childNodes;
579
+ }
580
+ get size() {
581
+ return this._size;
582
+ }
583
+ getKeys() {
584
+ return this.keyMap.keys();
585
+ }
586
+ getKeyBefore(key) {
587
+ let node = this.keyMap.get(key);
588
+ return node ? node.prevKey : null;
589
+ }
590
+ getKeyAfter(key) {
591
+ let node = this.keyMap.get(key);
592
+ return node ? node.nextKey : null;
593
+ }
594
+ getFirstKey() {
595
+ var _;
596
+ return (_ = [
597
+ ...this.body.childNodes
598
+ ][0]) === null || _ === void 0 ? void 0 : _.key;
599
+ }
600
+ getLastKey() {
601
+ var _rows_;
602
+ let rows = [
603
+ ...this.body.childNodes
604
+ ];
605
+ return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
606
+ }
607
+ getItem(key) {
608
+ return this.keyMap.get(key);
609
+ }
610
+ at(idx) {
611
+ const keys = [
612
+ ...this.getKeys()
613
+ ];
614
+ return this.getItem(keys[idx]);
615
+ }
616
+ constructor(nodes, prev, opts){
617
+ let rowHeaderColumnKeys = new Set();
618
+ let body;
619
+ let columns = [];
620
+ // Add cell for selection checkboxes if needed.
621
+ if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) {
622
+ let rowHeaderColumn = {
623
+ type: "column",
624
+ key: $788781baa30117fa$var$ROW_HEADER_COLUMN_KEY,
625
+ value: null,
626
+ textValue: "",
627
+ level: 0,
628
+ index: 0,
629
+ hasChildNodes: false,
630
+ rendered: null,
631
+ childNodes: [],
632
+ props: {
633
+ isSelectionCell: true
634
+ }
635
+ };
636
+ columns.unshift(rowHeaderColumn);
637
+ }
638
+ let rows = [];
639
+ let columnKeyMap = new Map();
640
+ let visit = (node)=>{
641
+ switch(node.type){
642
+ case "body":
643
+ body = node;
644
+ break;
645
+ case "column":
646
+ columnKeyMap.set(node.key, node);
647
+ if (!node.hasChildNodes) {
648
+ columns.push(node);
649
+ if (node.props.isRowHeader) rowHeaderColumnKeys.add(node.key);
650
+ }
651
+ break;
652
+ case "item":
653
+ rows.push(node);
654
+ return; // do not go into childNodes
655
+ }
656
+ for (let child of node.childNodes)visit(child);
657
+ };
658
+ for (let node of nodes)visit(node);
659
+ let headerRows = $788781baa30117fa$var$buildHeaderRows(columnKeyMap, columns);
660
+ headerRows.forEach((row, i)=>rows.splice(i, 0, row));
661
+ super({
662
+ columnCount: columns.length,
663
+ items: rows,
664
+ visitNode: (node)=>{
665
+ node.column = columns[node.index];
666
+ return node;
667
+ }
668
+ });
669
+ (0, $1BfjW$swchelperssrc_define_propertymjs)(this, "_size", 0);
670
+ this.columns = columns;
671
+ this.rowHeaderColumnKeys = rowHeaderColumnKeys;
672
+ this.body = body;
673
+ this.headerRows = headerRows;
674
+ this._size = [
675
+ ...body.childNodes
676
+ ].length;
677
+ // Default row header column to the first one.
678
+ if (this.rowHeaderColumnKeys.size === 0) this.rowHeaderColumnKeys.add(this.columns[(opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) ? 1 : 0].key);
679
+ }
680
+ }
681
+
682
+
683
+
684
+ const $4a0dd036d492cee4$var$OPPOSITE_SORT_DIRECTION = {
685
+ ascending: "descending",
686
+ descending: "ascending"
687
+ };
688
+ function $4a0dd036d492cee4$export$907bcc6c48325fd6(props) {
689
+ let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = (0, $1BfjW$useState)(false);
690
+ let { selectionMode: selectionMode = "none" } = props;
691
+ let context = (0, $1BfjW$useMemo)(()=>({
692
+ showSelectionCheckboxes: props.showSelectionCheckboxes && selectionMode !== "none",
693
+ selectionMode: selectionMode,
694
+ columns: []
695
+ }), [
696
+ props.children,
697
+ props.showSelectionCheckboxes,
698
+ selectionMode
699
+ ]);
700
+ let collection = (0, $1BfjW$useCollection)(props, (nodes, prev)=>new (0, $788781baa30117fa$export$596e1b2e2cf93690)(nodes, prev, context), context);
701
+ let { disabledKeys: disabledKeys , selectionManager: selectionManager } = (0, $1BfjW$useGridState)({
702
+ ...props,
703
+ collection: collection,
704
+ disabledBehavior: "selection"
705
+ });
706
+ return {
707
+ collection: collection,
708
+ disabledKeys: disabledKeys,
709
+ selectionManager: selectionManager,
710
+ showSelectionCheckboxes: props.showSelectionCheckboxes || false,
711
+ sortDescriptor: props.sortDescriptor,
712
+ isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
713
+ setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
714
+ sort (columnKey, direction) {
715
+ var _props_sortDescriptor;
716
+ props.onSortChange({
717
+ column: columnKey,
718
+ 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"
719
+ });
720
+ }
721
+ };
722
+ }
723
+
724
+
725
+ /*
726
+ * Copyright 2020 Adobe. All rights reserved.
727
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
728
+ * you may not use this file except in compliance with the License. You may obtain a copy
729
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
730
+ *
731
+ * Unless required by applicable law or agreed to in writing, software distributed under
732
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
733
+ * OF ANY KIND, either express or implied. See the License for the specific language
734
+ * governing permissions and limitations under the License.
735
+ */
736
+ function $312ae3b56a94a86e$var$TableHeader(props) {
737
+ return null;
738
+ }
739
+ $312ae3b56a94a86e$var$TableHeader.getCollectionNode = function* getCollectionNode(props) {
740
+ let { children: children , columns: columns } = props;
741
+ if (typeof children === "function") {
742
+ if (!columns) throw new Error("props.children was a function but props.columns is missing");
743
+ for (let column of columns)yield {
744
+ type: "column",
745
+ value: column,
746
+ renderer: children
747
+ };
748
+ } else {
749
+ let columns1 = [];
750
+ (0, $1BfjW$react).Children.forEach(children, (column)=>{
751
+ columns1.push({
752
+ type: "column",
753
+ element: column
754
+ });
755
+ });
756
+ yield* columns1;
757
+ }
758
+ };
759
+ /**
760
+ * A TableHeader is a container for the Column elements in a Table. Columns can be statically defined
761
+ * as children, or generated dynamically using a function based on the data passed to the `columns` prop.
762
+ */ // We don't want getCollectionNode to show up in the type definition
763
+ let $312ae3b56a94a86e$export$f850895b287ef28e = $312ae3b56a94a86e$var$TableHeader;
764
+
765
+
766
+ /*
767
+ * Copyright 2020 Adobe. All rights reserved.
768
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
769
+ * you may not use this file except in compliance with the License. You may obtain a copy
770
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
771
+ *
772
+ * Unless required by applicable law or agreed to in writing, software distributed under
773
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
774
+ * OF ANY KIND, either express or implied. See the License for the specific language
775
+ * governing permissions and limitations under the License.
776
+ */
777
+ function $4ae5314bf50db1a3$var$TableBody(props) {
778
+ return null;
779
+ }
780
+ $4ae5314bf50db1a3$var$TableBody.getCollectionNode = function* getCollectionNode(props) {
781
+ let { children: children , items: items } = props;
782
+ yield {
783
+ type: "body",
784
+ hasChildNodes: true,
785
+ props: props,
786
+ *childNodes () {
787
+ if (typeof children === "function") {
788
+ if (!items) throw new Error("props.children was a function but props.items is missing");
789
+ for (let item of items)yield {
790
+ type: "item",
791
+ value: item,
792
+ renderer: children
793
+ };
794
+ } else {
795
+ let items1 = [];
796
+ (0, $1BfjW$react).Children.forEach(children, (item)=>{
797
+ items1.push({
798
+ type: "item",
799
+ element: item
800
+ });
801
+ });
802
+ yield* items1;
803
+ }
804
+ }
805
+ };
806
+ };
807
+ /**
808
+ * A TableBody is a container for the Row elements of a Table. Rows can be statically defined
809
+ * as children, or generated dynamically using a function based on the data passed to the `items` prop.
810
+ */ // We don't want getCollectionNode to show up in the type definition
811
+ let $4ae5314bf50db1a3$export$76ccd210b9029917 = $4ae5314bf50db1a3$var$TableBody;
812
+
813
+
814
+ /*
815
+ * Copyright 2020 Adobe. All rights reserved.
816
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
817
+ * you may not use this file except in compliance with the License. You may obtain a copy
818
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
819
+ *
820
+ * Unless required by applicable law or agreed to in writing, software distributed under
821
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
822
+ * OF ANY KIND, either express or implied. See the License for the specific language
823
+ * governing permissions and limitations under the License.
824
+ */
825
+ function $1cd244557c2f97d5$var$Column(props) {
826
+ return null;
827
+ }
828
+ $1cd244557c2f97d5$var$Column.getCollectionNode = function* getCollectionNode(props, context) {
829
+ let { title: title , children: children , childColumns: childColumns } = props;
830
+ let rendered = title || children;
831
+ let textValue = props.textValue || (typeof rendered === "string" ? rendered : "") || props["aria-label"];
832
+ let fullNodes = yield {
833
+ type: "column",
834
+ hasChildNodes: !!childColumns || title && (0, $1BfjW$react).Children.count(children) > 0,
835
+ rendered: rendered,
836
+ textValue: textValue,
837
+ props: props,
838
+ *childNodes () {
839
+ if (childColumns) for (let child of childColumns)yield {
840
+ type: "column",
841
+ value: child
842
+ };
843
+ else if (title) {
844
+ let childColumns1 = [];
845
+ (0, $1BfjW$react).Children.forEach(children, (child)=>{
846
+ childColumns1.push({
847
+ type: "column",
848
+ element: child
849
+ });
850
+ });
851
+ yield* childColumns1;
852
+ }
853
+ },
854
+ shouldInvalidate (newContext) {
855
+ // This is a bit of a hack, but it works.
856
+ // If this method is called, then there's a cached version of this node available.
857
+ // But, we need to keep the list of columns in the new context up to date.
858
+ updateContext(newContext);
859
+ return false;
860
+ }
861
+ };
862
+ let updateContext = (context)=>{
863
+ // register leaf columns on the context so that <Row> can access them
864
+ for (let node of fullNodes)if (!node.hasChildNodes) context.columns.push(node);
865
+ };
866
+ updateContext(context);
867
+ };
868
+ /**
869
+ * A Column represents a field of each item within a Table. Columns may also contain nested
870
+ * Column elements to represent column groups. Nested columns can be statically defined as
871
+ * children, or dynamically generated using a function based on the `childColumns` prop.
872
+ */ // We don't want getCollectionNode to show up in the type definition
873
+ let $1cd244557c2f97d5$export$816b5d811295e6bc = $1cd244557c2f97d5$var$Column;
874
+
875
+
876
+ /*
877
+ * Copyright 2020 Adobe. All rights reserved.
878
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
879
+ * you may not use this file except in compliance with the License. You may obtain a copy
880
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
881
+ *
882
+ * Unless required by applicable law or agreed to in writing, software distributed under
883
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
884
+ * OF ANY KIND, either express or implied. See the License for the specific language
885
+ * governing permissions and limitations under the License.
886
+ */
887
+ function $70d70eb16ea48428$var$Row(props) {
888
+ return null;
889
+ }
890
+ $70d70eb16ea48428$var$Row.getCollectionNode = function* getCollectionNode(props, context) {
891
+ let { children: children , textValue: textValue } = props;
892
+ yield {
893
+ type: "item",
894
+ props: props,
895
+ textValue: textValue,
896
+ "aria-label": props["aria-label"],
897
+ hasChildNodes: true,
898
+ *childNodes () {
899
+ // Process cells first
900
+ if (context.showSelectionCheckboxes && context.selectionMode !== "none") yield {
901
+ type: "cell",
902
+ key: "header",
903
+ props: {
904
+ isSelectionCell: true
905
+ }
906
+ };
907
+ if (typeof children === "function") for (let column of context.columns)yield {
908
+ type: "cell",
909
+ element: children(column.key),
910
+ key: column.key // this is combined with the row key by CollectionBuilder
911
+ };
912
+ else {
913
+ let cells = [];
914
+ (0, $1BfjW$react).Children.forEach(children, (cell)=>{
915
+ cells.push({
916
+ type: "cell",
917
+ element: cell
918
+ });
919
+ });
920
+ if (cells.length !== context.columns.length) throw new Error(`Cell count must match column count. Found ${cells.length} cells and ${context.columns.length} columns.`);
921
+ yield* cells;
922
+ }
923
+ },
924
+ shouldInvalidate (newContext) {
925
+ // Invalidate all rows if the columns changed.
926
+ return newContext.columns.length !== context.columns.length || newContext.columns.some((c, i)=>c.key !== context.columns[i].key) || newContext.showSelectionCheckboxes !== context.showSelectionCheckboxes || newContext.selectionMode !== context.selectionMode;
927
+ }
928
+ };
929
+ };
930
+ /**
931
+ * A Row represents a single item in a Table and contains Cell elements for each column.
932
+ * Cells can be statically defined as children, or generated dynamically using a function
933
+ * based on the columns defined in the TableHeader.
934
+ */ // We don't want getCollectionNode to show up in the type definition
935
+ let $70d70eb16ea48428$export$b59bdbef9ce70de2 = $70d70eb16ea48428$var$Row;
936
+
937
+
938
+ /*
939
+ * Copyright 2020 Adobe. All rights reserved.
940
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
941
+ * you may not use this file except in compliance with the License. You may obtain a copy
942
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
943
+ *
944
+ * Unless required by applicable law or agreed to in writing, software distributed under
945
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
946
+ * OF ANY KIND, either express or implied. See the License for the specific language
947
+ * governing permissions and limitations under the License.
948
+ */ function $941d1d9a6a28982a$var$Cell(props) {
949
+ return null;
950
+ }
951
+ $941d1d9a6a28982a$var$Cell.getCollectionNode = function* getCollectionNode(props) {
952
+ let { children: children } = props;
953
+ let textValue = props.textValue || (typeof children === "string" ? children : "") || props["aria-label"] || "";
954
+ yield {
955
+ type: "cell",
956
+ props: props,
957
+ rendered: children,
958
+ textValue: textValue,
959
+ "aria-label": props["aria-label"],
960
+ hasChildNodes: false
961
+ };
962
+ };
963
+ /**
964
+ * A Cell represents the value of a single Column within a Table Row.
965
+ */ // We don't want getCollectionNode to show up in the type definition
966
+ let $941d1d9a6a28982a$export$f6f0c3fe4ec306ea = $941d1d9a6a28982a$var$Cell;
967
+
968
+
969
+
970
+
971
+
972
+
973
+
974
+ export {$292bc4e09cd0eb62$export$cb895dcf85db1319 as useTableColumnResizeState, $4a0dd036d492cee4$export$907bcc6c48325fd6 as useTableState, $312ae3b56a94a86e$export$f850895b287ef28e as TableHeader, $4ae5314bf50db1a3$export$76ccd210b9029917 as TableBody, $1cd244557c2f97d5$export$816b5d811295e6bc as Column, $70d70eb16ea48428$export$b59bdbef9ce70de2 as Row, $941d1d9a6a28982a$export$f6f0c3fe4ec306ea as Cell, $6555104ff085bef4$re_export$Section as Section, $788781baa30117fa$export$596e1b2e2cf93690 as TableCollection, $a9e7ae544a4e41dd$export$7ff77a162970b30e as TableColumnLayout};
975
+ //# sourceMappingURL=module.js.map