@omnigrid/core 0.1.17 → 0.1.19

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.
@@ -64,3 +64,20 @@ export declare function matchesColumnFilter(value: unknown, model: ColumnFilterM
64
64
  * @api
65
65
  */
66
66
  export declare function applyFilterModel<T>(data: T[], model: FilterModel, columns: ColumnDef<T>[]): T[];
67
+ /**
68
+ * Splits a quick filter query into comma-separated terms, trims whitespace,
69
+ * and matches every row against the union of searchable columns.
70
+ *
71
+ * Terms are matched case-insensitively using `String.prototype.includes`.
72
+ * A column participates when its `searchable` property is not `false`; the
73
+ * column's `valueGetter` takes precedence over `field` when resolving the
74
+ * cell value. An empty query returns the input array unchanged (same
75
+ * reference) so callers can short-circuit.
76
+ *
77
+ * @param data - Rows to filter.
78
+ * @param query - The raw quick filter query (may contain commas).
79
+ * @param columns - Column definitions used to resolve searchable columns.
80
+ * @returns Rows matching at least one term in at least one searchable column.
81
+ * @api
82
+ */
83
+ export declare function applyQuickFilter<T>(data: T[], query: string, columns: ColumnDef<T>[]): T[];
package/dist/filtering.js CHANGED
@@ -178,3 +178,40 @@ export function applyFilterModel(data, model, columns) {
178
178
  return data;
179
179
  return data.filter((row) => compiled.every(({ column, predicate }) => predicate(getCellValue(row, column))));
180
180
  }
181
+ /**
182
+ * Splits a quick filter query into comma-separated terms, trims whitespace,
183
+ * and matches every row against the union of searchable columns.
184
+ *
185
+ * Terms are matched case-insensitively using `String.prototype.includes`.
186
+ * A column participates when its `searchable` property is not `false`; the
187
+ * column's `valueGetter` takes precedence over `field` when resolving the
188
+ * cell value. An empty query returns the input array unchanged (same
189
+ * reference) so callers can short-circuit.
190
+ *
191
+ * @param data - Rows to filter.
192
+ * @param query - The raw quick filter query (may contain commas).
193
+ * @param columns - Column definitions used to resolve searchable columns.
194
+ * @returns Rows matching at least one term in at least one searchable column.
195
+ * @api
196
+ */
197
+ export function applyQuickFilter(data, query, columns) {
198
+ const trimmed = query.trim();
199
+ if (trimmed === "")
200
+ return data;
201
+ const terms = trimmed
202
+ .split(",")
203
+ .map((term) => term.trim().toLowerCase())
204
+ .filter((term) => term.length > 0);
205
+ if (terms.length === 0)
206
+ return data;
207
+ const searchable = flattenColumns(columns).filter((column) => column.searchable !== false);
208
+ if (searchable.length === 0)
209
+ return data;
210
+ return data.filter((row) => searchable.some((column) => {
211
+ const value = getCellValue(row, column);
212
+ if (value === undefined || value === null)
213
+ return false;
214
+ const text = String(value).toLowerCase();
215
+ return terms.some((term) => text.includes(term));
216
+ }));
217
+ }
package/dist/grid.d.ts CHANGED
@@ -64,6 +64,21 @@ export declare class Grid<T> implements GridApi<T> {
64
64
  getFilterModel(): FilterModel;
65
65
  setColumnFilter(field: string, condition: FilterCondition | null): void;
66
66
  clearFilters(): void;
67
+ /**
68
+ * Sets the global quick filter query string. The query is split on commas
69
+ * and matched case-insensitively against every column whose `searchable`
70
+ * property is not `false`, using the column's `valueGetter` when present.
71
+ * An empty string clears the quick filter. Emits `quickFilterChanged`.
72
+ * @param query - The quick filter query.
73
+ * @api
74
+ */
75
+ setQuickFilter(query: string): void;
76
+ /**
77
+ * Returns the current global quick filter query string.
78
+ * @returns The active quick filter query string.
79
+ * @api
80
+ */
81
+ getQuickFilter(): string;
67
82
  registerFilterMenu(): () => void;
68
83
  hasFilterMenu(): boolean;
69
84
  requestFilterMenu(columnId: string, anchor: UIPopupAnchor): void;
package/dist/grid.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { flattenColumns, getColumnGroups } from "./columns";
2
2
  import { EventBus } from "./events";
3
- import { applyFilterModel, isActiveCondition } from "./filtering";
3
+ import { applyFilterModel, applyQuickFilter, isActiveCondition } from "./filtering";
4
4
  import { PopupManager } from "./ui";
5
5
  import { evaluateAutoOverlay } from "./overlays";
6
6
  import { IconRegistry } from "./icons";
@@ -43,6 +43,7 @@ export class Grid {
43
43
  rowOverscan: options.rowOverscan ?? 5,
44
44
  columnOverscan: options.columnOverscan ?? 2,
45
45
  overlay: { type: null },
46
+ quickFilter: options.quickFilter ?? "",
46
47
  };
47
48
  this.store = new Store(state);
48
49
  this.licenseKey = options.licenseKey;
@@ -216,7 +217,11 @@ export class Grid {
216
217
  if (this.filteredDataCache !== null)
217
218
  return this.filteredDataCache;
218
219
  const state = this.getState();
219
- this.filteredDataCache = applyFilterModel(state.data, this.filterModel, state.columns);
220
+ let data = applyFilterModel(state.data, this.filterModel, state.columns);
221
+ if (state.quickFilter) {
222
+ data = applyQuickFilter(data, state.quickFilter, state.columns);
223
+ }
224
+ this.filteredDataCache = data;
220
225
  return this.filteredDataCache;
221
226
  }
222
227
  static cloneFilterModel(model) {
@@ -266,6 +271,35 @@ export class Grid {
266
271
  return;
267
272
  this.setFilterModel({});
268
273
  }
274
+ /**
275
+ * Sets the global quick filter query string. The query is split on commas
276
+ * and matched case-insensitively against every column whose `searchable`
277
+ * property is not `false`, using the column's `valueGetter` when present.
278
+ * An empty string clears the quick filter. Emits `quickFilterChanged`.
279
+ * @param query - The quick filter query.
280
+ * @api
281
+ */
282
+ setQuickFilter(query) {
283
+ this.assertActive();
284
+ const nextQuery = query ?? "";
285
+ if (this.store.getState().quickFilter === nextQuery)
286
+ return;
287
+ this.filteredDataCache = null;
288
+ this.processedDataCache = null;
289
+ this.revision += 1;
290
+ this.store.setState({ quickFilter: nextQuery });
291
+ this.scrollTo({ scrollTop: 0 });
292
+ this.recomputeOverlay();
293
+ this.events.emit("quickFilterChanged", nextQuery);
294
+ }
295
+ /**
296
+ * Returns the current global quick filter query string.
297
+ * @returns The active quick filter query string.
298
+ * @api
299
+ */
300
+ getQuickFilter() {
301
+ return this.store.getState().quickFilter;
302
+ }
269
303
  registerFilterMenu() {
270
304
  this.assertActive();
271
305
  this.filterMenuProviders += 1;
package/dist/icons.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { SlotNodeContent } from "./types";
2
- export type IconName = "chevron-left" | "chevron-right" | "chevron-up" | "chevron-down" | "chevron-first" | "chevron-last" | "arrow-up" | "arrow-down" | "arrow-up-down";
2
+ export type IconName = "chevron-left" | "chevron-right" | "chevron-up" | "chevron-down" | "chevron-first" | "chevron-last" | "arrow-up" | "arrow-down" | "arrow-up-down" | "filter" | "search";
3
3
  export type IconDefinition<T> = SlotNodeContent<T> | (() => SlotNodeContent<T>);
4
4
  /** Framework-agnostic registry of declarative SVG slot nodes. */
5
5
  export declare class IconRegistry<T> {
package/dist/icons.js CHANGED
@@ -25,6 +25,11 @@ const DEFAULT_ICON_PATHS = {
25
25
  { tag: "path", attrs: { d: "m21 8-4-4-4 4" } },
26
26
  { tag: "path", attrs: { d: "M17 4v16" } },
27
27
  ],
28
+ "filter": [{ tag: "path", attrs: { d: "M22 3H2l8 9.46V19l4 2v-8.54L22 3z" } }],
29
+ "search": [
30
+ { tag: "circle", attrs: { cx: "11", cy: "11", r: "8" } },
31
+ { tag: "path", attrs: { d: "m21 21-4.3-4.3" } },
32
+ ],
28
33
  };
29
34
  function createSvgIcon(name, paths) {
30
35
  return {
package/dist/index.d.ts CHANGED
@@ -7,10 +7,10 @@ export { Grid } from "./grid";
7
7
  export { Grid as GridCore } from "./grid";
8
8
  export { SlotManager } from "./slots";
9
9
  export { Store } from "./store";
10
- export { applyFilterModel, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
10
+ export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
11
11
  export type { ColumnFilterModel, FilterCondition, FilterModel, FilterOperator } from "./filtering";
12
12
  export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIInputControl, UIPopupAnchor, UIPopupDescriptor, UISelectControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui";
13
13
  export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
14
- export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnClassRules, ColumnDataType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GridApi, GridEvents, GridOptions, GridPlugin, GridState, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
14
+ export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnClassRules, ColumnDataType, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GridApi, GridEvents, GridOptions, GridPlugin, GridState, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
15
15
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
16
16
  export { Virtualizer } from "./virtualizer";
package/dist/index.js CHANGED
@@ -6,6 +6,6 @@ export { Grid } from "./grid";
6
6
  export { Grid as GridCore } from "./grid";
7
7
  export { SlotManager } from "./slots";
8
8
  export { Store } from "./store";
9
- export { applyFilterModel, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
9
+ export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
10
10
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
11
11
  export { Virtualizer } from "./virtualizer";
package/dist/slots.d.ts CHANGED
@@ -26,6 +26,7 @@ export declare class SlotManager<T> {
26
26
  mount(slot: SlotName, content: SlotProvider<T>, options?: SlotMountOptions): SlotMount<T>;
27
27
  /** Removes a mount by id within a slot. Returns true if found. */
28
28
  unmount(slot: SlotName, id: string): boolean;
29
+ private unmountFromSlot;
29
30
  /** Sorted copy of mounts for the slot. */
30
31
  getMounts(slot: SlotName): SlotMount<T>[];
31
32
  hasMounts(slot: SlotName): boolean;
package/dist/slots.js CHANGED
@@ -39,6 +39,16 @@ export class SlotManager {
39
39
  }
40
40
  /** Removes a mount by id within a slot. Returns true if found. */
41
41
  unmount(slot, id) {
42
+ let removed = this.unmountFromSlot(slot, id);
43
+ if (!removed && slot === "bottom") {
44
+ removed = this.unmountFromSlot("down", id);
45
+ }
46
+ else if (!removed && slot === "down") {
47
+ removed = this.unmountFromSlot("bottom", id);
48
+ }
49
+ return removed;
50
+ }
51
+ unmountFromSlot(slot, id) {
42
52
  const slotMounts = this.mounts.get(slot);
43
53
  if (!slotMounts)
44
54
  return false;
@@ -53,10 +63,23 @@ export class SlotManager {
53
63
  }
54
64
  /** Sorted copy of mounts for the slot. */
55
65
  getMounts(slot) {
56
- return [...(this.mounts.get(slot) ?? [])];
66
+ const direct = this.mounts.get(slot) ?? [];
67
+ if (slot === "bottom") {
68
+ const down = this.mounts.get("down") ?? [];
69
+ if (down.length > 0) {
70
+ return [...direct, ...down].sort((left, right) => (left.priority === right.priority ? 0 : left.priority < right.priority ? -1 : 1));
71
+ }
72
+ }
73
+ else if (slot === "down") {
74
+ const bottom = this.mounts.get("bottom") ?? [];
75
+ if (bottom.length > 0) {
76
+ return [...direct, ...bottom].sort((left, right) => (left.priority === right.priority ? 0 : left.priority < right.priority ? -1 : 1));
77
+ }
78
+ }
79
+ return [...direct];
57
80
  }
58
81
  hasMounts(slot) {
59
- return (this.mounts.get(slot)?.length ?? 0) > 0;
82
+ return this.getMounts(slot).length > 0;
60
83
  }
61
84
  clear(slot) {
62
85
  if (slot) {
package/dist/types.d.ts CHANGED
@@ -8,11 +8,26 @@ export type SortDirection = "asc" | "desc";
8
8
  export type CellAlign = "left" | "center" | "right";
9
9
  export type DataProcessor<T> = (data: T[]) => T[];
10
10
  /**
11
- * Data type of a column, used for filtering, formatting, and auto-detecting filter controls.
11
+ * Nature of the values stored in a column.
12
+ *
13
+ * It describes the data itself — never the filter UI. Used for sorting,
14
+ * formatting and to pick the default filter type of a column (a `number`
15
+ * column gets the numeric filter, and so on).
16
+ *
17
+ * @api
18
+ */
19
+ export type ColumnDataType = "text" | "number" | "date" | "boolean";
20
+ /**
21
+ * Kind of filter UI rendered for a column.
22
+ *
23
+ * - `text` / `number` / `date` — single value input with an operator drop-down;
24
+ * - `boolean` — All / Yes / No switch;
25
+ * - `set` — checklist of the distinct values of the column;
26
+ * - `custom` — filter registered by a third-party plugin.
12
27
  *
13
28
  * @api
14
29
  */
15
- export type ColumnDataType = "text" | "number" | "date" | "select" | "boolean";
30
+ export type ColumnFilterType = "text" | "number" | "date" | "boolean" | "set" | "custom";
16
31
  export interface RowRenderParams<T> {
17
32
  id: RowId;
18
33
  index: number;
@@ -149,6 +164,13 @@ interface BaseColumnDef<T> {
149
164
  resizable?: boolean;
150
165
  /** Custom renderer for this column's header. */
151
166
  headerRenderer?: (column: ColumnDef<T>) => unknown;
167
+ /**
168
+ * Whether this column participates in the global quick filter. Defaults to true.
169
+ * Columns with `searchable: false` are completely ignored by the global quick filter.
170
+ * @default true
171
+ * @api
172
+ */
173
+ searchable?: boolean;
152
174
  }
153
175
  export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
154
176
  /** Row property used as the cell value source. */
@@ -166,10 +188,20 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
166
188
  /** Whether this column can be sorted. */
167
189
  sortable?: boolean;
168
190
  /**
169
- * Data type of the column. When omitted, the grid attempts to infer the type
170
- * from data rows or filter options.
191
+ * Nature of the values in this column. When omitted, the filtering plugin
192
+ * infers it by sampling the data.
171
193
  */
172
194
  dataType?: ColumnDataType;
195
+ /**
196
+ * Kind of filter UI rendered for this column. When omitted, it is derived
197
+ * from `dataType` (and, failing that, from the sampled data).
198
+ */
199
+ filterType?: ColumnFilterType;
200
+ /**
201
+ * Identifier of a custom filter registered with the filtering plugin.
202
+ * Required when `filterType` is `"custom"`.
203
+ */
204
+ filterTypeId?: string;
173
205
  /**
174
206
  * Whether this column offers a filter menu. Set to `false` to opt the column out of
175
207
  * filtering UI (the header filter icon is hidden).
@@ -181,8 +213,8 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
181
213
  */
182
214
  allowedOperators?: FilterOperator[];
183
215
  /**
184
- * Fixed options for select / set filtering. When provided, the column
185
- * automatically defaults to `dataType: "select"`.
216
+ * Fixed option list used by the `"set"` filter. When provided, the column
217
+ * defaults to `filterType: "set"` unless `filterType` is set explicitly.
186
218
  */
187
219
  filterOptions?: Array<{
188
220
  label: string;
@@ -293,6 +325,11 @@ export interface GridOptions<T> {
293
325
  plugins?: GridPlugin<T>[];
294
326
  /** Initial filter model applied to the data pipeline. */
295
327
  filterModel?: FilterModel;
328
+ /**
329
+ * Initial global quick filter query string. Applied across every column
330
+ * whose `searchable` property is not `false`.
331
+ */
332
+ quickFilter?: string;
296
333
  /**
297
334
  * License key for Pro plugins. When provided, Pro plugins verify the
298
335
  * cryptographic signature and activate full functionality. When missing
@@ -414,6 +451,11 @@ export interface GridState<T> {
414
451
  columnOverscan: number;
415
452
  /** Active overlay state — updated automatically by the grid's overlay manager. */
416
453
  overlay: OverlayState;
454
+ /**
455
+ * Global quick filter query string. Applied across every column whose
456
+ * `searchable` property is not `false`. Empty string means no quick filter.
457
+ */
458
+ quickFilter: string;
417
459
  }
418
460
  export interface GridEvents<T> {
419
461
  stateChange: GridState<T>;
@@ -437,6 +479,8 @@ export interface GridEvents<T> {
437
479
  overlayChange: OverlayState;
438
480
  /** Fired after the filter model changed; the payload is a copy of the new model. */
439
481
  filterChanged: FilterModel;
482
+ /** Fired after the global quick filter changed; the payload is the new query string. */
483
+ quickFilterChanged: string;
440
484
  /** Fired when a popup is opened, updated (`descriptor`) or closed (`null`). */
441
485
  popupChange: UIPopupDescriptor | null;
442
486
  /** Fired when the user asks for a column's filter menu (e.g. clicks the header filter icon). */
@@ -520,7 +564,7 @@ export interface GridPlugin<T> {
520
564
  getRowClass?(params: RowRenderParams<T>): string | undefined;
521
565
  getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
522
566
  }
523
- export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom";
567
+ export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom" | "down";
524
568
  export type SlotPosition = "start" | "center" | "end";
525
569
  /**
526
570
  * Placement of a single UI block that a plugin mounts into a slot.
@@ -710,6 +754,20 @@ export interface GridApi<T> {
710
754
  * @api
711
755
  */
712
756
  clearFilters(): void;
757
+ /**
758
+ * Sets the global quick filter query string. The query is split on commas
759
+ * and matched case-insensitively against every column whose `searchable`
760
+ * property is not `false`, using the column's `valueGetter` when present.
761
+ * An empty string clears the quick filter. Emits `quickFilterChanged`.
762
+ * @param query - The quick filter query.
763
+ * @api
764
+ */
765
+ setQuickFilter(query: string): void;
766
+ /**
767
+ * Returns the current global quick filter query string.
768
+ * @api
769
+ */
770
+ getQuickFilter(): string;
713
771
  /**
714
772
  * Declares that a plugin provides a column filter menu. While at least one
715
773
  * provider is registered, adapters show the filter icon in column headers.
package/dist/ui.d.ts CHANGED
@@ -18,6 +18,19 @@ export interface UIControlBase {
18
18
  id: string;
19
19
  /** Visible label rendered next to the control. */
20
20
  label?: string;
21
+ /**
22
+ * Accessible name applied as `aria-label`; preferred over `label` when the
23
+ * visible label should stay hidden from the layout.
24
+ * @api
25
+ */
26
+ ariaLabel?: string;
27
+ /**
28
+ * Name of a core icon (e.g. `"filter"`) rendered to the left of the control body.
29
+ * Resolved by the adapter through the grid's icon registry; supported by
30
+ * input, select, multi-select and checkbox controls.
31
+ * @api
32
+ */
33
+ icon?: string;
21
34
  /** Disables the control. @default false */
22
35
  disabled?: boolean;
23
36
  /** Extra CSS class names. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",