@omnigrid/core 0.1.16 → 0.1.17

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,66 @@
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[];
@@ -0,0 +1,180 @@
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
+ }
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,18 @@ 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
+ registerFilterMenu(): () => void;
68
+ hasFilterMenu(): boolean;
69
+ requestFilterMenu(columnId: string, anchor: UIPopupAnchor): void;
70
+ openPopup(descriptor: UIPopupDescriptor): void;
71
+ closePopup(): void;
72
+ getPopup(): UIPopupDescriptor | null;
54
73
  getRowId(row: T, index: number): RowId;
55
74
  setData(data: T[] | null | undefined): void;
56
75
  /**
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, 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;
@@ -42,6 +49,8 @@ export class Grid {
42
49
  this.resolveRowId = options.getRowId ?? ((_row, index) => index);
43
50
  this.loading = options.loading ?? false;
44
51
  this.hasData = options.data !== undefined && options.data !== null;
52
+ if (options.filterModel)
53
+ this.filterModel = Grid.cloneFilterModel(options.filterModel);
45
54
  this.virtualizer = new Virtualizer({
46
55
  rowHeight: state.rowHeight,
47
56
  rowOverscan: state.rowOverscan,
@@ -193,15 +202,102 @@ export class Grid {
193
202
  };
194
203
  }
195
204
  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.
205
+ // Pipeline: raw data -> filter engine -> processors (sort, ...) -> virtualization.
206
+ // Cache is invalidated by setData / setColumns / filter changes / processor
207
+ // registration. During scroll the pipeline is NOT re-run — critical
208
+ // optimization for DOM Pool operation with large row counts.
199
209
  if (this.processedDataCache !== null)
200
210
  return this.processedDataCache;
201
- const result = [...this.dataProcessors].reduce((data, processor) => processor(data), this.getState().data);
211
+ const result = [...this.dataProcessors].reduce((data, processor) => processor(data), this.getFilteredData());
202
212
  this.processedDataCache = result;
203
213
  return result;
204
214
  }
215
+ getFilteredData() {
216
+ if (this.filteredDataCache !== null)
217
+ return this.filteredDataCache;
218
+ const state = this.getState();
219
+ this.filteredDataCache = applyFilterModel(state.data, this.filterModel, state.columns);
220
+ return this.filteredDataCache;
221
+ }
222
+ static cloneFilterModel(model) {
223
+ const clone = {};
224
+ for (const [key, entry] of Object.entries(model)) {
225
+ const conditions = entry.conditions.map((condition) => ({ ...condition }));
226
+ clone[key] = entry.logic ? { conditions, logic: entry.logic } : { conditions };
227
+ }
228
+ return clone;
229
+ }
230
+ setFilterModel(model) {
231
+ this.assertActive();
232
+ const next = {};
233
+ for (const [key, entry] of Object.entries(Grid.cloneFilterModel(model))) {
234
+ if (entry.conditions.length > 0)
235
+ next[key] = entry;
236
+ }
237
+ this.filterModel = next;
238
+ this.filteredDataCache = null;
239
+ this.processedDataCache = null;
240
+ this.revision += 1;
241
+ this.scrollTo({ scrollTop: 0 });
242
+ this.store.setState({});
243
+ this.recomputeOverlay();
244
+ this.events.emit("filterChanged", this.getFilterModel());
245
+ }
246
+ getFilterModel() {
247
+ return Grid.cloneFilterModel(this.filterModel);
248
+ }
249
+ setColumnFilter(field, condition) {
250
+ this.assertActive();
251
+ const next = this.getFilterModel();
252
+ if (condition === null || !isActiveCondition(condition)) {
253
+ if (!(field in next))
254
+ return;
255
+ delete next[field];
256
+ }
257
+ else {
258
+ const entry = { conditions: [{ ...condition }] };
259
+ next[field] = entry;
260
+ }
261
+ this.setFilterModel(next);
262
+ }
263
+ clearFilters() {
264
+ this.assertActive();
265
+ if (Object.keys(this.filterModel).length === 0)
266
+ return;
267
+ this.setFilterModel({});
268
+ }
269
+ registerFilterMenu() {
270
+ this.assertActive();
271
+ this.filterMenuProviders += 1;
272
+ this.refresh();
273
+ let removed = false;
274
+ return () => {
275
+ if (removed)
276
+ return;
277
+ removed = true;
278
+ this.filterMenuProviders -= 1;
279
+ if (!this.destroyed)
280
+ this.refresh();
281
+ };
282
+ }
283
+ hasFilterMenu() {
284
+ return this.filterMenuProviders > 0;
285
+ }
286
+ requestFilterMenu(columnId, anchor) {
287
+ this.assertActive();
288
+ this.events.emit("filterMenuRequest", { columnId, anchor });
289
+ }
290
+ openPopup(descriptor) {
291
+ this.assertActive();
292
+ this.popups.open(descriptor);
293
+ }
294
+ closePopup() {
295
+ this.assertActive();
296
+ this.popups.close();
297
+ }
298
+ getPopup() {
299
+ return this.popups.get();
300
+ }
205
301
  getRowId(row, index) {
206
302
  return this.resolveRowId(row, index);
207
303
  }
@@ -210,6 +306,7 @@ export class Grid {
210
306
  this.loadError = undefined;
211
307
  this.hasData = data !== undefined && data !== null;
212
308
  const nextData = data ?? [];
309
+ this.filteredDataCache = null;
213
310
  this.processedDataCache = null;
214
311
  this.revision += 1;
215
312
  this.store.setState({ data: nextData });
@@ -230,6 +327,7 @@ export class Grid {
230
327
  const currentData = this.store.getState().data;
231
328
  const nextData = [...currentData, ...rows];
232
329
  this.hasData = true;
330
+ this.filteredDataCache = null;
233
331
  this.processedDataCache = null;
234
332
  this.revision += 1;
235
333
  this.store.setState({ data: nextData });
@@ -293,6 +391,7 @@ export class Grid {
293
391
  }
294
392
  setColumns(columns) {
295
393
  this.assertActive();
394
+ this.filteredDataCache = null;
296
395
  this.processedDataCache = null;
297
396
  this.revision += 1;
298
397
  this.store.setState({ columns });
@@ -458,6 +557,8 @@ export class Grid {
458
557
  this.cleanupPlugins.forEach((cleanup) => cleanup());
459
558
  this.cleanupPlugins.clear();
460
559
  this.dataProcessors.clear();
560
+ this.popups.close();
561
+ this.filteredDataCache = null;
461
562
  this.processedDataCache = null;
462
563
  this.overlayState = { type: null };
463
564
  this.overlayManual = false;
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, 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, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
9
10
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
10
11
  export { Virtualizer } from "./virtualizer";
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;
@@ -157,6 +165,29 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
157
165
  maxWidth?: number;
158
166
  /** Whether this column can be sorted. */
