Skip to content

Commit d431f40

Browse files
zeroxaaclaude
andcommitted
fix: resolve thumbnail refs through ContentProvider for card previews
Cards now show thumbnail images in browse mode by resolving thumbnailRef through the ContentProvider. Previously refs like 'hero-photo' were passed directly as image URLs instead of being resolved to actual URLs. Added thumbnailRef to all HTML demo cards so they show placeholder images during browsing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 96cd8a0 commit d431f40

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

src/bootstrap.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,28 @@ demoContent.set('mdn-docs', {
508508
url: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe',
509509
})
510510

511-
// Thumbnails
511+
// Thumbnails for HTML cards (shown during browse mode)
512+
demoContent.set('thumb-landing', {
513+
type: 'image',
514+
src: 'https://picsum.photos/seed/landing/1040/1160',
515+
})
516+
demoContent.set('thumb-pricing', {
517+
type: 'image',
518+
src: 'https://picsum.photos/seed/pricing/1280/960',
519+
})
520+
demoContent.set('thumb-signup', {
521+
type: 'image',
522+
src: 'https://picsum.photos/seed/signup/800/1280',
523+
})
524+
demoContent.set('thumb-dashboard', {
525+
type: 'image',
526+
src: 'https://picsum.photos/seed/dashboard/1120/1040',
527+
})
528+
demoContent.set('thumb-mobile', {
529+
type: 'image',
530+
src: 'https://picsum.photos/seed/mobile/750/1400',
531+
})
532+
demoContent.set('thumb-chat', { type: 'image', src: 'https://picsum.photos/seed/chat/760/1080' })
512533
demoContent.set('thumb-wikipedia', {
513534
type: 'image',
514535
src: 'https://images.unsplash.com/photo-1481627834876-b7833e8f5570?w=960&h=800&fit=crop',
@@ -540,6 +561,7 @@ const DEMO_CARDS: CardRecord[] = [
540561
updatedAt: now,
541562
contentRef: 'landing-page',
542563
contentType: 'html',
564+
thumbnailRef: 'thumb-landing',
543565
capabilities: CAP_FULL,
544566
},
545567
{
@@ -558,6 +580,7 @@ const DEMO_CARDS: CardRecord[] = [
558580
updatedAt: now,
559581
contentRef: 'pricing-page',
560582
contentType: 'html',
583+
thumbnailRef: 'thumb-pricing',
561584
capabilities: CAP_FULL,
562585
},
563586
{
@@ -576,6 +599,7 @@ const DEMO_CARDS: CardRecord[] = [
576599
updatedAt: now,
577600
contentRef: 'signup-form',
578601
contentType: 'html',
602+
thumbnailRef: 'thumb-signup',
579603
capabilities: CAP_FULL,
580604
},
581605

@@ -596,6 +620,7 @@ const DEMO_CARDS: CardRecord[] = [
596620
updatedAt: now,
597621
contentRef: 'dashboard',
598622
contentType: 'html',
623+
thumbnailRef: 'thumb-dashboard',
599624
capabilities: CAP_FULL,
600625
},
601626
{
@@ -614,6 +639,7 @@ const DEMO_CARDS: CardRecord[] = [
614639
updatedAt: now,
615640
contentRef: 'mobile-app',
616641
contentType: 'html',
642+
thumbnailRef: 'thumb-mobile',
617643
capabilities: CAP_FULL,
618644
},
619645
{
@@ -632,6 +658,7 @@ const DEMO_CARDS: CardRecord[] = [
632658
updatedAt: now,
633659
contentRef: 'chat-ui',
634660
contentType: 'html',
661+
thumbnailRef: 'thumb-chat',
635662
capabilities: CAP_FULL,
636663
},
637664

src/konva/KonvaAdapter.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ export class KonvaAdapter {
118118
this.worldGroup.destroyChildren()
119119

120120
for (const card of cards.sort((a, b) => a.zIndex - b.zIndex)) {
121-
const plugin = this.editor.plugins.get(card.type)
122-
const descriptor = plugin.getRenderDescriptor(card)
123121
const frameRect = resolveCardRect(this.editor, card)
124122

125123
const group = new Konva.Group({
@@ -143,26 +141,20 @@ export class KonvaAdapter {
143141
}),
144142
)
145143

146-
// Resolve thumbnail: use thumbnailRef, or for image-type cards resolve contentRef
147-
let imageUrl = descriptor.src
148-
if (!imageUrl && card.thumbnailRef) {
144+
// Resolve an image URL for the card preview.
145+
// Try thumbnailRef first, then contentRef for image-type cards.
146+
// All refs go through the content provider to get actual URLs.
147+
let imageUrl: string | undefined
148+
const refToResolve =
149+
card.thumbnailRef ?? (card.contentType === 'image' ? card.contentRef : undefined)
150+
if (refToResolve) {
149151
try {
150-
const resolved = this.editor.content.resolve(card.thumbnailRef, 'image')
152+
const resolved = this.editor.content.resolve(refToResolve, 'image')
151153
if (!(resolved instanceof Promise) && resolved.type === 'image') {
152154
imageUrl = resolved.src
153155
}
154156
} catch {
155-
// no thumbnail available
156-
}
157-
}
158-
if (!imageUrl && card.contentRef && card.contentType === 'image') {
159-
try {
160-
const resolved = this.editor.content.resolve(card.contentRef, 'image')
161-
if (!(resolved instanceof Promise) && resolved.type === 'image') {
162-
imageUrl = resolved.src
163-
}
164-
} catch {
165-
// no content available
157+
// ref not resolvable — no preview
166158
}
167159
}
168160
if (imageUrl) {

0 commit comments

Comments
 (0)