feat: tinymce

This commit is contained in:
wangqiao
2025-08-24 09:04:21 +08:00
parent b603d9d854
commit a2fe21a497
212 changed files with 95245 additions and 373 deletions

View File

@ -0,0 +1,7 @@
// Exports the "save" plugin for usage with module loaders
// Usage:
// CommonJS:
// require('tinymce/plugins/save')
// ES2015:
// import 'tinymce/plugins/save'
require('./plugin.js');

View File

@ -0,0 +1,119 @@
/**
* TinyMCE version 7.7.2 (2025-03-19)
*/
(function () {
'use strict';
var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager');
const isSimpleType = type => value => typeof value === type;
const isFunction = isSimpleType('function');
var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
const option = name => editor => editor.options.get(name);
const register$2 = editor => {
const registerOption = editor.options.register;
registerOption('save_enablewhendirty', {
processor: 'boolean',
default: true
});
registerOption('save_onsavecallback', { processor: 'function' });
registerOption('save_oncancelcallback', { processor: 'function' });
};
const enableWhenDirty = option('save_enablewhendirty');
const getOnSaveCallback = option('save_onsavecallback');
const getOnCancelCallback = option('save_oncancelcallback');
const displayErrorMessage = (editor, message) => {
editor.notificationManager.open({
text: message,
type: 'error'
});
};
const save = editor => {
const formObj = global$1.DOM.getParent(editor.id, 'form');
if (enableWhenDirty(editor) && !editor.isDirty()) {
return;
}
editor.save();
const onSaveCallback = getOnSaveCallback(editor);
if (isFunction(onSaveCallback)) {
onSaveCallback.call(editor, editor);
editor.nodeChanged();
return;
}
if (formObj) {
editor.setDirty(false);
if (!formObj.onsubmit || formObj.onsubmit()) {
if (typeof formObj.submit === 'function') {
formObj.submit();
} else {
displayErrorMessage(editor, 'Error: Form submit field collision.');
}
}
editor.nodeChanged();
} else {
displayErrorMessage(editor, 'Error: No form element found.');
}
};
const cancel = editor => {
const h = global.trim(editor.startContent);
const onCancelCallback = getOnCancelCallback(editor);
if (isFunction(onCancelCallback)) {
onCancelCallback.call(editor, editor);
return;
}
editor.resetContent(h);
};
const register$1 = editor => {
editor.addCommand('mceSave', () => {
save(editor);
});
editor.addCommand('mceCancel', () => {
cancel(editor);
});
};
const stateToggle = editor => api => {
const handler = () => {
api.setEnabled(!enableWhenDirty(editor) || editor.isDirty());
};
handler();
editor.on('NodeChange dirty', handler);
return () => editor.off('NodeChange dirty', handler);
};
const register = editor => {
editor.ui.registry.addButton('save', {
icon: 'save',
tooltip: 'Save',
enabled: false,
onAction: () => editor.execCommand('mceSave'),
onSetup: stateToggle(editor),
shortcut: 'Meta+S'
});
editor.ui.registry.addButton('cancel', {
icon: 'cancel',
tooltip: 'Cancel',
enabled: false,
onAction: () => editor.execCommand('mceCancel'),
onSetup: stateToggle(editor)
});
editor.addShortcut('Meta+S', '', 'mceSave');
};
var Plugin = () => {
global$2.add('save', editor => {
register$2(editor);
register(editor);
register$1(editor);
});
};
Plugin();
})();

View File

@ -0,0 +1,4 @@
/**
* TinyMCE version 7.7.2 (2025-03-19)
*/
!function(){"use strict";var e=tinymce.util.Tools.resolve("tinymce.PluginManager");const o=e=>"function"==typeof e;var t=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),n=tinymce.util.Tools.resolve("tinymce.util.Tools");const a=e=>o=>o.options.get(e),c=a("save_enablewhendirty"),i=a("save_onsavecallback"),s=a("save_oncancelcallback"),r=(e,o)=>{e.notificationManager.open({text:o,type:"error"})},l=e=>o=>{const t=()=>{o.setEnabled(!c(e)||e.isDirty())};return t(),e.on("NodeChange dirty",t),()=>e.off("NodeChange dirty",t)};e.add("save",(e=>{(e=>{const o=e.options.register;o("save_enablewhendirty",{processor:"boolean",default:!0}),o("save_onsavecallback",{processor:"function"}),o("save_oncancelcallback",{processor:"function"})})(e),(e=>{e.ui.registry.addButton("save",{icon:"save",tooltip:"Save",enabled:!1,onAction:()=>e.execCommand("mceSave"),onSetup:l(e),shortcut:"Meta+S"}),e.ui.registry.addButton("cancel",{icon:"cancel",tooltip:"Cancel",enabled:!1,onAction:()=>e.execCommand("mceCancel"),onSetup:l(e)}),e.addShortcut("Meta+S","","mceSave")})(e),(e=>{e.addCommand("mceSave",(()=>{(e=>{const n=t.DOM.getParent(e.id,"form");if(c(e)&&!e.isDirty())return;e.save();const a=i(e);if(o(a))return a.call(e,e),void e.nodeChanged();n?(e.setDirty(!1),n.onsubmit&&!n.onsubmit()||("function"==typeof n.submit?n.submit():r(e,"Error: Form submit field collision.")),e.nodeChanged()):r(e,"Error: No form element found.")})(e)})),e.addCommand("mceCancel",(()=>{(e=>{const t=n.trim(e.startContent),a=s(e);o(a)?a.call(e,e):e.resetContent(t)})(e)}))})(e)}))}();