plugin.js 60 KB

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