@fluentui/react-table 9.1.1 → 9.2.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/CHANGELOG.json +103 -1
- package/CHANGELOG.md +32 -2
- package/dist/index.d.ts +7 -3
- package/lib/components/DataGrid/DataGrid.types.js.map +1 -1
- package/lib/components/DataGrid/useDataGrid.js.map +1 -1
- package/lib/components/DataGridRow/DataGridRow.types.js.map +1 -1
- package/lib/components/DataGridRow/renderDataGridRow.js +1 -1
- package/lib/components/DataGridRow/renderDataGridRow.js.map +1 -1
- package/lib/components/DataGridRow/useDataGridRow.js +3 -1
- package/lib/components/DataGridRow/useDataGridRow.js.map +1 -1
- package/lib/hooks/types.js.map +1 -1
- package/lib/hooks/useKeyboardResizing.js +95 -0
- package/lib/hooks/useKeyboardResizing.js.map +1 -0
- package/lib/hooks/useTableColumnResizeState.js.map +1 -1
- package/lib/hooks/useTableColumnSizing.js +15 -5
- package/lib/hooks/useTableColumnSizing.js.map +1 -1
- package/lib-amd/components/DataGrid/DataGrid.types.js.map +1 -1
- package/lib-amd/components/DataGrid/useDataGrid.js +3 -1
- package/lib-amd/components/DataGrid/useDataGrid.js.map +1 -1
- package/lib-amd/components/DataGridRow/DataGridRow.types.js.map +1 -1
- package/lib-amd/components/DataGridRow/renderDataGridRow.js +1 -1
- package/lib-amd/components/DataGridRow/renderDataGridRow.js.map +1 -1
- package/lib-amd/components/DataGridRow/useDataGridRow.js +2 -1
- package/lib-amd/components/DataGridRow/useDataGridRow.js.map +1 -1
- package/lib-amd/hooks/types.js.map +1 -1
- package/lib-amd/hooks/useKeyboardResizing.js +97 -0
- package/lib-amd/hooks/useKeyboardResizing.js.map +1 -0
- package/lib-amd/hooks/useTableColumnResizeState.js.map +1 -1
- package/lib-amd/hooks/useTableColumnSizing.js +12 -1
- package/lib-amd/hooks/useTableColumnSizing.js.map +1 -1
- package/lib-commonjs/components/DataGrid/DataGrid.types.js.map +1 -1
- package/lib-commonjs/components/DataGrid/useDataGrid.js.map +1 -1
- package/lib-commonjs/components/DataGridRow/DataGridRow.types.js.map +1 -1
- package/lib-commonjs/components/DataGridRow/renderDataGridRow.js +1 -1
- package/lib-commonjs/components/DataGridRow/renderDataGridRow.js.map +1 -1
- package/lib-commonjs/components/DataGridRow/useDataGridRow.js +3 -1
- package/lib-commonjs/components/DataGridRow/useDataGridRow.js.map +1 -1
- package/lib-commonjs/hooks/types.js.map +1 -1
- package/lib-commonjs/hooks/useKeyboardResizing.js +102 -0
- package/lib-commonjs/hooks/useKeyboardResizing.js.map +1 -0
- package/lib-commonjs/hooks/useTableColumnResizeState.js.map +1 -1
- package/lib-commonjs/hooks/useTableColumnSizing.js +15 -5
- package/lib-commonjs/hooks/useTableColumnSizing.js.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,109 @@
|
|
|
2
2
|
"name": "@fluentui/react-table",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Wed, 15 Mar 2023 10:17:03 GMT",
|
|
6
|
+
"tag": "@fluentui/react-table_v9.2.0",
|
|
7
|
+
"version": "9.2.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "jirivyhnalek@microsoft.com",
|
|
12
|
+
"package": "@fluentui/react-table",
|
|
13
|
+
"commit": "55230fb45b3e30941ee9f4005cf3ada071a4f626",
|
|
14
|
+
"comment": "Added support for keyboard navigation in Table/DataGrid"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "beachball",
|
|
18
|
+
"package": "@fluentui/react-table",
|
|
19
|
+
"comment": "Bump @fluentui/react-avatar to v9.4.3",
|
|
20
|
+
"commit": "5da01b4766ae6d81befb7bcd588d9cf8d969e1e2"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"author": "beachball",
|
|
24
|
+
"package": "@fluentui/react-table",
|
|
25
|
+
"comment": "Bump @fluentui/react-checkbox to v9.1.3",
|
|
26
|
+
"commit": "5da01b4766ae6d81befb7bcd588d9cf8d969e1e2"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"author": "beachball",
|
|
30
|
+
"package": "@fluentui/react-table",
|
|
31
|
+
"comment": "Bump @fluentui/react-radio to v9.1.3",
|
|
32
|
+
"commit": "5da01b4766ae6d81befb7bcd588d9cf8d969e1e2"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"author": "beachball",
|
|
36
|
+
"package": "@fluentui/react-table",
|
|
37
|
+
"comment": "Bump @fluentui/react-shared-contexts to v9.3.1",
|
|
38
|
+
"commit": "5da01b4766ae6d81befb7bcd588d9cf8d969e1e2"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"author": "beachball",
|
|
42
|
+
"package": "@fluentui/react-table",
|
|
43
|
+
"comment": "Bump @fluentui/react-tabster to v9.5.7",
|
|
44
|
+
"commit": "5da01b4766ae6d81befb7bcd588d9cf8d969e1e2"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"author": "beachball",
|
|
48
|
+
"package": "@fluentui/react-table",
|
|
49
|
+
"comment": "Bump @fluentui/react-theme to v9.1.6",
|
|
50
|
+
"commit": "5da01b4766ae6d81befb7bcd588d9cf8d969e1e2"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"date": "Mon, 13 Mar 2023 08:58:26 GMT",
|
|
57
|
+
"tag": "@fluentui/react-table_v9.1.2",
|
|
58
|
+
"version": "9.1.2",
|
|
59
|
+
"comments": {
|
|
60
|
+
"patch": [
|
|
61
|
+
{
|
|
62
|
+
"author": "beachball",
|
|
63
|
+
"package": "@fluentui/react-table",
|
|
64
|
+
"comment": "Bump @fluentui/react-aria to v9.3.13",
|
|
65
|
+
"commit": "edf96a6b5d6f13843ada1400480e347b84384b8e"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"author": "beachball",
|
|
69
|
+
"package": "@fluentui/react-table",
|
|
70
|
+
"comment": "Bump @fluentui/react-avatar to v9.4.2",
|
|
71
|
+
"commit": "edf96a6b5d6f13843ada1400480e347b84384b8e"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"author": "beachball",
|
|
75
|
+
"package": "@fluentui/react-table",
|
|
76
|
+
"comment": "Bump @fluentui/react-checkbox to v9.1.2",
|
|
77
|
+
"commit": "edf96a6b5d6f13843ada1400480e347b84384b8e"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"author": "beachball",
|
|
81
|
+
"package": "@fluentui/react-table",
|
|
82
|
+
"comment": "Bump @fluentui/react-context-selector to v9.1.13",
|
|
83
|
+
"commit": "edf96a6b5d6f13843ada1400480e347b84384b8e"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"author": "beachball",
|
|
87
|
+
"package": "@fluentui/react-table",
|
|
88
|
+
"comment": "Bump @fluentui/react-radio to v9.1.2",
|
|
89
|
+
"commit": "edf96a6b5d6f13843ada1400480e347b84384b8e"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"author": "beachball",
|
|
93
|
+
"package": "@fluentui/react-table",
|
|
94
|
+
"comment": "Bump @fluentui/react-tabster to v9.5.6",
|
|
95
|
+
"commit": "edf96a6b5d6f13843ada1400480e347b84384b8e"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"author": "beachball",
|
|
99
|
+
"package": "@fluentui/react-table",
|
|
100
|
+
"comment": "Bump @fluentui/react-utilities to v9.7.0",
|
|
101
|
+
"commit": "edf96a6b5d6f13843ada1400480e347b84384b8e"
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"date": "Fri, 10 Mar 2023 07:14:01 GMT",
|
|
6
108
|
"tag": "@fluentui/react-table_v9.1.1",
|
|
7
109
|
"version": "9.1.1",
|
|
8
110
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-table
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 15 Mar 2023 10:17:03 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-table_v9.2.0)
|
|
8
|
+
|
|
9
|
+
Wed, 15 Mar 2023 10:17:03 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-table_v9.1.2..@fluentui/react-table_v9.2.0)
|
|
11
|
+
|
|
12
|
+
### Minor changes
|
|
13
|
+
|
|
14
|
+
- Added support for keyboard navigation in Table/DataGrid ([PR #26956](https://github.com/microsoft/fluentui/pull/26956) by jirivyhnalek@microsoft.com)
|
|
15
|
+
- Bump @fluentui/react-avatar to v9.4.3 ([PR #27213](https://github.com/microsoft/fluentui/pull/27213) by beachball)
|
|
16
|
+
- Bump @fluentui/react-checkbox to v9.1.3 ([PR #27213](https://github.com/microsoft/fluentui/pull/27213) by beachball)
|
|
17
|
+
- Bump @fluentui/react-radio to v9.1.3 ([PR #27213](https://github.com/microsoft/fluentui/pull/27213) by beachball)
|
|
18
|
+
- Bump @fluentui/react-shared-contexts to v9.3.1 ([PR #27213](https://github.com/microsoft/fluentui/pull/27213) by beachball)
|
|
19
|
+
- Bump @fluentui/react-tabster to v9.5.7 ([PR #27213](https://github.com/microsoft/fluentui/pull/27213) by beachball)
|
|
20
|
+
- Bump @fluentui/react-theme to v9.1.6 ([PR #27213](https://github.com/microsoft/fluentui/pull/27213) by beachball)
|
|
21
|
+
|
|
22
|
+
## [9.1.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-table_v9.1.2)
|
|
23
|
+
|
|
24
|
+
Mon, 13 Mar 2023 08:58:26 GMT
|
|
25
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-table_v9.1.1..@fluentui/react-table_v9.1.2)
|
|
26
|
+
|
|
27
|
+
### Patches
|
|
28
|
+
|
|
29
|
+
- Bump @fluentui/react-aria to v9.3.13 ([PR #27161](https://github.com/microsoft/fluentui/pull/27161) by beachball)
|
|
30
|
+
- Bump @fluentui/react-avatar to v9.4.2 ([PR #27161](https://github.com/microsoft/fluentui/pull/27161) by beachball)
|
|
31
|
+
- Bump @fluentui/react-checkbox to v9.1.2 ([PR #27161](https://github.com/microsoft/fluentui/pull/27161) by beachball)
|
|
32
|
+
- Bump @fluentui/react-context-selector to v9.1.13 ([PR #27161](https://github.com/microsoft/fluentui/pull/27161) by beachball)
|
|
33
|
+
- Bump @fluentui/react-radio to v9.1.2 ([PR #27161](https://github.com/microsoft/fluentui/pull/27161) by beachball)
|
|
34
|
+
- Bump @fluentui/react-tabster to v9.5.6 ([PR #27161](https://github.com/microsoft/fluentui/pull/27161) by beachball)
|
|
35
|
+
- Bump @fluentui/react-utilities to v9.7.0 ([PR #27161](https://github.com/microsoft/fluentui/pull/27161) by beachball)
|
|
36
|
+
|
|
7
37
|
## [9.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-table_v9.1.1)
|
|
8
38
|
|
|
9
|
-
Fri, 10 Mar 2023 07:
|
|
39
|
+
Fri, 10 Mar 2023 07:14:01 GMT
|
|
10
40
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-table_v9.1.0..@fluentui/react-table_v9.1.1)
|
|
11
41
|
|
|
12
42
|
### Patches
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { ReactNode } from 'react';
|
|
|
13
13
|
import type { Slot } from '@fluentui/react-utilities';
|
|
14
14
|
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
15
15
|
|
|
16
|
-
export declare type CellRenderFunction<TItem = unknown> = (column: TableColumnDefinition<TItem
|
|
16
|
+
export declare type CellRenderFunction<TItem = unknown> = (column: TableColumnDefinition<TItem>, dataGridContextValue: DataGridContextValue) => React_2.ReactNode;
|
|
17
17
|
|
|
18
18
|
declare type ColumnSizingTableCellProps = Pick<TableHeaderCellProps, 'style'>;
|
|
19
19
|
|
|
@@ -185,7 +185,7 @@ export declare type DataGridProps = TableProps & Pick<DataGridContextValue, 'ite
|
|
|
185
185
|
/**
|
|
186
186
|
* A callback triggered when a column is resized.
|
|
187
187
|
*/
|
|
188
|
-
onColumnResize?: (e: TouchEvent | MouseEvent | undefined, data: {
|
|
188
|
+
onColumnResize?: (e: KeyboardEvent | TouchEvent | MouseEvent | undefined, data: {
|
|
189
189
|
columnId: TableColumnId;
|
|
190
190
|
width: number;
|
|
191
191
|
}) => void;
|
|
@@ -219,6 +219,7 @@ export declare type DataGridRowSlots = TableRowSlots & {
|
|
|
219
219
|
export declare type DataGridRowState = TableRowState & ComponentState<DataGridRowSlots> & {
|
|
220
220
|
renderCell: CellRenderFunction;
|
|
221
221
|
columnDefs: TableColumnDefinition<any>[];
|
|
222
|
+
dataGridContextValue: DataGridContextValue;
|
|
222
223
|
};
|
|
223
224
|
|
|
224
225
|
/**
|
|
@@ -249,6 +250,8 @@ export declare type DataGridState = TableState & {
|
|
|
249
250
|
tableState: TableFeaturesState<unknown>;
|
|
250
251
|
} & Pick<DataGridContextValue, 'focusMode' | 'selectableRows' | 'subtleSelection' | 'selectionAppearance' | 'getRowId' | 'resizableColumns'>;
|
|
251
252
|
|
|
253
|
+
declare type EnableKeyboardModeOnChangeCallback = (columnId: TableColumnId, isKeyboardMode: boolean) => void;
|
|
254
|
+
|
|
252
255
|
declare interface OnSelectionChangeData {
|
|
253
256
|
selectedItems: Set<TableRowId>;
|
|
254
257
|
}
|
|
@@ -507,6 +510,7 @@ declare interface TableColumnSizingState {
|
|
|
507
510
|
getColumnWidths: () => ColumnWidthState[];
|
|
508
511
|
getTableHeaderCellProps: (columnId: TableColumnId) => ColumnSizingTableHeaderCellProps;
|
|
509
512
|
getTableCellProps: (columnId: TableColumnId) => ColumnSizingTableCellProps;
|
|
513
|
+
enableKeyboardMode: (columnId: TableColumnId, onChange?: EnableKeyboardModeOnChangeCallback) => (e: React_2.MouseEvent | React_2.TouchEvent) => void;
|
|
510
514
|
}
|
|
511
515
|
|
|
512
516
|
export declare const TableContextProvider: React_2.Provider<TableContextValue | undefined>;
|
|
@@ -1016,7 +1020,7 @@ export declare function useTableColumnSizing_unstable<TItem>(params?: UseTableCo
|
|
|
1016
1020
|
|
|
1017
1021
|
declare type UseTableColumnSizingParams = {
|
|
1018
1022
|
columnSizingOptions?: TableColumnSizingOptions;
|
|
1019
|
-
onColumnResize?: (e: TouchEvent | MouseEvent | undefined, data: {
|
|
1023
|
+
onColumnResize?: (e: KeyboardEvent | TouchEvent | MouseEvent | undefined, data: {
|
|
1020
1024
|
columnId: TableColumnId;
|
|
1021
1025
|
width: number;
|
|
1022
1026
|
}) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGrid.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { TableContextValues, TableProps, TableSlots, TableState } from '../Table/Table.types';\nimport type {\n SortState,\n TableFeaturesState,\n UseTableSortOptions,\n SelectionMode,\n UseTableSelectionOptions,\n OnSelectionChangeData,\n TableColumnSizingOptions,\n TableColumnId,\n} from '../../hooks';\nimport { TableRowProps } from '../TableRow/TableRow.types';\n\nexport type DataGridSlots = TableSlots;\n\nexport type DataGridFocusMode = 'none' | 'cell' | 'row_unstable';\n\nexport type DataGridContextValues = TableContextValues & {\n dataGrid: DataGridContextValue;\n};\n\n// Use any here since we can't know the user types\n// The user is responsible for narrowing the type downstream\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DataGridContextValue = TableFeaturesState<any> & {\n /**\n * How focus navigation will work in the datagrid\n * @default cell\n */\n focusMode: DataGridFocusMode;\n\n /**\n * Lets child components know if rows selection is enabled\n * @see selectionMode prop enables row selection on the component\n */\n selectableRows: boolean;\n\n /**\n * Enables subtle selection style\n * @default false\n */\n subtleSelection: boolean;\n\n /**\n * Row appearance when selected\n * @default brand\n */\n selectionAppearance: TableRowProps['appearance'];\n\n /**\n * Enables column resizing\n */\n resizableColumns?: boolean;\n};\n\n/**\n * DataGrid Props\n */\nexport type DataGridProps = TableProps &\n Pick<DataGridContextValue, 'items' | 'columns' | 'getRowId'> &\n Pick<Partial<DataGridContextValue>, 'focusMode' | 'subtleSelection' | 'selectionAppearance' | 'resizableColumns'> &\n Pick<UseTableSortOptions, 'sortState' | 'defaultSortState'> &\n Pick<UseTableSelectionOptions, 'defaultSelectedItems' | 'selectedItems'> & {\n onSortChange?: (e: React.MouseEvent, sortState: SortState) => void;\n onSelectionChange?: (e: React.MouseEvent | React.KeyboardEvent, data: OnSelectionChangeData) => void;\n /**\n * Enables row selection and sets the selection mode\n * @default false\n */\n selectionMode?: SelectionMode;\n /**\n * Options for column resizing\n */\n columnSizingOptions?: TableColumnSizingOptions;\n /**\n * A callback triggered when a column is resized.\n */\n onColumnResize?: (e: TouchEvent | MouseEvent | undefined
|
|
1
|
+
{"version":3,"file":"DataGrid.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { TableContextValues, TableProps, TableSlots, TableState } from '../Table/Table.types';\nimport type {\n SortState,\n TableFeaturesState,\n UseTableSortOptions,\n SelectionMode,\n UseTableSelectionOptions,\n OnSelectionChangeData,\n TableColumnSizingOptions,\n TableColumnId,\n} from '../../hooks';\nimport { TableRowProps } from '../TableRow/TableRow.types';\n\nexport type DataGridSlots = TableSlots;\n\nexport type DataGridFocusMode = 'none' | 'cell' | 'row_unstable';\n\nexport type DataGridContextValues = TableContextValues & {\n dataGrid: DataGridContextValue;\n};\n\n// Use any here since we can't know the user types\n// The user is responsible for narrowing the type downstream\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DataGridContextValue = TableFeaturesState<any> & {\n /**\n * How focus navigation will work in the datagrid\n * @default cell\n */\n focusMode: DataGridFocusMode;\n\n /**\n * Lets child components know if rows selection is enabled\n * @see selectionMode prop enables row selection on the component\n */\n selectableRows: boolean;\n\n /**\n * Enables subtle selection style\n * @default false\n */\n subtleSelection: boolean;\n\n /**\n * Row appearance when selected\n * @default brand\n */\n selectionAppearance: TableRowProps['appearance'];\n\n /**\n * Enables column resizing\n */\n resizableColumns?: boolean;\n};\n\n/**\n * DataGrid Props\n */\nexport type DataGridProps = TableProps &\n Pick<DataGridContextValue, 'items' | 'columns' | 'getRowId'> &\n Pick<Partial<DataGridContextValue>, 'focusMode' | 'subtleSelection' | 'selectionAppearance' | 'resizableColumns'> &\n Pick<UseTableSortOptions, 'sortState' | 'defaultSortState'> &\n Pick<UseTableSelectionOptions, 'defaultSelectedItems' | 'selectedItems'> & {\n onSortChange?: (e: React.MouseEvent, sortState: SortState) => void;\n onSelectionChange?: (e: React.MouseEvent | React.KeyboardEvent, data: OnSelectionChangeData) => void;\n /**\n * Enables row selection and sets the selection mode\n * @default false\n */\n selectionMode?: SelectionMode;\n /**\n * Options for column resizing\n */\n columnSizingOptions?: TableColumnSizingOptions;\n /**\n * A callback triggered when a column is resized.\n */\n onColumnResize?: (\n e: KeyboardEvent | TouchEvent | MouseEvent | undefined,\n data: { columnId: TableColumnId; width: number },\n ) => void;\n };\n\n/**\n * State used in rendering DataGrid\n */\nexport type DataGridState = TableState & { tableState: TableFeaturesState<unknown> } & Pick<\n DataGridContextValue,\n 'focusMode' | 'selectableRows' | 'subtleSelection' | 'selectionAppearance' | 'getRowId' | 'resizableColumns'\n >;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useArrowNavigationGroup","useFocusFinders","useTable_unstable","useTableFeatures","useTableSort","useTableSelection","useTableColumnSizing_unstable","CELL_WIDTH","useEventCallback","useMergedRefs","End","Home","useDataGrid_unstable","props","ref","items","columns","focusMode","selectionMode","onSortChange","onSelectionChange","defaultSortState","sortState","selectedItems","defaultSelectedItems","subtleSelection","selectionAppearance","getRowId","resizableColumns","columnSizingOptions","onColumnResize","navigable","keyboardNavAttr","axis","tableState","containerWidthOffset","innerRef","useRef","findFirstFocusable","findLastFocusable","onKeyDown","e","_a","call","current","ctrlKey","defaultPrevented","key","firstRow","querySelector","_b","focus","rows","querySelectorAll","length","lastRow","item","_c","baseTableState","role","as","noNativeElements","tableRef","selectableRows"],"sources":["../src/packages/react-components/react-table/src/components/DataGrid/useDataGrid.ts"],"sourcesContent":["import * as React from 'react';\nimport { useArrowNavigationGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport type { DataGridProps, DataGridState } from './DataGrid.types';\nimport { useTable_unstable } from '../Table/useTable';\nimport { useTableFeatures, useTableSort, useTableSelection, useTableColumnSizing_unstable } from '../../hooks';\nimport { CELL_WIDTH } from '../TableSelectionCell';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { End, Home } from '@fluentui/keyboard-keys';\n\n/**\n * Create the state required to render DataGrid.\n *\n * The returned state can be modified with hooks such as useDataGridStyles_unstable,\n * before being passed to renderDataGrid_unstable.\n *\n * @param props - props from this instance of DataGrid\n * @param ref - reference to root HTMLElement of DataGrid\n */\nexport const useDataGrid_unstable = (props: DataGridProps, ref: React.Ref<HTMLElement>): DataGridState => {\n const {\n items,\n columns,\n focusMode = 'cell',\n selectionMode,\n onSortChange,\n onSelectionChange,\n defaultSortState,\n sortState,\n selectedItems,\n defaultSelectedItems,\n subtleSelection = false,\n selectionAppearance = 'brand',\n getRowId,\n resizableColumns,\n columnSizingOptions,\n onColumnResize,\n } = props;\n\n const navigable = focusMode !== 'none';\n const keyboardNavAttr = useArrowNavigationGroup({
|
|
1
|
+
{"version":3,"names":["React","useArrowNavigationGroup","useFocusFinders","useTable_unstable","useTableFeatures","useTableSort","useTableSelection","useTableColumnSizing_unstable","CELL_WIDTH","useEventCallback","useMergedRefs","End","Home","useDataGrid_unstable","props","ref","items","columns","focusMode","selectionMode","onSortChange","onSelectionChange","defaultSortState","sortState","selectedItems","defaultSelectedItems","subtleSelection","selectionAppearance","getRowId","resizableColumns","columnSizingOptions","onColumnResize","navigable","keyboardNavAttr","axis","tableState","containerWidthOffset","innerRef","useRef","findFirstFocusable","findLastFocusable","onKeyDown","e","_a","call","current","ctrlKey","defaultPrevented","key","firstRow","querySelector","_b","focus","rows","querySelectorAll","length","lastRow","item","_c","baseTableState","role","as","noNativeElements","tableRef","selectableRows"],"sources":["../src/packages/react-components/react-table/src/components/DataGrid/useDataGrid.ts"],"sourcesContent":["import * as React from 'react';\nimport { useArrowNavigationGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport type { DataGridProps, DataGridState } from './DataGrid.types';\nimport { useTable_unstable } from '../Table/useTable';\nimport { useTableFeatures, useTableSort, useTableSelection, useTableColumnSizing_unstable } from '../../hooks';\nimport { CELL_WIDTH } from '../TableSelectionCell';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { End, Home } from '@fluentui/keyboard-keys';\n\n/**\n * Create the state required to render DataGrid.\n *\n * The returned state can be modified with hooks such as useDataGridStyles_unstable,\n * before being passed to renderDataGrid_unstable.\n *\n * @param props - props from this instance of DataGrid\n * @param ref - reference to root HTMLElement of DataGrid\n */\nexport const useDataGrid_unstable = (props: DataGridProps, ref: React.Ref<HTMLElement>): DataGridState => {\n const {\n items,\n columns,\n focusMode = 'cell',\n selectionMode,\n onSortChange,\n onSelectionChange,\n defaultSortState,\n sortState,\n selectedItems,\n defaultSelectedItems,\n subtleSelection = false,\n selectionAppearance = 'brand',\n getRowId,\n resizableColumns,\n columnSizingOptions,\n onColumnResize,\n } = props;\n\n const navigable = focusMode !== 'none';\n const keyboardNavAttr = useArrowNavigationGroup({\n axis: 'grid',\n });\n\n const tableState = useTableFeatures({ items, columns, getRowId }, [\n useTableSort({\n defaultSortState,\n sortState,\n onSortChange,\n }),\n useTableSelection({\n defaultSelectedItems,\n selectedItems,\n onSelectionChange,\n selectionMode: selectionMode ?? 'multiselect',\n }),\n useTableColumnSizing_unstable({\n onColumnResize,\n columnSizingOptions,\n // The selection cell is not part of the columns, therefore its width needs to be subtracted\n // from the container to make sure the columns don't overflow the table.\n containerWidthOffset: selectionMode ? -CELL_WIDTH : 0,\n }),\n ]);\n\n const innerRef = React.useRef<HTMLDivElement>(null);\n const { findFirstFocusable, findLastFocusable } = useFocusFinders();\n const onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLTableElement>) => {\n props.onKeyDown?.(e);\n if (!innerRef.current || !e.ctrlKey || e.defaultPrevented) {\n return;\n }\n\n if (e.key === Home) {\n const firstRow = innerRef.current.querySelector('[role=\"row\"]') as HTMLElement | null;\n if (firstRow) {\n findFirstFocusable(firstRow)?.focus();\n }\n }\n\n if (e.key === End) {\n const rows = innerRef.current.querySelectorAll('[role=\"row\"]');\n if (rows.length) {\n const lastRow = rows.item(rows.length - 1);\n findLastFocusable(lastRow as HTMLElement)?.focus();\n }\n }\n });\n\n const baseTableState = useTable_unstable(\n {\n role: 'grid',\n as: 'div',\n noNativeElements: true,\n ...(navigable && keyboardNavAttr),\n ...props,\n onKeyDown,\n },\n useMergedRefs(ref, tableState.tableRef, innerRef),\n );\n\n return {\n ...baseTableState,\n focusMode,\n tableState,\n selectableRows: !!selectionMode,\n subtleSelection,\n selectionAppearance,\n resizableColumns,\n };\n};\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,uBAAuB,EAAEC,eAAe,QAAQ,yBAAyB;AAElF,SAASC,iBAAiB,QAAQ,mBAAmB;AACrD,SAASC,gBAAgB,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,6BAA6B,QAAQ,aAAa;AAC9G,SAASC,UAAU,QAAQ,uBAAuB;AAClD,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,2BAA2B;AAC3E,SAASC,GAAG,EAAEC,IAAI,QAAQ,yB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
1
|
-
{"version":3,"file":"DataGridRow.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-table/src/components/DataGridRow/DataGridRow.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type {
|
|
1
|
+
{"version":3,"file":"DataGridRow.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-table/src/components/DataGridRow/DataGridRow.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { TableColumnDefinition } from '../../hooks';\nimport { DataGridContextValue } from '../DataGrid/DataGrid.types';\nimport type { TableRowProps, TableRowSlots, TableRowState } from '../TableRow/TableRow.types';\nimport type { TableSelectionCell } from '../TableSelectionCell/TableSelectionCell';\n\nexport type DataGridRowSlots = TableRowSlots & {\n /**\n * When selection is enabled on the @see DataGrid, all rows\n * will render the selection cell.\n */\n selectionCell?: Slot<typeof TableSelectionCell>;\n};\n\nexport type CellRenderFunction<TItem = unknown> = (\n column: TableColumnDefinition<TItem>,\n dataGridContextValue: DataGridContextValue,\n) => React.ReactNode;\n\n/**\n * DataGridRow Props\n */\nexport type DataGridRowProps<TItem = unknown> = Omit<TableRowProps, 'children'> &\n Omit<ComponentProps<DataGridRowSlots>, 'children'> & {\n children: CellRenderFunction<TItem>;\n };\n\n/**\n * State used in rendering DataGridRow\n */\nexport type DataGridRowState = TableRowState &\n ComponentState<DataGridRowSlots> & {\n renderCell: CellRenderFunction;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n columnDefs: TableColumnDefinition<any>[];\n dataGridContextValue: DataGridContextValue;\n };\n"]}
|
|
@@ -16,6 +16,6 @@ export const renderDataGridRow_unstable = state => {
|
|
|
16
16
|
}), state.columnDefs.map(columnDef => /*#__PURE__*/React.createElement(ColumnIdContextProvider, {
|
|
17
17
|
value: columnDef.columnId,
|
|
18
18
|
key: columnDef.columnId
|
|
19
|
-
}, state.renderCell(columnDef))));
|
|
19
|
+
}, state.renderCell(columnDef, state.dataGridContextValue))));
|
|
20
20
|
};
|
|
21
21
|
//# sourceMappingURL=renderDataGridRow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","getSlots","ColumnIdContextProvider","renderDataGridRow_unstable","state","slots","slotProps","createElement","root","selectionCell","columnDefs","map","columnDef","value","columnId","key","renderCell"],"sources":["../src/packages/react-components/react-table/src/components/DataGridRow/renderDataGridRow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { DataGridRowState, DataGridRowSlots } from './DataGridRow.types';\nimport { ColumnIdContextProvider } from '../../contexts/columnIdContext';\n\n/**\n * Render the final JSX of DataGridRow\n */\nexport const renderDataGridRow_unstable = (state: DataGridRowState) => {\n const { slots, slotProps } = getSlots<DataGridRowSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.selectionCell && <slots.selectionCell {...slotProps.selectionCell} />}\n {state.columnDefs.map(columnDef => (\n <ColumnIdContextProvider value={columnDef.columnId} key={columnDef.columnId}>\n {state.renderCell(columnDef)}\n </ColumnIdContextProvider>\n ))}\n </slots.root>\n );\n};\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAEpD,SAASC,uBAAuB,QAAQ,gCAAgC;AAExE;;;AAGA,OAAO,MAAMC,0BAA0B,GAAIC,KAAuB,IAAI;EACpE,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGL,QAAQ,CAAmBG,KAAK,CAAC;EAE9D,oBACEJ,KAAA,CAAAO,aAAA,CAACF,KAAK,CAACG,IAAI;IAAA,GAAKF,SAAS,CAACE;EAAI,GAC3BH,KAAK,CAACI,aAAa,iBAAIT,KAAA,CAAAO,aAAA,CAACF,KAAK,CAACI,aAAa;IAAA,GAAKH,SAAS,CAACG;EAAa,EAAI,EAC3EL,KAAK,CAACM,UAAU,CAACC,GAAG,CAACC,SAAS,iBAC7BZ,KAAA,CAAAO,aAAA,CAACL,uBAAuB;IAACW,KAAK,EAAED,SAAS,CAACE,QAAQ;IAAEC,GAAG,EAAEH,SAAS,CAACE;EAAQ,GACxEV,KAAK,CAACY,UAAU,CAACJ,SAAS,CAAC,
|
|
1
|
+
{"version":3,"names":["React","getSlots","ColumnIdContextProvider","renderDataGridRow_unstable","state","slots","slotProps","createElement","root","selectionCell","columnDefs","map","columnDef","value","columnId","key","renderCell","dataGridContextValue"],"sources":["../src/packages/react-components/react-table/src/components/DataGridRow/renderDataGridRow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { DataGridRowState, DataGridRowSlots } from './DataGridRow.types';\nimport { ColumnIdContextProvider } from '../../contexts/columnIdContext';\n\n/**\n * Render the final JSX of DataGridRow\n */\nexport const renderDataGridRow_unstable = (state: DataGridRowState) => {\n const { slots, slotProps } = getSlots<DataGridRowSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.selectionCell && <slots.selectionCell {...slotProps.selectionCell} />}\n {state.columnDefs.map(columnDef => (\n <ColumnIdContextProvider value={columnDef.columnId} key={columnDef.columnId}>\n {state.renderCell(columnDef, state.dataGridContextValue)}\n </ColumnIdContextProvider>\n ))}\n </slots.root>\n );\n};\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAEpD,SAASC,uBAAuB,QAAQ,gCAAgC;AAExE;;;AAGA,OAAO,MAAMC,0BAA0B,GAAIC,KAAuB,IAAI;EACpE,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGL,QAAQ,CAAmBG,KAAK,CAAC;EAE9D,oBACEJ,KAAA,CAAAO,aAAA,CAACF,KAAK,CAACG,IAAI;IAAA,GAAKF,SAAS,CAACE;EAAI,GAC3BH,KAAK,CAACI,aAAa,iBAAIT,KAAA,CAAAO,aAAA,CAACF,KAAK,CAACI,aAAa;IAAA,GAAKH,SAAS,CAACG;EAAa,EAAI,EAC3EL,KAAK,CAACM,UAAU,CAACC,GAAG,CAACC,SAAS,iBAC7BZ,KAAA,CAAAO,aAAA,CAACL,uBAAuB;IAACW,KAAK,EAAED,SAAS,CAACE,QAAQ;IAAEC,GAAG,EAAEH,SAAS,CAACE;EAAQ,GACxEV,KAAK,CAACY,UAAU,CAACJ,SAAS,EAAER,KAAK,CAACa,oBAAoB,CAAC,CAE3D,CAAC,CACS;AAEjB,CAAC"}
|
|
@@ -28,6 +28,7 @@ export const useDataGridRow_unstable = (props, ref) => {
|
|
|
28
28
|
return 'none';
|
|
29
29
|
});
|
|
30
30
|
const toggleRow = useDataGridContext_unstable(ctx => ctx.selection.toggleRow);
|
|
31
|
+
const dataGridContextValue = useDataGridContext_unstable(ctx => ctx);
|
|
31
32
|
const onClick = useEventCallback(e => {
|
|
32
33
|
var _a;
|
|
33
34
|
if (selectable && !isHeader) {
|
|
@@ -64,7 +65,8 @@ export const useDataGridRow_unstable = (props, ref) => {
|
|
|
64
65
|
required: selectable
|
|
65
66
|
}),
|
|
66
67
|
renderCell: props.children,
|
|
67
|
-
columnDefs
|
|
68
|
+
columnDefs,
|
|
69
|
+
dataGridContextValue
|
|
68
70
|
};
|
|
69
71
|
};
|
|
70
72
|
//# sourceMappingURL=useDataGridRow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isInteractiveHTMLElement","useEventCallback","resolveShorthand","Space","useTableRow_unstable","useDataGridContext_unstable","DataGridSelectionCell","useTableRowIdContext","useIsInTableHeader","useDataGridRow_unstable","props","ref","rowId","isHeader","columnDefs","ctx","columns","selectable","selectableRows","selected","selection","isRowSelected","tabbable","focusMode","appearance","selectionAppearance","toggleRow","onClick","e","_a","call","onKeyDown","key","target","preventDefault","baseState","undefined","children","as","tabIndex","components","selectionCell","required","renderCell"],"sources":["../src/packages/react-components/react-table/src/components/DataGridRow/useDataGridRow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { isInteractiveHTMLElement, useEventCallback, resolveShorthand } from '@fluentui/react-utilities';\nimport { Space } from '@fluentui/keyboard-keys';\nimport type { DataGridRowProps, DataGridRowState } from './DataGridRow.types';\nimport { useTableRow_unstable } from '../TableRow/useTableRow';\nimport { useDataGridContext_unstable } from '../../contexts/dataGridContext';\nimport { DataGridSelectionCell } from '../DataGridSelectionCell/DataGridSelectionCell';\nimport { useTableRowIdContext } from '../../contexts/rowIdContext';\nimport { useIsInTableHeader } from '../../contexts/tableHeaderContext';\n\n/**\n * Create the state required to render DataGridRow.\n *\n * The returned state can be modified with hooks such as useDataGridRowStyles_unstable,\n * before being passed to renderDataGridRow_unstable.\n *\n * @param props - props from this instance of DataGridRow\n * @param ref - reference to root HTMLElement of DataGridRow\n */\nexport const useDataGridRow_unstable = (props: DataGridRowProps, ref: React.Ref<HTMLElement>): DataGridRowState => {\n const rowId = useTableRowIdContext();\n const isHeader = useIsInTableHeader();\n const columnDefs = useDataGridContext_unstable(ctx => ctx.columns);\n const selectable = useDataGridContext_unstable(ctx => ctx.selectableRows);\n const selected = useDataGridContext_unstable(ctx => ctx.selection.isRowSelected(rowId));\n const tabbable = useDataGridContext_unstable(ctx => ctx.focusMode === 'row_unstable');\n const appearance = useDataGridContext_unstable(ctx => {\n if (!isHeader && selectable && ctx.selection.isRowSelected(rowId)) {\n return ctx.selectionAppearance;\n }\n\n return 'none';\n });\n const toggleRow = useDataGridContext_unstable(ctx => ctx.selection.toggleRow);\n\n const onClick = useEventCallback((e: React.MouseEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader) {\n toggleRow(e, rowId);\n }\n\n props.onClick?.(e);\n });\n\n const onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader && e.key === Space && !isInteractiveHTMLElement(e.target as HTMLElement)) {\n // stop scrolling\n e.preventDefault();\n toggleRow(e, rowId);\n }\n\n props.onKeyDown?.(e);\n });\n\n const baseState = useTableRow_unstable(\n {\n appearance,\n 'aria-selected': selectable ? selected : undefined,\n ...props,\n onClick,\n onKeyDown,\n children: null,\n as: 'div',\n tabIndex: tabbable && !isHeader ? 0 : undefined,\n },\n ref,\n );\n\n return {\n ...baseState,\n components: {\n ...baseState.components,\n selectionCell: DataGridSelectionCell,\n },\n selectionCell: resolveShorthand(props.selectionCell, { required: selectable }),\n renderCell: props.children,\n columnDefs,\n };\n};\n"],"mappings":"AACA,SAASA,wBAAwB,EAAEC,gBAAgB,EAAEC,gBAAgB,QAAQ,2BAA2B;AACxG,SAASC,KAAK,QAAQ,yBAAyB;AAE/C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,2BAA2B,QAAQ,gCAAgC;AAC5E,SAASC,qBAAqB,QAAQ,gDAAgD;AACtF,SAASC,oBAAoB,QAAQ,6BAA6B;AAClE,SAASC,kBAAkB,QAAQ,mCAAmC;AAEtE;;;;;;;;;AASA,OAAO,MAAMC,uBAAuB,GAAGA,CAACC,KAAuB,EAAEC,GAA2B,KAAsB;EAChH,MAAMC,KAAK,GAAGL,oBAAoB,EAAE;EACpC,MAAMM,QAAQ,GAAGL,kBAAkB,EAAE;EACrC,MAAMM,UAAU,GAAGT,2BAA2B,CAACU,GAAG,IAAIA,GAAG,CAACC,OAAO,CAAC;EAClE,MAAMC,UAAU,GAAGZ,2BAA2B,CAACU,GAAG,IAAIA,GAAG,CAACG,cAAc,CAAC;EACzE,MAAMC,QAAQ,GAAGd,2BAA2B,CAACU,GAAG,IAAIA,GAAG,CAACK,SAAS,CAACC,aAAa,CAACT,KAAK,CAAC,CAAC;EACvF,MAAMU,QAAQ,GAAGjB,2BAA2B,CAACU,GAAG,IAAIA,GAAG,CAACQ,SAAS,KAAK,cAAc,CAAC;EACrF,MAAMC,UAAU,GAAGnB,2BAA2B,CAACU,GAAG,IAAG;IACnD,IAAI,CAACF,QAAQ,IAAII,UAAU,IAAIF,GAAG,CAACK,SAAS,CAACC,aAAa,CAACT,KAAK,CAAC,EAAE;MACjE,OAAOG,GAAG,CAACU,mBAAmB;;IAGhC,OAAO,MAAM;EACf,CAAC,CAAC;EACF,MAAMC,SAAS,GAAGrB,2BAA2B,CAACU,GAAG,IAAIA,GAAG,CAACK,SAAS,CAACM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"names":["isInteractiveHTMLElement","useEventCallback","resolveShorthand","Space","useTableRow_unstable","useDataGridContext_unstable","DataGridSelectionCell","useTableRowIdContext","useIsInTableHeader","useDataGridRow_unstable","props","ref","rowId","isHeader","columnDefs","ctx","columns","selectable","selectableRows","selected","selection","isRowSelected","tabbable","focusMode","appearance","selectionAppearance","toggleRow","dataGridContextValue","onClick","e","_a","call","onKeyDown","key","target","preventDefault","baseState","undefined","children","as","tabIndex","components","selectionCell","required","renderCell"],"sources":["../src/packages/react-components/react-table/src/components/DataGridRow/useDataGridRow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { isInteractiveHTMLElement, useEventCallback, resolveShorthand } from '@fluentui/react-utilities';\nimport { Space } from '@fluentui/keyboard-keys';\nimport type { DataGridRowProps, DataGridRowState } from './DataGridRow.types';\nimport { useTableRow_unstable } from '../TableRow/useTableRow';\nimport { useDataGridContext_unstable } from '../../contexts/dataGridContext';\nimport { DataGridSelectionCell } from '../DataGridSelectionCell/DataGridSelectionCell';\nimport { useTableRowIdContext } from '../../contexts/rowIdContext';\nimport { useIsInTableHeader } from '../../contexts/tableHeaderContext';\n\n/**\n * Create the state required to render DataGridRow.\n *\n * The returned state can be modified with hooks such as useDataGridRowStyles_unstable,\n * before being passed to renderDataGridRow_unstable.\n *\n * @param props - props from this instance of DataGridRow\n * @param ref - reference to root HTMLElement of DataGridRow\n */\nexport const useDataGridRow_unstable = (props: DataGridRowProps, ref: React.Ref<HTMLElement>): DataGridRowState => {\n const rowId = useTableRowIdContext();\n const isHeader = useIsInTableHeader();\n const columnDefs = useDataGridContext_unstable(ctx => ctx.columns);\n const selectable = useDataGridContext_unstable(ctx => ctx.selectableRows);\n const selected = useDataGridContext_unstable(ctx => ctx.selection.isRowSelected(rowId));\n const tabbable = useDataGridContext_unstable(ctx => ctx.focusMode === 'row_unstable');\n const appearance = useDataGridContext_unstable(ctx => {\n if (!isHeader && selectable && ctx.selection.isRowSelected(rowId)) {\n return ctx.selectionAppearance;\n }\n\n return 'none';\n });\n const toggleRow = useDataGridContext_unstable(ctx => ctx.selection.toggleRow);\n const dataGridContextValue = useDataGridContext_unstable(ctx => ctx);\n\n const onClick = useEventCallback((e: React.MouseEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader) {\n toggleRow(e, rowId);\n }\n\n props.onClick?.(e);\n });\n\n const onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader && e.key === Space && !isInteractiveHTMLElement(e.target as HTMLElement)) {\n // stop scrolling\n e.preventDefault();\n toggleRow(e, rowId);\n }\n\n props.onKeyDown?.(e);\n });\n\n const baseState = useTableRow_unstable(\n {\n appearance,\n 'aria-selected': selectable ? selected : undefined,\n ...props,\n onClick,\n onKeyDown,\n children: null,\n as: 'div',\n tabIndex: tabbable && !isHeader ? 0 : undefined,\n },\n ref,\n );\n\n return {\n ...baseState,\n components: {\n ...baseState.components,\n selectionCell: DataGridSelectionCell,\n },\n selectionCell: resolveShorthand(props.selectionCell, { required: selectable }),\n renderCell: props.children,\n columnDefs,\n dataGridContextValue,\n };\n};\n"],"mappings":"AACA,SAASA,wBAAwB,EAAEC,gBAAgB,EAAEC,gBAAgB,QAAQ,2BAA2B;AACxG,SAASC,KAAK,QAAQ,yBAAyB;AAE/C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,2BAA2B,QAAQ,gCAAgC;AAC5E,SAASC,qBAAqB,QAAQ,gDAAgD;AACtF,SAASC,oBAAoB,QAAQ,6BAA6B;AAClE,SAASC,kBAAkB,QAAQ,mCAAmC;AAEtE;;;;;;;;;AASA,OAAO,MAAMC,uBAAuB,GAAGA,CAACC,KAAuB,EAAEC,GAA2B,KAAsB;EAChH,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AAC,CAACI,GAAG,KAAK9B,KAAK,IAAI,CAACH,wBAAwB,CAAC6B,CAAC,CAACK,MAAqB,CAAC,EAAE;MACpG;MACAL,CAAC,CAACM,cAAc,EAAE;MAClBT,SAAS,CAACG,CAAC,EAAEjB,KAAK,CAAC;;IAGrB,CAAAkB,EAAA,GAAApB,KAAK,CAACsB,SAAS,cAAAF,EAAA,uBAAAA,EAAA,CAAAC,IAAA,CAAfrB,KAAK,EAAamB,CAAC,CAAC;EACtB,CAAC,CAAC;EAEF,MAAMO,SAAS,GAAGhC,oBAAoB,CACpC;IACEoB,UAAU;IACV,eAAe,EAAEP,UAAU,GAAGE,QAAQ,GAAGkB,SAAS;IAClD,GAAG3B,KAAK;IACRkB,OAAO;IACPI,SAAS;IACTM,QAAQ,EAAE,IAAI;IACdC,EAAE,EAAE,KAAK;IACTC,QAAQ,EAAElB,QAAQ,IAAI,CAACT,QAAQ,GAAG,CAAC,GAAGwB;GACvC,EACD1B,GAAG,CACJ;EAED,OAAO;IACL,GAAGyB,SAAS;IACZK,UAAU,EAAE;MACV,GAAGL,SAAS,CAACK,UAAU;MACvBC,aAAa,EAAEpC;KAChB;IACDoC,aAAa,EAAExC,gBAAgB,CAACQ,KAAK,CAACgC,aAAa,EAAE;MAAEC,QAAQ,EAAE1B;IAAU,CAAE,CAAC;IAC9E2B,UAAU,EAAElC,KAAK,CAAC4B,QAAQ;IAC1BxB,UAAU;IACVa;GACD;AACH,CAAC"}
|
package/lib/hooks/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["packages/react-components/react-table/src/hooks/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { SortDirection } from '../components/Table/Table.types';\nimport { TableHeaderCellProps } from '../components/TableHeaderCell/TableHeaderCell.types';\n\nexport type TableRowId = string | number;\nexport type TableColumnId = string | number;\nexport type SelectionMode = 'single' | 'multiselect';\n\nexport interface SortState {\n sortColumn: TableColumnId | undefined;\n sortDirection: SortDirection;\n}\n\nexport interface OnSelectionChangeData {\n selectedItems: Set<TableRowId>;\n}\n\nexport interface CreateTableColumnOptions<TItem> extends Partial<TableColumnDefinition<TItem>> {\n columnId: TableColumnId;\n}\n\nexport interface TableColumnDefinition<TItem> {\n columnId: TableColumnId;\n compare: (a: TItem, b: TItem) => number;\n renderHeaderCell: () => React.ReactNode;\n renderCell: (item: TItem) => React.ReactNode;\n}\n\nexport type RowEnhancer<TItem, TRowState extends TableRowData<TItem> = TableRowData<TItem>> = (\n row: TableRowData<TItem>,\n) => TRowState;\n\nexport interface TableSortState<TItem> {\n /**\n * Current sort direction\n */\n sortDirection: SortDirection;\n /**\n * Column id of the currently sorted column\n */\n sortColumn: TableColumnId | undefined;\n /**\n * Set the sort direction for the specified column\n */\n setColumnSort: (event: React.SyntheticEvent, columnId: TableColumnId, sortDirection: SortDirection) => void;\n /**\n * Toggles the sort direction for specified column\n */\n toggleColumnSort: (event: React.SyntheticEvent, columnId: TableColumnId) => void;\n /**\n * Returns the sort direction if a column is sorted,\n * returns undefined if the column is not sorted\n */\n getSortDirection: (columnId: TableColumnId) => SortDirection | undefined;\n\n /**\n * Sorts rows and returns a **shallow** copy of original items\n */\n sort: <TRowState extends TableRowData<TItem>>(rows: TRowState[]) => TRowState[];\n}\n\nexport interface TableSelectionState {\n /**\n * Clears all selected rows\n */\n clearRows: (e: React.SyntheticEvent) => void;\n /**\n * Selects single row\n */\n selectRow: (e: React.SyntheticEvent, rowId: TableRowId) => void;\n /**\n * De-selects single row\n */\n deselectRow: (e: React.SyntheticEvent, rowId: TableRowId) => void;\n /**\n * Toggle selection of all rows\n */\n toggleAllRows: (e: React.SyntheticEvent) => void;\n /**\n * Toggle selection of single row\n */\n toggleRow: (e: React.SyntheticEvent, rowId: TableRowId) => void;\n /**\n * Collection of row ids corresponding to selected rows\n */\n selectedRows: Set<TableRowId>;\n /**\n * Whether all rows are selected\n */\n allRowsSelected: boolean;\n /**\n * Whether some rows are selected\n */\n someRowsSelected: boolean;\n\n /**\n * Checks if a given rowId is selected\n */\n isRowSelected: (rowId: TableRowId) => boolean;\n\n selectionMode: SelectionMode;\n}\n\nexport interface TableRowData<TItem> {\n /**\n * User provided data\n */\n item: TItem;\n /**\n * The row id, defaults to index position in the collection\n */\n rowId: TableRowId;\n}\n\nexport interface TableFeaturesState<TItem> extends Pick<UseTableFeaturesOptions<TItem>, 'items' | 'getRowId'> {\n /**\n * The row data for rendering\n * @param rowEnhancer - Enhances the row with extra user data\n */\n getRows: <TRowState extends TableRowData<TItem> = TableRowData<TItem>>(\n rowEnhancer?: RowEnhancer<TItem, TRowState>,\n ) => TRowState[];\n /**\n * State and actions to manage row selection\n */\n selection: TableSelectionState;\n /**\n * State and actions to manage row sorting\n */\n sort: TableSortState<TItem>;\n /**\n * Table columns\n */\n columns: TableColumnDefinition<TItem>[];\n /**\n * State and actions to manage column resizing\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n columnSizing_unstable: TableColumnSizingState;\n /**\n * A React.Ref object to be set as a ref for the table.\n * Used with column resizing.\n */\n tableRef: React.Ref<HTMLDivElement>;\n}\n\nexport interface UseTableSortOptions {\n /**\n * Used to control sorting\n */\n sortState?: SortState;\n /**\n * Used in uncontrolled mode to set initial sort column and direction on mount\n */\n defaultSortState?: SortState;\n /**\n * Called when sort changes\n */\n onSortChange?(e: React.SyntheticEvent, state: SortState): void;\n}\n\nexport interface UseTableSelectionOptions {\n /**\n * Can be multi or single select\n */\n selectionMode: SelectionMode;\n /**\n * Used in uncontrolled mode to set initial selected rows on mount\n */\n defaultSelectedItems?: Iterable<TableRowId>;\n /**\n * Used to control row selection\n */\n selectedItems?: Iterable<TableRowId>;\n /**\n * Called when selection changes\n */\n onSelectionChange?(e: React.SyntheticEvent, data: OnSelectionChangeData): void;\n}\n\nexport interface UseTableFeaturesOptions<TItem> {\n columns: TableColumnDefinition<TItem>[];\n items: TItem[];\n getRowId?: (item: TItem) => TableRowId;\n}\n\nexport type TableFeaturePlugin = <TItem>(tableState: TableFeaturesState<TItem>) => TableFeaturesState<TItem>;\n\nexport interface ColumnWidthState {\n columnId: TableColumnId;\n width: number;\n minWidth: number;\n idealWidth: number;\n padding: number;\n}\n\nexport type ColumnSizingTableHeaderCellProps = Pick<TableHeaderCellProps, 'style' | 'aside'>;\nexport type ColumnSizingTableCellProps = Pick<TableHeaderCellProps, 'style'>;\n\nexport interface TableColumnSizingState {\n getOnMouseDown: (columnId: TableColumnId) => (e: React.MouseEvent | React.TouchEvent) => void;\n setColumnWidth: (columnId: TableColumnId, newSize: number) => void;\n getColumnWidths: () => ColumnWidthState[];\n getTableHeaderCellProps: (columnId: TableColumnId) => ColumnSizingTableHeaderCellProps;\n getTableCellProps: (columnId: TableColumnId) => ColumnSizingTableCellProps;\n}\n\nexport type ColumnResizeState = {\n getColumnWidth: (columnId: TableColumnId) => number;\n setColumnWidth: (e: TouchEvent | MouseEvent | undefined
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["packages/react-components/react-table/src/hooks/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { SortDirection } from '../components/Table/Table.types';\nimport { TableHeaderCellProps } from '../components/TableHeaderCell/TableHeaderCell.types';\n\nexport type TableRowId = string | number;\nexport type TableColumnId = string | number;\nexport type SelectionMode = 'single' | 'multiselect';\n\nexport interface SortState {\n sortColumn: TableColumnId | undefined;\n sortDirection: SortDirection;\n}\n\nexport interface OnSelectionChangeData {\n selectedItems: Set<TableRowId>;\n}\n\nexport interface CreateTableColumnOptions<TItem> extends Partial<TableColumnDefinition<TItem>> {\n columnId: TableColumnId;\n}\n\nexport interface TableColumnDefinition<TItem> {\n columnId: TableColumnId;\n compare: (a: TItem, b: TItem) => number;\n renderHeaderCell: () => React.ReactNode;\n renderCell: (item: TItem) => React.ReactNode;\n}\n\nexport type RowEnhancer<TItem, TRowState extends TableRowData<TItem> = TableRowData<TItem>> = (\n row: TableRowData<TItem>,\n) => TRowState;\n\nexport interface TableSortState<TItem> {\n /**\n * Current sort direction\n */\n sortDirection: SortDirection;\n /**\n * Column id of the currently sorted column\n */\n sortColumn: TableColumnId | undefined;\n /**\n * Set the sort direction for the specified column\n */\n setColumnSort: (event: React.SyntheticEvent, columnId: TableColumnId, sortDirection: SortDirection) => void;\n /**\n * Toggles the sort direction for specified column\n */\n toggleColumnSort: (event: React.SyntheticEvent, columnId: TableColumnId) => void;\n /**\n * Returns the sort direction if a column is sorted,\n * returns undefined if the column is not sorted\n */\n getSortDirection: (columnId: TableColumnId) => SortDirection | undefined;\n\n /**\n * Sorts rows and returns a **shallow** copy of original items\n */\n sort: <TRowState extends TableRowData<TItem>>(rows: TRowState[]) => TRowState[];\n}\n\nexport interface TableSelectionState {\n /**\n * Clears all selected rows\n */\n clearRows: (e: React.SyntheticEvent) => void;\n /**\n * Selects single row\n */\n selectRow: (e: React.SyntheticEvent, rowId: TableRowId) => void;\n /**\n * De-selects single row\n */\n deselectRow: (e: React.SyntheticEvent, rowId: TableRowId) => void;\n /**\n * Toggle selection of all rows\n */\n toggleAllRows: (e: React.SyntheticEvent) => void;\n /**\n * Toggle selection of single row\n */\n toggleRow: (e: React.SyntheticEvent, rowId: TableRowId) => void;\n /**\n * Collection of row ids corresponding to selected rows\n */\n selectedRows: Set<TableRowId>;\n /**\n * Whether all rows are selected\n */\n allRowsSelected: boolean;\n /**\n * Whether some rows are selected\n */\n someRowsSelected: boolean;\n\n /**\n * Checks if a given rowId is selected\n */\n isRowSelected: (rowId: TableRowId) => boolean;\n\n selectionMode: SelectionMode;\n}\n\nexport interface TableRowData<TItem> {\n /**\n * User provided data\n */\n item: TItem;\n /**\n * The row id, defaults to index position in the collection\n */\n rowId: TableRowId;\n}\n\nexport interface TableFeaturesState<TItem> extends Pick<UseTableFeaturesOptions<TItem>, 'items' | 'getRowId'> {\n /**\n * The row data for rendering\n * @param rowEnhancer - Enhances the row with extra user data\n */\n getRows: <TRowState extends TableRowData<TItem> = TableRowData<TItem>>(\n rowEnhancer?: RowEnhancer<TItem, TRowState>,\n ) => TRowState[];\n /**\n * State and actions to manage row selection\n */\n selection: TableSelectionState;\n /**\n * State and actions to manage row sorting\n */\n sort: TableSortState<TItem>;\n /**\n * Table columns\n */\n columns: TableColumnDefinition<TItem>[];\n /**\n * State and actions to manage column resizing\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n columnSizing_unstable: TableColumnSizingState;\n /**\n * A React.Ref object to be set as a ref for the table.\n * Used with column resizing.\n */\n tableRef: React.Ref<HTMLDivElement>;\n}\n\nexport interface UseTableSortOptions {\n /**\n * Used to control sorting\n */\n sortState?: SortState;\n /**\n * Used in uncontrolled mode to set initial sort column and direction on mount\n */\n defaultSortState?: SortState;\n /**\n * Called when sort changes\n */\n onSortChange?(e: React.SyntheticEvent, state: SortState): void;\n}\n\nexport interface UseTableSelectionOptions {\n /**\n * Can be multi or single select\n */\n selectionMode: SelectionMode;\n /**\n * Used in uncontrolled mode to set initial selected rows on mount\n */\n defaultSelectedItems?: Iterable<TableRowId>;\n /**\n * Used to control row selection\n */\n selectedItems?: Iterable<TableRowId>;\n /**\n * Called when selection changes\n */\n onSelectionChange?(e: React.SyntheticEvent, data: OnSelectionChangeData): void;\n}\n\nexport interface UseTableFeaturesOptions<TItem> {\n columns: TableColumnDefinition<TItem>[];\n items: TItem[];\n getRowId?: (item: TItem) => TableRowId;\n}\n\nexport type TableFeaturePlugin = <TItem>(tableState: TableFeaturesState<TItem>) => TableFeaturesState<TItem>;\n\nexport interface ColumnWidthState {\n columnId: TableColumnId;\n width: number;\n minWidth: number;\n idealWidth: number;\n padding: number;\n}\n\nexport type ColumnSizingTableHeaderCellProps = Pick<TableHeaderCellProps, 'style' | 'aside'>;\nexport type ColumnSizingTableCellProps = Pick<TableHeaderCellProps, 'style'>;\n\nexport type EnableKeyboardModeOnChangeCallback = (columnId: TableColumnId, isKeyboardMode: boolean) => void;\n\nexport interface TableColumnSizingState {\n getOnMouseDown: (columnId: TableColumnId) => (e: React.MouseEvent | React.TouchEvent) => void;\n setColumnWidth: (columnId: TableColumnId, newSize: number) => void;\n getColumnWidths: () => ColumnWidthState[];\n getTableHeaderCellProps: (columnId: TableColumnId) => ColumnSizingTableHeaderCellProps;\n getTableCellProps: (columnId: TableColumnId) => ColumnSizingTableCellProps;\n enableKeyboardMode: (\n columnId: TableColumnId,\n onChange?: EnableKeyboardModeOnChangeCallback,\n ) => (e: React.MouseEvent | React.TouchEvent) => void;\n}\n\nexport type ColumnResizeState = {\n getColumnWidth: (columnId: TableColumnId) => number;\n setColumnWidth: (\n e: KeyboardEvent | TouchEvent | MouseEvent | undefined,\n data: { columnId: TableColumnId; width: number },\n ) => void;\n getColumnById: (columnId: TableColumnId) => ColumnWidthState | undefined;\n getColumns: () => ColumnWidthState[];\n};\n\nexport type TableColumnSizingOptions = Record<\n TableColumnId,\n Partial<Pick<ColumnWidthState, 'minWidth' | 'idealWidth' | 'padding'>> & { defaultWidth?: number }\n>;\n\nexport type UseTableColumnSizingParams = {\n columnSizingOptions?: TableColumnSizingOptions;\n onColumnResize?: (\n e: KeyboardEvent | TouchEvent | MouseEvent | undefined,\n data: { columnId: TableColumnId; width: number },\n ) => void;\n containerWidthOffset?: number;\n};\n"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ArrowLeft, ArrowRight, Enter, Escape, Shift, Space } from '@fluentui/keyboard-keys';
|
|
3
|
+
import { useEventCallback } from '@fluentui/react-utilities';
|
|
4
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
5
|
+
const STEP = 20;
|
|
6
|
+
const PRECISION_MODIFIER = Shift;
|
|
7
|
+
const PRECISION_FACTOR = 1 / 4;
|
|
8
|
+
export function useKeyboardResizing(columnResizeState) {
|
|
9
|
+
const columnId = React.useRef();
|
|
10
|
+
const onChangeRef = React.useRef();
|
|
11
|
+
const addListenerTimeout = React.useRef();
|
|
12
|
+
const columnResizeStateRef = React.useRef(columnResizeState);
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
columnResizeStateRef.current = columnResizeState;
|
|
15
|
+
}, [columnResizeState]);
|
|
16
|
+
const {
|
|
17
|
+
targetDocument
|
|
18
|
+
} = useFluent();
|
|
19
|
+
const keyboardHandler = useEventCallback(event => {
|
|
20
|
+
const colId = columnId.current;
|
|
21
|
+
if (!colId) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const width = columnResizeStateRef.current.getColumnWidth(colId);
|
|
25
|
+
const precisionModifier = event.getModifierState(PRECISION_MODIFIER);
|
|
26
|
+
const stopEvent = () => {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
event.stopPropagation();
|
|
29
|
+
};
|
|
30
|
+
switch (event.key) {
|
|
31
|
+
case ArrowLeft:
|
|
32
|
+
stopEvent();
|
|
33
|
+
columnResizeStateRef.current.setColumnWidth(event, {
|
|
34
|
+
columnId: colId,
|
|
35
|
+
width: width - (precisionModifier ? STEP * PRECISION_FACTOR : STEP)
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
case ArrowRight:
|
|
39
|
+
stopEvent();
|
|
40
|
+
columnResizeStateRef.current.setColumnWidth(event, {
|
|
41
|
+
columnId: colId,
|
|
42
|
+
width: width + (precisionModifier ? STEP * PRECISION_FACTOR : STEP)
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
case Space:
|
|
46
|
+
case Enter:
|
|
47
|
+
case Escape:
|
|
48
|
+
stopEvent();
|
|
49
|
+
disableInteractiveMode();
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
// On component unmout, cancel any timer for adding a listener (if it exists) and remove the listener
|
|
54
|
+
React.useEffect(() => () => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
(_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.clearTimeout(addListenerTimeout.current);
|
|
57
|
+
(_b = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _b === void 0 ? void 0 : _b.removeEventListener('keydown', keyboardHandler);
|
|
58
|
+
}, [keyboardHandler, targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView]);
|
|
59
|
+
const enableInteractiveMode = React.useCallback(colId => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
columnId.current = colId;
|
|
62
|
+
(_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, colId, true);
|
|
63
|
+
// Create the listener in the next tick, because the event that triggered this is still propagating
|
|
64
|
+
// when Enter was pressed and would be caught in the keyboardHandler, disabling the keyboard mode immediately.
|
|
65
|
+
// No idea why this is happening, but this is a working workaround.
|
|
66
|
+
// Tracked here: https://github.com/microsoft/fluentui/issues/27177
|
|
67
|
+
addListenerTimeout.current = (_b = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _b === void 0 ? void 0 : _b.setTimeout(() => {
|
|
68
|
+
var _a;
|
|
69
|
+
(_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.addEventListener('keydown', keyboardHandler);
|
|
70
|
+
}, 0);
|
|
71
|
+
}, [keyboardHandler, targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView]);
|
|
72
|
+
const disableInteractiveMode = React.useCallback(() => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (columnId.current) {
|
|
75
|
+
(_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, columnId.current, false);
|
|
76
|
+
}
|
|
77
|
+
columnId.current = undefined;
|
|
78
|
+
(_b = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _b === void 0 ? void 0 : _b.removeEventListener('keydown', keyboardHandler);
|
|
79
|
+
}, [keyboardHandler, targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView]);
|
|
80
|
+
const toggleInteractiveMode = (colId, onChange) => {
|
|
81
|
+
onChangeRef.current = onChange;
|
|
82
|
+
if (!columnId.current) {
|
|
83
|
+
enableInteractiveMode(colId);
|
|
84
|
+
} else if (colId && columnId.current !== colId) {
|
|
85
|
+
columnId.current = colId;
|
|
86
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(columnId.current, true);
|
|
87
|
+
} else {
|
|
88
|
+
disableInteractiveMode();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
toggleInteractiveMode
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=useKeyboardResizing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","ArrowLeft","ArrowRight","Enter","Escape","Shift","Space","useEventCallback","useFluent_unstable","useFluent","STEP","PRECISION_MODIFIER","PRECISION_FACTOR","useKeyboardResizing","columnResizeState","columnId","useRef","onChangeRef","addListenerTimeout","columnResizeStateRef","useEffect","current","targetDocument","keyboardHandler","event","colId","width","getColumnWidth","precisionModifier","getModifierState","stopEvent","preventDefault","stopPropagation","key","setColumnWidth","disableInteractiveMode","_a","defaultView","clearTimeout","_b","removeEventListener","enableInteractiveMode","useCallback","call","setTimeout","addEventListener","undefined","toggleInteractiveMode","onChange"],"sources":["../src/packages/react-components/react-table/src/hooks/useKeyboardResizing.ts"],"sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, ArrowRight, Enter, Escape, Shift, Space } from '@fluentui/keyboard-keys';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { ColumnResizeState, EnableKeyboardModeOnChangeCallback, TableColumnId } from './types';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst STEP = 20;\nconst PRECISION_MODIFIER = Shift;\nconst PRECISION_FACTOR = 1 / 4;\n\nexport function useKeyboardResizing(columnResizeState: ColumnResizeState) {\n const columnId = React.useRef<TableColumnId>();\n const onChangeRef = React.useRef<EnableKeyboardModeOnChangeCallback>();\n const addListenerTimeout = React.useRef<number>();\n\n const columnResizeStateRef = React.useRef<ColumnResizeState>(columnResizeState);\n React.useEffect(() => {\n columnResizeStateRef.current = columnResizeState;\n }, [columnResizeState]);\n\n const { targetDocument } = useFluent();\n\n const keyboardHandler = useEventCallback((event: KeyboardEvent) => {\n const colId = columnId.current;\n\n if (!colId) {\n return;\n }\n\n const width = columnResizeStateRef.current.getColumnWidth(colId);\n const precisionModifier = event.getModifierState(PRECISION_MODIFIER);\n\n const stopEvent = () => {\n event.preventDefault();\n event.stopPropagation();\n };\n\n switch (event.key) {\n case ArrowLeft:\n stopEvent();\n columnResizeStateRef.current.setColumnWidth(event, {\n columnId: colId,\n width: width - (precisionModifier ? STEP * PRECISION_FACTOR : STEP),\n });\n return;\n\n case ArrowRight:\n stopEvent();\n columnResizeStateRef.current.setColumnWidth(event, {\n columnId: colId,\n width: width + (precisionModifier ? STEP * PRECISION_FACTOR : STEP),\n });\n return;\n\n case Space:\n case Enter:\n case Escape:\n stopEvent();\n disableInteractiveMode();\n break;\n }\n });\n\n // On component unmout, cancel any timer for adding a listener (if it exists) and remove the listener\n React.useEffect(\n () => () => {\n targetDocument?.defaultView?.clearTimeout(addListenerTimeout.current);\n targetDocument?.defaultView?.removeEventListener('keydown', keyboardHandler);\n },\n [keyboardHandler, targetDocument?.defaultView],\n );\n\n const enableInteractiveMode = React.useCallback(\n (colId: TableColumnId) => {\n columnId.current = colId;\n onChangeRef.current?.(colId, true);\n // Create the listener in the next tick, because the event that triggered this is still propagating\n // when Enter was pressed and would be caught in the keyboardHandler, disabling the keyboard mode immediately.\n // No idea why this is happening, but this is a working workaround.\n // Tracked here: https://github.com/microsoft/fluentui/issues/27177\n addListenerTimeout.current = targetDocument?.defaultView?.setTimeout(() => {\n targetDocument?.defaultView?.addEventListener('keydown', keyboardHandler);\n }, 0);\n },\n [keyboardHandler, targetDocument?.defaultView],\n );\n\n const disableInteractiveMode = React.useCallback(() => {\n if (columnId.current) {\n onChangeRef.current?.(columnId.current, false);\n }\n columnId.current = undefined;\n targetDocument?.defaultView?.removeEventListener('keydown', keyboardHandler);\n }, [keyboardHandler, targetDocument?.defaultView]);\n\n const toggleInteractiveMode = (colId: TableColumnId, onChange?: EnableKeyboardModeOnChangeCallback) => {\n onChangeRef.current = onChange;\n if (!columnId.current) {\n enableInteractiveMode(colId);\n } else if (colId && columnId.current !== colId) {\n columnId.current = colId;\n onChange?.(columnId.current, true);\n } else {\n disableInteractiveMode();\n }\n };\n\n return {\n toggleInteractiveMode,\n };\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,SAAS,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,KAAK,EAAEC,KAAK,QAAQ,yBAAyB;AAC5F,SAASC,gBAAgB,QAAQ,2BAA2B;AAE5D,SAASC,kBAAkB,IAAIC,SAAS,QAAQ,iCAAiC;AAEjF,MAAMC,IAAI,GAAG,EAAE;AACf,MAAMC,kBAAkB,GAAGN,KAAK;AAChC,MAAMO,gBAAgB,GAAG,CAAC,GAAG,CAAC;AAE9B,OAAM,SAAUC,mBAAmBA,CAACC,iBAAoC;EACtE,MAAMC,QAAQ,GAAGf,KAAK,CAACgB,MAAM,EAAiB;EAC9C,MAAMC,WAAW,GAAGjB,KAAK,CAACgB,MAAM,EAAsC;EACtE,MAAME,kBAAkB,GAAGlB,KAAK,CAACgB,MAAM,EAAU;EAEjD,MAAMG,oBAAoB,GAAGnB,KAAK,CAACgB,MAAM,CAAoBF,iBAAiB,CAAC;EAC/Ed,KAAK,CAACoB,SAAS,CAAC,MAAK;IACnBD,oBAAoB,CAACE,OAAO,GAAGP,iBAAiB;EAClD,CAAC,EAAE,CAACA,iBAAiB,CAAC,CAAC;EAEvB,MAAM;IAAEQ;EAAc,CAAE,GAAGb,SAAS,EAAE;EAEtC,MAAMc,eAAe,GAAGhB,gBAAgB,CAAEiB,KAAoB,IAAI;IAChE,MAAMC,KAAK,GAAGV,QAAQ,CAACM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mBAAmB,CAAC,SAAS,EAAEjB,eAAe,CAAC;EAC9E,CAAC,EAAE,CAACA,eAAe,EAAED,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAEe,WAAW,CAAC,CAAC;EAElD,MAAMU,qBAAqB,GAAGA,CAACtB,KAAoB,EAAEuB,QAA6C,KAAI;IACpG/B,WAAW,CAACI,OAAO,GAAG2B,QAAQ;IAC9B,IAAI,CAACjC,QAAQ,CAACM,OAAO,EAAE;MACrBoB,qBAAqB,CAAChB,KAAK,CAAC;KAC7B,MAAM,IAAIA,KAAK,IAAIV,QAAQ,CAACM,OAAO,KAAKI,KAAK,EAAE;MAC9CV,QAAQ,CAACM,OAAO,GAAGI,KAAK;MACxBuB,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAGjC,QAAQ,CAACM,OAAO,EAAE,IAAI,CAAC;KACnC,MAAM;MACLc,sBAAsB,EAAE;;EAE5B,CAAC;EAED,OAAO;IACLY;GACD;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEventCallback","useIsomorphicLayoutEffect","React","columnDefinitionsToState","adjustColumnWidthsToFitContainer","getColumnById","setColumnProperty","getColumnWidth","createReducer","state","action","type","containerWidth","columnWidthState","newS","columns","columnSizingOptions","newState","columnId","width","column","newColumnWidthState","useTableColumnResizeState","params","onColumnResize","reducer","useMemo","dispatch","useReducer","undefined","setColumnWidth","event","data","col","Math","max","minWidth","colId","getColumns"],"sources":["../src/packages/react-components/react-table/src/hooks/useTableColumnResizeState.ts"],"sourcesContent":["import { useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport {\n TableColumnDefinition,\n TableColumnId,\n ColumnResizeState,\n ColumnWidthState,\n UseTableColumnSizingParams,\n TableColumnSizingOptions,\n} from './types';\nimport {\n columnDefinitionsToState,\n adjustColumnWidthsToFitContainer,\n getColumnById,\n setColumnProperty,\n getColumnWidth,\n} from '../utils/columnResizeUtils';\n\ntype ComponentState<T> = {\n columns: TableColumnDefinition<T>[];\n containerWidth: number;\n columnWidthState: ColumnWidthState[];\n columnSizingOptions: TableColumnSizingOptions | undefined;\n};\n\ntype ColumnResizeStateAction<T> =\n | {\n type: 'CONTAINER_WIDTH_UPDATED';\n containerWidth: number;\n }\n | {\n type: 'COLUMNS_UPDATED';\n columns: TableColumnDefinition<T>[];\n }\n | {\n type: 'COLUMN_SIZING_OPTIONS_UPDATED';\n columnSizingOptions: TableColumnSizingOptions | undefined;\n }\n | {\n type: 'SET_COLUMN_WIDTH';\n columnId: TableColumnId;\n width: number;\n };\n\nconst createReducer =\n <T>() =>\n (state: ComponentState<T>, action: ColumnResizeStateAction<T>): ComponentState<T> => {\n switch (action.type) {\n case 'CONTAINER_WIDTH_UPDATED':\n return {\n ...state,\n containerWidth: action.containerWidth,\n columnWidthState: adjustColumnWidthsToFitContainer(state.columnWidthState, action.containerWidth),\n };\n\n case 'COLUMNS_UPDATED':\n const newS = columnDefinitionsToState(action.columns, state.columnWidthState, state.columnSizingOptions);\n return {\n ...state,\n columns: action.columns,\n columnWidthState: adjustColumnWidthsToFitContainer(newS, state.containerWidth),\n };\n\n case 'COLUMN_SIZING_OPTIONS_UPDATED':\n const newState = columnDefinitionsToState(state.columns, state.columnWidthState, action.columnSizingOptions);\n return {\n ...state,\n columnSizingOptions: action.columnSizingOptions,\n columnWidthState: adjustColumnWidthsToFitContainer(newState, state.containerWidth),\n };\n\n case 'SET_COLUMN_WIDTH':\n const { columnId, width } = action;\n const { containerWidth } = state;\n\n const column = getColumnById(state.columnWidthState, columnId);\n let newColumnWidthState = [...state.columnWidthState];\n\n if (!column) {\n return state;\n }\n\n // Adjust the column width and measure the new total width\n newColumnWidthState = setColumnProperty(newColumnWidthState, columnId, 'width', width);\n // Set this width as idealWidth, because its a deliberate change, not a recalculation because of container\n newColumnWidthState = setColumnProperty(newColumnWidthState, columnId, 'idealWidth', width);\n // Adjust the widths to the container size\n newColumnWidthState = adjustColumnWidthsToFitContainer(newColumnWidthState, containerWidth);\n\n return { ...state, columnWidthState: newColumnWidthState };\n }\n };\n\nexport function useTableColumnResizeState<T>(\n columns: TableColumnDefinition<T>[],\n containerWidth: number,\n params: UseTableColumnSizingParams = {},\n): ColumnResizeState {\n const { onColumnResize, columnSizingOptions } = params;\n\n const reducer = React.useMemo(() => createReducer<T>(), []);\n\n const [state, dispatch] = React.useReducer(reducer, {\n columns,\n containerWidth: 0,\n columnWidthState: columnDefinitionsToState(columns, undefined, columnSizingOptions),\n columnSizingOptions,\n });\n\n useIsomorphicLayoutEffect(() => {\n dispatch({ type: 'CONTAINER_WIDTH_UPDATED', containerWidth });\n }, [containerWidth]);\n\n useIsomorphicLayoutEffect(() => {\n dispatch({ type: 'COLUMNS_UPDATED', columns });\n }, [columns]);\n\n useIsomorphicLayoutEffect(() => {\n dispatch({ type: 'COLUMN_SIZING_OPTIONS_UPDATED', columnSizingOptions });\n }, [columnSizingOptions]);\n\n const setColumnWidth = useEventCallback(\n (event: MouseEvent | TouchEvent | undefined, data: { columnId: TableColumnId; width: number }) => {\n let { width } = data;\n const { columnId } = data;\n const col = getColumnById(state.columnWidthState, columnId);\n if (!col) {\n return;\n }\n\n width = Math.max(col.minWidth || 0, width);\n\n if (onColumnResize) {\n onColumnResize(event, { columnId, width });\n }\n dispatch({ type: 'SET_COLUMN_WIDTH', columnId, width });\n },\n );\n\n return {\n getColumnById: (colId: TableColumnId) => getColumnById(state.columnWidthState, colId),\n getColumns: () => state.columnWidthState,\n getColumnWidth: (colId: TableColumnId) => getColumnWidth(state.columnWidthState, colId),\n setColumnWidth,\n };\n}\n"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,2BAA2B;AACvF,OAAO,KAAKC,KAAK,MAAM,OAAO;AAS9B,SACEC,wBAAwB,EACxBC,gCAAgC,EAChCC,aAAa,EACbC,iBAAiB,EACjBC,cAAc,QACT,4BAA4B;AA4BnC,MAAMC,aAAa,GACjBA,CAAA,KACA,CAACC,K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":3,"names":["useEventCallback","useIsomorphicLayoutEffect","React","columnDefinitionsToState","adjustColumnWidthsToFitContainer","getColumnById","setColumnProperty","getColumnWidth","createReducer","state","action","type","containerWidth","columnWidthState","newS","columns","columnSizingOptions","newState","columnId","width","column","newColumnWidthState","useTableColumnResizeState","params","onColumnResize","reducer","useMemo","dispatch","useReducer","undefined","setColumnWidth","event","data","col","Math","max","minWidth","colId","getColumns"],"sources":["../src/packages/react-components/react-table/src/hooks/useTableColumnResizeState.ts"],"sourcesContent":["import { useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport {\n TableColumnDefinition,\n TableColumnId,\n ColumnResizeState,\n ColumnWidthState,\n UseTableColumnSizingParams,\n TableColumnSizingOptions,\n} from './types';\nimport {\n columnDefinitionsToState,\n adjustColumnWidthsToFitContainer,\n getColumnById,\n setColumnProperty,\n getColumnWidth,\n} from '../utils/columnResizeUtils';\n\ntype ComponentState<T> = {\n columns: TableColumnDefinition<T>[];\n containerWidth: number;\n columnWidthState: ColumnWidthState[];\n columnSizingOptions: TableColumnSizingOptions | undefined;\n};\n\ntype ColumnResizeStateAction<T> =\n | {\n type: 'CONTAINER_WIDTH_UPDATED';\n containerWidth: number;\n }\n | {\n type: 'COLUMNS_UPDATED';\n columns: TableColumnDefinition<T>[];\n }\n | {\n type: 'COLUMN_SIZING_OPTIONS_UPDATED';\n columnSizingOptions: TableColumnSizingOptions | undefined;\n }\n | {\n type: 'SET_COLUMN_WIDTH';\n columnId: TableColumnId;\n width: number;\n };\n\nconst createReducer =\n <T>() =>\n (state: ComponentState<T>, action: ColumnResizeStateAction<T>): ComponentState<T> => {\n switch (action.type) {\n case 'CONTAINER_WIDTH_UPDATED':\n return {\n ...state,\n containerWidth: action.containerWidth,\n columnWidthState: adjustColumnWidthsToFitContainer(state.columnWidthState, action.containerWidth),\n };\n\n case 'COLUMNS_UPDATED':\n const newS = columnDefinitionsToState(action.columns, state.columnWidthState, state.columnSizingOptions);\n return {\n ...state,\n columns: action.columns,\n columnWidthState: adjustColumnWidthsToFitContainer(newS, state.containerWidth),\n };\n\n case 'COLUMN_SIZING_OPTIONS_UPDATED':\n const newState = columnDefinitionsToState(state.columns, state.columnWidthState, action.columnSizingOptions);\n return {\n ...state,\n columnSizingOptions: action.columnSizingOptions,\n columnWidthState: adjustColumnWidthsToFitContainer(newState, state.containerWidth),\n };\n\n case 'SET_COLUMN_WIDTH':\n const { columnId, width } = action;\n const { containerWidth } = state;\n\n const column = getColumnById(state.columnWidthState, columnId);\n let newColumnWidthState = [...state.columnWidthState];\n\n if (!column) {\n return state;\n }\n\n // Adjust the column width and measure the new total width\n newColumnWidthState = setColumnProperty(newColumnWidthState, columnId, 'width', width);\n // Set this width as idealWidth, because its a deliberate change, not a recalculation because of container\n newColumnWidthState = setColumnProperty(newColumnWidthState, columnId, 'idealWidth', width);\n // Adjust the widths to the container size\n newColumnWidthState = adjustColumnWidthsToFitContainer(newColumnWidthState, containerWidth);\n\n return { ...state, columnWidthState: newColumnWidthState };\n }\n };\n\nexport function useTableColumnResizeState<T>(\n columns: TableColumnDefinition<T>[],\n containerWidth: number,\n params: UseTableColumnSizingParams = {},\n): ColumnResizeState {\n const { onColumnResize, columnSizingOptions } = params;\n\n const reducer = React.useMemo(() => createReducer<T>(), []);\n\n const [state, dispatch] = React.useReducer(reducer, {\n columns,\n containerWidth: 0,\n columnWidthState: columnDefinitionsToState(columns, undefined, columnSizingOptions),\n columnSizingOptions,\n });\n\n useIsomorphicLayoutEffect(() => {\n dispatch({ type: 'CONTAINER_WIDTH_UPDATED', containerWidth });\n }, [containerWidth]);\n\n useIsomorphicLayoutEffect(() => {\n dispatch({ type: 'COLUMNS_UPDATED', columns });\n }, [columns]);\n\n useIsomorphicLayoutEffect(() => {\n dispatch({ type: 'COLUMN_SIZING_OPTIONS_UPDATED', columnSizingOptions });\n }, [columnSizingOptions]);\n\n const setColumnWidth = useEventCallback(\n (event: KeyboardEvent | MouseEvent | TouchEvent | undefined, data: { columnId: TableColumnId; width: number }) => {\n let { width } = data;\n const { columnId } = data;\n const col = getColumnById(state.columnWidthState, columnId);\n if (!col) {\n return;\n }\n\n width = Math.max(col.minWidth || 0, width);\n\n if (onColumnResize) {\n onColumnResize(event, { columnId, width });\n }\n dispatch({ type: 'SET_COLUMN_WIDTH', columnId, width });\n },\n );\n\n return {\n getColumnById: (colId: TableColumnId) => getColumnById(state.columnWidthState, colId),\n getColumns: () => state.columnWidthState,\n getColumnWidth: (colId: TableColumnId) => getColumnWidth(state.columnWidthState, colId),\n setColumnWidth,\n };\n}\n"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,2BAA2B;AACvF,OAAO,KAAKC,KAAK,MAAM,OAAO;AAS9B,SACEC,wBAAwB,EACxBC,gCAAgC,EAChCC,aAAa,EACbC,iBAAiB,EACjBC,cAAc,QACT,4BAA4B;AA4BnC,MAAMC,aAAa,GACjBA,CAAA,KACA,CAACC,KAAwB,EAAEC,MAAkC,KAAuB;EAClF,QAAQA,MAAM,CAACC,IAAI;IACjB,KAAK,yBAAyB;MAC5B,OAAO;QACL,GAAGF,KAAK;QACRG,cAAc,EAAEF,MAAM,CAACE,cAAc;QACrCC,gBAAgB,EAAET,gCAAgC,CAACK,KAAK,CAACI,gBAAgB,EAAEH,MAAM,CAACE,cAAc;OACjG;IAEH,KAAK,iBAAiB;MACpB,MAAME,IAAI,GAAGX,wBAAwB,CAACO,MAAM,CAACK,OAAO,EAAEN,KAAK,CAACI,gBAAgB,EAAEJ,KAAK,CAACO,mBAAmB,CAAC;MACxG,OAAO;QACL,GAAGP,KAAK;QACRM,OAAO,EAAEL,MAAM,CAACK,OAAO;QACvBF,gBAAgB,EAAET,gCAAgC,CAACU,IAAI,EAAEL,KAAK,CAACG,cAAc;OAC9E;IAEH,KAAK,+BAA+B;MAClC,MAAMK,QAAQ,GAAGd,wBAAwB,CAACM,KAAK,CAACM,OAAO,EAAEN,KAAK,CAACI,gBAAgB,EAA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UAAU,EAAEA,CAAA,KAAM7B,KAAK,CAACI,gBAAgB;IACxCN,cAAc,EAAG8B,KAAoB,IAAK9B,cAAc,CAACE,KAAK,CAACI,gBAAgB,EAAEwB,KAAK,CAAC;IACvFP;GACD;AACH"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useTableColumnResizeState } from './useTableColumnResizeState';
|
|
3
|
-
import { useTableColumnResizeMouseHandler } from './useTableColumnResizeMouseHandler';
|
|
4
|
-
import { useMeasureElement } from './useMeasureElement';
|
|
5
2
|
import { TableResizeHandle } from '../TableResizeHandle';
|
|
3
|
+
import { useMeasureElement } from './useMeasureElement';
|
|
4
|
+
import { useTableColumnResizeMouseHandler } from './useTableColumnResizeMouseHandler';
|
|
5
|
+
import { useTableColumnResizeState } from './useTableColumnResizeState';
|
|
6
|
+
import { useKeyboardResizing } from './useKeyboardResizing';
|
|
6
7
|
export const defaultColumnSizingState = {
|
|
7
8
|
getColumnWidths: () => [],
|
|
8
9
|
getOnMouseDown: () => () => null,
|
|
@@ -14,7 +15,8 @@ export const defaultColumnSizingState = {
|
|
|
14
15
|
getTableCellProps: () => ({
|
|
15
16
|
style: {},
|
|
16
17
|
columnId: ''
|
|
17
|
-
})
|
|
18
|
+
}),
|
|
19
|
+
enableKeyboardMode: () => () => null
|
|
18
20
|
};
|
|
19
21
|
export function useTableColumnSizing_unstable(params) {
|
|
20
22
|
// False positive, these plugin hooks are intended to be run on every render
|
|
@@ -44,6 +46,13 @@ function useTableColumnSizingState(tableState, params) {
|
|
|
44
46
|
const columnResizeState = useTableColumnResizeState(columns, width + ((params === null || params === void 0 ? void 0 : params.containerWidthOffset) || 0), params);
|
|
45
47
|
// Creates the mouse handler and attaches the state to it
|
|
46
48
|
const mouseHandler = useTableColumnResizeMouseHandler(columnResizeState);
|
|
49
|
+
// Creates the keyboard handler for resizing columns
|
|
50
|
+
const keyboardResizing = useKeyboardResizing(columnResizeState);
|
|
51
|
+
const enableKeyboardMode = React.useCallback((columnId, onChange) => e => {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
e.nativeEvent.stopPropagation();
|
|
54
|
+
keyboardResizing.toggleInteractiveMode(columnId, onChange);
|
|
55
|
+
}, [keyboardResizing]);
|
|
47
56
|
return {
|
|
48
57
|
...tableState,
|
|
49
58
|
tableRef: measureElementRef,
|
|
@@ -71,7 +80,8 @@ function useTableColumnSizingState(tableState, params) {
|
|
|
71
80
|
return col ? {
|
|
72
81
|
style: getColumnStyles(col)
|
|
73
82
|
} : {};
|
|
74
|
-
}
|
|
83
|
+
},
|
|
84
|
+
enableKeyboardMode
|
|
75
85
|
}
|
|
76
86
|
};
|
|
77
87
|
}
|