@proto-labs-inc/rig 0.2.4 → 0.3.0

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # @proto-labs-inc/rig
2
2
 
3
- The rig for React prototypes: `<ProtoRig manifest={…}>` at the root, and
4
- `usePreviewState` / `useVariant` wherever a view reads its state or variant.
5
- All logic lives in `@proto-labs-inc/rig-core`; this package is the React idiom.
3
+ Wrap the prototype in `<ProtoRig manifest={manifest}>`. Children render after
4
+ the current compatible hosted runtime initializes. Startup failure shows Retry.
5
+ Components keep using `usePreviewState` and `useVariant`; framework-independent
6
+ behavior lives in the hosted runtime, not the bundled adapter.
7
+
8
+ Ordinary runtime releases do not require rebuilding this prototype. Adapter or
9
+ loader changes still require an explicit package upgrade and rebuild.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
- * @proto-labs-inc/rig — the React adapter over @proto-labs-inc/rig-core. All rig logic
3
- * (URL-state sync, the bridge, tooling loader) lives in the core; this file
4
- * is only the React idiom: a provider component + hooks.
2
+ * @proto-labs-inc/rig — the React adapter over @proto-labs-inc/rig-core. The core loads hosted behavior; this file gates React rendering and
3
+ * exposes provider/hooks over its stable store contract.
5
4
  */
6
5
  import { type ReactNode } from "react";
7
6
  import { type Manifest } from "@proto-labs-inc/wire";
package/dist/index.js CHANGED
@@ -1,22 +1,38 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  /**
4
- * @proto-labs-inc/rig — the React adapter over @proto-labs-inc/rig-core. All rig logic
5
- * (URL-state sync, the bridge, tooling loader) lives in the core; this file
6
- * is only the React idiom: a provider component + hooks.
4
+ * @proto-labs-inc/rig — the React adapter over @proto-labs-inc/rig-core. The core loads hosted behavior; this file gates React rendering and
5
+ * exposes provider/hooks over its stable store contract.
7
6
  */
8
- import { createContext, useCallback, useContext, useEffect, useRef, useSyncExternalStore, } from "react";
9
- import { RigStore, wireRig, STATE_PARAM, variantParam, } from "@proto-labs-inc/rig-core";
7
+ import { createContext, useCallback, useContext, useEffect, useState, useMemo, useSyncExternalStore, } from "react";
8
+ import { loadRuntime, STATE_PARAM, variantParam, } from "@proto-labs-inc/rig-core";
10
9
  const RigContext = createContext(null);
11
10
  export function ProtoRig({ manifest, children, }) {
12
- // One store per mount; survives re-renders, resets on full reload (correct:
13
- // a reload re-hydrates from the URL, which is the source of truth).
14
- const storeRef = useRef(null);
15
- if (storeRef.current === null)
16
- storeRef.current = new RigStore(manifest);
17
- const store = storeRef.current;
18
- useEffect(() => wireRig(store, manifest), [store, manifest]);
19
- return _jsx(RigContext.Provider, { value: store, children: children });
11
+ const manifestJson = JSON.stringify(manifest);
12
+ const stableManifest = useMemo(() => JSON.parse(manifestJson), [manifestJson]);
13
+ const [boot, setBoot] = useState({ status: "loading" });
14
+ useEffect(() => {
15
+ const controller = new AbortController();
16
+ let runtime;
17
+ setBoot({ status: "loading" });
18
+ void loadRuntime(stableManifest, controller.signal).then(value => {
19
+ if (controller.signal.aborted) {
20
+ value.dispose();
21
+ return;
22
+ }
23
+ runtime = value;
24
+ setBoot({ status: "ready", runtime: value });
25
+ }).catch(error => {
26
+ if (!controller.signal.aborted)
27
+ setBoot({ status: "error", message: String(error) });
28
+ });
29
+ return () => { controller.abort(); runtime?.dispose(); };
30
+ }, [stableManifest]);
31
+ if (boot.status === "loading")
32
+ return _jsx("div", { role: "status", children: "Loading prototype\u2026" });
33
+ if (boot.status === "error")
34
+ return _jsxs("div", { role: "alert", children: ["Could not load the rig. ", boot.message, " ", _jsx("button", { onClick: () => window.location.reload(), children: "Retry" })] });
35
+ return _jsx(RigContext.Provider, { value: boot.runtime.store, children: children });
20
36
  }
21
37
  function useRigValue(key, fallback, valid) {
22
38
  const store = useContext(RigContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proto-labs-inc/rig",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Proto's rig for React prototypes: a provider and hooks over @proto-labs-inc/rig-core.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,8 +23,8 @@
23
23
  "react": ">=18"
24
24
  },
25
25
  "dependencies": {
26
- "@proto-labs-inc/wire": "^0.2.3",
27
- "@proto-labs-inc/rig-core": "^0.2.4"
26
+ "@proto-labs-inc/rig-core": "^0.3.0",
27
+ "@proto-labs-inc/wire": "^0.3.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "~6.0.2",