plugin.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.1.0 (2019-10-17)
  8. */
  9. (function (domGlobals) {
  10. 'use strict';
  11. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var global$2 = tinymce.util.Tools.resolve('tinymce.util.VK');
  13. var typeOf = function (x) {
  14. if (x === null) {
  15. return 'null';
  16. }
  17. var t = typeof x;
  18. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  19. return 'array';
  20. }
  21. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  22. return 'string';
  23. }
  24. return t;
  25. };
  26. var isType = function (type) {
  27. return function (value) {
  28. return typeOf(value) === type;
  29. };
  30. };
  31. var isString = isType('string');
  32. var isArray = isType('array');
  33. var isBoolean = isType('boolean');
  34. var isFunction = isType('function');
  35. var assumeExternalTargets = function (editor) {
  36. var externalTargets = editor.getParam('link_assume_external_targets', false);
  37. if (isBoolean(externalTargets) && externalTargets) {
  38. return 1;
  39. } else if (isString(externalTargets) && (externalTargets === 'http' || externalTargets === 'https')) {
  40. return externalTargets;
  41. }
  42. return 0;
  43. };
  44. var hasContextToolbar = function (editor) {
  45. return editor.getParam('link_context_toolbar', false, 'boolean');
  46. };
  47. var getLinkList = function (editor) {
  48. return editor.getParam('link_list');
  49. };
  50. var getDefaultLinkTarget = function (editor) {
  51. return editor.getParam('default_link_target');
  52. };
  53. var getTargetList = function (editor) {
  54. return editor.getParam('target_list', true);
  55. };
  56. var getRelList = function (editor) {
  57. return editor.getParam('rel_list', [], 'array');
  58. };
  59. var getLinkClassList = function (editor) {
  60. return editor.getParam('link_class_list', [], 'array');
  61. };
  62. var shouldShowLinkTitle = function (editor) {
  63. return editor.getParam('link_title', true, 'boolean');
  64. };
  65. var allowUnsafeLinkTarget = function (editor) {
  66. return editor.getParam('allow_unsafe_link_target', false, 'boolean');
  67. };
  68. var useQuickLink = function (editor) {
  69. return editor.getParam('link_quicklink', false, 'boolean');
  70. };
  71. var Settings = {
  72. assumeExternalTargets: assumeExternalTargets,
  73. hasContextToolbar: hasContextToolbar,
  74. getLinkList: getLinkList,
  75. getDefaultLinkTarget: getDefaultLinkTarget,
  76. getTargetList: getTargetList,
  77. getRelList: getRelList,
  78. getLinkClassList: getLinkClassList,
  79. shouldShowLinkTitle: shouldShowLinkTitle,
  80. allowUnsafeLinkTarget: allowUnsafeLinkTarget,
  81. useQuickLink: useQuickLink
  82. };
  83. var appendClickRemove = function (link, evt) {
  84. domGlobals.document.body.appendChild(link);
  85. link.dispatchEvent(evt);
  86. domGlobals.document.body.removeChild(link);
  87. };
  88. var open = function (url) {
  89. var link = domGlobals.document.createElement('a');
  90. link.target = '_blank';
  91. link.href = url;
  92. link.rel = 'noreferrer noopener';
  93. var evt = domGlobals.document.createEvent('MouseEvents');
  94. evt.initMouseEvent('click', true, true, domGlobals.window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  95. appendClickRemove(link, evt);
  96. };
  97. var OpenUrl = { open: open };
  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 nativeSlice = Array.prototype.slice;
  216. var nativeIndexOf = Array.prototype.indexOf;
  217. var nativePush = Array.prototype.push;
  218. var rawIndexOf = function (ts, t) {
  219. return nativeIndexOf.call(ts, t);
  220. };
  221. var contains = function (xs, x) {
  222. return rawIndexOf(xs, x) > -1;
  223. };
  224. var map = function (xs, f) {
  225. var len = xs.length;
  226. var r = new Array(len);
  227. for (var i = 0; i < len; i++) {
  228. var x = xs[i];
  229. r[i] = f(x, i);
  230. }
  231. return r;
  232. };
  233. var each = function (xs, f) {
  234. for (var i = 0, len = xs.length; i < len; i++) {
  235. var x = xs[i];
  236. f(x, i);
  237. }
  238. };
  239. var foldl = function (xs, f, acc) {
  240. each(xs, function (x) {
  241. acc = f(acc, x);
  242. });
  243. return acc;
  244. };
  245. var flatten = function (xs) {
  246. var r = [];
  247. for (var i = 0, len = xs.length; i < len; ++i) {
  248. if (!isArray(xs[i])) {
  249. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  250. }
  251. nativePush.apply(r, xs[i]);
  252. }
  253. return r;
  254. };
  255. var bind = function (xs, f) {
  256. var output = map(xs, f);
  257. return flatten(output);
  258. };
  259. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  260. return nativeSlice.call(x);
  261. };
  262. var global$3 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  263. var hasProtocol = function (url) {
  264. return /^\w+:/i.test(url);
  265. };
  266. var getHref = function (elm) {
  267. var href = elm.getAttribute('data-mce-href');
  268. return href ? href : elm.getAttribute('href');
  269. };
  270. var applyRelTargetRules = function (rel, isUnsafe) {
  271. var rules = ['noopener'];
  272. var rels = rel ? rel.split(/\s+/) : [];
  273. var toString = function (rels) {
  274. return global$3.trim(rels.sort().join(' '));
  275. };
  276. var addTargetRules = function (rels) {
  277. rels = removeTargetRules(rels);
  278. return rels.length > 0 ? rels.concat(rules) : rules;
  279. };
  280. var removeTargetRules = function (rels) {
  281. return rels.filter(function (val) {
  282. return global$3.inArray(rules, val) === -1;
  283. });
  284. };
  285. var newRels = isUnsafe ? addTargetRules(rels) : removeTargetRules(rels);
  286. return newRels.length > 0 ? toString(newRels) : '';
  287. };
  288. var trimCaretContainers = function (text) {
  289. return text.replace(/\uFEFF/g, '');
  290. };
  291. var getAnchorElement = function (editor, selectedElm) {
  292. selectedElm = selectedElm || editor.selection.getNode();
  293. if (isImageFigure(selectedElm)) {
  294. return editor.dom.select('a[href]', selectedElm)[0];
  295. } else {
  296. return editor.dom.getParent(selectedElm, 'a[href]');
  297. }
  298. };
  299. var getAnchorText = function (selection, anchorElm) {
  300. var text = anchorElm ? anchorElm.innerText || anchorElm.textContent : selection.getContent({ format: 'text' });
  301. return trimCaretContainers(text);
  302. };
  303. var isLink = function (elm) {
  304. return elm && elm.nodeName === 'A' && !!elm.href;
  305. };
  306. var hasLinks = function (elements) {
  307. return global$3.grep(elements, isLink).length > 0;
  308. };
  309. var isOnlyTextSelected = function (html) {
  310. if (/</.test(html) && (!/^<a [^>]+>[^<]+<\/a>$/.test(html) || html.indexOf('href=') === -1)) {
  311. return false;
  312. }
  313. return true;
  314. };
  315. var isImageFigure = function (elm) {
  316. return elm && elm.nodeName === 'FIGURE' && /\bimage\b/i.test(elm.className);
  317. };
  318. var getLinkAttrs = function (data) {
  319. return foldl([
  320. 'title',
  321. 'rel',
  322. 'class',
  323. 'target'
  324. ], function (acc, key) {
  325. data[key].each(function (value) {
  326. acc[key] = value.length > 0 ? value : null;
  327. });
  328. return acc;
  329. }, { href: data.href });
  330. };
  331. var handleExternalTargets = function (href, assumeExternalTargets) {
  332. if ((assumeExternalTargets === 'http' || assumeExternalTargets === 'https') && !hasProtocol(href)) {
  333. return assumeExternalTargets + '://' + href;
  334. }
  335. return href;
  336. };
  337. var updateLink = function (editor, anchorElm, text, linkAttrs) {
  338. text.each(function (text) {
  339. if (anchorElm.hasOwnProperty('innerText')) {
  340. anchorElm.innerText = text;
  341. } else {
  342. anchorElm.textContent = text;
  343. }
  344. });
  345. editor.dom.setAttribs(anchorElm, linkAttrs);
  346. editor.selection.select(anchorElm);
  347. };
  348. var createLink = function (editor, selectedElm, text, linkAttrs) {
  349. if (isImageFigure(selectedElm)) {
  350. linkImageFigure(editor, selectedElm, linkAttrs);
  351. } else {
  352. text.fold(function () {
  353. editor.execCommand('mceInsertLink', false, linkAttrs);
  354. }, function (text) {
  355. editor.insertContent(editor.dom.createHTML('a', linkAttrs, editor.dom.encode(text)));
  356. });
  357. }
  358. };
  359. var link = function (editor, attachState, data) {
  360. editor.undoManager.transact(function () {
  361. var selectedElm = editor.selection.getNode();
  362. var anchorElm = getAnchorElement(editor, selectedElm);
  363. var linkAttrs = getLinkAttrs(data);
  364. if (!(Settings.getRelList(editor).length > 0) && Settings.allowUnsafeLinkTarget(editor) === false) {
  365. var newRel = applyRelTargetRules(linkAttrs.rel, linkAttrs.target === '_blank');
  366. linkAttrs.rel = newRel ? newRel : null;
  367. }
  368. if (Option.from(linkAttrs.target).isNone()) {
  369. linkAttrs.target = Settings.getDefaultLinkTarget(editor);
  370. }
  371. linkAttrs.href = handleExternalTargets(linkAttrs.href, Settings.assumeExternalTargets(editor));
  372. if (data.href === attachState.href) {
  373. attachState.attach();
  374. }
  375. if (anchorElm) {
  376. editor.focus();
  377. updateLink(editor, anchorElm, data.text, linkAttrs);
  378. } else {
  379. createLink(editor, selectedElm, data.text, linkAttrs);
  380. }
  381. });
  382. };
  383. var unlink = function (editor) {
  384. editor.undoManager.transact(function () {
  385. var node = editor.selection.getNode();
  386. if (isImageFigure(node)) {
  387. unlinkImageFigure(editor, node);
  388. } else {
  389. var anchorElm = editor.dom.getParent(node, 'a[href]', editor.getBody());
  390. if (anchorElm) {
  391. editor.dom.remove(anchorElm, true);
  392. }
  393. }
  394. editor.focus();
  395. });
  396. };
  397. var unlinkImageFigure = function (editor, fig) {
  398. var img = editor.dom.select('img', fig)[0];
  399. if (img) {
  400. var a = editor.dom.getParents(img, 'a[href]', fig)[0];
  401. if (a) {
  402. a.parentNode.insertBefore(img, a);
  403. editor.dom.remove(a);
  404. }
  405. }
  406. };
  407. var linkImageFigure = function (editor, fig, attrs) {
  408. var img = editor.dom.select('img', fig)[0];
  409. if (img) {
  410. var a = editor.dom.create('a', attrs);
  411. img.parentNode.insertBefore(a, img);
  412. a.appendChild(img);
  413. }
  414. };
  415. var Utils = {
  416. link: link,
  417. unlink: unlink,
  418. isLink: isLink,
  419. hasLinks: hasLinks,
  420. getHref: getHref,
  421. isOnlyTextSelected: isOnlyTextSelected,
  422. getAnchorElement: getAnchorElement,
  423. getAnchorText: getAnchorText,
  424. applyRelTargetRules: applyRelTargetRules,
  425. hasProtocol: hasProtocol
  426. };
  427. var cat = function (arr) {
  428. var r = [];
  429. var push = function (x) {
  430. r.push(x);
  431. };
  432. for (var i = 0; i < arr.length; i++) {
  433. arr[i].each(push);
  434. }
  435. return r;
  436. };
  437. var findMap = function (arr, f) {
  438. for (var i = 0; i < arr.length; i++) {
  439. var r = f(arr[i], i);
  440. if (r.isSome()) {
  441. return r;
  442. }
  443. }
  444. return Option.none();
  445. };
  446. var getValue = function (item) {
  447. return isString(item.value) ? item.value : '';
  448. };
  449. var sanitizeList = function (list, extractValue) {
  450. var out = [];
  451. global$3.each(list, function (item) {
  452. var text = isString(item.text) ? item.text : isString(item.title) ? item.title : '';
  453. if (item.menu !== undefined) ; else {
  454. var value = extractValue(item);
  455. out.push({
  456. text: text,
  457. value: value
  458. });
  459. }
  460. });
  461. return out;
  462. };
  463. var sanitizeWith = function (extracter) {
  464. if (extracter === void 0) {
  465. extracter = getValue;
  466. }
  467. return function (list) {
  468. return Option.from(list).map(function (list) {
  469. return sanitizeList(list, extracter);
  470. });
  471. };
  472. };
  473. var sanitize = function (list) {
  474. return sanitizeWith(getValue)(list);
  475. };
  476. var createUi = function (name, label) {
  477. return function (items) {
  478. return {
  479. name: name,
  480. type: 'selectbox',
  481. label: label,
  482. items: items
  483. };
  484. };
  485. };
  486. var ListOptions = {
  487. sanitize: sanitize,
  488. sanitizeWith: sanitizeWith,
  489. createUi: createUi,
  490. getValue: getValue
  491. };
  492. var Cell = function (initial) {
  493. var value = initial;
  494. var get = function () {
  495. return value;
  496. };
  497. var set = function (v) {
  498. value = v;
  499. };
  500. var clone = function () {
  501. return Cell(get());
  502. };
  503. return {
  504. get: get,
  505. set: set,
  506. clone: clone
  507. };
  508. };
  509. var findTextByValue = function (value, catalog) {
  510. return findMap(catalog, function (item) {
  511. return Option.some(item).filter(function (i) {
  512. return i.value === value;
  513. });
  514. });
  515. };
  516. var getDelta = function (persistentText, fieldName, catalog, data) {
  517. var value = data[fieldName];
  518. var hasPersistentText = persistentText.length > 0;
  519. return value !== undefined ? findTextByValue(value, catalog).map(function (i) {
  520. return {
  521. url: {
  522. value: i.value,
  523. meta: {
  524. text: hasPersistentText ? persistentText : i.text,
  525. attach: noop
  526. }
  527. },
  528. text: hasPersistentText ? persistentText : i.text
  529. };
  530. }) : Option.none();
  531. };
  532. var findCatalog = function (settings, fieldName) {
  533. if (fieldName === 'link') {
  534. return settings.catalogs.link;
  535. } else if (fieldName === 'anchor') {
  536. return settings.catalogs.anchor;
  537. } else {
  538. return Option.none();
  539. }
  540. };
  541. var init = function (initialData, linkSettings) {
  542. var persistentText = Cell(initialData.text);
  543. var onUrlChange = function (data) {
  544. if (persistentText.get().length <= 0) {
  545. var urlText = data.url.meta.text !== undefined ? data.url.meta.text : data.url.value;
  546. return Option.some({ text: urlText });
  547. } else {
  548. return Option.none();
  549. }
  550. };
  551. var onCatalogChange = function (data, change) {
  552. var catalog = findCatalog(linkSettings, change.name).getOr([]);
  553. return getDelta(persistentText.get(), change.name, catalog, data);
  554. };
  555. var onChange = function (getData, change) {
  556. if (change.name === 'url') {
  557. return onUrlChange(getData());
  558. } else if (contains([
  559. 'anchor',
  560. 'link'
  561. ], change.name)) {
  562. return onCatalogChange(getData(), change);
  563. } else if (change.name === 'text') {
  564. persistentText.set(getData().text);
  565. return Option.none();
  566. } else {
  567. return Option.none();
  568. }
  569. };
  570. return { onChange: onChange };
  571. };
  572. var DialogChanges = {
  573. init: init,
  574. getDelta: getDelta
  575. };
  576. var __assign = function () {
  577. __assign = Object.assign || function __assign(t) {
  578. for (var s, i = 1, n = arguments.length; i < n; i++) {
  579. s = arguments[i];
  580. for (var p in s)
  581. if (Object.prototype.hasOwnProperty.call(s, p))
  582. t[p] = s[p];
  583. }
  584. return t;
  585. };
  586. return __assign.apply(this, arguments);
  587. };
  588. var exports$1 = {}, module = { exports: exports$1 };
  589. (function (define, exports, module, require) {
  590. (function (f) {
  591. if (typeof exports === 'object' && typeof module !== 'undefined') {
  592. module.exports = f();
  593. } else if (typeof define === 'function' && define.amd) {
  594. define([], f);
  595. } else {
  596. var g;
  597. if (typeof window !== 'undefined') {
  598. g = window;
  599. } else if (typeof global !== 'undefined') {
  600. g = global;
  601. } else if (typeof self !== 'undefined') {
  602. g = self;
  603. } else {
  604. g = this;
  605. }
  606. g.EphoxContactWrapper = f();
  607. }
  608. }(function () {
  609. return function () {
  610. function r(e, n, t) {
  611. function o(i, f) {
  612. if (!n[i]) {
  613. if (!e[i]) {
  614. var c = 'function' == typeof require && require;
  615. if (!f && c)
  616. return c(i, !0);
  617. if (u)
  618. return u(i, !0);
  619. var a = new Error('Cannot find module \'' + i + '\'');
  620. throw a.code = 'MODULE_NOT_FOUND', a;
  621. }
  622. var p = n[i] = { exports: {} };
  623. e[i][0].call(p.exports, function (r) {
  624. var n = e[i][1][r];
  625. return o(n || r);
  626. }, p, p.exports, r, e, n, t);
  627. }
  628. return n[i].exports;
  629. }
  630. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  631. o(t[i]);
  632. return o;
  633. }
  634. return r;
  635. }()({
  636. 1: [
  637. function (require, module, exports) {
  638. var process = module.exports = {};
  639. var cachedSetTimeout;
  640. var cachedClearTimeout;
  641. function defaultSetTimout() {
  642. throw new Error('setTimeout has not been defined');
  643. }
  644. function defaultClearTimeout() {
  645. throw new Error('clearTimeout has not been defined');
  646. }
  647. (function () {
  648. try {
  649. if (typeof setTimeout === 'function') {
  650. cachedSetTimeout = setTimeout;
  651. } else {
  652. cachedSetTimeout = defaultSetTimout;
  653. }
  654. } catch (e) {
  655. cachedSetTimeout = defaultSetTimout;
  656. }
  657. try {
  658. if (typeof clearTimeout === 'function') {
  659. cachedClearTimeout = clearTimeout;
  660. } else {
  661. cachedClearTimeout = defaultClearTimeout;
  662. }
  663. } catch (e) {
  664. cachedClearTimeout = defaultClearTimeout;
  665. }
  666. }());
  667. function runTimeout(fun) {
  668. if (cachedSetTimeout === setTimeout) {
  669. return setTimeout(fun, 0);
  670. }
  671. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  672. cachedSetTimeout = setTimeout;
  673. return setTimeout(fun, 0);
  674. }
  675. try {
  676. return cachedSetTimeout(fun, 0);
  677. } catch (e) {
  678. try {
  679. return cachedSetTimeout.call(null, fun, 0);
  680. } catch (e) {
  681. return cachedSetTimeout.call(this, fun, 0);
  682. }
  683. }
  684. }
  685. function runClearTimeout(marker) {
  686. if (cachedClearTimeout === clearTimeout) {
  687. return clearTimeout(marker);
  688. }
  689. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  690. cachedClearTimeout = clearTimeout;
  691. return clearTimeout(marker);
  692. }
  693. try {
  694. return cachedClearTimeout(marker);
  695. } catch (e) {
  696. try {
  697. return cachedClearTimeout.call(null, marker);
  698. } catch (e) {
  699. return cachedClearTimeout.call(this, marker);
  700. }
  701. }
  702. }
  703. var queue = [];
  704. var draining = false;
  705. var currentQueue;
  706. var queueIndex = -1;
  707. function cleanUpNextTick() {
  708. if (!draining || !currentQueue) {
  709. return;
  710. }
  711. draining = false;
  712. if (currentQueue.length) {
  713. queue = currentQueue.concat(queue);
  714. } else {
  715. queueIndex = -1;
  716. }
  717. if (queue.length) {
  718. drainQueue();
  719. }
  720. }
  721. function drainQueue() {
  722. if (draining) {
  723. return;
  724. }
  725. var timeout = runTimeout(cleanUpNextTick);
  726. draining = true;
  727. var len = queue.length;
  728. while (len) {
  729. currentQueue = queue;
  730. queue = [];
  731. while (++queueIndex < len) {
  732. if (currentQueue) {
  733. currentQueue[queueIndex].run();
  734. }
  735. }
  736. queueIndex = -1;
  737. len = queue.length;
  738. }
  739. currentQueue = null;
  740. draining = false;
  741. runClearTimeout(timeout);
  742. }
  743. process.nextTick = function (fun) {
  744. var args = new Array(arguments.length - 1);
  745. if (arguments.length > 1) {
  746. for (var i = 1; i < arguments.length; i++) {
  747. args[i - 1] = arguments[i];
  748. }
  749. }
  750. queue.push(new Item(fun, args));
  751. if (queue.length === 1 && !draining) {
  752. runTimeout(drainQueue);
  753. }
  754. };
  755. function Item(fun, array) {
  756. this.fun = fun;
  757. this.array = array;
  758. }
  759. Item.prototype.run = function () {
  760. this.fun.apply(null, this.array);
  761. };
  762. process.title = 'browser';
  763. process.browser = true;
  764. process.env = {};
  765. process.argv = [];
  766. process.version = '';
  767. process.versions = {};
  768. function noop() {
  769. }
  770. process.on = noop;
  771. process.addListener = noop;
  772. process.once = noop;
  773. process.off = noop;
  774. process.removeListener = noop;
  775. process.removeAllListeners = noop;
  776. process.emit = noop;
  777. process.prependListener = noop;
  778. process.prependOnceListener = noop;
  779. process.listeners = function (name) {
  780. return [];
  781. };
  782. process.binding = function (name) {
  783. throw new Error('process.binding is not supported');
  784. };
  785. process.cwd = function () {
  786. return '/';
  787. };
  788. process.chdir = function (dir) {
  789. throw new Error('process.chdir is not supported');
  790. };
  791. process.umask = function () {
  792. return 0;
  793. };
  794. },
  795. {}
  796. ],
  797. 2: [
  798. function (require, module, exports) {
  799. (function (setImmediate) {
  800. (function (root) {
  801. var setTimeoutFunc = setTimeout;
  802. function noop() {
  803. }
  804. function bind(fn, thisArg) {
  805. return function () {
  806. fn.apply(thisArg, arguments);
  807. };
  808. }
  809. function Promise(fn) {
  810. if (typeof this !== 'object')
  811. throw new TypeError('Promises must be constructed via new');
  812. if (typeof fn !== 'function')
  813. throw new TypeError('not a function');
  814. this._state = 0;
  815. this._handled = false;
  816. this._value = undefined;
  817. this._deferreds = [];
  818. doResolve(fn, this);
  819. }
  820. function handle(self, deferred) {
  821. while (self._state === 3) {
  822. self = self._value;
  823. }
  824. if (self._state === 0) {
  825. self._deferreds.push(deferred);
  826. return;
  827. }
  828. self._handled = true;
  829. Promise._immediateFn(function () {
  830. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  831. if (cb === null) {
  832. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  833. return;
  834. }
  835. var ret;
  836. try {
  837. ret = cb(self._value);
  838. } catch (e) {
  839. reject(deferred.promise, e);
  840. return;
  841. }
  842. resolve(deferred.promise, ret);
  843. });
  844. }
  845. function resolve(self, newValue) {
  846. try {
  847. if (newValue === self)
  848. throw new TypeError('A promise cannot be resolved with itself.');
  849. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  850. var then = newValue.then;
  851. if (newValue instanceof Promise) {
  852. self._state = 3;
  853. self._value = newValue;
  854. finale(self);
  855. return;
  856. } else if (typeof then === 'function') {
  857. doResolve(bind(then, newValue), self);
  858. return;
  859. }
  860. }
  861. self._state = 1;
  862. self._value = newValue;
  863. finale(self);
  864. } catch (e) {
  865. reject(self, e);
  866. }
  867. }
  868. function reject(self, newValue) {
  869. self._state = 2;
  870. self._value = newValue;
  871. finale(self);
  872. }
  873. function finale(self) {
  874. if (self._state === 2 && self._deferreds.length === 0) {
  875. Promise._immediateFn(function () {
  876. if (!self._handled) {
  877. Promise._unhandledRejectionFn(self._value);
  878. }
  879. });
  880. }
  881. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  882. handle(self, self._deferreds[i]);
  883. }
  884. self._deferreds = null;
  885. }
  886. function Handler(onFulfilled, onRejected, promise) {
  887. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  888. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  889. this.promise = promise;
  890. }
  891. function doResolve(fn, self) {
  892. var done = false;
  893. try {
  894. fn(function (value) {
  895. if (done)
  896. return;
  897. done = true;
  898. resolve(self, value);
  899. }, function (reason) {
  900. if (done)
  901. return;
  902. done = true;
  903. reject(self, reason);
  904. });
  905. } catch (ex) {
  906. if (done)
  907. return;
  908. done = true;
  909. reject(self, ex);
  910. }
  911. }
  912. Promise.prototype['catch'] = function (onRejected) {
  913. return this.then(null, onRejected);
  914. };
  915. Promise.prototype.then = function (onFulfilled, onRejected) {
  916. var prom = new this.constructor(noop);
  917. handle(this, new Handler(onFulfilled, onRejected, prom));
  918. return prom;
  919. };
  920. Promise.all = function (arr) {
  921. var args = Array.prototype.slice.call(arr);
  922. return new Promise(function (resolve, reject) {
  923. if (args.length === 0)
  924. return resolve([]);
  925. var remaining = args.length;
  926. function res(i, val) {
  927. try {
  928. if (val && (typeof val === 'object' || typeof val === 'function')) {
  929. var then = val.then;
  930. if (typeof then === 'function') {
  931. then.call(val, function (val) {
  932. res(i, val);
  933. }, reject);
  934. return;
  935. }
  936. }
  937. args[i] = val;
  938. if (--remaining === 0) {
  939. resolve(args);
  940. }
  941. } catch (ex) {
  942. reject(ex);
  943. }
  944. }
  945. for (var i = 0; i < args.length; i++) {
  946. res(i, args[i]);
  947. }
  948. });
  949. };
  950. Promise.resolve = function (value) {
  951. if (value && typeof value === 'object' && value.constructor === Promise) {
  952. return value;
  953. }
  954. return new Promise(function (resolve) {
  955. resolve(value);
  956. });
  957. };
  958. Promise.reject = function (value) {
  959. return new Promise(function (resolve, reject) {
  960. reject(value);
  961. });
  962. };
  963. Promise.race = function (values) {
  964. return new Promise(function (resolve, reject) {
  965. for (var i = 0, len = values.length; i < len; i++) {
  966. values[i].then(resolve, reject);
  967. }
  968. });
  969. };
  970. Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
  971. setImmediate(fn);
  972. } : function (fn) {
  973. setTimeoutFunc(fn, 0);
  974. };
  975. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  976. if (typeof console !== 'undefined' && console) {
  977. console.warn('Possible Unhandled Promise Rejection:', err);
  978. }
  979. };
  980. Promise._setImmediateFn = function _setImmediateFn(fn) {
  981. Promise._immediateFn = fn;
  982. };
  983. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  984. Promise._unhandledRejectionFn = fn;
  985. };
  986. if (typeof module !== 'undefined' && module.exports) {
  987. module.exports = Promise;
  988. } else if (!root.Promise) {
  989. root.Promise = Promise;
  990. }
  991. }(this));
  992. }.call(this, require('timers').setImmediate));
  993. },
  994. { 'timers': 3 }
  995. ],
  996. 3: [
  997. function (require, module, exports) {
  998. (function (setImmediate, clearImmediate) {
  999. var nextTick = require('process/browser.js').nextTick;
  1000. var apply = Function.prototype.apply;
  1001. var slice = Array.prototype.slice;
  1002. var immediateIds = {};
  1003. var nextImmediateId = 0;
  1004. exports.setTimeout = function () {
  1005. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  1006. };
  1007. exports.setInterval = function () {
  1008. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  1009. };
  1010. exports.clearTimeout = exports.clearInterval = function (timeout) {
  1011. timeout.close();
  1012. };
  1013. function Timeout(id, clearFn) {
  1014. this._id = id;
  1015. this._clearFn = clearFn;
  1016. }
  1017. Timeout.prototype.unref = Timeout.prototype.ref = function () {
  1018. };
  1019. Timeout.prototype.close = function () {
  1020. this._clearFn.call(window, this._id);
  1021. };
  1022. exports.enroll = function (item, msecs) {
  1023. clearTimeout(item._idleTimeoutId);
  1024. item._idleTimeout = msecs;
  1025. };
  1026. exports.unenroll = function (item) {
  1027. clearTimeout(item._idleTimeoutId);
  1028. item._idleTimeout = -1;
  1029. };
  1030. exports._unrefActive = exports.active = function (item) {
  1031. clearTimeout(item._idleTimeoutId);
  1032. var msecs = item._idleTimeout;
  1033. if (msecs >= 0) {
  1034. item._idleTimeoutId = setTimeout(function onTimeout() {
  1035. if (item._onTimeout)
  1036. item._onTimeout();
  1037. }, msecs);
  1038. }
  1039. };
  1040. exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
  1041. var id = nextImmediateId++;
  1042. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  1043. immediateIds[id] = true;
  1044. nextTick(function onNextTick() {
  1045. if (immediateIds[id]) {
  1046. if (args) {
  1047. fn.apply(null, args);
  1048. } else {
  1049. fn.call(null);
  1050. }
  1051. exports.clearImmediate(id);
  1052. }
  1053. });
  1054. return id;
  1055. };
  1056. exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
  1057. delete immediateIds[id];
  1058. };
  1059. }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
  1060. },
  1061. {
  1062. 'process/browser.js': 1,
  1063. 'timers': 3
  1064. }
  1065. ],
  1066. 4: [
  1067. function (require, module, exports) {
  1068. var promisePolyfill = require('promise-polyfill');
  1069. var Global = function () {
  1070. if (typeof window !== 'undefined') {
  1071. return window;
  1072. } else {
  1073. return Function('return this;')();
  1074. }
  1075. }();
  1076. module.exports = { boltExport: Global.Promise || promisePolyfill };
  1077. },
  1078. { 'promise-polyfill': 2 }
  1079. ]
  1080. }, {}, [4])(4);
  1081. }));
  1082. }(undefined, exports$1, module, undefined));
  1083. var Promise = module.exports.boltExport;
  1084. var nu = function (baseFn) {
  1085. var data = Option.none();
  1086. var callbacks = [];
  1087. var map = function (f) {
  1088. return nu(function (nCallback) {
  1089. get(function (data) {
  1090. nCallback(f(data));
  1091. });
  1092. });
  1093. };
  1094. var get = function (nCallback) {
  1095. if (isReady()) {
  1096. call(nCallback);
  1097. } else {
  1098. callbacks.push(nCallback);
  1099. }
  1100. };
  1101. var set = function (x) {
  1102. data = Option.some(x);
  1103. run(callbacks);
  1104. callbacks = [];
  1105. };
  1106. var isReady = function () {
  1107. return data.isSome();
  1108. };
  1109. var run = function (cbs) {
  1110. each(cbs, call);
  1111. };
  1112. var call = function (cb) {
  1113. data.each(function (x) {
  1114. domGlobals.setTimeout(function () {
  1115. cb(x);
  1116. }, 0);
  1117. });
  1118. };
  1119. baseFn(set);
  1120. return {
  1121. get: get,
  1122. map: map,
  1123. isReady: isReady
  1124. };
  1125. };
  1126. var pure = function (a) {
  1127. return nu(function (callback) {
  1128. callback(a);
  1129. });
  1130. };
  1131. var LazyValue = {
  1132. nu: nu,
  1133. pure: pure
  1134. };
  1135. var errorReporter = function (err) {
  1136. domGlobals.setTimeout(function () {
  1137. throw err;
  1138. }, 0);
  1139. };
  1140. var make = function (run) {
  1141. var get = function (callback) {
  1142. run().then(callback, errorReporter);
  1143. };
  1144. var map = function (fab) {
  1145. return make(function () {
  1146. return run().then(fab);
  1147. });
  1148. };
  1149. var bind = function (aFutureB) {
  1150. return make(function () {
  1151. return run().then(function (v) {
  1152. return aFutureB(v).toPromise();
  1153. });
  1154. });
  1155. };
  1156. var anonBind = function (futureB) {
  1157. return make(function () {
  1158. return run().then(function () {
  1159. return futureB.toPromise();
  1160. });
  1161. });
  1162. };
  1163. var toLazy = function () {
  1164. return LazyValue.nu(get);
  1165. };
  1166. var toCached = function () {
  1167. var cache = null;
  1168. return make(function () {
  1169. if (cache === null) {
  1170. cache = run();
  1171. }
  1172. return cache;
  1173. });
  1174. };
  1175. var toPromise = run;
  1176. return {
  1177. map: map,
  1178. bind: bind,
  1179. anonBind: anonBind,
  1180. toLazy: toLazy,
  1181. toCached: toCached,
  1182. toPromise: toPromise,
  1183. get: get
  1184. };
  1185. };
  1186. var nu$1 = function (baseFn) {
  1187. return make(function () {
  1188. return new Promise(baseFn);
  1189. });
  1190. };
  1191. var pure$1 = function (a) {
  1192. return make(function () {
  1193. return Promise.resolve(a);
  1194. });
  1195. };
  1196. var Future = {
  1197. nu: nu$1,
  1198. pure: pure$1
  1199. };
  1200. var global$4 = tinymce.util.Tools.resolve('tinymce.util.Delay');
  1201. var delayedConfirm = function (editor, message, callback) {
  1202. var rng = editor.selection.getRng();
  1203. global$4.setEditorTimeout(editor, function () {
  1204. editor.windowManager.confirm(message, function (state) {
  1205. editor.selection.setRng(rng);
  1206. callback(state);
  1207. });
  1208. });
  1209. };
  1210. var tryEmailTransform = function (data) {
  1211. var url = data.href;
  1212. var suggestMailTo = url.indexOf('@') > 0 && url.indexOf('//') === -1 && url.indexOf('mailto:') === -1;
  1213. return suggestMailTo ? Option.some({
  1214. message: 'The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?',
  1215. preprocess: function (oldData) {
  1216. return __assign(__assign({}, oldData), { href: 'mailto:' + url });
  1217. }
  1218. }) : Option.none();
  1219. };
  1220. var tryProtocolTransform = function (assumeExternalTargets) {
  1221. return function (data) {
  1222. var url = data.href;
  1223. var suggestProtocol = assumeExternalTargets === 1 && !Utils.hasProtocol(url) || assumeExternalTargets === 0 && /^\s*www[\.|\d\.]/i.test(url);
  1224. return suggestProtocol ? Option.some({
  1225. message: 'The URL you entered seems to be an external link. Do you want to add the required http:// prefix?',
  1226. preprocess: function (oldData) {
  1227. return __assign(__assign({}, oldData), { href: 'http://' + url });
  1228. }
  1229. }) : Option.none();
  1230. };
  1231. };
  1232. var preprocess = function (editor, assumeExternalTargets, data) {
  1233. return findMap([
  1234. tryEmailTransform,
  1235. tryProtocolTransform(assumeExternalTargets)
  1236. ], function (f) {
  1237. return f(data);
  1238. }).fold(function () {
  1239. return Future.pure(data);
  1240. }, function (transform) {
  1241. return Future.nu(function (callback) {
  1242. delayedConfirm(editor, transform.message, function (state) {
  1243. callback(state ? transform.preprocess(data) : data);
  1244. });
  1245. });
  1246. });
  1247. };
  1248. var DialogConfirms = { preprocess: preprocess };
  1249. var getAnchors = function (editor) {
  1250. var anchorNodes = editor.dom.select('a:not([href])');
  1251. var anchors = bind(anchorNodes, function (anchor) {
  1252. var id = anchor.name || anchor.id;
  1253. return id ? [{
  1254. text: id,
  1255. value: '#' + id
  1256. }] : [];
  1257. });
  1258. return anchors.length > 0 ? Option.some([{
  1259. text: 'None',
  1260. value: ''
  1261. }].concat(anchors)) : Option.none();
  1262. };
  1263. var AnchorListOptions = { getAnchors: getAnchors };
  1264. var getClasses = function (editor) {
  1265. var list = Settings.getLinkClassList(editor);
  1266. if (list.length > 0) {
  1267. return ListOptions.sanitize(list);
  1268. }
  1269. return Option.none();
  1270. };
  1271. var ClassListOptions = { getClasses: getClasses };
  1272. var global$5 = tinymce.util.Tools.resolve('tinymce.util.XHR');
  1273. var parseJson = function (text) {
  1274. try {
  1275. return Option.some(JSON.parse(text));
  1276. } catch (err) {
  1277. return Option.none();
  1278. }
  1279. };
  1280. var getLinks = function (editor) {
  1281. var extractor = function (item) {
  1282. return editor.convertURL(item.value || item.url, 'href');
  1283. };
  1284. var linkList = Settings.getLinkList(editor);
  1285. return Future.nu(function (callback) {
  1286. if (isString(linkList)) {
  1287. global$5.send({
  1288. url: linkList,
  1289. success: function (text) {
  1290. return callback(parseJson(text));
  1291. },
  1292. error: function (_) {
  1293. return callback(Option.none());
  1294. }
  1295. });
  1296. } else if (isFunction(linkList)) {
  1297. linkList(function (output) {
  1298. return callback(Option.some(output));
  1299. });
  1300. } else {
  1301. callback(Option.from(linkList));
  1302. }
  1303. }).map(function (optItems) {
  1304. return optItems.bind(ListOptions.sanitizeWith(extractor)).map(function (items) {
  1305. if (items.length > 0) {
  1306. return [{
  1307. text: 'None',
  1308. value: ''
  1309. }].concat(items);
  1310. } else {
  1311. return items;
  1312. }
  1313. });
  1314. });
  1315. };
  1316. var LinkListOptions = { getLinks: getLinks };
  1317. var getRels = function (editor, initialTarget) {
  1318. var list = Settings.getRelList(editor);
  1319. if (list.length > 0) {
  1320. var isTargetBlank_1 = initialTarget.is('_blank');
  1321. var enforceSafe = Settings.allowUnsafeLinkTarget(editor) === false;
  1322. var safeRelExtractor = function (item) {
  1323. return Utils.applyRelTargetRules(ListOptions.getValue(item), isTargetBlank_1);
  1324. };
  1325. var sanitizer = enforceSafe ? ListOptions.sanitizeWith(safeRelExtractor) : ListOptions.sanitize;
  1326. return sanitizer(list);
  1327. }
  1328. return Option.none();
  1329. };
  1330. var RelOptions = { getRels: getRels };
  1331. var fallbacks = [
  1332. {
  1333. text: 'Current window',
  1334. value: ''
  1335. },
  1336. {
  1337. text: 'New window',
  1338. value: '_blank'
  1339. }
  1340. ];
  1341. var getTargets = function (editor) {
  1342. var list = Settings.getTargetList(editor);
  1343. if (isArray(list)) {
  1344. return ListOptions.sanitize(list).orThunk(function () {
  1345. return Option.some(fallbacks);
  1346. });
  1347. } else if (list === false) {
  1348. return Option.none();
  1349. }
  1350. return Option.some(fallbacks);
  1351. };
  1352. var TargetOptions = { getTargets: getTargets };
  1353. var nonEmptyAttr = function (dom, elem, name) {
  1354. var val = dom.getAttrib(elem, name);
  1355. return val !== null && val.length > 0 ? Option.some(val) : Option.none();
  1356. };
  1357. var extractFromAnchor = function (editor, anchor) {
  1358. var dom = editor.dom;
  1359. var onlyText = Utils.isOnlyTextSelected(editor.selection.getContent());
  1360. var text = onlyText ? Option.some(Utils.getAnchorText(editor.selection, anchor)) : Option.none();
  1361. var url = anchor ? Option.some(dom.getAttrib(anchor, 'href')) : Option.none();
  1362. var target = anchor ? Option.from(dom.getAttrib(anchor, 'target')) : Option.none();
  1363. var rel = nonEmptyAttr(dom, anchor, 'rel');
  1364. var linkClass = nonEmptyAttr(dom, anchor, 'class');
  1365. var title = nonEmptyAttr(dom, anchor, 'title');
  1366. return {
  1367. url: url,
  1368. text: text,
  1369. title: title,
  1370. target: target,
  1371. rel: rel,
  1372. linkClass: linkClass
  1373. };
  1374. };
  1375. var collect = function (editor, linkNode) {
  1376. return LinkListOptions.getLinks(editor).map(function (links) {
  1377. var anchor = extractFromAnchor(editor, linkNode);
  1378. return {
  1379. anchor: anchor,
  1380. catalogs: {
  1381. targets: TargetOptions.getTargets(editor),
  1382. rels: RelOptions.getRels(editor, anchor.target),
  1383. classes: ClassListOptions.getClasses(editor),
  1384. anchor: AnchorListOptions.getAnchors(editor),
  1385. link: links
  1386. },
  1387. optNode: Option.from(linkNode),
  1388. flags: { titleEnabled: Settings.shouldShowLinkTitle(editor) }
  1389. };
  1390. });
  1391. };
  1392. var DialogInfo = { collect: collect };
  1393. var handleSubmit = function (editor, info, assumeExternalTargets) {
  1394. return function (api) {
  1395. var data = api.getData();
  1396. if (!data.url.value) {
  1397. Utils.unlink(editor);
  1398. api.close();
  1399. return;
  1400. }
  1401. var getChangedValue = function (key) {
  1402. return Option.from(data[key]).filter(function (value) {
  1403. return !info.anchor[key].is(value);
  1404. });
  1405. };
  1406. var changedData = {
  1407. href: data.url.value,
  1408. text: getChangedValue('text'),
  1409. target: getChangedValue('target'),
  1410. rel: getChangedValue('rel'),
  1411. class: getChangedValue('linkClass'),
  1412. title: getChangedValue('title')
  1413. };
  1414. var attachState = {
  1415. href: data.url.value,
  1416. attach: data.url.meta !== undefined && data.url.meta.attach ? data.url.meta.attach : function () {
  1417. }
  1418. };
  1419. DialogConfirms.preprocess(editor, assumeExternalTargets, changedData).get(function (pData) {
  1420. Utils.link(editor, attachState, pData);
  1421. });
  1422. api.close();
  1423. };
  1424. };
  1425. var collectData = function (editor) {
  1426. var anchorNode = Utils.getAnchorElement(editor);
  1427. return DialogInfo.collect(editor, anchorNode);
  1428. };
  1429. var getInitialData = function (info, defaultTarget) {
  1430. return {
  1431. url: {
  1432. value: info.anchor.url.getOr(''),
  1433. meta: {
  1434. attach: function () {
  1435. },
  1436. text: info.anchor.url.fold(function () {
  1437. return '';
  1438. }, function () {
  1439. return info.anchor.text.getOr('');
  1440. }),
  1441. original: { value: info.anchor.url.getOr('') }
  1442. }
  1443. },
  1444. text: info.anchor.text.getOr(''),
  1445. title: info.anchor.title.getOr(''),
  1446. anchor: info.anchor.url.getOr(''),
  1447. link: info.anchor.url.getOr(''),
  1448. rel: info.anchor.rel.getOr(''),
  1449. target: info.anchor.target.or(defaultTarget).getOr(''),
  1450. linkClass: info.anchor.linkClass.getOr('')
  1451. };
  1452. };
  1453. var makeDialog = function (settings, onSubmit, editor) {
  1454. var urlInput = [{
  1455. name: 'url',
  1456. type: 'urlinput',
  1457. filetype: 'file',
  1458. label: 'URL'
  1459. }];
  1460. var displayText = settings.anchor.text.map(function () {
  1461. return {
  1462. name: 'text',
  1463. type: 'input',
  1464. label: 'Text to display'
  1465. };
  1466. }).toArray();
  1467. var titleText = settings.flags.titleEnabled ? [{
  1468. name: 'title',
  1469. type: 'input',
  1470. label: 'Title'
  1471. }] : [];
  1472. var defaultTarget = Option.from(Settings.getDefaultLinkTarget(editor));
  1473. var initialData = getInitialData(settings, defaultTarget);
  1474. var dialogDelta = DialogChanges.init(initialData, settings);
  1475. var catalogs = settings.catalogs;
  1476. var body = {
  1477. type: 'panel',
  1478. items: flatten([
  1479. urlInput,
  1480. displayText,
  1481. titleText,
  1482. cat([
  1483. catalogs.anchor.map(ListOptions.createUi('anchor', 'Anchors')),
  1484. catalogs.rels.map(ListOptions.createUi('rel', 'Rel')),
  1485. catalogs.targets.map(ListOptions.createUi('target', 'Open link in...')),
  1486. catalogs.link.map(ListOptions.createUi('link', 'Link list')),
  1487. catalogs.classes.map(ListOptions.createUi('linkClass', 'Class'))
  1488. ])
  1489. ])
  1490. };
  1491. return {
  1492. title: 'Insert/Edit Link',
  1493. size: 'normal',
  1494. body: body,
  1495. buttons: [
  1496. {
  1497. type: 'cancel',
  1498. name: 'cancel',
  1499. text: 'Cancel'
  1500. },
  1501. {
  1502. type: 'submit',
  1503. name: 'save',
  1504. text: 'Save',
  1505. primary: true
  1506. }
  1507. ],
  1508. initialData: initialData,
  1509. onChange: function (api, _a) {
  1510. var name = _a.name;
  1511. dialogDelta.onChange(api.getData, { name: name }).each(function (newData) {
  1512. api.setData(newData);
  1513. });
  1514. },
  1515. onSubmit: onSubmit
  1516. };
  1517. };
  1518. var open$1 = function (editor) {
  1519. var data = collectData(editor);
  1520. data.map(function (info) {
  1521. var onSubmit = handleSubmit(editor, info, Settings.assumeExternalTargets(editor));
  1522. return makeDialog(info, onSubmit, editor);
  1523. }).get(function (spec) {
  1524. editor.windowManager.open(spec);
  1525. });
  1526. };
  1527. var Dialog = { open: open$1 };
  1528. var getLink = function (editor, elm) {
  1529. return editor.dom.getParent(elm, 'a[href]');
  1530. };
  1531. var getSelectedLink = function (editor) {
  1532. return getLink(editor, editor.selection.getStart());
  1533. };
  1534. var hasOnlyAltModifier = function (e) {
  1535. return e.altKey === true && e.shiftKey === false && e.ctrlKey === false && e.metaKey === false;
  1536. };
  1537. var gotoLink = function (editor, a) {
  1538. if (a) {
  1539. var href = Utils.getHref(a);
  1540. if (/^#/.test(href)) {
  1541. var targetEl = editor.$(href);
  1542. if (targetEl.length) {
  1543. editor.selection.scrollIntoView(targetEl[0], true);
  1544. }
  1545. } else {
  1546. OpenUrl.open(a.href);
  1547. }
  1548. }
  1549. };
  1550. var openDialog = function (editor) {
  1551. return function () {
  1552. Dialog.open(editor);
  1553. };
  1554. };
  1555. var gotoSelectedLink = function (editor) {
  1556. return function () {
  1557. gotoLink(editor, getSelectedLink(editor));
  1558. };
  1559. };
  1560. var leftClickedOnAHref = function (editor) {
  1561. return function (elm) {
  1562. var sel, rng, node;
  1563. if (Settings.hasContextToolbar(editor) && Utils.isLink(elm)) {
  1564. sel = editor.selection;
  1565. rng = sel.getRng();
  1566. node = rng.startContainer;
  1567. if (node.nodeType === 3 && sel.isCollapsed() && rng.startOffset > 0 && rng.startOffset < node.data.length) {
  1568. return true;
  1569. }
  1570. }
  1571. return false;
  1572. };
  1573. };
  1574. var setupGotoLinks = function (editor) {
  1575. editor.on('click', function (e) {
  1576. var link = getLink(editor, e.target);
  1577. if (link && global$2.metaKeyPressed(e)) {
  1578. e.preventDefault();
  1579. gotoLink(editor, link);
  1580. }
  1581. });
  1582. editor.on('keydown', function (e) {
  1583. var link = getSelectedLink(editor);
  1584. if (link && e.keyCode === 13 && hasOnlyAltModifier(e)) {
  1585. e.preventDefault();
  1586. gotoLink(editor, link);
  1587. }
  1588. });
  1589. };
  1590. var toggleActiveState = function (editor) {
  1591. return function (api) {
  1592. var nodeChangeHandler = function (e) {
  1593. return api.setActive(!editor.readonly && !!Utils.getAnchorElement(editor, e.element));
  1594. };
  1595. editor.on('NodeChange', nodeChangeHandler);
  1596. return function () {
  1597. return editor.off('NodeChange', nodeChangeHandler);
  1598. };
  1599. };
  1600. };
  1601. var toggleEnabledState = function (editor) {
  1602. return function (api) {
  1603. api.setDisabled(!Utils.hasLinks(editor.dom.getParents(editor.selection.getStart())));
  1604. var nodeChangeHandler = function (e) {
  1605. return api.setDisabled(!Utils.hasLinks(e.parents));
  1606. };
  1607. editor.on('NodeChange', nodeChangeHandler);
  1608. return function () {
  1609. return editor.off('NodeChange', nodeChangeHandler);
  1610. };
  1611. };
  1612. };
  1613. var Actions = {
  1614. openDialog: openDialog,
  1615. gotoSelectedLink: gotoSelectedLink,
  1616. leftClickedOnAHref: leftClickedOnAHref,
  1617. setupGotoLinks: setupGotoLinks,
  1618. toggleActiveState: toggleActiveState,
  1619. toggleEnabledState: toggleEnabledState
  1620. };
  1621. var register = function (editor) {
  1622. editor.addCommand('mceLink', function () {
  1623. if (Settings.useQuickLink(editor)) {
  1624. editor.fire('contexttoolbar-show', { toolbarKey: 'quicklink' });
  1625. } else {
  1626. Actions.openDialog(editor)();
  1627. }
  1628. });
  1629. };
  1630. var Commands = { register: register };
  1631. var setup = function (editor) {
  1632. editor.addShortcut('Meta+K', '', function () {
  1633. editor.execCommand('mceLink');
  1634. });
  1635. };
  1636. var Keyboard = { setup: setup };
  1637. var setupButtons = function (editor) {
  1638. editor.ui.registry.addToggleButton('link', {
  1639. icon: 'link',
  1640. tooltip: 'Insert/edit link',
  1641. onAction: Actions.openDialog(editor),
  1642. onSetup: Actions.toggleActiveState(editor)
  1643. });
  1644. editor.ui.registry.addButton('openlink', {
  1645. icon: 'new-tab',
  1646. tooltip: 'Open link',
  1647. onAction: Actions.gotoSelectedLink(editor),
  1648. onSetup: Actions.toggleEnabledState(editor)
  1649. });
  1650. editor.ui.registry.addButton('unlink', {
  1651. icon: 'unlink',
  1652. tooltip: 'Remove link',
  1653. onAction: function () {
  1654. return Utils.unlink(editor);
  1655. },
  1656. onSetup: Actions.toggleEnabledState(editor)
  1657. });
  1658. };
  1659. var setupMenuItems = function (editor) {
  1660. editor.ui.registry.addMenuItem('openlink', {
  1661. text: 'Open link',
  1662. icon: 'new-tab',
  1663. onAction: Actions.gotoSelectedLink(editor),
  1664. onSetup: Actions.toggleEnabledState(editor)
  1665. });
  1666. editor.ui.registry.addMenuItem('link', {
  1667. icon: 'link',
  1668. text: 'Link...',
  1669. shortcut: 'Meta+K',
  1670. onAction: Actions.openDialog(editor)
  1671. });
  1672. editor.ui.registry.addMenuItem('unlink', {
  1673. icon: 'unlink',
  1674. text: 'Remove link',
  1675. onAction: function () {
  1676. return Utils.unlink(editor);
  1677. },
  1678. onSetup: Actions.toggleEnabledState(editor)
  1679. });
  1680. };
  1681. var setupContextMenu = function (editor) {
  1682. var inLink = 'link unlink openlink';
  1683. var noLink = 'link';
  1684. editor.ui.registry.addContextMenu('link', {
  1685. update: function (element) {
  1686. return Utils.hasLinks(editor.dom.getParents(element, 'a')) ? inLink : noLink;
  1687. }
  1688. });
  1689. };
  1690. var setupContextToolbars = function (editor) {
  1691. var collapseSelectionToEnd = function (editor) {
  1692. editor.selection.collapse(false);
  1693. };
  1694. var onSetupLink = function (buttonApi) {
  1695. var node = editor.selection.getNode();
  1696. buttonApi.setDisabled(!Utils.getAnchorElement(editor, node));
  1697. return function () {
  1698. };
  1699. };
  1700. editor.ui.registry.addContextForm('quicklink', {
  1701. launch: {
  1702. type: 'contextformtogglebutton',
  1703. icon: 'link',
  1704. tooltip: 'Link',
  1705. onSetup: Actions.toggleActiveState(editor)
  1706. },
  1707. label: 'Link',
  1708. predicate: function (node) {
  1709. return !!Utils.getAnchorElement(editor, node) && Settings.hasContextToolbar(editor);
  1710. },
  1711. initValue: function () {
  1712. var elm = Utils.getAnchorElement(editor);
  1713. return !!elm ? Utils.getHref(elm) : '';
  1714. },
  1715. commands: [
  1716. {
  1717. type: 'contextformtogglebutton',
  1718. icon: 'link',
  1719. tooltip: 'Link',
  1720. primary: true,
  1721. onSetup: function (buttonApi) {
  1722. var node = editor.selection.getNode();
  1723. buttonApi.setActive(!!Utils.getAnchorElement(editor, node));
  1724. return Actions.toggleActiveState(editor)(buttonApi);
  1725. },
  1726. onAction: function (formApi) {
  1727. var anchor = Utils.getAnchorElement(editor);
  1728. var value = formApi.getValue();
  1729. if (!anchor) {
  1730. var attachState = {
  1731. href: value,
  1732. attach: function () {
  1733. }
  1734. };
  1735. var onlyText = Utils.isOnlyTextSelected(editor.selection.getContent());
  1736. var text = onlyText ? Option.some(Utils.getAnchorText(editor.selection, anchor)).filter(function (t) {
  1737. return t.length > 0;
  1738. }).or(Option.from(value)) : Option.none();
  1739. Utils.link(editor, attachState, {
  1740. href: value,
  1741. text: text,
  1742. title: Option.none(),
  1743. rel: Option.none(),
  1744. target: Option.none(),
  1745. class: Option.none()
  1746. });
  1747. formApi.hide();
  1748. } else {
  1749. editor.dom.setAttrib(anchor, 'href', value);
  1750. collapseSelectionToEnd(editor);
  1751. formApi.hide();
  1752. }
  1753. }
  1754. },
  1755. {
  1756. type: 'contextformbutton',
  1757. icon: 'unlink',
  1758. tooltip: 'Remove link',
  1759. onSetup: onSetupLink,
  1760. onAction: function (formApi) {
  1761. Utils.unlink(editor);
  1762. formApi.hide();
  1763. }
  1764. },
  1765. {
  1766. type: 'contextformbutton',
  1767. icon: 'new-tab',
  1768. tooltip: 'Open link',
  1769. onSetup: onSetupLink,
  1770. onAction: function (formApi) {
  1771. Actions.gotoSelectedLink(editor)();
  1772. formApi.hide();
  1773. }
  1774. }
  1775. ]
  1776. });
  1777. };
  1778. var Controls = {
  1779. setupButtons: setupButtons,
  1780. setupMenuItems: setupMenuItems,
  1781. setupContextMenu: setupContextMenu,
  1782. setupContextToolbars: setupContextToolbars
  1783. };
  1784. function Plugin () {
  1785. global$1.add('link', function (editor) {
  1786. Controls.setupButtons(editor);
  1787. Controls.setupMenuItems(editor);
  1788. Controls.setupContextMenu(editor);
  1789. Controls.setupContextToolbars(editor);
  1790. Actions.setupGotoLinks(editor);
  1791. Commands.register(editor);
  1792. Keyboard.setup(editor);
  1793. });
  1794. }
  1795. Plugin();
  1796. }(window));