@absreim/react-bootstrap-data-grid-pro 4.0.0 → 4.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.
Files changed (112) hide show
  1. package/common/constants.d.ts +2 -0
  2. package/common/constants.js +2 -0
  3. package/common/editing/types.d.ts +30 -0
  4. package/common/export/types.d.ts +6 -0
  5. package/common/export/useExportFn.js +1 -1
  6. package/common/filtering/DateFilterRow.d.ts +1 -1
  7. package/common/filtering/DateFilterRow.js +1 -1
  8. package/common/filtering/FilterOptionsTable.d.ts +3 -2
  9. package/common/filtering/NumberFilterRow.d.ts +1 -1
  10. package/common/filtering/NumberFilterRow.js +1 -1
  11. package/common/filtering/StringFilterRow.js +1 -1
  12. package/common/filtering/constants.d.ts +19 -0
  13. package/common/filtering/constants.js +44 -0
  14. package/common/filtering/internalTypes.d.ts +77 -0
  15. package/common/filtering/types.d.ts +165 -22
  16. package/common/filtering/types.js +46 -17
  17. package/common/filtering/useFilterFormState.d.ts +1 -1
  18. package/common/index.d.ts +0 -3
  19. package/common/index.js +0 -3
  20. package/common/internalTypes.d.ts +10 -0
  21. package/common/pagination/Pagination.d.ts +1 -1
  22. package/common/pagination/internalTypes.d.ts +8 -0
  23. package/common/pagination/types.d.ts +105 -5
  24. package/common/pipeline/{types.d.ts → internalTypes.d.ts} +5 -0
  25. package/common/pipeline/internalTypes.js +1 -0
  26. package/common/pipeline/useAugFormattedRows.d.ts +3 -2
  27. package/common/pipeline/useColNameToWidth.d.ts +2 -1
  28. package/common/pipeline/useCombinedPipeline/index.d.ts +4 -3
  29. package/common/pipeline/useCombinedPipeline/useCurrentPageRows.d.ts +2 -1
  30. package/common/pipeline/useCombinedPipeline/useCurrentPageRows.js +3 -2
  31. package/common/pipeline/useCombinedPipeline/useFilterStateFromEditable.d.ts +2 -1
  32. package/common/pipeline/useCombinedPipeline/useFilterStateStore.d.ts +2 -1
  33. package/common/pipeline/useGridSelectionFns.d.ts +2 -1
  34. package/common/selection/internalTypes.d.ts +34 -0
  35. package/common/selection/internalTypes.js +1 -0
  36. package/common/selection/types.d.ts +91 -17
  37. package/common/selection/types.js +0 -3
  38. package/common/sorting/internalTypes.d.ts +10 -0
  39. package/common/sorting/internalTypes.js +1 -0
  40. package/common/sorting/types.d.ts +48 -4
  41. package/common/sorting/useSortHeaderStates.d.ts +1 -1
  42. package/common/styling/types.d.ts +57 -0
  43. package/common/toolbar/Toolbar.d.ts +1 -1
  44. package/common/toolbar/ToolbarContainer.d.ts +1 -1
  45. package/common/toolbar/{types.d.ts → internalTypes.d.ts} +27 -0
  46. package/common/toolbar/internalTypes.js +1 -0
  47. package/common/toolbar/useInterfaces.d.ts +1 -1
  48. package/common/types.d.ts +165 -18
  49. package/common/util/datetime.d.ts +17 -0
  50. package/common/util/datetime.js +17 -0
  51. package/common/util/getWidthStyle.d.ts +9 -0
  52. package/common/util/getWidthStyle.js +9 -0
  53. package/common/util/index.d.ts +0 -4
  54. package/common/util/index.js +0 -4
  55. package/common/util/isSubset.d.ts +12 -1
  56. package/common/util/isSubset.js +13 -2
  57. package/common/util/trueModulo.d.ts +8 -0
  58. package/common/util/trueModulo.js +8 -0
  59. package/common/util/useControlledHover.d.ts +5 -0
  60. package/common/util/useControlledHover.js +5 -0
  61. package/grid/focus/types.d.ts +15 -0
  62. package/grid/focus/types.js +1 -0
  63. package/grid/focus/useGridFocus.d.ts +10 -0
  64. package/grid/focus/useGridFocus.js +130 -0
  65. package/grid/main/Grid.d.ts +5 -0
  66. package/grid/main/Grid.js +26 -8
  67. package/grid/main/GridBody.d.ts +1 -1
  68. package/grid/main/GridBody.js +19 -6
  69. package/grid/main/GridHeader.d.ts +1 -1
  70. package/grid/main/GridHeader.js +8 -4
  71. package/grid/main/internalTypes.d.ts +29 -0
  72. package/grid/main/internalTypes.js +1 -0
  73. package/grid/main/types.d.ts +114 -16
  74. package/grid.css +1 -1
  75. package/grid.scss +26 -14
  76. package/package.json +5 -5
  77. package/table/InternalTable.d.ts +1 -1
  78. package/table/Table.d.ts +5 -1
  79. package/table/Table.js +5 -0
  80. package/table/editing/EditableRow.d.ts +1 -1
  81. package/table/editing/EditableRow.js +1 -1
  82. package/table/internalTypes.d.ts +23 -0
  83. package/table/internalTypes.js +1 -0
  84. package/table/main/BodyRows.d.ts +4 -3
  85. package/table/main/ColHeaderCell/index.d.ts +1 -1
  86. package/table/selection/SelectAllHeaderCell.d.ts +1 -1
  87. package/table/styling/types.d.ts +122 -5
  88. package/table/types.d.ts +62 -15
  89. package/table-pro/ColHeaderCellPro.d.ts +1 -1
  90. package/table-pro/TablePro.d.ts +5 -0
  91. package/table-pro/TablePro.js +5 -0
  92. package/table-pro/index.d.ts +0 -1
  93. package/table-pro/index.js +0 -1
  94. package/table-pro/internalTypes.d.ts +11 -0
  95. package/table-pro/internalTypes.js +1 -0
  96. package/table-pro/reorder/ReorderHandleCell.d.ts +2 -1
  97. package/table-pro/reorder/internalTypes.d.ts +53 -0
  98. package/table-pro/reorder/internalTypes.js +1 -0
  99. package/table-pro/reorder/types.d.ts +36 -15
  100. package/table-pro/reorder/useKeyboardReorder.d.ts +1 -1
  101. package/table-pro/reorder/useKeyboardReorderListener.d.ts +2 -1
  102. package/table-pro/reorder/useReorderStyles.d.ts +2 -1
  103. package/table-pro/resize/internalType.d.ts +20 -0
  104. package/table-pro/resize/internalType.js +1 -0
  105. package/table-pro/resize/useResizeModel.d.ts +1 -1
  106. package/table-pro/types.d.ts +91 -8
  107. package/table-pro/util/reorderRows.d.ts +13 -0
  108. package/table-pro/util/reorderRows.js +13 -0
  109. package/table-pro/resize/types.d.ts +0 -5
  110. /package/common/{pipeline/types.js → filtering/internalTypes.js} +0 -0
  111. /package/common/{toolbar/types.js → internalTypes.js} +0 -0
  112. /package/{table-pro/resize/types.js → common/pagination/internalTypes.js} +0 -0
