@omnigrid/core 0.1.15 → 0.1.16

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
@@ -7,6 +7,7 @@ export declare class Grid<T> implements GridApi<T> {
7
7
  private readonly events;
8
8
  private readonly virtualizer;
9
9
  private readonly cleanupPlugins;
10
+ private readonly pluginRegistrations;
10
11
  private readonly dataProcessors;
11
12
  private readonly resolveRowId;
12
13
  readonly slots: SlotManager<T>;
@@ -77,6 +78,15 @@ export declare class Grid<T> implements GridApi<T> {
77
78
  on<EventName extends keyof GridEvents<T>>(event: EventName, listener: (payload: GridEvents<T>[EventName]) => void): () => void;
78
79
  emit<EventName extends keyof GridEvents<T>>(event: EventName, payload: GridEvents<T>[EventName]): void;
79
80
  registerPlugin(plugin: GridPlugin<T>): () => void;
81
+ /**
82
+ * Reconciles the registered plugins with the given list: plugins missing from
83
+ * the list are unregistered (their cleanup restores default behavior), new
84
+ * ones are registered. Plugins already registered are left untouched.
85
+ * When the set actually changes, the vertical scroll position is reset to
86
+ * the top, since the plugin set redefines how rows are sourced.
87
+ * @param plugins - The desired plugin set.
88
+ */
89
+ setPlugins(plugins: GridPlugin<T>[] | null | undefined): void;
80
90
  getSlotMounts(slot: SlotName): SlotMount<T>[];
81
91
  showOverlay(options: OverlayOptions): void;
82
92
  hideOverlay(): void;
package/dist/grid.js CHANGED
@@ -9,6 +9,7 @@ export class Grid {
9
9
  constructor(options) {
10
10
  this.events = new EventBus();
11
11
  this.cleanupPlugins = new Set();
12
+ this.pluginRegistrations = new Map();
12
13
  this.dataProcessors = new Set();
13
14
  this.icons = new IconRegistry();
14
15
  this.processedDataCache = null;
@@ -341,10 +342,42 @@ export class Grid {
341
342
  const unregister = () => {
342
343
  cleanup?.();
343
344
  this.cleanupPlugins.delete(unregister);
345
+ if (this.pluginRegistrations.get(plugin) === unregister)
346
+ this.pluginRegistrations.delete(plugin);
344
347
  };
345
348
  this.cleanupPlugins.add(unregister);
349
+ this.pluginRegistrations.set(plugin, unregister);
346
350
  return unregister;
347
351
  }
352
+ /**
353
+ * Reconciles the registered plugins with the given list: plugins missing from
354
+ * the list are unregistered (their cleanup restores default behavior), new
355
+ * ones are registered. Plugins already registered are left untouched.
356
+ * When the set actually changes, the vertical scroll position is reset to
357
+ * the top, since the plugin set redefines how rows are sourced.
358
+ * @param plugins - The desired plugin set.
359
+ */
360
+ setPlugins(plugins) {
361
+ this.assertActive();
362
+ const next = plugins ?? [];
363
+ let changed = false;
364
+ Array.from(this.pluginRegistrations.entries()).forEach(([plugin, unregister]) => {
365
+ if (!next.includes(plugin)) {
366
+ unregister();
367
+ changed = true;
368
+ }
369
+ });
370
+ next.forEach((plugin) => {
371
+ if (!this.pluginRegistrations.has(plugin)) {
372
+ this.registerPlugin(plugin);
373
+ changed = true;
374
+ }
375
+ });
376
+ if (changed) {
377
+ this.scrollTo({ scrollTop: 0 });
378
+ this.refresh();
379
+ }
380
+ }
348
381
  getSlotMounts(slot) {
349
382
  return this.slots.getMounts(slot);
350
383
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",