Nenhuma Descrição

plugin.js 80KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368
  1. (function () {
  2. var paste = (function (domGlobals) {
  3. 'use strict';
  4. var Cell = function (initial) {
  5. var value = initial;
  6. var get = function () {
  7. return value;
  8. };
  9. var set = function (v) {
  10. value = v;
  11. };
  12. var clone = function () {
  13. return Cell(get());
  14. };
  15. return {
  16. get: get,
  17. set: set,
  18. clone: clone
  19. };
  20. };
  21. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  22. var hasProPlugin = function (editor) {
  23. if (/(^|[ ,])powerpaste([, ]|$)/.test(editor.settings.plugins) && global$1.get('powerpaste')) {
  24. if (typeof domGlobals.window.console !== 'undefined' && domGlobals.window.console.log) {
  25. domGlobals.window.console.log('PowerPaste is incompatible with Paste plugin! Remove \'paste\' from the \'plugins\' option.');
  26. }
  27. return true;
  28. } else {
  29. return false;
  30. }
  31. };
  32. var DetectProPlugin = { hasProPlugin: hasProPlugin };
  33. var get = function (clipboard, quirks) {
  34. return {
  35. clipboard: clipboard,
  36. quirks: quirks
  37. };
  38. };
  39. var Api = { get: get };
  40. var firePastePreProcess = function (editor, html, internal, isWordHtml) {
  41. return editor.fire('PastePreProcess', {
  42. content: html,
  43. internal: internal,
  44. wordContent: isWordHtml
  45. });
  46. };
  47. var firePastePostProcess = function (editor, node, internal, isWordHtml) {
  48. return editor.fire('PastePostProcess', {
  49. node: node,
  50. internal: internal,
  51. wordContent: isWordHtml
  52. });
  53. };
  54. var firePastePlainTextToggle = function (editor, state) {
  55. return editor.fire('PastePlainTextToggle', { state: state });
  56. };
  57. var firePaste = function (editor, ieFake) {
  58. return editor.fire('paste', { ieFake: ieFake });
  59. };
  60. var Events = {
  61. firePastePreProcess: firePastePreProcess,
  62. firePastePostProcess: firePastePostProcess,
  63. firePastePlainTextToggle: firePastePlainTextToggle,
  64. firePaste: firePaste
  65. };
  66. var shouldPlainTextInform = function (editor) {
  67. return editor.getParam('paste_plaintext_inform', true);
  68. };
  69. var shouldBlockDrop = function (editor) {
  70. return editor.getParam('paste_block_drop', false);
  71. };
  72. var shouldPasteDataImages = function (editor) {
  73. return editor.getParam('paste_data_images', false);
  74. };
  75. var shouldFilterDrop = function (editor) {
  76. return editor.getParam('paste_filter_drop', true);
  77. };
  78. var getPreProcess = function (editor) {
  79. return editor.getParam('paste_preprocess');
  80. };
  81. var getPostProcess = function (editor) {
  82. return editor.getParam('paste_postprocess');
  83. };
  84. var getWebkitStyles = function (editor) {
  85. return editor.getParam('paste_webkit_styles');
  86. };
  87. var shouldRemoveWebKitStyles = function (editor) {
  88. return editor.getParam('paste_remove_styles_if_webkit', true);
  89. };
  90. var shouldMergeFormats = function (editor) {
  91. return editor.getParam('paste_merge_formats', true);
  92. };
  93. var isSmartPasteEnabled = function (editor) {
  94. return editor.getParam('smart_paste', true);
  95. };
  96. var isPasteAsTextEnabled = function (editor) {
  97. return editor.getParam('paste_as_text', false);
  98. };
  99. var getRetainStyleProps = function (editor) {
  100. return editor.getParam('paste_retain_style_properties');
  101. };
  102. var getWordValidElements = function (editor) {
  103. 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';
  104. return editor.getParam('paste_word_valid_elements', defaultValidElements);
  105. };
  106. var shouldConvertWordFakeLists = function (editor) {
  107. return editor.getParam('paste_convert_word_fake_lists', true);
  108. };
  109. var shouldUseDefaultFilters = function (editor) {
  110. return editor.getParam('paste_enable_default_filters', true);
  111. };
  112. var Settings = {
  113. shouldPlainTextInform: shouldPlainTextInform,
  114. shouldBlockDrop: shouldBlockDrop,
  115. shouldPasteDataImages: shouldPasteDataImages,
  116. shouldFilterDrop: shouldFilterDrop,
  117. getPreProcess: getPreProcess,
  118. getPostProcess: getPostProcess,
  119. getWebkitStyles: getWebkitStyles,
  120. shouldRemoveWebKitStyles: shouldRemoveWebKitStyles,
  121. shouldMergeFormats: shouldMergeFormats,
  122. isSmartPasteEnabled: isSmartPasteEnabled,
  123. isPasteAsTextEnabled: isPasteAsTextEnabled,
  124. getRetainStyleProps: getRetainStyleProps,
  125. getWordValidElements: getWordValidElements,
  126. shouldConvertWordFakeLists: shouldConvertWordFakeLists,
  127. shouldUseDefaultFilters: shouldUseDefaultFilters
  128. };
  129. var shouldInformUserAboutPlainText = function (editor, userIsInformedState) {
  130. return userIsInformedState.get() === false && Settings.shouldPlainTextInform(editor);
  131. };
  132. var displayNotification = function (editor, message) {
  133. editor.notificationManager.open({
  134. text: editor.translate(message),
  135. type: 'info'
  136. });
  137. };
  138. var togglePlainTextPaste = function (editor, clipboard, userIsInformedState) {
  139. if (clipboard.pasteFormat.get() === 'text') {
  140. clipboard.pasteFormat.set('html');
  141. Events.firePastePlainTextToggle(editor, false);
  142. } else {
  143. clipboard.pasteFormat.set('text');
  144. Events.firePastePlainTextToggle(editor, true);
  145. if (shouldInformUserAboutPlainText(editor, userIsInformedState)) {
  146. displayNotification(editor, 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.');
  147. userIsInformedState.set(true);
  148. }
  149. }
  150. editor.focus();
  151. };
  152. var Actions = { togglePlainTextPaste: togglePlainTextPaste };
  153. var register = function (editor, clipboard, userIsInformedState) {
  154. editor.addCommand('mceTogglePlainTextPaste', function () {
  155. Actions.togglePlainTextPaste(editor, clipboard, userIsInformedState);
  156. });
  157. editor.addCommand('mceInsertClipboardContent', function (ui, value) {
  158. if (value.content) {
  159. clipboard.pasteHtml(value.content, value.internal);
  160. }
  161. if (value.text) {
  162. clipboard.pasteText(value.text);
  163. }
  164. });
  165. };
  166. var Commands = { register: register };
  167. var global$2 = tinymce.util.Tools.resolve('tinymce.Env');
  168. var global$3 = tinymce.util.Tools.resolve('tinymce.util.Delay');
  169. var global$4 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  170. var global$5 = tinymce.util.Tools.resolve('tinymce.util.VK');
  171. var internalMimeType = 'x-tinymce/html';
  172. var internalMark = '<!-- ' + internalMimeType + ' -->';
  173. var mark = function (html) {
  174. return internalMark + html;
  175. };
  176. var unmark = function (html) {
  177. return html.replace(internalMark, '');
  178. };
  179. var isMarked = function (html) {
  180. return html.indexOf(internalMark) !== -1;
  181. };
  182. var InternalHtml = {
  183. mark: mark,
  184. unmark: unmark,
  185. isMarked: isMarked,
  186. internalHtmlMime: function () {
  187. return internalMimeType;
  188. }
  189. };
  190. var global$6 = tinymce.util.Tools.resolve('tinymce.html.Entities');
  191. var isPlainText = function (text) {
  192. return !/<(?:\/?(?!(?:div|p|br|span)>)\w+|(?:(?!(?:span style="white-space:\s?pre;?">)|br\s?\/>))\w+\s[^>]+)>/i.test(text);
  193. };
  194. var toBRs = function (text) {
  195. return text.replace(/\r?\n/g, '<br>');
  196. };
  197. var openContainer = function (rootTag, rootAttrs) {
  198. var key;
  199. var attrs = [];
  200. var tag = '<' + rootTag;
  201. if (typeof rootAttrs === 'object') {
  202. for (key in rootAttrs) {
  203. if (rootAttrs.hasOwnProperty(key)) {
  204. attrs.push(key + '="' + global$6.encodeAllRaw(rootAttrs[key]) + '"');
  205. }
  206. }
  207. if (attrs.length) {
  208. tag += ' ' + attrs.join(' ');
  209. }
  210. }
  211. return tag + '>';
  212. };
  213. var toBlockElements = function (text, rootTag, rootAttrs) {
  214. var blocks = text.split(/\n\n/);
  215. var tagOpen = openContainer(rootTag, rootAttrs);
  216. var tagClose = '</' + rootTag + '>';
  217. var paragraphs = global$4.map(blocks, function (p) {
  218. return p.split(/\n/).join('<br />');
  219. });
  220. var stitch = function (p) {
  221. return tagOpen + p + tagClose;
  222. };
  223. return paragraphs.length === 1 ? paragraphs[0] : global$4.map(paragraphs, stitch).join('');
  224. };
  225. var convert = function (text, rootTag, rootAttrs) {
  226. return rootTag ? toBlockElements(text, rootTag, rootAttrs) : toBRs(text);
  227. };
  228. var Newlines = {
  229. isPlainText: isPlainText,
  230. convert: convert,
  231. toBRs: toBRs,
  232. toBlockElements: toBlockElements
  233. };
  234. var global$7 = tinymce.util.Tools.resolve('tinymce.html.DomParser');
  235. var global$8 = tinymce.util.Tools.resolve('tinymce.html.Serializer');
  236. var global$9 = tinymce.util.Tools.resolve('tinymce.html.Node');
  237. var global$a = tinymce.util.Tools.resolve('tinymce.html.Schema');
  238. function filter(content, items) {
  239. global$4.each(items, function (v) {
  240. if (v.constructor === RegExp) {
  241. content = content.replace(v, '');
  242. } else {
  243. content = content.replace(v[0], v[1]);
  244. }
  245. });
  246. return content;
  247. }
  248. function innerText(html) {
  249. var schema = global$a();
  250. var domParser = global$7({}, schema);
  251. var text = '';
  252. var shortEndedElements = schema.getShortEndedElements();
  253. var ignoreElements = global$4.makeMap('script noscript style textarea video audio iframe object', ' ');
  254. var blockElements = schema.getBlockElements();
  255. function walk(node) {
  256. var name = node.name, currentNode = node;
  257. if (name === 'br') {
  258. text += '\n';
  259. return;
  260. }
  261. if (name === 'wbr') {
  262. return;
  263. }
  264. if (shortEndedElements[name]) {
  265. text += ' ';
  266. }
  267. if (ignoreElements[name]) {
  268. text += ' ';
  269. return;
  270. }
  271. if (node.type === 3) {
  272. text += node.value;
  273. }
  274. if (!node.shortEnded) {
  275. if (node = node.firstChild) {
  276. do {
  277. walk(node);
  278. } while (node = node.next);
  279. }
  280. }
  281. if (blockElements[name] && currentNode.next) {
  282. text += '\n';
  283. if (name === 'p') {
  284. text += '\n';
  285. }
  286. }
  287. }
  288. html = filter(html, [/<!\[[^\]]+\]>/g]);
  289. walk(domParser.parse(html));
  290. return text;
  291. }
  292. function trimHtml(html) {
  293. function trimSpaces(all, s1, s2) {
  294. if (!s1 && !s2) {
  295. return ' ';
  296. }
  297. return '\xA0';
  298. }
  299. html = filter(html, [
  300. /^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig,
  301. /<!--StartFragment-->|<!--EndFragment-->/g,
  302. [
  303. /( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g,
  304. trimSpaces
  305. ],
  306. /<br class="Apple-interchange-newline">/g,
  307. /<br>$/i
  308. ]);
  309. return html;
  310. }
  311. function createIdGenerator(prefix) {
  312. var count = 0;
  313. return function () {
  314. return prefix + count++;
  315. };
  316. }
  317. var isMsEdge = function () {
  318. return domGlobals.navigator.userAgent.indexOf(' Edge/') !== -1;
  319. };
  320. var Utils = {
  321. filter: filter,
  322. innerText: innerText,
  323. trimHtml: trimHtml,
  324. createIdGenerator: createIdGenerator,
  325. isMsEdge: isMsEdge
  326. };
  327. function isWordContent(content) {
  328. 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);
  329. }
  330. function isNumericList(text) {
  331. var found, patterns;
  332. patterns = [
  333. /^[IVXLMCD]{1,2}\.[ \u00a0]/,
  334. /^[ivxlmcd]{1,2}\.[ \u00a0]/,
  335. /^[a-z]{1,2}[\.\)][ \u00a0]/,
  336. /^[A-Z]{1,2}[\.\)][ \u00a0]/,
  337. /^[0-9]+\.[ \u00a0]/,
  338. /^[\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+\.[ \u00a0]/,
  339. /^[\u58f1\u5f10\u53c2\u56db\u4f0d\u516d\u4e03\u516b\u4e5d\u62fe]+\.[ \u00a0]/
  340. ];
  341. text = text.replace(/^[\u00a0 ]+/, '');
  342. global$4.each(patterns, function (pattern) {
  343. if (pattern.test(text)) {
  344. found = true;
  345. return false;
  346. }
  347. });
  348. return found;
  349. }
  350. function isBulletList(text) {
  351. return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
  352. }
  353. function convertFakeListsToProperLists(node) {
  354. var currentListNode, prevListNode, lastLevel = 1;
  355. function getText(node) {
  356. var txt = '';
  357. if (node.type === 3) {
  358. return node.value;
  359. }
  360. if (node = node.firstChild) {
  361. do {
  362. txt += getText(node);
  363. } while (node = node.next);
  364. }
  365. return txt;
  366. }
  367. function trimListStart(node, regExp) {
  368. if (node.type === 3) {
  369. if (regExp.test(node.value)) {
  370. node.value = node.value.replace(regExp, '');
  371. return false;
  372. }
  373. }
  374. if (node = node.firstChild) {
  375. do {
  376. if (!trimListStart(node, regExp)) {
  377. return false;
  378. }
  379. } while (node = node.next);
  380. }
  381. return true;
  382. }
  383. function removeIgnoredNodes(node) {
  384. if (node._listIgnore) {
  385. node.remove();
  386. return;
  387. }
  388. if (node = node.firstChild) {
  389. do {
  390. removeIgnoredNodes(node);
  391. } while (node = node.next);
  392. }
  393. }
  394. function convertParagraphToLi(paragraphNode, listName, start) {
  395. var level = paragraphNode._listLevel || lastLevel;
  396. if (level !== lastLevel) {
  397. if (level < lastLevel) {
  398. if (currentListNode) {
  399. currentListNode = currentListNode.parent.parent;
  400. }
  401. } else {
  402. prevListNode = currentListNode;
  403. currentListNode = null;
  404. }
  405. }
  406. if (!currentListNode || currentListNode.name !== listName) {
  407. prevListNode = prevListNode || currentListNode;
  408. currentListNode = new global$9(listName, 1);
  409. if (start > 1) {
  410. currentListNode.attr('start', '' + start);
  411. }
  412. paragraphNode.wrap(currentListNode);
  413. } else {
  414. currentListNode.append(paragraphNode);
  415. }
  416. paragraphNode.name = 'li';
  417. if (level > lastLevel && prevListNode) {
  418. prevListNode.lastChild.append(currentListNode);
  419. }
  420. lastLevel = level;
  421. removeIgnoredNodes(paragraphNode);
  422. trimListStart(paragraphNode, /^\u00a0+/);
  423. trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
  424. trimListStart(paragraphNode, /^\u00a0+/);
  425. }
  426. var elements = [];
  427. var child = node.firstChild;
  428. while (typeof child !== 'undefined' && child !== null) {
  429. elements.push(child);
  430. child = child.walk();
  431. if (child !== null) {
  432. while (typeof child !== 'undefined' && child.parent !== node) {
  433. child = child.walk();
  434. }
  435. }
  436. }
  437. for (var i = 0; i < elements.length; i++) {
  438. node = elements[i];
  439. if (node.name === 'p' && node.firstChild) {
  440. var nodeText = getText(node);
  441. if (isBulletList(nodeText)) {
  442. convertParagraphToLi(node, 'ul');
  443. continue;
  444. }
  445. if (isNumericList(nodeText)) {
  446. var matches = /([0-9]+)\./.exec(nodeText);
  447. var start = 1;
  448. if (matches) {
  449. start = parseInt(matches[1], 10);
  450. }
  451. convertParagraphToLi(node, 'ol', start);
  452. continue;
  453. }
  454. if (node._listLevel) {
  455. convertParagraphToLi(node, 'ul', 1);
  456. continue;
  457. }
  458. currentListNode = null;
  459. } else {
  460. prevListNode = currentListNode;
  461. currentListNode = null;
  462. }
  463. }
  464. }
  465. function filterStyles(editor, validStyles, node, styleValue) {
  466. var outputStyles = {}, matches;
  467. var styles = editor.dom.parseStyle(styleValue);
  468. global$4.each(styles, function (value, name) {
  469. switch (name) {
  470. case 'mso-list':
  471. matches = /\w+ \w+([0-9]+)/i.exec(styleValue);
  472. if (matches) {
  473. node._listLevel = parseInt(matches[1], 10);
  474. }
  475. if (/Ignore/i.test(value) && node.firstChild) {
  476. node._listIgnore = true;
  477. node.firstChild._listIgnore = true;
  478. }
  479. break;
  480. case 'horiz-align':
  481. name = 'text-align';
  482. break;
  483. case 'vert-align':
  484. name = 'vertical-align';
  485. break;
  486. case 'font-color':
  487. case 'mso-foreground':
  488. name = 'color';
  489. break;
  490. case 'mso-background':
  491. case 'mso-highlight':
  492. name = 'background';
  493. break;
  494. case 'font-weight':
  495. case 'font-style':
  496. if (value !== 'normal') {
  497. outputStyles[name] = value;
  498. }
  499. return;
  500. case 'mso-element':
  501. if (/^(comment|comment-list)$/i.test(value)) {
  502. node.remove();
  503. return;
  504. }
  505. break;
  506. }
  507. if (name.indexOf('mso-comment') === 0) {
  508. node.remove();
  509. return;
  510. }
  511. if (name.indexOf('mso-') === 0) {
  512. return;
  513. }
  514. if (Settings.getRetainStyleProps(editor) === 'all' || validStyles && validStyles[name]) {
  515. outputStyles[name] = value;
  516. }
  517. });
  518. if (/(bold)/i.test(outputStyles['font-weight'])) {
  519. delete outputStyles['font-weight'];
  520. node.wrap(new global$9('b', 1));
  521. }
  522. if (/(italic)/i.test(outputStyles['font-style'])) {
  523. delete outputStyles['font-style'];
  524. node.wrap(new global$9('i', 1));
  525. }
  526. outputStyles = editor.dom.serializeStyle(outputStyles, node.name);
  527. if (outputStyles) {
  528. return outputStyles;
  529. }
  530. return null;
  531. }
  532. var filterWordContent = function (editor, content) {
  533. var retainStyleProperties, validStyles;
  534. retainStyleProperties = Settings.getRetainStyleProps(editor);
  535. if (retainStyleProperties) {
  536. validStyles = global$4.makeMap(retainStyleProperties.split(/[, ]/));
  537. }
  538. content = Utils.filter(content, [
  539. /<br class="?Apple-interchange-newline"?>/gi,
  540. /<b[^>]+id="?docs-internal-[^>]*>/gi,
  541. /<!--[\s\S]+?-->/gi,
  542. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
  543. [
  544. /<(\/?)s>/gi,
  545. '<$1strike>'
  546. ],
  547. [
  548. /&nbsp;/gi,
  549. '\xA0'
  550. ],
  551. [
  552. /<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
  553. function (str, spaces) {
  554. return spaces.length > 0 ? spaces.replace(/./, ' ').slice(Math.floor(spaces.length / 2)).split('').join('\xA0') : '';
  555. }
  556. ]
  557. ]);
  558. var validElements = Settings.getWordValidElements(editor);
  559. var schema = global$a({
  560. valid_elements: validElements,
  561. valid_children: '-li[p]'
  562. });
  563. global$4.each(schema.elements, function (rule) {
  564. if (!rule.attributes.class) {
  565. rule.attributes.class = {};
  566. rule.attributesOrder.push('class');
  567. }
  568. if (!rule.attributes.style) {
  569. rule.attributes.style = {};
  570. rule.attributesOrder.push('style');
  571. }
  572. });
  573. var domParser = global$7({}, schema);
  574. domParser.addAttributeFilter('style', function (nodes) {
  575. var i = nodes.length, node;
  576. while (i--) {
  577. node = nodes[i];
  578. node.attr('style', filterStyles(editor, validStyles, node, node.attr('style')));
  579. if (node.name === 'span' && node.parent && !node.attributes.length) {
  580. node.unwrap();
  581. }
  582. }
  583. });
  584. domParser.addAttributeFilter('class', function (nodes) {
  585. var i = nodes.length, node, className;
  586. while (i--) {
  587. node = nodes[i];
  588. className = node.attr('class');
  589. if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
  590. node.remove();
  591. }
  592. node.attr('class', null);
  593. }
  594. });
  595. domParser.addNodeFilter('del', function (nodes) {
  596. var i = nodes.length;
  597. while (i--) {
  598. nodes[i].remove();
  599. }
  600. });
  601. domParser.addNodeFilter('a', function (nodes) {
  602. var i = nodes.length, node, href, name;
  603. while (i--) {
  604. node = nodes[i];
  605. href = node.attr('href');
  606. name = node.attr('name');
  607. if (href && href.indexOf('#_msocom_') !== -1) {
  608. node.remove();
  609. continue;
  610. }
  611. if (href && href.indexOf('file://') === 0) {
  612. href = href.split('#')[1];
  613. if (href) {
  614. href = '#' + href;
  615. }
  616. }
  617. if (!href && !name) {
  618. node.unwrap();
  619. } else {
  620. if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) {
  621. node.unwrap();
  622. continue;
  623. }
  624. node.attr({
  625. href: href,
  626. name: name
  627. });
  628. }
  629. }
  630. });
  631. var rootNode = domParser.parse(content);
  632. if (Settings.shouldConvertWordFakeLists(editor)) {
  633. convertFakeListsToProperLists(rootNode);
  634. }
  635. content = global$8({ validate: editor.settings.validate }, schema).serialize(rootNode);
  636. return content;
  637. };
  638. var preProcess = function (editor, content) {
  639. return Settings.shouldUseDefaultFilters(editor) ? filterWordContent(editor, content) : content;
  640. };
  641. var WordFilter = {
  642. preProcess: preProcess,
  643. isWordContent: isWordContent
  644. };
  645. var preProcess$1 = function (editor, html) {
  646. var parser = global$7({}, editor.schema);
  647. parser.addNodeFilter('meta', function (nodes) {
  648. global$4.each(nodes, function (node) {
  649. return node.remove();
  650. });
  651. });
  652. var fragment = parser.parse(html, {
  653. forced_root_block: false,
  654. isRootContent: true
  655. });
  656. return global$8({ validate: editor.settings.validate }, editor.schema).serialize(fragment);
  657. };
  658. var processResult = function (content, cancelled) {
  659. return {
  660. content: content,
  661. cancelled: cancelled
  662. };
  663. };
  664. var postProcessFilter = function (editor, html, internal, isWordHtml) {
  665. var tempBody = editor.dom.create('div', { style: 'display:none' }, html);
  666. var postProcessArgs = Events.firePastePostProcess(editor, tempBody, internal, isWordHtml);
  667. return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented());
  668. };
  669. var filterContent = function (editor, content, internal, isWordHtml) {
  670. var preProcessArgs = Events.firePastePreProcess(editor, content, internal, isWordHtml);
  671. var filteredContent = preProcess$1(editor, preProcessArgs.content);
  672. if (editor.hasEventListeners('PastePostProcess') && !preProcessArgs.isDefaultPrevented()) {
  673. return postProcessFilter(editor, filteredContent, internal, isWordHtml);
  674. } else {
  675. return processResult(filteredContent, preProcessArgs.isDefaultPrevented());
  676. }
  677. };
  678. var process = function (editor, html, internal) {
  679. var isWordHtml = WordFilter.isWordContent(html);
  680. var content = isWordHtml ? WordFilter.preProcess(editor, html) : html;
  681. return filterContent(editor, content, internal, isWordHtml);
  682. };
  683. var ProcessFilters = { process: process };
  684. var pasteHtml = function (editor, html) {
  685. editor.insertContent(html, {
  686. merge: Settings.shouldMergeFormats(editor),
  687. paste: true
  688. });
  689. return true;
  690. };
  691. var isAbsoluteUrl = function (url) {
  692. return /^https?:\/\/[\w\?\-\/+=.&%@~#]+$/i.test(url);
  693. };
  694. var isImageUrl = function (url) {
  695. return isAbsoluteUrl(url) && /.(gif|jpe?g|png)$/.test(url);
  696. };
  697. var createImage = function (editor, url, pasteHtmlFn) {
  698. editor.undoManager.extra(function () {
  699. pasteHtmlFn(editor, url);
  700. }, function () {
  701. editor.insertContent('<img src="' + url + '">');
  702. });
  703. return true;
  704. };
  705. var createLink = function (editor, url, pasteHtmlFn) {
  706. editor.undoManager.extra(function () {
  707. pasteHtmlFn(editor, url);
  708. }, function () {
  709. editor.execCommand('mceInsertLink', false, url);
  710. });
  711. return true;
  712. };
  713. var linkSelection = function (editor, html, pasteHtmlFn) {
  714. return editor.selection.isCollapsed() === false && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtmlFn) : false;
  715. };
  716. var insertImage = function (editor, html, pasteHtmlFn) {
  717. return isImageUrl(html) ? createImage(editor, html, pasteHtmlFn) : false;
  718. };
  719. var smartInsertContent = function (editor, html) {
  720. global$4.each([
  721. linkSelection,
  722. insertImage,
  723. pasteHtml
  724. ], function (action) {
  725. return action(editor, html, pasteHtml) !== true;
  726. });
  727. };
  728. var insertContent = function (editor, html) {
  729. if (Settings.isSmartPasteEnabled(editor) === false) {
  730. pasteHtml(editor, html);
  731. } else {
  732. smartInsertContent(editor, html);
  733. }
  734. };
  735. var SmartPaste = {
  736. isImageUrl: isImageUrl,
  737. isAbsoluteUrl: isAbsoluteUrl,
  738. insertContent: insertContent
  739. };
  740. var noop = function () {
  741. };
  742. var constant = function (value) {
  743. return function () {
  744. return value;
  745. };
  746. };
  747. function curry(fn) {
  748. var initialArgs = [];
  749. for (var _i = 1; _i < arguments.length; _i++) {
  750. initialArgs[_i - 1] = arguments[_i];
  751. }
  752. return function () {
  753. var restArgs = [];
  754. for (var _i = 0; _i < arguments.length; _i++) {
  755. restArgs[_i] = arguments[_i];
  756. }
  757. var all = initialArgs.concat(restArgs);
  758. return fn.apply(null, all);
  759. };
  760. }
  761. var never = constant(false);
  762. var always = constant(true);
  763. var none = function () {
  764. return NONE;
  765. };
  766. var NONE = function () {
  767. var eq = function (o) {
  768. return o.isNone();
  769. };
  770. var call = function (thunk) {
  771. return thunk();
  772. };
  773. var id = function (n) {
  774. return n;
  775. };
  776. var me = {
  777. fold: function (n, s) {
  778. return n();
  779. },
  780. is: never,
  781. isSome: never,
  782. isNone: always,
  783. getOr: id,
  784. getOrThunk: call,
  785. getOrDie: function (msg) {
  786. throw new Error(msg || 'error: getOrDie called on none.');
  787. },
  788. getOrNull: constant(null),
  789. getOrUndefined: constant(undefined),
  790. or: id,
  791. orThunk: call,
  792. map: none,
  793. each: noop,
  794. bind: none,
  795. exists: never,
  796. forall: always,
  797. filter: none,
  798. equals: eq,
  799. equals_: eq,
  800. toArray: function () {
  801. return [];
  802. },
  803. toString: constant('none()')
  804. };
  805. if (Object.freeze) {
  806. Object.freeze(me);
  807. }
  808. return me;
  809. }();
  810. var some = function (a) {
  811. var constant_a = constant(a);
  812. var self = function () {
  813. return me;
  814. };
  815. var bind = function (f) {
  816. return f(a);
  817. };
  818. var me = {
  819. fold: function (n, s) {
  820. return s(a);
  821. },
  822. is: function (v) {
  823. return a === v;
  824. },
  825. isSome: always,
  826. isNone: never,
  827. getOr: constant_a,
  828. getOrThunk: constant_a,
  829. getOrDie: constant_a,
  830. getOrNull: constant_a,
  831. getOrUndefined: constant_a,
  832. or: self,
  833. orThunk: self,
  834. map: function (f) {
  835. return some(f(a));
  836. },
  837. each: function (f) {
  838. f(a);
  839. },
  840. bind: bind,
  841. exists: bind,
  842. forall: bind,
  843. filter: function (f) {
  844. return f(a) ? me : NONE;
  845. },
  846. toArray: function () {
  847. return [a];
  848. },
  849. toString: function () {
  850. return 'some(' + a + ')';
  851. },
  852. equals: function (o) {
  853. return o.is(a);
  854. },
  855. equals_: function (o, elementEq) {
  856. return o.fold(never, function (b) {
  857. return elementEq(a, b);
  858. });
  859. }
  860. };
  861. return me;
  862. };
  863. var from = function (value) {
  864. return value === null || value === undefined ? NONE : some(value);
  865. };
  866. var Option = {
  867. some: some,
  868. none: none,
  869. from: from
  870. };
  871. var typeOf = function (x) {
  872. if (x === null) {
  873. return 'null';
  874. }
  875. var t = typeof x;
  876. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  877. return 'array';
  878. }
  879. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  880. return 'string';
  881. }
  882. return t;
  883. };
  884. var isType = function (type) {
  885. return function (value) {
  886. return typeOf(value) === type;
  887. };
  888. };
  889. var isFunction = isType('function');
  890. var nativeSlice = Array.prototype.slice;
  891. var map = function (xs, f) {
  892. var len = xs.length;
  893. var r = new Array(len);
  894. for (var i = 0; i < len; i++) {
  895. var x = xs[i];
  896. r[i] = f(x, i);
  897. }
  898. return r;
  899. };
  900. var each = function (xs, f) {
  901. for (var i = 0, len = xs.length; i < len; i++) {
  902. var x = xs[i];
  903. f(x, i);
  904. }
  905. };
  906. var filter$1 = function (xs, pred) {
  907. var r = [];
  908. for (var i = 0, len = xs.length; i < len; i++) {
  909. var x = xs[i];
  910. if (pred(x, i)) {
  911. r.push(x);
  912. }
  913. }
  914. return r;
  915. };
  916. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  917. return nativeSlice.call(x);
  918. };
  919. var exports$1 = {}, module = { exports: exports$1 };
  920. (function (define, exports, module, require) {
  921. (function (f) {
  922. if (typeof exports === 'object' && typeof module !== 'undefined') {
  923. module.exports = f();
  924. } else if (typeof define === 'function' && define.amd) {
  925. define([], f);
  926. } else {
  927. var g;
  928. if (typeof window !== 'undefined') {
  929. g = window;
  930. } else if (typeof global !== 'undefined') {
  931. g = global;
  932. } else if (typeof self !== 'undefined') {
  933. g = self;
  934. } else {
  935. g = this;
  936. }
  937. g.EphoxContactWrapper = f();
  938. }
  939. }(function () {
  940. return function () {
  941. function r(e, n, t) {
  942. function o(i, f) {
  943. if (!n[i]) {
  944. if (!e[i]) {
  945. var c = 'function' == typeof require && require;
  946. if (!f && c)
  947. return c(i, !0);
  948. if (u)
  949. return u(i, !0);
  950. var a = new Error('Cannot find module \'' + i + '\'');
  951. throw a.code = 'MODULE_NOT_FOUND', a;
  952. }
  953. var p = n[i] = { exports: {} };
  954. e[i][0].call(p.exports, function (r) {
  955. var n = e[i][1][r];
  956. return o(n || r);
  957. }, p, p.exports, r, e, n, t);
  958. }
  959. return n[i].exports;
  960. }
  961. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  962. o(t[i]);
  963. return o;
  964. }
  965. return r;
  966. }()({
  967. 1: [
  968. function (require, module, exports) {
  969. var process = module.exports = {};
  970. var cachedSetTimeout;
  971. var cachedClearTimeout;
  972. function defaultSetTimout() {
  973. throw new Error('setTimeout has not been defined');
  974. }
  975. function defaultClearTimeout() {
  976. throw new Error('clearTimeout has not been defined');
  977. }
  978. (function () {
  979. try {
  980. if (typeof setTimeout === 'function') {
  981. cachedSetTimeout = setTimeout;
  982. } else {
  983. cachedSetTimeout = defaultSetTimout;
  984. }
  985. } catch (e) {
  986. cachedSetTimeout = defaultSetTimout;
  987. }
  988. try {
  989. if (typeof clearTimeout === 'function') {
  990. cachedClearTimeout = clearTimeout;
  991. } else {
  992. cachedClearTimeout = defaultClearTimeout;
  993. }
  994. } catch (e) {
  995. cachedClearTimeout = defaultClearTimeout;
  996. }
  997. }());
  998. function runTimeout(fun) {
  999. if (cachedSetTimeout === setTimeout) {
  1000. return setTimeout(fun, 0);
  1001. }
  1002. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1003. cachedSetTimeout = setTimeout;
  1004. return setTimeout(fun, 0);
  1005. }
  1006. try {
  1007. return cachedSetTimeout(fun, 0);
  1008. } catch (e) {
  1009. try {
  1010. return cachedSetTimeout.call(null, fun, 0);
  1011. } catch (e) {
  1012. return cachedSetTimeout.call(this, fun, 0);
  1013. }
  1014. }
  1015. }
  1016. function runClearTimeout(marker) {
  1017. if (cachedClearTimeout === clearTimeout) {
  1018. return clearTimeout(marker);
  1019. }
  1020. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1021. cachedClearTimeout = clearTimeout;
  1022. return clearTimeout(marker);
  1023. }
  1024. try {
  1025. return cachedClearTimeout(marker);
  1026. } catch (e) {
  1027. try {
  1028. return cachedClearTimeout.call(null, marker);
  1029. } catch (e) {
  1030. return cachedClearTimeout.call(this, marker);
  1031. }
  1032. }
  1033. }
  1034. var queue = [];
  1035. var draining = false;
  1036. var currentQueue;
  1037. var queueIndex = -1;
  1038. function cleanUpNextTick() {
  1039. if (!draining || !currentQueue) {
  1040. return;
  1041. }
  1042. draining = false;
  1043. if (currentQueue.length) {
  1044. queue = currentQueue.concat(queue);
  1045. } else {
  1046. queueIndex = -1;
  1047. }
  1048. if (queue.length) {
  1049. drainQueue();
  1050. }
  1051. }
  1052. function drainQueue() {
  1053. if (draining) {
  1054. return;
  1055. }
  1056. var timeout = runTimeout(cleanUpNextTick);
  1057. draining = true;
  1058. var len = queue.length;
  1059. while (len) {
  1060. currentQueue = queue;
  1061. queue = [];
  1062. while (++queueIndex < len) {
  1063. if (currentQueue) {
  1064. currentQueue[queueIndex].run();
  1065. }
  1066. }
  1067. queueIndex = -1;
  1068. len = queue.length;
  1069. }
  1070. currentQueue = null;
  1071. draining = false;
  1072. runClearTimeout(timeout);
  1073. }
  1074. process.nextTick = function (fun) {
  1075. var args = new Array(arguments.length - 1);
  1076. if (arguments.length > 1) {
  1077. for (var i = 1; i < arguments.length; i++) {
  1078. args[i - 1] = arguments[i];
  1079. }
  1080. }
  1081. queue.push(new Item(fun, args));
  1082. if (queue.length === 1 && !draining) {
  1083. runTimeout(drainQueue);
  1084. }
  1085. };
  1086. function Item(fun, array) {
  1087. this.fun = fun;
  1088. this.array = array;
  1089. }
  1090. Item.prototype.run = function () {
  1091. this.fun.apply(null, this.array);
  1092. };
  1093. process.title = 'browser';
  1094. process.browser = true;
  1095. process.env = {};
  1096. process.argv = [];
  1097. process.version = '';
  1098. process.versions = {};
  1099. function noop() {
  1100. }
  1101. process.on = noop;
  1102. process.addListener = noop;
  1103. process.once = noop;
  1104. process.off = noop;
  1105. process.removeListener = noop;
  1106. process.removeAllListeners = noop;
  1107. process.emit = noop;
  1108. process.prependListener = noop;
  1109. process.prependOnceListener = noop;
  1110. process.listeners = function (name) {
  1111. return [];
  1112. };
  1113. process.binding = function (name) {
  1114. throw new Error('process.binding is not supported');
  1115. };
  1116. process.cwd = function () {
  1117. return '/';
  1118. };
  1119. process.chdir = function (dir) {
  1120. throw new Error('process.chdir is not supported');
  1121. };
  1122. process.umask = function () {
  1123. return 0;
  1124. };
  1125. },
  1126. {}
  1127. ],
  1128. 2: [
  1129. function (require, module, exports) {
  1130. (function (setImmediate) {
  1131. (function (root) {
  1132. var setTimeoutFunc = setTimeout;
  1133. function noop() {
  1134. }
  1135. function bind(fn, thisArg) {
  1136. return function () {
  1137. fn.apply(thisArg, arguments);
  1138. };
  1139. }
  1140. function Promise(fn) {
  1141. if (typeof this !== 'object')
  1142. throw new TypeError('Promises must be constructed via new');
  1143. if (typeof fn !== 'function')
  1144. throw new TypeError('not a function');
  1145. this._state = 0;
  1146. this._handled = false;
  1147. this._value = undefined;
  1148. this._deferreds = [];
  1149. doResolve(fn, this);
  1150. }
  1151. function handle(self, deferred) {
  1152. while (self._state === 3) {
  1153. self = self._value;
  1154. }
  1155. if (self._state === 0) {
  1156. self._deferreds.push(deferred);
  1157. return;
  1158. }
  1159. self._handled = true;
  1160. Promise._immediateFn(function () {
  1161. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  1162. if (cb === null) {
  1163. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  1164. return;
  1165. }
  1166. var ret;
  1167. try {
  1168. ret = cb(self._value);
  1169. } catch (e) {
  1170. reject(deferred.promise, e);
  1171. return;
  1172. }
  1173. resolve(deferred.promise, ret);
  1174. });
  1175. }
  1176. function resolve(self, newValue) {
  1177. try {
  1178. if (newValue === self)
  1179. throw new TypeError('A promise cannot be resolved with itself.');
  1180. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  1181. var then = newValue.then;
  1182. if (newValue instanceof Promise) {
  1183. self._state = 3;
  1184. self._value = newValue;
  1185. finale(self);
  1186. return;
  1187. } else if (typeof then === 'function') {
  1188. doResolve(bind(then, newValue), self);
  1189. return;
  1190. }
  1191. }
  1192. self._state = 1;
  1193. self._value = newValue;
  1194. finale(self);
  1195. } catch (e) {
  1196. reject(self, e);
  1197. }
  1198. }
  1199. function reject(self, newValue) {
  1200. self._state = 2;
  1201. self._value = newValue;
  1202. finale(self);
  1203. }
  1204. function finale(self) {
  1205. if (self._state === 2 && self._deferreds.length === 0) {
  1206. Promise._immediateFn(function () {
  1207. if (!self._handled) {
  1208. Promise._unhandledRejectionFn(self._value);
  1209. }
  1210. });
  1211. }
  1212. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  1213. handle(self, self._deferreds[i]);
  1214. }
  1215. self._deferreds = null;
  1216. }
  1217. function Handler(onFulfilled, onRejected, promise) {
  1218. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  1219. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  1220. this.promise = promise;
  1221. }
  1222. function doResolve(fn, self) {
  1223. var done = false;
  1224. try {
  1225. fn(function (value) {
  1226. if (done)
  1227. return;
  1228. done = true;
  1229. resolve(self, value);
  1230. }, function (reason) {
  1231. if (done)
  1232. return;
  1233. done = true;
  1234. reject(self, reason);
  1235. });
  1236. } catch (ex) {
  1237. if (done)
  1238. return;
  1239. done = true;
  1240. reject(self, ex);
  1241. }
  1242. }
  1243. Promise.prototype['catch'] = function (onRejected) {
  1244. return this.then(null, onRejected);
  1245. };
  1246. Promise.prototype.then = function (onFulfilled, onRejected) {
  1247. var prom = new this.constructor(noop);
  1248. handle(this, new Handler(onFulfilled, onRejected, prom));
  1249. return prom;
  1250. };
  1251. Promise.all = function (arr) {
  1252. var args = Array.prototype.slice.call(arr);
  1253. return new Promise(function (resolve, reject) {
  1254. if (args.length === 0)
  1255. return resolve([]);
  1256. var remaining = args.length;
  1257. function res(i, val) {
  1258. try {
  1259. if (val && (typeof val === 'object' || typeof val === 'function')) {
  1260. var then = val.then;
  1261. if (typeof then === 'function') {
  1262. then.call(val, function (val) {
  1263. res(i, val);
  1264. }, reject);
  1265. return;
  1266. }
  1267. }
  1268. args[i] = val;
  1269. if (--remaining === 0) {
  1270. resolve(args);
  1271. }
  1272. } catch (ex) {
  1273. reject(ex);
  1274. }
  1275. }
  1276. for (var i = 0; i < args.length; i++) {
  1277. res(i, args[i]);
  1278. }
  1279. });
  1280. };
  1281. Promise.resolve = function (value) {
  1282. if (value && typeof value === 'object' && value.constructor === Promise) {
  1283. return value;
  1284. }
  1285. return new Promise(function (resolve) {
  1286. resolve(value);
  1287. });
  1288. };
  1289. Promise.reject = function (value) {
  1290. return new Promise(function (resolve, reject) {
  1291. reject(value);
  1292. });
  1293. };
  1294. Promise.race = function (values) {
  1295. return new Promise(function (resolve, reject) {
  1296. for (var i = 0, len = values.length; i < len; i++) {
  1297. values[i].then(resolve, reject);
  1298. }
  1299. });
  1300. };
  1301. Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
  1302. setImmediate(fn);
  1303. } : function (fn) {
  1304. setTimeoutFunc(fn, 0);
  1305. };
  1306. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  1307. if (typeof console !== 'undefined' && console) {
  1308. console.warn('Possible Unhandled Promise Rejection:', err);
  1309. }
  1310. };
  1311. Promise._setImmediateFn = function _setImmediateFn(fn) {
  1312. Promise._immediateFn = fn;
  1313. };
  1314. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  1315. Promise._unhandledRejectionFn = fn;
  1316. };
  1317. if (typeof module !== 'undefined' && module.exports) {
  1318. module.exports = Promise;
  1319. } else if (!root.Promise) {
  1320. root.Promise = Promise;
  1321. }
  1322. }(this));
  1323. }.call(this, require('timers').setImmediate));
  1324. },
  1325. { 'timers': 3 }
  1326. ],
  1327. 3: [
  1328. function (require, module, exports) {
  1329. (function (setImmediate, clearImmediate) {
  1330. var nextTick = require('process/browser.js').nextTick;
  1331. var apply = Function.prototype.apply;
  1332. var slice = Array.prototype.slice;
  1333. var immediateIds = {};
  1334. var nextImmediateId = 0;
  1335. exports.setTimeout = function () {
  1336. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  1337. };
  1338. exports.setInterval = function () {
  1339. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  1340. };
  1341. exports.clearTimeout = exports.clearInterval = function (timeout) {
  1342. timeout.close();
  1343. };
  1344. function Timeout(id, clearFn) {
  1345. this._id = id;
  1346. this._clearFn = clearFn;
  1347. }
  1348. Timeout.prototype.unref = Timeout.prototype.ref = function () {
  1349. };
  1350. Timeout.prototype.close = function () {
  1351. this._clearFn.call(window, this._id);
  1352. };
  1353. exports.enroll = function (item, msecs) {
  1354. clearTimeout(item._idleTimeoutId);
  1355. item._idleTimeout = msecs;
  1356. };
  1357. exports.unenroll = function (item) {
  1358. clearTimeout(item._idleTimeoutId);
  1359. item._idleTimeout = -1;
  1360. };
  1361. exports._unrefActive = exports.active = function (item) {
  1362. clearTimeout(item._idleTimeoutId);
  1363. var msecs = item._idleTimeout;
  1364. if (msecs >= 0) {
  1365. item._idleTimeoutId = setTimeout(function onTimeout() {
  1366. if (item._onTimeout)
  1367. item._onTimeout();
  1368. }, msecs);
  1369. }
  1370. };
  1371. exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
  1372. var id = nextImmediateId++;
  1373. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  1374. immediateIds[id] = true;
  1375. nextTick(function onNextTick() {
  1376. if (immediateIds[id]) {
  1377. if (args) {
  1378. fn.apply(null, args);
  1379. } else {
  1380. fn.call(null);
  1381. }
  1382. exports.clearImmediate(id);
  1383. }
  1384. });
  1385. return id;
  1386. };
  1387. exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
  1388. delete immediateIds[id];
  1389. };
  1390. }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
  1391. },
  1392. {
  1393. 'process/browser.js': 1,
  1394. 'timers': 3
  1395. }
  1396. ],
  1397. 4: [
  1398. function (require, module, exports) {
  1399. var promisePolyfill = require('promise-polyfill');
  1400. var Global = function () {
  1401. if (typeof window !== 'undefined') {
  1402. return window;
  1403. } else {
  1404. return Function('return this;')();
  1405. }
  1406. }();
  1407. module.exports = { boltExport: Global.Promise || promisePolyfill };
  1408. },
  1409. { 'promise-polyfill': 2 }
  1410. ]
  1411. }, {}, [4])(4);
  1412. }));
  1413. }(undefined, exports$1, module, undefined));
  1414. var Promise = module.exports.boltExport;
  1415. var nu = function (baseFn) {
  1416. var data = Option.none();
  1417. var callbacks = [];
  1418. var map = function (f) {
  1419. return nu(function (nCallback) {
  1420. get(function (data) {
  1421. nCallback(f(data));
  1422. });
  1423. });
  1424. };
  1425. var get = function (nCallback) {
  1426. if (isReady()) {
  1427. call(nCallback);
  1428. } else {
  1429. callbacks.push(nCallback);
  1430. }
  1431. };
  1432. var set = function (x) {
  1433. data = Option.some(x);
  1434. run(callbacks);
  1435. callbacks = [];
  1436. };
  1437. var isReady = function () {
  1438. return data.isSome();
  1439. };
  1440. var run = function (cbs) {
  1441. each(cbs, call);
  1442. };
  1443. var call = function (cb) {
  1444. data.each(function (x) {
  1445. domGlobals.setTimeout(function () {
  1446. cb(x);
  1447. }, 0);
  1448. });
  1449. };
  1450. baseFn(set);
  1451. return {
  1452. get: get,
  1453. map: map,
  1454. isReady: isReady
  1455. };
  1456. };
  1457. var pure = function (a) {
  1458. return nu(function (callback) {
  1459. callback(a);
  1460. });
  1461. };
  1462. var LazyValue = {
  1463. nu: nu,
  1464. pure: pure
  1465. };
  1466. var errorReporter = function (err) {
  1467. domGlobals.setTimeout(function () {
  1468. throw err;
  1469. }, 0);
  1470. };
  1471. var make = function (run) {
  1472. var get = function (callback) {
  1473. run().then(callback, errorReporter);
  1474. };
  1475. var map = function (fab) {
  1476. return make(function () {
  1477. return run().then(fab);
  1478. });
  1479. };
  1480. var bind = function (aFutureB) {
  1481. return make(function () {
  1482. return run().then(function (v) {
  1483. return aFutureB(v).toPromise();
  1484. });
  1485. });
  1486. };
  1487. var anonBind = function (futureB) {
  1488. return make(function () {
  1489. return run().then(function () {
  1490. return futureB.toPromise();
  1491. });
  1492. });
  1493. };
  1494. var toLazy = function () {
  1495. return LazyValue.nu(get);
  1496. };
  1497. var toCached = function () {
  1498. var cache = null;
  1499. return make(function () {
  1500. if (cache === null) {
  1501. cache = run();
  1502. }
  1503. return cache;
  1504. });
  1505. };
  1506. var toPromise = run;
  1507. return {
  1508. map: map,
  1509. bind: bind,
  1510. anonBind: anonBind,
  1511. toLazy: toLazy,
  1512. toCached: toCached,
  1513. toPromise: toPromise,
  1514. get: get
  1515. };
  1516. };
  1517. var nu$1 = function (baseFn) {
  1518. return make(function () {
  1519. return new Promise(baseFn);
  1520. });
  1521. };
  1522. var pure$1 = function (a) {
  1523. return make(function () {
  1524. return Promise.resolve(a);
  1525. });
  1526. };
  1527. var Future = {
  1528. nu: nu$1,
  1529. pure: pure$1
  1530. };
  1531. var par = function (asyncValues, nu) {
  1532. return nu(function (callback) {
  1533. var r = [];
  1534. var count = 0;
  1535. var cb = function (i) {
  1536. return function (value) {
  1537. r[i] = value;
  1538. count++;
  1539. if (count >= asyncValues.length) {
  1540. callback(r);
  1541. }
  1542. };
  1543. };
  1544. if (asyncValues.length === 0) {
  1545. callback([]);
  1546. } else {
  1547. each(asyncValues, function (asyncValue, i) {
  1548. asyncValue.get(cb(i));
  1549. });
  1550. }
  1551. });
  1552. };
  1553. var par$1 = function (futures) {
  1554. return par(futures, Future.nu);
  1555. };
  1556. var traverse = function (array, fn) {
  1557. return par$1(map(array, fn));
  1558. };
  1559. var mapM = traverse;
  1560. var value = function () {
  1561. var subject = Cell(Option.none());
  1562. var clear = function () {
  1563. subject.set(Option.none());
  1564. };
  1565. var set = function (s) {
  1566. subject.set(Option.some(s));
  1567. };
  1568. var on = function (f) {
  1569. subject.get().each(f);
  1570. };
  1571. var isSet = function () {
  1572. return subject.get().isSome();
  1573. };
  1574. return {
  1575. clear: clear,
  1576. set: set,
  1577. isSet: isSet,
  1578. on: on
  1579. };
  1580. };
  1581. var pasteHtml$1 = function (editor, html, internalFlag) {
  1582. var internal = internalFlag ? internalFlag : InternalHtml.isMarked(html);
  1583. var args = ProcessFilters.process(editor, InternalHtml.unmark(html), internal);
  1584. if (args.cancelled === false) {
  1585. SmartPaste.insertContent(editor, args.content);
  1586. }
  1587. };
  1588. var pasteText = function (editor, text) {
  1589. text = editor.dom.encode(text).replace(/\r\n/g, '\n');
  1590. text = Newlines.convert(text, editor.settings.forced_root_block, editor.settings.forced_root_block_attrs);
  1591. pasteHtml$1(editor, text, false);
  1592. };
  1593. var getDataTransferItems = function (dataTransfer) {
  1594. var items = {};
  1595. var mceInternalUrlPrefix = 'data:text/mce-internal,';
  1596. if (dataTransfer) {
  1597. if (dataTransfer.getData) {
  1598. var legacyText = dataTransfer.getData('Text');
  1599. if (legacyText && legacyText.length > 0) {
  1600. if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
  1601. items['text/plain'] = legacyText;
  1602. }
  1603. }
  1604. }
  1605. if (dataTransfer.types) {
  1606. for (var i = 0; i < dataTransfer.types.length; i++) {
  1607. var contentType = dataTransfer.types[i];
  1608. try {
  1609. items[contentType] = dataTransfer.getData(contentType);
  1610. } catch (ex) {
  1611. items[contentType] = '';
  1612. }
  1613. }
  1614. }
  1615. }
  1616. return items;
  1617. };
  1618. var getClipboardContent = function (editor, clipboardEvent) {
  1619. var content = getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
  1620. return Utils.isMsEdge() ? global$4.extend(content, { 'text/html': '' }) : content;
  1621. };
  1622. var hasContentType = function (clipboardContent, mimeType) {
  1623. return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
  1624. };
  1625. var hasHtmlOrText = function (content) {
  1626. return hasContentType(content, 'text/html') || hasContentType(content, 'text/plain');
  1627. };
  1628. var getBase64FromUri = function (uri) {
  1629. var idx;
  1630. idx = uri.indexOf(',');
  1631. if (idx !== -1) {
  1632. return uri.substr(idx + 1);
  1633. }
  1634. return null;
  1635. };
  1636. var isValidDataUriImage = function (settings, imgElm) {
  1637. return settings.images_dataimg_filter ? settings.images_dataimg_filter(imgElm) : true;
  1638. };
  1639. var extractFilename = function (editor, str) {
  1640. var m = str.match(/([\s\S]+?)\.(?:jpeg|jpg|png|gif)$/i);
  1641. return m ? editor.dom.encode(m[1]) : null;
  1642. };
  1643. var uniqueId = Utils.createIdGenerator('mceclip');
  1644. var pasteImage = function (editor, imageItem) {
  1645. var base64 = getBase64FromUri(imageItem.uri);
  1646. var id = uniqueId();
  1647. var name = editor.settings.images_reuse_filename && imageItem.blob.name ? extractFilename(editor, imageItem.blob.name) : id;
  1648. var img = new domGlobals.Image();
  1649. img.src = imageItem.uri;
  1650. if (isValidDataUriImage(editor.settings, img)) {
  1651. var blobCache = editor.editorUpload.blobCache;
  1652. var blobInfo = void 0, existingBlobInfo = void 0;
  1653. existingBlobInfo = blobCache.findFirst(function (cachedBlobInfo) {
  1654. return cachedBlobInfo.base64() === base64;
  1655. });
  1656. if (!existingBlobInfo) {
  1657. blobInfo = blobCache.create(id, imageItem.blob, base64, name);
  1658. blobCache.add(blobInfo);
  1659. } else {
  1660. blobInfo = existingBlobInfo;
  1661. }
  1662. pasteHtml$1(editor, '<img src="' + blobInfo.blobUri() + '">', false);
  1663. } else {
  1664. pasteHtml$1(editor, '<img src="' + imageItem.uri + '">', false);
  1665. }
  1666. };
  1667. var isClipboardEvent = function (event) {
  1668. return event.type === 'paste';
  1669. };
  1670. var readBlobsAsDataUris = function (items) {
  1671. return mapM(items, function (item) {
  1672. return Future.nu(function (resolve) {
  1673. var blob = item.getAsFile ? item.getAsFile() : item;
  1674. var reader = new window.FileReader();
  1675. reader.onload = function () {
  1676. resolve({
  1677. blob: blob,
  1678. uri: reader.result
  1679. });
  1680. };
  1681. reader.readAsDataURL(blob);
  1682. });
  1683. });
  1684. };
  1685. var getImagesFromDataTransfer = function (dataTransfer) {
  1686. var items = dataTransfer.items ? map(from$1(dataTransfer.items), function (item) {
  1687. return item.getAsFile();
  1688. }) : [];
  1689. var files = dataTransfer.files ? from$1(dataTransfer.files) : [];
  1690. var images = filter$1(items.length > 0 ? items : files, function (file) {
  1691. return /^image\/(jpeg|png|gif|bmp)$/.test(file.type);
  1692. });
  1693. return images;
  1694. };
  1695. var pasteImageData = function (editor, e, rng) {
  1696. var dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
  1697. if (editor.settings.paste_data_images && dataTransfer) {
  1698. var images = getImagesFromDataTransfer(dataTransfer);
  1699. if (images.length > 0) {
  1700. e.preventDefault();
  1701. readBlobsAsDataUris(images).get(function (blobResults) {
  1702. if (rng) {
  1703. editor.selection.setRng(rng);
  1704. }
  1705. each(blobResults, function (result) {
  1706. pasteImage(editor, result);
  1707. });
  1708. });
  1709. return true;
  1710. }
  1711. }
  1712. return false;
  1713. };
  1714. var isBrokenAndroidClipboardEvent = function (e) {
  1715. var clipboardData = e.clipboardData;
  1716. return domGlobals.navigator.userAgent.indexOf('Android') !== -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
  1717. };
  1718. var isKeyboardPasteEvent = function (e) {
  1719. return global$5.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
  1720. };
  1721. var registerEventHandlers = function (editor, pasteBin, pasteFormat) {
  1722. var keyboardPasteEvent = value();
  1723. var keyboardPastePlainTextState;
  1724. editor.on('keydown', function (e) {
  1725. function removePasteBinOnKeyUp(e) {
  1726. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  1727. pasteBin.remove();
  1728. }
  1729. }
  1730. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  1731. keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
  1732. if (keyboardPastePlainTextState && global$2.webkit && domGlobals.navigator.userAgent.indexOf('Version/') !== -1) {
  1733. return;
  1734. }
  1735. e.stopImmediatePropagation();
  1736. keyboardPasteEvent.set(e);
  1737. window.setTimeout(function () {
  1738. keyboardPasteEvent.clear();
  1739. }, 100);
  1740. if (global$2.ie && keyboardPastePlainTextState) {
  1741. e.preventDefault();
  1742. Events.firePaste(editor, true);
  1743. return;
  1744. }
  1745. pasteBin.remove();
  1746. pasteBin.create();
  1747. editor.once('keyup', removePasteBinOnKeyUp);
  1748. editor.once('paste', function () {
  1749. editor.off('keyup', removePasteBinOnKeyUp);
  1750. });
  1751. }
  1752. });
  1753. function insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal) {
  1754. var content, isPlainTextHtml;
  1755. if (hasContentType(clipboardContent, 'text/html')) {
  1756. content = clipboardContent['text/html'];
  1757. } else {
  1758. content = pasteBin.getHtml();
  1759. internal = internal ? internal : InternalHtml.isMarked(content);
  1760. if (pasteBin.isDefaultContent(content)) {
  1761. plainTextMode = true;
  1762. }
  1763. }
  1764. content = Utils.trimHtml(content);
  1765. pasteBin.remove();
  1766. isPlainTextHtml = internal === false && Newlines.isPlainText(content);
  1767. if (!content.length || isPlainTextHtml) {
  1768. plainTextMode = true;
  1769. }
  1770. if (plainTextMode) {
  1771. if (hasContentType(clipboardContent, 'text/plain') && isPlainTextHtml) {
  1772. content = clipboardContent['text/plain'];
  1773. } else {
  1774. content = Utils.innerText(content);
  1775. }
  1776. }
  1777. if (pasteBin.isDefaultContent(content)) {
  1778. if (!isKeyBoardPaste) {
  1779. editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
  1780. }
  1781. return;
  1782. }
  1783. if (plainTextMode) {
  1784. pasteText(editor, content);
  1785. } else {
  1786. pasteHtml$1(editor, content, internal);
  1787. }
  1788. }
  1789. var getLastRng = function () {
  1790. return pasteBin.getLastRng() || editor.selection.getRng();
  1791. };
  1792. editor.on('paste', function (e) {
  1793. var isKeyBoardPaste = keyboardPasteEvent.isSet();
  1794. var clipboardContent = getClipboardContent(editor, e);
  1795. var plainTextMode = pasteFormat.get() === 'text' || keyboardPastePlainTextState;
  1796. var internal = hasContentType(clipboardContent, InternalHtml.internalHtmlMime());
  1797. keyboardPastePlainTextState = false;
  1798. if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
  1799. pasteBin.remove();
  1800. return;
  1801. }
  1802. if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
  1803. pasteBin.remove();
  1804. return;
  1805. }
  1806. if (!isKeyBoardPaste) {
  1807. e.preventDefault();
  1808. }
  1809. if (global$2.ie && (!isKeyBoardPaste || e.ieFake) && !hasContentType(clipboardContent, 'text/html')) {
  1810. pasteBin.create();
  1811. editor.dom.bind(pasteBin.getEl(), 'paste', function (e) {
  1812. e.stopPropagation();
  1813. });
  1814. editor.getDoc().execCommand('Paste', false, null);
  1815. clipboardContent['text/html'] = pasteBin.getHtml();
  1816. }
  1817. if (hasContentType(clipboardContent, 'text/html')) {
  1818. e.preventDefault();
  1819. if (!internal) {
  1820. internal = InternalHtml.isMarked(clipboardContent['text/html']);
  1821. }
  1822. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  1823. } else {
  1824. global$3.setEditorTimeout(editor, function () {
  1825. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  1826. }, 0);
  1827. }
  1828. });
  1829. };
  1830. var registerEventsAndFilters = function (editor, pasteBin, pasteFormat) {
  1831. registerEventHandlers(editor, pasteBin, pasteFormat);
  1832. var src;
  1833. editor.parser.addNodeFilter('img', function (nodes, name, args) {
  1834. var isPasteInsert = function (args) {
  1835. return args.data && args.data.paste === true;
  1836. };
  1837. var remove = function (node) {
  1838. if (!node.attr('data-mce-object') && src !== global$2.transparentSrc) {
  1839. node.remove();
  1840. }
  1841. };
  1842. var isWebKitFakeUrl = function (src) {
  1843. return src.indexOf('webkit-fake-url') === 0;
  1844. };
  1845. var isDataUri = function (src) {
  1846. return src.indexOf('data:') === 0;
  1847. };
  1848. if (!editor.settings.paste_data_images && isPasteInsert(args)) {
  1849. var i = nodes.length;
  1850. while (i--) {
  1851. src = nodes[i].attributes.map.src;
  1852. if (!src) {
  1853. continue;
  1854. }
  1855. if (isWebKitFakeUrl(src)) {
  1856. remove(nodes[i]);
  1857. } else if (!editor.settings.allow_html_data_urls && isDataUri(src)) {
  1858. remove(nodes[i]);
  1859. }
  1860. }
  1861. }
  1862. });
  1863. };
  1864. var getPasteBinParent = function (editor) {
  1865. return global$2.ie && editor.inline ? domGlobals.document.body : editor.getBody();
  1866. };
  1867. var isExternalPasteBin = function (editor) {
  1868. return getPasteBinParent(editor) !== editor.getBody();
  1869. };
  1870. var delegatePasteEvents = function (editor, pasteBinElm, pasteBinDefaultContent) {
  1871. if (isExternalPasteBin(editor)) {
  1872. editor.dom.bind(pasteBinElm, 'paste keyup', function (e) {
  1873. if (!isDefault(editor, pasteBinDefaultContent)) {
  1874. editor.fire('paste');
  1875. }
  1876. });
  1877. }
  1878. };
  1879. var create = function (editor, lastRngCell, pasteBinDefaultContent) {
  1880. var dom = editor.dom, body = editor.getBody();
  1881. var pasteBinElm;
  1882. lastRngCell.set(editor.selection.getRng());
  1883. pasteBinElm = editor.dom.add(getPasteBinParent(editor), 'div', {
  1884. 'id': 'mcepastebin',
  1885. 'class': 'mce-pastebin',
  1886. 'contentEditable': true,
  1887. 'data-mce-bogus': 'all',
  1888. 'style': 'position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0'
  1889. }, pasteBinDefaultContent);
  1890. if (global$2.ie || global$2.gecko) {
  1891. dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) === 'rtl' ? 65535 : -65535);
  1892. }
  1893. dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function (e) {
  1894. e.stopPropagation();
  1895. });
  1896. delegatePasteEvents(editor, pasteBinElm, pasteBinDefaultContent);
  1897. pasteBinElm.focus();
  1898. editor.selection.select(pasteBinElm, true);
  1899. };
  1900. var remove = function (editor, lastRngCell) {
  1901. if (getEl(editor)) {
  1902. var pasteBinClone = void 0;
  1903. var lastRng = lastRngCell.get();
  1904. while (pasteBinClone = editor.dom.get('mcepastebin')) {
  1905. editor.dom.remove(pasteBinClone);
  1906. editor.dom.unbind(pasteBinClone);
  1907. }
  1908. if (lastRng) {
  1909. editor.selection.setRng(lastRng);
  1910. }
  1911. }
  1912. lastRngCell.set(null);
  1913. };
  1914. var getEl = function (editor) {
  1915. return editor.dom.get('mcepastebin');
  1916. };
  1917. var getHtml = function (editor) {
  1918. var pasteBinElm, pasteBinClones, i, dirtyWrappers, cleanWrapper;
  1919. var copyAndRemove = function (toElm, fromElm) {
  1920. toElm.appendChild(fromElm);
  1921. editor.dom.remove(fromElm, true);
  1922. };
  1923. pasteBinClones = global$4.grep(getPasteBinParent(editor).childNodes, function (elm) {
  1924. return elm.id === 'mcepastebin';
  1925. });
  1926. pasteBinElm = pasteBinClones.shift();
  1927. global$4.each(pasteBinClones, function (pasteBinClone) {
  1928. copyAndRemove(pasteBinElm, pasteBinClone);
  1929. });
  1930. dirtyWrappers = editor.dom.select('div[id=mcepastebin]', pasteBinElm);
  1931. for (i = dirtyWrappers.length - 1; i >= 0; i--) {
  1932. cleanWrapper = editor.dom.create('div');
  1933. pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
  1934. copyAndRemove(cleanWrapper, dirtyWrappers[i]);
  1935. }
  1936. return pasteBinElm ? pasteBinElm.innerHTML : '';
  1937. };
  1938. var getLastRng = function (lastRng) {
  1939. return lastRng.get();
  1940. };
  1941. var isDefaultContent = function (pasteBinDefaultContent, content) {
  1942. return content === pasteBinDefaultContent;
  1943. };
  1944. var isPasteBin = function (elm) {
  1945. return elm && elm.id === 'mcepastebin';
  1946. };
  1947. var isDefault = function (editor, pasteBinDefaultContent) {
  1948. var pasteBinElm = getEl(editor);
  1949. return isPasteBin(pasteBinElm) && isDefaultContent(pasteBinDefaultContent, pasteBinElm.innerHTML);
  1950. };
  1951. var PasteBin = function (editor) {
  1952. var lastRng = Cell(null);
  1953. var pasteBinDefaultContent = '%MCEPASTEBIN%';
  1954. return {
  1955. create: function () {
  1956. return create(editor, lastRng, pasteBinDefaultContent);
  1957. },
  1958. remove: function () {
  1959. return remove(editor, lastRng);
  1960. },
  1961. getEl: function () {
  1962. return getEl(editor);
  1963. },
  1964. getHtml: function () {
  1965. return getHtml(editor);
  1966. },
  1967. getLastRng: function () {
  1968. return getLastRng(lastRng);
  1969. },
  1970. isDefault: function () {
  1971. return isDefault(editor, pasteBinDefaultContent);
  1972. },
  1973. isDefaultContent: function (content) {
  1974. return isDefaultContent(pasteBinDefaultContent, content);
  1975. }
  1976. };
  1977. };
  1978. var Clipboard = function (editor, pasteFormat) {
  1979. var pasteBin = PasteBin(editor);
  1980. editor.on('preInit', function () {
  1981. return registerEventsAndFilters(editor, pasteBin, pasteFormat);
  1982. });
  1983. return {
  1984. pasteFormat: pasteFormat,
  1985. pasteHtml: function (html, internalFlag) {
  1986. return pasteHtml$1(editor, html, internalFlag);
  1987. },
  1988. pasteText: function (text) {
  1989. return pasteText(editor, text);
  1990. },
  1991. pasteImageData: function (e, rng) {
  1992. return pasteImageData(editor, e, rng);
  1993. },
  1994. getDataTransferItems: getDataTransferItems,
  1995. hasHtmlOrText: hasHtmlOrText,
  1996. hasContentType: hasContentType
  1997. };
  1998. };
  1999. var noop$1 = function () {
  2000. };
  2001. var hasWorkingClipboardApi = function (clipboardData) {
  2002. return global$2.iOS === false && clipboardData !== undefined && typeof clipboardData.setData === 'function' && Utils.isMsEdge() !== true;
  2003. };
  2004. var setHtml5Clipboard = function (clipboardData, html, text) {
  2005. if (hasWorkingClipboardApi(clipboardData)) {
  2006. try {
  2007. clipboardData.clearData();
  2008. clipboardData.setData('text/html', html);
  2009. clipboardData.setData('text/plain', text);
  2010. clipboardData.setData(InternalHtml.internalHtmlMime(), html);
  2011. return true;
  2012. } catch (e) {
  2013. return false;
  2014. }
  2015. } else {
  2016. return false;
  2017. }
  2018. };
  2019. var setClipboardData = function (evt, data, fallback, done) {
  2020. if (setHtml5Clipboard(evt.clipboardData, data.html, data.text)) {
  2021. evt.preventDefault();
  2022. done();
  2023. } else {
  2024. fallback(data.html, done);
  2025. }
  2026. };
  2027. var fallback = function (editor) {
  2028. return function (html, done) {
  2029. var markedHtml = InternalHtml.mark(html);
  2030. var outer = editor.dom.create('div', {
  2031. 'contenteditable': 'false',
  2032. 'data-mce-bogus': 'all'
  2033. });
  2034. var inner = editor.dom.create('div', { contenteditable: 'true' }, markedHtml);
  2035. editor.dom.setStyles(outer, {
  2036. position: 'fixed',
  2037. top: '0',
  2038. left: '-3000px',
  2039. width: '1000px',
  2040. overflow: 'hidden'
  2041. });
  2042. outer.appendChild(inner);
  2043. editor.dom.add(editor.getBody(), outer);
  2044. var range = editor.selection.getRng();
  2045. inner.focus();
  2046. var offscreenRange = editor.dom.createRng();
  2047. offscreenRange.selectNodeContents(inner);
  2048. editor.selection.setRng(offscreenRange);
  2049. setTimeout(function () {
  2050. editor.selection.setRng(range);
  2051. outer.parentNode.removeChild(outer);
  2052. done();
  2053. }, 0);
  2054. };
  2055. };
  2056. var getData = function (editor) {
  2057. return {
  2058. html: editor.selection.getContent({ contextual: true }),
  2059. text: editor.selection.getContent({ format: 'text' })
  2060. };
  2061. };
  2062. var isTableSelection = function (editor) {
  2063. return !!editor.dom.getParent(editor.selection.getStart(), 'td[data-mce-selected],th[data-mce-selected]', editor.getBody());
  2064. };
  2065. var hasSelectedContent = function (editor) {
  2066. return !editor.selection.isCollapsed() || isTableSelection(editor);
  2067. };
  2068. var cut = function (editor) {
  2069. return function (evt) {
  2070. if (hasSelectedContent(editor)) {
  2071. setClipboardData(evt, getData(editor), fallback(editor), function () {
  2072. setTimeout(function () {
  2073. editor.execCommand('Delete');
  2074. }, 0);
  2075. });
  2076. }
  2077. };
  2078. };
  2079. var copy = function (editor) {
  2080. return function (evt) {
  2081. if (hasSelectedContent(editor)) {
  2082. setClipboardData(evt, getData(editor), fallback(editor), noop$1);
  2083. }
  2084. };
  2085. };
  2086. var register$1 = function (editor) {
  2087. editor.on('cut', cut(editor));
  2088. editor.on('copy', copy(editor));
  2089. };
  2090. var CutCopy = { register: register$1 };
  2091. var global$b = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');
  2092. var getCaretRangeFromEvent = function (editor, e) {
  2093. return global$b.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
  2094. };
  2095. var isPlainTextFileUrl = function (content) {
  2096. var plainTextContent = content['text/plain'];
  2097. return plainTextContent ? plainTextContent.indexOf('file://') === 0 : false;
  2098. };
  2099. var setFocusedRange = function (editor, rng) {
  2100. editor.focus();
  2101. editor.selection.setRng(rng);
  2102. };
  2103. var setup = function (editor, clipboard, draggingInternallyState) {
  2104. if (Settings.shouldBlockDrop(editor)) {
  2105. editor.on('dragend dragover draggesture dragdrop drop drag', function (e) {
  2106. e.preventDefault();
  2107. e.stopPropagation();
  2108. });
  2109. }
  2110. if (!Settings.shouldPasteDataImages(editor)) {
  2111. editor.on('drop', function (e) {
  2112. var dataTransfer = e.dataTransfer;
  2113. if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
  2114. e.preventDefault();
  2115. }
  2116. });
  2117. }
  2118. editor.on('drop', function (e) {
  2119. var dropContent, rng;
  2120. rng = getCaretRangeFromEvent(editor, e);
  2121. if (e.isDefaultPrevented() || draggingInternallyState.get()) {
  2122. return;
  2123. }
  2124. dropContent = clipboard.getDataTransferItems(e.dataTransfer);
  2125. var internal = clipboard.hasContentType(dropContent, InternalHtml.internalHtmlMime());
  2126. if ((!clipboard.hasHtmlOrText(dropContent) || isPlainTextFileUrl(dropContent)) && clipboard.pasteImageData(e, rng)) {
  2127. return;
  2128. }
  2129. if (rng && Settings.shouldFilterDrop(editor)) {
  2130. var content_1 = dropContent['mce-internal'] || dropContent['text/html'] || dropContent['text/plain'];
  2131. if (content_1) {
  2132. e.preventDefault();
  2133. global$3.setEditorTimeout(editor, function () {
  2134. editor.undoManager.transact(function () {
  2135. if (dropContent['mce-internal']) {
  2136. editor.execCommand('Delete');
  2137. }
  2138. setFocusedRange(editor, rng);
  2139. content_1 = Utils.trimHtml(content_1);
  2140. if (!dropContent['text/html']) {
  2141. clipboard.pasteText(content_1);
  2142. } else {
  2143. clipboard.pasteHtml(content_1, internal);
  2144. }
  2145. });
  2146. });
  2147. }
  2148. }
  2149. });
  2150. editor.on('dragstart', function (e) {
  2151. draggingInternallyState.set(true);
  2152. });
  2153. editor.on('dragover dragend', function (e) {
  2154. if (Settings.shouldPasteDataImages(editor) && draggingInternallyState.get() === false) {
  2155. e.preventDefault();
  2156. setFocusedRange(editor, getCaretRangeFromEvent(editor, e));
  2157. }
  2158. if (e.type === 'dragend') {
  2159. draggingInternallyState.set(false);
  2160. }
  2161. });
  2162. };
  2163. var DragDrop = { setup: setup };
  2164. var setup$1 = function (editor) {
  2165. var plugin = editor.plugins.paste;
  2166. var preProcess = Settings.getPreProcess(editor);
  2167. if (preProcess) {
  2168. editor.on('PastePreProcess', function (e) {
  2169. preProcess.call(plugin, plugin, e);
  2170. });
  2171. }
  2172. var postProcess = Settings.getPostProcess(editor);
  2173. if (postProcess) {
  2174. editor.on('PastePostProcess', function (e) {
  2175. postProcess.call(plugin, plugin, e);
  2176. });
  2177. }
  2178. };
  2179. var PrePostProcess = { setup: setup$1 };
  2180. function addPreProcessFilter(editor, filterFunc) {
  2181. editor.on('PastePreProcess', function (e) {
  2182. e.content = filterFunc(editor, e.content, e.internal, e.wordContent);
  2183. });
  2184. }
  2185. function addPostProcessFilter(editor, filterFunc) {
  2186. editor.on('PastePostProcess', function (e) {
  2187. filterFunc(editor, e.node);
  2188. });
  2189. }
  2190. function removeExplorerBrElementsAfterBlocks(editor, html) {
  2191. if (!WordFilter.isWordContent(html)) {
  2192. return html;
  2193. }
  2194. var blockElements = [];
  2195. global$4.each(editor.schema.getBlockElements(), function (block, blockName) {
  2196. blockElements.push(blockName);
  2197. });
  2198. var explorerBlocksRegExp = new RegExp('(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?(' + blockElements.join('|') + ')[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*', 'g');
  2199. html = Utils.filter(html, [[
  2200. explorerBlocksRegExp,
  2201. '$1'
  2202. ]]);
  2203. html = Utils.filter(html, [
  2204. [
  2205. /<br><br>/g,
  2206. '<BR><BR>'
  2207. ],
  2208. [
  2209. /<br>/g,
  2210. ' '
  2211. ],
  2212. [
  2213. /<BR><BR>/g,
  2214. '<br>'
  2215. ]
  2216. ]);
  2217. return html;
  2218. }
  2219. function removeWebKitStyles(editor, content, internal, isWordHtml) {
  2220. if (isWordHtml || internal) {
  2221. return content;
  2222. }
  2223. var webKitStylesSetting = Settings.getWebkitStyles(editor);
  2224. var webKitStyles;
  2225. if (Settings.shouldRemoveWebKitStyles(editor) === false || webKitStylesSetting === 'all') {
  2226. return content;
  2227. }
  2228. if (webKitStylesSetting) {
  2229. webKitStyles = webKitStylesSetting.split(/[, ]/);
  2230. }
  2231. if (webKitStyles) {
  2232. var dom_1 = editor.dom, node_1 = editor.selection.getNode();
  2233. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, function (all, before, value, after) {
  2234. var inputStyles = dom_1.parseStyle(dom_1.decode(value));
  2235. var outputStyles = {};
  2236. if (webKitStyles === 'none') {
  2237. return before + after;
  2238. }
  2239. for (var i = 0; i < webKitStyles.length; i++) {
  2240. var inputValue = inputStyles[webKitStyles[i]], currentValue = dom_1.getStyle(node_1, webKitStyles[i], true);
  2241. if (/color/.test(webKitStyles[i])) {
  2242. inputValue = dom_1.toHex(inputValue);
  2243. currentValue = dom_1.toHex(currentValue);
  2244. }
  2245. if (currentValue !== inputValue) {
  2246. outputStyles[webKitStyles[i]] = inputValue;
  2247. }
  2248. }
  2249. outputStyles = dom_1.serializeStyle(outputStyles, 'span');
  2250. if (outputStyles) {
  2251. return before + ' style="' + outputStyles + '"' + after;
  2252. }
  2253. return before + after;
  2254. });
  2255. } else {
  2256. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, '$1$3');
  2257. }
  2258. content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, function (all, before, value, after) {
  2259. return before + ' style="' + value + '"' + after;
  2260. });
  2261. return content;
  2262. }
  2263. function removeUnderlineAndFontInAnchor(editor, root) {
  2264. editor.$('a', root).find('font,u').each(function (i, node) {
  2265. editor.dom.remove(node, true);
  2266. });
  2267. }
  2268. var setup$2 = function (editor) {
  2269. if (global$2.webkit) {
  2270. addPreProcessFilter(editor, removeWebKitStyles);
  2271. }
  2272. if (global$2.ie) {
  2273. addPreProcessFilter(editor, removeExplorerBrElementsAfterBlocks);
  2274. addPostProcessFilter(editor, removeUnderlineAndFontInAnchor);
  2275. }
  2276. };
  2277. var Quirks = { setup: setup$2 };
  2278. var stateChange = function (editor, clipboard, e) {
  2279. var ctrl = e.control;
  2280. ctrl.active(clipboard.pasteFormat.get() === 'text');
  2281. editor.on('PastePlainTextToggle', function (e) {
  2282. ctrl.active(e.state);
  2283. });
  2284. };
  2285. var register$2 = function (editor, clipboard) {
  2286. var postRender = curry(stateChange, editor, clipboard);
  2287. editor.addButton('pastetext', {
  2288. active: false,
  2289. icon: 'pastetext',
  2290. tooltip: 'Paste as text',
  2291. cmd: 'mceTogglePlainTextPaste',
  2292. onPostRender: postRender
  2293. });
  2294. editor.addMenuItem('pastetext', {
  2295. text: 'Paste as text',
  2296. selectable: true,
  2297. active: clipboard.pasteFormat,
  2298. cmd: 'mceTogglePlainTextPaste',
  2299. onPostRender: postRender
  2300. });
  2301. };
  2302. var Buttons = { register: register$2 };
  2303. global$1.add('paste', function (editor) {
  2304. if (DetectProPlugin.hasProPlugin(editor) === false) {
  2305. var userIsInformedState = Cell(false);
  2306. var draggingInternallyState = Cell(false);
  2307. var pasteFormat = Cell(Settings.isPasteAsTextEnabled(editor) ? 'text' : 'html');
  2308. var clipboard = Clipboard(editor, pasteFormat);
  2309. var quirks = Quirks.setup(editor);
  2310. Buttons.register(editor, clipboard);
  2311. Commands.register(editor, clipboard, userIsInformedState);
  2312. PrePostProcess.setup(editor);
  2313. CutCopy.register(editor);
  2314. DragDrop.setup(editor, clipboard, draggingInternallyState);
  2315. return Api.get(clipboard, quirks);
  2316. }
  2317. });
  2318. function Plugin () {
  2319. }
  2320. return Plugin;
  2321. }(window));
  2322. })();