@itwin/itwinui-react 2.12.15 → 2.12.16

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.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.12.16
4
+
5
+ ### Patch Changes
6
+
7
+ - fa3a1c35: Made Table's Ctrl+Shift click implementation more consistent with Windows Explorer's implementation.
8
+ - fa3a1c35: Fixed occasional mismatch between the Table's visually selected rows and Table state's selected rows
9
+ - 9f7f66a0: Memoized `useId` fallback for react 17, to prevent unnecessary rerenders.
10
+
3
11
  ## 2.12.15
4
12
 
5
13
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { ActionType, TableInstance, TableState } from 'react-table';
1
+ import type { ActionType, TableInstance, TableState, IdType } from 'react-table';
2
2
  /**
3
3
  * Handles selection when toggling a row (Ctrl click or checkbox click)
4
4
  */
@@ -9,7 +9,7 @@ export declare const onToggleHandler: <T extends Record<string, unknown>>(newSta
9
9
  export declare const onSingleSelectHandler: <T extends Record<string, unknown>>(state: TableState<T>, action: ActionType, instance?: TableInstance<T> | undefined, onSelect?: ((selectedData: T[] | undefined, tableState?: TableState<T> | undefined) => void) | undefined, isRowDisabled?: ((rowData: T) => boolean) | undefined) => {
10
10
  lastSelectedRowId: any;
11
11
  selectedRowIds: Record<string, boolean>;
12
- hiddenColumns?: import("react-table").IdType<T>[] | undefined;
12
+ hiddenColumns?: IdType<T>[] | undefined;
13
13
  columnResizing: {
14
14
  startX?: number | undefined;
15
15
  columnWidth?: number | undefined;
@@ -25,11 +25,11 @@ export declare const onSingleSelectHandler: <T extends Record<string, unknown>>(
25
25
  isScrolledToRight?: boolean | undefined;
26
26
  isScrolledToLeft?: boolean | undefined;
27
27
  };
28
- columnOrder: import("react-table").IdType<T>[];
29
- expanded: Record<import("react-table").IdType<T>, boolean>;
28
+ columnOrder: IdType<T>[];
29
+ expanded: Record<IdType<T>, boolean>;
30
30
  filters: import("react-table").Filters<T>;
31
31
  globalFilter: any;
32
- groupBy: import("react-table").IdType<T>[];
32
+ groupBy: IdType<T>[];
33
33
  pageSize: number;
34
34
  pageIndex: number;
35
35
  rowState: Record<string, {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.onShiftSelectHandler = exports.onSingleSelectHandler = exports.onToggleHandler = void 0;
4
4
  /**
5
5
  * Handles subrow selection and validation.
6
+ * - Calls onSelect() with selected data
6
7
  * - Subrow selection: Selecting a row and calling this method automatically selects all the subrows that can be selected
7
8
  * - Validation: Ensures that any disabled/unselectable row/subrow is not selected
8
9
  */
@@ -83,19 +84,21 @@ const onShiftSelectHandler = (state, action, instance, onSelect, isRowDisabled)
83
84
  startIndex = endIndex;
84
85
  endIndex = temp;
85
86
  }
87
+ const isLastSelectedRowIdSelected = state.lastSelectedRowId == null || // When no row is selected before shift click, start selecting from first row to clicked row
88
+ !!state.selectedRowIds[state.lastSelectedRowId];
86
89
  // If ctrl + shift click, do not lose previous selection
87
90
  // If shift click, start new selection
88
91
  const selectedRowIds = !!action.ctrlPressed
89
- ? state.selectedRowIds
92
+ ? { ...state.selectedRowIds }
90
93
  : {};
91
- // 1. Select all rows between start and end
94
+ // 1. All rows between start and end are assigned the state of the last selected row
92
95
  instance.flatRows
93
96
  .slice(startIndex, endIndex + 1)
94
- .forEach((r) => (selectedRowIds[r.id] = true));
95
- // 2. Select all children of the last row (endIndex)
97
+ .forEach((r) => (selectedRowIds[r.id] = isLastSelectedRowIdSelected));
98
+ // 2. All children of the last row (endIndex) also are assigned the state of the last selected row
96
99
  // Since lastRow's children come after endIndex + 1 (not selected in step 1)
97
100
  const handleRow = (row) => {
98
- selectedRowIds[row.id] = true;
101
+ selectedRowIds[row.id] = isLastSelectedRowIdSelected;
99
102
  row.subRows.forEach((r) => handleRow(r));
100
103
  };
101
104
  handleRow(instance.flatRows[endIndex]);
@@ -43,4 +43,4 @@ exports.useId = useId;
43
43
  // This is needed to avoid bundlers trying to import non-existing export.
44
44
  // Read more: https://github.com/webpack/webpack/issues/14814
45
45
  const _React = React;
46
- const useUniqueValue = (_a = _React.useId) !== null && _a !== void 0 ? _a : (() => (0, numbers_js_1.getRandomValue)(10));
46
+ const useUniqueValue = (_a = _React.useId) !== null && _a !== void 0 ? _a : (() => React.useMemo(() => (0, numbers_js_1.getRandomValue)(10), []));
@@ -1,4 +1,4 @@
1
- import type { ActionType, TableInstance, TableState } from 'react-table';
1
+ import type { ActionType, TableInstance, TableState, IdType } from 'react-table';
2
2
  /**
3
3
  * Handles selection when toggling a row (Ctrl click or checkbox click)
4
4
  */
@@ -9,7 +9,7 @@ export declare const onToggleHandler: <T extends Record<string, unknown>>(newSta
9
9
  export declare const onSingleSelectHandler: <T extends Record<string, unknown>>(state: TableState<T>, action: ActionType, instance?: TableInstance<T> | undefined, onSelect?: ((selectedData: T[] | undefined, tableState?: TableState<T> | undefined) => void) | undefined, isRowDisabled?: ((rowData: T) => boolean) | undefined) => {
10
10
  lastSelectedRowId: any;
11
11
  selectedRowIds: Record<string, boolean>;
12
- hiddenColumns?: import("react-table").IdType<T>[] | undefined;
12
+ hiddenColumns?: IdType<T>[] | undefined;
13
13
  columnResizing: {
14
14
  startX?: number | undefined;
15
15
  columnWidth?: number | undefined;
@@ -25,11 +25,11 @@ export declare const onSingleSelectHandler: <T extends Record<string, unknown>>(
25
25
  isScrolledToRight?: boolean | undefined;
26
26
  isScrolledToLeft?: boolean | undefined;
27
27
  };
28
- columnOrder: import("react-table").IdType<T>[];
29
- expanded: Record<import("react-table").IdType<T>, boolean>;
28
+ columnOrder: IdType<T>[];
29
+ expanded: Record<IdType<T>, boolean>;
30
30
  filters: import("react-table").Filters<T>;
31
31
  globalFilter: any;
32
- groupBy: import("react-table").IdType<T>[];
32
+ groupBy: IdType<T>[];
33
33
  pageSize: number;
34
34
  pageIndex: number;
35
35
  rowState: Record<string, {
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Handles subrow selection and validation.
3
+ * - Calls onSelect() with selected data
3
4
  * - Subrow selection: Selecting a row and calling this method automatically selects all the subrows that can be selected
4
5
  * - Validation: Ensures that any disabled/unselectable row/subrow is not selected
5
6
  */
@@ -78,19 +79,21 @@ export const onShiftSelectHandler = (state, action, instance, onSelect, isRowDis
78
79
  startIndex = endIndex;
79
80
  endIndex = temp;
80
81
  }
82
+ const isLastSelectedRowIdSelected = state.lastSelectedRowId == null || // When no row is selected before shift click, start selecting from first row to clicked row
83
+ !!state.selectedRowIds[state.lastSelectedRowId];
81
84
  // If ctrl + shift click, do not lose previous selection
82
85
  // If shift click, start new selection
83
86
  const selectedRowIds = !!action.ctrlPressed
84
- ? state.selectedRowIds
87
+ ? { ...state.selectedRowIds }
85
88
  : {};
86
- // 1. Select all rows between start and end
89
+ // 1. All rows between start and end are assigned the state of the last selected row
87
90
  instance.flatRows
88
91
  .slice(startIndex, endIndex + 1)
89
- .forEach((r) => (selectedRowIds[r.id] = true));
90
- // 2. Select all children of the last row (endIndex)
92
+ .forEach((r) => (selectedRowIds[r.id] = isLastSelectedRowIdSelected));
93
+ // 2. All children of the last row (endIndex) also are assigned the state of the last selected row
91
94
  // Since lastRow's children come after endIndex + 1 (not selected in step 1)
92
95
  const handleRow = (row) => {
93
- selectedRowIds[row.id] = true;
96
+ selectedRowIds[row.id] = isLastSelectedRowIdSelected;
94
97
  row.subRows.forEach((r) => handleRow(r));
95
98
  };
96
99
  handleRow(instance.flatRows[endIndex]);
@@ -16,4 +16,4 @@ export const useId = () => {
16
16
  // This is needed to avoid bundlers trying to import non-existing export.
17
17
  // Read more: https://github.com/webpack/webpack/issues/14814
18
18
  const _React = React;
19
- const useUniqueValue = (_a = _React.useId) !== null && _a !== void 0 ? _a : (() => getRandomValue(10));
19
+ const useUniqueValue = (_a = _React.useId) !== null && _a !== void 0 ? _a : (() => React.useMemo(() => getRandomValue(10), []));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "2.12.15",
3
+ "version": "2.12.16",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "main": "cjs/index.js",