plugin.js 68 KB

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