package/common/types.d.ts CHANGED
@@ -1,57 +1,204 @@
1
- import { EditModel } from "./editing/types";
2
- import { PaginationModel } from "./pagination/types";
3
- import { SortModel } from "./sorting/types";
4
- import { FilterModel } from "./filtering/types";
5
- import { SelectModel } from "./selection/types";
6
- import { StyleModel } from "./styling/types";
1
+ /**
2
+ * Union of all possible column data types.
3
+ *
4
+ * @public
5
+ */
7
6
  export type ColDataType = string | number | Date;
7
+ /**
8
+ * Union of strings that describe the type of a column.
9
+ *
10
+ * @public
11
+ */
8
12
  export type ColDataTypeStrings = "string" | "number" | "date" | "datetime";
13
+ /**
14
+ * Properties to a define a column that is shared between community and pro
15
+ * editions.
16
+ *
17
+ * @typeParam ValueType - the type of the value of the column (e.g. string,
18
+ * number, or Date)
19
+ *
20
+ * @public
21
+ */
9
22
  export interface ColDefBase<ValueType = any> {
23
+ /**
24
+ * String that specifies the data type of the column.
25
+ */
10
26
  type: ColDataTypeStrings;
27
+ /**
28
+ * The name of the property for the column in the {@link RowDef} object.
29
+ */
11
30
  name: string;
31
+ /**
32
+ * The display name of the property in places like the column heading.
33
+ */
12
34
  label: string;
35
+ /**
36
+ * The formatter function for the column.
37
+ */
13
38
  formatter?: (value: ValueType) => string;
39
+ /**
40
+ * Specifies whether the column is sortable.
41
+ *
42
+ * @defaultValue false
43
+ */
14
44
  sortable?: boolean;
15
45
  }
