Subversion Repositories oidplus

Rev

Rev 1422 | View as "text/javascript" | Blame | Compare with Previous | Last modification | View Log | RSS feed

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