Skip to content

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

feat(chat): add visual Markdown workshop

Danila Poyarkovb7879ac0266f
diff --git a/src/components/chat/ChatMarkdown.stories.ts b/src/components/chat/ChatMarkdown.stories.ts
new file mode 100644
index 000000000..3416b9fd4
--- /dev/null
+++ b/src/components/chat/ChatMarkdown.stories.ts
@@ -0,0 +1,82 @@
+import type { Meta, StoryObj } from '@storybook/vue3-vite'
+
+import ChatMarkdown from './ChatMarkdown.vue'
+
+type ChatMarkdownStoryArgs = {
+ content: string
+ mode?: 'static' | 'streaming'
+}
+
+type Story = StoryObj<ChatMarkdownStoryArgs>
+
+const meta = {
+ title: 'Chat/Markdown',
+ component: ChatMarkdown,
+ parameters: { layout: 'centered' },
+ render: (args) => ({
+ components: { ChatMarkdown },
+ setup: () => ({ args }),
+ template:
+ '<div class="w-80 rounded-xl bg-hover px-3 py-2 text-surface"><ChatMarkdown v-bind="args" /></div>'
+ })
+} satisfies Meta<ChatMarkdownStoryArgs>
+
+export default meta
+
+export const Prose: Story = {
+ args: {
+ content: `# Compact heading
+
+A paragraph with **bold text**, *emphasis*, and [a link](https://openpencil.dev).
+
+## Smaller heading
+
+- First item
+- Second item
+
+---
+
+Closing paragraph.`
+ }
+}
+
+export const InlineCode: Story = {
+ args: {
+ content:
+ 'Rename cells using `Cell_R{row}C{col}`. Rows run from `Row_1` through `Row_4`; for example, use `Cell_R2C3`.'
+ }
+}
+
+export const CodeBlock: Story = {
+ args: {
+ content: `\`\`\`typescript
+const button = {
+ label: 'Subscribe',
+ rounded: 8,
+}
+\`\`\``
+ }
+}
+
+export const MixedContent: Story = {
+ args: {
+ content: `## Updated layout
+
+The grid uses \`Cell_R{row}C{col}\` names.
+
+\`\`\`typescript
+const columns = 4
+const rows = 4
+\`\`\`
+
+> Names remain stable when cells move.`
+ }
+}
+
+export const Streaming: Story = {
+ args: {
+ mode: 'streaming',
+ content:
+ 'The assistant is writing **streamed content** with `inline_code` and an unfinished [link'
+ }
+}
diff --git a/src/components/chat/ChatMarkdown.vue b/src/components/chat/ChatMarkdown.vue
index 1b4214e47..73fffbf18 100644
--- a/src/components/chat/ChatMarkdown.vue
+++ b/src/components/chat/ChatMarkdown.vue
@@ -7,6 +7,7 @@ import { IS_BROWSER } from '@open-pencil/core/constants'
import { createMarkdownHardenOptions, markdownExtensions } from '@/app/shell/markdown/config'
import { markdownRenderKey, type MarkdownSurface } from '@/app/shell/markdown/state'
import { resolvedAppTheme } from '@/app/shell/theme'
+import InlineCode from '@/components/chat/markdown/InlineCode.vue'
import { chatMarkdownTheme } from '@/theme/chat/markdown'
const {
@@ -21,6 +22,7 @@ const {
const isDark = computed(() => resolvedAppTheme.value === 'dark')
const ui = chatMarkdownTheme()
+const markdownComponents = { code: InlineCode }
const hardenOptions = computed(() =>
createMarkdownHardenOptions(IS_BROWSER ? window.location.origin : 'http://localhost/')
)
@@ -31,6 +33,7 @@ const renderKey = computed(() => markdownRenderKey({ mode, surface }))
<div data-slot="chat-markdown" :class="ui.root()">
<Markdown
:key="renderKey"
+ :components="markdownComponents"
:content="content"
:is-dark="isDark"
:mode="mode"
diff --git a/src/components/chat/ChatMessage.stories.ts b/src/components/chat/ChatMessage.stories.ts
new file mode 100644
index 000000000..2b5a4f6e9
--- /dev/null
+++ b/src/components/chat/ChatMessage.stories.ts
@@ -0,0 +1,55 @@
+import type { Meta, StoryObj } from '@storybook/vue3-vite'
+import type { UIMessage } from 'ai'
+
+import ChatMessage from './ChatMessage.vue'
+
+const userMessage: UIMessage = {
+ id: 'user-message',
+ role: 'user',
+ parts: [{ type: 'text', text: 'Rename these cells using the selected layer.' }]
+}
+
+const assistantMessage: UIMessage = {
+ id: 'assistant-message',
+ role: 'assistant',
+ parts: [
+ {
+ type: 'text',
+ text: 'Done. Names now follow `Cell_R{row}C{col}`, from `Row_1` through `Row_4`.'
+ }
+ ]
+}
+
+const reasoningMessage: UIMessage = {
+ id: 'reasoning-message',
+ role: 'assistant',
+ parts: [
+ { type: 'reasoning', text: 'Inspecting the selected hierarchy.', state: 'done' },
+ { type: 'text', text: 'The hierarchy is consistent.' }
+ ]
+}
+
+type ChatMessageStoryArgs = {
+ message: UIMessage
+ streaming?: boolean
+}
+
+const meta = {
+ title: 'Chat/Message',
+ component: ChatMessage,
+ parameters: { layout: 'centered' },
+ render: (args) => ({
+ components: { ChatMessage },
+ setup: () => ({ args }),
+ template:
+ '<div class="w-96 rounded-xl bg-panel p-4 text-surface"><ChatMessage v-bind="args" /></div>'
+ })
+} satisfies Meta<ChatMessageStoryArgs>
+
+export default meta
+type Story = StoryObj<ChatMessageStoryArgs>
+
+export const User: Story = { args: { message: userMessage } }
+export const Assistant: Story = { args: { message: assistantMessage } }
+export const Reasoning: Story = { args: { message: reasoningMessage } }
+export const Streaming: Story = { args: { message: assistantMessage, streaming: true } }
diff --git a/src/components/chat/attachment/AttachmentList.stories.ts b/src/components/chat/attachment/AttachmentList.stories.ts
new file mode 100644
index 000000000..ec719eaf7
--- /dev/null
+++ b/src/components/chat/attachment/AttachmentList.stories.ts
@@ -0,0 +1,60 @@
+import type { Meta, StoryObj } from '@storybook/vue3-vite'
+
+import type { AttachmentPresentation } from '@/app/ai/attachment/presentation/types'
+
+import AttachmentList from './AttachmentList.vue'
+
+const pixel = new Blob(
+ [
+ Uint8Array.from(
+ atob(
+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEAQH/69cbGAAAAABJRU5ErkJggg=='
+ ),
+ (character) => character.charCodeAt(0)
+ )
+ ],
+ { type: 'image/png' }
+)
+
+const image: AttachmentPresentation = {
+ id: 'image',
+ messageId: 'message',
+ kind: 'image',
+ name: 'reference.png',
+ preview: pixel,
+ mediaType: 'image/png',
+ originalSize: { x: 1280, y: 720 }
+}
+
+const node: AttachmentPresentation = {
+ id: 'node',
+ messageId: 'message',
+ kind: 'node',
+ name: 'Checkout card',
+ preview: pixel,
+ nodeId: '12:34',
+ nodeType: 'FRAME',
+ originalSize: { x: 320, y: 240 }
+}
+
+type AttachmentListStoryArgs = {
+ attachments: AttachmentPresentation[]
+}
+
+const meta = {
+ title: 'Chat/Attachments',
+ component: AttachmentList,
+ parameters: { layout: 'centered' },
+ render: (args) => ({
+ components: { AttachmentList },
+ setup: () => ({ args }),
+ template: '<div class="w-96 rounded-xl bg-accent p-3"><AttachmentList v-bind="args" /></div>'
+ })
+} satisfies Meta<AttachmentListStoryArgs>
+
+export default meta
+type Story = StoryObj<AttachmentListStoryArgs>
+
+export const Image: Story = { args: { attachments: [image] } }
+export const Node: Story = { args: { attachments: [node] } }
+export const Mixed: Story = { args: { attachments: [node, image] } }
diff --git a/src/components/chat/markdown/InlineCode.vue b/src/components/chat/markdown/InlineCode.vue
new file mode 100644
index 000000000..e15ef90da
--- /dev/null
+++ b/src/components/chat/markdown/InlineCode.vue
@@ -0,0 +1,15 @@
+<script setup lang="ts">
+import type { MarkdownComponentProps } from 'vue-stream-markdown'
+
+const { node: _node } = defineProps<MarkdownComponentProps>()
+</script>
+
+<template>
+ <code
+ data-stream-markdown="inline-code"
+ class="rounded bg-muted px-1 py-px font-mono text-[11px] leading-4 break-words whitespace-normal"
+ dir="ltr"
+ >
+ <slot />
+ </code>
+</template>
diff --git a/src/theme/chat/markdown.css b/src/theme/chat/markdown.css
index 015daba44..22d8461e6 100644
--- a/src/theme/chat/markdown.css
+++ b/src/theme/chat/markdown.css
@@ -39,10 +39,6 @@
}
}
- [data-stream-markdown='code']:not(.shiki) {
- @apply px-1 py-px text-[11px] leading-4;
- }
-
[data-stream-markdown='code-block'] [data-stream-markdown='code'] {
@apply p-1.5 text-[11px] leading-4;
}