plugin.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * TinyMCE version 8.0.2 (2025-08-14)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. /* eslint-disable @typescript-eslint/no-wrapper-object-types */
  8. const isSimpleType = (type) => (value) => typeof value === type;
  9. const isFunction = isSimpleType('function');
  10. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  11. var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
  12. const option = (name) => (editor) => editor.options.get(name);
  13. const register$2 = (editor) => {
  14. const registerOption = editor.options.register;
  15. registerOption('save_enablewhendirty', {
  16. processor: 'boolean',
  17. default: true
  18. });
  19. registerOption('save_onsavecallback', {
  20. processor: 'function'
  21. });
  22. registerOption('save_oncancelcallback', {
  23. processor: 'function'
  24. });
  25. };
  26. const enableWhenDirty = option('save_enablewhendirty');
  27. const getOnSaveCallback = option('save_onsavecallback');
  28. const getOnCancelCallback = option('save_oncancelcallback');
  29. const displayErrorMessage = (editor, message) => {
  30. editor.notificationManager.open({
  31. text: message,
  32. type: 'error'
  33. });
  34. };
  35. const save = (editor) => {
  36. const formObj = global$1.DOM.getParent(editor.id, 'form');
  37. if (enableWhenDirty(editor) && !editor.isDirty()) {
  38. return;
  39. }
  40. editor.save();
  41. // Use callback instead
  42. const onSaveCallback = getOnSaveCallback(editor);
  43. if (isFunction(onSaveCallback)) {
  44. onSaveCallback.call(editor, editor);
  45. editor.nodeChanged();
  46. return;
  47. }
  48. if (formObj) {
  49. editor.setDirty(false);
  50. // TODO: TINY-6105 this is probably broken, as an event should be passed to `onsubmit`
  51. // so we need to investigate this at some point
  52. if (!formObj.onsubmit || formObj.onsubmit()) {
  53. if (typeof formObj.submit === 'function') {
  54. formObj.submit();
  55. }
  56. else {
  57. displayErrorMessage(editor, 'Error: Form submit field collision.');
  58. }
  59. }
  60. editor.nodeChanged();
  61. }
  62. else {
  63. displayErrorMessage(editor, 'Error: No form element found.');
  64. }
  65. };
  66. const cancel = (editor) => {
  67. const h = global.trim(editor.startContent);
  68. // Use callback instead
  69. const onCancelCallback = getOnCancelCallback(editor);
  70. if (isFunction(onCancelCallback)) {
  71. onCancelCallback.call(editor, editor);
  72. return;
  73. }
  74. // Reset the editor content back to the initial state
  75. editor.resetContent(h);
  76. };
  77. const register$1 = (editor) => {
  78. editor.addCommand('mceSave', () => {
  79. save(editor);
  80. });
  81. editor.addCommand('mceCancel', () => {
  82. cancel(editor);
  83. });
  84. };
  85. const stateToggle = (editor) => (api) => {
  86. const handler = () => {
  87. api.setEnabled(!enableWhenDirty(editor) || editor.isDirty());
  88. };
  89. handler();
  90. editor.on('NodeChange dirty', handler);
  91. return () => editor.off('NodeChange dirty', handler);
  92. };
  93. const register = (editor) => {
  94. editor.ui.registry.addButton('save', {
  95. icon: 'save',
  96. tooltip: 'Save',
  97. enabled: false,
  98. onAction: () => editor.execCommand('mceSave'),
  99. onSetup: stateToggle(editor),
  100. shortcut: 'Meta+S'
  101. });
  102. editor.ui.registry.addButton('cancel', {
  103. icon: 'cancel',
  104. tooltip: 'Cancel',
  105. enabled: false,
  106. onAction: () => editor.execCommand('mceCancel'),
  107. onSetup: stateToggle(editor)
  108. });
  109. editor.addShortcut('Meta+S', '', 'mceSave');
  110. };
  111. var Plugin = () => {
  112. global$2.add('save', (editor) => {
  113. register$2(editor);
  114. register(editor);
  115. register$1(editor);
  116. });
  117. };
  118. Plugin();
  119. /** *****
  120. * DO NOT EXPORT ANYTHING
  121. *
  122. * IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
  123. *******/
  124. })();