wds-editor 1.0.1 → 1.1.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.
@@ -1,30 +1,30 @@
1
- import { TextSelection as Ve, NodeSelection as he, PluginKey as Gt, Plugin as xt, EditorState as jt } from "prosemirror-state";
2
- import { DecorationSet as Et, Decoration as St, EditorView as Vt } from "prosemirror-view";
3
- import { redo as Re, undo as At, redoDepth as Kt, undoDepth as Yt, history as Jt } from "prosemirror-history";
4
- import { Schema as Tt, DOMParser as Xt, DOMSerializer as Qt, Fragment as Ct, Slice as Dt } from "prosemirror-model";
5
- import { addListNodes as Zt, sinkListItem as en, liftListItem as Nt, wrapInList as tn, splitListItem as nn } from "prosemirror-schema-list";
6
- import { tableNodes as rn, isInTable as pe, goToNextCell as ze, addRowAfter as It, tableEditing as on, addRowBefore as an, addColumnBefore as sn, addColumnAfter as ln, deleteRow as cn, deleteColumn as dn, toggleHeaderRow as un, toggleHeaderColumn as hn, mergeCells as pn, splitCell as mn, deleteTable as fn } from "prosemirror-tables";
7
- import { inputRules as gn, InputRule as bn, textblockTypeInputRule as rt, wrappingInputRule as Ce, undoInputRule as wn } from "prosemirror-inputrules";
8
- import { keymap as Ke } from "prosemirror-keymap";
9
- import { lift as Ht, toggleMark as yn, setBlockType as De, wrapIn as vn, chainCommands as kn, exitCode as Mn, baseKeymap as Ln } from "prosemirror-commands";
10
- import { gapCursor as xn } from "prosemirror-gapcursor";
11
- import { dropCursor as En } from "prosemirror-dropcursor";
12
- const Sn = /^(https?:|mailto:|tel:)/i, Ot = /^[a-z][a-z0-9+.-]*:/i;
1
+ import { TextSelection as Ye, NodeSelection as he, PluginKey as Qt, Plugin as Ct, EditorState as Zt } from "prosemirror-state";
2
+ import { DecorationSet as Dt, Decoration as Nt, EditorView as en } from "prosemirror-view";
3
+ import { redo as Be, undo as It, redoDepth as tn, undoDepth as nn, history as rn } from "prosemirror-history";
4
+ import { Schema as Ht, DOMParser as on, DOMSerializer as an, Fragment as Ot, Slice as Rt } from "prosemirror-model";
5
+ import { addListNodes as sn, sinkListItem as ln, liftListItem as $t, wrapInList as cn, splitListItem as dn } from "prosemirror-schema-list";
6
+ import { tableNodes as un, isInTable as me, goToNextCell as Fe, addRowAfter as zt, tableEditing as hn, addRowBefore as pn, addColumnBefore as mn, addColumnAfter as fn, deleteRow as gn, deleteColumn as bn, toggleHeaderRow as wn, toggleHeaderColumn as yn, mergeCells as vn, splitCell as kn, deleteTable as Mn } from "prosemirror-tables";
7
+ import { inputRules as Ln, InputRule as xn, textblockTypeInputRule as it, wrappingInputRule as Ce, undoInputRule as En } from "prosemirror-inputrules";
8
+ import { keymap as Je } from "prosemirror-keymap";
9
+ import { lift as Bt, toggleMark as Sn, setBlockType as De, wrapIn as An, chainCommands as Tn, exitCode as Cn, baseKeymap as Dn } from "prosemirror-commands";
10
+ import { gapCursor as Nn } from "prosemirror-gapcursor";
11
+ import { dropCursor as In } from "prosemirror-dropcursor";
12
+ const Hn = /^(https?:|mailto:|tel:)/i, Ft = /^[a-z][a-z0-9+.-]*:/i;
13
13
  function q(t) {
14
14
  if (t == null) return null;
15
15
  const e = t.trim();
16
16
  if (!e) return null;
17
17
  const n = e.replace(/[\u0000- \u007f-\u009f]/g, "");
18
- return Ot.test(n) && !Sn.test(n) ? null : e;
18
+ return Ft.test(n) && !Hn.test(n) ? null : e;
19
19
  }
