dou-ui 0.1.0-alpha.23 → 0.1.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +26 -12
- 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/style.css +1 -1
- package/package.json +3 -3
|
@@ -25,6 +25,7 @@ var _hoisted_2 = [
|
|
|
25
25
|
"id",
|
|
26
26
|
"aria-busy",
|
|
27
27
|
"data-placement",
|
|
28
|
+
"data-trigger",
|
|
28
29
|
"data-dou-theme"
|
|
29
30
|
];
|
|
30
31
|
var _hoisted_3 = [
|
|
@@ -209,19 +210,31 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
209
210
|
const { next: nextZIndex } = useZIndex();
|
|
210
211
|
const menuZIndex = ref();
|
|
211
212
|
const menuWidth = ref();
|
|
213
|
+
const menuMaxWidth = ref();
|
|
212
214
|
const menuRendered = ref(false);
|
|
213
215
|
const { theme, sync: syncTheme } = useThemeScope(() => rootRef.value);
|
|
216
|
+
function readMenuMaxWidth() {
|
|
217
|
+
if (typeof window === "undefined" || teleportTarget.value.disabled) return void 0;
|
|
218
|
+
const el = rootRef.value;
|
|
219
|
+
if (!el) return void 0;
|
|
220
|
+
const value = getComputedStyle(el).getPropertyValue("--dou-chat-input-menu-max-width").trim();
|
|
221
|
+
if (!value) return void 0;
|
|
222
|
+
const target = typeof teleportTarget.value.to === "string" ? document.querySelector(teleportTarget.value.to) : teleportTarget.value.to;
|
|
223
|
+
return value !== (target ? getComputedStyle(target).getPropertyValue("--dou-chat-input-menu-max-width").trim() : "") ? value : void 0;
|
|
224
|
+
}
|
|
214
225
|
watch(menuOpen, (value) => {
|
|
215
226
|
if (!value) return;
|
|
216
227
|
menuRendered.value = true;
|
|
217
228
|
menuZIndex.value = nextZIndex();
|
|
218
229
|
menuWidth.value = rootRef.value?.offsetWidth;
|
|
230
|
+
menuMaxWidth.value = readMenuMaxWidth();
|
|
219
231
|
syncTheme();
|
|
220
232
|
});
|
|
221
233
|
const menuStyle = computed(() => ({
|
|
222
234
|
...floatingStyle.value,
|
|
223
235
|
zIndex: menuZIndex.value,
|
|
224
|
-
"--dou-chat-input-menu-width": menuWidth.value ? `${menuWidth.value}px` : void 0
|
|
236
|
+
"--dou-chat-input-menu-width": menuWidth.value ? `${menuWidth.value}px` : void 0,
|
|
237
|
+
"--dou-chat-input-menu-max-width": menuMaxWidth.value
|
|
225
238
|
}));
|
|
226
239
|
useLayer({
|
|
227
240
|
open: menuOpen,
|
|
@@ -414,6 +427,7 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
414
427
|
"aria-busy": stale.value || void 0,
|
|
415
428
|
style: normalizeStyle(menuStyle.value),
|
|
416
429
|
"data-placement": unref(menuPlacement),
|
|
430
|
+
"data-trigger": token.value?.trigger,
|
|
417
431
|
"data-dou-theme": unref(theme),
|
|
418
432
|
role: "listbox",
|
|
419
433
|
onMousedown: _cache[2] || (_cache[2] = withModifiers(() => {}, ["prevent"]))
|
|
@@ -425,6 +439,7 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
425
439
|
class: normalizeClass([
|
|
426
440
|
unref(ns).e("option"),
|
|
427
441
|
unref(ns).is("default", !slots.option),
|
|
442
|
+
unref(ns).is("stacked", !slots.option && token.value?.trigger === "/" && !!option.description),
|
|
428
443
|
unref(ns).is("active", index === active.value),
|
|
429
444
|
unref(ns).is("disabled", !!option.disabled)
|
|
430
445
|
]),
|
|
@@ -435,17 +450,16 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
435
450
|
}, [renderSlot(_ctx.$slots, "option", {
|
|
436
451
|
option,
|
|
437
452
|
trigger: token.value.trigger
|
|
438
|
-
}, () => [
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
])], 42, _hoisted_3);
|
|
453
|
+
}, () => [option.icon ? (openBlock(), createBlock(resolveDynamicComponent(option.icon), {
|
|
454
|
+
key: 0,
|
|
455
|
+
class: normalizeClass(unref(ns).e("option-icon"))
|
|
456
|
+
}, null, 8, ["class"])) : createCommentVNode("", true), token.value?.trigger === "/" && option.description ? (openBlock(), createElementBlock("span", {
|
|
457
|
+
key: 1,
|
|
458
|
+
class: normalizeClass(unref(ns).e("option-content"))
|
|
459
|
+
}, [createElementVNode("span", { class: normalizeClass(unref(ns).e("option-label")) }, " /" + toDisplayString(option.label ?? option.value), 3), createElementVNode("span", { class: normalizeClass(unref(ns).e("option-description")) }, toDisplayString(option.description), 3)], 2)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [createElementVNode("span", { class: normalizeClass(unref(ns).e("option-label")) }, toDisplayString(token.value?.trigger === "/" ? "/" : "@") + toDisplayString(option.label ?? option.value), 3), option.description ? (openBlock(), createElementBlock("span", {
|
|
460
|
+
key: 0,
|
|
461
|
+
class: normalizeClass(unref(ns).e("option-description"))
|
|
462
|
+
}, toDisplayString(option.description), 3)) : createCommentVNode("", true)], 64))])], 42, _hoisted_3);
|
|
449
463
|
}), 128))], 46, _hoisted_2)) : createCommentVNode("", true)]),
|
|
450
464
|
_: 3
|
|
451
465
|
})], 8, ["to", "disabled"])) : createCommentVNode("", true),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-input.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_useModel","_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_renderSlot","_createCommentVNode","_withDirectives","_createElementVNode","_mergeProps","_vModelText","_createBlock","_Teleport","_createVNode","_Transition","_withCtx","_withModifiers","_Fragment","_renderList","_resolveDynamicComponent","_toDisplayString"],"sources":["../../../src/components/chat-input/chat-input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpIcon, StopIcon } from '@dou-ui/icons'\nimport {\n computed,\n getCurrentInstance,\n nextTick,\n onBeforeUnmount,\n onMounted,\n reactive,\n ref,\n useAttrs,\n useId,\n useTemplateRef,\n watch,\n} from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useTeleport } from '../../utils/teleport'\nimport { DouButton } from '../button'\nimport { useLocale, useZIndex } from '../config-provider/use-config'\nimport { useFormDisabled } from '../form/use-form-item'\nimport { findToken } from './chat-input'\nimport type {\n ChatInputEmits,\n ChatInputExpose,\n ChatInputOption,\n ChatInputProps,\n ChatInputSlots,\n ChatInputToken,\n} from './chat-input'\n\ndefineOptions({ name: 'DouChatInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ChatInputProps>(), {\n submitOn: 'enter',\n loading: false,\n size: 'md',\n disabled: false,\n minRows: 1,\n maxRows: 8,\n canSubmit: undefined,\n commands: () => [],\n mentions: () => [],\n filter: true,\n searchDelay: 300,\n teleport: undefined,\n})\nconst emit = defineEmits<ChatInputEmits>()\nconst slots = defineSlots<ChatInputSlots>()\nconst model = defineModel<string>({ default: '' })\n\nconst ns = useNamespace('chat-input')\nconst id = useId()\nconst { t } = useLocale()\nconst disabled = useFormDisabled(() => props.disabled)\nconst buttonSize = computed(() => (props.size === 'lg' ? 'md' : 'sm'))\n\n// `class` and `style` dress the frame, the rest goes to the textarea.\nconst attrs = useAttrs()\nconst textareaAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n return rest\n})\n\nconst textareaRef = useTemplateRef<HTMLTextAreaElement>('textarea')\n\nconst submittable = computed(\n () => !disabled.value && (props.canSubmit ?? model.value.trim().length > 0),\n)\n\nfunction resize() {\n const el = textareaRef.value\n if (!el) return\n const style = getComputedStyle(el)\n const lineHeight = Number.parseFloat(style.lineHeight) || 22\n const padding = Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom)\n const min = props.minRows * lineHeight + (padding || 0)\n const max = props.maxRows * lineHeight + (padding || 0)\n el.style.height = 'auto'\n const content = el.scrollHeight\n el.style.height = `${Math.min(Math.max(content, min), max)}px`\n el.style.overflowY = content > max ? 'auto' : 'hidden'\n}\nwatch([model, () => props.minRows, () => props.maxRows], () => nextTick(resize))\nonMounted(resize)\n\n// While a reply is generated the button stops it, unless something new\n// has been typed: then it sends, and the app may queue the message.\nconst stopping = computed(() => props.loading && !submittable.value)\n\nfunction submit() {\n if (!submittable.value) return\n emit('submit', model.value)\n}\n\nfunction stop() {\n if (props.loading) emit('stop')\n}\n\n// --- `/` command and `@` mention menu ---\nconst token = ref<ChatInputToken | null>(null)\nconst dismissed = ref<number | null>(null)\nconst active = ref(0)\n\n// While an input method composes, the text holds what is being spelled\n// (pinyin, say), not what will be typed: wait for it to finish.\nlet composing = false\nfunction onCaret(event?: Event) {\n if (composing || (event instanceof KeyboardEvent && isComposing(event))) return\n if ((event as InputEvent | undefined)?.isComposing) return\n readToken()\n}\nfunction onCompositionStart() {\n composing = true\n}\nfunction onCompositionEnd() {\n composing = false\n readToken()\n}\n\nfunction readToken() {\n const el = textareaRef.value\n if (!el) return\n // the textarea's own text: the model may not have caught up yet, e.g. right\n // after an input method puts its text down\n const next = findToken(el.value, el.selectionStart ?? el.value.length)\n const current = token.value\n // keyup and click re-read the caret after every key, arrows included: an\n // unchanged token must keep its identity or the menu resets its highlight.\n if (\n next &&\n current &&\n next.trigger === current.trigger &&\n next.start === current.start &&\n next.end === current.end &&\n next.query === current.query\n )\n return\n if (next?.start !== current?.start) dismissed.value = null\n token.value = next\n}\n\nconst filterOf = (trigger: '/' | '@') =>\n typeof props.filter === 'object' ? (props.filter[trigger] ?? true) : props.filter\n\nconst options = computed<ChatInputOption[]>(() => {\n const current = token.value\n if (!current || dismissed.value === current.start) return []\n const source = current.trigger === '/' ? props.commands : props.mentions\n const filter = filterOf(current.trigger)\n if (filter === false || (filter === true && !current.query)) return source\n if (typeof filter === 'function')\n return source.filter((option) => filter(option, current.query, current.trigger))\n // what the person sees: the label, a mention's value (it gets inserted), the description\n const query = current.query.toLowerCase()\n const texts = (option: ChatInputOption) => [\n option.label ?? option.value,\n ...(current.trigger === '@' && option.label ? [option.value] : []),\n option.description ?? '',\n ...(option.keywords ?? []),\n ]\n return source.filter((option) => texts(option).some((text) => text.toLowerCase().includes(query)))\n})\n\n// Without local matching, a list the parent puts in after a `search` is the\n// answer to the last query handed out. While what is typed now differs from\n// that query (its search still waits for `searchDelay`, or its answer is on\n// the way), the list shown answers an older one: it stays in view, but\n// Enter and Tab must not pick from it. A list put in before any search,\n// e.g. loaded once after mounting, is fixed and never stale. Nor is any\n// list when nobody listens to `search`: with no one to answer, a parent\n// that passes a new array each render is not answering a query.\nconst instance = getCurrentInstance()\nconst listening = () => !!instance?.vnode.props?.onSearch\ntype Query = { start: number; query: string }\nconst asked: { '/'?: Query; '@'?: Query } = {}\nconst answered = reactive<{ '/'?: Query; '@'?: Query }>({})\nwatch(\n () => props.commands,\n () => (answered['/'] = asked['/']),\n)\nwatch(\n () => props.mentions,\n () => (answered['@'] = asked['@']),\n)\nconst stale = computed(() => {\n const current = token.value\n if (!current || filterOf(current.trigger) !== false || !listening()) return false\n const last = answered[current.trigger]\n return !!last && (last.start !== current.start || last.query !== current.query)\n})\n\n// Each new query is handed out once typing pauses, to look options up\n// elsewhere; the same text at another `@` is a new query too.\nlet searchTimer: ReturnType<typeof setTimeout> | undefined\nwatch(\n () => (token.value ? `${token.value.start}${token.value.trigger}${token.value.query}` : null),\n (key) => {\n clearTimeout(searchTimer)\n const current = token.value\n // Escape closed this one: nothing to look up until another is typed\n if (key === null || !current || dismissed.value === current.start) return\n searchTimer = setTimeout(() => {\n if (listening()) asked[current.trigger] = { start: current.start, query: current.query }\n emit('search', current.query, current.trigger)\n }, props.searchDelay)\n },\n)\nonBeforeUnmount(() => clearTimeout(searchTimer))\nconst menuOpen = computed(() => !disabled.value && options.value.length > 0)\n\n// The menu is a popup like any other: rendered on top of the page, above\n// the frame (or below it when there is no room), stacked over what opened\n// before and closed by a press outside. The focus stays in the textarea.\nconst rootRef = useTemplateRef<HTMLElement>('root')\nconst menuRef = useTemplateRef<HTMLElement>('menu')\nconst teleportTarget = useTeleport(() => props.teleport)\nconst { style: floatingStyle, placement: menuPlacement } = useFloating(\n () => (menuOpen.value ? rootRef.value : null),\n menuRef,\n { open: menuOpen, placement: 'top-start', offset: 6 },\n)\nconst { next: nextZIndex } = useZIndex()\nconst menuZIndex = ref<number>()\nconst menuWidth = ref<number>()\n// rendered the first time it opens, so the server output stays the same\nconst menuRendered = ref(false)\nconst { theme, sync: syncTheme } = useThemeScope(() => rootRef.value)\nwatch(menuOpen, (value) => {\n if (!value) return\n menuRendered.value = true\n menuZIndex.value = nextZIndex()\n menuWidth.value = rootRef.value?.offsetWidth\n syncTheme()\n})\nconst menuStyle = computed(() => ({\n ...floatingStyle.value,\n zIndex: menuZIndex.value,\n '--dou-chat-input-menu-width': menuWidth.value ? `${menuWidth.value}px` : undefined,\n}))\nuseLayer({\n open: menuOpen,\n elements: () => [rootRef.value, menuRef.value],\n onOutside: () => (token.value = null),\n onEscape: () => (dismissed.value = token.value?.start ?? null),\n})\n// Only a different list moves the highlight back to the first usable option.\nconst firstEnabled = () =>\n Math.max(\n 0,\n options.value.findIndex((option) => !option.disabled),\n )\nwatch(\n () =>\n menuOpen.value\n ? `${token.value?.trigger}${options.value.map((option) => option.value).join('\\u0000')}`\n : '',\n () => (active.value = firstEnabled()),\n)\n\nfunction move(step: 1 | -1) {\n const list = options.value\n for (let offset = 1; offset <= list.length; offset++) {\n const index = (((active.value + step * offset) % list.length) + list.length) % list.length\n if (!list[index]!.disabled) {\n active.value = index\n return\n }\n }\n}\nconst optionId = (index: number) => `${id}-option-${index}`\nwatch(active, async (index) => {\n await nextTick()\n document.getElementById(optionId(index))?.scrollIntoView?.({ block: 'nearest' })\n})\n\n// A label or description cut short shows in full on hover, for a mouse.\nfunction onOptionEnter(event: MouseEvent, option: ChatInputOption, index: number) {\n if (!option.disabled) active.value = index\n const row = event.currentTarget as HTMLElement\n for (const part of row.querySelectorAll<HTMLElement>(\n `.${ns.e('option-label')}, .${ns.e('option-description')}`,\n )) {\n const cut = part.scrollWidth > part.clientWidth || part.scrollHeight > part.clientHeight\n if (cut) part.title = part.textContent!.trim()\n else part.removeAttribute('title')\n }\n}\n\nfunction pick(option: ChatInputOption) {\n const current = token.value\n if (!current || option.disabled) return\n const before = model.value.slice(0, current.start)\n const after = model.value.slice(current.end)\n const inserted = current.trigger === '/' ? '' : `@${option.value} `\n const nextValue = before + inserted + after.replace(/^\\s+/, '')\n const caret = before.length + inserted.length\n const focusedBefore = document.activeElement\n model.value = nextValue\n token.value = null\n // Queue before emitting so a parent `nextTick` in the listener runs after\n // this one, and skip resetting the caret if the listener changed the text.\n void nextTick(() => {\n const el = textareaRef.value\n if (!el) return\n const activeEl = document.activeElement\n const movedElsewhere =\n activeEl && activeEl !== focusedBefore && activeEl !== document.body && activeEl !== el\n if (!movedElsewhere && activeEl !== el) el.focus()\n if (model.value === nextValue && el.value === nextValue) {\n el.setSelectionRange(caret, caret)\n }\n })\n if (current.trigger === '/') emit('command', option)\n else emit('mention', option)\n}\n\nfunction onMenuKeydown(event: KeyboardEvent): boolean {\n if (!menuOpen.value) return false\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault()\n move(event.key === 'ArrowDown' ? 1 : -1)\n return true\n }\n if ((event.key === 'Enter' || event.key === 'Tab') && !isComposing(event)) {\n event.preventDefault()\n // the results for what is typed now are on their way: wait for them\n if (stale.value) return true\n pick(options.value[active.value]!)\n return true\n }\n if (event.key === 'Escape') {\n event.preventDefault()\n dismissed.value = token.value?.start ?? null\n return true\n }\n return false\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (onMenuKeydown(event)) return\n if (event.key !== 'Enter' || isComposing(event)) return\n const mod = event.ctrlKey || event.metaKey\n const sends = props.submitOn === 'enter' ? !event.shiftKey && !mod : mod\n if (!sends) return\n event.preventDefault()\n submit()\n}\n\nconst filesOf = (list: DataTransferItemList | undefined) =>\n [...(list ?? [])]\n .filter((item) => item.kind === 'file')\n .map((item) => item.getAsFile())\n .filter((file): file is File => !!file)\n\nfunction pastedFilesOf(data: DataTransfer | null | undefined): File[] {\n const fromItems = filesOf(data?.items)\n if (fromItems.length) return fromItems\n return [...(data?.files ?? [])]\n}\n\nfunction onPaste(event: ClipboardEvent) {\n if (disabled.value) return\n const files = pastedFilesOf(event.clipboardData)\n if (!files.length) return\n // keep the file's name from being pasted as text\n event.preventDefault()\n emit('attach', files)\n}\n\nconst dragging = ref(false)\nlet depth = 0\nconst carriesFiles = (event: DragEvent) => !!event.dataTransfer?.types.includes('Files')\n\nfunction onDragenter(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n depth++\n dragging.value = true\n}\nfunction onDragover(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n event.preventDefault()\n}\nfunction onDragleave() {\n depth = Math.max(0, depth - 1)\n if (!depth) dragging.value = false\n}\nfunction onDrop(event: DragEvent) {\n depth = 0\n dragging.value = false\n if (disabled.value) return\n const files = [...(event.dataTransfer?.files ?? [])]\n if (!files.length) return\n event.preventDefault()\n emit('attach', files)\n}\n\n// A press anywhere on the frame that is not a control puts the caret in the text.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === textareaRef.value || target.closest('button, a, input, select, [tabindex]')) return\n event.preventDefault()\n textareaRef.value?.focus()\n}\n\ndefineExpose<ChatInputExpose>({\n get textarea() {\n return textareaRef.value\n },\n focus: () => textareaRef.value?.focus(),\n blur: () => textareaRef.value?.blur(),\n submit,\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.is('disabled', disabled),\n ns.is('loading', loading),\n ns.is('dragging', dragging),\n attrs.class,\n ]\"\n :style=\"attrs.style as StyleValue\"\n @mousedown=\"onMousedown\"\n @dragenter=\"onDragenter\"\n @dragover=\"onDragover\"\n @dragleave=\"onDragleave\"\n @drop=\"onDrop\"\n >\n <div v-if=\"slots.header\" :class=\"ns.e('header')\"><slot name=\"header\" /></div>\n <textarea\n ref=\"textarea\"\n v-model=\"model\"\n :aria-label=\"placeholder ?? t('chat.placeholder')\"\n v-bind=\"textareaAttrs\"\n :class=\"ns.e('native')\"\n :rows=\"minRows\"\n :placeholder=\"placeholder ?? t('chat.placeholder')\"\n :disabled=\"disabled\"\n :aria-autocomplete=\"commands.length || mentions.length ? 'list' : undefined\"\n :aria-expanded=\"commands.length || mentions.length ? menuOpen : undefined\"\n :aria-controls=\"menuOpen ? `${id}-menu` : undefined\"\n :aria-activedescendant=\"menuOpen ? optionId(active) : undefined\"\n @keydown=\"onKeydown\"\n @keyup=\"onCaret\"\n @click=\"onCaret\"\n @input=\"onCaret\"\n @compositionstart=\"onCompositionStart\"\n @compositionend=\"onCompositionEnd\"\n @blur=\"token = null\"\n @paste=\"onPaste\"\n />\n <Teleport v-if=\"menuRendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition name=\"dou-floating\">\n <ul\n v-if=\"menuOpen\"\n :id=\"`${id}-menu`\"\n ref=\"menu\"\n :class=\"[ns.e('menu'), 'dou-floating', ns.is('stale', stale)]\"\n :aria-busy=\"stale || undefined\"\n :style=\"menuStyle\"\n :data-placement=\"menuPlacement\"\n :data-dou-theme=\"theme\"\n role=\"listbox\"\n @mousedown.prevent\n >\n <li\n v-for=\"(option, index) in options\"\n :id=\"optionId(index)\"\n :key=\"option.value\"\n role=\"option\"\n :class=\"[\n ns.e('option'),\n ns.is('default', !slots.option),\n ns.is('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"onOptionEnter($event, option, index)\"\n @click=\"pick(option)\"\n >\n <slot name=\"option\" :option=\"option\" :trigger=\"token!.trigger\">\n <component :is=\"option.icon\" v-if=\"option.icon\" :class=\"ns.e('option-icon')\" />\n <span :class=\"ns.e('option-label')\">\n {{ token?.trigger === '/' ? '/' : '@' }}{{ option.label ?? option.value }}\n </span>\n <span v-if=\"option.description\" :class=\"ns.e('option-description')\">\n {{ option.description }}\n </span>\n </slot>\n </li>\n </ul>\n </Transition>\n </Teleport>\n <div :class=\"ns.e('footer')\">\n <div :class=\"ns.e('actions')\"><slot name=\"actions\" /></div>\n <slot\n name=\"submit\"\n :submit=\"submit\"\n :stop=\"stop\"\n :loading=\"loading\"\n :disabled=\"stopping ? false : !submittable\"\n >\n <DouButton\n v-if=\"stopping\"\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :aria-label=\"t('chat.stop')\"\n @click=\"stop\"\n >\n <StopIcon />\n </DouButton>\n <DouButton\n v-else\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :disabled=\"!submittable\"\n :aria-label=\"t('chat.send')\"\n @click=\"submit\"\n >\n <ArrowUpIcon />\n </DouButton>\n </slot>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCA,MAAM,QAAQ;EAcd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EACd,MAAM,QAAQC,SAAmB,SAAA,YAAgB;EAEjD,MAAM,KAAK,aAAa,YAAY;EACpC,MAAM,KAAK,MAAM;EACjB,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EACrD,MAAM,aAAa,eAAgB,MAAM,SAAS,OAAO,OAAO,IAAK;EAGrE,MAAM,QAAQ,SAAS;EACvB,MAAM,gBAA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createElementBlock","_normalizeClass","_unref","_normalizeStyle","_renderSlot","_createCommentVNode","_withDirectives","_createElementVNode","_mergeProps","_vModelText","_createBlock","_Teleport","_createVNode","_Transition","_withCtx","_withModifiers","_Fragment","_renderList","_resolveDynamicComponent","_toDisplayString"],"sources":["../../../src/components/chat-input/chat-input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpIcon, StopIcon } from '@dou-ui/icons'\nimport {\n computed,\n getCurrentInstance,\n nextTick,\n onBeforeUnmount,\n onMounted,\n reactive,\n ref,\n useAttrs,\n useId,\n useTemplateRef,\n watch,\n} from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useTeleport } from '../../utils/teleport'\nimport { DouButton } from '../button'\nimport { useLocale, useZIndex } from '../config-provider/use-config'\nimport { useFormDisabled } from '../form/use-form-item'\nimport { findToken } from './chat-input'\nimport type {\n ChatInputEmits,\n ChatInputExpose,\n ChatInputOption,\n ChatInputProps,\n ChatInputSlots,\n ChatInputToken,\n} from './chat-input'\n\ndefineOptions({ name: 'DouChatInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ChatInputProps>(), {\n submitOn: 'enter',\n loading: false,\n size: 'md',\n disabled: false,\n minRows: 1,\n maxRows: 8,\n canSubmit: undefined,\n commands: () => [],\n mentions: () => [],\n filter: true,\n searchDelay: 300,\n teleport: undefined,\n})\nconst emit = defineEmits<ChatInputEmits>()\nconst slots = defineSlots<ChatInputSlots>()\nconst model = defineModel<string>({ default: '' })\n\nconst ns = useNamespace('chat-input')\nconst id = useId()\nconst { t } = useLocale()\nconst disabled = useFormDisabled(() => props.disabled)\nconst buttonSize = computed(() => (props.size === 'lg' ? 'md' : 'sm'))\n\n// `class` and `style` dress the frame, the rest goes to the textarea.\nconst attrs = useAttrs()\nconst textareaAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n return rest\n})\n\nconst textareaRef = useTemplateRef<HTMLTextAreaElement>('textarea')\n\nconst submittable = computed(\n () => !disabled.value && (props.canSubmit ?? model.value.trim().length > 0),\n)\n\nfunction resize() {\n const el = textareaRef.value\n if (!el) return\n const style = getComputedStyle(el)\n const lineHeight = Number.parseFloat(style.lineHeight) || 22\n const padding = Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom)\n const min = props.minRows * lineHeight + (padding || 0)\n const max = props.maxRows * lineHeight + (padding || 0)\n el.style.height = 'auto'\n const content = el.scrollHeight\n el.style.height = `${Math.min(Math.max(content, min), max)}px`\n el.style.overflowY = content > max ? 'auto' : 'hidden'\n}\nwatch([model, () => props.minRows, () => props.maxRows], () => nextTick(resize))\nonMounted(resize)\n\n// While a reply is generated the button stops it, unless something new\n// has been typed: then it sends, and the app may queue the message.\nconst stopping = computed(() => props.loading && !submittable.value)\n\nfunction submit() {\n if (!submittable.value) return\n emit('submit', model.value)\n}\n\nfunction stop() {\n if (props.loading) emit('stop')\n}\n\n// --- `/` command and `@` mention menu ---\nconst token = ref<ChatInputToken | null>(null)\nconst dismissed = ref<number | null>(null)\nconst active = ref(0)\n\n// While an input method composes, the text holds what is being spelled\n// (pinyin, say), not what will be typed: wait for it to finish.\nlet composing = false\nfunction onCaret(event?: Event) {\n if (composing || (event instanceof KeyboardEvent && isComposing(event))) return\n if ((event as InputEvent | undefined)?.isComposing) return\n readToken()\n}\nfunction onCompositionStart() {\n composing = true\n}\nfunction onCompositionEnd() {\n composing = false\n readToken()\n}\n\nfunction readToken() {\n const el = textareaRef.value\n if (!el) return\n // the textarea's own text: the model may not have caught up yet, e.g. right\n // after an input method puts its text down\n const next = findToken(el.value, el.selectionStart ?? el.value.length)\n const current = token.value\n // keyup and click re-read the caret after every key, arrows included: an\n // unchanged token must keep its identity or the menu resets its highlight.\n if (\n next &&\n current &&\n next.trigger === current.trigger &&\n next.start === current.start &&\n next.end === current.end &&\n next.query === current.query\n )\n return\n if (next?.start !== current?.start) dismissed.value = null\n token.value = next\n}\n\nconst filterOf = (trigger: '/' | '@') =>\n typeof props.filter === 'object' ? (props.filter[trigger] ?? true) : props.filter\n\nconst options = computed<ChatInputOption[]>(() => {\n const current = token.value\n if (!current || dismissed.value === current.start) return []\n const source = current.trigger === '/' ? props.commands : props.mentions\n const filter = filterOf(current.trigger)\n if (filter === false || (filter === true && !current.query)) return source\n if (typeof filter === 'function')\n return source.filter((option) => filter(option, current.query, current.trigger))\n // what the person sees: the label, a mention's value (it gets inserted), the description\n const query = current.query.toLowerCase()\n const texts = (option: ChatInputOption) => [\n option.label ?? option.value,\n ...(current.trigger === '@' && option.label ? [option.value] : []),\n option.description ?? '',\n ...(option.keywords ?? []),\n ]\n return source.filter((option) => texts(option).some((text) => text.toLowerCase().includes(query)))\n})\n\n// Without local matching, a list the parent puts in after a `search` is the\n// answer to the last query handed out. While what is typed now differs from\n// that query (its search still waits for `searchDelay`, or its answer is on\n// the way), the list shown answers an older one: it stays in view, but\n// Enter and Tab must not pick from it. A list put in before any search,\n// e.g. loaded once after mounting, is fixed and never stale. Nor is any\n// list when nobody listens to `search`: with no one to answer, a parent\n// that passes a new array each render is not answering a query.\nconst instance = getCurrentInstance()\nconst listening = () => !!instance?.vnode.props?.onSearch\ntype Query = { start: number; query: string }\nconst asked: { '/'?: Query; '@'?: Query } = {}\nconst answered = reactive<{ '/'?: Query; '@'?: Query }>({})\nwatch(\n () => props.commands,\n () => (answered['/'] = asked['/']),\n)\nwatch(\n () => props.mentions,\n () => (answered['@'] = asked['@']),\n)\nconst stale = computed(() => {\n const current = token.value\n if (!current || filterOf(current.trigger) !== false || !listening()) return false\n const last = answered[current.trigger]\n return !!last && (last.start !== current.start || last.query !== current.query)\n})\n\n// Each new query is handed out once typing pauses, to look options up\n// elsewhere; the same text at another `@` is a new query too.\nlet searchTimer: ReturnType<typeof setTimeout> | undefined\nwatch(\n () => (token.value ? `${token.value.start}${token.value.trigger}${token.value.query}` : null),\n (key) => {\n clearTimeout(searchTimer)\n const current = token.value\n // Escape closed this one: nothing to look up until another is typed\n if (key === null || !current || dismissed.value === current.start) return\n searchTimer = setTimeout(() => {\n if (listening()) asked[current.trigger] = { start: current.start, query: current.query }\n emit('search', current.query, current.trigger)\n }, props.searchDelay)\n },\n)\nonBeforeUnmount(() => clearTimeout(searchTimer))\nconst menuOpen = computed(() => !disabled.value && options.value.length > 0)\n\n// The menu is a popup like any other: rendered on top of the page, above\n// the frame (or below it when there is no room), stacked over what opened\n// before and closed by a press outside. The focus stays in the textarea.\nconst rootRef = useTemplateRef<HTMLElement>('root')\nconst menuRef = useTemplateRef<HTMLElement>('menu')\nconst teleportTarget = useTeleport(() => props.teleport)\nconst { style: floatingStyle, placement: menuPlacement } = useFloating(\n () => (menuOpen.value ? rootRef.value : null),\n menuRef,\n { open: menuOpen, placement: 'top-start', offset: 6 },\n)\nconst { next: nextZIndex } = useZIndex()\nconst menuZIndex = ref<number>()\nconst menuWidth = ref<number>()\nconst menuMaxWidth = ref<string>()\n// rendered the first time it opens, so the server output stays the same\nconst menuRendered = ref(false)\nconst { theme, sync: syncTheme } = useThemeScope(() => rootRef.value)\n\nfunction readMenuMaxWidth() {\n if (typeof window === 'undefined' || teleportTarget.value.disabled) return undefined\n const el = rootRef.value\n if (!el) return undefined\n const value = getComputedStyle(el).getPropertyValue('--dou-chat-input-menu-max-width').trim()\n if (!value) return undefined\n const target =\n typeof teleportTarget.value.to === 'string'\n ? document.querySelector<HTMLElement>(teleportTarget.value.to)\n : teleportTarget.value.to\n const inherited = target\n ? getComputedStyle(target).getPropertyValue('--dou-chat-input-menu-max-width').trim()\n : ''\n // Forward only when the input or an ancestor overrides the teleport target's value,\n // so a rule directly on `.dou-chat-input__menu` still wins over `:root` / `body`.\n return value !== inherited ? value : undefined\n}\n\nwatch(menuOpen, (value) => {\n if (!value) return\n menuRendered.value = true\n menuZIndex.value = nextZIndex()\n menuWidth.value = rootRef.value?.offsetWidth\n menuMaxWidth.value = readMenuMaxWidth()\n syncTheme()\n})\nconst menuStyle = computed(() => ({\n ...floatingStyle.value,\n zIndex: menuZIndex.value,\n '--dou-chat-input-menu-width': menuWidth.value ? `${menuWidth.value}px` : undefined,\n '--dou-chat-input-menu-max-width': menuMaxWidth.value,\n}))\nuseLayer({\n open: menuOpen,\n elements: () => [rootRef.value, menuRef.value],\n onOutside: () => (token.value = null),\n onEscape: () => (dismissed.value = token.value?.start ?? null),\n})\n// Only a different list moves the highlight back to the first usable option.\nconst firstEnabled = () =>\n Math.max(\n 0,\n options.value.findIndex((option) => !option.disabled),\n )\nwatch(\n () =>\n menuOpen.value\n ? `${token.value?.trigger}${options.value.map((option) => option.value).join('\\u0000')}`\n : '',\n () => (active.value = firstEnabled()),\n)\n\nfunction move(step: 1 | -1) {\n const list = options.value\n for (let offset = 1; offset <= list.length; offset++) {\n const index = (((active.value + step * offset) % list.length) + list.length) % list.length\n if (!list[index]!.disabled) {\n active.value = index\n return\n }\n }\n}\nconst optionId = (index: number) => `${id}-option-${index}`\nwatch(active, async (index) => {\n await nextTick()\n document.getElementById(optionId(index))?.scrollIntoView?.({ block: 'nearest' })\n})\n\n// A label or description cut short shows in full on hover, for a mouse.\nfunction onOptionEnter(event: MouseEvent, option: ChatInputOption, index: number) {\n if (!option.disabled) active.value = index\n const row = event.currentTarget as HTMLElement\n for (const part of row.querySelectorAll<HTMLElement>(\n `.${ns.e('option-label')}, .${ns.e('option-description')}`,\n )) {\n const cut = part.scrollWidth > part.clientWidth || part.scrollHeight > part.clientHeight\n if (cut) part.title = part.textContent!.trim()\n else part.removeAttribute('title')\n }\n}\n\nfunction pick(option: ChatInputOption) {\n const current = token.value\n if (!current || option.disabled) return\n const before = model.value.slice(0, current.start)\n const after = model.value.slice(current.end)\n const inserted = current.trigger === '/' ? '' : `@${option.value} `\n const nextValue = before + inserted + after.replace(/^\\s+/, '')\n const caret = before.length + inserted.length\n const focusedBefore = document.activeElement\n model.value = nextValue\n token.value = null\n // Queue before emitting so a parent `nextTick` in the listener runs after\n // this one, and skip resetting the caret if the listener changed the text.\n void nextTick(() => {\n const el = textareaRef.value\n if (!el) return\n const activeEl = document.activeElement\n const movedElsewhere =\n activeEl && activeEl !== focusedBefore && activeEl !== document.body && activeEl !== el\n if (!movedElsewhere && activeEl !== el) el.focus()\n if (model.value === nextValue && el.value === nextValue) {\n el.setSelectionRange(caret, caret)\n }\n })\n if (current.trigger === '/') emit('command', option)\n else emit('mention', option)\n}\n\nfunction onMenuKeydown(event: KeyboardEvent): boolean {\n if (!menuOpen.value) return false\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault()\n move(event.key === 'ArrowDown' ? 1 : -1)\n return true\n }\n if ((event.key === 'Enter' || event.key === 'Tab') && !isComposing(event)) {\n event.preventDefault()\n // the results for what is typed now are on their way: wait for them\n if (stale.value) return true\n pick(options.value[active.value]!)\n return true\n }\n if (event.key === 'Escape') {\n event.preventDefault()\n dismissed.value = token.value?.start ?? null\n return true\n }\n return false\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (onMenuKeydown(event)) return\n if (event.key !== 'Enter' || isComposing(event)) return\n const mod = event.ctrlKey || event.metaKey\n const sends = props.submitOn === 'enter' ? !event.shiftKey && !mod : mod\n if (!sends) return\n event.preventDefault()\n submit()\n}\n\nconst filesOf = (list: DataTransferItemList | undefined) =>\n [...(list ?? [])]\n .filter((item) => item.kind === 'file')\n .map((item) => item.getAsFile())\n .filter((file): file is File => !!file)\n\nfunction pastedFilesOf(data: DataTransfer | null | undefined): File[] {\n const fromItems = filesOf(data?.items)\n if (fromItems.length) return fromItems\n return [...(data?.files ?? [])]\n}\n\nfunction onPaste(event: ClipboardEvent) {\n if (disabled.value) return\n const files = pastedFilesOf(event.clipboardData)\n if (!files.length) return\n // keep the file's name from being pasted as text\n event.preventDefault()\n emit('attach', files)\n}\n\nconst dragging = ref(false)\nlet depth = 0\nconst carriesFiles = (event: DragEvent) => !!event.dataTransfer?.types.includes('Files')\n\nfunction onDragenter(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n depth++\n dragging.value = true\n}\nfunction onDragover(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n event.preventDefault()\n}\nfunction onDragleave() {\n depth = Math.max(0, depth - 1)\n if (!depth) dragging.value = false\n}\nfunction onDrop(event: DragEvent) {\n depth = 0\n dragging.value = false\n if (disabled.value) return\n const files = [...(event.dataTransfer?.files ?? [])]\n if (!files.length) return\n event.preventDefault()\n emit('attach', files)\n}\n\n// A press anywhere on the frame that is not a control puts the caret in the text.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === textareaRef.value || target.closest('button, a, input, select, [tabindex]')) return\n event.preventDefault()\n textareaRef.value?.focus()\n}\n\ndefineExpose<ChatInputExpose>({\n get textarea() {\n return textareaRef.value\n },\n focus: () => textareaRef.value?.focus(),\n blur: () => textareaRef.value?.blur(),\n submit,\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.is('disabled', disabled),\n ns.is('loading', loading),\n ns.is('dragging', dragging),\n attrs.class,\n ]\"\n :style=\"attrs.style as StyleValue\"\n @mousedown=\"onMousedown\"\n @dragenter=\"onDragenter\"\n @dragover=\"onDragover\"\n @dragleave=\"onDragleave\"\n @drop=\"onDrop\"\n >\n <div v-if=\"slots.header\" :class=\"ns.e('header')\"><slot name=\"header\" /></div>\n <textarea\n ref=\"textarea\"\n v-model=\"model\"\n :aria-label=\"placeholder ?? t('chat.placeholder')\"\n v-bind=\"textareaAttrs\"\n :class=\"ns.e('native')\"\n :rows=\"minRows\"\n :placeholder=\"placeholder ?? t('chat.placeholder')\"\n :disabled=\"disabled\"\n :aria-autocomplete=\"commands.length || mentions.length ? 'list' : undefined\"\n :aria-expanded=\"commands.length || mentions.length ? menuOpen : undefined\"\n :aria-controls=\"menuOpen ? `${id}-menu` : undefined\"\n :aria-activedescendant=\"menuOpen ? optionId(active) : undefined\"\n @keydown=\"onKeydown\"\n @keyup=\"onCaret\"\n @click=\"onCaret\"\n @input=\"onCaret\"\n @compositionstart=\"onCompositionStart\"\n @compositionend=\"onCompositionEnd\"\n @blur=\"token = null\"\n @paste=\"onPaste\"\n />\n <Teleport v-if=\"menuRendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition name=\"dou-floating\">\n <ul\n v-if=\"menuOpen\"\n :id=\"`${id}-menu`\"\n ref=\"menu\"\n :class=\"[ns.e('menu'), 'dou-floating', ns.is('stale', stale)]\"\n :aria-busy=\"stale || undefined\"\n :style=\"menuStyle\"\n :data-placement=\"menuPlacement\"\n :data-trigger=\"token?.trigger\"\n :data-dou-theme=\"theme\"\n role=\"listbox\"\n @mousedown.prevent\n >\n <li\n v-for=\"(option, index) in options\"\n :id=\"optionId(index)\"\n :key=\"option.value\"\n role=\"option\"\n :class=\"[\n ns.e('option'),\n ns.is('default', !slots.option),\n ns.is('stacked', !slots.option && token?.trigger === '/' && !!option.description),\n ns.is('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"onOptionEnter($event, option, index)\"\n @click=\"pick(option)\"\n >\n <slot name=\"option\" :option=\"option\" :trigger=\"token!.trigger\">\n <component :is=\"option.icon\" v-if=\"option.icon\" :class=\"ns.e('option-icon')\" />\n <span\n v-if=\"token?.trigger === '/' && option.description\"\n :class=\"ns.e('option-content')\"\n >\n <span :class=\"ns.e('option-label')\"> /{{ option.label ?? option.value }} </span>\n <span :class=\"ns.e('option-description')\">\n {{ option.description }}\n </span>\n </span>\n <template v-else>\n <span :class=\"ns.e('option-label')\">\n {{ token?.trigger === '/' ? '/' : '@' }}{{ option.label ?? option.value }}\n </span>\n <span v-if=\"option.description\" :class=\"ns.e('option-description')\">\n {{ option.description }}\n </span>\n </template>\n </slot>\n </li>\n </ul>\n </Transition>\n </Teleport>\n <div :class=\"ns.e('footer')\">\n <div :class=\"ns.e('actions')\"><slot name=\"actions\" /></div>\n <slot\n name=\"submit\"\n :submit=\"submit\"\n :stop=\"stop\"\n :loading=\"loading\"\n :disabled=\"stopping ? false : !submittable\"\n >\n <DouButton\n v-if=\"stopping\"\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :aria-label=\"t('chat.stop')\"\n @click=\"stop\"\n >\n <StopIcon />\n </DouButton>\n <DouButton\n v-else\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :disabled=\"!submittable\"\n :aria-label=\"t('chat.send')\"\n @click=\"submit\"\n >\n <ArrowUpIcon />\n </DouButton>\n </slot>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCA,MAAM,QAAQ;EAcd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EACd,MAAM,QAAQC,SAAmB,SAAA,YAAgB;EAEjD,MAAM,KAAK,aAAa,YAAY;EACpC,MAAM,KAAK,MAAM;EACjB,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EACrD,MAAM,aAAa,eAAgB,MAAM,SAAS,OAAO,OAAO,IAAK;EAGrE,MAAM,QAAQ,SAAS;EACvB,MAAM,gBAAgB,eAAe;GACnC,MAAM,EAAE,OAAO,QAAQ,OAAO,QAAQ,GAAG,SAAS;GAClD,OAAO;EACT,CAAC;EAED,MAAM,cAAc,eAAoC,UAAU;EAElE,MAAM,cAAc,eACZ,CAAC,SAAS,UAAU,MAAM,aAAa,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,EAC3E;EAEA,SAAS,SAAS;GAChB,MAAM,KAAK,YAAY;GACvB,IAAI,CAAC,IAAI;GACT,MAAM,QAAQ,iBAAiB,EAAE;GACjC,MAAM,aAAa,OAAO,WA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CAAA,E,IACfK,mBAA2D,OAAA,EAArD,OAAKN,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA,E,IAAaE,WAAuB,KAAA,QAAA,SAAA,C,OACrDA,WA0BO,KAAA,QAAA,UAAA;KAxBI;KACF;KACN,SAAS,QAAA;KACT,UAAU,SAAA,QAAQ,QAAA,CAAY,YAAA;IALjC,SA0BO,CAlBG,SAAA,SADRL,UAAA,GAAAW,YAQYR,MAAA,SAAA,GAAA;;KANT,OAAKD,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;KACX,MAAM,WAAA;KACN,cAAYA,MAAA,CAAA,CAAC,CAAA,WAAA;KACb,SAAO;;KAER,SAAAY,cAAY,CAAZF,YAAYV,MAAA,QAAA,CAAA,C;;;;;;I,OAEdH,UAAA,GAAAW,YASYR,MAAA,SAAA,GAAA;;KAPT,OAAKD,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;KACX,MAAM,WAAA;KACN,UAAQ,CAAG,YAAA;KACX,cAAYA,MAAA,CAAA,CAAC,CAAA,WAAA;KACb,SAAO;;KAER,SAAAY,cAAe,CAAfF,YAAeV,MAAA,WAAA,CAAA,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-input2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-input/chat-input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpIcon, StopIcon } from '@dou-ui/icons'\nimport {\n computed,\n getCurrentInstance,\n nextTick,\n onBeforeUnmount,\n onMounted,\n reactive,\n ref,\n useAttrs,\n useId,\n useTemplateRef,\n watch,\n} from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useTeleport } from '../../utils/teleport'\nimport { DouButton } from '../button'\nimport { useLocale, useZIndex } from '../config-provider/use-config'\nimport { useFormDisabled } from '../form/use-form-item'\nimport { findToken } from './chat-input'\nimport type {\n ChatInputEmits,\n ChatInputExpose,\n ChatInputOption,\n ChatInputProps,\n ChatInputSlots,\n ChatInputToken,\n} from './chat-input'\n\ndefineOptions({ name: 'DouChatInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ChatInputProps>(), {\n submitOn: 'enter',\n loading: false,\n size: 'md',\n disabled: false,\n minRows: 1,\n maxRows: 8,\n canSubmit: undefined,\n commands: () => [],\n mentions: () => [],\n filter: true,\n searchDelay: 300,\n teleport: undefined,\n})\nconst emit = defineEmits<ChatInputEmits>()\nconst slots = defineSlots<ChatInputSlots>()\nconst model = defineModel<string>({ default: '' })\n\nconst ns = useNamespace('chat-input')\nconst id = useId()\nconst { t } = useLocale()\nconst disabled = useFormDisabled(() => props.disabled)\nconst buttonSize = computed(() => (props.size === 'lg' ? 'md' : 'sm'))\n\n// `class` and `style` dress the frame, the rest goes to the textarea.\nconst attrs = useAttrs()\nconst textareaAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n return rest\n})\n\nconst textareaRef = useTemplateRef<HTMLTextAreaElement>('textarea')\n\nconst submittable = computed(\n () => !disabled.value && (props.canSubmit ?? model.value.trim().length > 0),\n)\n\nfunction resize() {\n const el = textareaRef.value\n if (!el) return\n const style = getComputedStyle(el)\n const lineHeight = Number.parseFloat(style.lineHeight) || 22\n const padding = Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom)\n const min = props.minRows * lineHeight + (padding || 0)\n const max = props.maxRows * lineHeight + (padding || 0)\n el.style.height = 'auto'\n const content = el.scrollHeight\n el.style.height = `${Math.min(Math.max(content, min), max)}px`\n el.style.overflowY = content > max ? 'auto' : 'hidden'\n}\nwatch([model, () => props.minRows, () => props.maxRows], () => nextTick(resize))\nonMounted(resize)\n\n// While a reply is generated the button stops it, unless something new\n// has been typed: then it sends, and the app may queue the message.\nconst stopping = computed(() => props.loading && !submittable.value)\n\nfunction submit() {\n if (!submittable.value) return\n emit('submit', model.value)\n}\n\nfunction stop() {\n if (props.loading) emit('stop')\n}\n\n// --- `/` command and `@` mention menu ---\nconst token = ref<ChatInputToken | null>(null)\nconst dismissed = ref<number | null>(null)\nconst active = ref(0)\n\n// While an input method composes, the text holds what is being spelled\n// (pinyin, say), not what will be typed: wait for it to finish.\nlet composing = false\nfunction onCaret(event?: Event) {\n if (composing || (event instanceof KeyboardEvent && isComposing(event))) return\n if ((event as InputEvent | undefined)?.isComposing) return\n readToken()\n}\nfunction onCompositionStart() {\n composing = true\n}\nfunction onCompositionEnd() {\n composing = false\n readToken()\n}\n\nfunction readToken() {\n const el = textareaRef.value\n if (!el) return\n // the textarea's own text: the model may not have caught up yet, e.g. right\n // after an input method puts its text down\n const next = findToken(el.value, el.selectionStart ?? el.value.length)\n const current = token.value\n // keyup and click re-read the caret after every key, arrows included: an\n // unchanged token must keep its identity or the menu resets its highlight.\n if (\n next &&\n current &&\n next.trigger === current.trigger &&\n next.start === current.start &&\n next.end === current.end &&\n next.query === current.query\n )\n return\n if (next?.start !== current?.start) dismissed.value = null\n token.value = next\n}\n\nconst filterOf = (trigger: '/' | '@') =>\n typeof props.filter === 'object' ? (props.filter[trigger] ?? true) : props.filter\n\nconst options = computed<ChatInputOption[]>(() => {\n const current = token.value\n if (!current || dismissed.value === current.start) return []\n const source = current.trigger === '/' ? props.commands : props.mentions\n const filter = filterOf(current.trigger)\n if (filter === false || (filter === true && !current.query)) return source\n if (typeof filter === 'function')\n return source.filter((option) => filter(option, current.query, current.trigger))\n // what the person sees: the label, a mention's value (it gets inserted), the description\n const query = current.query.toLowerCase()\n const texts = (option: ChatInputOption) => [\n option.label ?? option.value,\n ...(current.trigger === '@' && option.label ? [option.value] : []),\n option.description ?? '',\n ...(option.keywords ?? []),\n ]\n return source.filter((option) => texts(option).some((text) => text.toLowerCase().includes(query)))\n})\n\n// Without local matching, a list the parent puts in after a `search` is the\n// answer to the last query handed out. While what is typed now differs from\n// that query (its search still waits for `searchDelay`, or its answer is on\n// the way), the list shown answers an older one: it stays in view, but\n// Enter and Tab must not pick from it. A list put in before any search,\n// e.g. loaded once after mounting, is fixed and never stale. Nor is any\n// list when nobody listens to `search`: with no one to answer, a parent\n// that passes a new array each render is not answering a query.\nconst instance = getCurrentInstance()\nconst listening = () => !!instance?.vnode.props?.onSearch\ntype Query = { start: number; query: string }\nconst asked: { '/'?: Query; '@'?: Query } = {}\nconst answered = reactive<{ '/'?: Query; '@'?: Query }>({})\nwatch(\n () => props.commands,\n () => (answered['/'] = asked['/']),\n)\nwatch(\n () => props.mentions,\n () => (answered['@'] = asked['@']),\n)\nconst stale = computed(() => {\n const current = token.value\n if (!current || filterOf(current.trigger) !== false || !listening()) return false\n const last = answered[current.trigger]\n return !!last && (last.start !== current.start || last.query !== current.query)\n})\n\n// Each new query is handed out once typing pauses, to look options up\n// elsewhere; the same text at another `@` is a new query too.\nlet searchTimer: ReturnType<typeof setTimeout> | undefined\nwatch(\n () => (token.value ? `${token.value.start}${token.value.trigger}${token.value.query}` : null),\n (key) => {\n clearTimeout(searchTimer)\n const current = token.value\n // Escape closed this one: nothing to look up until another is typed\n if (key === null || !current || dismissed.value === current.start) return\n searchTimer = setTimeout(() => {\n if (listening()) asked[current.trigger] = { start: current.start, query: current.query }\n emit('search', current.query, current.trigger)\n }, props.searchDelay)\n },\n)\nonBeforeUnmount(() => clearTimeout(searchTimer))\nconst menuOpen = computed(() => !disabled.value && options.value.length > 0)\n\n// The menu is a popup like any other: rendered on top of the page, above\n// the frame (or below it when there is no room), stacked over what opened\n// before and closed by a press outside. The focus stays in the textarea.\nconst rootRef = useTemplateRef<HTMLElement>('root')\nconst menuRef = useTemplateRef<HTMLElement>('menu')\nconst teleportTarget = useTeleport(() => props.teleport)\nconst { style: floatingStyle, placement: menuPlacement } = useFloating(\n () => (menuOpen.value ? rootRef.value : null),\n menuRef,\n { open: menuOpen, placement: 'top-start', offset: 6 },\n)\nconst { next: nextZIndex } = useZIndex()\nconst menuZIndex = ref<number>()\nconst menuWidth = ref<number>()\n// rendered the first time it opens, so the server output stays the same\nconst menuRendered = ref(false)\nconst { theme, sync: syncTheme } = useThemeScope(() => rootRef.value)\nwatch(menuOpen, (value) => {\n if (!value) return\n menuRendered.value = true\n menuZIndex.value = nextZIndex()\n menuWidth.value = rootRef.value?.offsetWidth\n syncTheme()\n})\nconst menuStyle = computed(() => ({\n ...floatingStyle.value,\n zIndex: menuZIndex.value,\n '--dou-chat-input-menu-width': menuWidth.value ? `${menuWidth.value}px` : undefined,\n}))\nuseLayer({\n open: menuOpen,\n elements: () => [rootRef.value, menuRef.value],\n onOutside: () => (token.value = null),\n onEscape: () => (dismissed.value = token.value?.start ?? null),\n})\n// Only a different list moves the highlight back to the first usable option.\nconst firstEnabled = () =>\n Math.max(\n 0,\n options.value.findIndex((option) => !option.disabled),\n )\nwatch(\n () =>\n menuOpen.value\n ? `${token.value?.trigger}${options.value.map((option) => option.value).join('\\u0000')}`\n : '',\n () => (active.value = firstEnabled()),\n)\n\nfunction move(step: 1 | -1) {\n const list = options.value\n for (let offset = 1; offset <= list.length; offset++) {\n const index = (((active.value + step * offset) % list.length) + list.length) % list.length\n if (!list[index]!.disabled) {\n active.value = index\n return\n }\n }\n}\nconst optionId = (index: number) => `${id}-option-${index}`\nwatch(active, async (index) => {\n await nextTick()\n document.getElementById(optionId(index))?.scrollIntoView?.({ block: 'nearest' })\n})\n\n// A label or description cut short shows in full on hover, for a mouse.\nfunction onOptionEnter(event: MouseEvent, option: ChatInputOption, index: number) {\n if (!option.disabled) active.value = index\n const row = event.currentTarget as HTMLElement\n for (const part of row.querySelectorAll<HTMLElement>(\n `.${ns.e('option-label')}, .${ns.e('option-description')}`,\n )) {\n const cut = part.scrollWidth > part.clientWidth || part.scrollHeight > part.clientHeight\n if (cut) part.title = part.textContent!.trim()\n else part.removeAttribute('title')\n }\n}\n\nfunction pick(option: ChatInputOption) {\n const current = token.value\n if (!current || option.disabled) return\n const before = model.value.slice(0, current.start)\n const after = model.value.slice(current.end)\n const inserted = current.trigger === '/' ? '' : `@${option.value} `\n const nextValue = before + inserted + after.replace(/^\\s+/, '')\n const caret = before.length + inserted.length\n const focusedBefore = document.activeElement\n model.value = nextValue\n token.value = null\n // Queue before emitting so a parent `nextTick` in the listener runs after\n // this one, and skip resetting the caret if the listener changed the text.\n void nextTick(() => {\n const el = textareaRef.value\n if (!el) return\n const activeEl = document.activeElement\n const movedElsewhere =\n activeEl && activeEl !== focusedBefore && activeEl !== document.body && activeEl !== el\n if (!movedElsewhere && activeEl !== el) el.focus()\n if (model.value === nextValue && el.value === nextValue) {\n el.setSelectionRange(caret, caret)\n }\n })\n if (current.trigger === '/') emit('command', option)\n else emit('mention', option)\n}\n\nfunction onMenuKeydown(event: KeyboardEvent): boolean {\n if (!menuOpen.value) return false\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault()\n move(event.key === 'ArrowDown' ? 1 : -1)\n return true\n }\n if ((event.key === 'Enter' || event.key === 'Tab') && !isComposing(event)) {\n event.preventDefault()\n // the results for what is typed now are on their way: wait for them\n if (stale.value) return true\n pick(options.value[active.value]!)\n return true\n }\n if (event.key === 'Escape') {\n event.preventDefault()\n dismissed.value = token.value?.start ?? null\n return true\n }\n return false\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (onMenuKeydown(event)) return\n if (event.key !== 'Enter' || isComposing(event)) return\n const mod = event.ctrlKey || event.metaKey\n const sends = props.submitOn === 'enter' ? !event.shiftKey && !mod : mod\n if (!sends) return\n event.preventDefault()\n submit()\n}\n\nconst filesOf = (list: DataTransferItemList | undefined) =>\n [...(list ?? [])]\n .filter((item) => item.kind === 'file')\n .map((item) => item.getAsFile())\n .filter((file): file is File => !!file)\n\nfunction pastedFilesOf(data: DataTransfer | null | undefined): File[] {\n const fromItems = filesOf(data?.items)\n if (fromItems.length) return fromItems\n return [...(data?.files ?? [])]\n}\n\nfunction onPaste(event: ClipboardEvent) {\n if (disabled.value) return\n const files = pastedFilesOf(event.clipboardData)\n if (!files.length) return\n // keep the file's name from being pasted as text\n event.preventDefault()\n emit('attach', files)\n}\n\nconst dragging = ref(false)\nlet depth = 0\nconst carriesFiles = (event: DragEvent) => !!event.dataTransfer?.types.includes('Files')\n\nfunction onDragenter(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n depth++\n dragging.value = true\n}\nfunction onDragover(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n event.preventDefault()\n}\nfunction onDragleave() {\n depth = Math.max(0, depth - 1)\n if (!depth) dragging.value = false\n}\nfunction onDrop(event: DragEvent) {\n depth = 0\n dragging.value = false\n if (disabled.value) return\n const files = [...(event.dataTransfer?.files ?? [])]\n if (!files.length) return\n event.preventDefault()\n emit('attach', files)\n}\n\n// A press anywhere on the frame that is not a control puts the caret in the text.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === textareaRef.value || target.closest('button, a, input, select, [tabindex]')) return\n event.preventDefault()\n textareaRef.value?.focus()\n}\n\ndefineExpose<ChatInputExpose>({\n get textarea() {\n return textareaRef.value\n },\n focus: () => textareaRef.value?.focus(),\n blur: () => textareaRef.value?.blur(),\n submit,\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.is('disabled', disabled),\n ns.is('loading', loading),\n ns.is('dragging', dragging),\n attrs.class,\n ]\"\n :style=\"attrs.style as StyleValue\"\n @mousedown=\"onMousedown\"\n @dragenter=\"onDragenter\"\n @dragover=\"onDragover\"\n @dragleave=\"onDragleave\"\n @drop=\"onDrop\"\n >\n <div v-if=\"slots.header\" :class=\"ns.e('header')\"><slot name=\"header\" /></div>\n <textarea\n ref=\"textarea\"\n v-model=\"model\"\n :aria-label=\"placeholder ?? t('chat.placeholder')\"\n v-bind=\"textareaAttrs\"\n :class=\"ns.e('native')\"\n :rows=\"minRows\"\n :placeholder=\"placeholder ?? t('chat.placeholder')\"\n :disabled=\"disabled\"\n :aria-autocomplete=\"commands.length || mentions.length ? 'list' : undefined\"\n :aria-expanded=\"commands.length || mentions.length ? menuOpen : undefined\"\n :aria-controls=\"menuOpen ? `${id}-menu` : undefined\"\n :aria-activedescendant=\"menuOpen ? optionId(active) : undefined\"\n @keydown=\"onKeydown\"\n @keyup=\"onCaret\"\n @click=\"onCaret\"\n @input=\"onCaret\"\n @compositionstart=\"onCompositionStart\"\n @compositionend=\"onCompositionEnd\"\n @blur=\"token = null\"\n @paste=\"onPaste\"\n />\n <Teleport v-if=\"menuRendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition name=\"dou-floating\">\n <ul\n v-if=\"menuOpen\"\n :id=\"`${id}-menu`\"\n ref=\"menu\"\n :class=\"[ns.e('menu'), 'dou-floating', ns.is('stale', stale)]\"\n :aria-busy=\"stale || undefined\"\n :style=\"menuStyle\"\n :data-placement=\"menuPlacement\"\n :data-dou-theme=\"theme\"\n role=\"listbox\"\n @mousedown.prevent\n >\n <li\n v-for=\"(option, index) in options\"\n :id=\"optionId(index)\"\n :key=\"option.value\"\n role=\"option\"\n :class=\"[\n ns.e('option'),\n ns.is('default', !slots.option),\n ns.is('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"onOptionEnter($event, option, index)\"\n @click=\"pick(option)\"\n >\n <slot name=\"option\" :option=\"option\" :trigger=\"token!.trigger\">\n <component :is=\"option.icon\" v-if=\"option.icon\" :class=\"ns.e('option-icon')\" />\n <span :class=\"ns.e('option-label')\">\n {{ token?.trigger === '/' ? '/' : '@' }}{{ option.label ?? option.value }}\n </span>\n <span v-if=\"option.description\" :class=\"ns.e('option-description')\">\n {{ option.description }}\n </span>\n </slot>\n </li>\n </ul>\n </Transition>\n </Teleport>\n <div :class=\"ns.e('footer')\">\n <div :class=\"ns.e('actions')\"><slot name=\"actions\" /></div>\n <slot\n name=\"submit\"\n :submit=\"submit\"\n :stop=\"stop\"\n :loading=\"loading\"\n :disabled=\"stopping ? false : !submittable\"\n >\n <DouButton\n v-if=\"stopping\"\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :aria-label=\"t('chat.stop')\"\n @click=\"stop\"\n >\n <StopIcon />\n </DouButton>\n <DouButton\n v-else\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :disabled=\"!submittable\"\n :aria-label=\"t('chat.send')\"\n @click=\"submit\"\n >\n <ArrowUpIcon />\n </DouButton>\n </slot>\n </div>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"chat-input2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-input/chat-input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpIcon, StopIcon } from '@dou-ui/icons'\nimport {\n computed,\n getCurrentInstance,\n nextTick,\n onBeforeUnmount,\n onMounted,\n reactive,\n ref,\n useAttrs,\n useId,\n useTemplateRef,\n watch,\n} from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useTeleport } from '../../utils/teleport'\nimport { DouButton } from '../button'\nimport { useLocale, useZIndex } from '../config-provider/use-config'\nimport { useFormDisabled } from '../form/use-form-item'\nimport { findToken } from './chat-input'\nimport type {\n ChatInputEmits,\n ChatInputExpose,\n ChatInputOption,\n ChatInputProps,\n ChatInputSlots,\n ChatInputToken,\n} from './chat-input'\n\ndefineOptions({ name: 'DouChatInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ChatInputProps>(), {\n submitOn: 'enter',\n loading: false,\n size: 'md',\n disabled: false,\n minRows: 1,\n maxRows: 8,\n canSubmit: undefined,\n commands: () => [],\n mentions: () => [],\n filter: true,\n searchDelay: 300,\n teleport: undefined,\n})\nconst emit = defineEmits<ChatInputEmits>()\nconst slots = defineSlots<ChatInputSlots>()\nconst model = defineModel<string>({ default: '' })\n\nconst ns = useNamespace('chat-input')\nconst id = useId()\nconst { t } = useLocale()\nconst disabled = useFormDisabled(() => props.disabled)\nconst buttonSize = computed(() => (props.size === 'lg' ? 'md' : 'sm'))\n\n// `class` and `style` dress the frame, the rest goes to the textarea.\nconst attrs = useAttrs()\nconst textareaAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n return rest\n})\n\nconst textareaRef = useTemplateRef<HTMLTextAreaElement>('textarea')\n\nconst submittable = computed(\n () => !disabled.value && (props.canSubmit ?? model.value.trim().length > 0),\n)\n\nfunction resize() {\n const el = textareaRef.value\n if (!el) return\n const style = getComputedStyle(el)\n const lineHeight = Number.parseFloat(style.lineHeight) || 22\n const padding = Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom)\n const min = props.minRows * lineHeight + (padding || 0)\n const max = props.maxRows * lineHeight + (padding || 0)\n el.style.height = 'auto'\n const content = el.scrollHeight\n el.style.height = `${Math.min(Math.max(content, min), max)}px`\n el.style.overflowY = content > max ? 'auto' : 'hidden'\n}\nwatch([model, () => props.minRows, () => props.maxRows], () => nextTick(resize))\nonMounted(resize)\n\n// While a reply is generated the button stops it, unless something new\n// has been typed: then it sends, and the app may queue the message.\nconst stopping = computed(() => props.loading && !submittable.value)\n\nfunction submit() {\n if (!submittable.value) return\n emit('submit', model.value)\n}\n\nfunction stop() {\n if (props.loading) emit('stop')\n}\n\n// --- `/` command and `@` mention menu ---\nconst token = ref<ChatInputToken | null>(null)\nconst dismissed = ref<number | null>(null)\nconst active = ref(0)\n\n// While an input method composes, the text holds what is being spelled\n// (pinyin, say), not what will be typed: wait for it to finish.\nlet composing = false\nfunction onCaret(event?: Event) {\n if (composing || (event instanceof KeyboardEvent && isComposing(event))) return\n if ((event as InputEvent | undefined)?.isComposing) return\n readToken()\n}\nfunction onCompositionStart() {\n composing = true\n}\nfunction onCompositionEnd() {\n composing = false\n readToken()\n}\n\nfunction readToken() {\n const el = textareaRef.value\n if (!el) return\n // the textarea's own text: the model may not have caught up yet, e.g. right\n // after an input method puts its text down\n const next = findToken(el.value, el.selectionStart ?? el.value.length)\n const current = token.value\n // keyup and click re-read the caret after every key, arrows included: an\n // unchanged token must keep its identity or the menu resets its highlight.\n if (\n next &&\n current &&\n next.trigger === current.trigger &&\n next.start === current.start &&\n next.end === current.end &&\n next.query === current.query\n )\n return\n if (next?.start !== current?.start) dismissed.value = null\n token.value = next\n}\n\nconst filterOf = (trigger: '/' | '@') =>\n typeof props.filter === 'object' ? (props.filter[trigger] ?? true) : props.filter\n\nconst options = computed<ChatInputOption[]>(() => {\n const current = token.value\n if (!current || dismissed.value === current.start) return []\n const source = current.trigger === '/' ? props.commands : props.mentions\n const filter = filterOf(current.trigger)\n if (filter === false || (filter === true && !current.query)) return source\n if (typeof filter === 'function')\n return source.filter((option) => filter(option, current.query, current.trigger))\n // what the person sees: the label, a mention's value (it gets inserted), the description\n const query = current.query.toLowerCase()\n const texts = (option: ChatInputOption) => [\n option.label ?? option.value,\n ...(current.trigger === '@' && option.label ? [option.value] : []),\n option.description ?? '',\n ...(option.keywords ?? []),\n ]\n return source.filter((option) => texts(option).some((text) => text.toLowerCase().includes(query)))\n})\n\n// Without local matching, a list the parent puts in after a `search` is the\n// answer to the last query handed out. While what is typed now differs from\n// that query (its search still waits for `searchDelay`, or its answer is on\n// the way), the list shown answers an older one: it stays in view, but\n// Enter and Tab must not pick from it. A list put in before any search,\n// e.g. loaded once after mounting, is fixed and never stale. Nor is any\n// list when nobody listens to `search`: with no one to answer, a parent\n// that passes a new array each render is not answering a query.\nconst instance = getCurrentInstance()\nconst listening = () => !!instance?.vnode.props?.onSearch\ntype Query = { start: number; query: string }\nconst asked: { '/'?: Query; '@'?: Query } = {}\nconst answered = reactive<{ '/'?: Query; '@'?: Query }>({})\nwatch(\n () => props.commands,\n () => (answered['/'] = asked['/']),\n)\nwatch(\n () => props.mentions,\n () => (answered['@'] = asked['@']),\n)\nconst stale = computed(() => {\n const current = token.value\n if (!current || filterOf(current.trigger) !== false || !listening()) return false\n const last = answered[current.trigger]\n return !!last && (last.start !== current.start || last.query !== current.query)\n})\n\n// Each new query is handed out once typing pauses, to look options up\n// elsewhere; the same text at another `@` is a new query too.\nlet searchTimer: ReturnType<typeof setTimeout> | undefined\nwatch(\n () => (token.value ? `${token.value.start}${token.value.trigger}${token.value.query}` : null),\n (key) => {\n clearTimeout(searchTimer)\n const current = token.value\n // Escape closed this one: nothing to look up until another is typed\n if (key === null || !current || dismissed.value === current.start) return\n searchTimer = setTimeout(() => {\n if (listening()) asked[current.trigger] = { start: current.start, query: current.query }\n emit('search', current.query, current.trigger)\n }, props.searchDelay)\n },\n)\nonBeforeUnmount(() => clearTimeout(searchTimer))\nconst menuOpen = computed(() => !disabled.value && options.value.length > 0)\n\n// The menu is a popup like any other: rendered on top of the page, above\n// the frame (or below it when there is no room), stacked over what opened\n// before and closed by a press outside. The focus stays in the textarea.\nconst rootRef = useTemplateRef<HTMLElement>('root')\nconst menuRef = useTemplateRef<HTMLElement>('menu')\nconst teleportTarget = useTeleport(() => props.teleport)\nconst { style: floatingStyle, placement: menuPlacement } = useFloating(\n () => (menuOpen.value ? rootRef.value : null),\n menuRef,\n { open: menuOpen, placement: 'top-start', offset: 6 },\n)\nconst { next: nextZIndex } = useZIndex()\nconst menuZIndex = ref<number>()\nconst menuWidth = ref<number>()\nconst menuMaxWidth = ref<string>()\n// rendered the first time it opens, so the server output stays the same\nconst menuRendered = ref(false)\nconst { theme, sync: syncTheme } = useThemeScope(() => rootRef.value)\n\nfunction readMenuMaxWidth() {\n if (typeof window === 'undefined' || teleportTarget.value.disabled) return undefined\n const el = rootRef.value\n if (!el) return undefined\n const value = getComputedStyle(el).getPropertyValue('--dou-chat-input-menu-max-width').trim()\n if (!value) return undefined\n const target =\n typeof teleportTarget.value.to === 'string'\n ? document.querySelector<HTMLElement>(teleportTarget.value.to)\n : teleportTarget.value.to\n const inherited = target\n ? getComputedStyle(target).getPropertyValue('--dou-chat-input-menu-max-width').trim()\n : ''\n // Forward only when the input or an ancestor overrides the teleport target's value,\n // so a rule directly on `.dou-chat-input__menu` still wins over `:root` / `body`.\n return value !== inherited ? value : undefined\n}\n\nwatch(menuOpen, (value) => {\n if (!value) return\n menuRendered.value = true\n menuZIndex.value = nextZIndex()\n menuWidth.value = rootRef.value?.offsetWidth\n menuMaxWidth.value = readMenuMaxWidth()\n syncTheme()\n})\nconst menuStyle = computed(() => ({\n ...floatingStyle.value,\n zIndex: menuZIndex.value,\n '--dou-chat-input-menu-width': menuWidth.value ? `${menuWidth.value}px` : undefined,\n '--dou-chat-input-menu-max-width': menuMaxWidth.value,\n}))\nuseLayer({\n open: menuOpen,\n elements: () => [rootRef.value, menuRef.value],\n onOutside: () => (token.value = null),\n onEscape: () => (dismissed.value = token.value?.start ?? null),\n})\n// Only a different list moves the highlight back to the first usable option.\nconst firstEnabled = () =>\n Math.max(\n 0,\n options.value.findIndex((option) => !option.disabled),\n )\nwatch(\n () =>\n menuOpen.value\n ? `${token.value?.trigger}${options.value.map((option) => option.value).join('\\u0000')}`\n : '',\n () => (active.value = firstEnabled()),\n)\n\nfunction move(step: 1 | -1) {\n const list = options.value\n for (let offset = 1; offset <= list.length; offset++) {\n const index = (((active.value + step * offset) % list.length) + list.length) % list.length\n if (!list[index]!.disabled) {\n active.value = index\n return\n }\n }\n}\nconst optionId = (index: number) => `${id}-option-${index}`\nwatch(active, async (index) => {\n await nextTick()\n document.getElementById(optionId(index))?.scrollIntoView?.({ block: 'nearest' })\n})\n\n// A label or description cut short shows in full on hover, for a mouse.\nfunction onOptionEnter(event: MouseEvent, option: ChatInputOption, index: number) {\n if (!option.disabled) active.value = index\n const row = event.currentTarget as HTMLElement\n for (const part of row.querySelectorAll<HTMLElement>(\n `.${ns.e('option-label')}, .${ns.e('option-description')}`,\n )) {\n const cut = part.scrollWidth > part.clientWidth || part.scrollHeight > part.clientHeight\n if (cut) part.title = part.textContent!.trim()\n else part.removeAttribute('title')\n }\n}\n\nfunction pick(option: ChatInputOption) {\n const current = token.value\n if (!current || option.disabled) return\n const before = model.value.slice(0, current.start)\n const after = model.value.slice(current.end)\n const inserted = current.trigger === '/' ? '' : `@${option.value} `\n const nextValue = before + inserted + after.replace(/^\\s+/, '')\n const caret = before.length + inserted.length\n const focusedBefore = document.activeElement\n model.value = nextValue\n token.value = null\n // Queue before emitting so a parent `nextTick` in the listener runs after\n // this one, and skip resetting the caret if the listener changed the text.\n void nextTick(() => {\n const el = textareaRef.value\n if (!el) return\n const activeEl = document.activeElement\n const movedElsewhere =\n activeEl && activeEl !== focusedBefore && activeEl !== document.body && activeEl !== el\n if (!movedElsewhere && activeEl !== el) el.focus()\n if (model.value === nextValue && el.value === nextValue) {\n el.setSelectionRange(caret, caret)\n }\n })\n if (current.trigger === '/') emit('command', option)\n else emit('mention', option)\n}\n\nfunction onMenuKeydown(event: KeyboardEvent): boolean {\n if (!menuOpen.value) return false\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault()\n move(event.key === 'ArrowDown' ? 1 : -1)\n return true\n }\n if ((event.key === 'Enter' || event.key === 'Tab') && !isComposing(event)) {\n event.preventDefault()\n // the results for what is typed now are on their way: wait for them\n if (stale.value) return true\n pick(options.value[active.value]!)\n return true\n }\n if (event.key === 'Escape') {\n event.preventDefault()\n dismissed.value = token.value?.start ?? null\n return true\n }\n return false\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (onMenuKeydown(event)) return\n if (event.key !== 'Enter' || isComposing(event)) return\n const mod = event.ctrlKey || event.metaKey\n const sends = props.submitOn === 'enter' ? !event.shiftKey && !mod : mod\n if (!sends) return\n event.preventDefault()\n submit()\n}\n\nconst filesOf = (list: DataTransferItemList | undefined) =>\n [...(list ?? [])]\n .filter((item) => item.kind === 'file')\n .map((item) => item.getAsFile())\n .filter((file): file is File => !!file)\n\nfunction pastedFilesOf(data: DataTransfer | null | undefined): File[] {\n const fromItems = filesOf(data?.items)\n if (fromItems.length) return fromItems\n return [...(data?.files ?? [])]\n}\n\nfunction onPaste(event: ClipboardEvent) {\n if (disabled.value) return\n const files = pastedFilesOf(event.clipboardData)\n if (!files.length) return\n // keep the file's name from being pasted as text\n event.preventDefault()\n emit('attach', files)\n}\n\nconst dragging = ref(false)\nlet depth = 0\nconst carriesFiles = (event: DragEvent) => !!event.dataTransfer?.types.includes('Files')\n\nfunction onDragenter(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n depth++\n dragging.value = true\n}\nfunction onDragover(event: DragEvent) {\n if (disabled.value || !carriesFiles(event)) return\n event.preventDefault()\n}\nfunction onDragleave() {\n depth = Math.max(0, depth - 1)\n if (!depth) dragging.value = false\n}\nfunction onDrop(event: DragEvent) {\n depth = 0\n dragging.value = false\n if (disabled.value) return\n const files = [...(event.dataTransfer?.files ?? [])]\n if (!files.length) return\n event.preventDefault()\n emit('attach', files)\n}\n\n// A press anywhere on the frame that is not a control puts the caret in the text.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === textareaRef.value || target.closest('button, a, input, select, [tabindex]')) return\n event.preventDefault()\n textareaRef.value?.focus()\n}\n\ndefineExpose<ChatInputExpose>({\n get textarea() {\n return textareaRef.value\n },\n focus: () => textareaRef.value?.focus(),\n blur: () => textareaRef.value?.blur(),\n submit,\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.is('disabled', disabled),\n ns.is('loading', loading),\n ns.is('dragging', dragging),\n attrs.class,\n ]\"\n :style=\"attrs.style as StyleValue\"\n @mousedown=\"onMousedown\"\n @dragenter=\"onDragenter\"\n @dragover=\"onDragover\"\n @dragleave=\"onDragleave\"\n @drop=\"onDrop\"\n >\n <div v-if=\"slots.header\" :class=\"ns.e('header')\"><slot name=\"header\" /></div>\n <textarea\n ref=\"textarea\"\n v-model=\"model\"\n :aria-label=\"placeholder ?? t('chat.placeholder')\"\n v-bind=\"textareaAttrs\"\n :class=\"ns.e('native')\"\n :rows=\"minRows\"\n :placeholder=\"placeholder ?? t('chat.placeholder')\"\n :disabled=\"disabled\"\n :aria-autocomplete=\"commands.length || mentions.length ? 'list' : undefined\"\n :aria-expanded=\"commands.length || mentions.length ? menuOpen : undefined\"\n :aria-controls=\"menuOpen ? `${id}-menu` : undefined\"\n :aria-activedescendant=\"menuOpen ? optionId(active) : undefined\"\n @keydown=\"onKeydown\"\n @keyup=\"onCaret\"\n @click=\"onCaret\"\n @input=\"onCaret\"\n @compositionstart=\"onCompositionStart\"\n @compositionend=\"onCompositionEnd\"\n @blur=\"token = null\"\n @paste=\"onPaste\"\n />\n <Teleport v-if=\"menuRendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition name=\"dou-floating\">\n <ul\n v-if=\"menuOpen\"\n :id=\"`${id}-menu`\"\n ref=\"menu\"\n :class=\"[ns.e('menu'), 'dou-floating', ns.is('stale', stale)]\"\n :aria-busy=\"stale || undefined\"\n :style=\"menuStyle\"\n :data-placement=\"menuPlacement\"\n :data-trigger=\"token?.trigger\"\n :data-dou-theme=\"theme\"\n role=\"listbox\"\n @mousedown.prevent\n >\n <li\n v-for=\"(option, index) in options\"\n :id=\"optionId(index)\"\n :key=\"option.value\"\n role=\"option\"\n :class=\"[\n ns.e('option'),\n ns.is('default', !slots.option),\n ns.is('stacked', !slots.option && token?.trigger === '/' && !!option.description),\n ns.is('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"onOptionEnter($event, option, index)\"\n @click=\"pick(option)\"\n >\n <slot name=\"option\" :option=\"option\" :trigger=\"token!.trigger\">\n <component :is=\"option.icon\" v-if=\"option.icon\" :class=\"ns.e('option-icon')\" />\n <span\n v-if=\"token?.trigger === '/' && option.description\"\n :class=\"ns.e('option-content')\"\n >\n <span :class=\"ns.e('option-label')\"> /{{ option.label ?? option.value }} </span>\n <span :class=\"ns.e('option-description')\">\n {{ option.description }}\n </span>\n </span>\n <template v-else>\n <span :class=\"ns.e('option-label')\">\n {{ token?.trigger === '/' ? '/' : '@' }}{{ option.label ?? option.value }}\n </span>\n <span v-if=\"option.description\" :class=\"ns.e('option-description')\">\n {{ option.description }}\n </span>\n </template>\n </slot>\n </li>\n </ul>\n </Transition>\n </Teleport>\n <div :class=\"ns.e('footer')\">\n <div :class=\"ns.e('actions')\"><slot name=\"actions\" /></div>\n <slot\n name=\"submit\"\n :submit=\"submit\"\n :stop=\"stop\"\n :loading=\"loading\"\n :disabled=\"stopping ? false : !submittable\"\n >\n <DouButton\n v-if=\"stopping\"\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :aria-label=\"t('chat.stop')\"\n @click=\"stop\"\n >\n <StopIcon />\n </DouButton>\n <DouButton\n v-else\n :class=\"ns.e('submit')\"\n :size=\"buttonSize\"\n :disabled=\"!submittable\"\n :aria-label=\"t('chat.send')\"\n @click=\"submit\"\n >\n <ArrowUpIcon />\n </DouButton>\n </slot>\n </div>\n </div>\n</template>\n"],"mappings":""}
|