dou-ui 0.1.0-alpha.3 → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/card/card.js.map +1 -1
- package/dist/components/card/card.vue_vue_type_script_setup_true_lang.js +45 -19
- package/dist/components/card/card.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-confirm/chat-confirm.js.map +1 -1
- package/dist/components/chat-confirm/chat-confirm.vue_vue_type_script_setup_true_lang.js +2 -3
- package/dist/components/chat-confirm/chat-confirm.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-context-meter/chat-context-meter.js +19 -2
- package/dist/components/chat-context-meter/chat-context-meter.js.map +1 -1
- package/dist/components/chat-context-meter/chat-context-meter.vue_vue_type_script_setup_true_lang.js +43 -42
- package/dist/components/chat-context-meter/chat-context-meter.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-context-meter/chat-context-meter2.js.map +1 -1
- package/dist/components/chat-context-meter/index.js +2 -1
- package/dist/components/chat-context-meter/index.js.map +1 -1
- package/dist/components/chat-context-meter/style.js +1 -3
- package/dist/components/chat-input/chat-input.js.map +1 -1
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +75 -7
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input2.js.map +1 -1
- package/dist/components/chat-list/chat-list.js +9 -4
- package/dist/components/chat-list/chat-list.js.map +1 -1
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js +34 -0
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-list/chat-list2.js +6 -0
- package/dist/components/chat-list/chat-list2.js.map +1 -0
- package/dist/components/chat-list/index.js +1 -1
- package/dist/components/chat-message/chat-message.js.map +1 -1
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js +33 -8
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-message/chat-message2.js.map +1 -1
- package/dist/components/chat-message/style.js +1 -0
- package/dist/components/chat-question/chat-question.js +6 -0
- package/dist/components/chat-question/chat-question.js.map +1 -0
- package/dist/components/chat-question/chat-question.vue_vue_type_script_setup_true_lang.js +116 -0
- package/dist/components/chat-question/chat-question.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/chat-question/index.js +7 -0
- package/dist/components/chat-question/index.js.map +1 -0
- package/dist/components/chat-question/style.d.ts +1 -0
- package/dist/components/chat-question/style.js +2 -0
- package/dist/components/comment-thread/comment-thread.js.map +1 -1
- package/dist/components/comment-thread/comment-thread.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/comment-thread/comment-thread.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/config-provider/use-config.js +5 -2
- package/dist/components/config-provider/use-config.js.map +1 -1
- package/dist/components/copy-button/copy-button.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/dialog/functional.js +3 -7
- package/dist/components/dialog/functional.js.map +1 -1
- package/dist/components/dialog/index.js +4 -3
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/image/image.js.map +1 -1
- package/dist/components/image/image.vue_vue_type_script_setup_true_lang.js +10 -1
- package/dist/components/image/image.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/link/link.js.map +1 -1
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js +116 -31
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-actions.js +65 -0
- package/dist/components/menu/menu-actions.js.map +1 -0
- package/dist/components/menu/menu-item.js.map +1 -1
- package/dist/components/menu/menu-item.vue_vue_type_script_setup_true_lang.js +50 -12
- package/dist/components/menu/menu-item.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-list.js.map +1 -1
- package/dist/components/menu/menu-list.vue_vue_type_script_setup_true_lang.js +32 -17
- package/dist/components/menu/menu-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-popup.js.map +1 -1
- package/dist/components/menu/menu-popup.vue_vue_type_script_setup_true_lang.js +37 -8
- package/dist/components/menu/menu-popup.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu.js +1 -0
- package/dist/components/menu/menu.js.map +1 -1
- package/dist/components/menu/menu.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/menu/menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu2.js.map +1 -1
- package/dist/components/node-graph/layout.js +123 -15
- package/dist/components/node-graph/layout.js.map +1 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/toast/index.js +5 -4
- package/dist/components/toast/index.js.map +1 -1
- package/dist/components/toast/store.js +1 -9
- package/dist/components/toast/store.js.map +1 -1
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/components/tooltip/tooltip.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/tooltip/tooltip.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/virtual-list/virtual-list.js +7 -1
- package/dist/components/virtual-list/virtual-list.js.map +1 -1
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js +2 -7
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/virtual-list/virtual-list2.js.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/locale/en.js +1 -0
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/zh-cn.js +1 -0
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-tw.js +1 -0
- package/dist/locale/zh-tw.js.map +1 -1
- package/dist/plugin.js +6 -2
- package/dist/plugin.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/card/card.d.ts +6 -1
- package/dist/types/components/chat-context-meter/chat-context-meter.d.ts +23 -3
- package/dist/types/components/chat-context-meter/index.d.ts +1 -0
- package/dist/types/components/chat-input/chat-input.d.ts +33 -3
- package/dist/types/components/chat-input/chat-input.vue.d.ts +7 -0
- package/dist/types/components/chat-input/index.d.ts +20 -0
- package/dist/types/components/chat-list/chat-list.d.ts +19 -1
- package/dist/types/components/chat-message/chat-message.d.ts +32 -2
- package/dist/types/components/chat-message/chat-message.vue.d.ts +4 -1
- package/dist/types/components/chat-message/index.d.ts +8 -0
- package/dist/types/components/chat-question/chat-question.d.ts +43 -0
- package/dist/types/components/chat-question/chat-question.vue.d.ts +18 -0
- package/dist/types/components/chat-question/index.d.ts +43 -0
- package/dist/types/components/comment-thread/comment-thread.d.ts +6 -0
- package/dist/types/components/comment-thread/comment-thread.vue.d.ts +1 -0
- package/dist/types/components/comment-thread/index.d.ts +3 -0
- package/dist/types/components/dialog/functional.d.ts +0 -3
- package/dist/types/components/dialog/index.d.ts +1 -1
- package/dist/types/components/dropdown/dropdown.vue.d.ts +1 -1
- package/dist/types/components/dropdown/index.d.ts +3 -3
- package/dist/types/components/image/image.d.ts +9 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/link/index.d.ts +3 -0
- package/dist/types/components/link/link.d.ts +24 -3
- package/dist/types/components/link/link.vue.d.ts +1 -0
- package/dist/types/components/menu/index.d.ts +3 -0
- package/dist/types/components/menu/menu-actions.d.ts +26 -0
- package/dist/types/components/menu/menu-item.vue.d.ts +6 -0
- package/dist/types/components/menu/menu.d.ts +32 -0
- package/dist/types/components/menu/menu.vue.d.ts +1 -0
- package/dist/types/components/node-graph/layout.d.ts +26 -0
- package/dist/types/components/popover/index.d.ts +3 -3
- package/dist/types/components/popover/popover.vue.d.ts +1 -1
- package/dist/types/components/select/index.d.ts +3 -3
- package/dist/types/components/select/select.vue.d.ts +1 -1
- package/dist/types/components/toast/index.d.ts +0 -2
- package/dist/types/components/toast/store.d.ts +0 -4
- package/dist/types/components/virtual-list/virtual-list.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/locale/types.d.ts +3 -1
- package/dist/types/utils/app-context.d.ts +14 -0
- package/dist/utils/app-context.js +22 -0
- package/dist/utils/app-context.js.map +1 -0
- package/package.json +3 -3
|
@@ -8,7 +8,7 @@ import { useFormDisabled } from "../form/use-form-item.js";
|
|
|
8
8
|
import { useTeleport } from "../../utils/teleport.js";
|
|
9
9
|
import { DouButton } from "../button/index.js";
|
|
10
10
|
import { findToken } from "./chat-input.js";
|
|
11
|
-
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, onMounted, openBlock, ref, renderList, renderSlot, resolveDynamicComponent, toDisplayString, unref, useAttrs, useId, useModel, useSlots, useTemplateRef, vModelText, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
11
|
+
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, getCurrentInstance, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, reactive, ref, renderList, renderSlot, resolveDynamicComponent, toDisplayString, unref, useAttrs, useId, useModel, useSlots, useTemplateRef, vModelText, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
12
12
|
import { ArrowUpIcon, StopIcon } from "@dou-ui/icons";
|
|
13
13
|
// src/components/chat-input/chat-input.vue?vue&type=script&setup=true&lang.ts
|
|
14
14
|
var _hoisted_1 = [
|
|
@@ -23,6 +23,7 @@ var _hoisted_1 = [
|
|
|
23
23
|
];
|
|
24
24
|
var _hoisted_2 = [
|
|
25
25
|
"id",
|
|
26
|
+
"aria-busy",
|
|
26
27
|
"data-placement",
|
|
27
28
|
"data-dou-theme"
|
|
28
29
|
];
|
|
@@ -58,6 +59,15 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
58
59
|
},
|
|
59
60
|
commands: { default: () => [] },
|
|
60
61
|
mentions: { default: () => [] },
|
|
62
|
+
filter: {
|
|
63
|
+
type: [
|
|
64
|
+
Boolean,
|
|
65
|
+
Function,
|
|
66
|
+
Object
|
|
67
|
+
],
|
|
68
|
+
default: true
|
|
69
|
+
},
|
|
70
|
+
searchDelay: { default: 300 },
|
|
61
71
|
teleport: {
|
|
62
72
|
type: [String, Boolean],
|
|
63
73
|
default: void 0
|
|
@@ -72,6 +82,7 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
72
82
|
"stop",
|
|
73
83
|
"command",
|
|
74
84
|
"mention",
|
|
85
|
+
"search",
|
|
75
86
|
"attach"
|
|
76
87
|
], ["update:modelValue"]),
|
|
77
88
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
@@ -121,22 +132,71 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
121
132
|
const token = ref(null);
|
|
122
133
|
const dismissed = ref(null);
|
|
123
134
|
const active = ref(0);
|
|
135
|
+
let composing = false;
|
|
136
|
+
function onCaret(event) {
|
|
137
|
+
if (composing || event instanceof KeyboardEvent && isComposing(event)) return;
|
|
138
|
+
if (event?.isComposing) return;
|
|
139
|
+
readToken();
|
|
140
|
+
}
|
|
141
|
+
function onCompositionStart() {
|
|
142
|
+
composing = true;
|
|
143
|
+
}
|
|
144
|
+
function onCompositionEnd() {
|
|
145
|
+
composing = false;
|
|
146
|
+
readToken();
|
|
147
|
+
}
|
|
124
148
|
function readToken() {
|
|
125
149
|
const el = textareaRef.value;
|
|
126
150
|
if (!el) return;
|
|
127
|
-
const next = findToken(
|
|
151
|
+
const next = findToken(el.value, el.selectionStart ?? el.value.length);
|
|
128
152
|
const current = token.value;
|
|
129
153
|
if (next && current && next.trigger === current.trigger && next.start === current.start && next.end === current.end && next.query === current.query) return;
|
|
130
154
|
if (next?.start !== current?.start) dismissed.value = null;
|
|
131
155
|
token.value = next;
|
|
132
156
|
}
|
|
157
|
+
const filterOf = (trigger) => typeof props.filter === "object" ? props.filter[trigger] ?? true : props.filter;
|
|
133
158
|
const options = computed(() => {
|
|
134
159
|
const current = token.value;
|
|
135
160
|
if (!current || dismissed.value === current.start) return [];
|
|
136
161
|
const source = current.trigger === "/" ? props.commands : props.mentions;
|
|
162
|
+
const filter = filterOf(current.trigger);
|
|
163
|
+
if (filter === false || filter === true && !current.query) return source;
|
|
164
|
+
if (typeof filter === "function") return source.filter((option) => filter(option, current.query, current.trigger));
|
|
137
165
|
const query = current.query.toLowerCase();
|
|
138
|
-
|
|
166
|
+
const texts = (option) => [
|
|
167
|
+
option.label ?? option.value,
|
|
168
|
+
...current.trigger === "@" && option.label ? [option.value] : [],
|
|
169
|
+
option.description ?? "",
|
|
170
|
+
...option.keywords ?? []
|
|
171
|
+
];
|
|
172
|
+
return source.filter((option) => texts(option).some((text) => text.toLowerCase().includes(query)));
|
|
173
|
+
});
|
|
174
|
+
const instance = getCurrentInstance();
|
|
175
|
+
const listening = () => !!instance?.vnode.props?.onSearch;
|
|
176
|
+
const asked = {};
|
|
177
|
+
const answered = reactive({});
|
|
178
|
+
watch(() => props.commands, () => answered["/"] = asked["/"]);
|
|
179
|
+
watch(() => props.mentions, () => answered["@"] = asked["@"]);
|
|
180
|
+
const stale = computed(() => {
|
|
181
|
+
const current = token.value;
|
|
182
|
+
if (!current || filterOf(current.trigger) !== false || !listening()) return false;
|
|
183
|
+
const last = answered[current.trigger];
|
|
184
|
+
return !!last && (last.start !== current.start || last.query !== current.query);
|
|
185
|
+
});
|
|
186
|
+
let searchTimer;
|
|
187
|
+
watch(() => token.value ? `${token.value.start}${token.value.trigger}${token.value.query}` : null, (key) => {
|
|
188
|
+
clearTimeout(searchTimer);
|
|
189
|
+
const current = token.value;
|
|
190
|
+
if (key === null || !current || dismissed.value === current.start) return;
|
|
191
|
+
searchTimer = setTimeout(() => {
|
|
192
|
+
if (listening()) asked[current.trigger] = {
|
|
193
|
+
start: current.start,
|
|
194
|
+
query: current.query
|
|
195
|
+
};
|
|
196
|
+
emit("search", current.query, current.trigger);
|
|
197
|
+
}, props.searchDelay);
|
|
139
198
|
});
|
|
199
|
+
onBeforeUnmount(() => clearTimeout(searchTimer));
|
|
140
200
|
const menuOpen = computed(() => !disabled.value && options.value.length > 0);
|
|
141
201
|
const rootRef = useTemplateRef("root");
|
|
142
202
|
const menuRef = useTemplateRef("menu");
|
|
@@ -217,6 +277,7 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
217
277
|
}
|
|
218
278
|
if ((event.key === "Enter" || event.key === "Tab") && !isComposing(event)) {
|
|
219
279
|
event.preventDefault();
|
|
280
|
+
if (stale.value) return true;
|
|
220
281
|
pick(options.value[active.value]);
|
|
221
282
|
return true;
|
|
222
283
|
}
|
|
@@ -317,9 +378,11 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
317
378
|
"aria-controls": menuOpen.value ? `${unref(id)}-menu` : void 0,
|
|
318
379
|
"aria-activedescendant": menuOpen.value ? optionId(active.value) : void 0,
|
|
319
380
|
onKeydown,
|
|
320
|
-
onKeyup:
|
|
321
|
-
onClick:
|
|
322
|
-
onInput:
|
|
381
|
+
onKeyup: onCaret,
|
|
382
|
+
onClick: onCaret,
|
|
383
|
+
onInput: onCaret,
|
|
384
|
+
onCompositionstart: onCompositionStart,
|
|
385
|
+
onCompositionend: onCompositionEnd,
|
|
323
386
|
onBlur: _cache[1] || (_cache[1] = ($event) => token.value = null),
|
|
324
387
|
onPaste
|
|
325
388
|
}), null, 16, _hoisted_1), [[vModelText, model.value]]),
|
|
@@ -332,7 +395,12 @@ var chat_input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
332
395
|
key: 0,
|
|
333
396
|
id: `${unref(id)}-menu`,
|
|
334
397
|
ref: "menu",
|
|
335
|
-
class: normalizeClass([
|
|
398
|
+
class: normalizeClass([
|
|
399
|
+
unref(ns).e("menu"),
|
|
400
|
+
"dou-floating",
|
|
401
|
+
unref(ns).is("stale", stale.value)
|
|
402
|
+
]),
|
|
403
|
+
"aria-busy": stale.value || void 0,
|
|
336
404
|
style: normalizeStyle(menuStyle.value),
|
|
337
405
|
"data-placement": unref(menuPlacement),
|
|
338
406
|
"data-dou-theme": unref(theme),
|
|
@@ -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 { computed, nextTick, onMounted, ref, useAttrs, useId, useTemplateRef, watch } 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 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\nfunction readToken() {\n const el = textareaRef.value\n if (!el) return\n const next = findToken(model.value, el.selectionStart ?? model.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 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 query = current.query.toLowerCase()\n return source.filter(\n (option) =>\n option.value.toLowerCase().includes(query) ||\n (option.label ?? '').toLowerCase().includes(query),\n )\n})\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\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 let caret: number\n if (current.trigger === '/') {\n model.value = before + after.replace(/^\\s+/, '')\n caret = before.length\n emit('command', option)\n } else {\n const inserted = `@${option.value} `\n model.value = before + inserted + after.replace(/^\\s+/, '')\n caret = before.length + inserted.length\n emit('mention', option)\n }\n token.value = null\n void nextTick(() => {\n textareaRef.value?.focus()\n textareaRef.value?.setSelectionRange(caret, caret)\n })\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 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 onPaste(event: ClipboardEvent) {\n const files = filesOf(event.clipboardData?.items)\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=\"readToken\"\n @click=\"readToken\"\n @input=\"readToken\"\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']\"\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('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"!option.disabled && (active = 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,MAAM,QAAQ;EAYd,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,cAAc,WAAW;GACrD,MAAM,MAAM,MAAM,UAAU,c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AuB,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>()\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\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 let caret: number\n if (current.trigger === '/') {\n model.value = before + after.replace(/^\\s+/, '')\n caret = before.length\n emit('command', option)\n } else {\n const inserted = `@${option.value} `\n model.value = before + inserted + after.replace(/^\\s+/, '')\n caret = before.length + inserted.length\n emit('mention', option)\n }\n token.value = null\n void nextTick(() => {\n textareaRef.value?.focus()\n textareaRef.value?.setSelectionRange(caret, caret)\n })\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 onPaste(event: ClipboardEvent) {\n const files = filesOf(event.clipboardData?.items)\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('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"!option.disabled && (active = 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,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AArD,OAAKN,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA,E,IAAaE,WAAuB,KAAA,QAAA,SAAA,C,OACrDA,WA0BO,KAAA,QAAA,UAAA;KAxBI;KACF;KACN,SAAS,QAAA;KACT,UAAU,SAAA,QAAQ,QAAA,CAAY,YAAA;IALjC,SA0BO,CAlBG,SAAA,SADRL,UAAA,GAAAW,YAQYR,MAAA,SAAA,GAAA;;KANT,OAAKD,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;KACX,MAAM,WAAA;KACN,cAAYA,MAAA,CAAA,CAAC,CAAA,WAAA;KACb,SAAO;;KAER,SAAAY,cAAY,CAAZF,YAAYV,MAAA,QAAA,CAAA,C;;;;;;I,OAEdH,UAAA,GAAAW,YASYR,MAAA,SAAA,GAAA;;KAPT,OAAKD,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;KACX,MAAM,WAAA;KACN,UAAQ,CAAG,YAAA;KACX,cAAYA,MAAA,CAAA,CAAC,CAAA,WAAA;KACb,SAAO;;KAER,SAAAY,cAAe,CAAfF,YAAeV,MAAA,WAAA,CAAA,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-input2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-input/chat-input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpIcon, StopIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onMounted, ref, useAttrs, useId, useTemplateRef, watch } 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 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\nfunction readToken() {\n const el = textareaRef.value\n if (!el) return\n const next = findToken(model.value, el.selectionStart ?? model.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 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 query = current.query.toLowerCase()\n return source.filter(\n (option) =>\n option.value.toLowerCase().includes(query) ||\n (option.label ?? '').toLowerCase().includes(query),\n )\n})\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\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 let caret: number\n if (current.trigger === '/') {\n model.value = before + after.replace(/^\\s+/, '')\n caret = before.length\n emit('command', option)\n } else {\n const inserted = `@${option.value} `\n model.value = before + inserted + after.replace(/^\\s+/, '')\n caret = before.length + inserted.length\n emit('mention', option)\n }\n token.value = null\n void nextTick(() => {\n textareaRef.value?.focus()\n textareaRef.value?.setSelectionRange(caret, caret)\n })\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 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 onPaste(event: ClipboardEvent) {\n const files = filesOf(event.clipboardData?.items)\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=\"readToken\"\n @click=\"readToken\"\n @input=\"readToken\"\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']\"\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('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"!option.disabled && (active = 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>()\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\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 let caret: number\n if (current.trigger === '/') {\n model.value = before + after.replace(/^\\s+/, '')\n caret = before.length\n emit('command', option)\n } else {\n const inserted = `@${option.value} `\n model.value = before + inserted + after.replace(/^\\s+/, '')\n caret = before.length + inserted.length\n emit('mention', option)\n }\n token.value = null\n void nextTick(() => {\n textareaRef.value?.focus()\n textareaRef.value?.setSelectionRange(caret, caret)\n })\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 onPaste(event: ClipboardEvent) {\n const files = filesOf(event.clipboardData?.items)\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('active', index === active),\n ns.is('disabled', !!option.disabled),\n ]\"\n :aria-selected=\"index === active\"\n :aria-disabled=\"option.disabled || undefined\"\n @mouseenter=\"!option.disabled && (active = 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,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
// src/components/chat-list/chat-list.ts
|
|
2
|
+
/** @internal Whether the target is an element or a component, not a key. */
|
|
3
|
+
var isTarget = (target) => typeof target === "object" && target !== null;
|
|
4
|
+
/** @internal The element of a target: a component gives its root element. */
|
|
5
|
+
function elementOf(target) {
|
|
6
|
+
const el = "$el" in target ? target.$el : target;
|
|
7
|
+
return el instanceof HTMLElement ? el : null;
|
|
8
|
+
}
|
|
9
|
+
export { elementOf, isTarget };
|
|
5
10
|
|
|
6
11
|
//# sourceMappingURL=chat-list.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-list.js","names":[
|
|
1
|
+
{"version":3,"file":"chat-list.js","names":[],"sources":["../../../src/components/chat-list/chat-list.ts"],"sourcesContent":["import type { ComponentPublicInstance } from 'vue'\nimport type { VirtualListAlign, VirtualListKey } from '../virtual-list/virtual-list'\n\n/**\n * A message to scroll to: its key with `items`; otherwise its element, or\n * the component that renders it (a `ref` on DouChatMessage).\n */\nexport type ChatListTarget = VirtualListKey | Element | ComponentPublicInstance\n\n/** @internal Whether the target is an element or a component, not a key. */\nexport const isTarget = (target: ChatListTarget): target is Element | ComponentPublicInstance =>\n typeof target === 'object' && target !== null\n\n/** @internal The element of a target: a component gives its root element. */\nexport function elementOf(target: Element | ComponentPublicInstance): HTMLElement | null {\n const el = '$el' in target ? (target.$el as unknown) : target\n return el instanceof HTMLElement ? el : null\n}\n\nexport interface ChatListProps<T = any> {\n /**\n * Follow new content: while the list is scrolled to the bottom, it stays\n * there as messages arrive and text streams in. Scrolling up pauses\n * following until the bottom is reached again.\n */\n autoScroll?: boolean\n /** How close to the bottom, in px, still counts as at the bottom. */\n threshold?: number\n /** Show a button that scrolls back down while the list is away from the bottom. */\n showScrollButton?: boolean\n /**\n * The messages as data, drawn one by one with the `item` slot. Only the\n * messages in or near view are in the page, so long conversations stay\n * light; each is measured once rendered.\n */\n items?: T[]\n /** With `items`, a property of each message, or a function, that gives it a unique key. */\n itemKey?: string | ((item: T, index: number) => VirtualListKey)\n /** With `items`, the height in px to assume for a message not rendered yet. */\n estimateSize?: number\n}\n\nexport interface ChatListEmits {\n /** Whether the list is at the bottom changed. */\n atBottomChange: [atBottom: boolean]\n /** Scrolled to the very top, e.g. to load earlier messages. */\n topReached: []\n}\n\nexport interface ChatListSlots<T = any> {\n /** The messages, usually `DouChatBubble`s. */\n default?: () => unknown\n /** With `items`, one message. */\n item?: (props: { item: T; index: number }) => unknown\n /** Replaces the scroll-to-bottom button. */\n button?: (props: { scrollToBottom: () => void }) => unknown\n}\n\nexport interface ChatListExpose {\n /** The scrolling element. */\n viewport: HTMLElement | null\n /** Scroll to the end and follow new content again. */\n scrollToBottom: (behavior?: ScrollBehavior) => void\n /**\n * Jump to one message, e.g. one found by a search, and stop following\n * new content. With `items` give its key (as `itemKey` makes it, or its\n * index without one); otherwise its element or its DouChatMessage. Pair\n * it with the message's `highlighted` to show which one it is. A target\n * not in the list is ignored. `align` defaults to `center`.\n */\n scrollToMessage: (target: ChatListTarget | null | undefined, align?: VirtualListAlign) => void\n /** Whether the list is at the bottom now. */\n readonly atBottom: boolean\n}\n"],"mappings":";;AAUA,IAAa,YAAY,WACvB,OAAO,WAAW,YAAY,WAAW;;AAG3C,SAAgB,UAAU,QAA+D;CACvF,MAAM,KAAK,SAAS,SAAU,OAAO,MAAkB;CACvD,OAAO,cAAc,cAAc,KAAK;AAC1C"}
|
|
@@ -2,8 +2,11 @@ import { useNamespace } from "../../utils/namespace.js";
|
|
|
2
2
|
import { scrollPositionOf } from "../../utils/scroll.js";
|
|
3
3
|
import { useLocale } from "../config-provider/use-config.js";
|
|
4
4
|
import { useReducedMotion } from "../../composables/use-motion.js";
|
|
5
|
+
import { devWarn } from "../../utils/status-check.js";
|
|
6
|
+
import { virtualItemKey } from "../virtual-list/virtual-list.js";
|
|
5
7
|
import { useTouchScroll } from "../../composables/use-touch-scroll.js";
|
|
6
8
|
import { DouVirtualList } from "../virtual-list/index.js";
|
|
9
|
+
import { elementOf, isTarget } from "./chat-list.js";
|
|
7
10
|
import { Transition, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, onBeforeUnmount, onMounted, openBlock, ref, renderSlot, unref, useTemplateRef, watch, withCtx } from "vue";
|
|
8
11
|
import { ArrowDownIcon } from "@dou-ui/icons";
|
|
9
12
|
// src/components/chat-list/chat-list.vue?vue&type=script&setup=true&lang.ts
|
|
@@ -143,11 +146,42 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
143
146
|
if (content) observer.observe(content);
|
|
144
147
|
}
|
|
145
148
|
watch(() => props.items?.length, observeContent, { flush: "post" });
|
|
149
|
+
function scrollToMessage(target, align = "center") {
|
|
150
|
+
if (target == null) return;
|
|
151
|
+
if (isTarget(target)) {
|
|
152
|
+
const el = viewportRef.value;
|
|
153
|
+
const node = elementOf(target);
|
|
154
|
+
if (!el || !node || !el.contains(node)) return;
|
|
155
|
+
const box = el.getBoundingClientRect();
|
|
156
|
+
const item = node.getBoundingClientRect();
|
|
157
|
+
const top = item.top - box.top + el.scrollTop;
|
|
158
|
+
const offsets = {
|
|
159
|
+
start: top,
|
|
160
|
+
end: top + item.height - el.clientHeight
|
|
161
|
+
};
|
|
162
|
+
let to = top - (el.clientHeight - item.height) / 2;
|
|
163
|
+
if (align === "start") to = offsets.start;
|
|
164
|
+
else if (align === "end") to = offsets.end;
|
|
165
|
+
else if (align === "nearest") to = item.top < box.top ? offsets.start : item.bottom > box.bottom ? offsets.end : el.scrollTop;
|
|
166
|
+
following = false;
|
|
167
|
+
el.scrollTop = Math.max(0, to);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!props.items) {
|
|
171
|
+
if (process.env.NODE_ENV !== "production") devWarn("[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const index = props.items.findIndex((item, at) => virtualItemKey(props.itemKey, item, at) === target);
|
|
175
|
+
if (index < 0) return;
|
|
176
|
+
following = false;
|
|
177
|
+
listRef.value?.scrollToIndex(index, align);
|
|
178
|
+
}
|
|
146
179
|
__expose({
|
|
147
180
|
get viewport() {
|
|
148
181
|
return viewportRef.value;
|
|
149
182
|
},
|
|
150
183
|
scrollToBottom,
|
|
184
|
+
scrollToMessage,
|
|
151
185
|
get atBottom() {
|
|
152
186
|
return atBottom.value;
|
|
153
187
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-list.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_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 { onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListExpose } from '../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 { useLocale } from '../config-provider/use-config'\nimport type { ChatListEmits, ChatListExpose, ChatListProps, ChatListSlots } 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 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 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' })\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div :class=\"[ns.b(), ns.is('at-bottom', atBottom), ns.is('virtual', !!items)]\">\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBA,MAAM,QAAQ;EAkBd,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,gBAAgB,iBAAiB;EACvC,MAAM,EAAE,MAAM,UAAU;EAExB,MAAM,gBAAgB,eAA4B,UAAU;EAC5D,MAAM,eAAe,eAA4B,SAAS;EAC1D,MAAM,UAAU,eAAkC,MAAM;EAExD,MAAM,cAAc,EAClB,IAAI,QAAQ;GACV,OAAO,MAAM,QAAS,QAAQ,OAAO,GAAG,KAAK,OAAQ,cAAc;EACrE,EACF;EACA,MAAM,aAAa,EACjB,IAAI,QAAQ;GACV,OAAO,MAAM,QACR,YAAY,OAAO,oBACpB,aAAa;EACnB,EACF;EAEA,MAAM,WAAW,IAAI,IAAI;EACzB,MAAM,WAAW,UAAU,KAAK,kBAAkB,KAAK,CAAC;EAKxD,IAAI,YAAY;EAChB,IAAI,UAAU;EACd,IAAI,QAAQ;EACZ,MAAM,QAAQ,eAAe;EAE7B,SAAS,iBAAiB,IAAiB;GACzC,OAAO,GAAG,eAAe,GAAG,YAAY,GAAG;EAC7C;EAEA,MAAM,SAAS,OACb,iBAAiB,EAAE,CAAC,CAAC,OAAO,KAAK,GAAG,eAAe,GAAG;EAExD,SAAS,WAAW;GAClB,MAAM,KAAK,YAAY;GACvB,IAAI,CAAC,IAAI;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-list.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_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 { 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 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 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' })\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 offsets = { start: top, end: top + item.height - el.clientHeight }\n let to = top - (el.clientHeight - 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 ? offsets.start : item.bottom > box.bottom ? offsets.end : 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 :class=\"[ns.b(), ns.is('at-bottom', atBottom), ns.is('virtual', !!items)]\">\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 :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MAAA,CAAA,CAAC,CAAA,eAAA;IACG,iBAAA;IACD,gBAAA;G,IAEhBI,mBAA0D,OAAA;IAArD,KAAI;IAAW,OAAKL,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA;G,IAAaG,WAAQ,KAAA,QAAA,SAAA,C,0BAEtDE,YAaaC,YAAA,EAbD,MAAK,uBAAsB,GAAA;IACrC,SAAAJ,cAWM,CAXK,QAAA,oBAAgB,CAAK,SAAA,SAAhCL,UAAA,GAAAC,mBAWM,OAAA;;KAXqC,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;I,IACpDG,WASO,KAAA,QAAA,UAAA,EATc,sBAAwB,eAAc,EAA3D,SASO,CARLC,mBAOS,UAAA;KANP,MAAK;KACJ,OAAKL,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,eAAA,CAAA;KACX,cAAYA,MAAA,CAAA,CAAC,CAAA,qBAAA;KACb,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,eAAc;I,IAEtBK,YAAiBL,MAAA,aAAA,CAAA,C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import chat_list_vue_vue_type_script_setup_true_lang_default from "./chat-list.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/components/chat-list/chat-list.vue
|
|
3
|
+
var chat_list_default = chat_list_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { chat_list_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=chat-list2.js.map
|
|
@@ -0,0 +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 { 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 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 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' })\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 offsets = { start: top, end: top + item.height - el.clientHeight }\n let to = top - (el.clientHeight - 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 ? offsets.start : item.bottom > box.bottom ? offsets.end : 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 :class=\"[ns.b(), ns.is('at-bottom', atBottom), ns.is('virtual', !!items)]\">\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":""}
|