1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762 |
- import {
- __commonJS
- } from "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/paste/plugin.js
- var require_plugin = __commonJS({
- "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/paste/plugin.js"() {
- (function() {
- "use strict";
- var Cell = function(initial) {
- var value2 = initial;
- var get2 = function() {
- return value2;
- };
- var set = function(v) {
- value2 = v;
- };
- return {
- get: get2,
- set
- };
- };
- var global$b = tinymce.util.Tools.resolve("tinymce.PluginManager");
- var hasProPlugin = function(editor) {
- if (editor.hasPlugin("powerpaste", true)) {
- if (typeof window.console !== "undefined" && window.console.log) {
- window.console.log("PowerPaste is incompatible with Paste plugin! Remove 'paste' from the 'plugins' option.");
- }
- return true;
- } else {
- return false;
- }
- };
- var get = function(clipboard) {
- return { clipboard };
- };
- 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(value2) {
- return typeOf(value2) === type;
- };
- };
- var isSimpleType = function(type) {
- return function(value2) {
- return typeof value2 === type;
- };
- };
- var isArray = isType("array");
- var isNullable = function(a) {
- return a === null || a === void 0;
- };
- var isNonNullable = function(a) {
- return !isNullable(a);
- };
- var isFunction = isSimpleType("function");
- var noop = function() {
- };
- var constant = function(value2) {
- return function() {
- return value2;
- };
- };
- var identity = function(x) {
- return x;
- };
- var never = constant(false);
- var always = constant(true);
- 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 bind2 = 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: bind2,
- exists: bind2,
- forall: bind2,
- filter: function(f) {
- return f(a) ? me : NONE;
- },
- toArray: function() {
- return [a];
- },
- toString: function() {
- return "some(" + a + ")";
- }
- };
- return me;
- };
- var from$1 = function(value2) {
- return value2 === null || value2 === void 0 ? NONE : some(value2);
- };
- var Optional = {
- some,
- none,
- from: from$1
- };
- var nativeSlice = Array.prototype.slice;
- var nativePush = Array.prototype.push;
- var exists = function(xs, pred) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- return true;
- }
- }
- return false;
- };
- 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 each = function(xs, f) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- f(x, i);
- }
- };
- var filter$1 = function(xs, pred) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- r.push(x);
- }
- }
- return r;
- };
- var foldl = function(xs, f, acc) {
- each(xs, function(x, i) {
- acc = f(acc, x, i);
- });
- return acc;
- };
- var flatten = function(xs) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; ++i) {
- if (!isArray(xs[i])) {
- throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
- }
- nativePush.apply(r, xs[i]);
- }
- return r;
- };
- var bind = function(xs, f) {
- return flatten(map(xs, f));
- };
- var from = isFunction(Array.from) ? Array.from : function(x) {
- return nativeSlice.call(x);
- };
- var __assign = function() {
- __assign = Object.assign || function __assign2(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s)
- if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var singleton = function(doRevoke) {
- var subject = Cell(Optional.none());
- var revoke = function() {
- return subject.get().each(doRevoke);
- };
- var clear = function() {
- revoke();
- subject.set(Optional.none());
- };
- var isSet = function() {
- return subject.get().isSome();
- };
- var get2 = function() {
- return subject.get();
- };
- var set = function(s) {
- revoke();
- subject.set(Optional.some(s));
- };
- return {
- clear,
- isSet,
- get: get2,
- set
- };
- };
- var value = function() {
- var subject = singleton(noop);
- var on = function(f) {
- return subject.get().each(f);
- };
- return __assign(__assign({}, subject), { on });
- };
- var checkRange = function(str, substr, start) {
- return substr === "" || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
- };
- var startsWith = function(str, prefix) {
- return checkRange(str, prefix, 0);
- };
- var endsWith = function(str, suffix) {
- return checkRange(str, suffix, str.length - suffix.length);
- };
- var repeat = function(s, count) {
- return count <= 0 ? "" : new Array(count + 1).join(s);
- };
- var global$a = tinymce.util.Tools.resolve("tinymce.Env");
- var global$9 = tinymce.util.Tools.resolve("tinymce.util.Delay");
- var global$8 = tinymce.util.Tools.resolve("tinymce.util.Promise");
- var global$7 = tinymce.util.Tools.resolve("tinymce.util.VK");
- var firePastePreProcess = function(editor, html, internal, isWordHtml) {
- return editor.fire("PastePreProcess", {
- content: html,
- internal,
- wordContent: isWordHtml
- });
- };
- var firePastePostProcess = function(editor, node, internal, isWordHtml) {
- return editor.fire("PastePostProcess", {
- node,
- internal,
- wordContent: isWordHtml
- });
- };
- var firePastePlainTextToggle = function(editor, state) {
- return editor.fire("PastePlainTextToggle", { state });
- };
- var firePaste = function(editor, ieFake) {
- return editor.fire("paste", { ieFake });
- };
- var global$6 = tinymce.util.Tools.resolve("tinymce.util.Tools");
- var shouldBlockDrop = function(editor) {
- return editor.getParam("paste_block_drop", false);
- };
- var shouldPasteDataImages = function(editor) {
- return editor.getParam("paste_data_images", false);
- };
- var shouldFilterDrop = function(editor) {
- return editor.getParam("paste_filter_drop", true);
- };
- var getPreProcess = function(editor) {
- return editor.getParam("paste_preprocess");
- };
- var getPostProcess = function(editor) {
- return editor.getParam("paste_postprocess");
- };
- var getWebkitStyles = function(editor) {
- return editor.getParam("paste_webkit_styles");
- };
- var shouldRemoveWebKitStyles = function(editor) {
- return editor.getParam("paste_remove_styles_if_webkit", true);
- };
- var shouldMergeFormats = function(editor) {
- return editor.getParam("paste_merge_formats", true);
- };
- var isSmartPasteEnabled = function(editor) {
- return editor.getParam("smart_paste", true);
- };
- var isPasteAsTextEnabled = function(editor) {
- return editor.getParam("paste_as_text", false);
- };
- var getRetainStyleProps = function(editor) {
- return editor.getParam("paste_retain_style_properties");
- };
- var getWordValidElements = function(editor) {
- var defaultValidElements = "-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-p/div,-a[href|name],sub,sup,strike,br,del,table[width],tr,td[colspan|rowspan|width],th[colspan|rowspan|width],thead,tfoot,tbody";
- return editor.getParam("paste_word_valid_elements", defaultValidElements);
- };
- var shouldConvertWordFakeLists = function(editor) {
- return editor.getParam("paste_convert_word_fake_lists", true);
- };
- var shouldUseDefaultFilters = function(editor) {
- return editor.getParam("paste_enable_default_filters", true);
- };
- var getValidate = function(editor) {
- return editor.getParam("validate");
- };
- var getAllowHtmlDataUrls = function(editor) {
- return editor.getParam("allow_html_data_urls", false, "boolean");
- };
- var getPasteDataImages = function(editor) {
- return editor.getParam("paste_data_images", false, "boolean");
- };
- var getImagesDataImgFilter = function(editor) {
- return editor.getParam("images_dataimg_filter");
- };
- var getImagesReuseFilename = function(editor) {
- return editor.getParam("images_reuse_filename");
- };
- var getForcedRootBlock = function(editor) {
- return editor.getParam("forced_root_block");
- };
- var getForcedRootBlockAttrs = function(editor) {
- return editor.getParam("forced_root_block_attrs");
- };
- var getTabSpaces = function(editor) {
- return editor.getParam("paste_tab_spaces", 4, "number");
- };
- var getAllowedImageFileTypes = function(editor) {
- var defaultImageFileTypes = "jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp";
- return global$6.explode(editor.getParam("images_file_types", defaultImageFileTypes, "string"));
- };
- var internalMimeType = "x-tinymce/html";
- var internalMark = "<!-- " + internalMimeType + " -->";
- var mark = function(html) {
- return internalMark + html;
- };
- var unmark = function(html) {
- return html.replace(internalMark, "");
- };
- var isMarked = function(html) {
- return html.indexOf(internalMark) !== -1;
- };
- var internalHtmlMime = constant(internalMimeType);
- var hasOwnProperty = Object.hasOwnProperty;
- var has = function(obj, key) {
- return hasOwnProperty.call(obj, key);
- };
- var global$5 = tinymce.util.Tools.resolve("tinymce.html.Entities");
- var isPlainText = function(text) {
- return !/<(?:\/?(?!(?:div|p|br|span)>)\w+|(?:(?!(?:span style="white-space:\s?pre;?">)|br\s?\/>))\w+\s[^>]+)>/i.test(text);
- };
- var toBRs = function(text) {
- return text.replace(/\r?\n/g, "<br>");
- };
- var openContainer = function(rootTag, rootAttrs) {
- var attrs = [];
- var tag = "<" + rootTag;
- if (typeof rootAttrs === "object") {
- for (var key in rootAttrs) {
- if (has(rootAttrs, key)) {
- attrs.push(key + '="' + global$5.encodeAllRaw(rootAttrs[key]) + '"');
- }
- }
- if (attrs.length) {
- tag += " " + attrs.join(" ");
- }
- }
- return tag + ">";
- };
- var toBlockElements = function(text, rootTag, rootAttrs) {
- var blocks = text.split(/\n\n/);
- var tagOpen = openContainer(rootTag, rootAttrs);
- var tagClose = "</" + rootTag + ">";
- var paragraphs = global$6.map(blocks, function(p) {
- return p.split(/\n/).join("<br />");
- });
- var stitch = function(p) {
- return tagOpen + p + tagClose;
- };
- return paragraphs.length === 1 ? paragraphs[0] : global$6.map(paragraphs, stitch).join("");
- };
- var convert = function(text, rootTag, rootAttrs) {
- return rootTag ? toBlockElements(text, rootTag === true ? "p" : rootTag, rootAttrs) : toBRs(text);
- };
- var global$4 = tinymce.util.Tools.resolve("tinymce.html.DomParser");
- var global$3 = tinymce.util.Tools.resolve("tinymce.html.Serializer");
- var nbsp = " ";
- var global$2 = tinymce.util.Tools.resolve("tinymce.html.Node");
- var global$1 = tinymce.util.Tools.resolve("tinymce.html.Schema");
- var isRegExp = function(val) {
- return val.constructor === RegExp;
- };
- var filter = function(content, items) {
- global$6.each(items, function(v) {
- if (isRegExp(v)) {
- content = content.replace(v, "");
- } else {
- content = content.replace(v[0], v[1]);
- }
- });
- return content;
- };
- var innerText = function(html) {
- var schema = global$1();
- var domParser = global$4({}, schema);
- var text = "";
- var shortEndedElements = schema.getShortEndedElements();
- var ignoreElements = global$6.makeMap("script noscript style textarea video audio iframe object", " ");
- var blockElements = schema.getBlockElements();
- var walk = function(node) {
- var name = node.name, currentNode = node;
- if (name === "br") {
- text += "\n";
- return;
- }
- if (name === "wbr") {
- return;
- }
- if (shortEndedElements[name]) {
- text += " ";
- }
- if (ignoreElements[name]) {
- text += " ";
- return;
- }
- if (node.type === 3) {
- text += node.value;
- }
- if (!node.shortEnded) {
- if (node = node.firstChild) {
- do {
- walk(node);
- } while (node = node.next);
- }
- }
- if (blockElements[name] && currentNode.next) {
- text += "\n";
- if (name === "p") {
- text += "\n";
- }
- }
- };
- html = filter(html, [/<!\[[^\]]+\]>/g]);
- walk(domParser.parse(html));
- return text;
- };
- var trimHtml = function(html) {
- var trimSpaces = function(all, s1, s2) {
- if (!s1 && !s2) {
- return " ";
- }
- return nbsp;
- };
- html = filter(html, [
- /^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig,
- /<!--StartFragment-->|<!--EndFragment-->/g,
- [
- /( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g,
- trimSpaces
- ],
- /<br class="Apple-interchange-newline">/g,
- /<br>$/i
- ]);
- return html;
- };
- var createIdGenerator = function(prefix) {
- var count = 0;
- return function() {
- return prefix + count++;
- };
- };
- var getImageMimeType = function(ext) {
- var lowerExt = ext.toLowerCase();
- var mimeOverrides = {
- jpg: "jpeg",
- jpe: "jpeg",
- jfi: "jpeg",
- jif: "jpeg",
- jfif: "jpeg",
- pjpeg: "jpeg",
- pjp: "jpeg",
- svg: "svg+xml"
- };
- return global$6.hasOwn(mimeOverrides, lowerExt) ? "image/" + mimeOverrides[lowerExt] : "image/" + lowerExt;
- };
- var isWordContent = function(content) {
- return /<font face="Times New Roman"|class="?Mso|style="[^"]*\bmso-|style='[^']*\bmso-|w:WordDocument/i.test(content) || /class="OutlineElement/.test(content) || /id="?docs\-internal\-guid\-/.test(content);
- };
- var isNumericList = function(text) {
- var found = false;
- var patterns = [
- /^[IVXLMCD]+\.[ \u00a0]/,
- /^[ivxlmcd]+\.[ \u00a0]/,
- /^[a-z]{1,2}[\.\)][ \u00a0]/,
- /^[A-Z]{1,2}[\.\)][ \u00a0]/,
- /^[0-9]+\.[ \u00a0]/,
- /^[\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+\.[ \u00a0]/,
- /^[\u58f1\u5f10\u53c2\u56db\u4f0d\u516d\u4e03\u516b\u4e5d\u62fe]+\.[ \u00a0]/
- ];
- text = text.replace(/^[\u00a0 ]+/, "");
- global$6.each(patterns, function(pattern) {
- if (pattern.test(text)) {
- found = true;
- return false;
- }
- });
- return found;
- };
- var isBulletList = function(text) {
- return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
- };
- var convertFakeListsToProperLists = function(node) {
- var currentListNode, prevListNode, lastLevel = 1;
- var getText = function(node2) {
- var txt = "";
- if (node2.type === 3) {
- return node2.value;
- }
- if (node2 = node2.firstChild) {
- do {
- txt += getText(node2);
- } while (node2 = node2.next);
- }
- return txt;
- };
- var trimListStart = function(node2, regExp) {
- if (node2.type === 3) {
- if (regExp.test(node2.value)) {
- node2.value = node2.value.replace(regExp, "");
- return false;
- }
- }
- if (node2 = node2.firstChild) {
- do {
- if (!trimListStart(node2, regExp)) {
- return false;
- }
- } while (node2 = node2.next);
- }
- return true;
- };
- var removeIgnoredNodes = function(node2) {
- if (node2._listIgnore) {
- node2.remove();
- return;
- }
- if (node2 = node2.firstChild) {
- do {
- removeIgnoredNodes(node2);
- } while (node2 = node2.next);
- }
- };
- var convertParagraphToLi = function(paragraphNode, listName, start2) {
- var level = paragraphNode._listLevel || lastLevel;
- if (level !== lastLevel) {
- if (level < lastLevel) {
- if (currentListNode) {
- currentListNode = currentListNode.parent.parent;
- }
- } else {
- prevListNode = currentListNode;
- currentListNode = null;
- }
- }
- if (!currentListNode || currentListNode.name !== listName) {
- prevListNode = prevListNode || currentListNode;
- currentListNode = new global$2(listName, 1);
- if (start2 > 1) {
- currentListNode.attr("start", "" + start2);
- }
- paragraphNode.wrap(currentListNode);
- } else {
- currentListNode.append(paragraphNode);
- }
- paragraphNode.name = "li";
- if (level > lastLevel && prevListNode) {
- prevListNode.lastChild.append(currentListNode);
- }
- lastLevel = level;
- removeIgnoredNodes(paragraphNode);
- trimListStart(paragraphNode, /^\u00a0+/);
- trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
- trimListStart(paragraphNode, /^\u00a0+/);
- };
- var elements = [];
- var child = node.firstChild;
- while (typeof child !== "undefined" && child !== null) {
- elements.push(child);
- child = child.walk();
- if (child !== null) {
- while (typeof child !== "undefined" && child.parent !== node) {
- child = child.walk();
- }
- }
- }
- for (var i = 0; i < elements.length; i++) {
- node = elements[i];
- if (node.name === "p" && node.firstChild) {
- var nodeText = getText(node);
- if (isBulletList(nodeText)) {
- convertParagraphToLi(node, "ul");
- continue;
- }
- if (isNumericList(nodeText)) {
- var matches = /([0-9]+)\./.exec(nodeText);
- var start = 1;
- if (matches) {
- start = parseInt(matches[1], 10);
- }
- convertParagraphToLi(node, "ol", start);
- continue;
- }
- if (node._listLevel) {
- convertParagraphToLi(node, "ul", 1);
- continue;
- }
- currentListNode = null;
- } else {
- prevListNode = currentListNode;
- currentListNode = null;
- }
- }
- };
- var filterStyles = function(editor, validStyles, node, styleValue) {
- var outputStyles = {};
- var styles = editor.dom.parseStyle(styleValue);
- global$6.each(styles, function(value2, name) {
- switch (name) {
- case "mso-list":
- var matches = /\w+ \w+([0-9]+)/i.exec(styleValue);
- if (matches) {
- node._listLevel = parseInt(matches[1], 10);
- }
- if (/Ignore/i.test(value2) && node.firstChild) {
- node._listIgnore = true;
- node.firstChild._listIgnore = true;
- }
- break;
- case "horiz-align":
- name = "text-align";
- break;
- case "vert-align":
- name = "vertical-align";
- break;
- case "font-color":
- case "mso-foreground":
- name = "color";
- break;
- case "mso-background":
- case "mso-highlight":
- name = "background";
- break;
- case "font-weight":
- case "font-style":
- if (value2 !== "normal") {
- outputStyles[name] = value2;
- }
- return;
- case "mso-element":
- if (/^(comment|comment-list)$/i.test(value2)) {
- node.remove();
- return;
- }
- break;
- }
- if (name.indexOf("mso-comment") === 0) {
- node.remove();
- return;
- }
- if (name.indexOf("mso-") === 0) {
- return;
- }
- if (getRetainStyleProps(editor) === "all" || validStyles && validStyles[name]) {
- outputStyles[name] = value2;
- }
- });
- if (/(bold)/i.test(outputStyles["font-weight"])) {
- delete outputStyles["font-weight"];
- node.wrap(new global$2("b", 1));
- }
- if (/(italic)/i.test(outputStyles["font-style"])) {
- delete outputStyles["font-style"];
- node.wrap(new global$2("i", 1));
- }
- var outputStyle = editor.dom.serializeStyle(outputStyles, node.name);
- if (outputStyle) {
- return outputStyle;
- }
- return null;
- };
- var filterWordContent = function(editor, content) {
- var validStyles;
- var retainStyleProperties = getRetainStyleProps(editor);
- if (retainStyleProperties) {
- validStyles = global$6.makeMap(retainStyleProperties.split(/[, ]/));
- }
- content = filter(content, [
- /<br class="?Apple-interchange-newline"?>/gi,
- /<b[^>]+id="?docs-internal-[^>]*>/gi,
- /<!--[\s\S]+?-->/gi,
- /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
- [
- /<(\/?)s>/gi,
- "<$1strike>"
- ],
- [
- / /gi,
- nbsp
- ],
- [
- /<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
- function(str, spaces) {
- return spaces.length > 0 ? spaces.replace(/./, " ").slice(Math.floor(spaces.length / 2)).split("").join(nbsp) : "";
- }
- ]
- ]);
- var validElements = getWordValidElements(editor);
- var schema = global$1({
- valid_elements: validElements,
- valid_children: "-li[p]"
- });
- global$6.each(schema.elements, function(rule) {
- if (!rule.attributes.class) {
- rule.attributes.class = {};
- rule.attributesOrder.push("class");
- }
- if (!rule.attributes.style) {
- rule.attributes.style = {};
- rule.attributesOrder.push("style");
- }
- });
- var domParser = global$4({}, schema);
- domParser.addAttributeFilter("style", function(nodes) {
- var i = nodes.length, node;
- while (i--) {
- node = nodes[i];
- node.attr("style", filterStyles(editor, validStyles, node, node.attr("style")));
- if (node.name === "span" && node.parent && !node.attributes.length) {
- node.unwrap();
- }
- }
- });
- domParser.addAttributeFilter("class", function(nodes) {
- var i = nodes.length, node, className;
- while (i--) {
- node = nodes[i];
- className = node.attr("class");
- if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
- node.remove();
- }
- node.attr("class", null);
- }
- });
- domParser.addNodeFilter("del", function(nodes) {
- var i = nodes.length;
- while (i--) {
- nodes[i].remove();
- }
- });
- domParser.addNodeFilter("a", function(nodes) {
- var i = nodes.length, node, href, name;
- while (i--) {
- node = nodes[i];
- href = node.attr("href");
- name = node.attr("name");
- if (href && href.indexOf("#_msocom_") !== -1) {
- node.remove();
- continue;
- }
- if (href && href.indexOf("file://") === 0) {
- href = href.split("#")[1];
- if (href) {
- href = "#" + href;
- }
- }
- if (!href && !name) {
- node.unwrap();
- } else {
- if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) {
- node.unwrap();
- continue;
- }
- node.attr({
- href,
- name
- });
- }
- }
- });
- var rootNode = domParser.parse(content);
- if (shouldConvertWordFakeLists(editor)) {
- convertFakeListsToProperLists(rootNode);
- }
- content = global$3({ validate: getValidate(editor) }, schema).serialize(rootNode);
- return content;
- };
- var preProcess$1 = function(editor, content) {
- return shouldUseDefaultFilters(editor) ? filterWordContent(editor, content) : content;
- };
- var preProcess = function(editor, html) {
- var parser = global$4({}, editor.schema);
- parser.addNodeFilter("meta", function(nodes) {
- global$6.each(nodes, function(node) {
- node.remove();
- });
- });
- var fragment = parser.parse(html, {
- forced_root_block: false,
- isRootContent: true
- });
- return global$3({ validate: getValidate(editor) }, editor.schema).serialize(fragment);
- };
- var processResult = function(content, cancelled) {
- return {
- content,
- cancelled
- };
- };
- var postProcessFilter = function(editor, html, internal, isWordHtml) {
- var tempBody = editor.dom.create("div", { style: "display:none" }, html);
- var postProcessArgs = firePastePostProcess(editor, tempBody, internal, isWordHtml);
- return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented());
- };
- var filterContent = function(editor, content, internal, isWordHtml) {
- var preProcessArgs = firePastePreProcess(editor, content, internal, isWordHtml);
- var filteredContent = preProcess(editor, preProcessArgs.content);
- if (editor.hasEventListeners("PastePostProcess") && !preProcessArgs.isDefaultPrevented()) {
- return postProcessFilter(editor, filteredContent, internal, isWordHtml);
- } else {
- return processResult(filteredContent, preProcessArgs.isDefaultPrevented());
- }
- };
- var process = function(editor, html, internal) {
- var isWordHtml = isWordContent(html);
- var content = isWordHtml ? preProcess$1(editor, html) : html;
- return filterContent(editor, content, internal, isWordHtml);
- };
- var pasteHtml$1 = function(editor, html) {
- editor.insertContent(html, {
- merge: shouldMergeFormats(editor),
- paste: true
- });
- return true;
- };
- var isAbsoluteUrl = function(url) {
- return /^https?:\/\/[\w\-\/+=.,!;:&%@^~(){}?#]+$/i.test(url);
- };
- var isImageUrl = function(editor, url) {
- return isAbsoluteUrl(url) && exists(getAllowedImageFileTypes(editor), function(type) {
- return endsWith(url.toLowerCase(), "." + type.toLowerCase());
- });
- };
- var createImage = function(editor, url, pasteHtmlFn) {
- editor.undoManager.extra(function() {
- pasteHtmlFn(editor, url);
- }, function() {
- editor.insertContent('<img src="' + url + '">');
- });
- return true;
- };
- var createLink = function(editor, url, pasteHtmlFn) {
- editor.undoManager.extra(function() {
- pasteHtmlFn(editor, url);
- }, function() {
- editor.execCommand("mceInsertLink", false, url);
- });
- return true;
- };
- var linkSelection = function(editor, html, pasteHtmlFn) {
- return editor.selection.isCollapsed() === false && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtmlFn) : false;
- };
- var insertImage = function(editor, html, pasteHtmlFn) {
- return isImageUrl(editor, html) ? createImage(editor, html, pasteHtmlFn) : false;
- };
- var smartInsertContent = function(editor, html) {
- global$6.each([
- linkSelection,
- insertImage,
- pasteHtml$1
- ], function(action) {
- return action(editor, html, pasteHtml$1) !== true;
- });
- };
- var insertContent = function(editor, html, pasteAsText) {
- if (pasteAsText || isSmartPasteEnabled(editor) === false) {
- pasteHtml$1(editor, html);
- } else {
- smartInsertContent(editor, html);
- }
- };
- var isCollapsibleWhitespace = function(c) {
- return " \f \v".indexOf(c) !== -1;
- };
- var isNewLineChar = function(c) {
- return c === "\n" || c === "\r";
- };
- var isNewline = function(text, idx) {
- return idx < text.length && idx >= 0 ? isNewLineChar(text[idx]) : false;
- };
- var normalizeWhitespace = function(editor, text) {
- var tabSpace = repeat(" ", getTabSpaces(editor));
- var normalizedText = text.replace(/\t/g, tabSpace);
- var result = foldl(normalizedText, function(acc, c) {
- if (isCollapsibleWhitespace(c) || c === nbsp) {
- if (acc.pcIsSpace || acc.str === "" || acc.str.length === normalizedText.length - 1 || isNewline(normalizedText, acc.str.length + 1)) {
- return {
- pcIsSpace: false,
- str: acc.str + nbsp
- };
- } else {
- return {
- pcIsSpace: true,
- str: acc.str + " "
- };
- }
- } else {
- return {
- pcIsSpace: isNewLineChar(c),
- str: acc.str + c
- };
- }
- }, {
- pcIsSpace: false,
- str: ""
- });
- return result.str;
- };
- var doPaste = function(editor, content, internal, pasteAsText) {
- var args = process(editor, content, internal);
- if (args.cancelled === false) {
- insertContent(editor, args.content, pasteAsText);
- }
- };
- var pasteHtml = function(editor, html, internalFlag) {
- var internal = internalFlag ? internalFlag : isMarked(html);
- doPaste(editor, unmark(html), internal, false);
- };
- var pasteText = function(editor, text) {
- var encodedText = editor.dom.encode(text).replace(/\r\n/g, "\n");
- var normalizedText = normalizeWhitespace(editor, encodedText);
- var html = convert(normalizedText, getForcedRootBlock(editor), getForcedRootBlockAttrs(editor));
- doPaste(editor, html, false, true);
- };
- var getDataTransferItems = function(dataTransfer) {
- var items = {};
- var mceInternalUrlPrefix = "data:text/mce-internal,";
- if (dataTransfer) {
- if (dataTransfer.getData) {
- var legacyText = dataTransfer.getData("Text");
- if (legacyText && legacyText.length > 0) {
- if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
- items["text/plain"] = legacyText;
- }
- }
- }
- if (dataTransfer.types) {
- for (var i = 0; i < dataTransfer.types.length; i++) {
- var contentType = dataTransfer.types[i];
- try {
- items[contentType] = dataTransfer.getData(contentType);
- } catch (ex) {
- items[contentType] = "";
- }
- }
- }
- }
- return items;
- };
- var getClipboardContent = function(editor, clipboardEvent) {
- return getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
- };
- var hasContentType = function(clipboardContent, mimeType) {
- return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
- };
- var hasHtmlOrText = function(content) {
- return hasContentType(content, "text/html") || hasContentType(content, "text/plain");
- };
- var parseDataUri = function(uri) {
- var matches = /data:([^;]+);base64,([a-z0-9\+\/=]+)/i.exec(uri);
- if (matches) {
- return {
- type: matches[1],
- data: decodeURIComponent(matches[2])
- };
- } else {
- return {
- type: null,
- data: null
- };
- }
- };
- var isValidDataUriImage = function(editor, imgElm) {
- var filter2 = getImagesDataImgFilter(editor);
- return filter2 ? filter2(imgElm) : true;
- };
- var extractFilename = function(editor, str) {
- var m = str.match(/([\s\S]+?)(?:\.[a-z0-9.]+)$/i);
- return isNonNullable(m) ? editor.dom.encode(m[1]) : null;
- };
- var uniqueId = createIdGenerator("mceclip");
- var pasteImage = function(editor, imageItem) {
- var _a = parseDataUri(imageItem.uri), base64 = _a.data, type = _a.type;
- var id = uniqueId();
- var file = imageItem.blob;
- var img = new Image();
- img.src = imageItem.uri;
- if (isValidDataUriImage(editor, img)) {
- var blobCache = editor.editorUpload.blobCache;
- var blobInfo = void 0;
- var existingBlobInfo = blobCache.getByData(base64, type);
- if (!existingBlobInfo) {
- var useFileName = getImagesReuseFilename(editor) && isNonNullable(file.name);
- var name_1 = useFileName ? extractFilename(editor, file.name) : id;
- var filename = useFileName ? file.name : void 0;
- blobInfo = blobCache.create(id, file, base64, name_1, filename);
- blobCache.add(blobInfo);
- } else {
- blobInfo = existingBlobInfo;
- }
- pasteHtml(editor, '<img src="' + blobInfo.blobUri() + '">', false);
- } else {
- pasteHtml(editor, '<img src="' + imageItem.uri + '">', false);
- }
- };
- var isClipboardEvent = function(event) {
- return event.type === "paste";
- };
- var isDataTransferItem = function(item) {
- return isNonNullable(item.getAsFile);
- };
- var readFilesAsDataUris = function(items) {
- return global$8.all(map(items, function(item) {
- return new global$8(function(resolve) {
- var blob = isDataTransferItem(item) ? item.getAsFile() : item;
- var reader = new window.FileReader();
- reader.onload = function() {
- resolve({
- blob,
- uri: reader.result
- });
- };
- reader.readAsDataURL(blob);
- });
- }));
- };
- var isImage = function(editor) {
- var allowedExtensions = getAllowedImageFileTypes(editor);
- return function(file) {
- return startsWith(file.type, "image/") && exists(allowedExtensions, function(extension) {
- return getImageMimeType(extension) === file.type;
- });
- };
- };
- var getImagesFromDataTransfer = function(editor, dataTransfer) {
- var items = dataTransfer.items ? bind(from(dataTransfer.items), function(item) {
- return item.kind === "file" ? [item.getAsFile()] : [];
- }) : [];
- var files = dataTransfer.files ? from(dataTransfer.files) : [];
- return filter$1(items.length > 0 ? items : files, isImage(editor));
- };
- var pasteImageData = function(editor, e, rng) {
- var dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
- if (getPasteDataImages(editor) && dataTransfer) {
- var images = getImagesFromDataTransfer(editor, dataTransfer);
- if (images.length > 0) {
- e.preventDefault();
- readFilesAsDataUris(images).then(function(fileResults) {
- if (rng) {
- editor.selection.setRng(rng);
- }
- each(fileResults, function(result) {
- pasteImage(editor, result);
- });
- });
- return true;
- }
- }
- return false;
- };
- var isBrokenAndroidClipboardEvent = function(e) {
- var clipboardData = e.clipboardData;
- return navigator.userAgent.indexOf("Android") !== -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
- };
- var isKeyboardPasteEvent = function(e) {
- return global$7.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
- };
- var registerEventHandlers = function(editor, pasteBin, pasteFormat) {
- var keyboardPasteEvent = value();
- var keyboardPastePressed = value();
- var keyboardPastePlainTextState;
- editor.on("keyup", keyboardPastePressed.clear);
- editor.on("keydown", function(e) {
- var removePasteBinOnKeyUp = function(e2) {
- if (isKeyboardPasteEvent(e2) && !e2.isDefaultPrevented()) {
- pasteBin.remove();
- }
- };
- if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
- keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
- if (keyboardPastePlainTextState && global$a.webkit && navigator.userAgent.indexOf("Version/") !== -1) {
- return;
- }
- e.stopImmediatePropagation();
- keyboardPasteEvent.set(e);
- keyboardPastePressed.set(true);
- if (global$a.ie && keyboardPastePlainTextState) {
- e.preventDefault();
- firePaste(editor, true);
- return;
- }
- pasteBin.remove();
- pasteBin.create();
- editor.once("keyup", removePasteBinOnKeyUp);
- editor.once("paste", function() {
- editor.off("keyup", removePasteBinOnKeyUp);
- });
- }
- });
- var insertClipboardContent = function(editor2, clipboardContent, isKeyBoardPaste, plainTextMode, internal) {
- var content;
- if (hasContentType(clipboardContent, "text/html")) {
- content = clipboardContent["text/html"];
- } else {
- content = pasteBin.getHtml();
- internal = internal ? internal : isMarked(content);
- if (pasteBin.isDefaultContent(content)) {
- plainTextMode = true;
- }
- }
- content = trimHtml(content);
- pasteBin.remove();
- var isPlainTextHtml = internal === false && isPlainText(content);
- var isAbsoluteUrl$1 = isAbsoluteUrl(content);
- if (!content.length || isPlainTextHtml && !isAbsoluteUrl$1) {
- plainTextMode = true;
- }
- if (plainTextMode || isAbsoluteUrl$1) {
- if (hasContentType(clipboardContent, "text/plain") && isPlainTextHtml) {
- content = clipboardContent["text/plain"];
- } else {
- content = innerText(content);
- }
- }
- if (pasteBin.isDefaultContent(content)) {
- if (!isKeyBoardPaste) {
- editor2.windowManager.alert("Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.");
- }
- return;
- }
- if (plainTextMode) {
- pasteText(editor2, content);
- } else {
- pasteHtml(editor2, content, internal);
- }
- };
- var getLastRng = function() {
- return pasteBin.getLastRng() || editor.selection.getRng();
- };
- editor.on("paste", function(e) {
- var isKeyboardPaste = keyboardPasteEvent.isSet() || keyboardPastePressed.isSet();
- if (isKeyboardPaste) {
- keyboardPasteEvent.clear();
- }
- var clipboardContent = getClipboardContent(editor, e);
- var plainTextMode = pasteFormat.get() === "text" || keyboardPastePlainTextState;
- var internal = hasContentType(clipboardContent, internalHtmlMime());
- keyboardPastePlainTextState = false;
- if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
- pasteBin.remove();
- return;
- }
- if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
- pasteBin.remove();
- return;
- }
- if (!isKeyboardPaste) {
- e.preventDefault();
- }
- if (global$a.ie && (!isKeyboardPaste || e.ieFake) && !hasContentType(clipboardContent, "text/html")) {
- pasteBin.create();
- editor.dom.bind(pasteBin.getEl(), "paste", function(e2) {
- e2.stopPropagation();
- });
- editor.getDoc().execCommand("Paste", false, null);
- clipboardContent["text/html"] = pasteBin.getHtml();
- }
- if (hasContentType(clipboardContent, "text/html")) {
- e.preventDefault();
- if (!internal) {
- internal = isMarked(clipboardContent["text/html"]);
- }
- insertClipboardContent(editor, clipboardContent, isKeyboardPaste, plainTextMode, internal);
- } else {
- global$9.setEditorTimeout(editor, function() {
- insertClipboardContent(editor, clipboardContent, isKeyboardPaste, plainTextMode, internal);
- }, 0);
- }
- });
- };
- var registerEventsAndFilters = function(editor, pasteBin, pasteFormat) {
- registerEventHandlers(editor, pasteBin, pasteFormat);
- var src;
- editor.parser.addNodeFilter("img", function(nodes, name, args) {
- var isPasteInsert = function(args2) {
- return args2.data && args2.data.paste === true;
- };
- var remove2 = function(node) {
- if (!node.attr("data-mce-object") && src !== global$a.transparentSrc) {
- node.remove();
- }
- };
- var isWebKitFakeUrl = function(src2) {
- return src2.indexOf("webkit-fake-url") === 0;
- };
- var isDataUri = function(src2) {
- return src2.indexOf("data:") === 0;
- };
- if (!getPasteDataImages(editor) && isPasteInsert(args)) {
- var i = nodes.length;
- while (i--) {
- src = nodes[i].attr("src");
- if (!src) {
- continue;
- }
- if (isWebKitFakeUrl(src)) {
- remove2(nodes[i]);
- } else if (!getAllowHtmlDataUrls(editor) && isDataUri(src)) {
- remove2(nodes[i]);
- }
- }
- }
- });
- };
- var getPasteBinParent = function(editor) {
- return global$a.ie && editor.inline ? document.body : editor.getBody();
- };
- var isExternalPasteBin = function(editor) {
- return getPasteBinParent(editor) !== editor.getBody();
- };
- var delegatePasteEvents = function(editor, pasteBinElm, pasteBinDefaultContent) {
- if (isExternalPasteBin(editor)) {
- editor.dom.bind(pasteBinElm, "paste keyup", function(_e) {
- if (!isDefault(editor, pasteBinDefaultContent)) {
- editor.fire("paste");
- }
- });
- }
- };
- var create = function(editor, lastRngCell, pasteBinDefaultContent) {
- var dom = editor.dom, body = editor.getBody();
- lastRngCell.set(editor.selection.getRng());
- var pasteBinElm = editor.dom.add(getPasteBinParent(editor), "div", {
- "id": "mcepastebin",
- "class": "mce-pastebin",
- "contentEditable": true,
- "data-mce-bogus": "all",
- "style": "position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0"
- }, pasteBinDefaultContent);
- if (global$a.ie || global$a.gecko) {
- dom.setStyle(pasteBinElm, "left", dom.getStyle(body, "direction", true) === "rtl" ? 65535 : -65535);
- }
- dom.bind(pasteBinElm, "beforedeactivate focusin focusout", function(e) {
- e.stopPropagation();
- });
- delegatePasteEvents(editor, pasteBinElm, pasteBinDefaultContent);
- pasteBinElm.focus();
- editor.selection.select(pasteBinElm, true);
- };
- var remove = function(editor, lastRngCell) {
- if (getEl(editor)) {
- var pasteBinClone = void 0;
- var lastRng = lastRngCell.get();
- while (pasteBinClone = editor.dom.get("mcepastebin")) {
- editor.dom.remove(pasteBinClone);
- editor.dom.unbind(pasteBinClone);
- }
- if (lastRng) {
- editor.selection.setRng(lastRng);
- }
- }
- lastRngCell.set(null);
- };
- var getEl = function(editor) {
- return editor.dom.get("mcepastebin");
- };
- var getHtml = function(editor) {
- var copyAndRemove = function(toElm, fromElm) {
- toElm.appendChild(fromElm);
- editor.dom.remove(fromElm, true);
- };
- var pasteBinClones = global$6.grep(getPasteBinParent(editor).childNodes, function(elm) {
- return elm.id === "mcepastebin";
- });
- var pasteBinElm = pasteBinClones.shift();
- global$6.each(pasteBinClones, function(pasteBinClone) {
- copyAndRemove(pasteBinElm, pasteBinClone);
- });
- var dirtyWrappers = editor.dom.select("div[id=mcepastebin]", pasteBinElm);
- for (var i = dirtyWrappers.length - 1; i >= 0; i--) {
- var cleanWrapper = editor.dom.create("div");
- pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
- copyAndRemove(cleanWrapper, dirtyWrappers[i]);
- }
- return pasteBinElm ? pasteBinElm.innerHTML : "";
- };
- var isDefaultContent = function(pasteBinDefaultContent, content) {
- return content === pasteBinDefaultContent;
- };
- var isPasteBin = function(elm) {
- return elm && elm.id === "mcepastebin";
- };
- var isDefault = function(editor, pasteBinDefaultContent) {
- var pasteBinElm = getEl(editor);
- return isPasteBin(pasteBinElm) && isDefaultContent(pasteBinDefaultContent, pasteBinElm.innerHTML);
- };
- var PasteBin = function(editor) {
- var lastRng = Cell(null);
- var pasteBinDefaultContent = "%MCEPASTEBIN%";
- return {
- create: function() {
- return create(editor, lastRng, pasteBinDefaultContent);
- },
- remove: function() {
- return remove(editor, lastRng);
- },
- getEl: function() {
- return getEl(editor);
- },
- getHtml: function() {
- return getHtml(editor);
- },
- getLastRng: lastRng.get,
- isDefault: function() {
- return isDefault(editor, pasteBinDefaultContent);
- },
- isDefaultContent: function(content) {
- return isDefaultContent(pasteBinDefaultContent, content);
- }
- };
- };
- var Clipboard = function(editor, pasteFormat) {
- var pasteBin = PasteBin(editor);
- editor.on("PreInit", function() {
- return registerEventsAndFilters(editor, pasteBin, pasteFormat);
- });
- return {
- pasteFormat,
- pasteHtml: function(html, internalFlag) {
- return pasteHtml(editor, html, internalFlag);
- },
- pasteText: function(text) {
- return pasteText(editor, text);
- },
- pasteImageData: function(e, rng) {
- return pasteImageData(editor, e, rng);
- },
- getDataTransferItems,
- hasHtmlOrText,
- hasContentType
- };
- };
- var togglePlainTextPaste = function(editor, clipboard) {
- if (clipboard.pasteFormat.get() === "text") {
- clipboard.pasteFormat.set("html");
- firePastePlainTextToggle(editor, false);
- } else {
- clipboard.pasteFormat.set("text");
- firePastePlainTextToggle(editor, true);
- }
- editor.focus();
- };
- var register$2 = function(editor, clipboard) {
- editor.addCommand("mceTogglePlainTextPaste", function() {
- togglePlainTextPaste(editor, clipboard);
- });
- editor.addCommand("mceInsertClipboardContent", function(ui, value2) {
- if (value2.content) {
- clipboard.pasteHtml(value2.content, value2.internal);
- }
- if (value2.text) {
- clipboard.pasteText(value2.text);
- }
- });
- };
- var hasWorkingClipboardApi = function(clipboardData) {
- return global$a.iOS === false && typeof (clipboardData === null || clipboardData === void 0 ? void 0 : clipboardData.setData) === "function";
- };
- var setHtml5Clipboard = function(clipboardData, html, text) {
- if (hasWorkingClipboardApi(clipboardData)) {
- try {
- clipboardData.clearData();
- clipboardData.setData("text/html", html);
- clipboardData.setData("text/plain", text);
- clipboardData.setData(internalHtmlMime(), html);
- return true;
- } catch (e) {
- return false;
- }
- } else {
- return false;
- }
- };
- var setClipboardData = function(evt, data, fallback2, done) {
- if (setHtml5Clipboard(evt.clipboardData, data.html, data.text)) {
- evt.preventDefault();
- done();
- } else {
- fallback2(data.html, done);
- }
- };
- var fallback = function(editor) {
- return function(html, done) {
- var markedHtml = mark(html);
- var outer = editor.dom.create("div", {
- "contenteditable": "false",
- "data-mce-bogus": "all"
- });
- var inner = editor.dom.create("div", { contenteditable: "true" }, markedHtml);
- editor.dom.setStyles(outer, {
- position: "fixed",
- top: "0",
- left: "-3000px",
- width: "1000px",
- overflow: "hidden"
- });
- outer.appendChild(inner);
- editor.dom.add(editor.getBody(), outer);
- var range = editor.selection.getRng();
- inner.focus();
- var offscreenRange = editor.dom.createRng();
- offscreenRange.selectNodeContents(inner);
- editor.selection.setRng(offscreenRange);
- global$9.setTimeout(function() {
- editor.selection.setRng(range);
- outer.parentNode.removeChild(outer);
- done();
- }, 0);
- };
- };
- var getData = function(editor) {
- return {
- html: editor.selection.getContent({ contextual: true }),
- text: editor.selection.getContent({ format: "text" })
- };
- };
- var isTableSelection = function(editor) {
- return !!editor.dom.getParent(editor.selection.getStart(), "td[data-mce-selected],th[data-mce-selected]", editor.getBody());
- };
- var hasSelectedContent = function(editor) {
- return !editor.selection.isCollapsed() || isTableSelection(editor);
- };
- var cut = function(editor) {
- return function(evt) {
- if (hasSelectedContent(editor)) {
- setClipboardData(evt, getData(editor), fallback(editor), function() {
- if (global$a.browser.isChrome() || global$a.browser.isFirefox()) {
- var rng_1 = editor.selection.getRng();
- global$9.setEditorTimeout(editor, function() {
- editor.selection.setRng(rng_1);
- editor.execCommand("Delete");
- }, 0);
- } else {
- editor.execCommand("Delete");
- }
- });
- }
- };
- };
- var copy = function(editor) {
- return function(evt) {
- if (hasSelectedContent(editor)) {
- setClipboardData(evt, getData(editor), fallback(editor), noop);
- }
- };
- };
- var register$1 = function(editor) {
- editor.on("cut", cut(editor));
- editor.on("copy", copy(editor));
- };
- var global = tinymce.util.Tools.resolve("tinymce.dom.RangeUtils");
- var getCaretRangeFromEvent = function(editor, e) {
- return global.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
- };
- var isPlainTextFileUrl = function(content) {
- var plainTextContent = content["text/plain"];
- return plainTextContent ? plainTextContent.indexOf("file://") === 0 : false;
- };
- var setFocusedRange = function(editor, rng) {
- editor.focus();
- editor.selection.setRng(rng);
- };
- var setup$2 = function(editor, clipboard, draggingInternallyState) {
- if (shouldBlockDrop(editor)) {
- editor.on("dragend dragover draggesture dragdrop drop drag", function(e) {
- e.preventDefault();
- e.stopPropagation();
- });
- }
- if (!shouldPasteDataImages(editor)) {
- editor.on("drop", function(e) {
- var dataTransfer = e.dataTransfer;
- if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
- e.preventDefault();
- }
- });
- }
- editor.on("drop", function(e) {
- var rng = getCaretRangeFromEvent(editor, e);
- if (e.isDefaultPrevented() || draggingInternallyState.get()) {
- return;
- }
- var dropContent = clipboard.getDataTransferItems(e.dataTransfer);
- var internal = clipboard.hasContentType(dropContent, internalHtmlMime());
- if ((!clipboard.hasHtmlOrText(dropContent) || isPlainTextFileUrl(dropContent)) && clipboard.pasteImageData(e, rng)) {
- return;
- }
- if (rng && shouldFilterDrop(editor)) {
- var content_1 = dropContent["mce-internal"] || dropContent["text/html"] || dropContent["text/plain"];
- if (content_1) {
- e.preventDefault();
- global$9.setEditorTimeout(editor, function() {
- editor.undoManager.transact(function() {
- if (dropContent["mce-internal"]) {
- editor.execCommand("Delete");
- }
- setFocusedRange(editor, rng);
- content_1 = trimHtml(content_1);
- if (!dropContent["text/html"]) {
- clipboard.pasteText(content_1);
- } else {
- clipboard.pasteHtml(content_1, internal);
- }
- });
- });
- }
- }
- });
- editor.on("dragstart", function(_e) {
- draggingInternallyState.set(true);
- });
- editor.on("dragover dragend", function(e) {
- if (shouldPasteDataImages(editor) && draggingInternallyState.get() === false) {
- e.preventDefault();
- setFocusedRange(editor, getCaretRangeFromEvent(editor, e));
- }
- if (e.type === "dragend") {
- draggingInternallyState.set(false);
- }
- });
- };
- var setup$1 = function(editor) {
- var plugin = editor.plugins.paste;
- var preProcess2 = getPreProcess(editor);
- if (preProcess2) {
- editor.on("PastePreProcess", function(e) {
- preProcess2.call(plugin, plugin, e);
- });
- }
- var postProcess = getPostProcess(editor);
- if (postProcess) {
- editor.on("PastePostProcess", function(e) {
- postProcess.call(plugin, plugin, e);
- });
- }
- };
- var addPreProcessFilter = function(editor, filterFunc) {
- editor.on("PastePreProcess", function(e) {
- e.content = filterFunc(editor, e.content, e.internal, e.wordContent);
- });
- };
- var addPostProcessFilter = function(editor, filterFunc) {
- editor.on("PastePostProcess", function(e) {
- filterFunc(editor, e.node);
- });
- };
- var removeExplorerBrElementsAfterBlocks = function(editor, html) {
- if (!isWordContent(html)) {
- return html;
- }
- var blockElements = [];
- global$6.each(editor.schema.getBlockElements(), function(block, blockName) {
- blockElements.push(blockName);
- });
- var explorerBlocksRegExp = new RegExp("(?:<br> [\\s\\r\\n]+|<br>)*(<\\/?(" + blockElements.join("|") + ")[^>]*>)(?:<br> [\\s\\r\\n]+|<br>)*", "g");
- html = filter(html, [[
- explorerBlocksRegExp,
- "$1"
- ]]);
- html = filter(html, [
- [
- /<br><br>/g,
- "<BR><BR>"
- ],
- [
- /<br>/g,
- " "
- ],
- [
- /<BR><BR>/g,
- "<br>"
- ]
- ]);
- return html;
- };
- var removeWebKitStyles = function(editor, content, internal, isWordHtml) {
- if (isWordHtml || internal) {
- return content;
- }
- var webKitStylesSetting = getWebkitStyles(editor);
- var webKitStyles;
- if (shouldRemoveWebKitStyles(editor) === false || webKitStylesSetting === "all") {
- return content;
- }
- if (webKitStylesSetting) {
- webKitStyles = webKitStylesSetting.split(/[, ]/);
- }
- if (webKitStyles) {
- var dom_1 = editor.dom, node_1 = editor.selection.getNode();
- content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, function(all, before, value2, after) {
- var inputStyles = dom_1.parseStyle(dom_1.decode(value2));
- var outputStyles = {};
- if (webKitStyles === "none") {
- return before + after;
- }
- for (var i = 0; i < webKitStyles.length; i++) {
- var inputValue = inputStyles[webKitStyles[i]], currentValue = dom_1.getStyle(node_1, webKitStyles[i], true);
- if (/color/.test(webKitStyles[i])) {
- inputValue = dom_1.toHex(inputValue);
- currentValue = dom_1.toHex(currentValue);
- }
- if (currentValue !== inputValue) {
- outputStyles[webKitStyles[i]] = inputValue;
- }
- }
- var outputStyle = dom_1.serializeStyle(outputStyles, "span");
- if (outputStyle) {
- return before + ' style="' + outputStyle + '"' + after;
- }
- return before + after;
- });
- } else {
- content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, "$1$3");
- }
- content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, function(all, before, value2, after) {
- return before + ' style="' + value2 + '"' + after;
- });
- return content;
- };
- var removeUnderlineAndFontInAnchor = function(editor, root) {
- editor.$("a", root).find("font,u").each(function(i, node) {
- editor.dom.remove(node, true);
- });
- };
- var setup = function(editor) {
- if (global$a.webkit) {
- addPreProcessFilter(editor, removeWebKitStyles);
- }
- if (global$a.ie) {
- addPreProcessFilter(editor, removeExplorerBrElementsAfterBlocks);
- addPostProcessFilter(editor, removeUnderlineAndFontInAnchor);
- }
- };
- var makeSetupHandler = function(editor, clipboard) {
- return function(api) {
- api.setActive(clipboard.pasteFormat.get() === "text");
- var pastePlainTextToggleHandler = function(e) {
- return api.setActive(e.state);
- };
- editor.on("PastePlainTextToggle", pastePlainTextToggleHandler);
- return function() {
- return editor.off("PastePlainTextToggle", pastePlainTextToggleHandler);
- };
- };
- };
- var register = function(editor, clipboard) {
- var onAction = function() {
- return editor.execCommand("mceTogglePlainTextPaste");
- };
- editor.ui.registry.addToggleButton("pastetext", {
- active: false,
- icon: "paste-text",
- tooltip: "Paste as text",
- onAction,
- onSetup: makeSetupHandler(editor, clipboard)
- });
- editor.ui.registry.addToggleMenuItem("pastetext", {
- text: "Paste as text",
- icon: "paste-text",
- onAction,
- onSetup: makeSetupHandler(editor, clipboard)
- });
- };
- function Plugin() {
- global$b.add("paste", function(editor) {
- if (hasProPlugin(editor) === false) {
- var draggingInternallyState = Cell(false);
- var pasteFormat = Cell(isPasteAsTextEnabled(editor) ? "text" : "html");
- var clipboard = Clipboard(editor, pasteFormat);
- setup(editor);
- register(editor, clipboard);
- register$2(editor, clipboard);
- setup$1(editor);
- register$1(editor);
- setup$2(editor, clipboard, draggingInternallyState);
- return get(clipboard);
- }
- });
- }
- Plugin();
- })();
- }
- });
- // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/paste/index.js
- require_plugin();
- //# sourceMappingURL=tinymce_plugins_paste.js.map
|