159
167
  sortable?: boolean;
168
+ /**
169
+ * Data type of the column. When omitted, the grid attempts to infer the type
170
+ * from data rows or filter options.
171
+ */
172
+ dataType?: ColumnDataType;
173
+ /**
174
+ * Whether this column offers a filter menu. Set to `false` to opt the column out of
175
+ * filtering UI (the header filter icon is hidden).
176
+ * @default true
177
+ */
178
+ filterable?: boolean;
179
+ /**
180
+ * Custom subset of operators allowed for this column's filter menu.
181
+ */
182
+ allowedOperators?: FilterOperator[];
183
+ /**
184
+ * Fixed options for select / set filtering. When provided, the column
185
+ * automatically defaults to `dataType: "select"`.
186
+ */
187
+ filterOptions?: Array<{
188
+ label: string;
189
+ value: any;
190
+ }>;
160
191
  /** Horizontal alignment of cell content. */
161
192
  align?: CellAlign;
162
193
  /** Initial sort direction used by SortingPlugin. */
@@ -260,6 +291,8 @@ export interface GridOptions<T> {
260
291
  getRowClass?: (params: RowRenderParams<T>) => string | undefined;
261
292
  rowClassRules?: RowClassRules<T>;
262
293
  plugins?: GridPlugin<T>[];
294
+ /** Initial filter model applied to the data pipeline. */
295
+ filterModel?: FilterModel;
263
296
  /**
264
297
  * License key for Pro plugins. When provided, Pro plugins verify the
265
298
  * cryptographic signature and activate full functionality. When missing
@@ -402,6 +435,15 @@ export interface GridEvents<T> {
402
435
  mounts: SlotMount<T>[];
403
436
  };
404
437
  overlayChange: OverlayState;
438
+ /** Fired after the filter model changed; the payload is a copy of the new model. */
439
+ filterChanged: FilterModel;
440
+ /** Fired when a popup is opened, updated (`descriptor`) or closed (`null`). */
441
+ popupChange: UIPopupDescriptor | null;
442
+ /** Fired when the user asks for a column's filter menu (e.g. clicks the header filter icon). */
443
+ filterMenuRequest: {
444
+ columnId: string;
445
+ anchor: UIPopupAnchor;
446
+ };
405
447
  }
