tinymce_plugins_paste.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/paste/plugin.js
  5. var require_plugin = __commonJS({
  6. "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/paste/plugin.js"() {
  7. (function() {
  8. "use strict";
  9. var Cell = function(initial) {
  10. var value2 = initial;
  11. var get2 = function() {
  12. return value2;
  13. };
  14. var set = function(v) {
  15. value2 = v;
  16. };
  17. return {
  18. get: get2,
  19. set
  20. };
  21. };
  22. var global$b = tinymce.util.Tools.resolve("tinymce.PluginManager");
  23. var hasProPlugin = function(editor) {
  24. if (editor.hasPlugin("powerpaste", true)) {
  25. if (typeof window.console !== "undefined" && window.console.log) {
  26. window.console.log("PowerPaste is incompatible with Paste plugin! Remove 'paste' from the 'plugins' option.");
  27. }
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. };
  33. var get = function(clipboard) {
  34. return { clipboard };
  35. };
  36. var typeOf = function(x) {
  37. var t = typeof x;
  38. if (x === null) {
  39. return "null";
  40. } else if (t === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
  41. return "array";
  42. } else if (t === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
  43. return "string";
  44. } else {
  45. return t;
  46. }
  47. };
  48. var isType = function(type) {
  49. return function(value2) {
  50. return typeOf(value2) === type;
  51. };
  52. };
  53. var isSimpleType = function(type) {
  54. return function(value2) {
  55. return typeof value2 === type;
  56. };
  57. };
  58. var isArray = isType("array");
  59. var isNullable = function(a) {
  60. return a === null || a === void 0;
  61. };
  62. var isNonNullable = function(a) {
  63. return !isNullable(a);
  64. };
  65. var isFunction = isSimpleType("function");
  66. var noop = function() {
  67. };
  68. var constant = function(value2) {
  69. return function() {
  70. return value2;
  71. };
  72. };
  73. var identity = function(x) {
  74. return x;
  75. };
  76. var never = constant(false);
  77. var always = constant(true);
  78. var none = function() {
  79. return NONE;
  80. };
  81. var NONE = function() {
  82. var call = function(thunk) {
  83. return thunk();
  84. };
  85. var id = identity;
  86. var me = {
  87. fold: function(n, _s) {
  88. return n();
  89. },
  90. isSome: never,
  91. isNone: always,
  92. getOr: id,
  93. getOrThunk: call,
  94. getOrDie: function(msg) {
  95. throw new Error(msg || "error: getOrDie called on none.");
  96. },
  97. getOrNull: constant(null),
  98. getOrUndefined: constant(void 0),
  99. or: id,
  100. orThunk: call,
  101. map: none,
  102. each: noop,
  103. bind: none,
  104. exists: never,
  105. forall: always,
  106. filter: function() {
  107. return none();
  108. },
  109. toArray: function() {
  110. return [];
  111. },
  112. toString: constant("none()")
  113. };
  114. return me;
  115. }();
  116. var some = function(a) {
  117. var constant_a = constant(a);
  118. var self = function() {
  119. return me;
  120. };
  121. var bind2 = function(f) {
  122. return f(a);
  123. };
  124. var me = {
  125. fold: function(n, s) {
  126. return s(a);
  127. },
  128. isSome: always,
  129. isNone: never,
  130. getOr: constant_a,
  131. getOrThunk: constant_a,
  132. getOrDie: constant_a,
  133. getOrNull: constant_a,
  134. getOrUndefined: constant_a,
  135. or: self,
  136. orThunk: self,
  137. map: function(f) {
  138. return some(f(a));
  139. },
  140. each: function(f) {
  141. f(a);
  142. },
  143. bind: bind2,
  144. exists: bind2,
  145. forall: bind2,
  146. filter: function(f) {
  147. return f(a) ? me : NONE;
  148. },
  149. toArray: function() {
  150. return [a];
  151. },
  152. toString: function() {
  153. return "some(" + a + ")";
  154. }
  155. };
  156. return me;
  157. };
  158. var from$1 = function(value2) {
  159. return value2 === null || value2 === void 0 ? NONE : some(value2);
  160. };
  161. var Optional = {
  162. some,
  163. none,
  164. from: from$1
  165. };
  166. var nativeSlice = Array.prototype.slice;
  167. var nativePush = Array.prototype.push;
  168. var exists = function(xs, pred) {
  169. for (var i = 0, len = xs.length; i < len; i++) {
  170. var x = xs[i];
  171. if (pred(x, i)) {
  172. return true;
  173. }
  174. }
  175. return false;
  176. };
  177. var map = function(xs, f) {
  178. var len = xs.length;
  179. var r = new Array(len);
  180. for (var i = 0; i < len; i++) {
  181. var x = xs[i];
  182. r[i] = f(x, i);
  183. }
  184. return r;
  185. };
  186. var each = function(xs, f) {
  187. for (var i = 0, len = xs.length; i < len; i++) {
  188. var x = xs[i];
  189. f(x, i);
  190. }
  191. };
  192. var filter$1 = function(xs, pred) {
  193. var r = [];
  194. for (var i = 0, len = xs.length; i < len; i++) {
  195. var x = xs[i];
  196. if (pred(x, i)) {
  197. r.push(x);
  198. }
  199. }
  200. return r;
  201. };
  202. var foldl = function(xs, f, acc) {
  203. each(xs, function(x, i) {
  204. acc = f(acc, x, i);
  205. });
  206. return acc;
  207. };
  208. var flatten = function(xs) {
  209. var r = [];
  210. for (var i = 0, len = xs.length; i < len; ++i) {
  211. if (!isArray(xs[i])) {
  212. throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
  213. }
  214. nativePush.apply(r, xs[i]);
  215. }
  216. return r;
  217. };
  218. var bind = function(xs, f) {
  219. return flatten(map(xs, f));
  220. };
  221. var from = isFunction(Array.from) ? Array.from : function(x) {
  222. return nativeSlice.call(x);
  223. };
  224. var __assign = function() {
  225. __assign = Object.assign || function __assign2(t) {
  226. for (var s, i = 1, n = arguments.length; i < n; i++) {
  227. s = arguments[i];
  228. for (var p in s)
  229. if (Object.prototype.hasOwnProperty.call(s, p))
  230. t[p] = s[p];
  231. }
  232. return t;
  233. };
  234. return __assign.apply(this, arguments);
  235. };
  236. var singleton = function(doRevoke) {
  237. var subject = Cell(Optional.none());
  238. var revoke = function() {
  239. return subject.get().each(doRevoke);
  240. };
  241. var clear = function() {
  242. revoke();
  243. subject.set(Optional.none());
  244. };
  245. var isSet = function() {
  246. return subject.get().isSome();
  247. };
  248. var get2 = function() {
  249. return subject.get();
  250. };
  251. var set = function(s) {
  252. revoke();
  253. subject.set(Optional.some(s));
  254. };
  255. return {
  256. clear,
  257. isSet,
  258. get: get2,
  259. set
  260. };
  261. };
  262. var value = function() {
  263. var subject = singleton(noop);
  264. var on = function(f) {
  265. return subject.get().each(f);
  266. };
  267. return __assign(__assign({}, subject), { on });
  268. };
  269. var checkRange = function(str, substr, start) {
  270. return substr === "" || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
  271. };
  272. var startsWith = function(str, prefix) {
  273. return checkRange(str, prefix, 0);
  274. };
  275. var endsWith = function(str, suffix) {
  276. return checkRange(str, suffix, str.length - suffix.length);
  277. };
  278. var repeat = function(s, count) {
  279. return count <= 0 ? "" : new Array(count + 1).join(s);
  280. };
  281. var global$a = tinymce.util.Tools.resolve("tinymce.Env");
  282. var global$9 = tinymce.util.Tools.resolve("tinymce.util.Delay");
  283. var global$8 = tinymce.util.Tools.resolve("tinymce.util.Promise");
  284. var global$7 = tinymce.util.Tools.resolve("tinymce.util.VK");
  285. var firePastePreProcess = function(editor, html, internal, isWordHtml) {
  286. return editor.fire("PastePreProcess", {
  287. content: html,
  288. internal,
  289. wordContent: isWordHtml
  290. });
  291. };
  292. var firePastePostProcess = function(editor, node, internal, isWordHtml) {
  293. return editor.fire("PastePostProcess", {
  294. node,
  295. internal,
  296. wordContent: isWordHtml
  297. });
  298. };
  299. var firePastePlainTextToggle = function(editor, state) {
  300. return editor.fire("PastePlainTextToggle", { state });
  301. };
  302. var firePaste = function(editor, ieFake) {
  303. return editor.fire("paste", { ieFake });
  304. };
  305. var global$6 = tinymce.util.Tools.resolve("tinymce.util.Tools");
  306. var shouldBlockDrop = function(editor) {
  307. return editor.getParam("paste_block_drop", false);
  308. };
  309. var shouldPasteDataImages = function(editor) {
  310. return editor.getParam("paste_data_images", false);
  311. };
  312. var shouldFilterDrop = function(editor) {
  313. return editor.getParam("paste_filter_drop", true);
  314. };
  315. var getPreProcess = function(editor) {
  316. return editor.getParam("paste_preprocess");
  317. };
  318. var getPostProcess = function(editor) {
  319. return editor.getParam("paste_postprocess");
  320. };
  321. var getWebkitStyles = function(editor) {
  322. return editor.getParam("paste_webkit_styles");
  323. };
  324. var shouldRemoveWebKitStyles = function(editor) {
  325. return editor.getParam("paste_remove_styles_if_webkit", true);
  326. };
  327. var shouldMergeFormats = function(editor) {
  328. return editor.getParam("paste_merge_formats", true);
  329. };
  330. var isSmartPasteEnabled = function(editor) {
  331. return editor.getParam("smart_paste", true);
  332. };
  333. var isPasteAsTextEnabled = function(editor) {
  334. return editor.getParam("paste_as_text", false);
  335. };
  336. var getRetainStyleProps = function(editor) {
  337. return editor.getParam("paste_retain_style_properties");
  338. };
  339. var getWordValidElements = function(editor) {
  340. 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";
  341. return editor.getParam("paste_word_valid_elements", defaultValidElements);
  342. };
  343. var shouldConvertWordFakeLists = function(editor) {
  344. return editor.getParam("paste_convert_word_fake_lists", true);
  345. };
  346. var shouldUseDefaultFilters = function(editor) {
  347. return editor.getParam("paste_enable_default_filters", true);
  348. };
  349. var getValidate = function(editor) {
  350. return editor.getParam("validate");
  351. };
  352. var getAllowHtmlDataUrls = function(editor) {
  353. return editor.getParam("allow_html_data_urls", false, "boolean");
  354. };
  355. var getPasteDataImages = function(editor) {
  356. return editor.getParam("paste_data_images", false, "boolean");
  357. };
  358. var getImagesDataImgFilter = function(editor) {
  359. return editor.getParam("images_dataimg_filter");
  360. };
  361. var getImagesReuseFilename = function(editor) {
  362. return editor.getParam("images_reuse_filename");
  363. };
  364. var getForcedRootBlock = function(editor) {
  365. return editor.getParam("forced_root_block");
  366. };
  367. var getForcedRootBlockAttrs = function(editor) {
  368. return editor.getParam("forced_root_block_attrs");
  369. };
  370. var getTabSpaces = function(editor) {
  371. return editor.getParam("paste_tab_spaces", 4, "number");
  372. };
  373. var getAllowedImageFileTypes = function(editor) {
  374. var defaultImageFileTypes = "jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp";
  375. return global$6.explode(editor.getParam("images_file_types", defaultImageFileTypes, "string"));
  376. };
  377. var internalMimeType = "x-tinymce/html";
  378. var internalMark = "<!-- " + internalMimeType + " -->";
  379. var mark = function(html) {
  380. return internalMark + html;
  381. };
  382. var unmark = function(html) {
  383. return html.replace(internalMark, "");
  384. };
  385. var isMarked = function(html) {
  386. return html.indexOf(internalMark) !== -1;
  387. };
  388. var internalHtmlMime = constant(internalMimeType);
  389. var hasOwnProperty = Object.hasOwnProperty;
  390. var has = function(obj, key) {
  391. return hasOwnProperty.call(obj, key);
  392. };
  393. var global$5 = tinymce.util.Tools.resolve("tinymce.html.Entities");
  394. var isPlainText = function(text) {
  395. return !/<(?:\/?(?!(?:div|p|br|span)>)\w+|(?:(?!(?:span style="white-space:\s?pre;?">)|br\s?\/>))\w+\s[^>]+)>/i.test(text);
  396. };
  397. var toBRs = function(text) {
  398. return text.replace(/\r?\n/g, "<br>");
  399. };
  400. var openContainer = function(rootTag, rootAttrs) {
  401. var attrs = [];
  402. var tag = "<" + rootTag;
  403. if (typeof rootAttrs === "object") {
  404. for (var key in rootAttrs) {
  405. if (has(rootAttrs, key)) {
  406. attrs.push(key + '="' + global$5.encodeAllRaw(rootAttrs[key]) + '"');
  407. }
  408. }
  409. if (attrs.length) {
  410. tag += " " + attrs.join(" ");
  411. }
  412. }
  413. return tag + ">";
  414. };
  415. var toBlockElements = function(text, rootTag, rootAttrs) {
  416. var blocks = text.split(/\n\n/);
  417. var tagOpen = openContainer(rootTag, rootAttrs);
  418. var tagClose = "</" + rootTag + ">";
  419. var paragraphs = global$6.map(blocks, function(p) {
  420. return p.split(/\n/).join("<br />");
  421. });
  422. var stitch = function(p) {
  423. return tagOpen + p + tagClose;
  424. };
  425. return paragraphs.length === 1 ? paragraphs[0] : global$6.map(paragraphs, stitch).join("");
  426. };
  427. var convert = function(text, rootTag, rootAttrs) {
  428. return rootTag ? toBlockElements(text, rootTag === true ? "p" : rootTag, rootAttrs) : toBRs(text);
  429. };
  430. var global$4 = tinymce.util.Tools.resolve("tinymce.html.DomParser");
  431. var global$3 = tinymce.util.Tools.resolve("tinymce.html.Serializer");
  432. var nbsp = " ";
  433. var global$2 = tinymce.util.Tools.resolve("tinymce.html.Node");
  434. var global$1 = tinymce.util.Tools.resolve("tinymce.html.Schema");
  435. var isRegExp = function(val) {
  436. return val.constructor === RegExp;
  437. };
  438. var filter = function(content, items) {
  439. global$6.each(items, function(v) {
  440. if (isRegExp(v)) {
  441. content = content.replace(v, "");
  442. } else {
  443. content = content.replace(v[0], v[1]);
  444. }
  445. });
  446. return content;
  447. };
  448. var innerText = function(html) {
  449. var schema = global$1();
  450. var domParser = global$4({}, schema);
  451. var text = "";
  452. var shortEndedElements = schema.getShortEndedElements();
  453. var ignoreElements = global$6.makeMap("script noscript style textarea video audio iframe object", " ");
  454. var blockElements = schema.getBlockElements();
  455. var walk = function(node) {
  456. var name = node.name, currentNode = node;
  457. if (name === "br") {
  458. text += "\n";
  459. return;
  460. }
  461. if (name === "wbr") {
  462. return;
  463. }
  464. if (shortEndedElements[name]) {
  465. text += " ";
  466. }
  467. if (ignoreElements[name]) {
  468. text += " ";
  469. return;
  470. }
  471. if (node.type === 3) {
  472. text += node.value;
  473. }
  474. if (!node.shortEnded) {
  475. if (node = node.firstChild) {
  476. do {
  477. walk(node);
  478. } while (node = node.next);
  479. }
  480. }
  481. if (blockElements[name] && currentNode.next) {
  482. text += "\n";
  483. if (name === "p") {
  484. text += "\n";
  485. }
  486. }
  487. };
  488. html = filter(html, [/<!\[[^\]]+\]>/g]);
  489. walk(domParser.parse(html));
  490. return text;
  491. };
  492. var trimHtml = function(html) {
  493. var trimSpaces = function(all, s1, s2) {
  494. if (!s1 && !s2) {
  495. return " ";
  496. }
  497. return nbsp;
  498. };
  499. html = filter(html, [
  500. /^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig,
  501. /<!--StartFragment-->|<!--EndFragment-->/g,
  502. [
  503. /( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g,
  504. trimSpaces
  505. ],
  506. /<br class="Apple-interchange-newline">/g,
  507. /<br>$/i
  508. ]);
  509. return html;
  510. };
  511. var createIdGenerator = function(prefix) {
  512. var count = 0;
  513. return function() {
  514. return prefix + count++;
  515. };
  516. };
  517. var getImageMimeType = function(ext) {
  518. var lowerExt = ext.toLowerCase();
  519. var mimeOverrides = {
  520. jpg: "jpeg",
  521. jpe: "jpeg",
  522. jfi: "jpeg",
  523. jif: "jpeg",
  524. jfif: "jpeg",
  525. pjpeg: "jpeg",
  526. pjp: "jpeg",
  527. svg: "svg+xml"
  528. };
  529. return global$6.hasOwn(mimeOverrides, lowerExt) ? "image/" + mimeOverrides[lowerExt] : "image/" + lowerExt;
  530. };
  531. var isWordContent = function(content) {
  532. 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);
  533. };
  534. var isNumericList = function(text) {
  535. var found = false;
  536. var patterns = [
  537. /^[IVXLMCD]+\.[ \u00a0]/,
  538. /^[ivxlmcd]+\.[ \u00a0]/,
  539. /^[a-z]{1,2}[\.\)][ \u00a0]/,
  540. /^[A-Z]{1,2}[\.\)][ \u00a0]/,
  541. /^[0-9]+\.[ \u00a0]/,
  542. /^[\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+\.[ \u00a0]/,
  543. /^[\u58f1\u5f10\u53c2\u56db\u4f0d\u516d\u4e03\u516b\u4e5d\u62fe]+\.[ \u00a0]/
  544. ];
  545. text = text.replace(/^[\u00a0 ]+/, "");
  546. global$6.each(patterns, function(pattern) {
  547. if (pattern.test(text)) {
  548. found = true;
  549. return false;
  550. }
  551. });
  552. return found;
  553. };
  554. var isBulletList = function(text) {
  555. return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
  556. };
  557. var convertFakeListsToProperLists = function(node) {
  558. var currentListNode, prevListNode, lastLevel = 1;
  559. var getText = function(node2) {
  560. var txt = "";
  561. if (node2.type === 3) {
  562. return node2.value;
  563. }
  564. if (node2 = node2.firstChild) {
  565. do {
  566. txt += getText(node2);
  567. } while (node2 = node2.next);
  568. }
  569. return txt;
  570. };
  571. var trimListStart = function(node2, regExp) {
  572. if (node2.type === 3) {
  573. if (regExp.test(node2.value)) {
  574. node2.value = node2.value.replace(regExp, "");
  575. return false;
  576. }
  577. }
  578. if (node2 = node2.firstChild) {
  579. do {
  580. if (!trimListStart(node2, regExp)) {
  581. return false;
  582. }
  583. } while (node2 = node2.next);
  584. }
  585. return true;
  586. };
  587. var removeIgnoredNodes = function(node2) {
  588. if (node2._listIgnore) {
  589. node2.remove();
  590. return;
  591. }
  592. if (node2 = node2.firstChild) {
  593. do {
  594. removeIgnoredNodes(node2);
  595. } while (node2 = node2.next);
  596. }
  597. };
  598. var convertParagraphToLi = function(paragraphNode, listName, start2) {
  599. var level = paragraphNode._listLevel || lastLevel;
  600. if (level !== lastLevel) {
  601. if (level < lastLevel) {
  602. if (currentListNode) {
  603. currentListNode = currentListNode.parent.parent;
  604. }
  605. } else {
  606. prevListNode = currentListNode;
  607. currentListNode = null;
  608. }
  609. }
  610. if (!currentListNode || currentListNode.name !== listName) {
  611. prevListNode = prevListNode || currentListNode;
  612. currentListNode = new global$2(listName, 1);
  613. if (start2 > 1) {
  614. currentListNode.attr("start", "" + start2);
  615. }
  616. paragraphNode.wrap(currentListNode);
  617. } else {
  618. currentListNode.append(paragraphNode);
  619. }
  620. paragraphNode.name = "li";
  621. if (level > lastLevel && prevListNode) {
  622. prevListNode.lastChild.append(currentListNode);
  623. }
  624. lastLevel = level;
  625. removeIgnoredNodes(paragraphNode);
  626. trimListStart(paragraphNode, /^\u00a0+/);
  627. trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
  628. trimListStart(paragraphNode, /^\u00a0+/);
  629. };
  630. var elements = [];
  631. var child = node.firstChild;
  632. while (typeof child !== "undefined" && child !== null) {
  633. elements.push(child);
  634. child = child.walk();
  635. if (child !== null) {
  636. while (typeof child !== "undefined" && child.parent !== node) {
  637. child = child.walk();
  638. }
  639. }
  640. }
  641. for (var i = 0; i < elements.length; i++) {
  642. node = elements[i];
  643. if (node.name === "p" && node.firstChild) {
  644. var nodeText = getText(node);
  645. if (isBulletList(nodeText)) {
  646. convertParagraphToLi(node, "ul");
  647. continue;
  648. }
  649. if (isNumericList(nodeText)) {
  650. var matches = /([0-9]+)\./.exec(nodeText);
  651. var start = 1;
  652. if (matches) {
  653. start = parseInt(matches[1], 10);
  654. }
  655. convertParagraphToLi(node, "ol", start);
  656. continue;
  657. }
  658. if (node._listLevel) {
  659. convertParagraphToLi(node, "ul", 1);
  660. continue;
  661. }
  662. currentListNode = null;
  663. } else {
  664. prevListNode = currentListNode;
  665. currentListNode = null;
  666. }
  667. }
  668. };
  669. var filterStyles = function(editor, validStyles, node, styleValue) {
  670. var outputStyles = {};
  671. var styles = editor.dom.parseStyle(styleValue);
  672. global$6.each(styles, function(value2, name) {
  673. switch (name) {
  674. case "mso-list":
  675. var matches = /\w+ \w+([0-9]+)/i.exec(styleValue);
  676. if (matches) {
  677. node._listLevel = parseInt(matches[1], 10);
  678. }
  679. if (/Ignore/i.test(value2) && node.firstChild) {
  680. node._listIgnore = true;
  681. node.firstChild._listIgnore = true;
  682. }
  683. break;
  684. case "horiz-align":
  685. name = "text-align";
  686. break;
  687. case "vert-align":
  688. name = "vertical-align";
  689. break;
  690. case "font-color":
  691. case "mso-foreground":
  692. name = "color";
  693. break;
  694. case "mso-background":
  695. case "mso-highlight":
  696. name = "background";
  697. break;
  698. case "font-weight":
  699. case "font-style":
  700. if (value2 !== "normal") {
  701. outputStyles[name] = value2;
  702. }
  703. return;
  704. case "mso-element":
  705. if (/^(comment|comment-list)$/i.test(value2)) {
  706. node.remove();
  707. return;
  708. }
  709. break;
  710. }
  711. if (name.indexOf("mso-comment") === 0) {
  712. node.remove();
  713. return;
  714. }
  715. if (name.indexOf("mso-") === 0) {
  716. return;
  717. }
  718. if (getRetainStyleProps(editor) === "all" || validStyles && validStyles[name]) {
  719. outputStyles[name] = value2;
  720. }
  721. });
  722. if (/(bold)/i.test(outputStyles["font-weight"])) {
  723. delete outputStyles["font-weight"];
  724. node.wrap(new global$2("b", 1));
  725. }
  726. if (/(italic)/i.test(outputStyles["font-style"])) {
  727. delete outputStyles["font-style"];
  728. node.wrap(new global$2("i", 1));
  729. }
  730. var outputStyle = editor.dom.serializeStyle(outputStyles, node.name);
  731. if (outputStyle) {
  732. return outputStyle;
  733. }
  734. return null;
  735. };
  736. var filterWordContent = function(editor, content) {
  737. var validStyles;
  738. var retainStyleProperties = getRetainStyleProps(editor);
  739. if (retainStyleProperties) {
  740. validStyles = global$6.makeMap(retainStyleProperties.split(/[, ]/));
  741. }
  742. content = filter(content, [
  743. /<br class="?Apple-interchange-newline"?>/gi,
  744. /<b[^>]+id="?docs-internal-[^>]*>/gi,
  745. /<!--[\s\S]+?-->/gi,
  746. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
  747. [
  748. /<(\/?)s>/gi,
  749. "<$1strike>"
  750. ],
  751. [
  752. /&nbsp;/gi,
  753. nbsp
  754. ],
  755. [
  756. /<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
  757. function(str, spaces) {
  758. return spaces.length > 0 ? spaces.replace(/./, " ").slice(Math.floor(spaces.length / 2)).split("").join(nbsp) : "";
  759. }
  760. ]
  761. ]);
  762. var validElements = getWordValidElements(editor);
  763. var schema = global$1({
  764. valid_elements: validElements,
  765. valid_children: "-li[p]"
  766. });
  767. global$6.each(schema.elements, function(rule) {
  768. if (!rule.attributes.class) {
  769. rule.attributes.class = {};
  770. rule.attributesOrder.push("class");
  771. }
  772. if (!rule.attributes.style) {
  773. rule.attributes.style = {};
  774. rule.attributesOrder.push("style");
  775. }
  776. });
  777. var domParser = global$4({}, schema);
  778. domParser.addAttributeFilter("style", function(nodes) {
  779. var i = nodes.length, node;
  780. while (i--) {
  781. node = nodes[i];
  782. node.attr("style", filterStyles(editor, validStyles, node, node.attr("style")));
  783. if (node.name === "span" && node.parent && !node.attributes.length) {
  784. node.unwrap();
  785. }
  786. }
  787. });
  788. domParser.addAttributeFilter("class", function(nodes) {
  789. var i = nodes.length, node, className;
  790. while (i--) {
  791. node = nodes[i];
  792. className = node.attr("class");
  793. if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
  794. node.remove();
  795. }
  796. node.attr("class", null);
  797. }
  798. });
  799. domParser.addNodeFilter("del", function(nodes) {
  800. var i = nodes.length;
  801. while (i--) {
  802. nodes[i].remove();
  803. }
  804. });
  805. domParser.addNodeFilter("a", function(nodes) {
  806. var i = nodes.length, node, href, name;
  807. while (i--) {
  808. node = nodes[i];
  809. href = node.attr("href");
  810. name = node.attr("name");
  811. if (href && href.indexOf("#_msocom_") !== -1) {
  812. node.remove();
  813. continue;
  814. }
  815. if (href && href.indexOf("file://") === 0) {
  816. href = href.split("#")[1];
  817. if (href) {
  818. href = "#" + href;
  819. }
  820. }
  821. if (!href && !name) {
  822. node.unwrap();
  823. } else {
  824. if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) {
  825. node.unwrap();
  826. continue;
  827. }
  828. node.attr({
  829. href,
  830. name
  831. });
  832. }
  833. }
  834. });
  835. var rootNode = domParser.parse(content);
  836. if (shouldConvertWordFakeLists(editor)) {
  837. convertFakeListsToProperLists(rootNode);
  838. }
  839. content = global$3({ validate: getValidate(editor) }, schema).serialize(rootNode);
  840. return content;
  841. };
  842. var preProcess$1 = function(editor, content) {
  843. return shouldUseDefaultFilters(editor) ? filterWordContent(editor, content) : content;
  844. };
  845. var preProcess = function(editor, html) {
  846. var parser = global$4({}, editor.schema);
  847. parser.addNodeFilter("meta", function(nodes) {
  848. global$6.each(nodes, function(node) {
  849. node.remove();
  850. });
  851. });
  852. var fragment = parser.parse(html, {
  853. forced_root_block: false,
  854. isRootContent: true
  855. });
  856. return global$3({ validate: getValidate(editor) }, editor.schema).serialize(fragment);
  857. };
  858. var processResult = function(content, cancelled) {
  859. return {
  860. content,
  861. cancelled
  862. };
  863. };
  864. var postProcessFilter = function(editor, html, internal, isWordHtml) {
  865. var tempBody = editor.dom.create("div", { style: "display:none" }, html);
  866. var postProcessArgs = firePastePostProcess(editor, tempBody, internal, isWordHtml);
  867. return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented());
  868. };
  869. var filterContent = function(editor, content, internal, isWordHtml) {
  870. var preProcessArgs = firePastePreProcess(editor, content, internal, isWordHtml);
  871. var filteredContent = preProcess(editor, preProcessArgs.content);
  872. if (editor.hasEventListeners("PastePostProcess") && !preProcessArgs.isDefaultPrevented()) {
  873. return postProcessFilter(editor, filteredContent, internal, isWordHtml);
  874. } else {
  875. return processResult(filteredContent, preProcessArgs.isDefaultPrevented());
  876. }
  877. };
  878. var process = function(editor, html, internal) {
  879. var isWordHtml = isWordContent(html);
  880. var content = isWordHtml ? preProcess$1(editor, html) : html;
  881. return filterContent(editor, content, internal, isWordHtml);
  882. };
  883. var pasteHtml$1 = function(editor, html) {
  884. editor.insertContent(html, {
  885. merge: shouldMergeFormats(editor),
  886. paste: true
  887. });
  888. return true;
  889. };
  890. var isAbsoluteUrl = function(url) {
  891. return /^https?:\/\/[\w\-\/+=.,!;:&%@^~(){}?#]+$/i.test(url);
  892. };
  893. var isImageUrl = function(editor, url) {
  894. return isAbsoluteUrl(url) && exists(getAllowedImageFileTypes(editor), function(type) {
  895. return endsWith(url.toLowerCase(), "." + type.toLowerCase());
  896. });
  897. };
  898. var createImage = function(editor, url, pasteHtmlFn) {
  899. editor.undoManager.extra(function() {
  900. pasteHtmlFn(editor, url);
  901. }, function() {
  902. editor.insertContent('<img src="' + url + '">');
  903. });
  904. return true;
  905. };
  906. var createLink = function(editor, url, pasteHtmlFn) {
  907. editor.undoManager.extra(function() {
  908. pasteHtmlFn(editor, url);
  909. }, function() {
  910. editor.execCommand("mceInsertLink", false, url);
  911. });
  912. return true;
  913. };
  914. var linkSelection = function(editor, html, pasteHtmlFn) {
  915. return editor.selection.isCollapsed() === false && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtmlFn) : false;
  916. };
  917. var insertImage = function(editor, html, pasteHtmlFn) {
  918. return isImageUrl(editor, html) ? createImage(editor, html, pasteHtmlFn) : false;
  919. };
  920. var smartInsertContent = function(editor, html) {
  921. global$6.each([
  922. linkSelection,
  923. insertImage,
  924. pasteHtml$1
  925. ], function(action) {
  926. return action(editor, html, pasteHtml$1) !== true;
  927. });
  928. };
  929. var insertContent = function(editor, html, pasteAsText) {
  930. if (pasteAsText || isSmartPasteEnabled(editor) === false) {
  931. pasteHtml$1(editor, html);
  932. } else {
  933. smartInsertContent(editor, html);
  934. }
  935. };
  936. var isCollapsibleWhitespace = function(c) {
  937. return " \f \v".indexOf(c) !== -1;
  938. };
  939. var isNewLineChar = function(c) {
  940. return c === "\n" || c === "\r";
  941. };
  942. var isNewline = function(text, idx) {
  943. return idx < text.length && idx >= 0 ? isNewLineChar(text[idx]) : false;
  944. };
  945. var normalizeWhitespace = function(editor, text) {
  946. var tabSpace = repeat(" ", getTabSpaces(editor));
  947. var normalizedText = text.replace(/\t/g, tabSpace);
  948. var result = foldl(normalizedText, function(acc, c) {
  949. if (isCollapsibleWhitespace(c) || c === nbsp) {
  950. if (acc.pcIsSpace || acc.str === "" || acc.str.length === normalizedText.length - 1 || isNewline(normalizedText, acc.str.length + 1)) {
  951. return {
  952. pcIsSpace: false,
  953. str: acc.str + nbsp
  954. };
  955. } else {
  956. return {
  957. pcIsSpace: true,
  958. str: acc.str + " "
  959. };
  960. }
  961. } else {
  962. return {
  963. pcIsSpace: isNewLineChar(c),
  964. str: acc.str + c
  965. };
  966. }
  967. }, {
  968. pcIsSpace: false,
  969. str: ""
  970. });
  971. return result.str;
  972. };
  973. var doPaste = function(editor, content, internal, pasteAsText) {
  974. var args = process(editor, content, internal);
  975. if (args.cancelled === false) {
  976. insertContent(editor, args.content, pasteAsText);
  977. }
  978. };
  979. var pasteHtml = function(editor, html, internalFlag) {
  980. var internal = internalFlag ? internalFlag : isMarked(html);
  981. doPaste(editor, unmark(html), internal, false);
  982. };
  983. var pasteText = function(editor, text) {
  984. var encodedText = editor.dom.encode(text).replace(/\r\n/g, "\n");
  985. var normalizedText = normalizeWhitespace(editor, encodedText);
  986. var html = convert(normalizedText, getForcedRootBlock(editor), getForcedRootBlockAttrs(editor));
  987. doPaste(editor, html, false, true);
  988. };
  989. var getDataTransferItems = function(dataTransfer) {
  990. var items = {};
  991. var mceInternalUrlPrefix = "data:text/mce-internal,";
  992. if (dataTransfer) {
  993. if (dataTransfer.getData) {
  994. var legacyText = dataTransfer.getData("Text");
  995. if (legacyText && legacyText.length > 0) {
  996. if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
  997. items["text/plain"] = legacyText;
  998. }
  999. }
  1000. }
  1001. if (dataTransfer.types) {
  1002. for (var i = 0; i < dataTransfer.types.length; i++) {
  1003. var contentType = dataTransfer.types[i];
  1004. try {
  1005. items[contentType] = dataTransfer.getData(contentType);
  1006. } catch (ex) {
  1007. items[contentType] = "";
  1008. }
  1009. }
  1010. }
  1011. }
  1012. return items;
  1013. };
  1014. var getClipboardContent = function(editor, clipboardEvent) {
  1015. return getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
  1016. };
  1017. var hasContentType = function(clipboardContent, mimeType) {
  1018. return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
  1019. };
  1020. var hasHtmlOrText = function(content) {
  1021. return hasContentType(content, "text/html") || hasContentType(content, "text/plain");
  1022. };
  1023. var parseDataUri = function(uri) {
  1024. var matches = /data:([^;]+);base64,([a-z0-9\+\/=]+)/i.exec(uri);
  1025. if (matches) {
  1026. return {
  1027. type: matches[1],
  1028. data: decodeURIComponent(matches[2])
  1029. };
  1030. } else {
  1031. return {
  1032. type: null,
  1033. data: null
  1034. };
  1035. }
  1036. };
  1037. var isValidDataUriImage = function(editor, imgElm) {
  1038. var filter2 = getImagesDataImgFilter(editor);
  1039. return filter2 ? filter2(imgElm) : true;
  1040. };
  1041. var extractFilename = function(editor, str) {
  1042. var m = str.match(/([\s\S]+?)(?:\.[a-z0-9.]+)$/i);
  1043. return isNonNullable(m) ? editor.dom.encode(m[1]) : null;
  1044. };
  1045. var uniqueId = createIdGenerator("mceclip");
  1046. var pasteImage = function(editor, imageItem) {
  1047. var _a = parseDataUri(imageItem.uri), base64 = _a.data, type = _a.type;
  1048. var id = uniqueId();
  1049. var file = imageItem.blob;
  1050. var img = new Image();
  1051. img.src = imageItem.uri;
  1052. if (isValidDataUriImage(editor, img)) {
  1053. var blobCache = editor.editorUpload.blobCache;
  1054. var blobInfo = void 0;
  1055. var existingBlobInfo = blobCache.getByData(base64, type);
  1056. if (!existingBlobInfo) {
  1057. var useFileName = getImagesReuseFilename(editor) && isNonNullable(file.name);
  1058. var name_1 = useFileName ? extractFilename(editor, file.name) : id;
  1059. var filename = useFileName ? file.name : void 0;
  1060. blobInfo = blobCache.create(id, file, base64, name_1, filename);
  1061. blobCache.add(blobInfo);
  1062. } else {
  1063. blobInfo = existingBlobInfo;
  1064. }
  1065. pasteHtml(editor, '<img src="' + blobInfo.blobUri() + '">', false);
  1066. } else {
  1067. pasteHtml(editor, '<img src="' + imageItem.uri + '">', false);
  1068. }
  1069. };
  1070. var isClipboardEvent = function(event) {
  1071. return event.type === "paste";
  1072. };
  1073. var isDataTransferItem = function(item) {
  1074. return isNonNullable(item.getAsFile);
  1075. };
  1076. var readFilesAsDataUris = function(items) {
  1077. return global$8.all(map(items, function(item) {
  1078. return new global$8(function(resolve) {
  1079. var blob = isDataTransferItem(item) ? item.getAsFile() : item;
  1080. var reader = new window.FileReader();
  1081. reader.onload = function() {
  1082. resolve({
  1083. blob,
  1084. uri: reader.result
  1085. });
  1086. };
  1087. reader.readAsDataURL(blob);
  1088. });
  1089. }));
  1090. };
  1091. var isImage = function(editor) {
  1092. var allowedExtensions = getAllowedImageFileTypes(editor);
  1093. return function(file) {
  1094. return startsWith(file.type, "image/") && exists(allowedExtensions, function(extension) {
  1095. return getImageMimeType(extension) === file.type;
  1096. });
  1097. };
  1098. };
  1099. var getImagesFromDataTransfer = function(editor, dataTransfer) {
  1100. var items = dataTransfer.items ? bind(from(dataTransfer.items), function(item) {
  1101. return item.kind === "file" ? [item.getAsFile()] : [];
  1102. }) : [];
  1103. var files = dataTransfer.files ? from(dataTransfer.files) : [];
  1104. return filter$1(items.length > 0 ? items : files, isImage(editor));
  1105. };
  1106. var pasteImageData = function(editor, e, rng) {
  1107. var dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
  1108. if (getPasteDataImages(editor) && dataTransfer) {
  1109. var images = getImagesFromDataTransfer(editor, dataTransfer);
  1110. if (images.length > 0) {
  1111. e.preventDefault();
  1112. readFilesAsDataUris(images).then(function(fileResults) {
  1113. if (rng) {
  1114. editor.selection.setRng(rng);
  1115. }
  1116. each(fileResults, function(result) {
  1117. pasteImage(editor, result);
  1118. });
  1119. });
  1120. return true;
  1121. }
  1122. }
  1123. return false;
  1124. };
  1125. var isBrokenAndroidClipboardEvent = function(e) {
  1126. var clipboardData = e.clipboardData;
  1127. return navigator.userAgent.indexOf("Android") !== -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
  1128. };
  1129. var isKeyboardPasteEvent = function(e) {
  1130. return global$7.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
  1131. };
  1132. var registerEventHandlers = function(editor, pasteBin, pasteFormat) {
  1133. var keyboardPasteEvent = value();
  1134. var keyboardPastePressed = value();
  1135. var keyboardPastePlainTextState;
  1136. editor.on("keyup", keyboardPastePressed.clear);
  1137. editor.on("keydown", function(e) {
  1138. var removePasteBinOnKeyUp = function(e2) {
  1139. if (isKeyboardPasteEvent(e2) && !e2.isDefaultPrevented()) {
  1140. pasteBin.remove();
  1141. }
  1142. };
  1143. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  1144. keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
  1145. if (keyboardPastePlainTextState && global$a.webkit && navigator.userAgent.indexOf("Version/") !== -1) {
  1146. return;
  1147. }
  1148. e.stopImmediatePropagation();
  1149. keyboardPasteEvent.set(e);
  1150. keyboardPastePressed.set(true);
  1151. if (global$a.ie && keyboardPastePlainTextState) {
  1152. e.preventDefault();
  1153. firePaste(editor, true);
  1154. return;
  1155. }
  1156. pasteBin.remove();
  1157. pasteBin.create();
  1158. editor.once("keyup", removePasteBinOnKeyUp);
  1159. editor.once("paste", function() {
  1160. editor.off("keyup", removePasteBinOnKeyUp);
  1161. });
  1162. }
  1163. });
  1164. var insertClipboardContent = function(editor2, clipboardContent, isKeyBoardPaste, plainTextMode, internal) {
  1165. var content;
  1166. if (hasContentType(clipboardContent, "text/html")) {
  1167. content = clipboardContent["text/html"];
  1168. } else {
  1169. content = pasteBin.getHtml();
  1170. internal = internal ? internal : isMarked(content);
  1171. if (pasteBin.isDefaultContent(content)) {
  1172. plainTextMode = true;
  1173. }
  1174. }
  1175. content = trimHtml(content);
  1176. pasteBin.remove();
  1177. var isPlainTextHtml = internal === false && isPlainText(content);
  1178. var isAbsoluteUrl$1 = isAbsoluteUrl(content);
  1179. if (!content.length || isPlainTextHtml && !isAbsoluteUrl$1) {
  1180. plainTextMode = true;
  1181. }
  1182. if (plainTextMode || isAbsoluteUrl$1) {
  1183. if (hasContentType(clipboardContent, "text/plain") && isPlainTextHtml) {
  1184. content = clipboardContent["text/plain"];
  1185. } else {
  1186. content = innerText(content);
  1187. }
  1188. }
  1189. if (pasteBin.isDefaultContent(content)) {
  1190. if (!isKeyBoardPaste) {
  1191. editor2.windowManager.alert("Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.");
  1192. }
  1193. return;
  1194. }
  1195. if (plainTextMode) {
  1196. pasteText(editor2, content);
  1197. } else {
  1198. pasteHtml(editor2, content, internal);
  1199. }
  1200. };
  1201. var getLastRng = function() {
  1202. return pasteBin.getLastRng() || editor.selection.getRng();
  1203. };
  1204. editor.on("paste", function(e) {
  1205. var isKeyboardPaste = keyboardPasteEvent.isSet() || keyboardPastePressed.isSet();
  1206. if (isKeyboardPaste) {
  1207. keyboardPasteEvent.clear();
  1208. }
  1209. var clipboardContent = getClipboardContent(editor, e);
  1210. var plainTextMode = pasteFormat.get() === "text" || keyboardPastePlainTextState;
  1211. var internal = hasContentType(clipboardContent, internalHtmlMime());
  1212. keyboardPastePlainTextState = false;
  1213. if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
  1214. pasteBin.remove();
  1215. return;
  1216. }
  1217. if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
  1218. pasteBin.remove();
  1219. return;
  1220. }
  1221. if (!isKeyboardPaste) {
  1222. e.preventDefault();
  1223. }
  1224. if (global$a.ie && (!isKeyboardPaste || e.ieFake) && !hasContentType(clipboardContent, "text/html")) {
  1225. pasteBin.create();
  1226. editor.dom.bind(pasteBin.getEl(), "paste", function(e2) {
  1227. e2.stopPropagation();
  1228. });
  1229. editor.getDoc().execCommand("Paste", false, null);
  1230. clipboardContent["text/html"] = pasteBin.getHtml();
  1231. }
  1232. if (hasContentType(clipboardContent, "text/html")) {
  1233. e.preventDefault();
  1234. if (!internal) {
  1235. internal = isMarked(clipboardContent["text/html"]);
  1236. }
  1237. insertClipboardContent(editor, clipboardContent, isKeyboardPaste, plainTextMode, internal);
  1238. } else {
  1239. global$9.setEditorTimeout(editor, function() {
  1240. insertClipboardContent(editor, clipboardContent, isKeyboardPaste, plainTextMode, internal);
  1241. }, 0);
  1242. }
  1243. });
  1244. };
  1245. var registerEventsAndFilters = function(editor, pasteBin, pasteFormat) {
  1246. registerEventHandlers(editor, pasteBin, pasteFormat);
  1247. var src;
  1248. editor.parser.addNodeFilter("img", function(nodes, name, args) {
  1249. var isPasteInsert = function(args2) {
  1250. return args2.data && args2.data.paste === true;
  1251. };
  1252. var remove2 = function(node) {
  1253. if (!node.attr("data-mce-object") && src !== global$a.transparentSrc) {
  1254. node.remove();
  1255. }
  1256. };
  1257. var isWebKitFakeUrl = function(src2) {
  1258. return src2.indexOf("webkit-fake-url") === 0;
  1259. };
  1260. var isDataUri = function(src2) {
  1261. return src2.indexOf("data:") === 0;
  1262. };
  1263. if (!getPasteDataImages(editor) && isPasteInsert(args)) {
  1264. var i = nodes.length;
  1265. while (i--) {
  1266. src = nodes[i].attr("src");
  1267. if (!src) {
  1268. continue;
  1269. }
  1270. if (isWebKitFakeUrl(src)) {
  1271. remove2(nodes[i]);
  1272. } else if (!getAllowHtmlDataUrls(editor) && isDataUri(src)) {
  1273. remove2(nodes[i]);
  1274. }
  1275. }
  1276. }
  1277. });
  1278. };
  1279. var getPasteBinParent = function(editor) {
  1280. return global$a.ie && editor.inline ? document.body : editor.getBody();
  1281. };
  1282. var isExternalPasteBin = function(editor) {
  1283. return getPasteBinParent(editor) !== editor.getBody();
  1284. };
  1285. var delegatePasteEvents = function(editor, pasteBinElm, pasteBinDefaultContent) {
  1286. if (isExternalPasteBin(editor)) {
  1287. editor.dom.bind(pasteBinElm, "paste keyup", function(_e) {
  1288. if (!isDefault(editor, pasteBinDefaultContent)) {
  1289. editor.fire("paste");
  1290. }
  1291. });
  1292. }
  1293. };
  1294. var create = function(editor, lastRngCell, pasteBinDefaultContent) {
  1295. var dom = editor.dom, body = editor.getBody();
  1296. lastRngCell.set(editor.selection.getRng());
  1297. var pasteBinElm = editor.dom.add(getPasteBinParent(editor), "div", {
  1298. "id": "mcepastebin",
  1299. "class": "mce-pastebin",
  1300. "contentEditable": true,
  1301. "data-mce-bogus": "all",
  1302. "style": "position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0"
  1303. }, pasteBinDefaultContent);
  1304. if (global$a.ie || global$a.gecko) {
  1305. dom.setStyle(pasteBinElm, "left", dom.getStyle(body, "direction", true) === "rtl" ? 65535 : -65535);
  1306. }
  1307. dom.bind(pasteBinElm, "beforedeactivate focusin focusout", function(e) {
  1308. e.stopPropagation();
  1309. });
  1310. delegatePasteEvents(editor, pasteBinElm, pasteBinDefaultContent);
  1311. pasteBinElm.focus();
  1312. editor.selection.select(pasteBinElm, true);
  1313. };
  1314. var remove = function(editor, lastRngCell) {
  1315. if (getEl(editor)) {
  1316. var pasteBinClone = void 0;
  1317. var lastRng = lastRngCell.get();
  1318. while (pasteBinClone = editor.dom.get("mcepastebin")) {
  1319. editor.dom.remove(pasteBinClone);
  1320. editor.dom.unbind(pasteBinClone);
  1321. }
  1322. if (lastRng) {
  1323. editor.selection.setRng(lastRng);
  1324. }
  1325. }
  1326. lastRngCell.set(null);
  1327. };
  1328. var getEl = function(editor) {
  1329. return editor.dom.get("mcepastebin");
  1330. };
  1331. var getHtml = function(editor) {
  1332. var copyAndRemove = function(toElm, fromElm) {
  1333. toElm.appendChild(fromElm);
  1334. editor.dom.remove(fromElm, true);
  1335. };
  1336. var pasteBinClones = global$6.grep(getPasteBinParent(editor).childNodes, function(elm) {
  1337. return elm.id === "mcepastebin";
  1338. });
  1339. var pasteBinElm = pasteBinClones.shift();
  1340. global$6.each(pasteBinClones, function(pasteBinClone) {
  1341. copyAndRemove(pasteBinElm, pasteBinClone);
  1342. });
  1343. var dirtyWrappers = editor.dom.select("div[id=mcepastebin]", pasteBinElm);
  1344. for (var i = dirtyWrappers.length - 1; i >= 0; i--) {
  1345. var cleanWrapper = editor.dom.create("div");
  1346. pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
  1347. copyAndRemove(cleanWrapper, dirtyWrappers[i]);
  1348. }
  1349. return pasteBinElm ? pasteBinElm.innerHTML : "";
  1350. };
  1351. var isDefaultContent = function(pasteBinDefaultContent, content) {
  1352. return content === pasteBinDefaultContent;
  1353. };
  1354. var isPasteBin = function(elm) {
  1355. return elm && elm.id === "mcepastebin";
  1356. };
  1357. var isDefault = function(editor, pasteBinDefaultContent) {
  1358. var pasteBinElm = getEl(editor);
  1359. return isPasteBin(pasteBinElm) && isDefaultContent(pasteBinDefaultContent, pasteBinElm.innerHTML);
  1360. };
  1361. var PasteBin = function(editor) {
  1362. var lastRng = Cell(null);
  1363. var pasteBinDefaultContent = "%MCEPASTEBIN%";
  1364. return {
  1365. create: function() {
  1366. return create(editor, lastRng, pasteBinDefaultContent);
  1367. },
  1368. remove: function() {
  1369. return remove(editor, lastRng);
  1370. },
  1371. getEl: function() {
  1372. return getEl(editor);
  1373. },
  1374. getHtml: function() {
  1375. return getHtml(editor);
  1376. },
  1377. getLastRng: lastRng.get,
  1378. isDefault: function() {
  1379. return isDefault(editor, pasteBinDefaultContent);
  1380. },
  1381. isDefaultContent: function(content) {
  1382. return isDefaultContent(pasteBinDefaultContent, content);
  1383. }
  1384. };
  1385. };
  1386. var Clipboard = function(editor, pasteFormat) {
  1387. var pasteBin = PasteBin(editor);
  1388. editor.on("PreInit", function() {
  1389. return registerEventsAndFilters(editor, pasteBin, pasteFormat);
  1390. });
  1391. return {
  1392. pasteFormat,
  1393. pasteHtml: function(html, internalFlag) {
  1394. return pasteHtml(editor, html, internalFlag);
  1395. },
  1396. pasteText: function(text) {
  1397. return pasteText(editor, text);
  1398. },
  1399. pasteImageData: function(e, rng) {
  1400. return pasteImageData(editor, e, rng);
  1401. },
  1402. getDataTransferItems,
  1403. hasHtmlOrText,
  1404. hasContentType
  1405. };
  1406. };
  1407. var togglePlainTextPaste = function(editor, clipboard) {
  1408. if (clipboard.pasteFormat.get() === "text") {
  1409. clipboard.pasteFormat.set("html");
  1410. firePastePlainTextToggle(editor, false);
  1411. } else {
  1412. clipboard.pasteFormat.set("text");
  1413. firePastePlainTextToggle(editor, true);
  1414. }
  1415. editor.focus();
  1416. };
  1417. var register$2 = function(editor, clipboard) {
  1418. editor.addCommand("mceTogglePlainTextPaste", function() {
  1419. togglePlainTextPaste(editor, clipboard);
  1420. });
  1421. editor.addCommand("mceInsertClipboardContent", function(ui, value2) {
  1422. if (value2.content) {
  1423. clipboard.pasteHtml(value2.content, value2.internal);
  1424. }
  1425. if (value2.text) {
  1426. clipboard.pasteText(value2.text);
  1427. }
  1428. });
  1429. };
  1430. var hasWorkingClipboardApi = function(clipboardData) {
  1431. return global$a.iOS === false && typeof (clipboardData === null || clipboardData === void 0 ? void 0 : clipboardData.setData) === "function";
  1432. };
  1433. var setHtml5Clipboard = function(clipboardData, html, text) {
  1434. if (hasWorkingClipboardApi(clipboardData)) {
  1435. try {
  1436. clipboardData.clearData();
  1437. clipboardData.setData("text/html", html);
  1438. clipboardData.setData("text/plain", text);
  1439. clipboardData.setData(internalHtmlMime(), html);
  1440. return true;
  1441. } catch (e) {
  1442. return false;
  1443. }
  1444. } else {
  1445. return false;
  1446. }
  1447. };
  1448. var setClipboardData = function(evt, data, fallback2, done) {
  1449. if (setHtml5Clipboard(evt.clipboardData, data.html, data.text)) {
  1450. evt.preventDefault();
  1451. done();
  1452. } else {
  1453. fallback2(data.html, done);
  1454. }
  1455. };
  1456. var fallback = function(editor) {
  1457. return function(html, done) {
  1458. var markedHtml = mark(html);
  1459. var outer = editor.dom.create("div", {
  1460. "contenteditable": "false",
  1461. "data-mce-bogus": "all"
  1462. });
  1463. var inner = editor.dom.create("div", { contenteditable: "true" }, markedHtml);
  1464. editor.dom.setStyles(outer, {
  1465. position: "fixed",
  1466. top: "0",
  1467. left: "-3000px",
  1468. width: "1000px",
  1469. overflow: "hidden"
  1470. });
  1471. outer.appendChild(inner);
  1472. editor.dom.add(editor.getBody(), outer);
  1473. var range = editor.selection.getRng();
  1474. inner.focus();
  1475. var offscreenRange = editor.dom.createRng();
  1476. offscreenRange.selectNodeContents(inner);
  1477. editor.selection.setRng(offscreenRange);
  1478. global$9.setTimeout(function() {
  1479. editor.selection.setRng(range);
  1480. outer.parentNode.removeChild(outer);
  1481. done();
  1482. }, 0);
  1483. };
  1484. };
  1485. var getData = function(editor) {
  1486. return {
  1487. html: editor.selection.getContent({ contextual: true }),
  1488. text: editor.selection.getContent({ format: "text" })
  1489. };
  1490. };
  1491. var isTableSelection = function(editor) {
  1492. return !!editor.dom.getParent(editor.selection.getStart(), "td[data-mce-selected],th[data-mce-selected]", editor.getBody());
  1493. };
  1494. var hasSelectedContent = function(editor) {
  1495. return !editor.selection.isCollapsed() || isTableSelection(editor);
  1496. };
  1497. var cut = function(editor) {
  1498. return function(evt) {
  1499. if (hasSelectedContent(editor)) {
  1500. setClipboardData(evt, getData(editor), fallback(editor), function() {
  1501. if (global$a.browser.isChrome() || global$a.browser.isFirefox()) {
  1502. var rng_1 = editor.selection.getRng();
  1503. global$9.setEditorTimeout(editor, function() {
  1504. editor.selection.setRng(rng_1);
  1505. editor.execCommand("Delete");
  1506. }, 0);
  1507. } else {
  1508. editor.execCommand("Delete");
  1509. }
  1510. });
  1511. }
  1512. };
  1513. };
  1514. var copy = function(editor) {
  1515. return function(evt) {
  1516. if (hasSelectedContent(editor)) {
  1517. setClipboardData(evt, getData(editor), fallback(editor), noop);
  1518. }
  1519. };
  1520. };
  1521. var register$1 = function(editor) {
  1522. editor.on("cut", cut(editor));
  1523. editor.on("copy", copy(editor));
  1524. };
  1525. var global = tinymce.util.Tools.resolve("tinymce.dom.RangeUtils");
  1526. var getCaretRangeFromEvent = function(editor, e) {
  1527. return global.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
  1528. };
  1529. var isPlainTextFileUrl = function(content) {
  1530. var plainTextContent = content["text/plain"];
  1531. return plainTextContent ? plainTextContent.indexOf("file://") === 0 : false;
  1532. };
  1533. var setFocusedRange = function(editor, rng) {
  1534. editor.focus();
  1535. editor.selection.setRng(rng);
  1536. };
  1537. var setup$2 = function(editor, clipboard, draggingInternallyState) {
  1538. if (shouldBlockDrop(editor)) {
  1539. editor.on("dragend dragover draggesture dragdrop drop drag", function(e) {
  1540. e.preventDefault();
  1541. e.stopPropagation();
  1542. });
  1543. }
  1544. if (!shouldPasteDataImages(editor)) {
  1545. editor.on("drop", function(e) {
  1546. var dataTransfer = e.dataTransfer;
  1547. if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
  1548. e.preventDefault();
  1549. }
  1550. });
  1551. }
  1552. editor.on("drop", function(e) {
  1553. var rng = getCaretRangeFromEvent(editor, e);
  1554. if (e.isDefaultPrevented() || draggingInternallyState.get()) {
  1555. return;
  1556. }
  1557. var dropContent = clipboard.getDataTransferItems(e.dataTransfer);
  1558. var internal = clipboard.hasContentType(dropContent, internalHtmlMime());
  1559. if ((!clipboard.hasHtmlOrText(dropContent) || isPlainTextFileUrl(dropContent)) && clipboard.pasteImageData(e, rng)) {
  1560. return;
  1561. }
  1562. if (rng && shouldFilterDrop(editor)) {
  1563. var content_1 = dropContent["mce-internal"] || dropContent["text/html"] || dropContent["text/plain"];
  1564. if (content_1) {
  1565. e.preventDefault();
  1566. global$9.setEditorTimeout(editor, function() {
  1567. editor.undoManager.transact(function() {
  1568. if (dropContent["mce-internal"]) {
  1569. editor.execCommand("Delete");
  1570. }
  1571. setFocusedRange(editor, rng);
  1572. content_1 = trimHtml(content_1);
  1573. if (!dropContent["text/html"]) {
  1574. clipboard.pasteText(content_1);
  1575. } else {
  1576. clipboard.pasteHtml(content_1, internal);
  1577. }
  1578. });
  1579. });
  1580. }
  1581. }
  1582. });
  1583. editor.on("dragstart", function(_e) {
  1584. draggingInternallyState.set(true);
  1585. });
  1586. editor.on("dragover dragend", function(e) {
  1587. if (shouldPasteDataImages(editor) && draggingInternallyState.get() === false) {
  1588. e.preventDefault();
  1589. setFocusedRange(editor, getCaretRangeFromEvent(editor, e));
  1590. }
  1591. if (e.type === "dragend") {
  1592. draggingInternallyState.set(false);
  1593. }
  1594. });
  1595. };
  1596. var setup$1 = function(editor) {
  1597. var plugin = editor.plugins.paste;
  1598. var preProcess2 = getPreProcess(editor);
  1599. if (preProcess2) {
  1600. editor.on("PastePreProcess", function(e) {
  1601. preProcess2.call(plugin, plugin, e);
  1602. });
  1603. }
  1604. var postProcess = getPostProcess(editor);
  1605. if (postProcess) {
  1606. editor.on("PastePostProcess", function(e) {
  1607. postProcess.call(plugin, plugin, e);
  1608. });
  1609. }
  1610. };
  1611. var addPreProcessFilter = function(editor, filterFunc) {
  1612. editor.on("PastePreProcess", function(e) {
  1613. e.content = filterFunc(editor, e.content, e.internal, e.wordContent);
  1614. });
  1615. };
  1616. var addPostProcessFilter = function(editor, filterFunc) {
  1617. editor.on("PastePostProcess", function(e) {
  1618. filterFunc(editor, e.node);
  1619. });
  1620. };
  1621. var removeExplorerBrElementsAfterBlocks = function(editor, html) {
  1622. if (!isWordContent(html)) {
  1623. return html;
  1624. }
  1625. var blockElements = [];
  1626. global$6.each(editor.schema.getBlockElements(), function(block, blockName) {
  1627. blockElements.push(blockName);
  1628. });
  1629. var explorerBlocksRegExp = new RegExp("(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?(" + blockElements.join("|") + ")[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*", "g");
  1630. html = filter(html, [[
  1631. explorerBlocksRegExp,
  1632. "$1"
  1633. ]]);
  1634. html = filter(html, [
  1635. [
  1636. /<br><br>/g,
  1637. "<BR><BR>"
  1638. ],
  1639. [
  1640. /<br>/g,
  1641. " "
  1642. ],
  1643. [
  1644. /<BR><BR>/g,
  1645. "<br>"
  1646. ]
  1647. ]);
  1648. return html;
  1649. };
  1650. var removeWebKitStyles = function(editor, content, internal, isWordHtml) {
  1651. if (isWordHtml || internal) {
  1652. return content;
  1653. }
  1654. var webKitStylesSetting = getWebkitStyles(editor);
  1655. var webKitStyles;
  1656. if (shouldRemoveWebKitStyles(editor) === false || webKitStylesSetting === "all") {
  1657. return content;
  1658. }
  1659. if (webKitStylesSetting) {
  1660. webKitStyles = webKitStylesSetting.split(/[, ]/);
  1661. }
  1662. if (webKitStyles) {
  1663. var dom_1 = editor.dom, node_1 = editor.selection.getNode();
  1664. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, function(all, before, value2, after) {
  1665. var inputStyles = dom_1.parseStyle(dom_1.decode(value2));
  1666. var outputStyles = {};
  1667. if (webKitStyles === "none") {
  1668. return before + after;
  1669. }
  1670. for (var i = 0; i < webKitStyles.length; i++) {
  1671. var inputValue = inputStyles[webKitStyles[i]], currentValue = dom_1.getStyle(node_1, webKitStyles[i], true);
  1672. if (/color/.test(webKitStyles[i])) {
  1673. inputValue = dom_1.toHex(inputValue);
  1674. currentValue = dom_1.toHex(currentValue);
  1675. }
  1676. if (currentValue !== inputValue) {
  1677. outputStyles[webKitStyles[i]] = inputValue;
  1678. }
  1679. }
  1680. var outputStyle = dom_1.serializeStyle(outputStyles, "span");
  1681. if (outputStyle) {
  1682. return before + ' style="' + outputStyle + '"' + after;
  1683. }
  1684. return before + after;
  1685. });
  1686. } else {
  1687. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, "$1$3");
  1688. }
  1689. content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, function(all, before, value2, after) {
  1690. return before + ' style="' + value2 + '"' + after;
  1691. });
  1692. return content;
  1693. };
  1694. var removeUnderlineAndFontInAnchor = function(editor, root) {
  1695. editor.$("a", root).find("font,u").each(function(i, node) {
  1696. editor.dom.remove(node, true);
  1697. });
  1698. };
  1699. var setup = function(editor) {
  1700. if (global$a.webkit) {
  1701. addPreProcessFilter(editor, removeWebKitStyles);
  1702. }
  1703. if (global$a.ie) {
  1704. addPreProcessFilter(editor, removeExplorerBrElementsAfterBlocks);
  1705. addPostProcessFilter(editor, removeUnderlineAndFontInAnchor);
  1706. }
  1707. };
  1708. var makeSetupHandler = function(editor, clipboard) {
  1709. return function(api) {
  1710. api.setActive(clipboard.pasteFormat.get() === "text");
  1711. var pastePlainTextToggleHandler = function(e) {
  1712. return api.setActive(e.state);
  1713. };
  1714. editor.on("PastePlainTextToggle", pastePlainTextToggleHandler);
  1715. return function() {
  1716. return editor.off("PastePlainTextToggle", pastePlainTextToggleHandler);
  1717. };
  1718. };
  1719. };
  1720. var register = function(editor, clipboard) {
  1721. var onAction = function() {
  1722. return editor.execCommand("mceTogglePlainTextPaste");
  1723. };
  1724. editor.ui.registry.addToggleButton("pastetext", {
  1725. active: false,
  1726. icon: "paste-text",
  1727. tooltip: "Paste as text",
  1728. onAction,
  1729. onSetup: makeSetupHandler(editor, clipboard)
  1730. });
  1731. editor.ui.registry.addToggleMenuItem("pastetext", {
  1732. text: "Paste as text",
  1733. icon: "paste-text",
  1734. onAction,
  1735. onSetup: makeSetupHandler(editor, clipboard)
  1736. });
  1737. };
  1738. function Plugin() {
  1739. global$b.add("paste", function(editor) {
  1740. if (hasProPlugin(editor) === false) {
  1741. var draggingInternallyState = Cell(false);
  1742. var pasteFormat = Cell(isPasteAsTextEnabled(editor) ? "text" : "html");
  1743. var clipboard = Clipboard(editor, pasteFormat);
  1744. setup(editor);
  1745. register(editor, clipboard);
  1746. register$2(editor, clipboard);
  1747. setup$1(editor);
  1748. register$1(editor);
  1749. setup$2(editor, clipboard, draggingInternallyState);
  1750. return get(clipboard);
  1751. }
  1752. });
  1753. }
  1754. Plugin();
  1755. })();
  1756. }
  1757. });
  1758. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/paste/index.js
  1759. require_plugin();
  1760. //# sourceMappingURL=tinymce_plugins_paste.js.map