@wiris/mathtype-tinymce6 7.31.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/README.md +95 -0
- package/editor_plugin.src.js +399 -0
- package/global.js +27 -0
- package/package.json +51 -0
- package/package.json.temp +51 -0
- package/plugin.min.js +1 -0
- package/webpack.config.js +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# MathType for TinyMCE V6
|
|
2
|
+
|
|
3
|
+
Type and handwrite mathematical notation with MathType.
|
|
4
|
+
|
|
5
|
+
Easily include quality math equations in your documents and digital content.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Install instructions](#install-instructions)
|
|
10
|
+
- [Known issues](#known-issues)
|
|
11
|
+
- [Services](#services)
|
|
12
|
+
- [Documentation](#documentation)
|
|
13
|
+
- [Displaying on Target Page](#displaying-on-target-page)
|
|
14
|
+
- [Privacy policy](#privacy-policy)
|
|
15
|
+
|
|
16
|
+
## Install instructions
|
|
17
|
+
|
|
18
|
+
1. Install the npm module:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @wiris/mathtype-tinymce6
|
|
22
|
+
```
|
|
23
|
+
> MathType is fully compatible with TinyMCE 6 from version 6.1.0.
|
|
24
|
+
|
|
25
|
+
2. Add the plugin as an external plugin:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
tinymce.init({
|
|
29
|
+
external_plugins: {
|
|
30
|
+
'tiny_mce_wiris': `node_modules/@wiris/mathtype-tinymce6/plugin.min.js`,
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
3. Add MathType buttons to the TinyMCE6 toolbar and the recommended settings:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
tinymce.init({
|
|
40
|
+
toolbar: 'tiny_mce_wiris_formulaEditor tiny_mce_wiris_formulaEditorChemistry',
|
|
41
|
+
// We recommend to set 'draggable_modal' to true to avoid overlapping issues
|
|
42
|
+
// with the different UI modal dialog windows implementations between core and third-party plugins on TinyMCE.
|
|
43
|
+
// @see: https://github.com/wiris/html-integrations/issues/134#issuecomment-905448642
|
|
44
|
+
draggable_modal: true,
|
|
45
|
+
|
|
46
|
+
// This option allows you to introduce mathml formulas with wiris plugins.
|
|
47
|
+
// Not enabling this, will provide formulas from beeing created and rendered.
|
|
48
|
+
extended_valid_elements: '*[.*]',
|
|
49
|
+
|
|
50
|
+
// You could set a different language for MathType editor:
|
|
51
|
+
// language: 'fr_FR',
|
|
52
|
+
// mathTypeParameters: {
|
|
53
|
+
// editorParameters: { language: 'fr' },
|
|
54
|
+
// },
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Notice the example assumes this directory structure:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
└───index.html
|
|
62
|
+
└───node_modules
|
|
63
|
+
└───@wiris/mathtype-tinymce6
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Known issues
|
|
67
|
+
|
|
68
|
+
* The editor's caret is lost when inserting a new formula on Safari with ChemType [#486](https://github.com/wiris/html-integrations/issues/486)
|
|
69
|
+
|
|
70
|
+
## Services
|
|
71
|
+
|
|
72
|
+
This npm module uses remotely hosted services to render MathML data. However, we recommend you install these services on your backend. This will allow you, among other things, to configure the service and to locally store the images generated by MathType.
|
|
73
|
+
|
|
74
|
+
The services are available for Java, PHP, .NET and Ruby on Rails. If you use any of these technologies, please download the plugin for your backend technology from [here](https://store.wiris.com/en/products/downloads/mathtype/integrations#froala3?utm_source=npmjs&utm_medium=referral).
|
|
75
|
+
|
|
76
|
+
## Displaying on Target Page
|
|
77
|
+
|
|
78
|
+
In order to display mathematical formulas on the target page, i.e. the page where content produced by the HTML editor will be visible, the target page needs to include the [MathType script](https://docs.wiris.com/en/mathtype/mathtype_web/integrations/mathml-mode#add_a_script_to_head). For example for the default setting this would be:
|
|
79
|
+
```html
|
|
80
|
+
<script src="https://www.wiris.net/demo/plugins/app/WIRISplugins.js?viewer=image"></script>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Documentation
|
|
84
|
+
|
|
85
|
+
To find out more information about MathType, please go to the following documentation:
|
|
86
|
+
|
|
87
|
+
* [Install instructions](https://docs.wiris.com/mathtype/en/mathtype-integrations/mathtype-for-html-editors/mathtype-for-tinymce.html?utm_source=npmjs&utm_medium=referral)
|
|
88
|
+
* [MathType documentation](https://docs.wiris.com/en/mathtype/mathtype_web/start?utm_source=npmjs&utm_medium=referral)
|
|
89
|
+
* [Introductory tutorials](https://docs.wiris.com/en/mathtype/mathtype_web/intro_tutorials?utm_source=npmjs&utm_medium=referral)
|
|
90
|
+
* [Service customization](https://docs.wiris.com/en/mathtype/mathtype_web/integrations/config-table?utm_source=npmjs&utm_medium=referral)
|
|
91
|
+
* [Testing](https://docs.wiris.com/en/mathtype/mathtype_web/integrations/html/plugins-test?utm_source=npmjs&utm_medium=referral)
|
|
92
|
+
|
|
93
|
+
## Privacy policy
|
|
94
|
+
|
|
95
|
+
The [MathType Privacy Policy](https://www.wiris.com/en/mathtype-privacy-policy/?utm_source=npmjs&utm_medium=referral) covers the data processing operations for the MathType users. It is an addendum of the company’s general Privacy Policy and the [general Privacy Policy](https://www.wiris.com/en/privacy-policy?utm_source=npmjs&utm_medium=referral) still applies to MathType users.
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import IntegrationModel from '@wiris/mathtype-html-integration-devkit/src/integrationmodel';
|
|
2
|
+
import Configuration from '@wiris/mathtype-html-integration-devkit/src/configuration';
|
|
3
|
+
import Parser from '@wiris/mathtype-html-integration-devkit/src/parser';
|
|
4
|
+
import Util from '@wiris/mathtype-html-integration-devkit/src/util';
|
|
5
|
+
import Listeners from '@wiris/mathtype-html-integration-devkit/src/listeners';
|
|
6
|
+
|
|
7
|
+
import packageInfo from './package.json';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* TinyMCE integration class. This class extends IntegrationModel class.
|
|
11
|
+
*/
|
|
12
|
+
export class TinyMceIntegration extends IntegrationModel {
|
|
13
|
+
constructor(integrationModelProperties) {
|
|
14
|
+
super(integrationModelProperties);
|
|
15
|
+
/**
|
|
16
|
+
* Indicates if the content of the TinyMCe editor has
|
|
17
|
+
* been parsed.
|
|
18
|
+
* @type {Boolean}
|
|
19
|
+
*/
|
|
20
|
+
this.initParsed = integrationModelProperties.initParsed;
|
|
21
|
+
/**
|
|
22
|
+
* Indicates if the TinyMCE is integrated in Moodle.
|
|
23
|
+
* @type {Boolean}
|
|
24
|
+
*/
|
|
25
|
+
this.isMoodle = integrationModelProperties.isMoodle;
|
|
26
|
+
/**
|
|
27
|
+
* Indicates if the plugin is loaded as an external plugin by TinyMCE.
|
|
28
|
+
* @type {Boolean}
|
|
29
|
+
*/
|
|
30
|
+
this.isExternal = integrationModelProperties.isExternal;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns the absolute path of the integration script. Depends on
|
|
35
|
+
* TinyMCE integration (Moodle or standard).
|
|
36
|
+
* @returns {Boolean} - Absolute path for the integration script.
|
|
37
|
+
*/
|
|
38
|
+
getPath() {
|
|
39
|
+
if (this.isMoodle) {
|
|
40
|
+
// return '/lib/editor/tinymce/plugins/tiny_mce_wiris/tinymce/';
|
|
41
|
+
const search = 'lib/editor/tinymce';
|
|
42
|
+
const pos = tinymce.baseURL.indexOf(search);
|
|
43
|
+
const baseURL = tinymce.baseURL.substr(0, pos + search.length);
|
|
44
|
+
return `${baseURL}/plugins/tiny_mce_wiris/tinymce/`;
|
|
45
|
+
} if (this.isExternal) {
|
|
46
|
+
const externalUrl = this.editorObject.getParam('external_plugins').tiny_mce_wiris;
|
|
47
|
+
return externalUrl.substring(0, externalUrl.lastIndexOf('/') + 1);
|
|
48
|
+
}
|
|
49
|
+
return `${tinymce.baseURL}/plugins/tiny_mce_wiris/`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns the absolute path of plugin icons. A set of different
|
|
54
|
+
* icons is needed for TinyMCE and Moodle 2.5-
|
|
55
|
+
* @returns {String} - Absolute path of the icons folder.
|
|
56
|
+
*/
|
|
57
|
+
getIconsPath() {
|
|
58
|
+
if (this.isMoodle && Configuration.get('versionPlatform') < 2013111800) {
|
|
59
|
+
return `${this.getPath()}icons/tinymce3/`;
|
|
60
|
+
}
|
|
61
|
+
return `${this.getPath()}icons/`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns the integration language. TinyMCE language is inherited.
|
|
66
|
+
* When no language is set, TinyMCE sets the toolbar to english.
|
|
67
|
+
* @returns {String} - Integration language.
|
|
68
|
+
*/
|
|
69
|
+
getLanguage() {
|
|
70
|
+
const editorSettings = this.editorObject;
|
|
71
|
+
try {
|
|
72
|
+
return editorSettings.mathTypeParameters.editorParameters.language;
|
|
73
|
+
} catch (e) { console.error(); }
|
|
74
|
+
// Get the deprecated wirisformulaeditorlang
|
|
75
|
+
if (editorSettings.wirisformulaeditorlang) {
|
|
76
|
+
console.warn('Deprecated property wirisformulaeditorlang. Use mathTypeParameters on instead.');
|
|
77
|
+
return editorSettings.wirisformulaeditorlang;
|
|
78
|
+
}
|
|
79
|
+
const langParam = this.editorObject.getParam('language');
|
|
80
|
+
return langParam || super.getLanguage();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Callback function called before 'onTargetLoad' is fired. All the logic here is to
|
|
85
|
+
* avoid TinyMCE change MathType formulas.
|
|
86
|
+
*/
|
|
87
|
+
callbackFunction() {
|
|
88
|
+
const dataImgFiltered = [];
|
|
89
|
+
super.callbackFunction();
|
|
90
|
+
|
|
91
|
+
// Avoid to change class of image formulas.
|
|
92
|
+
const imageClassName = Configuration.get('imageClassName');
|
|
93
|
+
if (this.isIframe) {
|
|
94
|
+
// Attaching observers to wiris images.
|
|
95
|
+
if (typeof Parser.observer !== 'undefined') {
|
|
96
|
+
Array.prototype.forEach.call(this.target.contentDocument.getElementsByClassName(imageClassName), (wirisImages) => {
|
|
97
|
+
Parser.observer.observe(wirisImages);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
} else { // Inline.
|
|
101
|
+
// Attaching observers to wiris images.
|
|
102
|
+
Array.prototype.forEach.call(document.getElementsByClassName(imageClassName), (wirisImages) => {
|
|
103
|
+
Parser.observer.observe(wirisImages);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// When a formula is updated TinyMCE 'Change' event must be fired.
|
|
108
|
+
// See https://www.tiny.cloud/docs/advanced/events/#change for further information.
|
|
109
|
+
const listener = Listeners.newListener('onAfterFormulaInsertion', () => {
|
|
110
|
+
if (typeof this.editorObject.fire !== 'undefined') {
|
|
111
|
+
this.editorObject.fire('Change');
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
this.getCore().addListener(listener);
|
|
115
|
+
|
|
116
|
+
// Deprecated part on TinyMCE6; We need to find a workaround
|
|
117
|
+
// Avoid filter formulas with performance enabled.
|
|
118
|
+
dataImgFiltered[this.editorObject.id] = this.editorObject.images_dataimg_filter;
|
|
119
|
+
this.editorObject.images_dataimg_filter = (img) => {
|
|
120
|
+
if (img.hasAttribute('class') && img.getAttribute('class').indexOf(Configuration.get('imageClassName')) !== -1) {
|
|
121
|
+
return img.hasAttribute('internal-blob');
|
|
122
|
+
}
|
|
123
|
+
// If the client put an image data filter, run. Otherwise default behaviour (put blob).
|
|
124
|
+
if (typeof dataImgFiltered[this.editorObject.id] !== 'undefined') {
|
|
125
|
+
return dataImgFiltered[this.editorObject.id](img);
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Fires the event ExecCommand and transform a MathML into an image formula.
|
|
133
|
+
* @param {string} mathml - MathML to generate the formula and can be caught with the event.
|
|
134
|
+
*/
|
|
135
|
+
updateFormula(mathml) {
|
|
136
|
+
if (typeof this.editorObject.fire !== 'undefined') {
|
|
137
|
+
this.editorObject.fire('ExecCommand', { command: 'updateFormula', value: mathml });
|
|
138
|
+
}
|
|
139
|
+
super.updateFormula(mathml);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Object containing all TinyMCE integration instances. One for each TinyMCE editor.
|
|
145
|
+
* @type {Object}
|
|
146
|
+
*/
|
|
147
|
+
export const instances = {};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* TinyMCE integration current instance. The current instance
|
|
151
|
+
* is the instance related with the focused editor.
|
|
152
|
+
* @type {TinyMceIntegration}
|
|
153
|
+
*/
|
|
154
|
+
export const currentInstance = null;
|
|
155
|
+
|
|
156
|
+
/*
|
|
157
|
+
Note: We have included the plugin in the same JavaScript file as the TinyMCE
|
|
158
|
+
instance for display purposes only. Tiny recommends not maintaining the plugin
|
|
159
|
+
with the TinyMCE instance and using the `external_plugins` option.
|
|
160
|
+
*/
|
|
161
|
+
(function () {
|
|
162
|
+
tinymce.PluginManager.add('tiny_mce_wiris', (editor, url) => ({ // eslint-disable-line no-unused-vars
|
|
163
|
+
init(editor) {
|
|
164
|
+
const callbackMethodArguments = {};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Integration model properties
|
|
168
|
+
* @type {Object}
|
|
169
|
+
* @property {Object} target - Integration DOM target.
|
|
170
|
+
* @property {String} configurationService - Configuration integration service.
|
|
171
|
+
* @property {String} version - Plugin version.
|
|
172
|
+
* @property {String} scriptName - Integration script name.
|
|
173
|
+
* @property {Object} environment - Integration environment properties.
|
|
174
|
+
* @property {String} editor - Editor name.
|
|
175
|
+
*/
|
|
176
|
+
const integrationModelProperties = {};
|
|
177
|
+
integrationModelProperties.serviceProviderProperties = {};
|
|
178
|
+
integrationModelProperties.serviceProviderProperties.URI = 'https://www.wiris.net/demo/plugins/app';
|
|
179
|
+
integrationModelProperties.serviceProviderProperties.server = 'java';
|
|
180
|
+
integrationModelProperties.version = packageInfo.version;
|
|
181
|
+
integrationModelProperties.isMoodle = (!!((typeof M === 'object' && M !== null))); // eslint-disable-line no-undef
|
|
182
|
+
if (integrationModelProperties.isMoodle) {
|
|
183
|
+
// eslint-disable-next-line no-undef
|
|
184
|
+
integrationModelProperties.configurationService = M.cfg.wwwroot + '/filter/wiris/integration/configurationjs.php'; // eslint-disable-line prefer-template
|
|
185
|
+
}
|
|
186
|
+
if (typeof (editor.getParam('wiriscontextpath')) !== 'undefined') {
|
|
187
|
+
integrationModelProperties.configurationService = Util.concatenateUrl(editor.getParam('wiriscontextpath'), integrationModelProperties.configurationService);
|
|
188
|
+
`${editor.getParam('wiriscontextpath')}/${integrationModelProperties.configurationService}`; // eslint-disable-line no-unused-expressions
|
|
189
|
+
console.warn('Deprecated property wiriscontextpath. Use mathTypeParameters on instead.', editor.opts.wiriscontextpath);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Overriding MathType integration parameters.
|
|
193
|
+
if (typeof (editor.getParam('mathTypeParameters')) !== 'undefined') {
|
|
194
|
+
integrationModelProperties.integrationParameters = editor.getParam('mathTypeParameters');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
integrationModelProperties.scriptName = 'plugin.min.js';
|
|
198
|
+
integrationModelProperties.environment = {};
|
|
199
|
+
|
|
200
|
+
integrationModelProperties.environment.editor = 'TinyMCE 6.x';
|
|
201
|
+
integrationModelProperties.environment.editorVersion = `${tinymce.majorVersion}.${tinymce.minorVersion}`;
|
|
202
|
+
|
|
203
|
+
integrationModelProperties.callbackMethodArguments = callbackMethodArguments;
|
|
204
|
+
integrationModelProperties.editorObject = editor;
|
|
205
|
+
integrationModelProperties.initParsed = false;
|
|
206
|
+
// We need to create the instance before TinyMce initialization in order to register commands.
|
|
207
|
+
// However, as TinyMCE is not initialized at this point the HTML target is not created.
|
|
208
|
+
// Here we create the target as null and onInit object the target is updated.
|
|
209
|
+
integrationModelProperties.target = null;
|
|
210
|
+
const isExternalPlugin = typeof (editor.getParam('external_plugins')) !== 'undefined' && 'tiny_mce_wiris' in editor.getParam('external_plugins');
|
|
211
|
+
integrationModelProperties.isExternal = isExternalPlugin;
|
|
212
|
+
integrationModelProperties.rtl = (editor.getParam('directionality') === 'rtl');
|
|
213
|
+
|
|
214
|
+
// GenericIntegration instance.
|
|
215
|
+
const tinyMceIntegrationInstance = new TinyMceIntegration(integrationModelProperties);
|
|
216
|
+
tinyMceIntegrationInstance.init();
|
|
217
|
+
WirisPlugin.instances[tinyMceIntegrationInstance.editorObject.id] = tinyMceIntegrationInstance;
|
|
218
|
+
WirisPlugin.currentInstance = tinyMceIntegrationInstance;
|
|
219
|
+
|
|
220
|
+
const onInit = function (editor) { // eslint-disable-line no-shadow
|
|
221
|
+
const integrationInstance = WirisPlugin.instances[tinyMceIntegrationInstance.editorObject.id];
|
|
222
|
+
if (!editor.inline) {
|
|
223
|
+
integrationInstance.setTarget(editor.getContentAreaContainer().firstChild);
|
|
224
|
+
} else {
|
|
225
|
+
integrationInstance.setTarget(editor.getElement());
|
|
226
|
+
}
|
|
227
|
+
integrationInstance.setEditorObject(editor);
|
|
228
|
+
integrationInstance.listeners.fire('onTargetReady', {});
|
|
229
|
+
if ('wiriseditorparameters' in editor) {
|
|
230
|
+
Configuration.update('editorParameters', editor.wiriseditorparameters);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Prevent TinyMCE attributes insertion.
|
|
234
|
+
// TinyMCE insert attributes only when a new node is inserted.
|
|
235
|
+
// For this reason, the mutation observer only acts on addedNodes.
|
|
236
|
+
const mutationInstance = new MutationObserver(function (editor, mutations) { // eslint-disable-line no-shadow
|
|
237
|
+
Array.prototype.forEach.call(mutations, function (editor, mutation) { // eslint-disable-line no-shadow
|
|
238
|
+
Array.prototype.forEach.call(mutation.addedNodes, function (editor, node) { // eslint-disable-line no-shadow
|
|
239
|
+
if (node.nodeType === 1) {
|
|
240
|
+
// Act only in our own formulas.
|
|
241
|
+
Array.prototype.forEach.call(node.querySelectorAll(`.${WirisPlugin.Configuration.get('imageClassName')}`), ((editor, image) => { // eslint-disable-line no-shadow
|
|
242
|
+
// This only is executed due to init parse.
|
|
243
|
+
image.removeAttribute('data-mce-src');
|
|
244
|
+
image.removeAttribute('data-mce-style');
|
|
245
|
+
}).bind(this, editor));
|
|
246
|
+
}
|
|
247
|
+
}.bind(this, editor));
|
|
248
|
+
}.bind(this, editor));
|
|
249
|
+
}.bind(this, editor));
|
|
250
|
+
mutationInstance.observe(editor.getBody(), {
|
|
251
|
+
attributes: true,
|
|
252
|
+
childList: true,
|
|
253
|
+
characterData: true,
|
|
254
|
+
subtree: true,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const content = editor.getContent();
|
|
258
|
+
// We set content in html because other tiny plugins need data-mce
|
|
259
|
+
// and this is not possible with raw format.
|
|
260
|
+
editor.setContent(Parser.initParse(content, editor.getParam('language')), { format: 'html' });
|
|
261
|
+
// This clean undoQueue for prevent onChange and Dirty state.
|
|
262
|
+
editor.undoManager.clear();
|
|
263
|
+
// Init parsing OK. If a setContent method is called
|
|
264
|
+
// wrs_initParse is called again.
|
|
265
|
+
// Now if source code is edited the returned code is parsed.
|
|
266
|
+
// PLUGINS-1070: We set this variable out of condition to parse content after.
|
|
267
|
+
WirisPlugin.instances[editor.id].initParsed = true;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
if ('onInit' in editor) {
|
|
271
|
+
editor.onInit.add(onInit);
|
|
272
|
+
} else {
|
|
273
|
+
editor.on('init', () => {
|
|
274
|
+
onInit(editor);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if ('onActivate' in editor) {
|
|
279
|
+
editor.onActivate.add((editor) => { // eslint-disable-line no-unused-vars, no-shadow
|
|
280
|
+
WirisPlugin.currentInstance = WirisPlugin.instances[tinymce.activeEditor.id];
|
|
281
|
+
});
|
|
282
|
+
} else {
|
|
283
|
+
editor.on('focus', (event) => { // eslint-disable-line no-unused-vars, no-shadow
|
|
284
|
+
WirisPlugin.currentInstance = WirisPlugin.instances[tinymce.activeEditor.id];
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const onSave = function (editor, params) { // eslint-disable-line no-shadow
|
|
289
|
+
params.content = Parser.endParse(params.content, editor.getParam('language'));
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
if ('onSaveContent' in editor) {
|
|
293
|
+
editor.onSaveContent.add(onSave);
|
|
294
|
+
} else {
|
|
295
|
+
editor.on('saveContent', (params) => {
|
|
296
|
+
onSave(editor, params);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if ('onGetContent' in editor) {
|
|
301
|
+
editor.onGetContent.add(onSave);
|
|
302
|
+
} else {
|
|
303
|
+
editor.on('getContent', (params) => {
|
|
304
|
+
onSave(editor, params);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if ('onBeforeSetContent' in editor) {
|
|
309
|
+
editor.onBeforeSetContent.add((e, params) => {
|
|
310
|
+
if (WirisPlugin.instances[editor.id].initParsed) {
|
|
311
|
+
params.content = Parser.initParse(params.content, editor.getParam('language'));
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
editor.on('beforeSetContent', (params) => {
|
|
316
|
+
if (WirisPlugin.instances[editor.id].initParsed) {
|
|
317
|
+
params.content = Parser.initParse(params.content, editor.getParam('language'));
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function openFormulaEditorFunction() {
|
|
323
|
+
const tinyMceIntegrationInstance = WirisPlugin.instances[editor.id]; // eslint-disable-line no-shadow
|
|
324
|
+
// Disable previous custom editors.
|
|
325
|
+
tinyMceIntegrationInstance.core.getCustomEditors().disable();
|
|
326
|
+
tinyMceIntegrationInstance.openNewFormulaEditor();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const commonEditor = editor.ui.registry;
|
|
330
|
+
const mathTypeIcon = 'mathtypeicon';
|
|
331
|
+
const chemTypeIcon = 'chemtypeicon';
|
|
332
|
+
const mathTypeIconSvg = '<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"viewBox="0 0 300 261.7" style="enable-background:new 0 0 300 261.7;" xml:space="preserve"><g id=icon-wirisformula stroke="none" stroke-width="1" fill-rule="evenodd"><g><path class="st1" d="M90.2,257.7c-11.4,0-21.9-6.4-27-16.7l-60-119.9c-7.5-14.9-1.4-33.1,13.5-40.5c14.9-7.5,33.1-1.4,40.5,13.5l27.3,54.7L121.1,39c5.3-15.8,22.4-24.4,38.2-19.1c15.8,5.3,24.4,22.4,19.1,38.2l-59.6,179c-3.9,11.6-14.3,19.7-26.5,20.6C91.6,257.7,90.9,257.7,90.2,257.7"/></g></g><g><g><path class="st2" d="M300,32.8c0-16.4-13.4-29.7-29.9-29.7c-2.9,0-7.2,0.8-7.2,0.8c-37.9,9.1-71.3,14-112,14c-0.3,0-0.6,0-1,0c-16.5,0-29.9,13.3-29.9,29.7c0,16.4,13.4,29.7,29.9,29.7l0,0c45.3,0,83.1-5.3,125.3-15.3h0C289.3,59.5,300,47.4,300,32.8"/></g></g></svg>'; // eslint-disable-line max-len
|
|
333
|
+
const chemTypeIconSvg = '<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve"> <image id="image0" width="16" height="16" x="0" y="0"href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfiChwSIwERK9BGAAABfklEQVQoz12RvUtbcRiFn/uRXKNJNCJSokFFqoKDIjHEqKA4WRAc/AsUKl2Ck5ODIKKDm4v+BbqIEr8WQ+hgQSgOElGJgkPTih+3tUabeL3353A1CX3Hcx7OC+dIAIL3CwXEmJU6XBHWuyIVgIjrOcoUblCTrolE/D+gc0QsUJePEtrGh+jajzcg1GQu0W87ldl7zZQAtPP9Dh5lADNm25rx+Xb7ZdWMCAARyHXhVQD8iwAD+qLV61B++U4Hb5pKS9Tx3w05Umr+K3Mlsk6SfY7x9oX7OvDiwlEEoLPLNkdc4yRJG9WkuCoCxBV7JMhg8cgRl7h44m9xwhM3PLyVYnBni3LBX64p4MHGYLSzOV9UWDd8AO608iW+2eP5NyVN4JR/7rRU2T0MzVRmATI197FIInsmTeIErcwTxqcAxHPDFdLHE4cJmPV4AAKZ+XStyrkCMC00K8Qnj+6+kAFKjfE/sw6/zAXf7bFUqmill+5v7es+vzVqlhukOWCLr6/ZMH/PRaOKYwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxOC0xMC0yOVQwMTozNTowMS0wNzowMOC+eEAAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTgtMTAtMjlUMDE6MzU6MDEtMDc6MDCR48D8AAAAAElFTkSuQmCC" /></svg>'; // eslint-disable-line max-len
|
|
334
|
+
|
|
335
|
+
commonEditor.addIcon(mathTypeIcon, mathTypeIconSvg);
|
|
336
|
+
commonEditor.addIcon(chemTypeIcon, chemTypeIconSvg);
|
|
337
|
+
|
|
338
|
+
// The next two blocks create menu items to give the possibility
|
|
339
|
+
// of add MathType in the menubar.
|
|
340
|
+
commonEditor.addMenuItem('tiny_mce_wiris_formulaEditor', {
|
|
341
|
+
text: 'MathType',
|
|
342
|
+
icon: mathTypeIcon,
|
|
343
|
+
onAction: openFormulaEditorFunction,
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// Dynamic customEditors buttons.
|
|
347
|
+
const customEditors = WirisPlugin.instances[editor.id].getCore().getCustomEditors();
|
|
348
|
+
Object.keys(customEditors.editors).forEach((customEditor) => {
|
|
349
|
+
if (customEditors.editors[customEditor].confVariable) {
|
|
350
|
+
commonEditor.addMenuItem(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
351
|
+
text: customEditors.editors[customEditor].title,
|
|
352
|
+
icon: chemTypeIcon, // Parametrize when other custom editors are added.
|
|
353
|
+
onAction: () => {
|
|
354
|
+
customEditors.enable(customEditor);
|
|
355
|
+
WirisPlugin.instances[editor.id].openNewFormulaEditor();
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// MathType button.
|
|
362
|
+
commonEditor.addButton('tiny_mce_wiris_formulaEditor', {
|
|
363
|
+
tooltip: 'Insert a math equation - MathType',
|
|
364
|
+
image: `${WirisPlugin.instances[editor.id].getIconsPath()}formula.png`,
|
|
365
|
+
onAction: openFormulaEditorFunction,
|
|
366
|
+
icon: mathTypeIcon,
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// Dynamic customEditors buttons.
|
|
370
|
+
for (const customEditor in customEditors.editors) {
|
|
371
|
+
if (customEditors.editors[customEditor].confVariable) {
|
|
372
|
+
const cmd = `tiny_mce_wiris_openFormulaEditor${customEditors.editors[customEditor].name}`;
|
|
373
|
+
// eslint-disable-next-line no-inner-declarations, no-loop-func
|
|
374
|
+
function commandFunction() {
|
|
375
|
+
customEditors.enable(customEditor);
|
|
376
|
+
WirisPlugin.instances[editor.id].openNewFormulaEditor(); // eslint-disable-line no-undef
|
|
377
|
+
}
|
|
378
|
+
editor.addCommand(cmd, commandFunction);
|
|
379
|
+
commonEditor.addButton(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
380
|
+
tooltip: customEditors.editors[customEditor].tooltip,
|
|
381
|
+
onAction: commandFunction,
|
|
382
|
+
image: WirisPlugin.instances[editor.id].getIconsPath() + customEditors.editors[customEditor].icon,
|
|
383
|
+
icon: chemTypeIcon, // At the moment only chemTypeIcon because of the provisional solution for TinyMCE6.
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
|
|
389
|
+
// All versions.
|
|
390
|
+
getMetadata() {
|
|
391
|
+
return {
|
|
392
|
+
longname: 'tiny_mce_wiris',
|
|
393
|
+
name: 'Maths for More',
|
|
394
|
+
url: 'http://www.wiris.com',
|
|
395
|
+
version: packageInfo.version,
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
}));
|
|
399
|
+
}());
|
package/global.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Core from '@wiris/mathtype-html-integration-devkit/src/core.src';
|
|
2
|
+
import Parser from '@wiris/mathtype-html-integration-devkit/src/parser';
|
|
3
|
+
import Util from '@wiris/mathtype-html-integration-devkit/src/util';
|
|
4
|
+
import Image from '@wiris/mathtype-html-integration-devkit/src/image';
|
|
5
|
+
import Configuration from '@wiris/mathtype-html-integration-devkit/src/configuration';
|
|
6
|
+
import Listeners from '@wiris/mathtype-html-integration-devkit/src/listeners';
|
|
7
|
+
import IntegrationModel from '@wiris/mathtype-html-integration-devkit/src/integrationmodel';
|
|
8
|
+
import Latex from '@wiris/mathtype-html-integration-devkit/src/latex';
|
|
9
|
+
import '@wiris/mathtype-html-integration-devkit/src/backwardslib';
|
|
10
|
+
import Test from '@wiris/mathtype-html-integration-devkit/src/test';
|
|
11
|
+
import { TinyMceIntegration, currentInstance, instances } from './editor_plugin.src';
|
|
12
|
+
|
|
13
|
+
// Expose WirisPlugin variable to the window.
|
|
14
|
+
window.WirisPlugin = {
|
|
15
|
+
Core,
|
|
16
|
+
Parser,
|
|
17
|
+
Image,
|
|
18
|
+
Util,
|
|
19
|
+
Configuration,
|
|
20
|
+
Listeners,
|
|
21
|
+
IntegrationModel,
|
|
22
|
+
currentInstance,
|
|
23
|
+
instances,
|
|
24
|
+
TinyMceIntegration,
|
|
25
|
+
Latex,
|
|
26
|
+
Test,
|
|
27
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wiris/mathtype-tinymce6",
|
|
3
|
+
"version": "7.31.0",
|
|
4
|
+
"description": "MathType Web for TinyMCE6 editor",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chem",
|
|
7
|
+
"chemistry",
|
|
8
|
+
"chemtype",
|
|
9
|
+
"editor",
|
|
10
|
+
"equation",
|
|
11
|
+
"latex",
|
|
12
|
+
"math",
|
|
13
|
+
"mathml",
|
|
14
|
+
"maths",
|
|
15
|
+
"mathtype",
|
|
16
|
+
"tinymce",
|
|
17
|
+
"tinymce5",
|
|
18
|
+
"wiris"
|
|
19
|
+
],
|
|
20
|
+
"repository": "https://github.com/wiris/html-integrations/tree/stable/packages/mathtype-tinymce6",
|
|
21
|
+
"homepage": "www.wiris.com/?utm_source=npmjs&utm_medium=referral",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"email": "support@wiris.com"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "WIRIS Team (www.wiris.com/?utm_source=npmjs&utm_medium=referral)",
|
|
27
|
+
"main": "plugin.min.js",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "webpack --mode production",
|
|
30
|
+
"build-dev": "webpack --mode development",
|
|
31
|
+
"clean": "shx rm -f plugin.min.js",
|
|
32
|
+
"compile": "node ../../scripts/services/compile editor_plugin.src.js .",
|
|
33
|
+
"prepack": "npm install && npm run compile -- npm"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@wiris/mathtype-html-integration-devkit": "1.8.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@babel/core": "^7.15.0",
|
|
40
|
+
"@babel/preset-env": "^7.15.0",
|
|
41
|
+
"babel-loader": "^8.2.2",
|
|
42
|
+
"css-loader": "^5.2.4",
|
|
43
|
+
"raw-loader": "^4.0.2",
|
|
44
|
+
"shx": "^0.3.3",
|
|
45
|
+
"style-loader": "^3.3.0",
|
|
46
|
+
"terser-webpack-plugin": "^5.3.0",
|
|
47
|
+
"url-loader": "^4.1.1",
|
|
48
|
+
"webpack": "^5.50.0",
|
|
49
|
+
"webpack-cli": "^4.8.0"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wiris/mathtype-tinymce6",
|
|
3
|
+
"version": "7.27.1",
|
|
4
|
+
"description": "MathType Web for TinyMCE6 editor",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chem",
|
|
7
|
+
"chemistry",
|
|
8
|
+
"chemtype",
|
|
9
|
+
"editor",
|
|
10
|
+
"equation",
|
|
11
|
+
"latex",
|
|
12
|
+
"math",
|
|
13
|
+
"mathml",
|
|
14
|
+
"maths",
|
|
15
|
+
"mathtype",
|
|
16
|
+
"tinymce",
|
|
17
|
+
"tinymce5",
|
|
18
|
+
"wiris"
|
|
19
|
+
],
|
|
20
|
+
"repository": "https://github.com/wiris/html-integrations/tree/stable/packages/mathtype-tinymce6",
|
|
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
|
+
"main": "plugin.min.js",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "webpack --mode production",
|
|
30
|
+
"build-dev": "webpack --mode development",
|
|
31
|
+
"clean": "shx rm -f plugin.min.js",
|
|
32
|
+
"compile": "node ../../scripts/services/compile editor_plugin.src.js .",
|
|
33
|
+
"prepack": "npm install && npm run compile -- npm"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@wiris/mathtype-html-integration-devkit": "1.6.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@babel/core": "^7.15.0",
|
|
40
|
+
"@babel/preset-env": "^7.15.0",
|
|
41
|
+
"babel-loader": "^8.2.2",
|
|
42
|
+
"css-loader": "^5.2.4",
|
|
43
|
+
"raw-loader": "^4.0.2",
|
|
44
|
+
"shx": "^0.3.3",
|
|
45
|
+
"style-loader": "^3.3.0",
|
|
46
|
+
"terser-webpack-plugin": "^5.3.0",
|
|
47
|
+
"url-loader": "^4.1.1",
|
|
48
|
+
"webpack": "^5.50.0",
|
|
49
|
+
"webpack-cli": "^4.8.0"
|
|
50
|
+
}
|
|
51
|
+
}
|