plugin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * TinyMCE version 6.0.3 (2022-05-25)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. const setContent = (editor, html) => {
  8. editor.focus();
  9. editor.undoManager.transact(() => {
  10. editor.setContent(html);
  11. });
  12. editor.selection.setCursorLocation();
  13. editor.nodeChanged();
  14. };
  15. const getContent = editor => {
  16. return editor.getContent({ source_view: true });
  17. };
  18. const open = editor => {
  19. const editorContent = getContent(editor);
  20. editor.windowManager.open({
  21. title: 'Source Code',
  22. size: 'large',
  23. body: {
  24. type: 'panel',
  25. items: [{
  26. type: 'textarea',
  27. name: 'code'
  28. }]
  29. },
  30. buttons: [
  31. {
  32. type: 'cancel',
  33. name: 'cancel',
  34. text: 'Cancel'
  35. },
  36. {
  37. type: 'submit',
  38. name: 'save',
  39. text: 'Save',
  40. primary: true
  41. }
  42. ],
  43. initialData: { code: editorContent },
  44. onSubmit: api => {
  45. setContent(editor, api.getData().code);
  46. api.close();
  47. }
  48. });
  49. };
  50. const register$1 = editor => {
  51. editor.addCommand('mceCodeEditor', () => {
  52. open(editor);
  53. });
  54. };
  55. const register = editor => {
  56. const onAction = () => editor.execCommand('mceCodeEditor');
  57. editor.ui.registry.addButton('code', {
  58. icon: 'sourcecode',
  59. tooltip: 'Source code',
  60. onAction
  61. });
  62. editor.ui.registry.addMenuItem('code', {
  63. icon: 'sourcecode',
  64. text: 'Source code',
  65. onAction
  66. });
  67. };
  68. var Plugin = () => {
  69. global.add('code', editor => {
  70. register$1(editor);
  71. register(editor);
  72. return {};
  73. });
  74. };
  75. Plugin();
  76. })();