@formulaxjs/tiptap 0.1.0 → 0.2.1
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 +22 -0
- package/README.zh-CN.md +22 -0
- package/dist/index.cjs +134 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +148 -140
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +134 -122
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.global.js
CHANGED
|
@@ -14249,7 +14249,7 @@ var FormulaX = (() => {
|
|
|
14249
14249
|
var start_GQH6XUBI_exports = {};
|
|
14250
14250
|
__export(start_GQH6XUBI_exports, {
|
|
14251
14251
|
Factory: () => factory_default,
|
|
14252
|
-
KFEditor: () =>
|
|
14252
|
+
KFEditor: () => editor_default,
|
|
14253
14253
|
default: () => start_default,
|
|
14254
14254
|
installKityEditorStart: () => installKityEditorStart
|
|
14255
14255
|
});
|
|
@@ -14960,23 +14960,23 @@ var FormulaX = (() => {
|
|
|
14960
14960
|
function installKityEditorStart(target = window) {
|
|
14961
14961
|
const runtimeTarget = target;
|
|
14962
14962
|
if (!installed3) {
|
|
14963
|
-
|
|
14964
|
-
|
|
14965
|
-
|
|
14966
|
-
|
|
14967
|
-
|
|
14968
|
-
|
|
14969
|
-
|
|
14963
|
+
editor_default.registerComponents("ui", ui_default);
|
|
14964
|
+
editor_default.registerComponents("parser", parser_default);
|
|
14965
|
+
editor_default.registerComponents("render", render_default);
|
|
14966
|
+
editor_default.registerComponents("position", position_default);
|
|
14967
|
+
editor_default.registerComponents("syntax", syntax_default);
|
|
14968
|
+
editor_default.registerComponents("control", controller_default);
|
|
14969
|
+
editor_default.registerComponents("print", printer_default);
|
|
14970
14970
|
installed3 = true;
|
|
14971
14971
|
}
|
|
14972
14972
|
runtimeTarget.kf = runtimeTarget.kf ?? {};
|
|
14973
14973
|
runtimeTarget.kf.EditorFactory = factory_default;
|
|
14974
14974
|
return {
|
|
14975
|
-
KFEditor:
|
|
14975
|
+
KFEditor: editor_default,
|
|
14976
14976
|
Factory: factory_default
|
|
14977
14977
|
};
|
|
14978
14978
|
}
|
|
14979
|
-
var defaultOptions, components, kity, kf, KFEditor,
|
|
14979
|
+
var defaultOptions, components, kity, kf, KFEditor, editor_default, EditorWrapper, factory, factory_default, PREFIX, LIST_OFFSET, DEFAULT_OPTIONS2, $$, kity2, Button, button_default, PREFIX2, $$2, kity3, List, list_default, kity4, $$3, PREFIX3, BOX_TYPE, ITEM_TYPE, SCROLL_STEP, BoxItem, Box, box_default, PREFIX4, PANEL_HEIGHT, $$4, kity5, Area, area_default, PREFIX5, $$5, kity6, Delimiter, delimiter_default, $$6, kity7, DrapdownBox, dropdown_box_default, UiImpl, ui_impl_default, $$7, kity8, Toolbar, toolbar_default, SCROLLBAR_DEF, SCROLLBAR_CONF, CLASS_PREFIX, kity9, Scrollbar, scrollbar_default, UNICODE_SYMBOLS, STYLE_FONT_MAP, UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, config, toolbar_config_default, $$8, VIEW_STATE, DEFAULT_EDIT_AREA_HEIGHT, kity10, UIComponent, ui_default, kity11, kf2, PlaceholderOperator, kf_ext_placeholder_operator_default, kity12, kf3, BaseCompoundExpression, PlaceholderExpression, kf_ext_placeholder_expression_default, kf4, kf_ext_extension_default, legacyVirtualGroupMap, vgroup_def_default, CURSOR_CHAR, ROOT_P_TEXT, COMBINATION_NAME, PID_PREFIX, pidSeed, kity13, kf5, BaseComponent, Parser, parser_default, DEFAULT_OPTIONS22, kity14, kf6, BaseComponent2, RenderComponent, render_default, kity15, PositionComponent, position_default, kity16, DeleteComponent, syntax_delete_default, kity17, MoveComponent, syntax_move_default, CURSOR_CHAR2, kity18, SyntaxComponent, syntax_default, KEY_CODE, kity19, InputComponent, input_default, kity20, LocationComponent, location_default, MAX_DISTANCE, kity21, SelectionComponent, selection_default, kity22, ListenerComponent, listener_default, kity23, ControllerComponent, controller_default, kity24, Printer, printer_default, installed3, start_default;
|
|
14980
14980
|
var init_start_GQH6XUBI = __esm({
|
|
14981
14981
|
"../kity-runtime/dist/start-GQH6XUBI.js"() {
|
|
14982
14982
|
"use strict";
|
|
@@ -15087,12 +15087,12 @@ var FormulaX = (() => {
|
|
|
15087
15087
|
components[name] = component;
|
|
15088
15088
|
}
|
|
15089
15089
|
});
|
|
15090
|
-
|
|
15090
|
+
editor_default = KFEditor;
|
|
15091
15091
|
EditorWrapper = class {
|
|
15092
15092
|
callbacks = [];
|
|
15093
15093
|
editor;
|
|
15094
15094
|
constructor(container, options) {
|
|
15095
|
-
this.editor = new
|
|
15095
|
+
this.editor = new editor_default(container, options);
|
|
15096
15096
|
this.editor.ready(() => {
|
|
15097
15097
|
this.trigger();
|
|
15098
15098
|
});
|
|
@@ -26799,11 +26799,9 @@ var FormulaX = (() => {
|
|
|
26799
26799
|
|
|
26800
26800
|
// ../kity-runtime/dist/index.js
|
|
26801
26801
|
init_chunk_EKIJQ64F();
|
|
26802
|
-
|
|
26803
|
-
// ../kity-assets/dist/index.js
|
|
26804
26802
|
var btn_default = "./btn-5DANP6JY.png";
|
|
26805
26803
|
var other_default = "./other-OMWJFGL5.png";
|
|
26806
|
-
var
|
|
26804
|
+
var editor_default2 = "./editor-JT5KLVXX.css?url";
|
|
26807
26805
|
var KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
|
|
26808
26806
|
var KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
|
|
26809
26807
|
var KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
|
|
@@ -26821,15 +26819,13 @@ var FormulaX = (() => {
|
|
|
26821
26819
|
other: other_default
|
|
26822
26820
|
};
|
|
26823
26821
|
var kityStyleAssets = {
|
|
26824
|
-
editor:
|
|
26822
|
+
editor: editor_default2
|
|
26825
26823
|
};
|
|
26826
26824
|
var kityAssetManifest = {
|
|
26827
26825
|
fonts: kityFontAssets,
|
|
26828
26826
|
toolbar: kityToolbarAssets,
|
|
26829
26827
|
styles: kityStyleAssets
|
|
26830
26828
|
};
|
|
26831
|
-
|
|
26832
|
-
// ../kity-runtime/dist/index.js
|
|
26833
26829
|
var legacyCharPosition = {
|
|
26834
26830
|
"\\pm": {
|
|
26835
26831
|
"x": 5,
|
|
@@ -31222,6 +31218,7 @@ var FormulaX = (() => {
|
|
|
31222
31218
|
var FORMULAX_NODE_NAME = "formulaX";
|
|
31223
31219
|
function resolveOptions(options = {}) {
|
|
31224
31220
|
return {
|
|
31221
|
+
name: options.name ?? FORMULAX_NODE_NAME,
|
|
31225
31222
|
formulaClassName: options.formulaClassName ?? DEFAULT_FORMULA_CLASS,
|
|
31226
31223
|
formulaAttributeName: options.formulaAttributeName ?? DEFAULT_FORMULA_ATTRIBUTE,
|
|
31227
31224
|
cursorStyle: options.cursorStyle ?? "pointer",
|
|
@@ -31243,140 +31240,151 @@ var FormulaX = (() => {
|
|
|
31243
31240
|
}
|
|
31244
31241
|
};
|
|
31245
31242
|
}
|
|
31246
|
-
|
|
31247
|
-
|
|
31248
|
-
|
|
31249
|
-
|
|
31250
|
-
|
|
31251
|
-
|
|
31252
|
-
|
|
31253
|
-
|
|
31254
|
-
|
|
31255
|
-
|
|
31256
|
-
|
|
31257
|
-
|
|
31258
|
-
|
|
31259
|
-
|
|
31260
|
-
|
|
31261
|
-
|
|
31262
|
-
|
|
31263
|
-
|
|
31243
|
+
function warnDuplicateNodeName(extension) {
|
|
31244
|
+
const extensions = extension.editor?.extensionManager?.extensions ?? [];
|
|
31245
|
+
const duplicates = extensions.filter((item) => item?.name === extension.name);
|
|
31246
|
+
if (duplicates.length > 1) {
|
|
31247
|
+
console.warn(
|
|
31248
|
+
`[FormulaX] TipTap node name "${extension.name}" is already registered. Pass a unique "name" option to avoid schema collisions.`
|
|
31249
|
+
);
|
|
31250
|
+
}
|
|
31251
|
+
}
|
|
31252
|
+
function createFormulaXNodeConfig(options) {
|
|
31253
|
+
return {
|
|
31254
|
+
name: options.name,
|
|
31255
|
+
group: "inline",
|
|
31256
|
+
inline: true,
|
|
31257
|
+
atom: true,
|
|
31258
|
+
selectable: true,
|
|
31259
|
+
addOptions() {
|
|
31260
|
+
return options;
|
|
31261
|
+
},
|
|
31262
|
+
onCreate() {
|
|
31263
|
+
warnDuplicateNodeName(this);
|
|
31264
|
+
if (typeof document !== "undefined") {
|
|
31265
|
+
ensureFormulaXModalStyles(document);
|
|
31264
31266
|
}
|
|
31265
|
-
}
|
|
31266
|
-
|
|
31267
|
-
|
|
31268
|
-
|
|
31269
|
-
|
|
31270
|
-
getAttrs: (element) => {
|
|
31271
|
-
if (!(element instanceof HTMLElement)) {
|
|
31272
|
-
return false;
|
|
31267
|
+
},
|
|
31268
|
+
addAttributes() {
|
|
31269
|
+
return {
|
|
31270
|
+
latex: {
|
|
31271
|
+
default: ""
|
|
31273
31272
|
}
|
|
31274
|
-
|
|
31275
|
-
|
|
31276
|
-
|
|
31277
|
-
|
|
31278
|
-
|
|
31279
|
-
|
|
31280
|
-
|
|
31281
|
-
|
|
31282
|
-
return [
|
|
31283
|
-
"span",
|
|
31284
|
-
{
|
|
31285
|
-
"data-formulax": "true",
|
|
31286
|
-
[this.options.formulaAttributeName]: node.attrs.latex,
|
|
31287
|
-
"data-latex": node.attrs.latex
|
|
31288
|
-
},
|
|
31289
|
-
node.attrs.latex || "\\square"
|
|
31290
|
-
];
|
|
31291
|
-
}
|
|
31292
|
-
return createFormulaDomElement(document, node.attrs, this.options);
|
|
31293
|
-
},
|
|
31294
|
-
addCommands() {
|
|
31295
|
-
return {
|
|
31296
|
-
openFormulaX: () => () => {
|
|
31297
|
-
const selectedFormula = getSelectedFormula(this.editor);
|
|
31298
|
-
const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;
|
|
31299
|
-
void openFormulaXTiptapModal({
|
|
31300
|
-
initialLatex,
|
|
31301
|
-
isUpdate: Boolean(selectedFormula),
|
|
31302
|
-
options: this.options
|
|
31303
|
-
}).then((payload) => {
|
|
31304
|
-
if (!payload) {
|
|
31305
|
-
return;
|
|
31273
|
+
};
|
|
31274
|
+
},
|
|
31275
|
+
parseHTML() {
|
|
31276
|
+
return [{
|
|
31277
|
+
tag: "span[data-formulax]",
|
|
31278
|
+
getAttrs: (element) => {
|
|
31279
|
+
if (!(element instanceof HTMLElement)) {
|
|
31280
|
+
return false;
|
|
31306
31281
|
}
|
|
31307
|
-
|
|
31308
|
-
|
|
31309
|
-
|
|
31310
|
-
return true;
|
|
31311
|
-
}
|
|
31312
|
-
};
|
|
31313
|
-
},
|
|
31314
|
-
addKeyboardShortcuts() {
|
|
31315
|
-
return {
|
|
31316
|
-
Enter: () => {
|
|
31317
|
-
if (!getSelectedFormula(this.editor)) {
|
|
31318
|
-
return false;
|
|
31319
|
-
}
|
|
31320
|
-
return this.editor.commands.openFormulaX();
|
|
31321
|
-
},
|
|
31322
|
-
Space: () => {
|
|
31323
|
-
if (!getSelectedFormula(this.editor)) {
|
|
31324
|
-
return false;
|
|
31282
|
+
return {
|
|
31283
|
+
latex: getFormulaLatexFromElement(element, this.options.formulaAttributeName)
|
|
31284
|
+
};
|
|
31325
31285
|
}
|
|
31326
|
-
|
|
31286
|
+
}];
|
|
31287
|
+
},
|
|
31288
|
+
renderHTML({ node }) {
|
|
31289
|
+
if (typeof document === "undefined") {
|
|
31290
|
+
return [
|
|
31291
|
+
"span",
|
|
31292
|
+
{
|
|
31293
|
+
"data-formulax": "true",
|
|
31294
|
+
[this.options.formulaAttributeName]: node.attrs.latex,
|
|
31295
|
+
"data-latex": node.attrs.latex
|
|
31296
|
+
},
|
|
31297
|
+
node.attrs.latex || "\\square"
|
|
31298
|
+
];
|
|
31327
31299
|
}
|
|
31328
|
-
|
|
31329
|
-
|
|
31330
|
-
|
|
31331
|
-
|
|
31332
|
-
|
|
31333
|
-
|
|
31334
|
-
|
|
31335
|
-
|
|
31336
|
-
|
|
31337
|
-
|
|
31338
|
-
|
|
31300
|
+
return createFormulaDomElement(document, node.attrs, this.options);
|
|
31301
|
+
},
|
|
31302
|
+
addCommands() {
|
|
31303
|
+
return {
|
|
31304
|
+
openFormulaX: () => () => {
|
|
31305
|
+
const selectedFormula = getSelectedFormula(this.editor, this.name);
|
|
31306
|
+
const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;
|
|
31307
|
+
void openFormulaXTiptapModal({
|
|
31308
|
+
initialLatex,
|
|
31309
|
+
isUpdate: Boolean(selectedFormula),
|
|
31310
|
+
options: this.options
|
|
31311
|
+
}).then((payload) => {
|
|
31312
|
+
if (!payload) {
|
|
31313
|
+
return;
|
|
31314
|
+
}
|
|
31315
|
+
applyFormulaPayload(this.editor, payload, selectedFormula, this.name);
|
|
31316
|
+
this.editor.commands.focus();
|
|
31317
|
+
});
|
|
31318
|
+
return true;
|
|
31339
31319
|
}
|
|
31340
|
-
editor.commands.setNodeSelection?.(position);
|
|
31341
31320
|
};
|
|
31342
|
-
|
|
31343
|
-
|
|
31344
|
-
selectNode();
|
|
31345
|
-
});
|
|
31346
|
-
dom.addEventListener("dblclick", (event2) => {
|
|
31347
|
-
event2.preventDefault();
|
|
31348
|
-
event2.stopPropagation();
|
|
31349
|
-
selectNode();
|
|
31350
|
-
editor.commands.openFormulaX();
|
|
31351
|
-
});
|
|
31321
|
+
},
|
|
31322
|
+
addKeyboardShortcuts() {
|
|
31352
31323
|
return {
|
|
31353
|
-
|
|
31354
|
-
|
|
31355
|
-
if (updatedNode.type.name !== FORMULAX_NODE_NAME) {
|
|
31324
|
+
Enter: () => {
|
|
31325
|
+
if (!getSelectedFormula(this.editor, this.name)) {
|
|
31356
31326
|
return false;
|
|
31357
31327
|
}
|
|
31358
|
-
|
|
31359
|
-
void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);
|
|
31360
|
-
return true;
|
|
31361
|
-
},
|
|
31362
|
-
selectNode: () => {
|
|
31363
|
-
dom.classList.add("ProseMirror-selectednode");
|
|
31328
|
+
return this.editor.commands.openFormulaX();
|
|
31364
31329
|
},
|
|
31365
|
-
|
|
31366
|
-
|
|
31330
|
+
Space: () => {
|
|
31331
|
+
if (!getSelectedFormula(this.editor, this.name)) {
|
|
31332
|
+
return false;
|
|
31333
|
+
}
|
|
31334
|
+
return this.editor.commands.openFormulaX();
|
|
31367
31335
|
}
|
|
31368
31336
|
};
|
|
31369
|
-
}
|
|
31370
|
-
|
|
31371
|
-
|
|
31337
|
+
},
|
|
31338
|
+
addNodeView() {
|
|
31339
|
+
return ({ editor, getPos, node }) => {
|
|
31340
|
+
const dom = createFormulaDomElement(document, node.attrs, this.options) ?? document.createElement("span");
|
|
31341
|
+
dom.classList.add("formulax-math--interactive");
|
|
31342
|
+
void renderFormulaIntoElement(dom, node.attrs, this.options);
|
|
31343
|
+
const selectNode = () => {
|
|
31344
|
+
const position = getPos();
|
|
31345
|
+
if (typeof position !== "number") {
|
|
31346
|
+
return;
|
|
31347
|
+
}
|
|
31348
|
+
editor.commands.setNodeSelection?.(position);
|
|
31349
|
+
};
|
|
31350
|
+
dom.addEventListener("click", (event2) => {
|
|
31351
|
+
event2.preventDefault();
|
|
31352
|
+
selectNode();
|
|
31353
|
+
});
|
|
31354
|
+
dom.addEventListener("dblclick", (event2) => {
|
|
31355
|
+
event2.preventDefault();
|
|
31356
|
+
event2.stopPropagation();
|
|
31357
|
+
selectNode();
|
|
31358
|
+
editor.commands.openFormulaX();
|
|
31359
|
+
});
|
|
31360
|
+
return {
|
|
31361
|
+
dom,
|
|
31362
|
+
update: (updatedNode) => {
|
|
31363
|
+
if (updatedNode.type.name !== this.name) {
|
|
31364
|
+
return false;
|
|
31365
|
+
}
|
|
31366
|
+
syncFormulaDomElement(dom, updatedNode.attrs, this.options);
|
|
31367
|
+
void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);
|
|
31368
|
+
return true;
|
|
31369
|
+
},
|
|
31370
|
+
selectNode: () => {
|
|
31371
|
+
dom.classList.add("ProseMirror-selectednode");
|
|
31372
|
+
},
|
|
31373
|
+
deselectNode: () => {
|
|
31374
|
+
dom.classList.remove("ProseMirror-selectednode");
|
|
31375
|
+
}
|
|
31376
|
+
};
|
|
31377
|
+
};
|
|
31378
|
+
}
|
|
31379
|
+
};
|
|
31380
|
+
}
|
|
31372
31381
|
function createFormulaXNode(nodeFactory = Node2, options) {
|
|
31373
|
-
|
|
31374
|
-
return options ? extension.configure(options) : extension;
|
|
31382
|
+
return nodeFactory.create(createFormulaXNodeConfig(resolveOptions(options)));
|
|
31375
31383
|
}
|
|
31376
31384
|
var FormulaXNode = createFormulaXNode();
|
|
31377
31385
|
var createFormulaXPayload = (latex) => parseLatex(latex);
|
|
31378
31386
|
var serializeFormulaXPayload = (doc2) => serializeLatex(doc2);
|
|
31379
|
-
function applyFormulaPayload(editor, payload, selectedFormula) {
|
|
31387
|
+
function applyFormulaPayload(editor, payload, selectedFormula, nodeName) {
|
|
31380
31388
|
const latex = payload.latex.trim();
|
|
31381
31389
|
if (selectedFormula) {
|
|
31382
31390
|
if (!latex) {
|
|
@@ -31391,19 +31399,19 @@ var FormulaX = (() => {
|
|
|
31391
31399
|
from: selectedFormula.from,
|
|
31392
31400
|
to: selectedFormula.to
|
|
31393
31401
|
},
|
|
31394
|
-
createFormulaNodeContent(payload)
|
|
31402
|
+
createFormulaNodeContent(payload, nodeName)
|
|
31395
31403
|
).run();
|
|
31396
31404
|
return;
|
|
31397
31405
|
}
|
|
31398
31406
|
if (!latex) {
|
|
31399
31407
|
return;
|
|
31400
31408
|
}
|
|
31401
|
-
editor.chain().focus().insertContent(createFormulaNodeContent(payload)).run();
|
|
31409
|
+
editor.chain().focus().insertContent(createFormulaNodeContent(payload, nodeName)).run();
|
|
31402
31410
|
}
|
|
31403
|
-
function getSelectedFormula(editor) {
|
|
31411
|
+
function getSelectedFormula(editor, nodeName) {
|
|
31404
31412
|
const { selection } = editor.state;
|
|
31405
31413
|
const node = selection.node;
|
|
31406
|
-
if (node?.type?.name !==
|
|
31414
|
+
if (node?.type?.name !== nodeName) {
|
|
31407
31415
|
return null;
|
|
31408
31416
|
}
|
|
31409
31417
|
return {
|
|
@@ -31414,9 +31422,9 @@ var FormulaX = (() => {
|
|
|
31414
31422
|
}
|
|
31415
31423
|
};
|
|
31416
31424
|
}
|
|
31417
|
-
function createFormulaNodeContent(payload) {
|
|
31425
|
+
function createFormulaNodeContent(payload, nodeName = FORMULAX_NODE_NAME) {
|
|
31418
31426
|
return {
|
|
31419
|
-
type:
|
|
31427
|
+
type: nodeName,
|
|
31420
31428
|
attrs: {
|
|
31421
31429
|
latex: payload.latex
|
|
31422
31430
|
}
|