Skip to content

AI-native design editor. Open-source Figma alternative.

fix: show previews of recent and stored files on Home again (#1660)

Valery Komarov18dca2f43cf5
diff --git a/changes/1660/fixed.md b/changes/1660/fixed.md
new file mode 100644
index 000000000..e495efa4d
--- /dev/null
+++ b/changes/1660/fixed.md
@@ -0,0 +1 @@
+- Home shows previews of recent and stored files again instead of a placeholder icon.
diff --git a/src/components/home/document/DocumentEntry.stories.ts b/src/components/home/document/DocumentEntry.stories.ts
index eded2b41a..a174567c7 100644
--- a/src/components/home/document/DocumentEntry.stories.ts
+++ b/src/components/home/document/DocumentEntry.stories.ts
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from '@storybook/vue3-vite'
+import { ref, type Directive } from 'vue'
import DocumentEntry from './DocumentEntry.vue'
@@ -17,6 +18,7 @@ const meta = {
metadata: string
view: 'grid' | 'list'
disabled?: boolean
+ previewURL?: string
menu?: { actions: string; delete: string }
}>
@@ -31,3 +33,24 @@ export const Disabled: Story = { args: { disabled: true } }
const menu = { actions: 'Actions for Design system', delete: 'Delete' }
export const WithMenu: Story = { args: { menu } }
export const ListWithMenu: Story = { args: { view: 'list', menu } }
+
+/** A 16×9 indigo PNG, so a story shows a preview without a server. */
+const PREVIEW_URL =
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAJCAIAAAC0SDtlAAAAFElEQVR4nGNITvtIEmIY1TAoNAAA5CT4oTrOkfMAAAAASUVORK5CYII='
+
+/** A parent's directive reaches the entry's element, as Home's preview directives must. */
+const markLoaded: Directive<HTMLElement> = {
+ mounted(element) {
+ element.dataset.previewRequested = 'true'
+ }
+}
+export const WithMenuAndDirective: Story = {
+ args: { menu, previewURL: PREVIEW_URL },
+ render: (args) => ({
+ components: { DocumentEntry },
+ directives: { markLoaded },
+ setup: () => ({ args, deleted: ref(false) }),
+ template:
+ '<div class="max-w-sm bg-panel p-4 text-surface" :data-deleted="deleted"><DocumentEntry v-mark-loaded v-bind="args" @delete="deleted = true" /></div>'
+ })
+}
diff --git a/src/components/home/document/DocumentEntry.vue b/src/components/home/document/DocumentEntry.vue
index 945a8716d..d0a3bd928 100644
--- a/src/components/home/document/DocumentEntry.vue
+++ b/src/components/home/document/DocumentEntry.vue
@@ -46,9 +46,13 @@ const menuUI = useMenuUI({ content: 'min-w-40', item: 'justify-start gap-2 text-
</script>
<template>
- <ContextMenuRoot :disabled="!menu">
- <ContextMenuTrigger as-child>
- <div data-slot="document-entry" :class="styles.root({ class: normalizeClass(className) })">
+ <!--
+ The entry's own element is its root, so a parent's directives and attributes reach it, as the
+ preview directives of Home do; under the context menu they would land on a fragment.
+ -->
+ <div data-slot="document-entry" :class="styles.root({ class: normalizeClass(className) })">
+ <ContextMenuRoot :disabled="!menu">
+ <ContextMenuTrigger as="div" data-slot="surface" :class="styles.surface()">
<button
type="button"
:disabled="disabled"
@@ -98,17 +102,17 @@ const menuUI = useMenuUI({ content: 'min-w-40', item: 'justify-start gap-2 text-
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
- </div>
- </ContextMenuTrigger>
- <ContextMenuPortal v-if="menu">
- <ContextMenuContent :class="menuUI.content">
- <MenuScrollArea>
- <ContextMenuItem :class="menuUI.item" @select="emit('delete')">
- <icon-lucide-trash-2 :class="menuUI.icon" />
- {{ menu.delete }}
- </ContextMenuItem>
- </MenuScrollArea>
- </ContextMenuContent>
- </ContextMenuPortal>
- </ContextMenuRoot>
+ </ContextMenuTrigger>
+ <ContextMenuPortal v-if="menu">
+ <ContextMenuContent :class="menuUI.content">
+ <MenuScrollArea>
+ <ContextMenuItem :class="menuUI.item" @select="emit('delete')">
+ <icon-lucide-trash-2 :class="menuUI.icon" />
+ {{ menu.delete }}
+ </ContextMenuItem>
+ </MenuScrollArea>
+ </ContextMenuContent>
+ </ContextMenuPortal>
+ </ContextMenuRoot>
+ </div>
</template>
diff --git a/src/theme/home/document-entry.ts b/src/theme/home/document-entry.ts
index 0068a7654..ec10d54a3 100644
--- a/src/theme/home/document-entry.ts
+++ b/src/theme/home/document-entry.ts
@@ -1,6 +1,8 @@
export default {
slots: {
root: 'group relative min-w-0',
+ // The context menu's trigger: it fills the root, so a right-click anywhere on the entry opens it.
+ surface: '',
trigger:
'min-w-0 w-full text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-50',
preview:
@@ -27,7 +29,7 @@ export default {
menuTrigger: 'absolute top-2 right-2 bg-panel/90 shadow-sm'
},
list: {
- root: 'flex items-center border-b border-border last:border-b-0 hover:bg-hover',
+ surface: 'flex items-center border-b border-border group-last:border-b-0 hover:bg-hover',
trigger: 'flex min-h-14 items-center gap-3 px-3 py-2 sm:min-h-0 sm:px-4 sm:py-3',
metadata: 'sm:hidden',
menuTrigger: 'mr-2 sm:mr-3'
diff --git a/tests/e2e/storybook/document-entry.spec.ts b/tests/e2e/storybook/document-entry.spec.ts
new file mode 100644
index 000000000..618a55e98
--- /dev/null
+++ b/tests/e2e/storybook/document-entry.spec.ts
@@ -0,0 +1,27 @@
+import { expect, test } from '@playwright/test'
+
+test('a document entry with a menu takes its parent directives, shows its preview, and deletes from the context menu', async ({
+ page
+}) => {
+ await page.goto('/iframe.html?id=app-home-document-entry--with-menu-and-directive&viewMode=story')
+ const entry = page.locator('[data-slot="document-entry"]')
+ await expect(entry).toHaveAttribute('data-preview-requested', 'true')
+
+ const preview = entry.locator('[data-slot="preview"] img')
+ await expect(preview).toBeVisible()
+ await expect(preview).toHaveJSProperty('naturalWidth', 16)
+
+ await entry.locator('[data-slot="trigger"]').click({ button: 'right' })
+ await page.getByRole('menuitem', { name: 'Delete' }).click()
+ await expect(page.locator('[data-deleted="true"]')).toHaveCount(1)
+})
+
+test('a right-click anywhere on a list entry opens its context menu', async ({ page }) => {
+ await page.goto('/iframe.html?id=app-home-document-entry--list-with-menu&viewMode=story')
+ const entry = page.locator('[data-slot="document-entry"]')
+ const box = await entry.boundingBox()
+ if (!box) throw new Error('The entry has no box')
+ // The gap right of the ⋯ button belongs to no control, only to the row.
+ await entry.click({ button: 'right', position: { x: box.width - 2, y: box.height / 2 } })
+ await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeVisible()
+})