lib/editor/tiny/plugins/premium/amd/src/configuration.js

  1. // This file is part of Moodle - http://moodle.org/
  2. //
  3. // Moodle is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // Moodle is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * Tiny Premium configuration.
  17. *
  18. * @module tiny_premium/configuration
  19. * @copyright 2023 David Woloszyn <david.woloszyn@moodle.com>
  20. * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import {
  23. addToolbarButton,
  24. addMenubarItem,
  25. addToolbarSection,
  26. addContextmenuItem
  27. } from 'editor_tiny/utils';
  28. import {
  29. getInitialPluginConfiguration,
  30. getPluginOptionName
  31. } from 'editor_tiny/options';
  32. const configureToolbar = (toolbar) => {
  33. // Add premium toolbar sections to house all the plugins with no natural home.
  34. toolbar = addToolbarSection(toolbar, 'premium_a', 'advanced', true);
  35. toolbar = addToolbarSection(toolbar, 'premium_b', 'formatting', true);
  36. return toolbar;
  37. };
  38. export const configure = (instanceConfig, options) => {
  39. // Get the namespaced options for Tiny Premium before they are officially initialised.
  40. // Due to the timing the plugin options are available, we need to get at the options in this slightly unconventional way.
  41. const pluginOptions = getInitialPluginConfiguration(options);
  42. const enabledPremiumPlugins = pluginOptions[getPluginOptionName('tiny_premium/plugin', 'premiumplugins')].split(',');
  43. let plugins = instanceConfig.plugins;
  44. let menu = instanceConfig.menu;
  45. let toolbar = configureToolbar(instanceConfig.toolbar);
  46. let contextmenu = instanceConfig.contextmenu;
  47. let pluginsettings = {};
  48. // Advanced Table.
  49. if (enabledPremiumPlugins.indexOf('advtable') !== -1) {
  50. plugins += ` advtable`;
  51. menu = addMenubarItem(menu, 'table', '| advtablerownumbering', 'advtablesort');
  52. }
  53. // Enhanced Image Editing.
  54. if (enabledPremiumPlugins.indexOf('editimage') !== -1) {
  55. plugins += ` editimage`;
  56. toolbar = addToolbarButton(toolbar, 'content', 'editimage', 'tiny_media_image');
  57. // Remove the duplicate image button from the quickbar toolbar by redefining the values without 'imageoptions'.
  58. // eslint-disable-next-line camelcase
  59. instanceConfig.editimage_toolbar = 'rotateleft rotateright flipv fliph editimage';
  60. }
  61. // Export.
  62. if (enabledPremiumPlugins.indexOf('export') !== -1) {
  63. plugins += ` export`;
  64. menu = addMenubarItem(menu, 'tools', '| export');
  65. }
  66. // Page Embed.
  67. if (enabledPremiumPlugins.indexOf('pageembed') !== -1) {
  68. plugins += ` pageembed`;
  69. toolbar = addToolbarButton(toolbar, 'content', 'pageembed', 'tiny_media_video');
  70. }
  71. // Advanced Typography.
  72. if (enabledPremiumPlugins.indexOf('typography') !== -1) {
  73. plugins += ` typography`;
  74. toolbar = addToolbarButton(toolbar, 'premium_b', 'typography');
  75. }
  76. // Case Change.
  77. if (enabledPremiumPlugins.indexOf('casechange') !== -1) {
  78. plugins += ` casechange`;
  79. toolbar = addToolbarButton(toolbar, 'premium_a', 'casechange');
  80. }
  81. // Checklist.
  82. if (enabledPremiumPlugins.indexOf('checklist') !== -1) {
  83. plugins += ` checklist`;
  84. toolbar = addToolbarButton(toolbar, 'lists', 'checklist');
  85. }
  86. // Spell Checker Pro.
  87. if (enabledPremiumPlugins.indexOf('tinymcespellchecker') !== -1) {
  88. plugins += ` tinymcespellchecker`;
  89. menu = addMenubarItem(menu, 'tools', 'spellcheckdialog', 'spellcheckerlanguage');
  90. contextmenu = addContextmenuItem(contextmenu, 'spellchecker');
  91. toolbar = addToolbarButton(toolbar, 'premium_a', 'spellcheckdialog');
  92. }
  93. // Spelling Autocorrect.
  94. if (enabledPremiumPlugins.indexOf('autocorrect') !== -1) {
  95. plugins += ` autocorrect`;
  96. menu = addMenubarItem(menu, 'tools', '| autocorrect capitalization', 'spellcheckdialog');
  97. }
  98. // Permanent Pen.
  99. if (enabledPremiumPlugins.indexOf('permanentpen') !== -1) {
  100. plugins += ` permanentpen`;
  101. menu = addMenubarItem(menu, 'format', '| permanentpen configurepermanentpen');
  102. toolbar = addToolbarButton(toolbar, 'premium_a', 'permanentpen');
  103. contextmenu = addContextmenuItem(contextmenu, 'configurepermanentpen');
  104. }
  105. // Format Painter.
  106. if (enabledPremiumPlugins.indexOf('formatpainter') !== -1) {
  107. plugins += ` formatpainter`;
  108. toolbar = addToolbarButton(toolbar, 'premium_a', 'formatpainter');
  109. }
  110. // Link Checker.
  111. if (enabledPremiumPlugins.indexOf('linkchecker') !== -1) {
  112. plugins += ` linkchecker`;
  113. contextmenu = addContextmenuItem(contextmenu, 'linkchecker');
  114. }
  115. // Table of Contents.
  116. if (enabledPremiumPlugins.indexOf('tableofcontents') !== -1) {
  117. plugins += ` tableofcontents`;
  118. toolbar = addToolbarButton(toolbar, 'premium_a', 'tableofcontents');
  119. }
  120. // MathML
  121. if (enabledPremiumPlugins.indexOf('math') !== -1) {
  122. plugins += ` math`;
  123. toolbar = addToolbarButton(toolbar, 'premium_a', 'math');
  124. menu = addMenubarItem(menu, 'insert', 'math', 'tableofcontents');
  125. }
  126. // Footnotes.
  127. if (enabledPremiumPlugins.indexOf('footnotes') !== -1) {
  128. plugins += ` footnotes`;
  129. toolbar = addToolbarButton(toolbar, 'premium_a', 'footnotes');
  130. menu = addMenubarItem(menu, 'insert', 'footnotes', 'tableofcontents');
  131. }
  132. // Powerpaste.
  133. if (enabledPremiumPlugins.indexOf('powerpaste') !== -1) {
  134. plugins += ` powerpaste`;
  135. }
  136. return {
  137. plugins,
  138. toolbar,
  139. menu,
  140. contextmenu,
  141. ...pluginsettings
  142. };
  143. };