2 * TinyMCE version 6.6.2 (2023-08-09)
8 var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager');
10 const isSimpleType = type => value => typeof value === type;
11 const isFunction = isSimpleType('function');
13 var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
15 var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
17 const option = name => editor => editor.options.get(name);
18 const register$2 = editor => {
19 const registerOption = editor.options.register;
20 registerOption('save_enablewhendirty', {
24 registerOption('save_onsavecallback', { processor: 'function' });
25 registerOption('save_oncancelcallback', { processor: 'function' });
27 const enableWhenDirty = option('save_enablewhendirty');
28 const getOnSaveCallback = option('save_onsavecallback');
29 const getOnCancelCallback = option('save_oncancelcallback');
31 const displayErrorMessage = (editor, message) => {
32 editor.notificationManager.open({
37 const save = editor => {
38 const formObj = global$1.DOM.getParent(editor.id, 'form');
39 if (enableWhenDirty(editor) && !editor.isDirty()) {
43 const onSaveCallback = getOnSaveCallback(editor);
44 if (isFunction(onSaveCallback)) {
45 onSaveCallback.call(editor, editor);
50 editor.setDirty(false);
51 if (!formObj.onsubmit || formObj.onsubmit()) {
52 if (typeof formObj.submit === 'function') {
55 displayErrorMessage(editor, 'Error: Form submit field collision.');
60 displayErrorMessage(editor, 'Error: No form element found.');
63 const cancel = editor => {
64 const h = global.trim(editor.startContent);
65 const onCancelCallback = getOnCancelCallback(editor);
66 if (isFunction(onCancelCallback)) {
67 onCancelCallback.call(editor, editor);
70 editor.resetContent(h);
73 const register$1 = editor => {
74 editor.addCommand('mceSave', () => {
77 editor.addCommand('mceCancel', () => {
82 const stateToggle = editor => api => {
83 const handler = () => {
84 api.setEnabled(!enableWhenDirty(editor) || editor.isDirty());
87 editor.on('NodeChange dirty', handler);
88 return () => editor.off('NodeChange dirty', handler);
90 const register = editor => {
91 editor.ui.registry.addButton('save', {
95 onAction: () => editor.execCommand('mceSave'),
96 onSetup: stateToggle(editor)
98 editor.ui.registry.addButton('cancel', {
102 onAction: () => editor.execCommand('mceCancel'),
103 onSetup: stateToggle(editor)
105 editor.addShortcut('Meta+S', '', 'mceSave');
109 global$2.add('save', editor => {