dou-ui 0.1.0-alpha.22 → 0.1.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js +26 -10
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-list/chat-list2.js.map +1 -1
- package/dist/components/chat-message/chat-message.js.map +1 -1
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js +52 -12
- 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/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js +47 -17
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/virtual-list/virtual-list2.js.map +1 -1
- package/dist/composables/use-measured-sizes.js +7 -3
- package/dist/composables/use-measured-sizes.js.map +1 -1
- package/dist/composables/use-touch-scroll.js +141 -29
- package/dist/composables/use-touch-scroll.js.map +1 -1
- package/dist/locale/en.js +2 -0
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/zh-cn.js +2 -0
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-tw.js +2 -0
- package/dist/locale/zh-tw.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/chat-message/chat-message.d.ts +18 -0
- package/dist/types/components/chat-message/chat-message.vue.d.ts +1 -0
- package/dist/types/components/chat-message/index.d.ts +3 -0
- package/dist/types/composables/use-measured-sizes.d.ts +2 -0
- package/dist/types/composables/use-touch-scroll.d.ts +8 -0
- package/dist/types/locale/types.d.ts +4 -0
- package/package.json +3 -3
|
@@ -63,17 +63,25 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
63
63
|
let lastTop = 0;
|
|
64
64
|
let atTop = false;
|
|
65
65
|
const touch = useTouchScroll();
|
|
66
|
+
const plainContentStyle = computed(() => {
|
|
67
|
+
const offset = !props.items ? touch.pendingShift(plainViewport.value) : 0;
|
|
68
|
+
return offset ? { transform: `translateY(${-offset}px)` } : void 0;
|
|
69
|
+
});
|
|
70
|
+
function logicalTopOf(el) {
|
|
71
|
+
return Math.max(0, scrollPositionOf(el).top + touch.pendingShift(el));
|
|
72
|
+
}
|
|
66
73
|
function distanceToBottom(el) {
|
|
67
|
-
return el.scrollHeight - el.scrollTop - el.clientHeight;
|
|
74
|
+
return el.scrollHeight - (el.scrollTop + touch.pendingShift(el)) - el.clientHeight;
|
|
68
75
|
}
|
|
69
|
-
const isTop = (el) =>
|
|
76
|
+
const isTop = (el) => logicalTopOf(el) <= 0 && el.scrollHeight > el.clientHeight;
|
|
70
77
|
function onScroll() {
|
|
71
78
|
const el = viewportRef.value;
|
|
72
79
|
if (!el) return;
|
|
80
|
+
const top = el.scrollTop + touch.pendingShift(el);
|
|
73
81
|
const near = distanceToBottom(el) <= props.threshold;
|
|
74
82
|
if (near) following = true;
|
|
75
|
-
else if (
|
|
76
|
-
lastTop =
|
|
83
|
+
else if (top < lastTop) following = false;
|
|
84
|
+
lastTop = top;
|
|
77
85
|
atBottom.value = near;
|
|
78
86
|
if (!isTop(el)) {
|
|
79
87
|
atTop = false;
|
|
@@ -119,6 +127,7 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
119
127
|
function scrollToBottom(behavior = reducedMotion.value ? "auto" : "smooth") {
|
|
120
128
|
const el = viewportRef.value;
|
|
121
129
|
if (!el) return;
|
|
130
|
+
touch.clearShift(el);
|
|
122
131
|
following = true;
|
|
123
132
|
el.scrollTo?.({
|
|
124
133
|
top: el.scrollHeight,
|
|
@@ -133,6 +142,7 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
133
142
|
if (el) atBottom.value = distanceToBottom(el) <= props.threshold;
|
|
134
143
|
return;
|
|
135
144
|
}
|
|
145
|
+
touch.clearShift(el);
|
|
136
146
|
el.scrollTop = el.scrollHeight;
|
|
137
147
|
lastTop = el.scrollTop;
|
|
138
148
|
atBottom.value = true;
|
|
@@ -145,7 +155,10 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
145
155
|
observeContent();
|
|
146
156
|
if (viewportRef.value) observer.observe(viewportRef.value);
|
|
147
157
|
});
|
|
148
|
-
onBeforeUnmount(() =>
|
|
158
|
+
onBeforeUnmount(() => {
|
|
159
|
+
observer?.disconnect();
|
|
160
|
+
touch.clearShift(plainViewport.value);
|
|
161
|
+
});
|
|
149
162
|
let observed;
|
|
150
163
|
function observeContent() {
|
|
151
164
|
const content = contentRef.value;
|
|
@@ -162,9 +175,10 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
162
175
|
const el = viewportRef.value;
|
|
163
176
|
const node = elementOf(target);
|
|
164
177
|
if (!el || !node || !el.contains(node)) return;
|
|
178
|
+
const pending = touch.pendingShift(el);
|
|
165
179
|
const box = el.getBoundingClientRect();
|
|
166
180
|
const item = node.getBoundingClientRect();
|
|
167
|
-
const top = item.top - box.top + el.scrollTop;
|
|
181
|
+
const top = item.top - box.top + el.scrollTop + pending;
|
|
168
182
|
const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0;
|
|
169
183
|
const visibleHeight = Math.max(0, el.clientHeight - bottomInset);
|
|
170
184
|
const offsets = {
|
|
@@ -174,8 +188,9 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
174
188
|
let to = top - (visibleHeight - item.height) / 2;
|
|
175
189
|
if (align === "start") to = offsets.start;
|
|
176
190
|
else if (align === "end") to = offsets.end;
|
|
177
|
-
else if (align === "nearest") to = item.top < box.top ? offsets.start : item.bottom > box.bottom - bottomInset ? offsets.end : el.scrollTop;
|
|
191
|
+
else if (align === "nearest") to = item.top < box.top ? offsets.start : item.bottom > box.bottom - bottomInset ? offsets.end : el.scrollTop + pending;
|
|
178
192
|
following = false;
|
|
193
|
+
touch.clearShift(el);
|
|
179
194
|
el.scrollTop = Math.max(0, to);
|
|
180
195
|
return;
|
|
181
196
|
}
|
|
@@ -216,7 +231,7 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
216
231
|
"estimate-size": __props.estimateSize,
|
|
217
232
|
role: "log",
|
|
218
233
|
"aria-label": unref(t)("chat.messages"),
|
|
219
|
-
|
|
234
|
+
onScroll,
|
|
220
235
|
onWheelPassive: onWheel
|
|
221
236
|
}, {
|
|
222
237
|
default: withCtx(({ item, index }) => [renderSlot(_ctx.$slots, "item", {
|
|
@@ -241,8 +256,9 @@ var chat_list_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
241
256
|
onWheelPassive: onWheel
|
|
242
257
|
}, [createElementVNode("div", {
|
|
243
258
|
ref: "content",
|
|
244
|
-
class: normalizeClass(unref(ns).e("content"))
|
|
245
|
-
|
|
259
|
+
class: normalizeClass(unref(ns).e("content")),
|
|
260
|
+
style: normalizeStyle(plainContentStyle.value)
|
|
261
|
+
}, [renderSlot(_ctx.$slots, "default")], 6)], 42, _hoisted_1)), createVNode(Transition, { name: "dou-chat-list-button" }, {
|
|
246
262
|
default: withCtx(() => [__props.showScrollButton && !atBottom.value ? (openBlock(), createElementBlock("div", {
|
|
247
263
|
key: 0,
|
|
248
264
|
class: normalizeClass(unref(ns).e("scroll"))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-list.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createBlock","_withCtx","_renderSlot","_createElementVNode","_createVNode","_Transition","_createCommentVNode"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - el.scrollTop - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) =>\n scrollPositionOf(el).top <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (el.scrollTop < lastTop) following = false\n lastTop = el.scrollTop\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => observer?.disconnect())\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n const top = item.top - box.top + el.scrollTop\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.scrollToBottom')\"\n @click=\"scrollToBottom()\"\n >\n <ArrowDownIcon />\n </button>\n </slot>\n </div>\n </Transition>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,MAAM,QAAQ;EAoBd,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,gBAAgB,iBAAiB;EACvC,MAAM,EAAE,MAAM,UAAU;EAExB,MAAM,YAAY,eAAe;GAC/B,IAAI,MAAM,gBAAgB,KAAA,GAAW,OAAO,KAAA;GAC5C,OAAO,EACL,gCACE,OAAO,MAAM,gBAAgB,WAAW,GAAG,MAAM,YAAY,MAAM,MAAM,YAC7E;EACF,CAAC;EAED,MAAM,gBAAgB,eAA4B,UAAU;EAC5D,MAAM,eAAe,eAA4B,SAAS;EAC1D,MAAM,UAAU,eAAkC,MAAM;EAExD,MAAM,cAAc,EAClB,IAAI,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,SA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CAAA,C"}
|
|
1
|
+
{"version":3,"file":"chat-list.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createBlock","_withCtx","_renderSlot","_createElementVNode","_createVNode","_Transition","_createCommentVNode"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\nconst plainContentStyle = computed(() => {\n const offset = !props.items ? touch.pendingShift(plainViewport.value) : 0\n return offset ? { transform: `translateY(${-offset}px)` } : undefined\n})\n\nfunction logicalTopOf(el: HTMLElement) {\n return Math.max(0, scrollPositionOf(el).top + touch.pendingShift(el))\n}\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - (el.scrollTop + touch.pendingShift(el)) - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) => logicalTopOf(el) <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const top = el.scrollTop + touch.pendingShift(el)\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (top < lastTop) following = false\n lastTop = top\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n touch.clearShift(el)\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n touch.clearShift(el)\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => {\n observer?.disconnect()\n touch.clearShift(plainViewport.value)\n})\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const pending = touch.pendingShift(el)\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n // Content is visually shifted by `translateY(-pending)` while a dropped\n // touch shift is pending, so add `pending` back to recover layout offset.\n const top = item.top - box.top + el.scrollTop + pending\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop + pending\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n touch.clearShift(el)\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\" :style=\"plainContentStyle\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.scrollToBottom')\"\n @click=\"scrollToBottom()\"\n >\n <ArrowDownIcon />\n </button>\n </slot>\n </div>\n </Transition>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,MAAM,QAAQ;EAoBd,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,gBAAgB,iBAAiB;EACvC,MAAM,EAAE,MAAM,UAAU;EAExB,MAAM,YAAY,eAAe;GAC/B,IAAI,MAAM,gBAAgB,KAAA,GAAW,OAAO,KAAA;GAC5C,OAAO,EACL,gCACE,OAAO,MAAM,gBAAgB,WAAW,GAAG,MAAM,YAAY,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
{"version":3,"file":"chat-list2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - el.scrollTop - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) =>\n scrollPositionOf(el).top <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (el.scrollTop < lastTop) following = false\n lastTop = el.scrollTop\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => observer?.disconnect())\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n const top = item.top - box.top + el.scrollTop\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.scrollToBottom')\"\n @click=\"scrollToBottom()\"\n >\n <ArrowDownIcon />\n </button>\n </slot>\n </div>\n </Transition>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"chat-list2.js","names":["_sfc_main"],"sources":["../../../src/components/chat-list/chat-list.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport type { HTMLAttributes } from 'vue'\nimport type { ForwardedAttributes } from '../../utils/install'\nimport { ArrowDownIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\nimport { DouVirtualList } from '../virtual-list'\nimport type { VirtualListAlign, VirtualListExpose } from '../virtual-list'\nimport { virtualItemKey } from '../virtual-list/virtual-list'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useTouchScroll } from '../../composables/use-touch-scroll'\nimport { scrollPositionOf } from '../../utils/scroll'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport type {\n ChatListEmits,\n ChatListExpose,\n ChatListProps,\n ChatListSlots,\n ChatListTarget,\n} from './chat-list'\nimport { elementOf, isTarget } from './chat-list'\n\ndefineOptions({ name: 'DouChatList' })\n\nconst props = withDefaults(\n defineProps<\n ChatListProps<T> &\n /* @vue-ignore */ ForwardedAttributes<\n HTMLAttributes,\n ChatListProps<T>,\n keyof ChatListEmits & string\n >\n >(),\n {\n autoScroll: true,\n threshold: 24,\n showScrollButton: true,\n bottomInset: undefined,\n bottomFade: false,\n items: undefined,\n itemKey: undefined,\n estimateSize: 120,\n },\n)\nconst emit = defineEmits<ChatListEmits>()\ndefineSlots<ChatListSlots<T>>()\n\nconst ns = useNamespace('chat-list')\nconst reducedMotion = useReducedMotion()\nconst { t } = useLocale()\n\nconst rootStyle = computed(() => {\n if (props.bottomInset === undefined) return undefined\n return {\n '--dou-chat-list-bottom-inset':\n typeof props.bottomInset === 'number' ? `${props.bottomInset}px` : props.bottomInset,\n }\n})\n\nconst plainViewport = useTemplateRef<HTMLElement>('viewport')\nconst plainContent = useTemplateRef<HTMLElement>('content')\nconst listRef = useTemplateRef<VirtualListExpose>('list')\n// With `items`, the virtual list scrolls and its spacer holds the content.\nconst viewportRef = {\n get value() {\n return props.items ? (listRef.value?.el() ?? null) : plainViewport.value\n },\n}\nconst contentRef = {\n get value() {\n return props.items\n ? (viewportRef.value?.firstElementChild as HTMLElement | null | undefined)\n : plainContent.value\n },\n}\n\nconst atBottom = ref(true)\nwatch(atBottom, (value) => emit('atBottomChange', value))\n\n// Following is a decision of the reader: scrolling up turns it off,\n// reaching the bottom turns it on again. Growing content alone never\n// changes it.\nlet following = true\nlet lastTop = 0\nlet atTop = false\nconst touch = useTouchScroll()\nconst plainContentStyle = computed(() => {\n const offset = !props.items ? touch.pendingShift(plainViewport.value) : 0\n return offset ? { transform: `translateY(${-offset}px)` } : undefined\n})\n\nfunction logicalTopOf(el: HTMLElement) {\n return Math.max(0, scrollPositionOf(el).top + touch.pendingShift(el))\n}\n\nfunction distanceToBottom(el: HTMLElement) {\n return el.scrollHeight - (el.scrollTop + touch.pendingShift(el)) - el.clientHeight\n}\n\nconst isTop = (el: HTMLElement) => logicalTopOf(el) <= 0 && el.scrollHeight > el.clientHeight\n\nfunction onScroll() {\n const el = viewportRef.value\n if (!el) return\n const top = el.scrollTop + touch.pendingShift(el)\n const near = distanceToBottom(el) <= props.threshold\n if (near) following = true\n else if (top < lastTop) following = false\n lastTop = top\n atBottom.value = near\n if (!isTop(el)) {\n atTop = false\n setTopAnchor(el, undefined)\n } else if (!atTop) touch.whenSettled(reachTop)\n}\n\n// Earlier messages loaded on top keep what is in view where it was. On iOS\n// the top is reached while the content still bounces; a position written\n// then is dropped, so `topReached` waits until the scroll is over.\nfunction reachTop() {\n const el = viewportRef.value\n if (!el || atTop || !isTop(el)) return\n atTop = true\n // the virtual list keeps its own first item in place\n if (!props.items) setTopAnchor(el, anchorOf())\n emit('topReached')\n}\n\n/** The first message, and how far it is from the top of the messages. */\nlet topAnchor: { node: Element; y: number } | undefined\n/** Kept by hand while it lasts, so the browser's own anchoring can't add to it. */\nfunction setTopAnchor(el: HTMLElement, anchor: typeof topAnchor) {\n topAnchor = anchor\n el.style.overflowAnchor = anchor ? 'none' : ''\n}\n\nconst offsetOf = (node: Element, content: Element) =>\n node.getBoundingClientRect().top - content.getBoundingClientRect().top\n\nfunction anchorOf() {\n const content = contentRef.value\n const node = content?.firstElementChild\n return content && node ? { node, y: offsetOf(node, content) } : undefined\n}\n\nfunction keepTopAnchor() {\n const content = contentRef.value\n if (!content || !topAnchor?.node.isConnected) return\n const y = offsetOf(topAnchor.node, content)\n const shift = y - topAnchor.y\n if (Math.abs(shift) < 1) return\n topAnchor.y = y\n const el = viewportRef.value\n // a move iOS drops during a touch scroll is made once it is over\n if (el) touch.shiftScroll(el, shift)\n}\n\nfunction onWheel(event: WheelEvent) {\n // a wheel turn upwards stops following at once, even mid smooth-scroll\n if (event.deltaY < 0) following = false\n}\n\nfunction scrollToBottom(behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth') {\n const el = viewportRef.value\n if (!el) return\n touch.clearShift(el)\n following = true\n el.scrollTo?.({ top: el.scrollHeight, behavior })\n if (!el.scrollTo) el.scrollTop = el.scrollHeight\n}\n\nfunction follow() {\n const el = viewportRef.value\n if (el && !props.items) keepTopAnchor()\n if (!el || !props.autoScroll || !following) {\n if (el) atBottom.value = distanceToBottom(el) <= props.threshold\n return\n }\n touch.clearShift(el)\n el.scrollTop = el.scrollHeight\n lastTop = el.scrollTop\n atBottom.value = true\n}\n\nlet observer: ResizeObserver | undefined\nonMounted(() => {\n follow()\n if (typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(follow)\n observeContent()\n if (viewportRef.value) observer.observe(viewportRef.value)\n})\nonBeforeUnmount(() => {\n observer?.disconnect()\n touch.clearShift(plainViewport.value)\n})\n\n// A virtual list draws its content only once it has items.\nlet observed: HTMLElement | null | undefined\nfunction observeContent() {\n const content = contentRef.value\n if (!observer || content === observed) return\n if (observed) observer.unobserve(observed)\n observed = content\n if (content) observer.observe(content)\n}\nwatch(() => props.items?.length, observeContent, { flush: 'post' })\nwatch(\n () => props.bottomInset,\n () => void nextTick(follow),\n)\n\n// Jump straight to the message, by key or by element alike: a virtual list\n// only knows where an item is once it is rendered, so it cannot glide there.\nfunction scrollToMessage(\n target: ChatListTarget | null | undefined,\n align: VirtualListAlign = 'center',\n) {\n // nothing there, e.g. the ref of a message no longer shown: like a key not found\n if (target == null) return\n if (isTarget(target)) {\n const el = viewportRef.value\n const node = elementOf(target)\n if (!el || !node || !el.contains(node)) return\n const pending = touch.pendingShift(el)\n const box = el.getBoundingClientRect()\n const item = node.getBoundingClientRect()\n // Content is visually shifted by `translateY(-pending)` while a dropped\n // touch shift is pending, so add `pending` back to recover layout offset.\n const top = item.top - box.top + el.scrollTop + pending\n const bottomInset = Number.parseFloat(getComputedStyle(el).scrollPaddingBlockEnd) || 0\n const visibleHeight = Math.max(0, el.clientHeight - bottomInset)\n const offsets = { start: top, end: top + item.height - visibleHeight }\n let to = top - (visibleHeight - item.height) / 2\n if (align === 'start') to = offsets.start\n else if (align === 'end') to = offsets.end\n else if (align === 'nearest')\n to =\n item.top < box.top\n ? offsets.start\n : item.bottom > box.bottom - bottomInset\n ? offsets.end\n : el.scrollTop + pending\n // the reader asked to look elsewhere: new content must not pull them away\n following = false\n touch.clearShift(el)\n el.scrollTop = Math.max(0, to)\n return\n }\n if (!props.items) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouChatList: `scrollToMessage` takes a key only with `items`; with the default slot, pass the message’s element or component.',\n )\n return\n }\n const index = props.items.findIndex(\n (item, at) => virtualItemKey(props.itemKey, item, at) === target,\n )\n if (index < 0) return\n following = false\n listRef.value?.scrollToIndex(index, align)\n}\n\ndefineExpose<ChatListExpose>({\n get viewport() {\n return viewportRef.value\n },\n scrollToBottom,\n scrollToMessage,\n get atBottom() {\n return atBottom.value\n },\n})\n</script>\n\n<template>\n <div\n :class=\"[\n ns.b(),\n ns.is('at-bottom', atBottom),\n ns.is('virtual', !!items),\n ns.is('bottom-fade', bottomFade),\n ]\"\n :style=\"rootStyle\"\n >\n <DouVirtualList\n v-if=\"items\"\n ref=\"list\"\n :class=\"ns.e('viewport')\"\n :items=\"items\"\n :item-key=\"itemKey\"\n :estimate-size=\"estimateSize\"\n role=\"log\"\n :aria-label=\"t('chat.messages')\"\n @scroll=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <template #default=\"{ item, index }\">\n <slot name=\"item\" :item=\"item\" :index=\"index\" />\n </template>\n </DouVirtualList>\n <div\n v-else\n ref=\"viewport\"\n :class=\"ns.e('viewport')\"\n role=\"log\"\n tabindex=\"0\"\n :aria-label=\"t('chat.messages')\"\n @scroll.passive=\"onScroll\"\n @wheel.passive=\"onWheel\"\n >\n <div ref=\"content\" :class=\"ns.e('content')\" :style=\"plainContentStyle\"><slot /></div>\n </div>\n <Transition name=\"dou-chat-list-button\">\n <div v-if=\"showScrollButton && !atBottom\" :class=\"ns.e('scroll')\">\n <slot name=\"button\" :scroll-to-bottom=\"() => scrollToBottom()\">\n <button\n type=\"button\"\n :class=\"ns.e('scroll-button')\"\n :aria-label=\"t('chat.scrollToBottom')\"\n @click=\"scrollToBottom()\"\n >\n <ArrowDownIcon />\n </button>\n </slot>\n </div>\n </Transition>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-message.js","names":[],"sources":["../../../src/components/chat-message/chat-message.ts"],"sourcesContent":["import type { ChatArtifactKind, ChatArtifactStatus } from '../chat-artifact/chat-artifact'\nimport type { ChatAttachment } from '../chat-attachments/chat-attachments'\nimport type {\n ChatConfirmDecision,\n ChatConfirmStatus,\n ChatConfirmTone,\n} from '../chat-confirm/chat-confirm'\nimport type { ChatPlanItem } from '../chat-plan/chat-plan'\nimport type { ChatQuestionOption, ChatQuestionStatus } from '../chat-question/chat-question'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport type { ChatStep } from '../chat-steps/chat-steps'\nimport type { ChatToolCallStatus } from '../chat-tool-call/chat-tool-call'\nimport type { MarkdownProps, MarkdownSlots } from '../markdown/markdown'\n\n/** Options for the Markdown of text and reasoning parts. */\nexport type ChatMessageMarkdown = Pick<\n MarkdownProps,\n 'smooth' | 'speed' | 'caret' | 'linkTarget' | 'sanitizeUrl'\n>\n\n/** Who wrote the message. */\nexport type ChatMessageSender = 'user' | 'assistant' | 'system'\n\n/** When the bar of actions over a message shows. */\nexport type ChatMessageActionsVisible = 'always' | 'hover'\n\n/** One kind of reaction on a message, e.g. 👍 from three people. */\nexport interface ChatMessageReaction {\n /** The emoji, or any key the app knows the reaction by; shown as is unless the `reaction` slot renders it. */\n emoji: string\n /** How many reacted this way. A reaction at 0 is not shown. */\n count: number\n /** The person reacted this way too; pressing it again takes theirs back. */\n reacted?: boolean\n /** More about it, e.g. who reacted; read out and shown on hover after the emoji and count. */\n label?: string\n}\n\nexport interface ChatTextPart {\n type: 'text'\n text: string\n /** More text is still coming. */\n streaming?: boolean\n}\nexport interface ChatReasoningPart {\n type: 'reasoning'\n text: string\n thinking?: boolean\n /** Seconds it took. */\n duration?: number\n}\nexport interface ChatToolPart {\n type: 'tool'\n name?: string\n title?: string\n status?: ChatToolCallStatus\n input?: unknown\n output?: unknown\n live?: boolean\n}\nexport interface ChatStepsPart {\n type: 'steps'\n items: ChatStep[]\n live?: boolean\n title?: string\n}\nexport interface ChatPlanPart {\n type: 'plan'\n items: ChatPlanItem[]\n title?: string\n showHeader?: boolean\n collapsible?: boolean\n live?: boolean\n}\nexport interface ChatSourcesPart {\n type: 'sources'\n items: ChatSource[]\n}\nexport interface ChatFilesPart {\n type: 'files'\n files: ChatAttachment[]\n}\nexport interface ChatArtifactPart {\n type: 'artifact'\n /** Handed back with `artifact`, to tell artifacts apart. */\n id?: string | number\n title: string\n kind?: ChatArtifactKind\n /** Below the title. While running it shimmers; left out, the line reads \"Generating\". */\n description?: string\n status?: ChatArtifactStatus\n active?: boolean\n}\nexport interface ChatConfirmPart {\n type: 'confirm'\n /** Handed back with `confirm`, to tell requests apart. */\n id?: string | number\n title: string\n description?: string\n status?: ChatConfirmStatus\n allowAlways?: boolean\n tone?: ChatConfirmTone\n /** Shown as monospace detail, e.g. the command to run or a diff. */\n detail?: string\n}\nexport interface ChatQuestionPart {\n type: 'question'\n /** Handed back with `question`, to tell questions apart. */\n id?: string | number\n title: string\n description?: string\n options: ChatQuestionOption[]\n status?: ChatQuestionStatus\n /** The `value` of the option chosen. */\n answer?: string | number\n}\n/** Any other part; render it with the `part` slot. */\nexport interface ChatCustomPart {\n type: string\n [key: string]: unknown\n}\n\nexport type ChatMessagePart =\n | ChatTextPart\n | ChatReasoningPart\n | ChatToolPart\n | ChatStepsPart\n | ChatPlanPart\n | ChatSourcesPart\n | ChatFilesPart\n | ChatArtifactPart\n | ChatConfirmPart\n | ChatQuestionPart\n\nexport interface ChatMessageProps {\n sender?: ChatMessageSender\n /**\n * What the message is made of, in order: text, reasoning, tool calls,\n * steps, a plan, sources, files, artifacts, confirmations and questions may follow\n * one another in any order.\n */\n parts?: (ChatMessagePart | ChatCustomPart)[]\n /** Shorthand for a message of one text part. */\n content?: string\n /**\n * Render text and reasoning parts as Markdown, streaming included. `[1]`\n * in the text becomes a citation of the message's sources parts. An\n * object turns it on with options for the Markdown component, such as\n * `sanitizeUrl`. Set it for every message in the ConfigProvider's\n * `defaults`.\n */\n markdown?: boolean | ChatMessageMarkdown\n /** No part has arrived yet: show the waiting dots, like ChatBubble's. */\n loading?: boolean\n /**\n * When the bar of actions over the top right corner shows: `'always'`,\n * or `'hover'` while the pointer is over the message, focus is inside,\n * or after a tap on it on a touch screen. Buttons from the `actions`\n * slot follow along. Defaults to `'hover'`.\n */\n actionsVisible?: ChatMessageActionsVisible\n /** Show a copy button among the actions, copying the text parts. */\n copyable?: boolean\n /** Offer an edit button on the person's own messages; saving emits `edit`. */\n editable?: boolean\n /** How many versions of this message there are, e.g. after regenerating. Two or more show a switcher. */\n versions?: number\n /** Which version is shown, from 1. Bound with `v-model:version`. */\n version?: number\n /**\n * Mark this message with a ring in the primary color that hugs the\n * bubble, e.g. after a search jumped to it. It stays while set and fades\n * once turned off (at once with reduced motion): turn it off after a\n * moment. Pair it with ChatList's `scrollToMessage`.\n */\n highlighted?: boolean\n /**\n * The reactions under the message, each with how many reacted and\n * whether the person did; one entry per emoji. Pressing one emits `react`; the app adds or\n * takes back the person's reaction itself.\n */\n reactions?: ChatMessageReaction[]\n /**\n * Let the person press `reactions` and add new ones. Turn it off to only\n * show them, e.g. on their own messages or in an archived conversation:\n * the chips look the same and keep the hover text, but cannot be pressed,\n * and there is no add-reaction button even with a `reaction-picker` slot.\n * Defaults to `true`.\n */\n reactable?: boolean\n}\n\nexport interface ChatMessageEmits {\n 'update:version': [version: number]\n /** An edited message was saved, with its new text. */\n edit: [text: string]\n /** A confirmation part was answered. */\n confirm: [part: ChatConfirmPart, decision: ChatConfirmDecision]\n /** An artifact part was pressed. */\n artifact: [part: ChatArtifactPart]\n /** An option of a question part was pressed, with its `value` and the option itself. */\n question: [part: ChatQuestionPart, value: string | number, option: ChatQuestionOption]\n /**\n * A reaction was pressed, or picked in the `reaction-picker` slot: add\n * the person's reaction, or take it back if `reacted` was on. `reaction`\n * is the entry of `reactions` with that emoji, if there is one.\n */\n react: [emoji: string, reaction: ChatMessageReaction | undefined]\n}\n\nexport interface ChatMessageSlots {\n /**\n * Renders a text part by hand, in place of plain text or `markdown`.\n * `text` is what has been revealed so far; `part.text` is all of it.\n * `sources` are the message's sources, for citations.\n */\n text?: (props: {\n part: ChatTextPart\n text: string\n index: number\n sources: ChatSource[]\n }) => unknown\n /** Renders parts of a type the message does not know. */\n part?: (props: { part: ChatCustomPart; index: number }) => unknown\n /** Buttons after the built-in actions, e.g. regenerate or feedback. */\n actions?: () => unknown\n /**\n * Content that follows the last word of the last text part on the same\n * line, e.g. an \"edited\" mark. Unlike `actions` it always shows, whatever\n * `actionsVisible` is. Without a text part it takes a line after the parts,\n * once `loading` is off.\n */\n trailing?: () => unknown\n /**\n * The panel opened by the add-reaction button, e.g. a row of common\n * emoji. Without it there is no add button. `react(emoji)` emits `react`\n * and closes the panel; `close` closes it without reacting.\n */\n 'reaction-picker'?: (props: { react: (emoji: string) => void; close: () => void }) => unknown\n /** Renders the emoji of a reaction, e.g. a custom image for an app's own key. */\n reaction?: (props: { reaction: ChatMessageReaction }) => unknown\n /** Replaces all parts, for a message laid out by hand. */\n default?: () => unknown\n}\n\n/**\n * The Markdown component's slots, with a `markdown-` prefix, for text\n * rendered with `markdown`: `markdown-code`, `markdown-container-tip`, ...\n */\nexport type ChatMessageMarkdownSlots = {\n [K in Exclude<keyof MarkdownSlots, 'trailing'> as `markdown-${K & string}`]: MarkdownSlots[K]\n}\n\n/** The text of a message, for copying: its text parts, one paragraph each. */\nexport function messageText(parts: readonly { type: string; text?: unknown }[]): string {\n return parts\n .filter((part) => part.type === 'text' && typeof part.text === 'string')\n .map((part) => part.text as string)\n .join('\\n\\n')\n}\n"],"mappings":";;AA8PA,SAAgB,YAAY,OAA4D;CACtF,OAAO,MACJ,QAAQ,SAAS,KAAK,SAAS,UAAU,OAAO,KAAK,SAAS,QAAQ,CAAC,CACvE,KAAK,SAAS,KAAK,IAAc,CAAC,CAClC,KAAK,MAAM;AAChB"}
|
|
1
|
+
{"version":3,"file":"chat-message.js","names":[],"sources":["../../../src/components/chat-message/chat-message.ts"],"sourcesContent":["import type { ChatArtifactKind, ChatArtifactStatus } from '../chat-artifact/chat-artifact'\nimport type { ChatAttachment } from '../chat-attachments/chat-attachments'\nimport type {\n ChatConfirmDecision,\n ChatConfirmStatus,\n ChatConfirmTone,\n} from '../chat-confirm/chat-confirm'\nimport type { ChatPlanItem } from '../chat-plan/chat-plan'\nimport type { ChatQuestionOption, ChatQuestionStatus } from '../chat-question/chat-question'\nimport type { ChatSource } from '../chat-sources/chat-sources'\nimport type { ChatStep } from '../chat-steps/chat-steps'\nimport type { ChatToolCallStatus } from '../chat-tool-call/chat-tool-call'\nimport type { MarkdownProps, MarkdownSlots } from '../markdown/markdown'\n\n/** Options for the Markdown of text and reasoning parts. */\nexport type ChatMessageMarkdown = Pick<\n MarkdownProps,\n 'smooth' | 'speed' | 'caret' | 'linkTarget' | 'sanitizeUrl'\n>\n\n/** Who wrote the message. */\nexport type ChatMessageSender = 'user' | 'assistant' | 'system'\n\n/** Delivery state of a user message, shown beside the bottom-left corner of its bubble. */\nexport type ChatMessageStatus = 'sending' | 'sent' | 'error'\n\n/** When the bar of actions over a message shows. */\nexport type ChatMessageActionsVisible = 'always' | 'hover'\n\n/** One kind of reaction on a message, e.g. 👍 from three people. */\nexport interface ChatMessageReaction {\n /** The emoji, or any key the app knows the reaction by; shown as is unless the `reaction` slot renders it. */\n emoji: string\n /** How many reacted this way. A reaction at 0 is not shown. */\n count: number\n /** The person reacted this way too; pressing it again takes theirs back. */\n reacted?: boolean\n /** More about it, e.g. who reacted; read out and shown on hover after the emoji and count. */\n label?: string\n}\n\nexport interface ChatTextPart {\n type: 'text'\n text: string\n /** More text is still coming. */\n streaming?: boolean\n}\nexport interface ChatReasoningPart {\n type: 'reasoning'\n text: string\n thinking?: boolean\n /** Seconds it took. */\n duration?: number\n}\nexport interface ChatToolPart {\n type: 'tool'\n name?: string\n title?: string\n status?: ChatToolCallStatus\n input?: unknown\n output?: unknown\n live?: boolean\n}\nexport interface ChatStepsPart {\n type: 'steps'\n items: ChatStep[]\n live?: boolean\n title?: string\n}\nexport interface ChatPlanPart {\n type: 'plan'\n items: ChatPlanItem[]\n title?: string\n showHeader?: boolean\n collapsible?: boolean\n live?: boolean\n}\nexport interface ChatSourcesPart {\n type: 'sources'\n items: ChatSource[]\n}\nexport interface ChatFilesPart {\n type: 'files'\n files: ChatAttachment[]\n}\nexport interface ChatArtifactPart {\n type: 'artifact'\n /** Handed back with `artifact`, to tell artifacts apart. */\n id?: string | number\n title: string\n kind?: ChatArtifactKind\n /** Below the title. While running it shimmers; left out, the line reads \"Generating\". */\n description?: string\n status?: ChatArtifactStatus\n active?: boolean\n}\nexport interface ChatConfirmPart {\n type: 'confirm'\n /** Handed back with `confirm`, to tell requests apart. */\n id?: string | number\n title: string\n description?: string\n status?: ChatConfirmStatus\n allowAlways?: boolean\n tone?: ChatConfirmTone\n /** Shown as monospace detail, e.g. the command to run or a diff. */\n detail?: string\n}\nexport interface ChatQuestionPart {\n type: 'question'\n /** Handed back with `question`, to tell questions apart. */\n id?: string | number\n title: string\n description?: string\n options: ChatQuestionOption[]\n status?: ChatQuestionStatus\n /** The `value` of the option chosen. */\n answer?: string | number\n}\n/** Any other part; render it with the `part` slot. */\nexport interface ChatCustomPart {\n type: string\n [key: string]: unknown\n}\n\nexport type ChatMessagePart =\n | ChatTextPart\n | ChatReasoningPart\n | ChatToolPart\n | ChatStepsPart\n | ChatPlanPart\n | ChatSourcesPart\n | ChatFilesPart\n | ChatArtifactPart\n | ChatConfirmPart\n | ChatQuestionPart\n\nexport interface ChatMessageProps {\n sender?: ChatMessageSender\n /**\n * What the message is made of, in order: text, reasoning, tool calls,\n * steps, a plan, sources, files, artifacts, confirmations and questions may follow\n * one another in any order.\n */\n parts?: (ChatMessagePart | ChatCustomPart)[]\n /** Shorthand for a message of one text part. */\n content?: string\n /**\n * Render text and reasoning parts as Markdown, streaming included. `[1]`\n * in the text becomes a citation of the message's sources parts. An\n * object turns it on with options for the Markdown component, such as\n * `sanitizeUrl`. Set it for every message in the ConfigProvider's\n * `defaults`.\n */\n markdown?: boolean | ChatMessageMarkdown\n /** No part has arrived yet: show the waiting dots, like ChatBubble's. */\n loading?: boolean\n /**\n * Delivery state of a user message: `'sending'` shows a spinner beside the\n * bottom-left corner of the bubble (or attachments) and hides the actions\n * bar until confirmed; `'error'` shows a failure mark in the same spot;\n * `'sent'` clears it smoothly. Use the `status` slot to draw your own\n * indicator or a retry button.\n */\n status?: ChatMessageStatus\n /**\n * When the bar of actions over the top right corner shows: `'always'`,\n * or `'hover'` while the pointer is over the message, focus is inside,\n * or after a tap on it on a touch screen. Buttons from the `actions`\n * slot follow along. Defaults to `'hover'`.\n */\n actionsVisible?: ChatMessageActionsVisible\n /** Show a copy button among the actions, copying the text parts. */\n copyable?: boolean\n /** Offer an edit button on the person's own messages; saving emits `edit`. */\n editable?: boolean\n /** How many versions of this message there are, e.g. after regenerating. Two or more show a switcher. */\n versions?: number\n /** Which version is shown, from 1. Bound with `v-model:version`. */\n version?: number\n /**\n * Mark this message with a ring in the primary color that hugs the\n * bubble, e.g. after a search jumped to it. It stays while set and fades\n * once turned off (at once with reduced motion): turn it off after a\n * moment. Pair it with ChatList's `scrollToMessage`.\n */\n highlighted?: boolean\n /**\n * The reactions under the message, each with how many reacted and\n * whether the person did; one entry per emoji. Pressing one emits `react`; the app adds or\n * takes back the person's reaction itself.\n */\n reactions?: ChatMessageReaction[]\n /**\n * Let the person press `reactions` and add new ones. Turn it off to only\n * show them, e.g. on their own messages or in an archived conversation:\n * the chips look the same and keep the hover text, but cannot be pressed,\n * and there is no add-reaction button even with a `reaction-picker` slot.\n * Defaults to `true`.\n */\n reactable?: boolean\n}\n\nexport interface ChatMessageEmits {\n 'update:version': [version: number]\n /** An edited message was saved, with its new text. */\n edit: [text: string]\n /** A confirmation part was answered. */\n confirm: [part: ChatConfirmPart, decision: ChatConfirmDecision]\n /** An artifact part was pressed. */\n artifact: [part: ChatArtifactPart]\n /** An option of a question part was pressed, with its `value` and the option itself. */\n question: [part: ChatQuestionPart, value: string | number, option: ChatQuestionOption]\n /**\n * A reaction was pressed, or picked in the `reaction-picker` slot: add\n * the person's reaction, or take it back if `reacted` was on. `reaction`\n * is the entry of `reactions` with that emoji, if there is one.\n */\n react: [emoji: string, reaction: ChatMessageReaction | undefined]\n}\n\nexport interface ChatMessageSlots {\n /**\n * Renders a text part by hand, in place of plain text or `markdown`.\n * `text` is what has been revealed so far; `part.text` is all of it.\n * `sources` are the message's sources, for citations.\n */\n text?: (props: {\n part: ChatTextPart\n text: string\n index: number\n sources: ChatSource[]\n }) => unknown\n /** Renders parts of a type the message does not know. */\n part?: (props: { part: ChatCustomPart; index: number }) => unknown\n /** Buttons after the built-in actions, e.g. regenerate or feedback. */\n actions?: () => unknown\n /**\n * Content shown beside the bottom-left corner of a user message's bubble\n * (or attachments), replacing the built-in indicator for `status`. Useful\n * for a retry button on `'error'` or a custom delivery mark.\n */\n status?: (props: { status: ChatMessageStatus | undefined }) => unknown\n /**\n * Content that follows the last word of the last text part on the same\n * line, e.g. an \"edited\" mark. Unlike `actions` it always shows, whatever\n * `actionsVisible` is. Without a text part it takes a line after the parts,\n * once `loading` is off.\n */\n trailing?: () => unknown\n /**\n * The panel opened by the add-reaction button, e.g. a row of common\n * emoji. Without it there is no add button. `react(emoji)` emits `react`\n * and closes the panel; `close` closes it without reacting.\n */\n 'reaction-picker'?: (props: { react: (emoji: string) => void; close: () => void }) => unknown\n /** Renders the emoji of a reaction, e.g. a custom image for an app's own key. */\n reaction?: (props: { reaction: ChatMessageReaction }) => unknown\n /** Replaces all parts, for a message laid out by hand. */\n default?: () => unknown\n}\n\n/**\n * The Markdown component's slots, with a `markdown-` prefix, for text\n * rendered with `markdown`: `markdown-code`, `markdown-container-tip`, ...\n */\nexport type ChatMessageMarkdownSlots = {\n [K in Exclude<keyof MarkdownSlots, 'trailing'> as `markdown-${K & string}`]: MarkdownSlots[K]\n}\n\n/** The text of a message, for copying: its text parts, one paragraph each. */\nexport function messageText(parts: readonly { type: string; text?: unknown }[]): string {\n return parts\n .filter((part) => part.type === 'text' && typeof part.text === 'string')\n .map((part) => part.text as string)\n .join('\\n\\n')\n}\n"],"mappings":";;AA+QA,SAAgB,YAAY,OAA4D;CACtF,OAAO,MACJ,QAAQ,SAAS,KAAK,SAAS,UAAU,OAAO,KAAK,SAAS,QAAQ,CAAC,CACvE,KAAK,SAAS,KAAK,IAAc,CAAC,CAClC,KAAK,MAAM;AAChB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
2
|
import { useLocale } from "../config-provider/use-config.js";
|
|
3
|
-
import { devWarn } from "../../utils/status-check.js";
|
|
3
|
+
import { devWarn, useStatusCheck } from "../../utils/status-check.js";
|
|
4
4
|
import { isComposing } from "../../utils/keyboard.js";
|
|
5
|
+
import { DouSpinner } from "../spinner/index.js";
|
|
6
|
+
import { SlotNodes, filled } from "../../utils/slot.js";
|
|
5
7
|
import { DouButton } from "../button/index.js";
|
|
6
8
|
import { DouChatArtifact } from "../chat-artifact/index.js";
|
|
7
9
|
import { DouChatAttachments } from "../chat-attachments/index.js";
|
|
@@ -20,20 +22,21 @@ import { DouCopyButton } from "../copy-button/index.js";
|
|
|
20
22
|
import { DouMarkdown } from "../markdown/index.js";
|
|
21
23
|
import { DouStreamText } from "../stream-text/index.js";
|
|
22
24
|
import { messageText } from "./chat-message.js";
|
|
23
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, mergeProps, nextTick, normalizeClass, onBeforeUnmount, openBlock, ref, renderList, renderSlot, toDisplayString, unref, useSlots, useTemplateRef, vModelText, watch, withCtx, withDirectives } from "vue";
|
|
24
|
-
import { ChevronLeftIcon, ChevronRightIcon, EditIcon, SmilePlusIcon } from "@dou-ui/icons";
|
|
25
|
+
import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, mergeProps, nextTick, normalizeClass, onBeforeUnmount, openBlock, ref, renderList, renderSlot, toDisplayString, unref, useSlots, useTemplateRef, vModelText, watch, withCtx, withDirectives } from "vue";
|
|
26
|
+
import { AlertCircleIcon, ChevronLeftIcon, ChevronRightIcon, EditIcon, SmilePlusIcon } from "@dou-ui/icons";
|
|
25
27
|
// src/components/chat-message/chat-message.vue?vue&type=script&setup=true&lang.ts
|
|
26
28
|
var _hoisted_1 = ["aria-busy", "aria-current"];
|
|
27
29
|
var _hoisted_2 = ["aria-label"];
|
|
28
30
|
var _hoisted_3 = ["aria-label"];
|
|
29
31
|
var _hoisted_4 = ["aria-label"];
|
|
30
32
|
var _hoisted_5 = ["aria-label"];
|
|
31
|
-
var _hoisted_6 = [
|
|
33
|
+
var _hoisted_6 = ["aria-label"];
|
|
34
|
+
var _hoisted_7 = [
|
|
32
35
|
"aria-pressed",
|
|
33
36
|
"aria-label",
|
|
34
37
|
"onClick"
|
|
35
38
|
];
|
|
36
|
-
var
|
|
39
|
+
var _hoisted_8 = ["aria-label"];
|
|
37
40
|
var PREFIX = "markdown-";
|
|
38
41
|
var INTERACTIVE = "button, a[href], input, textarea, select, summary, [role=\"button\"]";
|
|
39
42
|
var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
@@ -51,6 +54,7 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
51
54
|
type: Boolean,
|
|
52
55
|
default: false
|
|
53
56
|
},
|
|
57
|
+
status: { default: void 0 },
|
|
54
58
|
actionsVisible: { default: void 0 },
|
|
55
59
|
copyable: {
|
|
56
60
|
type: Boolean,
|
|
@@ -83,6 +87,11 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
83
87
|
const slots = useSlots();
|
|
84
88
|
const ns = useNamespace("chat-message");
|
|
85
89
|
const { t } = useLocale();
|
|
90
|
+
useStatusCheck("DouChatMessage", () => [props.status], [
|
|
91
|
+
"sending",
|
|
92
|
+
"sent",
|
|
93
|
+
"error"
|
|
94
|
+
], { failed: "error" });
|
|
86
95
|
const parts = computed(() => props.parts ?? (props.content === void 0 ? [] : [{
|
|
87
96
|
type: "text",
|
|
88
97
|
text: props.content
|
|
@@ -124,7 +133,7 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
124
133
|
if (next.length === lastSources.length && next.every((s, i) => s === lastSources[i])) return lastSources;
|
|
125
134
|
return lastSources = next;
|
|
126
135
|
});
|
|
127
|
-
const busy = computed(() => props.loading || parts.value.some((part) => {
|
|
136
|
+
const busy = computed(() => props.loading || isUser.value && props.status === "sending" || parts.value.some((part) => {
|
|
128
137
|
const p = part;
|
|
129
138
|
const working = p.status === "running" && p.type !== "artifact" && p.live !== false;
|
|
130
139
|
const live = p.live;
|
|
@@ -239,6 +248,8 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
239
248
|
unref(ns).m(__props.sender),
|
|
240
249
|
unref(ns).m(`actions-${actionsShow.value}`),
|
|
241
250
|
unref(ns).is("loading", __props.loading),
|
|
251
|
+
unref(ns).is("sending", isUser.value && __props.status === "sending"),
|
|
252
|
+
unref(ns).is("error", isUser.value && __props.status === "error"),
|
|
242
253
|
unref(ns).is("editing", editing.value),
|
|
243
254
|
unref(ns).is("highlighted", __props.highlighted),
|
|
244
255
|
unref(ns).is("reacting", pickerOpen.value),
|
|
@@ -428,8 +439,37 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
428
439
|
createElementVNode("i", null, null, -1),
|
|
429
440
|
createElementVNode("i", null, null, -1)
|
|
430
441
|
])], 10, _hoisted_3)) : createCommentVNode("", true)], 2)) : createCommentVNode("", true),
|
|
442
|
+
isUser.value ? (openBlock(true), createElementBlock(Fragment, { key: 3 }, renderList([unref(filled)(slots.status, { status: __props.status })], (customStatus) => {
|
|
443
|
+
return openBlock(), createBlock(Transition, {
|
|
444
|
+
key: 0,
|
|
445
|
+
name: "dou-chat-message-status"
|
|
446
|
+
}, {
|
|
447
|
+
default: withCtx(() => [!editing.value && (customStatus || __props.status === "sending" || __props.status === "error") ? (openBlock(), createElementBlock("div", {
|
|
448
|
+
key: 0,
|
|
449
|
+
class: normalizeClass(unref(ns).e("status"))
|
|
450
|
+
}, [customStatus ? (openBlock(), createBlock(unref(SlotNodes), {
|
|
451
|
+
key: 0,
|
|
452
|
+
nodes: customStatus
|
|
453
|
+
}, null, 8, ["nodes"])) : __props.status === "sending" ? (openBlock(), createBlock(unref(DouSpinner), {
|
|
454
|
+
key: 1,
|
|
455
|
+
size: "sm",
|
|
456
|
+
label: unref(t)("chat.sending")
|
|
457
|
+
}, null, 8, ["label"])) : __props.status === "error" ? (openBlock(), createBlock(unref(DouTooltip), {
|
|
458
|
+
key: 2,
|
|
459
|
+
content: unref(t)("chat.sendError")
|
|
460
|
+
}, {
|
|
461
|
+
default: withCtx(() => [createElementVNode("span", {
|
|
462
|
+
class: normalizeClass(unref(ns).e("status-icon")),
|
|
463
|
+
role: "status",
|
|
464
|
+
"aria-label": unref(t)("chat.sendError")
|
|
465
|
+
}, [createVNode(unref(AlertCircleIcon), { "aria-hidden": "true" })], 10, _hoisted_4)]),
|
|
466
|
+
_: 1
|
|
467
|
+
}, 8, ["content"])) : createCommentVNode("", true)], 2)) : createCommentVNode("", true)]),
|
|
468
|
+
_: 2
|
|
469
|
+
}, 1024);
|
|
470
|
+
}), 128)) : createCommentVNode("", true),
|
|
431
471
|
reactions.value.length && !editing.value ? (openBlock(), createElementBlock("div", {
|
|
432
|
-
key:
|
|
472
|
+
key: 4,
|
|
433
473
|
class: normalizeClass(unref(ns).e("reactions")),
|
|
434
474
|
role: "group",
|
|
435
475
|
"aria-label": unref(t)("chat.reactions")
|
|
@@ -448,14 +488,14 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
448
488
|
unref(ns).is("readonly", true)
|
|
449
489
|
]),
|
|
450
490
|
"aria-label": reactionLabel(reaction)
|
|
451
|
-
}, [createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-emoji")) }, [renderSlot(_ctx.$slots, "reaction", { reaction }, () => [createTextVNode(toDisplayString(reaction.emoji), 1)])], 2), createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-count")) }, toDisplayString(reaction.count), 3)], 10,
|
|
491
|
+
}, [createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-emoji")) }, [renderSlot(_ctx.$slots, "reaction", { reaction }, () => [createTextVNode(toDisplayString(reaction.emoji), 1)])], 2), createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-count")) }, toDisplayString(reaction.count), 3)], 10, _hoisted_6)) : (openBlock(), createElementBlock("button", {
|
|
452
492
|
key: 1,
|
|
453
493
|
type: "button",
|
|
454
494
|
class: normalizeClass([unref(ns).e("reaction"), unref(ns).is("reacted", !!reaction.reacted)]),
|
|
455
495
|
"aria-pressed": !!reaction.reacted,
|
|
456
496
|
"aria-label": reactionLabel(reaction),
|
|
457
497
|
onClick: ($event) => react(reaction.emoji)
|
|
458
|
-
}, [createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-emoji")) }, [renderSlot(_ctx.$slots, "reaction", { reaction }, () => [createTextVNode(toDisplayString(reaction.emoji), 1)])], 2), createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-count")) }, toDisplayString(reaction.count), 3)], 10,
|
|
498
|
+
}, [createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-emoji")) }, [renderSlot(_ctx.$slots, "reaction", { reaction }, () => [createTextVNode(toDisplayString(reaction.emoji), 1)])], 2), createElementVNode("span", { class: normalizeClass(unref(ns).e("reaction-count")) }, toDisplayString(reaction.count), 3)], 10, _hoisted_7))]),
|
|
459
499
|
_: 2
|
|
460
500
|
}, 1032, ["content"]);
|
|
461
501
|
}), 128)), canReact.value ? (openBlock(), createBlock(unref(DouTooltip), {
|
|
@@ -483,9 +523,9 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
483
523
|
_: 3
|
|
484
524
|
}, 8, ["open"])]),
|
|
485
525
|
_: 3
|
|
486
|
-
}, 8, ["content"])) : createCommentVNode("", true)], 10,
|
|
526
|
+
}, 8, ["content"])) : createCommentVNode("", true)], 10, _hoisted_5)) : createCommentVNode("", true),
|
|
487
527
|
showActions.value && !editing.value ? (openBlock(), createElementBlock("div", {
|
|
488
|
-
key:
|
|
528
|
+
key: 5,
|
|
489
529
|
class: normalizeClass(unref(ns).e("toolbar"))
|
|
490
530
|
}, [createElementVNode("div", { class: normalizeClass(unref(ns).e("actions")) }, [
|
|
491
531
|
__props.versions > 1 ? (openBlock(), createElementBlock("div", {
|
|
@@ -515,7 +555,7 @@ var chat_message_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
515
555
|
default: withCtx(() => [createVNode(unref(ChevronRightIcon))]),
|
|
516
556
|
_: 1
|
|
517
557
|
}, 8, ["disabled", "aria-label"])
|
|
518
|
-
], 10,
|
|
558
|
+
], 10, _hoisted_8)) : createCommentVNode("", true),
|
|
519
559
|
__props.copyable && text.value ? (openBlock(), createBlock(unref(DouCopyButton), {
|
|
520
560
|
key: 1,
|
|
521
561
|
size: "sm",
|