406
448
  /** Opaque token for a row node owned by the adapter. */
407
449
  export type RowHost<T> = object;
@@ -642,6 +684,68 @@ export interface GridApi<T> {
642
684
  * @api
643
685
  */
644
686
  setLoading(isLoading: boolean, error?: unknown): void;
687
+ /**
688
+ * Replaces the whole filter model. Filtering runs before every data
689
+ * processor (sorting, pagination, ...) and its result is cached until the
690
+ * data, columns or filter model change. Emits `filterChanged`.
691
+ * @param model - New filter model; an empty object clears all filters.
692
+ * @api
693
+ */
694
+ setFilterModel(model: FilterModel): void;
695
+ /**
696
+ * Returns a copy of the current filter model.
697
+ * @api
698
+ */
699
+ getFilterModel(): FilterModel;
700
+ /**
701
+ * Sets (replaces) the single condition of one column, or removes that
702
+ * column's filter when `condition` is `null`.
703
+ * @param field - Column id or field.
704
+ * @param condition - New condition, or `null` to clear.
705
+ * @api
706
+ */
707
+ setColumnFilter(field: string, condition: FilterCondition | null): void;
708
+ /**
709
+ * Removes every column filter.
710
+ * @api
711
+ */
712
+ clearFilters(): void;
713
+ /**
714
+ * Declares that a plugin provides a column filter menu. While at least one
715
+ * provider is registered, adapters show the filter icon in column headers.
716
+ * @returns Function that removes the registration.
717
+ * @api
718
+ */
719
+ registerFilterMenu(): () => void;
720
+ /**
721
+ * Whether a filter menu provider is registered.
722
+ * @api
723
+ */
724
+ hasFilterMenu(): boolean;
725
+ /**
726
+ * Asks the filter menu provider to open the menu of a column (emits `filterMenuRequest`).
727
+ * @param columnId - Column id.
728
+ * @param anchor - Viewport-relative rectangle of the trigger element.
729
+ * @api
730
+ */
731
+ requestFilterMenu(columnId: string, anchor: UIPopupAnchor): void;
732
+ /**
733
+ * Opens (or updates, when the id matches) a declarative popup rendered by
734
+ * the active UI adapter.
735
+ * @param descriptor - Framework-agnostic popup description.
736
+ * @api
737
+ */
738
+ openPopup(descriptor: UIPopupDescriptor): void;
739
+ /**
740
+ * Closes the active popup, if any.
741
+ * @api
742
+ */
743
+ closePopup(): void;
744
+ /**
745
+ * Returns the active popup descriptor or `null`.
746
+ * @api
747
+ */
748
+ getPopup(): UIPopupDescriptor | null;
645
749
  /** Monotonic counter for structural changes (refresh / data / columns). */
646
750
  getRevision(): number;
647
751
  destroy(): void;
package/dist/ui.d.ts ADDED
@@ -0,0 +1,142 @@
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
+ /** Disables the control. @default false */
22
+ disabled?: boolean;
23
+ /** Extra CSS class names. */
24
+ className?: string;
25
+ }
26
+ /** Single-line text, number or date input. @api */
27
+ export interface UIInputControl extends UIControlBase {
28
+ type: "text" | "number" | "date";
29
+ /** Current value. */
30
+ value: string;
31
+ /** Placeholder text. */
32
+ placeholder?: string;
33
+ /** Debounce applied by the adapter before `onChange` fires. @default 250 */
34
+ debounceMs?: number;
35
+ /** Called with the (debounced) new value. */
36
+ onChange: (value: string) => void;
37
+ /** Called when the user presses Enter while the input is focused. */
38
+ onEnter?: () => void;
39
+ }
40
+ /** Drop-down select. @api */
41
+ export interface UISelectControl extends UIControlBase {
42
+ type: "select";
43
+ /** Currently selected option value. */
44
+ value: string;
45
+ /** Available options. */
46
+ options: UISelectOption[];
47
+ /** Called with the newly selected value. */
48
+ onChange: (value: string) => void;
49
+ }
50
+ /** Checkbox. @api */
51
+ export interface UICheckboxDescriptor extends UIControlBase {
52
+ type: "checkbox";
53
+ /** Current checked state. */
54
+ checked: boolean;
55
+ /** Called with the new checked state. */
56
+ onChange: (checked: boolean) => void;
57
+ }
58
+ /** Push button. @api */
59
+ export interface UIButtonControl extends UIControlBase {
60
+ type: "button";
61
+ /** Button caption. */
62
+ text: string;
63
+ /** Visual emphasis. @default "secondary" */
64
+ variant?: "primary" | "secondary";
65
+ /** Called when the button is clicked. */
66
+ onClick: () => void;
67
+ }
68
+ /** Static text. @api */
69
+ export interface UITextBlockControl extends UIControlBase {
70
+ type: "label";
71
+ /** Text to display. */
72
+ text: string;
73
+ }
74
+ /** Option for a multi-select set control. @api */
75
+ export interface UIMultiSelectOption {
76
+ /** Value of the item. */
77
+ value: string;
78
+ /** Human-readable label. */
79
+ label: string;
80
+ /** Whether this item is currently selected. */
81
+ checked: boolean;
82
+ }
83
+ /** Searchable checklist / set filter control. @api */
84
+ export interface UIMultiSelectControl extends UIControlBase {
85
+ type: "multi-select";
86
+ /** Available options with checked state. */
87
+ options: UIMultiSelectOption[];
88
+ /** Placeholder for the search input. @default "Search..." */
89
+ searchPlaceholder?: string;
90
+ /** Called when the selected set changes. */
91
+ onChange: (selectedValues: string[]) => void;
92
+ }
93
+ /** Container laying out child controls. @api */
94
+ export interface UIGroupControl extends UIControlBase {
95
+ type: "group";
96
+ /** Layout direction. @default "column" */
97
+ direction?: "row" | "column";
98
+ /** Nested controls. */
99
+ children: UIControlDescriptor[];
100
+ }
101
+ /** Any declarative control. @api */
102
+ export type UIControlDescriptor = UIInputControl | UISelectControl | UICheckboxDescriptor | UIButtonControl | UITextBlockControl | UIMultiSelectControl | UIGroupControl;
103
+ /** Viewport-relative anchor rectangle (CSS pixels) a popup is positioned against. @api */
104
+ export interface UIPopupAnchor {
105
+ x: number;
106
+ y: number;
107
+ width?: number;
108
+ height?: number;
109
+ }
110
+ /** Declarative floating panel. @api */
111
+ export interface UIPopupDescriptor {
112
+ /** Stable identifier. Re-opening a popup with the same id updates it in place. */
113
+ id: string;
114
+ /** Optional heading. */
115
+ title?: string;
116
+ /** Rectangle the popup is attached to; centered in the grid when omitted. */
117
+ anchor?: UIPopupAnchor;
118
+ /** Placement relative to the anchor. @default "bottom-start" */
119
+ placement?: "bottom-start" | "bottom-end";
120
+ /** Popup body. */
121
+ controls: UIControlDescriptor[];
122
+ /** Close when the user clicks outside. @default true */
123
+ closeOnOutsideClick?: boolean;
124
+ /** Close on Escape. @default true */
125
+ closeOnEscape?: boolean;
126
+ /** Extra CSS class names. */
127
+ className?: string;
128
+ /** Invoked after the popup has been closed. */
129
+ onClose?: () => void;
130
+ }
131
+ /**
132
+ * Holds the single active popup and notifies the adapter on change.
133
+ * @internal
134
+ */
135
+ export declare class PopupManager {
136
+ private readonly onChange;
137
+ private current;
138
+ constructor(onChange: (popup: UIPopupDescriptor | null) => void);
139
+ open(descriptor: UIPopupDescriptor): void;
140
+ close(): void;
141
+ get(): UIPopupDescriptor | null;
142
+ }
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.17",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",