@react-stately/table 3.11.7-nightly.4552 → 3.11.7-nightly.4558

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/Cell.main.js +38 -0
  2. package/dist/Cell.main.js.map +1 -0
  3. package/dist/Cell.mjs +33 -0
  4. package/dist/Cell.module.js +33 -0
  5. package/dist/Cell.module.js.map +1 -0
  6. package/dist/Column.main.js +75 -0
  7. package/dist/Column.main.js.map +1 -0
  8. package/dist/Column.mjs +66 -0
  9. package/dist/Column.module.js +66 -0
  10. package/dist/Column.module.js.map +1 -0
  11. package/dist/Row.main.js +97 -0
  12. package/dist/Row.main.js.map +1 -0
  13. package/dist/Row.mjs +88 -0
  14. package/dist/Row.module.js +88 -0
  15. package/dist/Row.module.js.map +1 -0
  16. package/dist/TableBody.main.js +61 -0
  17. package/dist/TableBody.main.js.map +1 -0
  18. package/dist/TableBody.mjs +52 -0
  19. package/dist/TableBody.module.js +52 -0
  20. package/dist/TableBody.module.js.map +1 -0
  21. package/dist/TableCollection.main.js +284 -0
  22. package/dist/TableCollection.main.js.map +1 -0
  23. package/dist/TableCollection.mjs +278 -0
  24. package/dist/TableCollection.module.js +278 -0
  25. package/dist/TableCollection.module.js.map +1 -0
  26. package/dist/TableColumnLayout.main.js +162 -0
  27. package/dist/TableColumnLayout.main.js.map +1 -0
  28. package/dist/TableColumnLayout.mjs +157 -0
  29. package/dist/TableColumnLayout.module.js +157 -0
  30. package/dist/TableColumnLayout.module.js.map +1 -0
  31. package/dist/TableHeader.main.js +56 -0
  32. package/dist/TableHeader.main.js.map +1 -0
  33. package/dist/TableHeader.mjs +47 -0
  34. package/dist/TableHeader.module.js +47 -0
  35. package/dist/TableHeader.module.js.map +1 -0
  36. package/dist/TableUtils.main.js +184 -0
  37. package/dist/TableUtils.main.js.map +1 -0
  38. package/dist/TableUtils.mjs +175 -0
  39. package/dist/TableUtils.module.js +175 -0
  40. package/dist/TableUtils.module.js.map +1 -0
  41. package/dist/import.mjs +11 -1216
  42. package/dist/main.js +21 -1230
  43. package/dist/main.js.map +1 -1
  44. package/dist/module.js +11 -1216
  45. package/dist/module.js.map +1 -1
  46. package/dist/types.d.ts +1 -1
  47. package/dist/useTableColumnResizeState.main.js +113 -0
  48. package/dist/useTableColumnResizeState.main.js.map +1 -0
  49. package/dist/useTableColumnResizeState.mjs +108 -0
  50. package/dist/useTableColumnResizeState.module.js +108 -0
  51. package/dist/useTableColumnResizeState.module.js.map +1 -0
  52. package/dist/useTableState.main.js +71 -0
  53. package/dist/useTableState.main.js.map +1 -0
  54. package/dist/useTableState.mjs +66 -0
  55. package/dist/useTableState.module.js +66 -0
  56. package/dist/useTableState.module.js.map +1 -0
  57. package/dist/useTreeGridState.main.js +207 -0
  58. package/dist/useTreeGridState.main.js.map +1 -0
  59. package/dist/useTreeGridState.mjs +202 -0
  60. package/dist/useTreeGridState.module.js +202 -0
  61. package/dist/useTreeGridState.module.js.map +1 -0
  62. package/package.json +10 -10
