@dfosco/storyboard-react 3.8.0 → 3.8.2
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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dfosco/storyboard-react",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@dfosco/storyboard-core": "3.8.
|
|
6
|
+
"@dfosco/storyboard-core": "3.8.2",
|
|
7
7
|
"@dfosco/tiny-canvas": "^1.1.0",
|
|
8
8
|
"@neodrag/react": "^2.3.1",
|
|
9
9
|
"glob": "^11.0.0",
|
package/src/canvas/useCanvas.js
CHANGED
|
@@ -14,6 +14,17 @@ async function fetchCanvasFromServer(name) {
|
|
|
14
14
|
return null
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function isAbsoluteUrl(value) {
|
|
18
|
+
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(value)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resolveCanvasModuleImport(modulePath, baseUrl = import.meta.env?.BASE_URL || '/') {
|
|
22
|
+
if (!modulePath || isAbsoluteUrl(modulePath)) return modulePath
|
|
23
|
+
if (!modulePath.startsWith('/')) return modulePath
|
|
24
|
+
const base = String(baseUrl || '/').replace(/\/$/, '')
|
|
25
|
+
return `${base}${modulePath}` || modulePath
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
/**
|
|
18
29
|
* Hook to load canvas data by name.
|
|
19
30
|
* Uses build-time data for static config (routes, JSX path), but fetches
|
|
@@ -48,13 +59,20 @@ export function useCanvas(name) {
|
|
|
48
59
|
})
|
|
49
60
|
}, [name, buildTimeCanvas])
|
|
50
61
|
|
|
62
|
+
const jsxModule = canvas?._jsxModule
|
|
63
|
+
const jsxImport = canvas?._jsxImport
|
|
64
|
+
|
|
51
65
|
useEffect(() => {
|
|
52
|
-
if (!
|
|
66
|
+
if (!jsxModule) {
|
|
53
67
|
setJsxExports(null)
|
|
54
68
|
return
|
|
55
69
|
}
|
|
56
70
|
|
|
57
|
-
|
|
71
|
+
const loadPromise = jsxImport
|
|
72
|
+
? jsxImport()
|
|
73
|
+
: import(/* @vite-ignore */ resolveCanvasModuleImport(jsxModule))
|
|
74
|
+
|
|
75
|
+
loadPromise
|
|
58
76
|
.then((mod) => {
|
|
59
77
|
const exports = {}
|
|
60
78
|
for (const [key, value] of Object.entries(mod)) {
|
|
@@ -65,10 +83,10 @@ export function useCanvas(name) {
|
|
|
65
83
|
setJsxExports(exports)
|
|
66
84
|
})
|
|
67
85
|
.catch((err) => {
|
|
68
|
-
console.error(`[storyboard] Failed to load canvas JSX module: ${
|
|
86
|
+
console.error(`[storyboard] Failed to load canvas JSX module: ${jsxModule}`, err)
|
|
69
87
|
setJsxExports(null)
|
|
70
88
|
})
|
|
71
|
-
}, [
|
|
89
|
+
}, [jsxModule, jsxImport])
|
|
72
90
|
|
|
73
91
|
// In dev, react to file mutations from the data plugin without reloading
|
|
74
92
|
// the current page. This keeps canvas editing state and route stable.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { resolveCanvasModuleImport } from './useCanvas.js'
|
|
3
|
+
|
|
4
|
+
describe('resolveCanvasModuleImport', () => {
|
|
5
|
+
it('prefixes root-relative module paths with BASE_URL', () => {
|
|
6
|
+
expect(resolveCanvasModuleImport('/src/canvas/button-patterns.canvas.jsx', '/feature-branch/')).toBe(
|
|
7
|
+
'/feature-branch/src/canvas/button-patterns.canvas.jsx',
|
|
8
|
+
)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('keeps root-relative paths unchanged when BASE_URL is root', () => {
|
|
12
|
+
expect(resolveCanvasModuleImport('/src/canvas/button-patterns.canvas.jsx', '/')).toBe(
|
|
13
|
+
'/src/canvas/button-patterns.canvas.jsx',
|
|
14
|
+
)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('returns relative paths as-is', () => {
|
|
18
|
+
expect(resolveCanvasModuleImport('./local-module.js', '/feature-branch/')).toBe('./local-module.js')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('returns absolute URLs as-is', () => {
|
|
22
|
+
expect(resolveCanvasModuleImport('https://cdn.example.com/module.js', '/feature-branch/')).toBe(
|
|
23
|
+
'https://cdn.example.com/module.js',
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -73,7 +73,9 @@ export function useFlowData(path) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
if (sceneValue === undefined) {
|
|
76
|
-
|
|
76
|
+
if (data != null && Object.keys(data).length > 0) {
|
|
77
|
+
console.warn(`[useFlowData] Path "${path}" not found in flow data.`)
|
|
78
|
+
}
|
|
77
79
|
return {}
|
|
78
80
|
}
|
|
79
81
|
|
package/src/vite/data-plugin.js
CHANGED
|
@@ -444,7 +444,11 @@ function generateModule({ index, protoFolders, flowRoutes, canvasRoutes }, root)
|
|
|
444
444
|
}
|
|
445
445
|
parsed = resolveTemplateVars(parsed, templateVars)
|
|
446
446
|
|
|
447
|
-
|
|
447
|
+
if (suffix === 'canvas' && parsed._jsxModule) {
|
|
448
|
+
declarations.push(`const ${varName} = Object.assign(${JSON.stringify(parsed)}, { _jsxImport: () => import(${JSON.stringify(parsed._jsxModule)}) })`)
|
|
449
|
+
} else {
|
|
450
|
+
declarations.push(`const ${varName} = ${JSON.stringify(parsed)}`)
|
|
451
|
+
}
|
|
448
452
|
entries[suffix].push(` ${JSON.stringify(name)}: ${varName}`)
|
|
449
453
|
}
|
|
450
454
|
}
|