@react-stately/table 3.15.4 → 3.16.0

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 (76) hide show
  1. package/dist/import.mjs +6 -18
  2. package/dist/main.js +18 -30
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +6 -18
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +9 -0
  7. package/package.json +17 -20
  8. package/src/index.ts +9 -16
  9. package/dist/Cell.main.js +0 -38
  10. package/dist/Cell.main.js.map +0 -1
  11. package/dist/Cell.mjs +0 -33
  12. package/dist/Cell.module.js +0 -33
  13. package/dist/Cell.module.js.map +0 -1
  14. package/dist/Column.main.js +0 -75
  15. package/dist/Column.main.js.map +0 -1
  16. package/dist/Column.mjs +0 -66
  17. package/dist/Column.module.js +0 -66
  18. package/dist/Column.module.js.map +0 -1
  19. package/dist/Row.main.js +0 -102
  20. package/dist/Row.main.js.map +0 -1
  21. package/dist/Row.mjs +0 -93
  22. package/dist/Row.module.js +0 -93
  23. package/dist/Row.module.js.map +0 -1
  24. package/dist/TableBody.main.js +0 -61
  25. package/dist/TableBody.main.js.map +0 -1
  26. package/dist/TableBody.mjs +0 -52
  27. package/dist/TableBody.module.js +0 -52
  28. package/dist/TableBody.module.js.map +0 -1
  29. package/dist/TableCollection.main.js +0 -308
  30. package/dist/TableCollection.main.js.map +0 -1
  31. package/dist/TableCollection.mjs +0 -302
  32. package/dist/TableCollection.module.js +0 -302
  33. package/dist/TableCollection.module.js.map +0 -1
  34. package/dist/TableColumnLayout.main.js +0 -113
  35. package/dist/TableColumnLayout.main.js.map +0 -1
  36. package/dist/TableColumnLayout.mjs +0 -108
  37. package/dist/TableColumnLayout.module.js +0 -108
  38. package/dist/TableColumnLayout.module.js.map +0 -1
  39. package/dist/TableHeader.main.js +0 -56
  40. package/dist/TableHeader.main.js.map +0 -1
  41. package/dist/TableHeader.mjs +0 -47
  42. package/dist/TableHeader.module.js +0 -47
  43. package/dist/TableHeader.module.js.map +0 -1
  44. package/dist/TableUtils.main.js +0 -182
  45. package/dist/TableUtils.main.js.map +0 -1
  46. package/dist/TableUtils.mjs +0 -175
  47. package/dist/TableUtils.module.js +0 -175
  48. package/dist/TableUtils.module.js.map +0 -1
  49. package/dist/types.d.ts +0 -194
  50. package/dist/types.d.ts.map +0 -1
  51. package/dist/useTableColumnResizeState.main.js +0 -109
  52. package/dist/useTableColumnResizeState.main.js.map +0 -1
  53. package/dist/useTableColumnResizeState.mjs +0 -104
  54. package/dist/useTableColumnResizeState.module.js +0 -104
  55. package/dist/useTableColumnResizeState.module.js.map +0 -1
  56. package/dist/useTableState.main.js +0 -86
  57. package/dist/useTableState.main.js.map +0 -1
  58. package/dist/useTableState.mjs +0 -80
  59. package/dist/useTableState.module.js +0 -80
  60. package/dist/useTableState.module.js.map +0 -1
  61. package/dist/useTreeGridState.main.js +0 -207
  62. package/dist/useTreeGridState.main.js.map +0 -1
  63. package/dist/useTreeGridState.mjs +0 -202
  64. package/dist/useTreeGridState.module.js +0 -202
  65. package/dist/useTreeGridState.module.js.map +0 -1
  66. package/src/Cell.ts +0 -40
  67. package/src/Column.ts +0 -83
  68. package/src/Row.ts +0 -121
  69. package/src/TableBody.ts +0 -61
  70. package/src/TableCollection.ts +0 -367
  71. package/src/TableColumnLayout.ts +0 -127
  72. package/src/TableHeader.ts +0 -59
  73. package/src/TableUtils.ts +0 -266
  74. package/src/useTableColumnResizeState.ts +0 -147
  75. package/src/useTableState.ts +0 -124
  76. package/src/useTreeGridState.ts +0 -278
