@omnigrid/core 0.1.3 → 0.1.4
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/grid.d.ts +2 -0
- package/dist/grid.js +2 -0
- package/dist/icons.d.ts +12 -0
- package/dist/icons.js +89 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/types.d.ts +7 -1
- package/package.json +1 -1
package/dist/grid.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IconRegistry } from "./icons";
|
|
1
2
|
import { SlotManager } from "./slots";
|
|
2
3
|
import type { DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHoverEvent, RowId, ScrollPosition, SlotMount, SlotName, ViewportData, ViewportState } from "./types";
|
|
3
4
|
export declare class Grid<T> implements GridApi<T> {
|
|
@@ -8,6 +9,7 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
8
9
|
private readonly dataProcessors;
|
|
9
10
|
private readonly resolveRowId;
|
|
10
11
|
readonly slots: SlotManager<T>;
|
|
12
|
+
readonly icons: IconRegistry<T>;
|
|
11
13
|
private processedDataCache;
|
|
12
14
|
private revision;
|
|
13
15
|
private destroyed;
|
package/dist/grid.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { flattenColumns, getColumnGroups } from "./columns";
|
|
2
2
|
import { EventBus } from "./events";
|
|
3
|
+
import { IconRegistry } from "./icons";
|
|
3
4
|
import { SlotManager } from "./slots";
|
|
4
5
|
import { Store } from "./store";
|
|
5
6
|
import { Virtualizer } from "./virtualizer";
|
|
@@ -8,6 +9,7 @@ export class Grid {
|
|
|
8
9
|
this.events = new EventBus();
|
|
9
10
|
this.cleanupPlugins = new Set();
|
|
10
11
|
this.dataProcessors = new Set();
|
|
12
|
+
this.icons = new IconRegistry();
|
|
11
13
|
this.processedDataCache = null;
|
|
12
14
|
this.revision = 0;
|
|
13
15
|
this.destroyed = false;
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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";
|
|
3
|
+
export type IconDefinition<T> = SlotNodeContent<T> | (() => SlotNodeContent<T>);
|
|
4
|
+
/** Framework-agnostic registry of declarative SVG slot nodes. */
|
|
5
|
+
export declare class IconRegistry<T> {
|
|
6
|
+
private readonly definitions;
|
|
7
|
+
constructor();
|
|
8
|
+
has(name: string): boolean;
|
|
9
|
+
get(name: string): SlotNodeContent<T>;
|
|
10
|
+
/** Registers or replaces an icon. Unregistering restores any previous definition. */
|
|
11
|
+
register(name: string, icon: IconDefinition<T>): () => void;
|
|
12
|
+
}
|
package/dist/icons.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const DEFAULT_ICON_PATHS = {
|
|
2
|
+
"chevron-left": [{ tag: "path", attrs: { d: "m15 18-6-6 6-6" } }],
|
|
3
|
+
"chevron-right": [{ tag: "path", attrs: { d: "m9 18 6-6-6-6" } }],
|
|
4
|
+
"chevron-up": [{ tag: "path", attrs: { d: "m18 15-6-6-6 6" } }],
|
|
5
|
+
"chevron-down": [{ tag: "path", attrs: { d: "m6 9 6 6 6-6" } }],
|
|
6
|
+
"chevron-first": [
|
|
7
|
+
{ tag: "path", attrs: { d: "m17 18-6-6 6-6" } },
|
|
8
|
+
{ tag: "path", attrs: { d: "M7 6v12" } },
|
|
9
|
+
],
|
|
10
|
+
"chevron-last": [
|
|
11
|
+
{ tag: "path", attrs: { d: "m7 18 6-6-6-6" } },
|
|
12
|
+
{ tag: "path", attrs: { d: "M17 6v12" } },
|
|
13
|
+
],
|
|
14
|
+
"arrow-up": [
|
|
15
|
+
{ tag: "path", attrs: { d: "M12 19V5" } },
|
|
16
|
+
{ tag: "path", attrs: { d: "m5 12 7-7 7 7" } },
|
|
17
|
+
],
|
|
18
|
+
"arrow-down": [
|
|
19
|
+
{ tag: "path", attrs: { d: "M12 5v14" } },
|
|
20
|
+
{ tag: "path", attrs: { d: "m19 12-7 7-7-7" } },
|
|
21
|
+
],
|
|
22
|
+
"arrow-up-down": [
|
|
23
|
+
{ tag: "path", attrs: { d: "m3 16 4 4 4-4" } },
|
|
24
|
+
{ tag: "path", attrs: { d: "M7 20V4" } },
|
|
25
|
+
{ tag: "path", attrs: { d: "m21 8-4-4-4 4" } },
|
|
26
|
+
{ tag: "path", attrs: { d: "M17 4v16" } },
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
function createSvgIcon(name, paths) {
|
|
30
|
+
return {
|
|
31
|
+
type: "node",
|
|
32
|
+
tag: "svg",
|
|
33
|
+
attrs: {
|
|
34
|
+
class: `omnigrid-icon omnigrid-icon-${name}`,
|
|
35
|
+
width: "16",
|
|
36
|
+
height: "16",
|
|
37
|
+
viewBox: "0 0 24 24",
|
|
38
|
+
fill: "none",
|
|
39
|
+
stroke: "currentColor",
|
|
40
|
+
strokeWidth: "2",
|
|
41
|
+
strokeLinecap: "round",
|
|
42
|
+
strokeLinejoin: "round",
|
|
43
|
+
"aria-hidden": "true",
|
|
44
|
+
},
|
|
45
|
+
children: paths.map(({ tag, attrs }) => ({ type: "node", tag, attrs })),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Framework-agnostic registry of declarative SVG slot nodes. */
|
|
49
|
+
export class IconRegistry {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.definitions = new Map();
|
|
52
|
+
for (const [name, paths] of Object.entries(DEFAULT_ICON_PATHS)) {
|
|
53
|
+
this.definitions.set(name, {
|
|
54
|
+
render: () => createSvgIcon(name, paths),
|
|
55
|
+
active: true,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
has(name) {
|
|
60
|
+
return this.definitions.has(name);
|
|
61
|
+
}
|
|
62
|
+
get(name) {
|
|
63
|
+
const definition = this.definitions.get(name);
|
|
64
|
+
if (!definition)
|
|
65
|
+
throw new Error(`Unknown OmniGrid icon: ${name}`);
|
|
66
|
+
return definition.render();
|
|
67
|
+
}
|
|
68
|
+
/** Registers or replaces an icon. Unregistering restores any previous definition. */
|
|
69
|
+
register(name, icon) {
|
|
70
|
+
const definition = {
|
|
71
|
+
render: typeof icon === "function" ? icon : () => icon,
|
|
72
|
+
previous: this.definitions.get(name),
|
|
73
|
+
active: true,
|
|
74
|
+
};
|
|
75
|
+
this.definitions.set(name, definition);
|
|
76
|
+
return () => {
|
|
77
|
+
definition.active = false;
|
|
78
|
+
if (this.definitions.get(name) !== definition)
|
|
79
|
+
return;
|
|
80
|
+
let previous = definition.previous;
|
|
81
|
+
while (previous && !previous.active)
|
|
82
|
+
previous = previous.previous;
|
|
83
|
+
if (previous)
|
|
84
|
+
this.definitions.set(name, previous);
|
|
85
|
+
else
|
|
86
|
+
this.definitions.delete(name);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { DomPool } from "./dom-pool";
|
|
2
2
|
export { EventBus } from "./events";
|
|
3
|
+
export { IconRegistry } from "./icons";
|
|
4
|
+
export type { IconDefinition, IconName } from "./icons";
|
|
3
5
|
export { Grid } from "./grid";
|
|
4
6
|
export { Grid as GridCore } from "./grid";
|
|
5
7
|
export { SlotManager } from "./slots";
|
|
6
8
|
export { Store } from "./store";
|
|
7
|
-
export type { CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, DataProcessor, DomPoolBindings, DomPoolUpdate, GridApi, GridEvents, GridOptions, GridPlugin, GridState, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
9
|
+
export type { CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, DataProcessor, DomPoolBindings, DomPoolUpdate, GridApi, GridEvents, GridOptions, GridPlugin, GridState, 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";
|
|
8
10
|
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf } from "./columns";
|
|
9
11
|
export { Virtualizer } from "./virtualizer";
|
package/dist/index.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SlotManager } from "./slots";
|
|
2
|
+
import type { IconRegistry } from "./icons";
|
|
2
3
|
export type RowId = string | number;
|
|
3
4
|
export type SortDirection = "asc" | "desc";
|
|
4
5
|
export type CellAlign = "left" | "center" | "right";
|
|
@@ -265,6 +266,10 @@ export interface GridPlugin<T> {
|
|
|
265
266
|
export type SlotName = "top" | "bottom" | "left" | "right";
|
|
266
267
|
export type SlotPosition = "start" | "center" | "end";
|
|
267
268
|
export type SlotNodeEventName = "click" | "change" | "keydown";
|
|
269
|
+
export interface SlotNodeEvent {
|
|
270
|
+
value?: string;
|
|
271
|
+
key?: string;
|
|
272
|
+
}
|
|
268
273
|
/**
|
|
269
274
|
* Context passed to the slot content provider. Headless: the plugin
|
|
270
275
|
* works only with the core API and state — no DOM or framework code.
|
|
@@ -288,7 +293,7 @@ export interface SlotNodeContent<T> {
|
|
|
288
293
|
type: "node";
|
|
289
294
|
tag: string;
|
|
290
295
|
attrs?: Record<string, string | number | boolean | undefined>;
|
|
291
|
-
on?: Partial<Record<SlotNodeEventName, (context: SlotRenderContext<T
|
|
296
|
+
on?: Partial<Record<SlotNodeEventName, (context: SlotRenderContext<T>, event: SlotNodeEvent) => void>>;
|
|
292
297
|
children?: SlotContent[];
|
|
293
298
|
}
|
|
294
299
|
/**
|
|
@@ -350,6 +355,7 @@ export interface GridApi<T> {
|
|
|
350
355
|
rowClick(row: RowClickEvent<T>): void;
|
|
351
356
|
rowHover(row: RowHoverEvent<T>): void;
|
|
352
357
|
readonly slots: SlotManager<T>;
|
|
358
|
+
readonly icons: IconRegistry<T>;
|
|
353
359
|
getSlotMounts(slot: SlotName): SlotMount<T>[];
|
|
354
360
|
/** Monotonic counter for structural changes (refresh / data / columns). */
|
|
355
361
|
getRevision(): number;
|