@omnigrid/core 0.1.17 → 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.
- package/dist/filtering.d.ts +17 -0
- package/dist/filtering.js +37 -0
- package/dist/grid.d.ts +15 -0
- package/dist/grid.js +36 -2
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/slots.d.ts +1 -0
- package/dist/slots.js +25 -2
- package/dist/types.d.ts +34 -1
- package/dist/ui.d.ts +13 -0
- package/package.json +1 -1
package/dist/filtering.d.ts
CHANGED
|
@@ -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
|
-
|
|
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,7 +7,7 @@ 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";
|
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
|
-
|
|
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
|
|
82
|
+
return this.getMounts(slot).length > 0;
|
|
60
83
|
}
|
|
61
84
|
clear(slot) {
|
|
62
85
|
if (slot) {
|
package/dist/types.d.ts
CHANGED
|
@@ -149,6 +149,13 @@ interface BaseColumnDef<T> {
|
|
|
149
149
|
resizable?: boolean;
|
|
150
150
|
/** Custom renderer for this column's header. */
|
|
151
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;
|
|
152
159
|
}
|
|
153
160
|
export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
|
|
154
161
|
/** Row property used as the cell value source. */
|
|
@@ -293,6 +300,11 @@ export interface GridOptions<T> {
|
|
|
293
300
|
plugins?: GridPlugin<T>[];
|
|
294
301
|
/** Initial filter model applied to the data pipeline. */
|
|
295
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;
|
|
296
308
|
/**
|
|
297
309
|
* License key for Pro plugins. When provided, Pro plugins verify the
|
|
298
310
|
* cryptographic signature and activate full functionality. When missing
|
|
@@ -414,6 +426,11 @@ export interface GridState<T> {
|
|
|
414
426
|
columnOverscan: number;
|
|
415
427
|
/** Active overlay state — updated automatically by the grid's overlay manager. */
|
|
416
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;
|
|
417
434
|
}
|
|
418
435
|
export interface GridEvents<T> {
|
|
419
436
|
stateChange: GridState<T>;
|
|
@@ -437,6 +454,8 @@ export interface GridEvents<T> {
|
|
|
437
454
|
overlayChange: OverlayState;
|
|
438
455
|
/** Fired after the filter model changed; the payload is a copy of the new model. */
|
|
439
456
|
filterChanged: FilterModel;
|
|
457
|
+
/** Fired after the global quick filter changed; the payload is the new query string. */
|
|
458
|
+
quickFilterChanged: string;
|
|
440
459
|
/** Fired when a popup is opened, updated (`descriptor`) or closed (`null`). */
|
|
441
460
|
popupChange: UIPopupDescriptor | null;
|
|
442
461
|
/** Fired when the user asks for a column's filter menu (e.g. clicks the header filter icon). */
|
|
@@ -520,7 +539,7 @@ export interface GridPlugin<T> {
|
|
|
520
539
|
getRowClass?(params: RowRenderParams<T>): string | undefined;
|
|
521
540
|
getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
|
|
522
541
|
}
|
|
523
|
-
export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom";
|
|
542
|
+
export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom" | "down";
|
|
524
543
|
export type SlotPosition = "start" | "center" | "end";
|
|
525
544
|
/**
|
|
526
545
|
* Placement of a single UI block that a plugin mounts into a slot.
|
|
@@ -710,6 +729,20 @@ export interface GridApi<T> {
|
|
|
710
729
|
* @api
|
|
711
730
|
*/
|
|
712
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;
|
|
713
746
|
/**
|
|
714
747
|
* Declares that a plugin provides a column filter menu. While at least one
|
|
715
748
|
* 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. */
|