@wiris/mathtype-ckeditor5 7.26.0 → 7.27.2

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,52 +1,44 @@
1
- {
2
- "name": "@wiris/mathtype-ckeditor5",
3
- "version": "7.26.0",
4
- "description": "MathType Web for CKEditor5 editor",
5
- "keywords": [
6
- "chem",
7
- "chemistry",
8
- "chemtype",
9
- "ckeditor",
10
- "ckeditor5",
11
- "editor",
12
- "equation",
13
- "latex",
14
- "math",
15
- "mathml",
16
- "maths",
17
- "mathtype",
18
- "wiris"
19
- ],
20
- "repository": "https://github.com/wiris/html-integrations/tree/stable/packages/mathtype-ckeditor5",
21
- "homepage": "http://www.wiris.com/",
22
- "bugs": {
23
- "email": "support@wiris.com"
24
- },
25
- "license": "MIT",
26
- "author": "WIRIS Team (http://www.wiris.com)",
27
- "files": [
28
- "/src",
29
- "icons",
30
- "theme",
31
- "lang"
32
- ],
33
- "main": "src/plugin.js",
34
- "scripts": {
35
- "compile": "node ../../scripts/services/compile src/plugin.js .",
36
- "test": "jest"
37
- },
38
- "dependencies": {
39
- "@ckeditor/ckeditor5-core": ">=23.0.0",
40
- "@ckeditor/ckeditor5-engine": ">=23.0.0",
41
- "@ckeditor/ckeditor5-ui": ">=23.0.0",
42
- "@ckeditor/ckeditor5-widget": ">=23.0.0",
43
- "@wiris/mathtype-html-integration-devkit": "1.5.0"
44
- },
45
- "devDependencies": {
46
- "babel-jest": "^26.1.0",
47
- "jest": "^26.1.0",
48
- "jest-css-modules-transform": "^4.0.1",
49
- "jest-html-reporter": "^3.1.3",
50
- "jest-raw-loader": "^1.0.1"
51
- }
52
- }
1
+ {
2
+ "name": "@wiris/mathtype-ckeditor5",
3
+ "version": "7.27.2",
4
+ "description": "MathType Web for CKEditor5 editor",
5
+ "keywords": [
6
+ "chem",
7
+ "chemistry",
8
+ "chemtype",
9
+ "ckeditor",
10
+ "ckeditor5",
11
+ "editor",
12
+ "equation",
13
+ "latex",
14
+ "math",
15
+ "mathml",
16
+ "maths",
17
+ "mathtype",
18
+ "wiris"
19
+ ],
20
+ "repository": "https://github.com/wiris/html-integrations/tree/stable/packages/mathtype-ckeditor5",
21
+ "homepage": "https://www.wiris.com/",
22
+ "bugs": {
23
+ "email": "support@wiris.com"
24
+ },
25
+ "license": "MIT",
26
+ "author": "WIRIS Team (http://www.wiris.com)",
27
+ "files": [
28
+ "/src",
29
+ "icons",
30
+ "theme",
31
+ "lang"
32
+ ],
33
+ "main": "src/plugin.js",
34
+ "scripts": {
35
+ "compile": "node ../../scripts/services/compile src/plugin.js ."
36
+ },
37
+ "dependencies": {
38
+ "@ckeditor/ckeditor5-core": ">=23.0.0",
39
+ "@ckeditor/ckeditor5-engine": ">=23.0.0",
40
+ "@ckeditor/ckeditor5-ui": ">=23.0.0",
41
+ "@ckeditor/ckeditor5-widget": ">=23.0.0",
42
+ "@wiris/mathtype-html-integration-devkit": "1.6.1"
43
+ }
44
+ }
package/src/commands.js CHANGED
@@ -1,99 +1,90 @@
1
+ /* eslint-disable max-classes-per-file */
1
2
  import Command from '@ckeditor/ckeditor5-core/src/command';
2
-
3
3
  import CKEditor5Integration from './integration';
4
4
 
5
-
6
5
  /**
7
6
  * Command for opening the MathType editor
8
7
  */
