wds-editor 1.0.1 → 1.2.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.
Files changed (45) hide show
  1. package/README.md +92 -3
  2. package/dist/lang/ar.d.mts +3 -0
  3. package/dist/lang/ar.js +6 -0
  4. package/dist/lang/ar.mjs +2 -0
  5. package/dist/lang/de.d.mts +3 -0
  6. package/dist/lang/de.js +6 -0
  7. package/dist/lang/de.mjs +2 -0
  8. package/dist/lang/es.d.mts +3 -0
  9. package/dist/lang/es.js +6 -0
  10. package/dist/lang/es.mjs +2 -0
  11. package/dist/lang/fr.d.mts +3 -0
  12. package/dist/lang/fr.js +6 -0
  13. package/dist/lang/fr.mjs +2 -0
  14. package/dist/lang/it.d.mts +3 -0
  15. package/dist/lang/it.js +6 -0
  16. package/dist/lang/it.mjs +2 -0
  17. package/dist/lang/ja.d.mts +3 -0
  18. package/dist/lang/ja.js +6 -0
  19. package/dist/lang/ja.mjs +2 -0
  20. package/dist/lang/pt.d.mts +3 -0
  21. package/dist/lang/pt.js +6 -0
  22. package/dist/lang/pt.mjs +2 -0
  23. package/dist/lang/ru.d.mts +3 -0
  24. package/dist/lang/ru.js +6 -0
  25. package/dist/lang/ru.mjs +2 -0
  26. package/dist/lang/zh.d.mts +3 -0
  27. package/dist/lang/zh.js +6 -0
  28. package/dist/lang/zh.mjs +2 -0
  29. package/dist/types/autosave.d.ts +37 -0
  30. package/dist/types/commands.d.ts +8 -2
  31. package/dist/types/contentcss.d.ts +24 -0
  32. package/dist/types/editor.d.ts +40 -2
  33. package/dist/types/filemanager/api.d.ts +3 -0
  34. package/dist/types/find.d.ts +38 -0
  35. package/dist/types/i18n.d.ts +27 -1
  36. package/dist/types/ui/menu.d.ts +2 -0
  37. package/dist/types/video.d.ts +20 -0
  38. package/dist/wds-editor.js +1480 -944
  39. package/dist/wds-editor.js.map +1 -1
  40. package/dist/wds-editor.min.css +1 -1
  41. package/dist/wds-editor.min.js +13 -12
  42. package/dist/wds-editor.min.js.map +1 -1
  43. package/dist/wds-editor.umd.cjs +6 -5
  44. package/dist/wds-editor.umd.cjs.map +1 -1
  45. package/package.json +84 -72
@@ -1,30 +1,119 @@
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 { NodeSelection as Z, TextSelection as be, PluginKey as Ut, Plugin as it, EditorState as pn } from "prosemirror-state";
2
+ import { DecorationSet as st, Decoration as ot, EditorView as gn } from "prosemirror-view";
3
+ import { redo as je, undo as Wt, redoDepth as bn, undoDepth as wn, history as yn } from "prosemirror-history";
4
+ import { Schema as _t, DOMParser as vn, DOMSerializer as kn, Fragment as Vt, Slice as qt } from "prosemirror-model";
5
+ import { addListNodes as Mn, sinkListItem as xn, liftListItem as Gt, wrapInList as Ln, splitListItem as Sn } from "prosemirror-schema-list";
6
+ import { tableNodes as En, isInTable as we, goToNextCell as Ke, addRowAfter as jt, tableEditing as An, addRowBefore as Tn, addColumnBefore as Cn, addColumnAfter as In, deleteRow as Dn, deleteColumn as Nn, toggleHeaderRow as Rn, toggleHeaderColumn as $n, mergeCells as On, splitCell as Hn, deleteTable as Pn } from "prosemirror-tables";
7
+ import { inputRules as Bn, InputRule as zn, textblockTypeInputRule as gt, wrappingInputRule as $e, undoInputRule as Fn } from "prosemirror-inputrules";
8
+ import { keymap as at } from "prosemirror-keymap";
9
+ import { lift as Kt, toggleMark as Un, setBlockType as Oe, wrapIn as Wn, chainCommands as _n, exitCode as Vn, baseKeymap as qn } from "prosemirror-commands";
10
+ import { gapCursor as Gn } from "prosemirror-gapcursor";
11
+ import { dropCursor as jn } from "prosemirror-dropcursor";
12
+ const Kn = /^(https?:|mailto:|tel:)/i, Yt = /^[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 Yt.test(n) && !Kn.test(n) ? null : e;
19
19
  }
20
- function ot(t) {
20
+ function bt(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}` : !Yt.test(e) && !/^[/#?.]/.test(e) && /^[\w-]+(\.[\w-]+)+/.test(e) ? `https://${e}` : q(e) : null;
23
23
  }
