@wiris/mathtype-ckeditor5 8.14.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 +139 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.js +139 -11
- 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 +85 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/integration.js +17 -3
- package/src/plugin.js +94 -5
- 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
|
@@ -150,7 +150,9 @@ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js'
|
|
|
150
150
|
// Remove selection
|
|
151
151
|
if (!viewSelection.isCollapsed) {
|
|
152
152
|
for (const range of viewSelection.getRanges()){
|
|
153
|
-
|
|
153
|
+
const modelRange = this.editorObject.editing.mapper.toModelRange(range);
|
|
154
|
+
const modelSelection = this.editorObject.model.createSelection(modelRange);
|
|
155
|
+
this.editorObject.model.deleteContent(modelSelection);
|
|
154
156
|
}
|
|
155
157
|
}
|
|
156
158
|
// Set carret after the formula
|
|
@@ -166,7 +168,7 @@ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js'
|
|
|
166
168
|
if (mathml) {
|
|
167
169
|
this.editorObject.model.insertObject(modelElementNew, position);
|
|
168
170
|
}
|
|
169
|
-
|
|
171
|
+
this.editorObject.model.deleteContent(this.editorObject.model.createSelection(modelElementOld, 'on'));
|
|
170
172
|
}
|
|
171
173
|
// eslint-disable-next-line consistent-return
|
|
172
174
|
return modelElementNew;
|
|
@@ -210,6 +212,14 @@ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js'
|
|
|
210
212
|
returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);
|
|
211
213
|
this.editorObject.model.change((writer)=>{
|
|
212
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
|
+
}
|
|
213
223
|
const startNode = this.findText(latexRange.startContainer);
|
|
214
224
|
const endNode = this.findText(latexRange.endContainer);
|
|
215
225
|
let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);
|
|
@@ -237,7 +247,8 @@ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js'
|
|
|
237
247
|
range = writer.createRange(startPosition, endPosition);
|
|
238
248
|
}
|
|
239
249
|
}
|
|
240
|
-
|
|
250
|
+
const modelSelection = this.editorObject.model.createSelection(range);
|
|
251
|
+
this.editorObject.model.deleteContent(modelSelection);
|
|
241
252
|
writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);
|
|
242
253
|
});
|
|
243
254
|
} else {
|
|
@@ -358,7 +369,7 @@ var mathIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adob
|
|
|
358
369
|
|
|
359
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";
|
|
360
371
|
|
|
361
|
-
var version = "8.
|
|
372
|
+
var version = "8.15.1";
|
|
362
373
|
var packageInfo = {
|
|
363
374
|
version: version};
|
|
364
375
|
|
|
@@ -378,7 +389,9 @@ class MathType extends Plugin {
|
|
|
378
389
|
const integration = this._addIntegration();
|
|
379
390
|
currentInstance = integration;
|
|
380
391
|
// Add the MathType and ChemType commands to the editor
|
|
381
|
-
this._addCommands();
|
|
392
|
+
this._addCommands(integration);
|
|
393
|
+
// Add the track changes feature integration
|
|
394
|
+
this._addTrackChangesIntegration(integration);
|
|
382
395
|
// Add the buttons for MathType and ChemType
|
|
383
396
|
this._addViews(integration);
|
|
384
397
|
// Registers the <mathml> element in the schema
|
|
@@ -698,7 +711,8 @@ class MathType extends Plugin {
|
|
|
698
711
|
imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);
|
|
699
712
|
} else if (formula) {
|
|
700
713
|
const mathString = formula.replaceAll('ref="<"', 'ref="<"');
|
|
701
|
-
const
|
|
714
|
+
const lang = integration?.getLanguage() || "en"; // Safe fallback to 'en' in case integration is undefined.
|
|
715
|
+
const imgHtml = Parser.initParse(mathString, lang);
|
|
702
716
|
imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);
|
|
703
717
|
// Add HTML element (<img>) to model
|
|
704
718
|
viewWriter.setAttribute("htmlContent", imgHtml, modelItem);
|
|
@@ -756,13 +770,63 @@ class MathType extends Plugin {
|
|
|
756
770
|
editor.editing.mapper.on("viewToModelPosition", viewToModelPositionOutsideModelElement(editor.model, (viewElement)=>viewElement.hasClass("ck-math-widget")));
|
|
757
771
|
// Keep a reference to the original get and set function.
|
|
758
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
|
+
}
|
|
759
787
|
/**
|
|
760
|
-
*
|
|
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.
|
|
761
797
|
*/ editor.data.on("get", (e)=>{
|
|
762
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
|
|
763
827
|
const parsedResult = Parser.endParse(output);
|
|
764
|
-
//
|
|
765
|
-
//
|
|
828
|
+
// Remove all semantic annotations (including handwritten data points)
|
|
829
|
+
// to ensure clean, standard MathML format for storage
|
|
766
830
|
e.return = MathML.removeSafeXMLSemantics(parsedResult);
|
|
767
831
|
}, {
|
|
768
832
|
priority: "low"
|
|
@@ -818,6 +882,18 @@ class MathType extends Plugin {
|
|
|
818
882
|
Latex
|
|
819
883
|
};
|
|
820
884
|
}
|
|
885
|
+
_addTrackChangesIntegration(integration) {
|
|
886
|
+
const { editor } = this;
|
|
887
|
+
if (editor.plugins.has("TrackChangesEditing")) {
|
|
888
|
+
const trackChangesEditing = editor.plugins.get("TrackChangesEditing");
|
|
889
|
+
// Makes MathType and ChemType buttons available when editor is in the track changes mode
|
|
890
|
+
trackChangesEditing.enableCommand("MathType");
|
|
891
|
+
trackChangesEditing.enableCommand("ChemType");
|
|
892
|
+
// Adds custom label replacing the default 'mathml'.
|
|
893
|
+
// Handles both singular and plural forms.
|
|
894
|
+
trackChangesEditing.descriptionFactory.registerElementLabel("mathml", (quantity)=>(quantity > 1 ? `${quantity} ` : "") + StringManager.get(quantity > 1 ? "formulas" : "formula", integration?.getLanguage() || "en"));
|
|
895
|
+
}
|
|
896
|
+
}
|
|
821
897
|
}
|
|
822
898
|
|
|
823
899
|
export { CKEditor5Integration, ChemTypeCommand, MathTypeCommand, MathType as default };
|