@dfosco/storyboard-react 3.8.0 → 3.8.1

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.0",
3
+ "version": "3.8.1",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "@dfosco/storyboard-core": "3.8.0",
6
+ "@dfosco/storyboard-core": "3.8.1",
7
7
  "@dfosco/tiny-canvas": "^1.1.0",
8
8
  "@neodrag/react": "^2.3.1",
9
9
  "glob": "^11.0.0",
@@ -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
@@ -54,7 +65,8 @@ export function useCanvas(name) {
54
65
  return
55
66
  }
56
67
 
57
- import(/* @vite-ignore */ canvas._jsxModule)
68
+ const moduleImportPath = resolveCanvasModuleImport(canvas._jsxModule)
69
+ import(/* @vite-ignore */ moduleImportPath)
58
70
  .then((mod) => {
59
71
  const exports = {}
60
72
  for (const [key, value] of Object.entries(mod)) {
@@ -65,7 +77,7 @@ export function useCanvas(name) {
65
77
  setJsxExports(exports)
66
78
  })
67
79
  .catch((err) => {
68
- console.error(`[storyboard] Failed to load canvas JSX module: ${canvas._jsxModule}`, err)
80
+ console.error(`[storyboard] Failed to load canvas JSX module: ${moduleImportPath}`, err)
69
81
  setJsxExports(null)
70
82
  })
71
83
  }, [canvas?._jsxModule])
@@ -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
+ })