富文本

This commit is contained in:
2024-12-22 17:14:01 +08:00
parent dcea82e412
commit 1bcd94ec3f
216 changed files with 132481 additions and 1 deletions

View File

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

View File

@@ -0,0 +1,99 @@
/**
* TinyMCE version 7.5.1 (TBD)
*/
(function () {
'use strict';
var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager');
var global$1 = tinymce.util.Tools.resolve('tinymce.Env');
var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
const option = name => editor => editor.options.get(name);
const getContentStyle = option('content_style');
const shouldUseContentCssCors = option('content_css_cors');
const getBodyClass = option('body_class');
const getBodyId = option('body_id');
const getPreviewHtml = editor => {
var _a;
let headHtml = '';
const encode = editor.dom.encode;
const contentStyle = (_a = getContentStyle(editor)) !== null && _a !== void 0 ? _a : '';
headHtml += '<base href="' + encode(editor.documentBaseURI.getURI()) + '">';
const cors = shouldUseContentCssCors(editor) ? ' crossorigin="anonymous"' : '';
global.each(editor.contentCSS, url => {
headHtml += '<link type="text/css" rel="stylesheet" href="' + encode(editor.documentBaseURI.toAbsolute(url)) + '"' + cors + '>';
});
if (contentStyle) {
headHtml += '<style type="text/css">' + contentStyle + '</style>';
}
const bodyId = getBodyId(editor);
const bodyClass = getBodyClass(editor);
const isMetaKeyPressed = global$1.os.isMacOS() || global$1.os.isiOS() ? 'e.metaKey' : 'e.ctrlKey && !e.altKey';
const preventClicksOnLinksScript = '<script>' + 'document.addEventListener && document.addEventListener("click", function(e) {' + 'for (var elm = e.target; elm; elm = elm.parentNode) {' + 'if (elm.nodeName === "A" && !(' + isMetaKeyPressed + ')) {' + 'e.preventDefault();' + '}' + '}' + '}, false);' + '</script> ';
const directionality = editor.getBody().dir;
const dirAttr = directionality ? ' dir="' + encode(directionality) + '"' : '';
const previewHtml = '<!DOCTYPE html>' + '<html>' + '<head>' + headHtml + '</head>' + '<body id="' + encode(bodyId) + '" class="mce-content-body ' + encode(bodyClass) + '"' + dirAttr + '>' + editor.getContent() + preventClicksOnLinksScript + '</body>' + '</html>';
return previewHtml;
};
const open = editor => {
const content = getPreviewHtml(editor);
const dataApi = editor.windowManager.open({
title: 'Preview',
size: 'large',
body: {
type: 'panel',
items: [{
name: 'preview',
type: 'iframe',
sandboxed: true,
transparent: false
}]
},
buttons: [{
type: 'cancel',
name: 'close',
text: 'Close',
primary: true
}],
initialData: { preview: content }
});
dataApi.focus('close');
};
const register$1 = editor => {
editor.addCommand('mcePreview', () => {
open(editor);
});
};
const register = editor => {
const onAction = () => editor.execCommand('mcePreview');
editor.ui.registry.addButton('preview', {
icon: 'preview',
tooltip: 'Preview',
onAction,
context: 'any'
});
editor.ui.registry.addMenuItem('preview', {
icon: 'preview',
text: 'Preview',
onAction,
context: 'any'
});
};
var Plugin = () => {
global$2.add('preview', editor => {
register$1(editor);
register(editor);
});
};
Plugin();
})();

View File

@@ -0,0 +1,4 @@
/**
* TinyMCE version 7.5.1 (TBD)
*/
!function(){"use strict";var e=tinymce.util.Tools.resolve("tinymce.PluginManager"),t=tinymce.util.Tools.resolve("tinymce.Env"),n=tinymce.util.Tools.resolve("tinymce.util.Tools");const o=e=>t=>t.options.get(e),i=o("content_style"),s=o("content_css_cors"),c=o("body_class"),r=o("body_id");e.add("preview",(e=>{(e=>{e.addCommand("mcePreview",(()=>{(e=>{const o=(e=>{var o;let a="";const l=e.dom.encode,d=null!==(o=i(e))&&void 0!==o?o:"";a+='<base href="'+l(e.documentBaseURI.getURI())+'">';const m=s(e)?' crossorigin="anonymous"':"";n.each(e.contentCSS,(t=>{a+='<link type="text/css" rel="stylesheet" href="'+l(e.documentBaseURI.toAbsolute(t))+'"'+m+">"})),d&&(a+='<style type="text/css">'+d+"</style>");const y=r(e),u=c(e),v='<script>document.addEventListener && document.addEventListener("click", function(e) {for (var elm = e.target; elm; elm = elm.parentNode) {if (elm.nodeName === "A" && !('+(t.os.isMacOS()||t.os.isiOS()?"e.metaKey":"e.ctrlKey && !e.altKey")+")) {e.preventDefault();}}}, false);<\/script> ",p=e.getBody().dir,w=p?' dir="'+l(p)+'"':"";return"<!DOCTYPE html><html><head>"+a+'</head><body id="'+l(y)+'" class="mce-content-body '+l(u)+'"'+w+">"+e.getContent()+v+"</body></html>"})(e);e.windowManager.open({title:"Preview",size:"large",body:{type:"panel",items:[{name:"preview",type:"iframe",sandboxed:!0,transparent:!1}]},buttons:[{type:"cancel",name:"close",text:"Close",primary:!0}],initialData:{preview:o}}).focus("close")})(e)}))})(e),(e=>{const t=()=>e.execCommand("mcePreview");e.ui.registry.addButton("preview",{icon:"preview",tooltip:"Preview",onAction:t,context:"any"}),e.ui.registry.addMenuItem("preview",{icon:"preview",text:"Preview",onAction:t,context:"any"})})(e)}))}();