Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

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