16
- export type ColDef<ValueType = any> = ColDefBase<ValueType> & {
46
+ /**
47
+ * Column definition properties specific to the community edition of the table
48
+ * and grid.
49
+ *
50
+ * @public
51
+ */
52
+ export interface CommunitySpecificColProps {
53
+ /**
54
+ * Sets the min-width and max-width CSS properties for all cells of the
55
+ * column.
56
+ *
57
+ * For the table, if no value is specified, then no value for min-width
58
+ * or max-width will be set.
59
+ *
60
+ * @defaultValue - 100 for the grid, undefined for the table
61
+ */
17
62
  width?: number;
18
- };
63
+ }
64
+ /**
65
+ * Column definition object for the community edition of the table and grid.
66
+ *
67
+ * @typeParam ValueType - the type of the value of the column (e.g. string,
68
+ * number, or Date)
69
+ *
70
+ * @public
71
+ */
72
+ export type ColDef<ValueType = any> = ColDefBase<ValueType> & CommunitySpecificColProps;
73
+ /**
74
+ * Type alias for "data" property of the {@link RowDef} interface. This type
75
+ * alias represents the most general type possible. One can specify a more
76
+ * specific type via the Data type parameter.
77
+ *
78
+ * @public
79
+ */
19
80
  export type ValidRowData = Record<string, any>;
81
+ /**
82
+ * The data fields for a row in a table or grid. Excludes the primary key for
83
+ * the row, which is stored separately in the "id" field of the {@link RowDef}
84
+ * interface.
85
+ *
86
+ * @typeParam Data - the type of the object. A more specific type can be
87
+ * specified in place of the default {@link ValidRowData} type to assist in
88
+ * type safety and IDE coding assistance.
89
+ *
90
+ * @public
91
+ */
20
92
  export type RowData<Data extends ValidRowData = ValidRowData> = Data;
93
+ /**
94
+ * A union of the possible values for an id of a {@link RowDef} object.
95
+ *
96
+ * @public
97
+ */
21
98
  export type RowId = string | number;
99
+ /**
100
+ * An object that represents a single row.
101
+ *
102
+ * @typeParam Data - the type of the "data" property. Can be specified to
103
+ * enhance type safety.
104
+ *
105
+ * @public
106
+ */
22
107
  export interface RowDef<Data extends ValidRowData = ValidRowData> {
108
+ /**
109
+ * An id for the row that must be unique among all rows passed in the "rows"
110
+ * prop of the {@link Table} or {@link Grid}.
111
+ */
23
112
  id: RowId;
113
+ /**
114
+ * Contains all data fields for different columns of the row.
115
+ */
24
116
  data: RowData<Data>;
25
117
  }
118
+ /**
119
+ * Interface that contains parameters shared between the Table, TablePro, and
120
+ * Grid components.
121
+ *
122
+ * @public
123
+ */
26
124
  export interface MainComponentSharedProps {
125
+ /**
126
+ * The rows of data to be displayed by the table or grid
127
+ */
27
128
  rows: RowDef[];
129
+ /**
130
+ * The column definitions of the table or grid
131
+ */
28
132
  cols: ColDef[];
29
- pagination?: PaginationModel;
30
- sortModel?: SortModel;
31
- filterModel?: FilterModel;
32
- selectModel?: SelectModel;
33
- editModel?: EditModel;
34
- styleModel?: StyleModel;
35
- allowExport?: boolean;
36
133
  }
134
+ /**
135
+ * {@link RowDef} object that additionally contains the index of the row in the
136
+ * original array.
137
+ *
138
+ * @typeParam Data - type of the data property of the RowDef object
139
+ *
140
+ * @public
141
+ */
37
142
  export type AugRowDef<Data extends ValidRowData = ValidRowData> = RowDef<Data> & {
38
143
  origIndex: number;
39
144
  };
145
+ /**
146
+ * Row definition object that additionally contains index of the row before
147
+ * pagination was applied.
148
+ *
149
+ * @public
150
+ */
40
151
  export type PostPaginationRowDef<Data extends ValidRowData = ValidRowData> = AugRowDef<Data> & {
41
152
  prePaginationIndex: number;
42
153
  };
