dou-ui 0.1.0-alpha.21 → 0.1.0-alpha.22
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-input/chat-input.vue_vue_type_script_setup_true_lang.js +19 -14
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input2.js.map +1 -1
- package/dist/components/chat-list/chat-list.js.map +1 -1
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js +26 -10
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-list/chat-list2.js.map +1 -1
- package/dist/components/chat-message/chat-message.js.map +1 -1
- package/dist/components/chat-plan/chat-plan.js.map +1 -1
- package/dist/components/chat-plan/chat-plan.vue_vue_type_script_setup_true_lang.js +22 -9
- package/dist/components/chat-plan/chat-plan.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-plan/chat-plan2.js.map +1 -1
- package/dist/components/code-block/code-block.js.map +1 -1
- package/dist/components/code-block/code-block.vue_vue_type_script_setup_true_lang.js +144 -7
- package/dist/components/code-block/code-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/dock-group.js.map +1 -1
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/dock.js.map +1 -1
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js +30 -4
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/style.js +1 -0
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/form/form2.js.map +1 -1
- package/dist/components/image/image-preview.js.map +1 -1
- package/dist/components/image/image-preview.vue_vue_type_script_setup_true_lang.js +63 -95
- package/dist/components/image/image-preview.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/image/use-preview-viewport.js +619 -0
- package/dist/components/image/use-preview-viewport.js.map +1 -0
- package/dist/components/image/viewport.js +142 -0
- package/dist/components/image/viewport.js.map +1 -0
- package/dist/components/link/link.js.map +1 -1
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js +59 -14
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js +13 -3
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/splitter/splitter.js.map +1 -1
- package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js +111 -41
- package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/style.js +1 -0
- package/dist/components/tabs/tab-button.js +6 -0
- package/dist/components/tabs/tab-button.js.map +1 -0
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js +108 -0
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/tabs/tab-drag.js +10 -2
- package/dist/components/tabs/tab-drag.js.map +1 -1
- package/dist/components/tabs/tab-panel.js.map +1 -1
- package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js +430 -181
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tabs2.js.map +1 -1
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js +33 -20
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/virtual-list/virtual-list2.js.map +1 -1
- package/dist/composables/use-floating.js +60 -8
- package/dist/composables/use-floating.js.map +1 -1
- package/dist/composables/use-popup.js +3 -0
- package/dist/composables/use-popup.js.map +1 -1
- package/dist/locale/en.js +1 -2
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/zh-cn.js +1 -2
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-tw.js +1 -2
- package/dist/locale/zh-tw.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/chat-list/chat-list.d.ts +13 -0
- package/dist/types/components/chat-list/index.d.ts +2 -0
- package/dist/types/components/chat-message/chat-message.d.ts +1 -0
- package/dist/types/components/chat-plan/chat-plan.d.ts +3 -1
- package/dist/types/components/chat-plan/chat-plan.vue.d.ts +1 -0
- package/dist/types/components/chat-plan/index.d.ts +3 -0
- package/dist/types/components/code-block/code-block.d.ts +23 -0
- package/dist/types/components/code-block/code-block.vue.d.ts +8 -2
- package/dist/types/components/code-block/index.d.ts +19 -3
- package/dist/types/components/dock/dock.d.ts +6 -0
- package/dist/types/components/image/image.d.ts +1 -1
- package/dist/types/components/image/use-preview-viewport.d.ts +48 -0
- package/dist/types/components/image/viewport.d.ts +58 -0
- package/dist/types/components/link/index.d.ts +3 -0
- package/dist/types/components/link/link.d.ts +12 -3
- package/dist/types/components/link/link.vue.d.ts +1 -0
- package/dist/types/components/popover/index.d.ts +3 -0
- package/dist/types/components/popover/popover.d.ts +7 -0
- package/dist/types/components/popover/popover.vue.d.ts +1 -0
- package/dist/types/components/splitter/index.d.ts +6 -9
- package/dist/types/components/splitter/splitter.d.ts +31 -4
- package/dist/types/components/splitter/splitter.vue.d.ts +3 -4
- package/dist/types/components/tabs/index.d.ts +3 -0
- package/dist/types/components/tabs/tab-button.vue.d.ts +28 -0
- package/dist/types/components/tabs/tab-drag.d.ts +8 -0
- package/dist/types/components/tabs/tab-panel.vue.d.ts +1 -0
- package/dist/types/components/tabs/tabs.d.ts +6 -0
- package/dist/types/composables/use-floating.d.ts +1 -1
- package/dist/types/locale/types.d.ts +2 -3
- 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 bar of actions over a message shows. */\nexport type ChatMessageActionsVisible = 'always' | 'hover'\n\n/** One kind of reaction on a message, e.g. 👍 from three people. */\nexport interface ChatMessageReaction {\n /** The emoji, or any key the app knows the reaction by; shown as is unless the `reaction` slot renders it. */\n emoji: string\n /** How many reacted this way. A reaction at 0 is not shown. */\n count: number\n /** The person reacted this way too; pressing it again takes theirs back. */\n reacted?: boolean\n /** More about it, e.g. who reacted; read out and shown on hover after the emoji and count. */\n label?: string\n}\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 bar of actions over the top right corner shows: `'always'`,\n * or `'hover'` while the pointer is over the message, focus is inside,\n * or after a tap on it on a touch screen. Buttons from the `actions`\n * slot follow along. Defaults to `'hover'`.\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 * The reactions under the message, each with how many reacted and\n * whether the person did; one entry per emoji. Pressing one emits `react`; the app adds or\n * takes back the person's reaction itself.\n */\n reactions?: ChatMessageReaction[]\n /**\n * Let the person press `reactions` and add new ones. Turn it off to only\n * show them, e.g. on their own messages or in an archived conversation:\n * the chips look the same and keep the hover text, but cannot be pressed,\n * and there is no add-reaction button even with a `reaction-picker` slot.\n * Defaults to `true`.\n */\n reactable?: 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 * A reaction was pressed, or picked in the `reaction-picker` slot: add\n * the person's reaction, or take it back if `reacted` was on. `reaction`\n * is the entry of `reactions` with that emoji, if there is one.\n */\n react: [emoji: string, reaction: ChatMessageReaction | undefined]\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 /**\n * The panel opened by the add-reaction button, e.g. a row of common\n * emoji. Without it there is no add button. `react(emoji)` emits `react`\n * and closes the panel; `close` closes it without reacting.\n */\n 'reaction-picker'?: (props: { react: (emoji: string) => void; close: () => void }) => unknown\n /** Renders the emoji of a reaction, e.g. a custom image for an app's own key. */\n reaction?: (props: { reaction: ChatMessageReaction }) => 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":";;
|
|
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 bar of actions over a message shows. */\nexport type ChatMessageActionsVisible = 'always' | 'hover'\n\n/** One kind of reaction on a message, e.g. 👍 from three people. */\nexport interface ChatMessageReaction {\n /** The emoji, or any key the app knows the reaction by; shown as is unless the `reaction` slot renders it. */\n emoji: string\n /** How many reacted this way. A reaction at 0 is not shown. */\n count: number\n /** The person reacted this way too; pressing it again takes theirs back. */\n reacted?: boolean\n /** More about it, e.g. who reacted; read out and shown on hover after the emoji and count. */\n label?: string\n}\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 showHeader?: boolean\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 bar of actions over the top right corner shows: `'always'`,\n * or `'hover'` while the pointer is over the message, focus is inside,\n * or after a tap on it on a touch screen. Buttons from the `actions`\n * slot follow along. Defaults to `'hover'`.\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 * The reactions under the message, each with how many reacted and\n * whether the person did; one entry per emoji. Pressing one emits `react`; the app adds or\n * takes back the person's reaction itself.\n */\n reactions?: ChatMessageReaction[]\n /**\n * Let the person press `reactions` and add new ones. Turn it off to only\n * show them, e.g. on their own messages or in an archived conversation:\n * the chips look the same and keep the hover text, but cannot be pressed,\n * and there is no add-reaction button even with a `reaction-picker` slot.\n * Defaults to `true`.\n */\n reactable?: 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 * A reaction was pressed, or picked in the `reaction-picker` slot: add\n * the person's reaction, or take it back if `reacted` was on. `reaction`\n * is the entry of `reactions` with that emoji, if there is one.\n */\n react: [emoji: string, reaction: ChatMessageReaction | undefined]\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 /**\n * The panel opened by the add-reaction button, e.g. a row of common\n * emoji. Without it there is no add button. `react(emoji)` emits `react`\n * and closes the panel; `close` closes it without reacting.\n */\n 'reaction-picker'?: (props: { react: (emoji: string) => void; close: () => void }) => unknown\n /** Renders the emoji of a reaction, e.g. a custom image for an app's own key. */\n reaction?: (props: { reaction: ChatMessageReaction }) => 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":";;AA8PA,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-plan.js","names":[],"sources":["../../../src/components/chat-plan/chat-plan.ts"],"sourcesContent":["/**\n * `waiting` is a step paused on someone else, such as a confirmation from\n * the user or an outside job, as opposed to `pending`, which hasn't started.\n */\nexport type ChatPlanItemStatus = 'pending' | 'running' | 'waiting' | 'done' | 'skipped' | 'error'\n\nexport interface ChatPlanItem {\n /** Unique within the plan. Defaults to the position. */\n key?: string | number\n label: string\n /** A second line under the label. */\n description?: string\n status?: ChatPlanItemStatus\n}\n\nexport interface ChatPlanProps {\n /** The steps, in order. */\n items?: ChatPlanItem[]\n /** Defaults to the locale's \"Plan\". */\n title?: string\n /** Let the header fold the list away. Off gives a plain panel that always shows the steps. */\n collapsible?: boolean\n /** Expanded or not. Bound with `v-model:open`; open by default. Ignored when not `collapsible
|
|
1
|
+
{"version":3,"file":"chat-plan.js","names":[],"sources":["../../../src/components/chat-plan/chat-plan.ts"],"sourcesContent":["/**\n * `waiting` is a step paused on someone else, such as a confirmation from\n * the user or an outside job, as opposed to `pending`, which hasn't started.\n */\nexport type ChatPlanItemStatus = 'pending' | 'running' | 'waiting' | 'done' | 'skipped' | 'error'\n\nexport interface ChatPlanItem {\n /** Unique within the plan. Defaults to the position. */\n key?: string | number\n label: string\n /** A second line under the label. */\n description?: string\n status?: ChatPlanItemStatus\n}\n\nexport interface ChatPlanProps {\n /** The steps, in order. */\n items?: ChatPlanItem[]\n /** Defaults to the locale's \"Plan\". */\n title?: string\n /** Show the header bar with icon, title and counter. Off hides the header and keeps the list open. */\n showHeader?: boolean\n /** Let the header fold the list away. Off gives a plain panel that always shows the steps. */\n collapsible?: boolean\n /** Expanded or not. Bound with `v-model:open`; open by default. Ignored when not `collapsible` or `showHeader` is false. */\n open?: boolean\n /**\n * The run is going on now. Off once the turn has ended or been stopped: a\n * `running` step stays the current one but holds still, a solid dot in\n * place of the spinner and no shimmer, so the steps needn't be rewritten.\n */\n live?: boolean\n}\n\nexport interface ChatPlanEmits {\n 'update:open': [open: boolean]\n}\n\nexport interface ChatPlanSlots {\n /** Replaces the label and description of each item. */\n item?: (props: { item: ChatPlanItem; index: number }) => unknown\n}\n\n/**\n * Whether the plan shows a step running: one is `running` and the run hasn't\n * stopped. ChatMessage reads the same for `aria-busy`.\n */\nexport function planRunning(items: readonly ChatPlanItem[] | undefined, live = true): boolean {\n return live && !!items?.some((item) => item.status === 'running')\n}\n"],"mappings":";;;;;AA+CA,SAAgB,YAAY,OAA4C,OAAO,MAAe;CAC5F,OAAO,QAAQ,CAAC,CAAC,OAAO,MAAM,SAAS,KAAK,WAAW,SAAS;AAClE"}
|
|
@@ -8,13 +8,21 @@ import { planRunning } from "./chat-plan.js";
|
|
|
8
8
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, renderSlot, resolveDynamicComponent, toDisplayString, unref, useId, vShow, watchEffect, withCtx, withDirectives } from "vue";
|
|
9
9
|
import { AlertCircleIcon, CheckIcon, ChevronDownIcon, ClockPauseIcon, ListChecksIcon } from "@dou-ui/icons";
|
|
10
10
|
// src/components/chat-plan/chat-plan.vue?vue&type=script&setup=true&lang.ts
|
|
11
|
-
var _hoisted_1 = [
|
|
11
|
+
var _hoisted_1 = [
|
|
12
|
+
"id",
|
|
13
|
+
"aria-labelledby",
|
|
14
|
+
"aria-label"
|
|
15
|
+
];
|
|
12
16
|
var chat_plan_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
13
17
|
name: "DouChatPlan",
|
|
14
18
|
__name: "chat-plan",
|
|
15
19
|
props: {
|
|
16
20
|
items: { default: () => [] },
|
|
17
21
|
title: {},
|
|
22
|
+
showHeader: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
default: true
|
|
25
|
+
},
|
|
18
26
|
collapsible: {
|
|
19
27
|
type: Boolean,
|
|
20
28
|
default: true
|
|
@@ -36,7 +44,8 @@ var chat_plan_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
36
44
|
const { t } = useLocale();
|
|
37
45
|
const id = useId();
|
|
38
46
|
const inner = ref(true);
|
|
39
|
-
const
|
|
47
|
+
const canCollapse = computed(() => props.showHeader && props.collapsible);
|
|
48
|
+
const open = computed(() => !canCollapse.value || (props.open ?? inner.value));
|
|
40
49
|
function toggle() {
|
|
41
50
|
inner.value = !open.value;
|
|
42
51
|
emit("update:open", inner.value);
|
|
@@ -44,9 +53,10 @@ var chat_plan_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
44
53
|
if (process.env.NODE_ENV !== "production") {
|
|
45
54
|
let warned = false;
|
|
46
55
|
watchEffect(() => {
|
|
47
|
-
if (warned ||
|
|
56
|
+
if (warned || canCollapse.value || props.open === void 0) return;
|
|
48
57
|
warned = true;
|
|
49
|
-
|
|
58
|
+
const reason = props.collapsible ? "`showHeader`" : "`collapsible`";
|
|
59
|
+
console.warn(`[dou-ui] DouChatPlan: \`open\` is ignored when ${reason} is false.`);
|
|
50
60
|
});
|
|
51
61
|
}
|
|
52
62
|
const finished = computed(() => props.items.filter((item) => item.status === "done" || item.status === "skipped").length);
|
|
@@ -54,10 +64,12 @@ var chat_plan_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
54
64
|
return (_ctx, _cache) => {
|
|
55
65
|
return openBlock(), createElementBlock("div", { class: normalizeClass([
|
|
56
66
|
unref(ns).b(),
|
|
57
|
-
unref(ns).is("collapsible",
|
|
67
|
+
unref(ns).is("collapsible", canCollapse.value),
|
|
58
68
|
unref(ns).is("open", open.value),
|
|
59
|
-
unref(ns).is("running", running.value)
|
|
60
|
-
|
|
69
|
+
unref(ns).is("running", running.value),
|
|
70
|
+
unref(ns).is("headless", !__props.showHeader)
|
|
71
|
+
]) }, [__props.showHeader ? (openBlock(), createBlock(resolveDynamicComponent(__props.collapsible ? "button" : "div"), {
|
|
72
|
+
key: 0,
|
|
61
73
|
id: `${unref(id)}-header`,
|
|
62
74
|
class: normalizeClass(unref(ns).e("header")),
|
|
63
75
|
type: __props.collapsible ? "button" : void 0,
|
|
@@ -81,12 +93,13 @@ var chat_plan_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
81
93
|
"type",
|
|
82
94
|
"aria-expanded",
|
|
83
95
|
"aria-controls"
|
|
84
|
-
])), createVNode(unref(DouCollapseTransition), null, {
|
|
96
|
+
])) : createCommentVNode("", true), createVNode(unref(DouCollapseTransition), null, {
|
|
85
97
|
default: withCtx(() => [withDirectives(createElementVNode("div", {
|
|
86
98
|
id: `${unref(id)}-panel`,
|
|
87
99
|
role: "region",
|
|
88
100
|
class: normalizeClass(unref(ns).e("panel")),
|
|
89
|
-
"aria-labelledby": `${unref(id)}-header`
|
|
101
|
+
"aria-labelledby": __props.showHeader ? `${unref(id)}-header` : void 0,
|
|
102
|
+
"aria-label": __props.showHeader ? void 0 : __props.title || unref(t)("chat.plan")
|
|
90
103
|
}, [createElementVNode("ol", { class: normalizeClass(unref(ns).e("list")) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.items, (item, index) => {
|
|
91
104
|
return openBlock(), createElementBlock("li", {
|
|
92
105
|
key: item.key ?? index,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-plan.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_createBlock","_resolveDynamicComponent","_withCtx","_createVNode","_createElementVNode","_toDisplayString","_createCommentVNode","CollapseTransition","_withDirectives","_Fragment","_renderList","_renderSlot","_createTextVNode","_vShow"],"sources":["../../../src/components/chat-plan/chat-plan.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n AlertCircleIcon,\n CheckIcon,\n ChevronDownIcon,\n ClockPauseIcon,\n ListChecksIcon,\n} from '@dou-ui/icons'\nimport { computed, ref, useId, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouCollapseTransition as CollapseTransition } from '../collapse/collapse-transition'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouShimmer } from '../shimmer'\nimport { DouSpinner } from '../spinner'\nimport { DouStatusDot } from '../status-dot'\nimport { planRunning } from './chat-plan'\nimport type { ChatPlanEmits, ChatPlanProps, ChatPlanSlots } from './chat-plan'\n\ndefineOptions({ name: 'DouChatPlan' })\n\nconst props = withDefaults(defineProps<ChatPlanProps>(), {\n items: () => [],\n collapsible: true,\n open: undefined,\n live: true,\n})\nconst emit = defineEmits<ChatPlanEmits>()\ndefineSlots<ChatPlanSlots>()\n\nconst ns = useNamespace('chat-plan')\nconst { t } = useLocale()\nconst id = useId()\n\nconst inner = ref(true)\nconst
|
|
1
|
+
{"version":3,"file":"chat-plan.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_createBlock","_resolveDynamicComponent","_withCtx","_createVNode","_createElementVNode","_toDisplayString","_createCommentVNode","CollapseTransition","_withDirectives","_Fragment","_renderList","_renderSlot","_createTextVNode","_vShow"],"sources":["../../../src/components/chat-plan/chat-plan.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n AlertCircleIcon,\n CheckIcon,\n ChevronDownIcon,\n ClockPauseIcon,\n ListChecksIcon,\n} from '@dou-ui/icons'\nimport { computed, ref, useId, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouCollapseTransition as CollapseTransition } from '../collapse/collapse-transition'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouShimmer } from '../shimmer'\nimport { DouSpinner } from '../spinner'\nimport { DouStatusDot } from '../status-dot'\nimport { planRunning } from './chat-plan'\nimport type { ChatPlanEmits, ChatPlanProps, ChatPlanSlots } from './chat-plan'\n\ndefineOptions({ name: 'DouChatPlan' })\n\nconst props = withDefaults(defineProps<ChatPlanProps>(), {\n items: () => [],\n showHeader: true,\n collapsible: true,\n open: undefined,\n live: true,\n})\nconst emit = defineEmits<ChatPlanEmits>()\ndefineSlots<ChatPlanSlots>()\n\nconst ns = useNamespace('chat-plan')\nconst { t } = useLocale()\nconst id = useId()\n\nconst inner = ref(true)\nconst canCollapse = computed(() => props.showHeader && props.collapsible)\nconst open = computed(() => !canCollapse.value || (props.open ?? inner.value))\nfunction toggle() {\n inner.value = !open.value\n emit('update:open', inner.value)\n}\n\n// Say once, while developing, that `open` does nothing when the list cannot fold.\n// The app's bundler replaces this, as for Vue's own warnings.\nif (process.env.NODE_ENV !== 'production') {\n let warned = false\n watchEffect(() => {\n if (warned || canCollapse.value || props.open === undefined) return\n warned = true\n const reason = props.collapsible ? '`showHeader`' : '`collapsible`'\n console.warn(`[dou-ui] DouChatPlan: \\`open\\` is ignored when ${reason} is false.`)\n })\n}\n\nconst finished = computed(\n () => props.items.filter((item) => item.status === 'done' || item.status === 'skipped').length,\n)\n// `live` false: the run has stopped, so a running step holds still\nconst running = computed(() => planRunning(props.items, props.live))\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('collapsible', canCollapse),\n ns.is('open', open),\n ns.is('running', running),\n ns.is('headless', !showHeader),\n ]\"\n >\n <component\n :is=\"collapsible ? 'button' : 'div'\"\n v-if=\"showHeader\"\n :id=\"`${id}-header`\"\n :class=\"ns.e('header')\"\n :type=\"collapsible ? 'button' : undefined\"\n :aria-expanded=\"collapsible ? open : undefined\"\n :aria-controls=\"collapsible ? `${id}-panel` : undefined\"\n @click=\"collapsible && toggle()\"\n >\n <ListChecksIcon :class=\"ns.e('icon')\" />\n <span :class=\"ns.e('title')\">{{ title ?? t('chat.plan') }}</span>\n <span :class=\"ns.e('count')\">{{ finished }} / {{ items.length }}</span>\n <ChevronDownIcon v-if=\"collapsible\" :class=\"ns.e('arrow')\" />\n </component>\n <CollapseTransition>\n <div\n v-show=\"open\"\n :id=\"`${id}-panel`\"\n role=\"region\"\n :class=\"ns.e('panel')\"\n :aria-labelledby=\"showHeader ? `${id}-header` : undefined\"\n :aria-label=\"showHeader ? undefined : title || t('chat.plan')\"\n >\n <ol :class=\"ns.e('list')\">\n <li\n v-for=\"(item, index) in items\"\n :key=\"item.key ?? index\"\n :class=\"[ns.e('item'), ns.is(item.status ?? 'pending')]\"\n >\n <span :class=\"ns.e('mark')\">\n <template v-if=\"item.status === 'running'\">\n <DouSpinner v-if=\"live\" size=\"sm\" :label=\"t('chat.stepRunning')\" />\n <DouStatusDot v-else :label=\"t('chat.stepRunning')\" />\n </template>\n <ClockPauseIcon\n v-else-if=\"item.status === 'waiting'\"\n :label=\"t('chat.stepWaiting')\"\n />\n <CheckIcon v-else-if=\"item.status === 'done'\" :label=\"t('chat.stepDone')\" />\n <AlertCircleIcon v-else-if=\"item.status === 'error'\" :label=\"t('chat.stepError')\" />\n <span v-else :class=\"ns.e('dot')\" />\n </span>\n <span :class=\"ns.e('text')\">\n <slot name=\"item\" :item=\"item\" :index=\"index\">\n <span :class=\"ns.e('label')\">\n <DouShimmer :active=\"live && item.status === 'running'\">{{\n item.label\n }}</DouShimmer>\n </span>\n <span v-if=\"item.description\" :class=\"ns.e('description')\">\n {{ item.description }}\n </span>\n </slot>\n </span>\n </li>\n </ol>\n </div>\n </CollapseTransition>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBA,MAAM,QAAQ;EAOd,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,KAAK,MAAM;EAEjB,MAAM,QAAQ,IAAI,IAAI;EACtB,MAAM,cAAc,eAAe,MAAM,cAAc,MAAM,WAAW;EACxE,MAAM,OAAO,eAAe,CAAC,YAAY,UAAU,MAAM,QAAQ,MAAM,MAAM;EAC7E,SAAS,SAAS;GAChB,MAAM,QAAQ,CAAC,KAAK;GACpB,KAAK,eAAe,MAAM,KAAK;EACjC;EAIA,IAAA,QAAA,IAAA,aAA6B,cAAc;GACzC,IAAI,SAAS;GACb,kBAAkB;IAChB,IAAI,UAAU,YAAY,SAAS,MAAM,SAAS,KAAA,GAAW;IAC7D,SAAS;IACT,MAAM,SAAS,MAAM,cAAc,iBAAiB;IACpD,QAAQ,KAAK,kDAAkD,OAAO,WAAW;GACnF,CAAC;EACH;EAEA,MAAM,WAAW,eACT,MAAM,MAAM,QAAQ,SAAS,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import {\n AlertCircleIcon,\n CheckIcon,\n ChevronDownIcon,\n ClockPauseIcon,\n ListChecksIcon,\n} from '@dou-ui/icons'\nimport { computed, ref, useId, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouCollapseTransition as CollapseTransition } from '../collapse/collapse-transition'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouShimmer } from '../shimmer'\nimport { DouSpinner } from '../spinner'\nimport { DouStatusDot } from '../status-dot'\nimport { planRunning } from './chat-plan'\nimport type { ChatPlanEmits, ChatPlanProps, ChatPlanSlots } from './chat-plan'\n\ndefineOptions({ name: 'DouChatPlan' })\n\nconst props = withDefaults(defineProps<ChatPlanProps>(), {\n items: () => [],\n collapsible: true,\n open: undefined,\n live: true,\n})\nconst emit = defineEmits<ChatPlanEmits>()\ndefineSlots<ChatPlanSlots>()\n\nconst ns = useNamespace('chat-plan')\nconst { t } = useLocale()\nconst id = useId()\n\nconst inner = ref(true)\nconst
|
|
1
|
+
{"version":3,"file":"chat-plan2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-plan/chat-plan.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n AlertCircleIcon,\n CheckIcon,\n ChevronDownIcon,\n ClockPauseIcon,\n ListChecksIcon,\n} from '@dou-ui/icons'\nimport { computed, ref, useId, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouCollapseTransition as CollapseTransition } from '../collapse/collapse-transition'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouShimmer } from '../shimmer'\nimport { DouSpinner } from '../spinner'\nimport { DouStatusDot } from '../status-dot'\nimport { planRunning } from './chat-plan'\nimport type { ChatPlanEmits, ChatPlanProps, ChatPlanSlots } from './chat-plan'\n\ndefineOptions({ name: 'DouChatPlan' })\n\nconst props = withDefaults(defineProps<ChatPlanProps>(), {\n items: () => [],\n showHeader: true,\n collapsible: true,\n open: undefined,\n live: true,\n})\nconst emit = defineEmits<ChatPlanEmits>()\ndefineSlots<ChatPlanSlots>()\n\nconst ns = useNamespace('chat-plan')\nconst { t } = useLocale()\nconst id = useId()\n\nconst inner = ref(true)\nconst canCollapse = computed(() => props.showHeader && props.collapsible)\nconst open = computed(() => !canCollapse.value || (props.open ?? inner.value))\nfunction toggle() {\n inner.value = !open.value\n emit('update:open', inner.value)\n}\n\n// Say once, while developing, that `open` does nothing when the list cannot fold.\n// The app's bundler replaces this, as for Vue's own warnings.\nif (process.env.NODE_ENV !== 'production') {\n let warned = false\n watchEffect(() => {\n if (warned || canCollapse.value || props.open === undefined) return\n warned = true\n const reason = props.collapsible ? '`showHeader`' : '`collapsible`'\n console.warn(`[dou-ui] DouChatPlan: \\`open\\` is ignored when ${reason} is false.`)\n })\n}\n\nconst finished = computed(\n () => props.items.filter((item) => item.status === 'done' || item.status === 'skipped').length,\n)\n// `live` false: the run has stopped, so a running step holds still\nconst running = computed(() => planRunning(props.items, props.live))\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('collapsible', canCollapse),\n ns.is('open', open),\n ns.is('running', running),\n ns.is('headless', !showHeader),\n ]\"\n >\n <component\n :is=\"collapsible ? 'button' : 'div'\"\n v-if=\"showHeader\"\n :id=\"`${id}-header`\"\n :class=\"ns.e('header')\"\n :type=\"collapsible ? 'button' : undefined\"\n :aria-expanded=\"collapsible ? open : undefined\"\n :aria-controls=\"collapsible ? `${id}-panel` : undefined\"\n @click=\"collapsible && toggle()\"\n >\n <ListChecksIcon :class=\"ns.e('icon')\" />\n <span :class=\"ns.e('title')\">{{ title ?? t('chat.plan') }}</span>\n <span :class=\"ns.e('count')\">{{ finished }} / {{ items.length }}</span>\n <ChevronDownIcon v-if=\"collapsible\" :class=\"ns.e('arrow')\" />\n </component>\n <CollapseTransition>\n <div\n v-show=\"open\"\n :id=\"`${id}-panel`\"\n role=\"region\"\n :class=\"ns.e('panel')\"\n :aria-labelledby=\"showHeader ? `${id}-header` : undefined\"\n :aria-label=\"showHeader ? undefined : title || t('chat.plan')\"\n >\n <ol :class=\"ns.e('list')\">\n <li\n v-for=\"(item, index) in items\"\n :key=\"item.key ?? index\"\n :class=\"[ns.e('item'), ns.is(item.status ?? 'pending')]\"\n >\n <span :class=\"ns.e('mark')\">\n <template v-if=\"item.status === 'running'\">\n <DouSpinner v-if=\"live\" size=\"sm\" :label=\"t('chat.stepRunning')\" />\n <DouStatusDot v-else :label=\"t('chat.stepRunning')\" />\n </template>\n <ClockPauseIcon\n v-else-if=\"item.status === 'waiting'\"\n :label=\"t('chat.stepWaiting')\"\n />\n <CheckIcon v-else-if=\"item.status === 'done'\" :label=\"t('chat.stepDone')\" />\n <AlertCircleIcon v-else-if=\"item.status === 'error'\" :label=\"t('chat.stepError')\" />\n <span v-else :class=\"ns.e('dot')\" />\n </span>\n <span :class=\"ns.e('text')\">\n <slot name=\"item\" :item=\"item\" :index=\"index\">\n <span :class=\"ns.e('label')\">\n <DouShimmer :active=\"live && item.status === 'running'\">{{\n item.label\n }}</DouShimmer>\n </span>\n <span v-if=\"item.description\" :class=\"ns.e('description')\">\n {{ item.description }}\n </span>\n </slot>\n </span>\n </li>\n </ol>\n </div>\n </CollapseTransition>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-block.js","names":["_sfc_main"],"sources":["../../../src/components/code-block/code-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, ref, shallowRef, useId, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useGlobalConfig, useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport type { CodeBlockHighlighter, CodeBlockProps, CodeBlockSlots } from './code-block'\nimport { htmlLines, parseLines, plainLines } from './lines'\n\ndefineOptions({ name: 'DouCodeBlock' })\n\nconst props = withDefaults(defineProps<CodeBlockProps>(), {\n code: '',\n lang: 'text',\n lineNumbers: false,\n startLine: 1,\n wrap: false,\n copyable: true,\n streaming: false,\n bordered: true,\n})\nconst slots = defineSlots<CodeBlockSlots>()\n\nconst ns = useNamespace('code-block')\nconst { t } = useLocale()\nconst config = useGlobalConfig()\nconst bodyId = `dou-code-block-${useId()}`\n\n// A function prop cannot take its default from ConfigProvider the way\n// other props do, so the configured one is read here.\nconst highlighter = computed<CodeBlockHighlighter | undefined>(\n () =>\n props.highlight ??\n (config.value.defaults as { DouCodeBlock?: { highlight?: CodeBlockHighlighter } }).DouCodeBlock\n ?.highlight,\n)\n\nconst code = computed(() => props.code.replace(/\\n$/, ''))\n\n/*\n * Plain lines until the highlighter answers. A synchronous highlighter\n * answers during setup, so server-rendered markup is already highlighted;\n * an async one fills in after. Only the latest call may land. While the\n * next answer is on its way, lines that were highlighted before and have\n * not changed keep their colors.\n */\nconst lines = shallowRef<string[]>(plainLines(code.value))\nlet run = 0\n// what the last answer covered, and its lines\nlet landed: { source: string; lines: string[] } | undefined\nwatchEffect(() => {\n const current = ++run\n const highlight = highlighter.value\n const raw = props.code\n // while streaming, the line still being written stays plain\n const cut = props.streaming ? raw.lastIndexOf('\\n') + 1 : raw.length\n const source = raw.slice(0, cut).replace(/\\n$/, '')\n const tail = props.streaming ? raw.slice(cut) : ''\n const after = tail ? plainLines(tail) : []\n if (!highlight || !source) {\n lines.value = plainLines(code.value)\n return\n }\n if (landed?.source === source) {\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n return\n }\n const kept = landed && source.startsWith(`${landed.source}\\n`) ? landed : undefined\n lines.value = kept\n ? [...kept.lines, ...plainLines(source.slice(kept.source.length + 1)), ...after]\n : [...plainLines(source), ...after]\n const apply = (html: string) => {\n if (current !== run) return\n landed = { source, lines: htmlLines(html) }\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n }\n try {\n const result = highlight(source, props.lang)\n if (typeof result === 'string') apply(result)\n else void result.then(apply, () => {})\n } catch {\n // a highlighter that throws leaves the plain text\n }\n})\n\nconst marked = computed(() => parseLines(props.highlightLines))\nconst rows = computed(() =>\n lines.value.map((html, index) => {\n const number = props.startLine + index\n return { html, number, marked: marked.value.has(number) }\n }),\n)\n\nconst expanded = ref(false)\nconst foldable = computed(() => props.maxLines !== undefined && rows.value.length > props.maxLines)\nconst folded = computed(() => foldable.value && !expanded.value)\n\nconst title = computed(() => props.filename ?? (props.lang === 'text' ? '' : props.lang))\nconst hasHeader = computed(() => !!(slots.title || title.value || slots.actions))\n\nconst classes = computed(() => [\n ns.b(),\n ns.is('wrap', props.wrap),\n ns.is('numbered', props.lineNumbers),\n ns.is('folded', folded.value),\n ns.is('headless', !hasHeader.value),\n ns.is('streaming', props.streaming),\n ns.is('bordered', props.bordered),\n])\n</script>\n\n<template>\n <div :class=\"classes\" :style=\"foldable ? { '--dou-code-block-max-lines': maxLines } : undefined\">\n <div v-if=\"hasHeader\" :class=\"ns.e('header')\">\n <span :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </span>\n <span :class=\"ns.e('actions')\">\n <slot name=\"actions\" />\n <DouCopyButton v-if=\"copyable\" :text=\"code\" size=\"sm\" />\n </span>\n </div>\n <DouCopyButton v-else-if=\"copyable\" :class=\"ns.e('copy')\" :text=\"code\" size=\"sm\" />\n <div :id=\"bodyId\" :class=\"ns.e('body')\" :data-lang=\"lang\">\n <code :class=\"ns.e('code')\">\n <span\n v-for=\"row in rows\"\n :key=\"row.number\"\n :class=\"[ns.e('row'), ns.is('marked', row.marked)]\"\n >\n <span v-if=\"lineNumbers\" :class=\"ns.e('number')\" aria-hidden=\"true\">{{\n row.number\n }}</span>\n <span :class=\"ns.e('line')\" v-html=\"row.html\" />\n </span>\n </code>\n </div>\n <button\n v-if=\"foldable\"\n type=\"button\"\n :class=\"ns.e('toggle')\"\n :aria-expanded=\"expanded\"\n :aria-controls=\"bodyId\"\n @click=\"expanded = !expanded\"\n >\n {{ expanded ? t('codeBlock.collapse') : t('codeBlock.expand', { count: rows.length }) }}\n </button>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"code-block.js","names":["_sfc_main"],"sources":["../../../src/components/code-block/code-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\n useId,\n useTemplateRef,\n watch,\n watchEffect,\n} from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useGlobalConfig, useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport type {\n CodeBlockEmits,\n CodeBlockExpose,\n CodeBlockHighlighter,\n CodeBlockProps,\n CodeBlockSlots,\n} from './code-block'\nimport { htmlLines, parseLines, plainLines } from './lines'\n\ndefineOptions({ name: 'DouCodeBlock' })\n\nconst props = withDefaults(defineProps<CodeBlockProps>(), {\n code: '',\n lang: 'text',\n lineNumbers: false,\n startLine: 1,\n wrap: false,\n maxHeight: undefined,\n copyable: true,\n streaming: false,\n autoScroll: undefined,\n bordered: true,\n})\nconst emit = defineEmits<CodeBlockEmits>()\nconst slots = defineSlots<CodeBlockSlots>()\n\nconst ns = useNamespace('code-block')\nconst { t } = useLocale()\nconst config = useGlobalConfig()\nconst bodyId = `dou-code-block-${useId()}`\n\n// A function prop cannot take its default from ConfigProvider the way\n// other props do, so the configured one is read here.\nconst highlighter = computed<CodeBlockHighlighter | undefined>(\n () =>\n props.highlight ??\n (config.value.defaults as { DouCodeBlock?: { highlight?: CodeBlockHighlighter } }).DouCodeBlock\n ?.highlight,\n)\n\nconst code = computed(() => props.code.replace(/\\n$/, ''))\n\n/*\n * Plain lines until the highlighter answers. A synchronous highlighter\n * answers during setup, so server-rendered markup is already highlighted;\n * an async one fills in after. Only the latest call may land. While the\n * next answer is on its way, lines that were highlighted before and have\n * not changed keep their colors.\n */\nconst lines = shallowRef<string[]>(plainLines(code.value))\nlet run = 0\n// what the last answer covered, and its lines\nlet landed: { source: string; lines: string[] } | undefined\nwatchEffect(() => {\n const current = ++run\n const highlight = highlighter.value\n const raw = props.code\n // while streaming, the line still being written stays plain\n const cut = props.streaming ? raw.lastIndexOf('\\n') + 1 : raw.length\n const source = raw.slice(0, cut).replace(/\\n$/, '')\n const tail = props.streaming ? raw.slice(cut) : ''\n const after = tail ? plainLines(tail) : []\n if (!highlight || !source) {\n lines.value = plainLines(code.value)\n return\n }\n if (landed?.source === source) {\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n return\n }\n const kept = landed && source.startsWith(`${landed.source}\\n`) ? landed : undefined\n lines.value = kept\n ? [...kept.lines, ...plainLines(source.slice(kept.source.length + 1)), ...after]\n : [...plainLines(source), ...after]\n const apply = (html: string) => {\n if (current !== run) return\n landed = { source, lines: htmlLines(html) }\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n }\n try {\n const result = highlight(source, props.lang)\n if (typeof result === 'string') apply(result)\n else void result.then(apply, () => {})\n } catch {\n // a highlighter that throws leaves the plain text\n }\n})\n\nconst marked = computed(() => parseLines(props.highlightLines))\nconst rows = computed(() =>\n lines.value.map((html, index) => {\n const number = props.startLine + index\n return { html, number, marked: marked.value.has(number) }\n }),\n)\n\nconst expanded = ref(false)\nconst foldable = computed(() => props.maxLines !== undefined && rows.value.length > props.maxLines)\nconst folded = computed(() => foldable.value && !expanded.value)\n\nconst maxHeightValue = computed(() => {\n if (props.maxHeight === undefined || props.maxHeight === '') return undefined\n return typeof props.maxHeight === 'number' ? `${props.maxHeight}px` : props.maxHeight\n})\nconst scrollable = computed(() => maxHeightValue.value !== undefined)\n\nconst bodyRef = useTemplateRef<HTMLElement>('body')\nconst codeRef = useTemplateRef<HTMLElement>('codeEl')\nconst scrollbarWidth = ref(0)\n\nfunction syncScrollbarWidth() {\n const el = bodyRef.value\n if (!el || !scrollable.value || folded.value) {\n scrollbarWidth.value = 0\n return\n }\n scrollbarWidth.value = Math.max(0, el.offsetWidth - el.clientWidth)\n}\n\nconst AT_BOTTOM_THRESHOLD = 24\nconst shouldAutoScroll = computed(() => props.autoScroll ?? props.streaming)\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a choice of the reader: scrolling up pauses it, and reaching\n// the bottom resumes it. Appending content alone never turns it off.\nlet following = true\nlet scrollingToBottom = false\nlet lastScrollTop = 0\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - el.scrollTop - el.clientHeight\n}\n\nfunction isNearBottom(el: HTMLElement) {\n return distanceToBottom(el) <= AT_BOTTOM_THRESHOLD\n}\n\nfunction onBodyScroll() {\n const el = bodyRef.value\n if (!el) return\n const distance = distanceToBottom(el)\n const near = distance <= AT_BOTTOM_THRESHOLD\n if (el.scrollTop < lastScrollTop && distance > 1) {\n scrollingToBottom = false\n following = false\n } else if (near) {\n following = true\n scrollingToBottom = false\n } else if (scrollingToBottom && el.scrollTop >= lastScrollTop) {\n following = true\n } else if (el.scrollTop !== lastScrollTop) {\n scrollingToBottom = false\n following = false\n }\n lastScrollTop = el.scrollTop\n atBottom.value = near\n}\n\nfunction onBodyWheel(event: WheelEvent) {\n const el = bodyRef.value\n if (event.deltaY < 0 && el && el.scrollHeight > el.clientHeight) {\n following = false\n scrollingToBottom = false\n }\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = 'auto') {\n const el = bodyRef.value\n if (!el) return\n following = true\n const maxTop = Math.max(0, el.scrollHeight - el.clientHeight)\n if (behavior === 'smooth' && typeof el.scrollTo === 'function') {\n el.scrollTo({ top: el.scrollHeight, behavior })\n const near = isNearBottom(el)\n scrollingToBottom = !near\n lastScrollTop = el.scrollTop\n atBottom.value = near\n } else {\n scrollingToBottom = false\n el.scrollTop = maxTop\n lastScrollTop = el.scrollTop\n atBottom.value = true\n }\n}\n\nfunction follow() {\n syncScrollbarWidth()\n const el = bodyRef.value\n if (!el) return\n if (!shouldAutoScroll.value || !following || folded.value) {\n atBottom.value = isNearBottom(el)\n return\n }\n scrollingToBottom = false\n el.scrollTop = Math.max(0, el.scrollHeight - el.clientHeight)\n lastScrollTop = el.scrollTop\n atBottom.value = true\n}\n\nlet resizeObserver: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n resizeObserver = new ResizeObserver(follow)\n if (bodyRef.value) resizeObserver.observe(bodyRef.value)\n if (codeRef.value) resizeObserver.observe(codeRef.value)\n})\nonBeforeUnmount(() => resizeObserver?.disconnect())\n\nwatch(\n [() => props.code, lines, maxHeightValue, () => props.wrap, folded, shouldAutoScroll],\n follow,\n { flush: 'post' },\n)\n\nconst title = computed(() => props.filename ?? (props.lang === 'text' ? '' : props.lang))\nconst hasHeader = computed(() => !!(slots.title || title.value || slots.actions))\n\nconst classes = computed(() => [\n ns.b(),\n ns.is('wrap', props.wrap),\n ns.is('numbered', props.lineNumbers),\n ns.is('folded', folded.value),\n ns.is('scrollable', scrollable.value),\n ns.is('headless', !hasHeader.value),\n ns.is('streaming', props.streaming),\n ns.is('bordered', props.bordered),\n])\n\nconst rootStyle = computed(() => {\n const style: Record<string, string | number> = {}\n if (foldable.value && props.maxLines !== undefined) {\n style['--dou-code-block-max-lines'] = props.maxLines\n }\n if (maxHeightValue.value !== undefined) {\n style['--dou-code-block-max-height'] = maxHeightValue.value\n }\n if (scrollbarWidth.value > 0) {\n style['--dou-code-block-scrollbar-width'] = `${scrollbarWidth.value}px`\n }\n return Object.keys(style).length ? style : undefined\n})\n\ndefineExpose<CodeBlockExpose>({\n get body() {\n return bodyRef.value\n },\n scrollToBottom,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div :class=\"classes\" :style=\"rootStyle\">\n <div v-if=\"hasHeader\" :class=\"ns.e('header')\">\n <span :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </span>\n <span :class=\"ns.e('actions')\">\n <slot name=\"actions\" />\n <DouCopyButton v-if=\"copyable\" :text=\"code\" size=\"sm\" />\n </span>\n </div>\n <DouCopyButton v-else-if=\"copyable\" :class=\"ns.e('copy')\" :text=\"code\" size=\"sm\" />\n <div\n :id=\"bodyId\"\n ref=\"body\"\n :class=\"ns.e('body')\"\n :data-lang=\"lang\"\n :tabindex=\"scrollable && !folded ? 0 : undefined\"\n @scroll.passive=\"onBodyScroll\"\n @wheel.passive=\"onBodyWheel\"\n >\n <code ref=\"codeEl\" :class=\"ns.e('code')\">\n <span\n v-for=\"row in rows\"\n :key=\"row.number\"\n :class=\"[ns.e('row'), ns.is('marked', row.marked)]\"\n >\n <span v-if=\"lineNumbers\" :class=\"ns.e('number')\" aria-hidden=\"true\">{{\n row.number\n }}</span>\n <span :class=\"ns.e('line')\" v-html=\"row.html\" />\n </span>\n </code>\n </div>\n <button\n v-if=\"foldable\"\n type=\"button\"\n :class=\"ns.e('toggle')\"\n :aria-expanded=\"expanded\"\n :aria-controls=\"bodyId\"\n @click=\"expanded = !expanded\"\n >\n {{ expanded ? t('codeBlock.collapse') : t('codeBlock.expand', { count: rows.length }) }}\n </button>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -2,11 +2,12 @@ import { useNamespace } from "../../utils/namespace.js";
|
|
|
2
2
|
import { useGlobalConfig, useLocale } from "../config-provider/use-config.js";
|
|
3
3
|
import { DouCopyButton } from "../copy-button/index.js";
|
|
4
4
|
import { htmlLines, parseLines, plainLines } from "./lines.js";
|
|
5
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, ref, renderList, renderSlot, shallowRef, toDisplayString, unref, useId, useSlots, watchEffect } from "vue";
|
|
5
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, defineComponent, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, renderList, renderSlot, shallowRef, toDisplayString, unref, useId, useSlots, useTemplateRef, watch, watchEffect } from "vue";
|
|
6
6
|
// src/components/code-block/code-block.vue?vue&type=script&setup=true&lang.ts
|
|
7
|
-
var _hoisted_1 = ["data-lang"];
|
|
7
|
+
var _hoisted_1 = ["data-lang", "tabindex"];
|
|
8
8
|
var _hoisted_2 = ["innerHTML"];
|
|
9
9
|
var _hoisted_3 = ["aria-expanded"];
|
|
10
|
+
var AT_BOTTOM_THRESHOLD = 24;
|
|
10
11
|
var code_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
11
12
|
name: "DouCodeBlock",
|
|
12
13
|
__name: "code-block",
|
|
@@ -26,6 +27,7 @@ var code_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
26
27
|
default: false
|
|
27
28
|
},
|
|
28
29
|
maxLines: {},
|
|
30
|
+
maxHeight: { default: void 0 },
|
|
29
31
|
copyable: {
|
|
30
32
|
type: Boolean,
|
|
31
33
|
default: true
|
|
@@ -34,13 +36,19 @@ var code_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
34
36
|
type: Boolean,
|
|
35
37
|
default: false
|
|
36
38
|
},
|
|
39
|
+
autoScroll: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: void 0
|
|
42
|
+
},
|
|
37
43
|
bordered: {
|
|
38
44
|
type: Boolean,
|
|
39
45
|
default: true
|
|
40
46
|
}
|
|
41
47
|
},
|
|
42
|
-
|
|
48
|
+
emits: ["atBottomChange"],
|
|
49
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
43
50
|
const props = __props;
|
|
51
|
+
const emit = __emit;
|
|
44
52
|
const slots = useSlots();
|
|
45
53
|
const ns = useNamespace("code-block");
|
|
46
54
|
const { t } = useLocale();
|
|
@@ -99,6 +107,111 @@ var code_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
99
107
|
const expanded = ref(false);
|
|
100
108
|
const foldable = computed(() => props.maxLines !== void 0 && rows.value.length > props.maxLines);
|
|
101
109
|
const folded = computed(() => foldable.value && !expanded.value);
|
|
110
|
+
const maxHeightValue = computed(() => {
|
|
111
|
+
if (props.maxHeight === void 0 || props.maxHeight === "") return void 0;
|
|
112
|
+
return typeof props.maxHeight === "number" ? `${props.maxHeight}px` : props.maxHeight;
|
|
113
|
+
});
|
|
114
|
+
const scrollable = computed(() => maxHeightValue.value !== void 0);
|
|
115
|
+
const bodyRef = useTemplateRef("body");
|
|
116
|
+
const codeRef = useTemplateRef("codeEl");
|
|
117
|
+
const scrollbarWidth = ref(0);
|
|
118
|
+
function syncScrollbarWidth() {
|
|
119
|
+
const el = bodyRef.value;
|
|
120
|
+
if (!el || !scrollable.value || folded.value) {
|
|
121
|
+
scrollbarWidth.value = 0;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
scrollbarWidth.value = Math.max(0, el.offsetWidth - el.clientWidth);
|
|
125
|
+
}
|
|
126
|
+
const shouldAutoScroll = computed(() => props.autoScroll ?? props.streaming);
|
|
127
|
+
const atBottom = ref(true);
|
|
128
|
+
watch(atBottom, (value) => emit("atBottomChange", value));
|
|
129
|
+
let following = true;
|
|
130
|
+
let scrollingToBottom = false;
|
|
131
|
+
let lastScrollTop = 0;
|
|
132
|
+
function distanceToBottom(el) {
|
|
133
|
+
return el.scrollHeight - el.scrollTop - el.clientHeight;
|
|
134
|
+
}
|
|
135
|
+
function isNearBottom(el) {
|
|
136
|
+
return distanceToBottom(el) <= AT_BOTTOM_THRESHOLD;
|
|
137
|
+
}
|
|
138
|
+
function onBodyScroll() {
|
|
139
|
+
const el = bodyRef.value;
|
|
140
|
+
if (!el) return;
|
|
141
|
+
const distance = distanceToBottom(el);
|
|
142
|
+
const near = distance <= AT_BOTTOM_THRESHOLD;
|
|
143
|
+
if (el.scrollTop < lastScrollTop && distance > 1) {
|
|
144
|
+
scrollingToBottom = false;
|
|
145
|
+
following = false;
|
|
146
|
+
} else if (near) {
|
|
147
|
+
following = true;
|
|
148
|
+
scrollingToBottom = false;
|
|
149
|
+
} else if (scrollingToBottom && el.scrollTop >= lastScrollTop) following = true;
|
|
150
|
+
else if (el.scrollTop !== lastScrollTop) {
|
|
151
|
+
scrollingToBottom = false;
|
|
152
|
+
following = false;
|
|
153
|
+
}
|
|
154
|
+
lastScrollTop = el.scrollTop;
|
|
155
|
+
atBottom.value = near;
|
|
156
|
+
}
|
|
157
|
+
function onBodyWheel(event) {
|
|
158
|
+
const el = bodyRef.value;
|
|
159
|
+
if (event.deltaY < 0 && el && el.scrollHeight > el.clientHeight) {
|
|
160
|
+
following = false;
|
|
161
|
+
scrollingToBottom = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function scrollToBottom(behavior = "auto") {
|
|
165
|
+
const el = bodyRef.value;
|
|
166
|
+
if (!el) return;
|
|
167
|
+
following = true;
|
|
168
|
+
const maxTop = Math.max(0, el.scrollHeight - el.clientHeight);
|
|
169
|
+
if (behavior === "smooth" && typeof el.scrollTo === "function") {
|
|
170
|
+
el.scrollTo({
|
|
171
|
+
top: el.scrollHeight,
|
|
172
|
+
behavior
|
|
173
|
+
});
|
|
174
|
+
const near = isNearBottom(el);
|
|
175
|
+
scrollingToBottom = !near;
|
|
176
|
+
lastScrollTop = el.scrollTop;
|
|
177
|
+
atBottom.value = near;
|
|
178
|
+
} else {
|
|
179
|
+
scrollingToBottom = false;
|
|
180
|
+
el.scrollTop = maxTop;
|
|
181
|
+
lastScrollTop = el.scrollTop;
|
|
182
|
+
atBottom.value = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function follow() {
|
|
186
|
+
syncScrollbarWidth();
|
|
187
|
+
const el = bodyRef.value;
|
|
188
|
+
if (!el) return;
|
|
189
|
+
if (!shouldAutoScroll.value || !following || folded.value) {
|
|
190
|
+
atBottom.value = isNearBottom(el);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
scrollingToBottom = false;
|
|
194
|
+
el.scrollTop = Math.max(0, el.scrollHeight - el.clientHeight);
|
|
195
|
+
lastScrollTop = el.scrollTop;
|
|
196
|
+
atBottom.value = true;
|
|
197
|
+
}
|
|
198
|
+
let resizeObserver;
|
|
199
|
+
onMounted(() => {
|
|
200
|
+
follow();
|
|
201
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
202
|
+
resizeObserver = new ResizeObserver(follow);
|
|
203
|
+
if (bodyRef.value) resizeObserver.observe(bodyRef.value);
|
|
204
|
+
if (codeRef.value) resizeObserver.observe(codeRef.value);
|
|
205
|
+
});
|
|
206
|
+
onBeforeUnmount(() => resizeObserver?.disconnect());
|
|
207
|
+
watch([
|
|
208
|
+
() => props.code,
|
|
209
|
+
lines,
|
|
210
|
+
maxHeightValue,
|
|
211
|
+
() => props.wrap,
|
|
212
|
+
folded,
|
|
213
|
+
shouldAutoScroll
|
|
214
|
+
], follow, { flush: "post" });
|
|
102
215
|
const title = computed(() => props.filename ?? (props.lang === "text" ? "" : props.lang));
|
|
103
216
|
const hasHeader = computed(() => !!(slots.title || title.value || slots.actions));
|
|
104
217
|
const classes = computed(() => [
|
|
@@ -106,14 +219,31 @@ var code_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
106
219
|
ns.is("wrap", props.wrap),
|
|
107
220
|
ns.is("numbered", props.lineNumbers),
|
|
108
221
|
ns.is("folded", folded.value),
|
|
222
|
+
ns.is("scrollable", scrollable.value),
|
|
109
223
|
ns.is("headless", !hasHeader.value),
|
|
110
224
|
ns.is("streaming", props.streaming),
|
|
111
225
|
ns.is("bordered", props.bordered)
|
|
112
226
|
]);
|
|
227
|
+
const rootStyle = computed(() => {
|
|
228
|
+
const style = {};
|
|
229
|
+
if (foldable.value && props.maxLines !== void 0) style["--dou-code-block-max-lines"] = props.maxLines;
|
|
230
|
+
if (maxHeightValue.value !== void 0) style["--dou-code-block-max-height"] = maxHeightValue.value;
|
|
231
|
+
if (scrollbarWidth.value > 0) style["--dou-code-block-scrollbar-width"] = `${scrollbarWidth.value}px`;
|
|
232
|
+
return Object.keys(style).length ? style : void 0;
|
|
233
|
+
});
|
|
234
|
+
__expose({
|
|
235
|
+
get body() {
|
|
236
|
+
return bodyRef.value;
|
|
237
|
+
},
|
|
238
|
+
scrollToBottom,
|
|
239
|
+
get atBottom() {
|
|
240
|
+
return atBottom.value;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
113
243
|
return (_ctx, _cache) => {
|
|
114
244
|
return openBlock(), createElementBlock("div", {
|
|
115
245
|
class: normalizeClass(classes.value),
|
|
116
|
-
style: normalizeStyle(
|
|
246
|
+
style: normalizeStyle(rootStyle.value)
|
|
117
247
|
}, [
|
|
118
248
|
hasHeader.value ? (openBlock(), createElementBlock("div", {
|
|
119
249
|
key: 0,
|
|
@@ -130,9 +260,16 @@ var code_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
130
260
|
}, null, 8, ["class", "text"])) : createCommentVNode("", true),
|
|
131
261
|
createElementVNode("div", {
|
|
132
262
|
id: bodyId,
|
|
263
|
+
ref: "body",
|
|
133
264
|
class: normalizeClass(unref(ns).e("body")),
|
|
134
|
-
"data-lang": __props.lang
|
|
135
|
-
|
|
265
|
+
"data-lang": __props.lang,
|
|
266
|
+
tabindex: scrollable.value && !folded.value ? 0 : void 0,
|
|
267
|
+
onScrollPassive: onBodyScroll,
|
|
268
|
+
onWheelPassive: onBodyWheel
|
|
269
|
+
}, [createElementVNode("code", {
|
|
270
|
+
ref: "codeEl",
|
|
271
|
+
class: normalizeClass(unref(ns).e("code"))
|
|
272
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(rows.value, (row) => {
|
|
136
273
|
return openBlock(), createElementBlock("span", {
|
|
137
274
|
key: row.number,
|
|
138
275
|
class: normalizeClass([unref(ns).e("row"), unref(ns).is("marked", row.marked)])
|
|
@@ -144,7 +281,7 @@ var code_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
144
281
|
class: normalizeClass(unref(ns).e("line")),
|
|
145
282
|
innerHTML: row.html
|
|
146
283
|
}, null, 10, _hoisted_2)], 2);
|
|
147
|
-
}), 128))], 2)],
|
|
284
|
+
}), 128))], 2)], 42, _hoisted_1),
|
|
148
285
|
foldable.value ? (openBlock(), createElementBlock("button", {
|
|
149
286
|
key: 2,
|
|
150
287
|
type: "button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-block.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_unref","_createElementVNode","_renderSlot","_createTextVNode","_toDisplayString","_createBlock","_createCommentVNode","_Fragment","_renderList"],"sources":["../../../src/components/code-block/code-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, ref, shallowRef, useId, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useGlobalConfig, useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport type { CodeBlockHighlighter, CodeBlockProps, CodeBlockSlots } from './code-block'\nimport { htmlLines, parseLines, plainLines } from './lines'\n\ndefineOptions({ name: 'DouCodeBlock' })\n\nconst props = withDefaults(defineProps<CodeBlockProps>(), {\n code: '',\n lang: 'text',\n lineNumbers: false,\n startLine: 1,\n wrap: false,\n copyable: true,\n streaming: false,\n bordered: true,\n})\nconst slots = defineSlots<CodeBlockSlots>()\n\nconst ns = useNamespace('code-block')\nconst { t } = useLocale()\nconst config = useGlobalConfig()\nconst bodyId = `dou-code-block-${useId()}`\n\n// A function prop cannot take its default from ConfigProvider the way\n// other props do, so the configured one is read here.\nconst highlighter = computed<CodeBlockHighlighter | undefined>(\n () =>\n props.highlight ??\n (config.value.defaults as { DouCodeBlock?: { highlight?: CodeBlockHighlighter } }).DouCodeBlock\n ?.highlight,\n)\n\nconst code = computed(() => props.code.replace(/\\n$/, ''))\n\n/*\n * Plain lines until the highlighter answers. A synchronous highlighter\n * answers during setup, so server-rendered markup is already highlighted;\n * an async one fills in after. Only the latest call may land. While the\n * next answer is on its way, lines that were highlighted before and have\n * not changed keep their colors.\n */\nconst lines = shallowRef<string[]>(plainLines(code.value))\nlet run = 0\n// what the last answer covered, and its lines\nlet landed: { source: string; lines: string[] } | undefined\nwatchEffect(() => {\n const current = ++run\n const highlight = highlighter.value\n const raw = props.code\n // while streaming, the line still being written stays plain\n const cut = props.streaming ? raw.lastIndexOf('\\n') + 1 : raw.length\n const source = raw.slice(0, cut).replace(/\\n$/, '')\n const tail = props.streaming ? raw.slice(cut) : ''\n const after = tail ? plainLines(tail) : []\n if (!highlight || !source) {\n lines.value = plainLines(code.value)\n return\n }\n if (landed?.source === source) {\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n return\n }\n const kept = landed && source.startsWith(`${landed.source}\\n`) ? landed : undefined\n lines.value = kept\n ? [...kept.lines, ...plainLines(source.slice(kept.source.length + 1)), ...after]\n : [...plainLines(source), ...after]\n const apply = (html: string) => {\n if (current !== run) return\n landed = { source, lines: htmlLines(html) }\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n }\n try {\n const result = highlight(source, props.lang)\n if (typeof result === 'string') apply(result)\n else void result.then(apply, () => {})\n } catch {\n // a highlighter that throws leaves the plain text\n }\n})\n\nconst marked = computed(() => parseLines(props.highlightLines))\nconst rows = computed(() =>\n lines.value.map((html, index) => {\n const number = props.startLine + index\n return { html, number, marked: marked.value.has(number) }\n }),\n)\n\nconst expanded = ref(false)\nconst foldable = computed(() => props.maxLines !== undefined && rows.value.length > props.maxLines)\nconst folded = computed(() => foldable.value && !expanded.value)\n\nconst title = computed(() => props.filename ?? (props.lang === 'text' ? '' : props.lang))\nconst hasHeader = computed(() => !!(slots.title || title.value || slots.actions))\n\nconst classes = computed(() => [\n ns.b(),\n ns.is('wrap', props.wrap),\n ns.is('numbered', props.lineNumbers),\n ns.is('folded', folded.value),\n ns.is('headless', !hasHeader.value),\n ns.is('streaming', props.streaming),\n ns.is('bordered', props.bordered),\n])\n</script>\n\n<template>\n <div :class=\"classes\" :style=\"foldable ? { '--dou-code-block-max-lines': maxLines } : undefined\">\n <div v-if=\"hasHeader\" :class=\"ns.e('header')\">\n <span :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </span>\n <span :class=\"ns.e('actions')\">\n <slot name=\"actions\" />\n <DouCopyButton v-if=\"copyable\" :text=\"code\" size=\"sm\" />\n </span>\n </div>\n <DouCopyButton v-else-if=\"copyable\" :class=\"ns.e('copy')\" :text=\"code\" size=\"sm\" />\n <div :id=\"bodyId\" :class=\"ns.e('body')\" :data-lang=\"lang\">\n <code :class=\"ns.e('code')\">\n <span\n v-for=\"row in rows\"\n :key=\"row.number\"\n :class=\"[ns.e('row'), ns.is('marked', row.marked)]\"\n >\n <span v-if=\"lineNumbers\" :class=\"ns.e('number')\" aria-hidden=\"true\">{{\n row.number\n }}</span>\n <span :class=\"ns.e('line')\" v-html=\"row.html\" />\n </span>\n </code>\n </div>\n <button\n v-if=\"foldable\"\n type=\"button\"\n :class=\"ns.e('toggle')\"\n :aria-expanded=\"expanded\"\n :aria-controls=\"bodyId\"\n @click=\"expanded = !expanded\"\n >\n {{ expanded ? t('codeBlock.collapse') : t('codeBlock.expand', { count: rows.length }) }}\n </button>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUA,MAAM,QAAQ;EAUd,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,YAAY;EACpC,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,SAAS,gBAAgB;EAC/B,MAAM,SAAS,kBAAkB,MAAM;EAIvC,MAAM,cAAc,eAEhB,MAAM,aACL,OAAO,MAAM,SAAqE,cAC/E,SACR;EAEA,MAAM,OAAO,eAAe,MAAM,KAAK,QAAQ,OAAO,EAAE,CAAC;EASzD,MAAM,QAAQ,WAAqB,WAAW,KAAK,KAAK,CAAC;EACzD,IAAI,MAAM;EAEV,IAAI;EACJ,kBAAkB;GAChB,MAAM,UAAU,EAAE;GAClB,MAAM,YAAY,YAAY;GAC9B,MAAM,MAAM,MAAM;GAElB,MAAM,MAAM,MAAM,YAAY,IAAI,YAAY,IAAI,IAAI,IAAI,IAAI;GAC9D,MAAM,SAAS,IAAI,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,OAAO,EAAE;GAClD,MAAM,O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script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_unref","_createElementVNode","_renderSlot","_createTextVNode","_toDisplayString","_createBlock","_createCommentVNode","_Fragment","_renderList"],"sources":["../../../src/components/code-block/code-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\n useId,\n useTemplateRef,\n watch,\n watchEffect,\n} from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useGlobalConfig, useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport type {\n CodeBlockEmits,\n CodeBlockExpose,\n CodeBlockHighlighter,\n CodeBlockProps,\n CodeBlockSlots,\n} from './code-block'\nimport { htmlLines, parseLines, plainLines } from './lines'\n\ndefineOptions({ name: 'DouCodeBlock' })\n\nconst props = withDefaults(defineProps<CodeBlockProps>(), {\n code: '',\n lang: 'text',\n lineNumbers: false,\n startLine: 1,\n wrap: false,\n maxHeight: undefined,\n copyable: true,\n streaming: false,\n autoScroll: undefined,\n bordered: true,\n})\nconst emit = defineEmits<CodeBlockEmits>()\nconst slots = defineSlots<CodeBlockSlots>()\n\nconst ns = useNamespace('code-block')\nconst { t } = useLocale()\nconst config = useGlobalConfig()\nconst bodyId = `dou-code-block-${useId()}`\n\n// A function prop cannot take its default from ConfigProvider the way\n// other props do, so the configured one is read here.\nconst highlighter = computed<CodeBlockHighlighter | undefined>(\n () =>\n props.highlight ??\n (config.value.defaults as { DouCodeBlock?: { highlight?: CodeBlockHighlighter } }).DouCodeBlock\n ?.highlight,\n)\n\nconst code = computed(() => props.code.replace(/\\n$/, ''))\n\n/*\n * Plain lines until the highlighter answers. A synchronous highlighter\n * answers during setup, so server-rendered markup is already highlighted;\n * an async one fills in after. Only the latest call may land. While the\n * next answer is on its way, lines that were highlighted before and have\n * not changed keep their colors.\n */\nconst lines = shallowRef<string[]>(plainLines(code.value))\nlet run = 0\n// what the last answer covered, and its lines\nlet landed: { source: string; lines: string[] } | undefined\nwatchEffect(() => {\n const current = ++run\n const highlight = highlighter.value\n const raw = props.code\n // while streaming, the line still being written stays plain\n const cut = props.streaming ? raw.lastIndexOf('\\n') + 1 : raw.length\n const source = raw.slice(0, cut).replace(/\\n$/, '')\n const tail = props.streaming ? raw.slice(cut) : ''\n const after = tail ? plainLines(tail) : []\n if (!highlight || !source) {\n lines.value = plainLines(code.value)\n return\n }\n if (landed?.source === source) {\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n return\n }\n const kept = landed && source.startsWith(`${landed.source}\\n`) ? landed : undefined\n lines.value = kept\n ? [...kept.lines, ...plainLines(source.slice(kept.source.length + 1)), ...after]\n : [...plainLines(source), ...after]\n const apply = (html: string) => {\n if (current !== run) return\n landed = { source, lines: htmlLines(html) }\n lines.value = after.length ? [...landed.lines, ...after] : landed.lines\n }\n try {\n const result = highlight(source, props.lang)\n if (typeof result === 'string') apply(result)\n else void result.then(apply, () => {})\n } catch {\n // a highlighter that throws leaves the plain text\n }\n})\n\nconst marked = computed(() => parseLines(props.highlightLines))\nconst rows = computed(() =>\n lines.value.map((html, index) => {\n const number = props.startLine + index\n return { html, number, marked: marked.value.has(number) }\n }),\n)\n\nconst expanded = ref(false)\nconst foldable = computed(() => props.maxLines !== undefined && rows.value.length > props.maxLines)\nconst folded = computed(() => foldable.value && !expanded.value)\n\nconst maxHeightValue = computed(() => {\n if (props.maxHeight === undefined || props.maxHeight === '') return undefined\n return typeof props.maxHeight === 'number' ? `${props.maxHeight}px` : props.maxHeight\n})\nconst scrollable = computed(() => maxHeightValue.value !== undefined)\n\nconst bodyRef = useTemplateRef<HTMLElement>('body')\nconst codeRef = useTemplateRef<HTMLElement>('codeEl')\nconst scrollbarWidth = ref(0)\n\nfunction syncScrollbarWidth() {\n const el = bodyRef.value\n if (!el || !scrollable.value || folded.value) {\n scrollbarWidth.value = 0\n return\n }\n scrollbarWidth.value = Math.max(0, el.offsetWidth - el.clientWidth)\n}\n\nconst AT_BOTTOM_THRESHOLD = 24\nconst shouldAutoScroll = computed(() => props.autoScroll ?? props.streaming)\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a choice of the reader: scrolling up pauses it, and reaching\n// the bottom resumes it. Appending content alone never turns it off.\nlet following = true\nlet scrollingToBottom = false\nlet lastScrollTop = 0\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - el.scrollTop - el.clientHeight\n}\n\nfunction isNearBottom(el: HTMLElement) {\n return distanceToBottom(el) <= AT_BOTTOM_THRESHOLD\n}\n\nfunction onBodyScroll() {\n const el = bodyRef.value\n if (!el) return\n const distance = distanceToBottom(el)\n const near = distance <= AT_BOTTOM_THRESHOLD\n if (el.scrollTop < lastScrollTop && distance > 1) {\n scrollingToBottom = false\n following = false\n } else if (near) {\n following = true\n scrollingToBottom = false\n } else if (scrollingToBottom && el.scrollTop >= lastScrollTop) {\n following = true\n } else if (el.scrollTop !== lastScrollTop) {\n scrollingToBottom = false\n following = false\n }\n lastScrollTop = el.scrollTop\n atBottom.value = near\n}\n\nfunction onBodyWheel(event: WheelEvent) {\n const el = bodyRef.value\n if (event.deltaY < 0 && el && el.scrollHeight > el.clientHeight) {\n following = false\n scrollingToBottom = false\n }\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = 'auto') {\n const el = bodyRef.value\n if (!el) return\n following = true\n const maxTop = Math.max(0, el.scrollHeight - el.clientHeight)\n if (behavior === 'smooth' && typeof el.scrollTo === 'function') {\n el.scrollTo({ top: el.scrollHeight, behavior })\n const near = isNearBottom(el)\n scrollingToBottom = !near\n lastScrollTop = el.scrollTop\n atBottom.value = near\n } else {\n scrollingToBottom = false\n el.scrollTop = maxTop\n lastScrollTop = el.scrollTop\n atBottom.value = true\n }\n}\n\nfunction follow() {\n syncScrollbarWidth()\n const el = bodyRef.value\n if (!el) return\n if (!shouldAutoScroll.value || !following || folded.value) {\n atBottom.value = isNearBottom(el)\n return\n }\n scrollingToBottom = false\n el.scrollTop = Math.max(0, el.scrollHeight - el.clientHeight)\n lastScrollTop = el.scrollTop\n atBottom.value = true\n}\n\nlet resizeObserver: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n resizeObserver = new ResizeObserver(follow)\n if (bodyRef.value) resizeObserver.observe(bodyRef.value)\n if (codeRef.value) resizeObserver.observe(codeRef.value)\n})\nonBeforeUnmount(() => resizeObserver?.disconnect())\n\nwatch(\n [() => props.code, lines, maxHeightValue, () => props.wrap, folded, shouldAutoScroll],\n follow,\n { flush: 'post' },\n)\n\nconst title = computed(() => props.filename ?? (props.lang === 'text' ? '' : props.lang))\nconst hasHeader = computed(() => !!(slots.title || title.value || slots.actions))\n\nconst classes = computed(() => [\n ns.b(),\n ns.is('wrap', props.wrap),\n ns.is('numbered', props.lineNumbers),\n ns.is('folded', folded.value),\n ns.is('scrollable', scrollable.value),\n ns.is('headless', !hasHeader.value),\n ns.is('streaming', props.streaming),\n ns.is('bordered', props.bordered),\n])\n\nconst rootStyle = computed(() => {\n const style: Record<string, string | number> = {}\n if (foldable.value && props.maxLines !== undefined) {\n style['--dou-code-block-max-lines'] = props.maxLines\n }\n if (maxHeightValue.value !== undefined) {\n style['--dou-code-block-max-height'] = maxHeightValue.value\n }\n if (scrollbarWidth.value > 0) {\n style['--dou-code-block-scrollbar-width'] = `${scrollbarWidth.value}px`\n }\n return Object.keys(style).length ? style : undefined\n})\n\ndefineExpose<CodeBlockExpose>({\n get body() {\n return bodyRef.value\n },\n scrollToBottom,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div :class=\"classes\" :style=\"rootStyle\">\n <div v-if=\"hasHeader\" :class=\"ns.e('header')\">\n <span :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </span>\n <span :class=\"ns.e('actions')\">\n <slot name=\"actions\" />\n <DouCopyButton v-if=\"copyable\" :text=\"code\" size=\"sm\" />\n </span>\n </div>\n <DouCopyButton v-else-if=\"copyable\" :class=\"ns.e('copy')\" :text=\"code\" size=\"sm\" />\n <div\n :id=\"bodyId\"\n ref=\"body\"\n :class=\"ns.e('body')\"\n :data-lang=\"lang\"\n :tabindex=\"scrollable && !folded ? 0 : undefined\"\n @scroll.passive=\"onBodyScroll\"\n @wheel.passive=\"onBodyWheel\"\n >\n <code ref=\"codeEl\" :class=\"ns.e('code')\">\n <span\n v-for=\"row in rows\"\n :key=\"row.number\"\n :class=\"[ns.e('row'), ns.is('marked', row.marked)]\"\n >\n <span v-if=\"lineNumbers\" :class=\"ns.e('number')\" aria-hidden=\"true\">{{\n row.number\n }}</span>\n <span :class=\"ns.e('line')\" v-html=\"row.html\" />\n </span>\n </code>\n </div>\n <button\n v-if=\"foldable\"\n type=\"button\"\n :class=\"ns.e('toggle')\"\n :aria-expanded=\"expanded\"\n :aria-controls=\"bodyId\"\n @click=\"expanded = !expanded\"\n >\n {{ expanded ? t('codeBlock.collapse') : t('codeBlock.expand', { count: rows.length }) }}\n </button>\n </div>\n</template>\n"],"mappings":";;;;;;;;;AAsIA,IAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA5G5B,MAAM,QAAQ;EAYd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,YAAY;EACpC,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,SAAS,gBAAgB;EAC/B,MAAM,SAAS,kBAAkB,MAAM;EAIvC,MAAM,cAAc,eAEhB,MAAM,aACL,OAAO,MAAM,SAAqE,cAC/E,SACR;EAEA,MAAM,OAAO,eAAe,MAAM,KAAK,QAAQ,OAAO,EAAE,CAAC;EASzD,MAAM,QAAQ,WAAqB,WAAW,KAAK,KAAK,CAAC;EACzD,IAAI,MAAM;EAEV,IAAI;EACJ,kBAAkB;GAChB,MAAM,UAAU,EAAE;GAClB,MAAM,YAAY,YAAY;GAC9B,MAAM,MAAM,MAAM;GAElB,MAAM,MAAM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,UAAA,GAAAC,mBAES,QAAA;;MAFiB,OAAKC,eAAEE,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;MAAY,eAAY;KAC3D,GAAAI,gBAAA,IAAI,MAAM,GAAA,CAAA,K,8BAEZH,mBAAgD,QAAA;MAAzC,OAAKH,eAAEE,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;MAAU,WAAQ,IAAI;;;IAKtC,SAAA,SADRJ,UAAA,GAAAC,mBASS,UAAA;;KAPP,MAAK;KACJ,OAAKC,eAAEE,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;KACX,iBAAe,SAAA;KACf,iBAAe;KACf,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,SAAA,QAAQ,CAAI,SAAA;IAEjB,GAAAI,gBAAA,SAAA,QAAWJ,MAAA,CAAA,CAAC,CAAA,oBAAA,IAAyBA,MAAA,CAAA,CAAC,CAAA,oBAAA,EAAA,OAA8B,KAAA,MAAK,OAAM,CAAA,CAAA,GAAA,IAAA,UAAA,K"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dock-group.js","names":["_sfc_main"],"sources":["../../../src/components/dock/dock-group.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { inject, onBeforeUnmount, onMounted, onUpdated, ref, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouTabPanel, DouTabs } from '../tabs'\nimport { registerTabDropZone } from '../tabs/tab-drag'\nimport { dockKey } from './context'\nimport { dockDropSide } from './drop-side'\nimport type { FunctionalComponent } from 'vue'\nimport type { DockGroup, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDockGroup' })\n\nconst props = defineProps<{\n group: DockGroup\n /** Which slots the dock has; read in its render, so a slot that comes later shows up. */\n slotted: { label: boolean; extra: boolean; empty: boolean }\n}>()\nconst dock = inject(dockKey)!\nconst ns = useNamespace('dock')\n\n/* the edges of the body split a tab off, the middle takes it in */\n\nconst el = useTemplateRef<HTMLElement>('el')\nconst target = ref<DockSide | 'center' | null>(null)\n\nfunction sideAt(x: number, y: number) {\n return dockDropSide(el.value!.getBoundingClientRect(), x, y, {\n width: dock.min('horizontal'),\n height: dock.min('vertical'),\n })\n}\n\nconst zone = registerTabDropZone({\n el: () => el.value,\n accepts: (drag) => drag.group === dock.group,\n over(drag, x, y) {\n const side = sideAt(x, y)\n target.value = dock.canDrop(drag, props.group, side) ? side : null\n },\n leave: () => (target.value = null),\n drop(drag) {\n const side = target.value\n target.value = null\n if (side) dock.drop(drag, props.group, side)\n },\n})\nonMounted(() => zone.update())\nonUpdated(() => zone.update())\nonBeforeUnmount(() => zone.remove())\n\n/** Renders what a slot of the dock gives back, under one component type so it is not remounted. */\nconst Outlet: FunctionalComponent<{ render: () => unknown }> = (outlet) =>\n outlet.render() as ReturnType<FunctionalComponent>\n\nconst label = (value: string | number) => dock.panel(value)?.label ?? String(value)\n</script>\n\n<template>\n <div\n ref=\"el\"\n :class=\"[ns.e('group'), ns.is('empty', !group.tabs.length)]\"\n :data-dock-group=\"group.id\"\n @pointerdown.capture=\"dock.use(group.id)\"\n @focusin=\"dock.use(group.id)\"\n >\n <DouTabs\n :model-value=\"group.active ?? group.tabs[0]\"\n :name=\"group.id\"\n :group=\"dock.group\"\n :size=\"dock.size()\"\n :closable=\"dock.closable()\"\n :addable=\"dock.addable()\"\n height=\"100%\"\n :draggable=\"dock.draggable()\"\n @update:model-value=\"$event !== undefined && dock.select(group, $event)\"\n @move=\"dock.move\"\n @remove=\"dock.remove($event, group)\"\n @add=\"dock.add(group)\"\n >\n <DouTabPanel\n v-for=\"value in group.tabs\"\n :key=\"value\"\n :value=\"value\"\n :label=\"label(value)\"\n :icon=\"dock.panel(value)?.icon\"\n :closable=\"dock.panel(value)?.closable\"\n :disabled=\"dock.panel(value)?.disabled\"\n :draggable=\"dock.panel(value)?.draggable\"\n >\n <template v-if=\"slotted.label\" #label=\"{ selected }\">\n <Outlet :render=\"() => dock.slots.label?.({ value, selected })\" />\n </template>\n <Outlet :render=\"() => dock.slots.default?.({ value })\" />\n </DouTabPanel>\n <template v-if=\"slotted.extra\" #extra>\n <Outlet\n :render=\"() => dock.slots.extra?.({ group, active: group.active ?? group.tabs[0] })\"\n />\n </template>\n </DouTabs>\n <div v-if=\"!group.tabs.length && slotted.empty\" :class=\"ns.e('empty')\">\n <Outlet :render=\"() => dock.slots.empty?.()\" />\n </div>\n <div\n :class=\"[ns.e('drop'), target && ns.is(target, true), ns.is('shown', !!target)]\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"dock-group.js","names":["_sfc_main"],"sources":["../../../src/components/dock/dock-group.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { inject, onBeforeUnmount, onMounted, onUpdated, ref, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouTabPanel, DouTabs } from '../tabs'\nimport { registerTabDropZone } from '../tabs/tab-drag'\nimport { dockKey } from './context'\nimport { dockDropSide } from './drop-side'\nimport type { FunctionalComponent } from 'vue'\nimport type { DockGroup, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDockGroup' })\n\nconst props = defineProps<{\n group: DockGroup\n /** Which slots the dock has; read in its render, so a slot that comes later shows up. */\n slotted: { label: boolean; extra: boolean; empty: boolean }\n}>()\nconst dock = inject(dockKey)!\nconst ns = useNamespace('dock')\n\n/* the edges of the body split a tab off, the middle takes it in */\n\nconst el = useTemplateRef<HTMLElement>('el')\nconst target = ref<DockSide | 'center' | null>(null)\n\nfunction sideAt(x: number, y: number) {\n return dockDropSide(el.value!.getBoundingClientRect(), x, y, {\n width: dock.min('horizontal'),\n height: dock.min('vertical'),\n })\n}\n\nconst zone = registerTabDropZone({\n el: () => el.value,\n accepts: (drag) => drag.group === dock.group,\n over(drag, x, y) {\n const side = sideAt(x, y)\n target.value = dock.canDrop(drag, props.group, side) ? side : null\n },\n leave: () => (target.value = null),\n drop(drag) {\n const side = target.value\n target.value = null\n if (side) dock.drop(drag, props.group, side)\n },\n})\nonMounted(() => zone.update())\nonUpdated(() => zone.update())\nonBeforeUnmount(() => zone.remove())\n\n/** Renders what a slot of the dock gives back, under one component type so it is not remounted. */\nconst Outlet: FunctionalComponent<{ render: () => unknown }> = (outlet) =>\n outlet.render() as ReturnType<FunctionalComponent>\n\nconst label = (value: string | number) => dock.panel(value)?.label ?? String(value)\n</script>\n\n<template>\n <div\n ref=\"el\"\n :class=\"[ns.e('group'), ns.is('empty', !group.tabs.length)]\"\n :data-dock-group=\"group.id\"\n @pointerdown.capture=\"dock.use(group.id)\"\n @focusin=\"dock.use(group.id)\"\n >\n <DouTabs\n :model-value=\"group.active ?? group.tabs[0]\"\n :name=\"group.id\"\n :group=\"dock.group\"\n :size=\"dock.size()\"\n :closable=\"dock.closable()\"\n :addable=\"dock.addable()\"\n height=\"100%\"\n :draggable=\"dock.draggable()\"\n @update:model-value=\"$event !== undefined && dock.select(group, $event)\"\n @move=\"dock.move\"\n @remove=\"dock.remove($event, group)\"\n @add=\"dock.add(group)\"\n >\n <DouTabPanel\n v-for=\"value in group.tabs\"\n :key=\"value\"\n :value=\"value\"\n :label=\"label(value)\"\n :icon=\"dock.panel(value)?.icon\"\n :closable=\"dock.panel(value)?.closable\"\n :disabled=\"dock.panel(value)?.disabled\"\n :draggable=\"dock.panel(value)?.draggable\"\n :pinned=\"dock.panel(value)?.pinned\"\n >\n <template v-if=\"slotted.label\" #label=\"{ selected }\">\n <Outlet :render=\"() => dock.slots.label?.({ value, selected })\" />\n </template>\n <Outlet :render=\"() => dock.slots.default?.({ value })\" />\n </DouTabPanel>\n <template v-if=\"slotted.extra\" #extra>\n <Outlet\n :render=\"() => dock.slots.extra?.({ group, active: group.active ?? group.tabs[0] })\"\n />\n </template>\n </DouTabs>\n <div v-if=\"!group.tabs.length && slotted.empty\" :class=\"ns.e('empty')\">\n <Outlet :render=\"() => dock.slots.empty?.()\" />\n </div>\n <div\n :class=\"[ns.e('drop'), target && ns.is(target, true), ns.is('shown', !!target)]\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -76,7 +76,8 @@ var dock_group_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
76
76
|
icon: unref(dock).panel(value)?.icon,
|
|
77
77
|
closable: unref(dock).panel(value)?.closable,
|
|
78
78
|
disabled: unref(dock).panel(value)?.disabled,
|
|
79
|
-
draggable: unref(dock).panel(value)?.draggable
|
|
79
|
+
draggable: unref(dock).panel(value)?.draggable,
|
|
80
|
+
pinned: unref(dock).panel(value)?.pinned
|
|
80
81
|
}, createSlots({
|
|
81
82
|
default: withCtx(() => [createVNode(Outlet, { render: () => unref(dock).slots.default?.({ value }) }, null, 8, ["render"])]),
|
|
82
83
|
_: 2
|
|
@@ -93,7 +94,8 @@ var dock_group_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
93
94
|
"icon",
|
|
94
95
|
"closable",
|
|
95
96
|
"disabled",
|
|
96
|
-
"draggable"
|
|
97
|
+
"draggable",
|
|
98
|
+
"pinned"
|
|
97
99
|
]);
|
|
98
100
|
}), 128))]),
|
|
99
101
|
_: 2
|