@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 +44 -52
- package/src/commands.js +54 -63
- package/src/integration.js +268 -294
- package/src/plugin.js +419 -443
package/package.json
CHANGED
|
@@ -1,52 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@wiris/mathtype-ckeditor5",
|
|
3
|
-
"version": "7.
|
|
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": "
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
"@ckeditor/ckeditor5-
|
|
40
|
-
"@ckeditor/ckeditor5-
|
|
41
|
-
"@ckeditor/ckeditor5-
|
|
42
|
-
"@
|
|
43
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
|
|
19
|
+
// Set custom editor or disable it
|
|
20
|
+
this.setEditor();
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
// Open the editor
|
|
23
|
+
this.openEditor();
|
|
24
|
+
}
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
this.openEditor();
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
26
|
+
/**
|
|
34
27
|
* Sets the appropriate custom editor, if any, or disables them.
|
|
35
28
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
52
|
+
_getSelectedImage() {
|
|
53
|
+
const { selection } = this.editor.editing.view.document;
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
60
|
+
// Look for the <span> wrapping the formula and then for the <img/> inside
|
|
73
61
|
|
|
74
|
-
|
|
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
|
-
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
64
|
+
let image;
|
|
85
65
|
|
|
86
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
87
|
+
setEditor() {
|
|
88
|
+
this.integration.core.getCustomEditors().enable('chemistry');
|
|
89
|
+
}
|
|
90
|
+
}
|