@matechat/core 1.9.0 → 1.10.0-alpha.0

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.
@@ -0,0 +1 @@
1
+ .mc-alert{position:fixed;top:50px;left:50%;transform:translate(-50%);padding:10px;border-radius:var(--devui-border-radius, 2px);transition:all .3s ease-in-out;z-index:10000}.mc-alert--error{background-color:var(--devui-info-bg, #e9edfa)}.mc-alert__header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.mc-alert__title{font-weight:700;font-size:var(--devui-font-size, 12px);color:var(--devui-text, #252b3a)}.mc-alert__close-btn{background:none;border:none;cursor:pointer;font-size:16px;color:var(--devui-aide-text, #71757f)}.mc-alert__close-btn:hover{color:var(--devui-text, #252b3a)}.mc-alert__content{font-size:var(--devui-font-size-sm, 12px);color:var(--devui-aide-text, #71757f)}.mc-alert__message{white-space:pre-wrap;word-wrap:break-word;margin:0;font-family:inherit}.mc-alert-fade-enter-from,.mc-alert-fade-leave-to{opacity:0;transform:translate(-50%) translateY(-100%)}.mc-attachment{display:inline-block;cursor:pointer;position:relative}.mc-attachment .mc-attachment-file{display:none}.mc-attachment .mc-attachment-default-trigger{padding:4px 8px;color:var(--devui-text, #252b3a);font-size:var(--devui-font-size-sm, 12px);cursor:pointer;outline:none;transition:all .3s ease;box-sizing:border-box;border:1px solid transparent}.mc-attachment .mc-attachment-default-trigger:disabled{cursor:not-allowed;color:var(--devui-disabled-text, #cfd0d3)}.mc-attachment-drag-modal{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);padding:20px 40px;background-color:var(--devui-base-bg, #ffffff);border:2px dashed var(--devui-brand, #5e7ce0);border-radius:var(--devui-border-radius, 2px);color:var(--devui-text, #252b3a);font-size:var(--devui-font-size, 12px);font-weight:700;z-index:9999;pointer-events:none}.mc-attachment-drag-modal.is-disabled{border-color:var(--devui-danger, #f66f6a);color:var(--devui-danger, #f66f6a)}
@@ -0,0 +1,387 @@
1
+ import "./index.css";
2
+ import { createApp as $, h as H, defineComponent as P, ref as D, onMounted as R, createBlock as j, openBlock as v, Transition as L, withCtx as W, createElementBlock as F, createCommentVNode as E, normalizeClass as S, createElementVNode as g, toDisplayString as _, computed as Y, onUnmounted as X, mergeModels as M, useModel as G, Fragment as N, unref as u, renderSlot as J, Teleport as K, createTextVNode as V } from "vue";
3
+ import { useMcI18n as q } from "@matechat/core/Locale";
4
+ const Q = {
5
+ uploadOptions: {
6
+ type: Object,
7
+ default: {}
8
+ },
9
+ disabled: {
10
+ type: Boolean,
11
+ default: !1
12
+ },
13
+ accept: {
14
+ type: String,
15
+ default: ""
16
+ },
17
+ maxCount: {
18
+ type: Number,
19
+ default: Number.POSITIVE_INFINITY
20
+ },
21
+ maxSize: {
22
+ type: Number,
23
+ default: Number.POSITIVE_INFINITY
24
+ },
25
+ multiple: {
26
+ type: Boolean,
27
+ default: !0
28
+ },
29
+ draggable: {
30
+ type: Boolean,
31
+ default: !0
32
+ },
33
+ beforeUpload: {
34
+ type: Function,
35
+ default: null
36
+ }
37
+ }, Z = {
38
+ change: (e, s) => e instanceof File && Array.isArray(s),
39
+ success: (e, s, t) => e instanceof File && Array.isArray(t),
40
+ error: (e, s, t) => e instanceof File && Array.isArray(t),
41
+ progress: (e, s) => e instanceof File && Array.isArray(s),
42
+ drop: (e) => Array.isArray(e)
43
+ }, ee = { class: "mc-alert__header" }, te = { class: "mc-alert__title" }, ae = { class: "mc-alert__content" }, ne = { class: "mc-alert__message" };
44
+ function z(e) {
45
+ const s = document.createElement("div");
46
+ document.body.appendChild(s);
47
+ const t = $({
48
+ render() {
49
+ return H(se, {
50
+ ...e,
51
+ // 这个函数将作为 'onClose' prop 传递给 AlertComponent 实例
52
+ onClose: () => {
53
+ t.unmount(), s.parentNode && s.parentNode.removeChild(s);
54
+ }
55
+ });
56
+ }
57
+ });
58
+ t.mount(s);
59
+ }
60
+ const se = /* @__PURE__ */ P({
61
+ __name: "Alert",
62
+ props: {
63
+ type: {
64
+ type: String,
65
+ default: "info"
66
+ },
67
+ title: {
68
+ type: String,
69
+ required: !0
70
+ },
71
+ message: {
72
+ type: String,
73
+ required: !0
74
+ },
75
+ duration: {
76
+ type: Number,
77
+ default: 4500
78
+ },
79
+ // 这个 prop 由上面的 showAlert 函数传入
80
+ onClose: {
81
+ type: Function,
82
+ required: !0
83
+ }
84
+ },
85
+ setup(e) {
86
+ const s = e, t = D(!1);
87
+ R(() => {
88
+ t.value = !0, s.duration > 0 && setTimeout(l, s.duration);
89
+ });
90
+ function l() {
91
+ t.value = !1, setTimeout(() => {
92
+ s.onClose();
93
+ }, 300);
94
+ }
95
+ return (m, f) => (v(), j(L, { name: "mc-alert-fade" }, {
96
+ default: W(() => [
97
+ t.value ? (v(), F(
98
+ "div",
99
+ {
100
+ key: 0,
101
+ class: S(["mc-alert", `mc-alert--${e.type}`])
102
+ },
103
+ [
104
+ g("div", ee, [
105
+ g(
106
+ "span",
107
+ te,
108
+ _(e.title),
109
+ 1
110
+ /* TEXT */
111
+ ),
112
+ g("button", {
113
+ class: "mc-alert__close-btn",
114
+ onClick: l
115
+ }, "✕")
116
+ ]),
117
+ g("div", ae, [
118
+ g(
119
+ "pre",
120
+ ne,
121
+ _(e.message),
122
+ 1
123
+ /* TEXT */
124
+ )
125
+ ])
126
+ ],
127
+ 2
128
+ /* CLASS */
129
+ )) : E("v-if", !0)
130
+ ]),
131
+ _: 1
132
+ /* STABLE */
133
+ }));
134
+ }
135
+ });
136
+ function oe(e) {
137
+ const { file: s, options: t, onProgress: l, onSuccess: m, onError: f } = e, a = new XMLHttpRequest();
138
+ a.upload.onprogress = (i) => {
139
+ if (i.lengthComputable) {
140
+ const h = Math.round(i.loaded * 100 / i.total);
141
+ l(h);
142
+ }
143
+ }, a.onerror = () => {
144
+ f({
145
+ message: "Upload failed due to a network error.",
146
+ status: a.status,
147
+ statusText: a.statusText
148
+ });
149
+ }, a.onload = () => {
150
+ if (a.status >= 200 && a.status < 300) {
151
+ const i = t.responseType === "text" || !a.response ? a.responseText : a.response;
152
+ m(i);
153
+ } else
154
+ f({
155
+ message: `Upload failed with status: ${a.status}`,
156
+ status: a.status,
157
+ statusText: a.statusText,
158
+ response: a.response
159
+ });
160
+ };
161
+ const p = new FormData(), b = t.fileFieldName || "file";
162
+ if (p.append(b, s, s.name), t.additionalParameter)
163
+ for (const i of Object.keys(t.additionalParameter))
164
+ p.append(i, t.additionalParameter[i]);
165
+ if (a.open(t.method || "POST", t.uri, !0), t.withCredentials && (a.withCredentials = !0), t.responseType && (a.responseType = t.responseType), t.headers)
166
+ for (const i of Object.keys(t.headers))
167
+ a.setRequestHeader(i, t.headers[i]);
168
+ if (t.authToken) {
169
+ const i = t.authTokenHeader || "Authorization";
170
+ a.setRequestHeader(i, t.authToken);
171
+ }
172
+ a.send(p);
173
+ }
174
+ let re = Date.now();
175
+ function le(e, s, t, l) {
176
+ const { t: m } = q(), f = D(!1);
177
+ let a = 0;
178
+ const p = Y(() => e.disabled || l.value.length >= e.maxCount), b = (n) => {
179
+ const d = URL.createObjectURL(n);
180
+ return {
181
+ uid: re++,
182
+ name: n.name,
183
+ size: n.size,
184
+ type: n.type,
185
+ status: "uploading",
186
+ percentage: 0,
187
+ url: d,
188
+ thumbUrl: d
189
+ };
190
+ }, i = async (n) => {
191
+ if (n.length === 0) return;
192
+ if (l.value.length + n.length > e.maxCount) {
193
+ z({
194
+ type: "error",
195
+ title: m("Attachment.exceedCountTitle"),
196
+ message: m("Attachment.exceedCountMessage", {
197
+ maxCount: e.maxCount
198
+ })
199
+ });
200
+ return;
201
+ }
202
+ const d = [], c = [];
203
+ for (const o of n) {
204
+ let r = !0;
205
+ if (e.accept && e.accept !== "*") {
206
+ const C = e.accept.split(",").map((y) => y.trim().toLowerCase()), k = o.type.toLowerCase(), B = o.name.toLowerCase();
207
+ C.some((y) => y.endsWith("/*") ? k.startsWith(y.slice(0, -1)) : y.startsWith(".") ? B.endsWith(y) : k === y) || (c.push(
208
+ m("Attachment.unsupportedFileType", { fileName: o.name })
209
+ ), r = !1);
210
+ }
211
+ if (r && o.size / 1024 / 1024 > e.maxSize && (c.push(
212
+ m("Attachment.exceedSizeLimit", {
213
+ fileName: o.name,
214
+ maxSize: e.maxSize
215
+ })
216
+ ), r = !1), r && e.beforeUpload)
217
+ try {
218
+ await Promise.resolve(e.beforeUpload(o)) === !1 && (c.push(
219
+ m("Attachment.uploadRejected", { fileName: o.name })
220
+ ), r = !1);
221
+ } catch (C) {
222
+ const k = C instanceof Error ? C.message : String(C);
223
+ c.push(
224
+ m("Attachment.beforeUploadFailed", {
225
+ fileName: o.name,
226
+ errorMsg: k
227
+ })
228
+ ), r = !1;
229
+ }
230
+ r && d.push(o);
231
+ }
232
+ if (c.length > 0 && z({
233
+ type: "error",
234
+ title: m("Attachment.uploadFailedTitle"),
235
+ message: c.join(`
236
+ `)
237
+ }), d.length !== 0)
238
+ for (const o of d) {
239
+ const r = b(o);
240
+ l.value.push(r), s("change", o, [...l.value]), h(o, r);
241
+ }
242
+ }, h = (n, d) => {
243
+ const c = () => l.value.findIndex((o) => o.uid === d.uid);
244
+ oe({
245
+ file: n,
246
+ options: e.uploadOptions,
247
+ onProgress: (o) => {
248
+ const r = c();
249
+ r > -1 && (l.value[r].percentage = o, s("progress", n, [...l.value]));
250
+ },
251
+ onSuccess: (o) => {
252
+ const r = c();
253
+ r > -1 && (l.value[r].status = "success", l.value[r].response = o, s("success", n, o, [...l.value]));
254
+ },
255
+ onError: (o) => {
256
+ const r = c();
257
+ r > -1 && (l.value[r].status = "uploadError", l.value[r].error = o, s("error", n, o, [...l.value]));
258
+ }
259
+ });
260
+ }, x = (n) => {
261
+ const d = n.target.files;
262
+ d && i(Array.from(d));
263
+ }, A = () => {
264
+ var n;
265
+ p.value || (n = t.value) == null || n.click();
266
+ }, T = (n) => {
267
+ n.preventDefault(), a++, a === 1 && (f.value = !0);
268
+ }, I = (n) => {
269
+ n.preventDefault();
270
+ }, U = (n) => {
271
+ n.preventDefault(), a--, a === 0 && (f.value = !1);
272
+ }, w = (n) => {
273
+ var c;
274
+ if (n.preventDefault(), f.value = !1, a = 0, p.value) return;
275
+ const d = Array.from(((c = n.dataTransfer) == null ? void 0 : c.files) || []);
276
+ d.length > 0 && (s("drop", d), i(d));
277
+ };
278
+ return R(() => {
279
+ e.draggable && (document.body.addEventListener("dragenter", T), document.body.addEventListener("dragover", I), document.body.addEventListener("dragleave", U), document.body.addEventListener("drop", w));
280
+ }), X(() => {
281
+ e.draggable && (document.body.removeEventListener("dragenter", T), document.body.removeEventListener("dragover", I), document.body.removeEventListener("dragleave", U), document.body.removeEventListener("drop", w));
282
+ }), {
283
+ isDragging: f,
284
+ isDisabled: p,
285
+ handleClick: A,
286
+ handleFileChange: x
287
+ };
288
+ }
289
+ const ie = ["disabled"], de = ["accept", "multiple", "disabled"], O = /* @__PURE__ */ P({
290
+ name: "McAttachment",
291
+ __name: "Attachment",
292
+ props: /* @__PURE__ */ M(Q, {
293
+ modelValue: { default: [] },
294
+ modelModifiers: {}
295
+ }),
296
+ emits: /* @__PURE__ */ M(Z, ["update:modelValue"]),
297
+ setup(e, { emit: s }) {
298
+ const t = e, l = s, m = G(e, "modelValue"), { t: f } = q(), a = D(), { handleClick: p, handleFileChange: b, isDragging: i, isDisabled: h } = le(
299
+ t,
300
+ l,
301
+ a,
302
+ m
303
+ );
304
+ return (x, A) => (v(), F(
305
+ N,
306
+ null,
307
+ [
308
+ g(
309
+ "div",
310
+ {
311
+ class: S(["mc-attachment", { "is-disabled": u(h) }]),
312
+ onClick: A[1] || (A[1] = //@ts-ignore
313
+ (...T) => u(p) && u(p)(...T))
314
+ },
315
+ [
316
+ E(" 使用插槽允许用户自定义触发器内容,例如按钮或文本 "),
317
+ J(x.$slots, "default", {}, () => [
318
+ g("button", {
319
+ class: "mc-attachment-default-trigger",
320
+ disabled: u(h)
321
+ }, " + " + _(u(f)("Attachment.attachFile")), 9, ie)
322
+ ]),
323
+ g("input", {
324
+ ref_key: "inputRef",
325
+ ref: a,
326
+ type: "file",
327
+ class: "mc-attachment-file",
328
+ accept: x.accept,
329
+ multiple: x.multiple,
330
+ disabled: u(h),
331
+ onChange: A[0] || (A[0] = //@ts-ignore
332
+ (...T) => u(b) && u(b)(...T))
333
+ }, null, 40, de)
334
+ ],
335
+ 2
336
+ /* CLASS */
337
+ ),
338
+ (v(), j(K, { to: "body" }, [
339
+ u(i) ? (v(), F(
340
+ "div",
341
+ {
342
+ key: 0,
343
+ class: S(["mc-attachment-drag-modal", { "is-disabled": u(h) }])
344
+ },
345
+ [
346
+ u(h) ? (v(), F(
347
+ N,
348
+ { key: 0 },
349
+ [
350
+ V(
351
+ _(u(f)("Attachment.disabledUpload")),
352
+ 1
353
+ /* TEXT */
354
+ )
355
+ ],
356
+ 64
357
+ /* STABLE_FRAGMENT */
358
+ )) : (v(), F(
359
+ N,
360
+ { key: 1 },
361
+ [
362
+ V(
363
+ _(u(f)("Attachment.dragToUpload")),
364
+ 1
365
+ /* TEXT */
366
+ )
367
+ ],
368
+ 64
369
+ /* STABLE_FRAGMENT */
370
+ ))
371
+ ],
372
+ 2
373
+ /* CLASS */
374
+ )) : E("v-if", !0)
375
+ ]))
376
+ ],
377
+ 64
378
+ /* STABLE_FRAGMENT */
379
+ ));
380
+ }
381
+ });
382
+ O.install = (e) => {
383
+ e.component("McAttachment", O);
384
+ };
385
+ export {
386
+ O as McAttachment
387
+ };
@@ -0,0 +1 @@
1
+ .mc-file-list{background-color:var(--devui-base-bg, #ffffff);padding:0 10px}.mc-file-list--context-input{position:relative;padding-bottom:5px}.mc-file-list--context-input .mc-file-list__container{max-height:170px;overflow-y:auto}.mc-file-list--context-input:after{content:"";position:absolute;bottom:0;left:50%;transform:translate(-50%);width:97%;height:1px;background-color:var(--devui-dividing-line, #f2f2f3)}.mc-file-list--context-dialog{padding:0}.mc-file-list--context-dialog .mc-file-list__container{max-width:606px;max-height:none;overflow-y:visible;background-color:var(--devui-global-bg, #f6f6f8);border-radius:var(--devui-border-radius-card, 6px)}.mc-file-list--context-dialog .mc-file-item{border-color:transparent}.mc-file-list--context-dialog .mc-file-item--downloadError,.mc-file-list--context-dialog .mc-file-item--downloading{background-color:var(--devui-base-bg, #ffffff)}.mc-file-list__container{display:flex;padding:2px 0;flex-wrap:wrap}.mc-file-list__container::-webkit-scrollbar{width:4px}.mc-file-list__container::-webkit-scrollbar-track{background:var(--devui-global-bg, #f6f6f8)}.mc-file-list__container::-webkit-scrollbar-thumb{background:var(--devui-disabled-bg, #f5f5f5);border-radius:2px}.mc-file-item{position:relative;width:192px;height:58px;margin:5px;display:flex;align-items:center;padding:4px 8px;border:1px solid var(--devui-line, #d7d8da);transition:all .3s ease;border-radius:var(--devui-border-radius-card, 6px)}.mc-file-item:hover .mc-file-item__actions{opacity:1}.mc-file-item__image-preview{width:36px;height:36px;object-fit:cover;border-radius:var(--devui-border-radius, 2px);cursor:pointer}.mc-file-item--success,.mc-file-item--uploadError,.mc-file-item--downloadError{background-color:var(--devui-base-bg, #ffffff)}.mc-file-item__icon{margin-right:10px;flex-shrink:0;position:relative;display:flex;align-items:center;justify-content:center}.mc-file-item__type-icon{display:inline-block}.mc-file-item__info{flex:1;min-width:0}.mc-file-item__name{font-size:var(--devui-font-size-sm, 12px);color:var(--devui-text, #252b3a);margin-bottom:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mc-file-item__meta{display:flex;align-items:center;font-size:var(--devui-font-size-sm, 12px);color:var(--devui-aide-text, #71757f);gap:8px}.mc-file-item__meta-action{color:var(--devui-link, #526ecc);cursor:pointer}.mc-file-item__size{color:var(--devui-aide-text, #71757f)}.mc-file-item__status--error{color:var(--devui-danger, #f66f6a)}.mc-file-item__progress-overlay{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:105%;height:105%;display:flex;align-items:center;justify-content:center;border-radius:7px;overflow:hidden}.mc-file-item__progress-mask{position:absolute;top:0;left:0;width:100%;height:100%;background-color:#0006}.mc-file-item__wrong-icon{position:relative;z-index:999}.mc-file-item__progress-ring{position:relative;width:17.5px;height:17.5px}.mc-file-item__progress-ring-track,.mc-file-item__progress-ring-circle{fill:transparent;stroke-width:5}.mc-file-item__progress-ring-track{stroke:var(--devui-disabled-bg, #f5f5f5);stroke-opacity:.3}.mc-file-item__progress-ring-circle{stroke:var(--devui-base-bg, #ffffff);stroke-linecap:round;transition:stroke-dashoffset .3s}.mc-file-item__actions{position:absolute;top:-6px;right:-6px;opacity:0;display:flex;align-items:center;justify-content:center;transition:opacity .3s ease}.mc-file-item__action-btn{border:none;background:#c2c2c2;cursor:pointer;border-radius:50%;font-size:8px;width:12px;height:12px;transition:all .3s ease}.mc-file-item__action-btn--remove{color:var(--devui-light-text, #ffffff)}.mc-file-preview__overlay{position:fixed;top:0;left:0;width:100%;height:100%;background-color:#000000b3;display:flex;align-items:center;justify-content:center;z-index:2000}.mc-file-preview__content{max-width:90vw;max-height:90vh;object-fit:contain}.mc-file-preview__iframe{width:80vw;height:90vh;border:none}.mc-file-preview__unsupported{padding:40px 60px;background-color:var(--devui-base-bg, #ffffff);border-radius:var(--devui-border-radius, 2px);color:var(--devui-text, #252b3a);font-size:var(--devui-font-size, 12px)}.mc-file-preview__close-btn{position:absolute;top:40px;right:40px;width:40px;height:40px;border-radius:50%;background:#1e1e1e80;color:#fff;border:none;font-size:20px;cursor:pointer;display:flex;align-items:center;justify-content:center;line-height:1;transition:background-color .2s}.mc-file-preview__close-btn:hover{background:#0009}.mc-file-preview-fade-enter-active,.mc-file-preview-fade-leave-active{transition:opacity .3s ease}.mc-file-preview-fade-enter-from,.mc-file-preview-fade-leave-to{opacity:0}