154
+ /**
155
+ * Object that describes the contents for a single table or grid cell along
156
+ * with various metadata.
157
+ *
158
+ * @public
159
+ */
43
160
  export interface CellData {
161
+ /**
162
+ * The name of the property in the {@link RowDef} "data" property that
163
+ * contains the value for the cell.
164
+ */
44
165
  fieldName: string;
166
+ /**
167
+ * The raw, unformatted, value of the cell.
168
+ */
45
169
  value: ColDataType;
170
+ /**
171
+ * A string that specifies of the value type of the column for the cell.
172
+ * Same as the "type" property in corresponding {@link ColDef} object.
173
+ */
46
174
  type: ColDataTypeStrings;
175
+ /**
176
+ * The ARIA column index of the column that contains the cell.
177
+ */
47
178
  ariaColIndex: number;
179
+ /**
180
+ * The value of the cell after the column's formatter function is applied.
181
+ */
48
182
  formattedValue: string;
183
+ /**
184
+ * The label of the column that the cell is in. Same as the property of the
185
+ * same name in the corresponding {@link ColDef} object.
186
+ */
49
187
  label: string;
188
+ /**
189
+ * The width of the column that the cell is in. Same as the property of the
190
+ * same name in the corresponding {@link ColDef} object.
191
+ */
50
192
  width?: number;
51
193
  }
194
+ /**
195
+ * Comprehensive information for an entire row of a table or grid, after
196
+ * postprocessing such as sorting, pagination, and filtering are applied.
197
+ *
198
+ * Contains an array of {@link CellData} in the order that the columns appear.
199
+ *
200
+ * @public
201
+ */
52
202
  export type FormattedRow = {
53
203
  contents: Omit<CellData, "width">[];
54
204
  } & Omit<PostPaginationRowDef, "data">;
55
- export type AugFormattedRow = {
56
- contents: CellData[];
57
- } & Omit<PostPaginationRowDef, "data">;
@@ -1,2 +1,19 @@
1
+ /**
2
+ * Returns a string that represents a date in the format used by the input
3
+ * element of type "date".
4
+ *
5
+ * @param date - the Date object to format
6
+ * @returns a string in the format YYYY-MM-DD
7
+ *
8
+ * @public
9
+ */
1
10
  export declare const dateToInputStr: (date: Date) => string;
11
+ /**
12
+ * Returns of string representation of datetime from a Date object.
13
+ *
14
+ * @param date - the Date object to format
15
+ * @returns a string in the format YYYY-MM-DDTHH:mm
16
+ *
17
+ * @public
18
+ */
2
19
  export declare const dateToDatetimeInputStr: (date: Date) => string;
@@ -1,3 +1,20 @@
1
1
  import dayjs from "dayjs";
2
+ /**
3
+ * Returns a string that represents a date in the format used by the input
4
+ * element of type "date".
5
+ *
6
+ * @param date - the Date object to format
7
+ * @returns a string in the format YYYY-MM-DD
8
+ *
9
+ * @public
10
+ */
2
11
  export const dateToInputStr = (date) => dayjs(date).format("YYYY-MM-DD");
12
+ /**
13
+ * Returns of string representation of datetime from a Date object.
14
+ *
15
+ * @param date - the Date object to format
16
+ * @returns a string in the format YYYY-MM-DDTHH:mm
17
+ *
18
+ * @public
19
+ */
3
20
  export const dateToDatetimeInputStr = (date) => dayjs(date).format("YYYY-MM-DDTHH:mm");
@@ -1,3 +1,12 @@
1
1
  import { CSSProperties } from "react";
2
+ /**
3
+ * Given a number representing a width, returns a React CSSProperties object
4
+ * that sets the min-width and max-width CSS properties based on that number.
5
+ * Returns undefined if the input is undefined.
6
+ *
7
+ * @param width - the number representing the width, or undefined
8
+ *
9
+ * @internal
10
+ */
2
11
  declare const getWidthStyle: (width: number | undefined) => CSSProperties | undefined;
3
12
  export default getWidthStyle;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Given a number representing a width, returns a React CSSProperties object
3
+ * that sets the min-width and max-width CSS properties based on that number.
4
+ * Returns undefined if the input is undefined.
5
+ *
6
+ * @param width - the number representing the width, or undefined
7
+ *
8
+ * @internal
9
+ */
1
10
  const getWidthStyle = (width) => width === undefined
2
11
  ? undefined
