@wiris/mathtype-ckeditor5 8.1.1 → 8.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wiris/mathtype-ckeditor5",
3
- "version": "8.1.1",
3
+ "version": "8.2.0",
4
4
  "description": "MathType Web for CKEditor5 editor",
5
5
  "keywords": [
6
6
  "chem",
package/src/commands.js CHANGED
@@ -36,6 +36,7 @@ export class MathTypeCommand extends Command {
36
36
  * Checks whether we are editing an existing formula or a new one and opens the editor.
37
37
  */
38
38
  openEditor() {
39
+ this.integration.core.editionProperties.dbclick = false;
39
40
  const image = this._getSelectedImage();
40
41
  if (typeof image !== 'undefined' && image !== null && image.classList.contains(WirisPlugin.Configuration.get('imageClassName'))) {
41
42
  this.integration.core.editionProperties.temporalImage = image;
@@ -2,6 +2,8 @@ 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 MathML from '@wiris/mathtype-html-integration-devkit/src/mathml';
6
+ import Telemeter from '@wiris/mathtype-html-integration-devkit/src/telemeter';
5
7
 
6
8
  /**
7
9
  * This class represents the MathType integration for CKEditor5.
@@ -93,10 +95,11 @@ export default class CKEditor5Integration extends IntegrationModel {
93
95
  * @param {MouseEvent} event - event which trigger the handler.
94
96
  */
95
97
  doubleClickHandler(element, event) {
98
+ this.core.editionProperties.dbclick = true;
96
99
  if (this.editorObject.isReadOnly === false) {
97
100
  if (element.nodeName.toLowerCase() === 'img') {
98
101
  if (Util.containsClass(element, Configuration.get('imageClassName'))) {
99
- // Some plugins (image2, image) open a dialog on double click. On formulas
102
+ // Some plugins (image2, image) open a dialog on Double-click. On formulas
100
103
  // doubleclick event ends here.
101
104
  if (typeof event.stopPropagation !== 'undefined') { // old I.E compatibility.
102
105
  event.stopPropagation();
@@ -218,6 +221,7 @@ export default class CKEditor5Integration extends IntegrationModel {
218
221
  insertFormula(focusElement, windowTarget, mathml, wirisProperties) { // eslint-disable-line no-unused-vars
219
222
  const returnObject = {};
220
223
 
224
+ let mathmlOrigin;
221
225
  if (!mathml) {
222
226
  this.insertMathml('');
223
227
  } else if (this.core.editMode === 'latex') {
@@ -242,6 +246,7 @@ export default class CKEditor5Integration extends IntegrationModel {
242
246
  writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);
243
247
  });
244
248
  } else {
249
+ mathmlOrigin = this.core.editionProperties.temporalImage?.dataset.mathml;
245
250
  try {
246
251
  returnObject.node = this.editorObject.editing.view.domConverter.viewToDom(
247
252
  this.editorObject.editing.mapper.toViewElement(
@@ -256,10 +261,36 @@ export default class CKEditor5Integration extends IntegrationModel {
256
261
  }
257
262
  }
258
263
 
264
+ // Build the telemeter payload separated to delete null/undefined entries.
265
+ let payload = {
266
+ mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,
267
+ mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,
268
+ elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,
269
+ editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop
270
+ toolbar: this.core.modalDialog.contentManager.toolbar,
271
+ size: mathml?.length,
272
+ };
273
+
274
+ // Remove desired null keys.
275
+ Object.keys(payload).forEach(key => {
276
+ if (key === 'mathml_origin' || key === 'editor_origin') !payload[key] ? delete payload[key] : {}
277
+ });
278
+
279
+ try {
280
+ Telemeter.telemeter.track("INSERTED_FORMULA", {
281
+ ...payload,
282
+ });
283
+ } catch (err) {
284
+ console.error(err);
285
+ }
286
+
259
287
  /* Due to PLUGINS-1329, we add the onChange event to the CK4 insertFormula.
260
288
  We probably should add it here as well, but we should look further into how */
261
289
  // this.editorObject.fire('change');
262
290
 
291
+ // Remove temporal image of inserted formula
292
+ this.core.editionProperties.temporalImage = null;
293
+
263
294
  return returnObject;
264
295
  }
265
296
 
package/src/plugin.js CHANGED
@@ -27,6 +27,8 @@ import CKEditor5Integration from './integration';
27
27
  import mathIcon from '../theme/icons/formula.svg';
28
28
  import chemIcon from '../theme/icons/chem.svg';
29
29
 
30
+ import packageInfo from '../package.json';
31
+
30
32
  export let currentInstance = null; // eslint-disable-line import/no-mutable-exports
31
33
 
32
34
  export default class MathType extends Plugin {
@@ -81,6 +83,7 @@ export default class MathType extends Plugin {
81
83
  integrationProperties.environment = {};
82
84
  integrationProperties.environment.editor = 'CKEditor5';
83
85
  integrationProperties.environment.editorVersion = '5.x';
86
+ integrationProperties.version = packageInfo.version;
84
87
  integrationProperties.editorObject = editor;
85
88
  integrationProperties.serviceProviderProperties = {};
86
89
  integrationProperties.serviceProviderProperties.URI = 'https://www.wiris.net/demo/plugins/app';
@@ -102,7 +105,7 @@ export default class MathType extends Plugin {
102
105
  integration.checkElement();
103
106
 
104
107
  this.listenTo(editor.editing.view.document, 'click', (evt, data) => {
105
- // Is double click
108
+ // Is Double-click
106
109
  if (data.domEvent.detail === 2) {
107
110
  integration.doubleClickHandler(data.domTarget, data.domEvent);
108
111
  evt.stop();
@@ -185,7 +188,7 @@ export default class MathType extends Plugin {
185
188
  });
186
189
  }
187
190
 
188
- // Observer for the double click event
191
+ // Observer for the Double-click event
189
192
  editor.editing.view.addObserver(ClickObserver);
190
193
  }
191
194