@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,109 +0,0 @@
1
- var $2240a72410c17d51$exports = require("./TableColumnLayout.main.js");
2
- var $cVZrS$react = require("react");
3
-
4
-
5
- function $parcel$export(e, n, v, s) {
6
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
- }
8
-
9
- $parcel$export(module.exports, "useTableColumnResizeState", () => $7aa22d80cd4ca621$export$cb895dcf85db1319);
10
- /*
11
- * Copyright 2022 Adobe. All rights reserved.
12
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License. You may obtain a copy
14
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software distributed under
17
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
- * OF ANY KIND, either express or implied. See the License for the specific language
19
- * governing permissions and limitations under the License.
20
- */
21
-
22
- function $7aa22d80cd4ca621$export$cb895dcf85db1319(props, state) {
23
- let { getDefaultWidth: getDefaultWidth, getDefaultMinWidth: getDefaultMinWidth, tableWidth: tableWidth = 0 } = props;
24
- let [resizingColumn, setResizingColumn] = (0, $cVZrS$react.useState)(null);
25
- let columnLayout = (0, $cVZrS$react.useMemo)(()=>new (0, $2240a72410c17d51$exports.TableColumnLayout)({
26
- getDefaultWidth: getDefaultWidth,
27
- getDefaultMinWidth: getDefaultMinWidth
28
- }), [
29
- getDefaultWidth,
30
- getDefaultMinWidth
31
- ]);
32
- let [controlledColumns, uncontrolledColumns] = (0, $cVZrS$react.useMemo)(()=>columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns), [
33
- state.collection.columns,
34
- columnLayout
35
- ]);
36
- // uncontrolled column widths
37
- let [uncontrolledWidths, setUncontrolledWidths] = (0, $cVZrS$react.useState)(()=>columnLayout.getInitialUncontrolledWidths(uncontrolledColumns));
38
- // Update uncontrolled widths if the columns changed.
39
- let [lastColumns, setLastColumns] = (0, $cVZrS$react.useState)(state.collection.columns);
40
- if (state.collection.columns !== lastColumns) {
41
- if (state.collection.columns.length !== lastColumns.length || state.collection.columns.some((c, i)=>c.key !== lastColumns[i].key)) {
42
- let newUncontrolledWidths = columnLayout.getInitialUncontrolledWidths(uncontrolledColumns);
43
- setUncontrolledWidths(newUncontrolledWidths);
44
- }
45
- setLastColumns(state.collection.columns);
46
- }
47
- // combine columns back into one map that maintains same order as the columns
48
- let colWidths = (0, $cVZrS$react.useMemo)(()=>columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns), [
49
- state.collection.columns,
50
- uncontrolledWidths,
51
- uncontrolledColumns,
52
- controlledColumns,
53
- columnLayout
54
- ]);
55
- let startResize = (0, $cVZrS$react.useCallback)((key)=>{
56
- setResizingColumn(key);
57
- }, [
58
- setResizingColumn
59
- ]);
60
- let updateResizedColumns = (0, $cVZrS$react.useCallback)((key, width)=>{
61
- let newSizes = columnLayout.resizeColumnWidth(state.collection, uncontrolledWidths, key, width);
62
- let map = new Map(Array.from(uncontrolledColumns).map(([key])=>[
63
- key,
64
- newSizes.get(key)
65
- ]));
66
- map.set(key, width);
67
- setUncontrolledWidths(map);
68
- return newSizes;
69
- }, [
70
- uncontrolledColumns,
71
- setUncontrolledWidths,
72
- columnLayout,
73
- state.collection,
74
- uncontrolledWidths
75
- ]);
76
- let endResize = (0, $cVZrS$react.useCallback)(()=>{
77
- setResizingColumn(null);
78
- }, [
79
- setResizingColumn
80
- ]);
81
- let columnWidths = (0, $cVZrS$react.useMemo)(()=>columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths), [
82
- tableWidth,
83
- state.collection,
84
- colWidths,
85
- columnLayout
86
- ]);
87
- return (0, $cVZrS$react.useMemo)(()=>({
88
- resizingColumn: resizingColumn,
89
- updateResizedColumns: updateResizedColumns,
90
- startResize: startResize,
91
- endResize: endResize,
92
- getColumnWidth: (key)=>columnLayout.getColumnWidth(key),
93
- getColumnMinWidth: (key)=>columnLayout.getColumnMinWidth(key),
94
- getColumnMaxWidth: (key)=>columnLayout.getColumnMaxWidth(key),
95
- tableState: state,
96
- columnWidths: columnWidths
97
- }), [
98
- columnLayout,
99
- columnWidths,
100
- resizingColumn,
101
- updateResizedColumns,
102
- startResize,
103
- endResize,
104
- state
105
- ]);
106
- }
107
-
108
-
109
- //# sourceMappingURL=useTableColumnResizeState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;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,IAAI,cAAc,CAAA,GAAA,wBAAU,EAAE,CAAC;QAC7B,kBAAkB;IACpB,GAAG;QAAC;KAAkB;IAEtB,IAAI,uBAAuB,CAAA,GAAA,wBAAU,EAAE,CAAC,KAAU;QAChD,IAAI,WAAW,aAAa,iBAAiB,CAAC,MAAM,UAAU,EAAE,oBAAoB,KAAK;QACzF,IAAI,MAAM,IAAI,IAAI,MAAM,IAAI,CAAC,qBAAqB,GAAG,CAAC,CAAC,CAAC,IAAI,GAAK;gBAAC;gBAAK,SAAS,GAAG,CAAC;aAAM;QAC1F,IAAI,GAAG,CAAC,KAAK;QACb,sBAAsB;QACtB,OAAO;IACT,GAAG;QAAC;QAAqB;QAAuB;QAAc,MAAM,UAAU;QAAE;KAAmB;IAEnG,IAAI,YAAY,CAAA,GAAA,wBAAU,EAAE;QAC1B,kBAAkB;IACpB,GAAG;QAAC;KAAkB;IAEtB,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IACzB,aAAa,iBAAiB,CAAC,YAAY,MAAM,UAAU,EAAE,YAC7D;QAAC;QAAY,MAAM,UAAU;QAAE;QAAW;KAAa;IAEzD,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;4BACpB;kCACA;yBACA;uBACA;YACA,gBAAgB,CAAC,MACf,aAAa,cAAc,CAAC;YAC9B,mBAAmB,CAAC,MAClB,aAAa,iBAAiB,CAAC;YACjC,mBAAmB,CAAC,MAClB,aAAa,iBAAiB,CAAC;YACjC,YAAY;0BACZ;QACF,CAAA,GAAI;QACF;QACA;QACA;QACA;QACA;QACA;QACA;KACD;AACH","sources":["packages/@react-stately/table/src/useTableColumnResizeState.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 {GridNode} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\nimport {TableColumnLayout} from './TableColumnLayout';\nimport {TableState} from './useTableState';\nimport {useCallback, useMemo, useState} from 'react';\n\nexport interface TableColumnResizeStateProps<T> {\n /**\n * Current width of the table or table viewport that the columns\n * should be calculated against.\n */\n tableWidth: number,\n /** A function that is called to find the default width for a given column. */\n getDefaultWidth?: (node: GridNode<T>) => ColumnSize | null | undefined,\n /** A function that is called to find the default minWidth for a given column. */\n getDefaultMinWidth?: (node: GridNode<T>) => ColumnSize | null | undefined\n}\nexport interface TableColumnResizeState<T> {\n /**\n * Called to update the state that a resize event has occurred.\n * Returns the new widths for all columns based on the resized column.\n */\n updateResizedColumns: (key: Key, width: number) => Map<Key, ColumnSize>,\n /** Callback for when onColumnResize has started. */\n startResize: (key: Key) => void,\n /** Callback for when onColumnResize has ended. */\n endResize: () => void,\n /** Gets the current width for the specified column. */\n getColumnWidth: (key: Key) => number,\n /** Gets the current minWidth for the specified column. */\n getColumnMinWidth: (key: Key) => number,\n /** Gets the current maxWidth for the specified column. */\n getColumnMaxWidth: (key: Key) => number,\n /** Key of the currently resizing column. */\n resizingColumn: Key | null,\n /** A reference to the table state. */\n tableState: TableState<T>,\n /** A map of the current column widths. */\n columnWidths: Map<Key, number>\n}\n\n/**\n * Provides column width state management for a table component with column resizing support. Handles building\n * a map of column widths calculated from the table's width and any provided column width information from the collection.\n * In addition, it tracks the currently resizing column and provides callbacks for updating the widths upon resize operations.\n * @param props - Props for the table.\n * @param state - State for the table, as returned by `useTableState`.\n */\nexport function useTableColumnResizeState<T>(props: TableColumnResizeStateProps<T>, state: TableState<T>): TableColumnResizeState<T> {\n let {\n getDefaultWidth,\n getDefaultMinWidth,\n tableWidth = 0\n } = props;\n\n let [resizingColumn, setResizingColumn] = useState<Key | null>(null);\n let columnLayout = useMemo(\n () => new TableColumnLayout({\n getDefaultWidth,\n getDefaultMinWidth\n }),\n [getDefaultWidth, getDefaultMinWidth]\n );\n\n let [controlledColumns, uncontrolledColumns] = useMemo(() =>\n columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns)\n , [state.collection.columns, columnLayout]);\n\n // uncontrolled column widths\n let [uncontrolledWidths, setUncontrolledWidths] = useState(() =>\n columnLayout.getInitialUncontrolledWidths(uncontrolledColumns)\n );\n\n // Update uncontrolled widths if the columns changed.\n let [lastColumns, setLastColumns] = useState(state.collection.columns);\n if (state.collection.columns !== lastColumns) {\n if (\n state.collection.columns.length !== lastColumns.length ||\n state.collection.columns.some((c, i) => c.key !== lastColumns[i].key)\n ) {\n let newUncontrolledWidths = columnLayout.getInitialUncontrolledWidths(uncontrolledColumns);\n setUncontrolledWidths(newUncontrolledWidths);\n }\n setLastColumns(state.collection.columns);\n }\n\n // combine columns back into one map that maintains same order as the columns\n let colWidths = useMemo(() =>\n columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns)\n , [state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns, columnLayout]);\n\n let startResize = useCallback((key: Key) => {\n setResizingColumn(key);\n }, [setResizingColumn]);\n\n let updateResizedColumns = useCallback((key: Key, width: number): Map<Key, ColumnSize> => {\n let newSizes = columnLayout.resizeColumnWidth(state.collection, uncontrolledWidths, key, width);\n let map = new Map(Array.from(uncontrolledColumns).map(([key]) => [key, newSizes.get(key)!]));\n map.set(key, width);\n setUncontrolledWidths(map);\n return newSizes;\n }, [uncontrolledColumns, setUncontrolledWidths, columnLayout, state.collection, uncontrolledWidths]);\n\n let endResize = useCallback(() => {\n setResizingColumn(null);\n }, [setResizingColumn]);\n\n let columnWidths = useMemo(() =>\n columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths)\n , [tableWidth, state.collection, colWidths, columnLayout]);\n\n return useMemo(() => ({\n resizingColumn,\n updateResizedColumns,\n startResize,\n endResize,\n getColumnWidth: (key: Key) =>\n columnLayout.getColumnWidth(key),\n getColumnMinWidth: (key: Key) =>\n columnLayout.getColumnMinWidth(key),\n getColumnMaxWidth: (key: Key) =>\n columnLayout.getColumnMaxWidth(key),\n tableState: state,\n columnWidths\n }), [\n columnLayout,\n columnWidths,\n resizingColumn,\n updateResizedColumns,\n startResize,\n endResize,\n state\n ]);\n}\n"],"names":[],"version":3,"file":"useTableColumnResizeState.main.js.map"}
@@ -1,104 +0,0 @@
1
- import {TableColumnLayout as $a9e7ae544a4e41dd$export$7ff77a162970b30e} from "./TableColumnLayout.mjs";
2
- import {useState as $cPT3l$useState, useMemo as $cPT3l$useMemo, useCallback as $cPT3l$useCallback} from "react";
3
-
4
- /*
5
- * Copyright 2022 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- function $292bc4e09cd0eb62$export$cb895dcf85db1319(props, state) {
17
- let { getDefaultWidth: getDefaultWidth, getDefaultMinWidth: getDefaultMinWidth, tableWidth: tableWidth = 0 } = props;
18
- let [resizingColumn, setResizingColumn] = (0, $cPT3l$useState)(null);
19
- let columnLayout = (0, $cPT3l$useMemo)(()=>new (0, $a9e7ae544a4e41dd$export$7ff77a162970b30e)({
20
- getDefaultWidth: getDefaultWidth,
21
- getDefaultMinWidth: getDefaultMinWidth
22
- }), [
23
- getDefaultWidth,
24
- getDefaultMinWidth
25
- ]);
26
- let [controlledColumns, uncontrolledColumns] = (0, $cPT3l$useMemo)(()=>columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns), [
27
- state.collection.columns,
28
- columnLayout
29
- ]);
30
- // uncontrolled column widths
31
- let [uncontrolledWidths, setUncontrolledWidths] = (0, $cPT3l$useState)(()=>columnLayout.getInitialUncontrolledWidths(uncontrolledColumns));
32
- // Update uncontrolled widths if the columns changed.
33
- let [lastColumns, setLastColumns] = (0, $cPT3l$useState)(state.collection.columns);
34
- if (state.collection.columns !== lastColumns) {
35
- if (state.collection.columns.length !== lastColumns.length || state.collection.columns.some((c, i)=>c.key !== lastColumns[i].key)) {
36
- let newUncontrolledWidths = columnLayout.getInitialUncontrolledWidths(uncontrolledColumns);
37
- setUncontrolledWidths(newUncontrolledWidths);
38
- }
39
- setLastColumns(state.collection.columns);
40
- }
41
- // combine columns back into one map that maintains same order as the columns
42
- let colWidths = (0, $cPT3l$useMemo)(()=>columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns), [
43
- state.collection.columns,
44
- uncontrolledWidths,
45
- uncontrolledColumns,
46
- controlledColumns,
47
- columnLayout
48
- ]);
49
- let startResize = (0, $cPT3l$useCallback)((key)=>{
50
- setResizingColumn(key);
51
- }, [
52
- setResizingColumn
53
- ]);
54
- let updateResizedColumns = (0, $cPT3l$useCallback)((key, width)=>{
55
- let newSizes = columnLayout.resizeColumnWidth(state.collection, uncontrolledWidths, key, width);
56
- let map = new Map(Array.from(uncontrolledColumns).map(([key])=>[
57
- key,
58
- newSizes.get(key)
59
- ]));
60
- map.set(key, width);
61
- setUncontrolledWidths(map);
62
- return newSizes;
63
- }, [
64
- uncontrolledColumns,
65
- setUncontrolledWidths,
66
- columnLayout,
67
- state.collection,
68
- uncontrolledWidths
69
- ]);
70
- let endResize = (0, $cPT3l$useCallback)(()=>{
71
- setResizingColumn(null);
72
- }, [
73
- setResizingColumn
74
- ]);
75
- let columnWidths = (0, $cPT3l$useMemo)(()=>columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths), [
76
- tableWidth,
77
- state.collection,
78
- colWidths,
79
- columnLayout
80
- ]);
81
- return (0, $cPT3l$useMemo)(()=>({
82
- resizingColumn: resizingColumn,
83
- updateResizedColumns: updateResizedColumns,
84
- startResize: startResize,
85
- endResize: endResize,
86
- getColumnWidth: (key)=>columnLayout.getColumnWidth(key),
87
- getColumnMinWidth: (key)=>columnLayout.getColumnMinWidth(key),
88
- getColumnMaxWidth: (key)=>columnLayout.getColumnMaxWidth(key),
89
- tableState: state,
90
- columnWidths: columnWidths
91
- }), [
92
- columnLayout,
93
- columnWidths,
94
- resizingColumn,
95
- updateResizedColumns,
96
- startResize,
97
- endResize,
98
- state
99
- ]);
100
- }
101
-
102
-
103
- export {$292bc4e09cd0eb62$export$cb895dcf85db1319 as useTableColumnResizeState};
104
- //# sourceMappingURL=useTableColumnResizeState.module.js.map
@@ -1,104 +0,0 @@
1
- import {TableColumnLayout as $a9e7ae544a4e41dd$export$7ff77a162970b30e} from "./TableColumnLayout.module.js";
2
- import {useState as $cPT3l$useState, useMemo as $cPT3l$useMemo, useCallback as $cPT3l$useCallback} from "react";
3
-
4
- /*
5
- * Copyright 2022 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- function $292bc4e09cd0eb62$export$cb895dcf85db1319(props, state) {
17
- let { getDefaultWidth: getDefaultWidth, getDefaultMinWidth: getDefaultMinWidth, tableWidth: tableWidth = 0 } = props;
18
- let [resizingColumn, setResizingColumn] = (0, $cPT3l$useState)(null);
19
- let columnLayout = (0, $cPT3l$useMemo)(()=>new (0, $a9e7ae544a4e41dd$export$7ff77a162970b30e)({
20
- getDefaultWidth: getDefaultWidth,
21
- getDefaultMinWidth: getDefaultMinWidth
22
- }), [
23
- getDefaultWidth,
24
- getDefaultMinWidth
25
- ]);
26
- let [controlledColumns, uncontrolledColumns] = (0, $cPT3l$useMemo)(()=>columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns), [
27
- state.collection.columns,
28
- columnLayout
29
- ]);
30
- // uncontrolled column widths
31
- let [uncontrolledWidths, setUncontrolledWidths] = (0, $cPT3l$useState)(()=>columnLayout.getInitialUncontrolledWidths(uncontrolledColumns));
32
- // Update uncontrolled widths if the columns changed.
33
- let [lastColumns, setLastColumns] = (0, $cPT3l$useState)(state.collection.columns);
34
- if (state.collection.columns !== lastColumns) {
35
- if (state.collection.columns.length !== lastColumns.length || state.collection.columns.some((c, i)=>c.key !== lastColumns[i].key)) {
36
- let newUncontrolledWidths = columnLayout.getInitialUncontrolledWidths(uncontrolledColumns);
37
- setUncontrolledWidths(newUncontrolledWidths);
38
- }
39
- setLastColumns(state.collection.columns);
40
- }
41
- // combine columns back into one map that maintains same order as the columns
42
- let colWidths = (0, $cPT3l$useMemo)(()=>columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns), [
43
- state.collection.columns,
44
- uncontrolledWidths,
45
- uncontrolledColumns,
46
- controlledColumns,
47
- columnLayout
48
- ]);
49
- let startResize = (0, $cPT3l$useCallback)((key)=>{
50
- setResizingColumn(key);
51
- }, [
52
- setResizingColumn
53
- ]);
54
- let updateResizedColumns = (0, $cPT3l$useCallback)((key, width)=>{
55
- let newSizes = columnLayout.resizeColumnWidth(state.collection, uncontrolledWidths, key, width);
56
- let map = new Map(Array.from(uncontrolledColumns).map(([key])=>[
57
- key,
58
- newSizes.get(key)
59
- ]));
60
- map.set(key, width);
61
- setUncontrolledWidths(map);
62
- return newSizes;
63
- }, [
64
- uncontrolledColumns,
65
- setUncontrolledWidths,
66
- columnLayout,
67
- state.collection,
68
- uncontrolledWidths
69
- ]);
70
- let endResize = (0, $cPT3l$useCallback)(()=>{
71
- setResizingColumn(null);
72
- }, [
73
- setResizingColumn
74
- ]);
75
- let columnWidths = (0, $cPT3l$useMemo)(()=>columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths), [
76
- tableWidth,
77
- state.collection,
78
- colWidths,
79
- columnLayout
80
- ]);
81
- return (0, $cPT3l$useMemo)(()=>({
82
- resizingColumn: resizingColumn,
83
- updateResizedColumns: updateResizedColumns,
84
- startResize: startResize,
85
- endResize: endResize,
86
- getColumnWidth: (key)=>columnLayout.getColumnWidth(key),
87
- getColumnMinWidth: (key)=>columnLayout.getColumnMinWidth(key),
88
- getColumnMaxWidth: (key)=>columnLayout.getColumnMaxWidth(key),
89
- tableState: state,
90
- columnWidths: columnWidths
91
- }), [
92
- columnLayout,
93
- columnWidths,
94
- resizingColumn,
95
- updateResizedColumns,
96
- startResize,
97
- endResize,
98
- state
99
- ]);
100
- }
101
-
102
-
103
- export {$292bc4e09cd0eb62$export$cb895dcf85db1319 as useTableColumnResizeState};
104
- //# sourceMappingURL=useTableColumnResizeState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAmDM,SAAS,0CAA6B,KAAqC,EAAE,KAAoB;IACtG,IAAI,mBACF,eAAe,sBACf,kBAAkB,cAClB,aAAa,GACd,GAAG;IAEJ,IAAI,CAAC,gBAAgB,kBAAkB,GAAG,CAAA,GAAA,eAAO,EAAc;IAC/D,IAAI,eAAe,CAAA,GAAA,cAAM,EACvB,IAAM,IAAI,CAAA,GAAA,yCAAgB,EAAE;6BAC1B;gCACA;QACF,IACA;QAAC;QAAiB;KAAmB;IAGvC,IAAI,CAAC,mBAAmB,oBAAoB,GAAG,CAAA,GAAA,cAAM,EAAE,IACnD,aAAa,yCAAyC,CAAC,MAAM,UAAU,CAAC,OAAO,GACjF;QAAC,MAAM,UAAU,CAAC,OAAO;QAAE;KAAa;IAE1C,6BAA6B;IAC7B,IAAI,CAAC,oBAAoB,sBAAsB,GAAG,CAAA,GAAA,eAA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EtB,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IACzB,aAAa,iBAAiB,CAAC,YAAY,MAAM,UAAU,EAAE,YAC7D;QAAC;QAAY,MAAM,UAAU;QAAE;QAAW;KAAa;IAEzD,OAAO,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;4BACpB;kCACA;yBACA;uBACA;YACA,gBAAgB,CAAC,MACf,aAAa,cAAc,CAAC;YAC9B,mBAAmB,CAAC,MAClB,aAAa,iBAAiB,CAAC;YACjC,mBAAmB,CAAC,MAClB,aAAa,iBAAiB,CAAC;YACjC,YAAY;0BACZ;QACF,CAAA,GAAI;QACF;QACA;QACA;QACA;QACA;QACA;QACA;KACD;AACH","sources":["packages/@react-stately/table/src/useTableColumnResizeState.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 {GridNode} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\nimport {TableColumnLayout} from './TableColumnLayout';\nimport {TableState} from './useTableState';\nimport {useCallback, useMemo, useState} from 'react';\n\nexport interface TableColumnResizeStateProps<T> {\n /**\n * Current width of the table or table viewport that the columns\n * should be calculated against.\n */\n tableWidth: number,\n /** A function that is called to find the default width for a given column. */\n getDefaultWidth?: (node: GridNode<T>) => ColumnSize | null | undefined,\n /** A function that is called to find the default minWidth for a given column. */\n getDefaultMinWidth?: (node: GridNode<T>) => ColumnSize | null | undefined\n}\nexport interface TableColumnResizeState<T> {\n /**\n * Called to update the state that a resize event has occurred.\n * Returns the new widths for all columns based on the resized column.\n */\n updateResizedColumns: (key: Key, width: number) => Map<Key, ColumnSize>,\n /** Callback for when onColumnResize has started. */\n startResize: (key: Key) => void,\n /** Callback for when onColumnResize has ended. */\n endResize: () => void,\n /** Gets the current width for the specified column. */\n getColumnWidth: (key: Key) => number,\n /** Gets the current minWidth for the specified column. */\n getColumnMinWidth: (key: Key) => number,\n /** Gets the current maxWidth for the specified column. */\n getColumnMaxWidth: (key: Key) => number,\n /** Key of the currently resizing column. */\n resizingColumn: Key | null,\n /** A reference to the table state. */\n tableState: TableState<T>,\n /** A map of the current column widths. */\n columnWidths: Map<Key, number>\n}\n\n/**\n * Provides column width state management for a table component with column resizing support. Handles building\n * a map of column widths calculated from the table's width and any provided column width information from the collection.\n * In addition, it tracks the currently resizing column and provides callbacks for updating the widths upon resize operations.\n * @param props - Props for the table.\n * @param state - State for the table, as returned by `useTableState`.\n */\nexport function useTableColumnResizeState<T>(props: TableColumnResizeStateProps<T>, state: TableState<T>): TableColumnResizeState<T> {\n let {\n getDefaultWidth,\n getDefaultMinWidth,\n tableWidth = 0\n } = props;\n\n let [resizingColumn, setResizingColumn] = useState<Key | null>(null);\n let columnLayout = useMemo(\n () => new TableColumnLayout({\n getDefaultWidth,\n getDefaultMinWidth\n }),\n [getDefaultWidth, getDefaultMinWidth]\n );\n\n let [controlledColumns, uncontrolledColumns] = useMemo(() =>\n columnLayout.splitColumnsIntoControlledAndUncontrolled(state.collection.columns)\n , [state.collection.columns, columnLayout]);\n\n // uncontrolled column widths\n let [uncontrolledWidths, setUncontrolledWidths] = useState(() =>\n columnLayout.getInitialUncontrolledWidths(uncontrolledColumns)\n );\n\n // Update uncontrolled widths if the columns changed.\n let [lastColumns, setLastColumns] = useState(state.collection.columns);\n if (state.collection.columns !== lastColumns) {\n if (\n state.collection.columns.length !== lastColumns.length ||\n state.collection.columns.some((c, i) => c.key !== lastColumns[i].key)\n ) {\n let newUncontrolledWidths = columnLayout.getInitialUncontrolledWidths(uncontrolledColumns);\n setUncontrolledWidths(newUncontrolledWidths);\n }\n setLastColumns(state.collection.columns);\n }\n\n // combine columns back into one map that maintains same order as the columns\n let colWidths = useMemo(() =>\n columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns)\n , [state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns, columnLayout]);\n\n let startResize = useCallback((key: Key) => {\n setResizingColumn(key);\n }, [setResizingColumn]);\n\n let updateResizedColumns = useCallback((key: Key, width: number): Map<Key, ColumnSize> => {\n let newSizes = columnLayout.resizeColumnWidth(state.collection, uncontrolledWidths, key, width);\n let map = new Map(Array.from(uncontrolledColumns).map(([key]) => [key, newSizes.get(key)!]));\n map.set(key, width);\n setUncontrolledWidths(map);\n return newSizes;\n }, [uncontrolledColumns, setUncontrolledWidths, columnLayout, state.collection, uncontrolledWidths]);\n\n let endResize = useCallback(() => {\n setResizingColumn(null);\n }, [setResizingColumn]);\n\n let columnWidths = useMemo(() =>\n columnLayout.buildColumnWidths(tableWidth, state.collection, colWidths)\n , [tableWidth, state.collection, colWidths, columnLayout]);\n\n return useMemo(() => ({\n resizingColumn,\n updateResizedColumns,\n startResize,\n endResize,\n getColumnWidth: (key: Key) =>\n columnLayout.getColumnWidth(key),\n getColumnMinWidth: (key: Key) =>\n columnLayout.getColumnMinWidth(key),\n getColumnMaxWidth: (key: Key) =>\n columnLayout.getColumnMaxWidth(key),\n tableState: state,\n columnWidths\n }), [\n columnLayout,\n columnWidths,\n resizingColumn,\n updateResizedColumns,\n startResize,\n endResize,\n state\n ]);\n}\n"],"names":[],"version":3,"file":"useTableColumnResizeState.module.js.map"}
@@ -1,86 +0,0 @@
1
- var $7f5a58334d8866a5$exports = require("./TableCollection.main.js");
2
- var $hkaUn$reactstatelygrid = require("@react-stately/grid");
3
- var $hkaUn$react = require("react");
4
- var $hkaUn$reactstatelycollections = require("@react-stately/collections");
5
-
6
-
7
- function $parcel$export(e, n, v, s) {
8
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
- }
10
-
11
- $parcel$export(module.exports, "useTableState", () => $e3f7784147dde23d$export$907bcc6c48325fd6);
12
- $parcel$export(module.exports, "UNSTABLE_useFilteredTableState", () => $e3f7784147dde23d$export$31447e17397b15c2);
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
-
25
-
26
-
27
- const $e3f7784147dde23d$var$OPPOSITE_SORT_DIRECTION = {
28
- ascending: 'descending',
29
- descending: 'ascending'
30
- };
31
- function $e3f7784147dde23d$export$907bcc6c48325fd6(props) {
32
- let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = (0, $hkaUn$react.useState)(false);
33
- let { selectionMode: selectionMode = 'none', showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons } = props;
34
- let context = (0, $hkaUn$react.useMemo)(()=>({
35
- showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',
36
- showDragButtons: showDragButtons,
37
- selectionMode: selectionMode,
38
- columns: []
39
- }), [
40
- props.children,
41
- showSelectionCheckboxes,
42
- selectionMode,
43
- showDragButtons
44
- ]);
45
- let collection = (0, $hkaUn$reactstatelycollections.useCollection)(props, (0, $hkaUn$react.useCallback)((nodes)=>new (0, $7f5a58334d8866a5$exports.TableCollection)(nodes, null, context), [
46
- context
47
- ]), context);
48
- let { disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $hkaUn$reactstatelygrid.useGridState)({
49
- ...props,
50
- collection: collection,
51
- disabledBehavior: props.disabledBehavior || 'selection'
52
- });
53
- var _props_sortDescriptor;
54
- return {
55
- collection: collection,
56
- disabledKeys: disabledKeys,
57
- selectionManager: selectionManager,
58
- showSelectionCheckboxes: props.showSelectionCheckboxes || false,
59
- sortDescriptor: (_props_sortDescriptor = props.sortDescriptor) !== null && _props_sortDescriptor !== void 0 ? _props_sortDescriptor : null,
60
- isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
61
- setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
62
- sort (columnKey, direction) {
63
- var _props_sortDescriptor, _props_onSortChange;
64
- (_props_onSortChange = props.onSortChange) === null || _props_onSortChange === void 0 ? void 0 : _props_onSortChange.call(props, {
65
- column: columnKey,
66
- direction: direction !== null && direction !== void 0 ? direction : ((_props_sortDescriptor = props.sortDescriptor) === null || _props_sortDescriptor === void 0 ? void 0 : _props_sortDescriptor.column) === columnKey ? $e3f7784147dde23d$var$OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction] : 'ascending'
67
- });
68
- }
69
- };
70
- }
71
- function $e3f7784147dde23d$export$31447e17397b15c2(state, filterFn) {
72
- let collection = (0, $hkaUn$react.useMemo)(()=>filterFn ? state.collection.filter(filterFn) : state.collection, [
73
- state.collection,
74
- filterFn
75
- ]);
76
- let selectionManager = state.selectionManager.withCollection(collection);
77
- // TODO: handle focus key reset? That logic is in useGridState
78
- return {
79
- ...state,
80
- collection: collection,
81
- selectionManager: selectionManager
82
- };
83
- }
84
-
85
-
86
- //# sourceMappingURL=useTableState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiDD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BAA8B,8BAA8B,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC7E,IAAI,iBAAC,gBAAgB,iCAAQ,uBAAuB,mBAAE,eAAe,EAAC,GAAG;IAEzE,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;Y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ourcesContent":["/*\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 {GridState, useGridState} from '@react-stately/grid';\nimport {TableCollection as ITableCollection, TableBodyProps, TableHeaderProps} from '@react-types/table';\nimport {Key, Node, SelectionMode, Sortable, SortDescriptor, SortDirection} from '@react-types/shared';\nimport {MultipleSelectionState, MultipleSelectionStateProps} from '@react-stately/selection';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>,\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean,\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null,\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean,\n /** Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n setKeyboardNavigationDisabled: (val: boolean) => void\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean,\n showDragButtons: boolean,\n selectionMode: SelectionMode,\n columns: Node<T>[]\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>],\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>,\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>,\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean,\n /** Whether the row drag button should be displayed.\n * @private\n */\n showDragButtons?: boolean,\n /** @private - do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection\n * of columns and rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons} = props;\n\n let context = useMemo(() => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]);\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback((nodes) => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction: direction ?? (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n }\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(state: TableState<T>, filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined): TableState<T> {\n let collection = useMemo(() => filterFn ? state.collection.filter!(filterFn) : state.collection, [state.collection, filterFn]) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.main.js.map"}
@@ -1,80 +0,0 @@
1
- import {TableCollection as $788781baa30117fa$export$596e1b2e2cf93690} from "./TableCollection.mjs";
2
- import {useGridState as $1YSEb$useGridState} from "@react-stately/grid";
3
- import {useState as $1YSEb$useState, useMemo as $1YSEb$useMemo, useCallback as $1YSEb$useCallback} from "react";
4
- import {useCollection as $1YSEb$useCollection} from "@react-stately/collections";
5
-
6
- /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */
17
-
18
-
19
-
20
- const $4a0dd036d492cee4$var$OPPOSITE_SORT_DIRECTION = {
21
- ascending: 'descending',
22
- descending: 'ascending'
23
- };
24
- function $4a0dd036d492cee4$export$907bcc6c48325fd6(props) {
25
- let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = (0, $1YSEb$useState)(false);
26
- let { selectionMode: selectionMode = 'none', showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons } = props;
27
- let context = (0, $1YSEb$useMemo)(()=>({
28
- showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',
29
- showDragButtons: showDragButtons,
30
- selectionMode: selectionMode,
31
- columns: []
32
- }), [
33
- props.children,
34
- showSelectionCheckboxes,
35
- selectionMode,
36
- showDragButtons
37
- ]);
38
- let collection = (0, $1YSEb$useCollection)(props, (0, $1YSEb$useCallback)((nodes)=>new (0, $788781baa30117fa$export$596e1b2e2cf93690)(nodes, null, context), [
39
- context
40
- ]), context);
41
- let { disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $1YSEb$useGridState)({
42
- ...props,
43
- collection: collection,
44
- disabledBehavior: props.disabledBehavior || 'selection'
45
- });
46
- var _props_sortDescriptor;
47
- return {
48
- collection: collection,
49
- disabledKeys: disabledKeys,
50
- selectionManager: selectionManager,
51
- showSelectionCheckboxes: props.showSelectionCheckboxes || false,
52
- sortDescriptor: (_props_sortDescriptor = props.sortDescriptor) !== null && _props_sortDescriptor !== void 0 ? _props_sortDescriptor : null,
53
- isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
54
- setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
55
- sort (columnKey, direction) {
56
- var _props_sortDescriptor, _props_onSortChange;
57
- (_props_onSortChange = props.onSortChange) === null || _props_onSortChange === void 0 ? void 0 : _props_onSortChange.call(props, {
58
- column: columnKey,
59
- direction: direction !== null && direction !== void 0 ? direction : ((_props_sortDescriptor = props.sortDescriptor) === null || _props_sortDescriptor === void 0 ? void 0 : _props_sortDescriptor.column) === columnKey ? $4a0dd036d492cee4$var$OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction] : 'ascending'
60
- });
61
- }
62
- };
63
- }
64
- function $4a0dd036d492cee4$export$31447e17397b15c2(state, filterFn) {
65
- let collection = (0, $1YSEb$useMemo)(()=>filterFn ? state.collection.filter(filterFn) : state.collection, [
66
- state.collection,
67
- filterFn
68
- ]);
69
- let selectionManager = state.selectionManager.withCollection(collection);
70
- // TODO: handle focus key reset? That logic is in useGridState
71
- return {
72
- ...state,
73
- collection: collection,
74
- selectionManager: selectionManager
75
- };
76
- }
77
-
78
-
79
- export {$4a0dd036d492cee4$export$907bcc6c48325fd6 as useTableState, $4a0dd036d492cee4$export$31447e17397b15c2 as UNSTABLE_useFilteredTableState};
80
- //# sourceMappingURL=useTableState.module.js.map
@@ -1,80 +0,0 @@
1
- import {TableCollection as $788781baa30117fa$export$596e1b2e2cf93690} from "./TableCollection.module.js";
2
- import {useGridState as $1YSEb$useGridState} from "@react-stately/grid";
3
- import {useState as $1YSEb$useState, useMemo as $1YSEb$useMemo, useCallback as $1YSEb$useCallback} from "react";
4
- import {useCollection as $1YSEb$useCollection} from "@react-stately/collections";
5
-
6
- /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */
17
-
18
-
19
-
20
- const $4a0dd036d492cee4$var$OPPOSITE_SORT_DIRECTION = {
21
- ascending: 'descending',
22
- descending: 'ascending'
23
- };
24
- function $4a0dd036d492cee4$export$907bcc6c48325fd6(props) {
25
- let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = (0, $1YSEb$useState)(false);
26
- let { selectionMode: selectionMode = 'none', showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons } = props;
27
- let context = (0, $1YSEb$useMemo)(()=>({
28
- showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',
29
- showDragButtons: showDragButtons,
30
- selectionMode: selectionMode,
31
- columns: []
32
- }), [
33
- props.children,
34
- showSelectionCheckboxes,
35
- selectionMode,
36
- showDragButtons
37
- ]);
38
- let collection = (0, $1YSEb$useCollection)(props, (0, $1YSEb$useCallback)((nodes)=>new (0, $788781baa30117fa$export$596e1b2e2cf93690)(nodes, null, context), [
39
- context
40
- ]), context);
41
- let { disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $1YSEb$useGridState)({
42
- ...props,
43
- collection: collection,
44
- disabledBehavior: props.disabledBehavior || 'selection'
45
- });
46
- var _props_sortDescriptor;
47
- return {
48
- collection: collection,
49
- disabledKeys: disabledKeys,
50
- selectionManager: selectionManager,
51
- showSelectionCheckboxes: props.showSelectionCheckboxes || false,
52
- sortDescriptor: (_props_sortDescriptor = props.sortDescriptor) !== null && _props_sortDescriptor !== void 0 ? _props_sortDescriptor : null,
53
- isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
54
- setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
55
- sort (columnKey, direction) {
56
- var _props_sortDescriptor, _props_onSortChange;
57
- (_props_onSortChange = props.onSortChange) === null || _props_onSortChange === void 0 ? void 0 : _props_onSortChange.call(props, {
58
- column: columnKey,
59
- direction: direction !== null && direction !== void 0 ? direction : ((_props_sortDescriptor = props.sortDescriptor) === null || _props_sortDescriptor === void 0 ? void 0 : _props_sortDescriptor.column) === columnKey ? $4a0dd036d492cee4$var$OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction] : 'ascending'
60
- });
61
- }
62
- };
63
- }
64
- function $4a0dd036d492cee4$export$31447e17397b15c2(state, filterFn) {
65
- let collection = (0, $1YSEb$useMemo)(()=>filterFn ? state.collection.filter(filterFn) : state.collection, [
66
- state.collection,
67
- filterFn
68
- ]);
69
- let selectionManager = state.selectionManager.withCollection(collection);
70
- // TODO: handle focus key reset? That logic is in useGridState
71
- return {
72
- ...state,
73
- collection: collection,
74
- selectionManager: selectionManager
75
- };
76
- }
77
-
78
-
79
- export {$4a0dd036d492cee4$export$907bcc6c48325fd6 as useTableState, $4a0dd036d492cee4$export$31447e17397b15c2 as UNSTABLE_useFilteredTableState};
80
- //# sourceMappingURL=useTableState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiDD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cAAM,EAAE,IAAM,WAAW,MAAM,UAAU,CAAC,MAAM,CAAE,YAAY,MAAM,UAAU,EAAE;QAAC,MAAM,UAAU;QAAE;KAAS;IAC7H,IAAI,mBAAmB,MAAM,gBAAgB,CAAC,cAAc,CAAC;IAC7D,8DAA8D;IAE9D,OAAO;QACL,GAAG,KAAK;oBACR;0BACA;IACF;AACF","sources":["packages/@react-stately/table/src/useTableState.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 {GridState, useGridState} from '@react-stately/grid';\nimport {TableCollection as ITableCollection, TableBodyProps, TableHeaderProps} from '@react-types/table';\nimport {Key, Node, SelectionMode, Sortable, SortDescriptor, SortDirection} from '@react-types/shared';\nimport {MultipleSelectionState, MultipleSelectionStateProps} from '@react-stately/selection';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>,\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean,\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null,\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean,\n /** Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n setKeyboardNavigationDisabled: (val: boolean) => void\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean,\n showDragButtons: boolean,\n selectionMode: SelectionMode,\n columns: Node<T>[]\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>],\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>,\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>,\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean,\n /** Whether the row drag button should be displayed.\n * @private\n */\n showDragButtons?: boolean,\n /** @private - do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection\n * of columns and rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons} = props;\n\n let context = useMemo(() => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]);\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback((nodes) => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction: direction ?? (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n }\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(state: TableState<T>, filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined): TableState<T> {\n let collection = useMemo(() => filterFn ? state.collection.filter!(filterFn) : state.collection, [state.collection, filterFn]) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.module.js.map"}