dou-ui 0.1.0-alpha.10 → 0.1.0-alpha.11
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/dist/components/chat-message/chat-message.js.map +1 -1
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js +19 -3
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-message/chat-message2.js.map +1 -1
- package/dist/components/markdown/markdown.js.map +1 -1
- package/dist/components/markdown/markdown.vue_vue_type_script_setup_true_lang.js +12 -4
- package/dist/components/markdown/markdown.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/markdown/render.js +8 -3
- package/dist/components/markdown/render.js.map +1 -1
- package/dist/components/stream-text/stream-text.js.map +1 -1
- package/dist/components/stream-text/stream-text.vue_vue_type_script_setup_true_lang.js +15 -8
- package/dist/components/stream-text/stream-text.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/stream-text/stream-text2.js.map +1 -1
- package/dist/components/toast/toast-item.js.map +1 -1
- package/dist/components/toast/toast-item.vue_vue_type_script_setup_true_lang.js +44 -15
- package/dist/components/toast/toast-item.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/toast/toast-stack.js +6 -0
- package/dist/components/toast/toast-stack.js.map +1 -0
- package/dist/components/toast/toast-stack.vue_vue_type_script_setup_true_lang.js +147 -0
- package/dist/components/toast/toast-stack.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/toast/toast-viewport.js.map +1 -1
- package/dist/components/toast/toast-viewport.vue_vue_type_script_setup_true_lang.js +26 -19
- package/dist/components/toast/toast-viewport.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/chat-message/chat-message.d.ts +8 -1
- package/dist/types/components/markdown/markdown.d.ts +6 -0
- package/dist/types/components/markdown/render.d.ts +2 -0
- package/dist/types/components/stream-text/stream-text.d.ts +5 -0
- package/dist/types/components/toast/index.d.ts +1 -0
- package/dist/types/components/toast/toast-item.vue.d.ts +21 -1
- package/dist/types/components/toast/toast-stack.vue.d.ts +13 -0
- package/dist/types/components/toast/toast-viewport.vue.d.ts +1 -0
- package/dist/types/components/toast/toast.d.ts +6 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-message.js","names":[],"sources":["../../../src/components/chat-message/chat-message.ts"],"sourcesContent":["import type { ChatArtifactKind, ChatArtifactStatus } from '../chat-artifact/chat-artifact'\nimport type { ChatAttachment } from '../chat-attachments/chat-attachments'\nimport type {\n ChatConfirmDecision,\n ChatConfirmStatus,\n ChatConfirmTone,\n} from '../chat-confirm/chat-confirm'\nimport type { ChatPlanItem } from '../chat-plan/chat-plan'\nimport type { ChatQuestionOption, ChatQuestionStatus } from '../chat-question/chat-question'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport type { ChatStep } from '../chat-steps/chat-steps'\nimport type { ChatToolCallStatus } from '../chat-tool-call/chat-tool-call'\nimport type { MarkdownProps, MarkdownSlots } from '../markdown/markdown'\n\n/** Options for the Markdown of text and reasoning parts. */\nexport type ChatMessageMarkdown = Pick<\n MarkdownProps,\n 'smooth' | 'speed' | 'caret' | 'linkTarget' | 'sanitizeUrl'\n>\n\n/** Who wrote the message. */\nexport type ChatMessageSender = 'user' | 'assistant' | 'system'\n\n/** When the actions under a message show. */\nexport type ChatMessageActionsVisible = 'always' | 'hover'\n\nexport interface ChatTextPart {\n type: 'text'\n text: string\n /** More text is still coming. */\n streaming?: boolean\n}\nexport interface ChatReasoningPart {\n type: 'reasoning'\n text: string\n thinking?: boolean\n /** Seconds it took. */\n duration?: number\n}\nexport interface ChatToolPart {\n type: 'tool'\n name?: string\n title?: string\n status?: ChatToolCallStatus\n input?: unknown\n output?: unknown\n live?: boolean\n}\nexport interface ChatStepsPart {\n type: 'steps'\n items: ChatStep[]\n live?: boolean\n title?: string\n}\nexport interface ChatPlanPart {\n type: 'plan'\n items: ChatPlanItem[]\n title?: string\n collapsible?: boolean\n live?: boolean\n}\nexport interface ChatSourcesPart {\n type: 'sources'\n items: ChatSource[]\n}\nexport interface ChatFilesPart {\n type: 'files'\n files: ChatAttachment[]\n}\nexport interface ChatArtifactPart {\n type: 'artifact'\n /** Handed back with `artifact`, to tell artifacts apart. */\n id?: string | number\n title: string\n kind?: ChatArtifactKind\n /** Below the title. While running it shimmers; left out, the line reads \"Generating\". */\n description?: string\n status?: ChatArtifactStatus\n active?: boolean\n}\nexport interface ChatConfirmPart {\n type: 'confirm'\n /** Handed back with `confirm`, to tell requests apart. */\n id?: string | number\n title: string\n description?: string\n status?: ChatConfirmStatus\n allowAlways?: boolean\n tone?: ChatConfirmTone\n /** Shown as monospace detail, e.g. the command to run or a diff. */\n detail?: string\n}\nexport interface ChatQuestionPart {\n type: 'question'\n /** Handed back with `question`, to tell questions apart. */\n id?: string | number\n title: string\n description?: string\n options: ChatQuestionOption[]\n status?: ChatQuestionStatus\n /** The `value` of the option chosen. */\n answer?: string | number\n}\n/** Any other part; render it with the `part` slot. */\nexport interface ChatCustomPart {\n type: string\n [key: string]: unknown\n}\n\nexport type ChatMessagePart =\n | ChatTextPart\n | ChatReasoningPart\n | ChatToolPart\n | ChatStepsPart\n | ChatPlanPart\n | ChatSourcesPart\n | ChatFilesPart\n | ChatArtifactPart\n | ChatConfirmPart\n | ChatQuestionPart\n\nexport interface ChatMessageProps {\n sender?: ChatMessageSender\n /**\n * What the message is made of, in order: text, reasoning, tool calls,\n * steps, a plan, sources, files, artifacts, confirmations and questions may follow\n * one another in any order.\n */\n parts?: (ChatMessagePart | ChatCustomPart)[]\n /** Shorthand for a message of one text part. */\n content?: string\n /**\n * Render text and reasoning parts as Markdown, streaming included. `[1]`\n * in the text becomes a citation of the message's sources parts. An\n * object turns it on with options for the Markdown component, such as\n * `sanitizeUrl`. Set it for every message in the ConfigProvider's\n * `defaults`.\n */\n markdown?: boolean | ChatMessageMarkdown\n /** No part has arrived yet: show the waiting dots, like ChatBubble's. */\n loading?: boolean\n /**\n * When the actions show: `'always'`, or `'hover'` while the pointer is\n * over the message or focus is inside. Devices without hover always show\n * them. Buttons from the `actions` slot follow along. Defaults to\n * `'hover'` for the person's messages and `'always'` for the rest.\n */\n actionsVisible?: ChatMessageActionsVisible\n /** Show a copy button among the actions, copying the text parts. */\n copyable?: boolean\n /** Offer an edit button on the person's own messages; saving emits `edit`. */\n editable?: boolean\n /** How many versions of this message there are, e.g. after regenerating. Two or more show a switcher. */\n versions?: number\n /** Which version is shown, from 1. Bound with `v-model:version`. */\n version?: number\n /**\n * Mark this message with a ring in the primary color that hugs the\n * bubble, e.g. after a search jumped to it. It stays while set and fades\n * once turned off (at once with reduced motion): turn it off after a\n * moment. Pair it with ChatList's `scrollToMessage`.\n */\n highlighted?: boolean\n}\n\nexport interface ChatMessageEmits {\n 'update:version': [version: number]\n /** An edited message was saved, with its new text. */\n edit: [text: string]\n /** A confirmation part was answered. */\n confirm: [part: ChatConfirmPart, decision: ChatConfirmDecision]\n /** An artifact part was pressed. */\n artifact: [part: ChatArtifactPart]\n /** An option of a question part was pressed, with its `value` and the option itself. */\n question: [part: ChatQuestionPart, value: string | number, option: ChatQuestionOption]\n}\n\nexport interface ChatMessageSlots {\n /**\n * Renders a text part by hand, in place of plain text or `markdown`.\n * `text` is what has been revealed so far; `part.text` is all of it.\n * `sources` are the message's sources, for citations.\n */\n text?: (props: {\n part: ChatTextPart\n text: string\n index: number\n sources: ChatSource[]\n }) => unknown\n /** Renders parts of a type the message does not know. */\n part?: (props: { part: ChatCustomPart; index: number }) => unknown\n /** Buttons after the built-in actions, e.g. regenerate or feedback. */\n actions?: () => unknown\n /** Replaces all parts, for a message laid out by hand. */\n default?: () => unknown\n}\n\n/**\n * The Markdown component's slots, with a `markdown-` prefix, for text\n * rendered with `markdown`: `markdown-code`, `markdown-container-tip`, ...\n */\nexport type ChatMessageMarkdownSlots = {\n [K in keyof MarkdownSlots as `markdown-${K & string}`]: MarkdownSlots[K]\n}\n\n/** The text of a message, for copying: its text parts, one paragraph each. */\nexport function messageText(parts: readonly { type: string; text?: unknown }[]): string {\n return parts\n .filter((part) => part.type === 'text' && typeof part.text === 'string')\n .map((part) => part.text as string)\n .join('\\n\\n')\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"chat-message.js","names":[],"sources":["../../../src/components/chat-message/chat-message.ts"],"sourcesContent":["import type { ChatArtifactKind, ChatArtifactStatus } from '../chat-artifact/chat-artifact'\nimport type { ChatAttachment } from '../chat-attachments/chat-attachments'\nimport type {\n ChatConfirmDecision,\n ChatConfirmStatus,\n ChatConfirmTone,\n} from '../chat-confirm/chat-confirm'\nimport type { ChatPlanItem } from '../chat-plan/chat-plan'\nimport type { ChatQuestionOption, ChatQuestionStatus } from '../chat-question/chat-question'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport type { ChatStep } from '../chat-steps/chat-steps'\nimport type { ChatToolCallStatus } from '../chat-tool-call/chat-tool-call'\nimport type { MarkdownProps, MarkdownSlots } from '../markdown/markdown'\n\n/** Options for the Markdown of text and reasoning parts. */\nexport type ChatMessageMarkdown = Pick<\n MarkdownProps,\n 'smooth' | 'speed' | 'caret' | 'linkTarget' | 'sanitizeUrl'\n>\n\n/** Who wrote the message. */\nexport type ChatMessageSender = 'user' | 'assistant' | 'system'\n\n/** When the actions under a message show. */\nexport type ChatMessageActionsVisible = 'always' | 'hover'\n\nexport interface ChatTextPart {\n type: 'text'\n text: string\n /** More text is still coming. */\n streaming?: boolean\n}\nexport interface ChatReasoningPart {\n type: 'reasoning'\n text: string\n thinking?: boolean\n /** Seconds it took. */\n duration?: number\n}\nexport interface ChatToolPart {\n type: 'tool'\n name?: string\n title?: string\n status?: ChatToolCallStatus\n input?: unknown\n output?: unknown\n live?: boolean\n}\nexport interface ChatStepsPart {\n type: 'steps'\n items: ChatStep[]\n live?: boolean\n title?: string\n}\nexport interface ChatPlanPart {\n type: 'plan'\n items: ChatPlanItem[]\n title?: string\n collapsible?: boolean\n live?: boolean\n}\nexport interface ChatSourcesPart {\n type: 'sources'\n items: ChatSource[]\n}\nexport interface ChatFilesPart {\n type: 'files'\n files: ChatAttachment[]\n}\nexport interface ChatArtifactPart {\n type: 'artifact'\n /** Handed back with `artifact`, to tell artifacts apart. */\n id?: string | number\n title: string\n kind?: ChatArtifactKind\n /** Below the title. While running it shimmers; left out, the line reads \"Generating\". */\n description?: string\n status?: ChatArtifactStatus\n active?: boolean\n}\nexport interface ChatConfirmPart {\n type: 'confirm'\n /** Handed back with `confirm`, to tell requests apart. */\n id?: string | number\n title: string\n description?: string\n status?: ChatConfirmStatus\n allowAlways?: boolean\n tone?: ChatConfirmTone\n /** Shown as monospace detail, e.g. the command to run or a diff. */\n detail?: string\n}\nexport interface ChatQuestionPart {\n type: 'question'\n /** Handed back with `question`, to tell questions apart. */\n id?: string | number\n title: string\n description?: string\n options: ChatQuestionOption[]\n status?: ChatQuestionStatus\n /** The `value` of the option chosen. */\n answer?: string | number\n}\n/** Any other part; render it with the `part` slot. */\nexport interface ChatCustomPart {\n type: string\n [key: string]: unknown\n}\n\nexport type ChatMessagePart =\n | ChatTextPart\n | ChatReasoningPart\n | ChatToolPart\n | ChatStepsPart\n | ChatPlanPart\n | ChatSourcesPart\n | ChatFilesPart\n | ChatArtifactPart\n | ChatConfirmPart\n | ChatQuestionPart\n\nexport interface ChatMessageProps {\n sender?: ChatMessageSender\n /**\n * What the message is made of, in order: text, reasoning, tool calls,\n * steps, a plan, sources, files, artifacts, confirmations and questions may follow\n * one another in any order.\n */\n parts?: (ChatMessagePart | ChatCustomPart)[]\n /** Shorthand for a message of one text part. */\n content?: string\n /**\n * Render text and reasoning parts as Markdown, streaming included. `[1]`\n * in the text becomes a citation of the message's sources parts. An\n * object turns it on with options for the Markdown component, such as\n * `sanitizeUrl`. Set it for every message in the ConfigProvider's\n * `defaults`.\n */\n markdown?: boolean | ChatMessageMarkdown\n /** No part has arrived yet: show the waiting dots, like ChatBubble's. */\n loading?: boolean\n /**\n * When the actions show: `'always'`, or `'hover'` while the pointer is\n * over the message or focus is inside. Devices without hover always show\n * them. Buttons from the `actions` slot follow along. Defaults to\n * `'hover'` for the person's messages and `'always'` for the rest.\n */\n actionsVisible?: ChatMessageActionsVisible\n /** Show a copy button among the actions, copying the text parts. */\n copyable?: boolean\n /** Offer an edit button on the person's own messages; saving emits `edit`. */\n editable?: boolean\n /** How many versions of this message there are, e.g. after regenerating. Two or more show a switcher. */\n versions?: number\n /** Which version is shown, from 1. Bound with `v-model:version`. */\n version?: number\n /**\n * Mark this message with a ring in the primary color that hugs the\n * bubble, e.g. after a search jumped to it. It stays while set and fades\n * once turned off (at once with reduced motion): turn it off after a\n * moment. Pair it with ChatList's `scrollToMessage`.\n */\n highlighted?: boolean\n}\n\nexport interface ChatMessageEmits {\n 'update:version': [version: number]\n /** An edited message was saved, with its new text. */\n edit: [text: string]\n /** A confirmation part was answered. */\n confirm: [part: ChatConfirmPart, decision: ChatConfirmDecision]\n /** An artifact part was pressed. */\n artifact: [part: ChatArtifactPart]\n /** An option of a question part was pressed, with its `value` and the option itself. */\n question: [part: ChatQuestionPart, value: string | number, option: ChatQuestionOption]\n}\n\nexport interface ChatMessageSlots {\n /**\n * Renders a text part by hand, in place of plain text or `markdown`.\n * `text` is what has been revealed so far; `part.text` is all of it.\n * `sources` are the message's sources, for citations.\n */\n text?: (props: {\n part: ChatTextPart\n text: string\n index: number\n sources: ChatSource[]\n }) => unknown\n /** Renders parts of a type the message does not know. */\n part?: (props: { part: ChatCustomPart; index: number }) => unknown\n /** Buttons after the built-in actions, e.g. regenerate or feedback. */\n actions?: () => unknown\n /**\n * Content that follows the last word of the last text part on the same\n * line, e.g. an \"edited\" mark. Unlike `actions` it always shows, whatever\n * `actionsVisible` is. Without a text part it takes a line after the parts,\n * once `loading` is off.\n */\n trailing?: () => unknown\n /** Replaces all parts, for a message laid out by hand. */\n default?: () => unknown\n}\n\n/**\n * The Markdown component's slots, with a `markdown-` prefix, for text\n * rendered with `markdown`: `markdown-code`, `markdown-container-tip`, ...\n */\nexport type ChatMessageMarkdownSlots = {\n [K in Exclude<keyof MarkdownSlots, 'trailing'> as `markdown-${K & string}`]: MarkdownSlots[K]\n}\n\n/** The text of a message, for copying: its text parts, one paragraph each. */\nexport function messageText(parts: readonly { type: string; text?: unknown }[]): string {\n return parts\n .filter((part) => part.type === 'text' && typeof part.text === 'string')\n .map((part) => part.text as string)\n .join('\\n\\n')\n}\n"],"mappings":";;AAqNA,SAAgB,YAAY,OAA4D;CACtF,OAAO,MACJ,QAAQ,SAAS,KAAK,SAAS,UAAU,OAAO,KAAK,SAAS,QAAQ,CAAC,CACvE,KAAK,SAAS,KAAK,IAAc,CAAC,CAClC,KAAK,MAAM;AAChB"}
|
|
@@ -72,7 +72,7 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
72
72
|
text: props.content
|
|
73
73
|
}]));
|
|
74
74
|
const markdownOptions = computed(() => typeof props.markdown === "object" ? props.markdown : void 0);
|
|
75
|
-
const markdownSlots = () => Object.keys(slots).filter((name) => name.startsWith(PREFIX)).map((name) => ({
|
|
75
|
+
const markdownSlots = () => Object.keys(slots).filter((name) => name.startsWith(PREFIX) && name !== `${PREFIX}trailing`).map((name) => ({
|
|
76
76
|
name,
|
|
77
77
|
inner: name.slice(9)
|
|
78
78
|
}));
|
|
@@ -81,6 +81,11 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
81
81
|
const files = computed(() => isUser.value ? parts.value.filter((p) => p.type === "files") : []);
|
|
82
82
|
const body = computed(() => isUser.value ? parts.value.filter((p) => p.type !== "files") : parts.value);
|
|
83
83
|
const text = computed(() => messageText(parts.value));
|
|
84
|
+
/** The last text part, which the `trailing` slot follows; -1 without one. */
|
|
85
|
+
const lastText = computed(() => {
|
|
86
|
+
for (let i = body.value.length - 1; i >= 0; i--) if (body.value[i].type === "text") return i;
|
|
87
|
+
return -1;
|
|
88
|
+
});
|
|
84
89
|
let lastSources = [];
|
|
85
90
|
const sources = computed(() => {
|
|
86
91
|
const next = parts.value.flatMap((part) => part.type === "sources" ? part.items ?? [] : []);
|
|
@@ -226,7 +231,11 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
226
231
|
name: slot.inner,
|
|
227
232
|
fn: withCtx((scope) => [renderSlot(_ctx.$slots, slot.name, mergeProps({ ref_for: true }, scope))])
|
|
228
233
|
};
|
|
229
|
-
})
|
|
234
|
+
}), slots.trailing && index === lastText.value ? {
|
|
235
|
+
name: "trailing",
|
|
236
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "trailing")]),
|
|
237
|
+
key: "0"
|
|
238
|
+
} : void 0]), 1040, [
|
|
230
239
|
"class",
|
|
231
240
|
"content",
|
|
232
241
|
"streaming",
|
|
@@ -245,6 +254,10 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
245
254
|
sources: sources.value
|
|
246
255
|
})]),
|
|
247
256
|
key: "0"
|
|
257
|
+
} : void 0, slots.trailing && index === lastText.value ? {
|
|
258
|
+
name: "trailing",
|
|
259
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "trailing")]),
|
|
260
|
+
key: "1"
|
|
248
261
|
} : void 0]), 1032, [
|
|
249
262
|
"class",
|
|
250
263
|
"content",
|
|
@@ -332,7 +345,10 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
332
345
|
part,
|
|
333
346
|
index
|
|
334
347
|
}, void 0, void 0, 11) : createCommentVNode("", true)], 64);
|
|
335
|
-
}), 128))
|
|
348
|
+
}), 128)), slots.trailing && lastText.value < 0 && !__props.loading ? (openBlock(), createElementBlock("div", {
|
|
349
|
+
key: 0,
|
|
350
|
+
class: normalizeClass(unref(ns).e("trailing"))
|
|
351
|
+
}, [renderSlot(_ctx.$slots, "trailing")], 2)) : createCommentVNode("", true)]), __props.loading ? (openBlock(), createElementBlock("span", {
|
|
336
352
|
key: 0,
|
|
337
353
|
class: normalizeClass(unref(ns).e("loading")),
|
|
338
354
|
role: "status",
|
package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-message.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_Fragment","_renderList","_createBlock","_createCommentVNode","_withDirectives","_createElementVNode","_vModelText","_createVNode","_withCtx","_createTextVNode","_toDisplayString","_renderSlot","_mergeProps","_createSlots"],"sources":["../../../src/components/chat-message/chat-message.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronLeftIcon, ChevronRightIcon, EditIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useTemplateRef } from 'vue'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouButton } from '../button'\nimport { DouChatArtifact } from '../chat-artifact'\nimport { DouChatAttachments } from '../chat-attachments'\nimport { DouChatConfirm } from '../chat-confirm'\nimport { DouChatQuestion } from '../chat-question'\nimport { DouChatPlan } from '../chat-plan'\nimport { planRunning, type ChatPlanItem } from '../chat-plan/chat-plan'\nimport { DouChatReasoning } from '../chat-reasoning'\nimport { DouChatSources } from '../chat-sources'\nimport { DouChatSteps } from '../chat-steps'\nimport { stepsLive, type ChatStep } from '../chat-steps/chat-steps'\nimport { DouChatToolCall } from '../chat-tool-call'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport { DouMarkdown } from '../markdown'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport { DouStreamText } from '../stream-text'\nimport { DouTooltip } from '../tooltip'\nimport { messageText } from './chat-message'\nimport type {\n ChatArtifactPart,\n ChatConfirmPart,\n ChatQuestionPart,\n ChatCustomPart,\n ChatMessageEmits,\n ChatMessagePart,\n ChatMessageMarkdownSlots,\n ChatMessageProps,\n ChatMessageSlots,\n} from './chat-message'\n\ndefineOptions({ name: 'DouChatMessage' })\n\nconst props = withDefaults(defineProps<ChatMessageProps>(), {\n sender: 'assistant',\n loading: false,\n copyable: true,\n editable: false,\n markdown: false,\n actionsVisible: undefined,\n versions: 1,\n version: undefined,\n})\nconst emit = defineEmits<ChatMessageEmits>()\nconst slots = defineSlots<ChatMessageSlots & ChatMessageMarkdownSlots>()\n\nconst ns = useNamespace('chat-message')\nconst { t } = useLocale()\n\ntype AnyPart = ChatMessagePart | ChatCustomPart\n\nconst parts = computed<AnyPart[]>(\n () => props.parts ?? (props.content === undefined ? [] : [{ type: 'text', text: props.content }]),\n)\nconst markdownOptions = computed(() =>\n typeof props.markdown === 'object' ? props.markdown : undefined,\n)\n// `markdown-code` here is the Markdown component's `code`\nconst PREFIX = 'markdown-'\nconst markdownSlots = () =>\n Object.keys(slots)\n .filter((name) => name.startsWith(PREFIX))\n .map((name) => ({\n name: name as keyof ChatMessageMarkdownSlots,\n inner: name.slice(PREFIX.length),\n }))\nconst isUser = computed(() => props.sender === 'user')\nconst actionsShow = computed(() => props.actionsVisible ?? (isUser.value ? 'hover' : 'always'))\n// the person's attachments sit above their bubble, not inside it\nconst files = computed(() => (isUser.value ? parts.value.filter((p) => p.type === 'files') : []))\nconst body = computed(() =>\n isUser.value ? parts.value.filter((p) => p.type !== 'files') : parts.value,\n)\nconst text = computed(() => messageText(parts.value as { type: string; text?: unknown }[]))\n// Every source of the message, numbered in order, for `[1]` in Markdown\n// text. The same array while the sources stay the same, so text that\n// streams in does not redraw the whole reply.\nlet lastSources: ChatSource[] = []\nconst sources = computed(() => {\n const next = parts.value.flatMap((part) =>\n part.type === 'sources' ? ((part as { items?: ChatSource[] }).items ?? []) : [],\n )\n if (next.length === lastSources.length && next.every((s, i) => s === lastSources[i]))\n return lastSources\n return (lastSources = next)\n})\n\nconst busy = computed(\n () =>\n props.loading ||\n parts.value.some((part) => {\n const p = part as Record<string, unknown>\n // an artifact can keep being made after the reply ends, so it doesn't hold the actions back\n const working = p.status === 'running' && p.type !== 'artifact' && p.live !== false\n // busy exactly when steps or a plan show themselves running\n const live = p.live as boolean | undefined\n const steps = p.type === 'steps' && stepsLive(p.items as ChatStep[] | undefined, live)\n const plan = p.type === 'plan' && planRunning(p.items as ChatPlanItem[] | undefined, live)\n return !!p.streaming || !!p.thinking || steps || plan || working\n }),\n)\n\nconst innerVersion = ref(props.versions)\nconst version = computed(() => Math.min(props.version ?? innerVersion.value, props.versions))\nfunction step(delta: number) {\n const next = Math.min(Math.max(version.value + delta, 1), props.versions)\n innerVersion.value = next\n emit('update:version', next)\n}\n\nconst showActions = computed(\n () =>\n !busy.value &&\n (props.versions > 1 ||\n (props.copyable && !!text.value) ||\n (props.editable && isUser.value) ||\n !!slots.actions),\n)\n\n// editing in place\nconst editing = ref(false)\nconst draft = ref('')\nconst editorRef = useTemplateRef<HTMLTextAreaElement>('editor')\nfunction startEdit() {\n draft.value = text.value\n editing.value = true\n void nextTick(() => {\n const el = editorRef.value\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n fitEditor()\n })\n}\nfunction cancelEdit() {\n editing.value = false\n}\nfunction saveEdit() {\n if (!draft.value.trim()) return\n editing.value = false\n emit('edit', draft.value)\n}\nfunction fitEditor() {\n const el = editorRef.value\n if (!el) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nfunction onEditorKeydown(event: KeyboardEvent) {\n if (event.key === 'Escape') {\n event.preventDefault()\n cancelEdit()\n } else if (event.key === 'Enter' && !event.shiftKey && !isComposing(event)) {\n event.preventDefault()\n saveEdit()\n }\n}\n\nconst asText = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'text' }>\nconst asReasoning = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'reasoning' }>\nconst asFiles = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'files' }>\nconst asConfirm = (part: AnyPart) => part as ChatConfirmPart\nconst asArtifact = (part: AnyPart) => part as ChatArtifactPart\nconst asQuestion = (part: AnyPart) => part as ChatQuestionPart\nconst known = new Set([\n 'text',\n 'reasoning',\n 'tool',\n 'steps',\n 'plan',\n 'sources',\n 'files',\n 'artifact',\n 'confirm',\n 'question',\n])\n// props for the part components, without the `type` discriminator\nconst rest = (part: AnyPart) => {\n const { type: _type, ...others } = part as Record<string, unknown>\n return others\n}\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.m(sender),\n ns.m(`actions-${actionsShow}`),\n ns.is('loading', loading),\n ns.is('editing', editing),\n ns.is('highlighted', highlighted),\n ]\"\n :aria-busy=\"busy || undefined\"\n :aria-current=\"highlighted || undefined\"\n >\n <div v-if=\"files.length && !editing\" :class=\"ns.e('files')\">\n <template v-for=\"(part, index) in files\" :key=\"`f${index}`\">\n <DouChatAttachments :model-value=\"asFiles(part).files\" :removable=\"false\" />\n </template>\n </div>\n\n <div v-if=\"editing\" :class=\"ns.e('editor')\">\n <textarea\n ref=\"editor\"\n v-model=\"draft\"\n :class=\"ns.e('editor-native')\"\n rows=\"1\"\n :aria-label=\"t('chat.edit')\"\n @input=\"fitEditor\"\n @keydown=\"onEditorKeydown\"\n />\n <div :class=\"ns.e('editor-actions')\">\n <DouButton size=\"sm\" variant=\"ghost\" @click=\"cancelEdit\">{{ t('chat.cancel') }}</DouButton>\n <DouButton size=\"sm\" :disabled=\"!draft.trim()\" @click=\"saveEdit\">\n {{ t('chat.send') }}\n </DouButton>\n </div>\n </div>\n\n <div v-else-if=\"body.length || loading || slots.default\" :class=\"ns.e('content')\">\n <slot>\n <template v-for=\"(part, index) in body\" :key=\"index\">\n <DouMarkdown\n v-if=\"part.type === 'text' && markdown && !slots.text\"\n v-bind=\"markdownOptions\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n :sources=\"sources.length ? sources : undefined\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else-if=\"part.type === 'text'\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n >\n <template v-if=\"slots.text\" #default=\"{ text: shown }\">\n <slot\n name=\"text\"\n :part=\"asText(part)\"\n :text=\"shown\"\n :index=\"index\"\n :sources=\"sources\"\n />\n </template>\n </DouStreamText>\n <DouChatReasoning\n v-else-if=\"part.type === 'reasoning'\"\n :thinking=\"!!asReasoning(part).thinking\"\n :duration=\"asReasoning(part).duration\"\n >\n <DouMarkdown\n v-if=\"markdown\"\n v-bind=\"markdownOptions\"\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n />\n </DouChatReasoning>\n <DouChatToolCall v-else-if=\"part.type === 'tool'\" v-bind=\"rest(part)\" />\n <DouChatSteps v-else-if=\"part.type === 'steps'\" v-bind=\"rest(part)\" />\n <DouChatPlan v-else-if=\"part.type === 'plan'\" v-bind=\"rest(part)\" />\n <DouChatSources v-else-if=\"part.type === 'sources'\" v-bind=\"rest(part)\" />\n <DouChatAttachments\n v-else-if=\"part.type === 'files'\"\n :model-value=\"asFiles(part).files\"\n :removable=\"false\"\n />\n <DouChatArtifact\n v-else-if=\"part.type === 'artifact'\"\n v-bind=\"rest(part)\"\n @open=\"emit('artifact', asArtifact(part))\"\n />\n <DouChatConfirm\n v-else-if=\"part.type === 'confirm'\"\n :title=\"asConfirm(part).title\"\n :description=\"asConfirm(part).description\"\n :status=\"asConfirm(part).status\"\n :allow-always=\"asConfirm(part).allowAlways\"\n :tone=\"asConfirm(part).tone\"\n @decide=\"emit('confirm', asConfirm(part), $event)\"\n >\n <pre v-if=\"asConfirm(part).detail\" :class=\"ns.e('code')\">{{\n asConfirm(part).detail\n }}</pre>\n </DouChatConfirm>\n <DouChatQuestion\n v-else-if=\"part.type === 'question'\"\n :title=\"asQuestion(part).title\"\n :description=\"asQuestion(part).description\"\n :options=\"asQuestion(part).options\"\n :status=\"asQuestion(part).status\"\n :answer=\"asQuestion(part).answer\"\n @select=\"(value, option) => emit('question', asQuestion(part), value, option)\"\n />\n <slot\n v-else-if=\"!known.has(part.type)\"\n name=\"part\"\n :part=\"part as ChatCustomPart\"\n :index=\"index\"\n />\n </template>\n </slot>\n <span v-if=\"loading\" :class=\"ns.e('loading')\" role=\"status\" :aria-label=\"t('chat.loading')\">\n <i /><i /><i />\n </span>\n </div>\n\n <div v-if=\"showActions && !editing\" :class=\"ns.e('actions')\">\n <div\n v-if=\"versions > 1\"\n :class=\"ns.e('versions')\"\n role=\"group\"\n :aria-label=\"t('chat.versions')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version <= 1\"\n :aria-label=\"t('chat.previousVersion')\"\n @click=\"step(-1)\"\n >\n <ChevronLeftIcon />\n </DouButton>\n <span :class=\"ns.e('version')\">{{ version }} / {{ versions }}</span>\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version >= versions\"\n :aria-label=\"t('chat.nextVersion')\"\n @click=\"step(1)\"\n >\n <ChevronRightIcon />\n </DouButton>\n </div>\n <DouCopyButton v-if=\"copyable && text\" size=\"sm\" :text=\"text\" />\n <DouTooltip v-if=\"editable && isUser\" :content=\"t('chat.edit')\">\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('chat.edit')\" @click=\"startEdit\">\n <EditIcon />\n </DouButton>\n </DouTooltip>\n <slot name=\"actions\" />\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,IAAM,SAAS;;;;;;;;;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,cAEY,CAFZD,YAEYR,MAAA,SAAA,GAAA;OAFD,SAAQ;OAAQ,MAAK;OAAM,cAAYA,MAAA,CAAA,CAAC,CAAA,WAAA;OAAgB,SAAO;;OACxE,SAAAS,cAAY,CAAZD,YAAYR,MAAA,QAAA,CAAA,C;;;;;KAGhBY,WAAuB,KAAA,QAAA,SAAA"}
|
|
1
|
+
{"version":3,"file":"chat-message.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_Fragment","_renderList","_createBlock","_createCommentVNode","_withDirectives","_createElementVNode","_vModelText","_createVNode","_withCtx","_createTextVNode","_toDisplayString","_renderSlot","_mergeProps","_createSlots"],"sources":["../../../src/components/chat-message/chat-message.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronLeftIcon, ChevronRightIcon, EditIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useTemplateRef } from 'vue'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouButton } from '../button'\nimport { DouChatArtifact } from '../chat-artifact'\nimport { DouChatAttachments } from '../chat-attachments'\nimport { DouChatConfirm } from '../chat-confirm'\nimport { DouChatQuestion } from '../chat-question'\nimport { DouChatPlan } from '../chat-plan'\nimport { planRunning, type ChatPlanItem } from '../chat-plan/chat-plan'\nimport { DouChatReasoning } from '../chat-reasoning'\nimport { DouChatSources } from '../chat-sources'\nimport { DouChatSteps } from '../chat-steps'\nimport { stepsLive, type ChatStep } from '../chat-steps/chat-steps'\nimport { DouChatToolCall } from '../chat-tool-call'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport { DouMarkdown } from '../markdown'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport { DouStreamText } from '../stream-text'\nimport { DouTooltip } from '../tooltip'\nimport { messageText } from './chat-message'\nimport type {\n ChatArtifactPart,\n ChatConfirmPart,\n ChatQuestionPart,\n ChatCustomPart,\n ChatMessageEmits,\n ChatMessagePart,\n ChatMessageMarkdownSlots,\n ChatMessageProps,\n ChatMessageSlots,\n} from './chat-message'\n\ndefineOptions({ name: 'DouChatMessage' })\n\nconst props = withDefaults(defineProps<ChatMessageProps>(), {\n sender: 'assistant',\n loading: false,\n copyable: true,\n editable: false,\n markdown: false,\n actionsVisible: undefined,\n versions: 1,\n version: undefined,\n})\nconst emit = defineEmits<ChatMessageEmits>()\nconst slots = defineSlots<ChatMessageSlots & ChatMessageMarkdownSlots>()\n\nconst ns = useNamespace('chat-message')\nconst { t } = useLocale()\n\ntype AnyPart = ChatMessagePart | ChatCustomPart\n\nconst parts = computed<AnyPart[]>(\n () => props.parts ?? (props.content === undefined ? [] : [{ type: 'text', text: props.content }]),\n)\nconst markdownOptions = computed(() =>\n typeof props.markdown === 'object' ? props.markdown : undefined,\n)\n// `markdown-code` here is the Markdown component's `code`\nconst PREFIX = 'markdown-'\nconst markdownSlots = () =>\n Object.keys(slots)\n // the message's own `trailing` goes to its last text, not to every Markdown in it\n .filter((name) => name.startsWith(PREFIX) && name !== `${PREFIX}trailing`)\n .map((name) => ({\n name: name as keyof ChatMessageMarkdownSlots,\n inner: name.slice(PREFIX.length),\n }))\nconst isUser = computed(() => props.sender === 'user')\nconst actionsShow = computed(() => props.actionsVisible ?? (isUser.value ? 'hover' : 'always'))\n// the person's attachments sit above their bubble, not inside it\nconst files = computed(() => (isUser.value ? parts.value.filter((p) => p.type === 'files') : []))\nconst body = computed(() =>\n isUser.value ? parts.value.filter((p) => p.type !== 'files') : parts.value,\n)\nconst text = computed(() => messageText(parts.value as { type: string; text?: unknown }[]))\n/** The last text part, which the `trailing` slot follows; -1 without one. */\nconst lastText = computed(() => {\n for (let i = body.value.length - 1; i >= 0; i--) if (body.value[i]!.type === 'text') return i\n return -1\n})\n// Every source of the message, numbered in order, for `[1]` in Markdown\n// text. The same array while the sources stay the same, so text that\n// streams in does not redraw the whole reply.\nlet lastSources: ChatSource[] = []\nconst sources = computed(() => {\n const next = parts.value.flatMap((part) =>\n part.type === 'sources' ? ((part as { items?: ChatSource[] }).items ?? []) : [],\n )\n if (next.length === lastSources.length && next.every((s, i) => s === lastSources[i]))\n return lastSources\n return (lastSources = next)\n})\n\nconst busy = computed(\n () =>\n props.loading ||\n parts.value.some((part) => {\n const p = part as Record<string, unknown>\n // an artifact can keep being made after the reply ends, so it doesn't hold the actions back\n const working = p.status === 'running' && p.type !== 'artifact' && p.live !== false\n // busy exactly when steps or a plan show themselves running\n const live = p.live as boolean | undefined\n const steps = p.type === 'steps' && stepsLive(p.items as ChatStep[] | undefined, live)\n const plan = p.type === 'plan' && planRunning(p.items as ChatPlanItem[] | undefined, live)\n return !!p.streaming || !!p.thinking || steps || plan || working\n }),\n)\n\nconst innerVersion = ref(props.versions)\nconst version = computed(() => Math.min(props.version ?? innerVersion.value, props.versions))\nfunction step(delta: number) {\n const next = Math.min(Math.max(version.value + delta, 1), props.versions)\n innerVersion.value = next\n emit('update:version', next)\n}\n\nconst showActions = computed(\n () =>\n !busy.value &&\n (props.versions > 1 ||\n (props.copyable && !!text.value) ||\n (props.editable && isUser.value) ||\n !!slots.actions),\n)\n\n// editing in place\nconst editing = ref(false)\nconst draft = ref('')\nconst editorRef = useTemplateRef<HTMLTextAreaElement>('editor')\nfunction startEdit() {\n draft.value = text.value\n editing.value = true\n void nextTick(() => {\n const el = editorRef.value\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n fitEditor()\n })\n}\nfunction cancelEdit() {\n editing.value = false\n}\nfunction saveEdit() {\n if (!draft.value.trim()) return\n editing.value = false\n emit('edit', draft.value)\n}\nfunction fitEditor() {\n const el = editorRef.value\n if (!el) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nfunction onEditorKeydown(event: KeyboardEvent) {\n if (event.key === 'Escape') {\n event.preventDefault()\n cancelEdit()\n } else if (event.key === 'Enter' && !event.shiftKey && !isComposing(event)) {\n event.preventDefault()\n saveEdit()\n }\n}\n\nconst asText = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'text' }>\nconst asReasoning = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'reasoning' }>\nconst asFiles = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'files' }>\nconst asConfirm = (part: AnyPart) => part as ChatConfirmPart\nconst asArtifact = (part: AnyPart) => part as ChatArtifactPart\nconst asQuestion = (part: AnyPart) => part as ChatQuestionPart\nconst known = new Set([\n 'text',\n 'reasoning',\n 'tool',\n 'steps',\n 'plan',\n 'sources',\n 'files',\n 'artifact',\n 'confirm',\n 'question',\n])\n// props for the part components, without the `type` discriminator\nconst rest = (part: AnyPart) => {\n const { type: _type, ...others } = part as Record<string, unknown>\n return others\n}\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.m(sender),\n ns.m(`actions-${actionsShow}`),\n ns.is('loading', loading),\n ns.is('editing', editing),\n ns.is('highlighted', highlighted),\n ]\"\n :aria-busy=\"busy || undefined\"\n :aria-current=\"highlighted || undefined\"\n >\n <div v-if=\"files.length && !editing\" :class=\"ns.e('files')\">\n <template v-for=\"(part, index) in files\" :key=\"`f${index}`\">\n <DouChatAttachments :model-value=\"asFiles(part).files\" :removable=\"false\" />\n </template>\n </div>\n\n <div v-if=\"editing\" :class=\"ns.e('editor')\">\n <textarea\n ref=\"editor\"\n v-model=\"draft\"\n :class=\"ns.e('editor-native')\"\n rows=\"1\"\n :aria-label=\"t('chat.edit')\"\n @input=\"fitEditor\"\n @keydown=\"onEditorKeydown\"\n />\n <div :class=\"ns.e('editor-actions')\">\n <DouButton size=\"sm\" variant=\"ghost\" @click=\"cancelEdit\">{{ t('chat.cancel') }}</DouButton>\n <DouButton size=\"sm\" :disabled=\"!draft.trim()\" @click=\"saveEdit\">\n {{ t('chat.send') }}\n </DouButton>\n </div>\n </div>\n\n <div v-else-if=\"body.length || loading || slots.default\" :class=\"ns.e('content')\">\n <slot>\n <template v-for=\"(part, index) in body\" :key=\"index\">\n <DouMarkdown\n v-if=\"part.type === 'text' && markdown && !slots.text\"\n v-bind=\"markdownOptions\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n :sources=\"sources.length ? sources : undefined\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n <template v-if=\"slots.trailing && index === lastText\" #trailing>\n <slot name=\"trailing\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else-if=\"part.type === 'text'\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n >\n <template v-if=\"slots.text\" #default=\"{ text: shown }\">\n <slot\n name=\"text\"\n :part=\"asText(part)\"\n :text=\"shown\"\n :index=\"index\"\n :sources=\"sources\"\n />\n </template>\n <template v-if=\"slots.trailing && index === lastText\" #trailing>\n <slot name=\"trailing\" />\n </template>\n </DouStreamText>\n <DouChatReasoning\n v-else-if=\"part.type === 'reasoning'\"\n :thinking=\"!!asReasoning(part).thinking\"\n :duration=\"asReasoning(part).duration\"\n >\n <DouMarkdown\n v-if=\"markdown\"\n v-bind=\"markdownOptions\"\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n />\n </DouChatReasoning>\n <DouChatToolCall v-else-if=\"part.type === 'tool'\" v-bind=\"rest(part)\" />\n <DouChatSteps v-else-if=\"part.type === 'steps'\" v-bind=\"rest(part)\" />\n <DouChatPlan v-else-if=\"part.type === 'plan'\" v-bind=\"rest(part)\" />\n <DouChatSources v-else-if=\"part.type === 'sources'\" v-bind=\"rest(part)\" />\n <DouChatAttachments\n v-else-if=\"part.type === 'files'\"\n :model-value=\"asFiles(part).files\"\n :removable=\"false\"\n />\n <DouChatArtifact\n v-else-if=\"part.type === 'artifact'\"\n v-bind=\"rest(part)\"\n @open=\"emit('artifact', asArtifact(part))\"\n />\n <DouChatConfirm\n v-else-if=\"part.type === 'confirm'\"\n :title=\"asConfirm(part).title\"\n :description=\"asConfirm(part).description\"\n :status=\"asConfirm(part).status\"\n :allow-always=\"asConfirm(part).allowAlways\"\n :tone=\"asConfirm(part).tone\"\n @decide=\"emit('confirm', asConfirm(part), $event)\"\n >\n <pre v-if=\"asConfirm(part).detail\" :class=\"ns.e('code')\">{{\n asConfirm(part).detail\n }}</pre>\n </DouChatConfirm>\n <DouChatQuestion\n v-else-if=\"part.type === 'question'\"\n :title=\"asQuestion(part).title\"\n :description=\"asQuestion(part).description\"\n :options=\"asQuestion(part).options\"\n :status=\"asQuestion(part).status\"\n :answer=\"asQuestion(part).answer\"\n @select=\"(value, option) => emit('question', asQuestion(part), value, option)\"\n />\n <slot\n v-else-if=\"!known.has(part.type)\"\n name=\"part\"\n :part=\"part as ChatCustomPart\"\n :index=\"index\"\n />\n </template>\n <div v-if=\"slots.trailing && lastText < 0 && !loading\" :class=\"ns.e('trailing')\">\n <slot name=\"trailing\" />\n </div>\n </slot>\n <span v-if=\"loading\" :class=\"ns.e('loading')\" role=\"status\" :aria-label=\"t('chat.loading')\">\n <i /><i /><i />\n </span>\n </div>\n\n <div v-if=\"showActions && !editing\" :class=\"ns.e('actions')\">\n <div\n v-if=\"versions > 1\"\n :class=\"ns.e('versions')\"\n role=\"group\"\n :aria-label=\"t('chat.versions')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version <= 1\"\n :aria-label=\"t('chat.previousVersion')\"\n @click=\"step(-1)\"\n >\n <ChevronLeftIcon />\n </DouButton>\n <span :class=\"ns.e('version')\">{{ version }} / {{ versions }}</span>\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version >= versions\"\n :aria-label=\"t('chat.nextVersion')\"\n @click=\"step(1)\"\n >\n <ChevronRightIcon />\n </DouButton>\n </div>\n <DouCopyButton v-if=\"copyable && text\" size=\"sm\" :text=\"text\" />\n <DouTooltip v-if=\"editable && isUser\" :content=\"t('chat.edit')\">\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('chat.edit')\" @click=\"startEdit\">\n <EditIcon />\n </DouButton>\n </DouTooltip>\n <slot name=\"actions\" />\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,IAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAzBf,MAAM,QAAQ;EAUd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,cAAc;EACtC,MAAM,EAAE,MAAM,UAAU;EAIxB,MAAM,QAAQ,eACN,MAAM,UAAU,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,CAAC;GAAE,MAAM;GAAQ,MAAM,MAAM;EAAQ,CAAC,EACjG;EACA,MAAM,kBAAkB,eACtB,OAAO,MAAM,aAAa,WAAW,MAAM,WAAW,KAAA,CACxD;EAGA,MAAM,sBACJ,OAAO,KAAK,KAAK,CAAA,CAEd,QAAQ,SAAS,KAAK,WAAW,MAAM,KAAK,SAAS,GAAG,OAAO,SAAS,CAAA,CACxE,KAAK,UAAU;GACR;GACN,OAAO,KAAK,MAAM,CAAa;EACjC,EAAE;EACN,MAAM,SAAS,eAAe,MAAM,WAAW,MAAM;EACrD,MAAM,cAAc,eAAe,MAAM,mBAAmB,OAAO,QAAQ,UAAU,SAAS;EAE9F,MAAM,QAAQ,eAAgB,OAAO,QAAQ,MAAM,MAAM,QAAQ,MAAM,EAAE,SAAS,OAAO,IAAI,CAAC,CAAE;EAChG,MAAM,OAAO,eACX,OAAO,QAAQ,MAAM,MAAM,QAAQ,MAAM,EAAE,SAAS,OAAO,IAAI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@
|
|
|
1
|
-
{"version":3,"file":"chat-message2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-message/chat-message.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronLeftIcon, ChevronRightIcon, EditIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useTemplateRef } from 'vue'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouButton } from '../button'\nimport { DouChatArtifact } from '../chat-artifact'\nimport { DouChatAttachments } from '../chat-attachments'\nimport { DouChatConfirm } from '../chat-confirm'\nimport { DouChatQuestion } from '../chat-question'\nimport { DouChatPlan } from '../chat-plan'\nimport { planRunning, type ChatPlanItem } from '../chat-plan/chat-plan'\nimport { DouChatReasoning } from '../chat-reasoning'\nimport { DouChatSources } from '../chat-sources'\nimport { DouChatSteps } from '../chat-steps'\nimport { stepsLive, type ChatStep } from '../chat-steps/chat-steps'\nimport { DouChatToolCall } from '../chat-tool-call'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport { DouMarkdown } from '../markdown'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport { DouStreamText } from '../stream-text'\nimport { DouTooltip } from '../tooltip'\nimport { messageText } from './chat-message'\nimport type {\n ChatArtifactPart,\n ChatConfirmPart,\n ChatQuestionPart,\n ChatCustomPart,\n ChatMessageEmits,\n ChatMessagePart,\n ChatMessageMarkdownSlots,\n ChatMessageProps,\n ChatMessageSlots,\n} from './chat-message'\n\ndefineOptions({ name: 'DouChatMessage' })\n\nconst props = withDefaults(defineProps<ChatMessageProps>(), {\n sender: 'assistant',\n loading: false,\n copyable: true,\n editable: false,\n markdown: false,\n actionsVisible: undefined,\n versions: 1,\n version: undefined,\n})\nconst emit = defineEmits<ChatMessageEmits>()\nconst slots = defineSlots<ChatMessageSlots & ChatMessageMarkdownSlots>()\n\nconst ns = useNamespace('chat-message')\nconst { t } = useLocale()\n\ntype AnyPart = ChatMessagePart | ChatCustomPart\n\nconst parts = computed<AnyPart[]>(\n () => props.parts ?? (props.content === undefined ? [] : [{ type: 'text', text: props.content }]),\n)\nconst markdownOptions = computed(() =>\n typeof props.markdown === 'object' ? props.markdown : undefined,\n)\n// `markdown-code` here is the Markdown component's `code`\nconst PREFIX = 'markdown-'\nconst markdownSlots = () =>\n Object.keys(slots)\n .filter((name) => name.startsWith(PREFIX))\n .map((name) => ({\n name: name as keyof ChatMessageMarkdownSlots,\n inner: name.slice(PREFIX.length),\n }))\nconst isUser = computed(() => props.sender === 'user')\nconst actionsShow = computed(() => props.actionsVisible ?? (isUser.value ? 'hover' : 'always'))\n// the person's attachments sit above their bubble, not inside it\nconst files = computed(() => (isUser.value ? parts.value.filter((p) => p.type === 'files') : []))\nconst body = computed(() =>\n isUser.value ? parts.value.filter((p) => p.type !== 'files') : parts.value,\n)\nconst text = computed(() => messageText(parts.value as { type: string; text?: unknown }[]))\n// Every source of the message, numbered in order, for `[1]` in Markdown\n// text. The same array while the sources stay the same, so text that\n// streams in does not redraw the whole reply.\nlet lastSources: ChatSource[] = []\nconst sources = computed(() => {\n const next = parts.value.flatMap((part) =>\n part.type === 'sources' ? ((part as { items?: ChatSource[] }).items ?? []) : [],\n )\n if (next.length === lastSources.length && next.every((s, i) => s === lastSources[i]))\n return lastSources\n return (lastSources = next)\n})\n\nconst busy = computed(\n () =>\n props.loading ||\n parts.value.some((part) => {\n const p = part as Record<string, unknown>\n // an artifact can keep being made after the reply ends, so it doesn't hold the actions back\n const working = p.status === 'running' && p.type !== 'artifact' && p.live !== false\n // busy exactly when steps or a plan show themselves running\n const live = p.live as boolean | undefined\n const steps = p.type === 'steps' && stepsLive(p.items as ChatStep[] | undefined, live)\n const plan = p.type === 'plan' && planRunning(p.items as ChatPlanItem[] | undefined, live)\n return !!p.streaming || !!p.thinking || steps || plan || working\n }),\n)\n\nconst innerVersion = ref(props.versions)\nconst version = computed(() => Math.min(props.version ?? innerVersion.value, props.versions))\nfunction step(delta: number) {\n const next = Math.min(Math.max(version.value + delta, 1), props.versions)\n innerVersion.value = next\n emit('update:version', next)\n}\n\nconst showActions = computed(\n () =>\n !busy.value &&\n (props.versions > 1 ||\n (props.copyable && !!text.value) ||\n (props.editable && isUser.value) ||\n !!slots.actions),\n)\n\n// editing in place\nconst editing = ref(false)\nconst draft = ref('')\nconst editorRef = useTemplateRef<HTMLTextAreaElement>('editor')\nfunction startEdit() {\n draft.value = text.value\n editing.value = true\n void nextTick(() => {\n const el = editorRef.value\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n fitEditor()\n })\n}\nfunction cancelEdit() {\n editing.value = false\n}\nfunction saveEdit() {\n if (!draft.value.trim()) return\n editing.value = false\n emit('edit', draft.value)\n}\nfunction fitEditor() {\n const el = editorRef.value\n if (!el) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nfunction onEditorKeydown(event: KeyboardEvent) {\n if (event.key === 'Escape') {\n event.preventDefault()\n cancelEdit()\n } else if (event.key === 'Enter' && !event.shiftKey && !isComposing(event)) {\n event.preventDefault()\n saveEdit()\n }\n}\n\nconst asText = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'text' }>\nconst asReasoning = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'reasoning' }>\nconst asFiles = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'files' }>\nconst asConfirm = (part: AnyPart) => part as ChatConfirmPart\nconst asArtifact = (part: AnyPart) => part as ChatArtifactPart\nconst asQuestion = (part: AnyPart) => part as ChatQuestionPart\nconst known = new Set([\n 'text',\n 'reasoning',\n 'tool',\n 'steps',\n 'plan',\n 'sources',\n 'files',\n 'artifact',\n 'confirm',\n 'question',\n])\n// props for the part components, without the `type` discriminator\nconst rest = (part: AnyPart) => {\n const { type: _type, ...others } = part as Record<string, unknown>\n return others\n}\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.m(sender),\n ns.m(`actions-${actionsShow}`),\n ns.is('loading', loading),\n ns.is('editing', editing),\n ns.is('highlighted', highlighted),\n ]\"\n :aria-busy=\"busy || undefined\"\n :aria-current=\"highlighted || undefined\"\n >\n <div v-if=\"files.length && !editing\" :class=\"ns.e('files')\">\n <template v-for=\"(part, index) in files\" :key=\"`f${index}`\">\n <DouChatAttachments :model-value=\"asFiles(part).files\" :removable=\"false\" />\n </template>\n </div>\n\n <div v-if=\"editing\" :class=\"ns.e('editor')\">\n <textarea\n ref=\"editor\"\n v-model=\"draft\"\n :class=\"ns.e('editor-native')\"\n rows=\"1\"\n :aria-label=\"t('chat.edit')\"\n @input=\"fitEditor\"\n @keydown=\"onEditorKeydown\"\n />\n <div :class=\"ns.e('editor-actions')\">\n <DouButton size=\"sm\" variant=\"ghost\" @click=\"cancelEdit\">{{ t('chat.cancel') }}</DouButton>\n <DouButton size=\"sm\" :disabled=\"!draft.trim()\" @click=\"saveEdit\">\n {{ t('chat.send') }}\n </DouButton>\n </div>\n </div>\n\n <div v-else-if=\"body.length || loading || slots.default\" :class=\"ns.e('content')\">\n <slot>\n <template v-for=\"(part, index) in body\" :key=\"index\">\n <DouMarkdown\n v-if=\"part.type === 'text' && markdown && !slots.text\"\n v-bind=\"markdownOptions\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n :sources=\"sources.length ? sources : undefined\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else-if=\"part.type === 'text'\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n >\n <template v-if=\"slots.text\" #default=\"{ text: shown }\">\n <slot\n name=\"text\"\n :part=\"asText(part)\"\n :text=\"shown\"\n :index=\"index\"\n :sources=\"sources\"\n />\n </template>\n </DouStreamText>\n <DouChatReasoning\n v-else-if=\"part.type === 'reasoning'\"\n :thinking=\"!!asReasoning(part).thinking\"\n :duration=\"asReasoning(part).duration\"\n >\n <DouMarkdown\n v-if=\"markdown\"\n v-bind=\"markdownOptions\"\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n />\n </DouChatReasoning>\n <DouChatToolCall v-else-if=\"part.type === 'tool'\" v-bind=\"rest(part)\" />\n <DouChatSteps v-else-if=\"part.type === 'steps'\" v-bind=\"rest(part)\" />\n <DouChatPlan v-else-if=\"part.type === 'plan'\" v-bind=\"rest(part)\" />\n <DouChatSources v-else-if=\"part.type === 'sources'\" v-bind=\"rest(part)\" />\n <DouChatAttachments\n v-else-if=\"part.type === 'files'\"\n :model-value=\"asFiles(part).files\"\n :removable=\"false\"\n />\n <DouChatArtifact\n v-else-if=\"part.type === 'artifact'\"\n v-bind=\"rest(part)\"\n @open=\"emit('artifact', asArtifact(part))\"\n />\n <DouChatConfirm\n v-else-if=\"part.type === 'confirm'\"\n :title=\"asConfirm(part).title\"\n :description=\"asConfirm(part).description\"\n :status=\"asConfirm(part).status\"\n :allow-always=\"asConfirm(part).allowAlways\"\n :tone=\"asConfirm(part).tone\"\n @decide=\"emit('confirm', asConfirm(part), $event)\"\n >\n <pre v-if=\"asConfirm(part).detail\" :class=\"ns.e('code')\">{{\n asConfirm(part).detail\n }}</pre>\n </DouChatConfirm>\n <DouChatQuestion\n v-else-if=\"part.type === 'question'\"\n :title=\"asQuestion(part).title\"\n :description=\"asQuestion(part).description\"\n :options=\"asQuestion(part).options\"\n :status=\"asQuestion(part).status\"\n :answer=\"asQuestion(part).answer\"\n @select=\"(value, option) => emit('question', asQuestion(part), value, option)\"\n />\n <slot\n v-else-if=\"!known.has(part.type)\"\n name=\"part\"\n :part=\"part as ChatCustomPart\"\n :index=\"index\"\n />\n </template>\n </slot>\n <span v-if=\"loading\" :class=\"ns.e('loading')\" role=\"status\" :aria-label=\"t('chat.loading')\">\n <i /><i /><i />\n </span>\n </div>\n\n <div v-if=\"showActions && !editing\" :class=\"ns.e('actions')\">\n <div\n v-if=\"versions > 1\"\n :class=\"ns.e('versions')\"\n role=\"group\"\n :aria-label=\"t('chat.versions')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version <= 1\"\n :aria-label=\"t('chat.previousVersion')\"\n @click=\"step(-1)\"\n >\n <ChevronLeftIcon />\n </DouButton>\n <span :class=\"ns.e('version')\">{{ version }} / {{ versions }}</span>\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version >= versions\"\n :aria-label=\"t('chat.nextVersion')\"\n @click=\"step(1)\"\n >\n <ChevronRightIcon />\n </DouButton>\n </div>\n <DouCopyButton v-if=\"copyable && text\" size=\"sm\" :text=\"text\" />\n <DouTooltip v-if=\"editable && isUser\" :content=\"t('chat.edit')\">\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('chat.edit')\" @click=\"startEdit\">\n <EditIcon />\n </DouButton>\n </DouTooltip>\n <slot name=\"actions\" />\n </div>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"chat-message2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-message/chat-message.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronLeftIcon, ChevronRightIcon, EditIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useTemplateRef } from 'vue'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouButton } from '../button'\nimport { DouChatArtifact } from '../chat-artifact'\nimport { DouChatAttachments } from '../chat-attachments'\nimport { DouChatConfirm } from '../chat-confirm'\nimport { DouChatQuestion } from '../chat-question'\nimport { DouChatPlan } from '../chat-plan'\nimport { planRunning, type ChatPlanItem } from '../chat-plan/chat-plan'\nimport { DouChatReasoning } from '../chat-reasoning'\nimport { DouChatSources } from '../chat-sources'\nimport { DouChatSteps } from '../chat-steps'\nimport { stepsLive, type ChatStep } from '../chat-steps/chat-steps'\nimport { DouChatToolCall } from '../chat-tool-call'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport { DouMarkdown } from '../markdown'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport { DouStreamText } from '../stream-text'\nimport { DouTooltip } from '../tooltip'\nimport { messageText } from './chat-message'\nimport type {\n ChatArtifactPart,\n ChatConfirmPart,\n ChatQuestionPart,\n ChatCustomPart,\n ChatMessageEmits,\n ChatMessagePart,\n ChatMessageMarkdownSlots,\n ChatMessageProps,\n ChatMessageSlots,\n} from './chat-message'\n\ndefineOptions({ name: 'DouChatMessage' })\n\nconst props = withDefaults(defineProps<ChatMessageProps>(), {\n sender: 'assistant',\n loading: false,\n copyable: true,\n editable: false,\n markdown: false,\n actionsVisible: undefined,\n versions: 1,\n version: undefined,\n})\nconst emit = defineEmits<ChatMessageEmits>()\nconst slots = defineSlots<ChatMessageSlots & ChatMessageMarkdownSlots>()\n\nconst ns = useNamespace('chat-message')\nconst { t } = useLocale()\n\ntype AnyPart = ChatMessagePart | ChatCustomPart\n\nconst parts = computed<AnyPart[]>(\n () => props.parts ?? (props.content === undefined ? [] : [{ type: 'text', text: props.content }]),\n)\nconst markdownOptions = computed(() =>\n typeof props.markdown === 'object' ? props.markdown : undefined,\n)\n// `markdown-code` here is the Markdown component's `code`\nconst PREFIX = 'markdown-'\nconst markdownSlots = () =>\n Object.keys(slots)\n // the message's own `trailing` goes to its last text, not to every Markdown in it\n .filter((name) => name.startsWith(PREFIX) && name !== `${PREFIX}trailing`)\n .map((name) => ({\n name: name as keyof ChatMessageMarkdownSlots,\n inner: name.slice(PREFIX.length),\n }))\nconst isUser = computed(() => props.sender === 'user')\nconst actionsShow = computed(() => props.actionsVisible ?? (isUser.value ? 'hover' : 'always'))\n// the person's attachments sit above their bubble, not inside it\nconst files = computed(() => (isUser.value ? parts.value.filter((p) => p.type === 'files') : []))\nconst body = computed(() =>\n isUser.value ? parts.value.filter((p) => p.type !== 'files') : parts.value,\n)\nconst text = computed(() => messageText(parts.value as { type: string; text?: unknown }[]))\n/** The last text part, which the `trailing` slot follows; -1 without one. */\nconst lastText = computed(() => {\n for (let i = body.value.length - 1; i >= 0; i--) if (body.value[i]!.type === 'text') return i\n return -1\n})\n// Every source of the message, numbered in order, for `[1]` in Markdown\n// text. The same array while the sources stay the same, so text that\n// streams in does not redraw the whole reply.\nlet lastSources: ChatSource[] = []\nconst sources = computed(() => {\n const next = parts.value.flatMap((part) =>\n part.type === 'sources' ? ((part as { items?: ChatSource[] }).items ?? []) : [],\n )\n if (next.length === lastSources.length && next.every((s, i) => s === lastSources[i]))\n return lastSources\n return (lastSources = next)\n})\n\nconst busy = computed(\n () =>\n props.loading ||\n parts.value.some((part) => {\n const p = part as Record<string, unknown>\n // an artifact can keep being made after the reply ends, so it doesn't hold the actions back\n const working = p.status === 'running' && p.type !== 'artifact' && p.live !== false\n // busy exactly when steps or a plan show themselves running\n const live = p.live as boolean | undefined\n const steps = p.type === 'steps' && stepsLive(p.items as ChatStep[] | undefined, live)\n const plan = p.type === 'plan' && planRunning(p.items as ChatPlanItem[] | undefined, live)\n return !!p.streaming || !!p.thinking || steps || plan || working\n }),\n)\n\nconst innerVersion = ref(props.versions)\nconst version = computed(() => Math.min(props.version ?? innerVersion.value, props.versions))\nfunction step(delta: number) {\n const next = Math.min(Math.max(version.value + delta, 1), props.versions)\n innerVersion.value = next\n emit('update:version', next)\n}\n\nconst showActions = computed(\n () =>\n !busy.value &&\n (props.versions > 1 ||\n (props.copyable && !!text.value) ||\n (props.editable && isUser.value) ||\n !!slots.actions),\n)\n\n// editing in place\nconst editing = ref(false)\nconst draft = ref('')\nconst editorRef = useTemplateRef<HTMLTextAreaElement>('editor')\nfunction startEdit() {\n draft.value = text.value\n editing.value = true\n void nextTick(() => {\n const el = editorRef.value\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n fitEditor()\n })\n}\nfunction cancelEdit() {\n editing.value = false\n}\nfunction saveEdit() {\n if (!draft.value.trim()) return\n editing.value = false\n emit('edit', draft.value)\n}\nfunction fitEditor() {\n const el = editorRef.value\n if (!el) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nfunction onEditorKeydown(event: KeyboardEvent) {\n if (event.key === 'Escape') {\n event.preventDefault()\n cancelEdit()\n } else if (event.key === 'Enter' && !event.shiftKey && !isComposing(event)) {\n event.preventDefault()\n saveEdit()\n }\n}\n\nconst asText = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'text' }>\nconst asReasoning = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'reasoning' }>\nconst asFiles = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'files' }>\nconst asConfirm = (part: AnyPart) => part as ChatConfirmPart\nconst asArtifact = (part: AnyPart) => part as ChatArtifactPart\nconst asQuestion = (part: AnyPart) => part as ChatQuestionPart\nconst known = new Set([\n 'text',\n 'reasoning',\n 'tool',\n 'steps',\n 'plan',\n 'sources',\n 'files',\n 'artifact',\n 'confirm',\n 'question',\n])\n// props for the part components, without the `type` discriminator\nconst rest = (part: AnyPart) => {\n const { type: _type, ...others } = part as Record<string, unknown>\n return others\n}\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.m(sender),\n ns.m(`actions-${actionsShow}`),\n ns.is('loading', loading),\n ns.is('editing', editing),\n ns.is('highlighted', highlighted),\n ]\"\n :aria-busy=\"busy || undefined\"\n :aria-current=\"highlighted || undefined\"\n >\n <div v-if=\"files.length && !editing\" :class=\"ns.e('files')\">\n <template v-for=\"(part, index) in files\" :key=\"`f${index}`\">\n <DouChatAttachments :model-value=\"asFiles(part).files\" :removable=\"false\" />\n </template>\n </div>\n\n <div v-if=\"editing\" :class=\"ns.e('editor')\">\n <textarea\n ref=\"editor\"\n v-model=\"draft\"\n :class=\"ns.e('editor-native')\"\n rows=\"1\"\n :aria-label=\"t('chat.edit')\"\n @input=\"fitEditor\"\n @keydown=\"onEditorKeydown\"\n />\n <div :class=\"ns.e('editor-actions')\">\n <DouButton size=\"sm\" variant=\"ghost\" @click=\"cancelEdit\">{{ t('chat.cancel') }}</DouButton>\n <DouButton size=\"sm\" :disabled=\"!draft.trim()\" @click=\"saveEdit\">\n {{ t('chat.send') }}\n </DouButton>\n </div>\n </div>\n\n <div v-else-if=\"body.length || loading || slots.default\" :class=\"ns.e('content')\">\n <slot>\n <template v-for=\"(part, index) in body\" :key=\"index\">\n <DouMarkdown\n v-if=\"part.type === 'text' && markdown && !slots.text\"\n v-bind=\"markdownOptions\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n :sources=\"sources.length ? sources : undefined\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n <template v-if=\"slots.trailing && index === lastText\" #trailing>\n <slot name=\"trailing\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else-if=\"part.type === 'text'\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n >\n <template v-if=\"slots.text\" #default=\"{ text: shown }\">\n <slot\n name=\"text\"\n :part=\"asText(part)\"\n :text=\"shown\"\n :index=\"index\"\n :sources=\"sources\"\n />\n </template>\n <template v-if=\"slots.trailing && index === lastText\" #trailing>\n <slot name=\"trailing\" />\n </template>\n </DouStreamText>\n <DouChatReasoning\n v-else-if=\"part.type === 'reasoning'\"\n :thinking=\"!!asReasoning(part).thinking\"\n :duration=\"asReasoning(part).duration\"\n >\n <DouMarkdown\n v-if=\"markdown\"\n v-bind=\"markdownOptions\"\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n />\n </DouChatReasoning>\n <DouChatToolCall v-else-if=\"part.type === 'tool'\" v-bind=\"rest(part)\" />\n <DouChatSteps v-else-if=\"part.type === 'steps'\" v-bind=\"rest(part)\" />\n <DouChatPlan v-else-if=\"part.type === 'plan'\" v-bind=\"rest(part)\" />\n <DouChatSources v-else-if=\"part.type === 'sources'\" v-bind=\"rest(part)\" />\n <DouChatAttachments\n v-else-if=\"part.type === 'files'\"\n :model-value=\"asFiles(part).files\"\n :removable=\"false\"\n />\n <DouChatArtifact\n v-else-if=\"part.type === 'artifact'\"\n v-bind=\"rest(part)\"\n @open=\"emit('artifact', asArtifact(part))\"\n />\n <DouChatConfirm\n v-else-if=\"part.type === 'confirm'\"\n :title=\"asConfirm(part).title\"\n :description=\"asConfirm(part).description\"\n :status=\"asConfirm(part).status\"\n :allow-always=\"asConfirm(part).allowAlways\"\n :tone=\"asConfirm(part).tone\"\n @decide=\"emit('confirm', asConfirm(part), $event)\"\n >\n <pre v-if=\"asConfirm(part).detail\" :class=\"ns.e('code')\">{{\n asConfirm(part).detail\n }}</pre>\n </DouChatConfirm>\n <DouChatQuestion\n v-else-if=\"part.type === 'question'\"\n :title=\"asQuestion(part).title\"\n :description=\"asQuestion(part).description\"\n :options=\"asQuestion(part).options\"\n :status=\"asQuestion(part).status\"\n :answer=\"asQuestion(part).answer\"\n @select=\"(value, option) => emit('question', asQuestion(part), value, option)\"\n />\n <slot\n v-else-if=\"!known.has(part.type)\"\n name=\"part\"\n :part=\"part as ChatCustomPart\"\n :index=\"index\"\n />\n </template>\n <div v-if=\"slots.trailing && lastText < 0 && !loading\" :class=\"ns.e('trailing')\">\n <slot name=\"trailing\" />\n </div>\n </slot>\n <span v-if=\"loading\" :class=\"ns.e('loading')\" role=\"status\" :aria-label=\"t('chat.loading')\">\n <i /><i /><i />\n </span>\n </div>\n\n <div v-if=\"showActions && !editing\" :class=\"ns.e('actions')\">\n <div\n v-if=\"versions > 1\"\n :class=\"ns.e('versions')\"\n role=\"group\"\n :aria-label=\"t('chat.versions')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version <= 1\"\n :aria-label=\"t('chat.previousVersion')\"\n @click=\"step(-1)\"\n >\n <ChevronLeftIcon />\n </DouButton>\n <span :class=\"ns.e('version')\">{{ version }} / {{ versions }}</span>\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version >= versions\"\n :aria-label=\"t('chat.nextVersion')\"\n @click=\"step(1)\"\n >\n <ChevronRightIcon />\n </DouButton>\n </div>\n <DouCopyButton v-if=\"copyable && text\" size=\"sm\" :text=\"text\" />\n <DouTooltip v-if=\"editable && isUser\" :content=\"t('chat.edit')\">\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('chat.edit')\" @click=\"startEdit\">\n <EditIcon />\n </DouButton>\n </DouTooltip>\n <slot name=\"actions\" />\n </div>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","names":["_sfc_main"],"sources":["../../../src/components/markdown/markdown.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {
|
|
1
|
+
{"version":3,"file":"markdown.js","names":["_sfc_main"],"sources":["../../../src/components/markdown/markdown.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n h,\n onBeforeUnmount,\n onMounted,\n provide,\n ref,\n shallowRef,\n watch,\n type VNode,\n} from 'vue'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useNamespace } from '../../utils/namespace'\nimport { safeCut } from '../stream-text/stream-text'\nimport type {\n MarkdownBlock,\n MarkdownEmits,\n MarkdownExpose,\n MarkdownProps,\n MarkdownSlots,\n} from './markdown'\nimport { createMarkdownParser } from './parser'\nimport {\n markdownContextKey,\n MarkdownChunkView,\n type MarkdownCommit,\n type MarkdownRenderContext,\n} from './render'\nimport { defaultSanitizeUrl } from './url'\n\ndefineOptions({ name: 'DouMarkdown' })\n\nconst props = withDefaults(defineProps<MarkdownProps>(), {\n content: '',\n streaming: false,\n smooth: true,\n speed: 40,\n caret: true,\n linkTarget: '_blank',\n})\nconst emit = defineEmits<MarkdownEmits>()\nconst slots = defineSlots<MarkdownSlots>()\n\nconst ns = useNamespace('markdown')\nconst reducedMotion = useReducedMotion()\n\n/** The fade of new content; the same as the `--dou-motion-duration-slow` token. */\nconst FADE = 320\n/** Blocks per chunk: a chunk that is complete is skipped as a whole. */\nconst CHUNK = 32\n\nconst parser = createMarkdownParser()\n// How much of `content` is shown, in UTF-16 units. What is there at mount shows at once.\nconst shown = ref(props.content.length)\nlet committed = props.content.length\nlet committedText = props.content\nlet committedFinal = !props.streaming\nconst blocks = shallowRef<MarkdownBlock[]>(parser.update(props.content, { final: committedFinal }))\nconst tick = ref(0)\n\nconst commits: MarkdownCommit[] = []\nconst ctx: MarkdownRenderContext = {\n get streaming() {\n return props.streaming\n },\n get sources() {\n return props.sources\n },\n get linkTarget() {\n return props.linkTarget\n },\n slots,\n sanitize: (url, kind) => (props.sanitizeUrl ?? defaultSanitizeUrl)(url, kind),\n commits,\n duration: FADE,\n now: 0,\n delays: new Map(),\n caret: null,\n end: null,\n drawing: null,\n fading: new Set(),\n}\nprovide(markdownContextKey, ctx)\n\nlet mounted = false\nconst animate = () => mounted && props.smooth && !reducedMotion.value\n\n/** The last leaf, where the caret and the `trailing` slot go. */\nfunction caretTarget(list: MarkdownBlock[]): object | null {\n let node: MarkdownBlock | MarkdownBlock[] | undefined = list[list.length - 1]\n for (;;) {\n if (!node) return null\n if (Array.isArray(node)) node = node[node.length - 1]\n else if (node.type === 'blockquote' || node.type === 'container')\n node = node.children[node.children.length - 1]\n else if (node.type === 'list') {\n const item = node.children[node.children.length - 1]\n if (!item) return null\n const child = item.children[item.children.length - 1]\n if (!child) return item\n node = child\n } else if (node.type === 'table') return node.rows[node.rows.length - 1] ?? node.head\n else if (node.type === 'paragraph' || node.type === 'heading') return node\n else return null\n }\n}\n\n// complete chunks are kept, so the same array goes back to the same component\nlet chunks: MarkdownBlock[][] = []\nfunction chunkOf(list: MarkdownBlock[]): MarkdownBlock[][] {\n const next: MarkdownBlock[][] = []\n for (let from = 0; from < list.length; from += CHUNK) {\n const index = from / CHUNK\n const prev = chunks[index]\n const to = Math.min(from + CHUNK, list.length)\n if (prev && prev.length === to - from && prev.every((block, i) => block === list[from + i]))\n next.push(prev)\n else next.push(list.slice(from, to))\n }\n chunks = next\n return next\n}\nconst chunked = shallowRef(chunkOf(blocks.value))\n\nlet cleanup: ReturnType<typeof setTimeout> | undefined\nfunction commit(now: number) {\n const final = !props.streaming && shown.value >= props.content.length\n if (animate() && shown.value > committed) commits.push({ from: committed, time: now })\n // fades that are over need no span any more\n let ended = false\n while (commits.length && now - commits[0]!.time >= FADE) {\n const old = commits.shift()!\n ended = true\n for (const key of ctx.delays.keys()) if (key.endsWith(`:${old.from}`)) ctx.delays.delete(key)\n }\n if (ended) {\n // blocks that are finished are not drawn again by themselves\n for (const block of ctx.fading) if (!block.isUnmounted) block.proxy?.$forceUpdate()\n ctx.fading.clear()\n }\n committedText = props.content.slice(0, shown.value)\n committed = shown.value\n committedFinal = final\n ctx.now = now\n blocks.value = parser.update(committedText, { final })\n chunked.value = chunkOf(blocks.value)\n tick.value++\n clearTimeout(cleanup)\n // one more render once the last fade ends, to merge its spans back into text\n if (commits.length) cleanup = setTimeout(() => commit(performance.now()), FADE + 20)\n}\n\nlet frame = 0\nlet last = 0\nlet carry = 0\nfunction step(now: number) {\n frame = 0\n const total = props.content.length\n if (animate()) {\n const elapsed = last ? Math.min(now - last, 100) : 16\n last = now\n const backlog = total - shown.value\n // at least `speed`, and fast enough to catch up in a moment\n const rate = Math.max(props.speed, backlog / (props.streaming ? 0.4 : 0.25))\n carry += (rate * elapsed) / 1000\n const advance = Math.floor(carry)\n if (advance > 0) {\n carry -= advance\n shown.value = safeCut(props.content, Math.min(total, shown.value + advance))\n }\n } else shown.value = total\n const final = !props.streaming && shown.value >= total\n if (shown.value !== committed || final !== committedFinal) commit(now)\n if (shown.value < total) frame = requestAnimationFrame(step)\n else last = 0\n}\n\nfunction schedule() {\n if (!mounted || typeof requestAnimationFrame === 'undefined') {\n shown.value = props.content.length\n commit(0)\n return\n }\n if (!frame) frame = requestAnimationFrame(step)\n}\n\nfunction flush() {\n if (frame) cancelAnimationFrame(frame)\n frame = 0\n last = 0\n carry = 0\n shown.value = props.content.length\n commit(typeof performance === 'undefined' ? 0 : performance.now())\n}\n\nwatch(\n () => props.content,\n (value) => {\n // replaced rather than extended: keep what still matches\n if (!value.startsWith(committedText)) {\n let common = 0\n const limit = Math.min(value.length, committedText.length)\n while (common < limit && value.charCodeAt(common) === committedText.charCodeAt(common))\n common++\n shown.value = safeCut(value, common)\n committed = Math.min(committed, shown.value)\n while (commits.length && commits[commits.length - 1]!.from >= shown.value) commits.pop()\n }\n schedule()\n },\n)\nwatch(() => props.streaming, schedule)\nwatch(\n () => props.smooth,\n (smooth) => {\n if (!smooth) flush()\n },\n)\n\nconst done = computed(() => !props.streaming && shown.value >= props.content.length)\nwatch(done, (value) => {\n if (value) emit('done')\n})\n\nonMounted(() => {\n mounted = true\n})\nonBeforeUnmount(() => {\n if (frame) cancelAnimationFrame(frame)\n clearTimeout(cleanup)\n})\n\ndefineExpose<MarkdownExpose>({ flush })\n\n// Renders the blocks. The caret target is set here, untracked, so that\n// moving the caret does not re-render every block that checks for it.\nfunction Body() {\n ctx.drawing = null\n const target = caretTarget(blocks.value)\n ctx.caret = props.caret && !done.value ? target : null\n ctx.end = slots.trailing ? target : null\n const list = chunked.value\n // the last chunk draws again when the `trailing` slot comes or goes\n const lastTick = tick.value * 2 + (slots.trailing ? 1 : 0)\n const children = list.map((chunk, index) =>\n h(MarkdownChunkView, {\n key: index,\n blocks: chunk,\n tick: index === list.length - 1 ? lastTick : 0,\n }),\n )\n if (props.caret && !done.value && !target)\n children.push(h('span', { key: 'caret', class: ns.e('caret'), 'aria-hidden': 'true' }))\n // after a code block or a rule, nothing to follow on the same line: a line of its own\n if (slots.trailing && !target)\n children.push(\n h('div', { key: 'trailing', class: ns.e('trailing') }, slots.trailing() as VNode[]),\n )\n return children\n}\n</script>\n\n<template>\n <div :class=\"[ns.b(), ns.is('streaming', !done)]\" :aria-busy=\"done ? undefined : 'true'\">\n <Body />\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -65,13 +65,14 @@ var markdown_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
|
|
|
65
65
|
now: 0,
|
|
66
66
|
delays: /* @__PURE__ */ new Map(),
|
|
67
67
|
caret: null,
|
|
68
|
+
end: null,
|
|
68
69
|
drawing: null,
|
|
69
70
|
fading: /* @__PURE__ */ new Set()
|
|
70
71
|
};
|
|
71
72
|
provide(markdownContextKey, ctx);
|
|
72
73
|
let mounted = false;
|
|
73
74
|
const animate = () => mounted && props.smooth && !reducedMotion.value;
|
|
74
|
-
/** The last leaf, where the caret
|
|
75
|
+
/** The last leaf, where the caret and the `trailing` slot go. */
|
|
75
76
|
function caretTarget(list) {
|
|
76
77
|
let node = list[list.length - 1];
|
|
77
78
|
for (;;) {
|
|
@@ -198,18 +199,25 @@ var markdown_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
|
|
|
198
199
|
__expose({ flush });
|
|
199
200
|
function Body() {
|
|
200
201
|
ctx.drawing = null;
|
|
201
|
-
|
|
202
|
+
const target = caretTarget(blocks.value);
|
|
203
|
+
ctx.caret = props.caret && !done.value ? target : null;
|
|
204
|
+
ctx.end = slots.trailing ? target : null;
|
|
202
205
|
const list = chunked.value;
|
|
206
|
+
const lastTick = tick.value * 2 + (slots.trailing ? 1 : 0);
|
|
203
207
|
const children = list.map((chunk, index) => h(MarkdownChunkView, {
|
|
204
208
|
key: index,
|
|
205
209
|
blocks: chunk,
|
|
206
|
-
tick: index === list.length - 1 ?
|
|
210
|
+
tick: index === list.length - 1 ? lastTick : 0
|
|
207
211
|
}));
|
|
208
|
-
if (props.caret && !done.value && !
|
|
212
|
+
if (props.caret && !done.value && !target) children.push(h("span", {
|
|
209
213
|
key: "caret",
|
|
210
214
|
class: ns.e("caret"),
|
|
211
215
|
"aria-hidden": "true"
|
|
212
216
|
}));
|
|
217
|
+
if (slots.trailing && !target) children.push(h("div", {
|
|
218
|
+
key: "trailing",
|
|
219
|
+
class: ns.e("trailing")
|
|
220
|
+
}, slots.trailing()));
|
|
213
221
|
return children;
|
|
214
222
|
}
|
|
215
223
|
return (_ctx, _cache) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createVNode"],"sources":["../../../src/components/markdown/markdown.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, h, onBeforeUnmount, onMounted, provide, ref, shallowRef, watch } from 'vue'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useNamespace } from '../../utils/namespace'\nimport { safeCut } from '../stream-text/stream-text'\nimport type {\n MarkdownBlock,\n MarkdownEmits,\n MarkdownExpose,\n MarkdownProps,\n MarkdownSlots,\n} from './markdown'\nimport { createMarkdownParser } from './parser'\nimport {\n markdownContextKey,\n MarkdownChunkView,\n type MarkdownCommit,\n type MarkdownRenderContext,\n} from './render'\nimport { defaultSanitizeUrl } from './url'\n\ndefineOptions({ name: 'DouMarkdown' })\n\nconst props = withDefaults(defineProps<MarkdownProps>(), {\n content: '',\n streaming: false,\n smooth: true,\n speed: 40,\n caret: true,\n linkTarget: '_blank',\n})\nconst emit = defineEmits<MarkdownEmits>()\nconst slots = defineSlots<MarkdownSlots>()\n\nconst ns = useNamespace('markdown')\nconst reducedMotion = useReducedMotion()\n\n/** The fade of new content; the same as the `--dou-motion-duration-slow` token. */\nconst FADE = 320\n/** Blocks per chunk: a chunk that is complete is skipped as a whole. */\nconst CHUNK = 32\n\nconst parser = createMarkdownParser()\n// How much of `content` is shown, in UTF-16 units. What is there at mount shows at once.\nconst shown = ref(props.content.length)\nlet committed = props.content.length\nlet committedText = props.content\nlet committedFinal = !props.streaming\nconst blocks = shallowRef<MarkdownBlock[]>(parser.update(props.content, { final: committedFinal }))\nconst tick = ref(0)\n\nconst commits: MarkdownCommit[] = []\nconst ctx: MarkdownRenderContext = {\n get streaming() {\n return props.streaming\n },\n get sources() {\n return props.sources\n },\n get linkTarget() {\n return props.linkTarget\n },\n slots,\n sanitize: (url, kind) => (props.sanitizeUrl ?? defaultSanitizeUrl)(url, kind),\n commits,\n duration: FADE,\n now: 0,\n delays: new Map(),\n caret: null,\n drawing: null,\n fading: new Set(),\n}\nprovide(markdownContextKey, ctx)\n\nlet mounted = false\nconst animate = () => mounted && props.smooth && !reducedMotion.value\n\n/** The last leaf, where the caret goes. */\nfunction caretTarget(list: MarkdownBlock[]): object | null {\n let node: MarkdownBlock | MarkdownBlock[] | undefined = list[list.length - 1]\n for (;;) {\n if (!node) return null\n if (Array.isArray(node)) node = node[node.length - 1]\n else if (node.type === 'blockquote' || node.type === 'container')\n node = node.children[node.children.length - 1]\n else if (node.type === 'list') {\n const item = node.children[node.children.length - 1]\n if (!item) return null\n const child = item.children[item.children.length - 1]\n if (!child) return item\n node = child\n } else if (node.type === 'table') return node.rows[node.rows.length - 1] ?? node.head\n else if (node.type === 'paragraph' || node.type === 'heading') return node\n else return null\n }\n}\n\n// complete chunks are kept, so the same array goes back to the same component\nlet chunks: MarkdownBlock[][] = []\nfunction chunkOf(list: MarkdownBlock[]): MarkdownBlock[][] {\n const next: MarkdownBlock[][] = []\n for (let from = 0; from < list.length; from += CHUNK) {\n const index = from / CHUNK\n const prev = chunks[index]\n const to = Math.min(from + CHUNK, list.length)\n if (prev && prev.length === to - from && prev.every((block, i) => block === list[from + i]))\n next.push(prev)\n else next.push(list.slice(from, to))\n }\n chunks = next\n return next\n}\nconst chunked = shallowRef(chunkOf(blocks.value))\n\nlet cleanup: ReturnType<typeof setTimeout> | undefined\nfunction commit(now: number) {\n const final = !props.streaming && shown.value >= props.content.length\n if (animate() && shown.value > committed) commits.push({ from: committed, time: now })\n // fades that are over need no span any more\n let ended = false\n while (commits.length && now - commits[0]!.time >= FADE) {\n const old = commits.shift()!\n ended = true\n for (const key of ctx.delays.keys()) if (key.endsWith(`:${old.from}`)) ctx.delays.delete(key)\n }\n if (ended) {\n // blocks that are finished are not drawn again by themselves\n for (const block of ctx.fading) if (!block.isUnmounted) block.proxy?.$forceUpdate()\n ctx.fading.clear()\n }\n committedText = props.content.slice(0, shown.value)\n committed = shown.value\n committedFinal = final\n ctx.now = now\n blocks.value = parser.update(committedText, { final })\n chunked.value = chunkOf(blocks.value)\n tick.value++\n clearTimeout(cleanup)\n // one more render once the last fade ends, to merge its spans back into text\n if (commits.length) cleanup = setTimeout(() => commit(performance.now()), FADE + 20)\n}\n\nlet frame = 0\nlet last = 0\nlet carry = 0\nfunction step(now: number) {\n frame = 0\n const total = props.content.length\n if (animate()) {\n const elapsed = last ? Math.min(now - last, 100) : 16\n last = now\n const backlog = total - shown.value\n // at least `speed`, and fast enough to catch up in a moment\n const rate = Math.max(props.speed, backlog / (props.streaming ? 0.4 : 0.25))\n carry += (rate * elapsed) / 1000\n const advance = Math.floor(carry)\n if (advance > 0) {\n carry -= advance\n shown.value = safeCut(props.content, Math.min(total, shown.value + advance))\n }\n } else shown.value = total\n const final = !props.streaming && shown.value >= total\n if (shown.value !== committed || final !== committedFinal) commit(now)\n if (shown.value < total) frame = requestAnimationFrame(step)\n else last = 0\n}\n\nfunction schedule() {\n if (!mounted || typeof requestAnimationFrame === 'undefined') {\n shown.value = props.content.length\n commit(0)\n return\n }\n if (!frame) frame = requestAnimationFrame(step)\n}\n\nfunction flush() {\n if (frame) cancelAnimationFrame(frame)\n frame = 0\n last = 0\n carry = 0\n shown.value = props.content.length\n commit(typeof performance === 'undefined' ? 0 : performance.now())\n}\n\nwatch(\n () => props.content,\n (value) => {\n // replaced rather than extended: keep what still matches\n if (!value.startsWith(committedText)) {\n let common = 0\n const limit = Math.min(value.length, committedText.length)\n while (common < limit && value.charCodeAt(common) === committedText.charCodeAt(common))\n common++\n shown.value = safeCut(value, common)\n committed = Math.min(committed, shown.value)\n while (commits.length && commits[commits.length - 1]!.from >= shown.value) commits.pop()\n }\n schedule()\n },\n)\nwatch(() => props.streaming, schedule)\nwatch(\n () => props.smooth,\n (smooth) => {\n if (!smooth) flush()\n },\n)\n\nconst done = computed(() => !props.streaming && shown.value >= props.content.length)\nwatch(done, (value) => {\n if (value) emit('done')\n})\n\nonMounted(() => {\n mounted = true\n})\nonBeforeUnmount(() => {\n if (frame) cancelAnimationFrame(frame)\n clearTimeout(cleanup)\n})\n\ndefineExpose<MarkdownExpose>({ flush })\n\n// Renders the blocks. The caret target is set here, untracked, so that\n// moving the caret does not re-render every block that checks for it.\nfunction Body() {\n ctx.drawing = null\n ctx.caret = props.caret && !done.value ? caretTarget(blocks.value) : null\n const list = chunked.value\n const children = list.map((chunk, index) =>\n h(MarkdownChunkView, {\n key: index,\n blocks: chunk,\n tick: index === list.length - 1 ? tick.value : 0,\n }),\n )\n if (props.caret && !done.value && !ctx.caret)\n children.push(h('span', { key: 'caret', class: ns.e('caret'), 'aria-hidden': 'true' }))\n return children\n}\n</script>\n\n<template>\n <div :class=\"[ns.b(), ns.is('streaming', !done)]\" :aria-busy=\"done ? undefined : 'true'\">\n <Body />\n </div>\n</template>\n"],"mappings":";;;;;;;;;AAsCA,IAAM,OAAO;;AAEb,IAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;EAjBd,MAAM,QAAQ;EAQd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,UAAU;EAClC,MAAM,gBAAgB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;IAAE,KAAK;IAAS,OAAO,GAAG,EAAE,OAAO;IAAG,eAAe;GAAO,CAAC,CAAC;GACxF,OAAO;EACT;;GAIE,OAAAC,UAAA,GAAAC,mBAEM,OAAA;IAFA,OAAKC,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,GAAIA,MAAA,EAAA,CAAE,CAAC,GAAE,aAAA,CAAe,KAAA,KAAI,CAAA,CAAA;IAAK,aAAW,KAAA,QAAO,KAAA,IAAS;G,IAC5EC,YAAQ,IAAA,C"}
|
|
1
|
+
{"version":3,"file":"markdown.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createVNode"],"sources":["../../../src/components/markdown/markdown.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n h,\n onBeforeUnmount,\n onMounted,\n provide,\n ref,\n shallowRef,\n watch,\n type VNode,\n} from 'vue'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useNamespace } from '../../utils/namespace'\nimport { safeCut } from '../stream-text/stream-text'\nimport type {\n MarkdownBlock,\n MarkdownEmits,\n MarkdownExpose,\n MarkdownProps,\n MarkdownSlots,\n} from './markdown'\nimport { createMarkdownParser } from './parser'\nimport {\n markdownContextKey,\n MarkdownChunkView,\n type MarkdownCommit,\n type MarkdownRenderContext,\n} from './render'\nimport { defaultSanitizeUrl } from './url'\n\ndefineOptions({ name: 'DouMarkdown' })\n\nconst props = withDefaults(defineProps<MarkdownProps>(), {\n content: '',\n streaming: false,\n smooth: true,\n speed: 40,\n caret: true,\n linkTarget: '_blank',\n})\nconst emit = defineEmits<MarkdownEmits>()\nconst slots = defineSlots<MarkdownSlots>()\n\nconst ns = useNamespace('markdown')\nconst reducedMotion = useReducedMotion()\n\n/** The fade of new content; the same as the `--dou-motion-duration-slow` token. */\nconst FADE = 320\n/** Blocks per chunk: a chunk that is complete is skipped as a whole. */\nconst CHUNK = 32\n\nconst parser = createMarkdownParser()\n// How much of `content` is shown, in UTF-16 units. What is there at mount shows at once.\nconst shown = ref(props.content.length)\nlet committed = props.content.length\nlet committedText = props.content\nlet committedFinal = !props.streaming\nconst blocks = shallowRef<MarkdownBlock[]>(parser.update(props.content, { final: committedFinal }))\nconst tick = ref(0)\n\nconst commits: MarkdownCommit[] = []\nconst ctx: MarkdownRenderContext = {\n get streaming() {\n return props.streaming\n },\n get sources() {\n return props.sources\n },\n get linkTarget() {\n return props.linkTarget\n },\n slots,\n sanitize: (url, kind) => (props.sanitizeUrl ?? defaultSanitizeUrl)(url, kind),\n commits,\n duration: FADE,\n now: 0,\n delays: new Map(),\n caret: null,\n end: null,\n drawing: null,\n fading: new Set(),\n}\nprovide(markdownContextKey, ctx)\n\nlet mounted = false\nconst animate = () => mounted && props.smooth && !reducedMotion.value\n\n/** The last leaf, where the caret and the `trailing` slot go. */\nfunction caretTarget(list: MarkdownBlock[]): object | null {\n let node: MarkdownBlock | MarkdownBlock[] | undefined = list[list.length - 1]\n for (;;) {\n if (!node) return null\n if (Array.isArray(node)) node = node[node.length - 1]\n else if (node.type === 'blockquote' || node.type === 'container')\n node = node.children[node.children.length - 1]\n else if (node.type === 'list') {\n const item = node.children[node.children.length - 1]\n if (!item) return null\n const child = item.children[item.children.length - 1]\n if (!child) return item\n node = child\n } else if (node.type === 'table') return node.rows[node.rows.length - 1] ?? node.head\n else if (node.type === 'paragraph' || node.type === 'heading') return node\n else return null\n }\n}\n\n// complete chunks are kept, so the same array goes back to the same component\nlet chunks: MarkdownBlock[][] = []\nfunction chunkOf(list: MarkdownBlock[]): MarkdownBlock[][] {\n const next: MarkdownBlock[][] = []\n for (let from = 0; from < list.length; from += CHUNK) {\n const index = from / CHUNK\n const prev = chunks[index]\n const to = Math.min(from + CHUNK, list.length)\n if (prev && prev.length === to - from && prev.every((block, i) => block === list[from + i]))\n next.push(prev)\n else next.push(list.slice(from, to))\n }\n chunks = next\n return next\n}\nconst chunked = shallowRef(chunkOf(blocks.value))\n\nlet cleanup: ReturnType<typeof setTimeout> | undefined\nfunction commit(now: number) {\n const final = !props.streaming && shown.value >= props.content.length\n if (animate() && shown.value > committed) commits.push({ from: committed, time: now })\n // fades that are over need no span any more\n let ended = false\n while (commits.length && now - commits[0]!.time >= FADE) {\n const old = commits.shift()!\n ended = true\n for (const key of ctx.delays.keys()) if (key.endsWith(`:${old.from}`)) ctx.delays.delete(key)\n }\n if (ended) {\n // blocks that are finished are not drawn again by themselves\n for (const block of ctx.fading) if (!block.isUnmounted) block.proxy?.$forceUpdate()\n ctx.fading.clear()\n }\n committedText = props.content.slice(0, shown.value)\n committed = shown.value\n committedFinal = final\n ctx.now = now\n blocks.value = parser.update(committedText, { final })\n chunked.value = chunkOf(blocks.value)\n tick.value++\n clearTimeout(cleanup)\n // one more render once the last fade ends, to merge its spans back into text\n if (commits.length) cleanup = setTimeout(() => commit(performance.now()), FADE + 20)\n}\n\nlet frame = 0\nlet last = 0\nlet carry = 0\nfunction step(now: number) {\n frame = 0\n const total = props.content.length\n if (animate()) {\n const elapsed = last ? Math.min(now - last, 100) : 16\n last = now\n const backlog = total - shown.value\n // at least `speed`, and fast enough to catch up in a moment\n const rate = Math.max(props.speed, backlog / (props.streaming ? 0.4 : 0.25))\n carry += (rate * elapsed) / 1000\n const advance = Math.floor(carry)\n if (advance > 0) {\n carry -= advance\n shown.value = safeCut(props.content, Math.min(total, shown.value + advance))\n }\n } else shown.value = total\n const final = !props.streaming && shown.value >= total\n if (shown.value !== committed || final !== committedFinal) commit(now)\n if (shown.value < total) frame = requestAnimationFrame(step)\n else last = 0\n}\n\nfunction schedule() {\n if (!mounted || typeof requestAnimationFrame === 'undefined') {\n shown.value = props.content.length\n commit(0)\n return\n }\n if (!frame) frame = requestAnimationFrame(step)\n}\n\nfunction flush() {\n if (frame) cancelAnimationFrame(frame)\n frame = 0\n last = 0\n carry = 0\n shown.value = props.content.length\n commit(typeof performance === 'undefined' ? 0 : performance.now())\n}\n\nwatch(\n () => props.content,\n (value) => {\n // replaced rather than extended: keep what still matches\n if (!value.startsWith(committedText)) {\n let common = 0\n const limit = Math.min(value.length, committedText.length)\n while (common < limit && value.charCodeAt(common) === committedText.charCodeAt(common))\n common++\n shown.value = safeCut(value, common)\n committed = Math.min(committed, shown.value)\n while (commits.length && commits[commits.length - 1]!.from >= shown.value) commits.pop()\n }\n schedule()\n },\n)\nwatch(() => props.streaming, schedule)\nwatch(\n () => props.smooth,\n (smooth) => {\n if (!smooth) flush()\n },\n)\n\nconst done = computed(() => !props.streaming && shown.value >= props.content.length)\nwatch(done, (value) => {\n if (value) emit('done')\n})\n\nonMounted(() => {\n mounted = true\n})\nonBeforeUnmount(() => {\n if (frame) cancelAnimationFrame(frame)\n clearTimeout(cleanup)\n})\n\ndefineExpose<MarkdownExpose>({ flush })\n\n// Renders the blocks. The caret target is set here, untracked, so that\n// moving the caret does not re-render every block that checks for it.\nfunction Body() {\n ctx.drawing = null\n const target = caretTarget(blocks.value)\n ctx.caret = props.caret && !done.value ? target : null\n ctx.end = slots.trailing ? target : null\n const list = chunked.value\n // the last chunk draws again when the `trailing` slot comes or goes\n const lastTick = tick.value * 2 + (slots.trailing ? 1 : 0)\n const children = list.map((chunk, index) =>\n h(MarkdownChunkView, {\n key: index,\n blocks: chunk,\n tick: index === list.length - 1 ? lastTick : 0,\n }),\n )\n if (props.caret && !done.value && !target)\n children.push(h('span', { key: 'caret', class: ns.e('caret'), 'aria-hidden': 'true' }))\n // after a code block or a rule, nothing to follow on the same line: a line of its own\n if (slots.trailing && !target)\n children.push(\n h('div', { key: 'trailing', class: ns.e('trailing') }, slots.trailing() as VNode[]),\n )\n return children\n}\n</script>\n\n<template>\n <div :class=\"[ns.b(), ns.is('streaming', !done)]\" :aria-busy=\"done ? undefined : 'true'\">\n <Body />\n </div>\n</template>\n"],"mappings":";;;;;;;;;AAgDA,IAAM,OAAO;;AAEb,IAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;EAjBd,MAAM,QAAQ;EAQd,MAAM,OAAO;EACb,MAAM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AE,mBAAmB;IACnB,KAAK;IACL,QAAQ;IACR,MAAM,UAAU,KAAK,SAAS,IAAI,WAAW;GAC/C,CAAC,CACH;GACA,IAAI,MAAM,SAAS,CAAC,KAAK,SAAS,CAAC,QACjC,SAAS,KAAK,EAAE,QAAQ;IAAE,KAAK;IAAS,OAAO,GAAG,EAAE,OAAO;IAAG,eAAe;GAAO,CAAC,CAAC;GAExF,IAAI,MAAM,YAAY,CAAC,QACrB,SAAS,KACP,EAAE,OAAO;IAAE,KAAK;IAAY,OAAO,GAAG,EAAE,UAAU;GAAE,GAAG,MAAM,SAAS,CAAY,CACpF;GACF,OAAO;EACT;;GAIE,OAAAC,UAAA,GAAAC,mBAEM,OAAA;IAFA,OAAKC,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,GAAIA,MAAA,EAAA,CAAE,CAAC,GAAE,aAAA,CAAe,KAAA,KAAI,CAAA,CAAA;IAAK,aAAW,KAAA,QAAO,KAAA,IAAS;G,IAC5EC,YAAQ,IAAA,C"}
|
|
@@ -52,6 +52,11 @@ function caretNode() {
|
|
|
52
52
|
"aria-hidden": "true"
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
+
/** The caret and the `trailing` slot, after the last word of `owner`. */
|
|
56
|
+
function tail(ctx, owner, out) {
|
|
57
|
+
if (ctx.caret === owner) out.push(caretNode());
|
|
58
|
+
if (ctx.end === owner && ctx.slots.trailing) out.push(h("span", { class: `${B}__trailing` }, ctx.slots.trailing()));
|
|
59
|
+
}
|
|
55
60
|
/** Text, with the parts that are still fading in wrapped in spans. */
|
|
56
61
|
function text(ctx, value, at, out, fade) {
|
|
57
62
|
const commits = ctx.commits;
|
|
@@ -205,7 +210,7 @@ function inlines(ctx, nodes, fade, out = [], inLink = false) {
|
|
|
205
210
|
}
|
|
206
211
|
function leafContent(ctx, owner, nodes, fade = true) {
|
|
207
212
|
const out = inlines(ctx, nodes, fade);
|
|
208
|
-
|
|
213
|
+
tail(ctx, owner, out);
|
|
209
214
|
return out;
|
|
210
215
|
}
|
|
211
216
|
function blockList(nodes, tick) {
|
|
@@ -238,7 +243,7 @@ function renderItem(ctx, item, tick) {
|
|
|
238
243
|
tick: index === last ? tick : 0
|
|
239
244
|
}));
|
|
240
245
|
});
|
|
241
|
-
|
|
246
|
+
tail(ctx, item, children);
|
|
242
247
|
if (slot) return output(slot({
|
|
243
248
|
node: item,
|
|
244
249
|
checked: item.checked,
|
|
@@ -250,7 +255,7 @@ function renderRow(ctx, row, align, cell, fade) {
|
|
|
250
255
|
const entering = fade ? enter(ctx, row.start) : void 0;
|
|
251
256
|
return h("tr", { class: entering }, row.cells.map((content, index) => {
|
|
252
257
|
const out = inlines(ctx, content, fade && !entering);
|
|
253
|
-
if (
|
|
258
|
+
if (index === row.cells.length - 1) tail(ctx, row, out);
|
|
254
259
|
return h(cell, { style: align[index] ? { textAlign: align[index] } : void 0 }, out);
|
|
255
260
|
}));
|
|
256
261
|
}
|