@wiris/mathtype-tinymce6 8.3.1 → 8.5.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/editor_plugin.src.js +122 -59
- package/package.json +3 -3
- package/plugin.min.js +1 -1
- package/project.json +26 -17
package/editor_plugin.src.js
CHANGED
|
@@ -38,7 +38,6 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
38
38
|
*/
|
|
39
39
|
getPath() {
|
|
40
40
|
if (this.isMoodle) {
|
|
41
|
-
// return '/lib/editor/tinymce/plugins/tiny_mce_wiris/tinymce/';
|
|
42
41
|
const search = 'lib/editor/tinymce';
|
|
43
42
|
const pos = tinymce.baseURL.indexOf(search);
|
|
44
43
|
const baseURL = tinymce.baseURL.substr(0, pos + search.length);
|
|
@@ -51,14 +50,10 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
/**
|
|
54
|
-
* Returns the absolute path of plugin icons.
|
|
55
|
-
* icons is needed for TinyMCE and Moodle 2.5-
|
|
53
|
+
* Returns the absolute path of plugin icons.
|
|
56
54
|
* @returns {String} - Absolute path of the icons folder.
|
|
57
55
|
*/
|
|
58
56
|
getIconsPath() {
|
|
59
|
-
if (this.isMoodle && Configuration.get('versionPlatform') < 2013111800) {
|
|
60
|
-
return `${this.getPath()}icons/tinymce3/`;
|
|
61
|
-
}
|
|
62
57
|
return `${this.getPath()}icons/`;
|
|
63
58
|
}
|
|
64
59
|
|
|
@@ -69,9 +64,10 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
69
64
|
*/
|
|
70
65
|
getLanguage() {
|
|
71
66
|
const editorSettings = this.editorObject;
|
|
67
|
+
// Try to get editorParameters.language, fail silently otherwise
|
|
72
68
|
try {
|
|
73
69
|
return editorSettings.options.get('mathTypeParameters').editorParameters.language;
|
|
74
|
-
} catch (e) {
|
|
70
|
+
} catch (e) {}
|
|
75
71
|
// Get the deprecated wirisformulaeditorlang
|
|
76
72
|
if (editorSettings.options.get('wirisformulaeditorlang')) {
|
|
77
73
|
console.warn('Deprecated property wirisformulaeditorlang. Use mathTypeParameters on instead.');
|
|
@@ -139,6 +135,30 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
139
135
|
}
|
|
140
136
|
super.updateFormula(mathml);
|
|
141
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Set Moodle configuration on plugin.
|
|
141
|
+
* @param {string} editor - Editor instance.
|
|
142
|
+
* @param {string} pluginName - TinyMCE 6 plugin name.
|
|
143
|
+
*/
|
|
144
|
+
registerMoodleOption (editor, pluginName) {
|
|
145
|
+
const registerOption = editor.options.register;
|
|
146
|
+
|
|
147
|
+
registerOption(`${pluginName}:filterEnabled`, {
|
|
148
|
+
processor: 'boolean',
|
|
149
|
+
'default': false,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
registerOption(`${pluginName}:editorEnabled`, {
|
|
153
|
+
processor: 'boolean',
|
|
154
|
+
'default': false,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
registerOption(`${pluginName}:chemistryEnabled`, {
|
|
158
|
+
processor: 'boolean',
|
|
159
|
+
'default': false,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
142
162
|
}
|
|
143
163
|
|
|
144
164
|
/**
|
|
@@ -160,7 +180,10 @@ export const currentInstance = null;
|
|
|
160
180
|
with the TinyMCE instance and using the `external_plugins` option.
|
|
161
181
|
*/
|
|
162
182
|
(function () {
|
|
163
|
-
|
|
183
|
+
const isMoodle = !!((typeof M === 'object' && M !== null)); // eslint-disable-line no-undef;
|
|
184
|
+
const pluginName = isMoodle ? 'tiny_wiris/plugin' : 'tiny_mce_wiris';
|
|
185
|
+
|
|
186
|
+
tinymce.PluginManager.add(pluginName, (editor, url) => ({ // eslint-disable-line no-unused-vars
|
|
164
187
|
init(editor) {
|
|
165
188
|
const callbackMethodArguments = {};
|
|
166
189
|
|
|
@@ -180,7 +203,7 @@ export const currentInstance = null;
|
|
|
180
203
|
server: process.env.SERVICE_PROVIDER_SERVER,
|
|
181
204
|
};
|
|
182
205
|
integrationModelProperties.version = packageInfo.version;
|
|
183
|
-
integrationModelProperties.isMoodle =
|
|
206
|
+
integrationModelProperties.isMoodle = isMoodle; // eslint-disable-line no-undef
|
|
184
207
|
if (integrationModelProperties.isMoodle) {
|
|
185
208
|
// eslint-disable-next-line no-undef
|
|
186
209
|
integrationModelProperties.configurationService = M.cfg.wwwroot + '/filter/wiris/integration/configurationjs.php'; // eslint-disable-line prefer-template
|
|
@@ -220,12 +243,36 @@ export const currentInstance = null;
|
|
|
220
243
|
integrationModelProperties.isExternal = isExternalPlugin;
|
|
221
244
|
integrationModelProperties.rtl = (editor.options.get('directionality') === 'rtl');
|
|
222
245
|
|
|
246
|
+
// Set Moodle configurations for Telemetry purposes.
|
|
247
|
+
const registerOption = editor.options.register;
|
|
248
|
+
registerOption(`${pluginName}:moodleCourseCategory`, {
|
|
249
|
+
processor: 'integer',
|
|
250
|
+
'default': undefined
|
|
251
|
+
});
|
|
252
|
+
registerOption(`${pluginName}:moodleCourseName`, {
|
|
253
|
+
processor: 'string',
|
|
254
|
+
'default': undefined
|
|
255
|
+
});
|
|
256
|
+
registerOption(`${pluginName}:moodleVersion`, {
|
|
257
|
+
processor: 'integer',
|
|
258
|
+
'default': undefined
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
integrationModelProperties.environment.moodleVersion = editor.options.get(`${pluginName}:moodleVersion`);
|
|
262
|
+
integrationModelProperties.environment.moodleCourseCategory = editor.options.get(`${pluginName}:moodleCourseCategory`);
|
|
263
|
+
integrationModelProperties.environment.moodleCourseName = editor.options.get(`${pluginName}:moodleCourseName`);
|
|
264
|
+
|
|
223
265
|
// GenericIntegration instance.
|
|
224
266
|
const tinyMceIntegrationInstance = new TinyMceIntegration(integrationModelProperties);
|
|
225
267
|
tinyMceIntegrationInstance.init();
|
|
226
268
|
WirisPlugin.instances[tinyMceIntegrationInstance.editorObject.id] = tinyMceIntegrationInstance;
|
|
227
269
|
WirisPlugin.currentInstance = tinyMceIntegrationInstance;
|
|
228
270
|
|
|
271
|
+
// Set Moodle configuration parameters to the plugin
|
|
272
|
+
if (isMoodle) {
|
|
273
|
+
tinyMceIntegrationInstance.registerMoodleOption(editor, pluginName);
|
|
274
|
+
}
|
|
275
|
+
|
|
229
276
|
const onInit = function (editor) { // eslint-disable-line no-shadow
|
|
230
277
|
const integrationInstance = WirisPlugin.instances[tinyMceIntegrationInstance.editorObject.id];
|
|
231
278
|
if (!editor.inline) {
|
|
@@ -295,7 +342,11 @@ export const currentInstance = null;
|
|
|
295
342
|
}
|
|
296
343
|
|
|
297
344
|
const onSave = function (editor, params) { // eslint-disable-line no-shadow
|
|
298
|
-
|
|
345
|
+
if (integrationModelProperties.isMoodle) {
|
|
346
|
+
params.content = Parser.endParseSaveMode(params.content, editor.getParam('language'));
|
|
347
|
+
} else {
|
|
348
|
+
params.content = Parser.endParse(params.content, editor.getParam('language'));
|
|
349
|
+
}
|
|
299
350
|
};
|
|
300
351
|
|
|
301
352
|
if ('onSaveContent' in editor) {
|
|
@@ -316,14 +367,18 @@ export const currentInstance = null;
|
|
|
316
367
|
|
|
317
368
|
if ('onBeforeSetContent' in editor) {
|
|
318
369
|
editor.onBeforeSetContent.add((e, params) => {
|
|
319
|
-
if (
|
|
320
|
-
params.content = Parser.
|
|
370
|
+
if (integrationModelProperties.isMoodle) {
|
|
371
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam('language'));
|
|
372
|
+
} else if (WirisPlugin.instances[editor.id].initParsed) {
|
|
373
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam('language'));
|
|
321
374
|
}
|
|
322
375
|
});
|
|
323
376
|
} else {
|
|
324
377
|
editor.on('beforeSetContent', (params) => {
|
|
325
|
-
if (
|
|
326
|
-
params.content = Parser.
|
|
378
|
+
if (integrationModelProperties.isMoodle) {
|
|
379
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam('language'));
|
|
380
|
+
} else if (WirisPlugin.instances[editor.id].initParsed) {
|
|
381
|
+
params.content = Parser.initParse(params.content, editor.getParam('language'));
|
|
327
382
|
}
|
|
328
383
|
});
|
|
329
384
|
}
|
|
@@ -344,57 +399,65 @@ export const currentInstance = null;
|
|
|
344
399
|
commonEditor.addIcon(mathTypeIcon, mathTypeIconSvg);
|
|
345
400
|
commonEditor.addIcon(chemTypeIcon, chemTypeIconSvg);
|
|
346
401
|
|
|
347
|
-
// The next two blocks create menu items to give the possibility
|
|
348
|
-
// of add MathType in the menubar.
|
|
349
|
-
commonEditor.addMenuItem('tiny_mce_wiris_formulaEditor', {
|
|
350
|
-
text: 'MathType',
|
|
351
|
-
icon: mathTypeIcon,
|
|
352
|
-
onAction: openFormulaEditorFunction,
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
// Dynamic customEditors buttons.
|
|
356
|
-
const customEditors = WirisPlugin.instances[editor.id].getCore().getCustomEditors();
|
|
357
|
-
Object.keys(customEditors.editors).forEach((customEditor) => {
|
|
358
|
-
if (customEditors.editors[customEditor].confVariable) {
|
|
359
|
-
commonEditor.addMenuItem(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
360
|
-
text: customEditors.editors[customEditor].title,
|
|
361
|
-
icon: chemTypeIcon, // Parametrize when other custom editors are added.
|
|
362
|
-
onAction: () => {
|
|
363
|
-
customEditors.enable(customEditor);
|
|
364
|
-
WirisPlugin.instances[editor.id].openNewFormulaEditor();
|
|
365
|
-
},
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
|
|
370
402
|
// Get editor language code
|
|
371
403
|
let lang_code = editor.options.get('language');
|
|
372
404
|
lang_code = (lang_code.split("-")[0]).split("_")[0];
|
|
373
405
|
|
|
374
|
-
// MathType
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
406
|
+
// Check If MathType/ChemType are enabled on Moodle
|
|
407
|
+
const editorEnabled = !isMoodle || (isMoodle && editor.options.get(`${pluginName}:editorEnabled`) && editor.options.get(`${pluginName}:filterEnabled`));
|
|
408
|
+
const chemEnabled = !isMoodle || (isMoodle && editor.options.get(`${pluginName}:chemistryEnabled`) && editor.options.get(`${pluginName}:filterEnabled`));
|
|
409
|
+
|
|
410
|
+
if (editorEnabled) {
|
|
411
|
+
// The next two blocks create menu items to give the possibility
|
|
412
|
+
// of add MathType in the menubar.
|
|
413
|
+
commonEditor.addMenuItem('tiny_mce_wiris_formulaEditor', {
|
|
414
|
+
text: 'MathType',
|
|
415
|
+
icon: mathTypeIcon,
|
|
416
|
+
onAction: openFormulaEditorFunction,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// MathType button.
|
|
420
|
+
commonEditor.addButton('tiny_mce_wiris_formulaEditor', {
|
|
421
|
+
tooltip: StringManager.get('insert_math', lang_code),
|
|
422
|
+
image: `${WirisPlugin.instances[editor.id].getIconsPath()}formula.png`,
|
|
423
|
+
onAction: openFormulaEditorFunction,
|
|
424
|
+
icon: mathTypeIcon,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
381
427
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
428
|
+
if (chemEnabled) {
|
|
429
|
+
// Dynamic customEditors buttons.
|
|
430
|
+
const customEditors = WirisPlugin.instances[editor.id].getCore().getCustomEditors();
|
|
431
|
+
Object.keys(customEditors.editors).forEach((customEditor) => {
|
|
432
|
+
if (customEditors.editors[customEditor].confVariable) {
|
|
433
|
+
commonEditor.addMenuItem(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
434
|
+
text: customEditors.editors[customEditor].title,
|
|
435
|
+
icon: chemTypeIcon, // Parametrize when other custom editors are added.
|
|
436
|
+
onAction: () => {
|
|
437
|
+
customEditors.enable(customEditor);
|
|
438
|
+
WirisPlugin.instances[editor.id].openNewFormulaEditor();
|
|
439
|
+
},
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// Dynamic customEditors buttons.
|
|
445
|
+
for (const customEditor in customEditors.editors) {
|
|
446
|
+
if (customEditors.editors[customEditor].confVariable) {
|
|
447
|
+
const cmd = `tiny_mce_wiris_openFormulaEditor${customEditors.editors[customEditor].name}`;
|
|
448
|
+
// eslint-disable-next-line no-inner-declarations, no-loop-func
|
|
449
|
+
function commandFunction() {
|
|
450
|
+
customEditors.enable(customEditor);
|
|
451
|
+
WirisPlugin.instances[editor.id].openNewFormulaEditor(); // eslint-disable-line no-undef
|
|
452
|
+
}
|
|
453
|
+
editor.addCommand(cmd, commandFunction);
|
|
454
|
+
commonEditor.addButton(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
455
|
+
tooltip: StringManager.get('insert_chem', lang_code),
|
|
456
|
+
onAction: commandFunction,
|
|
457
|
+
image: WirisPlugin.instances[editor.id].getIconsPath() + customEditors.editors[customEditor].icon,
|
|
458
|
+
icon: chemTypeIcon, // At the moment only chemTypeIcon because of the provisional solution for TinyMCE6.
|
|
459
|
+
});
|
|
390
460
|
}
|
|
391
|
-
editor.addCommand(cmd, commandFunction);
|
|
392
|
-
commonEditor.addButton(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
393
|
-
tooltip: StringManager.get('insert_chem', lang_code),
|
|
394
|
-
onAction: commandFunction,
|
|
395
|
-
image: WirisPlugin.instances[editor.id].getIconsPath() + customEditors.editors[customEditor].icon,
|
|
396
|
-
icon: chemTypeIcon, // At the moment only chemTypeIcon because of the provisional solution for TinyMCE6.
|
|
397
|
-
});
|
|
398
461
|
}
|
|
399
462
|
}
|
|
400
463
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiris/mathtype-tinymce6",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"description": "MathType Web for TinyMCE6 editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chem",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"build": "webpack --mode production",
|
|
30
30
|
"build-dev": "webpack --mode development",
|
|
31
31
|
"clean": "shx rm -f plugin.min.js",
|
|
32
|
-
"prepack": "
|
|
32
|
+
"prepack": "yarn && npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@wiris/mathtype-html-integration-devkit": "1.
|
|
35
|
+
"@wiris/mathtype-html-integration-devkit": "1.13.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "^7.15.0",
|