24
- function An(t) {
24
+ function Yn(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 Jn = /^[\w-]{11}$/, Jt = 560;
28
+ function Xn(t) {
29
+ if (!t) return 0;
30
+ if (/^\d+$/.test(t)) return +t;
31
+ const e = t.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);
32
+ return e ? +(e[1] ?? 0) * 3600 + +(e[2] ?? 0) * 60 + +(e[3] ?? 0) : 0;
33
+ }
34
+ function Le(t) {
35
+ if (!t) return null;
36
+ let e = t.trim();
37
+ const n = e.match(/<iframe[^>]*\ssrc=["']([^"']+)["']/i);
38
+ n && (e = n[1]), e.startsWith("//") && (e = `https:${e}`), /^https?:\/\//i.test(e) || (e = `https://${e}`);
39
+ let r;
40
+ try {
41
+ r = new URL(e.replace(/&amp;/g, "&"));
42
+ } catch {
43
+ return null;
44
+ }
45
+ const i = r.hostname.replace(/^(www|m|music)\./, ""), s = r.pathname.split("/").filter(Boolean);
46
+ if (i === "youtube.com" || i === "youtube-nocookie.com" || i === "youtu.be") {
47
+ let o = null;
48
+ if (i === "youtu.be" ? o = s[0] ?? null : s[0] === "watch" ? o = r.searchParams.get("v") : ["embed", "shorts", "live", "v"].includes(s[0]) && (o = s[1] ?? null), !o || !Jn.test(o)) return null;
49
+ const c = Xn(r.searchParams.get("start") ?? r.searchParams.get("t"));
50
+ return `https://www.youtube-nocookie.com/embed/${o}${c ? `?start=${c}` : ""}`;
51
+ }
52
+ if (i === "vimeo.com" || i === "player.vimeo.com") {
53
+ const o = s.findIndex((l) => /^\d+$/.test(l));
54
+ if (o < 0) return null;
55
+ const c = s[o], a = r.searchParams.get("h") ?? (i === "vimeo.com" && /^[\da-f]+$/i.test(s[o + 1] ?? "") ? s[o + 1] : null);
56
+ return `https://player.vimeo.com/video/${c}${a ? `?h=${a}` : ""}`;
57
+ }
58
+ return null;
59
+ }
60
+ const Qn = (t) => {
61
+ const e = parseInt(t.style.maxWidth, 10), n = parseInt(t.getAttribute("width") ?? "", 10), r = e > 0 ? e : n;
62
+ return r > 0 && r <= 4e3 ? r : null;
63
+ };
64
+ function Xt(t) {
65
+ const e = t.width ?? Jt;
66
+ return {
67
+ src: t.src,
68
+ title: t.title || "Video",
69
+ width: String(e),
70
+ height: String(Math.round(e * 9 / 16)),
71
+ style: `width: 100%; max-width: ${e}px; height: auto; aspect-ratio: 16 / 9; border: 0`,
72
+ allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
73
+ referrerpolicy: "strict-origin-when-cross-origin",
74
+ loading: "lazy",
75
+ allowfullscreen: "true"
76
+ };
77
+ }
78
+ const Zn = {
79
+ group: "block",
80
+ atom: !0,
81
+ draggable: !0,
82
+ attrs: { src: {}, title: { default: "" }, width: { default: null } },
83
+ parseDOM: [
84
+ {
85
+ tag: "iframe[src]",
86
+ getAttrs: (t) => {
87
+ const e = t, n = Le(e.getAttribute("src"));
88
+ if (!n) return !1;
89
+ const r = e.getAttribute("title") ?? "";
90
+ return { src: n, title: r === "Video" ? "" : r, width: Qn(e) };
91
+ }
92
+ }
93
+ ],
94
+ toDOM: (t) => ["iframe", Xt(t.attrs)]
95
+ };
96
+ class er {
97
+ constructor(e, n, r) {
98
+ this.onEdit = n, this.dom = document.createElement("div"), this.dom.className = "wds-video", this.dom.contentEditable = "false", this.iframe = document.createElement("iframe"), this.dom.append(this.iframe), this.dom.addEventListener("dblclick", () => this.onEdit()), this.render(e);
99
+ }
100
+ render(e) {
101
+ const n = Xt(e.attrs);
102
+ for (const [r, i] of Object.entries(n))
103
+ this.iframe.getAttribute(r) !== i && this.iframe.setAttribute(r, i);
104
+ this.iframe.tabIndex = -1, this.dom.style.maxWidth = `${e.attrs.width ?? Jt}px`;
105
+ }
106
+ update(e) {
107
+ return e.type.name !== "video" ? !1 : (this.render(e), !0);
108
+ }
109
+ stopEvent() {
110
+ return !1;
111
+ }
112
+ ignoreMutation() {
113
+ return !0;
114
+ }
115
+ }
116
+ const wt = {
28
117
  black: "#000000",
29
118
  white: "#ffffff",
30
119
  red: "#ff0000",
@@ -53,23 +142,23 @@ const it = {
53
142
  lightgrey: "#d3d3d3",
54
143
  darkgray: "#a9a9a9",
55
144
  darkgrey: "#a9a9a9"
56
- }, Ne = (t) => Math.max(0, Math.min(255, Math.round(t))).toString(16).padStart(2, "0");
57
- function oe(t) {
145
+ }, He = (t) => Math.max(0, Math.min(255, Math.round(t))).toString(16).padStart(2, "0");
146
+ function se(t) {
58
147
  if (!t) return null;
59
148
  const e = t.trim().toLowerCase().replace(/\s*!important$/, "");
60
- if (it[e]) return it[e];
149
+ if (wt[e]) return wt[e];
61
150
  let n = /^#([0-9a-f]{3})$/.exec(e);
62
- return n ? "#" + [...n[1]].map((r) => r + r).join("") : (n = /^#([0-9a-f]{6})(ff)?$/.exec(e), n ? "#" + n[1] : (n = /^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(e), n ? n[4] !== void 0 && (n[4].endsWith("%") ? parseFloat(n[4]) / 100 : parseFloat(n[4])) < 1 ? null : "#" + Ne(+n[1]) + Ne(+n[2]) + Ne(+n[3]) : null));
151
+ 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 : "#" + He(+n[1]) + He(+n[2]) + He(+n[3]) : null));
63
152
  }
64
- function at(t) {
65
- const e = oe(t);
153
+ function yt(t) {
154
+ const e = se(t);
66
155
  return e && e !== "#000000" ? e : null;
67
156
  }
68
- function Ie(t) {
69
- const e = oe(t) ?? oe((t ?? "").split(/\s+(?![^(]*\))/).find((n) => oe(n)));
157
+ function Pe(t) {
158
+ const e = se(t) ?? se((t ?? "").split(/\s+(?![^(]*\))/).find((n) => se(n)));
70
159
  return e && e !== "#ffffff" ? e : null;
71
160
  }
72
- const Tn = [
161
+ const tr = [
73
162
  { color: "#dc2626", name: "colorRed" },
74
163
  { color: "#ea580c", name: "colorOrange" },
75
164
  { color: "#ca8a04", name: "colorAmber" },
@@ -80,35 +169,35 @@ const Tn = [
80
169
  { color: "#db2777", name: "colorPink" },
81
170
  { color: "#475569", name: "colorSlate" },
82
171
  { color: "#94a3b8", name: "colorGray" }
83
- ], Cn = [
172
+ ], nr = [
84
173
  { color: "#fef08a", name: "colorYellow" },
85
174
  { color: "#bbf7d0", name: "colorGreen" },
86
175
  { color: "#bae6fd", name: "colorBlue" },
87
176
  { color: "#fbcfe8", name: "colorPink" },
88
177
  { color: "#fed7aa", name: "colorOrange" },
89
178
  { color: "#e9d5ff", name: "colorPurple" }
90
- ], Dn = ["left", "center", "right", "justify"];
91
- function st(t) {
179
+ ], rr = ["left", "center", "right", "justify"];
180
+ function vt(t) {
92
181
  const e = (t.style.textAlign || t.getAttribute("align") || "").toLowerCase();
93
- return Dn.includes(e) && e !== "left" ? e : null;
182
+ return rr.includes(e) && e !== "left" ? e : null;
94
183
  }
95
- function lt(t) {
184
+ function kt(t) {
96
185
  return t ? { style: `text-align: ${t}` } : {};
97
186
  }
98
- const Nn = {
187
+ const ir = {
99
188
  left: "float: left; margin: 0 1em 1em 0",
100
189
  right: "float: right; margin: 0 0 1em 1em",
101
190
  center: "display: block; margin-left: auto; margin-right: auto"
102
- }, In = {
191
+ }, sr = {
103
192
  left: "float: left; margin: 0 1em 1em 0",
104
193
  right: "float: right; margin: 0 0 1em 1em",
105
194
  center: "display: table; margin-left: auto; margin-right: auto"
106
195
  };
107
- function Hn(t) {
196
+ function or(t) {
108
197
  const e = t.style.float || t.getAttribute("align") || "";
109
198
  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
199
  }
111
- const ct = {
200
+ const Mt = {
112
201
  src: {},
113
202
  alt: { default: "" },
114
203
  title: { default: null },
@@ -116,35 +205,35 @@ const ct = {
116
205
  height: { default: null },
117
206
  align: { default: null }
118
207
  };
119
- function dt(t, e) {
208
+ function xt(t, e) {
120
209
  const n = q(t.getAttribute("src"));
121
210
  return n ? {
122
211
  src: n,
123
212
  alt: t.getAttribute("alt") ?? "",
124
213
  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)
214
+ width: Lt(t.getAttribute("width") ?? t.style.width),
215
+ height: Lt(t.getAttribute("height") ?? t.style.height),
216
+ align: or(e)
128
217
  } : !1;
129
218
  }
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;
134
- return a && (i.style = a), i;
219
+ function Ye(t, e) {
220
+ const { src: n, alt: r, title: i, width: s, height: o, align: c } = t, a = { src: n, alt: r ?? "" };
221
+ i && (a.title = i), s && (a.width = String(s)), s && o && (a.height = String(o));
222
+ const l = e ? ir[c] : void 0;
223
+ return l && (a.style = l), a;
135
224
  }
136
- function ut(t) {
225
+ function Lt(t) {
137
226
  const e = /^\s*(\d{1,5})(px)?\s*$/.exec(t ?? "");
138
227
  return e ? Number(e[1]) : null;
139
228
  }
140
- const On = {
229
+ const ar = {
141
230
  doc: { content: "block+" },
142
231
  paragraph: {
143
232
  content: "inline*",
144
233
  group: "block",
145
234
  attrs: { align: { default: null } },
146
- parseDOM: [{ tag: "p", getAttrs: (t) => ({ align: st(t) }) }],
147
- toDOM: (t) => ["p", lt(t.attrs.align), 0]
235
+ parseDOM: [{ tag: "p", getAttrs: (t) => ({ align: vt(t) }) }],
236
+ toDOM: (t) => ["p", kt(t.attrs.align), 0]
148
237
  },
149
238
  heading: {
150
239
  content: "inline*",
@@ -154,9 +243,9 @@ const On = {
154
243
  parseDOM: [1, 2, 3, 4, 5, 6].map((t) => ({
155
244
  tag: `h${t}`,
156
245
  // 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) })
246
+ getAttrs: (e) => ({ level: Math.min(t, 4), align: vt(e) })
158
247
  })),
159
- toDOM: (t) => [`h${t.attrs.level}`, lt(t.attrs.align), 0]
248
+ toDOM: (t) => [`h${t.attrs.level}`, kt(t.attrs.align), 0]
160
249
  },
161
250
  blockquote: {
162
251
  content: "block+",
@@ -192,15 +281,15 @@ const On = {
192
281
  ["code", t.attrs.language ? { class: `language-${t.attrs.language}` } : {}, 0]
193
282
  ]
194
283
  },
195
- ...rn({ tableGroup: "block", cellContent: "block+", cellAttributes: {} }),
284
+ ...En({ tableGroup: "block", cellContent: "block+", cellAttributes: {} }),
196
285
  text: { group: "inline" },
197
286
  image: {
198
287
  inline: !0,
199
288
  group: "inline",
200
289
  draggable: !0,
201
- attrs: ct,
202
- parseDOM: [{ tag: "img[src]", getAttrs: (t) => dt(t, t) }],
203
- toDOM: (t) => ["img", Be(t.attrs, !0)]
290
+ attrs: Mt,
291
+ parseDOM: [{ tag: "img[src]", getAttrs: (t) => xt(t, t) }],
292
+ toDOM: (t) => ["img", Ye(t.attrs, !0)]
204
293
  },
205
294
  /** Image with a caption: <figure><img><figcaption>…</figcaption></figure>. The caption is the node's content. */
206
295
  figure: {
@@ -209,22 +298,24 @@ const On = {
209
298
  marks: "_",
210
299
  draggable: !0,
211
300
  isolating: !0,
212
- attrs: ct,
301
+ attrs: Mt,
213
302
  parseDOM: [
214
303
  {
215
304
  tag: "figure",
216
305
  getAttrs: (t) => {
217
306
  const e = t.querySelector("img");
218
- return e ? dt(e, t) : !1;
307
+ return e ? xt(e, t) : !1;
219
308
  },
220
309
  contentElement: (t) => t.querySelector("figcaption") ?? document.createElement("figcaption")
221
310
  }
222
311
  ],
223
312
  toDOM: (t) => {
224
- const e = In[t.attrs.align];
225
- return ["figure", e ? { style: e } : {}, ["img", Be(t.attrs, !1)], ["figcaption", 0]];
313
+ const e = sr[t.attrs.align];
314
+ return ["figure", e ? { style: e } : {}, ["img", Ye(t.attrs, !1)], ["figcaption", 0]];
226
315
  }
227
316
  },
317
+ /** YouTube / Vimeo player (<iframe>); other iframes are dropped. */
318
+ video: Zn,
228
319
  hard_break: {
229
320
  inline: !0,
230
321
  group: "inline",
@@ -232,7 +323,7 @@ const On = {
232
323
  parseDOM: [{ tag: "br" }],
233
324
  toDOM: () => ["br"]
234
325
  }
235
- }, $n = {
326
+ }, lr = {
236
327
  link: {
237
328
  attrs: { href: {}, title: { default: null }, target: { default: null } },
238
329
  inclusive: !1,
@@ -294,14 +385,14 @@ const On = {
294
385
  {
295
386
  tag: "span",
296
387
  getAttrs: (t) => {
297
- const e = at(t.style.color);
388
+ const e = yt(t.style.color);
298
389
  return e ? { color: e } : !1;
299
390
  }
300
391
  },
301
392
  {
302
393
  tag: "font[color]",
303
394
  getAttrs: (t) => {
304
- const e = at(t.getAttribute("color"));
395
+ const e = yt(t.getAttribute("color"));
305
396
  return e ? { color: e } : !1;
306
397
  }
307
398
  }
@@ -314,247 +405,251 @@ const On = {
314
405
  parseDOM: [
315
406
  {
316
407
  tag: "mark",
317
- getAttrs: (t) => ({ color: Ie(t.style.backgroundColor) ?? "#fef08a" })
408
+ getAttrs: (t) => ({ color: Pe(t.style.backgroundColor) ?? "#fef08a" })
318
409
  },
319
410
  {
320
411
  style: "background-color",
321
412
  getAttrs: (t) => {
322
- const e = Ie(t);
413
+ const e = Pe(t);
323
414
  return e ? { color: e } : !1;
324
415
  }
325
416
  },
326
417
  {
327
418
  style: "background",
328
419
  getAttrs: (t) => {
329
- const e = Ie(t);
420
+ const e = Pe(t);
330
421
  return e ? { color: e } : !1;
331
422
  }
332
423
  }
333
424
  ],
334
- toDOM: (t) => ["mark", { style: `background-color: ${oe(t.attrs.color) ?? "#fef08a"}` }, 0]
425
+ toDOM: (t) => ["mark", { style: `background-color: ${se(t.attrs.color) ?? "#fef08a"}` }, 0]
335
426
  },
336
427
  code: {
337
428
  parseDOM: [{ tag: "code" }],
338
429
  toDOM: () => ["code", 0]
339
430
  }
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) {
431
+ }, St = new _t({ nodes: ar, marks: lr }), f = new _t({
432
+ nodes: Mn(St.spec.nodes, "paragraph block*", "block"),
433
+ marks: St.spec.marks
434
+ }), cr = kn.fromSchema(f), dr = vn.fromSchema(f);
435
+ function ke(t) {
345
436
  const e = new window.DOMParser().parseFromString(`<!doctype html><body>${t}`, "text/html");
346
- return zn.parse(e.body);
437
+ return dr.parse(e.body);
347
438
  }
348
- function be(t) {
349
- if ($t(t)) return "";
439
+ function Me(t) {
440
+ if (Qt(t)) return "";
350
441
  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;
442
+ return e.append(cr.serializeFragment(t.content)), e.querySelectorAll("[style]").forEach((n) => n.setAttribute("style", hr(n.getAttribute("style") ?? ""))), e.innerHTML;
352
443
  }
353
- const Bn = (t, e, n, r) => "#" + [e, n, r].map((o) => (+o).toString(16).padStart(2, "0")).join("");
354
- function Fn(t) {
444
+ const ur = (t, e, n, r) => "#" + [e, n, r].map((i) => (+i).toString(16).padStart(2, "0")).join("");
445
+ function hr(t) {
355
446
  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*/, ": ")
447
+ (e) => e.replace(/rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/g, ur).replace(/(^|[\s:])0px(?![\w.])/g, (n, r) => `${r}0`).replace(/\s*:\s*/, ": ")
357
448
  ).join("; ");
358
449
  }
359
- function $t(t) {
450
+ function Qt(t) {
360
451
  const e = t.firstChild;
361
- return t.childCount === 1 && !!e && e.type === p.nodes.paragraph && e.content.size === 0 && !e.attrs.align;
452
+ return t.childCount === 1 && !!e && e.type === f.nodes.paragraph && e.content.size === 0 && !e.attrs.align;
362
453
  }
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) => {
454
+ const Je = /* @__PURE__ */ new Set(["UL", "OL", "BLOCKQUOTE", "TABLE", "THEAD", "TBODY", "TFOOT", "TR", "FIGURE"]), Xe = /* @__PURE__ */ new Set(["LI", "TH", "TD"]), Et = (t) => t.nodeType === 1 && (Je.has(t.tagName) || Xe.has(t.tagName) || /^(P|H[1-6]|PRE|HR|FIGCAPTION|IMG|DIV|IFRAME)$/.test(t.tagName)), fr = (t) => {
364
455
  const n = t.cloneNode(!1).outerHTML;
365
456
  return n.slice(0, n.length - `</${t.localName}>`.length);
366
457
  };
367
- function mt(t) {
458
+ function At(t) {
368
459
  const e = document.createElement("div");
369
460
  e.innerHTML = t;
370
- const n = [], r = (o, s) => {
371
- const l = " ".repeat(s);
372
- let d = "";
373
- const i = () => {
374
- d.trim() && n.push(l + d.trim()), d = "";
461
+ const n = [], r = (i, s) => {
462
+ const o = " ".repeat(s);
463
+ let c = "";
464
+ const a = () => {
465
+ c.trim() && n.push(o + c.trim()), c = "";
375
466
  };
376
- o.childNodes.forEach((a) => {
377
- if (!pt(a)) {
378
- d += a.nodeType === 1 ? a.outerHTML : a.nodeType === 3 ? Pn(a.textContent ?? "") : "";
467
+ i.childNodes.forEach((l) => {
468
+ if (!Et(l)) {
469
+ c += l.nodeType === 1 ? l.outerHTML : l.nodeType === 3 ? mr(l.textContent ?? "") : "";
379
470
  return;
380
471
  }
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}>`));
384
- }), i();
472
+ a();
473
+ const d = l, u = Array.from(d.childNodes).filter(Et);
474
+ (Xe.has(d.tagName) ? u.length <= 1 && u.every((p) => !Je.has(p.tagName) && !Xe.has(p.tagName)) : !Je.has(d.tagName)) ? n.push(o + d.outerHTML) : (n.push(o + fr(d)), r(d, s + 1), n.push(`${o}</${d.localName}>`));
475
+ }), a();
385
476
  };
386
477
  return r(e, 0), n.join(`
387
478
  `);
388
479
  }
389
- const Pn = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/ /g, "&nbsp;");
390
- function de(t, e) {
391
- const { from: n, $from: r, to: o, empty: s } = t.selection;
392
- return s ? !!e.isInSet(t.storedMarks || r.marks()) : t.doc.rangeHasMark(n, o, e);
480
+ const mr = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/ /g, "&nbsp;");
481
+ function fe(t, e) {
482
+ const { from: n, $from: r, to: i, empty: s } = t.selection;
483
+ return s ? !!e.isInSet(t.storedMarks || r.marks()) : t.doc.rangeHasMark(n, i, e);
393
484
  }
394
- function _n(t) {
485
+ function pr(t) {
395
486
  const e = t.selection.$from.parent;
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;
487
+ return e.type === f.nodes.paragraph ? "paragraph" : e.type === f.nodes.code_block ? "codeBlock" : e.type === f.nodes.heading ? `heading${e.attrs.level}` : null;
397
488
  }
398
- function Wn(t) {
399
- return t === "paragraph" ? De(p.nodes.paragraph) : t === "codeBlock" ? De(p.nodes.code_block) : De(p.nodes.heading, { level: Number(t.slice(-1)) });
489
+ function gr(t) {
490
+ return t === "paragraph" ? Oe(f.nodes.paragraph) : t === "codeBlock" ? Oe(f.nodes.code_block) : Oe(f.nodes.heading, { level: Number(t.slice(-1)) });
400
491
  }
401
- const _ = (t) => yn(p.marks[t]);
402
- function Rt(t, e) {
492
+ const _ = (t) => Un(f.marks[t]);
493
+ function Zt(t, e) {
403
494
  const { $from: n } = t.selection;
404
495
  for (let r = n.depth; r > 0; r--) if (n.node(r).type === e) return !0;
405
496
  return !1;
406
497
  }
407
- function ft(t) {
498
+ function Tt(t) {
408
499
  const { $from: e } = t.selection;
409
500
  for (let n = e.depth; n > 0; n--) {
410
501
  const r = e.node(n).type;
411
- if (r === p.nodes.bullet_list || r === p.nodes.ordered_list) return r;
502
+ if (r === f.nodes.bullet_list || r === f.nodes.ordered_list) return r;
412
503
  }
413
504
  return null;
414
505
  }
415
- function gt(t) {
506
+ function Ct(t) {
416
507
  return (e, n, r) => {
417
- const { $from: o } = e.selection;
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);
508
+ const { $from: i } = e.selection;
509
+ for (let s = i.depth; s > 0; s--) {
510
+ const o = i.node(s);
511
+ if (o.type === f.nodes.bullet_list || o.type === f.nodes.ordered_list)
512
+ return o.type === t ? Gt(f.nodes.list_item)(e, n, r) : (n && n(e.tr.setNodeMarkup(i.before(s), t)), !0);
422
513
  }
423
- return tn(t)(e, n, r);
514
+ return Ln(t)(e, n, r);
424
515
  };
425
516
  }
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);
517
+ const Qe = xn(f.nodes.list_item), Ze = (t, e, n) => Gt(f.nodes.list_item)(t, e, n) || Kt(t, e);
518
+ function br() {
519
+ return (t, e) => Zt(t, f.nodes.blockquote) ? Kt(t, e) : Wn(f.nodes.blockquote)(t, e);
429
520
  }
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;
521
+ function It(t, e = "left") {
522
+ return (n, r) => {
523
+ const i = t === e ? null : t, { from: s, to: o } = n.selection, c = n.tr;
524
+ let a = !1;
525
+ return n.doc.nodesBetween(s, o, (l, d) => l.type === f.nodes.paragraph || l.type === f.nodes.heading ? (a = !0, l.attrs.align !== i && c.setNodeMarkup(d, void 0, { ...l.attrs, align: i }), !1) : !0), a ? (r && r(c), !0) : !1;
435
526
  };
436
527
  }
437
- function we(t) {
438
- return t.selection.$from.parent.attrs.align ?? "left";
528
+ function wr(t, e = "left") {
529
+ return t.selection.$from.parent.attrs.align ?? e;
439
530
  }
440
- const Gn = (t, e) => {
441
- const n = p.nodes.horizontal_rule;
531
+ const yr = (t, e) => {
532
+ const n = f.nodes.horizontal_rule;
442
533
  if (!e) return !0;
443
- const r = t.tr.replaceSelectionWith(n.create()), o = r.selection.$from;
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) => {
446
- const { from: n, to: r, empty: o } = t.selection, s = t.tr;
447
- if (o)
534
+ const r = t.tr.replaceSelectionWith(n.create()), i = r.selection.$from;
535
+ return !i.nodeAfter && i.parent.type === f.nodes.doc && r.insert(i.pos, f.nodes.paragraph.create()), e(r.scrollIntoView()), !0;
536
+ }, vr = (t, e) => {
537
+ const { from: n, to: r, empty: i } = t.selection, s = t.tr;
538
+ if (i)
448
539
  s.setStoredMarks([]);
449
540
  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;
541
+ for (const o of Object.values(f.marks)) o !== f.marks.link && s.removeMark(n, r, o);
542
+ return t.doc.nodesBetween(n, r, (o, c) => o.isTextblock && o.type !== f.nodes.paragraph ? (s.setBlockType(c, c + o.nodeSize, f.nodes.paragraph), !1) : (o.type === f.nodes.paragraph && o.attrs.align && s.setNodeMarkup(c, void 0, { align: null }), !0)), e && e(s), !0;
452
543
  };
453
- function We(t) {
454
- const e = p.marks.link, { $from: n, from: r, to: o, empty: s } = t.selection;
544
+ function et(t) {
545
+ const e = f.marks.link, { $from: n, from: r, to: i, empty: s } = t.selection;
455
546
  if (!s) {
456
547
  let u = null;
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 });
548
+ return t.doc.nodesBetween(r, i, (m, p) => {
549
+ const b = e.isInSet(m.marks);
550
+ b && !u && (u = { from: Math.max(p, r), to: Math.min(p + m.nodeSize, i), ...b.attrs });
460
551
  }), u;
461
552
  }
462
- const l = e.isInSet(n.marks()) ?? e.isInSet(n.nodeBefore?.marks ?? []);
463
- if (!l) return null;
464
- const d = n.start(), i = [];
465
- let a = 0;
553
+ const o = e.isInSet(n.marks()) ?? e.isInSet(n.nodeBefore?.marks ?? []);
554
+ if (!o) return null;
555
+ const c = n.start(), a = [];
556
+ let l = 0;
466
557
  n.parent.forEach((u) => {
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]);
558
+ const m = c + l, p = m + u.nodeSize;
559
+ if (o.isInSet(u.marks)) {
560
+ const b = a[a.length - 1];
561
+ b && b[1] === m ? b[1] = p : a.push([m, p]);
471
562
  }
472
- a += u.nodeSize;
563
+ l += u.nodeSize;
473
564
  });
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;
565
+ const d = a.find(([u, m]) => u <= n.pos && n.pos <= m);
566
+ return d ? { from: d[0], to: d[1], ...o.attrs } : null;
476
567
  }
477
- function qe(t) {
568
+ function en(t) {
478
569
  const e = t.selection;
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;
570
+ return e instanceof Z && e.node.type === f.nodes.video ? { pos: e.from, node: e.node } : null;
480
571
  }
481
- function bt(t, e, n) {
482
- const r = p.nodes.figure.create(n), o = t.doc.resolve(e), s = o.parent;
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;
572
+ function tt(t) {
573
+ const e = t.selection;
574
+ return e instanceof Z && (e.node.type === f.nodes.image || e.node.type === f.nodes.figure) ? { pos: e.from, attrs: e.node.attrs, figure: e.node.type === f.nodes.figure, node: e.node } : null;
486
575
  }
487
- function Vn(t, e, n, r) {
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));
576
+ function Dt(t, e, n) {
577
+ const r = f.nodes.figure.create(n), i = t.doc.resolve(e), s = i.parent;
578
+ s.type === f.nodes.paragraph && s.childCount === 1 ? t.replaceWith(i.before(), i.after(), r) : t.replaceRangeWith(e, e + 1, r);
579
+ let o = -1;
580
+ return t.doc.descendants((c, a) => o >= 0 ? !1 : (c.type === f.nodes.figure && c.attrs.src === n.src && c.content.size === 0 && (o = a), !0)), o >= 0 && t.setSelection(be.create(t.doc, o + 1)), t;
490
581
  }
491
- function Kn(t, e, n = !0) {
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)));
582
+ function kr(t, e, n, r) {
583
+ const i = f.nodes.image.create(r), s = [f.nodes.paragraph.create(null, i)];
584
+ return n.content.size && s.push(f.nodes.paragraph.create(null, n.content)), t.replaceWith(e, e + n.nodeSize, Vt.from(s)), t.setSelection(Z.create(t.doc, e + 1));
494
585
  }
495
- function Yn(t, e) {
586
+ function Mr(t, e, n = !0) {
587
+ const r = f.nodes, i = (s) => r.table_row.create(null, Array.from({ length: e }, () => s.createAndFill()));
588
+ return r.table.create(null, Array.from({ length: t }, (s, o) => i(n && o === 0 ? r.table_header : r.table_cell)));
589
+ }
590
+ function xr(t, e) {
496
591
  return (n, r) => {
497
- if (pe(n)) return !1;
592
+ if (we(n)) return !1;
498
593
  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);
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) {
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));
594
+ const i = Mr(t, e), s = n.tr, o = n.selection.$from;
595
+ o.parent.type === f.nodes.paragraph && o.parent.content.size === 0 && o.depth === 1 ? s.replaceWith(o.before(), o.after(), i) : s.replaceSelectionWith(i);
596
+ let a = -1;
597
+ if (s.doc.descendants((l, d) => a >= 0 ? !1 : (l === i && (a = d), a < 0 && l.type !== f.nodes.table)), a >= 0) {
598
+ const l = a + s.doc.nodeAt(a).nodeSize;
599
+ l >= s.doc.content.size && s.insert(l, f.nodes.paragraph.create()), s.setSelection(be.create(s.doc, a + 4));
505
600
  }
506
601
  return r(s.scrollIntoView()), !0;
507
602
  };
508
603
  }
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;
513
- let d;
514
- return t.doc.nodesBetween(r, o, (i) => {
515
- if (!i.isText || d === null) return;
516
- const a = n.isInSet(i.marks)?.attrs.color ?? null;
517
- d = d === void 0 || d === a ? a : null;
518
- }), d ?? null;
519
- }
520
- function Qn(t, e) {
604
+ const Lr = (t, e, n) => we(t) ? Ke(1)(t, e) || !e || !n ? !0 : (jt(t, e), Ke(1)(n.state, e)) : !1, Sr = (t, e) => we(t) && Ke(-1)(t, e);
605
+ function nt(t, e) {
606
+ const n = f.marks[e], { from: r, to: i, empty: s, $from: o } = t.selection;
607
+ if (s) return n.isInSet(t.storedMarks || o.marks())?.attrs.color ?? null;
608
+ let c;
609
+ return t.doc.nodesBetween(r, i, (a) => {
610
+ if (!a.isText || c === null) return;
611
+ const l = n.isInSet(a.marks)?.attrs.color ?? null;
612
+ c = c === void 0 || c === l ? l : null;
613
+ }), c ?? null;
614
+ }
615
+ function Er(t, e) {
521
616
  return (n, r) => {
522
- const o = p.marks[t], { from: s, to: l, empty: d } = n.selection;
617
+ const i = f.marks[t], { from: s, to: o, empty: c } = n.selection;
523
618
  if (!r) return !0;
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;
619
+ const a = n.tr;
620
+ return c ? (a.removeStoredMark(i), e && a.addStoredMark(i.create({ color: e }))) : (a.removeMark(s, o, i), e && a.addMark(s, o, i.create({ color: e }))), r(a.scrollIntoView()), !0;
526
621
  };
527
622
  }
528
- function Zn() {
529
- const t = p.nodes;
530
- return gn({
623
+ function Ar() {
624
+ const t = f.nodes;
625
+ return Bn({
531
626
  rules: [
532
- rt(/^(#{1,4})\s$/, t.heading, (e) => ({ level: e[1].length })),
533
- Ce(/^\s*>\s$/, t.blockquote),
534
- Ce(/^\s*([-+*])\s$/, t.bullet_list),
535
- Ce(
627
+ gt(/^(#{1,4})\s$/, t.heading, (e) => ({ level: e[1].length })),
628
+ $e(/^\s*>\s$/, t.blockquote),
629
+ $e(/^\s*([-+*])\s$/, t.bullet_list),
630
+ $e(
536
631
  /^(\d+)\.\s$/,
537
632
  t.ordered_list,
538
633
  (e) => ({ order: +e[1] }),
539
634
  (e, n) => n.childCount + n.attrs.order === +e[1]
540
635
  ),
541
- rt(/^```$/, t.code_block),
542
- new bn(/^(?:---|\*\*\*|___)$/, (e, n, r, o) => {
636
+ gt(/^```$/, t.code_block),
637
+ new zn(/^(?:---|\*\*\*|___)$/, (e, n, r, i) => {
543
638
  const s = e.doc.resolve(r);
544
639
  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()]);
640
+ const o = s.before();
641
+ return e.tr.replaceWith(o, i + 1, [t.horizontal_rule.create(), t.paragraph.create()]);
547
642
  })
548
643
  ]
549
644
  });
550
645
  }
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,
646
+ function Tr(t) {
647
+ const e = _n(Vn, (n, r) => (r && r(n.tr.replaceSelectionWith(f.nodes.hard_break.create()).scrollIntoView()), !0));
648
+ return at({
649
+ "Mod-z": Wt,
650
+ "Mod-y": je,
651
+ "Shift-Mod-z": je,
652
+ Backspace: Fn,
558
653
  "Mod-b": _("strong"),
559
654
  "Mod-i": _("em"),
560
655
  "Mod-u": _("underline"),
@@ -563,36 +658,36 @@ function er(t) {
563
658
  "Mod-k": t.link,
564
659
  "Shift-Enter": e,
565
660
  "Mod-Enter": e,
566
- Enter: nn(p.nodes.list_item),
567
- Tab: Pe,
568
- "Shift-Tab": _e
661
+ Enter: Sn(f.nodes.list_item),
662
+ Tab: Qe,
663
+ "Shift-Tab": Ze
569
664
  });
570
665
  }
571
- const tr = () => Ke(Ln);
572
- function nr(t) {
573
- return new xt({
666
+ const Cr = () => at(qn);
667
+ function Ir(t) {
668
+ return new it({
574
669
  props: {
575
670
  decorations(e) {
576
671
  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 })
672
+ return !t || n.childCount !== 1 || !r || !r.isTextblock || r.content.size > 0 ? null : st.create(n, [
673
+ ot.node(0, r.nodeSize, { class: "wds-placeholder", "data-placeholder": t })
579
674
  ]);
580
675
  }
581
676
  }
582
677
  });
583
678
  }
584
- const Q = new Gt("wds-upload");
585
- function rr() {
586
- return new xt({
679
+ const Q = new Ut("wds-upload");
680
+ function Dr() {
681
+ return new it({
587
682
  key: Q,
588
683
  state: {
589
- init: () => Et.empty,
684
+ init: () => st.empty,
590
685
  apply(t, e) {
591
686
  e = e.map(t.mapping, t.doc);
592
687
  const n = t.getMeta(Q);
593
688
  if (n && "add" in n) {
594
689
  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 })]);
690
+ r.className = "wds-upload-placeholder", r.setAttribute("aria-hidden", "true"), e = e.add(t.doc, [ot.widget(n.add.pos, r, { id: n.add.id })]);
596
691
  } else n && "remove" in n && (e = e.remove(e.find(void 0, void 0, (r) => r.id === n.remove.id)));
597
692
  return e;
598
693
  }
@@ -602,76 +697,197 @@ function rr() {
602
697
  }
603
698
  });
604
699
  }
605
- function or(t, e) {
700
+ function Nr(t, e) {
606
701
  const n = Q.getState(t)?.find(void 0, void 0, (r) => r.id === e);
607
702
  return n && n.length ? n[0].from : null;
608
703
  }
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 = {
610
- undo: E('<path d="M9 14 4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>'),
611
- redo: E('<path d="m15 14 5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>'),
612
- bold: E('<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7z"/>'),
613
- italic: E('<path d="M14 5h-4"/><path d="M14 19h-4"/><path d="m14 5-4 14"/><path d="M18 5h-4M10 19H6"/>'),
614
- underline: E('<path d="M7 4v7a5 5 0 0 0 10 0V4"/><path d="M5 20h14"/>'),
615
- strike: E('<path d="M4 12h16"/><path d="M16.5 7.5C16 5.6 14.2 4.5 12 4.5c-2.6 0-4.5 1.4-4.5 3.4 0 1.3.8 2.3 2.4 3"/><path d="M8 16.5c.6 1.9 2.2 3 4.3 3 2.7 0 4.6-1.4 4.6-3.6 0-.9-.3-1.6-.9-2.2"/>'),
616
- code: E('<path d="m9 8-4 4 4 4"/><path d="m15 8 4 4-4 4"/>'),
617
- link: E('<path d="M10 14a4.5 4.5 0 0 0 6.4 0l3-3a4.5 4.5 0 0 0-6.4-6.4l-1 1"/><path d="M14 10a4.5 4.5 0 0 0-6.4 0l-3 3a4.5 4.5 0 0 0 6.4 6.4l1-1"/>'),
618
- blockquote: E('<path d="M5 18c2.5-1 4-3.2 4-6.5V7H5v5h3"/><path d="M14 18c2.5-1 4-3.2 4-6.5V7h-4v5h3"/>'),
619
- bulletList: E('<circle cx="5" cy="7" r="1" fill="currentColor"/><circle cx="5" cy="12" r="1" fill="currentColor"/><circle cx="5" cy="17" r="1" fill="currentColor"/><path d="M9 7h11M9 12h11M9 17h11"/>'),
620
- orderedList: E('<path d="M10 7h10M10 12h10M10 17h10"/><path d="M4 5.5 5.5 5v4"/><path d="M4 14.2c.3-.6.8-.9 1.4-.9.7 0 1.1.4 1.1 1 0 .9-1.4 1.6-2.5 2.7h2.6"/>'),
621
- indent: E('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m4 9.5 3 2.5-3 2.5"/>'),
622
- outdent: E('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m7 9.5-3 2.5 3 2.5"/>'),
623
- alignLeft: E('<path d="M4 6h16M4 10h10M4 14h16M4 18h10"/>'),
624
- alignCenter: E('<path d="M4 6h16M7 10h10M4 14h16M7 18h10"/>'),
625
- alignRight: E('<path d="M4 6h16M10 10h10M4 14h16M10 18h10"/>'),
626
- alignJustify: E('<path d="M4 6h16M4 10h16M4 14h16M4 18h16"/>'),
627
- hr: E('<path d="M3 12h18"/><path d="M8 7h8M8 17h8" opacity=".45"/>'),
628
- clear: E('<path d="M6 5h12"/><path d="M12 5 9 19"/><path d="m15 14 5 5M20 14l-5 5"/>'),
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
- fullscreen: E('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),
631
- close: E('<path d="M6 6l12 12M18 6 6 18"/>'),
632
- 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
- 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"/>'),
634
- folder: E('<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>'),
635
- upload: E('<path d="M12 16V4"/><path d="m7 9 5-5 5 5"/><path d="M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3"/>'),
636
- grid: E('<rect x="4" y="4" width="6" height="6" rx="1"/><rect x="14" y="4" width="6" height="6" rx="1"/><rect x="4" y="14" width="6" height="6" rx="1"/><rect x="14" y="14" width="6" height="6" rx="1"/>'),
637
- list: E('<path d="M9 6h11M9 12h11M9 18h11"/><path d="M4 6h1M4 12h1M4 18h1"/>'),
638
- trash: E('<path d="M4 7h16"/><path d="M10 11v6M14 11v6"/><path d="M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12"/><path d="M9 7V4h6v3"/>'),
639
- table: E('<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16"/>'),
640
- pasteText: E('<path d="M9 4h6v3H9z"/><path d="M15 5h2a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2"/><path d="M9 12h6M12 12v6"/>'),
704
+ const S = (t) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${t}</svg>`, L = {
705
+ undo: S('<path d="M9 14 4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>'),
706
+ redo: S('<path d="m15 14 5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>'),
707
+ bold: S('<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7z"/>'),
708
+ italic: S('<path d="M14 5h-4"/><path d="M14 19h-4"/><path d="m14 5-4 14"/><path d="M18 5h-4M10 19H6"/>'),
709
+ underline: S('<path d="M7 4v7a5 5 0 0 0 10 0V4"/><path d="M5 20h14"/>'),
710
+ strike: S('<path d="M4 12h16"/><path d="M16.5 7.5C16 5.6 14.2 4.5 12 4.5c-2.6 0-4.5 1.4-4.5 3.4 0 1.3.8 2.3 2.4 3"/><path d="M8 16.5c.6 1.9 2.2 3 4.3 3 2.7 0 4.6-1.4 4.6-3.6 0-.9-.3-1.6-.9-2.2"/>'),
711
+ code: S('<path d="m9 8-4 4 4 4"/><path d="m15 8 4 4-4 4"/>'),
712
+ link: S('<path d="M10 14a4.5 4.5 0 0 0 6.4 0l3-3a4.5 4.5 0 0 0-6.4-6.4l-1 1"/><path d="M14 10a4.5 4.5 0 0 0-6.4 0l-3 3a4.5 4.5 0 0 0 6.4 6.4l1-1"/>'),
713
+ blockquote: S('<path d="M5 18c2.5-1 4-3.2 4-6.5V7H5v5h3"/><path d="M14 18c2.5-1 4-3.2 4-6.5V7h-4v5h3"/>'),
714
+ bulletList: S('<circle cx="5" cy="7" r="1" fill="currentColor"/><circle cx="5" cy="12" r="1" fill="currentColor"/><circle cx="5" cy="17" r="1" fill="currentColor"/><path d="M9 7h11M9 12h11M9 17h11"/>'),
715
+ orderedList: S('<path d="M10 7h10M10 12h10M10 17h10"/><path d="M4 5.5 5.5 5v4"/><path d="M4 14.2c.3-.6.8-.9 1.4-.9.7 0 1.1.4 1.1 1 0 .9-1.4 1.6-2.5 2.7h2.6"/>'),
716
+ indent: S('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m4 9.5 3 2.5-3 2.5"/>'),
717
+ outdent: S('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m7 9.5-3 2.5 3 2.5"/>'),
718
+ alignLeft: S('<path d="M4 6h16M4 10h10M4 14h16M4 18h10"/>'),
719
+ alignCenter: S('<path d="M4 6h16M7 10h10M4 14h16M7 18h10"/>'),
720
+ alignRight: S('<path d="M4 6h16M10 10h10M4 14h16M10 18h10"/>'),
721
+ alignJustify: S('<path d="M4 6h16M4 10h16M4 14h16M4 18h16"/>'),
722
+ hr: S('<path d="M3 12h18"/><path d="M8 7h8M8 17h8" opacity=".45"/>'),
723
+ clear: S('<path d="M6 5h12"/><path d="M12 5 9 19"/><path d="m15 14 5 5M20 14l-5 5"/>'),
724
+ source: S('<path d="m8 7-5 5 5 5"/><path d="m16 7 5 5-5 5"/><path d="m14 4-4 16"/>'),
725
+ fullscreen: S('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),
726
+ 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>',
727
+ close: S('<path d="M6 6l12 12M18 6 6 18"/>'),
728
+ image: S('<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="8.5" cy="9.5" r="1.5"/><path d="m21 16-5-5-9 9"/>'),
729
+ file: S('<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M9 13h6M9 17h4"/>'),
730
+ folder: S('<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>'),
731
+ upload: S('<path d="M12 16V4"/><path d="m7 9 5-5 5 5"/><path d="M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3"/>'),
732
+ grid: S('<rect x="4" y="4" width="6" height="6" rx="1"/><rect x="14" y="4" width="6" height="6" rx="1"/><rect x="4" y="14" width="6" height="6" rx="1"/><rect x="14" y="14" width="6" height="6" rx="1"/>'),
733
+ list: S('<path d="M9 6h11M9 12h11M9 18h11"/><path d="M4 6h1M4 12h1M4 18h1"/>'),
734
+ trash: S('<path d="M4 7h16"/><path d="M10 11v6M14 11v6"/><path d="M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12"/><path d="M9 7V4h6v3"/>'),
735
+ video: S('<rect x="3" y="5" width="18" height="14" rx="3"/><path d="m10 9 5 3-5 3z"/>'),
736
+ search: S('<circle cx="11" cy="11" r="6.5"/><path d="m20 20-4.2-4.2"/>'),
737
+ arrowUp: S('<path d="m6 15 6-6 6 6"/>'),
738
+ arrowDown: S('<path d="m6 9 6 6 6-6"/>'),
739
+ table: S('<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16"/>'),
740
+ pasteText: S('<path d="M9 4h6v3H9z"/><path d="M15 5h2a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2"/><path d="M9 12h6M12 12v6"/>'),
641
741
  // The bar (class wds-swatch-bar) shows the current color through --wds-swatch
642
- 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
- 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
- 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 },
742
+ textColor: S('<path d="m6 16 6-12 6 12"/><path d="M8.5 11h7"/><rect class="wds-swatch-bar" x="3" y="19" width="18" height="3" rx="1" stroke="none"/>'),
743
+ highlight: S('<path d="m14 4 5 5-7 7H7v-5z"/><path d="M7 16l-2 2"/><rect class="wds-swatch-bar" x="3" y="19" width="18" height="3" rx="1" stroke="none"/>'),
744
+ globe: S('<circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><path d="M12 3a14 14 0 0 1 0 18 14 14 0 0 1 0-18"/>')
745
+ }, ae = (t) => getComputedStyle(t).direction === "rtl";
746
+ let Se = null;
747
+ function tn() {
748
+ Se?.close();
749
+ }
750
+ function lt(t, e, n, r) {
751
+ tn();
752
+ const i = document.createElement("div");
753
+ i.className = `wds-menu ${n}`, e.append(i);
754
+ const s = () => {
755
+ const u = t.getBoundingClientRect();
756
+ i.style.maxHeight = "";
757
+ const m = i.offsetWidth, p = i.offsetHeight, b = ae(e) ? u.right - m : u.left;
758
+ i.style.left = `${Math.max(4, Math.min(b, window.innerWidth - m - 4))}px`;
759
+ const x = window.innerHeight - u.bottom - 8, T = u.top - 8;
760
+ p <= x || x >= T ? (i.style.top = `${u.bottom + 4}px`, p > x && (i.style.maxHeight = `${x}px`)) : (i.style.top = `${Math.max(4, u.top - Math.min(p, T) - 4)}px`, p > T && (i.style.maxHeight = `${T}px`));
761
+ }, o = (u) => {
762
+ if (u.target instanceof Node && i.contains(u.target)) return;
763
+ const m = t.getBoundingClientRect();
764
+ m.bottom < 0 || m.top > window.innerHeight || !t.isConnected ? d() : s();
765
+ };
766
+ t.setAttribute("aria-expanded", "true");
767
+ const c = (u) => {
768
+ !i.contains(u.target) && u.target !== t && !t.contains(u.target) && d();
769
+ }, a = (u) => {
770
+ u.key === "Escape" && (u.preventDefault(), u.stopPropagation(), d(!0));
771
+ };
772
+ let l = !1;
773
+ function d(u = !1) {
774
+ l || (l = !0, i.remove(), t.setAttribute("aria-expanded", "false"), document.removeEventListener("mousedown", c, !0), window.removeEventListener("scroll", o, !0), window.removeEventListener("resize", o), i.removeEventListener("keydown", a), Se?.close === d && (Se = null), u && t.focus());
775
+ }
776
+ return document.addEventListener("mousedown", c, !0), window.addEventListener("scroll", o, !0), window.addEventListener("resize", o), i.addEventListener("keydown", a), Se = { close: d }, { popup: i, place: s, close: d };
777
+ }
778
+ function Rr(t, e, n, r) {
779
+ const { popup: i, place: s, close: o } = lt(t, e, "wds-menu-list");
780
+ i.setAttribute("role", "menu"), i.setAttribute("aria-label", r);
781
+ for (const a of n) {
782
+ if (a === "|") {
783
+ const d = document.createElement("div");
784
+ d.className = "wds-menu-sep", d.setAttribute("role", "separator"), i.append(d);
785
+ continue;
786
+ }
787
+ const l = document.createElement("button");
788
+ l.type = "button", l.className = `wds-menu-item${a.danger ? " is-danger" : ""}`, l.setAttribute("role", "menuitem"), l.tabIndex = -1, l.innerHTML = a.icon ?? "", l.append(document.createTextNode(a.label)), a.enabled === !1 && (l.disabled = !0), l.addEventListener("mousedown", (d) => d.preventDefault()), l.addEventListener("click", () => {
789
+ o(), a.run();
790
+ }), i.append(l);
791
+ }
792
+ const c = () => [...i.querySelectorAll(".wds-menu-item:not(:disabled)")];
793
+ i.addEventListener("keydown", (a) => {
794
+ const l = c(), d = l.indexOf(document.activeElement);
795
+ let u = -1;
796
+ a.key === "ArrowDown" ? u = (d + 1) % l.length : a.key === "ArrowUp" ? u = (d - 1 + l.length) % l.length : a.key === "Home" ? u = 0 : a.key === "End" ? u = l.length - 1 : a.key === "Tab" && o(), u >= 0 && (a.preventDefault(), l[u]?.focus());
797
+ }), s(), c()[0]?.focus();
798
+ }
799
+ function $r(t, e, n, r, i) {
800
+ const { popup: c, place: a, close: l } = lt(t, e, "wds-table-picker");
801
+ c.setAttribute("role", "dialog"), c.setAttribute("aria-label", n);
802
+ const d = document.createElement("div");
803
+ d.className = "wds-picker-grid", d.style.gridTemplateColumns = "repeat(10, 1fr)", d.tabIndex = 0, d.setAttribute("role", "grid"), d.setAttribute("aria-label", n);
804
+ const u = document.createElement("div");
805
+ u.className = "wds-picker-label", u.setAttribute("aria-live", "polite");
806
+ const m = [];
807
+ let p = 3, b = 3;
808
+ const x = () => {
809
+ m.forEach((T, A) => T.classList.toggle("is-on", Math.floor(A / 10) < p && A % 10 < b)), u.textContent = r(p, b), d.setAttribute("aria-valuetext", u.textContent);
810
+ };
811
+ for (let T = 0; T < 8; T++)
812
+ for (let A = 0; A < 10; A++) {
813
+ const N = document.createElement("span");
814
+ N.className = "wds-picker-cell", N.addEventListener("mouseenter", () => {
815
+ p = T + 1, b = A + 1, x();
816
+ }), N.addEventListener("mousedown", (v) => v.preventDefault()), N.addEventListener("click", () => {
817
+ l(), i(T + 1, A + 1);
818
+ }), m.push(N), d.append(N);
819
+ }
820
+ d.addEventListener("keydown", (T) => {
821
+ const A = ae(d) ? -1 : 1, N = { ArrowRight: [0, A], ArrowLeft: [0, -A], ArrowDown: [1, 0], ArrowUp: [-1, 0] };
822
+ N[T.key] ? (T.preventDefault(), p = Math.min(8, Math.max(1, p + N[T.key][0])), b = Math.min(10, Math.max(1, b + N[T.key][1])), x()) : T.key === "Enter" || T.key === " " ? (T.preventDefault(), l(), i(p, b)) : T.key === "Tab" && l();
823
+ }), c.append(d, u), x(), a(), d.focus();
824
+ }
825
+ function Or(t, e, n) {
826
+ const { popup: r, place: i, close: s } = lt(t, e, "wds-color-picker");
827
+ r.setAttribute("role", "dialog"), r.setAttribute("aria-label", n.label);
828
+ const o = (l) => {
829
+ s(), n.onPick(l);
830
+ }, c = document.createElement("button");
831
+ c.type = "button", c.className = "wds-menu-item wds-color-remove", c.innerHTML = '<span class="wds-swatch is-none" aria-hidden="true"></span>', c.append(document.createTextNode(n.removeLabel)), c.addEventListener("mousedown", (l) => l.preventDefault()), c.addEventListener("click", () => o(null));
832
+ const a = document.createElement("div");
833
+ a.className = "wds-swatches", a.style.gridTemplateColumns = `repeat(${n.columns}, 1fr)`;
834
+ for (const l of n.swatches) {
835
+ const d = document.createElement("button");
836
+ d.type = "button", d.className = "wds-swatch", d.style.background = l.color, d.title = l.label, d.setAttribute("aria-label", l.label);
837
+ const u = l.color === n.current;
838
+ d.setAttribute("aria-pressed", String(u)), u && d.classList.add("is-current"), d.addEventListener("mousedown", (m) => m.preventDefault()), d.addEventListener("click", () => o(l.color)), a.append(d);
839
+ }
840
+ r.append(c, a), r.addEventListener("keydown", (l) => {
841
+ const d = [c, ...a.querySelectorAll(".wds-swatch")], u = d.indexOf(document.activeElement);
842
+ if (u < 0) return;
843
+ const m = n.columns;
844
+ let p = -1;
845
+ const b = ae(r) ? "ArrowLeft" : "ArrowRight", x = ae(r) ? "ArrowRight" : "ArrowLeft";
846
+ l.key === b ? p = Math.min(d.length - 1, u + 1) : l.key === x ? p = Math.max(0, u - 1) : l.key === "ArrowDown" ? p = u === 0 ? 1 : Math.min(d.length - 1, u + m) : l.key === "ArrowUp" ? p = u <= m ? 0 : u - m : l.key === "Tab" && s(), p >= 0 && (l.preventDefault(), d[p].focus());
847
+ }), i(), (a.querySelector(".is-current") ?? a.querySelector(".wds-swatch"))?.focus();
848
+ }
849
+ const O = (t) => (e) => e.exec(t), Be = (t) => ae(t.root) ? "right" : "left", xe = (t) => {
850
+ const e = `align${t[0].toUpperCase()}${t.slice(1)}`;
851
+ return {
852
+ type: "button",
853
+ label: e,
854
+ icon: L[e],
855
+ run: (n) => n.exec(It(t, Be(n))),
856
+ active: (n, r) => wr(n, Be(r)) === t,
857
+ enabled: (n, r) => It(t, Be(r))(n)
858
+ };
859
+ }, Hr = {
860
+ undo: { type: "button", label: "undo", icon: L.undo, shortcut: "Mod+Z", run: (t) => t.undo(), enabled: (t) => wn(t) > 0 },
861
+ redo: { type: "button", label: "redo", icon: L.redo, shortcut: "Mod+Y", run: (t) => t.redo(), enabled: (t) => bn(t) > 0 },
648
862
  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) },
863
+ bold: { type: "button", label: "bold", icon: L.bold, shortcut: "Mod+B", run: O(_("strong")), active: (t) => fe(t, f.marks.strong) },
864
+ italic: { type: "button", label: "italic", icon: L.italic, shortcut: "Mod+I", run: O(_("em")), active: (t) => fe(t, f.marks.em) },
865
+ underline: { type: "button", label: "underline", icon: L.underline, shortcut: "Mod+U", run: O(_("underline")), active: (t) => fe(t, f.marks.underline) },
866
+ strike: { type: "button", label: "strike", icon: L.strike, run: O(_("strike")), active: (t) => fe(t, f.marks.strike) },
867
+ textColor: { type: "button", label: "textColor", icon: L.textColor, popup: !0, run: (t, e) => t.openColorPicker("textColor", e), swatch: (t) => nt(t, "textColor") },
868
+ highlight: { type: "button", label: "highlight", icon: L.highlight, popup: !0, run: (t, e) => t.openColorPicker("highlight", e), swatch: (t) => nt(t, "highlight") },
869
+ code: { type: "button", label: "code", icon: L.code, run: O(_("code")), active: (t) => fe(t, f.marks.code) },
870
+ link: { type: "button", label: "link", icon: L.link, shortcut: "Mod+K", run: (t) => t.openLinkDialog(), active: (t) => !!et(t) },
871
+ image: { type: "button", label: "image", icon: L.image, run: (t) => t.openImageDialog(), active: (t) => !!tt(t) },
658
872
  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) },
873
+ video: { type: "button", label: "video", icon: L.video, run: (t) => t.openVideoDialog(), active: (t) => !!en(t) },
874
+ find: { type: "button", label: "findReplace", icon: L.search, shortcut: "Mod+F", run: (t) => t.openFind(), active: (t, e) => e.isFindOpen() },
875
+ table: { type: "button", label: "table", icon: L.table, popup: !0, run: (t, e) => t.openTableMenu(e), active: (t) => we(t) },
876
+ blockquote: { type: "button", label: "blockquote", icon: L.blockquote, run: O(br()), active: (t) => Zt(t, f.nodes.blockquote) },
877
+ bulletList: { type: "button", label: "bulletList", icon: L.bulletList, run: O(Ct(f.nodes.bullet_list)), active: (t) => Tt(t) === f.nodes.bullet_list },
878
+ orderedList: { type: "button", label: "orderedList", icon: L.orderedList, run: O(Ct(f.nodes.ordered_list)), active: (t) => Tt(t) === f.nodes.ordered_list },
879
+ outdent: { type: "button", label: "outdent", icon: L.outdent, run: O(Ze), enabled: (t) => Ze(t) },
880
+ indent: { type: "button", label: "indent", icon: L.indent, run: O(Qe), enabled: (t) => Qe(t) },
881
+ alignLeft: xe("left"),
882
+ alignCenter: xe("center"),
883
+ alignRight: xe("right"),
884
+ alignJustify: xe("justify"),
885
+ hr: { type: "button", label: "hr", icon: L.hr, run: O(yr) },
886
+ clear: { type: "button", label: "clear", icon: L.clear, run: O(vr) },
671
887
  pasteText: { type: "button", label: "pasteText", icon: L.pasteText, run: (t) => t.togglePlainPaste(), active: (t, e) => e.isPlainPaste() },
672
888
  source: { type: "button", label: "source", icon: L.source, run: (t) => t.toggleSource(), active: (t, e) => e.isSourceMode(), inSource: !0 },
673
889
  fullscreen: { type: "button", label: "fullscreen", icon: L.fullscreen, run: (t) => t.toggleFullscreen(), active: (t, e) => e.isFullscreen(), inSource: !0 }
674
- }, ar = [
890
+ }, Pr = [
675
891
  "undo",
676
892
  "redo",
677
893
  "|",
@@ -688,6 +904,7 @@ const E = (t) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" st
688
904
  "link",
689
905
  "image",
690
906
  "file",
907
+ "video",
691
908
  "table",
692
909
  "blockquote",
693
910
  "bulletList",
@@ -706,131 +923,131 @@ const E = (t) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" st
706
923
  "|",
707
924
  "source",
708
925
  "fullscreen"
709
- ], sr = [
926
+ ], Br = [
710
927
  ["paragraph", "paragraph"],
711
928
  ["heading1", "heading1"],
712
929
  ["heading2", "heading2"],
713
930
  ["heading3", "heading3"],
714
931
  ["heading4", "heading4"],
715
932
  ["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) {
933
+ ], zr = typeof navigator < "u" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent), Fr = (t) => t.replace("Mod", zr ? "⌘" : "Ctrl");
934
+ function Ur(t, e, n) {
718
935
  const r = document.createElement("div");
719
936
  r.className = "wds-toolbar", r.setAttribute("role", "toolbar"), r.setAttribute("aria-label", n.toolbarLabel);
720
- const o = [];
937
+ const i = [];
721
938
  let s = document.createElement("div");
722
939
  s.className = "wds-group", r.append(s);
723
- for (const d of e) {
724
- if (d === "|") {
940
+ for (const c of e) {
941
+ if (c === "|") {
725
942
  s.childElementCount && (s = document.createElement("div"), s.className = "wds-group", r.append(s));
726
943
  continue;
727
944
  }
728
- const i = ir[d];
729
- if (!i) {
730
- console.warn(`[WDS Editor] Unknown toolbar item "${d}".`);
945
+ const a = Hr[c];
946
+ if (!a) {
947
+ console.warn(`[WDS Editor] Unknown toolbar item "${c}".`);
731
948
  continue;
732
949
  }
733
- if (i.type === "blocks") {
950
+ if (a.type === "blocks") {
734
951
  const u = document.createElement("select");
735
952
  u.className = "wds-select", u.setAttribute("aria-label", n.blockType), u.title = n.blockType;
736
- for (const [g, v] of sr) {
737
- const D = document.createElement("option");
738
- D.value = g, D.textContent = n[v], u.append(D);
953
+ for (const [p, b] of Br) {
954
+ const x = document.createElement("option");
955
+ x.value = p, x.textContent = n[b], u.append(x);
739
956
  }
740
957
  const m = document.createElement("option");
741
958
  m.value = "", m.textContent = "—", m.hidden = !0, u.append(m), u.addEventListener("change", () => {
742
- u.value && t.exec(Wn(u.value)), t.focus();
743
- }), s.append(u), o.push((g) => {
744
- u.value = _n(g) ?? "", u.disabled = t.isSourceMode() || t.isReadOnly();
959
+ u.value && t.exec(gr(u.value)), t.focus();
960
+ }), s.append(u), i.push((p) => {
961
+ u.value = pr(p) ?? "", u.disabled = t.isSourceMode() || t.isReadOnly();
745
962
  });
746
963
  continue;
747
964
  }
748
- if (i.available && !i.available(t)) continue;
749
- const a = document.createElement("button");
750
- 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", () => {
753
- a.disabled || i.run(t, a);
754
- }), s.append(a), o.push((u) => {
755
- const m = t.isSourceMode() && !i.inSource || t.isReadOnly() && !i.inSource;
756
- if (a.disabled = m || (i.enabled ? !i.enabled(u, t) : !1), i.swatch) {
757
- const g = m ? null : i.swatch(u);
758
- g ? a.style.setProperty("--wds-swatch", g) : a.style.removeProperty("--wds-swatch");
965
+ if (a.available && !a.available(t)) continue;
966
+ const l = document.createElement("button");
967
+ l.type = "button", l.className = "wds-button-tool", l.innerHTML = a.icon;
968
+ const d = n[a.label];
969
+ l.setAttribute("aria-label", d), l.title = a.shortcut ? `${d} (${Fr(a.shortcut)})` : d, l.dataset.item = c, a.popup && (l.setAttribute("aria-haspopup", "true"), l.setAttribute("aria-expanded", "false")), l.addEventListener("mousedown", (u) => u.preventDefault()), l.addEventListener("click", () => {
970
+ l.disabled || a.run(t, l);
971
+ }), s.append(l), i.push((u) => {
972
+ const m = t.isSourceMode() && !a.inSource || t.isReadOnly() && !a.inSource;
973
+ if (l.disabled = m || (a.enabled ? !a.enabled(u, t) : !1), a.swatch) {
974
+ const p = m ? null : a.swatch(u);
975
+ p ? l.style.setProperty("--wds-swatch", p) : l.style.removeProperty("--wds-swatch");
759
976
  }
760
- if (i.active) {
761
- const g = !m && i.active(u, t);
762
- a.classList.toggle("is-active", g), a.setAttribute("aria-pressed", String(g));
977
+ if (a.active) {
978
+ const p = !m && a.active(u, t);
979
+ l.classList.toggle("is-active", p), l.setAttribute("aria-pressed", String(p));
763
980
  }
764
981
  });
765
982
  }
766
- return r.addEventListener("keydown", (d) => {
767
- if (d.key !== "ArrowRight" && d.key !== "ArrowLeft" && d.key !== "Home" && d.key !== "End" || d.target.tagName === "SELECT" && (d.key === "Home" || d.key === "End")) return;
768
- const i = [...r.querySelectorAll("button:not([disabled]), select:not([disabled])")], a = i.indexOf(document.activeElement);
769
- if (a < 0) return;
770
- 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();
773
- }), { element: r, update: (d) => {
774
- o.forEach((a) => a(d));
775
- const i = [...r.querySelectorAll("button, select")];
776
- if (!i.some((a) => a.tabIndex === 0 && !a.disabled)) {
777
- i.forEach((c) => c.tabIndex = -1);
778
- const a = i.find((c) => !c.disabled);
779
- a && (a.tabIndex = 0);
983
+ return r.addEventListener("keydown", (c) => {
984
+ if (c.key !== "ArrowRight" && c.key !== "ArrowLeft" && c.key !== "Home" && c.key !== "End" || c.target.tagName === "SELECT" && (c.key === "Home" || c.key === "End")) return;
985
+ const a = [...r.querySelectorAll("button:not([disabled]), select:not([disabled])")], l = a.indexOf(document.activeElement);
986
+ if (l < 0) return;
987
+ c.preventDefault();
988
+ const d = c.key === "Home" ? 0 : c.key === "End" ? a.length - 1 : (l + (c.key === "ArrowRight" !== ae(r) ? 1 : -1) + a.length) % a.length;
989
+ a.forEach((u) => u.tabIndex = -1), a[d].tabIndex = 0, a[d].focus();
990
+ }), { element: r, update: (c) => {
991
+ i.forEach((l) => l(c));
992
+ const a = [...r.querySelectorAll("button, select")];
993
+ if (!a.some((l) => l.tabIndex === 0 && !l.disabled)) {
994
+ a.forEach((d) => d.tabIndex = -1);
995
+ const l = a.find((d) => !d.disabled);
996
+ l && (l.tabIndex = 0);
780
997
  }
781
998
  } };
782
999
  }
783
- function zt(t, e, n, r) {
784
- const o = document.createElement("span");
785
- o.className = "wds-image";
1000
+ function nn(t, e, n, r) {
1001
+ const i = document.createElement("span");
1002
+ i.className = "wds-image";
786
1003
  const s = document.createElement("img");
787
1004
  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);
790
- const d = () => {
791
- const c = e();
792
- c !== void 0 && t.dispatch(t.state.tr.setSelection(he.create(t.state.doc, c)));
1005
+ const o = document.createElement("span");
1006
+ o.className = "wds-resize-handle", o.title = r.resizeLabel, o.setAttribute("aria-hidden", "true"), i.append(s, o);
1007
+ const c = () => {
1008
+ const d = e();
1009
+ d !== void 0 && t.dispatch(t.state.tr.setSelection(Z.create(t.state.doc, d)));
793
1010
  };
794
- let i = !1;
795
- return l.addEventListener("pointerdown", (c) => {
1011
+ let a = !1;
1012
+ return o.addEventListener("pointerdown", (d) => {
796
1013
  if (!t.editable) return;
797
- c.preventDefault(), c.stopPropagation(), d(), i = !0;
1014
+ d.preventDefault(), d.stopPropagation(), c(), a = !0;
798
1015
  try {
799
- l.setPointerCapture(c.pointerId);
1016
+ o.setPointerCapture(d.pointerId);
800
1017
  } catch {
801
1018
  }
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)));
1019
+ const u = d.clientX, m = s.getBoundingClientRect().width, p = Math.max(40, t.dom.clientWidth - 8);
1020
+ let b = m;
1021
+ const x = (A) => {
1022
+ b = Math.round(Math.min(p, Math.max(40, m + A.clientX - u))), s.style.width = `${b}px`, s.style.height = "auto", i.dataset.size = `${b}px`;
1023
+ }, T = () => {
1024
+ a = !1, window.removeEventListener("pointermove", x), window.removeEventListener("pointerup", T), window.removeEventListener("pointercancel", T), delete i.dataset.size, s.style.width = "", s.style.height = "";
1025
+ const A = e();
1026
+ if (A === void 0 || Math.abs(b - m) < 2) return;
1027
+ const N = n(), v = t.state.tr.setNodeMarkup(A, void 0, { ...N.attrs, width: b, height: null });
1028
+ t.dispatch(v.setSelection(Z.create(v.doc, A)));
812
1029
  };
813
- window.addEventListener("pointermove", D), window.addEventListener("pointerup", C), window.addEventListener("pointercancel", C);
814
- }), o.addEventListener("dblclick", (c) => {
1030
+ window.addEventListener("pointermove", x), window.addEventListener("pointerup", T), window.addEventListener("pointercancel", T);
1031
+ }), i.addEventListener("dblclick", (d) => {
815
1032
  if (!t.editable) return;
816
- c.preventDefault(), d();
1033
+ d.preventDefault(), c();
817
1034
  const u = e();
818
1035
  u !== void 0 && r.onEdit(u);
819
- }), { box: o, img: s, handle: l, select: d, render: (c) => {
820
- const u = Be(c.attrs, !1);
1036
+ }), { box: i, img: s, handle: o, select: c, render: (d) => {
1037
+ const u = Ye(d.attrs, !1);
821
1038
  for (const m of ["src", "alt", "title", "width", "height"])
822
1039
  u[m] !== void 0 ? s.setAttribute(m, u[m]) : s.removeAttribute(m);
823
- }, isResizing: () => i };
1040
+ }, isResizing: () => a };
824
1041
  }
825
- const Bt = (t, e) => {
1042
+ const rn = (t, e) => {
826
1043
  t.classList.remove("wds-align-left", "wds-align-center", "wds-align-right"), e && t.classList.add(`wds-align-${e}`);
827
1044
  };
828
- class ur {
829
- constructor(e, n, r, o) {
830
- this.node = e, this.parts = zt(n, r, () => this.node, o), this.dom = this.parts.box, this.render();
1045
+ class Wr {
1046
+ constructor(e, n, r, i) {
1047
+ this.node = e, this.parts = nn(n, r, () => this.node, i), this.dom = this.parts.box, this.render();
831
1048
  }
832
1049
  render() {
833
- this.parts.render(this.node), Bt(this.dom, this.node.attrs.align);
1050
+ this.parts.render(this.node), rn(this.dom, this.node.attrs.align);
834
1051
  }
835
1052
  update(e) {
836
1053
  return e.type !== this.node.type ? !1 : (this.node = e, this.render(), !0);
@@ -842,14 +1059,14 @@ class ur {
842
1059
  return !0;
843
1060
  }
844
1061
  }
845
- class hr {
846
- 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) => {
1062
+ class _r {
1063
+ constructor(e, n, r, i) {
1064
+ this.node = e, this.dom = document.createElement("figure"), this.dom.className = "wds-figure", this.parts = nn(n, r, () => this.node, i), this.parts.box.contentEditable = "false", this.parts.box.addEventListener("mousedown", (s) => {
848
1065
  s.target === this.parts.handle || s.detail > 1 || (s.preventDefault(), this.parts.select(), n.focus());
849
- }), this.contentDOM = document.createElement("figcaption"), this.contentDOM.dataset.placeholder = o.captionPlaceholder, this.dom.append(this.parts.box, this.contentDOM), this.render();
1066
+ }), this.contentDOM = document.createElement("figcaption"), this.contentDOM.dataset.placeholder = i.captionPlaceholder, this.dom.append(this.parts.box, this.contentDOM), this.render();
850
1067
  }
851
1068
  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);
1069
+ this.parts.render(this.node), rn(this.dom, this.node.attrs.align), this.dom.classList.toggle("is-empty", this.node.content.size === 0);
853
1070
  }
854
1071
  update(e) {
855
1072
  return e.type !== this.node.type ? !1 : (this.node = e, this.render(), !0);
@@ -861,109 +1078,7 @@ class hr {
861
1078
  return !this.contentDOM.contains(e.target);
862
1079
  }
863
1080
  }
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 = {
1081
+ const Ee = {
967
1082
  undo: "Undo",
968
1083
  redo: "Redo",
969
1084
  blockType: "Text style",
@@ -1049,6 +1164,8 @@ const ve = {
1049
1164
  fmListFailed: "The file list could not be loaded. {error}",
1050
1165
  fmDeleteFailed: "The file could not be deleted. {error}",
1051
1166
  fmUploading: "Uploading {name}",
1167
+ fmNetworkError: "Check your connection and try again.",
1168
+ fmInvalidResponse: "The server sent an unexpected response.",
1052
1169
  table: "Table",
1053
1170
  tableInsert: "Insert table",
1054
1171
  tableSize: "{rows} × {cols} table",
@@ -1081,8 +1198,28 @@ const ve = {
1081
1198
  colorPurple: "Purple",
1082
1199
  colorPink: "Pink",
1083
1200
  colorSlate: "Slate",
1084
- colorGray: "Gray"
1085
- }, gr = {
1201
+ colorGray: "Gray",
1202
+ video: "Video",
1203
+ videoEdit: "Edit video",
1204
+ videoUrl: "YouTube or Vimeo address",
1205
+ videoHint: "Paste the link of the video page or its embed code.",
1206
+ videoTitle: "Title (read by screen readers)",
1207
+ videoInvalid: "Enter a YouTube or Vimeo video address.",
1208
+ findReplace: "Find and replace",
1209
+ find: "Find",
1210
+ replaceWith: "Replace with",
1211
+ findNext: "Next match",
1212
+ findPrevious: "Previous match",
1213
+ replace: "Replace",
1214
+ replaceAll: "Replace all",
1215
+ matchCase: "Match case",
1216
+ matchCount: "{current} of {total}",
1217
+ noMatches: "No results",
1218
+ replacedCount: "{count} replaced",
1219
+ draftFound: "An unsaved draft from {time} was found.",
1220
+ draftRestore: "Restore draft",
1221
+ draftDiscard: "Discard"
1222
+ }, Vr = {
1086
1223
  undo: "Geri al",
1087
1224
  redo: "Yinele",
1088
1225
  blockType: "Metin stili",
@@ -1168,6 +1305,8 @@ const ve = {
1168
1305
  fmListFailed: "Dosya listesi yüklenemedi. {error}",
1169
1306
  fmDeleteFailed: "Dosya silinemedi. {error}",
1170
1307
  fmUploading: "{name} yükleniyor",
1308
+ fmNetworkError: "Bağlantınızı kontrol edip tekrar deneyin.",
1309
+ fmInvalidResponse: "Sunucu beklenmeyen bir yanıt gönderdi.",
1171
1310
  table: "Tablo",
1172
1311
  tableInsert: "Tablo ekle",
1173
1312
  tableSize: "{rows} × {cols} tablo",
@@ -1200,123 +1339,157 @@ const ve = {
1200
1339
  colorPurple: "Mor",
1201
1340
  colorPink: "Pembe",
1202
1341
  colorSlate: "Arduvaz",
1203
- colorGray: "Gri"
1204
- }, ke = { en: ve, tr: gr };
1205
- function br(t, e) {
1206
- ke[t.toLowerCase()] = { ...ve, ...ke[t.toLowerCase()], ...e };
1207
- }
1208
- function wr(t) {
1209
- if (t && typeof t == "object") return { ...ve, ...t };
1342
+ colorGray: "Gri",
1343
+ video: "Video",
1344
+ videoEdit: "Videoyu düzenle",
1345
+ videoUrl: "YouTube veya Vimeo adresi",
1346
+ videoHint: "Video sayfasının bağlantısını ya da yerleştirme kodunu yapıştırın.",
1347
+ videoTitle: "Başlık (ekran okuyucular okur)",
1348
+ videoInvalid: "Bir YouTube veya Vimeo video adresi girin.",
1349
+ findReplace: "Bul ve değiştir",
1350
+ find: "Bul",
1351
+ replaceWith: "Şununla değiştir",
1352
+ findNext: "Sonraki eşleşme",
1353
+ findPrevious: "Önceki eşleşme",
1354
+ replace: "Değiştir",
1355
+ replaceAll: "Tümünü değiştir",
1356
+ matchCase: "Büyük/küçük harf duyarlı",
1357
+ matchCount: "{current} / {total}",
1358
+ noMatches: "Sonuç yok",
1359
+ replacedCount: "{count} yer değiştirildi",
1360
+ draftFound: "{time} tarihli kaydedilmemiş bir taslak bulundu.",
1361
+ draftRestore: "Taslağı geri yükle",
1362
+ draftDiscard: "Sil"
1363
+ }, ge = { en: Ee, tr: Vr };
1364
+ function sn(t, e) {
1365
+ ge[t.toLowerCase()] = { ...Ee, ...ge[t.toLowerCase()], ...e };
1366
+ }
1367
+ function Nt(t) {
1368
+ return globalThis.WDSEditorLang?.[t];
1369
+ }
1370
+ function Rt(t) {
1371
+ return !ge[t] && Nt(t) && sn(t, Nt(t)), ge[t];
1372
+ }
1373
+ function on(t) {
1210
1374
  const e = (t || (typeof navigator < "u" ? navigator.language : "en") || "en").toLowerCase();
1211
- return ke[e] ?? ke[e.split("-")[0]] ?? ve;
1375
+ if (Rt(e)) return e;
1376
+ const n = e.split("-")[0];
1377
+ return Rt(n) ? n : "en";
1212
1378
  }
1213
- function V(t, e) {
1214
- return t.replace(/\{(\w+)\}/g, (n, r) => e[r] ?? n);
1379
+ function qr(t) {
1380
+ return t && typeof t == "object" ? { ...Ee, ...t } : ge[on(t)] ?? Ee;
1215
1381
  }
1216
- let yr = 0;
1217
- function wt(t, e) {
1218
- const n = `wds-dlg-${++yr}`, r = document.createElement("dialog");
1382
+ const Gr = /* @__PURE__ */ new Set(["ar", "he", "fa", "ur", "ps", "yi", "dv", "ckb"]);
1383
+ function jr(t) {
1384
+ return Gr.has(t.toLowerCase().split("-")[0]);
1385
+ }
1386
+ function z(t, e) {
1387
+ return t.replace(/\{(\w+)\}/g, (n, r) => r in e ? String(e[r]) : n);
1388
+ }
1389
+ let Kr = 0;
1390
+ function ze(t, e) {
1391
+ const n = `wds-dlg-${++Kr}`, r = document.createElement("dialog");
1219
1392
  r.className = "wds-dialog", r.setAttribute("aria-labelledby", `${n}-title`);
1220
- const o = document.createElement("form");
1221
- o.method = "dialog", o.noValidate = !0;
1393
+ const i = document.createElement("form");
1394
+ i.method = "dialog", i.noValidate = !0;
1222
1395
  const s = document.createElement("div");
1223
1396
  s.className = "wds-dialog-header";
1224
- const l = document.createElement("h2");
1225
- l.id = `${n}-title`, l.textContent = e.title;
1226
- 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);
1228
- const i = document.createElement("div");
1229
- i.className = "wds-dialog-body";
1230
- const a = /* @__PURE__ */ new Map();
1231
- for (const y of e.fields) {
1232
- 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 ?? []) {
1236
- const G = document.createElement("option");
1237
- G.value = $.value, G.textContent = $.label, A.append(G);
1397
+ const o = document.createElement("h2");
1398
+ o.id = `${n}-title`, o.textContent = e.title;
1399
+ const c = document.createElement("button");
1400
+ c.type = "button", c.className = "wds-icon-button", c.setAttribute("aria-label", e.closeLabel), c.innerHTML = L.close, s.append(o, c);
1401
+ const a = document.createElement("div");
1402
+ a.className = "wds-dialog-body";
1403
+ const l = /* @__PURE__ */ new Map();
1404
+ for (const v of e.fields) {
1405
+ if (v.type === "select") {
1406
+ const I = document.createElement("select");
1407
+ I.id = `${n}-${v.name}`, I.name = v.name, I.className = "wds-input";
1408
+ for (const $ of v.options ?? []) {
1409
+ const j = document.createElement("option");
1410
+ j.value = $.value, j.textContent = $.label, I.append(j);
1238
1411
  }
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);
1412
+ I.value = typeof v.value == "string" ? v.value : "";
1413
+ const R = document.createElement("label");
1414
+ R.className = "wds-label", R.htmlFor = I.id, R.textContent = v.label, a.append(R, I), l.set(v.name, I);
1242
1415
  continue;
1243
1416
  }
1244
- const x = document.createElement("input");
1245
- if (x.id = `${n}-${y.name}`, x.name = y.name, y.type === "checkbox") {
1246
- 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);
1417
+ const E = document.createElement("input");
1418
+ if (E.id = `${n}-${v.name}`, E.name = v.name, v.type === "checkbox") {
1419
+ E.type = "checkbox", E.checked = !!v.value;
1420
+ const I = document.createElement("label");
1421
+ I.className = "wds-check", I.htmlFor = E.id, I.append(E, document.createTextNode(v.label)), a.append(I);
1249
1422
  } else {
1250
- 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);
1423
+ E.type = "text", v.type === "url" && (E.inputMode = "url"), v.type === "number" && (E.inputMode = "numeric"), E.className = "wds-input", E.value = typeof v.value == "string" ? v.value : "", E.autocomplete = "off", E.spellcheck = !1, v.placeholder && (E.placeholder = v.placeholder);
1424
+ const I = document.createElement("label");
1425
+ if (I.className = "wds-label", I.htmlFor = E.id, I.textContent = v.label, a.append(I, E), v.hint) {
1426
+ const R = document.createElement("p");
1427
+ R.className = "wds-hint", R.id = `${E.id}-hint`, R.textContent = v.hint, E.setAttribute("aria-describedby", R.id), a.append(R);
1255
1428
  }
1256
1429
  }
1257
- a.set(y.name, x);
1430
+ l.set(v.name, E);
1258
1431
  }
1259
- const c = document.createElement("p");
1260
- c.className = "wds-dialog-error", c.setAttribute("role", "alert"), c.hidden = !0, i.append(c);
1432
+ const d = document.createElement("p");
1433
+ d.className = "wds-dialog-error", d.setAttribute("role", "alert"), d.hidden = !0, a.append(d);
1261
1434
  const u = document.createElement("div");
1262
1435
  if (u.className = "wds-dialog-footer", e.extraAction) {
1263
- const y = document.createElement("button");
1264
- y.type = "button", y.className = "wds-button wds-button-danger", y.textContent = e.extraAction.label, y.addEventListener("click", () => {
1265
- e.extraAction.onClick(), T();
1266
- }), u.append(y);
1436
+ const v = document.createElement("button");
1437
+ v.type = "button", v.className = "wds-button wds-button-danger", v.textContent = e.extraAction.label, v.addEventListener("click", () => {
1438
+ e.extraAction.onClick(), A();
1439
+ }), u.append(v);
1267
1440
  }
1268
1441
  const m = document.createElement("span");
1269
1442
  m.className = "wds-spacer";
1270
- const g = document.createElement("button");
1271
- 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);
1274
- const D = () => {
1275
- const y = {};
1276
- return a.forEach((x, A) => y[A] = x instanceof HTMLInputElement && x.type === "checkbox" ? x.checked : x.value), y;
1443
+ const p = document.createElement("button");
1444
+ p.type = "button", p.className = "wds-button", p.textContent = e.cancelLabel;
1445
+ const b = document.createElement("button");
1446
+ b.type = "submit", b.className = "wds-button wds-button-primary", b.textContent = e.submitLabel, u.append(m, p, b), i.append(s, a, u), r.append(i), t.append(r);
1447
+ const x = () => {
1448
+ const v = {};
1449
+ return l.forEach((E, I) => v[I] = E instanceof HTMLInputElement && E.type === "checkbox" ? E.checked : E.value), v;
1277
1450
  };
1278
- let C = !1;
1279
- function T() {
1280
- C || (C = !0, r.open && r.close(), r.remove(), e.onClose?.());
1281
- }
1282
- o.addEventListener("submit", (y) => {
1283
- 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();
1451
+ let T = !1;
1452
+ function A() {
1453
+ T || (T = !0, r.open && r.close(), r.remove(), e.onClose?.());
1454
+ }
1455
+ i.addEventListener("submit", (v) => {
1456
+ v.preventDefault();
1457
+ const E = x(), I = e.validate?.(E) ?? null;
1458
+ if (I) {
1459
+ d.textContent = I, d.hidden = !1, [...l.values()][0]?.focus();
1287
1460
  return;
1288
1461
  }
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();
1462
+ e.onSubmit(E), A();
1463
+ }), p.addEventListener("click", A), c.addEventListener("click", A), r.addEventListener("close", A), r.addEventListener("click", (v) => {
1464
+ v.target === r && A();
1292
1465
  }), r.showModal();
1293
- const O = [...a.values()].find((y) => y instanceof HTMLInputElement && y.type !== "checkbox");
1294
- return O?.focus(), O?.select(), T;
1466
+ const N = [...l.values()].find((v) => v instanceof HTMLInputElement && v.type !== "checkbox");
1467
+ return N?.focus(), N?.select(), A;
1295
1468
  }
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) {
1469
+ const K = (t) => typeof t == "string" && t.trim() ? t : void 0, Fe = (t) => typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : void 0;
1470
+ function an(t) {
1298
1471
  if (!t || typeof t != "object") return null;
1299
1472
  const e = t, n = q(K(e.url)), r = K(e.name);
1300
1473
  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;
1474
+ const i = { url: n, name: r }, s = Fe(e.size), o = Fe(e.width), c = Fe(e.height);
1475
+ s !== void 0 && (i.size = s), o !== void 0 && (i.width = o), c !== void 0 && (i.height = c), K(e.type) && (i.type = e.type.toLowerCase());
1476
+ const a = q(K(e.thumb));
1477
+ return a && (i.thumb = a), K(e.modified) && !Number.isNaN(Date.parse(e.modified)) && (i.modified = e.modified), i;
1305
1478
  }
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) }));
1479
+ function Yr(t, e = "/") {
1480
+ const n = Array.isArray(t) ? { files: t } : t && typeof t == "object" ? t : {}, r = (Array.isArray(n.files) ? n.files : []).map(an).filter((s) => !!s), i = (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: rt(s.path) }));
1308
1481
  return {
1309
- path: je(K(n.path) ?? e),
1310
- folders: o,
1482
+ path: rt(K(n.path) ?? e),
1483
+ folders: i,
1311
1484
  files: r,
1312
1485
  hasMore: n.hasMore === !0,
1313
1486
  serverSearch: typeof n.q == "string"
1314
1487
  };
1315
1488
  }
1316
- function je(t) {
1489
+ function rt(t) {
1317
1490
  return "/" + t.split("/").filter((n) => n && n !== "." && n !== "..").join("/");
1318
1491
  }
1319
- const kr = /\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i, Mr = {
1492
+ const Jr = /\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i, Xr = {
1320
1493
  jpg: "image/jpeg",
1321
1494
  jpeg: "image/jpeg",
1322
1495
  png: "image/png",
@@ -1336,23 +1509,23 @@ const kr = /\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i, Mr = {
1336
1509
  xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1337
1510
  mp4: "video/mp4",
1338
1511
  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)] || "";
1512
+ }, ln = (t) => (/\.([a-z0-9]+)$/i.exec(t)?.[1] ?? "").toLowerCase();
1513
+ function cn(t) {
1514
+ return t.type || Xr[ln(t.name)] || "";
1342
1515
  }
1343
- function ue(t) {
1344
- const e = _t(t);
1345
- return e ? e.startsWith("image/") : kr.test(t.url ?? t.name);
1516
+ function pe(t) {
1517
+ const e = cn(t);
1518
+ return e ? e.startsWith("image/") : Jr.test(t.url ?? t.name);
1346
1519
  }
1347
- function yt(t, e) {
1520
+ function $t(t, e) {
1348
1521
  if (!e || !e.trim()) return !0;
1349
- const n = _t(t), r = "." + Pt(t.name);
1350
- return e.split(",").some((o) => {
1351
- const s = o.trim().toLowerCase();
1522
+ const n = cn(t), r = "." + ln(t.name);
1523
+ return e.split(",").some((i) => {
1524
+ const s = i.trim().toLowerCase();
1352
1525
  return s ? s.startsWith(".") ? r === s : s.endsWith("/*") ? n.startsWith(s.slice(0, -1)) : n === s : !1;
1353
1526
  });
1354
1527
  }
1355
- function vt(t) {
1528
+ function Ot(t) {
1356
1529
  if (t === void 0) return "";
1357
1530
  if (t < 1024) return `${t} B`;
1358
1531
  const e = ["KB", "MB", "GB"];
@@ -1361,9 +1534,12 @@ function vt(t) {
1361
1534
  n /= 1024, r++;
1362
1535
  return `${n < 10 ? n.toFixed(1) : Math.round(n)} ${e[r]}`;
1363
1536
  }
1364
- class P extends Error {
1537
+ class H extends Error {
1538
+ constructor(e, n) {
1539
+ super(e), this.code = n;
1540
+ }
1365
1541
  }
1366
- async function kt(t) {
1542
+ async function Ht(t) {
1367
1543
  try {
1368
1544
  const e = await t.clone().json();
1369
1545
  if (e && typeof e.error == "string") return e.error;
@@ -1371,12 +1547,12 @@ async function kt(t) {
1371
1547
  }
1372
1548
  return `HTTP ${t.status}`;
1373
1549
  }
1374
- function Lr(t, e) {
1550
+ function Qr(t, e) {
1375
1551
  const n = new URL(t, document.baseURI);
1376
- for (const [r, o] of Object.entries(e)) o && n.searchParams.set(r, o);
1552
+ for (const [r, i] of Object.entries(e)) i && n.searchParams.set(r, i);
1377
1553
  return n.href;
1378
1554
  }
1379
- class xr {
1555
+ class Zr {
1380
1556
  constructor(e) {
1381
1557
  this.options = e;
1382
1558
  }
@@ -1393,428 +1569,737 @@ class xr {
1393
1569
  headers: { Accept: "application/json", ...this.options.headers, ...e.headers }
1394
1570
  };
1395
1571
  }
1396
- 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;
1572
+ async list(e, n, r, i) {
1573
+ const s = Qr(this.options.listUrl, { path: e, q: n, page: r > 1 ? String(r) : "" });
1574
+ let o;
1399
1575
  try {
1400
- l = await fetch(s, { ...this.init(), signal: o });
1401
- } catch (i) {
1402
- throw i.name === "AbortError" ? i : new P(i.message || "Network error");
1576
+ o = await fetch(s, { ...this.init(), signal: i });
1577
+ } catch (a) {
1578
+ throw a.name === "AbortError" ? a : new H(a.message || "Network error", "network");
1403
1579
  }
1404
- if (!l.ok) throw new P(await kt(l));
1405
- let d;
1580
+ if (!o.ok) throw new H(await Ht(o));
1581
+ let c;
1406
1582
  try {
1407
- d = await l.json();
1583
+ c = await o.json();
1408
1584
  } catch {
1409
- throw new P("Invalid JSON");
1585
+ throw new H("Invalid JSON", "response");
1410
1586
  }
1411
- return vr(d, e);
1587
+ return Yr(c, e);
1412
1588
  }
1413
1589
  /** Multipart upload with progress (XMLHttpRequest, because fetch has no upload progress). */
1414
1590
  upload(e, n, r) {
1415
- const { uploadUrl: o, headers: s = {}, withCredentials: l } = this.options;
1416
- return o ? new Promise((d, i) => {
1417
- const a = new XMLHttpRequest();
1418
- a.open("POST", new URL(o, document.baseURI).href), a.withCredentials = !!l, a.setRequestHeader("Accept", "application/json");
1419
- 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 = () => {
1591
+ const { uploadUrl: i, headers: s = {}, withCredentials: o } = this.options;
1592
+ return i ? new Promise((c, a) => {
1593
+ const l = new XMLHttpRequest();
1594
+ l.open("POST", new URL(i, document.baseURI).href), l.withCredentials = !!o, l.setRequestHeader("Accept", "application/json");
1595
+ for (const [u, m] of Object.entries(s)) l.setRequestHeader(u, m);
1596
+ l.upload.onprogress = (u) => u.lengthComputable && r?.(u.loaded / u.total), l.onerror = () => a(new H("Network error", "network")), l.onload = () => {
1421
1597
  let u = null;
1422
1598
  try {
1423
- u = JSON.parse(a.responseText);
1599
+ u = JSON.parse(l.responseText);
1424
1600
  } catch {
1425
1601
  }
1426
- if (a.status < 200 || a.status >= 300) {
1427
- i(new P(typeof u?.error == "string" ? u.error : `HTTP ${a.status}`));
1602
+ if (l.status < 200 || l.status >= 300) {
1603
+ a(new H(typeof u?.error == "string" ? u.error : `HTTP ${l.status}`));
1428
1604
  return;
1429
1605
  }
1430
- const m = Ut(u?.file);
1431
- m ? d(m) : i(new P("Invalid upload response"));
1606
+ const m = an(u?.file);
1607
+ m ? c(m) : a(new H("Invalid upload response", "response"));
1432
1608
  };
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"));
1609
+ const d = new FormData();
1610
+ d.append("file", e, e.name), d.append("path", n), l.send(d);
1611
+ }) : Promise.reject(new H("Upload is not configured"));
1436
1612
  }
1437
1613
  async remove(e) {
1438
1614
  const { deleteUrl: n } = this.options;
1439
- if (!n) throw new P("Delete is not configured");
1615
+ if (!n) throw new H("Delete is not configured");
1440
1616
  let r;
1441
1617
  try {
1442
1618
  r = await fetch(
1443
1619
  new URL(n, document.baseURI).href,
1444
1620
  this.init({ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ url: e }) })
1445
1621
  );
1446
- } catch (o) {
1447
- throw new P(o.message || "Network error");
1622
+ } catch (i) {
1623
+ throw new H(i.message || "Network error", "network");
1448
1624
  }
1449
- if (!r.ok) throw new P(await kt(r));
1625
+ if (!r.ok) throw new H(await Ht(r));
1450
1626
  }
1451
1627
  }
1452
- const b = (t, e, n) => {
1628
+ function Ue(t, e) {
1629
+ return t instanceof H && t.code === "network" ? e.fmNetworkError : t instanceof H && t.code === "response" ? e.fmInvalidResponse : t?.message ?? "";
1630
+ }
1631
+ const w = (t, e, n) => {
1453
1632
  const r = document.createElement(t);
1454
1633
  return e && (r.className = e), n !== void 0 && (r.textContent = n), r;
1455
- }, Oe = (t, e, n = "wds-icon-button") => {
1456
- const r = b("button", n);
1634
+ }, We = (t, e, n = "wds-icon-button") => {
1635
+ const r = w("button", n);
1457
1636
  return r.type = "button", r.innerHTML = t, r.setAttribute("aria-label", e), r.title = e, r;
1458
- }, Er = [
1637
+ }, ei = [
1459
1638
  ["", "alignNone"],
1460
1639
  ["left", "alignLeftShort"],
1461
1640
  ["center", "alignCenterShort"],
1462
1641
  ["right", "alignRightShort"]
1463
1642
  ];
1464
- class Sr {
1643
+ class ti {
1465
1644
  constructor(e, n, r) {
1466
1645
  this.host = e, this.api = n, this.t = r, this.path = "/", this.view = "grid", this.sort = "newest";
1467
1646
  }
1468
1647
  open(e) {
1469
1648
  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");
1478
- y.setAttribute("aria-label", n.fmBreadcrumb);
1479
- const x = b("input", "wds-input wds-fm-search");
1480
- 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;
1483
- for (const [h, f] of [["newest", "fmSortNewest"], ["name", "fmSortName"], ["largest", "fmSortLargest"]]) {
1484
- const M = b("option", void 0, n[f]);
1485
- M.value = h, A.append(M);
1649
+ let i = [], s = [], o = 1, c = !1, a = !1, l = "", d = null, u = null, m = 0, p = !1;
1650
+ const b = w("dialog", "wds-dialog wds-fm");
1651
+ b.setAttribute("aria-labelledby", "wds-fm-title");
1652
+ const x = w("div", "wds-dialog-header"), T = w("h2", void 0, n.fmTitle);
1653
+ T.id = "wds-fm-title";
1654
+ const A = We(L.close, n.close);
1655
+ x.append(T, A);
1656
+ const N = w("div", "wds-fm-bar"), v = w("nav", "wds-fm-crumbs");
1657
+ v.setAttribute("aria-label", n.fmBreadcrumb);
1658
+ const E = w("input", "wds-input wds-fm-search");
1659
+ E.type = "search", E.placeholder = n.fmSearch, E.setAttribute("aria-label", n.fmSearch);
1660
+ const I = w("select", "wds-input wds-fm-sort");
1661
+ I.setAttribute("aria-label", n.fmSort), I.title = n.fmSort;
1662
+ for (const [h, g] of [["newest", "fmSortNewest"], ["name", "fmSortName"], ["largest", "fmSortLargest"]]) {
1663
+ const M = w("option", void 0, n[g]);
1664
+ M.value = h, I.append(M);
1486
1665
  }
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");
1666
+ I.value = this.sort;
1667
+ const R = We(this.view === "grid" ? L.list : L.grid, this.view === "grid" ? n.fmList : n.fmGrid), $ = w("input");
1489
1668
  $.type = "file", $.multiple = !0, $.hidden = !0, r && ($.accept = r);
1490
- 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>`;
1492
- 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);
1496
- const N = b("p", "wds-fm-status");
1497
- N.setAttribute("role", "status");
1498
- const Z = b("button", "wds-button", n.fmRetry);
1499
- Z.type = "button", Z.hidden = !0;
1500
- const ee = b("button", "wds-button wds-fm-more", n.fmLoadMore);
1669
+ const j = w("button", "wds-button wds-button-primary wds-fm-upload");
1670
+ j.type = "button", j.innerHTML = `${L.upload}<span>${_e(n.fmUpload)}</span>`;
1671
+ const Ae = w("div", "wds-fm-tools");
1672
+ Ae.append(E, I, R), this.api.canUpload && Ae.append(j, $), N.append(v, Ae);
1673
+ const ct = w("div", "wds-fm-main"), V = w("div", "wds-fm-browser"), Te = w("div", "wds-fm-uploads"), F = w("ul", `wds-fm-items is-${this.view}`);
1674
+ F.setAttribute("aria-label", n.fmTitle);
1675
+ const D = w("p", "wds-fm-status");
1676
+ D.setAttribute("role", "status");
1677
+ const ee = w("button", "wds-button", n.fmRetry);
1501
1678
  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);
1506
- const xe = b("div", "wds-dialog-footer");
1679
+ const te = w("button", "wds-button wds-fm-more", n.fmLoadMore);
1680
+ te.type = "button", te.hidden = !0;
1681
+ const dt = w("div", "wds-fm-drop", n.fmDrop);
1682
+ dt.setAttribute("aria-hidden", "true"), V.append(Te, F, D, ee, te, dt);
1683
+ const U = w("aside", "wds-fm-details");
1684
+ U.setAttribute("aria-label", n.imageEdit), ct.append(V, U);
1685
+ const Ce = w("div", "wds-dialog-footer");
1507
1686
  if (e.onFromUrl) {
1508
- 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", () => {
1687
+ const h = w("button", "wds-button wds-fm-fromurl");
1688
+ h.type = "button", h.innerHTML = `${L.globe}<span>${_e(n.fmFromUrl)}</span>`, h.addEventListener("click", () => {
1510
1689
  X(), e.onFromUrl();
1511
- }), xe.append(h);
1690
+ }), Ce.append(h);
1512
1691
  }
1513
- const Ee = b("button", "wds-button", n.cancel);
1514
- Ee.type = "button";
1515
- 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) => {
1519
- f.id = M;
1520
- 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);
1692
+ const Ie = w("button", "wds-button", n.cancel);
1693
+ Ie.type = "button";
1694
+ const le = w("button", "wds-button wds-button-primary", n.insert);
1695
+ le.type = "button", le.disabled = !0, Ce.append(w("span", "wds-spacer"), Ie, le), b.append(x, N, ct, Ce), this.host.append(b);
1696
+ let ce = null, W = null, de = null, Y = null, ue = null;
1697
+ const ye = (h, g, M, y) => {
1698
+ g.id = M;
1699
+ const C = w("label", "wds-label", h);
1700
+ if (C.htmlFor = M, U.append(C, g), y) {
1701
+ const k = w("p", "wds-hint", y);
1702
+ k.id = `${M}-hint`, g.setAttribute("aria-describedby", k.id), U.append(k);
1524
1703
  }
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));
1704
+ }, ve = () => {
1705
+ if (U.replaceChildren(), ce = W = ue = Y = null, de = null, le.disabled = !d, !d) {
1706
+ U.append(w("p", "wds-fm-placeholder", n.fmNoSelection));
1528
1707
  return;
1529
1708
  }
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 = () => [
1709
+ const h = d, g = w("div", "wds-fm-preview"), M = w("p", "wds-fm-filename", h.name), y = w("p", "wds-fm-facts"), C = () => [
1531
1710
  h.width && h.height ? `${h.width} × ${h.height}` : "",
1532
- vt(h.size),
1711
+ Ot(h.size),
1533
1712
  h.modified ? new Date(h.modified).toLocaleDateString() : ""
1534
1713
  ].filter(Boolean).join(" · ");
1535
- if (w.textContent = S(), ue(h)) {
1536
- const k = b("img");
1714
+ if (y.textContent = C(), pe(h)) {
1715
+ const k = w("img");
1537
1716
  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);
1717
+ !k.naturalWidth || d !== h || (h.width = k.naturalWidth, h.height = k.naturalHeight, y.textContent = C(), W && !W.placeholder && (W.placeholder = String(h.width)));
1718
+ }, { once: !0 }), k.src = h.thumb ?? h.url, g.append(k);
1540
1719
  } else
1541
- 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);
1720
+ g.innerHTML = L.file;
1721
+ if (U.append(g, M, y), e.mode === "image" && pe(h)) {
1722
+ ce = w("input", "wds-input"), ce.value = h.name.replace(/\.[a-z0-9]+$/i, "").replace(/[-_]+/g, " "), ye(n.imageAlt, ce, "wds-fm-alt", n.imageAltHint), W = w("input", "wds-input"), W.inputMode = "numeric", W.placeholder = h.width ? String(h.width) : "", ye(n.imageWidth, W, "wds-fm-width"), de = w("select", "wds-input");
1723
+ for (const [P, B] of ei) {
1724
+ const ne = w("option", void 0, n[B]);
1725
+ ne.value = P, de.append(ne);
1547
1726
  }
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);
1727
+ ye(n.imageAlign, de, "wds-fm-align"), Y = w("input"), Y.type = "checkbox", Y.id = "wds-fm-caption";
1728
+ const k = w("label", "wds-check");
1729
+ k.htmlFor = Y.id, k.append(Y, document.createTextNode(n.caption)), U.append(k);
1551
1730
  } else
1552
- le = b("input", "wds-input"), le.value = h.name, me(n.fmLinkText, le, "wds-fm-text");
1731
+ ue = w("input", "wds-input"), ue.value = h.name, ye(n.fmLinkText, ue, "wds-fm-text");
1553
1732
  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);
1733
+ const k = w("button", "wds-button wds-button-danger wds-fm-delete");
1734
+ k.type = "button", k.innerHTML = `${L.trash}<span>${_e(n.fmDelete)}</span>`, k.addEventListener("click", () => mn(h)), U.append(k);
1556
1735
  }
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;
1559
- 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
- }, Se = () => {
1561
- y.replaceChildren();
1562
- const h = this.path.split("/").filter(Boolean), f = [[n.fmRoot, "/"], ...h.map((M, w) => [M, "/" + h.slice(0, w + 1).join("/")])];
1563
- f.forEach(([M, w], S) => {
1564
- 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);
1736
+ }, fn = () => {
1737
+ const h = l.trim().toLocaleLowerCase(), g = i.filter((y) => $t(y, r) && (a || !h || y.name.toLocaleLowerCase().includes(h))), M = (y) => y.modified ? Date.parse(y.modified) : -1 / 0;
1738
+ return this.sort === "name" ? g.sort((y, C) => y.name.localeCompare(C.name, void 0, { numeric: !0, sensitivity: "base" })) : this.sort === "largest" ? g.sort((y, C) => (C.size ?? -1) - (y.size ?? -1)) : g.sort((y, C) => M(C) - M(y)), g;
1739
+ }, De = () => {
1740
+ v.replaceChildren();
1741
+ const h = this.path.split("/").filter(Boolean), g = [[n.fmRoot, "/"], ...h.map((M, y) => [M, "/" + h.slice(0, y + 1).join("/")])];
1742
+ g.forEach(([M, y], C) => {
1743
+ if (C && v.append(w("span", "wds-fm-sep", "/")), C === g.length - 1) {
1744
+ const k = w("span", "wds-fm-crumb is-current", M);
1745
+ k.setAttribute("aria-current", "location"), v.append(k);
1567
1746
  } else {
1568
- const k = b("button", "wds-fm-crumb", M);
1569
- k.type = "button", k.addEventListener("click", () => et(w)), y.append(k);
1747
+ const k = w("button", "wds-fm-crumb", M);
1748
+ k.type = "button", k.addEventListener("click", () => ft(y)), v.append(k);
1570
1749
  }
1571
1750
  });
1572
1751
  }, J = () => {
1573
- B.className = `wds-fm-items is-${this.view}`, B.replaceChildren();
1574
- const h = !a.trim();
1752
+ F.className = `wds-fm-items is-${this.view}`, F.replaceChildren();
1753
+ const h = !l.trim();
1575
1754
  if (h)
1576
- 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));
1755
+ for (const y of s) {
1756
+ const C = ht(L.folder, y.name, n.fmFolder, !0);
1757
+ C.addEventListener("click", () => ft(y.path)), F.append(ut(C));
1579
1758
  }
1580
- const f = Wt();
1581
- 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);
1583
- 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);
1759
+ const g = fn();
1760
+ for (const y of g) {
1761
+ const C = pe(y) ? y.thumb ?? y.url : null, k = ht(C ? "" : L.file, y.name, [Ot(y.size), y.width && y.height ? `${y.width}×${y.height}` : ""].filter(Boolean).join(" · "), !1);
1762
+ if (C) {
1763
+ const B = w("img");
1764
+ B.loading = "lazy", B.decoding = "async", B.alt = "", B.src = C, k.querySelector(".wds-fm-thumb").append(B);
1586
1765
  }
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", () => {
1590
- Ae(w), Te();
1591
- }), B.append(Qe(k));
1766
+ k.dataset.url = y.url;
1767
+ const P = d?.url === y.url;
1768
+ k.classList.toggle("is-selected", P), k.setAttribute("aria-pressed", String(P)), k.addEventListener("click", () => Ne(y)), k.addEventListener("dblclick", () => {
1769
+ Ne(y), Re();
1770
+ }), F.append(ut(k));
1592
1771
  }
1593
- 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) => {
1596
- const f = b("li");
1597
- return f.append(h), f;
1598
- }, Ze = (h, f, M, w) => {
1599
- const S = b("button", `wds-fm-item${w ? " is-folder" : ""}`);
1600
- S.type = "button";
1601
- const k = b("span", "wds-fm-thumb");
1772
+ const M = !g.length && !(h && s.length);
1773
+ !D.dataset.busy && !D.dataset.error && (D.textContent = M ? l.trim() ? n.fmNoResults : n.fmEmpty : ""), te.hidden = !c || !!D.dataset.busy;
1774
+ }, ut = (h) => {
1775
+ const g = w("li");
1776
+ return g.append(h), g;
1777
+ }, ht = (h, g, M, y) => {
1778
+ const C = w("button", `wds-fm-item${y ? " is-folder" : ""}`);
1779
+ C.type = "button";
1780
+ const k = w("span", "wds-fm-thumb");
1602
1781
  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;
1607
- }, Ae = (h) => {
1608
- c = h, B.querySelectorAll(".wds-fm-item[data-url]").forEach((f) => {
1609
- const M = f.dataset.url === h.url;
1610
- f.classList.toggle("is-selected", M), f.setAttribute("aria-pressed", String(M));
1611
- }), fe();
1612
- }, 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();
1782
+ const P = w("span", "wds-fm-name", g);
1783
+ P.title = g;
1784
+ const B = w("span", "wds-fm-meta", M);
1785
+ return C.append(k, P, B), C;
1786
+ }, Ne = (h) => {
1787
+ d = h, F.querySelectorAll(".wds-fm-item[data-url]").forEach((g) => {
1788
+ const M = g.dataset.url === h.url;
1789
+ g.classList.toggle("is-selected", M), g.setAttribute("aria-pressed", String(M));
1790
+ }), ve();
1791
+ }, he = async (h) => {
1792
+ u?.abort(), u = new AbortController(), h && (o = 1, i = [], s = []), D.dataset.busy = "1", delete D.dataset.error, D.textContent = n.fmLoading, ee.hidden = !0, te.hidden = !0, h && J();
1614
1793
  try {
1615
- const f = await this.api.list(this.path, a.trim(), l, u.signal);
1616
- if (g) return;
1617
- this.path = f.path, i = f.serverSearch, d = f.hasMore, s = h ? f.folders : s;
1618
- 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();
1620
- } catch (f) {
1621
- 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;
1794
+ const g = await this.api.list(this.path, l.trim(), o, u.signal);
1795
+ if (p) return;
1796
+ this.path = g.path, a = g.serverSearch, c = g.hasMore, s = h ? g.folders : s;
1797
+ const M = new Set(i.map((y) => y.url));
1798
+ i = [...i, ...g.files.filter((y) => !M.has(y.url))], delete D.dataset.busy, D.textContent = "", De(), J();
1799
+ } catch (g) {
1800
+ if (g.name === "AbortError" || p) return;
1801
+ delete D.dataset.busy, D.dataset.error = "1", D.textContent = z(n.fmListFailed, { error: Ue(g, n) }), D.setAttribute("role", "alert"), ee.hidden = !1;
1623
1802
  }
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) => {
1627
- 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);
1803
+ }, ft = (h) => {
1804
+ this.path = rt(h), l = "", E.value = "", d = null, ve(), De(), he(!0).then(() => F.querySelector(".wds-fm-item")?.focus());
1805
+ }, mt = (h) => {
1806
+ for (const g of Array.from(h)) {
1807
+ const M = w("div", "wds-fm-upload-row"), y = w("span", "wds-fm-upload-name", z(n.fmUploading, { name: g.name }));
1808
+ if (!$t(g, r)) {
1809
+ pt(M, z(n.fmNotAllowed, { name: g.name })), Te.append(M);
1631
1810
  continue;
1632
1811
  }
1633
- 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));
1812
+ const C = w("progress");
1813
+ C.max = 1, C.value = 0, M.append(y, C), Te.append(M), this.api.upload(g, this.path, (k) => C.value = k).then((k) => {
1814
+ p || (M.remove(), i = [k, ...i.filter((P) => P.url !== k.url)], J(), Ne(k), e.onUpload?.(k));
1636
1815
  }).catch((k) => {
1637
- g || (M.replaceChildren(), nt(M, V(n.fmUploadFailed, { name: f.name, error: k.message })));
1816
+ p || (M.replaceChildren(), pt(M, z(n.fmUploadFailed, { name: g.name, error: Ue(k, n) })));
1638
1817
  });
1639
1818
  }
1640
- }, nt = (h, f) => {
1819
+ }, pt = (h, g) => {
1641
1820
  h.classList.add("is-error");
1642
- const M = b("span", "wds-fm-upload-name", f);
1821
+ const M = w("span", "wds-fm-upload-name", g);
1643
1822
  M.setAttribute("role", "alert");
1644
- const w = Oe(L.close, n.close);
1645
- w.addEventListener("click", () => h.remove()), h.append(M, w);
1646
- }, qt = async (h) => {
1647
- if (window.confirm(V(n.fmDeleteConfirm, { name: h.name })))
1823
+ const y = We(L.close, n.close);
1824
+ y.addEventListener("click", () => h.remove()), h.append(M, y);
1825
+ }, mn = async (h) => {
1826
+ if (window.confirm(z(n.fmDeleteConfirm, { name: h.name })))
1648
1827
  try {
1649
- await this.api.remove(h.url), o = o.filter((f) => f.url !== h.url), c = null, fe(), J();
1650
- } catch (f) {
1651
- N.dataset.error = "1", N.setAttribute("role", "alert"), N.textContent = V(n.fmDeleteFailed, { error: f.message });
1828
+ await this.api.remove(h.url), i = i.filter((g) => g.url !== h.url), d = null, ve(), J();
1829
+ } catch (g) {
1830
+ D.dataset.error = "1", D.setAttribute("role", "alert"), D.textContent = z(n.fmDeleteFailed, { error: Ue(g, n) });
1652
1831
  }
1653
- }, Te = () => {
1654
- if (!c) return;
1655
- const h = U ? parseInt(U.value, 10) : NaN;
1832
+ }, Re = () => {
1833
+ if (!d) return;
1834
+ const h = W ? parseInt(W.value, 10) : NaN;
1656
1835
  e.onPick({
1657
- file: c,
1658
- alt: ae?.value.trim() ?? "",
1836
+ file: d,
1837
+ alt: ce?.value.trim() ?? "",
1659
1838
  width: Number.isFinite(h) && h > 0 ? h : null,
1660
- align: se?.value || null,
1661
- text: le?.value.trim() || c.name,
1839
+ align: de?.value || null,
1840
+ text: ue?.value.trim() || d.name,
1662
1841
  caption: !!Y?.checked
1663
1842
  }), X();
1664
1843
  };
1665
1844
  function X() {
1666
- g || (g = !0, u?.abort(), window.clearTimeout(m), v.open && v.close(), v.remove(), e.onClose?.());
1845
+ p || (p = !0, u?.abort(), window.clearTimeout(m), b.open && b.close(), b.remove(), e.onClose?.());
1667
1846
  }
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", () => {
1669
- 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;
1847
+ if (A.addEventListener("click", X), Ie.addEventListener("click", X), le.addEventListener("click", Re), b.addEventListener("close", X), b.addEventListener("click", (h) => h.target === b && X()), ee.addEventListener("click", () => {
1848
+ D.setAttribute("role", "status"), he(!0);
1849
+ }), te.addEventListener("click", () => {
1850
+ o++, he(!1);
1851
+ }), I.addEventListener("change", () => {
1852
+ this.sort = I.value, J();
1853
+ }), R.addEventListener("click", () => {
1854
+ this.view = this.view === "grid" ? "list" : "grid", R.innerHTML = this.view === "grid" ? L.list : L.grid;
1676
1855
  const h = this.view === "grid" ? n.fmList : n.fmGrid;
1677
- I.setAttribute("aria-label", h), I.title = h, J();
1678
- }), x.addEventListener("input", () => {
1856
+ R.setAttribute("aria-label", h), R.title = h, J();
1857
+ }), E.addEventListener("input", () => {
1679
1858
  window.clearTimeout(m), m = window.setTimeout(() => {
1680
- a = x.value, !i && !d ? J() : ce(!0);
1859
+ l = E.value, !a && !c ? J() : he(!0);
1681
1860
  }, 250);
1682
- }), G.addEventListener("click", () => $.click()), $.addEventListener("change", () => {
1683
- $.files?.length && tt($.files), $.value = "";
1861
+ }), j.addEventListener("click", () => $.click()), $.addEventListener("change", () => {
1862
+ $.files?.length && mt($.files), $.value = "";
1684
1863
  }), this.api.canUpload) {
1685
1864
  let h = 0;
1686
- W.addEventListener("dragenter", (f) => {
1687
- f.dataTransfer?.types.includes("Files") && (h++, W.classList.add("is-dragging"));
1688
- }), W.addEventListener("dragleave", () => {
1689
- h = Math.max(0, h - 1), h || W.classList.remove("is-dragging");
1690
- }), W.addEventListener("dragover", (f) => {
1691
- f.dataTransfer?.types.includes("Files") && f.preventDefault();
1692
- }), W.addEventListener("drop", (f) => {
1693
- f.preventDefault(), h = 0, W.classList.remove("is-dragging"), f.dataTransfer?.files.length && tt(f.dataTransfer.files);
1865
+ V.addEventListener("dragenter", (g) => {
1866
+ g.dataTransfer?.types.includes("Files") && (h++, V.classList.add("is-dragging"));
1867
+ }), V.addEventListener("dragleave", () => {
1868
+ h = Math.max(0, h - 1), h || V.classList.remove("is-dragging");
1869
+ }), V.addEventListener("dragover", (g) => {
1870
+ g.dataTransfer?.types.includes("Files") && g.preventDefault();
1871
+ }), V.addEventListener("drop", (g) => {
1872
+ g.preventDefault(), h = 0, V.classList.remove("is-dragging"), g.dataTransfer?.files.length && mt(g.dataTransfer.files);
1694
1873
  });
1695
1874
  }
1696
- return B.addEventListener("keydown", (h) => {
1875
+ return F.addEventListener("keydown", (h) => {
1697
1876
  if (!["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp", "Home", "End"].includes(h.key)) return;
1698
- const M = [...B.querySelectorAll(".wds-fm-item")], w = M.indexOf(document.activeElement);
1699
- if (w < 0) return;
1877
+ const M = [...F.querySelectorAll(".wds-fm-item")], y = M.indexOf(document.activeElement);
1878
+ if (y < 0) return;
1700
1879
  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) => {
1704
- h.key === "Enter" && h.target.tagName === "INPUT" && (h.preventDefault(), Te());
1705
- }), Se(), fe(), v.showModal(), x.focus(), ce(!0), X;
1880
+ const C = M[0].offsetTop, k = this.view === "list" ? 1 : Math.max(1, M.findIndex((ne) => ne.offsetTop !== C) === -1 ? M.length : M.findIndex((ne) => ne.offsetTop !== C)), P = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: k, ArrowUp: -k }, B = h.key === "Home" ? 0 : h.key === "End" ? M.length - 1 : Math.min(M.length - 1, Math.max(0, y + P[h.key]));
1881
+ M[B].focus();
1882
+ }), U.addEventListener("keydown", (h) => {
1883
+ h.key === "Enter" && h.target.tagName === "INPUT" && (h.preventDefault(), Re());
1884
+ }), De(), ve(), b.showModal(), E.focus(), he(!0), X;
1706
1885
  }
1707
1886
  }
1708
- function $e(t) {
1887
+ function _e(t) {
1709
1888
  const e = document.createElement("span");
1710
1889
  return e.textContent = t, e.innerHTML;
1711
1890
  }
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);
1891
+ const Pt = /* @__PURE__ */ new Map();
1892
+ let ni = 0;
1893
+ function ri(t) {
1894
+ const e = [];
1895
+ let n = 0, r = "", i = "";
1896
+ for (let s = 0; s < t.length; s++) {
1897
+ const o = t[s];
1898
+ if (r) {
1899
+ if (o === "\\") {
1900
+ i += o + (t[++s] ?? "");
1901
+ continue;
1902
+ }
1903
+ o === r && (r = "");
1904
+ } else if (o === '"' || o === "'") r = o;
1905
+ else if (o === "(" || o === "[") n++;
1906
+ else if (o === ")" || o === "]") n--;
1907
+ else if (o === "," && n === 0) {
1908
+ e.push(i.trim()), i = "";
1909
+ continue;
1910
+ }
1911
+ i += o;
1912
+ }
1913
+ return i.trim() && e.push(i.trim()), e;
1914
+ }
1915
+ const Ve = /^(?::root|:host|html|body)(?![\w-])((?:\[[^\]]*\]|[.:#][\w-]+(?:\([^)]*\))?)*)/i;
1916
+ function ii(t, e) {
1917
+ return ri(t).map((n) => {
1918
+ let r = n, i = !1, s = "";
1919
+ for (let c = r.match(Ve); c; c = r.match(Ve)) {
1920
+ i = !0, s = c[1] ?? "", r = r.slice(c[0].length).trimStart();
1921
+ const a = r.replace(/^>\s*/, "");
1922
+ a !== r && Ve.test(a) && (r = a);
1923
+ }
1924
+ if (!i) return `${e} ${n}`;
1925
+ const o = e + s;
1926
+ return r ? `${o} ${r}` : o;
1927
+ }).join(", ");
1928
+ }
1929
+ function dn(t, e) {
1930
+ for (const n of Array.from(t))
1931
+ if ("selectorText" in n && typeof n.selectorText == "string") {
1932
+ const r = n;
1933
+ r.selectorText = ii(r.selectorText, e);
1934
+ } else "cssRules" in n && !("name" in n && "appendRule" in n) && dn(n.cssRules, e);
1935
+ }
1936
+ function un(t) {
1937
+ const e = typeof CSSLayerBlockRule < "u";
1938
+ for (let n = 0; n < t.cssRules.length; n++) {
1939
+ const r = t.cssRules[n];
1940
+ if (e && r instanceof CSSLayerStatementRule)
1941
+ t.deleteRule(n--);
1942
+ else if (e && r instanceof CSSLayerBlockRule) {
1943
+ const i = Array.from(r.cssRules, (s) => s.cssText);
1944
+ t.deleteRule(n), i.forEach((s, o) => {
1945
+ try {
1946
+ t.insertRule(s, n + o);
1947
+ } catch {
1948
+ }
1949
+ }), n--;
1950
+ } else typeof CSSGroupingRule < "u" && r instanceof CSSGroupingRule && un(r);
1951
+ }
1715
1952
  }
1716
- const re = class re {
1953
+ const si = () => typeof CSSStyleSheet < "u" && "replaceSync" in CSSStyleSheet.prototype && "adoptedStyleSheets" in document;
1954
+ async function oi(t, e) {
1955
+ const n = `:where(.${e})`, r = t.css === void 0 ? [] : Array.isArray(t.css) ? t.css : [t.css], i = await Promise.all(
1956
+ r.map(async (o) => {
1957
+ const c = new URL(o, document.baseURI).href;
1958
+ try {
1959
+ const a = await fetch(c, { credentials: "same-origin" });
1960
+ if (!a.ok) throw new Error(`HTTP ${a.status}`);
1961
+ return { text: await a.text(), baseURL: c };
1962
+ } catch (a) {
1963
+ return console.warn(`[WDS Editor] contentCss could not be loaded: ${c}`, a), null;
1964
+ }
1965
+ })
1966
+ );
1967
+ t.style && i.push({ text: t.style, baseURL: document.baseURI });
1968
+ const s = [];
1969
+ for (const o of i) {
1970
+ if (!o) continue;
1971
+ const c = new CSSStyleSheet({ baseURL: o.baseURL });
1972
+ c.replaceSync(o.text.replace(/@import[^;]*;/g, "")), un(c), dn(c.cssRules, n), s.push(c);
1973
+ }
1974
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, ...s];
1975
+ }
1976
+ function ai(t) {
1977
+ if (!t.css?.length && !t.style) return null;
1978
+ if (!si())
1979
+ return console.warn("[WDS Editor] contentCss needs constructable stylesheets (all current browsers)."), null;
1980
+ const e = JSON.stringify([t.css, t.style ?? ""]);
1981
+ let n = Pt.get(e);
1982
+ if (!n) {
1983
+ const r = `wds-site-${++ni}`;
1984
+ n = { className: r, ready: oi(t, r) }, Pt.set(e, n);
1985
+ }
1986
+ return n;
1987
+ }
1988
+ const G = new Ut("wds-find");
1989
+ function li(t, e, n) {
1990
+ const r = [];
1991
+ if (!e) return r;
1992
+ const i = n ? e : e.toLowerCase();
1993
+ return t.descendants((s, o) => {
1994
+ if (!s.isTextblock) return !0;
1995
+ let c = "";
1996
+ s.forEach((l) => {
1997
+ c += l.isText ? l.text : "".repeat(l.nodeSize);
1998
+ });
1999
+ const a = n ? c : c.toLowerCase();
2000
+ for (let l = a.indexOf(i); l >= 0; l = a.indexOf(i, l + i.length))
2001
+ r.push({ from: o + 1 + l, to: o + 1 + l + i.length });
2002
+ return !1;
2003
+ }), r;
2004
+ }
2005
+ function ci(t, e) {
2006
+ if (!t.length) return -1;
2007
+ const n = t.findIndex((r) => r.to > e);
2008
+ return n < 0 ? 0 : n;
2009
+ }
2010
+ function di() {
2011
+ return new it({
2012
+ key: G,
2013
+ state: {
2014
+ init: () => ({ query: "", caseSensitive: !1, matches: [], current: -1 }),
2015
+ apply(t, e, n, r) {
2016
+ const i = t.getMeta(G);
2017
+ if (!i && !t.docChanged) return e;
2018
+ const s = i?.query ?? e.query, o = i?.caseSensitive ?? e.caseSensitive, c = li(r.doc, s, o);
2019
+ let a = i?.current ?? (i?.query !== void 0 || i?.caseSensitive !== void 0 ? ci(c, r.selection.from) : e.current);
2020
+ return a >= c.length && (a = c.length ? 0 : -1), a < 0 && c.length && (a = 0), { query: s, caseSensitive: o, matches: c, current: a };
2021
+ }
2022
+ },
2023
+ props: {
2024
+ decorations(t) {
2025
+ const e = G.getState(t);
2026
+ return e?.matches.length ? st.create(
2027
+ t.doc,
2028
+ e.matches.map((n, r) => ot.inline(n.from, n.to, { class: r === e.current ? "wds-find-match wds-find-current" : "wds-find-match" }))
2029
+ ) : null;
2030
+ }
2031
+ }
2032
+ });
2033
+ }
2034
+ const oe = (t) => G.getState(t);
2035
+ function qe(t, e) {
2036
+ const n = oe(t.state);
2037
+ if (!n.matches.length) return;
2038
+ const r = (n.current + e + n.matches.length) % n.matches.length, i = n.matches[r];
2039
+ t.dispatch(t.state.tr.setMeta(G, { current: r }).setSelection(be.create(t.state.doc, i.from, i.to)).scrollIntoView());
2040
+ }
2041
+ function hn(t, e, n) {
2042
+ n ? t.insertText(n, e.from, e.to) : t.delete(e.from, e.to);
2043
+ }
2044
+ function Bt(t, e) {
2045
+ const n = oe(t.state), r = n.matches[n.current];
2046
+ if (!r) return;
2047
+ const i = t.state.tr;
2048
+ hn(i, r, e), i.setMeta(G, { current: n.current }), t.dispatch(i.scrollIntoView());
2049
+ const s = oe(t.state).matches[oe(t.state).current];
2050
+ s && t.dispatch(t.state.tr.setSelection(be.create(t.state.doc, s.from, s.to)).scrollIntoView());
2051
+ }
2052
+ function ui(t, e) {
2053
+ const { matches: n } = oe(t.state);
2054
+ if (!n.length) return 0;
2055
+ const r = t.state.tr;
2056
+ for (let i = n.length - 1; i >= 0; i--) hn(r, n[i], e);
2057
+ return t.dispatch(r.scrollIntoView()), n.length;
2058
+ }
2059
+ function Ge(t, e) {
2060
+ const n = document.createElement("button");
2061
+ return n.type = "button", n.className = "wds-icon-button", n.innerHTML = t, n.setAttribute("aria-label", e), n.title = e, n;
2062
+ }
2063
+ class hi {
2064
+ constructor(e, n, r) {
2065
+ this.view = e, this.t = n, this.onClose = r;
2066
+ const i = this.element = document.createElement("div");
2067
+ i.className = "wds-find", i.setAttribute("role", "search"), i.hidden = !0;
2068
+ const s = (x, T) => {
2069
+ const A = document.createElement("input");
2070
+ return A.type = "text", A.className = "wds-input wds-find-input", A.placeholder = T, A.setAttribute("aria-label", x), A.spellcheck = !1, A;
2071
+ };
2072
+ this.findInput = s(n.find, n.find), this.replaceInput = s(n.replaceWith, n.replaceWith), this.count = document.createElement("span"), this.count.className = "wds-find-count", this.count.setAttribute("aria-live", "polite");
2073
+ const o = Ge(L.arrowUp, n.findPrevious), c = Ge(L.arrowDown, n.findNext), a = document.createElement("button");
2074
+ a.type = "button", a.className = "wds-button", a.textContent = n.replace;
2075
+ const l = document.createElement("button");
2076
+ l.type = "button", l.className = "wds-button", l.textContent = n.replaceAll, this.buttons = [o, c, a, l];
2077
+ const d = document.createElement("label");
2078
+ d.className = "wds-find-case", this.caseInput = document.createElement("input"), this.caseInput.type = "checkbox", d.append(this.caseInput, ` ${n.matchCase}`);
2079
+ const u = Ge(L.close, n.close), m = document.createElement("div");
2080
+ m.className = "wds-find-row", m.append(this.findInput, this.count, o, c);
2081
+ const p = document.createElement("div");
2082
+ p.className = "wds-find-row", p.append(this.replaceInput, a, l), i.append(m, p, d, u);
2083
+ const b = () => e.dispatch(e.state.tr.setMeta(G, { query: this.findInput.value, caseSensitive: this.caseInput.checked }));
2084
+ this.findInput.addEventListener("input", b), this.caseInput.addEventListener("change", b), o.addEventListener("click", () => qe(e, -1)), c.addEventListener("click", () => qe(e, 1)), a.addEventListener("click", () => Bt(e, this.replaceInput.value)), l.addEventListener("click", () => {
2085
+ const x = ui(e, this.replaceInput.value);
2086
+ x && (this.count.textContent = z(n.replacedCount, { count: x }));
2087
+ }), u.addEventListener("click", () => this.close()), i.addEventListener("keydown", (x) => {
2088
+ x.key === "Escape" ? (x.preventDefault(), x.stopPropagation(), this.close()) : x.key === "Enter" && x.target === this.findInput ? (x.preventDefault(), qe(e, x.shiftKey ? -1 : 1)) : x.key === "Enter" && x.target === this.replaceInput && (x.preventDefault(), Bt(e, this.replaceInput.value));
2089
+ });
2090
+ }
2091
+ get isOpen() {
2092
+ return !this.element.hidden;
2093
+ }
2094
+ open() {
2095
+ const { from: e, to: n, empty: r } = this.view.state.selection, i = r ? "" : this.view.state.doc.textBetween(e, n, " ");
2096
+ i && i.length < 100 && !i.includes(`
2097
+ `) && (this.findInput.value = i), this.element.hidden = !1, this.findInput.focus(), this.findInput.select(), this.view.dispatch(this.view.state.tr.setMeta(G, { query: this.findInput.value, caseSensitive: this.caseInput.checked }));
2098
+ }
2099
+ close() {
2100
+ this.element.hidden || (this.element.hidden = !0, this.view.dispatch(this.view.state.tr.setMeta(G, { query: "" })), this.onClose());
2101
+ }
2102
+ /** Updates the "3 of 10" counter and the button states after every transaction. */
2103
+ update(e, n) {
2104
+ if (this.element.hidden) return;
2105
+ const r = oe(e), i = r.matches.length;
2106
+ this.count.textContent = r.query ? i ? z(this.t.matchCount, { current: r.current + 1, total: i }) : this.t.noMatches : "";
2107
+ const s = this.buttons.find((o) => o === document.activeElement);
2108
+ this.buttons.forEach((o, c) => o.disabled = !i || c > 1 && !n), s?.disabled && this.findInput.focus(), this.replaceInput.disabled = !n;
2109
+ }
2110
+ }
2111
+ const fi = "wds-editor:draft:";
2112
+ function me() {
2113
+ try {
2114
+ return window.localStorage;
2115
+ } catch {
2116
+ return null;
2117
+ }
2118
+ }
2119
+ class mi {
2120
+ constructor(e, n, r, i, s, o) {
2121
+ this.host = r, this.before = i, this.t = s, this.restore = o, this.timer = 0, this.pending = null, this.bar = null, this.onPageHide = () => this.flush(), this.key = fi + (e.key ?? n), this.delay = e.delay ?? 1e3, this.expires = e.expires ?? 7, window.addEventListener("pagehide", this.onPageHide);
2122
+ }
2123
+ /** Shows the restore bar when a saved draft differs from the content the editor started with. */
2124
+ check(e) {
2125
+ const n = this.read();
2126
+ if (!n || n.html === e) return;
2127
+ const r = this.bar = document.createElement("div");
2128
+ r.className = "wds-draft", r.setAttribute("role", "status");
2129
+ const i = document.createElement("span"), s = new Date(n.time).toLocaleString(this.host.lang || void 0, { dateStyle: "short", timeStyle: "short" });
2130
+ i.textContent = z(this.t.draftFound, { time: s });
2131
+ const o = document.createElement("button");
2132
+ o.type = "button", o.className = "wds-button wds-button-primary", o.textContent = this.t.draftRestore;
2133
+ const c = document.createElement("button");
2134
+ c.type = "button", c.className = "wds-button", c.textContent = this.t.draftDiscard, o.addEventListener("click", () => {
2135
+ this.hideBar(), this.restore(n.html);
2136
+ }), c.addEventListener("click", () => {
2137
+ this.hideBar(), this.clear();
2138
+ }), r.append(i, o, c), this.host.insertBefore(r, this.before);
2139
+ }
2140
+ /** Called on every content change. While the restore bar is open the old draft is kept. */
2141
+ schedule(e) {
2142
+ this.bar || (this.pending = e, window.clearTimeout(this.timer), this.timer = window.setTimeout(() => this.flush(), this.delay));
2143
+ }
2144
+ flush() {
2145
+ if (window.clearTimeout(this.timer), this.pending === null) return;
2146
+ const e = this.pending;
2147
+ this.pending = null;
2148
+ try {
2149
+ e ? me()?.setItem(this.key, JSON.stringify({ html: e, time: Date.now() })) : me()?.removeItem(this.key);
2150
+ } catch {
2151
+ }
2152
+ }
2153
+ /** Removes the draft (after the content was saved on the server). */
2154
+ clear() {
2155
+ window.clearTimeout(this.timer), this.pending = null;
2156
+ try {
2157
+ me()?.removeItem(this.key);
2158
+ } catch {
2159
+ }
2160
+ }
2161
+ destroy() {
2162
+ this.flush(), this.hideBar(), window.removeEventListener("pagehide", this.onPageHide);
2163
+ }
2164
+ hideBar() {
2165
+ this.bar?.remove(), this.bar = null;
2166
+ }
2167
+ read() {
2168
+ try {
2169
+ const e = me()?.getItem(this.key);
2170
+ if (!e) return null;
2171
+ const n = JSON.parse(e);
2172
+ return typeof n?.html != "string" || typeof n.time != "number" ? null : Date.now() - n.time > this.expires * 864e5 ? (me()?.removeItem(this.key), null) : n;
2173
+ } catch {
2174
+ return null;
2175
+ }
2176
+ }
2177
+ }
2178
+ const re = /* @__PURE__ */ new WeakMap(), zt = (t) => t === void 0 ? void 0 : typeof t == "number" ? `${t}px` : t;
2179
+ function pi(t) {
2180
+ return t === !1 ? [] : t === void 0 || t === "default" ? Pr : Array.isArray(t) ? t : t.split(/\s+/).filter(Boolean);
2181
+ }
2182
+ const ie = class ie {
1717
2183
  constructor(e, n = {}) {
1718
- if (this.listeners = /* @__PURE__ */ new Map(), this.notice = null, this.noticeTimer = 0, this.onFormSubmit = () => this.syncTarget(), this.onKeydown = (i) => {
1719
- 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;
2184
+ if (this.listeners = /* @__PURE__ */ new Map(), this.notice = null, this.noticeTimer = 0, this.onFormSubmit = () => {
2185
+ this.syncTarget(), this.autosave?.clear();
2186
+ }, this.onKeydown = (d) => {
2187
+ d.key === "Escape" && this.fullscreen && this.toggleFullscreen();
2188
+ }, this.sourceMode = !1, this.plainPaste = !1, this.fullscreen = !1, this.destroyed = !1, re.has(e)) throw new Error("[WDS Editor] This element already has an editor. Use WDSEditor.get() or destroy() first.");
2189
+ this.target = e, this.options = n, this.t = qr(n.language), this.readOnly = !!n.readOnly, this.textarea = e instanceof HTMLTextAreaElement ? e : null, this.originalContent = this.textarea ? this.textarea.value : e.innerHTML;
1722
2190
  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({
1727
- schema: p,
1728
- doc: ge(r),
2191
+ if (this.root = document.createElement("div"), this.root.className = "wds-editor", this.root.dataset.theme = n.theme ?? "light", typeof n.language != "object") {
2192
+ const d = on(n.language);
2193
+ this.root.lang = d;
2194
+ const u = n.dir ?? "auto";
2195
+ u === "rtl" || u === "auto" && jr(d) ? this.root.dir = "rtl" : u === "ltr" && (this.root.dir = "ltr");
2196
+ } else n.dir && n.dir !== "auto" && (this.root.dir = n.dir);
2197
+ this.fileManager = n.fileManager?.listUrl ? new ti(this.root, new Zr(n.fileManager), this.t) : null, this.contentWrap = document.createElement("div"), this.contentWrap.className = "wds-content-wrap";
2198
+ const i = zt(n.height);
2199
+ i ? (this.contentWrap.style.height = i, this.root.classList.add("wds-fixed-height")) : this.contentWrap.style.minHeight = zt(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);
2200
+ const s = pn.create({
2201
+ schema: f,
2202
+ doc: ke(r),
1729
2203
  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 })
2204
+ An(),
2205
+ at({ Tab: Lr, "Shift-Tab": Sr, "Mod-f": () => (this.openFind(), !0) }),
2206
+ di(),
2207
+ Ar(),
2208
+ Tr({ link: () => (this.openLinkDialog(), !0) }),
2209
+ Cr(),
2210
+ yn(),
2211
+ Ir(n.placeholder ?? ""),
2212
+ Dr(),
2213
+ Gn(),
2214
+ jn({ class: "wds-dropcursor", color: !1 })
1740
2215
  ]
1741
- }), l = {
2216
+ }), o = ai({ css: n.contentCss, style: n.contentStyle });
2217
+ (o || n.contentClass !== void 0) && this.root.classList.add("wds-site-styles"), o && this.contentWrap.classList.add(o.className);
2218
+ const c = ["wds-content", n.contentClass?.trim()].filter(Boolean).join(" "), a = {
1742
2219
  onEdit: () => this.openImageUrlDialog(),
1743
2220
  resizeLabel: this.t.resizeImage,
1744
2221
  captionPlaceholder: this.t.captionPlaceholder
1745
2222
  };
1746
- this.view = new Vt(this.contentWrap, {
2223
+ this.view = new gn(this.contentWrap, {
1747
2224
  state: s,
1748
2225
  editable: () => !this.readOnly,
1749
2226
  attributes: {
1750
- class: "wds-content",
2227
+ class: c,
1751
2228
  role: "textbox",
1752
2229
  "aria-multiline": "true",
1753
2230
  "aria-label": this.t.editorLabel
1754
2231
  },
1755
- dispatchTransaction: (i) => this.dispatch(i),
1756
- transformPastedHTML: An,
1757
- handlePaste: (i, a) => {
1758
- const c = a.clipboardData;
1759
- if (this.plainPaste && c) {
1760
- const m = c.getData("text/plain");
1761
- if (m)
1762
- return i.dispatch(i.state.tr.replaceSelection(Tr(m)).scrollIntoView()), !0;
2232
+ dispatchTransaction: (d) => this.dispatch(d),
2233
+ transformPastedHTML: Yn,
2234
+ handlePaste: (d, u) => {
2235
+ const m = u.clipboardData;
2236
+ if (this.plainPaste && m) {
2237
+ const b = m.getData("text/plain");
2238
+ if (b)
2239
+ return d.dispatch(d.state.tr.replaceSelection(gi(b)).scrollIntoView()), !0;
1763
2240
  }
1764
- if (!c?.files.length || !this.canUploadInline() || c.getData("text/plain")) return !1;
1765
- const u = [...c.files].filter((m) => m.type.startsWith("image/"));
1766
- return u.length ? (this.uploadFiles(u), !0) : !1;
2241
+ if (!m?.files.length || !this.canUploadInline() || m.getData("text/plain")) return !1;
2242
+ const p = [...m.files].filter((b) => b.type.startsWith("image/"));
2243
+ return p.length ? (this.uploadFiles(p), !0) : !1;
1767
2244
  },
1768
- handleDrop: (i, a, c, u) => {
1769
- const m = a.dataTransfer?.files;
1770
- if (u || !m?.length || !this.canUploadInline()) return !1;
1771
- const g = i.posAtCoords({ left: a.clientX, top: a.clientY })?.pos;
1772
- return a.preventDefault(), this.uploadFiles([...m], g), !0;
2245
+ handleDrop: (d, u, m, p) => {
2246
+ const b = u.dataTransfer?.files;
2247
+ if (p || !b?.length || !this.canUploadInline()) return !1;
2248
+ const x = d.posAtCoords({ left: u.clientX, top: u.clientY })?.pos;
2249
+ return u.preventDefault(), this.uploadFiles([...b], x), !0;
1773
2250
  },
1774
2251
  nodeViews: {
1775
- image: (i, a, c) => new ur(i, a, c, l),
1776
- figure: (i, a, c) => new hr(i, a, c, l)
2252
+ image: (d, u, m) => new Wr(d, u, m, a),
2253
+ figure: (d, u, m) => new _r(d, u, m, a),
2254
+ video: (d) => new er(d, () => this.openVideoDialog())
1777
2255
  },
1778
2256
  handleDOMEvents: {
1779
2257
  focus: () => (this.root.classList.add("is-focused"), this.emit("focus"), !1),
1780
2258
  blur: () => (this.root.classList.remove("is-focused"), this.emit("blur"), !1)
1781
2259
  }
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);
1783
- const d = document.createElement("div");
1784
- 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
- 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);
2260
+ }), this.contentWrap.append(this.sourceArea), this.toolbar = Ur(this, pi(n.toolbar), this.t), this.toolbar.element.childElementCount && this.toolbar.element.firstElementChild.childElementCount && this.root.append(this.toolbar.element), this.findPanel = new hi(this.view, this.t, () => this.view.focus()), this.root.append(this.findPanel.element, this.contentWrap), this.autosave = n.autosave ? new mi(
2261
+ n.autosave === !0 ? {} : n.autosave,
2262
+ `${location.pathname}#${e.id || e.getAttribute("name") || "editor"}`,
2263
+ this.root,
2264
+ this.contentWrap,
2265
+ this.t,
2266
+ (d) => this.setHTML(d)
2267
+ ) : null;
2268
+ const l = document.createElement("div");
2269
+ if (l.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"), l.append(this.counter)), n.branding !== !1) {
2270
+ const d = document.createElement("a");
2271
+ d.className = "wds-branding", d.href = "https://webdevsnippets.com/wds-editor", d.target = "_blank", d.rel = "noopener", d.innerHTML = `${bi(this.t.poweredBy)} <strong>WDS Editor</strong>`, l.append(d);
1787
2272
  }
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");
2273
+ l.childElementCount && this.root.append(l), 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), re.set(e, this), this.lastHtml = this.getHTML(), this.autosave?.check(this.lastHtml), this.syncTarget(), this.refresh(), this.emit("init");
1789
2274
  }
1790
2275
  /** Creates (or returns the existing) editor for the first element matching options.selector. */
1791
2276
  static init(e) {
1792
2277
  const n = typeof e.selector == "string" ? document.querySelector(e.selector) : e.selector;
1793
2278
  if (!n) throw new Error(`[WDS Editor] No element matches "${String(e.selector)}".`);
1794
- return ne.get(n) ?? new re(n, e);
2279
+ return re.get(n) ?? new ie(n, e);
1795
2280
  }
1796
2281
  /** Creates editors for every element matching options.selector. */
1797
2282
  static initAll(e) {
1798
- return [...document.querySelectorAll(e.selector)].map((n) => ne.get(n) ?? new re(n, e));
2283
+ return [...document.querySelectorAll(e.selector)].map((n) => re.get(n) ?? new ie(n, e));
1799
2284
  }
1800
2285
  /** Returns the editor attached to an element (or selector), if any. */
1801
2286
  static get(e) {
1802
2287
  const n = typeof e == "string" ? document.querySelector(e) : e;
1803
- return n ? ne.get(n) : void 0;
2288
+ return n ? re.get(n) : void 0;
1804
2289
  }
1805
2290
  // ---------- content ----------
1806
2291
  getHTML() {
1807
- return this.sourceMode && this.applySource(), be(this.view.state.doc);
2292
+ return this.sourceMode && this.applySource(), Me(this.view.state.doc);
1808
2293
  }
1809
2294
  /** Replaces the whole content. The change can be undone. */
1810
2295
  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)));
2296
+ this.sourceMode && (this.sourceArea.value = At(e));
2297
+ const n = ke(e), r = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, n.content);
2298
+ this.dispatch(r.setSelection(be.atStart(r.doc)));
1814
2299
  }
1815
2300
  /** Inserts HTML at the cursor (replacing the selection). */
1816
2301
  insertHTML(e) {
1817
- const n = ge(e), r = Dt.maxOpen(n.content);
2302
+ const n = ke(e), r = qt.maxOpen(n.content);
1818
2303
  this.dispatch(this.view.state.tr.replaceSelection(r).scrollIntoView());
1819
2304
  }
1820
2305
  getText() {
@@ -1825,7 +2310,7 @@ const re = class re {
1825
2310
  `);
1826
2311
  }
1827
2312
  isEmpty() {
1828
- return $t(this.view.state.doc);
2313
+ return Qt(this.view.state.doc);
1829
2314
  }
1830
2315
  // ---------- state ----------
1831
2316
  focus() {
@@ -1844,17 +2329,31 @@ const re = class re {
1844
2329
  return this.view.focus(), n;
1845
2330
  }
1846
2331
  undo() {
1847
- this.exec(At);
2332
+ this.exec(Wt);
1848
2333
  }
1849
2334
  redo() {
1850
- this.exec(Re);
2335
+ this.exec(je);
1851
2336
  }
1852
2337
  // ---------- views ----------
1853
2338
  isSourceMode() {
1854
2339
  return this.sourceMode;
1855
2340
  }
1856
2341
  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();
2342
+ 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.findPanel.close(), this.sourceArea.value = At(Me(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();
2343
+ }
2344
+ /** Removes the autosave draft, e.g. after saving with fetch instead of a form submit. */
2345
+ clearDraft() {
2346
+ this.autosave?.clear();
2347
+ }
2348
+ /** Opens the find and replace bar (Ctrl+F / Cmd+F inside the editor). */
2349
+ openFind() {
2350
+ this.sourceMode || (this.findPanel.open(), this.refresh());
2351
+ }
2352
+ closeFind() {
2353
+ this.findPanel.close();
2354
+ }
2355
+ isFindOpen() {
2356
+ return this.findPanel.isOpen;
1858
2357
  }
1859
2358
  isFullscreen() {
1860
2359
  return this.fullscreen;
@@ -1865,38 +2364,75 @@ const re = class re {
1865
2364
  // ---------- link dialog ----------
1866
2365
  openLinkDialog() {
1867
2366
  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, {
1870
- title: i.link,
1871
- closeLabel: i.close,
1872
- submitLabel: i.save,
1873
- cancelLabel: i.cancel,
2367
+ const e = this.view.state, n = et(e), { from: r, to: i, empty: s } = e.selection, o = s ? "" : e.doc.textBetween(r, i, " "), c = s && !n, a = this.t;
2368
+ ze(this.root, {
2369
+ title: a.link,
2370
+ closeLabel: a.close,
2371
+ submitLabel: a.save,
2372
+ cancelLabel: a.cancel,
1874
2373
  fields: [
1875
- { name: "href", label: i.linkUrl, type: "url", value: n?.href ?? "", placeholder: "https://" },
1876
- ...d ? [{ name: "text", label: i.linkText, type: "text", value: l }] : [],
1877
- { name: "title", label: i.linkTitle, type: "text", value: n?.title ?? "" },
1878
- { name: "newTab", label: i.linkNewTab, type: "checkbox", value: n?.target === "_blank" }
2374
+ { name: "href", label: a.linkUrl, type: "url", value: n?.href ?? "", placeholder: "https://" },
2375
+ ...c ? [{ name: "text", label: a.linkText, type: "text", value: o }] : [],
2376
+ { name: "title", label: a.linkTitle, type: "text", value: n?.title ?? "" },
2377
+ { name: "newTab", label: a.linkNewTab, type: "checkbox", value: n?.target === "_blank" }
1879
2378
  ],
1880
- extraAction: n ? { label: i.remove, onClick: () => this.removeLink() } : void 0,
1881
- validate: (a) => ot(String(a.href)) ? null : i.linkInvalid,
1882
- 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;
2379
+ extraAction: n ? { label: a.remove, onClick: () => this.removeLink() } : void 0,
2380
+ validate: (l) => bt(String(l.href)) ? null : a.linkInvalid,
2381
+ onSubmit: (l) => {
2382
+ const d = bt(String(l.href)), u = { href: d, title: String(l.title).trim() || null, target: l.newTab ? "_blank" : null }, m = f.marks.link.create(u), p = this.view.state;
2383
+ let b = p.tr;
1885
2384
  if (n)
1886
- v = v.removeMark(n.from, n.to, p.marks.link).addMark(n.from, n.to, m);
1887
- else if (d) {
1888
- const D = String(a.text ?? "").trim() || c.replace(/^mailto:/, "");
1889
- v = v.replaceSelectionWith(p.text(D, [m]), !1);
2385
+ b = b.removeMark(n.from, n.to, f.marks.link).addMark(n.from, n.to, m);
2386
+ else if (c) {
2387
+ const x = String(l.text ?? "").trim() || d.replace(/^mailto:/, "");
2388
+ b = b.replaceSelectionWith(f.text(x, [m]), !1);
1890
2389
  } else
1891
- v = v.addMark(g.selection.from, g.selection.to, m);
1892
- this.dispatch(v.scrollIntoView());
2390
+ b = b.addMark(p.selection.from, p.selection.to, m);
2391
+ this.dispatch(b.scrollIntoView());
1893
2392
  },
1894
2393
  onClose: () => this.view.focus()
1895
2394
  });
1896
2395
  }
1897
2396
  removeLink() {
1898
- const e = We(this.view.state);
1899
- e && this.dispatch(this.view.state.tr.removeMark(e.from, e.to, p.marks.link));
2397
+ const e = et(this.view.state);
2398
+ e && this.dispatch(this.view.state.tr.removeMark(e.from, e.to, f.marks.link));
2399
+ }
2400
+ // ---------- video ----------
2401
+ /**
2402
+ * Inserts a YouTube or Vimeo video (watch page, short link or embed URL) at the cursor.
2403
+ * Returns false for other addresses.
2404
+ */
2405
+ insertVideo(e, n = {}) {
2406
+ const r = Le(e);
2407
+ if (!r || this.readOnly || this.sourceMode) return !1;
2408
+ const i = f.nodes.video.create({ src: r, title: n.title?.trim() ?? "", width: n.width ?? null }), s = this.view.state.tr.replaceSelectionWith(i);
2409
+ return this.dispatch(s.scrollIntoView()), !0;
2410
+ }
2411
+ /** Video button: edits the selected video or asks for a YouTube / Vimeo address. */
2412
+ openVideoDialog() {
2413
+ if (this.readOnly || this.sourceMode) return;
2414
+ const e = this.t, n = en(this.view.state), r = n?.node.attrs ?? {};
2415
+ ze(this.root, {
2416
+ title: n ? e.videoEdit : e.video,
2417
+ closeLabel: e.close,
2418
+ submitLabel: n ? e.save : e.insert,
2419
+ cancelLabel: e.cancel,
2420
+ fields: [
2421
+ { name: "url", label: e.videoUrl, type: "url", value: r.src ?? "", placeholder: "https://www.youtube.com/watch?v=…", hint: e.videoHint },
2422
+ { name: "title", label: e.videoTitle, type: "text", value: r.title ?? "" },
2423
+ { name: "width", label: e.imageWidth, type: "number", value: r.width ? String(r.width) : "", placeholder: "560" }
2424
+ ],
2425
+ validate: (i) => Le(String(i.url)) ? null : e.videoInvalid,
2426
+ onSubmit: (i) => {
2427
+ const s = parseInt(String(i.width), 10), o = { src: Le(String(i.url)), title: String(i.title).trim(), width: s > 0 ? Math.min(s, 4e3) : null };
2428
+ if (n) {
2429
+ const c = this.view.state.tr.setNodeMarkup(n.pos, void 0, o);
2430
+ this.dispatch(c.setSelection(Z.create(c.doc, n.pos)).scrollIntoView());
2431
+ } else
2432
+ this.insertVideo(o.src, o);
2433
+ },
2434
+ onClose: () => this.view.focus()
2435
+ });
1900
2436
  }
1901
2437
  // ---------- images and files ----------
1902
2438
  /** True when a file manager (listUrl) is configured. */
@@ -1907,15 +2443,15 @@ const re = class re {
1907
2443
  insertImage(e) {
1908
2444
  const n = q(e.src);
1909
2445
  if (!n || this.readOnly || this.sourceMode) return !1;
1910
- const r = p.nodes.image.create({
2446
+ const r = f.nodes.image.create({
1911
2447
  src: n,
1912
2448
  alt: e.alt ?? "",
1913
2449
  title: e.title ?? null,
1914
2450
  width: e.width ?? null,
1915
2451
  height: e.width ? e.height ?? null : null,
1916
2452
  align: e.align ?? null
1917
- }), o = this.view.state.tr.replaceSelectionWith(r);
1918
- return e.caption && bt(o, o.selection.from - 1, r.attrs), this.dispatch(o.scrollIntoView()), !0;
2453
+ }), i = this.view.state.tr.replaceSelectionWith(r);
2454
+ return e.caption && Dt(i, i.selection.from - 1, r.attrs), this.dispatch(i.scrollIntoView()), !0;
1919
2455
  }
1920
2456
  /**
1921
2457
  * Image button: edits the selected image, otherwise opens the file manager (when configured)
@@ -1923,7 +2459,7 @@ const re = class re {
1923
2459
  */
1924
2460
  openImageDialog() {
1925
2461
  if (this.readOnly || this.sourceMode) return;
1926
- qe(this.view.state) || !this.fileManager ? this.openImageUrlDialog() : this.openFileManager("image");
2462
+ tt(this.view.state) || !this.fileManager ? this.openImageUrlDialog() : this.openFileManager("image");
1927
2463
  }
1928
2464
  /** Opens the file manager. "image" lists images (accept option, default image/*), "file" lists every file. */
1929
2465
  openFileManager(e = "image") {
@@ -1932,16 +2468,16 @@ const re = class re {
1932
2468
  accept: e === "image" ? this.options.fileManager?.accept ?? "image/*" : "",
1933
2469
  onFromUrl: e === "image" ? () => this.openImageUrlDialog() : void 0,
1934
2470
  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);
2471
+ onPick: ({ file: n, alt: r, width: i, align: s, text: o, caption: c }) => {
2472
+ e === "image" && pe(n) ? this.insertImage({ src: n.url, alt: r, width: i, align: s, caption: c }) : this.insertFileLink(n, o), this.emit("fileSelect", n);
1937
2473
  },
1938
2474
  onClose: () => this.view.focus()
1939
2475
  });
1940
2476
  }
1941
2477
  /** Dialog for an image by URL, or for editing the selected image (alt text, width, alignment). */
1942
2478
  openImageUrlDialog() {
1943
- const e = this.t, n = qe(this.view.state), r = n?.attrs ?? {};
1944
- wt(this.root, {
2479
+ const e = this.t, n = tt(this.view.state), r = n?.attrs ?? {};
2480
+ ze(this.root, {
1945
2481
  title: n ? e.imageEdit : e.image,
1946
2482
  closeLabel: e.close,
1947
2483
  submitLabel: n ? e.save : e.insert,
@@ -1964,19 +2500,19 @@ const re = class re {
1964
2500
  },
1965
2501
  { name: "caption", label: e.caption, type: "checkbox", value: !!n?.figure }
1966
2502
  ],
1967
- validate: (o) => q(String(o.src)) && !/^(mailto|tel):/i.test(String(o.src).trim()) ? null : e.imageInvalid,
1968
- onSubmit: (o) => {
1969
- const s = parseInt(String(o.width), 10), l = {
1970
- src: q(String(o.src)),
1971
- alt: String(o.alt).trim(),
2503
+ validate: (i) => q(String(i.src)) && !/^(mailto|tel):/i.test(String(i.src).trim()) ? null : e.imageInvalid,
2504
+ onSubmit: (i) => {
2505
+ const s = parseInt(String(i.width), 10), o = {
2506
+ src: q(String(i.src)),
2507
+ alt: String(i.alt).trim(),
1972
2508
  width: s > 0 ? s : null,
1973
- align: String(o.align) || null
1974
- }, d = !!o.caption;
2509
+ align: String(i.align) || null
2510
+ }, c = !!i.caption;
1975
2511
  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());
2512
+ const a = o.width && o.width === r.width ? r.height ?? null : null, l = { ...r, ...o, height: a }, d = this.view.state.tr;
2513
+ c && !n.figure ? Dt(d, n.pos, l) : !c && n.figure ? kr(d, n.pos, n.node, l) : d.setNodeMarkup(n.pos, void 0, l).setSelection(Z.create(d.doc, n.pos)), this.dispatch(d.scrollIntoView());
1978
2514
  } else
1979
- this.insertImage({ ...l, caption: d });
2515
+ this.insertImage({ ...o, caption: c });
1980
2516
  },
1981
2517
  onClose: () => this.view.focus()
1982
2518
  });
@@ -1986,46 +2522,46 @@ const re = class re {
1986
2522
  openTableMenu(e) {
1987
2523
  if (this.readOnly || this.sourceMode) return;
1988
2524
  const n = this.t, r = this.view.state;
1989
- if (!pe(r)) {
1990
- mr(
2525
+ if (!we(r)) {
2526
+ $r(
1991
2527
  e,
1992
2528
  this.root,
1993
2529
  n.tableInsert,
1994
- (l, d) => V(n.tableSize, { rows: String(l), cols: String(d) }),
1995
- (l, d) => this.exec(Yn(l, d))
2530
+ (o, c) => z(n.tableSize, { rows: String(o), cols: String(c) }),
2531
+ (o, c) => this.exec(xr(o, c))
1996
2532
  );
1997
2533
  return;
1998
2534
  }
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),
2535
+ const i = (o, c, a = !1) => ({ label: o, danger: a, enabled: c(r), run: () => this.exec(c) }), s = [
2536
+ i(n.rowAbove, Tn),
2537
+ i(n.rowBelow, jt),
2538
+ i(n.colLeft, Cn),
2539
+ i(n.colRight, In),
2004
2540
  "|",
2005
- o(n.deleteRow, cn),
2006
- o(n.deleteCol, dn),
2541
+ i(n.deleteRow, Dn),
2542
+ i(n.deleteCol, Nn),
2007
2543
  "|",
2008
- o(n.headerRow, un),
2009
- o(n.headerCol, hn),
2010
- o(n.mergeCells, pn),
2011
- o(n.splitCell, mn),
2544
+ i(n.headerRow, Rn),
2545
+ i(n.headerCol, $n),
2546
+ i(n.mergeCells, On),
2547
+ i(n.splitCell, Hn),
2012
2548
  "|",
2013
- o(n.deleteTable, fn, !0)
2549
+ i(n.deleteTable, Pn, !0)
2014
2550
  ];
2015
- pr(e, this.root, s, n.table);
2551
+ Rr(e, this.root, s, n.table);
2016
2552
  }
2017
2553
  // ---------- colors ----------
2018
2554
  /** Opens the text color or highlight palette under the given toolbar button. */
2019
2555
  openColorPicker(e, n) {
2020
2556
  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);
2022
- fr(n, this.root, {
2557
+ const r = this.t, s = ((e === "textColor" ? this.options.colors?.text : this.options.colors?.highlight) ?? (e === "textColor" ? tr : nr)).map((o) => typeof o == "string" ? { color: o, name: o } : o).map((o) => ({ color: se(o.color), label: r[o.name] ?? o.name })).filter((o) => !!o.color);
2558
+ Or(n, this.root, {
2023
2559
  label: e === "textColor" ? r.textColor : r.highlight,
2024
2560
  removeLabel: e === "textColor" ? r.removeColor : r.removeHighlight,
2025
2561
  swatches: s,
2026
2562
  columns: e === "textColor" ? 5 : 6,
2027
- current: Ge(this.view.state, e),
2028
- onPick: (l) => this.exec(Qn(e, l))
2563
+ current: nt(this.view.state, e),
2564
+ onPick: (o) => this.exec(Er(e, o))
2029
2565
  });
2030
2566
  }
2031
2567
  // ---------- paste ----------
@@ -2040,8 +2576,8 @@ const re = class re {
2040
2576
  insertFileLink(e, n) {
2041
2577
  const r = q(e.url);
2042
2578
  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());
2579
+ const i = f.marks.link.create({ href: r }), s = this.view.state, o = s.selection.empty ? s.tr.replaceSelectionWith(f.text(n || e.name, [i]), !1) : s.tr.addMark(s.selection.from, s.selection.to, i);
2580
+ this.dispatch(o.scrollIntoView());
2045
2581
  }
2046
2582
  canUploadInline() {
2047
2583
  return !!this.fileManager?.api.canUpload && !this.readOnly && !this.sourceMode;
@@ -2053,19 +2589,19 @@ const re = class re {
2053
2589
  uploadFiles(e, n) {
2054
2590
  if (!this.canUploadInline()) return;
2055
2591
  const r = this.fileManager.api;
2056
- for (const o of e) {
2592
+ for (const i of e) {
2057
2593
  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) => {
2594
+ let o = this.view.state.tr;
2595
+ n === void 0 && !o.selection.empty && (o = o.deleteSelection());
2596
+ const c = n ?? o.selection.from;
2597
+ this.dispatch(o.setMeta(Q, { add: { id: s, pos: c } })), r.upload(i, this.fileManager.path).then((a) => {
2062
2598
  if (this.destroyed) return;
2063
- const a = or(this.view.state, s);
2064
- 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);
2067
- }).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 })));
2599
+ const l = Nr(this.view.state, s);
2600
+ if (l === null) return;
2601
+ const d = pe(a) ? f.nodes.image.create({ src: a.url, alt: "" }) : f.text(a.name, [f.marks.link.create({ href: a.url })]);
2602
+ this.dispatch(this.view.state.tr.replaceWith(l, l, d).setMeta(Q, { remove: { id: s } })), this.emit("upload", a);
2603
+ }).catch((a) => {
2604
+ this.destroyed || (this.dispatch(this.view.state.tr.setMeta(Q, { remove: { id: s } })), this.showNotice(z(this.t.fmUploadFailed, { name: i.name, error: a.message })));
2069
2605
  });
2070
2606
  }
2071
2607
  }
@@ -2085,69 +2621,69 @@ const re = class re {
2085
2621
  if (this.destroyed) return;
2086
2622
  this.emit("destroy");
2087
2623
  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();
2624
+ this.destroyed = !0, window.clearTimeout(this.noticeTimer), this.autosave?.destroy(), tn(), 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, re.delete(this.target), this.listeners.clear();
2089
2625
  }
2090
2626
  // ---------- internals ----------
2091
2627
  dispatch(e) {
2092
2628
  if (this.destroyed) return;
2093
2629
  const n = this.view.state.apply(e);
2094
2630
  if (this.view.updateState(n), e.docChanged) {
2095
- const r = be(n.doc);
2096
- r !== this.lastHtml && (this.lastHtml = r, this.syncTarget(r), this.options.onChange?.(r, this), this.emit("change"));
2631
+ const r = Me(n.doc);
2632
+ r !== this.lastHtml && (this.lastHtml = r, this.syncTarget(r), this.autosave?.schedule(r), this.options.onChange?.(r, this), this.emit("change"));
2097
2633
  }
2098
2634
  this.refresh();
2099
2635
  }
2100
2636
  applySource() {
2101
- const e = this.sourceArea.value, n = ge(e);
2637
+ const e = this.sourceArea.value, n = ke(e);
2102
2638
  if (n.eq(this.view.state.doc)) return;
2103
- 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");
2639
+ const r = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, n.content), i = this.view.state.apply(r);
2640
+ this.view.updateState(i), this.lastHtml = Me(i.doc), this.syncTarget(this.lastHtml), this.autosave?.schedule(this.lastHtml), this.options.onChange?.(this.lastHtml, this), this.emit("change");
2105
2641
  }
2106
2642
  syncTarget(e) {
2107
2643
  this.textarea && (this.textarea.value = e ?? this.getHTML());
2108
2644
  }
2109
2645
  refresh() {
2110
2646
  const e = this.view.state;
2111
- if (this.toolbar.update(e), this.counter) {
2112
- const n = this.getText(), r = (n.match(/[\p{L}\p{N}][\p{L}\p{N}'’-]*/gu) ?? []).length, o = n.replace(/\n/g, "").length;
2113
- this.counter.textContent = `${r} ${this.t.words} · ${o} ${this.t.characters}`;
2647
+ if (this.toolbar.update(e), this.findPanel?.update(e, !this.readOnly), this.counter) {
2648
+ const n = this.getText(), r = (n.match(/[\p{L}\p{N}][\p{L}\p{N}'’-]*/gu) ?? []).length, i = n.replace(/\n/g, "").length;
2649
+ this.counter.textContent = `${r} ${this.t.words} · ${i} ${this.t.characters}`;
2114
2650
  }
2115
2651
  }
2116
2652
  emit(e, n) {
2117
2653
  this.listeners.get(e)?.forEach((r) => {
2118
2654
  try {
2119
2655
  r(this, n);
2120
- } catch (o) {
2121
- console.error(o);
2656
+ } catch (i) {
2657
+ console.error(i);
2122
2658
  }
2123
2659
  });
2124
2660
  }
2125
2661
  };
2126
- re.version = "1.0.1", re.addLanguage = br;
2127
- let Lt = re;
2128
- function Tr(t) {
2662
+ ie.version = "1.2.0", ie.addLanguage = sn;
2663
+ let Ft = ie;
2664
+ function gi(t) {
2129
2665
  const e = t.replace(/\r\n?/g, `
2130
2666
  `).split(/\n{2,}/).map((n) => {
2131
- const o = n.split(`
2132
- `).flatMap((s, l) => [...l ? [p.nodes.hard_break.create()] : [], ...s ? [p.text(s)] : []]);
2133
- return p.nodes.paragraph.create(null, o);
2667
+ const i = n.split(`
2668
+ `).flatMap((s, o) => [...o ? [f.nodes.hard_break.create()] : [], ...s ? [f.text(s)] : []]);
2669
+ return f.nodes.paragraph.create(null, i);
2134
2670
  });
2135
- return new Dt(Ct.from(e), 1, 1);
2671
+ return new qt(Vt.from(e), 1, 1);
2136
2672
  }
2137
- function Cr(t) {
2673
+ function bi(t) {
2138
2674
  const e = document.createElement("span");
2139
2675
  return e.textContent = t, e.innerHTML;
2140
2676
  }
2141
2677
  export {
2142
- ar as DEFAULT_TOOLBAR,
2143
- Lt as WDSEditor,
2144
- br as addLanguage,
2145
- ve as en,
2146
- ue as isImage,
2147
- yt as matchesAccept,
2148
- vr as normalizeList,
2149
- p as schema,
2150
- ir as toolbarItems,
2151
- gr as tr
2678
+ Pr as DEFAULT_TOOLBAR,
2679
+ Ft as WDSEditor,
2680
+ sn as addLanguage,
2681
+ Ee as en,
2682
+ pe as isImage,
2683
+ $t as matchesAccept,
2684
+ Yr as normalizeList,
2685
+ f as schema,
2686
+ Hr as toolbarItems,
2687
+ Vr as tr
2152
2688
  };
2153
2689
  //# sourceMappingURL=wds-editor.js.map