@homebound/beam 2.130.0 → 2.131.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.
@@ -121,6 +121,7 @@ export declare type GridSortConfig<S> = {
121
121
  on: "client";
122
122
  /** The optional initial column (index in columns) and direction to sort. */
123
123
  initial?: [S | GridColumn<any>, Direction] | undefined;
124
+ caseSensitive?: boolean;
124
125
  } | {
125
126
  on: "server";
126
127
  /** The current sort by value + direction (if server-side sorting). */
@@ -113,14 +113,14 @@ function GridTable(props) {
113
113
  const columnSizes = (0, columnSizes_1.useSetupColumnSizes)(style, columns, tableRef, resizeTarget);
114
114
  // Make a single copy of our current collapsed state, so we'll have a single observer.
115
115
  const collapsedIds = (0, hooks_1.useComputed)(() => rowState.collapsedIds, [rowState]);
116
- const [sortState, setSortKey, sortOn] = (0, useSortState_1.useSortState)(columns, props.sorting);
116
+ const [sortState, setSortKey, sortOn, caseSensitive] = (0, useSortState_1.useSortState)(columns, props.sorting);
117
117
  const maybeSorted = (0, react_1.useMemo)(() => {
118
118
  if (sortOn === "client" && sortState) {
119
119
  // If using client-side sort, the sortState use S = number
120
- return (0, sortRows_1.sortRows)(columns, rows, sortState);
120
+ return (0, sortRows_1.sortRows)(columns, rows, sortState, caseSensitive);
121
121
  }
122
122
  return rows;
123
- }, [columns, rows, sortOn, sortState]);
123
+ }, [columns, rows, sortOn, sortState, caseSensitive]);
124
124
  let hasTotalsRow = false;
125
125
  // Filter rows - ensures parent rows remain in the list if any children match the filter.
