@react-stately/table 3.11.7-nightly.4555 → 3.11.7-nightly.4560
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Cell.main.js +38 -0
- package/dist/Cell.main.js.map +1 -0
- package/dist/Cell.mjs +33 -0
- package/dist/Cell.module.js +33 -0
- package/dist/Cell.module.js.map +1 -0
- package/dist/Column.main.js +75 -0
- package/dist/Column.main.js.map +1 -0
- package/dist/Column.mjs +66 -0
- package/dist/Column.module.js +66 -0
- package/dist/Column.module.js.map +1 -0
- package/dist/Row.main.js +97 -0
- package/dist/Row.main.js.map +1 -0
- package/dist/Row.mjs +88 -0
- package/dist/Row.module.js +88 -0
- package/dist/Row.module.js.map +1 -0
- package/dist/TableBody.main.js +61 -0
- package/dist/TableBody.main.js.map +1 -0
- package/dist/TableBody.mjs +52 -0
- package/dist/TableBody.module.js +52 -0
- package/dist/TableBody.module.js.map +1 -0
- package/dist/TableCollection.main.js +284 -0
- package/dist/TableCollection.main.js.map +1 -0
- package/dist/TableCollection.mjs +278 -0
- package/dist/TableCollection.module.js +278 -0
- package/dist/TableCollection.module.js.map +1 -0
- package/dist/TableColumnLayout.main.js +162 -0
- package/dist/TableColumnLayout.main.js.map +1 -0
- package/dist/TableColumnLayout.mjs +157 -0
- package/dist/TableColumnLayout.module.js +157 -0
- package/dist/TableColumnLayout.module.js.map +1 -0
- package/dist/TableHeader.main.js +56 -0
- package/dist/TableHeader.main.js.map +1 -0
- package/dist/TableHeader.mjs +47 -0
- package/dist/TableHeader.module.js +47 -0
- package/dist/TableHeader.module.js.map +1 -0
- package/dist/TableUtils.main.js +184 -0
- package/dist/TableUtils.main.js.map +1 -0
- package/dist/TableUtils.mjs +175 -0
- package/dist/TableUtils.module.js +175 -0
- package/dist/TableUtils.module.js.map +1 -0
- package/dist/import.mjs +11 -1216
- package/dist/main.js +21 -1230
- package/dist/main.js.map +1 -1
- package/dist/module.js +11 -1216
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/useTableColumnResizeState.main.js +113 -0
- package/dist/useTableColumnResizeState.main.js.map +1 -0
- package/dist/useTableColumnResizeState.mjs +108 -0
- package/dist/useTableColumnResizeState.module.js +108 -0
- package/dist/useTableColumnResizeState.module.js.map +1 -0
- package/dist/useTableState.main.js +71 -0
- package/dist/useTableState.main.js.map +1 -0
- package/dist/useTableState.mjs +66 -0
- package/dist/useTableState.module.js +66 -0
- package/dist/useTableState.module.js.map +1 -0
- package/dist/useTreeGridState.main.js +207 -0
- package/dist/useTreeGridState.main.js.map +1 -0
- package/dist/useTreeGridState.mjs +202 -0
- package/dist/useTreeGridState.module.js +202 -0
- package/dist/useTreeGridState.module.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const $e3f7784147dde23d$var$OPPOSITE_SORT_DIRECTION = {
|
|
27
|
+
ascending: "descending",
|
|
28
|
+
descending: "ascending"
|
|
29
|
+
};
|
|
30
|
+
function $e3f7784147dde23d$export$907bcc6c48325fd6(props) {
|
|
31
|
+
let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = (0, $hkaUn$react.useState)(false);
|
|
32
|
+
let { selectionMode: selectionMode = "none", showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons } = props;
|
|
33
|
+
let context = (0, $hkaUn$react.useMemo)(()=>({
|
|
34
|
+
showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
|
|
35
|
+
showDragButtons: showDragButtons,
|
|
36
|
+
selectionMode: selectionMode,
|
|
37
|
+
columns: []
|
|
38
|
+
}), [
|
|
39
|
+
props.children,
|
|
40
|
+
showSelectionCheckboxes,
|
|
41
|
+
selectionMode,
|
|
42
|
+
showDragButtons
|
|
43
|
+
]);
|
|
44
|
+
let collection = (0, $hkaUn$reactstatelycollections.useCollection)(props, (0, $hkaUn$react.useCallback)((nodes)=>new (0, $7f5a58334d8866a5$exports.TableCollection)(nodes, null, context), [
|
|
45
|
+
context
|
|
46
|
+
]), context);
|
|
47
|
+
let { disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $hkaUn$reactstatelygrid.useGridState)({
|
|
48
|
+
...props,
|
|
49
|
+
collection: collection,
|
|
50
|
+
disabledBehavior: props.disabledBehavior || "selection"
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
collection: collection,
|
|
54
|
+
disabledKeys: disabledKeys,
|
|
55
|
+
selectionManager: selectionManager,
|
|
56
|
+
showSelectionCheckboxes: props.showSelectionCheckboxes || false,
|
|
57
|
+
sortDescriptor: props.sortDescriptor,
|
|
58
|
+
isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
|
|
59
|
+
setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
|
|
60
|
+
sort (columnKey, direction) {
|
|
61
|
+
var _props_sortDescriptor;
|
|
62
|
+
props.onSortChange({
|
|
63
|
+
column: columnKey,
|
|
64
|
+
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"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=useTableState.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA+CD,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;YAC3B,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QAEb,CAAA,GAAI;QAAC,MAAM,QAAQ;QAAE;QAAyB;QAAe;KAAgB;IAE7E,IAAI,aAAa,CAAA,GAAA,4CAAY,EAC3B,OACA,CAAA,GAAA,wBAAU,EAAE,CAAC,QAAU,IAAI,CAAA,GAAA,yCAAc,EAAE,OAAO,MAAM,UAAU;QAAC;KAAQ,GAC3E;IAEF,IAAI,gBAAC,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,oCAAW,EAAE;QAClD,GAAG,KAAK;oBACR;QACA,kBAAkB,MAAM,gBAAgB,IAAI;IAC9C;IAEA,OAAO;oBACL;sBACA;0BACA;QACA,yBAAyB,MAAM,uBAAuB,IAAI;QAC1D,gBAAgB,MAAM,cAAc;QACpC,8BAA8B,WAAW,IAAI,KAAK,KAAK;uCACvD;QACA,MAAK,SAAc,EAAE,SAAsC;gBAG9B;YAF3B,MAAM,YAAY,CAAC;gBACjB,QAAQ;gBACR,WAAW,sBAAA,uBAAA,YAAc,EAAA,wBAAA,MAAM,cAAc,cAApB,4CAAA,sBAAsB,MAAM,MAAK,YACtD,6CAAuB,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,GACvD;YACN;QACF;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 {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,\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}\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,\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"],"names":[],"version":3,"file":"useTableState.main.js.map"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
return {
|
|
47
|
+
collection: collection,
|
|
48
|
+
disabledKeys: disabledKeys,
|
|
49
|
+
selectionManager: selectionManager,
|
|
50
|
+
showSelectionCheckboxes: props.showSelectionCheckboxes || false,
|
|
51
|
+
sortDescriptor: props.sortDescriptor,
|
|
52
|
+
isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
|
|
53
|
+
setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
|
|
54
|
+
sort (columnKey, direction) {
|
|
55
|
+
var _props_sortDescriptor;
|
|
56
|
+
props.onSortChange({
|
|
57
|
+
column: columnKey,
|
|
58
|
+
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"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
export {$4a0dd036d492cee4$export$907bcc6c48325fd6 as useTableState};
|
|
66
|
+
//# sourceMappingURL=useTableState.mjs.map
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
return {
|
|
47
|
+
collection: collection,
|
|
48
|
+
disabledKeys: disabledKeys,
|
|
49
|
+
selectionManager: selectionManager,
|
|
50
|
+
showSelectionCheckboxes: props.showSelectionCheckboxes || false,
|
|
51
|
+
sortDescriptor: props.sortDescriptor,
|
|
52
|
+
isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
|
|
53
|
+
setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
|
|
54
|
+
sort (columnKey, direction) {
|
|
55
|
+
var _props_sortDescriptor;
|
|
56
|
+
props.onSortChange({
|
|
57
|
+
column: columnKey,
|
|
58
|
+
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"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
export {$4a0dd036d492cee4$export$907bcc6c48325fd6 as useTableState};
|
|
66
|
+
//# sourceMappingURL=useTableState.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA+CD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BAA8B,8BAA8B,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7E,IAAI,iBAAC,gBAAgB,iCAAQ,uBAAuB,mBAAE,eAAe,EAAC,GAAG;IAEzE,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;YAC3B,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QAEb,CAAA,GAAI;QAAC,MAAM,QAAQ;QAAE;QAAyB;QAAe;KAAgB;IAE7E,IAAI,aAAa,CAAA,GAAA,oBAAY,EAC3B,OACA,CAAA,GAAA,kBAAU,EAAE,CAAC,QAAU,IAAI,CAAA,GAAA,yCAAc,EAAE,OAAO,MAAM,UAAU;QAAC;KAAQ,GAC3E;IAEF,IAAI,gBAAC,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE;QAClD,GAAG,KAAK;oBACR;QACA,kBAAkB,MAAM,gBAAgB,IAAI;IAC9C;IAEA,OAAO;oBACL;sBACA;0BACA;QACA,yBAAyB,MAAM,uBAAuB,IAAI;QAC1D,gBAAgB,MAAM,cAAc;QACpC,8BAA8B,WAAW,IAAI,KAAK,KAAK;uCACvD;QACA,MAAK,SAAc,EAAE,SAAsC;gBAG9B;YAF3B,MAAM,YAAY,CAAC;gBACjB,QAAQ;gBACR,WAAW,sBAAA,uBAAA,YAAc,EAAA,wBAAA,MAAM,cAAc,cAApB,4CAAA,sBAAsB,MAAM,MAAK,YACtD,6CAAuB,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,GACvD;YACN;QACF;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 {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,\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}\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,\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"],"names":[],"version":3,"file":"useTableState.module.js.map"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
var $7f5a58334d8866a5$exports = require("./TableCollection.main.js");
|
|
2
|
+
var $e3f7784147dde23d$exports = require("./useTableState.main.js");
|
|
3
|
+
var $5Qo8l$reactstatelycollections = require("@react-stately/collections");
|
|
4
|
+
var $5Qo8l$react = require("react");
|
|
5
|
+
var $5Qo8l$reactstatelyflags = require("@react-stately/flags");
|
|
6
|
+
var $5Qo8l$reactstatelyutils = require("@react-stately/utils");
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $parcel$export(e, n, v, s) {
|
|
10
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
$parcel$export(module.exports, "UNSTABLE_useTreeGridState", () => $ed4e0b68b470dcfd$export$34dfa8a1622185a4);
|
|
14
|
+
/*
|
|
15
|
+
* Copyright 2023 Adobe. All rights reserved.
|
|
16
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
18
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
21
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
22
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
23
|
+
* governing permissions and limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function $ed4e0b68b470dcfd$export$34dfa8a1622185a4(props) {
|
|
31
|
+
let { selectionMode: selectionMode = "none", showSelectionCheckboxes: showSelectionCheckboxes, showDragButtons: showDragButtons, UNSTABLE_expandedKeys: propExpandedKeys, UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys, UNSTABLE_onExpandedChange: UNSTABLE_onExpandedChange, children: children } = props;
|
|
32
|
+
if (!(0, $5Qo8l$reactstatelyflags.tableNestedRows)()) throw new Error("Feature flag for table nested rows must be enabled to use useTreeGridState.");
|
|
33
|
+
let [expandedKeys, setExpandedKeys] = (0, $5Qo8l$reactstatelyutils.useControlledState)(propExpandedKeys ? $ed4e0b68b470dcfd$var$convertExpanded(propExpandedKeys) : undefined, propDefaultExpandedKeys ? $ed4e0b68b470dcfd$var$convertExpanded(propDefaultExpandedKeys) : new Set(), UNSTABLE_onExpandedChange);
|
|
34
|
+
let context = (0, $5Qo8l$react.useMemo)(()=>({
|
|
35
|
+
showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== "none",
|
|
36
|
+
showDragButtons: showDragButtons,
|
|
37
|
+
selectionMode: selectionMode,
|
|
38
|
+
columns: []
|
|
39
|
+
}), [
|
|
40
|
+
children,
|
|
41
|
+
showSelectionCheckboxes,
|
|
42
|
+
selectionMode,
|
|
43
|
+
showDragButtons
|
|
44
|
+
]);
|
|
45
|
+
let builder = (0, $5Qo8l$react.useMemo)(()=>new (0, $5Qo8l$reactstatelycollections.CollectionBuilder)(), []);
|
|
46
|
+
let nodes = (0, $5Qo8l$react.useMemo)(()=>builder.build({
|
|
47
|
+
children: children
|
|
48
|
+
}, context), [
|
|
49
|
+
builder,
|
|
50
|
+
children,
|
|
51
|
+
context
|
|
52
|
+
]);
|
|
53
|
+
let treeGridCollection = (0, $5Qo8l$react.useMemo)(()=>{
|
|
54
|
+
return $ed4e0b68b470dcfd$var$generateTreeGridCollection(nodes, {
|
|
55
|
+
showSelectionCheckboxes: showSelectionCheckboxes,
|
|
56
|
+
showDragButtons: showDragButtons,
|
|
57
|
+
expandedKeys: expandedKeys
|
|
58
|
+
});
|
|
59
|
+
}, [
|
|
60
|
+
nodes,
|
|
61
|
+
showSelectionCheckboxes,
|
|
62
|
+
showDragButtons,
|
|
63
|
+
expandedKeys
|
|
64
|
+
]);
|
|
65
|
+
let onToggle = (key)=>{
|
|
66
|
+
setExpandedKeys($ed4e0b68b470dcfd$var$toggleKey(expandedKeys, key, treeGridCollection));
|
|
67
|
+
};
|
|
68
|
+
let collection = (0, $5Qo8l$react.useMemo)(()=>{
|
|
69
|
+
return new (0, $7f5a58334d8866a5$exports.TableCollection)(treeGridCollection.tableNodes, null, context);
|
|
70
|
+
}, [
|
|
71
|
+
context,
|
|
72
|
+
treeGridCollection.tableNodes
|
|
73
|
+
]);
|
|
74
|
+
let tableState = (0, $e3f7784147dde23d$exports.useTableState)({
|
|
75
|
+
...props,
|
|
76
|
+
collection: collection
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
...tableState,
|
|
80
|
+
keyMap: treeGridCollection.keyMap,
|
|
81
|
+
userColumnCount: treeGridCollection.userColumnCount,
|
|
82
|
+
expandedKeys: expandedKeys,
|
|
83
|
+
toggleKey: onToggle
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function $ed4e0b68b470dcfd$var$toggleKey(currentExpandedKeys, key, collection) {
|
|
87
|
+
let updatedExpandedKeys;
|
|
88
|
+
if (currentExpandedKeys === "all") {
|
|
89
|
+
updatedExpandedKeys = new Set(collection.flattenedRows.filter((row)=>row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map((row)=>row.key));
|
|
90
|
+
updatedExpandedKeys.delete(key);
|
|
91
|
+
} else {
|
|
92
|
+
updatedExpandedKeys = new Set(currentExpandedKeys);
|
|
93
|
+
if (updatedExpandedKeys.has(key)) updatedExpandedKeys.delete(key);
|
|
94
|
+
else updatedExpandedKeys.add(key);
|
|
95
|
+
}
|
|
96
|
+
return updatedExpandedKeys;
|
|
97
|
+
}
|
|
98
|
+
function $ed4e0b68b470dcfd$var$convertExpanded(expanded) {
|
|
99
|
+
if (!expanded) return new Set();
|
|
100
|
+
return expanded === "all" ? "all" : new Set(expanded);
|
|
101
|
+
}
|
|
102
|
+
function $ed4e0b68b470dcfd$var$generateTreeGridCollection(nodes, opts) {
|
|
103
|
+
let { expandedKeys: expandedKeys = new Set() } = opts;
|
|
104
|
+
let body;
|
|
105
|
+
let flattenedRows = [];
|
|
106
|
+
let columnCount = 0;
|
|
107
|
+
let userColumnCount = 0;
|
|
108
|
+
let originalColumns = [];
|
|
109
|
+
let keyMap = new Map();
|
|
110
|
+
if (opts === null || opts === void 0 ? void 0 : opts.showSelectionCheckboxes) columnCount++;
|
|
111
|
+
if (opts === null || opts === void 0 ? void 0 : opts.showDragButtons) columnCount++;
|
|
112
|
+
let topLevelRows = [];
|
|
113
|
+
let visit = (node)=>{
|
|
114
|
+
switch(node.type){
|
|
115
|
+
case "body":
|
|
116
|
+
body = node;
|
|
117
|
+
keyMap.set(body.key, body);
|
|
118
|
+
break;
|
|
119
|
+
case "column":
|
|
120
|
+
if (!node.hasChildNodes) userColumnCount++;
|
|
121
|
+
break;
|
|
122
|
+
case "item":
|
|
123
|
+
topLevelRows.push(node);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
for (let child of node.childNodes)visit(child);
|
|
127
|
+
};
|
|
128
|
+
for (let node of nodes){
|
|
129
|
+
if (node.type === "column") originalColumns.push(node);
|
|
130
|
+
visit(node);
|
|
131
|
+
}
|
|
132
|
+
columnCount += userColumnCount;
|
|
133
|
+
// Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume
|
|
134
|
+
let globalRowCount = 0;
|
|
135
|
+
let visitNode = (node, i)=>{
|
|
136
|
+
// Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided
|
|
137
|
+
// to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure
|
|
138
|
+
// values automatically calculated via CollectionBuilder
|
|
139
|
+
if (node.type === "item") {
|
|
140
|
+
let childNodes = [];
|
|
141
|
+
for (let child of node.childNodes)if (child.type === "cell") {
|
|
142
|
+
let cellClone = {
|
|
143
|
+
...child
|
|
144
|
+
};
|
|
145
|
+
if (cellClone.index + 1 === columnCount) cellClone.nextKey = null;
|
|
146
|
+
childNodes.push({
|
|
147
|
+
...cellClone
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
let clone = {
|
|
151
|
+
...node,
|
|
152
|
+
childNodes: childNodes,
|
|
153
|
+
parentKey: body.key,
|
|
154
|
+
level: 1,
|
|
155
|
+
index: globalRowCount++
|
|
156
|
+
};
|
|
157
|
+
flattenedRows.push(clone);
|
|
158
|
+
}
|
|
159
|
+
let newProps = {};
|
|
160
|
+
// Assign indexOfType to cells and rows for aria-posinset
|
|
161
|
+
if (node.type !== "placeholder" && node.type !== "column") newProps["indexOfType"] = i;
|
|
162
|
+
// Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes
|
|
163
|
+
// via .childNodes returns the same object as the one found via keyMap look up
|
|
164
|
+
Object.assign(node, newProps);
|
|
165
|
+
keyMap.set(node.key, node);
|
|
166
|
+
let lastNode;
|
|
167
|
+
let rowIndex = 0;
|
|
168
|
+
for (let child of node.childNodes)if (!(child.type === "item" && expandedKeys !== "all" && !expandedKeys.has(node.key))) {
|
|
169
|
+
if (child.parentKey == null) // if child is a cell/expanded row/column and the parent key isn't already established by the collection, match child node to parent row
|
|
170
|
+
child.parentKey = node.key;
|
|
171
|
+
if (lastNode) {
|
|
172
|
+
lastNode.nextKey = child.key;
|
|
173
|
+
child.prevKey = lastNode.key;
|
|
174
|
+
} else child.prevKey = null;
|
|
175
|
+
if (child.type === "item") visitNode(child, rowIndex++);
|
|
176
|
+
else // We enforce that the cells come before rows so can just reuse cell index
|
|
177
|
+
visitNode(child, child.index);
|
|
178
|
+
lastNode = child;
|
|
179
|
+
}
|
|
180
|
+
if (lastNode) lastNode.nextKey = null;
|
|
181
|
+
};
|
|
182
|
+
let last;
|
|
183
|
+
topLevelRows.forEach((node, i)=>{
|
|
184
|
+
visitNode(node, i);
|
|
185
|
+
if (last) {
|
|
186
|
+
last.nextKey = node.key;
|
|
187
|
+
node.prevKey = last.key;
|
|
188
|
+
} else node.prevKey = null;
|
|
189
|
+
last = node;
|
|
190
|
+
});
|
|
191
|
+
if (last) last.nextKey = null;
|
|
192
|
+
return {
|
|
193
|
+
keyMap: keyMap,
|
|
194
|
+
userColumnCount: userColumnCount,
|
|
195
|
+
flattenedRows: flattenedRows,
|
|
196
|
+
tableNodes: [
|
|
197
|
+
...originalColumns,
|
|
198
|
+
{
|
|
199
|
+
...body,
|
|
200
|
+
childNodes: flattenedRows
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
//# sourceMappingURL=useTreeGridState.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","sources":["packages/@react-stately/table/src/useTreeGridState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {CollectionBuilder} from '@react-stately/collections';\nimport {GridNode} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\nimport {ReactElement, useMemo} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {tableNestedRows} from '@react-stately/flags';\nimport {TableState, TableStateProps, useTableState} from './useTableState';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeGridState<T> extends TableState<T> {\n /** A set of keys for items that are expanded. */\n expandedKeys: 'all' | Set<Key>,\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void,\n /** The key map containing nodes representing the collection's tree grid structure. */\n keyMap: Map<Key, GridNode<T>>,\n /** The number of leaf columns provided by the user. */\n userColumnCount: number\n}\n\nexport interface TreeGridStateProps<T> extends Omit<TableStateProps<T>, 'collection'> {\n /** The currently expanded keys in the collection (controlled). */\n UNSTABLE_expandedKeys?: 'all' | Iterable<Key>,\n /** The initial expanded keys in the collection (uncontrolled). */\n UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>,\n /** Handler that is called when items are expanded or collapsed. */\n UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any\n}\n\n/**\n * Provides state management for a tree grid component. Handles building a collection\n * of columns and rows from props. In addition, it tracks and manages expanded rows, row selection, and sort order changes.\n */\nexport function UNSTABLE_useTreeGridState<T extends object>(props: TreeGridStateProps<T>): TreeGridState<T> {\n let {\n selectionMode = 'none',\n showSelectionCheckboxes,\n showDragButtons,\n UNSTABLE_expandedKeys: propExpandedKeys,\n UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys,\n UNSTABLE_onExpandedChange,\n children\n } = props;\n\n if (!tableNestedRows()) {\n throw new Error('Feature flag for table nested rows must be enabled to use useTreeGridState.');\n }\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n propExpandedKeys ? convertExpanded(propExpandedKeys) : undefined,\n propDefaultExpandedKeys ? convertExpanded(propDefaultExpandedKeys) : new Set(),\n UNSTABLE_onExpandedChange\n );\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 }), [children, showSelectionCheckboxes, selectionMode, showDragButtons]);\n\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let nodes = useMemo(() => builder.build({children: children as ReactElement[]}, context), [builder, children, context]);\n let treeGridCollection = useMemo(() => {\n return generateTreeGridCollection<T>(nodes, {showSelectionCheckboxes, showDragButtons, expandedKeys});\n }, [nodes, showSelectionCheckboxes, showDragButtons, expandedKeys]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key, treeGridCollection));\n };\n\n let collection = useMemo(() => {\n return new TableCollection(treeGridCollection.tableNodes, null, context);\n }, [context, treeGridCollection.tableNodes]);\n\n let tableState = useTableState({...props, collection});\n return {\n ...tableState,\n keyMap: treeGridCollection.keyMap,\n userColumnCount: treeGridCollection.userColumnCount,\n expandedKeys,\n toggleKey: onToggle\n };\n}\n\nfunction toggleKey<T>(currentExpandedKeys: 'all' | Set<Key>, key: Key, collection: TreeGridCollection<T>): Set<Key> {\n let updatedExpandedKeys: Set<Key>;\n if (currentExpandedKeys === 'all') {\n updatedExpandedKeys = new Set(collection.flattenedRows.filter(row => row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map(row => row.key));\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys = new Set(currentExpandedKeys);\n if (updatedExpandedKeys.has(key)) {\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys.add(key);\n }\n }\n\n return updatedExpandedKeys;\n}\n\nfunction convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {\n if (!expanded) {\n return new Set<Key>();\n }\n\n return expanded === 'all'\n ? 'all'\n : new Set(expanded);\n}\n\ninterface TreeGridCollectionOptions {\n showSelectionCheckboxes?: boolean,\n showDragButtons?: boolean,\n expandedKeys: 'all' | Set<Key>\n}\n\ninterface TreeGridCollection<T> {\n keyMap: Map<Key, GridNode<T>>,\n tableNodes: GridNode<T>[],\n flattenedRows: GridNode<T>[],\n userColumnCount: number\n}\nfunction generateTreeGridCollection<T>(nodes, opts: TreeGridCollectionOptions): TreeGridCollection<T> {\n let {\n expandedKeys = new Set()\n } = opts;\n\n let body: GridNode<T>;\n let flattenedRows = [];\n let columnCount = 0;\n let userColumnCount = 0;\n let originalColumns = [];\n let keyMap = new Map();\n\n if (opts?.showSelectionCheckboxes) {\n columnCount++;\n }\n\n if (opts?.showDragButtons) {\n columnCount++;\n }\n\n let topLevelRows = [];\n let visit = (node: GridNode<T>) => {\n switch (node.type) {\n case 'body':\n body = node;\n keyMap.set(body.key, body);\n break;\n case 'column':\n if (!node.hasChildNodes) {\n userColumnCount++;\n }\n break;\n case 'item':\n topLevelRows.push(node);\n return;\n }\n\n for (let child of node.childNodes) {\n visit(child);\n }\n };\n\n for (let node of nodes) {\n if (node.type === 'column') {\n originalColumns.push(node);\n }\n visit(node);\n }\n columnCount += userColumnCount;\n\n // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume\n let globalRowCount = 0;\n let visitNode = (node: GridNode<T>, i?: number) => {\n // Clone row node and its children so modifications to the node for treegrid specific values aren't applied on the nodes provided\n // to TableCollection. Index, level, and parent keys are all changed to reflect a flattened row structure rather than the treegrid structure\n // values automatically calculated via CollectionBuilder\n if (node.type === 'item') {\n let childNodes = [];\n for (let child of node.childNodes) {\n if (child.type === 'cell') {\n let cellClone = {...child};\n if (cellClone.index + 1 === columnCount) {\n cellClone.nextKey = null;\n }\n childNodes.push({...cellClone});\n }\n }\n let clone = {...node, childNodes: childNodes, parentKey: body.key, level: 1, index: globalRowCount++};\n flattenedRows.push(clone);\n }\n\n let newProps = {};\n\n // Assign indexOfType to cells and rows for aria-posinset\n if (node.type !== 'placeholder' && node.type !== 'column') {\n newProps['indexOfType'] = i;\n }\n\n // Use Object.assign instead of spread to preserve object reference for keyMap. Also ensures retrieving nodes\n // via .childNodes returns the same object as the one found via keyMap look up\n Object.assign(node, newProps);\n keyMap.set(node.key, node);\n\n let lastNode: GridNode<T>;\n let rowIndex = 0;\n for (let child of node.childNodes) {\n if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {\n if (child.parentKey == null) {\n // if child is a cell/expanded row/column and the parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n\n if (lastNode) {\n lastNode.nextKey = child.key;\n child.prevKey = lastNode.key;\n } else {\n child.prevKey = null;\n }\n\n if (child.type === 'item') {\n visitNode(child, rowIndex++);\n } else {\n // We enforce that the cells come before rows so can just reuse cell index\n visitNode(child, child.index);\n }\n\n lastNode = child;\n }\n }\n\n if (lastNode) {\n lastNode.nextKey = null;\n }\n };\n\n let last: GridNode<T>;\n topLevelRows.forEach((node: GridNode<T>, i) => {\n visitNode(node as GridNode<T>, i);\n\n if (last) {\n last.nextKey = node.key;\n node.prevKey = last.key;\n } else {\n node.prevKey = null;\n }\n\n last = node;\n });\n\n if (last) {\n last.nextKey = null;\n }\n\n return {\n keyMap,\n userColumnCount,\n flattenedRows,\n tableNodes: [...originalColumns, {...body, childNodes: flattenedRows}]\n };\n}\n"],"names":[],"version":3,"file":"useTreeGridState.main.js.map"}
|