@ornery/ui-grid-vanilla 1.0.6 → 1.0.7

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/index.d.mts CHANGED
@@ -291,6 +291,8 @@ declare class VanillaGridController {
291
291
  private labels;
292
292
  private visibleColumns;
293
293
  private apiRegistered;
294
+ private disposed;
295
+ private wasmEngineInitRequested;
294
296
  private readonly subscribers;
295
297
  readonly gridApi: UiGridApi;
296
298
  constructor(options: GridOptions);
@@ -479,6 +481,7 @@ declare class VanillaGridController {
479
481
  scrollLeft: number;
480
482
  }) | null, restore: ((scrollTop: number, scrollLeft: number) => void) | null): void;
481
483
  private refresh;
484
+ private maybeEnableWasmEngine;
482
485
  private emit;
483
486
  private findRowById;
484
487
  private buildRowsFromData;
package/dist/index.d.ts CHANGED
@@ -291,6 +291,8 @@ declare class VanillaGridController {
291
291
  private labels;
292
292
  private visibleColumns;
293
293
  private apiRegistered;
294
+ private disposed;
295
+ private wasmEngineInitRequested;
294
296
  private readonly subscribers;
295
297
  readonly gridApi: UiGridApi;
296
298
  constructor(options: GridOptions);
@@ -479,6 +481,7 @@ declare class VanillaGridController {
479
481
  scrollLeft: number;
480
482
  }) | null, restore: ((scrollTop: number, scrollLeft: number) => void) | null): void;
481
483
  private refresh;
484
+ private maybeEnableWasmEngine;
482
485
  private emit;
483
486
  private findRowById;
484
487
  private buildRowsFromData;
