@wiris/mathtype-ckeditor5 8.2.6 → 8.3.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/package.json +2 -2
- package/src/integration.js +42 -5
- package/src/plugin.js +8 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiris/mathtype-ckeditor5",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.1",
|
|
4
4
|
"description": "MathType Web for CKEditor5 editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chem",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
"@ckeditor/ckeditor5-engine": ">=23.0.0",
|
|
40
40
|
"@ckeditor/ckeditor5-ui": ">=23.0.0",
|
|
41
41
|
"@ckeditor/ckeditor5-widget": ">=23.0.0",
|
|
42
|
-
"@wiris/mathtype-html-integration-devkit": "1.
|
|
42
|
+
"@wiris/mathtype-html-integration-devkit": "1.12.1"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/integration.js
CHANGED
|
@@ -2,6 +2,7 @@ import IntegrationModel from '@wiris/mathtype-html-integration-devkit/src/integr
|
|
|
2
2
|
import Util from '@wiris/mathtype-html-integration-devkit/src/util';
|
|
3
3
|
import Configuration from '@wiris/mathtype-html-integration-devkit/src/configuration';
|
|
4
4
|
import Latex from '@wiris/mathtype-html-integration-devkit/src/latex';
|
|
5
|
+
import Parser from '@wiris/mathtype-html-integration-devkit/src/parser';
|
|
5
6
|
import MathML from '@wiris/mathtype-html-integration-devkit/src/mathml';
|
|
6
7
|
import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter';
|
|
7
8
|
|
|
@@ -211,7 +212,12 @@ export default class CKEditor5Integration extends IntegrationModel {
|
|
|
211
212
|
const range = this.editorObject.model.createRangeIn(element);
|
|
212
213
|
const descendants = Array.from(range.getItems());
|
|
213
214
|
for (const node of descendants) {
|
|
214
|
-
|
|
215
|
+
let viewElementData = viewElement.data;
|
|
216
|
+
if (viewElement.nodeType === 3) {
|
|
217
|
+
// Remove invisible white spaces
|
|
218
|
+
viewElementData = viewElementData.replaceAll(String.fromCharCode(8288), '')
|
|
219
|
+
}
|
|
220
|
+
if (node.is('textProxy') && node.data === viewElementData.replace(String.fromCharCode(160), ' ')) {
|
|
215
221
|
return node.textNode;
|
|
216
222
|
}
|
|
217
223
|
}
|
|
@@ -234,14 +240,45 @@ export default class CKEditor5Integration extends IntegrationModel {
|
|
|
234
240
|
const startNode = this.findText(latexRange.startContainer);
|
|
235
241
|
const endNode = this.findText(latexRange.endContainer);
|
|
236
242
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
243
|
+
let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);
|
|
244
|
+
let endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);
|
|
245
|
+
|
|
246
|
+
let range = writer.createRange(
|
|
241
247
|
startPosition,
|
|
242
248
|
endPosition,
|
|
243
249
|
);
|
|
244
250
|
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
// When Latex is next to image/formula.
|
|
254
|
+
if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {
|
|
255
|
+
// Get the position of the latex to be replaced.
|
|
256
|
+
let latexEdited = '$$' +(Latex.getLatexFromMathML(MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml))) + '$$';
|
|
257
|
+
let data = latexRange.startContainer.data;
|
|
258
|
+
|
|
259
|
+
// Remove invisible characters.
|
|
260
|
+
data = data.replaceAll(String.fromCharCode(8288), '')
|
|
261
|
+
|
|
262
|
+
// Get to the start of the latex we are editing.
|
|
263
|
+
let offset = data.indexOf(latexEdited);
|
|
264
|
+
let dataOffset = data.substring(offset);
|
|
265
|
+
let second$ = dataOffset.substring(2).indexOf("$$") + 4;
|
|
266
|
+
let substring = dataOffset.substr(0, second$);
|
|
267
|
+
data = data.replace(substring, '');
|
|
268
|
+
|
|
269
|
+
if (!data) {
|
|
270
|
+
startPosition = writer.createPositionBefore(startNode);
|
|
271
|
+
range = startNode;
|
|
272
|
+
} else {
|
|
273
|
+
startPosition = startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + offset);
|
|
274
|
+
endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + second$ + offset);
|
|
275
|
+
range = writer.createRange(
|
|
276
|
+
startPosition,
|
|
277
|
+
endPosition,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
245
282
|
writer.remove(range);
|
|
246
283
|
writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);
|
|
247
284
|
});
|
package/src/plugin.js
CHANGED
|
@@ -65,7 +65,7 @@ export default class MathType extends Plugin {
|
|
|
65
65
|
* Inherited from Plugin class: Executed when CKEditor5 is destroyed
|
|
66
66
|
*/
|
|
67
67
|
destroy() { // eslint-disable-line class-methods-use-this
|
|
68
|
-
currentInstance.
|
|
68
|
+
currentInstance.destroy();
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -366,10 +366,10 @@ export default class MathType extends Plugin {
|
|
|
366
366
|
});
|
|
367
367
|
|
|
368
368
|
/**
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
369
|
+
* Makes a copy of the given view node.
|
|
370
|
+
* @param {module:engine/view/node~Node} sourceNode Node to copy.
|
|
371
|
+
* @returns {module:engine/view/node~Node} Copy of the node.
|
|
372
|
+
*/
|
|
373
373
|
function clone(viewWriter, sourceNode) {
|
|
374
374
|
if (sourceNode.is('text')) {
|
|
375
375
|
return viewWriter.createText(sourceNode.data);
|
|
@@ -392,11 +392,6 @@ export default class MathType extends Plugin {
|
|
|
392
392
|
|
|
393
393
|
let mathString = Parser.endParseSaveMode(modelItem.getAttribute('formula'));
|
|
394
394
|
|
|
395
|
-
// Remove the traces from Hand. This code should be removed once PLUGINS-1307 is solved.
|
|
396
|
-
if (!Configuration.get('saveHandTraces')) {
|
|
397
|
-
mathString = MathML.removeAnnotation(mathString, 'application/json');
|
|
398
|
-
}
|
|
399
|
-
|
|
400
395
|
const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);
|
|
401
396
|
|
|
402
397
|
return clone(viewWriter, sourceMathElement);
|
|
@@ -412,11 +407,11 @@ export default class MathType extends Plugin {
|
|
|
412
407
|
const { get } = editor.data;
|
|
413
408
|
|
|
414
409
|
/**
|
|
415
|
-
|
|
416
|
-
|
|
410
|
+
* Hack to transform $$latex$$ into <math> in editor.getData()'s output.
|
|
411
|
+
*/
|
|
417
412
|
editor.data.get = (options) => {
|
|
418
413
|
const output = get.bind(editor.data)(options);
|
|
419
|
-
return Parser.endParse(output);
|
|
414
|
+
return Parser.endParse(MathML.mathMLEntities(output));
|
|
420
415
|
};
|
|
421
416
|
}
|
|
422
417
|
|