@dfosco/storyboard 0.6.9 → 0.6.10
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/package.json
CHANGED
|
@@ -54,22 +54,24 @@ export default forwardRef(function PrototypeEmbed({ id: widgetId, props, onUpdat
|
|
|
54
54
|
|
|
55
55
|
const basePath = (import.meta.env.BASE_URL || '/').replace(/\/$/, '')
|
|
56
56
|
const baseSegment = basePath.replace(/^\//, '')
|
|
57
|
-
//
|
|
58
|
-
// -
|
|
59
|
-
// broken prototype's transform/HMR errors
|
|
60
|
-
//
|
|
61
|
-
// prototypes.html
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
// External http(s) URLs are left alone.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
// Two URLs are derived from `src`:
|
|
58
|
+
// - rawSrc — the iframe URL. In DEV this routes through the isolated
|
|
59
|
+
// prototypes.html entry so a broken prototype's transform/HMR errors
|
|
60
|
+
// stay inside the iframe (see .agents/plans/vite-isolation.md):
|
|
61
|
+
// /MyProto/SignupForm becomes prototypes.html?proto=MyProto#/MyProto/SignupForm.
|
|
62
|
+
// In PROD it loads the prototype path directly through the canvas SPA
|
|
63
|
+
// (prototypes.html is a build-time isolation artifact that must not
|
|
64
|
+
// leak into deployed URLs).
|
|
65
|
+
// - externalSrc — the URL used by "Open in new tab". Always direct
|
|
66
|
+
// (`${basePath}/<protoPath>`), never prototypes.html, even in dev —
|
|
67
|
+
// opening prototypes.html#/... in a fresh tab is a leaky surprise
|
|
68
|
+
// for users navigating from the canvas.
|
|
69
|
+
// External http(s) URLs are left alone in both cases. basePath already
|
|
70
|
+
// carries the /branch--xxx/ prefix on branch deploys, so both work for
|
|
71
|
+
// main and branch deploys alike.
|
|
72
|
+
const { rawSrc, externalSrc } = useMemo(() => {
|
|
73
|
+
if (!src) return { rawSrc: '', externalSrc: '' }
|
|
74
|
+
if (/^https?:\/\//.test(src)) return { rawSrc: src, externalSrc: src }
|
|
73
75
|
const cleaned = src.replace(/^\/branch--[^/]+/, '')
|
|
74
76
|
let normalized
|
|
75
77
|
if (baseSegment && cleaned.startsWith(basePath)) normalized = cleaned
|
|
@@ -77,7 +79,7 @@ export default forwardRef(function PrototypeEmbed({ id: widgetId, props, onUpdat
|
|
|
77
79
|
else normalized = `${basePath}${cleaned}`
|
|
78
80
|
// Strip basePath so we can split path/query/hash cleanly and
|
|
79
81
|
// re-anchor for whichever mode we're in. Any pre-existing #hash on
|
|
80
|
-
// the original src is preserved
|
|
82
|
+
// the original src is preserved.
|
|
81
83
|
const withoutBase = baseSegment && normalized.startsWith(basePath)
|
|
82
84
|
? normalized.slice(basePath.length) || '/'
|
|
83
85
|
: normalized
|
|
@@ -86,18 +88,20 @@ export default forwardRef(function PrototypeEmbed({ id: widgetId, props, onUpdat
|
|
|
86
88
|
const pathAndQuery = hashIdx >= 0 ? withoutBase.slice(0, hashIdx) : withoutBase
|
|
87
89
|
const routePath = pathAndQuery.startsWith('/') ? pathAndQuery : `/${pathAndQuery}`
|
|
88
90
|
const suffix = innerHash ? `#${innerHash}` : ''
|
|
91
|
+
// Direct path through the canvas SPA — used in prod for the iframe and
|
|
92
|
+
// always for "Open in new tab".
|
|
93
|
+
const directUrl = `${basePath}${routePath}${suffix}`
|
|
89
94
|
if (import.meta.env.PROD) {
|
|
90
|
-
|
|
91
|
-
// production URLs.
|
|
92
|
-
return `${basePath}${routePath}${suffix}`
|
|
95
|
+
return { rawSrc: directUrl, externalSrc: directUrl }
|
|
93
96
|
}
|
|
94
|
-
// Dev: prototypes.html with ?proto= narrowing. The consumer's
|
|
97
|
+
// Dev iframe: prototypes.html with ?proto= narrowing. The consumer's
|
|
95
98
|
// prototypes-entry.jsx reads ?proto= and calls getRoutesForProto();
|
|
96
99
|
// older scaffolds harmlessly ignore the param and load the full tree.
|
|
97
100
|
const pathOnly = pathAndQuery.split('?')[0]
|
|
98
101
|
const protoName = pathOnly.split('/').filter(Boolean)[0] || ''
|
|
99
102
|
const queryStr = protoName ? `?proto=${encodeURIComponent(protoName)}` : ''
|
|
100
|
-
|
|
103
|
+
const iframeUrl = `${basePath}/prototypes.html${queryStr}#${routePath}${suffix}`
|
|
104
|
+
return { rawSrc: iframeUrl, externalSrc: directUrl }
|
|
101
105
|
}, [src, basePath, baseSegment])
|
|
102
106
|
|
|
103
107
|
const scale = zoom / 100
|
|
@@ -332,7 +336,7 @@ export default forwardRef(function PrototypeEmbed({ id: widgetId, props, onUpdat
|
|
|
332
336
|
} else if (actionId === 'split-screen') {
|
|
333
337
|
setExpandMode('split')
|
|
334
338
|
} else if (actionId === 'open-external') {
|
|
335
|
-
if (
|
|
339
|
+
if (externalSrc) window.open(externalSrc, '_blank', 'noopener')
|
|
336
340
|
} else if (actionId === 'refresh-frame') {
|
|
337
341
|
const iframe = iframeRef.current
|
|
338
342
|
if (iframe) {
|
|
@@ -347,7 +351,7 @@ export default forwardRef(function PrototypeEmbed({ id: widgetId, props, onUpdat
|
|
|
347
351
|
onUpdate?.({ zoom: Math.max(25, zoom - step) })
|
|
348
352
|
}
|
|
349
353
|
},
|
|
350
|
-
}), [
|
|
354
|
+
}), [externalSrc, zoom, onUpdate])
|
|
351
355
|
|
|
352
356
|
function handlePickRoute(route) {
|
|
353
357
|
onUpdate?.({ src: route })
|