package/dist/index.js CHANGED
@@ -54,6 +54,7 @@ var FrameworkSlotBridge = class {
54
54
  constructor(host) {
55
55
  this.host = host;
56
56
  }
57
+ host;
57
58
  flaggedCells = /* @__PURE__ */ new Set();
58
59
  flaggedHeaders = /* @__PURE__ */ new Set();
59
60
  flaggedFilters = /* @__PURE__ */ new Set();
@@ -2371,6 +2372,8 @@ var VanillaGridController = class {
2371
2372
  labels;
2372
2373
  visibleColumns = [];
2373
2374
  apiRegistered = false;
2375
+ disposed = false;
2376
+ wasmEngineInitRequested = false;
2374
2377
  subscribers = /* @__PURE__ */ new Set();
2375
2378
  gridApi;
2376
2379
  constructor(options) {
@@ -2579,6 +2582,7 @@ var VanillaGridController = class {
2579
2582
  * subscriptions). */
2580
2583
  disposeLanguageListener = null;
2581
2584
  dispose() {
2585
+ this.disposed = true;
2582
2586
  this.disposeLanguageListener?.();
2583
2587
  this.disposeLanguageListener = null;
2584
2588
  this.subscribers.clear();
@@ -3579,6 +3583,7 @@ var VanillaGridController = class {
3579
3583
  this.saveStateScrollRestore = restore;
3580
3584
  }
3581
3585
  refresh() {
3586
+ this.maybeEnableWasmEngine();
3582
3587
  const orderedColumns = orderVisibleColumns(this.options.columnDefs, this.columnOrder);
3583
3588
  const applyWidthOverrides = (columns) => columns.map((col) => {
3584
3589
  const override = this.columnWidthOverrides[col.name];
@@ -3642,6 +3647,19 @@ var VanillaGridController = class {
3642
3647
  }
3643
3648
  this.emit();
3644
3649
  }
3650
+ maybeEnableWasmEngine() {
3651
+ if (this.wasmEngineInitRequested || (0, import_ui_grid_core5.activeGridEngineBackend)() === "rust-wasm") {
3652
+ return;
3653
+ }
3654
+ this.wasmEngineInitRequested = true;
3655
+ void (0, import_ui_grid_core5.enableUiGridWasmEngine)().then(() => {
3656
+ if (!this.disposed) {
3657
+ this.refresh();
3658
+ }
3659
+ }).catch(() => {
3660
+ this.wasmEngineInitRequested = false;
3661
+ });
3662
+ }
3645
3663
  emit() {
3646
3664
  const snapshot = this.getSnapshot();
3647
3665
  for (const subscriber of this.subscribers) {
package/dist/index.mjs CHANGED
@@ -27,6 +27,7 @@ var FrameworkSlotBridge = class {
27
27
  constructor(host) {
28
28
  this.host = host;
29
29
  }
30
+ host;
30
31
  flaggedCells = /* @__PURE__ */ new Set();
31
32
  flaggedHeaders = /* @__PURE__ */ new Set();
32
33
  flaggedFilters = /* @__PURE__ */ new Set();
@@ -2235,6 +2236,7 @@ var IconRegistry = class {
2235
2236
  // src/grid-controller.ts
2236
2237
  import {
2237
2238
  SORT_DIRECTIONS as SORT_DIRECTIONS2,
2239
+ activeGridEngineBackend,
2238
2240
  beginGridCellEditCommand,
2239
2241
  buildGridRows,
2240
2242
  buildGridCellContext,
@@ -2250,6 +2252,7 @@ import {
2250
2252
  defaultGridEngine,
2251
2253
  expandAllGridRowsCommand,
2252
2254
  expandAllGridTreeRowsCommand,
2255
+ enableUiGridWasmEngine,
2253
2256
  findGridRowById as coreFindGridRowById,
2254
2257
  formatGridCellDisplayValue,
2255
2258
  getCellValue as getCellValue3,
@@ -2458,6 +2461,8 @@ var VanillaGridController = class {
2458
2461
  labels;
2459
2462
  visibleColumns = [];
2460
2463
  apiRegistered = false;
2464
+ disposed = false;
2465
+ wasmEngineInitRequested = false;
2461
2466
  subscribers = /* @__PURE__ */ new Set();
2462
2467
  gridApi;
2463
2468
  constructor(options) {
@@ -2666,6 +2671,7 @@ var VanillaGridController = class {
2666
2671
  * subscriptions). */
2667
2672
  disposeLanguageListener = null;
2668
2673
  dispose() {
2674
+ this.disposed = true;
2669
2675
  this.disposeLanguageListener?.();
2670
2676
  this.disposeLanguageListener = null;
2671
2677
  this.subscribers.clear();
@@ -3666,6 +3672,7 @@ var VanillaGridController = class {
3666
3672
  this.saveStateScrollRestore = restore;
3667
3673
  }
3668
3674
  refresh() {
3675
+ this.maybeEnableWasmEngine();
3669
3676
  const orderedColumns = orderVisibleColumns(this.options.columnDefs, this.columnOrder);
3670
3677
  const applyWidthOverrides = (columns) => columns.map((col) => {
3671
3678
  const override = this.columnWidthOverrides[col.name];
@@ -3729,6 +3736,19 @@ var VanillaGridController = class {
3729
3736
  }
3730
3737
  this.emit();
3731
3738
  }
3739
+ maybeEnableWasmEngine() {
3740
+ if (this.wasmEngineInitRequested || activeGridEngineBackend() === "rust-wasm") {
3741
+ return;
3742
+ }
3743
+ this.wasmEngineInitRequested = true;
3744
+ void enableUiGridWasmEngine().then(() => {
3745
+ if (!this.disposed) {
3746
+ this.refresh();
3747
+ }
3748
+ }).catch(() => {
3749
+ this.wasmEngineInitRequested = false;
3750
+ });
3751
+ }
3732
3752
  emit() {
3733
3753
  const snapshot = this.getSnapshot();
3734
3754
  for (const subscriber of this.subscribers) {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@ornery/ui-grid-vanilla",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Vanilla DOM wrapper for the Rust/WASM-backed @ornery/ui-grid-core custom element",
5
5
  "publishConfig": {
6
+ "registry": "https://registry.npmjs.org/",
6
7
  "access": "public"
7
8
  },
8
9
  "main": "dist/index.js",
@@ -13,7 +14,13 @@
13
14
  "types": "./dist/index.d.ts",
14
15
  "import": "./dist/index.mjs",
15
16
  "require": "./dist/index.js"
16
- }
17
+ },
18
+ "./browser": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/browser/ui-grid-element.js",
21
+ "default": "./dist/browser/ui-grid-element.js"
22
+ },
23
+ "./browser/ui-grid-element.js": "./dist/browser/ui-grid-element.js"
17
24
  },
18
25
  "dependencies": {
19
26
  "@ornery/ui-grid-core": "1.0.6"
@@ -0,0 +1,9 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import './browser';
4
+
5
+ describe('browser entry', () => {
6
+ it('auto-registers the standalone grid element', () => {
7
+ expect(customElements.get('ui-grid-element')).toBeDefined();
8
+ });
9
+ });
package/src/browser.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './index';
2
+ export { defineStandaloneUiGridElement } from './ui-grid-standalone.element';
3
+
4
+ import { defineStandaloneUiGridElement } from './ui-grid-standalone.element';
5
+
6
+ if (typeof window !== 'undefined' && typeof customElements !== 'undefined') {
7
+ void defineStandaloneUiGridElement();
8
+ }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  SORT_DIRECTIONS,
3
+ activeGridEngineBackend,
3
4
  beginGridCellEditCommand,
4
5
  buildGridRows,
5
6
  buildGridCellContext,
@@ -15,6 +16,7 @@ import {
15
16
  defaultGridEngine,
16
17
  expandAllGridRowsCommand,
17
18
  expandAllGridTreeRowsCommand,
19
+ enableUiGridWasmEngine,
18
20
  findGridRowById as coreFindGridRowById,
19
21
  formatGridCellDisplayValue,
20
22
  getCellValue,
@@ -343,6 +345,8 @@ export class VanillaGridController {
343
345
  private labels: GridLabels;
344
346
  private visibleColumns: GridColumnDef[] = [];
345
347
  private apiRegistered = false;
348
+ private disposed = false;
349
+ private wasmEngineInitRequested = false;
346
350
 
347
351
  private readonly subscribers = new Set<GridControllerSubscriber>();
348
352
 
@@ -591,6 +595,7 @@ export class VanillaGridController {
591
595
  * subscriptions). */
592
596
  private disposeLanguageListener: (() => void) | null = null;
593
597
  dispose(): void {
598
+ this.disposed = true;
594
599
  this.disposeLanguageListener?.();
595
600
  this.disposeLanguageListener = null;
596
601
  this.subscribers.clear();
@@ -1811,6 +1816,8 @@ export class VanillaGridController {
1811
1816
  }
1812
1817
 
1813
1818
  private refresh(): void {
1819
+ this.maybeEnableWasmEngine();
1820
+
1814
1821
  const orderedColumns = orderVisibleColumns(this.options.columnDefs, this.columnOrder);
1815
1822
  const applyWidthOverrides = (columns: GridColumnDef[]): GridColumnDef[] =>
1816
1823
  columns.map((col) => {
@@ -1897,6 +1904,23 @@ export class VanillaGridController {
1897
1904
  this.emit();
1898
1905
  }
1899
1906
 
1907
+ private maybeEnableWasmEngine(): void {
1908
+ if (this.wasmEngineInitRequested || activeGridEngineBackend() === 'rust-wasm') {
1909
+ return;
1910
+ }
1911
+
1912
+ this.wasmEngineInitRequested = true;
1913
+ void enableUiGridWasmEngine()
1914
+ .then(() => {
1915
+ if (!this.disposed) {
1916
+ this.refresh();
1917
+ }
1918
+ })
1919
+ .catch(() => {
1920
+ this.wasmEngineInitRequested = false;
1921
+ });
1922
+ }
1923
+
1900
1924
  private emit(): void {
1901
1925
  const snapshot = this.getSnapshot();
1902
1926
  for (const subscriber of this.subscribers) {
@@ -4,9 +4,11 @@ import * as core from '@ornery/ui-grid-core';
4
4
  import {
5
5
  SORT_DIRECTIONS,
6
6
  activeGridEngineBackend,
7
+ buildGridRows,
7
8
  clearRustWasmGridEngine,
8
9
  } from '@ornery/ui-grid-core';
9
10
  import {
11
+ defineStandaloneUiGridElement,
10
12
  mountVanillaUiGrid,
11
13
  registerVanillaUiGridRustModule,
12
14
  type GridOptions,
@@ -177,8 +179,25 @@ describe('mountVanillaUiGrid integration', () => {
177
179
  ]);
178
180
  });
179
181
 
180
- it('does not auto-enable the wasm engine during controller refreshes', () => {
181
- const enableSpy = vi.spyOn(core, 'enableUiGridWasmEngine');
182
+ it('lazy-loads the wasm engine once and refreshes through it when ready', async () => {
183
+ const enableSpy = vi.spyOn(core, 'enableUiGridWasmEngine').mockImplementation(async () => {
184
+ core.registerRustWasmGridEngine({
185
+ buildPipeline(context) {
186
+ return {
187
+ visibleRows: buildGridRows(
188
+ context.options,
189
+ context.rowSize,
190
+ context.hiddenRowReasons,
191
+ context.expandedRows,
192
+ ),
193
+ displayItems: [],
194
+ virtualizationEnabled: false,
195
+ pipelineMs: 123,
196
+ totalItems: context.options.data.length,
197
+ };
198
+ },
199
+ });
200
+ });
182
201
 
183
202
  const controller = createVanillaGridController({
184
203
  id: 'controller-wasm-bootstrap',
@@ -191,14 +210,20 @@ describe('mountVanillaUiGrid integration', () => {
191
210
  enableFiltering: true,
192
211
  });
193
212
 
194
- expect(enableSpy).not.toHaveBeenCalled();
195
- expect(activeGridEngineBackend()).toBe('typescript');
213
+ expect(enableSpy).toHaveBeenCalledTimes(1);
214
+
215
+ await waitFor(() => {
216
+ const snapshot = controller.getSnapshot();
217
+ return activeGridEngineBackend() === 'rust-wasm' && snapshot.pipeline.pipelineMs === 123
218
+ ? snapshot
219
+ : null;
220
+ });
196
221
 
197
222
  controller.setFilter('name', 'Alpha');
198
223
  controller.sortColumn('name', SORT_DIRECTIONS.asc);
199
224
 
200
- expect(enableSpy).not.toHaveBeenCalled();
201
- expect(controller.getSnapshot().pipeline.pipelineMs).not.toBe(123);
225
+ expect(enableSpy).toHaveBeenCalledTimes(1);
226
+ expect(controller.getSnapshot().pipeline.pipelineMs).toBe(123);
202
227
  enableSpy.mockRestore();
203
228
  });
204
229
 
@@ -322,4 +347,5 @@ describe('mountVanillaUiGrid integration', () => {
322
347
  expect((grid.options.data as Array<{ id: string; name: string }>)[0].name).toBe('Gamma');
323
348
  expect(grid.options.minRowsToShow).toBe(20);
324
349
  });
350
+
325
351
  });
package/tsup.config.ts CHANGED
@@ -1,10 +1,25 @@
1
1
  import { defineConfig } from 'tsup';
2
2
  import { scssInlineEsbuild } from './scss-plugin';
3
3
 
4
- export default defineConfig({
5
- entry: ['src/index.ts'],
6
- format: ['esm', 'cjs'],
7
- dts: true,
8
- tsconfig: './tsconfig.json',
9
- esbuildPlugins: [scssInlineEsbuild()],
10
- });
4
+ export default defineConfig([
5
+ {
6
+ entry: ['src/index.ts'],
7
+ format: ['esm', 'cjs'],
8
+ dts: true,
9
+ tsconfig: './tsconfig.json',
10
+ esbuildPlugins: [scssInlineEsbuild()],
11
+ },
12
+ {
13
+ entry: { 'ui-grid-element': 'src/browser.ts' },
14
+ format: ['esm'],
15
+ dts: false,
16
+ splitting: false,
17
+ platform: 'browser',
18
+ target: 'es2022',
19
+ outDir: 'dist/browser',
20
+ outExtension: () => ({ js: '.js' }),
21
+ tsconfig: './tsconfig.json',
22
+ noExternal: ['@ornery/ui-grid-core'],
23
+ esbuildPlugins: [scssInlineEsbuild()],
24
+ },
25
+ ]);