@react-stately/table 3.15.3 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/import.mjs +6 -18
  2. package/dist/main.js +18 -30
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +6 -18
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +9 -0
  7. package/package.json +17 -20
  8. package/src/index.ts +9 -16
  9. package/dist/Cell.main.js +0 -38
  10. package/dist/Cell.main.js.map +0 -1
  11. package/dist/Cell.mjs +0 -33
  12. package/dist/Cell.module.js +0 -33
  13. package/dist/Cell.module.js.map +0 -1
  14. package/dist/Column.main.js +0 -75
  15. package/dist/Column.main.js.map +0 -1
  16. package/dist/Column.mjs +0 -66
  17. package/dist/Column.module.js +0 -66
  18. package/dist/Column.module.js.map +0 -1
  19. package/dist/Row.main.js +0 -102
  20. package/dist/Row.main.js.map +0 -1
  21. package/dist/Row.mjs +0 -93
  22. package/dist/Row.module.js +0 -93
  23. package/dist/Row.module.js.map +0 -1
  24. package/dist/TableBody.main.js +0 -61
  25. package/dist/TableBody.main.js.map +0 -1
  26. package/dist/TableBody.mjs +0 -52
  27. package/dist/TableBody.module.js +0 -52
  28. package/dist/TableBody.module.js.map +0 -1
  29. package/dist/TableCollection.main.js +0 -308
  30. package/dist/TableCollection.main.js.map +0 -1
  31. package/dist/TableCollection.mjs +0 -302
  32. package/dist/TableCollection.module.js +0 -302
  33. package/dist/TableCollection.module.js.map +0 -1
  34. package/dist/TableColumnLayout.main.js +0 -113
  35. package/dist/TableColumnLayout.main.js.map +0 -1
  36. package/dist/TableColumnLayout.mjs +0 -108
  37. package/dist/TableColumnLayout.module.js +0 -108
  38. package/dist/TableColumnLayout.module.js.map +0 -1
  39. package/dist/TableHeader.main.js +0 -56
  40. package/dist/TableHeader.main.js.map +0 -1
  41. package/dist/TableHeader.mjs +0 -47
  42. package/dist/TableHeader.module.js +0 -47
  43. package/dist/TableHeader.module.js.map +0 -1
  44. package/dist/TableUtils.main.js +0 -182
  45. package/dist/TableUtils.main.js.map +0 -1
  46. package/dist/TableUtils.mjs +0 -175
  47. package/dist/TableUtils.module.js +0 -175
  48. package/dist/TableUtils.module.js.map +0 -1
  49. package/dist/types.d.ts +0 -194
  50. package/dist/types.d.ts.map +0 -1
  51. package/dist/useTableColumnResizeState.main.js +0 -109
  52. package/dist/useTableColumnResizeState.main.js.map +0 -1
  53. package/dist/useTableColumnResizeState.mjs +0 -104
  54. package/dist/useTableColumnResizeState.module.js +0 -104
  55. package/dist/useTableColumnResizeState.module.js.map +0 -1
  56. package/dist/useTableState.main.js +0 -86
  57. package/dist/useTableState.main.js.map +0 -1
  58. package/dist/useTableState.mjs +0 -80
  59. package/dist/useTableState.module.js +0 -80
  60. package/dist/useTableState.module.js.map +0 -1
  61. package/dist/useTreeGridState.main.js +0 -207
  62. package/dist/useTreeGridState.main.js.map +0 -1
  63. package/dist/useTreeGridState.mjs +0 -202
  64. package/dist/useTreeGridState.module.js +0 -202
  65. package/dist/useTreeGridState.module.js.map +0 -1
  66. package/src/Cell.ts +0 -40
  67. package/src/Column.ts +0 -83
  68. package/src/Row.ts +0 -121
  69. package/src/TableBody.ts +0 -61
  70. package/src/TableCollection.ts +0 -367
  71. package/src/TableColumnLayout.ts +0 -127
  72. package/src/TableHeader.ts +0 -59
  73. package/src/TableUtils.ts +0 -266
  74. package/src/useTableColumnResizeState.ts +0 -147
  75. package/src/useTableState.ts +0 -124
  76. package/src/useTreeGridState.ts +0 -278
