@dfosco/storyboard-react 4.0.0-beta.36 → 4.0.0-beta.37

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.
@@ -1663,6 +1663,20 @@ export default function CanvasPage({ canvasId: canvasIdProp, name, siblingPages
1663
1663
  return () => document.removeEventListener('wheel', handleWheel)
1664
1664
  }, [])
1665
1665
 
1666
+ // Receive cmd+wheel events forwarded from prototype/story iframes
1667
+ useEffect(() => {
1668
+ function handleMessage(e) {
1669
+ if (e.data?.type !== 'storyboard:embed:wheel') return
1670
+ zoomAccum.current += -e.data.deltaY
1671
+ const step = Math.trunc(zoomAccum.current)
1672
+ if (step === 0) return
1673
+ zoomAccum.current -= step
1674
+ applyZoom(zoomRef.current + step)
1675
+ }
1676
+ window.addEventListener('message', handleMessage)
1677
+ return () => window.removeEventListener('message', handleMessage)
1678
+ }, [])
1679
+
1666
1680
  // Touch pinch-to-zoom for mobile — two-finger pinch zooms the canvas
1667
1681
  const pinchState = useRef({ active: false, startDist: 0, startZoom: 0, centerX: 0, centerY: 0 })
1668
1682
  useEffect(() => {
@@ -228,6 +228,38 @@ export default function LinkPreview({ id, props, onUpdate, resizable }) {
228
228
  )
229
229
  }
230
230
 
231
+ const ogImage = props?.ogImage || null
232
+ const description = props?.description || ''
233
+ const canEdit = typeof onUpdate === 'function'
234
+ const cardRef = useRef(null)
235
+ const inputRef = useRef(null)
236
+ const [editing, setEditing] = useState(false)
237
+ const [editValue, setEditValue] = useState(title)
238
+
239
+ // Sync editValue when title prop changes externally
240
+ useEffect(() => { setEditValue(title) }, [title])
241
+
242
+ const startEditing = useCallback(() => {
243
+ if (!canEdit) return
244
+ setEditValue(title)
245
+ setEditing(true)
246
+ }, [canEdit, title])
247
+
248
+ const commitEdit = useCallback(() => {
249
+ setEditing(false)
250
+ const trimmed = editValue.trim()
251
+ if (trimmed !== title) {
252
+ onUpdate?.({ title: trimmed })
253
+ }
254
+ }, [editValue, title, onUpdate])
255
+
256
+ useEffect(() => {
257
+ if (editing && inputRef.current) {
258
+ inputRef.current.focus()
259
+ inputRef.current.select()
260
+ }
261
+ }, [editing])
262
+
231
263
  const sizeStyle = (width || height)
232
264
  ? { ...(width ? { width: `${width}px` } : {}), ...(height ? { minHeight: `${height}px` } : {}) }
233
265
  : undefined
@@ -238,14 +270,46 @@ export default function LinkPreview({ id, props, onUpdate, resizable }) {
238
270
  const handleResize = (w, h) => onUpdate?.({ width: w, height: h })
239
271
 
240
272
  return (
241
- <WidgetWrapper>
242
- <div className={styles.card} style={sizeStyle}>
243
- <div className={styles.header}>
244
- <span className={styles.icon}>🔗</span>
245
- <div className={styles.text}>
246
- {title && <p className={styles.title}>{title}</p>}
247
- </div>
248
- </div>
273
+ <div ref={cardRef} className={styles.card} style={sizeStyle}>
274
+ {ogImage && (
275
+ <img
276
+ className={styles.ogImage}
277
+ src={ogImage}
278
+ alt=""
279
+ loading="lazy"
280
+ onError={(e) => { e.target.style.display = 'none' }}
281
+ />
282
+ )}
283
+ <div className={styles.body}>
284
+ {editing ? (
285
+ <input
286
+ ref={inputRef}
287
+ className={styles.titleInput}
288
+ data-canvas-allow-text-selection
289
+ type="text"
290
+ value={editValue}
291
+ onChange={(e) => setEditValue(e.target.value)}
292
+ onBlur={commitEdit}
293
+ onKeyDown={(e) => {
294
+ if (e.key === 'Enter') commitEdit()
295
+ if (e.key === 'Escape') setEditing(false)
296
+ }}
297
+ onMouseDown={(e) => e.stopPropagation()}
298
+ onPointerDown={(e) => e.stopPropagation()}
299
+ />
300
+ ) : (
301
+ <p
302
+ className={styles.title}
303
+ data-canvas-allow-text-selection={!canEdit ? '' : undefined}
304
+ onDoubleClick={startEditing}
305
+ role={canEdit ? 'button' : undefined}
306
+ tabIndex={canEdit ? 0 : undefined}
307
+ onKeyDown={canEdit ? (e) => { if (e.key === 'Enter') startEditing() } : undefined}
308
+ >
309
+ {title || hostname || url || 'Untitled'}
310
+ </p>
311
+ )}
312
+ {description && <p className={styles.description}>{description}</p>}
249
313
  <a
250
314
  href={url || '#'}
251
315
  target="_blank"
@@ -257,7 +321,7 @@ export default function LinkPreview({ id, props, onUpdate, resizable }) {
257
321
  {hostname || url}
258
322
  </a>
259
323
  </div>
260
- {resizable && <ResizeHandle width={width} height={height} onResize={handleResize} />}
261
- </WidgetWrapper>
324
+ {resizable && <ResizeHandle targetRef={cardRef} width={width} height={height} onResize={handleResize} />}
325
+ </div>
262
326
  )
263
327
  }
@@ -87,7 +87,7 @@
87
87
  border-radius: 4px;
88
88
  font-size: 12px;
89
89
  font-weight: 400;
90
- font-family: "Ioskeley Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
90
+ font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
91
91
  }
92
92
 
93
93
  .preview ul {
@@ -169,7 +169,7 @@
169
169
  padding: 0;
170
170
  font-size: 12px;
171
171
  font-weight: 400;
172
- font-family: "Ioskeley Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
172
+ font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
173
173
  white-space: pre;
174
174
  word-break: normal;
175
175
  overflow-wrap: normal;
@@ -403,7 +403,7 @@ export default forwardRef(function PrototypeEmbed({ id: widgetId, props, onUpdat
403
403
  </div>
404
404
  )}
405
405
  </div>
406
- {resizable && <ResizeHandle width={width} height={height} onResize={handleResize} />}
406
+ {resizable && <ResizeHandle targetRef={embedRef} width={width} height={height} onResize={handleResize} />}
407
407
  </WidgetWrapper>
408
408
  {createPortal(
409
409
  <div
@@ -270,7 +270,7 @@ export default forwardRef(function StoryWidget({ id: widgetId, props, onUpdate,
270
270
  </>
271
271
  )}
272
272
  </div>
273
- {resizable && <ResizeHandle width={width} height={height} onResize={handleResize} />}
273
+ {resizable && <ResizeHandle targetRef={containerRef} width={width} height={height} onResize={handleResize} />}
274
274
  </WidgetWrapper>
275
275
  )
276
276
  })
@@ -118,7 +118,7 @@
118
118
  }
119
119
 
120
120
  .codeLabel {
121
- font-family: "Ioskeley Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
121
+ font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
122
122
  }
123
123
 
124
124
  .codeCloseBtn {
@@ -152,7 +152,7 @@
152
152
  .codeBlock pre {
153
153
  margin: 0;
154
154
  padding: var(--base-size-8, 8px) !important;
155
- font-family: "Ioskeley Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
155
+ font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
156
156
  font-size: 12px;
157
157
  font-weight: 400;
158
158
  line-height: 1.6;
@@ -163,7 +163,7 @@
163
163
 
164
164
  /* Fallback when no highlighted HTML (plain pre/code) */
165
165
  .codeBlock > code {
166
- font-family: "Ioskeley Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
166
+ font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
167
167
  font-size: 12px;
168
168
  font-weight: 400;
169
169
  line-height: 1.6;
package/src/index.js CHANGED
@@ -35,7 +35,7 @@ export { FormContext } from './context/FormContext.js'
35
35
  // ModeSwitch and ToolbarShell UI moved to @dfosco/storyboard-svelte-ui
36
36
 
37
37
  // Viewfinder dashboard
38
- export { default as Viewfinder } from './Viewfinder.jsx'
38
+ export { default as Viewfinder } from './ViewfinderNew.jsx'
39
39
 
40
40
  // Canvas
41
41
  export { default as CanvasPage } from './canvas/CanvasPage.jsx'
@@ -1128,6 +1128,30 @@ export default function storyboardDataPlugin() {
1128
1128
  return []
1129
1129
  },
1130
1130
 
1131
+ // Inject __SB_BRANCHES__ into HTML so the Viewfinder branch selector works.
1132
+ // Reads .worktrees/ports.json to enumerate active worktree dev servers.
1133
+ transformIndexHtml(html, ctx) {
1134
+ // Only inject in dev mode
1135
+ if (!ctx.server) return html
1136
+
1137
+ try {
1138
+ const portsJsonPath = path.resolve(root, '.worktrees', 'ports.json')
1139
+ if (!fs.existsSync(portsJsonPath)) return html
1140
+
1141
+ const ports = JSON.parse(fs.readFileSync(portsJsonPath, 'utf-8'))
1142
+ const branches = Object.entries(ports)
1143
+ .filter(([name]) => name !== 'main')
1144
+ .map(([name, port]) => ({ branch: name, folder: `branch--${name}`, port }))
1145
+
1146
+ if (branches.length === 0) return html
1147
+
1148
+ const script = `<script>window.__SB_BRANCHES__ = ${JSON.stringify(branches)};</script>`
1149
+ return html.replace('</head>', `${script}\n</head>`)
1150
+ } catch {
1151
+ return html
1152
+ }
1153
+ },
1154
+
1131
1155
  // Rebuild index on each build start
1132
1156
  buildStart() {
1133
1157
  buildResult = null
@@ -1,72 +0,0 @@
1
-
2
- import { useRef, useEffect, useMemo } from 'react'
3
-
4
- /**
5
- * Viewfinder — thin React wrapper around the Svelte Viewfinder component.
6
- *
7
- * Mounts the core Svelte Viewfinder into a container div and manages
8
- * its lifecycle via React's useEffect.
9
- *
10
- * @param {Object} props
11
- * @param {Record<string, unknown>} [props.scenes] - Scene/flow index (deprecated, ignored — data comes from core)
12
- * @param {Record<string, unknown>} [props.flows] - Flow index (deprecated, ignored — data comes from core)
13
- * @param {Record<string, unknown>} [props.pageModules] - import.meta.glob result for page files
14
- * @param {string} [props.basePath] - Base URL path
15
- * @param {string} [props.title] - Header title
16
- * @param {string} [props.subtitle] - Optional subtitle
17
- * @param {boolean} [props.showThumbnails] - Show thumbnail previews
18
- * @param {boolean} [props.hideDefaultFlow] - Hide the "default" flow from the "Other flows" section
19
- */
20
- export default function Viewfinder({ pageModules = {}, basePath, title = 'Storyboard', subtitle, showThumbnails = false, hideDefaultFlow, hideDefaultScene = false }) {
21
- const containerRef = useRef(null)
22
- const handleRef = useRef(null)
23
-
24
- const shouldHideDefault = hideDefaultFlow ?? hideDefaultScene
25
-
26
- const knownRoutes = useMemo(() => Object.keys(pageModules)
27
- .map(p => p.replace('/src/prototypes/', '').replace('.jsx', ''))
28
- .filter(n => !n.startsWith('_') && n !== 'index' && n !== 'viewfinder'),
29
- [pageModules])
30
-
31
- useEffect(() => {
32
- if (!containerRef.current) return
33
-
34
- let cancelled = false
35
-
36
- import('@dfosco/storyboard-core/ui-runtime').then(({ mountViewfinder, unmountViewfinder }) => {
37
- if (cancelled) return
38
- // Ensure clean state for re-mounts
39
- unmountViewfinder()
40
- handleRef.current = mountViewfinder(containerRef.current, {
41
- title,
42
- subtitle,
43
- basePath,
44
- knownRoutes,
45
- showThumbnails,
46
- hideDefaultFlow: shouldHideDefault,
47
- })
48
- // Wait for styles to be fully loaded before revealing
49
- handleRef.current.ready.then(() => {
50
- requestAnimationFrame(() => {
51
- if (containerRef.current) containerRef.current.style.opacity = '1'
52
- })
53
- })
54
- })
55
-
56
- return () => {
57
- cancelled = true
58
- if (handleRef.current) {
59
- handleRef.current.destroy()
60
- handleRef.current = null
61
- }
62
- }
63
- }, [title, subtitle, basePath, knownRoutes, showThumbnails, shouldHideDefault])
64
-
65
- return <div ref={containerRef} style={{
66
- minHeight: '100vh',
67
- background: 'var(--bgColor-default, #0d1117)',
68
- opacity: 0,
69
- transition: 'opacity 0.15s ease',
70
- }} />
71
- }
72
-
@@ -1,235 +0,0 @@
1
- .container {
2
- min-height: 100vh;
3
- background-color: var(--bgColor-default, #0d1117);
4
- color: var(--fgColor-default, #e6edf3);
5
- padding: 80px 32px 48px;
6
- }
7
-
8
- .header {
9
- max-width: 720px;
10
- margin: 0 auto 64px;
11
- }
12
-
13
- .title {
14
- font-size: 72px;
15
- font-weight: 400;
16
- margin: 0 0 12px;
17
- color: var(--fgColor-default, #e6edf3);
18
- letter-spacing: -0.03em;
19
- line-height: 1;
20
- }
21
-
22
- .subtitle {
23
- font-size: 15px;
24
- color: var(--fgColor-muted, #848d97);
25
- margin: 4px 0 0;
26
- letter-spacing: 0.01em;
27
- }
28
-
29
- .sceneCount {
30
- font-size: 13px;
31
- color: var(--fgColor-muted, #848d97);
32
- margin: 16px 0 0;
33
- letter-spacing: 0.01em;
34
- }
35
-
36
- .grid {
37
- display: grid;
38
- grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
39
- gap: 16px;
40
- max-width: 720px;
41
- margin: 0 auto;
42
- }
43
-
44
- .list {
45
- display: flex;
46
- flex-direction: column;
47
- max-width: 720px;
48
- margin: 0 auto;
49
- }
50
-
51
- .listItem {
52
- display: block;
53
- padding: 8px 0;
54
- text-decoration: none;
55
- color: inherit;
56
- /* border-bottom: 1px solid var(--borderColor-muted, #21262d); */
57
- }
58
-
59
- .listItem:first-child {
60
- /* border-top: 1px solid var(--borderColor-muted, #21262d); */
61
- }
62
-
63
- .listItem:hover {
64
- text-decoration: none !important;
65
- }
66
-
67
- .listItem .author {
68
- margin-top: 8px;
69
- }
70
-
71
- .card {
72
- display: block;
73
- border: 1px solid var(--borderColor-default, #30363d);
74
- border-radius: 8px;
75
- overflow: hidden;
76
- background: var(--bgColor-muted, #161b22);
77
- text-decoration: none;
78
- color: inherit;
79
- transition: border-color 0.15s ease, box-shadow 0.15s ease;
80
- }
81
-
82
- .card:hover {
83
- border-color: var(--borderColor-accent-emphasis, #1f6feb);
84
- box-shadow: 0 0 0 1px var(--borderColor-accent-emphasis, #1f6feb);
85
- text-decoration: none !important;
86
- }
87
-
88
- .thumbnail {
89
- aspect-ratio: 16 / 10;
90
- display: flex;
91
- align-items: center;
92
- justify-content: center;
93
- overflow: hidden;
94
- background: var(--bgColor-inset, #010409);
95
-
96
- --placeholder-bg: var(--bgColor-inset, #010409);
97
- --placeholder-grid: var(--borderColor-default, #30363d);
98
- --placeholder-accent: var(--fgColor-accent, #58a6ff);
99
- --placeholder-fg: var(--fgColor-default, #c9d1d9);
100
- --placeholder-muted: var(--fgColor-muted, #484f58);
101
- }
102
-
103
- .thumbnail svg {
104
- width: 100%;
105
- height: 100%;
106
- }
107
-
108
- .cardBody {
109
- padding: 12px 16px;
110
-
111
- &:hover {
112
- background-color: var(--bgColor-muted);
113
- }
114
- }
115
-
116
- .sceneName {
117
- font-size: 28px;
118
- font-weight: 400;
119
- color: var(--fgColor-default, #e6edf3);
120
- margin: 0;
121
- letter-spacing: -0.02em;
122
- line-height: 1.2;
123
- transition: font-style 0.15s ease;
124
- }
125
-
126
- .empty {
127
- text-align: center;
128
- padding: 80px 24px;
129
- color: var(--fgColor-muted, #848d97);
130
- font-size: 15px;
131
- max-width: 720px;
132
- margin: 0 auto;
133
- }
134
-
135
- .sectionTitle {
136
- font-size: 11px;
137
- font-weight: 700;
138
- text-transform: uppercase;
139
- letter-spacing: 0.12em;
140
- color: var(--fgColor-muted, #848d97);
141
- margin: 0 auto 20px;
142
- max-width: 720px;
143
- }
144
-
145
- .headerTop {
146
- display: flex;
147
- align-items: baseline;
148
- justify-content: space-between;
149
- gap: 16px;
150
- }
151
-
152
- .branchDropdown {
153
- display: flex;
154
- align-items: center;
155
- gap: 0;
156
- flex-shrink: 0;
157
- position: relative;
158
- }
159
-
160
- .branchIcon {
161
- position: absolute;
162
- left: 10px;
163
- color: var(--fgColor-muted, #848d97);
164
- pointer-events: none;
165
- z-index: 1;
166
- }
167
-
168
- .branchSelect {
169
- appearance: none;
170
- background-color: transparent;
171
- color: var(--fgColor-default, #e6edf3);
172
- border: 1px solid var(--borderColor-default, #30363d);
173
- border-radius: 20px;
174
- padding: 6px 32px 6px 32px;
175
- font-size: 13px;
176
- font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
177
- cursor: pointer;
178
- background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23848d97'%3E%3Cpath d='M6 8.5L1.5 4h9L6 8.5z'/%3E%3C/svg%3E");
179
- background-repeat: no-repeat;
180
- background-position: right 12px center;
181
- min-width: 140px;
182
- max-width: 220px;
183
- text-overflow: ellipsis;
184
- overflow: hidden;
185
- transition: border-color 0.15s ease;
186
- }
187
-
188
- .branchSelect:hover {
189
- border-color: var(--fgColor-muted, #848d97);
190
- }
191
-
192
- .branchSelect:focus-visible {
193
- outline: 2px solid var(--borderColor-accent-emphasis, #1f6feb);
194
- outline-offset: -1px;
195
- }
196
-
197
- .author {
198
- display: flex;
199
- align-items: center;
200
- gap: 8px;
201
- margin-top: 6px;
202
- }
203
-
204
- .authorAvatars {
205
- display: flex;
206
- flex-direction: row;
207
- }
208
-
209
- .authorAvatars:hover .authorAvatar {
210
- margin-left: 2px;
211
- }
212
-
213
- .authorAvatars:hover .authorAvatar:first-child {
214
- margin-left: 0;
215
- }
216
-
217
- .authorAvatar {
218
- width: 18px;
219
- height: 18px;
220
- border-radius: 50%;
221
- margin-left: -6px;
222
- transition: margin-left 0.15s ease;
223
- outline: 2px solid var(--bgColor-default, #0d1117);
224
- position: relative;
225
- }
226
-
227
- .authorAvatar:first-child {
228
- margin-left: 0;
229
- }
230
-
231
- .authorName {
232
- font-size: 13px;
233
- color: var(--fgColor-muted, #848d97);
234
- letter-spacing: 0.01em;
235
- }