Нема описа

plugin.js 69KB

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