plugin.js 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400
  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.2.0 (2020-02-13)
  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.Serializer');
  999. var global$9 = tinymce.util.Tools.resolve('tinymce.html.Node');
  1000. var global$a = tinymce.util.Tools.resolve('tinymce.html.Schema');
  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. var nbsp = '\xA0';
  1061. function filter$1(content, items) {
  1062. global$4.each(items, function (v) {
  1063. if (v.constructor === RegExp) {
  1064. content = content.replace(v, '');
  1065. } else {
  1066. content = content.replace(v[0], v[1]);
  1067. }
  1068. });
  1069. return content;
  1070. }
  1071. function innerText(html) {
  1072. var schema = global$a();
  1073. var domParser = global$7({}, schema);
  1074. var text = '';
  1075. var shortEndedElements = schema.getShortEndedElements();
  1076. var ignoreElements = global$4.makeMap('script noscript style textarea video audio iframe object', ' ');
  1077. var blockElements = schema.getBlockElements();
  1078. function walk(node) {
  1079. var name = node.name, currentNode = node;
  1080. if (name === 'br') {
  1081. text += '\n';
  1082. return;
  1083. }
  1084. if (name === 'wbr') {
  1085. return;
  1086. }
  1087. if (shortEndedElements[name]) {
  1088. text += ' ';
  1089. }
  1090. if (ignoreElements[name]) {
  1091. text += ' ';
  1092. return;
  1093. }
  1094. if (node.type === 3) {
  1095. text += node.value;
  1096. }
  1097. if (!node.shortEnded) {
  1098. if (node = node.firstChild) {
  1099. do {
  1100. walk(node);
  1101. } while (node = node.next);
  1102. }
  1103. }
  1104. if (blockElements[name] && currentNode.next) {
  1105. text += '\n';
  1106. if (name === 'p') {
  1107. text += '\n';
  1108. }
  1109. }
  1110. }
  1111. html = filter$1(html, [/<!\[[^\]]+\]>/g]);
  1112. walk(domParser.parse(html));
  1113. return text;
  1114. }
  1115. function trimHtml(html) {
  1116. function trimSpaces(all, s1, s2) {
  1117. if (!s1 && !s2) {
  1118. return ' ';
  1119. }
  1120. return nbsp;
  1121. }
  1122. html = filter$1(html, [
  1123. /^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig,
  1124. /<!--StartFragment-->|<!--EndFragment-->/g,
  1125. [
  1126. /( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g,
  1127. trimSpaces
  1128. ],
  1129. /<br class="Apple-interchange-newline">/g,
  1130. /<br>$/i
  1131. ]);
  1132. return html;
  1133. }
  1134. function createIdGenerator(prefix) {
  1135. var count = 0;
  1136. return function () {
  1137. return prefix + count++;
  1138. };
  1139. }
  1140. var isMsEdge = function () {
  1141. return domGlobals.navigator.userAgent.indexOf(' Edge/') !== -1;
  1142. };
  1143. var Utils = {
  1144. filter: filter$1,
  1145. innerText: innerText,
  1146. trimHtml: trimHtml,
  1147. createIdGenerator: createIdGenerator,
  1148. isMsEdge: isMsEdge
  1149. };
  1150. function isWordContent(content) {
  1151. 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);
  1152. }
  1153. function isNumericList(text) {
  1154. var found, patterns;
  1155. patterns = [
  1156. /^[IVXLMCD]{1,2}\.[ \u00a0]/,
  1157. /^[ivxlmcd]{1,2}\.[ \u00a0]/,
  1158. /^[a-z]{1,2}[\.\)][ \u00a0]/,
  1159. /^[A-Z]{1,2}[\.\)][ \u00a0]/,
  1160. /^[0-9]+\.[ \u00a0]/,
  1161. /^[\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+\.[ \u00a0]/,
  1162. /^[\u58f1\u5f10\u53c2\u56db\u4f0d\u516d\u4e03\u516b\u4e5d\u62fe]+\.[ \u00a0]/
  1163. ];
  1164. text = text.replace(/^[\u00a0 ]+/, '');
  1165. global$4.each(patterns, function (pattern) {
  1166. if (pattern.test(text)) {
  1167. found = true;
  1168. return false;
  1169. }
  1170. });
  1171. return found;
  1172. }
  1173. function isBulletList(text) {
  1174. return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
  1175. }
  1176. function convertFakeListsToProperLists(node) {
  1177. var currentListNode, prevListNode, lastLevel = 1;
  1178. function getText(node) {
  1179. var txt = '';
  1180. if (node.type === 3) {
  1181. return node.value;
  1182. }
  1183. if (node = node.firstChild) {
  1184. do {
  1185. txt += getText(node);
  1186. } while (node = node.next);
  1187. }
  1188. return txt;
  1189. }
  1190. function trimListStart(node, regExp) {
  1191. if (node.type === 3) {
  1192. if (regExp.test(node.value)) {
  1193. node.value = node.value.replace(regExp, '');
  1194. return false;
  1195. }
  1196. }
  1197. if (node = node.firstChild) {
  1198. do {
  1199. if (!trimListStart(node, regExp)) {
  1200. return false;
  1201. }
  1202. } while (node = node.next);
  1203. }
  1204. return true;
  1205. }
  1206. function removeIgnoredNodes(node) {
  1207. if (node._listIgnore) {
  1208. node.remove();
  1209. return;
  1210. }
  1211. if (node = node.firstChild) {
  1212. do {
  1213. removeIgnoredNodes(node);
  1214. } while (node = node.next);
  1215. }
  1216. }
  1217. function convertParagraphToLi(paragraphNode, listName, start) {
  1218. var level = paragraphNode._listLevel || lastLevel;
  1219. if (level !== lastLevel) {
  1220. if (level < lastLevel) {
  1221. if (currentListNode) {
  1222. currentListNode = currentListNode.parent.parent;
  1223. }
  1224. } else {
  1225. prevListNode = currentListNode;
  1226. currentListNode = null;
  1227. }
  1228. }
  1229. if (!currentListNode || currentListNode.name !== listName) {
  1230. prevListNode = prevListNode || currentListNode;
  1231. currentListNode = new global$9(listName, 1);
  1232. if (start > 1) {
  1233. currentListNode.attr('start', '' + start);
  1234. }
  1235. paragraphNode.wrap(currentListNode);
  1236. } else {
  1237. currentListNode.append(paragraphNode);
  1238. }
  1239. paragraphNode.name = 'li';
  1240. if (level > lastLevel && prevListNode) {
  1241. prevListNode.lastChild.append(currentListNode);
  1242. }
  1243. lastLevel = level;
  1244. removeIgnoredNodes(paragraphNode);
  1245. trimListStart(paragraphNode, /^\u00a0+/);
  1246. trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
  1247. trimListStart(paragraphNode, /^\u00a0+/);
  1248. }
  1249. var elements = [];
  1250. var child = node.firstChild;
  1251. while (typeof child !== 'undefined' && child !== null) {
  1252. elements.push(child);
  1253. child = child.walk();
  1254. if (child !== null) {
  1255. while (typeof child !== 'undefined' && child.parent !== node) {
  1256. child = child.walk();
  1257. }
  1258. }
  1259. }
  1260. for (var i = 0; i < elements.length; i++) {
  1261. node = elements[i];
  1262. if (node.name === 'p' && node.firstChild) {
  1263. var nodeText = getText(node);
  1264. if (isBulletList(nodeText)) {
  1265. convertParagraphToLi(node, 'ul');
  1266. continue;
  1267. }
  1268. if (isNumericList(nodeText)) {
  1269. var matches = /([0-9]+)\./.exec(nodeText);
  1270. var start = 1;
  1271. if (matches) {
  1272. start = parseInt(matches[1], 10);
  1273. }
  1274. convertParagraphToLi(node, 'ol', start);
  1275. continue;
  1276. }
  1277. if (node._listLevel) {
  1278. convertParagraphToLi(node, 'ul', 1);
  1279. continue;
  1280. }
  1281. currentListNode = null;
  1282. } else {
  1283. prevListNode = currentListNode;
  1284. currentListNode = null;
  1285. }
  1286. }
  1287. }
  1288. function filterStyles(editor, validStyles, node, styleValue) {
  1289. var outputStyles = {}, matches;
  1290. var styles = editor.dom.parseStyle(styleValue);
  1291. global$4.each(styles, function (value, name) {
  1292. switch (name) {
  1293. case 'mso-list':
  1294. matches = /\w+ \w+([0-9]+)/i.exec(styleValue);
  1295. if (matches) {
  1296. node._listLevel = parseInt(matches[1], 10);
  1297. }
  1298. if (/Ignore/i.test(value) && node.firstChild) {
  1299. node._listIgnore = true;
  1300. node.firstChild._listIgnore = true;
  1301. }
  1302. break;
  1303. case 'horiz-align':
  1304. name = 'text-align';
  1305. break;
  1306. case 'vert-align':
  1307. name = 'vertical-align';
  1308. break;
  1309. case 'font-color':
  1310. case 'mso-foreground':
  1311. name = 'color';
  1312. break;
  1313. case 'mso-background':
  1314. case 'mso-highlight':
  1315. name = 'background';
  1316. break;
  1317. case 'font-weight':
  1318. case 'font-style':
  1319. if (value !== 'normal') {
  1320. outputStyles[name] = value;
  1321. }
  1322. return;
  1323. case 'mso-element':
  1324. if (/^(comment|comment-list)$/i.test(value)) {
  1325. node.remove();
  1326. return;
  1327. }
  1328. break;
  1329. }
  1330. if (name.indexOf('mso-comment') === 0) {
  1331. node.remove();
  1332. return;
  1333. }
  1334. if (name.indexOf('mso-') === 0) {
  1335. return;
  1336. }
  1337. if (Settings.getRetainStyleProps(editor) === 'all' || validStyles && validStyles[name]) {
  1338. outputStyles[name] = value;
  1339. }
  1340. });
  1341. if (/(bold)/i.test(outputStyles['font-weight'])) {
  1342. delete outputStyles['font-weight'];
  1343. node.wrap(new global$9('b', 1));
  1344. }
  1345. if (/(italic)/i.test(outputStyles['font-style'])) {
  1346. delete outputStyles['font-style'];
  1347. node.wrap(new global$9('i', 1));
  1348. }
  1349. outputStyles = editor.dom.serializeStyle(outputStyles, node.name);
  1350. if (outputStyles) {
  1351. return outputStyles;
  1352. }
  1353. return null;
  1354. }
  1355. var filterWordContent = function (editor, content) {
  1356. var retainStyleProperties, validStyles;
  1357. retainStyleProperties = Settings.getRetainStyleProps(editor);
  1358. if (retainStyleProperties) {
  1359. validStyles = global$4.makeMap(retainStyleProperties.split(/[, ]/));
  1360. }
  1361. content = Utils.filter(content, [
  1362. /<br class="?Apple-interchange-newline"?>/gi,
  1363. /<b[^>]+id="?docs-internal-[^>]*>/gi,
  1364. /<!--[\s\S]+?-->/gi,
  1365. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
  1366. [
  1367. /<(\/?)s>/gi,
  1368. '<$1strike>'
  1369. ],
  1370. [
  1371. /&nbsp;/gi,
  1372. nbsp
  1373. ],
  1374. [
  1375. /<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
  1376. function (str, spaces) {
  1377. return spaces.length > 0 ? spaces.replace(/./, ' ').slice(Math.floor(spaces.length / 2)).split('').join(nbsp) : '';
  1378. }
  1379. ]
  1380. ]);
  1381. var validElements = Settings.getWordValidElements(editor);
  1382. var schema = global$a({
  1383. valid_elements: validElements,
  1384. valid_children: '-li[p]'
  1385. });
  1386. global$4.each(schema.elements, function (rule) {
  1387. if (!rule.attributes.class) {
  1388. rule.attributes.class = {};
  1389. rule.attributesOrder.push('class');
  1390. }
  1391. if (!rule.attributes.style) {
  1392. rule.attributes.style = {};
  1393. rule.attributesOrder.push('style');
  1394. }
  1395. });
  1396. var domParser = global$7({}, schema);
  1397. domParser.addAttributeFilter('style', function (nodes) {
  1398. var i = nodes.length, node;
  1399. while (i--) {
  1400. node = nodes[i];
  1401. node.attr('style', filterStyles(editor, validStyles, node, node.attr('style')));
  1402. if (node.name === 'span' && node.parent && !node.attributes.length) {
  1403. node.unwrap();
  1404. }
  1405. }
  1406. });
  1407. domParser.addAttributeFilter('class', function (nodes) {
  1408. var i = nodes.length, node, className;
  1409. while (i--) {
  1410. node = nodes[i];
  1411. className = node.attr('class');
  1412. if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
  1413. node.remove();
  1414. }
  1415. node.attr('class', null);
  1416. }
  1417. });
  1418. domParser.addNodeFilter('del', function (nodes) {
  1419. var i = nodes.length;
  1420. while (i--) {
  1421. nodes[i].remove();
  1422. }
  1423. });
  1424. domParser.addNodeFilter('a', function (nodes) {
  1425. var i = nodes.length, node, href, name;
  1426. while (i--) {
  1427. node = nodes[i];
  1428. href = node.attr('href');
  1429. name = node.attr('name');
  1430. if (href && href.indexOf('#_msocom_') !== -1) {
  1431. node.remove();
  1432. continue;
  1433. }
  1434. if (href && href.indexOf('file://') === 0) {
  1435. href = href.split('#')[1];
  1436. if (href) {
  1437. href = '#' + href;
  1438. }
  1439. }
  1440. if (!href && !name) {
  1441. node.unwrap();
  1442. } else {
  1443. if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) {
  1444. node.unwrap();
  1445. continue;
  1446. }
  1447. node.attr({
  1448. href: href,
  1449. name: name
  1450. });
  1451. }
  1452. }
  1453. });
  1454. var rootNode = domParser.parse(content);
  1455. if (Settings.shouldConvertWordFakeLists(editor)) {
  1456. convertFakeListsToProperLists(rootNode);
  1457. }
  1458. content = global$8({ validate: editor.settings.validate }, schema).serialize(rootNode);
  1459. return content;
  1460. };
  1461. var preProcess = function (editor, content) {
  1462. return Settings.shouldUseDefaultFilters(editor) ? filterWordContent(editor, content) : content;
  1463. };
  1464. var WordFilter = {
  1465. preProcess: preProcess,
  1466. isWordContent: isWordContent
  1467. };
  1468. var preProcess$1 = function (editor, html) {
  1469. var parser = global$7({}, editor.schema);
  1470. parser.addNodeFilter('meta', function (nodes) {
  1471. global$4.each(nodes, function (node) {
  1472. return node.remove();
  1473. });
  1474. });
  1475. var fragment = parser.parse(html, {
  1476. forced_root_block: false,
  1477. isRootContent: true
  1478. });
  1479. return global$8({ validate: editor.settings.validate }, editor.schema).serialize(fragment);
  1480. };
  1481. var processResult = function (content, cancelled) {
  1482. return {
  1483. content: content,
  1484. cancelled: cancelled
  1485. };
  1486. };
  1487. var postProcessFilter = function (editor, html, internal, isWordHtml) {
  1488. var tempBody = editor.dom.create('div', { style: 'display:none' }, html);
  1489. var postProcessArgs = Events.firePastePostProcess(editor, tempBody, internal, isWordHtml);
  1490. return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented());
  1491. };
  1492. var filterContent = function (editor, content, internal, isWordHtml) {
  1493. var preProcessArgs = Events.firePastePreProcess(editor, content, internal, isWordHtml);
  1494. var filteredContent = preProcess$1(editor, preProcessArgs.content);
  1495. if (editor.hasEventListeners('PastePostProcess') && !preProcessArgs.isDefaultPrevented()) {
  1496. return postProcessFilter(editor, filteredContent, internal, isWordHtml);
  1497. } else {
  1498. return processResult(filteredContent, preProcessArgs.isDefaultPrevented());
  1499. }
  1500. };
  1501. var process = function (editor, html, internal) {
  1502. var isWordHtml = WordFilter.isWordContent(html);
  1503. var content = isWordHtml ? WordFilter.preProcess(editor, html) : html;
  1504. return filterContent(editor, content, internal, isWordHtml);
  1505. };
  1506. var ProcessFilters = { process: process };
  1507. var pasteHtml = function (editor, html) {
  1508. editor.insertContent(html, {
  1509. merge: Settings.shouldMergeFormats(editor),
  1510. paste: true
  1511. });
  1512. return true;
  1513. };
  1514. var isAbsoluteUrl = function (url) {
  1515. return /^https?:\/\/[\w\?\-\/+=.&%@~#]+$/i.test(url);
  1516. };
  1517. var isImageUrl = function (url) {
  1518. return isAbsoluteUrl(url) && /.(gif|jpe?g|png)$/.test(url);
  1519. };
  1520. var createImage = function (editor, url, pasteHtmlFn) {
  1521. editor.undoManager.extra(function () {
  1522. pasteHtmlFn(editor, url);
  1523. }, function () {
  1524. editor.insertContent('<img src="' + url + '">');
  1525. });
  1526. return true;
  1527. };
  1528. var createLink = function (editor, url, pasteHtmlFn) {
  1529. editor.undoManager.extra(function () {
  1530. pasteHtmlFn(editor, url);
  1531. }, function () {
  1532. editor.execCommand('mceInsertLink', false, url);
  1533. });
  1534. return true;
  1535. };
  1536. var linkSelection = function (editor, html, pasteHtmlFn) {
  1537. return editor.selection.isCollapsed() === false && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtmlFn) : false;
  1538. };
  1539. var insertImage = function (editor, html, pasteHtmlFn) {
  1540. return isImageUrl(html) ? createImage(editor, html, pasteHtmlFn) : false;
  1541. };
  1542. var smartInsertContent = function (editor, html) {
  1543. global$4.each([
  1544. linkSelection,
  1545. insertImage,
  1546. pasteHtml
  1547. ], function (action) {
  1548. return action(editor, html, pasteHtml) !== true;
  1549. });
  1550. };
  1551. var insertContent = function (editor, html, pasteAsText) {
  1552. if (pasteAsText || Settings.isSmartPasteEnabled(editor) === false) {
  1553. pasteHtml(editor, html);
  1554. } else {
  1555. smartInsertContent(editor, html);
  1556. }
  1557. };
  1558. var SmartPaste = {
  1559. isImageUrl: isImageUrl,
  1560. isAbsoluteUrl: isAbsoluteUrl,
  1561. insertContent: insertContent
  1562. };
  1563. var isCollapsibleWhitespace = function (c) {
  1564. return ' \f\t\x0B'.indexOf(c) !== -1;
  1565. };
  1566. var isNewLineChar = function (c) {
  1567. return c === '\n' || c === '\r';
  1568. };
  1569. var isNewline = function (text, idx) {
  1570. return idx < text.length && idx >= 0 ? isNewLineChar(text[idx]) : false;
  1571. };
  1572. var normalizeWhitespace = function (text) {
  1573. var result = foldl(text, function (acc, c) {
  1574. if (isCollapsibleWhitespace(c) || c === nbsp) {
  1575. if (acc.pcIsSpace || acc.str === '' || acc.str.length === text.length - 1 || isNewline(text, acc.str.length + 1)) {
  1576. return {
  1577. pcIsSpace: false,
  1578. str: acc.str + nbsp
  1579. };
  1580. } else {
  1581. return {
  1582. pcIsSpace: true,
  1583. str: acc.str + ' '
  1584. };
  1585. }
  1586. } else {
  1587. return {
  1588. pcIsSpace: isNewLineChar(c),
  1589. str: acc.str + c
  1590. };
  1591. }
  1592. }, {
  1593. pcIsSpace: false,
  1594. str: ''
  1595. });
  1596. return result.str;
  1597. };
  1598. var doPaste = function (editor, content, internal, pasteAsText) {
  1599. var args = ProcessFilters.process(editor, content, internal);
  1600. if (args.cancelled === false) {
  1601. SmartPaste.insertContent(editor, args.content, pasteAsText);
  1602. }
  1603. };
  1604. var pasteHtml$1 = function (editor, html, internalFlag) {
  1605. var internal = internalFlag ? internalFlag : InternalHtml.isMarked(html);
  1606. doPaste(editor, InternalHtml.unmark(html), internal, false);
  1607. };
  1608. var pasteText = function (editor, text) {
  1609. var encodedText = editor.dom.encode(text).replace(/\r\n/g, '\n');
  1610. var normalizedText = normalizeWhitespace(encodedText);
  1611. var html = Newlines.convert(normalizedText, editor.settings.forced_root_block, editor.settings.forced_root_block_attrs);
  1612. doPaste(editor, html, false, true);
  1613. };
  1614. var getDataTransferItems = function (dataTransfer) {
  1615. var items = {};
  1616. var mceInternalUrlPrefix = 'data:text/mce-internal,';
  1617. if (dataTransfer) {
  1618. if (dataTransfer.getData) {
  1619. var legacyText = dataTransfer.getData('Text');
  1620. if (legacyText && legacyText.length > 0) {
  1621. if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
  1622. items['text/plain'] = legacyText;
  1623. }
  1624. }
  1625. }
  1626. if (dataTransfer.types) {
  1627. for (var i = 0; i < dataTransfer.types.length; i++) {
  1628. var contentType = dataTransfer.types[i];
  1629. try {
  1630. items[contentType] = dataTransfer.getData(contentType);
  1631. } catch (ex) {
  1632. items[contentType] = '';
  1633. }
  1634. }
  1635. }
  1636. }
  1637. return items;
  1638. };
  1639. var getClipboardContent = function (editor, clipboardEvent) {
  1640. var content = getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
  1641. return Utils.isMsEdge() ? global$4.extend(content, { 'text/html': '' }) : content;
  1642. };
  1643. var hasContentType = function (clipboardContent, mimeType) {
  1644. return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
  1645. };
  1646. var hasHtmlOrText = function (content) {
  1647. return hasContentType(content, 'text/html') || hasContentType(content, 'text/plain');
  1648. };
  1649. var getBase64FromUri = function (uri) {
  1650. var idx;
  1651. idx = uri.indexOf(',');
  1652. if (idx !== -1) {
  1653. return uri.substr(idx + 1);
  1654. }
  1655. return null;
  1656. };
  1657. var isValidDataUriImage = function (settings, imgElm) {
  1658. return settings.images_dataimg_filter ? settings.images_dataimg_filter(imgElm) : true;
  1659. };
  1660. var extractFilename = function (editor, str) {
  1661. var m = str.match(/([\s\S]+?)\.(?:jpeg|jpg|png|gif)$/i);
  1662. return m ? editor.dom.encode(m[1]) : null;
  1663. };
  1664. var uniqueId = Utils.createIdGenerator('mceclip');
  1665. var pasteImage = function (editor, imageItem) {
  1666. var base64 = getBase64FromUri(imageItem.uri);
  1667. var id = uniqueId();
  1668. var name = editor.settings.images_reuse_filename && imageItem.blob.name ? extractFilename(editor, imageItem.blob.name) : id;
  1669. var img = new domGlobals.Image();
  1670. img.src = imageItem.uri;
  1671. if (isValidDataUriImage(editor.settings, img)) {
  1672. var blobCache = editor.editorUpload.blobCache;
  1673. var blobInfo = void 0, existingBlobInfo = void 0;
  1674. existingBlobInfo = blobCache.findFirst(function (cachedBlobInfo) {
  1675. return cachedBlobInfo.base64() === base64;
  1676. });
  1677. if (!existingBlobInfo) {
  1678. blobInfo = blobCache.create(id, imageItem.blob, base64, name);
  1679. blobCache.add(blobInfo);
  1680. } else {
  1681. blobInfo = existingBlobInfo;
  1682. }
  1683. pasteHtml$1(editor, '<img src="' + blobInfo.blobUri() + '">', false);
  1684. } else {
  1685. pasteHtml$1(editor, '<img src="' + imageItem.uri + '">', false);
  1686. }
  1687. };
  1688. var isClipboardEvent = function (event) {
  1689. return event.type === 'paste';
  1690. };
  1691. var readBlobsAsDataUris = function (items) {
  1692. return traverse(items, function (item) {
  1693. return Future.nu(function (resolve) {
  1694. var blob = item.getAsFile ? item.getAsFile() : item;
  1695. var reader = new window.FileReader();
  1696. reader.onload = function () {
  1697. resolve({
  1698. blob: blob,
  1699. uri: reader.result
  1700. });
  1701. };
  1702. reader.readAsDataURL(blob);
  1703. });
  1704. });
  1705. };
  1706. var getImagesFromDataTransfer = function (dataTransfer) {
  1707. var items = dataTransfer.items ? map(from$1(dataTransfer.items), function (item) {
  1708. return item.getAsFile();
  1709. }) : [];
  1710. var files = dataTransfer.files ? from$1(dataTransfer.files) : [];
  1711. var images = filter(items.length > 0 ? items : files, function (file) {
  1712. return /^image\/(jpeg|png|gif|bmp)$/.test(file.type);
  1713. });
  1714. return images;
  1715. };
  1716. var pasteImageData = function (editor, e, rng) {
  1717. var dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
  1718. if (editor.settings.paste_data_images && dataTransfer) {
  1719. var images = getImagesFromDataTransfer(dataTransfer);
  1720. if (images.length > 0) {
  1721. e.preventDefault();
  1722. readBlobsAsDataUris(images).get(function (blobResults) {
  1723. if (rng) {
  1724. editor.selection.setRng(rng);
  1725. }
  1726. each(blobResults, function (result) {
  1727. pasteImage(editor, result);
  1728. });
  1729. });
  1730. return true;
  1731. }
  1732. }
  1733. return false;
  1734. };
  1735. var isBrokenAndroidClipboardEvent = function (e) {
  1736. var clipboardData = e.clipboardData;
  1737. return domGlobals.navigator.userAgent.indexOf('Android') !== -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
  1738. };
  1739. var isKeyboardPasteEvent = function (e) {
  1740. return global$5.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
  1741. };
  1742. var registerEventHandlers = function (editor, pasteBin, pasteFormat) {
  1743. var keyboardPasteEvent = value();
  1744. var keyboardPastePlainTextState;
  1745. editor.on('keydown', function (e) {
  1746. function removePasteBinOnKeyUp(e) {
  1747. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  1748. pasteBin.remove();
  1749. }
  1750. }
  1751. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  1752. keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
  1753. if (keyboardPastePlainTextState && global$2.webkit && domGlobals.navigator.userAgent.indexOf('Version/') !== -1) {
  1754. return;
  1755. }
  1756. e.stopImmediatePropagation();
  1757. keyboardPasteEvent.set(e);
  1758. window.setTimeout(function () {
  1759. keyboardPasteEvent.clear();
  1760. }, 100);
  1761. if (global$2.ie && keyboardPastePlainTextState) {
  1762. e.preventDefault();
  1763. Events.firePaste(editor, true);
  1764. return;
  1765. }
  1766. pasteBin.remove();
  1767. pasteBin.create();
  1768. editor.once('keyup', removePasteBinOnKeyUp);
  1769. editor.once('paste', function () {
  1770. editor.off('keyup', removePasteBinOnKeyUp);
  1771. });
  1772. }
  1773. });
  1774. function insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal) {
  1775. var content, isPlainTextHtml, isImage;
  1776. if (hasContentType(clipboardContent, 'text/html')) {
  1777. content = clipboardContent['text/html'];
  1778. } else {
  1779. content = pasteBin.getHtml();
  1780. internal = internal ? internal : InternalHtml.isMarked(content);
  1781. if (pasteBin.isDefaultContent(content)) {
  1782. plainTextMode = true;
  1783. }
  1784. }
  1785. content = Utils.trimHtml(content);
  1786. pasteBin.remove();
  1787. isPlainTextHtml = internal === false && Newlines.isPlainText(content);
  1788. isImage = SmartPaste.isImageUrl(content);
  1789. if (!content.length || isPlainTextHtml && !isImage) {
  1790. plainTextMode = true;
  1791. }
  1792. if (plainTextMode || isImage) {
  1793. if (hasContentType(clipboardContent, 'text/plain') && isPlainTextHtml) {
  1794. content = clipboardContent['text/plain'];
  1795. } else {
  1796. content = Utils.innerText(content);
  1797. }
  1798. }
  1799. if (pasteBin.isDefaultContent(content)) {
  1800. if (!isKeyBoardPaste) {
  1801. editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
  1802. }
  1803. return;
  1804. }
  1805. if (plainTextMode) {
  1806. pasteText(editor, content);
  1807. } else {
  1808. pasteHtml$1(editor, content, internal);
  1809. }
  1810. }
  1811. var getLastRng = function () {
  1812. return pasteBin.getLastRng() || editor.selection.getRng();
  1813. };
  1814. editor.on('paste', function (e) {
  1815. var isKeyBoardPaste = keyboardPasteEvent.isSet();
  1816. var clipboardContent = getClipboardContent(editor, e);
  1817. var plainTextMode = pasteFormat.get() === 'text' || keyboardPastePlainTextState;
  1818. var internal = hasContentType(clipboardContent, InternalHtml.internalHtmlMime());
  1819. keyboardPastePlainTextState = false;
  1820. if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
  1821. pasteBin.remove();
  1822. return;
  1823. }
  1824. if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
  1825. pasteBin.remove();
  1826. return;
  1827. }
  1828. if (!isKeyBoardPaste) {
  1829. e.preventDefault();
  1830. }
  1831. if (global$2.ie && (!isKeyBoardPaste || e.ieFake) && !hasContentType(clipboardContent, 'text/html')) {
  1832. pasteBin.create();
  1833. editor.dom.bind(pasteBin.getEl(), 'paste', function (e) {
  1834. e.stopPropagation();
  1835. });
  1836. editor.getDoc().execCommand('Paste', false, null);
  1837. clipboardContent['text/html'] = pasteBin.getHtml();
  1838. }
  1839. if (hasContentType(clipboardContent, 'text/html')) {
  1840. e.preventDefault();
  1841. if (!internal) {
  1842. internal = InternalHtml.isMarked(clipboardContent['text/html']);
  1843. }
  1844. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  1845. } else {
  1846. global$3.setEditorTimeout(editor, function () {
  1847. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  1848. }, 0);
  1849. }
  1850. });
  1851. };
  1852. var registerEventsAndFilters = function (editor, pasteBin, pasteFormat) {
  1853. registerEventHandlers(editor, pasteBin, pasteFormat);
  1854. var src;
  1855. editor.parser.addNodeFilter('img', function (nodes, name, args) {
  1856. var isPasteInsert = function (args) {
  1857. return args.data && args.data.paste === true;
  1858. };
  1859. var remove = function (node) {
  1860. if (!node.attr('data-mce-object') && src !== global$2.transparentSrc) {
  1861. node.remove();
  1862. }
  1863. };
  1864. var isWebKitFakeUrl = function (src) {
  1865. return src.indexOf('webkit-fake-url') === 0;
  1866. };
  1867. var isDataUri = function (src) {
  1868. return src.indexOf('data:') === 0;
  1869. };
  1870. if (!editor.settings.paste_data_images && isPasteInsert(args)) {
  1871. var i = nodes.length;
  1872. while (i--) {
  1873. src = nodes[i].attr('src');
  1874. if (!src) {
  1875. continue;
  1876. }
  1877. if (isWebKitFakeUrl(src)) {
  1878. remove(nodes[i]);
  1879. } else if (!editor.settings.allow_html_data_urls && isDataUri(src)) {
  1880. remove(nodes[i]);
  1881. }
  1882. }
  1883. }
  1884. });
  1885. };
  1886. var getPasteBinParent = function (editor) {
  1887. return global$2.ie && editor.inline ? domGlobals.document.body : editor.getBody();
  1888. };
  1889. var isExternalPasteBin = function (editor) {
  1890. return getPasteBinParent(editor) !== editor.getBody();
  1891. };
  1892. var delegatePasteEvents = function (editor, pasteBinElm, pasteBinDefaultContent) {
  1893. if (isExternalPasteBin(editor)) {
  1894. editor.dom.bind(pasteBinElm, 'paste keyup', function (e) {
  1895. if (!isDefault(editor, pasteBinDefaultContent)) {
  1896. editor.fire('paste');
  1897. }
  1898. });
  1899. }
  1900. };
  1901. var create = function (editor, lastRngCell, pasteBinDefaultContent) {
  1902. var dom = editor.dom, body = editor.getBody();
  1903. var pasteBinElm;
  1904. lastRngCell.set(editor.selection.getRng());
  1905. pasteBinElm = editor.dom.add(getPasteBinParent(editor), 'div', {
  1906. 'id': 'mcepastebin',
  1907. 'class': 'mce-pastebin',
  1908. 'contentEditable': true,
  1909. 'data-mce-bogus': 'all',
  1910. 'style': 'position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0'
  1911. }, pasteBinDefaultContent);
  1912. if (global$2.ie || global$2.gecko) {
  1913. dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) === 'rtl' ? 65535 : -65535);
  1914. }
  1915. dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function (e) {
  1916. e.stopPropagation();
  1917. });
  1918. delegatePasteEvents(editor, pasteBinElm, pasteBinDefaultContent);
  1919. pasteBinElm.focus();
  1920. editor.selection.select(pasteBinElm, true);
  1921. };
  1922. var remove = function (editor, lastRngCell) {
  1923. if (getEl(editor)) {
  1924. var pasteBinClone = void 0;
  1925. var lastRng = lastRngCell.get();
  1926. while (pasteBinClone = editor.dom.get('mcepastebin')) {
  1927. editor.dom.remove(pasteBinClone);
  1928. editor.dom.unbind(pasteBinClone);
  1929. }
  1930. if (lastRng) {
  1931. editor.selection.setRng(lastRng);
  1932. }
  1933. }
  1934. lastRngCell.set(null);
  1935. };
  1936. var getEl = function (editor) {
  1937. return editor.dom.get('mcepastebin');
  1938. };
  1939. var getHtml = function (editor) {
  1940. var pasteBinElm, pasteBinClones, i, dirtyWrappers, cleanWrapper;
  1941. var copyAndRemove = function (toElm, fromElm) {
  1942. toElm.appendChild(fromElm);
  1943. editor.dom.remove(fromElm, true);
  1944. };
  1945. pasteBinClones = global$4.grep(getPasteBinParent(editor).childNodes, function (elm) {
  1946. return elm.id === 'mcepastebin';
  1947. });
  1948. pasteBinElm = pasteBinClones.shift();
  1949. global$4.each(pasteBinClones, function (pasteBinClone) {
  1950. copyAndRemove(pasteBinElm, pasteBinClone);
  1951. });
  1952. dirtyWrappers = editor.dom.select('div[id=mcepastebin]', pasteBinElm);
  1953. for (i = dirtyWrappers.length - 1; i >= 0; i--) {
  1954. cleanWrapper = editor.dom.create('div');
  1955. pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
  1956. copyAndRemove(cleanWrapper, dirtyWrappers[i]);
  1957. }
  1958. return pasteBinElm ? pasteBinElm.innerHTML : '';
  1959. };
  1960. var getLastRng = function (lastRng) {
  1961. return lastRng.get();
  1962. };
  1963. var isDefaultContent = function (pasteBinDefaultContent, content) {
  1964. return content === pasteBinDefaultContent;
  1965. };
  1966. var isPasteBin = function (elm) {
  1967. return elm && elm.id === 'mcepastebin';
  1968. };
  1969. var isDefault = function (editor, pasteBinDefaultContent) {
  1970. var pasteBinElm = getEl(editor);
  1971. return isPasteBin(pasteBinElm) && isDefaultContent(pasteBinDefaultContent, pasteBinElm.innerHTML);
  1972. };
  1973. var PasteBin = function (editor) {
  1974. var lastRng = Cell(null);
  1975. var pasteBinDefaultContent = '%MCEPASTEBIN%';
  1976. return {
  1977. create: function () {
  1978. return create(editor, lastRng, pasteBinDefaultContent);
  1979. },
  1980. remove: function () {
  1981. return remove(editor, lastRng);
  1982. },
  1983. getEl: function () {
  1984. return getEl(editor);
  1985. },
  1986. getHtml: function () {
  1987. return getHtml(editor);
  1988. },
  1989. getLastRng: function () {
  1990. return getLastRng(lastRng);
  1991. },
  1992. isDefault: function () {
  1993. return isDefault(editor, pasteBinDefaultContent);
  1994. },
  1995. isDefaultContent: function (content) {
  1996. return isDefaultContent(pasteBinDefaultContent, content);
  1997. }
  1998. };
  1999. };
  2000. var Clipboard = function (editor, pasteFormat) {
  2001. var pasteBin = PasteBin(editor);
  2002. editor.on('PreInit', function () {
  2003. return registerEventsAndFilters(editor, pasteBin, pasteFormat);
  2004. });
  2005. return {
  2006. pasteFormat: pasteFormat,
  2007. pasteHtml: function (html, internalFlag) {
  2008. return pasteHtml$1(editor, html, internalFlag);
  2009. },
  2010. pasteText: function (text) {
  2011. return pasteText(editor, text);
  2012. },
  2013. pasteImageData: function (e, rng) {
  2014. return pasteImageData(editor, e, rng);
  2015. },
  2016. getDataTransferItems: getDataTransferItems,
  2017. hasHtmlOrText: hasHtmlOrText,
  2018. hasContentType: hasContentType
  2019. };
  2020. };
  2021. var hasWorkingClipboardApi = function (clipboardData) {
  2022. return global$2.iOS === false && clipboardData !== undefined && typeof clipboardData.setData === 'function' && Utils.isMsEdge() !== true;
  2023. };
  2024. var setHtml5Clipboard = function (clipboardData, html, text) {
  2025. if (hasWorkingClipboardApi(clipboardData)) {
  2026. try {
  2027. clipboardData.clearData();
  2028. clipboardData.setData('text/html', html);
  2029. clipboardData.setData('text/plain', text);
  2030. clipboardData.setData(InternalHtml.internalHtmlMime(), html);
  2031. return true;
  2032. } catch (e) {
  2033. return false;
  2034. }
  2035. } else {
  2036. return false;
  2037. }
  2038. };
  2039. var setClipboardData = function (evt, data, fallback, done) {
  2040. if (setHtml5Clipboard(evt.clipboardData, data.html, data.text)) {
  2041. evt.preventDefault();
  2042. done();
  2043. } else {
  2044. fallback(data.html, done);
  2045. }
  2046. };
  2047. var fallback = function (editor) {
  2048. return function (html, done) {
  2049. var markedHtml = InternalHtml.mark(html);
  2050. var outer = editor.dom.create('div', {
  2051. 'contenteditable': 'false',
  2052. 'data-mce-bogus': 'all'
  2053. });
  2054. var inner = editor.dom.create('div', { contenteditable: 'true' }, markedHtml);
  2055. editor.dom.setStyles(outer, {
  2056. position: 'fixed',
  2057. top: '0',
  2058. left: '-3000px',
  2059. width: '1000px',
  2060. overflow: 'hidden'
  2061. });
  2062. outer.appendChild(inner);
  2063. editor.dom.add(editor.getBody(), outer);
  2064. var range = editor.selection.getRng();
  2065. inner.focus();
  2066. var offscreenRange = editor.dom.createRng();
  2067. offscreenRange.selectNodeContents(inner);
  2068. editor.selection.setRng(offscreenRange);
  2069. global$3.setTimeout(function () {
  2070. editor.selection.setRng(range);
  2071. outer.parentNode.removeChild(outer);
  2072. done();
  2073. }, 0);
  2074. };
  2075. };
  2076. var getData = function (editor) {
  2077. return {
  2078. html: editor.selection.getContent({ contextual: true }),
  2079. text: editor.selection.getContent({ format: 'text' })
  2080. };
  2081. };
  2082. var isTableSelection = function (editor) {
  2083. return !!editor.dom.getParent(editor.selection.getStart(), 'td[data-mce-selected],th[data-mce-selected]', editor.getBody());
  2084. };
  2085. var hasSelectedContent = function (editor) {
  2086. return !editor.selection.isCollapsed() || isTableSelection(editor);
  2087. };
  2088. var cut = function (editor) {
  2089. return function (evt) {
  2090. if (hasSelectedContent(editor)) {
  2091. setClipboardData(evt, getData(editor), fallback(editor), function () {
  2092. if (global$2.browser.isChrome()) {
  2093. var rng_1 = editor.selection.getRng();
  2094. global$3.setEditorTimeout(editor, function () {
  2095. editor.selection.setRng(rng_1);
  2096. editor.execCommand('Delete');
  2097. }, 0);
  2098. } else {
  2099. editor.execCommand('Delete');
  2100. }
  2101. });
  2102. }
  2103. };
  2104. };
  2105. var copy = function (editor) {
  2106. return function (evt) {
  2107. if (hasSelectedContent(editor)) {
  2108. setClipboardData(evt, getData(editor), fallback(editor), function () {
  2109. });
  2110. }
  2111. };
  2112. };
  2113. var register$1 = function (editor) {
  2114. editor.on('cut', cut(editor));
  2115. editor.on('copy', copy(editor));
  2116. };
  2117. var CutCopy = { register: register$1 };
  2118. var global$b = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');
  2119. var getCaretRangeFromEvent = function (editor, e) {
  2120. return global$b.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
  2121. };
  2122. var isPlainTextFileUrl = function (content) {
  2123. var plainTextContent = content['text/plain'];
  2124. return plainTextContent ? plainTextContent.indexOf('file://') === 0 : false;
  2125. };
  2126. var setFocusedRange = function (editor, rng) {
  2127. editor.focus();
  2128. editor.selection.setRng(rng);
  2129. };
  2130. var setup = function (editor, clipboard, draggingInternallyState) {
  2131. if (Settings.shouldBlockDrop(editor)) {
  2132. editor.on('dragend dragover draggesture dragdrop drop drag', function (e) {
  2133. e.preventDefault();
  2134. e.stopPropagation();
  2135. });
  2136. }
  2137. if (!Settings.shouldPasteDataImages(editor)) {
  2138. editor.on('drop', function (e) {
  2139. var dataTransfer = e.dataTransfer;
  2140. if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
  2141. e.preventDefault();
  2142. }
  2143. });
  2144. }
  2145. editor.on('drop', function (e) {
  2146. var dropContent, rng;
  2147. rng = getCaretRangeFromEvent(editor, e);
  2148. if (e.isDefaultPrevented() || draggingInternallyState.get()) {
  2149. return;
  2150. }
  2151. dropContent = clipboard.getDataTransferItems(e.dataTransfer);
  2152. var internal = clipboard.hasContentType(dropContent, InternalHtml.internalHtmlMime());
  2153. if ((!clipboard.hasHtmlOrText(dropContent) || isPlainTextFileUrl(dropContent)) && clipboard.pasteImageData(e, rng)) {
  2154. return;
  2155. }
  2156. if (rng && Settings.shouldFilterDrop(editor)) {
  2157. var content_1 = dropContent['mce-internal'] || dropContent['text/html'] || dropContent['text/plain'];
  2158. if (content_1) {
  2159. e.preventDefault();
  2160. global$3.setEditorTimeout(editor, function () {
  2161. editor.undoManager.transact(function () {
  2162. if (dropContent['mce-internal']) {
  2163. editor.execCommand('Delete');
  2164. }
  2165. setFocusedRange(editor, rng);
  2166. content_1 = Utils.trimHtml(content_1);
  2167. if (!dropContent['text/html']) {
  2168. clipboard.pasteText(content_1);
  2169. } else {
  2170. clipboard.pasteHtml(content_1, internal);
  2171. }
  2172. });
  2173. });
  2174. }
  2175. }
  2176. });
  2177. editor.on('dragstart', function (e) {
  2178. draggingInternallyState.set(true);
  2179. });
  2180. editor.on('dragover dragend', function (e) {
  2181. if (Settings.shouldPasteDataImages(editor) && draggingInternallyState.get() === false) {
  2182. e.preventDefault();
  2183. setFocusedRange(editor, getCaretRangeFromEvent(editor, e));
  2184. }
  2185. if (e.type === 'dragend') {
  2186. draggingInternallyState.set(false);
  2187. }
  2188. });
  2189. };
  2190. var DragDrop = { setup: setup };
  2191. var setup$1 = function (editor) {
  2192. var plugin = editor.plugins.paste;
  2193. var preProcess = Settings.getPreProcess(editor);
  2194. if (preProcess) {
  2195. editor.on('PastePreProcess', function (e) {
  2196. preProcess.call(plugin, plugin, e);
  2197. });
  2198. }
  2199. var postProcess = Settings.getPostProcess(editor);
  2200. if (postProcess) {
  2201. editor.on('PastePostProcess', function (e) {
  2202. postProcess.call(plugin, plugin, e);
  2203. });
  2204. }
  2205. };
  2206. var PrePostProcess = { setup: setup$1 };
  2207. function addPreProcessFilter(editor, filterFunc) {
  2208. editor.on('PastePreProcess', function (e) {
  2209. e.content = filterFunc(editor, e.content, e.internal, e.wordContent);
  2210. });
  2211. }
  2212. function addPostProcessFilter(editor, filterFunc) {
  2213. editor.on('PastePostProcess', function (e) {
  2214. filterFunc(editor, e.node);
  2215. });
  2216. }
  2217. function removeExplorerBrElementsAfterBlocks(editor, html) {
  2218. if (!WordFilter.isWordContent(html)) {
  2219. return html;
  2220. }
  2221. var blockElements = [];
  2222. global$4.each(editor.schema.getBlockElements(), function (block, blockName) {
  2223. blockElements.push(blockName);
  2224. });
  2225. var explorerBlocksRegExp = new RegExp('(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?(' + blockElements.join('|') + ')[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*', 'g');
  2226. html = Utils.filter(html, [[
  2227. explorerBlocksRegExp,
  2228. '$1'
  2229. ]]);
  2230. html = Utils.filter(html, [
  2231. [
  2232. /<br><br>/g,
  2233. '<BR><BR>'
  2234. ],
  2235. [
  2236. /<br>/g,
  2237. ' '
  2238. ],
  2239. [
  2240. /<BR><BR>/g,
  2241. '<br>'
  2242. ]
  2243. ]);
  2244. return html;
  2245. }
  2246. function removeWebKitStyles(editor, content, internal, isWordHtml) {
  2247. if (isWordHtml || internal) {
  2248. return content;
  2249. }
  2250. var webKitStylesSetting = Settings.getWebkitStyles(editor);
  2251. var webKitStyles;
  2252. if (Settings.shouldRemoveWebKitStyles(editor) === false || webKitStylesSetting === 'all') {
  2253. return content;
  2254. }
  2255. if (webKitStylesSetting) {
  2256. webKitStyles = webKitStylesSetting.split(/[, ]/);
  2257. }
  2258. if (webKitStyles) {
  2259. var dom_1 = editor.dom, node_1 = editor.selection.getNode();
  2260. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, function (all, before, value, after) {
  2261. var inputStyles = dom_1.parseStyle(dom_1.decode(value));
  2262. var outputStyles = {};
  2263. if (webKitStyles === 'none') {
  2264. return before + after;
  2265. }
  2266. for (var i = 0; i < webKitStyles.length; i++) {
  2267. var inputValue = inputStyles[webKitStyles[i]], currentValue = dom_1.getStyle(node_1, webKitStyles[i], true);
  2268. if (/color/.test(webKitStyles[i])) {
  2269. inputValue = dom_1.toHex(inputValue);
  2270. currentValue = dom_1.toHex(currentValue);
  2271. }
  2272. if (currentValue !== inputValue) {
  2273. outputStyles[webKitStyles[i]] = inputValue;
  2274. }
  2275. }
  2276. outputStyles = dom_1.serializeStyle(outputStyles, 'span');
  2277. if (outputStyles) {
  2278. return before + ' style="' + outputStyles + '"' + after;
  2279. }
  2280. return before + after;
  2281. });
  2282. } else {
  2283. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, '$1$3');
  2284. }
  2285. content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, function (all, before, value, after) {
  2286. return before + ' style="' + value + '"' + after;
  2287. });
  2288. return content;
  2289. }
  2290. function removeUnderlineAndFontInAnchor(editor, root) {
  2291. editor.$('a', root).find('font,u').each(function (i, node) {
  2292. editor.dom.remove(node, true);
  2293. });
  2294. }
  2295. var setup$2 = function (editor) {
  2296. if (global$2.webkit) {
  2297. addPreProcessFilter(editor, removeWebKitStyles);
  2298. }
  2299. if (global$2.ie) {
  2300. addPreProcessFilter(editor, removeExplorerBrElementsAfterBlocks);
  2301. addPostProcessFilter(editor, removeUnderlineAndFontInAnchor);
  2302. }
  2303. };
  2304. var Quirks = { setup: setup$2 };
  2305. var makeSetupHandler = function (editor, clipboard) {
  2306. return function (api) {
  2307. api.setActive(clipboard.pasteFormat.get() === 'text');
  2308. var pastePlainTextToggleHandler = function (e) {
  2309. return api.setActive(e.state);
  2310. };
  2311. editor.on('PastePlainTextToggle', pastePlainTextToggleHandler);
  2312. return function () {
  2313. return editor.off('PastePlainTextToggle', pastePlainTextToggleHandler);
  2314. };
  2315. };
  2316. };
  2317. var register$2 = function (editor, clipboard) {
  2318. editor.ui.registry.addToggleButton('pastetext', {
  2319. active: false,
  2320. icon: 'paste-text',
  2321. tooltip: 'Paste as text',
  2322. onAction: function () {
  2323. return editor.execCommand('mceTogglePlainTextPaste');
  2324. },
  2325. onSetup: makeSetupHandler(editor, clipboard)
  2326. });
  2327. editor.ui.registry.addToggleMenuItem('pastetext', {
  2328. text: 'Paste as text',
  2329. onAction: function () {
  2330. return editor.execCommand('mceTogglePlainTextPaste');
  2331. },
  2332. onSetup: makeSetupHandler(editor, clipboard)
  2333. });
  2334. };
  2335. var Buttons = { register: register$2 };
  2336. function Plugin () {
  2337. global$1.add('paste', function (editor) {
  2338. if (DetectProPlugin.hasProPlugin(editor) === false) {
  2339. var draggingInternallyState = Cell(false);
  2340. var pasteFormat = Cell(Settings.isPasteAsTextEnabled(editor) ? 'text' : 'html');
  2341. var clipboard = Clipboard(editor, pasteFormat);
  2342. var quirks = Quirks.setup(editor);
  2343. Buttons.register(editor, clipboard);
  2344. Commands.register(editor, clipboard);
  2345. PrePostProcess.setup(editor);
  2346. CutCopy.register(editor);
  2347. DragDrop.setup(editor, clipboard, draggingInternallyState);
  2348. return Api.get(clipboard, quirks);
  2349. }
  2350. });
  2351. }
  2352. Plugin();
  2353. }(window));