@proto-labs-inc/rig 0.1.0 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @proto-labs-inc/rig — the React adapter over @proto-labs-inc/rig-core. All rig logic
3
- * (URL-state sync, the bridge, comment mode) lives in the core; this file
3
+ * (URL-state sync, the bridge, tooling loader) lives in the core; this file
4
4
  * is only the React idiom: a provider component + hooks.
5
5
  */
6
6
  import { type ReactNode } from "react";
package/dist/index.js CHANGED
@@ -1,85 +1,13 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  /**
4
4
  * @proto-labs-inc/rig — the React adapter over @proto-labs-inc/rig-core. All rig logic
5
- * (URL-state sync, the bridge, comment mode) lives in the core; this file
5
+ * (URL-state sync, the bridge, tooling loader) lives in the core; this file
6
6
  * is only the React idiom: a provider component + hooks.
7
7
  */
8
- import { createContext, useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore, } from "react";
9
- import { postToFrame, RigStore, wireRig, STATE_PARAM, variantParam, } from "@proto-labs-inc/rig-core";
10
- import { isFrameToRig } from "@proto-labs-inc/wire";
8
+ import { createContext, useCallback, useContext, useEffect, useRef, useSyncExternalStore, } from "react";
9
+ import { RigStore, wireRig, STATE_PARAM, variantParam, } from "@proto-labs-inc/rig-core";
11
10
  const RigContext = createContext(null);
12
- const PROTO_BLUE = "#0088FF";
13
- function TargetHighlight({ focus, onDismiss, }) {
14
- const [rect, setRect] = useState(null);
15
- useEffect(() => {
16
- let didScroll = false;
17
- const update = () => {
18
- const target = document.querySelector(`[data-proto-id="${CSS.escape(focus.id)}"]`);
19
- if (!target) {
20
- setRect(null);
21
- postToFrame({
22
- type: "target-measured",
23
- targetId: focus.id,
24
- anchor: null,
25
- });
26
- return;
27
- }
28
- if (!didScroll) {
29
- target.scrollIntoView({
30
- behavior: "smooth",
31
- block: "center",
32
- inline: "nearest",
33
- });
34
- didScroll = true;
35
- }
36
- const nextRect = target.getBoundingClientRect();
37
- setRect(nextRect);
38
- postToFrame({
39
- type: "target-measured",
40
- targetId: focus.id,
41
- anchor: {
42
- x: nextRect.left,
43
- y: nextRect.top,
44
- width: nextRect.width,
45
- height: nextRect.height,
46
- },
47
- });
48
- };
49
- update();
50
- const retry = window.setInterval(update, 50);
51
- const stopRetry = window.setTimeout(() => window.clearInterval(retry), 400);
52
- window.addEventListener("scroll", update, true);
53
- window.addEventListener("resize", update);
54
- // Dismiss before the prototype handles the interaction. A pointer-down can
55
- // replace the focused target before a click is dispatched, which removes
56
- // the visual highlight without giving the Frame a chance to clear its
57
- // associated selection.
58
- document.addEventListener("pointerdown", onDismiss, true);
59
- return () => {
60
- window.clearInterval(retry);
61
- window.clearTimeout(stopRetry);
62
- window.removeEventListener("scroll", update, true);
63
- window.removeEventListener("resize", update);
64
- document.removeEventListener("pointerdown", onDismiss, true);
65
- };
66
- }, [focus, onDismiss]);
67
- if (!rect)
68
- return null;
69
- return (_jsx("div", { "aria-hidden": "true", "data-proto-target-highlight": true, style: {
70
- position: "fixed",
71
- zIndex: 2147483647,
72
- pointerEvents: "none",
73
- top: rect.top,
74
- left: rect.left,
75
- width: rect.width,
76
- height: rect.height,
77
- border: `2px solid color-mix(in srgb, ${PROTO_BLUE} 55%, transparent)`,
78
- borderRadius: 9,
79
- background: `color-mix(in srgb, ${PROTO_BLUE} 6%, transparent)`,
80
- opacity: 1,
81
- } }));
82
- }
83
11
  export function ProtoRig({ manifest, children, }) {
84
12
  // One store per mount; survives re-renders, resets on full reload (correct:
85
13
  // a reload re-hydrates from the URL, which is the source of truth).
@@ -87,31 +15,8 @@ export function ProtoRig({ manifest, children, }) {
87
15
  if (storeRef.current === null)
88
16
  storeRef.current = new RigStore(manifest);
89
17
  const store = storeRef.current;
90
- const [targetFocus, setTargetFocus] = useState(null);
91
- useEffect(() => {
92
- const onMessage = (e) => {
93
- if (!isFrameToRig(e.data) || e.data.type !== "focus-target")
94
- return;
95
- if (e.data.id === null) {
96
- setTargetFocus(null);
97
- return;
98
- }
99
- setTargetFocus((current) => ({
100
- id: e.data.id,
101
- token: (current?.token ?? 0) + 1,
102
- }));
103
- };
104
- window.addEventListener("message", onMessage);
105
- const dispose = wireRig(store, manifest);
106
- return () => {
107
- window.removeEventListener("message", onMessage);
108
- dispose();
109
- };
110
- }, [store, manifest]);
111
- return (_jsxs(RigContext.Provider, { value: store, children: [children, targetFocus ? (_jsx(TargetHighlight, { focus: targetFocus, onDismiss: () => {
112
- setTargetFocus((current) => current?.token === targetFocus.token ? null : current);
113
- postToFrame({ type: "target-focus-dismissed" });
114
- } })) : null] }));
18
+ useEffect(() => wireRig(store, manifest), [store, manifest]);
19
+ return _jsx(RigContext.Provider, { value: store, children: children });
115
20
  }
116
21
  function useRigValue(key, fallback, valid) {
117
22
  const store = useContext(RigContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proto-labs-inc/rig",
3
- "version": "0.1.0",
3
+ "version": "0.2.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.1.0",
27
- "@proto-labs-inc/rig-core": "^0.1.0"
26
+ "@proto-labs-inc/rig-core": "^0.2.0",
27
+ "@proto-labs-inc/wire": "^0.2.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "~6.0.2",