@wiris/mathtype-ckeditor5 8.15.0 → 8.15.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 +1 -0
- package/dist/browser/index-editor.css +16 -1
- package/dist/browser/index.css +17 -0
- package/dist/browser/index.css.map +1 -1
- package/dist/browser/index.js +109 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.js +109 -6
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/index-editor.css +15 -0
- package/dist/index.css +18 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +65 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/integration.js +9 -0
- package/src/plugin.js +72 -6
- package/theme/styles.css +28 -0
package/dist/index-editor.css
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker{
|
|
2
|
+
border:none;
|
|
3
|
+
}
|
|
4
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-insertion .Wirisformula{
|
|
5
|
+
border:3px solid var(--ck-color-suggestion-marker-insertion-border);
|
|
6
|
+
}
|
|
7
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-insertion.ck-suggestion-marker--active .Wirisformula{
|
|
8
|
+
border:3px solid var(--ck-color-suggestion-marker-insertion-border-active);
|
|
9
|
+
}
|
|
10
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-deletion .Wirisformula{
|
|
11
|
+
border:3px solid var(--ck-color-suggestion-marker-deletion-border);
|
|
12
|
+
}
|
|
13
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-deletion.ck-suggestion-marker--active .Wirisformula{
|
|
14
|
+
border:3px solid var(--ck-color-suggestion-marker-deletion-border-active);
|
|
15
|
+
}
|
package/dist/index.css
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* Replace the default suggestion marker border because it's doesn't span the entire widget. */
|
|
2
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker {
|
|
3
|
+
border: none;
|
|
4
|
+
}
|
|
5
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-insertion .Wirisformula {
|
|
6
|
+
border: 3px solid var(--ck-color-suggestion-marker-insertion-border);
|
|
7
|
+
}
|
|
8
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-insertion.ck-suggestion-marker--active .Wirisformula {
|
|
9
|
+
border: 3px solid var(--ck-color-suggestion-marker-insertion-border-active);
|
|
10
|
+
}
|
|
11
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-deletion .Wirisformula {
|
|
12
|
+
border: 3px solid var(--ck-color-suggestion-marker-deletion-border);
|
|
13
|
+
}
|
|
14
|
+
.ck-widget.ck-math-widget.ck-suggestion-marker.ck-suggestion-marker-deletion.ck-suggestion-marker--active .Wirisformula {
|
|
15
|
+
border: 3px solid var(--ck-color-suggestion-marker-deletion-border-active);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../theme/styles.css"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F;EACE,YAAY;AAyBd;AAtBI;MACE,oEAAoE;IACtE;AAGE;QACE,2EAA2E;MAC7E;AAKF;MACE,mEAAmE;IACrE;AAGE;QACE,0EAA0E;MAC5E","file":"index.css","sourcesContent":["/* Replace the default suggestion marker border because it's doesn't span the entire widget. */\n.ck-widget.ck-math-widget.ck-suggestion-marker {\n border: none;\n\n &.ck-suggestion-marker-insertion {\n & .Wirisformula {\n border: 3px solid var(--ck-color-suggestion-marker-insertion-border);\n }\n\n &.ck-suggestion-marker--active {\n & .Wirisformula {\n border: 3px solid var(--ck-color-suggestion-marker-insertion-border-active);\n }\n }\n }\n\n &.ck-suggestion-marker-deletion {\n & .Wirisformula {\n border: 3px solid var(--ck-color-suggestion-marker-deletion-border);\n }\n\n &.ck-suggestion-marker--active {\n & .Wirisformula {\n border: 3px solid var(--ck-color-suggestion-marker-deletion-border-active);\n }\n }\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -212,6 +212,14 @@ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js'
|
|
|
212
212
|
returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);
|
|
213
213
|
this.editorObject.model.change((writer)=>{
|
|
214
214
|
const { latexRange } = this.core.editionProperties;
|
|
215
|
+
// Add null check for latexRange.
|
|
216
|
+
// When the editor is initialized in a textarea element, latexRange may not be set on initial load.
|
|
217
|
+
// This check ensures formulas can still be inserted by falling back to MathML insertion if latexRange is not available.
|
|
218
|
+
if (!latexRange) {
|
|
219
|
+
// Fallback to regular MathML insertion if latexRange is not available
|
|
220
|
+
this.insertMathml(mathml);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
215
223
|
const startNode = this.findText(latexRange.startContainer);
|
|
216
224
|
const endNode = this.findText(latexRange.endContainer);
|
|
217
225
|
let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);
|
|
@@ -361,7 +369,7 @@ var mathIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adob
|
|
|
361
369
|
|
|
362
370
|
var chemIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->\n<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n\t viewBox=\"0 0 40.3 49.5\" style=\"enable-background:new 0 0 40.3 49.5;\" xml:space=\"preserve\">\n<style type=\"text/css\">\n\t.st0{fill:#A4CF61;}\n</style>\n<path class=\"st0\" d=\"M39.2,12.1c0-1.9-1.1-3.6-2.7-4.4L24.5,0.9l0,0c-0.7-0.4-1.5-0.6-2.4-0.6c-0.9,0-1.7,0.2-2.4,0.6l0,0L2.3,10.8\n\tl0,0C0.9,11.7,0,13.2,0,14.9h0v19.6h0c0,1.7,0.9,3.3,2.3,4.1l0,0l17.4,9.9l0,0c0.7,0.4,1.5,0.6,2.4,0.6c0.9,0,1.7-0.2,2.4-0.6l0,0\n\tl12.2-6.9h0c1.5-0.8,2.6-2.5,2.6-4.3c0-2.7-2.2-4.9-4.9-4.9c-0.9,0-1.8,0.3-2.5,0.7l0,0l-9.7,5.6l-12.3-7V17.8l12.3-7l9.9,5.7l0,0\n\tc0.7,0.4,1.5,0.6,2.4,0.6C37,17,39.2,14.8,39.2,12.1\"/>\n</svg>\n";
|
|
363
371
|
|
|
364
|
-
var version = "8.15.
|
|
372
|
+
var version = "8.15.1";
|
|
365
373
|
var packageInfo = {
|
|
366
374
|
version: version};
|
|
367
375
|
|
|
@@ -703,7 +711,8 @@ class MathType extends Plugin {
|
|
|
703
711
|
imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);
|
|
704
712
|
} else if (formula) {
|
|
705
713
|
const mathString = formula.replaceAll('ref="<"', 'ref="<"');
|
|
706
|
-
const
|
|
714
|
+
const lang = integration?.getLanguage() || "en"; // Safe fallback to 'en' in case integration is undefined.
|
|
715
|
+
const imgHtml = Parser.initParse(mathString, lang);
|
|
707
716
|
imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);
|
|
708
717
|
// Add HTML element (<img>) to model
|
|
709
718
|
viewWriter.setAttribute("htmlContent", imgHtml, modelItem);
|
|
@@ -761,13 +770,63 @@ class MathType extends Plugin {
|
|
|
761
770
|
editor.editing.mapper.on("viewToModelPosition", viewToModelPositionOutsideModelElement(editor.model, (viewElement)=>viewElement.hasClass("ck-math-widget")));
|
|
762
771
|
// Keep a reference to the original get and set function.
|
|
763
772
|
const { get, set } = editor.data;
|
|
773
|
+
// Listen to the preview command execution to set a flag in localStorage.
|
|
774
|
+
// This flag will be used in the getData() to prevent converting formulas while generating the preview.
|
|
775
|
+
// This is necessary because the preview command uses editor.getData() multiple times internally.
|
|
776
|
+
const previewCommand = editor.commands.get("previewFinalContent");
|
|
777
|
+
if (previewCommand) {
|
|
778
|
+
this.listenTo(previewCommand, "execute", ()=>{
|
|
779
|
+
localStorage.setItem("isGeneratingPreview", true);
|
|
780
|
+
setTimeout(()=>{
|
|
781
|
+
localStorage.setItem("isGeneratingPreview", false);
|
|
782
|
+
}, 1000);
|
|
783
|
+
}, {
|
|
784
|
+
priority: "high"
|
|
785
|
+
});
|
|
786
|
+
}
|
|
764
787
|
/**
|
|
765
|
-
*
|
|
788
|
+
* Listener for getData() that handles Track Changes and semantics cleanup.
|
|
789
|
+
*
|
|
790
|
+
* This listener intercepts the getData() call and processes the output differently
|
|
791
|
+
* depending on whether we're generating a preview or performing a save operation:
|
|
792
|
+
*
|
|
793
|
+
* - Preview Mode: Removes deleted formulas (marked with Track Changes deletion attributes)
|
|
794
|
+
* while preserving formula images for visual representation.
|
|
795
|
+
* - Save Mode: Converts formulas to clean MathML by removing semantic annotations
|
|
796
|
+
* and handwritten data, ensuring clean storage format.
|
|
766
797
|
*/ editor.data.on("get", (e)=>{
|
|
767
798
|
const output = e.return;
|
|
799
|
+
// Check if we're in preview mode (flag set by previewFinalContent command)
|
|
800
|
+
const isGeneratingPreview = localStorage.getItem("isGeneratingPreview");
|
|
801
|
+
if (isGeneratingPreview === "true") {
|
|
802
|
+
// Wrap a <span> around all img elements to preserve Track Changes visibility for formulas.
|
|
803
|
+
// Span must contain all the img attributes to avoid render issues.
|
|
804
|
+
const attributesToPreserve = [
|
|
805
|
+
"data-suggestion-",
|
|
806
|
+
"data-comment-"
|
|
807
|
+
];
|
|
808
|
+
const previewOutput = output.replace(/<img([^>]*class="Wirisformula"[^>]*)>/g, (match, attributes)=>{
|
|
809
|
+
// Extract Track Changes attributes
|
|
810
|
+
const trackChangesAttrs = [];
|
|
811
|
+
attributesToPreserve.forEach((prefix)=>{
|
|
812
|
+
const regex = new RegExp(`(${prefix}[^=]*="[^"]*")`, "g");
|
|
813
|
+
let attrMatch;
|
|
814
|
+
while((attrMatch = regex.exec(attributes)) !== null){
|
|
815
|
+
trackChangesAttrs.push(attrMatch[1]);
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
const spanAttrs = trackChangesAttrs.length > 0 ? ` ${trackChangesAttrs.join(" ")}` : "";
|
|
819
|
+
return `<span${spanAttrs}>${match}</span>`;
|
|
820
|
+
});
|
|
821
|
+
// Cleans all the semantics tag for safexml
|
|
822
|
+
// including the handwritten data points
|
|
823
|
+
e.return = MathML.removeSafeXMLSemantics(previewOutput);
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
// In save mode, convert formula images back to clean MathML
|
|
768
827
|
const parsedResult = Parser.endParse(output);
|
|
769
|
-
//
|
|
770
|
-
//
|
|
828
|
+
// Remove all semantic annotations (including handwritten data points)
|
|
829
|
+
// to ensure clean, standard MathML format for storage
|
|
771
830
|
e.return = MathML.removeSafeXMLSemantics(parsedResult);
|
|
772
831
|
}, {
|
|
773
832
|
priority: "low"
|
|
@@ -832,7 +891,7 @@ class MathType extends Plugin {
|
|
|
832
891
|
trackChangesEditing.enableCommand("ChemType");
|
|
833
892
|
// Adds custom label replacing the default 'mathml'.
|
|
834
893
|
// Handles both singular and plural forms.
|
|
835
|
-
trackChangesEditing.descriptionFactory.registerElementLabel("mathml", (quantity)=>(quantity > 1 ? quantity
|
|
894
|
+
trackChangesEditing.descriptionFactory.registerElementLabel("mathml", (quantity)=>(quantity > 1 ? `${quantity} ` : "") + StringManager.get(quantity > 1 ? "formulas" : "formula", integration?.getLanguage() || "en"));
|
|
836
895
|
}
|
|
837
896
|
}
|
|
838
897
|
}
|