@proto-labs-inc/rig-vue 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 +13 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +10 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @proto-labs-inc/rig-vue
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Await the hosted runtime before mounting Vue:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
async function start() {
|
|
7
|
+
const rig = await protoRig(manifest);
|
|
8
|
+
createApp(App).use(rig).mount("#app");
|
|
9
|
+
}
|
|
10
|
+
void start().catch(showRetry);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Components keep using `usePreviewState` and `useVariant`. The adapter subscribes
|
|
14
|
+
to the framework-independent hosted runtime and disposes it on app unmount.
|
|
15
|
+
The initial startup requires a working connection to the configured runtime.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @proto-labs-inc/rig-vue — the Vue 3 adapter over @proto-labs-inc/rig-core.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @proto-labs-inc/rig-vue — the Vue 3 adapter over @proto-labs-inc/rig-core. Hosted rig logic
|
|
3
|
+
* loads before mounting. This file supplies the Vue plugin and composables
|
|
4
|
+
* mirroring the React hooks' [value, set] shape.
|
|
5
5
|
*
|
|
6
6
|
* Usage:
|
|
7
|
-
* app.use(protoRig(manifest))
|
|
7
|
+
* app.use(await protoRig(manifest))
|
|
8
8
|
* const [state, setState] = usePreviewState("populated", ["populated", "empty"])
|
|
9
9
|
*/
|
|
10
10
|
import { type Plugin, type Ref } from "vue";
|
|
11
11
|
import type { Manifest } from "@proto-labs-inc/wire";
|
|
12
12
|
/** Install on the app root; wires the bridge once, client-side. */
|
|
13
|
-
export declare function protoRig(manifest: Manifest): Plugin
|
|
13
|
+
export declare function protoRig(manifest: Manifest): Promise<Plugin>;
|
|
14
14
|
/** The prototype's preview state, addressable as ?state=<id>. */
|
|
15
15
|
export declare function usePreviewState(defaultId: string, validIds?: readonly string[]): readonly [Readonly<Ref<string, string>>, (v: string) => void];
|
|
16
16
|
/** A component's design variant, addressable as ?v.<component>=<id>. */
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @proto-labs-inc/rig-vue — the Vue 3 adapter over @proto-labs-inc/rig-core.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @proto-labs-inc/rig-vue — the Vue 3 adapter over @proto-labs-inc/rig-core. Hosted rig logic
|
|
3
|
+
* loads before mounting. This file supplies the Vue plugin and composables
|
|
4
|
+
* mirroring the React hooks' [value, set] shape.
|
|
5
5
|
*
|
|
6
6
|
* Usage:
|
|
7
|
-
* app.use(protoRig(manifest))
|
|
7
|
+
* app.use(await protoRig(manifest))
|
|
8
8
|
* const [state, setState] = usePreviewState("populated", ["populated", "empty"])
|
|
9
9
|
*/
|
|
10
10
|
import { inject, onScopeDispose, shallowRef, } from "vue";
|
|
11
|
-
import {
|
|
11
|
+
import { loadRuntime, STATE_PARAM, variantParam } from "@proto-labs-inc/rig-core";
|
|
12
12
|
const RIG_KEY = Symbol("proto-rig");
|
|
13
13
|
/** Install on the app root; wires the bridge once, client-side. */
|
|
14
|
-
export function protoRig(manifest) {
|
|
14
|
+
export async function protoRig(manifest) {
|
|
15
|
+
const runtime = await loadRuntime(manifest, new AbortController().signal);
|
|
15
16
|
return {
|
|
16
17
|
install(app) {
|
|
17
|
-
const store =
|
|
18
|
+
const store = runtime.store;
|
|
18
19
|
app.provide(RIG_KEY, store);
|
|
19
20
|
if (typeof window !== "undefined") {
|
|
20
|
-
const dispose =
|
|
21
|
+
const dispose = () => runtime.dispose();
|
|
21
22
|
const unmount = app.unmount.bind(app);
|
|
22
23
|
app.unmount = () => {
|
|
23
24
|
dispose();
|
|
@@ -30,7 +31,7 @@ export function protoRig(manifest) {
|
|
|
30
31
|
function useRigValue(key, fallback, valid) {
|
|
31
32
|
const store = inject(RIG_KEY, null);
|
|
32
33
|
if (!store)
|
|
33
|
-
throw new Error("useRig* composables require app.use(protoRig(manifest))");
|
|
34
|
+
throw new Error("useRig* composables require app.use(await protoRig(manifest))");
|
|
34
35
|
const normalize = (raw) => valid && !valid.includes(raw) ? fallback : raw;
|
|
35
36
|
const value = shallowRef(normalize(store.get(key) ?? fallback));
|
|
36
37
|
const unsubscribe = store.subscribe(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proto-labs-inc/rig-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Proto's rig for Vue prototypes: an app plugin and composables over @proto-labs-inc/rig-core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"vue": ">=3.3"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@proto-labs-inc/rig-core": "^0.
|
|
27
|
-
"@proto-labs-inc/wire": "^0.
|
|
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",
|