plugin.js 56 KB

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