@react-stately/table 3.12.3-nightly.5042 → 3.13.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.
- package/dist/Cell.main.js.map +1 -1
- package/dist/Cell.module.js.map +1 -1
- package/dist/Column.main.js +1 -1
- package/dist/Column.main.js.map +1 -1
- package/dist/Column.mjs +1 -1
- package/dist/Column.module.js +1 -1
- package/dist/Column.module.js.map +1 -1
- package/dist/Row.main.js.map +1 -1
- package/dist/Row.module.js.map +1 -1
- package/dist/TableBody.main.js.map +1 -1
- package/dist/TableBody.module.js.map +1 -1
- package/dist/TableCollection.main.js +33 -17
- package/dist/TableCollection.main.js.map +1 -1
- package/dist/TableCollection.mjs +33 -17
- package/dist/TableCollection.module.js +33 -17
- package/dist/TableCollection.module.js.map +1 -1
- package/dist/TableColumnLayout.main.js +2 -2
- package/dist/TableColumnLayout.main.js.map +1 -1
- package/dist/TableColumnLayout.mjs +2 -2
- package/dist/TableColumnLayout.module.js +2 -2
- package/dist/TableColumnLayout.module.js.map +1 -1
- package/dist/TableHeader.main.js.map +1 -1
- package/dist/TableHeader.module.js.map +1 -1
- package/dist/TableUtils.main.js +1 -1
- package/dist/TableUtils.main.js.map +1 -1
- package/dist/TableUtils.mjs +1 -1
- package/dist/TableUtils.module.js +1 -1
- package/dist/TableUtils.module.js.map +1 -1
- package/dist/types.d.ts +8 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/useTableColumnResizeState.main.js.map +1 -1
- package/dist/useTableColumnResizeState.module.js.map +1 -1
- package/dist/useTableState.main.js +4 -3
- package/dist/useTableState.main.js.map +1 -1
- package/dist/useTableState.mjs +4 -3
- package/dist/useTableState.module.js +4 -3
- package/dist/useTableState.module.js.map +1 -1
- package/dist/useTreeGridState.main.js +5 -5
- package/dist/useTreeGridState.main.js.map +1 -1
- package/dist/useTreeGridState.mjs +5 -5
- package/dist/useTreeGridState.module.js +5 -5
- package/dist/useTreeGridState.module.js.map +1 -1
- package/package.json +11 -11
- package/src/Cell.ts +1 -1
- package/src/Column.ts +2 -2
- package/src/Row.ts +1 -1
- package/src/TableBody.ts +1 -1
- package/src/TableCollection.ts +23 -19
- package/src/TableColumnLayout.ts +2 -2
- package/src/TableHeader.ts +1 -1
- package/src/TableUtils.ts +17 -6
- package/src/useTableColumnResizeState.ts +1 -1
- package/src/useTableState.ts +3 -3
- package/src/useTreeGridState.ts +12 -11
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;ACqBA,mCAA0C,CAAC;IACzC,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,KAAK,UAAU,GAAG,IAAI,GAAG,SAAS,CAAC;IACzE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,KAAK,UAAU,GAAG,IAAI,GAAG,SAAS,CAAA;CAC5E;AAED,+BAA+B,CAAC;IAC9B,eAAe,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,KAAK,UAAU,GAAG,IAAI,GAAG,SAAS,CAAC;IACxE,kBAAkB,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,KAAK,UAAU,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3E,YAAY,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAa;IAC3C,eAAe,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAa;IAC9C,eAAe,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAa;gBAElC,OAAO,EAAE,yBAAyB,CAAC,CAAC;IAKhD,2HAA2H;IAC3H,yCAAyC,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAWtH,iFAAiF;I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;GAGG;AAEH,OAAA,IAAI,aAA8B,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC;ACHjF;;;GAGG;AAEH,OAAA,IAAI,WAA0B,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC;ACgB3E;;;;GAIG;AAEH,OAAA,IAAI,QAAoB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC;AC8BlE;;;;GAIG;AAEH,OAAA,IAAI,KAAc,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC;ACnFzD;;GAEG;AAEH,OAAA,IAAI,MAAgB,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,OAAO,CAAC;ACxBtD,YAAY,EAAC,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAU3G,OAAO,EAAC,OAAO,EAAC,MAAM,4BAA4B,CAAC","sources":["packages/@react-stately/table/src/packages/@react-stately/table/src/TableUtils.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/TableColumnLayout.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/TableCollection.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/useTableState.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/useTableColumnResizeState.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/useTreeGridState.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/TableHeader.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/TableBody.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/Column.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/Row.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/Cell.ts","packages/@react-stately/table/src/packages/@react-stately/table/src/index.ts","packages/@react-stately/table/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,"/*\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\nexport type {TableColumnResizeState, TableColumnResizeStateProps} from './useTableColumnResizeState';\nexport type {TableState, CollectionBuilderContext, TableStateProps} from './useTableState';\nexport type {TableHeaderProps, TableBodyProps, ColumnProps, RowProps, CellProps} from '@react-types/table';\nexport type {TreeGridState, TreeGridStateProps} from './useTreeGridState';\n\nexport {useTableColumnResizeState} from './useTableColumnResizeState';\nexport {useTableState} from './useTableState';\nexport {TableHeader} from './TableHeader';\nexport {TableBody} from './TableBody';\nexport {Column} from './Column';\nexport {Row} from './Row';\nexport {Cell} from './Cell';\nexport {Section} from '@react-stately/collections';\nexport {TableCollection, buildHeaderRows} from './TableCollection';\nexport {TableColumnLayout} from './TableColumnLayout';\nexport {UNSTABLE_useTreeGridState} from './useTreeGridState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -1 +1 @@
|
|
|
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,qBAAO,EAAc;IAC/D,IAAI,eAAe,CAAA,GAAA,oBAAM,EACvB,IAAM,IAAI,CAAA,GAAA,2CAAgB,EAAE;6BAC1B;gCACA;QACF,IACA;QAAC;QAAiB;KAAmB;IAGvC,IAAI,CAAC,mBAAmB,oBAAoB,GAA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QAAoB;QAAqB;QAAmB;KAAa;IAEtG,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 +1 @@
|
|
|
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,eAAO,EAAE,IACzD,aAAa,4BAA4B,CAAC;IAG5C,qDAAqD;IACrD,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,eAAO,EAAE,MAAM,UAAU,CAAC,OAAO;IACrE,IAAI,MAAM,UAAU,CAAC,OAAO,KAAK,aAAa;QAC5C,IACE,MAAM,UAAU,CAAC,OAAO,CAAC,MAAM,KAAK,YAAY,MAAM,IACtD,MAAM,UAAU,CAAC,OAAO,CAA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AEnG,IAAI,YAAY,CAAA,GAAA,kBAAU,EAAE;QAC1B,kBAAkB;IACpB,GAAG;QAAC;KAAkB;IAEtB,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"}
|
|
@@ -49,17 +49,18 @@ function $e3f7784147dde23d$export$907bcc6c48325fd6(props) {
|
|
|
49
49
|
collection: collection,
|
|
50
50
|
disabledBehavior: props.disabledBehavior || 'selection'
|
|
51
51
|
});
|
|
52
|
+
var _props_sortDescriptor;
|
|
52
53
|
return {
|
|
53
54
|
collection: collection,
|
|
54
55
|
disabledKeys: disabledKeys,
|
|
55
56
|
selectionManager: selectionManager,
|
|
56
57
|
showSelectionCheckboxes: props.showSelectionCheckboxes || false,
|
|
57
|
-
sortDescriptor: props.sortDescriptor,
|
|
58
|
+
sortDescriptor: (_props_sortDescriptor = props.sortDescriptor) !== null && _props_sortDescriptor !== void 0 ? _props_sortDescriptor : null,
|
|
58
59
|
isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
|
|
59
60
|
setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
|
|
60
61
|
sort (columnKey, direction) {
|
|
61
|
-
var _props_sortDescriptor;
|
|
62
|
-
props.onSortChange({
|
|
62
|
+
var _props_sortDescriptor, _props_onSortChange;
|
|
63
|
+
(_props_onSortChange = props.onSortChange) === null || _props_onSortChange === void 0 ? void 0 : _props_onSortChange.call(props, {
|
|
63
64
|
column: columnKey,
|
|
64
65
|
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
|
});
|
|
@@ -1 +1 @@
|
|
|
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;YAC3B,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QAE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M,cAAc,cAApB,mCAAA,wBAAwB;QACxC,8BAA8B,WAAW,IAAI,KAAK,KAAK;uCACvD;QACA,MAAK,SAAc,EAAE,SAAsC;gBAG9B,uBAF3B;aAAA,sBAAA,MAAM,YAAY,cAAlB,0CAAA,yBAAA,OAAqB;gBACnB,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 {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"],"names":[],"version":3,"file":"useTableState.main.js.map"}
|
package/dist/useTableState.mjs
CHANGED
|
@@ -43,17 +43,18 @@ function $4a0dd036d492cee4$export$907bcc6c48325fd6(props) {
|
|
|
43
43
|
collection: collection,
|
|
44
44
|
disabledBehavior: props.disabledBehavior || 'selection'
|
|
45
45
|
});
|
|
46
|
+
var _props_sortDescriptor;
|
|
46
47
|
return {
|
|
47
48
|
collection: collection,
|
|
48
49
|
disabledKeys: disabledKeys,
|
|
49
50
|
selectionManager: selectionManager,
|
|
50
51
|
showSelectionCheckboxes: props.showSelectionCheckboxes || false,
|
|
51
|
-
sortDescriptor: props.sortDescriptor,
|
|
52
|
+
sortDescriptor: (_props_sortDescriptor = props.sortDescriptor) !== null && _props_sortDescriptor !== void 0 ? _props_sortDescriptor : null,
|
|
52
53
|
isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
|
|
53
54
|
setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
|
|
54
55
|
sort (columnKey, direction) {
|
|
55
|
-
var _props_sortDescriptor;
|
|
56
|
-
props.onSortChange({
|
|
56
|
+
var _props_sortDescriptor, _props_onSortChange;
|
|
57
|
+
(_props_onSortChange = props.onSortChange) === null || _props_onSortChange === void 0 ? void 0 : _props_onSortChange.call(props, {
|
|
57
58
|
column: columnKey,
|
|
58
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'
|
|
59
60
|
});
|
|
@@ -43,17 +43,18 @@ function $4a0dd036d492cee4$export$907bcc6c48325fd6(props) {
|
|
|
43
43
|
collection: collection,
|
|
44
44
|
disabledBehavior: props.disabledBehavior || 'selection'
|
|
45
45
|
});
|
|
46
|
+
var _props_sortDescriptor;
|
|
46
47
|
return {
|
|
47
48
|
collection: collection,
|
|
48
49
|
disabledKeys: disabledKeys,
|
|
49
50
|
selectionManager: selectionManager,
|
|
50
51
|
showSelectionCheckboxes: props.showSelectionCheckboxes || false,
|
|
51
|
-
sortDescriptor: props.sortDescriptor,
|
|
52
|
+
sortDescriptor: (_props_sortDescriptor = props.sortDescriptor) !== null && _props_sortDescriptor !== void 0 ? _props_sortDescriptor : null,
|
|
52
53
|
isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,
|
|
53
54
|
setKeyboardNavigationDisabled: setKeyboardNavigationDisabled,
|
|
54
55
|
sort (columnKey, direction) {
|
|
55
|
-
var _props_sortDescriptor;
|
|
56
|
-
props.onSortChange({
|
|
56
|
+
var _props_sortDescriptor, _props_onSortChange;
|
|
57
|
+
(_props_onSortChange = props.onSortChange) === null || _props_onSortChange === void 0 ? void 0 : _props_onSortChange.call(props, {
|
|
57
58
|
column: columnKey,
|
|
58
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'
|
|
59
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiDD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC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AC;KAAQ,GAC3E;IAEF,IAAI,gBAAC,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE;QAClD,GAAG,KAAK;oBACR;QACA,kBAAkB,MAAM,gBAAgB,IAAI;IAC9C;QAOkB;IALlB,OAAO;oBACL;sBACA;0BACA;QACA,yBAAyB,MAAM,uBAAuB,IAAI;QAC1D,gBAAgB,CAAA,wBAAA,MAAM,cAAc,cAApB,mCAAA,wBAAwB;QACxC,8BAA8B,WAAW,IAAI,KAAK,KAAK;uCACvD;QACA,MAAK,SAAc,EAAE,SAAsC;gBAG9B,uBAF3B;aAAA,sBAAA,MAAM,YAAY,cAAlB,0CAAA,yBAAA,OAAqB;gBACnB,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 {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"],"names":[],"version":3,"file":"useTableState.module.js.map"}
|
|
@@ -101,7 +101,7 @@ function $ed4e0b68b470dcfd$var$convertExpanded(expanded) {
|
|
|
101
101
|
}
|
|
102
102
|
function $ed4e0b68b470dcfd$var$generateTreeGridCollection(nodes, opts) {
|
|
103
103
|
let { expandedKeys: expandedKeys = new Set() } = opts;
|
|
104
|
-
let body;
|
|
104
|
+
let body = null;
|
|
105
105
|
let flattenedRows = [];
|
|
106
106
|
let columnCount = 0;
|
|
107
107
|
let userColumnCount = 0;
|
|
@@ -163,7 +163,7 @@ function $ed4e0b68b470dcfd$var$generateTreeGridCollection(nodes, opts) {
|
|
|
163
163
|
// via .childNodes returns the same object as the one found via keyMap look up
|
|
164
164
|
Object.assign(node, newProps);
|
|
165
165
|
keyMap.set(node.key, node);
|
|
166
|
-
let lastNode;
|
|
166
|
+
let lastNode = null;
|
|
167
167
|
let rowIndex = 0;
|
|
168
168
|
for (let child of node.childNodes)if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {
|
|
169
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
|
|
@@ -179,15 +179,15 @@ function $ed4e0b68b470dcfd$var$generateTreeGridCollection(nodes, opts) {
|
|
|
179
179
|
}
|
|
180
180
|
if (lastNode) lastNode.nextKey = null;
|
|
181
181
|
};
|
|
182
|
-
let last;
|
|
183
|
-
topLevelRows.
|
|
182
|
+
let last = null;
|
|
183
|
+
for (let [i, node] of topLevelRows.entries()){
|
|
184
184
|
visitNode(node, i);
|
|
185
185
|
if (last) {
|
|
186
186
|
last.nextKey = node.key;
|
|
187
187
|
node.prevKey = last.key;
|
|
188
188
|
} else node.prevKey = null;
|
|
189
189
|
last = node;
|
|
190
|
-
}
|
|
190
|
+
}
|
|
191
191
|
if (last) last.nextKey = null;
|
|
192
192
|
return {
|
|
193
193
|
keyMap: keyMap,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAA4C,KAA4B;IACtF,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC,CAAA,GAAA,wCAAc,KACjB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,2CAAiB,EACrD,mBAAmB,sCAAgB,oBAAoB,WACvD,0BAA0B,sCAAgB,2BAA2B,IAAI,OACzE;IAGF,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;YAC3B,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QAEb,CAAA,GAAI;QAAC;QAAU;QAAyB;QAAe;KAAgB;IAEvE,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE,IAAM,IA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IACxE;AACF","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<any>[]}, 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"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAA4C,KAA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AAO,GAAG,MAAM,GAAG;gBAC5B,MAAM,OAAO,GAAG,SAAS,GAAG;YAC9B,OACE,MAAM,OAAO,GAAG;YAGlB,IAAI,MAAM,IAAI,KAAK,QACjB,UAAU,OAAO;iBAEjB,0EAA0E;YAC1E,UAAU,OAAO,MAAM,KAAK;YAG9B,WAAW;QACb;QAGF,IAAI,UACF,SAAS,OAAO,GAAG;IAEvB;IAEA,IAAI,OAA2B;IAC/B,KAAK,IAAI,CAAC,GAAG,KAAK,IAAI,aAAa,OAAO,GAAI;QAC5C,UAAU,MAAqB;QAE/B,IAAI,MAAM;YACR,KAAK,OAAO,GAAG,KAAK,GAAG;YACvB,KAAK,OAAO,GAAG,KAAK,GAAG;QACzB,OACE,KAAK,OAAO,GAAG;QAGjB,OAAO;IACT;IAEA,IAAI,MACF,KAAK,OAAO,GAAG;IAGjB,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAG,YAAY;YAAa;SAAE;IACzE;AACF","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<any>[]}, 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> | null = null;\n let flattenedRows: GridNode<T>[] = [];\n let columnCount = 0;\n let userColumnCount = 0;\n let originalColumns: GridNode<T>[] = [];\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: GridNode<T>[] = [];\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\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: GridNode<T>[] = [];\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: GridNode<T> = {...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> | null = null;\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> | null = null;\n for (let [i, node] of topLevelRows.entries()) {\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"}
|
|
@@ -95,7 +95,7 @@ function $ee65a0057fd99531$var$convertExpanded(expanded) {
|
|
|
95
95
|
}
|
|
96
96
|
function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
|
|
97
97
|
let { expandedKeys: expandedKeys = new Set() } = opts;
|
|
98
|
-
let body;
|
|
98
|
+
let body = null;
|
|
99
99
|
let flattenedRows = [];
|
|
100
100
|
let columnCount = 0;
|
|
101
101
|
let userColumnCount = 0;
|
|
@@ -157,7 +157,7 @@ function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
|
|
|
157
157
|
// via .childNodes returns the same object as the one found via keyMap look up
|
|
158
158
|
Object.assign(node, newProps);
|
|
159
159
|
keyMap.set(node.key, node);
|
|
160
|
-
let lastNode;
|
|
160
|
+
let lastNode = null;
|
|
161
161
|
let rowIndex = 0;
|
|
162
162
|
for (let child of node.childNodes)if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {
|
|
163
163
|
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
|
|
@@ -173,15 +173,15 @@ function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
|
|
|
173
173
|
}
|
|
174
174
|
if (lastNode) lastNode.nextKey = null;
|
|
175
175
|
};
|
|
176
|
-
let last;
|
|
177
|
-
topLevelRows.
|
|
176
|
+
let last = null;
|
|
177
|
+
for (let [i, node] of topLevelRows.entries()){
|
|
178
178
|
visitNode(node, i);
|
|
179
179
|
if (last) {
|
|
180
180
|
last.nextKey = node.key;
|
|
181
181
|
node.prevKey = last.key;
|
|
182
182
|
} else node.prevKey = null;
|
|
183
183
|
last = node;
|
|
184
|
-
}
|
|
184
|
+
}
|
|
185
185
|
if (last) last.nextKey = null;
|
|
186
186
|
return {
|
|
187
187
|
keyMap: keyMap,
|
|
@@ -95,7 +95,7 @@ function $ee65a0057fd99531$var$convertExpanded(expanded) {
|
|
|
95
95
|
}
|
|
96
96
|
function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
|
|
97
97
|
let { expandedKeys: expandedKeys = new Set() } = opts;
|
|
98
|
-
let body;
|
|
98
|
+
let body = null;
|
|
99
99
|
let flattenedRows = [];
|
|
100
100
|
let columnCount = 0;
|
|
101
101
|
let userColumnCount = 0;
|
|
@@ -157,7 +157,7 @@ function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
|
|
|
157
157
|
// via .childNodes returns the same object as the one found via keyMap look up
|
|
158
158
|
Object.assign(node, newProps);
|
|
159
159
|
keyMap.set(node.key, node);
|
|
160
|
-
let lastNode;
|
|
160
|
+
let lastNode = null;
|
|
161
161
|
let rowIndex = 0;
|
|
162
162
|
for (let child of node.childNodes)if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {
|
|
163
163
|
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
|
|
@@ -173,15 +173,15 @@ function $ee65a0057fd99531$var$generateTreeGridCollection(nodes, opts) {
|
|
|
173
173
|
}
|
|
174
174
|
if (lastNode) lastNode.nextKey = null;
|
|
175
175
|
};
|
|
176
|
-
let last;
|
|
177
|
-
topLevelRows.
|
|
176
|
+
let last = null;
|
|
177
|
+
for (let [i, node] of topLevelRows.entries()){
|
|
178
178
|
visitNode(node, i);
|
|
179
179
|
if (last) {
|
|
180
180
|
last.nextKey = node.key;
|
|
181
181
|
node.prevKey = last.key;
|
|
182
182
|
} else node.prevKey = null;
|
|
183
183
|
last = node;
|
|
184
|
-
}
|
|
184
|
+
}
|
|
185
185
|
if (last) last.nextKey = null;
|
|
186
186
|
return {
|
|
187
187
|
keyMap: keyMap,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAA4C,KAA4B;IACtF,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC,CAAA,GAAA,sBAAc,KACjB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yBAAiB,EACrD,mBAAmB,sCAAgB,oBAAoB,WACvD,0BAA0B,sCAAgB,2BAA2B,IAAI,OACzE;IAGF,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;YAC3B,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QAEb,CAAA,GAAI;QAAC;QAAU;QAAyB;QAAe;KAAgB;IAEvE,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,wBAAgB,KAAQ,EAAE;IAC1D,IAAI,QAAQ,CAAA,GAAA,cAAM,EAAE,IAAM,QAAQ,KAAK,CAAC;YAAC,UAAU;QAA+B,GAAG,UAAU;QAAC;QAAS;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yD;QACzD,IAAI,KAAK,IAAI,KAAK,iBAAiB,KAAK,IAAI,KAAK,UAC/C,QAAQ,CAAC,cAAc,GAAG;QAG5B,6GAA6G;QAC7G,8EAA8E;QAC9E,OAAO,MAAM,CAAC,MAAM;QACpB,OAAO,GAAG,CAAC,KAAK,GAAG,EAAE;QAErB,IAAI;QACJ,IAAI,WAAW;QACf,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,IAAI,CAAE,CAAA,MAAM,IAAI,KAAK,UAAU,iBAAiB,SAAS,CAAC,aAAa,GAAG,CAAC,KAAK,GAAG,CAAA,GAAI;YACrF,IAAI,MAAM,SAAS,IAAI,MACrB,wIAAwI;YACxI,MAAM,SAAS,GAAG,KAAK,GAAG;YAG5B,IAAI,UAAU;gBACZ,SAAS,OAAO,GAAG,MAAM,GAAG;gBAC5B,MAAM,OAAO,GAAG,SAAS,GAAG;YAC9B,OACE,MAAM,OAAO,GAAG;YAGlB,IAAI,MAAM,IAAI,KAAK,QACjB,UAAU,OAAO;iBAEjB,0EAA0E;YAC1E,UAAU,OAAO,MAAM,KAAK;YAG9B,WAAW;QACb;QAGF,IAAI,UACF,SAAS,OAAO,GAAG;IAEvB;IAEA,IAAI;IACJ,aAAa,OAAO,CAAC,CAAC,MAAmB;QACvC,UAAU,MAAqB;QAE/B,IAAI,MAAM;YACR,KAAK,OAAO,GAAG,KAAK,GAAG;YACvB,KAAK,OAAO,GAAG,KAAK,GAAG;QACzB,OACE,KAAK,OAAO,GAAG;QAGjB,OAAO;IACT;IAEA,IAAI,MACF,KAAK,OAAO,GAAG;IAGjB,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAE,YAAY;YAAa;SAAE;IACxE;AACF","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<any>[]}, 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.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAA4C,KAA4B;IACtF,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC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AU,OAAO,MAAM,KAAK;YAG9B,WAAW;QACb;QAGF,IAAI,UACF,SAAS,OAAO,GAAG;IAEvB;IAEA,IAAI,OAA2B;IAC/B,KAAK,IAAI,CAAC,GAAG,KAAK,IAAI,aAAa,OAAO,GAAI;QAC5C,UAAU,MAAqB;QAE/B,IAAI,MAAM;YACR,KAAK,OAAO,GAAG,KAAK,GAAG;YACvB,KAAK,OAAO,GAAG,KAAK,GAAG;QACzB,OACE,KAAK,OAAO,GAAG;QAGjB,OAAO;IACT;IAEA,IAAI,MACF,KAAK,OAAO,GAAG;IAGjB,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAG,YAAY;YAAa;SAAE;IACzE;AACF","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<any>[]}, 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> | null = null;\n let flattenedRows: GridNode<T>[] = [];\n let columnCount = 0;\n let userColumnCount = 0;\n let originalColumns: GridNode<T>[] = [];\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: GridNode<T>[] = [];\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\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: GridNode<T>[] = [];\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: GridNode<T> = {...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> | null = null;\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> | null = null;\n for (let [i, node] of topLevelRows.entries()) {\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.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/table",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,21 +22,21 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/collections": "3.
|
|
26
|
-
"@react-stately/flags": "3.0.
|
|
27
|
-
"@react-stately/grid": "3.
|
|
28
|
-
"@react-stately/selection": "3.
|
|
29
|
-
"@react-stately/utils": "3.
|
|
30
|
-
"@react-types/grid": "3.2.
|
|
31
|
-
"@react-types/shared": "3.
|
|
32
|
-
"@react-types/table": "3.10.
|
|
25
|
+
"@react-stately/collections": "^3.12.0",
|
|
26
|
+
"@react-stately/flags": "^3.0.5",
|
|
27
|
+
"@react-stately/grid": "^3.10.0",
|
|
28
|
+
"@react-stately/selection": "^3.18.0",
|
|
29
|
+
"@react-stately/utils": "^3.10.5",
|
|
30
|
+
"@react-types/grid": "^3.2.10",
|
|
31
|
+
"@react-types/shared": "^3.26.0",
|
|
32
|
+
"@react-types/table": "^3.10.3",
|
|
33
33
|
"@swc/helpers": "^0.5.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
36
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
|
|
42
42
|
}
|
package/src/Cell.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {CellProps} from '@react-types/table';
|
|
|
14
14
|
import {JSX, ReactElement} from 'react';
|
|
15
15
|
import {PartialNode} from '@react-stately/collections';
|
|
16
16
|
|
|
17
|
-
function Cell(props: CellProps): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
17
|
+
function Cell(props: CellProps): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
|
package/src/Column.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {GridNode} from '@react-types/grid';
|
|
|
16
16
|
import {PartialNode} from '@react-stately/collections';
|
|
17
17
|
import React, {JSX, ReactElement} from 'react';
|
|
18
18
|
|
|
19
|
-
function Column<T>(props: ColumnProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
19
|
+
function Column<T>(props: ColumnProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -28,7 +28,7 @@ Column.getCollectionNode = function* getCollectionNode<T>(props: ColumnProps<T>,
|
|
|
28
28
|
|
|
29
29
|
let fullNodes = yield {
|
|
30
30
|
type: 'column',
|
|
31
|
-
hasChildNodes: !!childColumns || (title && React.Children.count(children) > 0),
|
|
31
|
+
hasChildNodes: !!childColumns || (!!title && React.Children.count(children) > 0),
|
|
32
32
|
rendered,
|
|
33
33
|
textValue,
|
|
34
34
|
props,
|
package/src/Row.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {PartialNode} from '@react-stately/collections';
|
|
|
15
15
|
import React, {JSX, ReactElement} from 'react';
|
|
16
16
|
import {RowProps} from '@react-types/table';
|
|
17
17
|
|
|
18
|
-
function Row<T>(props: RowProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
18
|
+
function Row<T>(props: RowProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
21
|
|