tinymce_plugins_preview.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/preview/plugin.js
  5. var require_plugin = __commonJS({
  6. "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/preview/plugin.js"() {
  7. (function() {
  8. "use strict";
  9. var global$2 = tinymce.util.Tools.resolve("tinymce.PluginManager");
  10. var global$1 = tinymce.util.Tools.resolve("tinymce.Env");
  11. var global = tinymce.util.Tools.resolve("tinymce.util.Tools");
  12. var getContentStyle = function(editor) {
  13. return editor.getParam("content_style", "", "string");
  14. };
  15. var shouldUseContentCssCors = function(editor) {
  16. return editor.getParam("content_css_cors", false, "boolean");
  17. };
  18. var getBodyClassByHash = function(editor) {
  19. var bodyClass = editor.getParam("body_class", "", "hash");
  20. return bodyClass[editor.id] || "";
  21. };
  22. var getBodyClass = function(editor) {
  23. var bodyClass = editor.getParam("body_class", "", "string");
  24. if (bodyClass.indexOf("=") === -1) {
  25. return bodyClass;
  26. } else {
  27. return getBodyClassByHash(editor);
  28. }
  29. };
  30. var getBodyIdByHash = function(editor) {
  31. var bodyId = editor.getParam("body_id", "", "hash");
  32. return bodyId[editor.id] || bodyId;
  33. };
  34. var getBodyId = function(editor) {
  35. var bodyId = editor.getParam("body_id", "tinymce", "string");
  36. if (bodyId.indexOf("=") === -1) {
  37. return bodyId;
  38. } else {
  39. return getBodyIdByHash(editor);
  40. }
  41. };
  42. var getPreviewHtml = function(editor) {
  43. var headHtml = "";
  44. var encode = editor.dom.encode;
  45. var contentStyle = getContentStyle(editor);
  46. headHtml += '<base href="' + encode(editor.documentBaseURI.getURI()) + '">';
  47. var cors = shouldUseContentCssCors(editor) ? ' crossorigin="anonymous"' : "";
  48. global.each(editor.contentCSS, function(url) {
  49. headHtml += '<link type="text/css" rel="stylesheet" href="' + encode(editor.documentBaseURI.toAbsolute(url)) + '"' + cors + ">";
  50. });
  51. if (contentStyle) {
  52. headHtml += '<style type="text/css">' + contentStyle + "</style>";
  53. }
  54. var bodyId = getBodyId(editor);
  55. var bodyClass = getBodyClass(editor);
  56. var isMetaKeyPressed = global$1.mac ? "e.metaKey" : "e.ctrlKey && !e.altKey";
  57. var 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> ";
  58. var directionality = editor.getBody().dir;
  59. var dirAttr = directionality ? ' dir="' + encode(directionality) + '"' : "";
  60. var previewHtml = "<!DOCTYPE html><html><head>" + headHtml + '</head><body id="' + encode(bodyId) + '" class="mce-content-body ' + encode(bodyClass) + '"' + dirAttr + ">" + editor.getContent() + preventClicksOnLinksScript + "</body></html>";
  61. return previewHtml;
  62. };
  63. var open = function(editor) {
  64. var content = getPreviewHtml(editor);
  65. var dataApi = editor.windowManager.open({
  66. title: "Preview",
  67. size: "large",
  68. body: {
  69. type: "panel",
  70. items: [{
  71. name: "preview",
  72. type: "iframe",
  73. sandboxed: true
  74. }]
  75. },
  76. buttons: [{
  77. type: "cancel",
  78. name: "close",
  79. text: "Close",
  80. primary: true
  81. }],
  82. initialData: { preview: content }
  83. });
  84. dataApi.focus("close");
  85. };
  86. var register$1 = function(editor) {
  87. editor.addCommand("mcePreview", function() {
  88. open(editor);
  89. });
  90. };
  91. var register = function(editor) {
  92. var onAction = function() {
  93. return editor.execCommand("mcePreview");
  94. };
  95. editor.ui.registry.addButton("preview", {
  96. icon: "preview",
  97. tooltip: "Preview",
  98. onAction
  99. });
  100. editor.ui.registry.addMenuItem("preview", {
  101. icon: "preview",
  102. text: "Preview",
  103. onAction
  104. });
  105. };
  106. function Plugin() {
  107. global$2.add("preview", function(editor) {
  108. register$1(editor);
  109. register(editor);
  110. });
  111. }
  112. Plugin();
  113. })();
  114. }
  115. });
  116. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/preview/index.js
  117. require_plugin();
  118. //# sourceMappingURL=tinymce_plugins_preview.js.map