126
126
  const filterRows = (0, react_1.useCallback)((acc, row) => {
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from "react";
2
2
  import { GridCellContent, GridColumn, GridDataRow, Kinded } from "./GridTable";
3
3
  import { SortOn, SortState } from "./useSortState";
4
- export declare function sortRows<R extends Kinded>(columns: GridColumn<R>[], rows: GridDataRow<R>[], sortState: SortState<number>): GridDataRow<R>[];
4
+ export declare function sortRows<R extends Kinded>(columns: GridColumn<R>[], rows: GridDataRow<R>[], sortState: SortState<number>, caseSensitive: boolean): GridDataRow<R>[];
5
5
  export declare function ensureClientSideSortValueIsSortable(sortOn: SortOn, isHeader: boolean, column: GridColumn<any>, idx: number, maybeContent: ReactNode | GridCellContent): void;
@@ -3,26 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ensureClientSideSortValueIsSortable = exports.sortRows = void 0;
4
4
  const GridTable_1 = require("./GridTable");
5
5
  // Returns a shallow copy of the `rows` parameter sorted based on `sortState`
6
- function sortRows(columns, rows, sortState) {
7
- const sorted = sortBatch(columns, rows, sortState);
6
+ function sortRows(columns, rows, sortState, caseSensitive) {
7
+ const sorted = sortBatch(columns, rows, sortState, caseSensitive);
8
8
  // Recursively sort child rows
9
9
  sorted.forEach((row, i) => {
10
10
  if (row.children) {
11
- sorted[i].children = sortRows(columns, row.children, sortState);
11
+ sorted[i].children = sortRows(columns, row.children, sortState, caseSensitive);
12
12
  }
13
13
  });
14
14
  return sorted;
15
15
  }
16
16
  exports.sortRows = sortRows;
17
- function sortBatch(columns, batch, sortState) {
17
+ function sortBatch(columns, batch, sortState, caseSensitive) {
18
18
  // When client-side sort, the sort value is the column index
19
19
  const [value, direction] = sortState;
20
20
  const column = columns[value];
21
21
  const invert = direction === "DESC";
22
22
  // Make a shallow copy for sorting to avoid mutating the original list
23
23
  return [...batch].sort((a, b) => {
24
- const v1 = sortValue((0, GridTable_1.applyRowFn)(column, a, {}, 0));
25
- const v2 = sortValue((0, GridTable_1.applyRowFn)(column, b, {}, 0));
24
+ const v1 = sortValue((0, GridTable_1.applyRowFn)(column, a, {}, 0), caseSensitive);
25
+ const v2 = sortValue((0, GridTable_1.applyRowFn)(column, b, {}, 0), caseSensitive);
26
26
  const v1e = v1 === null || v1 === undefined;
27
27
  const v2e = v2 === null || v2 === undefined;
28
28
  if (a.pin || b.pin) {
@@ -43,7 +43,7 @@ function sortBatch(columns, batch, sortState) {
43
43
  });
44
44
  }
45
45
  /** Look at a row and get its sort value. */
46
- function sortValue(value) {
46
+ function sortValue(value, caseSensitive) {
47
47
  // Check sortValue and then fallback on value
48
48
  let maybeFn = value;
49
49
  if (value && typeof value === "object") {
@@ -60,13 +60,14 @@ function sortValue(value) {
60
60
  }
61
61
  // Watch for functions that need to read from a potentially-changing proxy
62
62
  if (maybeFn instanceof Function) {
63
- return maybeFn();
63
+ maybeFn = maybeFn();
64
64
  }
65
- return maybeFn;
65
+ // If it is a string, then always lower case it for comparisons
66
+ return typeof maybeFn === "string" && !caseSensitive ? maybeFn.toLowerCase() : maybeFn;
66
67
  }
67
68
  function ensureClientSideSortValueIsSortable(sortOn, isHeader, column, idx, maybeContent) {
68
69
  if (process.env.NODE_ENV !== "production" && !isHeader && sortOn === "client" && column.clientSideSort !== false) {
69
- const value = sortValue(maybeContent);
70
+ const value = sortValue(maybeContent, false);
70
71
  if (!canClientSideSort(value)) {
71
72
  throw new Error(`Column ${idx} passed an unsortable value, use GridCellContent or clientSideSort=false`);
72
73
  }
@@ -10,5 +10,5 @@ import { Direction, GridColumn, GridSortConfig, Kinded } from "./GridTable";
10
10
  export declare type SortState<S> = readonly [S, Direction];
11
11
  export declare type SortOn = "client" | "server" | undefined;
12
12
  /** Small custom hook that wraps the "setSortColumn inverts the current sort" logic. */
13
- export declare function useSortState<R extends Kinded, S>(columns: GridColumn<R, S>[], sorting?: GridSortConfig<S>): [SortState<S> | undefined, (value: S) => void, SortOn];
13
+ export declare function useSortState<R extends Kinded, S>(columns: GridColumn<R, S>[], sorting?: GridSortConfig<S>): [SortState<S> | undefined, (value: S) => void, SortOn, boolean];
14
14
  export declare function deriveSortState<S>(currentSortState: SortState<S> | undefined, clickedKey: S, initialSortState: SortState<S> | undefined): SortState<S> | undefined;
@@ -47,7 +47,9 @@ function useSortState(columns, sorting) {
47
47
  },
48
48
  // Note that sorting.onSort is not listed here, so we bind to whatever the 1st sorting.onSort was
49
49
  [initialSortState, sortState, onSort]);
50
- return [sortState, setSortKey, sorting === null || sorting === void 0 ? void 0 : sorting.on];
50
+ // If sorting is done on the client, the by default the sort will NOT be case sensitive
51
+ const caseSensitive = (sorting === null || sorting === void 0 ? void 0 : sorting.on) === "client" ? !!sorting.caseSensitive : false;
52
+ return [sortState, setSortKey, sorting === null || sorting === void 0 ? void 0 : sorting.on, caseSensitive];
51
53
  }
52
54
  exports.useSortState = useSortState;
53
55
  // Exported for testing purposes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.130.0",
3
+ "version": "2.131.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",