wysio 0.0.1 → 0.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README.md +241 -3
  4. package/dist/auto-init.d.ts +12 -0
  5. package/dist/auto-init.d.ts.map +1 -0
  6. package/dist/cdn-full.d.ts +3 -0
  7. package/dist/cdn-full.d.ts.map +1 -0
  8. package/dist/cdn.d.ts +2 -0
  9. package/dist/cdn.d.ts.map +1 -0
  10. package/dist/commands.d.ts +19 -0
  11. package/dist/commands.d.ts.map +1 -0
  12. package/dist/content.d.ts +31 -0
  13. package/dist/content.d.ts.map +1 -0
  14. package/dist/editor.d.ts +158 -0
  15. package/dist/editor.d.ts.map +1 -0
  16. package/dist/emitter.d.ts +9 -0
  17. package/dist/emitter.d.ts.map +1 -0
  18. package/dist/format-html.d.ts +7 -0
  19. package/dist/format-html.d.ts.map +1 -0
  20. package/dist/i18n.d.ts +16 -0
  21. package/dist/i18n.d.ts.map +1 -0
  22. package/dist/icons.d.ts +34 -0
  23. package/dist/icons.d.ts.map +1 -0
  24. package/dist/index.d.ts +17 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/locales/nl.d.ts +81 -0
  27. package/dist/locales/nl.d.ts.map +1 -0
  28. package/dist/markdown/index.d.ts +17 -0
  29. package/dist/markdown/index.d.ts.map +1 -0
  30. package/dist/markdown.js +179 -0
  31. package/dist/markdown.js.map +1 -0
  32. package/dist/messages.d.ts +83 -0
  33. package/dist/messages.d.ts.map +1 -0
  34. package/dist/plugin.d.ts +94 -0
  35. package/dist/plugin.d.ts.map +1 -0
  36. package/dist/plugins/alignment.d.ts +10 -0
  37. package/dist/plugins/alignment.d.ts.map +1 -0
  38. package/dist/plugins/base.d.ts +7 -0
  39. package/dist/plugins/base.d.ts.map +1 -0
  40. package/dist/plugins/blocks.d.ts +4 -0
  41. package/dist/plugins/blocks.d.ts.map +1 -0
  42. package/dist/plugins/clear-formatting.d.ts +10 -0
  43. package/dist/plugins/clear-formatting.d.ts.map +1 -0
  44. package/dist/plugins/color.d.ts +36 -0
  45. package/dist/plugins/color.d.ts.map +1 -0
  46. package/dist/plugins/heading.d.ts +3 -0
  47. package/dist/plugins/heading.d.ts.map +1 -0
  48. package/dist/plugins/history.d.ts +2 -0
  49. package/dist/plugins/history.d.ts.map +1 -0
  50. package/dist/plugins/image.d.ts +56 -0
  51. package/dist/plugins/image.d.ts.map +1 -0
  52. package/dist/plugins/index.d.ts +29 -0
  53. package/dist/plugins/index.d.ts.map +1 -0
  54. package/dist/plugins/link.d.ts +15 -0
  55. package/dist/plugins/link.d.ts.map +1 -0
  56. package/dist/plugins/lists.d.ts +2 -0
  57. package/dist/plugins/lists.d.ts.map +1 -0
  58. package/dist/plugins/marks.d.ts +7 -0
  59. package/dist/plugins/marks.d.ts.map +1 -0
  60. package/dist/plugins/paste.d.ts +9 -0
  61. package/dist/plugins/paste.d.ts.map +1 -0
  62. package/dist/plugins/placeholder.d.ts +3 -0
  63. package/dist/plugins/placeholder.d.ts.map +1 -0
  64. package/dist/plugins/source.d.ts +5 -0
  65. package/dist/plugins/source.d.ts.map +1 -0
  66. package/dist/plugins/table.d.ts +14 -0
  67. package/dist/plugins/table.d.ts.map +1 -0
  68. package/dist/registry-BfhH2s8N.js +19 -0
  69. package/dist/registry-BfhH2s8N.js.map +1 -0
  70. package/dist/registry.d.ts +10 -0
  71. package/dist/registry.d.ts.map +1 -0
  72. package/dist/schema.d.ts +5 -0
  73. package/dist/schema.d.ts.map +1 -0
  74. package/dist/style.css +824 -0
  75. package/dist/toolbar/toolbar.d.ts +56 -0
  76. package/dist/toolbar/toolbar.d.ts.map +1 -0
  77. package/dist/ui/menu.d.ts +20 -0
  78. package/dist/ui/menu.d.ts.map +1 -0
  79. package/dist/ui/popover.d.ts +29 -0
  80. package/dist/ui/popover.d.ts.map +1 -0
  81. package/dist/url.d.ts +23 -0
  82. package/dist/url.d.ts.map +1 -0
  83. package/dist/web-component.d.ts +21 -0
  84. package/dist/web-component.d.ts.map +1 -0
  85. package/dist/wysio.full.iife.js +72 -0
  86. package/dist/wysio.iife.js +49 -0
  87. package/dist/wysio.js +2668 -0
  88. package/dist/wysio.js.map +1 -0
  89. package/package.json +68 -6
  90. package/index.js +0 -1
