@wiris/mathtype-ckeditor5 8.11.1 → 8.13.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.
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ import Listeners from '@wiris/mathtype-html-integration-devkit/src/listeners.js'
12
12
  import MathML from '@wiris/mathtype-html-integration-devkit/src/mathml.js';
13
13
  import Latex from '@wiris/mathtype-html-integration-devkit/src/latex.js';
14
14
  import StringManager from '@wiris/mathtype-html-integration-devkit/src/stringmanager.js';
15
+ import '@wiris/mathtype-html-integration-devkit/src/md5.js';
15
16
  import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js';
16
17
 
17
18
  /**
@@ -218,15 +219,15 @@ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js'
218
219
  // When Latex is next to image/formula.
219
220
  if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {
220
221
  // Get the position of the latex to be replaced.
221
- let latexEdited = "$$" + Latex.getLatexFromMathML(MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml)) + "$$";
222
+ const latexEdited = `$$${Latex.getLatexFromMathML(MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml))}$$`;
222
223
  let data = latexRange.startContainer.data;
223
224
  // Remove invisible characters.
224
225
  data = data.replaceAll(String.fromCharCode(8288), "");
225
226
  // Get to the start of the latex we are editing.
226
- let offset = data.indexOf(latexEdited);
227
- let dataOffset = data.substring(offset);
228
- let second$ = dataOffset.substring(2).indexOf("$$") + 4;
229
- let substring = dataOffset.substr(0, second$);
227
+ const offset = data.indexOf(latexEdited);
228
+ const dataOffset = data.substring(offset);
229
+ const second$ = dataOffset.substring(2).indexOf("$$") + 4;
230
+ const substring = dataOffset.substr(0, second$);
230
231
  data = data.replace(substring, "");
231
232
  if (!data) {
232
233
  startPosition = writer.createPositionBefore(startNode);
@@ -252,7 +253,7 @@ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter.js'
252
253
  }
253
254
  }
254
255
  // Build the telemeter payload separated to delete null/undefined entries.
255
- let payload = {
256
+ const payload = {
256
257
  mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,
257
258
  mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,
258
259
  elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,
@@ -358,82 +359,9 @@ var mathIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adob
358
359
 
359
360
  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
361
 
361
- var name = "@wiris/mathtype-ckeditor5";
362
- var version = "8.11.1";
363
- var description = "MathType Web for CKEditor5 editor";
364
- var keywords = [
365
- "chem",
366
- "chemistry",
367
- "chemtype",
368
- "ckeditor",
369
- "ckeditor5",
370
- "editor",
371
- "equation",
372
- "latex",
373
- "math",
374
- "mathml",
375
- "maths",
376
- "mathtype",
377
- "wiris"
378
- ];
379
- var repository = "https://github.com/wiris/html-integrations/tree/stable/packages/mathtype-ckeditor5";
380
- var homepage = "https://www.wiris.com/";
381
- var bugs = {
382
- email: "support@wiris.com"
383
- };
384
- var license = "MIT";
385
- var author = "WIRIS Team (http://www.wiris.com)";
386
- var files = [
387
- "dist",
388
- "src",
389
- "icons",
390
- "theme",
391
- "lang"
392
- ];
393
- var main = "src/plugin.js";
394
- var type = "module";
395
- var exports = {
396
- ".": "./src/plugin.js",
397
- "./dist/*": "./dist/*",
398
- "./browser/*": null,
399
- "./src/*": "./src/*",
400
- "./theme/*": "./theme/*",
401
- "./package.json": "./package.json"
402
- };
403
- var scripts = {
404
- build: "node ./scripts/build-dist.mjs",
405
- "build:dist": "node ./scripts/build-dist.mjs",
406
- prepare: "npm run build:dist"
407
- };
408
- var dependencies = {
409
- "@wiris/mathtype-html-integration-devkit": "1.17.5"
410
- };
411
- var devDependencies = {
412
- "@ckeditor/ckeditor5-dev-build-tools": "^42.1.0",
413
- ckeditor5: ">=43.0.0"
414
- };
415
- var peerDependencies = {
416
- ckeditor5: ">=43.0.0"
417
- };
362
+ var version = "8.13.0";
418
363
  var packageInfo = {
419
- name: name,
420
- version: version,
421
- description: description,
422
- keywords: keywords,
423
- repository: repository,
424
- homepage: homepage,
425
- bugs: bugs,
426
- license: license,
427
- author: author,
428
- files: files,
429
- main: main,
430
- type: type,
431
- exports: exports,
432
- scripts: scripts,
433
- dependencies: dependencies,
434
- devDependencies: devDependencies,
435
- peerDependencies: peerDependencies
436
- };
364
+ version: version};
437
365
 
438
366
  // CKEditor imports
439
367
  let currentInstance = null; // eslint-disable-line import/no-mutable-exports
@@ -465,7 +393,7 @@ class MathType extends Plugin {
465
393
  * Inherited from Plugin class: Executed when CKEditor5 is destroyed
466
394
  */ destroy() {
467
395
  // eslint-disable-line class-methods-use-this
468
- currentInstance.destroy();
396
+ currentInstance?.destroy();
469
397
  }