9
8
  export class MathTypeCommand extends Command {
10
-
11
- constructor( editor ) {
12
- super( editor );
9
+ execute(options = {}) {
10
+ // Check we get a valid integration
11
+ // eslint-disable-next-line no-prototype-builtins
12
+ if (!options.hasOwnProperty('integration') || !(options.integration instanceof CKEditor5Integration)) {
13
+ throw 'Must pass a valid CKEditor5Integration instance as attribute "integration" of options';
13
14
  }
14
15
 
15
- execute( options = {} ) {
16
-
17
- // Check we get a valid integration
18
- if ( !options.hasOwnProperty( 'integration' ) || !( options.integration instanceof CKEditor5Integration ) ) {
19
- throw 'Must pass a valid CKEditor5Integration instance as attribute "integration" of options';
20
- }
16
+ // Save the integration instance as a property of the command.
17
+ this.integration = options.integration;
21
18
 
22
- // Save the integration instance as a property of the command.
23
- this.integration = options.integration;
19
+ // Set custom editor or disable it
20
+ this.setEditor();
24
21
 
25
- // Set custom editor or disable it
26
- this.setEditor();
22
+ // Open the editor
23
+ this.openEditor();
24
+ }
27
25
 
28
- // Open the editor
29
- this.openEditor();
30
-
31
- }
32
-
33
- /**
26
+ /**
34
27
  * Sets the appropriate custom editor, if any, or disables them.
35
28
  */
36
- setEditor() {
37
- // It's possible that a custom editor was last used.
38
- // We need to disable it to avoid wrong behaviors.
39
- this.integration.core.getCustomEditors().disable();
40
- }
29
+ setEditor() {
30
+ // It's possible that a custom editor was last used.
31
+ // We need to disable it to avoid wrong behaviors.
32
+ this.integration.core.getCustomEditors().disable();
33
+ }
41
34
 
42
- /**
35
+ /**
43
36
  * Checks whether we are editing an existing formula or a new one and opens the editor.
44
37
  */
45
- openEditor() {
46
- const image = this._getSelectedImage();
47
- if ( typeof image !== 'undefined' && image !== null && image.classList.contains( WirisPlugin.Configuration.get( 'imageClassName' ) ) ) {
48
- this.integration.core.editionProperties.temporalImage = image;
49
- this.integration.openExistingFormulaEditor();
50
- } else {
51
- this.integration.openNewFormulaEditor();
52
- }
38
+ openEditor() {
39
+ const image = this._getSelectedImage();
40
+ if (typeof image !== 'undefined' && image !== null && image.classList.contains(WirisPlugin.Configuration.get('imageClassName'))) {
41
+ this.integration.core.editionProperties.temporalImage = image;
42
+ this.integration.openExistingFormulaEditor();
43
+ } else {
44
+ this.integration.openNewFormulaEditor();
53
45
  }
46
+ }
54
47
 
55
- /**
48
+ /**
56
49
  * Gets the currently selected formula image
57
50
  * @returns {Element} selected image, if any, undefined otherwise
58
51
  */
59
- _getSelectedImage() {
52
+ _getSelectedImage() {
53
+ const { selection } = this.editor.editing.view.document;
60
54
 
61
- const selection = this.editor.editing.view.document.selection;
62
-
63
- // If we can not extract the formula, fall back to default behavior.
64
- if ( selection.isCollapsed || selection.rangeCount !== 1 ) {
65
- return;
66
- }
67
-
68
- // Look for the <span> wrapping the formula and then for the <img/> inside
69
-
70
- const range = selection.getFirstRange();
55
+ // If we can not extract the formula, fall back to default behavior.
56
+ if (selection.isCollapsed || selection.rangeCount !== 1) {
57
+ return;
58
+ }
71
59
 
72
- let image;
60
+ // Look for the <span> wrapping the formula and then for the <img/> inside
73
61
 
74
- for ( const span of range ) {
75
- if ( span.item.name !== 'span' ) {
76
- return;
77
- }
78
- image = span.item.getChild( 0 );
79
- break;
80
- }
62
+ const range = selection.getFirstRange();
81
63
 
82
- if ( !image ) {
83
- return;
84
- }
64
+ let image;
85
65
 
86
- return this.editor.editing.view.domConverter.mapViewToDom( image );
66
+ for (const span of range) {
67
+ if (span.item.name !== 'span') {
68
+ return;
69
+ }
70
+ image = span.item.getChild(0);
71
+ break;
72
+ }
87
73
 
74
+ if (!image) {
75
+ return;
88
76
  }
89
77
 
78
+ // eslint-disable-next-line consistent-return
79
+ return this.editor.editing.view.domConverter.mapViewToDom(image);
80
+ }
90
81
  }
91
82
 
92
83
  /**
93
84
  * Command for opening the ChemType editor
94
85
  */
95
86
  export class ChemTypeCommand extends MathTypeCommand {
96
- setEditor() {
97
- this.integration.core.getCustomEditors().enable( 'chemistry' );
98
- }
99
- }
87
+ setEditor() {
88
+ this.integration.core.getCustomEditors().enable('chemistry');
89
+ }
90
+ }