dou-ui 0.1.0-alpha.22 → 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.
Files changed (31) hide show
  1. package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +26 -12
  2. package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js.map +1 -1
  3. package/dist/components/chat-input/chat-input2.js.map +1 -1
  4. package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js +26 -10
  5. package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
  6. package/dist/components/chat-list/chat-list2.js.map +1 -1
  7. package/dist/components/chat-message/chat-message.js.map +1 -1
  8. package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js +52 -12
  9. package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js.map +1 -1
  10. package/dist/components/chat-message/chat-message2.js.map +1 -1
  11. package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js +47 -17
  12. package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
  13. package/dist/components/virtual-list/virtual-list2.js.map +1 -1
  14. package/dist/composables/use-measured-sizes.js +7 -3
  15. package/dist/composables/use-measured-sizes.js.map +1 -1
  16. package/dist/composables/use-touch-scroll.js +141 -29
  17. package/dist/composables/use-touch-scroll.js.map +1 -1
  18. package/dist/locale/en.js +2 -0
  19. package/dist/locale/en.js.map +1 -1
  20. package/dist/locale/zh-cn.js +2 -0
  21. package/dist/locale/zh-cn.js.map +1 -1
  22. package/dist/locale/zh-tw.js +2 -0
  23. package/dist/locale/zh-tw.js.map +1 -1
  24. package/dist/style.css +1 -1
  25. package/dist/types/components/chat-message/chat-message.d.ts +18 -0
  26. package/dist/types/components/chat-message/chat-message.vue.d.ts +1 -0
  27. package/dist/types/components/chat-message/index.d.ts +3 -0
  28. package/dist/types/composables/use-measured-sizes.d.ts +2 -0
  29. package/dist/types/composables/use-touch-scroll.d.ts +8 -0
  30. package/dist/types/locale/types.d.ts +4 -0
  31. 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
- option.icon ? (openBlock(), createBlock(resolveDynamicComponent(option.icon), {
440
- key: 0,
441
- class: normalizeClass(unref(ns).e("option-icon"))
442
- }, null, 8, ["class"])) : createCommentVNode("", true),
443
- createElementVNode("span", { class: normalizeClass(unref(ns).e("option-label")) }, toDisplayString(token.value?.trigger === "/" ? "/" : "@") + toDisplayString(option.label ?? option.value), 3),
444
- option.description ? (openBlock(), createElementBlock("span", {
445
- key: 1,
446
- class: normalizeClass(unref(ns).e("option-description"))
447
- }, toDisplayString(option.description), 3)) : createCommentVNode("", true)
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,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,WAAW,MAAM,UAAU,KAAK;GAC1D,MAAM,UAAU,OAAO,WAAW,MAAM,UAAU,IAAI,OAAO,WAAW,MAAM,aAAa;GAC3F,MAAM,MAAM,MAAM,UAAU,cAA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AC,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
+ {"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>()\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":";;;;;;;;;;;;;;;;;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A,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":""}
@@ -63,17 +63,25 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
63
63
  let lastTop = 0;
64
64
  let atTop = false;
65
65
  const touch = useTouchScroll();
66
+ const plainContentStyle = computed(() => {
67
+ const offset = !props.items ? touch.pendingShift(plainViewport.value) : 0;
68
+ return offset ? { transform: `translateY(${-offset}px)` } : void 0;
69
+ });
70
+ function logicalTopOf(el) {
71
+ return Math.max(0, scrollPositionOf(el).top + touch.pendingShift(el));
72
+ }
66
73
  function distanceToBottom(el) {
67
- return el.scrollHeight - el.scrollTop - el.clientHeight;
74
+ return el.scrollHeight - (el.scrollTop + touch.pendingShift(el)) - el.clientHeight;
68
75
  }
