@webx-ui/core 0.42.0 → 0.44.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,805 @@
1
+ import { defineComponent as we, openBlock as r, createElementBlock as v, normalizeClass as ye, createElementVNode as H, unref as i, toDisplayString as A, computed as x, useModel as Ue, ref as _, watch as Q, Fragment as $, renderList as J, createBlock as N, withModifiers as de, createCommentVNode as w, withDirectives as fe, withKeys as qe, vModelText as We, createVNode as E, createTextVNode as W, withCtx as ve, normalizeStyle as Ye, vShow as je, mergeModels as he, nextTick as be } from "vue";
2
+ import { Mark as Ge, Node as Ze, Extension as me, createDocument as Qe, getHTMLFromFragment as Je } from "@tiptap/core";
3
+ import { useEditor as Xe, EditorContent as et } from "@tiptap/vue-3";
4
+ import pe from "@tiptap/starter-kit";
5
+ import { TableKit as tt } from "@tiptap/extension-table";
6
+ import lt from "@tiptap/extension-image";
7
+ import nt from "@tiptap/extension-youtube";
8
+ import ot from "@tiptap/extension-file-handler";
9
+ import { PluginKey as at, Plugin as it } from "@tiptap/pm/state";
10
+ import { DecorationSet as ke, Decoration as rt } from "@tiptap/pm/view";
11
+ import { _ as Le, b as st, t as ut, u as ct, a as dt, c as ft, d as vt, L as ht, W as ge, e as bt, f as mt, r as pt, g as kt } from "./index-OwTgLBpg.js";
12
+ const gt = {
13
+ bold: "M7 5h6a3.5 3.5 0 0 1 0 7H7zm0 7h7a3.5 3.5 0 0 1 0 7H7z",
14
+ italic: "M15 5h-5M14 19H9M13.5 5 10.5 19",
15
+ accent: "M5 19 12 5l7 14M8 13h8M18 4.5h.01",
16
+ strike: "M5 12h14M8 8.5A3 3 0 0 1 11 6h2a3 3 0 0 1 3 2.5M16 15.5A3 3 0 0 1 13 18h-2a3 3 0 0 1-3-2.5",
17
+ code: "m9 8-5 4 5 4M15 8l5 4-5 4",
18
+ bulletList: "M9 6h11M9 12h11M9 18h11M4.5 6h.01M4.5 12h.01M4.5 18h.01",
19
+ orderedList: "M10 6h10M10 12h10M10 18h10M4 6h1v4M4 10h2M4 14h2v2H4v2h2",
20
+ blockquote: "M7 15V9h4v6H7l-2 3M15 15V9h4v6h-4l-2 3",
21
+ hr: "M4 12h16",
22
+ link: "M10 13a4 4 0 0 0 5.7.4l2.6-2.6a4 4 0 0 0-5.7-5.7l-1.5 1.5M14 11a4 4 0 0 0-5.7-.4l-2.6 2.6a4 4 0 0 0 5.7 5.7l1.5-1.5",
23
+ table: "M4 6h16v12H4zM4 10h16M10 10v8M4 14h16",
24
+ image: "M4 6h16v12H4zM4 15l4-4 4 4 3-3 5 5M9 9.5h.01",
25
+ youtube: "M3 8.5A2.5 2.5 0 0 1 5.5 6h13A2.5 2.5 0 0 1 21 8.5v7a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 15.5zM10.5 9.5l4 2.5-4 2.5z",
26
+ undo: "M4 9h11a4.5 4.5 0 0 1 0 9h-4M4 9l4-4M4 9l4 4",
27
+ redo: "M20 9H9a4.5 4.5 0 0 0 0 9h4M20 9l-4-4M20 9l-4 4",
28
+ source: "m8 8-4 4 4 4M16 8l4 4-4 4M13.5 5l-3 14",
29
+ rowAfter: "M4 5h16M4 11h16M8 15v6M5 18h6",
30
+ rowBefore: "M4 19h16M4 13h16M8 3v6M5 6h6",
31
+ columnAfter: "M5 4v16M11 4v16M15 8h6M18 5v6",
32
+ columnBefore: "M19 4v16M13 4v16M3 8h6M6 5v6",
33
+ deleteRow: "M4 8h16M4 16h16M9 12h6",
34
+ deleteColumn: "M8 4v16M16 4v16M12 9v6",
35
+ deleteTable: "M5 7h14M9 7V5h6v2M7 7l1 12h8l1-12M10 11v4M14 11v4",
36
+ mergeCells: "M4 6h16v12H4zM12 6v3M12 15v3M9 12h6M9 12l2-2M9 12l2 2",
37
+ token: "M9 4H6v16h3M15 4h3v16h-3",
38
+ check: "m5 13 4 4L19 7",
39
+ close: "M6 6l12 12M18 6 6 18"
40
+ }, Mt = ["title", "aria-label", "aria-pressed", "disabled"], xt = {
41
+ key: 0,
42
+ viewBox: "0 0 24 24",
43
+ fill: "none",
44
+ "aria-hidden": "true"
45
+ }, wt = ["d"], yt = {
46
+ key: 1,
47
+ class: "wx-rich-text__tool-text"
48
+ }, Lt = /* @__PURE__ */ we({
49
+ name: "WxRichTextToolbarButton",
50
+ __name: "ToolbarButton",
51
+ props: {
52
+ icon: { default: void 0 },
53
+ text: { default: void 0 },
54
+ label: {},
55
+ active: { type: Boolean, default: !1 },
56
+ disabled: { type: Boolean, default: !1 }
57
+ },
58
+ emits: ["click"],
59
+ setup(o) {
60
+ return (p, d) => (r(), v("button", {
61
+ type: "button",
62
+ class: ye(["wx-rich-text__tool", { "is-active": o.active }]),
63
+ title: o.label,
64
+ "aria-label": o.label,
65
+ "aria-pressed": o.active,
66
+ disabled: o.disabled,
67
+ onClick: d[0] || (d[0] = (n) => p.$emit("click"))
68
+ }, [
69
+ o.icon ? (r(), v("svg", xt, [
70
+ H("path", {
71
+ d: i(gt)[o.icon],
72
+ stroke: "currentColor",
73
+ "stroke-width": "1.7",
74
+ "stroke-linecap": "round",
75
+ "stroke-linejoin": "round"
76
+ }, null, 8, wt)
77
+ ])) : (r(), v("span", yt, A(o.text), 1))
78
+ ], 10, Mt));
79
+ }
80
+ }), V = /* @__PURE__ */ Le(Lt, [["__scopeId", "data-v-c8c7e143"]]), Tt = /* @__PURE__ */ new Set([
81
+ "ul",
82
+ "ol",
83
+ "li",
84
+ "blockquote",
85
+ "table",
86
+ "colgroup",
87
+ "thead",
88
+ "tbody",
89
+ "tfoot",
90
+ "tr",
91
+ "th",
92
+ "td",
93
+ "div",
94
+ "figure"
95
+ ]), At = /* @__PURE__ */ new Set([
96
+ "p",
97
+ "h1",
98
+ "h2",
99
+ "h3",
100
+ "h4",
101
+ "h5",
102
+ "h6",
103
+ "pre",
104
+ "hr",
105
+ "img",
106
+ "iframe",
107
+ "col",
108
+ "figcaption"
109
+ ]), Ct = /* @__PURE__ */ new Set(["hr", "img", "br", "col", "wbr", "source", "input"]), _t = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)\b[^>]*?(\/?)>/g;
110
+ function Ht(o, p = " ") {
111
+ let d = "", n = 0, h = 0, f = 0, s = 0;
112
+ const m = () => {
113
+ d += `
114
+ ${p.repeat(n)}`;
115
+ };
116
+ for (const I of o.matchAll(_t)) {
117
+ const [y, B, a, R] = I, L = a.toLowerCase();
118
+ if (d += o.slice(s, I.index), s = I.index + y.length, f > 0 && L !== "pre") {
119
+ d += y;
120
+ continue;
121
+ }
122
+ const z = h === 0, F = Ct.has(L) || R === "/";
123
+ if (Tt.has(L) && z) {
124
+ B ? (n = Math.max(0, n - 1), m(), d += y) : (m(), d += y, F || (n += 1));
125
+ continue;
126
+ }
127
+ if (At.has(L)) {
128
+ !B && z && m(), d += y, L === "pre" && (f += B ? -1 : 1), F || (h += B ? -1 : 1), h = Math.max(0, h);
129
+ continue;
130
+ }
131
+ d += y;
132
+ }
133
+ return d += o.slice(s), d.replace(/^\n/, "");
134
+ }
135
+ const Bt = { b: "strong", i: "em", del: "s", strike: "s" };
136
+ function Me(o) {
137
+ const p = /* @__PURE__ */ new Map(), d = (h) => {
138
+ p.set(h, (p.get(h) ?? 0) + 1);
139
+ }, n = document.createElement("template");
140
+ n.innerHTML = o;
141
+ for (const h of n.content.querySelectorAll("*")) {
142
+ const f = h.tagName.toLowerCase(), s = Bt[f] ?? f;
143
+ d(`<${s}>`);
144
+ for (const m of h.getAttributeNames()) d(`${m} on <${s}>`);
145
+ }
146
+ return p;
147
+ }
148
+ function St(o, p) {
149
+ const d = Me(o), n = Me(p), h = [];
150
+ for (const [s, m] of d)
151
+ (n.get(s) ?? 0) < m && h.push(s);
152
+ const f = new Set(h.filter((s) => s.startsWith("<")));
153
+ return h.filter((s) => {
154
+ const m = / on (<[^>]+>)$/.exec(s);
155
+ return !m || !f.has(m[1]);
156
+ });
157
+ }
158
+ const $t = [
159
+ "bold",
160
+ "italic",
161
+ "strike",
162
+ "code",
163
+ "divider",
164
+ "h2",
165
+ "h3",
166
+ "h4",
167
+ "divider",
168
+ "bulletList",
169
+ "orderedList",
170
+ "blockquote",
171
+ "hr",
172
+ "divider",
173
+ "link",
174
+ "table",
175
+ "image",
176
+ "youtube",
177
+ "divider",
178
+ "undo",
179
+ "redo",
180
+ "divider",
181
+ "source"
182
+ ], Et = ["bold", "italic", "accent"], It = [
183
+ "image/png",
184
+ "image/jpeg",
185
+ "image/gif",
186
+ "image/webp",
187
+ "image/svg+xml"
188
+ ], Y = {
189
+ bold: { label: "Bold", icon: "bold" },
190
+ italic: { label: "Italic", icon: "italic" },
191
+ accent: { label: "Accent", icon: "accent" },
192
+ strike: { label: "Strikethrough", icon: "strike" },
193
+ code: { label: "Inline code", icon: "code" },
194
+ h2: { label: "Heading 2", text: "H2" },
195
+ h3: { label: "Heading 3", text: "H3" },
196
+ h4: { label: "Heading 4", text: "H4" },
197
+ bulletList: { label: "Bulleted list", icon: "bulletList" },
198
+ orderedList: { label: "Numbered list", icon: "orderedList" },
199
+ blockquote: { label: "Quote", icon: "blockquote" },
200
+ hr: { label: "Divider", icon: "hr" },
201
+ link: { label: "Link", icon: "link" },
202
+ table: { label: "Table", icon: "table" },
203
+ image: { label: "Image", icon: "image" },
204
+ youtube: { label: "YouTube video", icon: "youtube" },
205
+ undo: { label: "Undo", icon: "undo" },
206
+ redo: { label: "Redo", icon: "redo" },
207
+ source: { label: "HTML source", icon: "source" }
208
+ }, xe = [
209
+ { key: "addRowAfter", label: "Row below", icon: "rowAfter" },
210
+ { key: "addRowBefore", label: "Row above", icon: "rowBefore" },
211
+ { key: "addColumnAfter", label: "Column after", icon: "columnAfter" },
212
+ { key: "addColumnBefore", label: "Column before", icon: "columnBefore" },
213
+ { key: "deleteRow", label: "Delete row", icon: "deleteRow" },
214
+ { key: "deleteColumn", label: "Delete column", icon: "deleteColumn" },
215
+ { key: "mergeOrSplit", label: "Merge or split cells", icon: "mergeCells" },
216
+ { key: "deleteTable", label: "Delete table", icon: "deleteTable" }
217
+ ], Rt = ["aria-label"], zt = {
218
+ key: 0,
219
+ class: "wx-rich-text__divider",
220
+ "aria-hidden": "true"
221
+ }, Dt = {
222
+ key: 1,
223
+ class: "wx-rich-text__uploading"
224
+ }, Ot = {
225
+ key: 2,
226
+ class: "wx-rich-text__toolbar wx-rich-text__toolbar--table"
227
+ }, Nt = ["for"], Vt = ["id", "placeholder"], Ft = {
228
+ key: 4,
229
+ class: "wx-rich-text__prompt wx-rich-text__loss",
230
+ role: "alert"
231
+ }, Pt = { class: "wx-rich-text__loss-text" }, Kt = {
232
+ key: 5,
233
+ class: "wx-rich-text__source"
234
+ }, Ut = {
235
+ key: 0,
236
+ class: "wx-rich-text__placeholder"
237
+ }, qt = ["accept"], Wt = /* @__PURE__ */ we({
238
+ name: "WxRichText",
239
+ inheritAttrs: !1,
240
+ __name: "RichText",
241
+ props: /* @__PURE__ */ he({
242
+ placeholder: { default: void 0 },
243
+ disabled: { type: Boolean, default: void 0 },
244
+ readonly: { type: Boolean, default: !1 },
245
+ size: { default: void 0 },
246
+ status: { default: void 0 },
247
+ id: { default: void 0 },
248
+ ariaLabel: { default: void 0 },
249
+ inline: { type: Boolean, default: !1 },
250
+ minHeight: { default: void 0 },
251
+ tools: { default: void 0 },
252
+ upload: { type: Function, default: void 0 },
253
+ pickImage: { type: Function, default: void 0 },
254
+ accept: { default: () => It },
255
+ labels: { default: void 0 },
256
+ localized: { type: Boolean, default: !1 },
257
+ tokens: { default: void 0 },
258
+ tokensTitle: { default: "Placeholders" },
259
+ tokensLabel: { default: "Insert a placeholder" }
260
+ }, {
261
+ modelValue: { default: "" },
262
+ modelModifiers: {}
263
+ }),
264
+ emits: /* @__PURE__ */ he(["change", "focus", "blur", "uploadError"], ["update:modelValue"]),
265
+ setup(o, { expose: p, emit: d }) {
266
+ const n = o, h = {
267
+ toolbar: "Text formatting",
268
+ linkAddress: "Link address",
269
+ youtubeAddress: "YouTube URL",
270
+ apply: "Apply",
271
+ cancel: "Cancel",
272
+ uploading: "Uploading…",
273
+ sourceLoss: "The editor does not keep this markup and will remove it:",
274
+ sourceDrop: "Remove it",
275
+ sourceKeep: "Keep editing"
276
+ };
277
+ function f(e) {
278
+ const t = n.labels?.[e] ?? h[e];
279
+ return t !== void 0 ? t : e in Y ? Y[e].label : xe.find((l) => l.key === e)?.label ?? e;
280
+ }
281
+ const s = d, m = lt.extend({
282
+ addAttributes() {
283
+ return {
284
+ ...this.parent?.(),
285
+ path: {
286
+ default: null,
287
+ parseHTML: (e) => e.getAttribute("data-wx-path"),
288
+ renderHTML: (e) => e.path === null || e.path === void 0 ? {} : { "data-wx-path": String(e.path) }
289
+ }
290
+ };
291
+ }
292
+ }), I = Ge.create({
293
+ name: "accent",
294
+ parseHTML: () => [{ tag: "span" }],
295
+ renderHTML: () => ["span", 0]
296
+ }), y = Ze.create({ name: "doc", topNode: !0, content: "text*" }), B = me.create({
297
+ name: "wxOneLine",
298
+ addKeyboardShortcuts: () => ({
299
+ Enter: () => !0,
300
+ "Shift-Enter": () => !0,
301
+ "Mod-Enter": () => !0
302
+ })
303
+ }), a = st(() => n.tokens), R = x(() => a.all.value.length > 0), L = new at("wxTokenChips"), z = me.create({
304
+ name: "wxTokenChips",
305
+ addProseMirrorPlugins: () => [
306
+ new it({
307
+ key: L,
308
+ props: {
309
+ decorations: (e) => {
310
+ const t = a.known.value;
311
+ if (t.size === 0) return ke.empty;
312
+ const l = [];
313
+ return e.doc.descendants((c, C) => {
314
+ if (!(!c.isText || !c.text))
315
+ for (const O of ut(c.text, t))
316
+ l.push(
317
+ rt.inline(C + O.from, C + O.to, {
318
+ class: "wx-token",
319
+ "data-token": O.name
320
+ })
321
+ );
322
+ }), ke.create(e.doc, l);
323
+ }
324
+ }
325
+ })
326
+ ]
327
+ });
328
+ function F() {
329
+ return [
330
+ pe.configure({
331
+ document: !1,
332
+ paragraph: !1,
333
+ heading: !1,
334
+ blockquote: !1,
335
+ bulletList: !1,
336
+ orderedList: !1,
337
+ listItem: !1,
338
+ listKeymap: !1,
339
+ codeBlock: !1,
340
+ code: !1,
341
+ horizontalRule: !1,
342
+ hardBreak: !1,
343
+ strike: !1,
344
+ underline: !1,
345
+ link: !1,
346
+ trailingNode: !1,
347
+ gapcursor: !1
348
+ }),
349
+ y,
350
+ I,
351
+ B,
352
+ z
353
+ ];
354
+ }
355
+ function Te() {
356
+ return [
357
+ pe.configure({
358
+ link: {
359
+ openOnClick: !1,
360
+ autolink: !0,
361
+ HTMLAttributes: { rel: "noopener noreferrer nofollow", target: "_blank" }
362
+ }
363
+ }),
364
+ tt.configure({ table: { resizable: !0 } }),
365
+ m.configure({ HTMLAttributes: { class: "wx-rich-text__image" } }),
366
+ nt.configure({ nocookie: !0, width: 640, height: 360 }),
367
+ ot.configure({
368
+ allowedMimeTypes: n.accept,
369
+ onDrop: (e, t, l) => {
370
+ Z(t, l);
371
+ },
372
+ onPaste: (e, t) => {
373
+ Z(t);
374
+ }
375
+ }),
376
+ z
377
+ ];
378
+ }
379
+ const Ae = x(() => n.tools ?? (n.inline ? Et : $t)), X = x(() => n.minHeight ?? (n.inline ? void 0 : "220px")), Ce = Ue(o, "modelValue"), k = ct(n), g = dt(n, Ce), P = x(() => g.on.value ? g.active.value : void 0), D = x(() => g.read(P.value)), K = _(!1), j = _(0), ee = _(null), M = _(null), S = x(() => !k.disabled.value && !n.readonly), b = _(null), T = _(null);
380
+ let G = "";
381
+ function U() {
382
+ const e = u.value;
383
+ return !e || e.isEmpty ? "" : e.getHTML();
384
+ }
385
+ const u = Xe({
386
+ content: D.value,
387
+ editable: S.value,
388
+ extensions: n.inline ? F() : Te(),
389
+ editorProps: {
390
+ // The list's keys first: Enter picks a placeholder rather than splitting the paragraph.
391
+ handleKeyDown: (e, t) => a.keydown(t, ne),
392
+ ...n.inline ? {
393
+ // Pasted lines become one line: the breaks would otherwise vanish between the words
394
+ // and glue the last of one line to the first of the next.
395
+ transformPastedText: (e) => e.replace(/\s*[\r\n]+\s*/g, " ")
396
+ } : {}
397
+ },
398
+ onUpdate: () => {
399
+ const e = U();
400
+ e !== D.value && (g.write(P.value, e), s("change", e), le());
401
+ },
402
+ onSelectionUpdate: () => {
403
+ a.open.value && le();
404
+ },
405
+ onFocus: () => {
406
+ K.value = !0, s("focus");
407
+ },
408
+ onBlur: () => {
409
+ K.value = !1, a.close(), s("blur");
410
+ }
411
+ });
412
+ Q(D, (e) => {
413
+ const t = u.value;
414
+ if (t) {
415
+ if (b.value !== null) {
416
+ e !== b.value && re(e);
417
+ return;
418
+ }
419
+ e !== U() && t.commands.setContent(e, { emitUpdate: !1 });
420
+ }
421
+ }), Q(S, (e) => u.value?.setEditable(e, !1)), Q(a.known, () => {
422
+ const e = u.value;
423
+ e && e.view.dispatch(e.state.tr.setMeta(L, !0));
424
+ });
425
+ const q = _(null), _e = x(() => `${k.id.value}-tokens`);
426
+ function te(e) {
427
+ try {
428
+ const t = u.value?.view.coordsAtPos(e);
429
+ if (t && t.bottom > t.top)
430
+ return mt(pt(t.left, t.top, 0, t.bottom - t.top), q.value);
431
+ } catch {
432
+ }
433
+ return kt(q.value, null);
434
+ }
435
+ function le() {
436
+ const e = u.value;
437
+ if (!e || !R.value || !S.value) return;
438
+ const { selection: t } = e.state, { $from: l } = t;
439
+ if (!t.empty || !l.parent.isTextblock) return a.close();
440
+ const c = l.parent.textBetween(0, l.parentOffset, void 0, "");
441
+ a.suggest(
442
+ c,
443
+ l.pos,
444
+ () => te(l.pos - c.length + c.lastIndexOf("["))
445
+ );
446
+ }
447
+ function ne(e, t) {
448
+ const l = u.value;
449
+ l && l.chain().focus().command(({ tr: c }) => (c.insertText(ft(e), t.from, t.to), !0)).run();
450
+ }
451
+ function He() {
452
+ const e = u.value;
453
+ if (!e) return;
454
+ if (a.open.value && a.browsing.value) return a.close();
455
+ const { from: t, to: l } = e.state.selection;
456
+ e.commands.focus(), a.browse({ from: t, to: l }, te(t));
457
+ }
458
+ const Be = x(() => u.value?.isEmpty ?? !0), Se = x(() => u.value?.isActive("table") ?? !1), $e = x(() => [
459
+ "wx-rich-text",
460
+ `wx-rich-text--${k.size.value}`,
461
+ {
462
+ [`wx-rich-text--${k.status.value}`]: k.status.value !== "default",
463
+ "is-focused": K.value,
464
+ "is-disabled": k.disabled.value,
465
+ "is-readonly": n.readonly,
466
+ "is-localized": g.on.value,
467
+ "is-inline": n.inline
468
+ }
469
+ ]);
470
+ function Ee(e) {
471
+ g.active.value = e, be(() => u.value?.commands.focus());
472
+ }
473
+ function oe(e, t) {
474
+ const l = u.value;
475
+ if (!l) return;
476
+ const c = t ?? l.state.selection.anchor;
477
+ l.chain().focus().insertContentAt(c, {
478
+ type: "image",
479
+ attrs: { src: e.url, alt: e.alt, path: e.path ?? null }
480
+ }).run();
481
+ }
482
+ async function Z(e, t) {
483
+ if (n.upload)
484
+ for (const l of e) {
485
+ j.value += 1;
486
+ try {
487
+ oe(await n.upload(l), t);
488
+ } catch (c) {
489
+ s("uploadError", c, l);
490
+ } finally {
491
+ j.value -= 1;
492
+ }
493
+ }
494
+ }
495
+ async function Ie() {
496
+ if (n.pickImage) {
497
+ const e = await n.pickImage();
498
+ e && oe(typeof e == "string" ? { url: e } : e);
499
+ return;
500
+ }
501
+ ee.value?.click();
502
+ }
503
+ function Re(e) {
504
+ const t = e.target, l = Array.from(t.files ?? []);
505
+ t.value = "", Z(l);
506
+ }
507
+ function ae(e) {
508
+ const t = e === "link" ? u.value?.getAttributes("link").href ?? "" : "";
509
+ M.value = { kind: e, value: String(t) };
510
+ }
511
+ function ie() {
512
+ const e = u.value, t = M.value;
513
+ if (!e || !t) return;
514
+ const l = t.value.trim();
515
+ t.kind === "link" ? l ? e.chain().focus().extendMarkRange("link").setLink({ href: l }).run() : e.chain().focus().extendMarkRange("link").unsetLink().run() : l && e.commands.setYoutubeVideo({ src: l }), M.value = null;
516
+ }
517
+ function re(e = U()) {
518
+ M.value = null, T.value = null, G = Ht(e), b.value = G;
519
+ }
520
+ function ze(e) {
521
+ b.value = e, T.value = null, e !== D.value && (g.write(P.value, e), s("change", e));
522
+ }
523
+ function se(e = !1) {
524
+ const t = u.value, l = b.value;
525
+ if (!t || l === null) return;
526
+ const c = l !== G;
527
+ if (c && !e) {
528
+ const O = Qe(l, t.schema), ce = St(l, Je(O.content, t.schema));
529
+ if (ce.length > 0) {
530
+ T.value = ce;
531
+ return;
532
+ }
533
+ }
534
+ T.value = null, b.value = null, c && t.commands.setContent(l, { emitUpdate: !1 });
535
+ const C = U();
536
+ C !== D.value && (g.write(P.value, C), s("change", C)), be(() => t.commands.focus());
537
+ }
538
+ function ue(e) {
539
+ K.value = e, s(e ? "focus" : "blur");
540
+ }
541
+ function De() {
542
+ b.value === null ? re() : se();
543
+ }
544
+ function Oe(e) {
545
+ return e === "source" ? k.disabled.value : !S.value || b.value !== null;
546
+ }
547
+ function Ne(e) {
548
+ return e === "image" ? !!(n.upload || n.pickImage) : !0;
549
+ }
550
+ const Ve = x(() => Ae.value.filter(Ne));
551
+ function Fe(e) {
552
+ if (e === "source") return b.value !== null;
553
+ const t = u.value;
554
+ if (!t) return !1;
555
+ switch (e) {
556
+ case "h2":
557
+ return t.isActive("heading", { level: 2 });
558
+ case "h3":
559
+ return t.isActive("heading", { level: 3 });
560
+ case "h4":
561
+ return t.isActive("heading", { level: 4 });
562
+ default:
563
+ return t.isActive(e);
564
+ }
565
+ }
566
+ function Pe(e) {
567
+ if (e === "source") return De();
568
+ const t = u.value;
569
+ if (!t) return;
570
+ const l = t.chain().focus();
571
+ switch (e) {
572
+ case "bold":
573
+ l.toggleBold().run();
574
+ break;
575
+ case "italic":
576
+ l.toggleItalic().run();
577
+ break;
578
+ case "accent":
579
+ l.toggleMark("accent").run();
580
+ break;
581
+ case "strike":
582
+ l.toggleStrike().run();
583
+ break;
584
+ case "code":
585
+ l.toggleCode().run();
586
+ break;
587
+ case "h2":
588
+ l.toggleHeading({ level: 2 }).run();
589
+ break;
590
+ case "h3":
591
+ l.toggleHeading({ level: 3 }).run();
592
+ break;
593
+ case "h4":
594
+ l.toggleHeading({ level: 4 }).run();
595
+ break;
596
+ case "bulletList":
597
+ l.toggleBulletList().run();
598
+ break;
599
+ case "orderedList":
600
+ l.toggleOrderedList().run();
601
+ break;
602
+ case "blockquote":
603
+ l.toggleBlockquote().run();
604
+ break;
605
+ case "hr":
606
+ l.setHorizontalRule().run();
607
+ break;
608
+ case "undo":
609
+ l.undo().run();
610
+ break;
611
+ case "redo":
612
+ l.redo().run();
613
+ break;
614
+ case "table":
615
+ l.insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run();
616
+ break;
617
+ case "link":
618
+ ae("link");
619
+ break;
620
+ case "youtube":
621
+ ae("youtube");
622
+ break;
623
+ case "image":
624
+ Ie();
625
+ break;
626
+ }
627
+ }
628
+ function Ke(e) {
629
+ const t = u.value;
630
+ if (!t) return;
631
+ t.chain().focus()[e]().run();
632
+ }
633
+ return p({
634
+ editor: u,
635
+ focus: () => u.value?.commands.focus(),
636
+ clear: () => u.value?.commands.clearContent(!0)
637
+ }), (e, t) => (r(), v("div", {
638
+ ref_key: "rootRef",
639
+ ref: q,
640
+ class: ye($e.value)
641
+ }, [
642
+ H("div", {
643
+ class: "wx-rich-text__toolbar",
644
+ role: "toolbar",
645
+ "aria-label": o.ariaLabel ?? f("toolbar")
646
+ }, [
647
+ (r(!0), v($, null, J(Ve.value, (l, c) => (r(), v($, {
648
+ key: `${l}-${c}`
649
+ }, [
650
+ l === "divider" ? (r(), v("span", zt)) : (r(), N(V, {
651
+ key: 1,
652
+ icon: i(Y)[l].icon,
653
+ text: i(Y)[l].text,
654
+ label: f(l),
655
+ active: Fe(l),
656
+ disabled: Oe(l),
657
+ onClick: (C) => Pe(l)
658
+ }, null, 8, ["icon", "text", "label", "active", "disabled", "onClick"]))
659
+ ], 64))), 128)),
660
+ R.value ? (r(), N(V, {
661
+ key: 0,
662
+ class: "wx-rich-text__tokens",
663
+ icon: "token",
664
+ label: o.tokensLabel,
665
+ active: i(a).open.value && i(a).browsing.value,
666
+ disabled: !S.value || b.value !== null,
667
+ onMousedown: t[0] || (t[0] = de(() => {
668
+ }, ["prevent"])),
669
+ onClick: He
670
+ }, null, 8, ["label", "active", "disabled"])) : w("", !0),
671
+ j.value > 0 ? (r(), v("span", Dt, A(f("uploading")), 1)) : w("", !0)
672
+ ], 8, Rt),
673
+ R.value ? (r(), N(vt, {
674
+ key: 0,
675
+ open: i(a).open.value,
676
+ items: i(a).items.value,
677
+ active: i(a).active.value,
678
+ anchor: i(a).anchor.value,
679
+ "list-id": _e.value,
680
+ title: i(a).browsing.value ? o.tokensTitle : void 0,
681
+ owner: q.value,
682
+ onChoose: t[1] || (t[1] = (l) => i(a).choose(l, ne)),
683
+ onHover: t[2] || (t[2] = (l) => i(a).active.value = l),
684
+ onClose: t[3] || (t[3] = (l) => i(a).close())
685
+ }, null, 8, ["open", "items", "active", "anchor", "list-id", "title", "owner"])) : w("", !0),
686
+ i(g).on.value ? (r(), N(ht, {
687
+ key: 1,
688
+ locales: i(g).list.value,
689
+ active: i(g).active.value,
690
+ onChoose: Ee
691
+ }, null, 8, ["locales", "active"])) : w("", !0),
692
+ Se.value && S.value && b.value === null ? (r(), v("div", Ot, [
693
+ (r(!0), v($, null, J(i(xe), (l) => (r(), N(V, {
694
+ key: l.key,
695
+ icon: l.icon,
696
+ label: f(l.key),
697
+ onClick: (c) => Ke(l.key)
698
+ }, null, 8, ["icon", "label", "onClick"]))), 128))
699
+ ])) : w("", !0),
700
+ M.value ? (r(), v("form", {
701
+ key: 3,
702
+ class: "wx-rich-text__prompt",
703
+ onSubmit: de(ie, ["prevent"])
704
+ }, [
705
+ H("label", {
706
+ class: "wx-rich-text__prompt-label",
707
+ for: `${i(k).id.value}-prompt`
708
+ }, A(f(M.value.kind === "link" ? "linkAddress" : "youtubeAddress")), 9, Nt),
709
+ fe(H("input", {
710
+ id: `${i(k).id.value}-prompt`,
711
+ "onUpdate:modelValue": t[4] || (t[4] = (l) => M.value.value = l),
712
+ class: "wx-rich-text__prompt-input",
713
+ type: "url",
714
+ placeholder: M.value.kind === "link" ? "https://example.com" : "https://youtu.be/…",
715
+ onKeydown: t[5] || (t[5] = qe((l) => M.value = null, ["esc"]))
716
+ }, null, 40, Vt), [
717
+ [We, M.value.value]
718
+ ]),
719
+ E(V, {
720
+ icon: "check",
721
+ label: f("apply"),
722
+ onClick: ie
723
+ }, null, 8, ["label"]),
724
+ E(V, {
725
+ icon: "close",
726
+ label: f("cancel"),
727
+ onClick: t[6] || (t[6] = (l) => M.value = null)
728
+ }, null, 8, ["label"])
729
+ ], 32)) : w("", !0),
730
+ T.value ? (r(), v("div", Ft, [
731
+ H("p", Pt, [
732
+ W(A(f("sourceLoss")) + " ", 1),
733
+ (r(!0), v($, null, J(T.value, (l, c) => (r(), v($, { key: l }, [
734
+ H("code", null, A(l), 1),
735
+ c < T.value.length - 1 ? (r(), v($, { key: 0 }, [
736
+ W(", ")
737
+ ], 64)) : w("", !0)
738
+ ], 64))), 128))
739
+ ]),
740
+ E(ge, {
741
+ size: "sm",
742
+ type: "danger",
743
+ variant: "outline",
744
+ onClick: t[7] || (t[7] = (l) => se(!0))
745
+ }, {
746
+ default: ve(() => [
747
+ W(A(f("sourceDrop")), 1)
748
+ ]),
749
+ _: 1
750
+ }),
751
+ E(ge, {
752
+ size: "sm",
753
+ variant: "text",
754
+ onClick: t[8] || (t[8] = (l) => T.value = null)
755
+ }, {
756
+ default: ve(() => [
757
+ W(A(f("sourceKeep")), 1)
758
+ ]),
759
+ _: 1
760
+ })
761
+ ])) : w("", !0),
762
+ b.value !== null ? (r(), v("div", Kt, [
763
+ E(i(bt), {
764
+ "model-value": b.value,
765
+ language: "html",
766
+ "line-wrapping": "",
767
+ "min-height": X.value,
768
+ readonly: o.readonly,
769
+ disabled: i(k).disabled.value,
770
+ "aria-label": f("source"),
771
+ "onUpdate:modelValue": ze,
772
+ onFocus: t[9] || (t[9] = (l) => ue(!0)),
773
+ onBlur: t[10] || (t[10] = (l) => ue(!1))
774
+ }, null, 8, ["model-value", "min-height", "readonly", "disabled", "aria-label"])
775
+ ])) : w("", !0),
776
+ fe(H("div", {
777
+ class: "wx-rich-text__body",
778
+ style: Ye({ minHeight: X.value })
779
+ }, [
780
+ o.placeholder && Be.value ? (r(), v("span", Ut, A(o.placeholder), 1)) : w("", !0),
781
+ E(i(et), {
782
+ editor: i(u),
783
+ class: "wx-rich-text__content",
784
+ "aria-describedby": i(k).describedBy.value
785
+ }, null, 8, ["editor", "aria-describedby"])
786
+ ], 4), [
787
+ [je, b.value === null]
788
+ ]),
789
+ o.upload && !o.pickImage ? (r(), v("input", {
790
+ key: 6,
791
+ ref_key: "fileInput",
792
+ ref: ee,
793
+ class: "wx-rich-text__file",
794
+ type: "file",
795
+ accept: o.accept.join(","),
796
+ multiple: "",
797
+ onChange: Re
798
+ }, null, 40, qt)) : w("", !0)
799
+ ], 2));
800
+ }
801
+ }), ol = /* @__PURE__ */ Le(Wt, [["__scopeId", "data-v-bea63427"]]);
802
+ export {
803
+ ol as default
804
+ };
805
+ //# sourceMappingURL=RichText-Dmaf7-UT.js.map