20
- function ot(t) {
20
+ function at(t) {
21
21
  const e = t.trim();
22
- return e ? /^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(e) ? `mailto:${e}` : !Ot.test(e) && !/^[/#?.]/.test(e) && /^[\w-]+(\.[\w-]+)+/.test(e) ? `https://${e}` : q(e) : null;
22
+ return e ? /^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(e) ? `mailto:${e}` : !Ft.test(e) && !/^[/#?.]/.test(e) && /^[\w-]+(\.[\w-]+)+/.test(e) ? `https://${e}` : q(e) : null;
23
23
  }
24
- function An(t) {
24
+ function On(t) {
25
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
26
  }
27
- const it = {
27
+ const st = {
28
28
  black: "#000000",
29
29
  white: "#ffffff",
30
30
  red: "#ff0000",
@@ -54,22 +54,22 @@ const it = {
54
54
  darkgray: "#a9a9a9",
55
55
  darkgrey: "#a9a9a9"
56
56
  }, Ne = (t) => Math.max(0, Math.min(255, Math.round(t))).toString(16).padStart(2, "0");
57
- function oe(t) {
57
+ function re(t) {
58
58
  if (!t) return null;
59
59
  const e = t.trim().toLowerCase().replace(/\s*!important$/, "");
60
- if (it[e]) return it[e];
60
+ if (st[e]) return st[e];
61
61
  let n = /^#([0-9a-f]{3})$/.exec(e);
62
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 : "#" + Ne(+n[1]) + Ne(+n[2]) + Ne(+n[3]) : null));
63
63
  }
64
- function at(t) {
65
- const e = oe(t);
64
+ function lt(t) {
65
+ const e = re(t);
66
66
  return e && e !== "#000000" ? e : null;
67
67
  }
68
68
  function Ie(t) {
69
- const e = oe(t) ?? oe((t ?? "").split(/\s+(?![^(]*\))/).find((n) => oe(n)));
69
+ const e = re(t) ?? re((t ?? "").split(/\s+(?![^(]*\))/).find((n) => re(n)));
70
70
  return e && e !== "#ffffff" ? e : null;
71
71
  }
72
- const Tn = [
72
+ const Rn = [
73
73
  { color: "#dc2626", name: "colorRed" },
74
74
  { color: "#ea580c", name: "colorOrange" },
75
75
  { color: "#ca8a04", name: "colorAmber" },
@@ -80,35 +80,35 @@ const Tn = [
80
80
  { color: "#db2777", name: "colorPink" },
81
81
  { color: "#475569", name: "colorSlate" },
82
82
  { color: "#94a3b8", name: "colorGray" }
83
- ], Cn = [
83
+ ], $n = [
84
84
  { color: "#fef08a", name: "colorYellow" },
85
85
  { color: "#bbf7d0", name: "colorGreen" },
86
86
  { color: "#bae6fd", name: "colorBlue" },
87
87
  { color: "#fbcfe8", name: "colorPink" },
88
88
  { color: "#fed7aa", name: "colorOrange" },
89
89
  { color: "#e9d5ff", name: "colorPurple" }
90
- ], Dn = ["left", "center", "right", "justify"];
91
- function st(t) {
90
+ ], zn = ["left", "center", "right", "justify"];
91
+ function ct(t) {
92
92
  const e = (t.style.textAlign || t.getAttribute("align") || "").toLowerCase();
93
- return Dn.includes(e) && e !== "left" ? e : null;
93
+ return zn.includes(e) && e !== "left" ? e : null;
94
94
  }
95
- function lt(t) {
95
+ function dt(t) {
96
96
  return t ? { style: `text-align: ${t}` } : {};
97
97
  }
98
- const Nn = {
98
+ const Bn = {
99
99
  left: "float: left; margin: 0 1em 1em 0",
100
100
  right: "float: right; margin: 0 0 1em 1em",
101
101
  center: "display: block; margin-left: auto; margin-right: auto"
102
- }, In = {
102
+ }, Fn = {
103
103
  left: "float: left; margin: 0 1em 1em 0",
104
104
  right: "float: right; margin: 0 0 1em 1em",
105
105
  center: "display: table; margin-left: auto; margin-right: auto"
106
106
  };
107
- function Hn(t) {
107
+ function Un(t) {
108
108
  const e = t.style.float || t.getAttribute("align") || "";
109
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
110
  }
111
- const ct = {
111
+ const ut = {
112
112
  src: {},
113
113
  alt: { default: "" },
114
114
  title: { default: null },
@@ -116,35 +116,35 @@ const ct = {
116
116
  height: { default: null },
117
117
  align: { default: null }
118
118
  };
119
- function dt(t, e) {
119
+ function ht(t, e) {
120
120
  const n = q(t.getAttribute("src"));
121
121
  return n ? {
122
122
  src: n,
123
123
  alt: t.getAttribute("alt") ?? "",
124
124
  title: t.getAttribute("title"),
125
- width: ut(t.getAttribute("width") ?? t.style.width),
126
- height: ut(t.getAttribute("height") ?? t.style.height),
127
- align: Hn(e)
125
+ width: pt(t.getAttribute("width") ?? t.style.width),
126
+ height: pt(t.getAttribute("height") ?? t.style.height),
127
+ align: Un(e)
128
128
  } : !1;
129
129
  }
130
- function Be(t, e) {
131
- const { src: n, alt: r, title: o, width: s, height: l, align: d } = t, i = { src: n, alt: r ?? "" };
132
- o && (i.title = o), s && (i.width = String(s)), s && l && (i.height = String(l));
133
- const a = e ? Nn[d] : void 0;
130
+ function Ue(t, e) {
131
+ const { src: n, alt: r, title: o, width: s, height: c, align: d } = t, i = { src: n, alt: r ?? "" };
132
+ o && (i.title = o), s && (i.width = String(s)), s && c && (i.height = String(c));
133
+ const a = e ? Bn[d] : void 0;
134
134
  return a && (i.style = a), i;
135
135
  }
136
- function ut(t) {
136
+ function pt(t) {
137
137
  const e = /^\s*(\d{1,5})(px)?\s*$/.exec(t ?? "");
138
138
  return e ? Number(e[1]) : null;
139
139
  }
140
- const On = {
140
+ const Pn = {
141
141
  doc: { content: "block+" },
142
142
  paragraph: {
143
143
  content: "inline*",
144
144
  group: "block",
145
145
  attrs: { align: { default: null } },
146
- parseDOM: [{ tag: "p", getAttrs: (t) => ({ align: st(t) }) }],
147
- toDOM: (t) => ["p", lt(t.attrs.align), 0]
146
+ parseDOM: [{ tag: "p", getAttrs: (t) => ({ align: ct(t) }) }],
147
+ toDOM: (t) => ["p", dt(t.attrs.align), 0]
148
148
  },
149
149
  heading: {
150
150
  content: "inline*",
@@ -154,9 +154,9 @@ const On = {
154
154
  parseDOM: [1, 2, 3, 4, 5, 6].map((t) => ({
155
155
  tag: `h${t}`,
156
156
  // h5/h6 are folded into h4 so pasted content stays inside the supported range
157
- getAttrs: (e) => ({ level: Math.min(t, 4), align: st(e) })
157
+ getAttrs: (e) => ({ level: Math.min(t, 4), align: ct(e) })
158
158
  })),
159
- toDOM: (t) => [`h${t.attrs.level}`, lt(t.attrs.align), 0]
159
+ toDOM: (t) => [`h${t.attrs.level}`, dt(t.attrs.align), 0]
160
160
  },
161
161
  blockquote: {
162
162
  content: "block+",
@@ -192,15 +192,15 @@ const On = {
192
192
  ["code", t.attrs.language ? { class: `language-${t.attrs.language}` } : {}, 0]
193
193
  ]
194
194
  },
195
- ...rn({ tableGroup: "block", cellContent: "block+", cellAttributes: {} }),
195
+ ...un({ tableGroup: "block", cellContent: "block+", cellAttributes: {} }),
196
196
  text: { group: "inline" },
197
197
  image: {
198
198
  inline: !0,
199
199
  group: "inline",
200
200
  draggable: !0,
201
- attrs: ct,
202
- parseDOM: [{ tag: "img[src]", getAttrs: (t) => dt(t, t) }],
203
- toDOM: (t) => ["img", Be(t.attrs, !0)]
201
+ attrs: ut,
202
+ parseDOM: [{ tag: "img[src]", getAttrs: (t) => ht(t, t) }],
203
+ toDOM: (t) => ["img", Ue(t.attrs, !0)]
204
204
  },
205
205
  /** Image with a caption: <figure><img><figcaption>…</figcaption></figure>. The caption is the node's content. */
206
206
  figure: {
@@ -209,20 +209,20 @@ const On = {
209
209
  marks: "_",
210
210
  draggable: !0,
211
211
  isolating: !0,
212
- attrs: ct,
212
+ attrs: ut,
213
213
  parseDOM: [
214
214
  {
215
215
  tag: "figure",
216
216
  getAttrs: (t) => {
217
217
  const e = t.querySelector("img");
218
- return e ? dt(e, t) : !1;
218
+ return e ? ht(e, t) : !1;
219
219
  },
220
220
  contentElement: (t) => t.querySelector("figcaption") ?? document.createElement("figcaption")
221
221
  }
222
222
  ],
223
223
  toDOM: (t) => {
224
- const e = In[t.attrs.align];
225
- return ["figure", e ? { style: e } : {}, ["img", Be(t.attrs, !1)], ["figcaption", 0]];
224
+ const e = Fn[t.attrs.align];
225
+ return ["figure", e ? { style: e } : {}, ["img", Ue(t.attrs, !1)], ["figcaption", 0]];
226
226
  }
227
227
  },
228
228
  hard_break: {
@@ -232,7 +232,7 @@ const On = {
232
232
  parseDOM: [{ tag: "br" }],
233
233
  toDOM: () => ["br"]
234
234
  }
235
- }, $n = {
235
+ }, _n = {
236
236
  link: {
237
237
  attrs: { href: {}, title: { default: null }, target: { default: null } },
238
238
  inclusive: !1,
@@ -294,14 +294,14 @@ const On = {
294
294
  {
295
295
  tag: "span",
296
296
  getAttrs: (t) => {
297
- const e = at(t.style.color);
297
+ const e = lt(t.style.color);
298
298
  return e ? { color: e } : !1;
299
299
  }
300
300
  },
301
301
  {
302
302
  tag: "font[color]",
303
303
  getAttrs: (t) => {
304
- const e = at(t.getAttribute("color"));
304
+ const e = lt(t.getAttribute("color"));
305
305
  return e ? { color: e } : !1;
306
306
  }
307
307
  }
@@ -331,80 +331,80 @@ const On = {
331
331
  }
332
332
  }
333
333
  ],
334
- toDOM: (t) => ["mark", { style: `background-color: ${oe(t.attrs.color) ?? "#fef08a"}` }, 0]
334
+ toDOM: (t) => ["mark", { style: `background-color: ${re(t.attrs.color) ?? "#fef08a"}` }, 0]
335
335
  },
336
336
  code: {
337
337
  parseDOM: [{ tag: "code" }],
338
338
  toDOM: () => ["code", 0]
339
339
  }
340
- }, ht = new Tt({ nodes: On, marks: $n }), p = new Tt({
341
- nodes: Zt(ht.spec.nodes, "paragraph block*", "block"),
342
- marks: ht.spec.marks
343
- }), Rn = Qt.fromSchema(p), zn = Xt.fromSchema(p);
344
- function ge(t) {
340
+ }, mt = new Ht({ nodes: Pn, marks: _n }), p = new Ht({
341
+ nodes: sn(mt.spec.nodes, "paragraph block*", "block"),
342
+ marks: mt.spec.marks
343
+ }), Wn = an.fromSchema(p), qn = on.fromSchema(p);
344
+ function be(t) {
345
345
  const e = new window.DOMParser().parseFromString(`<!doctype html><body>${t}`, "text/html");
346
- return zn.parse(e.body);
346
+ return qn.parse(e.body);
347
347
  }
348
- function be(t) {
349
- if ($t(t)) return "";
348
+ function we(t) {
349
+ if (Ut(t)) return "";
350
350
  const e = document.createElement("div");
351
- return e.append(Rn.serializeFragment(t.content)), e.querySelectorAll("[style]").forEach((n) => n.setAttribute("style", Fn(n.getAttribute("style") ?? ""))), e.innerHTML;
351
+ return e.append(Wn.serializeFragment(t.content)), e.querySelectorAll("[style]").forEach((n) => n.setAttribute("style", jn(n.getAttribute("style") ?? ""))), e.innerHTML;
352
352
  }
353
- const Bn = (t, e, n, r) => "#" + [e, n, r].map((o) => (+o).toString(16).padStart(2, "0")).join("");
354
- function Fn(t) {
353
+ const Gn = (t, e, n, r) => "#" + [e, n, r].map((o) => (+o).toString(16).padStart(2, "0")).join("");
354
+ function jn(t) {
355
355
  return t.split(";").map((e) => e.trim()).filter(Boolean).map(
356
- (e) => e.replace(/rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/g, Bn).replace(/(^|[\s:])0px(?![\w.])/g, (n, r) => `${r}0`).replace(/\s*:\s*/, ": ")
356
+ (e) => e.replace(/rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/g, Gn).replace(/(^|[\s:])0px(?![\w.])/g, (n, r) => `${r}0`).replace(/\s*:\s*/, ": ")
357
357
  ).join("; ");
358
358
  }
359
- function $t(t) {
359
+ function Ut(t) {
360
360
  const e = t.firstChild;
361
361
  return t.childCount === 1 && !!e && e.type === p.nodes.paragraph && e.content.size === 0 && !e.attrs.align;
362
362
  }
363
- const Fe = /* @__PURE__ */ new Set(["UL", "OL", "BLOCKQUOTE", "TABLE", "THEAD", "TBODY", "TFOOT", "TR", "FIGURE"]), Ue = /* @__PURE__ */ new Set(["LI", "TH", "TD"]), pt = (t) => t.nodeType === 1 && (Fe.has(t.tagName) || Ue.has(t.tagName) || /^(P|H[1-6]|PRE|HR|FIGCAPTION|IMG|DIV)$/.test(t.tagName)), Un = (t) => {
363
+ const Pe = /* @__PURE__ */ new Set(["UL", "OL", "BLOCKQUOTE", "TABLE", "THEAD", "TBODY", "TFOOT", "TR", "FIGURE"]), _e = /* @__PURE__ */ new Set(["LI", "TH", "TD"]), ft = (t) => t.nodeType === 1 && (Pe.has(t.tagName) || _e.has(t.tagName) || /^(P|H[1-6]|PRE|HR|FIGCAPTION|IMG|DIV)$/.test(t.tagName)), Vn = (t) => {
364
364
  const n = t.cloneNode(!1).outerHTML;
365
365
  return n.slice(0, n.length - `</${t.localName}>`.length);
366
366
  };
367
- function mt(t) {
367
+ function gt(t) {
368
368
  const e = document.createElement("div");
369
369
  e.innerHTML = t;
370
370
  const n = [], r = (o, s) => {
371
- const l = " ".repeat(s);
371
+ const c = " ".repeat(s);
372
372
  let d = "";
373
373
  const i = () => {
374
- d.trim() && n.push(l + d.trim()), d = "";
374
+ d.trim() && n.push(c + d.trim()), d = "";
375
375
  };
376
376
  o.childNodes.forEach((a) => {
377
- if (!pt(a)) {
378
- d += a.nodeType === 1 ? a.outerHTML : a.nodeType === 3 ? Pn(a.textContent ?? "") : "";
377
+ if (!ft(a)) {
378
+ d += a.nodeType === 1 ? a.outerHTML : a.nodeType === 3 ? Kn(a.textContent ?? "") : "";
379
379
  return;
380
380
  }
381
381
  i();
382
- const c = a, u = Array.from(c.childNodes).filter(pt);
383
- (Ue.has(c.tagName) ? u.length <= 1 && u.every((g) => !Fe.has(g.tagName) && !Ue.has(g.tagName)) : !Fe.has(c.tagName)) ? n.push(l + c.outerHTML) : (n.push(l + Un(c)), r(c, s + 1), n.push(`${l}</${c.localName}>`));
382
+ const l = a, u = Array.from(l.childNodes).filter(ft);
383
+ (_e.has(l.tagName) ? u.length <= 1 && u.every((g) => !Pe.has(g.tagName) && !_e.has(g.tagName)) : !Pe.has(l.tagName)) ? n.push(c + l.outerHTML) : (n.push(c + Vn(l)), r(l, s + 1), n.push(`${c}</${l.localName}>`));
384
384
  }), i();
385
385
  };
386
386
  return r(e, 0), n.join(`
387
387
  `);
388
388
  }
389
- const Pn = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/ /g, "&nbsp;");
389
+ const Kn = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/ /g, "&nbsp;");
390
390
  function de(t, e) {
391
391
  const { from: n, $from: r, to: o, empty: s } = t.selection;
392
392
  return s ? !!e.isInSet(t.storedMarks || r.marks()) : t.doc.rangeHasMark(n, o, e);
393
393
  }
394
- function _n(t) {
394
+ function Yn(t) {
395
395
  const e = t.selection.$from.parent;
396
396
  return e.type === p.nodes.paragraph ? "paragraph" : e.type === p.nodes.code_block ? "codeBlock" : e.type === p.nodes.heading ? `heading${e.attrs.level}` : null;
397
397
  }
398
- function Wn(t) {
398
+ function Jn(t) {
399
399
  return t === "paragraph" ? De(p.nodes.paragraph) : t === "codeBlock" ? De(p.nodes.code_block) : De(p.nodes.heading, { level: Number(t.slice(-1)) });
400
400
  }
401
- const _ = (t) => yn(p.marks[t]);
402
- function Rt(t, e) {
401
+ const _ = (t) => Sn(p.marks[t]);
402
+ function Pt(t, e) {
403
403
  const { $from: n } = t.selection;
404
404
  for (let r = n.depth; r > 0; r--) if (n.node(r).type === e) return !0;
405
405
  return !1;
406
406
  }
407
- function ft(t) {
407
+ function bt(t) {
408
408
  const { $from: e } = t.selection;
409
409
  for (let n = e.depth; n > 0; n--) {
410
410
  const r = e.node(n).type;
@@ -412,104 +412,104 @@ function ft(t) {
412
412
  }
413
413
  return null;
414
414
  }
415
- function gt(t) {
415
+ function wt(t) {
416
416
  return (e, n, r) => {
417
417
  const { $from: o } = e.selection;
418
418
  for (let s = o.depth; s > 0; s--) {
419
- const l = o.node(s);
420
- if (l.type === p.nodes.bullet_list || l.type === p.nodes.ordered_list)
421
- return l.type === t ? Nt(p.nodes.list_item)(e, n, r) : (n && n(e.tr.setNodeMarkup(o.before(s), t)), !0);
419
+ const c = o.node(s);
420
+ if (c.type === p.nodes.bullet_list || c.type === p.nodes.ordered_list)
421
+ return c.type === t ? $t(p.nodes.list_item)(e, n, r) : (n && n(e.tr.setNodeMarkup(o.before(s), t)), !0);
422
422
  }
423
- return tn(t)(e, n, r);
423
+ return cn(t)(e, n, r);
424
424
  };
425
425
  }
426
- const Pe = en(p.nodes.list_item), _e = (t, e, n) => Nt(p.nodes.list_item)(t, e, n) || Ht(t, e);
427
- function qn() {
428
- return (t, e) => Rt(t, p.nodes.blockquote) ? Ht(t, e) : vn(p.nodes.blockquote)(t, e);
426
+ const We = ln(p.nodes.list_item), qe = (t, e, n) => $t(p.nodes.list_item)(t, e, n) || Bt(t, e);
427
+ function Xn() {
428
+ return (t, e) => Pt(t, p.nodes.blockquote) ? Bt(t, e) : An(p.nodes.blockquote)(t, e);
429
429
  }
430
- function j(t) {
431
- return (e, n) => {
432
- const r = t === "left" ? null : t, { from: o, to: s } = e.selection, l = e.tr;
433
- let d = !1;
434
- return e.doc.nodesBetween(o, s, (i, a) => i.type === p.nodes.paragraph || i.type === p.nodes.heading ? (d = !0, i.attrs.align !== r && l.setNodeMarkup(a, void 0, { ...i.attrs, align: r }), !1) : !0), d ? (n && n(l), !0) : !1;
430
+ function yt(t, e = "left") {
431
+ return (n, r) => {
432
+ const o = t === e ? null : t, { from: s, to: c } = n.selection, d = n.tr;
433
+ let i = !1;
434
+ return n.doc.nodesBetween(s, c, (a, l) => a.type === p.nodes.paragraph || a.type === p.nodes.heading ? (i = !0, a.attrs.align !== o && d.setNodeMarkup(l, void 0, { ...a.attrs, align: o }), !1) : !0), i ? (r && r(d), !0) : !1;
435
435
  };
436
436
  }
437
- function we(t) {
438
- return t.selection.$from.parent.attrs.align ?? "left";
437
+ function Qn(t, e = "left") {
438
+ return t.selection.$from.parent.attrs.align ?? e;
439
439
  }
440
- const Gn = (t, e) => {
440
+ const Zn = (t, e) => {
441
441
  const n = p.nodes.horizontal_rule;
442
442
  if (!e) return !0;
443
443
  const r = t.tr.replaceSelectionWith(n.create()), o = r.selection.$from;
444
444
  return !o.nodeAfter && o.parent.type === p.nodes.doc && r.insert(o.pos, p.nodes.paragraph.create()), e(r.scrollIntoView()), !0;
445
- }, jn = (t, e) => {
445
+ }, er = (t, e) => {
446
446
  const { from: n, to: r, empty: o } = t.selection, s = t.tr;
447
447
  if (o)
448
448
  s.setStoredMarks([]);
449
449
  else
450
- for (const l of Object.values(p.marks)) l !== p.marks.link && s.removeMark(n, r, l);
451
- return t.doc.nodesBetween(n, r, (l, d) => l.isTextblock && l.type !== p.nodes.paragraph ? (s.setBlockType(d, d + l.nodeSize, p.nodes.paragraph), !1) : (l.type === p.nodes.paragraph && l.attrs.align && s.setNodeMarkup(d, void 0, { align: null }), !0)), e && e(s), !0;
450
+ for (const c of Object.values(p.marks)) c !== p.marks.link && s.removeMark(n, r, c);
451
+ return t.doc.nodesBetween(n, r, (c, d) => c.isTextblock && c.type !== p.nodes.paragraph ? (s.setBlockType(d, d + c.nodeSize, p.nodes.paragraph), !1) : (c.type === p.nodes.paragraph && c.attrs.align && s.setNodeMarkup(d, void 0, { align: null }), !0)), e && e(s), !0;
452
452
  };
453
- function We(t) {
453
+ function Ge(t) {
454
454
  const e = p.marks.link, { $from: n, from: r, to: o, empty: s } = t.selection;
455
455
  if (!s) {
456
456
  let u = null;
457
457
  return t.doc.nodesBetween(r, o, (m, g) => {
458
- const v = e.isInSet(m.marks);
459
- v && !u && (u = { from: Math.max(g, r), to: Math.min(g + m.nodeSize, o), ...v.attrs });
458
+ const k = e.isInSet(m.marks);
459
+ k && !u && (u = { from: Math.max(g, r), to: Math.min(g + m.nodeSize, o), ...k.attrs });
460
460
  }), u;
461
461
  }
462
- const l = e.isInSet(n.marks()) ?? e.isInSet(n.nodeBefore?.marks ?? []);
463
- if (!l) return null;
462
+ const c = e.isInSet(n.marks()) ?? e.isInSet(n.nodeBefore?.marks ?? []);
463
+ if (!c) return null;
464
464
  const d = n.start(), i = [];
465
465
  let a = 0;
466
466
  n.parent.forEach((u) => {
467
467
  const m = d + a, g = m + u.nodeSize;
468
- if (l.isInSet(u.marks)) {
469
- const v = i[i.length - 1];
470
- v && v[1] === m ? v[1] = g : i.push([m, g]);
468
+ if (c.isInSet(u.marks)) {
469
+ const k = i[i.length - 1];
470
+ k && k[1] === m ? k[1] = g : i.push([m, g]);
471
471
  }
472
472
  a += u.nodeSize;
473
473
  });
474
- const c = i.find(([u, m]) => u <= n.pos && n.pos <= m);
475
- return c ? { from: c[0], to: c[1], ...l.attrs } : null;
474
+ const l = i.find(([u, m]) => u <= n.pos && n.pos <= m);
475
+ return l ? { from: l[0], to: l[1], ...c.attrs } : null;
476
476
  }
477
- function qe(t) {
477
+ function je(t) {
478
478
  const e = t.selection;
479
479
  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;
480
480
  }
481
- function bt(t, e, n) {
481
+ function vt(t, e, n) {
482
482
  const r = p.nodes.figure.create(n), o = t.doc.resolve(e), s = o.parent;
483
483
  s.type === p.nodes.paragraph && s.childCount === 1 ? t.replaceWith(o.before(), o.after(), r) : t.replaceRangeWith(e, e + 1, r);
484
- let l = -1;
485
- 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(Ve.create(t.doc, l + 1)), t;
484
+ let c = -1;
485
+ return t.doc.descendants((d, i) => c >= 0 ? !1 : (d.type === p.nodes.figure && d.attrs.src === n.src && d.content.size === 0 && (c = i), !0)), c >= 0 && t.setSelection(Ye.create(t.doc, c + 1)), t;
486
486
  }
487
- function Vn(t, e, n, r) {
487
+ function tr(t, e, n, r) {
488
488
  const o = p.nodes.image.create(r), s = [p.nodes.paragraph.create(null, o)];
489
- return n.content.size && s.push(p.nodes.paragraph.create(null, n.content)), t.replaceWith(e, e + n.nodeSize, Ct.from(s)), t.setSelection(he.create(t.doc, e + 1));
489
+ return n.content.size && s.push(p.nodes.paragraph.create(null, n.content)), t.replaceWith(e, e + n.nodeSize, Ot.from(s)), t.setSelection(he.create(t.doc, e + 1));
490
490
  }
491
- function Kn(t, e, n = !0) {
491
+ function nr(t, e, n = !0) {
492
492
  const r = p.nodes, o = (s) => r.table_row.create(null, Array.from({ length: e }, () => s.createAndFill()));
493
- return r.table.create(null, Array.from({ length: t }, (s, l) => o(n && l === 0 ? r.table_header : r.table_cell)));
493
+ return r.table.create(null, Array.from({ length: t }, (s, c) => o(n && c === 0 ? r.table_header : r.table_cell)));
494
494
  }
495
- function Yn(t, e) {
495
+ function rr(t, e) {
496
496
  return (n, r) => {
497
- if (pe(n)) return !1;
497
+ if (me(n)) return !1;
498
498
  if (!r) return !0;
499
- const o = Kn(t, e), s = n.tr, l = n.selection.$from;
500
- l.parent.type === p.nodes.paragraph && l.parent.content.size === 0 && l.depth === 1 ? s.replaceWith(l.before(), l.after(), o) : s.replaceSelectionWith(o);
499
+ const o = nr(t, e), s = n.tr, c = n.selection.$from;
500
+ c.parent.type === p.nodes.paragraph && c.parent.content.size === 0 && c.depth === 1 ? s.replaceWith(c.before(), c.after(), o) : s.replaceSelectionWith(o);
501
501
  let i = -1;
502
- if (s.doc.descendants((a, c) => i >= 0 ? !1 : (a === o && (i = c), i < 0 && a.type !== p.nodes.table)), i >= 0) {
502
+ if (s.doc.descendants((a, l) => i >= 0 ? !1 : (a === o && (i = l), i < 0 && a.type !== p.nodes.table)), i >= 0) {
503
503
  const a = i + s.doc.nodeAt(i).nodeSize;
504
- a >= s.doc.content.size && s.insert(a, p.nodes.paragraph.create()), s.setSelection(Ve.create(s.doc, i + 4));
504
+ a >= s.doc.content.size && s.insert(a, p.nodes.paragraph.create()), s.setSelection(Ye.create(s.doc, i + 4));
505
505
  }
506
506
  return r(s.scrollIntoView()), !0;
507
507
  };
508
508
  }
509
- const Jn = (t, e, n) => pe(t) ? ze(1)(t, e) || !e || !n ? !0 : (It(t, e), ze(1)(n.state, e)) : !1, Xn = (t, e) => pe(t) && ze(-1)(t, e);
510
- function Ge(t, e) {
511
- const n = p.marks[e], { from: r, to: o, empty: s, $from: l } = t.selection;
512
- if (s) return n.isInSet(t.storedMarks || l.marks())?.attrs.color ?? null;
509
+ const or = (t, e, n) => me(t) ? Fe(1)(t, e) || !e || !n ? !0 : (zt(t, e), Fe(1)(n.state, e)) : !1, ir = (t, e) => me(t) && Fe(-1)(t, e);
510
+ function Ve(t, e) {
511
+ const n = p.marks[e], { from: r, to: o, empty: s, $from: c } = t.selection;
512
+ if (s) return n.isInSet(t.storedMarks || c.marks())?.attrs.color ?? null;
513
513
  let d;
514
514
  return t.doc.nodesBetween(r, o, (i) => {
515
515
  if (!i.isText || d === null) return;
@@ -517,19 +517,19 @@ function Ge(t, e) {
517
517
  d = d === void 0 || d === a ? a : null;
518
518
  }), d ?? null;
519
519
  }
520
- function Qn(t, e) {
520
+ function ar(t, e) {
521
521
  return (n, r) => {
522
- const o = p.marks[t], { from: s, to: l, empty: d } = n.selection;
522
+ const o = p.marks[t], { from: s, to: c, empty: d } = n.selection;
523
523
  if (!r) return !0;
524
524
  const i = n.tr;
525
- return d ? (i.removeStoredMark(o), e && i.addStoredMark(o.create({ color: e }))) : (i.removeMark(s, l, o), e && i.addMark(s, l, o.create({ color: e }))), r(i.scrollIntoView()), !0;
525
+ return d ? (i.removeStoredMark(o), e && i.addStoredMark(o.create({ color: e }))) : (i.removeMark(s, c, o), e && i.addMark(s, c, o.create({ color: e }))), r(i.scrollIntoView()), !0;
526
526
  };
527
527
  }
528
- function Zn() {
528
+ function sr() {
529
529
  const t = p.nodes;
530
- return gn({
530
+ return Ln({
531
531
  rules: [
532
- rt(/^(#{1,4})\s$/, t.heading, (e) => ({ level: e[1].length })),
532
+ it(/^(#{1,4})\s$/, t.heading, (e) => ({ level: e[1].length })),
533
533
  Ce(/^\s*>\s$/, t.blockquote),
534
534
  Ce(/^\s*([-+*])\s$/, t.bullet_list),
535
535
  Ce(
@@ -538,23 +538,23 @@ function Zn() {
538
538
  (e) => ({ order: +e[1] }),
539
539
  (e, n) => n.childCount + n.attrs.order === +e[1]
540
540
  ),
541
- rt(/^```$/, t.code_block),
542
- new bn(/^(?:---|\*\*\*|___)$/, (e, n, r, o) => {
541
+ it(/^```$/, t.code_block),
542
+ new xn(/^(?:---|\*\*\*|___)$/, (e, n, r, o) => {
543
543
  const s = e.doc.resolve(r);
544
544
  if (s.parent.type !== t.paragraph) return null;
545
- const l = s.before();
546
- return e.tr.replaceWith(l, o + 1, [t.horizontal_rule.create(), t.paragraph.create()]);
545
+ const c = s.before();
546
+ return e.tr.replaceWith(c, o + 1, [t.horizontal_rule.create(), t.paragraph.create()]);
547
547
  })
548
548
  ]
549
549
  });
550
550
  }
551
- function er(t) {
552
- const e = kn(Mn, (n, r) => (r && r(n.tr.replaceSelectionWith(p.nodes.hard_break.create()).scrollIntoView()), !0));
553
- return Ke({
554
- "Mod-z": At,
555
- "Mod-y": Re,
556
- "Shift-Mod-z": Re,
557
- Backspace: wn,
551
+ function lr(t) {
552
+ const e = Tn(Cn, (n, r) => (r && r(n.tr.replaceSelectionWith(p.nodes.hard_break.create()).scrollIntoView()), !0));
553
+ return Je({
554
+ "Mod-z": It,
555
+ "Mod-y": Be,
556
+ "Shift-Mod-z": Be,
557
+ Backspace: En,
558
558
  "Mod-b": _("strong"),
559
559
  "Mod-i": _("em"),
560
560
  "Mod-u": _("underline"),
@@ -563,47 +563,47 @@ function er(t) {
563
563
  "Mod-k": t.link,
564
564
  "Shift-Enter": e,
565
565
  "Mod-Enter": e,
566
- Enter: nn(p.nodes.list_item),
567
- Tab: Pe,
568
- "Shift-Tab": _e
566
+ Enter: dn(p.nodes.list_item),
567
+ Tab: We,
568
+ "Shift-Tab": qe
569
569
  });
570
570
  }
571
- const tr = () => Ke(Ln);
572
- function nr(t) {
573
- return new xt({
571
+ const cr = () => Je(Dn);
572
+ function dr(t) {
573
+ return new Ct({
574
574
  props: {
575
575
  decorations(e) {
576
576
  const n = e.doc, r = n.firstChild;
577
- return !t || n.childCount !== 1 || !r || !r.isTextblock || r.content.size > 0 ? null : Et.create(n, [
578
- St.node(0, r.nodeSize, { class: "wds-placeholder", "data-placeholder": t })
577
+ return !t || n.childCount !== 1 || !r || !r.isTextblock || r.content.size > 0 ? null : Dt.create(n, [
578
+ Nt.node(0, r.nodeSize, { class: "wds-placeholder", "data-placeholder": t })
579
579
  ]);
580
580
  }
581
581
  }
582
582
  });
583
583
  }
584
- const Q = new Gt("wds-upload");
585
- function rr() {
586
- return new xt({
587
- key: Q,
584
+ const X = new Qt("wds-upload");
585
+ function ur() {
586
+ return new Ct({
587
+ key: X,
588
588
  state: {
589
- init: () => Et.empty,
589
+ init: () => Dt.empty,
590
590
  apply(t, e) {
591
591
  e = e.map(t.mapping, t.doc);
592
- const n = t.getMeta(Q);
592
+ const n = t.getMeta(X);
593
593
  if (n && "add" in n) {
594
594
  const r = document.createElement("span");
595
- r.className = "wds-upload-placeholder", r.setAttribute("aria-hidden", "true"), e = e.add(t.doc, [St.widget(n.add.pos, r, { id: n.add.id })]);
595
+ r.className = "wds-upload-placeholder", r.setAttribute("aria-hidden", "true"), e = e.add(t.doc, [Nt.widget(n.add.pos, r, { id: n.add.id })]);
596
596
  } else n && "remove" in n && (e = e.remove(e.find(void 0, void 0, (r) => r.id === n.remove.id)));
597
597
  return e;
598
598
  }
599
599
  },
600
600
  props: {
601
- decorations: (t) => Q.getState(t)
601
+ decorations: (t) => X.getState(t)
602
602
  }
603
603
  });
604
604
  }
605
- function or(t, e) {
606
- const n = Q.getState(t)?.find(void 0, void 0, (r) => r.id === e);
605
+ function hr(t, e) {
606
+ const n = X.getState(t)?.find(void 0, void 0, (r) => r.id === e);
607
607
  return n && n.length ? n[0].from : null;
608
608
  }
609
609
  const E = (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>`, L = {
@@ -628,6 +628,7 @@ const E = (t) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" st
628
628
  clear: E('<path d="M6 5h12"/><path d="M12 5 9 19"/><path d="m15 14 5 5M20 14l-5 5"/>'),
629
629
  source: E('<path d="m8 7-5 5 5 5"/><path d="m16 7 5 5-5 5"/><path d="m14 4-4 16"/>'),
630
630
  fullscreen: E('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),
631
+ chevron: '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="m6 9 6 6 6-6"/></svg>',
631
632
  close: E('<path d="M6 6l12 12M18 6 6 18"/>'),
632
633
  image: E('<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"/>'),
633
634
  file: E('<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"/>'),
@@ -642,36 +643,150 @@ const E = (t) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" st
642
643
  textColor: E('<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"/>'),
643
644
  highlight: E('<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"/>'),
644
645
  globe: E('<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"/>')
645
- }, H = (t) => (e) => e.exec(t), ir = {
646
- undo: { type: "button", label: "undo", icon: L.undo, shortcut: "Mod+Z", run: (t) => t.undo(), enabled: (t) => Yt(t) > 0 },
647
- redo: { type: "button", label: "redo", icon: L.redo, shortcut: "Mod+Y", run: (t) => t.redo(), enabled: (t) => Kt(t) > 0 },
646
+ }, oe = (t) => getComputedStyle(t).direction === "rtl";
647
+ let ve = null;
648
+ function _t() {
649
+ ve?.close();
650
+ }
651
+ function Xe(t, e, n, r) {
652
+ _t();
653
+ const o = document.createElement("div");
654
+ o.className = `wds-menu ${n}`, e.append(o);
655
+ const s = () => {
656
+ const u = t.getBoundingClientRect();
657
+ o.style.maxHeight = "";
658
+ const m = o.offsetWidth, g = o.offsetHeight, k = oe(e) ? u.right - m : u.left;
659
+ o.style.left = `${Math.max(4, Math.min(k, window.innerWidth - m - 4))}px`;
660
+ const D = window.innerHeight - u.bottom - 8, A = u.top - 8;
661
+ g <= D || D >= A ? (o.style.top = `${u.bottom + 4}px`, g > D && (o.style.maxHeight = `${D}px`)) : (o.style.top = `${Math.max(4, u.top - Math.min(g, A) - 4)}px`, g > A && (o.style.maxHeight = `${A}px`));
662
+ }, c = (u) => {
663
+ if (u.target instanceof Node && o.contains(u.target)) return;
664
+ const m = t.getBoundingClientRect();
665
+ m.bottom < 0 || m.top > window.innerHeight || !t.isConnected ? l() : s();
666
+ };
667
+ t.setAttribute("aria-expanded", "true");
668
+ const d = (u) => {
669
+ !o.contains(u.target) && u.target !== t && !t.contains(u.target) && l();
670
+ }, i = (u) => {
671
+ u.key === "Escape" && (u.preventDefault(), u.stopPropagation(), l(!0));
672
+ };
673
+ let a = !1;
674
+ function l(u = !1) {
675
+ a || (a = !0, o.remove(), t.setAttribute("aria-expanded", "false"), document.removeEventListener("mousedown", d, !0), window.removeEventListener("scroll", c, !0), window.removeEventListener("resize", c), o.removeEventListener("keydown", i), ve?.close === l && (ve = null), u && t.focus());
676
+ }
677
+ return document.addEventListener("mousedown", d, !0), window.addEventListener("scroll", c, !0), window.addEventListener("resize", c), o.addEventListener("keydown", i), ve = { close: l }, { popup: o, place: s, close: l };
678
+ }
679
+ function pr(t, e, n, r) {
680
+ const { popup: o, place: s, close: c } = Xe(t, e, "wds-menu-list");
681
+ o.setAttribute("role", "menu"), o.setAttribute("aria-label", r);
682
+ for (const i of n) {
683
+ if (i === "|") {
684
+ const l = document.createElement("div");
685
+ l.className = "wds-menu-sep", l.setAttribute("role", "separator"), o.append(l);
686
+ continue;
687
+ }
688
+ const a = document.createElement("button");
689
+ a.type = "button", a.className = `wds-menu-item${i.danger ? " is-danger" : ""}`, a.setAttribute("role", "menuitem"), a.tabIndex = -1, a.innerHTML = i.icon ?? "", a.append(document.createTextNode(i.label)), i.enabled === !1 && (a.disabled = !0), a.addEventListener("mousedown", (l) => l.preventDefault()), a.addEventListener("click", () => {
690
+ c(), i.run();
691
+ }), o.append(a);
692
+ }
693
+ const d = () => [...o.querySelectorAll(".wds-menu-item:not(:disabled)")];
694
+ o.addEventListener("keydown", (i) => {
695
+ const a = d(), l = a.indexOf(document.activeElement);
696
+ let u = -1;
697
+ i.key === "ArrowDown" ? u = (l + 1) % a.length : i.key === "ArrowUp" ? u = (l - 1 + a.length) % a.length : i.key === "Home" ? u = 0 : i.key === "End" ? u = a.length - 1 : i.key === "Tab" && c(), u >= 0 && (i.preventDefault(), a[u]?.focus());
698
+ }), s(), d()[0]?.focus();
699
+ }
700
+ function mr(t, e, n, r, o) {
701
+ const { popup: d, place: i, close: a } = Xe(t, e, "wds-table-picker");
702
+ d.setAttribute("role", "dialog"), d.setAttribute("aria-label", n);
703
+ const l = document.createElement("div");
704
+ l.className = "wds-picker-grid", l.style.gridTemplateColumns = "repeat(10, 1fr)", l.tabIndex = 0, l.setAttribute("role", "grid"), l.setAttribute("aria-label", n);
705
+ const u = document.createElement("div");
706
+ u.className = "wds-picker-label", u.setAttribute("aria-live", "polite");
707
+ const m = [];
708
+ let g = 3, k = 3;
709
+ const D = () => {
710
+ m.forEach((A, C) => A.classList.toggle("is-on", Math.floor(C / 10) < g && C % 10 < k)), u.textContent = r(g, k), l.setAttribute("aria-valuetext", u.textContent);
711
+ };
712
+ for (let A = 0; A < 8; A++)
713
+ for (let C = 0; C < 10; C++) {
714
+ const I = document.createElement("span");
715
+ I.className = "wds-picker-cell", I.addEventListener("mouseenter", () => {
716
+ g = A + 1, k = C + 1, D();
717
+ }), I.addEventListener("mousedown", (y) => y.preventDefault()), I.addEventListener("click", () => {
718
+ a(), o(A + 1, C + 1);
719
+ }), m.push(I), l.append(I);
720
+ }
721
+ l.addEventListener("keydown", (A) => {
722
+ const C = oe(l) ? -1 : 1, I = { ArrowRight: [0, C], ArrowLeft: [0, -C], ArrowDown: [1, 0], ArrowUp: [-1, 0] };
723
+ I[A.key] ? (A.preventDefault(), g = Math.min(8, Math.max(1, g + I[A.key][0])), k = Math.min(10, Math.max(1, k + I[A.key][1])), D()) : A.key === "Enter" || A.key === " " ? (A.preventDefault(), a(), o(g, k)) : A.key === "Tab" && a();
724
+ }), d.append(l, u), D(), i(), l.focus();
725
+ }
726
+ function fr(t, e, n) {
727
+ const { popup: r, place: o, close: s } = Xe(t, e, "wds-color-picker");
728
+ r.setAttribute("role", "dialog"), r.setAttribute("aria-label", n.label);
729
+ const c = (a) => {
730
+ s(), n.onPick(a);
731
+ }, d = document.createElement("button");
732
+ 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", (a) => a.preventDefault()), d.addEventListener("click", () => c(null));
733
+ const i = document.createElement("div");
734
+ i.className = "wds-swatches", i.style.gridTemplateColumns = `repeat(${n.columns}, 1fr)`;
735
+ for (const a of n.swatches) {
736
+ const l = document.createElement("button");
737
+ l.type = "button", l.className = "wds-swatch", l.style.background = a.color, l.title = a.label, l.setAttribute("aria-label", a.label);
738
+ const u = a.color === n.current;
739
+ l.setAttribute("aria-pressed", String(u)), u && l.classList.add("is-current"), l.addEventListener("mousedown", (m) => m.preventDefault()), l.addEventListener("click", () => c(a.color)), i.append(l);
740
+ }
741
+ r.append(d, i), r.addEventListener("keydown", (a) => {
742
+ const l = [d, ...i.querySelectorAll(".wds-swatch")], u = l.indexOf(document.activeElement);
743
+ if (u < 0) return;
744
+ const m = n.columns;
745
+ let g = -1;
746
+ const k = oe(r) ? "ArrowLeft" : "ArrowRight", D = oe(r) ? "ArrowRight" : "ArrowLeft";
747
+ a.key === k ? g = Math.min(l.length - 1, u + 1) : a.key === D ? g = Math.max(0, u - 1) : a.key === "ArrowDown" ? g = u === 0 ? 1 : Math.min(l.length - 1, u + m) : a.key === "ArrowUp" ? g = u <= m ? 0 : u - m : a.key === "Tab" && s(), g >= 0 && (a.preventDefault(), l[g].focus());
748
+ }), o(), (i.querySelector(".is-current") ?? i.querySelector(".wds-swatch"))?.focus();
749
+ }
750
+ const R = (t) => (e) => e.exec(t), He = (t) => oe(t.root) ? "right" : "left", ye = (t) => {
751
+ const e = `align${t[0].toUpperCase()}${t.slice(1)}`;
752
+ return {
753
+ type: "button",
754
+ label: e,
755
+ icon: L[e],
756
+ run: (n) => n.exec(yt(t, He(n))),
757
+ active: (n, r) => Qn(n, He(r)) === t,
758
+ enabled: (n, r) => yt(t, He(r))(n)
759
+ };
760
+ }, gr = {
761
+ undo: { type: "button", label: "undo", icon: L.undo, shortcut: "Mod+Z", run: (t) => t.undo(), enabled: (t) => nn(t) > 0 },
762
+ redo: { type: "button", label: "redo", icon: L.redo, shortcut: "Mod+Y", run: (t) => t.redo(), enabled: (t) => tn(t) > 0 },
648
763
  blocks: { type: "blocks" },
649
- bold: { type: "button", label: "bold", icon: L.bold, shortcut: "Mod+B", run: H(_("strong")), active: (t) => de(t, p.marks.strong) },
650
- italic: { type: "button", label: "italic", icon: L.italic, shortcut: "Mod+I", run: H(_("em")), active: (t) => de(t, p.marks.em) },
651
- underline: { type: "button", label: "underline", icon: L.underline, shortcut: "Mod+U", run: H(_("underline")), active: (t) => de(t, p.marks.underline) },
652
- strike: { type: "button", label: "strike", icon: L.strike, run: H(_("strike")), active: (t) => de(t, p.marks.strike) },
653
- textColor: { type: "button", label: "textColor", icon: L.textColor, popup: !0, run: (t, e) => t.openColorPicker("textColor", e), swatch: (t) => Ge(t, "textColor") },
654
- highlight: { type: "button", label: "highlight", icon: L.highlight, popup: !0, run: (t, e) => t.openColorPicker("highlight", e), swatch: (t) => Ge(t, "highlight") },
655
- code: { type: "button", label: "code", icon: L.code, run: H(_("code")), active: (t) => de(t, p.marks.code) },
656
- link: { type: "button", label: "link", icon: L.link, shortcut: "Mod+K", run: (t) => t.openLinkDialog(), active: (t) => !!We(t) },
657
- image: { type: "button", label: "image", icon: L.image, run: (t) => t.openImageDialog(), active: (t) => !!qe(t) },
764
+ bold: { type: "button", label: "bold", icon: L.bold, shortcut: "Mod+B", run: R(_("strong")), active: (t) => de(t, p.marks.strong) },
765
+ italic: { type: "button", label: "italic", icon: L.italic, shortcut: "Mod+I", run: R(_("em")), active: (t) => de(t, p.marks.em) },
766
+ underline: { type: "button", label: "underline", icon: L.underline, shortcut: "Mod+U", run: R(_("underline")), active: (t) => de(t, p.marks.underline) },
767
+ strike: { type: "button", label: "strike", icon: L.strike, run: R(_("strike")), active: (t) => de(t, p.marks.strike) },
768
+ textColor: { type: "button", label: "textColor", icon: L.textColor, popup: !0, run: (t, e) => t.openColorPicker("textColor", e), swatch: (t) => Ve(t, "textColor") },
769
+ highlight: { type: "button", label: "highlight", icon: L.highlight, popup: !0, run: (t, e) => t.openColorPicker("highlight", e), swatch: (t) => Ve(t, "highlight") },
770
+ code: { type: "button", label: "code", icon: L.code, run: R(_("code")), active: (t) => de(t, p.marks.code) },
771
+ link: { type: "button", label: "link", icon: L.link, shortcut: "Mod+K", run: (t) => t.openLinkDialog(), active: (t) => !!Ge(t) },
772
+ image: { type: "button", label: "image", icon: L.image, run: (t) => t.openImageDialog(), active: (t) => !!je(t) },
658
773
  file: { type: "button", label: "file", icon: L.file, run: (t) => t.openFileManager("file"), available: (t) => t.hasFileManager() },
659
- table: { type: "button", label: "table", icon: L.table, popup: !0, run: (t, e) => t.openTableMenu(e), active: (t) => pe(t) },
660
- blockquote: { type: "button", label: "blockquote", icon: L.blockquote, run: H(qn()), active: (t) => Rt(t, p.nodes.blockquote) },
661
- bulletList: { type: "button", label: "bulletList", icon: L.bulletList, run: H(gt(p.nodes.bullet_list)), active: (t) => ft(t) === p.nodes.bullet_list },
662
- orderedList: { type: "button", label: "orderedList", icon: L.orderedList, run: H(gt(p.nodes.ordered_list)), active: (t) => ft(t) === p.nodes.ordered_list },
663
- outdent: { type: "button", label: "outdent", icon: L.outdent, run: H(_e), enabled: (t) => _e(t) },
664
- indent: { type: "button", label: "indent", icon: L.indent, run: H(Pe), enabled: (t) => Pe(t) },
665
- alignLeft: { type: "button", label: "alignLeft", icon: L.alignLeft, run: H(j("left")), active: (t) => we(t) === "left", enabled: (t) => j("left")(t) },
666
- alignCenter: { type: "button", label: "alignCenter", icon: L.alignCenter, run: H(j("center")), active: (t) => we(t) === "center", enabled: (t) => j("center")(t) },
667
- alignRight: { type: "button", label: "alignRight", icon: L.alignRight, run: H(j("right")), active: (t) => we(t) === "right", enabled: (t) => j("right")(t) },
668
- alignJustify: { type: "button", label: "alignJustify", icon: L.alignJustify, run: H(j("justify")), active: (t) => we(t) === "justify", enabled: (t) => j("justify")(t) },
669
- hr: { type: "button", label: "hr", icon: L.hr, run: H(Gn) },
670
- clear: { type: "button", label: "clear", icon: L.clear, run: H(jn) },
774
+ table: { type: "button", label: "table", icon: L.table, popup: !0, run: (t, e) => t.openTableMenu(e), active: (t) => me(t) },
775
+ blockquote: { type: "button", label: "blockquote", icon: L.blockquote, run: R(Xn()), active: (t) => Pt(t, p.nodes.blockquote) },
776
+ bulletList: { type: "button", label: "bulletList", icon: L.bulletList, run: R(wt(p.nodes.bullet_list)), active: (t) => bt(t) === p.nodes.bullet_list },
777
+ orderedList: { type: "button", label: "orderedList", icon: L.orderedList, run: R(wt(p.nodes.ordered_list)), active: (t) => bt(t) === p.nodes.ordered_list },
778
+ outdent: { type: "button", label: "outdent", icon: L.outdent, run: R(qe), enabled: (t) => qe(t) },
779
+ indent: { type: "button", label: "indent", icon: L.indent, run: R(We), enabled: (t) => We(t) },
780
+ alignLeft: ye("left"),
781
+ alignCenter: ye("center"),
782
+ alignRight: ye("right"),
783
+ alignJustify: ye("justify"),
784
+ hr: { type: "button", label: "hr", icon: L.hr, run: R(Zn) },
785
+ clear: { type: "button", label: "clear", icon: L.clear, run: R(er) },
671
786
  pasteText: { type: "button", label: "pasteText", icon: L.pasteText, run: (t) => t.togglePlainPaste(), active: (t, e) => e.isPlainPaste() },
672
787
  source: { type: "button", label: "source", icon: L.source, run: (t) => t.toggleSource(), active: (t, e) => e.isSourceMode(), inSource: !0 },
673
788
  fullscreen: { type: "button", label: "fullscreen", icon: L.fullscreen, run: (t) => t.toggleFullscreen(), active: (t, e) => e.isFullscreen(), inSource: !0 }
674
- }, ar = [
789
+ }, br = [
675
790
  "undo",
676
791
  "redo",
677
792
  "|",
@@ -706,15 +821,15 @@ const E = (t) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" st
706
821
  "|",
707
822
  "source",
708
823
  "fullscreen"
709
- ], sr = [
824
+ ], wr = [
710
825
  ["paragraph", "paragraph"],
711
826
  ["heading1", "heading1"],
712
827
  ["heading2", "heading2"],
713
828
  ["heading3", "heading3"],
714
829
  ["heading4", "heading4"],
715
830
  ["codeBlock", "codeBlock"]
716
- ], lr = typeof navigator < "u" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent), cr = (t) => t.replace("Mod", lr ? "⌘" : "Ctrl");
717
- function dr(t, e, n) {
831
+ ], yr = typeof navigator < "u" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent), vr = (t) => t.replace("Mod", yr ? "⌘" : "Ctrl");
832
+ function kr(t, e, n) {
718
833
  const r = document.createElement("div");
719
834
  r.className = "wds-toolbar", r.setAttribute("role", "toolbar"), r.setAttribute("aria-label", n.toolbarLabel);
720
835
  const o = [];
@@ -725,7 +840,7 @@ function dr(t, e, n) {
725
840
  s.childElementCount && (s = document.createElement("div"), s.className = "wds-group", r.append(s));
726
841
  continue;
727
842
  }
728
- const i = ir[d];
843
+ const i = gr[d];
729
844
  if (!i) {
730
845
  console.warn(`[WDS Editor] Unknown toolbar item "${d}".`);
731
846
  continue;
@@ -733,23 +848,23 @@ function dr(t, e, n) {
733
848
  if (i.type === "blocks") {
734
849
  const u = document.createElement("select");
735
850
  u.className = "wds-select", u.setAttribute("aria-label", n.blockType), u.title = n.blockType;
736
- for (const [g, v] of sr) {
851
+ for (const [g, k] of wr) {
737
852
  const D = document.createElement("option");
738
- D.value = g, D.textContent = n[v], u.append(D);
853
+ D.value = g, D.textContent = n[k], u.append(D);
739
854
  }
740
855
  const m = document.createElement("option");
741
856
  m.value = "", m.textContent = "—", m.hidden = !0, u.append(m), u.addEventListener("change", () => {
742
- u.value && t.exec(Wn(u.value)), t.focus();
857
+ u.value && t.exec(Jn(u.value)), t.focus();
743
858
  }), s.append(u), o.push((g) => {
744
- u.value = _n(g) ?? "", u.disabled = t.isSourceMode() || t.isReadOnly();
859
+ u.value = Yn(g) ?? "", u.disabled = t.isSourceMode() || t.isReadOnly();
745
860
  });
746
861
  continue;
747
862
  }
748
863
  if (i.available && !i.available(t)) continue;
749
864
  const a = document.createElement("button");
750
865
  a.type = "button", a.className = "wds-button-tool", a.innerHTML = i.icon;
751
- const c = n[i.label];
752
- a.setAttribute("aria-label", c), a.title = i.shortcut ? `${c} (${cr(i.shortcut)})` : c, a.dataset.item = d, i.popup && (a.setAttribute("aria-haspopup", "true"), a.setAttribute("aria-expanded", "false")), a.addEventListener("mousedown", (u) => u.preventDefault()), a.addEventListener("click", () => {
866
+ const l = n[i.label];
867
+ a.setAttribute("aria-label", l), a.title = i.shortcut ? `${l} (${vr(i.shortcut)})` : l, a.dataset.item = d, i.popup && (a.setAttribute("aria-haspopup", "true"), a.setAttribute("aria-expanded", "false")), a.addEventListener("mousedown", (u) => u.preventDefault()), a.addEventListener("click", () => {
753
868
  a.disabled || i.run(t, a);
754
869
  }), s.append(a), o.push((u) => {
755
870
  const m = t.isSourceMode() && !i.inSource || t.isReadOnly() && !i.inSource;
@@ -768,69 +883,69 @@ function dr(t, e, n) {
768
883
  const i = [...r.querySelectorAll("button:not([disabled]), select:not([disabled])")], a = i.indexOf(document.activeElement);
769
884
  if (a < 0) return;
770
885
  d.preventDefault();
771
- const c = d.key === "Home" ? 0 : d.key === "End" ? i.length - 1 : (a + (d.key === "ArrowRight" ? 1 : -1) + i.length) % i.length;
772
- i.forEach((u) => u.tabIndex = -1), i[c].tabIndex = 0, i[c].focus();
886
+ const l = d.key === "Home" ? 0 : d.key === "End" ? i.length - 1 : (a + (d.key === "ArrowRight" !== oe(r) ? 1 : -1) + i.length) % i.length;
887
+ i.forEach((u) => u.tabIndex = -1), i[l].tabIndex = 0, i[l].focus();
773
888
  }), { element: r, update: (d) => {
774
889
  o.forEach((a) => a(d));
775
890
  const i = [...r.querySelectorAll("button, select")];
776
891
  if (!i.some((a) => a.tabIndex === 0 && !a.disabled)) {
777
- i.forEach((c) => c.tabIndex = -1);
778
- const a = i.find((c) => !c.disabled);
892
+ i.forEach((l) => l.tabIndex = -1);
893
+ const a = i.find((l) => !l.disabled);
779
894
  a && (a.tabIndex = 0);
780
895
  }
781
896
  } };
782
897
  }
783
- function zt(t, e, n, r) {
898
+ function Wt(t, e, n, r) {
784
899
  const o = document.createElement("span");
785
900
  o.className = "wds-image";
786
901
  const s = document.createElement("img");
787
902
  s.draggable = !1;
788
- const l = document.createElement("span");
789
- l.className = "wds-resize-handle", l.title = r.resizeLabel, l.setAttribute("aria-hidden", "true"), o.append(s, l);
903
+ const c = document.createElement("span");
904
+ c.className = "wds-resize-handle", c.title = r.resizeLabel, c.setAttribute("aria-hidden", "true"), o.append(s, c);
790
905
  const d = () => {
791
- const c = e();
792
- c !== void 0 && t.dispatch(t.state.tr.setSelection(he.create(t.state.doc, c)));
906
+ const l = e();
907
+ l !== void 0 && t.dispatch(t.state.tr.setSelection(he.create(t.state.doc, l)));
793
908
  };
794
909
  let i = !1;
795
- return l.addEventListener("pointerdown", (c) => {
910
+ return c.addEventListener("pointerdown", (l) => {
796
911
  if (!t.editable) return;
797
- c.preventDefault(), c.stopPropagation(), d(), i = !0;
912
+ l.preventDefault(), l.stopPropagation(), d(), i = !0;
798
913
  try {
799
- l.setPointerCapture(c.pointerId);
914
+ c.setPointerCapture(l.pointerId);
800
915
  } catch {
801
916
  }
802
- const u = c.clientX, m = s.getBoundingClientRect().width, g = Math.max(40, t.dom.clientWidth - 8);
803
- let v = m;
804
- const D = (T) => {
805
- v = Math.round(Math.min(g, Math.max(40, m + T.clientX - u))), s.style.width = `${v}px`, s.style.height = "auto", o.dataset.size = `${v}px`;
806
- }, C = () => {
807
- i = !1, window.removeEventListener("pointermove", D), window.removeEventListener("pointerup", C), window.removeEventListener("pointercancel", C), delete o.dataset.size, s.style.width = "", s.style.height = "";
808
- const T = e();
809
- if (T === void 0 || Math.abs(v - m) < 2) return;
810
- const O = n(), y = t.state.tr.setNodeMarkup(T, void 0, { ...O.attrs, width: v, height: null });
811
- t.dispatch(y.setSelection(he.create(y.doc, T)));
917
+ const u = l.clientX, m = s.getBoundingClientRect().width, g = Math.max(40, t.dom.clientWidth - 8);
918
+ let k = m;
919
+ const D = (C) => {
920
+ k = Math.round(Math.min(g, Math.max(40, m + C.clientX - u))), s.style.width = `${k}px`, s.style.height = "auto", o.dataset.size = `${k}px`;
921
+ }, A = () => {
922
+ i = !1, window.removeEventListener("pointermove", D), window.removeEventListener("pointerup", A), window.removeEventListener("pointercancel", A), delete o.dataset.size, s.style.width = "", s.style.height = "";
923
+ const C = e();
924
+ if (C === void 0 || Math.abs(k - m) < 2) return;
925
+ const I = n(), y = t.state.tr.setNodeMarkup(C, void 0, { ...I.attrs, width: k, height: null });
926
+ t.dispatch(y.setSelection(he.create(y.doc, C)));
812
927
  };
813
- window.addEventListener("pointermove", D), window.addEventListener("pointerup", C), window.addEventListener("pointercancel", C);
814
- }), o.addEventListener("dblclick", (c) => {
928
+ window.addEventListener("pointermove", D), window.addEventListener("pointerup", A), window.addEventListener("pointercancel", A);
929
+ }), o.addEventListener("dblclick", (l) => {
815
930
  if (!t.editable) return;
816
- c.preventDefault(), d();
931
+ l.preventDefault(), d();
817
932
  const u = e();
818
933
  u !== void 0 && r.onEdit(u);
819
- }), { box: o, img: s, handle: l, select: d, render: (c) => {
820
- const u = Be(c.attrs, !1);
934
+ }), { box: o, img: s, handle: c, select: d, render: (l) => {
935
+ const u = Ue(l.attrs, !1);
821
936
  for (const m of ["src", "alt", "title", "width", "height"])
822
937
  u[m] !== void 0 ? s.setAttribute(m, u[m]) : s.removeAttribute(m);
823
938
  }, isResizing: () => i };
824
939
  }
825
- const Bt = (t, e) => {
940
+ const qt = (t, e) => {
826
941
  t.classList.remove("wds-align-left", "wds-align-center", "wds-align-right"), e && t.classList.add(`wds-align-${e}`);
827
942
  };
828
- class ur {
943
+ class Mr {
829
944
  constructor(e, n, r, o) {
830
- this.node = e, this.parts = zt(n, r, () => this.node, o), this.dom = this.parts.box, this.render();
945
+ this.node = e, this.parts = Wt(n, r, () => this.node, o), this.dom = this.parts.box, this.render();
831
946
  }
832
947
  render() {
833
- this.parts.render(this.node), Bt(this.dom, this.node.attrs.align);
948
+ this.parts.render(this.node), qt(this.dom, this.node.attrs.align);
834
949
  }
835
950
  update(e) {
836
951
  return e.type !== this.node.type ? !1 : (this.node = e, this.render(), !0);
@@ -842,14 +957,14 @@ class ur {
842
957
  return !0;
843
958
  }
844
959
  }
845
- class hr {
960
+ class Lr {
846
961
  constructor(e, n, r, o) {
847
- this.node = e, this.dom = document.createElement("figure"), this.dom.className = "wds-figure", this.parts = zt(n, r, () => this.node, o), this.parts.box.contentEditable = "false", this.parts.box.addEventListener("mousedown", (s) => {
962
+ this.node = e, this.dom = document.createElement("figure"), this.dom.className = "wds-figure", this.parts = Wt(n, r, () => this.node, o), this.parts.box.contentEditable = "false", this.parts.box.addEventListener("mousedown", (s) => {
848
963
  s.target === this.parts.handle || s.detail > 1 || (s.preventDefault(), this.parts.select(), n.focus());
849
964
  }), this.contentDOM = document.createElement("figcaption"), this.contentDOM.dataset.placeholder = o.captionPlaceholder, this.dom.append(this.parts.box, this.contentDOM), this.render();
850
965
  }
851
966
  render() {
852
- this.parts.render(this.node), Bt(this.dom, this.node.attrs.align), this.dom.classList.toggle("is-empty", this.node.content.size === 0);
967
+ this.parts.render(this.node), qt(this.dom, this.node.attrs.align), this.dom.classList.toggle("is-empty", this.node.content.size === 0);
853
968
  }
854
969
  update(e) {
855
970
  return e.type !== this.node.type ? !1 : (this.node = e, this.render(), !0);
@@ -861,109 +976,7 @@ class hr {
861
976
  return !this.contentDOM.contains(e.target);
862
977
  }
863
978
  }
864
- let ye = null;
865
- function Ft() {
866
- ye?.close();
867
- }
868
- function Ye(t, e, n, r) {
869
- Ft();
870
- const o = document.createElement("div");
871
- o.className = `wds-menu ${n}`, e.append(o);
872
- const s = () => {
873
- const u = t.getBoundingClientRect();
874
- o.style.maxHeight = "";
875
- const m = o.offsetWidth, g = o.offsetHeight;
876
- o.style.left = `${Math.max(4, Math.min(u.left, window.innerWidth - m - 4))}px`;
877
- const v = window.innerHeight - u.bottom - 8, D = u.top - 8;
878
- 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`));
879
- }, l = (u) => {
880
- if (u.target instanceof Node && o.contains(u.target)) return;
881
- const m = t.getBoundingClientRect();
882
- m.bottom < 0 || m.top > window.innerHeight || !t.isConnected ? c() : s();
883
- };
884
- t.setAttribute("aria-expanded", "true");
885
- const d = (u) => {
886
- !o.contains(u.target) && u.target !== t && !t.contains(u.target) && c();
887
- }, i = (u) => {
888
- u.key === "Escape" && (u.preventDefault(), u.stopPropagation(), c(!0));
889
- };
890
- let a = !1;
891
- function c(u = !1) {
892
- a || (a = !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());
893
- }
894
- 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: s, close: c };
895
- }
896
- function pr(t, e, n, r) {
897
- const { popup: o, place: s, close: l } = Ye(t, e, "wds-menu-list");
898
- o.setAttribute("role", "menu"), o.setAttribute("aria-label", r);
899
- for (const i of n) {
900
- if (i === "|") {
901
- const c = document.createElement("div");
902
- c.className = "wds-menu-sep", c.setAttribute("role", "separator"), o.append(c);
903
- continue;
904
- }
905
- const a = document.createElement("button");
906
- a.type = "button", a.className = `wds-menu-item${i.danger ? " is-danger" : ""}`, a.setAttribute("role", "menuitem"), a.tabIndex = -1, a.innerHTML = i.icon ?? "", a.append(document.createTextNode(i.label)), i.enabled === !1 && (a.disabled = !0), a.addEventListener("mousedown", (c) => c.preventDefault()), a.addEventListener("click", () => {
907
- l(), i.run();
908
- }), o.append(a);
909
- }
910
- const d = () => [...o.querySelectorAll(".wds-menu-item:not(:disabled)")];
911
- o.addEventListener("keydown", (i) => {
912
- const a = d(), c = a.indexOf(document.activeElement);
913
- let u = -1;
914
- i.key === "ArrowDown" ? u = (c + 1) % a.length : i.key === "ArrowUp" ? u = (c - 1 + a.length) % a.length : i.key === "Home" ? u = 0 : i.key === "End" ? u = a.length - 1 : i.key === "Tab" && l(), u >= 0 && (i.preventDefault(), a[u]?.focus());
915
- }), s(), d()[0]?.focus();
916
- }
917
- function mr(t, e, n, r, o) {
918
- const { popup: d, place: i, close: a } = Ye(t, e, "wds-table-picker");
919
- d.setAttribute("role", "dialog"), d.setAttribute("aria-label", n);
920
- const c = document.createElement("div");
921
- c.className = "wds-picker-grid", c.style.gridTemplateColumns = "repeat(10, 1fr)", c.tabIndex = 0, c.setAttribute("role", "grid"), c.setAttribute("aria-label", n);
922
- const u = document.createElement("div");
923
- u.className = "wds-picker-label", u.setAttribute("aria-live", "polite");
924
- const m = [];
925
- let g = 3, v = 3;
926
- const D = () => {
927
- m.forEach((C, T) => C.classList.toggle("is-on", Math.floor(T / 10) < g && T % 10 < v)), u.textContent = r(g, v), c.setAttribute("aria-valuetext", u.textContent);
928
- };
929
- for (let C = 0; C < 8; C++)
930
- for (let T = 0; T < 10; T++) {
931
- const O = document.createElement("span");
932
- O.className = "wds-picker-cell", O.addEventListener("mouseenter", () => {
933
- g = C + 1, v = T + 1, D();
934
- }), O.addEventListener("mousedown", (y) => y.preventDefault()), O.addEventListener("click", () => {
935
- a(), o(C + 1, T + 1);
936
- }), m.push(O), c.append(O);
937
- }
938
- c.addEventListener("keydown", (C) => {
939
- const T = { ArrowRight: [0, 1], ArrowLeft: [0, -1], ArrowDown: [1, 0], ArrowUp: [-1, 0] };
940
- T[C.key] ? (C.preventDefault(), g = Math.min(8, Math.max(1, g + T[C.key][0])), v = Math.min(10, Math.max(1, v + T[C.key][1])), D()) : C.key === "Enter" || C.key === " " ? (C.preventDefault(), a(), o(g, v)) : C.key === "Tab" && a();
941
- }), d.append(c, u), D(), i(), c.focus();
942
- }
943
- function fr(t, e, n) {
944
- const { popup: r, place: o, close: s } = Ye(t, e, "wds-color-picker");
945
- r.setAttribute("role", "dialog"), r.setAttribute("aria-label", n.label);
946
- const l = (a) => {
947
- s(), n.onPick(a);
948
- }, d = document.createElement("button");
949
- 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", (a) => a.preventDefault()), d.addEventListener("click", () => l(null));
950
- const i = document.createElement("div");
951
- i.className = "wds-swatches", i.style.gridTemplateColumns = `repeat(${n.columns}, 1fr)`;
952
- for (const a of n.swatches) {
953
- const c = document.createElement("button");
954
- c.type = "button", c.className = "wds-swatch", c.style.background = a.color, c.title = a.label, c.setAttribute("aria-label", a.label);
955
- const u = a.color === n.current;
956
- c.setAttribute("aria-pressed", String(u)), u && c.classList.add("is-current"), c.addEventListener("mousedown", (m) => m.preventDefault()), c.addEventListener("click", () => l(a.color)), i.append(c);
957
- }
958
- r.append(d, i), r.addEventListener("keydown", (a) => {
959
- const c = [d, ...i.querySelectorAll(".wds-swatch")], u = c.indexOf(document.activeElement);
960
- if (u < 0) return;
961
- const m = n.columns;
962
- let g = -1;
963
- a.key === "ArrowRight" ? g = Math.min(c.length - 1, u + 1) : a.key === "ArrowLeft" ? g = Math.max(0, u - 1) : a.key === "ArrowDown" ? g = u === 0 ? 1 : Math.min(c.length - 1, u + m) : a.key === "ArrowUp" ? g = u <= m ? 0 : u - m : a.key === "Tab" && s(), g >= 0 && (a.preventDefault(), c[g].focus());
964
- }), o(), (i.querySelector(".is-current") ?? i.querySelector(".wds-swatch"))?.focus();
965
- }
966
- const ve = {
979
+ const ke = {
967
980
  undo: "Undo",
968
981
  redo: "Redo",
969
982
  blockType: "Text style",
@@ -1049,6 +1062,8 @@ const ve = {
1049
1062
  fmListFailed: "The file list could not be loaded. {error}",
1050
1063
  fmDeleteFailed: "The file could not be deleted. {error}",
1051
1064
  fmUploading: "Uploading {name}",
1065
+ fmNetworkError: "Check your connection and try again.",
1066
+ fmInvalidResponse: "The server sent an unexpected response.",
1052
1067
  table: "Table",
1053
1068
  tableInsert: "Insert table",
1054
1069
  tableSize: "{rows} × {cols} table",
@@ -1082,7 +1097,7 @@ const ve = {
1082
1097
  colorPink: "Pink",
1083
1098
  colorSlate: "Slate",
1084
1099
  colorGray: "Gray"
1085
- }, gr = {
1100
+ }, xr = {
1086
1101
  undo: "Geri al",
1087
1102
  redo: "Yinele",
1088
1103
  blockType: "Metin stili",
@@ -1168,6 +1183,8 @@ const ve = {
1168
1183
  fmListFailed: "Dosya listesi yüklenemedi. {error}",
1169
1184
  fmDeleteFailed: "Dosya silinemedi. {error}",
1170
1185
  fmUploading: "{name} yükleniyor",
1186
+ fmNetworkError: "Bağlantınızı kontrol edip tekrar deneyin.",
1187
+ fmInvalidResponse: "Sunucu beklenmeyen bir yanıt gönderdi.",
1171
1188
  table: "Tablo",
1172
1189
  tableInsert: "Tablo ekle",
1173
1190
  tableSize: "{rows} × {cols} tablo",
@@ -1201,122 +1218,136 @@ const ve = {
1201
1218
  colorPink: "Pembe",
1202
1219
  colorSlate: "Arduvaz",
1203
1220
  colorGray: "Gri"
1204
- }, ke = { en: ve, tr: gr };
1205
- function br(t, e) {
1206
- ke[t.toLowerCase()] = { ...ve, ...ke[t.toLowerCase()], ...e };
1221
+ }, pe = { en: ke, tr: xr };
1222
+ function Gt(t, e) {
1223
+ pe[t.toLowerCase()] = { ...ke, ...pe[t.toLowerCase()], ...e };
1207
1224
  }
1208
- function wr(t) {
1209
- if (t && typeof t == "object") return { ...ve, ...t };
1225
+ function kt(t) {
1226
+ return globalThis.WDSEditorLang?.[t];
1227
+ }
1228
+ function Mt(t) {
1229
+ return !pe[t] && kt(t) && Gt(t, kt(t)), pe[t];
1230
+ }
1231
+ function jt(t) {
1210
1232
  const e = (t || (typeof navigator < "u" ? navigator.language : "en") || "en").toLowerCase();
1211
- return ke[e] ?? ke[e.split("-")[0]] ?? ve;
1233
+ if (Mt(e)) return e;
1234
+ const n = e.split("-")[0];
1235
+ return Mt(n) ? n : "en";
1212
1236
  }
1213
- function V(t, e) {
1237
+ function Er(t) {
1238
+ return t && typeof t == "object" ? { ...ke, ...t } : pe[jt(t)] ?? ke;
1239
+ }
1240
+ const Sr = /* @__PURE__ */ new Set(["ar", "he", "fa", "ur", "ps", "yi", "dv", "ckb"]);
1241
+ function Ar(t) {
1242
+ return Sr.has(t.toLowerCase().split("-")[0]);
1243
+ }
1244
+ function j(t, e) {
1214
1245
  return t.replace(/\{(\w+)\}/g, (n, r) => e[r] ?? n);
1215
1246
  }
1216
- let yr = 0;
1217
- function wt(t, e) {
1218
- const n = `wds-dlg-${++yr}`, r = document.createElement("dialog");
1247
+ let Tr = 0;
1248
+ function Lt(t, e) {
1249
+ const n = `wds-dlg-${++Tr}`, r = document.createElement("dialog");
1219
1250
  r.className = "wds-dialog", r.setAttribute("aria-labelledby", `${n}-title`);
1220
1251
  const o = document.createElement("form");
1221
1252
  o.method = "dialog", o.noValidate = !0;
1222
1253
  const s = document.createElement("div");
1223
1254
  s.className = "wds-dialog-header";
1224
- const l = document.createElement("h2");
1225
- l.id = `${n}-title`, l.textContent = e.title;
1255
+ const c = document.createElement("h2");
1256
+ c.id = `${n}-title`, c.textContent = e.title;
1226
1257
  const d = document.createElement("button");
1227
- d.type = "button", d.className = "wds-icon-button", d.setAttribute("aria-label", e.closeLabel), d.innerHTML = L.close, s.append(l, d);
1258
+ d.type = "button", d.className = "wds-icon-button", d.setAttribute("aria-label", e.closeLabel), d.innerHTML = L.close, s.append(c, d);
1228
1259
  const i = document.createElement("div");
1229
1260
  i.className = "wds-dialog-body";
1230
1261
  const a = /* @__PURE__ */ new Map();
1231
1262
  for (const y of e.fields) {
1232
1263
  if (y.type === "select") {
1233
- const A = document.createElement("select");
1234
- A.id = `${n}-${y.name}`, A.name = y.name, A.className = "wds-input";
1235
- for (const $ of y.options ?? []) {
1264
+ const T = document.createElement("select");
1265
+ T.id = `${n}-${y.name}`, T.name = y.name, T.className = "wds-input";
1266
+ for (const O of y.options ?? []) {
1236
1267
  const G = document.createElement("option");
1237
- G.value = $.value, G.textContent = $.label, A.append(G);
1268
+ G.value = O.value, G.textContent = O.label, T.append(G);
1238
1269
  }
1239
- A.value = typeof y.value == "string" ? y.value : "";
1240
- const I = document.createElement("label");
1241
- I.className = "wds-label", I.htmlFor = A.id, I.textContent = y.label, i.append(I, A), a.set(y.name, A);
1270
+ T.value = typeof y.value == "string" ? y.value : "";
1271
+ const H = document.createElement("label");
1272
+ H.className = "wds-label", H.htmlFor = T.id, H.textContent = y.label, i.append(H, T), a.set(y.name, T);
1242
1273
  continue;
1243
1274
  }
1244
1275
  const x = document.createElement("input");
1245
1276
  if (x.id = `${n}-${y.name}`, x.name = y.name, y.type === "checkbox") {
1246
1277
  x.type = "checkbox", x.checked = !!y.value;
1247
- const A = document.createElement("label");
1248
- A.className = "wds-check", A.htmlFor = x.id, A.append(x, document.createTextNode(y.label)), i.append(A);
1278
+ const T = document.createElement("label");
1279
+ T.className = "wds-check", T.htmlFor = x.id, T.append(x, document.createTextNode(y.label)), i.append(T);
1249
1280
  } else {
1250
1281
  x.type = "text", y.type === "url" && (x.inputMode = "url"), y.type === "number" && (x.inputMode = "numeric"), x.className = "wds-input", x.value = typeof y.value == "string" ? y.value : "", x.autocomplete = "off", x.spellcheck = !1, y.placeholder && (x.placeholder = y.placeholder);
1251
- const A = document.createElement("label");
1252
- if (A.className = "wds-label", A.htmlFor = x.id, A.textContent = y.label, i.append(A, x), y.hint) {
1253
- const I = document.createElement("p");
1254
- I.className = "wds-hint", I.id = `${x.id}-hint`, I.textContent = y.hint, x.setAttribute("aria-describedby", I.id), i.append(I);
1282
+ const T = document.createElement("label");
1283
+ if (T.className = "wds-label", T.htmlFor = x.id, T.textContent = y.label, i.append(T, x), y.hint) {
1284
+ const H = document.createElement("p");
1285
+ H.className = "wds-hint", H.id = `${x.id}-hint`, H.textContent = y.hint, x.setAttribute("aria-describedby", H.id), i.append(H);
1255
1286
  }
1256
1287
  }
1257
1288
  a.set(y.name, x);
1258
1289
  }
1259
- const c = document.createElement("p");
1260
- c.className = "wds-dialog-error", c.setAttribute("role", "alert"), c.hidden = !0, i.append(c);
1290
+ const l = document.createElement("p");
1291
+ l.className = "wds-dialog-error", l.setAttribute("role", "alert"), l.hidden = !0, i.append(l);
1261
1292
  const u = document.createElement("div");
1262
1293
  if (u.className = "wds-dialog-footer", e.extraAction) {
1263
1294
  const y = document.createElement("button");
1264
1295
  y.type = "button", y.className = "wds-button wds-button-danger", y.textContent = e.extraAction.label, y.addEventListener("click", () => {
1265
- e.extraAction.onClick(), T();
1296
+ e.extraAction.onClick(), C();
1266
1297
  }), u.append(y);
1267
1298
  }
1268
1299
  const m = document.createElement("span");
1269
1300
  m.className = "wds-spacer";
1270
1301
  const g = document.createElement("button");
1271
1302
  g.type = "button", g.className = "wds-button", g.textContent = e.cancelLabel;
1272
- const v = document.createElement("button");
1273
- v.type = "submit", v.className = "wds-button wds-button-primary", v.textContent = e.submitLabel, u.append(m, g, v), o.append(s, i, u), r.append(o), t.append(r);
1303
+ const k = document.createElement("button");
1304
+ k.type = "submit", k.className = "wds-button wds-button-primary", k.textContent = e.submitLabel, u.append(m, g, k), o.append(s, i, u), r.append(o), t.append(r);
1274
1305
  const D = () => {
1275
1306
  const y = {};
1276
- return a.forEach((x, A) => y[A] = x instanceof HTMLInputElement && x.type === "checkbox" ? x.checked : x.value), y;
1307
+ return a.forEach((x, T) => y[T] = x instanceof HTMLInputElement && x.type === "checkbox" ? x.checked : x.value), y;
1277
1308
  };
1278
- let C = !1;
1279
- function T() {
1280
- C || (C = !0, r.open && r.close(), r.remove(), e.onClose?.());
1309
+ let A = !1;
1310
+ function C() {
1311
+ A || (A = !0, r.open && r.close(), r.remove(), e.onClose?.());
1281
1312
  }
1282
1313
  o.addEventListener("submit", (y) => {
1283
1314
  y.preventDefault();
1284
- const x = D(), A = e.validate?.(x) ?? null;
1285
- if (A) {
1286
- c.textContent = A, c.hidden = !1, [...a.values()][0]?.focus();
1315
+ const x = D(), T = e.validate?.(x) ?? null;
1316
+ if (T) {
1317
+ l.textContent = T, l.hidden = !1, [...a.values()][0]?.focus();
1287
1318
  return;
1288
1319
  }
1289
- e.onSubmit(x), T();
1290
- }), g.addEventListener("click", T), d.addEventListener("click", T), r.addEventListener("close", T), r.addEventListener("click", (y) => {
1291
- y.target === r && T();
1320
+ e.onSubmit(x), C();
1321
+ }), g.addEventListener("click", C), d.addEventListener("click", C), r.addEventListener("close", C), r.addEventListener("click", (y) => {
1322
+ y.target === r && C();
1292
1323
  }), r.showModal();
1293
- const O = [...a.values()].find((y) => y instanceof HTMLInputElement && y.type !== "checkbox");
1294
- return O?.focus(), O?.select(), T;
1324
+ const I = [...a.values()].find((y) => y instanceof HTMLInputElement && y.type !== "checkbox");
1325
+ return I?.focus(), I?.select(), C;
1295
1326
  }
1296
- const K = (t) => typeof t == "string" && t.trim() ? t : void 0, He = (t) => typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : void 0;
1297
- function Ut(t) {
1327
+ const V = (t) => typeof t == "string" && t.trim() ? t : void 0, Oe = (t) => typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : void 0;
1328
+ function Vt(t) {
1298
1329
  if (!t || typeof t != "object") return null;
1299
- const e = t, n = q(K(e.url)), r = K(e.name);
1330
+ const e = t, n = q(V(e.url)), r = V(e.name);
1300
1331
  if (!n || !r) return null;
1301
- const o = { url: n, name: r }, s = He(e.size), l = He(e.width), d = He(e.height);
1302
- s !== void 0 && (o.size = s), l !== void 0 && (o.width = l), d !== void 0 && (o.height = d), K(e.type) && (o.type = e.type.toLowerCase());
1303
- const i = q(K(e.thumb));
1304
- return i && (o.thumb = i), K(e.modified) && !Number.isNaN(Date.parse(e.modified)) && (o.modified = e.modified), o;
1332
+ const o = { url: n, name: r }, s = Oe(e.size), c = Oe(e.width), d = Oe(e.height);
1333
+ s !== void 0 && (o.size = s), c !== void 0 && (o.width = c), d !== void 0 && (o.height = d), V(e.type) && (o.type = e.type.toLowerCase());
1334
+ const i = q(V(e.thumb));
1335
+ return i && (o.thumb = i), V(e.modified) && !Number.isNaN(Date.parse(e.modified)) && (o.modified = e.modified), o;
1305
1336
  }
1306
- function vr(t, e = "/") {
1307
- const n = Array.isArray(t) ? { files: t } : t && typeof t == "object" ? t : {}, r = (Array.isArray(n.files) ? n.files : []).map(Ut).filter((s) => !!s), o = (Array.isArray(n.folders) ? n.folders : []).map((s) => s && typeof s == "object" ? s : {}).filter((s) => K(s.name) && K(s.path)).map((s) => ({ name: s.name, path: je(s.path) }));
1337
+ function Cr(t, e = "/") {
1338
+ const n = Array.isArray(t) ? { files: t } : t && typeof t == "object" ? t : {}, r = (Array.isArray(n.files) ? n.files : []).map(Vt).filter((s) => !!s), o = (Array.isArray(n.folders) ? n.folders : []).map((s) => s && typeof s == "object" ? s : {}).filter((s) => V(s.name) && V(s.path)).map((s) => ({ name: s.name, path: Ke(s.path) }));
1308
1339
  return {
1309
- path: je(K(n.path) ?? e),
1340
+ path: Ke(V(n.path) ?? e),
1310
1341
  folders: o,
1311
1342
  files: r,
1312
1343
  hasMore: n.hasMore === !0,
1313
1344
  serverSearch: typeof n.q == "string"
1314
1345
  };
1315
1346
  }
1316
- function je(t) {
1347
+ function Ke(t) {
1317
1348
  return "/" + t.split("/").filter((n) => n && n !== "." && n !== "..").join("/");
1318
1349
  }
1319
- const kr = /\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i, Mr = {
1350
+ const Dr = /\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i, Nr = {
1320
1351
  jpg: "image/jpeg",
1321
1352
  jpeg: "image/jpeg",
1322
1353
  png: "image/png",
@@ -1336,23 +1367,23 @@ const kr = /\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i, Mr = {
1336
1367
  xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1337
1368
  mp4: "video/mp4",
1338
1369
  mp3: "audio/mpeg"
1339
- }, Pt = (t) => (/\.([a-z0-9]+)$/i.exec(t)?.[1] ?? "").toLowerCase();
1340
- function _t(t) {
1341
- return t.type || Mr[Pt(t.name)] || "";
1370
+ }, Kt = (t) => (/\.([a-z0-9]+)$/i.exec(t)?.[1] ?? "").toLowerCase();
1371
+ function Yt(t) {
1372
+ return t.type || Nr[Kt(t.name)] || "";
1342
1373
  }
1343
1374
  function ue(t) {
1344
- const e = _t(t);
1345
- return e ? e.startsWith("image/") : kr.test(t.url ?? t.name);
1375
+ const e = Yt(t);
1376
+ return e ? e.startsWith("image/") : Dr.test(t.url ?? t.name);
1346
1377
  }
1347
- function yt(t, e) {
1378
+ function xt(t, e) {
1348
1379
  if (!e || !e.trim()) return !0;
1349
- const n = _t(t), r = "." + Pt(t.name);
1380
+ const n = Yt(t), r = "." + Kt(t.name);
1350
1381
  return e.split(",").some((o) => {
1351
1382
  const s = o.trim().toLowerCase();
1352
1383
  return s ? s.startsWith(".") ? r === s : s.endsWith("/*") ? n.startsWith(s.slice(0, -1)) : n === s : !1;
1353
1384
  });
1354
1385
  }
1355
- function vt(t) {
1386
+ function Et(t) {
1356
1387
  if (t === void 0) return "";
1357
1388
  if (t < 1024) return `${t} B`;
1358
1389
  const e = ["KB", "MB", "GB"];
@@ -1361,9 +1392,12 @@ function vt(t) {
1361
1392
  n /= 1024, r++;
1362
1393
  return `${n < 10 ? n.toFixed(1) : Math.round(n)} ${e[r]}`;
1363
1394
  }
1364
- class P extends Error {
1395
+ class $ extends Error {
1396
+ constructor(e, n) {
1397
+ super(e), this.code = n;
1398
+ }
1365
1399
  }
1366
- async function kt(t) {
1400
+ async function St(t) {
1367
1401
  try {
1368
1402
  const e = await t.clone().json();
1369
1403
  if (e && typeof e.error == "string") return e.error;
@@ -1371,12 +1405,12 @@ async function kt(t) {
1371
1405
  }
1372
1406
  return `HTTP ${t.status}`;
1373
1407
  }
1374
- function Lr(t, e) {
1408
+ function Ir(t, e) {
1375
1409
  const n = new URL(t, document.baseURI);
1376
1410
  for (const [r, o] of Object.entries(e)) o && n.searchParams.set(r, o);
1377
1411
  return n.href;
1378
1412
  }
1379
- class xr {
1413
+ class Hr {
1380
1414
  constructor(e) {
1381
1415
  this.options = e;
1382
1416
  }
@@ -1394,49 +1428,49 @@ class xr {
1394
1428
  };
1395
1429
  }
1396
1430
  async list(e, n, r, o) {
1397
- const s = Lr(this.options.listUrl, { path: e, q: n, page: r > 1 ? String(r) : "" });
1398
- let l;
1431
+ const s = Ir(this.options.listUrl, { path: e, q: n, page: r > 1 ? String(r) : "" });
1432
+ let c;
1399
1433
  try {
1400
- l = await fetch(s, { ...this.init(), signal: o });
1434
+ c = await fetch(s, { ...this.init(), signal: o });
1401
1435
  } catch (i) {
1402
- throw i.name === "AbortError" ? i : new P(i.message || "Network error");
1436
+ throw i.name === "AbortError" ? i : new $(i.message || "Network error", "network");
1403
1437
  }
1404
- if (!l.ok) throw new P(await kt(l));
1438
+ if (!c.ok) throw new $(await St(c));
1405
1439
  let d;
1406
1440
  try {
1407
- d = await l.json();
1441
+ d = await c.json();
1408
1442
  } catch {
1409
- throw new P("Invalid JSON");
1443
+ throw new $("Invalid JSON", "response");
1410
1444
  }
1411
- return vr(d, e);
1445
+ return Cr(d, e);
1412
1446
  }
1413
1447
  /** Multipart upload with progress (XMLHttpRequest, because fetch has no upload progress). */
1414
1448
  upload(e, n, r) {
1415
- const { uploadUrl: o, headers: s = {}, withCredentials: l } = this.options;
1449
+ const { uploadUrl: o, headers: s = {}, withCredentials: c } = this.options;
1416
1450
  return o ? new Promise((d, i) => {
1417
1451
  const a = new XMLHttpRequest();
1418
- a.open("POST", new URL(o, document.baseURI).href), a.withCredentials = !!l, a.setRequestHeader("Accept", "application/json");
1452
+ a.open("POST", new URL(o, document.baseURI).href), a.withCredentials = !!c, a.setRequestHeader("Accept", "application/json");
1419
1453
  for (const [u, m] of Object.entries(s)) a.setRequestHeader(u, m);
1420
- a.upload.onprogress = (u) => u.lengthComputable && r?.(u.loaded / u.total), a.onerror = () => i(new P("Network error")), a.onload = () => {
1454
+ a.upload.onprogress = (u) => u.lengthComputable && r?.(u.loaded / u.total), a.onerror = () => i(new $("Network error", "network")), a.onload = () => {
1421
1455
  let u = null;
1422
1456
  try {
1423
1457
  u = JSON.parse(a.responseText);
1424
1458
  } catch {
1425
1459
  }
1426
1460
  if (a.status < 200 || a.status >= 300) {
1427
- i(new P(typeof u?.error == "string" ? u.error : `HTTP ${a.status}`));
1461
+ i(new $(typeof u?.error == "string" ? u.error : `HTTP ${a.status}`));
1428
1462
  return;
1429
1463
  }
1430
- const m = Ut(u?.file);
1431
- m ? d(m) : i(new P("Invalid upload response"));
1464
+ const m = Vt(u?.file);
1465
+ m ? d(m) : i(new $("Invalid upload response", "response"));
1432
1466
  };
1433
- const c = new FormData();
1434
- c.append("file", e, e.name), c.append("path", n), a.send(c);
1435
- }) : Promise.reject(new P("Upload is not configured"));
1467
+ const l = new FormData();
1468
+ l.append("file", e, e.name), l.append("path", n), a.send(l);
1469
+ }) : Promise.reject(new $("Upload is not configured"));
1436
1470
  }
1437
1471
  async remove(e) {
1438
1472
  const { deleteUrl: n } = this.options;
1439
- if (!n) throw new P("Delete is not configured");
1473
+ if (!n) throw new $("Delete is not configured");
1440
1474
  let r;
1441
1475
  try {
1442
1476
  r = await fetch(
@@ -1444,243 +1478,246 @@ class xr {
1444
1478
  this.init({ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ url: e }) })
1445
1479
  );
1446
1480
  } catch (o) {
1447
- throw new P(o.message || "Network error");
1481
+ throw new $(o.message || "Network error", "network");
1448
1482
  }
1449
- if (!r.ok) throw new P(await kt(r));
1483
+ if (!r.ok) throw new $(await St(r));
1450
1484
  }
1451
1485
  }
1486
+ function Re(t, e) {
1487
+ return t instanceof $ && t.code === "network" ? e.fmNetworkError : t instanceof $ && t.code === "response" ? e.fmInvalidResponse : t?.message ?? "";
1488
+ }
1452
1489
  const b = (t, e, n) => {
1453
1490
  const r = document.createElement(t);
1454
1491
  return e && (r.className = e), n !== void 0 && (r.textContent = n), r;
1455
- }, Oe = (t, e, n = "wds-icon-button") => {
1492
+ }, $e = (t, e, n = "wds-icon-button") => {
1456
1493
  const r = b("button", n);
1457
1494
  return r.type = "button", r.innerHTML = t, r.setAttribute("aria-label", e), r.title = e, r;
1458
- }, Er = [
1495
+ }, Or = [
1459
1496
  ["", "alignNone"],
1460
1497
  ["left", "alignLeftShort"],
1461
1498
  ["center", "alignCenterShort"],
1462
1499
  ["right", "alignRightShort"]
1463
1500
  ];
1464
- class Sr {
1501
+ class Rr {
1465
1502
  constructor(e, n, r) {
1466
1503
  this.host = e, this.api = n, this.t = r, this.path = "/", this.view = "grid", this.sort = "newest";
1467
1504
  }
1468
1505
  open(e) {
1469
1506
  const n = this.t, r = e.accept ?? "";
1470
- let o = [], s = [], l = 1, d = !1, i = !1, a = "", c = null, u = null, m = 0, g = !1;
1471
- const v = b("dialog", "wds-dialog wds-fm");
1472
- v.setAttribute("aria-labelledby", "wds-fm-title");
1473
- const D = b("div", "wds-dialog-header"), C = b("h2", void 0, n.fmTitle);
1474
- C.id = "wds-fm-title";
1475
- const T = Oe(L.close, n.close);
1476
- D.append(C, T);
1477
- const O = b("div", "wds-fm-bar"), y = b("nav", "wds-fm-crumbs");
1507
+ let o = [], s = [], c = 1, d = !1, i = !1, a = "", l = null, u = null, m = 0, g = !1;
1508
+ const k = b("dialog", "wds-dialog wds-fm");
1509
+ k.setAttribute("aria-labelledby", "wds-fm-title");
1510
+ const D = b("div", "wds-dialog-header"), A = b("h2", void 0, n.fmTitle);
1511
+ A.id = "wds-fm-title";
1512
+ const C = $e(L.close, n.close);
1513
+ D.append(A, C);
1514
+ const I = b("div", "wds-fm-bar"), y = b("nav", "wds-fm-crumbs");
1478
1515
  y.setAttribute("aria-label", n.fmBreadcrumb);
1479
1516
  const x = b("input", "wds-input wds-fm-search");
1480
1517
  x.type = "search", x.placeholder = n.fmSearch, x.setAttribute("aria-label", n.fmSearch);
1481
- const A = b("select", "wds-input wds-fm-sort");
1482
- A.setAttribute("aria-label", n.fmSort), A.title = n.fmSort;
1518
+ const T = b("select", "wds-input wds-fm-sort");
1519
+ T.setAttribute("aria-label", n.fmSort), T.title = n.fmSort;
1483
1520
  for (const [h, f] of [["newest", "fmSortNewest"], ["name", "fmSortName"], ["largest", "fmSortLargest"]]) {
1484
1521
  const M = b("option", void 0, n[f]);
1485
- M.value = h, A.append(M);
1522
+ M.value = h, T.append(M);
1486
1523
  }
1487
- A.value = this.sort;
1488
- const I = Oe(this.view === "grid" ? L.list : L.grid, this.view === "grid" ? n.fmList : n.fmGrid), $ = b("input");
1489
- $.type = "file", $.multiple = !0, $.hidden = !0, r && ($.accept = r);
1524
+ T.value = this.sort;
1525
+ const H = $e(this.view === "grid" ? L.list : L.grid, this.view === "grid" ? n.fmList : n.fmGrid), O = b("input");
1526
+ O.type = "file", O.multiple = !0, O.hidden = !0, r && (O.accept = r);
1490
1527
  const G = b("button", "wds-button wds-button-primary wds-fm-upload");
1491
- G.type = "button", G.innerHTML = `${L.upload}<span>${$e(n.fmUpload)}</span>`;
1528
+ G.type = "button", G.innerHTML = `${L.upload}<span>${ze(n.fmUpload)}</span>`;
1492
1529
  const Me = b("div", "wds-fm-tools");
1493
- Me.append(x, A, I), this.api.canUpload && Me.append(G, $), O.append(y, Me);
1494
- const Je = b("div", "wds-fm-main"), W = b("div", "wds-fm-browser"), Le = b("div", "wds-fm-uploads"), B = b("ul", `wds-fm-items is-${this.view}`);
1495
- B.setAttribute("aria-label", n.fmTitle);
1530
+ Me.append(x, T, H), this.api.canUpload && Me.append(G, O), I.append(y, Me);
1531
+ const Qe = b("div", "wds-fm-main"), W = b("div", "wds-fm-browser"), Le = b("div", "wds-fm-uploads"), F = b("ul", `wds-fm-items is-${this.view}`);
1532
+ F.setAttribute("aria-label", n.fmTitle);
1496
1533
  const N = b("p", "wds-fm-status");
1497
1534
  N.setAttribute("role", "status");
1498
- const Z = b("button", "wds-button", n.fmRetry);
1535
+ const Q = b("button", "wds-button", n.fmRetry);
1536
+ Q.type = "button", Q.hidden = !0;
1537
+ const Z = b("button", "wds-button wds-fm-more", n.fmLoadMore);
1499
1538
  Z.type = "button", Z.hidden = !0;
1500
- const ee = b("button", "wds-button wds-fm-more", n.fmLoadMore);
1501
- ee.type = "button", ee.hidden = !0;
1502
- const Xe = b("div", "wds-fm-drop", n.fmDrop);
1503
- Xe.setAttribute("aria-hidden", "true"), W.append(Le, B, N, Z, ee, Xe);
1504
- const F = b("aside", "wds-fm-details");
1505
- F.setAttribute("aria-label", n.imageEdit), Je.append(W, F);
1539
+ const Ze = b("div", "wds-fm-drop", n.fmDrop);
1540
+ Ze.setAttribute("aria-hidden", "true"), W.append(Le, F, N, Q, Z, Ze);
1541
+ const U = b("aside", "wds-fm-details");
1542
+ U.setAttribute("aria-label", n.imageEdit), Qe.append(W, U);
1506
1543
  const xe = b("div", "wds-dialog-footer");
1507
1544
  if (e.onFromUrl) {
1508
1545
  const h = b("button", "wds-button wds-fm-fromurl");
1509
- h.type = "button", h.innerHTML = `${L.globe}<span>${$e(n.fmFromUrl)}</span>`, h.addEventListener("click", () => {
1510
- X(), e.onFromUrl();
1546
+ h.type = "button", h.innerHTML = `${L.globe}<span>${ze(n.fmFromUrl)}</span>`, h.addEventListener("click", () => {
1547
+ J(), e.onFromUrl();
1511
1548
  }), xe.append(h);
1512
1549
  }
1513
1550
  const Ee = b("button", "wds-button", n.cancel);
1514
1551
  Ee.type = "button";
1515
1552
  const ie = b("button", "wds-button wds-button-primary", n.insert);
1516
- ie.type = "button", ie.disabled = !0, xe.append(b("span", "wds-spacer"), Ee, ie), v.append(D, O, Je, xe), this.host.append(v);
1517
- let ae = null, U = null, se = null, Y = null, le = null;
1518
- const me = (h, f, M, w) => {
1553
+ ie.type = "button", ie.disabled = !0, xe.append(b("span", "wds-spacer"), Ee, ie), k.append(D, I, Qe, xe), this.host.append(k);
1554
+ let ae = null, P = null, se = null, K = null, le = null;
1555
+ const fe = (h, f, M, w) => {
1519
1556
  f.id = M;
1520
1557
  const S = b("label", "wds-label", h);
1521
- if (S.htmlFor = M, F.append(S, f), w) {
1522
- const k = b("p", "wds-hint", w);
1523
- k.id = `${M}-hint`, f.setAttribute("aria-describedby", k.id), F.append(k);
1558
+ if (S.htmlFor = M, U.append(S, f), w) {
1559
+ const v = b("p", "wds-hint", w);
1560
+ v.id = `${M}-hint`, f.setAttribute("aria-describedby", v.id), U.append(v);
1524
1561
  }
1525
- }, fe = () => {
1526
- if (F.replaceChildren(), ae = U = le = Y = null, se = null, ie.disabled = !c, !c) {
1527
- F.append(b("p", "wds-fm-placeholder", n.fmNoSelection));
1562
+ }, ge = () => {
1563
+ if (U.replaceChildren(), ae = P = le = K = null, se = null, ie.disabled = !l, !l) {
1564
+ U.append(b("p", "wds-fm-placeholder", n.fmNoSelection));
1528
1565
  return;
1529
1566
  }
1530
- const h = c, f = b("div", "wds-fm-preview"), M = b("p", "wds-fm-filename", h.name), w = b("p", "wds-fm-facts"), S = () => [
1567
+ const h = l, f = b("div", "wds-fm-preview"), M = b("p", "wds-fm-filename", h.name), w = b("p", "wds-fm-facts"), S = () => [
1531
1568
  h.width && h.height ? `${h.width} × ${h.height}` : "",
1532
- vt(h.size),
1569
+ Et(h.size),
1533
1570
  h.modified ? new Date(h.modified).toLocaleDateString() : ""
1534
1571
  ].filter(Boolean).join(" · ");
1535
1572
  if (w.textContent = S(), ue(h)) {
1536
- const k = b("img");
1537
- k.alt = "", !h.thumb && !(h.width && h.height) && k.addEventListener("load", () => {
1538
- !k.naturalWidth || c !== h || (h.width = k.naturalWidth, h.height = k.naturalHeight, w.textContent = S(), U && !U.placeholder && (U.placeholder = String(h.width)));
1539
- }, { once: !0 }), k.src = h.thumb ?? h.url, f.append(k);
1573
+ const v = b("img");
1574
+ v.alt = "", !h.thumb && !(h.width && h.height) && v.addEventListener("load", () => {
1575
+ !v.naturalWidth || l !== h || (h.width = v.naturalWidth, h.height = v.naturalHeight, w.textContent = S(), P && !P.placeholder && (P.placeholder = String(h.width)));
1576
+ }, { once: !0 }), v.src = h.thumb ?? h.url, f.append(v);
1540
1577
  } else
1541
1578
  f.innerHTML = L.file;
1542
- if (F.append(f, M, w), e.mode === "image" && ue(h)) {
1543
- 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");
1544
- for (const [R, z] of Er) {
1545
- const te = b("option", void 0, n[z]);
1546
- te.value = R, se.append(te);
1579
+ if (U.append(f, M, w), e.mode === "image" && ue(h)) {
1580
+ ae = b("input", "wds-input"), ae.value = h.name.replace(/\.[a-z0-9]+$/i, "").replace(/[-_]+/g, " "), fe(n.imageAlt, ae, "wds-fm-alt", n.imageAltHint), P = b("input", "wds-input"), P.inputMode = "numeric", P.placeholder = h.width ? String(h.width) : "", fe(n.imageWidth, P, "wds-fm-width"), se = b("select", "wds-input");
1581
+ for (const [z, B] of Or) {
1582
+ const ee = b("option", void 0, n[B]);
1583
+ ee.value = z, se.append(ee);
1547
1584
  }
1548
- me(n.imageAlign, se, "wds-fm-align"), Y = b("input"), Y.type = "checkbox", Y.id = "wds-fm-caption";
1549
- const k = b("label", "wds-check");
1550
- k.htmlFor = Y.id, k.append(Y, document.createTextNode(n.caption)), F.append(k);
1585
+ fe(n.imageAlign, se, "wds-fm-align"), K = b("input"), K.type = "checkbox", K.id = "wds-fm-caption";
1586
+ const v = b("label", "wds-check");
1587
+ v.htmlFor = K.id, v.append(K, document.createTextNode(n.caption)), U.append(v);
1551
1588
  } else
1552
- le = b("input", "wds-input"), le.value = h.name, me(n.fmLinkText, le, "wds-fm-text");
1589
+ le = b("input", "wds-input"), le.value = h.name, fe(n.fmLinkText, le, "wds-fm-text");
1553
1590
  if (this.api.canDelete) {
1554
- const k = b("button", "wds-button wds-button-danger wds-fm-delete");
1555
- k.type = "button", k.innerHTML = `${L.trash}<span>${$e(n.fmDelete)}</span>`, k.addEventListener("click", () => qt(h)), F.append(k);
1591
+ const v = b("button", "wds-button wds-button-danger wds-fm-delete");
1592
+ v.type = "button", v.innerHTML = `${L.trash}<span>${ze(n.fmDelete)}</span>`, v.addEventListener("click", () => Xt(h)), U.append(v);
1556
1593
  }
1557
- }, Wt = () => {
1558
- const h = a.trim().toLocaleLowerCase(), f = o.filter((w) => yt(w, r) && (i || !h || w.name.toLocaleLowerCase().includes(h))), M = (w) => w.modified ? Date.parse(w.modified) : -1 / 0;
1594
+ }, Jt = () => {
1595
+ const h = a.trim().toLocaleLowerCase(), f = o.filter((w) => xt(w, r) && (i || !h || w.name.toLocaleLowerCase().includes(h))), M = (w) => w.modified ? Date.parse(w.modified) : -1 / 0;
1559
1596
  return this.sort === "name" ? f.sort((w, S) => w.name.localeCompare(S.name, void 0, { numeric: !0, sensitivity: "base" })) : this.sort === "largest" ? f.sort((w, S) => (S.size ?? -1) - (w.size ?? -1)) : f.sort((w, S) => M(S) - M(w)), f;
1560
1597
  }, Se = () => {
1561
1598
  y.replaceChildren();
1562
1599
  const h = this.path.split("/").filter(Boolean), f = [[n.fmRoot, "/"], ...h.map((M, w) => [M, "/" + h.slice(0, w + 1).join("/")])];
1563
1600
  f.forEach(([M, w], S) => {
1564
1601
  if (S && y.append(b("span", "wds-fm-sep", "/")), S === f.length - 1) {
1565
- const k = b("span", "wds-fm-crumb is-current", M);
1566
- k.setAttribute("aria-current", "location"), y.append(k);
1602
+ const v = b("span", "wds-fm-crumb is-current", M);
1603
+ v.setAttribute("aria-current", "location"), y.append(v);
1567
1604
  } else {
1568
- const k = b("button", "wds-fm-crumb", M);
1569
- k.type = "button", k.addEventListener("click", () => et(w)), y.append(k);
1605
+ const v = b("button", "wds-fm-crumb", M);
1606
+ v.type = "button", v.addEventListener("click", () => nt(w)), y.append(v);
1570
1607
  }
1571
1608
  });
1572
- }, J = () => {
1573
- B.className = `wds-fm-items is-${this.view}`, B.replaceChildren();
1609
+ }, Y = () => {
1610
+ F.className = `wds-fm-items is-${this.view}`, F.replaceChildren();
1574
1611
  const h = !a.trim();
1575
1612
  if (h)
1576
1613
  for (const w of s) {
1577
- const S = Ze(L.folder, w.name, n.fmFolder, !0);
1578
- S.addEventListener("click", () => et(w.path)), B.append(Qe(S));
1614
+ const S = tt(L.folder, w.name, n.fmFolder, !0);
1615
+ S.addEventListener("click", () => nt(w.path)), F.append(et(S));
1579
1616
  }
1580
- const f = Wt();
1617
+ const f = Jt();
1581
1618
  for (const w of f) {
1582
- const S = ue(w) ? w.thumb ?? w.url : null, k = Ze(S ? "" : L.file, w.name, [vt(w.size), w.width && w.height ? `${w.width}×${w.height}` : ""].filter(Boolean).join(" · "), !1);
1619
+ const S = ue(w) ? w.thumb ?? w.url : null, v = tt(S ? "" : L.file, w.name, [Et(w.size), w.width && w.height ? `${w.width}×${w.height}` : ""].filter(Boolean).join(" · "), !1);
1583
1620
  if (S) {
1584
- const z = b("img");
1585
- z.loading = "lazy", z.decoding = "async", z.alt = "", z.src = S, k.querySelector(".wds-fm-thumb").append(z);
1621
+ const B = b("img");
1622
+ B.loading = "lazy", B.decoding = "async", B.alt = "", B.src = S, v.querySelector(".wds-fm-thumb").append(B);
1586
1623
  }
1587
- k.dataset.url = w.url;
1588
- const R = c?.url === w.url;
1589
- k.classList.toggle("is-selected", R), k.setAttribute("aria-pressed", String(R)), k.addEventListener("click", () => Ae(w)), k.addEventListener("dblclick", () => {
1624
+ v.dataset.url = w.url;
1625
+ const z = l?.url === w.url;
1626
+ v.classList.toggle("is-selected", z), v.setAttribute("aria-pressed", String(z)), v.addEventListener("click", () => Ae(w)), v.addEventListener("dblclick", () => {
1590
1627
  Ae(w), Te();
1591
- }), B.append(Qe(k));
1628
+ }), F.append(et(v));
1592
1629
  }
1593
1630
  const M = !f.length && !(h && s.length);
1594
- !N.dataset.busy && !N.dataset.error && (N.textContent = M ? a.trim() ? n.fmNoResults : n.fmEmpty : ""), ee.hidden = !d || !!N.dataset.busy;
1595
- }, Qe = (h) => {
1631
+ !N.dataset.busy && !N.dataset.error && (N.textContent = M ? a.trim() ? n.fmNoResults : n.fmEmpty : ""), Z.hidden = !d || !!N.dataset.busy;
1632
+ }, et = (h) => {
1596
1633
  const f = b("li");
1597
1634
  return f.append(h), f;
1598
- }, Ze = (h, f, M, w) => {
1635
+ }, tt = (h, f, M, w) => {
1599
1636
  const S = b("button", `wds-fm-item${w ? " is-folder" : ""}`);
1600
1637
  S.type = "button";
1601
- const k = b("span", "wds-fm-thumb");
1602
- k.innerHTML = h;
1603
- const R = b("span", "wds-fm-name", f);
1604
- R.title = f;
1605
- const z = b("span", "wds-fm-meta", M);
1606
- return S.append(k, R, z), S;
1638
+ const v = b("span", "wds-fm-thumb");
1639
+ v.innerHTML = h;
1640
+ const z = b("span", "wds-fm-name", f);
1641
+ z.title = f;
1642
+ const B = b("span", "wds-fm-meta", M);
1643
+ return S.append(v, z, B), S;
1607
1644
  }, Ae = (h) => {
1608
- c = h, B.querySelectorAll(".wds-fm-item[data-url]").forEach((f) => {
1645
+ l = h, F.querySelectorAll(".wds-fm-item[data-url]").forEach((f) => {
1609
1646
  const M = f.dataset.url === h.url;
1610
1647
  f.classList.toggle("is-selected", M), f.setAttribute("aria-pressed", String(M));
1611
- }), fe();
1648
+ }), ge();
1612
1649
  }, ce = async (h) => {
1613
- u?.abort(), u = new AbortController(), h && (l = 1, o = [], s = []), N.dataset.busy = "1", delete N.dataset.error, N.textContent = n.fmLoading, Z.hidden = !0, ee.hidden = !0, h && J();
1650
+ u?.abort(), u = new AbortController(), h && (c = 1, o = [], s = []), N.dataset.busy = "1", delete N.dataset.error, N.textContent = n.fmLoading, Q.hidden = !0, Z.hidden = !0, h && Y();
1614
1651
  try {
1615
- const f = await this.api.list(this.path, a.trim(), l, u.signal);
1652
+ const f = await this.api.list(this.path, a.trim(), c, u.signal);
1616
1653
  if (g) return;
1617
1654
  this.path = f.path, i = f.serverSearch, d = f.hasMore, s = h ? f.folders : s;
1618
1655
  const M = new Set(o.map((w) => w.url));
1619
- o = [...o, ...f.files.filter((w) => !M.has(w.url))], delete N.dataset.busy, N.textContent = "", Se(), J();
1656
+ o = [...o, ...f.files.filter((w) => !M.has(w.url))], delete N.dataset.busy, N.textContent = "", Se(), Y();
1620
1657
  } catch (f) {
1621
1658
  if (f.name === "AbortError" || g) return;
1622
- delete N.dataset.busy, N.dataset.error = "1", N.textContent = V(n.fmListFailed, { error: f.message }), N.setAttribute("role", "alert"), Z.hidden = !1;
1659
+ delete N.dataset.busy, N.dataset.error = "1", N.textContent = j(n.fmListFailed, { error: Re(f, n) }), N.setAttribute("role", "alert"), Q.hidden = !1;
1623
1660
  }
1624
- }, et = (h) => {
1625
- this.path = je(h), a = "", x.value = "", c = null, fe(), Se(), ce(!0).then(() => B.querySelector(".wds-fm-item")?.focus());
1626
- }, tt = (h) => {
1661
+ }, nt = (h) => {
1662
+ this.path = Ke(h), a = "", x.value = "", l = null, ge(), Se(), ce(!0).then(() => F.querySelector(".wds-fm-item")?.focus());
1663
+ }, rt = (h) => {
1627
1664
  for (const f of Array.from(h)) {
1628
- const M = b("div", "wds-fm-upload-row"), w = b("span", "wds-fm-upload-name", V(n.fmUploading, { name: f.name }));
1629
- if (!yt(f, r)) {
1630
- nt(M, V(n.fmNotAllowed, { name: f.name })), Le.append(M);
1665
+ const M = b("div", "wds-fm-upload-row"), w = b("span", "wds-fm-upload-name", j(n.fmUploading, { name: f.name }));
1666
+ if (!xt(f, r)) {
1667
+ ot(M, j(n.fmNotAllowed, { name: f.name })), Le.append(M);
1631
1668
  continue;
1632
1669
  }
1633
1670
  const S = b("progress");
1634
- S.max = 1, S.value = 0, M.append(w, S), Le.append(M), this.api.upload(f, this.path, (k) => S.value = k).then((k) => {
1635
- g || (M.remove(), o = [k, ...o.filter((R) => R.url !== k.url)], J(), Ae(k), e.onUpload?.(k));
1636
- }).catch((k) => {
1637
- g || (M.replaceChildren(), nt(M, V(n.fmUploadFailed, { name: f.name, error: k.message })));
1671
+ S.max = 1, S.value = 0, M.append(w, S), Le.append(M), this.api.upload(f, this.path, (v) => S.value = v).then((v) => {
1672
+ g || (M.remove(), o = [v, ...o.filter((z) => z.url !== v.url)], Y(), Ae(v), e.onUpload?.(v));
1673
+ }).catch((v) => {
1674
+ g || (M.replaceChildren(), ot(M, j(n.fmUploadFailed, { name: f.name, error: Re(v, n) })));
1638
1675
  });
1639
1676
  }
1640
- }, nt = (h, f) => {
1677
+ }, ot = (h, f) => {
1641
1678
  h.classList.add("is-error");
1642
1679
  const M = b("span", "wds-fm-upload-name", f);
1643
1680
  M.setAttribute("role", "alert");
1644
- const w = Oe(L.close, n.close);
1681
+ const w = $e(L.close, n.close);
1645
1682
  w.addEventListener("click", () => h.remove()), h.append(M, w);
1646
- }, qt = async (h) => {
1647
- if (window.confirm(V(n.fmDeleteConfirm, { name: h.name })))
1683
+ }, Xt = async (h) => {
1684
+ if (window.confirm(j(n.fmDeleteConfirm, { name: h.name })))
1648
1685
  try {
1649
- await this.api.remove(h.url), o = o.filter((f) => f.url !== h.url), c = null, fe(), J();
1686
+ await this.api.remove(h.url), o = o.filter((f) => f.url !== h.url), l = null, ge(), Y();
1650
1687
  } catch (f) {
1651
- N.dataset.error = "1", N.setAttribute("role", "alert"), N.textContent = V(n.fmDeleteFailed, { error: f.message });
1688
+ N.dataset.error = "1", N.setAttribute("role", "alert"), N.textContent = j(n.fmDeleteFailed, { error: Re(f, n) });
1652
1689
  }
1653
1690
  }, Te = () => {
1654
- if (!c) return;
1655
- const h = U ? parseInt(U.value, 10) : NaN;
1691
+ if (!l) return;
1692
+ const h = P ? parseInt(P.value, 10) : NaN;
1656
1693
  e.onPick({
1657
- file: c,
1694
+ file: l,
1658
1695
  alt: ae?.value.trim() ?? "",
1659
1696
  width: Number.isFinite(h) && h > 0 ? h : null,
1660
1697
  align: se?.value || null,
1661
- text: le?.value.trim() || c.name,
1662
- caption: !!Y?.checked
1663
- }), X();
1698
+ text: le?.value.trim() || l.name,
1699
+ caption: !!K?.checked
1700
+ }), J();
1664
1701
  };
1665
- function X() {
1666
- g || (g = !0, u?.abort(), window.clearTimeout(m), v.open && v.close(), v.remove(), e.onClose?.());
1702
+ function J() {
1703
+ g || (g = !0, u?.abort(), window.clearTimeout(m), k.open && k.close(), k.remove(), e.onClose?.());
1667
1704
  }
1668
- if (T.addEventListener("click", X), Ee.addEventListener("click", X), ie.addEventListener("click", Te), v.addEventListener("close", X), v.addEventListener("click", (h) => h.target === v && X()), Z.addEventListener("click", () => {
1705
+ if (C.addEventListener("click", J), Ee.addEventListener("click", J), ie.addEventListener("click", Te), k.addEventListener("close", J), k.addEventListener("click", (h) => h.target === k && J()), Q.addEventListener("click", () => {
1669
1706
  N.setAttribute("role", "status"), ce(!0);
1670
- }), ee.addEventListener("click", () => {
1671
- l++, ce(!1);
1672
- }), A.addEventListener("change", () => {
1673
- this.sort = A.value, J();
1674
- }), I.addEventListener("click", () => {
1675
- this.view = this.view === "grid" ? "list" : "grid", I.innerHTML = this.view === "grid" ? L.list : L.grid;
1707
+ }), Z.addEventListener("click", () => {
1708
+ c++, ce(!1);
1709
+ }), T.addEventListener("change", () => {
1710
+ this.sort = T.value, Y();
1711
+ }), H.addEventListener("click", () => {
1712
+ this.view = this.view === "grid" ? "list" : "grid", H.innerHTML = this.view === "grid" ? L.list : L.grid;
1676
1713
  const h = this.view === "grid" ? n.fmList : n.fmGrid;
1677
- I.setAttribute("aria-label", h), I.title = h, J();
1714
+ H.setAttribute("aria-label", h), H.title = h, Y();
1678
1715
  }), x.addEventListener("input", () => {
1679
1716
  window.clearTimeout(m), m = window.setTimeout(() => {
1680
- a = x.value, !i && !d ? J() : ce(!0);
1717
+ a = x.value, !i && !d ? Y() : ce(!0);
1681
1718
  }, 250);
1682
- }), G.addEventListener("click", () => $.click()), $.addEventListener("change", () => {
1683
- $.files?.length && tt($.files), $.value = "";
1719
+ }), G.addEventListener("click", () => O.click()), O.addEventListener("change", () => {
1720
+ O.files?.length && rt(O.files), O.value = "";
1684
1721
  }), this.api.canUpload) {
1685
1722
  let h = 0;
1686
1723
  W.addEventListener("dragenter", (f) => {
@@ -1690,60 +1727,66 @@ class Sr {
1690
1727
  }), W.addEventListener("dragover", (f) => {
1691
1728
  f.dataTransfer?.types.includes("Files") && f.preventDefault();
1692
1729
  }), W.addEventListener("drop", (f) => {
1693
- f.preventDefault(), h = 0, W.classList.remove("is-dragging"), f.dataTransfer?.files.length && tt(f.dataTransfer.files);
1730
+ f.preventDefault(), h = 0, W.classList.remove("is-dragging"), f.dataTransfer?.files.length && rt(f.dataTransfer.files);
1694
1731
  });
1695
1732
  }
1696
- return B.addEventListener("keydown", (h) => {
1733
+ return F.addEventListener("keydown", (h) => {
1697
1734
  if (!["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp", "Home", "End"].includes(h.key)) return;
1698
- const M = [...B.querySelectorAll(".wds-fm-item")], w = M.indexOf(document.activeElement);
1735
+ const M = [...F.querySelectorAll(".wds-fm-item")], w = M.indexOf(document.activeElement);
1699
1736
  if (w < 0) return;
1700
1737
  h.preventDefault();
1701
- const S = M[0].offsetTop, k = this.view === "list" ? 1 : Math.max(1, M.findIndex((te) => te.offsetTop !== S) === -1 ? M.length : M.findIndex((te) => te.offsetTop !== S)), R = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: k, ArrowUp: -k }, z = h.key === "Home" ? 0 : h.key === "End" ? M.length - 1 : Math.min(M.length - 1, Math.max(0, w + R[h.key]));
1702
- M[z].focus();
1703
- }), F.addEventListener("keydown", (h) => {
1738
+ const S = M[0].offsetTop, v = this.view === "list" ? 1 : Math.max(1, M.findIndex((ee) => ee.offsetTop !== S) === -1 ? M.length : M.findIndex((ee) => ee.offsetTop !== S)), z = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: v, ArrowUp: -v }, B = h.key === "Home" ? 0 : h.key === "End" ? M.length - 1 : Math.min(M.length - 1, Math.max(0, w + z[h.key]));
1739
+ M[B].focus();
1740
+ }), U.addEventListener("keydown", (h) => {
1704
1741
  h.key === "Enter" && h.target.tagName === "INPUT" && (h.preventDefault(), Te());
1705
- }), Se(), fe(), v.showModal(), x.focus(), ce(!0), X;
1742
+ }), Se(), ge(), k.showModal(), x.focus(), ce(!0), J;
1706
1743
  }
1707
1744
  }
1708
- function $e(t) {
1745
+ function ze(t) {
1709
1746
  const e = document.createElement("span");
1710
1747
  return e.textContent = t, e.innerHTML;
1711
1748
  }
1712
- const ne = /* @__PURE__ */ new WeakMap(), Mt = (t) => t === void 0 ? void 0 : typeof t == "number" ? `${t}px` : t;
1713
- function Ar(t) {
1714
- return t === !1 ? [] : t === void 0 || t === "default" ? ar : Array.isArray(t) ? t : t.split(/\s+/).filter(Boolean);
1749
+ const te = /* @__PURE__ */ new WeakMap(), At = (t) => t === void 0 ? void 0 : typeof t == "number" ? `${t}px` : t;
1750
+ function $r(t) {
1751
+ return t === !1 ? [] : t === void 0 || t === "default" ? br : Array.isArray(t) ? t : t.split(/\s+/).filter(Boolean);
1715
1752
  }
1716
- const re = class re {
1753
+ const ne = class ne {
1717
1754
  constructor(e, n = {}) {
1718
1755
  if (this.listeners = /* @__PURE__ */ new Map(), this.notice = null, this.noticeTimer = 0, this.onFormSubmit = () => this.syncTarget(), this.onKeydown = (i) => {
1719
1756
  i.key === "Escape" && this.fullscreen && this.toggleFullscreen();
1720
- }, 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.");
1721
- this.target = e, this.options = n, this.t = wr(n.language), this.readOnly = !!n.readOnly, this.textarea = e instanceof HTMLTextAreaElement ? e : null, this.originalContent = this.textarea ? this.textarea.value : e.innerHTML;
1757
+ }, this.sourceMode = !1, this.plainPaste = !1, this.fullscreen = !1, this.destroyed = !1, te.has(e)) throw new Error("[WDS Editor] This element already has an editor. Use WDSEditor.get() or destroy() first.");
1758
+ this.target = e, this.options = n, this.t = Er(n.language), this.readOnly = !!n.readOnly, this.textarea = e instanceof HTMLTextAreaElement ? e : null, this.originalContent = this.textarea ? this.textarea.value : e.innerHTML;
1722
1759
  const r = n.content ?? this.originalContent;
1723
- this.root = document.createElement("div"), this.root.className = "wds-editor", this.root.dataset.theme = n.theme ?? "light", this.fileManager = n.fileManager?.listUrl ? new Sr(this.root, new xr(n.fileManager), this.t) : null, this.contentWrap = document.createElement("div"), this.contentWrap.className = "wds-content-wrap";
1724
- const o = Mt(n.height);
1725
- o ? (this.contentWrap.style.height = o, this.root.classList.add("wds-fixed-height")) : this.contentWrap.style.minHeight = Mt(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);
1726
- const s = jt.create({
1760
+ if (this.root = document.createElement("div"), this.root.className = "wds-editor", this.root.dataset.theme = n.theme ?? "light", typeof n.language != "object") {
1761
+ const i = jt(n.language);
1762
+ this.root.lang = i;
1763
+ const a = n.dir ?? "auto";
1764
+ a === "rtl" || a === "auto" && Ar(i) ? this.root.dir = "rtl" : a === "ltr" && (this.root.dir = "ltr");
1765
+ } else n.dir && n.dir !== "auto" && (this.root.dir = n.dir);
1766
+ this.fileManager = n.fileManager?.listUrl ? new Rr(this.root, new Hr(n.fileManager), this.t) : null, this.contentWrap = document.createElement("div"), this.contentWrap.className = "wds-content-wrap";
1767
+ const o = At(n.height);
1768
+ o ? (this.contentWrap.style.height = o, this.root.classList.add("wds-fixed-height")) : this.contentWrap.style.minHeight = At(n.minHeight ?? 240), this.sourceArea = document.createElement("textarea"), this.sourceArea.className = "wds-source", this.sourceArea.spellcheck = !1, this.sourceArea.dir = "ltr", this.sourceArea.hidden = !0, this.sourceArea.setAttribute("aria-label", this.t.sourceLabel);
1769
+ const s = Zt.create({
1727
1770
  schema: p,
1728
- doc: ge(r),
1771
+ doc: be(r),
1729
1772
  plugins: [
1730
- on(),
1731
- Ke({ Tab: Jn, "Shift-Tab": Xn }),
1732
- Zn(),
1733
- er({ link: () => (this.openLinkDialog(), !0) }),
1734
- tr(),
1735
- Jt(),
1736
- nr(n.placeholder ?? ""),
1737
- rr(),
1738
- xn(),
1739
- En({ class: "wds-dropcursor", color: !1 })
1773
+ hn(),
1774
+ Je({ Tab: or, "Shift-Tab": ir }),
1775
+ sr(),
1776
+ lr({ link: () => (this.openLinkDialog(), !0) }),
1777
+ cr(),
1778
+ rn(),
1779
+ dr(n.placeholder ?? ""),
1780
+ ur(),
1781
+ Nn(),
1782
+ In({ class: "wds-dropcursor", color: !1 })
1740
1783
  ]
1741
- }), l = {
1784
+ }), c = {
1742
1785
  onEdit: () => this.openImageUrlDialog(),
1743
1786
  resizeLabel: this.t.resizeImage,
1744
1787
  captionPlaceholder: this.t.captionPlaceholder
1745
1788
  };
1746
- this.view = new Vt(this.contentWrap, {
1789
+ this.view = new en(this.contentWrap, {
1747
1790
  state: s,
1748
1791
  editable: () => !this.readOnly,
1749
1792
  attributes: {
@@ -1753,68 +1796,68 @@ const re = class re {
1753
1796
  "aria-label": this.t.editorLabel
1754
1797
  },
1755
1798
  dispatchTransaction: (i) => this.dispatch(i),
1756
- transformPastedHTML: An,
1799
+ transformPastedHTML: On,
1757
1800
  handlePaste: (i, a) => {
1758
- const c = a.clipboardData;
1759
- if (this.plainPaste && c) {
1760
- const m = c.getData("text/plain");
1801
+ const l = a.clipboardData;
1802
+ if (this.plainPaste && l) {
1803
+ const m = l.getData("text/plain");
1761
1804
  if (m)
1762
- return i.dispatch(i.state.tr.replaceSelection(Tr(m)).scrollIntoView()), !0;
1805
+ return i.dispatch(i.state.tr.replaceSelection(zr(m)).scrollIntoView()), !0;
1763
1806
  }
1764
- if (!c?.files.length || !this.canUploadInline() || c.getData("text/plain")) return !1;
1765
- const u = [...c.files].filter((m) => m.type.startsWith("image/"));
1807
+ if (!l?.files.length || !this.canUploadInline() || l.getData("text/plain")) return !1;
1808
+ const u = [...l.files].filter((m) => m.type.startsWith("image/"));
1766
1809
  return u.length ? (this.uploadFiles(u), !0) : !1;
1767
1810
  },
1768
- handleDrop: (i, a, c, u) => {
1811
+ handleDrop: (i, a, l, u) => {
1769
1812
  const m = a.dataTransfer?.files;
1770
1813
  if (u || !m?.length || !this.canUploadInline()) return !1;
1771
1814
  const g = i.posAtCoords({ left: a.clientX, top: a.clientY })?.pos;
1772
1815
  return a.preventDefault(), this.uploadFiles([...m], g), !0;
1773
1816
  },
1774
1817
  nodeViews: {
1775
- image: (i, a, c) => new ur(i, a, c, l),
1776
- figure: (i, a, c) => new hr(i, a, c, l)
1818
+ image: (i, a, l) => new Mr(i, a, l, c),
1819
+ figure: (i, a, l) => new Lr(i, a, l, c)
1777
1820
  },
1778
1821
  handleDOMEvents: {
1779
1822
  focus: () => (this.root.classList.add("is-focused"), this.emit("focus"), !1),
1780
1823
  blur: () => (this.root.classList.remove("is-focused"), this.emit("blur"), !1)
1781
1824
  }
1782
- }), this.contentWrap.append(this.sourceArea), this.toolbar = dr(this, Ar(n.toolbar), this.t), this.toolbar.element.childElementCount && this.toolbar.element.firstElementChild.childElementCount && this.root.append(this.toolbar.element), this.root.append(this.contentWrap);
1825
+ }), this.contentWrap.append(this.sourceArea), this.toolbar = kr(this, $r(n.toolbar), this.t), this.toolbar.element.childElementCount && this.toolbar.element.firstElementChild.childElementCount && this.root.append(this.toolbar.element), this.root.append(this.contentWrap);
1783
1826
  const d = document.createElement("div");
1784
1827
  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) {
1785
1828
  const i = document.createElement("a");
1786
- i.className = "wds-branding", i.href = "https://webdevsnippets.com/wds-editor", i.target = "_blank", i.rel = "noopener", i.innerHTML = `${Cr(this.t.poweredBy)} <strong>WDS Editor</strong>`, d.append(i);
1829
+ i.className = "wds-branding", i.href = "https://webdevsnippets.com/wds-editor", i.target = "_blank", i.rel = "noopener", i.innerHTML = `${Br(this.t.poweredBy)} <strong>WDS Editor</strong>`, d.append(i);
1787
1830
  }
1788
- 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");
1831
+ 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), te.set(e, this), this.lastHtml = this.getHTML(), this.syncTarget(), this.refresh(), this.emit("init");
1789
1832
  }
1790
1833
  /** Creates (or returns the existing) editor for the first element matching options.selector. */
1791
1834
  static init(e) {
1792
1835
  const n = typeof e.selector == "string" ? document.querySelector(e.selector) : e.selector;
1793
1836
  if (!n) throw new Error(`[WDS Editor] No element matches "${String(e.selector)}".`);
1794
- return ne.get(n) ?? new re(n, e);
1837
+ return te.get(n) ?? new ne(n, e);
1795
1838
  }
1796
1839
  /** Creates editors for every element matching options.selector. */
1797
1840
  static initAll(e) {
1798
- return [...document.querySelectorAll(e.selector)].map((n) => ne.get(n) ?? new re(n, e));
1841
+ return [...document.querySelectorAll(e.selector)].map((n) => te.get(n) ?? new ne(n, e));
1799
1842
  }
1800
1843
  /** Returns the editor attached to an element (or selector), if any. */
1801
1844
  static get(e) {
1802
1845
  const n = typeof e == "string" ? document.querySelector(e) : e;
1803
- return n ? ne.get(n) : void 0;
1846
+ return n ? te.get(n) : void 0;
1804
1847
  }
1805
1848
  // ---------- content ----------
1806
1849
  getHTML() {
1807
- return this.sourceMode && this.applySource(), be(this.view.state.doc);
1850
+ return this.sourceMode && this.applySource(), we(this.view.state.doc);
1808
1851
  }
1809
1852
  /** Replaces the whole content. The change can be undone. */
1810
1853
  setHTML(e) {
1811
- this.sourceMode && (this.sourceArea.value = mt(e));
1812
- const n = ge(e), r = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, n.content);
1813
- this.dispatch(r.setSelection(Ve.atStart(r.doc)));
1854
+ this.sourceMode && (this.sourceArea.value = gt(e));
1855
+ const n = be(e), r = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, n.content);
1856
+ this.dispatch(r.setSelection(Ye.atStart(r.doc)));
1814
1857
  }
1815
1858
  /** Inserts HTML at the cursor (replacing the selection). */
1816
1859
  insertHTML(e) {
1817
- const n = ge(e), r = Dt.maxOpen(n.content);
1860
+ const n = be(e), r = Rt.maxOpen(n.content);
1818
1861
  this.dispatch(this.view.state.tr.replaceSelection(r).scrollIntoView());
1819
1862
  }
1820
1863
  getText() {
@@ -1825,7 +1868,7 @@ const re = class re {
1825
1868
  `);
1826
1869
  }
1827
1870
  isEmpty() {
1828
- return $t(this.view.state.doc);
1871
+ return Ut(this.view.state.doc);
1829
1872
  }
1830
1873
  // ---------- state ----------
1831
1874
  focus() {
@@ -1844,17 +1887,17 @@ const re = class re {
1844
1887
  return this.view.focus(), n;
1845
1888
  }
1846
1889
  undo() {
1847
- this.exec(At);
1890
+ this.exec(It);
1848
1891
  }
1849
1892
  redo() {
1850
- this.exec(Re);
1893
+ this.exec(Be);
1851
1894
  }
1852
1895
  // ---------- views ----------
1853
1896
  isSourceMode() {
1854
1897
  return this.sourceMode;
1855
1898
  }
1856
1899
  toggleSource() {
1857
- 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 = mt(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();
1900
+ 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 = gt(we(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();
1858
1901
  }
1859
1902
  isFullscreen() {
1860
1903
  return this.fullscreen;
@@ -1865,37 +1908,37 @@ const re = class re {
1865
1908
  // ---------- link dialog ----------
1866
1909
  openLinkDialog() {
1867
1910
  if (this.readOnly || this.sourceMode) return;
1868
- const e = this.view.state, n = We(e), { from: r, to: o, empty: s } = e.selection, l = s ? "" : e.doc.textBetween(r, o, " "), d = s && !n, i = this.t;
1869
- wt(this.root, {
1911
+ const e = this.view.state, n = Ge(e), { from: r, to: o, empty: s } = e.selection, c = s ? "" : e.doc.textBetween(r, o, " "), d = s && !n, i = this.t;
1912
+ Lt(this.root, {
1870
1913
  title: i.link,
1871
1914
  closeLabel: i.close,
1872
1915
  submitLabel: i.save,
1873
1916
  cancelLabel: i.cancel,
1874
1917
  fields: [
1875
1918
  { name: "href", label: i.linkUrl, type: "url", value: n?.href ?? "", placeholder: "https://" },
1876
- ...d ? [{ name: "text", label: i.linkText, type: "text", value: l }] : [],
1919
+ ...d ? [{ name: "text", label: i.linkText, type: "text", value: c }] : [],
1877
1920
  { name: "title", label: i.linkTitle, type: "text", value: n?.title ?? "" },
1878
1921
  { name: "newTab", label: i.linkNewTab, type: "checkbox", value: n?.target === "_blank" }
1879
1922
  ],
1880
1923
  extraAction: n ? { label: i.remove, onClick: () => this.removeLink() } : void 0,
1881
- validate: (a) => ot(String(a.href)) ? null : i.linkInvalid,
1924
+ validate: (a) => at(String(a.href)) ? null : i.linkInvalid,
1882
1925
  onSubmit: (a) => {
1883
- const c = ot(String(a.href)), u = { href: c, title: String(a.title).trim() || null, target: a.newTab ? "_blank" : null }, m = p.marks.link.create(u), g = this.view.state;
1884
- let v = g.tr;
1926
+ const l = at(String(a.href)), u = { href: l, title: String(a.title).trim() || null, target: a.newTab ? "_blank" : null }, m = p.marks.link.create(u), g = this.view.state;
1927
+ let k = g.tr;
1885
1928
  if (n)
1886
- v = v.removeMark(n.from, n.to, p.marks.link).addMark(n.from, n.to, m);
1929
+ k = k.removeMark(n.from, n.to, p.marks.link).addMark(n.from, n.to, m);
1887
1930
  else if (d) {
1888
- const D = String(a.text ?? "").trim() || c.replace(/^mailto:/, "");
1889
- v = v.replaceSelectionWith(p.text(D, [m]), !1);
1931
+ const D = String(a.text ?? "").trim() || l.replace(/^mailto:/, "");
1932
+ k = k.replaceSelectionWith(p.text(D, [m]), !1);
1890
1933
  } else
1891
- v = v.addMark(g.selection.from, g.selection.to, m);
1892
- this.dispatch(v.scrollIntoView());
1934
+ k = k.addMark(g.selection.from, g.selection.to, m);
1935
+ this.dispatch(k.scrollIntoView());
1893
1936
  },
1894
1937
  onClose: () => this.view.focus()
1895
1938
  });
1896
1939
  }
1897
1940
  removeLink() {
1898
- const e = We(this.view.state);
1941
+ const e = Ge(this.view.state);
1899
1942
  e && this.dispatch(this.view.state.tr.removeMark(e.from, e.to, p.marks.link));
1900
1943
  }
1901
1944
  // ---------- images and files ----------
@@ -1915,7 +1958,7 @@ const re = class re {
1915
1958
  height: e.width ? e.height ?? null : null,
1916
1959
  align: e.align ?? null
1917
1960
  }), o = this.view.state.tr.replaceSelectionWith(r);
1918
- return e.caption && bt(o, o.selection.from - 1, r.attrs), this.dispatch(o.scrollIntoView()), !0;
1961
+ return e.caption && vt(o, o.selection.from - 1, r.attrs), this.dispatch(o.scrollIntoView()), !0;
1919
1962
  }
1920
1963
  /**
1921
1964
  * Image button: edits the selected image, otherwise opens the file manager (when configured)
@@ -1923,7 +1966,7 @@ const re = class re {
1923
1966
  */
1924
1967
  openImageDialog() {
1925
1968
  if (this.readOnly || this.sourceMode) return;
1926
- qe(this.view.state) || !this.fileManager ? this.openImageUrlDialog() : this.openFileManager("image");
1969
+ je(this.view.state) || !this.fileManager ? this.openImageUrlDialog() : this.openFileManager("image");
1927
1970
  }
1928
1971
  /** Opens the file manager. "image" lists images (accept option, default image/*), "file" lists every file. */
1929
1972
  openFileManager(e = "image") {
@@ -1932,16 +1975,16 @@ const re = class re {
1932
1975
  accept: e === "image" ? this.options.fileManager?.accept ?? "image/*" : "",
1933
1976
  onFromUrl: e === "image" ? () => this.openImageUrlDialog() : void 0,
1934
1977
  onUpload: (n) => this.emit("upload", n),
1935
- onPick: ({ file: n, alt: r, width: o, align: s, text: l, caption: d }) => {
1936
- e === "image" && ue(n) ? this.insertImage({ src: n.url, alt: r, width: o, align: s, caption: d }) : this.insertFileLink(n, l), this.emit("fileSelect", n);
1978
+ onPick: ({ file: n, alt: r, width: o, align: s, text: c, caption: d }) => {
1979
+ e === "image" && ue(n) ? this.insertImage({ src: n.url, alt: r, width: o, align: s, caption: d }) : this.insertFileLink(n, c), this.emit("fileSelect", n);
1937
1980
  },
1938
1981
  onClose: () => this.view.focus()
1939
1982
  });
1940
1983
  }
1941
1984
  /** Dialog for an image by URL, or for editing the selected image (alt text, width, alignment). */
1942
1985
  openImageUrlDialog() {
1943
- const e = this.t, n = qe(this.view.state), r = n?.attrs ?? {};
1944
- wt(this.root, {
1986
+ const e = this.t, n = je(this.view.state), r = n?.attrs ?? {};
1987
+ Lt(this.root, {
1945
1988
  title: n ? e.imageEdit : e.image,
1946
1989
  closeLabel: e.close,
1947
1990
  submitLabel: n ? e.save : e.insert,
@@ -1966,17 +2009,17 @@ const re = class re {
1966
2009
  ],
1967
2010
  validate: (o) => q(String(o.src)) && !/^(mailto|tel):/i.test(String(o.src).trim()) ? null : e.imageInvalid,
1968
2011
  onSubmit: (o) => {
1969
- const s = parseInt(String(o.width), 10), l = {
2012
+ const s = parseInt(String(o.width), 10), c = {
1970
2013
  src: q(String(o.src)),
1971
2014
  alt: String(o.alt).trim(),
1972
2015
  width: s > 0 ? s : null,
1973
2016
  align: String(o.align) || null
1974
2017
  }, d = !!o.caption;
1975
2018
  if (n) {
1976
- const i = l.width && l.width === r.width ? r.height ?? null : null, a = { ...r, ...l, height: i }, c = this.view.state.tr;
1977
- d && !n.figure ? bt(c, n.pos, a) : !d && n.figure ? Vn(c, n.pos, n.node, a) : c.setNodeMarkup(n.pos, void 0, a).setSelection(he.create(c.doc, n.pos)), this.dispatch(c.scrollIntoView());
2019
+ const i = c.width && c.width === r.width ? r.height ?? null : null, a = { ...r, ...c, height: i }, l = this.view.state.tr;
2020
+ d && !n.figure ? vt(l, n.pos, a) : !d && n.figure ? tr(l, n.pos, n.node, a) : l.setNodeMarkup(n.pos, void 0, a).setSelection(he.create(l.doc, n.pos)), this.dispatch(l.scrollIntoView());
1978
2021
  } else
1979
- this.insertImage({ ...l, caption: d });
2022
+ this.insertImage({ ...c, caption: d });
1980
2023
  },
1981
2024
  onClose: () => this.view.focus()
1982
2025
  });
@@ -1986,31 +2029,31 @@ const re = class re {
1986
2029
  openTableMenu(e) {
1987
2030
  if (this.readOnly || this.sourceMode) return;
1988
2031
  const n = this.t, r = this.view.state;
1989
- if (!pe(r)) {
2032
+ if (!me(r)) {
1990
2033
  mr(
1991
2034
  e,
1992
2035
  this.root,
1993
2036
  n.tableInsert,
1994
- (l, d) => V(n.tableSize, { rows: String(l), cols: String(d) }),
1995
- (l, d) => this.exec(Yn(l, d))
2037
+ (c, d) => j(n.tableSize, { rows: String(c), cols: String(d) }),
2038
+ (c, d) => this.exec(rr(c, d))
1996
2039
  );
1997
2040
  return;
1998
2041
  }
1999
- const o = (l, d, i = !1) => ({ label: l, danger: i, enabled: d(r), run: () => this.exec(d) }), s = [
2000
- o(n.rowAbove, an),
2001
- o(n.rowBelow, It),
2002
- o(n.colLeft, sn),
2003
- o(n.colRight, ln),
2042
+ const o = (c, d, i = !1) => ({ label: c, danger: i, enabled: d(r), run: () => this.exec(d) }), s = [
2043
+ o(n.rowAbove, pn),
2044
+ o(n.rowBelow, zt),
2045
+ o(n.colLeft, mn),
2046
+ o(n.colRight, fn),
2004
2047
  "|",
2005
- o(n.deleteRow, cn),
2006
- o(n.deleteCol, dn),
2048
+ o(n.deleteRow, gn),
2049
+ o(n.deleteCol, bn),
2007
2050
  "|",
2008
- o(n.headerRow, un),
2009
- o(n.headerCol, hn),
2010
- o(n.mergeCells, pn),
2011
- o(n.splitCell, mn),
2051
+ o(n.headerRow, wn),
2052
+ o(n.headerCol, yn),
2053
+ o(n.mergeCells, vn),
2054
+ o(n.splitCell, kn),
2012
2055
  "|",
2013
- o(n.deleteTable, fn, !0)
2056
+ o(n.deleteTable, Mn, !0)
2014
2057
  ];
2015
2058
  pr(e, this.root, s, n.table);
2016
2059
  }
@@ -2018,14 +2061,14 @@ const re = class re {
2018
2061
  /** Opens the text color or highlight palette under the given toolbar button. */
2019
2062
  openColorPicker(e, n) {
2020
2063
  if (this.readOnly || this.sourceMode) return;
2021
- const r = this.t, s = ((e === "textColor" ? this.options.colors?.text : this.options.colors?.highlight) ?? (e === "textColor" ? Tn : Cn)).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);
2064
+ const r = this.t, s = ((e === "textColor" ? this.options.colors?.text : this.options.colors?.highlight) ?? (e === "textColor" ? Rn : $n)).map((c) => typeof c == "string" ? { color: c, name: c } : c).map((c) => ({ color: re(c.color), label: r[c.name] ?? c.name })).filter((c) => !!c.color);
2022
2065
  fr(n, this.root, {
2023
2066
  label: e === "textColor" ? r.textColor : r.highlight,
2024
2067
  removeLabel: e === "textColor" ? r.removeColor : r.removeHighlight,
2025
2068
  swatches: s,
2026
2069
  columns: e === "textColor" ? 5 : 6,
2027
- current: Ge(this.view.state, e),
2028
- onPick: (l) => this.exec(Qn(e, l))
2070
+ current: Ve(this.view.state, e),
2071
+ onPick: (c) => this.exec(ar(e, c))
2029
2072
  });
2030
2073
  }
2031
2074
  // ---------- paste ----------
@@ -2040,8 +2083,8 @@ const re = class re {
2040
2083
  insertFileLink(e, n) {
2041
2084
  const r = q(e.url);
2042
2085
  if (!r || this.readOnly || this.sourceMode) return;
2043
- const o = p.marks.link.create({ href: r }), s = this.view.state, l = s.selection.empty ? s.tr.replaceSelectionWith(p.text(n || e.name, [o]), !1) : s.tr.addMark(s.selection.from, s.selection.to, o);
2044
- this.dispatch(l.scrollIntoView());
2086
+ const o = p.marks.link.create({ href: r }), s = this.view.state, c = s.selection.empty ? s.tr.replaceSelectionWith(p.text(n || e.name, [o]), !1) : s.tr.addMark(s.selection.from, s.selection.to, o);
2087
+ this.dispatch(c.scrollIntoView());
2045
2088
  }
2046
2089
  canUploadInline() {
2047
2090
  return !!this.fileManager?.api.canUpload && !this.readOnly && !this.sourceMode;
@@ -2055,17 +2098,17 @@ const re = class re {
2055
2098
  const r = this.fileManager.api;
2056
2099
  for (const o of e) {
2057
2100
  const s = {};
2058
- let l = this.view.state.tr;
2059
- n === void 0 && !l.selection.empty && (l = l.deleteSelection());
2060
- const d = n ?? l.selection.from;
2061
- this.dispatch(l.setMeta(Q, { add: { id: s, pos: d } })), r.upload(o, this.fileManager.path).then((i) => {
2101
+ let c = this.view.state.tr;
2102
+ n === void 0 && !c.selection.empty && (c = c.deleteSelection());
2103
+ const d = n ?? c.selection.from;
2104
+ this.dispatch(c.setMeta(X, { add: { id: s, pos: d } })), r.upload(o, this.fileManager.path).then((i) => {
2062
2105
  if (this.destroyed) return;
2063
- const a = or(this.view.state, s);
2106
+ const a = hr(this.view.state, s);
2064
2107
  if (a === null) return;
2065
- const c = ue(i) ? p.nodes.image.create({ src: i.url, alt: "" }) : p.text(i.name, [p.marks.link.create({ href: i.url })]);
2066
- this.dispatch(this.view.state.tr.replaceWith(a, a, c).setMeta(Q, { remove: { id: s } })), this.emit("upload", i);
2108
+ const l = ue(i) ? p.nodes.image.create({ src: i.url, alt: "" }) : p.text(i.name, [p.marks.link.create({ href: i.url })]);
2109
+ this.dispatch(this.view.state.tr.replaceWith(a, a, l).setMeta(X, { remove: { id: s } })), this.emit("upload", i);
2067
2110
  }).catch((i) => {
2068
- this.destroyed || (this.dispatch(this.view.state.tr.setMeta(Q, { remove: { id: s } })), this.showNotice(V(this.t.fmUploadFailed, { name: o.name, error: i.message })));
2111
+ this.destroyed || (this.dispatch(this.view.state.tr.setMeta(X, { remove: { id: s } })), this.showNotice(j(this.t.fmUploadFailed, { name: o.name, error: i.message })));
2069
2112
  });
2070
2113
  }
2071
2114
  }
@@ -2085,23 +2128,23 @@ const re = class re {
2085
2128
  if (this.destroyed) return;
2086
2129
  this.emit("destroy");
2087
2130
  const e = this.getHTML();
2088
- this.destroyed = !0, window.clearTimeout(this.noticeTimer), Ft(), 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();
2131
+ this.destroyed = !0, window.clearTimeout(this.noticeTimer), _t(), 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, te.delete(this.target), this.listeners.clear();
2089
2132
  }
2090
2133
  // ---------- internals ----------
2091
2134
  dispatch(e) {
2092
2135
  if (this.destroyed) return;
2093
2136
  const n = this.view.state.apply(e);
2094
2137
  if (this.view.updateState(n), e.docChanged) {
2095
- const r = be(n.doc);
2138
+ const r = we(n.doc);
2096
2139
  r !== this.lastHtml && (this.lastHtml = r, this.syncTarget(r), this.options.onChange?.(r, this), this.emit("change"));
2097
2140
  }
2098
2141
  this.refresh();
2099
2142
  }
2100
2143
  applySource() {
2101
- const e = this.sourceArea.value, n = ge(e);
2144
+ const e = this.sourceArea.value, n = be(e);
2102
2145
  if (n.eq(this.view.state.doc)) return;
2103
2146
  const r = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, n.content), o = this.view.state.apply(r);
2104
- this.view.updateState(o), this.lastHtml = be(o.doc), this.syncTarget(this.lastHtml), this.options.onChange?.(this.lastHtml, this), this.emit("change");
2147
+ this.view.updateState(o), this.lastHtml = we(o.doc), this.syncTarget(this.lastHtml), this.options.onChange?.(this.lastHtml, this), this.emit("change");
2105
2148
  }
2106
2149
  syncTarget(e) {
2107
2150
  this.textarea && (this.textarea.value = e ?? this.getHTML());
@@ -2123,31 +2166,31 @@ const re = class re {
2123
2166
  });
2124
2167
  }
2125
2168
  };
2126
- re.version = "1.0.1", re.addLanguage = br;
2127
- let Lt = re;
2128
- function Tr(t) {
2169
+ ne.version = "1.1.0", ne.addLanguage = Gt;
2170
+ let Tt = ne;
2171
+ function zr(t) {
2129
2172
  const e = t.replace(/\r\n?/g, `
2130
2173
  `).split(/\n{2,}/).map((n) => {
2131
2174
  const o = n.split(`
2132
- `).flatMap((s, l) => [...l ? [p.nodes.hard_break.create()] : [], ...s ? [p.text(s)] : []]);
2175
+ `).flatMap((s, c) => [...c ? [p.nodes.hard_break.create()] : [], ...s ? [p.text(s)] : []]);
2133
2176
  return p.nodes.paragraph.create(null, o);
2134
2177
  });
2135
- return new Dt(Ct.from(e), 1, 1);
2178
+ return new Rt(Ot.from(e), 1, 1);
2136
2179
  }
2137
- function Cr(t) {
2180
+ function Br(t) {
2138
2181
  const e = document.createElement("span");
2139
2182
  return e.textContent = t, e.innerHTML;
2140
2183
  }
2141
2184
  export {
2142
- ar as DEFAULT_TOOLBAR,
2143
- Lt as WDSEditor,
2144
- br as addLanguage,
2145
- ve as en,
2185
+ br as DEFAULT_TOOLBAR,
2186
+ Tt as WDSEditor,
2187
+ Gt as addLanguage,
2188
+ ke as en,
2146
2189
  ue as isImage,
2147
- yt as matchesAccept,
2148
- vr as normalizeList,
2190
+ xt as matchesAccept,
2191
+ Cr as normalizeList,
2149
2192
  p as schema,
2150
- ir as toolbarItems,
2151
- gr as tr
2193
+ gr as toolbarItems,
2194
+ xr as tr
2152
2195
  };
2153
2196
  //# sourceMappingURL=wds-editor.js.map