@proto-labs-inc/rig-core 0.2.3 → 0.2.4
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/frame-tools-loader.js +41 -5
- package/dist/index.js +1 -1
- package/package.json +2 -2
|
@@ -3,12 +3,13 @@ export function loadFrameTools(frameOrigin) {
|
|
|
3
3
|
if (window.parent === window)
|
|
4
4
|
return () => { };
|
|
5
5
|
let disposed = false;
|
|
6
|
+
let closeRequest;
|
|
6
7
|
let unmount;
|
|
7
8
|
const report = (status, origin = "*") => {
|
|
8
9
|
if (!disposed)
|
|
9
10
|
window.parent.postMessage({ type: "frame-tools-status", status }, origin);
|
|
10
11
|
};
|
|
11
|
-
const dispose = () => { disposed = true; unmount?.(); };
|
|
12
|
+
const dispose = () => { disposed = true; closeRequest?.(); unmount?.(); };
|
|
12
13
|
if (!frameOrigin) {
|
|
13
14
|
report("unavailable");
|
|
14
15
|
return dispose;
|
|
@@ -31,12 +32,47 @@ export function loadFrameTools(frameOrigin) {
|
|
|
31
32
|
return dispose;
|
|
32
33
|
}
|
|
33
34
|
report("loading", origin);
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
// The Frame fetches its own public module. A published HTTPS prototype
|
|
36
|
+
// never needs to reach into a localhost or private-network Frame.
|
|
37
|
+
const channel = new MessageChannel();
|
|
38
|
+
const source = new Promise((resolve, reject) => {
|
|
39
|
+
const finish = () => {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
channel.port1.close();
|
|
42
|
+
closeRequest = undefined;
|
|
43
|
+
};
|
|
44
|
+
const timer = setTimeout(() => {
|
|
45
|
+
finish();
|
|
46
|
+
reject(new Error("Selection runtime request timed out"));
|
|
47
|
+
}, 15_000);
|
|
48
|
+
closeRequest = () => {
|
|
49
|
+
finish();
|
|
50
|
+
reject(new Error("Selection runtime request disposed"));
|
|
51
|
+
};
|
|
52
|
+
channel.port1.onmessage = (event) => {
|
|
53
|
+
finish();
|
|
54
|
+
const reply = event.data;
|
|
55
|
+
if (reply?.status === "ready" && typeof reply.source === "string")
|
|
56
|
+
resolve(reply.source);
|
|
57
|
+
else
|
|
58
|
+
reject(new Error("Selection runtime unavailable"));
|
|
59
|
+
};
|
|
60
|
+
window.parent.postMessage({ type: "request-frame-tools" }, origin, [channel.port2]);
|
|
61
|
+
});
|
|
62
|
+
void source.then(async (text) => {
|
|
36
63
|
if (disposed)
|
|
37
64
|
return;
|
|
38
|
-
|
|
39
|
-
|
|
65
|
+
const url = URL.createObjectURL(new Blob([text], { type: "text/javascript" }));
|
|
66
|
+
try {
|
|
67
|
+
const runtime = await import(/* webpackIgnore: true */ /* @vite-ignore */ url);
|
|
68
|
+
if (disposed)
|
|
69
|
+
return;
|
|
70
|
+
unmount = runtime.mountFrameTools({ frameOrigin: origin });
|
|
71
|
+
report("ready", origin);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
URL.revokeObjectURL(url);
|
|
75
|
+
}
|
|
40
76
|
}).catch((error) => {
|
|
41
77
|
if (disposed)
|
|
42
78
|
return;
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { PROTOCOL_VERSION, STATE_PARAM, variantParam, applyVariantSelection, isF
|
|
|
8
8
|
import { loadFrameTools } from "./frame-tools-loader.js";
|
|
9
9
|
import { observePageHistory } from "./page-history.js";
|
|
10
10
|
export { STATE_PARAM, variantParam } from "@proto-labs-inc/wire";
|
|
11
|
-
const RIG_VERSION = "0.2.
|
|
11
|
+
const RIG_VERSION = "0.2.4";
|
|
12
12
|
export const INTERNAL_PREVIEW_THEME_PARAM = "__protoTheme";
|
|
13
13
|
/** Mark the page light or dark (data-proto-theme and the "dark" class) for
|
|
14
14
|
* a prototype that styles both. The page's own CSS decides color-scheme:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proto-labs-inc/rig-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Proto's rig, framework-free: URL-state sync, the postMessage bridge to the Frame, and comment mode.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@proto-labs-inc/wire": "^0.2.
|
|
31
|
+
"@proto-labs-inc/wire": "^0.2.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"typescript": "~6.0.2",
|