package/dist/wysio.js ADDED
@@ -0,0 +1,2668 @@
1
+ import { baseKeymap as e, chainCommands as t, exitCode as n, lift as r, setBlockType as i, toggleMark as a, wrapIn as o } from "prosemirror-commands";
2
+ import { InputRule as s, inputRules as c, textblockTypeInputRule as l, undoInputRule as u, wrappingInputRule as d } from "prosemirror-inputrules";
3
+ import { keymap as f } from "prosemirror-keymap";
4
+ import { EditorState as ee, NodeSelection as te, Plugin as p, PluginKey as ne, TextSelection as re } from "prosemirror-state";
5
+ import { Decoration as ie, DecorationSet as ae, EditorView as oe } from "prosemirror-view";
6
+ import { DOMParser as se, DOMSerializer as ce, Node as le, Schema as ue } from "prosemirror-model";
7
+ import { n as de, r as m, t as fe } from "./registry-BfhH2s8N.js";
8
+ import { dropCursor as pe } from "prosemirror-dropcursor";
9
+ import { gapCursor as me } from "prosemirror-gapcursor";
10
+ import { liftListItem as he, sinkListItem as ge, splitListItem as _e, wrapInList as ve } from "prosemirror-schema-list";
11
+ import { history as ye, redo as be, undo as xe } from "prosemirror-history";
12
+ import { addColumnAfter as Se, addColumnBefore as Ce, addRowAfter as we, addRowBefore as Te, deleteColumn as Ee, deleteRow as De, deleteTable as Oe, goToNextCell as ke, isInTable as h, tableEditing as Ae } from "prosemirror-tables";
13
+ // src/content.ts
14
+ function g(e) {
15
+ let t = e ?? globalThis.document;
16
+ if (!t) throw Error("[wysio] A DOM document is required.");
17
+ return t;
18
+ }
19
+ function je(e, t, n) {
20
+ let r = new ((g(n).defaultView?.DOMParser) ?? globalThis.DOMParser)().parseFromString(t, "text/html").body;
21
+ return se.fromSchema(e).parse(r);
22
+ }
23
+ function Me(e, t, n) {
24
+ let r = g(n), i = r.createElement("div");
25
+ return i.appendChild(ce.fromSchema(e).serializeFragment(t.content, { document: r })), i.innerHTML;
26
+ }
27
+ function Ne(e, t, n) {
28
+ let r = g(n), i = r.createElement("div");
29
+ return i.appendChild(ce.fromSchema(e).serializeFragment(t.content, { document: r })), se.fromSchema(e).parse(i);
30
+ }
31
+ function Pe(e, t, n) {
32
+ let r = le.fromJSON(e, t);
33
+ return r.check(), Ne(e, r, n);
34
+ }
35
+ function _(e, t, n) {
36
+ return t == null || t === "" ? e.topNodeType.createAndFill() : typeof t == "string" ? je(e, t, n) : Pe(e, t, n);
37
+ }
38
+ function Fe(e) {
39
+ let t = e.firstChild;
40
+ return e.childCount === 0 || e.childCount === 1 && !!t?.isTextblock && t.content.size === 0;
41
+ }
42
+ // src/emitter.ts
43
+ var Ie = class {
44
+ listeners = /* @__PURE__ */ new Map();
45
+ on(e, t) {
46
+ let n = this.listeners.get(e);
47
+ return n || this.listeners.set(e, n = /* @__PURE__ */ new Set()), n.add(t), () => this.off(e, t);
48
+ }
49
+ off(e, t) {
50
+ this.listeners.get(e)?.delete(t);
51
+ }
52
+ emit(e, ...t) {
53
+ for (let n of [...this.listeners.get(e) ?? []]) n(...t);
54
+ }
55
+ has(e) {
56
+ return (this.listeners.get(e)?.size ?? 0) > 0;
57
+ }
58
+ clear() {
59
+ this.listeners.clear();
60
+ }
61
+ }, Le = {
62
+ toolbar: "Opmaak",
63
+ "toolbar.more": "Meer",
64
+ editor: "Teksteditor",
65
+ bold: "Vet",
66
+ italic: "Cursief",
67
+ underline: "Onderstrepen",
68
+ strike: "Doorhalen",
69
+ code: "Code",
70
+ heading: "Tekststijl",
71
+ paragraph: "Alinea",
72
+ heading1: "Kop 1",
73
+ heading2: "Kop 2",
74
+ heading3: "Kop 3",
75
+ heading4: "Kop 4",
76
+ bulletList: "Opsommingslijst",
77
+ orderedList: "Genummerde lijst",
78
+ blockquote: "Citaat",
79
+ horizontalRule: "Horizontale lijn",
80
+ link: "Link",
81
+ unlink: "Link verwijderen",
82
+ image: "Afbeelding",
83
+ "image.dialog": "Afbeelding",
84
+ "image.url": "Afbeeldings-URL",
85
+ "image.alt": "Alternatieve tekst",
86
+ "image.altHint": "Beschrijf de afbeelding voor wie ze niet kan zien. Laat leeg als ze enkel decoratief is.",
87
+ "image.upload": "Uploaden vanaf computer…",
88
+ "image.uploading": "Bezig met uploaden van {name}",
89
+ "image.invalid": "Voer een geldige afbeeldings-URL in (http of https).",
90
+ "image.align": "Uitlijning",
91
+ "image.alignNone": "Geen",
92
+ "image.alignLeft": "Links",
93
+ "image.alignCenter": "Gecentreerd",
94
+ "image.alignRight": "Rechts",
95
+ "image.remove": "Afbeelding verwijderen",
96
+ table: "Tabel",
97
+ "table.insert": "Tabel invoegen",
98
+ "table.size": "Tabelgrootte",
99
+ "table.cells": "{rows} × {cols}",
100
+ "table.header": "Kopregel",
101
+ "table.addRowBefore": "Rij erboven invoegen",
102
+ "table.addRowAfter": "Rij eronder invoegen",
103
+ "table.addColumnBefore": "Kolom links invoegen",
104
+ "table.addColumnAfter": "Kolom rechts invoegen",
105
+ "table.deleteRow": "Rij verwijderen",
106
+ "table.deleteColumn": "Kolom verwijderen",
107
+ "table.toggleHeaderRow": "Kopregel aan/uit",
108
+ "table.delete": "Tabel verwijderen",
109
+ align: "Uitlijning",
110
+ alignLeft: "Links uitlijnen",
111
+ alignCenter: "Centreren",
112
+ alignRight: "Rechts uitlijnen",
113
+ alignJustify: "Uitvullen",
114
+ textColor: "Tekstkleur",
115
+ highlight: "Markeren",
116
+ "color.remove": "Kleur verwijderen",
117
+ "highlight.remove": "Markering verwijderen",
118
+ "color.gray": "Grijs",
119
+ "color.red": "Rood",
120
+ "color.orange": "Oranje",
121
+ "color.yellow": "Geel",
122
+ "color.green": "Groen",
123
+ "color.teal": "Blauwgroen",
124
+ "color.blue": "Blauw",
125
+ "color.violet": "Violet",
126
+ "color.pink": "Roze",
127
+ clearFormatting: "Opmaak wissen",
128
+ source: "Broncode",
129
+ "source.label": "HTML-broncode",
130
+ undo: "Ongedaan maken",
131
+ redo: "Opnieuw",
132
+ "link.dialog": "Link bewerken",
133
+ "link.url": "URL",
134
+ "link.newTab": "Openen in nieuw tabblad",
135
+ "dialog.apply": "Toepassen",
136
+ "dialog.cancel": "Annuleren",
137
+ "link.remove": "Verwijderen",
138
+ "link.invalid": "Voer een geldige URL in (http, https, mailto of tel)."
139
+ }, v = {
140
+ toolbar: "Formatting",
141
+ "toolbar.more": "More",
142
+ editor: "Rich text editor",
143
+ bold: "Bold",
144
+ italic: "Italic",
145
+ underline: "Underline",
146
+ strike: "Strikethrough",
147
+ code: "Inline code",
148
+ heading: "Text style",
149
+ paragraph: "Paragraph",
150
+ heading1: "Heading 1",
151
+ heading2: "Heading 2",
152
+ heading3: "Heading 3",
153
+ heading4: "Heading 4",
154
+ bulletList: "Bulleted list",
155
+ orderedList: "Numbered list",
156
+ blockquote: "Quote",
157
+ horizontalRule: "Horizontal line",
158
+ link: "Link",
159
+ unlink: "Remove link",
160
+ image: "Image",
161
+ "image.dialog": "Image",
162
+ "image.url": "Image URL",
163
+ "image.alt": "Alternative text",
164
+ "image.altHint": "Describe the image for people who cannot see it. Leave empty if it is decorative.",
165
+ "image.upload": "Upload from computer…",
166
+ "image.uploading": "Uploading {name}",
167
+ "image.invalid": "Enter a valid image URL (http or https).",
168
+ "image.align": "Alignment",
169
+ "image.alignNone": "None",
170
+ "image.alignLeft": "Left",
171
+ "image.alignCenter": "Center",
172
+ "image.alignRight": "Right",
173
+ "image.remove": "Remove image",
174
+ table: "Table",
175
+ "table.insert": "Insert table",
176
+ "table.size": "Table size",
177
+ "table.cells": "{rows} × {cols}",
178
+ "table.header": "Header row",
179
+ "table.addRowBefore": "Insert row above",
180
+ "table.addRowAfter": "Insert row below",
181
+ "table.addColumnBefore": "Insert column left",
182
+ "table.addColumnAfter": "Insert column right",
183
+ "table.deleteRow": "Delete row",
184
+ "table.deleteColumn": "Delete column",
185
+ "table.toggleHeaderRow": "Toggle header row",
186
+ "table.delete": "Delete table",
187
+ align: "Alignment",
188
+ alignLeft: "Align left",
189
+ alignCenter: "Align center",
190
+ alignRight: "Align right",
191
+ alignJustify: "Justify",
192
+ textColor: "Text color",
193
+ highlight: "Highlight",
194
+ "color.remove": "Remove color",
195
+ "highlight.remove": "Remove highlight",
196
+ "color.gray": "Gray",
197
+ "color.red": "Red",
198
+ "color.orange": "Orange",
199
+ "color.yellow": "Yellow",
200
+ "color.green": "Green",
201
+ "color.teal": "Teal",
202
+ "color.blue": "Blue",
203
+ "color.violet": "Violet",
204
+ "color.pink": "Pink",
205
+ clearFormatting: "Clear formatting",
206
+ source: "Source code",
207
+ "source.label": "HTML source",
208
+ undo: "Undo",
209
+ redo: "Redo",
210
+ "link.dialog": "Edit link",
211
+ "link.url": "URL",
212
+ "link.newTab": "Open in new tab",
213
+ "dialog.apply": "Apply",
214
+ "dialog.cancel": "Cancel",
215
+ "link.remove": "Remove",
216
+ "link.invalid": "Enter a valid URL (http, https, mailto or tel)."
217
+ }, y = /* @__PURE__ */ new Map([["en", v], ["nl", Le]]);
218
+ function Re(e, t) {
219
+ y.set(e.toLowerCase(), t);
220
+ }
221
+ function ze() {
222
+ return [...y.keys()];
223
+ }
224
+ function Be(e) {
225
+ let t = e.toLowerCase().replace("_", "-");
226
+ for (let e of [t, t.split("-")[0]]) {
227
+ let t = y.get(e);
228
+ if (t) return {
229
+ code: e,
230
+ messages: t
231
+ };
232
+ }
233
+ return null;
234
+ }
235
+ function Ve(e, t) {
236
+ return t ? e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e) : e;
237
+ }
238
+ // src/icons.ts
239
+ var b = (e) => `<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">${e}</svg>`, x = {
240
+ bold: "<span class=\"wysio-glyph\" style=\"font-weight:700\">B</span>",
241
+ italic: "<span class=\"wysio-glyph\" style=\"font-style:italic;font-family:Georgia,serif\">I</span>",
242
+ underline: "<span class=\"wysio-glyph\" style=\"text-decoration:underline\">U</span>",
243
+ strike: "<span class=\"wysio-glyph\" style=\"text-decoration:line-through\">S</span>",
244
+ code: b("<path d=\"m8 7-5 5 5 5M16 7l5 5-5 5\"/>"),
245
+ bulletList: b("<path d=\"M9 6h11M9 12h11M9 18h11\"/><circle cx=\"4.5\" cy=\"6\" r=\"1\" fill=\"currentColor\"/><circle cx=\"4.5\" cy=\"12\" r=\"1\" fill=\"currentColor\"/><circle cx=\"4.5\" cy=\"18\" r=\"1\" fill=\"currentColor\"/>"),
246
+ orderedList: b("<path d=\"M10 6h10M10 12h10M10 18h10\"/><path d=\"M4 4h1.5v5M4 9h3\" stroke-width=\"1.5\"/><path d=\"M4 14.5c.4-.8 2.8-.9 2.8.6 0 1.2-2.8 2.2-2.8 3.4h3\" stroke-width=\"1.5\"/>"),
247
+ blockquote: b("<path d=\"M4 7h5v5c0 3-2 4.5-4 5M14 7h5v5c0 3-2 4.5-4 5\"/>"),
248
+ horizontalRule: b("<path d=\"M3 12h18\"/>"),
249
+ link: b("<path d=\"M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1\"/><path d=\"M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1\"/>"),
250
+ unlink: b("<path d=\"M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1\"/><path d=\"M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1\"/><path d=\"M3 3l18 18\"/>"),
251
+ image: b("<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\"/><circle cx=\"9\" cy=\"10\" r=\"2\"/><path d=\"m21 16-5-5-9 9\"/>"),
252
+ table: b("<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\"/><path d=\"M3 10h18M3 15h18M9 4v16M15 4v16\"/>"),
253
+ tableRowBefore: b("<path d=\"M3 14h18v6H3zM3 17h18M12 3v7M8.5 6.5h7\"/>"),
254
+ tableRowAfter: b("<path d=\"M3 4h18v6H3zM3 7h18M12 14v7M8.5 17.5h7\"/>"),
255
+ tableColumnBefore: b("<path d=\"M14 3h6v18h-6zM17 3v18M3 12h7M6.5 8.5v7\"/>"),
256
+ tableColumnAfter: b("<path d=\"M4 3h6v18H4zM7 3v18M14 12h7M17.5 8.5v7\"/>"),
257
+ tableDeleteRow: b("<path d=\"M3 9h18v6H3zM9 9v6M15 9v6M8 4l8 0M8 20h8\"/>"),
258
+ tableDeleteColumn: b("<path d=\"M9 3h6v18H9zM9 9h6M9 15h6M4 8v8M20 8v8\"/>"),
259
+ tableHeaderRow: b("<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\"/><path d=\"M3 10h18M9 10v10M15 10v10\"/><path d=\"M3 6h18\" stroke-width=\"4\"/>"),
260
+ tableDelete: b("<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\"/><path d=\"m9 9 6 6M15 9l-6 6\"/>"),
261
+ alignLeft: b("<path d=\"M4 6h16M4 10h10M4 14h16M4 18h10\"/>"),
262
+ alignCenter: b("<path d=\"M4 6h16M7 10h10M4 14h16M7 18h10\"/>"),
263
+ alignRight: b("<path d=\"M4 6h16M10 10h10M4 14h16M10 18h10\"/>"),
264
+ alignJustify: b("<path d=\"M4 6h16M4 10h16M4 14h16M4 18h16\"/>"),
265
+ textColor: b("<path d=\"m6 16 6-12 6 12M8.5 11h7\"/><path d=\"M4 20h16\" stroke-width=\"3\" stroke=\"var(--wysio-icon-accent, currentColor)\"/>"),
266
+ highlight: b("<path d=\"m9 11-5 5v3h3l5-5M9 11l4-4 4 4-4 4zM13 7l2-2a1.4 1.4 0 0 1 2 0l2 2a1.4 1.4 0 0 1 0 2l-2 2\"/><path d=\"M14 20h6\" stroke-width=\"3\" stroke=\"var(--wysio-icon-accent, currentColor)\"/>"),
267
+ clearFormatting: b("<path d=\"M6 5h11M11.5 5 8 19M4 4l16 16\"/><path d=\"M12 19h3\"/>"),
268
+ source: b("<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\"/><path d=\"m10 9-3 3 3 3M14 9l3 3-3 3\"/>"),
269
+ undo: b("<path d=\"M9 14 4 9l5-5\"/><path d=\"M4 9h10.5a5.5 5.5 0 0 1 0 11H11\"/>"),
270
+ redo: b("<path d=\"m15 14 5-5-5-5\"/><path d=\"M20 9H9.5a5.5 5.5 0 0 0 0 11H13\"/>")
271
+ }, He = 0, S = class {
272
+ editor;
273
+ dom;
274
+ key = "";
275
+ uid = `wysio-pop-${++He}`;
276
+ constructor(e, t) {
277
+ this.editor = e, this.dom = e.dom.ownerDocument.createElement("div"), this.dom.className = "wysio-popover", this.dom.setAttribute("role", "dialog"), e.locale && (this.dom.lang = e.locale), this.dom.setAttribute("aria-label", t), this.dom.hidden = !0, this.dom.addEventListener("focusout", (e) => {
278
+ let t = e.relatedTarget;
279
+ t && !this.dom.contains(t) && this.close(!1);
280
+ }), this.dom.addEventListener("keydown", (e) => {
281
+ e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), this.close());
282
+ }), e.dom.appendChild(this.dom);
283
+ }
284
+ get isOpen() {
285
+ return !this.dom.hidden;
286
+ }
287
+ show(e, t) {
288
+ this.dom.hidden = !1, this.notify(!0), this.position(e), this.editor.dom.ownerDocument.addEventListener("mousedown", this.onOutside, !0), t.focus();
289
+ }
290
+ close(e = !0) {
291
+ this.isOpen && (this.dom.hidden = !0, this.editor.dom.ownerDocument.removeEventListener("mousedown", this.onOutside, !0), this.notify(!1), e && this.editor.focus());
292
+ }
293
+ notify(e) {
294
+ this.editor.dom.dispatchEvent(new CustomEvent("wysio:popover", { detail: {
295
+ key: this.key,
296
+ open: e
297
+ } }));
298
+ }
299
+ destroy() {
300
+ this.close(!1), this.dom.remove();
301
+ }
302
+ position(e) {
303
+ let { view: t } = this.editor;
304
+ try {
305
+ let n = t.coordsAtPos(Math.min(e, t.state.doc.content.size)), r = this.editor.dom.getBoundingClientRect(), i = Math.max(0, Math.min(n.left - r.left, r.width - this.dom.offsetWidth));
306
+ this.dom.style.left = `${i}px`, this.dom.style.top = `${n.bottom - r.top + 6}px`;
307
+ } catch {}
308
+ }
309
+ onOutside = (e) => {
310
+ this.dom.contains(e.target) || this.close(!1);
311
+ };
312
+ }, C = /* @__PURE__ */ new WeakMap();
313
+ function w(e, t, n) {
314
+ let r = C.get(e);
315
+ if (!r) {
316
+ let t = /* @__PURE__ */ new Map();
317
+ C.set(e, r = t), e.on("destroy", () => {
318
+ for (let e of t.values()) e.destroy();
319
+ C.delete(e);
320
+ });
321
+ }
322
+ let i = r.get(t);
323
+ return i || (i = n(), i.key = t, r.set(t, i)), i;
324
+ }
325
+ function Ue(e, t, n) {
326
+ let r = e.createElement("form");
327
+ return r.noValidate = !0, r.innerHTML = n.replaceAll("{id}", t), r;
328
+ }
329
+ function T(e, t) {
330
+ let n = e.querySelector(t);
331
+ if (!n) throw Error(`[wysio] Missing element ${t}`);
332
+ return n;
333
+ }
334
+ // src/ui/menu.ts
335
+ var We = class extends S {
336
+ buttons = [];
337
+ constructor(e, t, n) {
338
+ super(e, t);
339
+ let r = e.dom.ownerDocument, i = r.createElement("div");
340
+ i.className = "wysio-menu";
341
+ for (let e of n) {
342
+ let t = r.createElement("button");
343
+ t.type = "button", t.className = "wysio-menu-item", t.dataset.action = e.id, t.innerHTML = e.icon ?? "", t.append(r.createTextNode(e.label)), e.isActive && t.setAttribute("aria-pressed", "false"), t.addEventListener("click", () => {
344
+ this.close(!1), e.run(this.editor);
345
+ }), i.appendChild(t), this.buttons.push({
346
+ button: t,
347
+ item: e
348
+ });
349
+ }
350
+ i.addEventListener("keydown", this.onKey), this.dom.appendChild(i);
351
+ }
352
+ open() {
353
+ let { state: e } = this.editor.view;
354
+ for (let { button: t, item: n } of this.buttons) t.disabled = n.isEnabled ? !n.isEnabled(e) : !1, n.isActive && t.setAttribute("aria-pressed", String(n.isActive(e)));
355
+ let t = this.buttons.filter((e) => !e.button.disabled), n = t.find((e) => e.button.getAttribute("aria-pressed") === "true") ?? t[0];
356
+ this.show(e.selection.from, n?.button ?? this.dom);
357
+ }
358
+ onKey = (e) => {
359
+ let t = this.buttons.map((e) => e.button).filter((e) => !e.disabled), n = t.indexOf(e.target), r = null;
360
+ e.key === "ArrowDown" ? r = (n + 1) % t.length : e.key === "ArrowUp" ? r = (n - 1 + t.length) % t.length : e.key === "Home" ? r = 0 : e.key === "End" && (r = t.length - 1), r !== null && (e.preventDefault(), t[r]?.focus());
361
+ };
362
+ }, E = [
363
+ "left",
364
+ "center",
365
+ "right",
366
+ "justify"
367
+ ], Ge = ["paragraph", "heading"], D = (e) => e === "center" || e === "right" || e === "justify" ? e : null;
368
+ function Ke(e) {
369
+ for (let t of E) if (e.classList.contains(`wysio-align-${t}`)) return t;
370
+ let t = (e.style.textAlign || e.getAttribute("align") || "").toLowerCase();
371
+ return E.includes(t) ? t : null;
372
+ }
373
+ function qe(e, t) {
374
+ if (!Array.isArray(e)) return e;
375
+ let [n, r, ...i] = e;
376
+ if (typeof r == "object" && r && !Array.isArray(r) && !(typeof Node < "u" && r instanceof Node)) {
377
+ let e = { ...r };
378
+ return e.class = e.class ? `${e.class} ${t}` : t, [
379
+ n,
380
+ e,
381
+ ...i
382
+ ];
383
+ }
384
+ return [
385
+ n,
386
+ { class: t },
387
+ ...r === void 0 ? [] : [r],
388
+ ...i
389
+ ];
390
+ }
391
+ function Je(e) {
392
+ let t = e.toDOM;
393
+ return {
394
+ ...e,
395
+ attrs: {
396
+ ...e.attrs,
397
+ align: {
398
+ default: null,
399
+ validate: "string|null"
400
+ }
401
+ },
402
+ parseDOM: e.parseDOM?.map((e) => {
403
+ if (!("tag" in e)) return e;
404
+ let t = e;
405
+ return {
406
+ ...t,
407
+ attrs: void 0,
408
+ getAttrs: (e) => {
409
+ let n = t.getAttrs ? t.getAttrs(e) : null;
410
+ return n !== !1 && {
411
+ ...t.attrs,
412
+ ...n,
413
+ align: D(Ke(e))
414
+ };
415
+ }
416
+ };
417
+ }),
418
+ toDOM: t ? (e) => {
419
+ let n = t(e), r = D(e.attrs.align);
420
+ return r ? qe(n, `wysio-align-${r}`) : n;
421
+ } : void 0
422
+ };
423
+ }
424
+ function Ye(e) {
425
+ let t = [];
426
+ for (let { $from: n, $to: r } of e.selection.ranges) e.doc.nodesBetween(n.pos, r.pos, (e, n) => (e.isTextblock && "align" in e.type.spec.attrs && t.push({
427
+ node: e,
428
+ pos: n
429
+ }), !e.isTextblock));
430
+ return t;
431
+ }
432
+ function O(e) {
433
+ return (t, n) => {
434
+ let r = Ye(t);
435
+ if (!r.length) return !1;
436
+ if (n) {
437
+ let i = t.tr, a = D(e);
438
+ for (let { node: e, pos: t } of r) i.setNodeMarkup(t, void 0, {
439
+ ...e.attrs,
440
+ align: a
441
+ });
442
+ n(i.scrollIntoView());
443
+ }
444
+ return !0;
445
+ };
446
+ }
447
+ function k(e, t) {
448
+ let n = Ye(e);
449
+ return n.length > 0 && n.every(({ node: e }) => (D(e.attrs.align) ?? "left") === t);
450
+ }
451
+ var Xe = {
452
+ left: "Mod-Shift-l",
453
+ center: "Mod-Shift-e",
454
+ right: "Mod-Shift-r",
455
+ justify: "Mod-Shift-j"
456
+ }, A = (e) => `align${e[0].toUpperCase()}${e.slice(1)}`;
457
+ function Ze(e) {
458
+ e.isEditable && w(e, "alignment", () => new We(e, e.t("align"), E.map((t) => ({
459
+ id: A(t),
460
+ label: e.t(A(t)),
461
+ icon: x[A(t)],
462
+ run: (e) => e.exec(O(t)),
463
+ isActive: (e) => k(e, t),
464
+ isEnabled: (e) => O(t)(e)
465
+ })))).open();
466
+ }
467
+ var Qe = m({
468
+ name: "alignment",
469
+ schema: { extendNodes: Object.fromEntries(Ge.map((e) => [e, Je])) },
470
+ keymap: () => Object.fromEntries(E.map((e) => [Xe[e], O(e)])),
471
+ toolbarItems: ({ editor: e }) => {
472
+ let t = { align: {
473
+ label: e.t("align"),
474
+ icon: x.alignLeft,
475
+ run: Ze,
476
+ popover: "alignment",
477
+ dropdown: !0,
478
+ render: (e, t) => {
479
+ let n = E.find((t) => k(e, t)) ?? "left";
480
+ t.setIcon(x[A(n)]);
481
+ },
482
+ isActive: (e) => E.slice(1).some((t) => k(e, t)),
483
+ isEnabled: (e) => O("left")(e)
484
+ } };
485
+ for (let n of E) t[A(n)] = {
486
+ label: e.t(A(n)),
487
+ icon: x[A(n)],
488
+ shortcut: Xe[n],
489
+ command: O(n),
490
+ isActive: (e) => k(e, n)
491
+ };
492
+ return t;
493
+ }
494
+ }), $e = m({
495
+ name: "base",
496
+ schema: { nodes: {
497
+ doc: { content: "block+" },
498
+ paragraph: {
499
+ content: "inline*",
500
+ group: "block",
501
+ parseDOM: [{ tag: "p" }],
502
+ toDOM: () => ["p", 0]
503
+ },
504
+ text: { group: "inline" }
505
+ } },
506
+ prosemirrorPlugins: () => [me(), pe({ class: "wysio-dropcursor" })]
507
+ });
508
+ // src/commands.ts
509
+ function j(e, t) {
510
+ let { from: n, to: r, empty: i, $from: a } = e.selection;
511
+ return i ? !!t.isInSet(e.storedMarks ?? a.marks()) : e.doc.rangeHasMark(n, r, t);
512
+ }
513
+ function M(e, t) {
514
+ let { $from: n } = e.selection;
515
+ for (let e = n.depth; e > 0; e--) {
516
+ let r = n.node(e);
517
+ if (t.includes(r.type)) return {
518
+ node: r,
519
+ depth: e,
520
+ pos: n.before(e)
521
+ };
522
+ }
523
+ return null;
524
+ }
525
+ function N(e, t, n) {
526
+ return (r, i) => {
527
+ let a = M(r, n);
528
+ return a ? a.node.type === e ? he(t)(r, i) : (i && i(r.tr.setNodeMarkup(a.pos, e).scrollIntoView()), !0) : ve(e)(r, i);
529
+ };
530
+ }
531
+ function et(e) {
532
+ return (t, n) => M(t, [e]) ? r(t, n) : o(e)(t, n);
533
+ }
534
+ function tt(e, t) {
535
+ let n = e.parent, r = n.childAfter(e.parentOffset), i = r.node ? t.isInSet(r.node.marks) : void 0;
536
+ if (!i && (r = n.childBefore(e.parentOffset), i = r.node ? t.isInSet(r.node.marks) : void 0, !i || !r.node)) return null;
537
+ let a = e.start(), o = r.index, s = a + r.offset;
538
+ for (; o > 0 && i.isInSet(n.child(o - 1).marks);) o--, s -= n.child(o).nodeSize;
539
+ let c = r.index + 1, l = a + r.offset + n.child(r.index).nodeSize;
540
+ for (; c < n.childCount && i.isInSet(n.child(c).marks);) l += n.child(c).nodeSize, c++;
541
+ return {
542
+ from: s,
543
+ to: l,
544
+ mark: i
545
+ };
546
+ }
547
+ // src/plugins/blocks.ts
548
+ var nt = m({
549
+ name: "blockquote",
550
+ schema: { nodes: { blockquote: {
551
+ content: "block+",
552
+ group: "block",
553
+ defining: !0,
554
+ parseDOM: [{ tag: "blockquote" }],
555
+ toDOM: () => ["blockquote", 0]
556
+ } } },
557
+ keymap: ({ schema: e }) => ({ "Mod-Shift-b": et(e.nodes.blockquote) }),
558
+ inputRules: ({ schema: e }) => [d(/^\s*>\s$/, e.nodes.blockquote)],
559
+ toolbarItems: ({ schema: e, editor: t }) => {
560
+ let n = e.nodes.blockquote;
561
+ return { blockquote: {
562
+ label: t.t("blockquote"),
563
+ icon: x.blockquote,
564
+ shortcut: "Mod-Shift-b",
565
+ command: et(n),
566
+ isActive: (e) => !!M(e, [n])
567
+ } };
568
+ }
569
+ }), rt = m({
570
+ name: "horizontalRule",
571
+ schema: { nodes: { horizontal_rule: {
572
+ group: "block",
573
+ parseDOM: [{ tag: "hr" }],
574
+ toDOM: () => ["hr"]
575
+ } } },
576
+ inputRules: ({ schema: e }) => [new s(/^(?:---|___|\*\*\*)$/, (t, n, r, i) => {
577
+ let a = t.doc.resolve(r), o = e.nodes.horizontal_rule.create();
578
+ return !a.parent.isTextblock || a.parent.content.size !== i - r + 1 ? null : t.tr.replaceRangeWith(a.before(), a.after(), o).scrollIntoView();
579
+ })],
580
+ toolbarItems: ({ schema: e, editor: t }) => {
581
+ let n = e.nodes.horizontal_rule;
582
+ return { horizontalRule: {
583
+ label: t.t("horizontalRule"),
584
+ icon: x.horizontalRule,
585
+ command: (e, t) => !e.selection.$from.parent.canReplaceWith(0, 0, n) && !e.selection.$from.parent.isTextblock ? !1 : (t && t(e.tr.replaceSelectionWith(n.create()).scrollIntoView()), !0)
586
+ } };
587
+ }
588
+ }), it = m({
589
+ name: "hardBreak",
590
+ schema: { nodes: { hard_break: {
591
+ inline: !0,
592
+ group: "inline",
593
+ selectable: !1,
594
+ parseDOM: [{ tag: "br" }],
595
+ toDOM: () => ["br"]
596
+ } } },
597
+ keymap: ({ schema: e }) => {
598
+ let r = e.nodes.hard_break, i = t(n, (e, t) => (t && t(e.tr.replaceSelectionWith(r.create()).scrollIntoView()), !0));
599
+ return {
600
+ "Shift-Enter": i,
601
+ "Mod-Enter": i
602
+ };
603
+ }
604
+ }), at = ["align"], ot = /* @__PURE__ */ new Set(["link"]), st = (e, t) => {
605
+ let n = e.tr, r = !1, i = Object.values(e.schema.marks).filter((e) => !ot.has(e.name)), a = (e) => {
606
+ let t = n.doc.nodeAt(e);
607
+ if (!t) return;
608
+ let i = {};
609
+ for (let e of at) e in t.type.spec.attrs && t.attrs[e] != null && (i[e] = null);
610
+ Object.keys(i).length && (n.setNodeMarkup(e, void 0, {
611
+ ...t.attrs,
612
+ ...i
613
+ }), r = !0);
614
+ };
615
+ for (let { $from: t, $to: o } of e.selection.ranges) {
616
+ let s = t.pos, c = o.pos;
617
+ for (let t of i) s < c && e.doc.rangeHasMark(s, c, t) && (n.removeMark(s, c, t), r = !0);
618
+ s === c ? t.depth > 0 && a(t.before()) : e.doc.nodesBetween(s, c, (e, t) => (e.isTextblock && a(t), !e.isTextblock));
619
+ }
620
+ if (e.selection.empty) {
621
+ let t = e.storedMarks ?? e.selection.$from.marks();
622
+ t.some((e) => !ot.has(e.type.name)) && (n.setStoredMarks(t.filter((e) => ot.has(e.type.name))), r = !0);
623
+ }
624
+ return r ? (t && t(n.scrollIntoView()), !0) : !1;
625
+ }, ct = m({
626
+ name: "clearFormatting",
627
+ keymap: () => ({ "Mod-\\": st }),
628
+ toolbarItems: ({ editor: e }) => ({ clearFormatting: {
629
+ label: e.t("clearFormatting"),
630
+ icon: x.clearFormatting,
631
+ shortcut: "Mod-\\",
632
+ command: st
633
+ } })
634
+ }), lt = [
635
+ {
636
+ name: "gray",
637
+ value: "#868e96"
638
+ },
639
+ {
640
+ name: "red",
641
+ value: "#e03131"
642
+ },
643
+ {
644
+ name: "orange",
645
+ value: "#e8590c"
646
+ },
647
+ {
648
+ name: "green",
649
+ value: "#2f9e44"
650
+ },
651
+ {
652
+ name: "teal",
653
+ value: "#0c8599"
654
+ },
655
+ {
656
+ name: "blue",
657
+ value: "#1971c2"
658
+ },
659
+ {
660
+ name: "violet",
661
+ value: "#6741d9"
662
+ },
663
+ {
664
+ name: "pink",
665
+ value: "#c2255c"
666
+ }
667
+ ], ut = [
668
+ {
669
+ name: "yellow",
670
+ value: "#ffec99"
671
+ },
672
+ {
673
+ name: "green",
674
+ value: "#b2f2bb"
675
+ },
676
+ {
677
+ name: "blue",
678
+ value: "#a5d8ff"
679
+ },
680
+ {
681
+ name: "pink",
682
+ value: "#fcc2d7"
683
+ },
684
+ {
685
+ name: "orange",
686
+ value: "#ffd8a8"
687
+ },
688
+ {
689
+ name: "violet",
690
+ value: "#d0bfff"
691
+ },
692
+ {
693
+ name: "red",
694
+ value: "#ffc9c9"
695
+ },
696
+ {
697
+ name: "gray",
698
+ value: "#e9ecef"
699
+ }
700
+ ], dt = (e) => e.toString(16).padStart(2, "0");
701
+ function ft(e) {
702
+ if (typeof e != "string") return null;
703
+ let t = e.trim().toLowerCase(), n = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(t);
704
+ if (n) return `#${n[1]}${n[1]}${n[2]}${n[2]}${n[3]}${n[3]}`;
705
+ if (/^#[0-9a-f]{6}$/.test(t)) return t;
706
+ if (n = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(1|1\.0+)\s*)?\)$/.exec(t), n) {
707
+ let e = [
708
+ n[1],
709
+ n[2],
710
+ n[3]
711
+ ].map(Number);
712
+ if (e.every((e) => e <= 255)) return `#${e.map(dt).join("")}`;
713
+ }
714
+ return null;
715
+ }
716
+ var pt = /^[a-z][a-z0-9-]*$/;
717
+ function mt(e) {
718
+ let t = e.map((e) => {
719
+ let t = ft(e.value);
720
+ if (!t || !pt.test(e.name)) throw Error(`[wysio] Invalid palette colour "${e.name}" (${e.value}).`);
721
+ return {
722
+ ...e,
723
+ value: t
724
+ };
725
+ }), n = new Map(t.map((e) => [e.name, e])), r = new Map(t.map((e) => [e.value, e.name]));
726
+ return {
727
+ colors: t,
728
+ name: (e) => typeof e == "string" && n.has(e) ? e : null,
729
+ fromCSS: (e) => r.get(ft(e) ?? "") ?? null,
730
+ fromClass: (e, t) => {
731
+ for (let r of e.classList) if (r.startsWith(t) && n.has(r.slice(t.length))) return r.slice(t.length);
732
+ return null;
733
+ },
734
+ value: (e) => n.get(e)?.value ?? null
735
+ };
736
+ }
737
+ function ht(e, t) {
738
+ return mt(t).colors.map((t) => e === "text" ? `.wysio-color-${t.name} { color: ${t.value}; }` : `.wysio-highlight-${t.name} { background-color: ${t.value}; }`).join("\n");
739
+ }
740
+ function gt(e, t, n) {
741
+ let r = n ? t.value(n) : null;
742
+ r ? e.style.setProperty("--wysio-icon-accent", r) : e.style.removeProperty("--wysio-icon-accent");
743
+ }
744
+ function _t(e, t) {
745
+ return (n, r) => {
746
+ if (!a(e)(n)) return !1;
747
+ if (r) {
748
+ let i = e.create({ color: t }), a = n.tr;
749
+ if (n.selection.empty) a.addStoredMark(i);
750
+ else for (let { $from: e, $to: t } of n.selection.ranges) a.addMark(e.pos, t.pos, i);
751
+ r(a.scrollIntoView());
752
+ }
753
+ return !0;
754
+ };
755
+ }
756
+ function vt(e) {
757
+ return (t, n) => {
758
+ if (n) {
759
+ let r = t.tr;
760
+ if (t.selection.empty) r.removeStoredMark(e);
761
+ else for (let { $from: n, $to: i } of t.selection.ranges) r.removeMark(n.pos, i.pos, e);
762
+ n(r.scrollIntoView());
763
+ }
764
+ return !0;
765
+ };
766
+ }
767
+ function P(e, t) {
768
+ let { empty: n, $from: r, from: i, to: a } = e.selection;
769
+ if (n) return t.isInSet(e.storedMarks ?? r.marks())?.attrs.color ?? null;
770
+ let o, s = !1;
771
+ return e.doc.nodesBetween(i, a, (e) => {
772
+ if (!e.isText) return;
773
+ let n = t.isInSet(e.marks)?.attrs.color ?? null;
774
+ o === void 0 ? o = n : o !== n && (s = !0);
775
+ }), s ? null : o ?? null;
776
+ }
777
+ var yt = (e, t) => {
778
+ if (t.label) return t.label;
779
+ let n = `color.${t.name}`, r = e.t(n);
780
+ return r === n ? t.name : r;
781
+ }, bt = 4, xt = class extends S {
782
+ type;
783
+ swatches = [];
784
+ constructor(e, t, n, r, i, a) {
785
+ super(e, t), this.type = n;
786
+ let o = e.dom.ownerDocument, s = o.createElement("div");
787
+ s.className = "wysio-palette", s.setAttribute("role", "group"), s.setAttribute("aria-label", t);
788
+ for (let t of r.colors) {
789
+ let n = o.createElement("button");
790
+ n.type = "button", n.className = `wysio-swatch wysio-swatch-${a}`, n.style.setProperty("--wysio-swatch", t.value), n.setAttribute("aria-label", yt(e, t)), n.title = yt(e, t), n.setAttribute("aria-pressed", "false"), n.tabIndex = -1, a === "text" && (n.textContent = "A"), n.addEventListener("click", () => this.apply(t.name)), s.appendChild(n), this.swatches.push({
791
+ button: n,
792
+ value: t.name
793
+ });
794
+ }
795
+ s.addEventListener("keydown", this.onKey);
796
+ let c = o.createElement("button");
797
+ c.type = "button", c.className = "wysio-button wysio-palette-remove", c.dataset.action = "remove", c.textContent = i, c.addEventListener("click", () => {
798
+ this.close(!1), this.editor.exec(vt(this.type));
799
+ }), this.dom.append(s, c);
800
+ }
801
+ open() {
802
+ let { state: e } = this.editor.view, t = P(e, this.type), n = this.swatches[0];
803
+ for (let e of this.swatches) {
804
+ let r = e.value === t;
805
+ e.button.setAttribute("aria-pressed", String(r)), r && (n = e);
806
+ }
807
+ for (let e of this.swatches) e.button.tabIndex = e === n ? 0 : -1;
808
+ this.show(e.selection.from, n?.button ?? this.dom);
809
+ }
810
+ apply(e) {
811
+ this.close(!1), this.editor.exec(_t(this.type, e));
812
+ }
813
+ onKey = (e) => {
814
+ let t = this.swatches.map((e) => e.button), n = t.indexOf(e.target);
815
+ if (n === -1) return;
816
+ let r = {
817
+ ArrowRight: 1,
818
+ ArrowLeft: -1,
819
+ ArrowDown: bt,
820
+ ArrowUp: -4
821
+ }, i = null;
822
+ e.key in r ? i = Math.min(t.length - 1, Math.max(0, n + r[e.key])) : e.key === "Home" ? i = 0 : e.key === "End" && (i = t.length - 1), i !== null && (e.preventDefault(), t.forEach((e, t) => e.tabIndex = t === i ? 0 : -1), t[i]?.focus());
823
+ };
824
+ };
825
+ function St(e = {}) {
826
+ let t = mt(e.colors ?? lt);
827
+ return m({
828
+ name: "textColor",
829
+ schema: { marks: { text_color: {
830
+ attrs: { color: { validate: "string" } },
831
+ parseDOM: [{
832
+ tag: "span",
833
+ getAttrs: (e) => {
834
+ let n = t.fromClass(e, "wysio-color-");
835
+ return n ? { color: n } : !1;
836
+ }
837
+ }, {
838
+ style: "color",
839
+ getAttrs: (e) => {
840
+ let n = t.fromCSS(e);
841
+ return n ? { color: n } : !1;
842
+ }
843
+ }],
844
+ toDOM: (e) => {
845
+ let n = t.name(e.attrs.color);
846
+ return [
847
+ "span",
848
+ n ? { class: `wysio-color-${n}` } : {},
849
+ 0
850
+ ];
851
+ }
852
+ } } },
853
+ toolbarItems: ({ schema: e, editor: n }) => {
854
+ let r = e.marks.text_color;
855
+ return { textColor: {
856
+ label: n.t("textColor"),
857
+ icon: x.textColor,
858
+ popover: "textColor",
859
+ dropdown: !0,
860
+ render: (e, n) => gt(n.el, t, P(e, r)),
861
+ run: (e) => w(e, "textColor", () => new xt(e, e.t("textColor"), r, t, e.t("color.remove"), "text")).open(),
862
+ isActive: (e) => P(e, r) !== null,
863
+ isEnabled: (e) => a(r)(e)
864
+ } };
865
+ }
866
+ });
867
+ }
868
+ function Ct(e = {}) {
869
+ let t = mt(e.colors ?? ut), n = t.colors[0]?.name;
870
+ return m({
871
+ name: "highlight",
872
+ schema: { marks: { highlight: {
873
+ attrs: { color: { validate: "string" } },
874
+ parseDOM: [{
875
+ tag: "mark",
876
+ getAttrs: (e) => {
877
+ let r = e, i = t.fromClass(r, "wysio-highlight-") ?? t.fromCSS(r.style.backgroundColor) ?? n;
878
+ return i ? { color: i } : !1;
879
+ }
880
+ }, {
881
+ style: "background-color",
882
+ getAttrs: (e) => {
883
+ let n = t.fromCSS(e);
884
+ return n ? { color: n } : !1;
885
+ }
886
+ }],
887
+ toDOM: (e) => {
888
+ let n = t.name(e.attrs.color);
889
+ return [
890
+ "mark",
891
+ n ? { class: `wysio-highlight-${n}` } : {},
892
+ 0
893
+ ];
894
+ }
895
+ } } },
896
+ toolbarItems: ({ schema: e, editor: n }) => {
897
+ let r = e.marks.highlight;
898
+ return { highlight: {
899
+ label: n.t("highlight"),
900
+ icon: x.highlight,
901
+ popover: "highlight",
902
+ dropdown: !0,
903
+ render: (e, n) => gt(n.el, t, P(e, r)),
904
+ run: (e) => w(e, "highlight", () => new xt(e, e.t("highlight"), r, t, e.t("highlight.remove"), "background")).open(),
905
+ isActive: (e) => P(e, r) !== null,
906
+ isEnabled: (e) => a(r)(e)
907
+ } };
908
+ }
909
+ });
910
+ }
911
+ // src/plugins/heading.ts
912
+ var F = [
913
+ 1,
914
+ 2,
915
+ 3,
916
+ 4
917
+ ], wt = (e) => Math.min(4, Math.max(1, Math.trunc(Number(e)) || 1)), Tt = m({
918
+ name: "heading",
919
+ schema: { nodes: { heading: {
920
+ attrs: { level: {
921
+ default: 1,
922
+ validate: "number"
923
+ } },
924
+ content: "inline*",
925
+ group: "block",
926
+ defining: !0,
927
+ parseDOM: [
928
+ ...F.map((e) => ({
929
+ tag: `h${e}`,
930
+ attrs: { level: e }
931
+ })),
932
+ {
933
+ tag: "h5",
934
+ attrs: { level: 4 }
935
+ },
936
+ {
937
+ tag: "h6",
938
+ attrs: { level: 4 }
939
+ }
940
+ ],
941
+ toDOM: (e) => [`h${wt(e.attrs.level)}`, 0]
942
+ } } },
943
+ keymap: ({ schema: e }) => {
944
+ let t = { "Mod-Alt-0": i(e.nodes.paragraph) };
945
+ for (let n of F) t[`Mod-Alt-${n}`] = i(e.nodes.heading, { level: n });
946
+ return t;
947
+ },
948
+ inputRules: ({ schema: e }) => [l(/^(#{1,4})\s$/, e.nodes.heading, (e) => ({ level: e[1].length }))],
949
+ toolbarItems: ({ schema: e, editor: t }) => {
950
+ let { paragraph: n, heading: r } = e.nodes;
951
+ return { heading: {
952
+ type: "select",
953
+ label: t.t("heading"),
954
+ options: [{
955
+ value: "p",
956
+ label: t.t("paragraph")
957
+ }, ...F.map((e) => ({
958
+ value: `h${e}`,
959
+ label: t.t(`heading${e}`)
960
+ }))],
961
+ getValue: (e) => {
962
+ let { $from: t, $to: i } = e.selection, a = t.parent;
963
+ return !t.sameParent(i) && a !== i.parent ? "" : a.type === n ? "p" : a.type === r ? `h${a.attrs.level}` : "";
964
+ },
965
+ isEnabled: (e) => i(n)(e) || i(r, { level: 1 })(e),
966
+ onSelect: (e, t) => {
967
+ let a = t === "p" ? i(n) : i(r, { level: wt(t.slice(1)) });
968
+ e.exec(a);
969
+ }
970
+ } };
971
+ }
972
+ }), Et = () => typeof navigator < "u" && /Mac|iP(hone|[oa]d)/.test(navigator.platform), Dt = m({
973
+ name: "history",
974
+ prosemirrorPlugins: () => [ye()],
975
+ keymap: () => ({
976
+ "Mod-z": xe,
977
+ "Mod-Shift-z": be,
978
+ ...Et() ? {} : { "Mod-y": be }
979
+ }),
980
+ toolbarItems: ({ editor: e }) => ({
981
+ undo: {
982
+ label: e.t("undo"),
983
+ icon: x.undo,
984
+ shortcut: "Mod-z",
985
+ command: xe
986
+ },
987
+ redo: {
988
+ label: e.t("redo"),
989
+ icon: x.redo,
990
+ shortcut: "Mod-Shift-z",
991
+ command: be
992
+ }
993
+ })
994
+ }), Ot = /* @__PURE__ */ new Set([
995
+ "http",
996
+ "https",
997
+ "mailto",
998
+ "tel"
999
+ ]), I = /[\u0000- \u007f-\u009f]/g, kt = /[\u0000-\u001f\u007f-\u009f]/g;
1000
+ function L(e) {
1001
+ if (typeof e != "string") return null;
1002
+ let t = e.trim().replace(kt, "");
1003
+ if (!t) return null;
1004
+ let n = t.replace(I, ""), r = /^([a-z][a-z0-9+.-]*):/i.exec(n);
1005
+ if (r) return Ot.has(r[1].toLowerCase()) ? t : null;
1006
+ let i = n.indexOf(":");
1007
+ if (i !== -1) {
1008
+ let e = n.search(/[/?#]/);
1009
+ if (e === -1 || i < e) return null;
1010
+ }
1011
+ return t;
1012
+ }
1013
+ function At(e) {
1014
+ let t = e.trim();
1015
+ if (!t) return null;
1016
+ let n = /^[a-z][a-z0-9+.-]*:/i.test(t), r = /^([/?#.]|\/\/)/.test(t);
1017
+ if (!n && !r) {
1018
+ if (/^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(t)) t = `mailto:${t}`;
1019
+ else if (/^[^\s/]+\.[^\s/]+/.test(t)) t = `https://${t}`;
1020
+ else return null;
1021
+ }
1022
+ let i = L(t);
1023
+ if (!i) return null;
1024
+ if (/^https?:/i.test(i)) try {
1025
+ if (!new URL(i).hostname) return null;
1026
+ } catch {
1027
+ return null;
1028
+ }
1029
+ return i;
1030
+ }
1031
+ var jt = /^data:image\/(png|gif|jpe?g|webp|avif|bmp);base64,[a-z0-9+/=\s]+$/i;
1032
+ function R(e, { allowDataUrls: t = !1 } = {}) {
1033
+ if (typeof e != "string") return null;
1034
+ let n = e.trim();
1035
+ if (/^data:/i.test(n.replace(I, ""))) return t && jt.test(n) ? n : null;
1036
+ let r = L(n);
1037
+ return !r || /^(mailto|tel):/i.test(r.replace(I, "")) ? null : r;
1038
+ }
1039
+ // src/plugins/image.ts
1040
+ var z = [
1041
+ "left",
1042
+ "center",
1043
+ "right"
1044
+ ], B = [
1045
+ "image/png",
1046
+ "image/jpeg",
1047
+ "image/gif",
1048
+ "image/webp",
1049
+ "image/avif"
1050
+ ], V = (e) => {
1051
+ let t = typeof e == "number" ? String(e) : typeof e == "string" ? e.trim() : "";
1052
+ if (!/^\d+$/.test(t)) return null;
1053
+ let n = Number(t);
1054
+ return n > 0 && n <= 1e4 ? n : null;
1055
+ }, Mt = (e) => typeof e == "string" ? e : null, H = (e) => z.includes(e) ? e : null;
1056
+ function Nt(e) {
1057
+ for (let t of z) if (e.classList.contains(`wysio-image-${t}`)) return t;
1058
+ let t = e.style.cssFloat || e.style.getPropertyValue("float");
1059
+ if (t === "left" || t === "right") return t;
1060
+ if (e.style.display === "block" && e.style.marginLeft === "auto" && e.style.marginRight === "auto") return "center";
1061
+ let n = e.getAttribute("align")?.toLowerCase();
1062
+ return n === "left" || n === "right" ? n : n === "middle" || n === "center" ? "center" : null;
1063
+ }
1064
+ var Pt = /* @__PURE__ */ new WeakMap(), U = (e) => Pt.get(e) ?? {
1065
+ allowDataUrls: !1,
1066
+ types: B
1067
+ };
1068
+ function W(e, t) {
1069
+ let n = R(e.src, t);
1070
+ return n ? {
1071
+ src: n,
1072
+ alt: Mt(e.alt),
1073
+ title: Mt(e.title),
1074
+ width: V(e.width),
1075
+ height: V(e.height),
1076
+ align: H(e.align)
1077
+ } : null;
1078
+ }
1079
+ var G = new ne("wysio-upload"), Ft = /* @__PURE__ */ new WeakMap();
1080
+ function It(e, t) {
1081
+ let n = G.getState(e)?.find(void 0, void 0, (e) => e.id === t);
1082
+ return n?.length ? n[0].from : null;
1083
+ }
1084
+ function Lt(e, t) {
1085
+ let n = e.dom.ownerDocument, r = n.createElement("span");
1086
+ r.className = "wysio-upload", r.setAttribute("role", "status"), r.setAttribute("aria-label", e.t("image.uploading", { name: t.name })), r.style.setProperty("--wysio-progress", "0");
1087
+ let i = "";
1088
+ if (typeof URL.createObjectURL == "function") {
1089
+ i = URL.createObjectURL(t);
1090
+ let e = n.createElement("img");
1091
+ e.src = i, e.alt = "", r.appendChild(e);
1092
+ }
1093
+ let a = n.createElement("span");
1094
+ return a.className = "wysio-upload-bar", r.appendChild(a), {
1095
+ dom: r,
1096
+ revoke: () => i && URL.revokeObjectURL(i)
1097
+ };
1098
+ }
1099
+ function K(e, t, n) {
1100
+ let r = e.options.upload, i = e.schema.nodes.image;
1101
+ if (!r || !i || !e.isEditable) return [];
1102
+ let a = U(e), o = Ft.get(e);
1103
+ if (!o) {
1104
+ let t = /* @__PURE__ */ new Set();
1105
+ Ft.set(e, o = t), e.on("destroy", () => t.forEach((e) => e.abort()));
1106
+ }
1107
+ let s = o;
1108
+ return [...t].map(async (t) => {
1109
+ if (!a.types.includes(t.type)) {
1110
+ e.reportError(/* @__PURE__ */ Error(`Unsupported image type: ${t.type || "unknown"}`), {
1111
+ source: "upload",
1112
+ file: t
1113
+ });
1114
+ return;
1115
+ }
1116
+ let { view: o } = e, c = {}, l = Lt(e, t), u = o.state.tr;
1117
+ n === void 0 && !u.selection.empty && u.deleteSelection();
1118
+ let d = n ?? u.selection.from;
1119
+ o.dispatch(u.setMeta(G, { add: {
1120
+ id: c,
1121
+ pos: d,
1122
+ dom: l.dom
1123
+ } }).setMeta("addToHistory", !1));
1124
+ let f = new AbortController();
1125
+ s.add(f);
1126
+ try {
1127
+ let n = await r(t, {
1128
+ editor: e,
1129
+ signal: f.signal,
1130
+ onProgress: (e) => l.dom.style.setProperty("--wysio-progress", String(Math.min(1, Math.max(0, e))))
1131
+ });
1132
+ if (f.signal.aborted) return;
1133
+ let { url: o, ...s } = typeof n == "string" ? { url: n } : n, u = W({
1134
+ ...s,
1135
+ src: o
1136
+ }, a);
1137
+ if (!u) throw Error("Upload handler returned an unsafe or empty URL");
1138
+ let d = It(e.view.state, c);
1139
+ if (d === null) return;
1140
+ e.view.dispatch(e.view.state.tr.insert(d, i.create(u)).setMeta(G, { remove: { id: c } }));
1141
+ } catch (n) {
1142
+ if (f.signal.aborted) return;
1143
+ It(e.view.state, c) !== null && e.view.dispatch(e.view.state.tr.setMeta(G, { remove: { id: c } }).setMeta("addToHistory", !1)), e.reportError(n, {
1144
+ source: "upload",
1145
+ file: t
1146
+ });
1147
+ } finally {
1148
+ s.delete(f), l.revoke();
1149
+ }
1150
+ });
1151
+ }
1152
+ function Rt(e, t) {
1153
+ let { types: n } = U(e);
1154
+ return [...t ?? []].filter((e) => n.includes(e.type));
1155
+ }
1156
+ function zt(e) {
1157
+ return new p({
1158
+ key: G,
1159
+ state: {
1160
+ init: () => ae.empty,
1161
+ apply(e, t) {
1162
+ let n = t.map(e.mapping, e.doc), r = e.getMeta(G);
1163
+ if (r?.add && (n = n.add(e.doc, [ie.widget(r.add.pos, r.add.dom, { id: r.add.id })])), r?.remove) {
1164
+ let { id: e } = r.remove;
1165
+ n = n.remove(n.find(void 0, void 0, (t) => t.id === e));
1166
+ }
1167
+ return n;
1168
+ }
1169
+ },
1170
+ props: {
1171
+ decorations: (e) => G.getState(e),
1172
+ handlePaste: (t, n) => {
1173
+ if (!e.options.upload) return !1;
1174
+ let r = n.clipboardData;
1175
+ if (!r || r.getData("text/html") || r.getData("text/plain")) return !1;
1176
+ let i = Rt(e, r.files);
1177
+ return i.length ? (n.preventDefault(), K(e, i), !0) : !1;
1178
+ },
1179
+ handleDrop: (t, n, r, i) => {
1180
+ if (i || !e.options.upload) return !1;
1181
+ let a = Rt(e, n.dataTransfer?.files);
1182
+ return a.length ? (n.preventDefault(), K(e, a, t.posAtCoords({
1183
+ left: n.clientX,
1184
+ top: n.clientY
1185
+ })?.pos ?? t.state.selection.from), !0) : !1;
1186
+ }
1187
+ }
1188
+ });
1189
+ }
1190
+ function q(e, t) {
1191
+ let { selection: n } = e;
1192
+ return n instanceof te && n.node.type === t ? n.node : null;
1193
+ }
1194
+ function Bt(e, t) {
1195
+ let n = e.schema.nodes.image, r = n && W(t, U(e));
1196
+ return !n || !r ? !1 : e.exec((e, i) => {
1197
+ let a = q(e, n);
1198
+ if (i) {
1199
+ let o = Object.fromEntries(Object.entries(r).filter(([e]) => t[e] !== void 0));
1200
+ i((a ? e.tr.setNodeMarkup(e.selection.from, void 0, {
1201
+ ...a.attrs,
1202
+ ...o
1203
+ }) : e.tr.replaceSelectionWith(n.create(r))).scrollIntoView());
1204
+ }
1205
+ return !0;
1206
+ });
1207
+ }
1208
+ function Vt(e) {
1209
+ let t = e.schema.nodes.image;
1210
+ return e.exec((e, n) => !t || !q(e, t) ? !1 : (n && n(e.tr.deleteSelection().scrollIntoView()), !0));
1211
+ }
1212
+ function Ht(e) {
1213
+ e.isEditable && e.schema.nodes.image && w(e, "image", () => new Ut(e)).open();
1214
+ }
1215
+ var Ut = class extends S {
1216
+ src;
1217
+ alt;
1218
+ align;
1219
+ error;
1220
+ file;
1221
+ uploadRow;
1222
+ removeButton;
1223
+ pos = 0;
1224
+ original = "";
1225
+ constructor(e) {
1226
+ super(e, e.t("image.dialog"));
1227
+ let t = Ue(e.dom.ownerDocument, this.uid, "<label class=\"wysio-field\" for=\"{id}-src\" data-text=\"image.url\"></label>\n <input class=\"wysio-input\" id=\"{id}-src\" name=\"src\" type=\"text\" inputmode=\"url\" autocomplete=\"off\" spellcheck=\"false\" aria-describedby=\"{id}-error\">\n <p class=\"wysio-error\" id=\"{id}-error\" role=\"alert\" hidden></p>\n <div class=\"wysio-upload-row\">\n <button type=\"button\" class=\"wysio-button\" data-action=\"upload\" data-text=\"image.upload\"></button>\n <input type=\"file\" name=\"file\" hidden>\n </div>\n <label class=\"wysio-field\" for=\"{id}-alt\" data-text=\"image.alt\"></label>\n <input class=\"wysio-input\" id=\"{id}-alt\" name=\"alt\" type=\"text\" aria-describedby=\"{id}-alt-hint\">\n <p class=\"wysio-hint\" id=\"{id}-alt-hint\" data-text=\"image.altHint\"></p>\n <label class=\"wysio-field\" for=\"{id}-align\" data-text=\"image.align\"></label>\n <select class=\"wysio-input\" id=\"{id}-align\" name=\"align\">\n <option value=\"\" data-text=\"image.alignNone\"></option>\n <option value=\"left\" data-text=\"image.alignLeft\"></option>\n <option value=\"center\" data-text=\"image.alignCenter\"></option>\n <option value=\"right\" data-text=\"image.alignRight\"></option>\n </select>\n <div class=\"wysio-actions\">\n <button type=\"submit\" class=\"wysio-button wysio-button-primary\" data-text=\"dialog.apply\"></button>\n <button type=\"button\" class=\"wysio-button\" data-action=\"remove\" data-text=\"image.remove\"></button>\n <button type=\"button\" class=\"wysio-button\" data-action=\"cancel\" data-text=\"dialog.cancel\"></button>\n </div>");
1228
+ for (let n of t.querySelectorAll("[data-text]")) n.textContent = e.t(n.dataset.text);
1229
+ this.src = T(t, "input[name=src]"), this.alt = T(t, "input[name=alt]"), this.align = T(t, "select[name=align]"), this.error = T(t, ".wysio-error"), this.file = T(t, "input[name=file]"), this.file.accept = U(e).types.join(","), this.file.multiple = !0, this.uploadRow = T(t, ".wysio-upload-row"), this.removeButton = T(t, "[data-action=remove]"), t.addEventListener("submit", (e) => {
1230
+ e.preventDefault(), this.apply();
1231
+ }), T(t, "[data-action=cancel]").addEventListener("click", () => this.close()), this.removeButton.addEventListener("click", () => {
1232
+ this.close(!1), Vt(this.editor);
1233
+ }), T(t, "[data-action=upload]").addEventListener("click", () => this.file.click()), this.file.addEventListener("change", () => {
1234
+ let e = [...this.file.files ?? []];
1235
+ this.file.value = "", e.length && (this.close(!1), this.editor.focus(), K(this.editor, e, this.pos));
1236
+ }), this.src.addEventListener("input", () => this.setError(!1)), this.dom.appendChild(t);
1237
+ }
1238
+ open() {
1239
+ let { state: e } = this.editor.view, t = q(e, this.editor.schema.nodes.image);
1240
+ this.pos = e.selection.from, this.original = t?.attrs.src ?? "", this.src.value = this.original, this.alt.value = t?.attrs.alt ?? "", this.align.value = t?.attrs.align ?? "", this.uploadRow.hidden = !this.editor.options.upload || !!t, this.removeButton.hidden = !t, this.setError(!1), this.show(this.pos, this.src), this.src.select();
1241
+ }
1242
+ apply() {
1243
+ let e = this.src.value.trim(), t = U(this.editor), n = e === this.original || /^data:/i.test(e) || /^[^/:]+\.(png|jpe?g|gif|webp|avif|svg|bmp)$/i.test(e) ? R(e, t) : R(At(e), t);
1244
+ n ? (this.close(!1), Bt(this.editor, {
1245
+ src: n,
1246
+ alt: this.alt.value.trim(),
1247
+ align: H(this.align.value)
1248
+ })) : (this.setError(!0), this.src.focus());
1249
+ }
1250
+ setError(e) {
1251
+ this.error.hidden = !e, this.error.textContent = e ? this.editor.t("image.invalid") : "", this.src.setAttribute("aria-invalid", String(e));
1252
+ }
1253
+ };
1254
+ function Wt(e = {}) {
1255
+ let t = {
1256
+ allowDataUrls: e.allowDataUrls ?? !1,
1257
+ types: e.types ?? B
1258
+ };
1259
+ return m({
1260
+ name: "image",
1261
+ schema: { nodes: { image: {
1262
+ inline: !0,
1263
+ group: "inline",
1264
+ draggable: !0,
1265
+ attrs: {
1266
+ src: { validate: "string" },
1267
+ alt: {
1268
+ default: null,
1269
+ validate: "string|null"
1270
+ },
1271
+ title: {
1272
+ default: null,
1273
+ validate: "string|null"
1274
+ },
1275
+ width: {
1276
+ default: null,
1277
+ validate: "number|null"
1278
+ },
1279
+ height: {
1280
+ default: null,
1281
+ validate: "number|null"
1282
+ },
1283
+ align: {
1284
+ default: null,
1285
+ validate: "string|null"
1286
+ }
1287
+ },
1288
+ parseDOM: [{
1289
+ tag: "img[src]",
1290
+ getAttrs: (e) => {
1291
+ let n = e;
1292
+ return W({
1293
+ src: n.getAttribute("src") ?? "",
1294
+ alt: n.getAttribute("alt"),
1295
+ title: n.getAttribute("title"),
1296
+ width: V(n.getAttribute("width")),
1297
+ height: V(n.getAttribute("height")),
1298
+ align: Nt(n)
1299
+ }, t) ?? !1;
1300
+ }
1301
+ }],
1302
+ toDOM: (e) => {
1303
+ let n = {}, r = R(e.attrs.src, t);
1304
+ r && (n.src = r), typeof e.attrs.alt == "string" && (n.alt = e.attrs.alt), typeof e.attrs.title == "string" && (n.title = e.attrs.title);
1305
+ let i = V(e.attrs.width), a = V(e.attrs.height);
1306
+ i && (n.width = String(i)), a && (n.height = String(a));
1307
+ let o = H(e.attrs.align);
1308
+ return o && (n.class = `wysio-image-${o}`), ["img", n];
1309
+ }
1310
+ } } },
1311
+ prosemirrorPlugins: ({ editor: e }) => (Pt.set(e, t), [zt(e)]),
1312
+ toolbarItems: ({ schema: e, editor: t }) => {
1313
+ let n = e.nodes.image;
1314
+ return { image: {
1315
+ label: t.t("image"),
1316
+ icon: x.image,
1317
+ run: Ht,
1318
+ popover: "image",
1319
+ isActive: (e) => !!q(e, n),
1320
+ isEnabled: (e) => !!q(e, n) || e.selection.$from.parent.inlineContent
1321
+ } };
1322
+ }
1323
+ });
1324
+ }
1325
+ // src/plugins/link.ts
1326
+ function Gt(e, t) {
1327
+ let { from: n, to: r, empty: i, $from: a } = e.selection;
1328
+ if (!i) return {
1329
+ from: n,
1330
+ to: r
1331
+ };
1332
+ let o = tt(a, t);
1333
+ return o ? {
1334
+ from: o.from,
1335
+ to: o.to
1336
+ } : null;
1337
+ }
1338
+ function Kt(e, t) {
1339
+ return (n, r) => {
1340
+ let i = L(t.href);
1341
+ if (!i) return !1;
1342
+ let a = e.create({
1343
+ href: i,
1344
+ target: t.target === "_blank" ? "_blank" : null
1345
+ }), o = Gt(n, e);
1346
+ if (r) {
1347
+ let t = n.tr;
1348
+ if (o) t.removeMark(o.from, o.to, e).addMark(o.from, o.to, a);
1349
+ else {
1350
+ let { from: e } = n.selection;
1351
+ t.insertText(i, e).addMark(e, e + i.length, a);
1352
+ }
1353
+ r(t.scrollIntoView());
1354
+ }
1355
+ return !0;
1356
+ };
1357
+ }
1358
+ function qt(e) {
1359
+ return (t, n) => {
1360
+ let r = Gt(t, e);
1361
+ return !r || !t.doc.rangeHasMark(r.from, r.to, e) ? !1 : (n && n(t.tr.removeMark(r.from, r.to, e).scrollIntoView()), !0);
1362
+ };
1363
+ }
1364
+ function Jt(e) {
1365
+ let t = e.schema.marks.link;
1366
+ e.isEditable && t && w(e, "link", () => new Yt(e, t)).open();
1367
+ }
1368
+ var Yt = class extends S {
1369
+ type;
1370
+ input;
1371
+ newTab;
1372
+ error;
1373
+ removeButton;
1374
+ range = null;
1375
+ constructor(e, t) {
1376
+ super(e, e.t("link.dialog")), this.type = t;
1377
+ let n = Ue(e.dom.ownerDocument, this.uid, "<label class=\"wysio-field\" for=\"{id}-url\"></label>\n <input class=\"wysio-input\" id=\"{id}-url\" name=\"href\" type=\"text\" inputmode=\"url\" autocomplete=\"off\" spellcheck=\"false\" aria-describedby=\"{id}-error\">\n <p class=\"wysio-error\" id=\"{id}-error\" role=\"alert\" hidden></p>\n <label class=\"wysio-check\"><input type=\"checkbox\" name=\"newTab\"> <span></span></label>\n <div class=\"wysio-actions\">\n <button type=\"submit\" class=\"wysio-button wysio-button-primary\" data-action=\"apply\"></button>\n <button type=\"button\" class=\"wysio-button\" data-action=\"remove\"></button>\n <button type=\"button\" class=\"wysio-button\" data-action=\"cancel\"></button>\n </div>");
1378
+ T(n, ".wysio-field").textContent = e.t("link.url"), T(n, ".wysio-check span").textContent = e.t("link.newTab"), T(n, "[data-action=apply]").textContent = e.t("dialog.apply");
1379
+ let r = T(n, "[data-action=cancel]");
1380
+ r.textContent = e.t("dialog.cancel"), this.removeButton = T(n, "[data-action=remove]"), this.removeButton.textContent = e.t("link.remove"), this.input = T(n, "input[name=href]"), this.newTab = T(n, "input[name=newTab]"), this.error = T(n, ".wysio-error"), n.addEventListener("submit", (e) => {
1381
+ e.preventDefault(), this.apply();
1382
+ }), this.removeButton.addEventListener("click", () => this.remove()), r.addEventListener("click", () => this.close()), this.input.addEventListener("input", () => this.setError(!1)), this.dom.appendChild(n);
1383
+ }
1384
+ open() {
1385
+ let { state: e } = this.editor.view, { from: t, to: n } = e.selection, r = tt(e.selection.$from, this.type);
1386
+ this.range = r && (e.selection.empty || r.from <= t && r.to >= n) ? {
1387
+ from: r.from,
1388
+ to: r.to
1389
+ } : {
1390
+ from: t,
1391
+ to: n
1392
+ };
1393
+ let i = r?.mark;
1394
+ this.input.value = i?.attrs.href ?? "", this.newTab.checked = i?.attrs.target === "_blank", this.removeButton.hidden = !i && !j(e, this.type), this.setError(!1), this.show(this.range.from, this.input), this.input.select();
1395
+ }
1396
+ apply() {
1397
+ let e = At(this.input.value);
1398
+ if (!e) {
1399
+ this.setError(!0), this.input.focus();
1400
+ return;
1401
+ }
1402
+ let { view: t } = this.editor, n = this.clampRange(), r = this.type.create({
1403
+ href: e,
1404
+ target: this.newTab.checked ? "_blank" : null
1405
+ }), i = t.state.tr;
1406
+ n.from === n.to ? i.insertText(e, n.from).addMark(n.from, n.from + e.length, r) : i.removeMark(n.from, n.to, this.type).addMark(n.from, n.to, r), t.dispatch(i.scrollIntoView()), this.close(!1), this.editor.focus();
1407
+ }
1408
+ remove() {
1409
+ let e = this.clampRange(), { view: t } = this.editor;
1410
+ t.dispatch(t.state.tr.removeMark(e.from, e.to, this.type)), this.close(!1), this.editor.focus();
1411
+ }
1412
+ clampRange() {
1413
+ let e = this.editor.view.state.doc.content.size, t = Math.min(this.range?.from ?? 0, e);
1414
+ return {
1415
+ from: t,
1416
+ to: Math.min(this.range?.to ?? t, e)
1417
+ };
1418
+ }
1419
+ setError(e) {
1420
+ this.error.hidden = !e, this.error.textContent = e ? this.editor.t("link.invalid") : "", this.input.setAttribute("aria-invalid", String(e));
1421
+ }
1422
+ }, Xt = m({
1423
+ name: "link",
1424
+ schema: { marks: { link: {
1425
+ attrs: {
1426
+ href: { validate: "string" },
1427
+ target: {
1428
+ default: null,
1429
+ validate: "string|null"
1430
+ }
1431
+ },
1432
+ inclusive: !1,
1433
+ parseDOM: [{
1434
+ tag: "a[href]",
1435
+ getAttrs: (e) => {
1436
+ let t = e, n = L(t.getAttribute("href"));
1437
+ return n ? {
1438
+ href: n,
1439
+ target: t.getAttribute("target") === "_blank" ? "_blank" : null
1440
+ } : !1;
1441
+ }
1442
+ }],
1443
+ toDOM: (e) => {
1444
+ let t = L(e.attrs.href), n = {};
1445
+ return t && (n.href = t), e.attrs.target === "_blank" && (n.target = "_blank", n.rel = "noopener noreferrer"), [
1446
+ "a",
1447
+ n,
1448
+ 0
1449
+ ];
1450
+ }
1451
+ } } },
1452
+ keymap: ({ editor: e }) => ({ "Mod-k": (t, n) => e.isEditable ? (n && Jt(e), !0) : !1 }),
1453
+ toolbarItems: ({ schema: e, editor: t }) => {
1454
+ let n = e.marks.link;
1455
+ return {
1456
+ link: {
1457
+ label: t.t("link"),
1458
+ icon: x.link,
1459
+ shortcut: "Mod-k",
1460
+ run: Jt,
1461
+ popover: "link",
1462
+ isActive: (e) => j(e, n),
1463
+ isEnabled: () => !0
1464
+ },
1465
+ unlink: {
1466
+ label: t.t("unlink"),
1467
+ icon: x.unlink,
1468
+ command: qt(n)
1469
+ }
1470
+ };
1471
+ }
1472
+ }), J = (e) => {
1473
+ let t = Math.trunc(Number(e));
1474
+ return Number.isFinite(t) ? t : 1;
1475
+ }, Zt = m({
1476
+ name: "lists",
1477
+ schema: { nodes: {
1478
+ bullet_list: {
1479
+ content: "list_item+",
1480
+ group: "block",
1481
+ parseDOM: [{ tag: "ul" }],
1482
+ toDOM: () => ["ul", 0]
1483
+ },
1484
+ ordered_list: {
1485
+ attrs: { start: {
1486
+ default: 1,
1487
+ validate: "number"
1488
+ } },
1489
+ content: "list_item+",
1490
+ group: "block",
1491
+ parseDOM: [{
1492
+ tag: "ol",
1493
+ getAttrs: (e) => ({ start: J(e.getAttribute("start") ?? 1) })
1494
+ }],
1495
+ toDOM: (e) => {
1496
+ let t = J(e.attrs.start);
1497
+ return t === 1 ? ["ol", 0] : [
1498
+ "ol",
1499
+ { start: String(t) },
1500
+ 0
1501
+ ];
1502
+ }
1503
+ },
1504
+ list_item: {
1505
+ content: "paragraph block*",
1506
+ defining: !0,
1507
+ parseDOM: [{ tag: "li" }],
1508
+ toDOM: () => ["li", 0]
1509
+ }
1510
+ } },
1511
+ keymap: ({ schema: e }) => {
1512
+ let t = e.nodes.list_item, n = [e.nodes.bullet_list, e.nodes.ordered_list];
1513
+ return {
1514
+ Enter: _e(t),
1515
+ Tab: ge(t),
1516
+ "Shift-Tab": he(t),
1517
+ "Mod-Shift-8": N(n[0], t, n),
1518
+ "Mod-Shift-7": N(n[1], t, n)
1519
+ };
1520
+ },
1521
+ inputRules: ({ schema: e }) => [d(/^\s*([-+*])\s$/, e.nodes.bullet_list), d(/^(\d+)\.\s$/, e.nodes.ordered_list, (e) => ({ start: J(e[1]) }), (e, t) => t.childCount + t.attrs.start === J(e[1]))],
1522
+ toolbarItems: ({ schema: e, editor: t }) => {
1523
+ let n = e.nodes.list_item, r = e.nodes.bullet_list, i = e.nodes.ordered_list, a = [r, i], o = (e) => (t) => M(t, a)?.node.type === e;
1524
+ return {
1525
+ bulletList: {
1526
+ label: t.t("bulletList"),
1527
+ icon: x.bulletList,
1528
+ shortcut: "Mod-Shift-8",
1529
+ command: N(r, n, a),
1530
+ isActive: o(r)
1531
+ },
1532
+ orderedList: {
1533
+ label: t.t("orderedList"),
1534
+ icon: x.orderedList,
1535
+ shortcut: "Mod-Shift-7",
1536
+ command: N(i, n, a),
1537
+ isActive: o(i)
1538
+ }
1539
+ };
1540
+ }
1541
+ });
1542
+ // src/plugins/marks.ts
1543
+ function Y(e, t, n) {
1544
+ return m({
1545
+ name: e,
1546
+ schema: { marks: { [e]: t } },
1547
+ keymap: ({ schema: t }) => ({ [n]: a(t.marks[e]) }),
1548
+ toolbarItems: ({ schema: t, editor: r }) => {
1549
+ let i = t.marks[e];
1550
+ return { [e]: {
1551
+ label: r.t(e),
1552
+ icon: x[e],
1553
+ shortcut: n,
1554
+ command: a(i),
1555
+ isActive: (e) => j(e, i)
1556
+ } };
1557
+ }
1558
+ });
1559
+ }
1560
+ var X = (e, t) => e.includes(t) && null, Qt = Y("bold", {
1561
+ parseDOM: [
1562
+ { tag: "strong" },
1563
+ {
1564
+ tag: "b",
1565
+ getAttrs: (e) => e.style.fontWeight !== "normal" && null
1566
+ },
1567
+ {
1568
+ style: "font-weight=400",
1569
+ clearMark: (e) => e.type.name === "bold"
1570
+ },
1571
+ {
1572
+ style: "font-weight",
1573
+ getAttrs: (e) => /^(bold(er)?|[5-9]\d{2,})$/.test(e) && null
1574
+ }
1575
+ ],
1576
+ toDOM: () => ["strong", 0]
1577
+ }, "Mod-b"), $t = Y("italic", {
1578
+ parseDOM: [
1579
+ { tag: "em" },
1580
+ { tag: "i" },
1581
+ { style: "font-style=italic" },
1582
+ {
1583
+ style: "font-style=normal",
1584
+ clearMark: (e) => e.type.name === "italic"
1585
+ }
1586
+ ],
1587
+ toDOM: () => ["em", 0]
1588
+ }, "Mod-i"), en = Y("underline", {
1589
+ parseDOM: [
1590
+ { tag: "u" },
1591
+ {
1592
+ style: "text-decoration",
1593
+ getAttrs: (e) => X(e, "underline")
1594
+ },
1595
+ {
1596
+ style: "text-decoration-line",
1597
+ getAttrs: (e) => X(e, "underline")
1598
+ }
1599
+ ],
1600
+ toDOM: () => ["u", 0]
1601
+ }, "Mod-u"), tn = Y("strike", {
1602
+ parseDOM: [
1603
+ { tag: "s" },
1604
+ { tag: "del" },
1605
+ { tag: "strike" },
1606
+ {
1607
+ style: "text-decoration",
1608
+ getAttrs: (e) => X(e, "line-through")
1609
+ },
1610
+ {
1611
+ style: "text-decoration-line",
1612
+ getAttrs: (e) => X(e, "line-through")
1613
+ }
1614
+ ],
1615
+ toDOM: () => ["s", 0]
1616
+ }, "Mod-Shift-x"), nn = Y("code", {
1617
+ code: !0,
1618
+ parseDOM: [{ tag: "code" }],
1619
+ toDOM: () => ["code", 0]
1620
+ }, "Mod-e"), rn = "script, style, meta, link, title, xml, template, noscript, object, embed, iframe, svg, canvas, video, audio, button, input, select, textarea", an = new Set("P H1 H2 H3 H4 H5 H6 UL OL LI TABLE DIV BLOCKQUOTE HR PRE FIGURE SECTION ARTICLE HEADER FOOTER".split(" ")), on = /* @__PURE__ */ new Set([
1621
+ "href",
1622
+ "target",
1623
+ "src",
1624
+ "alt",
1625
+ "title",
1626
+ "width",
1627
+ "height",
1628
+ "colspan",
1629
+ "rowspan",
1630
+ "start"
1631
+ ]), sn = "h1, h2, h3, h4, h5, h6";
1632
+ function cn(e) {
1633
+ e.replaceWith(...e.childNodes);
1634
+ }
1635
+ function ln(e, t) {
1636
+ if (!t.length) return;
1637
+ let n = e.ownerDocument, r = n.createElement(t[0]), i = r;
1638
+ for (let e of t.slice(1)) i = i.appendChild(n.createElement(e));
1639
+ i.append(...e.childNodes), e.appendChild(r);
1640
+ }
1641
+ function un(e) {
1642
+ let t = e.style, n = [], r = t.fontWeight;
1643
+ /^(bold(er)?|[6-9]\d\d)$/.test(r) && !e.closest(sn) && n.push("strong"), (t.fontStyle === "italic" || t.fontStyle === "oblique") && n.push("em");
1644
+ let i = `${t.textDecoration} ${t.getPropertyValue("text-decoration-line")}`;
1645
+ return i.includes("underline") && !e.closest("a") && n.push("u"), i.includes("line-through") && n.push("s"), n;
1646
+ }
1647
+ var dn = (e) => /mso-list\s*:\s*l\d+/i.test(e.getAttribute("style") ?? ""), fn = (e) => /mso-list\s*:\s*ignore/i.test(e.getAttribute("style") ?? "");
1648
+ function pn(e) {
1649
+ let t = null;
1650
+ for (let n of [...e.querySelectorAll("p")].filter(dn)) {
1651
+ let e = [...n.querySelectorAll("span")].find(fn), r = (e?.textContent ?? "").replace(/[\s\u00a0]+/g, ""), i = /^\(?(\d+|[a-z]{1,3})[.)]$/i.test(r) ? "OL" : "UL";
1652
+ e?.remove(), t && t.tagName === i && n.previousElementSibling === t || (t = n.ownerDocument.createElement(i), n.before(t));
1653
+ let a = n.ownerDocument.createElement("li");
1654
+ a.appendChild(n), t.appendChild(a);
1655
+ }
1656
+ }
1657
+ function mn(e) {
1658
+ let t = (e, t) => {
1659
+ for (; e && e.nodeType === Node.TEXT_NODE && hn(e.textContent);) e = e[t];
1660
+ return e;
1661
+ }, n = (e) => !e || an.has(e.tagName);
1662
+ return n(t(e.previousSibling, "previousSibling")) && n(t(e.nextSibling, "nextSibling"));
1663
+ }
1664
+ var hn = (e) => !(e ?? "").replace(/[\s\u00a0\u200b]/g, "");
1665
+ function gn(e, t = document) {
1666
+ if (/<[^>]+\sdata-pm-slice=/.test(e)) return e;
1667
+ let n = new ((t.defaultView?.DOMParser) ?? DOMParser)().parseFromString(e, "text/html"), r = n.body, i = [], a = n.createTreeWalker(r, NodeFilter.SHOW_COMMENT);
1668
+ for (; a.nextNode();) i.push(a.currentNode);
1669
+ i.forEach((e) => e.parentNode?.removeChild(e)), r.querySelectorAll(rn).forEach((e) => e.remove()), r.querySelectorAll("br.Apple-interchange-newline").forEach((e) => e.remove()), pn(r), r.querySelectorAll("span[style]").forEach((e) => {
1670
+ if (fn(e)) {
1671
+ let t = (e.textContent ?? "").replace(/[\s\u00a0]+/g, " ").trim();
1672
+ e.replaceWith(n.createTextNode(t ? `${t} ` : ""));
1673
+ }
1674
+ }), r.querySelectorAll("b, strong").forEach((e) => {
1675
+ (/^(normal|[1-4]00)$/.test(e.style.fontWeight) || e.id.startsWith("docs-internal-guid")) && cn(e);
1676
+ }), r.querySelectorAll("span").forEach((e) => {
1677
+ e.textContent && /^[\s\u00a0]+$/.test(e.textContent) && !e.children.length && e.replaceWith(n.createTextNode(" "));
1678
+ }), [...r.querySelectorAll("span[style], font[style]")].reverse().forEach((e) => ln(e, un(e)));
1679
+ for (let e of [...r.querySelectorAll("*")]) {
1680
+ if (e.tagName === "IMG") continue;
1681
+ let t = [...e.classList].filter((e) => e.startsWith("wysio-"));
1682
+ for (let t of [...e.attributes]) on.has(t.name.toLowerCase()) || e.removeAttribute(t.name);
1683
+ t.length && e.setAttribute("class", t.join(" "));
1684
+ }
1685
+ return [...r.querySelectorAll("*")].reverse().forEach((e) => {
1686
+ ((e.tagName === "SPAN" || e.tagName === "FONT") && !e.hasAttribute("class") || e.tagName.includes(":")) && cn(e);
1687
+ }), r.querySelectorAll("br").forEach((e) => {
1688
+ mn(e) && e.remove();
1689
+ }), r.querySelectorAll("p").forEach((e) => {
1690
+ hn(e.textContent) && !e.querySelector("img, br, table, hr") && e.remove();
1691
+ }), r.innerHTML;
1692
+ }
1693
+ var _n = m({
1694
+ name: "paste",
1695
+ prosemirrorPlugins: ({ editor: e }) => [new p({ props: { transformPastedHTML: (t) => gn(t, e.dom.ownerDocument) } })]
1696
+ }), vn = m({
1697
+ name: "placeholder",
1698
+ prosemirrorPlugins: ({ editor: e }) => [new p({ props: {
1699
+ decorations: (t) => {
1700
+ let n = e.options.placeholder, r = t.doc.firstChild;
1701
+ return !n || !r || !Fe(t.doc) ? null : ae.create(t.doc, [ie.node(0, r.nodeSize, {
1702
+ class: "wysio-placeholder",
1703
+ "data-placeholder": n
1704
+ })]);
1705
+ },
1706
+ attributes: () => {
1707
+ let t = e.options.placeholder;
1708
+ return t ? { "aria-placeholder": t } : {};
1709
+ }
1710
+ } })]
1711
+ }), yn = /* @__PURE__ */ new Set([
1712
+ "UL",
1713
+ "OL",
1714
+ "LI",
1715
+ "BLOCKQUOTE",
1716
+ "TABLE",
1717
+ "THEAD",
1718
+ "TBODY",
1719
+ "TR",
1720
+ "TD",
1721
+ "TH"
1722
+ ]), bn = /* @__PURE__ */ new Set([
1723
+ ...yn,
1724
+ "P",
1725
+ "H1",
1726
+ "H2",
1727
+ "H3",
1728
+ "H4",
1729
+ "H5",
1730
+ "H6",
1731
+ "HR",
1732
+ "PRE",
1733
+ "DIV"
1734
+ ]), xn = (e) => [...e.children].some((e) => bn.has(e.tagName));
1735
+ function Sn(e) {
1736
+ let t = e.cloneNode(!1).outerHTML, n = t.lastIndexOf("</");
1737
+ return n === -1 ? t : t.slice(0, n);
1738
+ }
1739
+ function Cn(e, t = " ", n = document) {
1740
+ let r = n.createElement("div");
1741
+ r.innerHTML = e;
1742
+ let i = [], a = (e, n) => {
1743
+ let r = t.repeat(n);
1744
+ if (e.nodeType === Node.TEXT_NODE) {
1745
+ (e.textContent ?? "").trim() && i.push(r + e.data.trim());
1746
+ return;
1747
+ }
1748
+ if (e.nodeType !== Node.ELEMENT_NODE) return;
1749
+ let o = e;
1750
+ yn.has(o.tagName) && xn(o) ? (i.push(r + Sn(o)), o.childNodes.forEach((e) => a(e, n + 1)), i.push(`${r}</${o.tagName.toLowerCase()}>`)) : i.push(r + o.outerHTML);
1751
+ };
1752
+ return r.childNodes.forEach((e) => a(e, 0)), i.join("\n");
1753
+ }
1754
+ // src/plugins/source.ts
1755
+ var wn = new ne("wysio-source"), Tn = class {
1756
+ editor;
1757
+ textarea;
1758
+ ownDoc = null;
1759
+ applying = !1;
1760
+ constructor(e) {
1761
+ this.editor = e;
1762
+ let t = e.dom.ownerDocument;
1763
+ this.textarea = t.createElement("textarea"), this.textarea.className = "wysio-source", this.textarea.spellcheck = !1, this.textarea.hidden = !0, this.textarea.setAttribute("aria-label", e.t("source.label")), this.textarea.setAttribute("autocapitalize", "off"), this.textarea.setAttribute("autocomplete", "off"), this.textarea.addEventListener("input", () => this.apply()), e.view.dom.parentElement.after(this.textarea);
1764
+ }
1765
+ get body() {
1766
+ return this.editor.view.dom.parentElement;
1767
+ }
1768
+ open() {
1769
+ this.ownDoc = this.editor.view.state.doc, this.textarea.value = Cn(this.editor.getHTML(), " ", this.editor.dom.ownerDocument), this.textarea.readOnly = !this.editor.isEditable;
1770
+ let e = this.body.offsetHeight;
1771
+ e && (this.textarea.style.height = `${e}px`), this.body.hidden = !0, this.textarea.hidden = !1, this.editor.setMode("source"), this.textarea.focus(), this.textarea.setSelectionRange(0, 0), this.textarea.scrollTop = 0;
1772
+ }
1773
+ close() {
1774
+ this.textarea.hidden = !0, this.body.hidden = !1, this.editor.setMode("wysiwyg"), this.editor.focus();
1775
+ }
1776
+ apply() {
1777
+ let { view: e, schema: t } = this.editor, n = _(t, this.textarea.value, this.editor.dom.ownerDocument);
1778
+ if (!n.eq(e.state.doc)) {
1779
+ this.applying = !0;
1780
+ try {
1781
+ e.dispatch(e.state.tr.replaceWith(0, e.state.doc.content.size, n.content).setMeta(wn, !0));
1782
+ } finally {
1783
+ this.applying = !1;
1784
+ }
1785
+ this.ownDoc = e.state.doc;
1786
+ }
1787
+ }
1788
+ sync() {
1789
+ if (this.editor.mode !== "source" || this.applying) return;
1790
+ this.textarea.readOnly = !this.editor.isEditable;
1791
+ let { doc: e } = this.editor.view.state;
1792
+ e !== this.ownDoc && (this.ownDoc = e, this.textarea.value = Cn(this.editor.getHTML(), " ", this.editor.dom.ownerDocument));
1793
+ }
1794
+ }, Z = /* @__PURE__ */ new WeakMap();
1795
+ function En(e) {
1796
+ let t = Z.get(e);
1797
+ return t || Z.set(e, t = new Tn(e)), t;
1798
+ }
1799
+ function Dn(e) {
1800
+ if (!e.hasPlugin("source")) return;
1801
+ let t = En(e);
1802
+ e.mode === "source" ? t.close() : t.open();
1803
+ }
1804
+ var On = m({
1805
+ name: "source",
1806
+ prosemirrorPlugins: ({ editor: e }) => [new p({
1807
+ key: wn,
1808
+ view: () => (Z.get(e)?.sync(), { update: () => Z.get(e)?.sync() })
1809
+ })],
1810
+ toolbarItems: ({ editor: e }) => ({ source: {
1811
+ label: e.t("source"),
1812
+ icon: x.source,
1813
+ run: Dn,
1814
+ isActive: () => e.mode === "source",
1815
+ isEnabled: () => !0,
1816
+ availableInSourceMode: !0
1817
+ } })
1818
+ }), kn = 10, An = 50, Q = (e) => {
1819
+ let t = Number(e);
1820
+ return Number.isInteger(t) && t >= 1 && t <= An ? t : 1;
1821
+ }, jn = {
1822
+ colspan: {
1823
+ default: 1,
1824
+ validate: "number"
1825
+ },
1826
+ rowspan: {
1827
+ default: 1,
1828
+ validate: "number"
1829
+ },
1830
+ colwidth: { default: null }
1831
+ };
1832
+ function Mn(e, t) {
1833
+ return {
1834
+ content: "block+",
1835
+ attrs: jn,
1836
+ tableRole: t,
1837
+ isolating: !0,
1838
+ parseDOM: [{
1839
+ tag: e,
1840
+ getAttrs: (e) => {
1841
+ let t = e;
1842
+ return {
1843
+ colspan: Q(t.getAttribute("colspan") ?? 1),
1844
+ rowspan: Q(t.getAttribute("rowspan") ?? 1)
1845
+ };
1846
+ }
1847
+ }],
1848
+ toDOM: (t) => {
1849
+ let n = {}, r = Q(t.attrs.colspan), i = Q(t.attrs.rowspan);
1850
+ return r !== 1 && (n.colspan = String(r)), i !== 1 && (n.rowspan = String(i)), [
1851
+ e,
1852
+ n,
1853
+ 0
1854
+ ];
1855
+ }
1856
+ };
1857
+ }
1858
+ function Nn(e, t, n, r = !0) {
1859
+ let { table: i, table_row: a, table_cell: o, table_header: s } = e.nodes;
1860
+ if (!i || !a || !o || !s) throw Error("[wysio] The table plugin is not enabled.");
1861
+ let c = (e) => Math.min(10, Math.max(1, Math.trunc(e) || 1));
1862
+ return i.create(null, Array.from({ length: c(t) }, (e, t) => a.create(null, Array.from({ length: c(n) }, () => (r && t === 0 ? s : o).createAndFill()))));
1863
+ }
1864
+ function Pn(e, t, n = !0) {
1865
+ return (r, i) => {
1866
+ if (!r.schema.nodes.table || h(r)) return !1;
1867
+ let a = Nn(r.schema, e, t, n), { $from: o } = r.selection, s = !1;
1868
+ for (let e = o.depth; e >= 0 && !s; e--) {
1869
+ let t = o.index(e);
1870
+ s = o.node(e).canReplaceWith(t, t, a.type);
1871
+ }
1872
+ if (!s) return !1;
1873
+ if (i) {
1874
+ let e = r.tr.replaceSelectionWith(a), t = -1;
1875
+ e.doc.descendants((e, n) => (e === a && (t = n), t === -1)), t !== -1 && e.setSelection(re.near(e.doc.resolve(t + 4))), i(e.scrollIntoView());
1876
+ }
1877
+ return !0;
1878
+ };
1879
+ }
1880
+ var Fn = (e, t) => {
1881
+ let { table: n, table_cell: r, table_header: i } = e.schema.nodes, a = n && r && i ? M(e, [n]) : null, o = a?.node.firstChild;
1882
+ if (!a || !o || !r || !i) return !1;
1883
+ if (t) {
1884
+ let n = o.content.content.some((e) => e.type !== i), s = e.tr;
1885
+ o.forEach((e, t) => {
1886
+ s.setNodeMarkup(a.pos + 2 + t, n ? i : r, e.attrs);
1887
+ }), t(s);
1888
+ }
1889
+ return !0;
1890
+ }, In = (e, t, n) => h(e) ? ke(1)(e, t, n) ? !0 : !t || !n ? we(e) : (we(e, t), ke(1)(n.state, t, n)) : !1;
1891
+ function Ln(e) {
1892
+ return [
1893
+ {
1894
+ name: "tableAddRowBefore",
1895
+ label: "table.addRowBefore",
1896
+ command: Te,
1897
+ icon: x.tableRowBefore
1898
+ },
1899
+ {
1900
+ name: "tableAddRowAfter",
1901
+ label: "table.addRowAfter",
1902
+ command: we,
1903
+ icon: x.tableRowAfter
1904
+ },
1905
+ {
1906
+ name: "tableAddColumnBefore",
1907
+ label: "table.addColumnBefore",
1908
+ command: Ce,
1909
+ icon: x.tableColumnBefore
1910
+ },
1911
+ {
1912
+ name: "tableAddColumnAfter",
1913
+ label: "table.addColumnAfter",
1914
+ command: Se,
1915
+ icon: x.tableColumnAfter
1916
+ },
1917
+ {
1918
+ name: "tableDeleteRow",
1919
+ label: "table.deleteRow",
1920
+ command: De,
1921
+ icon: x.tableDeleteRow
1922
+ },
1923
+ {
1924
+ name: "tableDeleteColumn",
1925
+ label: "table.deleteColumn",
1926
+ command: Ee,
1927
+ icon: x.tableDeleteColumn
1928
+ },
1929
+ {
1930
+ name: "tableToggleHeaderRow",
1931
+ label: "table.toggleHeaderRow",
1932
+ command: Fn,
1933
+ icon: x.tableHeaderRow
1934
+ },
1935
+ {
1936
+ name: "tableDelete",
1937
+ label: "table.delete",
1938
+ command: Oe,
1939
+ icon: x.tableDelete
1940
+ }
1941
+ ].map((t) => ({
1942
+ ...t,
1943
+ label: e.t(t.label)
1944
+ }));
1945
+ }
1946
+ function Rn(e) {
1947
+ e.isEditable && e.schema.nodes.table && w(e, "table", () => new zn(e)).open();
1948
+ }
1949
+ var zn = class extends S {
1950
+ picker;
1951
+ actions;
1952
+ cells = [];
1953
+ size;
1954
+ header;
1955
+ actionButtons = [];
1956
+ constructor(e) {
1957
+ super(e, e.t("table"));
1958
+ let t = e.dom.ownerDocument;
1959
+ this.dom.classList.add("wysio-popover-table");
1960
+ let n = Ue(t, this.uid, "<div class=\"wysio-table-picker\">\n <div class=\"wysio-table-grid\" role=\"group\"></div>\n <p class=\"wysio-table-size\" aria-live=\"polite\"></p>\n <label class=\"wysio-check\"><input type=\"checkbox\" name=\"header\" checked> <span></span></label>\n </div>\n <div class=\"wysio-table-actions\"></div>");
1961
+ this.picker = T(n, ".wysio-table-picker"), this.actions = T(n, ".wysio-table-actions"), this.size = T(n, ".wysio-table-size"), this.header = T(n, "input[name=header]"), T(n, ".wysio-check span").textContent = e.t("table.header");
1962
+ let r = T(n, ".wysio-table-grid");
1963
+ r.setAttribute("aria-label", e.t("table.size"));
1964
+ for (let e = 1; e <= 10; e++) for (let n = 1; n <= 10; n++) {
1965
+ let i = t.createElement("button");
1966
+ i.type = "button", i.className = "wysio-table-cell", i.tabIndex = -1, i.dataset.rows = String(e), i.dataset.cols = String(n), i.setAttribute("aria-label", this.sizeLabel(e, n)), i.addEventListener("mouseenter", () => this.highlight(e, n)), i.addEventListener("focus", () => this.highlight(e, n)), i.addEventListener("click", () => this.insert(e, n)), r.appendChild(i), this.cells.push(i);
1967
+ }
1968
+ r.addEventListener("keydown", this.onGridKey);
1969
+ for (let n of Ln(e)) {
1970
+ let e = t.createElement("button");
1971
+ e.type = "button", e.className = "wysio-menu-item", e.dataset.action = n.name, e.innerHTML = n.icon, e.append(t.createTextNode(n.label)), e.addEventListener("click", () => {
1972
+ this.close(!1), this.editor.exec(n.command);
1973
+ }), this.actions.appendChild(e), this.actionButtons.push({
1974
+ button: e,
1975
+ action: n
1976
+ });
1977
+ }
1978
+ this.actions.addEventListener("keydown", this.onActionsKey), this.dom.appendChild(n);
1979
+ }
1980
+ open() {
1981
+ let { state: e } = this.editor.view, t = h(e);
1982
+ if (this.picker.hidden = t, this.actions.hidden = !t, this.dom.setAttribute("aria-label", this.editor.t(t ? "table" : "table.insert")), t) {
1983
+ for (let { button: t, action: n } of this.actionButtons) t.disabled = !n.command(e);
1984
+ let t = this.actionButtons.find((e) => !e.button.disabled)?.button;
1985
+ this.show(e.selection.from, t ?? this.actions);
1986
+ } else this.highlight(1, 1), this.show(e.selection.from, this.cell(1, 1));
1987
+ }
1988
+ sizeLabel(e, t) {
1989
+ return this.editor.t("table.cells", {
1990
+ rows: e,
1991
+ cols: t
1992
+ });
1993
+ }
1994
+ cell(e, t) {
1995
+ return this.cells[(e - 1) * 10 + (t - 1)];
1996
+ }
1997
+ highlight(e, t) {
1998
+ for (let n of this.cells) {
1999
+ let r = Number(n.dataset.rows) <= e && Number(n.dataset.cols) <= t;
2000
+ n.classList.toggle("wysio-active", r), n.tabIndex = Number(n.dataset.rows) === e && Number(n.dataset.cols) === t ? 0 : -1;
2001
+ }
2002
+ this.size.textContent = this.sizeLabel(e, t);
2003
+ }
2004
+ insert(e, t) {
2005
+ this.close(!1), this.editor.exec(Pn(e, t, this.header.checked));
2006
+ }
2007
+ onGridKey = (e) => {
2008
+ let t = e.target, n = Number(t.dataset.rows), r = Number(t.dataset.cols);
2009
+ if (n && r) {
2010
+ if (e.key === "ArrowRight") r++;
2011
+ else if (e.key === "ArrowLeft") r--;
2012
+ else if (e.key === "ArrowDown") n++;
2013
+ else if (e.key === "ArrowUp") n--;
2014
+ else if (e.key === "Home") r = 1;
2015
+ else if (e.key === "End") r = 10;
2016
+ else return;
2017
+ e.preventDefault(), n = Math.min(10, Math.max(1, n)), r = Math.min(10, Math.max(1, r)), this.cell(n, r)?.focus();
2018
+ }
2019
+ };
2020
+ onActionsKey = (e) => {
2021
+ let t = this.actionButtons.map((e) => e.button).filter((e) => !e.disabled), n = t.indexOf(e.target), r = null;
2022
+ e.key === "ArrowDown" ? r = (n + 1) % t.length : e.key === "ArrowUp" ? r = (n - 1 + t.length) % t.length : e.key === "Home" ? r = 0 : e.key === "End" && (r = t.length - 1), r !== null && (e.preventDefault(), t[r]?.focus());
2023
+ };
2024
+ }, Bn = (e) => (t) => h(t) && e(t), Vn = m({
2025
+ name: "table",
2026
+ schema: { nodes: {
2027
+ table: {
2028
+ content: "table_row+",
2029
+ tableRole: "table",
2030
+ isolating: !0,
2031
+ group: "block",
2032
+ parseDOM: [{ tag: "table" }],
2033
+ toDOM: () => ["table", ["tbody", 0]]
2034
+ },
2035
+ table_row: {
2036
+ content: "(table_cell | table_header)*",
2037
+ tableRole: "row",
2038
+ parseDOM: [{ tag: "tr" }],
2039
+ toDOM: () => ["tr", 0]
2040
+ },
2041
+ table_cell: Mn("td", "cell"),
2042
+ table_header: Mn("th", "header_cell")
2043
+ } },
2044
+ keymap: () => ({
2045
+ Tab: In,
2046
+ "Shift-Tab": ke(-1)
2047
+ }),
2048
+ prosemirrorPlugins: () => [Ae()],
2049
+ toolbarItems: ({ editor: e }) => {
2050
+ let t = { table: {
2051
+ label: e.t("table"),
2052
+ icon: x.table,
2053
+ run: Rn,
2054
+ popover: "table",
2055
+ isActive: (e) => h(e),
2056
+ isEnabled: (e) => h(e) || Pn(1, 1)(e)
2057
+ } };
2058
+ for (let n of Ln(e)) t[n.name] = {
2059
+ label: n.label,
2060
+ icon: n.icon,
2061
+ command: n.command,
2062
+ isEnabled: Bn(n.command)
2063
+ };
2064
+ return t;
2065
+ }
2066
+ }), Hn = [
2067
+ $e,
2068
+ Tt,
2069
+ nt,
2070
+ Zt,
2071
+ rt,
2072
+ Vn,
2073
+ it,
2074
+ Wt(),
2075
+ Xt,
2076
+ Qt,
2077
+ $t,
2078
+ en,
2079
+ tn,
2080
+ nn,
2081
+ St(),
2082
+ Ct(),
2083
+ Qe,
2084
+ ct,
2085
+ _n,
2086
+ On,
2087
+ Dt,
2088
+ vn
2089
+ ];
2090
+ // src/schema.ts
2091
+ function Un(e) {
2092
+ let t = {}, n = {};
2093
+ for (let r of e) {
2094
+ for (let [e, n] of Object.entries(r.schema?.nodes ?? {})) {
2095
+ if (e in t) throw Error(`[wysio] Node "${e}" is defined twice (plugin "${r.name}").`);
2096
+ t[e] = n;
2097
+ }
2098
+ for (let [e, t] of Object.entries(r.schema?.marks ?? {})) {
2099
+ if (e in n) throw Error(`[wysio] Mark "${e}" is defined twice (plugin "${r.name}").`);
2100
+ n[e] = t;
2101
+ }
2102
+ }
2103
+ for (let n of e) for (let [e, r] of Object.entries(n.schema?.extendNodes ?? {})) {
2104
+ let n = t[e];
2105
+ n && (t[e] = r(n));
2106
+ }
2107
+ return new ue({
2108
+ nodes: t,
2109
+ marks: n
2110
+ });
2111
+ }
2112
+ var Wn = () => typeof navigator < "u" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
2113
+ function Gn(e) {
2114
+ let t = Wn();
2115
+ return e.split("-").map((e) => {
2116
+ switch (e) {
2117
+ case "Mod": return t ? "⌘" : "Ctrl";
2118
+ case "Shift": return t ? "⇧" : "Shift";
2119
+ case "Alt": return t ? "⌥" : "Alt";
2120
+ case "Ctrl": return t ? "⌃" : "Ctrl";
2121
+ default: return e.length === 1 ? e.toUpperCase() : e;
2122
+ }
2123
+ }).join(t ? "" : "+");
2124
+ }
2125
+ function Kn(e, t) {
2126
+ let n = 0;
2127
+ for (; n < e.length && e[n] <= t;) n++;
2128
+ return n;
2129
+ }
2130
+ var qn = "<svg class=\"wysio-caret\" viewBox=\"0 0 10 10\" width=\"8\" height=\"8\" aria-hidden=\"true\" focusable=\"false\"><path d=\"m2 3.5 3 3 3-3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>", Jn = 0, Yn = class {
2131
+ editor;
2132
+ dom;
2133
+ controls = [];
2134
+ entries = [];
2135
+ more = null;
2136
+ panel = null;
2137
+ observer = null;
2138
+ constructor(e, t, n, { warnUnknown: r = !0, mode: i = "overflow" } = {}) {
2139
+ this.editor = e;
2140
+ let a = e.dom.ownerDocument;
2141
+ this.dom = a.createElement("div"), this.dom.className = "wysio-toolbar", this.dom.dataset.mode = i, this.dom.setAttribute("role", "toolbar"), e.locale && (this.dom.lang = e.locale), this.dom.setAttribute("aria-label", e.t("toolbar")), this.dom.setAttribute("aria-controls", e.view.dom.id);
2142
+ let o = !0;
2143
+ for (let e of t) {
2144
+ if (e === "|") {
2145
+ if (o) continue;
2146
+ let e = a.createElement("span");
2147
+ e.className = "wysio-separator", e.setAttribute("role", "separator"), e.setAttribute("aria-orientation", "vertical"), this.entries.push(e), o = !0;
2148
+ continue;
2149
+ }
2150
+ let t = n.get(e);
2151
+ if (!t) {
2152
+ r && console.warn(`[wysio] Unknown toolbar item "${e}".`);
2153
+ continue;
2154
+ }
2155
+ let i = t.type === "select" ? this.createSelect(e, t) : this.createButton(e, t);
2156
+ this.controls.push(i), this.entries.push(i.el), o = !1;
2157
+ }
2158
+ this.entries.at(-1)?.classList.contains("wysio-separator") && this.entries.pop(), this.dom.append(...this.entries), i === "overflow" && this.setUpOverflow(), this.dom.addEventListener("keydown", this.onKeyDown), this.dom.addEventListener("focusin", this.onFocusIn), e.dom.addEventListener("wysio:popover", this.onPopover), this.controls[0]?.el.setAttribute("tabindex", "0");
2159
+ }
2160
+ label(e, t) {
2161
+ return t.labelKey ? this.editor.t(t.labelKey) : t.label ?? e;
2162
+ }
2163
+ createButton(e, t) {
2164
+ let n = this.editor.dom.ownerDocument, r = n.createElement("button"), i = this.label(e, t);
2165
+ r.type = "button", r.className = "wysio-tool", r.dataset.item = e, r.tabIndex = -1;
2166
+ let a = n.createElement("span");
2167
+ return a.className = "wysio-icon", a.innerHTML = t.icon, r.appendChild(a), t.dropdown && r.insertAdjacentHTML("beforeend", qn), r.setAttribute("aria-label", i), r.title = t.shortcut ? `${i} (${Gn(t.shortcut)})` : i, t.isActive && r.setAttribute("aria-pressed", "false"), t.popover && (r.setAttribute("aria-haspopup", "dialog"), r.setAttribute("aria-expanded", "false")), r.addEventListener("mousedown", (e) => e.preventDefault()), r.addEventListener("click", () => {
2168
+ r.getAttribute("aria-disabled") !== "true" && (t.run ? t.run(this.editor) : t.command && this.editor.exec(t.command));
2169
+ }), {
2170
+ kind: "button",
2171
+ item: t,
2172
+ el: r,
2173
+ icon: a
2174
+ };
2175
+ }
2176
+ createSelect(e, t) {
2177
+ let n = this.editor.dom.ownerDocument, r = n.createElement("select"), i = this.label(e, t);
2178
+ r.className = "wysio-select", r.dataset.item = e, r.tabIndex = -1, r.setAttribute("aria-label", i), r.title = i;
2179
+ let a = n.createElement("option");
2180
+ a.value = "", a.hidden = !0, a.textContent = "—", r.appendChild(a);
2181
+ for (let e of t.options) {
2182
+ let t = n.createElement("option");
2183
+ t.value = e.value, t.textContent = e.label, r.appendChild(t);
2184
+ }
2185
+ return r.addEventListener("change", () => {
2186
+ r.value && t.onSelect(this.editor, r.value);
2187
+ }), {
2188
+ kind: "select",
2189
+ item: t,
2190
+ el: r
2191
+ };
2192
+ }
2193
+ update(e) {
2194
+ let t = this.editor.isEditable, n = this.editor.mode === "wysiwyg";
2195
+ for (let r of this.controls) {
2196
+ let { item: i, el: a } = r, o = i.availableInSourceMode || t && n;
2197
+ if (o && (i.isEnabled ? o = i.isEnabled(e, this.editor) : r.kind === "button" && r.item.command && (o = r.item.command(e))), r.kind === "select") {
2198
+ r.el.disabled = !o, r.el.value = r.item.getValue(e);
2199
+ continue;
2200
+ }
2201
+ if (a.setAttribute("aria-disabled", String(!o)), r.item.isActive) {
2202
+ let t = (n || !!i.availableInSourceMode) && r.item.isActive(e);
2203
+ a.setAttribute("aria-pressed", String(t));
2204
+ }
2205
+ let { icon: s } = r;
2206
+ r.item.render?.(e, {
2207
+ el: r.el,
2208
+ setIcon: (e) => {
2209
+ s.innerHTML !== e && (s.innerHTML = e);
2210
+ }
2211
+ });
2212
+ }
2213
+ }
2214
+ focus() {
2215
+ let e = this.focusable();
2216
+ (e.find((e) => e.tabIndex === 0) ?? e[0])?.focus();
2217
+ }
2218
+ destroy() {
2219
+ this.observer?.disconnect(), this.closePanel(!1), this.editor.dom.removeEventListener("wysio:popover", this.onPopover), this.dom.remove();
2220
+ }
2221
+ setUpOverflow() {
2222
+ let e = this.editor.dom.ownerDocument, t = `wysio-toolbar-more-${++Jn}`;
2223
+ this.more = e.createElement("button"), this.more.type = "button", this.more.className = "wysio-tool wysio-more", this.more.tabIndex = -1, this.more.hidden = !0, this.more.innerHTML = "<svg viewBox=\"0 0 24 24\" width=\"18\" height=\"18\" aria-hidden=\"true\" focusable=\"false\"><circle cx=\"5\" cy=\"12\" r=\"1.75\" fill=\"currentColor\"/><circle cx=\"12\" cy=\"12\" r=\"1.75\" fill=\"currentColor\"/><circle cx=\"19\" cy=\"12\" r=\"1.75\" fill=\"currentColor\"/></svg>", this.more.setAttribute("aria-label", this.editor.t("toolbar.more")), this.more.title = this.editor.t("toolbar.more"), this.more.setAttribute("aria-expanded", "false"), this.more.setAttribute("aria-controls", t), this.more.addEventListener("mousedown", (e) => e.preventDefault()), this.more.addEventListener("click", () => {
2224
+ this.panel?.hidden ? this.openPanel() : this.closePanel(!0);
2225
+ }), this.panel = e.createElement("div"), this.panel.id = t, this.panel.className = "wysio-toolbar-panel", this.panel.hidden = !0, this.panel.setAttribute("role", "group"), this.panel.setAttribute("aria-label", this.editor.t("toolbar.more")), this.panel.addEventListener("keydown", this.onPanelKey), this.panel.addEventListener("click", (e) => {
2226
+ let t = e.target.closest("button");
2227
+ t && t.getAttribute("aria-disabled") !== "true" && this.closePanel(!1);
2228
+ }), this.panel.addEventListener("change", () => this.closePanel(!1)), this.dom.append(this.more, this.panel), typeof ResizeObserver < "u" && (this.observer = new ResizeObserver(() => this.layout()), this.observer.observe(this.dom));
2229
+ }
2230
+ layout() {
2231
+ let { more: e, panel: t } = this;
2232
+ if (!e || !t) return;
2233
+ let n = this.editor.dom.ownerDocument.activeElement;
2234
+ for (let t of this.entries) this.dom.insertBefore(t, e);
2235
+ if (e.hidden = !0, this.dom.scrollWidth <= this.dom.clientWidth) {
2236
+ this.closePanel(!1), this.ensureTabStop();
2237
+ return;
2238
+ }
2239
+ e.hidden = !1;
2240
+ let r = getComputedStyle(this.dom), i = parseFloat(r.columnGap) || 0, a = this.dom.clientWidth - (parseFloat(r.paddingRight) || 0) - e.offsetWidth - i, o = Kn(this.entries.map((e) => e.offsetLeft + e.offsetWidth), a);
2241
+ for (; o > 0 && this.entries[o - 1].classList.contains("wysio-separator");) o--;
2242
+ for (let e of this.entries.slice(o)) t.appendChild(e);
2243
+ this.ensureTabStop(), n instanceof HTMLElement && this.dom.contains(n) && n.focus();
2244
+ }
2245
+ openPanel() {
2246
+ let { more: e, panel: t } = this;
2247
+ e && t && (t.hidden = !1, e.setAttribute("aria-expanded", "true"), this.editor.dom.ownerDocument.addEventListener("mousedown", this.onOutside, !0), this.panelItems()[0]?.focus());
2248
+ }
2249
+ closePanel(e) {
2250
+ let { more: t, panel: n } = this;
2251
+ t && n && !n.hidden && (n.hidden = !0, t.setAttribute("aria-expanded", "false"), this.editor.dom.ownerDocument.removeEventListener("mousedown", this.onOutside, !0), e && t.focus());
2252
+ }
2253
+ panelItems() {
2254
+ return this.panel ? this.controls.map((e) => e.el).filter((e) => this.panel.contains(e) && !(e instanceof HTMLSelectElement && e.disabled)) : [];
2255
+ }
2256
+ onOutside = (e) => {
2257
+ let t = e.target;
2258
+ !this.panel?.contains(t) && !this.more?.contains(t) && this.closePanel(!1);
2259
+ };
2260
+ onPanelKey = (e) => {
2261
+ if (e.stopPropagation(), e.key === "Escape") {
2262
+ e.preventDefault(), this.closePanel(!0);
2263
+ return;
2264
+ }
2265
+ if (e.target instanceof HTMLSelectElement && (e.key === "ArrowUp" || e.key === "ArrowDown")) return;
2266
+ let t = this.panelItems(), n = t.indexOf(e.target), r = null;
2267
+ e.key === "ArrowRight" || e.key === "ArrowDown" ? r = (n + 1) % t.length : e.key === "ArrowLeft" || e.key === "ArrowUp" ? r = (n - 1 + t.length) % t.length : e.key === "Home" ? r = 0 : e.key === "End" && (r = t.length - 1), r !== null && (e.preventDefault(), t[r]?.focus());
2268
+ };
2269
+ focusable() {
2270
+ let e = this.controls.map((e) => e.el).filter((e) => e.parentElement === this.dom && !(e instanceof HTMLSelectElement && e.disabled));
2271
+ return this.more && !this.more.hidden ? [...e, this.more] : e;
2272
+ }
2273
+ ensureTabStop() {
2274
+ let e = this.focusable();
2275
+ if (!e.some((e) => e.tabIndex === 0)) {
2276
+ for (let e of this.controls) e.el.tabIndex = -1;
2277
+ this.more && (this.more.tabIndex = -1), e[0] && (e[0].tabIndex = 0);
2278
+ }
2279
+ }
2280
+ onFocusIn = (e) => {
2281
+ let t = e.target;
2282
+ if (this.focusable().includes(t)) {
2283
+ for (let e of this.controls) e.el.tabIndex = e.el === t ? 0 : -1;
2284
+ this.more && (this.more.tabIndex = this.more === t ? 0 : -1);
2285
+ }
2286
+ };
2287
+ onKeyDown = (e) => {
2288
+ if (e.key === "Escape") {
2289
+ e.preventDefault(), this.editor.focus();
2290
+ return;
2291
+ }
2292
+ let t = this.focusable();
2293
+ if (!t.length) return;
2294
+ let n = t.indexOf(e.target);
2295
+ if (n === -1) return;
2296
+ let r = null;
2297
+ e.key === "ArrowRight" ? r = (n + 1) % t.length : e.key === "ArrowLeft" ? r = (n - 1 + t.length) % t.length : e.key === "Home" ? r = 0 : e.key === "End" && (r = t.length - 1), r !== null && (e.preventDefault(), t[r]?.focus());
2298
+ };
2299
+ onPopover = (e) => {
2300
+ let { key: t, open: n } = e.detail;
2301
+ for (let e of this.controls) e.kind === "button" && e.item.popover === t && e.el.setAttribute("aria-expanded", String(n));
2302
+ };
2303
+ }, Xn = [
2304
+ "heading",
2305
+ "|",
2306
+ "bold",
2307
+ "italic",
2308
+ "underline",
2309
+ "strike",
2310
+ "code",
2311
+ "|",
2312
+ "textColor",
2313
+ "highlight",
2314
+ "clearFormatting",
2315
+ "|",
2316
+ "align",
2317
+ "bulletList",
2318
+ "orderedList",
2319
+ "blockquote",
2320
+ "horizontalRule",
2321
+ "table",
2322
+ "|",
2323
+ "link",
2324
+ "image",
2325
+ "|",
2326
+ "undo",
2327
+ "redo"
2328
+ ], Zn = 0, Qn = class {
2329
+ dom;
2330
+ view;
2331
+ schema;
2332
+ options;
2333
+ emitter = new Ie();
2334
+ toolbar = null;
2335
+ textarea = null;
2336
+ input = null;
2337
+ form = null;
2338
+ initialContent = null;
2339
+ plugins;
2340
+ messages;
2341
+ locale;
2342
+ formats = /* @__PURE__ */ new Map();
2343
+ editable;
2344
+ currentMode = "wysiwyg";
2345
+ destroyed = !1;
2346
+ constructor(e, t = {}) {
2347
+ let n = typeof e == "string" ? document.querySelector(e) : e;
2348
+ if (!n) throw Error(`[wysio] Element not found: ${String(e)}`);
2349
+ this.options = t;
2350
+ let { locale: r, messages: i } = $n(t.locale);
2351
+ this.locale = r, this.messages = {
2352
+ ...v,
2353
+ ...i,
2354
+ ...t.messages
2355
+ }, this.editable = t.editable ?? !0, this.plugins = er(t), this.schema = Un(this.plugins);
2356
+ let a = t.content, o = t.format;
2357
+ n instanceof HTMLTextAreaElement ? (this.textarea = n, a ??= n.value, this.dom = n.ownerDocument.createElement("div"), n.insertAdjacentElement("afterend", this.dom), n.hidden = !0) : (this.dom = n, a === void 0 && (a = n.innerHTML.trim(), o = "html"), n.innerHTML = ""), this.dom.classList.add("wysio");
2358
+ let s = this.dom.ownerDocument, c = {
2359
+ schema: this.schema,
2360
+ editor: this
2361
+ };
2362
+ for (let e of this.plugins) for (let [t, n] of Object.entries(e.formats?.(c) ?? {})) this.formats.set(t, n);
2363
+ let l = s.createElement("div");
2364
+ l.className = "wysio-body", this.dom.appendChild(l);
2365
+ let u = `wysio-${++Zn}`;
2366
+ if (this.view = new oe(l, {
2367
+ state: ee.create({
2368
+ doc: this.parseContent(a, o),
2369
+ plugins: this.createProseMirrorPlugins(c)
2370
+ }),
2371
+ editable: () => this.editable,
2372
+ attributes: {
2373
+ id: u,
2374
+ class: "wysio-content",
2375
+ role: "textbox",
2376
+ "aria-multiline": "true",
2377
+ "aria-label": t.ariaLabel ?? this.t("editor")
2378
+ },
2379
+ dispatchTransaction: (e) => this.dispatch(e),
2380
+ handleDOMEvents: {
2381
+ focus: (e, t) => (this.emitter.emit("focus", this, t), !1),
2382
+ blur: (e, t) => (this.emitter.emit("blur", this, t), !1)
2383
+ }
2384
+ }), t.toolbar !== !1) {
2385
+ let e = /* @__PURE__ */ new Map();
2386
+ for (let t of this.plugins) for (let [n, r] of Object.entries(t.toolbarItems?.(c) ?? {})) e.set(n, r);
2387
+ if (this.toolbar = new Yn(this, t.toolbar ?? Xn, e, {
2388
+ warnUnknown: !!t.toolbar,
2389
+ mode: t.toolbarMode ?? "overflow"
2390
+ }), t.sticky) {
2391
+ this.dom.classList.add("wysio-sticky");
2392
+ let e = typeof t.sticky == "number" ? t.sticky : 0;
2393
+ this.dom.style.setProperty("--wysio-sticky-top", `${e}px`);
2394
+ }
2395
+ this.dom.insertBefore(this.toolbar.dom, l), this.toolbar.update(this.view.state);
2396
+ }
2397
+ t.name && this.textarea ? this.textarea.name = t.name : t.name && (this.input = s.createElement("input"), this.input.type = "hidden", this.input.name = t.name, this.dom.appendChild(this.input)), this.form = (this.textarea ?? this.input)?.form ?? null, this.form?.addEventListener("reset", this.onFormReset), this.initialContent = this.isEmpty ? null : this.getJSON(), this.syncTextarea();
2398
+ }
2399
+ createProseMirrorPlugins(t) {
2400
+ let n = this.plugins.flatMap((e) => e.inputRules?.(t) ?? []);
2401
+ return [
2402
+ c({ rules: n }),
2403
+ f({
2404
+ Backspace: u,
2405
+ "Alt-F10": () => (this.toolbar?.focus(), !!this.toolbar)
2406
+ }),
2407
+ ...this.plugins.flatMap((e) => e.keymap ? [f(e.keymap(t))] : []),
2408
+ f(e),
2409
+ ...this.plugins.flatMap((e) => e.prosemirrorPlugins?.(t) ?? [])
2410
+ ];
2411
+ }
2412
+ dispatch(e) {
2413
+ this.destroyed || (this.view.updateState(this.view.state.apply(e)), this.toolbar?.update(this.view.state), this.emitter.emit("transaction", this, e), e.docChanged && this.changed());
2414
+ }
2415
+ changed() {
2416
+ this.syncTextarea(), this.emitter.emit("change", this), this.options.onChange?.(this);
2417
+ }
2418
+ syncTextarea() {
2419
+ if (!this.textarea && !this.input) return;
2420
+ let e = this.serialize(this.options.format ?? "html");
2421
+ this.textarea && (this.textarea.value = e), this.input && (this.input.value = e);
2422
+ }
2423
+ onFormReset = () => {
2424
+ queueMicrotask(() => {
2425
+ this.destroyed || this.setContent(this.initialContent, { emitChange: !0 });
2426
+ });
2427
+ };
2428
+ get state() {
2429
+ return this.view.state;
2430
+ }
2431
+ get mode() {
2432
+ return this.currentMode;
2433
+ }
2434
+ setMode(e) {
2435
+ e !== this.currentMode && (this.currentMode = e, this.dom.dataset.mode = e, this.toolbar?.update(this.view.state), this.emitter.emit("mode", this, e));
2436
+ }
2437
+ get isEditable() {
2438
+ return this.editable;
2439
+ }
2440
+ get isEmpty() {
2441
+ return Fe(this.view.state.doc);
2442
+ }
2443
+ t(e, t) {
2444
+ return Ve(this.messages[e] ?? e, t);
2445
+ }
2446
+ getHTML() {
2447
+ return this.isEmpty ? "" : Me(this.schema, this.view.state.doc, this.dom.ownerDocument);
2448
+ }
2449
+ getJSON() {
2450
+ return this.view.state.doc.toJSON();
2451
+ }
2452
+ getMarkdown() {
2453
+ return this.serialize("markdown");
2454
+ }
2455
+ serialize(e) {
2456
+ if (e === "html") return this.getHTML();
2457
+ if (e === "json") return this.isEmpty ? "" : JSON.stringify(this.getJSON());
2458
+ let t = this.formatHandler(e);
2459
+ return this.isEmpty ? "" : t.serialize(this.view.state.doc);
2460
+ }
2461
+ formatHandler(e) {
2462
+ let t = this.formats.get(e);
2463
+ if (!t) throw Error(`[wysio] No plugin provides the "${e}" format.${e === "markdown" ? " Add it with: import { markdown } from 'wysio/markdown'; plugins: [markdown()]. On a CDN, use wysio.full.iife.js." : ""}`);
2464
+ return t;
2465
+ }
2466
+ parseContent(e, t = "html") {
2467
+ let n = this.dom.ownerDocument;
2468
+ return typeof e != "string" || e === "" || t === "html" ? _(this.schema, e, n) : t === "json" ? _(this.schema, JSON.parse(e), n) : Ne(this.schema, this.formatHandler(t).parse(e, this.schema), n);
2469
+ }
2470
+ getText() {
2471
+ let { doc: e } = this.view.state;
2472
+ return e.textBetween(0, e.content.size, "\n\n");
2473
+ }
2474
+ setContent(e, { emitChange: t = !1, format: n = this.options.format } = {}) {
2475
+ let r = ee.create({
2476
+ doc: this.parseContent(e, n),
2477
+ plugins: this.view.state.plugins
2478
+ });
2479
+ this.view.updateState(r), this.toolbar?.update(r), this.syncTextarea(), t && (this.emitter.emit("change", this), this.options.onChange?.(this));
2480
+ }
2481
+ setEditable(e) {
2482
+ this.editable = e, this.view.setProps({}), this.toolbar?.update(this.view.state);
2483
+ }
2484
+ exec(e) {
2485
+ if (!this.editable) return !1;
2486
+ let t = e(this.view.state, this.view.dispatch, this.view);
2487
+ return this.focus(), t;
2488
+ }
2489
+ reportError(e, t) {
2490
+ this.emitter.has("error") ? this.emitter.emit("error", this, e, t) : console.error(`[wysio] ${t.source} failed:`, e);
2491
+ }
2492
+ hasPlugin(e) {
2493
+ return this.plugins.some((t) => t.name === e);
2494
+ }
2495
+ focus() {
2496
+ this.destroyed || this.view.focus();
2497
+ }
2498
+ on(e, t) {
2499
+ return this.emitter.on(e, t);
2500
+ }
2501
+ off(e, t) {
2502
+ this.emitter.off(e, t);
2503
+ }
2504
+ destroy() {
2505
+ if (this.destroyed) return;
2506
+ let e = this.getHTML(), t = this.serialize(this.options.format ?? "html");
2507
+ this.emitter.emit("destroy", this), this.destroyed = !0, this.emitter.clear(), this.view.destroy(), this.toolbar?.destroy(), this.form?.removeEventListener("reset", this.onFormReset), this.input?.remove(), this.textarea ? (this.textarea.value = t, this.textarea.hidden = !1, this.dom.remove()) : (this.dom.classList.remove("wysio", "wysio-sticky"), this.dom.style.removeProperty("--wysio-sticky-top"), delete this.dom.dataset.mode, this.dom.innerHTML = e);
2508
+ }
2509
+ };
2510
+ function $n(e) {
2511
+ if (e == null) return {
2512
+ locale: "en",
2513
+ messages: {}
2514
+ };
2515
+ if (typeof e != "string") return {
2516
+ locale: null,
2517
+ messages: e
2518
+ };
2519
+ let t = Be(e);
2520
+ return t ? {
2521
+ locale: t.code,
2522
+ messages: t.messages
2523
+ } : (console.warn(`[wysio] Unknown locale "${e}", using English. Add it with registerLocale().`), {
2524
+ locale: "en",
2525
+ messages: {}
2526
+ });
2527
+ }
2528
+ function er(e) {
2529
+ let t = new Set(e.removePlugins ?? []);
2530
+ if (t.has("base")) throw Error("[wysio] The \"base\" plugin cannot be removed.");
2531
+ let n = de(e.plugins ?? []);
2532
+ return [...Hn.filter((e) => !t.has(e.name)).map((e) => {
2533
+ let t = n.findIndex((t) => t.name === e.name);
2534
+ return t === -1 ? e : n.splice(t, 1)[0];
2535
+ }), ...n];
2536
+ }
2537
+ function tr(e, t) {
2538
+ return new Qn(e, t);
2539
+ }
2540
+ // src/auto-init.ts
2541
+ var $ = /* @__PURE__ */ new WeakMap();
2542
+ function nr(e) {
2543
+ return $.get(e) ?? null;
2544
+ }
2545
+ function rr(e = {}, t = document) {
2546
+ let n = [];
2547
+ for (let r of t.querySelectorAll("[data-wysio]")) {
2548
+ if ($.has(r)) continue;
2549
+ let t;
2550
+ try {
2551
+ let e = r.dataset.wysioOptions;
2552
+ t = e ? JSON.parse(e) : {};
2553
+ } catch (e) {
2554
+ console.error("[wysio] Invalid JSON in data-wysio-options:", r, e);
2555
+ continue;
2556
+ }
2557
+ let i = typeof e == "function" ? e(r) : e, a;
2558
+ try {
2559
+ a = tr(r, {
2560
+ ...i,
2561
+ ...t,
2562
+ plugins: [...i.plugins ?? [], ...t.plugins ?? []],
2563
+ messages: {
2564
+ ...i.messages,
2565
+ ...t.messages
2566
+ }
2567
+ });
2568
+ } catch (e) {
2569
+ console.error("[wysio] Could not create an editor for", r, e);
2570
+ continue;
2571
+ }
2572
+ $.set(r, a), a.on("destroy", () => $.delete(r)), n.push(a);
2573
+ }
2574
+ return n;
2575
+ }
2576
+ // src/web-component.ts
2577
+ var ir = ["readonly", "disabled"];
2578
+ function ar() {
2579
+ return class extends HTMLElement {
2580
+ static formAssociated = !0;
2581
+ static observedAttributes = [
2582
+ "value",
2583
+ "placeholder",
2584
+ ...ir
2585
+ ];
2586
+ #e = null;
2587
+ #t = null;
2588
+ #n = null;
2589
+ #r = !1;
2590
+ constructor() {
2591
+ super();
2592
+ try {
2593
+ this.#t = this.attachInternals();
2594
+ } catch {
2595
+ this.#t = null;
2596
+ }
2597
+ }
2598
+ get editor() {
2599
+ return this.#e;
2600
+ }
2601
+ get #i() {
2602
+ return this.getAttribute("format") || "html";
2603
+ }
2604
+ get #a() {
2605
+ return typeof this.#t?.setFormValue == "function";
2606
+ }
2607
+ get value() {
2608
+ return this.#e ? this.#e.serialize(this.#i) : this.#n ?? this.getAttribute("value") ?? "";
2609
+ }
2610
+ set value(e) {
2611
+ let t = e == null ? "" : String(e);
2612
+ this.#e ? this.#e.setContent(t) : this.#n = t, this.#s();
2613
+ }
2614
+ get form() {
2615
+ return this.#t?.form ?? this.closest("form");
2616
+ }
2617
+ get name() {
2618
+ return this.getAttribute("name") ?? "";
2619
+ }
2620
+ connectedCallback() {
2621
+ if (this.#e) return;
2622
+ let e = this.getAttribute("toolbar"), t = this.getAttribute("plugins");
2623
+ this.#e = tr(this, {
2624
+ content: this.#n ?? this.getAttribute("value") ?? "",
2625
+ format: this.#i,
2626
+ plugins: t ? t.split(/[\s,]+/).filter(Boolean) : void 0,
2627
+ name: this.#a ? void 0 : this.getAttribute("name") || void 0,
2628
+ placeholder: this.getAttribute("placeholder") ?? void 0,
2629
+ locale: this.getAttribute("locale") ?? void 0,
2630
+ ariaLabel: this.getAttribute("aria-label") ?? void 0,
2631
+ toolbar: e === "false" ? !1 : e ? e.split(/[\s,]+/).filter(Boolean) : void 0,
2632
+ editable: this.#o(),
2633
+ onChange: () => {
2634
+ this.#s(), this.dispatchEvent(new Event("change", { bubbles: !0 }));
2635
+ }
2636
+ }), this.#n = null, this.#s();
2637
+ }
2638
+ disconnectedCallback() {
2639
+ this.#e && (this.#n = this.#e.serialize(this.#i), this.#e.destroy(), this.#e = null, this.innerHTML = "");
2640
+ }
2641
+ attributeChangedCallback(e, t, n) {
2642
+ t !== n && this.#e && (e === "value" ? (n ?? "") !== this.value && (this.value = n ?? "") : ir.includes(e) && this.#e.setEditable(this.#o()));
2643
+ }
2644
+ formResetCallback() {
2645
+ this.value = this.getAttribute("value") ?? "";
2646
+ }
2647
+ formDisabledCallback(e) {
2648
+ this.#r = e, this.#e?.setEditable(this.#o());
2649
+ }
2650
+ formStateRestoreCallback(e) {
2651
+ typeof e == "string" && (this.value = e);
2652
+ }
2653
+ #o() {
2654
+ return !this.#r && ir.every((e) => !this.hasAttribute(e));
2655
+ }
2656
+ #s() {
2657
+ this.#a && this.#t.setFormValue(this.value);
2658
+ }
2659
+ };
2660
+ }
2661
+ function or(e = "wysio-editor") {
2662
+ typeof customElements > "u" || customElements.get(e) || customElements.define(e, ar());
2663
+ }
2664
+ // src/index.ts
2665
+ var sr = "0.2.0-alpha.0";
2666
+ export { E as ALIGNMENTS, ut as DEFAULT_HIGHLIGHT_COLORS, B as DEFAULT_IMAGE_TYPES, lt as DEFAULT_TEXT_COLORS, Qn as Editor, at as FORMATTING_ATTRIBUTES, z as IMAGE_ALIGNMENTS, kn as MAX_TABLE_SIZE, P as activeColor, Qe as alignment, rr as autoInit, ze as availableLocales, $e as base, nt as blockquote, Qt as bold, gn as cleanPastedHTML, st as clearFormatting, ct as clearFormattingPlugin, nn as code, tr as createEditor, Nn as createTable, v as defaultMessages, Hn as defaultPlugins, Xn as defaultToolbar, m as definePlugin, or as defineWysioElement, M as findAncestor, Kn as fitCount, Cn as formatHTML, nr as getEditor, tt as getMarkRange, it as hardBreak, Tt as heading, Ct as highlight, Dt as history, rt as horizontalRule, Wt as image, Bt as insertImage, Pn as insertTable, k as isAlignmentActive, j as isMarkActive, $t as italic, Xt as link, Zt as lists, Le as nl, ft as normalizeColor, Ze as openAlignmentMenu, Ht as openImageDialog, Jt as openLinkDialog, Rn as openTableMenu, ht as paletteCSS, _n as paste, vn as placeholder, Re as registerLocale, fe as registerPlugin, vt as removeColorMark, Vt as removeImage, qt as removeLink, R as sanitizeImageUrl, L as sanitizeUrl, O as setAlignment, _t as setColorMark, Kt as setLink, On as source, tn as strike, Vn as table, St as textColor, Fn as toggleHeaderRow, N as toggleList, Dn as toggleSourceView, et as toggleWrap, en as underline, K as uploadImages, sr as version };
2667
+
2668
+ //# sourceMappingURL=wysio.js.map