@vizhub/runtime 4.0.1 → 4.0.3
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/README.md +82 -0
- package/dist/build/build.d.ts.map +1 -1
- package/dist/build/types.d.ts +1 -0
- package/dist/build/types.d.ts.map +1 -1
- package/dist/{build-C3ij8Dz4.js → build-D8ObHgQc.js} +271 -205
- package/dist/build-D8ObHgQc.js.map +1 -0
- package/dist/build-t6B4kQWS.cjs +214 -0
- package/dist/build-t6B4kQWS.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -30
- package/dist/index.js.map +1 -1
- package/dist/orchestration/createRuntime.d.ts.map +1 -1
- package/dist/test/testMockedIframeWithWorker.d.ts.map +1 -1
- package/dist/v2/computeBundleJSV2.d.ts.map +1 -1
- package/dist/v3/v3Build.d.ts.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +3 -2
- package/dist/build-C3ij8Dz4.js.map +0 -1
- package/dist/build-Cnsq_4EK.cjs +0 -214
- package/dist/build-Cnsq_4EK.cjs.map +0 -1
package/README.md
CHANGED
@@ -337,6 +337,88 @@ npm install @vizhub/runtime
|
|
337
337
|
|
338
338
|
### Basic Usage
|
339
339
|
|
340
|
+
#### createRuntime(options)
|
341
|
+
|
342
|
+
Creates a runtime environment that manages code execution in an iframe with worker-based build support.
|
343
|
+
|
344
|
+
```typescript
|
345
|
+
const runtime = createRuntime({
|
346
|
+
iframe: HTMLIFrameElement,
|
347
|
+
worker: Worker,
|
348
|
+
setBuildErrorMessage?: (error: string | null) => void,
|
349
|
+
getLatestContent?: (vizId: string) => Promise<VizContent | null>,
|
350
|
+
resolveSlugKey?: (slugKey: string) => Promise<string | null>,
|
351
|
+
writeFile?: (fileName: string, content: string) => void
|
352
|
+
});
|
353
|
+
```
|
354
|
+
|
355
|
+
##### Options
|
356
|
+
|
357
|
+
- **iframe**: `HTMLIFrameElement` - The iframe element where the viz will be rendered
|
358
|
+
- **worker**: `Worker` - Web Worker instance that handles code building
|
359
|
+
- **setBuildErrorMessage**: `(error: string | null) => void` - Optional callback for handling build errors
|
360
|
+
- **getLatestContent**: `(vizId: string) => Promise<VizContent | null>` - Optional function to fetch viz content for cross-viz imports
|
361
|
+
- **resolveSlugKey**: `(slugKey: string) => Promise<string | null>` - Optional function to resolve viz slugs to IDs
|
362
|
+
- **writeFile**: `(fileName: string, content: string) => void` - Optional callback when code running in the iframe writes files
|
363
|
+
|
364
|
+
##### Returns
|
365
|
+
|
366
|
+
Returns a `VizHubRuntime` object with methods:
|
367
|
+
|
368
|
+
- **run**: `(options: RunOptions) => void` - Executes code in the iframe
|
369
|
+
- **options.files**: `FileCollection` - Map of filenames to file contents
|
370
|
+
- **options.enableHotReloading**: `boolean` - Enable hot reloading (v3 runtime only)
|
371
|
+
- **options.enableSourcemap**: `boolean` - Enable source maps for debugging
|
372
|
+
- **options.vizId**: `string` - ID of current viz (required for v3)
|
373
|
+
- **cleanup**: `() => void` - Removes event listeners from worker and iframe
|
374
|
+
- **invalidateVizCache**: `(changedVizIds: string[]) => Promise<void>` - Invalidates cache for specified viz IDs
|
375
|
+
|
376
|
+
##### Example
|
377
|
+
|
378
|
+
```javascript
|
379
|
+
import { createRuntime } from "@vizhub/runtime";
|
380
|
+
import BuildWorker from "./buildWorker?worker";
|
381
|
+
|
382
|
+
// Get iframe from DOM
|
383
|
+
const iframe = document.getElementById("viz-iframe");
|
384
|
+
|
385
|
+
// Create worker
|
386
|
+
const worker = new BuildWorker();
|
387
|
+
|
388
|
+
// Initialize runtime
|
389
|
+
const runtime = createRuntime({
|
390
|
+
iframe,
|
391
|
+
worker,
|
392
|
+
setBuildErrorMessage: (error) => {
|
393
|
+
error && console.error("Build error:", error);
|
394
|
+
},
|
395
|
+
getLatestContent: async (vizId) => {
|
396
|
+
// Fetch viz content from your backend
|
397
|
+
return await fetchVizContent(vizId);
|
398
|
+
},
|
399
|
+
resolveSlugKey: async (slugKey) => {
|
400
|
+
// Resolve slug to vizId from your backend
|
401
|
+
return await resolveSlug(slugKey);
|
402
|
+
},
|
403
|
+
});
|
404
|
+
|
405
|
+
// Run code in the iframe
|
406
|
+
runtime.run({
|
407
|
+
files: {
|
408
|
+
"index.js":
|
409
|
+
'console.log("Hello from VizHub runtime!");',
|
410
|
+
},
|
411
|
+
enableHotReloading: true,
|
412
|
+
enableSourcemap: true,
|
413
|
+
vizId: "example-viz",
|
414
|
+
});
|
415
|
+
|
416
|
+
// Clean up when done
|
417
|
+
runtime.cleanup();
|
418
|
+
```
|
419
|
+
|
420
|
+
### Building HTML Only
|
421
|
+
|
340
422
|
```javascript
|
341
423
|
import { build } from "@vizhub/runtime";
|
342
424
|
import { rollup } from "rollup";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAGL,SAAS,EACT,cAAc,EAEd,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAUtC,eAAO,MAAM,KAAK,GAAU,oFAQzB;IAGD,KAAK,CAAC,EAAE,cAAc,CAAC;IAGvB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IAQ1D,eAAe,CAAC,EAAE,OAAO,CAAC;IAI1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;CACnD,KAAG,OAAO,CAAC,WAAW,
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAGL,SAAS,EACT,cAAc,EAEd,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAUtC,eAAO,MAAM,KAAK,GAAU,oFAQzB;IAGD,KAAK,CAAC,EAAE,cAAc,CAAC;IAGvB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IAQ1D,eAAe,CAAC,EAAE,OAAO,CAAC;IAI1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;CACnD,KAAG,OAAO,CAAC,WAAW,CAuItB,CAAC"}
|
package/dist/build/types.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/build/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAGvD,MAAM,MAAM,WAAW,GAAG;IAKxB,IAAI,EAAE,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/build/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAGvD,MAAM,MAAM,WAAW,GAAG;IAKxB,IAAI,EAAE,MAAM,CAAC;IAGb,cAAc,EAAE,cAAc,CAAC;IAI/B,GAAG,CAAC,EAAE,MAAM,CAAC;IAIb,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
|