plugin.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * TinyMCE version 6.0.3 (2022-05-25)
  3. */
  4. (function () {
  5. 'use strict';
  6. const Cell = initial => {
  7. let value = initial;
  8. const get = () => {
  9. return value;
  10. };
  11. const set = v => {
  12. value = v;
  13. };
  14. return {
  15. get,
  16. set
  17. };
  18. };
  19. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  20. const fireVisualBlocks = (editor, state) => {
  21. editor.dispatch('VisualBlocks', { state });
  22. };
  23. const toggleVisualBlocks = (editor, pluginUrl, enabledState) => {
  24. const dom = editor.dom;
  25. dom.toggleClass(editor.getBody(), 'mce-visualblocks');
  26. enabledState.set(!enabledState.get());
  27. fireVisualBlocks(editor, enabledState.get());
  28. };
  29. const register$2 = (editor, pluginUrl, enabledState) => {
  30. editor.addCommand('mceVisualBlocks', () => {
  31. toggleVisualBlocks(editor, pluginUrl, enabledState);
  32. });
  33. };
  34. const option = name => editor => editor.options.get(name);
  35. const register$1 = editor => {
  36. const registerOption = editor.options.register;
  37. registerOption('visualblocks_default_state', {
  38. processor: 'boolean',
  39. default: false
  40. });
  41. };
  42. const isEnabledByDefault = option('visualblocks_default_state');
  43. const setup = (editor, pluginUrl, enabledState) => {
  44. editor.on('PreviewFormats AfterPreviewFormats', e => {
  45. if (enabledState.get()) {
  46. editor.dom.toggleClass(editor.getBody(), 'mce-visualblocks', e.type === 'afterpreviewformats');
  47. }
  48. });
  49. editor.on('init', () => {
  50. if (isEnabledByDefault(editor)) {
  51. toggleVisualBlocks(editor, pluginUrl, enabledState);
  52. }
  53. });
  54. };
  55. const toggleActiveState = (editor, enabledState) => api => {
  56. api.setActive(enabledState.get());
  57. const editorEventCallback = e => api.setActive(e.state);
  58. editor.on('VisualBlocks', editorEventCallback);
  59. return () => editor.off('VisualBlocks', editorEventCallback);
  60. };
  61. const register = (editor, enabledState) => {
  62. const onAction = () => editor.execCommand('mceVisualBlocks');
  63. editor.ui.registry.addToggleButton('visualblocks', {
  64. icon: 'visualblocks',
  65. tooltip: 'Show blocks',
  66. onAction,
  67. onSetup: toggleActiveState(editor, enabledState)
  68. });
  69. editor.ui.registry.addToggleMenuItem('visualblocks', {
  70. text: 'Show blocks',
  71. icon: 'visualblocks',
  72. onAction,
  73. onSetup: toggleActiveState(editor, enabledState)
  74. });
  75. };
  76. var Plugin = () => {
  77. global.add('visualblocks', (editor, pluginUrl) => {
  78. register$1(editor);
  79. const enabledState = Cell(false);
  80. register$2(editor, pluginUrl, enabledState);
  81. register(editor, enabledState);
  82. setup(editor, pluginUrl, enabledState);
  83. });
  84. };
  85. Plugin();
  86. })();