@wiris/mathtype-tinymce6 8.3.0 → 8.4.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 +120 -58
- package/package.json +3 -3
- package/plugin.min.js +1 -1
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
|
|
|
@@ -139,6 +134,30 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
139
134
|
}
|
|
140
135
|
super.updateFormula(mathml);
|
|
141
136
|
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Set Moodle configuration on plugin.
|
|
140
|
+
* @param {string} editor - Editor instance.
|
|
141
|
+
* @param {string} pluginName - TinyMCE 6 plugin name.
|
|
142
|
+
*/
|
|
143
|
+
registerMoodleOption (editor, pluginName) {
|
|
144
|
+
const registerOption = editor.options.register;
|
|
145
|
+
|
|
146
|
+
registerOption(`${pluginName}:filterEnabled`, {
|
|
147
|
+
processor: 'boolean',
|
|
148
|
+
'default': false,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
registerOption(`${pluginName}:editorEnabled`, {
|
|
152
|
+
processor: 'boolean',
|
|
153
|
+
'default': false,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
registerOption(`${pluginName}:chemistryEnabled`, {
|
|
157
|
+
processor: 'boolean',
|
|
158
|
+
'default': false,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
142
161
|
}
|
|
143
162
|
|
|
144
163
|
/**
|
|
@@ -160,7 +179,10 @@ export const currentInstance = null;
|
|
|
160
179
|
with the TinyMCE instance and using the `external_plugins` option.
|
|
161
180
|
*/
|
|
162
181
|
(function () {
|
|
163
|
-
|
|
182
|
+
const isMoodle = !!((typeof M === 'object' && M !== null)); // eslint-disable-line no-undef;
|
|
183
|
+
const pluginName = isMoodle ? 'tiny_wiris/plugin' : 'tiny_mce_wiris';
|
|
184
|
+
|
|
185
|
+
tinymce.PluginManager.add(pluginName, (editor, url) => ({ // eslint-disable-line no-unused-vars
|
|
164
186
|
init(editor) {
|
|
165
187
|
const callbackMethodArguments = {};
|
|
166
188
|
|
|
@@ -180,7 +202,7 @@ export const currentInstance = null;
|
|
|
180
202
|
server: process.env.SERVICE_PROVIDER_SERVER,
|
|
181
203
|
};
|
|
182
204
|
integrationModelProperties.version = packageInfo.version;
|
|
183
|
-
integrationModelProperties.isMoodle =
|
|
205
|
+
integrationModelProperties.isMoodle = isMoodle; // eslint-disable-line no-undef
|
|
184
206
|
if (integrationModelProperties.isMoodle) {
|
|
185
207
|
// eslint-disable-next-line no-undef
|
|
186
208
|
integrationModelProperties.configurationService = M.cfg.wwwroot + '/filter/wiris/integration/configurationjs.php'; // eslint-disable-line prefer-template
|
|
@@ -220,12 +242,36 @@ export const currentInstance = null;
|
|
|
220
242
|
integrationModelProperties.isExternal = isExternalPlugin;
|
|
221
243
|
integrationModelProperties.rtl = (editor.options.get('directionality') === 'rtl');
|
|
222
244
|
|
|
245
|
+
// Set Moodle configurations for Telemetry purposes.
|
|
246
|
+
const registerOption = editor.options.register;
|
|
247
|
+
registerOption(`${pluginName}:moodleCourseCategory`, {
|
|
248
|
+
processor: 'integer',
|
|
249
|
+
'default': undefined
|
|
250
|
+
});
|
|
251
|
+
registerOption(`${pluginName}:moodleCourseName`, {
|
|
252
|
+
processor: 'string',
|
|
253
|
+
'default': undefined
|
|
254
|
+
});
|
|
255
|
+
registerOption(`${pluginName}:moodleVersion`, {
|
|
256
|
+
processor: 'integer',
|
|
257
|
+
'default': undefined
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
integrationModelProperties.environment.moodleVersion = editor.options.get(`${pluginName}:moodleVersion`);
|
|
261
|
+
integrationModelProperties.environment.moodleCourseCategory = editor.options.get(`${pluginName}:moodleCourseCategory`);
|
|
262
|
+
integrationModelProperties.environment.moodleCourseName = editor.options.get(`${pluginName}:moodleCourseName`);
|
|
263
|
+
|
|
223
264
|
// GenericIntegration instance.
|
|
224
265
|
const tinyMceIntegrationInstance = new TinyMceIntegration(integrationModelProperties);
|
|
225
266
|
tinyMceIntegrationInstance.init();
|
|
226
267
|
WirisPlugin.instances[tinyMceIntegrationInstance.editorObject.id] = tinyMceIntegrationInstance;
|
|
227
268
|
WirisPlugin.currentInstance = tinyMceIntegrationInstance;
|
|
228
269
|
|
|
270
|
+
// Set Moodle configuration parameters to the plugin
|
|
271
|
+
if (isMoodle) {
|
|
272
|
+
tinyMceIntegrationInstance.registerMoodleOption(editor, pluginName);
|
|
273
|
+
}
|
|
274
|
+
|
|
229
275
|
const onInit = function (editor) { // eslint-disable-line no-shadow
|
|
230
276
|
const integrationInstance = WirisPlugin.instances[tinyMceIntegrationInstance.editorObject.id];
|
|
231
277
|
if (!editor.inline) {
|
|
@@ -295,7 +341,11 @@ export const currentInstance = null;
|
|
|
295
341
|
}
|
|
296
342
|
|
|
297
343
|
const onSave = function (editor, params) { // eslint-disable-line no-shadow
|
|
298
|
-
|
|
344
|
+
if (integrationModelProperties.isMoodle) {
|
|
345
|
+
params.content = Parser.endParseSaveMode(params.content, editor.getParam('language'));
|
|
346
|
+
} else {
|
|
347
|
+
params.content = Parser.endParse(params.content, editor.getParam('language'));
|
|
348
|
+
}
|
|
299
349
|
};
|
|
300
350
|
|
|
301
351
|
if ('onSaveContent' in editor) {
|
|
@@ -316,14 +366,18 @@ export const currentInstance = null;
|
|
|
316
366
|
|
|
317
367
|
if ('onBeforeSetContent' in editor) {
|
|
318
368
|
editor.onBeforeSetContent.add((e, params) => {
|
|
319
|
-
if (
|
|
320
|
-
params.content = Parser.
|
|
369
|
+
if (integrationModelProperties.isMoodle) {
|
|
370
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam('language'));
|
|
371
|
+
} else if (WirisPlugin.instances[editor.id].initParsed) {
|
|
372
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam('language'));
|
|
321
373
|
}
|
|
322
374
|
});
|
|
323
375
|
} else {
|
|
324
376
|
editor.on('beforeSetContent', (params) => {
|
|
325
|
-
if (
|
|
326
|
-
params.content = Parser.
|
|
377
|
+
if (integrationModelProperties.isMoodle) {
|
|
378
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam('language'));
|
|
379
|
+
} else if (WirisPlugin.instances[editor.id].initParsed) {
|
|
380
|
+
params.content = Parser.initParse(params.content, editor.getParam('language'));
|
|
327
381
|
}
|
|
328
382
|
});
|
|
329
383
|
}
|
|
@@ -344,57 +398,65 @@ export const currentInstance = null;
|
|
|
344
398
|
commonEditor.addIcon(mathTypeIcon, mathTypeIconSvg);
|
|
345
399
|
commonEditor.addIcon(chemTypeIcon, chemTypeIconSvg);
|
|
346
400
|
|
|
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
401
|
// Get editor language code
|
|
371
402
|
let lang_code = editor.options.get('language');
|
|
372
403
|
lang_code = (lang_code.split("-")[0]).split("_")[0];
|
|
373
404
|
|
|
374
|
-
// MathType
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
405
|
+
// Check If MathType/ChemType are enabled on Moodle
|
|
406
|
+
const editorEnabled = !isMoodle || (isMoodle && editor.options.get(`${pluginName}:editorEnabled`) && editor.options.get(`${pluginName}:filterEnabled`));
|
|
407
|
+
const chemEnabled = !isMoodle || (isMoodle && editor.options.get(`${pluginName}:chemistryEnabled`) && editor.options.get(`${pluginName}:filterEnabled`));
|
|
408
|
+
|
|
409
|
+
if (editorEnabled) {
|
|
410
|
+
// The next two blocks create menu items to give the possibility
|
|
411
|
+
// of add MathType in the menubar.
|
|
412
|
+
commonEditor.addMenuItem('tiny_mce_wiris_formulaEditor', {
|
|
413
|
+
text: 'MathType',
|
|
414
|
+
icon: mathTypeIcon,
|
|
415
|
+
onAction: openFormulaEditorFunction,
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// MathType button.
|
|
419
|
+
commonEditor.addButton('tiny_mce_wiris_formulaEditor', {
|
|
420
|
+
tooltip: StringManager.get('insert_math', lang_code),
|
|
421
|
+
image: `${WirisPlugin.instances[editor.id].getIconsPath()}formula.png`,
|
|
422
|
+
onAction: openFormulaEditorFunction,
|
|
423
|
+
icon: mathTypeIcon,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (chemEnabled) {
|
|
428
|
+
// Dynamic customEditors buttons.
|
|
429
|
+
const customEditors = WirisPlugin.instances[editor.id].getCore().getCustomEditors();
|
|
430
|
+
Object.keys(customEditors.editors).forEach((customEditor) => {
|
|
431
|
+
if (customEditors.editors[customEditor].confVariable) {
|
|
432
|
+
commonEditor.addMenuItem(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
433
|
+
text: customEditors.editors[customEditor].title,
|
|
434
|
+
icon: chemTypeIcon, // Parametrize when other custom editors are added.
|
|
435
|
+
onAction: () => {
|
|
436
|
+
customEditors.enable(customEditor);
|
|
437
|
+
WirisPlugin.instances[editor.id].openNewFormulaEditor();
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
});
|
|
381
442
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
443
|
+
// Dynamic customEditors buttons.
|
|
444
|
+
for (const customEditor in customEditors.editors) {
|
|
445
|
+
if (customEditors.editors[customEditor].confVariable) {
|
|
446
|
+
const cmd = `tiny_mce_wiris_openFormulaEditor${customEditors.editors[customEditor].name}`;
|
|
447
|
+
// eslint-disable-next-line no-inner-declarations, no-loop-func
|
|
448
|
+
function commandFunction() {
|
|
449
|
+
customEditors.enable(customEditor);
|
|
450
|
+
WirisPlugin.instances[editor.id].openNewFormulaEditor(); // eslint-disable-line no-undef
|
|
451
|
+
}
|
|
452
|
+
editor.addCommand(cmd, commandFunction);
|
|
453
|
+
commonEditor.addButton(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
454
|
+
tooltip: StringManager.get('insert_chem', lang_code),
|
|
455
|
+
onAction: commandFunction,
|
|
456
|
+
image: WirisPlugin.instances[editor.id].getIconsPath() + customEditors.editors[customEditor].icon,
|
|
457
|
+
icon: chemTypeIcon, // At the moment only chemTypeIcon because of the provisional solution for TinyMCE6.
|
|
458
|
+
});
|
|
390
459
|
}
|
|
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
460
|
}
|
|
399
461
|
}
|
|
400
462
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiris/mathtype-tinymce6",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.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.12.
|
|
35
|
+
"@wiris/mathtype-html-integration-devkit": "1.12.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "^7.15.0",
|