plugin.js 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  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.3.0 (2020-05-21)
  8. */
  9. (function (domGlobals) {
  10. 'use strict';
  11. var global = 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 not = function (f) {
  20. return function (t) {
  21. return !f(t);
  22. };
  23. };
  24. var never = constant(false);
  25. var always = constant(true);
  26. var none = function () {
  27. return NONE;
  28. };
  29. var NONE = function () {
  30. var eq = function (o) {
  31. return o.isNone();
  32. };
  33. var call = function (thunk) {
  34. return thunk();
  35. };
  36. var id = function (n) {
  37. return n;
  38. };
  39. var me = {
  40. fold: function (n, _s) {
  41. return n();
  42. },
  43. is: never,
  44. isSome: never,
  45. isNone: always,
  46. getOr: id,
  47. getOrThunk: call,
  48. getOrDie: function (msg) {
  49. throw new Error(msg || 'error: getOrDie called on none.');
  50. },
  51. getOrNull: constant(null),
  52. getOrUndefined: constant(undefined),
  53. or: id,
  54. orThunk: call,
  55. map: none,
  56. each: noop,
  57. bind: none,
  58. exists: never,
  59. forall: always,
  60. filter: none,
  61. equals: eq,
  62. equals_: eq,
  63. toArray: function () {
  64. return [];
  65. },
  66. toString: constant('none()')
  67. };
  68. return me;
  69. }();
  70. var some = function (a) {
  71. var constant_a = constant(a);
  72. var self = function () {
  73. return me;
  74. };
  75. var bind = function (f) {
  76. return f(a);
  77. };
  78. var me = {
  79. fold: function (n, s) {
  80. return s(a);
  81. },
  82. is: function (v) {
  83. return a === v;
  84. },
  85. isSome: always,
  86. isNone: never,
  87. getOr: constant_a,
  88. getOrThunk: constant_a,
  89. getOrDie: constant_a,
  90. getOrNull: constant_a,
  91. getOrUndefined: constant_a,
  92. or: self,
  93. orThunk: self,
  94. map: function (f) {
  95. return some(f(a));
  96. },
  97. each: function (f) {
  98. f(a);
  99. },
  100. bind: bind,
  101. exists: bind,
  102. forall: bind,
  103. filter: function (f) {
  104. return f(a) ? me : NONE;
  105. },
  106. toArray: function () {
  107. return [a];
  108. },
  109. toString: function () {
  110. return 'some(' + a + ')';
  111. },
  112. equals: function (o) {
  113. return o.is(a);
  114. },
  115. equals_: function (o, elementEq) {
  116. return o.fold(never, function (b) {
  117. return elementEq(a, b);
  118. });
  119. }
  120. };
  121. return me;
  122. };
  123. var from = function (value) {
  124. return value === null || value === undefined ? NONE : some(value);
  125. };
  126. var Option = {
  127. some: some,
  128. none: none,
  129. from: from
  130. };
  131. var typeOf = function (x) {
  132. var t = typeof x;
  133. if (x === null) {
  134. return 'null';
  135. } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  136. return 'array';
  137. } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  138. return 'string';
  139. } else {
  140. return t;
  141. }
  142. };
  143. var isType = function (type) {
  144. return function (value) {
  145. return typeOf(value) === type;
  146. };
  147. };
  148. var isSimpleType = function (type) {
  149. return function (value) {
  150. return typeof value === type;
  151. };
  152. };
  153. var isString = isType('string');
  154. var isArray = isType('array');
  155. var isBoolean = isSimpleType('boolean');
  156. var isFunction = isSimpleType('function');
  157. var isNumber = isSimpleType('number');
  158. var nativeSlice = Array.prototype.slice;
  159. var nativePush = Array.prototype.push;
  160. var map = function (xs, f) {
  161. var len = xs.length;
  162. var r = new Array(len);
  163. for (var i = 0; i < len; i++) {
  164. var x = xs[i];
  165. r[i] = f(x, i);
  166. }
  167. return r;
  168. };
  169. var each = function (xs, f) {
  170. for (var i = 0, len = xs.length; i < len; i++) {
  171. var x = xs[i];
  172. f(x, i);
  173. }
  174. };
  175. var filter = function (xs, pred) {
  176. var r = [];
  177. for (var i = 0, len = xs.length; i < len; i++) {
  178. var x = xs[i];
  179. if (pred(x, i)) {
  180. r.push(x);
  181. }
  182. }
  183. return r;
  184. };
  185. var groupBy = function (xs, f) {
  186. if (xs.length === 0) {
  187. return [];
  188. } else {
  189. var wasType = f(xs[0]);
  190. var r = [];
  191. var group = [];
  192. for (var i = 0, len = xs.length; i < len; i++) {
  193. var x = xs[i];
  194. var type = f(x);
  195. if (type !== wasType) {
  196. r.push(group);
  197. group = [];
  198. }
  199. wasType = type;
  200. group.push(x);
  201. }
  202. if (group.length !== 0) {
  203. r.push(group);
  204. }
  205. return r;
  206. }
  207. };
  208. var foldl = function (xs, f, acc) {
  209. each(xs, function (x) {
  210. acc = f(acc, x);
  211. });
  212. return acc;
  213. };
  214. var findUntil = function (xs, pred, until) {
  215. for (var i = 0, len = xs.length; i < len; i++) {
  216. var x = xs[i];
  217. if (pred(x, i)) {
  218. return Option.some(x);
  219. } else if (until(x, i)) {
  220. break;
  221. }
  222. }
  223. return Option.none();
  224. };
  225. var find = function (xs, pred) {
  226. return findUntil(xs, pred, never);
  227. };
  228. var flatten = function (xs) {
  229. var r = [];
  230. for (var i = 0, len = xs.length; i < len; ++i) {
  231. if (!isArray(xs[i])) {
  232. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  233. }
  234. nativePush.apply(r, xs[i]);
  235. }
  236. return r;
  237. };
  238. var bind = function (xs, f) {
  239. return flatten(map(xs, f));
  240. };
  241. var reverse = function (xs) {
  242. var r = nativeSlice.call(xs, 0);
  243. r.reverse();
  244. return r;
  245. };
  246. var head = function (xs) {
  247. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  248. };
  249. var last = function (xs) {
  250. return xs.length === 0 ? Option.none() : Option.some(xs[xs.length - 1]);
  251. };
  252. var compareDocumentPosition = function (a, b, match) {
  253. return (a.compareDocumentPosition(b) & match) !== 0;
  254. };
  255. var documentPositionContainedBy = function (a, b) {
  256. return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_CONTAINED_BY);
  257. };
  258. var __assign = function () {
  259. __assign = Object.assign || function __assign(t) {
  260. for (var s, i = 1, n = arguments.length; i < n; i++) {
  261. s = arguments[i];
  262. for (var p in s)
  263. if (Object.prototype.hasOwnProperty.call(s, p))
  264. t[p] = s[p];
  265. }
  266. return t;
  267. };
  268. return __assign.apply(this, arguments);
  269. };
  270. var cached = function (f) {
  271. var called = false;
  272. var r;
  273. return function () {
  274. var args = [];
  275. for (var _i = 0; _i < arguments.length; _i++) {
  276. args[_i] = arguments[_i];
  277. }
  278. if (!called) {
  279. called = true;
  280. r = f.apply(null, args);
  281. }
  282. return r;
  283. };
  284. };
  285. var firstMatch = function (regexes, s) {
  286. for (var i = 0; i < regexes.length; i++) {
  287. var x = regexes[i];
  288. if (x.test(s)) {
  289. return x;
  290. }
  291. }
  292. return undefined;
  293. };
  294. var find$1 = function (regexes, agent) {
  295. var r = firstMatch(regexes, agent);
  296. if (!r) {
  297. return {
  298. major: 0,
  299. minor: 0
  300. };
  301. }
  302. var group = function (i) {
  303. return Number(agent.replace(r, '$' + i));
  304. };
  305. return nu(group(1), group(2));
  306. };
  307. var detect = function (versionRegexes, agent) {
  308. var cleanedAgent = String(agent).toLowerCase();
  309. if (versionRegexes.length === 0) {
  310. return unknown();
  311. }
  312. return find$1(versionRegexes, cleanedAgent);
  313. };
  314. var unknown = function () {
  315. return nu(0, 0);
  316. };
  317. var nu = function (major, minor) {
  318. return {
  319. major: major,
  320. minor: minor
  321. };
  322. };
  323. var Version = {
  324. nu: nu,
  325. detect: detect,
  326. unknown: unknown
  327. };
  328. var edge = 'Edge';
  329. var chrome = 'Chrome';
  330. var ie = 'IE';
  331. var opera = 'Opera';
  332. var firefox = 'Firefox';
  333. var safari = 'Safari';
  334. var unknown$1 = function () {
  335. return nu$1({
  336. current: undefined,
  337. version: Version.unknown()
  338. });
  339. };
  340. var nu$1 = function (info) {
  341. var current = info.current;
  342. var version = info.version;
  343. var isBrowser = function (name) {
  344. return function () {
  345. return current === name;
  346. };
  347. };
  348. return {
  349. current: current,
  350. version: version,
  351. isEdge: isBrowser(edge),
  352. isChrome: isBrowser(chrome),
  353. isIE: isBrowser(ie),
  354. isOpera: isBrowser(opera),
  355. isFirefox: isBrowser(firefox),
  356. isSafari: isBrowser(safari)
  357. };
  358. };
  359. var Browser = {
  360. unknown: unknown$1,
  361. nu: nu$1,
  362. edge: constant(edge),
  363. chrome: constant(chrome),
  364. ie: constant(ie),
  365. opera: constant(opera),
  366. firefox: constant(firefox),
  367. safari: constant(safari)
  368. };
  369. var windows = 'Windows';
  370. var ios = 'iOS';
  371. var android = 'Android';
  372. var linux = 'Linux';
  373. var osx = 'OSX';
  374. var solaris = 'Solaris';
  375. var freebsd = 'FreeBSD';
  376. var chromeos = 'ChromeOS';
  377. var unknown$2 = function () {
  378. return nu$2({
  379. current: undefined,
  380. version: Version.unknown()
  381. });
  382. };
  383. var nu$2 = function (info) {
  384. var current = info.current;
  385. var version = info.version;
  386. var isOS = function (name) {
  387. return function () {
  388. return current === name;
  389. };
  390. };
  391. return {
  392. current: current,
  393. version: version,
  394. isWindows: isOS(windows),
  395. isiOS: isOS(ios),
  396. isAndroid: isOS(android),
  397. isOSX: isOS(osx),
  398. isLinux: isOS(linux),
  399. isSolaris: isOS(solaris),
  400. isFreeBSD: isOS(freebsd),
  401. isChromeOS: isOS(chromeos)
  402. };
  403. };
  404. var OperatingSystem = {
  405. unknown: unknown$2,
  406. nu: nu$2,
  407. windows: constant(windows),
  408. ios: constant(ios),
  409. android: constant(android),
  410. linux: constant(linux),
  411. osx: constant(osx),
  412. solaris: constant(solaris),
  413. freebsd: constant(freebsd),
  414. chromeos: constant(chromeos)
  415. };
  416. var DeviceType = function (os, browser, userAgent, mediaMatch) {
  417. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  418. var isiPhone = os.isiOS() && !isiPad;
  419. var isMobile = os.isiOS() || os.isAndroid();
  420. var isTouch = isMobile || mediaMatch('(pointer:coarse)');
  421. var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
  422. var isPhone = isiPhone || isMobile && !isTablet;
  423. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  424. var isDesktop = !isPhone && !isTablet && !iOSwebview;
  425. return {
  426. isiPad: constant(isiPad),
  427. isiPhone: constant(isiPhone),
  428. isTablet: constant(isTablet),
  429. isPhone: constant(isPhone),
  430. isTouch: constant(isTouch),
  431. isAndroid: os.isAndroid,
  432. isiOS: os.isiOS,
  433. isWebView: constant(iOSwebview),
  434. isDesktop: constant(isDesktop)
  435. };
  436. };
  437. var detect$1 = function (candidates, userAgent) {
  438. var agent = String(userAgent).toLowerCase();
  439. return find(candidates, function (candidate) {
  440. return candidate.search(agent);
  441. });
  442. };
  443. var detectBrowser = function (browsers, userAgent) {
  444. return detect$1(browsers, userAgent).map(function (browser) {
  445. var version = Version.detect(browser.versionRegexes, userAgent);
  446. return {
  447. current: browser.name,
  448. version: version
  449. };
  450. });
  451. };
  452. var detectOs = function (oses, userAgent) {
  453. return detect$1(oses, userAgent).map(function (os) {
  454. var version = Version.detect(os.versionRegexes, userAgent);
  455. return {
  456. current: os.name,
  457. version: version
  458. };
  459. });
  460. };
  461. var UaString = {
  462. detectBrowser: detectBrowser,
  463. detectOs: detectOs
  464. };
  465. var contains = function (str, substr) {
  466. return str.indexOf(substr) !== -1;
  467. };
  468. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  469. var checkContains = function (target) {
  470. return function (uastring) {
  471. return contains(uastring, target);
  472. };
  473. };
  474. var browsers = [
  475. {
  476. name: 'Edge',
  477. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  478. search: function (uastring) {
  479. return contains(uastring, 'edge/') && contains(uastring, 'chrome') && contains(uastring, 'safari') && contains(uastring, 'applewebkit');
  480. }
  481. },
  482. {
  483. name: 'Chrome',
  484. versionRegexes: [
  485. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  486. normalVersionRegex
  487. ],
  488. search: function (uastring) {
  489. return contains(uastring, 'chrome') && !contains(uastring, 'chromeframe');
  490. }
  491. },
  492. {
  493. name: 'IE',
  494. versionRegexes: [
  495. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  496. /.*?rv:([0-9]+)\.([0-9]+).*/
  497. ],
  498. search: function (uastring) {
  499. return contains(uastring, 'msie') || contains(uastring, 'trident');
  500. }
  501. },
  502. {
  503. name: 'Opera',
  504. versionRegexes: [
  505. normalVersionRegex,
  506. /.*?opera\/([0-9]+)\.([0-9]+).*/
  507. ],
  508. search: checkContains('opera')
  509. },
  510. {
  511. name: 'Firefox',
  512. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  513. search: checkContains('firefox')
  514. },
  515. {
  516. name: 'Safari',
  517. versionRegexes: [
  518. normalVersionRegex,
  519. /.*?cpu os ([0-9]+)_([0-9]+).*/
  520. ],
  521. search: function (uastring) {
  522. return (contains(uastring, 'safari') || contains(uastring, 'mobile/')) && contains(uastring, 'applewebkit');
  523. }
  524. }
  525. ];
  526. var oses = [
  527. {
  528. name: 'Windows',
  529. search: checkContains('win'),
  530. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  531. },
  532. {
  533. name: 'iOS',
  534. search: function (uastring) {
  535. return contains(uastring, 'iphone') || contains(uastring, 'ipad');
  536. },
  537. versionRegexes: [
  538. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  539. /.*cpu os ([0-9]+)_([0-9]+).*/,
  540. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  541. ]
  542. },
  543. {
  544. name: 'Android',
  545. search: checkContains('android'),
  546. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  547. },
  548. {
  549. name: 'OSX',
  550. search: checkContains('mac os x'),
  551. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
  552. },
  553. {
  554. name: 'Linux',
  555. search: checkContains('linux'),
  556. versionRegexes: []
  557. },
  558. {
  559. name: 'Solaris',
  560. search: checkContains('sunos'),
  561. versionRegexes: []
  562. },
  563. {
  564. name: 'FreeBSD',
  565. search: checkContains('freebsd'),
  566. versionRegexes: []
  567. },
  568. {
  569. name: 'ChromeOS',
  570. search: checkContains('cros'),
  571. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
  572. }
  573. ];
  574. var PlatformInfo = {
  575. browsers: constant(browsers),
  576. oses: constant(oses)
  577. };
  578. var detect$2 = function (userAgent, mediaMatch) {
  579. var browsers = PlatformInfo.browsers();
  580. var oses = PlatformInfo.oses();
  581. var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
  582. var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  583. var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
  584. return {
  585. browser: browser,
  586. os: os,
  587. deviceType: deviceType
  588. };
  589. };
  590. var PlatformDetection = { detect: detect$2 };
  591. var mediaMatch = function (query) {
  592. return domGlobals.window.matchMedia(query).matches;
  593. };
  594. var platform = cached(function () {
  595. return PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch);
  596. });
  597. var detect$3 = function () {
  598. return platform();
  599. };
  600. var fromHtml = function (html, scope) {
  601. var doc = scope || domGlobals.document;
  602. var div = doc.createElement('div');
  603. div.innerHTML = html;
  604. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  605. domGlobals.console.error('HTML does not have a single root node', html);
  606. throw new Error('HTML must have a single root node');
  607. }
  608. return fromDom(div.childNodes[0]);
  609. };
  610. var fromTag = function (tag, scope) {
  611. var doc = scope || domGlobals.document;
  612. var node = doc.createElement(tag);
  613. return fromDom(node);
  614. };
  615. var fromText = function (text, scope) {
  616. var doc = scope || domGlobals.document;
  617. var node = doc.createTextNode(text);
  618. return fromDom(node);
  619. };
  620. var fromDom = function (node) {
  621. if (node === null || node === undefined) {
  622. throw new Error('Node cannot be null or undefined');
  623. }
  624. return { dom: constant(node) };
  625. };
  626. var fromPoint = function (docElm, x, y) {
  627. var doc = docElm.dom();
  628. return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
  629. };
  630. var Element = {
  631. fromHtml: fromHtml,
  632. fromTag: fromTag,
  633. fromText: fromText,
  634. fromDom: fromDom,
  635. fromPoint: fromPoint
  636. };
  637. var ELEMENT = 1;
  638. var ELEMENT$1 = ELEMENT;
  639. var is = function (element, selector) {
  640. var dom = element.dom();
  641. if (dom.nodeType !== ELEMENT$1) {
  642. return false;
  643. } else {
  644. var elem = dom;
  645. if (elem.matches !== undefined) {
  646. return elem.matches(selector);
  647. } else if (elem.msMatchesSelector !== undefined) {
  648. return elem.msMatchesSelector(selector);
  649. } else if (elem.webkitMatchesSelector !== undefined) {
  650. return elem.webkitMatchesSelector(selector);
  651. } else if (elem.mozMatchesSelector !== undefined) {
  652. return elem.mozMatchesSelector(selector);
  653. } else {
  654. throw new Error('Browser lacks native selectors');
  655. }
  656. }
  657. };
  658. var eq = function (e1, e2) {
  659. return e1.dom() === e2.dom();
  660. };
  661. var regularContains = function (e1, e2) {
  662. var d1 = e1.dom();
  663. var d2 = e2.dom();
  664. return d1 === d2 ? false : d1.contains(d2);
  665. };
  666. var ieContains = function (e1, e2) {
  667. return documentPositionContainedBy(e1.dom(), e2.dom());
  668. };
  669. var contains$1 = function (e1, e2) {
  670. return detect$3().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2);
  671. };
  672. var is$1 = is;
  673. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');
  674. var global$2 = tinymce.util.Tools.resolve('tinymce.dom.TreeWalker');
  675. var global$3 = tinymce.util.Tools.resolve('tinymce.util.VK');
  676. var lift2 = function (oa, ob, f) {
  677. return oa.isSome() && ob.isSome() ? Option.some(f(oa.getOrDie(), ob.getOrDie())) : Option.none();
  678. };
  679. var fromElements = function (elements, scope) {
  680. var doc = scope || domGlobals.document;
  681. var fragment = doc.createDocumentFragment();
  682. each(elements, function (element) {
  683. fragment.appendChild(element.dom());
  684. });
  685. return Element.fromDom(fragment);
  686. };
  687. var parent = function (element) {
  688. return Option.from(element.dom().parentNode).map(Element.fromDom);
  689. };
  690. var children = function (element) {
  691. return map(element.dom().childNodes, Element.fromDom);
  692. };
  693. var child = function (element, index) {
  694. var cs = element.dom().childNodes;
  695. return Option.from(cs[index]).map(Element.fromDom);
  696. };
  697. var firstChild = function (element) {
  698. return child(element, 0);
  699. };
  700. var lastChild = function (element) {
  701. return child(element, element.dom().childNodes.length - 1);
  702. };
  703. var before = function (marker, element) {
  704. var parent$1 = parent(marker);
  705. parent$1.each(function (v) {
  706. v.dom().insertBefore(element.dom(), marker.dom());
  707. });
  708. };
  709. var append = function (parent, element) {
  710. parent.dom().appendChild(element.dom());
  711. };
  712. var before$1 = function (marker, elements) {
  713. each(elements, function (x) {
  714. before(marker, x);
  715. });
  716. };
  717. var append$1 = function (parent, elements) {
  718. each(elements, function (x) {
  719. append(parent, x);
  720. });
  721. };
  722. var remove = function (element) {
  723. var dom = element.dom();
  724. if (dom.parentNode !== null) {
  725. dom.parentNode.removeChild(dom);
  726. }
  727. };
  728. var fireListEvent = function (editor, action, element) {
  729. return editor.fire('ListMutation', {
  730. action: action,
  731. element: element
  732. });
  733. };
  734. var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
  735. var global$4 = tinymce.util.Tools.resolve('tinymce.dom.DomQuery');
  736. var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  737. var matchNodeName = function (name) {
  738. return function (node) {
  739. return node && node.nodeName.toLowerCase() === name;
  740. };
  741. };
  742. var matchNodeNames = function (regex) {
  743. return function (node) {
  744. return node && regex.test(node.nodeName);
  745. };
  746. };
  747. var isTextNode = function (node) {
  748. return node && node.nodeType === 3;
  749. };
  750. var isListNode = matchNodeNames(/^(OL|UL|DL)$/);
  751. var isOlUlNode = matchNodeNames(/^(OL|UL)$/);
  752. var isOlNode = matchNodeName('ol');
  753. var isListItemNode = matchNodeNames(/^(LI|DT|DD)$/);
  754. var isDlItemNode = matchNodeNames(/^(DT|DD)$/);
  755. var isTableCellNode = matchNodeNames(/^(TH|TD)$/);
  756. var isBr = matchNodeName('br');
  757. var isFirstChild = function (node) {
  758. return node.parentNode.firstChild === node;
  759. };
  760. var isTextBlock = function (editor, node) {
  761. return node && !!editor.schema.getTextBlockElements()[node.nodeName];
  762. };
  763. var isBlock = function (node, blockElements) {
  764. return node && node.nodeName in blockElements;
  765. };
  766. var isBogusBr = function (dom, node) {
  767. if (!isBr(node)) {
  768. return false;
  769. }
  770. if (dom.isBlock(node.nextSibling) && !isBr(node.previousSibling)) {
  771. return true;
  772. }
  773. return false;
  774. };
  775. var isEmpty = function (dom, elm, keepBookmarks) {
  776. var empty = dom.isEmpty(elm);
  777. if (keepBookmarks && dom.select('span[data-mce-type=bookmark]', elm).length > 0) {
  778. return false;
  779. }
  780. return empty;
  781. };
  782. var isChildOfBody = function (dom, elm) {
  783. return dom.isChildOf(elm, dom.getRoot());
  784. };
  785. var getParentList = function (editor, node) {
  786. var selectionStart = node || editor.selection.getStart(true);
  787. return editor.dom.getParent(selectionStart, 'OL,UL,DL', getClosestListRootElm(editor, selectionStart));
  788. };
  789. var isParentListSelected = function (parentList, selectedBlocks) {
  790. return parentList && selectedBlocks.length === 1 && selectedBlocks[0] === parentList;
  791. };
  792. var findSubLists = function (parentList) {
  793. return global$5.grep(parentList.querySelectorAll('ol,ul,dl'), function (elm) {
  794. return isListNode(elm);
  795. });
  796. };
  797. var getSelectedSubLists = function (editor) {
  798. var parentList = getParentList(editor);
  799. var selectedBlocks = editor.selection.getSelectedBlocks();
  800. if (isParentListSelected(parentList, selectedBlocks)) {
  801. return findSubLists(parentList);
  802. } else {
  803. return global$5.grep(selectedBlocks, function (elm) {
  804. return isListNode(elm) && parentList !== elm;
  805. });
  806. }
  807. };
  808. var findParentListItemsNodes = function (editor, elms) {
  809. var listItemsElms = global$5.map(elms, function (elm) {
  810. var parentLi = editor.dom.getParent(elm, 'li,dd,dt', getClosestListRootElm(editor, elm));
  811. return parentLi ? parentLi : elm;
  812. });
  813. return global$4.unique(listItemsElms);
  814. };
  815. var getSelectedListItems = function (editor) {
  816. var selectedBlocks = editor.selection.getSelectedBlocks();
  817. return global$5.grep(findParentListItemsNodes(editor, selectedBlocks), function (block) {
  818. return isListItemNode(block);
  819. });
  820. };
  821. var getSelectedDlItems = function (editor) {
  822. return filter(getSelectedListItems(editor), isDlItemNode);
  823. };
  824. var getClosestListRootElm = function (editor, elm) {
  825. var parentTableCell = editor.dom.getParents(elm, 'TD,TH');
  826. var root = parentTableCell.length > 0 ? parentTableCell[0] : editor.getBody();
  827. return root;
  828. };
  829. var findLastParentListNode = function (editor, elm) {
  830. var parentLists = editor.dom.getParents(elm, 'ol,ul', getClosestListRootElm(editor, elm));
  831. return last(parentLists);
  832. };
  833. var getSelectedLists = function (editor) {
  834. var firstList = findLastParentListNode(editor, editor.selection.getStart());
  835. var subsequentLists = filter(editor.selection.getSelectedBlocks(), isOlUlNode);
  836. return firstList.toArray().concat(subsequentLists);
  837. };
  838. var getSelectedListRoots = function (editor) {
  839. var selectedLists = getSelectedLists(editor);
  840. return getUniqueListRoots(editor, selectedLists);
  841. };
  842. var getUniqueListRoots = function (editor, lists) {
  843. var listRoots = map(lists, function (list) {
  844. return findLastParentListNode(editor, list).getOr(list);
  845. });
  846. return global$4.unique(listRoots);
  847. };
  848. var shouldIndentOnTab = function (editor) {
  849. return editor.getParam('lists_indent_on_tab', true);
  850. };
  851. var getForcedRootBlock = function (editor) {
  852. var block = editor.getParam('forced_root_block', 'p');
  853. if (block === false) {
  854. return '';
  855. } else if (block === true) {
  856. return 'p';
  857. } else {
  858. return block;
  859. }
  860. };
  861. var getForcedRootBlockAttrs = function (editor) {
  862. return editor.getParam('forced_root_block_attrs', {});
  863. };
  864. var createTextBlock = function (editor, contentNode) {
  865. var dom = editor.dom;
  866. var blockElements = editor.schema.getBlockElements();
  867. var fragment = dom.createFragment();
  868. var blockName = getForcedRootBlock(editor);
  869. var node, textBlock, hasContentNode;
  870. if (blockName) {
  871. textBlock = dom.create(blockName);
  872. if (textBlock.tagName === blockName.toUpperCase()) {
  873. dom.setAttribs(textBlock, getForcedRootBlockAttrs(editor));
  874. }
  875. if (!isBlock(contentNode.firstChild, blockElements)) {
  876. fragment.appendChild(textBlock);
  877. }
  878. }
  879. if (contentNode) {
  880. while (node = contentNode.firstChild) {
  881. var nodeName = node.nodeName;
  882. if (!hasContentNode && (nodeName !== 'SPAN' || node.getAttribute('data-mce-type') !== 'bookmark')) {
  883. hasContentNode = true;
  884. }
  885. if (isBlock(node, blockElements)) {
  886. fragment.appendChild(node);
  887. textBlock = null;
  888. } else {
  889. if (blockName) {
  890. if (!textBlock) {
  891. textBlock = dom.create(blockName);
  892. fragment.appendChild(textBlock);
  893. }
  894. textBlock.appendChild(node);
  895. } else {
  896. fragment.appendChild(node);
  897. }
  898. }
  899. }
  900. }
  901. if (!blockName) {
  902. fragment.appendChild(dom.create('br'));
  903. } else {
  904. if (!hasContentNode) {
  905. textBlock.appendChild(dom.create('br', { 'data-mce-bogus': '1' }));
  906. }
  907. }
  908. return fragment;
  909. };
  910. var keys = Object.keys;
  911. var each$1 = function (obj, f) {
  912. var props = keys(obj);
  913. for (var k = 0, len = props.length; k < len; k++) {
  914. var i = props[k];
  915. var x = obj[i];
  916. f(x, i);
  917. }
  918. };
  919. var objAcc = function (r) {
  920. return function (x, i) {
  921. r[i] = x;
  922. };
  923. };
  924. var internalFilter = function (obj, pred, onTrue, onFalse) {
  925. var r = {};
  926. each$1(obj, function (x, i) {
  927. (pred(x, i) ? onTrue : onFalse)(x, i);
  928. });
  929. return r;
  930. };
  931. var filter$1 = function (obj, pred) {
  932. var t = {};
  933. internalFilter(obj, pred, objAcc(t), noop);
  934. return t;
  935. };
  936. var name = function (element) {
  937. var r = element.dom().nodeName;
  938. return r.toLowerCase();
  939. };
  940. var type = function (element) {
  941. return element.dom().nodeType;
  942. };
  943. var isType$1 = function (t) {
  944. return function (element) {
  945. return type(element) === t;
  946. };
  947. };
  948. var isElement = isType$1(ELEMENT);
  949. var rawSet = function (dom, key, value) {
  950. if (isString(value) || isBoolean(value) || isNumber(value)) {
  951. dom.setAttribute(key, value + '');
  952. } else {
  953. domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  954. throw new Error('Attribute value was not simple');
  955. }
  956. };
  957. var setAll = function (element, attrs) {
  958. var dom = element.dom();
  959. each$1(attrs, function (v, k) {
  960. rawSet(dom, k, v);
  961. });
  962. };
  963. var clone = function (element) {
  964. return foldl(element.dom().attributes, function (acc, attr) {
  965. acc[attr.name] = attr.value;
  966. return acc;
  967. }, {});
  968. };
  969. var isSupported = function (dom) {
  970. return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
  971. };
  972. var internalSet = function (dom, property, value) {
  973. if (!isString(value)) {
  974. domGlobals.console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
  975. throw new Error('CSS value must be a string: ' + value);
  976. }
  977. if (isSupported(dom)) {
  978. dom.style.setProperty(property, value);
  979. }
  980. };
  981. var set = function (element, property, value) {
  982. var dom = element.dom();
  983. internalSet(dom, property, value);
  984. };
  985. var clone$1 = function (original, isDeep) {
  986. return Element.fromDom(original.dom().cloneNode(isDeep));
  987. };
  988. var deep = function (original) {
  989. return clone$1(original, true);
  990. };
  991. var shallowAs = function (original, tag) {
  992. var nu = Element.fromTag(tag);
  993. var attributes = clone(original);
  994. setAll(nu, attributes);
  995. return nu;
  996. };
  997. var mutate = function (original, tag) {
  998. var nu = shallowAs(original, tag);
  999. before(original, nu);
  1000. var children$1 = children(original);
  1001. append$1(nu, children$1);
  1002. remove(original);
  1003. return nu;
  1004. };
  1005. var joinSegment = function (parent, child) {
  1006. append(parent.item, child.list);
  1007. };
  1008. var joinSegments = function (segments) {
  1009. for (var i = 1; i < segments.length; i++) {
  1010. joinSegment(segments[i - 1], segments[i]);
  1011. }
  1012. };
  1013. var appendSegments = function (head$1, tail) {
  1014. lift2(last(head$1), head(tail), joinSegment);
  1015. };
  1016. var createSegment = function (scope, listType) {
  1017. var segment = {
  1018. list: Element.fromTag(listType, scope),
  1019. item: Element.fromTag('li', scope)
  1020. };
  1021. append(segment.list, segment.item);
  1022. return segment;
  1023. };
  1024. var createSegments = function (scope, entry, size) {
  1025. var segments = [];
  1026. for (var i = 0; i < size; i++) {
  1027. segments.push(createSegment(scope, entry.listType));
  1028. }
  1029. return segments;
  1030. };
  1031. var populateSegments = function (segments, entry) {
  1032. for (var i = 0; i < segments.length - 1; i++) {
  1033. set(segments[i].item, 'list-style-type', 'none');
  1034. }
  1035. last(segments).each(function (segment) {
  1036. setAll(segment.list, entry.listAttributes);
  1037. setAll(segment.item, entry.itemAttributes);
  1038. append$1(segment.item, entry.content);
  1039. });
  1040. };
  1041. var normalizeSegment = function (segment, entry) {
  1042. if (name(segment.list) !== entry.listType) {
  1043. segment.list = mutate(segment.list, entry.listType);
  1044. }
  1045. setAll(segment.list, entry.listAttributes);
  1046. };
  1047. var createItem = function (scope, attr, content) {
  1048. var item = Element.fromTag('li', scope);
  1049. setAll(item, attr);
  1050. append$1(item, content);
  1051. return item;
  1052. };
  1053. var appendItem = function (segment, item) {
  1054. append(segment.list, item);
  1055. segment.item = item;
  1056. };
  1057. var writeShallow = function (scope, cast, entry) {
  1058. var newCast = cast.slice(0, entry.depth);
  1059. last(newCast).each(function (segment) {
  1060. var item = createItem(scope, entry.itemAttributes, entry.content);
  1061. appendItem(segment, item);
  1062. normalizeSegment(segment, entry);
  1063. });
  1064. return newCast;
  1065. };
  1066. var writeDeep = function (scope, cast, entry) {
  1067. var segments = createSegments(scope, entry, entry.depth - cast.length);
  1068. joinSegments(segments);
  1069. populateSegments(segments, entry);
  1070. appendSegments(cast, segments);
  1071. return cast.concat(segments);
  1072. };
  1073. var composeList = function (scope, entries) {
  1074. var cast = foldl(entries, function (cast, entry) {
  1075. return entry.depth > cast.length ? writeDeep(scope, cast, entry) : writeShallow(scope, cast, entry);
  1076. }, []);
  1077. return head(cast).map(function (segment) {
  1078. return segment.list;
  1079. });
  1080. };
  1081. var isList = function (el) {
  1082. return is$1(el, 'OL,UL');
  1083. };
  1084. var hasFirstChildList = function (el) {
  1085. return firstChild(el).map(isList).getOr(false);
  1086. };
  1087. var hasLastChildList = function (el) {
  1088. return lastChild(el).map(isList).getOr(false);
  1089. };
  1090. var isIndented = function (entry) {
  1091. return entry.depth > 0;
  1092. };
  1093. var isSelected = function (entry) {
  1094. return entry.isSelected;
  1095. };
  1096. var cloneItemContent = function (li) {
  1097. var children$1 = children(li);
  1098. var content = hasLastChildList(li) ? children$1.slice(0, -1) : children$1;
  1099. return map(content, deep);
  1100. };
  1101. var createEntry = function (li, depth, isSelected) {
  1102. return parent(li).filter(isElement).map(function (list) {
  1103. return {
  1104. depth: depth,
  1105. dirty: false,
  1106. isSelected: isSelected,
  1107. content: cloneItemContent(li),
  1108. itemAttributes: clone(li),
  1109. listAttributes: clone(list),
  1110. listType: name(list)
  1111. };
  1112. });
  1113. };
  1114. var indentEntry = function (indentation, entry) {
  1115. switch (indentation) {
  1116. case 'Indent':
  1117. entry.depth++;
  1118. break;
  1119. case 'Outdent':
  1120. entry.depth--;
  1121. break;
  1122. case 'Flatten':
  1123. entry.depth = 0;
  1124. }
  1125. entry.dirty = true;
  1126. };
  1127. var cloneListProperties = function (target, source) {
  1128. target.listType = source.listType;
  1129. target.listAttributes = __assign({}, source.listAttributes);
  1130. };
  1131. var cleanListProperties = function (entry) {
  1132. entry.listAttributes = filter$1(entry.listAttributes, function (_value, key) {
  1133. return key !== 'start';
  1134. });
  1135. };
  1136. var closestSiblingEntry = function (entries, start) {
  1137. var depth = entries[start].depth;
  1138. var matches = function (entry) {
  1139. return entry.depth === depth && !entry.dirty;
  1140. };
  1141. var until = function (entry) {
  1142. return entry.depth < depth;
  1143. };
  1144. return findUntil(reverse(entries.slice(0, start)), matches, until).orThunk(function () {
  1145. return findUntil(entries.slice(start + 1), matches, until);
  1146. });
  1147. };
  1148. var normalizeEntries = function (entries) {
  1149. each(entries, function (entry, i) {
  1150. closestSiblingEntry(entries, i).fold(function () {
  1151. if (entry.dirty) {
  1152. cleanListProperties(entry);
  1153. }
  1154. }, function (matchingEntry) {
  1155. return cloneListProperties(entry, matchingEntry);
  1156. });
  1157. });
  1158. return entries;
  1159. };
  1160. var Cell = function (initial) {
  1161. var value = initial;
  1162. var get = function () {
  1163. return value;
  1164. };
  1165. var set = function (v) {
  1166. value = v;
  1167. };
  1168. return {
  1169. get: get,
  1170. set: set
  1171. };
  1172. };
  1173. var parseItem = function (depth, itemSelection, selectionState, item) {
  1174. return firstChild(item).filter(isList).fold(function () {
  1175. itemSelection.each(function (selection) {
  1176. if (eq(selection.start, item)) {
  1177. selectionState.set(true);
  1178. }
  1179. });
  1180. var currentItemEntry = createEntry(item, depth, selectionState.get());
  1181. itemSelection.each(function (selection) {
  1182. if (eq(selection.end, item)) {
  1183. selectionState.set(false);
  1184. }
  1185. });
  1186. var childListEntries = lastChild(item).filter(isList).map(function (list) {
  1187. return parseList(depth, itemSelection, selectionState, list);
  1188. }).getOr([]);
  1189. return currentItemEntry.toArray().concat(childListEntries);
  1190. }, function (list) {
  1191. return parseList(depth, itemSelection, selectionState, list);
  1192. });
  1193. };
  1194. var parseList = function (depth, itemSelection, selectionState, list) {
  1195. return bind(children(list), function (element) {
  1196. var parser = isList(element) ? parseList : parseItem;
  1197. var newDepth = depth + 1;
  1198. return parser(newDepth, itemSelection, selectionState, element);
  1199. });
  1200. };
  1201. var parseLists = function (lists, itemSelection) {
  1202. var selectionState = Cell(false);
  1203. var initialDepth = 0;
  1204. return map(lists, function (list) {
  1205. return {
  1206. sourceList: list,
  1207. entries: parseList(initialDepth, itemSelection, selectionState, list)
  1208. };
  1209. });
  1210. };
  1211. var outdentedComposer = function (editor, entries) {
  1212. var normalizedEntries = normalizeEntries(entries);
  1213. return map(normalizedEntries, function (entry) {
  1214. var content = fromElements(entry.content);
  1215. return Element.fromDom(createTextBlock(editor, content.dom()));
  1216. });
  1217. };
  1218. var indentedComposer = function (editor, entries) {
  1219. var normalizedEntries = normalizeEntries(entries);
  1220. return composeList(editor.contentDocument, normalizedEntries).toArray();
  1221. };
  1222. var composeEntries = function (editor, entries) {
  1223. return bind(groupBy(entries, isIndented), function (entries) {
  1224. var groupIsIndented = head(entries).map(isIndented).getOr(false);
  1225. return groupIsIndented ? indentedComposer(editor, entries) : outdentedComposer(editor, entries);
  1226. });
  1227. };
  1228. var indentSelectedEntries = function (entries, indentation) {
  1229. each(filter(entries, isSelected), function (entry) {
  1230. return indentEntry(indentation, entry);
  1231. });
  1232. };
  1233. var getItemSelection = function (editor) {
  1234. var selectedListItems = map(getSelectedListItems(editor), Element.fromDom);
  1235. return lift2(find(selectedListItems, not(hasFirstChildList)), find(reverse(selectedListItems), not(hasFirstChildList)), function (start, end) {
  1236. return {
  1237. start: start,
  1238. end: end
  1239. };
  1240. });
  1241. };
  1242. var listIndentation = function (editor, lists, indentation) {
  1243. var entrySets = parseLists(lists, getItemSelection(editor));
  1244. each(entrySets, function (entrySet) {
  1245. indentSelectedEntries(entrySet.entries, indentation);
  1246. var composedLists = composeEntries(editor, entrySet.entries);
  1247. each(composedLists, function (composedList) {
  1248. fireListEvent(editor, indentation === 'Indent' ? 'IndentList' : 'OutdentList', composedList.dom());
  1249. });
  1250. before$1(entrySet.sourceList, composedLists);
  1251. remove(entrySet.sourceList);
  1252. });
  1253. };
  1254. var global$6 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  1255. var DOM = global$6.DOM;
  1256. var splitList = function (editor, ul, li) {
  1257. var tmpRng, fragment, bookmarks, node, newBlock;
  1258. var removeAndKeepBookmarks = function (targetNode) {
  1259. global$5.each(bookmarks, function (node) {
  1260. targetNode.parentNode.insertBefore(node, li.parentNode);
  1261. });
  1262. DOM.remove(targetNode);
  1263. };
  1264. bookmarks = DOM.select('span[data-mce-type="bookmark"]', ul);
  1265. newBlock = createTextBlock(editor, li);
  1266. tmpRng = DOM.createRng();
  1267. tmpRng.setStartAfter(li);
  1268. tmpRng.setEndAfter(ul);
  1269. fragment = tmpRng.extractContents();
  1270. for (node = fragment.firstChild; node; node = node.firstChild) {
  1271. if (node.nodeName === 'LI' && editor.dom.isEmpty(node)) {
  1272. DOM.remove(node);
  1273. break;
  1274. }
  1275. }
  1276. if (!editor.dom.isEmpty(fragment)) {
  1277. DOM.insertAfter(fragment, ul);
  1278. }
  1279. DOM.insertAfter(newBlock, ul);
  1280. if (isEmpty(editor.dom, li.parentNode)) {
  1281. removeAndKeepBookmarks(li.parentNode);
  1282. }
  1283. DOM.remove(li);
  1284. if (isEmpty(editor.dom, ul)) {
  1285. DOM.remove(ul);
  1286. }
  1287. };
  1288. var outdentDlItem = function (editor, item) {
  1289. if (is$1(item, 'dd')) {
  1290. mutate(item, 'dt');
  1291. } else if (is$1(item, 'dt')) {
  1292. parent(item).each(function (dl) {
  1293. return splitList(editor, dl.dom(), item.dom());
  1294. });
  1295. }
  1296. };
  1297. var indentDlItem = function (item) {
  1298. if (is$1(item, 'dt')) {
  1299. mutate(item, 'dd');
  1300. }
  1301. };
  1302. var dlIndentation = function (editor, indentation, dlItems) {
  1303. if (indentation === 'Indent') {
  1304. each(dlItems, indentDlItem);
  1305. } else {
  1306. each(dlItems, function (item) {
  1307. return outdentDlItem(editor, item);
  1308. });
  1309. }
  1310. };
  1311. var getNormalizedPoint = function (container, offset) {
  1312. if (isTextNode(container)) {
  1313. return {
  1314. container: container,
  1315. offset: offset
  1316. };
  1317. }
  1318. var node = global$1.getNode(container, offset);
  1319. if (isTextNode(node)) {
  1320. return {
  1321. container: node,
  1322. offset: offset >= container.childNodes.length ? node.data.length : 0
  1323. };
  1324. } else if (node.previousSibling && isTextNode(node.previousSibling)) {
  1325. return {
  1326. container: node.previousSibling,
  1327. offset: node.previousSibling.data.length
  1328. };
  1329. } else if (node.nextSibling && isTextNode(node.nextSibling)) {
  1330. return {
  1331. container: node.nextSibling,
  1332. offset: 0
  1333. };
  1334. }
  1335. return {
  1336. container: container,
  1337. offset: offset
  1338. };
  1339. };
  1340. var normalizeRange = function (rng) {
  1341. var outRng = rng.cloneRange();
  1342. var rangeStart = getNormalizedPoint(rng.startContainer, rng.startOffset);
  1343. outRng.setStart(rangeStart.container, rangeStart.offset);
  1344. var rangeEnd = getNormalizedPoint(rng.endContainer, rng.endOffset);
  1345. outRng.setEnd(rangeEnd.container, rangeEnd.offset);
  1346. return outRng;
  1347. };
  1348. var selectionIndentation = function (editor, indentation) {
  1349. var lists = map(getSelectedListRoots(editor), Element.fromDom);
  1350. var dlItems = map(getSelectedDlItems(editor), Element.fromDom);
  1351. var isHandled = false;
  1352. if (lists.length || dlItems.length) {
  1353. var bookmark = editor.selection.getBookmark();
  1354. listIndentation(editor, lists, indentation);
  1355. dlIndentation(editor, indentation, dlItems);
  1356. editor.selection.moveToBookmark(bookmark);
  1357. editor.selection.setRng(normalizeRange(editor.selection.getRng()));
  1358. editor.nodeChanged();
  1359. isHandled = true;
  1360. }
  1361. return isHandled;
  1362. };
  1363. var indentListSelection = function (editor) {
  1364. return selectionIndentation(editor, 'Indent');
  1365. };
  1366. var outdentListSelection = function (editor) {
  1367. return selectionIndentation(editor, 'Outdent');
  1368. };
  1369. var flattenListSelection = function (editor) {
  1370. return selectionIndentation(editor, 'Flatten');
  1371. };
  1372. var global$7 = tinymce.util.Tools.resolve('tinymce.dom.BookmarkManager');
  1373. var DOM$1 = global$6.DOM;
  1374. var createBookmark = function (rng) {
  1375. var bookmark = {};
  1376. var setupEndPoint = function (start) {
  1377. var offsetNode, container, offset;
  1378. container = rng[start ? 'startContainer' : 'endContainer'];
  1379. offset = rng[start ? 'startOffset' : 'endOffset'];
  1380. if (container.nodeType === 1) {
  1381. offsetNode = DOM$1.create('span', { 'data-mce-type': 'bookmark' });
  1382. if (container.hasChildNodes()) {
  1383. offset = Math.min(offset, container.childNodes.length - 1);
  1384. if (start) {
  1385. container.insertBefore(offsetNode, container.childNodes[offset]);
  1386. } else {
  1387. DOM$1.insertAfter(offsetNode, container.childNodes[offset]);
  1388. }
  1389. } else {
  1390. container.appendChild(offsetNode);
  1391. }
  1392. container = offsetNode;
  1393. offset = 0;
  1394. }
  1395. bookmark[start ? 'startContainer' : 'endContainer'] = container;
  1396. bookmark[start ? 'startOffset' : 'endOffset'] = offset;
  1397. };
  1398. setupEndPoint(true);
  1399. if (!rng.collapsed) {
  1400. setupEndPoint();
  1401. }
  1402. return bookmark;
  1403. };
  1404. var resolveBookmark = function (bookmark) {
  1405. function restoreEndPoint(start) {
  1406. var container, offset, node;
  1407. var nodeIndex = function (container) {
  1408. var node = container.parentNode.firstChild, idx = 0;
  1409. while (node) {
  1410. if (node === container) {
  1411. return idx;
  1412. }
  1413. if (node.nodeType !== 1 || node.getAttribute('data-mce-type') !== 'bookmark') {
  1414. idx++;
  1415. }
  1416. node = node.nextSibling;
  1417. }
  1418. return -1;
  1419. };
  1420. container = node = bookmark[start ? 'startContainer' : 'endContainer'];
  1421. offset = bookmark[start ? 'startOffset' : 'endOffset'];
  1422. if (!container) {
  1423. return;
  1424. }
  1425. if (container.nodeType === 1) {
  1426. offset = nodeIndex(container);
  1427. container = container.parentNode;
  1428. DOM$1.remove(node);
  1429. if (!container.hasChildNodes() && DOM$1.isBlock(container)) {
  1430. container.appendChild(DOM$1.create('br'));
  1431. }
  1432. }
  1433. bookmark[start ? 'startContainer' : 'endContainer'] = container;
  1434. bookmark[start ? 'startOffset' : 'endOffset'] = offset;
  1435. }
  1436. restoreEndPoint(true);
  1437. restoreEndPoint();
  1438. var rng = DOM$1.createRng();
  1439. rng.setStart(bookmark.startContainer, bookmark.startOffset);
  1440. if (bookmark.endContainer) {
  1441. rng.setEnd(bookmark.endContainer, bookmark.endOffset);
  1442. }
  1443. return normalizeRange(rng);
  1444. };
  1445. var isCustomList = function (list) {
  1446. return /\btox\-/.test(list.className);
  1447. };
  1448. var listState = function (editor, listName, activate) {
  1449. return function () {
  1450. var nodeChangeHandler = function (e) {
  1451. var inList = findUntil(e.parents, isListNode, isTableCellNode).filter(function (list) {
  1452. return list.nodeName === listName && !isCustomList(list);
  1453. }).isSome();
  1454. activate(inList);
  1455. };
  1456. editor.on('NodeChange', nodeChangeHandler);
  1457. return function () {
  1458. return editor.off('NodeChange', nodeChangeHandler);
  1459. };
  1460. };
  1461. };
  1462. var listToggleActionFromListName = function (listName) {
  1463. switch (listName) {
  1464. case 'UL':
  1465. return 'ToggleUlList';
  1466. case 'OL':
  1467. return 'ToggleOlList';
  1468. case 'DL':
  1469. return 'ToggleDLList';
  1470. }
  1471. };
  1472. var updateListStyle = function (dom, el, detail) {
  1473. var type = detail['list-style-type'] ? detail['list-style-type'] : null;
  1474. dom.setStyle(el, 'list-style-type', type);
  1475. };
  1476. var setAttribs = function (elm, attrs) {
  1477. global$5.each(attrs, function (value, key) {
  1478. elm.setAttribute(key, value);
  1479. });
  1480. };
  1481. var updateListAttrs = function (dom, el, detail) {
  1482. setAttribs(el, detail['list-attributes']);
  1483. global$5.each(dom.select('li', el), function (li) {
  1484. setAttribs(li, detail['list-item-attributes']);
  1485. });
  1486. };
  1487. var updateListWithDetails = function (dom, el, detail) {
  1488. updateListStyle(dom, el, detail);
  1489. updateListAttrs(dom, el, detail);
  1490. };
  1491. var removeStyles = function (dom, element, styles) {
  1492. global$5.each(styles, function (style) {
  1493. var _a;
  1494. return dom.setStyle(element, (_a = {}, _a[style] = '', _a));
  1495. });
  1496. };
  1497. var getEndPointNode = function (editor, rng, start, root) {
  1498. var container, offset;
  1499. container = rng[start ? 'startContainer' : 'endContainer'];
  1500. offset = rng[start ? 'startOffset' : 'endOffset'];
  1501. if (container.nodeType === 1) {
  1502. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  1503. }
  1504. if (!start && isBr(container.nextSibling)) {
  1505. container = container.nextSibling;
  1506. }
  1507. while (container.parentNode !== root) {
  1508. if (isTextBlock(editor, container)) {
  1509. return container;
  1510. }
  1511. if (/^(TD|TH)$/.test(container.parentNode.nodeName)) {
  1512. return container;
  1513. }
  1514. container = container.parentNode;
  1515. }
  1516. return container;
  1517. };
  1518. var getSelectedTextBlocks = function (editor, rng, root) {
  1519. var textBlocks = [], dom = editor.dom;
  1520. var startNode = getEndPointNode(editor, rng, true, root);
  1521. var endNode = getEndPointNode(editor, rng, false, root);
  1522. var block;
  1523. var siblings = [];
  1524. for (var node = startNode; node; node = node.nextSibling) {
  1525. siblings.push(node);
  1526. if (node === endNode) {
  1527. break;
  1528. }
  1529. }
  1530. global$5.each(siblings, function (node) {
  1531. if (isTextBlock(editor, node)) {
  1532. textBlocks.push(node);
  1533. block = null;
  1534. return;
  1535. }
  1536. if (dom.isBlock(node) || isBr(node)) {
  1537. if (isBr(node)) {
  1538. dom.remove(node);
  1539. }
  1540. block = null;
  1541. return;
  1542. }
  1543. var nextSibling = node.nextSibling;
  1544. if (global$7.isBookmarkNode(node)) {
  1545. if (isTextBlock(editor, nextSibling) || !nextSibling && node.parentNode === root) {
  1546. block = null;
  1547. return;
  1548. }
  1549. }
  1550. if (!block) {
  1551. block = dom.create('p');
  1552. node.parentNode.insertBefore(block, node);
  1553. textBlocks.push(block);
  1554. }
  1555. block.appendChild(node);
  1556. });
  1557. return textBlocks;
  1558. };
  1559. var hasCompatibleStyle = function (dom, sib, detail) {
  1560. var sibStyle = dom.getStyle(sib, 'list-style-type');
  1561. var detailStyle = detail ? detail['list-style-type'] : '';
  1562. detailStyle = detailStyle === null ? '' : detailStyle;
  1563. return sibStyle === detailStyle;
  1564. };
  1565. var applyList = function (editor, listName, detail) {
  1566. if (detail === void 0) {
  1567. detail = {};
  1568. }
  1569. var rng = editor.selection.getRng(true);
  1570. var bookmark;
  1571. var listItemName = 'LI';
  1572. var root = getClosestListRootElm(editor, editor.selection.getStart(true));
  1573. var dom = editor.dom;
  1574. if (dom.getContentEditable(editor.selection.getNode()) === 'false') {
  1575. return;
  1576. }
  1577. listName = listName.toUpperCase();
  1578. if (listName === 'DL') {
  1579. listItemName = 'DT';
  1580. }
  1581. bookmark = createBookmark(rng);
  1582. global$5.each(getSelectedTextBlocks(editor, rng, root), function (block) {
  1583. var listBlock, sibling;
  1584. sibling = block.previousSibling;
  1585. if (sibling && isListNode(sibling) && sibling.nodeName === listName && hasCompatibleStyle(dom, sibling, detail)) {
  1586. listBlock = sibling;
  1587. block = dom.rename(block, listItemName);
  1588. sibling.appendChild(block);
  1589. } else {
  1590. listBlock = dom.create(listName);
  1591. block.parentNode.insertBefore(listBlock, block);
  1592. listBlock.appendChild(block);
  1593. block = dom.rename(block, listItemName);
  1594. }
  1595. removeStyles(dom, block, [
  1596. 'margin',
  1597. 'margin-right',
  1598. 'margin-bottom',
  1599. 'margin-left',
  1600. 'margin-top',
  1601. 'padding',
  1602. 'padding-right',
  1603. 'padding-bottom',
  1604. 'padding-left',
  1605. 'padding-top'
  1606. ]);
  1607. updateListWithDetails(dom, listBlock, detail);
  1608. mergeWithAdjacentLists(editor.dom, listBlock);
  1609. });
  1610. editor.selection.setRng(resolveBookmark(bookmark));
  1611. };
  1612. var isValidLists = function (list1, list2) {
  1613. return list1 && list2 && isListNode(list1) && list1.nodeName === list2.nodeName;
  1614. };
  1615. var hasSameListStyle = function (dom, list1, list2) {
  1616. var targetStyle = dom.getStyle(list1, 'list-style-type', true);
  1617. var style = dom.getStyle(list2, 'list-style-type', true);
  1618. return targetStyle === style;
  1619. };
  1620. var hasSameClasses = function (elm1, elm2) {
  1621. return elm1.className === elm2.className;
  1622. };
  1623. var shouldMerge = function (dom, list1, list2) {
  1624. return isValidLists(list1, list2) && hasSameListStyle(dom, list1, list2) && hasSameClasses(list1, list2);
  1625. };
  1626. var mergeWithAdjacentLists = function (dom, listBlock) {
  1627. var sibling, node;
  1628. sibling = listBlock.nextSibling;
  1629. if (shouldMerge(dom, listBlock, sibling)) {
  1630. while (node = sibling.firstChild) {
  1631. listBlock.appendChild(node);
  1632. }
  1633. dom.remove(sibling);
  1634. }
  1635. sibling = listBlock.previousSibling;
  1636. if (shouldMerge(dom, listBlock, sibling)) {
  1637. while (node = sibling.lastChild) {
  1638. listBlock.insertBefore(node, listBlock.firstChild);
  1639. }
  1640. dom.remove(sibling);
  1641. }
  1642. };
  1643. var updateList = function (editor, list, listName, detail) {
  1644. if (list.nodeName !== listName) {
  1645. var newList = editor.dom.rename(list, listName);
  1646. updateListWithDetails(editor.dom, newList, detail);
  1647. fireListEvent(editor, listToggleActionFromListName(listName), newList);
  1648. } else {
  1649. updateListWithDetails(editor.dom, list, detail);
  1650. fireListEvent(editor, listToggleActionFromListName(listName), list);
  1651. }
  1652. };
  1653. var toggleMultipleLists = function (editor, parentList, lists, listName, detail) {
  1654. if (parentList.nodeName === listName && !hasListStyleDetail(detail)) {
  1655. flattenListSelection(editor);
  1656. } else {
  1657. var bookmark = createBookmark(editor.selection.getRng(true));
  1658. global$5.each([parentList].concat(lists), function (elm) {
  1659. updateList(editor, elm, listName, detail);
  1660. });
  1661. editor.selection.setRng(resolveBookmark(bookmark));
  1662. }
  1663. };
  1664. var hasListStyleDetail = function (detail) {
  1665. return 'list-style-type' in detail;
  1666. };
  1667. var toggleSingleList = function (editor, parentList, listName, detail) {
  1668. if (parentList === editor.getBody()) {
  1669. return;
  1670. }
  1671. if (parentList) {
  1672. if (parentList.nodeName === listName && !hasListStyleDetail(detail) && !isCustomList(parentList)) {
  1673. flattenListSelection(editor);
  1674. } else {
  1675. var bookmark = createBookmark(editor.selection.getRng(true));
  1676. updateListWithDetails(editor.dom, parentList, detail);
  1677. var newList = editor.dom.rename(parentList, listName);
  1678. mergeWithAdjacentLists(editor.dom, newList);
  1679. editor.selection.setRng(resolveBookmark(bookmark));
  1680. fireListEvent(editor, listToggleActionFromListName(listName), newList);
  1681. }
  1682. } else {
  1683. applyList(editor, listName, detail);
  1684. fireListEvent(editor, listToggleActionFromListName(listName), parentList);
  1685. }
  1686. };
  1687. var toggleList = function (editor, listName, detail) {
  1688. var parentList = getParentList(editor);
  1689. var selectedSubLists = getSelectedSubLists(editor);
  1690. detail = detail ? detail : {};
  1691. if (parentList && selectedSubLists.length > 0) {
  1692. toggleMultipleLists(editor, parentList, selectedSubLists, listName, detail);
  1693. } else {
  1694. toggleSingleList(editor, parentList, listName, detail);
  1695. }
  1696. };
  1697. var DOM$2 = global$6.DOM;
  1698. var normalizeList = function (dom, ul) {
  1699. var sibling;
  1700. var parentNode = ul.parentNode;
  1701. if (parentNode.nodeName === 'LI' && parentNode.firstChild === ul) {
  1702. sibling = parentNode.previousSibling;
  1703. if (sibling && sibling.nodeName === 'LI') {
  1704. sibling.appendChild(ul);
  1705. if (isEmpty(dom, parentNode)) {
  1706. DOM$2.remove(parentNode);
  1707. }
  1708. } else {
  1709. DOM$2.setStyle(parentNode, 'listStyleType', 'none');
  1710. }
  1711. }
  1712. if (isListNode(parentNode)) {
  1713. sibling = parentNode.previousSibling;
  1714. if (sibling && sibling.nodeName === 'LI') {
  1715. sibling.appendChild(ul);
  1716. }
  1717. }
  1718. };
  1719. var normalizeLists = function (dom, element) {
  1720. global$5.each(global$5.grep(dom.select('ol,ul', element)), function (ul) {
  1721. normalizeList(dom, ul);
  1722. });
  1723. };
  1724. var findNextCaretContainer = function (editor, rng, isForward, root) {
  1725. var node = rng.startContainer;
  1726. var offset = rng.startOffset;
  1727. if (isTextNode(node) && (isForward ? offset < node.data.length : offset > 0)) {
  1728. return node;
  1729. }
  1730. var nonEmptyBlocks = editor.schema.getNonEmptyElements();
  1731. if (node.nodeType === 1) {
  1732. node = global$1.getNode(node, offset);
  1733. }
  1734. var walker = new global$2(node, root);
  1735. if (isForward) {
  1736. if (isBogusBr(editor.dom, node)) {
  1737. walker.next();
  1738. }
  1739. }
  1740. while (node = walker[isForward ? 'next' : 'prev2']()) {
  1741. if (node.nodeName === 'LI' && !node.hasChildNodes()) {
  1742. return node;
  1743. }
  1744. if (nonEmptyBlocks[node.nodeName]) {
  1745. return node;
  1746. }
  1747. if (isTextNode(node) && node.data.length > 0) {
  1748. return node;
  1749. }
  1750. }
  1751. };
  1752. var hasOnlyOneBlockChild = function (dom, elm) {
  1753. var childNodes = elm.childNodes;
  1754. return childNodes.length === 1 && !isListNode(childNodes[0]) && dom.isBlock(childNodes[0]);
  1755. };
  1756. var unwrapSingleBlockChild = function (dom, elm) {
  1757. if (hasOnlyOneBlockChild(dom, elm)) {
  1758. dom.remove(elm.firstChild, true);
  1759. }
  1760. };
  1761. var moveChildren = function (dom, fromElm, toElm) {
  1762. var node, targetElm;
  1763. targetElm = hasOnlyOneBlockChild(dom, toElm) ? toElm.firstChild : toElm;
  1764. unwrapSingleBlockChild(dom, fromElm);
  1765. if (!isEmpty(dom, fromElm, true)) {
  1766. while (node = fromElm.firstChild) {
  1767. targetElm.appendChild(node);
  1768. }
  1769. }
  1770. };
  1771. var mergeLiElements = function (dom, fromElm, toElm) {
  1772. var node, listNode;
  1773. var ul = fromElm.parentNode;
  1774. if (!isChildOfBody(dom, fromElm) || !isChildOfBody(dom, toElm)) {
  1775. return;
  1776. }
  1777. if (isListNode(toElm.lastChild)) {
  1778. listNode = toElm.lastChild;
  1779. }
  1780. if (ul === toElm.lastChild) {
  1781. if (isBr(ul.previousSibling)) {
  1782. dom.remove(ul.previousSibling);
  1783. }
  1784. }
  1785. node = toElm.lastChild;
  1786. if (node && isBr(node) && fromElm.hasChildNodes()) {
  1787. dom.remove(node);
  1788. }
  1789. if (isEmpty(dom, toElm, true)) {
  1790. dom.$(toElm).empty();
  1791. }
  1792. moveChildren(dom, fromElm, toElm);
  1793. if (listNode) {
  1794. toElm.appendChild(listNode);
  1795. }
  1796. var contains = contains$1(Element.fromDom(toElm), Element.fromDom(fromElm));
  1797. var nestedLists = contains ? dom.getParents(fromElm, isListNode, toElm) : [];
  1798. dom.remove(fromElm);
  1799. each(nestedLists, function (list) {
  1800. if (isEmpty(dom, list) && list !== dom.getRoot()) {
  1801. dom.remove(list);
  1802. }
  1803. });
  1804. };
  1805. var mergeIntoEmptyLi = function (editor, fromLi, toLi) {
  1806. editor.dom.$(toLi).empty();
  1807. mergeLiElements(editor.dom, fromLi, toLi);
  1808. editor.selection.setCursorLocation(toLi);
  1809. };
  1810. var mergeForward = function (editor, rng, fromLi, toLi) {
  1811. var dom = editor.dom;
  1812. if (dom.isEmpty(toLi)) {
  1813. mergeIntoEmptyLi(editor, fromLi, toLi);
  1814. } else {
  1815. var bookmark = createBookmark(rng);
  1816. mergeLiElements(dom, fromLi, toLi);
  1817. editor.selection.setRng(resolveBookmark(bookmark));
  1818. }
  1819. };
  1820. var mergeBackward = function (editor, rng, fromLi, toLi) {
  1821. var bookmark = createBookmark(rng);
  1822. mergeLiElements(editor.dom, fromLi, toLi);
  1823. var resolvedBookmark = resolveBookmark(bookmark);
  1824. editor.selection.setRng(resolvedBookmark);
  1825. };
  1826. var backspaceDeleteFromListToListCaret = function (editor, isForward) {
  1827. var dom = editor.dom, selection = editor.selection;
  1828. var selectionStartElm = selection.getStart();
  1829. var root = getClosestListRootElm(editor, selectionStartElm);
  1830. var li = dom.getParent(selection.getStart(), 'LI', root);
  1831. if (li) {
  1832. var ul = li.parentNode;
  1833. if (ul === editor.getBody() && isEmpty(dom, ul)) {
  1834. return true;
  1835. }
  1836. var rng_1 = normalizeRange(selection.getRng());
  1837. var otherLi_1 = dom.getParent(findNextCaretContainer(editor, rng_1, isForward, root), 'LI', root);
  1838. if (otherLi_1 && otherLi_1 !== li) {
  1839. editor.undoManager.transact(function () {
  1840. if (isForward) {
  1841. mergeForward(editor, rng_1, otherLi_1, li);
  1842. } else {
  1843. if (isFirstChild(li)) {
  1844. outdentListSelection(editor);
  1845. } else {
  1846. mergeBackward(editor, rng_1, li, otherLi_1);
  1847. }
  1848. }
  1849. });
  1850. return true;
  1851. } else if (!otherLi_1) {
  1852. if (!isForward && rng_1.startOffset === 0 && rng_1.endOffset === 0) {
  1853. editor.undoManager.transact(function () {
  1854. flattenListSelection(editor);
  1855. });
  1856. return true;
  1857. }
  1858. }
  1859. }
  1860. return false;
  1861. };
  1862. var removeBlock = function (dom, block, root) {
  1863. var parentBlock = dom.getParent(block.parentNode, dom.isBlock, root);
  1864. dom.remove(block);
  1865. if (parentBlock && dom.isEmpty(parentBlock)) {
  1866. dom.remove(parentBlock);
  1867. }
  1868. };
  1869. var backspaceDeleteIntoListCaret = function (editor, isForward) {
  1870. var dom = editor.dom;
  1871. var selectionStartElm = editor.selection.getStart();
  1872. var root = getClosestListRootElm(editor, selectionStartElm);
  1873. var block = dom.getParent(selectionStartElm, dom.isBlock, root);
  1874. if (block && dom.isEmpty(block)) {
  1875. var rng = normalizeRange(editor.selection.getRng());
  1876. var otherLi_2 = dom.getParent(findNextCaretContainer(editor, rng, isForward, root), 'LI', root);
  1877. if (otherLi_2) {
  1878. editor.undoManager.transact(function () {
  1879. removeBlock(dom, block, root);
  1880. mergeWithAdjacentLists(dom, otherLi_2.parentNode);
  1881. editor.selection.select(otherLi_2, true);
  1882. editor.selection.collapse(isForward);
  1883. });
  1884. return true;
  1885. }
  1886. }
  1887. return false;
  1888. };
  1889. var backspaceDeleteCaret = function (editor, isForward) {
  1890. return backspaceDeleteFromListToListCaret(editor, isForward) || backspaceDeleteIntoListCaret(editor, isForward);
  1891. };
  1892. var backspaceDeleteRange = function (editor) {
  1893. var selectionStartElm = editor.selection.getStart();
  1894. var root = getClosestListRootElm(editor, selectionStartElm);
  1895. var startListParent = editor.dom.getParent(selectionStartElm, 'LI,DT,DD', root);
  1896. if (startListParent || getSelectedListItems(editor).length > 0) {
  1897. editor.undoManager.transact(function () {
  1898. editor.execCommand('Delete');
  1899. normalizeLists(editor.dom, editor.getBody());
  1900. });
  1901. return true;
  1902. }
  1903. return false;
  1904. };
  1905. var backspaceDelete = function (editor, isForward) {
  1906. return editor.selection.isCollapsed() ? backspaceDeleteCaret(editor, isForward) : backspaceDeleteRange(editor);
  1907. };
  1908. var setup = function (editor) {
  1909. editor.on('keydown', function (e) {
  1910. if (e.keyCode === global$3.BACKSPACE) {
  1911. if (backspaceDelete(editor, false)) {
  1912. e.preventDefault();
  1913. }
  1914. } else if (e.keyCode === global$3.DELETE) {
  1915. if (backspaceDelete(editor, true)) {
  1916. e.preventDefault();
  1917. }
  1918. }
  1919. });
  1920. };
  1921. var get = function (editor) {
  1922. return {
  1923. backspaceDelete: function (isForward) {
  1924. backspaceDelete(editor, isForward);
  1925. }
  1926. };
  1927. };
  1928. var open = function (editor) {
  1929. var dom = editor.dom;
  1930. var currentList = getParentList(editor);
  1931. if (!isOlNode(currentList)) {
  1932. return;
  1933. }
  1934. editor.windowManager.open({
  1935. title: 'List Properties',
  1936. body: {
  1937. type: 'panel',
  1938. items: [{
  1939. type: 'input',
  1940. name: 'start',
  1941. label: 'Start list at number',
  1942. inputMode: 'numeric'
  1943. }]
  1944. },
  1945. initialData: { start: dom.getAttrib(currentList, 'start') || '1' },
  1946. buttons: [
  1947. {
  1948. type: 'cancel',
  1949. name: 'cancel',
  1950. text: 'Cancel'
  1951. },
  1952. {
  1953. type: 'submit',
  1954. name: 'save',
  1955. text: 'Save',
  1956. primary: true
  1957. }
  1958. ],
  1959. onSubmit: function (api) {
  1960. var data = api.getData();
  1961. editor.undoManager.transact(function () {
  1962. dom.setAttrib(getParentList(editor), 'start', data.start === '1' ? '' : data.start);
  1963. });
  1964. api.close();
  1965. }
  1966. });
  1967. };
  1968. var queryListCommandState = function (editor, listName) {
  1969. return function () {
  1970. var parentList = editor.dom.getParent(editor.selection.getStart(), 'UL,OL,DL');
  1971. return parentList && parentList.nodeName === listName;
  1972. };
  1973. };
  1974. var register = function (editor) {
  1975. editor.on('BeforeExecCommand', function (e) {
  1976. var cmd = e.command.toLowerCase();
  1977. if (cmd === 'indent') {
  1978. indentListSelection(editor);
  1979. } else if (cmd === 'outdent') {
  1980. outdentListSelection(editor);
  1981. }
  1982. });
  1983. editor.addCommand('InsertUnorderedList', function (ui, detail) {
  1984. toggleList(editor, 'UL', detail);
  1985. });
  1986. editor.addCommand('InsertOrderedList', function (ui, detail) {
  1987. toggleList(editor, 'OL', detail);
  1988. });
  1989. editor.addCommand('InsertDefinitionList', function (ui, detail) {
  1990. toggleList(editor, 'DL', detail);
  1991. });
  1992. editor.addCommand('RemoveList', function () {
  1993. flattenListSelection(editor);
  1994. });
  1995. editor.addCommand('mceListProps', function () {
  1996. open(editor);
  1997. });
  1998. editor.addQueryStateHandler('InsertUnorderedList', queryListCommandState(editor, 'UL'));
  1999. editor.addQueryStateHandler('InsertOrderedList', queryListCommandState(editor, 'OL'));
  2000. editor.addQueryStateHandler('InsertDefinitionList', queryListCommandState(editor, 'DL'));
  2001. };
  2002. var hasRtcPlugin = function (editor) {
  2003. if (/(^|[ ,])rtc([, ]|$)/.test(editor.settings.plugins) && global.get('rtc')) {
  2004. return true;
  2005. } else {
  2006. return false;
  2007. }
  2008. };
  2009. var setupTabKey = function (editor) {
  2010. editor.on('keydown', function (e) {
  2011. if (e.keyCode !== global$3.TAB || global$3.metaKeyPressed(e)) {
  2012. return;
  2013. }
  2014. editor.undoManager.transact(function () {
  2015. if (e.shiftKey ? outdentListSelection(editor) : indentListSelection(editor)) {
  2016. e.preventDefault();
  2017. }
  2018. });
  2019. });
  2020. };
  2021. var setup$1 = function (editor) {
  2022. if (shouldIndentOnTab(editor)) {
  2023. setupTabKey(editor);
  2024. }
  2025. setup(editor);
  2026. };
  2027. var register$1 = function (editor) {
  2028. var hasPlugin = function (editor, plugin) {
  2029. var plugins = editor.settings.plugins ? editor.settings.plugins : '';
  2030. return global$5.inArray(plugins.split(/[ ,]/), plugin) !== -1;
  2031. };
  2032. var exec = function (command) {
  2033. return function () {
  2034. return editor.execCommand(command);
  2035. };
  2036. };
  2037. if (!hasPlugin(editor, 'advlist')) {
  2038. editor.ui.registry.addToggleButton('numlist', {
  2039. icon: 'ordered-list',
  2040. active: false,
  2041. tooltip: 'Numbered list',
  2042. onAction: exec('InsertOrderedList'),
  2043. onSetup: function (api) {
  2044. return listState(editor, 'OL', api.setActive);
  2045. }
  2046. });
  2047. editor.ui.registry.addToggleButton('bullist', {
  2048. icon: 'unordered-list',
  2049. active: false,
  2050. tooltip: 'Bullet list',
  2051. onAction: exec('InsertUnorderedList'),
  2052. onSetup: function (api) {
  2053. return listState(editor, 'UL', api.setActive);
  2054. }
  2055. });
  2056. }
  2057. };
  2058. var register$2 = function (editor) {
  2059. var listProperties = {
  2060. text: 'List properties...',
  2061. icon: 'ordered-list',
  2062. onAction: function () {
  2063. return open(editor);
  2064. },
  2065. onSetup: function (api) {
  2066. return listState(editor, 'OL', function (active) {
  2067. return api.setDisabled(!active);
  2068. });
  2069. }
  2070. };
  2071. editor.ui.registry.addMenuItem('listprops', listProperties);
  2072. editor.ui.registry.addContextMenu('lists', {
  2073. update: function (node) {
  2074. var parentList = getParentList(editor, node);
  2075. return isOlNode(parentList) ? ['listprops'] : [];
  2076. }
  2077. });
  2078. };
  2079. function Plugin () {
  2080. global.add('lists', function (editor) {
  2081. if (hasRtcPlugin(editor) === false) {
  2082. setup$1(editor);
  2083. register(editor);
  2084. }
  2085. register$1(editor);
  2086. register$2(editor);
  2087. return get(editor);
  2088. });
  2089. }
  2090. Plugin();
  2091. }(window));