plugin.js 81 KB

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