@proto-labs-inc/rig-vue 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Proto Labs Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @proto-labs-inc/rig-vue
2
+
3
+ The rig for Vue prototypes: `app.use(protoRig(manifest))` at the root, and
4
+ `usePreviewState` / `useVariant` in components. All logic lives in
5
+ `@proto-labs-inc/rig-core`; this package is the Vue idiom.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @proto-labs-inc/rig-vue — the Vue 3 adapter over @proto-labs-inc/rig-core. All rig logic
3
+ * lives in the core; this file is only the Vue idiom: an app plugin +
4
+ * composables mirroring the React hooks' [value, set] shape.
5
+ *
6
+ * Usage:
7
+ * app.use(protoRig(manifest))
8
+ * const [state, setState] = usePreviewState("populated", ["populated", "empty"])
9
+ */
10
+ import { type Plugin, type Ref } from "vue";
11
+ import type { Manifest } from "@proto-labs-inc/wire";
12
+ /** Install on the app root; wires the bridge once, client-side. */
13
+ export declare function protoRig(manifest: Manifest): Plugin;
14
+ /** The prototype's preview state, addressable as ?state=<id>. */
15
+ export declare function usePreviewState(defaultId: string, validIds?: readonly string[]): readonly [Readonly<Ref<string, string>>, (v: string) => void];
16
+ /** A component's design variant, addressable as ?v.<component>=<id>. */
17
+ export declare function useVariant(component: string, defaultVariant: string, validIds?: readonly string[]): readonly [Readonly<Ref<string, string>>, (v: string) => void];
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @proto-labs-inc/rig-vue — the Vue 3 adapter over @proto-labs-inc/rig-core. All rig logic
3
+ * lives in the core; this file is only the Vue idiom: an app plugin +
4
+ * composables mirroring the React hooks' [value, set] shape.
5
+ *
6
+ * Usage:
7
+ * app.use(protoRig(manifest))
8
+ * const [state, setState] = usePreviewState("populated", ["populated", "empty"])
9
+ */
10
+ import { inject, onScopeDispose, shallowRef, } from "vue";
11
+ import { RigStore, wireRig, STATE_PARAM, variantParam } from "@proto-labs-inc/rig-core";
12
+ const RIG_KEY = Symbol("proto-rig");
13
+ /** Install on the app root; wires the bridge once, client-side. */
14
+ export function protoRig(manifest) {
15
+ return {
16
+ install(app) {
17
+ const store = new RigStore(manifest);
18
+ app.provide(RIG_KEY, store);
19
+ if (typeof window !== "undefined") {
20
+ const dispose = wireRig(store, manifest);
21
+ const unmount = app.unmount.bind(app);
22
+ app.unmount = () => {
23
+ dispose();
24
+ unmount();
25
+ };
26
+ }
27
+ },
28
+ };
29
+ }
30
+ function useRigValue(key, fallback, valid) {
31
+ const store = inject(RIG_KEY, null);
32
+ if (!store)
33
+ throw new Error("useRig* composables require app.use(protoRig(manifest))");
34
+ const normalize = (raw) => valid && !valid.includes(raw) ? fallback : raw;
35
+ const value = shallowRef(normalize(store.get(key) ?? fallback));
36
+ const unsubscribe = store.subscribe(() => {
37
+ value.value = normalize(store.get(key) ?? fallback);
38
+ });
39
+ onScopeDispose(unsubscribe);
40
+ const set = (v) => store.set(key, v);
41
+ return [value, set];
42
+ }
43
+ /** The prototype's preview state, addressable as ?state=<id>. */
44
+ export function usePreviewState(defaultId, validIds) {
45
+ return useRigValue(STATE_PARAM, defaultId, validIds);
46
+ }
47
+ /** A component's design variant, addressable as ?v.<component>=<id>. */
48
+ export function useVariant(component, defaultVariant, validIds) {
49
+ return useRigValue(variantParam(component), defaultVariant, validIds);
50
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@proto-labs-inc/rig-vue",
3
+ "version": "0.1.0",
4
+ "description": "Proto's rig for Vue prototypes: an app plugin and composables over @proto-labs-inc/rig-core.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/proto-labs-inc/proto.git",
9
+ "directory": "packages/rig-vue"
10
+ },
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "peerDependencies": {
23
+ "vue": ">=3.3"
24
+ },
25
+ "dependencies": {
26
+ "@proto-labs-inc/rig-core": "^0.1.0",
27
+ "@proto-labs-inc/wire": "^0.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "~6.0.2",
31
+ "vue": "^3.5.13"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.build.json",
38
+ "typecheck": "tsc --noEmit"
39
+ },
40
+ "main": "./dist/index.js",
41
+ "types": "./dist/index.d.ts"
42
+ }