stilo-editor 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +172 -2
- package/dist/characters--8h5uTeF.js +854 -0
- package/dist/content.css +161 -0
- package/dist/core/drop.d.ts +6 -0
- package/dist/core/editor.d.ts +108 -0
- package/dist/core/errors.d.ts +6 -0
- package/dist/core/events.d.ts +19 -0
- package/dist/core/extension-manager.d.ts +57 -0
- package/dist/core/extension.d.ts +43 -0
- package/dist/core/helpers/active.d.ts +33 -0
- package/dist/core/helpers/input-rules.d.ts +21 -0
- package/dist/core/helpers/lists.d.ts +12 -0
- package/dist/core/helpers/marks.d.ts +38 -0
- package/dist/core/helpers/nodes.d.ts +14 -0
- package/dist/core/helpers/parse-rules.d.ts +8 -0
- package/dist/core/html/css.d.ts +91 -0
- package/dist/core/html/parse.d.ts +7 -0
- package/dist/core/html/sanitize.d.ts +49 -0
- package/dist/core/html/serialize.d.ts +31 -0
- package/dist/core/types.d.ts +107 -0
- package/dist/extensions/blockquote/index.d.ts +15 -0
- package/dist/extensions/bold/index.d.ts +17 -0
- package/dist/extensions/bullet-list/index.d.ts +9 -0
- package/dist/extensions/clear-formatting/index.d.ts +12 -0
- package/dist/extensions/code/index.d.ts +15 -0
- package/dist/extensions/default-extensions/index.d.ts +46 -0
- package/dist/extensions/document/index.d.ts +17 -0
- package/dist/extensions/drop-cursor/index.d.ts +15 -0
- package/dist/extensions/gap-cursor/index.d.ts +6 -0
- package/dist/extensions/hard-break/index.d.ts +11 -0
- package/dist/extensions/heading/index.d.ts +24 -0
- package/dist/extensions/highlight/index.d.ts +24 -0
- package/dist/extensions/history/index.d.ts +21 -0
- package/dist/extensions/horizontal-rule/index.d.ts +11 -0
- package/dist/extensions/index.d.ts +27 -0
- package/dist/extensions/italic/index.d.ts +16 -0
- package/dist/extensions/link/index.d.ts +23 -0
- package/dist/extensions/list-item/index.d.ts +16 -0
- package/dist/extensions/move-block/index.d.ts +17 -0
- package/dist/extensions/ordered-list/index.d.ts +12 -0
- package/dist/extensions/paragraph/index.d.ts +14 -0
- package/dist/extensions/placeholder/index.d.ts +13 -0
- package/dist/extensions/strike/index.d.ts +16 -0
- package/dist/extensions/subscript/index.d.ts +16 -0
- package/dist/extensions/superscript/index.d.ts +17 -0
- package/dist/extensions/text/index.d.ts +12 -0
- package/dist/extensions/text-style/index.d.ts +14 -0
- package/dist/extensions/underline/index.d.ts +15 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -0
- package/dist/src-3tAxKI0c.js +1316 -0
- package/dist/style.css +797 -0
- package/dist/ui/components/character-picker.d.ts +22 -0
- package/dist/ui/components/characters.d.ts +10 -0
- package/dist/ui/components/color-button.d.ts +23 -0
- package/dist/ui/components/dropdown.d.ts +25 -0
- package/dist/ui/components/icon.d.ts +3 -0
- package/dist/ui/components/link-bubble.d.ts +19 -0
- package/dist/ui/components/link-popover.d.ts +20 -0
- package/dist/ui/components/popover.d.ts +27 -0
- package/dist/ui/components/shortcut.d.ts +11 -0
- package/dist/ui/i18n/en.d.ts +3 -0
- package/dist/ui/i18n/it.d.ts +3 -0
- package/dist/ui/i18n/types.d.ts +4 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/toolbar/items.d.ts +12 -0
- package/dist/ui/toolbar/palette.d.ts +6 -0
- package/dist/ui/toolbar/toolbar.d.ts +28 -0
- package/dist/ui/toolbar/types.d.ts +87 -0
- package/dist/ui.css +635 -0
- package/dist/ui.js +1292 -0
- package/package.json +86 -4
package/dist/ui.js
ADDED
|
@@ -0,0 +1,1292 @@
|
|
|
1
|
+
import { H as e } from "./src-3tAxKI0c.js";
|
|
2
|
+
import { Bold as t, ChevronDown as n, Code as r, ExternalLink as i, FaceSlightlySmilingPlus as a, Highlighter as o, Italic as s, Link as c, List as l, ListOrdered as u, Minus as d, Pencil as f, Redo2 as p, RemoveFormatting as m, Strikethrough as h, Subscript as g, Superscript as _, TextQuote as v, Type as y, Underline as b, Undo2 as x, Unlink as S, createElement as C } from "lucide";
|
|
3
|
+
import { autoUpdate as w, computePosition as T, flip as E, offset as D, shift as O } from "@floating-ui/dom";
|
|
4
|
+
//#region src/ui/components/shortcut.ts
|
|
5
|
+
function k() {
|
|
6
|
+
return /Mac|iPhone|iPad/.test(navigator.platform);
|
|
7
|
+
}
|
|
8
|
+
function A(e, t) {
|
|
9
|
+
let n = e.split("-"), r = n.pop(), i = [];
|
|
10
|
+
if (t) return n.includes("Ctrl") && i.push("⌃"), n.includes("Alt") && i.push("⌥"), n.includes("Shift") && i.push("⇧"), n.includes("Mod") && i.push("⌘"), i.join("") + (r.length === 1 ? r.toUpperCase() : r);
|
|
11
|
+
let a = n.includes("Mod"), o = n.includes("Ctrl");
|
|
12
|
+
return (o || a && !o) && i.push("Ctrl"), n.includes("Alt") && i.push("Alt"), n.includes("Shift") && i.push("Shift"), i.join("+") + (i.length > 0 ? "+" : "") + (r.length === 1 ? r.toUpperCase() : r);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/ui/i18n/en.ts
|
|
16
|
+
var j = {
|
|
17
|
+
"toolbar.label": "Formatting",
|
|
18
|
+
"toolbar.undo": "Undo",
|
|
19
|
+
"toolbar.redo": "Redo",
|
|
20
|
+
"toolbar.bold": "Bold",
|
|
21
|
+
"toolbar.italic": "Italic",
|
|
22
|
+
"toolbar.underline": "Underline",
|
|
23
|
+
"toolbar.strike": "Strikethrough",
|
|
24
|
+
"toolbar.subscript": "Subscript",
|
|
25
|
+
"toolbar.superscript": "Superscript",
|
|
26
|
+
"toolbar.code": "Code",
|
|
27
|
+
"toolbar.clearFormatting": "Clear formatting",
|
|
28
|
+
"toolbar.bulletList": "Bulleted list",
|
|
29
|
+
"toolbar.orderedList": "Numbered list",
|
|
30
|
+
"toolbar.blockquote": "Quote",
|
|
31
|
+
"toolbar.horizontalRule": "Horizontal line",
|
|
32
|
+
"toolbar.link": "Link",
|
|
33
|
+
"toolbar.heading": "Text style",
|
|
34
|
+
"heading.paragraph": "Paragraph",
|
|
35
|
+
"heading.h1": "Heading 1",
|
|
36
|
+
"heading.h2": "Heading 2",
|
|
37
|
+
"heading.h3": "Heading 3",
|
|
38
|
+
"heading.h4": "Heading 4",
|
|
39
|
+
"heading.h5": "Heading 5",
|
|
40
|
+
"heading.h6": "Heading 6",
|
|
41
|
+
"link.url": "URL",
|
|
42
|
+
"link.newTab": "Open in new tab",
|
|
43
|
+
"link.apply": "Apply",
|
|
44
|
+
"link.remove": "Remove link",
|
|
45
|
+
"link.edit": "Edit link",
|
|
46
|
+
"link.open": "Open link in a new tab",
|
|
47
|
+
"toolbar.characters": "Insert character",
|
|
48
|
+
"characters.search": "Search",
|
|
49
|
+
"characters.noResults": "No results",
|
|
50
|
+
"characters.symbols": "Symbols",
|
|
51
|
+
"characters.emoji": "Emoji",
|
|
52
|
+
"characters.punctuation": "Punctuation",
|
|
53
|
+
"characters.currency": "Currency",
|
|
54
|
+
"characters.math": "Math",
|
|
55
|
+
"characters.arrows": "Arrows",
|
|
56
|
+
"characters.greek": "Greek",
|
|
57
|
+
"characters.latin": "Accented letters",
|
|
58
|
+
"characters.signs": "Signs and shapes",
|
|
59
|
+
"characters.smileys": "Smileys",
|
|
60
|
+
"characters.people": "People and gestures",
|
|
61
|
+
"characters.nature": "Animals and nature",
|
|
62
|
+
"characters.food": "Food and drink",
|
|
63
|
+
"characters.travel": "Travel and places",
|
|
64
|
+
"characters.activities": "Activities",
|
|
65
|
+
"characters.objects": "Objects",
|
|
66
|
+
"characters.emojiSymbols": "Symbols",
|
|
67
|
+
"toolbar.textColor": "Text color",
|
|
68
|
+
"toolbar.highlight": "Highlight",
|
|
69
|
+
"color.more": "more colors",
|
|
70
|
+
"color.default": "Default",
|
|
71
|
+
"color.none": "No color",
|
|
72
|
+
"color.pick": "Pick a color",
|
|
73
|
+
"color.custom": "Custom color",
|
|
74
|
+
"color.apply": "Apply",
|
|
75
|
+
"color.black": "Black",
|
|
76
|
+
"color.darkGray2": "Dark gray 2",
|
|
77
|
+
"color.darkGray1": "Dark gray 1",
|
|
78
|
+
"color.gray": "Gray",
|
|
79
|
+
"color.lightGray1": "Light gray 1",
|
|
80
|
+
"color.lightGray2": "Light gray 2",
|
|
81
|
+
"color.lightGray3": "Light gray 3",
|
|
82
|
+
"color.white": "White",
|
|
83
|
+
"color.red": "Red",
|
|
84
|
+
"color.orange": "Orange",
|
|
85
|
+
"color.yellow": "Yellow",
|
|
86
|
+
"color.green": "Green",
|
|
87
|
+
"color.cyan": "Cyan",
|
|
88
|
+
"color.blue": "Blue",
|
|
89
|
+
"color.purple": "Purple",
|
|
90
|
+
"color.pink": "Pink",
|
|
91
|
+
"color.lightRed": "Light red",
|
|
92
|
+
"color.lightOrange": "Light orange",
|
|
93
|
+
"color.lightYellow": "Light yellow",
|
|
94
|
+
"color.lightGreen": "Light green",
|
|
95
|
+
"color.lightCyan": "Light cyan",
|
|
96
|
+
"color.lightBlue": "Light blue",
|
|
97
|
+
"color.lightPurple": "Light purple",
|
|
98
|
+
"color.lightPink": "Light pink",
|
|
99
|
+
"color.darkRed": "Dark red",
|
|
100
|
+
"color.darkOrange": "Dark orange",
|
|
101
|
+
"color.darkYellow": "Dark yellow",
|
|
102
|
+
"color.darkGreen": "Dark green",
|
|
103
|
+
"color.darkCyan": "Dark cyan",
|
|
104
|
+
"color.darkBlue": "Dark blue",
|
|
105
|
+
"color.darkPurple": "Dark purple",
|
|
106
|
+
"color.darkPink": "Dark pink"
|
|
107
|
+
}, M = {
|
|
108
|
+
"toolbar.label": "Formattazione",
|
|
109
|
+
"toolbar.undo": "Annulla",
|
|
110
|
+
"toolbar.redo": "Ripeti",
|
|
111
|
+
"toolbar.bold": "Grassetto",
|
|
112
|
+
"toolbar.italic": "Corsivo",
|
|
113
|
+
"toolbar.underline": "Sottolineato",
|
|
114
|
+
"toolbar.strike": "Barrato",
|
|
115
|
+
"toolbar.subscript": "Pedice",
|
|
116
|
+
"toolbar.superscript": "Apice",
|
|
117
|
+
"toolbar.code": "Codice",
|
|
118
|
+
"toolbar.clearFormatting": "Cancella formattazione",
|
|
119
|
+
"toolbar.bulletList": "Elenco puntato",
|
|
120
|
+
"toolbar.orderedList": "Elenco numerato",
|
|
121
|
+
"toolbar.blockquote": "Citazione",
|
|
122
|
+
"toolbar.horizontalRule": "Linea orizzontale",
|
|
123
|
+
"toolbar.link": "Collegamento",
|
|
124
|
+
"toolbar.heading": "Stile testo",
|
|
125
|
+
"heading.paragraph": "Paragrafo",
|
|
126
|
+
"heading.h1": "Titolo 1",
|
|
127
|
+
"heading.h2": "Titolo 2",
|
|
128
|
+
"heading.h3": "Titolo 3",
|
|
129
|
+
"heading.h4": "Titolo 4",
|
|
130
|
+
"heading.h5": "Titolo 5",
|
|
131
|
+
"heading.h6": "Titolo 6",
|
|
132
|
+
"link.url": "URL",
|
|
133
|
+
"link.newTab": "Apri in una nuova scheda",
|
|
134
|
+
"link.apply": "Applica",
|
|
135
|
+
"link.remove": "Rimuovi collegamento",
|
|
136
|
+
"link.edit": "Modifica collegamento",
|
|
137
|
+
"link.open": "Apri il collegamento in una nuova scheda",
|
|
138
|
+
"toolbar.characters": "Inserisci carattere",
|
|
139
|
+
"characters.search": "Cerca",
|
|
140
|
+
"characters.noResults": "Nessun risultato",
|
|
141
|
+
"characters.symbols": "Simboli",
|
|
142
|
+
"characters.emoji": "Emoji",
|
|
143
|
+
"characters.punctuation": "Punteggiatura",
|
|
144
|
+
"characters.currency": "Valute",
|
|
145
|
+
"characters.math": "Matematica",
|
|
146
|
+
"characters.arrows": "Frecce",
|
|
147
|
+
"characters.greek": "Greco",
|
|
148
|
+
"characters.latin": "Lettere accentate",
|
|
149
|
+
"characters.signs": "Segni e forme",
|
|
150
|
+
"characters.smileys": "Faccine",
|
|
151
|
+
"characters.people": "Persone e gesti",
|
|
152
|
+
"characters.nature": "Animali e natura",
|
|
153
|
+
"characters.food": "Cibo e bevande",
|
|
154
|
+
"characters.travel": "Viaggi e luoghi",
|
|
155
|
+
"characters.activities": "Attività",
|
|
156
|
+
"characters.objects": "Oggetti",
|
|
157
|
+
"characters.emojiSymbols": "Simboli",
|
|
158
|
+
"toolbar.textColor": "Colore testo",
|
|
159
|
+
"toolbar.highlight": "Evidenziatore",
|
|
160
|
+
"color.more": "altri colori",
|
|
161
|
+
"color.default": "Predefinito",
|
|
162
|
+
"color.none": "Nessun colore",
|
|
163
|
+
"color.pick": "Scegli un colore",
|
|
164
|
+
"color.custom": "Colore personalizzato",
|
|
165
|
+
"color.apply": "Applica",
|
|
166
|
+
"color.black": "Nero",
|
|
167
|
+
"color.darkGray2": "Grigio scuro 2",
|
|
168
|
+
"color.darkGray1": "Grigio scuro 1",
|
|
169
|
+
"color.gray": "Grigio",
|
|
170
|
+
"color.lightGray1": "Grigio chiaro 1",
|
|
171
|
+
"color.lightGray2": "Grigio chiaro 2",
|
|
172
|
+
"color.lightGray3": "Grigio chiaro 3",
|
|
173
|
+
"color.white": "Bianco",
|
|
174
|
+
"color.red": "Rosso",
|
|
175
|
+
"color.orange": "Arancione",
|
|
176
|
+
"color.yellow": "Giallo",
|
|
177
|
+
"color.green": "Verde",
|
|
178
|
+
"color.cyan": "Ciano",
|
|
179
|
+
"color.blue": "Blu",
|
|
180
|
+
"color.purple": "Viola",
|
|
181
|
+
"color.pink": "Rosa",
|
|
182
|
+
"color.lightRed": "Rosso chiaro",
|
|
183
|
+
"color.lightOrange": "Arancione chiaro",
|
|
184
|
+
"color.lightYellow": "Giallo chiaro",
|
|
185
|
+
"color.lightGreen": "Verde chiaro",
|
|
186
|
+
"color.lightCyan": "Ciano chiaro",
|
|
187
|
+
"color.lightBlue": "Blu chiaro",
|
|
188
|
+
"color.lightPurple": "Viola chiaro",
|
|
189
|
+
"color.lightPink": "Rosa chiaro",
|
|
190
|
+
"color.darkRed": "Rosso scuro",
|
|
191
|
+
"color.darkOrange": "Arancione scuro",
|
|
192
|
+
"color.darkYellow": "Giallo scuro",
|
|
193
|
+
"color.darkGreen": "Verde scuro",
|
|
194
|
+
"color.darkCyan": "Ciano scuro",
|
|
195
|
+
"color.darkBlue": "Blu scuro",
|
|
196
|
+
"color.darkPurple": "Viola scuro",
|
|
197
|
+
"color.darkPink": "Rosa scuro"
|
|
198
|
+
};
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/ui/components/popover.ts
|
|
201
|
+
function N(e) {
|
|
202
|
+
let { anchor: t, content: n, container: r, placement: i = "bottom-start", offset: a = 4, onClose: o } = e, s = !1, c = !1, l, u = 0;
|
|
203
|
+
n.classList.add("stilo-popover"), n.setAttribute("hidden", ""), r.classList.add("stilo-popover-host"), r.appendChild(n);
|
|
204
|
+
function d() {
|
|
205
|
+
let e = ++u;
|
|
206
|
+
Promise.resolve(T(t, n, {
|
|
207
|
+
strategy: "absolute",
|
|
208
|
+
placement: i,
|
|
209
|
+
middleware: [
|
|
210
|
+
D(a),
|
|
211
|
+
E(),
|
|
212
|
+
O({ padding: 8 })
|
|
213
|
+
]
|
|
214
|
+
}).then((t) => {
|
|
215
|
+
s || u !== e || (n.style.left = `${t.x}px`, n.style.top = `${t.y}px`);
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
function f() {
|
|
219
|
+
c || s || (c = !0, n.removeAttribute("hidden"), l = w(t, n, () => {
|
|
220
|
+
c && d();
|
|
221
|
+
}), document.addEventListener("pointerdown", h, !0), document.addEventListener("keydown", g, !0));
|
|
222
|
+
}
|
|
223
|
+
function p(e = "api") {
|
|
224
|
+
c && !s && (c = !1, n.setAttribute("hidden", ""), l?.(), l = void 0, document.removeEventListener("pointerdown", h, !0), document.removeEventListener("keydown", g, !0), o?.(e));
|
|
225
|
+
}
|
|
226
|
+
function m() {
|
|
227
|
+
s || (s = !0, c && (c = !1, n.setAttribute("hidden", ""), l?.(), l = void 0, document.removeEventListener("pointerdown", h, !0), document.removeEventListener("keydown", g, !0), o?.("api")), r.contains(n) && r.removeChild(n), r.querySelector(":scope > .stilo-popover") || r.classList.remove("stilo-popover-host"));
|
|
228
|
+
}
|
|
229
|
+
function h(e) {
|
|
230
|
+
if (!c || s) return;
|
|
231
|
+
let r = e.target;
|
|
232
|
+
n.contains(r) || typeof t == "object" && "nodeType" in t && t.nodeType === 1 && t.contains(r) || p("outside");
|
|
233
|
+
}
|
|
234
|
+
function g(e) {
|
|
235
|
+
c && !s && e.key === "Escape" && (e.preventDefault(), p("escape"));
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
get isOpen() {
|
|
239
|
+
return c;
|
|
240
|
+
},
|
|
241
|
+
open: f,
|
|
242
|
+
close: p,
|
|
243
|
+
destroy: m
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/ui/components/link-popover.ts
|
|
248
|
+
var P = "https://example.com";
|
|
249
|
+
function F(e) {
|
|
250
|
+
return e.isActive("link") || e.commands.setLink.can({ href: P });
|
|
251
|
+
}
|
|
252
|
+
function I(e, t) {
|
|
253
|
+
let { container: n, messages: r } = t, i = {
|
|
254
|
+
contextElement: e.view.dom,
|
|
255
|
+
getBoundingClientRect: () => {
|
|
256
|
+
let { from: t, to: n } = e.state.selection, r = e.view.coordsAtPos(t), i = e.view.coordsAtPos(n), a = Math.min(r.left, i.left), o = Math.max(r.right, i.right), { top: s } = r, { bottom: c } = i;
|
|
257
|
+
return {
|
|
258
|
+
x: a,
|
|
259
|
+
y: s,
|
|
260
|
+
left: a,
|
|
261
|
+
top: s,
|
|
262
|
+
right: o,
|
|
263
|
+
bottom: c,
|
|
264
|
+
width: o - a,
|
|
265
|
+
height: c - s
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}, a = document.createElement("div");
|
|
269
|
+
a.className = "stilo-link-popover", a.setAttribute("role", "dialog"), a.setAttribute("aria-label", r["toolbar.link"]);
|
|
270
|
+
let o = document.createElement("form");
|
|
271
|
+
o.className = "stilo-link-popover__form";
|
|
272
|
+
let s = document.createElement("input");
|
|
273
|
+
s.type = "text", s.inputMode = "url", s.className = "stilo-link-popover__url", s.placeholder = "https://", s.autocomplete = "off", s.spellcheck = !1, s.setAttribute("aria-label", r["link.url"]);
|
|
274
|
+
let c = document.createElement("label");
|
|
275
|
+
c.className = "stilo-link-popover__new-tab";
|
|
276
|
+
let l = document.createElement("input");
|
|
277
|
+
l.type = "checkbox", c.append(l, r["link.newTab"]);
|
|
278
|
+
let u = document.createElement("div");
|
|
279
|
+
u.className = "stilo-link-popover__actions";
|
|
280
|
+
let d = L("submit", r["link.apply"]);
|
|
281
|
+
d.classList.add("stilo-link-popover__button--primary");
|
|
282
|
+
let f = L("button", r["link.remove"]);
|
|
283
|
+
u.append(d, f), o.append(s, c, u), a.append(o);
|
|
284
|
+
let p = N({
|
|
285
|
+
anchor: i,
|
|
286
|
+
content: a,
|
|
287
|
+
container: n,
|
|
288
|
+
onClose: (t) => {
|
|
289
|
+
t === "escape" && e.focus();
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
function m() {
|
|
293
|
+
p.close(), e.focus();
|
|
294
|
+
}
|
|
295
|
+
let h = (t) => {
|
|
296
|
+
t.preventDefault();
|
|
297
|
+
let n = s.value.trim();
|
|
298
|
+
(n ? e.commands.setLink({
|
|
299
|
+
href: n,
|
|
300
|
+
target: l.checked ? "_blank" : null
|
|
301
|
+
}) : !e.isActive("link") || e.commands.unsetLink()) ? m() : (s.setAttribute("aria-invalid", "true"), s.focus());
|
|
302
|
+
}, g = () => {
|
|
303
|
+
e.commands.unsetLink(), m();
|
|
304
|
+
}, _ = () => {
|
|
305
|
+
s.removeAttribute("aria-invalid");
|
|
306
|
+
};
|
|
307
|
+
o.addEventListener("submit", h), f.addEventListener("click", g), s.addEventListener("input", _);
|
|
308
|
+
function v() {
|
|
309
|
+
if (p.isOpen || !F(e)) return;
|
|
310
|
+
let { href: t, target: n } = e.getAttributes("link");
|
|
311
|
+
s.value = typeof t == "string" ? t : "", s.removeAttribute("aria-invalid"), l.checked = n === "_blank", f.hidden = !e.isActive("link"), p.open(), s.focus({ preventScroll: !0 }), s.select();
|
|
312
|
+
}
|
|
313
|
+
function y() {
|
|
314
|
+
o.removeEventListener("submit", h), f.removeEventListener("click", g), s.removeEventListener("input", _), p.destroy();
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
get isOpen() {
|
|
318
|
+
return p.isOpen;
|
|
319
|
+
},
|
|
320
|
+
open: v,
|
|
321
|
+
close: () => p.close(),
|
|
322
|
+
destroy: y
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function L(e, t) {
|
|
326
|
+
let n = document.createElement("button");
|
|
327
|
+
return n.type = e, n.className = "stilo-link-popover__button", n.textContent = t, n;
|
|
328
|
+
}
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/ui/toolbar/palette.ts
|
|
331
|
+
function R(e, t) {
|
|
332
|
+
return {
|
|
333
|
+
color: e,
|
|
334
|
+
labelKey: t
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
var z = [
|
|
338
|
+
R("#000000", "color.black"),
|
|
339
|
+
R("#404040", "color.darkGray2"),
|
|
340
|
+
R("#737373", "color.darkGray1"),
|
|
341
|
+
R("#a3a3a3", "color.gray"),
|
|
342
|
+
R("#d4d4d4", "color.lightGray1"),
|
|
343
|
+
R("#e5e5e5", "color.lightGray2"),
|
|
344
|
+
R("#f5f5f5", "color.lightGray3"),
|
|
345
|
+
R("#ffffff", "color.white"),
|
|
346
|
+
R("#ef4444", "color.red"),
|
|
347
|
+
R("#f97316", "color.orange"),
|
|
348
|
+
R("#eab308", "color.yellow"),
|
|
349
|
+
R("#22c55e", "color.green"),
|
|
350
|
+
R("#06b6d4", "color.cyan"),
|
|
351
|
+
R("#3b82f6", "color.blue"),
|
|
352
|
+
R("#a855f7", "color.purple"),
|
|
353
|
+
R("#ec4899", "color.pink"),
|
|
354
|
+
R("#fecaca", "color.lightRed"),
|
|
355
|
+
R("#fed7aa", "color.lightOrange"),
|
|
356
|
+
R("#fef08a", "color.lightYellow"),
|
|
357
|
+
R("#bbf7d0", "color.lightGreen"),
|
|
358
|
+
R("#a5f3fc", "color.lightCyan"),
|
|
359
|
+
R("#bfdbfe", "color.lightBlue"),
|
|
360
|
+
R("#e9d5ff", "color.lightPurple"),
|
|
361
|
+
R("#fbcfe8", "color.lightPink"),
|
|
362
|
+
R("#991b1b", "color.darkRed"),
|
|
363
|
+
R("#9a3412", "color.darkOrange"),
|
|
364
|
+
R("#854d0e", "color.darkYellow"),
|
|
365
|
+
R("#166534", "color.darkGreen"),
|
|
366
|
+
R("#155e75", "color.darkCyan"),
|
|
367
|
+
R("#1e40af", "color.darkBlue"),
|
|
368
|
+
R("#6b21a8", "color.darkPurple"),
|
|
369
|
+
R("#9d174d", "color.darkPink")
|
|
370
|
+
], B = [
|
|
371
|
+
["undo", "redo"],
|
|
372
|
+
["heading"],
|
|
373
|
+
[
|
|
374
|
+
"bold",
|
|
375
|
+
"italic",
|
|
376
|
+
"underline",
|
|
377
|
+
"strike",
|
|
378
|
+
"code",
|
|
379
|
+
"subscript",
|
|
380
|
+
"superscript",
|
|
381
|
+
"link",
|
|
382
|
+
"clearFormatting"
|
|
383
|
+
],
|
|
384
|
+
["textColor", "highlight"],
|
|
385
|
+
[
|
|
386
|
+
"bulletList",
|
|
387
|
+
"orderedList",
|
|
388
|
+
"blockquote",
|
|
389
|
+
"horizontalRule",
|
|
390
|
+
"characters"
|
|
391
|
+
]
|
|
392
|
+
], V = {
|
|
393
|
+
undo: {
|
|
394
|
+
id: "undo",
|
|
395
|
+
kind: "button",
|
|
396
|
+
icon: x,
|
|
397
|
+
labelKey: "toolbar.undo",
|
|
398
|
+
shortcut: "Mod-z",
|
|
399
|
+
run: (e) => {
|
|
400
|
+
e.commands.undo();
|
|
401
|
+
},
|
|
402
|
+
isEnabled: (e) => e.commands.undo.can()
|
|
403
|
+
},
|
|
404
|
+
redo: {
|
|
405
|
+
id: "redo",
|
|
406
|
+
kind: "button",
|
|
407
|
+
icon: p,
|
|
408
|
+
labelKey: "toolbar.redo",
|
|
409
|
+
shortcut: "Mod-Shift-z",
|
|
410
|
+
run: (e) => {
|
|
411
|
+
e.commands.redo();
|
|
412
|
+
},
|
|
413
|
+
isEnabled: (e) => e.commands.redo.can()
|
|
414
|
+
},
|
|
415
|
+
bold: {
|
|
416
|
+
id: "bold",
|
|
417
|
+
kind: "button",
|
|
418
|
+
icon: t,
|
|
419
|
+
labelKey: "toolbar.bold",
|
|
420
|
+
shortcut: "Mod-b",
|
|
421
|
+
run: (e) => {
|
|
422
|
+
e.commands.toggleBold();
|
|
423
|
+
},
|
|
424
|
+
isActive: (e) => e.isActive("bold"),
|
|
425
|
+
isEnabled: (e) => "toggleBold" in e.commands && e.commands.toggleBold.can(),
|
|
426
|
+
isAvailable: (e) => "toggleBold" in e.commands
|
|
427
|
+
},
|
|
428
|
+
italic: {
|
|
429
|
+
id: "italic",
|
|
430
|
+
kind: "button",
|
|
431
|
+
icon: s,
|
|
432
|
+
labelKey: "toolbar.italic",
|
|
433
|
+
shortcut: "Mod-i",
|
|
434
|
+
run: (e) => {
|
|
435
|
+
e.commands.toggleItalic();
|
|
436
|
+
},
|
|
437
|
+
isActive: (e) => e.isActive("italic"),
|
|
438
|
+
isEnabled: (e) => "toggleItalic" in e.commands && e.commands.toggleItalic.can(),
|
|
439
|
+
isAvailable: (e) => "toggleItalic" in e.commands
|
|
440
|
+
},
|
|
441
|
+
underline: {
|
|
442
|
+
id: "underline",
|
|
443
|
+
kind: "button",
|
|
444
|
+
icon: b,
|
|
445
|
+
labelKey: "toolbar.underline",
|
|
446
|
+
shortcut: "Mod-u",
|
|
447
|
+
run: (e) => {
|
|
448
|
+
e.commands.toggleUnderline();
|
|
449
|
+
},
|
|
450
|
+
isActive: (e) => e.isActive("underline"),
|
|
451
|
+
isEnabled: (e) => "toggleUnderline" in e.commands && e.commands.toggleUnderline.can(),
|
|
452
|
+
isAvailable: (e) => "toggleUnderline" in e.commands
|
|
453
|
+
},
|
|
454
|
+
strike: {
|
|
455
|
+
id: "strike",
|
|
456
|
+
kind: "button",
|
|
457
|
+
icon: h,
|
|
458
|
+
labelKey: "toolbar.strike",
|
|
459
|
+
shortcut: "Mod-Shift-s",
|
|
460
|
+
run: (e) => {
|
|
461
|
+
e.commands.toggleStrike();
|
|
462
|
+
},
|
|
463
|
+
isActive: (e) => e.isActive("strike"),
|
|
464
|
+
isEnabled: (e) => "toggleStrike" in e.commands && e.commands.toggleStrike.can(),
|
|
465
|
+
isAvailable: (e) => "toggleStrike" in e.commands
|
|
466
|
+
},
|
|
467
|
+
code: {
|
|
468
|
+
id: "code",
|
|
469
|
+
kind: "button",
|
|
470
|
+
icon: r,
|
|
471
|
+
labelKey: "toolbar.code",
|
|
472
|
+
shortcut: "Mod-e",
|
|
473
|
+
run: (e) => {
|
|
474
|
+
e.commands.toggleCode();
|
|
475
|
+
},
|
|
476
|
+
isActive: (e) => e.isActive("code"),
|
|
477
|
+
isEnabled: (e) => "toggleCode" in e.commands && e.commands.toggleCode.can(),
|
|
478
|
+
isAvailable: (e) => "toggleCode" in e.commands
|
|
479
|
+
},
|
|
480
|
+
subscript: {
|
|
481
|
+
id: "subscript",
|
|
482
|
+
kind: "button",
|
|
483
|
+
icon: g,
|
|
484
|
+
labelKey: "toolbar.subscript",
|
|
485
|
+
shortcut: "Mod-,",
|
|
486
|
+
run: (e) => {
|
|
487
|
+
e.commands.toggleSubscript();
|
|
488
|
+
},
|
|
489
|
+
isActive: (e) => e.isActive("subscript"),
|
|
490
|
+
isEnabled: (e) => "toggleSubscript" in e.commands && e.commands.toggleSubscript.can(),
|
|
491
|
+
isAvailable: (e) => "toggleSubscript" in e.commands
|
|
492
|
+
},
|
|
493
|
+
superscript: {
|
|
494
|
+
id: "superscript",
|
|
495
|
+
kind: "button",
|
|
496
|
+
icon: _,
|
|
497
|
+
labelKey: "toolbar.superscript",
|
|
498
|
+
shortcut: "Mod-.",
|
|
499
|
+
run: (e) => {
|
|
500
|
+
e.commands.toggleSuperscript();
|
|
501
|
+
},
|
|
502
|
+
isActive: (e) => e.isActive("superscript"),
|
|
503
|
+
isEnabled: (e) => "toggleSuperscript" in e.commands && e.commands.toggleSuperscript.can(),
|
|
504
|
+
isAvailable: (e) => "toggleSuperscript" in e.commands
|
|
505
|
+
},
|
|
506
|
+
link: {
|
|
507
|
+
id: "link",
|
|
508
|
+
kind: "button",
|
|
509
|
+
icon: c,
|
|
510
|
+
labelKey: "toolbar.link",
|
|
511
|
+
shortcut: "Mod-k",
|
|
512
|
+
run: (e, t) => {
|
|
513
|
+
t.openLinkPopover();
|
|
514
|
+
},
|
|
515
|
+
isActive: (e) => e.isActive("link"),
|
|
516
|
+
isEnabled: (e) => "setLink" in e.commands && F(e),
|
|
517
|
+
isAvailable: (e) => "setLink" in e.commands
|
|
518
|
+
},
|
|
519
|
+
clearFormatting: {
|
|
520
|
+
id: "clearFormatting",
|
|
521
|
+
kind: "button",
|
|
522
|
+
icon: m,
|
|
523
|
+
labelKey: "toolbar.clearFormatting",
|
|
524
|
+
shortcut: "Mod-\\",
|
|
525
|
+
run: (e) => {
|
|
526
|
+
e.commands.clearFormatting();
|
|
527
|
+
},
|
|
528
|
+
isEnabled: (e) => "clearFormatting" in e.commands && e.commands.clearFormatting.can(),
|
|
529
|
+
isAvailable: (e) => "clearFormatting" in e.commands
|
|
530
|
+
},
|
|
531
|
+
bulletList: {
|
|
532
|
+
id: "bulletList",
|
|
533
|
+
kind: "button",
|
|
534
|
+
icon: l,
|
|
535
|
+
labelKey: "toolbar.bulletList",
|
|
536
|
+
shortcut: "Mod-Shift-8",
|
|
537
|
+
run: (e) => {
|
|
538
|
+
e.commands.toggleBulletList();
|
|
539
|
+
},
|
|
540
|
+
isActive: (e) => e.isActive("bulletList"),
|
|
541
|
+
isEnabled: (e) => "toggleBulletList" in e.commands && e.commands.toggleBulletList.can(),
|
|
542
|
+
isAvailable: (e) => "toggleBulletList" in e.commands
|
|
543
|
+
},
|
|
544
|
+
orderedList: {
|
|
545
|
+
id: "orderedList",
|
|
546
|
+
kind: "button",
|
|
547
|
+
icon: u,
|
|
548
|
+
labelKey: "toolbar.orderedList",
|
|
549
|
+
shortcut: "Mod-Shift-7",
|
|
550
|
+
run: (e) => {
|
|
551
|
+
e.commands.toggleOrderedList();
|
|
552
|
+
},
|
|
553
|
+
isActive: (e) => e.isActive("orderedList"),
|
|
554
|
+
isEnabled: (e) => "toggleOrderedList" in e.commands && e.commands.toggleOrderedList.can(),
|
|
555
|
+
isAvailable: (e) => "toggleOrderedList" in e.commands
|
|
556
|
+
},
|
|
557
|
+
blockquote: {
|
|
558
|
+
id: "blockquote",
|
|
559
|
+
kind: "button",
|
|
560
|
+
icon: v,
|
|
561
|
+
labelKey: "toolbar.blockquote",
|
|
562
|
+
shortcut: "Mod-Shift-b",
|
|
563
|
+
run: (e) => {
|
|
564
|
+
e.commands.toggleBlockquote();
|
|
565
|
+
},
|
|
566
|
+
isActive: (e) => e.isActive("blockquote"),
|
|
567
|
+
isEnabled: (e) => "toggleBlockquote" in e.commands && e.commands.toggleBlockquote.can(),
|
|
568
|
+
isAvailable: (e) => "toggleBlockquote" in e.commands
|
|
569
|
+
},
|
|
570
|
+
horizontalRule: {
|
|
571
|
+
id: "horizontalRule",
|
|
572
|
+
kind: "button",
|
|
573
|
+
icon: d,
|
|
574
|
+
labelKey: "toolbar.horizontalRule",
|
|
575
|
+
run: (e) => {
|
|
576
|
+
e.commands.setHorizontalRule();
|
|
577
|
+
},
|
|
578
|
+
isEnabled: (e) => "setHorizontalRule" in e.commands && e.commands.setHorizontalRule.can(),
|
|
579
|
+
isAvailable: (e) => "setHorizontalRule" in e.commands
|
|
580
|
+
},
|
|
581
|
+
characters: {
|
|
582
|
+
id: "characters",
|
|
583
|
+
kind: "button",
|
|
584
|
+
icon: a,
|
|
585
|
+
labelKey: "toolbar.characters",
|
|
586
|
+
run: (e, t) => {
|
|
587
|
+
t.toggleCharacterPicker();
|
|
588
|
+
},
|
|
589
|
+
isAvailable: (e) => "insertText" in e.commands
|
|
590
|
+
},
|
|
591
|
+
heading: G(),
|
|
592
|
+
textColor: U(),
|
|
593
|
+
highlight: W()
|
|
594
|
+
};
|
|
595
|
+
function H(e, t) {
|
|
596
|
+
let { color: n } = e.getAttributes(t);
|
|
597
|
+
return typeof n == "string" ? n : null;
|
|
598
|
+
}
|
|
599
|
+
function U(e = z) {
|
|
600
|
+
return {
|
|
601
|
+
id: "textColor",
|
|
602
|
+
kind: "color",
|
|
603
|
+
icon: y,
|
|
604
|
+
labelKey: "toolbar.textColor",
|
|
605
|
+
palette: e,
|
|
606
|
+
defaultColor: "#000000",
|
|
607
|
+
setColor: (e, t) => t !== null && e.commands.setColor(t),
|
|
608
|
+
unsetColor: (e) => {
|
|
609
|
+
e.commands.unsetColor();
|
|
610
|
+
},
|
|
611
|
+
hasColor: (e, t) => e.isActive("textStyle", { color: t }),
|
|
612
|
+
getColor: (e) => H(e, "textStyle"),
|
|
613
|
+
isEnabled: (e) => "setColor" in e.commands && e.commands.setColor.can("#000000"),
|
|
614
|
+
isAvailable: (e) => "setColor" in e.commands
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
function W(e = z) {
|
|
618
|
+
return {
|
|
619
|
+
id: "highlight",
|
|
620
|
+
kind: "color",
|
|
621
|
+
icon: o,
|
|
622
|
+
labelKey: "toolbar.highlight",
|
|
623
|
+
palette: e,
|
|
624
|
+
defaultColor: null,
|
|
625
|
+
defaultChoice: !0,
|
|
626
|
+
setColor: (e, t) => e.commands.setHighlight({ color: t }),
|
|
627
|
+
unsetColor: (e) => {
|
|
628
|
+
e.commands.unsetHighlight();
|
|
629
|
+
},
|
|
630
|
+
hasColor: (e, t) => e.isActive("highlight", { color: t }),
|
|
631
|
+
getColor: (e) => H(e, "highlight"),
|
|
632
|
+
isEnabled: (e) => "setHighlight" in e.commands && e.commands.setHighlight.can(),
|
|
633
|
+
isAvailable: (e) => "setHighlight" in e.commands
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function G(e = [
|
|
637
|
+
1,
|
|
638
|
+
2,
|
|
639
|
+
3,
|
|
640
|
+
4,
|
|
641
|
+
5,
|
|
642
|
+
6
|
|
643
|
+
]) {
|
|
644
|
+
return {
|
|
645
|
+
id: "heading",
|
|
646
|
+
kind: "dropdown",
|
|
647
|
+
labelKey: "toolbar.heading",
|
|
648
|
+
options: [{
|
|
649
|
+
id: "paragraph",
|
|
650
|
+
labelKey: "heading.paragraph",
|
|
651
|
+
shortcut: "Mod-Alt-0",
|
|
652
|
+
run: (e) => {
|
|
653
|
+
e.commands.setParagraph();
|
|
654
|
+
},
|
|
655
|
+
isActive: (e) => e.isActive("paragraph"),
|
|
656
|
+
isEnabled: (e) => e.isActive("paragraph") || e.commands.setParagraph.can()
|
|
657
|
+
}, ...e.map((e) => ({
|
|
658
|
+
id: `h${e}`,
|
|
659
|
+
labelKey: `heading.h${e}`,
|
|
660
|
+
shortcut: `Mod-Alt-${e}`,
|
|
661
|
+
run: (t) => {
|
|
662
|
+
t.commands.setHeading({ level: e });
|
|
663
|
+
},
|
|
664
|
+
isActive: (t) => t.isActive("heading", { level: e }),
|
|
665
|
+
isEnabled: (t) => t.isActive("heading", { level: e }) || t.commands.setHeading.can({ level: e })
|
|
666
|
+
}))],
|
|
667
|
+
isAvailable: (e) => "setHeading" in e.commands
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/ui/components/character-picker.ts
|
|
672
|
+
var K = 10;
|
|
673
|
+
async function q() {
|
|
674
|
+
let { SYMBOLS: e, EMOJI: t } = await import("./characters--8h5uTeF.js");
|
|
675
|
+
return {
|
|
676
|
+
symbols: e,
|
|
677
|
+
emoji: t
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
function J(e, t) {
|
|
681
|
+
let { anchor: n, container: r, messages: i } = t, a = document.createElement("div");
|
|
682
|
+
a.className = "stilo-char-picker", a.setAttribute("role", "dialog"), a.setAttribute("aria-label", i["toolbar.characters"]);
|
|
683
|
+
let o = document.createElement("input");
|
|
684
|
+
o.type = "search", o.className = "stilo-char-picker__search", o.placeholder = i["characters.search"], o.autocomplete = "off", o.spellcheck = !1, o.setAttribute("aria-label", i["characters.search"]);
|
|
685
|
+
let s = document.createElement("div");
|
|
686
|
+
s.className = "stilo-char-picker__tabs", s.setAttribute("role", "tablist");
|
|
687
|
+
let c = /* @__PURE__ */ new Map();
|
|
688
|
+
for (let e of ["symbols", "emoji"]) {
|
|
689
|
+
let t = document.createElement("button");
|
|
690
|
+
t.type = "button", t.className = "stilo-char-picker__tab", t.setAttribute("role", "tab"), t.textContent = i[`characters.${e}`], c.set(e, t), s.append(t);
|
|
691
|
+
}
|
|
692
|
+
let l = document.createElement("div");
|
|
693
|
+
l.className = "stilo-char-picker__panel", l.setAttribute("role", "tabpanel"), a.append(o, s, l), n.setAttribute("aria-haspopup", "dialog"), n.setAttribute("aria-expanded", "false");
|
|
694
|
+
let u = N({
|
|
695
|
+
anchor: n,
|
|
696
|
+
content: a,
|
|
697
|
+
container: r,
|
|
698
|
+
onClose: (t) => {
|
|
699
|
+
n.setAttribute("aria-expanded", "false"), t === "escape" && e.focus();
|
|
700
|
+
}
|
|
701
|
+
}), d = null, f = "symbols", p = [], m = [];
|
|
702
|
+
function h(e) {
|
|
703
|
+
f = e;
|
|
704
|
+
for (let [t, n] of c) {
|
|
705
|
+
let r = t === e;
|
|
706
|
+
n.setAttribute("aria-selected", String(r)), n.tabIndex = r ? 0 : -1;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
function g(e, t) {
|
|
710
|
+
let n = document.createElement("div");
|
|
711
|
+
n.className = "stilo-char-picker__grid", n.setAttribute("role", "group"), n.setAttribute("aria-label", t);
|
|
712
|
+
let r = e.map(([e, t]) => {
|
|
713
|
+
let n = document.createElement("button");
|
|
714
|
+
return n.type = "button", n.className = "stilo-char-picker__char", n.tabIndex = -1, n.title = t, n.setAttribute("aria-label", t), n.dataset.character = e, n.textContent = e, n;
|
|
715
|
+
});
|
|
716
|
+
n.append(...r), p.push(...r);
|
|
717
|
+
for (let e = 0; e < r.length; e += K) m.push(r.slice(e, e + K));
|
|
718
|
+
return n;
|
|
719
|
+
}
|
|
720
|
+
function _() {
|
|
721
|
+
if (!d) return;
|
|
722
|
+
p = [], m = [], l.replaceChildren();
|
|
723
|
+
let e = o.value.trim().toLowerCase();
|
|
724
|
+
if (s.hidden = e !== "", e) {
|
|
725
|
+
let t = [...d.symbols, ...d.emoji].flatMap((e) => e.characters).filter(([t, n]) => t === e || n.toLowerCase().includes(e));
|
|
726
|
+
if (t.length > 0) l.append(g(t, i["characters.search"]));
|
|
727
|
+
else {
|
|
728
|
+
let e = document.createElement("p");
|
|
729
|
+
e.className = "stilo-char-picker__empty", e.textContent = i["characters.noResults"], l.append(e);
|
|
730
|
+
}
|
|
731
|
+
} else for (let e of d[f]) {
|
|
732
|
+
let t = i[e.labelKey], n = document.createElement("div");
|
|
733
|
+
n.className = "stilo-char-picker__heading", n.textContent = t, l.append(n, g(e.characters, t));
|
|
734
|
+
}
|
|
735
|
+
p[0] && (p[0].tabIndex = 0);
|
|
736
|
+
}
|
|
737
|
+
function v(e) {
|
|
738
|
+
if (e) {
|
|
739
|
+
for (let e of p) e.tabIndex = -1;
|
|
740
|
+
e.tabIndex = 0, e.focus();
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function y(e, t) {
|
|
744
|
+
if (t === "ArrowLeft") return p[p.indexOf(e) - 1];
|
|
745
|
+
if (t === "ArrowRight") return p[p.indexOf(e) + 1];
|
|
746
|
+
let n = m.findIndex((t) => t.includes(e)), r = m[n].indexOf(e), i = m[t === "ArrowUp" ? n - 1 : n + 1];
|
|
747
|
+
return i?.[Math.min(r, i.length - 1)];
|
|
748
|
+
}
|
|
749
|
+
let b = () => _(), x = (e) => {
|
|
750
|
+
e.key === "ArrowDown" && p[0] && (e.preventDefault(), v(p[0]));
|
|
751
|
+
}, S = (e) => {
|
|
752
|
+
let t = [...c].find(([, t]) => t === e.target)?.[0];
|
|
753
|
+
t && (h(t), _());
|
|
754
|
+
}, C = (e) => {
|
|
755
|
+
if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
|
|
756
|
+
e.preventDefault();
|
|
757
|
+
let t = f === "symbols" ? "emoji" : "symbols";
|
|
758
|
+
h(t), _(), c.get(t).focus();
|
|
759
|
+
}, w = (t) => {
|
|
760
|
+
let n = t.target.closest(".stilo-char-picker__char");
|
|
761
|
+
n?.dataset.character && (e.commands.insertText(n.dataset.character), v(n));
|
|
762
|
+
}, T = (e) => {
|
|
763
|
+
let t = e.target.closest(".stilo-char-picker__char");
|
|
764
|
+
t && [
|
|
765
|
+
"ArrowLeft",
|
|
766
|
+
"ArrowRight",
|
|
767
|
+
"ArrowUp",
|
|
768
|
+
"ArrowDown"
|
|
769
|
+
].includes(e.key) && (e.preventDefault(), v(y(t, e.key)));
|
|
770
|
+
};
|
|
771
|
+
o.addEventListener("input", b), o.addEventListener("keydown", x), s.addEventListener("click", S), s.addEventListener("keydown", C), l.addEventListener("click", w), l.addEventListener("keydown", T), h(f);
|
|
772
|
+
async function E() {
|
|
773
|
+
u.isOpen || (u.open(), n.setAttribute("aria-expanded", "true"), d ??= await q(), u.isOpen && (o.value = "", _(), o.focus({ preventScroll: !0 })));
|
|
774
|
+
}
|
|
775
|
+
function D() {
|
|
776
|
+
u.isOpen && (u.close(), e.focus());
|
|
777
|
+
}
|
|
778
|
+
function O() {
|
|
779
|
+
o.removeEventListener("input", b), o.removeEventListener("keydown", x), s.removeEventListener("click", S), s.removeEventListener("keydown", C), l.removeEventListener("click", w), l.removeEventListener("keydown", T), u.destroy(), n.removeAttribute("aria-haspopup"), n.removeAttribute("aria-expanded");
|
|
780
|
+
}
|
|
781
|
+
return {
|
|
782
|
+
get isOpen() {
|
|
783
|
+
return u.isOpen;
|
|
784
|
+
},
|
|
785
|
+
open: E,
|
|
786
|
+
close: D,
|
|
787
|
+
toggle: () => u.isOpen ? D() : void E(),
|
|
788
|
+
destroy: O
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
//#endregion
|
|
792
|
+
//#region src/ui/components/icon.ts
|
|
793
|
+
function Y(e) {
|
|
794
|
+
return C(e, {
|
|
795
|
+
class: "stilo-icon",
|
|
796
|
+
"aria-hidden": "true"
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
800
|
+
//#region src/ui/components/color-button.ts
|
|
801
|
+
var X = 8, ee = "Mark", te = /^#[0-9a-f]{6}$/;
|
|
802
|
+
function Z(e, t) {
|
|
803
|
+
let n = document.createElement(e);
|
|
804
|
+
return n.className = t, n;
|
|
805
|
+
}
|
|
806
|
+
function Q(e, t) {
|
|
807
|
+
let n = Z("button", e);
|
|
808
|
+
return n.type = "button", n.setAttribute("aria-label", t), n.title = t, n;
|
|
809
|
+
}
|
|
810
|
+
function ne(e, t, r) {
|
|
811
|
+
let { container: i, messages: a } = r, o = a[t.labelKey] ?? t.labelKey, s = t.defaultColor, c = Z("span", "stilo-split"), l = Q("stilo-toolbar__button stilo-split__main", o), u = Z("span", "stilo-split__color");
|
|
812
|
+
l.append(Y(t.icon), u);
|
|
813
|
+
let d = Q("stilo-toolbar__button stilo-split__arrow", `${o}: ${a["color.more"]}`);
|
|
814
|
+
d.append(Y(n));
|
|
815
|
+
for (let e of [l, d]) e.dataset.item = t.id, e.tabIndex = -1;
|
|
816
|
+
l.setAttribute("aria-pressed", "false"), d.setAttribute("aria-haspopup", "dialog"), d.setAttribute("aria-expanded", "false"), c.append(l, d);
|
|
817
|
+
let f = Z("div", "stilo-color-picker");
|
|
818
|
+
f.setAttribute("role", "dialog"), f.setAttribute("aria-label", o);
|
|
819
|
+
let p = Z("div", "stilo-color-picker__actions"), m = Z("button", "stilo-color-picker__none");
|
|
820
|
+
m.type = "button", m.textContent = a["color.none"], p.append(m);
|
|
821
|
+
let h = null;
|
|
822
|
+
if (t.defaultChoice) {
|
|
823
|
+
let e = Z("span", "stilo-color-picker__separator");
|
|
824
|
+
e.setAttribute("aria-hidden", "true"), h = Z("button", "stilo-color-picker__default"), h.type = "button";
|
|
825
|
+
let t = document.createElement("mark");
|
|
826
|
+
t.textContent = a["color.default"], h.append(t), p.append(e, h);
|
|
827
|
+
}
|
|
828
|
+
let g = Z("div", "stilo-color-picker__grid");
|
|
829
|
+
g.setAttribute("role", "group"), g.setAttribute("aria-label", o);
|
|
830
|
+
let _ = t.palette.map(({ color: e, labelKey: t }) => {
|
|
831
|
+
let n = Q("stilo-color-picker__swatch", a[t] ?? t);
|
|
832
|
+
return n.tabIndex = -1, n.dataset.color = e, n.style.backgroundColor = e, n;
|
|
833
|
+
});
|
|
834
|
+
g.append(..._);
|
|
835
|
+
let v = Z("form", "stilo-color-picker__custom"), y = Z("input", "stilo-color-picker__native");
|
|
836
|
+
y.type = "color", y.setAttribute("aria-label", a["color.pick"]);
|
|
837
|
+
let b = Z("input", "stilo-color-picker__value");
|
|
838
|
+
b.type = "text", b.placeholder = "#000000", b.autocomplete = "off", b.spellcheck = !1, b.setAttribute("aria-label", a["color.custom"]);
|
|
839
|
+
let x = Z("button", "stilo-color-picker__apply");
|
|
840
|
+
x.type = "submit", x.textContent = a["color.apply"], v.append(y, b, x), f.append(p, g, v);
|
|
841
|
+
let S = N({
|
|
842
|
+
anchor: c,
|
|
843
|
+
content: f,
|
|
844
|
+
container: i,
|
|
845
|
+
onClose: (t) => {
|
|
846
|
+
d.setAttribute("aria-expanded", "false"), t === "escape" && e.focus();
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
function C() {
|
|
850
|
+
u.style.backgroundColor = s ?? ee;
|
|
851
|
+
}
|
|
852
|
+
function w() {
|
|
853
|
+
return t.isEnabled?.(e) ?? !0;
|
|
854
|
+
}
|
|
855
|
+
function T() {
|
|
856
|
+
let n = w();
|
|
857
|
+
for (let e of [l, d]) n ? e.removeAttribute("aria-disabled") : e.setAttribute("aria-disabled", "true");
|
|
858
|
+
let r = n && t.hasColor(e, s);
|
|
859
|
+
l.setAttribute("aria-pressed", String(r)), l.classList.toggle("stilo-toolbar__button--active", r);
|
|
860
|
+
}
|
|
861
|
+
function E(e, t) {
|
|
862
|
+
if (e) {
|
|
863
|
+
for (let e of _) e.tabIndex = -1;
|
|
864
|
+
e.tabIndex = 0, e.focus(t);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
function D() {
|
|
868
|
+
let n = t.getColor(e);
|
|
869
|
+
for (let e of _) e.setAttribute("aria-pressed", String(e.dataset.color === n));
|
|
870
|
+
h?.setAttribute("aria-pressed", String(t.hasColor(e, null))), b.value = n ?? "", b.removeAttribute("aria-invalid"), y.value = n && te.test(n) ? n : "#000000", S.open(), d.setAttribute("aria-expanded", "true");
|
|
871
|
+
let r = _.find((e) => e.getAttribute("aria-pressed") === "true");
|
|
872
|
+
!r && h?.getAttribute("aria-pressed") === "true" ? h.focus({ preventScroll: !0 }) : E(r ?? _[0], { preventScroll: !0 });
|
|
873
|
+
}
|
|
874
|
+
function O() {
|
|
875
|
+
S.close(), e.focus();
|
|
876
|
+
}
|
|
877
|
+
function k(n) {
|
|
878
|
+
return t.setColor(e, n) ? (s = t.getColor(e), C(), !0) : !1;
|
|
879
|
+
}
|
|
880
|
+
let A = () => {
|
|
881
|
+
w() && (S.close(), e.focus(), t.hasColor(e, s) ? t.unsetColor(e) : k(s));
|
|
882
|
+
}, j = () => {
|
|
883
|
+
S.isOpen ? O() : w() && D();
|
|
884
|
+
}, M = () => {
|
|
885
|
+
t.unsetColor(e), s = t.defaultColor, C(), O();
|
|
886
|
+
}, P = () => {
|
|
887
|
+
k(null), O();
|
|
888
|
+
}, F = (e) => {
|
|
889
|
+
let t = e.target.closest(".stilo-color-picker__swatch");
|
|
890
|
+
t?.dataset.color && (k(t.dataset.color), O());
|
|
891
|
+
}, I = (e) => {
|
|
892
|
+
let t = {
|
|
893
|
+
ArrowLeft: -1,
|
|
894
|
+
ArrowRight: 1,
|
|
895
|
+
ArrowUp: -8,
|
|
896
|
+
ArrowDown: X
|
|
897
|
+
}[e.key], n = _.indexOf(e.target);
|
|
898
|
+
t !== void 0 && n !== -1 && (e.preventDefault(), E(_[n + t]));
|
|
899
|
+
}, L = () => {
|
|
900
|
+
b.value = y.value, b.removeAttribute("aria-invalid");
|
|
901
|
+
}, R = () => b.removeAttribute("aria-invalid"), z = (e) => {
|
|
902
|
+
e.preventDefault(), k(b.value.trim()) ? O() : (b.setAttribute("aria-invalid", "true"), b.focus());
|
|
903
|
+
};
|
|
904
|
+
l.addEventListener("click", A), d.addEventListener("click", j), m.addEventListener("click", M), h?.addEventListener("click", P), g.addEventListener("click", F), g.addEventListener("keydown", I), y.addEventListener("input", L), b.addEventListener("input", R), v.addEventListener("submit", z), C();
|
|
905
|
+
function B() {
|
|
906
|
+
l.removeEventListener("click", A), d.removeEventListener("click", j), m.removeEventListener("click", M), h?.removeEventListener("click", P), g.removeEventListener("click", F), g.removeEventListener("keydown", I), y.removeEventListener("input", L), b.removeEventListener("input", R), v.removeEventListener("submit", z), S.destroy(), c.remove();
|
|
907
|
+
}
|
|
908
|
+
return {
|
|
909
|
+
element: c,
|
|
910
|
+
main: l,
|
|
911
|
+
arrow: d,
|
|
912
|
+
update: T,
|
|
913
|
+
destroy: B
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
//#endregion
|
|
917
|
+
//#region src/ui/components/dropdown.ts
|
|
918
|
+
function re(e) {
|
|
919
|
+
let { label: t, options: r, container: i, onSelect: a } = e, o = document.createElement("button");
|
|
920
|
+
o.type = "button", o.className = "stilo-toolbar__button stilo-dropdown__trigger", o.setAttribute("aria-haspopup", "menu"), o.setAttribute("aria-expanded", "false"), o.setAttribute("title", t), o.setAttribute("tabindex", "-1");
|
|
921
|
+
let s = document.createElement("span");
|
|
922
|
+
s.className = "stilo-dropdown__value", o.appendChild(s);
|
|
923
|
+
let c = Y(n);
|
|
924
|
+
o.appendChild(c);
|
|
925
|
+
let l = document.createElement("div");
|
|
926
|
+
l.className = "stilo-dropdown__menu stilo-popover", l.setAttribute("role", "menu"), l.setAttribute("aria-label", t), l.setAttribute("hidden", "");
|
|
927
|
+
let u = [];
|
|
928
|
+
for (let e of r) {
|
|
929
|
+
let t = document.createElement("div");
|
|
930
|
+
t.className = `stilo-dropdown__option stilo-dropdown__option--${e.id}`, t.setAttribute("role", "menuitemradio"), t.setAttribute("tabindex", "-1"), t.setAttribute("data-option", e.id), t.setAttribute("aria-checked", "false");
|
|
931
|
+
let n = document.createElement("span");
|
|
932
|
+
if (n.className = "stilo-dropdown__label", n.textContent = e.label, t.appendChild(n), e.shortcut) {
|
|
933
|
+
let n = document.createElement("span");
|
|
934
|
+
n.className = "stilo-dropdown__shortcut", n.textContent = e.shortcut, t.appendChild(n);
|
|
935
|
+
}
|
|
936
|
+
u.push(t), l.appendChild(t);
|
|
937
|
+
}
|
|
938
|
+
let d;
|
|
939
|
+
i.appendChild(l);
|
|
940
|
+
function f() {
|
|
941
|
+
if (d) return;
|
|
942
|
+
d = N({
|
|
943
|
+
anchor: o,
|
|
944
|
+
content: l,
|
|
945
|
+
container: i,
|
|
946
|
+
onClose(e) {
|
|
947
|
+
e === "escape" && o.focus(), o.setAttribute("aria-expanded", "false"), d = void 0;
|
|
948
|
+
}
|
|
949
|
+
}), o.setAttribute("aria-expanded", "true"), d.open();
|
|
950
|
+
let e = u.findIndex((e) => e.getAttribute("aria-checked") === "true");
|
|
951
|
+
if (e >= 0) u[e].focus();
|
|
952
|
+
else {
|
|
953
|
+
let e = u.findIndex((e) => e.getAttribute("aria-disabled") !== "true");
|
|
954
|
+
e >= 0 && u[e].focus();
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function p() {
|
|
958
|
+
d && (d.close(), o.setAttribute("aria-expanded", "false"));
|
|
959
|
+
}
|
|
960
|
+
function m() {
|
|
961
|
+
o.getAttribute("aria-disabled") !== "true" && (d ? p() : f());
|
|
962
|
+
}
|
|
963
|
+
o.addEventListener("click", m);
|
|
964
|
+
function h(e) {
|
|
965
|
+
if (o.getAttribute("aria-disabled") !== "true") switch (e.key) {
|
|
966
|
+
case "ArrowDown": {
|
|
967
|
+
e.preventDefault(), f();
|
|
968
|
+
let t = u.findIndex((e) => e.getAttribute("aria-disabled") !== "true");
|
|
969
|
+
t >= 0 && u[t].focus();
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
case "ArrowUp":
|
|
973
|
+
e.preventDefault(), f();
|
|
974
|
+
for (let e = u.length - 1; e >= 0; e--) if (u[e].getAttribute("aria-disabled") !== "true") {
|
|
975
|
+
u[e].focus();
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
o.addEventListener("keydown", h);
|
|
981
|
+
function g(e) {
|
|
982
|
+
let t = document.activeElement;
|
|
983
|
+
if (!t || !l.contains(t)) return;
|
|
984
|
+
let n = u.filter((e) => e.getAttribute("aria-disabled") !== "true"), r = n.indexOf(t);
|
|
985
|
+
switch (e.key) {
|
|
986
|
+
case "ArrowDown":
|
|
987
|
+
e.preventDefault(), n[(r + 1) % n.length].focus();
|
|
988
|
+
break;
|
|
989
|
+
case "ArrowUp":
|
|
990
|
+
e.preventDefault(), n[(r - 1 + n.length) % n.length].focus();
|
|
991
|
+
break;
|
|
992
|
+
case "Home":
|
|
993
|
+
e.preventDefault(), n[0].focus();
|
|
994
|
+
break;
|
|
995
|
+
case "End":
|
|
996
|
+
e.preventDefault(), n[n.length - 1].focus();
|
|
997
|
+
break;
|
|
998
|
+
case "Enter":
|
|
999
|
+
if (e.preventDefault(), t === document.activeElement && t !== o) {
|
|
1000
|
+
let e = t.getAttribute("data-option");
|
|
1001
|
+
e && t.getAttribute("aria-disabled") !== "true" && (a(e), p());
|
|
1002
|
+
}
|
|
1003
|
+
break;
|
|
1004
|
+
case " ":
|
|
1005
|
+
if (e.preventDefault(), t === document.activeElement && t !== o) {
|
|
1006
|
+
let e = t.getAttribute("data-option");
|
|
1007
|
+
e && t.getAttribute("aria-disabled") !== "true" && a(e);
|
|
1008
|
+
}
|
|
1009
|
+
break;
|
|
1010
|
+
case "Escape":
|
|
1011
|
+
e.preventDefault(), p(), o.focus();
|
|
1012
|
+
break;
|
|
1013
|
+
case "Tab": p();
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
l.addEventListener("keydown", g);
|
|
1017
|
+
for (let e of u) e.addEventListener("click", () => {
|
|
1018
|
+
let t = e.getAttribute("data-option");
|
|
1019
|
+
t && e.getAttribute("aria-disabled") !== "true" && (a(t), p());
|
|
1020
|
+
});
|
|
1021
|
+
let _ = !1;
|
|
1022
|
+
function v(e) {
|
|
1023
|
+
let { activeId: n, disabledIds: i } = e, a = r.find((e) => e.id === n)?.label ?? t;
|
|
1024
|
+
s.textContent = a, o.setAttribute("aria-label", `${t}: ${a}`), i.size === r.length ? o.setAttribute("aria-disabled", "true") : o.removeAttribute("aria-disabled");
|
|
1025
|
+
for (let e of u) {
|
|
1026
|
+
let t = e.getAttribute("data-option");
|
|
1027
|
+
i.has(t) ? e.setAttribute("aria-disabled", "true") : e.removeAttribute("aria-disabled"), e.setAttribute("aria-checked", t === n ? "true" : "false");
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
function y() {
|
|
1031
|
+
_ || (_ = !0, d?.destroy(), d = void 0, o.removeEventListener("click", m), o.removeEventListener("keydown", h), l.removeEventListener("keydown", g));
|
|
1032
|
+
}
|
|
1033
|
+
return {
|
|
1034
|
+
get trigger() {
|
|
1035
|
+
return o;
|
|
1036
|
+
},
|
|
1037
|
+
update: v,
|
|
1038
|
+
destroy: y
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/ui/components/link-bubble.ts
|
|
1043
|
+
function ie(e, t) {
|
|
1044
|
+
let { container: n, messages: r, onEdit: a } = t, o = null, s = {
|
|
1045
|
+
contextElement: e.view.dom,
|
|
1046
|
+
getBoundingClientRect: () => (o ?? e.view.dom).getBoundingClientRect()
|
|
1047
|
+
}, c = document.createElement("div");
|
|
1048
|
+
c.className = "stilo-link-bubble", c.setAttribute("role", "group"), c.setAttribute("aria-label", r["toolbar.link"]);
|
|
1049
|
+
let l = document.createElement("a");
|
|
1050
|
+
l.className = "stilo-link-bubble__button", l.target = "_blank", l.rel = "noopener noreferrer", l.setAttribute("aria-label", r["link.open"]), l.append(Y(i));
|
|
1051
|
+
let u = $(f, r["link.edit"]), d = $(S, r["link.remove"]);
|
|
1052
|
+
c.append(l, u, d);
|
|
1053
|
+
let p = N({
|
|
1054
|
+
anchor: s,
|
|
1055
|
+
content: c,
|
|
1056
|
+
container: n
|
|
1057
|
+
}), m = (e) => {
|
|
1058
|
+
e.preventDefault();
|
|
1059
|
+
}, h = () => {
|
|
1060
|
+
p.close(), a();
|
|
1061
|
+
}, g = () => {
|
|
1062
|
+
e.commands.unsetLink();
|
|
1063
|
+
};
|
|
1064
|
+
c.addEventListener("mousedown", m), u.addEventListener("click", h), d.addEventListener("click", g), e.on("transaction", v), e.on("focus", v), e.on("blur", v);
|
|
1065
|
+
function _() {
|
|
1066
|
+
let { selection: t } = e.state;
|
|
1067
|
+
if (!t.empty || !e.isActive("link") || !e.view.hasFocus()) return null;
|
|
1068
|
+
let { node: n } = e.view.domAtPos(t.from);
|
|
1069
|
+
return (n instanceof Element ? n : n.parentElement)?.closest("a") ?? null;
|
|
1070
|
+
}
|
|
1071
|
+
function v() {
|
|
1072
|
+
let t = _();
|
|
1073
|
+
if (t !== o && p.close(), o = t, !o) return;
|
|
1074
|
+
let n = String(e.getAttributes("link").href ?? "");
|
|
1075
|
+
l.href = n, l.title = `${r["link.open"]}: ${n}`, p.open();
|
|
1076
|
+
}
|
|
1077
|
+
function y() {
|
|
1078
|
+
e.off("transaction", v), e.off("focus", v), e.off("blur", v), c.removeEventListener("mousedown", m), u.removeEventListener("click", h), d.removeEventListener("click", g), p.destroy();
|
|
1079
|
+
}
|
|
1080
|
+
return {
|
|
1081
|
+
get isOpen() {
|
|
1082
|
+
return p.isOpen;
|
|
1083
|
+
},
|
|
1084
|
+
update: v,
|
|
1085
|
+
destroy: y
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
function $(e, t) {
|
|
1089
|
+
let n = document.createElement("button");
|
|
1090
|
+
return n.type = "button", n.className = "stilo-link-bubble__button", n.setAttribute("aria-label", t), n.title = t, n.append(Y(e)), n;
|
|
1091
|
+
}
|
|
1092
|
+
//#endregion
|
|
1093
|
+
//#region src/ui/toolbar/toolbar.ts
|
|
1094
|
+
function ae(t, n) {
|
|
1095
|
+
if (typeof t == "string") {
|
|
1096
|
+
let r = V[t];
|
|
1097
|
+
if (!r) throw new e(`Toolbar: unknown item "${t}"`);
|
|
1098
|
+
return r.isAvailable && !r.isAvailable(n) ? void 0 : r;
|
|
1099
|
+
}
|
|
1100
|
+
if (!t.isAvailable || t.isAvailable(n)) return t;
|
|
1101
|
+
}
|
|
1102
|
+
function oe(e, t) {
|
|
1103
|
+
let { container: n, items: r = B, messages: i = j, sticky: a = !0 } = t, o = k(), s = [];
|
|
1104
|
+
for (let t of r) {
|
|
1105
|
+
let n = [];
|
|
1106
|
+
for (let r of t) {
|
|
1107
|
+
let t = ae(r, e);
|
|
1108
|
+
t && n.push(t);
|
|
1109
|
+
}
|
|
1110
|
+
n.length > 0 && s.push(n);
|
|
1111
|
+
}
|
|
1112
|
+
let c = document.createElement("div");
|
|
1113
|
+
c.className = "stilo-toolbar", c.setAttribute("role", "toolbar"), c.setAttribute("aria-label", i?.["toolbar.label"] ?? "Formatting"), c.setAttribute("aria-orientation", "horizontal");
|
|
1114
|
+
let l = [], u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = [];
|
|
1115
|
+
for (let t of s) {
|
|
1116
|
+
let n = document.createElement("div");
|
|
1117
|
+
n.className = "stilo-toolbar__group", n.setAttribute("role", "group");
|
|
1118
|
+
for (let r of t) if (r.kind === "dropdown") {
|
|
1119
|
+
let t = r, a = t.options.map((e) => {
|
|
1120
|
+
let t = i[e.labelKey] ?? e.labelKey, n = e.shortcut ? A(e.shortcut, o) : void 0;
|
|
1121
|
+
return {
|
|
1122
|
+
id: e.id,
|
|
1123
|
+
label: t,
|
|
1124
|
+
shortcut: n
|
|
1125
|
+
};
|
|
1126
|
+
}), s = re({
|
|
1127
|
+
label: i[t.labelKey] ?? t.labelKey,
|
|
1128
|
+
options: a,
|
|
1129
|
+
container: c,
|
|
1130
|
+
onSelect: (n) => {
|
|
1131
|
+
let r = t.options.find((e) => e.id === n);
|
|
1132
|
+
r && (r.run(e), e.focus());
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
s.trigger.setAttribute("data-item", t.id), n.appendChild(s.trigger), l.push(s.trigger), u.set(s.trigger, t), d.set(t.id, s);
|
|
1136
|
+
} else if (r.kind === "color") {
|
|
1137
|
+
let t = ne(e, r, {
|
|
1138
|
+
container: c,
|
|
1139
|
+
messages: i
|
|
1140
|
+
});
|
|
1141
|
+
n.appendChild(t.element);
|
|
1142
|
+
for (let e of [t.main, t.arrow]) l.push(e), u.set(e, r);
|
|
1143
|
+
f.push(t);
|
|
1144
|
+
} else {
|
|
1145
|
+
let e = r, t = i[e.labelKey] ?? e.labelKey, a = e.shortcut === void 0 ? t : `${t} (${A(e.shortcut, o)})`, s = document.createElement("button");
|
|
1146
|
+
s.type = "button", s.className = "stilo-toolbar__button", s.setAttribute("data-item", e.id), s.setAttribute("aria-label", t), s.setAttribute("title", a), s.setAttribute("tabindex", "-1"), e.isActive && s.setAttribute("aria-pressed", "false");
|
|
1147
|
+
let c = Y(e.icon);
|
|
1148
|
+
s.appendChild(c), n.appendChild(s), l.push(s), u.set(s, e);
|
|
1149
|
+
}
|
|
1150
|
+
c.appendChild(n);
|
|
1151
|
+
}
|
|
1152
|
+
let p = e.view.dom.parentElement ?? c, m = "setLink" in e.commands ? I(e, {
|
|
1153
|
+
container: p,
|
|
1154
|
+
messages: i
|
|
1155
|
+
}) : null, h = m ? ie(e, {
|
|
1156
|
+
container: p,
|
|
1157
|
+
messages: i,
|
|
1158
|
+
onEdit: () => m.open()
|
|
1159
|
+
}) : null, g = c.querySelector("[data-item=\"characters\"]"), _ = g ? J(e, {
|
|
1160
|
+
anchor: g,
|
|
1161
|
+
container: c,
|
|
1162
|
+
messages: i
|
|
1163
|
+
}) : null, v = {
|
|
1164
|
+
openLinkPopover: () => m?.open(),
|
|
1165
|
+
toggleCharacterPicker: () => _?.toggle()
|
|
1166
|
+
};
|
|
1167
|
+
n.appendChild(c);
|
|
1168
|
+
let y = null;
|
|
1169
|
+
if (a) {
|
|
1170
|
+
n.classList.add("stilo-toolbar-host");
|
|
1171
|
+
let t = () => {
|
|
1172
|
+
let t = n.offsetHeight + 5;
|
|
1173
|
+
e.view.setProps({ scrollMargin: {
|
|
1174
|
+
top: t,
|
|
1175
|
+
right: 5,
|
|
1176
|
+
bottom: 5,
|
|
1177
|
+
left: 5
|
|
1178
|
+
} });
|
|
1179
|
+
};
|
|
1180
|
+
t(), typeof ResizeObserver < "u" && (y = new ResizeObserver(t), y.observe(n));
|
|
1181
|
+
}
|
|
1182
|
+
let b = 0, x = !1, S = 0;
|
|
1183
|
+
function C(e) {
|
|
1184
|
+
l.forEach((t, n) => {
|
|
1185
|
+
t.setAttribute("tabindex", n === e ? "0" : "-1");
|
|
1186
|
+
}), S = e;
|
|
1187
|
+
}
|
|
1188
|
+
C(0);
|
|
1189
|
+
function w() {
|
|
1190
|
+
for (let e of f) e.update();
|
|
1191
|
+
for (let t of l) {
|
|
1192
|
+
let n = u.get(t);
|
|
1193
|
+
if (n && n.kind !== "color") {
|
|
1194
|
+
if (n.kind === "dropdown") {
|
|
1195
|
+
let t = n, r = null, i = /* @__PURE__ */ new Set();
|
|
1196
|
+
for (let n of t.options) {
|
|
1197
|
+
let t = n.isActive(e);
|
|
1198
|
+
n.isEnabled !== void 0 && !n.isEnabled(e) && i.add(n.id), t && r === null && (r = n.id);
|
|
1199
|
+
}
|
|
1200
|
+
d.get(t.id)?.update({
|
|
1201
|
+
activeId: r,
|
|
1202
|
+
disabledIds: i
|
|
1203
|
+
});
|
|
1204
|
+
} else {
|
|
1205
|
+
let r = t, i = n;
|
|
1206
|
+
if (i.isActive) {
|
|
1207
|
+
let t = i.isActive(e);
|
|
1208
|
+
r.setAttribute("aria-pressed", t ? "true" : "false"), t ? r.classList.add("stilo-toolbar__button--active") : r.classList.remove("stilo-toolbar__button--active");
|
|
1209
|
+
} else r.removeAttribute("aria-pressed"), r.classList.remove("stilo-toolbar__button--active");
|
|
1210
|
+
i.isEnabled ? i.isEnabled(e) ? r.removeAttribute("aria-disabled") : r.setAttribute("aria-disabled", "true") : r.removeAttribute("aria-disabled");
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
w();
|
|
1216
|
+
let T = () => {
|
|
1217
|
+
x || (b ||= requestAnimationFrame(() => {
|
|
1218
|
+
x || (b = 0, w());
|
|
1219
|
+
}));
|
|
1220
|
+
};
|
|
1221
|
+
e.on("transaction", T);
|
|
1222
|
+
let E = (e) => {
|
|
1223
|
+
x || e.target.closest(".stilo-char-picker, .stilo-color-picker") || e.preventDefault();
|
|
1224
|
+
};
|
|
1225
|
+
c.addEventListener("mousedown", E);
|
|
1226
|
+
let D = (t) => {
|
|
1227
|
+
if (x) return;
|
|
1228
|
+
let n = t.target.closest("[data-item]");
|
|
1229
|
+
if (!n) return;
|
|
1230
|
+
let r = u.get(n);
|
|
1231
|
+
r && r.kind === "button" && (!r.isEnabled || r.isEnabled(e)) && (e.focus(), r.run(e, v));
|
|
1232
|
+
};
|
|
1233
|
+
c.addEventListener("click", D);
|
|
1234
|
+
let O = (t) => {
|
|
1235
|
+
if (x) return;
|
|
1236
|
+
let n = t.target.closest("[data-item]");
|
|
1237
|
+
if (!n) return;
|
|
1238
|
+
let r = l.indexOf(n);
|
|
1239
|
+
if (r !== -1) switch (t.key) {
|
|
1240
|
+
case "ArrowRight": {
|
|
1241
|
+
t.preventDefault();
|
|
1242
|
+
let e = (r + 1) % l.length;
|
|
1243
|
+
C(e), l[e].focus();
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
case "ArrowLeft": {
|
|
1247
|
+
t.preventDefault();
|
|
1248
|
+
let e = (r - 1 + l.length) % l.length;
|
|
1249
|
+
C(e), l[e].focus();
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
case "Home":
|
|
1253
|
+
t.preventDefault(), C(0), l[0].focus();
|
|
1254
|
+
break;
|
|
1255
|
+
case "End": {
|
|
1256
|
+
t.preventDefault();
|
|
1257
|
+
let e = l.length - 1;
|
|
1258
|
+
C(e), l[e].focus();
|
|
1259
|
+
break;
|
|
1260
|
+
}
|
|
1261
|
+
case "Escape": t.preventDefault(), e.focus();
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
c.addEventListener("keydown", O);
|
|
1265
|
+
let M = (t) => {
|
|
1266
|
+
if (x) return;
|
|
1267
|
+
let n = o ? t.metaKey : t.ctrlKey;
|
|
1268
|
+
m && n && !t.altKey && !t.shiftKey && t.key.toLowerCase() === "k" ? (t.preventDefault(), m.open()) : t.key === "F10" && t.altKey && (t.preventDefault(), e.focus(), S >= 0 && S < l.length && l[S].focus());
|
|
1269
|
+
};
|
|
1270
|
+
e.view.dom.addEventListener("keydown", M);
|
|
1271
|
+
let N = () => {
|
|
1272
|
+
P();
|
|
1273
|
+
};
|
|
1274
|
+
e.on("destroy", N);
|
|
1275
|
+
function P() {
|
|
1276
|
+
if (!x) {
|
|
1277
|
+
x = !0, b &&= (cancelAnimationFrame(b), 0), e.off("transaction", T), e.off("destroy", N), c.removeEventListener("mousedown", E), c.removeEventListener("click", D), c.removeEventListener("keydown", O), e.view.dom.removeEventListener("keydown", M);
|
|
1278
|
+
for (let e of d.values()) e.destroy();
|
|
1279
|
+
for (let e of f) e.destroy();
|
|
1280
|
+
m?.destroy(), h?.destroy(), _?.destroy(), n.contains(c) && n.removeChild(c), a && (y?.disconnect(), n.classList.remove("stilo-toolbar-host"), e.view.setProps({ scrollMargin: void 0 }));
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return {
|
|
1284
|
+
get element() {
|
|
1285
|
+
return c;
|
|
1286
|
+
},
|
|
1287
|
+
update: w,
|
|
1288
|
+
destroy: P
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
//#endregion
|
|
1292
|
+
export { V as DEFAULT_ITEMS, z as DEFAULT_PALETTE, B as DEFAULT_TOOLBAR, oe as createToolbar, j as en, A as formatShortcut, G as headingDropdown, W as highlightButton, M as it, U as textColorButton };
|