dou-ui 0.1.0-alpha.3 → 0.1.0-alpha.4
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/card/card.js.map +1 -1
- package/dist/components/card/card.vue_vue_type_script_setup_true_lang.js +45 -19
- package/dist/components/card/card.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-confirm/chat-confirm.js.map +1 -1
- package/dist/components/chat-confirm/chat-confirm.vue_vue_type_script_setup_true_lang.js +2 -3
- package/dist/components/chat-confirm/chat-confirm.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input.js.map +1 -1
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +75 -7
- 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 +9 -4
- 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 +34 -0
- 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 +6 -0
- package/dist/components/chat-list/chat-list2.js.map +1 -0
- package/dist/components/chat-list/index.js +1 -1
- package/dist/components/chat-message/chat-message.js.map +1 -1
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js +32 -7
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-message/chat-message2.js.map +1 -1
- package/dist/components/chat-message/style.js +1 -0
- package/dist/components/chat-question/chat-question.js +6 -0
- package/dist/components/chat-question/chat-question.js.map +1 -0
- package/dist/components/chat-question/chat-question.vue_vue_type_script_setup_true_lang.js +116 -0
- package/dist/components/chat-question/chat-question.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/chat-question/index.js +7 -0
- package/dist/components/chat-question/index.js.map +1 -0
- package/dist/components/chat-question/style.d.ts +1 -0
- package/dist/components/chat-question/style.js +2 -0
- package/dist/components/comment-thread/comment-thread.js.map +1 -1
- package/dist/components/comment-thread/comment-thread.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/comment-thread/comment-thread.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/config-provider/use-config.js +5 -2
- package/dist/components/config-provider/use-config.js.map +1 -1
- package/dist/components/dialog/functional.js +3 -7
- package/dist/components/dialog/functional.js.map +1 -1
- package/dist/components/dialog/index.js +4 -3
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/image/image.js.map +1 -1
- package/dist/components/image/image.vue_vue_type_script_setup_true_lang.js +10 -1
- package/dist/components/image/image.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/link/link.js.map +1 -1
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js +116 -31
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-actions.js +65 -0
- package/dist/components/menu/menu-actions.js.map +1 -0
- package/dist/components/menu/menu-item.js.map +1 -1
- package/dist/components/menu/menu-item.vue_vue_type_script_setup_true_lang.js +50 -12
- package/dist/components/menu/menu-item.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-list.js.map +1 -1
- package/dist/components/menu/menu-list.vue_vue_type_script_setup_true_lang.js +32 -17
- package/dist/components/menu/menu-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-popup.js.map +1 -1
- package/dist/components/menu/menu-popup.vue_vue_type_script_setup_true_lang.js +37 -8
- package/dist/components/menu/menu-popup.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu.js +1 -0
- package/dist/components/menu/menu.js.map +1 -1
- package/dist/components/menu/menu.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/menu/menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu2.js.map +1 -1
- package/dist/components/node-graph/layout.js +123 -15
- package/dist/components/node-graph/layout.js.map +1 -1
- package/dist/components/toast/index.js +5 -4
- package/dist/components/toast/index.js.map +1 -1
- package/dist/components/toast/store.js +1 -9
- package/dist/components/toast/store.js.map +1 -1
- package/dist/components/virtual-list/virtual-list.js +7 -1
- package/dist/components/virtual-list/virtual-list.js.map +1 -1
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js +2 -7
- 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/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/locale/en.js +1 -0
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/zh-cn.js +1 -0
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-tw.js +1 -0
- package/dist/locale/zh-tw.js.map +1 -1
- package/dist/plugin.js +4 -0
- package/dist/plugin.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/card/card.d.ts +6 -1
- package/dist/types/components/chat-input/chat-input.d.ts +33 -3
- package/dist/types/components/chat-input/chat-input.vue.d.ts +7 -0
- package/dist/types/components/chat-input/index.d.ts +20 -0
- package/dist/types/components/chat-list/chat-list.d.ts +19 -1
- package/dist/types/components/chat-message/chat-message.d.ts +32 -2
- package/dist/types/components/chat-message/chat-message.vue.d.ts +4 -1
- package/dist/types/components/chat-message/index.d.ts +8 -0
- package/dist/types/components/chat-question/chat-question.d.ts +43 -0
- package/dist/types/components/chat-question/chat-question.vue.d.ts +18 -0
- package/dist/types/components/chat-question/index.d.ts +43 -0
- package/dist/types/components/comment-thread/comment-thread.d.ts +6 -0
- package/dist/types/components/comment-thread/comment-thread.vue.d.ts +1 -0
- package/dist/types/components/comment-thread/index.d.ts +3 -0
- package/dist/types/components/dialog/functional.d.ts +0 -3
- package/dist/types/components/dialog/index.d.ts +1 -1
- package/dist/types/components/image/image.d.ts +9 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/link/index.d.ts +3 -0
- package/dist/types/components/link/link.d.ts +24 -3
- package/dist/types/components/link/link.vue.d.ts +1 -0
- package/dist/types/components/menu/index.d.ts +3 -0
- package/dist/types/components/menu/menu-actions.d.ts +26 -0
- package/dist/types/components/menu/menu-item.vue.d.ts +6 -0
- package/dist/types/components/menu/menu.d.ts +32 -0
- package/dist/types/components/menu/menu.vue.d.ts +1 -0
- package/dist/types/components/node-graph/layout.d.ts +26 -0
- package/dist/types/components/select/index.d.ts +3 -3
- package/dist/types/components/select/select.vue.d.ts +1 -1
- package/dist/types/components/toast/index.d.ts +0 -2
- package/dist/types/components/toast/store.d.ts +0 -4
- package/dist/types/components/virtual-list/virtual-list.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/locale/types.d.ts +3 -1
- package/dist/types/utils/app-context.d.ts +14 -0
- package/dist/utils/app-context.js +22 -0
- package/dist/utils/app-context.js.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-message2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-message/chat-message.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronLeftIcon, ChevronRightIcon, EditIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useTemplateRef } from 'vue'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouButton } from '../button'\nimport { DouChatArtifact } from '../chat-artifact'\nimport { DouChatAttachments } from '../chat-attachments'\nimport { DouChatConfirm } from '../chat-confirm'\nimport { DouChatPlan } from '../chat-plan'\nimport { planRunning, type ChatPlanItem } from '../chat-plan/chat-plan'\nimport { DouChatReasoning } from '../chat-reasoning'\nimport { DouChatSources } from '../chat-sources'\nimport { DouChatSteps } from '../chat-steps'\nimport { stepsLive, type ChatStep } from '../chat-steps/chat-steps'\nimport { DouChatToolCall } from '../chat-tool-call'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport { DouMarkdown } from '../markdown'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport { DouStreamText } from '../stream-text'\nimport { DouTooltip } from '../tooltip'\nimport { messageText } from './chat-message'\nimport type {\n ChatArtifactPart,\n ChatConfirmPart,\n ChatCustomPart,\n ChatMessageEmits,\n ChatMessagePart,\n ChatMessageMarkdownSlots,\n ChatMessageProps,\n ChatMessageSlots,\n} from './chat-message'\n\ndefineOptions({ name: 'DouChatMessage' })\n\nconst props = withDefaults(defineProps<ChatMessageProps>(), {\n sender: 'assistant',\n loading: false,\n copyable: true,\n editable: false,\n markdown: false,\n versions: 1,\n version: undefined,\n})\nconst emit = defineEmits<ChatMessageEmits>()\nconst slots = defineSlots<ChatMessageSlots & ChatMessageMarkdownSlots>()\n\nconst ns = useNamespace('chat-message')\nconst { t } = useLocale()\n\ntype AnyPart = ChatMessagePart | ChatCustomPart\n\nconst parts = computed<AnyPart[]>(\n () => props.parts ?? (props.content === undefined ? [] : [{ type: 'text', text: props.content }]),\n)\nconst markdownOptions = computed(() =>\n typeof props.markdown === 'object' ? props.markdown : undefined,\n)\n// `markdown-code` here is the Markdown component's `code`\nconst PREFIX = 'markdown-'\nconst markdownSlots = () =>\n Object.keys(slots)\n .filter((name) => name.startsWith(PREFIX))\n .map((name) => ({\n name: name as keyof ChatMessageMarkdownSlots,\n inner: name.slice(PREFIX.length),\n }))\nconst isUser = computed(() => props.sender === 'user')\n// the person's attachments sit above their bubble, not inside it\nconst files = computed(() => (isUser.value ? parts.value.filter((p) => p.type === 'files') : []))\nconst body = computed(() =>\n isUser.value ? parts.value.filter((p) => p.type !== 'files') : parts.value,\n)\nconst text = computed(() => messageText(parts.value as { type: string; text?: unknown }[]))\n// Every source of the message, numbered in order, for `[1]` in Markdown\n// text. The same array while the sources stay the same, so text that\n// streams in does not redraw the whole reply.\nlet lastSources: ChatSource[] = []\nconst sources = computed(() => {\n const next = parts.value.flatMap((part) =>\n part.type === 'sources' ? ((part as { items?: ChatSource[] }).items ?? []) : [],\n )\n if (next.length === lastSources.length && next.every((s, i) => s === lastSources[i]))\n return lastSources\n return (lastSources = next)\n})\n\nconst busy = computed(\n () =>\n props.loading ||\n parts.value.some((part) => {\n const p = part as Record<string, unknown>\n // an artifact can keep being made after the reply ends, so it doesn't hold the actions back\n const working = p.status === 'running' && p.type !== 'artifact' && p.live !== false\n // busy exactly when steps or a plan show themselves running\n const live = p.live as boolean | undefined\n const steps = p.type === 'steps' && stepsLive(p.items as ChatStep[] | undefined, live)\n const plan = p.type === 'plan' && planRunning(p.items as ChatPlanItem[] | undefined, live)\n return !!p.streaming || !!p.thinking || steps || plan || working\n }),\n)\n\nconst innerVersion = ref(props.versions)\nconst version = computed(() => Math.min(props.version ?? innerVersion.value, props.versions))\nfunction step(delta: number) {\n const next = Math.min(Math.max(version.value + delta, 1), props.versions)\n innerVersion.value = next\n emit('update:version', next)\n}\n\nconst showActions = computed(\n () =>\n !busy.value &&\n (props.versions > 1 ||\n (props.copyable && !!text.value) ||\n (props.editable && isUser.value) ||\n !!slots.actions),\n)\n\n// editing in place\nconst editing = ref(false)\nconst draft = ref('')\nconst editorRef = useTemplateRef<HTMLTextAreaElement>('editor')\nfunction startEdit() {\n draft.value = text.value\n editing.value = true\n void nextTick(() => {\n const el = editorRef.value\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n fitEditor()\n })\n}\nfunction cancelEdit() {\n editing.value = false\n}\nfunction saveEdit() {\n if (!draft.value.trim()) return\n editing.value = false\n emit('edit', draft.value)\n}\nfunction fitEditor() {\n const el = editorRef.value\n if (!el) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nfunction onEditorKeydown(event: KeyboardEvent) {\n if (event.key === 'Escape') {\n event.preventDefault()\n cancelEdit()\n } else if (event.key === 'Enter' && !event.shiftKey && !isComposing(event)) {\n event.preventDefault()\n saveEdit()\n }\n}\n\nconst asText = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'text' }>\nconst asReasoning = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'reasoning' }>\nconst asFiles = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'files' }>\nconst asConfirm = (part: AnyPart) => part as ChatConfirmPart\nconst asArtifact = (part: AnyPart) => part as ChatArtifactPart\nconst known = new Set([\n 'text',\n 'reasoning',\n 'tool',\n 'steps',\n 'plan',\n 'sources',\n 'files',\n 'artifact',\n 'confirm',\n])\n// props for the part components, without the `type` discriminator\nconst rest = (part: AnyPart) => {\n const { type: _type, ...others } = part as Record<string, unknown>\n return others\n}\n</script>\n\n<template>\n <div\n :class=\"[ns.b(), ns.m(sender), ns.is('loading', loading), ns.is('editing', editing)]\"\n :aria-busy=\"busy || undefined\"\n >\n <div v-if=\"files.length && !editing\" :class=\"ns.e('files')\">\n <template v-for=\"(part, index) in files\" :key=\"`f${index}`\">\n <DouChatAttachments :model-value=\"asFiles(part).files\" :removable=\"false\" />\n </template>\n </div>\n\n <div v-if=\"editing\" :class=\"ns.e('editor')\">\n <textarea\n ref=\"editor\"\n v-model=\"draft\"\n :class=\"ns.e('editor-native')\"\n rows=\"1\"\n :aria-label=\"t('chat.edit')\"\n @input=\"fitEditor\"\n @keydown=\"onEditorKeydown\"\n />\n <div :class=\"ns.e('editor-actions')\">\n <DouButton size=\"sm\" variant=\"ghost\" @click=\"cancelEdit\">{{ t('chat.cancel') }}</DouButton>\n <DouButton size=\"sm\" :disabled=\"!draft.trim()\" @click=\"saveEdit\">\n {{ t('chat.send') }}\n </DouButton>\n </div>\n </div>\n\n <div v-else-if=\"body.length || loading || slots.default\" :class=\"ns.e('content')\">\n <slot>\n <template v-for=\"(part, index) in body\" :key=\"index\">\n <DouMarkdown\n v-if=\"part.type === 'text' && markdown && !slots.text\"\n v-bind=\"markdownOptions\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n :sources=\"sources.length ? sources : undefined\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else-if=\"part.type === 'text'\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n >\n <template v-if=\"slots.text\" #default=\"{ text: shown }\">\n <slot\n name=\"text\"\n :part=\"asText(part)\"\n :text=\"shown\"\n :index=\"index\"\n :sources=\"sources\"\n />\n </template>\n </DouStreamText>\n <DouChatReasoning\n v-else-if=\"part.type === 'reasoning'\"\n :thinking=\"!!asReasoning(part).thinking\"\n :duration=\"asReasoning(part).duration\"\n >\n <DouMarkdown\n v-if=\"markdown\"\n v-bind=\"markdownOptions\"\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n />\n </DouChatReasoning>\n <DouChatToolCall v-else-if=\"part.type === 'tool'\" v-bind=\"rest(part)\" />\n <DouChatSteps v-else-if=\"part.type === 'steps'\" v-bind=\"rest(part)\" />\n <DouChatPlan v-else-if=\"part.type === 'plan'\" v-bind=\"rest(part)\" />\n <DouChatSources v-else-if=\"part.type === 'sources'\" v-bind=\"rest(part)\" />\n <DouChatAttachments\n v-else-if=\"part.type === 'files'\"\n :model-value=\"asFiles(part).files\"\n :removable=\"false\"\n />\n <DouChatArtifact\n v-else-if=\"part.type === 'artifact'\"\n v-bind=\"rest(part)\"\n @open=\"emit('artifact', asArtifact(part))\"\n />\n <DouChatConfirm\n v-else-if=\"part.type === 'confirm'\"\n :title=\"asConfirm(part).title\"\n :description=\"asConfirm(part).description\"\n :status=\"asConfirm(part).status\"\n :allow-always=\"asConfirm(part).allowAlways\"\n :tone=\"asConfirm(part).tone\"\n @decide=\"emit('confirm', asConfirm(part), $event)\"\n >\n <pre v-if=\"asConfirm(part).detail\" :class=\"ns.e('code')\">{{\n asConfirm(part).detail\n }}</pre>\n </DouChatConfirm>\n <slot\n v-else-if=\"!known.has(part.type)\"\n name=\"part\"\n :part=\"part as ChatCustomPart\"\n :index=\"index\"\n />\n </template>\n </slot>\n <span v-if=\"loading\" :class=\"ns.e('loading')\" role=\"status\" :aria-label=\"t('chat.loading')\">\n <i /><i /><i />\n </span>\n </div>\n\n <div v-if=\"showActions && !editing\" :class=\"ns.e('actions')\">\n <div\n v-if=\"versions > 1\"\n :class=\"ns.e('versions')\"\n role=\"group\"\n :aria-label=\"t('chat.versions')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version <= 1\"\n :aria-label=\"t('chat.previousVersion')\"\n @click=\"step(-1)\"\n >\n <ChevronLeftIcon />\n </DouButton>\n <span :class=\"ns.e('version')\">{{ version }} / {{ versions }}</span>\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version >= versions\"\n :aria-label=\"t('chat.nextVersion')\"\n @click=\"step(1)\"\n >\n <ChevronRightIcon />\n </DouButton>\n </div>\n <DouCopyButton v-if=\"copyable && text\" size=\"sm\" :text=\"text\" />\n <DouTooltip v-if=\"editable && isUser\" :content=\"t('chat.edit')\">\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('chat.edit')\" @click=\"startEdit\">\n <EditIcon />\n </DouButton>\n </DouTooltip>\n <slot name=\"actions\" />\n </div>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"chat-message2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-message/chat-message.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronLeftIcon, ChevronRightIcon, EditIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useTemplateRef } from 'vue'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouButton } from '../button'\nimport { DouChatArtifact } from '../chat-artifact'\nimport { DouChatAttachments } from '../chat-attachments'\nimport { DouChatConfirm } from '../chat-confirm'\nimport { DouChatQuestion } from '../chat-question'\nimport { DouChatPlan } from '../chat-plan'\nimport { planRunning, type ChatPlanItem } from '../chat-plan/chat-plan'\nimport { DouChatReasoning } from '../chat-reasoning'\nimport { DouChatSources } from '../chat-sources'\nimport { DouChatSteps } from '../chat-steps'\nimport { stepsLive, type ChatStep } from '../chat-steps/chat-steps'\nimport { DouChatToolCall } from '../chat-tool-call'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouCopyButton } from '../copy-button'\nimport { DouMarkdown } from '../markdown'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport { DouStreamText } from '../stream-text'\nimport { DouTooltip } from '../tooltip'\nimport { messageText } from './chat-message'\nimport type {\n ChatArtifactPart,\n ChatConfirmPart,\n ChatQuestionPart,\n ChatCustomPart,\n ChatMessageEmits,\n ChatMessagePart,\n ChatMessageMarkdownSlots,\n ChatMessageProps,\n ChatMessageSlots,\n} from './chat-message'\n\ndefineOptions({ name: 'DouChatMessage' })\n\nconst props = withDefaults(defineProps<ChatMessageProps>(), {\n sender: 'assistant',\n loading: false,\n copyable: true,\n editable: false,\n markdown: false,\n actionsVisible: undefined,\n versions: 1,\n version: undefined,\n})\nconst emit = defineEmits<ChatMessageEmits>()\nconst slots = defineSlots<ChatMessageSlots & ChatMessageMarkdownSlots>()\n\nconst ns = useNamespace('chat-message')\nconst { t } = useLocale()\n\ntype AnyPart = ChatMessagePart | ChatCustomPart\n\nconst parts = computed<AnyPart[]>(\n () => props.parts ?? (props.content === undefined ? [] : [{ type: 'text', text: props.content }]),\n)\nconst markdownOptions = computed(() =>\n typeof props.markdown === 'object' ? props.markdown : undefined,\n)\n// `markdown-code` here is the Markdown component's `code`\nconst PREFIX = 'markdown-'\nconst markdownSlots = () =>\n Object.keys(slots)\n .filter((name) => name.startsWith(PREFIX))\n .map((name) => ({\n name: name as keyof ChatMessageMarkdownSlots,\n inner: name.slice(PREFIX.length),\n }))\nconst isUser = computed(() => props.sender === 'user')\nconst actionsShow = computed(() => props.actionsVisible ?? (isUser.value ? 'hover' : 'always'))\n// the person's attachments sit above their bubble, not inside it\nconst files = computed(() => (isUser.value ? parts.value.filter((p) => p.type === 'files') : []))\nconst body = computed(() =>\n isUser.value ? parts.value.filter((p) => p.type !== 'files') : parts.value,\n)\nconst text = computed(() => messageText(parts.value as { type: string; text?: unknown }[]))\n// Every source of the message, numbered in order, for `[1]` in Markdown\n// text. The same array while the sources stay the same, so text that\n// streams in does not redraw the whole reply.\nlet lastSources: ChatSource[] = []\nconst sources = computed(() => {\n const next = parts.value.flatMap((part) =>\n part.type === 'sources' ? ((part as { items?: ChatSource[] }).items ?? []) : [],\n )\n if (next.length === lastSources.length && next.every((s, i) => s === lastSources[i]))\n return lastSources\n return (lastSources = next)\n})\n\nconst busy = computed(\n () =>\n props.loading ||\n parts.value.some((part) => {\n const p = part as Record<string, unknown>\n // an artifact can keep being made after the reply ends, so it doesn't hold the actions back\n const working = p.status === 'running' && p.type !== 'artifact' && p.live !== false\n // busy exactly when steps or a plan show themselves running\n const live = p.live as boolean | undefined\n const steps = p.type === 'steps' && stepsLive(p.items as ChatStep[] | undefined, live)\n const plan = p.type === 'plan' && planRunning(p.items as ChatPlanItem[] | undefined, live)\n return !!p.streaming || !!p.thinking || steps || plan || working\n }),\n)\n\nconst innerVersion = ref(props.versions)\nconst version = computed(() => Math.min(props.version ?? innerVersion.value, props.versions))\nfunction step(delta: number) {\n const next = Math.min(Math.max(version.value + delta, 1), props.versions)\n innerVersion.value = next\n emit('update:version', next)\n}\n\nconst showActions = computed(\n () =>\n !busy.value &&\n (props.versions > 1 ||\n (props.copyable && !!text.value) ||\n (props.editable && isUser.value) ||\n !!slots.actions),\n)\n\n// editing in place\nconst editing = ref(false)\nconst draft = ref('')\nconst editorRef = useTemplateRef<HTMLTextAreaElement>('editor')\nfunction startEdit() {\n draft.value = text.value\n editing.value = true\n void nextTick(() => {\n const el = editorRef.value\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n fitEditor()\n })\n}\nfunction cancelEdit() {\n editing.value = false\n}\nfunction saveEdit() {\n if (!draft.value.trim()) return\n editing.value = false\n emit('edit', draft.value)\n}\nfunction fitEditor() {\n const el = editorRef.value\n if (!el) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nfunction onEditorKeydown(event: KeyboardEvent) {\n if (event.key === 'Escape') {\n event.preventDefault()\n cancelEdit()\n } else if (event.key === 'Enter' && !event.shiftKey && !isComposing(event)) {\n event.preventDefault()\n saveEdit()\n }\n}\n\nconst asText = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'text' }>\nconst asReasoning = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'reasoning' }>\nconst asFiles = (part: AnyPart) => part as Extract<ChatMessagePart, { type: 'files' }>\nconst asConfirm = (part: AnyPart) => part as ChatConfirmPart\nconst asArtifact = (part: AnyPart) => part as ChatArtifactPart\nconst asQuestion = (part: AnyPart) => part as ChatQuestionPart\nconst known = new Set([\n 'text',\n 'reasoning',\n 'tool',\n 'steps',\n 'plan',\n 'sources',\n 'files',\n 'artifact',\n 'confirm',\n 'question',\n])\n// props for the part components, without the `type` discriminator\nconst rest = (part: AnyPart) => {\n const { type: _type, ...others } = part as Record<string, unknown>\n return others\n}\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.m(sender),\n ns.m(`actions-${actionsShow}`),\n ns.is('loading', loading),\n ns.is('editing', editing),\n ns.is('highlighted', highlighted),\n ]\"\n :aria-busy=\"busy || undefined\"\n :aria-current=\"highlighted || undefined\"\n >\n <div v-if=\"files.length && !editing\" :class=\"ns.e('files')\">\n <template v-for=\"(part, index) in files\" :key=\"`f${index}`\">\n <DouChatAttachments :model-value=\"asFiles(part).files\" :removable=\"false\" />\n </template>\n </div>\n\n <div v-if=\"editing\" :class=\"ns.e('editor')\">\n <textarea\n ref=\"editor\"\n v-model=\"draft\"\n :class=\"ns.e('editor-native')\"\n rows=\"1\"\n :aria-label=\"t('chat.edit')\"\n @input=\"fitEditor\"\n @keydown=\"onEditorKeydown\"\n />\n <div :class=\"ns.e('editor-actions')\">\n <DouButton size=\"sm\" variant=\"ghost\" @click=\"cancelEdit\">{{ t('chat.cancel') }}</DouButton>\n <DouButton size=\"sm\" :disabled=\"!draft.trim()\" @click=\"saveEdit\">\n {{ t('chat.send') }}\n </DouButton>\n </div>\n </div>\n\n <div v-else-if=\"body.length || loading || slots.default\" :class=\"ns.e('content')\">\n <slot>\n <template v-for=\"(part, index) in body\" :key=\"index\">\n <DouMarkdown\n v-if=\"part.type === 'text' && markdown && !slots.text\"\n v-bind=\"markdownOptions\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n :sources=\"sources.length ? sources : undefined\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else-if=\"part.type === 'text'\"\n :class=\"ns.e('text')\"\n :content=\"asText(part).text\"\n :streaming=\"!!asText(part).streaming\"\n >\n <template v-if=\"slots.text\" #default=\"{ text: shown }\">\n <slot\n name=\"text\"\n :part=\"asText(part)\"\n :text=\"shown\"\n :index=\"index\"\n :sources=\"sources\"\n />\n </template>\n </DouStreamText>\n <DouChatReasoning\n v-else-if=\"part.type === 'reasoning'\"\n :thinking=\"!!asReasoning(part).thinking\"\n :duration=\"asReasoning(part).duration\"\n >\n <DouMarkdown\n v-if=\"markdown\"\n v-bind=\"markdownOptions\"\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n >\n <template v-for=\"slot in markdownSlots()\" :key=\"slot.name\" #[slot.inner]=\"scope\">\n <slot :name=\"slot.name\" v-bind=\"scope\" />\n </template>\n </DouMarkdown>\n <DouStreamText\n v-else\n :content=\"asReasoning(part).text\"\n :streaming=\"!!asReasoning(part).thinking\"\n :caret=\"false\"\n />\n </DouChatReasoning>\n <DouChatToolCall v-else-if=\"part.type === 'tool'\" v-bind=\"rest(part)\" />\n <DouChatSteps v-else-if=\"part.type === 'steps'\" v-bind=\"rest(part)\" />\n <DouChatPlan v-else-if=\"part.type === 'plan'\" v-bind=\"rest(part)\" />\n <DouChatSources v-else-if=\"part.type === 'sources'\" v-bind=\"rest(part)\" />\n <DouChatAttachments\n v-else-if=\"part.type === 'files'\"\n :model-value=\"asFiles(part).files\"\n :removable=\"false\"\n />\n <DouChatArtifact\n v-else-if=\"part.type === 'artifact'\"\n v-bind=\"rest(part)\"\n @open=\"emit('artifact', asArtifact(part))\"\n />\n <DouChatConfirm\n v-else-if=\"part.type === 'confirm'\"\n :title=\"asConfirm(part).title\"\n :description=\"asConfirm(part).description\"\n :status=\"asConfirm(part).status\"\n :allow-always=\"asConfirm(part).allowAlways\"\n :tone=\"asConfirm(part).tone\"\n @decide=\"emit('confirm', asConfirm(part), $event)\"\n >\n <pre v-if=\"asConfirm(part).detail\" :class=\"ns.e('code')\">{{\n asConfirm(part).detail\n }}</pre>\n </DouChatConfirm>\n <DouChatQuestion\n v-else-if=\"part.type === 'question'\"\n :title=\"asQuestion(part).title\"\n :description=\"asQuestion(part).description\"\n :options=\"asQuestion(part).options\"\n :status=\"asQuestion(part).status\"\n :answer=\"asQuestion(part).answer\"\n @select=\"(value, option) => emit('question', asQuestion(part), value, option)\"\n />\n <slot\n v-else-if=\"!known.has(part.type)\"\n name=\"part\"\n :part=\"part as ChatCustomPart\"\n :index=\"index\"\n />\n </template>\n </slot>\n <span v-if=\"loading\" :class=\"ns.e('loading')\" role=\"status\" :aria-label=\"t('chat.loading')\">\n <i /><i /><i />\n </span>\n </div>\n\n <div v-if=\"showActions && !editing\" :class=\"ns.e('actions')\">\n <div\n v-if=\"versions > 1\"\n :class=\"ns.e('versions')\"\n role=\"group\"\n :aria-label=\"t('chat.versions')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version <= 1\"\n :aria-label=\"t('chat.previousVersion')\"\n @click=\"step(-1)\"\n >\n <ChevronLeftIcon />\n </DouButton>\n <span :class=\"ns.e('version')\">{{ version }} / {{ versions }}</span>\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"version >= versions\"\n :aria-label=\"t('chat.nextVersion')\"\n @click=\"step(1)\"\n >\n <ChevronRightIcon />\n </DouButton>\n </div>\n <DouCopyButton v-if=\"copyable && text\" size=\"sm\" :text=\"text\" />\n <DouTooltip v-if=\"editable && isUser\" :content=\"t('chat.edit')\">\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('chat.edit')\" @click=\"startEdit\">\n <EditIcon />\n </DouButton>\n </DouTooltip>\n <slot name=\"actions\" />\n </div>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -20,5 +20,6 @@ import '@dou-ui/theme/components/chat-plan.css'
|
|
|
20
20
|
import '@dou-ui/theme/components/chat-steps.css'
|
|
21
21
|
import '@dou-ui/theme/components/chat-sources.css'
|
|
22
22
|
import '@dou-ui/theme/components/chat-confirm.css'
|
|
23
|
+
import '@dou-ui/theme/components/chat-question.css'
|
|
23
24
|
import '@dou-ui/theme/components/chat-artifact.css'
|
|
24
25
|
import '@dou-ui/theme/components/chat-message.css'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import chat_question_vue_vue_type_script_setup_true_lang_default from "./chat-question.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/components/chat-question/chat-question.vue
|
|
3
|
+
var chat_question_default = chat_question_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { chat_question_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=chat-question.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-question.js","names":["_sfc_main"],"sources":["../../../src/components/chat-question/chat-question.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, MessageQuestionIcon, UndoIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useId, watch, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn, useStatusCheck } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatQuestionEmits,\n ChatQuestionOption,\n ChatQuestionProps,\n ChatQuestionSlots,\n} from './chat-question'\n\ndefineOptions({ name: 'DouChatQuestion' })\n\nconst props = withDefaults(defineProps<ChatQuestionProps>(), {\n options: () => [],\n status: 'waiting',\n})\nconst emit = defineEmits<ChatQuestionEmits>()\nconst slots = defineSlots<ChatQuestionSlots>()\n\nconst ns = useNamespace('chat-question')\nconst { t } = useLocale()\nconst id = useId()\n\nconst waiting = computed(() => props.status === 'waiting')\nconst chosen = computed(() => props.options.find((option) => option.value === props.answer))\n\nfunction pick(option: ChatQuestionOption) {\n if (waiting.value && !option.disabled) emit('select', option.value, option)\n}\n\n// Answering or withdrawing removes the options; if focus was on one, keep\n// it on the card instead of losing it to the page. The watcher runs before\n// the DOM updates, while the focused option is still there to find.\nconst root = ref<HTMLElement>()\nwatch(\n () => props.status,\n (now, before) => {\n if (before !== 'waiting' || now === 'waiting') return\n if (!root.value?.contains(document.activeElement)) return\n void nextTick(() => root.value?.focus({ preventScroll: true }))\n },\n)\n\nconst statuses = ['waiting', 'answered', 'withdrawn']\nuseStatusCheck('DouChatQuestion', () => [props.status], statuses, { pending: 'waiting' })\n\n// Mistakes the types can't catch, with options from a server.\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n const seen = new Set<string | number>()\n for (const option of props.options) {\n if (seen.has(option.value))\n devWarn(\n `[dou-ui] DouChatQuestion: two options share the value ${JSON.stringify(option.value)}; values tell the options apart and name the answer, so they must differ.`,\n )\n seen.add(option.value)\n }\n if (props.status === 'waiting' && !props.options.length)\n devWarn(\n '[dou-ui] DouChatQuestion: waiting with no options, so there is nothing to answer with.',\n )\n })\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[ns.b(), ns.is(status)]\"\n role=\"group\"\n tabindex=\"-1\"\n :aria-labelledby=\"title || slots.title ? `${id}-title` : undefined\"\n >\n <div :class=\"ns.e('header')\">\n <span :class=\"ns.e('icon')\" aria-hidden=\"true\">\n <slot name=\"icon\"><MessageQuestionIcon /></slot>\n </span>\n <div :class=\"ns.e('text')\">\n <div v-if=\"title || slots.title\" :id=\"`${id}-title`\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div v-if=\"description\" :class=\"ns.e('description')\">{{ description }}</div>\n </div>\n <!-- always there, so screen readers announce the outcome when it appears -->\n <span :class=\"ns.e('result')\" role=\"status\">\n <template v-if=\"status === 'answered'\">\n <CheckIcon aria-hidden=\"true\" />\n <!-- a long label is cut short: the whole of it on hover -->\n <span :class=\"ns.e('answer')\" :title=\"chosen?.label\">{{\n chosen?.label ?? t('chat.answered')\n }}</span>\n </template>\n <template v-else-if=\"status === 'withdrawn'\">\n <UndoIcon aria-hidden=\"true\" />\n {{ t('chat.withdrawn') }}\n </template>\n </span>\n </div>\n <ul v-if=\"waiting && options.length\" :class=\"ns.e('options')\">\n <li v-for=\"(option, index) in options\" :key=\"option.value\">\n <!-- named by the label alone, with the second line read as its description -->\n <button\n type=\"button\"\n :class=\"ns.e('option')\"\n :disabled=\"option.disabled\"\n :aria-labelledby=\"slots.option ? undefined : `${id}-${index}`\"\n :aria-describedby=\"option.description && !slots.option ? `${id}-${index}-d` : undefined\"\n @click=\"pick(option)\"\n >\n <slot name=\"option\" :option=\"option\">\n <component :is=\"option.icon\" v-if=\"option.icon\" :class=\"ns.e('option-icon')\" />\n <span :class=\"ns.e('option-text')\">\n <span :id=\"`${id}-${index}`\" :class=\"ns.e('label')\">{{ option.label }}</span>\n <span\n v-if=\"option.description\"\n :id=\"`${id}-${index}-d`\"\n :class=\"ns.e('option-description')\"\n >{{ option.description }}</span\n >\n </span>\n </slot>\n </button>\n </li>\n </ul>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useNamespace } from "../../utils/namespace.js";
|
|
2
|
+
import { useLocale } from "../config-provider/use-config.js";
|
|
3
|
+
import { devWarn, useStatusCheck } from "../../utils/status-check.js";
|
|
4
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, nextTick, normalizeClass, openBlock, ref, renderList, renderSlot, resolveDynamicComponent, toDisplayString, unref, useId, useSlots, watch, watchEffect } from "vue";
|
|
5
|
+
import { CheckIcon, MessageQuestionIcon, UndoIcon } from "@dou-ui/icons";
|
|
6
|
+
// src/components/chat-question/chat-question.vue?vue&type=script&setup=true&lang.ts
|
|
7
|
+
var _hoisted_1 = ["aria-labelledby"];
|
|
8
|
+
var _hoisted_2 = ["id"];
|
|
9
|
+
var _hoisted_3 = ["title"];
|
|
10
|
+
var _hoisted_4 = [
|
|
11
|
+
"disabled",
|
|
12
|
+
"aria-labelledby",
|
|
13
|
+
"aria-describedby",
|
|
14
|
+
"onClick"
|
|
15
|
+
];
|
|
16
|
+
var _hoisted_5 = ["id"];
|
|
17
|
+
var _hoisted_6 = ["id"];
|
|
18
|
+
var chat_question_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
19
|
+
name: "DouChatQuestion",
|
|
20
|
+
__name: "chat-question",
|
|
21
|
+
props: {
|
|
22
|
+
title: {},
|
|
23
|
+
description: {},
|
|
24
|
+
options: { default: () => [] },
|
|
25
|
+
status: { default: "waiting" },
|
|
26
|
+
answer: {}
|
|
27
|
+
},
|
|
28
|
+
emits: ["select"],
|
|
29
|
+
setup(__props, { emit: __emit }) {
|
|
30
|
+
const props = __props;
|
|
31
|
+
const emit = __emit;
|
|
32
|
+
const slots = useSlots();
|
|
33
|
+
const ns = useNamespace("chat-question");
|
|
34
|
+
const { t } = useLocale();
|
|
35
|
+
const id = useId();
|
|
36
|
+
const waiting = computed(() => props.status === "waiting");
|
|
37
|
+
const chosen = computed(() => props.options.find((option) => option.value === props.answer));
|
|
38
|
+
function pick(option) {
|
|
39
|
+
if (waiting.value && !option.disabled) emit("select", option.value, option);
|
|
40
|
+
}
|
|
41
|
+
const root = ref();
|
|
42
|
+
watch(() => props.status, (now, before) => {
|
|
43
|
+
if (before !== "waiting" || now === "waiting") return;
|
|
44
|
+
if (!root.value?.contains(document.activeElement)) return;
|
|
45
|
+
nextTick(() => root.value?.focus({ preventScroll: true }));
|
|
46
|
+
});
|
|
47
|
+
useStatusCheck("DouChatQuestion", () => [props.status], [
|
|
48
|
+
"waiting",
|
|
49
|
+
"answered",
|
|
50
|
+
"withdrawn"
|
|
51
|
+
], { pending: "waiting" });
|
|
52
|
+
if (process.env.NODE_ENV !== "production") watchEffect(() => {
|
|
53
|
+
const seen = /* @__PURE__ */ new Set();
|
|
54
|
+
for (const option of props.options) {
|
|
55
|
+
if (seen.has(option.value)) devWarn(`[dou-ui] DouChatQuestion: two options share the value ${JSON.stringify(option.value)}; values tell the options apart and name the answer, so they must differ.`);
|
|
56
|
+
seen.add(option.value);
|
|
57
|
+
}
|
|
58
|
+
if (props.status === "waiting" && !props.options.length) devWarn("[dou-ui] DouChatQuestion: waiting with no options, so there is nothing to answer with.");
|
|
59
|
+
});
|
|
60
|
+
return (_ctx, _cache) => {
|
|
61
|
+
return openBlock(), createElementBlock("div", {
|
|
62
|
+
ref_key: "root",
|
|
63
|
+
ref: root,
|
|
64
|
+
class: normalizeClass([unref(ns).b(), unref(ns).is(__props.status)]),
|
|
65
|
+
role: "group",
|
|
66
|
+
tabindex: "-1",
|
|
67
|
+
"aria-labelledby": __props.title || slots.title ? `${unref(id)}-title` : void 0
|
|
68
|
+
}, [createElementVNode("div", { class: normalizeClass(unref(ns).e("header")) }, [
|
|
69
|
+
createElementVNode("span", {
|
|
70
|
+
class: normalizeClass(unref(ns).e("icon")),
|
|
71
|
+
"aria-hidden": "true"
|
|
72
|
+
}, [renderSlot(_ctx.$slots, "icon", {}, () => [createVNode(unref(MessageQuestionIcon))])], 2),
|
|
73
|
+
createElementVNode("div", { class: normalizeClass(unref(ns).e("text")) }, [__props.title || slots.title ? (openBlock(), createElementBlock("div", {
|
|
74
|
+
key: 0,
|
|
75
|
+
id: `${unref(id)}-title`,
|
|
76
|
+
class: normalizeClass(unref(ns).e("title"))
|
|
77
|
+
}, [renderSlot(_ctx.$slots, "title", {}, () => [createTextVNode(toDisplayString(__props.title), 1)])], 10, _hoisted_2)) : createCommentVNode("", true), __props.description ? (openBlock(), createElementBlock("div", {
|
|
78
|
+
key: 1,
|
|
79
|
+
class: normalizeClass(unref(ns).e("description"))
|
|
80
|
+
}, toDisplayString(__props.description), 3)) : createCommentVNode("", true)], 2),
|
|
81
|
+
createElementVNode("span", {
|
|
82
|
+
class: normalizeClass(unref(ns).e("result")),
|
|
83
|
+
role: "status"
|
|
84
|
+
}, [__props.status === "answered" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createVNode(unref(CheckIcon), { "aria-hidden": "true" }), createElementVNode("span", {
|
|
85
|
+
class: normalizeClass(unref(ns).e("answer")),
|
|
86
|
+
title: chosen.value?.label
|
|
87
|
+
}, toDisplayString(chosen.value?.label ?? unref(t)("chat.answered")), 11, _hoisted_3)], 64)) : __props.status === "withdrawn" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [createVNode(unref(UndoIcon), { "aria-hidden": "true" }), createTextVNode(" " + toDisplayString(unref(t)("chat.withdrawn")), 1)], 64)) : createCommentVNode("", true)], 2)
|
|
88
|
+
], 2), waiting.value && __props.options.length ? (openBlock(), createElementBlock("ul", {
|
|
89
|
+
key: 0,
|
|
90
|
+
class: normalizeClass(unref(ns).e("options"))
|
|
91
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.options, (option, index) => {
|
|
92
|
+
return openBlock(), createElementBlock("li", { key: option.value }, [createElementVNode("button", {
|
|
93
|
+
type: "button",
|
|
94
|
+
class: normalizeClass(unref(ns).e("option")),
|
|
95
|
+
disabled: option.disabled,
|
|
96
|
+
"aria-labelledby": slots.option ? void 0 : `${unref(id)}-${index}`,
|
|
97
|
+
"aria-describedby": option.description && !slots.option ? `${unref(id)}-${index}-d` : void 0,
|
|
98
|
+
onClick: ($event) => pick(option)
|
|
99
|
+
}, [renderSlot(_ctx.$slots, "option", { option }, () => [option.icon ? (openBlock(), createBlock(resolveDynamicComponent(option.icon), {
|
|
100
|
+
key: 0,
|
|
101
|
+
class: normalizeClass(unref(ns).e("option-icon"))
|
|
102
|
+
}, null, 8, ["class"])) : createCommentVNode("", true), createElementVNode("span", { class: normalizeClass(unref(ns).e("option-text")) }, [createElementVNode("span", {
|
|
103
|
+
id: `${unref(id)}-${index}`,
|
|
104
|
+
class: normalizeClass(unref(ns).e("label"))
|
|
105
|
+
}, toDisplayString(option.label), 11, _hoisted_5), option.description ? (openBlock(), createElementBlock("span", {
|
|
106
|
+
key: 0,
|
|
107
|
+
id: `${unref(id)}-${index}-d`,
|
|
108
|
+
class: normalizeClass(unref(ns).e("option-description"))
|
|
109
|
+
}, toDisplayString(option.description), 11, _hoisted_6)) : createCommentVNode("", true)], 2)])], 10, _hoisted_4)]);
|
|
110
|
+
}), 128))], 2)) : createCommentVNode("", true)], 10, _hoisted_1);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
export { chat_question_vue_vue_type_script_setup_true_lang_default as default };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=chat-question.vue_vue_type_script_setup_true_lang.js.map
|
package/dist/components/chat-question/chat-question.vue_vue_type_script_setup_true_lang.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-question.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_renderSlot","_createVNode","_createTextVNode","_toDisplayString","_createCommentVNode","_Fragment","_renderList","_createBlock","_resolveDynamicComponent"],"sources":["../../../src/components/chat-question/chat-question.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, MessageQuestionIcon, UndoIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useId, watch, watchEffect } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn, useStatusCheck } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatQuestionEmits,\n ChatQuestionOption,\n ChatQuestionProps,\n ChatQuestionSlots,\n} from './chat-question'\n\ndefineOptions({ name: 'DouChatQuestion' })\n\nconst props = withDefaults(defineProps<ChatQuestionProps>(), {\n options: () => [],\n status: 'waiting',\n})\nconst emit = defineEmits<ChatQuestionEmits>()\nconst slots = defineSlots<ChatQuestionSlots>()\n\nconst ns = useNamespace('chat-question')\nconst { t } = useLocale()\nconst id = useId()\n\nconst waiting = computed(() => props.status === 'waiting')\nconst chosen = computed(() => props.options.find((option) => option.value === props.answer))\n\nfunction pick(option: ChatQuestionOption) {\n if (waiting.value && !option.disabled) emit('select', option.value, option)\n}\n\n// Answering or withdrawing removes the options; if focus was on one, keep\n// it on the card instead of losing it to the page. The watcher runs before\n// the DOM updates, while the focused option is still there to find.\nconst root = ref<HTMLElement>()\nwatch(\n () => props.status,\n (now, before) => {\n if (before !== 'waiting' || now === 'waiting') return\n if (!root.value?.contains(document.activeElement)) return\n void nextTick(() => root.value?.focus({ preventScroll: true }))\n },\n)\n\nconst statuses = ['waiting', 'answered', 'withdrawn']\nuseStatusCheck('DouChatQuestion', () => [props.status], statuses, { pending: 'waiting' })\n\n// Mistakes the types can't catch, with options from a server.\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n const seen = new Set<string | number>()\n for (const option of props.options) {\n if (seen.has(option.value))\n devWarn(\n `[dou-ui] DouChatQuestion: two options share the value ${JSON.stringify(option.value)}; values tell the options apart and name the answer, so they must differ.`,\n )\n seen.add(option.value)\n }\n if (props.status === 'waiting' && !props.options.length)\n devWarn(\n '[dou-ui] DouChatQuestion: waiting with no options, so there is nothing to answer with.',\n )\n })\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[ns.b(), ns.is(status)]\"\n role=\"group\"\n tabindex=\"-1\"\n :aria-labelledby=\"title || slots.title ? `${id}-title` : undefined\"\n >\n <div :class=\"ns.e('header')\">\n <span :class=\"ns.e('icon')\" aria-hidden=\"true\">\n <slot name=\"icon\"><MessageQuestionIcon /></slot>\n </span>\n <div :class=\"ns.e('text')\">\n <div v-if=\"title || slots.title\" :id=\"`${id}-title`\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div v-if=\"description\" :class=\"ns.e('description')\">{{ description }}</div>\n </div>\n <!-- always there, so screen readers announce the outcome when it appears -->\n <span :class=\"ns.e('result')\" role=\"status\">\n <template v-if=\"status === 'answered'\">\n <CheckIcon aria-hidden=\"true\" />\n <!-- a long label is cut short: the whole of it on hover -->\n <span :class=\"ns.e('answer')\" :title=\"chosen?.label\">{{\n chosen?.label ?? t('chat.answered')\n }}</span>\n </template>\n <template v-else-if=\"status === 'withdrawn'\">\n <UndoIcon aria-hidden=\"true\" />\n {{ t('chat.withdrawn') }}\n </template>\n </span>\n </div>\n <ul v-if=\"waiting && options.length\" :class=\"ns.e('options')\">\n <li v-for=\"(option, index) in options\" :key=\"option.value\">\n <!-- named by the label alone, with the second line read as its description -->\n <button\n type=\"button\"\n :class=\"ns.e('option')\"\n :disabled=\"option.disabled\"\n :aria-labelledby=\"slots.option ? undefined : `${id}-${index}`\"\n :aria-describedby=\"option.description && !slots.option ? `${id}-${index}-d` : undefined\"\n @click=\"pick(option)\"\n >\n <slot name=\"option\" :option=\"option\">\n <component :is=\"option.icon\" v-if=\"option.icon\" :class=\"ns.e('option-icon')\" />\n <span :class=\"ns.e('option-text')\">\n <span :id=\"`${id}-${index}`\" :class=\"ns.e('label')\">{{ option.label }}</span>\n <span\n v-if=\"option.description\"\n :id=\"`${id}-${index}-d`\"\n :class=\"ns.e('option-description')\"\n >{{ option.description }}</span\n >\n </span>\n </slot>\n </button>\n </li>\n </ul>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAeA,MAAM,QAAQ;EAId,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,eAAe;EACvC,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,KAAK,MAAM;EAEjB,MAAM,UAAU,eAAe,MAAM,WAAW,SAAS;EACzD,MAAM,SAAS,eAAe,MAAM,QAAQ,MAAM,WAAW,OAAO,UAAU,MAAM,MAAM,CAAC;EAE3F,SAAS,KAAK,QAA4B;GACxC,IAAI,QAAQ,SAAS,CAAC,OAAO,UAAU,KAAK,UAAU,OAAO,OAAO,MAAM;EAC5E;EAKA,MAAM,OAAO,IAAiB;EAC9B,YACQ,MAAM,SACX,KAAK,WAAW;GACf,IAAI,WAAW,aAAa,QAAQ,WAAW;GAC/C,IAAI,CAAC,KAAK,OAAO,SAAS,SAAS,aAAa,GAAG;GACnD,eAAoB,KAAK,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC,CAAC;EAChE,CACF;EAGA,eAAe,yBAAyB,CAAC,MAAM,MAAM,GAAG;GADtC;GAAW;GAAY;EACe,GAAU,EAAE,SAAS,UAAU,CAAC;EAGxF,IAAA,QAAA,IAAA,aAA6B,cAC3B,kBAAkB;GAChB,MAAM,uBAAO,IAAI,IAAqB;GACtC,KAAK,MAAM,UAAU,MAAM,SAAS;IAClC,IAAI,KAAK,IAAI,OAAO,KAAK,GACvB,QACE,yDAAyD,KAAK,UAAU,OAAO,KAAK,EAAE,0EACxF;IACF,KAAK,IAAI,OAAO,KAAK;GACvB;GACA,IAAI,MAAM,WAAW,aAAa,CAAC,MAAM,QAAQ,QAC/C,QACE,wFACF;EACJ,CAAC;;GAID,OAAAC,UA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AE,CAAC,EAAC,aAAA,CAAA;I,wDAC5DC,mBAQO,QAAA,EARA,OAAKF,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,aAAA,CAAA,E,IAChBC,mBAA6E,QAAA;KAAtE,IAAE,GAAKD,MAAA,EAAA,EAAE,GAAI;KAAU,OAAKD,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;IAAc,GAAAK,gBAAA,OAAO,KAAK,GAAA,IAAA,UAAA,GAE3D,OAAO,eADfR,UAAA,GAAAC,mBAKC,QAAA;;KAHE,IAAE,GAAKE,MAAA,EAAA,EAAE,GAAI,MAAK;KAClB,OAAKD,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,oBAAA,CAAA;IACR,GAAAK,gBAAA,OAAO,WAAW,GAAA,IAAA,UAAA,K"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { withInstall } from "../../utils/install.js";
|
|
2
|
+
import chat_question_default from "./chat-question.js";
|
|
3
|
+
// src/components/chat-question/index.ts
|
|
4
|
+
var DouChatQuestion = withInstall(chat_question_default);
|
|
5
|
+
export { DouChatQuestion, DouChatQuestion as default };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ChatQuestion"],"sources":["../../../src/components/chat-question/index.ts"],"sourcesContent":["import { withInstall } from '../../utils/install'\nimport ChatQuestion from './chat-question.vue'\n\nexport const DouChatQuestion = withInstall(ChatQuestion)\nexport default DouChatQuestion\n\nexport type * from './chat-question'\nexport type ChatQuestionInstance = InstanceType<typeof ChatQuestion>\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouChatQuestion: typeof DouChatQuestion\n }\n}\n"],"mappings":";;;AAGA,IAAa,kBAAkB,YAAYA,qBAAY"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment-thread.js","names":["_sfc_main"],"sources":["../../../src/components/comment-thread/comment-thread.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, MoreHorizontalIcon, RotateCcwIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onMounted, ref, useTemplateRef } from 'vue'\nimport type { TextareaHTMLAttributes } from 'vue'\nimport type { WithAttributes } from '../../utils/install'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouAvatar } from '../avatar'\nimport { DouButton } from '../button'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouDropdown, DouDropdownItem } from '../dropdown'\nimport { DouRelativeTime } from '../relative-time'\nimport { DouTextarea as DouTextareaComponent } from '../textarea'\nimport { DouTooltip } from '../tooltip'\nimport {\n applyCommentAction,\n createCommentId,\n type CommentAction,\n type CommentItem,\n type CommentThread,\n} from './comments'\nimport type {\n CommentThreadEmits,\n CommentThreadExpose,\n CommentThreadProps,\n CommentThreadSlots,\n} from './comment-thread'\n\n// 让模板里也能写这个组件转交的原生属性\nconst DouTextarea = DouTextareaComponent as WithAttributes<\n typeof DouTextareaComponent,\n TextareaHTMLAttributes\n>\n\ndefineOptions({ name: 'DouCommentThread' })\n\nconst props = withDefaults(defineProps<CommentThreadProps>(), {\n author: undefined,\n readonly: false,\n placeholder: undefined,\n autofocus: false,\n})\n// without `v-model:thread`, the thread is kept here\nconst thread = defineModel<CommentThread | null>('thread', { default: null })\nconst emit = defineEmits<{\n action: CommentThreadEmits['action']\n cancel: CommentThreadEmits['cancel']\n}>()\ndefineSlots<CommentThreadSlots>()\n\nconst ns = useNamespace('comment-thread')\nconst { t } = useLocale()\n\n/** A week: older comments show their date instead of \"3 days ago\". */\nconst WEEK = 7 * 24 * 3600 * 1000\n\nconst resolved = computed(() => thread.value?.resolved)\n/** Who may change things: nobody when read-only, or when no `author` says who is writing. */\nconst writer = computed(() => (props.readonly ? undefined : props.author))\nconst canWrite = computed(() => !!writer.value && !resolved.value)\n\nconst root = useTemplateRef<HTMLElement>('root')\n\nfunction act(action: CommentAction) {\n emit('action', action)\n if (action.type === 'create') thread.value = action.thread\n else if (thread.value) thread.value = applyCommentAction([thread.value], action)[0] ?? null\n void keepFocus()\n}\n\n/**\n * The button or box that held focus can go with a change (the edit box\n * once saved, the reply box once resolved): focus moves on to the reply\n * box, or the reopen button, instead of falling to the page.\n */\nasync function keepFocus() {\n await nextTick()\n const el = root.value\n const now = document.activeElement\n if (!el || (now && now !== document.body && !el.contains(now))) return\n if (now && now !== document.body && el.contains(now) && now.isConnected) return\n if (box.value) focus()\n else el.querySelector<HTMLElement>(`.${ns.e('status')} button`)?.focus({ preventScroll: true })\n}\n\nconst now = () => new Date().toISOString()\n\n// writing a new comment or a reply\nconst draft = ref('')\nconst box = useTemplateRef<InstanceType<typeof DouTextarea>>('box')\n\nfunction send() {\n const body = draft.value.trim()\n const author = writer.value\n if (!body || !author) return\n const comment: CommentItem = {\n id: createCommentId(),\n author: { ...author },\n body,\n createdAt: now(),\n }\n draft.value = ''\n if (thread.value) act({ type: 'reply', threadId: thread.value.id, comment })\n else act({ type: 'create', thread: { id: createCommentId(), comments: [comment] } })\n}\n\n/** A key handled here: not the page's too. */\nfunction handled(event: KeyboardEvent) {\n event.preventDefault()\n event.stopPropagation()\n}\n\nfunction onBoxKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n send()\n } else if (event.key === 'Escape') {\n // an empty box lets Escape go on, to close the popover or drawer around\n if (draft.value) {\n handled(event)\n draft.value = ''\n } else emit('cancel')\n }\n}\n\n// changing a comment in place\nconst editing = ref<string | null>(null)\nconst editDraft = ref('')\nconst editBox = useTemplateRef<InstanceType<typeof DouTextarea>[]>('editBox')\n\nfunction startEdit(comment: CommentItem) {\n confirming.value = false\n editing.value = comment.id\n editDraft.value = comment.body\n void nextTick(() => {\n const el = editBox.value?.[0]?.textarea\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n })\n}\n\nfunction saveEdit() {\n const id = editing.value\n const body = editDraft.value.trim()\n if (!id || !thread.value || !body) return\n editing.value = null\n const before = thread.value.comments.find((comment) => comment.id === id)\n if (before?.body === body) return void keepFocus()\n act({ type: 'edit', threadId: thread.value.id, commentId: id, body, editedAt: now() })\n}\n\nfunction onEditKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n saveEdit()\n } else if (event.key === 'Escape') {\n handled(event)\n editing.value = null\n void keepFocus()\n }\n}\n\n// deleting the first comment takes the thread with it: asked first\nconst confirming = ref(false)\n\nfunction onMenu(comment: CommentItem, index: number, value: unknown) {\n if (!thread.value) return\n if (value === 'edit') startEdit(comment)\n else if (value === 'delete') {\n if (index === 0) confirming.value = true\n else act({ type: 'delete', threadId: thread.value.id, commentId: comment.id })\n }\n}\n\nfunction removeThread() {\n if (!thread.value) return\n confirming.value = false\n act({ type: 'remove', threadId: thread.value.id })\n}\n\nfunction resolve() {\n const by = writer.value\n if (thread.value && by)\n act({ type: 'resolve', threadId: thread.value.id, by: { ...by }, at: now() })\n}\n\nfunction reopen() {\n if (thread.value) act({ type: 'reopen', threadId: thread.value.id })\n}\n\nconst placeholderText = computed(() =>\n thread.value\n ? t('commentThread.replyPlaceholder')\n : (props.placeholder ?? t('commentThread.placeholder')),\n)\n\nconst focus = () => box.value?.textarea?.focus({ preventScroll: true })\nonMounted(() => {\n if (props.autofocus) focus()\n})\ndefineExpose<CommentThreadExpose>({ focus })\n</script>\n\n<template>\n <div ref=\"root\" role=\"group\" :class=\"[ns.b(), { 'is-resolved': !!resolved, 'is-new': !thread }]\">\n <slot name=\"header\" />\n <div v-if=\"resolved\" :class=\"ns.e('status')\">\n <CheckIcon :class=\"ns.e('status-icon')\" />\n <span :class=\"ns.e('status-text')\">{{\n t('commentThread.resolvedBy', { name: resolved.by.name })\n }}</span>\n <DouButton v-if=\"writer\" variant=\"ghost\" size=\"sm\" @click=\"reopen\">\n <template #leading><RotateCcwIcon /></template>\n {{ t('commentThread.reopen') }}\n </DouButton>\n </div>\n <ol v-if=\"thread?.comments.length\" :class=\"ns.e('list')\">\n <li v-for=\"(comment, index) in thread.comments\" :key=\"comment.id\" :class=\"ns.e('comment')\">\n <div :class=\"ns.e('head')\">\n <DouAvatar\n :name=\"comment.author.name\"\n :src=\"comment.author.avatar\"\n size=\"sm\"\n :class=\"ns.e('avatar')\"\n />\n <span :class=\"ns.e('author')\">{{ comment.author.name }}</span>\n <DouRelativeTime\n :value=\"comment.createdAt\"\n short\n :absolute-after=\"WEEK\"\n :class=\"ns.e('time')\"\n />\n <span v-if=\"comment.editedAt\" :class=\"ns.e('edited')\">{{\n t('commentThread.edited')\n }}</span>\n <div v-if=\"writer\" :class=\"ns.e('actions')\">\n <DouTooltip v-if=\"index === 0 && !resolved\" :content=\"t('commentThread.resolve')\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"t('commentThread.resolve')\"\n @click=\"resolve\"\n >\n <CheckIcon />\n </DouButton>\n </DouTooltip>\n <DouDropdown\n v-if=\"comment.author.id === writer.id && !resolved\"\n placement=\"bottom-end\"\n @select=\"(value) => onMenu(comment, index, value)\"\n >\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('commentThread.more')\">\n <MoreHorizontalIcon />\n </DouButton>\n <template #menu>\n <DouDropdownItem value=\"edit\">{{ t('commentThread.edit') }}</DouDropdownItem>\n <DouDropdownItem value=\"delete\" tone=\"danger\">{{\n index === 0 ? t('commentThread.deleteThread') : t('commentThread.delete')\n }}</DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n </div>\n <div v-if=\"editing === comment.id\" :class=\"ns.e('editor')\">\n <DouTextarea\n ref=\"editBox\"\n v-model=\"editDraft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n size=\"sm\"\n @keydown=\"onEditKeydown\"\n />\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"editing = null\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!editDraft.trim()\"\n @click=\"saveEdit\"\n >{{ t('commentThread.save') }}</DouButton\n >\n </div>\n </div>\n <p v-else :class=\"ns.e('body')\">{{ comment.body }}</p>\n <div v-if=\"index === 0 && confirming\" :class=\"ns.e('confirm')\" role=\"alert\">\n <span>{{ t('commentThread.deleteThreadConfirm') }}</span>\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"confirming = false\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton variant=\"solid\" tone=\"danger\" size=\"sm\" @click=\"removeThread\">{{\n t('commentThread.delete')\n }}</DouButton>\n </div>\n </div>\n </li>\n </ol>\n <div v-if=\"canWrite\" :class=\"ns.e('composer')\">\n <DouTextarea\n ref=\"box\"\n v-model=\"draft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n :placeholder=\"placeholderText\"\n :aria-label=\"placeholderText\"\n size=\"sm\"\n @keydown=\"onBoxKeydown\"\n />\n <div v-if=\"draft || !thread\" :class=\"ns.e('buttons')\">\n <DouButton v-if=\"!thread\" variant=\"ghost\" size=\"sm\" @click=\"emit('cancel')\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!draft.trim()\"\n @click=\"send\"\n >{{ t('commentThread.send') }}</DouButton\n >\n </div>\n </div>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"comment-thread.js","names":["_sfc_main"],"sources":["../../../src/components/comment-thread/comment-thread.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, MoreHorizontalIcon, RotateCcwIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onMounted, ref, useTemplateRef } from 'vue'\nimport type { TextareaHTMLAttributes } from 'vue'\nimport type { WithAttributes } from '../../utils/install'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouAvatar } from '../avatar'\nimport { DouButton } from '../button'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouDropdown, DouDropdownItem } from '../dropdown'\nimport { DouRelativeTime } from '../relative-time'\nimport { DouTextarea as DouTextareaComponent } from '../textarea'\nimport { DouTooltip } from '../tooltip'\nimport {\n applyCommentAction,\n createCommentId,\n type CommentAction,\n type CommentItem,\n type CommentThread,\n} from './comments'\nimport type {\n CommentThreadEmits,\n CommentThreadExpose,\n CommentThreadProps,\n CommentThreadSlots,\n} from './comment-thread'\n\n// 让模板里也能写这个组件转交的原生属性\nconst DouTextarea = DouTextareaComponent as WithAttributes<\n typeof DouTextareaComponent,\n TextareaHTMLAttributes\n>\n\ndefineOptions({ name: 'DouCommentThread' })\n\nconst props = withDefaults(defineProps<CommentThreadProps>(), {\n author: undefined,\n readonly: false,\n resolvable: true,\n placeholder: undefined,\n autofocus: false,\n})\n// without `v-model:thread`, the thread is kept here\nconst thread = defineModel<CommentThread | null>('thread', { default: null })\nconst emit = defineEmits<{\n action: CommentThreadEmits['action']\n cancel: CommentThreadEmits['cancel']\n}>()\ndefineSlots<CommentThreadSlots>()\n\nconst ns = useNamespace('comment-thread')\nconst { t } = useLocale()\n\n/** A week: older comments show their date instead of \"3 days ago\". */\nconst WEEK = 7 * 24 * 3600 * 1000\n\nconst resolved = computed(() => thread.value?.resolved)\n/** Who may change things: nobody when read-only, or when no `author` says who is writing. */\nconst writer = computed(() => (props.readonly ? undefined : props.author))\nconst canWrite = computed(() => !!writer.value && !resolved.value)\n\nconst root = useTemplateRef<HTMLElement>('root')\n\nfunction act(action: CommentAction) {\n emit('action', action)\n if (action.type === 'create') thread.value = action.thread\n else if (thread.value) thread.value = applyCommentAction([thread.value], action)[0] ?? null\n void keepFocus()\n}\n\n/**\n * The button or box that held focus can go with a change (the edit box\n * once saved, the reply box once resolved): focus moves on to the reply\n * box, or the reopen button, instead of falling to the page.\n */\nasync function keepFocus() {\n await nextTick()\n const el = root.value\n const now = document.activeElement\n if (!el || (now && now !== document.body && !el.contains(now))) return\n if (now && now !== document.body && el.contains(now) && now.isConnected) return\n if (box.value) focus()\n else el.querySelector<HTMLElement>(`.${ns.e('status')} button`)?.focus({ preventScroll: true })\n}\n\nconst now = () => new Date().toISOString()\n\n// writing a new comment or a reply\nconst draft = ref('')\nconst box = useTemplateRef<InstanceType<typeof DouTextarea>>('box')\n\nfunction send() {\n const body = draft.value.trim()\n const author = writer.value\n if (!body || !author) return\n const comment: CommentItem = {\n id: createCommentId(),\n author: { ...author },\n body,\n createdAt: now(),\n }\n draft.value = ''\n if (thread.value) act({ type: 'reply', threadId: thread.value.id, comment })\n else act({ type: 'create', thread: { id: createCommentId(), comments: [comment] } })\n}\n\n/** A key handled here: not the page's too. */\nfunction handled(event: KeyboardEvent) {\n event.preventDefault()\n event.stopPropagation()\n}\n\nfunction onBoxKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n send()\n } else if (event.key === 'Escape') {\n // an empty box lets Escape go on, to close the popover or drawer around\n if (draft.value) {\n handled(event)\n draft.value = ''\n } else emit('cancel')\n }\n}\n\n// changing a comment in place\nconst editing = ref<string | null>(null)\nconst editDraft = ref('')\nconst editBox = useTemplateRef<InstanceType<typeof DouTextarea>[]>('editBox')\n\nfunction startEdit(comment: CommentItem) {\n confirming.value = false\n editing.value = comment.id\n editDraft.value = comment.body\n void nextTick(() => {\n const el = editBox.value?.[0]?.textarea\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n })\n}\n\nfunction saveEdit() {\n const id = editing.value\n const body = editDraft.value.trim()\n if (!id || !thread.value || !body) return\n editing.value = null\n const before = thread.value.comments.find((comment) => comment.id === id)\n if (before?.body === body) return void keepFocus()\n act({ type: 'edit', threadId: thread.value.id, commentId: id, body, editedAt: now() })\n}\n\nfunction onEditKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n saveEdit()\n } else if (event.key === 'Escape') {\n handled(event)\n editing.value = null\n void keepFocus()\n }\n}\n\n// deleting the first comment takes the thread with it: asked first\nconst confirming = ref(false)\n\nfunction onMenu(comment: CommentItem, index: number, value: unknown) {\n if (!thread.value) return\n if (value === 'edit') startEdit(comment)\n else if (value === 'delete') {\n if (index === 0) confirming.value = true\n else act({ type: 'delete', threadId: thread.value.id, commentId: comment.id })\n }\n}\n\nfunction removeThread() {\n if (!thread.value) return\n confirming.value = false\n act({ type: 'remove', threadId: thread.value.id })\n}\n\nfunction resolve() {\n const by = writer.value\n if (thread.value && by)\n act({ type: 'resolve', threadId: thread.value.id, by: { ...by }, at: now() })\n}\n\nfunction reopen() {\n if (thread.value) act({ type: 'reopen', threadId: thread.value.id })\n}\n\nconst placeholderText = computed(() =>\n thread.value\n ? t('commentThread.replyPlaceholder')\n : (props.placeholder ?? t('commentThread.placeholder')),\n)\n\nconst focus = () => box.value?.textarea?.focus({ preventScroll: true })\nonMounted(() => {\n if (props.autofocus) focus()\n})\ndefineExpose<CommentThreadExpose>({ focus })\n</script>\n\n<template>\n <div ref=\"root\" role=\"group\" :class=\"[ns.b(), { 'is-resolved': !!resolved, 'is-new': !thread }]\">\n <slot name=\"header\" />\n <div v-if=\"resolved\" :class=\"ns.e('status')\">\n <CheckIcon :class=\"ns.e('status-icon')\" />\n <span :class=\"ns.e('status-text')\">{{\n t('commentThread.resolvedBy', { name: resolved.by.name })\n }}</span>\n <DouButton v-if=\"writer\" variant=\"ghost\" size=\"sm\" @click=\"reopen\">\n <template #leading><RotateCcwIcon /></template>\n {{ t('commentThread.reopen') }}\n </DouButton>\n </div>\n <ol v-if=\"thread?.comments.length\" :class=\"ns.e('list')\">\n <li v-for=\"(comment, index) in thread.comments\" :key=\"comment.id\" :class=\"ns.e('comment')\">\n <div :class=\"ns.e('head')\">\n <DouAvatar\n :name=\"comment.author.name\"\n :src=\"comment.author.avatar\"\n size=\"sm\"\n :class=\"ns.e('avatar')\"\n />\n <span :class=\"ns.e('author')\">{{ comment.author.name }}</span>\n <DouRelativeTime\n :value=\"comment.createdAt\"\n short\n :absolute-after=\"WEEK\"\n :class=\"ns.e('time')\"\n />\n <span v-if=\"comment.editedAt\" :class=\"ns.e('edited')\">{{\n t('commentThread.edited')\n }}</span>\n <div v-if=\"writer\" :class=\"ns.e('actions')\">\n <DouTooltip\n v-if=\"index === 0 && resolvable && !resolved\"\n :content=\"t('commentThread.resolve')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"t('commentThread.resolve')\"\n @click=\"resolve\"\n >\n <CheckIcon />\n </DouButton>\n </DouTooltip>\n <DouDropdown\n v-if=\"comment.author.id === writer.id && !resolved\"\n placement=\"bottom-end\"\n @select=\"(value) => onMenu(comment, index, value)\"\n >\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('commentThread.more')\">\n <MoreHorizontalIcon />\n </DouButton>\n <template #menu>\n <DouDropdownItem value=\"edit\">{{ t('commentThread.edit') }}</DouDropdownItem>\n <DouDropdownItem value=\"delete\" tone=\"danger\">{{\n index === 0 ? t('commentThread.deleteThread') : t('commentThread.delete')\n }}</DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n </div>\n <div v-if=\"editing === comment.id\" :class=\"ns.e('editor')\">\n <DouTextarea\n ref=\"editBox\"\n v-model=\"editDraft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n size=\"sm\"\n @keydown=\"onEditKeydown\"\n />\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"editing = null\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!editDraft.trim()\"\n @click=\"saveEdit\"\n >{{ t('commentThread.save') }}</DouButton\n >\n </div>\n </div>\n <p v-else :class=\"ns.e('body')\">{{ comment.body }}</p>\n <div v-if=\"index === 0 && confirming\" :class=\"ns.e('confirm')\" role=\"alert\">\n <span>{{ t('commentThread.deleteThreadConfirm') }}</span>\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"confirming = false\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton variant=\"solid\" tone=\"danger\" size=\"sm\" @click=\"removeThread\">{{\n t('commentThread.delete')\n }}</DouButton>\n </div>\n </div>\n </li>\n </ol>\n <div v-if=\"canWrite\" :class=\"ns.e('composer')\">\n <DouTextarea\n ref=\"box\"\n v-model=\"draft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n :placeholder=\"placeholderText\"\n :aria-label=\"placeholderText\"\n size=\"sm\"\n @keydown=\"onBoxKeydown\"\n />\n <div v-if=\"draft || !thread\" :class=\"ns.e('buttons')\">\n <DouButton v-if=\"!thread\" variant=\"ghost\" size=\"sm\" @click=\"emit('cancel')\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!draft.trim()\"\n @click=\"send\"\n >{{ t('commentThread.send') }}</DouButton\n >\n </div>\n </div>\n </div>\n</template>\n"],"mappings":""}
|
package/dist/components/comment-thread/comment-thread.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -23,6 +23,10 @@ var comment_thread_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
23
23
|
type: Boolean,
|
|
24
24
|
default: false
|
|
25
25
|
},
|
|
26
|
+
resolvable: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
default: true
|
|
29
|
+
},
|
|
26
30
|
placeholder: { default: void 0 },
|
|
27
31
|
autofocus: {
|
|
28
32
|
type: Boolean,
|
|
@@ -251,7 +255,7 @@ var comment_thread_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
251
255
|
writer.value ? (openBlock(), createElementBlock("div", {
|
|
252
256
|
key: 1,
|
|
253
257
|
class: normalizeClass(unref(ns).e("actions"))
|
|
254
|
-
}, [index === 0 && !resolved.value ? (openBlock(), createBlock(unref(DouTooltip), {
|
|
258
|
+
}, [index === 0 && __props.resolvable && !resolved.value ? (openBlock(), createBlock(unref(DouTooltip), {
|
|
255
259
|
key: 0,
|
|
256
260
|
content: unref(t)("commentThread.resolve")
|
|
257
261
|
}, {
|
package/dist/components/comment-thread/comment-thread.vue_vue_type_script_setup_true_lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment-thread.vue_vue_type_script_setup_true_lang.js","names":["DouTextarea","DouTextareaComponent","_useModel","_openBlock","_createElementBlock","_normalizeClass","_unref","_renderSlot","_createVNode","_createElementVNode","_toDisplayString","_createBlock","_withCtx","_createTextVNode","_createCommentVNode","_Fragment","_renderList"],"sources":["../../../src/components/comment-thread/comment-thread.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, MoreHorizontalIcon, RotateCcwIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onMounted, ref, useTemplateRef } from 'vue'\nimport type { TextareaHTMLAttributes } from 'vue'\nimport type { WithAttributes } from '../../utils/install'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouAvatar } from '../avatar'\nimport { DouButton } from '../button'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouDropdown, DouDropdownItem } from '../dropdown'\nimport { DouRelativeTime } from '../relative-time'\nimport { DouTextarea as DouTextareaComponent } from '../textarea'\nimport { DouTooltip } from '../tooltip'\nimport {\n applyCommentAction,\n createCommentId,\n type CommentAction,\n type CommentItem,\n type CommentThread,\n} from './comments'\nimport type {\n CommentThreadEmits,\n CommentThreadExpose,\n CommentThreadProps,\n CommentThreadSlots,\n} from './comment-thread'\n\n// 让模板里也能写这个组件转交的原生属性\nconst DouTextarea = DouTextareaComponent as WithAttributes<\n typeof DouTextareaComponent,\n TextareaHTMLAttributes\n>\n\ndefineOptions({ name: 'DouCommentThread' })\n\nconst props = withDefaults(defineProps<CommentThreadProps>(), {\n author: undefined,\n readonly: false,\n placeholder: undefined,\n autofocus: false,\n})\n// without `v-model:thread`, the thread is kept here\nconst thread = defineModel<CommentThread | null>('thread', { default: null })\nconst emit = defineEmits<{\n action: CommentThreadEmits['action']\n cancel: CommentThreadEmits['cancel']\n}>()\ndefineSlots<CommentThreadSlots>()\n\nconst ns = useNamespace('comment-thread')\nconst { t } = useLocale()\n\n/** A week: older comments show their date instead of \"3 days ago\". */\nconst WEEK = 7 * 24 * 3600 * 1000\n\nconst resolved = computed(() => thread.value?.resolved)\n/** Who may change things: nobody when read-only, or when no `author` says who is writing. */\nconst writer = computed(() => (props.readonly ? undefined : props.author))\nconst canWrite = computed(() => !!writer.value && !resolved.value)\n\nconst root = useTemplateRef<HTMLElement>('root')\n\nfunction act(action: CommentAction) {\n emit('action', action)\n if (action.type === 'create') thread.value = action.thread\n else if (thread.value) thread.value = applyCommentAction([thread.value], action)[0] ?? null\n void keepFocus()\n}\n\n/**\n * The button or box that held focus can go with a change (the edit box\n * once saved, the reply box once resolved): focus moves on to the reply\n * box, or the reopen button, instead of falling to the page.\n */\nasync function keepFocus() {\n await nextTick()\n const el = root.value\n const now = document.activeElement\n if (!el || (now && now !== document.body && !el.contains(now))) return\n if (now && now !== document.body && el.contains(now) && now.isConnected) return\n if (box.value) focus()\n else el.querySelector<HTMLElement>(`.${ns.e('status')} button`)?.focus({ preventScroll: true })\n}\n\nconst now = () => new Date().toISOString()\n\n// writing a new comment or a reply\nconst draft = ref('')\nconst box = useTemplateRef<InstanceType<typeof DouTextarea>>('box')\n\nfunction send() {\n const body = draft.value.trim()\n const author = writer.value\n if (!body || !author) return\n const comment: CommentItem = {\n id: createCommentId(),\n author: { ...author },\n body,\n createdAt: now(),\n }\n draft.value = ''\n if (thread.value) act({ type: 'reply', threadId: thread.value.id, comment })\n else act({ type: 'create', thread: { id: createCommentId(), comments: [comment] } })\n}\n\n/** A key handled here: not the page's too. */\nfunction handled(event: KeyboardEvent) {\n event.preventDefault()\n event.stopPropagation()\n}\n\nfunction onBoxKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n send()\n } else if (event.key === 'Escape') {\n // an empty box lets Escape go on, to close the popover or drawer around\n if (draft.value) {\n handled(event)\n draft.value = ''\n } else emit('cancel')\n }\n}\n\n// changing a comment in place\nconst editing = ref<string | null>(null)\nconst editDraft = ref('')\nconst editBox = useTemplateRef<InstanceType<typeof DouTextarea>[]>('editBox')\n\nfunction startEdit(comment: CommentItem) {\n confirming.value = false\n editing.value = comment.id\n editDraft.value = comment.body\n void nextTick(() => {\n const el = editBox.value?.[0]?.textarea\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n })\n}\n\nfunction saveEdit() {\n const id = editing.value\n const body = editDraft.value.trim()\n if (!id || !thread.value || !body) return\n editing.value = null\n const before = thread.value.comments.find((comment) => comment.id === id)\n if (before?.body === body) return void keepFocus()\n act({ type: 'edit', threadId: thread.value.id, commentId: id, body, editedAt: now() })\n}\n\nfunction onEditKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n saveEdit()\n } else if (event.key === 'Escape') {\n handled(event)\n editing.value = null\n void keepFocus()\n }\n}\n\n// deleting the first comment takes the thread with it: asked first\nconst confirming = ref(false)\n\nfunction onMenu(comment: CommentItem, index: number, value: unknown) {\n if (!thread.value) return\n if (value === 'edit') startEdit(comment)\n else if (value === 'delete') {\n if (index === 0) confirming.value = true\n else act({ type: 'delete', threadId: thread.value.id, commentId: comment.id })\n }\n}\n\nfunction removeThread() {\n if (!thread.value) return\n confirming.value = false\n act({ type: 'remove', threadId: thread.value.id })\n}\n\nfunction resolve() {\n const by = writer.value\n if (thread.value && by)\n act({ type: 'resolve', threadId: thread.value.id, by: { ...by }, at: now() })\n}\n\nfunction reopen() {\n if (thread.value) act({ type: 'reopen', threadId: thread.value.id })\n}\n\nconst placeholderText = computed(() =>\n thread.value\n ? t('commentThread.replyPlaceholder')\n : (props.placeholder ?? t('commentThread.placeholder')),\n)\n\nconst focus = () => box.value?.textarea?.focus({ preventScroll: true })\nonMounted(() => {\n if (props.autofocus) focus()\n})\ndefineExpose<CommentThreadExpose>({ focus })\n</script>\n\n<template>\n <div ref=\"root\" role=\"group\" :class=\"[ns.b(), { 'is-resolved': !!resolved, 'is-new': !thread }]\">\n <slot name=\"header\" />\n <div v-if=\"resolved\" :class=\"ns.e('status')\">\n <CheckIcon :class=\"ns.e('status-icon')\" />\n <span :class=\"ns.e('status-text')\">{{\n t('commentThread.resolvedBy', { name: resolved.by.name })\n }}</span>\n <DouButton v-if=\"writer\" variant=\"ghost\" size=\"sm\" @click=\"reopen\">\n <template #leading><RotateCcwIcon /></template>\n {{ t('commentThread.reopen') }}\n </DouButton>\n </div>\n <ol v-if=\"thread?.comments.length\" :class=\"ns.e('list')\">\n <li v-for=\"(comment, index) in thread.comments\" :key=\"comment.id\" :class=\"ns.e('comment')\">\n <div :class=\"ns.e('head')\">\n <DouAvatar\n :name=\"comment.author.name\"\n :src=\"comment.author.avatar\"\n size=\"sm\"\n :class=\"ns.e('avatar')\"\n />\n <span :class=\"ns.e('author')\">{{ comment.author.name }}</span>\n <DouRelativeTime\n :value=\"comment.createdAt\"\n short\n :absolute-after=\"WEEK\"\n :class=\"ns.e('time')\"\n />\n <span v-if=\"comment.editedAt\" :class=\"ns.e('edited')\">{{\n t('commentThread.edited')\n }}</span>\n <div v-if=\"writer\" :class=\"ns.e('actions')\">\n <DouTooltip v-if=\"index === 0 && !resolved\" :content=\"t('commentThread.resolve')\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"t('commentThread.resolve')\"\n @click=\"resolve\"\n >\n <CheckIcon />\n </DouButton>\n </DouTooltip>\n <DouDropdown\n v-if=\"comment.author.id === writer.id && !resolved\"\n placement=\"bottom-end\"\n @select=\"(value) => onMenu(comment, index, value)\"\n >\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('commentThread.more')\">\n <MoreHorizontalIcon />\n </DouButton>\n <template #menu>\n <DouDropdownItem value=\"edit\">{{ t('commentThread.edit') }}</DouDropdownItem>\n <DouDropdownItem value=\"delete\" tone=\"danger\">{{\n index === 0 ? t('commentThread.deleteThread') : t('commentThread.delete')\n }}</DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n </div>\n <div v-if=\"editing === comment.id\" :class=\"ns.e('editor')\">\n <DouTextarea\n ref=\"editBox\"\n v-model=\"editDraft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n size=\"sm\"\n @keydown=\"onEditKeydown\"\n />\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"editing = null\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!editDraft.trim()\"\n @click=\"saveEdit\"\n >{{ t('commentThread.save') }}</DouButton\n >\n </div>\n </div>\n <p v-else :class=\"ns.e('body')\">{{ comment.body }}</p>\n <div v-if=\"index === 0 && confirming\" :class=\"ns.e('confirm')\" role=\"alert\">\n <span>{{ t('commentThread.deleteThreadConfirm') }}</span>\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"confirming = false\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton variant=\"solid\" tone=\"danger\" size=\"sm\" @click=\"removeThread\">{{\n t('commentThread.delete')\n }}</DouButton>\n </div>\n </div>\n </li>\n </ol>\n <div v-if=\"canWrite\" :class=\"ns.e('composer')\">\n <DouTextarea\n ref=\"box\"\n v-model=\"draft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n :placeholder=\"placeholderText\"\n :aria-label=\"placeholderText\"\n size=\"sm\"\n @keydown=\"onBoxKeydown\"\n />\n <div v-if=\"draft || !thread\" :class=\"ns.e('buttons')\">\n <DouButton v-if=\"!thread\" variant=\"ghost\" size=\"sm\" @click=\"emit('cancel')\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!draft.trim()\"\n @click=\"send\"\n >{{ t('commentThread.send') }}</DouButton\n >\n </div>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;AAsDA,IAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;EAzBb,MAAMA,gBAAcC;EAOpB,MAAM,QAAQ;EAOd,MAAM,SAASC,SAAiC,SAAC,QAA2B;EAC5E,MAAM,OAAO;EAMb,MAAM,KAAK,aAAa,gBAAgB;EACxC,MAAM,EAAE,MAAM,UAAU;;EAKxB,MAAM,WAAW,eAAe,OAAO,OAAO,QAAQ;;EAEtD,MAAM,SAAS,eAAgB,MAAM,WAAW,KAAA,IAAY,MAAM,MAAO;EACzE,MAAM,WAAW,eAAe,CAAC,CAAC,OAAO,SAAS,CAAC,SAAS,KAAK;EAEjE,MAAM,OAAO,eAA4B,MAAM;EAE/C,SAAS,IAAI,QAAuB;GAClC,KAAK,UAAU,MAAM;GACrB,IAAI,OAAO,SAAS,UAAU,OAAO,QAAQ,OAAO;QAC/C,IAAI,OAAO,OAAO,OAAO,QAAQ,mBAAmB,CAAC,OAAO,KAAK,GAAG,MAAM,CAAC,CAAC,MAAM;GACvF,UAAe;EACjB;;;;;;EAOA,eAAe,YAAY;GACzB,MAAM,SAAS;GACf,MAAM,KAAK,KAAK;GAChB,MAAM,MAAM,SAAS;GACrB,IAAI,CAAC,MAAO,OAAO,QAAQ,SAAS,QAAQ,CAAC,GAAG,SAAS,GAAG,GAAI;GAChE,IAAI,OAAO,QAAQ,SAAS,QAAQ,GAAG,SAAS,GAAG,KAAK,IAAI,aAAa;GACzE,IAAI,IAAI,OAAO,MAAM;QAChB,GAAG,cAA2B,IAAI,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,M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GAAA,CAAA,C"}
|
|
1
|
+
{"version":3,"file":"comment-thread.vue_vue_type_script_setup_true_lang.js","names":["DouTextarea","DouTextareaComponent","_useModel","_openBlock","_createElementBlock","_normalizeClass","_unref","_renderSlot","_createVNode","_createElementVNode","_toDisplayString","_createBlock","_withCtx","_createTextVNode","_createCommentVNode","_Fragment","_renderList"],"sources":["../../../src/components/comment-thread/comment-thread.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, MoreHorizontalIcon, RotateCcwIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onMounted, ref, useTemplateRef } from 'vue'\nimport type { TextareaHTMLAttributes } from 'vue'\nimport type { WithAttributes } from '../../utils/install'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouAvatar } from '../avatar'\nimport { DouButton } from '../button'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouDropdown, DouDropdownItem } from '../dropdown'\nimport { DouRelativeTime } from '../relative-time'\nimport { DouTextarea as DouTextareaComponent } from '../textarea'\nimport { DouTooltip } from '../tooltip'\nimport {\n applyCommentAction,\n createCommentId,\n type CommentAction,\n type CommentItem,\n type CommentThread,\n} from './comments'\nimport type {\n CommentThreadEmits,\n CommentThreadExpose,\n CommentThreadProps,\n CommentThreadSlots,\n} from './comment-thread'\n\n// 让模板里也能写这个组件转交的原生属性\nconst DouTextarea = DouTextareaComponent as WithAttributes<\n typeof DouTextareaComponent,\n TextareaHTMLAttributes\n>\n\ndefineOptions({ name: 'DouCommentThread' })\n\nconst props = withDefaults(defineProps<CommentThreadProps>(), {\n author: undefined,\n readonly: false,\n resolvable: true,\n placeholder: undefined,\n autofocus: false,\n})\n// without `v-model:thread`, the thread is kept here\nconst thread = defineModel<CommentThread | null>('thread', { default: null })\nconst emit = defineEmits<{\n action: CommentThreadEmits['action']\n cancel: CommentThreadEmits['cancel']\n}>()\ndefineSlots<CommentThreadSlots>()\n\nconst ns = useNamespace('comment-thread')\nconst { t } = useLocale()\n\n/** A week: older comments show their date instead of \"3 days ago\". */\nconst WEEK = 7 * 24 * 3600 * 1000\n\nconst resolved = computed(() => thread.value?.resolved)\n/** Who may change things: nobody when read-only, or when no `author` says who is writing. */\nconst writer = computed(() => (props.readonly ? undefined : props.author))\nconst canWrite = computed(() => !!writer.value && !resolved.value)\n\nconst root = useTemplateRef<HTMLElement>('root')\n\nfunction act(action: CommentAction) {\n emit('action', action)\n if (action.type === 'create') thread.value = action.thread\n else if (thread.value) thread.value = applyCommentAction([thread.value], action)[0] ?? null\n void keepFocus()\n}\n\n/**\n * The button or box that held focus can go with a change (the edit box\n * once saved, the reply box once resolved): focus moves on to the reply\n * box, or the reopen button, instead of falling to the page.\n */\nasync function keepFocus() {\n await nextTick()\n const el = root.value\n const now = document.activeElement\n if (!el || (now && now !== document.body && !el.contains(now))) return\n if (now && now !== document.body && el.contains(now) && now.isConnected) return\n if (box.value) focus()\n else el.querySelector<HTMLElement>(`.${ns.e('status')} button`)?.focus({ preventScroll: true })\n}\n\nconst now = () => new Date().toISOString()\n\n// writing a new comment or a reply\nconst draft = ref('')\nconst box = useTemplateRef<InstanceType<typeof DouTextarea>>('box')\n\nfunction send() {\n const body = draft.value.trim()\n const author = writer.value\n if (!body || !author) return\n const comment: CommentItem = {\n id: createCommentId(),\n author: { ...author },\n body,\n createdAt: now(),\n }\n draft.value = ''\n if (thread.value) act({ type: 'reply', threadId: thread.value.id, comment })\n else act({ type: 'create', thread: { id: createCommentId(), comments: [comment] } })\n}\n\n/** A key handled here: not the page's too. */\nfunction handled(event: KeyboardEvent) {\n event.preventDefault()\n event.stopPropagation()\n}\n\nfunction onBoxKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n send()\n } else if (event.key === 'Escape') {\n // an empty box lets Escape go on, to close the popover or drawer around\n if (draft.value) {\n handled(event)\n draft.value = ''\n } else emit('cancel')\n }\n}\n\n// changing a comment in place\nconst editing = ref<string | null>(null)\nconst editDraft = ref('')\nconst editBox = useTemplateRef<InstanceType<typeof DouTextarea>[]>('editBox')\n\nfunction startEdit(comment: CommentItem) {\n confirming.value = false\n editing.value = comment.id\n editDraft.value = comment.body\n void nextTick(() => {\n const el = editBox.value?.[0]?.textarea\n el?.focus()\n el?.setSelectionRange(el.value.length, el.value.length)\n })\n}\n\nfunction saveEdit() {\n const id = editing.value\n const body = editDraft.value.trim()\n if (!id || !thread.value || !body) return\n editing.value = null\n const before = thread.value.comments.find((comment) => comment.id === id)\n if (before?.body === body) return void keepFocus()\n act({ type: 'edit', threadId: thread.value.id, commentId: id, body, editedAt: now() })\n}\n\nfunction onEditKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter' && !event.shiftKey) {\n handled(event)\n saveEdit()\n } else if (event.key === 'Escape') {\n handled(event)\n editing.value = null\n void keepFocus()\n }\n}\n\n// deleting the first comment takes the thread with it: asked first\nconst confirming = ref(false)\n\nfunction onMenu(comment: CommentItem, index: number, value: unknown) {\n if (!thread.value) return\n if (value === 'edit') startEdit(comment)\n else if (value === 'delete') {\n if (index === 0) confirming.value = true\n else act({ type: 'delete', threadId: thread.value.id, commentId: comment.id })\n }\n}\n\nfunction removeThread() {\n if (!thread.value) return\n confirming.value = false\n act({ type: 'remove', threadId: thread.value.id })\n}\n\nfunction resolve() {\n const by = writer.value\n if (thread.value && by)\n act({ type: 'resolve', threadId: thread.value.id, by: { ...by }, at: now() })\n}\n\nfunction reopen() {\n if (thread.value) act({ type: 'reopen', threadId: thread.value.id })\n}\n\nconst placeholderText = computed(() =>\n thread.value\n ? t('commentThread.replyPlaceholder')\n : (props.placeholder ?? t('commentThread.placeholder')),\n)\n\nconst focus = () => box.value?.textarea?.focus({ preventScroll: true })\nonMounted(() => {\n if (props.autofocus) focus()\n})\ndefineExpose<CommentThreadExpose>({ focus })\n</script>\n\n<template>\n <div ref=\"root\" role=\"group\" :class=\"[ns.b(), { 'is-resolved': !!resolved, 'is-new': !thread }]\">\n <slot name=\"header\" />\n <div v-if=\"resolved\" :class=\"ns.e('status')\">\n <CheckIcon :class=\"ns.e('status-icon')\" />\n <span :class=\"ns.e('status-text')\">{{\n t('commentThread.resolvedBy', { name: resolved.by.name })\n }}</span>\n <DouButton v-if=\"writer\" variant=\"ghost\" size=\"sm\" @click=\"reopen\">\n <template #leading><RotateCcwIcon /></template>\n {{ t('commentThread.reopen') }}\n </DouButton>\n </div>\n <ol v-if=\"thread?.comments.length\" :class=\"ns.e('list')\">\n <li v-for=\"(comment, index) in thread.comments\" :key=\"comment.id\" :class=\"ns.e('comment')\">\n <div :class=\"ns.e('head')\">\n <DouAvatar\n :name=\"comment.author.name\"\n :src=\"comment.author.avatar\"\n size=\"sm\"\n :class=\"ns.e('avatar')\"\n />\n <span :class=\"ns.e('author')\">{{ comment.author.name }}</span>\n <DouRelativeTime\n :value=\"comment.createdAt\"\n short\n :absolute-after=\"WEEK\"\n :class=\"ns.e('time')\"\n />\n <span v-if=\"comment.editedAt\" :class=\"ns.e('edited')\">{{\n t('commentThread.edited')\n }}</span>\n <div v-if=\"writer\" :class=\"ns.e('actions')\">\n <DouTooltip\n v-if=\"index === 0 && resolvable && !resolved\"\n :content=\"t('commentThread.resolve')\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"t('commentThread.resolve')\"\n @click=\"resolve\"\n >\n <CheckIcon />\n </DouButton>\n </DouTooltip>\n <DouDropdown\n v-if=\"comment.author.id === writer.id && !resolved\"\n placement=\"bottom-end\"\n @select=\"(value) => onMenu(comment, index, value)\"\n >\n <DouButton variant=\"ghost\" size=\"sm\" :aria-label=\"t('commentThread.more')\">\n <MoreHorizontalIcon />\n </DouButton>\n <template #menu>\n <DouDropdownItem value=\"edit\">{{ t('commentThread.edit') }}</DouDropdownItem>\n <DouDropdownItem value=\"delete\" tone=\"danger\">{{\n index === 0 ? t('commentThread.deleteThread') : t('commentThread.delete')\n }}</DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n </div>\n <div v-if=\"editing === comment.id\" :class=\"ns.e('editor')\">\n <DouTextarea\n ref=\"editBox\"\n v-model=\"editDraft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n size=\"sm\"\n @keydown=\"onEditKeydown\"\n />\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"editing = null\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!editDraft.trim()\"\n @click=\"saveEdit\"\n >{{ t('commentThread.save') }}</DouButton\n >\n </div>\n </div>\n <p v-else :class=\"ns.e('body')\">{{ comment.body }}</p>\n <div v-if=\"index === 0 && confirming\" :class=\"ns.e('confirm')\" role=\"alert\">\n <span>{{ t('commentThread.deleteThreadConfirm') }}</span>\n <div :class=\"ns.e('buttons')\">\n <DouButton variant=\"ghost\" size=\"sm\" @click=\"confirming = false\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton variant=\"solid\" tone=\"danger\" size=\"sm\" @click=\"removeThread\">{{\n t('commentThread.delete')\n }}</DouButton>\n </div>\n </div>\n </li>\n </ol>\n <div v-if=\"canWrite\" :class=\"ns.e('composer')\">\n <DouTextarea\n ref=\"box\"\n v-model=\"draft\"\n :autosize=\"{ minRows: 1, maxRows: 8 }\"\n :placeholder=\"placeholderText\"\n :aria-label=\"placeholderText\"\n size=\"sm\"\n @keydown=\"onBoxKeydown\"\n />\n <div v-if=\"draft || !thread\" :class=\"ns.e('buttons')\">\n <DouButton v-if=\"!thread\" variant=\"ghost\" size=\"sm\" @click=\"emit('cancel')\">{{\n t('commentThread.cancel')\n }}</DouButton>\n <DouButton\n variant=\"solid\"\n tone=\"primary\"\n size=\"sm\"\n :disabled=\"!draft.trim()\"\n @click=\"send\"\n >{{ t('commentThread.send') }}</DouButton\n >\n </div>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;AAuDA,IAAM,OAAO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,CAAA,sBAAA,CAAA,GAAA,CAAA,C;;;;;IAMA,SAAA,SAAXH,UAAA,GAAAC,mBAuBM,OAAA;;KAvBgB,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,UAAA,CAAA;I,IAC/BE,YAQEF,MAAAN,aAAA,GAAA;KAPI,SAAA;KAAJ,KAAI;KACK,YAAA,MAAA;KAAA,uBAAA,OAAA,OAAA,OAAA,MAAA,WAAA,MAAK,QAAA;KACb,UAAU;MAAA,SAAA;MAAA,SAAA;KAAA;KACV,aAAa,gBAAA;KACb,cAAY,gBAAA;KACb,MAAK;KACJ,WAAS;;;;;I,IAED,MAAA,SAAK,CAAK,OAAA,SAArBG,UAAA,GAAAC,mBAYM,OAAA;;KAZwB,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA;I,IACrB,CAAA,OAAA,SAAlBH,UAAA,GAAAQ,YAEcL,MAAA,SAAA,GAAA;;KAFY,SAAQ;KAAQ,MAAK;KAAM,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,KAAI,QAAA;;KAAY,SAAAM,cAE1E,CADAC,gBAAAH,gBAAAJ,MAAA,CAAA,CAAC,CAAA,sBAAA,CAAA,GAAA,CAAA,C;;I,oCAEHE,YAOCF,MAAA,SAAA,GAAA;KANC,SAAQ;KACR,MAAK;KACL,MAAK;KACJ,UAAQ,CAAG,MAAA,MAAM,KAAI;KACrB,SAAO;;KACP,SAAAM,cAA6B,CAA1BC,gBAAAH,gBAAAJ,MAAA,CAAA,CAAC,CAAA,oBAAA,CAAA,GAAA,CAAA,C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setInstalledAppContext } from "../../utils/app-context.js";
|
|
1
2
|
import { configProviderKey } from "./config-provider.js";
|
|
2
3
|
import { zhCN } from "../../locale/zh-cn.js";
|
|
3
4
|
import { computed, hasInjectionContext, inject, provide, toValue } from "vue";
|
|
@@ -35,8 +36,10 @@ function provideGlobalConfig(config, app) {
|
|
|
35
36
|
}
|
|
36
37
|
return result;
|
|
37
38
|
});
|
|
38
|
-
if (app)
|
|
39
|
-
|
|
39
|
+
if (app) {
|
|
40
|
+
app.provide(configProviderKey, merged);
|
|
41
|
+
setInstalledAppContext(app._context);
|
|
42
|
+
} else provide(configProviderKey, merged);
|
|
40
43
|
return merged;
|
|
41
44
|
}
|
|
42
45
|
/** The config in effect for the current component, with defaults filled in. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-config.js","names":[],"sources":["../../../src/components/config-provider/use-config.ts"],"sourcesContent":["import { computed, hasInjectionContext, inject, provide, toValue } from 'vue'\nimport type { App, ComputedRef, MaybeRefOrGetter } from 'vue'\nimport { zhCN } from '../../locale/zh-cn'\nimport type { Locale } from '../../locale/types'\nimport { configProviderKey } from './config-provider'\nimport type { GlobalConfig, ResolvedGlobalConfig } from './config-provider'\n\nconst defaults: ResolvedGlobalConfig = {\n size: 'md',\n locale: zhCN,\n zIndex: 2000,\n defaults: {},\n motion: 'auto',\n}\n\nfunction defined(config: GlobalConfig): GlobalConfig {\n return Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined))\n}\n\n/**\n * Provide defaults to every component below the current one, or to the\n * whole app when `app` is given. Values left `undefined` fall through to\n * the nearest provider above.\n */\nexport function provideGlobalConfig(\n config: MaybeRefOrGetter<GlobalConfig>,\n app?: App,\n): ComputedRef<GlobalConfig> {\n const parent = !app && hasInjectionContext() ? inject(configProviderKey, undefined) : undefined\n const merged = computed(() => {\n const own = defined(toValue(config))\n const result: GlobalConfig = { ...parent?.value, ...own }\n // component defaults merge per component, so a nested provider can add to them\n if (parent?.value.defaults && own.defaults) {\n const perComponent: Record<string, object | undefined> = { ...parent.value.defaults }\n for (const [name, props] of Object.entries(own.defaults as Record<string, object>)) {\n perComponent[name] = { ...perComponent[name], ...props }\n }\n result.defaults = perComponent as GlobalConfig['defaults']\n }\n return result\n })\n if (app) app.provide(configProviderKey, merged)\n else provide(configProviderKey, merged)\n return merged\n}\n\n/** The config in effect for the current component, with defaults filled in. */\nexport function useGlobalConfig(): ComputedRef<ResolvedGlobalConfig> {\n const config = hasInjectionContext() ? inject(configProviderKey, undefined) : undefined\n return computed(() => ({ ...defaults, ...config?.value }))\n}\n\ntype MessagePath<T> = {\n [K in keyof T & string]: T[K] extends string\n ? K\n : T[K] extends object\n ? `${K}.${MessagePath<T[K]>}`\n : never\n}[keyof T & string]\n\nexport type LocaleMessagePath = MessagePath<Locale>\n\nexport type TranslateParams = Record<string, string | number>\n\n/** Fill `{name}` placeholders. */\nexport function format(message: string, params?: TranslateParams): string {\n if (!params) return message\n return message.replace(/\\{(\\w+)\\}/g, (match, key: string) =>\n key in params ? String(params[key]) : match,\n )\n}\n\nexport function translate(locale: Locale, path: LocaleMessagePath, params?: TranslateParams) {\n let value: unknown = locale\n for (const key of path.split('.')) value = (value as Record<string, unknown>)?.[key]\n return typeof value === 'string' ? format(value, params) : path\n}\n\n/** Read strings from the locale in effect. */\nexport function useLocale() {\n const config = useGlobalConfig()\n const locale = computed(() => config.value.locale)\n const t = (path: LocaleMessagePath, params?: TranslateParams) =>\n translate(locale.value, path, params)\n return { locale, t }\n}\n\nlet counter = 0\n\n/**\n * Stack floating layers. Each call to `next()` returns a `z-index` above\n * every one handed out before, starting from the configured base.\n */\nexport function useZIndex() {\n const config = useGlobalConfig()\n const base = computed(() => config.value.zIndex)\n return {\n base,\n current: () => base.value + counter,\n next: () => base.value + ++counter,\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-config.js","names":[],"sources":["../../../src/components/config-provider/use-config.ts"],"sourcesContent":["import { computed, hasInjectionContext, inject, provide, toValue } from 'vue'\nimport { setInstalledAppContext } from '../../utils/app-context'\nimport type { App, ComputedRef, MaybeRefOrGetter } from 'vue'\nimport { zhCN } from '../../locale/zh-cn'\nimport type { Locale } from '../../locale/types'\nimport { configProviderKey } from './config-provider'\nimport type { GlobalConfig, ResolvedGlobalConfig } from './config-provider'\n\nconst defaults: ResolvedGlobalConfig = {\n size: 'md',\n locale: zhCN,\n zIndex: 2000,\n defaults: {},\n motion: 'auto',\n}\n\nfunction defined(config: GlobalConfig): GlobalConfig {\n return Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined))\n}\n\n/**\n * Provide defaults to every component below the current one, or to the\n * whole app when `app` is given. Values left `undefined` fall through to\n * the nearest provider above.\n */\nexport function provideGlobalConfig(\n config: MaybeRefOrGetter<GlobalConfig>,\n app?: App,\n): ComputedRef<GlobalConfig> {\n const parent = !app && hasInjectionContext() ? inject(configProviderKey, undefined) : undefined\n const merged = computed(() => {\n const own = defined(toValue(config))\n const result: GlobalConfig = { ...parent?.value, ...own }\n // component defaults merge per component, so a nested provider can add to them\n if (parent?.value.defaults && own.defaults) {\n const perComponent: Record<string, object | undefined> = { ...parent.value.defaults }\n for (const [name, props] of Object.entries(own.defaults as Record<string, object>)) {\n perComponent[name] = { ...perComponent[name], ...props }\n }\n result.defaults = perComponent as GlobalConfig['defaults']\n }\n return result\n })\n if (app) {\n app.provide(configProviderKey, merged)\n // what is rendered outside the app's tree (dialog(), toast(), renderFlowSVG) takes it from here too\n // oxlint-disable-next-line no-underscore-dangle -- the public way to reach an app's context\n setInstalledAppContext(app._context)\n } else provide(configProviderKey, merged)\n return merged\n}\n\n/** The config in effect for the current component, with defaults filled in. */\nexport function useGlobalConfig(): ComputedRef<ResolvedGlobalConfig> {\n const config = hasInjectionContext() ? inject(configProviderKey, undefined) : undefined\n return computed(() => ({ ...defaults, ...config?.value }))\n}\n\ntype MessagePath<T> = {\n [K in keyof T & string]: T[K] extends string\n ? K\n : T[K] extends object\n ? `${K}.${MessagePath<T[K]>}`\n : never\n}[keyof T & string]\n\nexport type LocaleMessagePath = MessagePath<Locale>\n\nexport type TranslateParams = Record<string, string | number>\n\n/** Fill `{name}` placeholders. */\nexport function format(message: string, params?: TranslateParams): string {\n if (!params) return message\n return message.replace(/\\{(\\w+)\\}/g, (match, key: string) =>\n key in params ? String(params[key]) : match,\n )\n}\n\nexport function translate(locale: Locale, path: LocaleMessagePath, params?: TranslateParams) {\n let value: unknown = locale\n for (const key of path.split('.')) value = (value as Record<string, unknown>)?.[key]\n return typeof value === 'string' ? format(value, params) : path\n}\n\n/** Read strings from the locale in effect. */\nexport function useLocale() {\n const config = useGlobalConfig()\n const locale = computed(() => config.value.locale)\n const t = (path: LocaleMessagePath, params?: TranslateParams) =>\n translate(locale.value, path, params)\n return { locale, t }\n}\n\nlet counter = 0\n\n/**\n * Stack floating layers. Each call to `next()` returns a `z-index` above\n * every one handed out before, starting from the configured base.\n */\nexport function useZIndex() {\n const config = useGlobalConfig()\n const base = computed(() => config.value.zIndex)\n return {\n base,\n current: () => base.value + counter,\n next: () => base.value + ++counter,\n }\n}\n"],"mappings":";;;;;AAQA,IAAM,WAAiC;CACrC,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,UAAU,CAAC;CACX,QAAQ;AACV;AAEA,SAAS,QAAQ,QAAoC;CACnD,OAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAAC;AAC7F;;;;;;AAOA,SAAgB,oBACd,QACA,KAC2B;CAC3B,MAAM,SAAS,CAAC,OAAO,oBAAoB,IAAI,OAAO,mBAAmB,KAAA,CAAS,IAAI,KAAA;CACtF,MAAM,SAAS,eAAe;EAC5B,MAAM,MAAM,QAAQ,QAAQ,MAAM,CAAC;EACnC,MAAM,SAAuB;GAAE,GAAG,QAAQ;GAAO,GAAG;EAAI;EAExD,IAAI,QAAQ,MAAM,YAAY,IAAI,UAAU;GAC1C,MAAM,eAAmD,EAAE,GAAG,OAAO,MAAM,SAAS;GACpF,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,IAAI,QAAkC,GAC/E,aAAa,QAAQ;IAAE,GAAG,aAAa;IAAO,GAAG;GAAM;GAEzD,OAAO,WAAW;EACpB;EACA,OAAO;CACT,CAAC;CACD,IAAI,KAAK;EACP,IAAI,QAAQ,mBAAmB,MAAM;EAGrC,uBAAuB,IAAI,QAAQ;CACrC,OAAO,QAAQ,mBAAmB,MAAM;CACxC,OAAO;AACT;;AAGA,SAAgB,kBAAqD;CACnE,MAAM,SAAS,oBAAoB,IAAI,OAAO,mBAAmB,KAAA,CAAS,IAAI,KAAA;CAC9E,OAAO,gBAAgB;EAAE,GAAG;EAAU,GAAG,QAAQ;CAAM,EAAE;AAC3D;;AAeA,SAAgB,OAAO,SAAiB,QAAkC;CACxE,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,QAAQ,QAAQ,eAAe,OAAO,QAC3C,OAAO,SAAS,OAAO,OAAO,IAAI,IAAI,KACxC;AACF;AAEA,SAAgB,UAAU,QAAgB,MAAyB,QAA0B;CAC3F,IAAI,QAAiB;CACrB,KAAK,MAAM,OAAO,KAAK,MAAM,GAAG,GAAG,QAAS,QAAoC;CAChF,OAAO,OAAO,UAAU,WAAW,OAAO,OAAO,MAAM,IAAI;AAC7D;;AAGA,SAAgB,YAAY;CAC1B,MAAM,SAAS,gBAAgB;CAC/B,MAAM,SAAS,eAAe,OAAO,MAAM,MAAM;CACjD,MAAM,KAAK,MAAyB,WAClC,UAAU,OAAO,OAAO,MAAM,MAAM;CACtC,OAAO;EAAE;EAAQ;CAAE;AACrB;AAEA,IAAI,UAAU;;;;;AAMd,SAAgB,YAAY;CAC1B,MAAM,SAAS,gBAAgB;CAC/B,MAAM,OAAO,eAAe,OAAO,MAAM,MAAM;CAC/C,OAAO;EACL;EACA,eAAe,KAAK,QAAQ;EAC5B,YAAY,KAAK,QAAQ,EAAE;CAC7B;AACF"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
import { installedAppContext } from "../../utils/app-context.js";
|
|
1
2
|
import dialog_box_default from "./dialog-box.js";
|
|
2
3
|
import { getCurrentInstance, h, markRaw, render } from "vue";
|
|
3
4
|
// src/components/dialog/functional.ts
|
|
4
|
-
var context = null;
|
|
5
|
-
/** Remember the app whose config (locale, z-index) dialogs opened by `dialog` should use. */
|
|
6
|
-
function setDialogContext(appContext) {
|
|
7
|
-
context = appContext;
|
|
8
|
-
}
|
|
9
5
|
var open = /* @__PURE__ */ new Set();
|
|
10
6
|
var noop = () => {};
|
|
11
7
|
function normalize(input, extra) {
|
|
@@ -35,7 +31,7 @@ function show(kind, options, answer, appContext) {
|
|
|
35
31
|
},
|
|
36
32
|
onClosed: () => render(null, container)
|
|
37
33
|
});
|
|
38
|
-
vnode.appContext = appContext ??
|
|
34
|
+
vnode.appContext = appContext ?? installedAppContext();
|
|
39
35
|
render(vnode, container);
|
|
40
36
|
close = () => controller.close?.();
|
|
41
37
|
open.add(close);
|
|
@@ -70,6 +66,6 @@ var dialog = createDialogApi(null);
|
|
|
70
66
|
function useDialog() {
|
|
71
67
|
return createDialogApi(getCurrentInstance()?.appContext ?? null);
|
|
72
68
|
}
|
|
73
|
-
export { dialog,
|
|
69
|
+
export { dialog, useDialog };
|
|
74
70
|
|
|
75
71
|
//# sourceMappingURL=functional.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functional.js","names":["DialogBox"],"sources":["../../../src/components/dialog/functional.ts"],"sourcesContent":["import { getCurrentInstance, h, markRaw, render } from 'vue'\nimport type { AppContext } from 'vue'\nimport DialogBox from './dialog-box.vue'\nimport type {\n DialogAlertOptions,\n DialogBoxKind,\n DialogBoxState,\n DialogConfirmOptions,\n DialogHandle,\n DialogPromptOptions,\n} from './dialog-api'\n\
|
|
1
|
+
{"version":3,"file":"functional.js","names":["DialogBox"],"sources":["../../../src/components/dialog/functional.ts"],"sourcesContent":["import { getCurrentInstance, h, markRaw, render } from 'vue'\nimport type { AppContext } from 'vue'\nimport { installedAppContext } from '../../utils/app-context'\nimport DialogBox from './dialog-box.vue'\nimport type {\n DialogAlertOptions,\n DialogBoxKind,\n DialogBoxState,\n DialogConfirmOptions,\n DialogHandle,\n DialogPromptOptions,\n} from './dialog-api'\n\nconst open = new Set<() => void>()\nconst noop = () => {}\n\ntype Input<T> = string | T\n\nfunction normalize<T extends object>(input: Input<T>, extra?: T): T {\n return typeof input === 'string' ? ({ ...extra, content: input } as T) : { ...input }\n}\n\nfunction show<T>(\n kind: DialogBoxKind,\n options: DialogBoxState,\n answer: (confirmed: boolean, value: string) => T,\n appContext: AppContext | null,\n): DialogHandle<T> {\n let close: () => void = noop\n const promise = new Promise<T>((resolve) => {\n // Nothing to show while rendering on the server: answer \"cancel\".\n if (typeof document === 'undefined') {\n resolve(answer(false, ''))\n return\n }\n const container = document.createElement('div')\n const controller: { close?: () => void } = {}\n const vnode = h(DialogBox, {\n options: markRaw({ ...options, kind }),\n controller,\n onSettle: (confirmed: boolean, value: string) => {\n open.delete(close)\n resolve(answer(confirmed, value))\n },\n onClosed: () => render(null, container),\n })\n vnode.appContext = appContext ?? installedAppContext()\n render(vnode, container)\n close = () => controller.close?.()\n open.add(close)\n })\n return Object.assign(promise, { close: () => close() })\n}\n\nexport interface DialogApi {\n /** A message with one button. Resolves once it is dismissed. */\n alert: (input: Input<DialogAlertOptions>, options?: DialogAlertOptions) => DialogHandle<void>\n /** A question with \"OK\" and \"Cancel\". Resolves to whether it was confirmed. */\n confirm: (\n input: Input<DialogConfirmOptions>,\n options?: DialogConfirmOptions,\n ) => DialogHandle<boolean>\n /** Ask for one line of text. Resolves to the value, or `null` when cancelled. */\n prompt: (\n input: Input<DialogPromptOptions>,\n options?: DialogPromptOptions,\n ) => DialogHandle<string | null>\n /** Close every open dialog as if \"cancel\" had been pressed. */\n closeAll: () => void\n}\n\nfunction createDialogApi(appContext: AppContext | null): DialogApi {\n return {\n alert: (input, extra) =>\n show('alert', normalize(input, extra) as DialogBoxState, () => undefined, appContext),\n confirm: (input, extra) =>\n show('confirm', normalize(input, extra) as DialogBoxState, (ok) => ok, appContext),\n prompt: (input, extra) =>\n show(\n 'prompt',\n normalize(input, extra) as DialogBoxState,\n (ok, value) => (ok ? value : null),\n appContext,\n ),\n closeAll: () => {\n // Deleting the entry being visited is safe while iterating a Set.\n for (const close of open) close()\n },\n }\n}\n\n/**\n * Ask a quick question without a template.\n *\n * ```ts\n * if (await dialog.confirm({ title: '删除项目?', content: '此操作无法撤销。', tone: 'danger' })) {\n * await remove()\n * }\n * const name = await dialog.prompt({ title: '重命名', defaultValue: 'dou-ui' })\n * ```\n *\n * Dialogs take the config (locale, z-index) of the app DouUI was installed\n * in. Inside a component, `useDialog()` uses that component's app instead.\n */\nexport const dialog: DialogApi = createDialogApi(null)\n\n/** `dialog`, bound to the app of the component that calls it. */\nexport function useDialog(): DialogApi {\n return createDialogApi(getCurrentInstance()?.appContext ?? null)\n}\n"],"mappings":";;;;AAaA,IAAM,uBAAO,IAAI,IAAgB;AACjC,IAAM,aAAa,CAAC;AAIpB,SAAS,UAA4B,OAAiB,OAAc;CAClE,OAAO,OAAO,UAAU,WAAY;EAAE,GAAG;EAAO,SAAS;CAAM,IAAU,EAAE,GAAG,MAAM;AACtF;AAEA,SAAS,KACP,MACA,SACA,QACA,YACiB;CACjB,IAAI,QAAoB;CACxB,MAAM,UAAU,IAAI,SAAY,YAAY;EAE1C,IAAI,OAAO,aAAa,aAAa;GACnC,QAAQ,OAAO,OAAO,EAAE,CAAC;GACzB;EACF;EACA,MAAM,YAAY,SAAS,cAAc,KAAK;EAC9C,MAAM,aAAqC,CAAC;EAC5C,MAAM,QAAQ,EAAEA,oBAAW;GACzB,SAAS,QAAQ;IAAE,GAAG;IAAS;GAAK,CAAC;GACrC;GACA,WAAW,WAAoB,UAAkB;IAC/C,KAAK,OAAO,KAAK;IACjB,QAAQ,OAAO,WAAW,KAAK,CAAC;GAClC;GACA,gBAAgB,OAAO,MAAM,SAAS;EACxC,CAAC;EACD,MAAM,aAAa,cAAc,oBAAoB;EACrD,OAAO,OAAO,SAAS;EACvB,cAAc,WAAW,QAAQ;EACjC,KAAK,IAAI,KAAK;CAChB,CAAC;CACD,OAAO,OAAO,OAAO,SAAS,EAAE,aAAa,MAAM,EAAE,CAAC;AACxD;AAmBA,SAAS,gBAAgB,YAA0C;CACjE,OAAO;EACL,QAAQ,OAAO,UACb,KAAK,SAAS,UAAU,OAAO,KAAK,SAA2B,KAAA,GAAW,UAAU;EACtF,UAAU,OAAO,UACf,KAAK,WAAW,UAAU,OAAO,KAAK,IAAsB,OAAO,IAAI,UAAU;EACnF,SAAS,OAAO,UACd,KACE,UACA,UAAU,OAAO,KAAK,IACrB,IAAI,UAAW,KAAK,QAAQ,MAC7B,UACF;EACF,gBAAgB;GAEd,KAAK,MAAM,SAAS,MAAM,MAAM;EAClC;CACF;AACF;;;;;;;;;;;;;;AAeA,IAAa,SAAoB,gBAAgB,IAAI;;AAGrD,SAAgB,YAAuB;CACrC,OAAO,gBAAgB,mBAAmB,CAAC,EAAE,cAAc,IAAI;AACjE"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { setInstalledAppContext } from "../../utils/app-context.js";
|
|
1
2
|
import { withInstall } from "../../utils/install.js";
|
|
2
3
|
import dialog_default from "./dialog.js";
|
|
3
|
-
import { dialog,
|
|
4
|
+
import { dialog, useDialog } from "./functional.js";
|
|
4
5
|
// src/components/dialog/index.ts
|
|
5
6
|
var DouDialog = withInstall(dialog_default);
|
|
6
7
|
var installDialog = DouDialog.install;
|
|
7
8
|
DouDialog.install = (app) => {
|
|
8
9
|
installDialog?.(app);
|
|
9
|
-
|
|
10
|
+
setInstalledAppContext(app._context);
|
|
10
11
|
};
|
|
11
|
-
export { DouDialog, DouDialog as default, dialog,
|
|
12
|
+
export { DouDialog, DouDialog as default, dialog, useDialog };
|
|
12
13
|
|
|
13
14
|
//# sourceMappingURL=index.js.map
|