@omnigrid/core 0.1.16 → 0.1.18

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.
@@ -0,0 +1,83 @@
1
+ import type { ColumnDef } from "./types";
2
+ /**
3
+ * Comparison operators supported by the core filter engine.
4
+ *
5
+ * @api
6
+ */
7
+ export type FilterOperator = "contains" | "notContains" | "equals" | "notEqual" | "startsWith" | "endsWith" | "greaterThan" | "greaterThanOrEqual" | "lessThan" | "lessThanOrEqual" | "inRange" | "in" | "blank" | "notBlank" | "isEmpty" | "isNotEmpty";
8
+ /**
9
+ * A single filter predicate applied to one column.
10
+ *
11
+ * Conditions whose required operand is missing (`undefined`, `null` or an empty
12
+ * string) are treated as inactive and let every row through, so half-typed
13
+ * input never blanks the grid.
14
+ *
15
+ * @api
16
+ */
17
+ export interface FilterCondition {
18
+ /** Comparison operator. */
19
+ operator: FilterOperator;
20
+ /** Primary operand. For `in` it is an array of accepted values. */
21
+ value?: unknown;
22
+ /** Upper bound operand, used by `inRange` (inclusive). */
23
+ valueTo?: unknown;
24
+ /** Makes text operators case sensitive. @default false */
25
+ caseSensitive?: boolean;
26
+ }
27
+ /**
28
+ * Filter state of one column: one or more conditions combined with `logic`.
29
+ *
30
+ * @api
31
+ */
32
+ export interface ColumnFilterModel {
33
+ /** Conditions evaluated against the column value. */
34
+ conditions: FilterCondition[];
35
+ /** How multiple conditions combine. @default "and" */
36
+ logic?: "and" | "or";
37
+ }
38
+ /**
39
+ * Filter state of the whole grid, keyed by column id (or column field).
40
+ * Columns are combined with logical AND.
41
+ *
42
+ * @api
43
+ */
44
+ export type FilterModel = Record<string, ColumnFilterModel>;
45
+ /** True when the condition carries enough information to be evaluated. */
46
+ export declare function isActiveCondition(condition: FilterCondition): boolean;
47
+ /** Returns true when the model contains at least one active condition. */
48
+ export declare function isFilterModelActive(model: FilterModel): boolean;
49
+ /**
50
+ * Evaluates a single value against a column filter model. Exposed so plugins
51
+ * and server-side adapters can reuse the exact core semantics.
52
+ *
53
+ * @api
54
+ */
55
+ export declare function matchesColumnFilter(value: unknown, model: ColumnFilterModel): boolean;
56
+ /**
57
+ * Applies a filter model to a dataset. Predicates are compiled once per call, not
58
+ * per row. Returns the input array (same reference) when no condition is active.
59
+ *
60
+ * @param data - Raw rows.
61
+ * @param model - Active filter model.
62
+ * @param columns - Column definitions used to resolve cell values.
63
+ * @returns Rows matching every column filter.
64
+ * @api
65
+ */
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[];
@@ -0,0 +1,217 @@
1
+ import { flattenColumns, getCellValue } from "./columns";
2
+ function isEmptyOperand(value) {
3
+ return value === undefined || value === null || value === "";
4
+ }
5
+ function isBlank(value) {
6
+ return value === undefined || value === null || value === "";
7
+ }
8
+ /** True when the condition carries enough information to be evaluated. */
9
+ export function isActiveCondition(condition) {
10
+ switch (condition.operator) {
11
+ case "blank":
12
+ return true;
13
+ case "notBlank":
14
+ return true;
15
+ case "isEmpty":
16
+ return true;
17
+ case "isNotEmpty":
18
+ return true;
19
+ case "inRange":
20
+ return !isEmptyOperand(condition.value) || !isEmptyOperand(condition.valueTo);
21
+ case "in":
22
+ return Array.isArray(condition.value);
23
+ default:
24
+ return !isEmptyOperand(condition.value);
25
+ }
26
+ }
27
+ /** Returns true when the model contains at least one active condition. */
28
+ export function isFilterModelActive(model) {
29
+ return Object.values(model).some((entry) => entry.conditions.some(isActiveCondition));
30
+ }
31
+ function toComparable(value) {
32
+ if (typeof value === "number")
33
+ return value;
34
+ if (value instanceof Date)
35
+ return value.getTime();
36
+ if (typeof value === "boolean")
37
+ return value ? 1 : 0;
38
+ return String(value);
39
+ }
40
+ /** Compares a cell value to an operand; numeric when both sides are numeric, textual otherwise. */
41
+ function compareValues(cell, operand) {
42
+ const left = toComparable(cell);
43
+ let right = toComparable(operand);
44
+ if (typeof left === "number") {
45
+ if (typeof right === "string")
46
+ right = right.trim() === "" ? Number.NaN : Number(right);
47
+ return left - right;
48
+ }
49
+ if (typeof right === "number") {
50
+ const parsed = Number(left);
51
+ return parsed - right;
52
+ }
53
+ const leftNumber = Number(left);
54
+ const rightNumber = Number(right);
55
+ if (left.trim() !== "" && right.trim() !== "" && Number.isFinite(leftNumber) && Number.isFinite(rightNumber))
56
+ return leftNumber - rightNumber;
57
+ return left.localeCompare(right, undefined, { numeric: true, sensitivity: "base" });
58
+ }
59
+ function normalizeText(value, caseSensitive) {
60
+ const text = value instanceof Date ? value.toISOString() : String(value);
61
+ return caseSensitive ? text : text.toLowerCase();
62
+ }
63
+ function valuesEqual(cell, operand, caseSensitive) {
64
+ if (typeof cell === "number" || cell instanceof Date || typeof cell === "boolean") {
65
+ const result = compareValues(cell, operand);
66
+ return result === 0;
67
+ }
68
+ return normalizeText(cell, caseSensitive) === normalizeText(operand, caseSensitive);
69
+ }
70
+ /** Compiles a condition into a value predicate; `null` means the condition is inactive. */
71
+ function compileCondition(condition) {
72
+ if (!isActiveCondition(condition))
73
+ return null;
74
+ const caseSensitive = condition.caseSensitive ?? false;
75
+ const operand = condition.value;
76
+ const text = isEmptyOperand(operand) ? "" : normalizeText(operand, caseSensitive);
77
+ switch (condition.operator) {
78
+ case "blank":
79
+ case "isEmpty":
80
+ return (value) => isBlank(value);
81
+ case "notBlank":
82
+ case "isNotEmpty":
83
+ return (value) => !isBlank(value);
84
+ case "contains":
85
+ return (value) => !isBlank(value) && normalizeText(value, caseSensitive).includes(text);
86
+ case "notContains":
87
+ return (value) => isBlank(value) || !normalizeText(value, caseSensitive).includes(text);
88
+ case "startsWith":
89
+ return (value) => !isBlank(value) && normalizeText(value, caseSensitive).startsWith(text);
90
+ case "endsWith":
91
+ return (value) => !isBlank(value) && normalizeText(value, caseSensitive).endsWith(text);
92
+ case "equals":
93
+ return (value) => !isBlank(value) && valuesEqual(value, operand, caseSensitive);
94
+ case "notEqual":
95
+ return (value) => isBlank(value) || !valuesEqual(value, operand, caseSensitive);
96
+ case "greaterThan":
97
+ return (value) => !isBlank(value) && compareValues(value, operand) > 0;
98
+ case "greaterThanOrEqual":
99
+ return (value) => !isBlank(value) && compareValues(value, operand) >= 0;
100
+ case "lessThan":
101
+ return (value) => !isBlank(value) && compareValues(value, operand) < 0;
102
+ case "lessThanOrEqual":
103
+ return (value) => !isBlank(value) && compareValues(value, operand) <= 0;
104
+ case "inRange": {
105
+ const hasFrom = !isEmptyOperand(condition.value);
106
+ const hasTo = !isEmptyOperand(condition.valueTo);
107
+ return (value) => {
108
+ if (isBlank(value))
109
+ return false;
110
+ if (hasFrom && compareValues(value, condition.value) < 0)
111
+ return false;
112
+ if (hasTo && compareValues(value, condition.valueTo) > 0)
113
+ return false;
114
+ return true;
115
+ };
116
+ }
117
+ case "in": {
118
+ const accepted = condition.value;
119
+ return (value) => accepted.some((item) => valuesEqual(value, item, caseSensitive));
120
+ }
121
+ default:
122
+ return null;
123
+ }
124
+ }
125
+ /**
126
+ * Evaluates a single value against a column filter model. Exposed so plugins
127
+ * and server-side adapters can reuse the exact core semantics.
128
+ *
129
+ * @api
130
+ */
131
+ export function matchesColumnFilter(value, model) {
132
+ const predicates = [];
133
+ for (const condition of model.conditions) {
134
+ const predicate = compileCondition(condition);
135
+ if (predicate)
136
+ predicates.push(predicate);
137
+ }
138
+ if (predicates.length === 0)
139
+ return true;
140
+ return model.logic === "or" ? predicates.some((p) => p(value)) : predicates.every((p) => p(value));
141
+ }
142
+ /** Resolves a model key to a leaf column by id first, then by field. */
143
+ function resolveColumn(columns, key) {
144
+ return columns.find((column) => column.id === key) ?? columns.find((column) => column.field === key);
145
+ }
146
+ /**
147
+ * Applies a filter model to a dataset. Predicates are compiled once per call, not
148
+ * per row. Returns the input array (same reference) when no condition is active.
149
+ *
150
+ * @param data - Raw rows.
151
+ * @param model - Active filter model.
152
+ * @param columns - Column definitions used to resolve cell values.
153
+ * @returns Rows matching every column filter.
154
+ * @api
155
+ */
156
+ export function applyFilterModel(data, model, columns) {
157
+ const leaves = flattenColumns(columns);
158
+ const compiled = [];
159
+ for (const [key, entry] of Object.entries(model)) {
160
+ const column = resolveColumn(leaves, key);
161
+ if (!column)
162
+ continue;
163
+ const predicates = [];
164
+ for (const condition of entry.conditions) {
165
+ const predicate = compileCondition(condition);
166
+ if (predicate)
167
+ predicates.push(predicate);
168
+ }
169
+ if (predicates.length === 0)
170
+ continue;
171
+ const isOr = entry.logic === "or";
172
+ compiled.push({
173
+ column,
174
+ predicate: (value) => (isOr ? predicates.some((p) => p(value)) : predicates.every((p) => p(value))),
175
+ });
176
+ }
177
+ if (compiled.length === 0)
178
+ return data;
179
+ return data.filter((row) => compiled.every(({ column, predicate }) => predicate(getCellValue(row, column))));
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
@@ -1,3 +1,5 @@
1
+ import type { FilterCondition, FilterModel } from "./filtering";
2
+ import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
1
3
  import { IconRegistry } from "./icons";
2
4
  import { SlotManager } from "./slots";
3
5
  import type { DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHoverEvent, RowId, ScrollPosition, SlotMount, SlotName, ViewportData, ViewportState } from "./types";
@@ -13,6 +15,11 @@ export declare class Grid<T> implements GridApi<T> {
13
15
  readonly slots: SlotManager<T>;
14
16
  readonly icons: IconRegistry<T>;
15
17
  private processedDataCache;
18
+ /** Output of the built-in filter stage; sits in front of every data processor. */
19
+ private filteredDataCache;
20
+ private filterModel;
21
+ private filterMenuProviders;
22
+ private readonly popups;
16
23
  private revision;
17
24
  private destroyed;
18
25
  /**
@@ -51,6 +58,33 @@ export declare class Grid<T> implements GridApi<T> {
51
58
  scrollTo(position: Partial<ScrollPosition>): void;
52
59
  getViewportData(): ViewportData<T>;
53
60
  getProcessedData(): T[];
61
+ private getFilteredData;
62
+ private static cloneFilterModel;
63
+ setFilterModel(model: FilterModel): void;
64
+ getFilterModel(): FilterModel;
65
+ setColumnFilter(field: string, condition: FilterCondition | null): void;
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;
82
+ registerFilterMenu(): () => void;
83
+ hasFilterMenu(): boolean;
84
+ requestFilterMenu(columnId: string, anchor: UIPopupAnchor): void;
85
+ openPopup(descriptor: UIPopupDescriptor): void;
86
+ closePopup(): void;
87
+ getPopup(): UIPopupDescriptor | null;
54
88
  getRowId(row: T, index: number): RowId;
55
89
  setData(data: T[] | null | undefined): void;
56
90
  /**
package/dist/grid.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { flattenColumns, getColumnGroups } from "./columns";
2
2
  import { EventBus } from "./events";
3
+ import { applyFilterModel, applyQuickFilter, isActiveCondition } from "./filtering";
4
+ import { PopupManager } from "./ui";
3
5
  import { evaluateAutoOverlay } from "./overlays";
4
6
  import { IconRegistry } from "./icons";
5
7
  import { SlotManager } from "./slots";
@@ -13,6 +15,11 @@ export class Grid {
13
15
  this.dataProcessors = new Set();
14
16
  this.icons = new IconRegistry();
15
17
  this.processedDataCache = null;
18
+ /** Output of the built-in filter stage; sits in front of every data processor. */
19
+ this.filteredDataCache = null;
20
+ this.filterModel = {};
21
+ this.filterMenuProviders = 0;
22
+ this.popups = new PopupManager((popup) => this.events.emit("popupChange", popup));
16
23
  this.revision = 0;
17
24
  this.destroyed = false;
18
25
  this.loading = false;
@@ -36,12 +43,15 @@ export class Grid {
36
43
  rowOverscan: options.rowOverscan ?? 5,
37
44
  columnOverscan: options.columnOverscan ?? 2,
38
45
  overlay: { type: null },
46
+ quickFilter: options.quickFilter ?? "",
39
47
  };
40
48
  this.store = new Store(state);
41
49
  this.licenseKey = options.licenseKey;
42
50
  this.resolveRowId = options.getRowId ?? ((_row, index) => index);
43
51
  this.loading = options.loading ?? false;
44
52
  this.hasData = options.data !== undefined && options.data !== null;
53
+ if (options.filterModel)
54
+ this.filterModel = Grid.cloneFilterModel(options.filterModel);
45
55
  this.virtualizer = new Virtualizer({
46
56
  rowHeight: state.rowHeight,
47
57
  rowOverscan: state.rowOverscan,
@@ -193,15 +203,135 @@ export class Grid {
193
203
  };
194
204
  }
195
205
  getProcessedData() {
196
- // Cache is invalidated by setData / setColumns / processor registration.
197
- // During scroll the pipeline is NOT re-run — critical optimization for
198
- // DOM Pool operation with large row counts.
206
+ // Pipeline: raw data -> filter engine -> processors (sort, ...) -> virtualization.
207
+ // Cache is invalidated by setData / setColumns / filter changes / processor
208
+ // registration. During scroll the pipeline is NOT re-run — critical
209
+ // optimization for DOM Pool operation with large row counts.
199
210
  if (this.processedDataCache !== null)
200
211
  return this.processedDataCache;
201
- const result = [...this.dataProcessors].reduce((data, processor) => processor(data), this.getState().data);
212
+ const result = [...this.dataProcessors].reduce((data, processor) => processor(data), this.getFilteredData());
202
213
  this.processedDataCache = result;
203
214
  return result;
204
215
  }
216
+ getFilteredData() {
217
+ if (this.filteredDataCache !== null)
218
+ return this.filteredDataCache;
219
+ const state = this.getState();
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;
225
+ return this.filteredDataCache;
226
+ }
227
+ static cloneFilterModel(model) {
228
+ const clone = {};
229
+ for (const [key, entry] of Object.entries(model)) {
230
+ const conditions = entry.conditions.map((condition) => ({ ...condition }));
231
+ clone[key] = entry.logic ? { conditions, logic: entry.logic } : { conditions };
232
+ }
233
+ return clone;
234
+ }
235
+ setFilterModel(model) {
236
+ this.assertActive();
237
+ const next = {};
238
+ for (const [key, entry] of Object.entries(Grid.cloneFilterModel(model))) {
239
+ if (entry.conditions.length > 0)
240
+ next[key] = entry;
241
+ }
242
+ this.filterModel = next;
243
+ this.filteredDataCache = null;
244
+ this.processedDataCache = null;
245
+ this.revision += 1;
246
+ this.scrollTo({ scrollTop: 0 });
247
+ this.store.setState({});
248
+ this.recomputeOverlay();
249
+ this.events.emit("filterChanged", this.getFilterModel());
250
+ }
251
+ getFilterModel() {
252
+ return Grid.cloneFilterModel(this.filterModel);
253
+ }
254
+ setColumnFilter(field, condition) {
255
+ this.assertActive();
256
+ const next = this.getFilterModel();
257
+ if (condition === null || !isActiveCondition(condition)) {
258
+ if (!(field in next))
259
+ return;
260
+ delete next[field];
261
+ }
262
+ else {
263
+ const entry = { conditions: [{ ...condition }] };
264
+ next[field] = entry;
265
+ }
266
+ this.setFilterModel(next);
267
+ }
268
+ clearFilters() {
269
+ this.assertActive();
270
+ if (Object.keys(this.filterModel).length === 0)
271
+ return;
272
+ this.setFilterModel({});
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
+ }
303
+ registerFilterMenu() {
304
+ this.assertActive();
305
+ this.filterMenuProviders += 1;
306
+ this.refresh();
307
+ let removed = false;
308
+ return () => {
309
+ if (removed)
310
+ return;
311
+ removed = true;
312
+ this.filterMenuProviders -= 1;
313
+ if (!this.destroyed)
314
+ this.refresh();
315
+ };
316
+ }
317
+ hasFilterMenu() {
318
+ return this.filterMenuProviders > 0;
319
+ }
320
+ requestFilterMenu(columnId, anchor) {
321
+ this.assertActive();
322
+ this.events.emit("filterMenuRequest", { columnId, anchor });
323
+ }
324
+ openPopup(descriptor) {
325
+ this.assertActive();
326
+ this.popups.open(descriptor);
327
+ }
328
+ closePopup() {
329
+ this.assertActive();
330
+ this.popups.close();
331
+ }
332
+ getPopup() {
333
+ return this.popups.get();
334
+ }
205
335
  getRowId(row, index) {
206
336
  return this.resolveRowId(row, index);
207
337
  }
@@ -210,6 +340,7 @@ export class Grid {
210
340
  this.loadError = undefined;
211
341
  this.hasData = data !== undefined && data !== null;
212
342
  const nextData = data ?? [];
343
+ this.filteredDataCache = null;
213
344
  this.processedDataCache = null;
214
345
  this.revision += 1;
215
346
  this.store.setState({ data: nextData });
@@ -230,6 +361,7 @@ export class Grid {
230
361
  const currentData = this.store.getState().data;
231
362
  const nextData = [...currentData, ...rows];
232
363
  this.hasData = true;
364
+ this.filteredDataCache = null;
233
365
  this.processedDataCache = null;
234
366
  this.revision += 1;
235
367
  this.store.setState({ data: nextData });
@@ -293,6 +425,7 @@ export class Grid {
293
425
  }
294
426
  setColumns(columns) {
295
427
  this.assertActive();
428
+ this.filteredDataCache = null;
296
429
  this.processedDataCache = null;
297
430
  this.revision += 1;
298
431
  this.store.setState({ columns });
@@ -458,6 +591,8 @@ export class Grid {
458
591
  this.cleanupPlugins.forEach((cleanup) => cleanup());
459
592
  this.cleanupPlugins.clear();
460
593
  this.dataProcessors.clear();
594
+ this.popups.close();
595
+ this.filteredDataCache = null;
461
596
  this.processedDataCache = null;
462
597
  this.overlayState = { type: null };
463
598
  this.overlayManual = false;
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,7 +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, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
11
+ export type { ColumnFilterModel, FilterCondition, FilterModel, FilterOperator } from "./filtering";
12
+ export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIInputControl, UIPopupAnchor, UIPopupDescriptor, UISelectControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui";
10
13
  export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
11
- export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnClassRules, 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, 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";
12
15
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
13
16
  export { Virtualizer } from "./virtualizer";
package/dist/index.js CHANGED
@@ -6,5 +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, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
9
10
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
10
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
@@ -1,10 +1,18 @@
1
1
  import type { OverlayOptions, OverlayState, OverlayType } from "./overlays";
2
2
  import type { SlotManager } from "./slots";
3
3
  import type { IconRegistry } from "./icons";
4
+ import type { FilterCondition, FilterModel, FilterOperator } from "./filtering";
5
+ import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
4
6
  export type RowId = string | number;
5
7
  export type SortDirection = "asc" | "desc";
6
8
  export type CellAlign = "left" | "center" | "right";
7
9
  export type DataProcessor<T> = (data: T[]) => T[];
10
+ /**
11
+ * Data type of a column, used for filtering, formatting, and auto-detecting filter controls.
12
+ *
13
+ * @api
14
+ */
15
+ export type ColumnDataType = "text" | "number" | "date" | "select" | "boolean";
8
16
  export interface RowRenderParams<T> {
9
17
  id: RowId;
10
18
  index: number;
@@ -141,6 +149,13 @@ interface BaseColumnDef<T> {
141
149
  resizable?: boolean;
142
150
  /** Custom renderer for this column's header. */
143
151
  headerRenderer?: (column: ColumnDef<T>) => unknown;
152
+ /**
153
+ * Whether this column participates in the global quick filter. Defaults to true.
154
+ * Columns with `searchable: false` are completely ignored by the global quick filter.
155
+ * @default true
156
+ * @api
157
+ */
158
+ searchable?: boolean;
144
159
  }
145
160
  export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
146
161
  /** Row property used as the cell value source. */
@@ -157,6 +172,29 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
157
172
  maxWidth?: number;
158
173
  /** Whether this column can be sorted. */
159
174
  sortable?: boolean;
175
+ /**
176
+ * Data type of the column. When omitted, the grid attempts to infer the type
177
+ * from data rows or filter options.
178
+ */
179
+ dataType?: ColumnDataType;
180
+ /**
181
+ * Whether this column offers a filter menu. Set to `false` to opt the column out of
182
+ * filtering UI (the header filter icon is hidden).
183
+ * @default true
184
+ */
185
+ filterable?: boolean;
186
+ /**
187
+ * Custom subset of operators allowed for this column's filter menu.
188
+ */
189
+ allowedOperators?: FilterOperator[];
190
+ /**
191
+ * Fixed options for select / set filtering. When provided, the column
192
+ * automatically defaults to `dataType: "select"`.
193
+ */
194
+ filterOptions?: Array<{
195
+ label: string;
196
+ value: any;
197
+ }>;
160
198
  /** Horizontal alignment of cell content. */
161
199
  align?: CellAlign;
162
200
  /** Initial sort direction used by SortingPlugin. */
@@ -260,6 +298,13 @@ export interface GridOptions<T> {
260
298
  getRowClass?: (params: RowRenderParams<T>) => string | undefined;
261
299
  rowClassRules?: RowClassRules<T>;
262
300
  plugins?: GridPlugin<T>[];
301
+ /** Initial filter model applied to the data pipeline. */
302
+ filterModel?: FilterModel;
303
+ /**
304
+ * Initial global quick filter query string. Applied across every column
305
+ * whose `searchable` property is not `false`.
306
+ */
307
+ quickFilter?: string;
263
308
  /**
264
309
  * License key for Pro plugins. When provided, Pro plugins verify the
265
310
  * cryptographic signature and activate full functionality. When missing
@@ -381,6 +426,11 @@ export interface GridState<T> {
381
426
  columnOverscan: number;
382
427
  /** Active overlay state — updated automatically by the grid's overlay manager. */
383
428
  overlay: OverlayState;
429
+ /**
430
+ * Global quick filter query string. Applied across every column whose
431
+ * `searchable` property is not `false`. Empty string means no quick filter.
432
+ */
433
+ quickFilter: string;
384
434
  }
385
435
  export interface GridEvents<T> {
386
436
  stateChange: GridState<T>;
@@ -402,6 +452,17 @@ export interface GridEvents<T> {
402
452
  mounts: SlotMount<T>[];
403
453
  };
404
454
  overlayChange: OverlayState;
455
+ /** Fired after the filter model changed; the payload is a copy of the new model. */
456
+ filterChanged: FilterModel;
457
+ /** Fired after the global quick filter changed; the payload is the new query string. */
458
+ quickFilterChanged: string;
459
+ /** Fired when a popup is opened, updated (`descriptor`) or closed (`null`). */
460
+ popupChange: UIPopupDescriptor | null;
461
+ /** Fired when the user asks for a column's filter menu (e.g. clicks the header filter icon). */
462
+ filterMenuRequest: {
463
+ columnId: string;
464
+ anchor: UIPopupAnchor;
465
+ };
405
466
  }
406
467
  /** Opaque token for a row node owned by the adapter. */
407
468
  export type RowHost<T> = object;
@@ -478,7 +539,7 @@ export interface GridPlugin<T> {
478
539
  getRowClass?(params: RowRenderParams<T>): string | undefined;
479
540
  getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
480
541
  }
481
- export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom";
542
+ export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom" | "down";
482
543
  export type SlotPosition = "start" | "center" | "end";
483
544
  /**
484
545
  * Placement of a single UI block that a plugin mounts into a slot.
@@ -642,6 +703,82 @@ export interface GridApi<T> {
642
703
  * @api
643
704
  */
644
705
  setLoading(isLoading: boolean, error?: unknown): void;
706
+ /**
707
+ * Replaces the whole filter model. Filtering runs before every data
708
+ * processor (sorting, pagination, ...) and its result is cached until the
709
+ * data, columns or filter model change. Emits `filterChanged`.
710
+ * @param model - New filter model; an empty object clears all filters.
711
+ * @api
712
+ */
713
+ setFilterModel(model: FilterModel): void;
714
+ /**
715
+ * Returns a copy of the current filter model.
716
+ * @api
717
+ */
718
+ getFilterModel(): FilterModel;
719
+ /**
720
+ * Sets (replaces) the single condition of one column, or removes that
721
+ * column's filter when `condition` is `null`.
722
+ * @param field - Column id or field.
723
+ * @param condition - New condition, or `null` to clear.
724
+ * @api
725
+ */
726
+ setColumnFilter(field: string, condition: FilterCondition | null): void;
727
+ /**
728
+ * Removes every column filter.
729
+ * @api
730
+ */
731
+ clearFilters(): void;
732
+ /**
733
+ * Sets the global quick filter query string. The query is split on commas
734
+ * and matched case-insensitively against every column whose `searchable`
735
+ * property is not `false`, using the column's `valueGetter` when present.
736
+ * An empty string clears the quick filter. Emits `quickFilterChanged`.
737
+ * @param query - The quick filter query.
738
+ * @api
739
+ */
740
+ setQuickFilter(query: string): void;
741
+ /**
742
+ * Returns the current global quick filter query string.
743
+ * @api
744
+ */
745
+ getQuickFilter(): string;
746
+ /**
747
+ * Declares that a plugin provides a column filter menu. While at least one
748
+ * provider is registered, adapters show the filter icon in column headers.
749
+ * @returns Function that removes the registration.
750
+ * @api
751
+ */
752
+ registerFilterMenu(): () => void;
753
+ /**
754
+ * Whether a filter menu provider is registered.
755
+ * @api
756
+ */
757
+ hasFilterMenu(): boolean;
758
+ /**
759
+ * Asks the filter menu provider to open the menu of a column (emits `filterMenuRequest`).
760
+ * @param columnId - Column id.
761
+ * @param anchor - Viewport-relative rectangle of the trigger element.
762
+ * @api
763
+ */
764
+ requestFilterMenu(columnId: string, anchor: UIPopupAnchor): void;
765
+ /**
766
+ * Opens (or updates, when the id matches) a declarative popup rendered by
767
+ * the active UI adapter.
768
+ * @param descriptor - Framework-agnostic popup description.
769
+ * @api
770
+ */
771
+ openPopup(descriptor: UIPopupDescriptor): void;
772
+ /**
773
+ * Closes the active popup, if any.
774
+ * @api
775
+ */
776
+ closePopup(): void;
777
+ /**
778
+ * Returns the active popup descriptor or `null`.
779
+ * @api
780
+ */
781
+ getPopup(): UIPopupDescriptor | null;
645
782
  /** Monotonic counter for structural changes (refresh / data / columns). */
646
783
  getRevision(): number;
647
784
  destroy(): void;
package/dist/ui.d.ts ADDED
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Framework-agnostic UI descriptors. Plugins describe interactive panels
3
+ * declaratively; adapters (React, Vue, ...) materialise them. Descriptors are
4
+ * plain data plus callbacks — no framework types.
5
+ */
6
+ /** Option of a select control. @api */
7
+ export interface UISelectOption {
8
+ /** Value passed to `onChange` when the option is chosen. */
9
+ value: string;
10
+ /** Human-readable option label. */
11
+ label: string;
12
+ /** Disables the option. @default false */
13
+ disabled?: boolean;
14
+ }
15
+ /** Properties shared by every control descriptor. @api */
16
+ export interface UIControlBase {
17
+ /** Stable identifier; adapters use it as the element key. */
18
+ id: string;
19
+ /** Visible label rendered next to the control. */
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;
34
+ /** Disables the control. @default false */
35
+ disabled?: boolean;
36
+ /** Extra CSS class names. */
37
+ className?: string;
38
+ }
39
+ /** Single-line text, number or date input. @api */
40
+ export interface UIInputControl extends UIControlBase {
41
+ type: "text" | "number" | "date";
42
+ /** Current value. */
43
+ value: string;
44
+ /** Placeholder text. */
45
+ placeholder?: string;
46
+ /** Debounce applied by the adapter before `onChange` fires. @default 250 */
47
+ debounceMs?: number;
48
+ /** Called with the (debounced) new value. */
49
+ onChange: (value: string) => void;
50
+ /** Called when the user presses Enter while the input is focused. */
51
+ onEnter?: () => void;
52
+ }
53
+ /** Drop-down select. @api */
54
+ export interface UISelectControl extends UIControlBase {
55
+ type: "select";
56
+ /** Currently selected option value. */
57
+ value: string;
58
+ /** Available options. */
59
+ options: UISelectOption[];
60
+ /** Called with the newly selected value. */
61
+ onChange: (value: string) => void;
62
+ }
63
+ /** Checkbox. @api */
64
+ export interface UICheckboxDescriptor extends UIControlBase {
65
+ type: "checkbox";
66
+ /** Current checked state. */
67
+ checked: boolean;
68
+ /** Called with the new checked state. */
69
+ onChange: (checked: boolean) => void;
70
+ }
71
+ /** Push button. @api */
72
+ export interface UIButtonControl extends UIControlBase {
73
+ type: "button";
74
+ /** Button caption. */
75
+ text: string;
76
+ /** Visual emphasis. @default "secondary" */
77
+ variant?: "primary" | "secondary";
78
+ /** Called when the button is clicked. */
79
+ onClick: () => void;
80
+ }
81
+ /** Static text. @api */
82
+ export interface UITextBlockControl extends UIControlBase {
83
+ type: "label";
84
+ /** Text to display. */
85
+ text: string;
86
+ }
87
+ /** Option for a multi-select set control. @api */
88
+ export interface UIMultiSelectOption {
89
+ /** Value of the item. */
90
+ value: string;
91
+ /** Human-readable label. */
92
+ label: string;
93
+ /** Whether this item is currently selected. */
94
+ checked: boolean;
95
+ }
96
+ /** Searchable checklist / set filter control. @api */
97
+ export interface UIMultiSelectControl extends UIControlBase {
98
+ type: "multi-select";
99
+ /** Available options with checked state. */
100
+ options: UIMultiSelectOption[];
101
+ /** Placeholder for the search input. @default "Search..." */
102
+ searchPlaceholder?: string;
103
+ /** Called when the selected set changes. */
104
+ onChange: (selectedValues: string[]) => void;
105
+ }
106
+ /** Container laying out child controls. @api */
107
+ export interface UIGroupControl extends UIControlBase {
108
+ type: "group";
109
+ /** Layout direction. @default "column" */
110
+ direction?: "row" | "column";
111
+ /** Nested controls. */
112
+ children: UIControlDescriptor[];
113
+ }
114
+ /** Any declarative control. @api */
115
+ export type UIControlDescriptor = UIInputControl | UISelectControl | UICheckboxDescriptor | UIButtonControl | UITextBlockControl | UIMultiSelectControl | UIGroupControl;
116
+ /** Viewport-relative anchor rectangle (CSS pixels) a popup is positioned against. @api */
117
+ export interface UIPopupAnchor {
118
+ x: number;
119
+ y: number;
120
+ width?: number;
121
+ height?: number;
122
+ }
123
+ /** Declarative floating panel. @api */
124
+ export interface UIPopupDescriptor {
125
+ /** Stable identifier. Re-opening a popup with the same id updates it in place. */
126
+ id: string;
127
+ /** Optional heading. */
128
+ title?: string;
129
+ /** Rectangle the popup is attached to; centered in the grid when omitted. */
130
+ anchor?: UIPopupAnchor;
131
+ /** Placement relative to the anchor. @default "bottom-start" */
132
+ placement?: "bottom-start" | "bottom-end";
133
+ /** Popup body. */
134
+ controls: UIControlDescriptor[];
135
+ /** Close when the user clicks outside. @default true */
136
+ closeOnOutsideClick?: boolean;
137
+ /** Close on Escape. @default true */
138
+ closeOnEscape?: boolean;
139
+ /** Extra CSS class names. */
140
+ className?: string;
141
+ /** Invoked after the popup has been closed. */
142
+ onClose?: () => void;
143
+ }
144
+ /**
145
+ * Holds the single active popup and notifies the adapter on change.
146
+ * @internal
147
+ */
148
+ export declare class PopupManager {
149
+ private readonly onChange;
150
+ private current;
151
+ constructor(onChange: (popup: UIPopupDescriptor | null) => void);
152
+ open(descriptor: UIPopupDescriptor): void;
153
+ close(): void;
154
+ get(): UIPopupDescriptor | null;
155
+ }
package/dist/ui.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Framework-agnostic UI descriptors. Plugins describe interactive panels
3
+ * declaratively; adapters (React, Vue, ...) materialise them. Descriptors are
4
+ * plain data plus callbacks — no framework types.
5
+ */
6
+ /**
7
+ * Holds the single active popup and notifies the adapter on change.
8
+ * @internal
9
+ */
10
+ export class PopupManager {
11
+ constructor(onChange) {
12
+ this.onChange = onChange;
13
+ this.current = null;
14
+ }
15
+ open(descriptor) {
16
+ const previous = this.current;
17
+ this.current = descriptor;
18
+ if (previous && previous.id !== descriptor.id)
19
+ previous.onClose?.();
20
+ this.onChange(descriptor);
21
+ }
22
+ close() {
23
+ const previous = this.current;
24
+ if (!previous)
25
+ return;
26
+ this.current = null;
27
+ this.onChange(null);
28
+ previous.onClose?.();
29
+ }
30
+ get() {
31
+ return this.current;
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",