@react-stately/table 3.6.1-nightly.3608 → 3.6.1-nightly.3617

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var $56JBj$reactstatelycollections = require("@react-stately/collections");
2
2
  var $56JBj$react = require("react");
3
+ var $56JBj$swchelperslib_define_propertyjs = require("@swc/helpers/lib/_define_property.js");
3
4
  var $56JBj$reactstatelygrid = require("@react-stately/grid");
4
5
 
5
6
  function $parcel$export(e, n, v, s) {
@@ -18,6 +19,7 @@ $parcel$export(module.exports, "Row", () => $9ec6912e32cc0d81$export$b59bdbef9ce
18
19
  $parcel$export(module.exports, "Cell", () => $ad4ab0a21c733e1f$export$f6f0c3fe4ec306ea);
19
20
  $parcel$export(module.exports, "Section", () => $56JBj$reactstatelycollections.Section);
20
21
  $parcel$export(module.exports, "TableCollection", () => $7f5a58334d8866a5$export$596e1b2e2cf93690);
22
+ $parcel$export(module.exports, "TableColumnLayout", () => $2240a72410c17d51$export$7ff77a162970b30e);
21
23
  /*
22
24
  * Copyright 2020 Adobe. All rights reserved.
23
25
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -28,251 +30,369 @@ $parcel$export(module.exports, "TableCollection", () => $7f5a58334d8866a5$export
28
30
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
29
31
  * OF ANY KIND, either express or implied. See the License for the specific language
30
32
  * governing permissions and limitations under the License.
31
- */ function $3122b463430f41b1$export$f61abf052f87399f(widths) {
32
- return Array.from(widths).map((e)=>e[1]).reduce((acc, cur)=>acc + cur, 0);
33
- }
34
- function $3122b463430f41b1$export$1994a077b98ee0d5(width) {
33
+ */ /*
34
+ * Copyright 2022 Adobe. All rights reserved.
35
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
36
+ * you may not use this file except in compliance with the License. You may obtain a copy
37
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
38
+ *
39
+ * Unless required by applicable law or agreed to in writing, software distributed under
40
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
41
+ * OF ANY KIND, either express or implied. See the License for the specific language
42
+ * governing permissions and limitations under the License.
43
+ */
44
+ /*
45
+ * Copyright 2022 Adobe. All rights reserved.
46
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
47
+ * you may not use this file except in compliance with the License. You may obtain a copy
48
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
49
+ *
50
+ * Unless required by applicable law or agreed to in writing, software distributed under
51
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
52
+ * OF ANY KIND, either express or implied. See the License for the specific language
53
+ * governing permissions and limitations under the License.
54
+ */
55
+ /*
56
+ * Copyright 2022 Adobe. All rights reserved.
57
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
58
+ * you may not use this file except in compliance with the License. You may obtain a copy
59
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
60
+ *
61
+ * Unless required by applicable law or agreed to in writing, software distributed under
62
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
63
+ * OF ANY KIND, either express or implied. See the License for the specific language
64
+ * governing permissions and limitations under the License.
65
+ */ function $9e5f6a0caf75716e$export$1994a077b98ee0d5(width) {
35
66
  return width != null && (!isNaN(width) || String(width).match(/^(\d+)(?=%$)/) !== null);
36
67
  }
37
- function $3122b463430f41b1$var$parseFractionalUnit(width) {
68
+ function $9e5f6a0caf75716e$export$9078bad4c3934604(width) {
38
69
  if (!width) return 1;
39
- let match = width.match(/^(\d+)(?=fr$)/);
40
- // if width is the incorrect format, just deafult it to a 1fr
70
+ let match = width.match(/^(.+)(?=fr$)/);
71
+ // if width is the incorrect format, just default it to a 1fr
41
72
  if (!match) {
42
73
  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'");
43
74
  return 1;
44
75
  }
45
- return parseInt(match[0], 10);
76
+ return parseFloat(match[0]);
46
77
  }
47
- function $3122b463430f41b1$export$7bbad27896f7ae9f(width, tableWidth) {
78
+ function $9e5f6a0caf75716e$export$7bbad27896f7ae9f(width, tableWidth) {
48
79
  if (typeof width === "string") {
49
80
  let match = width.match(/^(\d+)(?=%$)/);
50
81
  if (!match) throw new Error("Only percentages or numbers are supported for static column widths");
51
- return tableWidth * (parseInt(match[0], 10) / 100);
82
+ return tableWidth * (parseFloat(match[0]) / 100);
52
83
  }
53
84
  return width;
54
85
  }
55
- function $3122b463430f41b1$export$59185c62a7544aa0(maxWidth, tableWidth) {
56
- return maxWidth != null ? $3122b463430f41b1$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
86
+ function $9e5f6a0caf75716e$export$59185c62a7544aa0(maxWidth, tableWidth) {
87
+ return maxWidth != null ? $9e5f6a0caf75716e$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
57
88
  }
58
- function $3122b463430f41b1$export$f556054ce4358701(minWidth, tableWidth) {
59
- return minWidth != null ? $3122b463430f41b1$export$7bbad27896f7ae9f(minWidth, tableWidth) : 75;
89
+ function $9e5f6a0caf75716e$export$f556054ce4358701(minWidth, tableWidth) {
90
+ return minWidth != null ? $9e5f6a0caf75716e$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
60
91
  }
61
- function $3122b463430f41b1$var$mapDynamicColumns(dynamicColumns, availableSpace, tableWidth) {
62
- let fractions = dynamicColumns.reduce((sum, column)=>sum + $3122b463430f41b1$var$parseFractionalUnit(column.props.defaultWidth), 0);
63
- let columns = dynamicColumns.map((column, index)=>{
64
- const targetWidth = $3122b463430f41b1$var$parseFractionalUnit(column.props.defaultWidth) * availableSpace / fractions;
65
- const delta = Math.max($3122b463430f41b1$export$f556054ce4358701(column.props.minWidth, tableWidth) - targetWidth, targetWidth - $3122b463430f41b1$export$59185c62a7544aa0(column.props.maxWidth, tableWidth));
92
+ // tell us the delta between min width and target width vs max width and target width
93
+ function $9e5f6a0caf75716e$var$mapDynamicColumns(dynamicColumns, availableSpace, tableWidth) {
94
+ let fractions = dynamicColumns.reduce((sum, column)=>column ? sum + $9e5f6a0caf75716e$export$9078bad4c3934604(column.column.width || column.column.defaultWidth) : sum, 0);
95
+ let columns = dynamicColumns.map((column)=>{
96
+ if (!column) return null;
97
+ const targetWidth = $9e5f6a0caf75716e$export$9078bad4c3934604(column.column.width || column.column.defaultWidth) * availableSpace / fractions;
98
+ const delta = Math.max($9e5f6a0caf75716e$export$f556054ce4358701(column.column.minWidth, tableWidth) - targetWidth, targetWidth - $9e5f6a0caf75716e$export$59185c62a7544aa0(column.column.maxWidth, tableWidth));
66
99
  return {
67
100
  ...column,
68
- index: index,
69
101
  delta: delta
70
102
  };
71
103
  });
72
104
  return columns;
73
105
  }
74
- function $3122b463430f41b1$var$findDynamicColumnWidths(dynamicColumns, availableSpace, tableWidth) {
75
- let fractions = dynamicColumns.reduce((sum, col)=>sum + $3122b463430f41b1$var$parseFractionalUnit(col.props.defaultWidth), 0);
76
- const columns = dynamicColumns.map((column)=>{
77
- const targetWidth = $3122b463430f41b1$var$parseFractionalUnit(column.props.defaultWidth) * availableSpace / fractions;
78
- let width = Math.max($3122b463430f41b1$export$f556054ce4358701(column.props.minWidth, tableWidth), Math.min(Math.floor(targetWidth), $3122b463430f41b1$export$59185c62a7544aa0(column.props.maxWidth, tableWidth)));
79
- column.calculatedWidth = width;
106
+ // mutates columns to set their width
107
+ function $9e5f6a0caf75716e$var$findDynamicColumnWidths(dynamicColumns, availableSpace, tableWidth) {
108
+ let fractions = dynamicColumns.reduce((sum, col)=>col ? sum + col.width : sum, 0);
109
+ dynamicColumns.forEach((column)=>{
110
+ if (!column) return null;
111
+ const targetWidth = column.width * availableSpace / fractions;
112
+ let width = Math.max($9e5f6a0caf75716e$export$f556054ce4358701(column.column.minWidth, tableWidth), Math.min(Math.round(targetWidth), $9e5f6a0caf75716e$export$59185c62a7544aa0(column.column.maxWidth, tableWidth)));
80
113
  availableSpace -= width;
81
- fractions -= $3122b463430f41b1$var$parseFractionalUnit(column.props.defaultWidth);
82
- return column;
114
+ fractions -= column.width;
115
+ column.width = width;
83
116
  });
84
- return columns;
85
117
  }
86
- function $3122b463430f41b1$export$a870e6692ac5ccb2(dynamicColumns, availableSpace, tableWidth) {
87
- let columns = $3122b463430f41b1$var$mapDynamicColumns(dynamicColumns, availableSpace, tableWidth);
88
- columns.sort((a, b)=>b.delta - a.delta);
89
- columns = $3122b463430f41b1$var$findDynamicColumnWidths(columns, availableSpace, tableWidth);
90
- columns.sort((a, b)=>a.index - b.index);
118
+ function $9e5f6a0caf75716e$export$a870e6692ac5ccb2(dynamicColumns, availableSpace, tableWidth) {
119
+ let columns = $9e5f6a0caf75716e$var$mapDynamicColumns(dynamicColumns, availableSpace, tableWidth);
120
+ // sort is nlogn and copying is n, so copying and sorting is faster than sorting twice
121
+ // sort by delta's to prioritize assigning width
122
+ let sorted = [
123
+ ...columns
124
+ ].sort((a, b)=>{
125
+ if (a && b) return b.delta - a.delta;
126
+ return a ? -1 : 1;
127
+ });
128
+ // this function mutates the column entries, so no need to have it return anything
129
+ // plus we don't need to undo the sort since we already have the correct order
130
+ $9e5f6a0caf75716e$var$findDynamicColumnWidths(sorted, availableSpace, tableWidth);
91
131
  return columns;
92
132
  }
133
+ function $9e5f6a0caf75716e$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
134
+ let remainingSpace = availableWidth;
135
+ let { staticColumns: staticColumns , dynamicColumns: dynamicColumns } = columns.reduce((acc, column, index)=>{
136
+ var _column_width, _ref, _ref1;
137
+ 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";
138
+ var _column_minWidth;
139
+ let minWidth = (_column_minWidth = column.minWidth) !== null && _column_minWidth !== void 0 ? _column_minWidth : getDefaultMinWidth === null || getDefaultMinWidth === void 0 ? void 0 : getDefaultMinWidth(index);
140
+ column.minWidth = minWidth;
141
+ if ($9e5f6a0caf75716e$export$1994a077b98ee0d5(width)) {
142
+ let w = $9e5f6a0caf75716e$export$7bbad27896f7ae9f(width, availableWidth);
143
+ w = Math.max($9e5f6a0caf75716e$export$f556054ce4358701(column.minWidth, availableWidth), Math.min(Math.floor(w), $9e5f6a0caf75716e$export$59185c62a7544aa0(column.maxWidth, availableWidth)));
144
+ acc.staticColumns.push({
145
+ index: index,
146
+ column: column,
147
+ width: w
148
+ });
149
+ acc.dynamicColumns.push(null);
150
+ remainingSpace -= w;
151
+ } else {
152
+ let w1 = $9e5f6a0caf75716e$export$9078bad4c3934604(width);
153
+ acc.staticColumns.push(null);
154
+ acc.dynamicColumns.push({
155
+ index: index,
156
+ column: column,
157
+ width: w1
158
+ });
159
+ }
160
+ return acc;
161
+ }, {
162
+ staticColumns: [],
163
+ dynamicColumns: []
164
+ });
165
+ let newColWidths = $9e5f6a0caf75716e$export$a870e6692ac5ccb2(dynamicColumns, remainingSpace, availableWidth);
166
+ return staticColumns.map((col, i)=>{
167
+ if (col) return col.width;
168
+ return newColWidths[i].width;
169
+ });
170
+ }
93
171
 
94
172
 
95
-
96
- function $7aa22d80cd4ca621$export$cb895dcf85db1319(props, state) {
97
- const { getDefaultWidth: getDefaultWidth , tableWidth: defaultTableWidth = null } = props;
98
- const { columns: columns } = state;
99
- const columnsRef = (0, $56JBj$react.useRef)([]);
100
- const tableWidth = (0, $56JBj$react.useRef)(defaultTableWidth);
101
- const isResizing = (0, $56JBj$react.useRef)(null);
102
- const startResizeContentWidth = (0, $56JBj$react.useRef)();
103
- const [columnWidths, setColumnWidths] = (0, $56JBj$react.useState)(new Map(columns.map((col)=>[
104
- col.key,
105
- 0
106
- ])));
107
- const columnWidthsRef = (0, $56JBj$react.useRef)(columnWidths);
108
- const affectedColumnWidthsRef = (0, $56JBj$react.useRef)([]);
109
- const [resizedColumns, setResizedColumns] = (0, $56JBj$react.useState)(new Set());
110
- const resizedColumnsRef = (0, $56JBj$react.useRef)(resizedColumns);
111
- const [currentlyResizingColumn, setCurrentlyResizingColumn] = (0, $56JBj$react.useState)(null);
112
- function setColumnWidthsForRef(newWidths) {
113
- columnWidthsRef.current = newWidths;
114
- // new map so that change detection is triggered
115
- setColumnWidths(newWidths);
173
+ class $2240a72410c17d51$export$7ff77a162970b30e {
174
+ /** Takes an array of columns and splits it into 2 maps of columns with controlled and columns with uncontrolled widths. */ splitColumnsIntoControlledAndUncontrolled(columns) {
175
+ return columns.reduce((acc, col)=>{
176
+ if (col.props.width != null) acc[0].set(col.key, col);
177
+ else acc[1].set(col.key, col);
178
+ return acc;
179
+ }, [
180
+ new Map(),
181
+ new Map()
182
+ ]);
116
183
  }
117
- /*
118
- returns the resolved column width in this order:
119
- previously calculated width -> controlled width prop -> uncontrolled defaultWidth prop -> dev assigned width -> default dynamic width
120
- */ let getResolvedColumnWidth = (0, $56JBj$react.useCallback)((column)=>{
121
- let columnProps = column.props;
122
- var _width, ref, ref1;
123
- return (resizedColumns === null || resizedColumns === void 0 ? void 0 : resizedColumns.has(column.key)) ? columnWidthsRef.current.get(column.key) : (ref1 = (ref = (_width = columnProps.width) !== null && _width !== void 0 ? _width : columnProps.defaultWidth) !== null && ref !== void 0 ? ref : getDefaultWidth === null || getDefaultWidth === void 0 ? void 0 : getDefaultWidth(column.props)) !== null && ref1 !== void 0 ? ref1 : "1fr";
124
- }, [
125
- getDefaultWidth,
126
- resizedColumns
127
- ]);
128
- let getStaticAndDynamicColumns = (0, $56JBj$react.useCallback)((columns)=>columns.reduce((acc, column)=>{
129
- let width = getResolvedColumnWidth(column);
130
- return (0, $3122b463430f41b1$export$1994a077b98ee0d5)(width) ? {
131
- ...acc,
132
- staticColumns: [
133
- ...acc.staticColumns,
134
- column
135
- ]
136
- } : {
137
- ...acc,
138
- dynamicColumns: [
139
- ...acc.dynamicColumns,
140
- column
141
- ]
142
- };
143
- }, {
144
- staticColumns: [],
145
- dynamicColumns: []
146
- }), [
147
- getResolvedColumnWidth
148
- ]);
149
- let buildColumnWidths = (0, $56JBj$react.useCallback)((affectedColumns, availableSpace)=>{
150
- const widths = new Map();
151
- let remainingSpace = availableSpace;
152
- const { staticColumns: staticColumns , dynamicColumns: dynamicColumns } = getStaticAndDynamicColumns(affectedColumns);
153
- staticColumns.forEach((column)=>{
154
- let width = getResolvedColumnWidth(column);
155
- let w = (0, $3122b463430f41b1$export$7bbad27896f7ae9f)(width, tableWidth.current);
156
- widths.set(column.key, w);
157
- remainingSpace -= w;
158
- });
159
- // dynamic columns
160
- if (dynamicColumns.length > 0) {
161
- const newColumnWidths = (0, $3122b463430f41b1$export$a870e6692ac5ccb2)(dynamicColumns, remainingSpace, tableWidth.current);
162
- for (let column of newColumnWidths)widths.set(column.key, column.calculatedWidth);
163
- }
164
- return widths;
165
- }, [
166
- getStaticAndDynamicColumns,
167
- getResolvedColumnWidth
168
- ]);
169
- const prevColKeys = columnsRef.current.map((col)=>col.key);
170
- const colKeys = columns.map((col)=>col.key);
171
- // if the columns change, need to rebuild widths.
172
- if (prevColKeys.length !== colKeys.length || !colKeys.every((col, i)=>col === prevColKeys[i])) {
173
- columnsRef.current = columns;
174
- const widths = buildColumnWidths(columns, tableWidth.current);
175
- setColumnWidthsForRef(widths);
184
+ /** Takes uncontrolled and controlled widths and joins them into a single Map. */ recombineColumns(columns, uncontrolledWidths, uncontrolledColumns, controlledColumns) {
185
+ return new Map(columns.map((col)=>{
186
+ if (uncontrolledColumns.has(col.key)) return [
187
+ col.key,
188
+ uncontrolledWidths.get(col.key)
189
+ ];
190
+ else return [
191
+ col.key,
192
+ controlledColumns.get(col.key).props.width
193
+ ];
194
+ }));
176
195
  }
177
- function setTableWidth(width) {
178
- if (width && width !== tableWidth.current) {
179
- tableWidth.current = width;
180
- if (!isResizing.current) {
181
- const widths = buildColumnWidths(columns, width);
182
- setColumnWidthsForRef(widths);
183
- }
184
- }
196
+ /** Used to make an initial Map of the uncontrolled widths based on default widths. */ getInitialUncontrolledWidths(uncontrolledColumns) {
197
+ var _col_props_defaultWidth, _ref;
198
+ return new Map(Array.from(uncontrolledColumns).map(([key, col])=>{
199
+ var _this, _this_getDefaultWidth;
200
+ return [
201
+ key,
202
+ (_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"
203
+ ];
204
+ }));
185
205
  }
186
- function onColumnResizeStart(column) {
187
- setCurrentlyResizingColumn(column.key);
188
- isResizing.current = true;
189
- startResizeContentWidth.current = (0, $3122b463430f41b1$export$f61abf052f87399f)(columnWidthsRef.current);
206
+ getColumnWidth(key) {
207
+ var _this_columnWidths_get;
208
+ return (_this_columnWidths_get = this.columnWidths.get(key)) !== null && _this_columnWidths_get !== void 0 ? _this_columnWidths_get : 0;
190
209
  }
191
- function onColumnResize(column, width) {
192
- let widthsObj = resizeColumn(column, width);
193
- affectedColumnWidthsRef.current = widthsObj;
194
- props.onColumnResize && props.onColumnResize(affectedColumnWidthsRef.current);
210
+ getColumnMinWidth(key) {
211
+ return this.columnMinWidths.get(key);
195
212
  }
196
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
197
- function onColumnResizeEnd(column) {
198
- props.onColumnResizeEnd && isResizing.current && props.onColumnResizeEnd(affectedColumnWidthsRef.current);
199
- setCurrentlyResizingColumn(null);
200
- isResizing.current = false;
201
- affectedColumnWidthsRef.current = [];
202
- let widths = new Map(columnWidthsRef.current);
203
- setColumnWidthsForRef(widths);
213
+ getColumnMaxWidth(key) {
214
+ return this.columnMaxWidths.get(key);
204
215
  }
205
- function resizeColumn(column, newWidth) {
206
- let boundedWidth = Math.max((0, $3122b463430f41b1$export$f556054ce4358701)(column.props.minWidth, tableWidth.current), Math.min(Math.floor(newWidth), (0, $3122b463430f41b1$export$59185c62a7544aa0)(column.props.maxWidth, tableWidth.current)));
207
- // copy the columnWidths map and set the new width for the column being resized
208
- let widths = new Map(columnWidthsRef.current);
209
- widths.set(column.key, boundedWidth);
210
- // keep track of all columns that have been sized
211
- resizedColumnsRef.current.add(column.key);
212
- setResizedColumns(resizedColumnsRef.current);
213
- // get the columns affected by resize and remaining space
214
- const resizeIndex = columnsRef.current.findIndex((col)=>col.key === column.key);
215
- let affectedColumns = columnsRef.current.slice(resizeIndex + 1);
216
- // we only care about the columns that CAN be resized, we ignore static columns.
217
- let { dynamicColumns: dynamicColumns } = getStaticAndDynamicColumns(affectedColumns);
218
- // available space for affected columns
219
- let availableSpace = columnsRef.current.reduce((acc, column, index)=>{
220
- if (index <= resizeIndex || (0, $3122b463430f41b1$export$1994a077b98ee0d5)(getResolvedColumnWidth(column))) return acc - widths.get(column.key);
221
- return acc;
222
- }, tableWidth.current);
223
- // merge the unaffected column widths and the recalculated column widths
224
- let recalculatedColumnWidths = buildColumnWidths(dynamicColumns, availableSpace);
225
- widths = new Map([
226
- ...widths,
227
- ...recalculatedColumnWidths
228
- ]);
229
- setColumnWidthsForRef(widths);
230
- /*
231
- when getting recalculated columns above, the column being resized is not considered "recalculated"
232
- so we need to add it to the list of affected columns
233
- */ let allAffectedColumns = [
234
- [
235
- column.key,
236
- boundedWidth
237
- ],
238
- ...recalculatedColumnWidths
239
- ].map(([key, width])=>({
240
- key: key,
241
- width: width
242
- }));
243
- return allAffectedColumns;
216
+ resizeColumnWidth(tableWidth, collection, controlledWidths, uncontrolledWidths, col = null, width) {
217
+ let prevColumnWidths = this.columnWidths;
218
+ // resizing a column
219
+ let resizeIndex = Infinity;
220
+ let controlledArray = Array.from(controlledWidths);
221
+ let uncontrolledArray = Array.from(uncontrolledWidths);
222
+ let combinedArray = controlledArray.concat(uncontrolledArray);
223
+ let resizingChanged = new Map(combinedArray);
224
+ let frKeys = new Map();
225
+ let percentKeys = new Map();
226
+ let frKeysToTheRight = new Map();
227
+ let minWidths = new Map();
228
+ // freeze columns to the left to their previous pixel value
229
+ // at the same time count how many total FR's are in play and which of those FRs are
230
+ // to the right or left of the resizing column
231
+ collection.columns.forEach((column, i)=>{
232
+ var _column_column_props_width, _column_column_props_width_endsWith;
233
+ let frKey;
234
+ minWidths.set(column.key, this.getDefaultMinWidth(collection.columns[i]));
235
+ if (col !== column.key && !column.column.props.width && !(0, $9e5f6a0caf75716e$export$1994a077b98ee0d5)(uncontrolledWidths.get(column.key))) {
236
+ // uncontrolled don't have props.width for us, so instead get from our state
237
+ frKey = column.key;
238
+ frKeys.set(column.key, (0, $9e5f6a0caf75716e$export$9078bad4c3934604)(uncontrolledWidths.get(column.key)));
239
+ } else if (col !== column.key && !(0, $9e5f6a0caf75716e$export$1994a077b98ee0d5)(column.column.props.width) && !uncontrolledWidths.get(column.key)) {
240
+ // controlledWidths will be the same in the collection
241
+ frKey = column.key;
242
+ frKeys.set(column.key, (0, $9e5f6a0caf75716e$export$9078bad4c3934604)(column.column.props.width));
243
+ } 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);
244
+ // don't freeze columns to the right of the resizing one
245
+ if (resizeIndex < i) {
246
+ if (frKey) frKeysToTheRight.set(frKey, frKeys.get(frKey));
247
+ return;
248
+ }
249
+ // we already know the new size of the resizing column
250
+ if (column.key === col) {
251
+ resizeIndex = i;
252
+ return;
253
+ }
254
+ // freeze column to previous value
255
+ resizingChanged.set(column.key, prevColumnWidths.get(column.key));
256
+ });
257
+ resizingChanged.set(col, Math.floor(width));
258
+ // predict pixels sizes for all columns based on resize
259
+ let columnWidths = (0, $9e5f6a0caf75716e$export$55d50dc687385491)(tableWidth, collection.columns.map((col)=>({
260
+ ...col.column.props,
261
+ key: col.key
262
+ })), resizingChanged, (i)=>this.getDefaultWidth(collection.columns[i]), (i)=>this.getDefaultMinWidth(collection.columns[i]));
263
+ // set all new column widths for onResize event
264
+ // columns going in will be the same order as the columns coming out
265
+ let newWidths = new Map();
266
+ // set all column widths based on calculateColumnSize
267
+ columnWidths.forEach((width, index)=>{
268
+ let key = collection.columns[index].key;
269
+ newWidths.set(key, width);
270
+ });
271
+ // add FR's back as they were to columns to the right
272
+ Array.from(frKeys).forEach(([key])=>{
273
+ if (frKeysToTheRight.has(key)) newWidths.set(key, `${frKeysToTheRight.get(key)}fr`);
274
+ });
275
+ // put back in percents
276
+ Array.from(percentKeys).forEach(([key, width])=>{
277
+ // resizing locks a column to a px width
278
+ if (key === col) return;
279
+ newWidths.set(key, width);
280
+ });
281
+ return newWidths;
282
+ }
283
+ buildColumnWidths(tableWidth, collection, widths) {
284
+ this.columnWidths = new Map();
285
+ this.columnMinWidths = new Map();
286
+ this.columnMaxWidths = new Map();
287
+ // initial layout or table/window resizing
288
+ let columnWidths = (0, $9e5f6a0caf75716e$export$55d50dc687385491)(tableWidth, collection.columns.map((col)=>({
289
+ ...col.column.props,
290
+ key: col.key
291
+ })), widths, (i)=>this.getDefaultWidth(collection.columns[i]), (i)=>this.getDefaultMinWidth(collection.columns[i]));
292
+ // columns going in will be the same order as the columns coming out
293
+ columnWidths.forEach((width, index)=>{
294
+ let key = collection.columns[index].key;
295
+ let column = collection.columns[index];
296
+ this.columnWidths.set(key, width);
297
+ var _column_column_props_minWidth;
298
+ this.columnMinWidths.set(key, (0, $9e5f6a0caf75716e$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));
299
+ this.columnMaxWidths.set(key, (0, $9e5f6a0caf75716e$export$59185c62a7544aa0)(column.column.props.maxWidth, tableWidth));
300
+ });
301
+ return this.columnWidths;
244
302
  }
245
- var ref;
246
- // This function is regenerated whenever columnWidthsRef.current changes in order to get the new correct ref value.
247
- // eslint-disable-next-line react-hooks/exhaustive-deps
248
- let getColumnWidth = (0, $56JBj$react.useCallback)((key)=>(ref = columnWidthsRef.current.get(key)) !== null && ref !== void 0 ? ref : 0, [
249
- columnWidthsRef.current
303
+ constructor(options){
304
+ (0, ($parcel$interopDefault($56JBj$swchelperslib_define_propertyjs)))(this, "columnWidths", new Map());
305
+ (0, ($parcel$interopDefault($56JBj$swchelperslib_define_propertyjs)))(this, "columnMinWidths", new Map());
306
+ (0, ($parcel$interopDefault($56JBj$swchelperslib_define_propertyjs)))(this, "columnMaxWidths", new Map());
307
+ this.getDefaultWidth = options.getDefaultWidth;
308
+ this.getDefaultMinWidth = options.getDefaultMinWidth;
309
+ }
310
+ }
311
+
312
+
313
+ function $7aa22d80cd4ca621$export$cb895dcf85db1319(props, state) {
314
+ let { getDefaultWidth: getDefaultWidth , getDefaultMinWidth: getDefaultMinWidth , onColumnResizeStart: propsOnColumnResizeStart , onColumnResizeEnd: propsOnColumnResizeEnd , tableWidth: tableWidth = 0 } = props;
315
+ let [resizingColumn, setResizingColumn] = (0, $56JBj$react.useState)(null);
316
+ let columnLayout = (0, $56JBj$react.useMemo)(()=>new (0, $2240a72410c17d51$export$7ff77a162970b30e)({
317
+ getDefaultWidth: getDefaultWidth,
318
+ getDefaultMinWidth: getDefaultMinWidth
319
+ }), [
320
+ getDefaultWidth,
321
+ getDefaultMinWidth
322
+ ]);
323
+ let [controlledColumns, uncontrolledColumns] = (0, $56JBj$react.useMemo)(()=>columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns), [
324
+ state.collection.columns,
325
+ columnLayout
326
+ ]);
327
+ // uncontrolled column widths
328
+ let [uncontrolledWidths, setUncontrolledWidths] = (0, $56JBj$react.useState)(()=>columnLayout.getInitialUncontrolledWidths(uncontrolledColumns));
329
+ // combine columns back into one map that maintains same order as the columns
330
+ let colWidths = (0, $56JBj$react.useMemo)(()=>columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns), [
331
+ state.collection.columns,
332
+ uncontrolledWidths,
333
+ uncontrolledColumns,
334
+ controlledColumns,
335
+ columnLayout
250
336
  ]);
251
- let getColumnMinWidth = (0, $56JBj$react.useCallback)((key)=>{
252
- const columnIndex = columns.findIndex((col)=>col.key === key);
253
- if (columnIndex === -1) return;
254
- return (0, $3122b463430f41b1$export$f556054ce4358701)(columns[columnIndex].props.minWidth, tableWidth.current);
337
+ let onColumnResizeStart = (0, $56JBj$react.useCallback)((key)=>{
338
+ setResizingColumn(key);
339
+ propsOnColumnResizeStart === null || propsOnColumnResizeStart === void 0 ? void 0 : propsOnColumnResizeStart(key);
255
340
  }, [
256
- columns
341
+ propsOnColumnResizeStart,
342
+ setResizingColumn
257
343
  ]);
258
- let getColumnMaxWidth = (0, $56JBj$react.useCallback)((key)=>{
259
- const columnIndex = columns.findIndex((col)=>col.key === key);
260
- if (columnIndex === -1) return;
261
- return (0, $3122b463430f41b1$export$59185c62a7544aa0)(columns[columnIndex].props.maxWidth, tableWidth.current);
344
+ let onColumnResize = (0, $56JBj$react.useCallback)((key, width)=>{
345
+ let newControlled = new Map(Array.from(controlledColumns).map(([key, entry])=>[
346
+ key,
347
+ entry.props.width
348
+ ]));
349
+ let newSizes = columnLayout.resizeColumnWidth(tableWidth, state.collection, newControlled, uncontrolledWidths, key, width);
350
+ let map = new Map(Array.from(uncontrolledColumns).map(([key])=>[
351
+ key,
352
+ newSizes.get(key)
353
+ ]));
354
+ map.set(key, width);
355
+ setUncontrolledWidths(map);
356
+ return newSizes;
262
357
  }, [
263
- columns
358
+ controlledColumns,
359
+ uncontrolledColumns,
360
+ setUncontrolledWidths,
361
+ tableWidth,
362
+ columnLayout,
363
+ state.collection,
364
+ uncontrolledWidths
365
+ ]);
366
+ let onColumnResizeEnd = (0, $56JBj$react.useCallback)((key)=>{
367
+ setResizingColumn(null);
368
+ propsOnColumnResizeEnd === null || propsOnColumnResizeEnd === void 0 ? void 0 : propsOnColumnResizeEnd(key);
369
+ }, [
370
+ propsOnColumnResizeEnd,
371
+ setResizingColumn
372
+ ]);
373
+ let columnWidths = (0, $56JBj$react.useMemo)(()=>columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths), [
374
+ tableWidth,
375
+ state.collection,
376
+ colWidths,
377
+ columnLayout
378
+ ]);
379
+ return (0, $56JBj$react.useMemo)(()=>({
380
+ resizingColumn: resizingColumn,
381
+ onColumnResize: onColumnResize,
382
+ onColumnResizeStart: onColumnResizeStart,
383
+ onColumnResizeEnd: onColumnResizeEnd,
384
+ getColumnWidth: (key)=>columnLayout.getColumnWidth(key),
385
+ getColumnMinWidth: (key)=>columnLayout.getColumnMinWidth(key),
386
+ getColumnMaxWidth: (key)=>columnLayout.getColumnMaxWidth(key),
387
+ widths: columnWidths
388
+ }), [
389
+ columnLayout,
390
+ resizingColumn,
391
+ onColumnResize,
392
+ onColumnResizeStart,
393
+ onColumnResizeEnd,
394
+ columnWidths
264
395
  ]);
265
- return {
266
- columnWidths: columnWidthsRef,
267
- setTableWidth: setTableWidth,
268
- onColumnResize: onColumnResize,
269
- onColumnResizeStart: onColumnResizeStart,
270
- onColumnResizeEnd: onColumnResizeEnd,
271
- getColumnWidth: getColumnWidth,
272
- getColumnMinWidth: getColumnMinWidth,
273
- getColumnMaxWidth: getColumnMaxWidth,
274
- currentlyResizingColumn: currentlyResizingColumn
275
- };
276
396
  }
277
397
 
278
398
 
@@ -299,6 +419,7 @@ function $7aa22d80cd4ca621$export$cb895dcf85db1319(props, state) {
299
419
  * OF ANY KIND, either express or implied. See the License for the specific language
300
420
  * governing permissions and limitations under the License.
301
421
  */
422
+
302
423
  const $7f5a58334d8866a5$var$ROW_HEADER_COLUMN_KEY = "row-header-column-" + Math.random().toString(36).slice(2);
303
424
  function $7f5a58334d8866a5$var$buildHeaderRows(keyMap, columnNodes) {
304
425
  let columns = [];
@@ -415,14 +536,13 @@ function $7f5a58334d8866a5$var$buildHeaderRows(keyMap, columnNodes) {
415
536
  return row;
416
537
  });
417
538
  }
539
+ let $7f5a58334d8866a5$var$_Symbol_iterator = Symbol.iterator;
418
540
  class $7f5a58334d8866a5$export$596e1b2e2cf93690 extends (0, $56JBj$reactstatelygrid.GridCollection) {
419
- *[Symbol.iterator]() {
541
+ *[$7f5a58334d8866a5$var$_Symbol_iterator]() {
420
542
  yield* this.body.childNodes;
421
543
  }
422
544
  get size() {
423
- return [
424
- ...this.body.childNodes
425
- ].length;
545
+ return this._size;
426
546
  }
427
547
  getKeys() {
428
548
  return this.keyMap.keys();
@@ -436,17 +556,17 @@ class $7f5a58334d8866a5$export$596e1b2e2cf93690 extends (0, $56JBj$reactstatelyg
436
556
  return node ? node.nextKey : null;
437
557
  }
438
558
  getFirstKey() {
439
- var ref;
440
- return (ref = [
559
+ var _;
560
+ return (_ = [
441
561
  ...this.body.childNodes
442
- ][0]) === null || ref === void 0 ? void 0 : ref.key;
562
+ ][0]) === null || _ === void 0 ? void 0 : _.key;
443
563
  }
444
564
  getLastKey() {
445
- var ref;
565
+ var _rows_;
446
566
  let rows = [
447
567
  ...this.body.childNodes
448
568
  ];
449
- return (ref = rows[rows.length - 1]) === null || ref === void 0 ? void 0 : ref.key;
569
+ return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
450
570
  }
451
571
  getItem(key) {
452
572
  return this.keyMap.get(key);
@@ -510,10 +630,14 @@ class $7f5a58334d8866a5$export$596e1b2e2cf93690 extends (0, $56JBj$reactstatelyg
510
630
  return node;
511
631
  }
512
632
  });
633
+ (0, ($parcel$interopDefault($56JBj$swchelperslib_define_propertyjs)))(this, "_size", 0);
513
634
  this.columns = columns;
514
635
  this.rowHeaderColumnKeys = rowHeaderColumnKeys;
515
636
  this.body = body;
516
637
  this.headerRows = headerRows;
638
+ this._size = [
639
+ ...body.childNodes
640
+ ].length;
517
641
  // Default row header column to the first one.
518
642
  if (this.rowHeaderColumnKeys.size === 0) this.rowHeaderColumnKeys.add(this.columns[(opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) ? 1 : 0].key);
519
643
  }
@@ -552,10 +676,10 @@ function $e3f7784147dde23d$export$907bcc6c48325fd6(props) {
552
676
  isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
553
677
  setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
554
678
  sort (columnKey, direction) {
555
- var ref;
679
+ var _props_sortDescriptor;
556
680
  props.onSortChange({
557
681
  column: columnKey,
558
- direction: direction !== null && direction !== void 0 ? direction : ((ref = props.sortDescriptor) === null || ref === void 0 ? void 0 : ref.column) === columnKey ? $e3f7784147dde23d$var$OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction] : "ascending"
682
+ 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"
559
683
  });
560
684
  }
561
685
  };
@@ -810,4 +934,5 @@ let $ad4ab0a21c733e1f$export$f6f0c3fe4ec306ea = $ad4ab0a21c733e1f$var$Cell;
810
934
 
811
935
 
812
936
 
937
+
813
938
  //# sourceMappingURL=main.js.map