wi-chat 0.5.0 → 0.5.1
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/mobile-ui/index.cjs +1 -1
- package/dist/mobile-ui/index.js +87 -81
- package/dist/mobile-ui/style.css +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +176 -161
- package/dist/tools/useAutoScroll.d.ts +11 -3
- package/dist/web-ui/index.cjs +1 -1
- package/dist/web-ui/index.js +336 -331
- package/dist/web-ui/style.css +1 -1
- package/package.json +1 -1
package/dist/tools/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import "wi-chat/style.css";
|
|
2
|
-
import { createVNode as
|
|
3
|
-
import { resolveAttachDownloadUrl as
|
|
4
|
-
import { consumeStream as
|
|
5
|
-
import { katex as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
const
|
|
9
|
-
const { langPrefix: t = "language-", imagePreview:
|
|
2
|
+
import { createVNode as j, render as E, defineComponent as I, ref as B, computed as q, onBeforeUnmount as F, openBlock as G, createElementBlock as N, unref as z, watch as J, getCurrentInstance as Z, onUnmounted as V, nextTick as M } from "vue";
|
|
3
|
+
import { resolveAttachDownloadUrl as X } from "wi-chat/parser";
|
|
4
|
+
import { consumeStream as Le } from "wi-chat/parser";
|
|
5
|
+
import { katex as Y } from "@mdit/plugin-katex";
|
|
6
|
+
import D from "highlight.js";
|
|
7
|
+
import A from "markdown-it";
|
|
8
|
+
const C = (e) => new A().utils.escapeHtml(e), $ = (e) => C(e).replace(/"/g, """).replace(/'/g, "'"), K = (e) => !e || e.includes("get_image_full") ? e : e.replace("get_image", "get_image_full"), P = (e) => {
|
|
9
|
+
const { langPrefix: t = "language-", imagePreview: o = !0, showCodeLang: n = !0, imageSrcResolver: d, imageDownload: l = !0, tableDownload: r = !0 } = e, a = '<button type="button" class="wi-md-table-download" title="下载 Excel" aria-label="下载表格为 Excel"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg></button>', i = new A({
|
|
10
10
|
linkify: !0,
|
|
11
11
|
typographer: !0,
|
|
12
12
|
breaks: !0,
|
|
13
13
|
html: !0,
|
|
14
14
|
langPrefix: t,
|
|
15
|
-
highlight: (
|
|
16
|
-
if (u &&
|
|
15
|
+
highlight: (c, u) => {
|
|
16
|
+
if (u && D.getLanguage(u))
|
|
17
17
|
try {
|
|
18
|
-
return
|
|
18
|
+
return D.highlight(c, { language: u }).value;
|
|
19
19
|
} catch {
|
|
20
|
-
return
|
|
20
|
+
return C(c);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return C(c);
|
|
23
23
|
}
|
|
24
|
-
}).use(
|
|
25
|
-
return
|
|
26
|
-
var
|
|
27
|
-
const
|
|
24
|
+
}).use(Y, { delimiters: "dollars" });
|
|
25
|
+
return i.renderer.rules.fence = (c, u, m, b, f) => {
|
|
26
|
+
var v;
|
|
27
|
+
const h = c[u], p = h.info.trim().split(/\s+/)[0].toLowerCase(), y = ((v = m.highlight) == null ? void 0 : v.call(m, h.content, p, "")) || C(h.content);
|
|
28
28
|
return `
|
|
29
29
|
<div class="wi-md-block">
|
|
30
30
|
<div class="wi-md-block-header">
|
|
31
|
-
<div class="wi-md-block-header-left">${
|
|
31
|
+
<div class="wi-md-block-header-left">${n && p ? `<span class="wi-md-lang">${C(p)}</span>` : ""}</div>
|
|
32
32
|
<div class="wi-md-block-header-right">
|
|
33
33
|
<button type="button" class="wi-md-copy" title="复制" aria-label="复制代码">
|
|
34
34
|
<svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Zm5-5C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"/></svg>
|
|
@@ -38,234 +38,249 @@ const y = (e) => new D().utils.escapeHtml(e), C = (e) => y(e).replace(/"/g, "&qu
|
|
|
38
38
|
</button>
|
|
39
39
|
</div>
|
|
40
40
|
</div>
|
|
41
|
-
<pre class="wi-md-code"><code class="${m.langPrefix}${
|
|
41
|
+
<pre class="wi-md-code"><code class="${m.langPrefix}${C(p)}">${y}</code></pre>
|
|
42
42
|
</div>
|
|
43
43
|
`.trim();
|
|
44
|
-
},
|
|
45
|
-
const
|
|
46
|
-
`src="${
|
|
47
|
-
`alt="${
|
|
48
|
-
|
|
44
|
+
}, i.renderer.rules.table_open = () => r ? '<div class="wi-md-table-wrap"><table class="wi-md-table">' : '<table class="wi-md-table">', i.renderer.rules.table_close = () => r ? `</table>${a}</div>` : "</table>", i.renderer.rules.ordered_list_open = (c, u, m, b, f) => (c[u].attrJoin("class", "wi-md-list wi-md-list-ordered"), f.renderToken(c, u, m)), i.renderer.rules.bullet_list_open = (c, u, m, b, f) => (c[u].attrJoin("class", "wi-md-list wi-md-list-bullet"), f.renderToken(c, u, m)), i.renderer.rules.list_item_open = (c, u, m, b, f) => (c[u].attrJoin("class", "wi-md-list-item"), f.renderToken(c, u, m)), i.renderer.rules.image = (c, u, m, b, f) => {
|
|
45
|
+
const h = c[u], p = h.attrGet("src") || "", y = h.attrGet("alt") || h.content || "", k = h.attrGet("title") || "", v = [
|
|
46
|
+
`src="${$(p)}"`,
|
|
47
|
+
`alt="${$(y)}"`,
|
|
48
|
+
k ? `title="${$(k)}"` : ""
|
|
49
49
|
].filter(Boolean).join(" ");
|
|
50
|
-
if (!
|
|
51
|
-
return `<img ${
|
|
52
|
-
const
|
|
53
|
-
return `<span class="wi-md-image-wrap" data-src="${
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
let
|
|
57
|
-
const
|
|
58
|
-
const e = "data-wi-md-scope", t = `wi-md-scope-${++
|
|
50
|
+
if (!o)
|
|
51
|
+
return `<img ${v} />`;
|
|
52
|
+
const S = d ? d(p) : K(p), w = l ? '<span class="wi-md-image-download" title="下载图片" role="button" aria-label="下载图片"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg></span>' : "";
|
|
53
|
+
return `<span class="wi-md-image-wrap" data-src="${$(S)}"><img ${v} loading="lazy" />${w}</span>`;
|
|
54
|
+
}, i;
|
|
55
|
+
}, Q = ".wi-markdown";
|
|
56
|
+
let W = 0;
|
|
57
|
+
const ee = () => {
|
|
58
|
+
const e = "data-wi-md-scope", t = `wi-md-scope-${++W}`;
|
|
59
59
|
return { attr: e, id: t, selector: `[${e}="${t}"]` };
|
|
60
|
-
},
|
|
61
|
-
const l = d.split(";").map((
|
|
62
|
-
return l ? `${
|
|
63
|
-
}),
|
|
64
|
-
const
|
|
65
|
-
let
|
|
66
|
-
const a = /^\s*@scope\b/i.test(
|
|
67
|
-
return
|
|
60
|
+
}, te = /^(background|padding|margin|width|height|min-width|min-height|max-width|max-height|overflow|display|position|inset|top|right|bottom|left|border|box-shadow|flex|gap|justify-content|align-items)/i, oe = (e) => e.replace(/(^|[{};,])(\s*)(?:html|body|:root)(?![\w-])\s*\{([^}]*)\}/gi, (t, o, n, d) => {
|
|
61
|
+
const l = d.split(";").map((r) => r.trim()).filter((r) => r && !te.test(r)).join(";");
|
|
62
|
+
return l ? `${o}${n}:scope{${l}}` : "";
|
|
63
|
+
}), ne = (e, t) => {
|
|
64
|
+
const o = [];
|
|
65
|
+
let n = e.replace(/<style\b([^>]*)>([\s\S]*?)<\/style\s*>/gi, (d, l, r) => {
|
|
66
|
+
const a = /^\s*@scope\b/i.test(r) ? `<style${l}>${r}</style>` : `<style${l}>@scope (${t}) {${oe(r)}}</style>`;
|
|
67
|
+
return o.push(a), `\0wi-md-style-${o.length - 1}\0`;
|
|
68
68
|
});
|
|
69
|
-
return
|
|
69
|
+
return n = n.replace(/<\/?style\b[^>]*>/gi, ""), n = n.replace(/<script\b[^>]*>[\s\S]*?<\/script\s*>/gi, "").replace(/<\/?script\b[^>]*>/gi, ""), n = n.replace(/<link\b[^>]*>/gi, ""), n.replace(/\u0000wi-md-style-(\d+)\u0000/g, (d, l) => o[Number(l)]);
|
|
70
70
|
};
|
|
71
|
-
let
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
return
|
|
71
|
+
let U = null;
|
|
72
|
+
const re = () => (U || (U = P({})), U), le = (e) => (e.langPrefix === void 0 || e.langPrefix === "language-") && (e.imagePreview === void 0 || e.imagePreview) && (e.showCodeLang === void 0 || e.showCodeLang) && (e.imageDownload === void 0 || e.imageDownload) && (e.tableDownload === void 0 || e.tableDownload) && !e.imageSrcResolver, ae = (e, t = {}) => {
|
|
73
|
+
const o = le(t) ? re() : P(t);
|
|
74
|
+
return ne(o.render(e), t.styleScope || Q);
|
|
75
75
|
};
|
|
76
|
-
let
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
document.body.appendChild(l),
|
|
83
|
-
const { ElImageViewer:
|
|
84
|
-
if (
|
|
76
|
+
let _ = null;
|
|
77
|
+
const O = () => {
|
|
78
|
+
_ && (E(null, _), _.remove(), _ = null);
|
|
79
|
+
}, ce = async (e, t, o) => {
|
|
80
|
+
O();
|
|
81
|
+
const n = t && t.length ? t.includes(e) ? t : [e, ...t.filter((i) => i !== e)] : [e], d = Math.max(o ?? n.indexOf(e), 0), l = document.createElement("div");
|
|
82
|
+
document.body.appendChild(l), _ = l;
|
|
83
|
+
const { ElImageViewer: r } = await import("element-plus");
|
|
84
|
+
if (_ !== l)
|
|
85
85
|
return;
|
|
86
|
-
const a =
|
|
87
|
-
urlList:
|
|
88
|
-
initialIndex: Math.min(d,
|
|
89
|
-
onClose:
|
|
86
|
+
const a = j(r, {
|
|
87
|
+
urlList: n,
|
|
88
|
+
initialIndex: Math.min(d, n.length - 1),
|
|
89
|
+
onClose: O,
|
|
90
90
|
hideOnClickModal: !0,
|
|
91
91
|
teleported: !0
|
|
92
92
|
});
|
|
93
93
|
E(a, l);
|
|
94
|
-
},
|
|
94
|
+
}, se = (e) => {
|
|
95
95
|
fetch(e).then((t) => t.blob()).then((t) => {
|
|
96
96
|
var d;
|
|
97
|
-
const
|
|
98
|
-
|
|
97
|
+
const o = URL.createObjectURL(t), n = document.createElement("a");
|
|
98
|
+
n.href = o, n.download = ((d = e.split("/").pop()) == null ? void 0 : d.split("?")[0]) || "image", document.body.appendChild(n), n.click(), document.body.removeChild(n), URL.revokeObjectURL(o);
|
|
99
99
|
}).catch(() => {
|
|
100
100
|
const t = document.createElement("a");
|
|
101
101
|
t.href = e, t.download = "", t.target = "_blank", document.body.appendChild(t), t.click(), document.body.removeChild(t);
|
|
102
102
|
});
|
|
103
|
-
},
|
|
103
|
+
}, ie = async (e, t) => {
|
|
104
104
|
try {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
const l =
|
|
108
|
-
|
|
109
|
-
} catch (
|
|
110
|
-
console.error("[downloadTableAsExcel] 表格导出 Excel 失败:",
|
|
105
|
+
const o = await import("xlsx"), n = o.utils.table_to_sheet(e), d = o.utils.book_new();
|
|
106
|
+
o.utils.book_append_sheet(d, n, "查询结果");
|
|
107
|
+
const l = o.write(d, { bookType: "xlsx", type: "array" }), r = new Blob([l], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }), a = URL.createObjectURL(r), i = document.createElement("a");
|
|
108
|
+
i.href = a, i.download = `${t || "表格"}_${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.xlsx`, document.body.appendChild(i), i.click(), document.body.removeChild(i), URL.revokeObjectURL(a);
|
|
109
|
+
} catch (o) {
|
|
110
|
+
console.error("[downloadTableAsExcel] 表格导出 Excel 失败:", o);
|
|
111
111
|
}
|
|
112
|
-
},
|
|
112
|
+
}, de = ["data-wi-md-scope", "innerHTML"], ke = /* @__PURE__ */ I({
|
|
113
113
|
__name: "MarkdownContent",
|
|
114
114
|
props: {
|
|
115
115
|
source: { default: "" },
|
|
116
116
|
renderOptions: { default: () => ({}) }
|
|
117
117
|
},
|
|
118
118
|
setup(e) {
|
|
119
|
-
const t = e,
|
|
119
|
+
const t = e, o = B(), n = ee(), d = q(() => ae(t.source, { ...t.renderOptions, styleScope: n.selector })), l = async (a, i) => {
|
|
120
120
|
try {
|
|
121
|
-
await navigator.clipboard.writeText(
|
|
121
|
+
await navigator.clipboard.writeText(i);
|
|
122
122
|
} catch {
|
|
123
|
-
const
|
|
124
|
-
|
|
123
|
+
const c = document.createElement("textarea");
|
|
124
|
+
c.value = i, c.style.position = "fixed", c.style.opacity = "0", document.body.appendChild(c), c.select(), document.execCommand("copy"), c.remove();
|
|
125
125
|
}
|
|
126
126
|
a.classList.add("wi-md-copied"), window.setTimeout(() => a.classList.remove("wi-md-copied"), 1500);
|
|
127
|
-
},
|
|
128
|
-
var
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
127
|
+
}, r = (a) => {
|
|
128
|
+
var h, p, y, k, v, S;
|
|
129
|
+
const i = a.target, c = i.closest(".wi-md-copy");
|
|
130
|
+
if (c) {
|
|
131
131
|
a.preventDefault();
|
|
132
|
-
const
|
|
133
|
-
l(
|
|
132
|
+
const w = ((p = (h = c.closest(".wi-md-block")) == null ? void 0 : h.querySelector(".wi-md-code code")) == null ? void 0 : p.textContent) || "";
|
|
133
|
+
l(c, w);
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
const u =
|
|
136
|
+
const u = i.closest(".wi-md-toggle");
|
|
137
137
|
if (u) {
|
|
138
|
-
a.preventDefault(), (
|
|
138
|
+
a.preventDefault(), (y = u.closest(".wi-md-block")) == null || y.classList.toggle("wi-md-collapsed");
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
-
const m =
|
|
141
|
+
const m = i.closest(".wi-md-image-download");
|
|
142
142
|
if (m) {
|
|
143
143
|
a.preventDefault(), a.stopPropagation();
|
|
144
|
-
const
|
|
145
|
-
|
|
144
|
+
const w = (k = m.closest(".wi-md-image-wrap")) == null ? void 0 : k.dataset.src;
|
|
145
|
+
w && se(w);
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
148
|
+
const b = i.closest(".wi-md-table-download");
|
|
149
|
+
if (b) {
|
|
150
150
|
a.preventDefault(), a.stopPropagation();
|
|
151
|
-
const
|
|
152
|
-
|
|
151
|
+
const w = (v = b.closest(".wi-md-table-wrap")) == null ? void 0 : v.querySelector("table");
|
|
152
|
+
w && ie(w);
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
155
|
+
const f = i.closest(".wi-md-image-wrap img");
|
|
156
|
+
if (f) {
|
|
157
157
|
a.preventDefault();
|
|
158
|
-
const
|
|
159
|
-
if (!
|
|
158
|
+
const w = f.closest(".wi-md-image-wrap"), x = (w == null ? void 0 : w.dataset.src) || f.src || "";
|
|
159
|
+
if (!x)
|
|
160
160
|
return;
|
|
161
|
-
const L = Array.from(((
|
|
162
|
-
var
|
|
163
|
-
return
|
|
161
|
+
const L = Array.from(((S = o.value) == null ? void 0 : S.querySelectorAll(".wi-md-image-wrap")) ?? []).map((T) => {
|
|
162
|
+
var s;
|
|
163
|
+
return T.dataset.src || ((s = T.querySelector("img")) == null ? void 0 : s.getAttribute("src")) || "";
|
|
164
164
|
}).filter(Boolean);
|
|
165
|
-
|
|
165
|
+
ce(x, L.length > 1 ? L : void 0, L.indexOf(x));
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
return
|
|
168
|
+
return F(O), (a, i) => (G(), N("div", {
|
|
169
169
|
ref_key: "rootEl",
|
|
170
|
-
ref:
|
|
170
|
+
ref: o,
|
|
171
171
|
class: "wi-markdown",
|
|
172
|
-
"data-wi-md-scope":
|
|
172
|
+
"data-wi-md-scope": z(n).id,
|
|
173
173
|
innerHTML: d.value,
|
|
174
|
-
onClick:
|
|
175
|
-
}, null, 8,
|
|
174
|
+
onClick: r
|
|
175
|
+
}, null, 8, de));
|
|
176
176
|
}
|
|
177
|
-
}),
|
|
178
|
-
await
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
177
|
+
}), ue = 48, me = 48, pe = async () => {
|
|
178
|
+
await M(), await new Promise((e) => requestAnimationFrame(() => e()));
|
|
179
|
+
}, we = (e) => {
|
|
180
|
+
typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : setTimeout(e, 0);
|
|
181
|
+
}, Se = (e) => {
|
|
182
|
+
const t = B(!1), o = B(!0);
|
|
183
|
+
let n, d, l, r = !1, a = 0, i, c = { preserveScroll: !0 }, u = !1, m = !1;
|
|
184
|
+
const b = (s) => s.scrollHeight - s.scrollTop - s.clientHeight <= ue, f = (s) => s.scrollTop <= me, h = (s) => {
|
|
185
|
+
const g = e.value;
|
|
186
|
+
if (!g)
|
|
185
187
|
return;
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
const R = g.scrollHeight > a;
|
|
189
|
+
a = g.scrollHeight, s && R && o.value && (g.scrollTop = g.scrollHeight);
|
|
190
|
+
const H = b(g);
|
|
191
|
+
o.value = H, t.value = !H;
|
|
192
|
+
}, p = () => h(!1), y = () => {
|
|
193
|
+
r || (r = !0, we(() => {
|
|
194
|
+
r = !1, h(!0);
|
|
195
|
+
}));
|
|
196
|
+
}, k = () => {
|
|
197
|
+
n == null || n(), n = void 0, d == null || d.disconnect(), d = void 0, l == null || l.disconnect(), l = void 0;
|
|
192
198
|
}, v = async () => {
|
|
193
|
-
|
|
199
|
+
await pe();
|
|
200
|
+
const s = e.value;
|
|
201
|
+
s && (s.scrollTop = s.scrollHeight, a = s.scrollHeight, o.value = !0, t.value = !1);
|
|
202
|
+
}, S = async () => {
|
|
203
|
+
if (!o.value) {
|
|
194
204
|
t.value = !0;
|
|
195
205
|
return;
|
|
196
206
|
}
|
|
197
|
-
await
|
|
198
|
-
},
|
|
199
|
-
const
|
|
207
|
+
await v();
|
|
208
|
+
}, w = () => {
|
|
209
|
+
const s = e.value;
|
|
210
|
+
s && (s.scrollTop = 0), a = 0, o.value = !0, t.value = !1;
|
|
211
|
+
}, x = async (s) => {
|
|
212
|
+
const g = e.value, R = g ? g.scrollHeight : 0;
|
|
200
213
|
try {
|
|
201
|
-
await
|
|
214
|
+
await s();
|
|
202
215
|
} finally {
|
|
203
|
-
await
|
|
216
|
+
await M(), e.value && R && (e.value.scrollTop += e.value.scrollHeight - R, a = e.value.scrollHeight);
|
|
204
217
|
}
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
},
|
|
208
|
-
const
|
|
209
|
-
if (!
|
|
218
|
+
}, L = (s, g = { preserveScroll: !0 }) => {
|
|
219
|
+
i = s, c = g;
|
|
220
|
+
}, T = async () => {
|
|
221
|
+
const s = e.value;
|
|
222
|
+
if (!s || (p(), !i || u))
|
|
210
223
|
return;
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
|
|
224
|
+
const g = f(s);
|
|
225
|
+
if (g && !m) {
|
|
226
|
+
m = !0, u = !0;
|
|
214
227
|
try {
|
|
215
|
-
(
|
|
228
|
+
(c == null ? void 0 : c.preserveScroll) !== !1 ? await x(i) : await i();
|
|
216
229
|
} finally {
|
|
217
|
-
|
|
230
|
+
u = !1, f(s) || (m = !1);
|
|
218
231
|
}
|
|
219
232
|
} else
|
|
220
|
-
|
|
233
|
+
g || (m = !1);
|
|
221
234
|
};
|
|
222
|
-
return
|
|
235
|
+
return J(
|
|
223
236
|
e,
|
|
224
|
-
(
|
|
225
|
-
|
|
237
|
+
(s) => {
|
|
238
|
+
k(), s && (s.addEventListener("scroll", T, { passive: !0 }), n = () => s.removeEventListener("scroll", T), typeof MutationObserver < "u" && (d = new MutationObserver(y), d.observe(s, { childList: !0, subtree: !0, characterData: !0 })), typeof ResizeObserver < "u" && (l = new ResizeObserver(y), l.observe(s)), a = 0, p());
|
|
226
239
|
},
|
|
227
240
|
{ immediate: !0, flush: "post" }
|
|
228
|
-
),
|
|
241
|
+
), Z() && V(() => k()), {
|
|
229
242
|
showScrollToBottom: t,
|
|
230
|
-
forceScrollToBottom:
|
|
231
|
-
requestScrollToBottom:
|
|
232
|
-
|
|
233
|
-
|
|
243
|
+
forceScrollToBottom: v,
|
|
244
|
+
requestScrollToBottom: S,
|
|
245
|
+
syncScrollState: p,
|
|
246
|
+
resetScrollState: w,
|
|
247
|
+
onReachTop: L,
|
|
248
|
+
preserveScrollPosition: x
|
|
234
249
|
};
|
|
235
|
-
},
|
|
250
|
+
}, xe = async (e, t = {}) => {
|
|
236
251
|
if (typeof window > "u" || typeof document > "u")
|
|
237
252
|
return;
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
240
|
-
const l = URL.createObjectURL(
|
|
241
|
-
|
|
253
|
+
const o = e.attachContent || {}, n = e.name || o.file_name || "download";
|
|
254
|
+
if (o.raw) {
|
|
255
|
+
const l = URL.createObjectURL(o.raw), r = document.createElement("a");
|
|
256
|
+
r.href = l, r.download = n, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(l);
|
|
242
257
|
return;
|
|
243
258
|
}
|
|
244
|
-
if (!
|
|
259
|
+
if (!o.fileId)
|
|
245
260
|
return;
|
|
246
|
-
const d =
|
|
261
|
+
const d = X(o.fileId, t.baseURL, t.getFileUrl);
|
|
247
262
|
if (d)
|
|
248
263
|
try {
|
|
249
264
|
const l = await fetch(d, { credentials: "include" });
|
|
250
265
|
if (!l.ok)
|
|
251
266
|
throw new Error(`Download failed with status ${l.status}`);
|
|
252
|
-
const
|
|
253
|
-
a.href =
|
|
267
|
+
const r = URL.createObjectURL(await l.blob()), a = document.createElement("a");
|
|
268
|
+
a.href = r, a.download = n, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(r);
|
|
254
269
|
} catch (l) {
|
|
255
270
|
console.error("[downloadAttachment] fetch blob 失败,降级为直接链接触发:", l);
|
|
256
|
-
const
|
|
257
|
-
|
|
271
|
+
const r = document.createElement("a");
|
|
272
|
+
r.href = d, r.download = n, document.body.appendChild(r), r.click(), document.body.removeChild(r);
|
|
258
273
|
}
|
|
259
274
|
};
|
|
260
275
|
export {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
276
|
+
ke as MarkdownContent,
|
|
277
|
+
O as closeImagePreview,
|
|
278
|
+
Le as consumeStream,
|
|
279
|
+
ee as createStyleScope,
|
|
280
|
+
xe as downloadAttachment,
|
|
281
|
+
ie as downloadTableAsExcel,
|
|
282
|
+
ce as openImagePreview,
|
|
283
|
+
ae as renderMarkdown,
|
|
284
|
+
Se as useAutoScroll
|
|
270
285
|
};
|
|
271
286
|
//# sourceMappingURL=index.js.map
|
|
@@ -11,20 +11,28 @@ export interface OnReachTopOptions {
|
|
|
11
11
|
* useAutoScroll 返回值
|
|
12
12
|
*/
|
|
13
13
|
export interface UseAutoScrollReturn {
|
|
14
|
-
/** 是否显示"回到底部"
|
|
14
|
+
/** 是否显示"回到底部"按钮(内容有溢出、且距底部超过阈值时为 true) */
|
|
15
15
|
showScrollToBottom: Ref<boolean>;
|
|
16
16
|
/** 强制滚动到底部:等待渲染完成(nextTick + 一帧)后执行,并重置自动滚动状态为开启 */
|
|
17
17
|
forceScrollToBottom: () => Promise<void>;
|
|
18
18
|
/** 请求滚动到底部:自动滚动开启时执行强制滚动;关闭(用户上翻)时仅点亮"回到底部"按钮,不强滚 */
|
|
19
19
|
requestScrollToBottom: () => Promise<void>;
|
|
20
|
+
/** 立即按当前滚动位置重算状态(内容被整体替换后外部可主动调用;观察器已自动触发,一般不用手调) */
|
|
21
|
+
syncScrollState: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* 重置滚动状态:滚动位置归零、重新开启自动滚动、隐藏按钮。
|
|
24
|
+
* 用于「整表替换」场景(如切换会话时消息被清空),避免上一会话的按钮状态/上翻态滞留。
|
|
25
|
+
*/
|
|
26
|
+
resetScrollState: () => void;
|
|
20
27
|
/** 注册"滚动触顶"回调(触发一次后需离开顶部区域才能再次触发;触发期间防重入),供向上翻页加载更早历史 */
|
|
21
28
|
onReachTop: (cb: () => unknown | Promise<unknown>, options?: OnReachTopOptions) => void;
|
|
22
29
|
/** 在执行前插动作(如加载更早历史)期间保持相对滚动位置:action 前记录 scrollHeight,渲染后补偿 scrollTop,避免视图跳变 */
|
|
23
30
|
preserveScrollPosition: (action: () => unknown | Promise<unknown>) => Promise<void>;
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
33
|
+
* 创建自动滚动控制句柄:监听滚动容器的滚动位置、内容变化与容器尺寸变化,维护
|
|
34
|
+
* "是否贴底 / 是否显示回到底部按钮"状态,并提供触顶回调注册与前插位置补偿;
|
|
35
|
+
* 组件内使用时卸载会自动移除监听与观察器。
|
|
28
36
|
* @param scrollEl 滚动容器元素的 ref(需指向实际发生滚动的元素;ref 值变化时自动重挂监听)
|
|
29
37
|
* @returns 自动滚动控制句柄(成员说明见 UseAutoScrollReturn)
|
|
30
38
|
*/
|