plugin.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * TinyMCE version 8.0.2 (2025-08-14)
  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. // Prevents the visualblocks from being presented in the preview of formats when that is computed
  45. editor.on('PreviewFormats AfterPreviewFormats', (e) => {
  46. if (enabledState.get()) {
  47. editor.dom.toggleClass(editor.getBody(), 'mce-visualblocks', e.type === 'afterpreviewformats');
  48. }
  49. });
  50. editor.on('init', () => {
  51. if (isEnabledByDefault(editor)) {
  52. toggleVisualBlocks(editor, pluginUrl, enabledState);
  53. }
  54. });
  55. };
  56. const toggleActiveState = (editor, enabledState) => (api) => {
  57. api.setActive(enabledState.get());
  58. const editorEventCallback = (e) => api.setActive(e.state);
  59. editor.on('VisualBlocks', editorEventCallback);
  60. return () => editor.off('VisualBlocks', editorEventCallback);
  61. };
  62. const register = (editor, enabledState) => {
  63. const onAction = () => editor.execCommand('mceVisualBlocks');
  64. editor.ui.registry.addToggleButton('visualblocks', {
  65. icon: 'visualblocks',
  66. tooltip: 'Show blocks',
  67. onAction,
  68. onSetup: toggleActiveState(editor, enabledState),
  69. context: 'any'
  70. });
  71. editor.ui.registry.addToggleMenuItem('visualblocks', {
  72. text: 'Show blocks',
  73. icon: 'visualblocks',
  74. onAction,
  75. onSetup: toggleActiveState(editor, enabledState),
  76. context: 'any'
  77. });
  78. };
  79. var Plugin = () => {
  80. global.add('visualblocks', (editor, pluginUrl) => {
  81. register$1(editor);
  82. const enabledState = Cell(false);
  83. register$2(editor, pluginUrl, enabledState);
  84. register(editor, enabledState);
  85. setup(editor, pluginUrl, enabledState);
  86. });
  87. };
  88. Plugin();
  89. /** *****
  90. * DO NOT EXPORT ANYTHING
  91. *
  92. * IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
  93. *******/
  94. })();