@vitral/editor 0.2.9 → 0.2.11
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/README.md +8 -0
- package/dist/buttons.js +3 -1
- package/dist/buttons.js.map +1 -1
- package/dist/editor.js +42 -4
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/math.d.ts +61 -0
- package/dist/math.js +404 -0
- package/dist/math.js.map +1 -0
- package/dist/render/toolbar.d.ts +2 -0
- package/dist/render/toolbar.js +17 -6
- package/dist/render/toolbar.js.map +1 -1
- package/dist/slash.js +2 -1
- package/dist/slash.js.map +1 -1
- package/dist/types.d.ts +43 -4
- package/package.json +6 -6
package/dist/math.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { drawMath, editorMathAt, en, isMathLoaded, loadMath, overlayContainerOf, paintMath } from "@vitral/core";
|
|
2
|
+
import { createOverlay } from "@vitral/controls";
|
|
3
|
+
import { h, mergeAttrs } from "@vitral/dom";
|
|
4
|
+
//#region src/math.ts
|
|
5
|
+
/** The formulas the panel offers when an application names none. */
|
|
6
|
+
function defaultMathTemplates(locale) {
|
|
7
|
+
const names = locale.editor.mathTemplateNames;
|
|
8
|
+
const entry = (id, latex) => ({
|
|
9
|
+
id,
|
|
10
|
+
label: names[id] ?? id,
|
|
11
|
+
latex
|
|
12
|
+
});
|
|
13
|
+
return [
|
|
14
|
+
entry("fraction", "\\frac{a}{b}"),
|
|
15
|
+
entry("squareRoot", "\\sqrt{x}"),
|
|
16
|
+
entry("root", "\\sqrt[n]{x}"),
|
|
17
|
+
entry("power", "x^{2}"),
|
|
18
|
+
entry("subscript", "x_{i}"),
|
|
19
|
+
entry("sum", "\\sum_{i=1}^{n} i"),
|
|
20
|
+
entry("product", "\\prod_{k=1}^{n} k"),
|
|
21
|
+
entry("integral", "\\int_{a}^{b} x \\, dx"),
|
|
22
|
+
entry("limit", "\\lim_{x \\to 0} f(x)"),
|
|
23
|
+
entry("parentheses", "\\left( \\frac{a}{b} \\right)"),
|
|
24
|
+
entry("matrix", "\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}"),
|
|
25
|
+
entry("cases", "\\begin{cases} a & x > 0 \\\\ b & x \\leq 0 \\end{cases}"),
|
|
26
|
+
entry("quadratic", "x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}"),
|
|
27
|
+
entry("times", "\\times"),
|
|
28
|
+
entry("divide", "\\div"),
|
|
29
|
+
entry("plusMinus", "\\pm"),
|
|
30
|
+
entry("lessEqual", "\\leq"),
|
|
31
|
+
entry("greaterEqual", "\\geq"),
|
|
32
|
+
entry("notEqual", "\\neq"),
|
|
33
|
+
entry("approximately", "\\approx"),
|
|
34
|
+
entry("pi", "\\pi"),
|
|
35
|
+
entry("infinity", "\\infty")
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
var SOURCE = "data-vt-math-source";
|
|
39
|
+
function createMathTools(options) {
|
|
40
|
+
let panel = null;
|
|
41
|
+
let anchorEl = null;
|
|
42
|
+
/** A piece of the source to select when the panel's box is first drawn. */
|
|
43
|
+
let select = null;
|
|
44
|
+
let inline = null;
|
|
45
|
+
let element = null;
|
|
46
|
+
const locale = () => options.locale?.() ?? en;
|
|
47
|
+
const enabled = () => options.enabled?.() ?? true;
|
|
48
|
+
const id = options.id ?? "vt-math";
|
|
49
|
+
const run = (name, ...args) => options.editor.run(name, ...args);
|
|
50
|
+
/** The formula's position from its element: the view reads a point inside one as just after it. */
|
|
51
|
+
function positionOf(host) {
|
|
52
|
+
const after = options.view()?.posFromDOM(host, 0);
|
|
53
|
+
return after && after.offset > 0 ? {
|
|
54
|
+
path: after.path,
|
|
55
|
+
offset: after.offset - 1
|
|
56
|
+
} : null;
|
|
57
|
+
}
|
|
58
|
+
function elementAt(at) {
|
|
59
|
+
const formulas = options.content()?.querySelectorAll("[data-math]") ?? [];
|
|
60
|
+
for (const host of Array.from(formulas)) {
|
|
61
|
+
const position = positionOf(host);
|
|
62
|
+
if (position && position.offset === at.offset && position.path.join(".") === at.path.join(".")) return host;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const overlay = createOverlay({
|
|
67
|
+
anchor: () => anchorEl,
|
|
68
|
+
render: () => panel ? panelView(panel) : null,
|
|
69
|
+
placement: "bottom-start",
|
|
70
|
+
target: () => options.overlayTarget,
|
|
71
|
+
zIndex: options.zIndex,
|
|
72
|
+
restoreFocus: false,
|
|
73
|
+
onOpen: (drawn) => {
|
|
74
|
+
const box = drawn.querySelector(`[${SOURCE}]`);
|
|
75
|
+
if (!box) return;
|
|
76
|
+
box.focus({ preventScroll: true });
|
|
77
|
+
if (select) box.setSelectionRange(select[0], select[1]);
|
|
78
|
+
else box.select();
|
|
79
|
+
select = null;
|
|
80
|
+
},
|
|
81
|
+
onClose: (reason) => {
|
|
82
|
+
panel = null;
|
|
83
|
+
if (reason === "escape") options.focus?.();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* What the panel draws a formula with: the drawing, or the source while
|
|
88
|
+
* there is nothing to draw with. The panel centres it, so where it would
|
|
89
|
+
* hang from a baseline does not come into it.
|
|
90
|
+
*/
|
|
91
|
+
const drawn = (tag, props, latex, display) => {
|
|
92
|
+
const drawing = drawMath(latex, { display });
|
|
93
|
+
return drawing ? h(tag, mergeAttrs(props, { innerHTML: drawing.svg })) : h(tag, props, latex);
|
|
94
|
+
};
|
|
95
|
+
function panelView(state) {
|
|
96
|
+
const words = locale().editor;
|
|
97
|
+
const { part } = options;
|
|
98
|
+
const button = (key, label, onClick, quiet = true) => h("button", mergeAttrs({
|
|
99
|
+
key,
|
|
100
|
+
type: "button",
|
|
101
|
+
class: quiet ? "vt-button vt-button-text vt-button-secondary vt-button-sm" : "vt-button vt-button-sm"
|
|
102
|
+
}, { onClick }), label);
|
|
103
|
+
const source = state.latex.trim();
|
|
104
|
+
return h("div", mergeAttrs({
|
|
105
|
+
role: "dialog",
|
|
106
|
+
id
|
|
107
|
+
}, part("panel"), part("mathPanel"), { "aria-label": words.math }), source ? drawn("div", mergeAttrs({ key: "preview" }, part("mathPreview")), source, state.display) : h("div", mergeAttrs({ key: "empty" }, part("mathPreview", { empty: true })), words.mathEmpty), h("label", mergeAttrs({ key: "source" }, part("field")), h("span", part("fieldLabel"), words.mathSource), h("span", { class: "vt-field vt-field-sm vt-field-fluid" }, h("input", {
|
|
108
|
+
type: "text",
|
|
109
|
+
class: "vt-field-input",
|
|
110
|
+
spellcheck: "false",
|
|
111
|
+
autocomplete: "off",
|
|
112
|
+
autocapitalize: "off",
|
|
113
|
+
[SOURCE]: "",
|
|
114
|
+
value: state.latex,
|
|
115
|
+
onInput: (event) => {
|
|
116
|
+
if (!panel) return;
|
|
117
|
+
panel = {
|
|
118
|
+
...panel,
|
|
119
|
+
latex: event.target.value
|
|
120
|
+
};
|
|
121
|
+
overlay.update();
|
|
122
|
+
},
|
|
123
|
+
onKeydown: (event) => {
|
|
124
|
+
if (event.key !== "Enter") return;
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
apply();
|
|
127
|
+
}
|
|
128
|
+
}))), h("label", mergeAttrs({ key: "display" }, part("check")), h("input", {
|
|
129
|
+
type: "checkbox",
|
|
130
|
+
checked: state.display,
|
|
131
|
+
onChange: (event) => {
|
|
132
|
+
if (!panel) return;
|
|
133
|
+
panel = {
|
|
134
|
+
...panel,
|
|
135
|
+
display: event.target.checked
|
|
136
|
+
};
|
|
137
|
+
overlay.update();
|
|
138
|
+
}
|
|
139
|
+
}), h("span", null, words.mathDisplay)), templates().length ? h("div", mergeAttrs({
|
|
140
|
+
key: "templates",
|
|
141
|
+
role: "group"
|
|
142
|
+
}, part("mathTemplates"), { "aria-label": words.mathTemplates }), templates().map((template) => drawn("button", mergeAttrs({
|
|
143
|
+
key: template.id,
|
|
144
|
+
type: "button"
|
|
145
|
+
}, part("mathTemplate"), {
|
|
146
|
+
"aria-label": template.label,
|
|
147
|
+
title: template.label,
|
|
148
|
+
onClick: () => write(template.latex)
|
|
149
|
+
}), template.latex, false))) : null, h("div", mergeAttrs({ key: "actions" }, part("actions")), state.at ? button("remove", words.removeMath, remove) : null, button("cancel", locale().cancel, cancel), button("apply", state.at ? words.apply : words.insert, apply, false)));
|
|
150
|
+
}
|
|
151
|
+
let offered = [];
|
|
152
|
+
const templates = () => offered;
|
|
153
|
+
/** Writes a ready-made formula into the box, over what is selected there, and leaves the caret after it. */
|
|
154
|
+
function write(latex) {
|
|
155
|
+
if (!panel) return;
|
|
156
|
+
const box = overlay.element()?.querySelector(`[${SOURCE}]`);
|
|
157
|
+
const start = box?.selectionStart ?? panel.latex.length;
|
|
158
|
+
const end = box?.selectionEnd ?? start;
|
|
159
|
+
const before = panel.latex.slice(0, start);
|
|
160
|
+
const glue = /\\[a-zA-Z]+$/.test(before) && /^[a-zA-Z]/.test(latex) ? " " : "";
|
|
161
|
+
const after = panel.latex.slice(end);
|
|
162
|
+
const tail = /\\[a-zA-Z]+$/.test(latex) && /^[a-zA-Z]/.test(after) ? " " : "";
|
|
163
|
+
panel = {
|
|
164
|
+
...panel,
|
|
165
|
+
latex: before + glue + latex + tail + after
|
|
166
|
+
};
|
|
167
|
+
overlay.update();
|
|
168
|
+
const caret = before.length + glue.length + latex.length + tail.length;
|
|
169
|
+
box?.focus({ preventScroll: true });
|
|
170
|
+
box?.setSelectionRange(caret, caret);
|
|
171
|
+
}
|
|
172
|
+
function apply() {
|
|
173
|
+
if (!panel) return;
|
|
174
|
+
const { at, display } = panel;
|
|
175
|
+
const latex = panel.latex.trim();
|
|
176
|
+
overlay.close();
|
|
177
|
+
if (at) run("setMath", at, {
|
|
178
|
+
latex,
|
|
179
|
+
display
|
|
180
|
+
});
|
|
181
|
+
else if (latex) run("insertMath", {
|
|
182
|
+
latex,
|
|
183
|
+
display
|
|
184
|
+
});
|
|
185
|
+
options.focus?.();
|
|
186
|
+
}
|
|
187
|
+
function remove() {
|
|
188
|
+
if (!panel?.at) return;
|
|
189
|
+
const { at } = panel;
|
|
190
|
+
overlay.close();
|
|
191
|
+
run("setMath", at, { latex: "" });
|
|
192
|
+
options.focus?.();
|
|
193
|
+
}
|
|
194
|
+
function cancel() {
|
|
195
|
+
overlay.close();
|
|
196
|
+
options.focus?.();
|
|
197
|
+
}
|
|
198
|
+
function openPanel(state, anchor, range) {
|
|
199
|
+
endInline(true);
|
|
200
|
+
offered = options.templates();
|
|
201
|
+
panel = state;
|
|
202
|
+
select = range ?? null;
|
|
203
|
+
anchorEl = anchor ?? (state.at ? elementAt(state.at) : null);
|
|
204
|
+
if (!anchorEl) {
|
|
205
|
+
options.place?.();
|
|
206
|
+
anchorEl = options.anchor();
|
|
207
|
+
}
|
|
208
|
+
if (overlay.isOpen) overlay.close();
|
|
209
|
+
overlay.open();
|
|
210
|
+
overlay.update();
|
|
211
|
+
if (!isMathLoaded()) loadMath().then(() => overlay.update());
|
|
212
|
+
}
|
|
213
|
+
function open(anchor) {
|
|
214
|
+
if (!enabled()) return;
|
|
215
|
+
const on = editorMathAt(options.editor.state);
|
|
216
|
+
openPanel(on ? {
|
|
217
|
+
at: {
|
|
218
|
+
path: on.path,
|
|
219
|
+
offset: on.offset
|
|
220
|
+
},
|
|
221
|
+
latex: on.latex,
|
|
222
|
+
display: on.display
|
|
223
|
+
} : {
|
|
224
|
+
at: null,
|
|
225
|
+
latex: "",
|
|
226
|
+
display: false
|
|
227
|
+
}, anchor);
|
|
228
|
+
}
|
|
229
|
+
/** The box is put over the piece it stands for, and is at least wide enough for what is in it. */
|
|
230
|
+
function placeInline() {
|
|
231
|
+
if (!inline) return;
|
|
232
|
+
const { host, input, start } = inline;
|
|
233
|
+
const end = start + input.value.length;
|
|
234
|
+
const rect = (host.querySelector(`[data-at="${start},${end}"]`) ?? host).getBoundingClientRect();
|
|
235
|
+
const size = Number.parseFloat(getComputedStyle(host).fontSize) || 16;
|
|
236
|
+
const width = Math.max(rect.width + size * .35, (input.value.length + .8) * size * .62);
|
|
237
|
+
const height = Math.max(rect.height, size * 1.3);
|
|
238
|
+
input.style.fontSize = `${size}px`;
|
|
239
|
+
input.style.width = `${width}px`;
|
|
240
|
+
input.style.height = `${height}px`;
|
|
241
|
+
input.style.left = `${rect.left + rect.width / 2 - width / 2}px`;
|
|
242
|
+
input.style.top = `${rect.top + rect.height / 2 - height / 2}px`;
|
|
243
|
+
}
|
|
244
|
+
const inlineSource = (state) => state.source.slice(0, state.start) + state.input.value + state.source.slice(state.end);
|
|
245
|
+
function startInline(host, at, start, end) {
|
|
246
|
+
endInline(true);
|
|
247
|
+
if (overlay.isOpen) overlay.close();
|
|
248
|
+
const source = host.getAttribute("data-math") ?? "";
|
|
249
|
+
const input = document.createElement("input");
|
|
250
|
+
input.type = "text";
|
|
251
|
+
input.value = source.slice(start, end);
|
|
252
|
+
input.spellcheck = false;
|
|
253
|
+
input.autocomplete = "off";
|
|
254
|
+
input.setAttribute("autocapitalize", "off");
|
|
255
|
+
input.setAttribute("aria-label", locale().editor.mathValue);
|
|
256
|
+
for (const [key, value] of Object.entries(options.part("mathInput"))) if (typeof value === "string") input.setAttribute(key, value);
|
|
257
|
+
input.style.position = "fixed";
|
|
258
|
+
input.style.zIndex = String(options.zIndex ?? 1e3);
|
|
259
|
+
inline = {
|
|
260
|
+
at,
|
|
261
|
+
host,
|
|
262
|
+
source,
|
|
263
|
+
display: host.getAttribute("data-display") === "true",
|
|
264
|
+
start,
|
|
265
|
+
end,
|
|
266
|
+
input
|
|
267
|
+
};
|
|
268
|
+
input.addEventListener("input", onInlineInput);
|
|
269
|
+
input.addEventListener("keydown", onInlineKeydown);
|
|
270
|
+
input.addEventListener("blur", onInlineBlur);
|
|
271
|
+
(overlayContainerOf(host) ?? host.ownerDocument.body).appendChild(input);
|
|
272
|
+
host.setAttribute("data-editing", "");
|
|
273
|
+
placeInline();
|
|
274
|
+
input.focus({ preventScroll: true });
|
|
275
|
+
input.select();
|
|
276
|
+
window.addEventListener("scroll", onInlineScroll, true);
|
|
277
|
+
window.addEventListener("resize", onInlineScroll);
|
|
278
|
+
}
|
|
279
|
+
/** The formula follows the typing: drawn again from what the source would be, before any of it is kept. */
|
|
280
|
+
function onInlineInput() {
|
|
281
|
+
if (!inline) return;
|
|
282
|
+
paintMath(inline.host, inlineSource(inline), {
|
|
283
|
+
display: inline.display,
|
|
284
|
+
interactive: true
|
|
285
|
+
});
|
|
286
|
+
placeInline();
|
|
287
|
+
}
|
|
288
|
+
function onInlineKeydown(event) {
|
|
289
|
+
if (!inline) return;
|
|
290
|
+
if (event.key === "Enter") {
|
|
291
|
+
event.preventDefault();
|
|
292
|
+
endInline(true);
|
|
293
|
+
options.focus?.();
|
|
294
|
+
} else if (event.key === "Escape") {
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
event.stopPropagation();
|
|
297
|
+
endInline(false);
|
|
298
|
+
options.focus?.();
|
|
299
|
+
} else if (event.key === "Tab") {
|
|
300
|
+
event.preventDefault();
|
|
301
|
+
const { at, start } = inline;
|
|
302
|
+
const length = inline.input.value.length;
|
|
303
|
+
const forward = !event.shiftKey;
|
|
304
|
+
endInline(true);
|
|
305
|
+
const host = elementAt(at);
|
|
306
|
+
const leaves = host ? Array.from(host.querySelectorAll("[data-leaf]")).map((leaf) => leaf.getAttribute("data-at").split(",").map(Number)) : [];
|
|
307
|
+
leaves.sort((a, b) => a[0] - b[0]);
|
|
308
|
+
const next = forward ? leaves.find(([from]) => from >= start + length) : leaves.reverse().find(([, to]) => to <= start);
|
|
309
|
+
if (host && next) startInline(host, at, next[0], next[1]);
|
|
310
|
+
else options.focus?.();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const onInlineBlur = () => endInline(true);
|
|
314
|
+
const onInlineScroll = (event) => {
|
|
315
|
+
if (event.target !== inline?.input) placeInline();
|
|
316
|
+
};
|
|
317
|
+
/** Closes the box. `keep` writes what was typed into the document, as one change; otherwise the formula is drawn as it was. */
|
|
318
|
+
function endInline(keep) {
|
|
319
|
+
const state = inline;
|
|
320
|
+
if (!state) return;
|
|
321
|
+
inline = null;
|
|
322
|
+
const { input, host, at } = state;
|
|
323
|
+
input.removeEventListener("blur", onInlineBlur);
|
|
324
|
+
input.removeEventListener("input", onInlineInput);
|
|
325
|
+
input.removeEventListener("keydown", onInlineKeydown);
|
|
326
|
+
window.removeEventListener("scroll", onInlineScroll, true);
|
|
327
|
+
window.removeEventListener("resize", onInlineScroll);
|
|
328
|
+
input.remove();
|
|
329
|
+
host.removeAttribute("data-editing");
|
|
330
|
+
const next = inlineSource(state);
|
|
331
|
+
if (keep && next !== state.source) {
|
|
332
|
+
paintMath(host, state.source, {
|
|
333
|
+
display: state.display,
|
|
334
|
+
interactive: true
|
|
335
|
+
});
|
|
336
|
+
run("setMath", at, { latex: next });
|
|
337
|
+
} else if (host.isConnected) paintMath(host, state.source, {
|
|
338
|
+
display: state.display,
|
|
339
|
+
interactive: true
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function onClick(event) {
|
|
343
|
+
const target = event.target;
|
|
344
|
+
const host = target?.closest?.("[data-math]");
|
|
345
|
+
if (!host || !element?.contains(host) || !enabled() || inline?.host === host) return;
|
|
346
|
+
const at = positionOf(host);
|
|
347
|
+
if (!at) return;
|
|
348
|
+
event.preventDefault();
|
|
349
|
+
const piece = target.closest("[data-at]");
|
|
350
|
+
const range = piece && host.contains(piece) ? piece.getAttribute("data-at").split(",").map(Number) : null;
|
|
351
|
+
if (range && piece.hasAttribute("data-leaf") && (options.inlineEdit?.() ?? true) && isMathLoaded()) {
|
|
352
|
+
startInline(host, at, range[0], range[1]);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
openPanel({
|
|
356
|
+
at,
|
|
357
|
+
latex: host.getAttribute("data-math") ?? "",
|
|
358
|
+
display: host.getAttribute("data-display") === "true"
|
|
359
|
+
}, host, range ?? void 0);
|
|
360
|
+
}
|
|
361
|
+
function listen() {
|
|
362
|
+
const next = options.content();
|
|
363
|
+
if (next === element) return;
|
|
364
|
+
element?.removeEventListener("click", onClick);
|
|
365
|
+
element = next;
|
|
366
|
+
element?.addEventListener("click", onClick);
|
|
367
|
+
}
|
|
368
|
+
const stop = options.editor.subscribe(() => {
|
|
369
|
+
listen();
|
|
370
|
+
if (!enabled()) {
|
|
371
|
+
endInline(false);
|
|
372
|
+
if (overlay.isOpen) overlay.close();
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (inline || panel?.at) queueMicrotask(settle);
|
|
376
|
+
});
|
|
377
|
+
function settle() {
|
|
378
|
+
if (inline && !inline.host.isConnected) endInline(false);
|
|
379
|
+
if (panel?.at && !elementAt(panel.at)) overlay.close();
|
|
380
|
+
}
|
|
381
|
+
listen();
|
|
382
|
+
return {
|
|
383
|
+
get isOpen() {
|
|
384
|
+
return overlay.isOpen;
|
|
385
|
+
},
|
|
386
|
+
open,
|
|
387
|
+
sync: listen,
|
|
388
|
+
close() {
|
|
389
|
+
endInline(true);
|
|
390
|
+
if (overlay.isOpen) overlay.close();
|
|
391
|
+
},
|
|
392
|
+
destroy() {
|
|
393
|
+
stop();
|
|
394
|
+
endInline(false);
|
|
395
|
+
element?.removeEventListener("click", onClick);
|
|
396
|
+
element = null;
|
|
397
|
+
overlay.destroy();
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
//#endregion
|
|
402
|
+
export { createMathTools, defaultMathTemplates };
|
|
403
|
+
|
|
404
|
+
//# sourceMappingURL=math.js.map
|
package/dist/math.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","names":[],"sources":["../src/math.ts"],"sourcesContent":["import { drawMath, editorMathAt, en, isMathLoaded, loadMath, overlayContainerOf, paintMath, type EditorInstance, type EditorPosition, type EditorView, type Locale } from '@vitral/core';\nimport { createOverlay, type OverlayTarget } from '@vitral/controls';\nimport { h, mergeAttrs, type Props, type VElement } from '@vitral/dom';\nimport type { MathTemplate } from './types';\n\n/**\n * Formulas, as a piece that attaches to any editor, the way the slash menu\n * does. A formula is held as LaTeX and drawn from it, and there are two ways\n * to change one:\n *\n * - the panel, which the toolbar's button and the slash menu open: the source\n * in a box, the formula drawn above it as it is typed, and the usual\n * formulas ready-made on buttons;\n * - pressing it in the text. A number, a letter or a sign is edited where it\n * stands, in a box over it, and the formula is drawn again around it with\n * every key; Tab goes on to the next value. A press anywhere else on the\n * formula opens the panel with that piece of the source selected.\n *\n * Either way the document only ever holds the source, and the drawing is made\n * from it again, so there is no drawing to get out of step. What is typed is\n * never trusted to be a formula: a piece that cannot be read is drawn as\n * written, where it stands, and the rest of the formula around it.\n */\n\nexport interface MathToolsOptions {\n editor: EditorInstance;\n view: () => EditorView | null;\n /** The `contenteditable` element, where a press on a formula is heard. */\n content: () => HTMLElement | null;\n /** What the panel hangs from when it is opened by no button and on no formula: an element over the caret. */\n anchor: () => HTMLElement | null;\n /** Puts that element where the caret is, before the panel opens. */\n place?: () => void;\n /** The ready-made formulas on offer; read every time the panel opens. */\n templates: () => MathTemplate[];\n /** Whether a value is edited where it stands. */\n inlineEdit?: () => boolean;\n part: (name: string, state?: unknown) => Props;\n locale?: () => Locale;\n /** Off while the editor is read-only, or has formulas turned off. */\n enabled?: () => boolean;\n /** Puts the keyboard back in the text. */\n focus?: () => void;\n id?: string;\n overlayTarget?: OverlayTarget;\n zIndex?: number;\n}\n\nexport interface MathTools {\n readonly isOpen: boolean;\n /**\n * Opens the panel: on the formula the selection is on, to change it, or\n * for a new one where the caret is. `anchor` is what it hangs from, a\n * toolbar button say; the formula itself, or the caret, otherwise.\n */\n open(anchor?: HTMLElement | null): void;\n /** Looks again for the element the text is in: called when the host has drawn. */\n sync(): void;\n close(): void;\n destroy(): void;\n}\n\n/** The formulas the panel offers when an application names none. */\nexport function defaultMathTemplates(locale: Locale): MathTemplate[] {\n const names = locale.editor.mathTemplateNames;\n const entry = (id: string, latex: string): MathTemplate => ({ id, label: names[id] ?? id, latex });\n return [\n entry('fraction', '\\\\frac{a}{b}'),\n entry('squareRoot', '\\\\sqrt{x}'),\n entry('root', '\\\\sqrt[n]{x}'),\n entry('power', 'x^{2}'),\n entry('subscript', 'x_{i}'),\n entry('sum', '\\\\sum_{i=1}^{n} i'),\n entry('product', '\\\\prod_{k=1}^{n} k'),\n entry('integral', '\\\\int_{a}^{b} x \\\\, dx'),\n entry('limit', '\\\\lim_{x \\\\to 0} f(x)'),\n entry('parentheses', '\\\\left( \\\\frac{a}{b} \\\\right)'),\n entry('matrix', '\\\\begin{pmatrix} a & b \\\\\\\\ c & d \\\\end{pmatrix}'),\n entry('cases', '\\\\begin{cases} a & x > 0 \\\\\\\\ b & x \\\\leq 0 \\\\end{cases}'),\n entry('quadratic', 'x = \\\\frac{-b \\\\pm \\\\sqrt{b^2 - 4ac}}{2a}'),\n entry('times', '\\\\times'),\n entry('divide', '\\\\div'),\n entry('plusMinus', '\\\\pm'),\n entry('lessEqual', '\\\\leq'),\n entry('greaterEqual', '\\\\geq'),\n entry('notEqual', '\\\\neq'),\n entry('approximately', '\\\\approx'),\n entry('pi', '\\\\pi'),\n entry('infinity', '\\\\infty')\n ];\n}\n\ninterface PanelState {\n /** The formula being changed; none when a new one is being written. */\n at: EditorPosition | null;\n latex: string;\n display: boolean;\n}\n\ninterface InlineState {\n at: EditorPosition;\n /** The formula's element in the text. */\n host: HTMLElement;\n /** The formula as it was when the box opened. */\n source: string;\n display: boolean;\n /** The piece of the source the box stands for. */\n start: number;\n end: number;\n input: HTMLInputElement;\n}\n\nconst SOURCE = 'data-vt-math-source';\n\nexport function createMathTools(options: MathToolsOptions): MathTools {\n let panel: PanelState | null = null;\n let anchorEl: HTMLElement | null = null;\n /** A piece of the source to select when the panel's box is first drawn. */\n let select: [number, number] | null = null;\n let inline: InlineState | null = null;\n let element: HTMLElement | null = null;\n\n const locale = () => options.locale?.() ?? en;\n const enabled = () => options.enabled?.() ?? true;\n const id = options.id ?? 'vt-math';\n const run = (name: string, ...args: unknown[]) => (options.editor.run as (n: string, ...a: unknown[]) => boolean)(name, ...args);\n\n // ---- where a formula is ------------------------------------------------------------------\n\n /** The formula's position from its element: the view reads a point inside one as just after it. */\n function positionOf(host: HTMLElement): EditorPosition | null {\n const after = options.view()?.posFromDOM(host, 0);\n return after && after.offset > 0 ? { path: after.path, offset: after.offset - 1 } : null;\n }\n\n function elementAt(at: EditorPosition): HTMLElement | null {\n const formulas = options.content()?.querySelectorAll<HTMLElement>('[data-math]') ?? [];\n for (const host of Array.from(formulas)) {\n const position = positionOf(host);\n if (position && position.offset === at.offset && position.path.join('.') === at.path.join('.')) return host;\n }\n return null;\n }\n\n // ---- the panel -----------------------------------------------------------------------------\n\n const overlay = createOverlay({\n anchor: () => anchorEl,\n render: () => (panel ? panelView(panel) : null),\n placement: 'bottom-start',\n target: () => options.overlayTarget,\n zIndex: options.zIndex,\n restoreFocus: false,\n onOpen: (drawn) => {\n const box = drawn.querySelector<HTMLInputElement>(`[${SOURCE}]`);\n if (!box) return;\n box.focus({ preventScroll: true });\n if (select) box.setSelectionRange(select[0], select[1]);\n else box.select();\n select = null;\n },\n onClose: (reason) => {\n panel = null;\n if (reason === 'escape') options.focus?.();\n }\n });\n\n /**\n * What the panel draws a formula with: the drawing, or the source while\n * there is nothing to draw with. The panel centres it, so where it would\n * hang from a baseline does not come into it.\n */\n const drawn = (tag: string, props: Props, latex: string, display: boolean): VElement => {\n const drawing = drawMath(latex, { display });\n return (drawing ? h(tag, mergeAttrs(props, { innerHTML: drawing.svg })) : h(tag, props, latex)) as VElement;\n };\n\n function panelView(state: PanelState): VElement {\n const words = locale().editor;\n const { part } = options;\n const button = (key: string, label: string, onClick: () => void, quiet = true) =>\n h('button', mergeAttrs({ key, type: 'button', class: quiet ? 'vt-button vt-button-text vt-button-secondary vt-button-sm' : 'vt-button vt-button-sm' }, { onClick }), label);\n const source = state.latex.trim();\n return h(\n 'div',\n mergeAttrs({ role: 'dialog', id }, part('panel'), part('mathPanel'), { 'aria-label': words.math }),\n source\n ? drawn('div', mergeAttrs({ key: 'preview' }, part('mathPreview')), source, state.display)\n : h('div', mergeAttrs({ key: 'empty' }, part('mathPreview', { empty: true })), words.mathEmpty),\n h(\n 'label',\n mergeAttrs({ key: 'source' }, part('field')),\n h('span', part('fieldLabel'), words.mathSource),\n h(\n 'span',\n { class: 'vt-field vt-field-sm vt-field-fluid' },\n h('input', {\n type: 'text',\n class: 'vt-field-input',\n spellcheck: 'false',\n autocomplete: 'off',\n autocapitalize: 'off',\n [SOURCE]: '',\n value: state.latex,\n onInput: (event: Event) => {\n if (!panel) return;\n panel = { ...panel, latex: (event.target as HTMLInputElement).value };\n overlay.update();\n },\n onKeydown: (event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n apply();\n }\n })\n )\n ),\n h(\n 'label',\n mergeAttrs({ key: 'display' }, part('check')),\n h('input', {\n type: 'checkbox',\n checked: state.display,\n onChange: (event: Event) => {\n if (!panel) return;\n panel = { ...panel, display: (event.target as HTMLInputElement).checked };\n overlay.update();\n }\n }),\n h('span', null, words.mathDisplay)\n ),\n templates().length\n ? h(\n 'div',\n mergeAttrs({ key: 'templates', role: 'group' }, part('mathTemplates'), { 'aria-label': words.mathTemplates }),\n templates().map((template) =>\n drawn(\n 'button',\n mergeAttrs({ key: template.id, type: 'button' }, part('mathTemplate'), { 'aria-label': template.label, title: template.label, onClick: () => write(template.latex) }),\n template.latex,\n false\n )\n )\n )\n : null,\n h(\n 'div',\n mergeAttrs({ key: 'actions' }, part('actions')),\n state.at ? button('remove', words.removeMath, remove) : null,\n button('cancel', locale().cancel, cancel),\n button('apply', state.at ? words.apply : words.insert, apply, false)\n )\n ) as VElement;\n }\n\n let offered: MathTemplate[] = [];\n const templates = () => offered;\n\n /** Writes a ready-made formula into the box, over what is selected there, and leaves the caret after it. */\n function write(latex: string) {\n if (!panel) return;\n const box = overlay.element()?.querySelector<HTMLInputElement>(`[${SOURCE}]`);\n const start = box?.selectionStart ?? panel.latex.length;\n const end = box?.selectionEnd ?? start;\n // A space keeps a command from running into the letters after it: `\\pi x`, not `\\pix`.\n const before = panel.latex.slice(0, start);\n const glue = /\\\\[a-zA-Z]+$/.test(before) && /^[a-zA-Z]/.test(latex) ? ' ' : '';\n const after = panel.latex.slice(end);\n const tail = /\\\\[a-zA-Z]+$/.test(latex) && /^[a-zA-Z]/.test(after) ? ' ' : '';\n panel = { ...panel, latex: before + glue + latex + tail + after };\n overlay.update();\n const caret = before.length + glue.length + latex.length + tail.length;\n box?.focus({ preventScroll: true });\n box?.setSelectionRange(caret, caret);\n }\n\n function apply() {\n if (!panel) return;\n const { at, display } = panel;\n const latex = panel.latex.trim();\n overlay.close();\n if (at) run('setMath', at, { latex, display });\n else if (latex) run('insertMath', { latex, display });\n options.focus?.();\n }\n\n function remove() {\n if (!panel?.at) return;\n const { at } = panel;\n overlay.close();\n run('setMath', at, { latex: '' });\n options.focus?.();\n }\n\n function cancel() {\n overlay.close();\n options.focus?.();\n }\n\n function openPanel(state: PanelState, anchor: HTMLElement | null | undefined, range?: [number, number]) {\n endInline(true);\n offered = options.templates();\n panel = state;\n select = range ?? null;\n anchorEl = anchor ?? (state.at ? elementAt(state.at) : null);\n if (!anchorEl) {\n options.place?.();\n anchorEl = options.anchor();\n }\n if (overlay.isOpen) overlay.close();\n overlay.open();\n overlay.update();\n // Nothing to draw with yet, in a document that had no formula in it: the panel draws again when there is.\n if (!isMathLoaded()) loadMath().then(() => overlay.update());\n }\n\n function open(anchor?: HTMLElement | null) {\n if (!enabled()) return;\n const on = editorMathAt(options.editor.state);\n openPanel(on ? { at: { path: on.path, offset: on.offset }, latex: on.latex, display: on.display } : { at: null, latex: '', display: false }, anchor);\n }\n\n // ---- a value, edited where it stands ---------------------------------------------------------\n\n /** The box is put over the piece it stands for, and is at least wide enough for what is in it. */\n function placeInline() {\n if (!inline) return;\n const { host, input, start } = inline;\n const end = start + input.value.length;\n const piece = host.querySelector(`[data-at=\"${start},${end}\"]`) ?? host;\n const rect = piece.getBoundingClientRect();\n const size = Number.parseFloat(getComputedStyle(host).fontSize) || 16;\n // Wide enough for what is typed in its own face, and never narrower than the piece it covers.\n const width = Math.max(rect.width + size * 0.35, (input.value.length + 0.8) * size * 0.62);\n const height = Math.max(rect.height, size * 1.3);\n input.style.fontSize = `${size}px`;\n input.style.width = `${width}px`;\n input.style.height = `${height}px`;\n input.style.left = `${rect.left + rect.width / 2 - width / 2}px`;\n input.style.top = `${rect.top + rect.height / 2 - height / 2}px`;\n }\n\n const inlineSource = (state: InlineState) => state.source.slice(0, state.start) + state.input.value + state.source.slice(state.end);\n\n function startInline(host: HTMLElement, at: EditorPosition, start: number, end: number) {\n endInline(true);\n if (overlay.isOpen) overlay.close();\n const source = host.getAttribute('data-math') ?? '';\n const input = document.createElement('input');\n input.type = 'text';\n input.value = source.slice(start, end);\n input.spellcheck = false;\n input.autocomplete = 'off';\n input.setAttribute('autocapitalize', 'off');\n input.setAttribute('aria-label', locale().editor.mathValue);\n for (const [key, value] of Object.entries(options.part('mathInput'))) if (typeof value === 'string') input.setAttribute(key, value);\n input.style.position = 'fixed';\n input.style.zIndex = String(options.zIndex ?? 1000);\n inline = { at, host, source, display: host.getAttribute('data-display') === 'true', start, end, input };\n input.addEventListener('input', onInlineInput);\n input.addEventListener('keydown', onInlineKeydown);\n input.addEventListener('blur', onInlineBlur);\n // Beside the other popups, so it wears the theme they wear.\n (overlayContainerOf(host) ?? host.ownerDocument.body).appendChild(input);\n host.setAttribute('data-editing', '');\n placeInline();\n input.focus({ preventScroll: true });\n input.select();\n window.addEventListener('scroll', onInlineScroll, true);\n window.addEventListener('resize', onInlineScroll);\n }\n\n /** The formula follows the typing: drawn again from what the source would be, before any of it is kept. */\n function onInlineInput() {\n if (!inline) return;\n paintMath(inline.host, inlineSource(inline), { display: inline.display, interactive: true });\n placeInline();\n }\n\n function onInlineKeydown(event: KeyboardEvent) {\n if (!inline) return;\n if (event.key === 'Enter') {\n event.preventDefault();\n endInline(true);\n options.focus?.();\n } else if (event.key === 'Escape') {\n event.preventDefault();\n event.stopPropagation();\n endInline(false);\n options.focus?.();\n } else if (event.key === 'Tab') {\n // On to the next value, or back to the one before; off the end, the keyboard goes back to the text.\n event.preventDefault();\n const { at, start } = inline;\n const length = inline.input.value.length;\n const forward = !event.shiftKey;\n endInline(true);\n const host = elementAt(at);\n const leaves = host ? Array.from(host.querySelectorAll<SVGElement>('[data-leaf]')).map((leaf) => leaf.getAttribute('data-at')!.split(',').map(Number) as [number, number]) : [];\n leaves.sort((a, b) => a[0] - b[0]);\n const next = forward ? leaves.find(([from]) => from >= start + length) : leaves.reverse().find(([, to]) => to <= start);\n if (host && next) startInline(host, at, next[0], next[1]);\n else options.focus?.();\n }\n }\n\n const onInlineBlur = () => endInline(true);\n // The box is placed by the page's coordinates, so it is placed again when the page moves under it.\n // (Not closed: a field scrolls its own text as it is typed into, and that is a scroll too.)\n const onInlineScroll = (event: Event) => {\n if (event.target !== inline?.input) placeInline();\n };\n\n /** Closes the box. `keep` writes what was typed into the document, as one change; otherwise the formula is drawn as it was. */\n function endInline(keep: boolean) {\n const state = inline;\n if (!state) return;\n inline = null;\n const { input, host, at } = state;\n input.removeEventListener('blur', onInlineBlur);\n input.removeEventListener('input', onInlineInput);\n input.removeEventListener('keydown', onInlineKeydown);\n window.removeEventListener('scroll', onInlineScroll, true);\n window.removeEventListener('resize', onInlineScroll);\n input.remove();\n host.removeAttribute('data-editing');\n const next = inlineSource(state);\n if (keep && next !== state.source) {\n // The element is put back as the document has it first, so that the change is the view's to draw.\n paintMath(host, state.source, { display: state.display, interactive: true });\n run('setMath', at, { latex: next });\n } else if (host.isConnected) paintMath(host, state.source, { display: state.display, interactive: true });\n }\n\n // ---- a press on a formula in the text --------------------------------------------------------\n\n function onClick(event: MouseEvent) {\n const target = event.target as Element | null;\n const host = target?.closest?.('[data-math]') as HTMLElement | null;\n if (!host || !element?.contains(host) || !enabled() || inline?.host === host) return;\n const at = positionOf(host);\n if (!at) return;\n event.preventDefault();\n const piece = target!.closest('[data-at]');\n const range = piece && host.contains(piece) ? (piece.getAttribute('data-at')!.split(',').map(Number) as [number, number]) : null;\n if (range && piece!.hasAttribute('data-leaf') && (options.inlineEdit?.() ?? true) && isMathLoaded()) {\n startInline(host, at, range[0], range[1]);\n return;\n }\n openPanel({ at, latex: host.getAttribute('data-math') ?? '', display: host.getAttribute('data-display') === 'true' }, host, range ?? undefined);\n }\n\n function listen() {\n const next = options.content();\n if (next === element) return;\n element?.removeEventListener('click', onClick);\n element = next;\n element?.addEventListener('click', onClick);\n }\n\n const stop = options.editor.subscribe(() => {\n listen();\n if (!enabled()) {\n endInline(false);\n if (overlay.isOpen) overlay.close();\n return;\n }\n // The document changed under an open box or panel (an undo, the application): what it was\n // editing may be gone. Looked at once the view has drawn the change, which it does after this.\n if (inline || panel?.at) queueMicrotask(settle);\n });\n\n function settle() {\n if (inline && !inline.host.isConnected) endInline(false);\n if (panel?.at && !elementAt(panel.at)) overlay.close();\n }\n listen();\n\n return {\n get isOpen() {\n return overlay.isOpen;\n },\n open,\n sync: listen,\n close() {\n endInline(true);\n if (overlay.isOpen) overlay.close();\n },\n destroy() {\n stop();\n endInline(false);\n element?.removeEventListener('click', onClick);\n element = null;\n overlay.destroy();\n }\n };\n}\n"],"mappings":";;;;;AA+DA,SAAgB,qBAAqB,QAAgC;CACjE,MAAM,QAAQ,OAAO,OAAO;CAC5B,MAAM,SAAS,IAAY,WAAiC;EAAE;EAAI,OAAO,MAAM,OAAO;EAAI;CAAM;CAChG,OAAO;EACH,MAAM,YAAY,cAAc;EAChC,MAAM,cAAc,WAAW;EAC/B,MAAM,QAAQ,cAAc;EAC5B,MAAM,SAAS,OAAO;EACtB,MAAM,aAAa,OAAO;EAC1B,MAAM,OAAO,mBAAmB;EAChC,MAAM,WAAW,oBAAoB;EACrC,MAAM,YAAY,wBAAwB;EAC1C,MAAM,SAAS,uBAAuB;EACtC,MAAM,eAAe,+BAA+B;EACpD,MAAM,UAAU,kDAAkD;EAClE,MAAM,SAAS,0DAA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A,UAAU;GAAE;GAAI,OAAO,KAAK,aAAa,WAAW,KAAK;GAAI,SAAS,KAAK,aAAa,cAAc,MAAM;EAAO,GAAG,MAAM,SAAS,KAAA,CAAS;CAClJ;CAEA,SAAS,SAAS;EACd,MAAM,OAAO,QAAQ,QAAQ;EAC7B,IAAI,SAAS,SAAS;EACtB,SAAS,oBAAoB,SAAS,OAAO;EAC7C,UAAU;EACV,SAAS,iBAAiB,SAAS,OAAO;CAC9C;CAEA,MAAM,OAAO,QAAQ,OAAO,gBAAgB;EACxC,OAAO;EACP,IAAI,CAAC,QAAQ,GAAG;GACZ,UAAU,KAAK;GACf,IAAI,QAAQ,QAAQ,QAAQ,MAAM;GAClC;EACJ;EAGA,IAAI,UAAU,OAAO,IAAI,eAAe,MAAM;CAClD,CAAC;CAED,SAAS,SAAS;EACd,IAAI,UAAU,CAAC,OAAO,KAAK,aAAa,UAAU,KAAK;EACvD,IAAI,OAAO,MAAM,CAAC,UAAU,MAAM,EAAE,GAAG,QAAQ,MAAM;CACzD;CACA,OAAO;CAEP,OAAO;EACH,IAAI,SAAS;GACT,OAAO,QAAQ;EACnB;EACA;EACA,MAAM;EACN,QAAQ;GACJ,UAAU,IAAI;GACd,IAAI,QAAQ,QAAQ,QAAQ,MAAM;EACtC;EACA,UAAU;GACN,KAAK;GACL,UAAU,KAAK;GACf,SAAS,oBAAoB,SAAS,OAAO;GAC7C,UAAU;GACV,QAAQ,QAAQ;EACpB;CACJ;AACJ"}
|
package/dist/render/toolbar.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface ToolbarActions {
|
|
|
36
36
|
openFind: () => void;
|
|
37
37
|
openImage: (event: MouseEvent) => void;
|
|
38
38
|
openTable: (event: MouseEvent) => void;
|
|
39
|
+
/** Opens the formula panel: on the formula the selection is on, or for a new one. */
|
|
40
|
+
openMath: (event: MouseEvent) => void;
|
|
39
41
|
openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;
|
|
40
42
|
blockSelect: (element: Element | null) => void;
|
|
41
43
|
}
|
package/dist/render/toolbar.js
CHANGED
|
@@ -14,6 +14,11 @@ var OPENERS = {
|
|
|
14
14
|
icon: "table",
|
|
15
15
|
label: (words) => words.table,
|
|
16
16
|
action: "openTable"
|
|
17
|
+
},
|
|
18
|
+
math: {
|
|
19
|
+
icon: "sigma",
|
|
20
|
+
label: (words) => words.math,
|
|
21
|
+
action: "openMath"
|
|
17
22
|
}
|
|
18
23
|
};
|
|
19
24
|
/** One command's button: a toggle where the command has a pressed state. */
|
|
@@ -47,22 +52,28 @@ function buttonView(context, item) {
|
|
|
47
52
|
onClick: (event) => isLink ? context.on.openLink(event) : context.on.command(command, args, event)
|
|
48
53
|
}), iconView(spec.icon.name, part("buttonIcon")));
|
|
49
54
|
}
|
|
50
|
-
/** A button that opens a panel: the image and table pickers. */
|
|
55
|
+
/** A button that opens a panel: the image and table pickers, the formula editor. */
|
|
51
56
|
function openerView(context, item) {
|
|
52
57
|
const spec = OPENERS[item];
|
|
53
58
|
const name = spec.label(context.locale.editor);
|
|
59
|
+
const pressed = item === "math" ? context.isActive("math") : void 0;
|
|
60
|
+
const disabled = !context.editable || item === "math" && context.isActive("codeBlock");
|
|
54
61
|
return h("button", mergeAttrs({
|
|
55
62
|
key: item,
|
|
56
63
|
type: "button"
|
|
57
|
-
}, context.part("button", {
|
|
64
|
+
}, context.part("button", {
|
|
65
|
+
active: pressed,
|
|
66
|
+
disabled
|
|
67
|
+
}), {
|
|
58
68
|
"aria-label": name,
|
|
59
69
|
"aria-haspopup": "dialog",
|
|
60
|
-
|
|
70
|
+
"aria-pressed": pressed === void 0 ? void 0 : pressed ? "true" : "false",
|
|
71
|
+
disabled,
|
|
61
72
|
ref: (element) => {
|
|
62
73
|
context.ref(item)(element);
|
|
63
74
|
context.on.tip(element, name);
|
|
64
75
|
},
|
|
65
|
-
onClick: (event) => spec.action === "openImage" ? context.on.openImage(event) : context.on.openTable(event)
|
|
76
|
+
onClick: (event) => spec.action === "openImage" ? context.on.openImage(event) : spec.action === "openMath" ? context.on.openMath(event) : context.on.openTable(event)
|
|
66
77
|
}), iconView(spec.icon, context.part("buttonIcon")));
|
|
67
78
|
}
|
|
68
79
|
/** The button that opens the find bar. */
|
|
@@ -115,11 +126,11 @@ function toolbarView(context, groups) {
|
|
|
115
126
|
}), groups.map((group, index) => h("div", mergeAttrs({
|
|
116
127
|
key: index,
|
|
117
128
|
role: "group"
|
|
118
|
-
}, part("toolbarGroup")), group.map((item) => item === "blockType" ? blockSelectView(context) : item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" ? openerView(context, item) : item === "find" ? findView(context) : buttonView(context, item)))));
|
|
129
|
+
}, part("toolbarGroup")), group.map((item) => item === "blockType" ? blockSelectView(context) : item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" || item === "math" ? openerView(context, item) : item === "find" ? findView(context) : buttonView(context, item)))));
|
|
119
130
|
}
|
|
120
131
|
/** The floating toolbar over a selection: the same buttons, in one group. */
|
|
121
132
|
function bubbleView(context, items) {
|
|
122
|
-
return h("div", mergeAttrs({ role: "toolbar" }, context.part("bubble"), { "aria-label": context.locale.editor.toolbar }), items.map((item) => item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" ? openerView(context, item) : buttonView(context, item)));
|
|
133
|
+
return h("div", mergeAttrs({ role: "toolbar" }, context.part("bubble"), { "aria-label": context.locale.editor.toolbar }), items.map((item) => item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" || item === "math" ? openerView(context, item) : buttonView(context, item)));
|
|
123
134
|
}
|
|
124
135
|
//#endregion
|
|
125
136
|
export { bubbleView, buttonView, iconView, toolbarView };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","names":[],"sources":["../../src/render/toolbar.ts"],"sourcesContent":["import { ariaEditorShortcut, formatEditorShortcut, type EditorColor, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { editorButtons, shortcutCommands } from '../buttons';\nimport type { EditorButtonCommand, EditorToolbarItem } from '../types';\n\n/**\n * The toolbar as plain objects: a group of buttons a command each, the block\n * type as a select, the two colour pickers, and the buttons that open a panel.\n * What is drawn is decided here; what happens when it is pressed is the\n * handle's.\n */\n\nexport interface ToolbarContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n editable: boolean;\n /** Whether a command applies right now. */\n can: (name: string, ...args: unknown[]) => boolean;\n isActive: (name: string, attrs?: Record<string, unknown>) => boolean;\n /** The shortcut for a command, as a label and as `aria-keyshortcuts`. */\n shortcut: (name: string, args?: readonly unknown[]) => { label: string; aria: string } | undefined;\n on: ToolbarActions;\n /** The element each opener is drawn into, so a panel can hang from it. */\n ref: (name: string) => (element: Element | null) => void;\n colors: { text?: EditorColor; highlight?: EditorColor };\n}\n\nexport interface ToolbarActions {\n /** Gives a button the tooltip that says what it is. */\n tip: (element: Element | null, text: string) => void;\n command: (name: string, args: readonly unknown[], event: MouseEvent) => void;\n openLink: (event: MouseEvent) => void;\n /** Opens or shuts the find bar. */\n openFind: () => void;\n openImage: (event: MouseEvent) => void;\n openTable: (event: MouseEvent) => void;\n openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;\n blockSelect: (element: Element | null) => void;\n}\n\nexport const iconView = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\n\nconst OPENERS: Partial<Record<EditorToolbarItem, { icon: string; label: (words: Locale['editor']) => string; action: keyof ToolbarActions }>> = {\n image: { icon: 'image', label: (words) => words.image, action: 'openImage' },\n table: { icon: 'table', label: (words) => words.table, action: 'openTable' }\n};\n\n/** One command's button: a toggle where the command has a pressed state. */\nexport function buttonView(context: ToolbarContext, item: EditorButtonCommand): Child {\n const { part, locale } = context;\n const spec = editorButtons[item];\n if (!spec) return null;\n const name = spec.label(locale.editor);\n const isLink = item === 'link';\n const pressed = spec.active ? context.isActive(spec.active[0], spec.active[1]) : undefined;\n const [command, ...args] = spec.command;\n const disabled = !context.editable || (isLink ? context.isActive('codeBlock') : !context.can(command, ...args));\n const [shortcutName, ...shortcutArgs] = shortcutCommands[item] ?? spec.command;\n const shortcut = context.shortcut(shortcutName, shortcutArgs);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, part('button', { active: pressed, disabled }), {\n 'aria-label': name,\n 'aria-pressed': isLink || pressed === undefined ? undefined : pressed ? 'true' : 'false',\n 'aria-haspopup': isLink ? 'dialog' : undefined,\n 'aria-keyshortcuts': shortcut?.aria,\n disabled,\n ref: (element: Element | null) => {\n if (isLink) context.ref('link')(element);\n context.on.tip(element, shortcut ? `${name} (${shortcut.label})` : name);\n },\n onClick: (event: MouseEvent) => (isLink ? context.on.openLink(event) : context.on.command(command, args, event))\n }),\n iconView(spec.icon.name, part('buttonIcon'))\n );\n}\n\n/** A button that opens a panel: the image and table pickers. */\nfunction openerView(context: ToolbarContext, item: 'image' | 'table'): Child {\n const spec = OPENERS[item]!;\n const name = spec.label(context.locale.editor);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, context.part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(item)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => (spec.action === 'openImage' ? context.on.openImage(event) : context.on.openTable(event))\n }),\n iconView(spec.icon, context.part('buttonIcon'))\n );\n}\n\n/** The button that opens the find bar. */\nfunction findView(context: ToolbarContext): Child {\n const name = context.locale.editor.find;\n return h(\n 'button',\n mergeAttrs({ key: 'find', type: 'button' }, context.part('button'), {\n 'aria-label': name,\n 'aria-keyshortcuts': ariaEditorShortcut('Mod-f'),\n ref: (element: Element | null) => context.on.tip(element, `${name} (${formatEditorShortcut('Mod-f')})`),\n onClick: () => context.on.openFind()\n }),\n iconView('search', context.part('buttonIcon'))\n );\n}\n\n/** The text and highlight pickers: a button showing the colour in hand. */\nfunction colorView(context: ToolbarContext, kind: 'color' | 'highlight'): Child {\n const { part, locale } = context;\n const name = kind === 'color' ? locale.editor.textColor : locale.editor.highlight;\n const chosen = context.colors[kind === 'color' ? 'text' : 'highlight'];\n return h(\n 'button',\n mergeAttrs({ key: kind, type: 'button' }, part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(kind)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => context.on.openColor(kind, event)\n }),\n iconView(kind === 'color' ? 'textColor' : 'highlighter', part('buttonIcon')),\n h('span', mergeAttrs({ key: 'bar', 'aria-hidden': 'true' }, part('colorBar'), { style: { background: chosen ? (kind === 'color' ? chosen.text : chosen.highlight) : 'transparent' } }))\n );\n}\n\n/** The block type, as the select the control kit draws; the handle mounts it. */\nfunction blockSelectView(context: ToolbarContext): Child {\n return h('span', mergeAttrs({ key: 'blockType' }, { ref: context.on.blockSelect }));\n}\n\nexport function toolbarView(context: ToolbarContext, groups: EditorToolbarItem[][]): Child {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ key: 'toolbar', role: 'toolbar' }, part('toolbar'), { 'aria-label': locale.editor.toolbar, 'aria-orientation': 'horizontal' }),\n groups.map((group, index) =>\n h(\n 'div',\n mergeAttrs({ key: index, role: 'group' }, part('toolbarGroup')),\n group.map((item) =>\n item === 'blockType'\n ? blockSelectView(context)\n : item === 'color' || item === 'highlight'\n ? colorView(context, item)\n : item === 'image' || item === 'table'\n ? openerView(context, item)\n : item === 'find'\n ? findView(context)\n : buttonView(context, item as EditorButtonCommand)\n )\n )\n )\n );\n}\n\n/** The floating toolbar over a selection: the same buttons, in one group. */\nexport function bubbleView(context: ToolbarContext, items: EditorToolbarItem[]): Child {\n return h(\n 'div',\n mergeAttrs({ role: 'toolbar' }, context.part('bubble'), { 'aria-label': context.locale.editor.toolbar }),\n items.map((item) =>\n item === 'color' || item === 'highlight' ? colorView(context, item) : item === 'image' || item === 'table' ? openerView(context, item) : buttonView(context, item as EditorButtonCommand)\n )\n );\n}\n\nexport const shortcutLabel = (binding: { key: string } | undefined): string | undefined => (binding ? formatEditorShortcut(binding.key) : undefined);\n"],"mappings":";;;;;AAyCA,IAAa,YAAY,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAE7F,IAAM,UAA0I;CAC5I,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;CAC3E,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;AAC/E;;AAGA,SAAgB,WAAW,SAAyB,MAAkC;CAClF,MAAM,EAAE,MAAM,WAAW;CACzB,MAAM,OAAO,cAAc;CAC3B,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,OAAO,KAAK,MAAM,OAAO,MAAM;CACrC,MAAM,SAAS,SAAS;CACxB,MAAM,UAAU,KAAK,SAAS,QAAQ,SAAS,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,KAAA;CACjF,MAAM,CAAC,SAAS,GAAG,QAAQ,KAAK;CAChC,MAAM,WAAW,CAAC,QAAQ,aAAa,SAAS,QAAQ,SAAS,WAAW,IAAI,CAAC,QAAQ,IAAI,SAAS,GAAG,IAAI;CAC7G,MAAM,CAAC,cAAc,GAAG,gBAAgB,iBAAiB,SAAS,KAAK;CACvE,MAAM,WAAW,QAAQ,SAAS,cAAc,YAAY;CAC5D,OAAO,EACH,UACA,WAAW;EAAE,KAAK;EAAM,MAAM;CAAS,GAAG,KAAK,UAAU;EAAE,QAAQ;EAAS;CAAS,CAAC,GAAG;EACrF,cAAc;EACd,gBAAgB,UAAU,YAAY,KAAA,IAAY,KAAA,IAAY,UAAU,SAAS;EACjF,iBAAiB,SAAS,WAAW,KAAA;EACrC,qBAAqB,UAAU;EAC/B;EACA,MAAM,YAA4B;GAC9B,IAAI,QAAQ,QAAQ,IAAI,MAAM,CAAC,CAAC,OAAO;GACvC,QAAQ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I,IACvB,SAAS,WAAW,SAAS,UAC3B,WAAW,SAAS,IAAI,IACxB,SAAS,SACP,SAAS,OAAO,IAChB,WAAW,SAAS,IAA2B,CAC/D,CACJ,CACJ,CACJ;AACJ;;AAGA,SAAgB,WAAW,SAAyB,OAAmC;CACnF,OAAO,EACH,OACA,WAAW,EAAE,MAAM,UAAU,GAAG,QAAQ,KAAK,QAAQ,GAAG,EAAE,cAAc,QAAQ,OAAO,OAAO,QAAQ,CAAC,GACvG,MAAM,KAAK,SACP,SAAS,WAAW,SAAS,cAAc,UAAU,SAAS,IAAI,IAAI,SAAS,WAAW,SAAS,UAAU,WAAW,SAAS,IAAI,IAAI,WAAW,SAAS,IAA2B,CAC5L,CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"toolbar.js","names":[],"sources":["../../src/render/toolbar.ts"],"sourcesContent":["import { ariaEditorShortcut, formatEditorShortcut, type EditorColor, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { editorButtons, shortcutCommands } from '../buttons';\nimport type { EditorButtonCommand, EditorToolbarItem } from '../types';\n\n/**\n * The toolbar as plain objects: a group of buttons a command each, the block\n * type as a select, the two colour pickers, and the buttons that open a panel.\n * What is drawn is decided here; what happens when it is pressed is the\n * handle's.\n */\n\nexport interface ToolbarContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n editable: boolean;\n /** Whether a command applies right now. */\n can: (name: string, ...args: unknown[]) => boolean;\n isActive: (name: string, attrs?: Record<string, unknown>) => boolean;\n /** The shortcut for a command, as a label and as `aria-keyshortcuts`. */\n shortcut: (name: string, args?: readonly unknown[]) => { label: string; aria: string } | undefined;\n on: ToolbarActions;\n /** The element each opener is drawn into, so a panel can hang from it. */\n ref: (name: string) => (element: Element | null) => void;\n colors: { text?: EditorColor; highlight?: EditorColor };\n}\n\nexport interface ToolbarActions {\n /** Gives a button the tooltip that says what it is. */\n tip: (element: Element | null, text: string) => void;\n command: (name: string, args: readonly unknown[], event: MouseEvent) => void;\n openLink: (event: MouseEvent) => void;\n /** Opens or shuts the find bar. */\n openFind: () => void;\n openImage: (event: MouseEvent) => void;\n openTable: (event: MouseEvent) => void;\n /** Opens the formula panel: on the formula the selection is on, or for a new one. */\n openMath: (event: MouseEvent) => void;\n openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;\n blockSelect: (element: Element | null) => void;\n}\n\nexport const iconView = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\n\nconst OPENERS: Partial<Record<EditorToolbarItem, { icon: string; label: (words: Locale['editor']) => string; action: keyof ToolbarActions }>> = {\n image: { icon: 'image', label: (words) => words.image, action: 'openImage' },\n table: { icon: 'table', label: (words) => words.table, action: 'openTable' },\n math: { icon: 'sigma', label: (words) => words.math, action: 'openMath' }\n};\n\n/** One command's button: a toggle where the command has a pressed state. */\nexport function buttonView(context: ToolbarContext, item: EditorButtonCommand): Child {\n const { part, locale } = context;\n const spec = editorButtons[item];\n if (!spec) return null;\n const name = spec.label(locale.editor);\n const isLink = item === 'link';\n const pressed = spec.active ? context.isActive(spec.active[0], spec.active[1]) : undefined;\n const [command, ...args] = spec.command;\n const disabled = !context.editable || (isLink ? context.isActive('codeBlock') : !context.can(command, ...args));\n const [shortcutName, ...shortcutArgs] = shortcutCommands[item] ?? spec.command;\n const shortcut = context.shortcut(shortcutName, shortcutArgs);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, part('button', { active: pressed, disabled }), {\n 'aria-label': name,\n 'aria-pressed': isLink || pressed === undefined ? undefined : pressed ? 'true' : 'false',\n 'aria-haspopup': isLink ? 'dialog' : undefined,\n 'aria-keyshortcuts': shortcut?.aria,\n disabled,\n ref: (element: Element | null) => {\n if (isLink) context.ref('link')(element);\n context.on.tip(element, shortcut ? `${name} (${shortcut.label})` : name);\n },\n onClick: (event: MouseEvent) => (isLink ? context.on.openLink(event) : context.on.command(command, args, event))\n }),\n iconView(spec.icon.name, part('buttonIcon'))\n );\n}\n\n/** A button that opens a panel: the image and table pickers, the formula editor. */\nfunction openerView(context: ToolbarContext, item: 'image' | 'table' | 'math'): Child {\n const spec = OPENERS[item]!;\n const name = spec.label(context.locale.editor);\n // The formula button is down while the selection is on a formula: pressed there, it changes that one.\n const pressed = item === 'math' ? context.isActive('math') : undefined;\n const disabled = !context.editable || (item === 'math' && context.isActive('codeBlock'));\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, context.part('button', { active: pressed, disabled }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n 'aria-pressed': pressed === undefined ? undefined : pressed ? 'true' : 'false',\n disabled,\n ref: (element: Element | null) => {\n context.ref(item)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => (spec.action === 'openImage' ? context.on.openImage(event) : spec.action === 'openMath' ? context.on.openMath(event) : context.on.openTable(event))\n }),\n iconView(spec.icon, context.part('buttonIcon'))\n );\n}\n\n/** The button that opens the find bar. */\nfunction findView(context: ToolbarContext): Child {\n const name = context.locale.editor.find;\n return h(\n 'button',\n mergeAttrs({ key: 'find', type: 'button' }, context.part('button'), {\n 'aria-label': name,\n 'aria-keyshortcuts': ariaEditorShortcut('Mod-f'),\n ref: (element: Element | null) => context.on.tip(element, `${name} (${formatEditorShortcut('Mod-f')})`),\n onClick: () => context.on.openFind()\n }),\n iconView('search', context.part('buttonIcon'))\n );\n}\n\n/** The text and highlight pickers: a button showing the colour in hand. */\nfunction colorView(context: ToolbarContext, kind: 'color' | 'highlight'): Child {\n const { part, locale } = context;\n const name = kind === 'color' ? locale.editor.textColor : locale.editor.highlight;\n const chosen = context.colors[kind === 'color' ? 'text' : 'highlight'];\n return h(\n 'button',\n mergeAttrs({ key: kind, type: 'button' }, part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(kind)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => context.on.openColor(kind, event)\n }),\n iconView(kind === 'color' ? 'textColor' : 'highlighter', part('buttonIcon')),\n h('span', mergeAttrs({ key: 'bar', 'aria-hidden': 'true' }, part('colorBar'), { style: { background: chosen ? (kind === 'color' ? chosen.text : chosen.highlight) : 'transparent' } }))\n );\n}\n\n/** The block type, as the select the control kit draws; the handle mounts it. */\nfunction blockSelectView(context: ToolbarContext): Child {\n return h('span', mergeAttrs({ key: 'blockType' }, { ref: context.on.blockSelect }));\n}\n\nexport function toolbarView(context: ToolbarContext, groups: EditorToolbarItem[][]): Child {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ key: 'toolbar', role: 'toolbar' }, part('toolbar'), { 'aria-label': locale.editor.toolbar, 'aria-orientation': 'horizontal' }),\n groups.map((group, index) =>\n h(\n 'div',\n mergeAttrs({ key: index, role: 'group' }, part('toolbarGroup')),\n group.map((item) =>\n item === 'blockType'\n ? blockSelectView(context)\n : item === 'color' || item === 'highlight'\n ? colorView(context, item)\n : item === 'image' || item === 'table' || item === 'math'\n ? openerView(context, item)\n : item === 'find'\n ? findView(context)\n : buttonView(context, item as EditorButtonCommand)\n )\n )\n )\n );\n}\n\n/** The floating toolbar over a selection: the same buttons, in one group. */\nexport function bubbleView(context: ToolbarContext, items: EditorToolbarItem[]): Child {\n return h(\n 'div',\n mergeAttrs({ role: 'toolbar' }, context.part('bubble'), { 'aria-label': context.locale.editor.toolbar }),\n items.map((item) =>\n item === 'color' || item === 'highlight' ? colorView(context, item) : item === 'image' || item === 'table' || item === 'math' ? openerView(context, item) : buttonView(context, item as EditorButtonCommand)\n )\n );\n}\n\nexport const shortcutLabel = (binding: { key: string } | undefined): string | undefined => (binding ? formatEditorShortcut(binding.key) : undefined);\n"],"mappings":";;;;;AA2CA,IAAa,YAAY,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAE7F,IAAM,UAA0I;CAC5I,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CA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