@formulaxjs/ckeditor5 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 +35 -0
- package/README.md +249 -0
- package/README.zh-CN.md +249 -0
- package/dist/KF_AMS_BB-5QF7FUSO.woff +0 -0
- package/dist/KF_AMS_CAL-NXRNLAZN.woff +0 -0
- package/dist/KF_AMS_FRAK-CO33WWN4.woff +0 -0
- package/dist/KF_AMS_MAIN-25QJVAWY.woff +0 -0
- package/dist/KF_AMS_ROMAN-243BR7HH.woff +0 -0
- package/dist/btn-5DANP6JY.png +0 -0
- package/dist/editor-JT5KLVXX.css +3 -0
- package/dist/index.cjs +434 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.global.js +62561 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +425 -0
- package/dist/index.js.map +1 -0
- package/dist/other-OMWJFGL5.png +0 -0
- package/package.json +54 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_FORMULA_ATTRIBUTE as DEFAULT_FORMULA_ATTRIBUTE2,
|
|
4
|
+
DEFAULT_FORMULA_CLASS as DEFAULT_FORMULA_CLASS2,
|
|
5
|
+
FORMULA_FLAG_ATTRIBUTE as FORMULA_FLAG_ATTRIBUTE2
|
|
6
|
+
} from "@formulaxjs/editor";
|
|
7
|
+
|
|
8
|
+
// src/plugin.ts
|
|
9
|
+
import {
|
|
10
|
+
ButtonView,
|
|
11
|
+
Command,
|
|
12
|
+
Plugin,
|
|
13
|
+
Widget,
|
|
14
|
+
toWidget,
|
|
15
|
+
viewToModelPositionOutsideModelElement
|
|
16
|
+
} from "ckeditor5";
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_FORMULA_ATTRIBUTE,
|
|
19
|
+
DEFAULT_FORMULA_CLASS,
|
|
20
|
+
FORMULA_FLAG_ATTRIBUTE,
|
|
21
|
+
createFormulaMarkup,
|
|
22
|
+
ensureFormulaXModalStyles as ensureFormulaXModalStyles2,
|
|
23
|
+
mountFormulaXKityEditor as mountFormulaXKityEditor2
|
|
24
|
+
} from "@formulaxjs/editor";
|
|
25
|
+
|
|
26
|
+
// src/modal.ts
|
|
27
|
+
import {
|
|
28
|
+
ensureFormulaXModalStyles,
|
|
29
|
+
escapeAttribute,
|
|
30
|
+
escapeHtml,
|
|
31
|
+
mountFormulaXKityEditor
|
|
32
|
+
} from "@formulaxjs/editor";
|
|
33
|
+
function openFormulaXModal(input) {
|
|
34
|
+
ensureFormulaXModalStyles(document);
|
|
35
|
+
const root = document.createElement("div");
|
|
36
|
+
root.className = "fx-formula-modal-root";
|
|
37
|
+
root.setAttribute("data-formulax-modal", "true");
|
|
38
|
+
const submitText = input.isUpdate ? input.options.modal.updateText : input.options.modal.insertText;
|
|
39
|
+
root.innerHTML = `
|
|
40
|
+
<div class="fx-formula-modal-backdrop" data-action="backdrop"></div>
|
|
41
|
+
<div class="fx-formula-modal" role="dialog" aria-modal="true" aria-label="${escapeAttribute(input.options.modal.title)}">
|
|
42
|
+
<header class="fx-formula-modal__header">
|
|
43
|
+
<h2 class="fx-formula-modal__title">${escapeHtml(input.options.modal.title)}</h2>
|
|
44
|
+
<button class="fx-formula-modal__close" type="button" data-action="close" aria-label="Close">\xD7</button>
|
|
45
|
+
</header>
|
|
46
|
+
<section class="fx-formula-modal__body">
|
|
47
|
+
<div class="fx-formula-editor-host"></div>
|
|
48
|
+
</section>
|
|
49
|
+
<footer class="fx-formula-modal__footer">
|
|
50
|
+
<button class="fx-formula-modal__button" type="button" data-action="cancel">${escapeHtml(input.options.modal.cancelText)}</button>
|
|
51
|
+
<button class="fx-formula-modal__button fx-formula-modal__button--primary" type="button" data-action="submit">${escapeHtml(submitText)}</button>
|
|
52
|
+
</footer>
|
|
53
|
+
</div>
|
|
54
|
+
`;
|
|
55
|
+
document.body.appendChild(root);
|
|
56
|
+
document.body.classList.add("fx-formula-modal-open");
|
|
57
|
+
const host = root.querySelector(".fx-formula-editor-host");
|
|
58
|
+
if (!host) {
|
|
59
|
+
root.remove();
|
|
60
|
+
return Promise.reject(new Error("[FormulaX] CKEditor 5 modal host not found."));
|
|
61
|
+
}
|
|
62
|
+
const mounted = mountFormulaXKityEditor(host, {
|
|
63
|
+
initialLatex: input.initialLatex,
|
|
64
|
+
height: input.options.editor.height,
|
|
65
|
+
autofocus: input.options.editor.autofocus,
|
|
66
|
+
assets: input.options.editor.assets,
|
|
67
|
+
render: {
|
|
68
|
+
fontsize: input.options.editor.render.fontsize
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
let closed = false;
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
const close = (payload) => {
|
|
74
|
+
if (closed) return;
|
|
75
|
+
closed = true;
|
|
76
|
+
mounted.destroy();
|
|
77
|
+
root.removeEventListener("click", onClick);
|
|
78
|
+
document.removeEventListener("keydown", onKeydown, true);
|
|
79
|
+
root.remove();
|
|
80
|
+
document.body.classList.remove("fx-formula-modal-open");
|
|
81
|
+
resolve(payload);
|
|
82
|
+
};
|
|
83
|
+
const submit = async () => {
|
|
84
|
+
try {
|
|
85
|
+
const latex = await mounted.getLatex();
|
|
86
|
+
close({ latex });
|
|
87
|
+
} catch (error) {
|
|
88
|
+
host.innerHTML = `
|
|
89
|
+
<div class="fx-formula-editor-error">
|
|
90
|
+
Failed to read FormulaX editor content.
|
|
91
|
+
<pre>${escapeHtml(error instanceof Error ? error.message : String(error))}</pre>
|
|
92
|
+
</div>
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function onClick(event) {
|
|
97
|
+
const action = event.target.closest("[data-action]")?.dataset.action;
|
|
98
|
+
if (!action) return;
|
|
99
|
+
if (action === "submit") {
|
|
100
|
+
void submit();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (action === "cancel" || action === "close") {
|
|
104
|
+
close(null);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (action === "backdrop" && input.options.modal.closeOnBackdrop) {
|
|
108
|
+
close(null);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function onKeydown(event) {
|
|
112
|
+
if (event.key === "Escape") {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
close(null);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
root.addEventListener("click", onClick);
|
|
118
|
+
document.addEventListener("keydown", onKeydown, true);
|
|
119
|
+
queueMicrotask(() => {
|
|
120
|
+
mounted.root.focus();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/plugin.ts
|
|
126
|
+
var DEFAULT_BUTTON_NAME = "formulaX";
|
|
127
|
+
function resolveOptions(options = {}) {
|
|
128
|
+
return {
|
|
129
|
+
buttonName: options.buttonName ?? DEFAULT_BUTTON_NAME,
|
|
130
|
+
toolbarText: options.toolbarText ?? "FormulaX",
|
|
131
|
+
tooltip: options.tooltip ?? "Insert or edit formula",
|
|
132
|
+
cursorStyle: options.cursorStyle ?? "pointer",
|
|
133
|
+
formulaClassName: options.formulaClassName ?? DEFAULT_FORMULA_CLASS,
|
|
134
|
+
formulaAttributeName: options.formulaAttributeName ?? DEFAULT_FORMULA_ATTRIBUTE,
|
|
135
|
+
modal: {
|
|
136
|
+
title: options.modal?.title ?? "FormulaX Editor",
|
|
137
|
+
insertText: options.modal?.insertText ?? "Insert",
|
|
138
|
+
updateText: options.modal?.updateText ?? "Update",
|
|
139
|
+
cancelText: options.modal?.cancelText ?? "Cancel",
|
|
140
|
+
closeOnBackdrop: options.modal?.closeOnBackdrop ?? true
|
|
141
|
+
},
|
|
142
|
+
editor: {
|
|
143
|
+
height: options.editor?.height ?? "100%",
|
|
144
|
+
autofocus: options.editor?.autofocus ?? true,
|
|
145
|
+
assets: options.editor?.assets ?? {},
|
|
146
|
+
render: {
|
|
147
|
+
fontsize: options.editor?.render?.fontsize ?? 40
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
var FormulaXCommand = class extends Command {
|
|
153
|
+
options;
|
|
154
|
+
constructor(editor, options) {
|
|
155
|
+
super(editor);
|
|
156
|
+
this.options = options;
|
|
157
|
+
}
|
|
158
|
+
refresh() {
|
|
159
|
+
this.isEnabled = true;
|
|
160
|
+
}
|
|
161
|
+
execute() {
|
|
162
|
+
const editor = this.editor;
|
|
163
|
+
const selectedFormula = getSelectedFormulaModelElement(editor);
|
|
164
|
+
const initialLatex = String(selectedFormula?.getAttribute("latex") ?? "");
|
|
165
|
+
void openFormulaXModal({
|
|
166
|
+
initialLatex,
|
|
167
|
+
isUpdate: Boolean(selectedFormula),
|
|
168
|
+
options: this.options
|
|
169
|
+
}).then((payload) => {
|
|
170
|
+
if (!payload) return;
|
|
171
|
+
applyFormulaPayload(editor, selectedFormula, payload);
|
|
172
|
+
editor.editing.view.focus();
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var FormulaX = class extends Plugin {
|
|
177
|
+
static get pluginName() {
|
|
178
|
+
return "FormulaX";
|
|
179
|
+
}
|
|
180
|
+
static get requires() {
|
|
181
|
+
return [Widget];
|
|
182
|
+
}
|
|
183
|
+
init() {
|
|
184
|
+
const editor = this.editor;
|
|
185
|
+
const options = resolveOptions(editor.config.get("formulaX"));
|
|
186
|
+
ensureFormulaXModalStyles2(document);
|
|
187
|
+
defineFormulaSchema(editor);
|
|
188
|
+
defineFormulaConverters(editor, options);
|
|
189
|
+
editor.editing.mapper.on(
|
|
190
|
+
"viewToModelPosition",
|
|
191
|
+
viewToModelPositionOutsideModelElement(editor.model, isFormulaWidgetView)
|
|
192
|
+
);
|
|
193
|
+
const command = new FormulaXCommand(editor, options);
|
|
194
|
+
editor.commands.add(options.buttonName, command);
|
|
195
|
+
editor.ui.componentFactory.add(options.buttonName, (locale) => {
|
|
196
|
+
const button = new ButtonView(locale);
|
|
197
|
+
button.set({
|
|
198
|
+
label: options.toolbarText,
|
|
199
|
+
tooltip: options.tooltip,
|
|
200
|
+
withText: true
|
|
201
|
+
});
|
|
202
|
+
button.bind("isEnabled").to(command, "isEnabled");
|
|
203
|
+
this.listenTo(button, "execute", () => editor.execute(options.buttonName));
|
|
204
|
+
return button;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function applyFormulaPayload(editor, selectedFormula, payload) {
|
|
209
|
+
editor.model.change((writer) => {
|
|
210
|
+
if (selectedFormula) {
|
|
211
|
+
if (!payload.latex.trim()) {
|
|
212
|
+
writer.remove(selectedFormula);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
writer.setAttribute("latex", payload.latex, selectedFormula);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!payload.latex.trim()) return;
|
|
219
|
+
const formula = writer.createElement("formulaX", {
|
|
220
|
+
latex: payload.latex
|
|
221
|
+
});
|
|
222
|
+
editor.model.insertObject(formula, null, null, { setSelection: "after" });
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function defineFormulaSchema(editor) {
|
|
226
|
+
editor.model.schema.register("formulaX", {
|
|
227
|
+
allowWhere: "$text",
|
|
228
|
+
isInline: true,
|
|
229
|
+
isObject: true,
|
|
230
|
+
allowAttributes: ["latex"]
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function defineFormulaConverters(editor, options) {
|
|
234
|
+
editor.conversion.for("upcast").elementToElement({
|
|
235
|
+
view: {
|
|
236
|
+
name: "span",
|
|
237
|
+
attributes: {
|
|
238
|
+
[FORMULA_FLAG_ATTRIBUTE]: true
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
model: (viewElement, { writer }) => writer.createElement("formulaX", {
|
|
242
|
+
latex: readFormulaLatexFromView(viewElement, options)
|
|
243
|
+
})
|
|
244
|
+
});
|
|
245
|
+
editor.conversion.for("dataDowncast").elementToElement({
|
|
246
|
+
model: createFormulaConverterModelDefinition(),
|
|
247
|
+
view: (modelElement, { writer }) => createFormulaRawElement(writer, modelElement, options)
|
|
248
|
+
});
|
|
249
|
+
editor.conversion.for("editingDowncast").elementToElement({
|
|
250
|
+
model: createFormulaConverterModelDefinition(),
|
|
251
|
+
view: (modelElement, { writer }) => {
|
|
252
|
+
const widgetElement = createFormulaWidgetElement(writer, modelElement, options, editor);
|
|
253
|
+
return toWidget(widgetElement, writer, { label: "FormulaX formula" });
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function createFormulaConverterModelDefinition() {
|
|
258
|
+
return {
|
|
259
|
+
name: "formulaX",
|
|
260
|
+
attributes: ["latex"]
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function createFormulaRawElement(writer, modelElement, options) {
|
|
264
|
+
const latex = String(modelElement.getAttribute("latex") ?? "");
|
|
265
|
+
const element = writer.createContainerElement(
|
|
266
|
+
"span",
|
|
267
|
+
createFormulaViewAttributes(latex, options)
|
|
268
|
+
);
|
|
269
|
+
writer.insert(
|
|
270
|
+
writer.createPositionAt(element, 0),
|
|
271
|
+
writer.createText(latex || "\\square")
|
|
272
|
+
);
|
|
273
|
+
return element;
|
|
274
|
+
}
|
|
275
|
+
function createFormulaWidgetElement(writer, modelElement, options, editor) {
|
|
276
|
+
const latex = String(modelElement.getAttribute("latex") ?? "");
|
|
277
|
+
const widgetElement = writer.createContainerElement(
|
|
278
|
+
"span",
|
|
279
|
+
createFormulaViewAttributes(latex, options)
|
|
280
|
+
);
|
|
281
|
+
const contentElement = writer.createRawElement(
|
|
282
|
+
"span",
|
|
283
|
+
{
|
|
284
|
+
class: `${options.formulaClassName}__content`,
|
|
285
|
+
"aria-hidden": "true"
|
|
286
|
+
},
|
|
287
|
+
(domElement) => {
|
|
288
|
+
domElement.innerHTML = createFormulaFallbackMarkup(latex, options);
|
|
289
|
+
void renderFormulaIntoElement(domElement, latex, options);
|
|
290
|
+
bindFormulaWidgetDomEvents(domElement, editor, modelElement, options.buttonName);
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
writer.insert(writer.createPositionAt(widgetElement, 0), contentElement);
|
|
294
|
+
return widgetElement;
|
|
295
|
+
}
|
|
296
|
+
function createFormulaViewAttributes(latex, options) {
|
|
297
|
+
return {
|
|
298
|
+
class: options.formulaClassName,
|
|
299
|
+
[FORMULA_FLAG_ATTRIBUTE]: "true",
|
|
300
|
+
[options.formulaAttributeName]: latex,
|
|
301
|
+
"data-latex": latex,
|
|
302
|
+
contenteditable: "false",
|
|
303
|
+
role: "button",
|
|
304
|
+
style: `cursor: ${options.cursorStyle}`,
|
|
305
|
+
tabindex: "0"
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function bindFormulaWidgetDomEvents(domElement, editor, modelElement, commandName) {
|
|
309
|
+
domElement.onclick = (event) => {
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
selectFormulaModelElement(editor, modelElement);
|
|
312
|
+
};
|
|
313
|
+
domElement.ondblclick = (event) => {
|
|
314
|
+
event.preventDefault();
|
|
315
|
+
event.stopPropagation();
|
|
316
|
+
selectFormulaModelElement(editor, modelElement);
|
|
317
|
+
editor.execute(commandName);
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function selectFormulaModelElement(editor, modelElement) {
|
|
321
|
+
if (!modelElement?.is?.("element", "formulaX")) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
editor.editing.view.focus();
|
|
325
|
+
editor.model.change((writer) => {
|
|
326
|
+
writer.setSelection(modelElement, "on");
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function createFormulaFallbackMarkup(latex, options) {
|
|
330
|
+
const markup = createFormulaMarkup(latex, {
|
|
331
|
+
attributeName: options.formulaAttributeName,
|
|
332
|
+
className: options.formulaClassName
|
|
333
|
+
});
|
|
334
|
+
return extractInnerHtml(markup);
|
|
335
|
+
}
|
|
336
|
+
function extractInnerHtml(markup) {
|
|
337
|
+
const wrapper = document.createElement("span");
|
|
338
|
+
wrapper.innerHTML = markup;
|
|
339
|
+
return wrapper.firstElementChild?.innerHTML ?? "";
|
|
340
|
+
}
|
|
341
|
+
function getSelectedFormulaModelElement(editor) {
|
|
342
|
+
const selectedElement = editor.model.document.selection.getSelectedElement();
|
|
343
|
+
return selectedElement?.is?.("element", "formulaX") ? selectedElement : null;
|
|
344
|
+
}
|
|
345
|
+
function isFormulaWidgetView(node) {
|
|
346
|
+
return Boolean(node?.is?.("element") && node.hasAttribute?.(FORMULA_FLAG_ATTRIBUTE));
|
|
347
|
+
}
|
|
348
|
+
function readFormulaLatexFromView(viewElement, options) {
|
|
349
|
+
return String(
|
|
350
|
+
viewElement.getAttribute(options.formulaAttributeName) ?? viewElement.getAttribute("data-latex") ?? ""
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
var formulaRenderCache = /* @__PURE__ */ new Map();
|
|
354
|
+
async function renderFormulaIntoElement(domElement, latex, options) {
|
|
355
|
+
const trimmedLatex = latex.trim();
|
|
356
|
+
const renderToken = `${trimmedLatex}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;
|
|
357
|
+
domElement.dataset.renderToken = renderToken;
|
|
358
|
+
if (!trimmedLatex) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
const markup = await renderFormulaSvgMarkup(trimmedLatex, options);
|
|
363
|
+
if (domElement.dataset.renderToken !== renderToken) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
domElement.innerHTML = markup;
|
|
367
|
+
} catch (error) {
|
|
368
|
+
if (domElement.dataset.renderToken !== renderToken) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
console.error("[FormulaX] Failed to render CKEditor5 formula widget:", error);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function renderFormulaSvgMarkup(latex, options) {
|
|
375
|
+
const cached = formulaRenderCache.get(latex);
|
|
376
|
+
if (cached) {
|
|
377
|
+
return cached;
|
|
378
|
+
}
|
|
379
|
+
const pending = (async () => {
|
|
380
|
+
const host = document.createElement("div");
|
|
381
|
+
host.style.position = "fixed";
|
|
382
|
+
host.style.left = "-100000px";
|
|
383
|
+
host.style.top = "0";
|
|
384
|
+
host.style.width = "1px";
|
|
385
|
+
host.style.height = "1px";
|
|
386
|
+
host.style.opacity = "0";
|
|
387
|
+
host.style.pointerEvents = "none";
|
|
388
|
+
host.setAttribute("aria-hidden", "true");
|
|
389
|
+
document.body.appendChild(host);
|
|
390
|
+
const mounted = mountFormulaXKityEditor2(host, {
|
|
391
|
+
initialLatex: latex,
|
|
392
|
+
height: options.editor.height,
|
|
393
|
+
autofocus: false,
|
|
394
|
+
assets: options.editor.assets,
|
|
395
|
+
render: {
|
|
396
|
+
fontsize: options.editor.render.fontsize
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
try {
|
|
400
|
+
return await mounted.getRenderHtml();
|
|
401
|
+
} finally {
|
|
402
|
+
mounted.destroy();
|
|
403
|
+
host.remove();
|
|
404
|
+
}
|
|
405
|
+
})();
|
|
406
|
+
formulaRenderCache.set(latex, pending);
|
|
407
|
+
pending.catch(() => {
|
|
408
|
+
if (formulaRenderCache.get(latex) === pending) {
|
|
409
|
+
formulaRenderCache.delete(latex);
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
return pending;
|
|
413
|
+
}
|
|
414
|
+
export {
|
|
415
|
+
DEFAULT_BUTTON_NAME,
|
|
416
|
+
DEFAULT_FORMULA_ATTRIBUTE2 as DEFAULT_FORMULA_ATTRIBUTE,
|
|
417
|
+
DEFAULT_FORMULA_CLASS2 as DEFAULT_FORMULA_CLASS,
|
|
418
|
+
FORMULA_FLAG_ATTRIBUTE2 as FORMULA_FLAG_ATTRIBUTE,
|
|
419
|
+
FormulaX,
|
|
420
|
+
FormulaXCommand,
|
|
421
|
+
FormulaX as default,
|
|
422
|
+
openFormulaXModal,
|
|
423
|
+
resolveOptions
|
|
424
|
+
};
|
|
425
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/plugin.ts","../src/modal.ts"],"sourcesContent":["export {\n DEFAULT_FORMULA_ATTRIBUTE,\n DEFAULT_FORMULA_CLASS,\n FORMULA_FLAG_ATTRIBUTE,\n} from '@formulaxjs/editor';\n\nexport {\n DEFAULT_BUTTON_NAME,\n FormulaX,\n FormulaXCommand,\n resolveOptions,\n} from './plugin';\n\nexport type {\n FormulaXCKEditor5Options,\n FormulaXPayload,\n RequiredFormulaXCKEditor5Options,\n} from './types';\n\nexport { openFormulaXModal } from './modal';\n\nexport { FormulaX as default } from './plugin';\n","import {\n ButtonView,\n Command,\n Plugin,\n Widget,\n toWidget,\n viewToModelPositionOutsideModelElement,\n} from 'ckeditor5';\nimport {\n DEFAULT_FORMULA_ATTRIBUTE,\n DEFAULT_FORMULA_CLASS,\n FORMULA_FLAG_ATTRIBUTE,\n createFormulaMarkup,\n ensureFormulaXModalStyles,\n mountFormulaXKityEditor,\n} from '@formulaxjs/editor';\nimport { openFormulaXModal } from './modal';\nimport type {\n FormulaXCKEditor5Options,\n FormulaXPayload,\n RequiredFormulaXCKEditor5Options,\n} from './types';\n\nconst DEFAULT_BUTTON_NAME = 'formulaX';\n\nexport { DEFAULT_BUTTON_NAME };\n\nexport function resolveOptions(options: FormulaXCKEditor5Options = {}): RequiredFormulaXCKEditor5Options {\n return {\n buttonName: options.buttonName ?? DEFAULT_BUTTON_NAME,\n toolbarText: options.toolbarText ?? 'FormulaX',\n tooltip: options.tooltip ?? 'Insert or edit formula',\n cursorStyle: options.cursorStyle ?? 'pointer',\n formulaClassName: options.formulaClassName ?? DEFAULT_FORMULA_CLASS,\n formulaAttributeName: options.formulaAttributeName ?? DEFAULT_FORMULA_ATTRIBUTE,\n modal: {\n title: options.modal?.title ?? 'FormulaX Editor',\n insertText: options.modal?.insertText ?? 'Insert',\n updateText: options.modal?.updateText ?? 'Update',\n cancelText: options.modal?.cancelText ?? 'Cancel',\n closeOnBackdrop: options.modal?.closeOnBackdrop ?? true,\n },\n editor: {\n height: options.editor?.height ?? '100%',\n autofocus: options.editor?.autofocus ?? true,\n assets: options.editor?.assets ?? {},\n render: {\n fontsize: options.editor?.render?.fontsize ?? 40,\n },\n },\n };\n}\n\nexport class FormulaXCommand extends Command {\n private readonly options: RequiredFormulaXCKEditor5Options;\n\n constructor(editor: unknown, options: RequiredFormulaXCKEditor5Options) {\n super(editor as any);\n this.options = options;\n }\n\n override refresh(): void {\n this.isEnabled = true;\n }\n\n override execute(): void {\n const editor = this.editor as any;\n const selectedFormula = getSelectedFormulaModelElement(editor);\n const initialLatex = String(selectedFormula?.getAttribute('latex') ?? '');\n\n void openFormulaXModal({\n initialLatex,\n isUpdate: Boolean(selectedFormula),\n options: this.options,\n }).then((payload) => {\n if (!payload) return;\n applyFormulaPayload(editor, selectedFormula, payload);\n editor.editing.view.focus();\n });\n }\n}\n\nexport class FormulaX extends Plugin {\n static get pluginName(): string {\n return 'FormulaX';\n }\n\n static get requires(): readonly [typeof Widget] {\n return [Widget];\n }\n\n init(): void {\n const editor = this.editor as any;\n const options = resolveOptions(editor.config.get('formulaX') as FormulaXCKEditor5Options | undefined);\n\n ensureFormulaXModalStyles(document);\n defineFormulaSchema(editor);\n defineFormulaConverters(editor, options);\n editor.editing.mapper.on(\n 'viewToModelPosition',\n viewToModelPositionOutsideModelElement(editor.model, isFormulaWidgetView),\n );\n\n const command = new FormulaXCommand(editor, options);\n editor.commands.add(options.buttonName, command);\n\n editor.ui.componentFactory.add(options.buttonName, (locale: unknown) => {\n const button = new ButtonView(locale as any);\n\n button.set({\n label: options.toolbarText,\n tooltip: options.tooltip,\n withText: true,\n });\n\n button.bind('isEnabled').to(command, 'isEnabled');\n this.listenTo(button, 'execute', () => editor.execute(options.buttonName));\n\n return button;\n });\n }\n}\n\nexport default FormulaX;\n\nfunction applyFormulaPayload(editor: any, selectedFormula: any, payload: FormulaXPayload): void {\n editor.model.change((writer: any) => {\n if (selectedFormula) {\n if (!payload.latex.trim()) {\n writer.remove(selectedFormula);\n return;\n }\n\n writer.setAttribute('latex', payload.latex, selectedFormula);\n return;\n }\n\n if (!payload.latex.trim()) return;\n\n const formula = writer.createElement('formulaX', {\n latex: payload.latex,\n });\n\n editor.model.insertObject(formula, null, null, { setSelection: 'after' });\n });\n}\n\nfunction defineFormulaSchema(editor: any): void {\n editor.model.schema.register('formulaX', {\n allowWhere: '$text',\n isInline: true,\n isObject: true,\n allowAttributes: ['latex'],\n });\n}\n\nfunction defineFormulaConverters(editor: any, options: RequiredFormulaXCKEditor5Options): void {\n editor.conversion.for('upcast').elementToElement({\n view: {\n name: 'span',\n attributes: {\n [FORMULA_FLAG_ATTRIBUTE]: true,\n },\n },\n model: (viewElement: any, { writer }: any) => writer.createElement('formulaX', {\n latex: readFormulaLatexFromView(viewElement, options),\n }),\n });\n\n editor.conversion.for('dataDowncast').elementToElement({\n model: createFormulaConverterModelDefinition(),\n view: (modelElement: any, { writer }: any) => createFormulaRawElement(writer, modelElement, options),\n });\n\n editor.conversion.for('editingDowncast').elementToElement({\n model: createFormulaConverterModelDefinition(),\n view: (modelElement: any, { writer }: any) => {\n const widgetElement = createFormulaWidgetElement(writer, modelElement, options, editor);\n return toWidget(widgetElement, writer, { label: 'FormulaX formula' });\n },\n });\n}\n\nfunction createFormulaConverterModelDefinition(): {\n name: string;\n attributes: string[];\n} {\n return {\n name: 'formulaX',\n attributes: ['latex'],\n };\n}\n\nfunction createFormulaRawElement(\n writer: any,\n modelElement: any,\n options: RequiredFormulaXCKEditor5Options,\n): any {\n const latex = String(modelElement.getAttribute('latex') ?? '');\n\n const element = writer.createContainerElement(\n 'span',\n createFormulaViewAttributes(latex, options),\n );\n\n writer.insert(\n writer.createPositionAt(element, 0),\n writer.createText(latex || '\\\\square'),\n );\n\n return element;\n}\n\nfunction createFormulaWidgetElement(\n writer: any,\n modelElement: any,\n options: RequiredFormulaXCKEditor5Options,\n editor: any,\n): any {\n const latex = String(modelElement.getAttribute('latex') ?? '');\n const widgetElement = writer.createContainerElement(\n 'span',\n createFormulaViewAttributes(latex, options),\n );\n const contentElement = writer.createRawElement(\n 'span',\n {\n class: `${options.formulaClassName}__content`,\n 'aria-hidden': 'true',\n },\n (domElement: HTMLElement) => {\n domElement.innerHTML = createFormulaFallbackMarkup(latex, options);\n void renderFormulaIntoElement(domElement, latex, options);\n bindFormulaWidgetDomEvents(domElement, editor, modelElement, options.buttonName);\n },\n );\n\n writer.insert(writer.createPositionAt(widgetElement, 0), contentElement);\n\n return widgetElement;\n}\n\nfunction createFormulaViewAttributes(\n latex: string,\n options: RequiredFormulaXCKEditor5Options,\n): Record<string, string> {\n return {\n class: options.formulaClassName,\n [FORMULA_FLAG_ATTRIBUTE]: 'true',\n [options.formulaAttributeName]: latex,\n 'data-latex': latex,\n contenteditable: 'false',\n role: 'button',\n style: `cursor: ${options.cursorStyle}`,\n tabindex: '0',\n };\n}\n\nfunction bindFormulaWidgetDomEvents(\n domElement: HTMLElement,\n editor: any,\n modelElement: any,\n commandName: string,\n): void {\n domElement.onclick = (event) => {\n event.preventDefault();\n selectFormulaModelElement(editor, modelElement);\n };\n\n domElement.ondblclick = (event) => {\n event.preventDefault();\n event.stopPropagation();\n selectFormulaModelElement(editor, modelElement);\n editor.execute(commandName);\n };\n}\n\nfunction selectFormulaModelElement(editor: any, modelElement: any): void {\n if (!modelElement?.is?.('element', 'formulaX')) {\n return;\n }\n\n editor.editing.view.focus();\n editor.model.change((writer: any) => {\n writer.setSelection(modelElement, 'on');\n });\n}\n\nfunction createFormulaFallbackMarkup(\n latex: string,\n options: RequiredFormulaXCKEditor5Options,\n): string {\n const markup = createFormulaMarkup(latex, {\n attributeName: options.formulaAttributeName,\n className: options.formulaClassName,\n });\n return extractInnerHtml(markup);\n}\n\nfunction extractInnerHtml(markup: string): string {\n const wrapper = document.createElement('span');\n wrapper.innerHTML = markup;\n return wrapper.firstElementChild?.innerHTML ?? '';\n}\n\nfunction getSelectedFormulaModelElement(editor: any): any | null {\n const selectedElement = editor.model.document.selection.getSelectedElement();\n return selectedElement?.is?.('element', 'formulaX') ? selectedElement : null;\n}\n\nfunction isFormulaWidgetView(node: any): boolean {\n return Boolean(node?.is?.('element') && node.hasAttribute?.(FORMULA_FLAG_ATTRIBUTE));\n}\n\nfunction readFormulaLatexFromView(viewElement: any, options: RequiredFormulaXCKEditor5Options): string {\n return String(\n viewElement.getAttribute(options.formulaAttributeName)\n ?? viewElement.getAttribute('data-latex')\n ?? '',\n );\n}\n\nconst formulaRenderCache = new Map<string, Promise<string>>();\n\nasync function renderFormulaIntoElement(\n domElement: HTMLElement,\n latex: string,\n options: RequiredFormulaXCKEditor5Options,\n): Promise<void> {\n const trimmedLatex = latex.trim();\n const renderToken = `${trimmedLatex}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;\n domElement.dataset.renderToken = renderToken;\n\n if (!trimmedLatex) {\n return;\n }\n\n try {\n const markup = await renderFormulaSvgMarkup(trimmedLatex, options);\n if (domElement.dataset.renderToken !== renderToken) {\n return;\n }\n\n domElement.innerHTML = markup;\n } catch (error) {\n if (domElement.dataset.renderToken !== renderToken) {\n return;\n }\n\n console.error('[FormulaX] Failed to render CKEditor5 formula widget:', error);\n }\n}\n\nfunction renderFormulaSvgMarkup(\n latex: string,\n options: RequiredFormulaXCKEditor5Options,\n): Promise<string> {\n const cached = formulaRenderCache.get(latex);\n if (cached) {\n return cached;\n }\n\n const pending = (async () => {\n const host = document.createElement('div');\n host.style.position = 'fixed';\n host.style.left = '-100000px';\n host.style.top = '0';\n host.style.width = '1px';\n host.style.height = '1px';\n host.style.opacity = '0';\n host.style.pointerEvents = 'none';\n host.setAttribute('aria-hidden', 'true');\n document.body.appendChild(host);\n\n const mounted = mountFormulaXKityEditor(host, {\n initialLatex: latex,\n height: options.editor.height,\n autofocus: false,\n assets: options.editor.assets,\n render: {\n fontsize: options.editor.render.fontsize,\n },\n });\n\n try {\n return await mounted.getRenderHtml();\n } finally {\n mounted.destroy();\n host.remove();\n }\n })();\n\n formulaRenderCache.set(latex, pending);\n pending.catch(() => {\n if (formulaRenderCache.get(latex) === pending) {\n formulaRenderCache.delete(latex);\n }\n });\n return pending;\n}\n","import {\n ensureFormulaXModalStyles,\n escapeAttribute,\n escapeHtml,\n mountFormulaXKityEditor,\n} from '@formulaxjs/editor';\nimport type { FormulaXPayload, RequiredFormulaXCKEditor5Options } from './types';\n\nexport interface OpenFormulaXModalInput {\n initialLatex: string;\n isUpdate: boolean;\n options: RequiredFormulaXCKEditor5Options;\n}\n\nexport function openFormulaXModal(input: OpenFormulaXModalInput): Promise<FormulaXPayload | null> {\n ensureFormulaXModalStyles(document);\n\n const root = document.createElement('div');\n root.className = 'fx-formula-modal-root';\n root.setAttribute('data-formulax-modal', 'true');\n\n const submitText = input.isUpdate ? input.options.modal.updateText : input.options.modal.insertText;\n\n root.innerHTML = `\n <div class=\"fx-formula-modal-backdrop\" data-action=\"backdrop\"></div>\n <div class=\"fx-formula-modal\" role=\"dialog\" aria-modal=\"true\" aria-label=\"${escapeAttribute(input.options.modal.title)}\">\n <header class=\"fx-formula-modal__header\">\n <h2 class=\"fx-formula-modal__title\">${escapeHtml(input.options.modal.title)}</h2>\n <button class=\"fx-formula-modal__close\" type=\"button\" data-action=\"close\" aria-label=\"Close\">×</button>\n </header>\n <section class=\"fx-formula-modal__body\">\n <div class=\"fx-formula-editor-host\"></div>\n </section>\n <footer class=\"fx-formula-modal__footer\">\n <button class=\"fx-formula-modal__button\" type=\"button\" data-action=\"cancel\">${escapeHtml(input.options.modal.cancelText)}</button>\n <button class=\"fx-formula-modal__button fx-formula-modal__button--primary\" type=\"button\" data-action=\"submit\">${escapeHtml(submitText)}</button>\n </footer>\n </div>\n `;\n\n document.body.appendChild(root);\n document.body.classList.add('fx-formula-modal-open');\n\n const host = root.querySelector<HTMLElement>('.fx-formula-editor-host');\n if (!host) {\n root.remove();\n return Promise.reject(new Error('[FormulaX] CKEditor 5 modal host not found.'));\n }\n\n const mounted = mountFormulaXKityEditor(host, {\n initialLatex: input.initialLatex,\n height: input.options.editor.height,\n autofocus: input.options.editor.autofocus,\n assets: input.options.editor.assets,\n render: {\n fontsize: input.options.editor.render.fontsize,\n },\n });\n let closed = false;\n\n return new Promise((resolve) => {\n const close = (payload: FormulaXPayload | null): void => {\n if (closed) return;\n closed = true;\n\n mounted.destroy();\n root.removeEventListener('click', onClick);\n document.removeEventListener('keydown', onKeydown, true);\n root.remove();\n document.body.classList.remove('fx-formula-modal-open');\n resolve(payload);\n };\n\n const submit = async (): Promise<void> => {\n try {\n const latex = await mounted.getLatex();\n close({ latex });\n } catch (error) {\n host.innerHTML = `\n <div class=\"fx-formula-editor-error\">\n Failed to read FormulaX editor content.\n <pre>${escapeHtml(error instanceof Error ? error.message : String(error))}</pre>\n </div>\n `;\n }\n };\n\n function onClick(event: MouseEvent): void {\n const action = (event.target as HTMLElement).closest<HTMLElement>('[data-action]')?.dataset.action;\n if (!action) return;\n\n if (action === 'submit') {\n void submit();\n return;\n }\n\n if (action === 'cancel' || action === 'close') {\n close(null);\n return;\n }\n\n if (action === 'backdrop' && input.options.modal.closeOnBackdrop) {\n close(null);\n }\n }\n\n function onKeydown(event: KeyboardEvent): void {\n if (event.key === 'Escape') {\n event.preventDefault();\n close(null);\n }\n }\n\n root.addEventListener('click', onClick);\n document.addEventListener('keydown', onKeydown, true);\n\n queueMicrotask(() => {\n mounted.root.focus();\n });\n });\n}\n"],"mappings":";AAAA;AAAA,EACE,6BAAAA;AAAA,EACA,yBAAAC;AAAA,EACA,0BAAAC;AAAA,OACK;;;ACJP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,6BAAAC;AAAA,EACA,2BAAAC;AAAA,OACK;;;ACfP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA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B;AACjB,QAAM,SAAS,mBAAmB,IAAI,KAAK;AAC3C,MAAI,QAAQ;AACV,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,YAAY;AAC3B,UAAM,OAAO,SAAS,cAAc,KAAK;AACzC,SAAK,MAAM,WAAW;AACtB,SAAK,MAAM,OAAO;AAClB,SAAK,MAAM,MAAM;AACjB,SAAK,MAAM,QAAQ;AACnB,SAAK,MAAM,SAAS;AACpB,SAAK,MAAM,UAAU;AACrB,SAAK,MAAM,gBAAgB;AAC3B,SAAK,aAAa,eAAe,MAAM;AACvC,aAAS,KAAK,YAAY,IAAI;AAE9B,UAAM,UAAUC,yBAAwB,MAAM;AAAA,MAC5C,cAAc;AAAA,MACd,QAAQ,QAAQ,OAAO;AAAA,MACvB,WAAW;AAAA,MACX,QAAQ,QAAQ,OAAO;AAAA,MACvB,QAAQ;AAAA,QACN,UAAU,QAAQ,OAAO,OAAO;AAAA,MAClC;AAAA,IACF,CAAC;AAED,QAAI;AACF,aAAO,MAAM,QAAQ,cAAc;AAAA,IACrC,UAAE;AACA,cAAQ,QAAQ;AAChB,WAAK,OAAO;AAAA,IACd;AAAA,EACF,GAAG;AAEH,qBAAmB,IAAI,OAAO,OAAO;AACrC,UAAQ,MAAM,MAAM;AAClB,QAAI,mBAAmB,IAAI,KAAK,MAAM,SAAS;AAC7C,yBAAmB,OAAO,KAAK;AAAA,IACjC;AAAA,EACF,CAAC;AACD,SAAO;AACT;","names":["DEFAULT_FORMULA_ATTRIBUTE","DEFAULT_FORMULA_CLASS","FORMULA_FLAG_ATTRIBUTE","ensureFormulaXModalStyles","mountFormulaXKityEditor","ensureFormulaXModalStyles","mountFormulaXKityEditor"]}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@formulaxjs/ckeditor5",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"description": "CKEditor 5 integration adapter for FormulaX.",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"formulax",
|
|
10
|
+
"formula",
|
|
11
|
+
"ckeditor5",
|
|
12
|
+
"editor",
|
|
13
|
+
"adapter"
|
|
14
|
+
],
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"unpkg": "./dist/browser/index.global.js",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@formulaxjs/core": "0.1.0",
|
|
34
|
+
"@formulaxjs/kity-assets": "0.1.0",
|
|
35
|
+
"@formulaxjs/kity-runtime": "0.1.0",
|
|
36
|
+
"@formulaxjs/editor": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"ckeditor5": ">=42 <49"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"ckeditor5": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"ckeditor5": "^46.1.1"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup --config ../../tsup.config.mjs",
|
|
51
|
+
"clean": "Remove-Item -Recurse -Force dist -ErrorAction SilentlyContinue",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|