@@ -1,108 +0,0 @@
1
- import {calculateColumnSizes as $6818b1c4fc67028d$export$55d50dc687385491, getMaxWidth as $6818b1c4fc67028d$export$59185c62a7544aa0, getMinWidth as $6818b1c4fc67028d$export$f556054ce4358701} from "./TableUtils.module.js";
2
-
3
- /*
4
- * Copyright 2022 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
- class $a9e7ae544a4e41dd$export$7ff77a162970b30e {
15
- /** Takes an array of columns and splits it into 2 maps of columns with controlled and columns with uncontrolled widths. */ splitColumnsIntoControlledAndUncontrolled(columns) {
16
- return columns.reduce((acc, col)=>{
17
- if (col.props.width != null) acc[0].set(col.key, col);
18
- else acc[1].set(col.key, col);
19
- return acc;
20
- }, [
21
- new Map(),
22
- new Map()
23
- ]);
24
- }
25
- /** Takes uncontrolled and controlled widths and joins them into a single Map. */ recombineColumns(columns, uncontrolledWidths, uncontrolledColumns, controlledColumns) {
26
- return new Map(columns.map((col)=>{
27
- if (uncontrolledColumns.has(col.key)) return [
28
- col.key,
29
- uncontrolledWidths.get(col.key)
30
- ];
31
- else return [
32
- col.key,
33
- controlledColumns.get(col.key).props.width
34
- ];
35
- }));
36
- }
37
- /** Used to make an initial Map of the uncontrolled widths based on default widths. */ getInitialUncontrolledWidths(uncontrolledColumns) {
38
- return new Map(Array.from(uncontrolledColumns).map(([key, col])=>{
39
- var _this_getDefaultWidth, _this;
40
- var _col_props_defaultWidth, _ref;
41
- return [
42
- key,
43
- (_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'
44
- ];
45
- }));
46
- }
47
- getColumnWidth(key) {
48
- var _this_columnWidths_get;
49
- return (_this_columnWidths_get = this.columnWidths.get(key)) !== null && _this_columnWidths_get !== void 0 ? _this_columnWidths_get : 0;
50
- }
51
- getColumnMinWidth(key) {
52
- var _this_columnMinWidths_get;
53
- return (_this_columnMinWidths_get = this.columnMinWidths.get(key)) !== null && _this_columnMinWidths_get !== void 0 ? _this_columnMinWidths_get : 0;
54
- }
55
- getColumnMaxWidth(key) {
56
- var _this_columnMaxWidths_get;
57
- return (_this_columnMaxWidths_get = this.columnMaxWidths.get(key)) !== null && _this_columnMaxWidths_get !== void 0 ? _this_columnMaxWidths_get : 0;
58
- }
59
- resizeColumnWidth(collection, uncontrolledWidths, col, width) {
60
- let prevColumnWidths = this.columnWidths;
61
- let freeze = true;
62
- let newWidths = new Map();
63
- width = Math.max(this.getColumnMinWidth(col), Math.min(this.getColumnMaxWidth(col), Math.floor(width)));
64
- collection.columns.forEach((column)=>{
65
- var _prevColumnWidths_get, _column_props_width;
66
- if (column.key === col) {
67
- newWidths.set(column.key, width);
68
- freeze = false;
69
- } else if (freeze) // freeze columns to the left to their previous pixel value
70
- newWidths.set(column.key, (_prevColumnWidths_get = prevColumnWidths.get(column.key)) !== null && _prevColumnWidths_get !== void 0 ? _prevColumnWidths_get : 0);
71
- else newWidths.set(column.key, (_column_props_width = column.props.width) !== null && _column_props_width !== void 0 ? _column_props_width : uncontrolledWidths.get(column.key));
72
- });
73
- return newWidths;
74
- }
75
- buildColumnWidths(tableWidth, collection, widths) {
76
- this.columnWidths = new Map();
77
- this.columnMinWidths = new Map();
78
- this.columnMaxWidths = new Map();
79
- // initial layout or table/window resizing
80
- let columnWidths = (0, $6818b1c4fc67028d$export$55d50dc687385491)(tableWidth, collection.columns.map((col)=>({
81
- ...col.props,
82
- key: col.key
83
- })), widths, (i)=>this.getDefaultWidth(collection.columns[i]), (i)=>this.getDefaultMinWidth(collection.columns[i]));
84
- // columns going in will be the same order as the columns coming out
85
- columnWidths.forEach((width, index)=>{
86
- let key = collection.columns[index].key;
87
- let column = collection.columns[index];
88
- this.columnWidths.set(key, width);
89
- var _column_props_minWidth;
90
- this.columnMinWidths.set(key, (0, $6818b1c4fc67028d$export$f556054ce4358701)((_column_props_minWidth = column.props.minWidth) !== null && _column_props_minWidth !== void 0 ? _column_props_minWidth : this.getDefaultMinWidth(column), tableWidth));
91
- this.columnMaxWidths.set(key, (0, $6818b1c4fc67028d$export$59185c62a7544aa0)(column.props.maxWidth, tableWidth));
92
- });
93
- return this.columnWidths;
94
- }
95
- constructor(options){
96
- this.columnWidths = new Map();
97
- this.columnMinWidths = new Map();
98
- this.columnMaxWidths = new Map();
99
- var _options_getDefaultWidth;
100
- this.getDefaultWidth = (_options_getDefaultWidth = options === null || options === void 0 ? void 0 : options.getDefaultWidth) !== null && _options_getDefaultWidth !== void 0 ? _options_getDefaultWidth : ()=>'1fr';
101
- var _options_getDefaultMinWidth;
102
- this.getDefaultMinWidth = (_options_getDefaultMinWidth = options === null || options === void 0 ? void 0 : options.getDefaultMinWidth) !== null && _options_getDefaultMinWidth !== void 0 ? _options_getDefaultMinWidth : ()=>75;
103
- }
104
- }
105
-
106
-
107
- export {$a9e7ae544a4e41dd$export$7ff77a162970b30e as TableColumnLayout};
108
- //# sourceMappingURL=TableColumnLayout.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAgBM,MAAM;IAYX,yHAAyH,GACzH,0CAA0C,OAA2B,EAAkD;QACrH,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK;YAC1B,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,MACrB,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE;iBAEpB,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE;YAEtB,OAAO;QACT,GAAG;YAAC,IAAI;YAAO,IAAI;SAAM;IAC3B;IAEA,+EAA+E,GAC/E,iBAAiB,OAA2B,EAAE,kBAAwC,EAAE,mBAA0C,EAAE,iBAAwC,EAAwB;QAClM,OAAO,IAAI,IAAI,QAAQ,GAAG,CAAC,CAAA;YACzB,IAAI,oBAAoB,GAAG,CAAC,IAA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AC,QAAQ,cAArB,oCAAA,yBAAyB,IAAI,CAAC,kBAAkB,CAAC,SAAS;YACpG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAA,GAAA,yCAAU,EAAE,OAAO,KAAK,CAAC,QAAQ,EAAE;QACnE;QACA,OAAO,IAAI,CAAC,YAAY;IAC1B;IA5FA,YAAY,OAAoC,CAAE;aAJlD,eAAiC,IAAI;aACrC,kBAAoC,IAAI;aACxC,kBAAoC,IAAI;YAGf;QAAvB,IAAI,CAAC,eAAe,GAAG,CAAA,2BAAA,oBAAA,8BAAA,QAAS,eAAe,cAAxB,sCAAA,2BAA6B,IAAM;YAChC;QAA1B,IAAI,CAAC,kBAAkB,GAAG,CAAA,8BAAA,oBAAA,8BAAA,QAAS,kBAAkB,cAA3B,yCAAA,8BAAgC,IAAM;IAClE;AA0FF","sources":["packages/@react-stately/table/src/TableColumnLayout.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 {\n calculateColumnSizes,\n getMaxWidth,\n getMinWidth\n} from './TableUtils';\nimport {ColumnSize, TableCollection} from '@react-types/table';\nimport {GridNode} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\n\nexport interface TableColumnLayoutOptions<T> {\n getDefaultWidth?: (column: GridNode<T>) => ColumnSize | null | undefined,\n getDefaultMinWidth?: (column: GridNode<T>) => ColumnSize | null | undefined\n}\n\nexport class TableColumnLayout<T> {\n getDefaultWidth: (column: GridNode<T>) => ColumnSize | null | undefined;\n getDefaultMinWidth: (column: GridNode<T>) => ColumnSize | null | undefined;\n columnWidths: Map<Key, number> = new Map();\n columnMinWidths: Map<Key, number> = new Map();\n columnMaxWidths: Map<Key, number> = new Map();\n\n constructor(options: TableColumnLayoutOptions<T>) {\n this.getDefaultWidth = options?.getDefaultWidth ?? (() => '1fr');\n this.getDefaultMinWidth = options?.getDefaultMinWidth ?? (() => 75);\n }\n\n /** Takes an array of columns and splits it into 2 maps of columns with controlled and columns with uncontrolled widths. */\n splitColumnsIntoControlledAndUncontrolled(columns: Array<GridNode<T>>): [Map<Key, GridNode<T>>, Map<Key, GridNode<T>>] {\n return columns.reduce((acc, col) => {\n if (col.props.width != null) {\n acc[0].set(col.key, col);\n } else {\n acc[1].set(col.key, col);\n }\n return acc;\n }, [new Map(), new Map()]);\n }\n\n /** Takes uncontrolled and controlled widths and joins them into a single Map. */\n recombineColumns(columns: Array<GridNode<T>>, uncontrolledWidths: Map<Key, ColumnSize>, uncontrolledColumns: Map<Key, GridNode<T>>, controlledColumns: Map<Key, GridNode<T>>): Map<Key, ColumnSize> {\n return new Map(columns.map(col => {\n if (uncontrolledColumns.has(col.key)) {\n return [col.key, uncontrolledWidths.get(col.key)];\n } else {\n return [col.key, controlledColumns.get(col.key)!.props.width];\n }\n }));\n }\n\n /** Used to make an initial Map of the uncontrolled widths based on default widths. */\n getInitialUncontrolledWidths(uncontrolledColumns: Map<Key, GridNode<T>>): Map<Key, ColumnSize> {\n return new Map(Array.from(uncontrolledColumns).map(([key, col]) =>\n [key, col.props.defaultWidth ?? this.getDefaultWidth?.(col) ?? '1fr']\n ));\n }\n\n getColumnWidth(key: Key): number {\n return this.columnWidths.get(key) ?? 0;\n }\n\n getColumnMinWidth(key: Key): number {\n return this.columnMinWidths.get(key) ?? 0;\n }\n\n getColumnMaxWidth(key: Key): number {\n return this.columnMaxWidths.get(key) ?? 0;\n }\n\n resizeColumnWidth(collection: TableCollection<T>, uncontrolledWidths: Map<Key, ColumnSize>, col: Key, width: number): Map<Key, ColumnSize> {\n let prevColumnWidths = this.columnWidths;\n let freeze = true;\n let newWidths = new Map<Key, ColumnSize>();\n\n width = Math.max(this.getColumnMinWidth(col), Math.min(this.getColumnMaxWidth(col), Math.floor(width)));\n\n collection.columns.forEach(column => {\n if (column.key === col) {\n newWidths.set(column.key, width);\n freeze = false;\n } else if (freeze) {\n // freeze columns to the left to their previous pixel value\n newWidths.set(column.key, prevColumnWidths.get(column.key) ?? 0);\n } else {\n newWidths.set(column.key, column.props.width ?? uncontrolledWidths.get(column.key));\n }\n });\n\n return newWidths;\n }\n\n buildColumnWidths(tableWidth: number, collection: TableCollection<T>, widths: Map<Key, ColumnSize>): Map<Key, number> {\n this.columnWidths = new Map();\n this.columnMinWidths = new Map();\n this.columnMaxWidths = new Map();\n\n // initial layout or table/window resizing\n let columnWidths = calculateColumnSizes(\n tableWidth,\n collection.columns.map(col => ({...col.props, key: col.key})),\n widths,\n (i) => this.getDefaultWidth(collection.columns[i]),\n (i) => this.getDefaultMinWidth(collection.columns[i])\n );\n\n // columns going in will be the same order as the columns coming out\n columnWidths.forEach((width, index) => {\n let key = collection.columns[index].key;\n let column = collection.columns[index];\n this.columnWidths.set(key, width);\n this.columnMinWidths.set(key, getMinWidth(column.props.minWidth ?? this.getDefaultMinWidth(column), tableWidth));\n this.columnMaxWidths.set(key, getMaxWidth(column.props.maxWidth, tableWidth));\n });\n return this.columnWidths;\n }\n}\n"],"names":[],"version":3,"file":"TableColumnLayout.module.js.map"}
@@ -1,56 +0,0 @@
1
- var $kcTb5$react = require("react");
2
-
3
-
4
- function $parcel$interopDefault(a) {
5
- return a && a.__esModule ? a.default : a;
6
- }
7
-
8
- function $parcel$export(e, n, v, s) {
9
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
- }
11
-
12
- $parcel$export(module.exports, "TableHeader", () => $f45775f5d6f744fa$export$f850895b287ef28e);
13
- /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */
24
- function $f45775f5d6f744fa$var$TableHeader(props) {
25
- return null;
26
- }
27
- $f45775f5d6f744fa$var$TableHeader.getCollectionNode = function* getCollectionNode(props, context) {
28
- let { children: children, columns: columns } = props;
29
- // Clear columns so they aren't double added in strict mode.
30
- context.columns = [];
31
- if (typeof children === 'function') {
32
- if (!columns) throw new Error('props.children was a function but props.columns is missing');
33
- for (let column of columns)yield {
34
- type: 'column',
35
- value: column,
36
- renderer: children
37
- };
38
- } else {
39
- let columns = [];
40
- (0, ($parcel$interopDefault($kcTb5$react))).Children.forEach(children, (column)=>{
41
- columns.push({
42
- type: 'column',
43
- element: column
44
- });
45
- });
46
- yield* columns;
47
- }
48
- };
49
- /**
50
- * A TableHeader is a container for the Column elements in a Table. Columns can be statically defined
51
- * as children, or generated dynamically using a function based on the data passed to the `columns` prop.
52
- */ // We don't want getCollectionNode to show up in the type definition
53
- let $f45775f5d6f744fa$export$f850895b287ef28e = $f45775f5d6f744fa$var$TableHeader;
54
-
55
-
56
- //# sourceMappingURL=TableHeader.main.js.map
@@ -1 +0,0 @@
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,sCAAI,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 | null { // 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.main.js.map"}
@@ -1,47 +0,0 @@
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
@@ -1,47 +0,0 @@
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
@@ -1 +0,0 @@
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 | null { // 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"}
@@ -1,182 +0,0 @@
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, "getMaxWidth", () => $9e5f6a0caf75716e$export$59185c62a7544aa0);
7
- $parcel$export(module.exports, "getMinWidth", () => $9e5f6a0caf75716e$export$f556054ce4358701);
8
- $parcel$export(module.exports, "calculateColumnSizes", () => $9e5f6a0caf75716e$export$55d50dc687385491);
9
- /*
10
- * Copyright 2022 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */ function $9e5f6a0caf75716e$export$1994a077b98ee0d5(width) {
20
- return width != null && (!isNaN(width) || String(width).match(/^(\d+)(?=%$)/) !== null);
21
- }
22
- function $9e5f6a0caf75716e$export$9078bad4c3934604(width) {
23
- if (!width || typeof width === 'number') return 1;
24
- let match = width.match(/^(.+)(?=fr$)/);
25
- // if width is the incorrect format, just default it to a 1fr
26
- if (!match) {
27
- if (process.env.NODE_ENV !== 'production') 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\'');
28
- return 1;
29
- }
30
- return parseFloat(match[0]);
31
- }
32
- function $9e5f6a0caf75716e$export$7bbad27896f7ae9f(width, tableWidth) {
33
- if (typeof width === 'string') {
34
- let match = width.match(/^(\d+)(?=%$)/);
35
- if (!match) throw new Error('Only percentages or numbers are supported for static column widths');
36
- return tableWidth * (parseFloat(match[0]) / 100);
37
- }
38
- return width;
39
- }
40
- function $9e5f6a0caf75716e$export$59185c62a7544aa0(maxWidth, tableWidth) {
41
- return maxWidth != null ? $9e5f6a0caf75716e$export$7bbad27896f7ae9f(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;
42
- }
43
- function $9e5f6a0caf75716e$export$f556054ce4358701(minWidth, tableWidth) {
44
- return minWidth != null ? $9e5f6a0caf75716e$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
45
- }
46
- function $9e5f6a0caf75716e$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
47
- let hasNonFrozenItems = false;
48
- let flexItems = columns.map((column, index)=>{
49
- var _changedColumns_get, _column_width, _ref, _ref1;
50
- let width = changedColumns.get(column.key) != null ? (_changedColumns_get = changedColumns.get(column.key)) !== null && _changedColumns_get !== void 0 ? _changedColumns_get : '1fr' : (_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';
51
- let frozen = false;
52
- let baseSize = 0;
53
- let flex = 0;
54
- let targetMainSize = 0;
55
- if ($9e5f6a0caf75716e$export$1994a077b98ee0d5(width)) {
56
- baseSize = $9e5f6a0caf75716e$export$7bbad27896f7ae9f(width, availableWidth);
57
- frozen = true;
58
- } else {
59
- flex = $9e5f6a0caf75716e$export$9078bad4c3934604(width);
60
- if (flex <= 0) frozen = true;
61
- }
62
- var _column_minWidth, _ref2;
63
- 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);
64
- let max = $9e5f6a0caf75716e$export$59185c62a7544aa0(column.maxWidth, availableWidth);
65
- let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
66
- // 9.7.1
67
- // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.
68
- // 9.7.2
69
- if (frozen) targetMainSize = hypotheticalMainSize;
70
- else if (baseSize > hypotheticalMainSize) {
71
- frozen = true;
72
- targetMainSize = hypotheticalMainSize;
73
- }
74
- // 9.7.3
75
- if (!frozen) hasNonFrozenItems = true;
76
- return {
77
- frozen: frozen,
78
- baseSize: baseSize,
79
- hypotheticalMainSize: hypotheticalMainSize,
80
- min: min,
81
- max: max,
82
- flex: flex,
83
- targetMainSize: targetMainSize,
84
- violation: 0
85
- };
86
- });
87
- // 9.7.4
88
- // 9.7.4.a
89
- while(hasNonFrozenItems){
90
- // 9.7.4.b
91
- /**
92
- * Calculate the remaining free space as for initial free space,
93
- * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is
94
- * less than one, multiply the initial free space by this sum (of flex factors).
95
- * If the magnitude of this value is less than the magnitude of
96
- * the remaining free space, use this as the remaining free space.
97
- */ let usedWidth = 0;
98
- let flexFactors = 0;
99
- flexItems.forEach((item)=>{
100
- if (item.frozen) usedWidth += item.targetMainSize;
101
- else {
102
- usedWidth += item.baseSize;
103
- flexFactors += item.flex;
104
- }
105
- });
106
- let remainingFreeSpace = availableWidth - usedWidth;
107
- // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0
108
- // so no need to check for flexFactors < 1
109
- // 9.7.4.c
110
- /**
111
- * If the remaining free space is zero
112
- * - Do nothing.
113
- * Else // remember, we're always in grow mode
114
- * - Find the ratio of the item’s flex grow factor to the
115
- * sum of the flex grow factors of all unfrozen items on
116
- * the line. Set the item’s target main size to its flex
117
- * base size plus a fraction of the remaining free space
118
- * proportional to the ratio.
119
- */ if (remainingFreeSpace > 0) flexItems.forEach((item)=>{
120
- if (!item.frozen) {
121
- let ratio = item.flex / flexFactors;
122
- item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
123
- }
124
- });
125
- // 9.7.4.d
126
- /**
127
- * Fix min/max violations. Clamp each non-frozen item’s
128
- * target main size by its used min and max main sizes
129
- * and floor its content-box size at zero. If the item’s
130
- * target main size was made smaller by this, it’s a max
131
- * violation. If the item’s target main size was made
132
- * larger by this, it’s a min violation.
133
- */ let totalViolation = 0;
134
- flexItems.forEach((item)=>{
135
- item.violation = 0;
136
- if (!item.frozen) {
137
- let { min: min, max: max, targetMainSize: targetMainSize } = item;
138
- item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
139
- item.violation = item.targetMainSize - targetMainSize;
140
- totalViolation += item.violation;
141
- }
142
- });
143
- // 9.7.4.e
144
- /**
145
- * Freeze over-flexed items. The total violation is the
146
- * sum of the adjustments from the previous step
147
- * ∑(clamped size - unclamped size). If the total violation is:
148
- * Zero
149
- * - Freeze all items.
150
- *
151
- * Positive
152
- * - Freeze all the items with min violations.
153
- *
154
- * Negative
155
- * - Freeze all the items with max violations.
156
- */ hasNonFrozenItems = false;
157
- flexItems.forEach((item)=>{
158
- if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
159
- else if (!item.frozen) hasNonFrozenItems = true;
160
- });
161
- }
162
- return $9e5f6a0caf75716e$var$cascadeRounding(flexItems);
163
- }
164
- function $9e5f6a0caf75716e$var$cascadeRounding(flexItems) {
165
- /*
166
- Given an array of floats that sum to an integer, this rounds the floats
167
- and returns an array of integers with the same sum.
168
- */ let fpTotal = 0;
169
- let intTotal = 0;
170
- let roundedArray = [];
171
- flexItems.forEach(function(item) {
172
- let float = item.targetMainSize;
173
- let integer = Math.round(float + fpTotal) - intTotal;
174
- fpTotal += float;
175
- intT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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?: ColumnSize | null): boolean {\n return width != null && (!isNaN(width as number) || (String(width)).match(/^(\\d+)(?=%$)/) !== null);\n}\n\nexport function parseFractionalUnit(width?: ColumnSize | null): number {\n if (!width || typeof width === 'number') {\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 if (process.env.NODE_ENV !== 'production') {\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 }\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 | null | undefined, 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\ninterface FlexItem {\n frozen: boolean,\n baseSize: number,\n hypotheticalMainSize: number,\n min: number,\n max: number,\n flex: number,\n targetMainSize: number,\n violation: number\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?: (index: number) => ColumnSize | null | undefined, getDefaultMinWidth?: (index: number) => ColumnSize | null | undefined): number[] {\n let hasNonFrozenItems = false;\n let flexItems: FlexItem[] = columns.map((column, index) => {\n let width: ColumnSize = (changedColumns.get(column.key) != null ? changedColumns.get(column.key) ?? '1fr' : column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr') as ColumnSize;\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = 0;\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: FlexItem[]): 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: number[] = [];\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"}