69
- const isTop = (el) => scrollPositionOf(el).top <= 0 && el.scrollHeight > el.clientHeight;
76
+ const isTop = (el) => logicalTopOf(el) <= 0 && el.scrollHeight > el.clientHeight;
70
77
  function onScroll() {
71
78
  const el = viewportRef.value;
72
79
  if (!el) return;
80
+ const top = el.scrollTop + touch.pendingShift(el);
73
81
  const near = distanceToBottom(el) <= props.threshold;
74
82
  if (near) following = true;
75
- else if (el.scrollTop < lastTop) following = false;
76
- lastTop = el.scrollTop;
83
+ else if (top < lastTop) following = false;
84
+ lastTop = top;
77
85
  atBottom.value = near;
78
86
  if (!isTop(el)) {
79
87
  atTop = false;
@@ -119,6 +127,7 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
119
127
  function scrollToBottom(behavior = reducedMotion.value ? "auto" : "smooth") {
120
128
  const el = viewportRef.value;
121
129
  if (!el) return;
130
+ touch.clearShift(el);
122
131
  following = true;
123
132
  el.scrollTo?.({
124
133
  top: el.scrollHeight,
@@ -133,6 +142,7 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
133
142
  if (el) atBottom.value = distanceToBottom(el) <= props.threshold;
134
143
  return;
135
144
  }
145
+ touch.clearShift(el);
136
146
  el.scrollTop = el.scrollHeight;
137
147
  lastTop = el.scrollTop;
138
148
  atBottom.value = true;
@@ -145,7 +155,10 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
145
155
  observeContent();
146
156
  if (viewportRef.value) observer.observe(viewportRef.value);
147
157
  });
148
- onBeforeUnmount(() => observer?.disconnect());
158
+ onBeforeUnmount(() => {
159
+ observer?.disconnect();
160
+ touch.clearShift(plainViewport.value);
161
+ });
149
162
  let observed;
150
163
  function observeContent() {
151
164
  const content = contentRef.value;
@@ -162,9 +175,10 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
162
175
  const el = viewportRef.value;
163
176
  const node = elementOf(target);
164
177
  if (!el || !node || !el.contains(node)) return;
178
+ const pending = touch.pendingShift(el);
165
179
  const box = el.getBoundingClientRect();
166
180
  const item = node.getBoundingClientRect();
167
- const top = item.top - box.top + el.scrollTop;
181
+ const top = item.top - box.top + el.scrollTop + pending;
168
182
  const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0;
169
183
  const visibleHeight = Math.max(0, el.clientHeight - bottomInset);
170
184
  const offsets = {
@@ -174,8 +188,9 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
174
188
  let to = top - (visibleHeight - item.height) / 2;
175
189
  if (align === "start") to = offsets.start;
176
190
  else if (align === "end") to = offsets.end;
177
- else if (align === "nearest") to = item.top < box.top ? offsets.start : item.bottom > box.bottom - bottomInset ? offsets.end : el.scrollTop;
191
+ else if (align === "nearest") to = item.top < box.top ? offsets.start : item.bottom > box.bottom - bottomInset ? offsets.end : el.scrollTop + pending;
178
192
  following = false;
193
+ touch.clearShift(el);
179
194
  el.scrollTop = Math.max(0, to);
180
195
  return;
181
196
  }
@@ -216,7 +231,7 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
216
231
  "estimate-size": __props.estimateSize,
217
232
  role: "log",
218
233
  "aria-label": unref(t)("chat.messages"),
219
- onScrollPassive: onScroll,
234
+ onScroll,
220
235
  onWheelPassive: onWheel
221
236
  }, {
222
237
  default: withCtx(({ item, index }) => [renderSlot(_ctx.$slots, "item", {
@@ -241,8 +256,9 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
241
256
  onWheelPassive: onWheel
242
257
  }, [createElementVNode("div", {
243
258
  ref: "content",
244
- class: normalizeClass(unref(ns).e("content"))
245
- }, [renderSlot(_ctx.$slots, "default")], 2)], 42, _hoisted_1)), createVNode(Transition, { name: "dou-chat-list-button" }, {
259
+ class: normalizeClass(unref(ns).e("content")),
260
+ style: normalizeStyle(plainContentStyle.value)
261
+ }, [renderSlot(_ctx.$slots, "default")], 6)], 42, _hoisted_1)), createVNode(Transition, { name: "dou-chat-list-button" }, {
246
262
  default: withCtx(() => [__props.showScrollButton && !atBottom.value ? (openBlock(), createElementBlock("div", {
247
263
  key: 0,
248
264
  class: normalizeClass(unref(ns).e("scroll"))
@@ -1 +1 @@
1
- {"version":3,"file":"chat-list.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createBlock","_withCtx","_renderSlot","_createElementVNode","_createVNode","_Transition","_createCommentVNode"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - el.scrollTop - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) =>\n scrollPositionOf(el).top <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (el.scrollTop < lastTop) following = false\n lastTop = el.scrollTop\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => observer?.disconnect())\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n const top = item.top - box.top + el.scrollTop\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.sc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EAAA,CAAE,CAAC,EAAC,UAAA,CAAA;IACX,OAAO,QAAA;IACP,YAAU,QAAA;IACV,iBAAe,QAAA;IAChB,MAAK;IACJ,cAAYA,MAAA,CAAA,CAAC,CAAA,eAAA;IACG,iBAAA;IACD,gBAAA;;IAEL,SAAOG,SACgC,EAD5B,MAAM,YAAK,CAC/BC,WAAgD,KAAA,QAAA,QAAA;KAAvB;KAAc;;;;;;;;;G,OAG3CP,UAAA,GAAAC,mBAWM,OAAA;;IATJ,KAAI;IACH,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,UAAA,CAAA;IACZ,MAAK;IACL,UAAS;IACR,cAAYA,MAAA,CAAA,CAAC,CAAA,eAAA;IACG,iBAAA;IACD,gBAAA;G,IAEhBK,mBAA0D,OAAA;IAArD,KAAI;IAAW,OAAKN,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA;G,IAAaI,WAAQ,KAAA,QAAA,SAAA,C,0BAEtDE,YAaaC,YAAA,EAbD,MAAK,uBAAsB,GAAA;IACrC,SAAAJ,cAWM,CAXK,QAAA,oBAAgB,CAAK,SAAA,SAAhCN,UAAA,GAAAC,mBAWM,OAAA;;KAXqC,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;I,IACpDI,WASO,KAAA,QAAA,UAAA,EATc,sBAAwB,eAAc,EAA3D,SASO,CARLC,mBAOS,UAAA;KANP,MAAK;KACJ,OAAKN,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,eAAA,CAAA;KACX,cAAYA,MAAA,CAAA,CAAC,CAAA,qBAAA;KACb,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,eAAc;I,IAEtBM,YAAiBN,MAAA,aAAA,CAAA,C"}
1
+ {"version":3,"file":"chat-list.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createBlock","_withCtx","_renderSlot","_createElementVNode","_createVNode","_Transition","_createCommentVNode"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\nconst plainContentStyle = computed(() => {\n const offset = !props.items ? touch.pendingShift(plainViewport.value) : 0\n return offset ? { transform: `translateY(${-offset}px)` } : undefined\n})\n\nfunction logicalTopOf(el: HTMLElement) {\n return Math.max(0, scrollPositionOf(el).top + touch.pendingShift(el))\n}\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - (el.scrollTop + touch.pendingShift(el)) - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) => logicalTopOf(el) <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const top = el.scrollTop + touch.pendingShift(el)\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (top < lastTop) following = false\n lastTop = top\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n touch.clearShift(el)\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n touch.clearShift(el)\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => {\n observer?.disconnect()\n touch.clearShift(plainViewport.value)\n})\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const pending = touch.pendingShift(el)\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n // Content is visually shifted by `translateY(-pending)` while a dropped\n // touch shift is pending, so add `pending` back to recover layout offset.\n const top = item.top - box.top + el.scrollTop + pending\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop + pending\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n touch.clearShift(el)\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\" :style=\"plainContentStyle\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.scrollToBottom')\"\n @click=\"scrollToBottom()\"\n >\n <ArrowDownIcon />\n </button>\n </slot>\n </div>\n </Transition>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,MAAM,QAAQ;EAoBd,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,gBAAgB,iBAAiB;EACvC,MAAM,EAAE,MAAM,UAAU;EAExB,MAAM,YAAY,eAAe;GAC/B,IAAI,MAAM,gBAAgB,KAAA,GAAW,OAAO,KAAA;GAC5C,OAAO,EACL,gCACE,OAAO,MAAM,gBAAgB,WAAW,GAAG,MAAM,YAAY,MAAM,MAAM,YAC7E;EACF,CAAC;EAED,MAAM,gBAAgB,eAA4B,UAAU;EAC5D,MAAM,eAAe,eAA4B,SAAS;EAC1D,MAAM,UAAU,eAAkC,MAAM;EAExD,MAAM,cAAc,EAClB,IAAI,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Ae,QAAA;IAChB,MAAK;IACJ,cAAYA,MAAA,CAAA,CAAC,CAAA,eAAA;IACL;IACO,gBAAA;;IAEL,SAAOG,SACgC,EAD5B,MAAM,YAAK,CAC/BC,WAAgD,KAAA,QAAA,QAAA;KAAvB;KAAc;;;;;;;;;G,OAG3CP,UAAA,GAAAC,mBAWM,OAAA;;IATJ,KAAI;IACH,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,UAAA,CAAA;IACZ,MAAK;IACL,UAAS;IACR,cAAYA,MAAA,CAAA,CAAC,CAAA,eAAA;IACG,iBAAA;IACD,gBAAA;G,IAEhBK,mBAAqF,OAAA;IAAhF,KAAI;IAAW,OAAKN,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA;IAAc,OAAKC,eAAE,kBAAA,KAAiB;G,IAAEG,WAAQ,KAAA,QAAA,SAAA,C,0BAEjFE,YAaaC,YAAA,EAbD,MAAK,uBAAsB,GAAA;IACrC,SAAAJ,cAWM,CAXK,QAAA,oBAAgB,CAAK,SAAA,SAAhCN,UAAA,GAAAC,mBAWM,OAAA;;KAXqC,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;I,IACpDI,WASO,KAAA,QAAA,UAAA,EATc,sBAAwB,eAAc,EAA3D,SASO,CARLC,mBAOS,UAAA;KANP,MAAK;KACJ,OAAKN,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,eAAA,CAAA;KACX,cAAYA,MAAA,CAAA,CAAC,CAAA,qBAAA;KACb,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,eAAc;I,IAEtBM,YAAiBN,MAAA,aAAA,CAAA,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"chat-list2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - el.scrollTop - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) =>\n scrollPositionOf(el).top <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (el.scrollTop < lastTop) following = false\n lastTop = el.scrollTop\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => observer?.disconnect())\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n const top = item.top - box.top + el.scrollTop\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.scrollToBottom')\"\n @click=\"scrollToBottom()\"\n >\n <ArrowDownIcon />\n </button>\n </slot>\n </div>\n </Transition>\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"chat-list2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\nconst plainContentStyle = computed(() => {\n const offset = !props.items ? touch.pendingShift(plainViewport.value) : 0\n return offset ? { transform: `translateY(${-offset}px)` } : undefined\n})\n\nfunction logicalTopOf(el: HTMLElement) {\n return Math.max(0, scrollPositionOf(el).top + touch.pendingShift(el))\n}\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - (el.scrollTop + touch.pendingShift(el)) - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) => logicalTopOf(el) <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const top = el.scrollTop + touch.pendingShift(el)\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (top < lastTop) following = false\n lastTop = top\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n touch.clearShift(el)\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n touch.clearShift(el)\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => {\n observer?.disconnect()\n touch.clearShift(plainViewport.value)\n})\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const pending = touch.pendingShift(el)\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n // Content is visually shifted by `translateY(-pending)` while a dropped\n // touch shift is pending, so add `pending` back to recover layout offset.\n const top = item.top - box.top + el.scrollTop + pending\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop + pending\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n touch.clearShift(el)\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\" :style=\"plainContentStyle\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.scrollToBottom')\"\n @click=\"scrollToBottom()\"\n >\n <ArrowDownIcon />\n </button>\n </slot>\n </div>\n </Transition>\n </div>\n</template>\n"],"mappings":""}