plugin.js 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519
  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 global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var noop = function () {
  13. };
  14. var constant = function (value) {
  15. return function () {
  16. return value;
  17. };
  18. };
  19. var identity = function (x) {
  20. return x;
  21. };
  22. var die = function (msg) {
  23. return function () {
  24. throw new Error(msg);
  25. };
  26. };
  27. var never = constant(false);
  28. var always = constant(true);
  29. var none = function () {
  30. return NONE;
  31. };
  32. var NONE = function () {
  33. var eq = function (o) {
  34. return o.isNone();
  35. };
  36. var call = function (thunk) {
  37. return thunk();
  38. };
  39. var id = function (n) {
  40. return n;
  41. };
  42. var me = {
  43. fold: function (n, s) {
  44. return n();
  45. },
  46. is: never,
  47. isSome: never,
  48. isNone: always,
  49. getOr: id,
  50. getOrThunk: call,
  51. getOrDie: function (msg) {
  52. throw new Error(msg || 'error: getOrDie called on none.');
  53. },
  54. getOrNull: constant(null),
  55. getOrUndefined: constant(undefined),
  56. or: id,
  57. orThunk: call,
  58. map: none,
  59. each: noop,
  60. bind: none,
  61. exists: never,
  62. forall: always,
  63. filter: none,
  64. equals: eq,
  65. equals_: eq,
  66. toArray: function () {
  67. return [];
  68. },
  69. toString: constant('none()')
  70. };
  71. if (Object.freeze) {
  72. Object.freeze(me);
  73. }
  74. return me;
  75. }();
  76. var some = function (a) {
  77. var constant_a = constant(a);
  78. var self = function () {
  79. return me;
  80. };
  81. var bind = function (f) {
  82. return f(a);
  83. };
  84. var me = {
  85. fold: function (n, s) {
  86. return s(a);
  87. },
  88. is: function (v) {
  89. return a === v;
  90. },
  91. isSome: always,
  92. isNone: never,
  93. getOr: constant_a,
  94. getOrThunk: constant_a,
  95. getOrDie: constant_a,
  96. getOrNull: constant_a,
  97. getOrUndefined: constant_a,
  98. or: self,
  99. orThunk: self,
  100. map: function (f) {
  101. return some(f(a));
  102. },
  103. each: function (f) {
  104. f(a);
  105. },
  106. bind: bind,
  107. exists: bind,
  108. forall: bind,
  109. filter: function (f) {
  110. return f(a) ? me : NONE;
  111. },
  112. toArray: function () {
  113. return [a];
  114. },
  115. toString: function () {
  116. return 'some(' + a + ')';
  117. },
  118. equals: function (o) {
  119. return o.is(a);
  120. },
  121. equals_: function (o, elementEq) {
  122. return o.fold(never, function (b) {
  123. return elementEq(a, b);
  124. });
  125. }
  126. };
  127. return me;
  128. };
  129. var from = function (value) {
  130. return value === null || value === undefined ? NONE : some(value);
  131. };
  132. var Option = {
  133. some: some,
  134. none: none,
  135. from: from
  136. };
  137. var typeOf = function (x) {
  138. if (x === null) {
  139. return 'null';
  140. }
  141. var t = typeof x;
  142. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  143. return 'array';
  144. }
  145. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  146. return 'string';
  147. }
  148. return t;
  149. };
  150. var isType = function (type) {
  151. return function (value) {
  152. return typeOf(value) === type;
  153. };
  154. };
  155. var isString = isType('string');
  156. var isObject = isType('object');
  157. var isArray = isType('array');
  158. var isBoolean = isType('boolean');
  159. var isFunction = isType('function');
  160. var isNumber = isType('number');
  161. var nativeSlice = Array.prototype.slice;
  162. var nativePush = Array.prototype.push;
  163. var each = function (xs, f) {
  164. for (var i = 0, len = xs.length; i < len; i++) {
  165. var x = xs[i];
  166. f(x, i);
  167. }
  168. };
  169. var flatten = function (xs) {
  170. var r = [];
  171. for (var i = 0, len = xs.length; i < len; ++i) {
  172. if (!isArray(xs[i])) {
  173. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  174. }
  175. nativePush.apply(r, xs[i]);
  176. }
  177. return r;
  178. };
  179. var head = function (xs) {
  180. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  181. };
  182. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  183. return nativeSlice.call(x);
  184. };
  185. var findMap = function (arr, f) {
  186. for (var i = 0; i < arr.length; i++) {
  187. var r = f(arr[i], i);
  188. if (r.isSome()) {
  189. return r;
  190. }
  191. }
  192. return Option.none();
  193. };
  194. var __assign = function () {
  195. __assign = Object.assign || function __assign(t) {
  196. for (var s, i = 1, n = arguments.length; i < n; i++) {
  197. s = arguments[i];
  198. for (var p in s)
  199. if (Object.prototype.hasOwnProperty.call(s, p))
  200. t[p] = s[p];
  201. }
  202. return t;
  203. };
  204. return __assign.apply(this, arguments);
  205. };
  206. var exports$1 = {}, module = { exports: exports$1 };
  207. (function (define, exports, module, require) {
  208. (function (f) {
  209. if (typeof exports === 'object' && typeof module !== 'undefined') {
  210. module.exports = f();
  211. } else if (typeof define === 'function' && define.amd) {
  212. define([], f);
  213. } else {
  214. var g;
  215. if (typeof window !== 'undefined') {
  216. g = window;
  217. } else if (typeof global !== 'undefined') {
  218. g = global;
  219. } else if (typeof self !== 'undefined') {
  220. g = self;
  221. } else {
  222. g = this;
  223. }
  224. g.EphoxContactWrapper = f();
  225. }
  226. }(function () {
  227. return function () {
  228. function r(e, n, t) {
  229. function o(i, f) {
  230. if (!n[i]) {
  231. if (!e[i]) {
  232. var c = 'function' == typeof require && require;
  233. if (!f && c)
  234. return c(i, !0);
  235. if (u)
  236. return u(i, !0);
  237. var a = new Error('Cannot find module \'' + i + '\'');
  238. throw a.code = 'MODULE_NOT_FOUND', a;
  239. }
  240. var p = n[i] = { exports: {} };
  241. e[i][0].call(p.exports, function (r) {
  242. var n = e[i][1][r];
  243. return o(n || r);
  244. }, p, p.exports, r, e, n, t);
  245. }
  246. return n[i].exports;
  247. }
  248. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  249. o(t[i]);
  250. return o;
  251. }
  252. return r;
  253. }()({
  254. 1: [
  255. function (require, module, exports) {
  256. var process = module.exports = {};
  257. var cachedSetTimeout;
  258. var cachedClearTimeout;
  259. function defaultSetTimout() {
  260. throw new Error('setTimeout has not been defined');
  261. }
  262. function defaultClearTimeout() {
  263. throw new Error('clearTimeout has not been defined');
  264. }
  265. (function () {
  266. try {
  267. if (typeof setTimeout === 'function') {
  268. cachedSetTimeout = setTimeout;
  269. } else {
  270. cachedSetTimeout = defaultSetTimout;
  271. }
  272. } catch (e) {
  273. cachedSetTimeout = defaultSetTimout;
  274. }
  275. try {
  276. if (typeof clearTimeout === 'function') {
  277. cachedClearTimeout = clearTimeout;
  278. } else {
  279. cachedClearTimeout = defaultClearTimeout;
  280. }
  281. } catch (e) {
  282. cachedClearTimeout = defaultClearTimeout;
  283. }
  284. }());
  285. function runTimeout(fun) {
  286. if (cachedSetTimeout === setTimeout) {
  287. return setTimeout(fun, 0);
  288. }
  289. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  290. cachedSetTimeout = setTimeout;
  291. return setTimeout(fun, 0);
  292. }
  293. try {
  294. return cachedSetTimeout(fun, 0);
  295. } catch (e) {
  296. try {
  297. return cachedSetTimeout.call(null, fun, 0);
  298. } catch (e) {
  299. return cachedSetTimeout.call(this, fun, 0);
  300. }
  301. }
  302. }
  303. function runClearTimeout(marker) {
  304. if (cachedClearTimeout === clearTimeout) {
  305. return clearTimeout(marker);
  306. }
  307. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  308. cachedClearTimeout = clearTimeout;
  309. return clearTimeout(marker);
  310. }
  311. try {
  312. return cachedClearTimeout(marker);
  313. } catch (e) {
  314. try {
  315. return cachedClearTimeout.call(null, marker);
  316. } catch (e) {
  317. return cachedClearTimeout.call(this, marker);
  318. }
  319. }
  320. }
  321. var queue = [];
  322. var draining = false;
  323. var currentQueue;
  324. var queueIndex = -1;
  325. function cleanUpNextTick() {
  326. if (!draining || !currentQueue) {
  327. return;
  328. }
  329. draining = false;
  330. if (currentQueue.length) {
  331. queue = currentQueue.concat(queue);
  332. } else {
  333. queueIndex = -1;
  334. }
  335. if (queue.length) {
  336. drainQueue();
  337. }
  338. }
  339. function drainQueue() {
  340. if (draining) {
  341. return;
  342. }
  343. var timeout = runTimeout(cleanUpNextTick);
  344. draining = true;
  345. var len = queue.length;
  346. while (len) {
  347. currentQueue = queue;
  348. queue = [];
  349. while (++queueIndex < len) {
  350. if (currentQueue) {
  351. currentQueue[queueIndex].run();
  352. }
  353. }
  354. queueIndex = -1;
  355. len = queue.length;
  356. }
  357. currentQueue = null;
  358. draining = false;
  359. runClearTimeout(timeout);
  360. }
  361. process.nextTick = function (fun) {
  362. var args = new Array(arguments.length - 1);
  363. if (arguments.length > 1) {
  364. for (var i = 1; i < arguments.length; i++) {
  365. args[i - 1] = arguments[i];
  366. }
  367. }
  368. queue.push(new Item(fun, args));
  369. if (queue.length === 1 && !draining) {
  370. runTimeout(drainQueue);
  371. }
  372. };
  373. function Item(fun, array) {
  374. this.fun = fun;
  375. this.array = array;
  376. }
  377. Item.prototype.run = function () {
  378. this.fun.apply(null, this.array);
  379. };
  380. process.title = 'browser';
  381. process.browser = true;
  382. process.env = {};
  383. process.argv = [];
  384. process.version = '';
  385. process.versions = {};
  386. function noop() {
  387. }
  388. process.on = noop;
  389. process.addListener = noop;
  390. process.once = noop;
  391. process.off = noop;
  392. process.removeListener = noop;
  393. process.removeAllListeners = noop;
  394. process.emit = noop;
  395. process.prependListener = noop;
  396. process.prependOnceListener = noop;
  397. process.listeners = function (name) {
  398. return [];
  399. };
  400. process.binding = function (name) {
  401. throw new Error('process.binding is not supported');
  402. };
  403. process.cwd = function () {
  404. return '/';
  405. };
  406. process.chdir = function (dir) {
  407. throw new Error('process.chdir is not supported');
  408. };
  409. process.umask = function () {
  410. return 0;
  411. };
  412. },
  413. {}
  414. ],
  415. 2: [
  416. function (require, module, exports) {
  417. (function (setImmediate) {
  418. (function (root) {
  419. var setTimeoutFunc = setTimeout;
  420. function noop() {
  421. }
  422. function bind(fn, thisArg) {
  423. return function () {
  424. fn.apply(thisArg, arguments);
  425. };
  426. }
  427. function Promise(fn) {
  428. if (typeof this !== 'object')
  429. throw new TypeError('Promises must be constructed via new');
  430. if (typeof fn !== 'function')
  431. throw new TypeError('not a function');
  432. this._state = 0;
  433. this._handled = false;
  434. this._value = undefined;
  435. this._deferreds = [];
  436. doResolve(fn, this);
  437. }
  438. function handle(self, deferred) {
  439. while (self._state === 3) {
  440. self = self._value;
  441. }
  442. if (self._state === 0) {
  443. self._deferreds.push(deferred);
  444. return;
  445. }
  446. self._handled = true;
  447. Promise._immediateFn(function () {
  448. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  449. if (cb === null) {
  450. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  451. return;
  452. }
  453. var ret;
  454. try {
  455. ret = cb(self._value);
  456. } catch (e) {
  457. reject(deferred.promise, e);
  458. return;
  459. }
  460. resolve(deferred.promise, ret);
  461. });
  462. }
  463. function resolve(self, newValue) {
  464. try {
  465. if (newValue === self)
  466. throw new TypeError('A promise cannot be resolved with itself.');
  467. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  468. var then = newValue.then;
  469. if (newValue instanceof Promise) {
  470. self._state = 3;
  471. self._value = newValue;
  472. finale(self);
  473. return;
  474. } else if (typeof then === 'function') {
  475. doResolve(bind(then, newValue), self);
  476. return;
  477. }
  478. }
  479. self._state = 1;
  480. self._value = newValue;
  481. finale(self);
  482. } catch (e) {
  483. reject(self, e);
  484. }
  485. }
  486. function reject(self, newValue) {
  487. self._state = 2;
  488. self._value = newValue;
  489. finale(self);
  490. }
  491. function finale(self) {
  492. if (self._state === 2 && self._deferreds.length === 0) {
  493. Promise._immediateFn(function () {
  494. if (!self._handled) {
  495. Promise._unhandledRejectionFn(self._value);
  496. }
  497. });
  498. }
  499. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  500. handle(self, self._deferreds[i]);
  501. }
  502. self._deferreds = null;
  503. }
  504. function Handler(onFulfilled, onRejected, promise) {
  505. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  506. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  507. this.promise = promise;
  508. }
  509. function doResolve(fn, self) {
  510. var done = false;
  511. try {
  512. fn(function (value) {
  513. if (done)
  514. return;
  515. done = true;
  516. resolve(self, value);
  517. }, function (reason) {
  518. if (done)
  519. return;
  520. done = true;
  521. reject(self, reason);
  522. });
  523. } catch (ex) {
  524. if (done)
  525. return;
  526. done = true;
  527. reject(self, ex);
  528. }
  529. }
  530. Promise.prototype['catch'] = function (onRejected) {
  531. return this.then(null, onRejected);
  532. };
  533. Promise.prototype.then = function (onFulfilled, onRejected) {
  534. var prom = new this.constructor(noop);
  535. handle(this, new Handler(onFulfilled, onRejected, prom));
  536. return prom;
  537. };
  538. Promise.all = function (arr) {
  539. var args = Array.prototype.slice.call(arr);
  540. return new Promise(function (resolve, reject) {
  541. if (args.length === 0)
  542. return resolve([]);
  543. var remaining = args.length;
  544. function res(i, val) {
  545. try {
  546. if (val && (typeof val === 'object' || typeof val === 'function')) {
  547. var then = val.then;
  548. if (typeof then === 'function') {
  549. then.call(val, function (val) {
  550. res(i, val);
  551. }, reject);
  552. return;
  553. }
  554. }
  555. args[i] = val;
  556. if (--remaining === 0) {
  557. resolve(args);
  558. }
  559. } catch (ex) {
  560. reject(ex);
  561. }
  562. }
  563. for (var i = 0; i < args.length; i++) {
  564. res(i, args[i]);
  565. }
  566. });
  567. };
  568. Promise.resolve = function (value) {
  569. if (value && typeof value === 'object' && value.constructor === Promise) {
  570. return value;
  571. }
  572. return new Promise(function (resolve) {
  573. resolve(value);
  574. });
  575. };
  576. Promise.reject = function (value) {
  577. return new Promise(function (resolve, reject) {
  578. reject(value);
  579. });
  580. };
  581. Promise.race = function (values) {
  582. return new Promise(function (resolve, reject) {
  583. for (var i = 0, len = values.length; i < len; i++) {
  584. values[i].then(resolve, reject);
  585. }
  586. });
  587. };
  588. Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
  589. setImmediate(fn);
  590. } : function (fn) {
  591. setTimeoutFunc(fn, 0);
  592. };
  593. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  594. if (typeof console !== 'undefined' && console) {
  595. console.warn('Possible Unhandled Promise Rejection:', err);
  596. }
  597. };
  598. Promise._setImmediateFn = function _setImmediateFn(fn) {
  599. Promise._immediateFn = fn;
  600. };
  601. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  602. Promise._unhandledRejectionFn = fn;
  603. };
  604. if (typeof module !== 'undefined' && module.exports) {
  605. module.exports = Promise;
  606. } else if (!root.Promise) {
  607. root.Promise = Promise;
  608. }
  609. }(this));
  610. }.call(this, require('timers').setImmediate));
  611. },
  612. { 'timers': 3 }
  613. ],
  614. 3: [
  615. function (require, module, exports) {
  616. (function (setImmediate, clearImmediate) {
  617. var nextTick = require('process/browser.js').nextTick;
  618. var apply = Function.prototype.apply;
  619. var slice = Array.prototype.slice;
  620. var immediateIds = {};
  621. var nextImmediateId = 0;
  622. exports.setTimeout = function () {
  623. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  624. };
  625. exports.setInterval = function () {
  626. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  627. };
  628. exports.clearTimeout = exports.clearInterval = function (timeout) {
  629. timeout.close();
  630. };
  631. function Timeout(id, clearFn) {
  632. this._id = id;
  633. this._clearFn = clearFn;
  634. }
  635. Timeout.prototype.unref = Timeout.prototype.ref = function () {
  636. };
  637. Timeout.prototype.close = function () {
  638. this._clearFn.call(window, this._id);
  639. };
  640. exports.enroll = function (item, msecs) {
  641. clearTimeout(item._idleTimeoutId);
  642. item._idleTimeout = msecs;
  643. };
  644. exports.unenroll = function (item) {
  645. clearTimeout(item._idleTimeoutId);
  646. item._idleTimeout = -1;
  647. };
  648. exports._unrefActive = exports.active = function (item) {
  649. clearTimeout(item._idleTimeoutId);
  650. var msecs = item._idleTimeout;
  651. if (msecs >= 0) {
  652. item._idleTimeoutId = setTimeout(function onTimeout() {
  653. if (item._onTimeout)
  654. item._onTimeout();
  655. }, msecs);
  656. }
  657. };
  658. exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
  659. var id = nextImmediateId++;
  660. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  661. immediateIds[id] = true;
  662. nextTick(function onNextTick() {
  663. if (immediateIds[id]) {
  664. if (args) {
  665. fn.apply(null, args);
  666. } else {
  667. fn.call(null);
  668. }
  669. exports.clearImmediate(id);
  670. }
  671. });
  672. return id;
  673. };
  674. exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
  675. delete immediateIds[id];
  676. };
  677. }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
  678. },
  679. {
  680. 'process/browser.js': 1,
  681. 'timers': 3
  682. }
  683. ],
  684. 4: [
  685. function (require, module, exports) {
  686. var promisePolyfill = require('promise-polyfill');
  687. var Global = function () {
  688. if (typeof window !== 'undefined') {
  689. return window;
  690. } else {
  691. return Function('return this;')();
  692. }
  693. }();
  694. module.exports = { boltExport: Global.Promise || promisePolyfill };
  695. },
  696. { 'promise-polyfill': 2 }
  697. ]
  698. }, {}, [4])(4);
  699. }));
  700. }(undefined, exports$1, module, undefined));
  701. var Promise = module.exports.boltExport;
  702. var nu = function (baseFn) {
  703. var data = Option.none();
  704. var callbacks = [];
  705. var map = function (f) {
  706. return nu(function (nCallback) {
  707. get(function (data) {
  708. nCallback(f(data));
  709. });
  710. });
  711. };
  712. var get = function (nCallback) {
  713. if (isReady()) {
  714. call(nCallback);
  715. } else {
  716. callbacks.push(nCallback);
  717. }
  718. };
  719. var set = function (x) {
  720. data = Option.some(x);
  721. run(callbacks);
  722. callbacks = [];
  723. };
  724. var isReady = function () {
  725. return data.isSome();
  726. };
  727. var run = function (cbs) {
  728. each(cbs, call);
  729. };
  730. var call = function (cb) {
  731. data.each(function (x) {
  732. domGlobals.setTimeout(function () {
  733. cb(x);
  734. }, 0);
  735. });
  736. };
  737. baseFn(set);
  738. return {
  739. get: get,
  740. map: map,
  741. isReady: isReady
  742. };
  743. };
  744. var pure = function (a) {
  745. return nu(function (callback) {
  746. callback(a);
  747. });
  748. };
  749. var LazyValue = {
  750. nu: nu,
  751. pure: pure
  752. };
  753. var errorReporter = function (err) {
  754. domGlobals.setTimeout(function () {
  755. throw err;
  756. }, 0);
  757. };
  758. var make = function (run) {
  759. var get = function (callback) {
  760. run().then(callback, errorReporter);
  761. };
  762. var map = function (fab) {
  763. return make(function () {
  764. return run().then(fab);
  765. });
  766. };
  767. var bind = function (aFutureB) {
  768. return make(function () {
  769. return run().then(function (v) {
  770. return aFutureB(v).toPromise();
  771. });
  772. });
  773. };
  774. var anonBind = function (futureB) {
  775. return make(function () {
  776. return run().then(function () {
  777. return futureB.toPromise();
  778. });
  779. });
  780. };
  781. var toLazy = function () {
  782. return LazyValue.nu(get);
  783. };
  784. var toCached = function () {
  785. var cache = null;
  786. return make(function () {
  787. if (cache === null) {
  788. cache = run();
  789. }
  790. return cache;
  791. });
  792. };
  793. var toPromise = run;
  794. return {
  795. map: map,
  796. bind: bind,
  797. anonBind: anonBind,
  798. toLazy: toLazy,
  799. toCached: toCached,
  800. toPromise: toPromise,
  801. get: get
  802. };
  803. };
  804. var nu$1 = function (baseFn) {
  805. return make(function () {
  806. return new Promise(baseFn);
  807. });
  808. };
  809. var pure$1 = function (a) {
  810. return make(function () {
  811. return Promise.resolve(a);
  812. });
  813. };
  814. var Future = {
  815. nu: nu$1,
  816. pure: pure$1
  817. };
  818. var value = function (o) {
  819. var is = function (v) {
  820. return o === v;
  821. };
  822. var or = function (opt) {
  823. return value(o);
  824. };
  825. var orThunk = function (f) {
  826. return value(o);
  827. };
  828. var map = function (f) {
  829. return value(f(o));
  830. };
  831. var mapError = function (f) {
  832. return value(o);
  833. };
  834. var each = function (f) {
  835. f(o);
  836. };
  837. var bind = function (f) {
  838. return f(o);
  839. };
  840. var fold = function (_, onValue) {
  841. return onValue(o);
  842. };
  843. var exists = function (f) {
  844. return f(o);
  845. };
  846. var forall = function (f) {
  847. return f(o);
  848. };
  849. var toOption = function () {
  850. return Option.some(o);
  851. };
  852. return {
  853. is: is,
  854. isValue: always,
  855. isError: never,
  856. getOr: constant(o),
  857. getOrThunk: constant(o),
  858. getOrDie: constant(o),
  859. or: or,
  860. orThunk: orThunk,
  861. fold: fold,
  862. map: map,
  863. mapError: mapError,
  864. each: each,
  865. bind: bind,
  866. exists: exists,
  867. forall: forall,
  868. toOption: toOption
  869. };
  870. };
  871. var error = function (message) {
  872. var getOrThunk = function (f) {
  873. return f();
  874. };
  875. var getOrDie = function () {
  876. return die(String(message))();
  877. };
  878. var or = function (opt) {
  879. return opt;
  880. };
  881. var orThunk = function (f) {
  882. return f();
  883. };
  884. var map = function (f) {
  885. return error(message);
  886. };
  887. var mapError = function (f) {
  888. return error(f(message));
  889. };
  890. var bind = function (f) {
  891. return error(message);
  892. };
  893. var fold = function (onError, _) {
  894. return onError(message);
  895. };
  896. return {
  897. is: never,
  898. isValue: never,
  899. isError: always,
  900. getOr: identity,
  901. getOrThunk: getOrThunk,
  902. getOrDie: getOrDie,
  903. or: or,
  904. orThunk: orThunk,
  905. fold: fold,
  906. map: map,
  907. mapError: mapError,
  908. each: noop,
  909. bind: bind,
  910. exists: never,
  911. forall: always,
  912. toOption: Option.none
  913. };
  914. };
  915. var fromOption = function (opt, err) {
  916. return opt.fold(function () {
  917. return error(err);
  918. }, value);
  919. };
  920. var Result = {
  921. value: value,
  922. error: error,
  923. fromOption: fromOption
  924. };
  925. var wrap = function (delegate) {
  926. var toCached = function () {
  927. return wrap(delegate.toCached());
  928. };
  929. var bindFuture = function (f) {
  930. return wrap(delegate.bind(function (resA) {
  931. return resA.fold(function (err) {
  932. return Future.pure(Result.error(err));
  933. }, function (a) {
  934. return f(a);
  935. });
  936. }));
  937. };
  938. var bindResult = function (f) {
  939. return wrap(delegate.map(function (resA) {
  940. return resA.bind(f);
  941. }));
  942. };
  943. var mapResult = function (f) {
  944. return wrap(delegate.map(function (resA) {
  945. return resA.map(f);
  946. }));
  947. };
  948. var mapError = function (f) {
  949. return wrap(delegate.map(function (resA) {
  950. return resA.mapError(f);
  951. }));
  952. };
  953. var foldResult = function (whenError, whenValue) {
  954. return delegate.map(function (res) {
  955. return res.fold(whenError, whenValue);
  956. });
  957. };
  958. var withTimeout = function (timeout, errorThunk) {
  959. return wrap(Future.nu(function (callback) {
  960. var timedOut = false;
  961. var timer = domGlobals.setTimeout(function () {
  962. timedOut = true;
  963. callback(Result.error(errorThunk()));
  964. }, timeout);
  965. delegate.get(function (result) {
  966. if (!timedOut) {
  967. domGlobals.clearTimeout(timer);
  968. callback(result);
  969. }
  970. });
  971. }));
  972. };
  973. return __assign(__assign({}, delegate), {
  974. toCached: toCached,
  975. bindFuture: bindFuture,
  976. bindResult: bindResult,
  977. mapResult: mapResult,
  978. mapError: mapError,
  979. foldResult: foldResult,
  980. withTimeout: withTimeout
  981. });
  982. };
  983. var nu$2 = function (worker) {
  984. return wrap(Future.nu(worker));
  985. };
  986. var value$1 = function (value) {
  987. return wrap(Future.pure(Result.value(value)));
  988. };
  989. var error$1 = function (error) {
  990. return wrap(Future.pure(Result.error(error)));
  991. };
  992. var fromResult = function (result) {
  993. return wrap(Future.pure(result));
  994. };
  995. var fromFuture = function (future) {
  996. return wrap(future.map(Result.value));
  997. };
  998. var fromPromise = function (promise) {
  999. return nu$2(function (completer) {
  1000. promise.then(function (value) {
  1001. completer(Result.value(value));
  1002. }, function (error) {
  1003. completer(Result.error(error));
  1004. });
  1005. });
  1006. };
  1007. var FutureResult = {
  1008. nu: nu$2,
  1009. wrap: wrap,
  1010. pure: value$1,
  1011. value: value$1,
  1012. error: error$1,
  1013. fromResult: fromResult,
  1014. fromFuture: fromFuture,
  1015. fromPromise: fromPromise
  1016. };
  1017. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1018. var deep = function (old, nu) {
  1019. var bothObjects = isObject(old) && isObject(nu);
  1020. return bothObjects ? deepMerge(old, nu) : nu;
  1021. };
  1022. var baseMerge = function (merger) {
  1023. return function () {
  1024. var objects = new Array(arguments.length);
  1025. for (var i = 0; i < objects.length; i++) {
  1026. objects[i] = arguments[i];
  1027. }
  1028. if (objects.length === 0) {
  1029. throw new Error('Can\'t merge zero objects');
  1030. }
  1031. var ret = {};
  1032. for (var j = 0; j < objects.length; j++) {
  1033. var curObject = objects[j];
  1034. for (var key in curObject) {
  1035. if (hasOwnProperty.call(curObject, key)) {
  1036. ret[key] = merger(ret[key], curObject[key]);
  1037. }
  1038. }
  1039. }
  1040. return ret;
  1041. };
  1042. };
  1043. var deepMerge = baseMerge(deep);
  1044. var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
  1045. var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
  1046. var COMMENT = domGlobals.Node.COMMENT_NODE;
  1047. var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
  1048. var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
  1049. var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
  1050. var ELEMENT = domGlobals.Node.ELEMENT_NODE;
  1051. var TEXT = domGlobals.Node.TEXT_NODE;
  1052. var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
  1053. var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
  1054. var ENTITY = domGlobals.Node.ENTITY_NODE;
  1055. var NOTATION = domGlobals.Node.NOTATION_NODE;
  1056. var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
  1057. var rawSet = function (dom, key, value) {
  1058. if (isString(value) || isBoolean(value) || isNumber(value)) {
  1059. dom.setAttribute(key, value + '');
  1060. } else {
  1061. domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  1062. throw new Error('Attribute value was not simple');
  1063. }
  1064. };
  1065. var set = function (element, key, value) {
  1066. rawSet(element.dom(), key, value);
  1067. };
  1068. var fromHtml = function (html, scope) {
  1069. var doc = scope || domGlobals.document;
  1070. var div = doc.createElement('div');
  1071. div.innerHTML = html;
  1072. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  1073. domGlobals.console.error('HTML does not have a single root node', html);
  1074. throw new Error('HTML must have a single root node');
  1075. }
  1076. return fromDom(div.childNodes[0]);
  1077. };
  1078. var fromTag = function (tag, scope) {
  1079. var doc = scope || domGlobals.document;
  1080. var node = doc.createElement(tag);
  1081. return fromDom(node);
  1082. };
  1083. var fromText = function (text, scope) {
  1084. var doc = scope || domGlobals.document;
  1085. var node = doc.createTextNode(text);
  1086. return fromDom(node);
  1087. };
  1088. var fromDom = function (node) {
  1089. if (node === null || node === undefined) {
  1090. throw new Error('Node cannot be null or undefined');
  1091. }
  1092. return { dom: constant(node) };
  1093. };
  1094. var fromPoint = function (docElm, x, y) {
  1095. var doc = docElm.dom();
  1096. return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
  1097. };
  1098. var Element = {
  1099. fromHtml: fromHtml,
  1100. fromTag: fromTag,
  1101. fromText: fromText,
  1102. fromDom: fromDom,
  1103. fromPoint: fromPoint
  1104. };
  1105. var global$2 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  1106. var global$3 = tinymce.util.Tools.resolve('tinymce.util.Promise');
  1107. var global$4 = tinymce.util.Tools.resolve('tinymce.util.XHR');
  1108. var hasDimensions = function (editor) {
  1109. return editor.getParam('image_dimensions', true, 'boolean');
  1110. };
  1111. var hasAdvTab = function (editor) {
  1112. return editor.getParam('image_advtab', false, 'boolean');
  1113. };
  1114. var hasUploadTab = function (editor) {
  1115. return editor.getParam('image_uploadtab', true, 'boolean');
  1116. };
  1117. var getPrependUrl = function (editor) {
  1118. return editor.getParam('image_prepend_url', '', 'string');
  1119. };
  1120. var getClassList = function (editor) {
  1121. return editor.getParam('image_class_list');
  1122. };
  1123. var hasDescription = function (editor) {
  1124. return editor.getParam('image_description', true, 'boolean');
  1125. };
  1126. var hasImageTitle = function (editor) {
  1127. return editor.getParam('image_title', false, 'boolean');
  1128. };
  1129. var hasImageCaption = function (editor) {
  1130. return editor.getParam('image_caption', false, 'boolean');
  1131. };
  1132. var getImageList = function (editor) {
  1133. return editor.getParam('image_list', false);
  1134. };
  1135. var hasUploadUrl = function (editor) {
  1136. return !!getUploadUrl(editor);
  1137. };
  1138. var hasUploadHandler = function (editor) {
  1139. return !!getUploadHandler(editor);
  1140. };
  1141. var getUploadUrl = function (editor) {
  1142. return editor.getParam('images_upload_url', '', 'string');
  1143. };
  1144. var getUploadHandler = function (editor) {
  1145. return editor.getParam('images_upload_handler', undefined, 'function');
  1146. };
  1147. var getUploadBasePath = function (editor) {
  1148. return editor.getParam('images_upload_base_path', undefined, 'string');
  1149. };
  1150. var getUploadCredentials = function (editor) {
  1151. return editor.getParam('images_upload_credentials', false, 'boolean');
  1152. };
  1153. var showAccessibilityOptions = function (editor) {
  1154. return editor.getParam('a11y_advanced_options', false, 'boolean');
  1155. };
  1156. var isAutomaticUploadsEnabled = function (editor) {
  1157. return editor.getParam('automatic_uploads', true, 'boolean');
  1158. };
  1159. var Settings = {
  1160. hasDimensions: hasDimensions,
  1161. hasUploadTab: hasUploadTab,
  1162. hasAdvTab: hasAdvTab,
  1163. getPrependUrl: getPrependUrl,
  1164. getClassList: getClassList,
  1165. hasDescription: hasDescription,
  1166. hasImageTitle: hasImageTitle,
  1167. hasImageCaption: hasImageCaption,
  1168. getImageList: getImageList,
  1169. hasUploadUrl: hasUploadUrl,
  1170. hasUploadHandler: hasUploadHandler,
  1171. getUploadUrl: getUploadUrl,
  1172. getUploadHandler: getUploadHandler,
  1173. getUploadBasePath: getUploadBasePath,
  1174. getUploadCredentials: getUploadCredentials,
  1175. showAccessibilityOptions: showAccessibilityOptions,
  1176. isAutomaticUploadsEnabled: isAutomaticUploadsEnabled
  1177. };
  1178. var parseIntAndGetMax = function (val1, val2) {
  1179. return Math.max(parseInt(val1, 10), parseInt(val2, 10));
  1180. };
  1181. var getImageSize = function (url, callback) {
  1182. var img = domGlobals.document.createElement('img');
  1183. var done = function (dimensions) {
  1184. if (img.parentNode) {
  1185. img.parentNode.removeChild(img);
  1186. }
  1187. callback(dimensions);
  1188. };
  1189. img.onload = function () {
  1190. var width = parseIntAndGetMax(img.width, img.clientWidth);
  1191. var height = parseIntAndGetMax(img.height, img.clientHeight);
  1192. var dimensions = {
  1193. width: width,
  1194. height: height
  1195. };
  1196. done(Result.value(dimensions));
  1197. };
  1198. img.onerror = function () {
  1199. done(Result.error('Failed to get image dimensions for: ' + url));
  1200. };
  1201. var style = img.style;
  1202. style.visibility = 'hidden';
  1203. style.position = 'fixed';
  1204. style.bottom = style.left = '0px';
  1205. style.width = style.height = 'auto';
  1206. domGlobals.document.body.appendChild(img);
  1207. img.src = url;
  1208. };
  1209. var removePixelSuffix = function (value) {
  1210. if (value) {
  1211. value = value.replace(/px$/, '');
  1212. }
  1213. return value;
  1214. };
  1215. var addPixelSuffix = function (value) {
  1216. if (value.length > 0 && /^[0-9]+$/.test(value)) {
  1217. value += 'px';
  1218. }
  1219. return value;
  1220. };
  1221. var mergeMargins = function (css) {
  1222. if (css.margin) {
  1223. var splitMargin = String(css.margin).split(' ');
  1224. switch (splitMargin.length) {
  1225. case 1:
  1226. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1227. css['margin-right'] = css['margin-right'] || splitMargin[0];
  1228. css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
  1229. css['margin-left'] = css['margin-left'] || splitMargin[0];
  1230. break;
  1231. case 2:
  1232. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1233. css['margin-right'] = css['margin-right'] || splitMargin[1];
  1234. css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
  1235. css['margin-left'] = css['margin-left'] || splitMargin[1];
  1236. break;
  1237. case 3:
  1238. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1239. css['margin-right'] = css['margin-right'] || splitMargin[1];
  1240. css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
  1241. css['margin-left'] = css['margin-left'] || splitMargin[1];
  1242. break;
  1243. case 4:
  1244. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1245. css['margin-right'] = css['margin-right'] || splitMargin[1];
  1246. css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
  1247. css['margin-left'] = css['margin-left'] || splitMargin[3];
  1248. }
  1249. delete css.margin;
  1250. }
  1251. return css;
  1252. };
  1253. var createImageList = function (editor, callback) {
  1254. var imageList = Settings.getImageList(editor);
  1255. if (typeof imageList === 'string') {
  1256. global$4.send({
  1257. url: imageList,
  1258. success: function (text) {
  1259. callback(JSON.parse(text));
  1260. }
  1261. });
  1262. } else if (typeof imageList === 'function') {
  1263. imageList(callback);
  1264. } else {
  1265. callback(imageList);
  1266. }
  1267. };
  1268. var waitLoadImage = function (editor, data, imgElm) {
  1269. var selectImage = function () {
  1270. imgElm.onload = imgElm.onerror = null;
  1271. if (editor.selection) {
  1272. editor.selection.select(imgElm);
  1273. editor.nodeChanged();
  1274. }
  1275. };
  1276. imgElm.onload = function () {
  1277. if (!data.width && !data.height && Settings.hasDimensions(editor)) {
  1278. editor.dom.setAttribs(imgElm, {
  1279. width: String(imgElm.clientWidth),
  1280. height: String(imgElm.clientHeight)
  1281. });
  1282. }
  1283. selectImage();
  1284. };
  1285. imgElm.onerror = selectImage;
  1286. };
  1287. var blobToDataUri = function (blob) {
  1288. return new global$3(function (resolve, reject) {
  1289. var reader = new domGlobals.FileReader();
  1290. reader.onload = function () {
  1291. resolve(reader.result);
  1292. };
  1293. reader.onerror = function () {
  1294. reject(reader.error.message);
  1295. };
  1296. reader.readAsDataURL(blob);
  1297. });
  1298. };
  1299. var isPlaceholderImage = function (imgElm) {
  1300. return imgElm.nodeName === 'IMG' && (imgElm.hasAttribute('data-mce-object') || imgElm.hasAttribute('data-mce-placeholder'));
  1301. };
  1302. var Utils = {
  1303. getImageSize: getImageSize,
  1304. removePixelSuffix: removePixelSuffix,
  1305. addPixelSuffix: addPixelSuffix,
  1306. mergeMargins: mergeMargins,
  1307. createImageList: createImageList,
  1308. waitLoadImage: waitLoadImage,
  1309. blobToDataUri: blobToDataUri,
  1310. isPlaceholderImage: isPlaceholderImage
  1311. };
  1312. var DOM = global$2.DOM;
  1313. var getHspace = function (image) {
  1314. if (image.style.marginLeft && image.style.marginRight && image.style.marginLeft === image.style.marginRight) {
  1315. return Utils.removePixelSuffix(image.style.marginLeft);
  1316. } else {
  1317. return '';
  1318. }
  1319. };
  1320. var getVspace = function (image) {
  1321. if (image.style.marginTop && image.style.marginBottom && image.style.marginTop === image.style.marginBottom) {
  1322. return Utils.removePixelSuffix(image.style.marginTop);
  1323. } else {
  1324. return '';
  1325. }
  1326. };
  1327. var getBorder = function (image) {
  1328. if (image.style.borderWidth) {
  1329. return Utils.removePixelSuffix(image.style.borderWidth);
  1330. } else {
  1331. return '';
  1332. }
  1333. };
  1334. var getAttrib = function (image, name) {
  1335. if (image.hasAttribute(name)) {
  1336. return image.getAttribute(name);
  1337. } else {
  1338. return '';
  1339. }
  1340. };
  1341. var getStyle = function (image, name) {
  1342. return image.style[name] ? image.style[name] : '';
  1343. };
  1344. var hasCaption = function (image) {
  1345. return image.parentNode !== null && image.parentNode.nodeName === 'FIGURE';
  1346. };
  1347. var setAttrib = function (image, name, value) {
  1348. image.setAttribute(name, value);
  1349. };
  1350. var wrapInFigure = function (image) {
  1351. var figureElm = DOM.create('figure', { class: 'image' });
  1352. DOM.insertAfter(figureElm, image);
  1353. figureElm.appendChild(image);
  1354. figureElm.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
  1355. figureElm.contentEditable = 'false';
  1356. };
  1357. var removeFigure = function (image) {
  1358. var figureElm = image.parentNode;
  1359. DOM.insertAfter(image, figureElm);
  1360. DOM.remove(figureElm);
  1361. };
  1362. var toggleCaption = function (image) {
  1363. if (hasCaption(image)) {
  1364. removeFigure(image);
  1365. } else {
  1366. wrapInFigure(image);
  1367. }
  1368. };
  1369. var normalizeStyle = function (image, normalizeCss) {
  1370. var attrValue = image.getAttribute('style');
  1371. var value = normalizeCss(attrValue !== null ? attrValue : '');
  1372. if (value.length > 0) {
  1373. image.setAttribute('style', value);
  1374. image.setAttribute('data-mce-style', value);
  1375. } else {
  1376. image.removeAttribute('style');
  1377. }
  1378. };
  1379. var setSize = function (name, normalizeCss) {
  1380. return function (image, name, value) {
  1381. if (image.style[name]) {
  1382. image.style[name] = Utils.addPixelSuffix(value);
  1383. normalizeStyle(image, normalizeCss);
  1384. } else {
  1385. setAttrib(image, name, value);
  1386. }
  1387. };
  1388. };
  1389. var getSize = function (image, name) {
  1390. if (image.style[name]) {
  1391. return Utils.removePixelSuffix(image.style[name]);
  1392. } else {
  1393. return getAttrib(image, name);
  1394. }
  1395. };
  1396. var setHspace = function (image, value) {
  1397. var pxValue = Utils.addPixelSuffix(value);
  1398. image.style.marginLeft = pxValue;
  1399. image.style.marginRight = pxValue;
  1400. };
  1401. var setVspace = function (image, value) {
  1402. var pxValue = Utils.addPixelSuffix(value);
  1403. image.style.marginTop = pxValue;
  1404. image.style.marginBottom = pxValue;
  1405. };
  1406. var setBorder = function (image, value) {
  1407. var pxValue = Utils.addPixelSuffix(value);
  1408. image.style.borderWidth = pxValue;
  1409. };
  1410. var setBorderStyle = function (image, value) {
  1411. image.style.borderStyle = value;
  1412. };
  1413. var getBorderStyle = function (image) {
  1414. return getStyle(image, 'borderStyle');
  1415. };
  1416. var isFigure = function (elm) {
  1417. return elm.nodeName === 'FIGURE';
  1418. };
  1419. var isImage = function (elm) {
  1420. return elm.nodeName === 'IMG';
  1421. };
  1422. var getIsDecorative = function (image) {
  1423. return DOM.getAttrib(image, 'alt').length === 0 && DOM.getAttrib(image, 'role') === 'presentation';
  1424. };
  1425. var getAlt = function (image) {
  1426. if (getIsDecorative(image)) {
  1427. return '';
  1428. } else {
  1429. return getAttrib(image, 'alt');
  1430. }
  1431. };
  1432. var defaultData = function () {
  1433. return {
  1434. src: '',
  1435. alt: '',
  1436. title: '',
  1437. width: '',
  1438. height: '',
  1439. class: '',
  1440. style: '',
  1441. caption: false,
  1442. hspace: '',
  1443. vspace: '',
  1444. border: '',
  1445. borderStyle: '',
  1446. isDecorative: false
  1447. };
  1448. };
  1449. var getStyleValue = function (normalizeCss, data) {
  1450. var image = domGlobals.document.createElement('img');
  1451. setAttrib(image, 'style', data.style);
  1452. if (getHspace(image) || data.hspace !== '') {
  1453. setHspace(image, data.hspace);
  1454. }
  1455. if (getVspace(image) || data.vspace !== '') {
  1456. setVspace(image, data.vspace);
  1457. }
  1458. if (getBorder(image) || data.border !== '') {
  1459. setBorder(image, data.border);
  1460. }
  1461. if (getBorderStyle(image) || data.borderStyle !== '') {
  1462. setBorderStyle(image, data.borderStyle);
  1463. }
  1464. return normalizeCss(image.getAttribute('style'));
  1465. };
  1466. var create = function (normalizeCss, data, info) {
  1467. var image = domGlobals.document.createElement('img');
  1468. write(normalizeCss, __assign(__assign({}, data), { caption: false }), image, info);
  1469. setAlt(image, data.alt, data.isDecorative, info);
  1470. if (data.caption) {
  1471. var figure = DOM.create('figure', { class: 'image' });
  1472. figure.appendChild(image);
  1473. figure.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
  1474. figure.contentEditable = 'false';
  1475. return figure;
  1476. } else {
  1477. return image;
  1478. }
  1479. };
  1480. var read = function (normalizeCss, image) {
  1481. return {
  1482. src: getAttrib(image, 'src'),
  1483. alt: getAlt(image),
  1484. title: getAttrib(image, 'title'),
  1485. width: getSize(image, 'width'),
  1486. height: getSize(image, 'height'),
  1487. class: getAttrib(image, 'class'),
  1488. style: normalizeCss(getAttrib(image, 'style')),
  1489. caption: hasCaption(image),
  1490. hspace: getHspace(image),
  1491. vspace: getVspace(image),
  1492. border: getBorder(image),
  1493. borderStyle: getStyle(image, 'borderStyle'),
  1494. isDecorative: getIsDecorative(image)
  1495. };
  1496. };
  1497. var updateProp = function (image, oldData, newData, name, set) {
  1498. if (newData[name] !== oldData[name]) {
  1499. set(image, name, newData[name]);
  1500. }
  1501. };
  1502. var setAlt = function (image, alt, isDecorative, info) {
  1503. if (isDecorative) {
  1504. DOM.setAttrib(image, 'role', 'presentation');
  1505. var sugarImage = Element.fromDom(image);
  1506. set(sugarImage, 'alt', '');
  1507. } else {
  1508. if (info.hasAccessibilityOptions) {
  1509. DOM.setAttrib(image, 'alt', alt);
  1510. } else {
  1511. var sugarImage = Element.fromDom(image);
  1512. set(sugarImage, 'alt', alt);
  1513. }
  1514. if (DOM.getAttrib(image, 'role') === 'presentation') {
  1515. DOM.setAttrib(image, 'role', '');
  1516. }
  1517. }
  1518. };
  1519. var updateAlt = function (image, oldData, newData, info) {
  1520. if (newData.alt !== oldData.alt || newData.isDecorative !== oldData.isDecorative) {
  1521. setAlt(image, newData.alt, newData.isDecorative, info);
  1522. }
  1523. };
  1524. var normalized = function (set, normalizeCss) {
  1525. return function (image, name, value) {
  1526. set(image, value);
  1527. normalizeStyle(image, normalizeCss);
  1528. };
  1529. };
  1530. var write = function (normalizeCss, newData, image, info) {
  1531. var oldData = read(normalizeCss, image);
  1532. updateProp(image, oldData, newData, 'caption', function (image, _name, _value) {
  1533. return toggleCaption(image);
  1534. });
  1535. updateProp(image, oldData, newData, 'src', setAttrib);
  1536. updateProp(image, oldData, newData, 'title', setAttrib);
  1537. updateProp(image, oldData, newData, 'width', setSize('width', normalizeCss));
  1538. updateProp(image, oldData, newData, 'height', setSize('height', normalizeCss));
  1539. updateProp(image, oldData, newData, 'class', setAttrib);
  1540. updateProp(image, oldData, newData, 'style', normalized(function (image, value) {
  1541. return setAttrib(image, 'style', value);
  1542. }, normalizeCss));
  1543. updateProp(image, oldData, newData, 'hspace', normalized(setHspace, normalizeCss));
  1544. updateProp(image, oldData, newData, 'vspace', normalized(setVspace, normalizeCss));
  1545. updateProp(image, oldData, newData, 'border', normalized(setBorder, normalizeCss));
  1546. updateProp(image, oldData, newData, 'borderStyle', normalized(setBorderStyle, normalizeCss));
  1547. updateAlt(image, oldData, newData, info);
  1548. };
  1549. var normalizeCss = function (editor, cssText) {
  1550. var css = editor.dom.styles.parse(cssText);
  1551. var mergedCss = Utils.mergeMargins(css);
  1552. var compressed = editor.dom.styles.parse(editor.dom.styles.serialize(mergedCss));
  1553. return editor.dom.styles.serialize(compressed);
  1554. };
  1555. var getSelectedImage = function (editor) {
  1556. var imgElm = editor.selection.getNode();
  1557. var figureElm = editor.dom.getParent(imgElm, 'figure.image');
  1558. if (figureElm) {
  1559. return editor.dom.select('img', figureElm)[0];
  1560. }
  1561. if (imgElm && (imgElm.nodeName !== 'IMG' || Utils.isPlaceholderImage(imgElm))) {
  1562. return null;
  1563. }
  1564. return imgElm;
  1565. };
  1566. var splitTextBlock = function (editor, figure) {
  1567. var dom = editor.dom;
  1568. var textBlock = dom.getParent(figure.parentNode, function (node) {
  1569. return !!editor.schema.getTextBlockElements()[node.nodeName];
  1570. }, editor.getBody());
  1571. if (textBlock) {
  1572. return dom.split(textBlock, figure);
  1573. } else {
  1574. return figure;
  1575. }
  1576. };
  1577. var readImageDataFromSelection = function (editor) {
  1578. var image = getSelectedImage(editor);
  1579. return image ? read(function (css) {
  1580. return normalizeCss(editor, css);
  1581. }, image) : defaultData();
  1582. };
  1583. var insertImageAtCaret = function (editor, data, info) {
  1584. var elm = create(function (css) {
  1585. return normalizeCss(editor, css);
  1586. }, data, info);
  1587. editor.dom.setAttrib(elm, 'data-mce-id', '__mcenew');
  1588. editor.focus();
  1589. editor.selection.setContent(elm.outerHTML);
  1590. var insertedElm = editor.dom.select('*[data-mce-id="__mcenew"]')[0];
  1591. editor.dom.setAttrib(insertedElm, 'data-mce-id', null);
  1592. if (isFigure(insertedElm)) {
  1593. var figure = splitTextBlock(editor, insertedElm);
  1594. editor.selection.select(figure);
  1595. } else {
  1596. editor.selection.select(insertedElm);
  1597. }
  1598. };
  1599. var syncSrcAttr = function (editor, image) {
  1600. editor.dom.setAttrib(image, 'src', image.getAttribute('src'));
  1601. };
  1602. var deleteImage = function (editor, image) {
  1603. if (image) {
  1604. var elm = editor.dom.is(image.parentNode, 'figure.image') ? image.parentNode : image;
  1605. editor.dom.remove(elm);
  1606. editor.focus();
  1607. editor.nodeChanged();
  1608. if (editor.dom.isEmpty(editor.getBody())) {
  1609. editor.setContent('');
  1610. editor.selection.setCursorLocation();
  1611. }
  1612. }
  1613. };
  1614. var writeImageDataToSelection = function (editor, data, info) {
  1615. var image = getSelectedImage(editor);
  1616. write(function (css) {
  1617. return normalizeCss(editor, css);
  1618. }, data, image, info);
  1619. syncSrcAttr(editor, image);
  1620. if (isFigure(image.parentNode)) {
  1621. var figure = image.parentNode;
  1622. splitTextBlock(editor, figure);
  1623. editor.selection.select(image.parentNode);
  1624. } else {
  1625. editor.selection.select(image);
  1626. Utils.waitLoadImage(editor, data, image);
  1627. }
  1628. };
  1629. var insertOrUpdateImage = function (editor, data, info) {
  1630. var image = getSelectedImage(editor);
  1631. if (image) {
  1632. if (data.src) {
  1633. writeImageDataToSelection(editor, data, info);
  1634. } else {
  1635. deleteImage(editor, image);
  1636. }
  1637. } else if (data.src) {
  1638. insertImageAtCaret(editor, data, info);
  1639. }
  1640. };
  1641. var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  1642. var getValue = function (item) {
  1643. return isString(item.value) ? item.value : '';
  1644. };
  1645. var sanitizeList = function (list, extractValue) {
  1646. var out = [];
  1647. global$5.each(list, function (item) {
  1648. var text = isString(item.text) ? item.text : isString(item.title) ? item.title : '';
  1649. if (item.menu !== undefined) {
  1650. var items = sanitizeList(item.menu, extractValue);
  1651. out.push({
  1652. text: text,
  1653. items: items
  1654. });
  1655. } else {
  1656. var value = extractValue(item);
  1657. out.push({
  1658. text: text,
  1659. value: value
  1660. });
  1661. }
  1662. });
  1663. return out;
  1664. };
  1665. var sanitizer = function (extracter) {
  1666. if (extracter === void 0) {
  1667. extracter = getValue;
  1668. }
  1669. return function (list) {
  1670. if (list) {
  1671. return Option.from(list).map(function (list) {
  1672. return sanitizeList(list, extracter);
  1673. });
  1674. } else {
  1675. return Option.none();
  1676. }
  1677. };
  1678. };
  1679. var sanitize = function (list) {
  1680. return sanitizer(getValue)(list);
  1681. };
  1682. var isGroup = function (item) {
  1683. return Object.prototype.hasOwnProperty.call(item, 'items');
  1684. };
  1685. var findEntryDelegate = function (list, value) {
  1686. return findMap(list, function (item) {
  1687. if (isGroup(item)) {
  1688. return findEntryDelegate(item.items, value);
  1689. } else if (item.value === value) {
  1690. return Option.some(item);
  1691. } else {
  1692. return Option.none();
  1693. }
  1694. });
  1695. };
  1696. var findEntry = function (optList, value) {
  1697. return optList.bind(function (list) {
  1698. return findEntryDelegate(list, value);
  1699. });
  1700. };
  1701. var ListUtils = {
  1702. sanitizer: sanitizer,
  1703. sanitize: sanitize,
  1704. findEntry: findEntry
  1705. };
  1706. var pathJoin = function (path1, path2) {
  1707. if (path1) {
  1708. return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '');
  1709. }
  1710. return path2;
  1711. };
  1712. function Uploader (settings) {
  1713. var defaultHandler = function (blobInfo, success, failure, progress) {
  1714. var xhr, formData;
  1715. xhr = new domGlobals.XMLHttpRequest();
  1716. xhr.open('POST', settings.url);
  1717. xhr.withCredentials = settings.credentials;
  1718. xhr.upload.onprogress = function (e) {
  1719. progress(e.loaded / e.total * 100);
  1720. };
  1721. xhr.onerror = function () {
  1722. failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
  1723. };
  1724. xhr.onload = function () {
  1725. var json;
  1726. if (xhr.status < 200 || xhr.status >= 300) {
  1727. failure('HTTP Error: ' + xhr.status);
  1728. return;
  1729. }
  1730. json = JSON.parse(xhr.responseText);
  1731. if (!json || typeof json.location !== 'string') {
  1732. failure('Invalid JSON: ' + xhr.responseText);
  1733. return;
  1734. }
  1735. success(pathJoin(settings.basePath, json.location));
  1736. };
  1737. formData = new domGlobals.FormData();
  1738. formData.append('file', blobInfo.blob(), blobInfo.filename());
  1739. xhr.send(formData);
  1740. };
  1741. var uploadBlob = function (blobInfo, handler) {
  1742. return new global$3(function (resolve, reject) {
  1743. try {
  1744. handler(blobInfo, resolve, reject, noop);
  1745. } catch (ex) {
  1746. reject(ex.message);
  1747. }
  1748. });
  1749. };
  1750. var isDefaultHandler = function (handler) {
  1751. return handler === defaultHandler;
  1752. };
  1753. var upload = function (blobInfo) {
  1754. return !settings.url && isDefaultHandler(settings.handler) ? global$3.reject('Upload url missing from the settings.') : uploadBlob(blobInfo, settings.handler);
  1755. };
  1756. settings = global$5.extend({
  1757. credentials: false,
  1758. handler: defaultHandler
  1759. }, settings);
  1760. return { upload: upload };
  1761. }
  1762. var makeTab = function (info) {
  1763. return {
  1764. title: 'Advanced',
  1765. name: 'advanced',
  1766. items: [
  1767. {
  1768. type: 'input',
  1769. label: 'Style',
  1770. name: 'style'
  1771. },
  1772. {
  1773. type: 'grid',
  1774. columns: 2,
  1775. items: [
  1776. {
  1777. type: 'input',
  1778. label: 'Vertical space',
  1779. name: 'vspace',
  1780. inputMode: 'numeric'
  1781. },
  1782. {
  1783. type: 'input',
  1784. label: 'Horizontal space',
  1785. name: 'hspace',
  1786. inputMode: 'numeric'
  1787. },
  1788. {
  1789. type: 'input',
  1790. label: 'Border width',
  1791. name: 'border',
  1792. inputMode: 'numeric'
  1793. },
  1794. {
  1795. type: 'selectbox',
  1796. name: 'borderstyle',
  1797. label: 'Border style',
  1798. items: [
  1799. {
  1800. text: 'Select...',
  1801. value: ''
  1802. },
  1803. {
  1804. text: 'Solid',
  1805. value: 'solid'
  1806. },
  1807. {
  1808. text: 'Dotted',
  1809. value: 'dotted'
  1810. },
  1811. {
  1812. text: 'Dashed',
  1813. value: 'dashed'
  1814. },
  1815. {
  1816. text: 'Double',
  1817. value: 'double'
  1818. },
  1819. {
  1820. text: 'Groove',
  1821. value: 'groove'
  1822. },
  1823. {
  1824. text: 'Ridge',
  1825. value: 'ridge'
  1826. },
  1827. {
  1828. text: 'Inset',
  1829. value: 'inset'
  1830. },
  1831. {
  1832. text: 'Outset',
  1833. value: 'outset'
  1834. },
  1835. {
  1836. text: 'None',
  1837. value: 'none'
  1838. },
  1839. {
  1840. text: 'Hidden',
  1841. value: 'hidden'
  1842. }
  1843. ]
  1844. }
  1845. ]
  1846. }
  1847. ]
  1848. };
  1849. };
  1850. var AdvTab = { makeTab: makeTab };
  1851. var collect = function (editor) {
  1852. var urlListSanitizer = ListUtils.sanitizer(function (item) {
  1853. return editor.convertURL(item.value || item.url, 'src');
  1854. });
  1855. var futureImageList = Future.nu(function (completer) {
  1856. Utils.createImageList(editor, function (imageList) {
  1857. completer(urlListSanitizer(imageList).map(function (items) {
  1858. return flatten([
  1859. [{
  1860. text: 'None',
  1861. value: ''
  1862. }],
  1863. items
  1864. ]);
  1865. }));
  1866. });
  1867. });
  1868. var classList = ListUtils.sanitize(Settings.getClassList(editor));
  1869. var hasAdvTab = Settings.hasAdvTab(editor);
  1870. var hasUploadTab = Settings.hasUploadTab(editor);
  1871. var hasUploadUrl = Settings.hasUploadUrl(editor);
  1872. var hasUploadHandler = Settings.hasUploadHandler(editor);
  1873. var image = readImageDataFromSelection(editor);
  1874. var hasDescription = Settings.hasDescription(editor);
  1875. var hasImageTitle = Settings.hasImageTitle(editor);
  1876. var hasDimensions = Settings.hasDimensions(editor);
  1877. var hasImageCaption = Settings.hasImageCaption(editor);
  1878. var hasAccessibilityOptions = Settings.showAccessibilityOptions(editor);
  1879. var url = Settings.getUploadUrl(editor);
  1880. var basePath = Settings.getUploadBasePath(editor);
  1881. var credentials = Settings.getUploadCredentials(editor);
  1882. var handler = Settings.getUploadHandler(editor);
  1883. var automaticUploads = Settings.isAutomaticUploadsEnabled(editor);
  1884. var prependURL = Option.some(Settings.getPrependUrl(editor)).filter(function (preUrl) {
  1885. return isString(preUrl) && preUrl.length > 0;
  1886. });
  1887. return futureImageList.map(function (imageList) {
  1888. return {
  1889. image: image,
  1890. imageList: imageList,
  1891. classList: classList,
  1892. hasAdvTab: hasAdvTab,
  1893. hasUploadTab: hasUploadTab,
  1894. hasUploadUrl: hasUploadUrl,
  1895. hasUploadHandler: hasUploadHandler,
  1896. hasDescription: hasDescription,
  1897. hasImageTitle: hasImageTitle,
  1898. hasDimensions: hasDimensions,
  1899. hasImageCaption: hasImageCaption,
  1900. url: url,
  1901. basePath: basePath,
  1902. credentials: credentials,
  1903. handler: handler,
  1904. prependURL: prependURL,
  1905. hasAccessibilityOptions: hasAccessibilityOptions,
  1906. automaticUploads: automaticUploads
  1907. };
  1908. });
  1909. };
  1910. var makeItems = function (info) {
  1911. var imageUrl = {
  1912. name: 'src',
  1913. type: 'urlinput',
  1914. filetype: 'image',
  1915. label: 'Source'
  1916. };
  1917. var imageList = info.imageList.map(function (items) {
  1918. return {
  1919. name: 'images',
  1920. type: 'selectbox',
  1921. label: 'Image list',
  1922. items: items
  1923. };
  1924. });
  1925. var imageDescription = {
  1926. name: 'alt',
  1927. type: 'input',
  1928. label: 'Alternative description',
  1929. disabled: info.hasAccessibilityOptions && info.image.isDecorative
  1930. };
  1931. var imageTitle = {
  1932. name: 'title',
  1933. type: 'input',
  1934. label: 'Image title'
  1935. };
  1936. var imageDimensions = {
  1937. name: 'dimensions',
  1938. type: 'sizeinput'
  1939. };
  1940. var isDecorative = {
  1941. type: 'label',
  1942. label: 'Accessibility',
  1943. items: [{
  1944. name: 'isDecorative',
  1945. type: 'checkbox',
  1946. label: 'Image is decorative'
  1947. }]
  1948. };
  1949. var classList = info.classList.map(function (items) {
  1950. return {
  1951. name: 'classes',
  1952. type: 'selectbox',
  1953. label: 'Class',
  1954. items: items
  1955. };
  1956. });
  1957. var caption = {
  1958. type: 'label',
  1959. label: 'Caption',
  1960. items: [{
  1961. type: 'checkbox',
  1962. name: 'caption',
  1963. label: 'Show caption'
  1964. }]
  1965. };
  1966. return flatten([
  1967. [imageUrl],
  1968. imageList.toArray(),
  1969. info.hasAccessibilityOptions && info.hasDescription ? [isDecorative] : [],
  1970. info.hasDescription ? [imageDescription] : [],
  1971. info.hasImageTitle ? [imageTitle] : [],
  1972. info.hasDimensions ? [imageDimensions] : [],
  1973. [{
  1974. type: 'grid',
  1975. columns: 2,
  1976. items: flatten([
  1977. classList.toArray(),
  1978. info.hasImageCaption ? [caption] : []
  1979. ])
  1980. }]
  1981. ]);
  1982. };
  1983. var makeTab$1 = function (info) {
  1984. return {
  1985. title: 'General',
  1986. name: 'general',
  1987. items: makeItems(info)
  1988. };
  1989. };
  1990. var MainTab = {
  1991. makeTab: makeTab$1,
  1992. makeItems: makeItems
  1993. };
  1994. var makeTab$2 = function (info) {
  1995. var items = [{
  1996. type: 'dropzone',
  1997. name: 'fileinput'
  1998. }];
  1999. return {
  2000. title: 'Upload',
  2001. name: 'upload',
  2002. items: items
  2003. };
  2004. };
  2005. var UploadTab = { makeTab: makeTab$2 };
  2006. var createState = function (info) {
  2007. return {
  2008. prevImage: ListUtils.findEntry(info.imageList, info.image.src),
  2009. prevAlt: info.image.alt,
  2010. open: true
  2011. };
  2012. };
  2013. var fromImageData = function (image) {
  2014. return {
  2015. src: {
  2016. value: image.src,
  2017. meta: {}
  2018. },
  2019. images: image.src,
  2020. alt: image.alt,
  2021. title: image.title,
  2022. dimensions: {
  2023. width: image.width,
  2024. height: image.height
  2025. },
  2026. classes: image.class,
  2027. caption: image.caption,
  2028. style: image.style,
  2029. vspace: image.vspace,
  2030. border: image.border,
  2031. hspace: image.hspace,
  2032. borderstyle: image.borderStyle,
  2033. fileinput: [],
  2034. isDecorative: image.isDecorative
  2035. };
  2036. };
  2037. var toImageData = function (data) {
  2038. return {
  2039. src: data.src.value,
  2040. alt: data.alt,
  2041. title: data.title,
  2042. width: data.dimensions.width,
  2043. height: data.dimensions.height,
  2044. class: data.classes,
  2045. style: data.style,
  2046. caption: data.caption,
  2047. hspace: data.hspace,
  2048. vspace: data.vspace,
  2049. border: data.border,
  2050. borderStyle: data.borderstyle,
  2051. isDecorative: data.isDecorative
  2052. };
  2053. };
  2054. var addPrependUrl2 = function (info, srcURL) {
  2055. if (!/^(?:[a-zA-Z]+:)?\/\//.test(srcURL)) {
  2056. return info.prependURL.bind(function (prependUrl) {
  2057. if (srcURL.substring(0, prependUrl.length) !== prependUrl) {
  2058. return Option.some(prependUrl + srcURL);
  2059. }
  2060. return Option.none();
  2061. });
  2062. }
  2063. return Option.none();
  2064. };
  2065. var addPrependUrl = function (info, api) {
  2066. var data = api.getData();
  2067. addPrependUrl2(info, data.src.value).each(function (srcURL) {
  2068. api.setData({
  2069. src: {
  2070. value: srcURL,
  2071. meta: data.src.meta
  2072. }
  2073. });
  2074. });
  2075. };
  2076. var formFillFromMeta2 = function (info, data, meta) {
  2077. if (info.hasDescription && isString(meta.alt)) {
  2078. data.alt = meta.alt;
  2079. }
  2080. if (info.hasAccessibilityOptions) {
  2081. data.isDecorative = meta.isDecorative || false;
  2082. }
  2083. if (info.hasImageTitle && isString(meta.title)) {
  2084. data.title = meta.title;
  2085. }
  2086. if (info.hasDimensions) {
  2087. if (isString(meta.width)) {
  2088. data.dimensions.width = meta.width;
  2089. }
  2090. if (isString(meta.height)) {
  2091. data.dimensions.height = meta.height;
  2092. }
  2093. }
  2094. if (isString(meta.class)) {
  2095. ListUtils.findEntry(info.classList, meta.class).each(function (entry) {
  2096. data.classes = entry.value;
  2097. });
  2098. }
  2099. if (info.hasImageCaption) {
  2100. if (isBoolean(meta.caption)) {
  2101. data.caption = meta.caption;
  2102. }
  2103. }
  2104. if (info.hasAdvTab) {
  2105. if (isString(meta.style)) {
  2106. data.style = meta.style;
  2107. }
  2108. if (isString(meta.vspace)) {
  2109. data.vspace = meta.vspace;
  2110. }
  2111. if (isString(meta.border)) {
  2112. data.border = meta.border;
  2113. }
  2114. if (isString(meta.hspace)) {
  2115. data.hspace = meta.hspace;
  2116. }
  2117. if (isString(meta.borderstyle)) {
  2118. data.borderstyle = meta.borderstyle;
  2119. }
  2120. }
  2121. };
  2122. var formFillFromMeta = function (info, api) {
  2123. var data = api.getData();
  2124. var meta = data.src.meta;
  2125. if (meta !== undefined) {
  2126. var newData = deepMerge({}, data);
  2127. formFillFromMeta2(info, newData, meta);
  2128. api.setData(newData);
  2129. }
  2130. };
  2131. var calculateImageSize = function (helpers, info, state, api) {
  2132. var data = api.getData();
  2133. var url = data.src.value;
  2134. var meta = data.src.meta || {};
  2135. if (!meta.width && !meta.height && info.hasDimensions) {
  2136. helpers.imageSize(url).get(function (result) {
  2137. result.each(function (size) {
  2138. if (state.open) {
  2139. api.setData({ dimensions: size });
  2140. }
  2141. });
  2142. });
  2143. }
  2144. };
  2145. var updateImagesDropdown = function (info, state, api) {
  2146. var data = api.getData();
  2147. var image = ListUtils.findEntry(info.imageList, data.src.value);
  2148. state.prevImage = image;
  2149. api.setData({
  2150. images: image.map(function (entry) {
  2151. return entry.value;
  2152. }).getOr('')
  2153. });
  2154. };
  2155. var changeSrc = function (helpers, info, state, api) {
  2156. addPrependUrl(info, api);
  2157. formFillFromMeta(info, api);
  2158. calculateImageSize(helpers, info, state, api);
  2159. updateImagesDropdown(info, state, api);
  2160. };
  2161. var changeImages = function (helpers, info, state, api) {
  2162. var data = api.getData();
  2163. var image = ListUtils.findEntry(info.imageList, data.images);
  2164. image.each(function (img) {
  2165. var updateAlt = data.alt === '' || state.prevImage.map(function (image) {
  2166. return image.text === data.alt;
  2167. }).getOr(false);
  2168. if (updateAlt) {
  2169. if (img.value === '') {
  2170. api.setData({
  2171. src: img,
  2172. alt: state.prevAlt
  2173. });
  2174. } else {
  2175. api.setData({
  2176. src: img,
  2177. alt: img.text
  2178. });
  2179. }
  2180. } else {
  2181. api.setData({ src: img });
  2182. }
  2183. });
  2184. state.prevImage = image;
  2185. changeSrc(helpers, info, state, api);
  2186. };
  2187. var calcVSpace = function (css) {
  2188. var matchingTopBottom = css['margin-top'] && css['margin-bottom'] && css['margin-top'] === css['margin-bottom'];
  2189. return matchingTopBottom ? Utils.removePixelSuffix(String(css['margin-top'])) : '';
  2190. };
  2191. var calcHSpace = function (css) {
  2192. var matchingLeftRight = css['margin-right'] && css['margin-left'] && css['margin-right'] === css['margin-left'];
  2193. return matchingLeftRight ? Utils.removePixelSuffix(String(css['margin-right'])) : '';
  2194. };
  2195. var calcBorderWidth = function (css) {
  2196. return css['border-width'] ? Utils.removePixelSuffix(String(css['border-width'])) : '';
  2197. };
  2198. var calcBorderStyle = function (css) {
  2199. return css['border-style'] ? String(css['border-style']) : '';
  2200. };
  2201. var calcStyle = function (parseStyle, serializeStyle, css) {
  2202. return serializeStyle(parseStyle(serializeStyle(css)));
  2203. };
  2204. var changeStyle2 = function (parseStyle, serializeStyle, data) {
  2205. var css = Utils.mergeMargins(parseStyle(data.style));
  2206. var dataCopy = deepMerge({}, data);
  2207. dataCopy.vspace = calcVSpace(css);
  2208. dataCopy.hspace = calcHSpace(css);
  2209. dataCopy.border = calcBorderWidth(css);
  2210. dataCopy.borderstyle = calcBorderStyle(css);
  2211. dataCopy.style = calcStyle(parseStyle, serializeStyle, css);
  2212. return dataCopy;
  2213. };
  2214. var changeStyle = function (helpers, api) {
  2215. var data = api.getData();
  2216. var newData = changeStyle2(helpers.parseStyle, helpers.serializeStyle, data);
  2217. api.setData(newData);
  2218. };
  2219. var changeAStyle = function (helpers, info, api) {
  2220. var data = deepMerge(fromImageData(info.image), api.getData());
  2221. var style = getStyleValue(helpers.normalizeCss, toImageData(data));
  2222. api.setData({ style: style });
  2223. };
  2224. var changeFileInput = function (helpers, info, state, api) {
  2225. var data = api.getData();
  2226. api.block('Uploading image');
  2227. head(data.fileinput).fold(function () {
  2228. api.unblock();
  2229. }, function (file) {
  2230. var blobUri = domGlobals.URL.createObjectURL(file);
  2231. var uploader = Uploader({
  2232. url: info.url,
  2233. basePath: info.basePath,
  2234. credentials: info.credentials,
  2235. handler: info.handler
  2236. });
  2237. var finalize = function () {
  2238. api.unblock();
  2239. domGlobals.URL.revokeObjectURL(blobUri);
  2240. };
  2241. var updateSrcAndSwitchTab = function (url) {
  2242. api.setData({
  2243. src: {
  2244. value: url,
  2245. meta: {}
  2246. }
  2247. });
  2248. api.showTab('general');
  2249. changeSrc(helpers, info, state, api);
  2250. };
  2251. Utils.blobToDataUri(file).then(function (dataUrl) {
  2252. var blobInfo = helpers.createBlobCache(file, blobUri, dataUrl);
  2253. if (info.automaticUploads) {
  2254. uploader.upload(blobInfo).then(function (url) {
  2255. updateSrcAndSwitchTab(url);
  2256. finalize();
  2257. }).catch(function (err) {
  2258. finalize();
  2259. helpers.alertErr(api, err);
  2260. });
  2261. } else {
  2262. helpers.addToBlobCache(blobInfo);
  2263. updateSrcAndSwitchTab(blobInfo.blobUri());
  2264. api.unblock();
  2265. }
  2266. });
  2267. });
  2268. };
  2269. var changeHandler = function (helpers, info, state) {
  2270. return function (api, evt) {
  2271. if (evt.name === 'src') {
  2272. changeSrc(helpers, info, state, api);
  2273. } else if (evt.name === 'images') {
  2274. changeImages(helpers, info, state, api);
  2275. } else if (evt.name === 'alt') {
  2276. state.prevAlt = api.getData().alt;
  2277. } else if (evt.name === 'style') {
  2278. changeStyle(helpers, api);
  2279. } else if (evt.name === 'vspace' || evt.name === 'hspace' || evt.name === 'border' || evt.name === 'borderstyle') {
  2280. changeAStyle(helpers, info, api);
  2281. } else if (evt.name === 'fileinput') {
  2282. changeFileInput(helpers, info, state, api);
  2283. } else if (evt.name === 'isDecorative') {
  2284. if (api.getData().isDecorative) {
  2285. api.disable('alt');
  2286. } else {
  2287. api.enable('alt');
  2288. }
  2289. }
  2290. };
  2291. };
  2292. var closeHandler = function (state) {
  2293. return function () {
  2294. state.open = false;
  2295. };
  2296. };
  2297. var makeDialogBody = function (info) {
  2298. if (info.hasAdvTab || info.hasUploadUrl || info.hasUploadHandler) {
  2299. var tabPanel = {
  2300. type: 'tabpanel',
  2301. tabs: flatten([
  2302. [MainTab.makeTab(info)],
  2303. info.hasAdvTab ? [AdvTab.makeTab(info)] : [],
  2304. info.hasUploadTab && (info.hasUploadUrl || info.hasUploadHandler) ? [UploadTab.makeTab(info)] : []
  2305. ])
  2306. };
  2307. return tabPanel;
  2308. } else {
  2309. var panel = {
  2310. type: 'panel',
  2311. items: MainTab.makeItems(info)
  2312. };
  2313. return panel;
  2314. }
  2315. };
  2316. var makeDialog = function (helpers) {
  2317. return function (info) {
  2318. var state = createState(info);
  2319. return {
  2320. title: 'Insert/Edit Image',
  2321. size: 'normal',
  2322. body: makeDialogBody(info),
  2323. buttons: [
  2324. {
  2325. type: 'cancel',
  2326. name: 'cancel',
  2327. text: 'Cancel'
  2328. },
  2329. {
  2330. type: 'submit',
  2331. name: 'save',
  2332. text: 'Save',
  2333. primary: true
  2334. }
  2335. ],
  2336. initialData: fromImageData(info.image),
  2337. onSubmit: helpers.onSubmit(info),
  2338. onChange: changeHandler(helpers, info, state),
  2339. onClose: closeHandler(state)
  2340. };
  2341. };
  2342. };
  2343. var submitHandler = function (editor) {
  2344. return function (info) {
  2345. return function (api) {
  2346. var data = deepMerge(fromImageData(info.image), api.getData());
  2347. editor.undoManager.transact(function () {
  2348. insertOrUpdateImage(editor, toImageData(data), info);
  2349. });
  2350. editor.editorUpload.uploadImagesAuto();
  2351. api.close();
  2352. };
  2353. };
  2354. };
  2355. var imageSize = function (editor) {
  2356. return function (url) {
  2357. return FutureResult.nu(function (completer) {
  2358. Utils.getImageSize(editor.documentBaseURI.toAbsolute(url), function (data) {
  2359. var result = data.map(function (dimensions) {
  2360. return {
  2361. width: String(dimensions.width),
  2362. height: String(dimensions.height)
  2363. };
  2364. });
  2365. completer(result);
  2366. });
  2367. });
  2368. };
  2369. };
  2370. var createBlobCache = function (editor) {
  2371. return function (file, blobUri, dataUrl) {
  2372. return editor.editorUpload.blobCache.create({
  2373. blob: file,
  2374. blobUri: blobUri,
  2375. name: file.name ? file.name.replace(/\.[^\.]+$/, '') : null,
  2376. base64: dataUrl.split(',')[1]
  2377. });
  2378. };
  2379. };
  2380. var addToBlobCache = function (editor) {
  2381. return function (blobInfo) {
  2382. editor.editorUpload.blobCache.add(blobInfo);
  2383. };
  2384. };
  2385. var alertErr = function (editor) {
  2386. return function (api, message) {
  2387. editor.windowManager.alert(message, api.close);
  2388. };
  2389. };
  2390. var normalizeCss$1 = function (editor) {
  2391. return function (cssText) {
  2392. return normalizeCss(editor, cssText);
  2393. };
  2394. };
  2395. var parseStyle = function (editor) {
  2396. return function (cssText) {
  2397. return editor.dom.parseStyle(cssText);
  2398. };
  2399. };
  2400. var serializeStyle = function (editor) {
  2401. return function (stylesArg, name) {
  2402. return editor.dom.serializeStyle(stylesArg, name);
  2403. };
  2404. };
  2405. var Dialog = function (editor) {
  2406. var helpers = {
  2407. onSubmit: submitHandler(editor),
  2408. imageSize: imageSize(editor),
  2409. addToBlobCache: addToBlobCache(editor),
  2410. createBlobCache: createBlobCache(editor),
  2411. alertErr: alertErr(editor),
  2412. normalizeCss: normalizeCss$1(editor),
  2413. parseStyle: parseStyle(editor),
  2414. serializeStyle: serializeStyle(editor)
  2415. };
  2416. var open = function () {
  2417. return collect(editor).map(makeDialog(helpers)).get(function (spec) {
  2418. editor.windowManager.open(spec);
  2419. });
  2420. };
  2421. return { open: open };
  2422. };
  2423. var register = function (editor) {
  2424. editor.addCommand('mceImage', Dialog(editor).open);
  2425. };
  2426. var Commands = { register: register };
  2427. var hasImageClass = function (node) {
  2428. var className = node.attr('class');
  2429. return className && /\bimage\b/.test(className);
  2430. };
  2431. var toggleContentEditableState = function (state) {
  2432. return function (nodes) {
  2433. var i = nodes.length;
  2434. var toggleContentEditable = function (node) {
  2435. node.attr('contenteditable', state ? 'true' : null);
  2436. };
  2437. while (i--) {
  2438. var node = nodes[i];
  2439. if (hasImageClass(node)) {
  2440. node.attr('contenteditable', state ? 'false' : null);
  2441. global$5.each(node.getAll('figcaption'), toggleContentEditable);
  2442. }
  2443. }
  2444. };
  2445. };
  2446. var setup = function (editor) {
  2447. editor.on('PreInit', function () {
  2448. editor.parser.addNodeFilter('figure', toggleContentEditableState(true));
  2449. editor.serializer.addNodeFilter('figure', toggleContentEditableState(false));
  2450. });
  2451. };
  2452. var FilterContent = { setup: setup };
  2453. var register$1 = function (editor) {
  2454. editor.ui.registry.addToggleButton('image', {
  2455. icon: 'image',
  2456. tooltip: 'Insert/edit image',
  2457. onAction: Dialog(editor).open,
  2458. onSetup: function (buttonApi) {
  2459. return editor.selection.selectorChangedWithUnbind('img:not([data-mce-object],[data-mce-placeholder]),figure.image', buttonApi.setActive).unbind;
  2460. }
  2461. });
  2462. editor.ui.registry.addMenuItem('image', {
  2463. icon: 'image',
  2464. text: 'Image...',
  2465. onAction: Dialog(editor).open
  2466. });
  2467. editor.ui.registry.addContextMenu('image', {
  2468. update: function (element) {
  2469. return isFigure(element) || isImage(element) && !Utils.isPlaceholderImage(element) ? ['image'] : [];
  2470. }
  2471. });
  2472. };
  2473. var Buttons = { register: register$1 };
  2474. function Plugin () {
  2475. global$1.add('image', function (editor) {
  2476. FilterContent.setup(editor);
  2477. Buttons.register(editor);
  2478. Commands.register(editor);
  2479. });
  2480. }
  2481. Plugin();
  2482. }(window));