3
12
  : {
@@ -1,5 +1 @@
1
1
  export * from "./datetime";
2
- export { default as getWidthStyle } from "./getWidthStyle";
3
- export { default as isSubset } from "./isSubset";
4
- export { default as trueModulo } from "./trueModulo";
5
- export { default as useControlledHover } from "./useControlledHover";
@@ -1,5 +1 @@
1
1
  export * from "./datetime";
2
- export { default as getWidthStyle } from "./getWidthStyle";
3
- export { default as isSubset } from "./isSubset";
4
- export { default as trueModulo } from "./trueModulo";
5
- export { default as useControlledHover } from "./useControlledHover";
@@ -1,2 +1,13 @@
1
- declare const isSubset: <T>(subset: T[], superSet: T[]) => boolean;
1
+ /**
2
+ * Determines whether the elements of an array is the subset of another.
3
+ *
4
+ * @param subset - an array that may be the subset of another set
5
+ * @param superset - an array that may be the superset of another set
6
+ *
7
+ * @returns a boolean value indicating whether the elements in subset are a
8
+ * subset of the elements in superset
9
+ *
10
+ * @internal
11
+ */
12
+ declare const isSubset: <T>(subset: T[], superset: T[]) => boolean;
2
13
  export default isSubset;
@@ -1,5 +1,16 @@
1
- const isSubset = (subset, superSet) => {
2
- const supersetSet = new Set(superSet);
1
+ /**
2
+ * Determines whether the elements of an array is the subset of another.
3
+ *
4
+ * @param subset - an array that may be the subset of another set
5
+ * @param superset - an array that may be the superset of another set
6
+ *
7
+ * @returns a boolean value indicating whether the elements in subset are a
8
+ * subset of the elements in superset
9
+ *
10
+ * @internal
11
+ */
12
+ const isSubset = (subset, superset) => {
13
+ const supersetSet = new Set(superset);
3
14
  for (const member of subset) {
4
15
  if (!supersetSet.has(member)) {
5
16
  return false;
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Computes a mathematical modulo.
3
+ *
4
+ * @param num - to number to which to apply the modulo operator
5
+ * @param divisor - the divisor of the module operator
6
+ *
7
+ * @internal
8
+ */
1
9
  declare const trueModulo: (num: number, divisor: number) => number;
2
10
  export default trueModulo;
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Computes a mathematical modulo.
3
+ *
4
+ * @param num - to number to which to apply the modulo operator
5
+ * @param divisor - the divisor of the module operator
6
+ *
7
+ * @internal
8
+ */
1
9
  const trueModulo = (num, divisor) => ((num % divisor) + divisor) % divisor;
2
10
  export default trueModulo;
@@ -5,5 +5,10 @@ export interface UseControlledHoverHook<T> {
5
5
  handleMouseOver: MouseEventHandler<T>;
6
6
  handleMouseOut: MouseEventHandler<T>;
7
7
  }
8
+ /**
9
+ * Implements React state-based hovering for an element.
10
+ *
11
+ * @internal
12
+ */
8
13
  declare const useControlledHover: <T>() => UseControlledHoverHook<T>;
9
14
  export default useControlledHover;
@@ -1,4 +1,9 @@
1
1
  import { useState } from "react";
2
+ /**
3
+ * Implements React state-based hovering for an element.
4
+ *
5
+ * @internal
6
+ */
2
7
  const useControlledHover = () => {
3
8
  const [isHovering, setIsHovering] = useState(false);
4
9
  const handleMouseOver = () => setIsHovering(true);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Grid cell coordinates based on ARIA row index and column index.
3
+ *
4
+ * @public
5
+ */
6
+ export interface FocusCoordinates {
7
+ /**
8
+ * The ARIA row index.
9
+ */
10
+ ariaRowIndex: number;
11
+ /**
12
+ * The ARIA column index.
13
+ */
14
+ ariaColIndex: number;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { KeyboardEventHandler, PointerEventHandler, RefObject } from "react";
2
+ import { FocusCoordinates } from "./types";
3
+ export interface GridFocusOutput {
4
+ effectiveCoords: FocusCoordinates;
5
+ gridClickHandler: PointerEventHandler<HTMLDivElement>;
6
+ gridKeydownHandler: KeyboardEventHandler<HTMLDivElement>;
7
+ }
8
+ declare const useGridFocus: (gridRef: RefObject<HTMLDivElement | null>, numRows: number, // Number that includes the header row
9
+ numCols: number) => GridFocusOutput;
10
+ export default useGridFocus;
@@ -0,0 +1,130 @@
1
+ import { useCallback, useEffect, useMemo, useState, } from "react";
2
+ const startingCoordinates = {
3
+ ariaColIndex: 1,
4
+ ariaRowIndex: 1,
5
+ };
6
+ const useGridFocus = (gridRef, numRows, numCols) => {
7
+ const [coords, setCoords] = useState(startingCoordinates);
8
+ // Even though row and col count can be gotten from attributes, it needs to
9
+ // be a prop here to update effective coordinates at the appropriate times.
10
+ const effectiveCoords = useMemo(() => ({
11
+ ariaColIndex: Math.min(coords.ariaColIndex, numCols),
12
+ ariaRowIndex: Math.min(coords.ariaRowIndex, numRows),
13
+ }), [coords.ariaColIndex, coords.ariaRowIndex, numCols, numRows]);
14
+ const gridClickHandler = useCallback((event) => {
15
+ let cursor = event.target;
16
+ while (cursor !== event.currentTarget && !cursor.hasAttribute("aria-colindex")) {
17
+ cursor = cursor.parentElement;
18
+ }
19
+ if (!cursor.hasAttribute("aria-colindex")) {
20
+ // This is a legit outcome if the click was registered at a level above
21
+ // grid cells or column headers.
22
+ return;
23
+ }
24
+ const row = cursor.parentElement;
25
+ setCoords({
26
+ ariaColIndex: Number(cursor.getAttribute("aria-colIndex")),
27
+ ariaRowIndex: Number(row.getAttribute("aria-rowIndex")),
28
+ });
29
+ }, []);
30
+ const gridKeydownHandler = useCallback((event) => {
31
+ switch (event.code) {
32
+ case "ArrowDown": {
33
+ if (effectiveCoords.ariaRowIndex !== numRows) {
34
+ setCoords({
35
+ ariaColIndex: effectiveCoords.ariaColIndex,
36
+ ariaRowIndex: effectiveCoords.ariaRowIndex + 1,
37
+ });
38
+ }
39
+ break;
40
+ }
41
+ case "ArrowUp": {
42
+ if (effectiveCoords.ariaRowIndex !== 1) {
43
+ setCoords({
44
+ ariaColIndex: effectiveCoords.ariaColIndex,
45
+ ariaRowIndex: effectiveCoords.ariaRowIndex - 1,
46
+ });
47
+ }
48
+ break;
49
+ }
50
+ case "ArrowLeft": {
51
+ if (effectiveCoords.ariaColIndex !== 1) {
52
+ setCoords({
53
+ ariaColIndex: effectiveCoords.ariaColIndex - 1,
54
+ ariaRowIndex: effectiveCoords.ariaRowIndex,
55
+ });
56
+ }
57
+ break;
58
+ }
59
+ case "ArrowRight": {
60
+ if (effectiveCoords.ariaColIndex !== numCols) {
61
+ setCoords({
62
+ ariaColIndex: effectiveCoords.ariaColIndex + 1,
63
+ ariaRowIndex: effectiveCoords.ariaRowIndex,
64
+ });
65
+ }
66
+ break;
67
+ }
68
+ case "Home": {
69
+ if (event.ctrlKey || event.metaKey) {
70
+ setCoords({
71
+ ariaColIndex: 1,
72
+ ariaRowIndex: 1,
73
+ });
74
+ break;
75
+ }
76
+ setCoords({
77
+ ariaColIndex: 1,
78
+ ariaRowIndex: effectiveCoords.ariaRowIndex,
79
+ });
80
+ break;
81
+ }
82
+ case "End": {
83
+ if (event.ctrlKey || event.metaKey) {
84
+ setCoords({
85
+ ariaColIndex: numCols,
86
+ ariaRowIndex: numRows,
87
+ });
88
+ break;
89
+ }
90
+ setCoords({
91
+ ariaColIndex: numCols,
92
+ ariaRowIndex: effectiveCoords.ariaRowIndex,
93
+ });
94
+ break;
95
+ }
96
+ default: {
97
+ return;
98
+ }
99
+ }
100
+ event.preventDefault();
101
+ // Optionally set the element focus here. Not sure how much differences it
102
+ // makes in terms of performance vs relying on the useEffect hook.
103
+ }, [
104
+ effectiveCoords.ariaColIndex,
105
+ effectiveCoords.ariaRowIndex,
106
+ numCols,
107
+ numRows,
108
+ ]);
109
+ useEffect(() => {
110
+ if (!gridRef.current) {
111
+ // Not completely sure when this code can be reached, but it seems like a
112
+ // decent solution to just return. At the worst the user may need to click
113
+ // or do a keypress again during a corner case.
114
+ return;
115
+ }
116
+ if (!gridRef.current.contains(document.activeElement)) {
117
+ return;
118
+ }
119
+ const elToFocus = gridRef.current.querySelector(`:scope > div > div[aria-rowindex="${effectiveCoords.ariaRowIndex}"] > div[aria-colindex="${effectiveCoords.ariaColIndex}"]`);
120
+ if (elToFocus !== document.activeElement) {
121
+ elToFocus.focus({ preventScroll: true });
122
+ }
123
+ }, [effectiveCoords.ariaColIndex, effectiveCoords.ariaRowIndex, gridRef]);
124
+ return {
125
+ effectiveCoords,
126
+ gridClickHandler,
127
+ gridKeydownHandler
128
+ };
129
+ };
130
+ export default useGridFocus;
@@ -1,4 +1,9 @@
1
1
  import { FC } from "react";
2
2
  import { GridProps } from "./types";
3
+ /**
4
+ * The main component for the grid feature of react-bootstrap-data-grid.
5
+ *
6
+ * @public
7
+ */
3
8
  declare const Grid: FC<GridProps>;
4
9
  export default Grid;
package/grid/main/Grid.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useMemo } from "react";
3
+ import { useCallback, useMemo, useRef, } from "react";
4
4
  import useCombinedPipeline from "../../common/pipeline/useCombinedPipeline";
5
5
  import useAugFormattedRows from "../../common/pipeline/useAugFormattedRows";
6
6
  import useColNameToWidth from "../../common/pipeline/useColNameToWidth";
@@ -8,14 +8,16 @@ import GridHeader from "./GridHeader";
8
8
  import GridBody from "./GridBody";
9
9
  import classNames from "classnames";
10
10
  import { CSS_PREFIX } from "../../common/constants";
11
- const Grid = ({ rows, cols, filterModel, sortModel, pagination, selectModel, width, height, variant, stripes, hover, borders, small, divider, borderVariant, headerCellVariant, headerRowVariant, bodyCellVariant, bodyRowVariant, }) => {
11
+ import useGridFocus from "../focus/useGridFocus";
12
+ /**
13
+ * The main component for the grid feature of react-bootstrap-data-grid.
14
+ *
15
+ * @public
16
+ */
17
+ const Grid = ({ rows, cols, width, height, variant, stripes, hover, borders, small, divider, borderVariant, headerCellVariant, headerRowVariant, bodyCellVariant, bodyRowVariant, headerCellFocusVariant, bodyCellFocusVariant }) => {
12
18
  const { displayRows, filteredRows } = useCombinedPipeline({
13
19
  rows,
14
20
  cols,
15
- filterModel,
16
- sortModel,
17
- pagination,
18
- selectModel,
19
21
  });
20
22
  const colNameToWidth = useColNameToWidth(cols);
21
23
  const augFormattedRows = useAugFormattedRows(colNameToWidth, displayRows);
@@ -44,7 +46,21 @@ const Grid = ({ rows, cols, filterModel, sortModel, pagination, selectModel, wid
44
46
  };
45
47
  }, [width, height]);
46
48
  const vertScrollable = height !== undefined && height !== "auto";
47
- return (_jsxs("div", { style: gridStyle, className: classNames({
49
+ const gridRef = useRef(null);
50
+ const { effectiveCoords, gridClickHandler, gridKeydownHandler } = useGridFocus(gridRef, rows.length + 1, cols.length);
51
+ const onCopy = useCallback((event) => {
52
+ var _a;
53
+ if (!((_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement))) {
54
+ return;
55
+ }
56
+ const selection = document.getSelection();
57
+ if (!selection || !selection.isCollapsed) {
58
+ return;
59
+ }
60
+ event.preventDefault();
61
+ event.clipboardData.setData("text/plain", selection.focusNode.textContent);
62
+ }, []);
63
+ return (_jsxs("div", { onCopy: onCopy, onClick: gridClickHandler, onKeyDown: gridKeydownHandler, ref: gridRef, style: gridStyle, className: classNames({
48
64
  "overflow-x-auto": width !== undefined && width !== "auto",
49
65
  "overflow-y-auto": vertScrollable,
50
66
  "rbdg-grid-striped": stripes === "rows",
@@ -54,6 +70,8 @@ const Grid = ({ rows, cols, filterModel, sortModel, pagination, selectModel, wid
54
70
  "rbdg-grid-borderless": borders === "none",
55
71
  "rbdg-grid-sm": !!small,
56
72
  "rbdg-grid-group-divider": !!divider,
57
- }, "rbdg-grid", variant && `${CSS_PREFIX}-${variant}`, borderVariant && `border-${borderVariant}`), role: "grid", "aria-colcount": cols.length, "aria-rowcount": filteredRows.length + 1, children: [_jsx(GridHeader, { cols: cols, rowVariant: headerRowVariant, cellVariant: headerCellVariant, vertScrollable: vertScrollable }), _jsx(GridBody, { augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant })] }));
73
+ }, "rbdg-grid", variant && `${CSS_PREFIX}-${variant}`, borderVariant && `border-${borderVariant}`), role: "grid", "aria-colcount": cols.length, "aria-rowcount": filteredRows.length + 1, children: [_jsx(GridHeader, { cols: cols, rowVariant: headerRowVariant, cellVariant: headerCellVariant, vertScrollable: vertScrollable, focusColIndex: effectiveCoords.ariaRowIndex === 1
74
+ ? effectiveCoords.ariaColIndex
75
+ : null, cellFocusVariant: headerCellFocusVariant }), _jsx(GridBody, { focusCoords: effectiveCoords, augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant, cellFocusVariant: bodyCellFocusVariant })] }));
58
76
  };
59
77
  export default Grid;
@@ -1,4 +1,4 @@
1
1
  import { FC } from "react";
2
- import { GridBodyProps } from "./types";
2
+ import { GridBodyProps } from "./internalTypes";
3
3
  declare const GridBody: FC<GridBodyProps>;
4
4
  export default GridBody;
@@ -3,11 +3,24 @@ import getWidthStyles from "./getWidthStyles";
3
3
  import classNames from "classnames";
4
4
  import { CSS_PREFIX, DEFAULT_COL_WIDTH } from "../../common/constants";
5
5
  import { GRID_BODY_DATA_TEST_ID } from "../constants";
6
- const GridBody = ({ augFormattedRows, cols, rowVariant, cellVariant, }) => {
7
- return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map((row, rowDisplayIndex) => (_jsx("div", { role: "row", "aria-rowindex": row.prePaginationIndex + 2, className: classNames("d-flex", "flex-row", rowVariant &&
8
- rowVariant(row, rowDisplayIndex) &&
9
- `${CSS_PREFIX}-${rowVariant(row, rowDisplayIndex)}`), children: row.contents.map(({ formattedValue, width }, index) => (_jsx("div", { style: getWidthStyles(width || DEFAULT_COL_WIDTH), role: "gridcell", className: classNames("rbdg-grid-cell", cellVariant &&
10
- cellVariant(row.contents[index], row, index, rowDisplayIndex) &&
11
- `${CSS_PREFIX}-${cellVariant(row.contents[index], row, index, rowDisplayIndex)}`), "aria-colindex": index + 1, children: formattedValue }, cols[index].name))) }, row.id))) }));
6
+ const GridBody = ({ augFormattedRows, cols, rowVariant, cellVariant, focusCoords, cellFocusVariant, }) => {
7
+ return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map((row, rowDisplayIndex) => {
8
+ const ariaRowIndex = row.prePaginationIndex + 2;
9
+ return (_jsx("div", { role: "row", "aria-rowindex": ariaRowIndex, className: classNames("d-flex", "flex-row", rowVariant &&
10
+ rowVariant(row, rowDisplayIndex) &&
11
+ `${CSS_PREFIX}-${rowVariant(row, rowDisplayIndex)}`), children: row.contents.map(({ formattedValue, width }, index) => {
12
+ const ariaColIndex = index + 1;
13
+ const isFocused = focusCoords.ariaColIndex === ariaColIndex &&
14
+ focusCoords.ariaRowIndex === ariaRowIndex;
15
+ const cellVariantVal = cellVariant &&
16
+ cellVariant(row.contents[index], row, index, rowDisplayIndex);
17
+ const cellFocusVariantVal = cellFocusVariant &&
18
+ cellFocusVariant(row.contents[index], row, index, rowDisplayIndex);
19
+ return (_jsx("div", { tabIndex: isFocused ? 0 : -1, style: getWidthStyles(width || DEFAULT_COL_WIDTH), role: "gridcell", className: classNames("rbdg-grid-cell", cellVariantVal && `${CSS_PREFIX}-${cellVariantVal}`, cellFocusVariantVal && `focus-ring-${cellFocusVariantVal}`, {
20
+ "z-2": isFocused,
21
+ "rbdg-focusable-cell": isFocused,
22
+ }), "aria-colindex": ariaColIndex, children: formattedValue }, cols[index].name));
23
+ }) }, row.id));
24
+ }) }));
12
25
  };
13
26
  export default GridBody;
@@ -1,4 +1,4 @@
1
1
  import { FC } from "react";
2
- import { GridHeaderProps } from "./types";
2
+ import { GridHeaderProps } from "./internalTypes";
3
3
  declare const GridHeader: FC<GridHeaderProps>;
4
4
  export default GridHeader;