@tensor_1/react 2.49.1 → 2.51.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.
@@ -24,8 +24,10 @@ declare function multiSort<T extends Row>(rows: readonly T[], keys: readonly Sor
24
24
  declare function nextSortDir(current: SortDir | 'none' | undefined): SortDir | 'none';
25
25
  /**
26
26
  * Toggle a field within a multi-sort key list. Without shift, it replaces the
27
- * list with just this field (cycling its direction); with shift, it adds/updates
28
- * the field as a secondary key (removing it when it cycles back to none).
27
+ * list with just this field (cycling its direction); with shift, a new field is
28
+ * appended as the last key, an existing key turns in place (it keeps its priority,
29
+ * as TanStack Table and TENSOR's DataTable do; 2.50, HAR-2623) and is removed when
30
+ * it cycles back to none.
29
31
  */
30
32
  declare function toggleSort(keys: readonly SortKey[], field: string, additive?: boolean): SortKey[];
31
33
  type FilterKind = 'enum' | 'text' | 'number' | 'date' | 'boolean';
@@ -37,6 +39,15 @@ interface ColumnFilter {
37
39
  /** value(s): a scalar, an array (enum / between), or [min,max] for between */
38
40
  value: Primitive | Primitive[];
39
41
  }
42
+ /**
43
+ * An `enum` `FilterValue` (what `FilterEditor` and `DataWorkspace` filters hold) as the engine's
44
+ * `ColumnFilter` for `field` (HAR-2631): `is-none-of` maps to `isNoneOf`, anything else to `isAnyOf`.
45
+ */
46
+ declare function enumColumnFilter(field: string, value: {
47
+ kind: 'enum';
48
+ values: readonly string[];
49
+ operator?: 'is-any-of' | 'is-none-of';
50
+ }): ColumnFilter;
40
51
  declare function matchFilter(row: Row, f: ColumnFilter): boolean;
41
52
  /** Keep rows that satisfy EVERY active filter (AND across columns). */
42
53
  declare function applyFilters<T extends Row>(rows: readonly T[], filters: readonly ColumnFilter[]): T[];
@@ -93,4 +104,4 @@ declare function togglePage(selected: ReadonlySet<string>, pageIds: readonly str
93
104
  /** Pinned rows (kept present regardless of filter/sort) hoisted above the rest. */
94
105
  declare function mergePinned<T extends Row>(all: readonly T[], visible: readonly T[], pinnedIds: ReadonlySet<string>, idField?: string): T[];
95
106
 
96
- export { type ColumnFilter, type FilterKind, type FilterOp, type Primitive, type Row, type Segment, type SelectAllState, type SortDir, type SortKey, type ViewState, type VirtualWindow, applyFilters, clampWidth, highlightSegments, matchFilter, mergePinned, multiSort, nextSortDir, parseView, reorder, searchRows, selectAllState, serializeView, shouldVirtualize, toggleId, togglePage, toggleSort, virtualWindow };
107
+ export { type ColumnFilter, type FilterKind, type FilterOp, type Primitive, type Row, type Segment, type SelectAllState, type SortDir, type SortKey, type ViewState, type VirtualWindow, applyFilters, clampWidth, enumColumnFilter, highlightSegments, matchFilter, mergePinned, multiSort, nextSortDir, parseView, reorder, searchRows, selectAllState, serializeView, shouldVirtualize, toggleId, togglePage, toggleSort, virtualWindow };
@@ -25,8 +25,12 @@ function toggleSort(keys, field, additive = false) {
25
25
  const existing = keys.find((k) => k.field === field);
26
26
  const dir = nextSortDir(existing?.dir);
27
27
  if (!additive) return dir === "none" ? [] : [{ field, dir }];
28
- const rest = keys.filter((k) => k.field !== field);
29
- return dir === "none" ? rest : [...rest, { field, dir }];
28
+ if (dir === "none") return keys.filter((k) => k.field !== field);
29
+ if (!existing) return [...keys, { field, dir }];
30
+ return keys.map((k) => k.field === field ? { field, dir } : k);
31
+ }
32
+ function enumColumnFilter(field, value) {
33
+ return { field, kind: "enum", op: value.operator === "is-none-of" ? "isNoneOf" : "isAnyOf", value: [...value.values] };
30
34
  }
31
35
  function asNum(v) {
32
36
  return typeof v === "number" ? v : Number(v);
@@ -236,6 +240,7 @@ function mergePinned(all, visible, pinnedIds, idField = "id") {
236
240
  export {
237
241
  applyFilters,
238
242
  clampWidth,
243
+ enumColumnFilter,
239
244
  highlightSegments,
240
245
  matchFilter,
241
246
  mergePinned,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tensor_1/react",
3
- "version": "2.49.1",
3
+ "version": "2.51.0",
4
4
  "description": "Thin React wrappers over the UIx v2 CSS component library.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",