wds-editor 0.0.0-stage → 1.0.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,2140 @@
1
+ import { TextSelection as Ge, NodeSelection as he, PluginKey as _t, Plugin as kt, EditorState as Wt } from "prosemirror-state";
2
+ import { DecorationSet as Mt, Decoration as xt, EditorView as qt } from "prosemirror-view";
3
+ import { redo as ze, undo as Lt, redoDepth as Gt, undoDepth as jt, history as Vt } from "prosemirror-history";
4
+ import { Schema as St, DOMParser as Kt, DOMSerializer as Yt, Fragment as Et, Slice as At } from "prosemirror-model";
5
+ import { addListNodes as Jt, sinkListItem as Xt, liftListItem as Ct, wrapInList as Qt, splitListItem as Zt } from "prosemirror-schema-list";
6
+ import { tableNodes as en, isInTable as pe, goToNextCell as Re, addRowAfter as Tt, tableEditing as tn, addRowBefore as nn, addColumnBefore as rn, addColumnAfter as on, deleteRow as an, deleteColumn as sn, toggleHeaderRow as ln, toggleHeaderColumn as cn, mergeCells as dn, splitCell as un, deleteTable as hn } from "prosemirror-tables";
7
+ import { inputRules as pn, InputRule as mn, textblockTypeInputRule as tt, wrappingInputRule as Te, undoInputRule as fn } from "prosemirror-inputrules";
8
+ import { keymap as je } from "prosemirror-keymap";
9
+ import { lift as Dt, toggleMark as gn, setBlockType as De, wrapIn as bn, chainCommands as wn, exitCode as yn, baseKeymap as vn } from "prosemirror-commands";
10
+ import { gapCursor as kn } from "prosemirror-gapcursor";
11
+ import { dropCursor as Mn } from "prosemirror-dropcursor";
12
+ const xn = /^(https?:|mailto:|tel:)/i, It = /^[a-z][a-z0-9+.-]*:/i;
13
+ function q(t) {
14
+ if (t == null) return null;
15
+ const e = t.trim();
16
+ if (!e) return null;
17
+ const n = e.replace(/[\u0000- \u007f-\u009f]/g, "");
18
+ return It.test(n) && !xn.test(n) ? null : e;
19
+ }
20
+ function nt(t) {
21
+ const e = t.trim();
22
+ return e ? /^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(e) ? `mailto:${e}` : !It.test(e) && !/^[/#?.]/.test(e) && /^[\w-]+(\.[\w-]+)+/.test(e) ? `https://${e}` : q(e) : null;
23
+ }
24
+ function Ln(t) {
25
+ return t.replace(/<!--[\s\S]*?-->/g, "").replace(/<\/?o:p[^>]*>/gi, "").replace(/<\/?(w|m|v):[^>]*>/gi, "").replace(/<xml[\s\S]*?<\/xml>/gi, "").replace(/<style[\s\S]*?<\/style>/gi, "").replace(/<meta[^>]*>/gi, "").replace(/<link[^>]*>/gi, "");
26
+ }
27
+ const rt = {
28
+ black: "#000000",
29
+ white: "#ffffff",
30
+ red: "#ff0000",
31
+ green: "#008000",
32
+ blue: "#0000ff",
33
+ yellow: "#ffff00",
34
+ orange: "#ffa500",
35
+ purple: "#800080",
36
+ pink: "#ffc0cb",
37
+ gray: "#808080",
38
+ grey: "#808080",
39
+ silver: "#c0c0c0",
40
+ navy: "#000080",
41
+ teal: "#008080",
42
+ maroon: "#800000",
43
+ olive: "#808000",
44
+ lime: "#00ff00",
45
+ aqua: "#00ffff",
46
+ cyan: "#00ffff",
47
+ fuchsia: "#ff00ff",
48
+ magenta: "#ff00ff",
49
+ darkred: "#8b0000",
50
+ darkblue: "#00008b",
51
+ darkgreen: "#006400",
52
+ lightgray: "#d3d3d3",
53
+ lightgrey: "#d3d3d3",
54
+ darkgray: "#a9a9a9",
55
+ darkgrey: "#a9a9a9"
56
+ }, Ie = (t) => Math.max(0, Math.min(255, Math.round(t))).toString(16).padStart(2, "0");
57
+ function oe(t) {
58
+ if (!t) return null;
59
+ const e = t.trim().toLowerCase().replace(/\s*!important$/, "");
60
+ if (rt[e]) return rt[e];
61
+ let n = /^#([0-9a-f]{3})$/.exec(e);
62
+ return n ? "#" + [...n[1]].map((r) => r + r).join("") : (n = /^#([0-9a-f]{6})(ff)?$/.exec(e), n ? "#" + n[1] : (n = /^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(e), n ? n[4] !== void 0 && (n[4].endsWith("%") ? parseFloat(n[4]) / 100 : parseFloat(n[4])) < 1 ? null : "#" + Ie(+n[1]) + Ie(+n[2]) + Ie(+n[3]) : null));
63
+ }
64
+ function ot(t) {
65
+ const e = oe(t);
66
+ return e && e !== "#000000" ? e : null;
67
+ }
68
+ function Ne(t) {
69
+ const e = oe(t) ?? oe((t ?? "").split(/\s+(?![^(]*\))/).find((n) => oe(n)));
70
+ return e && e !== "#ffffff" ? e : null;
71
+ }
72
+ const Sn = [
73
+ { color: "#dc2626", name: "colorRed" },
74
+ { color: "#ea580c", name: "colorOrange" },
75
+ { color: "#ca8a04", name: "colorAmber" },
76
+ { color: "#16a34a", name: "colorGreen" },
77
+ { color: "#0d9488", name: "colorTeal" },
78
+ { color: "#2563eb", name: "colorBlue" },
79
+ { color: "#7c3aed", name: "colorPurple" },
80
+ { color: "#db2777", name: "colorPink" },
81
+ { color: "#475569", name: "colorSlate" },
82
+ { color: "#94a3b8", name: "colorGray" }
83
+ ], En = [
84
+ { color: "#fef08a", name: "colorYellow" },
85
+ { color: "#bbf7d0", name: "colorGreen" },
86
+ { color: "#bae6fd", name: "colorBlue" },
87
+ { color: "#fbcfe8", name: "colorPink" },
88
+ { color: "#fed7aa", name: "colorOrange" },
89
+ { color: "#e9d5ff", name: "colorPurple" }
90
+ ], An = ["left", "center", "right", "justify"];
91
+ function it(t) {
92
+ const e = (t.style.textAlign || t.getAttribute("align") || "").toLowerCase();
93
+ return An.includes(e) && e !== "left" ? e : null;
94
+ }
95
+ function at(t) {
96
+ return t ? { style: `text-align: ${t}` } : {};
97
+ }
98
+ const Cn = {
99
+ left: "float: left; margin: 0 1em 1em 0",
100
+ right: "float: right; margin: 0 0 1em 1em",
101
+ center: "display: block; margin-left: auto; margin-right: auto"
102
+ }, Tn = {
103
+ left: "float: left; margin: 0 1em 1em 0",
104
+ right: "float: right; margin: 0 0 1em 1em",
105
+ center: "display: table; margin-left: auto; margin-right: auto"
106
+ };
107
+ function Dn(t) {
108
+ const e = t.style.float || t.getAttribute("align") || "";
109
+ return e === "left" || e === "right" ? e : (t.style.display === "block" || t.style.display === "table") && t.style.marginLeft === "auto" && t.style.marginRight === "auto" ? "center" : null;
110
+ }
111
+ const st = {
112
+ src: {},
113
+ alt: { default: "" },
114
+ title: { default: null },
115
+ width: { default: null },
116
+ height: { default: null },
117
+ align: { default: null }
118
+ };
119
+ function lt(t, e) {
120
+ const n = q(t.getAttribute("src"));
121
+ return n ? {
122
+ src: n,
123
+ alt: t.getAttribute("alt") ?? "",
124
+ title: t.getAttribute("title"),
125
+ width: ct(t.getAttribute("width") ?? t.style.width),
126
+ height: ct(t.getAttribute("height") ?? t.style.height),
127
+ align: Dn(e)
128
+ } : !1;
129
+ }
130
+ function Be(t, e) {
131
+ const { src: n, alt: r, title: o, width: a, height: l, align: d } = t, i = { src: n, alt: r ?? "" };
132
+ o && (i.title = o), a && (i.width = String(a)), a && l && (i.height = String(l));
133
+ const s = e ? Cn[d] : void 0;
134
+ return s && (i.style = s), i;
135
+ }
136
+ function ct(t) {
137
+ const e = /^\s*(\d{1,5})(px)?\s*$/.exec(t ?? "");
138
+ return e ? Number(e[1]) : null;
139
+ }
140
+ const In = {
141
+ doc: { content: "block+" },
142
+ paragraph: {
143
+ content: "inline*",
144
+ group: "block",
145
+ attrs: { align: { default: null } },
146
+ parseDOM: [{ tag: "p", getAttrs: (t) => ({ align: it(t) }) }],
147
+ toDOM: (t) => ["p", at(t.attrs.align), 0]
148
+ },
149
+ heading: {
150
+ content: "inline*",
151
+ group: "block",
152
+ defining: !0,
153
+ attrs: { level: { default: 2 }, align: { default: null } },
154
+ parseDOM: [1, 2, 3, 4, 5, 6].map((t) => ({
155
+ tag: `h${t}`,
156
+ // h5/h6 are folded into h4 so pasted content stays inside the supported range
157
+ getAttrs: (e) => ({ level: Math.min(t, 4), align: it(e) })
158
+ })),
159
+ toDOM: (t) => [`h${t.attrs.level}`, at(t.attrs.align), 0]
160
+ },
161
+ blockquote: {
162
+ content: "block+",
163
+ group: "block",
164
+ defining: !0,
165
+ parseDOM: [{ tag: "blockquote" }],
166
+ toDOM: () => ["blockquote", 0]
167
+ },
168
+ horizontal_rule: {
169
+ group: "block",
170
+ parseDOM: [{ tag: "hr" }],
171
+ toDOM: () => ["hr"]
172
+ },
173
+ code_block: {
174
+ content: "text*",
175
+ marks: "",
176
+ group: "block",
177
+ code: !0,
178
+ defining: !0,
179
+ attrs: { language: { default: null } },
180
+ parseDOM: [
181
+ {
182
+ tag: "pre",
183
+ preserveWhitespace: "full",
184
+ getAttrs: (t) => {
185
+ const e = t.querySelector("code"), n = /language-([\w-]+)/.exec(e?.className ?? "");
186
+ return { language: n ? n[1] : null };
187
+ }
188
+ }
189
+ ],
190
+ toDOM: (t) => [
191
+ "pre",
192
+ ["code", t.attrs.language ? { class: `language-${t.attrs.language}` } : {}, 0]
193
+ ]
194
+ },
195
+ ...en({ tableGroup: "block", cellContent: "block+", cellAttributes: {} }),
196
+ text: { group: "inline" },
197
+ image: {
198
+ inline: !0,
199
+ group: "inline",
200
+ draggable: !0,
201
+ attrs: st,
202
+ parseDOM: [{ tag: "img[src]", getAttrs: (t) => lt(t, t) }],
203
+ toDOM: (t) => ["img", Be(t.attrs, !0)]
204
+ },
205
+ /** Image with a caption: <figure><img><figcaption>…</figcaption></figure>. The caption is the node's content. */
206
+ figure: {
207
+ group: "block",
208
+ content: "inline*",
209
+ marks: "_",
210
+ draggable: !0,
211
+ isolating: !0,
212
+ attrs: st,
213
+ parseDOM: [
214
+ {
215
+ tag: "figure",
216
+ getAttrs: (t) => {
217
+ const e = t.querySelector("img");
218
+ return e ? lt(e, t) : !1;
219
+ },
220
+ contentElement: (t) => t.querySelector("figcaption") ?? document.createElement("figcaption")
221
+ }
222
+ ],
223
+ toDOM: (t) => {
224
+ const e = Tn[t.attrs.align];
225
+ return ["figure", e ? { style: e } : {}, ["img", Be(t.attrs, !1)], ["figcaption", 0]];
226
+ }
227
+ },
228
+ hard_break: {
229
+ inline: !0,
230
+ group: "inline",
231
+ selectable: !1,
232
+ parseDOM: [{ tag: "br" }],
233
+ toDOM: () => ["br"]
234
+ }
235
+ }, Nn = {
236
+ link: {
237
+ attrs: { href: {}, title: { default: null }, target: { default: null } },
238
+ inclusive: !1,
239
+ parseDOM: [
240
+ {
241
+ tag: "a[href]",
242
+ getAttrs: (t) => {
243
+ const e = t, n = q(e.getAttribute("href"));
244
+ return n ? {
245
+ href: n,
246
+ title: e.getAttribute("title"),
247
+ target: e.getAttribute("target") === "_blank" ? "_blank" : null
248
+ } : !1;
249
+ }
250
+ }
251
+ ],
252
+ toDOM: (t) => {
253
+ const e = { href: t.attrs.href };
254
+ return t.attrs.title && (e.title = t.attrs.title), t.attrs.target === "_blank" && (e.target = "_blank", e.rel = "noopener noreferrer"), ["a", e, 0];
255
+ }
256
+ },
257
+ strong: {
258
+ parseDOM: [
259
+ { tag: "strong" },
260
+ // Google Docs wraps everything in <b style="font-weight:normal">
261
+ { tag: "b", getAttrs: (t) => t.style.fontWeight !== "normal" && null },
262
+ { style: "font-weight=400", clearMark: (t) => t.type.name === "strong" },
263
+ { style: "font-weight", getAttrs: (t) => /^(bold(er)?|[5-9]\d{2,})$/.test(t) && null }
264
+ ],
265
+ toDOM: () => ["strong", 0]
266
+ },
267
+ em: {
268
+ parseDOM: [
269
+ { tag: "i" },
270
+ { tag: "em" },
271
+ { style: "font-style=italic" },
272
+ { style: "font-style=normal", clearMark: (t) => t.type.name === "em" }
273
+ ],
274
+ toDOM: () => ["em", 0]
275
+ },
276
+ underline: {
277
+ parseDOM: [{ tag: "u" }, { style: "text-decoration=underline" }, { style: "text-decoration-line=underline" }],
278
+ toDOM: () => ["u", 0]
279
+ },
280
+ strike: {
281
+ parseDOM: [
282
+ { tag: "s" },
283
+ { tag: "del" },
284
+ { tag: "strike" },
285
+ { style: "text-decoration=line-through" },
286
+ { style: "text-decoration-line=line-through" }
287
+ ],
288
+ toDOM: () => ["s", 0]
289
+ },
290
+ /** <span style="color: #rrggbb">. Only span / font colors are read, so pasted links keep their own styling. */
291
+ textColor: {
292
+ attrs: { color: {} },
293
+ parseDOM: [
294
+ {
295
+ tag: "span",
296
+ getAttrs: (t) => {
297
+ const e = ot(t.style.color);
298
+ return e ? { color: e } : !1;
299
+ }
300
+ },
301
+ {
302
+ tag: "font[color]",
303
+ getAttrs: (t) => {
304
+ const e = ot(t.getAttribute("color"));
305
+ return e ? { color: e } : !1;
306
+ }
307
+ }
308
+ ],
309
+ toDOM: (t) => ["span", { style: `color: ${t.attrs.color}` }, 0]
310
+ },
311
+ /** <mark style="background-color: #rrggbb">. */
312
+ highlight: {
313
+ attrs: { color: { default: "#fef08a" } },
314
+ parseDOM: [
315
+ {
316
+ tag: "mark",
317
+ getAttrs: (t) => ({ color: Ne(t.style.backgroundColor) ?? "#fef08a" })
318
+ },
319
+ {
320
+ style: "background-color",
321
+ getAttrs: (t) => {
322
+ const e = Ne(t);
323
+ return e ? { color: e } : !1;
324
+ }
325
+ },
326
+ {
327
+ style: "background",
328
+ getAttrs: (t) => {
329
+ const e = Ne(t);
330
+ return e ? { color: e } : !1;
331
+ }
332
+ }
333
+ ],
334
+ toDOM: (t) => ["mark", { style: `background-color: ${oe(t.attrs.color) ?? "#fef08a"}` }, 0]
335
+ },
336
+ code: {
337
+ parseDOM: [{ tag: "code" }],
338
+ toDOM: () => ["code", 0]
339
+ }
340
+ }, dt = new St({ nodes: In, marks: Nn }), p = new St({
341
+ nodes: Jt(dt.spec.nodes, "paragraph block*", "block"),
342
+ marks: dt.spec.marks
343
+ }), On = Yt.fromSchema(p), Hn = Kt.fromSchema(p);
344
+ function ge(t) {
345
+ const e = new window.DOMParser().parseFromString(`<!doctype html><body>${t}`, "text/html");
346
+ return Hn.parse(e.body);
347
+ }
348
+ function be(t) {
349
+ if (Nt(t)) return "";
350
+ const e = document.createElement("div");
351
+ return e.append(On.serializeFragment(t.content)), e.querySelectorAll("[style]").forEach((n) => n.setAttribute("style", zn(n.getAttribute("style") ?? ""))), e.innerHTML;
352
+ }
353
+ const $n = (t, e, n, r) => "#" + [e, n, r].map((o) => (+o).toString(16).padStart(2, "0")).join("");
354
+ function zn(t) {
355
+ return t.split(";").map((e) => e.trim()).filter(Boolean).map(
356
+ (e) => e.replace(/rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/g, $n).replace(/(^|[\s:])0px(?![\w.])/g, (n, r) => `${r}0`).replace(/\s*:\s*/, ": ")
357
+ ).join("; ");
358
+ }
359
+ function Nt(t) {
360
+ const e = t.firstChild;
361
+ return t.childCount === 1 && !!e && e.type === p.nodes.paragraph && e.content.size === 0 && !e.attrs.align;
362
+ }
363
+ const Rn = "p|h[1-6]|blockquote|pre|ul|ol|li|table|thead|tbody|tr|figure";
364
+ function ut(t) {
365
+ const e = t.replace(new RegExp(`(<\\/(?:${Rn})>|<hr>)`, "g"), `$1
366
+ `).replace(new RegExp("(<(?:ul|ol|blockquote)(?:\\s[^>]*)?>)", "g"), `$1
367
+ `).split(`
368
+ `).map((r) => r.trim()).filter(Boolean);
369
+ let n = 0;
370
+ return e.map((r) => {
371
+ /^<\/(ul|ol|blockquote)>/.test(r) && (n = Math.max(0, n - 1));
372
+ const o = " ".repeat(n) + r;
373
+ return /^<(ul|ol|blockquote)(\s[^>]*)?>$/.test(r) ? n++ : /<\/(ul|ol|blockquote)>$/.test(r) && !/^<\/(ul|ol|blockquote)>/.test(r) && (n = Math.max(0, n - 1)), o;
374
+ }).join(`
375
+ `);
376
+ }
377
+ function de(t, e) {
378
+ const { from: n, $from: r, to: o, empty: a } = t.selection;
379
+ return a ? !!e.isInSet(t.storedMarks || r.marks()) : t.doc.rangeHasMark(n, o, e);
380
+ }
381
+ function Bn(t) {
382
+ const e = t.selection.$from.parent;
383
+ return e.type === p.nodes.paragraph ? "paragraph" : e.type === p.nodes.code_block ? "codeBlock" : e.type === p.nodes.heading ? `heading${e.attrs.level}` : null;
384
+ }
385
+ function Fn(t) {
386
+ return t === "paragraph" ? De(p.nodes.paragraph) : t === "codeBlock" ? De(p.nodes.code_block) : De(p.nodes.heading, { level: Number(t.slice(-1)) });
387
+ }
388
+ const _ = (t) => gn(p.marks[t]);
389
+ function Ot(t, e) {
390
+ const { $from: n } = t.selection;
391
+ for (let r = n.depth; r > 0; r--) if (n.node(r).type === e) return !0;
392
+ return !1;
393
+ }
394
+ function ht(t) {
395
+ const { $from: e } = t.selection;
396
+ for (let n = e.depth; n > 0; n--) {
397
+ const r = e.node(n).type;
398
+ if (r === p.nodes.bullet_list || r === p.nodes.ordered_list) return r;
399
+ }
400
+ return null;
401
+ }
402
+ function pt(t) {
403
+ return (e, n, r) => {
404
+ const { $from: o } = e.selection;
405
+ for (let a = o.depth; a > 0; a--) {
406
+ const l = o.node(a);
407
+ if (l.type === p.nodes.bullet_list || l.type === p.nodes.ordered_list)
408
+ return l.type === t ? Ct(p.nodes.list_item)(e, n, r) : (n && n(e.tr.setNodeMarkup(o.before(a), t)), !0);
409
+ }
410
+ return Qt(t)(e, n, r);
411
+ };
412
+ }
413
+ const Fe = Xt(p.nodes.list_item), Ue = (t, e, n) => Ct(p.nodes.list_item)(t, e, n) || Dt(t, e);
414
+ function Un() {
415
+ return (t, e) => Ot(t, p.nodes.blockquote) ? Dt(t, e) : bn(p.nodes.blockquote)(t, e);
416
+ }
417
+ function j(t) {
418
+ return (e, n) => {
419
+ const r = t === "left" ? null : t, { from: o, to: a } = e.selection, l = e.tr;
420
+ let d = !1;
421
+ return e.doc.nodesBetween(o, a, (i, s) => i.type === p.nodes.paragraph || i.type === p.nodes.heading ? (d = !0, i.attrs.align !== r && l.setNodeMarkup(s, void 0, { ...i.attrs, align: r }), !1) : !0), d ? (n && n(l), !0) : !1;
422
+ };
423
+ }
424
+ function we(t) {
425
+ return t.selection.$from.parent.attrs.align ?? "left";
426
+ }
427
+ const Pn = (t, e) => {
428
+ const n = p.nodes.horizontal_rule;
429
+ if (!e) return !0;
430
+ const r = t.tr.replaceSelectionWith(n.create()), o = r.selection.$from;
431
+ return !o.nodeAfter && o.parent.type === p.nodes.doc && r.insert(o.pos, p.nodes.paragraph.create()), e(r.scrollIntoView()), !0;
432
+ }, _n = (t, e) => {
433
+ const { from: n, to: r, empty: o } = t.selection, a = t.tr;
434
+ if (o)
435
+ a.setStoredMarks([]);
436
+ else
437
+ for (const l of Object.values(p.marks)) l !== p.marks.link && a.removeMark(n, r, l);
438
+ return t.doc.nodesBetween(n, r, (l, d) => l.isTextblock && l.type !== p.nodes.paragraph ? (a.setBlockType(d, d + l.nodeSize, p.nodes.paragraph), !1) : (l.type === p.nodes.paragraph && l.attrs.align && a.setNodeMarkup(d, void 0, { align: null }), !0)), e && e(a), !0;
439
+ };
440
+ function Pe(t) {
441
+ const e = p.marks.link, { $from: n, from: r, to: o, empty: a } = t.selection;
442
+ if (!a) {
443
+ let u = null;
444
+ return t.doc.nodesBetween(r, o, (m, g) => {
445
+ const v = e.isInSet(m.marks);
446
+ v && !u && (u = { from: Math.max(g, r), to: Math.min(g + m.nodeSize, o), ...v.attrs });
447
+ }), u;
448
+ }
449
+ const l = e.isInSet(n.marks()) ?? e.isInSet(n.nodeBefore?.marks ?? []);
450
+ if (!l) return null;
451
+ const d = n.start(), i = [];
452
+ let s = 0;
453
+ n.parent.forEach((u) => {
454
+ const m = d + s, g = m + u.nodeSize;
455
+ if (l.isInSet(u.marks)) {
456
+ const v = i[i.length - 1];
457
+ v && v[1] === m ? v[1] = g : i.push([m, g]);
458
+ }
459
+ s += u.nodeSize;
460
+ });
461
+ const c = i.find(([u, m]) => u <= n.pos && n.pos <= m);
462
+ return c ? { from: c[0], to: c[1], ...l.attrs } : null;
463
+ }
464
+ function _e(t) {
465
+ const e = t.selection;
466
+ return e instanceof he && (e.node.type === p.nodes.image || e.node.type === p.nodes.figure) ? { pos: e.from, attrs: e.node.attrs, figure: e.node.type === p.nodes.figure, node: e.node } : null;
467
+ }
468
+ function mt(t, e, n) {
469
+ const r = p.nodes.figure.create(n), o = t.doc.resolve(e), a = o.parent;
470
+ a.type === p.nodes.paragraph && a.childCount === 1 ? t.replaceWith(o.before(), o.after(), r) : t.replaceRangeWith(e, e + 1, r);
471
+ let l = -1;
472
+ return t.doc.descendants((d, i) => l >= 0 ? !1 : (d.type === p.nodes.figure && d.attrs.src === n.src && d.content.size === 0 && (l = i), !0)), l >= 0 && t.setSelection(Ge.create(t.doc, l + 1)), t;
473
+ }
474
+ function Wn(t, e, n, r) {
475
+ const o = p.nodes.image.create(r), a = [p.nodes.paragraph.create(null, o)];
476
+ return n.content.size && a.push(p.nodes.paragraph.create(null, n.content)), t.replaceWith(e, e + n.nodeSize, Et.from(a)), t.setSelection(he.create(t.doc, e + 1));
477
+ }
478
+ function qn(t, e, n = !0) {
479
+ const r = p.nodes, o = (a) => r.table_row.create(null, Array.from({ length: e }, () => a.createAndFill()));
480
+ return r.table.create(null, Array.from({ length: t }, (a, l) => o(n && l === 0 ? r.table_header : r.table_cell)));
481
+ }
482
+ function Gn(t, e) {
483
+ return (n, r) => {
484
+ if (pe(n)) return !1;
485
+ if (!r) return !0;
486
+ const o = qn(t, e), a = n.tr, l = n.selection.$from;
487
+ l.parent.type === p.nodes.paragraph && l.parent.content.size === 0 && l.depth === 1 ? a.replaceWith(l.before(), l.after(), o) : a.replaceSelectionWith(o);
488
+ let i = -1;
489
+ if (a.doc.descendants((s, c) => i >= 0 ? !1 : (s === o && (i = c), i < 0 && s.type !== p.nodes.table)), i >= 0) {
490
+ const s = i + a.doc.nodeAt(i).nodeSize;
491
+ s >= a.doc.content.size && a.insert(s, p.nodes.paragraph.create()), a.setSelection(Ge.create(a.doc, i + 4));
492
+ }
493
+ return r(a.scrollIntoView()), !0;
494
+ };
495
+ }
496
+ const jn = (t, e, n) => pe(t) ? Re(1)(t, e) || !e || !n ? !0 : (Tt(t, e), Re(1)(n.state, e)) : !1, Vn = (t, e) => pe(t) && Re(-1)(t, e);
497
+ function We(t, e) {
498
+ const n = p.marks[e], { from: r, to: o, empty: a, $from: l } = t.selection;
499
+ if (a) return n.isInSet(t.storedMarks || l.marks())?.attrs.color ?? null;
500
+ let d;
501
+ return t.doc.nodesBetween(r, o, (i) => {
502
+ if (!i.isText || d === null) return;
503
+ const s = n.isInSet(i.marks)?.attrs.color ?? null;
504
+ d = d === void 0 || d === s ? s : null;
505
+ }), d ?? null;
506
+ }
507
+ function Kn(t, e) {
508
+ return (n, r) => {
509
+ const o = p.marks[t], { from: a, to: l, empty: d } = n.selection;
510
+ if (!r) return !0;
511
+ const i = n.tr;
512
+ return d ? (i.removeStoredMark(o), e && i.addStoredMark(o.create({ color: e }))) : (i.removeMark(a, l, o), e && i.addMark(a, l, o.create({ color: e }))), r(i.scrollIntoView()), !0;
513
+ };
514
+ }
515
+ function Yn() {
516
+ const t = p.nodes;
517
+ return pn({
518
+ rules: [
519
+ tt(/^(#{1,4})\s$/, t.heading, (e) => ({ level: e[1].length })),
520
+ Te(/^\s*>\s$/, t.blockquote),
521
+ Te(/^\s*([-+*])\s$/, t.bullet_list),
522
+ Te(
523
+ /^(\d+)\.\s$/,
524
+ t.ordered_list,
525
+ (e) => ({ order: +e[1] }),
526
+ (e, n) => n.childCount + n.attrs.order === +e[1]
527
+ ),
528
+ tt(/^```$/, t.code_block),
529
+ new mn(/^(?:---|\*\*\*|___)$/, (e, n, r, o) => {
530
+ const a = e.doc.resolve(r);
531
+ if (a.parent.type !== t.paragraph) return null;
532
+ const l = a.before();
533
+ return e.tr.replaceWith(l, o + 1, [t.horizontal_rule.create(), t.paragraph.create()]);
534
+ })
535
+ ]
536
+ });
537
+ }
538
+ function Jn(t) {
539
+ const e = wn(yn, (n, r) => (r && r(n.tr.replaceSelectionWith(p.nodes.hard_break.create()).scrollIntoView()), !0));
540
+ return je({
541
+ "Mod-z": Lt,
542
+ "Mod-y": ze,
543
+ "Shift-Mod-z": ze,
544
+ Backspace: fn,
545
+ "Mod-b": _("strong"),
546
+ "Mod-i": _("em"),
547
+ "Mod-u": _("underline"),
548
+ "Mod-Shift-x": _("strike"),
549
+ "Mod-e": _("code"),
550
+ "Mod-k": t.link,
551
+ "Shift-Enter": e,
552
+ "Mod-Enter": e,
553
+ Enter: Zt(p.nodes.list_item),
554
+ Tab: Fe,
555
+ "Shift-Tab": Ue
556
+ });
557
+ }
558
+ const Xn = () => je(vn);
559
+ function Qn(t) {
560
+ return new kt({
561
+ props: {
562
+ decorations(e) {
563
+ const n = e.doc, r = n.firstChild;
564
+ return !t || n.childCount !== 1 || !r || !r.isTextblock || r.content.size > 0 ? null : Mt.create(n, [
565
+ xt.node(0, r.nodeSize, { class: "wds-placeholder", "data-placeholder": t })
566
+ ]);
567
+ }
568
+ }
569
+ });
570
+ }
571
+ const Q = new _t("wds-upload");
572
+ function Zn() {
573
+ return new kt({
574
+ key: Q,
575
+ state: {
576
+ init: () => Mt.empty,
577
+ apply(t, e) {
578
+ e = e.map(t.mapping, t.doc);
579
+ const n = t.getMeta(Q);
580
+ if (n && "add" in n) {
581
+ const r = document.createElement("span");
582
+ r.className = "wds-upload-placeholder", r.setAttribute("aria-hidden", "true"), e = e.add(t.doc, [xt.widget(n.add.pos, r, { id: n.add.id })]);
583
+ } else n && "remove" in n && (e = e.remove(e.find(void 0, void 0, (r) => r.id === n.remove.id)));
584
+ return e;
585
+ }
586
+ },
587
+ props: {
588
+ decorations: (t) => Q.getState(t)
589
+ }
590
+ });
591
+ }
592
+ function er(t, e) {
593
+ const n = Q.getState(t)?.find(void 0, void 0, (r) => r.id === e);
594
+ return n && n.length ? n[0].from : null;
595
+ }
596
+ const S = (t) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${t}</svg>`, x = {
597
+ undo: S('<path d="M9 14 4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>'),
598
+ redo: S('<path d="m15 14 5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>'),
599
+ bold: S('<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7z"/>'),
600
+ italic: S('<path d="M14 5h-4"/><path d="M14 19h-4"/><path d="m14 5-4 14"/><path d="M18 5h-4M10 19H6"/>'),
601
+ underline: S('<path d="M7 4v7a5 5 0 0 0 10 0V4"/><path d="M5 20h14"/>'),
602
+ strike: S('<path d="M4 12h16"/><path d="M16.5 7.5C16 5.6 14.2 4.5 12 4.5c-2.6 0-4.5 1.4-4.5 3.4 0 1.3.8 2.3 2.4 3"/><path d="M8 16.5c.6 1.9 2.2 3 4.3 3 2.7 0 4.6-1.4 4.6-3.6 0-.9-.3-1.6-.9-2.2"/>'),
603
+ code: S('<path d="m9 8-4 4 4 4"/><path d="m15 8 4 4-4 4"/>'),
604
+ link: S('<path d="M10 14a4.5 4.5 0 0 0 6.4 0l3-3a4.5 4.5 0 0 0-6.4-6.4l-1 1"/><path d="M14 10a4.5 4.5 0 0 0-6.4 0l-3 3a4.5 4.5 0 0 0 6.4 6.4l1-1"/>'),
605
+ blockquote: S('<path d="M5 18c2.5-1 4-3.2 4-6.5V7H5v5h3"/><path d="M14 18c2.5-1 4-3.2 4-6.5V7h-4v5h3"/>'),
606
+ bulletList: S('<circle cx="5" cy="7" r="1" fill="currentColor"/><circle cx="5" cy="12" r="1" fill="currentColor"/><circle cx="5" cy="17" r="1" fill="currentColor"/><path d="M9 7h11M9 12h11M9 17h11"/>'),
607
+ orderedList: S('<path d="M10 7h10M10 12h10M10 17h10"/><path d="M4 5.5 5.5 5v4"/><path d="M4 14.2c.3-.6.8-.9 1.4-.9.7 0 1.1.4 1.1 1 0 .9-1.4 1.6-2.5 2.7h2.6"/>'),
608
+ indent: S('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m4 9.5 3 2.5-3 2.5"/>'),
609
+ outdent: S('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m7 9.5-3 2.5 3 2.5"/>'),
610
+ alignLeft: S('<path d="M4 6h16M4 10h10M4 14h16M4 18h10"/>'),
611
+ alignCenter: S('<path d="M4 6h16M7 10h10M4 14h16M7 18h10"/>'),
612
+ alignRight: S('<path d="M4 6h16M10 10h10M4 14h16M10 18h10"/>'),
613
+ alignJustify: S('<path d="M4 6h16M4 10h16M4 14h16M4 18h16"/>'),
614
+ hr: S('<path d="M3 12h18"/><path d="M8 7h8M8 17h8" opacity=".45"/>'),
615
+ clear: S('<path d="M6 5h12"/><path d="M12 5 9 19"/><path d="m15 14 5 5M20 14l-5 5"/>'),
616
+ source: S('<path d="m8 7-5 5 5 5"/><path d="m16 7 5 5-5 5"/><path d="m14 4-4 16"/>'),
617
+ fullscreen: S('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),
618
+ close: S('<path d="M6 6l12 12M18 6 6 18"/>'),
619
+ image: S('<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="8.5" cy="9.5" r="1.5"/><path d="m21 16-5-5-9 9"/>'),
620
+ file: S('<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M9 13h6M9 17h4"/>'),
621
+ folder: S('<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>'),
622
+ upload: S('<path d="M12 16V4"/><path d="m7 9 5-5 5 5"/><path d="M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3"/>'),
623
+ grid: S('<rect x="4" y="4" width="6" height="6" rx="1"/><rect x="14" y="4" width="6" height="6" rx="1"/><rect x="4" y="14" width="6" height="6" rx="1"/><rect x="14" y="14" width="6" height="6" rx="1"/>'),
624
+ list: S('<path d="M9 6h11M9 12h11M9 18h11"/><path d="M4 6h1M4 12h1M4 18h1"/>'),
625
+ trash: S('<path d="M4 7h16"/><path d="M10 11v6M14 11v6"/><path d="M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12"/><path d="M9 7V4h6v3"/>'),
626
+ table: S('<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16"/>'),
627
+ pasteText: S('<path d="M9 4h6v3H9z"/><path d="M15 5h2a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2"/><path d="M9 12h6M12 12v6"/>'),
628
+ // The bar (class wds-swatch-bar) shows the current color through --wds-swatch
629
+ textColor: S('<path d="m6 16 6-12 6 12"/><path d="M8.5 11h7"/><rect class="wds-swatch-bar" x="3" y="19" width="18" height="3" rx="1" stroke="none"/>'),
630
+ highlight: S('<path d="m14 4 5 5-7 7H7v-5z"/><path d="M7 16l-2 2"/><rect class="wds-swatch-bar" x="3" y="19" width="18" height="3" rx="1" stroke="none"/>'),
631
+ globe: S('<circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><path d="M12 3a14 14 0 0 1 0 18 14 14 0 0 1 0-18"/>')
632
+ }, O = (t) => (e) => e.exec(t), tr = {
633
+ undo: { type: "button", label: "undo", icon: x.undo, shortcut: "Mod+Z", run: (t) => t.undo(), enabled: (t) => jt(t) > 0 },
634
+ redo: { type: "button", label: "redo", icon: x.redo, shortcut: "Mod+Y", run: (t) => t.redo(), enabled: (t) => Gt(t) > 0 },
635
+ blocks: { type: "blocks" },
636
+ bold: { type: "button", label: "bold", icon: x.bold, shortcut: "Mod+B", run: O(_("strong")), active: (t) => de(t, p.marks.strong) },
637
+ italic: { type: "button", label: "italic", icon: x.italic, shortcut: "Mod+I", run: O(_("em")), active: (t) => de(t, p.marks.em) },
638
+ underline: { type: "button", label: "underline", icon: x.underline, shortcut: "Mod+U", run: O(_("underline")), active: (t) => de(t, p.marks.underline) },
639
+ strike: { type: "button", label: "strike", icon: x.strike, run: O(_("strike")), active: (t) => de(t, p.marks.strike) },
640
+ textColor: { type: "button", label: "textColor", icon: x.textColor, popup: !0, run: (t, e) => t.openColorPicker("textColor", e), swatch: (t) => We(t, "textColor") },
641
+ highlight: { type: "button", label: "highlight", icon: x.highlight, popup: !0, run: (t, e) => t.openColorPicker("highlight", e), swatch: (t) => We(t, "highlight") },
642
+ code: { type: "button", label: "code", icon: x.code, run: O(_("code")), active: (t) => de(t, p.marks.code) },
643
+ link: { type: "button", label: "link", icon: x.link, shortcut: "Mod+K", run: (t) => t.openLinkDialog(), active: (t) => !!Pe(t) },
644
+ image: { type: "button", label: "image", icon: x.image, run: (t) => t.openImageDialog(), active: (t) => !!_e(t) },
645
+ file: { type: "button", label: "file", icon: x.file, run: (t) => t.openFileManager("file"), available: (t) => t.hasFileManager() },
646
+ table: { type: "button", label: "table", icon: x.table, popup: !0, run: (t, e) => t.openTableMenu(e), active: (t) => pe(t) },
647
+ blockquote: { type: "button", label: "blockquote", icon: x.blockquote, run: O(Un()), active: (t) => Ot(t, p.nodes.blockquote) },
648
+ bulletList: { type: "button", label: "bulletList", icon: x.bulletList, run: O(pt(p.nodes.bullet_list)), active: (t) => ht(t) === p.nodes.bullet_list },
649
+ orderedList: { type: "button", label: "orderedList", icon: x.orderedList, run: O(pt(p.nodes.ordered_list)), active: (t) => ht(t) === p.nodes.ordered_list },
650
+ outdent: { type: "button", label: "outdent", icon: x.outdent, run: O(Ue), enabled: (t) => Ue(t) },
651
+ indent: { type: "button", label: "indent", icon: x.indent, run: O(Fe), enabled: (t) => Fe(t) },
652
+ alignLeft: { type: "button", label: "alignLeft", icon: x.alignLeft, run: O(j("left")), active: (t) => we(t) === "left", enabled: (t) => j("left")(t) },
653
+ alignCenter: { type: "button", label: "alignCenter", icon: x.alignCenter, run: O(j("center")), active: (t) => we(t) === "center", enabled: (t) => j("center")(t) },
654
+ alignRight: { type: "button", label: "alignRight", icon: x.alignRight, run: O(j("right")), active: (t) => we(t) === "right", enabled: (t) => j("right")(t) },
655
+ alignJustify: { type: "button", label: "alignJustify", icon: x.alignJustify, run: O(j("justify")), active: (t) => we(t) === "justify", enabled: (t) => j("justify")(t) },
656
+ hr: { type: "button", label: "hr", icon: x.hr, run: O(Pn) },
657
+ clear: { type: "button", label: "clear", icon: x.clear, run: O(_n) },
658
+ pasteText: { type: "button", label: "pasteText", icon: x.pasteText, run: (t) => t.togglePlainPaste(), active: (t, e) => e.isPlainPaste() },
659
+ source: { type: "button", label: "source", icon: x.source, run: (t) => t.toggleSource(), active: (t, e) => e.isSourceMode(), inSource: !0 },
660
+ fullscreen: { type: "button", label: "fullscreen", icon: x.fullscreen, run: (t) => t.toggleFullscreen(), active: (t, e) => e.isFullscreen(), inSource: !0 }
661
+ }, nr = [
662
+ "undo",
663
+ "redo",
664
+ "|",
665
+ "blocks",
666
+ "|",
667
+ "bold",
668
+ "italic",
669
+ "underline",
670
+ "strike",
671
+ "code",
672
+ "textColor",
673
+ "highlight",
674
+ "|",
675
+ "link",
676
+ "image",
677
+ "file",
678
+ "table",
679
+ "blockquote",
680
+ "bulletList",
681
+ "orderedList",
682
+ "outdent",
683
+ "indent",
684
+ "|",
685
+ "alignLeft",
686
+ "alignCenter",
687
+ "alignRight",
688
+ "alignJustify",
689
+ "|",
690
+ "hr",
691
+ "clear",
692
+ "pasteText",
693
+ "|",
694
+ "source",
695
+ "fullscreen"
696
+ ], rr = [
697
+ ["paragraph", "paragraph"],
698
+ ["heading1", "heading1"],
699
+ ["heading2", "heading2"],
700
+ ["heading3", "heading3"],
701
+ ["heading4", "heading4"],
702
+ ["codeBlock", "codeBlock"]
703
+ ], or = typeof navigator < "u" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent), ir = (t) => t.replace("Mod", or ? "⌘" : "Ctrl");
704
+ function ar(t, e, n) {
705
+ const r = document.createElement("div");
706
+ r.className = "wds-toolbar", r.setAttribute("role", "toolbar"), r.setAttribute("aria-label", n.toolbarLabel);
707
+ const o = [];
708
+ let a = document.createElement("div");
709
+ a.className = "wds-group", r.append(a);
710
+ for (const d of e) {
711
+ if (d === "|") {
712
+ a.childElementCount && (a = document.createElement("div"), a.className = "wds-group", r.append(a));
713
+ continue;
714
+ }
715
+ const i = tr[d];
716
+ if (!i) {
717
+ console.warn(`[WDS Editor] Unknown toolbar item "${d}".`);
718
+ continue;
719
+ }
720
+ if (i.type === "blocks") {
721
+ const u = document.createElement("select");
722
+ u.className = "wds-select", u.setAttribute("aria-label", n.blockType), u.title = n.blockType;
723
+ for (const [g, v] of rr) {
724
+ const D = document.createElement("option");
725
+ D.value = g, D.textContent = n[v], u.append(D);
726
+ }
727
+ const m = document.createElement("option");
728
+ m.value = "", m.textContent = "—", m.hidden = !0, u.append(m), u.addEventListener("change", () => {
729
+ u.value && t.exec(Fn(u.value)), t.focus();
730
+ }), a.append(u), o.push((g) => {
731
+ u.value = Bn(g) ?? "", u.disabled = t.isSourceMode() || t.isReadOnly();
732
+ });
733
+ continue;
734
+ }
735
+ if (i.available && !i.available(t)) continue;
736
+ const s = document.createElement("button");
737
+ s.type = "button", s.className = "wds-button-tool", s.innerHTML = i.icon;
738
+ const c = n[i.label];
739
+ s.setAttribute("aria-label", c), s.title = i.shortcut ? `${c} (${ir(i.shortcut)})` : c, s.dataset.item = d, i.popup && (s.setAttribute("aria-haspopup", "true"), s.setAttribute("aria-expanded", "false")), s.addEventListener("mousedown", (u) => u.preventDefault()), s.addEventListener("click", () => {
740
+ s.disabled || i.run(t, s);
741
+ }), a.append(s), o.push((u) => {
742
+ const m = t.isSourceMode() && !i.inSource || t.isReadOnly() && !i.inSource;
743
+ if (s.disabled = m || (i.enabled ? !i.enabled(u, t) : !1), i.swatch) {
744
+ const g = m ? null : i.swatch(u);
745
+ g ? s.style.setProperty("--wds-swatch", g) : s.style.removeProperty("--wds-swatch");
746
+ }
747
+ if (i.active) {
748
+ const g = !m && i.active(u, t);
749
+ s.classList.toggle("is-active", g), s.setAttribute("aria-pressed", String(g));
750
+ }
751
+ });
752
+ }
753
+ return r.addEventListener("keydown", (d) => {
754
+ if (d.key !== "ArrowRight" && d.key !== "ArrowLeft" && d.key !== "Home" && d.key !== "End" || d.target.tagName === "SELECT" && (d.key === "Home" || d.key === "End")) return;
755
+ const i = [...r.querySelectorAll("button:not([disabled]), select:not([disabled])")], s = i.indexOf(document.activeElement);
756
+ if (s < 0) return;
757
+ d.preventDefault();
758
+ const c = d.key === "Home" ? 0 : d.key === "End" ? i.length - 1 : (s + (d.key === "ArrowRight" ? 1 : -1) + i.length) % i.length;
759
+ i.forEach((u) => u.tabIndex = -1), i[c].tabIndex = 0, i[c].focus();
760
+ }), { element: r, update: (d) => {
761
+ o.forEach((s) => s(d));
762
+ const i = [...r.querySelectorAll("button, select")];
763
+ if (!i.some((s) => s.tabIndex === 0 && !s.disabled)) {
764
+ i.forEach((c) => c.tabIndex = -1);
765
+ const s = i.find((c) => !c.disabled);
766
+ s && (s.tabIndex = 0);
767
+ }
768
+ } };
769
+ }
770
+ function Ht(t, e, n, r) {
771
+ const o = document.createElement("span");
772
+ o.className = "wds-image";
773
+ const a = document.createElement("img");
774
+ a.draggable = !1;
775
+ const l = document.createElement("span");
776
+ l.className = "wds-resize-handle", l.title = r.resizeLabel, l.setAttribute("aria-hidden", "true"), o.append(a, l);
777
+ const d = () => {
778
+ const c = e();
779
+ c !== void 0 && t.dispatch(t.state.tr.setSelection(he.create(t.state.doc, c)));
780
+ };
781
+ let i = !1;
782
+ return l.addEventListener("pointerdown", (c) => {
783
+ if (!t.editable) return;
784
+ c.preventDefault(), c.stopPropagation(), d(), i = !0;
785
+ try {
786
+ l.setPointerCapture(c.pointerId);
787
+ } catch {
788
+ }
789
+ const u = c.clientX, m = a.getBoundingClientRect().width, g = Math.max(40, t.dom.clientWidth - 8);
790
+ let v = m;
791
+ const D = (C) => {
792
+ v = Math.round(Math.min(g, Math.max(40, m + C.clientX - u))), a.style.width = `${v}px`, a.style.height = "auto", o.dataset.size = `${v}px`;
793
+ }, T = () => {
794
+ i = !1, window.removeEventListener("pointermove", D), window.removeEventListener("pointerup", T), window.removeEventListener("pointercancel", T), delete o.dataset.size, a.style.width = "", a.style.height = "";
795
+ const C = e();
796
+ if (C === void 0 || Math.abs(v - m) < 2) return;
797
+ const H = n(), y = t.state.tr.setNodeMarkup(C, void 0, { ...H.attrs, width: v, height: null });
798
+ t.dispatch(y.setSelection(he.create(y.doc, C)));
799
+ };
800
+ window.addEventListener("pointermove", D), window.addEventListener("pointerup", T), window.addEventListener("pointercancel", T);
801
+ }), o.addEventListener("dblclick", (c) => {
802
+ if (!t.editable) return;
803
+ c.preventDefault(), d();
804
+ const u = e();
805
+ u !== void 0 && r.onEdit(u);
806
+ }), { box: o, img: a, handle: l, select: d, render: (c) => {
807
+ const u = Be(c.attrs, !1);
808
+ for (const m of ["src", "alt", "title", "width", "height"])
809
+ u[m] !== void 0 ? a.setAttribute(m, u[m]) : a.removeAttribute(m);
810
+ }, isResizing: () => i };
811
+ }
812
+ const $t = (t, e) => {
813
+ t.classList.remove("wds-align-left", "wds-align-center", "wds-align-right"), e && t.classList.add(`wds-align-${e}`);
814
+ };
815
+ class sr {
816
+ constructor(e, n, r, o) {
817
+ this.node = e, this.parts = Ht(n, r, () => this.node, o), this.dom = this.parts.box, this.render();
818
+ }
819
+ render() {
820
+ this.parts.render(this.node), $t(this.dom, this.node.attrs.align);
821
+ }
822
+ update(e) {
823
+ return e.type !== this.node.type ? !1 : (this.node = e, this.render(), !0);
824
+ }
825
+ stopEvent(e) {
826
+ return e.target === this.parts.handle || this.parts.isResizing();
827
+ }
828
+ ignoreMutation() {
829
+ return !0;
830
+ }
831
+ }
832
+ class lr {
833
+ constructor(e, n, r, o) {
834
+ this.node = e, this.dom = document.createElement("figure"), this.dom.className = "wds-figure", this.parts = Ht(n, r, () => this.node, o), this.parts.box.contentEditable = "false", this.parts.box.addEventListener("mousedown", (a) => {
835
+ a.target === this.parts.handle || a.detail > 1 || (a.preventDefault(), this.parts.select(), n.focus());
836
+ }), this.contentDOM = document.createElement("figcaption"), this.contentDOM.dataset.placeholder = o.captionPlaceholder, this.dom.append(this.parts.box, this.contentDOM), this.render();
837
+ }
838
+ render() {
839
+ this.parts.render(this.node), $t(this.dom, this.node.attrs.align), this.dom.classList.toggle("is-empty", this.node.content.size === 0);
840
+ }
841
+ update(e) {
842
+ return e.type !== this.node.type ? !1 : (this.node = e, this.render(), !0);
843
+ }
844
+ stopEvent(e) {
845
+ return this.parts.box.contains(e.target) && !e.type.startsWith("drag");
846
+ }
847
+ ignoreMutation(e) {
848
+ return !this.contentDOM.contains(e.target);
849
+ }
850
+ }
851
+ let ye = null;
852
+ function zt() {
853
+ ye?.close();
854
+ }
855
+ function Ve(t, e, n, r) {
856
+ zt();
857
+ const o = document.createElement("div");
858
+ o.className = `wds-menu ${n}`, e.append(o);
859
+ const a = () => {
860
+ const u = t.getBoundingClientRect();
861
+ o.style.maxHeight = "";
862
+ const m = o.offsetWidth, g = o.offsetHeight;
863
+ o.style.left = `${Math.max(4, Math.min(u.left, window.innerWidth - m - 4))}px`;
864
+ const v = window.innerHeight - u.bottom - 8, D = u.top - 8;
865
+ g <= v || v >= D ? (o.style.top = `${u.bottom + 4}px`, g > v && (o.style.maxHeight = `${v}px`)) : (o.style.top = `${Math.max(4, u.top - Math.min(g, D) - 4)}px`, g > D && (o.style.maxHeight = `${D}px`));
866
+ }, l = (u) => {
867
+ if (u.target instanceof Node && o.contains(u.target)) return;
868
+ const m = t.getBoundingClientRect();
869
+ m.bottom < 0 || m.top > window.innerHeight || !t.isConnected ? c() : a();
870
+ };
871
+ t.setAttribute("aria-expanded", "true");
872
+ const d = (u) => {
873
+ !o.contains(u.target) && u.target !== t && !t.contains(u.target) && c();
874
+ }, i = (u) => {
875
+ u.key === "Escape" && (u.preventDefault(), u.stopPropagation(), c(!0));
876
+ };
877
+ let s = !1;
878
+ function c(u = !1) {
879
+ s || (s = !0, o.remove(), t.setAttribute("aria-expanded", "false"), document.removeEventListener("mousedown", d, !0), window.removeEventListener("scroll", l, !0), window.removeEventListener("resize", l), o.removeEventListener("keydown", i), ye?.close === c && (ye = null), u && t.focus());
880
+ }
881
+ return document.addEventListener("mousedown", d, !0), window.addEventListener("scroll", l, !0), window.addEventListener("resize", l), o.addEventListener("keydown", i), ye = { close: c }, { popup: o, place: a, close: c };
882
+ }
883
+ function cr(t, e, n, r) {
884
+ const { popup: o, place: a, close: l } = Ve(t, e, "wds-menu-list");
885
+ o.setAttribute("role", "menu"), o.setAttribute("aria-label", r);
886
+ for (const i of n) {
887
+ if (i === "|") {
888
+ const c = document.createElement("div");
889
+ c.className = "wds-menu-sep", c.setAttribute("role", "separator"), o.append(c);
890
+ continue;
891
+ }
892
+ const s = document.createElement("button");
893
+ s.type = "button", s.className = `wds-menu-item${i.danger ? " is-danger" : ""}`, s.setAttribute("role", "menuitem"), s.tabIndex = -1, s.innerHTML = i.icon ?? "", s.append(document.createTextNode(i.label)), i.enabled === !1 && (s.disabled = !0), s.addEventListener("mousedown", (c) => c.preventDefault()), s.addEventListener("click", () => {
894
+ l(), i.run();
895
+ }), o.append(s);
896
+ }
897
+ const d = () => [...o.querySelectorAll(".wds-menu-item:not(:disabled)")];
898
+ o.addEventListener("keydown", (i) => {
899
+ const s = d(), c = s.indexOf(document.activeElement);
900
+ let u = -1;
901
+ i.key === "ArrowDown" ? u = (c + 1) % s.length : i.key === "ArrowUp" ? u = (c - 1 + s.length) % s.length : i.key === "Home" ? u = 0 : i.key === "End" ? u = s.length - 1 : i.key === "Tab" && l(), u >= 0 && (i.preventDefault(), s[u]?.focus());
902
+ }), a(), d()[0]?.focus();
903
+ }
904
+ function dr(t, e, n, r, o) {
905
+ const { popup: d, place: i, close: s } = Ve(t, e, "wds-table-picker");
906
+ d.setAttribute("role", "dialog"), d.setAttribute("aria-label", n);
907
+ const c = document.createElement("div");
908
+ c.className = "wds-picker-grid", c.style.gridTemplateColumns = "repeat(10, 1fr)", c.tabIndex = 0, c.setAttribute("role", "grid"), c.setAttribute("aria-label", n);
909
+ const u = document.createElement("div");
910
+ u.className = "wds-picker-label", u.setAttribute("aria-live", "polite");
911
+ const m = [];
912
+ let g = 3, v = 3;
913
+ const D = () => {
914
+ m.forEach((T, C) => T.classList.toggle("is-on", Math.floor(C / 10) < g && C % 10 < v)), u.textContent = r(g, v), c.setAttribute("aria-valuetext", u.textContent);
915
+ };
916
+ for (let T = 0; T < 8; T++)
917
+ for (let C = 0; C < 10; C++) {
918
+ const H = document.createElement("span");
919
+ H.className = "wds-picker-cell", H.addEventListener("mouseenter", () => {
920
+ g = T + 1, v = C + 1, D();
921
+ }), H.addEventListener("mousedown", (y) => y.preventDefault()), H.addEventListener("click", () => {
922
+ s(), o(T + 1, C + 1);
923
+ }), m.push(H), c.append(H);
924
+ }
925
+ c.addEventListener("keydown", (T) => {
926
+ const C = { ArrowRight: [0, 1], ArrowLeft: [0, -1], ArrowDown: [1, 0], ArrowUp: [-1, 0] };
927
+ C[T.key] ? (T.preventDefault(), g = Math.min(8, Math.max(1, g + C[T.key][0])), v = Math.min(10, Math.max(1, v + C[T.key][1])), D()) : T.key === "Enter" || T.key === " " ? (T.preventDefault(), s(), o(g, v)) : T.key === "Tab" && s();
928
+ }), d.append(c, u), D(), i(), c.focus();
929
+ }
930
+ function ur(t, e, n) {
931
+ const { popup: r, place: o, close: a } = Ve(t, e, "wds-color-picker");
932
+ r.setAttribute("role", "dialog"), r.setAttribute("aria-label", n.label);
933
+ const l = (s) => {
934
+ a(), n.onPick(s);
935
+ }, d = document.createElement("button");
936
+ d.type = "button", d.className = "wds-menu-item wds-color-remove", d.innerHTML = '<span class="wds-swatch is-none" aria-hidden="true"></span>', d.append(document.createTextNode(n.removeLabel)), d.addEventListener("mousedown", (s) => s.preventDefault()), d.addEventListener("click", () => l(null));
937
+ const i = document.createElement("div");
938
+ i.className = "wds-swatches", i.style.gridTemplateColumns = `repeat(${n.columns}, 1fr)`;
939
+ for (const s of n.swatches) {
940
+ const c = document.createElement("button");
941
+ c.type = "button", c.className = "wds-swatch", c.style.background = s.color, c.title = s.label, c.setAttribute("aria-label", s.label);
942
+ const u = s.color === n.current;
943
+ c.setAttribute("aria-pressed", String(u)), u && c.classList.add("is-current"), c.addEventListener("mousedown", (m) => m.preventDefault()), c.addEventListener("click", () => l(s.color)), i.append(c);
944
+ }
945
+ r.append(d, i), r.addEventListener("keydown", (s) => {
946
+ const c = [d, ...i.querySelectorAll(".wds-swatch")], u = c.indexOf(document.activeElement);
947
+ if (u < 0) return;
948
+ const m = n.columns;
949
+ let g = -1;
950
+ s.key === "ArrowRight" ? g = Math.min(c.length - 1, u + 1) : s.key === "ArrowLeft" ? g = Math.max(0, u - 1) : s.key === "ArrowDown" ? g = u === 0 ? 1 : Math.min(c.length - 1, u + m) : s.key === "ArrowUp" ? g = u <= m ? 0 : u - m : s.key === "Tab" && a(), g >= 0 && (s.preventDefault(), c[g].focus());
951
+ }), o(), (i.querySelector(".is-current") ?? i.querySelector(".wds-swatch"))?.focus();
952
+ }
953
+ const ve = {
954
+ undo: "Undo",
955
+ redo: "Redo",
956
+ blockType: "Text style",
957
+ paragraph: "Paragraph",
958
+ heading1: "Heading 1",
959
+ heading2: "Heading 2",
960
+ heading3: "Heading 3",
961
+ heading4: "Heading 4",
962
+ codeBlock: "Code block",
963
+ bold: "Bold",
964
+ italic: "Italic",
965
+ underline: "Underline",
966
+ strike: "Strikethrough",
967
+ code: "Inline code",
968
+ link: "Insert link",
969
+ blockquote: "Quote",
970
+ bulletList: "Bulleted list",
971
+ orderedList: "Numbered list",
972
+ indent: "Increase indent",
973
+ outdent: "Decrease indent",
974
+ alignLeft: "Align left",
975
+ alignCenter: "Align center",
976
+ alignRight: "Align right",
977
+ alignJustify: "Justify",
978
+ hr: "Horizontal line",
979
+ clear: "Clear formatting",
980
+ source: "Source code",
981
+ fullscreen: "Fullscreen",
982
+ linkUrl: "URL",
983
+ linkText: "Text to display",
984
+ linkTitle: "Title",
985
+ linkNewTab: "Open in a new tab",
986
+ linkInvalid: "Enter a valid web address, email address or relative URL.",
987
+ save: "Save",
988
+ cancel: "Cancel",
989
+ remove: "Remove link",
990
+ close: "Close",
991
+ words: "words",
992
+ characters: "characters",
993
+ poweredBy: "Powered by",
994
+ editorLabel: "Rich text editor",
995
+ toolbarLabel: "Editor toolbar",
996
+ sourceLabel: "HTML source",
997
+ image: "Insert image",
998
+ file: "Insert file",
999
+ imageEdit: "Image",
1000
+ imageUrl: "Image URL",
1001
+ imageAlt: "Alternative text",
1002
+ imageAltHint: "Describe the image for screen readers and search engines.",
1003
+ imageWidth: "Width (px)",
1004
+ imageAlign: "Alignment",
1005
+ alignNone: "None",
1006
+ alignLeftShort: "Left",
1007
+ alignCenterShort: "Center",
1008
+ alignRightShort: "Right",
1009
+ imageInvalid: "Enter a valid image address (https:// or a relative URL).",
1010
+ insert: "Insert",
1011
+ fmTitle: "File manager",
1012
+ fmRoot: "Files",
1013
+ fmBreadcrumb: "Folders",
1014
+ fmSearch: "Search files",
1015
+ fmSort: "Sort",
1016
+ fmSortNewest: "Newest first",
1017
+ fmSortName: "Name",
1018
+ fmSortLargest: "Largest first",
1019
+ fmGrid: "Grid view",
1020
+ fmList: "List view",
1021
+ fmUpload: "Upload",
1022
+ fmDrop: "Drop files to upload",
1023
+ fmLoading: "Loading…",
1024
+ fmEmpty: "No files here yet.",
1025
+ fmNoResults: "No files match your search.",
1026
+ fmLoadMore: "Load more",
1027
+ fmRetry: "Try again",
1028
+ fmDelete: "Delete",
1029
+ fmDeleteConfirm: 'Delete "{name}"? This cannot be undone.',
1030
+ fmFromUrl: "Insert from URL",
1031
+ fmLinkText: "Link text",
1032
+ fmFolder: "Folder",
1033
+ fmNoSelection: "Select a file to see its details.",
1034
+ fmNotAllowed: "{name}: this file type is not allowed here.",
1035
+ fmUploadFailed: "{name}: upload failed. {error}",
1036
+ fmListFailed: "The file list could not be loaded. {error}",
1037
+ fmDeleteFailed: "The file could not be deleted. {error}",
1038
+ fmUploading: "Uploading {name}",
1039
+ table: "Table",
1040
+ tableInsert: "Insert table",
1041
+ tableSize: "{rows} × {cols} table",
1042
+ rowAbove: "Insert row above",
1043
+ rowBelow: "Insert row below",
1044
+ colLeft: "Insert column left",
1045
+ colRight: "Insert column right",
1046
+ deleteRow: "Delete row",
1047
+ deleteCol: "Delete column",
1048
+ headerRow: "Toggle header row",
1049
+ headerCol: "Toggle header column",
1050
+ mergeCells: "Merge cells",
1051
+ splitCell: "Split cell",
1052
+ deleteTable: "Delete table",
1053
+ caption: "Show caption",
1054
+ captionPlaceholder: "Write a caption…",
1055
+ resizeImage: "Drag to resize",
1056
+ pasteText: "Paste as plain text",
1057
+ textColor: "Text color",
1058
+ highlight: "Highlight",
1059
+ removeColor: "Default color",
1060
+ removeHighlight: "No highlight",
1061
+ colorRed: "Red",
1062
+ colorOrange: "Orange",
1063
+ colorAmber: "Amber",
1064
+ colorYellow: "Yellow",
1065
+ colorGreen: "Green",
1066
+ colorTeal: "Teal",
1067
+ colorBlue: "Blue",
1068
+ colorPurple: "Purple",
1069
+ colorPink: "Pink",
1070
+ colorSlate: "Slate",
1071
+ colorGray: "Gray"
1072
+ }, hr = {
1073
+ undo: "Geri al",
1074
+ redo: "Yinele",
1075
+ blockType: "Metin stili",
1076
+ paragraph: "Paragraf",
1077
+ heading1: "Başlık 1",
1078
+ heading2: "Başlık 2",
1079
+ heading3: "Başlık 3",
1080
+ heading4: "Başlık 4",
1081
+ codeBlock: "Kod bloğu",
1082
+ bold: "Kalın",
1083
+ italic: "İtalik",
1084
+ underline: "Altı çizili",
1085
+ strike: "Üstü çizili",
1086
+ code: "Satır içi kod",
1087
+ link: "Bağlantı ekle",
1088
+ blockquote: "Alıntı",
1089
+ bulletList: "Madde işaretli liste",
1090
+ orderedList: "Numaralı liste",
1091
+ indent: "Girintiyi artır",
1092
+ outdent: "Girintiyi azalt",
1093
+ alignLeft: "Sola hizala",
1094
+ alignCenter: "Ortala",
1095
+ alignRight: "Sağa hizala",
1096
+ alignJustify: "İki yana yasla",
1097
+ hr: "Yatay çizgi",
1098
+ clear: "Biçimi temizle",
1099
+ source: "Kaynak kodu",
1100
+ fullscreen: "Tam ekran",
1101
+ linkUrl: "Adres (URL)",
1102
+ linkText: "Görünen metin",
1103
+ linkTitle: "Başlık",
1104
+ linkNewTab: "Yeni sekmede aç",
1105
+ linkInvalid: "Geçerli bir web adresi, e-posta adresi ya da göreli adres girin.",
1106
+ save: "Kaydet",
1107
+ cancel: "Vazgeç",
1108
+ remove: "Bağlantıyı kaldır",
1109
+ close: "Kapat",
1110
+ words: "kelime",
1111
+ characters: "karakter",
1112
+ poweredBy: "Destekleyen:",
1113
+ editorLabel: "Zengin metin editörü",
1114
+ toolbarLabel: "Editör araç çubuğu",
1115
+ sourceLabel: "HTML kaynağı",
1116
+ image: "Görsel ekle",
1117
+ file: "Dosya ekle",
1118
+ imageEdit: "Görsel",
1119
+ imageUrl: "Görsel adresi",
1120
+ imageAlt: "Alternatif metin",
1121
+ imageAltHint: "Ekran okuyucular ve arama motorları için görseli kısaca anlatın.",
1122
+ imageWidth: "Genişlik (px)",
1123
+ imageAlign: "Hizalama",
1124
+ alignNone: "Yok",
1125
+ alignLeftShort: "Sol",
1126
+ alignCenterShort: "Orta",
1127
+ alignRightShort: "Sağ",
1128
+ imageInvalid: "Geçerli bir görsel adresi girin (https:// ya da göreli adres).",
1129
+ insert: "Ekle",
1130
+ fmTitle: "Dosya yöneticisi",
1131
+ fmRoot: "Dosyalar",
1132
+ fmBreadcrumb: "Klasörler",
1133
+ fmSearch: "Dosyalarda ara",
1134
+ fmSort: "Sırala",
1135
+ fmSortNewest: "En yeni",
1136
+ fmSortName: "Ada göre",
1137
+ fmSortLargest: "En büyük",
1138
+ fmGrid: "Izgara görünümü",
1139
+ fmList: "Liste görünümü",
1140
+ fmUpload: "Yükle",
1141
+ fmDrop: "Yüklemek için dosyaları bırakın",
1142
+ fmLoading: "Yükleniyor…",
1143
+ fmEmpty: "Burada henüz dosya yok.",
1144
+ fmNoResults: "Aramanızla eşleşen dosya yok.",
1145
+ fmLoadMore: "Daha fazla yükle",
1146
+ fmRetry: "Tekrar dene",
1147
+ fmDelete: "Sil",
1148
+ fmDeleteConfirm: '"{name}" silinsin mi? Bu işlem geri alınamaz.',
1149
+ fmFromUrl: "Adresten ekle",
1150
+ fmLinkText: "Bağlantı metni",
1151
+ fmFolder: "Klasör",
1152
+ fmNoSelection: "Ayrıntıları görmek için bir dosya seçin.",
1153
+ fmNotAllowed: "{name}: bu dosya türüne burada izin verilmiyor.",
1154
+ fmUploadFailed: "{name}: yüklenemedi. {error}",
1155
+ fmListFailed: "Dosya listesi yüklenemedi. {error}",
1156
+ fmDeleteFailed: "Dosya silinemedi. {error}",
1157
+ fmUploading: "{name} yükleniyor",
1158
+ table: "Tablo",
1159
+ tableInsert: "Tablo ekle",
1160
+ tableSize: "{rows} × {cols} tablo",
1161
+ rowAbove: "Üste satır ekle",
1162
+ rowBelow: "Alta satır ekle",
1163
+ colLeft: "Sola sütun ekle",
1164
+ colRight: "Sağa sütun ekle",
1165
+ deleteRow: "Satırı sil",
1166
+ deleteCol: "Sütunu sil",
1167
+ headerRow: "Başlık satırı aç/kapat",
1168
+ headerCol: "Başlık sütunu aç/kapat",
1169
+ mergeCells: "Hücreleri birleştir",
1170
+ splitCell: "Hücreyi böl",
1171
+ deleteTable: "Tabloyu sil",
1172
+ caption: "Açıklama göster",
1173
+ captionPlaceholder: "Açıklama yazın…",
1174
+ resizeImage: "Boyutlandırmak için sürükleyin",
1175
+ pasteText: "Düz metin olarak yapıştır",
1176
+ textColor: "Yazı rengi",
1177
+ highlight: "Vurgu",
1178
+ removeColor: "Varsayılan renk",
1179
+ removeHighlight: "Vurgu yok",
1180
+ colorRed: "Kırmızı",
1181
+ colorOrange: "Turuncu",
1182
+ colorAmber: "Kehribar",
1183
+ colorYellow: "Sarı",
1184
+ colorGreen: "Yeşil",
1185
+ colorTeal: "Camgöbeği",
1186
+ colorBlue: "Mavi",
1187
+ colorPurple: "Mor",
1188
+ colorPink: "Pembe",
1189
+ colorSlate: "Arduvaz",
1190
+ colorGray: "Gri"
1191
+ }, ke = { en: ve, tr: hr };
1192
+ function pr(t, e) {
1193
+ ke[t.toLowerCase()] = { ...ve, ...ke[t.toLowerCase()], ...e };
1194
+ }
1195
+ function mr(t) {
1196
+ if (t && typeof t == "object") return { ...ve, ...t };
1197
+ const e = (t || (typeof navigator < "u" ? navigator.language : "en") || "en").toLowerCase();
1198
+ return ke[e] ?? ke[e.split("-")[0]] ?? ve;
1199
+ }
1200
+ function V(t, e) {
1201
+ return t.replace(/\{(\w+)\}/g, (n, r) => e[r] ?? n);
1202
+ }
1203
+ let fr = 0;
1204
+ function ft(t, e) {
1205
+ const n = `wds-dlg-${++fr}`, r = document.createElement("dialog");
1206
+ r.className = "wds-dialog", r.setAttribute("aria-labelledby", `${n}-title`);
1207
+ const o = document.createElement("form");
1208
+ o.method = "dialog", o.noValidate = !0;
1209
+ const a = document.createElement("div");
1210
+ a.className = "wds-dialog-header";
1211
+ const l = document.createElement("h2");
1212
+ l.id = `${n}-title`, l.textContent = e.title;
1213
+ const d = document.createElement("button");
1214
+ d.type = "button", d.className = "wds-icon-button", d.setAttribute("aria-label", e.closeLabel), d.innerHTML = x.close, a.append(l, d);
1215
+ const i = document.createElement("div");
1216
+ i.className = "wds-dialog-body";
1217
+ const s = /* @__PURE__ */ new Map();
1218
+ for (const y of e.fields) {
1219
+ if (y.type === "select") {
1220
+ const A = document.createElement("select");
1221
+ A.id = `${n}-${y.name}`, A.name = y.name, A.className = "wds-input";
1222
+ for (const $ of y.options ?? []) {
1223
+ const G = document.createElement("option");
1224
+ G.value = $.value, G.textContent = $.label, A.append(G);
1225
+ }
1226
+ A.value = typeof y.value == "string" ? y.value : "";
1227
+ const N = document.createElement("label");
1228
+ N.className = "wds-label", N.htmlFor = A.id, N.textContent = y.label, i.append(N, A), s.set(y.name, A);
1229
+ continue;
1230
+ }
1231
+ const L = document.createElement("input");
1232
+ if (L.id = `${n}-${y.name}`, L.name = y.name, y.type === "checkbox") {
1233
+ L.type = "checkbox", L.checked = !!y.value;
1234
+ const A = document.createElement("label");
1235
+ A.className = "wds-check", A.htmlFor = L.id, A.append(L, document.createTextNode(y.label)), i.append(A);
1236
+ } else {
1237
+ L.type = "text", y.type === "url" && (L.inputMode = "url"), y.type === "number" && (L.inputMode = "numeric"), L.className = "wds-input", L.value = typeof y.value == "string" ? y.value : "", L.autocomplete = "off", L.spellcheck = !1, y.placeholder && (L.placeholder = y.placeholder);
1238
+ const A = document.createElement("label");
1239
+ if (A.className = "wds-label", A.htmlFor = L.id, A.textContent = y.label, i.append(A, L), y.hint) {
1240
+ const N = document.createElement("p");
1241
+ N.className = "wds-hint", N.id = `${L.id}-hint`, N.textContent = y.hint, L.setAttribute("aria-describedby", N.id), i.append(N);
1242
+ }
1243
+ }
1244
+ s.set(y.name, L);
1245
+ }
1246
+ const c = document.createElement("p");
1247
+ c.className = "wds-dialog-error", c.setAttribute("role", "alert"), c.hidden = !0, i.append(c);
1248
+ const u = document.createElement("div");
1249
+ if (u.className = "wds-dialog-footer", e.extraAction) {
1250
+ const y = document.createElement("button");
1251
+ y.type = "button", y.className = "wds-button wds-button-danger", y.textContent = e.extraAction.label, y.addEventListener("click", () => {
1252
+ e.extraAction.onClick(), C();
1253
+ }), u.append(y);
1254
+ }
1255
+ const m = document.createElement("span");
1256
+ m.className = "wds-spacer";
1257
+ const g = document.createElement("button");
1258
+ g.type = "button", g.className = "wds-button", g.textContent = e.cancelLabel;
1259
+ const v = document.createElement("button");
1260
+ v.type = "submit", v.className = "wds-button wds-button-primary", v.textContent = e.submitLabel, u.append(m, g, v), o.append(a, i, u), r.append(o), t.append(r);
1261
+ const D = () => {
1262
+ const y = {};
1263
+ return s.forEach((L, A) => y[A] = L instanceof HTMLInputElement && L.type === "checkbox" ? L.checked : L.value), y;
1264
+ };
1265
+ let T = !1;
1266
+ function C() {
1267
+ T || (T = !0, r.open && r.close(), r.remove(), e.onClose?.());
1268
+ }
1269
+ o.addEventListener("submit", (y) => {
1270
+ y.preventDefault();
1271
+ const L = D(), A = e.validate?.(L) ?? null;
1272
+ if (A) {
1273
+ c.textContent = A, c.hidden = !1, [...s.values()][0]?.focus();
1274
+ return;
1275
+ }
1276
+ e.onSubmit(L), C();
1277
+ }), g.addEventListener("click", C), d.addEventListener("click", C), r.addEventListener("close", C), r.addEventListener("click", (y) => {
1278
+ y.target === r && C();
1279
+ }), r.showModal();
1280
+ const H = [...s.values()].find((y) => y instanceof HTMLInputElement && y.type !== "checkbox");
1281
+ return H?.focus(), H?.select(), C;
1282
+ }
1283
+ const K = (t) => typeof t == "string" && t.trim() ? t : void 0, Oe = (t) => typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : void 0;
1284
+ function Rt(t) {
1285
+ if (!t || typeof t != "object") return null;
1286
+ const e = t, n = q(K(e.url)), r = K(e.name);
1287
+ if (!n || !r) return null;
1288
+ const o = { url: n, name: r }, a = Oe(e.size), l = Oe(e.width), d = Oe(e.height);
1289
+ a !== void 0 && (o.size = a), l !== void 0 && (o.width = l), d !== void 0 && (o.height = d), K(e.type) && (o.type = e.type.toLowerCase());
1290
+ const i = q(K(e.thumb));
1291
+ return i && (o.thumb = i), K(e.modified) && !Number.isNaN(Date.parse(e.modified)) && (o.modified = e.modified), o;
1292
+ }
1293
+ function gr(t, e = "/") {
1294
+ const n = Array.isArray(t) ? { files: t } : t && typeof t == "object" ? t : {}, r = (Array.isArray(n.files) ? n.files : []).map(Rt).filter((a) => !!a), o = (Array.isArray(n.folders) ? n.folders : []).map((a) => a && typeof a == "object" ? a : {}).filter((a) => K(a.name) && K(a.path)).map((a) => ({ name: a.name, path: qe(a.path) }));
1295
+ return {
1296
+ path: qe(K(n.path) ?? e),
1297
+ folders: o,
1298
+ files: r,
1299
+ hasMore: n.hasMore === !0,
1300
+ serverSearch: typeof n.q == "string"
1301
+ };
1302
+ }
1303
+ function qe(t) {
1304
+ return "/" + t.split("/").filter((n) => n && n !== "." && n !== "..").join("/");
1305
+ }
1306
+ const br = /\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i, wr = {
1307
+ jpg: "image/jpeg",
1308
+ jpeg: "image/jpeg",
1309
+ png: "image/png",
1310
+ gif: "image/gif",
1311
+ webp: "image/webp",
1312
+ avif: "image/avif",
1313
+ svg: "image/svg+xml",
1314
+ bmp: "image/bmp",
1315
+ ico: "image/x-icon",
1316
+ pdf: "application/pdf",
1317
+ zip: "application/zip",
1318
+ txt: "text/plain",
1319
+ csv: "text/csv",
1320
+ doc: "application/msword",
1321
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1322
+ xls: "application/vnd.ms-excel",
1323
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1324
+ mp4: "video/mp4",
1325
+ mp3: "audio/mpeg"
1326
+ }, Bt = (t) => (/\.([a-z0-9]+)$/i.exec(t)?.[1] ?? "").toLowerCase();
1327
+ function Ft(t) {
1328
+ return t.type || wr[Bt(t.name)] || "";
1329
+ }
1330
+ function ue(t) {
1331
+ const e = Ft(t);
1332
+ return e ? e.startsWith("image/") : br.test(t.url ?? t.name);
1333
+ }
1334
+ function gt(t, e) {
1335
+ if (!e || !e.trim()) return !0;
1336
+ const n = Ft(t), r = "." + Bt(t.name);
1337
+ return e.split(",").some((o) => {
1338
+ const a = o.trim().toLowerCase();
1339
+ return a ? a.startsWith(".") ? r === a : a.endsWith("/*") ? n.startsWith(a.slice(0, -1)) : n === a : !1;
1340
+ });
1341
+ }
1342
+ function bt(t) {
1343
+ if (t === void 0) return "";
1344
+ if (t < 1024) return `${t} B`;
1345
+ const e = ["KB", "MB", "GB"];
1346
+ let n = t / 1024, r = 0;
1347
+ for (; n >= 1024 && r < e.length - 1; )
1348
+ n /= 1024, r++;
1349
+ return `${n < 10 ? n.toFixed(1) : Math.round(n)} ${e[r]}`;
1350
+ }
1351
+ class P extends Error {
1352
+ }
1353
+ async function wt(t) {
1354
+ try {
1355
+ const e = await t.clone().json();
1356
+ if (e && typeof e.error == "string") return e.error;
1357
+ } catch {
1358
+ }
1359
+ return `HTTP ${t.status}`;
1360
+ }
1361
+ function yr(t, e) {
1362
+ const n = new URL(t, document.baseURI);
1363
+ for (const [r, o] of Object.entries(e)) o && n.searchParams.set(r, o);
1364
+ return n.href;
1365
+ }
1366
+ class vr {
1367
+ constructor(e) {
1368
+ this.options = e;
1369
+ }
1370
+ get canUpload() {
1371
+ return !!this.options.uploadUrl;
1372
+ }
1373
+ get canDelete() {
1374
+ return !!this.options.deleteUrl;
1375
+ }
1376
+ init(e = {}) {
1377
+ return {
1378
+ ...e,
1379
+ credentials: this.options.withCredentials ? "include" : "same-origin",
1380
+ headers: { Accept: "application/json", ...this.options.headers, ...e.headers }
1381
+ };
1382
+ }
1383
+ async list(e, n, r, o) {
1384
+ const a = yr(this.options.listUrl, { path: e, q: n, page: r > 1 ? String(r) : "" });
1385
+ let l;
1386
+ try {
1387
+ l = await fetch(a, { ...this.init(), signal: o });
1388
+ } catch (i) {
1389
+ throw i.name === "AbortError" ? i : new P(i.message || "Network error");
1390
+ }
1391
+ if (!l.ok) throw new P(await wt(l));
1392
+ let d;
1393
+ try {
1394
+ d = await l.json();
1395
+ } catch {
1396
+ throw new P("Invalid JSON");
1397
+ }
1398
+ return gr(d, e);
1399
+ }
1400
+ /** Multipart upload with progress (XMLHttpRequest, because fetch has no upload progress). */
1401
+ upload(e, n, r) {
1402
+ const { uploadUrl: o, headers: a = {}, withCredentials: l } = this.options;
1403
+ return o ? new Promise((d, i) => {
1404
+ const s = new XMLHttpRequest();
1405
+ s.open("POST", new URL(o, document.baseURI).href), s.withCredentials = !!l, s.setRequestHeader("Accept", "application/json");
1406
+ for (const [u, m] of Object.entries(a)) s.setRequestHeader(u, m);
1407
+ s.upload.onprogress = (u) => u.lengthComputable && r?.(u.loaded / u.total), s.onerror = () => i(new P("Network error")), s.onload = () => {
1408
+ let u = null;
1409
+ try {
1410
+ u = JSON.parse(s.responseText);
1411
+ } catch {
1412
+ }
1413
+ if (s.status < 200 || s.status >= 300) {
1414
+ i(new P(typeof u?.error == "string" ? u.error : `HTTP ${s.status}`));
1415
+ return;
1416
+ }
1417
+ const m = Rt(u?.file);
1418
+ m ? d(m) : i(new P("Invalid upload response"));
1419
+ };
1420
+ const c = new FormData();
1421
+ c.append("file", e, e.name), c.append("path", n), s.send(c);
1422
+ }) : Promise.reject(new P("Upload is not configured"));
1423
+ }
1424
+ async remove(e) {
1425
+ const { deleteUrl: n } = this.options;
1426
+ if (!n) throw new P("Delete is not configured");
1427
+ let r;
1428
+ try {
1429
+ r = await fetch(
1430
+ new URL(n, document.baseURI).href,
1431
+ this.init({ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ url: e }) })
1432
+ );
1433
+ } catch (o) {
1434
+ throw new P(o.message || "Network error");
1435
+ }
1436
+ if (!r.ok) throw new P(await wt(r));
1437
+ }
1438
+ }
1439
+ const b = (t, e, n) => {
1440
+ const r = document.createElement(t);
1441
+ return e && (r.className = e), n !== void 0 && (r.textContent = n), r;
1442
+ }, He = (t, e, n = "wds-icon-button") => {
1443
+ const r = b("button", n);
1444
+ return r.type = "button", r.innerHTML = t, r.setAttribute("aria-label", e), r.title = e, r;
1445
+ }, kr = [
1446
+ ["", "alignNone"],
1447
+ ["left", "alignLeftShort"],
1448
+ ["center", "alignCenterShort"],
1449
+ ["right", "alignRightShort"]
1450
+ ];
1451
+ class Mr {
1452
+ constructor(e, n, r) {
1453
+ this.host = e, this.api = n, this.t = r, this.path = "/", this.view = "grid", this.sort = "newest";
1454
+ }
1455
+ open(e) {
1456
+ const n = this.t, r = e.accept ?? "";
1457
+ let o = [], a = [], l = 1, d = !1, i = !1, s = "", c = null, u = null, m = 0, g = !1;
1458
+ const v = b("dialog", "wds-dialog wds-fm");
1459
+ v.setAttribute("aria-labelledby", "wds-fm-title");
1460
+ const D = b("div", "wds-dialog-header"), T = b("h2", void 0, n.fmTitle);
1461
+ T.id = "wds-fm-title";
1462
+ const C = He(x.close, n.close);
1463
+ D.append(T, C);
1464
+ const H = b("div", "wds-fm-bar"), y = b("nav", "wds-fm-crumbs");
1465
+ y.setAttribute("aria-label", n.fmBreadcrumb);
1466
+ const L = b("input", "wds-input wds-fm-search");
1467
+ L.type = "search", L.placeholder = n.fmSearch, L.setAttribute("aria-label", n.fmSearch);
1468
+ const A = b("select", "wds-input wds-fm-sort");
1469
+ A.setAttribute("aria-label", n.fmSort), A.title = n.fmSort;
1470
+ for (const [h, f] of [["newest", "fmSortNewest"], ["name", "fmSortName"], ["largest", "fmSortLargest"]]) {
1471
+ const M = b("option", void 0, n[f]);
1472
+ M.value = h, A.append(M);
1473
+ }
1474
+ A.value = this.sort;
1475
+ const N = He(this.view === "grid" ? x.list : x.grid, this.view === "grid" ? n.fmList : n.fmGrid), $ = b("input");
1476
+ $.type = "file", $.multiple = !0, $.hidden = !0, r && ($.accept = r);
1477
+ const G = b("button", "wds-button wds-button-primary wds-fm-upload");
1478
+ G.type = "button", G.innerHTML = `${x.upload}<span>${$e(n.fmUpload)}</span>`;
1479
+ const Me = b("div", "wds-fm-tools");
1480
+ Me.append(L, A, N), this.api.canUpload && Me.append(G, $), H.append(y, Me);
1481
+ const Ke = b("div", "wds-fm-main"), W = b("div", "wds-fm-browser"), xe = b("div", "wds-fm-uploads"), B = b("ul", `wds-fm-items is-${this.view}`);
1482
+ B.setAttribute("aria-label", n.fmTitle);
1483
+ const I = b("p", "wds-fm-status");
1484
+ I.setAttribute("role", "status");
1485
+ const Z = b("button", "wds-button", n.fmRetry);
1486
+ Z.type = "button", Z.hidden = !0;
1487
+ const ee = b("button", "wds-button wds-fm-more", n.fmLoadMore);
1488
+ ee.type = "button", ee.hidden = !0;
1489
+ const Ye = b("div", "wds-fm-drop", n.fmDrop);
1490
+ Ye.setAttribute("aria-hidden", "true"), W.append(xe, B, I, Z, ee, Ye);
1491
+ const F = b("aside", "wds-fm-details");
1492
+ F.setAttribute("aria-label", n.imageEdit), Ke.append(W, F);
1493
+ const Le = b("div", "wds-dialog-footer");
1494
+ if (e.onFromUrl) {
1495
+ const h = b("button", "wds-button wds-fm-fromurl");
1496
+ h.type = "button", h.innerHTML = `${x.globe}<span>${$e(n.fmFromUrl)}</span>`, h.addEventListener("click", () => {
1497
+ X(), e.onFromUrl();
1498
+ }), Le.append(h);
1499
+ }
1500
+ const Se = b("button", "wds-button", n.cancel);
1501
+ Se.type = "button";
1502
+ const ie = b("button", "wds-button wds-button-primary", n.insert);
1503
+ ie.type = "button", ie.disabled = !0, Le.append(b("span", "wds-spacer"), Se, ie), v.append(D, H, Ke, Le), this.host.append(v);
1504
+ let ae = null, U = null, se = null, Y = null, le = null;
1505
+ const me = (h, f, M, w) => {
1506
+ f.id = M;
1507
+ const E = b("label", "wds-label", h);
1508
+ if (E.htmlFor = M, F.append(E, f), w) {
1509
+ const k = b("p", "wds-hint", w);
1510
+ k.id = `${M}-hint`, f.setAttribute("aria-describedby", k.id), F.append(k);
1511
+ }
1512
+ }, fe = () => {
1513
+ if (F.replaceChildren(), ae = U = le = Y = null, se = null, ie.disabled = !c, !c) {
1514
+ F.append(b("p", "wds-fm-placeholder", n.fmNoSelection));
1515
+ return;
1516
+ }
1517
+ const h = c, f = b("div", "wds-fm-preview"), M = b("p", "wds-fm-filename", h.name), w = b("p", "wds-fm-facts"), E = () => [
1518
+ h.width && h.height ? `${h.width} × ${h.height}` : "",
1519
+ bt(h.size),
1520
+ h.modified ? new Date(h.modified).toLocaleDateString() : ""
1521
+ ].filter(Boolean).join(" · ");
1522
+ if (w.textContent = E(), ue(h)) {
1523
+ const k = b("img");
1524
+ k.alt = "", !h.thumb && !(h.width && h.height) && k.addEventListener("load", () => {
1525
+ !k.naturalWidth || c !== h || (h.width = k.naturalWidth, h.height = k.naturalHeight, w.textContent = E(), U && !U.placeholder && (U.placeholder = String(h.width)));
1526
+ }, { once: !0 }), k.src = h.thumb ?? h.url, f.append(k);
1527
+ } else
1528
+ f.innerHTML = x.file;
1529
+ if (F.append(f, M, w), e.mode === "image" && ue(h)) {
1530
+ ae = b("input", "wds-input"), ae.value = h.name.replace(/\.[a-z0-9]+$/i, "").replace(/[-_]+/g, " "), me(n.imageAlt, ae, "wds-fm-alt", n.imageAltHint), U = b("input", "wds-input"), U.inputMode = "numeric", U.placeholder = h.width ? String(h.width) : "", me(n.imageWidth, U, "wds-fm-width"), se = b("select", "wds-input");
1531
+ for (const [z, R] of kr) {
1532
+ const te = b("option", void 0, n[R]);
1533
+ te.value = z, se.append(te);
1534
+ }
1535
+ me(n.imageAlign, se, "wds-fm-align"), Y = b("input"), Y.type = "checkbox", Y.id = "wds-fm-caption";
1536
+ const k = b("label", "wds-check");
1537
+ k.htmlFor = Y.id, k.append(Y, document.createTextNode(n.caption)), F.append(k);
1538
+ } else
1539
+ le = b("input", "wds-input"), le.value = h.name, me(n.fmLinkText, le, "wds-fm-text");
1540
+ if (this.api.canDelete) {
1541
+ const k = b("button", "wds-button wds-button-danger wds-fm-delete");
1542
+ k.type = "button", k.innerHTML = `${x.trash}<span>${$e(n.fmDelete)}</span>`, k.addEventListener("click", () => Pt(h)), F.append(k);
1543
+ }
1544
+ }, Ut = () => {
1545
+ const h = s.trim().toLocaleLowerCase(), f = o.filter((w) => gt(w, r) && (i || !h || w.name.toLocaleLowerCase().includes(h))), M = (w) => w.modified ? Date.parse(w.modified) : -1 / 0;
1546
+ return this.sort === "name" ? f.sort((w, E) => w.name.localeCompare(E.name, void 0, { numeric: !0, sensitivity: "base" })) : this.sort === "largest" ? f.sort((w, E) => (E.size ?? -1) - (w.size ?? -1)) : f.sort((w, E) => M(E) - M(w)), f;
1547
+ }, Ee = () => {
1548
+ y.replaceChildren();
1549
+ const h = this.path.split("/").filter(Boolean), f = [[n.fmRoot, "/"], ...h.map((M, w) => [M, "/" + h.slice(0, w + 1).join("/")])];
1550
+ f.forEach(([M, w], E) => {
1551
+ if (E && y.append(b("span", "wds-fm-sep", "/")), E === f.length - 1) {
1552
+ const k = b("span", "wds-fm-crumb is-current", M);
1553
+ k.setAttribute("aria-current", "location"), y.append(k);
1554
+ } else {
1555
+ const k = b("button", "wds-fm-crumb", M);
1556
+ k.type = "button", k.addEventListener("click", () => Qe(w)), y.append(k);
1557
+ }
1558
+ });
1559
+ }, J = () => {
1560
+ B.className = `wds-fm-items is-${this.view}`, B.replaceChildren();
1561
+ const h = !s.trim();
1562
+ if (h)
1563
+ for (const w of a) {
1564
+ const E = Xe(x.folder, w.name, n.fmFolder, !0);
1565
+ E.addEventListener("click", () => Qe(w.path)), B.append(Je(E));
1566
+ }
1567
+ const f = Ut();
1568
+ for (const w of f) {
1569
+ const E = ue(w) ? w.thumb ?? w.url : null, k = Xe(E ? "" : x.file, w.name, [bt(w.size), w.width && w.height ? `${w.width}×${w.height}` : ""].filter(Boolean).join(" · "), !1);
1570
+ if (E) {
1571
+ const R = b("img");
1572
+ R.loading = "lazy", R.decoding = "async", R.alt = "", R.src = E, k.querySelector(".wds-fm-thumb").append(R);
1573
+ }
1574
+ k.dataset.url = w.url;
1575
+ const z = c?.url === w.url;
1576
+ k.classList.toggle("is-selected", z), k.setAttribute("aria-pressed", String(z)), k.addEventListener("click", () => Ae(w)), k.addEventListener("dblclick", () => {
1577
+ Ae(w), Ce();
1578
+ }), B.append(Je(k));
1579
+ }
1580
+ const M = !f.length && !(h && a.length);
1581
+ !I.dataset.busy && !I.dataset.error && (I.textContent = M ? s.trim() ? n.fmNoResults : n.fmEmpty : ""), ee.hidden = !d || !!I.dataset.busy;
1582
+ }, Je = (h) => {
1583
+ const f = b("li");
1584
+ return f.append(h), f;
1585
+ }, Xe = (h, f, M, w) => {
1586
+ const E = b("button", `wds-fm-item${w ? " is-folder" : ""}`);
1587
+ E.type = "button";
1588
+ const k = b("span", "wds-fm-thumb");
1589
+ k.innerHTML = h;
1590
+ const z = b("span", "wds-fm-name", f);
1591
+ z.title = f;
1592
+ const R = b("span", "wds-fm-meta", M);
1593
+ return E.append(k, z, R), E;
1594
+ }, Ae = (h) => {
1595
+ c = h, B.querySelectorAll(".wds-fm-item[data-url]").forEach((f) => {
1596
+ const M = f.dataset.url === h.url;
1597
+ f.classList.toggle("is-selected", M), f.setAttribute("aria-pressed", String(M));
1598
+ }), fe();
1599
+ }, ce = async (h) => {
1600
+ u?.abort(), u = new AbortController(), h && (l = 1, o = [], a = []), I.dataset.busy = "1", delete I.dataset.error, I.textContent = n.fmLoading, Z.hidden = !0, ee.hidden = !0, h && J();
1601
+ try {
1602
+ const f = await this.api.list(this.path, s.trim(), l, u.signal);
1603
+ if (g) return;
1604
+ this.path = f.path, i = f.serverSearch, d = f.hasMore, a = h ? f.folders : a;
1605
+ const M = new Set(o.map((w) => w.url));
1606
+ o = [...o, ...f.files.filter((w) => !M.has(w.url))], delete I.dataset.busy, I.textContent = "", Ee(), J();
1607
+ } catch (f) {
1608
+ if (f.name === "AbortError" || g) return;
1609
+ delete I.dataset.busy, I.dataset.error = "1", I.textContent = V(n.fmListFailed, { error: f.message }), I.setAttribute("role", "alert"), Z.hidden = !1;
1610
+ }
1611
+ }, Qe = (h) => {
1612
+ this.path = qe(h), s = "", L.value = "", c = null, fe(), Ee(), ce(!0).then(() => B.querySelector(".wds-fm-item")?.focus());
1613
+ }, Ze = (h) => {
1614
+ for (const f of Array.from(h)) {
1615
+ const M = b("div", "wds-fm-upload-row"), w = b("span", "wds-fm-upload-name", V(n.fmUploading, { name: f.name }));
1616
+ if (!gt(f, r)) {
1617
+ et(M, V(n.fmNotAllowed, { name: f.name })), xe.append(M);
1618
+ continue;
1619
+ }
1620
+ const E = b("progress");
1621
+ E.max = 1, E.value = 0, M.append(w, E), xe.append(M), this.api.upload(f, this.path, (k) => E.value = k).then((k) => {
1622
+ g || (M.remove(), o = [k, ...o.filter((z) => z.url !== k.url)], J(), Ae(k), e.onUpload?.(k));
1623
+ }).catch((k) => {
1624
+ g || (M.replaceChildren(), et(M, V(n.fmUploadFailed, { name: f.name, error: k.message })));
1625
+ });
1626
+ }
1627
+ }, et = (h, f) => {
1628
+ h.classList.add("is-error");
1629
+ const M = b("span", "wds-fm-upload-name", f);
1630
+ M.setAttribute("role", "alert");
1631
+ const w = He(x.close, n.close);
1632
+ w.addEventListener("click", () => h.remove()), h.append(M, w);
1633
+ }, Pt = async (h) => {
1634
+ if (window.confirm(V(n.fmDeleteConfirm, { name: h.name })))
1635
+ try {
1636
+ await this.api.remove(h.url), o = o.filter((f) => f.url !== h.url), c = null, fe(), J();
1637
+ } catch (f) {
1638
+ I.dataset.error = "1", I.setAttribute("role", "alert"), I.textContent = V(n.fmDeleteFailed, { error: f.message });
1639
+ }
1640
+ }, Ce = () => {
1641
+ if (!c) return;
1642
+ const h = U ? parseInt(U.value, 10) : NaN;
1643
+ e.onPick({
1644
+ file: c,
1645
+ alt: ae?.value.trim() ?? "",
1646
+ width: Number.isFinite(h) && h > 0 ? h : null,
1647
+ align: se?.value || null,
1648
+ text: le?.value.trim() || c.name,
1649
+ caption: !!Y?.checked
1650
+ }), X();
1651
+ };
1652
+ function X() {
1653
+ g || (g = !0, u?.abort(), window.clearTimeout(m), v.open && v.close(), v.remove(), e.onClose?.());
1654
+ }
1655
+ if (C.addEventListener("click", X), Se.addEventListener("click", X), ie.addEventListener("click", Ce), v.addEventListener("close", X), v.addEventListener("click", (h) => h.target === v && X()), Z.addEventListener("click", () => {
1656
+ I.setAttribute("role", "status"), ce(!0);
1657
+ }), ee.addEventListener("click", () => {
1658
+ l++, ce(!1);
1659
+ }), A.addEventListener("change", () => {
1660
+ this.sort = A.value, J();
1661
+ }), N.addEventListener("click", () => {
1662
+ this.view = this.view === "grid" ? "list" : "grid", N.innerHTML = this.view === "grid" ? x.list : x.grid;
1663
+ const h = this.view === "grid" ? n.fmList : n.fmGrid;
1664
+ N.setAttribute("aria-label", h), N.title = h, J();
1665
+ }), L.addEventListener("input", () => {
1666
+ window.clearTimeout(m), m = window.setTimeout(() => {
1667
+ s = L.value, !i && !d ? J() : ce(!0);
1668
+ }, 250);
1669
+ }), G.addEventListener("click", () => $.click()), $.addEventListener("change", () => {
1670
+ $.files?.length && Ze($.files), $.value = "";
1671
+ }), this.api.canUpload) {
1672
+ let h = 0;
1673
+ W.addEventListener("dragenter", (f) => {
1674
+ f.dataTransfer?.types.includes("Files") && (h++, W.classList.add("is-dragging"));
1675
+ }), W.addEventListener("dragleave", () => {
1676
+ h = Math.max(0, h - 1), h || W.classList.remove("is-dragging");
1677
+ }), W.addEventListener("dragover", (f) => {
1678
+ f.dataTransfer?.types.includes("Files") && f.preventDefault();
1679
+ }), W.addEventListener("drop", (f) => {
1680
+ f.preventDefault(), h = 0, W.classList.remove("is-dragging"), f.dataTransfer?.files.length && Ze(f.dataTransfer.files);
1681
+ });
1682
+ }
1683
+ return B.addEventListener("keydown", (h) => {
1684
+ if (!["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp", "Home", "End"].includes(h.key)) return;
1685
+ const M = [...B.querySelectorAll(".wds-fm-item")], w = M.indexOf(document.activeElement);
1686
+ if (w < 0) return;
1687
+ h.preventDefault();
1688
+ const E = M[0].offsetTop, k = this.view === "list" ? 1 : Math.max(1, M.findIndex((te) => te.offsetTop !== E) === -1 ? M.length : M.findIndex((te) => te.offsetTop !== E)), z = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: k, ArrowUp: -k }, R = h.key === "Home" ? 0 : h.key === "End" ? M.length - 1 : Math.min(M.length - 1, Math.max(0, w + z[h.key]));
1689
+ M[R].focus();
1690
+ }), F.addEventListener("keydown", (h) => {
1691
+ h.key === "Enter" && h.target.tagName === "INPUT" && (h.preventDefault(), Ce());
1692
+ }), Ee(), fe(), v.showModal(), L.focus(), ce(!0), X;
1693
+ }
1694
+ }
1695
+ function $e(t) {
1696
+ const e = document.createElement("span");
1697
+ return e.textContent = t, e.innerHTML;
1698
+ }
1699
+ const ne = /* @__PURE__ */ new WeakMap(), yt = (t) => t === void 0 ? void 0 : typeof t == "number" ? `${t}px` : t;
1700
+ function xr(t) {
1701
+ return t === !1 ? [] : t === void 0 || t === "default" ? nr : Array.isArray(t) ? t : t.split(/\s+/).filter(Boolean);
1702
+ }
1703
+ const re = class re {
1704
+ constructor(e, n = {}) {
1705
+ if (this.listeners = /* @__PURE__ */ new Map(), this.notice = null, this.noticeTimer = 0, this.onFormSubmit = () => this.syncTarget(), this.onKeydown = (i) => {
1706
+ i.key === "Escape" && this.fullscreen && this.toggleFullscreen();
1707
+ }, this.sourceMode = !1, this.plainPaste = !1, this.fullscreen = !1, this.destroyed = !1, ne.has(e)) throw new Error("[WDS Editor] This element already has an editor. Use WDSEditor.get() or destroy() first.");
1708
+ this.target = e, this.options = n, this.t = mr(n.language), this.readOnly = !!n.readOnly, this.textarea = e instanceof HTMLTextAreaElement ? e : null, this.originalContent = this.textarea ? this.textarea.value : e.innerHTML;
1709
+ const r = n.content ?? this.originalContent;
1710
+ this.root = document.createElement("div"), this.root.className = "wds-editor", this.root.dataset.theme = n.theme ?? "light", this.fileManager = n.fileManager?.listUrl ? new Mr(this.root, new vr(n.fileManager), this.t) : null, this.contentWrap = document.createElement("div"), this.contentWrap.className = "wds-content-wrap";
1711
+ const o = yt(n.height);
1712
+ o ? (this.contentWrap.style.height = o, this.root.classList.add("wds-fixed-height")) : this.contentWrap.style.minHeight = yt(n.minHeight ?? 240), this.sourceArea = document.createElement("textarea"), this.sourceArea.className = "wds-source", this.sourceArea.spellcheck = !1, this.sourceArea.hidden = !0, this.sourceArea.setAttribute("aria-label", this.t.sourceLabel);
1713
+ const a = Wt.create({
1714
+ schema: p,
1715
+ doc: ge(r),
1716
+ plugins: [
1717
+ tn(),
1718
+ je({ Tab: jn, "Shift-Tab": Vn }),
1719
+ Yn(),
1720
+ Jn({ link: () => (this.openLinkDialog(), !0) }),
1721
+ Xn(),
1722
+ Vt(),
1723
+ Qn(n.placeholder ?? ""),
1724
+ Zn(),
1725
+ kn(),
1726
+ Mn({ class: "wds-dropcursor", color: !1 })
1727
+ ]
1728
+ }), l = {
1729
+ onEdit: () => this.openImageUrlDialog(),
1730
+ resizeLabel: this.t.resizeImage,
1731
+ captionPlaceholder: this.t.captionPlaceholder
1732
+ };
1733
+ this.view = new qt(this.contentWrap, {
1734
+ state: a,
1735
+ editable: () => !this.readOnly,
1736
+ attributes: {
1737
+ class: "wds-content",
1738
+ role: "textbox",
1739
+ "aria-multiline": "true",
1740
+ "aria-label": this.t.editorLabel
1741
+ },
1742
+ dispatchTransaction: (i) => this.dispatch(i),
1743
+ transformPastedHTML: Ln,
1744
+ handlePaste: (i, s) => {
1745
+ const c = s.clipboardData;
1746
+ if (this.plainPaste && c) {
1747
+ const m = c.getData("text/plain");
1748
+ if (m)
1749
+ return i.dispatch(i.state.tr.replaceSelection(Lr(m)).scrollIntoView()), !0;
1750
+ }
1751
+ if (!c?.files.length || !this.canUploadInline() || c.getData("text/plain")) return !1;
1752
+ const u = [...c.files].filter((m) => m.type.startsWith("image/"));
1753
+ return u.length ? (this.uploadFiles(u), !0) : !1;
1754
+ },
1755
+ handleDrop: (i, s, c, u) => {
1756
+ const m = s.dataTransfer?.files;
1757
+ if (u || !m?.length || !this.canUploadInline()) return !1;
1758
+ const g = i.posAtCoords({ left: s.clientX, top: s.clientY })?.pos;
1759
+ return s.preventDefault(), this.uploadFiles([...m], g), !0;
1760
+ },
1761
+ nodeViews: {
1762
+ image: (i, s, c) => new sr(i, s, c, l),
1763
+ figure: (i, s, c) => new lr(i, s, c, l)
1764
+ },
1765
+ handleDOMEvents: {
1766
+ focus: () => (this.root.classList.add("is-focused"), this.emit("focus"), !1),
1767
+ blur: () => (this.root.classList.remove("is-focused"), this.emit("blur"), !1)
1768
+ }
1769
+ }), this.contentWrap.append(this.sourceArea), this.toolbar = ar(this, xr(n.toolbar), this.t), this.toolbar.element.childElementCount && this.toolbar.element.firstElementChild.childElementCount && this.root.append(this.toolbar.element), this.root.append(this.contentWrap);
1770
+ const d = document.createElement("div");
1771
+ if (d.className = "wds-statusbar", this.counter = n.wordCount === !1 ? null : document.createElement("span"), this.counter && (this.counter.className = "wds-counter", this.counter.setAttribute("aria-live", "off"), d.append(this.counter)), n.branding !== !1) {
1772
+ const i = document.createElement("a");
1773
+ i.className = "wds-branding", i.href = "https://webdevsnippets.com/wds-editor", i.target = "_blank", i.rel = "noopener", i.innerHTML = `${Sr(this.t.poweredBy)} <strong>WDS Editor</strong>`, d.append(i);
1774
+ }
1775
+ d.childElementCount && this.root.append(d), this.textarea ? (this.textarea.style.display = "none", this.textarea.after(this.root), this.textarea.form?.addEventListener("submit", this.onFormSubmit)) : e.replaceChildren(this.root), document.addEventListener("keydown", this.onKeydown), ne.set(e, this), this.lastHtml = this.getHTML(), this.syncTarget(), this.refresh(), this.emit("init");
1776
+ }
1777
+ /** Creates (or returns the existing) editor for the first element matching options.selector. */
1778
+ static init(e) {
1779
+ const n = typeof e.selector == "string" ? document.querySelector(e.selector) : e.selector;
1780
+ if (!n) throw new Error(`[WDS Editor] No element matches "${String(e.selector)}".`);
1781
+ return ne.get(n) ?? new re(n, e);
1782
+ }
1783
+ /** Creates editors for every element matching options.selector. */
1784
+ static initAll(e) {
1785
+ return [...document.querySelectorAll(e.selector)].map((n) => ne.get(n) ?? new re(n, e));
1786
+ }
1787
+ /** Returns the editor attached to an element (or selector), if any. */
1788
+ static get(e) {
1789
+ const n = typeof e == "string" ? document.querySelector(e) : e;
1790
+ return n ? ne.get(n) : void 0;
1791
+ }
1792
+ // ---------- content ----------
1793
+ getHTML() {
1794
+ return this.sourceMode && this.applySource(), be(this.view.state.doc);
1795
+ }
1796
+ /** Replaces the whole content. The change can be undone. */
1797
+ setHTML(e) {
1798
+ this.sourceMode && (this.sourceArea.value = ut(e));
1799
+ const n = ge(e), r = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, n.content);
1800
+ this.dispatch(r.setSelection(Ge.atStart(r.doc)));
1801
+ }
1802
+ /** Inserts HTML at the cursor (replacing the selection). */
1803
+ insertHTML(e) {
1804
+ const n = ge(e), r = At.maxOpen(n.content);
1805
+ this.dispatch(this.view.state.tr.replaceSelection(r).scrollIntoView());
1806
+ }
1807
+ getText() {
1808
+ const e = this.view.state.doc;
1809
+ return e.textBetween(0, e.content.size, `
1810
+
1811
+ `, `
1812
+ `);
1813
+ }
1814
+ isEmpty() {
1815
+ return Nt(this.view.state.doc);
1816
+ }
1817
+ // ---------- state ----------
1818
+ focus() {
1819
+ this.sourceMode ? this.sourceArea.focus() : this.view.focus();
1820
+ }
1821
+ setReadOnly(e) {
1822
+ this.readOnly = e, this.root.classList.toggle("is-readonly", e), this.sourceArea.readOnly = e, this.view.setProps({}), this.refresh();
1823
+ }
1824
+ isReadOnly() {
1825
+ return this.readOnly;
1826
+ }
1827
+ /** Runs a ProseMirror command against the editor. Returns whether it applied. */
1828
+ exec(e) {
1829
+ if (this.readOnly || this.sourceMode) return !1;
1830
+ const n = e(this.view.state, (r) => this.dispatch(r), this.view);
1831
+ return this.view.focus(), n;
1832
+ }
1833
+ undo() {
1834
+ this.exec(Lt);
1835
+ }
1836
+ redo() {
1837
+ this.exec(ze);
1838
+ }
1839
+ // ---------- views ----------
1840
+ isSourceMode() {
1841
+ return this.sourceMode;
1842
+ }
1843
+ toggleSource() {
1844
+ this.sourceMode ? (this.applySource(), this.sourceMode = !1, this.sourceArea.hidden = !0, this.view.dom.hidden = !1, this.root.classList.remove("is-source"), this.view.focus()) : (this.sourceArea.value = ut(be(this.view.state.doc)), this.sourceMode = !0, this.view.dom.hidden = !0, this.sourceArea.hidden = !1, this.root.classList.add("is-source"), this.sourceArea.focus()), this.refresh();
1845
+ }
1846
+ isFullscreen() {
1847
+ return this.fullscreen;
1848
+ }
1849
+ toggleFullscreen() {
1850
+ this.fullscreen = !this.fullscreen, this.root.classList.toggle("is-fullscreen", this.fullscreen), document.documentElement.classList.toggle("wds-noscroll", this.fullscreen), this.refresh(), this.focus();
1851
+ }
1852
+ // ---------- link dialog ----------
1853
+ openLinkDialog() {
1854
+ if (this.readOnly || this.sourceMode) return;
1855
+ const e = this.view.state, n = Pe(e), { from: r, to: o, empty: a } = e.selection, l = a ? "" : e.doc.textBetween(r, o, " "), d = a && !n, i = this.t;
1856
+ ft(this.root, {
1857
+ title: i.link,
1858
+ closeLabel: i.close,
1859
+ submitLabel: i.save,
1860
+ cancelLabel: i.cancel,
1861
+ fields: [
1862
+ { name: "href", label: i.linkUrl, type: "url", value: n?.href ?? "", placeholder: "https://" },
1863
+ ...d ? [{ name: "text", label: i.linkText, type: "text", value: l }] : [],
1864
+ { name: "title", label: i.linkTitle, type: "text", value: n?.title ?? "" },
1865
+ { name: "newTab", label: i.linkNewTab, type: "checkbox", value: n?.target === "_blank" }
1866
+ ],
1867
+ extraAction: n ? { label: i.remove, onClick: () => this.removeLink() } : void 0,
1868
+ validate: (s) => nt(String(s.href)) ? null : i.linkInvalid,
1869
+ onSubmit: (s) => {
1870
+ const c = nt(String(s.href)), u = { href: c, title: String(s.title).trim() || null, target: s.newTab ? "_blank" : null }, m = p.marks.link.create(u), g = this.view.state;
1871
+ let v = g.tr;
1872
+ if (n)
1873
+ v = v.removeMark(n.from, n.to, p.marks.link).addMark(n.from, n.to, m);
1874
+ else if (d) {
1875
+ const D = String(s.text ?? "").trim() || c.replace(/^mailto:/, "");
1876
+ v = v.replaceSelectionWith(p.text(D, [m]), !1);
1877
+ } else
1878
+ v = v.addMark(g.selection.from, g.selection.to, m);
1879
+ this.dispatch(v.scrollIntoView());
1880
+ },
1881
+ onClose: () => this.view.focus()
1882
+ });
1883
+ }
1884
+ removeLink() {
1885
+ const e = Pe(this.view.state);
1886
+ e && this.dispatch(this.view.state.tr.removeMark(e.from, e.to, p.marks.link));
1887
+ }
1888
+ // ---------- images and files ----------
1889
+ /** True when a file manager (listUrl) is configured. */
1890
+ hasFileManager() {
1891
+ return !!this.fileManager;
1892
+ }
1893
+ /** Inserts an image at the cursor (replacing the selection). caption: true wraps it in <figure>. Unsafe sources are ignored. */
1894
+ insertImage(e) {
1895
+ const n = q(e.src);
1896
+ if (!n || this.readOnly || this.sourceMode) return !1;
1897
+ const r = p.nodes.image.create({
1898
+ src: n,
1899
+ alt: e.alt ?? "",
1900
+ title: e.title ?? null,
1901
+ width: e.width ?? null,
1902
+ height: e.width ? e.height ?? null : null,
1903
+ align: e.align ?? null
1904
+ }), o = this.view.state.tr.replaceSelectionWith(r);
1905
+ return e.caption && mt(o, o.selection.from - 1, r.attrs), this.dispatch(o.scrollIntoView()), !0;
1906
+ }
1907
+ /**
1908
+ * Image button: edits the selected image, otherwise opens the file manager (when configured)
1909
+ * or the "image by URL" dialog.
1910
+ */
1911
+ openImageDialog() {
1912
+ if (this.readOnly || this.sourceMode) return;
1913
+ _e(this.view.state) || !this.fileManager ? this.openImageUrlDialog() : this.openFileManager("image");
1914
+ }
1915
+ /** Opens the file manager. "image" lists images (accept option, default image/*), "file" lists every file. */
1916
+ openFileManager(e = "image") {
1917
+ !this.fileManager || this.readOnly || this.sourceMode || this.fileManager.open({
1918
+ mode: e,
1919
+ accept: e === "image" ? this.options.fileManager?.accept ?? "image/*" : "",
1920
+ onFromUrl: e === "image" ? () => this.openImageUrlDialog() : void 0,
1921
+ onUpload: (n) => this.emit("upload", n),
1922
+ onPick: ({ file: n, alt: r, width: o, align: a, text: l, caption: d }) => {
1923
+ e === "image" && ue(n) ? this.insertImage({ src: n.url, alt: r, width: o, align: a, caption: d }) : this.insertFileLink(n, l), this.emit("fileSelect", n);
1924
+ },
1925
+ onClose: () => this.view.focus()
1926
+ });
1927
+ }
1928
+ /** Dialog for an image by URL, or for editing the selected image (alt text, width, alignment). */
1929
+ openImageUrlDialog() {
1930
+ const e = this.t, n = _e(this.view.state), r = n?.attrs ?? {};
1931
+ ft(this.root, {
1932
+ title: n ? e.imageEdit : e.image,
1933
+ closeLabel: e.close,
1934
+ submitLabel: n ? e.save : e.insert,
1935
+ cancelLabel: e.cancel,
1936
+ fields: [
1937
+ { name: "src", label: e.imageUrl, type: "url", value: r.src ?? "", placeholder: "https://" },
1938
+ { name: "alt", label: e.imageAlt, type: "text", value: r.alt ?? "", hint: e.imageAltHint },
1939
+ { name: "width", label: e.imageWidth, type: "number", value: r.width ? String(r.width) : "" },
1940
+ {
1941
+ name: "align",
1942
+ label: e.imageAlign,
1943
+ type: "select",
1944
+ value: r.align ?? "",
1945
+ options: [
1946
+ { value: "", label: e.alignNone },
1947
+ { value: "left", label: e.alignLeftShort },
1948
+ { value: "center", label: e.alignCenterShort },
1949
+ { value: "right", label: e.alignRightShort }
1950
+ ]
1951
+ },
1952
+ { name: "caption", label: e.caption, type: "checkbox", value: !!n?.figure }
1953
+ ],
1954
+ validate: (o) => q(String(o.src)) && !/^(mailto|tel):/i.test(String(o.src).trim()) ? null : e.imageInvalid,
1955
+ onSubmit: (o) => {
1956
+ const a = parseInt(String(o.width), 10), l = {
1957
+ src: q(String(o.src)),
1958
+ alt: String(o.alt).trim(),
1959
+ width: a > 0 ? a : null,
1960
+ align: String(o.align) || null
1961
+ }, d = !!o.caption;
1962
+ if (n) {
1963
+ const i = l.width && l.width === r.width ? r.height ?? null : null, s = { ...r, ...l, height: i }, c = this.view.state.tr;
1964
+ d && !n.figure ? mt(c, n.pos, s) : !d && n.figure ? Wn(c, n.pos, n.node, s) : c.setNodeMarkup(n.pos, void 0, s).setSelection(he.create(c.doc, n.pos)), this.dispatch(c.scrollIntoView());
1965
+ } else
1966
+ this.insertImage({ ...l, caption: d });
1967
+ },
1968
+ onClose: () => this.view.focus()
1969
+ });
1970
+ }
1971
+ // ---------- tables ----------
1972
+ /** Table button: a size picker outside tables, the row / column menu inside one. */
1973
+ openTableMenu(e) {
1974
+ if (this.readOnly || this.sourceMode) return;
1975
+ const n = this.t, r = this.view.state;
1976
+ if (!pe(r)) {
1977
+ dr(
1978
+ e,
1979
+ this.root,
1980
+ n.tableInsert,
1981
+ (l, d) => V(n.tableSize, { rows: String(l), cols: String(d) }),
1982
+ (l, d) => this.exec(Gn(l, d))
1983
+ );
1984
+ return;
1985
+ }
1986
+ const o = (l, d, i = !1) => ({ label: l, danger: i, enabled: d(r), run: () => this.exec(d) }), a = [
1987
+ o(n.rowAbove, nn),
1988
+ o(n.rowBelow, Tt),
1989
+ o(n.colLeft, rn),
1990
+ o(n.colRight, on),
1991
+ "|",
1992
+ o(n.deleteRow, an),
1993
+ o(n.deleteCol, sn),
1994
+ "|",
1995
+ o(n.headerRow, ln),
1996
+ o(n.headerCol, cn),
1997
+ o(n.mergeCells, dn),
1998
+ o(n.splitCell, un),
1999
+ "|",
2000
+ o(n.deleteTable, hn, !0)
2001
+ ];
2002
+ cr(e, this.root, a, n.table);
2003
+ }
2004
+ // ---------- colors ----------
2005
+ /** Opens the text color or highlight palette under the given toolbar button. */
2006
+ openColorPicker(e, n) {
2007
+ if (this.readOnly || this.sourceMode) return;
2008
+ const r = this.t, a = ((e === "textColor" ? this.options.colors?.text : this.options.colors?.highlight) ?? (e === "textColor" ? Sn : En)).map((l) => typeof l == "string" ? { color: l, name: l } : l).map((l) => ({ color: oe(l.color), label: r[l.name] ?? l.name })).filter((l) => !!l.color);
2009
+ ur(n, this.root, {
2010
+ label: e === "textColor" ? r.textColor : r.highlight,
2011
+ removeLabel: e === "textColor" ? r.removeColor : r.removeHighlight,
2012
+ swatches: a,
2013
+ columns: e === "textColor" ? 5 : 6,
2014
+ current: We(this.view.state, e),
2015
+ onPick: (l) => this.exec(Kn(e, l))
2016
+ });
2017
+ }
2018
+ // ---------- paste ----------
2019
+ /** When on, pasted content is inserted as plain text (paragraphs and line breaks only). */
2020
+ togglePlainPaste(e = !this.plainPaste) {
2021
+ this.plainPaste = e, this.refresh(), this.view.focus();
2022
+ }
2023
+ isPlainPaste() {
2024
+ return this.plainPaste;
2025
+ }
2026
+ /** Inserts a link to a file: links the selected text, or inserts the text (default: file name). */
2027
+ insertFileLink(e, n) {
2028
+ const r = q(e.url);
2029
+ if (!r || this.readOnly || this.sourceMode) return;
2030
+ const o = p.marks.link.create({ href: r }), a = this.view.state, l = a.selection.empty ? a.tr.replaceSelectionWith(p.text(n || e.name, [o]), !1) : a.tr.addMark(a.selection.from, a.selection.to, o);
2031
+ this.dispatch(l.scrollIntoView());
2032
+ }
2033
+ canUploadInline() {
2034
+ return !!this.fileManager?.api.canUpload && !this.readOnly && !this.sourceMode;
2035
+ }
2036
+ /**
2037
+ * Uploads files to the current file manager folder and inserts them at pos (default: the cursor).
2038
+ * Images become <img>, other files become links. A placeholder shows where each file will land.
2039
+ */
2040
+ uploadFiles(e, n) {
2041
+ if (!this.canUploadInline()) return;
2042
+ const r = this.fileManager.api;
2043
+ for (const o of e) {
2044
+ const a = {};
2045
+ let l = this.view.state.tr;
2046
+ n === void 0 && !l.selection.empty && (l = l.deleteSelection());
2047
+ const d = n ?? l.selection.from;
2048
+ this.dispatch(l.setMeta(Q, { add: { id: a, pos: d } })), r.upload(o, this.fileManager.path).then((i) => {
2049
+ if (this.destroyed) return;
2050
+ const s = er(this.view.state, a);
2051
+ if (s === null) return;
2052
+ const c = ue(i) ? p.nodes.image.create({ src: i.url, alt: "" }) : p.text(i.name, [p.marks.link.create({ href: i.url })]);
2053
+ this.dispatch(this.view.state.tr.replaceWith(s, s, c).setMeta(Q, { remove: { id: a } })), this.emit("upload", i);
2054
+ }).catch((i) => {
2055
+ this.destroyed || (this.dispatch(this.view.state.tr.setMeta(Q, { remove: { id: a } })), this.showNotice(V(this.t.fmUploadFailed, { name: o.name, error: i.message })));
2056
+ });
2057
+ }
2058
+ }
2059
+ /** Short message over the bottom of the editing area (upload errors). */
2060
+ showNotice(e) {
2061
+ this.notice || (this.notice = document.createElement("div"), this.notice.className = "wds-notice", this.notice.setAttribute("role", "alert"), this.root.append(this.notice)), this.notice.textContent = e, this.notice.hidden = !1, window.clearTimeout(this.noticeTimer), this.noticeTimer = window.setTimeout(() => this.notice && (this.notice.hidden = !0), 6e3);
2062
+ }
2063
+ // ---------- events ----------
2064
+ on(e, n) {
2065
+ return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(n), this;
2066
+ }
2067
+ off(e, n) {
2068
+ return this.listeners.get(e)?.delete(n), this;
2069
+ }
2070
+ /** Removes the editor and restores the original element (the textarea keeps the latest HTML). */
2071
+ destroy() {
2072
+ if (this.destroyed) return;
2073
+ this.emit("destroy");
2074
+ const e = this.getHTML();
2075
+ this.destroyed = !0, window.clearTimeout(this.noticeTimer), zt(), this.view.destroy(), document.removeEventListener("keydown", this.onKeydown), this.fullscreen && document.documentElement.classList.remove("wds-noscroll"), this.textarea ? (this.textarea.form?.removeEventListener("submit", this.onFormSubmit), this.textarea.value = e, this.textarea.style.display = "", this.root.remove()) : this.target.innerHTML = e || this.originalContent, ne.delete(this.target), this.listeners.clear();
2076
+ }
2077
+ // ---------- internals ----------
2078
+ dispatch(e) {
2079
+ if (this.destroyed) return;
2080
+ const n = this.view.state.apply(e);
2081
+ if (this.view.updateState(n), e.docChanged) {
2082
+ const r = be(n.doc);
2083
+ r !== this.lastHtml && (this.lastHtml = r, this.syncTarget(r), this.options.onChange?.(r, this), this.emit("change"));
2084
+ }
2085
+ this.refresh();
2086
+ }
2087
+ applySource() {
2088
+ const e = this.sourceArea.value, n = ge(e);
2089
+ if (n.eq(this.view.state.doc)) return;
2090
+ const r = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, n.content), o = this.view.state.apply(r);
2091
+ this.view.updateState(o), this.lastHtml = be(o.doc), this.syncTarget(this.lastHtml), this.options.onChange?.(this.lastHtml, this), this.emit("change");
2092
+ }
2093
+ syncTarget(e) {
2094
+ this.textarea && (this.textarea.value = e ?? this.getHTML());
2095
+ }
2096
+ refresh() {
2097
+ const e = this.view.state;
2098
+ if (this.toolbar.update(e), this.counter) {
2099
+ const n = this.getText(), r = (n.match(/[\p{L}\p{N}][\p{L}\p{N}'’-]*/gu) ?? []).length, o = n.replace(/\n/g, "").length;
2100
+ this.counter.textContent = `${r} ${this.t.words} · ${o} ${this.t.characters}`;
2101
+ }
2102
+ }
2103
+ emit(e, n) {
2104
+ this.listeners.get(e)?.forEach((r) => {
2105
+ try {
2106
+ r(this, n);
2107
+ } catch (o) {
2108
+ console.error(o);
2109
+ }
2110
+ });
2111
+ }
2112
+ };
2113
+ re.version = "1.0.0", re.addLanguage = pr;
2114
+ let vt = re;
2115
+ function Lr(t) {
2116
+ const e = t.replace(/\r\n?/g, `
2117
+ `).split(/\n{2,}/).map((n) => {
2118
+ const o = n.split(`
2119
+ `).flatMap((a, l) => [...l ? [p.nodes.hard_break.create()] : [], ...a ? [p.text(a)] : []]);
2120
+ return p.nodes.paragraph.create(null, o);
2121
+ });
2122
+ return new At(Et.from(e), 1, 1);
2123
+ }
2124
+ function Sr(t) {
2125
+ const e = document.createElement("span");
2126
+ return e.textContent = t, e.innerHTML;
2127
+ }
2128
+ export {
2129
+ nr as DEFAULT_TOOLBAR,
2130
+ vt as WDSEditor,
2131
+ pr as addLanguage,
2132
+ ve as en,
2133
+ ue as isImage,
2134
+ gt as matchesAccept,
2135
+ gr as normalizeList,
2136
+ p as schema,
2137
+ tr as toolbarItems,
2138
+ hr as tr
2139
+ };
2140
+ //# sourceMappingURL=wds-editor.js.map