@omnigrid/core 0.1.2 → 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 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;
@@ -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
@@ -1,5 +1,6 @@
1
1
  export { DomPool } from "./dom-pool";
2
2
  export { EventBus } from "./events";
3
+ export { IconRegistry } from "./icons";
3
4
  export { Grid } from "./grid";
4
5
  export { Grid as GridCore } from "./grid";
5
6
  export { SlotManager } from "./slots";
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";
@@ -259,11 +260,16 @@ export interface RowHoverEvent<T> extends RowRenderParams<T> {
259
260
  export interface GridPlugin<T> {
260
261
  name: string;
261
262
  register(api: GridApi<T>): void | (() => void);
263
+ getRowClass?(params: RowRenderParams<T>): string | undefined;
262
264
  getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
263
265
  }
264
266
  export type SlotName = "top" | "bottom" | "left" | "right";
265
267
  export type SlotPosition = "start" | "center" | "end";
266
268
  export type SlotNodeEventName = "click" | "change" | "keydown";
269
+ export interface SlotNodeEvent {
270
+ value?: string;
271
+ key?: string;
272
+ }
267
273
  /**
268
274
  * Context passed to the slot content provider. Headless: the plugin
269
275
  * works only with the core API and state — no DOM or framework code.
@@ -287,7 +293,7 @@ export interface SlotNodeContent<T> {
287
293
  type: "node";
288
294
  tag: string;
289
295
  attrs?: Record<string, string | number | boolean | undefined>;
290
- on?: Partial<Record<SlotNodeEventName, (context: SlotRenderContext<T>) => void>>;
296
+ on?: Partial<Record<SlotNodeEventName, (context: SlotRenderContext<T>, event: SlotNodeEvent) => void>>;
291
297
  children?: SlotContent[];
292
298
  }
293
299
  /**
@@ -349,6 +355,7 @@ export interface GridApi<T> {
349
355
  rowClick(row: RowClickEvent<T>): void;
350
356
  rowHover(row: RowHoverEvent<T>): void;
351
357
  readonly slots: SlotManager<T>;
358
+ readonly icons: IconRegistry<T>;
352
359
  getSlotMounts(slot: SlotName): SlotMount<T>[];
353
360
  /** Monotonic counter for structural changes (refresh / data / columns). */
354
361
  getRevision(): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",