@fluentui/react-table 9.0.0-alpha.4 → 9.0.0-alpha.6
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/CHANGELOG.json +77 -5
- package/CHANGELOG.md +31 -6
- package/dist/index.d.ts +60 -47
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/types.js.map +1 -1
- package/lib/hooks/useSelection.js +40 -13
- package/lib/hooks/useSelection.js.map +1 -1
- package/lib/hooks/useSort.js +38 -16
- package/lib/hooks/useSort.js.map +1 -1
- package/lib/hooks/useTable.js +22 -77
- package/lib/hooks/useTable.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/hooks/index.js +4 -0
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useSelection.js +45 -15
- package/lib-commonjs/hooks/useSelection.js.map +1 -1
- package/lib-commonjs/hooks/useSort.js +43 -18
- package/lib-commonjs/hooks/useSort.js.map +1 -1
- package/lib-commonjs/hooks/useTable.js +19 -76
- package/lib-commonjs/hooks/useTable.js.map +1 -1
- package/lib-commonjs/index.js +14 -2
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +8 -8
package/lib/hooks/useTable.js
CHANGED
|
@@ -1,87 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { defaultTableSelectionState } from './useSelection';
|
|
2
|
+
import { defaultTableSortState } from './useSort';
|
|
3
|
+
|
|
4
|
+
const defaultRowEnhancer = row => row;
|
|
5
|
+
|
|
6
|
+
export function useTable(options, plugins = []) {
|
|
5
7
|
const {
|
|
6
|
-
items
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
selectionMode = 'multiselect',
|
|
10
|
-
rowEnhancer = row => row,
|
|
11
|
-
defaultSelectedRows,
|
|
12
|
-
selectedRows: userSelectedRows,
|
|
13
|
-
onSelectionChange,
|
|
14
|
-
sortState: userSortState,
|
|
15
|
-
defaultSortState,
|
|
16
|
-
onSortChange
|
|
8
|
+
items,
|
|
9
|
+
getRowId,
|
|
10
|
+
columns
|
|
17
11
|
} = options;
|
|
18
|
-
|
|
12
|
+
|
|
13
|
+
const getRows = (rowEnhancer = defaultRowEnhancer) => items.map((item, i) => {
|
|
19
14
|
var _a;
|
|
20
15
|
|
|
21
|
-
return (_a = getUserRowId(item)) !== null && _a !== void 0 ? _a : index;
|
|
22
|
-
}, [getUserRowId]);
|
|
23
|
-
const {
|
|
24
|
-
sortColumn,
|
|
25
|
-
sortDirection,
|
|
26
|
-
toggleColumnSort,
|
|
27
|
-
setColumnSort,
|
|
28
|
-
getSortDirection,
|
|
29
|
-
sort
|
|
30
|
-
} = useSort({
|
|
31
|
-
columns,
|
|
32
|
-
sortState: userSortState,
|
|
33
|
-
defaultSortState,
|
|
34
|
-
onSortChange
|
|
35
|
-
});
|
|
36
|
-
const sortState = React.useMemo(() => ({
|
|
37
|
-
sortColumn,
|
|
38
|
-
sortDirection,
|
|
39
|
-
setColumnSort,
|
|
40
|
-
toggleColumnSort,
|
|
41
|
-
getSortDirection
|
|
42
|
-
}), [sortColumn, sortDirection, setColumnSort, toggleColumnSort, getSortDirection]);
|
|
43
|
-
const {
|
|
44
|
-
isRowSelected,
|
|
45
|
-
toggleRow,
|
|
46
|
-
toggleAllRows,
|
|
47
|
-
clearRows,
|
|
48
|
-
selectedRows,
|
|
49
|
-
allRowsSelected,
|
|
50
|
-
someRowsSelected,
|
|
51
|
-
selectRow,
|
|
52
|
-
deselectRow
|
|
53
|
-
} = useSelection({
|
|
54
|
-
selectionMode,
|
|
55
|
-
items: baseItems,
|
|
56
|
-
getRowId,
|
|
57
|
-
defaultSelectedItems: defaultSelectedRows,
|
|
58
|
-
selectedItems: userSelectedRows,
|
|
59
|
-
onSelectionChange
|
|
60
|
-
});
|
|
61
|
-
const selectionState = React.useMemo(() => ({
|
|
62
|
-
isRowSelected,
|
|
63
|
-
clearRows,
|
|
64
|
-
deselectRow,
|
|
65
|
-
selectRow,
|
|
66
|
-
toggleAllRows,
|
|
67
|
-
toggleRow,
|
|
68
|
-
selectedRows: Array.from(selectedRows),
|
|
69
|
-
allRowsSelected,
|
|
70
|
-
someRowsSelected
|
|
71
|
-
}), [isRowSelected, clearRows, deselectRow, selectRow, toggleAllRows, toggleRow, selectedRows, allRowsSelected, someRowsSelected]);
|
|
72
|
-
const rows = React.useMemo(() => sort(baseItems).map((item, i) => {
|
|
73
16
|
return rowEnhancer({
|
|
74
17
|
item,
|
|
75
|
-
rowId: getRowId(item
|
|
76
|
-
}, {
|
|
77
|
-
selection: selectionState,
|
|
78
|
-
sort: sortState
|
|
18
|
+
rowId: (_a = getRowId === null || getRowId === void 0 ? void 0 : getRowId(item)) !== null && _a !== void 0 ? _a : i
|
|
79
19
|
});
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const initialState = {
|
|
23
|
+
getRowId,
|
|
24
|
+
items,
|
|
25
|
+
columns,
|
|
26
|
+
getRows,
|
|
27
|
+
selection: defaultTableSelectionState,
|
|
28
|
+
sort: defaultTableSortState
|
|
85
29
|
};
|
|
30
|
+
return plugins.reduce((state, plugin) => plugin(state), initialState);
|
|
86
31
|
}
|
|
87
32
|
//# sourceMappingURL=useTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useTable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useTable.ts"],"names":[],"mappings":"AACA,SAAS,0BAAT,QAA2C,gBAA3C;AACA,SAAS,qBAAT,QAAsC,WAAtC;;AAEA,MAAM,kBAAkB,GAA4C,GAAG,IAAI,GAA3E;;AAEA,OAAM,SAAU,QAAV,CAA0B,OAA1B,EAA2D,OAAA,GAA8B,EAAzF,EAA2F;EAC/F,MAAM;IAAE,KAAF;IAAS,QAAT;IAAmB;EAAnB,IAA+B,OAArC;;EAEA,MAAM,OAAO,GAAG,CACd,WAAA,GAAc,kBADA,KAEX,KAAK,CAAC,GAAN,CAAU,CAAC,IAAD,EAAO,CAAP,KAAY;IAAA,IAAA,EAAA;;IAAC,OAAA,WAAW,CAAC;MAAE,IAAF;MAAQ,KAAK,EAAE,CAAA,EAAA,GAAA,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAQ,KAAA,CAAR,GAAA,QAAQ,CAAG,IAAH,CAAR,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,EAAhB,GAAoB;IAAnC,CAAD,CAAX;EAAmD,CAA1E,CAFL;;EAIA,MAAM,YAAY,GAAsB;IACtC,QADsC;IAEtC,KAFsC;IAGtC,OAHsC;IAItC,OAJsC;IAKtC,SAAS,EAAE,0BAL2B;IAMtC,IAAI,EAAE;EANgC,CAAxC;EASA,OAAO,OAAO,CAAC,MAAR,CAAe,CAAC,KAAD,EAAQ,MAAR,KAAmB,MAAM,CAAC,KAAD,CAAxC,EAAiD,YAAjD,CAAP;AACD","sourcesContent":["import type { UseTableOptions, TableState, RowState, RowEnhancer, TableStatePlugin, TableSortState } from './types';\nimport { defaultTableSelectionState } from './useSelection';\nimport { defaultTableSortState } from './useSort';\n\nconst defaultRowEnhancer: RowEnhancer<unknown, RowState<unknown>> = row => row;\n\nexport function useTable<TItem>(options: UseTableOptions<TItem>, plugins: TableStatePlugin[] = []): TableState<TItem> {\n const { items, getRowId, columns } = options;\n\n const getRows = <TRowState extends RowState<TItem>>(\n rowEnhancer = defaultRowEnhancer as RowEnhancer<TItem, TRowState>,\n ) => items.map((item, i) => rowEnhancer({ item, rowId: getRowId?.(item) ?? i }));\n\n const initialState: TableState<TItem> = {\n getRowId,\n items,\n columns,\n getRows,\n selection: defaultTableSelectionState,\n sort: defaultTableSortState as TableSortState<TItem>,\n };\n\n return plugins.reduce((state, plugin) => plugin(state), initialState);\n}\n"],"sourceRoot":"../src/"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useTable } from './hooks';
|
|
1
|
+
export { useTable, useSelection, useSort } from './hooks';
|
|
2
2
|
export { TableCell, tableCellClassNames, tableCellClassName, useTableCellStyles_unstable, useTableCell_unstable, renderTableCell_unstable } from './TableCell';
|
|
3
3
|
export { TableRow, tableRowClassNames, tableRowClassName, useTableRowStyles_unstable, useTableRow_unstable, renderTableRow_unstable } from './TableRow';
|
|
4
4
|
export { TableBody, tableBodyClassName, tableBodyClassNames, useTableBodyStyles_unstable, useTableBody_unstable, renderTableBody_unstable } from './TableBody';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-table/src/index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-table/src/index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,YAAnB,EAAiC,OAAjC,QAAgD,SAAhD;AAaA,SACE,SADF,EAEE,mBAFF,EAGE,kBAHF,EAIE,2BAJF,EAKE,qBALF,EAME,wBANF,QAOO,aAPP;AAUA,SACE,QADF,EAEE,kBAFF,EAGE,iBAHF,EAIE,0BAJF,EAKE,oBALF,EAME,uBANF,QAOO,YAPP;AAUA,SACE,SADF,EAEE,kBAFF,EAGE,mBAHF,EAIE,2BAJF,EAKE,qBALF,EAME,wBANF,QAOO,aAPP;AAUA,SACE,KADF,EAEE,cAFF,EAGE,eAHF,EAIE,uBAJF,EAKE,iBALF,EAME,oBANF,QAOO,SAPP;AAUA,SACE,WADF,EAEE,qBAFF,EAGE,oBAHF,EAIE,6BAJF,EAKE,uBALF,EAME,0BANF,QAOO,eAPP;AAUA,SACE,eADF,EAEE,wBAFF,EAGE,yBAHF,EAIE,iCAJF,EAKE,2BALF,EAME,8BANF,QAOO,mBAPP;AAUA,SAAS,oBAAT,EAA+B,eAA/B,QAAsD,yBAAtD;AACA,SACE,kBADF,EAEE,oCAFF,EAGE,8BAHF,EAIE,iCAJF,EAKE,4BALF,QAMO,sBANP;AASA,SACE,gBADF,EAEE,0BAFF,EAGE,kCAHF,EAIE,4BAJF,EAKE,+BALF,QAMO,oBANP;AASA,SACE,eADF,EAEE,yBAFF,EAGE,iCAHF,EAIE,2BAJF,EAKE,8BALF,QAMO,mBANP","sourcesContent":["export { useTable, useSelection, useSort } from './hooks';\nexport type {\n UseTableOptions,\n TableState as HeadlessTableState,\n TableSelectionState,\n TableSortState,\n TableStatePlugin,\n RowState,\n RowId,\n ColumnDefinition,\n ColumnId,\n} from './hooks';\n\nexport {\n TableCell,\n tableCellClassNames,\n tableCellClassName,\n useTableCellStyles_unstable,\n useTableCell_unstable,\n renderTableCell_unstable,\n} from './TableCell';\nexport type { TableCellProps, TableCellState, TableCellSlots } from './TableCell';\n\nexport {\n TableRow,\n tableRowClassNames,\n tableRowClassName,\n useTableRowStyles_unstable,\n useTableRow_unstable,\n renderTableRow_unstable,\n} from './TableRow';\nexport type { TableRowProps, TableRowState, TableRowSlots } from './TableRow';\n\nexport {\n TableBody,\n tableBodyClassName,\n tableBodyClassNames,\n useTableBodyStyles_unstable,\n useTableBody_unstable,\n renderTableBody_unstable,\n} from './TableBody';\nexport type { TableBodyProps, TableBodyState, TableBodySlots } from './TableBody';\n\nexport {\n Table,\n tableClassName,\n tableClassNames,\n useTableStyles_unstable,\n useTable_unstable,\n renderTable_unstable,\n} from './Table';\nexport type { TableProps, TableSlots, TableState, TableContextValue, TableContextValues, SortDirection } from './Table';\n\nexport {\n TableHeader,\n tableHeaderClassNames,\n tableHeaderClassName,\n useTableHeaderStyles_unstable,\n useTableHeader_unstable,\n renderTableHeader_unstable,\n} from './TableHeader';\nexport type { TableHeaderProps, TableHeaderSlots, TableHeaderState } from './TableHeader';\n\nexport {\n TableHeaderCell,\n tableHeaderCellClassName,\n tableHeaderCellClassNames,\n useTableHeaderCellStyles_unstable,\n useTableHeaderCell_unstable,\n renderTableHeaderCell_unstable,\n} from './TableHeaderCell';\nexport type { TableHeaderCellProps, TableHeaderCellSlots, TableHeaderCellState } from './TableHeaderCell';\n\nexport { TableContextProvider, useTableContext } from './contexts/tableContext';\nexport {\n TableSelectionCell,\n useTableSelectionCellStyles_unstable,\n useTableSelectionCell_unstable,\n renderTableSelectionCell_unstable,\n tableSelectionCellClassNames,\n} from './TableSelectionCell';\n\nexport type { TableSelectionCellProps, TableSelectionCellState, TableSelectionCellSlots } from './TableSelectionCell';\nexport {\n TableCellActions,\n tableCellActionsClassNames,\n useTableCellActionsStyles_unstable,\n useTableCellActions_unstable,\n renderTableCellActions_unstable,\n} from './TableCellActions';\n\nexport type { TableCellActionsProps, TableCellActionsSlots, TableCellActionsState } from './TableCellActions';\nexport {\n TableCellLayout,\n tableCellLayoutClassNames,\n useTableCellLayoutStyles_unstable,\n useTableCellLayout_unstable,\n renderTableCellLayout_unstable,\n} from './TableCellLayout';\nexport type { TableCellLayoutProps, TableCellLayoutSlots, TableCellLayoutState } from './TableCellLayout';\n"],"sourceRoot":"../src/"}
|
|
@@ -9,4 +9,8 @@ const tslib_1 = /*#__PURE__*/require("tslib");
|
|
|
9
9
|
tslib_1.__exportStar(require("./types"), exports);
|
|
10
10
|
|
|
11
11
|
tslib_1.__exportStar(require("./useTable"), exports);
|
|
12
|
+
|
|
13
|
+
tslib_1.__exportStar(require("./useSort"), exports);
|
|
14
|
+
|
|
15
|
+
tslib_1.__exportStar(require("./useSelection"), exports);
|
|
12
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-table/src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './types';\nexport * from './useTable';\n"],"sourceRoot":"../src/"}
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-table/src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,WAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './types';\nexport * from './useTable';\nexport * from './useSort';\nexport * from './useSelection';\n"],"sourceRoot":"../src/"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useSelection = void 0;
|
|
6
|
+
exports.useSelectionState = exports.useSelection = exports.defaultTableSelectionState = void 0;
|
|
7
7
|
|
|
8
8
|
const React = /*#__PURE__*/require("react");
|
|
9
9
|
|
|
@@ -11,11 +11,35 @@ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
|
11
11
|
|
|
12
12
|
const selectionManager_1 = /*#__PURE__*/require("./selectionManager");
|
|
13
13
|
|
|
14
|
+
const noop = () => undefined;
|
|
15
|
+
|
|
16
|
+
exports.defaultTableSelectionState = {
|
|
17
|
+
allRowsSelected: false,
|
|
18
|
+
clearRows: noop,
|
|
19
|
+
deselectRow: noop,
|
|
20
|
+
isRowSelected: () => false,
|
|
21
|
+
selectRow: noop,
|
|
22
|
+
selectedRows: /*#__PURE__*/new Set(),
|
|
23
|
+
someRowsSelected: false,
|
|
24
|
+
toggleAllRows: noop,
|
|
25
|
+
toggleRow: noop
|
|
26
|
+
};
|
|
27
|
+
|
|
14
28
|
function useSelection(options) {
|
|
29
|
+
// False positive, these plugin hooks are intended to be run on every render
|
|
30
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
31
|
+
return tableState => useSelectionState(tableState, options);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.useSelection = useSelection;
|
|
35
|
+
|
|
36
|
+
function useSelectionState(tableState, options) {
|
|
15
37
|
const {
|
|
16
|
-
selectionMode,
|
|
17
38
|
items,
|
|
18
|
-
getRowId
|
|
39
|
+
getRowId
|
|
40
|
+
} = tableState;
|
|
41
|
+
const {
|
|
42
|
+
selectionMode,
|
|
19
43
|
defaultSelectedItems,
|
|
20
44
|
selectedItems,
|
|
21
45
|
onSelectionChange
|
|
@@ -34,7 +58,11 @@ function useSelection(options) {
|
|
|
34
58
|
});
|
|
35
59
|
}, [onSelectionChange, selectionMode, setSelected]);
|
|
36
60
|
const toggleAllRows = react_utilities_1.useEventCallback(() => {
|
|
37
|
-
selectionManager.toggleAllItems(items.map((item, i) =>
|
|
61
|
+
selectionManager.toggleAllItems(items.map((item, i) => {
|
|
62
|
+
var _a;
|
|
63
|
+
|
|
64
|
+
return (_a = getRowId === null || getRowId === void 0 ? void 0 : getRowId(item)) !== null && _a !== void 0 ? _a : i;
|
|
65
|
+
}), selected);
|
|
38
66
|
});
|
|
39
67
|
const toggleRow = react_utilities_1.useEventCallback(rowId => selectionManager.toggleItem(rowId, selected));
|
|
40
68
|
const deselectRow = react_utilities_1.useEventCallback(rowId => selectionManager.deselectItem(rowId, selected));
|
|
@@ -42,18 +70,20 @@ function useSelection(options) {
|
|
|
42
70
|
|
|
43
71
|
const isRowSelected = rowId => selectionManager.isSelected(rowId, selected);
|
|
44
72
|
|
|
45
|
-
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
73
|
+
return { ...tableState,
|
|
74
|
+
selection: {
|
|
75
|
+
someRowsSelected: selected.size > 0,
|
|
76
|
+
allRowsSelected: selectionMode === 'single' ? selected.size > 0 : selected.size === items.length,
|
|
77
|
+
selectedRows: selected,
|
|
78
|
+
toggleRow,
|
|
79
|
+
toggleAllRows,
|
|
80
|
+
clearRows: selectionManager.clearItems,
|
|
81
|
+
deselectRow,
|
|
82
|
+
selectRow,
|
|
83
|
+
isRowSelected
|
|
84
|
+
}
|
|
55
85
|
};
|
|
56
86
|
}
|
|
57
87
|
|
|
58
|
-
exports.
|
|
88
|
+
exports.useSelectionState = useSelectionState;
|
|
59
89
|
//# sourceMappingURL=useSelection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useSelection.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,kBAAA,gBAAA,OAAA,CAAA,oBAAA,CAAA;;
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useSelection.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback } from '@fluentui/react-utilities';\nimport { createSelectionManager } from './selectionManager';\nimport type { RowId, TableSelectionState, TableState, UseSelectionOptions } from './types';\n\nconst noop = () => undefined;\n\nexport const defaultTableSelectionState: TableSelectionState = {\n allRowsSelected: false,\n clearRows: noop,\n deselectRow: noop,\n isRowSelected: () => false,\n selectRow: noop,\n selectedRows: new Set(),\n someRowsSelected: false,\n toggleAllRows: noop,\n toggleRow: noop,\n};\n\nexport function useSelection<TItem>(options: UseSelectionOptions) {\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableState<TItem>) => useSelectionState(tableState, options);\n}\n\nexport function useSelectionState<TItem>(\n tableState: TableState<TItem>,\n options: UseSelectionOptions,\n): TableState<TItem> {\n const { items, getRowId } = tableState;\n const { selectionMode, defaultSelectedItems, selectedItems, onSelectionChange } = options;\n\n const [selected, setSelected] = useControllableState({\n initialState: new Set<RowId>(),\n defaultState: defaultSelectedItems,\n state: selectedItems,\n });\n\n const selectionManager = React.useMemo(() => {\n return createSelectionManager(selectionMode, newSelectedItems => {\n setSelected(() => {\n onSelectionChange?.(newSelectedItems);\n return newSelectedItems;\n });\n });\n }, [onSelectionChange, selectionMode, setSelected]);\n\n const toggleAllRows: TableSelectionState['toggleAllRows'] = useEventCallback(() => {\n selectionManager.toggleAllItems(\n items.map((item, i) => getRowId?.(item) ?? i),\n selected,\n );\n });\n\n const toggleRow: TableSelectionState['toggleRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.toggleItem(rowId, selected),\n );\n\n const deselectRow: TableSelectionState['deselectRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.deselectItem(rowId, selected),\n );\n\n const selectRow: TableSelectionState['selectRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.selectItem(rowId, selected),\n );\n\n const isRowSelected: TableSelectionState['isRowSelected'] = (rowId: RowId) =>\n selectionManager.isSelected(rowId, selected);\n\n return {\n ...tableState,\n selection: {\n someRowsSelected: selected.size > 0,\n allRowsSelected: selectionMode === 'single' ? selected.size > 0 : selected.size === items.length,\n selectedRows: selected,\n toggleRow,\n toggleAllRows,\n clearRows: selectionManager.clearItems,\n deselectRow,\n selectRow,\n isRowSelected,\n },\n };\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -3,13 +3,34 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useSort = void 0;
|
|
6
|
+
exports.useSortState = exports.useSort = exports.defaultTableSortState = void 0;
|
|
7
7
|
|
|
8
8
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
9
9
|
|
|
10
|
+
const noop = () => undefined;
|
|
11
|
+
|
|
12
|
+
exports.defaultTableSortState = {
|
|
13
|
+
getSortDirection: () => 'ascending',
|
|
14
|
+
setColumnSort: noop,
|
|
15
|
+
sort: rows => [...rows],
|
|
16
|
+
sortColumn: undefined,
|
|
17
|
+
sortDirection: 'ascending',
|
|
18
|
+
toggleColumnSort: noop
|
|
19
|
+
};
|
|
20
|
+
|
|
10
21
|
function useSort(options) {
|
|
22
|
+
// False positive, these plugin hooks are intended to be run on every render
|
|
23
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
24
|
+
return tableState => useSortState(tableState, options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.useSort = useSort;
|
|
28
|
+
|
|
29
|
+
function useSortState(tableState, options) {
|
|
30
|
+
const {
|
|
31
|
+
columns
|
|
32
|
+
} = tableState;
|
|
11
33
|
const {
|
|
12
|
-
columns,
|
|
13
34
|
sortState,
|
|
14
35
|
defaultSortState,
|
|
15
36
|
onSortChange
|
|
@@ -53,30 +74,34 @@ function useSort(options) {
|
|
|
53
74
|
setSorted(newState);
|
|
54
75
|
};
|
|
55
76
|
|
|
56
|
-
const sort =
|
|
57
|
-
|
|
77
|
+
const sort = rows => {
|
|
78
|
+
return rows.slice().sort((a, b) => {
|
|
79
|
+
const sortColumnDef = columns.find(column => column.columnId === sortColumn);
|
|
58
80
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
if (!(sortColumnDef === null || sortColumnDef === void 0 ? void 0 : sortColumnDef.compare)) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
62
84
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
const mod = sortDirection === 'ascending' ? 1 : -1;
|
|
86
|
+
return sortColumnDef.compare(a.item, b.item) * mod;
|
|
87
|
+
});
|
|
88
|
+
};
|
|
66
89
|
|
|
67
90
|
const getSortDirection = columnId => {
|
|
68
91
|
return sortColumn === columnId ? sortDirection : undefined;
|
|
69
92
|
};
|
|
70
93
|
|
|
71
|
-
return {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
94
|
+
return { ...tableState,
|
|
95
|
+
sort: {
|
|
96
|
+
sort,
|
|
97
|
+
sortColumn,
|
|
98
|
+
sortDirection,
|
|
99
|
+
setColumnSort,
|
|
100
|
+
toggleColumnSort,
|
|
101
|
+
getSortDirection
|
|
102
|
+
}
|
|
78
103
|
};
|
|
79
104
|
}
|
|
80
105
|
|
|
81
|
-
exports.
|
|
106
|
+
exports.useSortState = useSortState;
|
|
82
107
|
//# sourceMappingURL=useSort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useSort.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useSort.ts"],"names":[],"mappings":"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","sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport type { ColumnId, RowState, SortState, TableSortState, TableState, UseSortOptions } from './types';\n\nconst noop = () => undefined;\n\nexport const defaultTableSortState: TableSortState<unknown> = {\n getSortDirection: () => 'ascending',\n setColumnSort: noop,\n sort: (rows: RowState<unknown>[]) => [...rows],\n sortColumn: undefined,\n sortDirection: 'ascending',\n toggleColumnSort: noop,\n};\n\nexport function useSort<TItem>(options: UseSortOptions) {\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableState<TItem>) => useSortState(tableState, options);\n}\n\nexport function useSortState<TItem>(tableState: TableState<TItem>, options: UseSortOptions): TableState<TItem> {\n const { columns } = tableState;\n const { sortState, defaultSortState, onSortChange } = options;\n\n const [sorted, setSorted] = useControllableState<SortState>({\n initialState: {\n sortDirection: 'ascending' as const,\n sortColumn: undefined,\n },\n defaultState: defaultSortState,\n state: sortState,\n });\n\n const { sortColumn, sortDirection } = sorted;\n\n const toggleColumnSort = (columnId: ColumnId | undefined) => {\n setSorted(s => {\n const newState = { ...s, sortColumn: columnId };\n if (s.sortColumn === columnId) {\n newState.sortDirection = s.sortDirection === 'ascending' ? 'descending' : 'ascending';\n } else {\n newState.sortDirection = 'ascending';\n }\n\n onSortChange?.(newState);\n return newState;\n });\n };\n\n const setColumnSort: TableSortState<TItem>['setColumnSort'] = (nextSortColumn, nextSortDirection) => {\n const newState = { sortColumn: nextSortColumn, sortDirection: nextSortDirection };\n onSortChange?.(newState);\n setSorted(newState);\n };\n\n const sort = (rows: RowState<TItem>[]) => {\n return rows.slice().sort((a, b) => {\n const sortColumnDef = columns.find(column => column.columnId === sortColumn);\n if (!sortColumnDef?.compare) {\n return 0;\n }\n\n const mod = sortDirection === 'ascending' ? 1 : -1;\n return sortColumnDef.compare(a.item, b.item) * mod;\n });\n };\n\n const getSortDirection: TableSortState<TItem>['getSortDirection'] = (columnId: ColumnId) => {\n return sortColumn === columnId ? sortDirection : undefined;\n };\n\n return {\n ...tableState,\n sort: {\n sort,\n sortColumn,\n sortDirection,\n setColumnSort,\n toggleColumnSort,\n getSortDirection,\n },\n };\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -5,94 +5,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useTable = void 0;
|
|
7
7
|
|
|
8
|
-
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const useSelection_1 = /*#__PURE__*/require("./useSelection");
|
|
11
9
|
|
|
12
10
|
const useSort_1 = /*#__PURE__*/require("./useSort");
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
const defaultRowEnhancer = row => row;
|
|
13
|
+
|
|
14
|
+
function useTable(options, plugins = []) {
|
|
15
15
|
const {
|
|
16
|
-
items
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
selectionMode = 'multiselect',
|
|
20
|
-
rowEnhancer = row => row,
|
|
21
|
-
defaultSelectedRows,
|
|
22
|
-
selectedRows: userSelectedRows,
|
|
23
|
-
onSelectionChange,
|
|
24
|
-
sortState: userSortState,
|
|
25
|
-
defaultSortState,
|
|
26
|
-
onSortChange
|
|
16
|
+
items,
|
|
17
|
+
getRowId,
|
|
18
|
+
columns
|
|
27
19
|
} = options;
|
|
28
|
-
|
|
20
|
+
|
|
21
|
+
const getRows = (rowEnhancer = defaultRowEnhancer) => items.map((item, i) => {
|
|
29
22
|
var _a;
|
|
30
23
|
|
|
31
|
-
return (_a = getUserRowId(item)) !== null && _a !== void 0 ? _a : index;
|
|
32
|
-
}, [getUserRowId]);
|
|
33
|
-
const {
|
|
34
|
-
sortColumn,
|
|
35
|
-
sortDirection,
|
|
36
|
-
toggleColumnSort,
|
|
37
|
-
setColumnSort,
|
|
38
|
-
getSortDirection,
|
|
39
|
-
sort
|
|
40
|
-
} = useSort_1.useSort({
|
|
41
|
-
columns,
|
|
42
|
-
sortState: userSortState,
|
|
43
|
-
defaultSortState,
|
|
44
|
-
onSortChange
|
|
45
|
-
});
|
|
46
|
-
const sortState = React.useMemo(() => ({
|
|
47
|
-
sortColumn,
|
|
48
|
-
sortDirection,
|
|
49
|
-
setColumnSort,
|
|
50
|
-
toggleColumnSort,
|
|
51
|
-
getSortDirection
|
|
52
|
-
}), [sortColumn, sortDirection, setColumnSort, toggleColumnSort, getSortDirection]);
|
|
53
|
-
const {
|
|
54
|
-
isRowSelected,
|
|
55
|
-
toggleRow,
|
|
56
|
-
toggleAllRows,
|
|
57
|
-
clearRows,
|
|
58
|
-
selectedRows,
|
|
59
|
-
allRowsSelected,
|
|
60
|
-
someRowsSelected,
|
|
61
|
-
selectRow,
|
|
62
|
-
deselectRow
|
|
63
|
-
} = useSelection_1.useSelection({
|
|
64
|
-
selectionMode,
|
|
65
|
-
items: baseItems,
|
|
66
|
-
getRowId,
|
|
67
|
-
defaultSelectedItems: defaultSelectedRows,
|
|
68
|
-
selectedItems: userSelectedRows,
|
|
69
|
-
onSelectionChange
|
|
70
|
-
});
|
|
71
|
-
const selectionState = React.useMemo(() => ({
|
|
72
|
-
isRowSelected,
|
|
73
|
-
clearRows,
|
|
74
|
-
deselectRow,
|
|
75
|
-
selectRow,
|
|
76
|
-
toggleAllRows,
|
|
77
|
-
toggleRow,
|
|
78
|
-
selectedRows: Array.from(selectedRows),
|
|
79
|
-
allRowsSelected,
|
|
80
|
-
someRowsSelected
|
|
81
|
-
}), [isRowSelected, clearRows, deselectRow, selectRow, toggleAllRows, toggleRow, selectedRows, allRowsSelected, someRowsSelected]);
|
|
82
|
-
const rows = React.useMemo(() => sort(baseItems).map((item, i) => {
|
|
83
24
|
return rowEnhancer({
|
|
84
25
|
item,
|
|
85
|
-
rowId: getRowId(item
|
|
86
|
-
}, {
|
|
87
|
-
selection: selectionState,
|
|
88
|
-
sort: sortState
|
|
26
|
+
rowId: (_a = getRowId === null || getRowId === void 0 ? void 0 : getRowId(item)) !== null && _a !== void 0 ? _a : i
|
|
89
27
|
});
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const initialState = {
|
|
31
|
+
getRowId,
|
|
32
|
+
items,
|
|
33
|
+
columns,
|
|
34
|
+
getRows,
|
|
35
|
+
selection: useSelection_1.defaultTableSelectionState,
|
|
36
|
+
sort: useSort_1.defaultTableSortState
|
|
95
37
|
};
|
|
38
|
+
return plugins.reduce((state, plugin) => plugin(state), initialState);
|
|
96
39
|
}
|
|
97
40
|
|
|
98
41
|
exports.useTable = useTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useTable.ts"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-table/src/hooks/useTable.ts"],"names":[],"mappings":";;;;;;;AACA,MAAA,cAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;;AACA,MAAA,SAAA,gBAAA,OAAA,CAAA,WAAA,CAAA;;AAEA,MAAM,kBAAkB,GAA4C,GAAG,IAAI,GAA3E;;AAEA,SAAgB,QAAhB,CAAgC,OAAhC,EAAiE,OAAA,GAA8B,EAA/F,EAAiG;EAC/F,MAAM;IAAE,KAAF;IAAS,QAAT;IAAmB;EAAnB,IAA+B,OAArC;;EAEA,MAAM,OAAO,GAAG,CACd,WAAA,GAAc,kBADA,KAEX,KAAK,CAAC,GAAN,CAAU,CAAC,IAAD,EAAO,CAAP,KAAY;IAAA,IAAA,EAAA;;IAAC,OAAA,WAAW,CAAC;MAAE,IAAF;MAAQ,KAAK,EAAE,CAAA,EAAA,GAAA,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAQ,KAAA,CAAR,GAAA,QAAQ,CAAG,IAAH,CAAR,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,EAAhB,GAAoB;IAAnC,CAAD,CAAX;EAAmD,CAA1E,CAFL;;EAIA,MAAM,YAAY,GAAsB;IACtC,QADsC;IAEtC,KAFsC;IAGtC,OAHsC;IAItC,OAJsC;IAKtC,SAAS,EAAE,cAAA,CAAA,0BAL2B;IAMtC,IAAI,EAAE,SAAA,CAAA;EANgC,CAAxC;EASA,OAAO,OAAO,CAAC,MAAR,CAAe,CAAC,KAAD,EAAQ,MAAR,KAAmB,MAAM,CAAC,KAAD,CAAxC,EAAiD,YAAjD,CAAP;AACD;;AAjBD,OAAA,CAAA,QAAA,GAAA,QAAA","sourcesContent":["import type { UseTableOptions, TableState, RowState, RowEnhancer, TableStatePlugin, TableSortState } from './types';\nimport { defaultTableSelectionState } from './useSelection';\nimport { defaultTableSortState } from './useSort';\n\nconst defaultRowEnhancer: RowEnhancer<unknown, RowState<unknown>> = row => row;\n\nexport function useTable<TItem>(options: UseTableOptions<TItem>, plugins: TableStatePlugin[] = []): TableState<TItem> {\n const { items, getRowId, columns } = options;\n\n const getRows = <TRowState extends RowState<TItem>>(\n rowEnhancer = defaultRowEnhancer as RowEnhancer<TItem, TRowState>,\n ) => items.map((item, i) => rowEnhancer({ item, rowId: getRowId?.(item) ?? i }));\n\n const initialState: TableState<TItem> = {\n getRowId,\n items,\n columns,\n getRows,\n selection: defaultTableSelectionState,\n sort: defaultTableSortState as TableSortState<TItem>,\n };\n\n return plugins.reduce((state, plugin) => plugin(state), initialState);\n}\n"],"sourceRoot":"../src/"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.renderTableCellLayout_unstable = exports.useTableCellLayout_unstable = exports.useTableCellLayoutStyles_unstable = exports.tableCellLayoutClassNames = void 0;
|
|
6
|
+
exports.useTableCellActions_unstable = exports.useTableCellActionsStyles_unstable = exports.tableCellActionsClassNames = exports.TableCellActions = exports.tableSelectionCellClassNames = exports.renderTableSelectionCell_unstable = exports.useTableSelectionCell_unstable = exports.useTableSelectionCellStyles_unstable = exports.TableSelectionCell = exports.useTableContext = exports.TableContextProvider = exports.renderTableHeaderCell_unstable = exports.useTableHeaderCell_unstable = exports.useTableHeaderCellStyles_unstable = exports.tableHeaderCellClassNames = exports.tableHeaderCellClassName = exports.TableHeaderCell = exports.renderTableHeader_unstable = exports.useTableHeader_unstable = exports.useTableHeaderStyles_unstable = exports.tableHeaderClassName = exports.tableHeaderClassNames = exports.TableHeader = exports.renderTable_unstable = exports.useTable_unstable = exports.useTableStyles_unstable = exports.tableClassNames = exports.tableClassName = exports.Table = exports.renderTableBody_unstable = exports.useTableBody_unstable = exports.useTableBodyStyles_unstable = exports.tableBodyClassNames = exports.tableBodyClassName = exports.TableBody = exports.renderTableRow_unstable = exports.useTableRow_unstable = exports.useTableRowStyles_unstable = exports.tableRowClassName = exports.tableRowClassNames = exports.TableRow = exports.renderTableCell_unstable = exports.useTableCell_unstable = exports.useTableCellStyles_unstable = exports.tableCellClassName = exports.tableCellClassNames = exports.TableCell = exports.useSort = exports.useSelection = exports.useTable = void 0;
|
|
7
|
+
exports.renderTableCellLayout_unstable = exports.useTableCellLayout_unstable = exports.useTableCellLayoutStyles_unstable = exports.tableCellLayoutClassNames = exports.TableCellLayout = exports.renderTableCellActions_unstable = void 0;
|
|
8
8
|
|
|
9
9
|
var hooks_1 = /*#__PURE__*/require("./hooks");
|
|
10
10
|
|
|
@@ -14,6 +14,18 @@ Object.defineProperty(exports, "useTable", {
|
|
|
14
14
|
return hooks_1.useTable;
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
+
Object.defineProperty(exports, "useSelection", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return hooks_1.useSelection;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "useSort", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return hooks_1.useSort;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
17
29
|
|
|
18
30
|
var TableCell_1 = /*#__PURE__*/require("./TableCell");
|
|
19
31
|
|