@@ -1 +0,0 @@
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,GAA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AAM,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/src/Cell.ts DELETED
@@ -1,40 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {CellProps} from '@react-types/table';
14
- import {JSX, ReactElement} from 'react';
15
- import {PartialNode} from '@react-stately/collections';
16
-
17
- function Cell(props: CellProps): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
18
- return null;
19
- }
20
-
21
- Cell.getCollectionNode = function* getCollectionNode<T>(props: CellProps): Generator<PartialNode<T>> {
22
- let {children} = props;
23
-
24
- let textValue = props.textValue || (typeof children === 'string' ? children : '') || props['aria-label'] || '';
25
- yield {
26
- type: 'cell',
27
- props: props,
28
- rendered: children,
29
- textValue,
30
- 'aria-label': props['aria-label'],
31
- hasChildNodes: false
32
- };
33
- };
34
-
35
- /**
36
- * A Cell represents the value of a single Column within a Table Row.
37
- */
38
- // We don't want getCollectionNode to show up in the type definition
39
- let _Cell = Cell as (props: CellProps) => JSX.Element;
40
- export {_Cell as Cell};
package/src/Column.ts DELETED
@@ -1,83 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {CollectionBuilderContext} from './useTableState';
14
- import {ColumnProps} from '@react-types/table';
15
- import {GridNode} from '@react-types/grid';
16
- import {PartialNode} from '@react-stately/collections';
17
- import React, {JSX, ReactElement} from 'react';
18
-
19
- function Column<T>(props: ColumnProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
20
- return null;
21
- }
22
-
23
- Column.getCollectionNode = function* getCollectionNode<T>(props: ColumnProps<T>, context: CollectionBuilderContext<T>): Generator<PartialNode<T>, void, GridNode<T>[]> {
24
- let {title, children, childColumns} = props;
25
-
26
- let rendered = title || children;
27
- let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'];
28
-
29
- let fullNodes = yield {
30
- type: 'column',
31
- hasChildNodes: !!childColumns || (!!title && React.Children.count(children) > 0),
32
- rendered,
33
- textValue,
34
- props,
35
- *childNodes() {
36
- if (childColumns) {
37
- for (let child of childColumns) {
38
- yield {
39
- type: 'column',
40
- value: child
41
- };
42
- }
43
- } else if (title) {
44
- let childColumns: PartialNode<T>[] = [];
45
- React.Children.forEach(children, child => {
46
- childColumns.push({
47
- type: 'column',
48
- element: child as ReactElement<ColumnProps<T>>
49
- });
50
- });
51
-
52
- yield* childColumns;
53
- }
54
- },
55
- shouldInvalidate(newContext: CollectionBuilderContext<T>) {
56
- // This is a bit of a hack, but it works.
57
- // If this method is called, then there's a cached version of this node available.
58
- // But, we need to keep the list of columns in the new context up to date.
59
- updateContext(newContext);
60
- return false;
61
- }
62
- };
63
-
64
- let updateContext = (context: CollectionBuilderContext<T>) => {
65
- // register leaf columns on the context so that <Row> can access them
66
- for (let node of fullNodes) {
67
- if (!node.hasChildNodes) {
68
- context.columns.push(node);
69
- }
70
- }
71
- };
72
-
73
- updateContext(context);
74
- };
75
-
76
- /**
77
- * A Column represents a field of each item within a Table. Columns may also contain nested
78
- * Column elements to represent column groups. Nested columns can be statically defined as
79
- * children, or dynamically generated using a function based on the `childColumns` prop.
80
- */
81
- // We don't want getCollectionNode to show up in the type definition
82
- let _Column = Column as <T>(props: ColumnProps<T>) => JSX.Element;
83
- export {_Column as Column};
package/src/Row.ts DELETED
@@ -1,121 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {CollectionBuilderContext} from './useTableState';
14
- import {PartialNode} from '@react-stately/collections';
15
- import React, {JSX, ReactElement} from 'react';
16
- import {RowProps} from '@react-types/table';
17
-
18
- function Row<T>(props: RowProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
19
- return null;
20
- }
21
-
22
- Row.getCollectionNode = function* getCollectionNode<T>(props: RowProps<T>, context: CollectionBuilderContext<T>): Generator<PartialNode<T>> {
23
- let {children, textValue, UNSTABLE_childItems} = props;
24
-
25
- yield {
26
- type: 'item',
27
- props: props,
28
- textValue,
29
- 'aria-label': props['aria-label'],
30
- hasChildNodes: true,
31
- *childNodes() {
32
- // Process cells first
33
- if (context.showDragButtons) {
34
- yield {
35
- type: 'cell',
36
- key: 'header-drag', // this is combined with the row key by CollectionBuilder
37
- props: {
38
- isDragButtonCell: true
39
- }
40
- };
41
- }
42
-
43
- if (context.showSelectionCheckboxes && context.selectionMode !== 'none') {
44
- yield {
45
- type: 'cell',
46
- key: 'header', // this is combined with the row key by CollectionBuilder
47
- props: {
48
- isSelectionCell: true
49
- }
50
- };
51
- }
52
-
53
- if (typeof children === 'function') {
54
- for (let column of context.columns) {
55
- yield {
56
- type: 'cell',
57
- element: children(column.key),
58
- key: column.key // this is combined with the row key by CollectionBuilder
59
- };
60
- }
61
-
62
- if (UNSTABLE_childItems) {
63
- for (let child of UNSTABLE_childItems) {
64
- // Note: in order to reuse the render function of TableBody for our child rows, we just need to yield a type and a value here. CollectionBuilder will then look up
65
- // the parent renderer and use that to build the full node of this child row, using the value provided here to generate the cells
66
- yield {
67
- type: 'item',
68
- value: child
69
- };
70
- }
71
- }
72
- } else {
73
- let cells: PartialNode<T>[] = [];
74
- let childRows: PartialNode<T>[] = [];
75
- let columnCount = 0;
76
- React.Children.forEach(children, node => {
77
- if (node.type === Row) {
78
- if (cells.length < context.columns.length) {
79
- throw new Error('All of a Row\'s child Cells must be positioned before any child Rows.');
80
- }
81
-
82
- childRows.push({
83
- type: 'item',
84
- element: node
85
- });
86
- } else {
87
- cells.push({
88
- type: 'cell',
89
- element: node
90
- });
91
- columnCount += node.props.colSpan ?? 1;
92
- }
93
- });
94
-
95
- if (columnCount !== context.columns.length) {
96
- throw new Error(`Cell count must match column count. Found ${columnCount} cells and ${context.columns.length} columns.`);
97
- }
98
-
99
- yield* cells;
100
- yield* childRows;
101
- }
102
- },
103
- shouldInvalidate(newContext: CollectionBuilderContext<T>) {
104
- // Invalidate all rows if the columns changed.
105
- return newContext.columns.length !== context.columns.length ||
106
- newContext.columns.some((c, i) => c.key !== context.columns[i].key) ||
107
- newContext.showSelectionCheckboxes !== context.showSelectionCheckboxes ||
108
- newContext.showDragButtons !== context.showDragButtons ||
109
- newContext.selectionMode !== context.selectionMode;
110
- }
111
- };
112
- };
113
-
114
- /**
115
- * A Row represents a single item in a Table and contains Cell elements for each column.
116
- * Cells can be statically defined as children, or generated dynamically using a function
117
- * based on the columns defined in the TableHeader.
118
- */
119
- // We don't want getCollectionNode to show up in the type definition
120
- let _Row = Row as <T>(props: RowProps<T>) => JSX.Element;
121
- export {_Row as Row};
package/src/TableBody.ts DELETED
@@ -1,61 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {PartialNode} from '@react-stately/collections';
14
- import React, {JSX, ReactElement} from 'react';
15
- import {TableBodyProps} from '@react-types/table';
16
-
17
- function TableBody<T>(props: TableBodyProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
18
- return null;
19
- }
20
-
21
- TableBody.getCollectionNode = function* getCollectionNode<T>(props: TableBodyProps<T>): Generator<PartialNode<T>> {
22
- let {children, items} = props;
23
- yield {
24
- type: 'body',
25
- hasChildNodes: true,
26
- props,
27
- *childNodes() {
28
- if (typeof children === 'function') {
29
- if (!items) {
30
- throw new Error('props.children was a function but props.items is missing');
31
- }
32
-
33
- for (let item of items) {
34
- yield {
35
- type: 'item',
36
- value: item,
37
- renderer: children
38
- };
39
- }
40
- } else {
41
- let items: PartialNode<T>[] = [];
42
- React.Children.forEach(children, item => {
43
- items.push({
44
- type: 'item',
45
- element: item
46
- });
47
- });
48
-
49
- yield* items;
50
- }
51
- }
52
- };
53
- };
54
-
55
- /**
56
- * A TableBody is a container for the Row elements of a Table. Rows can be statically defined
57
- * as children, or generated dynamically using a function based on the data passed to the `items` prop.
58
- */
59
- // We don't want getCollectionNode to show up in the type definition
60
- let _TableBody = TableBody as <T>(props: TableBodyProps<T>) => JSX.Element;
61
- export {_TableBody as TableBody};