@@ -0,0 +1,47 @@
1
+ import $20k3Y$react from "react";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ function $312ae3b56a94a86e$var$TableHeader(props) {
15
+ return null;
16
+ }
17
+ $312ae3b56a94a86e$var$TableHeader.getCollectionNode = function* getCollectionNode(props, context) {
18
+ let { children: children, columns: columns } = props;
19
+ // Clear columns so they aren't double added in strict mode.
20
+ context.columns = [];
21
+ if (typeof children === "function") {
22
+ if (!columns) throw new Error("props.children was a function but props.columns is missing");
23
+ for (let column of columns)yield {
24
+ type: "column",
25
+ value: column,
26
+ renderer: children
27
+ };
28
+ } else {
29
+ let columns = [];
30
+ (0, $20k3Y$react).Children.forEach(children, (column)=>{
31
+ columns.push({
32
+ type: "column",
33
+ element: column
34
+ });
35
+ });
36
+ yield* columns;
37
+ }
38
+ };
39
+ /**
40
+ * A TableHeader is a container for the Column elements in a Table. Columns can be statically defined
41
+ * as children, or generated dynamically using a function based on the data passed to the `columns` prop.
42
+ */ // We don't want getCollectionNode to show up in the type definition
43
+ let $312ae3b56a94a86e$export$f850895b287ef28e = $312ae3b56a94a86e$var$TableHeader;
44
+
45
+
46
+ export {$312ae3b56a94a86e$export$f850895b287ef28e as TableHeader};
47
+ //# sourceMappingURL=TableHeader.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAOD,SAAS,kCAAe,KAA0B;IAChD,OAAO;AACT;AAEA,kCAAY,iBAAiB,GAAG,UAAU,kBAAqB,KAA0B,EAAE,OAAoC;IAC7H,IAAI,YAAC,QAAQ,WAAE,OAAO,EAAC,GAAG;IAE1B,4DAA4D;IAC5D,QAAQ,OAAO,GAAG,EAAE;IAEpB,IAAI,OAAO,aAAa,YAAY;QAClC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM;QAGlB,KAAK,IAAI,UAAU,QACjB,MAAM;YACJ,MAAM;YACN,OAAO;YACP,UAAU;QACZ;IAEJ,OAAO;QACL,IAAI,UAA4B,EAAE;QAClC,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA;YAC/B,QAAQ,IAAI,CAAC;gBACX,MAAM;gBACN,SAAS;YACX;QACF;QAEA,OAAO;IACT;AACF;AAEA;;;CAGC,GACD,oEAAoE;AACpE,IAAI,4CAAe","sources":["packages/@react-stately/table/src/TableHeader.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBuilderContext} from './useTableState';\nimport {PartialNode} from '@react-stately/collections';\nimport React, {JSX, ReactElement} from 'react';\nimport {TableHeaderProps} from '@react-types/table';\n\nfunction TableHeader<T>(props: TableHeaderProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nTableHeader.getCollectionNode = function* getCollectionNode<T>(props: TableHeaderProps<T>, context: CollectionBuilderContext<T>): Generator<PartialNode<T>, void, any> {\n let {children, columns} = props;\n\n // Clear columns so they aren't double added in strict mode.\n context.columns = [];\n\n if (typeof children === 'function') {\n if (!columns) {\n throw new Error('props.children was a function but props.columns is missing');\n }\n\n for (let column of columns) {\n yield {\n type: 'column',\n value: column,\n renderer: children\n };\n }\n } else {\n let columns: PartialNode<T>[] = [];\n React.Children.forEach(children, column => {\n columns.push({\n type: 'column',\n element: column\n });\n });\n\n yield* columns;\n }\n};\n\n/**\n * A TableHeader is a container for the Column elements in a Table. Columns can be statically defined\n * as children, or generated dynamically using a function based on the data passed to the `columns` prop.\n */\n// We don't want getCollectionNode to show up in the type definition\nlet _TableHeader = TableHeader as <T>(props: TableHeaderProps<T>) => JSX.Element;\nexport {_TableHeader as TableHeader};\n"],"names":[],"version":3,"file":"TableHeader.module.js.map"}
@@ -0,0 +1,184 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "isStatic", () => $9e5f6a0caf75716e$export$1994a077b98ee0d5);
7
+ $parcel$export(module.exports, "parseFractionalUnit", () => $9e5f6a0caf75716e$export$9078bad4c3934604);
8
+ $parcel$export(module.exports, "getMaxWidth", () => $9e5f6a0caf75716e$export$59185c62a7544aa0);
9
+ $parcel$export(module.exports, "getMinWidth", () => $9e5f6a0caf75716e$export$f556054ce4358701);
10
+ $parcel$export(module.exports, "calculateColumnSizes", () => $9e5f6a0caf75716e$export$55d50dc687385491);
11
+ /*
12
+ * Copyright 2022 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */ function $9e5f6a0caf75716e$export$1994a077b98ee0d5(width) {
22
+ return width != null && (!isNaN(width) || String(width).match(/^(\d+)(?=%$)/) !== null);
23
+ }
24
+ function $9e5f6a0caf75716e$export$9078bad4c3934604(width) {
25
+ if (!width) return 1;
26
+ let match = width.match(/^(.+)(?=fr$)/);
27
+ // if width is the incorrect format, just default it to a 1fr
28
+ if (!match) {
29
+ 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'");
30
+ return 1;
31
+ }
32
+ return parseFloat(match[0]);
33
+ }
34
+ function $9e5f6a0caf75716e$export$7bbad27896f7ae9f(width, tableWidth) {
35
+ if (typeof width === "string") {
36
+ let match = width.match(/^(\d+)(?=%$)/);
37
+ if (!match) throw new Error("Only percentages or numbers are supported for static column widths");
38
+ return tableWidth * (parseFloat(match[0]) / 100);
39
+ }
40
+ return width;
41
+ }
42
+ function $9e5f6a0caf75716e$export$59185c62a7544aa0(maxWidth, tableWidth) {
43
+ return maxWidth != null ? $9e5f6a0caf75716e$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
44
+ }
45
+ function $9e5f6a0caf75716e$export$f556054ce4358701(minWidth, tableWidth) {
46
+ return minWidth != null ? $9e5f6a0caf75716e$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
47
+ }
48
+ function $9e5f6a0caf75716e$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
49
+ let hasNonFrozenItems = false;
50
+ let flexItems = columns.map((column, index)=>{
51
+ var _column_width, _ref, _ref1;
52
+ 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";
53
+ let frozen = false;
54
+ let baseSize = 0;
55
+ let flex = 0;
56
+ let targetMainSize = null;
57
+ if ($9e5f6a0caf75716e$export$1994a077b98ee0d5(width)) {
58
+ baseSize = $9e5f6a0caf75716e$export$7bbad27896f7ae9f(width, availableWidth);
59
+ frozen = true;
60
+ } else {
61
+ flex = $9e5f6a0caf75716e$export$9078bad4c3934604(width);
62
+ if (flex <= 0) frozen = true;
63
+ }
64
+ var _column_minWidth, _ref2;
65
+ 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);
66
+ let max = $9e5f6a0caf75716e$export$59185c62a7544aa0(column.maxWidth, availableWidth);
67
+ let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
68
+ // 9.7.1
69
+ // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.
70
+ // 9.7.2
71
+ if (frozen) targetMainSize = hypotheticalMainSize;
72
+ else if (baseSize > hypotheticalMainSize) {
73
+ frozen = true;
74
+ targetMainSize = hypotheticalMainSize;
75
+ }
76
+ // 9.7.3
77
+ if (!frozen) hasNonFrozenItems = true;
78
+ return {
79
+ frozen: frozen,
80
+ baseSize: baseSize,
81
+ hypotheticalMainSize: hypotheticalMainSize,
82
+ min: min,
83
+ max: max,
84
+ flex: flex,
85
+ targetMainSize: targetMainSize,
86
+ violation: 0
87
+ };
88
+ });
89
+ // 9.7.4
90
+ // 9.7.4.a
91
+ while(hasNonFrozenItems){
92
+ // 9.7.4.b
93
+ /**
94
+ * Calculate the remaining free space as for initial free space,
95
+ * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is
96
+ * less than one, multiply the initial free space by this sum (of flex factors).
97
+ * If the magnitude of this value is less than the magnitude of
98
+ * the remaining free space, use this as the remaining free space.
99
+ */ let usedWidth = 0;
100
+ let flexFactors = 0;
101
+ flexItems.forEach((item)=>{
102
+ if (item.frozen) usedWidth += item.targetMainSize;
103
+ else {
104
+ usedWidth += item.baseSize;
105
+ flexFactors += item.flex;
106
+ }
107
+ });
108
+ let remainingFreeSpace = availableWidth - usedWidth;
109
+ // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0
110
+ // so no need to check for flexFactors < 1
111
+ // 9.7.4.c
112
+ /**
113
+ * If the remaining free space is zero
114
+ * - Do nothing.
115
+ * Else // remember, we're always in grow mode
116
+ * - Find the ratio of the item’s flex grow factor to the
117
+ * sum of the flex grow factors of all unfrozen items on
118
+ * the line. Set the item’s target main size to its flex
119
+ * base size plus a fraction of the remaining free space
120
+ * proportional to the ratio.
121
+ */ if (remainingFreeSpace > 0) flexItems.forEach((item)=>{
122
+ if (!item.frozen) {
123
+ let ratio = item.flex / flexFactors;
124
+ item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
125
+ }
126
+ });
127
+ // 9.7.4.d
128
+ /**
129
+ * Fix min/max violations. Clamp each non-frozen item’s
130
+ * target main size by its used min and max main sizes
131
+ * and floor its content-box size at zero. If the item’s
132
+ * target main size was made smaller by this, it’s a max
133
+ * violation. If the item’s target main size was made
134
+ * larger by this, it’s a min violation.
135
+ */ let totalViolation = 0;
136
+ flexItems.forEach((item)=>{
137
+ item.violation = 0;
138
+ if (!item.frozen) {
139
+ let { min: min, max: max, targetMainSize: targetMainSize } = item;
140
+ item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
141
+ item.violation = item.targetMainSize - targetMainSize;
142
+ totalViolation += item.violation;
143
+ }
144
+ });
145
+ // 9.7.4.e
146
+ /**
147
+ * Freeze over-flexed items. The total violation is the
148
+ * sum of the adjustments from the previous step
149
+ * ∑(clamped size - unclamped size). If the total violation is:
150
+ * Zero
151
+ * - Freeze all items.
152
+ *
153
+ * Positive
154
+ * - Freeze all the items with min violations.
155
+ *
156
+ * Negative
157
+ * - Freeze all the items with max violations.
158
+ */ hasNonFrozenItems = false;
159
+ flexItems.forEach((item)=>{
160
+ if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
161
+ else if (!item.frozen) hasNonFrozenItems = true;
162
+ });
163
+ }
164
+ return $9e5f6a0caf75716e$var$cascadeRounding(flexItems);
165
+ }
166
+ function $9e5f6a0caf75716e$var$cascadeRounding(flexItems) {
167
+ /*
168
+ Given an array of floats that sum to an integer, this rounds the floats
169
+ and returns an array of integers with the same sum.
170
+ */ let fpTotal = 0;
171
+ let intTotal = 0;
172
+ let roundedArray = [];
173
+ flexItems.forEach(function(item) {
174
+ let float = item.targetMainSize;
175
+ let integer = Math.round(float + fpTotal) - intTotal;
176
+ fpTotal += float;
177
+ intTotal += integer;
178
+ roundedArray.push(integer);
179
+ });
180
+ return roundedArray;
181
+ }
182
+
183
+
184
+ //# sourceMappingURL=TableUtils.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAMM,SAAS,0CAAS,KAAsB;IAC7C,OAAO,SAAS,QAAS,CAAA,CAAC,MAAM,UAAoB,AAAC,OAAO,OA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AAC,CAAA;YAChB,KAAK,SAAS,GAAG;YACjB,IAAI,CAAC,KAAK,MAAM,EAAE;gBAChB,IAAI,OAAC,GAAG,OAAE,GAAG,kBAAE,cAAc,EAAC,GAAG;gBACjC,KAAK,cAAc,GAAG,KAAK,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,gBAAgB;gBAE7D,KAAK,SAAS,GAAG,KAAK,cAAc,GAAG;gBACvC,kBAAkB,KAAK,SAAS;YAClC;QACF;QAEA,UAAU;QACV;;;;;;;;;;;;KAYC,GACD,oBAAoB;QACpB,UAAU,OAAO,CAAC,CAAA;YAChB,IAAI,mBAAmB,KAAK,KAAK,IAAI,CAAC,oBAAoB,KAAK,IAAI,CAAC,KAAK,SAAS,GAChF,KAAK,MAAM,GAAG;iBACT,IAAI,CAAC,KAAK,MAAM,EACrB,oBAAoB;QAExB;IACF;IAEA,OAAO,sCAAgB;AACzB;AAEA,SAAS,sCAAgB,SAAS;IAChC;;;EAGA,GAEA,IAAI,UAAU;IACd,IAAI,WAAW;IACf,IAAI,eAAe,EAAE;IACrB,UAAU,OAAO,CAAC,SAAU,IAAI;QAC9B,IAAI,QAAQ,KAAK,cAAc;QAC/B,IAAI,UAAU,KAAK,KAAK,CAAC,QAAQ,WAAW;QAC5C,WAAW;QACX,YAAY;QACZ,aAAa,IAAI,CAAC;IACpB;IAEA,OAAO;AACT","sources":["packages/@react-stately/table/src/TableUtils.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ColumnSize} from '@react-types/table';\nimport {Key} from '@react-types/shared';\n\n// numbers and percents are considered static. *fr units or a lack of units are considered dynamic.\nexport function isStatic(width: number | string): boolean {\n return width != null && (!isNaN(width as number) || (String(width)).match(/^(\\d+)(?=%$)/) !== null);\n}\n\nexport function parseFractionalUnit(width: string): number {\n if (!width) {\n return 1;\n }\n let match = width.match(/^(.+)(?=fr$)/);\n // if width is the incorrect format, just default it to a 1fr\n if (!match) {\n console.warn(`width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,\n 'defaulting to \\'1fr\\'');\n return 1;\n }\n return parseFloat(match[0]);\n}\n\nexport function parseStaticWidth(width: number | string, tableWidth: number): number {\n if (typeof width === 'string') {\n let match = width.match(/^(\\d+)(?=%$)/);\n if (!match) {\n throw new Error('Only percentages or numbers are supported for static column widths');\n }\n return tableWidth * (parseFloat(match[0]) / 100);\n }\n return width;\n}\n\n\nexport function getMaxWidth(maxWidth: number | string, tableWidth: number): number {\n return maxWidth != null\n ? parseStaticWidth(maxWidth, tableWidth)\n : Number.MAX_SAFE_INTEGER;\n}\n\n// cannot support FR units, we'd need to know everything else in the table to do that\nexport function getMinWidth(minWidth: number | string, tableWidth: number): number {\n return minWidth != null\n ? parseStaticWidth(minWidth, tableWidth)\n : 0;\n}\n\n\nexport interface IColumn {\n minWidth?: number | string,\n maxWidth?: number | string,\n width?: number | string,\n defaultWidth?: number | string,\n key?: Key\n}\n\n/**\n * Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm\n * It makes a few constraint/assumptions:\n * 1. All basis values are 0 unless it is a static width, then the basis is the static width\n * 2. All flex grow and shrink values are equal to the FR specified on the column, grow and shrink for the same column are equal\n * 3. We only have one row\n * An example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let the browser figure out the\n * flex of the columns.\n * Note: We differ in one key aspect, all of our column widths must be whole numbers, so we avoid browser\n * sub pixel rounding errors. To do this, we use a cascading rounding algorithm to ensure that the sum of the widths is maintained\n * while distributing the rounding remainder across the columns.\n *\n * As noted in the chrome source code, this algorithm is very accurate, but has the potential to be quadratic.\n * They have deemed this to be acceptable because the number of elements is usually small and the flex factors\n * are usually not high variance. I believe we can make the same assumptions. Particularly once resizing is\n * started, it will convert all columns to the left to static widths, so it will cut down on the number of FR columns.\n *\n * There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible for readability, accuracy, and for the\n * note that this behaving quadratically is unlikely to be a problem.\n * @param availableWidth - The visible width of the table.\n * @param columns - The table defined columns.\n * @param changedColumns - Any columns we want to override, for example, during resizing.\n * @param getDefaultWidth - A function that returns the default width of a column by its index.\n * @param getDefaultMinWidth - A function that returns the default min width of a column by its index.\n */\nexport function calculateColumnSizes(availableWidth: number, columns: IColumn[], changedColumns: Map<Key, ColumnSize>, getDefaultWidth, getDefaultMinWidth) {\n let hasNonFrozenItems = false;\n let flexItems = columns.map((column, index) => {\n let width = changedColumns.get(column.key) != null ? changedColumns.get(column.key) : column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr';\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = null;\n if (isStatic(width)) {\n baseSize = parseStaticWidth(width, availableWidth);\n frozen = true;\n } else {\n flex = parseFractionalUnit(width);\n if (flex <= 0) {\n frozen = true;\n }\n }\n\n let min = getMinWidth(column.minWidth ?? getDefaultMinWidth?.(index) ?? 0, availableWidth);\n let max = getMaxWidth(column.maxWidth, availableWidth);\n let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));\n\n // 9.7.1\n // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.\n // 9.7.2\n if (frozen) {\n targetMainSize = hypotheticalMainSize;\n } else if (baseSize > hypotheticalMainSize) {\n frozen = true;\n targetMainSize = hypotheticalMainSize;\n }\n\n // 9.7.3\n if (!frozen) {\n hasNonFrozenItems = true;\n }\n return {\n frozen,\n baseSize,\n hypotheticalMainSize,\n min,\n max,\n flex,\n targetMainSize,\n violation: 0\n };\n });\n\n // 9.7.4\n // 9.7.4.a\n while (hasNonFrozenItems) {\n // 9.7.4.b\n /**\n * Calculate the remaining free space as for initial free space,\n * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is\n * less than one, multiply the initial free space by this sum (of flex factors).\n * If the magnitude of this value is less than the magnitude of\n * the remaining free space, use this as the remaining free space.\n */\n let usedWidth = 0;\n let flexFactors = 0;\n flexItems.forEach(item => {\n if (item.frozen) {\n usedWidth += item.targetMainSize;\n } else {\n usedWidth += item.baseSize;\n flexFactors += item.flex;\n }\n });\n\n let remainingFreeSpace = availableWidth - usedWidth;\n // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0\n // so no need to check for flexFactors < 1\n // 9.7.4.c\n /**\n * If the remaining free space is zero\n * - Do nothing.\n * Else // remember, we're always in grow mode\n * - Find the ratio of the item’s flex grow factor to the\n * sum of the flex grow factors of all unfrozen items on\n * the line. Set the item’s target main size to its flex\n * base size plus a fraction of the remaining free space\n * proportional to the ratio.\n */\n if (remainingFreeSpace > 0) {\n flexItems.forEach((item) => {\n if (!item.frozen) {\n let ratio = item.flex / flexFactors;\n item.targetMainSize = item.baseSize + (ratio * remainingFreeSpace);\n }\n });\n }\n\n // 9.7.4.d\n /**\n * Fix min/max violations. Clamp each non-frozen item’s\n * target main size by its used min and max main sizes\n * and floor its content-box size at zero. If the item’s\n * target main size was made smaller by this, it’s a max\n * violation. If the item’s target main size was made\n * larger by this, it’s a min violation.\n */\n let totalViolation = 0;\n flexItems.forEach(item => {\n item.violation = 0;\n if (!item.frozen) {\n let {min, max, targetMainSize} = item;\n item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));\n\n item.violation = item.targetMainSize - targetMainSize;\n totalViolation += item.violation;\n }\n });\n\n // 9.7.4.e\n /**\n * Freeze over-flexed items. The total violation is the\n * sum of the adjustments from the previous step\n * ∑(clamped size - unclamped size). If the total violation is:\n * Zero\n * - Freeze all items.\n *\n * Positive\n * - Freeze all the items with min violations.\n *\n * Negative\n * - Freeze all the items with max violations.\n */\n hasNonFrozenItems = false;\n flexItems.forEach(item => {\n if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) {\n item.frozen = true;\n } else if (!item.frozen) {\n hasNonFrozenItems = true;\n }\n });\n }\n\n return cascadeRounding(flexItems);\n}\n\nfunction cascadeRounding(flexItems): number[] {\n /*\n Given an array of floats that sum to an integer, this rounds the floats\n and returns an array of integers with the same sum.\n */\n\n let fpTotal = 0;\n let intTotal = 0;\n let roundedArray = [];\n flexItems.forEach(function (item) {\n let float = item.targetMainSize;\n let integer = Math.round(float + fpTotal) - intTotal;\n fpTotal += float;\n intTotal += integer;\n roundedArray.push(integer);\n });\n\n return roundedArray;\n}\n"],"names":[],"version":3,"file":"TableUtils.main.js.map"}
@@ -0,0 +1,175 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ function $6818b1c4fc67028d$export$1994a077b98ee0d5(width) {
12
+ return width != null && (!isNaN(width) || String(width).match(/^(\d+)(?=%$)/) !== null);
13
+ }
14
+ function $6818b1c4fc67028d$export$9078bad4c3934604(width) {
15
+ if (!width) return 1;
16
+ let match = width.match(/^(.+)(?=fr$)/);
17
+ // if width is the incorrect format, just default it to a 1fr
18
+ if (!match) {
19
+ 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'");
20
+ return 1;
21
+ }
22
+ return parseFloat(match[0]);
23
+ }
24
+ function $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, tableWidth) {
25
+ if (typeof width === "string") {
26
+ let match = width.match(/^(\d+)(?=%$)/);
27
+ if (!match) throw new Error("Only percentages or numbers are supported for static column widths");
28
+ return tableWidth * (parseFloat(match[0]) / 100);
29
+ }
30
+ return width;
31
+ }
32
+ function $6818b1c4fc67028d$export$59185c62a7544aa0(maxWidth, tableWidth) {
33
+ return maxWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
34
+ }
35
+ function $6818b1c4fc67028d$export$f556054ce4358701(minWidth, tableWidth) {
36
+ return minWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
37
+ }
38
+ function $6818b1c4fc67028d$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
39
+ let hasNonFrozenItems = false;
40
+ let flexItems = columns.map((column, index)=>{
41
+ var _column_width, _ref, _ref1;
42
+ 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";
43
+ let frozen = false;
44
+ let baseSize = 0;
45
+ let flex = 0;
46
+ let targetMainSize = null;
47
+ if ($6818b1c4fc67028d$export$1994a077b98ee0d5(width)) {
48
+ baseSize = $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, availableWidth);
49
+ frozen = true;
50
+ } else {
51
+ flex = $6818b1c4fc67028d$export$9078bad4c3934604(width);
52
+ if (flex <= 0) frozen = true;
53
+ }
54
+ var _column_minWidth, _ref2;
55
+ 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);
56
+ let max = $6818b1c4fc67028d$export$59185c62a7544aa0(column.maxWidth, availableWidth);
57
+ let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
58
+ // 9.7.1
59
+ // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.
60
+ // 9.7.2
61
+ if (frozen) targetMainSize = hypotheticalMainSize;
62
+ else if (baseSize > hypotheticalMainSize) {
63
+ frozen = true;
64
+ targetMainSize = hypotheticalMainSize;
65
+ }
66
+ // 9.7.3
67
+ if (!frozen) hasNonFrozenItems = true;
68
+ return {
69
+ frozen: frozen,
70
+ baseSize: baseSize,
71
+ hypotheticalMainSize: hypotheticalMainSize,
72
+ min: min,
73
+ max: max,
74
+ flex: flex,
75
+ targetMainSize: targetMainSize,
76
+ violation: 0
77
+ };
78
+ });
79
+ // 9.7.4
80
+ // 9.7.4.a
81
+ while(hasNonFrozenItems){
82
+ // 9.7.4.b
83
+ /**
84
+ * Calculate the remaining free space as for initial free space,
85
+ * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is
86
+ * less than one, multiply the initial free space by this sum (of flex factors).
87
+ * If the magnitude of this value is less than the magnitude of
88
+ * the remaining free space, use this as the remaining free space.
89
+ */ let usedWidth = 0;
90
+ let flexFactors = 0;
91
+ flexItems.forEach((item)=>{
92
+ if (item.frozen) usedWidth += item.targetMainSize;
93
+ else {
94
+ usedWidth += item.baseSize;
95
+ flexFactors += item.flex;
96
+ }
97
+ });
98
+ let remainingFreeSpace = availableWidth - usedWidth;
99
+ // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0
100
+ // so no need to check for flexFactors < 1
101
+ // 9.7.4.c
102
+ /**
103
+ * If the remaining free space is zero
104
+ * - Do nothing.
105
+ * Else // remember, we're always in grow mode
106
+ * - Find the ratio of the item’s flex grow factor to the
107
+ * sum of the flex grow factors of all unfrozen items on
108
+ * the line. Set the item’s target main size to its flex
109
+ * base size plus a fraction of the remaining free space
110
+ * proportional to the ratio.
111
+ */ if (remainingFreeSpace > 0) flexItems.forEach((item)=>{
112
+ if (!item.frozen) {
113
+ let ratio = item.flex / flexFactors;
114
+ item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
115
+ }
116
+ });
117
+ // 9.7.4.d
118
+ /**
119
+ * Fix min/max violations. Clamp each non-frozen item’s
120
+ * target main size by its used min and max main sizes
121
+ * and floor its content-box size at zero. If the item’s
122
+ * target main size was made smaller by this, it’s a max
123
+ * violation. If the item’s target main size was made
124
+ * larger by this, it’s a min violation.
125
+ */ let totalViolation = 0;
126
+ flexItems.forEach((item)=>{
127
+ item.violation = 0;
128
+ if (!item.frozen) {
129
+ let { min: min, max: max, targetMainSize: targetMainSize } = item;
130
+ item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
131
+ item.violation = item.targetMainSize - targetMainSize;
132
+ totalViolation += item.violation;
133
+ }
134
+ });
135
+ // 9.7.4.e
136
+ /**
137
+ * Freeze over-flexed items. The total violation is the
138
+ * sum of the adjustments from the previous step
139
+ * ∑(clamped size - unclamped size). If the total violation is:
140
+ * Zero
141
+ * - Freeze all items.
142
+ *
143
+ * Positive
144
+ * - Freeze all the items with min violations.
145
+ *
146
+ * Negative
147
+ * - Freeze all the items with max violations.
148
+ */ hasNonFrozenItems = false;
149
+ flexItems.forEach((item)=>{
150
+ if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
151
+ else if (!item.frozen) hasNonFrozenItems = true;
152
+ });
153
+ }
154
+ return $6818b1c4fc67028d$var$cascadeRounding(flexItems);
155
+ }
156
+ function $6818b1c4fc67028d$var$cascadeRounding(flexItems) {
157
+ /*
158
+ Given an array of floats that sum to an integer, this rounds the floats
159
+ and returns an array of integers with the same sum.
160
+ */ let fpTotal = 0;
161
+ let intTotal = 0;
162
+ let roundedArray = [];
163
+ flexItems.forEach(function(item) {
164
+ let float = item.targetMainSize;
165
+ let integer = Math.round(float + fpTotal) - intTotal;
166
+ fpTotal += float;
167
+ intTotal += integer;
168
+ roundedArray.push(integer);
169
+ });
170
+ return roundedArray;
171
+ }
172
+
173
+
174
+ export {$6818b1c4fc67028d$export$1994a077b98ee0d5 as isStatic, $6818b1c4fc67028d$export$9078bad4c3934604 as parseFractionalUnit, $6818b1c4fc67028d$export$7bbad27896f7ae9f as parseStaticWidth, $6818b1c4fc67028d$export$59185c62a7544aa0 as getMaxWidth, $6818b1c4fc67028d$export$f556054ce4358701 as getMinWidth, $6818b1c4fc67028d$export$55d50dc687385491 as calculateColumnSizes};
175
+ //# sourceMappingURL=TableUtils.mjs.map
@@ -0,0 +1,175 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ function $6818b1c4fc67028d$export$1994a077b98ee0d5(width) {
12
+ return width != null && (!isNaN(width) || String(width).match(/^(\d+)(?=%$)/) !== null);
13
+ }
14
+ function $6818b1c4fc67028d$export$9078bad4c3934604(width) {
15
+ if (!width) return 1;
16
+ let match = width.match(/^(.+)(?=fr$)/);
17
+ // if width is the incorrect format, just default it to a 1fr
18
+ if (!match) {
19
+ 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'");
20
+ return 1;
21
+ }
22
+ return parseFloat(match[0]);
23
+ }
24
+ function $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, tableWidth) {
25
+ if (typeof width === "string") {
26
+ let match = width.match(/^(\d+)(?=%$)/);
27
+ if (!match) throw new Error("Only percentages or numbers are supported for static column widths");
28
+ return tableWidth * (parseFloat(match[0]) / 100);
29
+ }
30
+ return width;
31
+ }
32
+ function $6818b1c4fc67028d$export$59185c62a7544aa0(maxWidth, tableWidth) {
33
+ return maxWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
34
+ }
35
+ function $6818b1c4fc67028d$export$f556054ce4358701(minWidth, tableWidth) {
36
+ return minWidth != null ? $6818b1c4fc67028d$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
37
+ }
38
+ function $6818b1c4fc67028d$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
39
+ let hasNonFrozenItems = false;
40
+ let flexItems = columns.map((column, index)=>{
41
+ var _column_width, _ref, _ref1;
42
+ 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";
43
+ let frozen = false;
44
+ let baseSize = 0;
45
+ let flex = 0;
46
+ let targetMainSize = null;
47
+ if ($6818b1c4fc67028d$export$1994a077b98ee0d5(width)) {
48
+ baseSize = $6818b1c4fc67028d$export$7bbad27896f7ae9f(width, availableWidth);
49
+ frozen = true;
50
+ } else {
51
+ flex = $6818b1c4fc67028d$export$9078bad4c3934604(width);
52
+ if (flex <= 0) frozen = true;
53
+ }
54
+ var _column_minWidth, _ref2;
55
+ 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);
56
+ let max = $6818b1c4fc67028d$export$59185c62a7544aa0(column.maxWidth, availableWidth);
57
+ let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
58
+ // 9.7.1
59
+ // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.
60
+ // 9.7.2
61
+ if (frozen) targetMainSize = hypotheticalMainSize;
62
+ else if (baseSize > hypotheticalMainSize) {
63
+ frozen = true;
64
+ targetMainSize = hypotheticalMainSize;
65
+ }
66
+ // 9.7.3
67
+ if (!frozen) hasNonFrozenItems = true;
68
+ return {
69
+ frozen: frozen,
70
+ baseSize: baseSize,
71
+ hypotheticalMainSize: hypotheticalMainSize,
72
+ min: min,
73
+ max: max,
74
+ flex: flex,
75
+ targetMainSize: targetMainSize,
76
+ violation: 0
77
+ };
78
+ });
79
+ // 9.7.4
80
+ // 9.7.4.a
81
+ while(hasNonFrozenItems){
82
+ // 9.7.4.b
83
+ /**
84
+ * Calculate the remaining free space as for initial free space,
85
+ * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is
86
+ * less than one, multiply the initial free space by this sum (of flex factors).
87
+ * If the magnitude of this value is less than the magnitude of
88
+ * the remaining free space, use this as the remaining free space.
89
+ */ let usedWidth = 0;
90
+ let flexFactors = 0;
91
+ flexItems.forEach((item)=>{
92
+ if (item.frozen) usedWidth += item.targetMainSize;
93
+ else {
94
+ usedWidth += item.baseSize;
95
+ flexFactors += item.flex;
96
+ }
97
+ });
98
+ let remainingFreeSpace = availableWidth - usedWidth;
99
+ // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0
100
+ // so no need to check for flexFactors < 1
101
+ // 9.7.4.c
102
+ /**
103
+ * If the remaining free space is zero
104
+ * - Do nothing.
105
+ * Else // remember, we're always in grow mode
106
+ * - Find the ratio of the item’s flex grow factor to the
107
+ * sum of the flex grow factors of all unfrozen items on
108
+ * the line. Set the item’s target main size to its flex
109
+ * base size plus a fraction of the remaining free space
110
+ * proportional to the ratio.
111
+ */ if (remainingFreeSpace > 0) flexItems.forEach((item)=>{
112
+ if (!item.frozen) {
113
+ let ratio = item.flex / flexFactors;
114
+ item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
115
+ }
116
+ });
117
+ // 9.7.4.d
118
+ /**
119
+ * Fix min/max violations. Clamp each non-frozen item’s
120
+ * target main size by its used min and max main sizes
121
+ * and floor its content-box size at zero. If the item’s
122
+ * target main size was made smaller by this, it’s a max
123
+ * violation. If the item’s target main size was made
124
+ * larger by this, it’s a min violation.
125
+ */ let totalViolation = 0;
126
+ flexItems.forEach((item)=>{
127
+ item.violation = 0;
128
+ if (!item.frozen) {
129
+ let { min: min, max: max, targetMainSize: targetMainSize } = item;
130
+ item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
131
+ item.violation = item.targetMainSize - targetMainSize;
132
+ totalViolation += item.violation;
133
+ }
134
+ });
135
+ // 9.7.4.e
136
+ /**
137
+ * Freeze over-flexed items. The total violation is the
138
+ * sum of the adjustments from the previous step
139
+ * ∑(clamped size - unclamped size). If the total violation is:
140
+ * Zero
141
+ * - Freeze all items.
142
+ *
143
+ * Positive
144
+ * - Freeze all the items with min violations.
145
+ *
146
+ * Negative
147
+ * - Freeze all the items with max violations.
148
+ */ hasNonFrozenItems = false;
149
+ flexItems.forEach((item)=>{
150
+ if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
151
+ else if (!item.frozen) hasNonFrozenItems = true;
152
+ });
153
+ }
154
+ return $6818b1c4fc67028d$var$cascadeRounding(flexItems);
155
+ }
156
+ function $6818b1c4fc67028d$var$cascadeRounding(flexItems) {
157
+ /*
158
+ Given an array of floats that sum to an integer, this rounds the floats
159
+ and returns an array of integers with the same sum.
160
+ */ let fpTotal = 0;
161
+ let intTotal = 0;
162
+ let roundedArray = [];
163
+ flexItems.forEach(function(item) {
164
+ let float = item.targetMainSize;
165
+ let integer = Math.round(float + fpTotal) - intTotal;
166
+ fpTotal += float;
167
+ intTotal += integer;
168
+ roundedArray.push(integer);
169
+ });
170
+ return roundedArray;
171
+ }
172
+
173
+
174
+ export {$6818b1c4fc67028d$export$1994a077b98ee0d5 as isStatic, $6818b1c4fc67028d$export$9078bad4c3934604 as parseFractionalUnit, $6818b1c4fc67028d$export$7bbad27896f7ae9f as parseStaticWidth, $6818b1c4fc67028d$export$59185c62a7544aa0 as getMaxWidth, $6818b1c4fc67028d$export$f556054ce4358701 as getMinWidth, $6818b1c4fc67028d$export$55d50dc687385491 as calculateColumnSizes};
175
+ //# sourceMappingURL=TableUtils.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAMM,SAAS,0CAAS,KAAsB;IAC7C,OAAO,SAAS,QAAS,CAAA,CAAC,MAAM,UAAoB,AAAC,OAAO,OAAQ,KAAK,CAAC,oBAAoB,IAAG;AACnG;AAEO,SAAS,0CAAoB,KAAa;IAC/C,IAAI,CAAC,OACH,OAAO;IAET,IAAI,QAAQ,MAAM,KAAK,CAAC;IACxB,6DAA6D;IAC7D,IAAI,CAAC,OAAO;QACV,QAAQ,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,6GAA6G,CAAC,EACzI;QACF,OAAO;IACT;IACA,OAAO,WAAW,KAAK,CAAC,EAAE;AAC5B;AAEO,SAAS,0CAAiB,KAAsB,EAAE,UAAkB;IACzE,IAAI,OAAO,UAAU,UAAU;QAC7B,IAAI,QAAQ,MAAM,KAAK,CAAC;QACxB,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;QAElB,OAAO,aAAc,CAAA,WAAW,KAAK,CAAC,EAAE,IAAI,GAAE;IAChD;IACA,OAAO;AACT;AAGO,SAAS,0CAAY,QAAyB,EAAE,UAAkB;IACvE,OAAO,YAAY,OACf,0CAAiB,UAAU,cAC3B,OAAO,gBAAgB;AAC7B;AAGO,SAAS,0CAAY,QAAyB,EAAE,UAAkB;IACvE,OAAO,YAAY,OACf,0CAAiB,UAAU,cAC3B;AACN;AAoCO,SAAS,0CAAqB,cAAsB,EAAE,OAAkB,EAAE,cAAoC,EAAE,eAAe,EAAE,kBAAkB;IACxJ,IAAI,oBAAoB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;IACpB;IAEA,OAAO;AACT","sources":["packages/@react-stately/table/src/TableUtils.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ColumnSize} from '@react-types/table';\nimport {Key} from '@react-types/shared';\n\n// numbers and percents are considered static. *fr units or a lack of units are considered dynamic.\nexport function isStatic(width: number | string): boolean {\n return width != null && (!isNaN(width as number) || (String(width)).match(/^(\\d+)(?=%$)/) !== null);\n}\n\nexport function parseFractionalUnit(width: string): number {\n if (!width) {\n return 1;\n }\n let match = width.match(/^(.+)(?=fr$)/);\n // if width is the incorrect format, just default it to a 1fr\n if (!match) {\n console.warn(`width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,\n 'defaulting to \\'1fr\\'');\n return 1;\n }\n return parseFloat(match[0]);\n}\n\nexport function parseStaticWidth(width: number | string, tableWidth: number): number {\n if (typeof width === 'string') {\n let match = width.match(/^(\\d+)(?=%$)/);\n if (!match) {\n throw new Error('Only percentages or numbers are supported for static column widths');\n }\n return tableWidth * (parseFloat(match[0]) / 100);\n }\n return width;\n}\n\n\nexport function getMaxWidth(maxWidth: number | string, tableWidth: number): number {\n return maxWidth != null\n ? parseStaticWidth(maxWidth, tableWidth)\n : Number.MAX_SAFE_INTEGER;\n}\n\n// cannot support FR units, we'd need to know everything else in the table to do that\nexport function getMinWidth(minWidth: number | string, tableWidth: number): number {\n return minWidth != null\n ? parseStaticWidth(minWidth, tableWidth)\n : 0;\n}\n\n\nexport interface IColumn {\n minWidth?: number | string,\n maxWidth?: number | string,\n width?: number | string,\n defaultWidth?: number | string,\n key?: Key\n}\n\n/**\n * Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm\n * It makes a few constraint/assumptions:\n * 1. All basis values are 0 unless it is a static width, then the basis is the static width\n * 2. All flex grow and shrink values are equal to the FR specified on the column, grow and shrink for the same column are equal\n * 3. We only have one row\n * An example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let the browser figure out the\n * flex of the columns.\n * Note: We differ in one key aspect, all of our column widths must be whole numbers, so we avoid browser\n * sub pixel rounding errors. To do this, we use a cascading rounding algorithm to ensure that the sum of the widths is maintained\n * while distributing the rounding remainder across the columns.\n *\n * As noted in the chrome source code, this algorithm is very accurate, but has the potential to be quadratic.\n * They have deemed this to be acceptable because the number of elements is usually small and the flex factors\n * are usually not high variance. I believe we can make the same assumptions. Particularly once resizing is\n * started, it will convert all columns to the left to static widths, so it will cut down on the number of FR columns.\n *\n * There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible for readability, accuracy, and for the\n * note that this behaving quadratically is unlikely to be a problem.\n * @param availableWidth - The visible width of the table.\n * @param columns - The table defined columns.\n * @param changedColumns - Any columns we want to override, for example, during resizing.\n * @param getDefaultWidth - A function that returns the default width of a column by its index.\n * @param getDefaultMinWidth - A function that returns the default min width of a column by its index.\n */\nexport function calculateColumnSizes(availableWidth: number, columns: IColumn[], changedColumns: Map<Key, ColumnSize>, getDefaultWidth, getDefaultMinWidth) {\n let hasNonFrozenItems = false;\n let flexItems = columns.map((column, index) => {\n let width = changedColumns.get(column.key) != null ? changedColumns.get(column.key) : column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr';\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = null;\n if (isStatic(width)) {\n baseSize = parseStaticWidth(width, availableWidth);\n frozen = true;\n } else {\n flex = parseFractionalUnit(width);\n if (flex <= 0) {\n frozen = true;\n }\n }\n\n let min = getMinWidth(column.minWidth ?? getDefaultMinWidth?.(index) ?? 0, availableWidth);\n let max = getMaxWidth(column.maxWidth, availableWidth);\n let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));\n\n // 9.7.1\n // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.\n // 9.7.2\n if (frozen) {\n targetMainSize = hypotheticalMainSize;\n } else if (baseSize > hypotheticalMainSize) {\n frozen = true;\n targetMainSize = hypotheticalMainSize;\n }\n\n // 9.7.3\n if (!frozen) {\n hasNonFrozenItems = true;\n }\n return {\n frozen,\n baseSize,\n hypotheticalMainSize,\n min,\n max,\n flex,\n targetMainSize,\n violation: 0\n };\n });\n\n // 9.7.4\n // 9.7.4.a\n while (hasNonFrozenItems) {\n // 9.7.4.b\n /**\n * Calculate the remaining free space as for initial free space,\n * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is\n * less than one, multiply the initial free space by this sum (of flex factors).\n * If the magnitude of this value is less than the magnitude of\n * the remaining free space, use this as the remaining free space.\n */\n let usedWidth = 0;\n let flexFactors = 0;\n flexItems.forEach(item => {\n if (item.frozen) {\n usedWidth += item.targetMainSize;\n } else {\n usedWidth += item.baseSize;\n flexFactors += item.flex;\n }\n });\n\n let remainingFreeSpace = availableWidth - usedWidth;\n // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0\n // so no need to check for flexFactors < 1\n // 9.7.4.c\n /**\n * If the remaining free space is zero\n * - Do nothing.\n * Else // remember, we're always in grow mode\n * - Find the ratio of the item’s flex grow factor to the\n * sum of the flex grow factors of all unfrozen items on\n * the line. Set the item’s target main size to its flex\n * base size plus a fraction of the remaining free space\n * proportional to the ratio.\n */\n if (remainingFreeSpace > 0) {\n flexItems.forEach((item) => {\n if (!item.frozen) {\n let ratio = item.flex / flexFactors;\n item.targetMainSize = item.baseSize + (ratio * remainingFreeSpace);\n }\n });\n }\n\n // 9.7.4.d\n /**\n * Fix min/max violations. Clamp each non-frozen item’s\n * target main size by its used min and max main sizes\n * and floor its content-box size at zero. If the item’s\n * target main size was made smaller by this, it’s a max\n * violation. If the item’s target main size was made\n * larger by this, it’s a min violation.\n */\n let totalViolation = 0;\n flexItems.forEach(item => {\n item.violation = 0;\n if (!item.frozen) {\n let {min, max, targetMainSize} = item;\n item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));\n\n item.violation = item.targetMainSize - targetMainSize;\n totalViolation += item.violation;\n }\n });\n\n // 9.7.4.e\n /**\n * Freeze over-flexed items. The total violation is the\n * sum of the adjustments from the previous step\n * ∑(clamped size - unclamped size). If the total violation is:\n * Zero\n * - Freeze all items.\n *\n * Positive\n * - Freeze all the items with min violations.\n *\n * Negative\n * - Freeze all the items with max violations.\n */\n hasNonFrozenItems = false;\n flexItems.forEach(item => {\n if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) {\n item.frozen = true;\n } else if (!item.frozen) {\n hasNonFrozenItems = true;\n }\n });\n }\n\n return cascadeRounding(flexItems);\n}\n\nfunction cascadeRounding(flexItems): number[] {\n /*\n Given an array of floats that sum to an integer, this rounds the floats\n and returns an array of integers with the same sum.\n */\n\n let fpTotal = 0;\n let intTotal = 0;\n let roundedArray = [];\n flexItems.forEach(function (item) {\n let float = item.targetMainSize;\n let integer = Math.round(float + fpTotal) - intTotal;\n fpTotal += float;\n intTotal += integer;\n roundedArray.push(integer);\n });\n\n return roundedArray;\n}\n"],"names":[],"version":3,"file":"TableUtils.module.js.map"}