470
398
  /**
471
399
  * Create the MathType API Integration object
@@ -489,7 +417,7 @@ class MathType extends Plugin {
489
417
  integrationProperties.managesLanguage = true;
490
418
  // etc
491
419
  // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.
492
- // To avoid a wrong behaviour, this integration only starts if the workspace container exists.
420
+ // To avoid a wrong behavior, this integration only starts if the workspace container exists.
493
421
  let integration;
494
422
  if (integrationProperties.target) {
495
423
  // Instance of the integration associated to this editor instance
@@ -671,7 +599,7 @@ class MathType extends Plugin {
671
599
  const mathAttributes = [
672
600
  ...viewItem.getAttributes()
673
601
  ].map(([key, value])=>` ${key}="${value}"`).join("");
674
- let htmlContent = Util.htmlSanitize(`<img${mathAttributes}>`);
602
+ const htmlContent = Util.htmlSanitize(`<img${mathAttributes}>`);
675
603
  const modelNode = writer.createElement("mathml", {
676
604
  htmlContent
677
605
  });
@@ -748,9 +676,9 @@ class MathType extends Plugin {
748
676
  viewWriter.setAttribute("htmlContent", imgHtml, modelItem);
749
677
  }
750
678
  /* Although we use the HtmlDataProcessor to obtain the attributes,
751
- * we must create a new EmptyElement which is independent of the
752
- * DataProcessor being used by this editor instance
753
- */ if (imgElement) {
679
+ * we must create a new EmptyElement which is independent of the
680
+ * DataProcessor being used by this editor instance
681
+ */ if (imgElement) {
754
682
  return viewWriter.createEmptyElement("img", imgElement.getAttributes(), {
755
683
  renderUnsafeAttributes: [
756
684
  "src"
@@ -792,18 +720,18 @@ class MathType extends Plugin {
792
720
  function createDataString(modelItem, { writer: viewWriter }) {
793
721
  const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);
794
722
  // Load img element
795
- let mathString = modelItem.getAttribute("htmlContent");
723
+ const mathString = modelItem.getAttribute("htmlContent") || Parser.endParseSaveMode(modelItem.getAttribute("formula"));
796
724
  const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);
797
725
  return clone(viewWriter, sourceMathElement);
798
726
  }
799
727
  // This stops the view selection getting into the <span>s and messing up caret movement
800
728
  editor.editing.mapper.on("viewToModelPosition", viewToModelPositionOutsideModelElement(editor.model, (viewElement)=>viewElement.hasClass("ck-math-widget")));
801
729
  // Keep a reference to the original get and set function.
802
- editor.data;
730
+ const { get, set } = editor.data;
803
731
  /**
804
732
  * Hack to transform $$latex$$ into <math> in editor.getData()'s output.
805
733
  */ editor.data.on("get", (e)=>{
806
- let output = e.return;
734
+ const output = e.return;
807
735
  const parsedResult = Parser.endParse(output);
808
736
  // Cleans all the semantics tag for safexml
809
737
  // including the handwritten data points
@@ -828,14 +756,14 @@ class MathType extends Plugin {
828
756
  formulas.forEach((formula)=>{
829
757
  if (formula.includes('encoding="LaTeX"')) {
830
758
  // LaTeX found.
831
- let latex = "$$$" + Latex.getLatexFromMathML(formula) + "$$$"; // We add $$$ instead of $$ because the replace function ignores one $.
759
+ const latex = `$$$${Latex.getLatexFromMathML(formula)}$$$`; // We add $$$ instead of $$ because the replace function ignores one $.
832
760
  modifiedData = modifiedData.replace(formula, latex);
833
761
  } else if (formula.includes("<img")) {
834
762
  // If we found a formula image, we should find MathML data, and then substitute the entire image.
835
763
  const regexp = /«math\b[^»]*»(.*?)«\/math»/g;
836
764
  const safexml = formula.match(regexp);
837
765
  if (safexml !== null) {
838
- let decodeXML = MathML.safeXmlDecode(safexml[0]);
766
+ const decodeXML = MathML.safeXmlDecode(safexml[0]);
839
767
  modifiedData = modifiedData.replace(formula, decodeXML);
840
768
  }
841
769
  }
@@ -864,5 +792,5 @@ class MathType extends Plugin {
864
792
  }
865
793
  }
866
794
 
867
- export { MathType as default };
795
+ export { CKEditor5Integration, ChemTypeCommand, MathTypeCommand, MathType as default };
868
796
  //# sourceMappingURL=index.js.map