123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- import {
- __commonJS,
- init_define_APP_INFO
- } from "./chunk-XY75H3MP.js";
- // node_modules/tinymce/plugins/template/plugin.js
- var require_plugin = __commonJS({
- "node_modules/tinymce/plugins/template/plugin.js"() {
- init_define_APP_INFO();
- (function() {
- "use strict";
- var global$4 = tinymce.util.Tools.resolve("tinymce.PluginManager");
- var typeOf = function(x) {
- var t = typeof x;
- if (x === null) {
- return "null";
- } else if (t === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
- return "array";
- } else if (t === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
- return "string";
- } else {
- return t;
- }
- };
- var isType = function(type) {
- return function(value) {
- return typeOf(value) === type;
- };
- };
- var isSimpleType = function(type) {
- return function(value) {
- return typeof value === type;
- };
- };
- var isString = isType("string");
- var isFunction = isSimpleType("function");
- var noop = function() {
- };
- var constant = function(value) {
- return function() {
- return value;
- };
- };
- var identity = function(x) {
- return x;
- };
- function curry(fn) {
- var initialArgs = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- initialArgs[_i - 1] = arguments[_i];
- }
- return function() {
- var restArgs = [];
- for (var _i2 = 0; _i2 < arguments.length; _i2++) {
- restArgs[_i2] = arguments[_i2];
- }
- var all = initialArgs.concat(restArgs);
- return fn.apply(null, all);
- };
- }
- var never = constant(false);
- var always = constant(true);
- var global$3 = tinymce.util.Tools.resolve("tinymce.util.Tools");
- var global$2 = tinymce.util.Tools.resolve("tinymce.util.XHR");
- var getCreationDateClasses = function(editor) {
- return editor.getParam("template_cdate_classes", "cdate");
- };
- var getModificationDateClasses = function(editor) {
- return editor.getParam("template_mdate_classes", "mdate");
- };
- var getSelectedContentClasses = function(editor) {
- return editor.getParam("template_selected_content_classes", "selcontent");
- };
- var getPreviewReplaceValues = function(editor) {
- return editor.getParam("template_preview_replace_values");
- };
- var getContentStyle = function(editor) {
- return editor.getParam("content_style", "", "string");
- };
- var shouldUseContentCssCors = function(editor) {
- return editor.getParam("content_css_cors", false, "boolean");
- };
- var getTemplateReplaceValues = function(editor) {
- return editor.getParam("template_replace_values");
- };
- var getTemplates = function(editor) {
- return editor.getParam("templates");
- };
- var getCdateFormat = function(editor) {
- return editor.getParam("template_cdate_format", editor.translate("%Y-%m-%d"));
- };
- var getMdateFormat = function(editor) {
- return editor.getParam("template_mdate_format", editor.translate("%Y-%m-%d"));
- };
- var getBodyClassFromHash = function(editor) {
- var bodyClass = editor.getParam("body_class", "", "hash");
- return bodyClass[editor.id] || "";
- };
- var getBodyClass = function(editor) {
- var bodyClass = editor.getParam("body_class", "", "string");
- if (bodyClass.indexOf("=") === -1) {
- return bodyClass;
- } else {
- return getBodyClassFromHash(editor);
- }
- };
- var addZeros = function(value, len) {
- value = "" + value;
- if (value.length < len) {
- for (var i = 0; i < len - value.length; i++) {
- value = "0" + value;
- }
- }
- return value;
- };
- var getDateTime = function(editor, fmt, date) {
- if (date === void 0) {
- date = new Date();
- }
- var daysShort = "Sun Mon Tue Wed Thu Fri Sat Sun".split(" ");
- var daysLong = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" ");
- var monthsShort = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ");
- var monthsLong = "January February March April May June July August September October November December".split(" ");
- fmt = fmt.replace("%D", "%m/%d/%Y");
- fmt = fmt.replace("%r", "%I:%M:%S %p");
- fmt = fmt.replace("%Y", "" + date.getFullYear());
- fmt = fmt.replace("%y", "" + date.getYear());
- fmt = fmt.replace("%m", addZeros(date.getMonth() + 1, 2));
- fmt = fmt.replace("%d", addZeros(date.getDate(), 2));
- fmt = fmt.replace("%H", "" + addZeros(date.getHours(), 2));
- fmt = fmt.replace("%M", "" + addZeros(date.getMinutes(), 2));
- fmt = fmt.replace("%S", "" + addZeros(date.getSeconds(), 2));
- fmt = fmt.replace("%I", "" + ((date.getHours() + 11) % 12 + 1));
- fmt = fmt.replace("%p", date.getHours() < 12 ? "AM" : "PM");
- fmt = fmt.replace("%B", "" + editor.translate(monthsLong[date.getMonth()]));
- fmt = fmt.replace("%b", "" + editor.translate(monthsShort[date.getMonth()]));
- fmt = fmt.replace("%A", "" + editor.translate(daysLong[date.getDay()]));
- fmt = fmt.replace("%a", "" + editor.translate(daysShort[date.getDay()]));
- fmt = fmt.replace("%%", "%");
- return fmt;
- };
- var createTemplateList = function(editor, callback) {
- return function() {
- var templateList = getTemplates(editor);
- if (isFunction(templateList)) {
- templateList(callback);
- } else if (isString(templateList)) {
- global$2.send({
- url: templateList,
- success: function(text) {
- callback(JSON.parse(text));
- }
- });
- } else {
- callback(templateList);
- }
- };
- };
- var replaceTemplateValues = function(html, templateValues) {
- global$3.each(templateValues, function(v, k) {
- if (isFunction(v)) {
- v = v(k);
- }
- html = html.replace(new RegExp("\\{\\$" + k + "\\}", "g"), v);
- });
- return html;
- };
- var replaceVals = function(editor, scope) {
- var dom = editor.dom, vl = getTemplateReplaceValues(editor);
- global$3.each(dom.select("*", scope), function(e) {
- global$3.each(vl, function(v, k) {
- if (dom.hasClass(e, k)) {
- if (isFunction(v)) {
- v(e);
- }
- }
- });
- });
- };
- var hasClass = function(n, c) {
- return new RegExp("\\b" + c + "\\b", "g").test(n.className);
- };
- var insertTemplate = function(editor, _ui, html) {
- var dom = editor.dom;
- var sel = editor.selection.getContent();
- html = replaceTemplateValues(html, getTemplateReplaceValues(editor));
- var el = dom.create("div", null, html);
- var n = dom.select(".mceTmpl", el);
- if (n && n.length > 0) {
- el = dom.create("div", null);
- el.appendChild(n[0].cloneNode(true));
- }
- global$3.each(dom.select("*", el), function(n2) {
- if (hasClass(n2, getCreationDateClasses(editor).replace(/\s+/g, "|"))) {
- n2.innerHTML = getDateTime(editor, getCdateFormat(editor));
- }
- if (hasClass(n2, getModificationDateClasses(editor).replace(/\s+/g, "|"))) {
- n2.innerHTML = getDateTime(editor, getMdateFormat(editor));
- }
- if (hasClass(n2, getSelectedContentClasses(editor).replace(/\s+/g, "|"))) {
- n2.innerHTML = sel;
- }
- });
- replaceVals(editor, el);
- editor.execCommand("mceInsertContent", false, el.innerHTML);
- editor.addVisual();
- };
- var none = function() {
- return NONE;
- };
- var NONE = function() {
- var call = function(thunk) {
- return thunk();
- };
- var id = identity;
- var me = {
- fold: function(n, _s) {
- return n();
- },
- isSome: never,
- isNone: always,
- getOr: id,
- getOrThunk: call,
- getOrDie: function(msg) {
- throw new Error(msg || "error: getOrDie called on none.");
- },
- getOrNull: constant(null),
- getOrUndefined: constant(void 0),
- or: id,
- orThunk: call,
- map: none,
- each: noop,
- bind: none,
- exists: never,
- forall: always,
- filter: function() {
- return none();
- },
- toArray: function() {
- return [];
- },
- toString: constant("none()")
- };
- return me;
- }();
- var some = function(a) {
- var constant_a = constant(a);
- var self = function() {
- return me;
- };
- var bind = function(f) {
- return f(a);
- };
- var me = {
- fold: function(n, s) {
- return s(a);
- },
- isSome: always,
- isNone: never,
- getOr: constant_a,
- getOrThunk: constant_a,
- getOrDie: constant_a,
- getOrNull: constant_a,
- getOrUndefined: constant_a,
- or: self,
- orThunk: self,
- map: function(f) {
- return some(f(a));
- },
- each: function(f) {
- f(a);
- },
- bind,
- exists: bind,
- forall: bind,
- filter: function(f) {
- return f(a) ? me : NONE;
- },
- toArray: function() {
- return [a];
- },
- toString: function() {
- return "some(" + a + ")";
- }
- };
- return me;
- };
- var from = function(value) {
- return value === null || value === void 0 ? NONE : some(value);
- };
- var Optional = {
- some,
- none,
- from
- };
- var map = function(xs, f) {
- var len = xs.length;
- var r = new Array(len);
- for (var i = 0; i < len; i++) {
- var x = xs[i];
- r[i] = f(x, i);
- }
- return r;
- };
- var findUntil = function(xs, pred, until) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- return Optional.some(x);
- } else if (until(x, i)) {
- break;
- }
- }
- return Optional.none();
- };
- var find = function(xs, pred) {
- return findUntil(xs, pred, never);
- };
- var global$1 = tinymce.util.Tools.resolve("tinymce.Env");
- var global = tinymce.util.Tools.resolve("tinymce.util.Promise");
- var hasOwnProperty = Object.hasOwnProperty;
- var get = function(obj, key) {
- return has(obj, key) ? Optional.from(obj[key]) : Optional.none();
- };
- var has = function(obj, key) {
- return hasOwnProperty.call(obj, key);
- };
- var entitiesAttr = {
- '"': """,
- "<": "<",
- ">": ">",
- "&": "&",
- "'": "'"
- };
- var htmlEscape = function(html) {
- return html.replace(/["'<>&]/g, function(match) {
- return get(entitiesAttr, match).getOr(match);
- });
- };
- var getPreviewContent = function(editor, html) {
- if (html.indexOf("<html>") === -1) {
- var contentCssEntries_1 = "";
- var contentStyle = getContentStyle(editor);
- var cors_1 = shouldUseContentCssCors(editor) ? ' crossorigin="anonymous"' : "";
- global$3.each(editor.contentCSS, function(url) {
- contentCssEntries_1 += '<link type="text/css" rel="stylesheet" href="' + editor.documentBaseURI.toAbsolute(url) + '"' + cors_1 + ">";
- });
- if (contentStyle) {
- contentCssEntries_1 += '<style type="text/css">' + contentStyle + "</style>";
- }
- var bodyClass = getBodyClass(editor);
- var encode = editor.dom.encode;
- var isMetaKeyPressed = global$1.mac ? "e.metaKey" : "e.ctrlKey && !e.altKey";
- 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> ";
- var directionality = editor.getBody().dir;
- var dirAttr = directionality ? ' dir="' + encode(directionality) + '"' : "";
- html = '<!DOCTYPE html><html><head><base href="' + encode(editor.documentBaseURI.getURI()) + '">' + contentCssEntries_1 + preventClicksOnLinksScript + '</head><body class="' + encode(bodyClass) + '"' + dirAttr + ">" + html + "</body></html>";
- }
- return replaceTemplateValues(html, getPreviewReplaceValues(editor));
- };
- var open = function(editor, templateList) {
- var createTemplates = function() {
- if (!templateList || templateList.length === 0) {
- var message = editor.translate("No templates defined.");
- editor.notificationManager.open({
- text: message,
- type: "info"
- });
- return Optional.none();
- }
- return Optional.from(global$3.map(templateList, function(template, index) {
- var isUrlTemplate = function(t) {
- return t.url !== void 0;
- };
- return {
- selected: index === 0,
- text: template.title,
- value: {
- url: isUrlTemplate(template) ? Optional.from(template.url) : Optional.none(),
- content: !isUrlTemplate(template) ? Optional.from(template.content) : Optional.none(),
- description: template.description
- }
- };
- }));
- };
- var createSelectBoxItems = function(templates) {
- return map(templates, function(t) {
- return {
- text: t.text,
- value: t.text
- };
- });
- };
- var findTemplate = function(templates, templateTitle) {
- return find(templates, function(t) {
- return t.text === templateTitle;
- });
- };
- var loadFailedAlert = function(api) {
- editor.windowManager.alert("Could not load the specified template.", function() {
- return api.focus("template");
- });
- };
- var getTemplateContent = function(t) {
- return new global(function(resolve, reject) {
- t.value.url.fold(function() {
- return resolve(t.value.content.getOr(""));
- }, function(url) {
- return global$2.send({
- url,
- success: function(html) {
- resolve(html);
- },
- error: function(e) {
- reject(e);
- }
- });
- });
- });
- };
- var onChange = function(templates, updateDialog) {
- return function(api, change) {
- if (change.name === "template") {
- var newTemplateTitle = api.getData().template;
- findTemplate(templates, newTemplateTitle).each(function(t) {
- api.block("Loading...");
- getTemplateContent(t).then(function(previewHtml) {
- updateDialog(api, t, previewHtml);
- }).catch(function() {
- updateDialog(api, t, "");
- api.disable("save");
- loadFailedAlert(api);
- });
- });
- }
- };
- };
- var onSubmit = function(templates) {
- return function(api) {
- var data = api.getData();
- findTemplate(templates, data.template).each(function(t) {
- getTemplateContent(t).then(function(previewHtml) {
- editor.execCommand("mceInsertTemplate", false, previewHtml);
- api.close();
- }).catch(function() {
- api.disable("save");
- loadFailedAlert(api);
- });
- });
- };
- };
- var openDialog = function(templates) {
- var selectBoxItems = createSelectBoxItems(templates);
- var buildDialogSpec = function(bodyItems, initialData) {
- return {
- title: "Insert Template",
- size: "large",
- body: {
- type: "panel",
- items: bodyItems
- },
- initialData,
- buttons: [
- {
- type: "cancel",
- name: "cancel",
- text: "Cancel"
- },
- {
- type: "submit",
- name: "save",
- text: "Save",
- primary: true
- }
- ],
- onSubmit: onSubmit(templates),
- onChange: onChange(templates, updateDialog)
- };
- };
- var updateDialog = function(dialogApi2, template, previewHtml) {
- var content = getPreviewContent(editor, previewHtml);
- var bodyItems = [
- {
- type: "selectbox",
- name: "template",
- label: "Templates",
- items: selectBoxItems
- },
- {
- type: "htmlpanel",
- html: '<p aria-live="polite">' + htmlEscape(template.value.description) + "</p>"
- },
- {
- label: "Preview",
- type: "iframe",
- name: "preview",
- sandboxed: false
- }
- ];
- var initialData = {
- template: template.text,
- preview: content
- };
- dialogApi2.unblock();
- dialogApi2.redial(buildDialogSpec(bodyItems, initialData));
- dialogApi2.focus("template");
- };
- var dialogApi = editor.windowManager.open(buildDialogSpec([], {
- template: "",
- preview: ""
- }));
- dialogApi.block("Loading...");
- getTemplateContent(templates[0]).then(function(previewHtml) {
- updateDialog(dialogApi, templates[0], previewHtml);
- }).catch(function() {
- updateDialog(dialogApi, templates[0], "");
- dialogApi.disable("save");
- loadFailedAlert(dialogApi);
- });
- };
- var optTemplates = createTemplates();
- optTemplates.each(openDialog);
- };
- var showDialog = function(editor) {
- return function(templates) {
- open(editor, templates);
- };
- };
- var register$1 = function(editor) {
- editor.addCommand("mceInsertTemplate", curry(insertTemplate, editor));
- editor.addCommand("mceTemplate", createTemplateList(editor, showDialog(editor)));
- };
- var setup = function(editor) {
- editor.on("PreProcess", function(o) {
- var dom = editor.dom, dateFormat = getMdateFormat(editor);
- global$3.each(dom.select("div", o.node), function(e) {
- if (dom.hasClass(e, "mceTmpl")) {
- global$3.each(dom.select("*", e), function(e2) {
- if (dom.hasClass(e2, getModificationDateClasses(editor).replace(/\s+/g, "|"))) {
- e2.innerHTML = getDateTime(editor, dateFormat);
- }
- });
- replaceVals(editor, e);
- }
- });
- });
- };
- var register = function(editor) {
- var onAction = function() {
- return editor.execCommand("mceTemplate");
- };
- editor.ui.registry.addButton("template", {
- icon: "template",
- tooltip: "Insert template",
- onAction
- });
- editor.ui.registry.addMenuItem("template", {
- icon: "template",
- text: "Insert template...",
- onAction
- });
- };
- function Plugin() {
- global$4.add("template", function(editor) {
- register(editor);
- register$1(editor);
- setup(editor);
- });
- }
- Plugin();
- })();
- }
- });
- // node_modules/tinymce/plugins/template/index.js
- var require_template = __commonJS({
- "node_modules/tinymce/plugins/template/index.js"() {
- init_define_APP_INFO();
- require_plugin();
- }
- });
- // dep:tinymce_plugins_template
- init_define_APP_INFO();
- var tinymce_plugins_template_default = require_template();
- export {
- tinymce_plugins_template_default as default
- };
- //# sourceMappingURL=tinymce_plugins_template.js.map
|