@wiris/mathtype-ckeditor5 8.2.5 → 8.3.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/integration.js +42 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wiris/mathtype-ckeditor5",
3
- "version": "8.2.5",
3
+ "version": "8.3.0",
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.11.3"
42
+ "@wiris/mathtype-html-integration-devkit": "1.12.0"
43
43
  }
44
44
  }
@@ -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
- if (node.is('textProxy') && node.data === viewElement.data.replace(String.fromCharCode(160), ' ')) {
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
- const startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);
238
- const endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);
239
-
240
- const range = writer.createRange(
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
  });