plugin.js 71 KB

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