[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
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.5 (2022-05-25) 8 */ 9 (function () { 10 'use strict'; 11 12 var typeOf$1 = function (x) { 13 if (x === null) { 14 return 'null'; 15 } 16 if (x === undefined) { 17 return 'undefined'; 18 } 19 var t = typeof x; 20 if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) { 21 return 'array'; 22 } 23 if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) { 24 return 'string'; 25 } 26 return t; 27 }; 28 var isEquatableType = function (x) { 29 return [ 30 'undefined', 31 'boolean', 32 'number', 33 'string', 34 'function', 35 'xml', 36 'null' 37 ].indexOf(x) !== -1; 38 }; 39 40 var sort$1 = function (xs, compareFn) { 41 var clone = Array.prototype.slice.call(xs); 42 return clone.sort(compareFn); 43 }; 44 45 var contramap = function (eqa, f) { 46 return eq$2(function (x, y) { 47 return eqa.eq(f(x), f(y)); 48 }); 49 }; 50 var eq$2 = function (f) { 51 return { eq: f }; 52 }; 53 var tripleEq = eq$2(function (x, y) { 54 return x === y; 55 }); 56 var eqString = tripleEq; 57 var eqArray = function (eqa) { 58 return eq$2(function (x, y) { 59 if (x.length !== y.length) { 60 return false; 61 } 62 var len = x.length; 63 for (var i = 0; i < len; i++) { 64 if (!eqa.eq(x[i], y[i])) { 65 return false; 66 } 67 } 68 return true; 69 }); 70 }; 71 var eqSortedArray = function (eqa, compareFn) { 72 return contramap(eqArray(eqa), function (xs) { 73 return sort$1(xs, compareFn); 74 }); 75 }; 76 var eqRecord = function (eqa) { 77 return eq$2(function (x, y) { 78 var kx = Object.keys(x); 79 var ky = Object.keys(y); 80 if (!eqSortedArray(eqString).eq(kx, ky)) { 81 return false; 82 } 83 var len = kx.length; 84 for (var i = 0; i < len; i++) { 85 var q = kx[i]; 86 if (!eqa.eq(x[q], y[q])) { 87 return false; 88 } 89 } 90 return true; 91 }); 92 }; 93 var eqAny = eq$2(function (x, y) { 94 if (x === y) { 95 return true; 96 } 97 var tx = typeOf$1(x); 98 var ty = typeOf$1(y); 99 if (tx !== ty) { 100 return false; 101 } 102 if (isEquatableType(tx)) { 103 return x === y; 104 } else if (tx === 'array') { 105 return eqArray(eqAny).eq(x, y); 106 } else if (tx === 'object') { 107 return eqRecord(eqAny).eq(x, y); 108 } 109 return false; 110 }); 111 112 var typeOf = function (x) { 113 var t = typeof x; 114 if (x === null) { 115 return 'null'; 116 } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) { 117 return 'array'; 118 } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) { 119 return 'string'; 120 } else { 121 return t; 122 } 123 }; 124 var isType$1 = function (type) { 125 return function (value) { 126 return typeOf(value) === type; 127 }; 128 }; 129 var isSimpleType = function (type) { 130 return function (value) { 131 return typeof value === type; 132 }; 133 }; 134 var eq$1 = function (t) { 135 return function (a) { 136 return t === a; 137 }; 138 }; 139 var isString$1 = isType$1('string'); 140 var isObject = isType$1('object'); 141 var isArray$1 = isType$1('array'); 142 var isNull = eq$1(null); 143 var isBoolean = isSimpleType('boolean'); 144 var isUndefined = eq$1(undefined); 145 var isNullable = function (a) { 146 return a === null || a === undefined; 147 }; 148 var isNonNullable = function (a) { 149 return !isNullable(a); 150 }; 151 var isFunction = isSimpleType('function'); 152 var isNumber = isSimpleType('number'); 153 154 var noop = function () { 155 }; 156 var compose = function (fa, fb) { 157 return function () { 158 var args = []; 159 for (var _i = 0; _i < arguments.length; _i++) { 160 args[_i] = arguments[_i]; 161 } 162 return fa(fb.apply(null, args)); 163 }; 164 }; 165 var compose1 = function (fbc, fab) { 166 return function (a) { 167 return fbc(fab(a)); 168 }; 169 }; 170 var constant = function (value) { 171 return function () { 172 return value; 173 }; 174 }; 175 var identity = function (x) { 176 return x; 177 }; 178 var tripleEquals = function (a, b) { 179 return a === b; 180 }; 181 function curry(fn) { 182 var initialArgs = []; 183 for (var _i = 1; _i < arguments.length; _i++) { 184 initialArgs[_i - 1] = arguments[_i]; 185 } 186 return function () { 187 var restArgs = []; 188 for (var _i = 0; _i < arguments.length; _i++) { 189 restArgs[_i] = arguments[_i]; 190 } 191 var all = initialArgs.concat(restArgs); 192 return fn.apply(null, all); 193 }; 194 } 195 var not = function (f) { 196 return function (t) { 197 return !f(t); 198 }; 199 }; 200 var die = function (msg) { 201 return function () { 202 throw new Error(msg); 203 }; 204 }; 205 var apply = function (f) { 206 return f(); 207 }; 208 var call = function (f) { 209 f(); 210 }; 211 var never = constant(false); 212 var always = constant(true); 213 214 var none = function () { 215 return NONE; 216 }; 217 var NONE = function () { 218 var call = function (thunk) { 219 return thunk(); 220 }; 221 var id = identity; 222 var me = { 223 fold: function (n, _s) { 224 return n(); 225 }, 226 isSome: never, 227 isNone: always, 228 getOr: id, 229 getOrThunk: call, 230 getOrDie: function (msg) { 231 throw new Error(msg || 'error: getOrDie called on none.'); 232 }, 233 getOrNull: constant(null), 234 getOrUndefined: constant(undefined), 235 or: id, 236 orThunk: call, 237 map: none, 238 each: noop, 239 bind: none, 240 exists: never, 241 forall: always, 242 filter: function () { 243 return none(); 244 }, 245 toArray: function () { 246 return []; 247 }, 248 toString: constant('none()') 249 }; 250 return me; 251 }(); 252 var some = function (a) { 253 var constant_a = constant(a); 254 var self = function () { 255 return me; 256 }; 257 var bind = function (f) { 258 return f(a); 259 }; 260 var me = { 261 fold: function (n, s) { 262 return s(a); 263 }, 264 isSome: always, 265 isNone: never, 266 getOr: constant_a, 267 getOrThunk: constant_a, 268 getOrDie: constant_a, 269 getOrNull: constant_a, 270 getOrUndefined: constant_a, 271 or: self, 272 orThunk: self, 273 map: function (f) { 274 return some(f(a)); 275 }, 276 each: function (f) { 277 f(a); 278 }, 279 bind: bind, 280 exists: bind, 281 forall: bind, 282 filter: function (f) { 283 return f(a) ? me : NONE; 284 }, 285 toArray: function () { 286 return [a]; 287 }, 288 toString: function () { 289 return 'some(' + a + ')'; 290 } 291 }; 292 return me; 293 }; 294 var from$1 = function (value) { 295 return value === null || value === undefined ? NONE : some(value); 296 }; 297 var Optional = { 298 some: some, 299 none: none, 300 from: from$1 301 }; 302 303 var nativeSlice = Array.prototype.slice; 304 var nativeIndexOf = Array.prototype.indexOf; 305 var nativePush = Array.prototype.push; 306 var rawIndexOf = function (ts, t) { 307 return nativeIndexOf.call(ts, t); 308 }; 309 var indexOf$2 = function (xs, x) { 310 var r = rawIndexOf(xs, x); 311 return r === -1 ? Optional.none() : Optional.some(r); 312 }; 313 var contains$3 = function (xs, x) { 314 return rawIndexOf(xs, x) > -1; 315 }; 316 var exists = function (xs, pred) { 317 for (var i = 0, len = xs.length; i < len; i++) { 318 var x = xs[i]; 319 if (pred(x, i)) { 320 return true; 321 } 322 } 323 return false; 324 }; 325 var map$3 = function (xs, f) { 326 var len = xs.length; 327 var r = new Array(len); 328 for (var i = 0; i < len; i++) { 329 var x = xs[i]; 330 r[i] = f(x, i); 331 } 332 return r; 333 }; 334 var each$k = function (xs, f) { 335 for (var i = 0, len = xs.length; i < len; i++) { 336 var x = xs[i]; 337 f(x, i); 338 } 339 }; 340 var eachr = function (xs, f) { 341 for (var i = xs.length - 1; i >= 0; i--) { 342 var x = xs[i]; 343 f(x, i); 344 } 345 }; 346 var partition = function (xs, pred) { 347 var pass = []; 348 var fail = []; 349 for (var i = 0, len = xs.length; i < len; i++) { 350 var x = xs[i]; 351 var arr = pred(x, i) ? pass : fail; 352 arr.push(x); 353 } 354 return { 355 pass: pass, 356 fail: fail 357 }; 358 }; 359 var filter$4 = function (xs, pred) { 360 var r = []; 361 for (var i = 0, len = xs.length; i < len; i++) { 362 var x = xs[i]; 363 if (pred(x, i)) { 364 r.push(x); 365 } 366 } 367 return r; 368 }; 369 var foldr = function (xs, f, acc) { 370 eachr(xs, function (x, i) { 371 acc = f(acc, x, i); 372 }); 373 return acc; 374 }; 375 var foldl = function (xs, f, acc) { 376 each$k(xs, function (x, i) { 377 acc = f(acc, x, i); 378 }); 379 return acc; 380 }; 381 var findUntil$1 = function (xs, pred, until) { 382 for (var i = 0, len = xs.length; i < len; i++) { 383 var x = xs[i]; 384 if (pred(x, i)) { 385 return Optional.some(x); 386 } else if (until(x, i)) { 387 break; 388 } 389 } 390 return Optional.none(); 391 }; 392 var find$3 = function (xs, pred) { 393 return findUntil$1(xs, pred, never); 394 }; 395 var findIndex$2 = function (xs, pred) { 396 for (var i = 0, len = xs.length; i < len; i++) { 397 var x = xs[i]; 398 if (pred(x, i)) { 399 return Optional.some(i); 400 } 401 } 402 return Optional.none(); 403 }; 404 var flatten = function (xs) { 405 var r = []; 406 for (var i = 0, len = xs.length; i < len; ++i) { 407 if (!isArray$1(xs[i])) { 408 throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs); 409 } 410 nativePush.apply(r, xs[i]); 411 } 412 return r; 413 }; 414 var bind = function (xs, f) { 415 return flatten(map$3(xs, f)); 416 }; 417 var forall = function (xs, pred) { 418 for (var i = 0, len = xs.length; i < len; ++i) { 419 var x = xs[i]; 420 if (pred(x, i) !== true) { 421 return false; 422 } 423 } 424 return true; 425 }; 426 var reverse = function (xs) { 427 var r = nativeSlice.call(xs, 0); 428 r.reverse(); 429 return r; 430 }; 431 var difference = function (a1, a2) { 432 return filter$4(a1, function (x) { 433 return !contains$3(a2, x); 434 }); 435 }; 436 var mapToObject = function (xs, f) { 437 var r = {}; 438 for (var i = 0, len = xs.length; i < len; i++) { 439 var x = xs[i]; 440 r[String(x)] = f(x, i); 441 } 442 return r; 443 }; 444 var sort = function (xs, comparator) { 445 var copy = nativeSlice.call(xs, 0); 446 copy.sort(comparator); 447 return copy; 448 }; 449 var get$a = function (xs, i) { 450 return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none(); 451 }; 452 var head = function (xs) { 453 return get$a(xs, 0); 454 }; 455 var last$2 = function (xs) { 456 return get$a(xs, xs.length - 1); 457 }; 458 var from = isFunction(Array.from) ? Array.from : function (x) { 459 return nativeSlice.call(x); 460 }; 461 var findMap = function (arr, f) { 462 for (var i = 0; i < arr.length; i++) { 463 var r = f(arr[i], i); 464 if (r.isSome()) { 465 return r; 466 } 467 } 468 return Optional.none(); 469 }; 470 471 var keys = Object.keys; 472 var hasOwnProperty$1 = Object.hasOwnProperty; 473 var each$j = function (obj, f) { 474 var props = keys(obj); 475 for (var k = 0, len = props.length; k < len; k++) { 476 var i = props[k]; 477 var x = obj[i]; 478 f(x, i); 479 } 480 }; 481 var map$2 = function (obj, f) { 482 return tupleMap(obj, function (x, i) { 483 return { 484 k: i, 485 v: f(x, i) 486 }; 487 }); 488 }; 489 var tupleMap = function (obj, f) { 490 var r = {}; 491 each$j(obj, function (x, i) { 492 var tuple = f(x, i); 493 r[tuple.k] = tuple.v; 494 }); 495 return r; 496 }; 497 var objAcc = function (r) { 498 return function (x, i) { 499 r[i] = x; 500 }; 501 }; 502 var internalFilter = function (obj, pred, onTrue, onFalse) { 503 var r = {}; 504 each$j(obj, function (x, i) { 505 (pred(x, i) ? onTrue : onFalse)(x, i); 506 }); 507 return r; 508 }; 509 var bifilter = function (obj, pred) { 510 var t = {}; 511 var f = {}; 512 internalFilter(obj, pred, objAcc(t), objAcc(f)); 513 return { 514 t: t, 515 f: f 516 }; 517 }; 518 var filter$3 = function (obj, pred) { 519 var t = {}; 520 internalFilter(obj, pred, objAcc(t), noop); 521 return t; 522 }; 523 var mapToArray = function (obj, f) { 524 var r = []; 525 each$j(obj, function (value, name) { 526 r.push(f(value, name)); 527 }); 528 return r; 529 }; 530 var values = function (obj) { 531 return mapToArray(obj, identity); 532 }; 533 var get$9 = function (obj, key) { 534 return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none(); 535 }; 536 var has$2 = function (obj, key) { 537 return hasOwnProperty$1.call(obj, key); 538 }; 539 var hasNonNullableKey = function (obj, key) { 540 return has$2(obj, key) && obj[key] !== undefined && obj[key] !== null; 541 }; 542 var equal$1 = function (a1, a2, eq) { 543 if (eq === void 0) { 544 eq = eqAny; 545 } 546 return eqRecord(eq).eq(a1, a2); 547 }; 548 549 var isArray = Array.isArray; 550 var toArray$1 = function (obj) { 551 if (!isArray(obj)) { 552 var array = []; 553 for (var i = 0, l = obj.length; i < l; i++) { 554 array[i] = obj[i]; 555 } 556 return array; 557 } else { 558 return obj; 559 } 560 }; 561 var each$i = function (o, cb, s) { 562 var n, l; 563 if (!o) { 564 return false; 565 } 566 s = s || o; 567 if (o.length !== undefined) { 568 for (n = 0, l = o.length; n < l; n++) { 569 if (cb.call(s, o[n], n, o) === false) { 570 return false; 571 } 572 } 573 } else { 574 for (n in o) { 575 if (has$2(o, n)) { 576 if (cb.call(s, o[n], n, o) === false) { 577 return false; 578 } 579 } 580 } 581 } 582 return true; 583 }; 584 var map$1 = function (array, callback) { 585 var out = []; 586 each$i(array, function (item, index) { 587 out.push(callback(item, index, array)); 588 }); 589 return out; 590 }; 591 var filter$2 = function (a, f) { 592 var o = []; 593 each$i(a, function (v, index) { 594 if (!f || f(v, index, a)) { 595 o.push(v); 596 } 597 }); 598 return o; 599 }; 600 var indexOf$1 = function (a, v) { 601 if (a) { 602 for (var i = 0, l = a.length; i < l; i++) { 603 if (a[i] === v) { 604 return i; 605 } 606 } 607 } 608 return -1; 609 }; 610 var reduce = function (collection, iteratee, accumulator, thisArg) { 611 var acc = isUndefined(accumulator) ? collection[0] : accumulator; 612 for (var i = 0; i < collection.length; i++) { 613 acc = iteratee.call(thisArg, acc, collection[i], i); 614 } 615 return acc; 616 }; 617 var findIndex$1 = function (array, predicate, thisArg) { 618 var i, l; 619 for (i = 0, l = array.length; i < l; i++) { 620 if (predicate.call(thisArg, array[i], i, array)) { 621 return i; 622 } 623 } 624 return -1; 625 }; 626 var last$1 = function (collection) { 627 return collection[collection.length - 1]; 628 }; 629 630 var __assign = function () { 631 __assign = Object.assign || function __assign(t) { 632 for (var s, i = 1, n = arguments.length; i < n; i++) { 633 s = arguments[i]; 634 for (var p in s) 635 if (Object.prototype.hasOwnProperty.call(s, p)) 636 t[p] = s[p]; 637 } 638 return t; 639 }; 640 return __assign.apply(this, arguments); 641 }; 642 function __rest(s, e) { 643 var t = {}; 644 for (var p in s) 645 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) 646 t[p] = s[p]; 647 if (s != null && typeof Object.getOwnPropertySymbols === 'function') 648 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { 649 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) 650 t[p[i]] = s[p[i]]; 651 } 652 return t; 653 } 654 function __spreadArray(to, from, pack) { 655 if (pack || arguments.length === 2) 656 for (var i = 0, l = from.length, ar; i < l; i++) { 657 if (ar || !(i in from)) { 658 if (!ar) 659 ar = Array.prototype.slice.call(from, 0, i); 660 ar[i] = from[i]; 661 } 662 } 663 return to.concat(ar || Array.prototype.slice.call(from)); 664 } 665 666 var cached = function (f) { 667 var called = false; 668 var r; 669 return function () { 670 var args = []; 671 for (var _i = 0; _i < arguments.length; _i++) { 672 args[_i] = arguments[_i]; 673 } 674 if (!called) { 675 called = true; 676 r = f.apply(null, args); 677 } 678 return r; 679 }; 680 }; 681 682 var DeviceType = function (os, browser, userAgent, mediaMatch) { 683 var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true; 684 var isiPhone = os.isiOS() && !isiPad; 685 var isMobile = os.isiOS() || os.isAndroid(); 686 var isTouch = isMobile || mediaMatch('(pointer:coarse)'); 687 var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)'); 688 var isPhone = isiPhone || isMobile && !isTablet; 689 var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false; 690 var isDesktop = !isPhone && !isTablet && !iOSwebview; 691 return { 692 isiPad: constant(isiPad), 693 isiPhone: constant(isiPhone), 694 isTablet: constant(isTablet), 695 isPhone: constant(isPhone), 696 isTouch: constant(isTouch), 697 isAndroid: os.isAndroid, 698 isiOS: os.isiOS, 699 isWebView: constant(iOSwebview), 700 isDesktop: constant(isDesktop) 701 }; 702 }; 703 704 var firstMatch = function (regexes, s) { 705 for (var i = 0; i < regexes.length; i++) { 706 var x = regexes[i]; 707 if (x.test(s)) { 708 return x; 709 } 710 } 711 return undefined; 712 }; 713 var find$2 = function (regexes, agent) { 714 var r = firstMatch(regexes, agent); 715 if (!r) { 716 return { 717 major: 0, 718 minor: 0 719 }; 720 } 721 var group = function (i) { 722 return Number(agent.replace(r, '$' + i)); 723 }; 724 return nu$4(group(1), group(2)); 725 }; 726 var detect$3 = function (versionRegexes, agent) { 727 var cleanedAgent = String(agent).toLowerCase(); 728 if (versionRegexes.length === 0) { 729 return unknown$2(); 730 } 731 return find$2(versionRegexes, cleanedAgent); 732 }; 733 var unknown$2 = function () { 734 return nu$4(0, 0); 735 }; 736 var nu$4 = function (major, minor) { 737 return { 738 major: major, 739 minor: minor 740 }; 741 }; 742 var Version = { 743 nu: nu$4, 744 detect: detect$3, 745 unknown: unknown$2 746 }; 747 748 var detectBrowser$1 = function (browsers, userAgentData) { 749 return findMap(userAgentData.brands, function (uaBrand) { 750 var lcBrand = uaBrand.brand.toLowerCase(); 751 return find$3(browsers, function (browser) { 752 var _a; 753 return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase()); 754 }).map(function (info) { 755 return { 756 current: info.name, 757 version: Version.nu(parseInt(uaBrand.version, 10), 0) 758 }; 759 }); 760 }); 761 }; 762 763 var detect$2 = function (candidates, userAgent) { 764 var agent = String(userAgent).toLowerCase(); 765 return find$3(candidates, function (candidate) { 766 return candidate.search(agent); 767 }); 768 }; 769 var detectBrowser = function (browsers, userAgent) { 770 return detect$2(browsers, userAgent).map(function (browser) { 771 var version = Version.detect(browser.versionRegexes, userAgent); 772 return { 773 current: browser.name, 774 version: version 775 }; 776 }); 777 }; 778 var detectOs = function (oses, userAgent) { 779 return detect$2(oses, userAgent).map(function (os) { 780 var version = Version.detect(os.versionRegexes, userAgent); 781 return { 782 current: os.name, 783 version: version 784 }; 785 }); 786 }; 787 788 var removeFromStart = function (str, numChars) { 789 return str.substring(numChars); 790 }; 791 792 var checkRange = function (str, substr, start) { 793 return substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr; 794 }; 795 var removeLeading = function (str, prefix) { 796 return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str; 797 }; 798 var contains$2 = function (str, substr) { 799 return str.indexOf(substr) !== -1; 800 }; 801 var startsWith = function (str, prefix) { 802 return checkRange(str, prefix, 0); 803 }; 804 var blank = function (r) { 805 return function (s) { 806 return s.replace(r, ''); 807 }; 808 }; 809 var trim$4 = blank(/^\s+|\s+$/g); 810 var lTrim = blank(/^\s+/g); 811 var rTrim = blank(/\s+$/g); 812 var isNotEmpty = function (s) { 813 return s.length > 0; 814 }; 815 var isEmpty$3 = function (s) { 816 return !isNotEmpty(s); 817 }; 818 819 var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/; 820 var checkContains = function (target) { 821 return function (uastring) { 822 return contains$2(uastring, target); 823 }; 824 }; 825 var browsers = [ 826 { 827 name: 'Edge', 828 versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/], 829 search: function (uastring) { 830 return contains$2(uastring, 'edge/') && contains$2(uastring, 'chrome') && contains$2(uastring, 'safari') && contains$2(uastring, 'applewebkit'); 831 } 832 }, 833 { 834 name: 'Chrome', 835 brand: 'Chromium', 836 versionRegexes: [ 837 /.*?chrome\/([0-9]+)\.([0-9]+).*/, 838 normalVersionRegex 839 ], 840 search: function (uastring) { 841 return contains$2(uastring, 'chrome') && !contains$2(uastring, 'chromeframe'); 842 } 843 }, 844 { 845 name: 'IE', 846 versionRegexes: [ 847 /.*?msie\ ?([0-9]+)\.([0-9]+).*/, 848 /.*?rv:([0-9]+)\.([0-9]+).*/ 849 ], 850 search: function (uastring) { 851 return contains$2(uastring, 'msie') || contains$2(uastring, 'trident'); 852 } 853 }, 854 { 855 name: 'Opera', 856 versionRegexes: [ 857 normalVersionRegex, 858 /.*?opera\/([0-9]+)\.([0-9]+).*/ 859 ], 860 search: checkContains('opera') 861 }, 862 { 863 name: 'Firefox', 864 versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/], 865 search: checkContains('firefox') 866 }, 867 { 868 name: 'Safari', 869 versionRegexes: [ 870 normalVersionRegex, 871 /.*?cpu os ([0-9]+)_([0-9]+).*/ 872 ], 873 search: function (uastring) { 874 return (contains$2(uastring, 'safari') || contains$2(uastring, 'mobile/')) && contains$2(uastring, 'applewebkit'); 875 } 876 } 877 ]; 878 var oses = [ 879 { 880 name: 'Windows', 881 search: checkContains('win'), 882 versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/] 883 }, 884 { 885 name: 'iOS', 886 search: function (uastring) { 887 return contains$2(uastring, 'iphone') || contains$2(uastring, 'ipad'); 888 }, 889 versionRegexes: [ 890 /.*?version\/\ ?([0-9]+)\.([0-9]+).*/, 891 /.*cpu os ([0-9]+)_([0-9]+).*/, 892 /.*cpu iphone os ([0-9]+)_([0-9]+).*/ 893 ] 894 }, 895 { 896 name: 'Android', 897 search: checkContains('android'), 898 versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/] 899 }, 900 { 901 name: 'OSX', 902 search: checkContains('mac os x'), 903 versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/] 904 }, 905 { 906 name: 'Linux', 907 search: checkContains('linux'), 908 versionRegexes: [] 909 }, 910 { 911 name: 'Solaris', 912 search: checkContains('sunos'), 913 versionRegexes: [] 914 }, 915 { 916 name: 'FreeBSD', 917 search: checkContains('freebsd'), 918 versionRegexes: [] 919 }, 920 { 921 name: 'ChromeOS', 922 search: checkContains('cros'), 923 versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/] 924 } 925 ]; 926 var PlatformInfo = { 927 browsers: constant(browsers), 928 oses: constant(oses) 929 }; 930 931 var edge = 'Edge'; 932 var chrome = 'Chrome'; 933 var ie$1 = 'IE'; 934 var opera = 'Opera'; 935 var firefox = 'Firefox'; 936 var safari = 'Safari'; 937 var unknown$1 = function () { 938 return nu$3({ 939 current: undefined, 940 version: Version.unknown() 941 }); 942 }; 943 var nu$3 = function (info) { 944 var current = info.current; 945 var version = info.version; 946 var isBrowser = function (name) { 947 return function () { 948 return current === name; 949 }; 950 }; 951 return { 952 current: current, 953 version: version, 954 isEdge: isBrowser(edge), 955 isChrome: isBrowser(chrome), 956 isIE: isBrowser(ie$1), 957 isOpera: isBrowser(opera), 958 isFirefox: isBrowser(firefox), 959 isSafari: isBrowser(safari) 960 }; 961 }; 962 var Browser = { 963 unknown: unknown$1, 964 nu: nu$3, 965 edge: constant(edge), 966 chrome: constant(chrome), 967 ie: constant(ie$1), 968 opera: constant(opera), 969 firefox: constant(firefox), 970 safari: constant(safari) 971 }; 972 973 var windows = 'Windows'; 974 var ios = 'iOS'; 975 var android = 'Android'; 976 var linux = 'Linux'; 977 var osx = 'OSX'; 978 var solaris = 'Solaris'; 979 var freebsd = 'FreeBSD'; 980 var chromeos = 'ChromeOS'; 981 var unknown = function () { 982 return nu$2({ 983 current: undefined, 984 version: Version.unknown() 985 }); 986 }; 987 var nu$2 = function (info) { 988 var current = info.current; 989 var version = info.version; 990 var isOS = function (name) { 991 return function () { 992 return current === name; 993 }; 994 }; 995 return { 996 current: current, 997 version: version, 998 isWindows: isOS(windows), 999 isiOS: isOS(ios), 1000 isAndroid: isOS(android), 1001 isOSX: isOS(osx), 1002 isLinux: isOS(linux), 1003 isSolaris: isOS(solaris), 1004 isFreeBSD: isOS(freebsd), 1005 isChromeOS: isOS(chromeos) 1006 }; 1007 }; 1008 var OperatingSystem = { 1009 unknown: unknown, 1010 nu: nu$2, 1011 windows: constant(windows), 1012 ios: constant(ios), 1013 android: constant(android), 1014 linux: constant(linux), 1015 osx: constant(osx), 1016 solaris: constant(solaris), 1017 freebsd: constant(freebsd), 1018 chromeos: constant(chromeos) 1019 }; 1020 1021 var detect$1 = function (userAgent, userAgentDataOpt, mediaMatch) { 1022 var browsers = PlatformInfo.browsers(); 1023 var oses = PlatformInfo.oses(); 1024 var browser = userAgentDataOpt.bind(function (userAgentData) { 1025 return detectBrowser$1(browsers, userAgentData); 1026 }).orThunk(function () { 1027 return detectBrowser(browsers, userAgent); 1028 }).fold(Browser.unknown, Browser.nu); 1029 var os = detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu); 1030 var deviceType = DeviceType(os, browser, userAgent, mediaMatch); 1031 return { 1032 browser: browser, 1033 os: os, 1034 deviceType: deviceType 1035 }; 1036 }; 1037 var PlatformDetection = { detect: detect$1 }; 1038 1039 var mediaMatch = function (query) { 1040 return window.matchMedia(query).matches; 1041 }; 1042 var platform$2 = cached(function () { 1043 return PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch); 1044 }); 1045 var detect = function () { 1046 return platform$2(); 1047 }; 1048 1049 var userAgent = navigator.userAgent; 1050 var platform$1 = detect(); 1051 var browser$4 = platform$1.browser; 1052 var os = platform$1.os; 1053 var deviceType = platform$1.deviceType; 1054 var webkit = /WebKit/.test(userAgent) && !browser$4.isEdge(); 1055 var fileApi = 'FormData' in window && 'FileReader' in window && 'URL' in window && !!URL.createObjectURL; 1056 var windowsPhone = userAgent.indexOf('Windows Phone') !== -1; 1057 var Env = { 1058 opera: browser$4.isOpera(), 1059 webkit: webkit, 1060 ie: browser$4.isIE() || browser$4.isEdge() ? browser$4.version.major : false, 1061 gecko: browser$4.isFirefox(), 1062 mac: os.isOSX() || os.isiOS(), 1063 iOS: deviceType.isiPad() || deviceType.isiPhone(), 1064 android: os.isAndroid(), 1065 contentEditable: true, 1066 transparentSrc: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 1067 caretAfter: true, 1068 range: window.getSelection && 'Range' in window, 1069 documentMode: browser$4.isIE() ? document.documentMode || 7 : 10, 1070 fileApi: fileApi, 1071 ceFalse: true, 1072 cacheSuffix: null, 1073 container: null, 1074 experimentalShadowDom: false, 1075 canHaveCSP: !browser$4.isIE(), 1076 desktop: deviceType.isDesktop(), 1077 windowsPhone: windowsPhone, 1078 browser: { 1079 current: browser$4.current, 1080 version: browser$4.version, 1081 isChrome: browser$4.isChrome, 1082 isEdge: browser$4.isEdge, 1083 isFirefox: browser$4.isFirefox, 1084 isIE: browser$4.isIE, 1085 isOpera: browser$4.isOpera, 1086 isSafari: browser$4.isSafari 1087 }, 1088 os: { 1089 current: os.current, 1090 version: os.version, 1091 isAndroid: os.isAndroid, 1092 isChromeOS: os.isChromeOS, 1093 isFreeBSD: os.isFreeBSD, 1094 isiOS: os.isiOS, 1095 isLinux: os.isLinux, 1096 isOSX: os.isOSX, 1097 isSolaris: os.isSolaris, 1098 isWindows: os.isWindows 1099 }, 1100 deviceType: { 1101 isDesktop: deviceType.isDesktop, 1102 isiPad: deviceType.isiPad, 1103 isiPhone: deviceType.isiPhone, 1104 isPhone: deviceType.isPhone, 1105 isTablet: deviceType.isTablet, 1106 isTouch: deviceType.isTouch, 1107 isWebView: deviceType.isWebView 1108 } 1109 }; 1110 1111 var whiteSpaceRegExp$2 = /^\s*|\s*$/g; 1112 var trim$3 = function (str) { 1113 return str === null || str === undefined ? '' : ('' + str).replace(whiteSpaceRegExp$2, ''); 1114 }; 1115 var is$3 = function (obj, type) { 1116 if (!type) { 1117 return obj !== undefined; 1118 } 1119 if (type === 'array' && isArray(obj)) { 1120 return true; 1121 } 1122 return typeof obj === type; 1123 }; 1124 var makeMap$4 = function (items, delim, map) { 1125 var i; 1126 items = items || []; 1127 delim = delim || ','; 1128 if (typeof items === 'string') { 1129 items = items.split(delim); 1130 } 1131 map = map || {}; 1132 i = items.length; 1133 while (i--) { 1134 map[items[i]] = {}; 1135 } 1136 return map; 1137 }; 1138 var hasOwnProperty = has$2; 1139 var create$9 = function (s, p, root) { 1140 var self = this; 1141 var sp, scn, c, de = 0; 1142 s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); 1143 var cn = s[3].match(/(^|\.)(\w+)$/i)[2]; 1144 var ns = self.createNS(s[3].replace(/\.\w+$/, ''), root); 1145 if (ns[cn]) { 1146 return; 1147 } 1148 if (s[2] === 'static') { 1149 ns[cn] = p; 1150 if (this.onCreate) { 1151 this.onCreate(s[2], s[3], ns[cn]); 1152 } 1153 return; 1154 } 1155 if (!p[cn]) { 1156 p[cn] = function () { 1157 }; 1158 de = 1; 1159 } 1160 ns[cn] = p[cn]; 1161 self.extend(ns[cn].prototype, p); 1162 if (s[5]) { 1163 sp = self.resolve(s[5]).prototype; 1164 scn = s[5].match(/\.(\w+)$/i)[1]; 1165 c = ns[cn]; 1166 if (de) { 1167 ns[cn] = function () { 1168 return sp[scn].apply(this, arguments); 1169 }; 1170 } else { 1171 ns[cn] = function () { 1172 this.parent = sp[scn]; 1173 return c.apply(this, arguments); 1174 }; 1175 } 1176 ns[cn].prototype[cn] = ns[cn]; 1177 self.each(sp, function (f, n) { 1178 ns[cn].prototype[n] = sp[n]; 1179 }); 1180 self.each(p, function (f, n) { 1181 if (sp[n]) { 1182 ns[cn].prototype[n] = function () { 1183 this.parent = sp[n]; 1184 return f.apply(this, arguments); 1185 }; 1186 } else { 1187 if (n !== cn) { 1188 ns[cn].prototype[n] = f; 1189 } 1190 } 1191 }); 1192 } 1193 self.each(p.static, function (f, n) { 1194 ns[cn][n] = f; 1195 }); 1196 }; 1197 var extend$6 = function (obj) { 1198 var exts = []; 1199 for (var _i = 1; _i < arguments.length; _i++) { 1200 exts[_i - 1] = arguments[_i]; 1201 } 1202 for (var i = 0; i < exts.length; i++) { 1203 var ext = exts[i]; 1204 for (var name_1 in ext) { 1205 if (has$2(ext, name_1)) { 1206 var value = ext[name_1]; 1207 if (value !== undefined) { 1208 obj[name_1] = value; 1209 } 1210 } 1211 } 1212 } 1213 return obj; 1214 }; 1215 var walk$3 = function (o, f, n, s) { 1216 s = s || this; 1217 if (o) { 1218 if (n) { 1219 o = o[n]; 1220 } 1221 each$i(o, function (o, i) { 1222 if (f.call(s, o, i, n) === false) { 1223 return false; 1224 } 1225 walk$3(o, f, n, s); 1226 }); 1227 } 1228 }; 1229 var createNS = function (n, o) { 1230 var i, v; 1231 o = o || window; 1232 n = n.split('.'); 1233 for (i = 0; i < n.length; i++) { 1234 v = n[i]; 1235 if (!o[v]) { 1236 o[v] = {}; 1237 } 1238 o = o[v]; 1239 } 1240 return o; 1241 }; 1242 var resolve$3 = function (n, o) { 1243 var i, l; 1244 o = o || window; 1245 n = n.split('.'); 1246 for (i = 0, l = n.length; i < l; i++) { 1247 o = o[n[i]]; 1248 if (!o) { 1249 break; 1250 } 1251 } 1252 return o; 1253 }; 1254 var explode$4 = function (s, d) { 1255 if (!s || is$3(s, 'array')) { 1256 return s; 1257 } 1258 return map$1(s.split(d || ','), trim$3); 1259 }; 1260 var _addCacheSuffix = function (url) { 1261 var cacheSuffix = Env.cacheSuffix; 1262 if (cacheSuffix) { 1263 url += (url.indexOf('?') === -1 ? '?' : '&') + cacheSuffix; 1264 } 1265 return url; 1266 }; 1267 var Tools = { 1268 trim: trim$3, 1269 isArray: isArray, 1270 is: is$3, 1271 toArray: toArray$1, 1272 makeMap: makeMap$4, 1273 each: each$i, 1274 map: map$1, 1275 grep: filter$2, 1276 inArray: indexOf$1, 1277 hasOwn: hasOwnProperty, 1278 extend: extend$6, 1279 create: create$9, 1280 walk: walk$3, 1281 createNS: createNS, 1282 resolve: resolve$3, 1283 explode: explode$4, 1284 _addCacheSuffix: _addCacheSuffix 1285 }; 1286 1287 var fromHtml$1 = function (html, scope) { 1288 var doc = scope || document; 1289 var div = doc.createElement('div'); 1290 div.innerHTML = html; 1291 if (!div.hasChildNodes() || div.childNodes.length > 1) { 1292 console.error('HTML does not have a single root node', html); 1293 throw new Error('HTML must have a single root node'); 1294 } 1295 return fromDom$2(div.childNodes[0]); 1296 }; 1297 var fromTag = function (tag, scope) { 1298 var doc = scope || document; 1299 var node = doc.createElement(tag); 1300 return fromDom$2(node); 1301 }; 1302 var fromText = function (text, scope) { 1303 var doc = scope || document; 1304 var node = doc.createTextNode(text); 1305 return fromDom$2(node); 1306 }; 1307 var fromDom$2 = function (node) { 1308 if (node === null || node === undefined) { 1309 throw new Error('Node cannot be null or undefined'); 1310 } 1311 return { dom: node }; 1312 }; 1313 var fromPoint$1 = function (docElm, x, y) { 1314 return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$2); 1315 }; 1316 var SugarElement = { 1317 fromHtml: fromHtml$1, 1318 fromTag: fromTag, 1319 fromText: fromText, 1320 fromDom: fromDom$2, 1321 fromPoint: fromPoint$1 1322 }; 1323 1324 var toArray = function (target, f) { 1325 var r = []; 1326 var recurse = function (e) { 1327 r.push(e); 1328 return f(e); 1329 }; 1330 var cur = f(target); 1331 do { 1332 cur = cur.bind(recurse); 1333 } while (cur.isSome()); 1334 return r; 1335 }; 1336 1337 var compareDocumentPosition = function (a, b, match) { 1338 return (a.compareDocumentPosition(b) & match) !== 0; 1339 }; 1340 var documentPositionContainedBy = function (a, b) { 1341 return compareDocumentPosition(a, b, Node.DOCUMENT_POSITION_CONTAINED_BY); 1342 }; 1343 1344 var COMMENT = 8; 1345 var DOCUMENT = 9; 1346 var DOCUMENT_FRAGMENT = 11; 1347 var ELEMENT = 1; 1348 var TEXT = 3; 1349 1350 var is$2 = function (element, selector) { 1351 var dom = element.dom; 1352 if (dom.nodeType !== ELEMENT) { 1353 return false; 1354 } else { 1355 var elem = dom; 1356 if (elem.matches !== undefined) { 1357 return elem.matches(selector); 1358 } else if (elem.msMatchesSelector !== undefined) { 1359 return elem.msMatchesSelector(selector); 1360 } else if (elem.webkitMatchesSelector !== undefined) { 1361 return elem.webkitMatchesSelector(selector); 1362 } else if (elem.mozMatchesSelector !== undefined) { 1363 return elem.mozMatchesSelector(selector); 1364 } else { 1365 throw new Error('Browser lacks native selectors'); 1366 } 1367 } 1368 }; 1369 var bypassSelector = function (dom) { 1370 return dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0; 1371 }; 1372 var all = function (selector, scope) { 1373 var base = scope === undefined ? document : scope.dom; 1374 return bypassSelector(base) ? [] : map$3(base.querySelectorAll(selector), SugarElement.fromDom); 1375 }; 1376 var one = function (selector, scope) { 1377 var base = scope === undefined ? document : scope.dom; 1378 return bypassSelector(base) ? Optional.none() : Optional.from(base.querySelector(selector)).map(SugarElement.fromDom); 1379 }; 1380 1381 var eq = function (e1, e2) { 1382 return e1.dom === e2.dom; 1383 }; 1384 var regularContains = function (e1, e2) { 1385 var d1 = e1.dom; 1386 var d2 = e2.dom; 1387 return d1 === d2 ? false : d1.contains(d2); 1388 }; 1389 var ieContains = function (e1, e2) { 1390 return documentPositionContainedBy(e1.dom, e2.dom); 1391 }; 1392 var contains$1 = function (e1, e2) { 1393 return detect().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2); 1394 }; 1395 1396 typeof window !== 'undefined' ? window : Function('return this;')(); 1397 1398 var name = function (element) { 1399 var r = element.dom.nodeName; 1400 return r.toLowerCase(); 1401 }; 1402 var type = function (element) { 1403 return element.dom.nodeType; 1404 }; 1405 var isType = function (t) { 1406 return function (element) { 1407 return type(element) === t; 1408 }; 1409 }; 1410 var isComment$1 = function (element) { 1411 return type(element) === COMMENT || name(element) === '#comment'; 1412 }; 1413 var isElement$6 = isType(ELEMENT); 1414 var isText$8 = isType(TEXT); 1415 var isDocument$2 = isType(DOCUMENT); 1416 var isDocumentFragment$1 = isType(DOCUMENT_FRAGMENT); 1417 var isTag = function (tag) { 1418 return function (e) { 1419 return isElement$6(e) && name(e) === tag; 1420 }; 1421 }; 1422 1423 var owner$1 = function (element) { 1424 return SugarElement.fromDom(element.dom.ownerDocument); 1425 }; 1426 var documentOrOwner = function (dos) { 1427 return isDocument$2(dos) ? dos : owner$1(dos); 1428 }; 1429 var documentElement = function (element) { 1430 return SugarElement.fromDom(documentOrOwner(element).dom.documentElement); 1431 }; 1432 var defaultView = function (element) { 1433 return SugarElement.fromDom(documentOrOwner(element).dom.defaultView); 1434 }; 1435 var parent = function (element) { 1436 return Optional.from(element.dom.parentNode).map(SugarElement.fromDom); 1437 }; 1438 var parents$1 = function (element, isRoot) { 1439 var stop = isFunction(isRoot) ? isRoot : never; 1440 var dom = element.dom; 1441 var ret = []; 1442 while (dom.parentNode !== null && dom.parentNode !== undefined) { 1443 var rawParent = dom.parentNode; 1444 var p = SugarElement.fromDom(rawParent); 1445 ret.push(p); 1446 if (stop(p) === true) { 1447 break; 1448 } else { 1449 dom = rawParent; 1450 } 1451 } 1452 return ret; 1453 }; 1454 var siblings = function (element) { 1455 var filterSelf = function (elements) { 1456 return filter$4(elements, function (x) { 1457 return !eq(element, x); 1458 }); 1459 }; 1460 return parent(element).map(children).map(filterSelf).getOr([]); 1461 }; 1462 var prevSibling = function (element) { 1463 return Optional.from(element.dom.previousSibling).map(SugarElement.fromDom); 1464 }; 1465 var nextSibling = function (element) { 1466 return Optional.from(element.dom.nextSibling).map(SugarElement.fromDom); 1467 }; 1468 var prevSiblings = function (element) { 1469 return reverse(toArray(element, prevSibling)); 1470 }; 1471 var nextSiblings = function (element) { 1472 return toArray(element, nextSibling); 1473 }; 1474 var children = function (element) { 1475 return map$3(element.dom.childNodes, SugarElement.fromDom); 1476 }; 1477 var child$1 = function (element, index) { 1478 var cs = element.dom.childNodes; 1479 return Optional.from(cs[index]).map(SugarElement.fromDom); 1480 }; 1481 var firstChild = function (element) { 1482 return child$1(element, 0); 1483 }; 1484 var lastChild = function (element) { 1485 return child$1(element, element.dom.childNodes.length - 1); 1486 }; 1487 var childNodesCount = function (element) { 1488 return element.dom.childNodes.length; 1489 }; 1490 1491 var getHead = function (doc) { 1492 var b = doc.dom.head; 1493 if (b === null || b === undefined) { 1494 throw new Error('Head is not available yet'); 1495 } 1496 return SugarElement.fromDom(b); 1497 }; 1498 1499 var isShadowRoot = function (dos) { 1500 return isDocumentFragment$1(dos) && isNonNullable(dos.dom.host); 1501 }; 1502 var supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode); 1503 var isSupported$1 = constant(supported); 1504 var getRootNode = supported ? function (e) { 1505 return SugarElement.fromDom(e.dom.getRootNode()); 1506 } : documentOrOwner; 1507 var getStyleContainer = function (dos) { 1508 return isShadowRoot(dos) ? dos : getHead(documentOrOwner(dos)); 1509 }; 1510 var getShadowRoot = function (e) { 1511 var r = getRootNode(e); 1512 return isShadowRoot(r) ? Optional.some(r) : Optional.none(); 1513 }; 1514 var getShadowHost = function (e) { 1515 return SugarElement.fromDom(e.dom.host); 1516 }; 1517 var getOriginalEventTarget = function (event) { 1518 if (isSupported$1() && isNonNullable(event.target)) { 1519 var el = SugarElement.fromDom(event.target); 1520 if (isElement$6(el) && isOpenShadowHost(el)) { 1521 if (event.composed && event.composedPath) { 1522 var composedPath = event.composedPath(); 1523 if (composedPath) { 1524 return head(composedPath); 1525 } 1526 } 1527 } 1528 } 1529 return Optional.from(event.target); 1530 }; 1531 var isOpenShadowHost = function (element) { 1532 return isNonNullable(element.dom.shadowRoot); 1533 }; 1534 1535 var before$4 = function (marker, element) { 1536 var parent$1 = parent(marker); 1537 parent$1.each(function (v) { 1538 v.dom.insertBefore(element.dom, marker.dom); 1539 }); 1540 }; 1541 var after$3 = function (marker, element) { 1542 var sibling = nextSibling(marker); 1543 sibling.fold(function () { 1544 var parent$1 = parent(marker); 1545 parent$1.each(function (v) { 1546 append$1(v, element); 1547 }); 1548 }, function (v) { 1549 before$4(v, element); 1550 }); 1551 }; 1552 var prepend = function (parent, element) { 1553 var firstChild$1 = firstChild(parent); 1554 firstChild$1.fold(function () { 1555 append$1(parent, element); 1556 }, function (v) { 1557 parent.dom.insertBefore(element.dom, v.dom); 1558 }); 1559 }; 1560 var append$1 = function (parent, element) { 1561 parent.dom.appendChild(element.dom); 1562 }; 1563 var wrap$3 = function (element, wrapper) { 1564 before$4(element, wrapper); 1565 append$1(wrapper, element); 1566 }; 1567 1568 var before$3 = function (marker, elements) { 1569 each$k(elements, function (x) { 1570 before$4(marker, x); 1571 }); 1572 }; 1573 var append = function (parent, elements) { 1574 each$k(elements, function (x) { 1575 append$1(parent, x); 1576 }); 1577 }; 1578 1579 var empty = function (element) { 1580 element.dom.textContent = ''; 1581 each$k(children(element), function (rogue) { 1582 remove$7(rogue); 1583 }); 1584 }; 1585 var remove$7 = function (element) { 1586 var dom = element.dom; 1587 if (dom.parentNode !== null) { 1588 dom.parentNode.removeChild(dom); 1589 } 1590 }; 1591 var unwrap = function (wrapper) { 1592 var children$1 = children(wrapper); 1593 if (children$1.length > 0) { 1594 before$3(wrapper, children$1); 1595 } 1596 remove$7(wrapper); 1597 }; 1598 1599 var inBody = function (element) { 1600 var dom = isText$8(element) ? element.dom.parentNode : element.dom; 1601 if (dom === undefined || dom === null || dom.ownerDocument === null) { 1602 return false; 1603 } 1604 var doc = dom.ownerDocument; 1605 return getShadowRoot(SugarElement.fromDom(dom)).fold(function () { 1606 return doc.body.contains(dom); 1607 }, compose1(inBody, getShadowHost)); 1608 }; 1609 1610 var r = function (left, top) { 1611 var translate = function (x, y) { 1612 return r(left + x, top + y); 1613 }; 1614 return { 1615 left: left, 1616 top: top, 1617 translate: translate 1618 }; 1619 }; 1620 var SugarPosition = r; 1621 1622 var boxPosition = function (dom) { 1623 var box = dom.getBoundingClientRect(); 1624 return SugarPosition(box.left, box.top); 1625 }; 1626 var firstDefinedOrZero = function (a, b) { 1627 if (a !== undefined) { 1628 return a; 1629 } else { 1630 return b !== undefined ? b : 0; 1631 } 1632 }; 1633 var absolute = function (element) { 1634 var doc = element.dom.ownerDocument; 1635 var body = doc.body; 1636 var win = doc.defaultView; 1637 var html = doc.documentElement; 1638 if (body === element.dom) { 1639 return SugarPosition(body.offsetLeft, body.offsetTop); 1640 } 1641 var scrollTop = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageYOffset, html.scrollTop); 1642 var scrollLeft = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageXOffset, html.scrollLeft); 1643 var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop); 1644 var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft); 1645 return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop); 1646 }; 1647 var viewport = function (element) { 1648 var dom = element.dom; 1649 var doc = dom.ownerDocument; 1650 var body = doc.body; 1651 if (body === dom) { 1652 return SugarPosition(body.offsetLeft, body.offsetTop); 1653 } 1654 if (!inBody(element)) { 1655 return SugarPosition(0, 0); 1656 } 1657 return boxPosition(dom); 1658 }; 1659 1660 var get$8 = function (_DOC) { 1661 var doc = _DOC !== undefined ? _DOC.dom : document; 1662 var x = doc.body.scrollLeft || doc.documentElement.scrollLeft; 1663 var y = doc.body.scrollTop || doc.documentElement.scrollTop; 1664 return SugarPosition(x, y); 1665 }; 1666 var to = function (x, y, _DOC) { 1667 var doc = _DOC !== undefined ? _DOC.dom : document; 1668 var win = doc.defaultView; 1669 if (win) { 1670 win.scrollTo(x, y); 1671 } 1672 }; 1673 var intoView = function (element, alignToTop) { 1674 var isSafari = detect().browser.isSafari(); 1675 if (isSafari && isFunction(element.dom.scrollIntoViewIfNeeded)) { 1676 element.dom.scrollIntoViewIfNeeded(false); 1677 } else { 1678 element.dom.scrollIntoView(alignToTop); 1679 } 1680 }; 1681 1682 var get$7 = function (_win) { 1683 var win = _win === undefined ? window : _win; 1684 if (detect().browser.isFirefox()) { 1685 return Optional.none(); 1686 } else { 1687 return Optional.from(win['visualViewport']); 1688 } 1689 }; 1690 var bounds = function (x, y, width, height) { 1691 return { 1692 x: x, 1693 y: y, 1694 width: width, 1695 height: height, 1696 right: x + width, 1697 bottom: y + height 1698 }; 1699 }; 1700 var getBounds = function (_win) { 1701 var win = _win === undefined ? window : _win; 1702 var doc = win.document; 1703 var scroll = get$8(SugarElement.fromDom(doc)); 1704 return get$7(win).fold(function () { 1705 var html = win.document.documentElement; 1706 var width = html.clientWidth; 1707 var height = html.clientHeight; 1708 return bounds(scroll.left, scroll.top, width, height); 1709 }, function (visualViewport) { 1710 return bounds(Math.max(visualViewport.pageLeft, scroll.left), Math.max(visualViewport.pageTop, scroll.top), visualViewport.width, visualViewport.height); 1711 }); 1712 }; 1713 1714 var isNodeType = function (type) { 1715 return function (node) { 1716 return !!node && node.nodeType === type; 1717 }; 1718 }; 1719 var isRestrictedNode = function (node) { 1720 return !!node && !Object.getPrototypeOf(node); 1721 }; 1722 var isElement$5 = isNodeType(1); 1723 var matchNodeNames = function (names) { 1724 var lowercasedNames = names.map(function (s) { 1725 return s.toLowerCase(); 1726 }); 1727 return function (node) { 1728 if (node && node.nodeName) { 1729 var nodeName = node.nodeName.toLowerCase(); 1730 return contains$3(lowercasedNames, nodeName); 1731 } 1732 return false; 1733 }; 1734 }; 1735 var matchStyleValues = function (name, values) { 1736 var items = values.toLowerCase().split(' '); 1737 return function (node) { 1738 if (isElement$5(node)) { 1739 for (var i = 0; i < items.length; i++) { 1740 var computed = node.ownerDocument.defaultView.getComputedStyle(node, null); 1741 var cssValue = computed ? computed.getPropertyValue(name) : null; 1742 if (cssValue === items[i]) { 1743 return true; 1744 } 1745 } 1746 } 1747 return false; 1748 }; 1749 }; 1750 var hasAttribute = function (attrName) { 1751 return function (node) { 1752 return isElement$5(node) && node.hasAttribute(attrName); 1753 }; 1754 }; 1755 var hasAttributeValue = function (attrName, attrValue) { 1756 return function (node) { 1757 return isElement$5(node) && node.getAttribute(attrName) === attrValue; 1758 }; 1759 }; 1760 var isBogus$2 = function (node) { 1761 return isElement$5(node) && node.hasAttribute('data-mce-bogus'); 1762 }; 1763 var isBogusAll$1 = function (node) { 1764 return isElement$5(node) && node.getAttribute('data-mce-bogus') === 'all'; 1765 }; 1766 var isTable$3 = function (node) { 1767 return isElement$5(node) && node.tagName === 'TABLE'; 1768 }; 1769 var hasContentEditableState = function (value) { 1770 return function (node) { 1771 if (isElement$5(node)) { 1772 if (node.contentEditable === value) { 1773 return true; 1774 } 1775 if (node.getAttribute('data-mce-contenteditable') === value) { 1776 return true; 1777 } 1778 } 1779 return false; 1780 }; 1781 }; 1782 var isTextareaOrInput = matchNodeNames([ 1783 'textarea', 1784 'input' 1785 ]); 1786 var isText$7 = isNodeType(3); 1787 var isComment = isNodeType(8); 1788 var isDocument$1 = isNodeType(9); 1789 var isDocumentFragment = isNodeType(11); 1790 var isBr$5 = matchNodeNames(['br']); 1791 var isImg = matchNodeNames(['img']); 1792 var isContentEditableTrue$4 = hasContentEditableState('true'); 1793 var isContentEditableFalse$b = hasContentEditableState('false'); 1794 var isTableCell$5 = matchNodeNames([ 1795 'td', 1796 'th' 1797 ]); 1798 var isMedia$2 = matchNodeNames([ 1799 'video', 1800 'audio', 1801 'object', 1802 'embed' 1803 ]); 1804 1805 var is$1 = function (lhs, rhs, comparator) { 1806 if (comparator === void 0) { 1807 comparator = tripleEquals; 1808 } 1809 return lhs.exists(function (left) { 1810 return comparator(left, rhs); 1811 }); 1812 }; 1813 var cat = function (arr) { 1814 var r = []; 1815 var push = function (x) { 1816 r.push(x); 1817 }; 1818 for (var i = 0; i < arr.length; i++) { 1819 arr[i].each(push); 1820 } 1821 return r; 1822 }; 1823 var lift2 = function (oa, ob, f) { 1824 return oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none(); 1825 }; 1826 var lift3 = function (oa, ob, oc, f) { 1827 return oa.isSome() && ob.isSome() && oc.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Optional.none(); 1828 }; 1829 var someIf = function (b, a) { 1830 return b ? Optional.some(a) : Optional.none(); 1831 }; 1832 1833 var isSupported = function (dom) { 1834 return dom.style !== undefined && isFunction(dom.style.getPropertyValue); 1835 }; 1836 1837 var rawSet = function (dom, key, value) { 1838 if (isString$1(value) || isBoolean(value) || isNumber(value)) { 1839 dom.setAttribute(key, value + ''); 1840 } else { 1841 console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom); 1842 throw new Error('Attribute value was not simple'); 1843 } 1844 }; 1845 var set$1 = function (element, key, value) { 1846 rawSet(element.dom, key, value); 1847 }; 1848 var setAll$1 = function (element, attrs) { 1849 var dom = element.dom; 1850 each$j(attrs, function (v, k) { 1851 rawSet(dom, k, v); 1852 }); 1853 }; 1854 var get$6 = function (element, key) { 1855 var v = element.dom.getAttribute(key); 1856 return v === null ? undefined : v; 1857 }; 1858 var getOpt = function (element, key) { 1859 return Optional.from(get$6(element, key)); 1860 }; 1861 var has$1 = function (element, key) { 1862 var dom = element.dom; 1863 return dom && dom.hasAttribute ? dom.hasAttribute(key) : false; 1864 }; 1865 var remove$6 = function (element, key) { 1866 element.dom.removeAttribute(key); 1867 }; 1868 var clone$3 = function (element) { 1869 return foldl(element.dom.attributes, function (acc, attr) { 1870 acc[attr.name] = attr.value; 1871 return acc; 1872 }, {}); 1873 }; 1874 1875 var internalSet = function (dom, property, value) { 1876 if (!isString$1(value)) { 1877 console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom); 1878 throw new Error('CSS value must be a string: ' + value); 1879 } 1880 if (isSupported(dom)) { 1881 dom.style.setProperty(property, value); 1882 } 1883 }; 1884 var setAll = function (element, css) { 1885 var dom = element.dom; 1886 each$j(css, function (v, k) { 1887 internalSet(dom, k, v); 1888 }); 1889 }; 1890 var get$5 = function (element, property) { 1891 var dom = element.dom; 1892 var styles = window.getComputedStyle(dom); 1893 var r = styles.getPropertyValue(property); 1894 return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r; 1895 }; 1896 var getUnsafeProperty = function (dom, property) { 1897 return isSupported(dom) ? dom.style.getPropertyValue(property) : ''; 1898 }; 1899 var getRaw = function (element, property) { 1900 var dom = element.dom; 1901 var raw = getUnsafeProperty(dom, property); 1902 return Optional.from(raw).filter(function (r) { 1903 return r.length > 0; 1904 }); 1905 }; 1906 var getAllRaw = function (element) { 1907 var css = {}; 1908 var dom = element.dom; 1909 if (isSupported(dom)) { 1910 for (var i = 0; i < dom.style.length; i++) { 1911 var ruleName = dom.style.item(i); 1912 css[ruleName] = dom.style[ruleName]; 1913 } 1914 } 1915 return css; 1916 }; 1917 var reflow = function (e) { 1918 return e.dom.offsetWidth; 1919 }; 1920 1921 var browser$3 = detect().browser; 1922 var firstElement = function (nodes) { 1923 return find$3(nodes, isElement$6); 1924 }; 1925 var getTableCaptionDeltaY = function (elm) { 1926 if (browser$3.isFirefox() && name(elm) === 'table') { 1927 return firstElement(children(elm)).filter(function (elm) { 1928 return name(elm) === 'caption'; 1929 }).bind(function (caption) { 1930 return firstElement(nextSiblings(caption)).map(function (body) { 1931 var bodyTop = body.dom.offsetTop; 1932 var captionTop = caption.dom.offsetTop; 1933 var captionHeight = caption.dom.offsetHeight; 1934 return bodyTop <= captionTop ? -captionHeight : 0; 1935 }); 1936 }).getOr(0); 1937 } else { 1938 return 0; 1939 } 1940 }; 1941 var hasChild = function (elm, child) { 1942 return elm.children && contains$3(elm.children, child); 1943 }; 1944 var getPos = function (body, elm, rootElm) { 1945 var x = 0, y = 0; 1946 var doc = body.ownerDocument; 1947 rootElm = rootElm ? rootElm : body; 1948 if (elm) { 1949 if (rootElm === body && elm.getBoundingClientRect && get$5(SugarElement.fromDom(body), 'position') === 'static') { 1950 var pos = elm.getBoundingClientRect(); 1951 x = pos.left + (doc.documentElement.scrollLeft || body.scrollLeft) - doc.documentElement.clientLeft; 1952 y = pos.top + (doc.documentElement.scrollTop || body.scrollTop) - doc.documentElement.clientTop; 1953 return { 1954 x: x, 1955 y: y 1956 }; 1957 } 1958 var offsetParent = elm; 1959 while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) { 1960 var castOffsetParent = offsetParent; 1961 x += castOffsetParent.offsetLeft || 0; 1962 y += castOffsetParent.offsetTop || 0; 1963 offsetParent = castOffsetParent.offsetParent; 1964 } 1965 offsetParent = elm.parentNode; 1966 while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) { 1967 x -= offsetParent.scrollLeft || 0; 1968 y -= offsetParent.scrollTop || 0; 1969 offsetParent = offsetParent.parentNode; 1970 } 1971 y += getTableCaptionDeltaY(SugarElement.fromDom(elm)); 1972 } 1973 return { 1974 x: x, 1975 y: y 1976 }; 1977 }; 1978 1979 var exports$1 = {}, module$1 = { exports: exports$1 }; 1980 (function (define, exports, module, require) { 1981 (function (global, factory) { 1982 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.EphoxContactWrapper = factory()); 1983 }(this, function () { 1984 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; 1985 var promise = { exports: {} }; 1986 (function (module) { 1987 (function (root) { 1988 var setTimeoutFunc = setTimeout; 1989 function noop() { 1990 } 1991 function bind(fn, thisArg) { 1992 return function () { 1993 fn.apply(thisArg, arguments); 1994 }; 1995 } 1996 function Promise(fn) { 1997 if (typeof this !== 'object') 1998 throw new TypeError('Promises must be constructed via new'); 1999 if (typeof fn !== 'function') 2000 throw new TypeError('not a function'); 2001 this._state = 0; 2002 this._handled = false; 2003 this._value = undefined; 2004 this._deferreds = []; 2005 doResolve(fn, this); 2006 } 2007 function handle(self, deferred) { 2008 while (self._state === 3) { 2009 self = self._value; 2010 } 2011 if (self._state === 0) { 2012 self._deferreds.push(deferred); 2013 return; 2014 } 2015 self._handled = true; 2016 Promise._immediateFn(function () { 2017 var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; 2018 if (cb === null) { 2019 (self._state === 1 ? resolve : reject)(deferred.promise, self._value); 2020 return; 2021 } 2022 var ret; 2023 try { 2024 ret = cb(self._value); 2025 } catch (e) { 2026 reject(deferred.promise, e); 2027 return; 2028 } 2029 resolve(deferred.promise, ret); 2030 }); 2031 } 2032 function resolve(self, newValue) { 2033 try { 2034 if (newValue === self) 2035 throw new TypeError('A promise cannot be resolved with itself.'); 2036 if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) { 2037 var then = newValue.then; 2038 if (newValue instanceof Promise) { 2039 self._state = 3; 2040 self._value = newValue; 2041 finale(self); 2042 return; 2043 } else if (typeof then === 'function') { 2044 doResolve(bind(then, newValue), self); 2045 return; 2046 } 2047 } 2048 self._state = 1; 2049 self._value = newValue; 2050 finale(self); 2051 } catch (e) { 2052 reject(self, e); 2053 } 2054 } 2055 function reject(self, newValue) { 2056 self._state = 2; 2057 self._value = newValue; 2058 finale(self); 2059 } 2060 function finale(self) { 2061 if (self._state === 2 && self._deferreds.length === 0) { 2062 Promise._immediateFn(function () { 2063 if (!self._handled) { 2064 Promise._unhandledRejectionFn(self._value); 2065 } 2066 }); 2067 } 2068 for (var i = 0, len = self._deferreds.length; i < len; i++) { 2069 handle(self, self._deferreds[i]); 2070 } 2071 self._deferreds = null; 2072 } 2073 function Handler(onFulfilled, onRejected, promise) { 2074 this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; 2075 this.onRejected = typeof onRejected === 'function' ? onRejected : null; 2076 this.promise = promise; 2077 } 2078 function doResolve(fn, self) { 2079 var done = false; 2080 try { 2081 fn(function (value) { 2082 if (done) 2083 return; 2084 done = true; 2085 resolve(self, value); 2086 }, function (reason) { 2087 if (done) 2088 return; 2089 done = true; 2090 reject(self, reason); 2091 }); 2092 } catch (ex) { 2093 if (done) 2094 return; 2095 done = true; 2096 reject(self, ex); 2097 } 2098 } 2099 Promise.prototype['catch'] = function (onRejected) { 2100 return this.then(null, onRejected); 2101 }; 2102 Promise.prototype.then = function (onFulfilled, onRejected) { 2103 var prom = new this.constructor(noop); 2104 handle(this, new Handler(onFulfilled, onRejected, prom)); 2105 return prom; 2106 }; 2107 Promise.all = function (arr) { 2108 var args = Array.prototype.slice.call(arr); 2109 return new Promise(function (resolve, reject) { 2110 if (args.length === 0) 2111 return resolve([]); 2112 var remaining = args.length; 2113 function res(i, val) { 2114 try { 2115 if (val && (typeof val === 'object' || typeof val === 'function')) { 2116 var then = val.then; 2117 if (typeof then === 'function') { 2118 then.call(val, function (val) { 2119 res(i, val); 2120 }, reject); 2121 return; 2122 } 2123 } 2124 args[i] = val; 2125 if (--remaining === 0) { 2126 resolve(args); 2127 } 2128 } catch (ex) { 2129 reject(ex); 2130 } 2131 } 2132 for (var i = 0; i < args.length; i++) { 2133 res(i, args[i]); 2134 } 2135 }); 2136 }; 2137 Promise.resolve = function (value) { 2138 if (value && typeof value === 'object' && value.constructor === Promise) { 2139 return value; 2140 } 2141 return new Promise(function (resolve) { 2142 resolve(value); 2143 }); 2144 }; 2145 Promise.reject = function (value) { 2146 return new Promise(function (resolve, reject) { 2147 reject(value); 2148 }); 2149 }; 2150 Promise.race = function (values) { 2151 return new Promise(function (resolve, reject) { 2152 for (var i = 0, len = values.length; i < len; i++) { 2153 values[i].then(resolve, reject); 2154 } 2155 }); 2156 }; 2157 Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) { 2158 setImmediate(fn); 2159 } : function (fn) { 2160 setTimeoutFunc(fn, 0); 2161 }; 2162 Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { 2163 if (typeof console !== 'undefined' && console) { 2164 console.warn('Possible Unhandled Promise Rejection:', err); 2165 } 2166 }; 2167 Promise._setImmediateFn = function _setImmediateFn(fn) { 2168 Promise._immediateFn = fn; 2169 }; 2170 Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { 2171 Promise._unhandledRejectionFn = fn; 2172 }; 2173 if (module.exports) { 2174 module.exports = Promise; 2175 } else if (!root.Promise) { 2176 root.Promise = Promise; 2177 } 2178 }(commonjsGlobal)); 2179 }(promise)); 2180 var promisePolyfill = promise.exports; 2181 var Global = function () { 2182 if (typeof window !== 'undefined') { 2183 return window; 2184 } else { 2185 return Function('return this;')(); 2186 } 2187 }(); 2188 var promisePolyfill_1 = { boltExport: Global.Promise || promisePolyfill }; 2189 return promisePolyfill_1; 2190 })); 2191 }(undefined, exports$1, module$1)); 2192 var Promise$1 = module$1.exports.boltExport; 2193 2194 var nu$1 = function (baseFn) { 2195 var data = Optional.none(); 2196 var callbacks = []; 2197 var map = function (f) { 2198 return nu$1(function (nCallback) { 2199 get(function (data) { 2200 nCallback(f(data)); 2201 }); 2202 }); 2203 }; 2204 var get = function (nCallback) { 2205 if (isReady()) { 2206 call(nCallback); 2207 } else { 2208 callbacks.push(nCallback); 2209 } 2210 }; 2211 var set = function (x) { 2212 if (!isReady()) { 2213 data = Optional.some(x); 2214 run(callbacks); 2215 callbacks = []; 2216 } 2217 }; 2218 var isReady = function () { 2219 return data.isSome(); 2220 }; 2221 var run = function (cbs) { 2222 each$k(cbs, call); 2223 }; 2224 var call = function (cb) { 2225 data.each(function (x) { 2226 setTimeout(function () { 2227 cb(x); 2228 }, 0); 2229 }); 2230 }; 2231 baseFn(set); 2232 return { 2233 get: get, 2234 map: map, 2235 isReady: isReady 2236 }; 2237 }; 2238 var pure$1 = function (a) { 2239 return nu$1(function (callback) { 2240 callback(a); 2241 }); 2242 }; 2243 var LazyValue = { 2244 nu: nu$1, 2245 pure: pure$1 2246 }; 2247 2248 var errorReporter = function (err) { 2249 setTimeout(function () { 2250 throw err; 2251 }, 0); 2252 }; 2253 var make = function (run) { 2254 var get = function (callback) { 2255 run().then(callback, errorReporter); 2256 }; 2257 var map = function (fab) { 2258 return make(function () { 2259 return run().then(fab); 2260 }); 2261 }; 2262 var bind = function (aFutureB) { 2263 return make(function () { 2264 return run().then(function (v) { 2265 return aFutureB(v).toPromise(); 2266 }); 2267 }); 2268 }; 2269 var anonBind = function (futureB) { 2270 return make(function () { 2271 return run().then(function () { 2272 return futureB.toPromise(); 2273 }); 2274 }); 2275 }; 2276 var toLazy = function () { 2277 return LazyValue.nu(get); 2278 }; 2279 var toCached = function () { 2280 var cache = null; 2281 return make(function () { 2282 if (cache === null) { 2283 cache = run(); 2284 } 2285 return cache; 2286 }); 2287 }; 2288 var toPromise = run; 2289 return { 2290 map: map, 2291 bind: bind, 2292 anonBind: anonBind, 2293 toLazy: toLazy, 2294 toCached: toCached, 2295 toPromise: toPromise, 2296 get: get 2297 }; 2298 }; 2299 var nu = function (baseFn) { 2300 return make(function () { 2301 return new Promise$1(baseFn); 2302 }); 2303 }; 2304 var pure = function (a) { 2305 return make(function () { 2306 return Promise$1.resolve(a); 2307 }); 2308 }; 2309 var Future = { 2310 nu: nu, 2311 pure: pure 2312 }; 2313 2314 var par$1 = function (asyncValues, nu) { 2315 return nu(function (callback) { 2316 var r = []; 2317 var count = 0; 2318 var cb = function (i) { 2319 return function (value) { 2320 r[i] = value; 2321 count++; 2322 if (count >= asyncValues.length) { 2323 callback(r); 2324 } 2325 }; 2326 }; 2327 if (asyncValues.length === 0) { 2328 callback([]); 2329 } else { 2330 each$k(asyncValues, function (asyncValue, i) { 2331 asyncValue.get(cb(i)); 2332 }); 2333 } 2334 }); 2335 }; 2336 2337 var par = function (futures) { 2338 return par$1(futures, Future.nu); 2339 }; 2340 2341 var value$1 = function (o) { 2342 var or = function (_opt) { 2343 return value$1(o); 2344 }; 2345 var orThunk = function (_f) { 2346 return value$1(o); 2347 }; 2348 var map = function (f) { 2349 return value$1(f(o)); 2350 }; 2351 var mapError = function (_f) { 2352 return value$1(o); 2353 }; 2354 var each = function (f) { 2355 f(o); 2356 }; 2357 var bind = function (f) { 2358 return f(o); 2359 }; 2360 var fold = function (_, onValue) { 2361 return onValue(o); 2362 }; 2363 var exists = function (f) { 2364 return f(o); 2365 }; 2366 var forall = function (f) { 2367 return f(o); 2368 }; 2369 var toOptional = function () { 2370 return Optional.some(o); 2371 }; 2372 return { 2373 isValue: always, 2374 isError: never, 2375 getOr: constant(o), 2376 getOrThunk: constant(o), 2377 getOrDie: constant(o), 2378 or: or, 2379 orThunk: orThunk, 2380 fold: fold, 2381 map: map, 2382 mapError: mapError, 2383 each: each, 2384 bind: bind, 2385 exists: exists, 2386 forall: forall, 2387 toOptional: toOptional 2388 }; 2389 }; 2390 var error = function (message) { 2391 var getOrThunk = function (f) { 2392 return f(); 2393 }; 2394 var getOrDie = function () { 2395 return die(String(message))(); 2396 }; 2397 var or = identity; 2398 var orThunk = function (f) { 2399 return f(); 2400 }; 2401 var map = function (_f) { 2402 return error(message); 2403 }; 2404 var mapError = function (f) { 2405 return error(f(message)); 2406 }; 2407 var bind = function (_f) { 2408 return error(message); 2409 }; 2410 var fold = function (onError, _) { 2411 return onError(message); 2412 }; 2413 return { 2414 isValue: never, 2415 isError: always, 2416 getOr: identity, 2417 getOrThunk: getOrThunk, 2418 getOrDie: getOrDie, 2419 or: or, 2420 orThunk: orThunk, 2421 fold: fold, 2422 map: map, 2423 mapError: mapError, 2424 each: noop, 2425 bind: bind, 2426 exists: never, 2427 forall: always, 2428 toOptional: Optional.none 2429 }; 2430 }; 2431 var fromOption = function (opt, err) { 2432 return opt.fold(function () { 2433 return error(err); 2434 }, value$1); 2435 }; 2436 var Result = { 2437 value: value$1, 2438 error: error, 2439 fromOption: fromOption 2440 }; 2441 2442 var generate$1 = function (cases) { 2443 if (!isArray$1(cases)) { 2444 throw new Error('cases must be an array'); 2445 } 2446 if (cases.length === 0) { 2447 throw new Error('there must be at least one case'); 2448 } 2449 var constructors = []; 2450 var adt = {}; 2451 each$k(cases, function (acase, count) { 2452 var keys$1 = keys(acase); 2453 if (keys$1.length !== 1) { 2454 throw new Error('one and only one name per case'); 2455 } 2456 var key = keys$1[0]; 2457 var value = acase[key]; 2458 if (adt[key] !== undefined) { 2459 throw new Error('duplicate key detected:' + key); 2460 } else if (key === 'cata') { 2461 throw new Error('cannot have a case named cata (sorry)'); 2462 } else if (!isArray$1(value)) { 2463 throw new Error('case arguments must be an array'); 2464 } 2465 constructors.push(key); 2466 adt[key] = function () { 2467 var args = []; 2468 for (var _i = 0; _i < arguments.length; _i++) { 2469 args[_i] = arguments[_i]; 2470 } 2471 var argLength = args.length; 2472 if (argLength !== value.length) { 2473 throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength); 2474 } 2475 var match = function (branches) { 2476 var branchKeys = keys(branches); 2477 if (constructors.length !== branchKeys.length) { 2478 throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(',')); 2479 } 2480 var allReqd = forall(constructors, function (reqKey) { 2481 return contains$3(branchKeys, reqKey); 2482 }); 2483 if (!allReqd) { 2484 throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', ')); 2485 } 2486 return branches[key].apply(null, args); 2487 }; 2488 return { 2489 fold: function () { 2490 var foldArgs = []; 2491 for (var _i = 0; _i < arguments.length; _i++) { 2492 foldArgs[_i] = arguments[_i]; 2493 } 2494 if (foldArgs.length !== cases.length) { 2495 throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + foldArgs.length); 2496 } 2497 var target = foldArgs[count]; 2498 return target.apply(null, args); 2499 }, 2500 match: match, 2501 log: function (label) { 2502 console.log(label, { 2503 constructors: constructors, 2504 constructor: key, 2505 params: args 2506 }); 2507 } 2508 }; 2509 }; 2510 }); 2511 return adt; 2512 }; 2513 var Adt = { generate: generate$1 }; 2514 2515 Adt.generate([ 2516 { 2517 bothErrors: [ 2518 'error1', 2519 'error2' 2520 ] 2521 }, 2522 { 2523 firstError: [ 2524 'error1', 2525 'value2' 2526 ] 2527 }, 2528 { 2529 secondError: [ 2530 'value1', 2531 'error2' 2532 ] 2533 }, 2534 { 2535 bothValues: [ 2536 'value1', 2537 'value2' 2538 ] 2539 } 2540 ]); 2541 var unite = function (result) { 2542 return result.fold(identity, identity); 2543 }; 2544 2545 function ClosestOrAncestor (is, ancestor, scope, a, isRoot) { 2546 if (is(scope, a)) { 2547 return Optional.some(scope); 2548 } else if (isFunction(isRoot) && isRoot(scope)) { 2549 return Optional.none(); 2550 } else { 2551 return ancestor(scope, a, isRoot); 2552 } 2553 } 2554 2555 var ancestor$3 = function (scope, predicate, isRoot) { 2556 var element = scope.dom; 2557 var stop = isFunction(isRoot) ? isRoot : never; 2558 while (element.parentNode) { 2559 element = element.parentNode; 2560 var el = SugarElement.fromDom(element); 2561 if (predicate(el)) { 2562 return Optional.some(el); 2563 } else if (stop(el)) { 2564 break; 2565 } 2566 } 2567 return Optional.none(); 2568 }; 2569 var closest$3 = function (scope, predicate, isRoot) { 2570 var is = function (s, test) { 2571 return test(s); 2572 }; 2573 return ClosestOrAncestor(is, ancestor$3, scope, predicate, isRoot); 2574 }; 2575 var sibling$2 = function (scope, predicate) { 2576 var element = scope.dom; 2577 if (!element.parentNode) { 2578 return Optional.none(); 2579 } 2580 return child(SugarElement.fromDom(element.parentNode), function (x) { 2581 return !eq(scope, x) && predicate(x); 2582 }); 2583 }; 2584 var child = function (scope, predicate) { 2585 var pred = function (node) { 2586 return predicate(SugarElement.fromDom(node)); 2587 }; 2588 var result = find$3(scope.dom.childNodes, pred); 2589 return result.map(SugarElement.fromDom); 2590 }; 2591 2592 var ancestor$2 = function (scope, selector, isRoot) { 2593 return ancestor$3(scope, function (e) { 2594 return is$2(e, selector); 2595 }, isRoot); 2596 }; 2597 var descendant = function (scope, selector) { 2598 return one(selector, scope); 2599 }; 2600 var closest$2 = function (scope, selector, isRoot) { 2601 var is = function (element, selector) { 2602 return is$2(element, selector); 2603 }; 2604 return ClosestOrAncestor(is, ancestor$2, scope, selector, isRoot); 2605 }; 2606 2607 var promiseObj = window.Promise ? window.Promise : Promise$1; 2608 2609 var requestAnimationFramePromise; 2610 var requestAnimationFrame = function (callback, element) { 2611 var requestAnimationFrameFunc = window.requestAnimationFrame; 2612 var vendors = [ 2613 'ms', 2614 'moz', 2615 'webkit' 2616 ]; 2617 var featurefill = function (cb) { 2618 window.setTimeout(cb, 0); 2619 }; 2620 for (var i = 0; i < vendors.length && !requestAnimationFrameFunc; i++) { 2621 requestAnimationFrameFunc = window[vendors[i] + 'RequestAnimationFrame']; 2622 } 2623 if (!requestAnimationFrameFunc) { 2624 requestAnimationFrameFunc = featurefill; 2625 } 2626 requestAnimationFrameFunc(callback, element); 2627 }; 2628 var wrappedSetTimeout = function (callback, time) { 2629 if (typeof time !== 'number') { 2630 time = 0; 2631 } 2632 return setTimeout(callback, time); 2633 }; 2634 var wrappedSetInterval = function (callback, time) { 2635 if (typeof time !== 'number') { 2636 time = 1; 2637 } 2638 return setInterval(callback, time); 2639 }; 2640 var wrappedClearTimeout = function (id) { 2641 return clearTimeout(id); 2642 }; 2643 var wrappedClearInterval = function (id) { 2644 return clearInterval(id); 2645 }; 2646 var debounce = function (callback, time) { 2647 var timer; 2648 var func = function () { 2649 var args = []; 2650 for (var _i = 0; _i < arguments.length; _i++) { 2651 args[_i] = arguments[_i]; 2652 } 2653 clearTimeout(timer); 2654 timer = wrappedSetTimeout(function () { 2655 callback.apply(this, args); 2656 }, time); 2657 }; 2658 func.stop = function () { 2659 clearTimeout(timer); 2660 }; 2661 return func; 2662 }; 2663 var Delay = { 2664 requestAnimationFrame: function (callback, element) { 2665 if (requestAnimationFramePromise) { 2666 requestAnimationFramePromise.then(callback); 2667 return; 2668 } 2669 requestAnimationFramePromise = new promiseObj(function (resolve) { 2670 if (!element) { 2671 element = document.body; 2672 } 2673 requestAnimationFrame(resolve, element); 2674 }).then(callback); 2675 }, 2676 setTimeout: wrappedSetTimeout, 2677 setInterval: wrappedSetInterval, 2678 setEditorTimeout: function (editor, callback, time) { 2679 return wrappedSetTimeout(function () { 2680 if (!editor.removed) { 2681 callback(); 2682 } 2683 }, time); 2684 }, 2685 setEditorInterval: function (editor, callback, time) { 2686 var timer = wrappedSetInterval(function () { 2687 if (!editor.removed) { 2688 callback(); 2689 } else { 2690 clearInterval(timer); 2691 } 2692 }, time); 2693 return timer; 2694 }, 2695 debounce: debounce, 2696 throttle: debounce, 2697 clearInterval: wrappedClearInterval, 2698 clearTimeout: wrappedClearTimeout 2699 }; 2700 2701 var StyleSheetLoader = function (documentOrShadowRoot, settings) { 2702 if (settings === void 0) { 2703 settings = {}; 2704 } 2705 var idCount = 0; 2706 var loadedStates = {}; 2707 var edos = SugarElement.fromDom(documentOrShadowRoot); 2708 var doc = documentOrOwner(edos); 2709 var maxLoadTime = settings.maxLoadTime || 5000; 2710 var _setReferrerPolicy = function (referrerPolicy) { 2711 settings.referrerPolicy = referrerPolicy; 2712 }; 2713 var addStyle = function (element) { 2714 append$1(getStyleContainer(edos), element); 2715 }; 2716 var removeStyle = function (id) { 2717 var styleContainer = getStyleContainer(edos); 2718 descendant(styleContainer, '#' + id).each(remove$7); 2719 }; 2720 var getOrCreateState = function (url) { 2721 return get$9(loadedStates, url).getOrThunk(function () { 2722 return { 2723 id: 'mce-u' + idCount++, 2724 passed: [], 2725 failed: [], 2726 count: 0 2727 }; 2728 }); 2729 }; 2730 var load = function (url, success, failure) { 2731 var link; 2732 var urlWithSuffix = Tools._addCacheSuffix(url); 2733 var state = getOrCreateState(urlWithSuffix); 2734 loadedStates[urlWithSuffix] = state; 2735 state.count++; 2736 var resolve = function (callbacks, status) { 2737 var i = callbacks.length; 2738 while (i--) { 2739 callbacks[i](); 2740 } 2741 state.status = status; 2742 state.passed = []; 2743 state.failed = []; 2744 if (link) { 2745 link.onload = null; 2746 link.onerror = null; 2747 link = null; 2748 } 2749 }; 2750 var passed = function () { 2751 return resolve(state.passed, 2); 2752 }; 2753 var failed = function () { 2754 return resolve(state.failed, 3); 2755 }; 2756 var wait = function (testCallback, waitCallback) { 2757 if (!testCallback()) { 2758 if (Date.now() - startTime < maxLoadTime) { 2759 Delay.setTimeout(waitCallback); 2760 } else { 2761 failed(); 2762 } 2763 } 2764 }; 2765 var waitForWebKitLinkLoaded = function () { 2766 wait(function () { 2767 var styleSheets = documentOrShadowRoot.styleSheets; 2768 var i = styleSheets.length; 2769 while (i--) { 2770 var styleSheet = styleSheets[i]; 2771 var owner = styleSheet.ownerNode; 2772 if (owner && owner.id === link.id) { 2773 passed(); 2774 return true; 2775 } 2776 } 2777 return false; 2778 }, waitForWebKitLinkLoaded); 2779 }; 2780 if (success) { 2781 state.passed.push(success); 2782 } 2783 if (failure) { 2784 state.failed.push(failure); 2785 } 2786 if (state.status === 1) { 2787 return; 2788 } 2789 if (state.status === 2) { 2790 passed(); 2791 return; 2792 } 2793 if (state.status === 3) { 2794 failed(); 2795 return; 2796 } 2797 state.status = 1; 2798 var linkElem = SugarElement.fromTag('link', doc.dom); 2799 setAll$1(linkElem, { 2800 rel: 'stylesheet', 2801 type: 'text/css', 2802 id: state.id 2803 }); 2804 var startTime = Date.now(); 2805 if (settings.contentCssCors) { 2806 set$1(linkElem, 'crossOrigin', 'anonymous'); 2807 } 2808 if (settings.referrerPolicy) { 2809 set$1(linkElem, 'referrerpolicy', settings.referrerPolicy); 2810 } 2811 link = linkElem.dom; 2812 link.onload = waitForWebKitLinkLoaded; 2813 link.onerror = failed; 2814 addStyle(linkElem); 2815 set$1(linkElem, 'href', urlWithSuffix); 2816 }; 2817 var loadF = function (url) { 2818 return Future.nu(function (resolve) { 2819 load(url, compose(resolve, constant(Result.value(url))), compose(resolve, constant(Result.error(url)))); 2820 }); 2821 }; 2822 var loadAll = function (urls, success, failure) { 2823 par(map$3(urls, loadF)).get(function (result) { 2824 var parts = partition(result, function (r) { 2825 return r.isValue(); 2826 }); 2827 if (parts.fail.length > 0) { 2828 failure(parts.fail.map(unite)); 2829 } else { 2830 success(parts.pass.map(unite)); 2831 } 2832 }); 2833 }; 2834 var unload = function (url) { 2835 var urlWithSuffix = Tools._addCacheSuffix(url); 2836 get$9(loadedStates, urlWithSuffix).each(function (state) { 2837 var count = --state.count; 2838 if (count === 0) { 2839 delete loadedStates[urlWithSuffix]; 2840 removeStyle(state.id); 2841 } 2842 }); 2843 }; 2844 var unloadAll = function (urls) { 2845 each$k(urls, function (url) { 2846 unload(url); 2847 }); 2848 }; 2849 return { 2850 load: load, 2851 loadAll: loadAll, 2852 unload: unload, 2853 unloadAll: unloadAll, 2854 _setReferrerPolicy: _setReferrerPolicy 2855 }; 2856 }; 2857 2858 var create$8 = function () { 2859 var map = new WeakMap(); 2860 var forElement = function (referenceElement, settings) { 2861 var root = getRootNode(referenceElement); 2862 var rootDom = root.dom; 2863 return Optional.from(map.get(rootDom)).getOrThunk(function () { 2864 var sl = StyleSheetLoader(rootDom, settings); 2865 map.set(rootDom, sl); 2866 return sl; 2867 }); 2868 }; 2869 return { forElement: forElement }; 2870 }; 2871 var instance = create$8(); 2872 2873 var DomTreeWalker = function () { 2874 function DomTreeWalker(startNode, rootNode) { 2875 this.node = startNode; 2876 this.rootNode = rootNode; 2877 this.current = this.current.bind(this); 2878 this.next = this.next.bind(this); 2879 this.prev = this.prev.bind(this); 2880 this.prev2 = this.prev2.bind(this); 2881 } 2882 DomTreeWalker.prototype.current = function () { 2883 return this.node; 2884 }; 2885 DomTreeWalker.prototype.next = function (shallow) { 2886 this.node = this.findSibling(this.node, 'firstChild', 'nextSibling', shallow); 2887 return this.node; 2888 }; 2889 DomTreeWalker.prototype.prev = function (shallow) { 2890 this.node = this.findSibling(this.node, 'lastChild', 'previousSibling', shallow); 2891 return this.node; 2892 }; 2893 DomTreeWalker.prototype.prev2 = function (shallow) { 2894 this.node = this.findPreviousNode(this.node, 'lastChild', 'previousSibling', shallow); 2895 return this.node; 2896 }; 2897 DomTreeWalker.prototype.findSibling = function (node, startName, siblingName, shallow) { 2898 var sibling, parent; 2899 if (node) { 2900 if (!shallow && node[startName]) { 2901 return node[startName]; 2902 } 2903 if (node !== this.rootNode) { 2904 sibling = node[siblingName]; 2905 if (sibling) { 2906 return sibling; 2907 } 2908 for (parent = node.parentNode; parent && parent !== this.rootNode; parent = parent.parentNode) { 2909 sibling = parent[siblingName]; 2910 if (sibling) { 2911 return sibling; 2912 } 2913 } 2914 } 2915 } 2916 }; 2917 DomTreeWalker.prototype.findPreviousNode = function (node, startName, siblingName, shallow) { 2918 var sibling, parent, child; 2919 if (node) { 2920 sibling = node[siblingName]; 2921 if (this.rootNode && sibling === this.rootNode) { 2922 return; 2923 } 2924 if (sibling) { 2925 if (!shallow) { 2926 for (child = sibling[startName]; child; child = child[startName]) { 2927 if (!child[startName]) { 2928 return child; 2929 } 2930 } 2931 } 2932 return sibling; 2933 } 2934 parent = node.parentNode; 2935 if (parent && parent !== this.rootNode) { 2936 return parent; 2937 } 2938 } 2939 }; 2940 return DomTreeWalker; 2941 }(); 2942 2943 var blocks = [ 2944 'article', 2945 'aside', 2946 'details', 2947 'div', 2948 'dt', 2949 'figcaption', 2950 'footer', 2951 'form', 2952 'fieldset', 2953 'header', 2954 'hgroup', 2955 'html', 2956 'main', 2957 'nav', 2958 'section', 2959 'summary', 2960 'body', 2961 'p', 2962 'dl', 2963 'multicol', 2964 'dd', 2965 'figure', 2966 'address', 2967 'center', 2968 'blockquote', 2969 'h1', 2970 'h2', 2971 'h3', 2972 'h4', 2973 'h5', 2974 'h6', 2975 'listing', 2976 'xmp', 2977 'pre', 2978 'plaintext', 2979 'menu', 2980 'dir', 2981 'ul', 2982 'ol', 2983 'li', 2984 'hr', 2985 'table', 2986 'tbody', 2987 'thead', 2988 'tfoot', 2989 'th', 2990 'tr', 2991 'td', 2992 'caption' 2993 ]; 2994 var tableCells = [ 2995 'td', 2996 'th' 2997 ]; 2998 var tableSections = [ 2999 'thead', 3000 'tbody', 3001 'tfoot' 3002 ]; 3003 var textBlocks = [ 3004 'h1', 3005 'h2', 3006 'h3', 3007 'h4', 3008 'h5', 3009 'h6', 3010 'p', 3011 'div', 3012 'address', 3013 'pre', 3014 'form', 3015 'blockquote', 3016 'center', 3017 'dir', 3018 'fieldset', 3019 'header', 3020 'footer', 3021 'article', 3022 'section', 3023 'hgroup', 3024 'aside', 3025 'nav', 3026 'figure' 3027 ]; 3028 var headings = [ 3029 'h1', 3030 'h2', 3031 'h3', 3032 'h4', 3033 'h5', 3034 'h6' 3035 ]; 3036 var listItems$1 = [ 3037 'li', 3038 'dd', 3039 'dt' 3040 ]; 3041 var lists = [ 3042 'ul', 3043 'ol', 3044 'dl' 3045 ]; 3046 var wsElements = [ 3047 'pre', 3048 'script', 3049 'textarea', 3050 'style' 3051 ]; 3052 var lazyLookup = function (items) { 3053 var lookup; 3054 return function (node) { 3055 lookup = lookup ? lookup : mapToObject(items, always); 3056 return has$2(lookup, name(node)); 3057 }; 3058 }; 3059 var isHeading = lazyLookup(headings); 3060 var isBlock$2 = lazyLookup(blocks); 3061 var isTable$2 = function (node) { 3062 return name(node) === 'table'; 3063 }; 3064 var isInline$1 = function (node) { 3065 return isElement$6(node) && !isBlock$2(node); 3066 }; 3067 var isBr$4 = function (node) { 3068 return isElement$6(node) && name(node) === 'br'; 3069 }; 3070 var isTextBlock$2 = lazyLookup(textBlocks); 3071 var isList = lazyLookup(lists); 3072 var isListItem = lazyLookup(listItems$1); 3073 var isTableSection = lazyLookup(tableSections); 3074 var isTableCell$4 = lazyLookup(tableCells); 3075 var isWsPreserveElement = lazyLookup(wsElements); 3076 3077 var ancestor$1 = function (scope, selector, isRoot) { 3078 return ancestor$2(scope, selector, isRoot).isSome(); 3079 }; 3080 3081 var zeroWidth = '\uFEFF'; 3082 var nbsp = '\xA0'; 3083 var isZwsp$1 = function (char) { 3084 return char === zeroWidth; 3085 }; 3086 var removeZwsp = function (s) { 3087 return s.replace(/\uFEFF/g, ''); 3088 }; 3089 3090 var ZWSP$1 = zeroWidth; 3091 var isZwsp = isZwsp$1; 3092 var trim$2 = removeZwsp; 3093 3094 var isElement$4 = isElement$5; 3095 var isText$6 = isText$7; 3096 var isCaretContainerBlock$1 = function (node) { 3097 if (isText$6(node)) { 3098 node = node.parentNode; 3099 } 3100 return isElement$4(node) && node.hasAttribute('data-mce-caret'); 3101 }; 3102 var isCaretContainerInline = function (node) { 3103 return isText$6(node) && isZwsp(node.data); 3104 }; 3105 var isCaretContainer$2 = function (node) { 3106 return isCaretContainerBlock$1(node) || isCaretContainerInline(node); 3107 }; 3108 var hasContent = function (node) { 3109 return node.firstChild !== node.lastChild || !isBr$5(node.firstChild); 3110 }; 3111 var insertInline$1 = function (node, before) { 3112 var doc = node.ownerDocument; 3113 var textNode = doc.createTextNode(ZWSP$1); 3114 var parentNode = node.parentNode; 3115 if (!before) { 3116 var sibling = node.nextSibling; 3117 if (isText$6(sibling)) { 3118 if (isCaretContainer$2(sibling)) { 3119 return sibling; 3120 } 3121 if (startsWithCaretContainer$1(sibling)) { 3122 sibling.splitText(1); 3123 return sibling; 3124 } 3125 } 3126 if (node.nextSibling) { 3127 parentNode.insertBefore(textNode, node.nextSibling); 3128 } else { 3129 parentNode.appendChild(textNode); 3130 } 3131 } else { 3132 var sibling = node.previousSibling; 3133 if (isText$6(sibling)) { 3134 if (isCaretContainer$2(sibling)) { 3135 return sibling; 3136 } 3137 if (endsWithCaretContainer$1(sibling)) { 3138 return sibling.splitText(sibling.data.length - 1); 3139 } 3140 } 3141 parentNode.insertBefore(textNode, node); 3142 } 3143 return textNode; 3144 }; 3145 var isBeforeInline = function (pos) { 3146 var container = pos.container(); 3147 if (!isText$7(container)) { 3148 return false; 3149 } 3150 return container.data.charAt(pos.offset()) === ZWSP$1 || pos.isAtStart() && isCaretContainerInline(container.previousSibling); 3151 }; 3152 var isAfterInline = function (pos) { 3153 var container = pos.container(); 3154 if (!isText$7(container)) { 3155 return false; 3156 } 3157 return container.data.charAt(pos.offset() - 1) === ZWSP$1 || pos.isAtEnd() && isCaretContainerInline(container.nextSibling); 3158 }; 3159 var createBogusBr = function () { 3160 var br = document.createElement('br'); 3161 br.setAttribute('data-mce-bogus', '1'); 3162 return br; 3163 }; 3164 var insertBlock$1 = function (blockName, node, before) { 3165 var doc = node.ownerDocument; 3166 var blockNode = doc.createElement(blockName); 3167 blockNode.setAttribute('data-mce-caret', before ? 'before' : 'after'); 3168 blockNode.setAttribute('data-mce-bogus', 'all'); 3169 blockNode.appendChild(createBogusBr()); 3170 var parentNode = node.parentNode; 3171 if (!before) { 3172 if (node.nextSibling) { 3173 parentNode.insertBefore(blockNode, node.nextSibling); 3174 } else { 3175 parentNode.appendChild(blockNode); 3176 } 3177 } else { 3178 parentNode.insertBefore(blockNode, node); 3179 } 3180 return blockNode; 3181 }; 3182 var startsWithCaretContainer$1 = function (node) { 3183 return isText$6(node) && node.data[0] === ZWSP$1; 3184 }; 3185 var endsWithCaretContainer$1 = function (node) { 3186 return isText$6(node) && node.data[node.data.length - 1] === ZWSP$1; 3187 }; 3188 var trimBogusBr = function (elm) { 3189 var brs = elm.getElementsByTagName('br'); 3190 var lastBr = brs[brs.length - 1]; 3191 if (isBogus$2(lastBr)) { 3192 lastBr.parentNode.removeChild(lastBr); 3193 } 3194 }; 3195 var showCaretContainerBlock = function (caretContainer) { 3196 if (caretContainer && caretContainer.hasAttribute('data-mce-caret')) { 3197 trimBogusBr(caretContainer); 3198 caretContainer.removeAttribute('data-mce-caret'); 3199 caretContainer.removeAttribute('data-mce-bogus'); 3200 caretContainer.removeAttribute('style'); 3201 caretContainer.removeAttribute('_moz_abspos'); 3202 return caretContainer; 3203 } 3204 return null; 3205 }; 3206 var isRangeInCaretContainerBlock = function (range) { 3207 return isCaretContainerBlock$1(range.startContainer); 3208 }; 3209 3210 var isContentEditableTrue$3 = isContentEditableTrue$4; 3211 var isContentEditableFalse$a = isContentEditableFalse$b; 3212 var isBr$3 = isBr$5; 3213 var isText$5 = isText$7; 3214 var isInvalidTextElement = matchNodeNames([ 3215 'script', 3216 'style', 3217 'textarea' 3218 ]); 3219 var isAtomicInline = matchNodeNames([ 3220 'img', 3221 'input', 3222 'textarea', 3223 'hr', 3224 'iframe', 3225 'video', 3226 'audio', 3227 'object', 3228 'embed' 3229 ]); 3230 var isTable$1 = matchNodeNames(['table']); 3231 var isCaretContainer$1 = isCaretContainer$2; 3232 var isCaretCandidate$3 = function (node) { 3233 if (isCaretContainer$1(node)) { 3234 return false; 3235 } 3236 if (isText$5(node)) { 3237 return !isInvalidTextElement(node.parentNode); 3238 } 3239 return isAtomicInline(node) || isBr$3(node) || isTable$1(node) || isNonUiContentEditableFalse(node); 3240 }; 3241 var isUnselectable = function (node) { 3242 return isElement$5(node) && node.getAttribute('unselectable') === 'true'; 3243 }; 3244 var isNonUiContentEditableFalse = function (node) { 3245 return isUnselectable(node) === false && isContentEditableFalse$a(node); 3246 }; 3247 var isInEditable = function (node, root) { 3248 for (node = node.parentNode; node && node !== root; node = node.parentNode) { 3249 if (isNonUiContentEditableFalse(node)) { 3250 return false; 3251 } 3252 if (isContentEditableTrue$3(node)) { 3253 return true; 3254 } 3255 } 3256 return true; 3257 }; 3258 var isAtomicContentEditableFalse = function (node) { 3259 if (!isNonUiContentEditableFalse(node)) { 3260 return false; 3261 } 3262 return foldl(from(node.getElementsByTagName('*')), function (result, elm) { 3263 return result || isContentEditableTrue$3(elm); 3264 }, false) !== true; 3265 }; 3266 var isAtomic$1 = function (node) { 3267 return isAtomicInline(node) || isAtomicContentEditableFalse(node); 3268 }; 3269 var isEditableCaretCandidate$1 = function (node, root) { 3270 return isCaretCandidate$3(node) && isInEditable(node, root); 3271 }; 3272 3273 var whiteSpaceRegExp$1 = /^[ \t\r\n]*$/; 3274 var isWhitespaceText = function (text) { 3275 return whiteSpaceRegExp$1.test(text); 3276 }; 3277 3278 var hasWhitespacePreserveParent = function (node, rootNode) { 3279 var rootElement = SugarElement.fromDom(rootNode); 3280 var startNode = SugarElement.fromDom(node); 3281 return ancestor$1(startNode, 'pre,code', curry(eq, rootElement)); 3282 }; 3283 var isWhitespace = function (node, rootNode) { 3284 return isText$7(node) && isWhitespaceText(node.data) && hasWhitespacePreserveParent(node, rootNode) === false; 3285 }; 3286 var isNamedAnchor = function (node) { 3287 return isElement$5(node) && node.nodeName === 'A' && !node.hasAttribute('href') && (node.hasAttribute('name') || node.hasAttribute('id')); 3288 }; 3289 var isContent$1 = function (node, rootNode) { 3290 return isCaretCandidate$3(node) && isWhitespace(node, rootNode) === false || isNamedAnchor(node) || isBookmark(node); 3291 }; 3292 var isBookmark = hasAttribute('data-mce-bookmark'); 3293 var isBogus$1 = hasAttribute('data-mce-bogus'); 3294 var isBogusAll = hasAttributeValue('data-mce-bogus', 'all'); 3295 var isEmptyNode = function (targetNode, skipBogus) { 3296 var brCount = 0; 3297 if (isContent$1(targetNode, targetNode)) { 3298 return false; 3299 } else { 3300 var node = targetNode.firstChild; 3301 if (!node) { 3302 return true; 3303 } 3304 var walker = new DomTreeWalker(node, targetNode); 3305 do { 3306 if (skipBogus) { 3307 if (isBogusAll(node)) { 3308 node = walker.next(true); 3309 continue; 3310 } 3311 if (isBogus$1(node)) { 3312 node = walker.next(); 3313 continue; 3314 } 3315 } 3316 if (isBr$5(node)) { 3317 brCount++; 3318 node = walker.next(); 3319 continue; 3320 } 3321 if (isContent$1(node, targetNode)) { 3322 return false; 3323 } 3324 node = walker.next(); 3325 } while (node); 3326 return brCount <= 1; 3327 } 3328 }; 3329 var isEmpty$2 = function (elm, skipBogus) { 3330 if (skipBogus === void 0) { 3331 skipBogus = true; 3332 } 3333 return isEmptyNode(elm.dom, skipBogus); 3334 }; 3335 3336 var isSpan = function (node) { 3337 return node.nodeName.toLowerCase() === 'span'; 3338 }; 3339 var isInlineContent = function (node, root) { 3340 return isNonNullable(node) && (isContent$1(node, root) || isInline$1(SugarElement.fromDom(node))); 3341 }; 3342 var surroundedByInlineContent = function (node, root) { 3343 var prev = new DomTreeWalker(node, root).prev(false); 3344 var next = new DomTreeWalker(node, root).next(false); 3345 var prevIsInline = isUndefined(prev) || isInlineContent(prev, root); 3346 var nextIsInline = isUndefined(next) || isInlineContent(next, root); 3347 return prevIsInline && nextIsInline; 3348 }; 3349 var isBookmarkNode$2 = function (node) { 3350 return isSpan(node) && node.getAttribute('data-mce-type') === 'bookmark'; 3351 }; 3352 var isKeepTextNode = function (node, root) { 3353 return isText$7(node) && node.data.length > 0 && surroundedByInlineContent(node, root); 3354 }; 3355 var isKeepElement = function (node) { 3356 return isElement$5(node) ? node.childNodes.length > 0 : false; 3357 }; 3358 var isDocument = function (node) { 3359 return isDocumentFragment(node) || isDocument$1(node); 3360 }; 3361 var trimNode = function (dom, node, root) { 3362 var rootNode = root || node; 3363 if (isElement$5(node) && isBookmarkNode$2(node)) { 3364 return node; 3365 } 3366 var children = node.childNodes; 3367 for (var i = children.length - 1; i >= 0; i--) { 3368 trimNode(dom, children[i], rootNode); 3369 } 3370 if (isElement$5(node)) { 3371 var currentChildren = node.childNodes; 3372 if (currentChildren.length === 1 && isBookmarkNode$2(currentChildren[0])) { 3373 node.parentNode.insertBefore(currentChildren[0], node); 3374 } 3375 } 3376 if (!isDocument(node) && !isContent$1(node, rootNode) && !isKeepElement(node) && !isKeepTextNode(node, rootNode)) { 3377 dom.remove(node); 3378 } 3379 return node; 3380 }; 3381 3382 var makeMap$3 = Tools.makeMap; 3383 var attrsCharsRegExp = /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g; 3384 var textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g; 3385 var rawCharsRegExp = /[<>&\"\']/g; 3386 var entityRegExp = /&#([a-z0-9]+);?|&([a-z0-9]+);/gi; 3387 var asciiMap = { 3388 128: '\u20AC', 3389 130: '\u201A', 3390 131: '\u0192', 3391 132: '\u201E', 3392 133: '\u2026', 3393 134: '\u2020', 3394 135: '\u2021', 3395 136: '\u02c6', 3396 137: '\u2030', 3397 138: '\u0160', 3398 139: '\u2039', 3399 140: '\u0152', 3400 142: '\u017d', 3401 145: '\u2018', 3402 146: '\u2019', 3403 147: '\u201C', 3404 148: '\u201D', 3405 149: '\u2022', 3406 150: '\u2013', 3407 151: '\u2014', 3408 152: '\u02DC', 3409 153: '\u2122', 3410 154: '\u0161', 3411 155: '\u203A', 3412 156: '\u0153', 3413 158: '\u017e', 3414 159: '\u0178' 3415 }; 3416 var baseEntities = { 3417 '"': '"', 3418 '\'': ''', 3419 '<': '<', 3420 '>': '>', 3421 '&': '&', 3422 '`': '`' 3423 }; 3424 var reverseEntities = { 3425 '<': '<', 3426 '>': '>', 3427 '&': '&', 3428 '"': '"', 3429 ''': '\'' 3430 }; 3431 var nativeDecode = function (text) { 3432 var elm = SugarElement.fromTag('div').dom; 3433 elm.innerHTML = text; 3434 return elm.textContent || elm.innerText || text; 3435 }; 3436 var buildEntitiesLookup = function (items, radix) { 3437 var i, chr, entity; 3438 var lookup = {}; 3439 if (items) { 3440 items = items.split(','); 3441 radix = radix || 10; 3442 for (i = 0; i < items.length; i += 2) { 3443 chr = String.fromCharCode(parseInt(items[i], radix)); 3444 if (!baseEntities[chr]) { 3445 entity = '&' + items[i + 1] + ';'; 3446 lookup[chr] = entity; 3447 lookup[entity] = chr; 3448 } 3449 } 3450 return lookup; 3451 } 3452 }; 3453 var namedEntities = buildEntitiesLookup('50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' + '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' + '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' + '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' + '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' + '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' + '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' + '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' + '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' + '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' + 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' + 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' + 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' + 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' + 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' + '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' + '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' + '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' + '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' + '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' + 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' + 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' + 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' + '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' + '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32); 3454 var encodeRaw = function (text, attr) { 3455 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) { 3456 return baseEntities[chr] || chr; 3457 }); 3458 }; 3459 var encodeAllRaw = function (text) { 3460 return ('' + text).replace(rawCharsRegExp, function (chr) { 3461 return baseEntities[chr] || chr; 3462 }); 3463 }; 3464 var encodeNumeric = function (text, attr) { 3465 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) { 3466 if (chr.length > 1) { 3467 return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';'; 3468 } 3469 return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';'; 3470 }); 3471 }; 3472 var encodeNamed = function (text, attr, entities) { 3473 entities = entities || namedEntities; 3474 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) { 3475 return baseEntities[chr] || entities[chr] || chr; 3476 }); 3477 }; 3478 var getEncodeFunc = function (name, entities) { 3479 var entitiesMap = buildEntitiesLookup(entities) || namedEntities; 3480 var encodeNamedAndNumeric = function (text, attr) { 3481 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) { 3482 if (baseEntities[chr] !== undefined) { 3483 return baseEntities[chr]; 3484 } 3485 if (entitiesMap[chr] !== undefined) { 3486 return entitiesMap[chr]; 3487 } 3488 if (chr.length > 1) { 3489 return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';'; 3490 } 3491 return '&#' + chr.charCodeAt(0) + ';'; 3492 }); 3493 }; 3494 var encodeCustomNamed = function (text, attr) { 3495 return encodeNamed(text, attr, entitiesMap); 3496 }; 3497 var nameMap = makeMap$3(name.replace(/\+/g, ',')); 3498 if (nameMap.named && nameMap.numeric) { 3499 return encodeNamedAndNumeric; 3500 } 3501 if (nameMap.named) { 3502 if (entities) { 3503 return encodeCustomNamed; 3504 } 3505 return encodeNamed; 3506 } 3507 if (nameMap.numeric) { 3508 return encodeNumeric; 3509 } 3510 return encodeRaw; 3511 }; 3512 var decode = function (text) { 3513 return text.replace(entityRegExp, function (all, numeric) { 3514 if (numeric) { 3515 if (numeric.charAt(0).toLowerCase() === 'x') { 3516 numeric = parseInt(numeric.substr(1), 16); 3517 } else { 3518 numeric = parseInt(numeric, 10); 3519 } 3520 if (numeric > 65535) { 3521 numeric -= 65536; 3522 return String.fromCharCode(55296 + (numeric >> 10), 56320 + (numeric & 1023)); 3523 } 3524 return asciiMap[numeric] || String.fromCharCode(numeric); 3525 } 3526 return reverseEntities[all] || namedEntities[all] || nativeDecode(all); 3527 }); 3528 }; 3529 var Entities = { 3530 encodeRaw: encodeRaw, 3531 encodeAllRaw: encodeAllRaw, 3532 encodeNumeric: encodeNumeric, 3533 encodeNamed: encodeNamed, 3534 getEncodeFunc: getEncodeFunc, 3535 decode: decode 3536 }; 3537 3538 var mapCache = {}, dummyObj = {}; 3539 var makeMap$2 = Tools.makeMap, each$h = Tools.each, extend$5 = Tools.extend, explode$3 = Tools.explode, inArray$2 = Tools.inArray; 3540 var split$1 = function (items, delim) { 3541 items = Tools.trim(items); 3542 return items ? items.split(delim || ' ') : []; 3543 }; 3544 var createMap = function (defaultValue, extendWith) { 3545 var value = makeMap$2(defaultValue, ' ', makeMap$2(defaultValue.toUpperCase(), ' ')); 3546 return extend$5(value, extendWith); 3547 }; 3548 var getTextRootBlockElements = function (schema) { 3549 return createMap('td th li dt dd figcaption caption details summary', schema.getTextBlockElements()); 3550 }; 3551 var compileSchema = function (type) { 3552 var schema = {}; 3553 var globalAttributes, blockContent; 3554 var phrasingContent, flowContent, html4BlockContent, html4PhrasingContent; 3555 var add = function (name, attributes, children) { 3556 var ni, attributesOrder, element; 3557 var arrayToMap = function (array, obj) { 3558 var map = {}; 3559 var i, l; 3560 for (i = 0, l = array.length; i < l; i++) { 3561 map[array[i]] = obj || {}; 3562 } 3563 return map; 3564 }; 3565 children = children || []; 3566 attributes = attributes || ''; 3567 if (typeof children === 'string') { 3568 children = split$1(children); 3569 } 3570 var names = split$1(name); 3571 ni = names.length; 3572 while (ni--) { 3573 attributesOrder = split$1([ 3574 globalAttributes, 3575 attributes 3576 ].join(' ')); 3577 element = { 3578 attributes: arrayToMap(attributesOrder), 3579 attributesOrder: attributesOrder, 3580 children: arrayToMap(children, dummyObj) 3581 }; 3582 schema[names[ni]] = element; 3583 } 3584 }; 3585 var addAttrs = function (name, attributes) { 3586 var ni, schemaItem, i, l; 3587 var names = split$1(name); 3588 ni = names.length; 3589 var attrs = split$1(attributes); 3590 while (ni--) { 3591 schemaItem = schema[names[ni]]; 3592 for (i = 0, l = attrs.length; i < l; i++) { 3593 schemaItem.attributes[attrs[i]] = {}; 3594 schemaItem.attributesOrder.push(attrs[i]); 3595 } 3596 } 3597 }; 3598 if (mapCache[type]) { 3599 return mapCache[type]; 3600 } 3601 globalAttributes = 'id accesskey class dir lang style tabindex title role'; 3602 blockContent = 'address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul'; 3603 phrasingContent = 'a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd ' + 'label map noscript object q s samp script select small span strong sub sup ' + 'textarea u var #text #comment'; 3604 if (type !== 'html4') { 3605 globalAttributes += ' contenteditable contextmenu draggable dropzone ' + 'hidden spellcheck translate'; 3606 blockContent += ' article aside details dialog figure main header footer hgroup section nav'; 3607 phrasingContent += ' audio canvas command datalist mark meter output picture ' + 'progress time wbr video ruby bdi keygen'; 3608 } 3609 if (type !== 'html5-strict') { 3610 globalAttributes += ' xml:lang'; 3611 html4PhrasingContent = 'acronym applet basefont big font strike tt'; 3612 phrasingContent = [ 3613 phrasingContent, 3614 html4PhrasingContent 3615 ].join(' '); 3616 each$h(split$1(html4PhrasingContent), function (name) { 3617 add(name, '', phrasingContent); 3618 }); 3619 html4BlockContent = 'center dir isindex noframes'; 3620 blockContent = [ 3621 blockContent, 3622 html4BlockContent 3623 ].join(' '); 3624 flowContent = [ 3625 blockContent, 3626 phrasingContent 3627 ].join(' '); 3628 each$h(split$1(html4BlockContent), function (name) { 3629 add(name, '', flowContent); 3630 }); 3631 } 3632 flowContent = flowContent || [ 3633 blockContent, 3634 phrasingContent 3635 ].join(' '); 3636 add('html', 'manifest', 'head body'); 3637 add('head', '', 'base command link meta noscript script style title'); 3638 add('title hr noscript br'); 3639 add('base', 'href target'); 3640 add('link', 'href rel media hreflang type sizes hreflang'); 3641 add('meta', 'name http-equiv content charset'); 3642 add('style', 'media type scoped'); 3643 add('script', 'src async defer type charset'); 3644 add('body', 'onafterprint onbeforeprint onbeforeunload onblur onerror onfocus ' + 'onhashchange onload onmessage onoffline ononline onpagehide onpageshow ' + 'onpopstate onresize onscroll onstorage onunload', flowContent); 3645 add('address dt dd div caption', '', flowContent); 3646 add('h1 h2 h3 h4 h5 h6 pre p abbr code var samp kbd sub sup i b u bdo span legend em strong small s cite dfn', '', phrasingContent); 3647 add('blockquote', 'cite', flowContent); 3648 add('ol', 'reversed start type', 'li'); 3649 add('ul', '', 'li'); 3650 add('li', 'value', flowContent); 3651 add('dl', '', 'dt dd'); 3652 add('a', 'href target rel media hreflang type', phrasingContent); 3653 add('q', 'cite', phrasingContent); 3654 add('ins del', 'cite datetime', flowContent); 3655 add('img', 'src sizes srcset alt usemap ismap width height'); 3656 add('iframe', 'src name width height', flowContent); 3657 add('embed', 'src type width height'); 3658 add('object', 'data type typemustmatch name usemap form width height', [ 3659 flowContent, 3660 'param' 3661 ].join(' ')); 3662 add('param', 'name value'); 3663 add('map', 'name', [ 3664 flowContent, 3665 'area' 3666 ].join(' ')); 3667 add('area', 'alt coords shape href target rel media hreflang type'); 3668 add('table', 'border', 'caption colgroup thead tfoot tbody tr' + (type === 'html4' ? ' col' : '')); 3669 add('colgroup', 'span', 'col'); 3670 add('col', 'span'); 3671 add('tbody thead tfoot', '', 'tr'); 3672 add('tr', '', 'td th'); 3673 add('td', 'colspan rowspan headers', flowContent); 3674 add('th', 'colspan rowspan headers scope abbr', flowContent); 3675 add('form', 'accept-charset action autocomplete enctype method name novalidate target', flowContent); 3676 add('fieldset', 'disabled form name', [ 3677 flowContent, 3678 'legend' 3679 ].join(' ')); 3680 add('label', 'form for', phrasingContent); 3681 add('input', 'accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate ' + 'formtarget height list max maxlength min multiple name pattern readonly required size src step type value width'); 3682 add('button', 'disabled form formaction formenctype formmethod formnovalidate formtarget name type value', type === 'html4' ? flowContent : phrasingContent); 3683 add('select', 'disabled form multiple name required size', 'option optgroup'); 3684 add('optgroup', 'disabled label', 'option'); 3685 add('option', 'disabled label selected value'); 3686 add('textarea', 'cols dirname disabled form maxlength name readonly required rows wrap'); 3687 add('menu', 'type label', [ 3688 flowContent, 3689 'li' 3690 ].join(' ')); 3691 add('noscript', '', flowContent); 3692 if (type !== 'html4') { 3693 add('wbr'); 3694 add('ruby', '', [ 3695 phrasingContent, 3696 'rt rp' 3697 ].join(' ')); 3698 add('figcaption', '', flowContent); 3699 add('mark rt rp summary bdi', '', phrasingContent); 3700 add('canvas', 'width height', flowContent); 3701 add('video', 'src crossorigin poster preload autoplay mediagroup loop ' + 'muted controls width height buffered', [ 3702 flowContent, 3703 'track source' 3704 ].join(' ')); 3705 add('audio', 'src crossorigin preload autoplay mediagroup loop muted controls ' + 'buffered volume', [ 3706 flowContent, 3707 'track source' 3708 ].join(' ')); 3709 add('picture', '', 'img source'); 3710 add('source', 'src srcset type media sizes'); 3711 add('track', 'kind src srclang label default'); 3712 add('datalist', '', [ 3713 phrasingContent, 3714 'option' 3715 ].join(' ')); 3716 add('article section nav aside main header footer', '', flowContent); 3717 add('hgroup', '', 'h1 h2 h3 h4 h5 h6'); 3718 add('figure', '', [ 3719 flowContent, 3720 'figcaption' 3721 ].join(' ')); 3722 add('time', 'datetime', phrasingContent); 3723 add('dialog', 'open', flowContent); 3724 add('command', 'type label icon disabled checked radiogroup command'); 3725 add('output', 'for form name', phrasingContent); 3726 add('progress', 'value max', phrasingContent); 3727 add('meter', 'value min max low high optimum', phrasingContent); 3728 add('details', 'open', [ 3729 flowContent, 3730 'summary' 3731 ].join(' ')); 3732 add('keygen', 'autofocus challenge disabled form keytype name'); 3733 } 3734 if (type !== 'html5-strict') { 3735 addAttrs('script', 'language xml:space'); 3736 addAttrs('style', 'xml:space'); 3737 addAttrs('object', 'declare classid code codebase codetype archive standby align border hspace vspace'); 3738 addAttrs('embed', 'align name hspace vspace'); 3739 addAttrs('param', 'valuetype type'); 3740 addAttrs('a', 'charset name rev shape coords'); 3741 addAttrs('br', 'clear'); 3742 addAttrs('applet', 'codebase archive code object alt name width height align hspace vspace'); 3743 addAttrs('img', 'name longdesc align border hspace vspace'); 3744 addAttrs('iframe', 'longdesc frameborder marginwidth marginheight scrolling align'); 3745 addAttrs('font basefont', 'size color face'); 3746 addAttrs('input', 'usemap align'); 3747 addAttrs('select'); 3748 addAttrs('textarea'); 3749 addAttrs('h1 h2 h3 h4 h5 h6 div p legend caption', 'align'); 3750 addAttrs('ul', 'type compact'); 3751 addAttrs('li', 'type'); 3752 addAttrs('ol dl menu dir', 'compact'); 3753 addAttrs('pre', 'width xml:space'); 3754 addAttrs('hr', 'align noshade size width'); 3755 addAttrs('isindex', 'prompt'); 3756 addAttrs('table', 'summary width frame rules cellspacing cellpadding align bgcolor'); 3757 addAttrs('col', 'width align char charoff valign'); 3758 addAttrs('colgroup', 'width align char charoff valign'); 3759 addAttrs('thead', 'align char charoff valign'); 3760 addAttrs('tr', 'align char charoff valign bgcolor'); 3761 addAttrs('th', 'axis align char charoff valign nowrap bgcolor width height'); 3762 addAttrs('form', 'accept'); 3763 addAttrs('td', 'abbr axis scope align char charoff valign nowrap bgcolor width height'); 3764 addAttrs('tfoot', 'align char charoff valign'); 3765 addAttrs('tbody', 'align char charoff valign'); 3766 addAttrs('area', 'nohref'); 3767 addAttrs('body', 'background bgcolor text link vlink alink'); 3768 } 3769 if (type !== 'html4') { 3770 addAttrs('input button select textarea', 'autofocus'); 3771 addAttrs('input textarea', 'placeholder'); 3772 addAttrs('a', 'download'); 3773 addAttrs('link script img', 'crossorigin'); 3774 addAttrs('img', 'loading'); 3775 addAttrs('iframe', 'sandbox seamless allowfullscreen loading'); 3776 } 3777 each$h(split$1('a form meter progress dfn'), function (name) { 3778 if (schema[name]) { 3779 delete schema[name].children[name]; 3780 } 3781 }); 3782 delete schema.caption.children.table; 3783 delete schema.script; 3784 mapCache[type] = schema; 3785 return schema; 3786 }; 3787 var compileElementMap = function (value, mode) { 3788 var styles; 3789 if (value) { 3790 styles = {}; 3791 if (typeof value === 'string') { 3792 value = { '*': value }; 3793 } 3794 each$h(value, function (value, key) { 3795 styles[key] = styles[key.toUpperCase()] = mode === 'map' ? makeMap$2(value, /[, ]/) : explode$3(value, /[, ]/); 3796 }); 3797 } 3798 return styles; 3799 }; 3800 var Schema = function (settings) { 3801 var elements = {}; 3802 var children = {}; 3803 var patternElements = []; 3804 var customElementsMap = {}, specialElements = {}; 3805 var createLookupTable = function (option, defaultValue, extendWith) { 3806 var value = settings[option]; 3807 if (!value) { 3808 value = mapCache[option]; 3809 if (!value) { 3810 value = createMap(defaultValue, extendWith); 3811 mapCache[option] = value; 3812 } 3813 } else { 3814 value = makeMap$2(value, /[, ]/, makeMap$2(value.toUpperCase(), /[, ]/)); 3815 } 3816 return value; 3817 }; 3818 settings = settings || {}; 3819 var schemaItems = compileSchema(settings.schema); 3820 if (settings.verify_html === false) { 3821 settings.valid_elements = '*[*]'; 3822 } 3823 var validStyles = compileElementMap(settings.valid_styles); 3824 var invalidStyles = compileElementMap(settings.invalid_styles, 'map'); 3825 var validClasses = compileElementMap(settings.valid_classes, 'map'); 3826 var whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea video audio iframe object code'); 3827 var selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr'); 3828 var shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link ' + 'meta param embed source wbr track'); 3829 var boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize ' + 'noshade nowrap readonly selected autoplay loop controls'); 3830 var nonEmptyOrMoveCaretBeforeOnEnter = 'td th iframe video audio object script code'; 3831 var nonEmptyElementsMap = createLookupTable('non_empty_elements', nonEmptyOrMoveCaretBeforeOnEnter + ' pre', shortEndedElementsMap); 3832 var moveCaretBeforeOnEnterElementsMap = createLookupTable('move_caret_before_on_enter_elements', nonEmptyOrMoveCaretBeforeOnEnter + ' table', shortEndedElementsMap); 3833 var textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' + 'blockquote center dir fieldset header footer article section hgroup aside main nav figure'); 3834 var blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' + 'th tr td li ol ul caption dl dt dd noscript menu isindex option ' + 'datalist select optgroup figcaption details summary', textBlockElementsMap); 3835 var textInlineElementsMap = createLookupTable('text_inline_elements', 'span strong b em i font s strike u var cite ' + 'dfn code mark q sup sub samp'); 3836 each$h((settings.special || 'script noscript iframe noframes noembed title style textarea xmp').split(' '), function (name) { 3837 specialElements[name] = new RegExp('</' + name + '[^>]*>', 'gi'); 3838 }); 3839 var patternToRegExp = function (str) { 3840 return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$'); 3841 }; 3842 var addValidElements = function (validElements) { 3843 var ei, el, ai, al, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder, prefix, outputName, globalAttributes, globalAttributesOrder, value; 3844 var elementRuleRegExp = /^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)])?$/, attrRuleRegExp = /^([!\-])?(\w+[\\:]:\w+|[^=:<]+)?(?:([=:<])(.*))?$/, hasPatternsRegExp = /[*?+]/; 3845 if (validElements) { 3846 var validElementsArr = split$1(validElements, ','); 3847 if (elements['@']) { 3848 globalAttributes = elements['@'].attributes; 3849 globalAttributesOrder = elements['@'].attributesOrder; 3850 } 3851 for (ei = 0, el = validElementsArr.length; ei < el; ei++) { 3852 matches = elementRuleRegExp.exec(validElementsArr[ei]); 3853 if (matches) { 3854 prefix = matches[1]; 3855 elementName = matches[2]; 3856 outputName = matches[3]; 3857 attrData = matches[5]; 3858 attributes = {}; 3859 attributesOrder = []; 3860 element = { 3861 attributes: attributes, 3862 attributesOrder: attributesOrder 3863 }; 3864 if (prefix === '#') { 3865 element.paddEmpty = true; 3866 } 3867 if (prefix === '-') { 3868 element.removeEmpty = true; 3869 } 3870 if (matches[4] === '!') { 3871 element.removeEmptyAttrs = true; 3872 } 3873 if (globalAttributes) { 3874 each$j(globalAttributes, function (value, key) { 3875 attributes[key] = value; 3876 }); 3877 attributesOrder.push.apply(attributesOrder, globalAttributesOrder); 3878 } 3879 if (attrData) { 3880 attrData = split$1(attrData, '|'); 3881 for (ai = 0, al = attrData.length; ai < al; ai++) { 3882 matches = attrRuleRegExp.exec(attrData[ai]); 3883 if (matches) { 3884 attr = {}; 3885 attrType = matches[1]; 3886 attrName = matches[2].replace(/[\\:]:/g, ':'); 3887 prefix = matches[3]; 3888 value = matches[4]; 3889 if (attrType === '!') { 3890 element.attributesRequired = element.attributesRequired || []; 3891 element.attributesRequired.push(attrName); 3892 attr.required = true; 3893 } 3894 if (attrType === '-') { 3895 delete attributes[attrName]; 3896 attributesOrder.splice(inArray$2(attributesOrder, attrName), 1); 3897 continue; 3898 } 3899 if (prefix) { 3900 if (prefix === '=') { 3901 element.attributesDefault = element.attributesDefault || []; 3902 element.attributesDefault.push({ 3903 name: attrName, 3904 value: value 3905 }); 3906 attr.defaultValue = value; 3907 } 3908 if (prefix === ':') { 3909 element.attributesForced = element.attributesForced || []; 3910 element.attributesForced.push({ 3911 name: attrName, 3912 value: value 3913 }); 3914 attr.forcedValue = value; 3915 } 3916 if (prefix === '<') { 3917 attr.validValues = makeMap$2(value, '?'); 3918 } 3919 } 3920 if (hasPatternsRegExp.test(attrName)) { 3921 element.attributePatterns = element.attributePatterns || []; 3922 attr.pattern = patternToRegExp(attrName); 3923 element.attributePatterns.push(attr); 3924 } else { 3925 if (!attributes[attrName]) { 3926 attributesOrder.push(attrName); 3927 } 3928 attributes[attrName] = attr; 3929 } 3930 } 3931 } 3932 } 3933 if (!globalAttributes && elementName === '@') { 3934 globalAttributes = attributes; 3935 globalAttributesOrder = attributesOrder; 3936 } 3937 if (outputName) { 3938 element.outputName = elementName; 3939 elements[outputName] = element; 3940 } 3941 if (hasPatternsRegExp.test(elementName)) { 3942 element.pattern = patternToRegExp(elementName); 3943 patternElements.push(element); 3944 } else { 3945 elements[elementName] = element; 3946 } 3947 } 3948 } 3949 } 3950 }; 3951 var setValidElements = function (validElements) { 3952 elements = {}; 3953 patternElements = []; 3954 addValidElements(validElements); 3955 each$h(schemaItems, function (element, name) { 3956 children[name] = element.children; 3957 }); 3958 }; 3959 var addCustomElements = function (customElements) { 3960 var customElementRegExp = /^(~)?(.+)$/; 3961 if (customElements) { 3962 mapCache.text_block_elements = mapCache.block_elements = null; 3963 each$h(split$1(customElements, ','), function (rule) { 3964 var matches = customElementRegExp.exec(rule), inline = matches[1] === '~', cloneName = inline ? 'span' : 'div', name = matches[2]; 3965 children[name] = children[cloneName]; 3966 customElementsMap[name] = cloneName; 3967 if (!inline) { 3968 blockElementsMap[name.toUpperCase()] = {}; 3969 blockElementsMap[name] = {}; 3970 } 3971 if (!elements[name]) { 3972 var customRule = elements[cloneName]; 3973 customRule = extend$5({}, customRule); 3974 delete customRule.removeEmptyAttrs; 3975 delete customRule.removeEmpty; 3976 elements[name] = customRule; 3977 } 3978 each$h(children, function (element, elmName) { 3979 if (element[cloneName]) { 3980 children[elmName] = element = extend$5({}, children[elmName]); 3981 element[name] = element[cloneName]; 3982 } 3983 }); 3984 }); 3985 } 3986 }; 3987 var addValidChildren = function (validChildren) { 3988 var childRuleRegExp = /^([+\-]?)([A-Za-z0-9_\-.\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]+)\[([^\]]+)]$/; 3989 mapCache[settings.schema] = null; 3990 if (validChildren) { 3991 each$h(split$1(validChildren, ','), function (rule) { 3992 var matches = childRuleRegExp.exec(rule); 3993 var parent, prefix; 3994 if (matches) { 3995 prefix = matches[1]; 3996 if (prefix) { 3997 parent = children[matches[2]]; 3998 } else { 3999 parent = children[matches[2]] = { '#comment': {} }; 4000 } 4001 parent = children[matches[2]]; 4002 each$h(split$1(matches[3], '|'), function (child) { 4003 if (prefix === '-') { 4004 delete parent[child]; 4005 } else { 4006 parent[child] = {}; 4007 } 4008 }); 4009 } 4010 }); 4011 } 4012 }; 4013 var getElementRule = function (name) { 4014 var element = elements[name], i; 4015 if (element) { 4016 return element; 4017 } 4018 i = patternElements.length; 4019 while (i--) { 4020 element = patternElements[i]; 4021 if (element.pattern.test(name)) { 4022 return element; 4023 } 4024 } 4025 }; 4026 if (!settings.valid_elements) { 4027 each$h(schemaItems, function (element, name) { 4028 elements[name] = { 4029 attributes: element.attributes, 4030 attributesOrder: element.attributesOrder 4031 }; 4032 children[name] = element.children; 4033 }); 4034 if (settings.schema !== 'html5') { 4035 each$h(split$1('strong/b em/i'), function (item) { 4036 var items = split$1(item, '/'); 4037 elements[items[1]].outputName = items[0]; 4038 }); 4039 } 4040 each$h(textInlineElementsMap, function (_val, name) { 4041 if (elements[name]) { 4042 if (settings.padd_empty_block_inline_children) { 4043 elements[name].paddInEmptyBlock = true; 4044 } 4045 elements[name].removeEmpty = true; 4046 } 4047 }); 4048 each$h(split$1('ol ul blockquote a table tbody'), function (name) { 4049 if (elements[name]) { 4050 elements[name].removeEmpty = true; 4051 } 4052 }); 4053 each$h(split$1('p h1 h2 h3 h4 h5 h6 th td pre div address caption li'), function (name) { 4054 elements[name].paddEmpty = true; 4055 }); 4056 each$h(split$1('span'), function (name) { 4057 elements[name].removeEmptyAttrs = true; 4058 }); 4059 } else { 4060 setValidElements(settings.valid_elements); 4061 } 4062 addCustomElements(settings.custom_elements); 4063 addValidChildren(settings.valid_children); 4064 addValidElements(settings.extended_valid_elements); 4065 addValidChildren('+ol[ul|ol],+ul[ul|ol]'); 4066 each$h({ 4067 dd: 'dl', 4068 dt: 'dl', 4069 li: 'ul ol', 4070 td: 'tr', 4071 th: 'tr', 4072 tr: 'tbody thead tfoot', 4073 tbody: 'table', 4074 thead: 'table', 4075 tfoot: 'table', 4076 legend: 'fieldset', 4077 area: 'map', 4078 param: 'video audio object' 4079 }, function (parents, item) { 4080 if (elements[item]) { 4081 elements[item].parentsRequired = split$1(parents); 4082 } 4083 }); 4084 if (settings.invalid_elements) { 4085 each$h(explode$3(settings.invalid_elements), function (item) { 4086 if (elements[item]) { 4087 delete elements[item]; 4088 } 4089 }); 4090 } 4091 if (!getElementRule('span')) { 4092 addValidElements('span[!data-mce-type|*]'); 4093 } 4094 var getValidStyles = constant(validStyles); 4095 var getInvalidStyles = constant(invalidStyles); 4096 var getValidClasses = constant(validClasses); 4097 var getBoolAttrs = constant(boolAttrMap); 4098 var getBlockElements = constant(blockElementsMap); 4099 var getTextBlockElements = constant(textBlockElementsMap); 4100 var getTextInlineElements = constant(textInlineElementsMap); 4101 var getShortEndedElements = constant(shortEndedElementsMap); 4102 var getSelfClosingElements = constant(selfClosingElementsMap); 4103 var getNonEmptyElements = constant(nonEmptyElementsMap); 4104 var getMoveCaretBeforeOnEnterElements = constant(moveCaretBeforeOnEnterElementsMap); 4105 var getWhiteSpaceElements = constant(whiteSpaceElementsMap); 4106 var getSpecialElements = constant(specialElements); 4107 var isValidChild = function (name, child) { 4108 var parent = children[name.toLowerCase()]; 4109 return !!(parent && parent[child.toLowerCase()]); 4110 }; 4111 var isValid = function (name, attr) { 4112 var attrPatterns, i; 4113 var rule = getElementRule(name); 4114 if (rule) { 4115 if (attr) { 4116 if (rule.attributes[attr]) { 4117 return true; 4118 } 4119 attrPatterns = rule.attributePatterns; 4120 if (attrPatterns) { 4121 i = attrPatterns.length; 4122 while (i--) { 4123 if (attrPatterns[i].pattern.test(name)) { 4124 return true; 4125 } 4126 } 4127 } 4128 } else { 4129 return true; 4130 } 4131 } 4132 return false; 4133 }; 4134 var getCustomElements = constant(customElementsMap); 4135 return { 4136 children: children, 4137 elements: elements, 4138 getValidStyles: getValidStyles, 4139 getValidClasses: getValidClasses, 4140 getBlockElements: getBlockElements, 4141 getInvalidStyles: getInvalidStyles, 4142 getShortEndedElements: getShortEndedElements, 4143 getTextBlockElements: getTextBlockElements, 4144 getTextInlineElements: getTextInlineElements, 4145 getBoolAttrs: getBoolAttrs, 4146 getElementRule: getElementRule, 4147 getSelfClosingElements: getSelfClosingElements, 4148 getNonEmptyElements: getNonEmptyElements, 4149 getMoveCaretBeforeOnEnterElements: getMoveCaretBeforeOnEnterElements, 4150 getWhiteSpaceElements: getWhiteSpaceElements, 4151 getSpecialElements: getSpecialElements, 4152 isValidChild: isValidChild, 4153 isValid: isValid, 4154 getCustomElements: getCustomElements, 4155 addValidElements: addValidElements, 4156 setValidElements: setValidElements, 4157 addCustomElements: addCustomElements, 4158 addValidChildren: addValidChildren 4159 }; 4160 }; 4161 4162 var toHex = function (match, r, g, b) { 4163 var hex = function (val) { 4164 val = parseInt(val, 10).toString(16); 4165 return val.length > 1 ? val : '0' + val; 4166 }; 4167 return '#' + hex(r) + hex(g) + hex(b); 4168 }; 4169 var Styles = function (settings, schema) { 4170 var _this = this; 4171 var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi; 4172 var urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi; 4173 var styleRegExp = /\s*([^:]+):\s*([^;]+);?/g; 4174 var trimRightRegExp = /\s+$/; 4175 var i; 4176 var encodingLookup = {}; 4177 var validStyles; 4178 var invalidStyles; 4179 var invisibleChar = zeroWidth; 4180 settings = settings || {}; 4181 if (schema) { 4182 validStyles = schema.getValidStyles(); 4183 invalidStyles = schema.getInvalidStyles(); 4184 } 4185 var encodingItems = ('\\" \\\' \\; \\: ; : ' + invisibleChar).split(' '); 4186 for (i = 0; i < encodingItems.length; i++) { 4187 encodingLookup[encodingItems[i]] = invisibleChar + i; 4188 encodingLookup[invisibleChar + i] = encodingItems[i]; 4189 } 4190 return { 4191 toHex: function (color) { 4192 return color.replace(rgbRegExp, toHex); 4193 }, 4194 parse: function (css) { 4195 var styles = {}; 4196 var matches, name, value, isEncoded; 4197 var urlConverter = settings.url_converter; 4198 var urlConverterScope = settings.url_converter_scope || _this; 4199 var compress = function (prefix, suffix, noJoin) { 4200 var top = styles[prefix + '-top' + suffix]; 4201 if (!top) { 4202 return; 4203 } 4204 var right = styles[prefix + '-right' + suffix]; 4205 if (!right) { 4206 return; 4207 } 4208 var bottom = styles[prefix + '-bottom' + suffix]; 4209 if (!bottom) { 4210 return; 4211 } 4212 var left = styles[prefix + '-left' + suffix]; 4213 if (!left) { 4214 return; 4215 } 4216 var box = [ 4217 top, 4218 right, 4219 bottom, 4220 left 4221 ]; 4222 i = box.length - 1; 4223 while (i--) { 4224 if (box[i] !== box[i + 1]) { 4225 break; 4226 } 4227 } 4228 if (i > -1 && noJoin) { 4229 return; 4230 } 4231 styles[prefix + suffix] = i === -1 ? box[0] : box.join(' '); 4232 delete styles[prefix + '-top' + suffix]; 4233 delete styles[prefix + '-right' + suffix]; 4234 delete styles[prefix + '-bottom' + suffix]; 4235 delete styles[prefix + '-left' + suffix]; 4236 }; 4237 var canCompress = function (key) { 4238 var value = styles[key], i; 4239 if (!value) { 4240 return; 4241 } 4242 value = value.split(' '); 4243 i = value.length; 4244 while (i--) { 4245 if (value[i] !== value[0]) { 4246 return false; 4247 } 4248 } 4249 styles[key] = value[0]; 4250 return true; 4251 }; 4252 var compress2 = function (target, a, b, c) { 4253 if (!canCompress(a)) { 4254 return; 4255 } 4256 if (!canCompress(b)) { 4257 return; 4258 } 4259 if (!canCompress(c)) { 4260 return; 4261 } 4262 styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c]; 4263 delete styles[a]; 4264 delete styles[b]; 4265 delete styles[c]; 4266 }; 4267 var encode = function (str) { 4268 isEncoded = true; 4269 return encodingLookup[str]; 4270 }; 4271 var decode = function (str, keepSlashes) { 4272 if (isEncoded) { 4273 str = str.replace(/\uFEFF[0-9]/g, function (str) { 4274 return encodingLookup[str]; 4275 }); 4276 } 4277 if (!keepSlashes) { 4278 str = str.replace(/\\([\'\";:])/g, '$1'); 4279 } 4280 return str; 4281 }; 4282 var decodeSingleHexSequence = function (escSeq) { 4283 return String.fromCharCode(parseInt(escSeq.slice(1), 16)); 4284 }; 4285 var decodeHexSequences = function (value) { 4286 return value.replace(/\\[0-9a-f]+/gi, decodeSingleHexSequence); 4287 }; 4288 var processUrl = function (match, url, url2, url3, str, str2) { 4289 str = str || str2; 4290 if (str) { 4291 str = decode(str); 4292 return '\'' + str.replace(/\'/g, '\\\'') + '\''; 4293 } 4294 url = decode(url || url2 || url3); 4295 if (!settings.allow_script_urls) { 4296 var scriptUrl = url.replace(/[\s\r\n]+/g, ''); 4297 if (/(java|vb)script:/i.test(scriptUrl)) { 4298 return ''; 4299 } 4300 if (!settings.allow_svg_data_urls && /^data:image\/svg/i.test(scriptUrl)) { 4301 return ''; 4302 } 4303 } 4304 if (urlConverter) { 4305 url = urlConverter.call(urlConverterScope, url, 'style'); 4306 } 4307 return 'url(\'' + url.replace(/\'/g, '\\\'') + '\')'; 4308 }; 4309 if (css) { 4310 css = css.replace(/[\u0000-\u001F]/g, ''); 4311 css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function (str) { 4312 return str.replace(/[;:]/g, encode); 4313 }); 4314 while (matches = styleRegExp.exec(css)) { 4315 styleRegExp.lastIndex = matches.index + matches[0].length; 4316 name = matches[1].replace(trimRightRegExp, '').toLowerCase(); 4317 value = matches[2].replace(trimRightRegExp, ''); 4318 if (name && value) { 4319 name = decodeHexSequences(name); 4320 value = decodeHexSequences(value); 4321 if (name.indexOf(invisibleChar) !== -1 || name.indexOf('"') !== -1) { 4322 continue; 4323 } 4324 if (!settings.allow_script_urls && (name === 'behavior' || /expression\s*\(|\/\*|\*\//.test(value))) { 4325 continue; 4326 } 4327 if (name === 'font-weight' && value === '700') { 4328 value = 'bold'; 4329 } else if (name === 'color' || name === 'background-color') { 4330 value = value.toLowerCase(); 4331 } 4332 value = value.replace(rgbRegExp, toHex); 4333 value = value.replace(urlOrStrRegExp, processUrl); 4334 styles[name] = isEncoded ? decode(value, true) : value; 4335 } 4336 } 4337 compress('border', '', true); 4338 compress('border', '-width'); 4339 compress('border', '-color'); 4340 compress('border', '-style'); 4341 compress('padding', ''); 4342 compress('margin', ''); 4343 compress2('border', 'border-width', 'border-style', 'border-color'); 4344 if (styles.border === 'medium none') { 4345 delete styles.border; 4346 } 4347 if (styles['border-image'] === 'none') { 4348 delete styles['border-image']; 4349 } 4350 } 4351 return styles; 4352 }, 4353 serialize: function (styles, elementName) { 4354 var css = ''; 4355 var serializeStyles = function (name) { 4356 var value; 4357 var styleList = validStyles[name]; 4358 if (styleList) { 4359 for (var i_1 = 0, l = styleList.length; i_1 < l; i_1++) { 4360 name = styleList[i_1]; 4361 value = styles[name]; 4362 if (value) { 4363 css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';'; 4364 } 4365 } 4366 } 4367 }; 4368 var isValid = function (name, elementName) { 4369 var styleMap = invalidStyles['*']; 4370 if (styleMap && styleMap[name]) { 4371 return false; 4372 } 4373 styleMap = invalidStyles[elementName]; 4374 return !(styleMap && styleMap[name]); 4375 }; 4376 if (elementName && validStyles) { 4377 serializeStyles('*'); 4378 serializeStyles(elementName); 4379 } else { 4380 each$j(styles, function (value, name) { 4381 if (value && (!invalidStyles || isValid(name, elementName))) { 4382 css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';'; 4383 } 4384 }); 4385 } 4386 return css; 4387 } 4388 }; 4389 }; 4390 4391 var deprecated = { 4392 keyLocation: true, 4393 layerX: true, 4394 layerY: true, 4395 returnValue: true, 4396 webkitMovementX: true, 4397 webkitMovementY: true, 4398 keyIdentifier: true, 4399 mozPressure: true 4400 }; 4401 var isNativeEvent = function (event) { 4402 return event instanceof Event || isFunction(event.initEvent); 4403 }; 4404 var hasIsDefaultPrevented = function (event) { 4405 return event.isDefaultPrevented === always || event.isDefaultPrevented === never; 4406 }; 4407 var needsNormalizing = function (event) { 4408 return isNullable(event.preventDefault) || isNativeEvent(event); 4409 }; 4410 var clone$2 = function (originalEvent, data) { 4411 var event = data !== null && data !== void 0 ? data : {}; 4412 for (var name_1 in originalEvent) { 4413 if (!has$2(deprecated, name_1)) { 4414 event[name_1] = originalEvent[name_1]; 4415 } 4416 } 4417 if (isNonNullable(event.composedPath)) { 4418 event.composedPath = function () { 4419 return originalEvent.composedPath(); 4420 }; 4421 } 4422 return event; 4423 }; 4424 var normalize$3 = function (type, originalEvent, fallbackTarget, data) { 4425 var _a; 4426 var event = clone$2(originalEvent, data); 4427 event.type = type; 4428 if (isNullable(event.target)) { 4429 event.target = (_a = event.srcElement) !== null && _a !== void 0 ? _a : fallbackTarget; 4430 } 4431 if (needsNormalizing(originalEvent)) { 4432 event.preventDefault = function () { 4433 event.defaultPrevented = true; 4434 event.isDefaultPrevented = always; 4435 if (isFunction(originalEvent.preventDefault)) { 4436 originalEvent.preventDefault(); 4437 } else if (isNativeEvent(originalEvent)) { 4438 originalEvent.returnValue = false; 4439 } 4440 }; 4441 event.stopPropagation = function () { 4442 event.cancelBubble = true; 4443 event.isPropagationStopped = always; 4444 if (isFunction(originalEvent.stopPropagation)) { 4445 originalEvent.stopPropagation(); 4446 } else if (isNativeEvent(originalEvent)) { 4447 originalEvent.cancelBubble = true; 4448 } 4449 }; 4450 event.stopImmediatePropagation = function () { 4451 event.isImmediatePropagationStopped = always; 4452 event.stopPropagation(); 4453 }; 4454 if (!hasIsDefaultPrevented(event)) { 4455 event.isDefaultPrevented = event.defaultPrevented === true ? always : never; 4456 event.isPropagationStopped = event.cancelBubble === true ? always : never; 4457 event.isImmediatePropagationStopped = never; 4458 } 4459 } 4460 return event; 4461 }; 4462 4463 var eventExpandoPrefix = 'mce-data-'; 4464 var mouseEventRe = /^(?:mouse|contextmenu)|click/; 4465 var addEvent = function (target, name, callback, capture) { 4466 if (target.addEventListener) { 4467 target.addEventListener(name, callback, capture || false); 4468 } else if (target.attachEvent) { 4469 target.attachEvent('on' + name, callback); 4470 } 4471 }; 4472 var removeEvent = function (target, name, callback, capture) { 4473 if (target.removeEventListener) { 4474 target.removeEventListener(name, callback, capture || false); 4475 } else if (target.detachEvent) { 4476 target.detachEvent('on' + name, callback); 4477 } 4478 }; 4479 var isMouseEvent = function (event) { 4480 return isNonNullable(event) && mouseEventRe.test(event.type); 4481 }; 4482 var fix = function (originalEvent, data) { 4483 var event = normalize$3(originalEvent.type, originalEvent, document, data); 4484 if (isMouseEvent(originalEvent) && isUndefined(originalEvent.pageX) && !isUndefined(originalEvent.clientX)) { 4485 var eventDoc = event.target.ownerDocument || document; 4486 var doc = eventDoc.documentElement; 4487 var body = eventDoc.body; 4488 var mouseEvent = event; 4489 mouseEvent.pageX = originalEvent.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0); 4490 mouseEvent.pageY = originalEvent.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0); 4491 } 4492 if (isUndefined(event.metaKey)) { 4493 event.metaKey = false; 4494 } 4495 return event; 4496 }; 4497 var bindOnReady = function (win, callback, eventUtils) { 4498 var doc = win.document, event = { type: 'ready' }; 4499 if (eventUtils.domLoaded) { 4500 callback(event); 4501 return; 4502 } 4503 var isDocReady = function () { 4504 return doc.readyState === 'complete' || doc.readyState === 'interactive' && doc.body; 4505 }; 4506 var readyHandler = function () { 4507 removeEvent(win, 'DOMContentLoaded', readyHandler); 4508 removeEvent(win, 'load', readyHandler); 4509 if (!eventUtils.domLoaded) { 4510 eventUtils.domLoaded = true; 4511 callback(event); 4512 } 4513 win = null; 4514 }; 4515 if (isDocReady()) { 4516 readyHandler(); 4517 } else { 4518 addEvent(win, 'DOMContentLoaded', readyHandler); 4519 } 4520 if (!eventUtils.domLoaded) { 4521 addEvent(win, 'load', readyHandler); 4522 } 4523 }; 4524 var EventUtils = function () { 4525 function EventUtils() { 4526 this.domLoaded = false; 4527 this.events = {}; 4528 this.count = 1; 4529 this.expando = eventExpandoPrefix + (+new Date()).toString(32); 4530 this.hasMouseEnterLeave = 'onmouseenter' in document.documentElement; 4531 this.hasFocusIn = 'onfocusin' in document.documentElement; 4532 this.count = 1; 4533 } 4534 EventUtils.prototype.bind = function (target, names, callback, scope) { 4535 var self = this; 4536 var id, callbackList, i, name, fakeName, nativeHandler, capture; 4537 var win = window; 4538 var defaultNativeHandler = function (evt) { 4539 self.executeHandlers(fix(evt || win.event), id); 4540 }; 4541 if (!target || target.nodeType === 3 || target.nodeType === 8) { 4542 return; 4543 } 4544 if (!target[self.expando]) { 4545 id = self.count++; 4546 target[self.expando] = id; 4547 self.events[id] = {}; 4548 } else { 4549 id = target[self.expando]; 4550 } 4551 scope = scope || target; 4552 var namesList = names.split(' '); 4553 i = namesList.length; 4554 while (i--) { 4555 name = namesList[i]; 4556 nativeHandler = defaultNativeHandler; 4557 fakeName = capture = false; 4558 if (name === 'DOMContentLoaded') { 4559 name = 'ready'; 4560 } 4561 if (self.domLoaded && name === 'ready' && target.readyState === 'complete') { 4562 callback.call(scope, fix({ type: name })); 4563 continue; 4564 } 4565 if (!self.hasMouseEnterLeave) { 4566 fakeName = self.mouseEnterLeave[name]; 4567 if (fakeName) { 4568 nativeHandler = function (evt) { 4569 var current = evt.currentTarget; 4570 var related = evt.relatedTarget; 4571 if (related && current.contains) { 4572 related = current.contains(related); 4573 } else { 4574 while (related && related !== current) { 4575 related = related.parentNode; 4576 } 4577 } 4578 if (!related) { 4579 evt = fix(evt || win.event); 4580 evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter'; 4581 evt.target = current; 4582 self.executeHandlers(evt, id); 4583 } 4584 }; 4585 } 4586 } 4587 if (!self.hasFocusIn && (name === 'focusin' || name === 'focusout')) { 4588 capture = true; 4589 fakeName = name === 'focusin' ? 'focus' : 'blur'; 4590 nativeHandler = function (evt) { 4591 evt = fix(evt || win.event); 4592 evt.type = evt.type === 'focus' ? 'focusin' : 'focusout'; 4593 self.executeHandlers(evt, id); 4594 }; 4595 } 4596 callbackList = self.events[id][name]; 4597 if (!callbackList) { 4598 self.events[id][name] = callbackList = [{ 4599 func: callback, 4600 scope: scope 4601 }]; 4602 callbackList.fakeName = fakeName; 4603 callbackList.capture = capture; 4604 callbackList.nativeHandler = nativeHandler; 4605 if (name === 'ready') { 4606 bindOnReady(target, nativeHandler, self); 4607 } else { 4608 addEvent(target, fakeName || name, nativeHandler, capture); 4609 } 4610 } else { 4611 if (name === 'ready' && self.domLoaded) { 4612 callback(fix({ type: name })); 4613 } else { 4614 callbackList.push({ 4615 func: callback, 4616 scope: scope 4617 }); 4618 } 4619 } 4620 } 4621 target = callbackList = null; 4622 return callback; 4623 }; 4624 EventUtils.prototype.unbind = function (target, names, callback) { 4625 var callbackList, i, ci, name, eventMap; 4626 if (!target || target.nodeType === 3 || target.nodeType === 8) { 4627 return this; 4628 } 4629 var id = target[this.expando]; 4630 if (id) { 4631 eventMap = this.events[id]; 4632 if (names) { 4633 var namesList = names.split(' '); 4634 i = namesList.length; 4635 while (i--) { 4636 name = namesList[i]; 4637 callbackList = eventMap[name]; 4638 if (callbackList) { 4639 if (callback) { 4640 ci = callbackList.length; 4641 while (ci--) { 4642 if (callbackList[ci].func === callback) { 4643 var nativeHandler = callbackList.nativeHandler; 4644 var fakeName = callbackList.fakeName, capture = callbackList.capture; 4645 callbackList = callbackList.slice(0, ci).concat(callbackList.slice(ci + 1)); 4646 callbackList.nativeHandler = nativeHandler; 4647 callbackList.fakeName = fakeName; 4648 callbackList.capture = capture; 4649 eventMap[name] = callbackList; 4650 } 4651 } 4652 } 4653 if (!callback || callbackList.length === 0) { 4654 delete eventMap[name]; 4655 removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture); 4656 } 4657 } 4658 } 4659 } else { 4660 each$j(eventMap, function (callbackList, name) { 4661 removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture); 4662 }); 4663 eventMap = {}; 4664 } 4665 for (name in eventMap) { 4666 if (has$2(eventMap, name)) { 4667 return this; 4668 } 4669 } 4670 delete this.events[id]; 4671 try { 4672 delete target[this.expando]; 4673 } catch (ex) { 4674 target[this.expando] = null; 4675 } 4676 } 4677 return this; 4678 }; 4679 EventUtils.prototype.fire = function (target, name, args) { 4680 var id; 4681 if (!target || target.nodeType === 3 || target.nodeType === 8) { 4682 return this; 4683 } 4684 var event = fix({ 4685 type: name, 4686 target: target 4687 }, args); 4688 do { 4689 id = target[this.expando]; 4690 if (id) { 4691 this.executeHandlers(event, id); 4692 } 4693 target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow; 4694 } while (target && !event.isPropagationStopped()); 4695 return this; 4696 }; 4697 EventUtils.prototype.clean = function (target) { 4698 var i, children; 4699 if (!target || target.nodeType === 3 || target.nodeType === 8) { 4700 return this; 4701 } 4702 if (target[this.expando]) { 4703 this.unbind(target); 4704 } 4705 if (!target.getElementsByTagName) { 4706 target = target.document; 4707 } 4708 if (target && target.getElementsByTagName) { 4709 this.unbind(target); 4710 children = target.getElementsByTagName('*'); 4711 i = children.length; 4712 while (i--) { 4713 target = children[i]; 4714 if (target[this.expando]) { 4715 this.unbind(target); 4716 } 4717 } 4718 } 4719 return this; 4720 }; 4721 EventUtils.prototype.destroy = function () { 4722 this.events = {}; 4723 }; 4724 EventUtils.prototype.cancel = function (e) { 4725 if (e) { 4726 e.preventDefault(); 4727 e.stopImmediatePropagation(); 4728 } 4729 return false; 4730 }; 4731 EventUtils.prototype.executeHandlers = function (evt, id) { 4732 var container = this.events[id]; 4733 var callbackList = container && container[evt.type]; 4734 if (callbackList) { 4735 for (var i = 0, l = callbackList.length; i < l; i++) { 4736 var callback = callbackList[i]; 4737 if (callback && callback.func.call(callback.scope, evt) === false) { 4738 evt.preventDefault(); 4739 } 4740 if (evt.isImmediatePropagationStopped()) { 4741 return; 4742 } 4743 } 4744 } 4745 }; 4746 EventUtils.Event = new EventUtils(); 4747 return EventUtils; 4748 }(); 4749 4750 var support, Expr, getText, isXML, tokenize, compile, select$1, outermostContext, sortInput, hasDuplicate, setDocument, document$1, docElem, documentIsHTML, rbuggyQSA, rbuggyMatches, matches, contains, expando = 'sizzle' + -new Date(), preferredDoc = window.document, dirruns = 0, done = 0, classCache = createCache(), tokenCache = createCache(), compilerCache = createCache(), sortOrder = function (a, b) { 4751 if (a === b) { 4752 hasDuplicate = true; 4753 } 4754 return 0; 4755 }, strundefined = typeof undefined, MAX_NEGATIVE = 1 << 31, hasOwn = {}.hasOwnProperty, arr = [], pop = arr.pop, push_native = arr.push, push$1 = arr.push, slice$1 = arr.slice, indexOf = arr.indexOf || function (elem) { 4756 var i = 0, len = this.length; 4757 for (; i < len; i++) { 4758 if (this[i] === elem) { 4759 return i; 4760 } 4761 } 4762 return -1; 4763 }, booleans = 'checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped', whitespace = '[\\x20\\t\\r\\n\\f]', identifier = '(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+', attributes = '\\[' + whitespace + '*(' + identifier + ')(?:' + whitespace + '*([*^$|!~]?=)' + whitespace + '*(?:\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)"|(' + identifier + '))|)' + whitespace + '*\\]', pseudos = ':(' + identifier + ')(?:\\((' + '(\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)")|' + '((?:\\\\.|[^\\\\()[\\]]|' + attributes + ')*)|' + '.*' + ')\\)|)', rtrim = new RegExp('^' + whitespace + '+|((?:^|[^\\\\])(?:\\\\.)*)' + whitespace + '+$', 'g'), rcomma = new RegExp('^' + whitespace + '*,' + whitespace + '*'), rcombinators = new RegExp('^' + whitespace + '*([>+~]|' + whitespace + ')' + whitespace + '*'), rattributeQuotes = new RegExp('=' + whitespace + '*([^\\]\'"]*?)' + whitespace + '*\\]', 'g'), rpseudo = new RegExp(pseudos), ridentifier = new RegExp('^' + identifier + '$'), matchExpr = { 4764 ID: new RegExp('^#(' + identifier + ')'), 4765 CLASS: new RegExp('^\\.(' + identifier + ')'), 4766 TAG: new RegExp('^(' + identifier + '|[*])'), 4767 ATTR: new RegExp('^' + attributes), 4768 PSEUDO: new RegExp('^' + pseudos), 4769 CHILD: new RegExp('^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(' + whitespace + '*(even|odd|(([+-]|)(\\d*)n|)' + whitespace + '*(?:([+-]|)' + whitespace + '*(\\d+)|))' + whitespace + '*\\)|)', 'i'), 4770 bool: new RegExp('^(?:' + booleans + ')$', 'i'), 4771 needsContext: new RegExp('^' + whitespace + '*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(' + whitespace + '*((?:-\\d)?\\d*)' + whitespace + '*\\)|)(?=[^-]|$)', 'i') 4772 }, rinputs = /^(?:input|select|textarea|button)$/i, rheader = /^h\d$/i, rnative = /^[^{]+\{\s*\[native \w/, rquickExpr$1 = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, rsibling = /[+~]/, rescape = /'|\\/g, runescape = new RegExp('\\\\([\\da-f]{1,6}' + whitespace + '?|(' + whitespace + ')|.)', 'ig'), funescape = function (_, escaped, escapedWhitespace) { 4773 var high = '0x' + escaped - 65536; 4774 return high !== high || escapedWhitespace ? escaped : high < 0 ? String.fromCharCode(high + 65536) : String.fromCharCode(high >> 10 | 55296, high & 1023 | 56320); 4775 }; 4776 try { 4777 push$1.apply(arr = slice$1.call(preferredDoc.childNodes), preferredDoc.childNodes); 4778 arr[preferredDoc.childNodes.length].nodeType; 4779 } catch (e) { 4780 push$1 = { 4781 apply: arr.length ? function (target, els) { 4782 push_native.apply(target, slice$1.call(els)); 4783 } : function (target, els) { 4784 var j = target.length, i = 0; 4785 while (target[j++] = els[i++]) { 4786 } 4787 target.length = j - 1; 4788 } 4789 }; 4790 } 4791 var Sizzle = function (selector, context, results, seed) { 4792 var match, elem, m, nodeType, i, groups, old, nid, newContext, newSelector; 4793 if ((context ? context.ownerDocument || context : preferredDoc) !== document$1) { 4794 setDocument(context); 4795 } 4796 context = context || document$1; 4797 results = results || []; 4798 if (!selector || typeof selector !== 'string') { 4799 return results; 4800 } 4801 if ((nodeType = context.nodeType) !== 1 && nodeType !== 9) { 4802 return []; 4803 } 4804 if (documentIsHTML && !seed) { 4805 if (match = rquickExpr$1.exec(selector)) { 4806 if (m = match[1]) { 4807 if (nodeType === 9) { 4808 elem = context.getElementById(m); 4809 if (elem && elem.parentNode) { 4810 if (elem.id === m) { 4811 results.push(elem); 4812 return results; 4813 } 4814 } else { 4815 return results; 4816 } 4817 } else { 4818 if (context.ownerDocument && (elem = context.ownerDocument.getElementById(m)) && contains(context, elem) && elem.id === m) { 4819 results.push(elem); 4820 return results; 4821 } 4822 } 4823 } else if (match[2]) { 4824 push$1.apply(results, context.getElementsByTagName(selector)); 4825 return results; 4826 } else if ((m = match[3]) && support.getElementsByClassName) { 4827 push$1.apply(results, context.getElementsByClassName(m)); 4828 return results; 4829 } 4830 } 4831 if (support.qsa && (!rbuggyQSA || !rbuggyQSA.test(selector))) { 4832 nid = old = expando; 4833 newContext = context; 4834 newSelector = nodeType === 9 && selector; 4835 if (nodeType === 1 && context.nodeName.toLowerCase() !== 'object') { 4836 groups = tokenize(selector); 4837 if (old = context.getAttribute('id')) { 4838 nid = old.replace(rescape, '\\$&'); 4839 } else { 4840 context.setAttribute('id', nid); 4841 } 4842 nid = '[id=\'' + nid + '\'] '; 4843 i = groups.length; 4844 while (i--) { 4845 groups[i] = nid + toSelector(groups[i]); 4846 } 4847 newContext = rsibling.test(selector) && testContext(context.parentNode) || context; 4848 newSelector = groups.join(','); 4849 } 4850 if (newSelector) { 4851 try { 4852 push$1.apply(results, newContext.querySelectorAll(newSelector)); 4853 return results; 4854 } catch (qsaError) { 4855 } finally { 4856 if (!old) { 4857 context.removeAttribute('id'); 4858 } 4859 } 4860 } 4861 } 4862 } 4863 return select$1(selector.replace(rtrim, '$1'), context, results, seed); 4864 }; 4865 function createCache() { 4866 var keys = []; 4867 function cache(key, value) { 4868 if (keys.push(key + ' ') > Expr.cacheLength) { 4869 delete cache[keys.shift()]; 4870 } 4871 return cache[key + ' '] = value; 4872 } 4873 return cache; 4874 } 4875 function markFunction(fn) { 4876 fn[expando] = true; 4877 return fn; 4878 } 4879 function siblingCheck(a, b) { 4880 var cur = b && a, diff = cur && a.nodeType === 1 && b.nodeType === 1 && (~b.sourceIndex || MAX_NEGATIVE) - (~a.sourceIndex || MAX_NEGATIVE); 4881 if (diff) { 4882 return diff; 4883 } 4884 if (cur) { 4885 while (cur = cur.nextSibling) { 4886 if (cur === b) { 4887 return -1; 4888 } 4889 } 4890 } 4891 return a ? 1 : -1; 4892 } 4893 function createInputPseudo(type) { 4894 return function (elem) { 4895 var name = elem.nodeName.toLowerCase(); 4896 return name === 'input' && elem.type === type; 4897 }; 4898 } 4899 function createButtonPseudo(type) { 4900 return function (elem) { 4901 var name = elem.nodeName.toLowerCase(); 4902 return (name === 'input' || name === 'button') && elem.type === type; 4903 }; 4904 } 4905 function createPositionalPseudo(fn) { 4906 return markFunction(function (argument) { 4907 argument = +argument; 4908 return markFunction(function (seed, matches) { 4909 var j, matchIndexes = fn([], seed.length, argument), i = matchIndexes.length; 4910 while (i--) { 4911 if (seed[j = matchIndexes[i]]) { 4912 seed[j] = !(matches[j] = seed[j]); 4913 } 4914 } 4915 }); 4916 }); 4917 } 4918 function testContext(context) { 4919 return context && typeof context.getElementsByTagName !== strundefined && context; 4920 } 4921 support = Sizzle.support = {}; 4922 isXML = Sizzle.isXML = function (elem) { 4923 var documentElement = elem && (elem.ownerDocument || elem).documentElement; 4924 return documentElement ? documentElement.nodeName !== 'HTML' : false; 4925 }; 4926 setDocument = Sizzle.setDocument = function (node) { 4927 var hasCompare, doc = node ? node.ownerDocument || node : preferredDoc, parent = doc.defaultView; 4928 function getTop(win) { 4929 try { 4930 return win.top; 4931 } catch (ex) { 4932 } 4933 return null; 4934 } 4935 if (doc === document$1 || doc.nodeType !== 9 || !doc.documentElement) { 4936 return document$1; 4937 } 4938 document$1 = doc; 4939 docElem = doc.documentElement; 4940 documentIsHTML = !isXML(doc); 4941 if (parent && parent !== getTop(parent)) { 4942 if (parent.addEventListener) { 4943 parent.addEventListener('unload', function () { 4944 setDocument(); 4945 }, false); 4946 } else if (parent.attachEvent) { 4947 parent.attachEvent('onunload', function () { 4948 setDocument(); 4949 }); 4950 } 4951 } 4952 support.attributes = true; 4953 support.getElementsByTagName = true; 4954 support.getElementsByClassName = rnative.test(doc.getElementsByClassName); 4955 support.getById = true; 4956 Expr.find.ID = function (id, context) { 4957 if (typeof context.getElementById !== strundefined && documentIsHTML) { 4958 var m = context.getElementById(id); 4959 return m && m.parentNode ? [m] : []; 4960 } 4961 }; 4962 Expr.filter.ID = function (id) { 4963 var attrId = id.replace(runescape, funescape); 4964 return function (elem) { 4965 return elem.getAttribute('id') === attrId; 4966 }; 4967 }; 4968 Expr.find.TAG = support.getElementsByTagName ? function (tag, context) { 4969 if (typeof context.getElementsByTagName !== strundefined) { 4970 return context.getElementsByTagName(tag); 4971 } 4972 } : function (tag, context) { 4973 var elem, tmp = [], i = 0, results = context.getElementsByTagName(tag); 4974 if (tag === '*') { 4975 while (elem = results[i++]) { 4976 if (elem.nodeType === 1) { 4977 tmp.push(elem); 4978 } 4979 } 4980 return tmp; 4981 } 4982 return results; 4983 }; 4984 Expr.find.CLASS = support.getElementsByClassName && function (className, context) { 4985 if (documentIsHTML) { 4986 return context.getElementsByClassName(className); 4987 } 4988 }; 4989 rbuggyMatches = []; 4990 rbuggyQSA = []; 4991 support.disconnectedMatch = true; 4992 rbuggyQSA = rbuggyQSA.length && new RegExp(rbuggyQSA.join('|')); 4993 rbuggyMatches = rbuggyMatches.length && new RegExp(rbuggyMatches.join('|')); 4994 hasCompare = rnative.test(docElem.compareDocumentPosition); 4995 contains = hasCompare || rnative.test(docElem.contains) ? function (a, b) { 4996 var adown = a.nodeType === 9 ? a.documentElement : a, bup = b && b.parentNode; 4997 return a === bup || !!(bup && bup.nodeType === 1 && (adown.contains ? adown.contains(bup) : a.compareDocumentPosition && a.compareDocumentPosition(bup) & 16)); 4998 } : function (a, b) { 4999 if (b) { 5000 while (b = b.parentNode) { 5001 if (b === a) { 5002 return true; 5003 } 5004 } 5005 } 5006 return false; 5007 }; 5008 sortOrder = hasCompare ? function (a, b) { 5009 if (a === b) { 5010 hasDuplicate = true; 5011 return 0; 5012 } 5013 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition; 5014 if (compare) { 5015 return compare; 5016 } 5017 compare = (a.ownerDocument || a) === (b.ownerDocument || b) ? a.compareDocumentPosition(b) : 1; 5018 if (compare & 1 || !support.sortDetached && b.compareDocumentPosition(a) === compare) { 5019 if (a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a)) { 5020 return -1; 5021 } 5022 if (b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b)) { 5023 return 1; 5024 } 5025 return sortInput ? indexOf.call(sortInput, a) - indexOf.call(sortInput, b) : 0; 5026 } 5027 return compare & 4 ? -1 : 1; 5028 } : function (a, b) { 5029 if (a === b) { 5030 hasDuplicate = true; 5031 return 0; 5032 } 5033 var cur, i = 0, aup = a.parentNode, bup = b.parentNode, ap = [a], bp = [b]; 5034 if (!aup || !bup) { 5035 return a === doc ? -1 : b === doc ? 1 : aup ? -1 : bup ? 1 : sortInput ? indexOf.call(sortInput, a) - indexOf.call(sortInput, b) : 0; 5036 } else if (aup === bup) { 5037 return siblingCheck(a, b); 5038 } 5039 cur = a; 5040 while (cur = cur.parentNode) { 5041 ap.unshift(cur); 5042 } 5043 cur = b; 5044 while (cur = cur.parentNode) { 5045 bp.unshift(cur); 5046 } 5047 while (ap[i] === bp[i]) { 5048 i++; 5049 } 5050 return i ? siblingCheck(ap[i], bp[i]) : ap[i] === preferredDoc ? -1 : bp[i] === preferredDoc ? 1 : 0; 5051 }; 5052 return doc; 5053 }; 5054 Sizzle.matches = function (expr, elements) { 5055 return Sizzle(expr, null, null, elements); 5056 }; 5057 Sizzle.matchesSelector = function (elem, expr) { 5058 if ((elem.ownerDocument || elem) !== document$1) { 5059 setDocument(elem); 5060 } 5061 expr = expr.replace(rattributeQuotes, '=\'$1\']'); 5062 if (support.matchesSelector && documentIsHTML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && (!rbuggyQSA || !rbuggyQSA.test(expr))) { 5063 try { 5064 var ret = matches.call(elem, expr); 5065 if (ret || support.disconnectedMatch || elem.document && elem.document.nodeType !== 11) { 5066 return ret; 5067 } 5068 } catch (e) { 5069 } 5070 } 5071 return Sizzle(expr, document$1, null, [elem]).length > 0; 5072 }; 5073 Sizzle.contains = function (context, elem) { 5074 if ((context.ownerDocument || context) !== document$1) { 5075 setDocument(context); 5076 } 5077 return contains(context, elem); 5078 }; 5079 Sizzle.attr = function (elem, name) { 5080 if ((elem.ownerDocument || elem) !== document$1) { 5081 setDocument(elem); 5082 } 5083 var fn = Expr.attrHandle[name.toLowerCase()], val = fn && hasOwn.call(Expr.attrHandle, name.toLowerCase()) ? fn(elem, name, !documentIsHTML) : undefined; 5084 return val !== undefined ? val : support.attributes || !documentIsHTML ? elem.getAttribute(name) : (val = elem.getAttributeNode(name)) && val.specified ? val.value : null; 5085 }; 5086 Sizzle.error = function (msg) { 5087 throw new Error('Syntax error, unrecognized expression: ' + msg); 5088 }; 5089 Sizzle.uniqueSort = function (results) { 5090 var elem, duplicates = [], j = 0, i = 0; 5091 hasDuplicate = !support.detectDuplicates; 5092 sortInput = !support.sortStable && results.slice(0); 5093 results.sort(sortOrder); 5094 if (hasDuplicate) { 5095 while (elem = results[i++]) { 5096 if (elem === results[i]) { 5097 j = duplicates.push(i); 5098 } 5099 } 5100 while (j--) { 5101 results.splice(duplicates[j], 1); 5102 } 5103 } 5104 sortInput = null; 5105 return results; 5106 }; 5107 getText = Sizzle.getText = function (elem) { 5108 var node, ret = '', i = 0, nodeType = elem.nodeType; 5109 if (!nodeType) { 5110 while (node = elem[i++]) { 5111 ret += getText(node); 5112 } 5113 } else if (nodeType === 1 || nodeType === 9 || nodeType === 11) { 5114 if (typeof elem.textContent === 'string') { 5115 return elem.textContent; 5116 } else { 5117 for (elem = elem.firstChild; elem; elem = elem.nextSibling) { 5118 ret += getText(elem); 5119 } 5120 } 5121 } else if (nodeType === 3 || nodeType === 4) { 5122 return elem.nodeValue; 5123 } 5124 return ret; 5125 }; 5126 Expr = Sizzle.selectors = { 5127 cacheLength: 50, 5128 createPseudo: markFunction, 5129 match: matchExpr, 5130 attrHandle: {}, 5131 find: {}, 5132 relative: { 5133 '>': { 5134 dir: 'parentNode', 5135 first: true 5136 }, 5137 ' ': { dir: 'parentNode' }, 5138 '+': { 5139 dir: 'previousSibling', 5140 first: true 5141 }, 5142 '~': { dir: 'previousSibling' } 5143 }, 5144 preFilter: { 5145 ATTR: function (match) { 5146 match[1] = match[1].replace(runescape, funescape); 5147 match[3] = (match[3] || match[4] || match[5] || '').replace(runescape, funescape); 5148 if (match[2] === '~=') { 5149 match[3] = ' ' + match[3] + ' '; 5150 } 5151 return match.slice(0, 4); 5152 }, 5153 CHILD: function (match) { 5154 match[1] = match[1].toLowerCase(); 5155 if (match[1].slice(0, 3) === 'nth') { 5156 if (!match[3]) { 5157 Sizzle.error(match[0]); 5158 } 5159 match[4] = +(match[4] ? match[5] + (match[6] || 1) : 2 * (match[3] === 'even' || match[3] === 'odd')); 5160 match[5] = +(match[7] + match[8] || match[3] === 'odd'); 5161 } else if (match[3]) { 5162 Sizzle.error(match[0]); 5163 } 5164 return match; 5165 }, 5166 PSEUDO: function (match) { 5167 var excess, unquoted = !match[6] && match[2]; 5168 if (matchExpr.CHILD.test(match[0])) { 5169 return null; 5170 } 5171 if (match[3]) { 5172 match[2] = match[4] || match[5] || ''; 5173 } else if (unquoted && rpseudo.test(unquoted) && (excess = tokenize(unquoted, true)) && (excess = unquoted.indexOf(')', unquoted.length - excess) - unquoted.length)) { 5174 match[0] = match[0].slice(0, excess); 5175 match[2] = unquoted.slice(0, excess); 5176 } 5177 return match.slice(0, 3); 5178 } 5179 }, 5180 filter: { 5181 TAG: function (nodeNameSelector) { 5182 var nodeName = nodeNameSelector.replace(runescape, funescape).toLowerCase(); 5183 return nodeNameSelector === '*' ? function () { 5184 return true; 5185 } : function (elem) { 5186 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName; 5187 }; 5188 }, 5189 CLASS: function (className) { 5190 var pattern = classCache[className + ' ']; 5191 return pattern || (pattern = new RegExp('(^|' + whitespace + ')' + className + '(' + whitespace + '|$)')) && classCache(className, function (elem) { 5192 return pattern.test(typeof elem.className === 'string' && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute('class') || ''); 5193 }); 5194 }, 5195 ATTR: function (name, operator, check) { 5196 return function (elem) { 5197 var result = Sizzle.attr(elem, name); 5198 if (result == null) { 5199 return operator === '!='; 5200 } 5201 if (!operator) { 5202 return true; 5203 } 5204 result += ''; 5205 return operator === '=' ? result === check : operator === '!=' ? result !== check : operator === '^=' ? check && result.indexOf(check) === 0 : operator === '*=' ? check && result.indexOf(check) > -1 : operator === '$=' ? check && result.slice(-check.length) === check : operator === '~=' ? (' ' + result + ' ').indexOf(check) > -1 : operator === '|=' ? result === check || result.slice(0, check.length + 1) === check + '-' : false; 5206 }; 5207 }, 5208 CHILD: function (type, what, argument, first, last) { 5209 var simple = type.slice(0, 3) !== 'nth', forward = type.slice(-4) !== 'last', ofType = what === 'of-type'; 5210 return first === 1 && last === 0 ? function (elem) { 5211 return !!elem.parentNode; 5212 } : function (elem, context, xml) { 5213 var cache, outerCache, node, diff, nodeIndex, start, dir = simple !== forward ? 'nextSibling' : 'previousSibling', parent = elem.parentNode, name = ofType && elem.nodeName.toLowerCase(), useCache = !xml && !ofType; 5214 if (parent) { 5215 if (simple) { 5216 while (dir) { 5217 node = elem; 5218 while (node = node[dir]) { 5219 if (ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) { 5220 return false; 5221 } 5222 } 5223 start = dir = type === 'only' && !start && 'nextSibling'; 5224 } 5225 return true; 5226 } 5227 start = [forward ? parent.firstChild : parent.lastChild]; 5228 if (forward && useCache) { 5229 outerCache = parent[expando] || (parent[expando] = {}); 5230 cache = outerCache[type] || []; 5231 nodeIndex = cache[0] === dirruns && cache[1]; 5232 diff = cache[0] === dirruns && cache[2]; 5233 node = nodeIndex && parent.childNodes[nodeIndex]; 5234 while (node = ++nodeIndex && node && node[dir] || (diff = nodeIndex = 0) || start.pop()) { 5235 if (node.nodeType === 1 && ++diff && node === elem) { 5236 outerCache[type] = [ 5237 dirruns, 5238 nodeIndex, 5239 diff 5240 ]; 5241 break; 5242 } 5243 } 5244 } else if (useCache && (cache = (elem[expando] || (elem[expando] = {}))[type]) && cache[0] === dirruns) { 5245 diff = cache[1]; 5246 } else { 5247 while (node = ++nodeIndex && node && node[dir] || (diff = nodeIndex = 0) || start.pop()) { 5248 if ((ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) && ++diff) { 5249 if (useCache) { 5250 (node[expando] || (node[expando] = {}))[type] = [ 5251 dirruns, 5252 diff 5253 ]; 5254 } 5255 if (node === elem) { 5256 break; 5257 } 5258 } 5259 } 5260 } 5261 diff -= last; 5262 return diff === first || diff % first === 0 && diff / first >= 0; 5263 } 5264 }; 5265 }, 5266 PSEUDO: function (pseudo, argument) { 5267 var args, fn = Expr.pseudos[pseudo] || Expr.setFilters[pseudo.toLowerCase()] || Sizzle.error('unsupported pseudo: ' + pseudo); 5268 if (fn[expando]) { 5269 return fn(argument); 5270 } 5271 if (fn.length > 1) { 5272 args = [ 5273 pseudo, 5274 pseudo, 5275 '', 5276 argument 5277 ]; 5278 return Expr.setFilters.hasOwnProperty(pseudo.toLowerCase()) ? markFunction(function (seed, matches) { 5279 var idx, matched = fn(seed, argument), i = matched.length; 5280 while (i--) { 5281 idx = indexOf.call(seed, matched[i]); 5282 seed[idx] = !(matches[idx] = matched[i]); 5283 } 5284 }) : function (elem) { 5285 return fn(elem, 0, args); 5286 }; 5287 } 5288 return fn; 5289 } 5290 }, 5291 pseudos: { 5292 not: markFunction(function (selector) { 5293 var input = [], results = [], matcher = compile(selector.replace(rtrim, '$1')); 5294 return matcher[expando] ? markFunction(function (seed, matches, context, xml) { 5295 var elem, unmatched = matcher(seed, null, xml, []), i = seed.length; 5296 while (i--) { 5297 if (elem = unmatched[i]) { 5298 seed[i] = !(matches[i] = elem); 5299 } 5300 } 5301 }) : function (elem, context, xml) { 5302 input[0] = elem; 5303 matcher(input, null, xml, results); 5304 input[0] = null; 5305 return !results.pop(); 5306 }; 5307 }), 5308 has: markFunction(function (selector) { 5309 return function (elem) { 5310 return Sizzle(selector, elem).length > 0; 5311 }; 5312 }), 5313 contains: markFunction(function (text) { 5314 text = text.replace(runescape, funescape); 5315 return function (elem) { 5316 return (elem.textContent || elem.innerText || getText(elem)).indexOf(text) > -1; 5317 }; 5318 }), 5319 lang: markFunction(function (lang) { 5320 if (!ridentifier.test(lang || '')) { 5321 Sizzle.error('unsupported lang: ' + lang); 5322 } 5323 lang = lang.replace(runescape, funescape).toLowerCase(); 5324 return function (elem) { 5325 var elemLang; 5326 do { 5327 if (elemLang = documentIsHTML ? elem.lang : elem.getAttribute('xml:lang') || elem.getAttribute('lang')) { 5328 elemLang = elemLang.toLowerCase(); 5329 return elemLang === lang || elemLang.indexOf(lang + '-') === 0; 5330 } 5331 } while ((elem = elem.parentNode) && elem.nodeType === 1); 5332 return false; 5333 }; 5334 }), 5335 target: function (elem) { 5336 var hash = window.location && window.location.hash; 5337 return hash && hash.slice(1) === elem.id; 5338 }, 5339 root: function (elem) { 5340 return elem === docElem; 5341 }, 5342 focus: function (elem) { 5343 return elem === document$1.activeElement && (!document$1.hasFocus || document$1.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); 5344 }, 5345 enabled: function (elem) { 5346 return elem.disabled === false; 5347 }, 5348 disabled: function (elem) { 5349 return elem.disabled === true; 5350 }, 5351 checked: function (elem) { 5352 var nodeName = elem.nodeName.toLowerCase(); 5353 return nodeName === 'input' && !!elem.checked || nodeName === 'option' && !!elem.selected; 5354 }, 5355 selected: function (elem) { 5356 if (elem.parentNode) { 5357 elem.parentNode.selectedIndex; 5358 } 5359 return elem.selected === true; 5360 }, 5361 empty: function (elem) { 5362 for (elem = elem.firstChild; elem; elem = elem.nextSibling) { 5363 if (elem.nodeType < 6) { 5364 return false; 5365 } 5366 } 5367 return true; 5368 }, 5369 parent: function (elem) { 5370 return !Expr.pseudos.empty(elem); 5371 }, 5372 header: function (elem) { 5373 return rheader.test(elem.nodeName); 5374 }, 5375 input: function (elem) { 5376 return rinputs.test(elem.nodeName); 5377 }, 5378 button: function (elem) { 5379 var name = elem.nodeName.toLowerCase(); 5380 return name === 'input' && elem.type === 'button' || name === 'button'; 5381 }, 5382 text: function (elem) { 5383 var attr; 5384 return elem.nodeName.toLowerCase() === 'input' && elem.type === 'text' && ((attr = elem.getAttribute('type')) == null || attr.toLowerCase() === 'text'); 5385 }, 5386 first: createPositionalPseudo(function () { 5387 return [0]; 5388 }), 5389 last: createPositionalPseudo(function (matchIndexes, length) { 5390 return [length - 1]; 5391 }), 5392 eq: createPositionalPseudo(function (matchIndexes, length, argument) { 5393 return [argument < 0 ? argument + length : argument]; 5394 }), 5395 even: createPositionalPseudo(function (matchIndexes, length) { 5396 var i = 0; 5397 for (; i < length; i += 2) { 5398 matchIndexes.push(i); 5399 } 5400 return matchIndexes; 5401 }), 5402 odd: createPositionalPseudo(function (matchIndexes, length) { 5403 var i = 1; 5404 for (; i < length; i += 2) { 5405 matchIndexes.push(i); 5406 } 5407 return matchIndexes; 5408 }), 5409 lt: createPositionalPseudo(function (matchIndexes, length, argument) { 5410 var i = argument < 0 ? argument + length : argument; 5411 for (; --i >= 0;) { 5412 matchIndexes.push(i); 5413 } 5414 return matchIndexes; 5415 }), 5416 gt: createPositionalPseudo(function (matchIndexes, length, argument) { 5417 var i = argument < 0 ? argument + length : argument; 5418 for (; ++i < length;) { 5419 matchIndexes.push(i); 5420 } 5421 return matchIndexes; 5422 }) 5423 } 5424 }; 5425 Expr.pseudos.nth = Expr.pseudos.eq; 5426 each$k([ 5427 'radio', 5428 'checkbox', 5429 'file', 5430 'password', 5431 'image' 5432 ], function (i) { 5433 Expr.pseudos[i] = createInputPseudo(i); 5434 }); 5435 each$k([ 5436 'submit', 5437 'reset' 5438 ], function (i) { 5439 Expr.pseudos[i] = createButtonPseudo(i); 5440 }); 5441 function setFilters() { 5442 } 5443 setFilters.prototype = Expr.filters = Expr.pseudos; 5444 Expr.setFilters = new setFilters(); 5445 tokenize = Sizzle.tokenize = function (selector, parseOnly) { 5446 var matched, match, tokens, type, soFar, groups, preFilters, cached = tokenCache[selector + ' ']; 5447 if (cached) { 5448 return parseOnly ? 0 : cached.slice(0); 5449 } 5450 soFar = selector; 5451 groups = []; 5452 preFilters = Expr.preFilter; 5453 while (soFar) { 5454 if (!matched || (match = rcomma.exec(soFar))) { 5455 if (match) { 5456 soFar = soFar.slice(match[0].length) || soFar; 5457 } 5458 groups.push(tokens = []); 5459 } 5460 matched = false; 5461 if (match = rcombinators.exec(soFar)) { 5462 matched = match.shift(); 5463 tokens.push({ 5464 value: matched, 5465 type: match[0].replace(rtrim, ' ') 5466 }); 5467 soFar = soFar.slice(matched.length); 5468 } 5469 for (type in Expr.filter) { 5470 if (!Expr.filter.hasOwnProperty(type)) { 5471 continue; 5472 } 5473 if ((match = matchExpr[type].exec(soFar)) && (!preFilters[type] || (match = preFilters[type](match)))) { 5474 matched = match.shift(); 5475 tokens.push({ 5476 value: matched, 5477 type: type, 5478 matches: match 5479 }); 5480 soFar = soFar.slice(matched.length); 5481 } 5482 } 5483 if (!matched) { 5484 break; 5485 } 5486 } 5487 return parseOnly ? soFar.length : soFar ? Sizzle.error(selector) : tokenCache(selector, groups).slice(0); 5488 }; 5489 function toSelector(tokens) { 5490 var i = 0, len = tokens.length, selector = ''; 5491 for (; i < len; i++) { 5492 selector += tokens[i].value; 5493 } 5494 return selector; 5495 } 5496 function addCombinator(matcher, combinator, base) { 5497 var dir = combinator.dir, checkNonElements = base && dir === 'parentNode', doneName = done++; 5498 return combinator.first ? function (elem, context, xml) { 5499 while (elem = elem[dir]) { 5500 if (elem.nodeType === 1 || checkNonElements) { 5501 return matcher(elem, context, xml); 5502 } 5503 } 5504 } : function (elem, context, xml) { 5505 var oldCache, outerCache, newCache = [ 5506 dirruns, 5507 doneName 5508 ]; 5509 if (xml) { 5510 while (elem = elem[dir]) { 5511 if (elem.nodeType === 1 || checkNonElements) { 5512 if (matcher(elem, context, xml)) { 5513 return true; 5514 } 5515 } 5516 } 5517 } else { 5518 while (elem = elem[dir]) { 5519 if (elem.nodeType === 1 || checkNonElements) { 5520 outerCache = elem[expando] || (elem[expando] = {}); 5521 if ((oldCache = outerCache[dir]) && oldCache[0] === dirruns && oldCache[1] === doneName) { 5522 return newCache[2] = oldCache[2]; 5523 } else { 5524 outerCache[dir] = newCache; 5525 if (newCache[2] = matcher(elem, context, xml)) { 5526 return true; 5527 } 5528 } 5529 } 5530 } 5531 } 5532 }; 5533 } 5534 function elementMatcher(matchers) { 5535 return matchers.length > 1 ? function (elem, context, xml) { 5536 var i = matchers.length; 5537 while (i--) { 5538 if (!matchers[i](elem, context, xml)) { 5539 return false; 5540 } 5541 } 5542 return true; 5543 } : matchers[0]; 5544 } 5545 function multipleContexts(selector, contexts, results) { 5546 var i = 0, len = contexts.length; 5547 for (; i < len; i++) { 5548 Sizzle(selector, contexts[i], results); 5549 } 5550 return results; 5551 } 5552 function condense(unmatched, map, filter, context, xml) { 5553 var elem, newUnmatched = [], i = 0, len = unmatched.length, mapped = map != null; 5554 for (; i < len; i++) { 5555 if (elem = unmatched[i]) { 5556 if (!filter || filter(elem, context, xml)) { 5557 newUnmatched.push(elem); 5558 if (mapped) { 5559 map.push(i); 5560 } 5561 } 5562 } 5563 } 5564 return newUnmatched; 5565 } 5566 function setMatcher(preFilter, selector, matcher, postFilter, postFinder, postSelector) { 5567 if (postFilter && !postFilter[expando]) { 5568 postFilter = setMatcher(postFilter); 5569 } 5570 if (postFinder && !postFinder[expando]) { 5571 postFinder = setMatcher(postFinder, postSelector); 5572 } 5573 return markFunction(function (seed, results, context, xml) { 5574 var temp, i, elem, preMap = [], postMap = [], preexisting = results.length, elems = seed || multipleContexts(selector || '*', context.nodeType ? [context] : context, []), matcherIn = preFilter && (seed || !selector) ? condense(elems, preMap, preFilter, context, xml) : elems, matcherOut = matcher ? postFinder || (seed ? preFilter : preexisting || postFilter) ? [] : results : matcherIn; 5575 if (matcher) { 5576 matcher(matcherIn, matcherOut, context, xml); 5577 } 5578 if (postFilter) { 5579 temp = condense(matcherOut, postMap); 5580 postFilter(temp, [], context, xml); 5581 i = temp.length; 5582 while (i--) { 5583 if (elem = temp[i]) { 5584 matcherOut[postMap[i]] = !(matcherIn[postMap[i]] = elem); 5585 } 5586 } 5587 } 5588 if (seed) { 5589 if (postFinder || preFilter) { 5590 if (postFinder) { 5591 temp = []; 5592 i = matcherOut.length; 5593 while (i--) { 5594 if (elem = matcherOut[i]) { 5595 temp.push(matcherIn[i] = elem); 5596 } 5597 } 5598 postFinder(null, matcherOut = [], temp, xml); 5599 } 5600 i = matcherOut.length; 5601 while (i--) { 5602 if ((elem = matcherOut[i]) && (temp = postFinder ? indexOf.call(seed, elem) : preMap[i]) > -1) { 5603 seed[temp] = !(results[temp] = elem); 5604 } 5605 } 5606 } 5607 } else { 5608 matcherOut = condense(matcherOut === results ? matcherOut.splice(preexisting, matcherOut.length) : matcherOut); 5609 if (postFinder) { 5610 postFinder(null, results, matcherOut, xml); 5611 } else { 5612 push$1.apply(results, matcherOut); 5613 } 5614 } 5615 }); 5616 } 5617 function matcherFromTokens(tokens) { 5618 var checkContext, matcher, j, len = tokens.length, leadingRelative = Expr.relative[tokens[0].type], implicitRelative = leadingRelative || Expr.relative[' '], i = leadingRelative ? 1 : 0, matchContext = addCombinator(function (elem) { 5619 return elem === checkContext; 5620 }, implicitRelative, true), matchAnyContext = addCombinator(function (elem) { 5621 return indexOf.call(checkContext, elem) > -1; 5622 }, implicitRelative, true), matchers = [function (elem, context, xml) { 5623 var ret = !leadingRelative && (xml || context !== outermostContext) || ((checkContext = context).nodeType ? matchContext(elem, context, xml) : matchAnyContext(elem, context, xml)); 5624 checkContext = null; 5625 return ret; 5626 }]; 5627 for (; i < len; i++) { 5628 if (matcher = Expr.relative[tokens[i].type]) { 5629 matchers = [addCombinator(elementMatcher(matchers), matcher)]; 5630 } else { 5631 matcher = Expr.filter[tokens[i].type].apply(null, tokens[i].matches); 5632 if (matcher[expando]) { 5633 j = ++i; 5634 for (; j < len; j++) { 5635 if (Expr.relative[tokens[j].type]) { 5636 break; 5637 } 5638 } 5639 return setMatcher(i > 1 && elementMatcher(matchers), i > 1 && toSelector(tokens.slice(0, i - 1).concat({ value: tokens[i - 2].type === ' ' ? '*' : '' })).replace(rtrim, '$1'), matcher, i < j && matcherFromTokens(tokens.slice(i, j)), j < len && matcherFromTokens(tokens = tokens.slice(j)), j < len && toSelector(tokens)); 5640 } 5641 matchers.push(matcher); 5642 } 5643 } 5644 return elementMatcher(matchers); 5645 } 5646 function matcherFromGroupMatchers(elementMatchers, setMatchers) { 5647 var bySet = setMatchers.length > 0, byElement = elementMatchers.length > 0, superMatcher = function (seed, context, xml, results, outermost) { 5648 var elem, j, matcher, matchedCount = 0, i = '0', unmatched = seed && [], setMatched = [], contextBackup = outermostContext, elems = seed || byElement && Expr.find.TAG('*', outermost), dirrunsUnique = dirruns += contextBackup == null ? 1 : Math.random() || 0.1, len = elems.length; 5649 if (outermost) { 5650 outermostContext = context !== document$1 && context; 5651 } 5652 for (; i !== len && (elem = elems[i]) != null; i++) { 5653 if (byElement && elem) { 5654 j = 0; 5655 while (matcher = elementMatchers[j++]) { 5656 if (matcher(elem, context, xml)) { 5657 results.push(elem); 5658 break; 5659 } 5660 } 5661 if (outermost) { 5662 dirruns = dirrunsUnique; 5663 } 5664 } 5665 if (bySet) { 5666 if (elem = !matcher && elem) { 5667 matchedCount--; 5668 } 5669 if (seed) { 5670 unmatched.push(elem); 5671 } 5672 } 5673 } 5674 matchedCount += i; 5675 if (bySet && i !== matchedCount) { 5676 j = 0; 5677 while (matcher = setMatchers[j++]) { 5678 matcher(unmatched, setMatched, context, xml); 5679 } 5680 if (seed) { 5681 if (matchedCount > 0) { 5682 while (i--) { 5683 if (!(unmatched[i] || setMatched[i])) { 5684 setMatched[i] = pop.call(results); 5685 } 5686 } 5687 } 5688 setMatched = condense(setMatched); 5689 } 5690 push$1.apply(results, setMatched); 5691 if (outermost && !seed && setMatched.length > 0 && matchedCount + setMatchers.length > 1) { 5692 Sizzle.uniqueSort(results); 5693 } 5694 } 5695 if (outermost) { 5696 dirruns = dirrunsUnique; 5697 outermostContext = contextBackup; 5698 } 5699 return unmatched; 5700 }; 5701 return bySet ? markFunction(superMatcher) : superMatcher; 5702 } 5703 compile = Sizzle.compile = function (selector, match) { 5704 var i, setMatchers = [], elementMatchers = [], cached = compilerCache[selector + ' ']; 5705 if (!cached) { 5706 if (!match) { 5707 match = tokenize(selector); 5708 } 5709 i = match.length; 5710 while (i--) { 5711 cached = matcherFromTokens(match[i]); 5712 if (cached[expando]) { 5713 setMatchers.push(cached); 5714 } else { 5715 elementMatchers.push(cached); 5716 } 5717 } 5718 cached = compilerCache(selector, matcherFromGroupMatchers(elementMatchers, setMatchers)); 5719 cached.selector = selector; 5720 } 5721 return cached; 5722 }; 5723 select$1 = Sizzle.select = function (selector, context, results, seed) { 5724 var i, tokens, token, type, find, compiled = typeof selector === 'function' && selector, match = !seed && tokenize(selector = compiled.selector || selector); 5725 results = results || []; 5726 if (match.length === 1) { 5727 tokens = match[0] = match[0].slice(0); 5728 if (tokens.length > 2 && (token = tokens[0]).type === 'ID' && support.getById && context.nodeType === 9 && documentIsHTML && Expr.relative[tokens[1].type]) { 5729 context = (Expr.find.ID(token.matches[0].replace(runescape, funescape), context) || [])[0]; 5730 if (!context) { 5731 return results; 5732 } else if (compiled) { 5733 context = context.parentNode; 5734 } 5735 selector = selector.slice(tokens.shift().value.length); 5736 } 5737 i = matchExpr.needsContext.test(selector) ? 0 : tokens.length; 5738 while (i--) { 5739 token = tokens[i]; 5740 if (Expr.relative[type = token.type]) { 5741 break; 5742 } 5743 if (find = Expr.find[type]) { 5744 if (seed = find(token.matches[0].replace(runescape, funescape), rsibling.test(tokens[0].type) && testContext(context.parentNode) || context)) { 5745 tokens.splice(i, 1); 5746 selector = seed.length && toSelector(tokens); 5747 if (!selector) { 5748 push$1.apply(results, seed); 5749 return results; 5750 } 5751 break; 5752 } 5753 } 5754 } 5755 } 5756 (compiled || compile(selector, match))(seed, context, !documentIsHTML, results, rsibling.test(selector) && testContext(context.parentNode) || context); 5757 return results; 5758 }; 5759 support.sortStable = expando.split('').sort(sortOrder).join('') === expando; 5760 support.detectDuplicates = !!hasDuplicate; 5761 setDocument(); 5762 support.sortDetached = true; 5763 5764 var doc = document; 5765 var push = Array.prototype.push; 5766 var slice = Array.prototype.slice; 5767 var rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/; 5768 var Event$1 = EventUtils.Event; 5769 var skipUniques = Tools.makeMap('children,contents,next,prev'); 5770 var isDefined = function (obj) { 5771 return typeof obj !== 'undefined'; 5772 }; 5773 var isString = function (obj) { 5774 return typeof obj === 'string'; 5775 }; 5776 var isWindow = function (obj) { 5777 return obj && obj === obj.window; 5778 }; 5779 var createFragment$1 = function (html, fragDoc) { 5780 fragDoc = fragDoc || doc; 5781 var container = fragDoc.createElement('div'); 5782 var frag = fragDoc.createDocumentFragment(); 5783 container.innerHTML = html; 5784 var node; 5785 while (node = container.firstChild) { 5786 frag.appendChild(node); 5787 } 5788 return frag; 5789 }; 5790 var domManipulate = function (targetNodes, sourceItem, callback, reverse) { 5791 var i; 5792 if (isString(sourceItem)) { 5793 sourceItem = createFragment$1(sourceItem, getElementDocument(targetNodes[0])); 5794 } else if (sourceItem.length && !sourceItem.nodeType) { 5795 sourceItem = DomQuery.makeArray(sourceItem); 5796 if (reverse) { 5797 for (i = sourceItem.length - 1; i >= 0; i--) { 5798 domManipulate(targetNodes, sourceItem[i], callback, reverse); 5799 } 5800 } else { 5801 for (i = 0; i < sourceItem.length; i++) { 5802 domManipulate(targetNodes, sourceItem[i], callback, reverse); 5803 } 5804 } 5805 return targetNodes; 5806 } 5807 if (sourceItem.nodeType) { 5808 i = targetNodes.length; 5809 while (i--) { 5810 callback.call(targetNodes[i], sourceItem); 5811 } 5812 } 5813 return targetNodes; 5814 }; 5815 var hasClass = function (node, className) { 5816 return node && className && (' ' + node.className + ' ').indexOf(' ' + className + ' ') !== -1; 5817 }; 5818 var wrap$2 = function (elements, wrapper, all) { 5819 var lastParent, newWrapper; 5820 wrapper = DomQuery(wrapper)[0]; 5821 elements.each(function () { 5822 var self = this; 5823 if (!all || lastParent !== self.parentNode) { 5824 lastParent = self.parentNode; 5825 newWrapper = wrapper.cloneNode(false); 5826 self.parentNode.insertBefore(newWrapper, self); 5827 newWrapper.appendChild(self); 5828 } else { 5829 newWrapper.appendChild(self); 5830 } 5831 }); 5832 return elements; 5833 }; 5834 var numericCssMap = Tools.makeMap('fillOpacity fontWeight lineHeight opacity orphans widows zIndex zoom', ' '); 5835 var booleanMap = Tools.makeMap('checked compact declare defer disabled ismap multiple nohref noshade nowrap readonly selected', ' '); 5836 var propFix = { 5837 for: 'htmlFor', 5838 class: 'className', 5839 readonly: 'readOnly' 5840 }; 5841 var cssFix = { float: 'cssFloat' }; 5842 var attrHooks = {}, cssHooks = {}; 5843 var DomQueryConstructor = function (selector, context) { 5844 return new DomQuery.fn.init(selector, context); 5845 }; 5846 var inArray$1 = function (item, array) { 5847 var i; 5848 if (array.indexOf) { 5849 return array.indexOf(item); 5850 } 5851 i = array.length; 5852 while (i--) { 5853 if (array[i] === item) { 5854 return i; 5855 } 5856 } 5857 return -1; 5858 }; 5859 var whiteSpaceRegExp = /^\s*|\s*$/g; 5860 var trim$1 = function (str) { 5861 return str === null || str === undefined ? '' : ('' + str).replace(whiteSpaceRegExp, ''); 5862 }; 5863 var each$g = function (obj, callback) { 5864 var length, key, i, value; 5865 if (obj) { 5866 length = obj.length; 5867 if (length === undefined) { 5868 for (key in obj) { 5869 if (obj.hasOwnProperty(key)) { 5870 value = obj[key]; 5871 if (callback.call(value, key, value) === false) { 5872 break; 5873 } 5874 } 5875 } 5876 } else { 5877 for (i = 0; i < length; i++) { 5878 value = obj[i]; 5879 if (callback.call(value, i, value) === false) { 5880 break; 5881 } 5882 } 5883 } 5884 } 5885 return obj; 5886 }; 5887 var grep$2 = function (array, callback) { 5888 var out = []; 5889 each$g(array, function (i, item) { 5890 if (callback(item, i)) { 5891 out.push(item); 5892 } 5893 }); 5894 return out; 5895 }; 5896 var getElementDocument = function (element) { 5897 if (!element) { 5898 return doc; 5899 } 5900 if (element.nodeType === 9) { 5901 return element; 5902 } 5903 return element.ownerDocument; 5904 }; 5905 DomQueryConstructor.fn = DomQueryConstructor.prototype = { 5906 constructor: DomQueryConstructor, 5907 selector: '', 5908 context: null, 5909 length: 0, 5910 init: function (selector, context) { 5911 var self = this; 5912 var match, node; 5913 if (!selector) { 5914 return self; 5915 } 5916 if (selector.nodeType) { 5917 self.context = self[0] = selector; 5918 self.length = 1; 5919 return self; 5920 } 5921 if (context && context.nodeType) { 5922 self.context = context; 5923 } else { 5924 if (context) { 5925 return DomQuery(selector).attr(context); 5926 } 5927 self.context = context = document; 5928 } 5929 if (isString(selector)) { 5930 self.selector = selector; 5931 if (selector.charAt(0) === '<' && selector.charAt(selector.length - 1) === '>' && selector.length >= 3) { 5932 match = [ 5933 null, 5934 selector, 5935 null 5936 ]; 5937 } else { 5938 match = rquickExpr.exec(selector); 5939 } 5940 if (match) { 5941 if (match[1]) { 5942 node = createFragment$1(selector, getElementDocument(context)).firstChild; 5943 while (node) { 5944 push.call(self, node); 5945 node = node.nextSibling; 5946 } 5947 } else { 5948 node = getElementDocument(context).getElementById(match[2]); 5949 if (!node) { 5950 return self; 5951 } 5952 if (node.id !== match[2]) { 5953 return self.find(selector); 5954 } 5955 self.length = 1; 5956 self[0] = node; 5957 } 5958 } else { 5959 return DomQuery(context).find(selector); 5960 } 5961 } else { 5962 this.add(selector, false); 5963 } 5964 return self; 5965 }, 5966 toArray: function () { 5967 return Tools.toArray(this); 5968 }, 5969 add: function (items, sort) { 5970 var self = this; 5971 var nodes, i; 5972 if (isString(items)) { 5973 return self.add(DomQuery(items)); 5974 } 5975 if (sort !== false) { 5976 nodes = DomQuery.unique(self.toArray().concat(DomQuery.makeArray(items))); 5977 self.length = nodes.length; 5978 for (i = 0; i < nodes.length; i++) { 5979 self[i] = nodes[i]; 5980 } 5981 } else { 5982 push.apply(self, DomQuery.makeArray(items)); 5983 } 5984 return self; 5985 }, 5986 attr: function (name, value) { 5987 var self = this; 5988 var hook; 5989 if (typeof name === 'object') { 5990 each$g(name, function (name, value) { 5991 self.attr(name, value); 5992 }); 5993 } else if (isDefined(value)) { 5994 this.each(function () { 5995 var hook; 5996 if (this.nodeType === 1) { 5997 hook = attrHooks[name]; 5998 if (hook && hook.set) { 5999 hook.set(this, value); 6000 return; 6001 } 6002 if (value === null) { 6003 this.removeAttribute(name, 2); 6004 } else { 6005 this.setAttribute(name, value, 2); 6006 } 6007 } 6008 }); 6009 } else { 6010 if (self[0] && self[0].nodeType === 1) { 6011 hook = attrHooks[name]; 6012 if (hook && hook.get) { 6013 return hook.get(self[0], name); 6014 } 6015 if (booleanMap[name]) { 6016 return self.prop(name) ? name : undefined; 6017 } 6018 value = self[0].getAttribute(name, 2); 6019 if (value === null) { 6020 value = undefined; 6021 } 6022 } 6023 return value; 6024 } 6025 return self; 6026 }, 6027 removeAttr: function (name) { 6028 return this.attr(name, null); 6029 }, 6030 prop: function (name, value) { 6031 var self = this; 6032 name = propFix[name] || name; 6033 if (typeof name === 'object') { 6034 each$g(name, function (name, value) { 6035 self.prop(name, value); 6036 }); 6037 } else if (isDefined(value)) { 6038 this.each(function () { 6039 if (this.nodeType === 1) { 6040 this[name] = value; 6041 } 6042 }); 6043 } else { 6044 if (self[0] && self[0].nodeType && name in self[0]) { 6045 return self[0][name]; 6046 } 6047 return value; 6048 } 6049 return self; 6050 }, 6051 css: function (name, value) { 6052 var self = this; 6053 var elm, hook; 6054 var camel = function (name) { 6055 return name.replace(/-(\D)/g, function (a, b) { 6056 return b.toUpperCase(); 6057 }); 6058 }; 6059 var dashed = function (name) { 6060 return name.replace(/[A-Z]/g, function (a) { 6061 return '-' + a; 6062 }); 6063 }; 6064 if (typeof name === 'object') { 6065 each$g(name, function (name, value) { 6066 self.css(name, value); 6067 }); 6068 } else { 6069 if (isDefined(value)) { 6070 name = camel(name); 6071 if (typeof value === 'number' && !numericCssMap[name]) { 6072 value = value.toString() + 'px'; 6073 } 6074 self.each(function () { 6075 var style = this.style; 6076 hook = cssHooks[name]; 6077 if (hook && hook.set) { 6078 hook.set(this, value); 6079 return; 6080 } 6081 try { 6082 this.style[cssFix[name] || name] = value; 6083 } catch (ex) { 6084 } 6085 if (value === null || value === '') { 6086 if (style.removeProperty) { 6087 style.removeProperty(dashed(name)); 6088 } else { 6089 style.removeAttribute(name); 6090 } 6091 } 6092 }); 6093 } else { 6094 elm = self[0]; 6095 hook = cssHooks[name]; 6096 if (hook && hook.get) { 6097 return hook.get(elm); 6098 } 6099 if (elm.ownerDocument.defaultView) { 6100 try { 6101 return elm.ownerDocument.defaultView.getComputedStyle(elm, null).getPropertyValue(dashed(name)); 6102 } catch (ex) { 6103 return undefined; 6104 } 6105 } else if (elm.currentStyle) { 6106 return elm.currentStyle[camel(name)]; 6107 } else { 6108 return ''; 6109 } 6110 } 6111 } 6112 return self; 6113 }, 6114 remove: function () { 6115 var self = this; 6116 var node, i = this.length; 6117 while (i--) { 6118 node = self[i]; 6119 Event$1.clean(node); 6120 if (node.parentNode) { 6121 node.parentNode.removeChild(node); 6122 } 6123 } 6124 return this; 6125 }, 6126 empty: function () { 6127 var self = this; 6128 var node, i = this.length; 6129 while (i--) { 6130 node = self[i]; 6131 while (node.firstChild) { 6132 node.removeChild(node.firstChild); 6133 } 6134 } 6135 return this; 6136 }, 6137 html: function (value) { 6138 var self = this; 6139 var i; 6140 if (isDefined(value)) { 6141 i = self.length; 6142 try { 6143 while (i--) { 6144 self[i].innerHTML = value; 6145 } 6146 } catch (ex) { 6147 DomQuery(self[i]).empty().append(value); 6148 } 6149 return self; 6150 } 6151 return self[0] ? self[0].innerHTML : ''; 6152 }, 6153 text: function (value) { 6154 var self = this; 6155 var i; 6156 if (isDefined(value)) { 6157 i = self.length; 6158 while (i--) { 6159 if ('innerText' in self[i]) { 6160 self[i].innerText = value; 6161 } else { 6162 self[0].textContent = value; 6163 } 6164 } 6165 return self; 6166 } 6167 return self[0] ? self[0].innerText || self[0].textContent : ''; 6168 }, 6169 append: function () { 6170 return domManipulate(this, arguments, function (node) { 6171 if (this.nodeType === 1 || this.host && this.host.nodeType === 1) { 6172 this.appendChild(node); 6173 } 6174 }); 6175 }, 6176 prepend: function () { 6177 return domManipulate(this, arguments, function (node) { 6178 if (this.nodeType === 1 || this.host && this.host.nodeType === 1) { 6179 this.insertBefore(node, this.firstChild); 6180 } 6181 }, true); 6182 }, 6183 before: function () { 6184 var self = this; 6185 if (self[0] && self[0].parentNode) { 6186 return domManipulate(self, arguments, function (node) { 6187 this.parentNode.insertBefore(node, this); 6188 }); 6189 } 6190 return self; 6191 }, 6192 after: function () { 6193 var self = this; 6194 if (self[0] && self[0].parentNode) { 6195 return domManipulate(self, arguments, function (node) { 6196 this.parentNode.insertBefore(node, this.nextSibling); 6197 }, true); 6198 } 6199 return self; 6200 }, 6201 appendTo: function (val) { 6202 DomQuery(val).append(this); 6203 return this; 6204 }, 6205 prependTo: function (val) { 6206 DomQuery(val).prepend(this); 6207 return this; 6208 }, 6209 replaceWith: function (content) { 6210 return this.before(content).remove(); 6211 }, 6212 wrap: function (content) { 6213 return wrap$2(this, content); 6214 }, 6215 wrapAll: function (content) { 6216 return wrap$2(this, content, true); 6217 }, 6218 wrapInner: function (content) { 6219 this.each(function () { 6220 DomQuery(this).contents().wrapAll(content); 6221 }); 6222 return this; 6223 }, 6224 unwrap: function () { 6225 return this.parent().each(function () { 6226 DomQuery(this).replaceWith(this.childNodes); 6227 }); 6228 }, 6229 clone: function () { 6230 var result = []; 6231 this.each(function () { 6232 result.push(this.cloneNode(true)); 6233 }); 6234 return DomQuery(result); 6235 }, 6236 addClass: function (className) { 6237 return this.toggleClass(className, true); 6238 }, 6239 removeClass: function (className) { 6240 return this.toggleClass(className, false); 6241 }, 6242 toggleClass: function (className, state) { 6243 var self = this; 6244 if (typeof className !== 'string') { 6245 return self; 6246 } 6247 if (className.indexOf(' ') !== -1) { 6248 each$g(className.split(' '), function () { 6249 self.toggleClass(this, state); 6250 }); 6251 } else { 6252 self.each(function (index, node) { 6253 var classState = hasClass(node, className); 6254 if (classState !== state) { 6255 var existingClassName = node.className; 6256 if (classState) { 6257 node.className = trim$1((' ' + existingClassName + ' ').replace(' ' + className + ' ', ' ')); 6258 } else { 6259 node.className += existingClassName ? ' ' + className : className; 6260 } 6261 } 6262 }); 6263 } 6264 return self; 6265 }, 6266 hasClass: function (className) { 6267 return hasClass(this[0], className); 6268 }, 6269 each: function (callback) { 6270 return each$g(this, callback); 6271 }, 6272 on: function (name, callback) { 6273 return this.each(function () { 6274 Event$1.bind(this, name, callback); 6275 }); 6276 }, 6277 off: function (name, callback) { 6278 return this.each(function () { 6279 Event$1.unbind(this, name, callback); 6280 }); 6281 }, 6282 trigger: function (name) { 6283 return this.each(function () { 6284 if (typeof name === 'object') { 6285 Event$1.fire(this, name.type, name); 6286 } else { 6287 Event$1.fire(this, name); 6288 } 6289 }); 6290 }, 6291 show: function () { 6292 return this.css('display', ''); 6293 }, 6294 hide: function () { 6295 return this.css('display', 'none'); 6296 }, 6297 slice: function () { 6298 return DomQuery(slice.apply(this, arguments)); 6299 }, 6300 eq: function (index) { 6301 return index === -1 ? this.slice(index) : this.slice(index, +index + 1); 6302 }, 6303 first: function () { 6304 return this.eq(0); 6305 }, 6306 last: function () { 6307 return this.eq(-1); 6308 }, 6309 find: function (selector) { 6310 var i, l; 6311 var ret = []; 6312 for (i = 0, l = this.length; i < l; i++) { 6313 DomQuery.find(selector, this[i], ret); 6314 } 6315 return DomQuery(ret); 6316 }, 6317 filter: function (selector) { 6318 if (typeof selector === 'function') { 6319 return DomQuery(grep$2(this.toArray(), function (item, i) { 6320 return selector(i, item); 6321 })); 6322 } 6323 return DomQuery(DomQuery.filter(selector, this.toArray())); 6324 }, 6325 closest: function (selector) { 6326 var result = []; 6327 if (selector instanceof DomQuery) { 6328 selector = selector[0]; 6329 } 6330 this.each(function (i, node) { 6331 while (node) { 6332 if (typeof selector === 'string' && DomQuery(node).is(selector)) { 6333 result.push(node); 6334 break; 6335 } else if (node === selector) { 6336 result.push(node); 6337 break; 6338 } 6339 node = node.parentNode; 6340 } 6341 }); 6342 return DomQuery(result); 6343 }, 6344 offset: function (offset) { 6345 var elm, doc, docElm; 6346 var x = 0, y = 0, pos; 6347 if (!offset) { 6348 elm = this[0]; 6349 if (elm) { 6350 doc = elm.ownerDocument; 6351 docElm = doc.documentElement; 6352 if (elm.getBoundingClientRect) { 6353 pos = elm.getBoundingClientRect(); 6354 x = pos.left + (docElm.scrollLeft || doc.body.scrollLeft) - docElm.clientLeft; 6355 y = pos.top + (docElm.scrollTop || doc.body.scrollTop) - docElm.clientTop; 6356 } 6357 } 6358 return { 6359 left: x, 6360 top: y 6361 }; 6362 } 6363 return this.css(offset); 6364 }, 6365 push: push, 6366 sort: Array.prototype.sort, 6367 splice: Array.prototype.splice 6368 }; 6369 Tools.extend(DomQueryConstructor, { 6370 extend: Tools.extend, 6371 makeArray: function (object) { 6372 if (isWindow(object) || object.nodeType) { 6373 return [object]; 6374 } 6375 return Tools.toArray(object); 6376 }, 6377 inArray: inArray$1, 6378 isArray: Tools.isArray, 6379 each: each$g, 6380 trim: trim$1, 6381 grep: grep$2, 6382 find: Sizzle, 6383 expr: Sizzle.selectors, 6384 unique: Sizzle.uniqueSort, 6385 text: Sizzle.getText, 6386 contains: Sizzle.contains, 6387 filter: function (expr, elems, not) { 6388 var i = elems.length; 6389 if (not) { 6390 expr = ':not(' + expr + ')'; 6391 } 6392 while (i--) { 6393 if (elems[i].nodeType !== 1) { 6394 elems.splice(i, 1); 6395 } 6396 } 6397 if (elems.length === 1) { 6398 elems = DomQuery.find.matchesSelector(elems[0], expr) ? [elems[0]] : []; 6399 } else { 6400 elems = DomQuery.find.matches(expr, elems); 6401 } 6402 return elems; 6403 } 6404 }); 6405 var dir = function (el, prop, until) { 6406 var matched = []; 6407 var cur = el[prop]; 6408 if (typeof until !== 'string' && until instanceof DomQuery) { 6409 until = until[0]; 6410 } 6411 while (cur && cur.nodeType !== 9) { 6412 if (until !== undefined) { 6413 if (cur === until) { 6414 break; 6415 } 6416 if (typeof until === 'string' && DomQuery(cur).is(until)) { 6417 break; 6418 } 6419 } 6420 if (cur.nodeType === 1) { 6421 matched.push(cur); 6422 } 6423 cur = cur[prop]; 6424 } 6425 return matched; 6426 }; 6427 var sibling$1 = function (node, siblingName, nodeType, until) { 6428 var result = []; 6429 if (until instanceof DomQuery) { 6430 until = until[0]; 6431 } 6432 for (; node; node = node[siblingName]) { 6433 if (nodeType && node.nodeType !== nodeType) { 6434 continue; 6435 } 6436 if (until !== undefined) { 6437 if (node === until) { 6438 break; 6439 } 6440 if (typeof until === 'string' && DomQuery(node).is(until)) { 6441 break; 6442 } 6443 } 6444 result.push(node); 6445 } 6446 return result; 6447 }; 6448 var firstSibling = function (node, siblingName, nodeType) { 6449 for (node = node[siblingName]; node; node = node[siblingName]) { 6450 if (node.nodeType === nodeType) { 6451 return node; 6452 } 6453 } 6454 return null; 6455 }; 6456 each$g({ 6457 parent: function (node) { 6458 var parent = node.parentNode; 6459 return parent && parent.nodeType !== 11 ? parent : null; 6460 }, 6461 parents: function (node) { 6462 return dir(node, 'parentNode'); 6463 }, 6464 next: function (node) { 6465 return firstSibling(node, 'nextSibling', 1); 6466 }, 6467 prev: function (node) { 6468 return firstSibling(node, 'previousSibling', 1); 6469 }, 6470 children: function (node) { 6471 return sibling$1(node.firstChild, 'nextSibling', 1); 6472 }, 6473 contents: function (node) { 6474 return Tools.toArray((node.nodeName === 'iframe' ? node.contentDocument || node.contentWindow.document : node).childNodes); 6475 } 6476 }, function (name, fn) { 6477 DomQueryConstructor.fn[name] = function (selector) { 6478 var self = this; 6479 var result = []; 6480 self.each(function () { 6481 var nodes = fn.call(result, this, selector, result); 6482 if (nodes) { 6483 if (DomQuery.isArray(nodes)) { 6484 result.push.apply(result, nodes); 6485 } else { 6486 result.push(nodes); 6487 } 6488 } 6489 }); 6490 if (this.length > 1) { 6491 if (!skipUniques[name]) { 6492 result = DomQuery.unique(result); 6493 } 6494 if (name.indexOf('parents') === 0) { 6495 result = result.reverse(); 6496 } 6497 } 6498 var wrappedResult = DomQuery(result); 6499 if (selector) { 6500 return wrappedResult.filter(selector); 6501 } 6502 return wrappedResult; 6503 }; 6504 }); 6505 each$g({ 6506 parentsUntil: function (node, until) { 6507 return dir(node, 'parentNode', until); 6508 }, 6509 nextUntil: function (node, until) { 6510 return sibling$1(node, 'nextSibling', 1, until).slice(1); 6511 }, 6512 prevUntil: function (node, until) { 6513 return sibling$1(node, 'previousSibling', 1, until).slice(1); 6514 } 6515 }, function (name, fn) { 6516 DomQueryConstructor.fn[name] = function (selector, filter) { 6517 var self = this; 6518 var result = []; 6519 self.each(function () { 6520 var nodes = fn.call(result, this, selector, result); 6521 if (nodes) { 6522 if (DomQuery.isArray(nodes)) { 6523 result.push.apply(result, nodes); 6524 } else { 6525 result.push(nodes); 6526 } 6527 } 6528 }); 6529 if (this.length > 1) { 6530 result = DomQuery.unique(result); 6531 if (name.indexOf('parents') === 0 || name === 'prevUntil') { 6532 result = result.reverse(); 6533 } 6534 } 6535 var wrappedResult = DomQuery(result); 6536 if (filter) { 6537 return wrappedResult.filter(filter); 6538 } 6539 return wrappedResult; 6540 }; 6541 }); 6542 DomQueryConstructor.fn.is = function (selector) { 6543 return !!selector && this.filter(selector).length > 0; 6544 }; 6545 DomQueryConstructor.fn.init.prototype = DomQueryConstructor.fn; 6546 DomQueryConstructor.overrideDefaults = function (callback) { 6547 var defaults; 6548 var sub = function (selector, context) { 6549 defaults = defaults || callback(); 6550 if (arguments.length === 0) { 6551 selector = defaults.element; 6552 } 6553 if (!context) { 6554 context = defaults.context; 6555 } 6556 return new sub.fn.init(selector, context); 6557 }; 6558 DomQuery.extend(sub, this); 6559 return sub; 6560 }; 6561 DomQueryConstructor.attrHooks = attrHooks; 6562 DomQueryConstructor.cssHooks = cssHooks; 6563 var DomQuery = DomQueryConstructor; 6564 6565 var each$f = Tools.each; 6566 var grep$1 = Tools.grep; 6567 var isIE = Env.ie; 6568 var simpleSelectorRe = /^([a-z0-9],?)+$/i; 6569 var setupAttrHooks = function (styles, settings, getContext) { 6570 var keepValues = settings.keep_values; 6571 var keepUrlHook = { 6572 set: function ($elm, value, name) { 6573 if (settings.url_converter && value !== null) { 6574 value = settings.url_converter.call(settings.url_converter_scope || getContext(), value, name, $elm[0]); 6575 } 6576 $elm.attr('data-mce-' + name, value).attr(name, value); 6577 }, 6578 get: function ($elm, name) { 6579 return $elm.attr('data-mce-' + name) || $elm.attr(name); 6580 } 6581 }; 6582 var attrHooks = { 6583 style: { 6584 set: function ($elm, value) { 6585 if (value !== null && typeof value === 'object') { 6586 $elm.css(value); 6587 return; 6588 } 6589 if (keepValues) { 6590 $elm.attr('data-mce-style', value); 6591 } 6592 if (value !== null && typeof value === 'string') { 6593 $elm.removeAttr('style'); 6594 $elm.css(styles.parse(value)); 6595 } else { 6596 $elm.attr('style', value); 6597 } 6598 }, 6599 get: function ($elm) { 6600 var value = $elm.attr('data-mce-style') || $elm.attr('style'); 6601 value = styles.serialize(styles.parse(value), $elm[0].nodeName); 6602 return value; 6603 } 6604 } 6605 }; 6606 if (keepValues) { 6607 attrHooks.href = attrHooks.src = keepUrlHook; 6608 } 6609 return attrHooks; 6610 }; 6611 var updateInternalStyleAttr = function (styles, $elm) { 6612 var rawValue = $elm.attr('style'); 6613 var value = styles.serialize(styles.parse(rawValue), $elm[0].nodeName); 6614 if (!value) { 6615 value = null; 6616 } 6617 $elm.attr('data-mce-style', value); 6618 }; 6619 var findNodeIndex = function (node, normalized) { 6620 var idx = 0, lastNodeType, nodeType; 6621 if (node) { 6622 for (lastNodeType = node.nodeType, node = node.previousSibling; node; node = node.previousSibling) { 6623 nodeType = node.nodeType; 6624 if (normalized && nodeType === 3) { 6625 if (nodeType === lastNodeType || !node.nodeValue.length) { 6626 continue; 6627 } 6628 } 6629 idx++; 6630 lastNodeType = nodeType; 6631 } 6632 } 6633 return idx; 6634 }; 6635 var DOMUtils = function (doc, settings) { 6636 if (settings === void 0) { 6637 settings = {}; 6638 } 6639 var addedStyles = {}; 6640 var win = window; 6641 var files = {}; 6642 var counter = 0; 6643 var stdMode = true; 6644 var boxModel = true; 6645 var styleSheetLoader = instance.forElement(SugarElement.fromDom(doc), { 6646 contentCssCors: settings.contentCssCors, 6647 referrerPolicy: settings.referrerPolicy 6648 }); 6649 var boundEvents = []; 6650 var schema = settings.schema ? settings.schema : Schema({}); 6651 var styles = Styles({ 6652 url_converter: settings.url_converter, 6653 url_converter_scope: settings.url_converter_scope 6654 }, settings.schema); 6655 var events = settings.ownEvents ? new EventUtils() : EventUtils.Event; 6656 var blockElementsMap = schema.getBlockElements(); 6657 var $ = DomQuery.overrideDefaults(function () { 6658 return { 6659 context: doc, 6660 element: self.getRoot() 6661 }; 6662 }); 6663 var isBlock = function (node) { 6664 if (typeof node === 'string') { 6665 return !!blockElementsMap[node]; 6666 } else if (node) { 6667 var type = node.nodeType; 6668 if (type) { 6669 return !!(type === 1 && blockElementsMap[node.nodeName]); 6670 } 6671 } 6672 return false; 6673 }; 6674 var get = function (elm) { 6675 return elm && doc && isString$1(elm) ? doc.getElementById(elm) : elm; 6676 }; 6677 var $$ = function (elm) { 6678 return $(typeof elm === 'string' ? get(elm) : elm); 6679 }; 6680 var getAttrib = function (elm, name, defaultVal) { 6681 var hook, value; 6682 var $elm = $$(elm); 6683 if ($elm.length) { 6684 hook = attrHooks[name]; 6685 if (hook && hook.get) { 6686 value = hook.get($elm, name); 6687 } else { 6688 value = $elm.attr(name); 6689 } 6690 } 6691 if (typeof value === 'undefined') { 6692 value = defaultVal || ''; 6693 } 6694 return value; 6695 }; 6696 var getAttribs = function (elm) { 6697 var node = get(elm); 6698 if (!node) { 6699 return []; 6700 } 6701 return node.attributes; 6702 }; 6703 var setAttrib = function (elm, name, value) { 6704 if (value === '') { 6705 value = null; 6706 } 6707 var $elm = $$(elm); 6708 var originalValue = $elm.attr(name); 6709 if (!$elm.length) { 6710 return; 6711 } 6712 var hook = attrHooks[name]; 6713 if (hook && hook.set) { 6714 hook.set($elm, value, name); 6715 } else { 6716 $elm.attr(name, value); 6717 } 6718 if (originalValue !== value && settings.onSetAttrib) { 6719 settings.onSetAttrib({ 6720 attrElm: $elm, 6721 attrName: name, 6722 attrValue: value 6723 }); 6724 } 6725 }; 6726 var clone = function (node, deep) { 6727 if (!isIE || node.nodeType !== 1 || deep) { 6728 return node.cloneNode(deep); 6729 } else { 6730 var clone_1 = doc.createElement(node.nodeName); 6731 each$f(getAttribs(node), function (attr) { 6732 setAttrib(clone_1, attr.nodeName, getAttrib(node, attr.nodeName)); 6733 }); 6734 return clone_1; 6735 } 6736 }; 6737 var getRoot = function () { 6738 return settings.root_element || doc.body; 6739 }; 6740 var getViewPort = function (argWin) { 6741 var vp = getBounds(argWin); 6742 return { 6743 x: vp.x, 6744 y: vp.y, 6745 w: vp.width, 6746 h: vp.height 6747 }; 6748 }; 6749 var getPos$1 = function (elm, rootElm) { 6750 return getPos(doc.body, get(elm), rootElm); 6751 }; 6752 var setStyle = function (elm, name, value) { 6753 var $elm = isString$1(name) ? $$(elm).css(name, value) : $$(elm).css(name); 6754 if (settings.update_styles) { 6755 updateInternalStyleAttr(styles, $elm); 6756 } 6757 }; 6758 var setStyles = function (elm, stylesArg) { 6759 var $elm = $$(elm).css(stylesArg); 6760 if (settings.update_styles) { 6761 updateInternalStyleAttr(styles, $elm); 6762 } 6763 }; 6764 var getStyle = function (elm, name, computed) { 6765 var $elm = $$(elm); 6766 if (computed) { 6767 return $elm.css(name); 6768 } 6769 name = name.replace(/-(\D)/g, function (a, b) { 6770 return b.toUpperCase(); 6771 }); 6772 if (name === 'float') { 6773 name = Env.browser.isIE() ? 'styleFloat' : 'cssFloat'; 6774 } 6775 return $elm[0] && $elm[0].style ? $elm[0].style[name] : undefined; 6776 }; 6777 var getSize = function (elm) { 6778 var w, h; 6779 elm = get(elm); 6780 w = getStyle(elm, 'width'); 6781 h = getStyle(elm, 'height'); 6782 if (w.indexOf('px') === -1) { 6783 w = 0; 6784 } 6785 if (h.indexOf('px') === -1) { 6786 h = 0; 6787 } 6788 return { 6789 w: parseInt(w, 10) || elm.offsetWidth || elm.clientWidth, 6790 h: parseInt(h, 10) || elm.offsetHeight || elm.clientHeight 6791 }; 6792 }; 6793 var getRect = function (elm) { 6794 elm = get(elm); 6795 var pos = getPos$1(elm); 6796 var size = getSize(elm); 6797 return { 6798 x: pos.x, 6799 y: pos.y, 6800 w: size.w, 6801 h: size.h 6802 }; 6803 }; 6804 var is = function (elm, selector) { 6805 var i; 6806 if (!elm) { 6807 return false; 6808 } 6809 if (!Array.isArray(elm)) { 6810 if (selector === '*') { 6811 return elm.nodeType === 1; 6812 } 6813 if (simpleSelectorRe.test(selector)) { 6814 var selectors = selector.toLowerCase().split(/,/); 6815 var elmName = elm.nodeName.toLowerCase(); 6816 for (i = selectors.length - 1; i >= 0; i--) { 6817 if (selectors[i] === elmName) { 6818 return true; 6819 } 6820 } 6821 return false; 6822 } 6823 if (elm.nodeType && elm.nodeType !== 1) { 6824 return false; 6825 } 6826 } 6827 var elms = !Array.isArray(elm) ? [elm] : elm; 6828 return Sizzle(selector, elms[0].ownerDocument || elms[0], null, elms).length > 0; 6829 }; 6830 var getParents = function (elm, selector, root, collect) { 6831 var result = []; 6832 var selectorVal; 6833 var node = get(elm); 6834 collect = collect === undefined; 6835 root = root || (getRoot().nodeName !== 'BODY' ? getRoot().parentNode : null); 6836 if (Tools.is(selector, 'string')) { 6837 selectorVal = selector; 6838 if (selector === '*') { 6839 selector = function (node) { 6840 return node.nodeType === 1; 6841 }; 6842 } else { 6843 selector = function (node) { 6844 return is(node, selectorVal); 6845 }; 6846 } 6847 } 6848 while (node) { 6849 if (node === root || isNullable(node.nodeType) || isDocument$1(node) || isDocumentFragment(node)) { 6850 break; 6851 } 6852 if (!selector || typeof selector === 'function' && selector(node)) { 6853 if (collect) { 6854 result.push(node); 6855 } else { 6856 return [node]; 6857 } 6858 } 6859 node = node.parentNode; 6860 } 6861 return collect ? result : null; 6862 }; 6863 var getParent = function (node, selector, root) { 6864 var parents = getParents(node, selector, root, false); 6865 return parents && parents.length > 0 ? parents[0] : null; 6866 }; 6867 var _findSib = function (node, selector, name) { 6868 var func = selector; 6869 if (node) { 6870 if (typeof selector === 'string') { 6871 func = function (node) { 6872 return is(node, selector); 6873 }; 6874 } 6875 for (node = node[name]; node; node = node[name]) { 6876 if (typeof func === 'function' && func(node)) { 6877 return node; 6878 } 6879 } 6880 } 6881 return null; 6882 }; 6883 var getNext = function (node, selector) { 6884 return _findSib(node, selector, 'nextSibling'); 6885 }; 6886 var getPrev = function (node, selector) { 6887 return _findSib(node, selector, 'previousSibling'); 6888 }; 6889 var select = function (selector, scope) { 6890 return Sizzle(selector, get(scope) || settings.root_element || doc, []); 6891 }; 6892 var run = function (elm, func, scope) { 6893 var result; 6894 var node = typeof elm === 'string' ? get(elm) : elm; 6895 if (!node) { 6896 return false; 6897 } 6898 if (Tools.isArray(node) && (node.length || node.length === 0)) { 6899 result = []; 6900 each$f(node, function (elm, i) { 6901 if (elm) { 6902 result.push(func.call(scope, typeof elm === 'string' ? get(elm) : elm, i)); 6903 } 6904 }); 6905 return result; 6906 } 6907 var context = scope ? scope : this; 6908 return func.call(context, node); 6909 }; 6910 var setAttribs = function (elm, attrs) { 6911 $$(elm).each(function (i, node) { 6912 each$f(attrs, function (value, name) { 6913 setAttrib(node, name, value); 6914 }); 6915 }); 6916 }; 6917 var setHTML = function (elm, html) { 6918 var $elm = $$(elm); 6919 if (isIE) { 6920 $elm.each(function (i, target) { 6921 if (target.canHaveHTML === false) { 6922 return; 6923 } 6924 while (target.firstChild) { 6925 target.removeChild(target.firstChild); 6926 } 6927 try { 6928 target.innerHTML = '<br>' + html; 6929 target.removeChild(target.firstChild); 6930 } catch (ex) { 6931 DomQuery('<div></div>').html('<br>' + html).contents().slice(1).appendTo(target); 6932 } 6933 return html; 6934 }); 6935 } else { 6936 $elm.html(html); 6937 } 6938 }; 6939 var add = function (parentElm, name, attrs, html, create) { 6940 return run(parentElm, function (parentElm) { 6941 var newElm = typeof name === 'string' ? doc.createElement(name) : name; 6942 setAttribs(newElm, attrs); 6943 if (html) { 6944 if (typeof html !== 'string' && html.nodeType) { 6945 newElm.appendChild(html); 6946 } else if (typeof html === 'string') { 6947 setHTML(newElm, html); 6948 } 6949 } 6950 return !create ? parentElm.appendChild(newElm) : newElm; 6951 }); 6952 }; 6953 var create = function (name, attrs, html) { 6954 return add(doc.createElement(name), name, attrs, html, true); 6955 }; 6956 var decode = Entities.decode; 6957 var encode = Entities.encodeAllRaw; 6958 var createHTML = function (name, attrs, html) { 6959 var outHtml = '', key; 6960 outHtml += '<' + name; 6961 for (key in attrs) { 6962 if (hasNonNullableKey(attrs, key)) { 6963 outHtml += ' ' + key + '="' + encode(attrs[key]) + '"'; 6964 } 6965 } 6966 if (typeof html !== 'undefined') { 6967 return outHtml + '>' + html + '</' + name + '>'; 6968 } 6969 return outHtml + ' />'; 6970 }; 6971 var createFragment = function (html) { 6972 var node; 6973 var container = doc.createElement('div'); 6974 var frag = doc.createDocumentFragment(); 6975 frag.appendChild(container); 6976 if (html) { 6977 container.innerHTML = html; 6978 } 6979 while (node = container.firstChild) { 6980 frag.appendChild(node); 6981 } 6982 frag.removeChild(container); 6983 return frag; 6984 }; 6985 var remove = function (node, keepChildren) { 6986 var $node = $$(node); 6987 if (keepChildren) { 6988 $node.each(function () { 6989 var child; 6990 while (child = this.firstChild) { 6991 if (child.nodeType === 3 && child.data.length === 0) { 6992 this.removeChild(child); 6993 } else { 6994 this.parentNode.insertBefore(child, this); 6995 } 6996 } 6997 }).remove(); 6998 } else { 6999 $node.remove(); 7000 } 7001 return $node.length > 1 ? $node.toArray() : $node[0]; 7002 }; 7003 var removeAllAttribs = function (e) { 7004 return run(e, function (e) { 7005 var i; 7006 var attrs = e.attributes; 7007 for (i = attrs.length - 1; i >= 0; i--) { 7008 e.removeAttributeNode(attrs.item(i)); 7009 } 7010 }); 7011 }; 7012 var parseStyle = function (cssText) { 7013 return styles.parse(cssText); 7014 }; 7015 var serializeStyle = function (stylesArg, name) { 7016 return styles.serialize(stylesArg, name); 7017 }; 7018 var addStyle = function (cssText) { 7019 var head, styleElm; 7020 if (self !== DOMUtils.DOM && doc === document) { 7021 if (addedStyles[cssText]) { 7022 return; 7023 } 7024 addedStyles[cssText] = true; 7025 } 7026 styleElm = doc.getElementById('mceDefaultStyles'); 7027 if (!styleElm) { 7028 styleElm = doc.createElement('style'); 7029 styleElm.id = 'mceDefaultStyles'; 7030 styleElm.type = 'text/css'; 7031 head = doc.getElementsByTagName('head')[0]; 7032 if (head.firstChild) { 7033 head.insertBefore(styleElm, head.firstChild); 7034 } else { 7035 head.appendChild(styleElm); 7036 } 7037 } 7038 if (styleElm.styleSheet) { 7039 styleElm.styleSheet.cssText += cssText; 7040 } else { 7041 styleElm.appendChild(doc.createTextNode(cssText)); 7042 } 7043 }; 7044 var loadCSS = function (urls) { 7045 if (!urls) { 7046 urls = ''; 7047 } 7048 each$k(urls.split(','), function (url) { 7049 files[url] = true; 7050 styleSheetLoader.load(url, noop); 7051 }); 7052 }; 7053 var toggleClass = function (elm, cls, state) { 7054 $$(elm).toggleClass(cls, state).each(function () { 7055 if (this.className === '') { 7056 DomQuery(this).attr('class', null); 7057 } 7058 }); 7059 }; 7060 var addClass = function (elm, cls) { 7061 $$(elm).addClass(cls); 7062 }; 7063 var removeClass = function (elm, cls) { 7064 toggleClass(elm, cls, false); 7065 }; 7066 var hasClass = function (elm, cls) { 7067 return $$(elm).hasClass(cls); 7068 }; 7069 var show = function (elm) { 7070 $$(elm).show(); 7071 }; 7072 var hide = function (elm) { 7073 $$(elm).hide(); 7074 }; 7075 var isHidden = function (elm) { 7076 return $$(elm).css('display') === 'none'; 7077 }; 7078 var uniqueId = function (prefix) { 7079 return (!prefix ? 'mce_' : prefix) + counter++; 7080 }; 7081 var getOuterHTML = function (elm) { 7082 var node = typeof elm === 'string' ? get(elm) : elm; 7083 return isElement$5(node) ? node.outerHTML : DomQuery('<div></div>').append(DomQuery(node).clone()).html(); 7084 }; 7085 var setOuterHTML = function (elm, html) { 7086 $$(elm).each(function () { 7087 try { 7088 if ('outerHTML' in this) { 7089 this.outerHTML = html; 7090 return; 7091 } 7092 } catch (ex) { 7093 } 7094 remove(DomQuery(this).html(html), true); 7095 }); 7096 }; 7097 var insertAfter = function (node, reference) { 7098 var referenceNode = get(reference); 7099 return run(node, function (node) { 7100 var parent = referenceNode.parentNode; 7101 var nextSibling = referenceNode.nextSibling; 7102 if (nextSibling) { 7103 parent.insertBefore(node, nextSibling); 7104 } else { 7105 parent.appendChild(node); 7106 } 7107 return node; 7108 }); 7109 }; 7110 var replace = function (newElm, oldElm, keepChildren) { 7111 return run(oldElm, function (oldElm) { 7112 if (Tools.is(oldElm, 'array')) { 7113 newElm = newElm.cloneNode(true); 7114 } 7115 if (keepChildren) { 7116 each$f(grep$1(oldElm.childNodes), function (node) { 7117 newElm.appendChild(node); 7118 }); 7119 } 7120 return oldElm.parentNode.replaceChild(newElm, oldElm); 7121 }); 7122 }; 7123 var rename = function (elm, name) { 7124 var newElm; 7125 if (elm.nodeName !== name.toUpperCase()) { 7126 newElm = create(name); 7127 each$f(getAttribs(elm), function (attrNode) { 7128 setAttrib(newElm, attrNode.nodeName, getAttrib(elm, attrNode.nodeName)); 7129 }); 7130 replace(newElm, elm, true); 7131 } 7132 return newElm || elm; 7133 }; 7134 var findCommonAncestor = function (a, b) { 7135 var ps = a, pe; 7136 while (ps) { 7137 pe = b; 7138 while (pe && ps !== pe) { 7139 pe = pe.parentNode; 7140 } 7141 if (ps === pe) { 7142 break; 7143 } 7144 ps = ps.parentNode; 7145 } 7146 if (!ps && a.ownerDocument) { 7147 return a.ownerDocument.documentElement; 7148 } 7149 return ps; 7150 }; 7151 var toHex = function (rgbVal) { 7152 return styles.toHex(Tools.trim(rgbVal)); 7153 }; 7154 var isNonEmptyElement = function (node) { 7155 if (isElement$5(node)) { 7156 var isNamedAnchor = node.nodeName.toLowerCase() === 'a' && !getAttrib(node, 'href') && getAttrib(node, 'id'); 7157 if (getAttrib(node, 'name') || getAttrib(node, 'data-mce-bookmark') || isNamedAnchor) { 7158 return true; 7159 } 7160 } 7161 return false; 7162 }; 7163 var isEmpty = function (node, elements) { 7164 var type, name, brCount = 0; 7165 if (isNonEmptyElement(node)) { 7166 return false; 7167 } 7168 node = node.firstChild; 7169 if (node) { 7170 var walker = new DomTreeWalker(node, node.parentNode); 7171 var whitespace = schema ? schema.getWhiteSpaceElements() : {}; 7172 elements = elements || (schema ? schema.getNonEmptyElements() : null); 7173 do { 7174 type = node.nodeType; 7175 if (isElement$5(node)) { 7176 var bogusVal = node.getAttribute('data-mce-bogus'); 7177 if (bogusVal) { 7178 node = walker.next(bogusVal === 'all'); 7179 continue; 7180 } 7181 name = node.nodeName.toLowerCase(); 7182 if (elements && elements[name]) { 7183 if (name === 'br') { 7184 brCount++; 7185 node = walker.next(); 7186 continue; 7187 } 7188 return false; 7189 } 7190 if (isNonEmptyElement(node)) { 7191 return false; 7192 } 7193 } 7194 if (type === 8) { 7195 return false; 7196 } 7197 if (type === 3 && !isWhitespaceText(node.nodeValue)) { 7198 return false; 7199 } 7200 if (type === 3 && node.parentNode && whitespace[node.parentNode.nodeName] && isWhitespaceText(node.nodeValue)) { 7201 return false; 7202 } 7203 node = walker.next(); 7204 } while (node); 7205 } 7206 return brCount <= 1; 7207 }; 7208 var createRng = function () { 7209 return doc.createRange(); 7210 }; 7211 var split = function (parentElm, splitElm, replacementElm) { 7212 var range = createRng(); 7213 var beforeFragment; 7214 var afterFragment; 7215 var parentNode; 7216 if (parentElm && splitElm) { 7217 range.setStart(parentElm.parentNode, findNodeIndex(parentElm)); 7218 range.setEnd(splitElm.parentNode, findNodeIndex(splitElm)); 7219 beforeFragment = range.extractContents(); 7220 range = createRng(); 7221 range.setStart(splitElm.parentNode, findNodeIndex(splitElm) + 1); 7222 range.setEnd(parentElm.parentNode, findNodeIndex(parentElm) + 1); 7223 afterFragment = range.extractContents(); 7224 parentNode = parentElm.parentNode; 7225 parentNode.insertBefore(trimNode(self, beforeFragment), parentElm); 7226 if (replacementElm) { 7227 parentNode.insertBefore(replacementElm, parentElm); 7228 } else { 7229 parentNode.insertBefore(splitElm, parentElm); 7230 } 7231 parentNode.insertBefore(trimNode(self, afterFragment), parentElm); 7232 remove(parentElm); 7233 return replacementElm || splitElm; 7234 } 7235 }; 7236 var bind = function (target, name, func, scope) { 7237 if (Tools.isArray(target)) { 7238 var i = target.length; 7239 var rv = []; 7240 while (i--) { 7241 rv[i] = bind(target[i], name, func, scope); 7242 } 7243 return rv; 7244 } 7245 if (settings.collect && (target === doc || target === win)) { 7246 boundEvents.push([ 7247 target, 7248 name, 7249 func, 7250 scope 7251 ]); 7252 } 7253 var output = events.bind(target, name, func, scope || self); 7254 return output; 7255 }; 7256 var unbind = function (target, name, func) { 7257 if (Tools.isArray(target)) { 7258 var i = target.length; 7259 var rv = []; 7260 while (i--) { 7261 rv[i] = unbind(target[i], name, func); 7262 } 7263 return rv; 7264 } else { 7265 if (boundEvents.length > 0 && (target === doc || target === win)) { 7266 var i = boundEvents.length; 7267 while (i--) { 7268 var item = boundEvents[i]; 7269 if (target === item[0] && (!name || name === item[1]) && (!func || func === item[2])) { 7270 events.unbind(item[0], item[1], item[2]); 7271 } 7272 } 7273 } 7274 return events.unbind(target, name, func); 7275 } 7276 }; 7277 var fire = function (target, name, evt) { 7278 return events.fire(target, name, evt); 7279 }; 7280 var getContentEditable = function (node) { 7281 if (node && isElement$5(node)) { 7282 var contentEditable = node.getAttribute('data-mce-contenteditable'); 7283 if (contentEditable && contentEditable !== 'inherit') { 7284 return contentEditable; 7285 } 7286 return node.contentEditable !== 'inherit' ? node.contentEditable : null; 7287 } else { 7288 return null; 7289 } 7290 }; 7291 var getContentEditableParent = function (node) { 7292 var root = getRoot(); 7293 var state = null; 7294 for (; node && node !== root; node = node.parentNode) { 7295 state = getContentEditable(node); 7296 if (state !== null) { 7297 break; 7298 } 7299 } 7300 return state; 7301 }; 7302 var destroy = function () { 7303 if (boundEvents.length > 0) { 7304 var i = boundEvents.length; 7305 while (i--) { 7306 var item = boundEvents[i]; 7307 events.unbind(item[0], item[1], item[2]); 7308 } 7309 } 7310 each$j(files, function (_, url) { 7311 styleSheetLoader.unload(url); 7312 delete files[url]; 7313 }); 7314 if (Sizzle.setDocument) { 7315 Sizzle.setDocument(); 7316 } 7317 }; 7318 var isChildOf = function (node, parent) { 7319 if (!isIE) { 7320 return node === parent || parent.contains(node); 7321 } else { 7322 while (node) { 7323 if (parent === node) { 7324 return true; 7325 } 7326 node = node.parentNode; 7327 } 7328 return false; 7329 } 7330 }; 7331 var dumpRng = function (r) { 7332 return 'startContainer: ' + r.startContainer.nodeName + ', startOffset: ' + r.startOffset + ', endContainer: ' + r.endContainer.nodeName + ', endOffset: ' + r.endOffset; 7333 }; 7334 var self = { 7335 doc: doc, 7336 settings: settings, 7337 win: win, 7338 files: files, 7339 stdMode: stdMode, 7340 boxModel: boxModel, 7341 styleSheetLoader: styleSheetLoader, 7342 boundEvents: boundEvents, 7343 styles: styles, 7344 schema: schema, 7345 events: events, 7346 isBlock: isBlock, 7347 $: $, 7348 $$: $$, 7349 root: null, 7350 clone: clone, 7351 getRoot: getRoot, 7352 getViewPort: getViewPort, 7353 getRect: getRect, 7354 getSize: getSize, 7355 getParent: getParent, 7356 getParents: getParents, 7357 get: get, 7358 getNext: getNext, 7359 getPrev: getPrev, 7360 select: select, 7361 is: is, 7362 add: add, 7363 create: create, 7364 createHTML: createHTML, 7365 createFragment: createFragment, 7366 remove: remove, 7367 setStyle: setStyle, 7368 getStyle: getStyle, 7369 setStyles: setStyles, 7370 removeAllAttribs: removeAllAttribs, 7371 setAttrib: setAttrib, 7372 setAttribs: setAttribs, 7373 getAttrib: getAttrib, 7374 getPos: getPos$1, 7375 parseStyle: parseStyle, 7376 serializeStyle: serializeStyle, 7377 addStyle: addStyle, 7378 loadCSS: loadCSS, 7379 addClass: addClass, 7380 removeClass: removeClass, 7381 hasClass: hasClass, 7382 toggleClass: toggleClass, 7383 show: show, 7384 hide: hide, 7385 isHidden: isHidden, 7386 uniqueId: uniqueId, 7387 setHTML: setHTML, 7388 getOuterHTML: getOuterHTML, 7389 setOuterHTML: setOuterHTML, 7390 decode: decode, 7391 encode: encode, 7392 insertAfter: insertAfter, 7393 replace: replace, 7394 rename: rename, 7395 findCommonAncestor: findCommonAncestor, 7396 toHex: toHex, 7397 run: run, 7398 getAttribs: getAttribs, 7399 isEmpty: isEmpty, 7400 createRng: createRng, 7401 nodeIndex: findNodeIndex, 7402 split: split, 7403 bind: bind, 7404 unbind: unbind, 7405 fire: fire, 7406 getContentEditable: getContentEditable, 7407 getContentEditableParent: getContentEditableParent, 7408 destroy: destroy, 7409 isChildOf: isChildOf, 7410 dumpRng: dumpRng 7411 }; 7412 var attrHooks = setupAttrHooks(styles, settings, constant(self)); 7413 return self; 7414 }; 7415 DOMUtils.DOM = DOMUtils(document); 7416 DOMUtils.nodeIndex = findNodeIndex; 7417 7418 var DOM$a = DOMUtils.DOM; 7419 var each$e = Tools.each, grep = Tools.grep; 7420 var QUEUED = 0; 7421 var LOADING = 1; 7422 var LOADED = 2; 7423 var FAILED = 3; 7424 var ScriptLoader = function () { 7425 function ScriptLoader(settings) { 7426 if (settings === void 0) { 7427 settings = {}; 7428 } 7429 this.states = {}; 7430 this.queue = []; 7431 this.scriptLoadedCallbacks = {}; 7432 this.queueLoadedCallbacks = []; 7433 this.loading = 0; 7434 this.settings = settings; 7435 } 7436 ScriptLoader.prototype._setReferrerPolicy = function (referrerPolicy) { 7437 this.settings.referrerPolicy = referrerPolicy; 7438 }; 7439 ScriptLoader.prototype.loadScript = function (url, success, failure) { 7440 var dom = DOM$a; 7441 var elm; 7442 var cleanup = function () { 7443 dom.remove(id); 7444 if (elm) { 7445 elm.onerror = elm.onload = elm = null; 7446 } 7447 }; 7448 var done = function () { 7449 cleanup(); 7450 success(); 7451 }; 7452 var error = function () { 7453 cleanup(); 7454 if (isFunction(failure)) { 7455 failure(); 7456 } else { 7457 if (typeof console !== 'undefined' && console.log) { 7458 console.log('Failed to load script: ' + url); 7459 } 7460 } 7461 }; 7462 var id = dom.uniqueId(); 7463 elm = document.createElement('script'); 7464 elm.id = id; 7465 elm.type = 'text/javascript'; 7466 elm.src = Tools._addCacheSuffix(url); 7467 if (this.settings.referrerPolicy) { 7468 dom.setAttrib(elm, 'referrerpolicy', this.settings.referrerPolicy); 7469 } 7470 elm.onload = done; 7471 elm.onerror = error; 7472 (document.getElementsByTagName('head')[0] || document.body).appendChild(elm); 7473 }; 7474 ScriptLoader.prototype.isDone = function (url) { 7475 return this.states[url] === LOADED; 7476 }; 7477 ScriptLoader.prototype.markDone = function (url) { 7478 this.states[url] = LOADED; 7479 }; 7480 ScriptLoader.prototype.add = function (url, success, scope, failure) { 7481 var state = this.states[url]; 7482 this.queue.push(url); 7483 if (state === undefined) { 7484 this.states[url] = QUEUED; 7485 } 7486 if (success) { 7487 if (!this.scriptLoadedCallbacks[url]) { 7488 this.scriptLoadedCallbacks[url] = []; 7489 } 7490 this.scriptLoadedCallbacks[url].push({ 7491 success: success, 7492 failure: failure, 7493 scope: scope || this 7494 }); 7495 } 7496 }; 7497 ScriptLoader.prototype.load = function (url, success, scope, failure) { 7498 return this.add(url, success, scope, failure); 7499 }; 7500 ScriptLoader.prototype.remove = function (url) { 7501 delete this.states[url]; 7502 delete this.scriptLoadedCallbacks[url]; 7503 }; 7504 ScriptLoader.prototype.loadQueue = function (success, scope, failure) { 7505 this.loadScripts(this.queue, success, scope, failure); 7506 }; 7507 ScriptLoader.prototype.loadScripts = function (scripts, success, scope, failure) { 7508 var self = this; 7509 var failures = []; 7510 var execCallbacks = function (name, url) { 7511 each$e(self.scriptLoadedCallbacks[url], function (callback) { 7512 if (isFunction(callback[name])) { 7513 callback[name].call(callback.scope); 7514 } 7515 }); 7516 self.scriptLoadedCallbacks[url] = undefined; 7517 }; 7518 self.queueLoadedCallbacks.push({ 7519 success: success, 7520 failure: failure, 7521 scope: scope || this 7522 }); 7523 var loadScripts = function () { 7524 var loadingScripts = grep(scripts); 7525 scripts.length = 0; 7526 each$e(loadingScripts, function (url) { 7527 if (self.states[url] === LOADED) { 7528 execCallbacks('success', url); 7529 return; 7530 } 7531 if (self.states[url] === FAILED) { 7532 execCallbacks('failure', url); 7533 return; 7534 } 7535 if (self.states[url] !== LOADING) { 7536 self.states[url] = LOADING; 7537 self.loading++; 7538 self.loadScript(url, function () { 7539 self.states[url] = LOADED; 7540 self.loading--; 7541 execCallbacks('success', url); 7542 loadScripts(); 7543 }, function () { 7544 self.states[url] = FAILED; 7545 self.loading--; 7546 failures.push(url); 7547 execCallbacks('failure', url); 7548 loadScripts(); 7549 }); 7550 } 7551 }); 7552 if (!self.loading) { 7553 var notifyCallbacks = self.queueLoadedCallbacks.slice(0); 7554 self.queueLoadedCallbacks.length = 0; 7555 each$e(notifyCallbacks, function (callback) { 7556 if (failures.length === 0) { 7557 if (isFunction(callback.success)) { 7558 callback.success.call(callback.scope); 7559 } 7560 } else { 7561 if (isFunction(callback.failure)) { 7562 callback.failure.call(callback.scope, failures); 7563 } 7564 } 7565 }); 7566 } 7567 }; 7568 loadScripts(); 7569 }; 7570 ScriptLoader.ScriptLoader = new ScriptLoader(); 7571 return ScriptLoader; 7572 }(); 7573 7574 var Cell = function (initial) { 7575 var value = initial; 7576 var get = function () { 7577 return value; 7578 }; 7579 var set = function (v) { 7580 value = v; 7581 }; 7582 return { 7583 get: get, 7584 set: set 7585 }; 7586 }; 7587 7588 var isRaw = function (str) { 7589 return isObject(str) && has$2(str, 'raw'); 7590 }; 7591 var isTokenised = function (str) { 7592 return isArray$1(str) && str.length > 1; 7593 }; 7594 var data = {}; 7595 var currentCode = Cell('en'); 7596 var getLanguageData = function () { 7597 return get$9(data, currentCode.get()); 7598 }; 7599 var getData = function () { 7600 return map$2(data, function (value) { 7601 return __assign({}, value); 7602 }); 7603 }; 7604 var setCode = function (newCode) { 7605 if (newCode) { 7606 currentCode.set(newCode); 7607 } 7608 }; 7609 var getCode = function () { 7610 return currentCode.get(); 7611 }; 7612 var add$4 = function (code, items) { 7613 var langData = data[code]; 7614 if (!langData) { 7615 data[code] = langData = {}; 7616 } 7617 each$j(items, function (translation, name) { 7618 langData[name.toLowerCase()] = translation; 7619 }); 7620 }; 7621 var translate = function (text) { 7622 var langData = getLanguageData().getOr({}); 7623 var toString = function (obj) { 7624 if (isFunction(obj)) { 7625 return Object.prototype.toString.call(obj); 7626 } 7627 return !isEmpty(obj) ? '' + obj : ''; 7628 }; 7629 var isEmpty = function (text) { 7630 return text === '' || text === null || text === undefined; 7631 }; 7632 var getLangData = function (text) { 7633 var textstr = toString(text); 7634 return get$9(langData, textstr.toLowerCase()).map(toString).getOr(textstr); 7635 }; 7636 var removeContext = function (str) { 7637 return str.replace(/{context:\w+}$/, ''); 7638 }; 7639 if (isEmpty(text)) { 7640 return ''; 7641 } 7642 if (isRaw(text)) { 7643 return toString(text.raw); 7644 } 7645 if (isTokenised(text)) { 7646 var values_1 = text.slice(1); 7647 var substitued = getLangData(text[0]).replace(/\{([0-9]+)\}/g, function ($1, $2) { 7648 return has$2(values_1, $2) ? toString(values_1[$2]) : $1; 7649 }); 7650 return removeContext(substitued); 7651 } 7652 return removeContext(getLangData(text)); 7653 }; 7654 var isRtl$1 = function () { 7655 return getLanguageData().bind(function (items) { 7656 return get$9(items, '_dir'); 7657 }).exists(function (dir) { 7658 return dir === 'rtl'; 7659 }); 7660 }; 7661 var hasCode = function (code) { 7662 return has$2(data, code); 7663 }; 7664 var I18n = { 7665 getData: getData, 7666 setCode: setCode, 7667 getCode: getCode, 7668 add: add$4, 7669 translate: translate, 7670 isRtl: isRtl$1, 7671 hasCode: hasCode 7672 }; 7673 7674 var AddOnManager = function () { 7675 var items = []; 7676 var urls = {}; 7677 var lookup = {}; 7678 var _listeners = []; 7679 var runListeners = function (name, state) { 7680 var matchedListeners = filter$4(_listeners, function (listener) { 7681 return listener.name === name && listener.state === state; 7682 }); 7683 each$k(matchedListeners, function (listener) { 7684 return listener.callback(); 7685 }); 7686 }; 7687 var get = function (name) { 7688 if (lookup[name]) { 7689 return lookup[name].instance; 7690 } 7691 return undefined; 7692 }; 7693 var dependencies = function (name) { 7694 var result; 7695 if (lookup[name]) { 7696 result = lookup[name].dependencies; 7697 } 7698 return result || []; 7699 }; 7700 var requireLangPack = function (name, languages) { 7701 if (AddOnManager.languageLoad !== false) { 7702 waitFor(name, function () { 7703 var language = I18n.getCode(); 7704 var wrappedLanguages = ',' + (languages || '') + ','; 7705 if (!language || languages && wrappedLanguages.indexOf(',' + language + ',') === -1) { 7706 return; 7707 } 7708 ScriptLoader.ScriptLoader.add(urls[name] + '/langs/' + language + '.js'); 7709 }, 'loaded'); 7710 } 7711 }; 7712 var add = function (id, addOn, dependencies) { 7713 var addOnConstructor = addOn; 7714 items.push(addOnConstructor); 7715 lookup[id] = { 7716 instance: addOnConstructor, 7717 dependencies: dependencies 7718 }; 7719 runListeners(id, 'added'); 7720 return addOnConstructor; 7721 }; 7722 var remove = function (name) { 7723 delete urls[name]; 7724 delete lookup[name]; 7725 }; 7726 var createUrl = function (baseUrl, dep) { 7727 if (typeof dep === 'object') { 7728 return dep; 7729 } 7730 return typeof baseUrl === 'string' ? { 7731 prefix: '', 7732 resource: dep, 7733 suffix: '' 7734 } : { 7735 prefix: baseUrl.prefix, 7736 resource: dep, 7737 suffix: baseUrl.suffix 7738 }; 7739 }; 7740 var addComponents = function (pluginName, scripts) { 7741 var pluginUrl = urls[pluginName]; 7742 each$k(scripts, function (script) { 7743 ScriptLoader.ScriptLoader.add(pluginUrl + '/' + script); 7744 }); 7745 }; 7746 var loadDependencies = function (name, addOnUrl, success, scope) { 7747 var deps = dependencies(name); 7748 each$k(deps, function (dep) { 7749 var newUrl = createUrl(addOnUrl, dep); 7750 load(newUrl.resource, newUrl, undefined, undefined); 7751 }); 7752 if (success) { 7753 if (scope) { 7754 success.call(scope); 7755 } else { 7756 success.call(ScriptLoader); 7757 } 7758 } 7759 }; 7760 var load = function (name, addOnUrl, success, scope, failure) { 7761 if (urls[name]) { 7762 return; 7763 } 7764 var urlString = typeof addOnUrl === 'string' ? addOnUrl : addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix; 7765 if (urlString.indexOf('/') !== 0 && urlString.indexOf('://') === -1) { 7766 urlString = AddOnManager.baseURL + '/' + urlString; 7767 } 7768 urls[name] = urlString.substring(0, urlString.lastIndexOf('/')); 7769 var done = function () { 7770 runListeners(name, 'loaded'); 7771 loadDependencies(name, addOnUrl, success, scope); 7772 }; 7773 if (lookup[name]) { 7774 done(); 7775 } else { 7776 ScriptLoader.ScriptLoader.add(urlString, done, scope, failure); 7777 } 7778 }; 7779 var waitFor = function (name, callback, state) { 7780 if (state === void 0) { 7781 state = 'added'; 7782 } 7783 if (has$2(lookup, name) && state === 'added') { 7784 callback(); 7785 } else if (has$2(urls, name) && state === 'loaded') { 7786 callback(); 7787 } else { 7788 _listeners.push({ 7789 name: name, 7790 state: state, 7791 callback: callback 7792 }); 7793 } 7794 }; 7795 return { 7796 items: items, 7797 urls: urls, 7798 lookup: lookup, 7799 _listeners: _listeners, 7800 get: get, 7801 dependencies: dependencies, 7802 requireLangPack: requireLangPack, 7803 add: add, 7804 remove: remove, 7805 createUrl: createUrl, 7806 addComponents: addComponents, 7807 load: load, 7808 waitFor: waitFor 7809 }; 7810 }; 7811 AddOnManager.languageLoad = true; 7812 AddOnManager.baseURL = ''; 7813 AddOnManager.PluginManager = AddOnManager(); 7814 AddOnManager.ThemeManager = AddOnManager(); 7815 7816 var singleton = function (doRevoke) { 7817 var subject = Cell(Optional.none()); 7818 var revoke = function () { 7819 return subject.get().each(doRevoke); 7820 }; 7821 var clear = function () { 7822 revoke(); 7823 subject.set(Optional.none()); 7824 }; 7825 var isSet = function () { 7826 return subject.get().isSome(); 7827 }; 7828 var get = function () { 7829 return subject.get(); 7830 }; 7831 var set = function (s) { 7832 revoke(); 7833 subject.set(Optional.some(s)); 7834 }; 7835 return { 7836 clear: clear, 7837 isSet: isSet, 7838 get: get, 7839 set: set 7840 }; 7841 }; 7842 var value = function () { 7843 var subject = singleton(noop); 7844 var on = function (f) { 7845 return subject.get().each(f); 7846 }; 7847 return __assign(__assign({}, subject), { on: on }); 7848 }; 7849 7850 var first = function (fn, rate) { 7851 var timer = null; 7852 var cancel = function () { 7853 if (!isNull(timer)) { 7854 clearTimeout(timer); 7855 timer = null; 7856 } 7857 }; 7858 var throttle = function () { 7859 var args = []; 7860 for (var _i = 0; _i < arguments.length; _i++) { 7861 args[_i] = arguments[_i]; 7862 } 7863 if (isNull(timer)) { 7864 timer = setTimeout(function () { 7865 timer = null; 7866 fn.apply(null, args); 7867 }, rate); 7868 } 7869 }; 7870 return { 7871 cancel: cancel, 7872 throttle: throttle 7873 }; 7874 }; 7875 var last = function (fn, rate) { 7876 var timer = null; 7877 var cancel = function () { 7878 if (!isNull(timer)) { 7879 clearTimeout(timer); 7880 timer = null; 7881 } 7882 }; 7883 var throttle = function () { 7884 var args = []; 7885 for (var _i = 0; _i < arguments.length; _i++) { 7886 args[_i] = arguments[_i]; 7887 } 7888 cancel(); 7889 timer = setTimeout(function () { 7890 timer = null; 7891 fn.apply(null, args); 7892 }, rate); 7893 }; 7894 return { 7895 cancel: cancel, 7896 throttle: throttle 7897 }; 7898 }; 7899 7900 var read$4 = function (element, attr) { 7901 var value = get$6(element, attr); 7902 return value === undefined || value === '' ? [] : value.split(' '); 7903 }; 7904 var add$3 = function (element, attr, id) { 7905 var old = read$4(element, attr); 7906 var nu = old.concat([id]); 7907 set$1(element, attr, nu.join(' ')); 7908 return true; 7909 }; 7910 var remove$5 = function (element, attr, id) { 7911 var nu = filter$4(read$4(element, attr), function (v) { 7912 return v !== id; 7913 }); 7914 if (nu.length > 0) { 7915 set$1(element, attr, nu.join(' ')); 7916 } else { 7917 remove$6(element, attr); 7918 } 7919 return false; 7920 }; 7921 7922 var supports = function (element) { 7923 return element.dom.classList !== undefined; 7924 }; 7925 var get$4 = function (element) { 7926 return read$4(element, 'class'); 7927 }; 7928 var add$2 = function (element, clazz) { 7929 return add$3(element, 'class', clazz); 7930 }; 7931 var remove$4 = function (element, clazz) { 7932 return remove$5(element, 'class', clazz); 7933 }; 7934 7935 var add$1 = function (element, clazz) { 7936 if (supports(element)) { 7937 element.dom.classList.add(clazz); 7938 } else { 7939 add$2(element, clazz); 7940 } 7941 }; 7942 var cleanClass = function (element) { 7943 var classList = supports(element) ? element.dom.classList : get$4(element); 7944 if (classList.length === 0) { 7945 remove$6(element, 'class'); 7946 } 7947 }; 7948 var remove$3 = function (element, clazz) { 7949 if (supports(element)) { 7950 var classList = element.dom.classList; 7951 classList.remove(clazz); 7952 } else { 7953 remove$4(element, clazz); 7954 } 7955 cleanClass(element); 7956 }; 7957 var has = function (element, clazz) { 7958 return supports(element) && element.dom.classList.contains(clazz); 7959 }; 7960 7961 var descendants$1 = function (scope, predicate) { 7962 var result = []; 7963 each$k(children(scope), function (x) { 7964 if (predicate(x)) { 7965 result = result.concat([x]); 7966 } 7967 result = result.concat(descendants$1(x, predicate)); 7968 }); 7969 return result; 7970 }; 7971 7972 var descendants = function (scope, selector) { 7973 return all(selector, scope); 7974 }; 7975 7976 var annotation = constant('mce-annotation'); 7977 var dataAnnotation = constant('data-mce-annotation'); 7978 var dataAnnotationId = constant('data-mce-annotation-uid'); 7979 7980 var identify = function (editor, annotationName) { 7981 var rng = editor.selection.getRng(); 7982 var start = SugarElement.fromDom(rng.startContainer); 7983 var root = SugarElement.fromDom(editor.getBody()); 7984 var selector = annotationName.fold(function () { 7985 return '.' + annotation(); 7986 }, function (an) { 7987 return '[' + dataAnnotation() + '="' + an + '"]'; 7988 }); 7989 var newStart = child$1(start, rng.startOffset).getOr(start); 7990 var closest = closest$2(newStart, selector, function (n) { 7991 return eq(n, root); 7992 }); 7993 var getAttr = function (c, property) { 7994 if (has$1(c, property)) { 7995 return Optional.some(get$6(c, property)); 7996 } else { 7997 return Optional.none(); 7998 } 7999 }; 8000 return closest.bind(function (c) { 8001 return getAttr(c, '' + dataAnnotationId()).bind(function (uid) { 8002 return getAttr(c, '' + dataAnnotation()).map(function (name) { 8003 var elements = findMarkers(editor, uid); 8004 return { 8005 uid: uid, 8006 name: name, 8007 elements: elements 8008 }; 8009 }); 8010 }); 8011 }); 8012 }; 8013 var isAnnotation = function (elem) { 8014 return isElement$6(elem) && has(elem, annotation()); 8015 }; 8016 var findMarkers = function (editor, uid) { 8017 var body = SugarElement.fromDom(editor.getBody()); 8018 return descendants(body, '[' + dataAnnotationId() + '="' + uid + '"]'); 8019 }; 8020 var findAll = function (editor, name) { 8021 var body = SugarElement.fromDom(editor.getBody()); 8022 var markers = descendants(body, '[' + dataAnnotation() + '="' + name + '"]'); 8023 var directory = {}; 8024 each$k(markers, function (m) { 8025 var uid = get$6(m, dataAnnotationId()); 8026 var nodesAlready = get$9(directory, uid).getOr([]); 8027 directory[uid] = nodesAlready.concat([m]); 8028 }); 8029 return directory; 8030 }; 8031 8032 var setup$n = function (editor, _registry) { 8033 var changeCallbacks = Cell({}); 8034 var initData = function () { 8035 return { 8036 listeners: [], 8037 previous: value() 8038 }; 8039 }; 8040 var withCallbacks = function (name, f) { 8041 updateCallbacks(name, function (data) { 8042 f(data); 8043 return data; 8044 }); 8045 }; 8046 var updateCallbacks = function (name, f) { 8047 var callbackMap = changeCallbacks.get(); 8048 var data = get$9(callbackMap, name).getOrThunk(initData); 8049 var outputData = f(data); 8050 callbackMap[name] = outputData; 8051 changeCallbacks.set(callbackMap); 8052 }; 8053 var fireCallbacks = function (name, uid, elements) { 8054 withCallbacks(name, function (data) { 8055 each$k(data.listeners, function (f) { 8056 return f(true, name, { 8057 uid: uid, 8058 nodes: map$3(elements, function (elem) { 8059 return elem.dom; 8060 }) 8061 }); 8062 }); 8063 }); 8064 }; 8065 var fireNoAnnotation = function (name) { 8066 withCallbacks(name, function (data) { 8067 each$k(data.listeners, function (f) { 8068 return f(false, name); 8069 }); 8070 }); 8071 }; 8072 var onNodeChange = last(function () { 8073 var callbackMap = changeCallbacks.get(); 8074 var annotations = sort(keys(callbackMap)); 8075 each$k(annotations, function (name) { 8076 updateCallbacks(name, function (data) { 8077 var prev = data.previous.get(); 8078 identify(editor, Optional.some(name)).fold(function () { 8079 if (prev.isSome()) { 8080 fireNoAnnotation(name); 8081 data.previous.clear(); 8082 } 8083 }, function (_a) { 8084 var uid = _a.uid, name = _a.name, elements = _a.elements; 8085 if (!is$1(prev, uid)) { 8086 fireCallbacks(name, uid, elements); 8087 data.previous.set(uid); 8088 } 8089 }); 8090 return { 8091 previous: data.previous, 8092 listeners: data.listeners 8093 }; 8094 }); 8095 }); 8096 }, 30); 8097 editor.on('remove', function () { 8098 onNodeChange.cancel(); 8099 }); 8100 editor.on('NodeChange', function () { 8101 onNodeChange.throttle(); 8102 }); 8103 var addListener = function (name, f) { 8104 updateCallbacks(name, function (data) { 8105 return { 8106 previous: data.previous, 8107 listeners: data.listeners.concat([f]) 8108 }; 8109 }); 8110 }; 8111 return { addListener: addListener }; 8112 }; 8113 8114 var setup$m = function (editor, registry) { 8115 var identifyParserNode = function (span) { 8116 return Optional.from(span.attr(dataAnnotation())).bind(registry.lookup); 8117 }; 8118 editor.on('init', function () { 8119 editor.serializer.addNodeFilter('span', function (spans) { 8120 each$k(spans, function (span) { 8121 identifyParserNode(span).each(function (settings) { 8122 if (settings.persistent === false) { 8123 span.unwrap(); 8124 } 8125 }); 8126 }); 8127 }); 8128 }); 8129 }; 8130 8131 var create$7 = function () { 8132 var annotations = {}; 8133 var register = function (name, settings) { 8134 annotations[name] = { 8135 name: name, 8136 settings: settings 8137 }; 8138 }; 8139 var lookup = function (name) { 8140 return get$9(annotations, name).map(function (a) { 8141 return a.settings; 8142 }); 8143 }; 8144 return { 8145 register: register, 8146 lookup: lookup 8147 }; 8148 }; 8149 8150 var unique = 0; 8151 var generate = function (prefix) { 8152 var date = new Date(); 8153 var time = date.getTime(); 8154 var random = Math.floor(Math.random() * 1000000000); 8155 unique++; 8156 return prefix + '_' + random + unique + String(time); 8157 }; 8158 8159 var add = function (element, classes) { 8160 each$k(classes, function (x) { 8161 add$1(element, x); 8162 }); 8163 }; 8164 8165 var fromHtml = function (html, scope) { 8166 var doc = scope || document; 8167 var div = doc.createElement('div'); 8168 div.innerHTML = html; 8169 return children(SugarElement.fromDom(div)); 8170 }; 8171 var fromDom$1 = function (nodes) { 8172 return map$3(nodes, SugarElement.fromDom); 8173 }; 8174 8175 var get$3 = function (element) { 8176 return element.dom.innerHTML; 8177 }; 8178 var set = function (element, content) { 8179 var owner = owner$1(element); 8180 var docDom = owner.dom; 8181 var fragment = SugarElement.fromDom(docDom.createDocumentFragment()); 8182 var contentElements = fromHtml(content, docDom); 8183 append(fragment, contentElements); 8184 empty(element); 8185 append$1(element, fragment); 8186 }; 8187 8188 var clone$1 = function (original, isDeep) { 8189 return SugarElement.fromDom(original.dom.cloneNode(isDeep)); 8190 }; 8191 var shallow = function (original) { 8192 return clone$1(original, false); 8193 }; 8194 var deep$1 = function (original) { 8195 return clone$1(original, true); 8196 }; 8197 8198 var TextWalker = function (startNode, rootNode, isBoundary) { 8199 if (isBoundary === void 0) { 8200 isBoundary = never; 8201 } 8202 var walker = new DomTreeWalker(startNode, rootNode); 8203 var walk = function (direction) { 8204 var next; 8205 do { 8206 next = walker[direction](); 8207 } while (next && !isText$7(next) && !isBoundary(next)); 8208 return Optional.from(next).filter(isText$7); 8209 }; 8210 return { 8211 current: function () { 8212 return Optional.from(walker.current()).filter(isText$7); 8213 }, 8214 next: function () { 8215 return walk('next'); 8216 }, 8217 prev: function () { 8218 return walk('prev'); 8219 }, 8220 prev2: function () { 8221 return walk('prev2'); 8222 } 8223 }; 8224 }; 8225 8226 var TextSeeker = function (dom, isBoundary) { 8227 var isBlockBoundary = isBoundary ? isBoundary : function (node) { 8228 return dom.isBlock(node) || isBr$5(node) || isContentEditableFalse$b(node); 8229 }; 8230 var walk = function (node, offset, walker, process) { 8231 if (isText$7(node)) { 8232 var newOffset = process(node, offset, node.data); 8233 if (newOffset !== -1) { 8234 return Optional.some({ 8235 container: node, 8236 offset: newOffset 8237 }); 8238 } 8239 } 8240 return walker().bind(function (next) { 8241 return walk(next.container, next.offset, walker, process); 8242 }); 8243 }; 8244 var backwards = function (node, offset, process, root) { 8245 var walker = TextWalker(node, root, isBlockBoundary); 8246 return walk(node, offset, function () { 8247 return walker.prev().map(function (prev) { 8248 return { 8249 container: prev, 8250 offset: prev.length 8251 }; 8252 }); 8253 }, process).getOrNull(); 8254 }; 8255 var forwards = function (node, offset, process, root) { 8256 var walker = TextWalker(node, root, isBlockBoundary); 8257 return walk(node, offset, function () { 8258 return walker.next().map(function (next) { 8259 return { 8260 container: next, 8261 offset: 0 8262 }; 8263 }); 8264 }, process).getOrNull(); 8265 }; 8266 return { 8267 backwards: backwards, 8268 forwards: forwards 8269 }; 8270 }; 8271 8272 var round$2 = Math.round; 8273 var clone = function (rect) { 8274 if (!rect) { 8275 return { 8276 left: 0, 8277 top: 0, 8278 bottom: 0, 8279 right: 0, 8280 width: 0, 8281 height: 0 8282 }; 8283 } 8284 return { 8285 left: round$2(rect.left), 8286 top: round$2(rect.top), 8287 bottom: round$2(rect.bottom), 8288 right: round$2(rect.right), 8289 width: round$2(rect.width), 8290 height: round$2(rect.height) 8291 }; 8292 }; 8293 var collapse = function (rect, toStart) { 8294 rect = clone(rect); 8295 if (toStart) { 8296 rect.right = rect.left; 8297 } else { 8298 rect.left = rect.left + rect.width; 8299 rect.right = rect.left; 8300 } 8301 rect.width = 0; 8302 return rect; 8303 }; 8304 var isEqual = function (rect1, rect2) { 8305 return rect1.left === rect2.left && rect1.top === rect2.top && rect1.bottom === rect2.bottom && rect1.right === rect2.right; 8306 }; 8307 var isValidOverflow = function (overflowY, rect1, rect2) { 8308 return overflowY >= 0 && overflowY <= Math.min(rect1.height, rect2.height) / 2; 8309 }; 8310 var isAbove$1 = function (rect1, rect2) { 8311 var halfHeight = Math.min(rect2.height / 2, rect1.height / 2); 8312 if (rect1.bottom - halfHeight < rect2.top) { 8313 return true; 8314 } 8315 if (rect1.top > rect2.bottom) { 8316 return false; 8317 } 8318 return isValidOverflow(rect2.top - rect1.bottom, rect1, rect2); 8319 }; 8320 var isBelow$1 = function (rect1, rect2) { 8321 if (rect1.top > rect2.bottom) { 8322 return true; 8323 } 8324 if (rect1.bottom < rect2.top) { 8325 return false; 8326 } 8327 return isValidOverflow(rect2.bottom - rect1.top, rect1, rect2); 8328 }; 8329 var containsXY = function (rect, clientX, clientY) { 8330 return clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom; 8331 }; 8332 8333 var clamp$2 = function (value, min, max) { 8334 return Math.min(Math.max(value, min), max); 8335 }; 8336 8337 var getSelectedNode = function (range) { 8338 var startContainer = range.startContainer, startOffset = range.startOffset; 8339 if (startContainer.hasChildNodes() && range.endOffset === startOffset + 1) { 8340 return startContainer.childNodes[startOffset]; 8341 } 8342 return null; 8343 }; 8344 var getNode$1 = function (container, offset) { 8345 if (isElement$5(container) && container.hasChildNodes()) { 8346 var childNodes = container.childNodes; 8347 var safeOffset = clamp$2(offset, 0, childNodes.length - 1); 8348 return childNodes[safeOffset]; 8349 } else { 8350 return container; 8351 } 8352 }; 8353 var getNodeUnsafe = function (container, offset) { 8354 if (offset < 0 && isElement$5(container) && container.hasChildNodes()) { 8355 return undefined; 8356 } else { 8357 return getNode$1(container, offset); 8358 } 8359 }; 8360 8361 var extendingChars = new RegExp('[\u0300-\u036f\u0483-\u0487\u0488-\u0489\u0591-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u061a' + '\u064b-\u065f\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0' + '\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0902\u093a\u093c' + '\u0941-\u0948\u094d\u0951-\u0957\u0962-\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2-\u09e3' + '\u0a01-\u0a02\u0a3c\u0a41-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a51\u0a70-\u0a71\u0a75\u0a81-\u0a82\u0abc' + '\u0ac1-\u0ac5\u0ac7-\u0ac8\u0acd\u0ae2-\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57' + '\u0b62-\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c00\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56' + '\u0c62-\u0c63\u0c81\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc-\u0ccd\u0cd5-\u0cd6\u0ce2-\u0ce3\u0d01\u0d3e\u0d41-\u0d44' + '\u0d4d\u0d57\u0d62-\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9' + '\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86-\u0f87\u0f8d-\u0f97' + '\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039-\u103a\u103d-\u103e\u1058-\u1059\u105e-\u1060\u1071-\u1074' + '\u1082\u1085-\u1086\u108d\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b4-\u17b5' + '\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193b\u1a17-\u1a18' + '\u1a1b\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1ab0-\u1abd\u1ABE\u1b00-\u1b03\u1b34' + '\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80-\u1b81\u1ba2-\u1ba5\u1ba8-\u1ba9\u1bab-\u1bad\u1be6\u1be8-\u1be9' + '\u1bed\u1bef-\u1bf1\u1c2c-\u1c33\u1c36-\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1cf4\u1cf8-\u1cf9' + '\u1dc0-\u1df5\u1dfc-\u1dff\u200c-\u200d\u20d0-\u20dc\u20DD-\u20E0\u20e1\u20E2-\u20E4\u20e5-\u20f0\u2cef-\u2cf1' + '\u2d7f\u2de0-\u2dff\u302a-\u302d\u302e-\u302f\u3099-\u309a\ua66f\uA670-\uA672\ua674-\ua67d\ua69e-\ua69f\ua6f0-\ua6f1' + '\ua802\ua806\ua80b\ua825-\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc' + '\ua9e5\uaa29-\uaa2e\uaa31-\uaa32\uaa35-\uaa36\uaa43\uaa4c\uaa7c\uaab0\uaab2-\uaab4\uaab7-\uaab8\uaabe-\uaabf\uaac1' + '\uaaec-\uaaed\uaaf6\uabe5\uabe8\uabed\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\uff9e-\uff9f]'); 8362 var isExtendingChar = function (ch) { 8363 return typeof ch === 'string' && ch.charCodeAt(0) >= 768 && extendingChars.test(ch); 8364 }; 8365 8366 var or = function () { 8367 var args = []; 8368 for (var _i = 0; _i < arguments.length; _i++) { 8369 args[_i] = arguments[_i]; 8370 } 8371 return function (x) { 8372 for (var i = 0; i < args.length; i++) { 8373 if (args[i](x)) { 8374 return true; 8375 } 8376 } 8377 return false; 8378 }; 8379 }; 8380 var and = function () { 8381 var args = []; 8382 for (var _i = 0; _i < arguments.length; _i++) { 8383 args[_i] = arguments[_i]; 8384 } 8385 return function (x) { 8386 for (var i = 0; i < args.length; i++) { 8387 if (!args[i](x)) { 8388 return false; 8389 } 8390 } 8391 return true; 8392 }; 8393 }; 8394 8395 var isElement$3 = isElement$5; 8396 var isCaretCandidate$2 = isCaretCandidate$3; 8397 var isBlock$1 = matchStyleValues('display', 'block table'); 8398 var isFloated = matchStyleValues('float', 'left right'); 8399 var isValidElementCaretCandidate = and(isElement$3, isCaretCandidate$2, not(isFloated)); 8400 var isNotPre = not(matchStyleValues('white-space', 'pre pre-line pre-wrap')); 8401 var isText$4 = isText$7; 8402 var isBr$2 = isBr$5; 8403 var nodeIndex$1 = DOMUtils.nodeIndex; 8404 var resolveIndex$1 = getNodeUnsafe; 8405 var createRange$1 = function (doc) { 8406 return 'createRange' in doc ? doc.createRange() : DOMUtils.DOM.createRng(); 8407 }; 8408 var isWhiteSpace$1 = function (chr) { 8409 return chr && /[\r\n\t ]/.test(chr); 8410 }; 8411 var isRange = function (rng) { 8412 return !!rng.setStart && !!rng.setEnd; 8413 }; 8414 var isHiddenWhiteSpaceRange = function (range) { 8415 var container = range.startContainer; 8416 var offset = range.startOffset; 8417 if (isWhiteSpace$1(range.toString()) && isNotPre(container.parentNode) && isText$7(container)) { 8418 var text = container.data; 8419 if (isWhiteSpace$1(text[offset - 1]) || isWhiteSpace$1(text[offset + 1])) { 8420 return true; 8421 } 8422 } 8423 return false; 8424 }; 8425 var getBrClientRect = function (brNode) { 8426 var doc = brNode.ownerDocument; 8427 var rng = createRange$1(doc); 8428 var nbsp$1 = doc.createTextNode(nbsp); 8429 var parentNode = brNode.parentNode; 8430 parentNode.insertBefore(nbsp$1, brNode); 8431 rng.setStart(nbsp$1, 0); 8432 rng.setEnd(nbsp$1, 1); 8433 var clientRect = clone(rng.getBoundingClientRect()); 8434 parentNode.removeChild(nbsp$1); 8435 return clientRect; 8436 }; 8437 var getBoundingClientRectWebKitText = function (rng) { 8438 var sc = rng.startContainer; 8439 var ec = rng.endContainer; 8440 var so = rng.startOffset; 8441 var eo = rng.endOffset; 8442 if (sc === ec && isText$7(ec) && so === 0 && eo === 1) { 8443 var newRng = rng.cloneRange(); 8444 newRng.setEndAfter(ec); 8445 return getBoundingClientRect$1(newRng); 8446 } else { 8447 return null; 8448 } 8449 }; 8450 var isZeroRect = function (r) { 8451 return r.left === 0 && r.right === 0 && r.top === 0 && r.bottom === 0; 8452 }; 8453 var getBoundingClientRect$1 = function (item) { 8454 var clientRect; 8455 var clientRects = item.getClientRects(); 8456 if (clientRects.length > 0) { 8457 clientRect = clone(clientRects[0]); 8458 } else { 8459 clientRect = clone(item.getBoundingClientRect()); 8460 } 8461 if (!isRange(item) && isBr$2(item) && isZeroRect(clientRect)) { 8462 return getBrClientRect(item); 8463 } 8464 if (isZeroRect(clientRect) && isRange(item)) { 8465 return getBoundingClientRectWebKitText(item); 8466 } 8467 return clientRect; 8468 }; 8469 var collapseAndInflateWidth = function (clientRect, toStart) { 8470 var newClientRect = collapse(clientRect, toStart); 8471 newClientRect.width = 1; 8472 newClientRect.right = newClientRect.left + 1; 8473 return newClientRect; 8474 }; 8475 var getCaretPositionClientRects = function (caretPosition) { 8476 var clientRects = []; 8477 var addUniqueAndValidRect = function (clientRect) { 8478 if (clientRect.height === 0) { 8479 return; 8480 } 8481 if (clientRects.length > 0) { 8482 if (isEqual(clientRect, clientRects[clientRects.length - 1])) { 8483 return; 8484 } 8485 } 8486 clientRects.push(clientRect); 8487 }; 8488 var addCharacterOffset = function (container, offset) { 8489 var range = createRange$1(container.ownerDocument); 8490 if (offset < container.data.length) { 8491 if (isExtendingChar(container.data[offset])) { 8492 return clientRects; 8493 } 8494 if (isExtendingChar(container.data[offset - 1])) { 8495 range.setStart(container, offset); 8496 range.setEnd(container, offset + 1); 8497 if (!isHiddenWhiteSpaceRange(range)) { 8498 addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), false)); 8499 return clientRects; 8500 } 8501 } 8502 } 8503 if (offset > 0) { 8504 range.setStart(container, offset - 1); 8505 range.setEnd(container, offset); 8506 if (!isHiddenWhiteSpaceRange(range)) { 8507 addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), false)); 8508 } 8509 } 8510 if (offset < container.data.length) { 8511 range.setStart(container, offset); 8512 range.setEnd(container, offset + 1); 8513 if (!isHiddenWhiteSpaceRange(range)) { 8514 addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), true)); 8515 } 8516 } 8517 }; 8518 var container = caretPosition.container(); 8519 var offset = caretPosition.offset(); 8520 if (isText$4(container)) { 8521 addCharacterOffset(container, offset); 8522 return clientRects; 8523 } 8524 if (isElement$3(container)) { 8525 if (caretPosition.isAtEnd()) { 8526 var node = resolveIndex$1(container, offset); 8527 if (isText$4(node)) { 8528 addCharacterOffset(node, node.data.length); 8529 } 8530 if (isValidElementCaretCandidate(node) && !isBr$2(node)) { 8531 addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false)); 8532 } 8533 } else { 8534 var node = resolveIndex$1(container, offset); 8535 if (isText$4(node)) { 8536 addCharacterOffset(node, 0); 8537 } 8538 if (isValidElementCaretCandidate(node) && caretPosition.isAtEnd()) { 8539 addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false)); 8540 return clientRects; 8541 } 8542 var beforeNode = resolveIndex$1(caretPosition.container(), caretPosition.offset() - 1); 8543 if (isValidElementCaretCandidate(beforeNode) && !isBr$2(beforeNode)) { 8544 if (isBlock$1(beforeNode) || isBlock$1(node) || !isValidElementCaretCandidate(node)) { 8545 addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(beforeNode), false)); 8546 } 8547 } 8548 if (isValidElementCaretCandidate(node)) { 8549 addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), true)); 8550 } 8551 } 8552 } 8553 return clientRects; 8554 }; 8555 var CaretPosition = function (container, offset, clientRects) { 8556 var isAtStart = function () { 8557 if (isText$4(container)) { 8558 return offset === 0; 8559 } 8560 return offset === 0; 8561 }; 8562 var isAtEnd = function () { 8563 if (isText$4(container)) { 8564 return offset >= container.data.length; 8565 } 8566 return offset >= container.childNodes.length; 8567 }; 8568 var toRange = function () { 8569 var range = createRange$1(container.ownerDocument); 8570 range.setStart(container, offset); 8571 range.setEnd(container, offset); 8572 return range; 8573 }; 8574 var getClientRects = function () { 8575 if (!clientRects) { 8576 clientRects = getCaretPositionClientRects(CaretPosition(container, offset)); 8577 } 8578 return clientRects; 8579 }; 8580 var isVisible = function () { 8581 return getClientRects().length > 0; 8582 }; 8583 var isEqual = function (caretPosition) { 8584 return caretPosition && container === caretPosition.container() && offset === caretPosition.offset(); 8585 }; 8586 var getNode = function (before) { 8587 return resolveIndex$1(container, before ? offset - 1 : offset); 8588 }; 8589 return { 8590 container: constant(container), 8591 offset: constant(offset), 8592 toRange: toRange, 8593 getClientRects: getClientRects, 8594 isVisible: isVisible, 8595 isAtStart: isAtStart, 8596 isAtEnd: isAtEnd, 8597 isEqual: isEqual, 8598 getNode: getNode 8599 }; 8600 }; 8601 CaretPosition.fromRangeStart = function (range) { 8602 return CaretPosition(range.startContainer, range.startOffset); 8603 }; 8604 CaretPosition.fromRangeEnd = function (range) { 8605 return CaretPosition(range.endContainer, range.endOffset); 8606 }; 8607 CaretPosition.after = function (node) { 8608 return CaretPosition(node.parentNode, nodeIndex$1(node) + 1); 8609 }; 8610 CaretPosition.before = function (node) { 8611 return CaretPosition(node.parentNode, nodeIndex$1(node)); 8612 }; 8613 CaretPosition.isAbove = function (pos1, pos2) { 8614 return lift2(head(pos2.getClientRects()), last$2(pos1.getClientRects()), isAbove$1).getOr(false); 8615 }; 8616 CaretPosition.isBelow = function (pos1, pos2) { 8617 return lift2(last$2(pos2.getClientRects()), head(pos1.getClientRects()), isBelow$1).getOr(false); 8618 }; 8619 CaretPosition.isAtStart = function (pos) { 8620 return pos ? pos.isAtStart() : false; 8621 }; 8622 CaretPosition.isAtEnd = function (pos) { 8623 return pos ? pos.isAtEnd() : false; 8624 }; 8625 CaretPosition.isTextPosition = function (pos) { 8626 return pos ? isText$7(pos.container()) : false; 8627 }; 8628 CaretPosition.isElementPosition = function (pos) { 8629 return CaretPosition.isTextPosition(pos) === false; 8630 }; 8631 8632 var trimEmptyTextNode$1 = function (dom, node) { 8633 if (isText$7(node) && node.data.length === 0) { 8634 dom.remove(node); 8635 } 8636 }; 8637 var insertNode = function (dom, rng, node) { 8638 rng.insertNode(node); 8639 trimEmptyTextNode$1(dom, node.previousSibling); 8640 trimEmptyTextNode$1(dom, node.nextSibling); 8641 }; 8642 var insertFragment = function (dom, rng, frag) { 8643 var firstChild = Optional.from(frag.firstChild); 8644 var lastChild = Optional.from(frag.lastChild); 8645 rng.insertNode(frag); 8646 firstChild.each(function (child) { 8647 return trimEmptyTextNode$1(dom, child.previousSibling); 8648 }); 8649 lastChild.each(function (child) { 8650 return trimEmptyTextNode$1(dom, child.nextSibling); 8651 }); 8652 }; 8653 var rangeInsertNode = function (dom, rng, node) { 8654 if (isDocumentFragment(node)) { 8655 insertFragment(dom, rng, node); 8656 } else { 8657 insertNode(dom, rng, node); 8658 } 8659 }; 8660 8661 var isText$3 = isText$7; 8662 var isBogus = isBogus$2; 8663 var nodeIndex = DOMUtils.nodeIndex; 8664 var normalizedParent = function (node) { 8665 var parentNode = node.parentNode; 8666 if (isBogus(parentNode)) { 8667 return normalizedParent(parentNode); 8668 } 8669 return parentNode; 8670 }; 8671 var getChildNodes = function (node) { 8672 if (!node) { 8673 return []; 8674 } 8675 return reduce(node.childNodes, function (result, node) { 8676 if (isBogus(node) && node.nodeName !== 'BR') { 8677 result = result.concat(getChildNodes(node)); 8678 } else { 8679 result.push(node); 8680 } 8681 return result; 8682 }, []); 8683 }; 8684 var normalizedTextOffset = function (node, offset) { 8685 while (node = node.previousSibling) { 8686 if (!isText$3(node)) { 8687 break; 8688 } 8689 offset += node.data.length; 8690 } 8691 return offset; 8692 }; 8693 var equal = function (a) { 8694 return function (b) { 8695 return a === b; 8696 }; 8697 }; 8698 var normalizedNodeIndex = function (node) { 8699 var nodes, index; 8700 nodes = getChildNodes(normalizedParent(node)); 8701 index = findIndex$1(nodes, equal(node), node); 8702 nodes = nodes.slice(0, index + 1); 8703 var numTextFragments = reduce(nodes, function (result, node, i) { 8704 if (isText$3(node) && isText$3(nodes[i - 1])) { 8705 result++; 8706 } 8707 return result; 8708 }, 0); 8709 nodes = filter$2(nodes, matchNodeNames([node.nodeName])); 8710 index = findIndex$1(nodes, equal(node), node); 8711 return index - numTextFragments; 8712 }; 8713 var createPathItem = function (node) { 8714 var name; 8715 if (isText$3(node)) { 8716 name = 'text()'; 8717 } else { 8718 name = node.nodeName.toLowerCase(); 8719 } 8720 return name + '[' + normalizedNodeIndex(node) + ']'; 8721 }; 8722 var parentsUntil$1 = function (root, node, predicate) { 8723 var parents = []; 8724 for (node = node.parentNode; node !== root; node = node.parentNode) { 8725 if (predicate && predicate(node)) { 8726 break; 8727 } 8728 parents.push(node); 8729 } 8730 return parents; 8731 }; 8732 var create$6 = function (root, caretPosition) { 8733 var container, offset, path = [], outputOffset, childNodes, parents; 8734 container = caretPosition.container(); 8735 offset = caretPosition.offset(); 8736 if (isText$3(container)) { 8737 outputOffset = normalizedTextOffset(container, offset); 8738 } else { 8739 childNodes = container.childNodes; 8740 if (offset >= childNodes.length) { 8741 outputOffset = 'after'; 8742 offset = childNodes.length - 1; 8743 } else { 8744 outputOffset = 'before'; 8745 } 8746 container = childNodes[offset]; 8747 } 8748 path.push(createPathItem(container)); 8749 parents = parentsUntil$1(root, container); 8750 parents = filter$2(parents, not(isBogus$2)); 8751 path = path.concat(map$1(parents, function (node) { 8752 return createPathItem(node); 8753 })); 8754 return path.reverse().join('/') + ',' + outputOffset; 8755 }; 8756 var resolvePathItem = function (node, name, index) { 8757 var nodes = getChildNodes(node); 8758 nodes = filter$2(nodes, function (node, index) { 8759 return !isText$3(node) || !isText$3(nodes[index - 1]); 8760 }); 8761 nodes = filter$2(nodes, matchNodeNames([name])); 8762 return nodes[index]; 8763 }; 8764 var findTextPosition = function (container, offset) { 8765 var node = container, targetOffset = 0, dataLen; 8766 while (isText$3(node)) { 8767 dataLen = node.data.length; 8768 if (offset >= targetOffset && offset <= targetOffset + dataLen) { 8769 container = node; 8770 offset = offset - targetOffset; 8771 break; 8772 } 8773 if (!isText$3(node.nextSibling)) { 8774 container = node; 8775 offset = dataLen; 8776 break; 8777 } 8778 targetOffset += dataLen; 8779 node = node.nextSibling; 8780 } 8781 if (isText$3(container) && offset > container.data.length) { 8782 offset = container.data.length; 8783 } 8784 return CaretPosition(container, offset); 8785 }; 8786 var resolve$2 = function (root, path) { 8787 var offset; 8788 if (!path) { 8789 return null; 8790 } 8791 var parts = path.split(','); 8792 var paths = parts[0].split('/'); 8793 offset = parts.length > 1 ? parts[1] : 'before'; 8794 var container = reduce(paths, function (result, value) { 8795 var match = /([\w\-\(\)]+)\[([0-9]+)\]/.exec(value); 8796 if (!match) { 8797 return null; 8798 } 8799 if (match[1] === 'text()') { 8800 match[1] = '#text'; 8801 } 8802 return resolvePathItem(result, match[1], parseInt(match[2], 10)); 8803 }, root); 8804 if (!container) { 8805 return null; 8806 } 8807 if (!isText$3(container)) { 8808 if (offset === 'after') { 8809 offset = nodeIndex(container) + 1; 8810 } else { 8811 offset = nodeIndex(container); 8812 } 8813 return CaretPosition(container.parentNode, offset); 8814 } 8815 return findTextPosition(container, parseInt(offset, 10)); 8816 }; 8817 8818 var isContentEditableFalse$9 = isContentEditableFalse$b; 8819 var getNormalizedTextOffset = function (trim, container, offset) { 8820 var node, trimmedOffset; 8821 trimmedOffset = trim(container.data.slice(0, offset)).length; 8822 for (node = container.previousSibling; node && isText$7(node); node = node.previousSibling) { 8823 trimmedOffset += trim(node.data).length; 8824 } 8825 return trimmedOffset; 8826 }; 8827 var getPoint = function (dom, trim, normalized, rng, start) { 8828 var container = rng[start ? 'startContainer' : 'endContainer']; 8829 var offset = rng[start ? 'startOffset' : 'endOffset']; 8830 var point = []; 8831 var childNodes, after = 0; 8832 var root = dom.getRoot(); 8833 if (isText$7(container)) { 8834 point.push(normalized ? getNormalizedTextOffset(trim, container, offset) : offset); 8835 } else { 8836 childNodes = container.childNodes; 8837 if (offset >= childNodes.length && childNodes.length) { 8838 after = 1; 8839 offset = Math.max(0, childNodes.length - 1); 8840 } 8841 point.push(dom.nodeIndex(childNodes[offset], normalized) + after); 8842 } 8843 for (; container && container !== root; container = container.parentNode) { 8844 point.push(dom.nodeIndex(container, normalized)); 8845 } 8846 return point; 8847 }; 8848 var getLocation = function (trim, selection, normalized, rng) { 8849 var dom = selection.dom, bookmark = {}; 8850 bookmark.start = getPoint(dom, trim, normalized, rng, true); 8851 if (!selection.isCollapsed()) { 8852 bookmark.end = getPoint(dom, trim, normalized, rng, false); 8853 } 8854 if (isRangeInCaretContainerBlock(rng)) { 8855 bookmark.isFakeCaret = true; 8856 } 8857 return bookmark; 8858 }; 8859 var findIndex = function (dom, name, element) { 8860 var count = 0; 8861 Tools.each(dom.select(name), function (node) { 8862 if (node.getAttribute('data-mce-bogus') === 'all') { 8863 return; 8864 } 8865 if (node === element) { 8866 return false; 8867 } 8868 count++; 8869 }); 8870 return count; 8871 }; 8872 var moveEndPoint$1 = function (rng, start) { 8873 var container, offset, childNodes; 8874 var prefix = start ? 'start' : 'end'; 8875 container = rng[prefix + 'Container']; 8876 offset = rng[prefix + 'Offset']; 8877 if (isElement$5(container) && container.nodeName === 'TR') { 8878 childNodes = container.childNodes; 8879 container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)]; 8880 if (container) { 8881 offset = start ? 0 : container.childNodes.length; 8882 rng['set' + (start ? 'Start' : 'End')](container, offset); 8883 } 8884 } 8885 }; 8886 var normalizeTableCellSelection = function (rng) { 8887 moveEndPoint$1(rng, true); 8888 moveEndPoint$1(rng, false); 8889 return rng; 8890 }; 8891 var findSibling = function (node, offset) { 8892 var sibling; 8893 if (isElement$5(node)) { 8894 node = getNode$1(node, offset); 8895 if (isContentEditableFalse$9(node)) { 8896 return node; 8897 } 8898 } 8899 if (isCaretContainer$2(node)) { 8900 if (isText$7(node) && isCaretContainerBlock$1(node)) { 8901 node = node.parentNode; 8902 } 8903 sibling = node.previousSibling; 8904 if (isContentEditableFalse$9(sibling)) { 8905 return sibling; 8906 } 8907 sibling = node.nextSibling; 8908 if (isContentEditableFalse$9(sibling)) { 8909 return sibling; 8910 } 8911 } 8912 }; 8913 var findAdjacentContentEditableFalseElm = function (rng) { 8914 return findSibling(rng.startContainer, rng.startOffset) || findSibling(rng.endContainer, rng.endOffset); 8915 }; 8916 var getOffsetBookmark = function (trim, normalized, selection) { 8917 var element = selection.getNode(); 8918 var name = element ? element.nodeName : null; 8919 var rng = selection.getRng(); 8920 if (isContentEditableFalse$9(element) || name === 'IMG') { 8921 return { 8922 name: name, 8923 index: findIndex(selection.dom, name, element) 8924 }; 8925 } 8926 var sibling = findAdjacentContentEditableFalseElm(rng); 8927 if (sibling) { 8928 name = sibling.tagName; 8929 return { 8930 name: name, 8931 index: findIndex(selection.dom, name, sibling) 8932 }; 8933 } 8934 return getLocation(trim, selection, normalized, rng); 8935 }; 8936 var getCaretBookmark = function (selection) { 8937 var rng = selection.getRng(); 8938 return { 8939 start: create$6(selection.dom.getRoot(), CaretPosition.fromRangeStart(rng)), 8940 end: create$6(selection.dom.getRoot(), CaretPosition.fromRangeEnd(rng)) 8941 }; 8942 }; 8943 var getRangeBookmark = function (selection) { 8944 return { rng: selection.getRng() }; 8945 }; 8946 var createBookmarkSpan = function (dom, id, filled) { 8947 var args = { 8948 'data-mce-type': 'bookmark', 8949 id: id, 8950 'style': 'overflow:hidden;line-height:0px' 8951 }; 8952 return filled ? dom.create('span', args, '') : dom.create('span', args); 8953 }; 8954 var getPersistentBookmark = function (selection, filled) { 8955 var dom = selection.dom; 8956 var rng = selection.getRng(); 8957 var id = dom.uniqueId(); 8958 var collapsed = selection.isCollapsed(); 8959 var element = selection.getNode(); 8960 var name = element.nodeName; 8961 if (name === 'IMG') { 8962 return { 8963 name: name, 8964 index: findIndex(dom, name, element) 8965 }; 8966 } 8967 var rng2 = normalizeTableCellSelection(rng.cloneRange()); 8968 if (!collapsed) { 8969 rng2.collapse(false); 8970 var endBookmarkNode = createBookmarkSpan(dom, id + '_end', filled); 8971 rangeInsertNode(dom, rng2, endBookmarkNode); 8972 } 8973 rng = normalizeTableCellSelection(rng); 8974 rng.collapse(true); 8975 var startBookmarkNode = createBookmarkSpan(dom, id + '_start', filled); 8976 rangeInsertNode(dom, rng, startBookmarkNode); 8977 selection.moveToBookmark({ 8978 id: id, 8979 keep: true 8980 }); 8981 return { id: id }; 8982 }; 8983 var getBookmark$2 = function (selection, type, normalized) { 8984 if (type === 2) { 8985 return getOffsetBookmark(trim$2, normalized, selection); 8986 } else if (type === 3) { 8987 return getCaretBookmark(selection); 8988 } else if (type) { 8989 return getRangeBookmark(selection); 8990 } else { 8991 return getPersistentBookmark(selection, false); 8992 } 8993 }; 8994 var getUndoBookmark = curry(getOffsetBookmark, identity, true); 8995 8996 var DOM$9 = DOMUtils.DOM; 8997 var defaultPreviewStyles = 'font-family font-size font-weight font-style text-decoration text-transform color background-color border border-radius outline text-shadow'; 8998 var getBodySetting = function (editor, name, defaultValue) { 8999 var value = editor.getParam(name, defaultValue); 9000 if (value.indexOf('=') !== -1) { 9001 var bodyObj = editor.getParam(name, '', 'hash'); 9002 return get$9(bodyObj, editor.id).getOr(defaultValue); 9003 } else { 9004 return value; 9005 } 9006 }; 9007 var getIframeAttrs = function (editor) { 9008 return editor.getParam('iframe_attrs', {}); 9009 }; 9010 var getDocType = function (editor) { 9011 return editor.getParam('doctype', '<!DOCTYPE html>'); 9012 }; 9013 var getDocumentBaseUrl = function (editor) { 9014 return editor.getParam('document_base_url', ''); 9015 }; 9016 var getBodyId = function (editor) { 9017 return getBodySetting(editor, 'body_id', 'tinymce'); 9018 }; 9019 var getBodyClass = function (editor) { 9020 return getBodySetting(editor, 'body_class', ''); 9021 }; 9022 var getContentSecurityPolicy = function (editor) { 9023 return editor.getParam('content_security_policy', ''); 9024 }; 9025 var shouldPutBrInPre$1 = function (editor) { 9026 return editor.getParam('br_in_pre', true); 9027 }; 9028 var getForcedRootBlock = function (editor) { 9029 if (editor.getParam('force_p_newlines', false)) { 9030 return 'p'; 9031 } 9032 var block = editor.getParam('forced_root_block', 'p'); 9033 if (block === false) { 9034 return ''; 9035 } else if (block === true) { 9036 return 'p'; 9037 } else { 9038 return block; 9039 } 9040 }; 9041 var getForcedRootBlockAttrs = function (editor) { 9042 return editor.getParam('forced_root_block_attrs', {}); 9043 }; 9044 var getBrNewLineSelector = function (editor) { 9045 return editor.getParam('br_newline_selector', '.mce-toc h2,figcaption,caption'); 9046 }; 9047 var getNoNewLineSelector = function (editor) { 9048 return editor.getParam('no_newline_selector', ''); 9049 }; 9050 var shouldKeepStyles = function (editor) { 9051 return editor.getParam('keep_styles', true); 9052 }; 9053 var shouldEndContainerOnEmptyBlock = function (editor) { 9054 return editor.getParam('end_container_on_empty_block', false); 9055 }; 9056 var getFontStyleValues = function (editor) { 9057 return Tools.explode(editor.getParam('font_size_style_values', 'xx-small,x-small,small,medium,large,x-large,xx-large')); 9058 }; 9059 var getFontSizeClasses = function (editor) { 9060 return Tools.explode(editor.getParam('font_size_classes', '')); 9061 }; 9062 var getImagesDataImgFilter = function (editor) { 9063 return editor.getParam('images_dataimg_filter', always, 'function'); 9064 }; 9065 var isAutomaticUploadsEnabled = function (editor) { 9066 return editor.getParam('automatic_uploads', true, 'boolean'); 9067 }; 9068 var shouldReuseFileName = function (editor) { 9069 return editor.getParam('images_reuse_filename', false, 'boolean'); 9070 }; 9071 var shouldReplaceBlobUris = function (editor) { 9072 return editor.getParam('images_replace_blob_uris', true, 'boolean'); 9073 }; 9074 var getIconPackName = function (editor) { 9075 return editor.getParam('icons', '', 'string'); 9076 }; 9077 var getIconsUrl = function (editor) { 9078 return editor.getParam('icons_url', '', 'string'); 9079 }; 9080 var getImageUploadUrl = function (editor) { 9081 return editor.getParam('images_upload_url', '', 'string'); 9082 }; 9083 var getImageUploadBasePath = function (editor) { 9084 return editor.getParam('images_upload_base_path', '', 'string'); 9085 }; 9086 var getImagesUploadCredentials = function (editor) { 9087 return editor.getParam('images_upload_credentials', false, 'boolean'); 9088 }; 9089 var getImagesUploadHandler = function (editor) { 9090 return editor.getParam('images_upload_handler', null, 'function'); 9091 }; 9092 var shouldUseContentCssCors = function (editor) { 9093 return editor.getParam('content_css_cors', false, 'boolean'); 9094 }; 9095 var getReferrerPolicy = function (editor) { 9096 return editor.getParam('referrer_policy', '', 'string'); 9097 }; 9098 var getLanguageCode = function (editor) { 9099 return editor.getParam('language', 'en', 'string'); 9100 }; 9101 var getLanguageUrl = function (editor) { 9102 return editor.getParam('language_url', '', 'string'); 9103 }; 9104 var shouldIndentUseMargin = function (editor) { 9105 return editor.getParam('indent_use_margin', false); 9106 }; 9107 var getIndentation = function (editor) { 9108 return editor.getParam('indentation', '40px', 'string'); 9109 }; 9110 var getContentCss = function (editor) { 9111 var contentCss = editor.getParam('content_css'); 9112 if (isString$1(contentCss)) { 9113 return map$3(contentCss.split(','), trim$4); 9114 } else if (isArray$1(contentCss)) { 9115 return contentCss; 9116 } else if (contentCss === false || editor.inline) { 9117 return []; 9118 } else { 9119 return ['default']; 9120 } 9121 }; 9122 var getFontCss = function (editor) { 9123 var fontCss = editor.getParam('font_css', []); 9124 return isArray$1(fontCss) ? fontCss : map$3(fontCss.split(','), trim$4); 9125 }; 9126 var getDirectionality = function (editor) { 9127 return editor.getParam('directionality', I18n.isRtl() ? 'rtl' : undefined); 9128 }; 9129 var getInlineBoundarySelector = function (editor) { 9130 return editor.getParam('inline_boundaries_selector', 'a[href],code,.mce-annotation', 'string'); 9131 }; 9132 var getObjectResizing = function (editor) { 9133 var selector = editor.getParam('object_resizing'); 9134 if (selector === false || Env.iOS) { 9135 return false; 9136 } else { 9137 return isString$1(selector) ? selector : 'table,img,figure.image,div,video,iframe'; 9138 } 9139 }; 9140 var getResizeImgProportional = function (editor) { 9141 return editor.getParam('resize_img_proportional', true, 'boolean'); 9142 }; 9143 var getPlaceholder = function (editor) { 9144 return editor.getParam('placeholder', DOM$9.getAttrib(editor.getElement(), 'placeholder'), 'string'); 9145 }; 9146 var getEventRoot = function (editor) { 9147 return editor.getParam('event_root'); 9148 }; 9149 var getServiceMessage = function (editor) { 9150 return editor.getParam('service_message'); 9151 }; 9152 var getTheme = function (editor) { 9153 return editor.getParam('theme'); 9154 }; 9155 var shouldValidate = function (editor) { 9156 return editor.getParam('validate'); 9157 }; 9158 var isInlineBoundariesEnabled = function (editor) { 9159 return editor.getParam('inline_boundaries') !== false; 9160 }; 9161 var getFormats = function (editor) { 9162 return editor.getParam('formats'); 9163 }; 9164 var getPreviewStyles = function (editor) { 9165 var style = editor.getParam('preview_styles', defaultPreviewStyles); 9166 if (isString$1(style)) { 9167 return style; 9168 } else { 9169 return ''; 9170 } 9171 }; 9172 var canFormatEmptyLines = function (editor) { 9173 return editor.getParam('format_empty_lines', false, 'boolean'); 9174 }; 9175 var getCustomUiSelector = function (editor) { 9176 return editor.getParam('custom_ui_selector', '', 'string'); 9177 }; 9178 var getThemeUrl = function (editor) { 9179 return editor.getParam('theme_url'); 9180 }; 9181 var isInline = function (editor) { 9182 return editor.getParam('inline'); 9183 }; 9184 var hasHiddenInput = function (editor) { 9185 return editor.getParam('hidden_input'); 9186 }; 9187 var shouldPatchSubmit = function (editor) { 9188 return editor.getParam('submit_patch'); 9189 }; 9190 var isEncodingXml = function (editor) { 9191 return editor.getParam('encoding') === 'xml'; 9192 }; 9193 var shouldAddFormSubmitTrigger = function (editor) { 9194 return editor.getParam('add_form_submit_trigger'); 9195 }; 9196 var shouldAddUnloadTrigger = function (editor) { 9197 return editor.getParam('add_unload_trigger'); 9198 }; 9199 var hasForcedRootBlock = function (editor) { 9200 return getForcedRootBlock(editor) !== ''; 9201 }; 9202 var getCustomUndoRedoLevels = function (editor) { 9203 return editor.getParam('custom_undo_redo_levels', 0, 'number'); 9204 }; 9205 var shouldDisableNodeChange = function (editor) { 9206 return editor.getParam('disable_nodechange'); 9207 }; 9208 var isReadOnly$1 = function (editor) { 9209 return editor.getParam('readonly'); 9210 }; 9211 var hasContentCssCors = function (editor) { 9212 return editor.getParam('content_css_cors'); 9213 }; 9214 var getPlugins = function (editor) { 9215 return editor.getParam('plugins', '', 'string'); 9216 }; 9217 var getExternalPlugins$1 = function (editor) { 9218 return editor.getParam('external_plugins'); 9219 }; 9220 var shouldBlockUnsupportedDrop = function (editor) { 9221 return editor.getParam('block_unsupported_drop', true, 'boolean'); 9222 }; 9223 var isVisualAidsEnabled = function (editor) { 9224 return editor.getParam('visual', true, 'boolean'); 9225 }; 9226 var getVisualAidsTableClass = function (editor) { 9227 return editor.getParam('visual_table_class', 'mce-item-table', 'string'); 9228 }; 9229 var getVisualAidsAnchorClass = function (editor) { 9230 return editor.getParam('visual_anchor_class', 'mce-item-anchor', 'string'); 9231 }; 9232 var getIframeAriaText = function (editor) { 9233 return editor.getParam('iframe_aria_text', 'Rich Text Area. Press ALT-0 for help.', 'string'); 9234 }; 9235 9236 var isElement$2 = isElement$5; 9237 var isText$2 = isText$7; 9238 var removeNode$1 = function (node) { 9239 var parentNode = node.parentNode; 9240 if (parentNode) { 9241 parentNode.removeChild(node); 9242 } 9243 }; 9244 var trimCount = function (text) { 9245 var trimmedText = trim$2(text); 9246 return { 9247 count: text.length - trimmedText.length, 9248 text: trimmedText 9249 }; 9250 }; 9251 var deleteZwspChars = function (caretContainer) { 9252 var idx; 9253 while ((idx = caretContainer.data.lastIndexOf(ZWSP$1)) !== -1) { 9254 caretContainer.deleteData(idx, 1); 9255 } 9256 }; 9257 var removeUnchanged = function (caretContainer, pos) { 9258 remove$2(caretContainer); 9259 return pos; 9260 }; 9261 var removeTextAndReposition = function (caretContainer, pos) { 9262 var before = trimCount(caretContainer.data.substr(0, pos.offset())); 9263 var after = trimCount(caretContainer.data.substr(pos.offset())); 9264 var text = before.text + after.text; 9265 if (text.length > 0) { 9266 deleteZwspChars(caretContainer); 9267 return CaretPosition(caretContainer, pos.offset() - before.count); 9268 } else { 9269 return pos; 9270 } 9271 }; 9272 var removeElementAndReposition = function (caretContainer, pos) { 9273 var parentNode = pos.container(); 9274 var newPosition = indexOf$2(from(parentNode.childNodes), caretContainer).map(function (index) { 9275 return index < pos.offset() ? CaretPosition(parentNode, pos.offset() - 1) : pos; 9276 }).getOr(pos); 9277 remove$2(caretContainer); 9278 return newPosition; 9279 }; 9280 var removeTextCaretContainer = function (caretContainer, pos) { 9281 return isText$2(caretContainer) && pos.container() === caretContainer ? removeTextAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos); 9282 }; 9283 var removeElementCaretContainer = function (caretContainer, pos) { 9284 return pos.container() === caretContainer.parentNode ? removeElementAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos); 9285 }; 9286 var removeAndReposition = function (container, pos) { 9287 return CaretPosition.isTextPosition(pos) ? removeTextCaretContainer(container, pos) : removeElementCaretContainer(container, pos); 9288 }; 9289 var remove$2 = function (caretContainerNode) { 9290 if (isElement$2(caretContainerNode) && isCaretContainer$2(caretContainerNode)) { 9291 if (hasContent(caretContainerNode)) { 9292 caretContainerNode.removeAttribute('data-mce-caret'); 9293 } else { 9294 removeNode$1(caretContainerNode); 9295 } 9296 } 9297 if (isText$2(caretContainerNode)) { 9298 deleteZwspChars(caretContainerNode); 9299 if (caretContainerNode.data.length === 0) { 9300 removeNode$1(caretContainerNode); 9301 } 9302 } 9303 }; 9304 9305 var browser$2 = detect().browser; 9306 var isContentEditableFalse$8 = isContentEditableFalse$b; 9307 var isMedia$1 = isMedia$2; 9308 var isTableCell$3 = isTableCell$5; 9309 var inlineFakeCaretSelector = '*[contentEditable=false],video,audio,embed,object'; 9310 var getAbsoluteClientRect = function (root, element, before) { 9311 var clientRect = collapse(element.getBoundingClientRect(), before); 9312 var scrollX; 9313 var scrollY; 9314 if (root.tagName === 'BODY') { 9315 var docElm = root.ownerDocument.documentElement; 9316 scrollX = root.scrollLeft || docElm.scrollLeft; 9317 scrollY = root.scrollTop || docElm.scrollTop; 9318 } else { 9319 var rootRect = root.getBoundingClientRect(); 9320 scrollX = root.scrollLeft - rootRect.left; 9321 scrollY = root.scrollTop - rootRect.top; 9322 } 9323 clientRect.left += scrollX; 9324 clientRect.right += scrollX; 9325 clientRect.top += scrollY; 9326 clientRect.bottom += scrollY; 9327 clientRect.width = 1; 9328 var margin = element.offsetWidth - element.clientWidth; 9329 if (margin > 0) { 9330 if (before) { 9331 margin *= -1; 9332 } 9333 clientRect.left += margin; 9334 clientRect.right += margin; 9335 } 9336 return clientRect; 9337 }; 9338 var trimInlineCaretContainers = function (root) { 9339 var fakeCaretTargetNodes = descendants(SugarElement.fromDom(root), inlineFakeCaretSelector); 9340 for (var i = 0; i < fakeCaretTargetNodes.length; i++) { 9341 var node = fakeCaretTargetNodes[i].dom; 9342 var sibling = node.previousSibling; 9343 if (endsWithCaretContainer$1(sibling)) { 9344 var data = sibling.data; 9345 if (data.length === 1) { 9346 sibling.parentNode.removeChild(sibling); 9347 } else { 9348 sibling.deleteData(data.length - 1, 1); 9349 } 9350 } 9351 sibling = node.nextSibling; 9352 if (startsWithCaretContainer$1(sibling)) { 9353 var data = sibling.data; 9354 if (data.length === 1) { 9355 sibling.parentNode.removeChild(sibling); 9356 } else { 9357 sibling.deleteData(0, 1); 9358 } 9359 } 9360 } 9361 }; 9362 var FakeCaret = function (editor, root, isBlock, hasFocus) { 9363 var lastVisualCaret = value(); 9364 var cursorInterval; 9365 var caretContainerNode; 9366 var rootBlock = getForcedRootBlock(editor); 9367 var caretBlock = rootBlock.length > 0 ? rootBlock : 'p'; 9368 var show = function (before, element) { 9369 var rng; 9370 hide(); 9371 if (isTableCell$3(element)) { 9372 return null; 9373 } 9374 if (isBlock(element)) { 9375 caretContainerNode = insertBlock$1(caretBlock, element, before); 9376 var clientRect = getAbsoluteClientRect(root, element, before); 9377 DomQuery(caretContainerNode).css('top', clientRect.top); 9378 var caret = DomQuery('<div class="mce-visual-caret" data-mce-bogus="all"></div>').css(__assign({}, clientRect)).appendTo(root)[0]; 9379 lastVisualCaret.set({ 9380 caret: caret, 9381 element: element, 9382 before: before 9383 }); 9384 if (before) { 9385 DomQuery(caret).addClass('mce-visual-caret-before'); 9386 } 9387 startBlink(); 9388 rng = element.ownerDocument.createRange(); 9389 rng.setStart(caretContainerNode, 0); 9390 rng.setEnd(caretContainerNode, 0); 9391 } else { 9392 caretContainerNode = insertInline$1(element, before); 9393 rng = element.ownerDocument.createRange(); 9394 if (isInlineFakeCaretTarget(caretContainerNode.nextSibling)) { 9395 rng.setStart(caretContainerNode, 0); 9396 rng.setEnd(caretContainerNode, 0); 9397 } else { 9398 rng.setStart(caretContainerNode, 1); 9399 rng.setEnd(caretContainerNode, 1); 9400 } 9401 return rng; 9402 } 9403 return rng; 9404 }; 9405 var hide = function () { 9406 trimInlineCaretContainers(root); 9407 if (caretContainerNode) { 9408 remove$2(caretContainerNode); 9409 caretContainerNode = null; 9410 } 9411 lastVisualCaret.on(function (caretState) { 9412 DomQuery(caretState.caret).remove(); 9413 lastVisualCaret.clear(); 9414 }); 9415 if (cursorInterval) { 9416 Delay.clearInterval(cursorInterval); 9417 cursorInterval = undefined; 9418 } 9419 }; 9420 var startBlink = function () { 9421 cursorInterval = Delay.setInterval(function () { 9422 if (hasFocus()) { 9423 DomQuery('div.mce-visual-caret', root).toggleClass('mce-visual-caret-hidden'); 9424 } else { 9425 DomQuery('div.mce-visual-caret', root).addClass('mce-visual-caret-hidden'); 9426 } 9427 }, 500); 9428 }; 9429 var reposition = function () { 9430 lastVisualCaret.on(function (caretState) { 9431 var clientRect = getAbsoluteClientRect(root, caretState.element, caretState.before); 9432 DomQuery(caretState.caret).css(__assign({}, clientRect)); 9433 }); 9434 }; 9435 var destroy = function () { 9436 return Delay.clearInterval(cursorInterval); 9437 }; 9438 var getCss = function () { 9439 return '.mce-visual-caret {' + 'position: absolute;' + 'background-color: black;' + 'background-color: currentcolor;' + '}' + '.mce-visual-caret-hidden {' + 'display: none;' + '}' + '*[data-mce-caret] {' + 'position: absolute;' + 'left: -1000px;' + 'right: auto;' + 'top: 0;' + 'margin: 0;' + 'padding: 0;' + '}'; 9440 }; 9441 return { 9442 show: show, 9443 hide: hide, 9444 getCss: getCss, 9445 reposition: reposition, 9446 destroy: destroy 9447 }; 9448 }; 9449 var isFakeCaretTableBrowser = function () { 9450 return browser$2.isIE() || browser$2.isEdge() || browser$2.isFirefox(); 9451 }; 9452 var isInlineFakeCaretTarget = function (node) { 9453 return isContentEditableFalse$8(node) || isMedia$1(node); 9454 }; 9455 var isFakeCaretTarget = function (node) { 9456 return isInlineFakeCaretTarget(node) || isTable$3(node) && isFakeCaretTableBrowser(); 9457 }; 9458 9459 var isContentEditableFalse$7 = isContentEditableFalse$b; 9460 var isMedia = isMedia$2; 9461 var isBlockLike = matchStyleValues('display', 'block table table-cell table-caption list-item'); 9462 var isCaretContainer = isCaretContainer$2; 9463 var isCaretContainerBlock = isCaretContainerBlock$1; 9464 var isElement$1 = isElement$5; 9465 var isCaretCandidate$1 = isCaretCandidate$3; 9466 var isForwards = function (direction) { 9467 return direction > 0; 9468 }; 9469 var isBackwards = function (direction) { 9470 return direction < 0; 9471 }; 9472 var skipCaretContainers = function (walk, shallow) { 9473 var node; 9474 while (node = walk(shallow)) { 9475 if (!isCaretContainerBlock(node)) { 9476 return node; 9477 } 9478 } 9479 return null; 9480 }; 9481 var findNode$1 = function (node, direction, predicateFn, rootNode, shallow) { 9482 var walker = new DomTreeWalker(node, rootNode); 9483 var isCefOrCaretContainer = isContentEditableFalse$7(node) || isCaretContainerBlock(node); 9484 if (isBackwards(direction)) { 9485 if (isCefOrCaretContainer) { 9486 node = skipCaretContainers(walker.prev.bind(walker), true); 9487 if (predicateFn(node)) { 9488 return node; 9489 } 9490 } 9491 while (node = skipCaretContainers(walker.prev.bind(walker), shallow)) { 9492 if (predicateFn(node)) { 9493 return node; 9494 } 9495 } 9496 } 9497 if (isForwards(direction)) { 9498 if (isCefOrCaretContainer) { 9499 node = skipCaretContainers(walker.next.bind(walker), true); 9500 if (predicateFn(node)) { 9501 return node; 9502 } 9503 } 9504 while (node = skipCaretContainers(walker.next.bind(walker), shallow)) { 9505 if (predicateFn(node)) { 9506 return node; 9507 } 9508 } 9509 } 9510 return null; 9511 }; 9512 var getParentBlock$2 = function (node, rootNode) { 9513 while (node && node !== rootNode) { 9514 if (isBlockLike(node)) { 9515 return node; 9516 } 9517 node = node.parentNode; 9518 } 9519 return null; 9520 }; 9521 var isInSameBlock = function (caretPosition1, caretPosition2, rootNode) { 9522 return getParentBlock$2(caretPosition1.container(), rootNode) === getParentBlock$2(caretPosition2.container(), rootNode); 9523 }; 9524 var getChildNodeAtRelativeOffset = function (relativeOffset, caretPosition) { 9525 if (!caretPosition) { 9526 return null; 9527 } 9528 var container = caretPosition.container(); 9529 var offset = caretPosition.offset(); 9530 if (!isElement$1(container)) { 9531 return null; 9532 } 9533 return container.childNodes[offset + relativeOffset]; 9534 }; 9535 var beforeAfter = function (before, node) { 9536 var range = node.ownerDocument.createRange(); 9537 if (before) { 9538 range.setStartBefore(node); 9539 range.setEndBefore(node); 9540 } else { 9541 range.setStartAfter(node); 9542 range.setEndAfter(node); 9543 } 9544 return range; 9545 }; 9546 var isNodesInSameBlock = function (root, node1, node2) { 9547 return getParentBlock$2(node1, root) === getParentBlock$2(node2, root); 9548 }; 9549 var lean = function (left, root, node) { 9550 var siblingName = left ? 'previousSibling' : 'nextSibling'; 9551 while (node && node !== root) { 9552 var sibling = node[siblingName]; 9553 if (isCaretContainer(sibling)) { 9554 sibling = sibling[siblingName]; 9555 } 9556 if (isContentEditableFalse$7(sibling) || isMedia(sibling)) { 9557 if (isNodesInSameBlock(root, sibling, node)) { 9558 return sibling; 9559 } 9560 break; 9561 } 9562 if (isCaretCandidate$1(sibling)) { 9563 break; 9564 } 9565 node = node.parentNode; 9566 } 9567 return null; 9568 }; 9569 var before$2 = curry(beforeAfter, true); 9570 var after$2 = curry(beforeAfter, false); 9571 var normalizeRange = function (direction, root, range) { 9572 var node; 9573 var leanLeft = curry(lean, true, root); 9574 var leanRight = curry(lean, false, root); 9575 var container = range.startContainer; 9576 var offset = range.startOffset; 9577 if (isCaretContainerBlock$1(container)) { 9578 if (!isElement$1(container)) { 9579 container = container.parentNode; 9580 } 9581 var location_1 = container.getAttribute('data-mce-caret'); 9582 if (location_1 === 'before') { 9583 node = container.nextSibling; 9584 if (isFakeCaretTarget(node)) { 9585 return before$2(node); 9586 } 9587 } 9588 if (location_1 === 'after') { 9589 node = container.previousSibling; 9590 if (isFakeCaretTarget(node)) { 9591 return after$2(node); 9592 } 9593 } 9594 } 9595 if (!range.collapsed) { 9596 return range; 9597 } 9598 if (isText$7(container)) { 9599 if (isCaretContainer(container)) { 9600 if (direction === 1) { 9601 node = leanRight(container); 9602 if (node) { 9603 return before$2(node); 9604 } 9605 node = leanLeft(container); 9606 if (node) { 9607 return after$2(node); 9608 } 9609 } 9610 if (direction === -1) { 9611 node = leanLeft(container); 9612 if (node) { 9613 return after$2(node); 9614 } 9615 node = leanRight(container); 9616 if (node) { 9617 return before$2(node); 9618 } 9619 } 9620 return range; 9621 } 9622 if (endsWithCaretContainer$1(container) && offset >= container.data.length - 1) { 9623 if (direction === 1) { 9624 node = leanRight(container); 9625 if (node) { 9626 return before$2(node); 9627 } 9628 } 9629 return range; 9630 } 9631 if (startsWithCaretContainer$1(container) && offset <= 1) { 9632 if (direction === -1) { 9633 node = leanLeft(container); 9634 if (node) { 9635 return after$2(node); 9636 } 9637 } 9638 return range; 9639 } 9640 if (offset === container.data.length) { 9641 node = leanRight(container); 9642 if (node) { 9643 return before$2(node); 9644 } 9645 return range; 9646 } 9647 if (offset === 0) { 9648 node = leanLeft(container); 9649 if (node) { 9650 return after$2(node); 9651 } 9652 return range; 9653 } 9654 } 9655 return range; 9656 }; 9657 var getRelativeCefElm = function (forward, caretPosition) { 9658 return Optional.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, caretPosition)).filter(isContentEditableFalse$7); 9659 }; 9660 var getNormalizedRangeEndPoint = function (direction, root, range) { 9661 var normalizedRange = normalizeRange(direction, root, range); 9662 if (direction === -1) { 9663 return CaretPosition.fromRangeStart(normalizedRange); 9664 } 9665 return CaretPosition.fromRangeEnd(normalizedRange); 9666 }; 9667 var getElementFromPosition = function (pos) { 9668 return Optional.from(pos.getNode()).map(SugarElement.fromDom); 9669 }; 9670 var getElementFromPrevPosition = function (pos) { 9671 return Optional.from(pos.getNode(true)).map(SugarElement.fromDom); 9672 }; 9673 var getVisualCaretPosition = function (walkFn, caretPosition) { 9674 while (caretPosition = walkFn(caretPosition)) { 9675 if (caretPosition.isVisible()) { 9676 return caretPosition; 9677 } 9678 } 9679 return caretPosition; 9680 }; 9681 var isMoveInsideSameBlock = function (from, to) { 9682 var inSameBlock = isInSameBlock(from, to); 9683 if (!inSameBlock && isBr$5(from.getNode())) { 9684 return true; 9685 } 9686 return inSameBlock; 9687 }; 9688 9689 var HDirection; 9690 (function (HDirection) { 9691 HDirection[HDirection['Backwards'] = -1] = 'Backwards'; 9692 HDirection[HDirection['Forwards'] = 1] = 'Forwards'; 9693 }(HDirection || (HDirection = {}))); 9694 var isContentEditableFalse$6 = isContentEditableFalse$b; 9695 var isText$1 = isText$7; 9696 var isElement = isElement$5; 9697 var isBr$1 = isBr$5; 9698 var isCaretCandidate = isCaretCandidate$3; 9699 var isAtomic = isAtomic$1; 9700 var isEditableCaretCandidate = isEditableCaretCandidate$1; 9701 var getParents$3 = function (node, root) { 9702 var parents = []; 9703 while (node && node !== root) { 9704 parents.push(node); 9705 node = node.parentNode; 9706 } 9707 return parents; 9708 }; 9709 var nodeAtIndex = function (container, offset) { 9710 if (container.hasChildNodes() && offset < container.childNodes.length) { 9711 return container.childNodes[offset]; 9712 } 9713 return null; 9714 }; 9715 var getCaretCandidatePosition = function (direction, node) { 9716 if (isForwards(direction)) { 9717 if (isCaretCandidate(node.previousSibling) && !isText$1(node.previousSibling)) { 9718 return CaretPosition.before(node); 9719 } 9720 if (isText$1(node)) { 9721 return CaretPosition(node, 0); 9722 } 9723 } 9724 if (isBackwards(direction)) { 9725 if (isCaretCandidate(node.nextSibling) && !isText$1(node.nextSibling)) { 9726 return CaretPosition.after(node); 9727 } 9728 if (isText$1(node)) { 9729 return CaretPosition(node, node.data.length); 9730 } 9731 } 9732 if (isBackwards(direction)) { 9733 if (isBr$1(node)) { 9734 return CaretPosition.before(node); 9735 } 9736 return CaretPosition.after(node); 9737 } 9738 return CaretPosition.before(node); 9739 }; 9740 var moveForwardFromBr = function (root, nextNode) { 9741 var nextSibling = nextNode.nextSibling; 9742 if (nextSibling && isCaretCandidate(nextSibling)) { 9743 if (isText$1(nextSibling)) { 9744 return CaretPosition(nextSibling, 0); 9745 } else { 9746 return CaretPosition.before(nextSibling); 9747 } 9748 } else { 9749 return findCaretPosition$1(HDirection.Forwards, CaretPosition.after(nextNode), root); 9750 } 9751 }; 9752 var findCaretPosition$1 = function (direction, startPos, root) { 9753 var node; 9754 var nextNode; 9755 var innerNode; 9756 var caretPosition; 9757 if (!isElement(root) || !startPos) { 9758 return null; 9759 } 9760 if (startPos.isEqual(CaretPosition.after(root)) && root.lastChild) { 9761 caretPosition = CaretPosition.after(root.lastChild); 9762 if (isBackwards(direction) && isCaretCandidate(root.lastChild) && isElement(root.lastChild)) { 9763 return isBr$1(root.lastChild) ? CaretPosition.before(root.lastChild) : caretPosition; 9764 } 9765 } else { 9766 caretPosition = startPos; 9767 } 9768 var container = caretPosition.container(); 9769 var offset = caretPosition.offset(); 9770 if (isText$1(container)) { 9771 if (isBackwards(direction) && offset > 0) { 9772 return CaretPosition(container, --offset); 9773 } 9774 if (isForwards(direction) && offset < container.length) { 9775 return CaretPosition(container, ++offset); 9776 } 9777 node = container; 9778 } else { 9779 if (isBackwards(direction) && offset > 0) { 9780 nextNode = nodeAtIndex(container, offset - 1); 9781 if (isCaretCandidate(nextNode)) { 9782 if (!isAtomic(nextNode)) { 9783 innerNode = findNode$1(nextNode, direction, isEditableCaretCandidate, nextNode); 9784 if (innerNode) { 9785 if (isText$1(innerNode)) { 9786 return CaretPosition(innerNode, innerNode.data.length); 9787 } 9788 return CaretPosition.after(innerNode); 9789 } 9790 } 9791 if (isText$1(nextNode)) { 9792 return CaretPosition(nextNode, nextNode.data.length); 9793 } 9794 return CaretPosition.before(nextNode); 9795 } 9796 } 9797 if (isForwards(direction) && offset < container.childNodes.length) { 9798 nextNode = nodeAtIndex(container, offset); 9799 if (isCaretCandidate(nextNode)) { 9800 if (isBr$1(nextNode)) { 9801 return moveForwardFromBr(root, nextNode); 9802 } 9803 if (!isAtomic(nextNode)) { 9804 innerNode = findNode$1(nextNode, direction, isEditableCaretCandidate, nextNode); 9805 if (innerNode) { 9806 if (isText$1(innerNode)) { 9807 return CaretPosition(innerNode, 0); 9808 } 9809 return CaretPosition.before(innerNode); 9810 } 9811 } 9812 if (isText$1(nextNode)) { 9813 return CaretPosition(nextNode, 0); 9814 } 9815 return CaretPosition.after(nextNode); 9816 } 9817 } 9818 node = nextNode ? nextNode : caretPosition.getNode(); 9819 } 9820 if (isForwards(direction) && caretPosition.isAtEnd() || isBackwards(direction) && caretPosition.isAtStart()) { 9821 node = findNode$1(node, direction, always, root, true); 9822 if (isEditableCaretCandidate(node, root)) { 9823 return getCaretCandidatePosition(direction, node); 9824 } 9825 } 9826 nextNode = findNode$1(node, direction, isEditableCaretCandidate, root); 9827 var rootContentEditableFalseElm = last$1(filter$4(getParents$3(container, root), isContentEditableFalse$6)); 9828 if (rootContentEditableFalseElm && (!nextNode || !rootContentEditableFalseElm.contains(nextNode))) { 9829 if (isForwards(direction)) { 9830 caretPosition = CaretPosition.after(rootContentEditableFalseElm); 9831 } else { 9832 caretPosition = CaretPosition.before(rootContentEditableFalseElm); 9833 } 9834 return caretPosition; 9835 } 9836 if (nextNode) { 9837 return getCaretCandidatePosition(direction, nextNode); 9838 } 9839 return null; 9840 }; 9841 var CaretWalker = function (root) { 9842 return { 9843 next: function (caretPosition) { 9844 return findCaretPosition$1(HDirection.Forwards, caretPosition, root); 9845 }, 9846 prev: function (caretPosition) { 9847 return findCaretPosition$1(HDirection.Backwards, caretPosition, root); 9848 } 9849 }; 9850 }; 9851 9852 var walkToPositionIn = function (forward, root, start) { 9853 var position = forward ? CaretPosition.before(start) : CaretPosition.after(start); 9854 return fromPosition(forward, root, position); 9855 }; 9856 var afterElement = function (node) { 9857 return isBr$5(node) ? CaretPosition.before(node) : CaretPosition.after(node); 9858 }; 9859 var isBeforeOrStart = function (position) { 9860 if (CaretPosition.isTextPosition(position)) { 9861 return position.offset() === 0; 9862 } else { 9863 return isCaretCandidate$3(position.getNode()); 9864 } 9865 }; 9866 var isAfterOrEnd = function (position) { 9867 if (CaretPosition.isTextPosition(position)) { 9868 var container = position.container(); 9869 return position.offset() === container.data.length; 9870 } else { 9871 return isCaretCandidate$3(position.getNode(true)); 9872 } 9873 }; 9874 var isBeforeAfterSameElement = function (from, to) { 9875 return !CaretPosition.isTextPosition(from) && !CaretPosition.isTextPosition(to) && from.getNode() === to.getNode(true); 9876 }; 9877 var isAtBr = function (position) { 9878 return !CaretPosition.isTextPosition(position) && isBr$5(position.getNode()); 9879 }; 9880 var shouldSkipPosition = function (forward, from, to) { 9881 if (forward) { 9882 return !isBeforeAfterSameElement(from, to) && !isAtBr(from) && isAfterOrEnd(from) && isBeforeOrStart(to); 9883 } else { 9884 return !isBeforeAfterSameElement(to, from) && isBeforeOrStart(from) && isAfterOrEnd(to); 9885 } 9886 }; 9887 var fromPosition = function (forward, root, pos) { 9888 var walker = CaretWalker(root); 9889 return Optional.from(forward ? walker.next(pos) : walker.prev(pos)); 9890 }; 9891 var navigate = function (forward, root, from) { 9892 return fromPosition(forward, root, from).bind(function (to) { 9893 if (isInSameBlock(from, to, root) && shouldSkipPosition(forward, from, to)) { 9894 return fromPosition(forward, root, to); 9895 } else { 9896 return Optional.some(to); 9897 } 9898 }); 9899 }; 9900 var navigateIgnore = function (forward, root, from, ignoreFilter) { 9901 return navigate(forward, root, from).bind(function (pos) { 9902 return ignoreFilter(pos) ? navigateIgnore(forward, root, pos, ignoreFilter) : Optional.some(pos); 9903 }); 9904 }; 9905 var positionIn = function (forward, element) { 9906 var startNode = forward ? element.firstChild : element.lastChild; 9907 if (isText$7(startNode)) { 9908 return Optional.some(CaretPosition(startNode, forward ? 0 : startNode.data.length)); 9909 } else if (startNode) { 9910 if (isCaretCandidate$3(startNode)) { 9911 return Optional.some(forward ? CaretPosition.before(startNode) : afterElement(startNode)); 9912 } else { 9913 return walkToPositionIn(forward, element, startNode); 9914 } 9915 } else { 9916 return Optional.none(); 9917 } 9918 }; 9919 var nextPosition = curry(fromPosition, true); 9920 var prevPosition = curry(fromPosition, false); 9921 var firstPositionIn = curry(positionIn, true); 9922 var lastPositionIn = curry(positionIn, false); 9923 9924 var CARET_ID$1 = '_mce_caret'; 9925 var isCaretNode = function (node) { 9926 return isElement$5(node) && node.id === CARET_ID$1; 9927 }; 9928 var getParentCaretContainer = function (body, node) { 9929 while (node && node !== body) { 9930 if (node.id === CARET_ID$1) { 9931 return node; 9932 } 9933 node = node.parentNode; 9934 } 9935 return null; 9936 }; 9937 9938 var isStringPathBookmark = function (bookmark) { 9939 return isString$1(bookmark.start); 9940 }; 9941 var isRangeBookmark = function (bookmark) { 9942 return has$2(bookmark, 'rng'); 9943 }; 9944 var isIdBookmark = function (bookmark) { 9945 return has$2(bookmark, 'id'); 9946 }; 9947 var isIndexBookmark = function (bookmark) { 9948 return has$2(bookmark, 'name'); 9949 }; 9950 var isPathBookmark = function (bookmark) { 9951 return Tools.isArray(bookmark.start); 9952 }; 9953 9954 var addBogus = function (dom, node) { 9955 if (isElement$5(node) && dom.isBlock(node) && !node.innerHTML && !Env.ie) { 9956 node.innerHTML = '<br data-mce-bogus="1" />'; 9957 } 9958 return node; 9959 }; 9960 var resolveCaretPositionBookmark = function (dom, bookmark) { 9961 var pos; 9962 var rng = dom.createRng(); 9963 pos = resolve$2(dom.getRoot(), bookmark.start); 9964 rng.setStart(pos.container(), pos.offset()); 9965 pos = resolve$2(dom.getRoot(), bookmark.end); 9966 rng.setEnd(pos.container(), pos.offset()); 9967 return rng; 9968 }; 9969 var insertZwsp = function (node, rng) { 9970 var textNode = node.ownerDocument.createTextNode(ZWSP$1); 9971 node.appendChild(textNode); 9972 rng.setStart(textNode, 0); 9973 rng.setEnd(textNode, 0); 9974 }; 9975 var isEmpty$1 = function (node) { 9976 return node.hasChildNodes() === false; 9977 }; 9978 var tryFindRangePosition = function (node, rng) { 9979 return lastPositionIn(node).fold(never, function (pos) { 9980 rng.setStart(pos.container(), pos.offset()); 9981 rng.setEnd(pos.container(), pos.offset()); 9982 return true; 9983 }); 9984 }; 9985 var padEmptyCaretContainer = function (root, node, rng) { 9986 if (isEmpty$1(node) && getParentCaretContainer(root, node)) { 9987 insertZwsp(node, rng); 9988 return true; 9989 } else { 9990 return false; 9991 } 9992 }; 9993 var setEndPoint = function (dom, start, bookmark, rng) { 9994 var point = bookmark[start ? 'start' : 'end']; 9995 var i, node, offset, children; 9996 var root = dom.getRoot(); 9997 if (point) { 9998 offset = point[0]; 9999 for (node = root, i = point.length - 1; i >= 1; i--) { 10000 children = node.childNodes; 10001 if (padEmptyCaretContainer(root, node, rng)) { 10002 return true; 10003 } 10004 if (point[i] > children.length - 1) { 10005 if (padEmptyCaretContainer(root, node, rng)) { 10006 return true; 10007 } 10008 return tryFindRangePosition(node, rng); 10009 } 10010 node = children[point[i]]; 10011 } 10012 if (node.nodeType === 3) { 10013 offset = Math.min(point[0], node.nodeValue.length); 10014 } 10015 if (node.nodeType === 1) { 10016 offset = Math.min(point[0], node.childNodes.length); 10017 } 10018 if (start) { 10019 rng.setStart(node, offset); 10020 } else { 10021 rng.setEnd(node, offset); 10022 } 10023 } 10024 return true; 10025 }; 10026 var isValidTextNode = function (node) { 10027 return isText$7(node) && node.data.length > 0; 10028 }; 10029 var restoreEndPoint = function (dom, suffix, bookmark) { 10030 var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev; 10031 var keep = bookmark.keep; 10032 var container, offset; 10033 if (marker) { 10034 node = marker.parentNode; 10035 if (suffix === 'start') { 10036 if (!keep) { 10037 idx = dom.nodeIndex(marker); 10038 } else { 10039 if (marker.hasChildNodes()) { 10040 node = marker.firstChild; 10041 idx = 1; 10042 } else if (isValidTextNode(marker.nextSibling)) { 10043 node = marker.nextSibling; 10044 idx = 0; 10045 } else if (isValidTextNode(marker.previousSibling)) { 10046 node = marker.previousSibling; 10047 idx = marker.previousSibling.data.length; 10048 } else { 10049 node = marker.parentNode; 10050 idx = dom.nodeIndex(marker) + 1; 10051 } 10052 } 10053 container = node; 10054 offset = idx; 10055 } else { 10056 if (!keep) { 10057 idx = dom.nodeIndex(marker); 10058 } else { 10059 if (marker.hasChildNodes()) { 10060 node = marker.firstChild; 10061 idx = 1; 10062 } else if (isValidTextNode(marker.previousSibling)) { 10063 node = marker.previousSibling; 10064 idx = marker.previousSibling.data.length; 10065 } else { 10066 node = marker.parentNode; 10067 idx = dom.nodeIndex(marker); 10068 } 10069 } 10070 container = node; 10071 offset = idx; 10072 } 10073 if (!keep) { 10074 prev = marker.previousSibling; 10075 next = marker.nextSibling; 10076 Tools.each(Tools.grep(marker.childNodes), function (node) { 10077 if (isText$7(node)) { 10078 node.nodeValue = node.nodeValue.replace(/\uFEFF/g, ''); 10079 } 10080 }); 10081 while (marker = dom.get(bookmark.id + '_' + suffix)) { 10082 dom.remove(marker, true); 10083 } 10084 if (prev && next && prev.nodeType === next.nodeType && isText$7(prev) && !Env.opera) { 10085 idx = prev.nodeValue.length; 10086 prev.appendData(next.nodeValue); 10087 dom.remove(next); 10088 container = prev; 10089 offset = idx; 10090 } 10091 } 10092 return Optional.some(CaretPosition(container, offset)); 10093 } else { 10094 return Optional.none(); 10095 } 10096 }; 10097 var resolvePaths = function (dom, bookmark) { 10098 var rng = dom.createRng(); 10099 if (setEndPoint(dom, true, bookmark, rng) && setEndPoint(dom, false, bookmark, rng)) { 10100 return Optional.some(rng); 10101 } else { 10102 return Optional.none(); 10103 } 10104 }; 10105 var resolveId = function (dom, bookmark) { 10106 var startPos = restoreEndPoint(dom, 'start', bookmark); 10107 var endPos = restoreEndPoint(dom, 'end', bookmark); 10108 return lift2(startPos, endPos.or(startPos), function (spos, epos) { 10109 var rng = dom.createRng(); 10110 rng.setStart(addBogus(dom, spos.container()), spos.offset()); 10111 rng.setEnd(addBogus(dom, epos.container()), epos.offset()); 10112 return rng; 10113 }); 10114 }; 10115 var resolveIndex = function (dom, bookmark) { 10116 return Optional.from(dom.select(bookmark.name)[bookmark.index]).map(function (elm) { 10117 var rng = dom.createRng(); 10118 rng.selectNode(elm); 10119 return rng; 10120 }); 10121 }; 10122 var resolve$1 = function (selection, bookmark) { 10123 var dom = selection.dom; 10124 if (bookmark) { 10125 if (isPathBookmark(bookmark)) { 10126 return resolvePaths(dom, bookmark); 10127 } else if (isStringPathBookmark(bookmark)) { 10128 return Optional.some(resolveCaretPositionBookmark(dom, bookmark)); 10129 } else if (isIdBookmark(bookmark)) { 10130 return resolveId(dom, bookmark); 10131 } else if (isIndexBookmark(bookmark)) { 10132 return resolveIndex(dom, bookmark); 10133 } else if (isRangeBookmark(bookmark)) { 10134 return Optional.some(bookmark.rng); 10135 } 10136 } 10137 return Optional.none(); 10138 }; 10139 10140 var getBookmark$1 = function (selection, type, normalized) { 10141 return getBookmark$2(selection, type, normalized); 10142 }; 10143 var moveToBookmark = function (selection, bookmark) { 10144 resolve$1(selection, bookmark).each(function (rng) { 10145 selection.setRng(rng); 10146 }); 10147 }; 10148 var isBookmarkNode$1 = function (node) { 10149 return isElement$5(node) && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark'; 10150 }; 10151 10152 var is = function (expected) { 10153 return function (actual) { 10154 return expected === actual; 10155 }; 10156 }; 10157 var isNbsp = is(nbsp); 10158 var isWhiteSpace = function (chr) { 10159 return chr !== '' && ' \f\n\r\t\x0B'.indexOf(chr) !== -1; 10160 }; 10161 var isContent = function (chr) { 10162 return !isWhiteSpace(chr) && !isNbsp(chr); 10163 }; 10164 10165 var isNode = function (node) { 10166 return !!node.nodeType; 10167 }; 10168 var isInlineBlock = function (node) { 10169 return node && /^(IMG)$/.test(node.nodeName); 10170 }; 10171 var moveStart = function (dom, selection, rng) { 10172 var offset = rng.startOffset; 10173 var container = rng.startContainer; 10174 if (container === rng.endContainer) { 10175 if (isInlineBlock(container.childNodes[offset])) { 10176 return; 10177 } 10178 } 10179 if (isElement$5(container)) { 10180 var nodes = container.childNodes; 10181 var walker = void 0; 10182 if (offset < nodes.length) { 10183 container = nodes[offset]; 10184 walker = new DomTreeWalker(container, dom.getParent(container, dom.isBlock)); 10185 } else { 10186 container = nodes[nodes.length - 1]; 10187 walker = new DomTreeWalker(container, dom.getParent(container, dom.isBlock)); 10188 walker.next(true); 10189 } 10190 for (var node = walker.current(); node; node = walker.next()) { 10191 if (isText$7(node) && !isWhiteSpaceNode$1(node)) { 10192 rng.setStart(node, 0); 10193 selection.setRng(rng); 10194 return; 10195 } 10196 } 10197 } 10198 }; 10199 var getNonWhiteSpaceSibling = function (node, next, inc) { 10200 if (node) { 10201 var nextName = next ? 'nextSibling' : 'previousSibling'; 10202 for (node = inc ? node : node[nextName]; node; node = node[nextName]) { 10203 if (isElement$5(node) || !isWhiteSpaceNode$1(node)) { 10204 return node; 10205 } 10206 } 10207 } 10208 }; 10209 var isTextBlock$1 = function (editor, name) { 10210 if (isNode(name)) { 10211 name = name.nodeName; 10212 } 10213 return !!editor.schema.getTextBlockElements()[name.toLowerCase()]; 10214 }; 10215 var isValid = function (ed, parent, child) { 10216 return ed.schema.isValidChild(parent, child); 10217 }; 10218 var isWhiteSpaceNode$1 = function (node, allowSpaces) { 10219 if (allowSpaces === void 0) { 10220 allowSpaces = false; 10221 } 10222 if (isNonNullable(node) && isText$7(node)) { 10223 var data = allowSpaces ? node.data.replace(/ /g, '\xA0') : node.data; 10224 return isWhitespaceText(data); 10225 } else { 10226 return false; 10227 } 10228 }; 10229 var isEmptyTextNode$1 = function (node) { 10230 return isNonNullable(node) && isText$7(node) && node.length === 0; 10231 }; 10232 var replaceVars = function (value, vars) { 10233 if (isFunction(value)) { 10234 value = value(vars); 10235 } else if (isNonNullable(vars)) { 10236 value = value.replace(/%(\w+)/g, function (str, name) { 10237 return vars[name] || str; 10238 }); 10239 } 10240 return value; 10241 }; 10242 var isEq$5 = function (str1, str2) { 10243 str1 = str1 || ''; 10244 str2 = str2 || ''; 10245 str1 = '' + (str1.nodeName || str1); 10246 str2 = '' + (str2.nodeName || str2); 10247 return str1.toLowerCase() === str2.toLowerCase(); 10248 }; 10249 var normalizeStyleValue = function (dom, value, name) { 10250 if (name === 'color' || name === 'backgroundColor') { 10251 value = dom.toHex(value); 10252 } 10253 if (name === 'fontWeight' && value === 700) { 10254 value = 'bold'; 10255 } 10256 if (name === 'fontFamily') { 10257 value = value.replace(/[\'\"]/g, '').replace(/,\s+/g, ','); 10258 } 10259 return '' + value; 10260 }; 10261 var getStyle = function (dom, node, name) { 10262 return normalizeStyleValue(dom, dom.getStyle(node, name), name); 10263 }; 10264 var getTextDecoration = function (dom, node) { 10265 var decoration; 10266 dom.getParent(node, function (n) { 10267 decoration = dom.getStyle(n, 'text-decoration'); 10268 return decoration && decoration !== 'none'; 10269 }); 10270 return decoration; 10271 }; 10272 var getParents$2 = function (dom, node, selector) { 10273 return dom.getParents(node, selector, dom.getRoot()); 10274 }; 10275 var isVariableFormatName = function (editor, formatName) { 10276 var hasVariableValues = function (format) { 10277 var isVariableValue = function (val) { 10278 return val.length > 1 && val.charAt(0) === '%'; 10279 }; 10280 return exists([ 10281 'styles', 10282 'attributes' 10283 ], function (key) { 10284 return get$9(format, key).exists(function (field) { 10285 var fieldValues = isArray$1(field) ? field : values(field); 10286 return exists(fieldValues, isVariableValue); 10287 }); 10288 }); 10289 }; 10290 return exists(editor.formatter.get(formatName), hasVariableValues); 10291 }; 10292 var areSimilarFormats = function (editor, formatName, otherFormatName) { 10293 var validKeys = [ 10294 'inline', 10295 'block', 10296 'selector', 10297 'attributes', 10298 'styles', 10299 'classes' 10300 ]; 10301 var filterObj = function (format) { 10302 return filter$3(format, function (_, key) { 10303 return exists(validKeys, function (validKey) { 10304 return validKey === key; 10305 }); 10306 }); 10307 }; 10308 return exists(editor.formatter.get(formatName), function (fmt1) { 10309 var filteredFmt1 = filterObj(fmt1); 10310 return exists(editor.formatter.get(otherFormatName), function (fmt2) { 10311 var filteredFmt2 = filterObj(fmt2); 10312 return equal$1(filteredFmt1, filteredFmt2); 10313 }); 10314 }); 10315 }; 10316 var isBlockFormat = function (format) { 10317 return hasNonNullableKey(format, 'block'); 10318 }; 10319 var isSelectorFormat = function (format) { 10320 return hasNonNullableKey(format, 'selector'); 10321 }; 10322 var isInlineFormat = function (format) { 10323 return hasNonNullableKey(format, 'inline'); 10324 }; 10325 var isMixedFormat = function (format) { 10326 return isSelectorFormat(format) && isInlineFormat(format) && is$1(get$9(format, 'mixed'), true); 10327 }; 10328 var shouldExpandToSelector = function (format) { 10329 return isSelectorFormat(format) && format.expand !== false && !isInlineFormat(format); 10330 }; 10331 10332 var isBookmarkNode = isBookmarkNode$1; 10333 var getParents$1 = getParents$2; 10334 var isWhiteSpaceNode = isWhiteSpaceNode$1; 10335 var isTextBlock = isTextBlock$1; 10336 var isBogusBr = function (node) { 10337 return isBr$5(node) && node.getAttribute('data-mce-bogus') && !node.nextSibling; 10338 }; 10339 var findParentContentEditable = function (dom, node) { 10340 var parent = node; 10341 while (parent) { 10342 if (isElement$5(parent) && dom.getContentEditable(parent)) { 10343 return dom.getContentEditable(parent) === 'false' ? parent : node; 10344 } 10345 parent = parent.parentNode; 10346 } 10347 return node; 10348 }; 10349 var walkText = function (start, node, offset, predicate) { 10350 var str = node.data; 10351 for (var i = offset; start ? i >= 0 : i < str.length; start ? i-- : i++) { 10352 if (predicate(str.charAt(i))) { 10353 return start ? i + 1 : i; 10354 } 10355 } 10356 return -1; 10357 }; 10358 var findSpace = function (start, node, offset) { 10359 return walkText(start, node, offset, function (c) { 10360 return isNbsp(c) || isWhiteSpace(c); 10361 }); 10362 }; 10363 var findContent = function (start, node, offset) { 10364 return walkText(start, node, offset, isContent); 10365 }; 10366 var findWordEndPoint = function (dom, body, container, offset, start, includeTrailingSpaces) { 10367 var lastTextNode; 10368 var rootNode = dom.getParent(container, dom.isBlock) || body; 10369 var walk = function (container, offset, pred) { 10370 var textSeeker = TextSeeker(dom); 10371 var walker = start ? textSeeker.backwards : textSeeker.forwards; 10372 return Optional.from(walker(container, offset, function (text, textOffset) { 10373 if (isBookmarkNode(text.parentNode)) { 10374 return -1; 10375 } else { 10376 lastTextNode = text; 10377 return pred(start, text, textOffset); 10378 } 10379 }, rootNode)); 10380 }; 10381 var spaceResult = walk(container, offset, findSpace); 10382 return spaceResult.bind(function (result) { 10383 return includeTrailingSpaces ? walk(result.container, result.offset + (start ? -1 : 0), findContent) : Optional.some(result); 10384 }).orThunk(function () { 10385 return lastTextNode ? Optional.some({ 10386 container: lastTextNode, 10387 offset: start ? 0 : lastTextNode.length 10388 }) : Optional.none(); 10389 }); 10390 }; 10391 var findSelectorEndPoint = function (dom, formatList, rng, container, siblingName) { 10392 if (isText$7(container) && isEmpty$3(container.data) && container[siblingName]) { 10393 container = container[siblingName]; 10394 } 10395 var parents = getParents$1(dom, container); 10396 for (var i = 0; i < parents.length; i++) { 10397 for (var y = 0; y < formatList.length; y++) { 10398 var curFormat = formatList[y]; 10399 if (isNonNullable(curFormat.collapsed) && curFormat.collapsed !== rng.collapsed) { 10400 continue; 10401 } 10402 if (isSelectorFormat(curFormat) && dom.is(parents[i], curFormat.selector)) { 10403 return parents[i]; 10404 } 10405 } 10406 } 10407 return container; 10408 }; 10409 var findBlockEndPoint = function (editor, formatList, container, siblingName) { 10410 var node = container; 10411 var dom = editor.dom; 10412 var root = dom.getRoot(); 10413 var format = formatList[0]; 10414 if (isBlockFormat(format)) { 10415 node = format.wrapper ? null : dom.getParent(container, format.block, root); 10416 } 10417 if (!node) { 10418 var scopeRoot = dom.getParent(container, 'LI,TD,TH'); 10419 node = dom.getParent(isText$7(container) ? container.parentNode : container, function (node) { 10420 return node !== root && isTextBlock(editor, node); 10421 }, scopeRoot); 10422 } 10423 if (node && isBlockFormat(format) && format.wrapper) { 10424 node = getParents$1(dom, node, 'ul,ol').reverse()[0] || node; 10425 } 10426 if (!node) { 10427 node = container; 10428 while (node[siblingName] && !dom.isBlock(node[siblingName])) { 10429 node = node[siblingName]; 10430 if (isEq$5(node, 'br')) { 10431 break; 10432 } 10433 } 10434 } 10435 return node || container; 10436 }; 10437 var isAtBlockBoundary$1 = function (dom, root, container, siblingName) { 10438 var parent = container.parentNode; 10439 if (isNonNullable(container[siblingName])) { 10440 return false; 10441 } else if (parent === root || isNullable(parent) || dom.isBlock(parent)) { 10442 return true; 10443 } else { 10444 return isAtBlockBoundary$1(dom, root, parent, siblingName); 10445 } 10446 }; 10447 var findParentContainer = function (dom, formatList, container, offset, start) { 10448 var parent = container; 10449 var siblingName = start ? 'previousSibling' : 'nextSibling'; 10450 var root = dom.getRoot(); 10451 if (isText$7(container) && !isWhiteSpaceNode(container)) { 10452 if (start ? offset > 0 : offset < container.data.length) { 10453 return container; 10454 } 10455 } 10456 while (true) { 10457 if (!formatList[0].block_expand && dom.isBlock(parent)) { 10458 return parent; 10459 } 10460 for (var sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) { 10461 var allowSpaces = isText$7(sibling) && !isAtBlockBoundary$1(dom, root, sibling, siblingName); 10462 if (!isBookmarkNode(sibling) && !isBogusBr(sibling) && !isWhiteSpaceNode(sibling, allowSpaces)) { 10463 return parent; 10464 } 10465 } 10466 if (parent === root || parent.parentNode === root) { 10467 container = parent; 10468 break; 10469 } 10470 parent = parent.parentNode; 10471 } 10472 return container; 10473 }; 10474 var isSelfOrParentBookmark = function (container) { 10475 return isBookmarkNode(container.parentNode) || isBookmarkNode(container); 10476 }; 10477 var expandRng = function (editor, rng, formatList, includeTrailingSpace) { 10478 if (includeTrailingSpace === void 0) { 10479 includeTrailingSpace = false; 10480 } 10481 var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset; 10482 var dom = editor.dom; 10483 var format = formatList[0]; 10484 if (isElement$5(startContainer) && startContainer.hasChildNodes()) { 10485 startContainer = getNode$1(startContainer, startOffset); 10486 if (isText$7(startContainer)) { 10487 startOffset = 0; 10488 } 10489 } 10490 if (isElement$5(endContainer) && endContainer.hasChildNodes()) { 10491 endContainer = getNode$1(endContainer, rng.collapsed ? endOffset : endOffset - 1); 10492 if (isText$7(endContainer)) { 10493 endOffset = endContainer.nodeValue.length; 10494 } 10495 } 10496 startContainer = findParentContentEditable(dom, startContainer); 10497 endContainer = findParentContentEditable(dom, endContainer); 10498 if (isSelfOrParentBookmark(startContainer)) { 10499 startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode; 10500 if (rng.collapsed) { 10501 startContainer = startContainer.previousSibling || startContainer; 10502 } else { 10503 startContainer = startContainer.nextSibling || startContainer; 10504 } 10505 if (isText$7(startContainer)) { 10506 startOffset = rng.collapsed ? startContainer.length : 0; 10507 } 10508 } 10509 if (isSelfOrParentBookmark(endContainer)) { 10510 endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode; 10511 if (rng.collapsed) { 10512 endContainer = endContainer.nextSibling || endContainer; 10513 } else { 10514 endContainer = endContainer.previousSibling || endContainer; 10515 } 10516 if (isText$7(endContainer)) { 10517 endOffset = rng.collapsed ? 0 : endContainer.length; 10518 } 10519 } 10520 if (rng.collapsed) { 10521 var startPoint = findWordEndPoint(dom, editor.getBody(), startContainer, startOffset, true, includeTrailingSpace); 10522 startPoint.each(function (_a) { 10523 var container = _a.container, offset = _a.offset; 10524 startContainer = container; 10525 startOffset = offset; 10526 }); 10527 var endPoint = findWordEndPoint(dom, editor.getBody(), endContainer, endOffset, false, includeTrailingSpace); 10528 endPoint.each(function (_a) { 10529 var container = _a.container, offset = _a.offset; 10530 endContainer = container; 10531 endOffset = offset; 10532 }); 10533 } 10534 if (isInlineFormat(format) || format.block_expand) { 10535 if (!isInlineFormat(format) || (!isText$7(startContainer) || startOffset === 0)) { 10536 startContainer = findParentContainer(dom, formatList, startContainer, startOffset, true); 10537 } 10538 if (!isInlineFormat(format) || (!isText$7(endContainer) || endOffset === endContainer.nodeValue.length)) { 10539 endContainer = findParentContainer(dom, formatList, endContainer, endOffset, false); 10540 } 10541 } 10542 if (shouldExpandToSelector(format)) { 10543 startContainer = findSelectorEndPoint(dom, formatList, rng, startContainer, 'previousSibling'); 10544 endContainer = findSelectorEndPoint(dom, formatList, rng, endContainer, 'nextSibling'); 10545 } 10546 if (isBlockFormat(format) || isSelectorFormat(format)) { 10547 startContainer = findBlockEndPoint(editor, formatList, startContainer, 'previousSibling'); 10548 endContainer = findBlockEndPoint(editor, formatList, endContainer, 'nextSibling'); 10549 if (isBlockFormat(format)) { 10550 if (!dom.isBlock(startContainer)) { 10551 startContainer = findParentContainer(dom, formatList, startContainer, startOffset, true); 10552 } 10553 if (!dom.isBlock(endContainer)) { 10554 endContainer = findParentContainer(dom, formatList, endContainer, endOffset, false); 10555 } 10556 } 10557 } 10558 if (isElement$5(startContainer)) { 10559 startOffset = dom.nodeIndex(startContainer); 10560 startContainer = startContainer.parentNode; 10561 } 10562 if (isElement$5(endContainer)) { 10563 endOffset = dom.nodeIndex(endContainer) + 1; 10564 endContainer = endContainer.parentNode; 10565 } 10566 return { 10567 startContainer: startContainer, 10568 startOffset: startOffset, 10569 endContainer: endContainer, 10570 endOffset: endOffset 10571 }; 10572 }; 10573 10574 var walk$2 = function (dom, rng, callback) { 10575 var startOffset = rng.startOffset; 10576 var startContainer = getNode$1(rng.startContainer, startOffset); 10577 var endOffset = rng.endOffset; 10578 var endContainer = getNode$1(rng.endContainer, endOffset - 1); 10579 var exclude = function (nodes) { 10580 var firstNode = nodes[0]; 10581 if (isText$7(firstNode) && firstNode === startContainer && startOffset >= firstNode.data.length) { 10582 nodes.splice(0, 1); 10583 } 10584 var lastNode = nodes[nodes.length - 1]; 10585 if (endOffset === 0 && nodes.length > 0 && lastNode === endContainer && isText$7(lastNode)) { 10586 nodes.splice(nodes.length - 1, 1); 10587 } 10588 return nodes; 10589 }; 10590 var collectSiblings = function (node, name, endNode) { 10591 var siblings = []; 10592 for (; node && node !== endNode; node = node[name]) { 10593 siblings.push(node); 10594 } 10595 return siblings; 10596 }; 10597 var findEndPoint = function (node, root) { 10598 return dom.getParent(node, function (node) { 10599 return node.parentNode === root; 10600 }, root); 10601 }; 10602 var walkBoundary = function (startNode, endNode, next) { 10603 var siblingName = next ? 'nextSibling' : 'previousSibling'; 10604 for (var node = startNode, parent_1 = node.parentNode; node && node !== endNode; node = parent_1) { 10605 parent_1 = node.parentNode; 10606 var siblings_1 = collectSiblings(node === startNode ? node : node[siblingName], siblingName); 10607 if (siblings_1.length) { 10608 if (!next) { 10609 siblings_1.reverse(); 10610 } 10611 callback(exclude(siblings_1)); 10612 } 10613 } 10614 }; 10615 if (startContainer === endContainer) { 10616 return callback(exclude([startContainer])); 10617 } 10618 var ancestor = dom.findCommonAncestor(startContainer, endContainer); 10619 if (dom.isChildOf(startContainer, endContainer)) { 10620 return walkBoundary(startContainer, ancestor, true); 10621 } 10622 if (dom.isChildOf(endContainer, startContainer)) { 10623 return walkBoundary(endContainer, ancestor); 10624 } 10625 var startPoint = findEndPoint(startContainer, ancestor) || startContainer; 10626 var endPoint = findEndPoint(endContainer, ancestor) || endContainer; 10627 walkBoundary(startContainer, startPoint, true); 10628 var siblings = collectSiblings(startPoint === startContainer ? startPoint : startPoint.nextSibling, 'nextSibling', endPoint === endContainer ? endPoint.nextSibling : endPoint); 10629 if (siblings.length) { 10630 callback(exclude(siblings)); 10631 } 10632 walkBoundary(endContainer, endPoint); 10633 }; 10634 10635 var getRanges = function (selection) { 10636 var ranges = []; 10637 if (selection) { 10638 for (var i = 0; i < selection.rangeCount; i++) { 10639 ranges.push(selection.getRangeAt(i)); 10640 } 10641 } 10642 return ranges; 10643 }; 10644 var getSelectedNodes = function (ranges) { 10645 return bind(ranges, function (range) { 10646 var node = getSelectedNode(range); 10647 return node ? [SugarElement.fromDom(node)] : []; 10648 }); 10649 }; 10650 var hasMultipleRanges = function (selection) { 10651 return getRanges(selection).length > 1; 10652 }; 10653 10654 var getCellsFromRanges = function (ranges) { 10655 return filter$4(getSelectedNodes(ranges), isTableCell$4); 10656 }; 10657 var getCellsFromElement = function (elm) { 10658 return descendants(elm, 'td[data-mce-selected],th[data-mce-selected]'); 10659 }; 10660 var getCellsFromElementOrRanges = function (ranges, element) { 10661 var selectedCells = getCellsFromElement(element); 10662 return selectedCells.length > 0 ? selectedCells : getCellsFromRanges(ranges); 10663 }; 10664 var getCellsFromEditor = function (editor) { 10665 return getCellsFromElementOrRanges(getRanges(editor.selection.getSel()), SugarElement.fromDom(editor.getBody())); 10666 }; 10667 var getClosestTable = function (cell, isRoot) { 10668 return ancestor$2(cell, 'table', isRoot); 10669 }; 10670 10671 var getStartNode = function (rng) { 10672 var sc = rng.startContainer, so = rng.startOffset; 10673 if (isText$7(sc)) { 10674 return so === 0 ? Optional.some(SugarElement.fromDom(sc)) : Optional.none(); 10675 } else { 10676 return Optional.from(sc.childNodes[so]).map(SugarElement.fromDom); 10677 } 10678 }; 10679 var getEndNode = function (rng) { 10680 var ec = rng.endContainer, eo = rng.endOffset; 10681 if (isText$7(ec)) { 10682 return eo === ec.data.length ? Optional.some(SugarElement.fromDom(ec)) : Optional.none(); 10683 } else { 10684 return Optional.from(ec.childNodes[eo - 1]).map(SugarElement.fromDom); 10685 } 10686 }; 10687 var getFirstChildren = function (node) { 10688 return firstChild(node).fold(constant([node]), function (child) { 10689 return [node].concat(getFirstChildren(child)); 10690 }); 10691 }; 10692 var getLastChildren$1 = function (node) { 10693 return lastChild(node).fold(constant([node]), function (child) { 10694 if (name(child) === 'br') { 10695 return prevSibling(child).map(function (sibling) { 10696 return [node].concat(getLastChildren$1(sibling)); 10697 }).getOr([]); 10698 } else { 10699 return [node].concat(getLastChildren$1(child)); 10700 } 10701 }); 10702 }; 10703 var hasAllContentsSelected = function (elm, rng) { 10704 return lift2(getStartNode(rng), getEndNode(rng), function (startNode, endNode) { 10705 var start = find$3(getFirstChildren(elm), curry(eq, startNode)); 10706 var end = find$3(getLastChildren$1(elm), curry(eq, endNode)); 10707 return start.isSome() && end.isSome(); 10708 }).getOr(false); 10709 }; 10710 var moveEndPoint = function (dom, rng, node, start) { 10711 var root = node, walker = new DomTreeWalker(node, root); 10712 var moveCaretBeforeOnEnterElementsMap = filter$3(dom.schema.getMoveCaretBeforeOnEnterElements(), function (_, name) { 10713 return !contains$3([ 10714 'td', 10715 'th', 10716 'table' 10717 ], name.toLowerCase()); 10718 }); 10719 do { 10720 if (isText$7(node) && Tools.trim(node.nodeValue).length !== 0) { 10721 if (start) { 10722 rng.setStart(node, 0); 10723 } else { 10724 rng.setEnd(node, node.nodeValue.length); 10725 } 10726 return; 10727 } 10728 if (moveCaretBeforeOnEnterElementsMap[node.nodeName]) { 10729 if (start) { 10730 rng.setStartBefore(node); 10731 } else { 10732 if (node.nodeName === 'BR') { 10733 rng.setEndBefore(node); 10734 } else { 10735 rng.setEndAfter(node); 10736 } 10737 } 10738 return; 10739 } 10740 } while (node = start ? walker.next() : walker.prev()); 10741 if (root.nodeName === 'BODY') { 10742 if (start) { 10743 rng.setStart(root, 0); 10744 } else { 10745 rng.setEnd(root, root.childNodes.length); 10746 } 10747 } 10748 }; 10749 var hasAnyRanges = function (editor) { 10750 var sel = editor.selection.getSel(); 10751 return sel && sel.rangeCount > 0; 10752 }; 10753 var runOnRanges = function (editor, executor) { 10754 var fakeSelectionNodes = getCellsFromEditor(editor); 10755 if (fakeSelectionNodes.length > 0) { 10756 each$k(fakeSelectionNodes, function (elem) { 10757 var node = elem.dom; 10758 var fakeNodeRng = editor.dom.createRng(); 10759 fakeNodeRng.setStartBefore(node); 10760 fakeNodeRng.setEndAfter(node); 10761 executor(fakeNodeRng, true); 10762 }); 10763 } else { 10764 executor(editor.selection.getRng(), false); 10765 } 10766 }; 10767 var preserve = function (selection, fillBookmark, executor) { 10768 var bookmark = getPersistentBookmark(selection, fillBookmark); 10769 executor(bookmark); 10770 selection.moveToBookmark(bookmark); 10771 }; 10772 10773 var NodeValue = function (is, name) { 10774 var get = function (element) { 10775 if (!is(element)) { 10776 throw new Error('Can only get ' + name + ' value of a ' + name + ' node'); 10777 } 10778 return getOption(element).getOr(''); 10779 }; 10780 var getOption = function (element) { 10781 return is(element) ? Optional.from(element.dom.nodeValue) : Optional.none(); 10782 }; 10783 var set = function (element, value) { 10784 if (!is(element)) { 10785 throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node'); 10786 } 10787 element.dom.nodeValue = value; 10788 }; 10789 return { 10790 get: get, 10791 getOption: getOption, 10792 set: set 10793 }; 10794 }; 10795 10796 var api$1 = NodeValue(isText$8, 'text'); 10797 var get$2 = function (element) { 10798 return api$1.get(element); 10799 }; 10800 10801 var isZeroWidth = function (elem) { 10802 return isText$8(elem) && get$2(elem) === ZWSP$1; 10803 }; 10804 var context = function (editor, elem, wrapName, nodeName) { 10805 return parent(elem).fold(function () { 10806 return 'skipping'; 10807 }, function (parent) { 10808 if (nodeName === 'br' || isZeroWidth(elem)) { 10809 return 'valid'; 10810 } else if (isAnnotation(elem)) { 10811 return 'existing'; 10812 } else if (isCaretNode(elem.dom)) { 10813 return 'caret'; 10814 } else if (!isValid(editor, wrapName, nodeName) || !isValid(editor, name(parent), wrapName)) { 10815 return 'invalid-child'; 10816 } else { 10817 return 'valid'; 10818 } 10819 }); 10820 }; 10821 10822 var applyWordGrab = function (editor, rng) { 10823 var r = expandRng(editor, rng, [{ inline: 'span' }]); 10824 rng.setStart(r.startContainer, r.startOffset); 10825 rng.setEnd(r.endContainer, r.endOffset); 10826 editor.selection.setRng(rng); 10827 }; 10828 var makeAnnotation = function (eDoc, _a, annotationName, decorate) { 10829 var _b = _a.uid, uid = _b === void 0 ? generate('mce-annotation') : _b, data = __rest(_a, ['uid']); 10830 var master = SugarElement.fromTag('span', eDoc); 10831 add$1(master, annotation()); 10832 set$1(master, '' + dataAnnotationId(), uid); 10833 set$1(master, '' + dataAnnotation(), annotationName); 10834 var _c = decorate(uid, data), _d = _c.attributes, attributes = _d === void 0 ? {} : _d, _e = _c.classes, classes = _e === void 0 ? [] : _e; 10835 setAll$1(master, attributes); 10836 add(master, classes); 10837 return master; 10838 }; 10839 var annotate = function (editor, rng, annotationName, decorate, data) { 10840 var newWrappers = []; 10841 var master = makeAnnotation(editor.getDoc(), data, annotationName, decorate); 10842 var wrapper = value(); 10843 var finishWrapper = function () { 10844 wrapper.clear(); 10845 }; 10846 var getOrOpenWrapper = function () { 10847 return wrapper.get().getOrThunk(function () { 10848 var nu = shallow(master); 10849 newWrappers.push(nu); 10850 wrapper.set(nu); 10851 return nu; 10852 }); 10853 }; 10854 var processElements = function (elems) { 10855 each$k(elems, processElement); 10856 }; 10857 var processElement = function (elem) { 10858 var ctx = context(editor, elem, 'span', name(elem)); 10859 switch (ctx) { 10860 case 'invalid-child': { 10861 finishWrapper(); 10862 var children$1 = children(elem); 10863 processElements(children$1); 10864 finishWrapper(); 10865 break; 10866 } 10867 case 'valid': { 10868 var w = getOrOpenWrapper(); 10869 wrap$3(elem, w); 10870 break; 10871 } 10872 } 10873 }; 10874 var processNodes = function (nodes) { 10875 var elems = map$3(nodes, SugarElement.fromDom); 10876 processElements(elems); 10877 }; 10878 walk$2(editor.dom, rng, function (nodes) { 10879 finishWrapper(); 10880 processNodes(nodes); 10881 }); 10882 return newWrappers; 10883 }; 10884 var annotateWithBookmark = function (editor, name, settings, data) { 10885 editor.undoManager.transact(function () { 10886 var selection = editor.selection; 10887 var initialRng = selection.getRng(); 10888 var hasFakeSelection = getCellsFromEditor(editor).length > 0; 10889 if (initialRng.collapsed && !hasFakeSelection) { 10890 applyWordGrab(editor, initialRng); 10891 } 10892 if (selection.getRng().collapsed && !hasFakeSelection) { 10893 var wrapper = makeAnnotation(editor.getDoc(), data, name, settings.decorate); 10894 set(wrapper, nbsp); 10895 selection.getRng().insertNode(wrapper.dom); 10896 selection.select(wrapper.dom); 10897 } else { 10898 preserve(selection, false, function () { 10899 runOnRanges(editor, function (selectionRng) { 10900 annotate(editor, selectionRng, name, settings.decorate, data); 10901 }); 10902 }); 10903 } 10904 }); 10905 }; 10906 10907 var Annotator = function (editor) { 10908 var registry = create$7(); 10909 setup$m(editor, registry); 10910 var changes = setup$n(editor); 10911 return { 10912 register: function (name, settings) { 10913 registry.register(name, settings); 10914 }, 10915 annotate: function (name, data) { 10916 registry.lookup(name).each(function (settings) { 10917 annotateWithBookmark(editor, name, settings, data); 10918 }); 10919 }, 10920 annotationChanged: function (name, callback) { 10921 changes.addListener(name, callback); 10922 }, 10923 remove: function (name) { 10924 identify(editor, Optional.some(name)).each(function (_a) { 10925 var elements = _a.elements; 10926 each$k(elements, unwrap); 10927 }); 10928 }, 10929 getAll: function (name) { 10930 var directory = findAll(editor, name); 10931 return map$2(directory, function (elems) { 10932 return map$3(elems, function (elem) { 10933 return elem.dom; 10934 }); 10935 }); 10936 } 10937 }; 10938 }; 10939 10940 var BookmarkManager = function (selection) { 10941 return { 10942 getBookmark: curry(getBookmark$1, selection), 10943 moveToBookmark: curry(moveToBookmark, selection) 10944 }; 10945 }; 10946 BookmarkManager.isBookmarkNode = isBookmarkNode$1; 10947 10948 var getContentEditableRoot$1 = function (root, node) { 10949 while (node && node !== root) { 10950 if (isContentEditableTrue$4(node) || isContentEditableFalse$b(node)) { 10951 return node; 10952 } 10953 node = node.parentNode; 10954 } 10955 return null; 10956 }; 10957 10958 var isXYWithinRange = function (clientX, clientY, range) { 10959 if (range.collapsed) { 10960 return false; 10961 } 10962 if (Env.browser.isIE() && range.startOffset === range.endOffset - 1 && range.startContainer === range.endContainer) { 10963 var elm = range.startContainer.childNodes[range.startOffset]; 10964 if (isElement$5(elm)) { 10965 return exists(elm.getClientRects(), function (rect) { 10966 return containsXY(rect, clientX, clientY); 10967 }); 10968 } 10969 } 10970 return exists(range.getClientRects(), function (rect) { 10971 return containsXY(rect, clientX, clientY); 10972 }); 10973 }; 10974 10975 var firePreProcess = function (editor, args) { 10976 return editor.fire('PreProcess', args); 10977 }; 10978 var firePostProcess = function (editor, args) { 10979 return editor.fire('PostProcess', args); 10980 }; 10981 var fireRemove = function (editor) { 10982 return editor.fire('remove'); 10983 }; 10984 var fireDetach = function (editor) { 10985 return editor.fire('detach'); 10986 }; 10987 var fireSwitchMode = function (editor, mode) { 10988 return editor.fire('SwitchMode', { mode: mode }); 10989 }; 10990 var fireObjectResizeStart = function (editor, target, width, height, origin) { 10991 editor.fire('ObjectResizeStart', { 10992 target: target, 10993 width: width, 10994 height: height, 10995 origin: origin 10996 }); 10997 }; 10998 var fireObjectResized = function (editor, target, width, height, origin) { 10999 editor.fire('ObjectResized', { 11000 target: target, 11001 width: width, 11002 height: height, 11003 origin: origin 11004 }); 11005 }; 11006 var firePreInit = function (editor) { 11007 return editor.fire('PreInit'); 11008 }; 11009 var firePostRender = function (editor) { 11010 return editor.fire('PostRender'); 11011 }; 11012 var fireInit = function (editor) { 11013 return editor.fire('Init'); 11014 }; 11015 var firePlaceholderToggle = function (editor, state) { 11016 return editor.fire('PlaceholderToggle', { state: state }); 11017 }; 11018 var fireError = function (editor, errorType, error) { 11019 return editor.fire(errorType, error); 11020 }; 11021 var fireFormatApply = function (editor, format, node, vars) { 11022 return editor.fire('FormatApply', { 11023 format: format, 11024 node: node, 11025 vars: vars 11026 }); 11027 }; 11028 var fireFormatRemove = function (editor, format, node, vars) { 11029 return editor.fire('FormatRemove', { 11030 format: format, 11031 node: node, 11032 vars: vars 11033 }); 11034 }; 11035 11036 var VK = { 11037 BACKSPACE: 8, 11038 DELETE: 46, 11039 DOWN: 40, 11040 ENTER: 13, 11041 ESC: 27, 11042 LEFT: 37, 11043 RIGHT: 39, 11044 SPACEBAR: 32, 11045 TAB: 9, 11046 UP: 38, 11047 PAGE_UP: 33, 11048 PAGE_DOWN: 34, 11049 END: 35, 11050 HOME: 36, 11051 modifierPressed: function (e) { 11052 return e.shiftKey || e.ctrlKey || e.altKey || VK.metaKeyPressed(e); 11053 }, 11054 metaKeyPressed: function (e) { 11055 return Env.mac ? e.metaKey : e.ctrlKey && !e.altKey; 11056 } 11057 }; 11058 11059 var isContentEditableFalse$5 = isContentEditableFalse$b; 11060 var ControlSelection = function (selection, editor) { 11061 var elementSelectionAttr = 'data-mce-selected'; 11062 var dom = editor.dom, each = Tools.each; 11063 var selectedElm, selectedElmGhost, resizeHelper, selectedHandle, resizeBackdrop; 11064 var startX, startY, selectedElmX, selectedElmY, startW, startH, ratio, resizeStarted; 11065 var width, height; 11066 var editableDoc = editor.getDoc(), rootDocument = document; 11067 var abs = Math.abs, round = Math.round, rootElement = editor.getBody(); 11068 var startScrollWidth, startScrollHeight; 11069 var resizeHandles = { 11070 nw: [ 11071 0, 11072 0, 11073 -1, 11074 -1 11075 ], 11076 ne: [ 11077 1, 11078 0, 11079 1, 11080 -1 11081 ], 11082 se: [ 11083 1, 11084 1, 11085 1, 11086 1 11087 ], 11088 sw: [ 11089 0, 11090 1, 11091 -1, 11092 1 11093 ] 11094 }; 11095 var isImage = function (elm) { 11096 return elm && (elm.nodeName === 'IMG' || editor.dom.is(elm, 'figure.image')); 11097 }; 11098 var isMedia = function (elm) { 11099 return isMedia$2(elm) || dom.hasClass(elm, 'mce-preview-object'); 11100 }; 11101 var isEventOnImageOutsideRange = function (evt, range) { 11102 if (evt.type === 'longpress' || evt.type.indexOf('touch') === 0) { 11103 var touch = evt.touches[0]; 11104 return isImage(evt.target) && !isXYWithinRange(touch.clientX, touch.clientY, range); 11105 } else { 11106 return isImage(evt.target) && !isXYWithinRange(evt.clientX, evt.clientY, range); 11107 } 11108 }; 11109 var contextMenuSelectImage = function (evt) { 11110 var target = evt.target; 11111 if (isEventOnImageOutsideRange(evt, editor.selection.getRng()) && !evt.isDefaultPrevented()) { 11112 editor.selection.select(target); 11113 } 11114 }; 11115 var getResizeTargets = function (elm) { 11116 if (dom.is(elm, 'figure.image')) { 11117 return [elm.querySelector('img')]; 11118 } else if (dom.hasClass(elm, 'mce-preview-object') && isNonNullable(elm.firstElementChild)) { 11119 return [ 11120 elm, 11121 elm.firstElementChild 11122 ]; 11123 } else { 11124 return [elm]; 11125 } 11126 }; 11127 var isResizable = function (elm) { 11128 var selector = getObjectResizing(editor); 11129 if (!selector) { 11130 return false; 11131 } 11132 if (elm.getAttribute('data-mce-resize') === 'false') { 11133 return false; 11134 } 11135 if (elm === editor.getBody()) { 11136 return false; 11137 } 11138 if (dom.hasClass(elm, 'mce-preview-object')) { 11139 return is$2(SugarElement.fromDom(elm.firstElementChild), selector); 11140 } else { 11141 return is$2(SugarElement.fromDom(elm), selector); 11142 } 11143 }; 11144 var createGhostElement = function (elm) { 11145 if (isMedia(elm)) { 11146 return dom.create('img', { src: Env.transparentSrc }); 11147 } else { 11148 return elm.cloneNode(true); 11149 } 11150 }; 11151 var setSizeProp = function (element, name, value) { 11152 if (isNonNullable(value)) { 11153 var targets = getResizeTargets(element); 11154 each$k(targets, function (target) { 11155 if (target.style[name] || !editor.schema.isValid(target.nodeName.toLowerCase(), name)) { 11156 dom.setStyle(target, name, value); 11157 } else { 11158 dom.setAttrib(target, name, '' + value); 11159 } 11160 }); 11161 } 11162 }; 11163 var setGhostElmSize = function (ghostElm, width, height) { 11164 setSizeProp(ghostElm, 'width', width); 11165 setSizeProp(ghostElm, 'height', height); 11166 }; 11167 var resizeGhostElement = function (e) { 11168 var deltaX, deltaY, proportional; 11169 var resizeHelperX, resizeHelperY; 11170 deltaX = e.screenX - startX; 11171 deltaY = e.screenY - startY; 11172 width = deltaX * selectedHandle[2] + startW; 11173 height = deltaY * selectedHandle[3] + startH; 11174 width = width < 5 ? 5 : width; 11175 height = height < 5 ? 5 : height; 11176 if ((isImage(selectedElm) || isMedia(selectedElm)) && getResizeImgProportional(editor) !== false) { 11177 proportional = !VK.modifierPressed(e); 11178 } else { 11179 proportional = VK.modifierPressed(e); 11180 } 11181 if (proportional) { 11182 if (abs(deltaX) > abs(deltaY)) { 11183 height = round(width * ratio); 11184 width = round(height / ratio); 11185 } else { 11186 width = round(height / ratio); 11187 height = round(width * ratio); 11188 } 11189 } 11190 setGhostElmSize(selectedElmGhost, width, height); 11191 resizeHelperX = selectedHandle.startPos.x + deltaX; 11192 resizeHelperY = selectedHandle.startPos.y + deltaY; 11193 resizeHelperX = resizeHelperX > 0 ? resizeHelperX : 0; 11194 resizeHelperY = resizeHelperY > 0 ? resizeHelperY : 0; 11195 dom.setStyles(resizeHelper, { 11196 left: resizeHelperX, 11197 top: resizeHelperY, 11198 display: 'block' 11199 }); 11200 resizeHelper.innerHTML = width + ' × ' + height; 11201 if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) { 11202 dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width)); 11203 } 11204 if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) { 11205 dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height)); 11206 } 11207 deltaX = rootElement.scrollWidth - startScrollWidth; 11208 deltaY = rootElement.scrollHeight - startScrollHeight; 11209 if (deltaX + deltaY !== 0) { 11210 dom.setStyles(resizeHelper, { 11211 left: resizeHelperX - deltaX, 11212 top: resizeHelperY - deltaY 11213 }); 11214 } 11215 if (!resizeStarted) { 11216 fireObjectResizeStart(editor, selectedElm, startW, startH, 'corner-' + selectedHandle.name); 11217 resizeStarted = true; 11218 } 11219 }; 11220 var endGhostResize = function () { 11221 var wasResizeStarted = resizeStarted; 11222 resizeStarted = false; 11223 if (wasResizeStarted) { 11224 setSizeProp(selectedElm, 'width', width); 11225 setSizeProp(selectedElm, 'height', height); 11226 } 11227 dom.unbind(editableDoc, 'mousemove', resizeGhostElement); 11228 dom.unbind(editableDoc, 'mouseup', endGhostResize); 11229 if (rootDocument !== editableDoc) { 11230 dom.unbind(rootDocument, 'mousemove', resizeGhostElement); 11231 dom.unbind(rootDocument, 'mouseup', endGhostResize); 11232 } 11233 dom.remove(selectedElmGhost); 11234 dom.remove(resizeHelper); 11235 dom.remove(resizeBackdrop); 11236 showResizeRect(selectedElm); 11237 if (wasResizeStarted) { 11238 fireObjectResized(editor, selectedElm, width, height, 'corner-' + selectedHandle.name); 11239 dom.setAttrib(selectedElm, 'style', dom.getAttrib(selectedElm, 'style')); 11240 } 11241 editor.nodeChanged(); 11242 }; 11243 var showResizeRect = function (targetElm) { 11244 unbindResizeHandleEvents(); 11245 var position = dom.getPos(targetElm, rootElement); 11246 var selectedElmX = position.x; 11247 var selectedElmY = position.y; 11248 var rect = targetElm.getBoundingClientRect(); 11249 var targetWidth = rect.width || rect.right - rect.left; 11250 var targetHeight = rect.height || rect.bottom - rect.top; 11251 if (selectedElm !== targetElm) { 11252 hideResizeRect(); 11253 selectedElm = targetElm; 11254 width = height = 0; 11255 } 11256 var e = editor.fire('ObjectSelected', { target: targetElm }); 11257 var selectedValue = dom.getAttrib(selectedElm, elementSelectionAttr, '1'); 11258 if (isResizable(targetElm) && !e.isDefaultPrevented()) { 11259 each(resizeHandles, function (handle, name) { 11260 var handleElm; 11261 var startDrag = function (e) { 11262 var target = getResizeTargets(selectedElm)[0]; 11263 startX = e.screenX; 11264 startY = e.screenY; 11265 startW = target.clientWidth; 11266 startH = target.clientHeight; 11267 ratio = startH / startW; 11268 selectedHandle = handle; 11269 selectedHandle.name = name; 11270 selectedHandle.startPos = { 11271 x: targetWidth * handle[0] + selectedElmX, 11272 y: targetHeight * handle[1] + selectedElmY 11273 }; 11274 startScrollWidth = rootElement.scrollWidth; 11275 startScrollHeight = rootElement.scrollHeight; 11276 resizeBackdrop = dom.add(rootElement, 'div', { 11277 'class': 'mce-resize-backdrop', 11278 'data-mce-bogus': 'all' 11279 }); 11280 dom.setStyles(resizeBackdrop, { 11281 position: 'fixed', 11282 left: '0', 11283 top: '0', 11284 width: '100%', 11285 height: '100%' 11286 }); 11287 selectedElmGhost = createGhostElement(selectedElm); 11288 dom.addClass(selectedElmGhost, 'mce-clonedresizable'); 11289 dom.setAttrib(selectedElmGhost, 'data-mce-bogus', 'all'); 11290 selectedElmGhost.contentEditable = 'false'; 11291 dom.setStyles(selectedElmGhost, { 11292 left: selectedElmX, 11293 top: selectedElmY, 11294 margin: 0 11295 }); 11296 setGhostElmSize(selectedElmGhost, targetWidth, targetHeight); 11297 selectedElmGhost.removeAttribute(elementSelectionAttr); 11298 rootElement.appendChild(selectedElmGhost); 11299 dom.bind(editableDoc, 'mousemove', resizeGhostElement); 11300 dom.bind(editableDoc, 'mouseup', endGhostResize); 11301 if (rootDocument !== editableDoc) { 11302 dom.bind(rootDocument, 'mousemove', resizeGhostElement); 11303 dom.bind(rootDocument, 'mouseup', endGhostResize); 11304 } 11305 resizeHelper = dom.add(rootElement, 'div', { 11306 'class': 'mce-resize-helper', 11307 'data-mce-bogus': 'all' 11308 }, startW + ' × ' + startH); 11309 }; 11310 handleElm = dom.get('mceResizeHandle' + name); 11311 if (handleElm) { 11312 dom.remove(handleElm); 11313 } 11314 handleElm = dom.add(rootElement, 'div', { 11315 'id': 'mceResizeHandle' + name, 11316 'data-mce-bogus': 'all', 11317 'class': 'mce-resizehandle', 11318 'unselectable': true, 11319 'style': 'cursor:' + name + '-resize; margin:0; padding:0' 11320 }); 11321 if (Env.ie === 11) { 11322 handleElm.contentEditable = false; 11323 } 11324 dom.bind(handleElm, 'mousedown', function (e) { 11325 e.stopImmediatePropagation(); 11326 e.preventDefault(); 11327 startDrag(e); 11328 }); 11329 handle.elm = handleElm; 11330 dom.setStyles(handleElm, { 11331 left: targetWidth * handle[0] + selectedElmX - handleElm.offsetWidth / 2, 11332 top: targetHeight * handle[1] + selectedElmY - handleElm.offsetHeight / 2 11333 }); 11334 }); 11335 } else { 11336 hideResizeRect(); 11337 } 11338 if (!dom.getAttrib(selectedElm, elementSelectionAttr)) { 11339 selectedElm.setAttribute(elementSelectionAttr, selectedValue); 11340 } 11341 }; 11342 var hideResizeRect = function () { 11343 unbindResizeHandleEvents(); 11344 if (selectedElm) { 11345 selectedElm.removeAttribute(elementSelectionAttr); 11346 } 11347 each$j(resizeHandles, function (value, name) { 11348 var handleElm = dom.get('mceResizeHandle' + name); 11349 if (handleElm) { 11350 dom.unbind(handleElm); 11351 dom.remove(handleElm); 11352 } 11353 }); 11354 }; 11355 var updateResizeRect = function (e) { 11356 var startElm, controlElm; 11357 var isChildOrEqual = function (node, parent) { 11358 if (node) { 11359 do { 11360 if (node === parent) { 11361 return true; 11362 } 11363 } while (node = node.parentNode); 11364 } 11365 }; 11366 if (resizeStarted || editor.removed) { 11367 return; 11368 } 11369 each(dom.select('img[data-mce-selected],hr[data-mce-selected]'), function (img) { 11370 img.removeAttribute(elementSelectionAttr); 11371 }); 11372 controlElm = e.type === 'mousedown' ? e.target : selection.getNode(); 11373 controlElm = dom.$(controlElm).closest('table,img,figure.image,hr,video,span.mce-preview-object')[0]; 11374 if (isChildOrEqual(controlElm, rootElement)) { 11375 disableGeckoResize(); 11376 startElm = selection.getStart(true); 11377 if (isChildOrEqual(startElm, controlElm) && isChildOrEqual(selection.getEnd(true), controlElm)) { 11378 showResizeRect(controlElm); 11379 return; 11380 } 11381 } 11382 hideResizeRect(); 11383 }; 11384 var isWithinContentEditableFalse = function (elm) { 11385 return isContentEditableFalse$5(getContentEditableRoot$1(editor.getBody(), elm)); 11386 }; 11387 var unbindResizeHandleEvents = function () { 11388 each$j(resizeHandles, function (handle) { 11389 if (handle.elm) { 11390 dom.unbind(handle.elm); 11391 delete handle.elm; 11392 } 11393 }); 11394 }; 11395 var disableGeckoResize = function () { 11396 try { 11397 editor.getDoc().execCommand('enableObjectResizing', false, 'false'); 11398 } catch (ex) { 11399 } 11400 }; 11401 editor.on('init', function () { 11402 disableGeckoResize(); 11403 if (Env.browser.isIE() || Env.browser.isEdge()) { 11404 editor.on('mousedown click', function (e) { 11405 var target = e.target, nodeName = target.nodeName; 11406 if (!resizeStarted && /^(TABLE|IMG|HR)$/.test(nodeName) && !isWithinContentEditableFalse(target)) { 11407 if (e.button !== 2) { 11408 editor.selection.select(target, nodeName === 'TABLE'); 11409 } 11410 if (e.type === 'mousedown') { 11411 editor.nodeChanged(); 11412 } 11413 } 11414 }); 11415 var handleMSControlSelect_1 = function (e) { 11416 var delayedSelect = function (node) { 11417 Delay.setEditorTimeout(editor, function () { 11418 return editor.selection.select(node); 11419 }); 11420 }; 11421 if (isWithinContentEditableFalse(e.target) || isMedia$2(e.target)) { 11422 e.preventDefault(); 11423 delayedSelect(e.target); 11424 return; 11425 } 11426 if (/^(TABLE|IMG|HR)$/.test(e.target.nodeName)) { 11427 e.preventDefault(); 11428 if (e.target.tagName === 'IMG') { 11429 delayedSelect(e.target); 11430 } 11431 } 11432 }; 11433 dom.bind(rootElement, 'mscontrolselect', handleMSControlSelect_1); 11434 editor.on('remove', function () { 11435 return dom.unbind(rootElement, 'mscontrolselect', handleMSControlSelect_1); 11436 }); 11437 } 11438 var throttledUpdateResizeRect = Delay.throttle(function (e) { 11439 if (!editor.composing) { 11440 updateResizeRect(e); 11441 } 11442 }); 11443 editor.on('nodechange ResizeEditor ResizeWindow ResizeContent drop FullscreenStateChanged', throttledUpdateResizeRect); 11444 editor.on('keyup compositionend', function (e) { 11445 if (selectedElm && selectedElm.nodeName === 'TABLE') { 11446 throttledUpdateResizeRect(e); 11447 } 11448 }); 11449 editor.on('hide blur', hideResizeRect); 11450 editor.on('contextmenu longpress', contextMenuSelectImage, true); 11451 }); 11452 editor.on('remove', unbindResizeHandleEvents); 11453 var destroy = function () { 11454 selectedElm = selectedElmGhost = resizeBackdrop = null; 11455 }; 11456 return { 11457 isResizable: isResizable, 11458 showResizeRect: showResizeRect, 11459 hideResizeRect: hideResizeRect, 11460 updateResizeRect: updateResizeRect, 11461 destroy: destroy 11462 }; 11463 }; 11464 11465 var hasCeProperty = function (node) { 11466 return isContentEditableTrue$4(node) || isContentEditableFalse$b(node); 11467 }; 11468 var findParent$1 = function (node, rootNode, predicate) { 11469 while (node && node !== rootNode) { 11470 if (predicate(node)) { 11471 return node; 11472 } 11473 node = node.parentNode; 11474 } 11475 return null; 11476 }; 11477 var findClosestIeRange = function (clientX, clientY, doc) { 11478 var rects; 11479 var element = doc.elementFromPoint(clientX, clientY); 11480 var rng = doc.body.createTextRange(); 11481 if (!element || element.tagName === 'HTML') { 11482 element = doc.body; 11483 } 11484 rng.moveToElementText(element); 11485 rects = Tools.toArray(rng.getClientRects()); 11486 rects = rects.sort(function (a, b) { 11487 a = Math.abs(Math.max(a.top - clientY, a.bottom - clientY)); 11488 b = Math.abs(Math.max(b.top - clientY, b.bottom - clientY)); 11489 return a - b; 11490 }); 11491 if (rects.length > 0) { 11492 clientY = (rects[0].bottom + rects[0].top) / 2; 11493 try { 11494 rng.moveToPoint(clientX, clientY); 11495 rng.collapse(true); 11496 return rng; 11497 } catch (ex) { 11498 } 11499 } 11500 return null; 11501 }; 11502 var moveOutOfContentEditableFalse = function (rng, rootNode) { 11503 var parentElement = rng && rng.parentElement ? rng.parentElement() : null; 11504 return isContentEditableFalse$b(findParent$1(parentElement, rootNode, hasCeProperty)) ? null : rng; 11505 }; 11506 var fromPoint = function (clientX, clientY, doc) { 11507 var rng, point; 11508 var pointDoc = doc; 11509 if (pointDoc.caretPositionFromPoint) { 11510 point = pointDoc.caretPositionFromPoint(clientX, clientY); 11511 if (point) { 11512 rng = doc.createRange(); 11513 rng.setStart(point.offsetNode, point.offset); 11514 rng.collapse(true); 11515 } 11516 } else if (pointDoc.caretRangeFromPoint) { 11517 rng = pointDoc.caretRangeFromPoint(clientX, clientY); 11518 } else if (pointDoc.body.createTextRange) { 11519 rng = pointDoc.body.createTextRange(); 11520 try { 11521 rng.moveToPoint(clientX, clientY); 11522 rng.collapse(true); 11523 } catch (ex) { 11524 rng = findClosestIeRange(clientX, clientY, doc); 11525 } 11526 return moveOutOfContentEditableFalse(rng, doc.body); 11527 } 11528 return rng; 11529 }; 11530 11531 var isEq$4 = function (rng1, rng2) { 11532 return rng1 && rng2 && (rng1.startContainer === rng2.startContainer && rng1.startOffset === rng2.startOffset) && (rng1.endContainer === rng2.endContainer && rng1.endOffset === rng2.endOffset); 11533 }; 11534 11535 var findParent = function (node, rootNode, predicate) { 11536 while (node && node !== rootNode) { 11537 if (predicate(node)) { 11538 return node; 11539 } 11540 node = node.parentNode; 11541 } 11542 return null; 11543 }; 11544 var hasParent$1 = function (node, rootNode, predicate) { 11545 return findParent(node, rootNode, predicate) !== null; 11546 }; 11547 var hasParentWithName = function (node, rootNode, name) { 11548 return hasParent$1(node, rootNode, function (node) { 11549 return node.nodeName === name; 11550 }); 11551 }; 11552 var isTable = function (node) { 11553 return node && node.nodeName === 'TABLE'; 11554 }; 11555 var isTableCell$2 = function (node) { 11556 return node && /^(TD|TH|CAPTION)$/.test(node.nodeName); 11557 }; 11558 var isCeFalseCaretContainer = function (node, rootNode) { 11559 return isCaretContainer$2(node) && hasParent$1(node, rootNode, isCaretNode) === false; 11560 }; 11561 var hasBrBeforeAfter = function (dom, node, left) { 11562 var walker = new DomTreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || dom.getRoot()); 11563 while (node = walker[left ? 'prev' : 'next']()) { 11564 if (isBr$5(node)) { 11565 return true; 11566 } 11567 } 11568 }; 11569 var isPrevNode = function (node, name) { 11570 return node.previousSibling && node.previousSibling.nodeName === name; 11571 }; 11572 var hasContentEditableFalseParent = function (body, node) { 11573 while (node && node !== body) { 11574 if (isContentEditableFalse$b(node)) { 11575 return true; 11576 } 11577 node = node.parentNode; 11578 } 11579 return false; 11580 }; 11581 var findTextNodeRelative = function (dom, isAfterNode, collapsed, left, startNode) { 11582 var lastInlineElement; 11583 var body = dom.getRoot(); 11584 var node; 11585 var nonEmptyElementsMap = dom.schema.getNonEmptyElements(); 11586 var parentBlockContainer = dom.getParent(startNode.parentNode, dom.isBlock) || body; 11587 if (left && isBr$5(startNode) && isAfterNode && dom.isEmpty(parentBlockContainer)) { 11588 return Optional.some(CaretPosition(startNode.parentNode, dom.nodeIndex(startNode))); 11589 } 11590 var walker = new DomTreeWalker(startNode, parentBlockContainer); 11591 while (node = walker[left ? 'prev' : 'next']()) { 11592 if (dom.getContentEditableParent(node) === 'false' || isCeFalseCaretContainer(node, body)) { 11593 return Optional.none(); 11594 } 11595 if (isText$7(node) && node.nodeValue.length > 0) { 11596 if (hasParentWithName(node, body, 'A') === false) { 11597 return Optional.some(CaretPosition(node, left ? node.nodeValue.length : 0)); 11598 } 11599 return Optional.none(); 11600 } 11601 if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) { 11602 return Optional.none(); 11603 } 11604 lastInlineElement = node; 11605 } 11606 if (collapsed && lastInlineElement) { 11607 return Optional.some(CaretPosition(lastInlineElement, 0)); 11608 } 11609 return Optional.none(); 11610 }; 11611 var normalizeEndPoint = function (dom, collapsed, start, rng) { 11612 var container, offset; 11613 var body = dom.getRoot(); 11614 var node; 11615 var directionLeft, normalized = false; 11616 container = rng[(start ? 'start' : 'end') + 'Container']; 11617 offset = rng[(start ? 'start' : 'end') + 'Offset']; 11618 var isAfterNode = isElement$5(container) && offset === container.childNodes.length; 11619 var nonEmptyElementsMap = dom.schema.getNonEmptyElements(); 11620 directionLeft = start; 11621 if (isCaretContainer$2(container)) { 11622 return Optional.none(); 11623 } 11624 if (isElement$5(container) && offset > container.childNodes.length - 1) { 11625 directionLeft = false; 11626 } 11627 if (isDocument$1(container)) { 11628 container = body; 11629 offset = 0; 11630 } 11631 if (container === body) { 11632 if (directionLeft) { 11633 node = container.childNodes[offset > 0 ? offset - 1 : 0]; 11634 if (node) { 11635 if (isCaretContainer$2(node)) { 11636 return Optional.none(); 11637 } 11638 if (nonEmptyElementsMap[node.nodeName] || isTable(node)) { 11639 return Optional.none(); 11640 } 11641 } 11642 } 11643 if (container.hasChildNodes()) { 11644 offset = Math.min(!directionLeft && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1); 11645 container = container.childNodes[offset]; 11646 offset = isText$7(container) && isAfterNode ? container.data.length : 0; 11647 if (!collapsed && container === body.lastChild && isTable(container)) { 11648 return Optional.none(); 11649 } 11650 if (hasContentEditableFalseParent(body, container) || isCaretContainer$2(container)) { 11651 return Optional.none(); 11652 } 11653 if (container.hasChildNodes() && isTable(container) === false) { 11654 node = container; 11655 var walker = new DomTreeWalker(container, body); 11656 do { 11657 if (isContentEditableFalse$b(node) || isCaretContainer$2(node)) { 11658 normalized = false; 11659 break; 11660 } 11661 if (isText$7(node) && node.nodeValue.length > 0) { 11662 offset = directionLeft ? 0 : node.nodeValue.length; 11663 container = node; 11664 normalized = true; 11665 break; 11666 } 11667 if (nonEmptyElementsMap[node.nodeName.toLowerCase()] && !isTableCell$2(node)) { 11668 offset = dom.nodeIndex(node); 11669 container = node.parentNode; 11670 if (!directionLeft) { 11671 offset++; 11672 } 11673 normalized = true; 11674 break; 11675 } 11676 } while (node = directionLeft ? walker.next() : walker.prev()); 11677 } 11678 } 11679 } 11680 if (collapsed) { 11681 if (isText$7(container) && offset === 0) { 11682 findTextNodeRelative(dom, isAfterNode, collapsed, true, container).each(function (pos) { 11683 container = pos.container(); 11684 offset = pos.offset(); 11685 normalized = true; 11686 }); 11687 } 11688 if (isElement$5(container)) { 11689 node = container.childNodes[offset]; 11690 if (!node) { 11691 node = container.childNodes[offset - 1]; 11692 } 11693 if (node && isBr$5(node) && !isPrevNode(node, 'A') && !hasBrBeforeAfter(dom, node, false) && !hasBrBeforeAfter(dom, node, true)) { 11694 findTextNodeRelative(dom, isAfterNode, collapsed, true, node).each(function (pos) { 11695 container = pos.container(); 11696 offset = pos.offset(); 11697 normalized = true; 11698 }); 11699 } 11700 } 11701 } 11702 if (directionLeft && !collapsed && isText$7(container) && offset === container.nodeValue.length) { 11703 findTextNodeRelative(dom, isAfterNode, collapsed, false, container).each(function (pos) { 11704 container = pos.container(); 11705 offset = pos.offset(); 11706 normalized = true; 11707 }); 11708 } 11709 return normalized ? Optional.some(CaretPosition(container, offset)) : Optional.none(); 11710 }; 11711 var normalize$2 = function (dom, rng) { 11712 var collapsed = rng.collapsed, normRng = rng.cloneRange(); 11713 var startPos = CaretPosition.fromRangeStart(rng); 11714 normalizeEndPoint(dom, collapsed, true, normRng).each(function (pos) { 11715 if (!collapsed || !CaretPosition.isAbove(startPos, pos)) { 11716 normRng.setStart(pos.container(), pos.offset()); 11717 } 11718 }); 11719 if (!collapsed) { 11720 normalizeEndPoint(dom, collapsed, false, normRng).each(function (pos) { 11721 normRng.setEnd(pos.container(), pos.offset()); 11722 }); 11723 } 11724 if (collapsed) { 11725 normRng.collapse(true); 11726 } 11727 return isEq$4(rng, normRng) ? Optional.none() : Optional.some(normRng); 11728 }; 11729 11730 var splitText = function (node, offset) { 11731 return node.splitText(offset); 11732 }; 11733 var split = function (rng) { 11734 var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset; 11735 if (startContainer === endContainer && isText$7(startContainer)) { 11736 if (startOffset > 0 && startOffset < startContainer.nodeValue.length) { 11737 endContainer = splitText(startContainer, startOffset); 11738 startContainer = endContainer.previousSibling; 11739 if (endOffset > startOffset) { 11740 endOffset = endOffset - startOffset; 11741 startContainer = endContainer = splitText(endContainer, endOffset).previousSibling; 11742 endOffset = endContainer.nodeValue.length; 11743 startOffset = 0; 11744 } else { 11745 endOffset = 0; 11746 } 11747 } 11748 } else { 11749 if (isText$7(startContainer) && startOffset > 0 && startOffset < startContainer.nodeValue.length) { 11750 startContainer = splitText(startContainer, startOffset); 11751 startOffset = 0; 11752 } 11753 if (isText$7(endContainer) && endOffset > 0 && endOffset < endContainer.nodeValue.length) { 11754 endContainer = splitText(endContainer, endOffset).previousSibling; 11755 endOffset = endContainer.nodeValue.length; 11756 } 11757 } 11758 return { 11759 startContainer: startContainer, 11760 startOffset: startOffset, 11761 endContainer: endContainer, 11762 endOffset: endOffset 11763 }; 11764 }; 11765 11766 var RangeUtils = function (dom) { 11767 var walk = function (rng, callback) { 11768 return walk$2(dom, rng, callback); 11769 }; 11770 var split$1 = split; 11771 var normalize = function (rng) { 11772 return normalize$2(dom, rng).fold(never, function (normalizedRng) { 11773 rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset); 11774 rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset); 11775 return true; 11776 }); 11777 }; 11778 return { 11779 walk: walk, 11780 split: split$1, 11781 normalize: normalize 11782 }; 11783 }; 11784 RangeUtils.compareRanges = isEq$4; 11785 RangeUtils.getCaretRangeFromPoint = fromPoint; 11786 RangeUtils.getSelectedNode = getSelectedNode; 11787 RangeUtils.getNode = getNode$1; 11788 11789 var Dimension = function (name, getOffset) { 11790 var set = function (element, h) { 11791 if (!isNumber(h) && !h.match(/^[0-9]+$/)) { 11792 throw new Error(name + '.set accepts only positive integer values. Value was ' + h); 11793 } 11794 var dom = element.dom; 11795 if (isSupported(dom)) { 11796 dom.style[name] = h + 'px'; 11797 } 11798 }; 11799 var get = function (element) { 11800 var r = getOffset(element); 11801 if (r <= 0 || r === null) { 11802 var css = get$5(element, name); 11803 return parseFloat(css) || 0; 11804 } 11805 return r; 11806 }; 11807 var getOuter = get; 11808 var aggregate = function (element, properties) { 11809 return foldl(properties, function (acc, property) { 11810 var val = get$5(element, property); 11811 var value = val === undefined ? 0 : parseInt(val, 10); 11812 return isNaN(value) ? acc : acc + value; 11813 }, 0); 11814 }; 11815 var max = function (element, value, properties) { 11816 var cumulativeInclusions = aggregate(element, properties); 11817 var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0; 11818 return absoluteMax; 11819 }; 11820 return { 11821 set: set, 11822 get: get, 11823 getOuter: getOuter, 11824 aggregate: aggregate, 11825 max: max 11826 }; 11827 }; 11828 11829 var api = Dimension('height', function (element) { 11830 var dom = element.dom; 11831 return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight; 11832 }); 11833 var get$1 = function (element) { 11834 return api.get(element); 11835 }; 11836 11837 var walkUp = function (navigation, doc) { 11838 var frame = navigation.view(doc); 11839 return frame.fold(constant([]), function (f) { 11840 var parent = navigation.owner(f); 11841 var rest = walkUp(navigation, parent); 11842 return [f].concat(rest); 11843 }); 11844 }; 11845 var pathTo = function (element, navigation) { 11846 var d = navigation.owner(element); 11847 return walkUp(navigation, d); 11848 }; 11849 11850 var view = function (doc) { 11851 var _a; 11852 var element = doc.dom === document ? Optional.none() : Optional.from((_a = doc.dom.defaultView) === null || _a === void 0 ? void 0 : _a.frameElement); 11853 return element.map(SugarElement.fromDom); 11854 }; 11855 var owner = function (element) { 11856 return documentOrOwner(element); 11857 }; 11858 11859 var Navigation = /*#__PURE__*/Object.freeze({ 11860 __proto__: null, 11861 view: view, 11862 owner: owner 11863 }); 11864 11865 var find$1 = function (element) { 11866 var doc = SugarElement.fromDom(document); 11867 var scroll = get$8(doc); 11868 var frames = pathTo(element, Navigation); 11869 var offset = viewport(element); 11870 var r = foldr(frames, function (b, a) { 11871 var loc = viewport(a); 11872 return { 11873 left: b.left + loc.left, 11874 top: b.top + loc.top 11875 }; 11876 }, { 11877 left: 0, 11878 top: 0 11879 }); 11880 return SugarPosition(r.left + offset.left + scroll.left, r.top + offset.top + scroll.top); 11881 }; 11882 11883 var excludeFromDescend = function (element) { 11884 return name(element) === 'textarea'; 11885 }; 11886 var fireScrollIntoViewEvent = function (editor, data) { 11887 var scrollEvent = editor.fire('ScrollIntoView', data); 11888 return scrollEvent.isDefaultPrevented(); 11889 }; 11890 var fireAfterScrollIntoViewEvent = function (editor, data) { 11891 editor.fire('AfterScrollIntoView', data); 11892 }; 11893 var descend = function (element, offset) { 11894 var children$1 = children(element); 11895 if (children$1.length === 0 || excludeFromDescend(element)) { 11896 return { 11897 element: element, 11898 offset: offset 11899 }; 11900 } else if (offset < children$1.length && !excludeFromDescend(children$1[offset])) { 11901 return { 11902 element: children$1[offset], 11903 offset: 0 11904 }; 11905 } else { 11906 var last = children$1[children$1.length - 1]; 11907 if (excludeFromDescend(last)) { 11908 return { 11909 element: element, 11910 offset: offset 11911 }; 11912 } else { 11913 if (name(last) === 'img') { 11914 return { 11915 element: last, 11916 offset: 1 11917 }; 11918 } else if (isText$8(last)) { 11919 return { 11920 element: last, 11921 offset: get$2(last).length 11922 }; 11923 } else { 11924 return { 11925 element: last, 11926 offset: children(last).length 11927 }; 11928 } 11929 } 11930 } 11931 }; 11932 var markerInfo = function (element, cleanupFun) { 11933 var pos = absolute(element); 11934 var height = get$1(element); 11935 return { 11936 element: element, 11937 bottom: pos.top + height, 11938 height: height, 11939 pos: pos, 11940 cleanup: cleanupFun 11941 }; 11942 }; 11943 var createMarker = function (element, offset) { 11944 var startPoint = descend(element, offset); 11945 var span = SugarElement.fromHtml('<span data-mce-bogus="all" style="display: inline-block;">' + ZWSP$1 + '</span>'); 11946 before$4(startPoint.element, span); 11947 return markerInfo(span, function () { 11948 return remove$7(span); 11949 }); 11950 }; 11951 var elementMarker = function (element) { 11952 return markerInfo(SugarElement.fromDom(element), noop); 11953 }; 11954 var withMarker = function (editor, f, rng, alignToTop) { 11955 preserveWith(editor, function (_s, _e) { 11956 return applyWithMarker(editor, f, rng, alignToTop); 11957 }, rng); 11958 }; 11959 var withScrollEvents = function (editor, doc, f, marker, alignToTop) { 11960 var data = { 11961 elm: marker.element.dom, 11962 alignToTop: alignToTop 11963 }; 11964 if (fireScrollIntoViewEvent(editor, data)) { 11965 return; 11966 } 11967 var scrollTop = get$8(doc).top; 11968 f(doc, scrollTop, marker, alignToTop); 11969 fireAfterScrollIntoViewEvent(editor, data); 11970 }; 11971 var applyWithMarker = function (editor, f, rng, alignToTop) { 11972 var body = SugarElement.fromDom(editor.getBody()); 11973 var doc = SugarElement.fromDom(editor.getDoc()); 11974 reflow(body); 11975 var marker = createMarker(SugarElement.fromDom(rng.startContainer), rng.startOffset); 11976 withScrollEvents(editor, doc, f, marker, alignToTop); 11977 marker.cleanup(); 11978 }; 11979 var withElement = function (editor, element, f, alignToTop) { 11980 var doc = SugarElement.fromDom(editor.getDoc()); 11981 withScrollEvents(editor, doc, f, elementMarker(element), alignToTop); 11982 }; 11983 var preserveWith = function (editor, f, rng) { 11984 var startElement = rng.startContainer; 11985 var startOffset = rng.startOffset; 11986 var endElement = rng.endContainer; 11987 var endOffset = rng.endOffset; 11988 f(SugarElement.fromDom(startElement), SugarElement.fromDom(endElement)); 11989 var newRng = editor.dom.createRng(); 11990 newRng.setStart(startElement, startOffset); 11991 newRng.setEnd(endElement, endOffset); 11992 editor.selection.setRng(rng); 11993 }; 11994 var scrollToMarker = function (marker, viewHeight, alignToTop, doc) { 11995 var pos = marker.pos; 11996 if (alignToTop) { 11997 to(pos.left, pos.top, doc); 11998 } else { 11999 var y = pos.top - viewHeight + marker.height; 12000 to(pos.left, y, doc); 12001 } 12002 }; 12003 var intoWindowIfNeeded = function (doc, scrollTop, viewHeight, marker, alignToTop) { 12004 var viewportBottom = viewHeight + scrollTop; 12005 var markerTop = marker.pos.top; 12006 var markerBottom = marker.bottom; 12007 var largerThanViewport = markerBottom - markerTop >= viewHeight; 12008 if (markerTop < scrollTop) { 12009 scrollToMarker(marker, viewHeight, alignToTop !== false, doc); 12010 } else if (markerTop > viewportBottom) { 12011 var align = largerThanViewport ? alignToTop !== false : alignToTop === true; 12012 scrollToMarker(marker, viewHeight, align, doc); 12013 } else if (markerBottom > viewportBottom && !largerThanViewport) { 12014 scrollToMarker(marker, viewHeight, alignToTop === true, doc); 12015 } 12016 }; 12017 var intoWindow = function (doc, scrollTop, marker, alignToTop) { 12018 var viewHeight = doc.dom.defaultView.innerHeight; 12019 intoWindowIfNeeded(doc, scrollTop, viewHeight, marker, alignToTop); 12020 }; 12021 var intoFrame = function (doc, scrollTop, marker, alignToTop) { 12022 var frameViewHeight = doc.dom.defaultView.innerHeight; 12023 intoWindowIfNeeded(doc, scrollTop, frameViewHeight, marker, alignToTop); 12024 var op = find$1(marker.element); 12025 var viewportBounds = getBounds(window); 12026 if (op.top < viewportBounds.y) { 12027 intoView(marker.element, alignToTop !== false); 12028 } else if (op.top > viewportBounds.bottom) { 12029 intoView(marker.element, alignToTop === true); 12030 } 12031 }; 12032 var rangeIntoWindow = function (editor, rng, alignToTop) { 12033 return withMarker(editor, intoWindow, rng, alignToTop); 12034 }; 12035 var elementIntoWindow = function (editor, element, alignToTop) { 12036 return withElement(editor, element, intoWindow, alignToTop); 12037 }; 12038 var rangeIntoFrame = function (editor, rng, alignToTop) { 12039 return withMarker(editor, intoFrame, rng, alignToTop); 12040 }; 12041 var elementIntoFrame = function (editor, element, alignToTop) { 12042 return withElement(editor, element, intoFrame, alignToTop); 12043 }; 12044 var scrollElementIntoView = function (editor, element, alignToTop) { 12045 var scroller = editor.inline ? elementIntoWindow : elementIntoFrame; 12046 scroller(editor, element, alignToTop); 12047 }; 12048 var scrollRangeIntoView = function (editor, rng, alignToTop) { 12049 var scroller = editor.inline ? rangeIntoWindow : rangeIntoFrame; 12050 scroller(editor, rng, alignToTop); 12051 }; 12052 12053 var getDocument = function () { 12054 return SugarElement.fromDom(document); 12055 }; 12056 12057 var focus$1 = function (element) { 12058 return element.dom.focus(); 12059 }; 12060 var hasFocus$1 = function (element) { 12061 var root = getRootNode(element).dom; 12062 return element.dom === root.activeElement; 12063 }; 12064 var active = function (root) { 12065 if (root === void 0) { 12066 root = getDocument(); 12067 } 12068 return Optional.from(root.dom.activeElement).map(SugarElement.fromDom); 12069 }; 12070 var search = function (element) { 12071 return active(getRootNode(element)).filter(function (e) { 12072 return element.dom.contains(e.dom); 12073 }); 12074 }; 12075 12076 var create$5 = function (start, soffset, finish, foffset) { 12077 return { 12078 start: start, 12079 soffset: soffset, 12080 finish: finish, 12081 foffset: foffset 12082 }; 12083 }; 12084 var SimRange = { create: create$5 }; 12085 12086 var adt$1 = Adt.generate([ 12087 { before: ['element'] }, 12088 { 12089 on: [ 12090 'element', 12091 'offset' 12092 ] 12093 }, 12094 { after: ['element'] } 12095 ]); 12096 var cata = function (subject, onBefore, onOn, onAfter) { 12097 return subject.fold(onBefore, onOn, onAfter); 12098 }; 12099 var getStart$2 = function (situ) { 12100 return situ.fold(identity, identity, identity); 12101 }; 12102 var before$1 = adt$1.before; 12103 var on = adt$1.on; 12104 var after$1 = adt$1.after; 12105 var Situ = { 12106 before: before$1, 12107 on: on, 12108 after: after$1, 12109 cata: cata, 12110 getStart: getStart$2 12111 }; 12112 12113 var adt = Adt.generate([ 12114 { domRange: ['rng'] }, 12115 { 12116 relative: [ 12117 'startSitu', 12118 'finishSitu' 12119 ] 12120 }, 12121 { 12122 exact: [ 12123 'start', 12124 'soffset', 12125 'finish', 12126 'foffset' 12127 ] 12128 } 12129 ]); 12130 var exactFromRange = function (simRange) { 12131 return adt.exact(simRange.start, simRange.soffset, simRange.finish, simRange.foffset); 12132 }; 12133 var getStart$1 = function (selection) { 12134 return selection.match({ 12135 domRange: function (rng) { 12136 return SugarElement.fromDom(rng.startContainer); 12137 }, 12138 relative: function (startSitu, _finishSitu) { 12139 return Situ.getStart(startSitu); 12140 }, 12141 exact: function (start, _soffset, _finish, _foffset) { 12142 return start; 12143 } 12144 }); 12145 }; 12146 var domRange = adt.domRange; 12147 var relative = adt.relative; 12148 var exact = adt.exact; 12149 var getWin = function (selection) { 12150 var start = getStart$1(selection); 12151 return defaultView(start); 12152 }; 12153 var range = SimRange.create; 12154 var SimSelection = { 12155 domRange: domRange, 12156 relative: relative, 12157 exact: exact, 12158 exactFromRange: exactFromRange, 12159 getWin: getWin, 12160 range: range 12161 }; 12162 12163 var browser$1 = detect().browser; 12164 var clamp$1 = function (offset, element) { 12165 var max = isText$8(element) ? get$2(element).length : children(element).length + 1; 12166 if (offset > max) { 12167 return max; 12168 } else if (offset < 0) { 12169 return 0; 12170 } 12171 return offset; 12172 }; 12173 var normalizeRng = function (rng) { 12174 return SimSelection.range(rng.start, clamp$1(rng.soffset, rng.start), rng.finish, clamp$1(rng.foffset, rng.finish)); 12175 }; 12176 var isOrContains = function (root, elm) { 12177 return !isRestrictedNode(elm.dom) && (contains$1(root, elm) || eq(root, elm)); 12178 }; 12179 var isRngInRoot = function (root) { 12180 return function (rng) { 12181 return isOrContains(root, rng.start) && isOrContains(root, rng.finish); 12182 }; 12183 }; 12184 var shouldStore = function (editor) { 12185 return editor.inline === true || browser$1.isIE(); 12186 }; 12187 var nativeRangeToSelectionRange = function (r) { 12188 return SimSelection.range(SugarElement.fromDom(r.startContainer), r.startOffset, SugarElement.fromDom(r.endContainer), r.endOffset); 12189 }; 12190 var readRange = function (win) { 12191 var selection = win.getSelection(); 12192 var rng = !selection || selection.rangeCount === 0 ? Optional.none() : Optional.from(selection.getRangeAt(0)); 12193 return rng.map(nativeRangeToSelectionRange); 12194 }; 12195 var getBookmark = function (root) { 12196 var win = defaultView(root); 12197 return readRange(win.dom).filter(isRngInRoot(root)); 12198 }; 12199 var validate = function (root, bookmark) { 12200 return Optional.from(bookmark).filter(isRngInRoot(root)).map(normalizeRng); 12201 }; 12202 var bookmarkToNativeRng = function (bookmark) { 12203 var rng = document.createRange(); 12204 try { 12205 rng.setStart(bookmark.start.dom, bookmark.soffset); 12206 rng.setEnd(bookmark.finish.dom, bookmark.foffset); 12207 return Optional.some(rng); 12208 } catch (_) { 12209 return Optional.none(); 12210 } 12211 }; 12212 var store = function (editor) { 12213 var newBookmark = shouldStore(editor) ? getBookmark(SugarElement.fromDom(editor.getBody())) : Optional.none(); 12214 editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark; 12215 }; 12216 var storeNative = function (editor, rng) { 12217 var root = SugarElement.fromDom(editor.getBody()); 12218 var range = shouldStore(editor) ? Optional.from(rng) : Optional.none(); 12219 var newBookmark = range.map(nativeRangeToSelectionRange).filter(isRngInRoot(root)); 12220 editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark; 12221 }; 12222 var getRng = function (editor) { 12223 var bookmark = editor.bookmark ? editor.bookmark : Optional.none(); 12224 return bookmark.bind(function (x) { 12225 return validate(SugarElement.fromDom(editor.getBody()), x); 12226 }).bind(bookmarkToNativeRng); 12227 }; 12228 var restore = function (editor) { 12229 getRng(editor).each(function (rng) { 12230 return editor.selection.setRng(rng); 12231 }); 12232 }; 12233 12234 var isEditorUIElement$1 = function (elm) { 12235 var className = elm.className.toString(); 12236 return className.indexOf('tox-') !== -1 || className.indexOf('mce-') !== -1; 12237 }; 12238 var FocusManager = { isEditorUIElement: isEditorUIElement$1 }; 12239 12240 var isManualNodeChange = function (e) { 12241 return e.type === 'nodechange' && e.selectionChange; 12242 }; 12243 var registerPageMouseUp = function (editor, throttledStore) { 12244 var mouseUpPage = function () { 12245 throttledStore.throttle(); 12246 }; 12247 DOMUtils.DOM.bind(document, 'mouseup', mouseUpPage); 12248 editor.on('remove', function () { 12249 DOMUtils.DOM.unbind(document, 'mouseup', mouseUpPage); 12250 }); 12251 }; 12252 var registerFocusOut = function (editor) { 12253 editor.on('focusout', function () { 12254 store(editor); 12255 }); 12256 }; 12257 var registerMouseUp = function (editor, throttledStore) { 12258 editor.on('mouseup touchend', function (_e) { 12259 throttledStore.throttle(); 12260 }); 12261 }; 12262 var registerEditorEvents = function (editor, throttledStore) { 12263 var browser = detect().browser; 12264 if (browser.isIE()) { 12265 registerFocusOut(editor); 12266 } else { 12267 registerMouseUp(editor, throttledStore); 12268 } 12269 editor.on('keyup NodeChange', function (e) { 12270 if (!isManualNodeChange(e)) { 12271 store(editor); 12272 } 12273 }); 12274 }; 12275 var register$3 = function (editor) { 12276 var throttledStore = first(function () { 12277 store(editor); 12278 }, 0); 12279 editor.on('init', function () { 12280 if (editor.inline) { 12281 registerPageMouseUp(editor, throttledStore); 12282 } 12283 registerEditorEvents(editor, throttledStore); 12284 }); 12285 editor.on('remove', function () { 12286 throttledStore.cancel(); 12287 }); 12288 }; 12289 12290 var documentFocusInHandler; 12291 var DOM$8 = DOMUtils.DOM; 12292 var isEditorUIElement = function (elm) { 12293 return FocusManager.isEditorUIElement(elm); 12294 }; 12295 var isEditorContentAreaElement = function (elm) { 12296 var classList = elm.classList; 12297 if (classList !== undefined) { 12298 return classList.contains('tox-edit-area') || classList.contains('tox-edit-area__iframe') || classList.contains('mce-content-body'); 12299 } else { 12300 return false; 12301 } 12302 }; 12303 var isUIElement = function (editor, elm) { 12304 var customSelector = getCustomUiSelector(editor); 12305 var parent = DOM$8.getParent(elm, function (elm) { 12306 return isEditorUIElement(elm) || (customSelector ? editor.dom.is(elm, customSelector) : false); 12307 }); 12308 return parent !== null; 12309 }; 12310 var getActiveElement = function (editor) { 12311 try { 12312 var root = getRootNode(SugarElement.fromDom(editor.getElement())); 12313 return active(root).fold(function () { 12314 return document.body; 12315 }, function (x) { 12316 return x.dom; 12317 }); 12318 } catch (ex) { 12319 return document.body; 12320 } 12321 }; 12322 var registerEvents$1 = function (editorManager, e) { 12323 var editor = e.editor; 12324 register$3(editor); 12325 editor.on('focusin', function () { 12326 var focusedEditor = editorManager.focusedEditor; 12327 if (focusedEditor !== editor) { 12328 if (focusedEditor) { 12329 focusedEditor.fire('blur', { focusedEditor: editor }); 12330 } 12331 editorManager.setActive(editor); 12332 editorManager.focusedEditor = editor; 12333 editor.fire('focus', { blurredEditor: focusedEditor }); 12334 editor.focus(true); 12335 } 12336 }); 12337 editor.on('focusout', function () { 12338 Delay.setEditorTimeout(editor, function () { 12339 var focusedEditor = editorManager.focusedEditor; 12340 if (!isUIElement(editor, getActiveElement(editor)) && focusedEditor === editor) { 12341 editor.fire('blur', { focusedEditor: null }); 12342 editorManager.focusedEditor = null; 12343 } 12344 }); 12345 }); 12346 if (!documentFocusInHandler) { 12347 documentFocusInHandler = function (e) { 12348 var activeEditor = editorManager.activeEditor; 12349 if (activeEditor) { 12350 getOriginalEventTarget(e).each(function (target) { 12351 if (target.ownerDocument === document) { 12352 if (target !== document.body && !isUIElement(activeEditor, target) && editorManager.focusedEditor === activeEditor) { 12353 activeEditor.fire('blur', { focusedEditor: null }); 12354 editorManager.focusedEditor = null; 12355 } 12356 } 12357 }); 12358 } 12359 }; 12360 DOM$8.bind(document, 'focusin', documentFocusInHandler); 12361 } 12362 }; 12363 var unregisterDocumentEvents = function (editorManager, e) { 12364 if (editorManager.focusedEditor === e.editor) { 12365 editorManager.focusedEditor = null; 12366 } 12367 if (!editorManager.activeEditor) { 12368 DOM$8.unbind(document, 'focusin', documentFocusInHandler); 12369 documentFocusInHandler = null; 12370 } 12371 }; 12372 var setup$l = function (editorManager) { 12373 editorManager.on('AddEditor', curry(registerEvents$1, editorManager)); 12374 editorManager.on('RemoveEditor', curry(unregisterDocumentEvents, editorManager)); 12375 }; 12376 12377 var getContentEditableHost = function (editor, node) { 12378 return editor.dom.getParent(node, function (node) { 12379 return editor.dom.getContentEditable(node) === 'true'; 12380 }); 12381 }; 12382 var getCollapsedNode = function (rng) { 12383 return rng.collapsed ? Optional.from(getNode$1(rng.startContainer, rng.startOffset)).map(SugarElement.fromDom) : Optional.none(); 12384 }; 12385 var getFocusInElement = function (root, rng) { 12386 return getCollapsedNode(rng).bind(function (node) { 12387 if (isTableSection(node)) { 12388 return Optional.some(node); 12389 } else if (contains$1(root, node) === false) { 12390 return Optional.some(root); 12391 } else { 12392 return Optional.none(); 12393 } 12394 }); 12395 }; 12396 var normalizeSelection$1 = function (editor, rng) { 12397 getFocusInElement(SugarElement.fromDom(editor.getBody()), rng).bind(function (elm) { 12398 return firstPositionIn(elm.dom); 12399 }).fold(function () { 12400 editor.selection.normalize(); 12401 return; 12402 }, function (caretPos) { 12403 return editor.selection.setRng(caretPos.toRange()); 12404 }); 12405 }; 12406 var focusBody = function (body) { 12407 if (body.setActive) { 12408 try { 12409 body.setActive(); 12410 } catch (ex) { 12411 body.focus(); 12412 } 12413 } else { 12414 body.focus(); 12415 } 12416 }; 12417 var hasElementFocus = function (elm) { 12418 return hasFocus$1(elm) || search(elm).isSome(); 12419 }; 12420 var hasIframeFocus = function (editor) { 12421 return editor.iframeElement && hasFocus$1(SugarElement.fromDom(editor.iframeElement)); 12422 }; 12423 var hasInlineFocus = function (editor) { 12424 var rawBody = editor.getBody(); 12425 return rawBody && hasElementFocus(SugarElement.fromDom(rawBody)); 12426 }; 12427 var hasUiFocus = function (editor) { 12428 var dos = getRootNode(SugarElement.fromDom(editor.getElement())); 12429 return active(dos).filter(function (elem) { 12430 return !isEditorContentAreaElement(elem.dom) && isUIElement(editor, elem.dom); 12431 }).isSome(); 12432 }; 12433 var hasFocus = function (editor) { 12434 return editor.inline ? hasInlineFocus(editor) : hasIframeFocus(editor); 12435 }; 12436 var hasEditorOrUiFocus = function (editor) { 12437 return hasFocus(editor) || hasUiFocus(editor); 12438 }; 12439 var focusEditor = function (editor) { 12440 var selection = editor.selection; 12441 var body = editor.getBody(); 12442 var rng = selection.getRng(); 12443 editor.quirks.refreshContentEditable(); 12444 if (editor.bookmark !== undefined && hasFocus(editor) === false) { 12445 getRng(editor).each(function (bookmarkRng) { 12446 editor.selection.setRng(bookmarkRng); 12447 rng = bookmarkRng; 12448 }); 12449 } 12450 var contentEditableHost = getContentEditableHost(editor, selection.getNode()); 12451 if (editor.$.contains(body, contentEditableHost)) { 12452 focusBody(contentEditableHost); 12453 normalizeSelection$1(editor, rng); 12454 activateEditor(editor); 12455 return; 12456 } 12457 if (!editor.inline) { 12458 if (!Env.opera) { 12459 focusBody(body); 12460 } 12461 editor.getWin().focus(); 12462 } 12463 if (Env.gecko || editor.inline) { 12464 focusBody(body); 12465 normalizeSelection$1(editor, rng); 12466 } 12467 activateEditor(editor); 12468 }; 12469 var activateEditor = function (editor) { 12470 return editor.editorManager.setActive(editor); 12471 }; 12472 var focus = function (editor, skipFocus) { 12473 if (editor.removed) { 12474 return; 12475 } 12476 if (skipFocus) { 12477 activateEditor(editor); 12478 } else { 12479 focusEditor(editor); 12480 } 12481 }; 12482 12483 var getEndpointElement = function (root, rng, start, real, resolve) { 12484 var container = start ? rng.startContainer : rng.endContainer; 12485 var offset = start ? rng.startOffset : rng.endOffset; 12486 return Optional.from(container).map(SugarElement.fromDom).map(function (elm) { 12487 return !real || !rng.collapsed ? child$1(elm, resolve(elm, offset)).getOr(elm) : elm; 12488 }).bind(function (elm) { 12489 return isElement$6(elm) ? Optional.some(elm) : parent(elm).filter(isElement$6); 12490 }).map(function (elm) { 12491 return elm.dom; 12492 }).getOr(root); 12493 }; 12494 var getStart = function (root, rng, real) { 12495 return getEndpointElement(root, rng, true, real, function (elm, offset) { 12496 return Math.min(childNodesCount(elm), offset); 12497 }); 12498 }; 12499 var getEnd = function (root, rng, real) { 12500 return getEndpointElement(root, rng, false, real, function (elm, offset) { 12501 return offset > 0 ? offset - 1 : offset; 12502 }); 12503 }; 12504 var skipEmptyTextNodes = function (node, forwards) { 12505 var orig = node; 12506 while (node && isText$7(node) && node.length === 0) { 12507 node = forwards ? node.nextSibling : node.previousSibling; 12508 } 12509 return node || orig; 12510 }; 12511 var getNode = function (root, rng) { 12512 var elm, startContainer, endContainer; 12513 if (!rng) { 12514 return root; 12515 } 12516 startContainer = rng.startContainer; 12517 endContainer = rng.endContainer; 12518 var startOffset = rng.startOffset; 12519 var endOffset = rng.endOffset; 12520 elm = rng.commonAncestorContainer; 12521 if (!rng.collapsed) { 12522 if (startContainer === endContainer) { 12523 if (endOffset - startOffset < 2) { 12524 if (startContainer.hasChildNodes()) { 12525 elm = startContainer.childNodes[startOffset]; 12526 } 12527 } 12528 } 12529 if (startContainer.nodeType === 3 && endContainer.nodeType === 3) { 12530 if (startContainer.length === startOffset) { 12531 startContainer = skipEmptyTextNodes(startContainer.nextSibling, true); 12532 } else { 12533 startContainer = startContainer.parentNode; 12534 } 12535 if (endOffset === 0) { 12536 endContainer = skipEmptyTextNodes(endContainer.previousSibling, false); 12537 } else { 12538 endContainer = endContainer.parentNode; 12539 } 12540 if (startContainer && startContainer === endContainer) { 12541 return startContainer; 12542 } 12543 } 12544 } 12545 if (elm && elm.nodeType === 3) { 12546 return elm.parentNode; 12547 } 12548 return elm; 12549 }; 12550 var getSelectedBlocks = function (dom, rng, startElm, endElm) { 12551 var node; 12552 var selectedBlocks = []; 12553 var root = dom.getRoot(); 12554 startElm = dom.getParent(startElm || getStart(root, rng, rng.collapsed), dom.isBlock); 12555 endElm = dom.getParent(endElm || getEnd(root, rng, rng.collapsed), dom.isBlock); 12556 if (startElm && startElm !== root) { 12557 selectedBlocks.push(startElm); 12558 } 12559 if (startElm && endElm && startElm !== endElm) { 12560 node = startElm; 12561 var walker = new DomTreeWalker(startElm, root); 12562 while ((node = walker.next()) && node !== endElm) { 12563 if (dom.isBlock(node)) { 12564 selectedBlocks.push(node); 12565 } 12566 } 12567 } 12568 if (endElm && startElm !== endElm && endElm !== root) { 12569 selectedBlocks.push(endElm); 12570 } 12571 return selectedBlocks; 12572 }; 12573 var select = function (dom, node, content) { 12574 return Optional.from(node).map(function (node) { 12575 var idx = dom.nodeIndex(node); 12576 var rng = dom.createRng(); 12577 rng.setStart(node.parentNode, idx); 12578 rng.setEnd(node.parentNode, idx + 1); 12579 if (content) { 12580 moveEndPoint(dom, rng, node, true); 12581 moveEndPoint(dom, rng, node, false); 12582 } 12583 return rng; 12584 }); 12585 }; 12586 12587 var processRanges = function (editor, ranges) { 12588 return map$3(ranges, function (range) { 12589 var evt = editor.fire('GetSelectionRange', { range: range }); 12590 return evt.range !== range ? evt.range : range; 12591 }); 12592 }; 12593 12594 var typeLookup = { 12595 '#text': 3, 12596 '#comment': 8, 12597 '#cdata': 4, 12598 '#pi': 7, 12599 '#doctype': 10, 12600 '#document-fragment': 11 12601 }; 12602 var walk$1 = function (node, root, prev) { 12603 var startName = prev ? 'lastChild' : 'firstChild'; 12604 var siblingName = prev ? 'prev' : 'next'; 12605 if (node[startName]) { 12606 return node[startName]; 12607 } 12608 if (node !== root) { 12609 var sibling = node[siblingName]; 12610 if (sibling) { 12611 return sibling; 12612 } 12613 for (var parent_1 = node.parent; parent_1 && parent_1 !== root; parent_1 = parent_1.parent) { 12614 sibling = parent_1[siblingName]; 12615 if (sibling) { 12616 return sibling; 12617 } 12618 } 12619 } 12620 }; 12621 var isEmptyTextNode = function (node) { 12622 if (!isWhitespaceText(node.value)) { 12623 return false; 12624 } 12625 var parentNode = node.parent; 12626 if (parentNode && (parentNode.name !== 'span' || parentNode.attr('style')) && /^[ ]+$/.test(node.value)) { 12627 return false; 12628 } 12629 return true; 12630 }; 12631 var isNonEmptyElement = function (node) { 12632 var isNamedAnchor = node.name === 'a' && !node.attr('href') && node.attr('id'); 12633 return node.attr('name') || node.attr('id') && !node.firstChild || node.attr('data-mce-bookmark') || isNamedAnchor; 12634 }; 12635 var AstNode = function () { 12636 function AstNode(name, type) { 12637 this.name = name; 12638 this.type = type; 12639 if (type === 1) { 12640 this.attributes = []; 12641 this.attributes.map = {}; 12642 } 12643 } 12644 AstNode.create = function (name, attrs) { 12645 var node = new AstNode(name, typeLookup[name] || 1); 12646 if (attrs) { 12647 each$j(attrs, function (value, attrName) { 12648 node.attr(attrName, value); 12649 }); 12650 } 12651 return node; 12652 }; 12653 AstNode.prototype.replace = function (node) { 12654 var self = this; 12655 if (node.parent) { 12656 node.remove(); 12657 } 12658 self.insert(node, self); 12659 self.remove(); 12660 return self; 12661 }; 12662 AstNode.prototype.attr = function (name, value) { 12663 var self = this; 12664 var attrs; 12665 if (typeof name !== 'string') { 12666 if (name !== undefined && name !== null) { 12667 each$j(name, function (value, key) { 12668 self.attr(key, value); 12669 }); 12670 } 12671 return self; 12672 } 12673 if (attrs = self.attributes) { 12674 if (value !== undefined) { 12675 if (value === null) { 12676 if (name in attrs.map) { 12677 delete attrs.map[name]; 12678 var i = attrs.length; 12679 while (i--) { 12680 if (attrs[i].name === name) { 12681 attrs.splice(i, 1); 12682 return self; 12683 } 12684 } 12685 } 12686 return self; 12687 } 12688 if (name in attrs.map) { 12689 var i = attrs.length; 12690 while (i--) { 12691 if (attrs[i].name === name) { 12692 attrs[i].value = value; 12693 break; 12694 } 12695 } 12696 } else { 12697 attrs.push({ 12698 name: name, 12699 value: value 12700 }); 12701 } 12702 attrs.map[name] = value; 12703 return self; 12704 } 12705 return attrs.map[name]; 12706 } 12707 }; 12708 AstNode.prototype.clone = function () { 12709 var self = this; 12710 var clone = new AstNode(self.name, self.type); 12711 var selfAttrs; 12712 if (selfAttrs = self.attributes) { 12713 var cloneAttrs = []; 12714 cloneAttrs.map = {}; 12715 for (var i = 0, l = selfAttrs.length; i < l; i++) { 12716 var selfAttr = selfAttrs[i]; 12717 if (selfAttr.name !== 'id') { 12718 cloneAttrs[cloneAttrs.length] = { 12719 name: selfAttr.name, 12720 value: selfAttr.value 12721 }; 12722 cloneAttrs.map[selfAttr.name] = selfAttr.value; 12723 } 12724 } 12725 clone.attributes = cloneAttrs; 12726 } 12727 clone.value = self.value; 12728 clone.shortEnded = self.shortEnded; 12729 return clone; 12730 }; 12731 AstNode.prototype.wrap = function (wrapper) { 12732 var self = this; 12733 self.parent.insert(wrapper, self); 12734 wrapper.append(self); 12735 return self; 12736 }; 12737 AstNode.prototype.unwrap = function () { 12738 var self = this; 12739 for (var node = self.firstChild; node;) { 12740 var next = node.next; 12741 self.insert(node, self, true); 12742 node = next; 12743 } 12744 self.remove(); 12745 }; 12746 AstNode.prototype.remove = function () { 12747 var self = this, parent = self.parent, next = self.next, prev = self.prev; 12748 if (parent) { 12749 if (parent.firstChild === self) { 12750 parent.firstChild = next; 12751 if (next) { 12752 next.prev = null; 12753 } 12754 } else { 12755 prev.next = next; 12756 } 12757 if (parent.lastChild === self) { 12758 parent.lastChild = prev; 12759 if (prev) { 12760 prev.next = null; 12761 } 12762 } else { 12763 next.prev = prev; 12764 } 12765 self.parent = self.next = self.prev = null; 12766 } 12767 return self; 12768 }; 12769 AstNode.prototype.append = function (node) { 12770 var self = this; 12771 if (node.parent) { 12772 node.remove(); 12773 } 12774 var last = self.lastChild; 12775 if (last) { 12776 last.next = node; 12777 node.prev = last; 12778 self.lastChild = node; 12779 } else { 12780 self.lastChild = self.firstChild = node; 12781 } 12782 node.parent = self; 12783 return node; 12784 }; 12785 AstNode.prototype.insert = function (node, refNode, before) { 12786 if (node.parent) { 12787 node.remove(); 12788 } 12789 var parent = refNode.parent || this; 12790 if (before) { 12791 if (refNode === parent.firstChild) { 12792 parent.firstChild = node; 12793 } else { 12794 refNode.prev.next = node; 12795 } 12796 node.prev = refNode.prev; 12797 node.next = refNode; 12798 refNode.prev = node; 12799 } else { 12800 if (refNode === parent.lastChild) { 12801 parent.lastChild = node; 12802 } else { 12803 refNode.next.prev = node; 12804 } 12805 node.next = refNode.next; 12806 node.prev = refNode; 12807 refNode.next = node; 12808 } 12809 node.parent = parent; 12810 return node; 12811 }; 12812 AstNode.prototype.getAll = function (name) { 12813 var self = this; 12814 var collection = []; 12815 for (var node = self.firstChild; node; node = walk$1(node, self)) { 12816 if (node.name === name) { 12817 collection.push(node); 12818 } 12819 } 12820 return collection; 12821 }; 12822 AstNode.prototype.children = function () { 12823 var self = this; 12824 var collection = []; 12825 for (var node = self.firstChild; node; node = node.next) { 12826 collection.push(node); 12827 } 12828 return collection; 12829 }; 12830 AstNode.prototype.empty = function () { 12831 var self = this; 12832 if (self.firstChild) { 12833 var nodes = []; 12834 for (var node = self.firstChild; node; node = walk$1(node, self)) { 12835 nodes.push(node); 12836 } 12837 var i = nodes.length; 12838 while (i--) { 12839 var node = nodes[i]; 12840 node.parent = node.firstChild = node.lastChild = node.next = node.prev = null; 12841 } 12842 } 12843 self.firstChild = self.lastChild = null; 12844 return self; 12845 }; 12846 AstNode.prototype.isEmpty = function (elements, whitespace, predicate) { 12847 if (whitespace === void 0) { 12848 whitespace = {}; 12849 } 12850 var self = this; 12851 var node = self.firstChild; 12852 if (isNonEmptyElement(self)) { 12853 return false; 12854 } 12855 if (node) { 12856 do { 12857 if (node.type === 1) { 12858 if (node.attr('data-mce-bogus')) { 12859 continue; 12860 } 12861 if (elements[node.name]) { 12862 return false; 12863 } 12864 if (isNonEmptyElement(node)) { 12865 return false; 12866 } 12867 } 12868 if (node.type === 8) { 12869 return false; 12870 } 12871 if (node.type === 3 && !isEmptyTextNode(node)) { 12872 return false; 12873 } 12874 if (node.type === 3 && node.parent && whitespace[node.parent.name] && isWhitespaceText(node.value)) { 12875 return false; 12876 } 12877 if (predicate && predicate(node)) { 12878 return false; 12879 } 12880 } while (node = walk$1(node, self)); 12881 } 12882 return true; 12883 }; 12884 AstNode.prototype.walk = function (prev) { 12885 return walk$1(this, null, prev); 12886 }; 12887 return AstNode; 12888 }(); 12889 12890 var extractBase64DataUris = function (html) { 12891 var dataImageUri = /data:[^;<"'\s]+;base64,([a-z0-9\+\/=\s]+)/gi; 12892 var chunks = []; 12893 var uris = {}; 12894 var prefix = generate('img'); 12895 var matches; 12896 var index = 0; 12897 var count = 0; 12898 while (matches = dataImageUri.exec(html)) { 12899 var uri = matches[0]; 12900 var imageId = prefix + '_' + count++; 12901 uris[imageId] = uri; 12902 if (index < matches.index) { 12903 chunks.push(html.substr(index, matches.index - index)); 12904 } 12905 chunks.push(imageId); 12906 index = matches.index + uri.length; 12907 } 12908 var re = new RegExp(prefix + '_[0-9]+', 'g'); 12909 if (index === 0) { 12910 return { 12911 prefix: prefix, 12912 uris: uris, 12913 html: html, 12914 re: re 12915 }; 12916 } else { 12917 if (index < html.length) { 12918 chunks.push(html.substr(index)); 12919 } 12920 return { 12921 prefix: prefix, 12922 uris: uris, 12923 html: chunks.join(''), 12924 re: re 12925 }; 12926 } 12927 }; 12928 var restoreDataUris = function (html, result) { 12929 return html.replace(result.re, function (imageId) { 12930 return get$9(result.uris, imageId).getOr(imageId); 12931 }); 12932 }; 12933 var parseDataUri$1 = function (uri) { 12934 var matches = /data:([^;]+);base64,([a-z0-9\+\/=\s]+)/i.exec(uri); 12935 if (matches) { 12936 return Optional.some({ 12937 type: matches[1], 12938 data: decodeURIComponent(matches[2]) 12939 }); 12940 } else { 12941 return Optional.none(); 12942 } 12943 }; 12944 12945 var each$d = Tools.each, trim = Tools.trim; 12946 var queryParts = 'source protocol authority userInfo user password host port relative path directory file query anchor'.split(' '); 12947 var DEFAULT_PORTS = { 12948 ftp: 21, 12949 http: 80, 12950 https: 443, 12951 mailto: 25 12952 }; 12953 var safeSvgDataUrlElements = [ 12954 'img', 12955 'video' 12956 ]; 12957 var blockSvgDataUris = function (allowSvgDataUrls, tagName) { 12958 if (isNonNullable(allowSvgDataUrls)) { 12959 return !allowSvgDataUrls; 12960 } else { 12961 return isNonNullable(tagName) ? !contains$3(safeSvgDataUrlElements, tagName) : true; 12962 } 12963 }; 12964 var isInvalidUri = function (settings, uri, tagName) { 12965 if (settings.allow_html_data_urls) { 12966 return false; 12967 } else if (/^data:image\//i.test(uri)) { 12968 return blockSvgDataUris(settings.allow_svg_data_urls, tagName) && /^data:image\/svg\+xml/i.test(uri); 12969 } else { 12970 return /^data:/i.test(uri); 12971 } 12972 }; 12973 var URI = function () { 12974 function URI(url, settings) { 12975 url = trim(url); 12976 this.settings = settings || {}; 12977 var baseUri = this.settings.base_uri; 12978 var self = this; 12979 if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) { 12980 self.source = url; 12981 return; 12982 } 12983 var isProtocolRelative = url.indexOf('//') === 0; 12984 if (url.indexOf('/') === 0 && !isProtocolRelative) { 12985 url = (baseUri ? baseUri.protocol || 'http' : 'http') + '://mce_host' + url; 12986 } 12987 if (!/^[\w\-]*:?\/\//.test(url)) { 12988 var baseUrl = this.settings.base_uri ? this.settings.base_uri.path : new URI(document.location.href).directory; 12989 if (this.settings.base_uri && this.settings.base_uri.protocol == '') { 12990 url = '//mce_host' + self.toAbsPath(baseUrl, url); 12991 } else { 12992 var match = /([^#?]*)([#?]?.*)/.exec(url); 12993 url = (baseUri && baseUri.protocol || 'http') + '://mce_host' + self.toAbsPath(baseUrl, match[1]) + match[2]; 12994 } 12995 } 12996 url = url.replace(/@@/g, '(mce_at)'); 12997 var urlMatch = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?(\[[a-zA-Z0-9:.%]+\]|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url); 12998 each$d(queryParts, function (v, i) { 12999 var part = urlMatch[i]; 13000 if (part) { 13001 part = part.replace(/\(mce_at\)/g, '@@'); 13002 } 13003 self[v] = part; 13004 }); 13005 if (baseUri) { 13006 if (!self.protocol) { 13007 self.protocol = baseUri.protocol; 13008 } 13009 if (!self.userInfo) { 13010 self.userInfo = baseUri.userInfo; 13011 } 13012 if (!self.port && self.host === 'mce_host') { 13013 self.port = baseUri.port; 13014 } 13015 if (!self.host || self.host === 'mce_host') { 13016 self.host = baseUri.host; 13017 } 13018 self.source = ''; 13019 } 13020 if (isProtocolRelative) { 13021 self.protocol = ''; 13022 } 13023 } 13024 URI.parseDataUri = function (uri) { 13025 var type; 13026 var uriComponents = decodeURIComponent(uri).split(','); 13027 var matches = /data:([^;]+)/.exec(uriComponents[0]); 13028 if (matches) { 13029 type = matches[1]; 13030 } 13031 return { 13032 type: type, 13033 data: uriComponents[1] 13034 }; 13035 }; 13036 URI.isDomSafe = function (uri, context, options) { 13037 if (options === void 0) { 13038 options = {}; 13039 } 13040 if (options.allow_script_urls) { 13041 return true; 13042 } else { 13043 var decodedUri = Entities.decode(uri).replace(/[\s\u0000-\u001F]+/g, ''); 13044 try { 13045 decodedUri = decodeURIComponent(decodedUri); 13046 } catch (ex) { 13047 decodedUri = unescape(decodedUri); 13048 } 13049 if (/((java|vb)script|mhtml):/i.test(decodedUri)) { 13050 return false; 13051 } 13052 return !isInvalidUri(options, decodedUri, context); 13053 } 13054 }; 13055 URI.getDocumentBaseUrl = function (loc) { 13056 var baseUrl; 13057 if (loc.protocol.indexOf('http') !== 0 && loc.protocol !== 'file:') { 13058 baseUrl = loc.href; 13059 } else { 13060 baseUrl = loc.protocol + '//' + loc.host + loc.pathname; 13061 } 13062 if (/^[^:]+:\/\/\/?[^\/]+\//.test(baseUrl)) { 13063 baseUrl = baseUrl.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, ''); 13064 if (!/[\/\\]$/.test(baseUrl)) { 13065 baseUrl += '/'; 13066 } 13067 } 13068 return baseUrl; 13069 }; 13070 URI.prototype.setPath = function (path) { 13071 var pathMatch = /^(.*?)\/?(\w+)?$/.exec(path); 13072 this.path = pathMatch[0]; 13073 this.directory = pathMatch[1]; 13074 this.file = pathMatch[2]; 13075 this.source = ''; 13076 this.getURI(); 13077 }; 13078 URI.prototype.toRelative = function (uri) { 13079 var output; 13080 if (uri === './') { 13081 return uri; 13082 } 13083 var relativeUri = new URI(uri, { base_uri: this }); 13084 if (relativeUri.host !== 'mce_host' && this.host !== relativeUri.host && relativeUri.host || this.port !== relativeUri.port || this.protocol !== relativeUri.protocol && relativeUri.protocol !== '') { 13085 return relativeUri.getURI(); 13086 } 13087 var tu = this.getURI(), uu = relativeUri.getURI(); 13088 if (tu === uu || tu.charAt(tu.length - 1) === '/' && tu.substr(0, tu.length - 1) === uu) { 13089 return tu; 13090 } 13091 output = this.toRelPath(this.path, relativeUri.path); 13092 if (relativeUri.query) { 13093 output += '?' + relativeUri.query; 13094 } 13095 if (relativeUri.anchor) { 13096 output += '#' + relativeUri.anchor; 13097 } 13098 return output; 13099 }; 13100 URI.prototype.toAbsolute = function (uri, noHost) { 13101 var absoluteUri = new URI(uri, { base_uri: this }); 13102 return absoluteUri.getURI(noHost && this.isSameOrigin(absoluteUri)); 13103 }; 13104 URI.prototype.isSameOrigin = function (uri) { 13105 if (this.host == uri.host && this.protocol == uri.protocol) { 13106 if (this.port == uri.port) { 13107 return true; 13108 } 13109 var defaultPort = DEFAULT_PORTS[this.protocol]; 13110 if (defaultPort && (this.port || defaultPort) == (uri.port || defaultPort)) { 13111 return true; 13112 } 13113 } 13114 return false; 13115 }; 13116 URI.prototype.toRelPath = function (base, path) { 13117 var breakPoint = 0, out = '', i, l; 13118 var normalizedBase = base.substring(0, base.lastIndexOf('/')).split('/'); 13119 var items = path.split('/'); 13120 if (normalizedBase.length >= items.length) { 13121 for (i = 0, l = normalizedBase.length; i < l; i++) { 13122 if (i >= items.length || normalizedBase[i] !== items[i]) { 13123 breakPoint = i + 1; 13124 break; 13125 } 13126 } 13127 } 13128 if (normalizedBase.length < items.length) { 13129 for (i = 0, l = items.length; i < l; i++) { 13130 if (i >= normalizedBase.length || normalizedBase[i] !== items[i]) { 13131 breakPoint = i + 1; 13132 break; 13133 } 13134 } 13135 } 13136 if (breakPoint === 1) { 13137 return path; 13138 } 13139 for (i = 0, l = normalizedBase.length - (breakPoint - 1); i < l; i++) { 13140 out += '../'; 13141 } 13142 for (i = breakPoint - 1, l = items.length; i < l; i++) { 13143 if (i !== breakPoint - 1) { 13144 out += '/' + items[i]; 13145 } else { 13146 out += items[i]; 13147 } 13148 } 13149 return out; 13150 }; 13151 URI.prototype.toAbsPath = function (base, path) { 13152 var i, nb = 0, o = [], outPath; 13153 var tr = /\/$/.test(path) ? '/' : ''; 13154 var normalizedBase = base.split('/'); 13155 var normalizedPath = path.split('/'); 13156 each$d(normalizedBase, function (k) { 13157 if (k) { 13158 o.push(k); 13159 } 13160 }); 13161 normalizedBase = o; 13162 for (i = normalizedPath.length - 1, o = []; i >= 0; i--) { 13163 if (normalizedPath[i].length === 0 || normalizedPath[i] === '.') { 13164 continue; 13165 } 13166 if (normalizedPath[i] === '..') { 13167 nb++; 13168 continue; 13169 } 13170 if (nb > 0) { 13171 nb--; 13172 continue; 13173 } 13174 o.push(normalizedPath[i]); 13175 } 13176 i = normalizedBase.length - nb; 13177 if (i <= 0) { 13178 outPath = reverse(o).join('/'); 13179 } else { 13180 outPath = normalizedBase.slice(0, i).join('/') + '/' + reverse(o).join('/'); 13181 } 13182 if (outPath.indexOf('/') !== 0) { 13183 outPath = '/' + outPath; 13184 } 13185 if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) { 13186 outPath += tr; 13187 } 13188 return outPath; 13189 }; 13190 URI.prototype.getURI = function (noProtoHost) { 13191 if (noProtoHost === void 0) { 13192 noProtoHost = false; 13193 } 13194 var s; 13195 if (!this.source || noProtoHost) { 13196 s = ''; 13197 if (!noProtoHost) { 13198 if (this.protocol) { 13199 s += this.protocol + '://'; 13200 } else { 13201 s += '//'; 13202 } 13203 if (this.userInfo) { 13204 s += this.userInfo + '@'; 13205 } 13206 if (this.host) { 13207 s += this.host; 13208 } 13209 if (this.port) { 13210 s += ':' + this.port; 13211 } 13212 } 13213 if (this.path) { 13214 s += this.path; 13215 } 13216 if (this.query) { 13217 s += '?' + this.query; 13218 } 13219 if (this.anchor) { 13220 s += '#' + this.anchor; 13221 } 13222 this.source = s; 13223 } 13224 return this.source; 13225 }; 13226 return URI; 13227 }(); 13228 13229 var filteredClobberElements = Tools.makeMap('button,fieldset,form,iframe,img,image,input,object,output,select,textarea'); 13230 var isValidPrefixAttrName = function (name) { 13231 return name.indexOf('data-') === 0 || name.indexOf('aria-') === 0; 13232 }; 13233 var findMatchingEndTagIndex = function (schema, html, startIndex) { 13234 var startTagRegExp = /<([!?\/])?([A-Za-z0-9\-_:.]+)/g; 13235 var endTagRegExp = /(?:\s(?:[^'">]+(?:"[^"]*"|'[^']*'))*[^"'>]*(?:"[^">]*|'[^'>]*)?|\s*|\/)>/g; 13236 var shortEndedElements = schema.getShortEndedElements(); 13237 var count = 1, index = startIndex; 13238 while (count !== 0) { 13239 startTagRegExp.lastIndex = index; 13240 while (true) { 13241 var startMatch = startTagRegExp.exec(html); 13242 if (startMatch === null) { 13243 return index; 13244 } else if (startMatch[1] === '!') { 13245 if (startsWith(startMatch[2], '--')) { 13246 index = findCommentEndIndex(html, false, startMatch.index + '!--'.length); 13247 } else { 13248 index = findCommentEndIndex(html, true, startMatch.index + 1); 13249 } 13250 break; 13251 } else { 13252 endTagRegExp.lastIndex = startTagRegExp.lastIndex; 13253 var endMatch = endTagRegExp.exec(html); 13254 if (isNull(endMatch) || endMatch.index !== startTagRegExp.lastIndex) { 13255 continue; 13256 } 13257 if (startMatch[1] === '/') { 13258 count -= 1; 13259 } else if (!has$2(shortEndedElements, startMatch[2])) { 13260 count += 1; 13261 } 13262 index = startTagRegExp.lastIndex + endMatch[0].length; 13263 break; 13264 } 13265 } 13266 } 13267 return index; 13268 }; 13269 var isConditionalComment = function (html, startIndex) { 13270 return /^\s*\[if [\w\W]+\]>.*<!\[endif\](--!?)?>/.test(html.substr(startIndex)); 13271 }; 13272 var findCommentEndIndex = function (html, isBogus, startIndex) { 13273 if (startIndex === void 0) { 13274 startIndex = 0; 13275 } 13276 var lcHtml = html.toLowerCase(); 13277 if (lcHtml.indexOf('[if ', startIndex) !== -1 && isConditionalComment(lcHtml, startIndex)) { 13278 var endIfIndex = lcHtml.indexOf('[endif]', startIndex); 13279 return lcHtml.indexOf('>', endIfIndex); 13280 } else { 13281 if (isBogus) { 13282 var endIndex = lcHtml.indexOf('>', startIndex); 13283 return endIndex !== -1 ? endIndex : lcHtml.length; 13284 } else { 13285 var endCommentRegexp = /--!?>/g; 13286 endCommentRegexp.lastIndex = startIndex; 13287 var match = endCommentRegexp.exec(html); 13288 return match ? match.index + match[0].length : lcHtml.length; 13289 } 13290 } 13291 }; 13292 var checkBogusAttribute = function (regExp, attrString) { 13293 var matches = regExp.exec(attrString); 13294 if (matches) { 13295 var name_1 = matches[1]; 13296 var value = matches[2]; 13297 return typeof name_1 === 'string' && name_1.toLowerCase() === 'data-mce-bogus' ? value : null; 13298 } else { 13299 return null; 13300 } 13301 }; 13302 var SaxParser = function (settings, schema) { 13303 var _a; 13304 if (schema === void 0) { 13305 schema = Schema(); 13306 } 13307 settings = settings || {}; 13308 var doc = (_a = settings.document) !== null && _a !== void 0 ? _a : document; 13309 var form = doc.createElement('form'); 13310 if (settings.fix_self_closing !== false) { 13311 settings.fix_self_closing = true; 13312 } 13313 var comment = settings.comment ? settings.comment : noop; 13314 var cdata = settings.cdata ? settings.cdata : noop; 13315 var text = settings.text ? settings.text : noop; 13316 var start = settings.start ? settings.start : noop; 13317 var end = settings.end ? settings.end : noop; 13318 var pi = settings.pi ? settings.pi : noop; 13319 var doctype = settings.doctype ? settings.doctype : noop; 13320 var parseInternal = function (base64Extract, format) { 13321 if (format === void 0) { 13322 format = 'html'; 13323 } 13324 var html = base64Extract.html; 13325 var matches, index = 0, value, endRegExp; 13326 var stack = []; 13327 var attrList, i, textData, name; 13328 var isInternalElement, isShortEnded; 13329 var elementRule, isValidElement, attr, attribsValue, validAttributesMap, validAttributePatterns; 13330 var attributesRequired, attributesDefault, attributesForced; 13331 var anyAttributesRequired, attrValue, idCount = 0; 13332 var decode = Entities.decode; 13333 var filteredUrlAttrs = Tools.makeMap('src,href,data,background,action,formaction,poster,xlink:href'); 13334 var parsingMode = format === 'html' ? 0 : 1; 13335 var processEndTag = function (name) { 13336 var pos, i; 13337 pos = stack.length; 13338 while (pos--) { 13339 if (stack[pos].name === name) { 13340 break; 13341 } 13342 } 13343 if (pos >= 0) { 13344 for (i = stack.length - 1; i >= pos; i--) { 13345 name = stack[i]; 13346 if (name.valid) { 13347 end(name.name); 13348 } 13349 } 13350 stack.length = pos; 13351 } 13352 }; 13353 var processText = function (value, raw) { 13354 return text(restoreDataUris(value, base64Extract), raw); 13355 }; 13356 var processComment = function (value) { 13357 if (value === '') { 13358 return; 13359 } 13360 if (value.charAt(0) === '>') { 13361 value = ' ' + value; 13362 } 13363 if (!settings.allow_conditional_comments && value.substr(0, 3).toLowerCase() === '[if') { 13364 value = ' ' + value; 13365 } 13366 comment(restoreDataUris(value, base64Extract)); 13367 }; 13368 var processAttr = function (value) { 13369 return restoreDataUris(value, base64Extract); 13370 }; 13371 var processMalformedComment = function (value, startIndex) { 13372 var startTag = value || ''; 13373 var isBogus = !startsWith(startTag, '--'); 13374 var endIndex = findCommentEndIndex(html, isBogus, startIndex); 13375 value = html.substr(startIndex, endIndex - startIndex); 13376 processComment(isBogus ? startTag + value : value); 13377 return endIndex + 1; 13378 }; 13379 var parseAttribute = function (tagName, name, value, val2, val3) { 13380 name = name.toLowerCase(); 13381 value = processAttr(name in fillAttrsMap ? name : decode(value || val2 || val3 || '')); 13382 if (validate && !isInternalElement && isValidPrefixAttrName(name) === false) { 13383 var attrRule = validAttributesMap[name]; 13384 if (!attrRule && validAttributePatterns) { 13385 var i_1 = validAttributePatterns.length; 13386 while (i_1--) { 13387 attrRule = validAttributePatterns[i_1]; 13388 if (attrRule.pattern.test(name)) { 13389 break; 13390 } 13391 } 13392 if (i_1 === -1) { 13393 attrRule = null; 13394 } 13395 } 13396 if (!attrRule) { 13397 return; 13398 } 13399 if (attrRule.validValues && !(value in attrRule.validValues)) { 13400 return; 13401 } 13402 } 13403 var isNameOrId = name === 'name' || name === 'id'; 13404 if (isNameOrId && tagName in filteredClobberElements && (value in doc || value in form)) { 13405 return; 13406 } 13407 if (filteredUrlAttrs[name] && !URI.isDomSafe(value, tagName, settings)) { 13408 return; 13409 } 13410 if (isInternalElement && (name in filteredUrlAttrs || name.indexOf('on') === 0)) { 13411 return; 13412 } 13413 attrList.map[name] = value; 13414 attrList.push({ 13415 name: name, 13416 value: value 13417 }); 13418 }; 13419 var tokenRegExp = new RegExp('<(?:' + '(?:!--([\\w\\W]*?)--!?>)|' + '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + '(?:![Dd][Oo][Cc][Tt][Yy][Pp][Ee]([\\w\\W]*?)>)|' + '(?:!(--)?)|' + '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + '(?:\\/([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)>)|' + '(?:([A-Za-z][A-Za-z0-9\\-_:.]*)(\\s(?:[^\'">]+(?:"[^"]*"|\'[^\']*\'))*[^"\'>]*(?:"[^">]*|\'[^\'>]*)?|\\s*|\\/)>)' + ')', 'g'); 13420 var attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g; 13421 var shortEndedElements = schema.getShortEndedElements(); 13422 var selfClosing = settings.self_closing_elements || schema.getSelfClosingElements(); 13423 var fillAttrsMap = schema.getBoolAttrs(); 13424 var validate = settings.validate; 13425 var removeInternalElements = settings.remove_internals; 13426 var fixSelfClosing = settings.fix_self_closing; 13427 var specialElements = schema.getSpecialElements(); 13428 var processHtml = html + '>'; 13429 while (matches = tokenRegExp.exec(processHtml)) { 13430 var matchText = matches[0]; 13431 if (index < matches.index) { 13432 processText(decode(html.substr(index, matches.index - index))); 13433 } 13434 if (value = matches[7]) { 13435 value = value.toLowerCase(); 13436 if (value.charAt(0) === ':') { 13437 value = value.substr(1); 13438 } 13439 processEndTag(value); 13440 } else if (value = matches[8]) { 13441 if (matches.index + matchText.length > html.length) { 13442 processText(decode(html.substr(matches.index))); 13443 index = matches.index + matchText.length; 13444 continue; 13445 } 13446 value = value.toLowerCase(); 13447 if (value.charAt(0) === ':') { 13448 value = value.substr(1); 13449 } 13450 isShortEnded = value in shortEndedElements; 13451 if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value) { 13452 processEndTag(value); 13453 } 13454 var bogusValue = checkBogusAttribute(attrRegExp, matches[9]); 13455 if (bogusValue !== null) { 13456 if (bogusValue === 'all') { 13457 index = findMatchingEndTagIndex(schema, html, tokenRegExp.lastIndex); 13458 tokenRegExp.lastIndex = index; 13459 continue; 13460 } 13461 isValidElement = false; 13462 } 13463 if (!validate || (elementRule = schema.getElementRule(value))) { 13464 isValidElement = true; 13465 if (validate) { 13466 validAttributesMap = elementRule.attributes; 13467 validAttributePatterns = elementRule.attributePatterns; 13468 } 13469 if (attribsValue = matches[9]) { 13470 isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; 13471 if (isInternalElement && removeInternalElements) { 13472 isValidElement = false; 13473 } 13474 attrList = []; 13475 attrList.map = {}; 13476 attribsValue.replace(attrRegExp, function (match, name, val, val2, val3) { 13477 parseAttribute(value, name, val, val2, val3); 13478 return ''; 13479 }); 13480 } else { 13481 attrList = []; 13482 attrList.map = {}; 13483 } 13484 if (validate && !isInternalElement) { 13485 attributesRequired = elementRule.attributesRequired; 13486 attributesDefault = elementRule.attributesDefault; 13487 attributesForced = elementRule.attributesForced; 13488 anyAttributesRequired = elementRule.removeEmptyAttrs; 13489 if (anyAttributesRequired && !attrList.length) { 13490 isValidElement = false; 13491 } 13492 if (attributesForced) { 13493 i = attributesForced.length; 13494 while (i--) { 13495 attr = attributesForced[i]; 13496 name = attr.name; 13497 attrValue = attr.value; 13498 if (attrValue === '{$uid}') { 13499 attrValue = 'mce_' + idCount++; 13500 } 13501 attrList.map[name] = attrValue; 13502 attrList.push({ 13503 name: name, 13504 value: attrValue 13505 }); 13506 } 13507 } 13508 if (attributesDefault) { 13509 i = attributesDefault.length; 13510 while (i--) { 13511 attr = attributesDefault[i]; 13512 name = attr.name; 13513 if (!(name in attrList.map)) { 13514 attrValue = attr.value; 13515 if (attrValue === '{$uid}') { 13516 attrValue = 'mce_' + idCount++; 13517 } 13518 attrList.map[name] = attrValue; 13519 attrList.push({ 13520 name: name, 13521 value: attrValue 13522 }); 13523 } 13524 } 13525 } 13526 if (attributesRequired) { 13527 i = attributesRequired.length; 13528 while (i--) { 13529 if (attributesRequired[i] in attrList.map) { 13530 break; 13531 } 13532 } 13533 if (i === -1) { 13534 isValidElement = false; 13535 } 13536 } 13537 if (attr = attrList.map['data-mce-bogus']) { 13538 if (attr === 'all') { 13539 index = findMatchingEndTagIndex(schema, html, tokenRegExp.lastIndex); 13540 tokenRegExp.lastIndex = index; 13541 continue; 13542 } 13543 isValidElement = false; 13544 } 13545 } 13546 if (isValidElement) { 13547 start(value, attrList, isShortEnded); 13548 } 13549 } else { 13550 isValidElement = false; 13551 } 13552 if (endRegExp = specialElements[value]) { 13553 endRegExp.lastIndex = index = matches.index + matchText.length; 13554 if (matches = endRegExp.exec(html)) { 13555 if (isValidElement) { 13556 textData = html.substr(index, matches.index - index); 13557 } 13558 index = matches.index + matches[0].length; 13559 } else { 13560 textData = html.substr(index); 13561 index = html.length; 13562 } 13563 if (isValidElement) { 13564 if (textData.length > 0) { 13565 processText(textData, true); 13566 } 13567 end(value); 13568 } 13569 tokenRegExp.lastIndex = index; 13570 continue; 13571 } 13572 if (!isShortEnded) { 13573 if (!attribsValue || attribsValue.indexOf('/') !== attribsValue.length - 1) { 13574 stack.push({ 13575 name: value, 13576 valid: isValidElement 13577 }); 13578 } else if (isValidElement) { 13579 end(value); 13580 } 13581 } 13582 } else if (value = matches[1]) { 13583 processComment(value); 13584 } else if (value = matches[2]) { 13585 var isValidCdataSection = parsingMode === 1 || settings.preserve_cdata || stack.length > 0 && schema.isValidChild(stack[stack.length - 1].name, '#cdata'); 13586 if (isValidCdataSection) { 13587 cdata(value); 13588 } else { 13589 index = processMalformedComment('', matches.index + 2); 13590 tokenRegExp.lastIndex = index; 13591 continue; 13592 } 13593 } else if (value = matches[3]) { 13594 doctype(value); 13595 } else if ((value = matches[4]) || matchText === '<!') { 13596 index = processMalformedComment(value, matches.index + matchText.length); 13597 tokenRegExp.lastIndex = index; 13598 continue; 13599 } else if (value = matches[5]) { 13600 if (parsingMode === 1) { 13601 pi(value, matches[6]); 13602 } else { 13603 index = processMalformedComment('?', matches.index + 2); 13604 tokenRegExp.lastIndex = index; 13605 continue; 13606 } 13607 } 13608 index = matches.index + matchText.length; 13609 } 13610 if (index < html.length) { 13611 processText(decode(html.substr(index))); 13612 } 13613 for (i = stack.length - 1; i >= 0; i--) { 13614 value = stack[i]; 13615 if (value.valid) { 13616 end(value.name); 13617 } 13618 } 13619 }; 13620 var parse = function (html, format) { 13621 if (format === void 0) { 13622 format = 'html'; 13623 } 13624 parseInternal(extractBase64DataUris(html), format); 13625 }; 13626 return { parse: parse }; 13627 }; 13628 SaxParser.findEndTag = findMatchingEndTagIndex; 13629 13630 var trimHtml = function (tempAttrs, html) { 13631 var trimContentRegExp = new RegExp(['\\s?(' + tempAttrs.join('|') + ')="[^"]+"'].join('|'), 'gi'); 13632 return html.replace(trimContentRegExp, ''); 13633 }; 13634 var trimInternal = function (serializer, html) { 13635 var bogusAllRegExp = /<(\w+) [^>]*data-mce-bogus="all"[^>]*>/g; 13636 var schema = serializer.schema; 13637 var content = trimHtml(serializer.getTempAttrs(), html); 13638 var shortEndedElements = schema.getShortEndedElements(); 13639 var matches; 13640 while (matches = bogusAllRegExp.exec(content)) { 13641 var index = bogusAllRegExp.lastIndex; 13642 var matchLength = matches[0].length; 13643 var endTagIndex = void 0; 13644 if (shortEndedElements[matches[1]]) { 13645 endTagIndex = index; 13646 } else { 13647 endTagIndex = SaxParser.findEndTag(schema, content, index); 13648 } 13649 content = content.substring(0, index - matchLength) + content.substring(endTagIndex); 13650 bogusAllRegExp.lastIndex = index - matchLength; 13651 } 13652 return trim$2(content); 13653 }; 13654 var trimExternal = trimInternal; 13655 13656 var trimEmptyContents = function (editor, html) { 13657 var blockName = getForcedRootBlock(editor); 13658 var emptyRegExp = new RegExp('^(<' + blockName + '[^>]*>( | |\\s|\xA0|<br \\/>|)<\\/' + blockName + '>[\r\n]*|<br \\/>[\r\n]*)$'); 13659 return html.replace(emptyRegExp, ''); 13660 }; 13661 var setupArgs$3 = function (args, format) { 13662 return __assign(__assign({}, args), { 13663 format: format, 13664 get: true, 13665 getInner: true 13666 }); 13667 }; 13668 var getContentFromBody = function (editor, args, format, body) { 13669 var defaultedArgs = setupArgs$3(args, format); 13670 var updatedArgs = args.no_events ? defaultedArgs : editor.fire('BeforeGetContent', defaultedArgs); 13671 var content; 13672 if (updatedArgs.format === 'raw') { 13673 content = Tools.trim(trimExternal(editor.serializer, body.innerHTML)); 13674 } else if (updatedArgs.format === 'text') { 13675 content = editor.dom.isEmpty(body) ? '' : trim$2(body.innerText || body.textContent); 13676 } else if (updatedArgs.format === 'tree') { 13677 content = editor.serializer.serialize(body, updatedArgs); 13678 } else { 13679 content = trimEmptyContents(editor, editor.serializer.serialize(body, updatedArgs)); 13680 } 13681 if (!contains$3([ 13682 'text', 13683 'tree' 13684 ], updatedArgs.format) && !isWsPreserveElement(SugarElement.fromDom(body))) { 13685 updatedArgs.content = Tools.trim(content); 13686 } else { 13687 updatedArgs.content = content; 13688 } 13689 if (updatedArgs.no_events) { 13690 return updatedArgs.content; 13691 } else { 13692 return editor.fire('GetContent', updatedArgs).content; 13693 } 13694 }; 13695 var getContentInternal = function (editor, args, format) { 13696 return Optional.from(editor.getBody()).fold(constant(args.format === 'tree' ? new AstNode('body', 11) : ''), function (body) { 13697 return getContentFromBody(editor, args, format, body); 13698 }); 13699 }; 13700 13701 var each$c = Tools.each; 13702 var ElementUtils = function (dom) { 13703 var compare = function (node1, node2) { 13704 if (node1.nodeName !== node2.nodeName) { 13705 return false; 13706 } 13707 var getAttribs = function (node) { 13708 var attribs = {}; 13709 each$c(dom.getAttribs(node), function (attr) { 13710 var name = attr.nodeName.toLowerCase(); 13711 if (name.indexOf('_') !== 0 && name !== 'style' && name.indexOf('data-') !== 0) { 13712 attribs[name] = dom.getAttrib(node, name); 13713 } 13714 }); 13715 return attribs; 13716 }; 13717 var compareObjects = function (obj1, obj2) { 13718 var value, name; 13719 for (name in obj1) { 13720 if (has$2(obj1, name)) { 13721 value = obj2[name]; 13722 if (typeof value === 'undefined') { 13723 return false; 13724 } 13725 if (obj1[name] !== value) { 13726 return false; 13727 } 13728 delete obj2[name]; 13729 } 13730 } 13731 for (name in obj2) { 13732 if (has$2(obj2, name)) { 13733 return false; 13734 } 13735 } 13736 return true; 13737 }; 13738 if (!compareObjects(getAttribs(node1), getAttribs(node2))) { 13739 return false; 13740 } 13741 if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) { 13742 return false; 13743 } 13744 return !isBookmarkNode$1(node1) && !isBookmarkNode$1(node2); 13745 }; 13746 return { compare: compare }; 13747 }; 13748 13749 var makeMap$1 = Tools.makeMap; 13750 var Writer = function (settings) { 13751 var html = []; 13752 settings = settings || {}; 13753 var indent = settings.indent; 13754 var indentBefore = makeMap$1(settings.indent_before || ''); 13755 var indentAfter = makeMap$1(settings.indent_after || ''); 13756 var encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities); 13757 var htmlOutput = settings.element_format === 'html'; 13758 return { 13759 start: function (name, attrs, empty) { 13760 var i, l, attr, value; 13761 if (indent && indentBefore[name] && html.length > 0) { 13762 value = html[html.length - 1]; 13763 if (value.length > 0 && value !== '\n') { 13764 html.push('\n'); 13765 } 13766 } 13767 html.push('<', name); 13768 if (attrs) { 13769 for (i = 0, l = attrs.length; i < l; i++) { 13770 attr = attrs[i]; 13771 html.push(' ', attr.name, '="', encode(attr.value, true), '"'); 13772 } 13773 } 13774 if (!empty || htmlOutput) { 13775 html[html.length] = '>'; 13776 } else { 13777 html[html.length] = ' />'; 13778 } 13779 if (empty && indent && indentAfter[name] && html.length > 0) { 13780 value = html[html.length - 1]; 13781 if (value.length > 0 && value !== '\n') { 13782 html.push('\n'); 13783 } 13784 } 13785 }, 13786 end: function (name) { 13787 var value; 13788 html.push('</', name, '>'); 13789 if (indent && indentAfter[name] && html.length > 0) { 13790 value = html[html.length - 1]; 13791 if (value.length > 0 && value !== '\n') { 13792 html.push('\n'); 13793 } 13794 } 13795 }, 13796 text: function (text, raw) { 13797 if (text.length > 0) { 13798 html[html.length] = raw ? text : encode(text); 13799 } 13800 }, 13801 cdata: function (text) { 13802 html.push('<![CDATA[', text, ']]>'); 13803 }, 13804 comment: function (text) { 13805 html.push('<!--', text, '-->'); 13806 }, 13807 pi: function (name, text) { 13808 if (text) { 13809 html.push('<?', name, ' ', encode(text), '?>'); 13810 } else { 13811 html.push('<?', name, '?>'); 13812 } 13813 if (indent) { 13814 html.push('\n'); 13815 } 13816 }, 13817 doctype: function (text) { 13818 html.push('<!DOCTYPE', text, '>', indent ? '\n' : ''); 13819 }, 13820 reset: function () { 13821 html.length = 0; 13822 }, 13823 getContent: function () { 13824 return html.join('').replace(/\n$/, ''); 13825 } 13826 }; 13827 }; 13828 13829 var HtmlSerializer = function (settings, schema) { 13830 if (schema === void 0) { 13831 schema = Schema(); 13832 } 13833 var writer = Writer(settings); 13834 settings = settings || {}; 13835 settings.validate = 'validate' in settings ? settings.validate : true; 13836 var serialize = function (node) { 13837 var validate = settings.validate; 13838 var handlers = { 13839 3: function (node) { 13840 writer.text(node.value, node.raw); 13841 }, 13842 8: function (node) { 13843 writer.comment(node.value); 13844 }, 13845 7: function (node) { 13846 writer.pi(node.name, node.value); 13847 }, 13848 10: function (node) { 13849 writer.doctype(node.value); 13850 }, 13851 4: function (node) { 13852 writer.cdata(node.value); 13853 }, 13854 11: function (node) { 13855 if (node = node.firstChild) { 13856 do { 13857 walk(node); 13858 } while (node = node.next); 13859 } 13860 } 13861 }; 13862 writer.reset(); 13863 var walk = function (node) { 13864 var handler = handlers[node.type]; 13865 if (!handler) { 13866 var name_1 = node.name; 13867 var isEmpty = node.shortEnded; 13868 var attrs = node.attributes; 13869 if (validate && attrs && attrs.length > 1) { 13870 var sortedAttrs = []; 13871 sortedAttrs.map = {}; 13872 var elementRule = schema.getElementRule(node.name); 13873 if (elementRule) { 13874 for (var i = 0, l = elementRule.attributesOrder.length; i < l; i++) { 13875 var attrName = elementRule.attributesOrder[i]; 13876 if (attrName in attrs.map) { 13877 var attrValue = attrs.map[attrName]; 13878 sortedAttrs.map[attrName] = attrValue; 13879 sortedAttrs.push({ 13880 name: attrName, 13881 value: attrValue 13882 }); 13883 } 13884 } 13885 for (var i = 0, l = attrs.length; i < l; i++) { 13886 var attrName = attrs[i].name; 13887 if (!(attrName in sortedAttrs.map)) { 13888 var attrValue = attrs.map[attrName]; 13889 sortedAttrs.map[attrName] = attrValue; 13890 sortedAttrs.push({ 13891 name: attrName, 13892 value: attrValue 13893 }); 13894 } 13895 } 13896 attrs = sortedAttrs; 13897 } 13898 } 13899 writer.start(node.name, attrs, isEmpty); 13900 if (!isEmpty) { 13901 if (node = node.firstChild) { 13902 do { 13903 walk(node); 13904 } while (node = node.next); 13905 } 13906 writer.end(name_1); 13907 } 13908 } else { 13909 handler(node); 13910 } 13911 }; 13912 if (node.type === 1 && !settings.inner) { 13913 walk(node); 13914 } else { 13915 handlers[11](node); 13916 } 13917 return writer.getContent(); 13918 }; 13919 return { serialize: serialize }; 13920 }; 13921 13922 var nonInheritableStyles = new Set(); 13923 (function () { 13924 var nonInheritableStylesArr = [ 13925 'margin', 13926 'margin-left', 13927 'margin-right', 13928 'margin-top', 13929 'margin-bottom', 13930 'padding', 13931 'padding-left', 13932 'padding-right', 13933 'padding-top', 13934 'padding-bottom', 13935 'border', 13936 'border-width', 13937 'border-style', 13938 'border-color', 13939 'background', 13940 'background-attachment', 13941 'background-clip', 13942 'background-color', 13943 'background-image', 13944 'background-origin', 13945 'background-position', 13946 'background-repeat', 13947 'background-size', 13948 'float', 13949 'position', 13950 'left', 13951 'right', 13952 'top', 13953 'bottom', 13954 'z-index', 13955 'display', 13956 'transform', 13957 'width', 13958 'max-width', 13959 'min-width', 13960 'height', 13961 'max-height', 13962 'min-height', 13963 'overflow', 13964 'overflow-x', 13965 'overflow-y', 13966 'text-overflow', 13967 'vertical-align', 13968 'transition', 13969 'transition-delay', 13970 'transition-duration', 13971 'transition-property', 13972 'transition-timing-function' 13973 ]; 13974 each$k(nonInheritableStylesArr, function (style) { 13975 nonInheritableStyles.add(style); 13976 }); 13977 }()); 13978 var shorthandStyleProps = [ 13979 'font', 13980 'text-decoration', 13981 'text-emphasis' 13982 ]; 13983 var getStyleProps = function (dom, node) { 13984 return keys(dom.parseStyle(dom.getAttrib(node, 'style'))); 13985 }; 13986 var isNonInheritableStyle = function (style) { 13987 return nonInheritableStyles.has(style); 13988 }; 13989 var hasInheritableStyles = function (dom, node) { 13990 return forall(getStyleProps(dom, node), function (style) { 13991 return !isNonInheritableStyle(style); 13992 }); 13993 }; 13994 var getLonghandStyleProps = function (styles) { 13995 return filter$4(styles, function (style) { 13996 return exists(shorthandStyleProps, function (prop) { 13997 return startsWith(style, prop); 13998 }); 13999 }); 14000 }; 14001 var hasStyleConflict = function (dom, node, parentNode) { 14002 var nodeStyleProps = getStyleProps(dom, node); 14003 var parentNodeStyleProps = getStyleProps(dom, parentNode); 14004 var valueMismatch = function (prop) { 14005 var nodeValue = dom.getStyle(node, prop); 14006 var parentValue = dom.getStyle(parentNode, prop); 14007 return isNotEmpty(nodeValue) && isNotEmpty(parentValue) && nodeValue !== parentValue; 14008 }; 14009 return exists(nodeStyleProps, function (nodeStyleProp) { 14010 var propExists = function (props) { 14011 return exists(props, function (prop) { 14012 return prop === nodeStyleProp; 14013 }); 14014 }; 14015 if (!propExists(parentNodeStyleProps) && propExists(shorthandStyleProps)) { 14016 var longhandProps = getLonghandStyleProps(parentNodeStyleProps); 14017 return exists(longhandProps, valueMismatch); 14018 } else { 14019 return valueMismatch(nodeStyleProp); 14020 } 14021 }); 14022 }; 14023 14024 var isChar = function (forward, predicate, pos) { 14025 return Optional.from(pos.container()).filter(isText$7).exists(function (text) { 14026 var delta = forward ? 0 : -1; 14027 return predicate(text.data.charAt(pos.offset() + delta)); 14028 }); 14029 }; 14030 var isBeforeSpace = curry(isChar, true, isWhiteSpace); 14031 var isAfterSpace = curry(isChar, false, isWhiteSpace); 14032 var isEmptyText = function (pos) { 14033 var container = pos.container(); 14034 return isText$7(container) && (container.data.length === 0 || isZwsp(container.data) && BookmarkManager.isBookmarkNode(container.parentNode)); 14035 }; 14036 var matchesElementPosition = function (before, predicate) { 14037 return function (pos) { 14038 return Optional.from(getChildNodeAtRelativeOffset(before ? 0 : -1, pos)).filter(predicate).isSome(); 14039 }; 14040 }; 14041 var isImageBlock = function (node) { 14042 return isImg(node) && get$5(SugarElement.fromDom(node), 'display') === 'block'; 14043 }; 14044 var isCefNode = function (node) { 14045 return isContentEditableFalse$b(node) && !isBogusAll$1(node); 14046 }; 14047 var isBeforeImageBlock = matchesElementPosition(true, isImageBlock); 14048 var isAfterImageBlock = matchesElementPosition(false, isImageBlock); 14049 var isBeforeMedia = matchesElementPosition(true, isMedia$2); 14050 var isAfterMedia = matchesElementPosition(false, isMedia$2); 14051 var isBeforeTable = matchesElementPosition(true, isTable$3); 14052 var isAfterTable = matchesElementPosition(false, isTable$3); 14053 var isBeforeContentEditableFalse = matchesElementPosition(true, isCefNode); 14054 var isAfterContentEditableFalse = matchesElementPosition(false, isCefNode); 14055 14056 var getLastChildren = function (elm) { 14057 var children = []; 14058 var rawNode = elm.dom; 14059 while (rawNode) { 14060 children.push(SugarElement.fromDom(rawNode)); 14061 rawNode = rawNode.lastChild; 14062 } 14063 return children; 14064 }; 14065 var removeTrailingBr = function (elm) { 14066 var allBrs = descendants(elm, 'br'); 14067 var brs = filter$4(getLastChildren(elm).slice(-1), isBr$4); 14068 if (allBrs.length === brs.length) { 14069 each$k(brs, remove$7); 14070 } 14071 }; 14072 var fillWithPaddingBr = function (elm) { 14073 empty(elm); 14074 append$1(elm, SugarElement.fromHtml('<br data-mce-bogus="1">')); 14075 }; 14076 var trimBlockTrailingBr = function (elm) { 14077 lastChild(elm).each(function (lastChild) { 14078 prevSibling(lastChild).each(function (lastChildPrevSibling) { 14079 if (isBlock$2(elm) && isBr$4(lastChild) && isBlock$2(lastChildPrevSibling)) { 14080 remove$7(lastChild); 14081 } 14082 }); 14083 }); 14084 }; 14085 14086 var dropLast = function (xs) { 14087 return xs.slice(0, -1); 14088 }; 14089 var parentsUntil = function (start, root, predicate) { 14090 if (contains$1(root, start)) { 14091 return dropLast(parents$1(start, function (elm) { 14092 return predicate(elm) || eq(elm, root); 14093 })); 14094 } else { 14095 return []; 14096 } 14097 }; 14098 var parents = function (start, root) { 14099 return parentsUntil(start, root, never); 14100 }; 14101 var parentsAndSelf = function (start, root) { 14102 return [start].concat(parents(start, root)); 14103 }; 14104 14105 var navigateIgnoreEmptyTextNodes = function (forward, root, from) { 14106 return navigateIgnore(forward, root, from, isEmptyText); 14107 }; 14108 var getClosestBlock$1 = function (root, pos) { 14109 return find$3(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2); 14110 }; 14111 var isAtBeforeAfterBlockBoundary = function (forward, root, pos) { 14112 return navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(function (newPos) { 14113 return getClosestBlock$1(root, pos).fold(function () { 14114 return isInSameBlock(newPos, pos, root.dom) === false; 14115 }, function (fromBlock) { 14116 return isInSameBlock(newPos, pos, root.dom) === false && contains$1(fromBlock, SugarElement.fromDom(newPos.container())); 14117 }); 14118 }); 14119 }; 14120 var isAtBlockBoundary = function (forward, root, pos) { 14121 return getClosestBlock$1(root, pos).fold(function () { 14122 return navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(function (newPos) { 14123 return isInSameBlock(newPos, pos, root.dom) === false; 14124 }); 14125 }, function (parent) { 14126 return navigateIgnoreEmptyTextNodes(forward, parent.dom, pos).isNone(); 14127 }); 14128 }; 14129 var isAtStartOfBlock = curry(isAtBlockBoundary, false); 14130 var isAtEndOfBlock = curry(isAtBlockBoundary, true); 14131 var isBeforeBlock = curry(isAtBeforeAfterBlockBoundary, false); 14132 var isAfterBlock = curry(isAtBeforeAfterBlockBoundary, true); 14133 14134 var isBr = function (pos) { 14135 return getElementFromPosition(pos).exists(isBr$4); 14136 }; 14137 var findBr = function (forward, root, pos) { 14138 var parentBlocks = filter$4(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2); 14139 var scope = head(parentBlocks).getOr(root); 14140 return fromPosition(forward, scope.dom, pos).filter(isBr); 14141 }; 14142 var isBeforeBr$1 = function (root, pos) { 14143 return getElementFromPosition(pos).exists(isBr$4) || findBr(true, root, pos).isSome(); 14144 }; 14145 var isAfterBr = function (root, pos) { 14146 return getElementFromPrevPosition(pos).exists(isBr$4) || findBr(false, root, pos).isSome(); 14147 }; 14148 var findPreviousBr = curry(findBr, false); 14149 var findNextBr = curry(findBr, true); 14150 14151 var isInMiddleOfText = function (pos) { 14152 return CaretPosition.isTextPosition(pos) && !pos.isAtStart() && !pos.isAtEnd(); 14153 }; 14154 var getClosestBlock = function (root, pos) { 14155 var parentBlocks = filter$4(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2); 14156 return head(parentBlocks).getOr(root); 14157 }; 14158 var hasSpaceBefore = function (root, pos) { 14159 if (isInMiddleOfText(pos)) { 14160 return isAfterSpace(pos); 14161 } else { 14162 return isAfterSpace(pos) || prevPosition(getClosestBlock(root, pos).dom, pos).exists(isAfterSpace); 14163 } 14164 }; 14165 var hasSpaceAfter = function (root, pos) { 14166 if (isInMiddleOfText(pos)) { 14167 return isBeforeSpace(pos); 14168 } else { 14169 return isBeforeSpace(pos) || nextPosition(getClosestBlock(root, pos).dom, pos).exists(isBeforeSpace); 14170 } 14171 }; 14172 var isPreValue = function (value) { 14173 return contains$3([ 14174 'pre', 14175 'pre-wrap' 14176 ], value); 14177 }; 14178 var isInPre = function (pos) { 14179 return getElementFromPosition(pos).bind(function (elm) { 14180 return closest$3(elm, isElement$6); 14181 }).exists(function (elm) { 14182 return isPreValue(get$5(elm, 'white-space')); 14183 }); 14184 }; 14185 var isAtBeginningOfBody = function (root, pos) { 14186 return prevPosition(root.dom, pos).isNone(); 14187 }; 14188 var isAtEndOfBody = function (root, pos) { 14189 return nextPosition(root.dom, pos).isNone(); 14190 }; 14191 var isAtLineBoundary = function (root, pos) { 14192 return isAtBeginningOfBody(root, pos) || isAtEndOfBody(root, pos) || isAtStartOfBlock(root, pos) || isAtEndOfBlock(root, pos) || isAfterBr(root, pos) || isBeforeBr$1(root, pos); 14193 }; 14194 var needsToHaveNbsp = function (root, pos) { 14195 if (isInPre(pos)) { 14196 return false; 14197 } else { 14198 return isAtLineBoundary(root, pos) || hasSpaceBefore(root, pos) || hasSpaceAfter(root, pos); 14199 } 14200 }; 14201 var needsToBeNbspLeft = function (root, pos) { 14202 if (isInPre(pos)) { 14203 return false; 14204 } else { 14205 return isAtStartOfBlock(root, pos) || isBeforeBlock(root, pos) || isAfterBr(root, pos) || hasSpaceBefore(root, pos); 14206 } 14207 }; 14208 var leanRight = function (pos) { 14209 var container = pos.container(); 14210 var offset = pos.offset(); 14211 if (isText$7(container) && offset < container.data.length) { 14212 return CaretPosition(container, offset + 1); 14213 } else { 14214 return pos; 14215 } 14216 }; 14217 var needsToBeNbspRight = function (root, pos) { 14218 if (isInPre(pos)) { 14219 return false; 14220 } else { 14221 return isAtEndOfBlock(root, pos) || isAfterBlock(root, pos) || isBeforeBr$1(root, pos) || hasSpaceAfter(root, pos); 14222 } 14223 }; 14224 var needsToBeNbsp = function (root, pos) { 14225 return needsToBeNbspLeft(root, pos) || needsToBeNbspRight(root, leanRight(pos)); 14226 }; 14227 var isNbspAt = function (text, offset) { 14228 return isNbsp(text.charAt(offset)); 14229 }; 14230 var hasNbsp = function (pos) { 14231 var container = pos.container(); 14232 return isText$7(container) && contains$2(container.data, nbsp); 14233 }; 14234 var normalizeNbspMiddle = function (text) { 14235 var chars = text.split(''); 14236 return map$3(chars, function (chr, i) { 14237 if (isNbsp(chr) && i > 0 && i < chars.length - 1 && isContent(chars[i - 1]) && isContent(chars[i + 1])) { 14238 return ' '; 14239 } else { 14240 return chr; 14241 } 14242 }).join(''); 14243 }; 14244 var normalizeNbspAtStart = function (root, node) { 14245 var text = node.data; 14246 var firstPos = CaretPosition(node, 0); 14247 if (isNbspAt(text, 0) && !needsToBeNbsp(root, firstPos)) { 14248 node.data = ' ' + text.slice(1); 14249 return true; 14250 } else { 14251 return false; 14252 } 14253 }; 14254 var normalizeNbspInMiddleOfTextNode = function (node) { 14255 var text = node.data; 14256 var newText = normalizeNbspMiddle(text); 14257 if (newText !== text) { 14258 node.data = newText; 14259 return true; 14260 } else { 14261 return false; 14262 } 14263 }; 14264 var normalizeNbspAtEnd = function (root, node) { 14265 var text = node.data; 14266 var lastPos = CaretPosition(node, text.length - 1); 14267 if (isNbspAt(text, text.length - 1) && !needsToBeNbsp(root, lastPos)) { 14268 node.data = text.slice(0, -1) + ' '; 14269 return true; 14270 } else { 14271 return false; 14272 } 14273 }; 14274 var normalizeNbsps = function (root, pos) { 14275 return Optional.some(pos).filter(hasNbsp).bind(function (pos) { 14276 var container = pos.container(); 14277 var normalized = normalizeNbspAtStart(root, container) || normalizeNbspInMiddleOfTextNode(container) || normalizeNbspAtEnd(root, container); 14278 return normalized ? Optional.some(pos) : Optional.none(); 14279 }); 14280 }; 14281 var normalizeNbspsInEditor = function (editor) { 14282 var root = SugarElement.fromDom(editor.getBody()); 14283 if (editor.selection.isCollapsed()) { 14284 normalizeNbsps(root, CaretPosition.fromRangeStart(editor.selection.getRng())).each(function (pos) { 14285 editor.selection.setRng(pos.toRange()); 14286 }); 14287 } 14288 }; 14289 14290 var normalizeContent = function (content, isStartOfContent, isEndOfContent) { 14291 var result = foldl(content, function (acc, c) { 14292 if (isWhiteSpace(c) || isNbsp(c)) { 14293 if (acc.previousCharIsSpace || acc.str === '' && isStartOfContent || acc.str.length === content.length - 1 && isEndOfContent) { 14294 return { 14295 previousCharIsSpace: false, 14296 str: acc.str + nbsp 14297 }; 14298 } else { 14299 return { 14300 previousCharIsSpace: true, 14301 str: acc.str + ' ' 14302 }; 14303 } 14304 } else { 14305 return { 14306 previousCharIsSpace: false, 14307 str: acc.str + c 14308 }; 14309 } 14310 }, { 14311 previousCharIsSpace: false, 14312 str: '' 14313 }); 14314 return result.str; 14315 }; 14316 var normalize$1 = function (node, offset, count) { 14317 if (count === 0) { 14318 return; 14319 } 14320 var elm = SugarElement.fromDom(node); 14321 var root = ancestor$3(elm, isBlock$2).getOr(elm); 14322 var whitespace = node.data.slice(offset, offset + count); 14323 var isEndOfContent = offset + count >= node.data.length && needsToBeNbspRight(root, CaretPosition(node, node.data.length)); 14324 var isStartOfContent = offset === 0 && needsToBeNbspLeft(root, CaretPosition(node, 0)); 14325 node.replaceData(offset, count, normalizeContent(whitespace, isStartOfContent, isEndOfContent)); 14326 }; 14327 var normalizeWhitespaceAfter = function (node, offset) { 14328 var content = node.data.slice(offset); 14329 var whitespaceCount = content.length - lTrim(content).length; 14330 normalize$1(node, offset, whitespaceCount); 14331 }; 14332 var normalizeWhitespaceBefore = function (node, offset) { 14333 var content = node.data.slice(0, offset); 14334 var whitespaceCount = content.length - rTrim(content).length; 14335 normalize$1(node, offset - whitespaceCount, whitespaceCount); 14336 }; 14337 var mergeTextNodes = function (prevNode, nextNode, normalizeWhitespace, mergeToPrev) { 14338 if (mergeToPrev === void 0) { 14339 mergeToPrev = true; 14340 } 14341 var whitespaceOffset = rTrim(prevNode.data).length; 14342 var newNode = mergeToPrev ? prevNode : nextNode; 14343 var removeNode = mergeToPrev ? nextNode : prevNode; 14344 if (mergeToPrev) { 14345 newNode.appendData(removeNode.data); 14346 } else { 14347 newNode.insertData(0, removeNode.data); 14348 } 14349 remove$7(SugarElement.fromDom(removeNode)); 14350 if (normalizeWhitespace) { 14351 normalizeWhitespaceAfter(newNode, whitespaceOffset); 14352 } 14353 return newNode; 14354 }; 14355 14356 var needsReposition = function (pos, elm) { 14357 var container = pos.container(); 14358 var offset = pos.offset(); 14359 return CaretPosition.isTextPosition(pos) === false && container === elm.parentNode && offset > CaretPosition.before(elm).offset(); 14360 }; 14361 var reposition = function (elm, pos) { 14362 return needsReposition(pos, elm) ? CaretPosition(pos.container(), pos.offset() - 1) : pos; 14363 }; 14364 var beforeOrStartOf = function (node) { 14365 return isText$7(node) ? CaretPosition(node, 0) : CaretPosition.before(node); 14366 }; 14367 var afterOrEndOf = function (node) { 14368 return isText$7(node) ? CaretPosition(node, node.data.length) : CaretPosition.after(node); 14369 }; 14370 var getPreviousSiblingCaretPosition = function (elm) { 14371 if (isCaretCandidate$3(elm.previousSibling)) { 14372 return Optional.some(afterOrEndOf(elm.previousSibling)); 14373 } else { 14374 return elm.previousSibling ? lastPositionIn(elm.previousSibling) : Optional.none(); 14375 } 14376 }; 14377 var getNextSiblingCaretPosition = function (elm) { 14378 if (isCaretCandidate$3(elm.nextSibling)) { 14379 return Optional.some(beforeOrStartOf(elm.nextSibling)); 14380 } else { 14381 return elm.nextSibling ? firstPositionIn(elm.nextSibling) : Optional.none(); 14382 } 14383 }; 14384 var findCaretPositionBackwardsFromElm = function (rootElement, elm) { 14385 var startPosition = CaretPosition.before(elm.previousSibling ? elm.previousSibling : elm.parentNode); 14386 return prevPosition(rootElement, startPosition).fold(function () { 14387 return nextPosition(rootElement, CaretPosition.after(elm)); 14388 }, Optional.some); 14389 }; 14390 var findCaretPositionForwardsFromElm = function (rootElement, elm) { 14391 return nextPosition(rootElement, CaretPosition.after(elm)).fold(function () { 14392 return prevPosition(rootElement, CaretPosition.before(elm)); 14393 }, Optional.some); 14394 }; 14395 var findCaretPositionBackwards = function (rootElement, elm) { 14396 return getPreviousSiblingCaretPosition(elm).orThunk(function () { 14397 return getNextSiblingCaretPosition(elm); 14398 }).orThunk(function () { 14399 return findCaretPositionBackwardsFromElm(rootElement, elm); 14400 }); 14401 }; 14402 var findCaretPositionForward = function (rootElement, elm) { 14403 return getNextSiblingCaretPosition(elm).orThunk(function () { 14404 return getPreviousSiblingCaretPosition(elm); 14405 }).orThunk(function () { 14406 return findCaretPositionForwardsFromElm(rootElement, elm); 14407 }); 14408 }; 14409 var findCaretPosition = function (forward, rootElement, elm) { 14410 return forward ? findCaretPositionForward(rootElement, elm) : findCaretPositionBackwards(rootElement, elm); 14411 }; 14412 var findCaretPosOutsideElmAfterDelete = function (forward, rootElement, elm) { 14413 return findCaretPosition(forward, rootElement, elm).map(curry(reposition, elm)); 14414 }; 14415 var setSelection$1 = function (editor, forward, pos) { 14416 pos.fold(function () { 14417 editor.focus(); 14418 }, function (pos) { 14419 editor.selection.setRng(pos.toRange(), forward); 14420 }); 14421 }; 14422 var eqRawNode = function (rawNode) { 14423 return function (elm) { 14424 return elm.dom === rawNode; 14425 }; 14426 }; 14427 var isBlock = function (editor, elm) { 14428 return elm && has$2(editor.schema.getBlockElements(), name(elm)); 14429 }; 14430 var paddEmptyBlock = function (elm) { 14431 if (isEmpty$2(elm)) { 14432 var br = SugarElement.fromHtml('<br data-mce-bogus="1">'); 14433 empty(elm); 14434 append$1(elm, br); 14435 return Optional.some(CaretPosition.before(br.dom)); 14436 } else { 14437 return Optional.none(); 14438 } 14439 }; 14440 var deleteNormalized = function (elm, afterDeletePosOpt, normalizeWhitespace) { 14441 var prevTextOpt = prevSibling(elm).filter(isText$8); 14442 var nextTextOpt = nextSibling(elm).filter(isText$8); 14443 remove$7(elm); 14444 return lift3(prevTextOpt, nextTextOpt, afterDeletePosOpt, function (prev, next, pos) { 14445 var prevNode = prev.dom, nextNode = next.dom; 14446 var offset = prevNode.data.length; 14447 mergeTextNodes(prevNode, nextNode, normalizeWhitespace); 14448 return pos.container() === nextNode ? CaretPosition(prevNode, offset) : pos; 14449 }).orThunk(function () { 14450 if (normalizeWhitespace) { 14451 prevTextOpt.each(function (elm) { 14452 return normalizeWhitespaceBefore(elm.dom, elm.dom.length); 14453 }); 14454 nextTextOpt.each(function (elm) { 14455 return normalizeWhitespaceAfter(elm.dom, 0); 14456 }); 14457 } 14458 return afterDeletePosOpt; 14459 }); 14460 }; 14461 var isInlineElement = function (editor, element) { 14462 return has$2(editor.schema.getTextInlineElements(), name(element)); 14463 }; 14464 var deleteElement$2 = function (editor, forward, elm, moveCaret) { 14465 if (moveCaret === void 0) { 14466 moveCaret = true; 14467 } 14468 var afterDeletePos = findCaretPosOutsideElmAfterDelete(forward, editor.getBody(), elm.dom); 14469 var parentBlock = ancestor$3(elm, curry(isBlock, editor), eqRawNode(editor.getBody())); 14470 var normalizedAfterDeletePos = deleteNormalized(elm, afterDeletePos, isInlineElement(editor, elm)); 14471 if (editor.dom.isEmpty(editor.getBody())) { 14472 editor.setContent(''); 14473 editor.selection.setCursorLocation(); 14474 } else { 14475 parentBlock.bind(paddEmptyBlock).fold(function () { 14476 if (moveCaret) { 14477 setSelection$1(editor, forward, normalizedAfterDeletePos); 14478 } 14479 }, function (paddPos) { 14480 if (moveCaret) { 14481 setSelection$1(editor, forward, Optional.some(paddPos)); 14482 } 14483 }); 14484 } 14485 }; 14486 14487 var isRootFromElement = function (root) { 14488 return function (cur) { 14489 return eq(root, cur); 14490 }; 14491 }; 14492 var getTableCells = function (table) { 14493 return descendants(table, 'td,th'); 14494 }; 14495 var getTableDetailsFromRange = function (rng, isRoot) { 14496 var getTable = function (node) { 14497 return getClosestTable(SugarElement.fromDom(node), isRoot); 14498 }; 14499 var startTable = getTable(rng.startContainer); 14500 var endTable = getTable(rng.endContainer); 14501 var isStartInTable = startTable.isSome(); 14502 var isEndInTable = endTable.isSome(); 14503 var isSameTable = lift2(startTable, endTable, eq).getOr(false); 14504 var isMultiTable = !isSameTable && isStartInTable && isEndInTable; 14505 return { 14506 startTable: startTable, 14507 endTable: endTable, 14508 isStartInTable: isStartInTable, 14509 isEndInTable: isEndInTable, 14510 isSameTable: isSameTable, 14511 isMultiTable: isMultiTable 14512 }; 14513 }; 14514 14515 var tableCellRng = function (start, end) { 14516 return { 14517 start: start, 14518 end: end 14519 }; 14520 }; 14521 var tableSelection = function (rng, table, cells) { 14522 return { 14523 rng: rng, 14524 table: table, 14525 cells: cells 14526 }; 14527 }; 14528 var deleteAction = Adt.generate([ 14529 { 14530 singleCellTable: [ 14531 'rng', 14532 'cell' 14533 ] 14534 }, 14535 { fullTable: ['table'] }, 14536 { 14537 partialTable: [ 14538 'cells', 14539 'outsideDetails' 14540 ] 14541 }, 14542 { 14543 multiTable: [ 14544 'startTableCells', 14545 'endTableCells', 14546 'betweenRng' 14547 ] 14548 } 14549 ]); 14550 var getClosestCell$1 = function (container, isRoot) { 14551 return closest$2(SugarElement.fromDom(container), 'td,th', isRoot); 14552 }; 14553 var isExpandedCellRng = function (cellRng) { 14554 return !eq(cellRng.start, cellRng.end); 14555 }; 14556 var getTableFromCellRng = function (cellRng, isRoot) { 14557 return getClosestTable(cellRng.start, isRoot).bind(function (startParentTable) { 14558 return getClosestTable(cellRng.end, isRoot).bind(function (endParentTable) { 14559 return someIf(eq(startParentTable, endParentTable), startParentTable); 14560 }); 14561 }); 14562 }; 14563 var isSingleCellTable = function (cellRng, isRoot) { 14564 return !isExpandedCellRng(cellRng) && getTableFromCellRng(cellRng, isRoot).exists(function (table) { 14565 var rows = table.dom.rows; 14566 return rows.length === 1 && rows[0].cells.length === 1; 14567 }); 14568 }; 14569 var getCellRng = function (rng, isRoot) { 14570 var startCell = getClosestCell$1(rng.startContainer, isRoot); 14571 var endCell = getClosestCell$1(rng.endContainer, isRoot); 14572 return lift2(startCell, endCell, tableCellRng); 14573 }; 14574 var getCellRangeFromStartTable = function (isRoot) { 14575 return function (startCell) { 14576 return getClosestTable(startCell, isRoot).bind(function (table) { 14577 return last$2(getTableCells(table)).map(function (endCell) { 14578 return tableCellRng(startCell, endCell); 14579 }); 14580 }); 14581 }; 14582 }; 14583 var getCellRangeFromEndTable = function (isRoot) { 14584 return function (endCell) { 14585 return getClosestTable(endCell, isRoot).bind(function (table) { 14586 return head(getTableCells(table)).map(function (startCell) { 14587 return tableCellRng(startCell, endCell); 14588 }); 14589 }); 14590 }; 14591 }; 14592 var getTableSelectionFromCellRng = function (isRoot) { 14593 return function (cellRng) { 14594 return getTableFromCellRng(cellRng, isRoot).map(function (table) { 14595 return tableSelection(cellRng, table, getTableCells(table)); 14596 }); 14597 }; 14598 }; 14599 var getTableSelections = function (cellRng, selectionDetails, rng, isRoot) { 14600 if (rng.collapsed || !cellRng.forall(isExpandedCellRng)) { 14601 return Optional.none(); 14602 } else if (selectionDetails.isSameTable) { 14603 var sameTableSelection = cellRng.bind(getTableSelectionFromCellRng(isRoot)); 14604 return Optional.some({ 14605 start: sameTableSelection, 14606 end: sameTableSelection 14607 }); 14608 } else { 14609 var startCell = getClosestCell$1(rng.startContainer, isRoot); 14610 var endCell = getClosestCell$1(rng.endContainer, isRoot); 14611 var startTableSelection = startCell.bind(getCellRangeFromStartTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot)); 14612 var endTableSelection = endCell.bind(getCellRangeFromEndTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot)); 14613 return Optional.some({ 14614 start: startTableSelection, 14615 end: endTableSelection 14616 }); 14617 } 14618 }; 14619 var getCellIndex = function (cells, cell) { 14620 return findIndex$2(cells, function (x) { 14621 return eq(x, cell); 14622 }); 14623 }; 14624 var getSelectedCells = function (tableSelection) { 14625 return lift2(getCellIndex(tableSelection.cells, tableSelection.rng.start), getCellIndex(tableSelection.cells, tableSelection.rng.end), function (startIndex, endIndex) { 14626 return tableSelection.cells.slice(startIndex, endIndex + 1); 14627 }); 14628 }; 14629 var isSingleCellTableContentSelected = function (optCellRng, rng, isRoot) { 14630 return optCellRng.exists(function (cellRng) { 14631 return isSingleCellTable(cellRng, isRoot) && hasAllContentsSelected(cellRng.start, rng); 14632 }); 14633 }; 14634 var unselectCells = function (rng, selectionDetails) { 14635 var startTable = selectionDetails.startTable, endTable = selectionDetails.endTable; 14636 var otherContentRng = rng.cloneRange(); 14637 startTable.each(function (table) { 14638 return otherContentRng.setStartAfter(table.dom); 14639 }); 14640 endTable.each(function (table) { 14641 return otherContentRng.setEndBefore(table.dom); 14642 }); 14643 return otherContentRng; 14644 }; 14645 var handleSingleTable = function (cellRng, selectionDetails, rng, isRoot) { 14646 return getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(function (_a) { 14647 var start = _a.start, end = _a.end; 14648 return start.or(end); 14649 }).bind(function (tableSelection) { 14650 var isSameTable = selectionDetails.isSameTable; 14651 var selectedCells = getSelectedCells(tableSelection).getOr([]); 14652 if (isSameTable && tableSelection.cells.length === selectedCells.length) { 14653 return Optional.some(deleteAction.fullTable(tableSelection.table)); 14654 } else if (selectedCells.length > 0) { 14655 if (isSameTable) { 14656 return Optional.some(deleteAction.partialTable(selectedCells, Optional.none())); 14657 } else { 14658 var otherContentRng = unselectCells(rng, selectionDetails); 14659 return Optional.some(deleteAction.partialTable(selectedCells, Optional.some(__assign(__assign({}, selectionDetails), { rng: otherContentRng })))); 14660 } 14661 } else { 14662 return Optional.none(); 14663 } 14664 }); 14665 }; 14666 var handleMultiTable = function (cellRng, selectionDetails, rng, isRoot) { 14667 return getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(function (_a) { 14668 var start = _a.start, end = _a.end; 14669 var startTableSelectedCells = start.bind(getSelectedCells).getOr([]); 14670 var endTableSelectedCells = end.bind(getSelectedCells).getOr([]); 14671 if (startTableSelectedCells.length > 0 && endTableSelectedCells.length > 0) { 14672 var otherContentRng = unselectCells(rng, selectionDetails); 14673 return Optional.some(deleteAction.multiTable(startTableSelectedCells, endTableSelectedCells, otherContentRng)); 14674 } else { 14675 return Optional.none(); 14676 } 14677 }); 14678 }; 14679 var getActionFromRange = function (root, rng) { 14680 var isRoot = isRootFromElement(root); 14681 var optCellRng = getCellRng(rng, isRoot); 14682 var selectionDetails = getTableDetailsFromRange(rng, isRoot); 14683 if (isSingleCellTableContentSelected(optCellRng, rng, isRoot)) { 14684 return optCellRng.map(function (cellRng) { 14685 return deleteAction.singleCellTable(rng, cellRng.start); 14686 }); 14687 } else if (selectionDetails.isMultiTable) { 14688 return handleMultiTable(optCellRng, selectionDetails, rng, isRoot); 14689 } else { 14690 return handleSingleTable(optCellRng, selectionDetails, rng, isRoot); 14691 } 14692 }; 14693 14694 var freefallRtl = function (root) { 14695 var child = isComment$1(root) ? prevSibling(root) : lastChild(root); 14696 return child.bind(freefallRtl).orThunk(function () { 14697 return Optional.some(root); 14698 }); 14699 }; 14700 var cleanCells = function (cells) { 14701 return each$k(cells, function (cell) { 14702 remove$6(cell, 'contenteditable'); 14703 fillWithPaddingBr(cell); 14704 }); 14705 }; 14706 var getOutsideBlock = function (editor, container) { 14707 return Optional.from(editor.dom.getParent(container, editor.dom.isBlock)).map(SugarElement.fromDom); 14708 }; 14709 var handleEmptyBlock = function (editor, startInTable, emptyBlock) { 14710 emptyBlock.each(function (block) { 14711 if (startInTable) { 14712 remove$7(block); 14713 } else { 14714 fillWithPaddingBr(block); 14715 editor.selection.setCursorLocation(block.dom, 0); 14716 } 14717 }); 14718 }; 14719 var deleteContentInsideCell = function (editor, cell, rng, isFirstCellInSelection) { 14720 var insideTableRng = rng.cloneRange(); 14721 if (isFirstCellInSelection) { 14722 insideTableRng.setStart(rng.startContainer, rng.startOffset); 14723 insideTableRng.setEndAfter(cell.dom.lastChild); 14724 } else { 14725 insideTableRng.setStartBefore(cell.dom.firstChild); 14726 insideTableRng.setEnd(rng.endContainer, rng.endOffset); 14727 } 14728 deleteCellContents(editor, insideTableRng, cell, false); 14729 }; 14730 var collapseAndRestoreCellSelection = function (editor) { 14731 var selectedCells = getCellsFromEditor(editor); 14732 var selectedNode = SugarElement.fromDom(editor.selection.getNode()); 14733 if (isTableCell$5(selectedNode.dom) && isEmpty$2(selectedNode)) { 14734 editor.selection.setCursorLocation(selectedNode.dom, 0); 14735 } else { 14736 editor.selection.collapse(true); 14737 } 14738 if (selectedCells.length > 1 && exists(selectedCells, function (cell) { 14739 return eq(cell, selectedNode); 14740 })) { 14741 set$1(selectedNode, 'data-mce-selected', '1'); 14742 } 14743 }; 14744 var emptySingleTableCells = function (editor, cells, outsideDetails) { 14745 var editorRng = editor.selection.getRng(); 14746 var cellsToClean = outsideDetails.bind(function (_a) { 14747 var rng = _a.rng, isStartInTable = _a.isStartInTable; 14748 var outsideBlock = getOutsideBlock(editor, isStartInTable ? rng.endContainer : rng.startContainer); 14749 rng.deleteContents(); 14750 handleEmptyBlock(editor, isStartInTable, outsideBlock.filter(isEmpty$2)); 14751 var endPointCell = isStartInTable ? cells[0] : cells[cells.length - 1]; 14752 deleteContentInsideCell(editor, endPointCell, editorRng, isStartInTable); 14753 if (!isEmpty$2(endPointCell)) { 14754 return Optional.some(isStartInTable ? cells.slice(1) : cells.slice(0, -1)); 14755 } else { 14756 return Optional.none(); 14757 } 14758 }).getOr(cells); 14759 cleanCells(cellsToClean); 14760 collapseAndRestoreCellSelection(editor); 14761 return true; 14762 }; 14763 var emptyMultiTableCells = function (editor, startTableCells, endTableCells, betweenRng) { 14764 var rng = editor.selection.getRng(); 14765 var startCell = startTableCells[0]; 14766 var endCell = endTableCells[endTableCells.length - 1]; 14767 deleteContentInsideCell(editor, startCell, rng, true); 14768 deleteContentInsideCell(editor, endCell, rng, false); 14769 var startTableCellsToClean = isEmpty$2(startCell) ? startTableCells : startTableCells.slice(1); 14770 var endTableCellsToClean = isEmpty$2(endCell) ? endTableCells : endTableCells.slice(0, -1); 14771 cleanCells(startTableCellsToClean.concat(endTableCellsToClean)); 14772 betweenRng.deleteContents(); 14773 collapseAndRestoreCellSelection(editor); 14774 return true; 14775 }; 14776 var deleteCellContents = function (editor, rng, cell, moveSelection) { 14777 if (moveSelection === void 0) { 14778 moveSelection = true; 14779 } 14780 rng.deleteContents(); 14781 var lastNode = freefallRtl(cell).getOr(cell); 14782 var lastBlock = SugarElement.fromDom(editor.dom.getParent(lastNode.dom, editor.dom.isBlock)); 14783 if (isEmpty$2(lastBlock)) { 14784 fillWithPaddingBr(lastBlock); 14785 if (moveSelection) { 14786 editor.selection.setCursorLocation(lastBlock.dom, 0); 14787 } 14788 } 14789 if (!eq(cell, lastBlock)) { 14790 var additionalCleanupNodes = is$1(parent(lastBlock), cell) ? [] : siblings(lastBlock); 14791 each$k(additionalCleanupNodes.concat(children(cell)), function (node) { 14792 if (!eq(node, lastBlock) && !contains$1(node, lastBlock) && isEmpty$2(node)) { 14793 remove$7(node); 14794 } 14795 }); 14796 } 14797 return true; 14798 }; 14799 var deleteTableElement = function (editor, table) { 14800 deleteElement$2(editor, false, table); 14801 return true; 14802 }; 14803 var deleteCellRange = function (editor, rootElm, rng) { 14804 return getActionFromRange(rootElm, rng).map(function (action) { 14805 return action.fold(curry(deleteCellContents, editor), curry(deleteTableElement, editor), curry(emptySingleTableCells, editor), curry(emptyMultiTableCells, editor)); 14806 }); 14807 }; 14808 var deleteCaptionRange = function (editor, caption) { 14809 return emptyElement(editor, caption); 14810 }; 14811 var deleteTableRange = function (editor, rootElm, rng, startElm) { 14812 return getParentCaption(rootElm, startElm).fold(function () { 14813 return deleteCellRange(editor, rootElm, rng); 14814 }, function (caption) { 14815 return deleteCaptionRange(editor, caption); 14816 }).getOr(false); 14817 }; 14818 var deleteRange$2 = function (editor, startElm, selectedCells) { 14819 var rootNode = SugarElement.fromDom(editor.getBody()); 14820 var rng = editor.selection.getRng(); 14821 return selectedCells.length !== 0 ? emptySingleTableCells(editor, selectedCells, Optional.none()) : deleteTableRange(editor, rootNode, rng, startElm); 14822 }; 14823 var getParentCell = function (rootElm, elm) { 14824 return find$3(parentsAndSelf(elm, rootElm), isTableCell$4); 14825 }; 14826 var getParentCaption = function (rootElm, elm) { 14827 return find$3(parentsAndSelf(elm, rootElm), isTag('caption')); 14828 }; 14829 var deleteBetweenCells = function (editor, rootElm, forward, fromCell, from) { 14830 return navigate(forward, editor.getBody(), from).bind(function (to) { 14831 return getParentCell(rootElm, SugarElement.fromDom(to.getNode())).map(function (toCell) { 14832 return eq(toCell, fromCell) === false; 14833 }); 14834 }); 14835 }; 14836 var emptyElement = function (editor, elm) { 14837 fillWithPaddingBr(elm); 14838 editor.selection.setCursorLocation(elm.dom, 0); 14839 return Optional.some(true); 14840 }; 14841 var isDeleteOfLastCharPos = function (fromCaption, forward, from, to) { 14842 return firstPositionIn(fromCaption.dom).bind(function (first) { 14843 return lastPositionIn(fromCaption.dom).map(function (last) { 14844 return forward ? from.isEqual(first) && to.isEqual(last) : from.isEqual(last) && to.isEqual(first); 14845 }); 14846 }).getOr(true); 14847 }; 14848 var emptyCaretCaption = function (editor, elm) { 14849 return emptyElement(editor, elm); 14850 }; 14851 var validateCaretCaption = function (rootElm, fromCaption, to) { 14852 return getParentCaption(rootElm, SugarElement.fromDom(to.getNode())).map(function (toCaption) { 14853 return eq(toCaption, fromCaption) === false; 14854 }); 14855 }; 14856 var deleteCaretInsideCaption = function (editor, rootElm, forward, fromCaption, from) { 14857 return navigate(forward, editor.getBody(), from).bind(function (to) { 14858 return isDeleteOfLastCharPos(fromCaption, forward, from, to) ? emptyCaretCaption(editor, fromCaption) : validateCaretCaption(rootElm, fromCaption, to); 14859 }).or(Optional.some(true)); 14860 }; 14861 var deleteCaretCells = function (editor, forward, rootElm, startElm) { 14862 var from = CaretPosition.fromRangeStart(editor.selection.getRng()); 14863 return getParentCell(rootElm, startElm).bind(function (fromCell) { 14864 return isEmpty$2(fromCell) ? emptyElement(editor, fromCell) : deleteBetweenCells(editor, rootElm, forward, fromCell, from); 14865 }).getOr(false); 14866 }; 14867 var deleteCaretCaption = function (editor, forward, rootElm, fromCaption) { 14868 var from = CaretPosition.fromRangeStart(editor.selection.getRng()); 14869 return isEmpty$2(fromCaption) ? emptyElement(editor, fromCaption) : deleteCaretInsideCaption(editor, rootElm, forward, fromCaption, from); 14870 }; 14871 var isNearTable = function (forward, pos) { 14872 return forward ? isBeforeTable(pos) : isAfterTable(pos); 14873 }; 14874 var isBeforeOrAfterTable = function (editor, forward) { 14875 var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng()); 14876 return isNearTable(forward, fromPos) || fromPosition(forward, editor.getBody(), fromPos).exists(function (pos) { 14877 return isNearTable(forward, pos); 14878 }); 14879 }; 14880 var deleteCaret$3 = function (editor, forward, startElm) { 14881 var rootElm = SugarElement.fromDom(editor.getBody()); 14882 return getParentCaption(rootElm, startElm).fold(function () { 14883 return deleteCaretCells(editor, forward, rootElm, startElm) || isBeforeOrAfterTable(editor, forward); 14884 }, function (fromCaption) { 14885 return deleteCaretCaption(editor, forward, rootElm, fromCaption).getOr(false); 14886 }); 14887 }; 14888 var backspaceDelete$9 = function (editor, forward) { 14889 var startElm = SugarElement.fromDom(editor.selection.getStart(true)); 14890 var cells = getCellsFromEditor(editor); 14891 return editor.selection.isCollapsed() && cells.length === 0 ? deleteCaret$3(editor, forward, startElm) : deleteRange$2(editor, startElm, cells); 14892 }; 14893 14894 var createRange = function (sc, so, ec, eo) { 14895 var rng = document.createRange(); 14896 rng.setStart(sc, so); 14897 rng.setEnd(ec, eo); 14898 return rng; 14899 }; 14900 var normalizeBlockSelectionRange = function (rng) { 14901 var startPos = CaretPosition.fromRangeStart(rng); 14902 var endPos = CaretPosition.fromRangeEnd(rng); 14903 var rootNode = rng.commonAncestorContainer; 14904 return fromPosition(false, rootNode, endPos).map(function (newEndPos) { 14905 if (!isInSameBlock(startPos, endPos, rootNode) && isInSameBlock(startPos, newEndPos, rootNode)) { 14906 return createRange(startPos.container(), startPos.offset(), newEndPos.container(), newEndPos.offset()); 14907 } else { 14908 return rng; 14909 } 14910 }).getOr(rng); 14911 }; 14912 var normalize = function (rng) { 14913 return rng.collapsed ? rng : normalizeBlockSelectionRange(rng); 14914 }; 14915 14916 var hasOnlyOneChild$1 = function (node) { 14917 return node.firstChild && node.firstChild === node.lastChild; 14918 }; 14919 var isPaddingNode = function (node) { 14920 return node.name === 'br' || node.value === nbsp; 14921 }; 14922 var isPaddedEmptyBlock = function (schema, node) { 14923 var blockElements = schema.getBlockElements(); 14924 return blockElements[node.name] && hasOnlyOneChild$1(node) && isPaddingNode(node.firstChild); 14925 }; 14926 var isEmptyFragmentElement = function (schema, node) { 14927 var nonEmptyElements = schema.getNonEmptyElements(); 14928 return node && (node.isEmpty(nonEmptyElements) || isPaddedEmptyBlock(schema, node)); 14929 }; 14930 var isListFragment = function (schema, fragment) { 14931 var firstChild = fragment.firstChild; 14932 var lastChild = fragment.lastChild; 14933 if (firstChild && firstChild.name === 'meta') { 14934 firstChild = firstChild.next; 14935 } 14936 if (lastChild && lastChild.attr('id') === 'mce_marker') { 14937 lastChild = lastChild.prev; 14938 } 14939 if (isEmptyFragmentElement(schema, lastChild)) { 14940 lastChild = lastChild.prev; 14941 } 14942 if (!firstChild || firstChild !== lastChild) { 14943 return false; 14944 } 14945 return firstChild.name === 'ul' || firstChild.name === 'ol'; 14946 }; 14947 var cleanupDomFragment = function (domFragment) { 14948 var firstChild = domFragment.firstChild; 14949 var lastChild = domFragment.lastChild; 14950 if (firstChild && firstChild.nodeName === 'META') { 14951 firstChild.parentNode.removeChild(firstChild); 14952 } 14953 if (lastChild && lastChild.id === 'mce_marker') { 14954 lastChild.parentNode.removeChild(lastChild); 14955 } 14956 return domFragment; 14957 }; 14958 var toDomFragment = function (dom, serializer, fragment) { 14959 var html = serializer.serialize(fragment); 14960 var domFragment = dom.createFragment(html); 14961 return cleanupDomFragment(domFragment); 14962 }; 14963 var listItems = function (elm) { 14964 return filter$4(elm.childNodes, function (child) { 14965 return child.nodeName === 'LI'; 14966 }); 14967 }; 14968 var isPadding = function (node) { 14969 return node.data === nbsp || isBr$5(node); 14970 }; 14971 var isListItemPadded = function (node) { 14972 return node && node.firstChild && node.firstChild === node.lastChild && isPadding(node.firstChild); 14973 }; 14974 var isEmptyOrPadded = function (elm) { 14975 return !elm.firstChild || isListItemPadded(elm); 14976 }; 14977 var trimListItems = function (elms) { 14978 return elms.length > 0 && isEmptyOrPadded(elms[elms.length - 1]) ? elms.slice(0, -1) : elms; 14979 }; 14980 var getParentLi = function (dom, node) { 14981 var parentBlock = dom.getParent(node, dom.isBlock); 14982 return parentBlock && parentBlock.nodeName === 'LI' ? parentBlock : null; 14983 }; 14984 var isParentBlockLi = function (dom, node) { 14985 return !!getParentLi(dom, node); 14986 }; 14987 var getSplit = function (parentNode, rng) { 14988 var beforeRng = rng.cloneRange(); 14989 var afterRng = rng.cloneRange(); 14990 beforeRng.setStartBefore(parentNode); 14991 afterRng.setEndAfter(parentNode); 14992 return [ 14993 beforeRng.cloneContents(), 14994 afterRng.cloneContents() 14995 ]; 14996 }; 14997 var findFirstIn = function (node, rootNode) { 14998 var caretPos = CaretPosition.before(node); 14999 var caretWalker = CaretWalker(rootNode); 15000 var newCaretPos = caretWalker.next(caretPos); 15001 return newCaretPos ? newCaretPos.toRange() : null; 15002 }; 15003 var findLastOf = function (node, rootNode) { 15004 var caretPos = CaretPosition.after(node); 15005 var caretWalker = CaretWalker(rootNode); 15006 var newCaretPos = caretWalker.prev(caretPos); 15007 return newCaretPos ? newCaretPos.toRange() : null; 15008 }; 15009 var insertMiddle = function (target, elms, rootNode, rng) { 15010 var parts = getSplit(target, rng); 15011 var parentElm = target.parentNode; 15012 parentElm.insertBefore(parts[0], target); 15013 Tools.each(elms, function (li) { 15014 parentElm.insertBefore(li, target); 15015 }); 15016 parentElm.insertBefore(parts[1], target); 15017 parentElm.removeChild(target); 15018 return findLastOf(elms[elms.length - 1], rootNode); 15019 }; 15020 var insertBefore$1 = function (target, elms, rootNode) { 15021 var parentElm = target.parentNode; 15022 Tools.each(elms, function (elm) { 15023 parentElm.insertBefore(elm, target); 15024 }); 15025 return findFirstIn(target, rootNode); 15026 }; 15027 var insertAfter$1 = function (target, elms, rootNode, dom) { 15028 dom.insertAfter(elms.reverse(), target); 15029 return findLastOf(elms[0], rootNode); 15030 }; 15031 var insertAtCaret$1 = function (serializer, dom, rng, fragment) { 15032 var domFragment = toDomFragment(dom, serializer, fragment); 15033 var liTarget = getParentLi(dom, rng.startContainer); 15034 var liElms = trimListItems(listItems(domFragment.firstChild)); 15035 var BEGINNING = 1, END = 2; 15036 var rootNode = dom.getRoot(); 15037 var isAt = function (location) { 15038 var caretPos = CaretPosition.fromRangeStart(rng); 15039 var caretWalker = CaretWalker(dom.getRoot()); 15040 var newPos = location === BEGINNING ? caretWalker.prev(caretPos) : caretWalker.next(caretPos); 15041 return newPos ? getParentLi(dom, newPos.getNode()) !== liTarget : true; 15042 }; 15043 if (isAt(BEGINNING)) { 15044 return insertBefore$1(liTarget, liElms, rootNode); 15045 } else if (isAt(END)) { 15046 return insertAfter$1(liTarget, liElms, rootNode, dom); 15047 } 15048 return insertMiddle(liTarget, liElms, rootNode, rng); 15049 }; 15050 15051 var trimOrPadLeftRight = function (dom, rng, html) { 15052 var root = SugarElement.fromDom(dom.getRoot()); 15053 if (needsToBeNbspLeft(root, CaretPosition.fromRangeStart(rng))) { 15054 html = html.replace(/^ /, ' '); 15055 } else { 15056 html = html.replace(/^ /, ' '); 15057 } 15058 if (needsToBeNbspRight(root, CaretPosition.fromRangeEnd(rng))) { 15059 html = html.replace(/( | )(<br( \/)>)?$/, ' '); 15060 } else { 15061 html = html.replace(/ (<br( \/)?>)?$/, ' '); 15062 } 15063 return html; 15064 }; 15065 15066 var isTableCell$1 = isTableCell$5; 15067 var isTableCellContentSelected = function (dom, rng, cell) { 15068 if (cell !== null) { 15069 var endCell = dom.getParent(rng.endContainer, isTableCell$1); 15070 return cell === endCell && hasAllContentsSelected(SugarElement.fromDom(cell), rng); 15071 } else { 15072 return false; 15073 } 15074 }; 15075 var validInsertion = function (editor, value, parentNode) { 15076 if (parentNode.getAttribute('data-mce-bogus') === 'all') { 15077 parentNode.parentNode.insertBefore(editor.dom.createFragment(value), parentNode); 15078 } else { 15079 var node = parentNode.firstChild; 15080 var node2 = parentNode.lastChild; 15081 if (!node || node === node2 && node.nodeName === 'BR') { 15082 editor.dom.setHTML(parentNode, value); 15083 } else { 15084 editor.selection.setContent(value); 15085 } 15086 } 15087 }; 15088 var trimBrsFromTableCell = function (dom, elm) { 15089 Optional.from(dom.getParent(elm, 'td,th')).map(SugarElement.fromDom).each(trimBlockTrailingBr); 15090 }; 15091 var reduceInlineTextElements = function (editor, merge) { 15092 var textInlineElements = editor.schema.getTextInlineElements(); 15093 var dom = editor.dom; 15094 if (merge) { 15095 var root_1 = editor.getBody(); 15096 var elementUtils_1 = ElementUtils(dom); 15097 Tools.each(dom.select('*[data-mce-fragment]'), function (node) { 15098 var isInline = isNonNullable(textInlineElements[node.nodeName.toLowerCase()]); 15099 if (isInline && hasInheritableStyles(dom, node)) { 15100 for (var parentNode = node.parentNode; isNonNullable(parentNode) && parentNode !== root_1; parentNode = parentNode.parentNode) { 15101 var styleConflict = hasStyleConflict(dom, node, parentNode); 15102 if (styleConflict) { 15103 break; 15104 } 15105 if (elementUtils_1.compare(parentNode, node)) { 15106 dom.remove(node, true); 15107 break; 15108 } 15109 } 15110 } 15111 }); 15112 } 15113 }; 15114 var markFragmentElements = function (fragment) { 15115 var node = fragment; 15116 while (node = node.walk()) { 15117 if (node.type === 1) { 15118 node.attr('data-mce-fragment', '1'); 15119 } 15120 } 15121 }; 15122 var unmarkFragmentElements = function (elm) { 15123 Tools.each(elm.getElementsByTagName('*'), function (elm) { 15124 elm.removeAttribute('data-mce-fragment'); 15125 }); 15126 }; 15127 var isPartOfFragment = function (node) { 15128 return !!node.getAttribute('data-mce-fragment'); 15129 }; 15130 var canHaveChildren = function (editor, node) { 15131 return node && !editor.schema.getShortEndedElements()[node.nodeName]; 15132 }; 15133 var moveSelectionToMarker = function (editor, marker) { 15134 var nextRng; 15135 var dom = editor.dom; 15136 var selection = editor.selection; 15137 if (!marker) { 15138 return; 15139 } 15140 selection.scrollIntoView(marker); 15141 var parentEditableElm = getContentEditableRoot$1(editor.getBody(), marker); 15142 if (dom.getContentEditable(parentEditableElm) === 'false') { 15143 dom.remove(marker); 15144 selection.select(parentEditableElm); 15145 return; 15146 } 15147 var rng = dom.createRng(); 15148 var node = marker.previousSibling; 15149 if (isText$7(node)) { 15150 rng.setStart(node, node.nodeValue.length); 15151 if (!Env.ie) { 15152 var node2 = marker.nextSibling; 15153 if (isText$7(node2)) { 15154 node.appendData(node2.data); 15155 node2.parentNode.removeChild(node2); 15156 } 15157 } 15158 } else { 15159 rng.setStartBefore(marker); 15160 rng.setEndBefore(marker); 15161 } 15162 var findNextCaretRng = function (rng) { 15163 var caretPos = CaretPosition.fromRangeStart(rng); 15164 var caretWalker = CaretWalker(editor.getBody()); 15165 caretPos = caretWalker.next(caretPos); 15166 if (caretPos) { 15167 return caretPos.toRange(); 15168 } 15169 }; 15170 var parentBlock = dom.getParent(marker, dom.isBlock); 15171 dom.remove(marker); 15172 if (parentBlock && dom.isEmpty(parentBlock)) { 15173 editor.$(parentBlock).empty(); 15174 rng.setStart(parentBlock, 0); 15175 rng.setEnd(parentBlock, 0); 15176 if (!isTableCell$1(parentBlock) && !isPartOfFragment(parentBlock) && (nextRng = findNextCaretRng(rng))) { 15177 rng = nextRng; 15178 dom.remove(parentBlock); 15179 } else { 15180 dom.add(parentBlock, dom.create('br', { 'data-mce-bogus': '1' })); 15181 } 15182 } 15183 selection.setRng(rng); 15184 }; 15185 var deleteSelectedContent = function (editor) { 15186 var dom = editor.dom; 15187 var rng = normalize(editor.selection.getRng()); 15188 editor.selection.setRng(rng); 15189 var startCell = dom.getParent(rng.startContainer, isTableCell$1); 15190 if (isTableCellContentSelected(dom, rng, startCell)) { 15191 deleteCellContents(editor, rng, SugarElement.fromDom(startCell)); 15192 } else { 15193 editor.getDoc().execCommand('Delete', false, null); 15194 } 15195 }; 15196 var insertHtmlAtCaret = function (editor, value, details) { 15197 var parentNode; 15198 var rng, node; 15199 var selection = editor.selection; 15200 var dom = editor.dom; 15201 if (/^ | $/.test(value)) { 15202 value = trimOrPadLeftRight(dom, selection.getRng(), value); 15203 } 15204 var parser = editor.parser; 15205 var merge = details.merge; 15206 var serializer = HtmlSerializer({ validate: shouldValidate(editor) }, editor.schema); 15207 var bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark"></span>'; 15208 var args = editor.fire('BeforeSetContent', { 15209 content: value, 15210 format: 'html', 15211 selection: true, 15212 paste: details.paste 15213 }); 15214 if (args.isDefaultPrevented()) { 15215 editor.fire('SetContent', { 15216 content: args.content, 15217 format: 'html', 15218 selection: true, 15219 paste: details.paste 15220 }); 15221 return; 15222 } 15223 value = args.content; 15224 if (value.indexOf('{$caret}') === -1) { 15225 value += '{$caret}'; 15226 } 15227 value = value.replace(/\{\$caret\}/, bookmarkHtml); 15228 rng = selection.getRng(); 15229 var caretElement = rng.startContainer || (rng.parentElement ? rng.parentElement() : null); 15230 var body = editor.getBody(); 15231 if (caretElement === body && selection.isCollapsed()) { 15232 if (dom.isBlock(body.firstChild) && canHaveChildren(editor, body.firstChild) && dom.isEmpty(body.firstChild)) { 15233 rng = dom.createRng(); 15234 rng.setStart(body.firstChild, 0); 15235 rng.setEnd(body.firstChild, 0); 15236 selection.setRng(rng); 15237 } 15238 } 15239 if (!selection.isCollapsed()) { 15240 deleteSelectedContent(editor); 15241 } 15242 parentNode = selection.getNode(); 15243 var parserArgs = { 15244 context: parentNode.nodeName.toLowerCase(), 15245 data: details.data, 15246 insert: true 15247 }; 15248 var fragment = parser.parse(value, parserArgs); 15249 if (details.paste === true && isListFragment(editor.schema, fragment) && isParentBlockLi(dom, parentNode)) { 15250 rng = insertAtCaret$1(serializer, dom, selection.getRng(), fragment); 15251 selection.setRng(rng); 15252 editor.fire('SetContent', args); 15253 return; 15254 } 15255 markFragmentElements(fragment); 15256 node = fragment.lastChild; 15257 if (node.attr('id') === 'mce_marker') { 15258 var marker = node; 15259 for (node = node.prev; node; node = node.walk(true)) { 15260 if (node.type === 3 || !dom.isBlock(node.name)) { 15261 if (editor.schema.isValidChild(node.parent.name, 'span')) { 15262 node.parent.insert(marker, node, node.name === 'br'); 15263 } 15264 break; 15265 } 15266 } 15267 } 15268 editor._selectionOverrides.showBlockCaretContainer(parentNode); 15269 if (!parserArgs.invalid) { 15270 value = serializer.serialize(fragment); 15271 validInsertion(editor, value, parentNode); 15272 } else { 15273 editor.selection.setContent(bookmarkHtml); 15274 parentNode = selection.getNode(); 15275 var rootNode = editor.getBody(); 15276 if (parentNode.nodeType === 9) { 15277 parentNode = node = rootNode; 15278 } else { 15279 node = parentNode; 15280 } 15281 while (node !== rootNode) { 15282 parentNode = node; 15283 node = node.parentNode; 15284 } 15285 value = parentNode === rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode); 15286 value = serializer.serialize(parser.parse(value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function () { 15287 return serializer.serialize(fragment); 15288 }))); 15289 if (parentNode === rootNode) { 15290 dom.setHTML(rootNode, value); 15291 } else { 15292 dom.setOuterHTML(parentNode, value); 15293 } 15294 } 15295 reduceInlineTextElements(editor, merge); 15296 moveSelectionToMarker(editor, dom.get('mce_marker')); 15297 unmarkFragmentElements(editor.getBody()); 15298 trimBrsFromTableCell(dom, selection.getStart()); 15299 editor.fire('SetContent', args); 15300 editor.addVisual(); 15301 }; 15302 15303 var traverse = function (node, fn) { 15304 fn(node); 15305 if (node.firstChild) { 15306 traverse(node.firstChild, fn); 15307 } 15308 if (node.next) { 15309 traverse(node.next, fn); 15310 } 15311 }; 15312 var findMatchingNodes = function (nodeFilters, attributeFilters, node) { 15313 var nodeMatches = {}; 15314 var attrMatches = {}; 15315 var matches = []; 15316 if (node.firstChild) { 15317 traverse(node.firstChild, function (node) { 15318 each$k(nodeFilters, function (filter) { 15319 if (filter.name === node.name) { 15320 if (nodeMatches[filter.name]) { 15321 nodeMatches[filter.name].nodes.push(node); 15322 } else { 15323 nodeMatches[filter.name] = { 15324 filter: filter, 15325 nodes: [node] 15326 }; 15327 } 15328 } 15329 }); 15330 each$k(attributeFilters, function (filter) { 15331 if (typeof node.attr(filter.name) === 'string') { 15332 if (attrMatches[filter.name]) { 15333 attrMatches[filter.name].nodes.push(node); 15334 } else { 15335 attrMatches[filter.name] = { 15336 filter: filter, 15337 nodes: [node] 15338 }; 15339 } 15340 } 15341 }); 15342 }); 15343 } 15344 for (var name_1 in nodeMatches) { 15345 if (has$2(nodeMatches, name_1)) { 15346 matches.push(nodeMatches[name_1]); 15347 } 15348 } 15349 for (var name_2 in attrMatches) { 15350 if (has$2(attrMatches, name_2)) { 15351 matches.push(attrMatches[name_2]); 15352 } 15353 } 15354 return matches; 15355 }; 15356 var filter$1 = function (nodeFilters, attributeFilters, node) { 15357 var matches = findMatchingNodes(nodeFilters, attributeFilters, node); 15358 each$k(matches, function (match) { 15359 each$k(match.filter.callbacks, function (callback) { 15360 callback(match.nodes, match.filter.name, {}); 15361 }); 15362 }); 15363 }; 15364 15365 var defaultFormat$1 = 'html'; 15366 var isTreeNode = function (content) { 15367 return content instanceof AstNode; 15368 }; 15369 var moveSelection = function (editor) { 15370 if (hasFocus(editor)) { 15371 firstPositionIn(editor.getBody()).each(function (pos) { 15372 var node = pos.getNode(); 15373 var caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos; 15374 editor.selection.setRng(caretPos.toRange()); 15375 }); 15376 } 15377 }; 15378 var setEditorHtml = function (editor, html, noSelection) { 15379 editor.dom.setHTML(editor.getBody(), html); 15380 if (noSelection !== true) { 15381 moveSelection(editor); 15382 } 15383 }; 15384 var setContentString = function (editor, body, content, args) { 15385 if (content.length === 0 || /^\s+$/.test(content)) { 15386 var padd = '<br data-mce-bogus="1">'; 15387 if (body.nodeName === 'TABLE') { 15388 content = '<tr><td>' + padd + '</td></tr>'; 15389 } else if (/^(UL|OL)$/.test(body.nodeName)) { 15390 content = '<li>' + padd + '</li>'; 15391 } 15392 var forcedRootBlockName = getForcedRootBlock(editor); 15393 if (forcedRootBlockName && editor.schema.isValidChild(body.nodeName.toLowerCase(), forcedRootBlockName.toLowerCase())) { 15394 content = padd; 15395 content = editor.dom.createHTML(forcedRootBlockName, getForcedRootBlockAttrs(editor), content); 15396 } else if (!content) { 15397 content = '<br data-mce-bogus="1">'; 15398 } 15399 setEditorHtml(editor, content, args.no_selection); 15400 editor.fire('SetContent', args); 15401 } else { 15402 if (args.format !== 'raw') { 15403 content = HtmlSerializer({ validate: editor.validate }, editor.schema).serialize(editor.parser.parse(content, { 15404 isRootContent: true, 15405 insert: true 15406 })); 15407 } 15408 args.content = isWsPreserveElement(SugarElement.fromDom(body)) ? content : Tools.trim(content); 15409 setEditorHtml(editor, args.content, args.no_selection); 15410 if (!args.no_events) { 15411 editor.fire('SetContent', args); 15412 } 15413 } 15414 return args.content; 15415 }; 15416 var setContentTree = function (editor, body, content, args) { 15417 filter$1(editor.parser.getNodeFilters(), editor.parser.getAttributeFilters(), content); 15418 var html = HtmlSerializer({ validate: editor.validate }, editor.schema).serialize(content); 15419 args.content = isWsPreserveElement(SugarElement.fromDom(body)) ? html : Tools.trim(html); 15420 setEditorHtml(editor, args.content, args.no_selection); 15421 if (!args.no_events) { 15422 editor.fire('SetContent', args); 15423 } 15424 return content; 15425 }; 15426 var setupArgs$2 = function (args, content) { 15427 return __assign(__assign({ format: defaultFormat$1 }, args), { 15428 set: true, 15429 content: isTreeNode(content) ? '' : content 15430 }); 15431 }; 15432 var setContentInternal = function (editor, content, args) { 15433 var defaultedArgs = setupArgs$2(args, content); 15434 var updatedArgs = args.no_events ? defaultedArgs : editor.fire('BeforeSetContent', defaultedArgs); 15435 if (!isTreeNode(content)) { 15436 content = updatedArgs.content; 15437 } 15438 return Optional.from(editor.getBody()).fold(constant(content), function (body) { 15439 return isTreeNode(content) ? setContentTree(editor, body, content, updatedArgs) : setContentString(editor, body, content, updatedArgs); 15440 }); 15441 }; 15442 15443 var sibling = function (scope, predicate) { 15444 return sibling$2(scope, predicate).isSome(); 15445 }; 15446 15447 var ensureIsRoot = function (isRoot) { 15448 return isFunction(isRoot) ? isRoot : never; 15449 }; 15450 var ancestor = function (scope, transform, isRoot) { 15451 var element = scope.dom; 15452 var stop = ensureIsRoot(isRoot); 15453 while (element.parentNode) { 15454 element = element.parentNode; 15455 var el = SugarElement.fromDom(element); 15456 var transformed = transform(el); 15457 if (transformed.isSome()) { 15458 return transformed; 15459 } else if (stop(el)) { 15460 break; 15461 } 15462 } 15463 return Optional.none(); 15464 }; 15465 var closest$1 = function (scope, transform, isRoot) { 15466 var current = transform(scope); 15467 var stop = ensureIsRoot(isRoot); 15468 return current.orThunk(function () { 15469 return stop(scope) ? Optional.none() : ancestor(scope, transform, stop); 15470 }); 15471 }; 15472 15473 var isEq$3 = isEq$5; 15474 var matchesUnInheritedFormatSelector = function (ed, node, name) { 15475 var formatList = ed.formatter.get(name); 15476 if (formatList) { 15477 for (var i = 0; i < formatList.length; i++) { 15478 var format = formatList[i]; 15479 if (isSelectorFormat(format) && format.inherit === false && ed.dom.is(node, format.selector)) { 15480 return true; 15481 } 15482 } 15483 } 15484 return false; 15485 }; 15486 var matchParents = function (editor, node, name, vars, similar) { 15487 var root = editor.dom.getRoot(); 15488 if (node === root) { 15489 return false; 15490 } 15491 node = editor.dom.getParent(node, function (node) { 15492 if (matchesUnInheritedFormatSelector(editor, node, name)) { 15493 return true; 15494 } 15495 return node.parentNode === root || !!matchNode(editor, node, name, vars, true); 15496 }); 15497 return !!matchNode(editor, node, name, vars, similar); 15498 }; 15499 var matchName$1 = function (dom, node, format) { 15500 if (isEq$3(node, format.inline)) { 15501 return true; 15502 } 15503 if (isEq$3(node, format.block)) { 15504 return true; 15505 } 15506 if (format.selector) { 15507 return node.nodeType === 1 && dom.is(node, format.selector); 15508 } 15509 }; 15510 var matchItems = function (dom, node, format, itemName, similar, vars) { 15511 var items = format[itemName]; 15512 if (isFunction(format.onmatch)) { 15513 return format.onmatch(node, format, itemName); 15514 } 15515 if (items) { 15516 if (isUndefined(items.length)) { 15517 for (var key in items) { 15518 if (has$2(items, key)) { 15519 var value = itemName === 'attributes' ? dom.getAttrib(node, key) : getStyle(dom, node, key); 15520 var expectedValue = replaceVars(items[key], vars); 15521 var isEmptyValue = isNullable(value) || isEmpty$3(value); 15522 if (isEmptyValue && isNullable(expectedValue)) { 15523 continue; 15524 } 15525 if (similar && isEmptyValue && !format.exact) { 15526 return false; 15527 } 15528 if ((!similar || format.exact) && !isEq$3(value, normalizeStyleValue(dom, expectedValue, key))) { 15529 return false; 15530 } 15531 } 15532 } 15533 } else { 15534 for (var i = 0; i < items.length; i++) { 15535 if (itemName === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(dom, node, items[i])) { 15536 return true; 15537 } 15538 } 15539 } 15540 } 15541 return true; 15542 }; 15543 var matchNode = function (ed, node, name, vars, similar) { 15544 var formatList = ed.formatter.get(name); 15545 var dom = ed.dom; 15546 if (formatList && node) { 15547 for (var i = 0; i < formatList.length; i++) { 15548 var format = formatList[i]; 15549 if (matchName$1(ed.dom, node, format) && matchItems(dom, node, format, 'attributes', similar, vars) && matchItems(dom, node, format, 'styles', similar, vars)) { 15550 var classes = format.classes; 15551 if (classes) { 15552 for (var x = 0; x < classes.length; x++) { 15553 if (!ed.dom.hasClass(node, replaceVars(classes[x], vars))) { 15554 return; 15555 } 15556 } 15557 } 15558 return format; 15559 } 15560 } 15561 } 15562 }; 15563 var match$2 = function (editor, name, vars, node, similar) { 15564 if (node) { 15565 return matchParents(editor, node, name, vars, similar); 15566 } 15567 node = editor.selection.getNode(); 15568 if (matchParents(editor, node, name, vars, similar)) { 15569 return true; 15570 } 15571 var startNode = editor.selection.getStart(); 15572 if (startNode !== node) { 15573 if (matchParents(editor, startNode, name, vars, similar)) { 15574 return true; 15575 } 15576 } 15577 return false; 15578 }; 15579 var matchAll = function (editor, names, vars) { 15580 var matchedFormatNames = []; 15581 var checkedMap = {}; 15582 var startElement = editor.selection.getStart(); 15583 editor.dom.getParent(startElement, function (node) { 15584 for (var i = 0; i < names.length; i++) { 15585 var name_1 = names[i]; 15586 if (!checkedMap[name_1] && matchNode(editor, node, name_1, vars)) { 15587 checkedMap[name_1] = true; 15588 matchedFormatNames.push(name_1); 15589 } 15590 } 15591 }, editor.dom.getRoot()); 15592 return matchedFormatNames; 15593 }; 15594 var closest = function (editor, names) { 15595 var isRoot = function (elm) { 15596 return eq(elm, SugarElement.fromDom(editor.getBody())); 15597 }; 15598 var match = function (elm, name) { 15599 return matchNode(editor, elm.dom, name) ? Optional.some(name) : Optional.none(); 15600 }; 15601 return Optional.from(editor.selection.getStart(true)).bind(function (rawElm) { 15602 return closest$1(SugarElement.fromDom(rawElm), function (elm) { 15603 return findMap(names, function (name) { 15604 return match(elm, name); 15605 }); 15606 }, isRoot); 15607 }).getOrNull(); 15608 }; 15609 var canApply = function (editor, name) { 15610 var formatList = editor.formatter.get(name); 15611 var dom = editor.dom; 15612 if (formatList) { 15613 var startNode = editor.selection.getStart(); 15614 var parents = getParents$2(dom, startNode); 15615 for (var x = formatList.length - 1; x >= 0; x--) { 15616 var format = formatList[x]; 15617 if (!isSelectorFormat(format) || isNonNullable(format.defaultBlock)) { 15618 return true; 15619 } 15620 for (var i = parents.length - 1; i >= 0; i--) { 15621 if (dom.is(parents[i], format.selector)) { 15622 return true; 15623 } 15624 } 15625 } 15626 } 15627 return false; 15628 }; 15629 var matchAllOnNode = function (editor, node, formatNames) { 15630 return foldl(formatNames, function (acc, name) { 15631 var matchSimilar = isVariableFormatName(editor, name); 15632 if (editor.formatter.matchNode(node, name, {}, matchSimilar)) { 15633 return acc.concat([name]); 15634 } else { 15635 return acc; 15636 } 15637 }, []); 15638 }; 15639 15640 var ZWSP = ZWSP$1, CARET_ID = '_mce_caret'; 15641 var importNode = function (ownerDocument, node) { 15642 return ownerDocument.importNode(node, true); 15643 }; 15644 var getEmptyCaretContainers = function (node) { 15645 var nodes = []; 15646 while (node) { 15647 if (node.nodeType === 3 && node.nodeValue !== ZWSP || node.childNodes.length > 1) { 15648 return []; 15649 } 15650 if (node.nodeType === 1) { 15651 nodes.push(node); 15652 } 15653 node = node.firstChild; 15654 } 15655 return nodes; 15656 }; 15657 var isCaretContainerEmpty = function (node) { 15658 return getEmptyCaretContainers(node).length > 0; 15659 }; 15660 var findFirstTextNode = function (node) { 15661 if (node) { 15662 var walker = new DomTreeWalker(node, node); 15663 for (node = walker.current(); node; node = walker.next()) { 15664 if (isText$7(node)) { 15665 return node; 15666 } 15667 } 15668 } 15669 return null; 15670 }; 15671 var createCaretContainer = function (fill) { 15672 var caretContainer = SugarElement.fromTag('span'); 15673 setAll$1(caretContainer, { 15674 'id': CARET_ID, 15675 'data-mce-bogus': '1', 15676 'data-mce-type': 'format-caret' 15677 }); 15678 if (fill) { 15679 append$1(caretContainer, SugarElement.fromText(ZWSP)); 15680 } 15681 return caretContainer; 15682 }; 15683 var trimZwspFromCaretContainer = function (caretContainerNode) { 15684 var textNode = findFirstTextNode(caretContainerNode); 15685 if (textNode && textNode.nodeValue.charAt(0) === ZWSP) { 15686 textNode.deleteData(0, 1); 15687 } 15688 return textNode; 15689 }; 15690 var removeCaretContainerNode = function (editor, node, moveCaret) { 15691 if (moveCaret === void 0) { 15692 moveCaret = true; 15693 } 15694 var dom = editor.dom, selection = editor.selection; 15695 if (isCaretContainerEmpty(node)) { 15696 deleteElement$2(editor, false, SugarElement.fromDom(node), moveCaret); 15697 } else { 15698 var rng = selection.getRng(); 15699 var block = dom.getParent(node, dom.isBlock); 15700 var startContainer = rng.startContainer; 15701 var startOffset = rng.startOffset; 15702 var endContainer = rng.endContainer; 15703 var endOffset = rng.endOffset; 15704 var textNode = trimZwspFromCaretContainer(node); 15705 dom.remove(node, true); 15706 if (startContainer === textNode && startOffset > 0) { 15707 rng.setStart(textNode, startOffset - 1); 15708 } 15709 if (endContainer === textNode && endOffset > 0) { 15710 rng.setEnd(textNode, endOffset - 1); 15711 } 15712 if (block && dom.isEmpty(block)) { 15713 fillWithPaddingBr(SugarElement.fromDom(block)); 15714 } 15715 selection.setRng(rng); 15716 } 15717 }; 15718 var removeCaretContainer = function (editor, node, moveCaret) { 15719 if (moveCaret === void 0) { 15720 moveCaret = true; 15721 } 15722 var dom = editor.dom, selection = editor.selection; 15723 if (!node) { 15724 node = getParentCaretContainer(editor.getBody(), selection.getStart()); 15725 if (!node) { 15726 while (node = dom.get(CARET_ID)) { 15727 removeCaretContainerNode(editor, node, false); 15728 } 15729 } 15730 } else { 15731 removeCaretContainerNode(editor, node, moveCaret); 15732 } 15733 }; 15734 var insertCaretContainerNode = function (editor, caretContainer, formatNode) { 15735 var dom = editor.dom, block = dom.getParent(formatNode, curry(isTextBlock$1, editor)); 15736 if (block && dom.isEmpty(block)) { 15737 formatNode.parentNode.replaceChild(caretContainer, formatNode); 15738 } else { 15739 removeTrailingBr(SugarElement.fromDom(formatNode)); 15740 if (dom.isEmpty(formatNode)) { 15741 formatNode.parentNode.replaceChild(caretContainer, formatNode); 15742 } else { 15743 dom.insertAfter(caretContainer, formatNode); 15744 } 15745 } 15746 }; 15747 var appendNode = function (parentNode, node) { 15748 parentNode.appendChild(node); 15749 return node; 15750 }; 15751 var insertFormatNodesIntoCaretContainer = function (formatNodes, caretContainer) { 15752 var innerMostFormatNode = foldr(formatNodes, function (parentNode, formatNode) { 15753 return appendNode(parentNode, formatNode.cloneNode(false)); 15754 }, caretContainer); 15755 return appendNode(innerMostFormatNode, innerMostFormatNode.ownerDocument.createTextNode(ZWSP)); 15756 }; 15757 var cleanFormatNode = function (editor, caretContainer, formatNode, name, vars, similar) { 15758 var formatter = editor.formatter; 15759 var dom = editor.dom; 15760 var validFormats = filter$4(keys(formatter.get()), function (formatName) { 15761 return formatName !== name && !contains$2(formatName, 'removeformat'); 15762 }); 15763 var matchedFormats = matchAllOnNode(editor, formatNode, validFormats); 15764 var uniqueFormats = filter$4(matchedFormats, function (fmtName) { 15765 return !areSimilarFormats(editor, fmtName, name); 15766 }); 15767 if (uniqueFormats.length > 0) { 15768 var clonedFormatNode = formatNode.cloneNode(false); 15769 dom.add(caretContainer, clonedFormatNode); 15770 formatter.remove(name, vars, clonedFormatNode, similar); 15771 dom.remove(clonedFormatNode); 15772 return Optional.some(clonedFormatNode); 15773 } else { 15774 return Optional.none(); 15775 } 15776 }; 15777 var applyCaretFormat = function (editor, name, vars) { 15778 var caretContainer, textNode; 15779 var selection = editor.selection; 15780 var selectionRng = selection.getRng(); 15781 var offset = selectionRng.startOffset; 15782 var container = selectionRng.startContainer; 15783 var text = container.nodeValue; 15784 caretContainer = getParentCaretContainer(editor.getBody(), selection.getStart()); 15785 if (caretContainer) { 15786 textNode = findFirstTextNode(caretContainer); 15787 } 15788 var wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/; 15789 if (text && offset > 0 && offset < text.length && wordcharRegex.test(text.charAt(offset)) && wordcharRegex.test(text.charAt(offset - 1))) { 15790 var bookmark = selection.getBookmark(); 15791 selectionRng.collapse(true); 15792 var rng = expandRng(editor, selectionRng, editor.formatter.get(name)); 15793 rng = split(rng); 15794 editor.formatter.apply(name, vars, rng); 15795 selection.moveToBookmark(bookmark); 15796 } else { 15797 if (!caretContainer || textNode.nodeValue !== ZWSP) { 15798 caretContainer = importNode(editor.getDoc(), createCaretContainer(true).dom); 15799 textNode = caretContainer.firstChild; 15800 selectionRng.insertNode(caretContainer); 15801 offset = 1; 15802 editor.formatter.apply(name, vars, caretContainer); 15803 } else { 15804 editor.formatter.apply(name, vars, caretContainer); 15805 } 15806 selection.setCursorLocation(textNode, offset); 15807 } 15808 }; 15809 var removeCaretFormat = function (editor, name, vars, similar) { 15810 var dom = editor.dom; 15811 var selection = editor.selection; 15812 var hasContentAfter, node, formatNode; 15813 var parents = []; 15814 var rng = selection.getRng(); 15815 var container = rng.startContainer; 15816 var offset = rng.startOffset; 15817 node = container; 15818 if (container.nodeType === 3) { 15819 if (offset !== container.nodeValue.length) { 15820 hasContentAfter = true; 15821 } 15822 node = node.parentNode; 15823 } 15824 while (node) { 15825 if (matchNode(editor, node, name, vars, similar)) { 15826 formatNode = node; 15827 break; 15828 } 15829 if (node.nextSibling) { 15830 hasContentAfter = true; 15831 } 15832 parents.push(node); 15833 node = node.parentNode; 15834 } 15835 if (!formatNode) { 15836 return; 15837 } 15838 if (hasContentAfter) { 15839 var bookmark = selection.getBookmark(); 15840 rng.collapse(true); 15841 var expandedRng = expandRng(editor, rng, editor.formatter.get(name), true); 15842 expandedRng = split(expandedRng); 15843 editor.formatter.remove(name, vars, expandedRng, similar); 15844 selection.moveToBookmark(bookmark); 15845 } else { 15846 var caretContainer = getParentCaretContainer(editor.getBody(), formatNode); 15847 var newCaretContainer = createCaretContainer(false).dom; 15848 insertCaretContainerNode(editor, newCaretContainer, caretContainer !== null ? caretContainer : formatNode); 15849 var cleanedFormatNode = cleanFormatNode(editor, newCaretContainer, formatNode, name, vars, similar); 15850 var caretTextNode = insertFormatNodesIntoCaretContainer(parents.concat(cleanedFormatNode.toArray()), newCaretContainer); 15851 removeCaretContainerNode(editor, caretContainer, false); 15852 selection.setCursorLocation(caretTextNode, 1); 15853 if (dom.isEmpty(formatNode)) { 15854 dom.remove(formatNode); 15855 } 15856 } 15857 }; 15858 var disableCaretContainer = function (editor, keyCode) { 15859 var selection = editor.selection, body = editor.getBody(); 15860 removeCaretContainer(editor, null, false); 15861 if ((keyCode === 8 || keyCode === 46) && selection.isCollapsed() && selection.getStart().innerHTML === ZWSP) { 15862 removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart())); 15863 } 15864 if (keyCode === 37 || keyCode === 39) { 15865 removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart())); 15866 } 15867 }; 15868 var setup$k = function (editor) { 15869 editor.on('mouseup keydown', function (e) { 15870 disableCaretContainer(editor, e.keyCode); 15871 }); 15872 }; 15873 var replaceWithCaretFormat = function (targetNode, formatNodes) { 15874 var caretContainer = createCaretContainer(false); 15875 var innerMost = insertFormatNodesIntoCaretContainer(formatNodes, caretContainer.dom); 15876 before$4(SugarElement.fromDom(targetNode), caretContainer); 15877 remove$7(SugarElement.fromDom(targetNode)); 15878 return CaretPosition(innerMost, 0); 15879 }; 15880 var isFormatElement = function (editor, element) { 15881 var inlineElements = editor.schema.getTextInlineElements(); 15882 return has$2(inlineElements, name(element)) && !isCaretNode(element.dom) && !isBogus$2(element.dom); 15883 }; 15884 var isEmptyCaretFormatElement = function (element) { 15885 return isCaretNode(element.dom) && isCaretContainerEmpty(element.dom); 15886 }; 15887 15888 var postProcessHooks = {}; 15889 var filter = filter$2; 15890 var each$b = each$i; 15891 var addPostProcessHook = function (name, hook) { 15892 var hooks = postProcessHooks[name]; 15893 if (!hooks) { 15894 postProcessHooks[name] = []; 15895 } 15896 postProcessHooks[name].push(hook); 15897 }; 15898 var postProcess$1 = function (name, editor) { 15899 each$b(postProcessHooks[name], function (hook) { 15900 hook(editor); 15901 }); 15902 }; 15903 addPostProcessHook('pre', function (editor) { 15904 var rng = editor.selection.getRng(); 15905 var blocks; 15906 var hasPreSibling = function (pre) { 15907 return isPre(pre.previousSibling) && indexOf$1(blocks, pre.previousSibling) !== -1; 15908 }; 15909 var joinPre = function (pre1, pre2) { 15910 DomQuery(pre2).remove(); 15911 DomQuery(pre1).append('<br><br>').append(pre2.childNodes); 15912 }; 15913 var isPre = matchNodeNames(['pre']); 15914 if (!rng.collapsed) { 15915 blocks = editor.selection.getSelectedBlocks(); 15916 each$b(filter(filter(blocks, isPre), hasPreSibling), function (pre) { 15917 joinPre(pre.previousSibling, pre); 15918 }); 15919 } 15920 }); 15921 15922 var each$a = Tools.each; 15923 var isElementNode$1 = function (node) { 15924 return isElement$5(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$2(node); 15925 }; 15926 var findElementSibling = function (node, siblingName) { 15927 for (var sibling = node; sibling; sibling = sibling[siblingName]) { 15928 if (isText$7(sibling) && isNotEmpty(sibling.data)) { 15929 return node; 15930 } 15931 if (isElement$5(sibling) && !isBookmarkNode$1(sibling)) { 15932 return sibling; 15933 } 15934 } 15935 return node; 15936 }; 15937 var mergeSiblingsNodes = function (dom, prev, next) { 15938 var elementUtils = ElementUtils(dom); 15939 if (prev && next) { 15940 prev = findElementSibling(prev, 'previousSibling'); 15941 next = findElementSibling(next, 'nextSibling'); 15942 if (elementUtils.compare(prev, next)) { 15943 for (var sibling = prev.nextSibling; sibling && sibling !== next;) { 15944 var tmpSibling = sibling; 15945 sibling = sibling.nextSibling; 15946 prev.appendChild(tmpSibling); 15947 } 15948 dom.remove(next); 15949 Tools.each(Tools.grep(next.childNodes), function (node) { 15950 prev.appendChild(node); 15951 }); 15952 return prev; 15953 } 15954 } 15955 return next; 15956 }; 15957 var mergeSiblings = function (dom, format, vars, node) { 15958 if (node && format.merge_siblings !== false) { 15959 var newNode = mergeSiblingsNodes(dom, getNonWhiteSpaceSibling(node), node); 15960 mergeSiblingsNodes(dom, newNode, getNonWhiteSpaceSibling(newNode, true)); 15961 } 15962 }; 15963 var clearChildStyles = function (dom, format, node) { 15964 if (format.clear_child_styles) { 15965 var selector = format.links ? '*:not(a)' : '*'; 15966 each$a(dom.select(selector, node), function (node) { 15967 if (isElementNode$1(node)) { 15968 each$a(format.styles, function (value, name) { 15969 dom.setStyle(node, name, ''); 15970 }); 15971 } 15972 }); 15973 } 15974 }; 15975 var processChildElements = function (node, filter, process) { 15976 each$a(node.childNodes, function (node) { 15977 if (isElementNode$1(node)) { 15978 if (filter(node)) { 15979 process(node); 15980 } 15981 if (node.hasChildNodes()) { 15982 processChildElements(node, filter, process); 15983 } 15984 } 15985 }); 15986 }; 15987 var unwrapEmptySpan = function (dom, node) { 15988 if (node.nodeName === 'SPAN' && dom.getAttribs(node).length === 0) { 15989 dom.remove(node, true); 15990 } 15991 }; 15992 var hasStyle = function (dom, name) { 15993 return function (node) { 15994 return !!(node && getStyle(dom, node, name)); 15995 }; 15996 }; 15997 var applyStyle = function (dom, name, value) { 15998 return function (node) { 15999 dom.setStyle(node, name, value); 16000 if (node.getAttribute('style') === '') { 16001 node.removeAttribute('style'); 16002 } 16003 unwrapEmptySpan(dom, node); 16004 }; 16005 }; 16006 16007 var removeResult = Adt.generate([ 16008 { keep: [] }, 16009 { rename: ['name'] }, 16010 { removed: [] } 16011 ]); 16012 var MCE_ATTR_RE = /^(src|href|style)$/; 16013 var each$9 = Tools.each; 16014 var isEq$2 = isEq$5; 16015 var isTableCellOrRow = function (node) { 16016 return /^(TR|TH|TD)$/.test(node.nodeName); 16017 }; 16018 var isChildOfInlineParent = function (dom, node, parent) { 16019 return dom.isChildOf(node, parent) && node !== parent && !dom.isBlock(parent); 16020 }; 16021 var getContainer = function (ed, rng, start) { 16022 var container = rng[start ? 'startContainer' : 'endContainer']; 16023 var offset = rng[start ? 'startOffset' : 'endOffset']; 16024 if (isElement$5(container)) { 16025 var lastIdx = container.childNodes.length - 1; 16026 if (!start && offset) { 16027 offset--; 16028 } 16029 container = container.childNodes[offset > lastIdx ? lastIdx : offset]; 16030 } 16031 if (isText$7(container) && start && offset >= container.nodeValue.length) { 16032 container = new DomTreeWalker(container, ed.getBody()).next() || container; 16033 } 16034 if (isText$7(container) && !start && offset === 0) { 16035 container = new DomTreeWalker(container, ed.getBody()).prev() || container; 16036 } 16037 return container; 16038 }; 16039 var normalizeTableSelection = function (node, start) { 16040 var prop = start ? 'firstChild' : 'lastChild'; 16041 if (isTableCellOrRow(node) && node[prop]) { 16042 var childNode = node[prop]; 16043 if (node.nodeName === 'TR') { 16044 return childNode[prop] || childNode; 16045 } else { 16046 return childNode; 16047 } 16048 } 16049 return node; 16050 }; 16051 var wrap$1 = function (dom, node, name, attrs) { 16052 var wrapper = dom.create(name, attrs); 16053 node.parentNode.insertBefore(wrapper, node); 16054 wrapper.appendChild(node); 16055 return wrapper; 16056 }; 16057 var wrapWithSiblings = function (dom, node, next, name, attrs) { 16058 var start = SugarElement.fromDom(node); 16059 var wrapper = SugarElement.fromDom(dom.create(name, attrs)); 16060 var siblings = next ? nextSiblings(start) : prevSiblings(start); 16061 append(wrapper, siblings); 16062 if (next) { 16063 before$4(start, wrapper); 16064 prepend(wrapper, start); 16065 } else { 16066 after$3(start, wrapper); 16067 append$1(wrapper, start); 16068 } 16069 return wrapper.dom; 16070 }; 16071 var matchName = function (dom, node, format) { 16072 if (isInlineFormat(format) && isEq$2(node, format.inline)) { 16073 return true; 16074 } 16075 if (isBlockFormat(format) && isEq$2(node, format.block)) { 16076 return true; 16077 } 16078 if (isSelectorFormat(format)) { 16079 return isElement$5(node) && dom.is(node, format.selector); 16080 } 16081 }; 16082 var isColorFormatAndAnchor = function (node, format) { 16083 return format.links && node.nodeName === 'A'; 16084 }; 16085 var find = function (dom, node, next, inc) { 16086 var sibling = getNonWhiteSpaceSibling(node, next, inc); 16087 return isNullable(sibling) || sibling.nodeName === 'BR' || dom.isBlock(sibling); 16088 }; 16089 var removeNode = function (ed, node, format) { 16090 var parentNode = node.parentNode; 16091 var rootBlockElm; 16092 var dom = ed.dom, forcedRootBlock = getForcedRootBlock(ed); 16093 if (isBlockFormat(format)) { 16094 if (!forcedRootBlock) { 16095 if (dom.isBlock(node) && !dom.isBlock(parentNode)) { 16096 if (!find(dom, node, false) && !find(dom, node.firstChild, true, true)) { 16097 node.insertBefore(dom.create('br'), node.firstChild); 16098 } 16099 if (!find(dom, node, true) && !find(dom, node.lastChild, false, true)) { 16100 node.appendChild(dom.create('br')); 16101 } 16102 } 16103 } else { 16104 if (parentNode === dom.getRoot()) { 16105 if (!format.list_block || !isEq$2(node, format.list_block)) { 16106 each$k(from(node.childNodes), function (node) { 16107 if (isValid(ed, forcedRootBlock, node.nodeName.toLowerCase())) { 16108 if (!rootBlockElm) { 16109 rootBlockElm = wrap$1(dom, node, forcedRootBlock); 16110 dom.setAttribs(rootBlockElm, ed.settings.forced_root_block_attrs); 16111 } else { 16112 rootBlockElm.appendChild(node); 16113 } 16114 } else { 16115 rootBlockElm = null; 16116 } 16117 }); 16118 } 16119 } 16120 } 16121 } 16122 if (isMixedFormat(format) && !isEq$2(format.inline, node)) { 16123 return; 16124 } 16125 dom.remove(node, true); 16126 }; 16127 var removeFormatInternal = function (ed, format, vars, node, compareNode) { 16128 var stylesModified; 16129 var dom = ed.dom; 16130 if (!matchName(dom, node, format) && !isColorFormatAndAnchor(node, format)) { 16131 return removeResult.keep(); 16132 } 16133 var elm = node; 16134 if (isInlineFormat(format) && format.remove === 'all' && isArray$1(format.preserve_attributes)) { 16135 var attrsToPreserve = filter$4(dom.getAttribs(elm), function (attr) { 16136 return contains$3(format.preserve_attributes, attr.name.toLowerCase()); 16137 }); 16138 dom.removeAllAttribs(elm); 16139 each$k(attrsToPreserve, function (attr) { 16140 return dom.setAttrib(elm, attr.name, attr.value); 16141 }); 16142 if (attrsToPreserve.length > 0) { 16143 return removeResult.rename('span'); 16144 } 16145 } 16146 if (format.remove !== 'all') { 16147 each$9(format.styles, function (value, name) { 16148 value = normalizeStyleValue(dom, replaceVars(value, vars), name + ''); 16149 if (isNumber(name)) { 16150 name = value; 16151 compareNode = null; 16152 } 16153 if (format.remove_similar || (!compareNode || isEq$2(getStyle(dom, compareNode, name), value))) { 16154 dom.setStyle(elm, name, ''); 16155 } 16156 stylesModified = true; 16157 }); 16158 if (stylesModified && dom.getAttrib(elm, 'style') === '') { 16159 elm.removeAttribute('style'); 16160 elm.removeAttribute('data-mce-style'); 16161 } 16162 each$9(format.attributes, function (value, name) { 16163 var valueOut; 16164 value = replaceVars(value, vars); 16165 if (isNumber(name)) { 16166 name = value; 16167 compareNode = null; 16168 } 16169 if (format.remove_similar || (!compareNode || isEq$2(dom.getAttrib(compareNode, name), value))) { 16170 if (name === 'class') { 16171 value = dom.getAttrib(elm, name); 16172 if (value) { 16173 valueOut = ''; 16174 each$k(value.split(/\s+/), function (cls) { 16175 if (/mce\-\w+/.test(cls)) { 16176 valueOut += (valueOut ? ' ' : '') + cls; 16177 } 16178 }); 16179 if (valueOut) { 16180 dom.setAttrib(elm, name, valueOut); 16181 return; 16182 } 16183 } 16184 } 16185 if (MCE_ATTR_RE.test(name)) { 16186 elm.removeAttribute('data-mce-' + name); 16187 } 16188 if (name === 'style' && matchNodeNames(['li'])(elm) && dom.getStyle(elm, 'list-style-type') === 'none') { 16189 elm.removeAttribute(name); 16190 dom.setStyle(elm, 'list-style-type', 'none'); 16191 return; 16192 } 16193 if (name === 'class') { 16194 elm.removeAttribute('className'); 16195 } 16196 elm.removeAttribute(name); 16197 } 16198 }); 16199 each$9(format.classes, function (value) { 16200 value = replaceVars(value, vars); 16201 if (!compareNode || dom.hasClass(compareNode, value)) { 16202 dom.removeClass(elm, value); 16203 } 16204 }); 16205 var attrs = dom.getAttribs(elm); 16206 for (var i = 0; i < attrs.length; i++) { 16207 var attrName = attrs[i].nodeName; 16208 if (attrName.indexOf('_') !== 0 && attrName.indexOf('data-') !== 0) { 16209 return removeResult.keep(); 16210 } 16211 } 16212 } 16213 if (format.remove !== 'none') { 16214 removeNode(ed, elm, format); 16215 return removeResult.removed(); 16216 } 16217 return removeResult.keep(); 16218 }; 16219 var removeFormat$1 = function (ed, format, vars, node, compareNode) { 16220 return removeFormatInternal(ed, format, vars, node, compareNode).fold(never, function (newName) { 16221 ed.dom.rename(node, newName); 16222 return true; 16223 }, always); 16224 }; 16225 var findFormatRoot = function (editor, container, name, vars, similar) { 16226 var formatRoot; 16227 each$k(getParents$2(editor.dom, container.parentNode).reverse(), function (parent) { 16228 if (!formatRoot && parent.id !== '_start' && parent.id !== '_end') { 16229 var format = matchNode(editor, parent, name, vars, similar); 16230 if (format && format.split !== false) { 16231 formatRoot = parent; 16232 } 16233 } 16234 }); 16235 return formatRoot; 16236 }; 16237 var removeFormatFromClone = function (editor, format, vars, clone) { 16238 return removeFormatInternal(editor, format, vars, clone, clone).fold(constant(clone), function (newName) { 16239 var fragment = editor.dom.createFragment(); 16240 fragment.appendChild(clone); 16241 return editor.dom.rename(clone, newName); 16242 }, constant(null)); 16243 }; 16244 var wrapAndSplit = function (editor, formatList, formatRoot, container, target, split, format, vars) { 16245 var clone, lastClone, firstClone; 16246 var dom = editor.dom; 16247 if (formatRoot) { 16248 var formatRootParent = formatRoot.parentNode; 16249 for (var parent_1 = container.parentNode; parent_1 && parent_1 !== formatRootParent; parent_1 = parent_1.parentNode) { 16250 clone = dom.clone(parent_1, false); 16251 for (var i = 0; i < formatList.length; i++) { 16252 clone = removeFormatFromClone(editor, formatList[i], vars, clone); 16253 if (clone === null) { 16254 break; 16255 } 16256 } 16257 if (clone) { 16258 if (lastClone) { 16259 clone.appendChild(lastClone); 16260 } 16261 if (!firstClone) { 16262 firstClone = clone; 16263 } 16264 lastClone = clone; 16265 } 16266 } 16267 if (split && (!format.mixed || !dom.isBlock(formatRoot))) { 16268 container = dom.split(formatRoot, container); 16269 } 16270 if (lastClone) { 16271 target.parentNode.insertBefore(lastClone, target); 16272 firstClone.appendChild(target); 16273 if (isInlineFormat(format)) { 16274 mergeSiblings(dom, format, vars, lastClone); 16275 } 16276 } 16277 } 16278 return container; 16279 }; 16280 var remove$1 = function (ed, name, vars, node, similar) { 16281 var formatList = ed.formatter.get(name); 16282 var format = formatList[0]; 16283 var contentEditable = true; 16284 var dom = ed.dom; 16285 var selection = ed.selection; 16286 var splitToFormatRoot = function (container) { 16287 var formatRoot = findFormatRoot(ed, container, name, vars, similar); 16288 return wrapAndSplit(ed, formatList, formatRoot, container, container, true, format, vars); 16289 }; 16290 var isRemoveBookmarkNode = function (node) { 16291 return isBookmarkNode$1(node) && isElement$5(node) && (node.id === '_start' || node.id === '_end'); 16292 }; 16293 var removeNodeFormat = function (node) { 16294 return exists(formatList, function (fmt) { 16295 return removeFormat$1(ed, fmt, vars, node, node); 16296 }); 16297 }; 16298 var process = function (node) { 16299 var lastContentEditable = true; 16300 var hasContentEditableState = false; 16301 if (isElement$5(node) && dom.getContentEditable(node)) { 16302 lastContentEditable = contentEditable; 16303 contentEditable = dom.getContentEditable(node) === 'true'; 16304 hasContentEditableState = true; 16305 } 16306 var children = from(node.childNodes); 16307 if (contentEditable && !hasContentEditableState) { 16308 var removed = removeNodeFormat(node); 16309 var currentNodeMatches = removed || exists(formatList, function (f) { 16310 return matchName$1(dom, node, f); 16311 }); 16312 var parentNode = node.parentNode; 16313 if (!currentNodeMatches && isNonNullable(parentNode) && shouldExpandToSelector(format)) { 16314 removeNodeFormat(parentNode); 16315 } 16316 } 16317 if (format.deep) { 16318 if (children.length) { 16319 for (var i = 0; i < children.length; i++) { 16320 process(children[i]); 16321 } 16322 if (hasContentEditableState) { 16323 contentEditable = lastContentEditable; 16324 } 16325 } 16326 } 16327 var textDecorations = [ 16328 'underline', 16329 'line-through', 16330 'overline' 16331 ]; 16332 each$k(textDecorations, function (decoration) { 16333 if (isElement$5(node) && ed.dom.getStyle(node, 'text-decoration') === decoration && node.parentNode && getTextDecoration(dom, node.parentNode) === decoration) { 16334 removeFormat$1(ed, { 16335 deep: false, 16336 exact: true, 16337 inline: 'span', 16338 styles: { textDecoration: decoration } 16339 }, null, node); 16340 } 16341 }); 16342 }; 16343 var unwrap = function (start) { 16344 var node = dom.get(start ? '_start' : '_end'); 16345 var out = node[start ? 'firstChild' : 'lastChild']; 16346 if (isRemoveBookmarkNode(out)) { 16347 out = out[start ? 'firstChild' : 'lastChild']; 16348 } 16349 if (isText$7(out) && out.data.length === 0) { 16350 out = start ? node.previousSibling || node.nextSibling : node.nextSibling || node.previousSibling; 16351 } 16352 dom.remove(node, true); 16353 return out; 16354 }; 16355 var removeRngStyle = function (rng) { 16356 var startContainer, endContainer; 16357 var expandedRng = expandRng(ed, rng, formatList, rng.collapsed); 16358 if (format.split) { 16359 expandedRng = split(expandedRng); 16360 startContainer = getContainer(ed, expandedRng, true); 16361 endContainer = getContainer(ed, expandedRng); 16362 if (startContainer !== endContainer) { 16363 startContainer = normalizeTableSelection(startContainer, true); 16364 endContainer = normalizeTableSelection(endContainer, false); 16365 if (isChildOfInlineParent(dom, startContainer, endContainer)) { 16366 var marker = Optional.from(startContainer.firstChild).getOr(startContainer); 16367 splitToFormatRoot(wrapWithSiblings(dom, marker, true, 'span', { 16368 'id': '_start', 16369 'data-mce-type': 'bookmark' 16370 })); 16371 unwrap(true); 16372 return; 16373 } 16374 if (isChildOfInlineParent(dom, endContainer, startContainer)) { 16375 var marker = Optional.from(endContainer.lastChild).getOr(endContainer); 16376 splitToFormatRoot(wrapWithSiblings(dom, marker, false, 'span', { 16377 'id': '_end', 16378 'data-mce-type': 'bookmark' 16379 })); 16380 unwrap(false); 16381 return; 16382 } 16383 startContainer = wrap$1(dom, startContainer, 'span', { 16384 'id': '_start', 16385 'data-mce-type': 'bookmark' 16386 }); 16387 endContainer = wrap$1(dom, endContainer, 'span', { 16388 'id': '_end', 16389 'data-mce-type': 'bookmark' 16390 }); 16391 var newRng = dom.createRng(); 16392 newRng.setStartAfter(startContainer); 16393 newRng.setEndBefore(endContainer); 16394 walk$2(dom, newRng, function (nodes) { 16395 each$k(nodes, function (n) { 16396 if (!isBookmarkNode$1(n) && !isBookmarkNode$1(n.parentNode)) { 16397 splitToFormatRoot(n); 16398 } 16399 }); 16400 }); 16401 splitToFormatRoot(startContainer); 16402 splitToFormatRoot(endContainer); 16403 startContainer = unwrap(true); 16404 endContainer = unwrap(); 16405 } else { 16406 startContainer = endContainer = splitToFormatRoot(startContainer); 16407 } 16408 expandedRng.startContainer = startContainer.parentNode ? startContainer.parentNode : startContainer; 16409 expandedRng.startOffset = dom.nodeIndex(startContainer); 16410 expandedRng.endContainer = endContainer.parentNode ? endContainer.parentNode : endContainer; 16411 expandedRng.endOffset = dom.nodeIndex(endContainer) + 1; 16412 } 16413 walk$2(dom, expandedRng, function (nodes) { 16414 each$k(nodes, process); 16415 }); 16416 }; 16417 if (node) { 16418 if (isNode(node)) { 16419 var rng = dom.createRng(); 16420 rng.setStartBefore(node); 16421 rng.setEndAfter(node); 16422 removeRngStyle(rng); 16423 } else { 16424 removeRngStyle(node); 16425 } 16426 fireFormatRemove(ed, name, node, vars); 16427 return; 16428 } 16429 if (dom.getContentEditable(selection.getNode()) === 'false') { 16430 node = selection.getNode(); 16431 for (var i = 0; i < formatList.length; i++) { 16432 if (formatList[i].ceFalseOverride) { 16433 if (removeFormat$1(ed, formatList[i], vars, node, node)) { 16434 break; 16435 } 16436 } 16437 } 16438 fireFormatRemove(ed, name, node, vars); 16439 return; 16440 } 16441 if (!selection.isCollapsed() || !isInlineFormat(format) || getCellsFromEditor(ed).length) { 16442 preserve(selection, true, function () { 16443 runOnRanges(ed, removeRngStyle); 16444 }); 16445 if (isInlineFormat(format) && match$2(ed, name, vars, selection.getStart())) { 16446 moveStart(dom, selection, selection.getRng()); 16447 } 16448 ed.nodeChanged(); 16449 } else { 16450 removeCaretFormat(ed, name, vars, similar); 16451 } 16452 fireFormatRemove(ed, name, node, vars); 16453 }; 16454 16455 var each$8 = Tools.each; 16456 var mergeTextDecorationsAndColor = function (dom, format, vars, node) { 16457 var processTextDecorationsAndColor = function (n) { 16458 if (n.nodeType === 1 && n.parentNode && n.parentNode.nodeType === 1) { 16459 var textDecoration = getTextDecoration(dom, n.parentNode); 16460 if (dom.getStyle(n, 'color') && textDecoration) { 16461 dom.setStyle(n, 'text-decoration', textDecoration); 16462 } else if (dom.getStyle(n, 'text-decoration') === textDecoration) { 16463 dom.setStyle(n, 'text-decoration', null); 16464 } 16465 } 16466 }; 16467 if (format.styles && (format.styles.color || format.styles.textDecoration)) { 16468 Tools.walk(node, processTextDecorationsAndColor, 'childNodes'); 16469 processTextDecorationsAndColor(node); 16470 } 16471 }; 16472 var mergeBackgroundColorAndFontSize = function (dom, format, vars, node) { 16473 if (format.styles && format.styles.backgroundColor) { 16474 processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'backgroundColor', replaceVars(format.styles.backgroundColor, vars))); 16475 } 16476 }; 16477 var mergeSubSup = function (dom, format, vars, node) { 16478 if (isInlineFormat(format) && (format.inline === 'sub' || format.inline === 'sup')) { 16479 processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'fontSize', '')); 16480 dom.remove(dom.select(format.inline === 'sup' ? 'sub' : 'sup', node), true); 16481 } 16482 }; 16483 var mergeWithChildren = function (editor, formatList, vars, node) { 16484 each$8(formatList, function (format) { 16485 if (isInlineFormat(format)) { 16486 each$8(editor.dom.select(format.inline, node), function (child) { 16487 if (!isElementNode$1(child)) { 16488 return; 16489 } 16490 removeFormat$1(editor, format, vars, child, format.exact ? child : null); 16491 }); 16492 } 16493 clearChildStyles(editor.dom, format, node); 16494 }); 16495 }; 16496 var mergeWithParents = function (editor, format, name, vars, node) { 16497 if (matchNode(editor, node.parentNode, name, vars)) { 16498 if (removeFormat$1(editor, format, vars, node)) { 16499 return; 16500 } 16501 } 16502 if (format.merge_with_parents) { 16503 editor.dom.getParent(node.parentNode, function (parent) { 16504 if (matchNode(editor, parent, name, vars)) { 16505 removeFormat$1(editor, format, vars, node); 16506 return true; 16507 } 16508 }); 16509 } 16510 }; 16511 16512 var each$7 = Tools.each; 16513 var isElementNode = function (node) { 16514 return isElement$5(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$2(node); 16515 }; 16516 var canFormatBR = function (editor, format, node, parentName) { 16517 if (canFormatEmptyLines(editor) && isInlineFormat(format)) { 16518 var validBRParentElements = getTextRootBlockElements(editor.schema); 16519 var hasCaretNodeSibling = sibling(SugarElement.fromDom(node), function (sibling) { 16520 return isCaretNode(sibling.dom); 16521 }); 16522 return hasNonNullableKey(validBRParentElements, parentName) && isEmpty$2(SugarElement.fromDom(node.parentNode), false) && !hasCaretNodeSibling; 16523 } else { 16524 return false; 16525 } 16526 }; 16527 var applyFormat$1 = function (ed, name, vars, node) { 16528 var formatList = ed.formatter.get(name); 16529 var format = formatList[0]; 16530 var isCollapsed = !node && ed.selection.isCollapsed(); 16531 var dom = ed.dom; 16532 var selection = ed.selection; 16533 var setElementFormat = function (elm, fmt) { 16534 if (fmt === void 0) { 16535 fmt = format; 16536 } 16537 if (isFunction(fmt.onformat)) { 16538 fmt.onformat(elm, fmt, vars, node); 16539 } 16540 each$7(fmt.styles, function (value, name) { 16541 dom.setStyle(elm, name, replaceVars(value, vars)); 16542 }); 16543 if (fmt.styles) { 16544 var styleVal = dom.getAttrib(elm, 'style'); 16545 if (styleVal) { 16546 dom.setAttrib(elm, 'data-mce-style', styleVal); 16547 } 16548 } 16549 each$7(fmt.attributes, function (value, name) { 16550 dom.setAttrib(elm, name, replaceVars(value, vars)); 16551 }); 16552 each$7(fmt.classes, function (value) { 16553 value = replaceVars(value, vars); 16554 if (!dom.hasClass(elm, value)) { 16555 dom.addClass(elm, value); 16556 } 16557 }); 16558 }; 16559 var applyNodeStyle = function (formatList, node) { 16560 var found = false; 16561 each$7(formatList, function (format) { 16562 if (!isSelectorFormat(format)) { 16563 return false; 16564 } 16565 if (isNonNullable(format.collapsed) && format.collapsed !== isCollapsed) { 16566 return; 16567 } 16568 if (dom.is(node, format.selector) && !isCaretNode(node)) { 16569 setElementFormat(node, format); 16570 found = true; 16571 return false; 16572 } 16573 }); 16574 return found; 16575 }; 16576 var createWrapElement = function (wrapName) { 16577 if (isString$1(wrapName)) { 16578 var wrapElm = dom.create(wrapName); 16579 setElementFormat(wrapElm); 16580 return wrapElm; 16581 } else { 16582 return null; 16583 } 16584 }; 16585 var applyRngStyle = function (dom, rng, nodeSpecific) { 16586 var newWrappers = []; 16587 var contentEditable = true; 16588 var wrapName = format.inline || format.block; 16589 var wrapElm = createWrapElement(wrapName); 16590 walk$2(dom, rng, function (nodes) { 16591 var currentWrapElm; 16592 var process = function (node) { 16593 var hasContentEditableState = false; 16594 var lastContentEditable = contentEditable; 16595 var nodeName = node.nodeName.toLowerCase(); 16596 var parentNode = node.parentNode; 16597 var parentName = parentNode.nodeName.toLowerCase(); 16598 if (isElement$5(node) && dom.getContentEditable(node)) { 16599 lastContentEditable = contentEditable; 16600 contentEditable = dom.getContentEditable(node) === 'true'; 16601 hasContentEditableState = true; 16602 } 16603 if (isBr$5(node) && !canFormatBR(ed, format, node, parentName)) { 16604 currentWrapElm = null; 16605 if (isBlockFormat(format)) { 16606 dom.remove(node); 16607 } 16608 return; 16609 } 16610 if (isBlockFormat(format) && format.wrapper && matchNode(ed, node, name, vars)) { 16611 currentWrapElm = null; 16612 return; 16613 } 16614 if (contentEditable && !hasContentEditableState && isBlockFormat(format) && !format.wrapper && isTextBlock$1(ed, nodeName) && isValid(ed, parentName, wrapName)) { 16615 var elm = dom.rename(node, wrapName); 16616 setElementFormat(elm); 16617 newWrappers.push(elm); 16618 currentWrapElm = null; 16619 return; 16620 } 16621 if (isSelectorFormat(format)) { 16622 var found = applyNodeStyle(formatList, node); 16623 if (!found && isNonNullable(parentNode) && shouldExpandToSelector(format)) { 16624 found = applyNodeStyle(formatList, parentNode); 16625 } 16626 if (!isInlineFormat(format) || found) { 16627 currentWrapElm = null; 16628 return; 16629 } 16630 } 16631 if (contentEditable && !hasContentEditableState && isValid(ed, wrapName, nodeName) && isValid(ed, parentName, wrapName) && !(!nodeSpecific && isText$7(node) && isZwsp(node.data)) && !isCaretNode(node) && (!isInlineFormat(format) || !dom.isBlock(node))) { 16632 if (!currentWrapElm) { 16633 currentWrapElm = dom.clone(wrapElm, false); 16634 node.parentNode.insertBefore(currentWrapElm, node); 16635 newWrappers.push(currentWrapElm); 16636 } 16637 currentWrapElm.appendChild(node); 16638 } else { 16639 currentWrapElm = null; 16640 each$k(from(node.childNodes), process); 16641 if (hasContentEditableState) { 16642 contentEditable = lastContentEditable; 16643 } 16644 currentWrapElm = null; 16645 } 16646 }; 16647 each$k(nodes, process); 16648 }); 16649 if (format.links === true) { 16650 each$k(newWrappers, function (node) { 16651 var process = function (node) { 16652 if (node.nodeName === 'A') { 16653 setElementFormat(node, format); 16654 } 16655 each$k(from(node.childNodes), process); 16656 }; 16657 process(node); 16658 }); 16659 } 16660 each$k(newWrappers, function (node) { 16661 var getChildCount = function (node) { 16662 var count = 0; 16663 each$k(node.childNodes, function (node) { 16664 if (!isEmptyTextNode$1(node) && !isBookmarkNode$1(node)) { 16665 count++; 16666 } 16667 }); 16668 return count; 16669 }; 16670 var mergeStyles = function (node) { 16671 var childElement = find$3(node.childNodes, isElementNode).filter(function (child) { 16672 return matchName$1(dom, child, format); 16673 }); 16674 return childElement.map(function (child) { 16675 var clone = dom.clone(child, false); 16676 setElementFormat(clone); 16677 dom.replace(clone, node, true); 16678 dom.remove(child, true); 16679 return clone; 16680 }).getOr(node); 16681 }; 16682 var childCount = getChildCount(node); 16683 if ((newWrappers.length > 1 || !dom.isBlock(node)) && childCount === 0) { 16684 dom.remove(node, true); 16685 return; 16686 } 16687 if (isInlineFormat(format) || isBlockFormat(format) && format.wrapper) { 16688 if (!format.exact && childCount === 1) { 16689 node = mergeStyles(node); 16690 } 16691 mergeWithChildren(ed, formatList, vars, node); 16692 mergeWithParents(ed, format, name, vars, node); 16693 mergeBackgroundColorAndFontSize(dom, format, vars, node); 16694 mergeTextDecorationsAndColor(dom, format, vars, node); 16695 mergeSubSup(dom, format, vars, node); 16696 mergeSiblings(dom, format, vars, node); 16697 } 16698 }); 16699 }; 16700 if (dom.getContentEditable(selection.getNode()) === 'false') { 16701 node = selection.getNode(); 16702 for (var i = 0, l = formatList.length; i < l; i++) { 16703 var formatItem = formatList[i]; 16704 if (formatItem.ceFalseOverride && isSelectorFormat(formatItem) && dom.is(node, formatItem.selector)) { 16705 setElementFormat(node, formatItem); 16706 break; 16707 } 16708 } 16709 fireFormatApply(ed, name, node, vars); 16710 return; 16711 } 16712 if (format) { 16713 if (node) { 16714 if (isNode(node)) { 16715 if (!applyNodeStyle(formatList, node)) { 16716 var rng = dom.createRng(); 16717 rng.setStartBefore(node); 16718 rng.setEndAfter(node); 16719 applyRngStyle(dom, expandRng(ed, rng, formatList), true); 16720 } 16721 } else { 16722 applyRngStyle(dom, node, true); 16723 } 16724 } else { 16725 if (!isCollapsed || !isInlineFormat(format) || getCellsFromEditor(ed).length) { 16726 var curSelNode = selection.getNode(); 16727 var firstFormat = formatList[0]; 16728 if (!ed.settings.forced_root_block && firstFormat.defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) { 16729 applyFormat$1(ed, firstFormat.defaultBlock); 16730 } 16731 selection.setRng(normalize(selection.getRng())); 16732 preserve(selection, true, function () { 16733 runOnRanges(ed, function (selectionRng, fake) { 16734 var expandedRng = fake ? selectionRng : expandRng(ed, selectionRng, formatList); 16735 applyRngStyle(dom, expandedRng, false); 16736 }); 16737 }); 16738 moveStart(dom, selection, selection.getRng()); 16739 ed.nodeChanged(); 16740 } else { 16741 applyCaretFormat(ed, name, vars); 16742 } 16743 } 16744 postProcess$1(name, ed); 16745 } 16746 fireFormatApply(ed, name, node, vars); 16747 }; 16748 16749 var hasVars = function (value) { 16750 return has$2(value, 'vars'); 16751 }; 16752 var setup$j = function (registeredFormatListeners, editor) { 16753 registeredFormatListeners.set({}); 16754 editor.on('NodeChange', function (e) { 16755 updateAndFireChangeCallbacks(editor, e.element, registeredFormatListeners.get()); 16756 }); 16757 editor.on('FormatApply FormatRemove', function (e) { 16758 var element = Optional.from(e.node).map(function (nodeOrRange) { 16759 return isNode(nodeOrRange) ? nodeOrRange : nodeOrRange.startContainer; 16760 }).bind(function (node) { 16761 return isElement$5(node) ? Optional.some(node) : Optional.from(node.parentElement); 16762 }).getOrThunk(function () { 16763 return fallbackElement(editor); 16764 }); 16765 updateAndFireChangeCallbacks(editor, element, registeredFormatListeners.get()); 16766 }); 16767 }; 16768 var fallbackElement = function (editor) { 16769 return editor.selection.getStart(); 16770 }; 16771 var matchingNode = function (editor, parents, format, similar, vars) { 16772 var isMatchingNode = function (node) { 16773 var matchingFormat = editor.formatter.matchNode(node, format, vars !== null && vars !== void 0 ? vars : {}, similar); 16774 return !isUndefined(matchingFormat); 16775 }; 16776 var isUnableToMatch = function (node) { 16777 if (matchesUnInheritedFormatSelector(editor, node, format)) { 16778 return true; 16779 } else { 16780 if (!similar) { 16781 return isNonNullable(editor.formatter.matchNode(node, format, vars, true)); 16782 } else { 16783 return false; 16784 } 16785 } 16786 }; 16787 return findUntil$1(parents, isMatchingNode, isUnableToMatch); 16788 }; 16789 var getParents = function (editor, elm) { 16790 var element = elm !== null && elm !== void 0 ? elm : fallbackElement(editor); 16791 return filter$4(getParents$2(editor.dom, element), function (node) { 16792 return isElement$5(node) && !isBogus$2(node); 16793 }); 16794 }; 16795 var updateAndFireChangeCallbacks = function (editor, elm, registeredCallbacks) { 16796 var parents = getParents(editor, elm); 16797 each$j(registeredCallbacks, function (data, format) { 16798 var runIfChanged = function (spec) { 16799 var match = matchingNode(editor, parents, format, spec.similar, hasVars(spec) ? spec.vars : undefined); 16800 var isSet = match.isSome(); 16801 if (spec.state.get() !== isSet) { 16802 spec.state.set(isSet); 16803 var node_1 = match.getOr(elm); 16804 if (hasVars(spec)) { 16805 spec.callback(isSet, { 16806 node: node_1, 16807 format: format, 16808 parents: parents 16809 }); 16810 } else { 16811 each$k(spec.callbacks, function (callback) { 16812 return callback(isSet, { 16813 node: node_1, 16814 format: format, 16815 parents: parents 16816 }); 16817 }); 16818 } 16819 } 16820 }; 16821 each$k([ 16822 data.withSimilar, 16823 data.withoutSimilar 16824 ], runIfChanged); 16825 each$k(data.withVars, runIfChanged); 16826 }); 16827 }; 16828 var addListeners = function (editor, registeredFormatListeners, formats, callback, similar, vars) { 16829 var formatChangeItems = registeredFormatListeners.get(); 16830 each$k(formats.split(','), function (format) { 16831 var group = get$9(formatChangeItems, format).getOrThunk(function () { 16832 var base = { 16833 withSimilar: { 16834 state: Cell(false), 16835 similar: true, 16836 callbacks: [] 16837 }, 16838 withoutSimilar: { 16839 state: Cell(false), 16840 similar: false, 16841 callbacks: [] 16842 }, 16843 withVars: [] 16844 }; 16845 formatChangeItems[format] = base; 16846 return base; 16847 }); 16848 var getCurrent = function () { 16849 var parents = getParents(editor); 16850 return matchingNode(editor, parents, format, similar, vars).isSome(); 16851 }; 16852 if (isUndefined(vars)) { 16853 var toAppendTo = similar ? group.withSimilar : group.withoutSimilar; 16854 toAppendTo.callbacks.push(callback); 16855 if (toAppendTo.callbacks.length === 1) { 16856 toAppendTo.state.set(getCurrent()); 16857 } 16858 } else { 16859 group.withVars.push({ 16860 state: Cell(getCurrent()), 16861 similar: similar, 16862 vars: vars, 16863 callback: callback 16864 }); 16865 } 16866 }); 16867 registeredFormatListeners.set(formatChangeItems); 16868 }; 16869 var removeListeners = function (registeredFormatListeners, formats, callback) { 16870 var formatChangeItems = registeredFormatListeners.get(); 16871 each$k(formats.split(','), function (format) { 16872 return get$9(formatChangeItems, format).each(function (group) { 16873 formatChangeItems[format] = { 16874 withSimilar: __assign(__assign({}, group.withSimilar), { 16875 callbacks: filter$4(group.withSimilar.callbacks, function (cb) { 16876 return cb !== callback; 16877 }) 16878 }), 16879 withoutSimilar: __assign(__assign({}, group.withoutSimilar), { 16880 callbacks: filter$4(group.withoutSimilar.callbacks, function (cb) { 16881 return cb !== callback; 16882 }) 16883 }), 16884 withVars: filter$4(group.withVars, function (item) { 16885 return item.callback !== callback; 16886 }) 16887 }; 16888 }); 16889 }); 16890 registeredFormatListeners.set(formatChangeItems); 16891 }; 16892 var formatChangedInternal = function (editor, registeredFormatListeners, formats, callback, similar, vars) { 16893 if (registeredFormatListeners.get() === null) { 16894 setup$j(registeredFormatListeners, editor); 16895 } 16896 addListeners(editor, registeredFormatListeners, formats, callback, similar, vars); 16897 return { 16898 unbind: function () { 16899 return removeListeners(registeredFormatListeners, formats, callback); 16900 } 16901 }; 16902 }; 16903 16904 var toggle = function (editor, name, vars, node) { 16905 var fmt = editor.formatter.get(name); 16906 if (match$2(editor, name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle)) { 16907 remove$1(editor, name, vars, node); 16908 } else { 16909 applyFormat$1(editor, name, vars, node); 16910 } 16911 }; 16912 16913 var fromElements = function (elements, scope) { 16914 var doc = scope || document; 16915 var fragment = doc.createDocumentFragment(); 16916 each$k(elements, function (element) { 16917 fragment.appendChild(element.dom); 16918 }); 16919 return SugarElement.fromDom(fragment); 16920 }; 16921 16922 var tableModel = function (element, width, rows) { 16923 return { 16924 element: element, 16925 width: width, 16926 rows: rows 16927 }; 16928 }; 16929 var tableRow = function (element, cells) { 16930 return { 16931 element: element, 16932 cells: cells 16933 }; 16934 }; 16935 var cellPosition = function (x, y) { 16936 return { 16937 x: x, 16938 y: y 16939 }; 16940 }; 16941 var getSpan = function (td, key) { 16942 var value = parseInt(get$6(td, key), 10); 16943 return isNaN(value) ? 1 : value; 16944 }; 16945 var fillout = function (table, x, y, tr, td) { 16946 var rowspan = getSpan(td, 'rowspan'); 16947 var colspan = getSpan(td, 'colspan'); 16948 var rows = table.rows; 16949 for (var y2 = y; y2 < y + rowspan; y2++) { 16950 if (!rows[y2]) { 16951 rows[y2] = tableRow(deep$1(tr), []); 16952 } 16953 for (var x2 = x; x2 < x + colspan; x2++) { 16954 var cells = rows[y2].cells; 16955 cells[x2] = y2 === y && x2 === x ? td : shallow(td); 16956 } 16957 } 16958 }; 16959 var cellExists = function (table, x, y) { 16960 var rows = table.rows; 16961 var cells = rows[y] ? rows[y].cells : []; 16962 return !!cells[x]; 16963 }; 16964 var skipCellsX = function (table, x, y) { 16965 while (cellExists(table, x, y)) { 16966 x++; 16967 } 16968 return x; 16969 }; 16970 var getWidth = function (rows) { 16971 return foldl(rows, function (acc, row) { 16972 return row.cells.length > acc ? row.cells.length : acc; 16973 }, 0); 16974 }; 16975 var findElementPos = function (table, element) { 16976 var rows = table.rows; 16977 for (var y = 0; y < rows.length; y++) { 16978 var cells = rows[y].cells; 16979 for (var x = 0; x < cells.length; x++) { 16980 if (eq(cells[x], element)) { 16981 return Optional.some(cellPosition(x, y)); 16982 } 16983 } 16984 } 16985 return Optional.none(); 16986 }; 16987 var extractRows = function (table, sx, sy, ex, ey) { 16988 var newRows = []; 16989 var rows = table.rows; 16990 for (var y = sy; y <= ey; y++) { 16991 var cells = rows[y].cells; 16992 var slice = sx < ex ? cells.slice(sx, ex + 1) : cells.slice(ex, sx + 1); 16993 newRows.push(tableRow(rows[y].element, slice)); 16994 } 16995 return newRows; 16996 }; 16997 var subTable = function (table, startPos, endPos) { 16998 var sx = startPos.x, sy = startPos.y; 16999 var ex = endPos.x, ey = endPos.y; 17000 var newRows = sy < ey ? extractRows(table, sx, sy, ex, ey) : extractRows(table, sx, ey, ex, sy); 17001 return tableModel(table.element, getWidth(newRows), newRows); 17002 }; 17003 var createDomTable = function (table, rows) { 17004 var tableElement = shallow(table.element); 17005 var tableBody = SugarElement.fromTag('tbody'); 17006 append(tableBody, rows); 17007 append$1(tableElement, tableBody); 17008 return tableElement; 17009 }; 17010 var modelRowsToDomRows = function (table) { 17011 return map$3(table.rows, function (row) { 17012 var cells = map$3(row.cells, function (cell) { 17013 var td = deep$1(cell); 17014 remove$6(td, 'colspan'); 17015 remove$6(td, 'rowspan'); 17016 return td; 17017 }); 17018 var tr = shallow(row.element); 17019 append(tr, cells); 17020 return tr; 17021 }); 17022 }; 17023 var fromDom = function (tableElm) { 17024 var table = tableModel(shallow(tableElm), 0, []); 17025 each$k(descendants(tableElm, 'tr'), function (tr, y) { 17026 each$k(descendants(tr, 'td,th'), function (td, x) { 17027 fillout(table, skipCellsX(table, x, y), y, tr, td); 17028 }); 17029 }); 17030 return tableModel(table.element, getWidth(table.rows), table.rows); 17031 }; 17032 var toDom = function (table) { 17033 return createDomTable(table, modelRowsToDomRows(table)); 17034 }; 17035 var subsection = function (table, startElement, endElement) { 17036 return findElementPos(table, startElement).bind(function (startPos) { 17037 return findElementPos(table, endElement).map(function (endPos) { 17038 return subTable(table, startPos, endPos); 17039 }); 17040 }); 17041 }; 17042 17043 var findParentListContainer = function (parents) { 17044 return find$3(parents, function (elm) { 17045 return name(elm) === 'ul' || name(elm) === 'ol'; 17046 }); 17047 }; 17048 var getFullySelectedListWrappers = function (parents, rng) { 17049 return find$3(parents, function (elm) { 17050 return name(elm) === 'li' && hasAllContentsSelected(elm, rng); 17051 }).fold(constant([]), function (_li) { 17052 return findParentListContainer(parents).map(function (listCont) { 17053 var listElm = SugarElement.fromTag(name(listCont)); 17054 var listStyles = filter$3(getAllRaw(listCont), function (_style, name) { 17055 return startsWith(name, 'list-style'); 17056 }); 17057 setAll(listElm, listStyles); 17058 return [ 17059 SugarElement.fromTag('li'), 17060 listElm 17061 ]; 17062 }).getOr([]); 17063 }); 17064 }; 17065 var wrap = function (innerElm, elms) { 17066 var wrapped = foldl(elms, function (acc, elm) { 17067 append$1(elm, acc); 17068 return elm; 17069 }, innerElm); 17070 return elms.length > 0 ? fromElements([wrapped]) : wrapped; 17071 }; 17072 var directListWrappers = function (commonAnchorContainer) { 17073 if (isListItem(commonAnchorContainer)) { 17074 return parent(commonAnchorContainer).filter(isList).fold(constant([]), function (listElm) { 17075 return [ 17076 commonAnchorContainer, 17077 listElm 17078 ]; 17079 }); 17080 } else { 17081 return isList(commonAnchorContainer) ? [commonAnchorContainer] : []; 17082 } 17083 }; 17084 var getWrapElements = function (rootNode, rng) { 17085 var commonAnchorContainer = SugarElement.fromDom(rng.commonAncestorContainer); 17086 var parents = parentsAndSelf(commonAnchorContainer, rootNode); 17087 var wrapElements = filter$4(parents, function (elm) { 17088 return isInline$1(elm) || isHeading(elm); 17089 }); 17090 var listWrappers = getFullySelectedListWrappers(parents, rng); 17091 var allWrappers = wrapElements.concat(listWrappers.length ? listWrappers : directListWrappers(commonAnchorContainer)); 17092 return map$3(allWrappers, shallow); 17093 }; 17094 var emptyFragment = function () { 17095 return fromElements([]); 17096 }; 17097 var getFragmentFromRange = function (rootNode, rng) { 17098 return wrap(SugarElement.fromDom(rng.cloneContents()), getWrapElements(rootNode, rng)); 17099 }; 17100 var getParentTable = function (rootElm, cell) { 17101 return ancestor$2(cell, 'table', curry(eq, rootElm)); 17102 }; 17103 var getTableFragment = function (rootNode, selectedTableCells) { 17104 return getParentTable(rootNode, selectedTableCells[0]).bind(function (tableElm) { 17105 var firstCell = selectedTableCells[0]; 17106 var lastCell = selectedTableCells[selectedTableCells.length - 1]; 17107 var fullTableModel = fromDom(tableElm); 17108 return subsection(fullTableModel, firstCell, lastCell).map(function (sectionedTableModel) { 17109 return fromElements([toDom(sectionedTableModel)]); 17110 }); 17111 }).getOrThunk(emptyFragment); 17112 }; 17113 var getSelectionFragment = function (rootNode, ranges) { 17114 return ranges.length > 0 && ranges[0].collapsed ? emptyFragment() : getFragmentFromRange(rootNode, ranges[0]); 17115 }; 17116 var read$3 = function (rootNode, ranges) { 17117 var selectedCells = getCellsFromElementOrRanges(ranges, rootNode); 17118 return selectedCells.length > 0 ? getTableFragment(rootNode, selectedCells) : getSelectionFragment(rootNode, ranges); 17119 }; 17120 17121 var trimLeadingCollapsibleText = function (text) { 17122 return text.replace(/^[ \f\n\r\t\v]+/, ''); 17123 }; 17124 var isCollapsibleWhitespace = function (text, index) { 17125 return index >= 0 && index < text.length && isWhiteSpace(text.charAt(index)); 17126 }; 17127 var getInnerText = function (bin, shouldTrim) { 17128 var text = trim$2(bin.innerText); 17129 return shouldTrim ? trimLeadingCollapsibleText(text) : text; 17130 }; 17131 var getContextNodeName = function (parentBlockOpt) { 17132 return parentBlockOpt.map(function (block) { 17133 return block.nodeName; 17134 }).getOr('div').toLowerCase(); 17135 }; 17136 var getTextContent = function (editor) { 17137 return Optional.from(editor.selection.getRng()).map(function (rng) { 17138 var parentBlockOpt = Optional.from(editor.dom.getParent(rng.commonAncestorContainer, editor.dom.isBlock)); 17139 var body = editor.getBody(); 17140 var contextNodeName = getContextNodeName(parentBlockOpt); 17141 var shouldTrimSpaces = Env.browser.isIE() && contextNodeName !== 'pre'; 17142 var bin = editor.dom.add(body, contextNodeName, { 17143 'data-mce-bogus': 'all', 17144 'style': 'overflow: hidden; opacity: 0;' 17145 }, rng.cloneContents()); 17146 var text = getInnerText(bin, shouldTrimSpaces); 17147 var nonRenderedText = trim$2(bin.textContent); 17148 editor.dom.remove(bin); 17149 if (isCollapsibleWhitespace(nonRenderedText, 0) || isCollapsibleWhitespace(nonRenderedText, nonRenderedText.length - 1)) { 17150 var parentBlock = parentBlockOpt.getOr(body); 17151 var parentBlockText = getInnerText(parentBlock, shouldTrimSpaces); 17152 var textIndex = parentBlockText.indexOf(text); 17153 if (textIndex === -1) { 17154 return text; 17155 } else { 17156 var hasProceedingSpace = isCollapsibleWhitespace(parentBlockText, textIndex - 1); 17157 var hasTrailingSpace = isCollapsibleWhitespace(parentBlockText, textIndex + text.length); 17158 return (hasProceedingSpace ? ' ' : '') + text + (hasTrailingSpace ? ' ' : ''); 17159 } 17160 } else { 17161 return text; 17162 } 17163 }).getOr(''); 17164 }; 17165 var getSerializedContent = function (editor, args) { 17166 var rng = editor.selection.getRng(), tmpElm = editor.dom.create('body'); 17167 var sel = editor.selection.getSel(); 17168 var ranges = processRanges(editor, getRanges(sel)); 17169 var fragment = args.contextual ? read$3(SugarElement.fromDom(editor.getBody()), ranges).dom : rng.cloneContents(); 17170 if (fragment) { 17171 tmpElm.appendChild(fragment); 17172 } 17173 return editor.selection.serializer.serialize(tmpElm, args); 17174 }; 17175 var setupArgs$1 = function (args, format) { 17176 return __assign(__assign({}, args), { 17177 format: format, 17178 get: true, 17179 selection: true 17180 }); 17181 }; 17182 var getSelectedContentInternal = function (editor, format, args) { 17183 if (args === void 0) { 17184 args = {}; 17185 } 17186 var defaultedArgs = setupArgs$1(args, format); 17187 var updatedArgs = editor.fire('BeforeGetContent', defaultedArgs); 17188 if (updatedArgs.isDefaultPrevented()) { 17189 editor.fire('GetContent', updatedArgs); 17190 return updatedArgs.content; 17191 } 17192 if (updatedArgs.format === 'text') { 17193 return getTextContent(editor); 17194 } else { 17195 updatedArgs.getInner = true; 17196 var content = getSerializedContent(editor, updatedArgs); 17197 if (updatedArgs.format === 'tree') { 17198 return content; 17199 } else { 17200 updatedArgs.content = editor.selection.isCollapsed() ? '' : content; 17201 editor.fire('GetContent', updatedArgs); 17202 return updatedArgs.content; 17203 } 17204 } 17205 }; 17206 17207 var KEEP = 0, INSERT = 1, DELETE = 2; 17208 var diff = function (left, right) { 17209 var size = left.length + right.length + 2; 17210 var vDown = new Array(size); 17211 var vUp = new Array(size); 17212 var snake = function (start, end, diag) { 17213 return { 17214 start: start, 17215 end: end, 17216 diag: diag 17217 }; 17218 }; 17219 var buildScript = function (start1, end1, start2, end2, script) { 17220 var middle = getMiddleSnake(start1, end1, start2, end2); 17221 if (middle === null || middle.start === end1 && middle.diag === end1 - end2 || middle.end === start1 && middle.diag === start1 - start2) { 17222 var i = start1; 17223 var j = start2; 17224 while (i < end1 || j < end2) { 17225 if (i < end1 && j < end2 && left[i] === right[j]) { 17226 script.push([ 17227 KEEP, 17228 left[i] 17229 ]); 17230 ++i; 17231 ++j; 17232 } else { 17233 if (end1 - start1 > end2 - start2) { 17234 script.push([ 17235 DELETE, 17236 left[i] 17237 ]); 17238 ++i; 17239 } else { 17240 script.push([ 17241 INSERT, 17242 right[j] 17243 ]); 17244 ++j; 17245 } 17246 } 17247 } 17248 } else { 17249 buildScript(start1, middle.start, start2, middle.start - middle.diag, script); 17250 for (var i2 = middle.start; i2 < middle.end; ++i2) { 17251 script.push([ 17252 KEEP, 17253 left[i2] 17254 ]); 17255 } 17256 buildScript(middle.end, end1, middle.end - middle.diag, end2, script); 17257 } 17258 }; 17259 var buildSnake = function (start, diag, end1, end2) { 17260 var end = start; 17261 while (end - diag < end2 && end < end1 && left[end] === right[end - diag]) { 17262 ++end; 17263 } 17264 return snake(start, end, diag); 17265 }; 17266 var getMiddleSnake = function (start1, end1, start2, end2) { 17267 var m = end1 - start1; 17268 var n = end2 - start2; 17269 if (m === 0 || n === 0) { 17270 return null; 17271 } 17272 var delta = m - n; 17273 var sum = n + m; 17274 var offset = (sum % 2 === 0 ? sum : sum + 1) / 2; 17275 vDown[1 + offset] = start1; 17276 vUp[1 + offset] = end1 + 1; 17277 var d, k, i, x, y; 17278 for (d = 0; d <= offset; ++d) { 17279 for (k = -d; k <= d; k += 2) { 17280 i = k + offset; 17281 if (k === -d || k !== d && vDown[i - 1] < vDown[i + 1]) { 17282 vDown[i] = vDown[i + 1]; 17283 } else { 17284 vDown[i] = vDown[i - 1] + 1; 17285 } 17286 x = vDown[i]; 17287 y = x - start1 + start2 - k; 17288 while (x < end1 && y < end2 && left[x] === right[y]) { 17289 vDown[i] = ++x; 17290 ++y; 17291 } 17292 if (delta % 2 !== 0 && delta - d <= k && k <= delta + d) { 17293 if (vUp[i - delta] <= vDown[i]) { 17294 return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2); 17295 } 17296 } 17297 } 17298 for (k = delta - d; k <= delta + d; k += 2) { 17299 i = k + offset - delta; 17300 if (k === delta - d || k !== delta + d && vUp[i + 1] <= vUp[i - 1]) { 17301 vUp[i] = vUp[i + 1] - 1; 17302 } else { 17303 vUp[i] = vUp[i - 1]; 17304 } 17305 x = vUp[i] - 1; 17306 y = x - start1 + start2 - k; 17307 while (x >= start1 && y >= start2 && left[x] === right[y]) { 17308 vUp[i] = x--; 17309 y--; 17310 } 17311 if (delta % 2 === 0 && -d <= k && k <= d) { 17312 if (vUp[i] <= vDown[i + delta]) { 17313 return buildSnake(vUp[i], k + start1 - start2, end1, end2); 17314 } 17315 } 17316 } 17317 } 17318 }; 17319 var script = []; 17320 buildScript(0, left.length, 0, right.length, script); 17321 return script; 17322 }; 17323 17324 var getOuterHtml = function (elm) { 17325 if (isElement$5(elm)) { 17326 return elm.outerHTML; 17327 } else if (isText$7(elm)) { 17328 return Entities.encodeRaw(elm.data, false); 17329 } else if (isComment(elm)) { 17330 return '<!--' + elm.data + '-->'; 17331 } 17332 return ''; 17333 }; 17334 var createFragment = function (html) { 17335 var node; 17336 var container = document.createElement('div'); 17337 var frag = document.createDocumentFragment(); 17338 if (html) { 17339 container.innerHTML = html; 17340 } 17341 while (node = container.firstChild) { 17342 frag.appendChild(node); 17343 } 17344 return frag; 17345 }; 17346 var insertAt = function (elm, html, index) { 17347 var fragment = createFragment(html); 17348 if (elm.hasChildNodes() && index < elm.childNodes.length) { 17349 var target = elm.childNodes[index]; 17350 target.parentNode.insertBefore(fragment, target); 17351 } else { 17352 elm.appendChild(fragment); 17353 } 17354 }; 17355 var removeAt = function (elm, index) { 17356 if (elm.hasChildNodes() && index < elm.childNodes.length) { 17357 var target = elm.childNodes[index]; 17358 target.parentNode.removeChild(target); 17359 } 17360 }; 17361 var applyDiff = function (diff, elm) { 17362 var index = 0; 17363 each$k(diff, function (action) { 17364 if (action[0] === KEEP) { 17365 index++; 17366 } else if (action[0] === INSERT) { 17367 insertAt(elm, action[1], index); 17368 index++; 17369 } else if (action[0] === DELETE) { 17370 removeAt(elm, index); 17371 } 17372 }); 17373 }; 17374 var read$2 = function (elm) { 17375 return filter$4(map$3(from(elm.childNodes), getOuterHtml), function (item) { 17376 return item.length > 0; 17377 }); 17378 }; 17379 var write = function (fragments, elm) { 17380 var currentFragments = map$3(from(elm.childNodes), getOuterHtml); 17381 applyDiff(diff(currentFragments, fragments), elm); 17382 return elm; 17383 }; 17384 17385 var lazyTempDocument = cached(function () { 17386 return document.implementation.createHTMLDocument('undo'); 17387 }); 17388 var hasIframes = function (html) { 17389 return html.indexOf('</iframe>') !== -1; 17390 }; 17391 var createFragmentedLevel = function (fragments) { 17392 return { 17393 type: 'fragmented', 17394 fragments: fragments, 17395 content: '', 17396 bookmark: null, 17397 beforeBookmark: null 17398 }; 17399 }; 17400 var createCompleteLevel = function (content) { 17401 return { 17402 type: 'complete', 17403 fragments: null, 17404 content: content, 17405 bookmark: null, 17406 beforeBookmark: null 17407 }; 17408 }; 17409 var createFromEditor = function (editor) { 17410 var fragments = read$2(editor.getBody()); 17411 var trimmedFragments = bind(fragments, function (html) { 17412 var trimmed = trimInternal(editor.serializer, html); 17413 return trimmed.length > 0 ? [trimmed] : []; 17414 }); 17415 var content = trimmedFragments.join(''); 17416 return hasIframes(content) ? createFragmentedLevel(trimmedFragments) : createCompleteLevel(content); 17417 }; 17418 var applyToEditor = function (editor, level, before) { 17419 var bookmark = before ? level.beforeBookmark : level.bookmark; 17420 if (level.type === 'fragmented') { 17421 write(level.fragments, editor.getBody()); 17422 } else { 17423 editor.setContent(level.content, { 17424 format: 'raw', 17425 no_selection: isNonNullable(bookmark) && isPathBookmark(bookmark) ? !bookmark.isFakeCaret : true 17426 }); 17427 } 17428 editor.selection.moveToBookmark(bookmark); 17429 }; 17430 var getLevelContent = function (level) { 17431 return level.type === 'fragmented' ? level.fragments.join('') : level.content; 17432 }; 17433 var getCleanLevelContent = function (level) { 17434 var elm = SugarElement.fromTag('body', lazyTempDocument()); 17435 set(elm, getLevelContent(level)); 17436 each$k(descendants(elm, '*[data-mce-bogus]'), unwrap); 17437 return get$3(elm); 17438 }; 17439 var hasEqualContent = function (level1, level2) { 17440 return getLevelContent(level1) === getLevelContent(level2); 17441 }; 17442 var hasEqualCleanedContent = function (level1, level2) { 17443 return getCleanLevelContent(level1) === getCleanLevelContent(level2); 17444 }; 17445 var isEq$1 = function (level1, level2) { 17446 if (!level1 || !level2) { 17447 return false; 17448 } else if (hasEqualContent(level1, level2)) { 17449 return true; 17450 } else { 17451 return hasEqualCleanedContent(level1, level2); 17452 } 17453 }; 17454 17455 var isUnlocked = function (locks) { 17456 return locks.get() === 0; 17457 }; 17458 17459 var setTyping = function (undoManager, typing, locks) { 17460 if (isUnlocked(locks)) { 17461 undoManager.typing = typing; 17462 } 17463 }; 17464 var endTyping = function (undoManager, locks) { 17465 if (undoManager.typing) { 17466 setTyping(undoManager, false, locks); 17467 undoManager.add(); 17468 } 17469 }; 17470 var endTypingLevelIgnoreLocks = function (undoManager) { 17471 if (undoManager.typing) { 17472 undoManager.typing = false; 17473 undoManager.add(); 17474 } 17475 }; 17476 17477 var beforeChange$1 = function (editor, locks, beforeBookmark) { 17478 if (isUnlocked(locks)) { 17479 beforeBookmark.set(getUndoBookmark(editor.selection)); 17480 } 17481 }; 17482 var addUndoLevel$1 = function (editor, undoManager, index, locks, beforeBookmark, level, event) { 17483 var currentLevel = createFromEditor(editor); 17484 level = level || {}; 17485 level = Tools.extend(level, currentLevel); 17486 if (isUnlocked(locks) === false || editor.removed) { 17487 return null; 17488 } 17489 var lastLevel = undoManager.data[index.get()]; 17490 if (editor.fire('BeforeAddUndo', { 17491 level: level, 17492 lastLevel: lastLevel, 17493 originalEvent: event 17494 }).isDefaultPrevented()) { 17495 return null; 17496 } 17497 if (lastLevel && isEq$1(lastLevel, level)) { 17498 return null; 17499 } 17500 if (undoManager.data[index.get()]) { 17501 beforeBookmark.get().each(function (bm) { 17502 undoManager.data[index.get()].beforeBookmark = bm; 17503 }); 17504 } 17505 var customUndoRedoLevels = getCustomUndoRedoLevels(editor); 17506 if (customUndoRedoLevels) { 17507 if (undoManager.data.length > customUndoRedoLevels) { 17508 for (var i = 0; i < undoManager.data.length - 1; i++) { 17509 undoManager.data[i] = undoManager.data[i + 1]; 17510 } 17511 undoManager.data.length--; 17512 index.set(undoManager.data.length); 17513 } 17514 } 17515 level.bookmark = getUndoBookmark(editor.selection); 17516 if (index.get() < undoManager.data.length - 1) { 17517 undoManager.data.length = index.get() + 1; 17518 } 17519 undoManager.data.push(level); 17520 index.set(undoManager.data.length - 1); 17521 var args = { 17522 level: level, 17523 lastLevel: lastLevel, 17524 originalEvent: event 17525 }; 17526 if (index.get() > 0) { 17527 editor.setDirty(true); 17528 editor.fire('AddUndo', args); 17529 editor.fire('change', args); 17530 } else { 17531 editor.fire('AddUndo', args); 17532 } 17533 return level; 17534 }; 17535 var clear$1 = function (editor, undoManager, index) { 17536 undoManager.data = []; 17537 index.set(0); 17538 undoManager.typing = false; 17539 editor.fire('ClearUndos'); 17540 }; 17541 var extra$1 = function (editor, undoManager, index, callback1, callback2) { 17542 if (undoManager.transact(callback1)) { 17543 var bookmark = undoManager.data[index.get()].bookmark; 17544 var lastLevel = undoManager.data[index.get() - 1]; 17545 applyToEditor(editor, lastLevel, true); 17546 if (undoManager.transact(callback2)) { 17547 undoManager.data[index.get() - 1].beforeBookmark = bookmark; 17548 } 17549 } 17550 }; 17551 var redo$1 = function (editor, index, data) { 17552 var level; 17553 if (index.get() < data.length - 1) { 17554 index.set(index.get() + 1); 17555 level = data[index.get()]; 17556 applyToEditor(editor, level, false); 17557 editor.setDirty(true); 17558 editor.fire('Redo', { level: level }); 17559 } 17560 return level; 17561 }; 17562 var undo$1 = function (editor, undoManager, locks, index) { 17563 var level; 17564 if (undoManager.typing) { 17565 undoManager.add(); 17566 undoManager.typing = false; 17567 setTyping(undoManager, false, locks); 17568 } 17569 if (index.get() > 0) { 17570 index.set(index.get() - 1); 17571 level = undoManager.data[index.get()]; 17572 applyToEditor(editor, level, true); 17573 editor.setDirty(true); 17574 editor.fire('Undo', { level: level }); 17575 } 17576 return level; 17577 }; 17578 var reset$1 = function (undoManager) { 17579 undoManager.clear(); 17580 undoManager.add(); 17581 }; 17582 var hasUndo$1 = function (editor, undoManager, index) { 17583 return index.get() > 0 || undoManager.typing && undoManager.data[0] && !isEq$1(createFromEditor(editor), undoManager.data[0]); 17584 }; 17585 var hasRedo$1 = function (undoManager, index) { 17586 return index.get() < undoManager.data.length - 1 && !undoManager.typing; 17587 }; 17588 var transact$1 = function (undoManager, locks, callback) { 17589 endTyping(undoManager, locks); 17590 undoManager.beforeChange(); 17591 undoManager.ignore(callback); 17592 return undoManager.add(); 17593 }; 17594 var ignore$1 = function (locks, callback) { 17595 try { 17596 locks.set(locks.get() + 1); 17597 callback(); 17598 } finally { 17599 locks.set(locks.get() - 1); 17600 } 17601 }; 17602 17603 var addVisualInternal = function (editor, elm) { 17604 var dom = editor.dom; 17605 var scope = isNonNullable(elm) ? elm : editor.getBody(); 17606 if (isUndefined(editor.hasVisual)) { 17607 editor.hasVisual = isVisualAidsEnabled(editor); 17608 } 17609 each$k(dom.select('table,a', scope), function (matchedElm) { 17610 switch (matchedElm.nodeName) { 17611 case 'TABLE': 17612 var cls = getVisualAidsTableClass(editor); 17613 var value = dom.getAttrib(matchedElm, 'border'); 17614 if ((!value || value === '0') && editor.hasVisual) { 17615 dom.addClass(matchedElm, cls); 17616 } else { 17617 dom.removeClass(matchedElm, cls); 17618 } 17619 break; 17620 case 'A': 17621 if (!dom.getAttrib(matchedElm, 'href')) { 17622 var value_1 = dom.getAttrib(matchedElm, 'name') || matchedElm.id; 17623 var cls_1 = getVisualAidsAnchorClass(editor); 17624 if (value_1 && editor.hasVisual) { 17625 dom.addClass(matchedElm, cls_1); 17626 } else { 17627 dom.removeClass(matchedElm, cls_1); 17628 } 17629 } 17630 break; 17631 } 17632 }); 17633 editor.fire('VisualAid', { 17634 element: elm, 17635 hasVisual: editor.hasVisual 17636 }); 17637 }; 17638 17639 var makePlainAdaptor = function (editor) { 17640 return { 17641 undoManager: { 17642 beforeChange: function (locks, beforeBookmark) { 17643 return beforeChange$1(editor, locks, beforeBookmark); 17644 }, 17645 add: function (undoManager, index, locks, beforeBookmark, level, event) { 17646 return addUndoLevel$1(editor, undoManager, index, locks, beforeBookmark, level, event); 17647 }, 17648 undo: function (undoManager, locks, index) { 17649 return undo$1(editor, undoManager, locks, index); 17650 }, 17651 redo: function (index, data) { 17652 return redo$1(editor, index, data); 17653 }, 17654 clear: function (undoManager, index) { 17655 return clear$1(editor, undoManager, index); 17656 }, 17657 reset: function (undoManager) { 17658 return reset$1(undoManager); 17659 }, 17660 hasUndo: function (undoManager, index) { 17661 return hasUndo$1(editor, undoManager, index); 17662 }, 17663 hasRedo: function (undoManager, index) { 17664 return hasRedo$1(undoManager, index); 17665 }, 17666 transact: function (undoManager, locks, callback) { 17667 return transact$1(undoManager, locks, callback); 17668 }, 17669 ignore: function (locks, callback) { 17670 return ignore$1(locks, callback); 17671 }, 17672 extra: function (undoManager, index, callback1, callback2) { 17673 return extra$1(editor, undoManager, index, callback1, callback2); 17674 } 17675 }, 17676 formatter: { 17677 match: function (name, vars, node, similar) { 17678 return match$2(editor, name, vars, node, similar); 17679 }, 17680 matchAll: function (names, vars) { 17681 return matchAll(editor, names, vars); 17682 }, 17683 matchNode: function (node, name, vars, similar) { 17684 return matchNode(editor, node, name, vars, similar); 17685 }, 17686 canApply: function (name) { 17687 return canApply(editor, name); 17688 }, 17689 closest: function (names) { 17690 return closest(editor, names); 17691 }, 17692 apply: function (name, vars, node) { 17693 return applyFormat$1(editor, name, vars, node); 17694 }, 17695 remove: function (name, vars, node, similar) { 17696 return remove$1(editor, name, vars, node, similar); 17697 }, 17698 toggle: function (name, vars, node) { 17699 return toggle(editor, name, vars, node); 17700 }, 17701 formatChanged: function (registeredFormatListeners, formats, callback, similar, vars) { 17702 return formatChangedInternal(editor, registeredFormatListeners, formats, callback, similar, vars); 17703 } 17704 }, 17705 editor: { 17706 getContent: function (args, format) { 17707 return getContentInternal(editor, args, format); 17708 }, 17709 setContent: function (content, args) { 17710 return setContentInternal(editor, content, args); 17711 }, 17712 insertContent: function (value, details) { 17713 return insertHtmlAtCaret(editor, value, details); 17714 }, 17715 addVisual: function (elm) { 17716 return addVisualInternal(editor, elm); 17717 } 17718 }, 17719 selection: { 17720 getContent: function (format, args) { 17721 return getSelectedContentInternal(editor, format, args); 17722 } 17723 }, 17724 raw: { 17725 getModel: function () { 17726 return Optional.none(); 17727 } 17728 } 17729 }; 17730 }; 17731 var makeRtcAdaptor = function (rtcEditor) { 17732 var defaultVars = function (vars) { 17733 return isObject(vars) ? vars : {}; 17734 }; 17735 var undoManager = rtcEditor.undoManager, formatter = rtcEditor.formatter, editor = rtcEditor.editor, selection = rtcEditor.selection, raw = rtcEditor.raw; 17736 return { 17737 undoManager: { 17738 beforeChange: undoManager.beforeChange, 17739 add: undoManager.add, 17740 undo: undoManager.undo, 17741 redo: undoManager.redo, 17742 clear: undoManager.clear, 17743 reset: undoManager.reset, 17744 hasUndo: undoManager.hasUndo, 17745 hasRedo: undoManager.hasRedo, 17746 transact: function (_undoManager, _locks, fn) { 17747 return undoManager.transact(fn); 17748 }, 17749 ignore: function (_locks, callback) { 17750 return undoManager.ignore(callback); 17751 }, 17752 extra: function (_undoManager, _index, callback1, callback2) { 17753 return undoManager.extra(callback1, callback2); 17754 } 17755 }, 17756 formatter: { 17757 match: function (name, vars, _node, similar) { 17758 return formatter.match(name, defaultVars(vars), similar); 17759 }, 17760 matchAll: formatter.matchAll, 17761 matchNode: formatter.matchNode, 17762 canApply: function (name) { 17763 return formatter.canApply(name); 17764 }, 17765 closest: function (names) { 17766 return formatter.closest(names); 17767 }, 17768 apply: function (name, vars, _node) { 17769 return formatter.apply(name, defaultVars(vars)); 17770 }, 17771 remove: function (name, vars, _node, _similar) { 17772 return formatter.remove(name, defaultVars(vars)); 17773 }, 17774 toggle: function (name, vars, _node) { 17775 return formatter.toggle(name, defaultVars(vars)); 17776 }, 17777 formatChanged: function (_rfl, formats, callback, similar, vars) { 17778 return formatter.formatChanged(formats, callback, similar, vars); 17779 } 17780 }, 17781 editor: { 17782 getContent: function (args, _format) { 17783 return editor.getContent(args); 17784 }, 17785 setContent: function (content, args) { 17786 return editor.setContent(content, args); 17787 }, 17788 insertContent: function (content, _details) { 17789 return editor.insertContent(content); 17790 }, 17791 addVisual: editor.addVisual 17792 }, 17793 selection: { 17794 getContent: function (_format, args) { 17795 return selection.getContent(args); 17796 } 17797 }, 17798 raw: { 17799 getModel: function () { 17800 return Optional.some(raw.getRawModel()); 17801 } 17802 } 17803 }; 17804 }; 17805 var makeNoopAdaptor = function () { 17806 var nul = constant(null); 17807 var empty = constant(''); 17808 return { 17809 undoManager: { 17810 beforeChange: noop, 17811 add: nul, 17812 undo: nul, 17813 redo: nul, 17814 clear: noop, 17815 reset: noop, 17816 hasUndo: never, 17817 hasRedo: never, 17818 transact: nul, 17819 ignore: noop, 17820 extra: noop 17821 }, 17822 formatter: { 17823 match: never, 17824 matchAll: constant([]), 17825 matchNode: constant(undefined), 17826 canApply: never, 17827 closest: empty, 17828 apply: noop, 17829 remove: noop, 17830 toggle: noop, 17831 formatChanged: constant({ unbind: noop }) 17832 }, 17833 editor: { 17834 getContent: empty, 17835 setContent: empty, 17836 insertContent: noop, 17837 addVisual: noop 17838 }, 17839 selection: { getContent: empty }, 17840 raw: { getModel: constant(Optional.none()) } 17841 }; 17842 }; 17843 var isRtc = function (editor) { 17844 return has$2(editor.plugins, 'rtc'); 17845 }; 17846 var getRtcSetup = function (editor) { 17847 return get$9(editor.plugins, 'rtc').bind(function (rtcPlugin) { 17848 return Optional.from(rtcPlugin.setup); 17849 }); 17850 }; 17851 var setup$i = function (editor) { 17852 var editorCast = editor; 17853 return getRtcSetup(editor).fold(function () { 17854 editorCast.rtcInstance = makePlainAdaptor(editor); 17855 return Optional.none(); 17856 }, function (setup) { 17857 editorCast.rtcInstance = makeNoopAdaptor(); 17858 return Optional.some(function () { 17859 return setup().then(function (rtcEditor) { 17860 editorCast.rtcInstance = makeRtcAdaptor(rtcEditor); 17861 return rtcEditor.rtc.isRemote; 17862 }); 17863 }); 17864 }); 17865 }; 17866 var getRtcInstanceWithFallback = function (editor) { 17867 return editor.rtcInstance ? editor.rtcInstance : makePlainAdaptor(editor); 17868 }; 17869 var getRtcInstanceWithError = function (editor) { 17870 var rtcInstance = editor.rtcInstance; 17871 if (!rtcInstance) { 17872 throw new Error('Failed to get RTC instance not yet initialized.'); 17873 } else { 17874 return rtcInstance; 17875 } 17876 }; 17877 var beforeChange = function (editor, locks, beforeBookmark) { 17878 getRtcInstanceWithError(editor).undoManager.beforeChange(locks, beforeBookmark); 17879 }; 17880 var addUndoLevel = function (editor, undoManager, index, locks, beforeBookmark, level, event) { 17881 return getRtcInstanceWithError(editor).undoManager.add(undoManager, index, locks, beforeBookmark, level, event); 17882 }; 17883 var undo = function (editor, undoManager, locks, index) { 17884 return getRtcInstanceWithError(editor).undoManager.undo(undoManager, locks, index); 17885 }; 17886 var redo = function (editor, index, data) { 17887 return getRtcInstanceWithError(editor).undoManager.redo(index, data); 17888 }; 17889 var clear = function (editor, undoManager, index) { 17890 getRtcInstanceWithError(editor).undoManager.clear(undoManager, index); 17891 }; 17892 var reset = function (editor, undoManager) { 17893 getRtcInstanceWithError(editor).undoManager.reset(undoManager); 17894 }; 17895 var hasUndo = function (editor, undoManager, index) { 17896 return getRtcInstanceWithError(editor).undoManager.hasUndo(undoManager, index); 17897 }; 17898 var hasRedo = function (editor, undoManager, index) { 17899 return getRtcInstanceWithError(editor).undoManager.hasRedo(undoManager, index); 17900 }; 17901 var transact = function (editor, undoManager, locks, callback) { 17902 return getRtcInstanceWithError(editor).undoManager.transact(undoManager, locks, callback); 17903 }; 17904 var ignore = function (editor, locks, callback) { 17905 getRtcInstanceWithError(editor).undoManager.ignore(locks, callback); 17906 }; 17907 var extra = function (editor, undoManager, index, callback1, callback2) { 17908 getRtcInstanceWithError(editor).undoManager.extra(undoManager, index, callback1, callback2); 17909 }; 17910 var matchFormat = function (editor, name, vars, node, similar) { 17911 return getRtcInstanceWithError(editor).formatter.match(name, vars, node, similar); 17912 }; 17913 var matchAllFormats = function (editor, names, vars) { 17914 return getRtcInstanceWithError(editor).formatter.matchAll(names, vars); 17915 }; 17916 var matchNodeFormat = function (editor, node, name, vars, similar) { 17917 return getRtcInstanceWithError(editor).formatter.matchNode(node, name, vars, similar); 17918 }; 17919 var canApplyFormat = function (editor, name) { 17920 return getRtcInstanceWithError(editor).formatter.canApply(name); 17921 }; 17922 var closestFormat = function (editor, names) { 17923 return getRtcInstanceWithError(editor).formatter.closest(names); 17924 }; 17925 var applyFormat = function (editor, name, vars, node) { 17926 getRtcInstanceWithError(editor).formatter.apply(name, vars, node); 17927 }; 17928 var removeFormat = function (editor, name, vars, node, similar) { 17929 getRtcInstanceWithError(editor).formatter.remove(name, vars, node, similar); 17930 }; 17931 var toggleFormat = function (editor, name, vars, node) { 17932 getRtcInstanceWithError(editor).formatter.toggle(name, vars, node); 17933 }; 17934 var formatChanged = function (editor, registeredFormatListeners, formats, callback, similar, vars) { 17935 return getRtcInstanceWithError(editor).formatter.formatChanged(registeredFormatListeners, formats, callback, similar, vars); 17936 }; 17937 var getContent$2 = function (editor, args, format) { 17938 return getRtcInstanceWithFallback(editor).editor.getContent(args, format); 17939 }; 17940 var setContent$2 = function (editor, content, args) { 17941 return getRtcInstanceWithFallback(editor).editor.setContent(content, args); 17942 }; 17943 var insertContent = function (editor, value, details) { 17944 return getRtcInstanceWithFallback(editor).editor.insertContent(value, details); 17945 }; 17946 var getSelectedContent = function (editor, format, args) { 17947 return getRtcInstanceWithError(editor).selection.getContent(format, args); 17948 }; 17949 var addVisual$1 = function (editor, elm) { 17950 return getRtcInstanceWithError(editor).editor.addVisual(elm); 17951 }; 17952 17953 var getContent$1 = function (editor, args) { 17954 if (args === void 0) { 17955 args = {}; 17956 } 17957 var format = args.format ? args.format : 'html'; 17958 return getSelectedContent(editor, format, args); 17959 }; 17960 17961 var removeEmpty = function (text) { 17962 if (text.dom.length === 0) { 17963 remove$7(text); 17964 return Optional.none(); 17965 } else { 17966 return Optional.some(text); 17967 } 17968 }; 17969 var walkPastBookmark = function (node, start) { 17970 return node.filter(function (elm) { 17971 return BookmarkManager.isBookmarkNode(elm.dom); 17972 }).bind(start ? nextSibling : prevSibling); 17973 }; 17974 var merge = function (outer, inner, rng, start) { 17975 var outerElm = outer.dom; 17976 var innerElm = inner.dom; 17977 var oldLength = start ? outerElm.length : innerElm.length; 17978 if (start) { 17979 mergeTextNodes(outerElm, innerElm, false, !start); 17980 rng.setStart(innerElm, oldLength); 17981 } else { 17982 mergeTextNodes(innerElm, outerElm, false, !start); 17983 rng.setEnd(innerElm, oldLength); 17984 } 17985 }; 17986 var normalizeTextIfRequired = function (inner, start) { 17987 parent(inner).each(function (root) { 17988 var text = inner.dom; 17989 if (start && needsToBeNbspLeft(root, CaretPosition(text, 0))) { 17990 normalizeWhitespaceAfter(text, 0); 17991 } else if (!start && needsToBeNbspRight(root, CaretPosition(text, text.length))) { 17992 normalizeWhitespaceBefore(text, text.length); 17993 } 17994 }); 17995 }; 17996 var mergeAndNormalizeText = function (outerNode, innerNode, rng, start) { 17997 outerNode.bind(function (outer) { 17998 var normalizer = start ? normalizeWhitespaceBefore : normalizeWhitespaceAfter; 17999 normalizer(outer.dom, start ? outer.dom.length : 0); 18000 return innerNode.filter(isText$8).map(function (inner) { 18001 return merge(outer, inner, rng, start); 18002 }); 18003 }).orThunk(function () { 18004 var innerTextNode = walkPastBookmark(innerNode, start).or(innerNode).filter(isText$8); 18005 return innerTextNode.map(function (inner) { 18006 return normalizeTextIfRequired(inner, start); 18007 }); 18008 }); 18009 }; 18010 var rngSetContent = function (rng, fragment) { 18011 var firstChild = Optional.from(fragment.firstChild).map(SugarElement.fromDom); 18012 var lastChild = Optional.from(fragment.lastChild).map(SugarElement.fromDom); 18013 rng.deleteContents(); 18014 rng.insertNode(fragment); 18015 var prevText = firstChild.bind(prevSibling).filter(isText$8).bind(removeEmpty); 18016 var nextText = lastChild.bind(nextSibling).filter(isText$8).bind(removeEmpty); 18017 mergeAndNormalizeText(prevText, firstChild, rng, true); 18018 mergeAndNormalizeText(nextText, lastChild, rng, false); 18019 rng.collapse(false); 18020 }; 18021 var setupArgs = function (args, content) { 18022 return __assign(__assign({ format: 'html' }, args), { 18023 set: true, 18024 selection: true, 18025 content: content 18026 }); 18027 }; 18028 var cleanContent = function (editor, args) { 18029 if (args.format !== 'raw') { 18030 var rng = editor.selection.getRng(); 18031 var contextBlock = editor.dom.getParent(rng.commonAncestorContainer, editor.dom.isBlock); 18032 var contextArgs = contextBlock ? { context: contextBlock.nodeName.toLowerCase() } : {}; 18033 var node = editor.parser.parse(args.content, __assign(__assign({ 18034 isRootContent: true, 18035 forced_root_block: false 18036 }, contextArgs), args)); 18037 return HtmlSerializer({ validate: editor.validate }, editor.schema).serialize(node); 18038 } else { 18039 return args.content; 18040 } 18041 }; 18042 var setContent$1 = function (editor, content, args) { 18043 if (args === void 0) { 18044 args = {}; 18045 } 18046 var defaultedArgs = setupArgs(args, content); 18047 var updatedArgs = defaultedArgs; 18048 if (!defaultedArgs.no_events) { 18049 var eventArgs = editor.fire('BeforeSetContent', defaultedArgs); 18050 if (eventArgs.isDefaultPrevented()) { 18051 editor.fire('SetContent', eventArgs); 18052 return; 18053 } else { 18054 updatedArgs = eventArgs; 18055 } 18056 } 18057 updatedArgs.content = cleanContent(editor, updatedArgs); 18058 var rng = editor.selection.getRng(); 18059 rngSetContent(rng, rng.createContextualFragment(updatedArgs.content)); 18060 editor.selection.setRng(rng); 18061 scrollRangeIntoView(editor, rng); 18062 if (!updatedArgs.no_events) { 18063 editor.fire('SetContent', updatedArgs); 18064 } 18065 }; 18066 18067 var deleteFromCallbackMap = function (callbackMap, selector, callback) { 18068 if (callbackMap && has$2(callbackMap, selector)) { 18069 var newCallbacks = filter$4(callbackMap[selector], function (cb) { 18070 return cb !== callback; 18071 }); 18072 if (newCallbacks.length === 0) { 18073 delete callbackMap[selector]; 18074 } else { 18075 callbackMap[selector] = newCallbacks; 18076 } 18077 } 18078 }; 18079 function SelectorChanged (dom, editor) { 18080 var selectorChangedData; 18081 var currentSelectors; 18082 var findMatchingNode = function (selector, nodes) { 18083 return find$3(nodes, function (node) { 18084 return dom.is(node, selector); 18085 }); 18086 }; 18087 var getParents = function (elem) { 18088 return dom.getParents(elem, null, dom.getRoot()); 18089 }; 18090 return { 18091 selectorChangedWithUnbind: function (selector, callback) { 18092 if (!selectorChangedData) { 18093 selectorChangedData = {}; 18094 currentSelectors = {}; 18095 editor.on('NodeChange', function (e) { 18096 var node = e.element; 18097 var parents = getParents(node); 18098 var matchedSelectors = {}; 18099 Tools.each(selectorChangedData, function (callbacks, selector) { 18100 findMatchingNode(selector, parents).each(function (node) { 18101 if (!currentSelectors[selector]) { 18102 each$k(callbacks, function (callback) { 18103 callback(true, { 18104 node: node, 18105 selector: selector, 18106 parents: parents 18107 }); 18108 }); 18109 currentSelectors[selector] = callbacks; 18110 } 18111 matchedSelectors[selector] = callbacks; 18112 }); 18113 }); 18114 Tools.each(currentSelectors, function (callbacks, selector) { 18115 if (!matchedSelectors[selector]) { 18116 delete currentSelectors[selector]; 18117 Tools.each(callbacks, function (callback) { 18118 callback(false, { 18119 node: node, 18120 selector: selector, 18121 parents: parents 18122 }); 18123 }); 18124 } 18125 }); 18126 }); 18127 } 18128 if (!selectorChangedData[selector]) { 18129 selectorChangedData[selector] = []; 18130 } 18131 selectorChangedData[selector].push(callback); 18132 findMatchingNode(selector, getParents(editor.selection.getStart())).each(function () { 18133 currentSelectors[selector] = selectorChangedData[selector]; 18134 }); 18135 return { 18136 unbind: function () { 18137 deleteFromCallbackMap(selectorChangedData, selector, callback); 18138 deleteFromCallbackMap(currentSelectors, selector, callback); 18139 } 18140 }; 18141 } 18142 }; 18143 } 18144 18145 var isNativeIeSelection = function (rng) { 18146 return !!rng.select; 18147 }; 18148 var isAttachedToDom = function (node) { 18149 return !!(node && node.ownerDocument) && contains$1(SugarElement.fromDom(node.ownerDocument), SugarElement.fromDom(node)); 18150 }; 18151 var isValidRange = function (rng) { 18152 if (!rng) { 18153 return false; 18154 } else if (isNativeIeSelection(rng)) { 18155 return true; 18156 } else { 18157 return isAttachedToDom(rng.startContainer) && isAttachedToDom(rng.endContainer); 18158 } 18159 }; 18160 var EditorSelection = function (dom, win, serializer, editor) { 18161 var selectedRange; 18162 var explicitRange; 18163 var selectorChangedWithUnbind = SelectorChanged(dom, editor).selectorChangedWithUnbind; 18164 var setCursorLocation = function (node, offset) { 18165 var rng = dom.createRng(); 18166 if (isNonNullable(node) && isNonNullable(offset)) { 18167 rng.setStart(node, offset); 18168 rng.setEnd(node, offset); 18169 setRng(rng); 18170 collapse(false); 18171 } else { 18172 moveEndPoint(dom, rng, editor.getBody(), true); 18173 setRng(rng); 18174 } 18175 }; 18176 var getContent = function (args) { 18177 return getContent$1(editor, args); 18178 }; 18179 var setContent = function (content, args) { 18180 return setContent$1(editor, content, args); 18181 }; 18182 var getStart$1 = function (real) { 18183 return getStart(editor.getBody(), getRng$1(), real); 18184 }; 18185 var getEnd$1 = function (real) { 18186 return getEnd(editor.getBody(), getRng$1(), real); 18187 }; 18188 var getBookmark = function (type, normalized) { 18189 return bookmarkManager.getBookmark(type, normalized); 18190 }; 18191 var moveToBookmark = function (bookmark) { 18192 return bookmarkManager.moveToBookmark(bookmark); 18193 }; 18194 var select$1 = function (node, content) { 18195 select(dom, node, content).each(setRng); 18196 return node; 18197 }; 18198 var isCollapsed = function () { 18199 var rng = getRng$1(), sel = getSel(); 18200 if (!rng || rng.item) { 18201 return false; 18202 } 18203 if (rng.compareEndPoints) { 18204 return rng.compareEndPoints('StartToEnd', rng) === 0; 18205 } 18206 return !sel || rng.collapsed; 18207 }; 18208 var collapse = function (toStart) { 18209 var rng = getRng$1(); 18210 rng.collapse(!!toStart); 18211 setRng(rng); 18212 }; 18213 var getSel = function () { 18214 return win.getSelection ? win.getSelection() : win.document.selection; 18215 }; 18216 var getRng$1 = function () { 18217 var selection, rng, elm; 18218 var tryCompareBoundaryPoints = function (how, sourceRange, destinationRange) { 18219 try { 18220 return sourceRange.compareBoundaryPoints(how, destinationRange); 18221 } catch (ex) { 18222 return -1; 18223 } 18224 }; 18225 var doc = win.document; 18226 if (editor.bookmark !== undefined && hasFocus(editor) === false) { 18227 var bookmark = getRng(editor); 18228 if (bookmark.isSome()) { 18229 return bookmark.map(function (r) { 18230 return processRanges(editor, [r])[0]; 18231 }).getOr(doc.createRange()); 18232 } 18233 } 18234 try { 18235 if ((selection = getSel()) && !isRestrictedNode(selection.anchorNode)) { 18236 if (selection.rangeCount > 0) { 18237 rng = selection.getRangeAt(0); 18238 } else { 18239 rng = selection.createRange ? selection.createRange() : doc.createRange(); 18240 } 18241 rng = processRanges(editor, [rng])[0]; 18242 } 18243 } catch (ex) { 18244 } 18245 if (!rng) { 18246 rng = doc.createRange ? doc.createRange() : doc.body.createTextRange(); 18247 } 18248 if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) { 18249 elm = dom.getRoot(); 18250 rng.setStart(elm, 0); 18251 rng.setEnd(elm, 0); 18252 } 18253 if (selectedRange && explicitRange) { 18254 if (tryCompareBoundaryPoints(rng.START_TO_START, rng, selectedRange) === 0 && tryCompareBoundaryPoints(rng.END_TO_END, rng, selectedRange) === 0) { 18255 rng = explicitRange; 18256 } else { 18257 selectedRange = null; 18258 explicitRange = null; 18259 } 18260 } 18261 return rng; 18262 }; 18263 var setRng = function (rng, forward) { 18264 var node; 18265 if (!isValidRange(rng)) { 18266 return; 18267 } 18268 var ieRange = isNativeIeSelection(rng) ? rng : null; 18269 if (ieRange) { 18270 explicitRange = null; 18271 try { 18272 ieRange.select(); 18273 } catch (ex) { 18274 } 18275 return; 18276 } 18277 var sel = getSel(); 18278 var evt = editor.fire('SetSelectionRange', { 18279 range: rng, 18280 forward: forward 18281 }); 18282 rng = evt.range; 18283 if (sel) { 18284 explicitRange = rng; 18285 try { 18286 sel.removeAllRanges(); 18287 sel.addRange(rng); 18288 } catch (ex) { 18289 } 18290 if (forward === false && sel.extend) { 18291 sel.collapse(rng.endContainer, rng.endOffset); 18292 sel.extend(rng.startContainer, rng.startOffset); 18293 } 18294 selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null; 18295 } 18296 if (!rng.collapsed && rng.startContainer === rng.endContainer && sel.setBaseAndExtent && !Env.ie) { 18297 if (rng.endOffset - rng.startOffset < 2) { 18298 if (rng.startContainer.hasChildNodes()) { 18299 node = rng.startContainer.childNodes[rng.startOffset]; 18300 if (node && node.tagName === 'IMG') { 18301 sel.setBaseAndExtent(rng.startContainer, rng.startOffset, rng.endContainer, rng.endOffset); 18302 if (sel.anchorNode !== rng.startContainer || sel.focusNode !== rng.endContainer) { 18303 sel.setBaseAndExtent(node, 0, node, 1); 18304 } 18305 } 18306 } 18307 } 18308 } 18309 editor.fire('AfterSetSelectionRange', { 18310 range: rng, 18311 forward: forward 18312 }); 18313 }; 18314 var setNode = function (elm) { 18315 setContent(dom.getOuterHTML(elm)); 18316 return elm; 18317 }; 18318 var getNode$1 = function () { 18319 return getNode(editor.getBody(), getRng$1()); 18320 }; 18321 var getSelectedBlocks$1 = function (startElm, endElm) { 18322 return getSelectedBlocks(dom, getRng$1(), startElm, endElm); 18323 }; 18324 var isForward = function () { 18325 var sel = getSel(); 18326 var anchorNode = sel === null || sel === void 0 ? void 0 : sel.anchorNode; 18327 var focusNode = sel === null || sel === void 0 ? void 0 : sel.focusNode; 18328 if (!sel || !anchorNode || !focusNode || isRestrictedNode(anchorNode) || isRestrictedNode(focusNode)) { 18329 return true; 18330 } 18331 var anchorRange = dom.createRng(); 18332 anchorRange.setStart(anchorNode, sel.anchorOffset); 18333 anchorRange.collapse(true); 18334 var focusRange = dom.createRng(); 18335 focusRange.setStart(focusNode, sel.focusOffset); 18336 focusRange.collapse(true); 18337 return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0; 18338 }; 18339 var normalize = function () { 18340 var rng = getRng$1(); 18341 var sel = getSel(); 18342 if (!hasMultipleRanges(sel) && hasAnyRanges(editor)) { 18343 var normRng = normalize$2(dom, rng); 18344 normRng.each(function (normRng) { 18345 setRng(normRng, isForward()); 18346 }); 18347 return normRng.getOr(rng); 18348 } 18349 return rng; 18350 }; 18351 var selectorChanged = function (selector, callback) { 18352 selectorChangedWithUnbind(selector, callback); 18353 return exports; 18354 }; 18355 var getScrollContainer = function () { 18356 var scrollContainer; 18357 var node = dom.getRoot(); 18358 while (node && node.nodeName !== 'BODY') { 18359 if (node.scrollHeight > node.clientHeight) { 18360 scrollContainer = node; 18361 break; 18362 } 18363 node = node.parentNode; 18364 } 18365 return scrollContainer; 18366 }; 18367 var scrollIntoView = function (elm, alignToTop) { 18368 if (isNonNullable(elm)) { 18369 scrollElementIntoView(editor, elm, alignToTop); 18370 } else { 18371 scrollRangeIntoView(editor, getRng$1(), alignToTop); 18372 } 18373 }; 18374 var placeCaretAt = function (clientX, clientY) { 18375 return setRng(fromPoint(clientX, clientY, editor.getDoc())); 18376 }; 18377 var getBoundingClientRect = function () { 18378 var rng = getRng$1(); 18379 return rng.collapsed ? CaretPosition.fromRangeStart(rng).getClientRects()[0] : rng.getBoundingClientRect(); 18380 }; 18381 var destroy = function () { 18382 win = selectedRange = explicitRange = null; 18383 controlSelection.destroy(); 18384 }; 18385 var exports = { 18386 bookmarkManager: null, 18387 controlSelection: null, 18388 dom: dom, 18389 win: win, 18390 serializer: serializer, 18391 editor: editor, 18392 collapse: collapse, 18393 setCursorLocation: setCursorLocation, 18394 getContent: getContent, 18395 setContent: setContent, 18396 getBookmark: getBookmark, 18397 moveToBookmark: moveToBookmark, 18398 select: select$1, 18399 isCollapsed: isCollapsed, 18400 isForward: isForward, 18401 setNode: setNode, 18402 getNode: getNode$1, 18403 getSel: getSel, 18404 setRng: setRng, 18405 getRng: getRng$1, 18406 getStart: getStart$1, 18407 getEnd: getEnd$1, 18408 getSelectedBlocks: getSelectedBlocks$1, 18409 normalize: normalize, 18410 selectorChanged: selectorChanged, 18411 selectorChangedWithUnbind: selectorChangedWithUnbind, 18412 getScrollContainer: getScrollContainer, 18413 scrollIntoView: scrollIntoView, 18414 placeCaretAt: placeCaretAt, 18415 getBoundingClientRect: getBoundingClientRect, 18416 destroy: destroy 18417 }; 18418 var bookmarkManager = BookmarkManager(exports); 18419 var controlSelection = ControlSelection(exports, editor); 18420 exports.bookmarkManager = bookmarkManager; 18421 exports.controlSelection = controlSelection; 18422 return exports; 18423 }; 18424 18425 var removeAttrs = function (node, names) { 18426 each$k(names, function (name) { 18427 node.attr(name, null); 18428 }); 18429 }; 18430 var addFontToSpansFilter = function (domParser, styles, fontSizes) { 18431 domParser.addNodeFilter('font', function (nodes) { 18432 each$k(nodes, function (node) { 18433 var props = styles.parse(node.attr('style')); 18434 var color = node.attr('color'); 18435 var face = node.attr('face'); 18436 var size = node.attr('size'); 18437 if (color) { 18438 props.color = color; 18439 } 18440 if (face) { 18441 props['font-family'] = face; 18442 } 18443 if (size) { 18444 props['font-size'] = fontSizes[parseInt(node.attr('size'), 10) - 1]; 18445 } 18446 node.name = 'span'; 18447 node.attr('style', styles.serialize(props)); 18448 removeAttrs(node, [ 18449 'color', 18450 'face', 18451 'size' 18452 ]); 18453 }); 18454 }); 18455 }; 18456 var addStrikeToSpanFilter = function (domParser, styles) { 18457 domParser.addNodeFilter('strike', function (nodes) { 18458 each$k(nodes, function (node) { 18459 var props = styles.parse(node.attr('style')); 18460 props['text-decoration'] = 'line-through'; 18461 node.name = 'span'; 18462 node.attr('style', styles.serialize(props)); 18463 }); 18464 }); 18465 }; 18466 var addFilters = function (domParser, settings) { 18467 var styles = Styles(); 18468 if (settings.convert_fonts_to_spans) { 18469 addFontToSpansFilter(domParser, styles, Tools.explode(settings.font_size_legacy_values)); 18470 } 18471 addStrikeToSpanFilter(domParser, styles); 18472 }; 18473 var register$2 = function (domParser, settings) { 18474 if (settings.inline_styles) { 18475 addFilters(domParser, settings); 18476 } 18477 }; 18478 18479 var blobUriToBlob = function (url) { 18480 return new promiseObj(function (resolve, reject) { 18481 var rejectWithError = function () { 18482 reject('Cannot convert ' + url + ' to Blob. Resource might not exist or is inaccessible.'); 18483 }; 18484 try { 18485 var xhr_1 = new XMLHttpRequest(); 18486 xhr_1.open('GET', url, true); 18487 xhr_1.responseType = 'blob'; 18488 xhr_1.onload = function () { 18489 if (xhr_1.status === 200) { 18490 resolve(xhr_1.response); 18491 } else { 18492 rejectWithError(); 18493 } 18494 }; 18495 xhr_1.onerror = rejectWithError; 18496 xhr_1.send(); 18497 } catch (ex) { 18498 rejectWithError(); 18499 } 18500 }); 18501 }; 18502 var parseDataUri = function (uri) { 18503 var type; 18504 var uriParts = decodeURIComponent(uri).split(','); 18505 var matches = /data:([^;]+)/.exec(uriParts[0]); 18506 if (matches) { 18507 type = matches[1]; 18508 } 18509 return { 18510 type: type, 18511 data: uriParts[1] 18512 }; 18513 }; 18514 var buildBlob = function (type, data) { 18515 var str; 18516 try { 18517 str = atob(data); 18518 } catch (e) { 18519 return Optional.none(); 18520 } 18521 var arr = new Uint8Array(str.length); 18522 for (var i = 0; i < arr.length; i++) { 18523 arr[i] = str.charCodeAt(i); 18524 } 18525 return Optional.some(new Blob([arr], { type: type })); 18526 }; 18527 var dataUriToBlob = function (uri) { 18528 return new promiseObj(function (resolve) { 18529 var _a = parseDataUri(uri), type = _a.type, data = _a.data; 18530 buildBlob(type, data).fold(function () { 18531 return resolve(new Blob([])); 18532 }, resolve); 18533 }); 18534 }; 18535 var uriToBlob = function (url) { 18536 if (url.indexOf('blob:') === 0) { 18537 return blobUriToBlob(url); 18538 } 18539 if (url.indexOf('data:') === 0) { 18540 return dataUriToBlob(url); 18541 } 18542 return null; 18543 }; 18544 var blobToDataUri = function (blob) { 18545 return new promiseObj(function (resolve) { 18546 var reader = new FileReader(); 18547 reader.onloadend = function () { 18548 resolve(reader.result); 18549 }; 18550 reader.readAsDataURL(blob); 18551 }); 18552 }; 18553 18554 var count$1 = 0; 18555 var uniqueId = function (prefix) { 18556 return (prefix || 'blobid') + count$1++; 18557 }; 18558 var imageToBlobInfo = function (blobCache, img, resolve, reject) { 18559 var base64, blobInfo; 18560 if (img.src.indexOf('blob:') === 0) { 18561 blobInfo = blobCache.getByUri(img.src); 18562 if (blobInfo) { 18563 resolve({ 18564 image: img, 18565 blobInfo: blobInfo 18566 }); 18567 } else { 18568 uriToBlob(img.src).then(function (blob) { 18569 blobToDataUri(blob).then(function (dataUri) { 18570 base64 = parseDataUri(dataUri).data; 18571 blobInfo = blobCache.create(uniqueId(), blob, base64); 18572 blobCache.add(blobInfo); 18573 resolve({ 18574 image: img, 18575 blobInfo: blobInfo 18576 }); 18577 }); 18578 }, function (err) { 18579 reject(err); 18580 }); 18581 } 18582 return; 18583 } 18584 var _a = parseDataUri(img.src), data = _a.data, type = _a.type; 18585 base64 = data; 18586 blobInfo = blobCache.getByData(base64, type); 18587 if (blobInfo) { 18588 resolve({ 18589 image: img, 18590 blobInfo: blobInfo 18591 }); 18592 } else { 18593 uriToBlob(img.src).then(function (blob) { 18594 blobInfo = blobCache.create(uniqueId(), blob, base64); 18595 blobCache.add(blobInfo); 18596 resolve({ 18597 image: img, 18598 blobInfo: blobInfo 18599 }); 18600 }, function (err) { 18601 reject(err); 18602 }); 18603 } 18604 }; 18605 var getAllImages = function (elm) { 18606 return elm ? from(elm.getElementsByTagName('img')) : []; 18607 }; 18608 var ImageScanner = function (uploadStatus, blobCache) { 18609 var cachedPromises = {}; 18610 var findAll = function (elm, predicate) { 18611 if (!predicate) { 18612 predicate = always; 18613 } 18614 var images = filter$4(getAllImages(elm), function (img) { 18615 var src = img.src; 18616 if (!Env.fileApi) { 18617 return false; 18618 } 18619 if (img.hasAttribute('data-mce-bogus')) { 18620 return false; 18621 } 18622 if (img.hasAttribute('data-mce-placeholder')) { 18623 return false; 18624 } 18625 if (!src || src === Env.transparentSrc) { 18626 return false; 18627 } 18628 if (src.indexOf('blob:') === 0) { 18629 return !uploadStatus.isUploaded(src) && predicate(img); 18630 } 18631 if (src.indexOf('data:') === 0) { 18632 return predicate(img); 18633 } 18634 return false; 18635 }); 18636 var promises = map$3(images, function (img) { 18637 if (cachedPromises[img.src] !== undefined) { 18638 return new promiseObj(function (resolve) { 18639 cachedPromises[img.src].then(function (imageInfo) { 18640 if (typeof imageInfo === 'string') { 18641 return imageInfo; 18642 } 18643 resolve({ 18644 image: img, 18645 blobInfo: imageInfo.blobInfo 18646 }); 18647 }); 18648 }); 18649 } 18650 var newPromise = new promiseObj(function (resolve, reject) { 18651 imageToBlobInfo(blobCache, img, resolve, reject); 18652 }).then(function (result) { 18653 delete cachedPromises[result.image.src]; 18654 return result; 18655 }).catch(function (error) { 18656 delete cachedPromises[img.src]; 18657 return error; 18658 }); 18659 cachedPromises[img.src] = newPromise; 18660 return newPromise; 18661 }); 18662 return promiseObj.all(promises); 18663 }; 18664 return { findAll: findAll }; 18665 }; 18666 18667 var paddEmptyNode = function (settings, args, blockElements, node) { 18668 var brPreferred = settings.padd_empty_with_br || args.insert; 18669 if (brPreferred && blockElements[node.name]) { 18670 node.empty().append(new AstNode('br', 1)).shortEnded = true; 18671 } else { 18672 node.empty().append(new AstNode('#text', 3)).value = nbsp; 18673 } 18674 }; 18675 var isPaddedWithNbsp = function (node) { 18676 return hasOnlyChild(node, '#text') && node.firstChild.value === nbsp; 18677 }; 18678 var hasOnlyChild = function (node, name) { 18679 return node && node.firstChild && node.firstChild === node.lastChild && node.firstChild.name === name; 18680 }; 18681 var isPadded = function (schema, node) { 18682 var rule = schema.getElementRule(node.name); 18683 return rule && rule.paddEmpty; 18684 }; 18685 var isEmpty = function (schema, nonEmptyElements, whitespaceElements, node) { 18686 return node.isEmpty(nonEmptyElements, whitespaceElements, function (node) { 18687 return isPadded(schema, node); 18688 }); 18689 }; 18690 var isLineBreakNode = function (node, blockElements) { 18691 return node && (has$2(blockElements, node.name) || node.name === 'br'); 18692 }; 18693 18694 var isBogusImage = function (img) { 18695 return isNonNullable(img.attr('data-mce-bogus')); 18696 }; 18697 var isInternalImageSource = function (img) { 18698 return img.attr('src') === Env.transparentSrc || isNonNullable(img.attr('data-mce-placeholder')); 18699 }; 18700 var isValidDataImg = function (img, settings) { 18701 if (settings.images_dataimg_filter) { 18702 var imgElem_1 = new Image(); 18703 imgElem_1.src = img.attr('src'); 18704 each$j(img.attributes.map, function (value, key) { 18705 imgElem_1.setAttribute(key, value); 18706 }); 18707 return settings.images_dataimg_filter(imgElem_1); 18708 } else { 18709 return true; 18710 } 18711 }; 18712 var registerBase64ImageFilter = function (parser, settings) { 18713 var blobCache = settings.blob_cache; 18714 var processImage = function (img) { 18715 var inputSrc = img.attr('src'); 18716 if (isInternalImageSource(img) || isBogusImage(img)) { 18717 return; 18718 } 18719 parseDataUri$1(inputSrc).filter(function () { 18720 return isValidDataImg(img, settings); 18721 }).bind(function (_a) { 18722 var type = _a.type, data = _a.data; 18723 return Optional.from(blobCache.getByData(data, type)).orThunk(function () { 18724 return buildBlob(type, data).map(function (blob) { 18725 var blobInfo = blobCache.create(uniqueId(), blob, data); 18726 blobCache.add(blobInfo); 18727 return blobInfo; 18728 }); 18729 }); 18730 }).each(function (blobInfo) { 18731 img.attr('src', blobInfo.blobUri()); 18732 }); 18733 }; 18734 if (blobCache) { 18735 parser.addAttributeFilter('src', function (nodes) { 18736 return each$k(nodes, processImage); 18737 }); 18738 } 18739 }; 18740 var register$1 = function (parser, settings) { 18741 var schema = parser.schema; 18742 if (settings.remove_trailing_brs) { 18743 parser.addNodeFilter('br', function (nodes, _, args) { 18744 var i; 18745 var l = nodes.length; 18746 var node; 18747 var blockElements = Tools.extend({}, schema.getBlockElements()); 18748 var nonEmptyElements = schema.getNonEmptyElements(); 18749 var parent, lastParent, prev, prevName; 18750 var whiteSpaceElements = schema.getWhiteSpaceElements(); 18751 var elementRule, textNode; 18752 blockElements.body = 1; 18753 for (i = 0; i < l; i++) { 18754 node = nodes[i]; 18755 parent = node.parent; 18756 if (blockElements[node.parent.name] && node === parent.lastChild) { 18757 prev = node.prev; 18758 while (prev) { 18759 prevName = prev.name; 18760 if (prevName !== 'span' || prev.attr('data-mce-type') !== 'bookmark') { 18761 if (prevName === 'br') { 18762 node = null; 18763 } 18764 break; 18765 } 18766 prev = prev.prev; 18767 } 18768 if (node) { 18769 node.remove(); 18770 if (isEmpty(schema, nonEmptyElements, whiteSpaceElements, parent)) { 18771 elementRule = schema.getElementRule(parent.name); 18772 if (elementRule) { 18773 if (elementRule.removeEmpty) { 18774 parent.remove(); 18775 } else if (elementRule.paddEmpty) { 18776 paddEmptyNode(settings, args, blockElements, parent); 18777 } 18778 } 18779 } 18780 } 18781 } else { 18782 lastParent = node; 18783 while (parent && parent.firstChild === lastParent && parent.lastChild === lastParent) { 18784 lastParent = parent; 18785 if (blockElements[parent.name]) { 18786 break; 18787 } 18788 parent = parent.parent; 18789 } 18790 if (lastParent === parent && settings.padd_empty_with_br !== true) { 18791 textNode = new AstNode('#text', 3); 18792 textNode.value = nbsp; 18793 node.replace(textNode); 18794 } 18795 } 18796 } 18797 }); 18798 } 18799 parser.addAttributeFilter('href', function (nodes) { 18800 var i = nodes.length; 18801 var appendRel = function (rel) { 18802 var parts = rel.split(' ').filter(function (p) { 18803 return p.length > 0; 18804 }); 18805 return parts.concat(['noopener']).sort().join(' '); 18806 }; 18807 var addNoOpener = function (rel) { 18808 var newRel = rel ? Tools.trim(rel) : ''; 18809 if (!/\b(noopener)\b/g.test(newRel)) { 18810 return appendRel(newRel); 18811 } else { 18812 return newRel; 18813 } 18814 }; 18815 if (!settings.allow_unsafe_link_target) { 18816 while (i--) { 18817 var node = nodes[i]; 18818 if (node.name === 'a' && node.attr('target') === '_blank') { 18819 node.attr('rel', addNoOpener(node.attr('rel'))); 18820 } 18821 } 18822 } 18823 }); 18824 if (!settings.allow_html_in_named_anchor) { 18825 parser.addAttributeFilter('id,name', function (nodes) { 18826 var i = nodes.length, sibling, prevSibling, parent, node; 18827 while (i--) { 18828 node = nodes[i]; 18829 if (node.name === 'a' && node.firstChild && !node.attr('href')) { 18830 parent = node.parent; 18831 sibling = node.lastChild; 18832 do { 18833 prevSibling = sibling.prev; 18834 parent.insert(sibling, node); 18835 sibling = prevSibling; 18836 } while (sibling); 18837 } 18838 } 18839 }); 18840 } 18841 if (settings.fix_list_elements) { 18842 parser.addNodeFilter('ul,ol', function (nodes) { 18843 var i = nodes.length, node, parentNode; 18844 while (i--) { 18845 node = nodes[i]; 18846 parentNode = node.parent; 18847 if (parentNode.name === 'ul' || parentNode.name === 'ol') { 18848 if (node.prev && node.prev.name === 'li') { 18849 node.prev.append(node); 18850 } else { 18851 var li = new AstNode('li', 1); 18852 li.attr('style', 'list-style-type: none'); 18853 node.wrap(li); 18854 } 18855 } 18856 } 18857 }); 18858 } 18859 if (settings.validate && schema.getValidClasses()) { 18860 parser.addAttributeFilter('class', function (nodes) { 18861 var validClasses = schema.getValidClasses(); 18862 var i = nodes.length; 18863 while (i--) { 18864 var node = nodes[i]; 18865 var classList = node.attr('class').split(' '); 18866 var classValue = ''; 18867 for (var ci = 0; ci < classList.length; ci++) { 18868 var className = classList[ci]; 18869 var valid = false; 18870 var validClassesMap = validClasses['*']; 18871 if (validClassesMap && validClassesMap[className]) { 18872 valid = true; 18873 } 18874 validClassesMap = validClasses[node.name]; 18875 if (!valid && validClassesMap && validClassesMap[className]) { 18876 valid = true; 18877 } 18878 if (valid) { 18879 if (classValue) { 18880 classValue += ' '; 18881 } 18882 classValue += className; 18883 } 18884 } 18885 if (!classValue.length) { 18886 classValue = null; 18887 } 18888 node.attr('class', classValue); 18889 } 18890 }); 18891 } 18892 registerBase64ImageFilter(parser, settings); 18893 }; 18894 18895 var makeMap = Tools.makeMap, each$6 = Tools.each, explode$2 = Tools.explode, extend$4 = Tools.extend; 18896 var DomParser = function (settings, schema) { 18897 if (schema === void 0) { 18898 schema = Schema(); 18899 } 18900 var nodeFilters = {}; 18901 var attributeFilters = []; 18902 var matchedNodes = {}; 18903 var matchedAttributes = {}; 18904 settings = settings || {}; 18905 settings.validate = 'validate' in settings ? settings.validate : true; 18906 settings.root_name = settings.root_name || 'body'; 18907 var fixInvalidChildren = function (nodes) { 18908 var nonSplitableElements = makeMap('tr,td,th,tbody,thead,tfoot,table'); 18909 var nonEmptyElements = schema.getNonEmptyElements(); 18910 var whitespaceElements = schema.getWhiteSpaceElements(); 18911 var textBlockElements = schema.getTextBlockElements(); 18912 var specialElements = schema.getSpecialElements(); 18913 var removeOrUnwrapInvalidNode = function (node, originalNodeParent) { 18914 if (originalNodeParent === void 0) { 18915 originalNodeParent = node.parent; 18916 } 18917 if (specialElements[node.name]) { 18918 node.empty().remove(); 18919 } else { 18920 var children = node.children(); 18921 for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { 18922 var childNode = children_1[_i]; 18923 if (!schema.isValidChild(originalNodeParent.name, childNode.name)) { 18924 removeOrUnwrapInvalidNode(childNode, originalNodeParent); 18925 } 18926 } 18927 node.unwrap(); 18928 } 18929 }; 18930 for (var ni = 0; ni < nodes.length; ni++) { 18931 var node = nodes[ni]; 18932 var parent_1 = void 0, newParent = void 0, tempNode = void 0; 18933 if (!node.parent || node.fixed) { 18934 continue; 18935 } 18936 if (textBlockElements[node.name] && node.parent.name === 'li') { 18937 var sibling = node.next; 18938 while (sibling) { 18939 if (textBlockElements[sibling.name]) { 18940 sibling.name = 'li'; 18941 sibling.fixed = true; 18942 node.parent.insert(sibling, node.parent); 18943 } else { 18944 break; 18945 } 18946 sibling = sibling.next; 18947 } 18948 node.unwrap(); 18949 continue; 18950 } 18951 var parents = [node]; 18952 for (parent_1 = node.parent; parent_1 && !schema.isValidChild(parent_1.name, node.name) && !nonSplitableElements[parent_1.name]; parent_1 = parent_1.parent) { 18953 parents.push(parent_1); 18954 } 18955 if (parent_1 && parents.length > 1) { 18956 if (schema.isValidChild(parent_1.name, node.name)) { 18957 parents.reverse(); 18958 newParent = filterNode(parents[0].clone()); 18959 var currentNode = newParent; 18960 for (var i = 0; i < parents.length - 1; i++) { 18961 if (schema.isValidChild(currentNode.name, parents[i].name)) { 18962 tempNode = filterNode(parents[i].clone()); 18963 currentNode.append(tempNode); 18964 } else { 18965 tempNode = currentNode; 18966 } 18967 for (var childNode = parents[i].firstChild; childNode && childNode !== parents[i + 1];) { 18968 var nextNode = childNode.next; 18969 tempNode.append(childNode); 18970 childNode = nextNode; 18971 } 18972 currentNode = tempNode; 18973 } 18974 if (!isEmpty(schema, nonEmptyElements, whitespaceElements, newParent)) { 18975 parent_1.insert(newParent, parents[0], true); 18976 parent_1.insert(node, newParent); 18977 } else { 18978 parent_1.insert(node, parents[0], true); 18979 } 18980 parent_1 = parents[0]; 18981 if (isEmpty(schema, nonEmptyElements, whitespaceElements, parent_1) || hasOnlyChild(parent_1, 'br')) { 18982 parent_1.empty().remove(); 18983 } 18984 } else { 18985 removeOrUnwrapInvalidNode(node); 18986 } 18987 } else if (node.parent) { 18988 if (node.name === 'li') { 18989 var sibling = node.prev; 18990 if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) { 18991 sibling.append(node); 18992 continue; 18993 } 18994 sibling = node.next; 18995 if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) { 18996 sibling.insert(node, sibling.firstChild, true); 18997 continue; 18998 } 18999 node.wrap(filterNode(new AstNode('ul', 1))); 19000 continue; 19001 } 19002 if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) { 19003 node.wrap(filterNode(new AstNode('div', 1))); 19004 } else { 19005 removeOrUnwrapInvalidNode(node); 19006 } 19007 } 19008 } 19009 }; 19010 var filterNode = function (node) { 19011 var name = node.name; 19012 if (name in nodeFilters) { 19013 var list = matchedNodes[name]; 19014 if (list) { 19015 list.push(node); 19016 } else { 19017 matchedNodes[name] = [node]; 19018 } 19019 } 19020 var i = attributeFilters.length; 19021 while (i--) { 19022 var attrName = attributeFilters[i].name; 19023 if (attrName in node.attributes.map) { 19024 var list = matchedAttributes[attrName]; 19025 if (list) { 19026 list.push(node); 19027 } else { 19028 matchedAttributes[attrName] = [node]; 19029 } 19030 } 19031 } 19032 return node; 19033 }; 19034 var addNodeFilter = function (name, callback) { 19035 each$6(explode$2(name), function (name) { 19036 var list = nodeFilters[name]; 19037 if (!list) { 19038 nodeFilters[name] = list = []; 19039 } 19040 list.push(callback); 19041 }); 19042 }; 19043 var getNodeFilters = function () { 19044 var out = []; 19045 for (var name_1 in nodeFilters) { 19046 if (has$2(nodeFilters, name_1)) { 19047 out.push({ 19048 name: name_1, 19049 callbacks: nodeFilters[name_1] 19050 }); 19051 } 19052 } 19053 return out; 19054 }; 19055 var addAttributeFilter = function (name, callback) { 19056 each$6(explode$2(name), function (name) { 19057 var i; 19058 for (i = 0; i < attributeFilters.length; i++) { 19059 if (attributeFilters[i].name === name) { 19060 attributeFilters[i].callbacks.push(callback); 19061 return; 19062 } 19063 } 19064 attributeFilters.push({ 19065 name: name, 19066 callbacks: [callback] 19067 }); 19068 }); 19069 }; 19070 var getAttributeFilters = function () { 19071 return [].concat(attributeFilters); 19072 }; 19073 var parse = function (html, args) { 19074 var nodes, i, l, fi, fl, list, name; 19075 var invalidChildren = []; 19076 var node; 19077 var getRootBlockName = function (name) { 19078 if (name === false) { 19079 return ''; 19080 } else if (name === true) { 19081 return 'p'; 19082 } else { 19083 return name; 19084 } 19085 }; 19086 args = args || {}; 19087 matchedNodes = {}; 19088 matchedAttributes = {}; 19089 var blockElements = extend$4(makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements()); 19090 var textRootBlockElements = getTextRootBlockElements(schema); 19091 var nonEmptyElements = schema.getNonEmptyElements(); 19092 var children = schema.children; 19093 var validate = settings.validate; 19094 var forcedRootBlockName = 'forced_root_block' in args ? args.forced_root_block : settings.forced_root_block; 19095 var rootBlockName = getRootBlockName(forcedRootBlockName); 19096 var whiteSpaceElements = schema.getWhiteSpaceElements(); 19097 var startWhiteSpaceRegExp = /^[ \t\r\n]+/; 19098 var endWhiteSpaceRegExp = /[ \t\r\n]+$/; 19099 var allWhiteSpaceRegExp = /[ \t\r\n]+/g; 19100 var isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/; 19101 var isInWhiteSpacePreservedElement = has$2(whiteSpaceElements, args.context) || has$2(whiteSpaceElements, settings.root_name); 19102 var addRootBlocks = function () { 19103 var node = rootNode.firstChild, rootBlockNode = null; 19104 var trim = function (rootBlock) { 19105 if (rootBlock) { 19106 node = rootBlock.firstChild; 19107 if (node && node.type === 3) { 19108 node.value = node.value.replace(startWhiteSpaceRegExp, ''); 19109 } 19110 node = rootBlock.lastChild; 19111 if (node && node.type === 3) { 19112 node.value = node.value.replace(endWhiteSpaceRegExp, ''); 19113 } 19114 } 19115 }; 19116 if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) { 19117 return; 19118 } 19119 while (node) { 19120 var next = node.next; 19121 if (node.type === 3 || node.type === 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type')) { 19122 if (!rootBlockNode) { 19123 rootBlockNode = createNode(rootBlockName, 1); 19124 rootBlockNode.attr(settings.forced_root_block_attrs); 19125 rootNode.insert(rootBlockNode, node); 19126 rootBlockNode.append(node); 19127 } else { 19128 rootBlockNode.append(node); 19129 } 19130 } else { 19131 trim(rootBlockNode); 19132 rootBlockNode = null; 19133 } 19134 node = next; 19135 } 19136 trim(rootBlockNode); 19137 }; 19138 var createNode = function (name, type) { 19139 var node = new AstNode(name, type); 19140 var list; 19141 if (name in nodeFilters) { 19142 list = matchedNodes[name]; 19143 if (list) { 19144 list.push(node); 19145 } else { 19146 matchedNodes[name] = [node]; 19147 } 19148 } 19149 return node; 19150 }; 19151 var removeWhitespaceBefore = function (node) { 19152 var blockElements = schema.getBlockElements(); 19153 for (var textNode = node.prev; textNode && textNode.type === 3;) { 19154 var textVal = textNode.value.replace(endWhiteSpaceRegExp, ''); 19155 if (textVal.length > 0) { 19156 textNode.value = textVal; 19157 return; 19158 } 19159 var textNodeNext = textNode.next; 19160 if (textNodeNext) { 19161 if (textNodeNext.type === 3 && textNodeNext.value.length) { 19162 textNode = textNode.prev; 19163 continue; 19164 } 19165 if (!blockElements[textNodeNext.name] && textNodeNext.name !== 'script' && textNodeNext.name !== 'style') { 19166 textNode = textNode.prev; 19167 continue; 19168 } 19169 } 19170 var sibling = textNode.prev; 19171 textNode.remove(); 19172 textNode = sibling; 19173 } 19174 }; 19175 var cloneAndExcludeBlocks = function (input) { 19176 var output = {}; 19177 for (var name_2 in input) { 19178 if (name_2 !== 'li' && name_2 !== 'p') { 19179 output[name_2] = input[name_2]; 19180 } 19181 } 19182 return output; 19183 }; 19184 var isTextRootBlockEmpty = function (node) { 19185 var tempNode = node; 19186 while (isNonNullable(tempNode)) { 19187 if (tempNode.name in textRootBlockElements) { 19188 return isEmpty(schema, nonEmptyElements, whiteSpaceElements, tempNode); 19189 } else { 19190 tempNode = tempNode.parent; 19191 } 19192 } 19193 return false; 19194 }; 19195 var parser = SaxParser({ 19196 validate: validate, 19197 document: settings.document, 19198 allow_html_data_urls: settings.allow_html_data_urls, 19199 allow_svg_data_urls: settings.allow_svg_data_urls, 19200 allow_script_urls: settings.allow_script_urls, 19201 allow_conditional_comments: settings.allow_conditional_comments, 19202 preserve_cdata: settings.preserve_cdata, 19203 self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()), 19204 cdata: function (text) { 19205 node.append(createNode('#cdata', 4)).value = text; 19206 }, 19207 text: function (text, raw) { 19208 var textNode; 19209 if (!isInWhiteSpacePreservedElement) { 19210 text = text.replace(allWhiteSpaceRegExp, ' '); 19211 if (isLineBreakNode(node.lastChild, blockElements)) { 19212 text = text.replace(startWhiteSpaceRegExp, ''); 19213 } 19214 } 19215 if (text.length !== 0) { 19216 textNode = createNode('#text', 3); 19217 textNode.raw = !!raw; 19218 node.append(textNode).value = text; 19219 } 19220 }, 19221 comment: function (text) { 19222 node.append(createNode('#comment', 8)).value = text; 19223 }, 19224 pi: function (name, text) { 19225 node.append(createNode(name, 7)).value = text; 19226 removeWhitespaceBefore(node); 19227 }, 19228 doctype: function (text) { 19229 var newNode = node.append(createNode('#doctype', 10)); 19230 newNode.value = text; 19231 removeWhitespaceBefore(node); 19232 }, 19233 start: function (name, attrs, empty) { 19234 var elementRule = validate ? schema.getElementRule(name) : {}; 19235 if (elementRule) { 19236 var newNode = createNode(elementRule.outputName || name, 1); 19237 newNode.attributes = attrs; 19238 newNode.shortEnded = empty; 19239 node.append(newNode); 19240 var parent_2 = children[node.name]; 19241 if (parent_2 && children[newNode.name] && !parent_2[newNode.name]) { 19242 invalidChildren.push(newNode); 19243 } 19244 var attrFiltersLen = attributeFilters.length; 19245 while (attrFiltersLen--) { 19246 var attrName = attributeFilters[attrFiltersLen].name; 19247 if (attrName in attrs.map) { 19248 list = matchedAttributes[attrName]; 19249 if (list) { 19250 list.push(newNode); 19251 } else { 19252 matchedAttributes[attrName] = [newNode]; 19253 } 19254 } 19255 } 19256 if (blockElements[name]) { 19257 removeWhitespaceBefore(newNode); 19258 } 19259 if (!empty) { 19260 node = newNode; 19261 } 19262 if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) { 19263 isInWhiteSpacePreservedElement = true; 19264 } 19265 } 19266 }, 19267 end: function (name) { 19268 var textNode, text, sibling; 19269 var elementRule = validate ? schema.getElementRule(name) : {}; 19270 if (elementRule) { 19271 if (blockElements[name]) { 19272 if (!isInWhiteSpacePreservedElement) { 19273 textNode = node.firstChild; 19274 if (textNode && textNode.type === 3) { 19275 text = textNode.value.replace(startWhiteSpaceRegExp, ''); 19276 if (text.length > 0) { 19277 textNode.value = text; 19278 textNode = textNode.next; 19279 } else { 19280 sibling = textNode.next; 19281 textNode.remove(); 19282 textNode = sibling; 19283 while (textNode && textNode.type === 3) { 19284 text = textNode.value; 19285 sibling = textNode.next; 19286 if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) { 19287 textNode.remove(); 19288 textNode = sibling; 19289 } 19290 textNode = sibling; 19291 } 19292 } 19293 } 19294 textNode = node.lastChild; 19295 if (textNode && textNode.type === 3) { 19296 text = textNode.value.replace(endWhiteSpaceRegExp, ''); 19297 if (text.length > 0) { 19298 textNode.value = text; 19299 textNode = textNode.prev; 19300 } else { 19301 sibling = textNode.prev; 19302 textNode.remove(); 19303 textNode = sibling; 19304 while (textNode && textNode.type === 3) { 19305 text = textNode.value; 19306 sibling = textNode.prev; 19307 if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) { 19308 textNode.remove(); 19309 textNode = sibling; 19310 } 19311 textNode = sibling; 19312 } 19313 } 19314 } 19315 } 19316 } 19317 if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) { 19318 isInWhiteSpacePreservedElement = false; 19319 } 19320 var isNodeEmpty = isEmpty(schema, nonEmptyElements, whiteSpaceElements, node); 19321 var parentNode = node.parent; 19322 if (elementRule.paddInEmptyBlock && isNodeEmpty && isTextRootBlockEmpty(node)) { 19323 paddEmptyNode(settings, args, blockElements, node); 19324 } else if (elementRule.removeEmpty && isNodeEmpty) { 19325 if (blockElements[node.name]) { 19326 node.empty().remove(); 19327 } else { 19328 node.unwrap(); 19329 } 19330 } else if (elementRule.paddEmpty && (isPaddedWithNbsp(node) || isNodeEmpty)) { 19331 paddEmptyNode(settings, args, blockElements, node); 19332 } 19333 node = parentNode; 19334 } 19335 } 19336 }, schema); 19337 var rootNode = node = new AstNode(args.context || settings.root_name, 11); 19338 parser.parse(html, args.format); 19339 if (validate && invalidChildren.length) { 19340 if (!args.context) { 19341 fixInvalidChildren(invalidChildren); 19342 } else { 19343 args.invalid = true; 19344 } 19345 } 19346 if (rootBlockName && (rootNode.name === 'body' || args.isRootContent)) { 19347 addRootBlocks(); 19348 } 19349 if (!args.invalid) { 19350 for (name in matchedNodes) { 19351 if (!has$2(matchedNodes, name)) { 19352 continue; 19353 } 19354 list = nodeFilters[name]; 19355 nodes = matchedNodes[name]; 19356 fi = nodes.length; 19357 while (fi--) { 19358 if (!nodes[fi].parent) { 19359 nodes.splice(fi, 1); 19360 } 19361 } 19362 for (i = 0, l = list.length; i < l; i++) { 19363 list[i](nodes, name, args); 19364 } 19365 } 19366 for (i = 0, l = attributeFilters.length; i < l; i++) { 19367 list = attributeFilters[i]; 19368 if (list.name in matchedAttributes) { 19369 nodes = matchedAttributes[list.name]; 19370 fi = nodes.length; 19371 while (fi--) { 19372 if (!nodes[fi].parent) { 19373 nodes.splice(fi, 1); 19374 } 19375 } 19376 for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) { 19377 list.callbacks[fi](nodes, list.name, args); 19378 } 19379 } 19380 } 19381 } 19382 return rootNode; 19383 }; 19384 var exports = { 19385 schema: schema, 19386 addAttributeFilter: addAttributeFilter, 19387 getAttributeFilters: getAttributeFilters, 19388 addNodeFilter: addNodeFilter, 19389 getNodeFilters: getNodeFilters, 19390 filterNode: filterNode, 19391 parse: parse 19392 }; 19393 register$1(exports, settings); 19394 register$2(exports, settings); 19395 return exports; 19396 }; 19397 19398 var register = function (htmlParser, settings, dom) { 19399 htmlParser.addAttributeFilter('data-mce-tabindex', function (nodes, name) { 19400 var i = nodes.length; 19401 while (i--) { 19402 var node = nodes[i]; 19403 node.attr('tabindex', node.attr('data-mce-tabindex')); 19404 node.attr(name, null); 19405 } 19406 }); 19407 htmlParser.addAttributeFilter('src,href,style', function (nodes, name) { 19408 var internalName = 'data-mce-' + name; 19409 var urlConverter = settings.url_converter; 19410 var urlConverterScope = settings.url_converter_scope; 19411 var i = nodes.length; 19412 while (i--) { 19413 var node = nodes[i]; 19414 var value = node.attr(internalName); 19415 if (value !== undefined) { 19416 node.attr(name, value.length > 0 ? value : null); 19417 node.attr(internalName, null); 19418 } else { 19419 value = node.attr(name); 19420 if (name === 'style') { 19421 value = dom.serializeStyle(dom.parseStyle(value), node.name); 19422 } else if (urlConverter) { 19423 value = urlConverter.call(urlConverterScope, value, name, node.name); 19424 } 19425 node.attr(name, value.length > 0 ? value : null); 19426 } 19427 } 19428 }); 19429 htmlParser.addAttributeFilter('class', function (nodes) { 19430 var i = nodes.length; 19431 while (i--) { 19432 var node = nodes[i]; 19433 var value = node.attr('class'); 19434 if (value) { 19435 value = node.attr('class').replace(/(?:^|\s)mce-item-\w+(?!\S)/g, ''); 19436 node.attr('class', value.length > 0 ? value : null); 19437 } 19438 } 19439 }); 19440 htmlParser.addAttributeFilter('data-mce-type', function (nodes, name, args) { 19441 var i = nodes.length; 19442 while (i--) { 19443 var node = nodes[i]; 19444 if (node.attr('data-mce-type') === 'bookmark' && !args.cleanup) { 19445 var hasChildren = Optional.from(node.firstChild).exists(function (firstChild) { 19446 return !isZwsp(firstChild.value); 19447 }); 19448 if (hasChildren) { 19449 node.unwrap(); 19450 } else { 19451 node.remove(); 19452 } 19453 } 19454 } 19455 }); 19456 htmlParser.addNodeFilter('noscript', function (nodes) { 19457 var i = nodes.length; 19458 while (i--) { 19459 var node = nodes[i].firstChild; 19460 if (node) { 19461 node.value = Entities.decode(node.value); 19462 } 19463 } 19464 }); 19465 htmlParser.addNodeFilter('script,style', function (nodes, name) { 19466 var trim = function (value) { 19467 return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n').replace(/^[\r\n]*|[\r\n]*$/g, '').replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '').replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, ''); 19468 }; 19469 var i = nodes.length; 19470 while (i--) { 19471 var node = nodes[i]; 19472 var value = node.firstChild ? node.firstChild.value : ''; 19473 if (name === 'script') { 19474 var type = node.attr('type'); 19475 if (type) { 19476 node.attr('type', type === 'mce-no/type' ? null : type.replace(/^mce\-/, '')); 19477 } 19478 if (settings.element_format === 'xhtml' && value.length > 0) { 19479 node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>'; 19480 } 19481 } else { 19482 if (settings.element_format === 'xhtml' && value.length > 0) { 19483 node.firstChild.value = '<!--\n' + trim(value) + '\n-->'; 19484 } 19485 } 19486 } 19487 }); 19488 htmlParser.addNodeFilter('#comment', function (nodes) { 19489 var i = nodes.length; 19490 while (i--) { 19491 var node = nodes[i]; 19492 if (settings.preserve_cdata && node.value.indexOf('[CDATA[') === 0) { 19493 node.name = '#cdata'; 19494 node.type = 4; 19495 node.value = dom.decode(node.value.replace(/^\[CDATA\[|\]\]$/g, '')); 19496 } else if (node.value.indexOf('mce:protected ') === 0) { 19497 node.name = '#text'; 19498 node.type = 3; 19499 node.raw = true; 19500 node.value = unescape(node.value).substr(14); 19501 } 19502 } 19503 }); 19504 htmlParser.addNodeFilter('xml:namespace,input', function (nodes, name) { 19505 var i = nodes.length; 19506 while (i--) { 19507 var node = nodes[i]; 19508 if (node.type === 7) { 19509 node.remove(); 19510 } else if (node.type === 1) { 19511 if (name === 'input' && !node.attr('type')) { 19512 node.attr('type', 'text'); 19513 } 19514 } 19515 } 19516 }); 19517 htmlParser.addAttributeFilter('data-mce-type', function (nodes) { 19518 each$k(nodes, function (node) { 19519 if (node.attr('data-mce-type') === 'format-caret') { 19520 if (node.isEmpty(htmlParser.schema.getNonEmptyElements())) { 19521 node.remove(); 19522 } else { 19523 node.unwrap(); 19524 } 19525 } 19526 }); 19527 }); 19528 htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style,' + 'data-mce-selected,data-mce-expando,' + 'data-mce-type,data-mce-resize,data-mce-placeholder', function (nodes, name) { 19529 var i = nodes.length; 19530 while (i--) { 19531 nodes[i].attr(name, null); 19532 } 19533 }); 19534 }; 19535 var trimTrailingBr = function (rootNode) { 19536 var isBr = function (node) { 19537 return node && node.name === 'br'; 19538 }; 19539 var brNode1 = rootNode.lastChild; 19540 if (isBr(brNode1)) { 19541 var brNode2 = brNode1.prev; 19542 if (isBr(brNode2)) { 19543 brNode1.remove(); 19544 brNode2.remove(); 19545 } 19546 } 19547 }; 19548 19549 var preProcess = function (editor, node, args) { 19550 var oldDoc; 19551 var dom = editor.dom; 19552 var clonedNode = node.cloneNode(true); 19553 var impl = document.implementation; 19554 if (impl.createHTMLDocument) { 19555 var doc_1 = impl.createHTMLDocument(''); 19556 Tools.each(clonedNode.nodeName === 'BODY' ? clonedNode.childNodes : [clonedNode], function (node) { 19557 doc_1.body.appendChild(doc_1.importNode(node, true)); 19558 }); 19559 if (clonedNode.nodeName !== 'BODY') { 19560 clonedNode = doc_1.body.firstChild; 19561 } else { 19562 clonedNode = doc_1.body; 19563 } 19564 oldDoc = dom.doc; 19565 dom.doc = doc_1; 19566 } 19567 firePreProcess(editor, __assign(__assign({}, args), { node: clonedNode })); 19568 if (oldDoc) { 19569 dom.doc = oldDoc; 19570 } 19571 return clonedNode; 19572 }; 19573 var shouldFireEvent = function (editor, args) { 19574 return editor && editor.hasEventListeners('PreProcess') && !args.no_events; 19575 }; 19576 var process = function (editor, node, args) { 19577 return shouldFireEvent(editor, args) ? preProcess(editor, node, args) : node; 19578 }; 19579 19580 var addTempAttr = function (htmlParser, tempAttrs, name) { 19581 if (Tools.inArray(tempAttrs, name) === -1) { 19582 htmlParser.addAttributeFilter(name, function (nodes, name) { 19583 var i = nodes.length; 19584 while (i--) { 19585 nodes[i].attr(name, null); 19586 } 19587 }); 19588 tempAttrs.push(name); 19589 } 19590 }; 19591 var postProcess = function (editor, args, content) { 19592 if (!args.no_events && editor) { 19593 var outArgs = firePostProcess(editor, __assign(__assign({}, args), { content: content })); 19594 return outArgs.content; 19595 } else { 19596 return content; 19597 } 19598 }; 19599 var getHtmlFromNode = function (dom, node, args) { 19600 var html = trim$2(args.getInner ? node.innerHTML : dom.getOuterHTML(node)); 19601 return args.selection || isWsPreserveElement(SugarElement.fromDom(node)) ? html : Tools.trim(html); 19602 }; 19603 var parseHtml = function (htmlParser, html, args) { 19604 var parserArgs = args.selection ? __assign({ forced_root_block: false }, args) : args; 19605 var rootNode = htmlParser.parse(html, parserArgs); 19606 trimTrailingBr(rootNode); 19607 return rootNode; 19608 }; 19609 var serializeNode = function (settings, schema, node) { 19610 var htmlSerializer = HtmlSerializer(settings, schema); 19611 return htmlSerializer.serialize(node); 19612 }; 19613 var toHtml = function (editor, settings, schema, rootNode, args) { 19614 var content = serializeNode(settings, schema, rootNode); 19615 return postProcess(editor, args, content); 19616 }; 19617 var DomSerializerImpl = function (settings, editor) { 19618 var tempAttrs = ['data-mce-selected']; 19619 var dom = editor && editor.dom ? editor.dom : DOMUtils.DOM; 19620 var schema = editor && editor.schema ? editor.schema : Schema(settings); 19621 settings.entity_encoding = settings.entity_encoding || 'named'; 19622 settings.remove_trailing_brs = 'remove_trailing_brs' in settings ? settings.remove_trailing_brs : true; 19623 var htmlParser = DomParser(settings, schema); 19624 register(htmlParser, settings, dom); 19625 var serialize = function (node, parserArgs) { 19626 if (parserArgs === void 0) { 19627 parserArgs = {}; 19628 } 19629 var args = __assign({ format: 'html' }, parserArgs); 19630 var targetNode = process(editor, node, args); 19631 var html = getHtmlFromNode(dom, targetNode, args); 19632 var rootNode = parseHtml(htmlParser, html, args); 19633 return args.format === 'tree' ? rootNode : toHtml(editor, settings, schema, rootNode, args); 19634 }; 19635 return { 19636 schema: schema, 19637 addNodeFilter: htmlParser.addNodeFilter, 19638 addAttributeFilter: htmlParser.addAttributeFilter, 19639 serialize: serialize, 19640 addRules: schema.addValidElements, 19641 setRules: schema.setValidElements, 19642 addTempAttr: curry(addTempAttr, htmlParser, tempAttrs), 19643 getTempAttrs: constant(tempAttrs), 19644 getNodeFilters: htmlParser.getNodeFilters, 19645 getAttributeFilters: htmlParser.getAttributeFilters 19646 }; 19647 }; 19648 19649 var DomSerializer = function (settings, editor) { 19650 var domSerializer = DomSerializerImpl(settings, editor); 19651 return { 19652 schema: domSerializer.schema, 19653 addNodeFilter: domSerializer.addNodeFilter, 19654 addAttributeFilter: domSerializer.addAttributeFilter, 19655 serialize: domSerializer.serialize, 19656 addRules: domSerializer.addRules, 19657 setRules: domSerializer.setRules, 19658 addTempAttr: domSerializer.addTempAttr, 19659 getTempAttrs: domSerializer.getTempAttrs, 19660 getNodeFilters: domSerializer.getNodeFilters, 19661 getAttributeFilters: domSerializer.getAttributeFilters 19662 }; 19663 }; 19664 19665 var defaultFormat = 'html'; 19666 var getContent = function (editor, args) { 19667 if (args === void 0) { 19668 args = {}; 19669 } 19670 var format = args.format ? args.format : defaultFormat; 19671 return getContent$2(editor, args, format); 19672 }; 19673 19674 var setContent = function (editor, content, args) { 19675 if (args === void 0) { 19676 args = {}; 19677 } 19678 return setContent$2(editor, content, args); 19679 }; 19680 19681 var DOM$7 = DOMUtils.DOM; 19682 var restoreOriginalStyles = function (editor) { 19683 DOM$7.setStyle(editor.id, 'display', editor.orgDisplay); 19684 }; 19685 var safeDestroy = function (x) { 19686 return Optional.from(x).each(function (x) { 19687 return x.destroy(); 19688 }); 19689 }; 19690 var clearDomReferences = function (editor) { 19691 editor.contentAreaContainer = editor.formElement = editor.container = editor.editorContainer = null; 19692 editor.bodyElement = editor.contentDocument = editor.contentWindow = null; 19693 editor.iframeElement = editor.targetElm = null; 19694 if (editor.selection) { 19695 editor.selection = editor.selection.win = editor.selection.dom = editor.selection.dom.doc = null; 19696 } 19697 }; 19698 var restoreForm = function (editor) { 19699 var form = editor.formElement; 19700 if (form) { 19701 if (form._mceOldSubmit) { 19702 form.submit = form._mceOldSubmit; 19703 form._mceOldSubmit = null; 19704 } 19705 DOM$7.unbind(form, 'submit reset', editor.formEventDelegate); 19706 } 19707 }; 19708 var remove = function (editor) { 19709 if (!editor.removed) { 19710 var _selectionOverrides = editor._selectionOverrides, editorUpload = editor.editorUpload; 19711 var body = editor.getBody(); 19712 var element = editor.getElement(); 19713 if (body) { 19714 editor.save({ is_removing: true }); 19715 } 19716 editor.removed = true; 19717 editor.unbindAllNativeEvents(); 19718 if (editor.hasHiddenInput && element) { 19719 DOM$7.remove(element.nextSibling); 19720 } 19721 fireRemove(editor); 19722 editor.editorManager.remove(editor); 19723 if (!editor.inline && body) { 19724 restoreOriginalStyles(editor); 19725 } 19726 fireDetach(editor); 19727 DOM$7.remove(editor.getContainer()); 19728 safeDestroy(_selectionOverrides); 19729 safeDestroy(editorUpload); 19730 editor.destroy(); 19731 } 19732 }; 19733 var destroy = function (editor, automatic) { 19734 var selection = editor.selection, dom = editor.dom; 19735 if (editor.destroyed) { 19736 return; 19737 } 19738 if (!automatic && !editor.removed) { 19739 editor.remove(); 19740 return; 19741 } 19742 if (!automatic) { 19743 editor.editorManager.off('beforeunload', editor._beforeUnload); 19744 if (editor.theme && editor.theme.destroy) { 19745 editor.theme.destroy(); 19746 } 19747 safeDestroy(selection); 19748 safeDestroy(dom); 19749 } 19750 restoreForm(editor); 19751 clearDomReferences(editor); 19752 editor.destroyed = true; 19753 }; 19754 19755 var deep = function (old, nu) { 19756 var bothObjects = isObject(old) && isObject(nu); 19757 return bothObjects ? deepMerge(old, nu) : nu; 19758 }; 19759 var baseMerge = function (merger) { 19760 return function () { 19761 var objects = []; 19762 for (var _i = 0; _i < arguments.length; _i++) { 19763 objects[_i] = arguments[_i]; 19764 } 19765 if (objects.length === 0) { 19766 throw new Error('Can\'t merge zero objects'); 19767 } 19768 var ret = {}; 19769 for (var j = 0; j < objects.length; j++) { 19770 var curObject = objects[j]; 19771 for (var key in curObject) { 19772 if (has$2(curObject, key)) { 19773 ret[key] = merger(ret[key], curObject[key]); 19774 } 19775 } 19776 } 19777 return ret; 19778 }; 19779 }; 19780 var deepMerge = baseMerge(deep); 19781 19782 var deprecatedSettings = ('autoresize_on_init,content_editable_state,convert_fonts_to_spans,inline_styles,padd_empty_with_br,block_elements,' + 'boolean_attributes,editor_deselector,editor_selector,elements,file_browser_callback_types,filepicker_validator_handler,' + 'force_hex_style_colors,force_p_newlines,gecko_spellcheck,images_dataimg_filter,media_scripts,mode,move_caret_before_on_enter_elements,' + 'non_empty_elements,self_closing_elements,short_ended_elements,special,spellchecker_select_languages,spellchecker_whitelist,' + 'tab_focus,table_responsive_width,text_block_elements,text_inline_elements,toolbar_drawer,types,validate,whitespace_elements,' + 'paste_word_valid_elements,paste_retain_style_properties,paste_convert_word_fake_lists').split(','); 19783 var deprecatedPlugins = 'bbcode,colorpicker,contextmenu,fullpage,legacyoutput,spellchecker,textcolor'.split(','); 19784 var movedToPremiumPlugins = 'imagetools,toc'.split(','); 19785 var getDeprecatedSettings = function (settings) { 19786 var settingNames = filter$4(deprecatedSettings, function (setting) { 19787 return has$2(settings, setting); 19788 }); 19789 var forcedRootBlock = settings.forced_root_block; 19790 if (forcedRootBlock === false || forcedRootBlock === '') { 19791 settingNames.push('forced_root_block (false only)'); 19792 } 19793 return sort(settingNames); 19794 }; 19795 var getDeprecatedPlugins = function (settings) { 19796 var plugins = Tools.makeMap(settings.plugins, ' '); 19797 var hasPlugin = function (plugin) { 19798 return has$2(plugins, plugin); 19799 }; 19800 var pluginNames = __spreadArray(__spreadArray([], filter$4(deprecatedPlugins, hasPlugin), true), bind(movedToPremiumPlugins, function (plugin) { 19801 return hasPlugin(plugin) ? [plugin + ' (moving to premium)'] : []; 19802 }), true); 19803 return sort(pluginNames); 19804 }; 19805 var logDeprecationsWarning = function (rawSettings, finalSettings) { 19806 var deprecatedSettings = getDeprecatedSettings(rawSettings); 19807 var deprecatedPlugins = getDeprecatedPlugins(finalSettings); 19808 var hasDeprecatedPlugins = deprecatedPlugins.length > 0; 19809 var hasDeprecatedSettings = deprecatedSettings.length > 0; 19810 var isLegacyMobileTheme = finalSettings.theme === 'mobile'; 19811 if (hasDeprecatedPlugins || hasDeprecatedSettings || isLegacyMobileTheme) { 19812 var listJoiner = '\n- '; 19813 var themesMessage = isLegacyMobileTheme ? '\n\nThemes:' + listJoiner + 'mobile' : ''; 19814 var pluginsMessage = hasDeprecatedPlugins ? '\n\nPlugins:' + listJoiner + deprecatedPlugins.join(listJoiner) : ''; 19815 var settingsMessage = hasDeprecatedSettings ? '\n\nSettings:' + listJoiner + deprecatedSettings.join(listJoiner) : ''; 19816 console.warn('The following deprecated features are currently enabled, these will be removed in TinyMCE 6.0. ' + 'See https://www.tiny.cloud/docs/release-notes/6.0-upcoming-changes/ for more information.' + themesMessage + pluginsMessage + settingsMessage); 19817 } 19818 }; 19819 19820 var sectionResult = function (sections, settings) { 19821 return { 19822 sections: constant(sections), 19823 settings: constant(settings) 19824 }; 19825 }; 19826 var deviceDetection = detect().deviceType; 19827 var isTouch = deviceDetection.isTouch(); 19828 var isPhone = deviceDetection.isPhone(); 19829 var isTablet = deviceDetection.isTablet(); 19830 var legacyMobilePlugins = [ 19831 'lists', 19832 'autolink', 19833 'autosave' 19834 ]; 19835 var defaultTouchSettings = { 19836 table_grid: false, 19837 object_resizing: false, 19838 resize: false 19839 }; 19840 var normalizePlugins = function (plugins) { 19841 var pluginNames = isArray$1(plugins) ? plugins.join(' ') : plugins; 19842 var trimmedPlugins = map$3(isString$1(pluginNames) ? pluginNames.split(' ') : [], trim$4); 19843 return filter$4(trimmedPlugins, function (item) { 19844 return item.length > 0; 19845 }); 19846 }; 19847 var filterLegacyMobilePlugins = function (plugins) { 19848 return filter$4(plugins, curry(contains$3, legacyMobilePlugins)); 19849 }; 19850 var extractSections = function (keys, settings) { 19851 var result = bifilter(settings, function (value, key) { 19852 return contains$3(keys, key); 19853 }); 19854 return sectionResult(result.t, result.f); 19855 }; 19856 var getSection = function (sectionResult, name, defaults) { 19857 if (defaults === void 0) { 19858 defaults = {}; 19859 } 19860 var sections = sectionResult.sections(); 19861 var sectionSettings = get$9(sections, name).getOr({}); 19862 return Tools.extend({}, defaults, sectionSettings); 19863 }; 19864 var hasSection = function (sectionResult, name) { 19865 return has$2(sectionResult.sections(), name); 19866 }; 19867 var isSectionTheme = function (sectionResult, name, theme) { 19868 var section = sectionResult.sections(); 19869 return hasSection(sectionResult, name) && section[name].theme === theme; 19870 }; 19871 var getSectionConfig = function (sectionResult, name) { 19872 return hasSection(sectionResult, name) ? sectionResult.sections()[name] : {}; 19873 }; 19874 var getToolbarMode = function (settings, defaultVal) { 19875 return get$9(settings, 'toolbar_mode').orThunk(function () { 19876 return get$9(settings, 'toolbar_drawer').map(function (val) { 19877 return val === false ? 'wrap' : val; 19878 }); 19879 }).getOr(defaultVal); 19880 }; 19881 var getDefaultSettings = function (settings, id, documentBaseUrl, isTouch, editor) { 19882 var baseDefaults = { 19883 id: id, 19884 theme: 'silver', 19885 toolbar_mode: getToolbarMode(settings, 'floating'), 19886 plugins: '', 19887 document_base_url: documentBaseUrl, 19888 add_form_submit_trigger: true, 19889 submit_patch: true, 19890 add_unload_trigger: true, 19891 convert_urls: true, 19892 relative_urls: true, 19893 remove_script_host: true, 19894 object_resizing: true, 19895 doctype: '<!DOCTYPE html>', 19896 visual: true, 19897 font_size_legacy_values: 'xx-small,small,medium,large,x-large,xx-large,300%', 19898 forced_root_block: 'p', 19899 hidden_input: true, 19900 inline_styles: true, 19901 convert_fonts_to_spans: true, 19902 indent: true, 19903 indent_before: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist', 19904 indent_after: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist', 19905 entity_encoding: 'named', 19906 url_converter: editor.convertURL, 19907 url_converter_scope: editor 19908 }; 19909 return __assign(__assign({}, baseDefaults), isTouch ? defaultTouchSettings : {}); 19910 }; 19911 var getDefaultMobileSettings = function (mobileSettings, isPhone) { 19912 var defaultMobileSettings = { 19913 resize: false, 19914 toolbar_mode: getToolbarMode(mobileSettings, 'scrolling'), 19915 toolbar_sticky: false 19916 }; 19917 var defaultPhoneSettings = { menubar: false }; 19918 return __assign(__assign(__assign({}, defaultTouchSettings), defaultMobileSettings), isPhone ? defaultPhoneSettings : {}); 19919 }; 19920 var getExternalPlugins = function (overrideSettings, settings) { 19921 var userDefinedExternalPlugins = settings.external_plugins ? settings.external_plugins : {}; 19922 if (overrideSettings && overrideSettings.external_plugins) { 19923 return Tools.extend({}, overrideSettings.external_plugins, userDefinedExternalPlugins); 19924 } else { 19925 return userDefinedExternalPlugins; 19926 } 19927 }; 19928 var combinePlugins = function (forcedPlugins, plugins) { 19929 return [].concat(normalizePlugins(forcedPlugins)).concat(normalizePlugins(plugins)); 19930 }; 19931 var getPlatformPlugins = function (isMobileDevice, sectionResult, desktopPlugins, mobilePlugins) { 19932 if (isMobileDevice && isSectionTheme(sectionResult, 'mobile', 'mobile')) { 19933 return filterLegacyMobilePlugins(mobilePlugins); 19934 } else if (isMobileDevice && hasSection(sectionResult, 'mobile')) { 19935 return mobilePlugins; 19936 } else { 19937 return desktopPlugins; 19938 } 19939 }; 19940 var processPlugins = function (isMobileDevice, sectionResult, defaultOverrideSettings, settings) { 19941 var forcedPlugins = normalizePlugins(defaultOverrideSettings.forced_plugins); 19942 var desktopPlugins = normalizePlugins(settings.plugins); 19943 var mobileConfig = getSectionConfig(sectionResult, 'mobile'); 19944 var mobilePlugins = mobileConfig.plugins ? normalizePlugins(mobileConfig.plugins) : desktopPlugins; 19945 var platformPlugins = getPlatformPlugins(isMobileDevice, sectionResult, desktopPlugins, mobilePlugins); 19946 var combinedPlugins = combinePlugins(forcedPlugins, platformPlugins); 19947 if (Env.browser.isIE() && contains$3(combinedPlugins, 'rtc')) { 19948 throw new Error('RTC plugin is not supported on IE 11.'); 19949 } 19950 return Tools.extend(settings, { plugins: combinedPlugins.join(' ') }); 19951 }; 19952 var isOnMobile = function (isMobileDevice, sectionResult) { 19953 return isMobileDevice && hasSection(sectionResult, 'mobile'); 19954 }; 19955 var combineSettings = function (isMobileDevice, isPhone, defaultSettings, defaultOverrideSettings, settings) { 19956 var defaultDeviceSettings = isMobileDevice ? { mobile: getDefaultMobileSettings(settings.mobile || {}, isPhone) } : {}; 19957 var sectionResult = extractSections(['mobile'], deepMerge(defaultDeviceSettings, settings)); 19958 var extendedSettings = Tools.extend(defaultSettings, defaultOverrideSettings, sectionResult.settings(), isOnMobile(isMobileDevice, sectionResult) ? getSection(sectionResult, 'mobile') : {}, { 19959 validate: true, 19960 external_plugins: getExternalPlugins(defaultOverrideSettings, sectionResult.settings()) 19961 }); 19962 return processPlugins(isMobileDevice, sectionResult, defaultOverrideSettings, extendedSettings); 19963 }; 19964 var getEditorSettings = function (editor, id, documentBaseUrl, defaultOverrideSettings, settings) { 19965 var defaultSettings = getDefaultSettings(settings, id, documentBaseUrl, isTouch, editor); 19966 var finalSettings = combineSettings(isPhone || isTablet, isPhone, defaultSettings, defaultOverrideSettings, settings); 19967 if (finalSettings.deprecation_warnings !== false) { 19968 logDeprecationsWarning(settings, finalSettings); 19969 } 19970 return finalSettings; 19971 }; 19972 var getFiltered = function (predicate, editor, name) { 19973 return Optional.from(editor.settings[name]).filter(predicate); 19974 }; 19975 var getParamObject = function (value) { 19976 var output = {}; 19977 if (typeof value === 'string') { 19978 each$k(value.indexOf('=') > 0 ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value.split(','), function (val) { 19979 var arr = val.split('='); 19980 if (arr.length > 1) { 19981 output[Tools.trim(arr[0])] = Tools.trim(arr[1]); 19982 } else { 19983 output[Tools.trim(arr[0])] = Tools.trim(arr[0]); 19984 } 19985 }); 19986 } else { 19987 output = value; 19988 } 19989 return output; 19990 }; 19991 var isArrayOf = function (p) { 19992 return function (a) { 19993 return isArray$1(a) && forall(a, p); 19994 }; 19995 }; 19996 var getParam = function (editor, name, defaultVal, type) { 19997 var value = name in editor.settings ? editor.settings[name] : defaultVal; 19998 if (type === 'hash') { 19999 return getParamObject(value); 20000 } else if (type === 'string') { 20001 return getFiltered(isString$1, editor, name).getOr(defaultVal); 20002 } else if (type === 'number') { 20003 return getFiltered(isNumber, editor, name).getOr(defaultVal); 20004 } else if (type === 'boolean') { 20005 return getFiltered(isBoolean, editor, name).getOr(defaultVal); 20006 } else if (type === 'object') { 20007 return getFiltered(isObject, editor, name).getOr(defaultVal); 20008 } else if (type === 'array') { 20009 return getFiltered(isArray$1, editor, name).getOr(defaultVal); 20010 } else if (type === 'string[]') { 20011 return getFiltered(isArrayOf(isString$1), editor, name).getOr(defaultVal); 20012 } else if (type === 'function') { 20013 return getFiltered(isFunction, editor, name).getOr(defaultVal); 20014 } else { 20015 return value; 20016 } 20017 }; 20018 20019 var CreateIconManager = function () { 20020 var lookup = {}; 20021 var add = function (id, iconPack) { 20022 lookup[id] = iconPack; 20023 }; 20024 var get = function (id) { 20025 if (lookup[id]) { 20026 return lookup[id]; 20027 } 20028 return { icons: {} }; 20029 }; 20030 var has = function (id) { 20031 return has$2(lookup, id); 20032 }; 20033 return { 20034 add: add, 20035 get: get, 20036 has: has 20037 }; 20038 }; 20039 var IconManager = CreateIconManager(); 20040 20041 var getProp = function (propName, elm) { 20042 var rawElm = elm.dom; 20043 return rawElm[propName]; 20044 }; 20045 var getComputedSizeProp = function (propName, elm) { 20046 return parseInt(get$5(elm, propName), 10); 20047 }; 20048 var getClientWidth = curry(getProp, 'clientWidth'); 20049 var getClientHeight = curry(getProp, 'clientHeight'); 20050 var getMarginTop = curry(getComputedSizeProp, 'margin-top'); 20051 var getMarginLeft = curry(getComputedSizeProp, 'margin-left'); 20052 var getBoundingClientRect = function (elm) { 20053 return elm.dom.getBoundingClientRect(); 20054 }; 20055 var isInsideElementContentArea = function (bodyElm, clientX, clientY) { 20056 var clientWidth = getClientWidth(bodyElm); 20057 var clientHeight = getClientHeight(bodyElm); 20058 return clientX >= 0 && clientY >= 0 && clientX <= clientWidth && clientY <= clientHeight; 20059 }; 20060 var transpose = function (inline, elm, clientX, clientY) { 20061 var clientRect = getBoundingClientRect(elm); 20062 var deltaX = inline ? clientRect.left + elm.dom.clientLeft + getMarginLeft(elm) : 0; 20063 var deltaY = inline ? clientRect.top + elm.dom.clientTop + getMarginTop(elm) : 0; 20064 var x = clientX - deltaX; 20065 var y = clientY - deltaY; 20066 return { 20067 x: x, 20068 y: y 20069 }; 20070 }; 20071 var isXYInContentArea = function (editor, clientX, clientY) { 20072 var bodyElm = SugarElement.fromDom(editor.getBody()); 20073 var targetElm = editor.inline ? bodyElm : documentElement(bodyElm); 20074 var transposedPoint = transpose(editor.inline, targetElm, clientX, clientY); 20075 return isInsideElementContentArea(targetElm, transposedPoint.x, transposedPoint.y); 20076 }; 20077 var fromDomSafe = function (node) { 20078 return Optional.from(node).map(SugarElement.fromDom); 20079 }; 20080 var isEditorAttachedToDom = function (editor) { 20081 var rawContainer = editor.inline ? editor.getBody() : editor.getContentAreaContainer(); 20082 return fromDomSafe(rawContainer).map(inBody).getOr(false); 20083 }; 20084 20085 var NotificationManagerImpl = function () { 20086 var unimplemented = function () { 20087 throw new Error('Theme did not provide a NotificationManager implementation.'); 20088 }; 20089 return { 20090 open: unimplemented, 20091 close: unimplemented, 20092 reposition: unimplemented, 20093 getArgs: unimplemented 20094 }; 20095 }; 20096 20097 var NotificationManager = function (editor) { 20098 var notifications = []; 20099 var getImplementation = function () { 20100 var theme = editor.theme; 20101 return theme && theme.getNotificationManagerImpl ? theme.getNotificationManagerImpl() : NotificationManagerImpl(); 20102 }; 20103 var getTopNotification = function () { 20104 return Optional.from(notifications[0]); 20105 }; 20106 var isEqual = function (a, b) { 20107 return a.type === b.type && a.text === b.text && !a.progressBar && !a.timeout && !b.progressBar && !b.timeout; 20108 }; 20109 var reposition = function () { 20110 if (notifications.length > 0) { 20111 getImplementation().reposition(notifications); 20112 } 20113 }; 20114 var addNotification = function (notification) { 20115 notifications.push(notification); 20116 }; 20117 var closeNotification = function (notification) { 20118 findIndex$2(notifications, function (otherNotification) { 20119 return otherNotification === notification; 20120 }).each(function (index) { 20121 notifications.splice(index, 1); 20122 }); 20123 }; 20124 var open = function (spec, fireEvent) { 20125 if (fireEvent === void 0) { 20126 fireEvent = true; 20127 } 20128 if (editor.removed || !isEditorAttachedToDom(editor)) { 20129 return; 20130 } 20131 if (fireEvent) { 20132 editor.fire('BeforeOpenNotification', { notification: spec }); 20133 } 20134 return find$3(notifications, function (notification) { 20135 return isEqual(getImplementation().getArgs(notification), spec); 20136 }).getOrThunk(function () { 20137 editor.editorManager.setActive(editor); 20138 var notification = getImplementation().open(spec, function () { 20139 closeNotification(notification); 20140 reposition(); 20141 getTopNotification().fold(function () { 20142 return editor.focus(); 20143 }, function (top) { 20144 return focus$1(SugarElement.fromDom(top.getEl())); 20145 }); 20146 }); 20147 addNotification(notification); 20148 reposition(); 20149 editor.fire('OpenNotification', { notification: __assign({}, notification) }); 20150 return notification; 20151 }); 20152 }; 20153 var close = function () { 20154 getTopNotification().each(function (notification) { 20155 getImplementation().close(notification); 20156 closeNotification(notification); 20157 reposition(); 20158 }); 20159 }; 20160 var getNotifications = constant(notifications); 20161 var registerEvents = function (editor) { 20162 editor.on('SkinLoaded', function () { 20163 var serviceMessage = getServiceMessage(editor); 20164 if (serviceMessage) { 20165 open({ 20166 text: serviceMessage, 20167 type: 'warning', 20168 timeout: 0 20169 }, false); 20170 } 20171 reposition(); 20172 }); 20173 editor.on('show ResizeEditor ResizeWindow NodeChange', function () { 20174 Delay.requestAnimationFrame(reposition); 20175 }); 20176 editor.on('remove', function () { 20177 each$k(notifications.slice(), function (notification) { 20178 getImplementation().close(notification); 20179 }); 20180 }); 20181 }; 20182 registerEvents(editor); 20183 return { 20184 open: open, 20185 close: close, 20186 getNotifications: getNotifications 20187 }; 20188 }; 20189 20190 var PluginManager = AddOnManager.PluginManager; 20191 20192 var ThemeManager = AddOnManager.ThemeManager; 20193 20194 function WindowManagerImpl () { 20195 var unimplemented = function () { 20196 throw new Error('Theme did not provide a WindowManager implementation.'); 20197 }; 20198 return { 20199 open: unimplemented, 20200 openUrl: unimplemented, 20201 alert: unimplemented, 20202 confirm: unimplemented, 20203 close: unimplemented, 20204 getParams: unimplemented, 20205 setParams: unimplemented 20206 }; 20207 } 20208 20209 var WindowManager = function (editor) { 20210 var dialogs = []; 20211 var getImplementation = function () { 20212 var theme = editor.theme; 20213 return theme && theme.getWindowManagerImpl ? theme.getWindowManagerImpl() : WindowManagerImpl(); 20214 }; 20215 var funcBind = function (scope, f) { 20216 return function () { 20217 var args = []; 20218 for (var _i = 0; _i < arguments.length; _i++) { 20219 args[_i] = arguments[_i]; 20220 } 20221 return f ? f.apply(scope, args) : undefined; 20222 }; 20223 }; 20224 var fireOpenEvent = function (dialog) { 20225 editor.fire('OpenWindow', { dialog: dialog }); 20226 }; 20227 var fireCloseEvent = function (dialog) { 20228 editor.fire('CloseWindow', { dialog: dialog }); 20229 }; 20230 var addDialog = function (dialog) { 20231 dialogs.push(dialog); 20232 fireOpenEvent(dialog); 20233 }; 20234 var closeDialog = function (dialog) { 20235 fireCloseEvent(dialog); 20236 dialogs = filter$4(dialogs, function (otherDialog) { 20237 return otherDialog !== dialog; 20238 }); 20239 if (dialogs.length === 0) { 20240 editor.focus(); 20241 } 20242 }; 20243 var getTopDialog = function () { 20244 return Optional.from(dialogs[dialogs.length - 1]); 20245 }; 20246 var storeSelectionAndOpenDialog = function (openDialog) { 20247 editor.editorManager.setActive(editor); 20248 store(editor); 20249 var dialog = openDialog(); 20250 addDialog(dialog); 20251 return dialog; 20252 }; 20253 var open = function (args, params) { 20254 return storeSelectionAndOpenDialog(function () { 20255 return getImplementation().open(args, params, closeDialog); 20256 }); 20257 }; 20258 var openUrl = function (args) { 20259 return storeSelectionAndOpenDialog(function () { 20260 return getImplementation().openUrl(args, closeDialog); 20261 }); 20262 }; 20263 var alert = function (message, callback, scope) { 20264 var windowManagerImpl = getImplementation(); 20265 windowManagerImpl.alert(message, funcBind(scope ? scope : windowManagerImpl, callback)); 20266 }; 20267 var confirm = function (message, callback, scope) { 20268 var windowManagerImpl = getImplementation(); 20269 windowManagerImpl.confirm(message, funcBind(scope ? scope : windowManagerImpl, callback)); 20270 }; 20271 var close = function () { 20272 getTopDialog().each(function (dialog) { 20273 getImplementation().close(dialog); 20274 closeDialog(dialog); 20275 }); 20276 }; 20277 editor.on('remove', function () { 20278 each$k(dialogs, function (dialog) { 20279 getImplementation().close(dialog); 20280 }); 20281 }); 20282 return { 20283 open: open, 20284 openUrl: openUrl, 20285 alert: alert, 20286 confirm: confirm, 20287 close: close 20288 }; 20289 }; 20290 20291 var displayNotification = function (editor, message) { 20292 editor.notificationManager.open({ 20293 type: 'error', 20294 text: message 20295 }); 20296 }; 20297 var displayError = function (editor, message) { 20298 if (editor._skinLoaded) { 20299 displayNotification(editor, message); 20300 } else { 20301 editor.on('SkinLoaded', function () { 20302 displayNotification(editor, message); 20303 }); 20304 } 20305 }; 20306 var uploadError = function (editor, message) { 20307 displayError(editor, I18n.translate([ 20308 'Failed to upload image: {0}', 20309 message 20310 ])); 20311 }; 20312 var logError = function (editor, errorType, msg) { 20313 fireError(editor, errorType, { message: msg }); 20314 console.error(msg); 20315 }; 20316 var createLoadError = function (type, url, name) { 20317 return name ? 'Failed to load ' + type + ': ' + name + ' from url ' + url : 'Failed to load ' + type + ' url: ' + url; 20318 }; 20319 var pluginLoadError = function (editor, url, name) { 20320 logError(editor, 'PluginLoadError', createLoadError('plugin', url, name)); 20321 }; 20322 var iconsLoadError = function (editor, url, name) { 20323 logError(editor, 'IconsLoadError', createLoadError('icons', url, name)); 20324 }; 20325 var languageLoadError = function (editor, url, name) { 20326 logError(editor, 'LanguageLoadError', createLoadError('language', url, name)); 20327 }; 20328 var pluginInitError = function (editor, name, err) { 20329 var message = I18n.translate([ 20330 'Failed to initialize plugin: {0}', 20331 name 20332 ]); 20333 fireError(editor, 'PluginLoadError', { message: message }); 20334 initError(message, err); 20335 displayError(editor, message); 20336 }; 20337 var initError = function (message) { 20338 var x = []; 20339 for (var _i = 1; _i < arguments.length; _i++) { 20340 x[_i - 1] = arguments[_i]; 20341 } 20342 var console = window.console; 20343 if (console) { 20344 if (console.error) { 20345 console.error.apply(console, __spreadArray([message], x, false)); 20346 } else { 20347 console.log.apply(console, __spreadArray([message], x, false)); 20348 } 20349 } 20350 }; 20351 20352 var isContentCssSkinName = function (url) { 20353 return /^[a-z0-9\-]+$/i.test(url); 20354 }; 20355 var getContentCssUrls = function (editor) { 20356 return transformToUrls(editor, getContentCss(editor)); 20357 }; 20358 var getFontCssUrls = function (editor) { 20359 return transformToUrls(editor, getFontCss(editor)); 20360 }; 20361 var transformToUrls = function (editor, cssLinks) { 20362 var skinUrl = editor.editorManager.baseURL + '/skins/content'; 20363 var suffix = editor.editorManager.suffix; 20364 var contentCssFile = 'content' + suffix + '.css'; 20365 var inline = editor.inline === true; 20366 return map$3(cssLinks, function (url) { 20367 if (isContentCssSkinName(url) && !inline) { 20368 return skinUrl + '/' + url + '/' + contentCssFile; 20369 } else { 20370 return editor.documentBaseURI.toAbsolute(url); 20371 } 20372 }); 20373 }; 20374 var appendContentCssFromSettings = function (editor) { 20375 editor.contentCSS = editor.contentCSS.concat(getContentCssUrls(editor), getFontCssUrls(editor)); 20376 }; 20377 20378 var UploadStatus = function () { 20379 var PENDING = 1, UPLOADED = 2; 20380 var blobUriStatuses = {}; 20381 var createStatus = function (status, resultUri) { 20382 return { 20383 status: status, 20384 resultUri: resultUri 20385 }; 20386 }; 20387 var hasBlobUri = function (blobUri) { 20388 return blobUri in blobUriStatuses; 20389 }; 20390 var getResultUri = function (blobUri) { 20391 var result = blobUriStatuses[blobUri]; 20392 return result ? result.resultUri : null; 20393 }; 20394 var isPending = function (blobUri) { 20395 return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === PENDING : false; 20396 }; 20397 var isUploaded = function (blobUri) { 20398 return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === UPLOADED : false; 20399 }; 20400 var markPending = function (blobUri) { 20401 blobUriStatuses[blobUri] = createStatus(PENDING, null); 20402 }; 20403 var markUploaded = function (blobUri, resultUri) { 20404 blobUriStatuses[blobUri] = createStatus(UPLOADED, resultUri); 20405 }; 20406 var removeFailed = function (blobUri) { 20407 delete blobUriStatuses[blobUri]; 20408 }; 20409 var destroy = function () { 20410 blobUriStatuses = {}; 20411 }; 20412 return { 20413 hasBlobUri: hasBlobUri, 20414 getResultUri: getResultUri, 20415 isPending: isPending, 20416 isUploaded: isUploaded, 20417 markPending: markPending, 20418 markUploaded: markUploaded, 20419 removeFailed: removeFailed, 20420 destroy: destroy 20421 }; 20422 }; 20423 20424 var count = 0; 20425 var seed = function () { 20426 var rnd = function () { 20427 return Math.round(Math.random() * 4294967295).toString(36); 20428 }; 20429 var now = new Date().getTime(); 20430 return 's' + now.toString(36) + rnd() + rnd() + rnd(); 20431 }; 20432 var uuid = function (prefix) { 20433 return prefix + count++ + seed(); 20434 }; 20435 20436 var BlobCache = function () { 20437 var cache = []; 20438 var mimeToExt = function (mime) { 20439 var mimes = { 20440 'image/jpeg': 'jpg', 20441 'image/jpg': 'jpg', 20442 'image/gif': 'gif', 20443 'image/png': 'png', 20444 'image/apng': 'apng', 20445 'image/avif': 'avif', 20446 'image/svg+xml': 'svg', 20447 'image/webp': 'webp', 20448 'image/bmp': 'bmp', 20449 'image/tiff': 'tiff' 20450 }; 20451 return mimes[mime.toLowerCase()] || 'dat'; 20452 }; 20453 var create = function (o, blob, base64, name, filename) { 20454 if (isString$1(o)) { 20455 var id = o; 20456 return toBlobInfo({ 20457 id: id, 20458 name: name, 20459 filename: filename, 20460 blob: blob, 20461 base64: base64 20462 }); 20463 } else if (isObject(o)) { 20464 return toBlobInfo(o); 20465 } else { 20466 throw new Error('Unknown input type'); 20467 } 20468 }; 20469 var toBlobInfo = function (o) { 20470 if (!o.blob || !o.base64) { 20471 throw new Error('blob and base64 representations of the image are required for BlobInfo to be created'); 20472 } 20473 var id = o.id || uuid('blobid'); 20474 var name = o.name || id; 20475 var blob = o.blob; 20476 return { 20477 id: constant(id), 20478 name: constant(name), 20479 filename: constant(o.filename || name + '.' + mimeToExt(blob.type)), 20480 blob: constant(blob), 20481 base64: constant(o.base64), 20482 blobUri: constant(o.blobUri || URL.createObjectURL(blob)), 20483 uri: constant(o.uri) 20484 }; 20485 }; 20486 var add = function (blobInfo) { 20487 if (!get(blobInfo.id())) { 20488 cache.push(blobInfo); 20489 } 20490 }; 20491 var findFirst = function (predicate) { 20492 return find$3(cache, predicate).getOrUndefined(); 20493 }; 20494 var get = function (id) { 20495 return findFirst(function (cachedBlobInfo) { 20496 return cachedBlobInfo.id() === id; 20497 }); 20498 }; 20499 var getByUri = function (blobUri) { 20500 return findFirst(function (blobInfo) { 20501 return blobInfo.blobUri() === blobUri; 20502 }); 20503 }; 20504 var getByData = function (base64, type) { 20505 return findFirst(function (blobInfo) { 20506 return blobInfo.base64() === base64 && blobInfo.blob().type === type; 20507 }); 20508 }; 20509 var removeByUri = function (blobUri) { 20510 cache = filter$4(cache, function (blobInfo) { 20511 if (blobInfo.blobUri() === blobUri) { 20512 URL.revokeObjectURL(blobInfo.blobUri()); 20513 return false; 20514 } 20515 return true; 20516 }); 20517 }; 20518 var destroy = function () { 20519 each$k(cache, function (cachedBlobInfo) { 20520 URL.revokeObjectURL(cachedBlobInfo.blobUri()); 20521 }); 20522 cache = []; 20523 }; 20524 return { 20525 create: create, 20526 add: add, 20527 get: get, 20528 getByUri: getByUri, 20529 getByData: getByData, 20530 findFirst: findFirst, 20531 removeByUri: removeByUri, 20532 destroy: destroy 20533 }; 20534 }; 20535 20536 var Uploader = function (uploadStatus, settings) { 20537 var pendingPromises = {}; 20538 var pathJoin = function (path1, path2) { 20539 if (path1) { 20540 return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, ''); 20541 } 20542 return path2; 20543 }; 20544 var defaultHandler = function (blobInfo, success, failure, progress) { 20545 var xhr = new XMLHttpRequest(); 20546 xhr.open('POST', settings.url); 20547 xhr.withCredentials = settings.credentials; 20548 xhr.upload.onprogress = function (e) { 20549 progress(e.loaded / e.total * 100); 20550 }; 20551 xhr.onerror = function () { 20552 failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status); 20553 }; 20554 xhr.onload = function () { 20555 if (xhr.status < 200 || xhr.status >= 300) { 20556 failure('HTTP Error: ' + xhr.status); 20557 return; 20558 } 20559 var json = JSON.parse(xhr.responseText); 20560 if (!json || typeof json.location !== 'string') { 20561 failure('Invalid JSON: ' + xhr.responseText); 20562 return; 20563 } 20564 success(pathJoin(settings.basePath, json.location)); 20565 }; 20566 var formData = new FormData(); 20567 formData.append('file', blobInfo.blob(), blobInfo.filename()); 20568 xhr.send(formData); 20569 }; 20570 var noUpload = function () { 20571 return new promiseObj(function (resolve) { 20572 resolve([]); 20573 }); 20574 }; 20575 var handlerSuccess = function (blobInfo, url) { 20576 return { 20577 url: url, 20578 blobInfo: blobInfo, 20579 status: true 20580 }; 20581 }; 20582 var handlerFailure = function (blobInfo, message, options) { 20583 return { 20584 url: '', 20585 blobInfo: blobInfo, 20586 status: false, 20587 error: { 20588 message: message, 20589 options: options 20590 } 20591 }; 20592 }; 20593 var resolvePending = function (blobUri, result) { 20594 Tools.each(pendingPromises[blobUri], function (resolve) { 20595 resolve(result); 20596 }); 20597 delete pendingPromises[blobUri]; 20598 }; 20599 var uploadBlobInfo = function (blobInfo, handler, openNotification) { 20600 uploadStatus.markPending(blobInfo.blobUri()); 20601 return new promiseObj(function (resolve) { 20602 var notification, progress; 20603 try { 20604 var closeNotification_1 = function () { 20605 if (notification) { 20606 notification.close(); 20607 progress = noop; 20608 } 20609 }; 20610 var success = function (url) { 20611 closeNotification_1(); 20612 uploadStatus.markUploaded(blobInfo.blobUri(), url); 20613 resolvePending(blobInfo.blobUri(), handlerSuccess(blobInfo, url)); 20614 resolve(handlerSuccess(blobInfo, url)); 20615 }; 20616 var failure = function (error, options) { 20617 var failureOptions = options ? options : {}; 20618 closeNotification_1(); 20619 uploadStatus.removeFailed(blobInfo.blobUri()); 20620 resolvePending(blobInfo.blobUri(), handlerFailure(blobInfo, error, failureOptions)); 20621 resolve(handlerFailure(blobInfo, error, failureOptions)); 20622 }; 20623 progress = function (percent) { 20624 if (percent < 0 || percent > 100) { 20625 return; 20626 } 20627 Optional.from(notification).orThunk(function () { 20628 return Optional.from(openNotification).map(apply); 20629 }).each(function (n) { 20630 notification = n; 20631 n.progressBar.value(percent); 20632 }); 20633 }; 20634 handler(blobInfo, success, failure, progress); 20635 } catch (ex) { 20636 resolve(handlerFailure(blobInfo, ex.message, {})); 20637 } 20638 }); 20639 }; 20640 var isDefaultHandler = function (handler) { 20641 return handler === defaultHandler; 20642 }; 20643 var pendingUploadBlobInfo = function (blobInfo) { 20644 var blobUri = blobInfo.blobUri(); 20645 return new promiseObj(function (resolve) { 20646 pendingPromises[blobUri] = pendingPromises[blobUri] || []; 20647 pendingPromises[blobUri].push(resolve); 20648 }); 20649 }; 20650 var uploadBlobs = function (blobInfos, openNotification) { 20651 blobInfos = Tools.grep(blobInfos, function (blobInfo) { 20652 return !uploadStatus.isUploaded(blobInfo.blobUri()); 20653 }); 20654 return promiseObj.all(Tools.map(blobInfos, function (blobInfo) { 20655 return uploadStatus.isPending(blobInfo.blobUri()) ? pendingUploadBlobInfo(blobInfo) : uploadBlobInfo(blobInfo, settings.handler, openNotification); 20656 })); 20657 }; 20658 var upload = function (blobInfos, openNotification) { 20659 return !settings.url && isDefaultHandler(settings.handler) ? noUpload() : uploadBlobs(blobInfos, openNotification); 20660 }; 20661 if (isFunction(settings.handler) === false) { 20662 settings.handler = defaultHandler; 20663 } 20664 return { upload: upload }; 20665 }; 20666 20667 var openNotification = function (editor) { 20668 return function () { 20669 return editor.notificationManager.open({ 20670 text: editor.translate('Image uploading...'), 20671 type: 'info', 20672 timeout: -1, 20673 progressBar: true 20674 }); 20675 }; 20676 }; 20677 var createUploader = function (editor, uploadStatus) { 20678 return Uploader(uploadStatus, { 20679 url: getImageUploadUrl(editor), 20680 basePath: getImageUploadBasePath(editor), 20681 credentials: getImagesUploadCredentials(editor), 20682 handler: getImagesUploadHandler(editor) 20683 }); 20684 }; 20685 var ImageUploader = function (editor) { 20686 var uploadStatus = UploadStatus(); 20687 var uploader = createUploader(editor, uploadStatus); 20688 return { 20689 upload: function (blobInfos, showNotification) { 20690 if (showNotification === void 0) { 20691 showNotification = true; 20692 } 20693 return uploader.upload(blobInfos, showNotification ? openNotification(editor) : undefined); 20694 } 20695 }; 20696 }; 20697 20698 var UploadChangeHandler = function (editor) { 20699 var lastChangedLevel = Cell(null); 20700 editor.on('change AddUndo', function (e) { 20701 lastChangedLevel.set(__assign({}, e.level)); 20702 }); 20703 var fireIfChanged = function () { 20704 var data = editor.undoManager.data; 20705 last$2(data).filter(function (level) { 20706 return !isEq$1(lastChangedLevel.get(), level); 20707 }).each(function (level) { 20708 editor.setDirty(true); 20709 editor.fire('change', { 20710 level: level, 20711 lastLevel: get$a(data, data.length - 2).getOrNull() 20712 }); 20713 }); 20714 }; 20715 return { fireIfChanged: fireIfChanged }; 20716 }; 20717 var EditorUpload = function (editor) { 20718 var blobCache = BlobCache(); 20719 var uploader, imageScanner; 20720 var uploadStatus = UploadStatus(); 20721 var urlFilters = []; 20722 var changeHandler = UploadChangeHandler(editor); 20723 var aliveGuard = function (callback) { 20724 return function (result) { 20725 if (editor.selection) { 20726 return callback(result); 20727 } 20728 return []; 20729 }; 20730 }; 20731 var cacheInvalidator = function (url) { 20732 return url + (url.indexOf('?') === -1 ? '?' : '&') + new Date().getTime(); 20733 }; 20734 var replaceString = function (content, search, replace) { 20735 var index = 0; 20736 do { 20737 index = content.indexOf(search, index); 20738 if (index !== -1) { 20739 content = content.substring(0, index) + replace + content.substr(index + search.length); 20740 index += replace.length - search.length + 1; 20741 } 20742 } while (index !== -1); 20743 return content; 20744 }; 20745 var replaceImageUrl = function (content, targetUrl, replacementUrl) { 20746 var replacementString = 'src="' + replacementUrl + '"' + (replacementUrl === Env.transparentSrc ? ' data-mce-placeholder="1"' : ''); 20747 content = replaceString(content, 'src="' + targetUrl + '"', replacementString); 20748 content = replaceString(content, 'data-mce-src="' + targetUrl + '"', 'data-mce-src="' + replacementUrl + '"'); 20749 return content; 20750 }; 20751 var replaceUrlInUndoStack = function (targetUrl, replacementUrl) { 20752 each$k(editor.undoManager.data, function (level) { 20753 if (level.type === 'fragmented') { 20754 level.fragments = map$3(level.fragments, function (fragment) { 20755 return replaceImageUrl(fragment, targetUrl, replacementUrl); 20756 }); 20757 } else { 20758 level.content = replaceImageUrl(level.content, targetUrl, replacementUrl); 20759 } 20760 }); 20761 }; 20762 var replaceImageUriInView = function (image, resultUri) { 20763 var src = editor.convertURL(resultUri, 'src'); 20764 replaceUrlInUndoStack(image.src, resultUri); 20765 editor.$(image).attr({ 20766 'src': shouldReuseFileName(editor) ? cacheInvalidator(resultUri) : resultUri, 20767 'data-mce-src': src 20768 }); 20769 }; 20770 var uploadImages = function (callback) { 20771 if (!uploader) { 20772 uploader = createUploader(editor, uploadStatus); 20773 } 20774 return scanForImages().then(aliveGuard(function (imageInfos) { 20775 var blobInfos = map$3(imageInfos, function (imageInfo) { 20776 return imageInfo.blobInfo; 20777 }); 20778 return uploader.upload(blobInfos, openNotification(editor)).then(aliveGuard(function (result) { 20779 var imagesToRemove = []; 20780 var filteredResult = map$3(result, function (uploadInfo, index) { 20781 var blobInfo = imageInfos[index].blobInfo; 20782 var image = imageInfos[index].image; 20783 if (uploadInfo.status && shouldReplaceBlobUris(editor)) { 20784 blobCache.removeByUri(image.src); 20785 if (isRtc(editor)) ; else { 20786 replaceImageUriInView(image, uploadInfo.url); 20787 } 20788 } else if (uploadInfo.error) { 20789 if (uploadInfo.error.options.remove) { 20790 replaceUrlInUndoStack(image.getAttribute('src'), Env.transparentSrc); 20791 imagesToRemove.push(image); 20792 } 20793 uploadError(editor, uploadInfo.error.message); 20794 } 20795 return { 20796 element: image, 20797 status: uploadInfo.status, 20798 uploadUri: uploadInfo.url, 20799 blobInfo: blobInfo 20800 }; 20801 }); 20802 if (filteredResult.length > 0) { 20803 changeHandler.fireIfChanged(); 20804 } 20805 if (imagesToRemove.length > 0) { 20806 if (isRtc(editor)) { 20807 console.error('Removing images on failed uploads is currently unsupported for RTC'); 20808 } else { 20809 editor.undoManager.transact(function () { 20810 each$k(imagesToRemove, function (element) { 20811 editor.dom.remove(element); 20812 blobCache.removeByUri(element.src); 20813 }); 20814 }); 20815 } 20816 } 20817 if (callback) { 20818 callback(filteredResult); 20819 } 20820 return filteredResult; 20821 })); 20822 })); 20823 }; 20824 var uploadImagesAuto = function (callback) { 20825 if (isAutomaticUploadsEnabled(editor)) { 20826 return uploadImages(callback); 20827 } 20828 }; 20829 var isValidDataUriImage = function (imgElm) { 20830 if (forall(urlFilters, function (filter) { 20831 return filter(imgElm); 20832 }) === false) { 20833 return false; 20834 } 20835 if (imgElm.getAttribute('src').indexOf('data:') === 0) { 20836 var dataImgFilter = getImagesDataImgFilter(editor); 20837 return dataImgFilter(imgElm); 20838 } 20839 return true; 20840 }; 20841 var addFilter = function (filter) { 20842 urlFilters.push(filter); 20843 }; 20844 var scanForImages = function () { 20845 if (!imageScanner) { 20846 imageScanner = ImageScanner(uploadStatus, blobCache); 20847 } 20848 return imageScanner.findAll(editor.getBody(), isValidDataUriImage).then(aliveGuard(function (result) { 20849 result = filter$4(result, function (resultItem) { 20850 if (typeof resultItem === 'string') { 20851 displayError(editor, resultItem); 20852 return false; 20853 } 20854 return true; 20855 }); 20856 if (isRtc(editor)) ; else { 20857 each$k(result, function (resultItem) { 20858 replaceUrlInUndoStack(resultItem.image.src, resultItem.blobInfo.blobUri()); 20859 resultItem.image.src = resultItem.blobInfo.blobUri(); 20860 resultItem.image.removeAttribute('data-mce-src'); 20861 }); 20862 } 20863 return result; 20864 })); 20865 }; 20866 var destroy = function () { 20867 blobCache.destroy(); 20868 uploadStatus.destroy(); 20869 imageScanner = uploader = null; 20870 }; 20871 var replaceBlobUris = function (content) { 20872 return content.replace(/src="(blob:[^"]+)"/g, function (match, blobUri) { 20873 var resultUri = uploadStatus.getResultUri(blobUri); 20874 if (resultUri) { 20875 return 'src="' + resultUri + '"'; 20876 } 20877 var blobInfo = blobCache.getByUri(blobUri); 20878 if (!blobInfo) { 20879 blobInfo = foldl(editor.editorManager.get(), function (result, editor) { 20880 return result || editor.editorUpload && editor.editorUpload.blobCache.getByUri(blobUri); 20881 }, null); 20882 } 20883 if (blobInfo) { 20884 var blob = blobInfo.blob(); 20885 return 'src="data:' + blob.type + ';base64,' + blobInfo.base64() + '"'; 20886 } 20887 return match; 20888 }); 20889 }; 20890 editor.on('SetContent', function () { 20891 if (isAutomaticUploadsEnabled(editor)) { 20892 uploadImagesAuto(); 20893 } else { 20894 scanForImages(); 20895 } 20896 }); 20897 editor.on('RawSaveContent', function (e) { 20898 e.content = replaceBlobUris(e.content); 20899 }); 20900 editor.on('GetContent', function (e) { 20901 if (e.source_view || e.format === 'raw' || e.format === 'tree') { 20902 return; 20903 } 20904 e.content = replaceBlobUris(e.content); 20905 }); 20906 editor.on('PostRender', function () { 20907 editor.parser.addNodeFilter('img', function (images) { 20908 each$k(images, function (img) { 20909 var src = img.attr('src'); 20910 if (blobCache.getByUri(src)) { 20911 return; 20912 } 20913 var resultUri = uploadStatus.getResultUri(src); 20914 if (resultUri) { 20915 img.attr('src', resultUri); 20916 } 20917 }); 20918 }); 20919 }); 20920 return { 20921 blobCache: blobCache, 20922 addFilter: addFilter, 20923 uploadImages: uploadImages, 20924 uploadImagesAuto: uploadImagesAuto, 20925 scanForImages: scanForImages, 20926 destroy: destroy 20927 }; 20928 }; 20929 20930 var get = function (dom) { 20931 var formats = { 20932 valigntop: [{ 20933 selector: 'td,th', 20934 styles: { verticalAlign: 'top' } 20935 }], 20936 valignmiddle: [{ 20937 selector: 'td,th', 20938 styles: { verticalAlign: 'middle' } 20939 }], 20940 valignbottom: [{ 20941 selector: 'td,th', 20942 styles: { verticalAlign: 'bottom' } 20943 }], 20944 alignleft: [ 20945 { 20946 selector: 'figure.image', 20947 collapsed: false, 20948 classes: 'align-left', 20949 ceFalseOverride: true, 20950 preview: 'font-family font-size' 20951 }, 20952 { 20953 selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', 20954 styles: { textAlign: 'left' }, 20955 inherit: false, 20956 preview: false, 20957 defaultBlock: 'div' 20958 }, 20959 { 20960 selector: 'img,table,audio,video', 20961 collapsed: false, 20962 styles: { float: 'left' }, 20963 preview: 'font-family font-size' 20964 } 20965 ], 20966 aligncenter: [ 20967 { 20968 selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', 20969 styles: { textAlign: 'center' }, 20970 inherit: false, 20971 preview: 'font-family font-size', 20972 defaultBlock: 'div' 20973 }, 20974 { 20975 selector: 'figure.image', 20976 collapsed: false, 20977 classes: 'align-center', 20978 ceFalseOverride: true, 20979 preview: 'font-family font-size' 20980 }, 20981 { 20982 selector: 'img,audio,video', 20983 collapsed: false, 20984 styles: { 20985 display: 'block', 20986 marginLeft: 'auto', 20987 marginRight: 'auto' 20988 }, 20989 preview: false 20990 }, 20991 { 20992 selector: 'table', 20993 collapsed: false, 20994 styles: { 20995 marginLeft: 'auto', 20996 marginRight: 'auto' 20997 }, 20998 preview: 'font-family font-size' 20999 } 21000 ], 21001 alignright: [ 21002 { 21003 selector: 'figure.image', 21004 collapsed: false, 21005 classes: 'align-right', 21006 ceFalseOverride: true, 21007 preview: 'font-family font-size' 21008 }, 21009 { 21010 selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', 21011 styles: { textAlign: 'right' }, 21012 inherit: false, 21013 preview: 'font-family font-size', 21014 defaultBlock: 'div' 21015 }, 21016 { 21017 selector: 'img,table,audio,video', 21018 collapsed: false, 21019 styles: { float: 'right' }, 21020 preview: 'font-family font-size' 21021 } 21022 ], 21023 alignjustify: [{ 21024 selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', 21025 styles: { textAlign: 'justify' }, 21026 inherit: false, 21027 defaultBlock: 'div', 21028 preview: 'font-family font-size' 21029 }], 21030 bold: [ 21031 { 21032 inline: 'strong', 21033 remove: 'all', 21034 preserve_attributes: [ 21035 'class', 21036 'style' 21037 ] 21038 }, 21039 { 21040 inline: 'span', 21041 styles: { fontWeight: 'bold' } 21042 }, 21043 { 21044 inline: 'b', 21045 remove: 'all', 21046 preserve_attributes: [ 21047 'class', 21048 'style' 21049 ] 21050 } 21051 ], 21052 italic: [ 21053 { 21054 inline: 'em', 21055 remove: 'all', 21056 preserve_attributes: [ 21057 'class', 21058 'style' 21059 ] 21060 }, 21061 { 21062 inline: 'span', 21063 styles: { fontStyle: 'italic' } 21064 }, 21065 { 21066 inline: 'i', 21067 remove: 'all', 21068 preserve_attributes: [ 21069 'class', 21070 'style' 21071 ] 21072 } 21073 ], 21074 underline: [ 21075 { 21076 inline: 'span', 21077 styles: { textDecoration: 'underline' }, 21078 exact: true 21079 }, 21080 { 21081 inline: 'u', 21082 remove: 'all', 21083 preserve_attributes: [ 21084 'class', 21085 'style' 21086 ] 21087 } 21088 ], 21089 strikethrough: [ 21090 { 21091 inline: 'span', 21092 styles: { textDecoration: 'line-through' }, 21093 exact: true 21094 }, 21095 { 21096 inline: 'strike', 21097 remove: 'all', 21098 preserve_attributes: [ 21099 'class', 21100 'style' 21101 ] 21102 }, 21103 { 21104 inline: 's', 21105 remove: 'all', 21106 preserve_attributes: [ 21107 'class', 21108 'style' 21109 ] 21110 } 21111 ], 21112 forecolor: { 21113 inline: 'span', 21114 styles: { color: '%value' }, 21115 links: true, 21116 remove_similar: true, 21117 clear_child_styles: true 21118 }, 21119 hilitecolor: { 21120 inline: 'span', 21121 styles: { backgroundColor: '%value' }, 21122 links: true, 21123 remove_similar: true, 21124 clear_child_styles: true 21125 }, 21126 fontname: { 21127 inline: 'span', 21128 toggle: false, 21129 styles: { fontFamily: '%value' }, 21130 clear_child_styles: true 21131 }, 21132 fontsize: { 21133 inline: 'span', 21134 toggle: false, 21135 styles: { fontSize: '%value' }, 21136 clear_child_styles: true 21137 }, 21138 lineheight: { 21139 selector: 'h1,h2,h3,h4,h5,h6,p,li,td,th,div', 21140 defaultBlock: 'p', 21141 styles: { lineHeight: '%value' } 21142 }, 21143 fontsize_class: { 21144 inline: 'span', 21145 attributes: { class: '%value' } 21146 }, 21147 blockquote: { 21148 block: 'blockquote', 21149 wrapper: true, 21150 remove: 'all' 21151 }, 21152 subscript: { inline: 'sub' }, 21153 superscript: { inline: 'sup' }, 21154 code: { inline: 'code' }, 21155 link: { 21156 inline: 'a', 21157 selector: 'a', 21158 remove: 'all', 21159 split: true, 21160 deep: true, 21161 onmatch: function (node, _fmt, _itemName) { 21162 return isElement$5(node) && node.hasAttribute('href'); 21163 }, 21164 onformat: function (elm, _fmt, vars) { 21165 Tools.each(vars, function (value, key) { 21166 dom.setAttrib(elm, key, value); 21167 }); 21168 } 21169 }, 21170 lang: { 21171 inline: 'span', 21172 clear_child_styles: true, 21173 remove_similar: true, 21174 attributes: { 21175 'lang': '%value', 21176 'data-mce-lang': function (vars) { 21177 var _a; 21178 return (_a = vars === null || vars === void 0 ? void 0 : vars.customValue) !== null && _a !== void 0 ? _a : null; 21179 } 21180 } 21181 }, 21182 removeformat: [ 21183 { 21184 selector: 'b,strong,em,i,font,u,strike,s,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins,small', 21185 remove: 'all', 21186 split: true, 21187 expand: false, 21188 block_expand: true, 21189 deep: true 21190 }, 21191 { 21192 selector: 'span', 21193 attributes: [ 21194 'style', 21195 'class' 21196 ], 21197 remove: 'empty', 21198 split: true, 21199 expand: false, 21200 deep: true 21201 }, 21202 { 21203 selector: '*', 21204 attributes: [ 21205 'style', 21206 'class' 21207 ], 21208 split: false, 21209 expand: false, 21210 deep: true 21211 } 21212 ] 21213 }; 21214 Tools.each('p h1 h2 h3 h4 h5 h6 div address pre dt dd samp'.split(/\s/), function (name) { 21215 formats[name] = { 21216 block: name, 21217 remove: 'all' 21218 }; 21219 }); 21220 return formats; 21221 }; 21222 21223 var FormatRegistry = function (editor) { 21224 var formats = {}; 21225 var get$1 = function (name) { 21226 return isNonNullable(name) ? formats[name] : formats; 21227 }; 21228 var has = function (name) { 21229 return has$2(formats, name); 21230 }; 21231 var register = function (name, format) { 21232 if (name) { 21233 if (!isString$1(name)) { 21234 each$j(name, function (format, name) { 21235 register(name, format); 21236 }); 21237 } else { 21238 if (!isArray$1(format)) { 21239 format = [format]; 21240 } 21241 each$k(format, function (format) { 21242 if (isUndefined(format.deep)) { 21243 format.deep = !isSelectorFormat(format); 21244 } 21245 if (isUndefined(format.split)) { 21246 format.split = !isSelectorFormat(format) || isInlineFormat(format); 21247 } 21248 if (isUndefined(format.remove) && isSelectorFormat(format) && !isInlineFormat(format)) { 21249 format.remove = 'none'; 21250 } 21251 if (isSelectorFormat(format) && isInlineFormat(format)) { 21252 format.mixed = true; 21253 format.block_expand = true; 21254 } 21255 if (isString$1(format.classes)) { 21256 format.classes = format.classes.split(/\s+/); 21257 } 21258 }); 21259 formats[name] = format; 21260 } 21261 } 21262 }; 21263 var unregister = function (name) { 21264 if (name && formats[name]) { 21265 delete formats[name]; 21266 } 21267 return formats; 21268 }; 21269 register(get(editor.dom)); 21270 register(getFormats(editor)); 21271 return { 21272 get: get$1, 21273 has: has, 21274 register: register, 21275 unregister: unregister 21276 }; 21277 }; 21278 21279 var each$5 = Tools.each; 21280 var dom = DOMUtils.DOM; 21281 var parsedSelectorToHtml = function (ancestry, editor) { 21282 var elm, item, fragment; 21283 var schema = editor && editor.schema || Schema({}); 21284 var decorate = function (elm, item) { 21285 if (item.classes.length) { 21286 dom.addClass(elm, item.classes.join(' ')); 21287 } 21288 dom.setAttribs(elm, item.attrs); 21289 }; 21290 var createElement = function (sItem) { 21291 item = typeof sItem === 'string' ? { 21292 name: sItem, 21293 classes: [], 21294 attrs: {} 21295 } : sItem; 21296 var elm = dom.create(item.name); 21297 decorate(elm, item); 21298 return elm; 21299 }; 21300 var getRequiredParent = function (elm, candidate) { 21301 var name = typeof elm !== 'string' ? elm.nodeName.toLowerCase() : elm; 21302 var elmRule = schema.getElementRule(name); 21303 var parentsRequired = elmRule && elmRule.parentsRequired; 21304 if (parentsRequired && parentsRequired.length) { 21305 return candidate && Tools.inArray(parentsRequired, candidate) !== -1 ? candidate : parentsRequired[0]; 21306 } else { 21307 return false; 21308 } 21309 }; 21310 var wrapInHtml = function (elm, ancestry, siblings) { 21311 var parent, parentCandidate; 21312 var ancestor = ancestry.length > 0 && ancestry[0]; 21313 var ancestorName = ancestor && ancestor.name; 21314 var parentRequired = getRequiredParent(elm, ancestorName); 21315 if (parentRequired) { 21316 if (ancestorName === parentRequired) { 21317 parentCandidate = ancestry[0]; 21318 ancestry = ancestry.slice(1); 21319 } else { 21320 parentCandidate = parentRequired; 21321 } 21322 } else if (ancestor) { 21323 parentCandidate = ancestry[0]; 21324 ancestry = ancestry.slice(1); 21325 } else if (!siblings) { 21326 return elm; 21327 } 21328 if (parentCandidate) { 21329 parent = createElement(parentCandidate); 21330 parent.appendChild(elm); 21331 } 21332 if (siblings) { 21333 if (!parent) { 21334 parent = dom.create('div'); 21335 parent.appendChild(elm); 21336 } 21337 Tools.each(siblings, function (sibling) { 21338 var siblingElm = createElement(sibling); 21339 parent.insertBefore(siblingElm, elm); 21340 }); 21341 } 21342 return wrapInHtml(parent, ancestry, parentCandidate && parentCandidate.siblings); 21343 }; 21344 if (ancestry && ancestry.length) { 21345 item = ancestry[0]; 21346 elm = createElement(item); 21347 fragment = dom.create('div'); 21348 fragment.appendChild(wrapInHtml(elm, ancestry.slice(1), item.siblings)); 21349 return fragment; 21350 } else { 21351 return ''; 21352 } 21353 }; 21354 var parseSelectorItem = function (item) { 21355 var tagName; 21356 var obj = { 21357 classes: [], 21358 attrs: {} 21359 }; 21360 item = obj.selector = Tools.trim(item); 21361 if (item !== '*') { 21362 tagName = item.replace(/(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g, function ($0, $1, $2, $3, $4) { 21363 switch ($1) { 21364 case '#': 21365 obj.attrs.id = $2; 21366 break; 21367 case '.': 21368 obj.classes.push($2); 21369 break; 21370 case ':': 21371 if (Tools.inArray('checked disabled enabled read-only required'.split(' '), $2) !== -1) { 21372 obj.attrs[$2] = $2; 21373 } 21374 break; 21375 } 21376 if ($3 === '[') { 21377 var m = $4.match(/([\w\-]+)(?:\=\"([^\"]+))?/); 21378 if (m) { 21379 obj.attrs[m[1]] = m[2]; 21380 } 21381 } 21382 return ''; 21383 }); 21384 } 21385 obj.name = tagName || 'div'; 21386 return obj; 21387 }; 21388 var parseSelector = function (selector) { 21389 if (!selector || typeof selector !== 'string') { 21390 return []; 21391 } 21392 selector = selector.split(/\s*,\s*/)[0]; 21393 selector = selector.replace(/\s*(~\+|~|\+|>)\s*/g, '$1'); 21394 return Tools.map(selector.split(/(?:>|\s+(?![^\[\]]+\]))/), function (item) { 21395 var siblings = Tools.map(item.split(/(?:~\+|~|\+)/), parseSelectorItem); 21396 var obj = siblings.pop(); 21397 if (siblings.length) { 21398 obj.siblings = siblings; 21399 } 21400 return obj; 21401 }).reverse(); 21402 }; 21403 var getCssText = function (editor, format) { 21404 var name, previewFrag; 21405 var previewCss = '', parentFontSize; 21406 var previewStyles = getPreviewStyles(editor); 21407 if (previewStyles === '') { 21408 return ''; 21409 } 21410 var removeVars = function (val) { 21411 return val.replace(/%(\w+)/g, ''); 21412 }; 21413 if (typeof format === 'string') { 21414 format = editor.formatter.get(format); 21415 if (!format) { 21416 return; 21417 } 21418 format = format[0]; 21419 } 21420 if ('preview' in format) { 21421 var previewOpt = get$9(format, 'preview'); 21422 if (is$1(previewOpt, false)) { 21423 return ''; 21424 } else { 21425 previewStyles = previewOpt.getOr(previewStyles); 21426 } 21427 } 21428 name = format.block || format.inline || 'span'; 21429 var items = parseSelector(format.selector); 21430 if (items.length) { 21431 if (!items[0].name) { 21432 items[0].name = name; 21433 } 21434 name = format.selector; 21435 previewFrag = parsedSelectorToHtml(items, editor); 21436 } else { 21437 previewFrag = parsedSelectorToHtml([name], editor); 21438 } 21439 var previewElm = dom.select(name, previewFrag)[0] || previewFrag.firstChild; 21440 each$5(format.styles, function (value, name) { 21441 var newValue = removeVars(value); 21442 if (newValue) { 21443 dom.setStyle(previewElm, name, newValue); 21444 } 21445 }); 21446 each$5(format.attributes, function (value, name) { 21447 var newValue = removeVars(value); 21448 if (newValue) { 21449 dom.setAttrib(previewElm, name, newValue); 21450 } 21451 }); 21452 each$5(format.classes, function (value) { 21453 var newValue = removeVars(value); 21454 if (!dom.hasClass(previewElm, newValue)) { 21455 dom.addClass(previewElm, newValue); 21456 } 21457 }); 21458 editor.fire('PreviewFormats'); 21459 dom.setStyles(previewFrag, { 21460 position: 'absolute', 21461 left: -65535 21462 }); 21463 editor.getBody().appendChild(previewFrag); 21464 parentFontSize = dom.getStyle(editor.getBody(), 'fontSize', true); 21465 parentFontSize = /px$/.test(parentFontSize) ? parseInt(parentFontSize, 10) : 0; 21466 each$5(previewStyles.split(' '), function (name) { 21467 var value = dom.getStyle(previewElm, name, true); 21468 if (name === 'background-color' && /transparent|rgba\s*\([^)]+,\s*0\)/.test(value)) { 21469 value = dom.getStyle(editor.getBody(), name, true); 21470 if (dom.toHex(value).toLowerCase() === '#ffffff') { 21471 return; 21472 } 21473 } 21474 if (name === 'color') { 21475 if (dom.toHex(value).toLowerCase() === '#000000') { 21476 return; 21477 } 21478 } 21479 if (name === 'font-size') { 21480 if (/em|%$/.test(value)) { 21481 if (parentFontSize === 0) { 21482 return; 21483 } 21484 var numValue = parseFloat(value) / (/%$/.test(value) ? 100 : 1); 21485 value = numValue * parentFontSize + 'px'; 21486 } 21487 } 21488 if (name === 'border' && value) { 21489 previewCss += 'padding:0 2px;'; 21490 } 21491 previewCss += name + ':' + value + ';'; 21492 }); 21493 editor.fire('AfterPreviewFormats'); 21494 dom.remove(previewFrag); 21495 return previewCss; 21496 }; 21497 21498 var setup$h = function (editor) { 21499 editor.addShortcut('meta+b', '', 'Bold'); 21500 editor.addShortcut('meta+i', '', 'Italic'); 21501 editor.addShortcut('meta+u', '', 'Underline'); 21502 for (var i = 1; i <= 6; i++) { 21503 editor.addShortcut('access+' + i, '', [ 21504 'FormatBlock', 21505 false, 21506 'h' + i 21507 ]); 21508 } 21509 editor.addShortcut('access+7', '', [ 21510 'FormatBlock', 21511 false, 21512 'p' 21513 ]); 21514 editor.addShortcut('access+8', '', [ 21515 'FormatBlock', 21516 false, 21517 'div' 21518 ]); 21519 editor.addShortcut('access+9', '', [ 21520 'FormatBlock', 21521 false, 21522 'address' 21523 ]); 21524 }; 21525 21526 var Formatter = function (editor) { 21527 var formats = FormatRegistry(editor); 21528 var formatChangeState = Cell(null); 21529 setup$h(editor); 21530 setup$k(editor); 21531 return { 21532 get: formats.get, 21533 has: formats.has, 21534 register: formats.register, 21535 unregister: formats.unregister, 21536 apply: function (name, vars, node) { 21537 applyFormat(editor, name, vars, node); 21538 }, 21539 remove: function (name, vars, node, similar) { 21540 removeFormat(editor, name, vars, node, similar); 21541 }, 21542 toggle: function (name, vars, node) { 21543 toggleFormat(editor, name, vars, node); 21544 }, 21545 match: function (name, vars, node, similar) { 21546 return matchFormat(editor, name, vars, node, similar); 21547 }, 21548 closest: function (names) { 21549 return closestFormat(editor, names); 21550 }, 21551 matchAll: function (names, vars) { 21552 return matchAllFormats(editor, names, vars); 21553 }, 21554 matchNode: function (node, name, vars, similar) { 21555 return matchNodeFormat(editor, node, name, vars, similar); 21556 }, 21557 canApply: function (name) { 21558 return canApplyFormat(editor, name); 21559 }, 21560 formatChanged: function (formats, callback, similar, vars) { 21561 return formatChanged(editor, formatChangeState, formats, callback, similar, vars); 21562 }, 21563 getCssText: curry(getCssText, editor) 21564 }; 21565 }; 21566 21567 var shouldIgnoreCommand = function (cmd) { 21568 switch (cmd.toLowerCase()) { 21569 case 'undo': 21570 case 'redo': 21571 case 'mcerepaint': 21572 case 'mcefocus': 21573 return true; 21574 default: 21575 return false; 21576 } 21577 }; 21578 var registerEvents = function (editor, undoManager, locks) { 21579 var isFirstTypedCharacter = Cell(false); 21580 var addNonTypingUndoLevel = function (e) { 21581 setTyping(undoManager, false, locks); 21582 undoManager.add({}, e); 21583 }; 21584 editor.on('init', function () { 21585 undoManager.add(); 21586 }); 21587 editor.on('BeforeExecCommand', function (e) { 21588 var cmd = e.command; 21589 if (!shouldIgnoreCommand(cmd)) { 21590 endTyping(undoManager, locks); 21591 undoManager.beforeChange(); 21592 } 21593 }); 21594 editor.on('ExecCommand', function (e) { 21595 var cmd = e.command; 21596 if (!shouldIgnoreCommand(cmd)) { 21597 addNonTypingUndoLevel(e); 21598 } 21599 }); 21600 editor.on('ObjectResizeStart cut', function () { 21601 undoManager.beforeChange(); 21602 }); 21603 editor.on('SaveContent ObjectResized blur', addNonTypingUndoLevel); 21604 editor.on('dragend', addNonTypingUndoLevel); 21605 editor.on('keyup', function (e) { 21606 var keyCode = e.keyCode; 21607 if (e.isDefaultPrevented()) { 21608 return; 21609 } 21610 if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45 || e.ctrlKey) { 21611 addNonTypingUndoLevel(); 21612 editor.nodeChanged(); 21613 } 21614 if (keyCode === 46 || keyCode === 8) { 21615 editor.nodeChanged(); 21616 } 21617 if (isFirstTypedCharacter.get() && undoManager.typing && isEq$1(createFromEditor(editor), undoManager.data[0]) === false) { 21618 if (editor.isDirty() === false) { 21619 editor.setDirty(true); 21620 editor.fire('change', { 21621 level: undoManager.data[0], 21622 lastLevel: null 21623 }); 21624 } 21625 editor.fire('TypingUndo'); 21626 isFirstTypedCharacter.set(false); 21627 editor.nodeChanged(); 21628 } 21629 }); 21630 editor.on('keydown', function (e) { 21631 var keyCode = e.keyCode; 21632 if (e.isDefaultPrevented()) { 21633 return; 21634 } 21635 if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45) { 21636 if (undoManager.typing) { 21637 addNonTypingUndoLevel(e); 21638 } 21639 return; 21640 } 21641 var modKey = e.ctrlKey && !e.altKey || e.metaKey; 21642 if ((keyCode < 16 || keyCode > 20) && keyCode !== 224 && keyCode !== 91 && !undoManager.typing && !modKey) { 21643 undoManager.beforeChange(); 21644 setTyping(undoManager, true, locks); 21645 undoManager.add({}, e); 21646 isFirstTypedCharacter.set(true); 21647 } 21648 }); 21649 editor.on('mousedown', function (e) { 21650 if (undoManager.typing) { 21651 addNonTypingUndoLevel(e); 21652 } 21653 }); 21654 var isInsertReplacementText = function (event) { 21655 return event.inputType === 'insertReplacementText'; 21656 }; 21657 var isInsertTextDataNull = function (event) { 21658 return event.inputType === 'insertText' && event.data === null; 21659 }; 21660 var isInsertFromPasteOrDrop = function (event) { 21661 return event.inputType === 'insertFromPaste' || event.inputType === 'insertFromDrop'; 21662 }; 21663 editor.on('input', function (e) { 21664 if (e.inputType && (isInsertReplacementText(e) || isInsertTextDataNull(e) || isInsertFromPasteOrDrop(e))) { 21665 addNonTypingUndoLevel(e); 21666 } 21667 }); 21668 editor.on('AddUndo Undo Redo ClearUndos', function (e) { 21669 if (!e.isDefaultPrevented()) { 21670 editor.nodeChanged(); 21671 } 21672 }); 21673 }; 21674 var addKeyboardShortcuts = function (editor) { 21675 editor.addShortcut('meta+z', '', 'Undo'); 21676 editor.addShortcut('meta+y,meta+shift+z', '', 'Redo'); 21677 }; 21678 21679 var UndoManager = function (editor) { 21680 var beforeBookmark = value(); 21681 var locks = Cell(0); 21682 var index = Cell(0); 21683 var undoManager = { 21684 data: [], 21685 typing: false, 21686 beforeChange: function () { 21687 beforeChange(editor, locks, beforeBookmark); 21688 }, 21689 add: function (level, event) { 21690 return addUndoLevel(editor, undoManager, index, locks, beforeBookmark, level, event); 21691 }, 21692 undo: function () { 21693 return undo(editor, undoManager, locks, index); 21694 }, 21695 redo: function () { 21696 return redo(editor, index, undoManager.data); 21697 }, 21698 clear: function () { 21699 clear(editor, undoManager, index); 21700 }, 21701 reset: function () { 21702 reset(editor, undoManager); 21703 }, 21704 hasUndo: function () { 21705 return hasUndo(editor, undoManager, index); 21706 }, 21707 hasRedo: function () { 21708 return hasRedo(editor, undoManager, index); 21709 }, 21710 transact: function (callback) { 21711 return transact(editor, undoManager, locks, callback); 21712 }, 21713 ignore: function (callback) { 21714 ignore(editor, locks, callback); 21715 }, 21716 extra: function (callback1, callback2) { 21717 extra(editor, undoManager, index, callback1, callback2); 21718 } 21719 }; 21720 if (!isRtc(editor)) { 21721 registerEvents(editor, undoManager, locks); 21722 } 21723 addKeyboardShortcuts(editor); 21724 return undoManager; 21725 }; 21726 21727 var nonTypingKeycodes = [ 21728 9, 21729 27, 21730 VK.HOME, 21731 VK.END, 21732 19, 21733 20, 21734 44, 21735 144, 21736 145, 21737 33, 21738 34, 21739 45, 21740 16, 21741 17, 21742 18, 21743 91, 21744 92, 21745 93, 21746 VK.DOWN, 21747 VK.UP, 21748 VK.LEFT, 21749 VK.RIGHT 21750 ].concat(Env.browser.isFirefox() ? [224] : []); 21751 var placeholderAttr = 'data-mce-placeholder'; 21752 var isKeyboardEvent = function (e) { 21753 return e.type === 'keydown' || e.type === 'keyup'; 21754 }; 21755 var isDeleteEvent = function (e) { 21756 var keyCode = e.keyCode; 21757 return keyCode === VK.BACKSPACE || keyCode === VK.DELETE; 21758 }; 21759 var isNonTypingKeyboardEvent = function (e) { 21760 if (isKeyboardEvent(e)) { 21761 var keyCode = e.keyCode; 21762 return !isDeleteEvent(e) && (VK.metaKeyPressed(e) || e.altKey || keyCode >= 112 && keyCode <= 123 || contains$3(nonTypingKeycodes, keyCode)); 21763 } else { 21764 return false; 21765 } 21766 }; 21767 var isTypingKeyboardEvent = function (e) { 21768 return isKeyboardEvent(e) && !(isDeleteEvent(e) || e.type === 'keyup' && e.keyCode === 229); 21769 }; 21770 var isVisuallyEmpty = function (dom, rootElm, forcedRootBlock) { 21771 if (isEmpty$2(SugarElement.fromDom(rootElm), false)) { 21772 var isForcedRootBlockFalse = forcedRootBlock === ''; 21773 var firstElement = rootElm.firstElementChild; 21774 if (!firstElement) { 21775 return true; 21776 } else if (dom.getStyle(rootElm.firstElementChild, 'padding-left') || dom.getStyle(rootElm.firstElementChild, 'padding-right')) { 21777 return false; 21778 } else { 21779 return isForcedRootBlockFalse ? !dom.isBlock(firstElement) : forcedRootBlock === firstElement.nodeName.toLowerCase(); 21780 } 21781 } else { 21782 return false; 21783 } 21784 }; 21785 var setup$g = function (editor) { 21786 var dom = editor.dom; 21787 var rootBlock = getForcedRootBlock(editor); 21788 var placeholder = getPlaceholder(editor); 21789 var updatePlaceholder = function (e, initial) { 21790 if (isNonTypingKeyboardEvent(e)) { 21791 return; 21792 } 21793 var body = editor.getBody(); 21794 var showPlaceholder = isTypingKeyboardEvent(e) ? false : isVisuallyEmpty(dom, body, rootBlock); 21795 var isPlaceholderShown = dom.getAttrib(body, placeholderAttr) !== ''; 21796 if (isPlaceholderShown !== showPlaceholder || initial) { 21797 dom.setAttrib(body, placeholderAttr, showPlaceholder ? placeholder : null); 21798 dom.setAttrib(body, 'aria-placeholder', showPlaceholder ? placeholder : null); 21799 firePlaceholderToggle(editor, showPlaceholder); 21800 editor.on(showPlaceholder ? 'keydown' : 'keyup', updatePlaceholder); 21801 editor.off(showPlaceholder ? 'keyup' : 'keydown', updatePlaceholder); 21802 } 21803 }; 21804 if (placeholder) { 21805 editor.on('init', function (e) { 21806 updatePlaceholder(e, true); 21807 editor.on('change SetContent ExecCommand', updatePlaceholder); 21808 editor.on('paste', function (e) { 21809 return Delay.setEditorTimeout(editor, function () { 21810 return updatePlaceholder(e); 21811 }); 21812 }); 21813 }); 21814 } 21815 }; 21816 21817 var strongRtl = /[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/; 21818 var hasStrongRtl = function (text) { 21819 return strongRtl.test(text); 21820 }; 21821 21822 var isInlineTarget = function (editor, elm) { 21823 return is$2(SugarElement.fromDom(elm), getInlineBoundarySelector(editor)); 21824 }; 21825 var isRtl = function (element) { 21826 return DOMUtils.DOM.getStyle(element, 'direction', true) === 'rtl' || hasStrongRtl(element.textContent); 21827 }; 21828 var findInlineParents = function (isInlineTarget, rootNode, pos) { 21829 return filter$4(DOMUtils.DOM.getParents(pos.container(), '*', rootNode), isInlineTarget); 21830 }; 21831 var findRootInline = function (isInlineTarget, rootNode, pos) { 21832 var parents = findInlineParents(isInlineTarget, rootNode, pos); 21833 return Optional.from(parents[parents.length - 1]); 21834 }; 21835 var hasSameParentBlock = function (rootNode, node1, node2) { 21836 var block1 = getParentBlock$2(node1, rootNode); 21837 var block2 = getParentBlock$2(node2, rootNode); 21838 return block1 && block1 === block2; 21839 }; 21840 var isAtZwsp = function (pos) { 21841 return isBeforeInline(pos) || isAfterInline(pos); 21842 }; 21843 var normalizePosition = function (forward, pos) { 21844 if (!pos) { 21845 return pos; 21846 } 21847 var container = pos.container(), offset = pos.offset(); 21848 if (forward) { 21849 if (isCaretContainerInline(container)) { 21850 if (isText$7(container.nextSibling)) { 21851 return CaretPosition(container.nextSibling, 0); 21852 } else { 21853 return CaretPosition.after(container); 21854 } 21855 } else { 21856 return isBeforeInline(pos) ? CaretPosition(container, offset + 1) : pos; 21857 } 21858 } else { 21859 if (isCaretContainerInline(container)) { 21860 if (isText$7(container.previousSibling)) { 21861 return CaretPosition(container.previousSibling, container.previousSibling.data.length); 21862 } else { 21863 return CaretPosition.before(container); 21864 } 21865 } else { 21866 return isAfterInline(pos) ? CaretPosition(container, offset - 1) : pos; 21867 } 21868 } 21869 }; 21870 var normalizeForwards = curry(normalizePosition, true); 21871 var normalizeBackwards = curry(normalizePosition, false); 21872 21873 var isBeforeRoot = function (rootNode) { 21874 return function (elm) { 21875 return eq(rootNode, SugarElement.fromDom(elm.dom.parentNode)); 21876 }; 21877 }; 21878 var isTextBlockOrListItem = function (element) { 21879 return isTextBlock$2(element) || isListItem(element); 21880 }; 21881 var getParentBlock$1 = function (rootNode, elm) { 21882 if (contains$1(rootNode, elm)) { 21883 return closest$3(elm, isTextBlockOrListItem, isBeforeRoot(rootNode)); 21884 } else { 21885 return Optional.none(); 21886 } 21887 }; 21888 var placeCaretInEmptyBody = function (editor) { 21889 var body = editor.getBody(); 21890 var node = body.firstChild && editor.dom.isBlock(body.firstChild) ? body.firstChild : body; 21891 editor.selection.setCursorLocation(node, 0); 21892 }; 21893 var paddEmptyBody = function (editor) { 21894 if (editor.dom.isEmpty(editor.getBody())) { 21895 editor.setContent(''); 21896 placeCaretInEmptyBody(editor); 21897 } 21898 }; 21899 var willDeleteLastPositionInElement = function (forward, fromPos, elm) { 21900 return lift2(firstPositionIn(elm), lastPositionIn(elm), function (firstPos, lastPos) { 21901 var normalizedFirstPos = normalizePosition(true, firstPos); 21902 var normalizedLastPos = normalizePosition(false, lastPos); 21903 var normalizedFromPos = normalizePosition(false, fromPos); 21904 if (forward) { 21905 return nextPosition(elm, normalizedFromPos).exists(function (nextPos) { 21906 return nextPos.isEqual(normalizedLastPos) && fromPos.isEqual(normalizedFirstPos); 21907 }); 21908 } else { 21909 return prevPosition(elm, normalizedFromPos).exists(function (prevPos) { 21910 return prevPos.isEqual(normalizedFirstPos) && fromPos.isEqual(normalizedLastPos); 21911 }); 21912 } 21913 }).getOr(true); 21914 }; 21915 21916 var blockPosition = function (block, position) { 21917 return { 21918 block: block, 21919 position: position 21920 }; 21921 }; 21922 var blockBoundary = function (from, to) { 21923 return { 21924 from: from, 21925 to: to 21926 }; 21927 }; 21928 var getBlockPosition = function (rootNode, pos) { 21929 var rootElm = SugarElement.fromDom(rootNode); 21930 var containerElm = SugarElement.fromDom(pos.container()); 21931 return getParentBlock$1(rootElm, containerElm).map(function (block) { 21932 return blockPosition(block, pos); 21933 }); 21934 }; 21935 var isDifferentBlocks = function (blockBoundary) { 21936 return eq(blockBoundary.from.block, blockBoundary.to.block) === false; 21937 }; 21938 var hasSameParent = function (blockBoundary) { 21939 return parent(blockBoundary.from.block).bind(function (parent1) { 21940 return parent(blockBoundary.to.block).filter(function (parent2) { 21941 return eq(parent1, parent2); 21942 }); 21943 }).isSome(); 21944 }; 21945 var isEditable$1 = function (blockBoundary) { 21946 return isContentEditableFalse$b(blockBoundary.from.block.dom) === false && isContentEditableFalse$b(blockBoundary.to.block.dom) === false; 21947 }; 21948 var skipLastBr = function (rootNode, forward, blockPosition) { 21949 if (isBr$5(blockPosition.position.getNode()) && isEmpty$2(blockPosition.block) === false) { 21950 return positionIn(false, blockPosition.block.dom).bind(function (lastPositionInBlock) { 21951 if (lastPositionInBlock.isEqual(blockPosition.position)) { 21952 return fromPosition(forward, rootNode, lastPositionInBlock).bind(function (to) { 21953 return getBlockPosition(rootNode, to); 21954 }); 21955 } else { 21956 return Optional.some(blockPosition); 21957 } 21958 }).getOr(blockPosition); 21959 } else { 21960 return blockPosition; 21961 } 21962 }; 21963 var readFromRange = function (rootNode, forward, rng) { 21964 var fromBlockPos = getBlockPosition(rootNode, CaretPosition.fromRangeStart(rng)); 21965 var toBlockPos = fromBlockPos.bind(function (blockPos) { 21966 return fromPosition(forward, rootNode, blockPos.position).bind(function (to) { 21967 return getBlockPosition(rootNode, to).map(function (blockPos) { 21968 return skipLastBr(rootNode, forward, blockPos); 21969 }); 21970 }); 21971 }); 21972 return lift2(fromBlockPos, toBlockPos, blockBoundary).filter(function (blockBoundary) { 21973 return isDifferentBlocks(blockBoundary) && hasSameParent(blockBoundary) && isEditable$1(blockBoundary); 21974 }); 21975 }; 21976 var read$1 = function (rootNode, forward, rng) { 21977 return rng.collapsed ? readFromRange(rootNode, forward, rng) : Optional.none(); 21978 }; 21979 21980 var getChildrenUntilBlockBoundary = function (block) { 21981 var children$1 = children(block); 21982 return findIndex$2(children$1, isBlock$2).fold(constant(children$1), function (index) { 21983 return children$1.slice(0, index); 21984 }); 21985 }; 21986 var extractChildren = function (block) { 21987 var children = getChildrenUntilBlockBoundary(block); 21988 each$k(children, remove$7); 21989 return children; 21990 }; 21991 var removeEmptyRoot = function (rootNode, block) { 21992 var parents = parentsAndSelf(block, rootNode); 21993 return find$3(parents.reverse(), function (element) { 21994 return isEmpty$2(element); 21995 }).each(remove$7); 21996 }; 21997 var isEmptyBefore = function (el) { 21998 return filter$4(prevSiblings(el), function (el) { 21999 return !isEmpty$2(el); 22000 }).length === 0; 22001 }; 22002 var nestedBlockMerge = function (rootNode, fromBlock, toBlock, insertionPoint) { 22003 if (isEmpty$2(toBlock)) { 22004 fillWithPaddingBr(toBlock); 22005 return firstPositionIn(toBlock.dom); 22006 } 22007 if (isEmptyBefore(insertionPoint) && isEmpty$2(fromBlock)) { 22008 before$4(insertionPoint, SugarElement.fromTag('br')); 22009 } 22010 var position = prevPosition(toBlock.dom, CaretPosition.before(insertionPoint.dom)); 22011 each$k(extractChildren(fromBlock), function (child) { 22012 before$4(insertionPoint, child); 22013 }); 22014 removeEmptyRoot(rootNode, fromBlock); 22015 return position; 22016 }; 22017 var sidelongBlockMerge = function (rootNode, fromBlock, toBlock) { 22018 if (isEmpty$2(toBlock)) { 22019 remove$7(toBlock); 22020 if (isEmpty$2(fromBlock)) { 22021 fillWithPaddingBr(fromBlock); 22022 } 22023 return firstPositionIn(fromBlock.dom); 22024 } 22025 var position = lastPositionIn(toBlock.dom); 22026 each$k(extractChildren(fromBlock), function (child) { 22027 append$1(toBlock, child); 22028 }); 22029 removeEmptyRoot(rootNode, fromBlock); 22030 return position; 22031 }; 22032 var findInsertionPoint = function (toBlock, block) { 22033 var parentsAndSelf$1 = parentsAndSelf(block, toBlock); 22034 return Optional.from(parentsAndSelf$1[parentsAndSelf$1.length - 1]); 22035 }; 22036 var getInsertionPoint = function (fromBlock, toBlock) { 22037 return contains$1(toBlock, fromBlock) ? findInsertionPoint(toBlock, fromBlock) : Optional.none(); 22038 }; 22039 var trimBr = function (first, block) { 22040 positionIn(first, block.dom).map(function (position) { 22041 return position.getNode(); 22042 }).map(SugarElement.fromDom).filter(isBr$4).each(remove$7); 22043 }; 22044 var mergeBlockInto = function (rootNode, fromBlock, toBlock) { 22045 trimBr(true, fromBlock); 22046 trimBr(false, toBlock); 22047 return getInsertionPoint(fromBlock, toBlock).fold(curry(sidelongBlockMerge, rootNode, fromBlock, toBlock), curry(nestedBlockMerge, rootNode, fromBlock, toBlock)); 22048 }; 22049 var mergeBlocks = function (rootNode, forward, block1, block2) { 22050 return forward ? mergeBlockInto(rootNode, block2, block1) : mergeBlockInto(rootNode, block1, block2); 22051 }; 22052 22053 var backspaceDelete$8 = function (editor, forward) { 22054 var rootNode = SugarElement.fromDom(editor.getBody()); 22055 var position = read$1(rootNode.dom, forward, editor.selection.getRng()).bind(function (blockBoundary) { 22056 return mergeBlocks(rootNode, forward, blockBoundary.from.block, blockBoundary.to.block); 22057 }); 22058 position.each(function (pos) { 22059 editor.selection.setRng(pos.toRange()); 22060 }); 22061 return position.isSome(); 22062 }; 22063 22064 var deleteRangeMergeBlocks = function (rootNode, selection) { 22065 var rng = selection.getRng(); 22066 return lift2(getParentBlock$1(rootNode, SugarElement.fromDom(rng.startContainer)), getParentBlock$1(rootNode, SugarElement.fromDom(rng.endContainer)), function (block1, block2) { 22067 if (eq(block1, block2) === false) { 22068 rng.deleteContents(); 22069 mergeBlocks(rootNode, true, block1, block2).each(function (pos) { 22070 selection.setRng(pos.toRange()); 22071 }); 22072 return true; 22073 } else { 22074 return false; 22075 } 22076 }).getOr(false); 22077 }; 22078 var isRawNodeInTable = function (root, rawNode) { 22079 var node = SugarElement.fromDom(rawNode); 22080 var isRoot = curry(eq, root); 22081 return ancestor$3(node, isTableCell$4, isRoot).isSome(); 22082 }; 22083 var isSelectionInTable = function (root, rng) { 22084 return isRawNodeInTable(root, rng.startContainer) || isRawNodeInTable(root, rng.endContainer); 22085 }; 22086 var isEverythingSelected = function (root, rng) { 22087 var noPrevious = prevPosition(root.dom, CaretPosition.fromRangeStart(rng)).isNone(); 22088 var noNext = nextPosition(root.dom, CaretPosition.fromRangeEnd(rng)).isNone(); 22089 return !isSelectionInTable(root, rng) && noPrevious && noNext; 22090 }; 22091 var emptyEditor = function (editor) { 22092 editor.setContent(''); 22093 editor.selection.setCursorLocation(); 22094 return true; 22095 }; 22096 var deleteRange$1 = function (editor) { 22097 var rootNode = SugarElement.fromDom(editor.getBody()); 22098 var rng = editor.selection.getRng(); 22099 return isEverythingSelected(rootNode, rng) ? emptyEditor(editor) : deleteRangeMergeBlocks(rootNode, editor.selection); 22100 }; 22101 var backspaceDelete$7 = function (editor, _forward) { 22102 return editor.selection.isCollapsed() ? false : deleteRange$1(editor); 22103 }; 22104 22105 var isContentEditableTrue$2 = isContentEditableTrue$4; 22106 var isContentEditableFalse$4 = isContentEditableFalse$b; 22107 var showCaret = function (direction, editor, node, before, scrollIntoView) { 22108 return Optional.from(editor._selectionOverrides.showCaret(direction, node, before, scrollIntoView)); 22109 }; 22110 var getNodeRange = function (node) { 22111 var rng = node.ownerDocument.createRange(); 22112 rng.selectNode(node); 22113 return rng; 22114 }; 22115 var selectNode = function (editor, node) { 22116 var e = editor.fire('BeforeObjectSelected', { target: node }); 22117 if (e.isDefaultPrevented()) { 22118 return Optional.none(); 22119 } 22120 return Optional.some(getNodeRange(node)); 22121 }; 22122 var renderCaretAtRange = function (editor, range, scrollIntoView) { 22123 var normalizedRange = normalizeRange(1, editor.getBody(), range); 22124 var caretPosition = CaretPosition.fromRangeStart(normalizedRange); 22125 var caretPositionNode = caretPosition.getNode(); 22126 if (isInlineFakeCaretTarget(caretPositionNode)) { 22127 return showCaret(1, editor, caretPositionNode, !caretPosition.isAtEnd(), false); 22128 } 22129 var caretPositionBeforeNode = caretPosition.getNode(true); 22130 if (isInlineFakeCaretTarget(caretPositionBeforeNode)) { 22131 return showCaret(1, editor, caretPositionBeforeNode, false, false); 22132 } 22133 var ceRoot = editor.dom.getParent(caretPosition.getNode(), function (node) { 22134 return isContentEditableFalse$4(node) || isContentEditableTrue$2(node); 22135 }); 22136 if (isInlineFakeCaretTarget(ceRoot)) { 22137 return showCaret(1, editor, ceRoot, false, scrollIntoView); 22138 } 22139 return Optional.none(); 22140 }; 22141 var renderRangeCaret = function (editor, range, scrollIntoView) { 22142 return range.collapsed ? renderCaretAtRange(editor, range, scrollIntoView).getOr(range) : range; 22143 }; 22144 22145 var isBeforeBoundary = function (pos) { 22146 return isBeforeContentEditableFalse(pos) || isBeforeMedia(pos); 22147 }; 22148 var isAfterBoundary = function (pos) { 22149 return isAfterContentEditableFalse(pos) || isAfterMedia(pos); 22150 }; 22151 var trimEmptyTextNode = function (dom, node) { 22152 if (isText$7(node) && node.data.length === 0) { 22153 dom.remove(node); 22154 } 22155 }; 22156 var deleteContentAndShowCaret = function (editor, range, node, direction, forward, peekCaretPosition) { 22157 showCaret(direction, editor, peekCaretPosition.getNode(!forward), forward, true).each(function (caretRange) { 22158 if (range.collapsed) { 22159 var deleteRange = range.cloneRange(); 22160 if (forward) { 22161 deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset); 22162 } else { 22163 deleteRange.setStart(caretRange.endContainer, caretRange.endOffset); 22164 } 22165 deleteRange.deleteContents(); 22166 } else { 22167 range.deleteContents(); 22168 } 22169 editor.selection.setRng(caretRange); 22170 }); 22171 trimEmptyTextNode(editor.dom, node); 22172 return true; 22173 }; 22174 var deleteBoundaryText = function (editor, forward) { 22175 var range = editor.selection.getRng(); 22176 if (!isText$7(range.commonAncestorContainer)) { 22177 return false; 22178 } 22179 var direction = forward ? HDirection.Forwards : HDirection.Backwards; 22180 var caretWalker = CaretWalker(editor.getBody()); 22181 var getNextPosFn = curry(getVisualCaretPosition, forward ? caretWalker.next : caretWalker.prev); 22182 var isBeforeFn = forward ? isBeforeBoundary : isAfterBoundary; 22183 var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range); 22184 var nextCaretPosition = normalizePosition(forward, getNextPosFn(caretPosition)); 22185 if (!nextCaretPosition || !isMoveInsideSameBlock(caretPosition, nextCaretPosition)) { 22186 return false; 22187 } else if (isBeforeFn(nextCaretPosition)) { 22188 return deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, nextCaretPosition); 22189 } 22190 var peekCaretPosition = getNextPosFn(nextCaretPosition); 22191 if (peekCaretPosition && isBeforeFn(peekCaretPosition)) { 22192 if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) { 22193 return deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, peekCaretPosition); 22194 } 22195 } 22196 return false; 22197 }; 22198 var backspaceDelete$6 = function (editor, forward) { 22199 return deleteBoundaryText(editor, forward); 22200 }; 22201 22202 var isCompoundElement = function (node) { 22203 return isTableCell$4(SugarElement.fromDom(node)) || isListItem(SugarElement.fromDom(node)); 22204 }; 22205 var DeleteAction = Adt.generate([ 22206 { remove: ['element'] }, 22207 { moveToElement: ['element'] }, 22208 { moveToPosition: ['position'] } 22209 ]); 22210 var isAtContentEditableBlockCaret = function (forward, from) { 22211 var elm = from.getNode(forward === false); 22212 var caretLocation = forward ? 'after' : 'before'; 22213 return isElement$5(elm) && elm.getAttribute('data-mce-caret') === caretLocation; 22214 }; 22215 var isDeleteFromCefDifferentBlocks = function (root, forward, from, to) { 22216 var inSameBlock = function (elm) { 22217 return isInline$1(SugarElement.fromDom(elm)) && !isInSameBlock(from, to, root); 22218 }; 22219 return getRelativeCefElm(!forward, from).fold(function () { 22220 return getRelativeCefElm(forward, to).fold(never, inSameBlock); 22221 }, inSameBlock); 22222 }; 22223 var deleteEmptyBlockOrMoveToCef = function (root, forward, from, to) { 22224 var toCefElm = to.getNode(forward === false); 22225 return getParentBlock$1(SugarElement.fromDom(root), SugarElement.fromDom(from.getNode())).map(function (blockElm) { 22226 return isEmpty$2(blockElm) ? DeleteAction.remove(blockElm.dom) : DeleteAction.moveToElement(toCefElm); 22227 }).orThunk(function () { 22228 return Optional.some(DeleteAction.moveToElement(toCefElm)); 22229 }); 22230 }; 22231 var findCefPosition = function (root, forward, from) { 22232 return fromPosition(forward, root, from).bind(function (to) { 22233 if (isCompoundElement(to.getNode())) { 22234 return Optional.none(); 22235 } else if (isDeleteFromCefDifferentBlocks(root, forward, from, to)) { 22236 return Optional.none(); 22237 } else if (forward && isContentEditableFalse$b(to.getNode())) { 22238 return deleteEmptyBlockOrMoveToCef(root, forward, from, to); 22239 } else if (forward === false && isContentEditableFalse$b(to.getNode(true))) { 22240 return deleteEmptyBlockOrMoveToCef(root, forward, from, to); 22241 } else if (forward && isAfterContentEditableFalse(from)) { 22242 return Optional.some(DeleteAction.moveToPosition(to)); 22243 } else if (forward === false && isBeforeContentEditableFalse(from)) { 22244 return Optional.some(DeleteAction.moveToPosition(to)); 22245 } else { 22246 return Optional.none(); 22247 } 22248 }); 22249 }; 22250 var getContentEditableBlockAction = function (forward, elm) { 22251 if (forward && isContentEditableFalse$b(elm.nextSibling)) { 22252 return Optional.some(DeleteAction.moveToElement(elm.nextSibling)); 22253 } else if (forward === false && isContentEditableFalse$b(elm.previousSibling)) { 22254 return Optional.some(DeleteAction.moveToElement(elm.previousSibling)); 22255 } else { 22256 return Optional.none(); 22257 } 22258 }; 22259 var skipMoveToActionFromInlineCefToContent = function (root, from, deleteAction) { 22260 return deleteAction.fold(function (elm) { 22261 return Optional.some(DeleteAction.remove(elm)); 22262 }, function (elm) { 22263 return Optional.some(DeleteAction.moveToElement(elm)); 22264 }, function (to) { 22265 if (isInSameBlock(from, to, root)) { 22266 return Optional.none(); 22267 } else { 22268 return Optional.some(DeleteAction.moveToPosition(to)); 22269 } 22270 }); 22271 }; 22272 var getContentEditableAction = function (root, forward, from) { 22273 if (isAtContentEditableBlockCaret(forward, from)) { 22274 return getContentEditableBlockAction(forward, from.getNode(forward === false)).fold(function () { 22275 return findCefPosition(root, forward, from); 22276 }, Optional.some); 22277 } else { 22278 return findCefPosition(root, forward, from).bind(function (deleteAction) { 22279 return skipMoveToActionFromInlineCefToContent(root, from, deleteAction); 22280 }); 22281 } 22282 }; 22283 var read = function (root, forward, rng) { 22284 var normalizedRange = normalizeRange(forward ? 1 : -1, root, rng); 22285 var from = CaretPosition.fromRangeStart(normalizedRange); 22286 var rootElement = SugarElement.fromDom(root); 22287 if (forward === false && isAfterContentEditableFalse(from)) { 22288 return Optional.some(DeleteAction.remove(from.getNode(true))); 22289 } else if (forward && isBeforeContentEditableFalse(from)) { 22290 return Optional.some(DeleteAction.remove(from.getNode())); 22291 } else if (forward === false && isBeforeContentEditableFalse(from) && isAfterBr(rootElement, from)) { 22292 return findPreviousBr(rootElement, from).map(function (br) { 22293 return DeleteAction.remove(br.getNode()); 22294 }); 22295 } else if (forward && isAfterContentEditableFalse(from) && isBeforeBr$1(rootElement, from)) { 22296 return findNextBr(rootElement, from).map(function (br) { 22297 return DeleteAction.remove(br.getNode()); 22298 }); 22299 } else { 22300 return getContentEditableAction(root, forward, from); 22301 } 22302 }; 22303 22304 var deleteElement$1 = function (editor, forward) { 22305 return function (element) { 22306 editor._selectionOverrides.hideFakeCaret(); 22307 deleteElement$2(editor, forward, SugarElement.fromDom(element)); 22308 return true; 22309 }; 22310 }; 22311 var moveToElement = function (editor, forward) { 22312 return function (element) { 22313 var pos = forward ? CaretPosition.before(element) : CaretPosition.after(element); 22314 editor.selection.setRng(pos.toRange()); 22315 return true; 22316 }; 22317 }; 22318 var moveToPosition = function (editor) { 22319 return function (pos) { 22320 editor.selection.setRng(pos.toRange()); 22321 return true; 22322 }; 22323 }; 22324 var getAncestorCe = function (editor, node) { 22325 return Optional.from(getContentEditableRoot$1(editor.getBody(), node)); 22326 }; 22327 var backspaceDeleteCaret = function (editor, forward) { 22328 var selectedNode = editor.selection.getNode(); 22329 return getAncestorCe(editor, selectedNode).filter(isContentEditableFalse$b).fold(function () { 22330 return read(editor.getBody(), forward, editor.selection.getRng()).exists(function (deleteAction) { 22331 return deleteAction.fold(deleteElement$1(editor, forward), moveToElement(editor, forward), moveToPosition(editor)); 22332 }); 22333 }, always); 22334 }; 22335 var deleteOffscreenSelection = function (rootElement) { 22336 each$k(descendants(rootElement, '.mce-offscreen-selection'), remove$7); 22337 }; 22338 var backspaceDeleteRange = function (editor, forward) { 22339 var selectedNode = editor.selection.getNode(); 22340 if (isContentEditableFalse$b(selectedNode) && !isTableCell$5(selectedNode)) { 22341 var hasCefAncestor = getAncestorCe(editor, selectedNode.parentNode).filter(isContentEditableFalse$b); 22342 return hasCefAncestor.fold(function () { 22343 deleteOffscreenSelection(SugarElement.fromDom(editor.getBody())); 22344 deleteElement$2(editor, forward, SugarElement.fromDom(editor.selection.getNode())); 22345 paddEmptyBody(editor); 22346 return true; 22347 }, always); 22348 } 22349 return false; 22350 }; 22351 var paddEmptyElement = function (editor) { 22352 var dom = editor.dom, selection = editor.selection; 22353 var ceRoot = getContentEditableRoot$1(editor.getBody(), selection.getNode()); 22354 if (isContentEditableTrue$4(ceRoot) && dom.isBlock(ceRoot) && dom.isEmpty(ceRoot)) { 22355 var br = dom.create('br', { 'data-mce-bogus': '1' }); 22356 dom.setHTML(ceRoot, ''); 22357 ceRoot.appendChild(br); 22358 selection.setRng(CaretPosition.before(br).toRange()); 22359 } 22360 return true; 22361 }; 22362 var backspaceDelete$5 = function (editor, forward) { 22363 if (editor.selection.isCollapsed()) { 22364 return backspaceDeleteCaret(editor, forward); 22365 } else { 22366 return backspaceDeleteRange(editor, forward); 22367 } 22368 }; 22369 22370 var deleteCaret$2 = function (editor, forward) { 22371 var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng()); 22372 return fromPosition(forward, editor.getBody(), fromPos).filter(function (pos) { 22373 return forward ? isBeforeImageBlock(pos) : isAfterImageBlock(pos); 22374 }).bind(function (pos) { 22375 return Optional.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, pos)); 22376 }).exists(function (elm) { 22377 editor.selection.select(elm); 22378 return true; 22379 }); 22380 }; 22381 var backspaceDelete$4 = function (editor, forward) { 22382 return editor.selection.isCollapsed() ? deleteCaret$2(editor, forward) : false; 22383 }; 22384 22385 var isText = isText$7; 22386 var startsWithCaretContainer = function (node) { 22387 return isText(node) && node.data[0] === ZWSP$1; 22388 }; 22389 var endsWithCaretContainer = function (node) { 22390 return isText(node) && node.data[node.data.length - 1] === ZWSP$1; 22391 }; 22392 var createZwsp = function (node) { 22393 return node.ownerDocument.createTextNode(ZWSP$1); 22394 }; 22395 var insertBefore = function (node) { 22396 if (isText(node.previousSibling)) { 22397 if (endsWithCaretContainer(node.previousSibling)) { 22398 return node.previousSibling; 22399 } else { 22400 node.previousSibling.appendData(ZWSP$1); 22401 return node.previousSibling; 22402 } 22403 } else if (isText(node)) { 22404 if (startsWithCaretContainer(node)) { 22405 return node; 22406 } else { 22407 node.insertData(0, ZWSP$1); 22408 return node; 22409 } 22410 } else { 22411 var newNode = createZwsp(node); 22412 node.parentNode.insertBefore(newNode, node); 22413 return newNode; 22414 } 22415 }; 22416 var insertAfter = function (node) { 22417 if (isText(node.nextSibling)) { 22418 if (startsWithCaretContainer(node.nextSibling)) { 22419 return node.nextSibling; 22420 } else { 22421 node.nextSibling.insertData(0, ZWSP$1); 22422 return node.nextSibling; 22423 } 22424 } else if (isText(node)) { 22425 if (endsWithCaretContainer(node)) { 22426 return node; 22427 } else { 22428 node.appendData(ZWSP$1); 22429 return node; 22430 } 22431 } else { 22432 var newNode = createZwsp(node); 22433 if (node.nextSibling) { 22434 node.parentNode.insertBefore(newNode, node.nextSibling); 22435 } else { 22436 node.parentNode.appendChild(newNode); 22437 } 22438 return newNode; 22439 } 22440 }; 22441 var insertInline = function (before, node) { 22442 return before ? insertBefore(node) : insertAfter(node); 22443 }; 22444 var insertInlineBefore = curry(insertInline, true); 22445 var insertInlineAfter = curry(insertInline, false); 22446 22447 var insertInlinePos = function (pos, before) { 22448 if (isText$7(pos.container())) { 22449 return insertInline(before, pos.container()); 22450 } else { 22451 return insertInline(before, pos.getNode()); 22452 } 22453 }; 22454 var isPosCaretContainer = function (pos, caret) { 22455 var caretNode = caret.get(); 22456 return caretNode && pos.container() === caretNode && isCaretContainerInline(caretNode); 22457 }; 22458 var renderCaret = function (caret, location) { 22459 return location.fold(function (element) { 22460 remove$2(caret.get()); 22461 var text = insertInlineBefore(element); 22462 caret.set(text); 22463 return Optional.some(CaretPosition(text, text.length - 1)); 22464 }, function (element) { 22465 return firstPositionIn(element).map(function (pos) { 22466 if (!isPosCaretContainer(pos, caret)) { 22467 remove$2(caret.get()); 22468 var text = insertInlinePos(pos, true); 22469 caret.set(text); 22470 return CaretPosition(text, 1); 22471 } else { 22472 return CaretPosition(caret.get(), 1); 22473 } 22474 }); 22475 }, function (element) { 22476 return lastPositionIn(element).map(function (pos) { 22477 if (!isPosCaretContainer(pos, caret)) { 22478 remove$2(caret.get()); 22479 var text = insertInlinePos(pos, false); 22480 caret.set(text); 22481 return CaretPosition(text, text.length - 1); 22482 } else { 22483 return CaretPosition(caret.get(), caret.get().length - 1); 22484 } 22485 }); 22486 }, function (element) { 22487 remove$2(caret.get()); 22488 var text = insertInlineAfter(element); 22489 caret.set(text); 22490 return Optional.some(CaretPosition(text, 1)); 22491 }); 22492 }; 22493 22494 var evaluateUntil = function (fns, args) { 22495 for (var i = 0; i < fns.length; i++) { 22496 var result = fns[i].apply(null, args); 22497 if (result.isSome()) { 22498 return result; 22499 } 22500 } 22501 return Optional.none(); 22502 }; 22503 22504 var Location = Adt.generate([ 22505 { before: ['element'] }, 22506 { start: ['element'] }, 22507 { end: ['element'] }, 22508 { after: ['element'] } 22509 ]); 22510 var rescope$1 = function (rootNode, node) { 22511 var parentBlock = getParentBlock$2(node, rootNode); 22512 return parentBlock ? parentBlock : rootNode; 22513 }; 22514 var before = function (isInlineTarget, rootNode, pos) { 22515 var nPos = normalizeForwards(pos); 22516 var scope = rescope$1(rootNode, nPos.container()); 22517 return findRootInline(isInlineTarget, scope, nPos).fold(function () { 22518 return nextPosition(scope, nPos).bind(curry(findRootInline, isInlineTarget, scope)).map(function (inline) { 22519 return Location.before(inline); 22520 }); 22521 }, Optional.none); 22522 }; 22523 var isNotInsideFormatCaretContainer = function (rootNode, elm) { 22524 return getParentCaretContainer(rootNode, elm) === null; 22525 }; 22526 var findInsideRootInline = function (isInlineTarget, rootNode, pos) { 22527 return findRootInline(isInlineTarget, rootNode, pos).filter(curry(isNotInsideFormatCaretContainer, rootNode)); 22528 }; 22529 var start$1 = function (isInlineTarget, rootNode, pos) { 22530 var nPos = normalizeBackwards(pos); 22531 return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (inline) { 22532 var prevPos = prevPosition(inline, nPos); 22533 return prevPos.isNone() ? Optional.some(Location.start(inline)) : Optional.none(); 22534 }); 22535 }; 22536 var end = function (isInlineTarget, rootNode, pos) { 22537 var nPos = normalizeForwards(pos); 22538 return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (inline) { 22539 var nextPos = nextPosition(inline, nPos); 22540 return nextPos.isNone() ? Optional.some(Location.end(inline)) : Optional.none(); 22541 }); 22542 }; 22543 var after = function (isInlineTarget, rootNode, pos) { 22544 var nPos = normalizeBackwards(pos); 22545 var scope = rescope$1(rootNode, nPos.container()); 22546 return findRootInline(isInlineTarget, scope, nPos).fold(function () { 22547 return prevPosition(scope, nPos).bind(curry(findRootInline, isInlineTarget, scope)).map(function (inline) { 22548 return Location.after(inline); 22549 }); 22550 }, Optional.none); 22551 }; 22552 var isValidLocation = function (location) { 22553 return isRtl(getElement(location)) === false; 22554 }; 22555 var readLocation = function (isInlineTarget, rootNode, pos) { 22556 var location = evaluateUntil([ 22557 before, 22558 start$1, 22559 end, 22560 after 22561 ], [ 22562 isInlineTarget, 22563 rootNode, 22564 pos 22565 ]); 22566 return location.filter(isValidLocation); 22567 }; 22568 var getElement = function (location) { 22569 return location.fold(identity, identity, identity, identity); 22570 }; 22571 var getName = function (location) { 22572 return location.fold(constant('before'), constant('start'), constant('end'), constant('after')); 22573 }; 22574 var outside = function (location) { 22575 return location.fold(Location.before, Location.before, Location.after, Location.after); 22576 }; 22577 var inside = function (location) { 22578 return location.fold(Location.start, Location.start, Location.end, Location.end); 22579 }; 22580 var isEq = function (location1, location2) { 22581 return getName(location1) === getName(location2) && getElement(location1) === getElement(location2); 22582 }; 22583 var betweenInlines = function (forward, isInlineTarget, rootNode, from, to, location) { 22584 return lift2(findRootInline(isInlineTarget, rootNode, from), findRootInline(isInlineTarget, rootNode, to), function (fromInline, toInline) { 22585 if (fromInline !== toInline && hasSameParentBlock(rootNode, fromInline, toInline)) { 22586 return Location.after(forward ? fromInline : toInline); 22587 } else { 22588 return location; 22589 } 22590 }).getOr(location); 22591 }; 22592 var skipNoMovement = function (fromLocation, toLocation) { 22593 return fromLocation.fold(always, function (fromLocation) { 22594 return !isEq(fromLocation, toLocation); 22595 }); 22596 }; 22597 var findLocationTraverse = function (forward, isInlineTarget, rootNode, fromLocation, pos) { 22598 var from = normalizePosition(forward, pos); 22599 var to = fromPosition(forward, rootNode, from).map(curry(normalizePosition, forward)); 22600 var location = to.fold(function () { 22601 return fromLocation.map(outside); 22602 }, function (to) { 22603 return readLocation(isInlineTarget, rootNode, to).map(curry(betweenInlines, forward, isInlineTarget, rootNode, from, to)).filter(curry(skipNoMovement, fromLocation)); 22604 }); 22605 return location.filter(isValidLocation); 22606 }; 22607 var findLocationSimple = function (forward, location) { 22608 if (forward) { 22609 return location.fold(compose(Optional.some, Location.start), Optional.none, compose(Optional.some, Location.after), Optional.none); 22610 } else { 22611 return location.fold(Optional.none, compose(Optional.some, Location.before), Optional.none, compose(Optional.some, Location.end)); 22612 } 22613 }; 22614 var findLocation$1 = function (forward, isInlineTarget, rootNode, pos) { 22615 var from = normalizePosition(forward, pos); 22616 var fromLocation = readLocation(isInlineTarget, rootNode, from); 22617 return readLocation(isInlineTarget, rootNode, from).bind(curry(findLocationSimple, forward)).orThunk(function () { 22618 return findLocationTraverse(forward, isInlineTarget, rootNode, fromLocation, pos); 22619 }); 22620 }; 22621 curry(findLocation$1, false); 22622 curry(findLocation$1, true); 22623 22624 var hasSelectionModifyApi = function (editor) { 22625 return isFunction(editor.selection.getSel().modify); 22626 }; 22627 var moveRel = function (forward, selection, pos) { 22628 var delta = forward ? 1 : -1; 22629 selection.setRng(CaretPosition(pos.container(), pos.offset() + delta).toRange()); 22630 selection.getSel().modify('move', forward ? 'forward' : 'backward', 'word'); 22631 return true; 22632 }; 22633 var moveByWord = function (forward, editor) { 22634 var rng = editor.selection.getRng(); 22635 var pos = forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng); 22636 if (!hasSelectionModifyApi(editor)) { 22637 return false; 22638 } else if (forward && isBeforeInline(pos)) { 22639 return moveRel(true, editor.selection, pos); 22640 } else if (!forward && isAfterInline(pos)) { 22641 return moveRel(false, editor.selection, pos); 22642 } else { 22643 return false; 22644 } 22645 }; 22646 22647 var BreakType; 22648 (function (BreakType) { 22649 BreakType[BreakType['Br'] = 0] = 'Br'; 22650 BreakType[BreakType['Block'] = 1] = 'Block'; 22651 BreakType[BreakType['Wrap'] = 2] = 'Wrap'; 22652 BreakType[BreakType['Eol'] = 3] = 'Eol'; 22653 }(BreakType || (BreakType = {}))); 22654 var flip = function (direction, positions) { 22655 return direction === HDirection.Backwards ? reverse(positions) : positions; 22656 }; 22657 var walk = function (direction, caretWalker, pos) { 22658 return direction === HDirection.Forwards ? caretWalker.next(pos) : caretWalker.prev(pos); 22659 }; 22660 var getBreakType = function (scope, direction, currentPos, nextPos) { 22661 if (isBr$5(nextPos.getNode(direction === HDirection.Forwards))) { 22662 return BreakType.Br; 22663 } else if (isInSameBlock(currentPos, nextPos) === false) { 22664 return BreakType.Block; 22665 } else { 22666 return BreakType.Wrap; 22667 } 22668 }; 22669 var getPositionsUntil = function (predicate, direction, scope, start) { 22670 var caretWalker = CaretWalker(scope); 22671 var currentPos = start; 22672 var positions = []; 22673 while (currentPos) { 22674 var nextPos = walk(direction, caretWalker, currentPos); 22675 if (!nextPos) { 22676 break; 22677 } 22678 if (isBr$5(nextPos.getNode(false))) { 22679 if (direction === HDirection.Forwards) { 22680 return { 22681 positions: flip(direction, positions).concat([nextPos]), 22682 breakType: BreakType.Br, 22683 breakAt: Optional.some(nextPos) 22684 }; 22685 } else { 22686 return { 22687 positions: flip(direction, positions), 22688 breakType: BreakType.Br, 22689 breakAt: Optional.some(nextPos) 22690 }; 22691 } 22692 } 22693 if (!nextPos.isVisible()) { 22694 currentPos = nextPos; 22695 continue; 22696 } 22697 if (predicate(currentPos, nextPos)) { 22698 var breakType = getBreakType(scope, direction, currentPos, nextPos); 22699 return { 22700 positions: flip(direction, positions), 22701 breakType: breakType, 22702 breakAt: Optional.some(nextPos) 22703 }; 22704 } 22705 positions.push(nextPos); 22706 currentPos = nextPos; 22707 } 22708 return { 22709 positions: flip(direction, positions), 22710 breakType: BreakType.Eol, 22711 breakAt: Optional.none() 22712 }; 22713 }; 22714 var getAdjacentLinePositions = function (direction, getPositionsUntilBreak, scope, start) { 22715 return getPositionsUntilBreak(scope, start).breakAt.map(function (pos) { 22716 var positions = getPositionsUntilBreak(scope, pos).positions; 22717 return direction === HDirection.Backwards ? positions.concat(pos) : [pos].concat(positions); 22718 }).getOr([]); 22719 }; 22720 var findClosestHorizontalPositionFromPoint = function (positions, x) { 22721 return foldl(positions, function (acc, newPos) { 22722 return acc.fold(function () { 22723 return Optional.some(newPos); 22724 }, function (lastPos) { 22725 return lift2(head(lastPos.getClientRects()), head(newPos.getClientRects()), function (lastRect, newRect) { 22726 var lastDist = Math.abs(x - lastRect.left); 22727 var newDist = Math.abs(x - newRect.left); 22728 return newDist <= lastDist ? newPos : lastPos; 22729 }).or(acc); 22730 }); 22731 }, Optional.none()); 22732 }; 22733 var findClosestHorizontalPosition = function (positions, pos) { 22734 return head(pos.getClientRects()).bind(function (targetRect) { 22735 return findClosestHorizontalPositionFromPoint(positions, targetRect.left); 22736 }); 22737 }; 22738 var getPositionsUntilPreviousLine = curry(getPositionsUntil, CaretPosition.isAbove, -1); 22739 var getPositionsUntilNextLine = curry(getPositionsUntil, CaretPosition.isBelow, 1); 22740 var getPositionsAbove = curry(getAdjacentLinePositions, -1, getPositionsUntilPreviousLine); 22741 var getPositionsBelow = curry(getAdjacentLinePositions, 1, getPositionsUntilNextLine); 22742 var isAtFirstLine = function (scope, pos) { 22743 return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone(); 22744 }; 22745 var isAtLastLine = function (scope, pos) { 22746 return getPositionsUntilNextLine(scope, pos).breakAt.isNone(); 22747 }; 22748 var getFirstLinePositions = function (scope) { 22749 return firstPositionIn(scope).map(function (pos) { 22750 return [pos].concat(getPositionsUntilNextLine(scope, pos).positions); 22751 }).getOr([]); 22752 }; 22753 var getLastLinePositions = function (scope) { 22754 return lastPositionIn(scope).map(function (pos) { 22755 return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos); 22756 }).getOr([]); 22757 }; 22758 22759 var getNodeClientRects = function (node) { 22760 var toArrayWithNode = function (clientRects) { 22761 return map$3(clientRects, function (rect) { 22762 var clientRect = clone(rect); 22763 clientRect.node = node; 22764 return clientRect; 22765 }); 22766 }; 22767 if (isElement$5(node)) { 22768 return toArrayWithNode(node.getClientRects()); 22769 } 22770 if (isText$7(node)) { 22771 var rng = node.ownerDocument.createRange(); 22772 rng.setStart(node, 0); 22773 rng.setEnd(node, node.data.length); 22774 return toArrayWithNode(rng.getClientRects()); 22775 } 22776 }; 22777 var getClientRects = function (nodes) { 22778 return bind(nodes, getNodeClientRects); 22779 }; 22780 22781 var VDirection; 22782 (function (VDirection) { 22783 VDirection[VDirection['Up'] = -1] = 'Up'; 22784 VDirection[VDirection['Down'] = 1] = 'Down'; 22785 }(VDirection || (VDirection = {}))); 22786 var findUntil = function (direction, root, predicateFn, node) { 22787 while (node = findNode$1(node, direction, isEditableCaretCandidate$1, root)) { 22788 if (predicateFn(node)) { 22789 return; 22790 } 22791 } 22792 }; 22793 var walkUntil$1 = function (direction, isAboveFn, isBeflowFn, root, predicateFn, caretPosition) { 22794 var line = 0; 22795 var result = []; 22796 var add = function (node) { 22797 var clientRects = getClientRects([node]); 22798 if (direction === -1) { 22799 clientRects = clientRects.reverse(); 22800 } 22801 for (var i = 0; i < clientRects.length; i++) { 22802 var clientRect = clientRects[i]; 22803 if (isBeflowFn(clientRect, targetClientRect)) { 22804 continue; 22805 } 22806 if (result.length > 0 && isAboveFn(clientRect, last$1(result))) { 22807 line++; 22808 } 22809 clientRect.line = line; 22810 if (predicateFn(clientRect)) { 22811 return true; 22812 } 22813 result.push(clientRect); 22814 } 22815 }; 22816 var targetClientRect = last$1(caretPosition.getClientRects()); 22817 if (!targetClientRect) { 22818 return result; 22819 } 22820 var node = caretPosition.getNode(); 22821 add(node); 22822 findUntil(direction, root, add, node); 22823 return result; 22824 }; 22825 var aboveLineNumber = function (lineNumber, clientRect) { 22826 return clientRect.line > lineNumber; 22827 }; 22828 var isLineNumber = function (lineNumber, clientRect) { 22829 return clientRect.line === lineNumber; 22830 }; 22831 var upUntil = curry(walkUntil$1, VDirection.Up, isAbove$1, isBelow$1); 22832 var downUntil = curry(walkUntil$1, VDirection.Down, isBelow$1, isAbove$1); 22833 var positionsUntil = function (direction, root, predicateFn, node) { 22834 var caretWalker = CaretWalker(root); 22835 var walkFn; 22836 var isBelowFn; 22837 var isAboveFn; 22838 var caretPosition; 22839 var result = []; 22840 var line = 0; 22841 var getClientRect = function (caretPosition) { 22842 if (direction === 1) { 22843 return last$1(caretPosition.getClientRects()); 22844 } 22845 return last$1(caretPosition.getClientRects()); 22846 }; 22847 if (direction === 1) { 22848 walkFn = caretWalker.next; 22849 isBelowFn = isBelow$1; 22850 isAboveFn = isAbove$1; 22851 caretPosition = CaretPosition.after(node); 22852 } else { 22853 walkFn = caretWalker.prev; 22854 isBelowFn = isAbove$1; 22855 isAboveFn = isBelow$1; 22856 caretPosition = CaretPosition.before(node); 22857 } 22858 var targetClientRect = getClientRect(caretPosition); 22859 do { 22860 if (!caretPosition.isVisible()) { 22861 continue; 22862 } 22863 var rect = getClientRect(caretPosition); 22864 if (isAboveFn(rect, targetClientRect)) { 22865 continue; 22866 } 22867 if (result.length > 0 && isBelowFn(rect, last$1(result))) { 22868 line++; 22869 } 22870 var clientRect = clone(rect); 22871 clientRect.position = caretPosition; 22872 clientRect.line = line; 22873 if (predicateFn(clientRect)) { 22874 return result; 22875 } 22876 result.push(clientRect); 22877 } while (caretPosition = walkFn(caretPosition)); 22878 return result; 22879 }; 22880 var isAboveLine = function (lineNumber) { 22881 return function (clientRect) { 22882 return aboveLineNumber(lineNumber, clientRect); 22883 }; 22884 }; 22885 var isLine = function (lineNumber) { 22886 return function (clientRect) { 22887 return isLineNumber(lineNumber, clientRect); 22888 }; 22889 }; 22890 22891 var isContentEditableFalse$3 = isContentEditableFalse$b; 22892 var findNode = findNode$1; 22893 var distanceToRectLeft = function (clientRect, clientX) { 22894 return Math.abs(clientRect.left - clientX); 22895 }; 22896 var distanceToRectRight = function (clientRect, clientX) { 22897 return Math.abs(clientRect.right - clientX); 22898 }; 22899 var isInsideX = function (clientX, clientRect) { 22900 return clientX >= clientRect.left && clientX <= clientRect.right; 22901 }; 22902 var isInsideY = function (clientY, clientRect) { 22903 return clientY >= clientRect.top && clientY <= clientRect.bottom; 22904 }; 22905 var isNodeClientRect = function (rect) { 22906 return hasNonNullableKey(rect, 'node'); 22907 }; 22908 var findClosestClientRect = function (clientRects, clientX, allowInside) { 22909 if (allowInside === void 0) { 22910 allowInside = always; 22911 } 22912 return reduce(clientRects, function (oldClientRect, clientRect) { 22913 if (isInsideX(clientX, clientRect)) { 22914 return allowInside(clientRect) ? clientRect : oldClientRect; 22915 } 22916 if (isInsideX(clientX, oldClientRect)) { 22917 return allowInside(oldClientRect) ? oldClientRect : clientRect; 22918 } 22919 var oldDistance = Math.min(distanceToRectLeft(oldClientRect, clientX), distanceToRectRight(oldClientRect, clientX)); 22920 var newDistance = Math.min(distanceToRectLeft(clientRect, clientX), distanceToRectRight(clientRect, clientX)); 22921 if (newDistance === oldDistance && isNodeClientRect(clientRect) && isContentEditableFalse$3(clientRect.node)) { 22922 return clientRect; 22923 } 22924 if (newDistance < oldDistance) { 22925 return clientRect; 22926 } 22927 return oldClientRect; 22928 }); 22929 }; 22930 var walkUntil = function (direction, root, predicateFn, startNode, includeChildren) { 22931 var node = findNode(startNode, direction, isEditableCaretCandidate$1, root, !includeChildren); 22932 do { 22933 if (!node || predicateFn(node)) { 22934 return; 22935 } 22936 } while (node = findNode(node, direction, isEditableCaretCandidate$1, root)); 22937 }; 22938 var findLineNodeRects = function (root, targetNodeRect, includeChildren) { 22939 if (includeChildren === void 0) { 22940 includeChildren = true; 22941 } 22942 var clientRects = []; 22943 var collect = function (checkPosFn, node) { 22944 var lineRects = filter$4(getClientRects([node]), function (clientRect) { 22945 return !checkPosFn(clientRect, targetNodeRect); 22946 }); 22947 clientRects = clientRects.concat(lineRects); 22948 return lineRects.length === 0; 22949 }; 22950 clientRects.push(targetNodeRect); 22951 walkUntil(VDirection.Up, root, curry(collect, isAbove$1), targetNodeRect.node, includeChildren); 22952 walkUntil(VDirection.Down, root, curry(collect, isBelow$1), targetNodeRect.node, includeChildren); 22953 return clientRects; 22954 }; 22955 var getFakeCaretTargets = function (root) { 22956 return filter$4(from(root.getElementsByTagName('*')), isFakeCaretTarget); 22957 }; 22958 var caretInfo = function (clientRect, clientX) { 22959 return { 22960 node: clientRect.node, 22961 before: distanceToRectLeft(clientRect, clientX) < distanceToRectRight(clientRect, clientX) 22962 }; 22963 }; 22964 var closestFakeCaret = function (root, clientX, clientY) { 22965 var fakeTargetNodeRects = getClientRects(getFakeCaretTargets(root)); 22966 var targetNodeRects = filter$4(fakeTargetNodeRects, curry(isInsideY, clientY)); 22967 var checkInside = function (clientRect) { 22968 return !isTable$3(clientRect.node) && !isMedia$2(clientRect.node); 22969 }; 22970 var closestNodeRect = findClosestClientRect(targetNodeRects, clientX, checkInside); 22971 if (closestNodeRect) { 22972 var includeChildren = checkInside(closestNodeRect); 22973 closestNodeRect = findClosestClientRect(findLineNodeRects(root, closestNodeRect, includeChildren), clientX, checkInside); 22974 if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) { 22975 return caretInfo(closestNodeRect, clientX); 22976 } 22977 } 22978 return null; 22979 }; 22980 22981 var moveToRange = function (editor, rng) { 22982 editor.selection.setRng(rng); 22983 scrollRangeIntoView(editor, editor.selection.getRng()); 22984 }; 22985 var renderRangeCaretOpt = function (editor, range, scrollIntoView) { 22986 return Optional.some(renderRangeCaret(editor, range, scrollIntoView)); 22987 }; 22988 var moveHorizontally = function (editor, direction, range, isBefore, isAfter, isElement) { 22989 var forwards = direction === HDirection.Forwards; 22990 var caretWalker = CaretWalker(editor.getBody()); 22991 var getNextPosFn = curry(getVisualCaretPosition, forwards ? caretWalker.next : caretWalker.prev); 22992 var isBeforeFn = forwards ? isBefore : isAfter; 22993 if (!range.collapsed) { 22994 var node = getSelectedNode(range); 22995 if (isElement(node)) { 22996 return showCaret(direction, editor, node, direction === HDirection.Backwards, false); 22997 } 22998 } 22999 var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range); 23000 if (isBeforeFn(caretPosition)) { 23001 return selectNode(editor, caretPosition.getNode(!forwards)); 23002 } 23003 var nextCaretPosition = normalizePosition(forwards, getNextPosFn(caretPosition)); 23004 var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range); 23005 if (!nextCaretPosition) { 23006 return rangeIsInContainerBlock ? Optional.some(range) : Optional.none(); 23007 } 23008 if (isBeforeFn(nextCaretPosition)) { 23009 return showCaret(direction, editor, nextCaretPosition.getNode(!forwards), forwards, false); 23010 } 23011 var peekCaretPosition = getNextPosFn(nextCaretPosition); 23012 if (peekCaretPosition && isBeforeFn(peekCaretPosition)) { 23013 if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) { 23014 return showCaret(direction, editor, peekCaretPosition.getNode(!forwards), forwards, false); 23015 } 23016 } 23017 if (rangeIsInContainerBlock) { 23018 return renderRangeCaretOpt(editor, nextCaretPosition.toRange(), false); 23019 } 23020 return Optional.none(); 23021 }; 23022 var moveVertically = function (editor, direction, range, isBefore, isAfter, isElement) { 23023 var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range); 23024 var caretClientRect = last$1(caretPosition.getClientRects()); 23025 var forwards = direction === VDirection.Down; 23026 if (!caretClientRect) { 23027 return Optional.none(); 23028 } 23029 var walkerFn = forwards ? downUntil : upUntil; 23030 var linePositions = walkerFn(editor.getBody(), isAboveLine(1), caretPosition); 23031 var nextLinePositions = filter$4(linePositions, isLine(1)); 23032 var clientX = caretClientRect.left; 23033 var nextLineRect = findClosestClientRect(nextLinePositions, clientX); 23034 if (nextLineRect && isElement(nextLineRect.node)) { 23035 var dist1 = Math.abs(clientX - nextLineRect.left); 23036 var dist2 = Math.abs(clientX - nextLineRect.right); 23037 return showCaret(direction, editor, nextLineRect.node, dist1 < dist2, false); 23038 } 23039 var currentNode; 23040 if (isBefore(caretPosition)) { 23041 currentNode = caretPosition.getNode(); 23042 } else if (isAfter(caretPosition)) { 23043 currentNode = caretPosition.getNode(true); 23044 } else { 23045 currentNode = getSelectedNode(range); 23046 } 23047 if (currentNode) { 23048 var caretPositions = positionsUntil(direction, editor.getBody(), isAboveLine(1), currentNode); 23049 var closestNextLineRect = findClosestClientRect(filter$4(caretPositions, isLine(1)), clientX); 23050 if (closestNextLineRect) { 23051 return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false); 23052 } 23053 closestNextLineRect = last$1(filter$4(caretPositions, isLine(0))); 23054 if (closestNextLineRect) { 23055 return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false); 23056 } 23057 } 23058 if (nextLinePositions.length === 0) { 23059 return getLineEndPoint(editor, forwards).filter(forwards ? isAfter : isBefore).map(function (pos) { 23060 return renderRangeCaret(editor, pos.toRange(), false); 23061 }); 23062 } 23063 return Optional.none(); 23064 }; 23065 var getLineEndPoint = function (editor, forward) { 23066 var rng = editor.selection.getRng(); 23067 var body = editor.getBody(); 23068 if (forward) { 23069 var from = CaretPosition.fromRangeEnd(rng); 23070 var result = getPositionsUntilNextLine(body, from); 23071 return last$2(result.positions); 23072 } else { 23073 var from = CaretPosition.fromRangeStart(rng); 23074 var result = getPositionsUntilPreviousLine(body, from); 23075 return head(result.positions); 23076 } 23077 }; 23078 var moveToLineEndPoint$3 = function (editor, forward, isElementPosition) { 23079 return getLineEndPoint(editor, forward).filter(isElementPosition).exists(function (pos) { 23080 editor.selection.setRng(pos.toRange()); 23081 return true; 23082 }); 23083 }; 23084 23085 var setCaretPosition = function (editor, pos) { 23086 var rng = editor.dom.createRng(); 23087 rng.setStart(pos.container(), pos.offset()); 23088 rng.setEnd(pos.container(), pos.offset()); 23089 editor.selection.setRng(rng); 23090 }; 23091 var setSelected = function (state, elm) { 23092 if (state) { 23093 elm.setAttribute('data-mce-selected', 'inline-boundary'); 23094 } else { 23095 elm.removeAttribute('data-mce-selected'); 23096 } 23097 }; 23098 var renderCaretLocation = function (editor, caret, location) { 23099 return renderCaret(caret, location).map(function (pos) { 23100 setCaretPosition(editor, pos); 23101 return location; 23102 }); 23103 }; 23104 var findLocation = function (editor, caret, forward) { 23105 var rootNode = editor.getBody(); 23106 var from = CaretPosition.fromRangeStart(editor.selection.getRng()); 23107 var isInlineTarget$1 = curry(isInlineTarget, editor); 23108 var location = findLocation$1(forward, isInlineTarget$1, rootNode, from); 23109 return location.bind(function (location) { 23110 return renderCaretLocation(editor, caret, location); 23111 }); 23112 }; 23113 var toggleInlines = function (isInlineTarget, dom, elms) { 23114 var inlineBoundaries = map$3(descendants(SugarElement.fromDom(dom.getRoot()), '*[data-mce-selected="inline-boundary"]'), function (e) { 23115 return e.dom; 23116 }); 23117 var selectedInlines = filter$4(inlineBoundaries, isInlineTarget); 23118 var targetInlines = filter$4(elms, isInlineTarget); 23119 each$k(difference(selectedInlines, targetInlines), curry(setSelected, false)); 23120 each$k(difference(targetInlines, selectedInlines), curry(setSelected, true)); 23121 }; 23122 var safeRemoveCaretContainer = function (editor, caret) { 23123 if (editor.selection.isCollapsed() && editor.composing !== true && caret.get()) { 23124 var pos = CaretPosition.fromRangeStart(editor.selection.getRng()); 23125 if (CaretPosition.isTextPosition(pos) && isAtZwsp(pos) === false) { 23126 setCaretPosition(editor, removeAndReposition(caret.get(), pos)); 23127 caret.set(null); 23128 } 23129 } 23130 }; 23131 var renderInsideInlineCaret = function (isInlineTarget, editor, caret, elms) { 23132 if (editor.selection.isCollapsed()) { 23133 var inlines = filter$4(elms, isInlineTarget); 23134 each$k(inlines, function (_inline) { 23135 var pos = CaretPosition.fromRangeStart(editor.selection.getRng()); 23136 readLocation(isInlineTarget, editor.getBody(), pos).bind(function (location) { 23137 return renderCaretLocation(editor, caret, location); 23138 }); 23139 }); 23140 } 23141 }; 23142 var move$2 = function (editor, caret, forward) { 23143 return isInlineBoundariesEnabled(editor) ? findLocation(editor, caret, forward).isSome() : false; 23144 }; 23145 var moveWord = function (forward, editor, _caret) { 23146 return isInlineBoundariesEnabled(editor) ? moveByWord(forward, editor) : false; 23147 }; 23148 var setupSelectedState = function (editor) { 23149 var caret = Cell(null); 23150 var isInlineTarget$1 = curry(isInlineTarget, editor); 23151 editor.on('NodeChange', function (e) { 23152 if (isInlineBoundariesEnabled(editor) && !(Env.browser.isIE() && e.initial)) { 23153 toggleInlines(isInlineTarget$1, editor.dom, e.parents); 23154 safeRemoveCaretContainer(editor, caret); 23155 renderInsideInlineCaret(isInlineTarget$1, editor, caret, e.parents); 23156 } 23157 }); 23158 return caret; 23159 }; 23160 var moveNextWord = curry(moveWord, true); 23161 var movePrevWord = curry(moveWord, false); 23162 var moveToLineEndPoint$2 = function (editor, forward, caret) { 23163 if (isInlineBoundariesEnabled(editor)) { 23164 var linePoint = getLineEndPoint(editor, forward).getOrThunk(function () { 23165 var rng = editor.selection.getRng(); 23166 return forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng); 23167 }); 23168 return readLocation(curry(isInlineTarget, editor), editor.getBody(), linePoint).exists(function (loc) { 23169 var outsideLoc = outside(loc); 23170 return renderCaret(caret, outsideLoc).exists(function (pos) { 23171 setCaretPosition(editor, pos); 23172 return true; 23173 }); 23174 }); 23175 } else { 23176 return false; 23177 } 23178 }; 23179 23180 var rangeFromPositions = function (from, to) { 23181 var range = document.createRange(); 23182 range.setStart(from.container(), from.offset()); 23183 range.setEnd(to.container(), to.offset()); 23184 return range; 23185 }; 23186 var hasOnlyTwoOrLessPositionsLeft = function (elm) { 23187 return lift2(firstPositionIn(elm), lastPositionIn(elm), function (firstPos, lastPos) { 23188 var normalizedFirstPos = normalizePosition(true, firstPos); 23189 var normalizedLastPos = normalizePosition(false, lastPos); 23190 return nextPosition(elm, normalizedFirstPos).forall(function (pos) { 23191 return pos.isEqual(normalizedLastPos); 23192 }); 23193 }).getOr(true); 23194 }; 23195 var setCaretLocation = function (editor, caret) { 23196 return function (location) { 23197 return renderCaret(caret, location).exists(function (pos) { 23198 setCaretPosition(editor, pos); 23199 return true; 23200 }); 23201 }; 23202 }; 23203 var deleteFromTo = function (editor, caret, from, to) { 23204 var rootNode = editor.getBody(); 23205 var isInlineTarget$1 = curry(isInlineTarget, editor); 23206 editor.undoManager.ignore(function () { 23207 editor.selection.setRng(rangeFromPositions(from, to)); 23208 editor.execCommand('Delete'); 23209 readLocation(isInlineTarget$1, rootNode, CaretPosition.fromRangeStart(editor.selection.getRng())).map(inside).map(setCaretLocation(editor, caret)); 23210 }); 23211 editor.nodeChanged(); 23212 }; 23213 var rescope = function (rootNode, node) { 23214 var parentBlock = getParentBlock$2(node, rootNode); 23215 return parentBlock ? parentBlock : rootNode; 23216 }; 23217 var backspaceDeleteCollapsed = function (editor, caret, forward, from) { 23218 var rootNode = rescope(editor.getBody(), from.container()); 23219 var isInlineTarget$1 = curry(isInlineTarget, editor); 23220 var fromLocation = readLocation(isInlineTarget$1, rootNode, from); 23221 return fromLocation.bind(function (location) { 23222 if (forward) { 23223 return location.fold(constant(Optional.some(inside(location))), Optional.none, constant(Optional.some(outside(location))), Optional.none); 23224 } else { 23225 return location.fold(Optional.none, constant(Optional.some(outside(location))), Optional.none, constant(Optional.some(inside(location)))); 23226 } 23227 }).map(setCaretLocation(editor, caret)).getOrThunk(function () { 23228 var toPosition = navigate(forward, rootNode, from); 23229 var toLocation = toPosition.bind(function (pos) { 23230 return readLocation(isInlineTarget$1, rootNode, pos); 23231 }); 23232 return lift2(fromLocation, toLocation, function () { 23233 return findRootInline(isInlineTarget$1, rootNode, from).exists(function (elm) { 23234 if (hasOnlyTwoOrLessPositionsLeft(elm)) { 23235 deleteElement$2(editor, forward, SugarElement.fromDom(elm)); 23236 return true; 23237 } else { 23238 return false; 23239 } 23240 }); 23241 }).orThunk(function () { 23242 return toLocation.bind(function (_) { 23243 return toPosition.map(function (to) { 23244 if (forward) { 23245 deleteFromTo(editor, caret, from, to); 23246 } else { 23247 deleteFromTo(editor, caret, to, from); 23248 } 23249 return true; 23250 }); 23251 }); 23252 }).getOr(false); 23253 }); 23254 }; 23255 var backspaceDelete$3 = function (editor, caret, forward) { 23256 if (editor.selection.isCollapsed() && isInlineBoundariesEnabled(editor)) { 23257 var from = CaretPosition.fromRangeStart(editor.selection.getRng()); 23258 return backspaceDeleteCollapsed(editor, caret, forward, from); 23259 } 23260 return false; 23261 }; 23262 23263 var getParentInlines = function (rootElm, startElm) { 23264 var parents = parentsAndSelf(startElm, rootElm); 23265 return findIndex$2(parents, isBlock$2).fold(constant(parents), function (index) { 23266 return parents.slice(0, index); 23267 }); 23268 }; 23269 var hasOnlyOneChild = function (elm) { 23270 return childNodesCount(elm) === 1; 23271 }; 23272 var deleteLastPosition = function (forward, editor, target, parentInlines) { 23273 var isFormatElement$1 = curry(isFormatElement, editor); 23274 var formatNodes = map$3(filter$4(parentInlines, isFormatElement$1), function (elm) { 23275 return elm.dom; 23276 }); 23277 if (formatNodes.length === 0) { 23278 deleteElement$2(editor, forward, target); 23279 } else { 23280 var pos = replaceWithCaretFormat(target.dom, formatNodes); 23281 editor.selection.setRng(pos.toRange()); 23282 } 23283 }; 23284 var deleteCaret$1 = function (editor, forward) { 23285 var rootElm = SugarElement.fromDom(editor.getBody()); 23286 var startElm = SugarElement.fromDom(editor.selection.getStart()); 23287 var parentInlines = filter$4(getParentInlines(rootElm, startElm), hasOnlyOneChild); 23288 return last$2(parentInlines).exists(function (target) { 23289 var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng()); 23290 if (willDeleteLastPositionInElement(forward, fromPos, target.dom) && !isEmptyCaretFormatElement(target)) { 23291 deleteLastPosition(forward, editor, target, parentInlines); 23292 return true; 23293 } else { 23294 return false; 23295 } 23296 }); 23297 }; 23298 var backspaceDelete$2 = function (editor, forward) { 23299 return editor.selection.isCollapsed() ? deleteCaret$1(editor, forward) : false; 23300 }; 23301 23302 var deleteElement = function (editor, forward, element) { 23303 editor._selectionOverrides.hideFakeCaret(); 23304 deleteElement$2(editor, forward, SugarElement.fromDom(element)); 23305 return true; 23306 }; 23307 var deleteCaret = function (editor, forward) { 23308 var isNearMedia = forward ? isBeforeMedia : isAfterMedia; 23309 var direction = forward ? HDirection.Forwards : HDirection.Backwards; 23310 var fromPos = getNormalizedRangeEndPoint(direction, editor.getBody(), editor.selection.getRng()); 23311 if (isNearMedia(fromPos)) { 23312 return deleteElement(editor, forward, fromPos.getNode(!forward)); 23313 } else { 23314 return Optional.from(normalizePosition(forward, fromPos)).filter(function (pos) { 23315 return isNearMedia(pos) && isMoveInsideSameBlock(fromPos, pos); 23316 }).exists(function (pos) { 23317 return deleteElement(editor, forward, pos.getNode(!forward)); 23318 }); 23319 } 23320 }; 23321 var deleteRange = function (editor, forward) { 23322 var selectedNode = editor.selection.getNode(); 23323 return isMedia$2(selectedNode) ? deleteElement(editor, forward, selectedNode) : false; 23324 }; 23325 var backspaceDelete$1 = function (editor, forward) { 23326 return editor.selection.isCollapsed() ? deleteCaret(editor, forward) : deleteRange(editor, forward); 23327 }; 23328 23329 var isEditable = function (target) { 23330 return closest$3(target, function (elm) { 23331 return isContentEditableTrue$4(elm.dom) || isContentEditableFalse$b(elm.dom); 23332 }).exists(function (elm) { 23333 return isContentEditableTrue$4(elm.dom); 23334 }); 23335 }; 23336 var parseIndentValue = function (value) { 23337 var number = parseInt(value, 10); 23338 return isNaN(number) ? 0 : number; 23339 }; 23340 var getIndentStyleName = function (useMargin, element) { 23341 var indentStyleName = useMargin || isTable$2(element) ? 'margin' : 'padding'; 23342 var suffix = get$5(element, 'direction') === 'rtl' ? '-right' : '-left'; 23343 return indentStyleName + suffix; 23344 }; 23345 var indentElement = function (dom, command, useMargin, value, unit, element) { 23346 var indentStyleName = getIndentStyleName(useMargin, SugarElement.fromDom(element)); 23347 if (command === 'outdent') { 23348 var styleValue = Math.max(0, parseIndentValue(element.style[indentStyleName]) - value); 23349 dom.setStyle(element, indentStyleName, styleValue ? styleValue + unit : ''); 23350 } else { 23351 var styleValue = parseIndentValue(element.style[indentStyleName]) + value + unit; 23352 dom.setStyle(element, indentStyleName, styleValue); 23353 } 23354 }; 23355 var validateBlocks = function (editor, blocks) { 23356 return forall(blocks, function (block) { 23357 var indentStyleName = getIndentStyleName(shouldIndentUseMargin(editor), block); 23358 var intentValue = getRaw(block, indentStyleName).map(parseIndentValue).getOr(0); 23359 var contentEditable = editor.dom.getContentEditable(block.dom); 23360 return contentEditable !== 'false' && intentValue > 0; 23361 }); 23362 }; 23363 var canOutdent = function (editor) { 23364 var blocks = getBlocksToIndent(editor); 23365 return !editor.mode.isReadOnly() && (blocks.length > 1 || validateBlocks(editor, blocks)); 23366 }; 23367 var isListComponent = function (el) { 23368 return isList(el) || isListItem(el); 23369 }; 23370 var parentIsListComponent = function (el) { 23371 return parent(el).exists(isListComponent); 23372 }; 23373 var getBlocksToIndent = function (editor) { 23374 return filter$4(fromDom$1(editor.selection.getSelectedBlocks()), function (el) { 23375 return !isListComponent(el) && !parentIsListComponent(el) && isEditable(el); 23376 }); 23377 }; 23378 var handle = function (editor, command) { 23379 var dom = editor.dom, selection = editor.selection, formatter = editor.formatter; 23380 var indentation = getIndentation(editor); 23381 var indentUnit = /[a-z%]+$/i.exec(indentation)[0]; 23382 var indentValue = parseInt(indentation, 10); 23383 var useMargin = shouldIndentUseMargin(editor); 23384 var forcedRootBlock = getForcedRootBlock(editor); 23385 if (!editor.queryCommandState('InsertUnorderedList') && !editor.queryCommandState('InsertOrderedList')) { 23386 if (forcedRootBlock === '' && !dom.getParent(selection.getNode(), dom.isBlock)) { 23387 formatter.apply('div'); 23388 } 23389 } 23390 each$k(getBlocksToIndent(editor), function (block) { 23391 indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom); 23392 }); 23393 }; 23394 23395 var backspaceDelete = function (editor, _forward) { 23396 if (editor.selection.isCollapsed() && canOutdent(editor)) { 23397 var dom = editor.dom; 23398 var rng = editor.selection.getRng(); 23399 var pos = CaretPosition.fromRangeStart(rng); 23400 var block = dom.getParent(rng.startContainer, dom.isBlock); 23401 if (block !== null && isAtStartOfBlock(SugarElement.fromDom(block), pos)) { 23402 handle(editor, 'outdent'); 23403 return true; 23404 } 23405 } 23406 return false; 23407 }; 23408 23409 var nativeCommand = function (editor, command) { 23410 editor.getDoc().execCommand(command, false, null); 23411 }; 23412 var deleteCommand = function (editor, caret) { 23413 if (backspaceDelete(editor)) { 23414 return; 23415 } else if (backspaceDelete$5(editor, false)) { 23416 return; 23417 } else if (backspaceDelete$6(editor, false)) { 23418 return; 23419 } else if (backspaceDelete$3(editor, caret, false)) { 23420 return; 23421 } else if (backspaceDelete$8(editor, false)) { 23422 return; 23423 } else if (backspaceDelete$9(editor)) { 23424 return; 23425 } else if (backspaceDelete$4(editor, false)) { 23426 return; 23427 } else if (backspaceDelete$1(editor, false)) { 23428 return; 23429 } else if (backspaceDelete$7(editor)) { 23430 return; 23431 } else if (backspaceDelete$2(editor, false)) { 23432 return; 23433 } else { 23434 nativeCommand(editor, 'Delete'); 23435 paddEmptyBody(editor); 23436 } 23437 }; 23438 var forwardDeleteCommand = function (editor, caret) { 23439 if (backspaceDelete$5(editor, true)) { 23440 return; 23441 } else if (backspaceDelete$6(editor, true)) { 23442 return; 23443 } else if (backspaceDelete$3(editor, caret, true)) { 23444 return; 23445 } else if (backspaceDelete$8(editor, true)) { 23446 return; 23447 } else if (backspaceDelete$9(editor)) { 23448 return; 23449 } else if (backspaceDelete$4(editor, true)) { 23450 return; 23451 } else if (backspaceDelete$1(editor, true)) { 23452 return; 23453 } else if (backspaceDelete$7(editor)) { 23454 return; 23455 } else if (backspaceDelete$2(editor, true)) { 23456 return; 23457 } else { 23458 nativeCommand(editor, 'ForwardDelete'); 23459 } 23460 }; 23461 var setup$f = function (editor, caret) { 23462 editor.addCommand('delete', function () { 23463 deleteCommand(editor, caret); 23464 }); 23465 editor.addCommand('forwardDelete', function () { 23466 forwardDeleteCommand(editor, caret); 23467 }); 23468 }; 23469 23470 var SIGNIFICANT_MOVE = 5; 23471 var LONGPRESS_DELAY = 400; 23472 var getTouch = function (event) { 23473 if (event.touches === undefined || event.touches.length !== 1) { 23474 return Optional.none(); 23475 } 23476 return Optional.some(event.touches[0]); 23477 }; 23478 var isFarEnough = function (touch, data) { 23479 var distX = Math.abs(touch.clientX - data.x); 23480 var distY = Math.abs(touch.clientY - data.y); 23481 return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE; 23482 }; 23483 var setup$e = function (editor) { 23484 var startData = value(); 23485 var longpressFired = Cell(false); 23486 var debounceLongpress = last(function (e) { 23487 editor.fire('longpress', __assign(__assign({}, e), { type: 'longpress' })); 23488 longpressFired.set(true); 23489 }, LONGPRESS_DELAY); 23490 editor.on('touchstart', function (e) { 23491 getTouch(e).each(function (touch) { 23492 debounceLongpress.cancel(); 23493 var data = { 23494 x: touch.clientX, 23495 y: touch.clientY, 23496 target: e.target 23497 }; 23498 debounceLongpress.throttle(e); 23499 longpressFired.set(false); 23500 startData.set(data); 23501 }); 23502 }, true); 23503 editor.on('touchmove', function (e) { 23504 debounceLongpress.cancel(); 23505 getTouch(e).each(function (touch) { 23506 startData.on(function (data) { 23507 if (isFarEnough(touch, data)) { 23508 startData.clear(); 23509 longpressFired.set(false); 23510 editor.fire('longpresscancel'); 23511 } 23512 }); 23513 }); 23514 }, true); 23515 editor.on('touchend touchcancel', function (e) { 23516 debounceLongpress.cancel(); 23517 if (e.type === 'touchcancel') { 23518 return; 23519 } 23520 startData.get().filter(function (data) { 23521 return data.target.isEqualNode(e.target); 23522 }).each(function () { 23523 if (longpressFired.get()) { 23524 e.preventDefault(); 23525 } else { 23526 editor.fire('tap', __assign(__assign({}, e), { type: 'tap' })); 23527 } 23528 }); 23529 }, true); 23530 }; 23531 23532 var isBlockElement = function (blockElements, node) { 23533 return has$2(blockElements, node.nodeName); 23534 }; 23535 var isValidTarget = function (blockElements, node) { 23536 if (isText$7(node)) { 23537 return true; 23538 } else if (isElement$5(node)) { 23539 return !isBlockElement(blockElements, node) && !isBookmarkNode$1(node); 23540 } else { 23541 return false; 23542 } 23543 }; 23544 var hasBlockParent = function (blockElements, root, node) { 23545 return exists(parents(SugarElement.fromDom(node), SugarElement.fromDom(root)), function (elm) { 23546 return isBlockElement(blockElements, elm.dom); 23547 }); 23548 }; 23549 var shouldRemoveTextNode = function (blockElements, node) { 23550 if (isText$7(node)) { 23551 if (node.nodeValue.length === 0) { 23552 return true; 23553 } else if (/^\s+$/.test(node.nodeValue) && (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))) { 23554 return true; 23555 } 23556 } 23557 return false; 23558 }; 23559 var addRootBlocks = function (editor) { 23560 var dom = editor.dom, selection = editor.selection; 23561 var schema = editor.schema, blockElements = schema.getBlockElements(); 23562 var node = selection.getStart(); 23563 var rootNode = editor.getBody(); 23564 var rootBlockNode, tempNode, wrapped; 23565 var forcedRootBlock = getForcedRootBlock(editor); 23566 if (!node || !isElement$5(node) || !forcedRootBlock) { 23567 return; 23568 } 23569 var rootNodeName = rootNode.nodeName.toLowerCase(); 23570 if (!schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) || hasBlockParent(blockElements, rootNode, node)) { 23571 return; 23572 } 23573 var rng = selection.getRng(); 23574 var startContainer = rng.startContainer; 23575 var startOffset = rng.startOffset; 23576 var endContainer = rng.endContainer; 23577 var endOffset = rng.endOffset; 23578 var restoreSelection = hasFocus(editor); 23579 node = rootNode.firstChild; 23580 while (node) { 23581 if (isValidTarget(blockElements, node)) { 23582 if (shouldRemoveTextNode(blockElements, node)) { 23583 tempNode = node; 23584 node = node.nextSibling; 23585 dom.remove(tempNode); 23586 continue; 23587 } 23588 if (!rootBlockNode) { 23589 rootBlockNode = dom.create(forcedRootBlock, getForcedRootBlockAttrs(editor)); 23590 node.parentNode.insertBefore(rootBlockNode, node); 23591 wrapped = true; 23592 } 23593 tempNode = node; 23594 node = node.nextSibling; 23595 rootBlockNode.appendChild(tempNode); 23596 } else { 23597 rootBlockNode = null; 23598 node = node.nextSibling; 23599 } 23600 } 23601 if (wrapped && restoreSelection) { 23602 rng.setStart(startContainer, startOffset); 23603 rng.setEnd(endContainer, endOffset); 23604 selection.setRng(rng); 23605 editor.nodeChanged(); 23606 } 23607 }; 23608 var setup$d = function (editor) { 23609 if (getForcedRootBlock(editor)) { 23610 editor.on('NodeChange', curry(addRootBlocks, editor)); 23611 } 23612 }; 23613 23614 var findBlockCaretContainer = function (editor) { 23615 return descendant(SugarElement.fromDom(editor.getBody()), '*[data-mce-caret]').map(function (elm) { 23616 return elm.dom; 23617 }).getOrNull(); 23618 }; 23619 var removeIeControlRect = function (editor) { 23620 editor.selection.setRng(editor.selection.getRng()); 23621 }; 23622 var showBlockCaretContainer = function (editor, blockCaretContainer) { 23623 if (blockCaretContainer.hasAttribute('data-mce-caret')) { 23624 showCaretContainerBlock(blockCaretContainer); 23625 removeIeControlRect(editor); 23626 editor.selection.scrollIntoView(blockCaretContainer); 23627 } 23628 }; 23629 var handleBlockContainer = function (editor, e) { 23630 var blockCaretContainer = findBlockCaretContainer(editor); 23631 if (!blockCaretContainer) { 23632 return; 23633 } 23634 if (e.type === 'compositionstart') { 23635 e.preventDefault(); 23636 e.stopPropagation(); 23637 showBlockCaretContainer(editor, blockCaretContainer); 23638 return; 23639 } 23640 if (hasContent(blockCaretContainer)) { 23641 showBlockCaretContainer(editor, blockCaretContainer); 23642 editor.undoManager.add(); 23643 } 23644 }; 23645 var setup$c = function (editor) { 23646 editor.on('keyup compositionstart', curry(handleBlockContainer, editor)); 23647 }; 23648 23649 var isContentEditableFalse$2 = isContentEditableFalse$b; 23650 var moveToCeFalseHorizontally = function (direction, editor, range) { 23651 return moveHorizontally(editor, direction, range, isBeforeContentEditableFalse, isAfterContentEditableFalse, isContentEditableFalse$2); 23652 }; 23653 var moveToCeFalseVertically = function (direction, editor, range) { 23654 var isBefore = function (caretPosition) { 23655 return isBeforeContentEditableFalse(caretPosition) || isBeforeTable(caretPosition); 23656 }; 23657 var isAfter = function (caretPosition) { 23658 return isAfterContentEditableFalse(caretPosition) || isAfterTable(caretPosition); 23659 }; 23660 return moveVertically(editor, direction, range, isBefore, isAfter, isContentEditableFalse$2); 23661 }; 23662 var createTextBlock = function (editor) { 23663 var textBlock = editor.dom.create(getForcedRootBlock(editor)); 23664 if (!Env.ie || Env.ie >= 11) { 23665 textBlock.innerHTML = '<br data-mce-bogus="1">'; 23666 } 23667 return textBlock; 23668 }; 23669 var exitPreBlock = function (editor, direction, range) { 23670 var caretWalker = CaretWalker(editor.getBody()); 23671 var getVisualCaretPosition$1 = curry(getVisualCaretPosition, direction === 1 ? caretWalker.next : caretWalker.prev); 23672 if (range.collapsed && hasForcedRootBlock(editor)) { 23673 var pre = editor.dom.getParent(range.startContainer, 'PRE'); 23674 if (!pre) { 23675 return; 23676 } 23677 var caretPos = getVisualCaretPosition$1(CaretPosition.fromRangeStart(range)); 23678 if (!caretPos) { 23679 var newBlock = createTextBlock(editor); 23680 if (direction === 1) { 23681 editor.$(pre).after(newBlock); 23682 } else { 23683 editor.$(pre).before(newBlock); 23684 } 23685 editor.selection.select(newBlock, true); 23686 editor.selection.collapse(); 23687 } 23688 } 23689 }; 23690 var getHorizontalRange = function (editor, forward) { 23691 var direction = forward ? HDirection.Forwards : HDirection.Backwards; 23692 var range = editor.selection.getRng(); 23693 return moveToCeFalseHorizontally(direction, editor, range).orThunk(function () { 23694 exitPreBlock(editor, direction, range); 23695 return Optional.none(); 23696 }); 23697 }; 23698 var getVerticalRange = function (editor, down) { 23699 var direction = down ? 1 : -1; 23700 var range = editor.selection.getRng(); 23701 return moveToCeFalseVertically(direction, editor, range).orThunk(function () { 23702 exitPreBlock(editor, direction, range); 23703 return Optional.none(); 23704 }); 23705 }; 23706 var moveH$2 = function (editor, forward) { 23707 return getHorizontalRange(editor, forward).exists(function (newRange) { 23708 moveToRange(editor, newRange); 23709 return true; 23710 }); 23711 }; 23712 var moveV$3 = function (editor, down) { 23713 return getVerticalRange(editor, down).exists(function (newRange) { 23714 moveToRange(editor, newRange); 23715 return true; 23716 }); 23717 }; 23718 var moveToLineEndPoint$1 = function (editor, forward) { 23719 var isCefPosition = forward ? isAfterContentEditableFalse : isBeforeContentEditableFalse; 23720 return moveToLineEndPoint$3(editor, forward, isCefPosition); 23721 }; 23722 23723 var isTarget = function (node) { 23724 return contains$3(['figcaption'], name(node)); 23725 }; 23726 var rangeBefore = function (target) { 23727 var rng = document.createRange(); 23728 rng.setStartBefore(target.dom); 23729 rng.setEndBefore(target.dom); 23730 return rng; 23731 }; 23732 var insertElement = function (root, elm, forward) { 23733 if (forward) { 23734 append$1(root, elm); 23735 } else { 23736 prepend(root, elm); 23737 } 23738 }; 23739 var insertBr = function (root, forward) { 23740 var br = SugarElement.fromTag('br'); 23741 insertElement(root, br, forward); 23742 return rangeBefore(br); 23743 }; 23744 var insertBlock = function (root, forward, blockName, attrs) { 23745 var block = SugarElement.fromTag(blockName); 23746 var br = SugarElement.fromTag('br'); 23747 setAll$1(block, attrs); 23748 append$1(block, br); 23749 insertElement(root, block, forward); 23750 return rangeBefore(br); 23751 }; 23752 var insertEmptyLine = function (root, rootBlockName, attrs, forward) { 23753 if (rootBlockName === '') { 23754 return insertBr(root, forward); 23755 } else { 23756 return insertBlock(root, forward, rootBlockName, attrs); 23757 } 23758 }; 23759 var getClosestTargetBlock = function (pos, root) { 23760 var isRoot = curry(eq, root); 23761 return closest$3(SugarElement.fromDom(pos.container()), isBlock$2, isRoot).filter(isTarget); 23762 }; 23763 var isAtFirstOrLastLine = function (root, forward, pos) { 23764 return forward ? isAtLastLine(root.dom, pos) : isAtFirstLine(root.dom, pos); 23765 }; 23766 var moveCaretToNewEmptyLine = function (editor, forward) { 23767 var root = SugarElement.fromDom(editor.getBody()); 23768 var pos = CaretPosition.fromRangeStart(editor.selection.getRng()); 23769 var rootBlock = getForcedRootBlock(editor); 23770 var rootBlockAttrs = getForcedRootBlockAttrs(editor); 23771 return getClosestTargetBlock(pos, root).exists(function () { 23772 if (isAtFirstOrLastLine(root, forward, pos)) { 23773 var rng = insertEmptyLine(root, rootBlock, rootBlockAttrs, forward); 23774 editor.selection.setRng(rng); 23775 return true; 23776 } else { 23777 return false; 23778 } 23779 }); 23780 }; 23781 var moveV$2 = function (editor, forward) { 23782 if (editor.selection.isCollapsed()) { 23783 return moveCaretToNewEmptyLine(editor, forward); 23784 } else { 23785 return false; 23786 } 23787 }; 23788 23789 var defaultPatterns = function (patterns) { 23790 return map$3(patterns, function (pattern) { 23791 return __assign({ 23792 shiftKey: false, 23793 altKey: false, 23794 ctrlKey: false, 23795 metaKey: false, 23796 keyCode: 0, 23797 action: noop 23798 }, pattern); 23799 }); 23800 }; 23801 var matchesEvent = function (pattern, evt) { 23802 return evt.keyCode === pattern.keyCode && evt.shiftKey === pattern.shiftKey && evt.altKey === pattern.altKey && evt.ctrlKey === pattern.ctrlKey && evt.metaKey === pattern.metaKey; 23803 }; 23804 var match$1 = function (patterns, evt) { 23805 return bind(defaultPatterns(patterns), function (pattern) { 23806 return matchesEvent(pattern, evt) ? [pattern] : []; 23807 }); 23808 }; 23809 var action = function (f) { 23810 var x = []; 23811 for (var _i = 1; _i < arguments.length; _i++) { 23812 x[_i - 1] = arguments[_i]; 23813 } 23814 return function () { 23815 return f.apply(null, x); 23816 }; 23817 }; 23818 var execute = function (patterns, evt) { 23819 return find$3(match$1(patterns, evt), function (pattern) { 23820 return pattern.action(); 23821 }); 23822 }; 23823 23824 var moveH$1 = function (editor, forward) { 23825 var direction = forward ? HDirection.Forwards : HDirection.Backwards; 23826 var range = editor.selection.getRng(); 23827 return moveHorizontally(editor, direction, range, isBeforeMedia, isAfterMedia, isMedia$2).exists(function (newRange) { 23828 moveToRange(editor, newRange); 23829 return true; 23830 }); 23831 }; 23832 var moveV$1 = function (editor, down) { 23833 var direction = down ? 1 : -1; 23834 var range = editor.selection.getRng(); 23835 return moveVertically(editor, direction, range, isBeforeMedia, isAfterMedia, isMedia$2).exists(function (newRange) { 23836 moveToRange(editor, newRange); 23837 return true; 23838 }); 23839 }; 23840 var moveToLineEndPoint = function (editor, forward) { 23841 var isNearMedia = forward ? isAfterMedia : isBeforeMedia; 23842 return moveToLineEndPoint$3(editor, forward, isNearMedia); 23843 }; 23844 23845 var deflate = function (rect, delta) { 23846 return { 23847 left: rect.left - delta, 23848 top: rect.top - delta, 23849 right: rect.right + delta * 2, 23850 bottom: rect.bottom + delta * 2, 23851 width: rect.width + delta, 23852 height: rect.height + delta 23853 }; 23854 }; 23855 var getCorners = function (getYAxisValue, tds) { 23856 return bind(tds, function (td) { 23857 var rect = deflate(clone(td.getBoundingClientRect()), -1); 23858 return [ 23859 { 23860 x: rect.left, 23861 y: getYAxisValue(rect), 23862 cell: td 23863 }, 23864 { 23865 x: rect.right, 23866 y: getYAxisValue(rect), 23867 cell: td 23868 } 23869 ]; 23870 }); 23871 }; 23872 var findClosestCorner = function (corners, x, y) { 23873 return foldl(corners, function (acc, newCorner) { 23874 return acc.fold(function () { 23875 return Optional.some(newCorner); 23876 }, function (oldCorner) { 23877 var oldDist = Math.sqrt(Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y)); 23878 var newDist = Math.sqrt(Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y)); 23879 return Optional.some(newDist < oldDist ? newCorner : oldCorner); 23880 }); 23881 }, Optional.none()); 23882 }; 23883 var getClosestCell = function (getYAxisValue, isTargetCorner, table, x, y) { 23884 var cells = descendants(SugarElement.fromDom(table), 'td,th,caption').map(function (e) { 23885 return e.dom; 23886 }); 23887 var corners = filter$4(getCorners(getYAxisValue, cells), function (corner) { 23888 return isTargetCorner(corner, y); 23889 }); 23890 return findClosestCorner(corners, x, y).map(function (corner) { 23891 return corner.cell; 23892 }); 23893 }; 23894 var getBottomValue = function (rect) { 23895 return rect.bottom; 23896 }; 23897 var getTopValue = function (rect) { 23898 return rect.top; 23899 }; 23900 var isAbove = function (corner, y) { 23901 return corner.y < y; 23902 }; 23903 var isBelow = function (corner, y) { 23904 return corner.y > y; 23905 }; 23906 var getClosestCellAbove = curry(getClosestCell, getBottomValue, isAbove); 23907 var getClosestCellBelow = curry(getClosestCell, getTopValue, isBelow); 23908 var findClosestPositionInAboveCell = function (table, pos) { 23909 return head(pos.getClientRects()).bind(function (rect) { 23910 return getClosestCellAbove(table, rect.left, rect.top); 23911 }).bind(function (cell) { 23912 return findClosestHorizontalPosition(getLastLinePositions(cell), pos); 23913 }); 23914 }; 23915 var findClosestPositionInBelowCell = function (table, pos) { 23916 return last$2(pos.getClientRects()).bind(function (rect) { 23917 return getClosestCellBelow(table, rect.left, rect.top); 23918 }).bind(function (cell) { 23919 return findClosestHorizontalPosition(getFirstLinePositions(cell), pos); 23920 }); 23921 }; 23922 23923 var hasNextBreak = function (getPositionsUntil, scope, lineInfo) { 23924 return lineInfo.breakAt.exists(function (breakPos) { 23925 return getPositionsUntil(scope, breakPos).breakAt.isSome(); 23926 }); 23927 }; 23928 var startsWithWrapBreak = function (lineInfo) { 23929 return lineInfo.breakType === BreakType.Wrap && lineInfo.positions.length === 0; 23930 }; 23931 var startsWithBrBreak = function (lineInfo) { 23932 return lineInfo.breakType === BreakType.Br && lineInfo.positions.length === 1; 23933 }; 23934 var isAtTableCellLine = function (getPositionsUntil, scope, pos) { 23935 var lineInfo = getPositionsUntil(scope, pos); 23936 if (startsWithWrapBreak(lineInfo) || !isBr$5(pos.getNode()) && startsWithBrBreak(lineInfo)) { 23937 return !hasNextBreak(getPositionsUntil, scope, lineInfo); 23938 } else { 23939 return lineInfo.breakAt.isNone(); 23940 } 23941 }; 23942 var isAtFirstTableCellLine = curry(isAtTableCellLine, getPositionsUntilPreviousLine); 23943 var isAtLastTableCellLine = curry(isAtTableCellLine, getPositionsUntilNextLine); 23944 var isCaretAtStartOrEndOfTable = function (forward, rng, table) { 23945 var caretPos = CaretPosition.fromRangeStart(rng); 23946 return positionIn(!forward, table).exists(function (pos) { 23947 return pos.isEqual(caretPos); 23948 }); 23949 }; 23950 var navigateHorizontally = function (editor, forward, table, _td) { 23951 var rng = editor.selection.getRng(); 23952 var direction = forward ? 1 : -1; 23953 if (isFakeCaretTableBrowser() && isCaretAtStartOrEndOfTable(forward, rng, table)) { 23954 showCaret(direction, editor, table, !forward, false).each(function (newRng) { 23955 moveToRange(editor, newRng); 23956 }); 23957 return true; 23958 } 23959 return false; 23960 }; 23961 var getClosestAbovePosition = function (root, table, start) { 23962 return findClosestPositionInAboveCell(table, start).orThunk(function () { 23963 return head(start.getClientRects()).bind(function (rect) { 23964 return findClosestHorizontalPositionFromPoint(getPositionsAbove(root, CaretPosition.before(table)), rect.left); 23965 }); 23966 }).getOr(CaretPosition.before(table)); 23967 }; 23968 var getClosestBelowPosition = function (root, table, start) { 23969 return findClosestPositionInBelowCell(table, start).orThunk(function () { 23970 return head(start.getClientRects()).bind(function (rect) { 23971 return findClosestHorizontalPositionFromPoint(getPositionsBelow(root, CaretPosition.after(table)), rect.left); 23972 }); 23973 }).getOr(CaretPosition.after(table)); 23974 }; 23975 var getTable = function (previous, pos) { 23976 var node = pos.getNode(previous); 23977 return isElement$5(node) && node.nodeName === 'TABLE' ? Optional.some(node) : Optional.none(); 23978 }; 23979 var renderBlock = function (down, editor, table, pos) { 23980 var forcedRootBlock = getForcedRootBlock(editor); 23981 if (forcedRootBlock) { 23982 editor.undoManager.transact(function () { 23983 var element = SugarElement.fromTag(forcedRootBlock); 23984 setAll$1(element, getForcedRootBlockAttrs(editor)); 23985 append$1(element, SugarElement.fromTag('br')); 23986 if (down) { 23987 after$3(SugarElement.fromDom(table), element); 23988 } else { 23989 before$4(SugarElement.fromDom(table), element); 23990 } 23991 var rng = editor.dom.createRng(); 23992 rng.setStart(element.dom, 0); 23993 rng.setEnd(element.dom, 0); 23994 moveToRange(editor, rng); 23995 }); 23996 } else { 23997 moveToRange(editor, pos.toRange()); 23998 } 23999 }; 24000 var moveCaret = function (editor, down, pos) { 24001 var table = down ? getTable(true, pos) : getTable(false, pos); 24002 var last = down === false; 24003 table.fold(function () { 24004 return moveToRange(editor, pos.toRange()); 24005 }, function (table) { 24006 return positionIn(last, editor.getBody()).filter(function (lastPos) { 24007 return lastPos.isEqual(pos); 24008 }).fold(function () { 24009 return moveToRange(editor, pos.toRange()); 24010 }, function (_) { 24011 return renderBlock(down, editor, table, pos); 24012 }); 24013 }); 24014 }; 24015 var navigateVertically = function (editor, down, table, td) { 24016 var rng = editor.selection.getRng(); 24017 var pos = CaretPosition.fromRangeStart(rng); 24018 var root = editor.getBody(); 24019 if (!down && isAtFirstTableCellLine(td, pos)) { 24020 var newPos = getClosestAbovePosition(root, table, pos); 24021 moveCaret(editor, down, newPos); 24022 return true; 24023 } else if (down && isAtLastTableCellLine(td, pos)) { 24024 var newPos = getClosestBelowPosition(root, table, pos); 24025 moveCaret(editor, down, newPos); 24026 return true; 24027 } else { 24028 return false; 24029 } 24030 }; 24031 var move$1 = function (editor, forward, mover) { 24032 return Optional.from(editor.dom.getParent(editor.selection.getNode(), 'td,th')).bind(function (td) { 24033 return Optional.from(editor.dom.getParent(td, 'table')).map(function (table) { 24034 return mover(editor, forward, table, td); 24035 }); 24036 }).getOr(false); 24037 }; 24038 var moveH = function (editor, forward) { 24039 return move$1(editor, forward, navigateHorizontally); 24040 }; 24041 var moveV = function (editor, forward) { 24042 return move$1(editor, forward, navigateVertically); 24043 }; 24044 24045 var executeKeydownOverride$3 = function (editor, caret, evt) { 24046 var os = detect().os; 24047 execute([ 24048 { 24049 keyCode: VK.RIGHT, 24050 action: action(moveH$2, editor, true) 24051 }, 24052 { 24053 keyCode: VK.LEFT, 24054 action: action(moveH$2, editor, false) 24055 }, 24056 { 24057 keyCode: VK.UP, 24058 action: action(moveV$3, editor, false) 24059 }, 24060 { 24061 keyCode: VK.DOWN, 24062 action: action(moveV$3, editor, true) 24063 }, 24064 { 24065 keyCode: VK.RIGHT, 24066 action: action(moveH, editor, true) 24067 }, 24068 { 24069 keyCode: VK.LEFT, 24070 action: action(moveH, editor, false) 24071 }, 24072 { 24073 keyCode: VK.UP, 24074 action: action(moveV, editor, false) 24075 }, 24076 { 24077 keyCode: VK.DOWN, 24078 action: action(moveV, editor, true) 24079 }, 24080 { 24081 keyCode: VK.RIGHT, 24082 action: action(moveH$1, editor, true) 24083 }, 24084 { 24085 keyCode: VK.LEFT, 24086 action: action(moveH$1, editor, false) 24087 }, 24088 { 24089 keyCode: VK.UP, 24090 action: action(moveV$1, editor, false) 24091 }, 24092 { 24093 keyCode: VK.DOWN, 24094 action: action(moveV$1, editor, true) 24095 }, 24096 { 24097 keyCode: VK.RIGHT, 24098 action: action(move$2, editor, caret, true) 24099 }, 24100 { 24101 keyCode: VK.LEFT, 24102 action: action(move$2, editor, caret, false) 24103 }, 24104 { 24105 keyCode: VK.RIGHT, 24106 ctrlKey: !os.isOSX(), 24107 altKey: os.isOSX(), 24108 action: action(moveNextWord, editor, caret) 24109 }, 24110 { 24111 keyCode: VK.LEFT, 24112 ctrlKey: !os.isOSX(), 24113 altKey: os.isOSX(), 24114 action: action(movePrevWord, editor, caret) 24115 }, 24116 { 24117 keyCode: VK.UP, 24118 action: action(moveV$2, editor, false) 24119 }, 24120 { 24121 keyCode: VK.DOWN, 24122 action: action(moveV$2, editor, true) 24123 } 24124 ], evt).each(function (_) { 24125 evt.preventDefault(); 24126 }); 24127 }; 24128 var setup$b = function (editor, caret) { 24129 editor.on('keydown', function (evt) { 24130 if (evt.isDefaultPrevented() === false) { 24131 executeKeydownOverride$3(editor, caret, evt); 24132 } 24133 }); 24134 }; 24135 24136 var executeKeydownOverride$2 = function (editor, caret, evt) { 24137 execute([ 24138 { 24139 keyCode: VK.BACKSPACE, 24140 action: action(backspaceDelete, editor, false) 24141 }, 24142 { 24143 keyCode: VK.BACKSPACE, 24144 action: action(backspaceDelete$5, editor, false) 24145 }, 24146 { 24147 keyCode: VK.DELETE, 24148 action: action(backspaceDelete$5, editor, true) 24149 }, 24150 { 24151 keyCode: VK.BACKSPACE, 24152 action: action(backspaceDelete$6, editor, false) 24153 }, 24154 { 24155 keyCode: VK.DELETE, 24156 action: action(backspaceDelete$6, editor, true) 24157 }, 24158 { 24159 keyCode: VK.BACKSPACE, 24160 action: action(backspaceDelete$3, editor, caret, false) 24161 }, 24162 { 24163 keyCode: VK.DELETE, 24164 action: action(backspaceDelete$3, editor, caret, true) 24165 }, 24166 { 24167 keyCode: VK.BACKSPACE, 24168 action: action(backspaceDelete$9, editor, false) 24169 }, 24170 { 24171 keyCode: VK.DELETE, 24172 action: action(backspaceDelete$9, editor, true) 24173 }, 24174 { 24175 keyCode: VK.BACKSPACE, 24176 action: action(backspaceDelete$4, editor, false) 24177 }, 24178 { 24179 keyCode: VK.DELETE, 24180 action: action(backspaceDelete$4, editor, true) 24181 }, 24182 { 24183 keyCode: VK.BACKSPACE, 24184 action: action(backspaceDelete$1, editor, false) 24185 }, 24186 { 24187 keyCode: VK.DELETE, 24188 action: action(backspaceDelete$1, editor, true) 24189 }, 24190 { 24191 keyCode: VK.BACKSPACE, 24192 action: action(backspaceDelete$7, editor, false) 24193 }, 24194 { 24195 keyCode: VK.DELETE, 24196 action: action(backspaceDelete$7, editor, true) 24197 }, 24198 { 24199 keyCode: VK.BACKSPACE, 24200 action: action(backspaceDelete$8, editor, false) 24201 }, 24202 { 24203 keyCode: VK.DELETE, 24204 action: action(backspaceDelete$8, editor, true) 24205 }, 24206 { 24207 keyCode: VK.BACKSPACE, 24208 action: action(backspaceDelete$2, editor, false) 24209 }, 24210 { 24211 keyCode: VK.DELETE, 24212 action: action(backspaceDelete$2, editor, true) 24213 } 24214 ], evt).each(function (_) { 24215 evt.preventDefault(); 24216 }); 24217 }; 24218 var executeKeyupOverride = function (editor, evt) { 24219 execute([ 24220 { 24221 keyCode: VK.BACKSPACE, 24222 action: action(paddEmptyElement, editor) 24223 }, 24224 { 24225 keyCode: VK.DELETE, 24226 action: action(paddEmptyElement, editor) 24227 } 24228 ], evt); 24229 }; 24230 var setup$a = function (editor, caret) { 24231 editor.on('keydown', function (evt) { 24232 if (evt.isDefaultPrevented() === false) { 24233 executeKeydownOverride$2(editor, caret, evt); 24234 } 24235 }); 24236 editor.on('keyup', function (evt) { 24237 if (evt.isDefaultPrevented() === false) { 24238 executeKeyupOverride(editor, evt); 24239 } 24240 }); 24241 }; 24242 24243 var firstNonWhiteSpaceNodeSibling = function (node) { 24244 while (node) { 24245 if (node.nodeType === 1 || node.nodeType === 3 && node.data && /[\r\n\s]/.test(node.data)) { 24246 return node; 24247 } 24248 node = node.nextSibling; 24249 } 24250 }; 24251 var moveToCaretPosition = function (editor, root) { 24252 var node, lastNode = root; 24253 var dom = editor.dom; 24254 var moveCaretBeforeOnEnterElementsMap = editor.schema.getMoveCaretBeforeOnEnterElements(); 24255 if (!root) { 24256 return; 24257 } 24258 if (/^(LI|DT|DD)$/.test(root.nodeName)) { 24259 var firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild); 24260 if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) { 24261 root.insertBefore(dom.doc.createTextNode(nbsp), root.firstChild); 24262 } 24263 } 24264 var rng = dom.createRng(); 24265 root.normalize(); 24266 if (root.hasChildNodes()) { 24267 var walker = new DomTreeWalker(root, root); 24268 while (node = walker.current()) { 24269 if (isText$7(node)) { 24270 rng.setStart(node, 0); 24271 rng.setEnd(node, 0); 24272 break; 24273 } 24274 if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) { 24275 rng.setStartBefore(node); 24276 rng.setEndBefore(node); 24277 break; 24278 } 24279 lastNode = node; 24280 node = walker.next(); 24281 } 24282 if (!node) { 24283 rng.setStart(lastNode, 0); 24284 rng.setEnd(lastNode, 0); 24285 } 24286 } else { 24287 if (isBr$5(root)) { 24288 if (root.nextSibling && dom.isBlock(root.nextSibling)) { 24289 rng.setStartBefore(root); 24290 rng.setEndBefore(root); 24291 } else { 24292 rng.setStartAfter(root); 24293 rng.setEndAfter(root); 24294 } 24295 } else { 24296 rng.setStart(root, 0); 24297 rng.setEnd(root, 0); 24298 } 24299 } 24300 editor.selection.setRng(rng); 24301 scrollRangeIntoView(editor, rng); 24302 }; 24303 var getEditableRoot$1 = function (dom, node) { 24304 var root = dom.getRoot(); 24305 var parent, editableRoot; 24306 parent = node; 24307 while (parent !== root && dom.getContentEditable(parent) !== 'false') { 24308 if (dom.getContentEditable(parent) === 'true') { 24309 editableRoot = parent; 24310 } 24311 parent = parent.parentNode; 24312 } 24313 return parent !== root ? editableRoot : root; 24314 }; 24315 var getParentBlock = function (editor) { 24316 return Optional.from(editor.dom.getParent(editor.selection.getStart(true), editor.dom.isBlock)); 24317 }; 24318 var getParentBlockName = function (editor) { 24319 return getParentBlock(editor).fold(constant(''), function (parentBlock) { 24320 return parentBlock.nodeName.toUpperCase(); 24321 }); 24322 }; 24323 var isListItemParentBlock = function (editor) { 24324 return getParentBlock(editor).filter(function (elm) { 24325 return isListItem(SugarElement.fromDom(elm)); 24326 }).isSome(); 24327 }; 24328 24329 var hasFirstChild = function (elm, name) { 24330 return elm.firstChild && elm.firstChild.nodeName === name; 24331 }; 24332 var isFirstChild = function (elm) { 24333 var _a; 24334 return ((_a = elm.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild) === elm; 24335 }; 24336 var hasParent = function (elm, parentName) { 24337 return elm && elm.parentNode && elm.parentNode.nodeName === parentName; 24338 }; 24339 var isListBlock = function (elm) { 24340 return elm && /^(OL|UL|LI)$/.test(elm.nodeName); 24341 }; 24342 var isNestedList = function (elm) { 24343 return isListBlock(elm) && isListBlock(elm.parentNode); 24344 }; 24345 var getContainerBlock = function (containerBlock) { 24346 var containerBlockParent = containerBlock.parentNode; 24347 if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) { 24348 return containerBlockParent; 24349 } 24350 return containerBlock; 24351 }; 24352 var isFirstOrLastLi = function (containerBlock, parentBlock, first) { 24353 var node = containerBlock[first ? 'firstChild' : 'lastChild']; 24354 while (node) { 24355 if (isElement$5(node)) { 24356 break; 24357 } 24358 node = node[first ? 'nextSibling' : 'previousSibling']; 24359 } 24360 return node === parentBlock; 24361 }; 24362 var insert$3 = function (editor, createNewBlock, containerBlock, parentBlock, newBlockName) { 24363 var dom = editor.dom; 24364 var rng = editor.selection.getRng(); 24365 if (containerBlock === editor.getBody()) { 24366 return; 24367 } 24368 if (isNestedList(containerBlock)) { 24369 newBlockName = 'LI'; 24370 } 24371 var newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR'); 24372 if (isFirstOrLastLi(containerBlock, parentBlock, true) && isFirstOrLastLi(containerBlock, parentBlock, false)) { 24373 if (hasParent(containerBlock, 'LI')) { 24374 var containerBlockParent = getContainerBlock(containerBlock); 24375 dom.insertAfter(newBlock, containerBlockParent); 24376 if (isFirstChild(containerBlock)) { 24377 dom.remove(containerBlockParent); 24378 } else { 24379 dom.remove(containerBlock); 24380 } 24381 } else { 24382 dom.replace(newBlock, containerBlock); 24383 } 24384 } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) { 24385 if (hasParent(containerBlock, 'LI')) { 24386 dom.insertAfter(newBlock, getContainerBlock(containerBlock)); 24387 newBlock.appendChild(dom.doc.createTextNode(' ')); 24388 newBlock.appendChild(containerBlock); 24389 } else { 24390 containerBlock.parentNode.insertBefore(newBlock, containerBlock); 24391 } 24392 dom.remove(parentBlock); 24393 } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) { 24394 dom.insertAfter(newBlock, getContainerBlock(containerBlock)); 24395 dom.remove(parentBlock); 24396 } else { 24397 containerBlock = getContainerBlock(containerBlock); 24398 var tmpRng = rng.cloneRange(); 24399 tmpRng.setStartAfter(parentBlock); 24400 tmpRng.setEndAfter(containerBlock); 24401 var fragment = tmpRng.extractContents(); 24402 if (newBlockName === 'LI' && hasFirstChild(fragment, 'LI')) { 24403 newBlock = fragment.firstChild; 24404 dom.insertAfter(fragment, containerBlock); 24405 } else { 24406 dom.insertAfter(fragment, containerBlock); 24407 dom.insertAfter(newBlock, containerBlock); 24408 } 24409 dom.remove(parentBlock); 24410 } 24411 moveToCaretPosition(editor, newBlock); 24412 }; 24413 24414 var trimZwsp = function (fragment) { 24415 each$k(descendants$1(SugarElement.fromDom(fragment), isText$8), function (text) { 24416 var rawNode = text.dom; 24417 rawNode.nodeValue = trim$2(rawNode.nodeValue); 24418 }); 24419 }; 24420 var isEmptyAnchor = function (dom, elm) { 24421 return elm && elm.nodeName === 'A' && dom.isEmpty(elm); 24422 }; 24423 var isTableCell = function (node) { 24424 return node && /^(TD|TH|CAPTION)$/.test(node.nodeName); 24425 }; 24426 var emptyBlock = function (elm) { 24427 elm.innerHTML = '<br data-mce-bogus="1">'; 24428 }; 24429 var containerAndSiblingName = function (container, nodeName) { 24430 return container.nodeName === nodeName || container.previousSibling && container.previousSibling.nodeName === nodeName; 24431 }; 24432 var canSplitBlock = function (dom, node) { 24433 return node && dom.isBlock(node) && !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) && !/^(fixed|absolute)/i.test(node.style.position) && dom.getContentEditable(node) !== 'true'; 24434 }; 24435 var trimInlineElementsOnLeftSideOfBlock = function (dom, nonEmptyElementsMap, block) { 24436 var node = block; 24437 var firstChilds = []; 24438 var i; 24439 if (!node) { 24440 return; 24441 } 24442 while (node = node.firstChild) { 24443 if (dom.isBlock(node)) { 24444 return; 24445 } 24446 if (isElement$5(node) && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) { 24447 firstChilds.push(node); 24448 } 24449 } 24450 i = firstChilds.length; 24451 while (i--) { 24452 node = firstChilds[i]; 24453 if (!node.hasChildNodes() || node.firstChild === node.lastChild && node.firstChild.nodeValue === '') { 24454 dom.remove(node); 24455 } else { 24456 if (isEmptyAnchor(dom, node)) { 24457 dom.remove(node); 24458 } 24459 } 24460 } 24461 }; 24462 var normalizeZwspOffset = function (start, container, offset) { 24463 if (isText$7(container) === false) { 24464 return offset; 24465 } else if (start) { 24466 return offset === 1 && container.data.charAt(offset - 1) === ZWSP$1 ? 0 : offset; 24467 } else { 24468 return offset === container.data.length - 1 && container.data.charAt(offset) === ZWSP$1 ? container.data.length : offset; 24469 } 24470 }; 24471 var includeZwspInRange = function (rng) { 24472 var newRng = rng.cloneRange(); 24473 newRng.setStart(rng.startContainer, normalizeZwspOffset(true, rng.startContainer, rng.startOffset)); 24474 newRng.setEnd(rng.endContainer, normalizeZwspOffset(false, rng.endContainer, rng.endOffset)); 24475 return newRng; 24476 }; 24477 var trimLeadingLineBreaks = function (node) { 24478 do { 24479 if (isText$7(node)) { 24480 node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, ''); 24481 } 24482 node = node.firstChild; 24483 } while (node); 24484 }; 24485 var getEditableRoot = function (dom, node) { 24486 var root = dom.getRoot(); 24487 var parent, editableRoot; 24488 parent = node; 24489 while (parent !== root && dom.getContentEditable(parent) !== 'false') { 24490 if (dom.getContentEditable(parent) === 'true') { 24491 editableRoot = parent; 24492 } 24493 parent = parent.parentNode; 24494 } 24495 return parent !== root ? editableRoot : root; 24496 }; 24497 var applyAttributes = function (editor, node, forcedRootBlockAttrs) { 24498 var dom = editor.dom; 24499 Optional.from(forcedRootBlockAttrs.style).map(dom.parseStyle).each(function (attrStyles) { 24500 var currentStyles = getAllRaw(SugarElement.fromDom(node)); 24501 var newStyles = __assign(__assign({}, currentStyles), attrStyles); 24502 dom.setStyles(node, newStyles); 24503 }); 24504 var attrClassesOpt = Optional.from(forcedRootBlockAttrs.class).map(function (attrClasses) { 24505 return attrClasses.split(/\s+/); 24506 }); 24507 var currentClassesOpt = Optional.from(node.className).map(function (currentClasses) { 24508 return filter$4(currentClasses.split(/\s+/), function (clazz) { 24509 return clazz !== ''; 24510 }); 24511 }); 24512 lift2(attrClassesOpt, currentClassesOpt, function (attrClasses, currentClasses) { 24513 var filteredClasses = filter$4(currentClasses, function (clazz) { 24514 return !contains$3(attrClasses, clazz); 24515 }); 24516 var newClasses = __spreadArray(__spreadArray([], attrClasses, true), filteredClasses, true); 24517 dom.setAttrib(node, 'class', newClasses.join(' ')); 24518 }); 24519 var appliedAttrs = [ 24520 'style', 24521 'class' 24522 ]; 24523 var remainingAttrs = filter$3(forcedRootBlockAttrs, function (_, attrs) { 24524 return !contains$3(appliedAttrs, attrs); 24525 }); 24526 dom.setAttribs(node, remainingAttrs); 24527 }; 24528 var setForcedBlockAttrs = function (editor, node) { 24529 var forcedRootBlockName = getForcedRootBlock(editor); 24530 if (forcedRootBlockName && forcedRootBlockName.toLowerCase() === node.tagName.toLowerCase()) { 24531 var forcedRootBlockAttrs = getForcedRootBlockAttrs(editor); 24532 applyAttributes(editor, node, forcedRootBlockAttrs); 24533 } 24534 }; 24535 var wrapSelfAndSiblingsInDefaultBlock = function (editor, newBlockName, rng, container, offset) { 24536 var newBlock, parentBlock, startNode, node, next, rootBlockName; 24537 var blockName = newBlockName || 'P'; 24538 var dom = editor.dom, editableRoot = getEditableRoot(dom, container); 24539 parentBlock = dom.getParent(container, dom.isBlock); 24540 if (!parentBlock || !canSplitBlock(dom, parentBlock)) { 24541 parentBlock = parentBlock || editableRoot; 24542 if (parentBlock === editor.getBody() || isTableCell(parentBlock)) { 24543 rootBlockName = parentBlock.nodeName.toLowerCase(); 24544 } else { 24545 rootBlockName = parentBlock.parentNode.nodeName.toLowerCase(); 24546 } 24547 if (!parentBlock.hasChildNodes()) { 24548 newBlock = dom.create(blockName); 24549 setForcedBlockAttrs(editor, newBlock); 24550 parentBlock.appendChild(newBlock); 24551 rng.setStart(newBlock, 0); 24552 rng.setEnd(newBlock, 0); 24553 return newBlock; 24554 } 24555 node = container; 24556 while (node.parentNode !== parentBlock) { 24557 node = node.parentNode; 24558 } 24559 while (node && !dom.isBlock(node)) { 24560 startNode = node; 24561 node = node.previousSibling; 24562 } 24563 if (startNode && editor.schema.isValidChild(rootBlockName, blockName.toLowerCase())) { 24564 newBlock = dom.create(blockName); 24565 setForcedBlockAttrs(editor, newBlock); 24566 startNode.parentNode.insertBefore(newBlock, startNode); 24567 node = startNode; 24568 while (node && !dom.isBlock(node)) { 24569 next = node.nextSibling; 24570 newBlock.appendChild(node); 24571 node = next; 24572 } 24573 rng.setStart(container, offset); 24574 rng.setEnd(container, offset); 24575 } 24576 } 24577 return container; 24578 }; 24579 var addBrToBlockIfNeeded = function (dom, block) { 24580 block.normalize(); 24581 var lastChild = block.lastChild; 24582 if (!lastChild || /^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true))) { 24583 dom.add(block, 'br'); 24584 } 24585 }; 24586 var insert$2 = function (editor, evt) { 24587 var tmpRng, container, offset, parentBlock; 24588 var newBlock, fragment, containerBlock, parentBlockName, newBlockName, isAfterLastNodeInContainer; 24589 var dom = editor.dom; 24590 var schema = editor.schema, nonEmptyElementsMap = schema.getNonEmptyElements(); 24591 var rng = editor.selection.getRng(); 24592 var createNewBlock = function (name) { 24593 var node = container, block, clonedNode, caretNode; 24594 var textInlineElements = schema.getTextInlineElements(); 24595 if (name || parentBlockName === 'TABLE' || parentBlockName === 'HR') { 24596 block = dom.create(name || newBlockName); 24597 } else { 24598 block = parentBlock.cloneNode(false); 24599 } 24600 caretNode = block; 24601 if (shouldKeepStyles(editor) === false) { 24602 dom.setAttrib(block, 'style', null); 24603 dom.setAttrib(block, 'class', null); 24604 } else { 24605 do { 24606 if (textInlineElements[node.nodeName]) { 24607 if (isCaretNode(node) || isBookmarkNode$1(node)) { 24608 continue; 24609 } 24610 clonedNode = node.cloneNode(false); 24611 dom.setAttrib(clonedNode, 'id', ''); 24612 if (block.hasChildNodes()) { 24613 clonedNode.appendChild(block.firstChild); 24614 block.appendChild(clonedNode); 24615 } else { 24616 caretNode = clonedNode; 24617 block.appendChild(clonedNode); 24618 } 24619 } 24620 } while ((node = node.parentNode) && node !== editableRoot); 24621 } 24622 setForcedBlockAttrs(editor, block); 24623 emptyBlock(caretNode); 24624 return block; 24625 }; 24626 var isCaretAtStartOrEndOfBlock = function (start) { 24627 var node, name; 24628 var normalizedOffset = normalizeZwspOffset(start, container, offset); 24629 if (isText$7(container) && (start ? normalizedOffset > 0 : normalizedOffset < container.nodeValue.length)) { 24630 return false; 24631 } 24632 if (container.parentNode === parentBlock && isAfterLastNodeInContainer && !start) { 24633 return true; 24634 } 24635 if (start && isElement$5(container) && container === parentBlock.firstChild) { 24636 return true; 24637 } 24638 if (containerAndSiblingName(container, 'TABLE') || containerAndSiblingName(container, 'HR')) { 24639 return isAfterLastNodeInContainer && !start || !isAfterLastNodeInContainer && start; 24640 } 24641 var walker = new DomTreeWalker(container, parentBlock); 24642 if (isText$7(container)) { 24643 if (start && normalizedOffset === 0) { 24644 walker.prev(); 24645 } else if (!start && normalizedOffset === container.nodeValue.length) { 24646 walker.next(); 24647 } 24648 } 24649 while (node = walker.current()) { 24650 if (isElement$5(node)) { 24651 if (!node.getAttribute('data-mce-bogus')) { 24652 name = node.nodeName.toLowerCase(); 24653 if (nonEmptyElementsMap[name] && name !== 'br') { 24654 return false; 24655 } 24656 } 24657 } else if (isText$7(node) && !isWhitespaceText(node.nodeValue)) { 24658 return false; 24659 } 24660 if (start) { 24661 walker.prev(); 24662 } else { 24663 walker.next(); 24664 } 24665 } 24666 return true; 24667 }; 24668 var insertNewBlockAfter = function () { 24669 if (/^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) && containerBlockName !== 'HGROUP') { 24670 newBlock = createNewBlock(newBlockName); 24671 } else { 24672 newBlock = createNewBlock(); 24673 } 24674 if (shouldEndContainerOnEmptyBlock(editor) && canSplitBlock(dom, containerBlock) && dom.isEmpty(parentBlock)) { 24675 newBlock = dom.split(containerBlock, parentBlock); 24676 } else { 24677 dom.insertAfter(newBlock, parentBlock); 24678 } 24679 moveToCaretPosition(editor, newBlock); 24680 }; 24681 normalize$2(dom, rng).each(function (normRng) { 24682 rng.setStart(normRng.startContainer, normRng.startOffset); 24683 rng.setEnd(normRng.endContainer, normRng.endOffset); 24684 }); 24685 container = rng.startContainer; 24686 offset = rng.startOffset; 24687 newBlockName = getForcedRootBlock(editor); 24688 var shiftKey = !!(evt && evt.shiftKey); 24689 var ctrlKey = !!(evt && evt.ctrlKey); 24690 if (isElement$5(container) && container.hasChildNodes()) { 24691 isAfterLastNodeInContainer = offset > container.childNodes.length - 1; 24692 container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container; 24693 if (isAfterLastNodeInContainer && isText$7(container)) { 24694 offset = container.nodeValue.length; 24695 } else { 24696 offset = 0; 24697 } 24698 } 24699 var editableRoot = getEditableRoot(dom, container); 24700 if (!editableRoot) { 24701 return; 24702 } 24703 if (newBlockName && !shiftKey || !newBlockName && shiftKey) { 24704 container = wrapSelfAndSiblingsInDefaultBlock(editor, newBlockName, rng, container, offset); 24705 } 24706 parentBlock = dom.getParent(container, dom.isBlock); 24707 containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null; 24708 parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''; 24709 var containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : ''; 24710 if (containerBlockName === 'LI' && !ctrlKey) { 24711 parentBlock = containerBlock; 24712 containerBlock = containerBlock.parentNode; 24713 parentBlockName = containerBlockName; 24714 } 24715 if (/^(LI|DT|DD)$/.test(parentBlockName)) { 24716 if (dom.isEmpty(parentBlock)) { 24717 insert$3(editor, createNewBlock, containerBlock, parentBlock, newBlockName); 24718 return; 24719 } 24720 } 24721 if (newBlockName && parentBlock === editor.getBody()) { 24722 return; 24723 } 24724 newBlockName = newBlockName || 'P'; 24725 if (isCaretContainerBlock$1(parentBlock)) { 24726 newBlock = showCaretContainerBlock(parentBlock); 24727 if (dom.isEmpty(parentBlock)) { 24728 emptyBlock(parentBlock); 24729 } 24730 setForcedBlockAttrs(editor, newBlock); 24731 moveToCaretPosition(editor, newBlock); 24732 } else if (isCaretAtStartOrEndOfBlock()) { 24733 insertNewBlockAfter(); 24734 } else if (isCaretAtStartOrEndOfBlock(true)) { 24735 newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock); 24736 moveToCaretPosition(editor, containerAndSiblingName(parentBlock, 'HR') ? newBlock : parentBlock); 24737 } else { 24738 tmpRng = includeZwspInRange(rng).cloneRange(); 24739 tmpRng.setEndAfter(parentBlock); 24740 fragment = tmpRng.extractContents(); 24741 trimZwsp(fragment); 24742 trimLeadingLineBreaks(fragment); 24743 newBlock = fragment.firstChild; 24744 dom.insertAfter(fragment, parentBlock); 24745 trimInlineElementsOnLeftSideOfBlock(dom, nonEmptyElementsMap, newBlock); 24746 addBrToBlockIfNeeded(dom, parentBlock); 24747 if (dom.isEmpty(parentBlock)) { 24748 emptyBlock(parentBlock); 24749 } 24750 newBlock.normalize(); 24751 if (dom.isEmpty(newBlock)) { 24752 dom.remove(newBlock); 24753 insertNewBlockAfter(); 24754 } else { 24755 setForcedBlockAttrs(editor, newBlock); 24756 moveToCaretPosition(editor, newBlock); 24757 } 24758 } 24759 dom.setAttrib(newBlock, 'id', ''); 24760 editor.fire('NewBlock', { newBlock: newBlock }); 24761 }; 24762 24763 var hasRightSideContent = function (schema, container, parentBlock) { 24764 var walker = new DomTreeWalker(container, parentBlock); 24765 var node; 24766 var nonEmptyElementsMap = schema.getNonEmptyElements(); 24767 while (node = walker.next()) { 24768 if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) { 24769 return true; 24770 } 24771 } 24772 }; 24773 var moveSelectionToBr = function (editor, brElm, extraBr) { 24774 var rng = editor.dom.createRng(); 24775 if (!extraBr) { 24776 rng.setStartAfter(brElm); 24777 rng.setEndAfter(brElm); 24778 } else { 24779 rng.setStartBefore(brElm); 24780 rng.setEndBefore(brElm); 24781 } 24782 editor.selection.setRng(rng); 24783 scrollRangeIntoView(editor, rng); 24784 }; 24785 var insertBrAtCaret = function (editor, evt) { 24786 var selection = editor.selection; 24787 var dom = editor.dom; 24788 var rng = selection.getRng(); 24789 var brElm; 24790 var extraBr; 24791 normalize$2(dom, rng).each(function (normRng) { 24792 rng.setStart(normRng.startContainer, normRng.startOffset); 24793 rng.setEnd(normRng.endContainer, normRng.endOffset); 24794 }); 24795 var offset = rng.startOffset; 24796 var container = rng.startContainer; 24797 if (container.nodeType === 1 && container.hasChildNodes()) { 24798 var isAfterLastNodeInContainer = offset > container.childNodes.length - 1; 24799 container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container; 24800 if (isAfterLastNodeInContainer && container.nodeType === 3) { 24801 offset = container.nodeValue.length; 24802 } else { 24803 offset = 0; 24804 } 24805 } 24806 var parentBlock = dom.getParent(container, dom.isBlock); 24807 var containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null; 24808 var containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : ''; 24809 var isControlKey = !!(evt && evt.ctrlKey); 24810 if (containerBlockName === 'LI' && !isControlKey) { 24811 parentBlock = containerBlock; 24812 } 24813 if (container && container.nodeType === 3 && offset >= container.nodeValue.length) { 24814 if (!hasRightSideContent(editor.schema, container, parentBlock)) { 24815 brElm = dom.create('br'); 24816 rng.insertNode(brElm); 24817 rng.setStartAfter(brElm); 24818 rng.setEndAfter(brElm); 24819 extraBr = true; 24820 } 24821 } 24822 brElm = dom.create('br'); 24823 rangeInsertNode(dom, rng, brElm); 24824 moveSelectionToBr(editor, brElm, extraBr); 24825 editor.undoManager.add(); 24826 }; 24827 var insertBrBefore = function (editor, inline) { 24828 var br = SugarElement.fromTag('br'); 24829 before$4(SugarElement.fromDom(inline), br); 24830 editor.undoManager.add(); 24831 }; 24832 var insertBrAfter = function (editor, inline) { 24833 if (!hasBrAfter(editor.getBody(), inline)) { 24834 after$3(SugarElement.fromDom(inline), SugarElement.fromTag('br')); 24835 } 24836 var br = SugarElement.fromTag('br'); 24837 after$3(SugarElement.fromDom(inline), br); 24838 moveSelectionToBr(editor, br.dom, false); 24839 editor.undoManager.add(); 24840 }; 24841 var isBeforeBr = function (pos) { 24842 return isBr$5(pos.getNode()); 24843 }; 24844 var hasBrAfter = function (rootNode, startNode) { 24845 if (isBeforeBr(CaretPosition.after(startNode))) { 24846 return true; 24847 } else { 24848 return nextPosition(rootNode, CaretPosition.after(startNode)).map(function (pos) { 24849 return isBr$5(pos.getNode()); 24850 }).getOr(false); 24851 } 24852 }; 24853 var isAnchorLink = function (elm) { 24854 return elm && elm.nodeName === 'A' && 'href' in elm; 24855 }; 24856 var isInsideAnchor = function (location) { 24857 return location.fold(never, isAnchorLink, isAnchorLink, never); 24858 }; 24859 var readInlineAnchorLocation = function (editor) { 24860 var isInlineTarget$1 = curry(isInlineTarget, editor); 24861 var position = CaretPosition.fromRangeStart(editor.selection.getRng()); 24862 return readLocation(isInlineTarget$1, editor.getBody(), position).filter(isInsideAnchor); 24863 }; 24864 var insertBrOutsideAnchor = function (editor, location) { 24865 location.fold(noop, curry(insertBrBefore, editor), curry(insertBrAfter, editor), noop); 24866 }; 24867 var insert$1 = function (editor, evt) { 24868 var anchorLocation = readInlineAnchorLocation(editor); 24869 if (anchorLocation.isSome()) { 24870 anchorLocation.each(curry(insertBrOutsideAnchor, editor)); 24871 } else { 24872 insertBrAtCaret(editor, evt); 24873 } 24874 }; 24875 24876 var matchesSelector = function (editor, selector) { 24877 return getParentBlock(editor).filter(function (parentBlock) { 24878 return selector.length > 0 && is$2(SugarElement.fromDom(parentBlock), selector); 24879 }).isSome(); 24880 }; 24881 var shouldInsertBr = function (editor) { 24882 return matchesSelector(editor, getBrNewLineSelector(editor)); 24883 }; 24884 var shouldBlockNewLine$1 = function (editor) { 24885 return matchesSelector(editor, getNoNewLineSelector(editor)); 24886 }; 24887 24888 var newLineAction = Adt.generate([ 24889 { br: [] }, 24890 { block: [] }, 24891 { none: [] } 24892 ]); 24893 var shouldBlockNewLine = function (editor, _shiftKey) { 24894 return shouldBlockNewLine$1(editor); 24895 }; 24896 var isBrMode = function (requiredState) { 24897 return function (editor, _shiftKey) { 24898 var brMode = getForcedRootBlock(editor) === ''; 24899 return brMode === requiredState; 24900 }; 24901 }; 24902 var inListBlock = function (requiredState) { 24903 return function (editor, _shiftKey) { 24904 return isListItemParentBlock(editor) === requiredState; 24905 }; 24906 }; 24907 var inBlock = function (blockName, requiredState) { 24908 return function (editor, _shiftKey) { 24909 var state = getParentBlockName(editor) === blockName.toUpperCase(); 24910 return state === requiredState; 24911 }; 24912 }; 24913 var inPreBlock = function (requiredState) { 24914 return inBlock('pre', requiredState); 24915 }; 24916 var inSummaryBlock = function () { 24917 return inBlock('summary', true); 24918 }; 24919 var shouldPutBrInPre = function (requiredState) { 24920 return function (editor, _shiftKey) { 24921 return shouldPutBrInPre$1(editor) === requiredState; 24922 }; 24923 }; 24924 var inBrContext = function (editor, _shiftKey) { 24925 return shouldInsertBr(editor); 24926 }; 24927 var hasShiftKey = function (_editor, shiftKey) { 24928 return shiftKey; 24929 }; 24930 var canInsertIntoEditableRoot = function (editor) { 24931 var forcedRootBlock = getForcedRootBlock(editor); 24932 var rootEditable = getEditableRoot$1(editor.dom, editor.selection.getStart()); 24933 return rootEditable && editor.schema.isValidChild(rootEditable.nodeName, forcedRootBlock ? forcedRootBlock : 'P'); 24934 }; 24935 var match = function (predicates, action) { 24936 return function (editor, shiftKey) { 24937 var isMatch = foldl(predicates, function (res, p) { 24938 return res && p(editor, shiftKey); 24939 }, true); 24940 return isMatch ? Optional.some(action) : Optional.none(); 24941 }; 24942 }; 24943 var getAction = function (editor, evt) { 24944 return evaluateUntil([ 24945 match([shouldBlockNewLine], newLineAction.none()), 24946 match([inSummaryBlock()], newLineAction.br()), 24947 match([ 24948 inPreBlock(true), 24949 shouldPutBrInPre(false), 24950 hasShiftKey 24951 ], newLineAction.br()), 24952 match([ 24953 inPreBlock(true), 24954 shouldPutBrInPre(false) 24955 ], newLineAction.block()), 24956 match([ 24957 inPreBlock(true), 24958 shouldPutBrInPre(true), 24959 hasShiftKey 24960 ], newLineAction.block()), 24961 match([ 24962 inPreBlock(true), 24963 shouldPutBrInPre(true) 24964 ], newLineAction.br()), 24965 match([ 24966 inListBlock(true), 24967 hasShiftKey 24968 ], newLineAction.br()), 24969 match([inListBlock(true)], newLineAction.block()), 24970 match([ 24971 isBrMode(true), 24972 hasShiftKey, 24973 canInsertIntoEditableRoot 24974 ], newLineAction.block()), 24975 match([isBrMode(true)], newLineAction.br()), 24976 match([inBrContext], newLineAction.br()), 24977 match([ 24978 isBrMode(false), 24979 hasShiftKey 24980 ], newLineAction.br()), 24981 match([canInsertIntoEditableRoot], newLineAction.block()) 24982 ], [ 24983 editor, 24984 !!(evt && evt.shiftKey) 24985 ]).getOr(newLineAction.none()); 24986 }; 24987 24988 var insert = function (editor, evt) { 24989 getAction(editor, evt).fold(function () { 24990 insert$1(editor, evt); 24991 }, function () { 24992 insert$2(editor, evt); 24993 }, noop); 24994 }; 24995 24996 var handleEnterKeyEvent = function (editor, event) { 24997 if (event.isDefaultPrevented()) { 24998 return; 24999 } 25000 event.preventDefault(); 25001 endTypingLevelIgnoreLocks(editor.undoManager); 25002 editor.undoManager.transact(function () { 25003 if (editor.selection.isCollapsed() === false) { 25004 editor.execCommand('Delete'); 25005 } 25006 insert(editor, event); 25007 }); 25008 }; 25009 var setup$9 = function (editor) { 25010 editor.on('keydown', function (event) { 25011 if (event.keyCode === VK.ENTER) { 25012 handleEnterKeyEvent(editor, event); 25013 } 25014 }); 25015 }; 25016 25017 var executeKeydownOverride$1 = function (editor, caret, evt) { 25018 execute([ 25019 { 25020 keyCode: VK.END, 25021 action: action(moveToLineEndPoint$1, editor, true) 25022 }, 25023 { 25024 keyCode: VK.HOME, 25025 action: action(moveToLineEndPoint$1, editor, false) 25026 }, 25027 { 25028 keyCode: VK.END, 25029 action: action(moveToLineEndPoint, editor, true) 25030 }, 25031 { 25032 keyCode: VK.HOME, 25033 action: action(moveToLineEndPoint, editor, false) 25034 }, 25035 { 25036 keyCode: VK.END, 25037 action: action(moveToLineEndPoint$2, editor, true, caret) 25038 }, 25039 { 25040 keyCode: VK.HOME, 25041 action: action(moveToLineEndPoint$2, editor, false, caret) 25042 } 25043 ], evt).each(function (_) { 25044 evt.preventDefault(); 25045 }); 25046 }; 25047 var setup$8 = function (editor, caret) { 25048 editor.on('keydown', function (evt) { 25049 if (evt.isDefaultPrevented() === false) { 25050 executeKeydownOverride$1(editor, caret, evt); 25051 } 25052 }); 25053 }; 25054 25055 var browser = detect().browser; 25056 var setupIeInput = function (editor) { 25057 var keypressThrotter = first(function () { 25058 if (!editor.composing) { 25059 normalizeNbspsInEditor(editor); 25060 } 25061 }, 0); 25062 if (browser.isIE()) { 25063 editor.on('keypress', function (_e) { 25064 keypressThrotter.throttle(); 25065 }); 25066 editor.on('remove', function (_e) { 25067 keypressThrotter.cancel(); 25068 }); 25069 } 25070 }; 25071 var setup$7 = function (editor) { 25072 setupIeInput(editor); 25073 editor.on('input', function (e) { 25074 if (e.isComposing === false) { 25075 normalizeNbspsInEditor(editor); 25076 } 25077 }); 25078 }; 25079 25080 var platform = detect(); 25081 var executeKeyupAction = function (editor, caret, evt) { 25082 execute([ 25083 { 25084 keyCode: VK.PAGE_UP, 25085 action: action(moveToLineEndPoint$2, editor, false, caret) 25086 }, 25087 { 25088 keyCode: VK.PAGE_DOWN, 25089 action: action(moveToLineEndPoint$2, editor, true, caret) 25090 } 25091 ], evt); 25092 }; 25093 var stopImmediatePropagation = function (e) { 25094 return e.stopImmediatePropagation(); 25095 }; 25096 var isPageUpDown = function (evt) { 25097 return evt.keyCode === VK.PAGE_UP || evt.keyCode === VK.PAGE_DOWN; 25098 }; 25099 var setNodeChangeBlocker = function (blocked, editor, block) { 25100 if (block && !blocked.get()) { 25101 editor.on('NodeChange', stopImmediatePropagation, true); 25102 } else if (!block && blocked.get()) { 25103 editor.off('NodeChange', stopImmediatePropagation); 25104 } 25105 blocked.set(block); 25106 }; 25107 var setup$6 = function (editor, caret) { 25108 if (platform.os.isOSX()) { 25109 return; 25110 } 25111 var blocked = Cell(false); 25112 editor.on('keydown', function (evt) { 25113 if (isPageUpDown(evt)) { 25114 setNodeChangeBlocker(blocked, editor, true); 25115 } 25116 }); 25117 editor.on('keyup', function (evt) { 25118 if (evt.isDefaultPrevented() === false) { 25119 executeKeyupAction(editor, caret, evt); 25120 } 25121 if (isPageUpDown(evt) && blocked.get()) { 25122 setNodeChangeBlocker(blocked, editor, false); 25123 editor.nodeChanged(); 25124 } 25125 }); 25126 }; 25127 25128 var insertTextAtPosition = function (text, pos) { 25129 var container = pos.container(); 25130 var offset = pos.offset(); 25131 if (isText$7(container)) { 25132 container.insertData(offset, text); 25133 return Optional.some(CaretPosition(container, offset + text.length)); 25134 } else { 25135 return getElementFromPosition(pos).map(function (elm) { 25136 var textNode = SugarElement.fromText(text); 25137 if (pos.isAtEnd()) { 25138 after$3(elm, textNode); 25139 } else { 25140 before$4(elm, textNode); 25141 } 25142 return CaretPosition(textNode.dom, text.length); 25143 }); 25144 } 25145 }; 25146 var insertNbspAtPosition = curry(insertTextAtPosition, nbsp); 25147 var insertSpaceAtPosition = curry(insertTextAtPosition, ' '); 25148 25149 var locationToCaretPosition = function (root) { 25150 return function (location) { 25151 return location.fold(function (element) { 25152 return prevPosition(root.dom, CaretPosition.before(element)); 25153 }, function (element) { 25154 return firstPositionIn(element); 25155 }, function (element) { 25156 return lastPositionIn(element); 25157 }, function (element) { 25158 return nextPosition(root.dom, CaretPosition.after(element)); 25159 }); 25160 }; 25161 }; 25162 var insertInlineBoundarySpaceOrNbsp = function (root, pos) { 25163 return function (checkPos) { 25164 return needsToHaveNbsp(root, checkPos) ? insertNbspAtPosition(pos) : insertSpaceAtPosition(pos); 25165 }; 25166 }; 25167 var setSelection = function (editor) { 25168 return function (pos) { 25169 editor.selection.setRng(pos.toRange()); 25170 editor.nodeChanged(); 25171 return true; 25172 }; 25173 }; 25174 var insertSpaceOrNbspAtSelection = function (editor) { 25175 var pos = CaretPosition.fromRangeStart(editor.selection.getRng()); 25176 var root = SugarElement.fromDom(editor.getBody()); 25177 if (editor.selection.isCollapsed()) { 25178 var isInlineTarget$1 = curry(isInlineTarget, editor); 25179 var caretPosition = CaretPosition.fromRangeStart(editor.selection.getRng()); 25180 return readLocation(isInlineTarget$1, editor.getBody(), caretPosition).bind(locationToCaretPosition(root)).bind(insertInlineBoundarySpaceOrNbsp(root, pos)).exists(setSelection(editor)); 25181 } else { 25182 return false; 25183 } 25184 }; 25185 25186 var executeKeydownOverride = function (editor, evt) { 25187 execute([{ 25188 keyCode: VK.SPACEBAR, 25189 action: action(insertSpaceOrNbspAtSelection, editor) 25190 }], evt).each(function (_) { 25191 evt.preventDefault(); 25192 }); 25193 }; 25194 var setup$5 = function (editor) { 25195 editor.on('keydown', function (evt) { 25196 if (evt.isDefaultPrevented() === false) { 25197 executeKeydownOverride(editor, evt); 25198 } 25199 }); 25200 }; 25201 25202 var registerKeyboardOverrides = function (editor) { 25203 var caret = setupSelectedState(editor); 25204 setup$c(editor); 25205 setup$b(editor, caret); 25206 setup$a(editor, caret); 25207 setup$9(editor); 25208 setup$5(editor); 25209 setup$7(editor); 25210 setup$8(editor, caret); 25211 setup$6(editor, caret); 25212 return caret; 25213 }; 25214 var setup$4 = function (editor) { 25215 if (!isRtc(editor)) { 25216 return registerKeyboardOverrides(editor); 25217 } else { 25218 return Cell(null); 25219 } 25220 }; 25221 25222 var NodeChange = function () { 25223 function NodeChange(editor) { 25224 this.lastPath = []; 25225 this.editor = editor; 25226 var lastRng; 25227 var self = this; 25228 if (!('onselectionchange' in editor.getDoc())) { 25229 editor.on('NodeChange click mouseup keyup focus', function (e) { 25230 var nativeRng = editor.selection.getRng(); 25231 var fakeRng = { 25232 startContainer: nativeRng.startContainer, 25233 startOffset: nativeRng.startOffset, 25234 endContainer: nativeRng.endContainer, 25235 endOffset: nativeRng.endOffset 25236 }; 25237 if (e.type === 'nodechange' || !isEq$4(fakeRng, lastRng)) { 25238 editor.fire('SelectionChange'); 25239 } 25240 lastRng = fakeRng; 25241 }); 25242 } 25243 editor.on('contextmenu', function () { 25244 editor.fire('SelectionChange'); 25245 }); 25246 editor.on('SelectionChange', function () { 25247 var startElm = editor.selection.getStart(true); 25248 if (!startElm || !Env.range && editor.selection.isCollapsed()) { 25249 return; 25250 } 25251 if (hasAnyRanges(editor) && !self.isSameElementPath(startElm) && editor.dom.isChildOf(startElm, editor.getBody())) { 25252 editor.nodeChanged({ selectionChange: true }); 25253 } 25254 }); 25255 editor.on('mouseup', function (e) { 25256 if (!e.isDefaultPrevented() && hasAnyRanges(editor)) { 25257 if (editor.selection.getNode().nodeName === 'IMG') { 25258 Delay.setEditorTimeout(editor, function () { 25259 editor.nodeChanged(); 25260 }); 25261 } else { 25262 editor.nodeChanged(); 25263 } 25264 } 25265 }); 25266 } 25267 NodeChange.prototype.nodeChanged = function (args) { 25268 var selection = this.editor.selection; 25269 var node, parents, root; 25270 if (this.editor.initialized && selection && !shouldDisableNodeChange(this.editor) && !this.editor.mode.isReadOnly()) { 25271 root = this.editor.getBody(); 25272 node = selection.getStart(true) || root; 25273 if (node.ownerDocument !== this.editor.getDoc() || !this.editor.dom.isChildOf(node, root)) { 25274 node = root; 25275 } 25276 parents = []; 25277 this.editor.dom.getParent(node, function (node) { 25278 if (node === root) { 25279 return true; 25280 } 25281 parents.push(node); 25282 }); 25283 args = args || {}; 25284 args.element = node; 25285 args.parents = parents; 25286 this.editor.fire('NodeChange', args); 25287 } 25288 }; 25289 NodeChange.prototype.isSameElementPath = function (startElm) { 25290 var i; 25291 var currentPath = this.editor.$(startElm).parentsUntil(this.editor.getBody()).add(startElm); 25292 if (currentPath.length === this.lastPath.length) { 25293 for (i = currentPath.length; i >= 0; i--) { 25294 if (currentPath[i] !== this.lastPath[i]) { 25295 break; 25296 } 25297 } 25298 if (i === -1) { 25299 this.lastPath = currentPath; 25300 return true; 25301 } 25302 } 25303 this.lastPath = currentPath; 25304 return false; 25305 }; 25306 return NodeChange; 25307 }(); 25308 25309 var preventSummaryToggle = function (editor) { 25310 editor.on('click', function (e) { 25311 if (editor.dom.getParent(e.target, 'details')) { 25312 e.preventDefault(); 25313 } 25314 }); 25315 }; 25316 var filterDetails = function (editor) { 25317 editor.parser.addNodeFilter('details', function (elms) { 25318 each$k(elms, function (details) { 25319 details.attr('data-mce-open', details.attr('open')); 25320 details.attr('open', 'open'); 25321 }); 25322 }); 25323 editor.serializer.addNodeFilter('details', function (elms) { 25324 each$k(elms, function (details) { 25325 var open = details.attr('data-mce-open'); 25326 details.attr('open', isString$1(open) ? open : null); 25327 details.attr('data-mce-open', null); 25328 }); 25329 }); 25330 }; 25331 var setup$3 = function (editor) { 25332 preventSummaryToggle(editor); 25333 filterDetails(editor); 25334 }; 25335 25336 var isTextBlockNode = function (node) { 25337 return isElement$5(node) && isTextBlock$2(SugarElement.fromDom(node)); 25338 }; 25339 var normalizeSelection = function (editor) { 25340 var rng = editor.selection.getRng(); 25341 var startPos = CaretPosition.fromRangeStart(rng); 25342 var endPos = CaretPosition.fromRangeEnd(rng); 25343 if (CaretPosition.isElementPosition(startPos)) { 25344 var container = startPos.container(); 25345 if (isTextBlockNode(container)) { 25346 firstPositionIn(container).each(function (pos) { 25347 return rng.setStart(pos.container(), pos.offset()); 25348 }); 25349 } 25350 } 25351 if (CaretPosition.isElementPosition(endPos)) { 25352 var container = startPos.container(); 25353 if (isTextBlockNode(container)) { 25354 lastPositionIn(container).each(function (pos) { 25355 return rng.setEnd(pos.container(), pos.offset()); 25356 }); 25357 } 25358 } 25359 editor.selection.setRng(normalize(rng)); 25360 }; 25361 var setup$2 = function (editor) { 25362 editor.on('click', function (e) { 25363 if (e.detail >= 3) { 25364 normalizeSelection(editor); 25365 } 25366 }); 25367 }; 25368 25369 var getAbsolutePosition = function (elm) { 25370 var clientRect = elm.getBoundingClientRect(); 25371 var doc = elm.ownerDocument; 25372 var docElem = doc.documentElement; 25373 var win = doc.defaultView; 25374 return { 25375 top: clientRect.top + win.pageYOffset - docElem.clientTop, 25376 left: clientRect.left + win.pageXOffset - docElem.clientLeft 25377 }; 25378 }; 25379 var getBodyPosition = function (editor) { 25380 return editor.inline ? getAbsolutePosition(editor.getBody()) : { 25381 left: 0, 25382 top: 0 25383 }; 25384 }; 25385 var getScrollPosition = function (editor) { 25386 var body = editor.getBody(); 25387 return editor.inline ? { 25388 left: body.scrollLeft, 25389 top: body.scrollTop 25390 } : { 25391 left: 0, 25392 top: 0 25393 }; 25394 }; 25395 var getBodyScroll = function (editor) { 25396 var body = editor.getBody(), docElm = editor.getDoc().documentElement; 25397 var inlineScroll = { 25398 left: body.scrollLeft, 25399 top: body.scrollTop 25400 }; 25401 var iframeScroll = { 25402 left: body.scrollLeft || docElm.scrollLeft, 25403 top: body.scrollTop || docElm.scrollTop 25404 }; 25405 return editor.inline ? inlineScroll : iframeScroll; 25406 }; 25407 var getMousePosition = function (editor, event) { 25408 if (event.target.ownerDocument !== editor.getDoc()) { 25409 var iframePosition = getAbsolutePosition(editor.getContentAreaContainer()); 25410 var scrollPosition = getBodyScroll(editor); 25411 return { 25412 left: event.pageX - iframePosition.left + scrollPosition.left, 25413 top: event.pageY - iframePosition.top + scrollPosition.top 25414 }; 25415 } 25416 return { 25417 left: event.pageX, 25418 top: event.pageY 25419 }; 25420 }; 25421 var calculatePosition = function (bodyPosition, scrollPosition, mousePosition) { 25422 return { 25423 pageX: mousePosition.left - bodyPosition.left + scrollPosition.left, 25424 pageY: mousePosition.top - bodyPosition.top + scrollPosition.top 25425 }; 25426 }; 25427 var calc = function (editor, event) { 25428 return calculatePosition(getBodyPosition(editor), getScrollPosition(editor), getMousePosition(editor, event)); 25429 }; 25430 25431 var isContentEditableFalse$1 = isContentEditableFalse$b, isContentEditableTrue$1 = isContentEditableTrue$4; 25432 var isDraggable = function (rootElm, elm) { 25433 return isContentEditableFalse$1(elm) && elm !== rootElm; 25434 }; 25435 var isValidDropTarget = function (editor, targetElement, dragElement) { 25436 if (targetElement === dragElement || editor.dom.isChildOf(targetElement, dragElement)) { 25437 return false; 25438 } 25439 return !isContentEditableFalse$1(targetElement); 25440 }; 25441 var cloneElement = function (elm) { 25442 var cloneElm = elm.cloneNode(true); 25443 cloneElm.removeAttribute('data-mce-selected'); 25444 return cloneElm; 25445 }; 25446 var createGhost = function (editor, elm, width, height) { 25447 var dom = editor.dom; 25448 var clonedElm = elm.cloneNode(true); 25449 dom.setStyles(clonedElm, { 25450 width: width, 25451 height: height 25452 }); 25453 dom.setAttrib(clonedElm, 'data-mce-selected', null); 25454 var ghostElm = dom.create('div', { 25455 'class': 'mce-drag-container', 25456 'data-mce-bogus': 'all', 25457 'unselectable': 'on', 25458 'contenteditable': 'false' 25459 }); 25460 dom.setStyles(ghostElm, { 25461 position: 'absolute', 25462 opacity: 0.5, 25463 overflow: 'hidden', 25464 border: 0, 25465 padding: 0, 25466 margin: 0, 25467 width: width, 25468 height: height 25469 }); 25470 dom.setStyles(clonedElm, { 25471 margin: 0, 25472 boxSizing: 'border-box' 25473 }); 25474 ghostElm.appendChild(clonedElm); 25475 return ghostElm; 25476 }; 25477 var appendGhostToBody = function (ghostElm, bodyElm) { 25478 if (ghostElm.parentNode !== bodyElm) { 25479 bodyElm.appendChild(ghostElm); 25480 } 25481 }; 25482 var moveGhost = function (ghostElm, position, width, height, maxX, maxY) { 25483 var overflowX = 0, overflowY = 0; 25484 ghostElm.style.left = position.pageX + 'px'; 25485 ghostElm.style.top = position.pageY + 'px'; 25486 if (position.pageX + width > maxX) { 25487 overflowX = position.pageX + width - maxX; 25488 } 25489 if (position.pageY + height > maxY) { 25490 overflowY = position.pageY + height - maxY; 25491 } 25492 ghostElm.style.width = width - overflowX + 'px'; 25493 ghostElm.style.height = height - overflowY + 'px'; 25494 }; 25495 var removeElement = function (elm) { 25496 if (elm && elm.parentNode) { 25497 elm.parentNode.removeChild(elm); 25498 } 25499 }; 25500 var isLeftMouseButtonPressed = function (e) { 25501 return e.button === 0; 25502 }; 25503 var applyRelPos = function (state, position) { 25504 return { 25505 pageX: position.pageX - state.relX, 25506 pageY: position.pageY + 5 25507 }; 25508 }; 25509 var start = function (state, editor) { 25510 return function (e) { 25511 if (isLeftMouseButtonPressed(e)) { 25512 var ceElm = find$3(editor.dom.getParents(e.target), or(isContentEditableFalse$1, isContentEditableTrue$1)).getOr(null); 25513 if (isDraggable(editor.getBody(), ceElm)) { 25514 var elmPos = editor.dom.getPos(ceElm); 25515 var bodyElm = editor.getBody(); 25516 var docElm = editor.getDoc().documentElement; 25517 state.set({ 25518 element: ceElm, 25519 dragging: false, 25520 screenX: e.screenX, 25521 screenY: e.screenY, 25522 maxX: (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2, 25523 maxY: (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2, 25524 relX: e.pageX - elmPos.x, 25525 relY: e.pageY - elmPos.y, 25526 width: ceElm.offsetWidth, 25527 height: ceElm.offsetHeight, 25528 ghost: createGhost(editor, ceElm, ceElm.offsetWidth, ceElm.offsetHeight) 25529 }); 25530 } 25531 } 25532 }; 25533 }; 25534 var move = function (state, editor) { 25535 var throttledPlaceCaretAt = Delay.throttle(function (clientX, clientY) { 25536 editor._selectionOverrides.hideFakeCaret(); 25537 editor.selection.placeCaretAt(clientX, clientY); 25538 }, 0); 25539 editor.on('remove', throttledPlaceCaretAt.stop); 25540 return function (e) { 25541 return state.on(function (state) { 25542 var movement = Math.max(Math.abs(e.screenX - state.screenX), Math.abs(e.screenY - state.screenY)); 25543 if (!state.dragging && movement > 10) { 25544 var args = editor.fire('dragstart', { target: state.element }); 25545 if (args.isDefaultPrevented()) { 25546 return; 25547 } 25548 state.dragging = true; 25549 editor.focus(); 25550 } 25551 if (state.dragging) { 25552 var targetPos = applyRelPos(state, calc(editor, e)); 25553 appendGhostToBody(state.ghost, editor.getBody()); 25554 moveGhost(state.ghost, targetPos, state.width, state.height, state.maxX, state.maxY); 25555 throttledPlaceCaretAt(e.clientX, e.clientY); 25556 } 25557 }); 25558 }; 25559 }; 25560 var getRawTarget = function (selection) { 25561 var rng = selection.getSel().getRangeAt(0); 25562 var startContainer = rng.startContainer; 25563 return startContainer.nodeType === 3 ? startContainer.parentNode : startContainer; 25564 }; 25565 var drop = function (state, editor) { 25566 return function (e) { 25567 state.on(function (state) { 25568 if (state.dragging) { 25569 if (isValidDropTarget(editor, getRawTarget(editor.selection), state.element)) { 25570 var targetClone_1 = cloneElement(state.element); 25571 var args = editor.fire('drop', { 25572 clientX: e.clientX, 25573 clientY: e.clientY 25574 }); 25575 if (!args.isDefaultPrevented()) { 25576 editor.undoManager.transact(function () { 25577 removeElement(state.element); 25578 editor.insertContent(editor.dom.getOuterHTML(targetClone_1)); 25579 editor._selectionOverrides.hideFakeCaret(); 25580 }); 25581 } 25582 } 25583 editor.fire('dragend'); 25584 } 25585 }); 25586 removeDragState(state); 25587 }; 25588 }; 25589 var stop = function (state, editor) { 25590 return function () { 25591 state.on(function (state) { 25592 if (state.dragging) { 25593 editor.fire('dragend'); 25594 } 25595 }); 25596 removeDragState(state); 25597 }; 25598 }; 25599 var removeDragState = function (state) { 25600 state.on(function (state) { 25601 removeElement(state.ghost); 25602 }); 25603 state.clear(); 25604 }; 25605 var bindFakeDragEvents = function (editor) { 25606 var state = value(); 25607 var pageDom = DOMUtils.DOM; 25608 var rootDocument = document; 25609 var dragStartHandler = start(state, editor); 25610 var dragHandler = move(state, editor); 25611 var dropHandler = drop(state, editor); 25612 var dragEndHandler = stop(state, editor); 25613 editor.on('mousedown', dragStartHandler); 25614 editor.on('mousemove', dragHandler); 25615 editor.on('mouseup', dropHandler); 25616 pageDom.bind(rootDocument, 'mousemove', dragHandler); 25617 pageDom.bind(rootDocument, 'mouseup', dragEndHandler); 25618 editor.on('remove', function () { 25619 pageDom.unbind(rootDocument, 'mousemove', dragHandler); 25620 pageDom.unbind(rootDocument, 'mouseup', dragEndHandler); 25621 }); 25622 editor.on('keydown', function (e) { 25623 if (e.keyCode === VK.ESC) { 25624 dragEndHandler(); 25625 } 25626 }); 25627 }; 25628 var blockIeDrop = function (editor) { 25629 editor.on('drop', function (e) { 25630 var realTarget = typeof e.clientX !== 'undefined' ? editor.getDoc().elementFromPoint(e.clientX, e.clientY) : null; 25631 if (isContentEditableFalse$1(realTarget) || editor.dom.getContentEditableParent(realTarget) === 'false') { 25632 e.preventDefault(); 25633 } 25634 }); 25635 }; 25636 var blockUnsupportedFileDrop = function (editor) { 25637 var preventFileDrop = function (e) { 25638 if (!e.isDefaultPrevented()) { 25639 var dataTransfer = e.dataTransfer; 25640 if (dataTransfer && (contains$3(dataTransfer.types, 'Files') || dataTransfer.files.length > 0)) { 25641 e.preventDefault(); 25642 if (e.type === 'drop') { 25643 displayError(editor, 'Dropped file type is not supported'); 25644 } 25645 } 25646 } 25647 }; 25648 var preventFileDropIfUIElement = function (e) { 25649 if (isUIElement(editor, e.target)) { 25650 preventFileDrop(e); 25651 } 25652 }; 25653 var setup = function () { 25654 var pageDom = DOMUtils.DOM; 25655 var dom = editor.dom; 25656 var doc = document; 25657 var editorRoot = editor.inline ? editor.getBody() : editor.getDoc(); 25658 var eventNames = [ 25659 'drop', 25660 'dragover' 25661 ]; 25662 each$k(eventNames, function (name) { 25663 pageDom.bind(doc, name, preventFileDropIfUIElement); 25664 dom.bind(editorRoot, name, preventFileDrop); 25665 }); 25666 editor.on('remove', function () { 25667 each$k(eventNames, function (name) { 25668 pageDom.unbind(doc, name, preventFileDropIfUIElement); 25669 dom.unbind(editorRoot, name, preventFileDrop); 25670 }); 25671 }); 25672 }; 25673 editor.on('init', function () { 25674 Delay.setEditorTimeout(editor, setup, 0); 25675 }); 25676 }; 25677 var init$2 = function (editor) { 25678 bindFakeDragEvents(editor); 25679 blockIeDrop(editor); 25680 if (shouldBlockUnsupportedDrop(editor)) { 25681 blockUnsupportedFileDrop(editor); 25682 } 25683 }; 25684 25685 var setup$1 = function (editor) { 25686 var renderFocusCaret = first(function () { 25687 if (!editor.removed && editor.getBody().contains(document.activeElement)) { 25688 var rng = editor.selection.getRng(); 25689 if (rng.collapsed) { 25690 var caretRange = renderRangeCaret(editor, rng, false); 25691 editor.selection.setRng(caretRange); 25692 } 25693 } 25694 }, 0); 25695 editor.on('focus', function () { 25696 renderFocusCaret.throttle(); 25697 }); 25698 editor.on('blur', function () { 25699 renderFocusCaret.cancel(); 25700 }); 25701 }; 25702 25703 var setup = function (editor) { 25704 editor.on('init', function () { 25705 editor.on('focusin', function (e) { 25706 var target = e.target; 25707 if (isMedia$2(target)) { 25708 var ceRoot = getContentEditableRoot$1(editor.getBody(), target); 25709 var node = isContentEditableFalse$b(ceRoot) ? ceRoot : target; 25710 if (editor.selection.getNode() !== node) { 25711 selectNode(editor, node).each(function (rng) { 25712 return editor.selection.setRng(rng); 25713 }); 25714 } 25715 } 25716 }); 25717 }); 25718 }; 25719 25720 var isContentEditableTrue = isContentEditableTrue$4; 25721 var isContentEditableFalse = isContentEditableFalse$b; 25722 var getContentEditableRoot = function (editor, node) { 25723 return getContentEditableRoot$1(editor.getBody(), node); 25724 }; 25725 var SelectionOverrides = function (editor) { 25726 var selection = editor.selection, dom = editor.dom; 25727 var isBlock = dom.isBlock; 25728 var rootNode = editor.getBody(); 25729 var fakeCaret = FakeCaret(editor, rootNode, isBlock, function () { 25730 return hasFocus(editor); 25731 }); 25732 var realSelectionId = 'sel-' + dom.uniqueId(); 25733 var elementSelectionAttr = 'data-mce-selected'; 25734 var selectedElement; 25735 var isFakeSelectionElement = function (node) { 25736 return dom.hasClass(node, 'mce-offscreen-selection'); 25737 }; 25738 var isFakeSelectionTargetElement = function (node) { 25739 return node !== rootNode && (isContentEditableFalse(node) || isMedia$2(node)) && dom.isChildOf(node, rootNode); 25740 }; 25741 var isNearFakeSelectionElement = function (pos) { 25742 return isBeforeContentEditableFalse(pos) || isAfterContentEditableFalse(pos) || isBeforeMedia(pos) || isAfterMedia(pos); 25743 }; 25744 var getRealSelectionElement = function () { 25745 var container = dom.get(realSelectionId); 25746 return container ? container.getElementsByTagName('*')[0] : container; 25747 }; 25748 var setRange = function (range) { 25749 if (range) { 25750 selection.setRng(range); 25751 } 25752 }; 25753 var getRange = selection.getRng; 25754 var showCaret = function (direction, node, before, scrollIntoView) { 25755 if (scrollIntoView === void 0) { 25756 scrollIntoView = true; 25757 } 25758 var e = editor.fire('ShowCaret', { 25759 target: node, 25760 direction: direction, 25761 before: before 25762 }); 25763 if (e.isDefaultPrevented()) { 25764 return null; 25765 } 25766 if (scrollIntoView) { 25767 selection.scrollIntoView(node, direction === -1); 25768 } 25769 return fakeCaret.show(before, node); 25770 }; 25771 var showBlockCaretContainer = function (blockCaretContainer) { 25772 if (blockCaretContainer.hasAttribute('data-mce-caret')) { 25773 showCaretContainerBlock(blockCaretContainer); 25774 setRange(getRange()); 25775 selection.scrollIntoView(blockCaretContainer); 25776 } 25777 }; 25778 var registerEvents = function () { 25779 editor.on('mouseup', function (e) { 25780 var range = getRange(); 25781 if (range.collapsed && isXYInContentArea(editor, e.clientX, e.clientY)) { 25782 renderCaretAtRange(editor, range, false).each(setRange); 25783 } 25784 }); 25785 editor.on('click', function (e) { 25786 var contentEditableRoot = getContentEditableRoot(editor, e.target); 25787 if (contentEditableRoot) { 25788 if (isContentEditableFalse(contentEditableRoot)) { 25789 e.preventDefault(); 25790 editor.focus(); 25791 } 25792 if (isContentEditableTrue(contentEditableRoot)) { 25793 if (dom.isChildOf(contentEditableRoot, selection.getNode())) { 25794 removeElementSelection(); 25795 } 25796 } 25797 } 25798 }); 25799 editor.on('blur NewBlock', removeElementSelection); 25800 editor.on('ResizeWindow FullscreenStateChanged', fakeCaret.reposition); 25801 var hasNormalCaretPosition = function (elm) { 25802 var start = elm.firstChild; 25803 if (isNullable(start)) { 25804 return false; 25805 } 25806 var startPos = CaretPosition.before(start); 25807 if (isBr$5(startPos.getNode()) && elm.childNodes.length === 1) { 25808 return !isNearFakeSelectionElement(startPos); 25809 } else { 25810 var caretWalker = CaretWalker(elm); 25811 var newPos = caretWalker.next(startPos); 25812 return newPos && !isNearFakeSelectionElement(newPos); 25813 } 25814 }; 25815 var isInSameBlock = function (node1, node2) { 25816 var block1 = dom.getParent(node1, isBlock); 25817 var block2 = dom.getParent(node2, isBlock); 25818 return block1 === block2; 25819 }; 25820 var hasBetterMouseTarget = function (targetNode, caretNode) { 25821 var targetBlock = dom.getParent(targetNode, isBlock); 25822 var caretBlock = dom.getParent(caretNode, isBlock); 25823 if (isNullable(targetBlock)) { 25824 return false; 25825 } 25826 if (targetNode !== caretBlock && dom.isChildOf(targetBlock, caretBlock) && isContentEditableFalse(getContentEditableRoot(editor, targetBlock)) === false) { 25827 return true; 25828 } 25829 return !dom.isChildOf(caretBlock, targetBlock) && !isInSameBlock(targetBlock, caretBlock) && hasNormalCaretPosition(targetBlock); 25830 }; 25831 editor.on('tap', function (e) { 25832 var targetElm = e.target; 25833 var contentEditableRoot = getContentEditableRoot(editor, targetElm); 25834 if (isContentEditableFalse(contentEditableRoot)) { 25835 e.preventDefault(); 25836 selectNode(editor, contentEditableRoot).each(setElementSelection); 25837 } else if (isFakeSelectionTargetElement(targetElm)) { 25838 selectNode(editor, targetElm).each(setElementSelection); 25839 } 25840 }, true); 25841 editor.on('mousedown', function (e) { 25842 var targetElm = e.target; 25843 if (targetElm !== rootNode && targetElm.nodeName !== 'HTML' && !dom.isChildOf(targetElm, rootNode)) { 25844 return; 25845 } 25846 if (isXYInContentArea(editor, e.clientX, e.clientY) === false) { 25847 return; 25848 } 25849 var contentEditableRoot = getContentEditableRoot(editor, targetElm); 25850 if (contentEditableRoot) { 25851 if (isContentEditableFalse(contentEditableRoot)) { 25852 e.preventDefault(); 25853 selectNode(editor, contentEditableRoot).each(setElementSelection); 25854 } else { 25855 removeElementSelection(); 25856 if (!(isContentEditableTrue(contentEditableRoot) && e.shiftKey) && !isXYWithinRange(e.clientX, e.clientY, selection.getRng())) { 25857 hideFakeCaret(); 25858 selection.placeCaretAt(e.clientX, e.clientY); 25859 } 25860 } 25861 } else if (isFakeSelectionTargetElement(targetElm)) { 25862 selectNode(editor, targetElm).each(setElementSelection); 25863 } else if (isFakeCaretTarget(targetElm) === false) { 25864 removeElementSelection(); 25865 hideFakeCaret(); 25866 var fakeCaretInfo = closestFakeCaret(rootNode, e.clientX, e.clientY); 25867 if (fakeCaretInfo) { 25868 if (!hasBetterMouseTarget(targetElm, fakeCaretInfo.node)) { 25869 e.preventDefault(); 25870 var range = showCaret(1, fakeCaretInfo.node, fakeCaretInfo.before, false); 25871 setRange(range); 25872 editor.getBody().focus(); 25873 } 25874 } 25875 } 25876 }); 25877 editor.on('keypress', function (e) { 25878 if (VK.modifierPressed(e)) { 25879 return; 25880 } 25881 if (isContentEditableFalse(selection.getNode())) { 25882 e.preventDefault(); 25883 } 25884 }); 25885 editor.on('GetSelectionRange', function (e) { 25886 var rng = e.range; 25887 if (selectedElement) { 25888 if (!selectedElement.parentNode) { 25889 selectedElement = null; 25890 return; 25891 } 25892 rng = rng.cloneRange(); 25893 rng.selectNode(selectedElement); 25894 e.range = rng; 25895 } 25896 }); 25897 editor.on('SetSelectionRange', function (e) { 25898 e.range = normalizeShortEndedElementSelection(e.range); 25899 var rng = setElementSelection(e.range, e.forward); 25900 if (rng) { 25901 e.range = rng; 25902 } 25903 }); 25904 var isPasteBin = function (node) { 25905 return node.id === 'mcepastebin'; 25906 }; 25907 editor.on('AfterSetSelectionRange', function (e) { 25908 var rng = e.range; 25909 var parentNode = rng.startContainer.parentNode; 25910 if (!isRangeInCaretContainer(rng) && !isPasteBin(parentNode)) { 25911 hideFakeCaret(); 25912 } 25913 if (!isFakeSelectionElement(parentNode)) { 25914 removeElementSelection(); 25915 } 25916 }); 25917 editor.on('copy', function (e) { 25918 var clipboardData = e.clipboardData; 25919 if (!e.isDefaultPrevented() && e.clipboardData && !Env.ie) { 25920 var realSelectionElement = getRealSelectionElement(); 25921 if (realSelectionElement) { 25922 e.preventDefault(); 25923 clipboardData.clearData(); 25924 clipboardData.setData('text/html', realSelectionElement.outerHTML); 25925 clipboardData.setData('text/plain', realSelectionElement.outerText || realSelectionElement.innerText); 25926 } 25927 } 25928 }); 25929 init$2(editor); 25930 setup$1(editor); 25931 setup(editor); 25932 }; 25933 var isWithinCaretContainer = function (node) { 25934 return isCaretContainer$2(node) || startsWithCaretContainer$1(node) || endsWithCaretContainer$1(node); 25935 }; 25936 var isRangeInCaretContainer = function (rng) { 25937 return isWithinCaretContainer(rng.startContainer) || isWithinCaretContainer(rng.endContainer); 25938 }; 25939 var normalizeShortEndedElementSelection = function (rng) { 25940 var shortEndedElements = editor.schema.getShortEndedElements(); 25941 var newRng = dom.createRng(); 25942 var startContainer = rng.startContainer; 25943 var startOffset = rng.startOffset; 25944 var endContainer = rng.endContainer; 25945 var endOffset = rng.endOffset; 25946 if (has$2(shortEndedElements, startContainer.nodeName.toLowerCase())) { 25947 if (startOffset === 0) { 25948 newRng.setStartBefore(startContainer); 25949 } else { 25950 newRng.setStartAfter(startContainer); 25951 } 25952 } else { 25953 newRng.setStart(startContainer, startOffset); 25954 } 25955 if (has$2(shortEndedElements, endContainer.nodeName.toLowerCase())) { 25956 if (endOffset === 0) { 25957 newRng.setEndBefore(endContainer); 25958 } else { 25959 newRng.setEndAfter(endContainer); 25960 } 25961 } else { 25962 newRng.setEnd(endContainer, endOffset); 25963 } 25964 return newRng; 25965 }; 25966 var setupOffscreenSelection = function (node, targetClone, origTargetClone) { 25967 var $ = editor.$; 25968 var $realSelectionContainer = descendant(SugarElement.fromDom(editor.getBody()), '#' + realSelectionId).fold(function () { 25969 return $([]); 25970 }, function (elm) { 25971 return $([elm.dom]); 25972 }); 25973 if ($realSelectionContainer.length === 0) { 25974 $realSelectionContainer = $('<div data-mce-bogus="all" class="mce-offscreen-selection"></div>').attr('id', realSelectionId); 25975 $realSelectionContainer.appendTo(editor.getBody()); 25976 } 25977 var newRange = dom.createRng(); 25978 if (targetClone === origTargetClone && Env.ie) { 25979 $realSelectionContainer.empty().append('<p style="font-size: 0" data-mce-bogus="all">\xA0</p>').append(targetClone); 25980 newRange.setStartAfter($realSelectionContainer[0].firstChild.firstChild); 25981 newRange.setEndAfter(targetClone); 25982 } else { 25983 $realSelectionContainer.empty().append(nbsp).append(targetClone).append(nbsp); 25984 newRange.setStart($realSelectionContainer[0].firstChild, 1); 25985 newRange.setEnd($realSelectionContainer[0].lastChild, 0); 25986 } 25987 $realSelectionContainer.css({ top: dom.getPos(node, editor.getBody()).y }); 25988 $realSelectionContainer[0].focus(); 25989 var sel = selection.getSel(); 25990 sel.removeAllRanges(); 25991 sel.addRange(newRange); 25992 return newRange; 25993 }; 25994 var selectElement = function (elm) { 25995 var targetClone = elm.cloneNode(true); 25996 var e = editor.fire('ObjectSelected', { 25997 target: elm, 25998 targetClone: targetClone 25999 }); 26000 if (e.isDefaultPrevented()) { 26001 return null; 26002 } 26003 var range = setupOffscreenSelection(elm, e.targetClone, targetClone); 26004 var nodeElm = SugarElement.fromDom(elm); 26005 each$k(descendants(SugarElement.fromDom(editor.getBody()), '*[data-mce-selected]'), function (elm) { 26006 if (!eq(nodeElm, elm)) { 26007 remove$6(elm, elementSelectionAttr); 26008 } 26009 }); 26010 if (!dom.getAttrib(elm, elementSelectionAttr)) { 26011 elm.setAttribute(elementSelectionAttr, '1'); 26012 } 26013 selectedElement = elm; 26014 hideFakeCaret(); 26015 return range; 26016 }; 26017 var setElementSelection = function (range, forward) { 26018 if (!range) { 26019 return null; 26020 } 26021 if (range.collapsed) { 26022 if (!isRangeInCaretContainer(range)) { 26023 var dir = forward ? 1 : -1; 26024 var caretPosition = getNormalizedRangeEndPoint(dir, rootNode, range); 26025 var beforeNode = caretPosition.getNode(!forward); 26026 if (isFakeCaretTarget(beforeNode)) { 26027 return showCaret(dir, beforeNode, forward ? !caretPosition.isAtEnd() : false, false); 26028 } 26029 var afterNode = caretPosition.getNode(forward); 26030 if (isFakeCaretTarget(afterNode)) { 26031 return showCaret(dir, afterNode, forward ? false : !caretPosition.isAtEnd(), false); 26032 } 26033 } 26034 return null; 26035 } 26036 var startContainer = range.startContainer; 26037 var startOffset = range.startOffset; 26038 var endOffset = range.endOffset; 26039 if (startContainer.nodeType === 3 && startOffset === 0 && isContentEditableFalse(startContainer.parentNode)) { 26040 startContainer = startContainer.parentNode; 26041 startOffset = dom.nodeIndex(startContainer); 26042 startContainer = startContainer.parentNode; 26043 } 26044 if (startContainer.nodeType !== 1) { 26045 return null; 26046 } 26047 if (endOffset === startOffset + 1 && startContainer === range.endContainer) { 26048 var node = startContainer.childNodes[startOffset]; 26049 if (isFakeSelectionTargetElement(node)) { 26050 return selectElement(node); 26051 } 26052 } 26053 return null; 26054 }; 26055 var removeElementSelection = function () { 26056 if (selectedElement) { 26057 selectedElement.removeAttribute(elementSelectionAttr); 26058 } 26059 descendant(SugarElement.fromDom(editor.getBody()), '#' + realSelectionId).each(remove$7); 26060 selectedElement = null; 26061 }; 26062 var destroy = function () { 26063 fakeCaret.destroy(); 26064 selectedElement = null; 26065 }; 26066 var hideFakeCaret = function () { 26067 fakeCaret.hide(); 26068 }; 26069 if (Env.ceFalse && !isRtc(editor)) { 26070 registerEvents(); 26071 } 26072 return { 26073 showCaret: showCaret, 26074 showBlockCaretContainer: showBlockCaretContainer, 26075 hideFakeCaret: hideFakeCaret, 26076 destroy: destroy 26077 }; 26078 }; 26079 26080 var Quirks = function (editor) { 26081 var each = Tools.each; 26082 var BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection, parser = editor.parser; 26083 var isGecko = Env.gecko, isIE = Env.ie, isWebKit = Env.webkit; 26084 var mceInternalUrlPrefix = 'data:text/mce-internal,'; 26085 var mceInternalDataType = isIE ? 'Text' : 'URL'; 26086 var setEditorCommandState = function (cmd, state) { 26087 try { 26088 editor.getDoc().execCommand(cmd, false, state); 26089 } catch (ex) { 26090 } 26091 }; 26092 var isDefaultPrevented = function (e) { 26093 return e.isDefaultPrevented(); 26094 }; 26095 var setMceInternalContent = function (e) { 26096 var selectionHtml, internalContent; 26097 if (e.dataTransfer) { 26098 if (editor.selection.isCollapsed() && e.target.tagName === 'IMG') { 26099 selection.select(e.target); 26100 } 26101 selectionHtml = editor.selection.getContent(); 26102 if (selectionHtml.length > 0) { 26103 internalContent = mceInternalUrlPrefix + escape(editor.id) + ',' + escape(selectionHtml); 26104 e.dataTransfer.setData(mceInternalDataType, internalContent); 26105 } 26106 } 26107 }; 26108 var getMceInternalContent = function (e) { 26109 var internalContent; 26110 if (e.dataTransfer) { 26111 internalContent = e.dataTransfer.getData(mceInternalDataType); 26112 if (internalContent && internalContent.indexOf(mceInternalUrlPrefix) >= 0) { 26113 internalContent = internalContent.substr(mceInternalUrlPrefix.length).split(','); 26114 return { 26115 id: unescape(internalContent[0]), 26116 html: unescape(internalContent[1]) 26117 }; 26118 } 26119 } 26120 return null; 26121 }; 26122 var insertClipboardContents = function (content, internal) { 26123 if (editor.queryCommandSupported('mceInsertClipboardContent')) { 26124 editor.execCommand('mceInsertClipboardContent', false, { 26125 content: content, 26126 internal: internal 26127 }); 26128 } else { 26129 editor.execCommand('mceInsertContent', false, content); 26130 } 26131 }; 26132 var emptyEditorWhenDeleting = function () { 26133 var serializeRng = function (rng) { 26134 var body = dom.create('body'); 26135 var contents = rng.cloneContents(); 26136 body.appendChild(contents); 26137 return selection.serializer.serialize(body, { format: 'html' }); 26138 }; 26139 var allContentsSelected = function (rng) { 26140 var selection = serializeRng(rng); 26141 var allRng = dom.createRng(); 26142 allRng.selectNode(editor.getBody()); 26143 var allSelection = serializeRng(allRng); 26144 return selection === allSelection; 26145 }; 26146 editor.on('keydown', function (e) { 26147 var keyCode = e.keyCode; 26148 var isCollapsed, body; 26149 if (!isDefaultPrevented(e) && (keyCode === DELETE || keyCode === BACKSPACE)) { 26150 isCollapsed = editor.selection.isCollapsed(); 26151 body = editor.getBody(); 26152 if (isCollapsed && !dom.isEmpty(body)) { 26153 return; 26154 } 26155 if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) { 26156 return; 26157 } 26158 e.preventDefault(); 26159 editor.setContent(''); 26160 if (body.firstChild && dom.isBlock(body.firstChild)) { 26161 editor.selection.setCursorLocation(body.firstChild, 0); 26162 } else { 26163 editor.selection.setCursorLocation(body, 0); 26164 } 26165 editor.nodeChanged(); 26166 } 26167 }); 26168 }; 26169 var selectAll = function () { 26170 editor.shortcuts.add('meta+a', null, 'SelectAll'); 26171 }; 26172 var documentElementEditingFocus = function () { 26173 if (!editor.inline) { 26174 dom.bind(editor.getDoc(), 'mousedown mouseup', function (e) { 26175 var rng; 26176 if (e.target === editor.getDoc().documentElement) { 26177 rng = selection.getRng(); 26178 editor.getBody().focus(); 26179 if (e.type === 'mousedown') { 26180 if (isCaretContainer$2(rng.startContainer)) { 26181 return; 26182 } 26183 selection.placeCaretAt(e.clientX, e.clientY); 26184 } else { 26185 selection.setRng(rng); 26186 } 26187 } 26188 }); 26189 } 26190 }; 26191 var removeHrOnBackspace = function () { 26192 editor.on('keydown', function (e) { 26193 if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) { 26194 if (!editor.getBody().getElementsByTagName('hr').length) { 26195 return; 26196 } 26197 if (selection.isCollapsed() && selection.getRng().startOffset === 0) { 26198 var node = selection.getNode(); 26199 var previousSibling = node.previousSibling; 26200 if (node.nodeName === 'HR') { 26201 dom.remove(node); 26202 e.preventDefault(); 26203 return; 26204 } 26205 if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'hr') { 26206 dom.remove(previousSibling); 26207 e.preventDefault(); 26208 } 26209 } 26210 } 26211 }); 26212 }; 26213 var focusBody = function () { 26214 if (!Range.prototype.getClientRects) { 26215 editor.on('mousedown', function (e) { 26216 if (!isDefaultPrevented(e) && e.target.nodeName === 'HTML') { 26217 var body_1 = editor.getBody(); 26218 body_1.blur(); 26219 Delay.setEditorTimeout(editor, function () { 26220 body_1.focus(); 26221 }); 26222 } 26223 }); 26224 } 26225 }; 26226 var selectControlElements = function () { 26227 editor.on('click', function (e) { 26228 var target = e.target; 26229 if (/^(IMG|HR)$/.test(target.nodeName) && dom.getContentEditableParent(target) !== 'false') { 26230 e.preventDefault(); 26231 editor.selection.select(target); 26232 editor.nodeChanged(); 26233 } 26234 if (target.nodeName === 'A' && dom.hasClass(target, 'mce-item-anchor')) { 26235 e.preventDefault(); 26236 selection.select(target); 26237 } 26238 }); 26239 }; 26240 var removeStylesWhenDeletingAcrossBlockElements = function () { 26241 var getAttributeApplyFunction = function () { 26242 var template = dom.getAttribs(selection.getStart().cloneNode(false)); 26243 return function () { 26244 var target = selection.getStart(); 26245 if (target !== editor.getBody()) { 26246 dom.setAttrib(target, 'style', null); 26247 each(template, function (attr) { 26248 target.setAttributeNode(attr.cloneNode(true)); 26249 }); 26250 } 26251 }; 26252 }; 26253 var isSelectionAcrossElements = function () { 26254 return !selection.isCollapsed() && dom.getParent(selection.getStart(), dom.isBlock) !== dom.getParent(selection.getEnd(), dom.isBlock); 26255 }; 26256 editor.on('keypress', function (e) { 26257 var applyAttributes; 26258 if (!isDefaultPrevented(e) && (e.keyCode === 8 || e.keyCode === 46) && isSelectionAcrossElements()) { 26259 applyAttributes = getAttributeApplyFunction(); 26260 editor.getDoc().execCommand('delete', false, null); 26261 applyAttributes(); 26262 e.preventDefault(); 26263 return false; 26264 } 26265 }); 26266 dom.bind(editor.getDoc(), 'cut', function (e) { 26267 var applyAttributes; 26268 if (!isDefaultPrevented(e) && isSelectionAcrossElements()) { 26269 applyAttributes = getAttributeApplyFunction(); 26270 Delay.setEditorTimeout(editor, function () { 26271 applyAttributes(); 26272 }); 26273 } 26274 }); 26275 }; 26276 var disableBackspaceIntoATable = function () { 26277 editor.on('keydown', function (e) { 26278 if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) { 26279 if (selection.isCollapsed() && selection.getRng().startOffset === 0) { 26280 var previousSibling = selection.getNode().previousSibling; 26281 if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'table') { 26282 e.preventDefault(); 26283 return false; 26284 } 26285 } 26286 } 26287 }); 26288 }; 26289 var removeBlockQuoteOnBackSpace = function () { 26290 editor.on('keydown', function (e) { 26291 var rng, parent; 26292 if (isDefaultPrevented(e) || e.keyCode !== VK.BACKSPACE) { 26293 return; 26294 } 26295 rng = selection.getRng(); 26296 var container = rng.startContainer; 26297 var offset = rng.startOffset; 26298 var root = dom.getRoot(); 26299 parent = container; 26300 if (!rng.collapsed || offset !== 0) { 26301 return; 26302 } 26303 while (parent && parent.parentNode && parent.parentNode.firstChild === parent && parent.parentNode !== root) { 26304 parent = parent.parentNode; 26305 } 26306 if (parent.tagName === 'BLOCKQUOTE') { 26307 editor.formatter.toggle('blockquote', null, parent); 26308 rng = dom.createRng(); 26309 rng.setStart(container, 0); 26310 rng.setEnd(container, 0); 26311 selection.setRng(rng); 26312 } 26313 }); 26314 }; 26315 var setGeckoEditingOptions = function () { 26316 var setOpts = function () { 26317 setEditorCommandState('StyleWithCSS', false); 26318 setEditorCommandState('enableInlineTableEditing', false); 26319 if (!getObjectResizing(editor)) { 26320 setEditorCommandState('enableObjectResizing', false); 26321 } 26322 }; 26323 if (!isReadOnly$1(editor)) { 26324 editor.on('BeforeExecCommand mousedown', setOpts); 26325 } 26326 }; 26327 var addBrAfterLastLinks = function () { 26328 var fixLinks = function () { 26329 each(dom.select('a'), function (node) { 26330 var parentNode = node.parentNode; 26331 var root = dom.getRoot(); 26332 if (parentNode.lastChild === node) { 26333 while (parentNode && !dom.isBlock(parentNode)) { 26334 if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) { 26335 return; 26336 } 26337 parentNode = parentNode.parentNode; 26338 } 26339 dom.add(parentNode, 'br', { 'data-mce-bogus': 1 }); 26340 } 26341 }); 26342 }; 26343 editor.on('SetContent ExecCommand', function (e) { 26344 if (e.type === 'setcontent' || e.command === 'mceInsertLink') { 26345 fixLinks(); 26346 } 26347 }); 26348 }; 26349 var setDefaultBlockType = function () { 26350 if (getForcedRootBlock(editor)) { 26351 editor.on('init', function () { 26352 setEditorCommandState('DefaultParagraphSeparator', getForcedRootBlock(editor)); 26353 }); 26354 } 26355 }; 26356 var normalizeSelection = function () { 26357 editor.on('keyup focusin mouseup', function (e) { 26358 if (!VK.modifierPressed(e)) { 26359 selection.normalize(); 26360 } 26361 }, true); 26362 }; 26363 var showBrokenImageIcon = function () { 26364 editor.contentStyles.push('img:-moz-broken {' + '-moz-force-broken-image-icon:1;' + 'min-width:24px;' + 'min-height:24px' + '}'); 26365 }; 26366 var restoreFocusOnKeyDown = function () { 26367 if (!editor.inline) { 26368 editor.on('keydown', function () { 26369 if (document.activeElement === document.body) { 26370 editor.getWin().focus(); 26371 } 26372 }); 26373 } 26374 }; 26375 var bodyHeight = function () { 26376 if (!editor.inline) { 26377 editor.contentStyles.push('body {min-height: 150px}'); 26378 editor.on('click', function (e) { 26379 var rng; 26380 if (e.target.nodeName === 'HTML') { 26381 if (Env.ie > 11) { 26382 editor.getBody().focus(); 26383 return; 26384 } 26385 rng = editor.selection.getRng(); 26386 editor.getBody().focus(); 26387 editor.selection.setRng(rng); 26388 editor.selection.normalize(); 26389 editor.nodeChanged(); 26390 } 26391 }); 26392 } 26393 }; 26394 var blockCmdArrowNavigation = function () { 26395 if (Env.mac) { 26396 editor.on('keydown', function (e) { 26397 if (VK.metaKeyPressed(e) && !e.shiftKey && (e.keyCode === 37 || e.keyCode === 39)) { 26398 e.preventDefault(); 26399 var selection_1 = editor.selection.getSel(); 26400 selection_1.modify('move', e.keyCode === 37 ? 'backward' : 'forward', 'lineboundary'); 26401 } 26402 }); 26403 } 26404 }; 26405 var disableAutoUrlDetect = function () { 26406 setEditorCommandState('AutoUrlDetect', false); 26407 }; 26408 var tapLinksAndImages = function () { 26409 editor.on('click', function (e) { 26410 var elm = e.target; 26411 do { 26412 if (elm.tagName === 'A') { 26413 e.preventDefault(); 26414 return; 26415 } 26416 } while (elm = elm.parentNode); 26417 }); 26418 editor.contentStyles.push('.mce-content-body {-webkit-touch-callout: none}'); 26419 }; 26420 var blockFormSubmitInsideEditor = function () { 26421 editor.on('init', function () { 26422 editor.dom.bind(editor.getBody(), 'submit', function (e) { 26423 e.preventDefault(); 26424 }); 26425 }); 26426 }; 26427 var removeAppleInterchangeBrs = function () { 26428 parser.addNodeFilter('br', function (nodes) { 26429 var i = nodes.length; 26430 while (i--) { 26431 if (nodes[i].attr('class') === 'Apple-interchange-newline') { 26432 nodes[i].remove(); 26433 } 26434 } 26435 }); 26436 }; 26437 var ieInternalDragAndDrop = function () { 26438 editor.on('dragstart', function (e) { 26439 setMceInternalContent(e); 26440 }); 26441 editor.on('drop', function (e) { 26442 if (!isDefaultPrevented(e)) { 26443 var internalContent = getMceInternalContent(e); 26444 if (internalContent && internalContent.id !== editor.id) { 26445 e.preventDefault(); 26446 var rng = fromPoint(e.x, e.y, editor.getDoc()); 26447 selection.setRng(rng); 26448 insertClipboardContents(internalContent.html, true); 26449 } 26450 } 26451 }); 26452 }; 26453 var refreshContentEditable = noop; 26454 var isHidden = function () { 26455 if (!isGecko || editor.removed) { 26456 return false; 26457 } 26458 var sel = editor.selection.getSel(); 26459 return !sel || !sel.rangeCount || sel.rangeCount === 0; 26460 }; 26461 var setupRtc = function () { 26462 if (isWebKit) { 26463 documentElementEditingFocus(); 26464 selectControlElements(); 26465 blockFormSubmitInsideEditor(); 26466 selectAll(); 26467 if (Env.iOS) { 26468 restoreFocusOnKeyDown(); 26469 bodyHeight(); 26470 tapLinksAndImages(); 26471 } 26472 } 26473 if (isGecko) { 26474 focusBody(); 26475 setGeckoEditingOptions(); 26476 showBrokenImageIcon(); 26477 blockCmdArrowNavigation(); 26478 } 26479 }; 26480 var setup = function () { 26481 removeBlockQuoteOnBackSpace(); 26482 emptyEditorWhenDeleting(); 26483 if (!Env.windowsPhone) { 26484 normalizeSelection(); 26485 } 26486 if (isWebKit) { 26487 documentElementEditingFocus(); 26488 selectControlElements(); 26489 setDefaultBlockType(); 26490 blockFormSubmitInsideEditor(); 26491 disableBackspaceIntoATable(); 26492 removeAppleInterchangeBrs(); 26493 if (Env.iOS) { 26494 restoreFocusOnKeyDown(); 26495 bodyHeight(); 26496 tapLinksAndImages(); 26497 } else { 26498 selectAll(); 26499 } 26500 } 26501 if (Env.ie >= 11) { 26502 bodyHeight(); 26503 disableBackspaceIntoATable(); 26504 } 26505 if (Env.ie) { 26506 selectAll(); 26507 disableAutoUrlDetect(); 26508 ieInternalDragAndDrop(); 26509 } 26510 if (isGecko) { 26511 removeHrOnBackspace(); 26512 focusBody(); 26513 removeStylesWhenDeletingAcrossBlockElements(); 26514 setGeckoEditingOptions(); 26515 addBrAfterLastLinks(); 26516 showBrokenImageIcon(); 26517 blockCmdArrowNavigation(); 26518 disableBackspaceIntoATable(); 26519 } 26520 }; 26521 if (isRtc(editor)) { 26522 setupRtc(); 26523 } else { 26524 setup(); 26525 } 26526 return { 26527 refreshContentEditable: refreshContentEditable, 26528 isHidden: isHidden 26529 }; 26530 }; 26531 26532 var DOM$6 = DOMUtils.DOM; 26533 var appendStyle = function (editor, text) { 26534 var body = SugarElement.fromDom(editor.getBody()); 26535 var container = getStyleContainer(getRootNode(body)); 26536 var style = SugarElement.fromTag('style'); 26537 set$1(style, 'type', 'text/css'); 26538 append$1(style, SugarElement.fromText(text)); 26539 append$1(container, style); 26540 editor.on('remove', function () { 26541 remove$7(style); 26542 }); 26543 }; 26544 var getRootName = function (editor) { 26545 return editor.inline ? editor.getElement().nodeName.toLowerCase() : undefined; 26546 }; 26547 var removeUndefined = function (obj) { 26548 return filter$3(obj, function (v) { 26549 return isUndefined(v) === false; 26550 }); 26551 }; 26552 var mkSchemaSettings = function (editor) { 26553 var settings = editor.settings; 26554 return removeUndefined({ 26555 block_elements: settings.block_elements, 26556 boolean_attributes: settings.boolean_attributes, 26557 custom_elements: settings.custom_elements, 26558 extended_valid_elements: settings.extended_valid_elements, 26559 invalid_elements: settings.invalid_elements, 26560 invalid_styles: settings.invalid_styles, 26561 move_caret_before_on_enter_elements: settings.move_caret_before_on_enter_elements, 26562 non_empty_elements: settings.non_empty_elements, 26563 schema: settings.schema, 26564 self_closing_elements: settings.self_closing_elements, 26565 short_ended_elements: settings.short_ended_elements, 26566 special: settings.special, 26567 text_block_elements: settings.text_block_elements, 26568 text_inline_elements: settings.text_inline_elements, 26569 valid_children: settings.valid_children, 26570 valid_classes: settings.valid_classes, 26571 valid_elements: settings.valid_elements, 26572 valid_styles: settings.valid_styles, 26573 verify_html: settings.verify_html, 26574 whitespace_elements: settings.whitespace_elements, 26575 padd_empty_block_inline_children: settings.format_empty_lines 26576 }); 26577 }; 26578 var mkParserSettings = function (editor) { 26579 var settings = editor.settings; 26580 var blobCache = editor.editorUpload.blobCache; 26581 return removeUndefined({ 26582 allow_conditional_comments: settings.allow_conditional_comments, 26583 allow_html_data_urls: settings.allow_html_data_urls, 26584 allow_svg_data_urls: settings.allow_svg_data_urls, 26585 allow_html_in_named_anchor: settings.allow_html_in_named_anchor, 26586 allow_script_urls: settings.allow_script_urls, 26587 allow_unsafe_link_target: settings.allow_unsafe_link_target, 26588 convert_fonts_to_spans: settings.convert_fonts_to_spans, 26589 fix_list_elements: settings.fix_list_elements, 26590 font_size_legacy_values: settings.font_size_legacy_values, 26591 forced_root_block: settings.forced_root_block, 26592 forced_root_block_attrs: settings.forced_root_block_attrs, 26593 padd_empty_with_br: settings.padd_empty_with_br, 26594 preserve_cdata: settings.preserve_cdata, 26595 remove_trailing_brs: settings.remove_trailing_brs, 26596 inline_styles: settings.inline_styles, 26597 root_name: getRootName(editor), 26598 validate: true, 26599 blob_cache: blobCache, 26600 document: editor.getDoc(), 26601 images_dataimg_filter: settings.images_dataimg_filter 26602 }); 26603 }; 26604 var mkSerializerSettings = function (editor) { 26605 var settings = editor.settings; 26606 return __assign(__assign(__assign({}, mkParserSettings(editor)), mkSchemaSettings(editor)), removeUndefined({ 26607 url_converter: settings.url_converter, 26608 url_converter_scope: settings.url_converter_scope, 26609 element_format: settings.element_format, 26610 entities: settings.entities, 26611 entity_encoding: settings.entity_encoding, 26612 indent: settings.indent, 26613 indent_after: settings.indent_after, 26614 indent_before: settings.indent_before 26615 })); 26616 }; 26617 var createParser = function (editor) { 26618 var parser = DomParser(mkParserSettings(editor), editor.schema); 26619 parser.addAttributeFilter('src,href,style,tabindex', function (nodes, name) { 26620 var i = nodes.length, node, value; 26621 var dom = editor.dom; 26622 var internalName = 'data-mce-' + name; 26623 while (i--) { 26624 node = nodes[i]; 26625 value = node.attr(name); 26626 if (value && !node.attr(internalName)) { 26627 if (value.indexOf('data:') === 0 || value.indexOf('blob:') === 0) { 26628 continue; 26629 } 26630 if (name === 'style') { 26631 value = dom.serializeStyle(dom.parseStyle(value), node.name); 26632 if (!value.length) { 26633 value = null; 26634 } 26635 node.attr(internalName, value); 26636 node.attr(name, value); 26637 } else if (name === 'tabindex') { 26638 node.attr(internalName, value); 26639 node.attr(name, null); 26640 } else { 26641 node.attr(internalName, editor.convertURL(value, name, node.name)); 26642 } 26643 } 26644 } 26645 }); 26646 parser.addNodeFilter('script', function (nodes) { 26647 var i = nodes.length; 26648 while (i--) { 26649 var node = nodes[i]; 26650 var type = node.attr('type') || 'no/type'; 26651 if (type.indexOf('mce-') !== 0) { 26652 node.attr('type', 'mce-' + type); 26653 } 26654 } 26655 }); 26656 if (editor.settings.preserve_cdata) { 26657 parser.addNodeFilter('#cdata', function (nodes) { 26658 var i = nodes.length; 26659 while (i--) { 26660 var node = nodes[i]; 26661 node.type = 8; 26662 node.name = '#comment'; 26663 node.value = '[CDATA[' + editor.dom.encode(node.value) + ']]'; 26664 } 26665 }); 26666 } 26667 parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function (nodes) { 26668 var i = nodes.length; 26669 var nonEmptyElements = editor.schema.getNonEmptyElements(); 26670 while (i--) { 26671 var node = nodes[i]; 26672 if (node.isEmpty(nonEmptyElements) && node.getAll('br').length === 0) { 26673 node.append(new AstNode('br', 1)).shortEnded = true; 26674 } 26675 } 26676 }); 26677 return parser; 26678 }; 26679 var autoFocus = function (editor) { 26680 if (editor.settings.auto_focus) { 26681 Delay.setEditorTimeout(editor, function () { 26682 var focusEditor; 26683 if (editor.settings.auto_focus === true) { 26684 focusEditor = editor; 26685 } else { 26686 focusEditor = editor.editorManager.get(editor.settings.auto_focus); 26687 } 26688 if (!focusEditor.destroyed) { 26689 focusEditor.focus(); 26690 } 26691 }, 100); 26692 } 26693 }; 26694 var moveSelectionToFirstCaretPosition = function (editor) { 26695 var root = editor.dom.getRoot(); 26696 if (!editor.inline && (!hasAnyRanges(editor) || editor.selection.getStart(true) === root)) { 26697 firstPositionIn(root).each(function (pos) { 26698 var node = pos.getNode(); 26699 var caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos; 26700 if (Env.browser.isIE()) { 26701 storeNative(editor, caretPos.toRange()); 26702 } else { 26703 editor.selection.setRng(caretPos.toRange()); 26704 } 26705 }); 26706 } 26707 }; 26708 var initEditor = function (editor) { 26709 editor.bindPendingEventDelegates(); 26710 editor.initialized = true; 26711 fireInit(editor); 26712 editor.focus(true); 26713 moveSelectionToFirstCaretPosition(editor); 26714 editor.nodeChanged({ initial: true }); 26715 editor.execCallback('init_instance_callback', editor); 26716 autoFocus(editor); 26717 }; 26718 var getStyleSheetLoader$1 = function (editor) { 26719 return editor.inline ? editor.ui.styleSheetLoader : editor.dom.styleSheetLoader; 26720 }; 26721 var makeStylesheetLoadingPromises = function (editor, css, framedFonts) { 26722 var promises = [new promiseObj(function (resolve, reject) { 26723 return getStyleSheetLoader$1(editor).loadAll(css, resolve, reject); 26724 })]; 26725 if (editor.inline) { 26726 return promises; 26727 } else { 26728 return promises.concat([new promiseObj(function (resolve, reject) { 26729 return editor.ui.styleSheetLoader.loadAll(framedFonts, resolve, reject); 26730 })]); 26731 } 26732 }; 26733 var loadContentCss = function (editor) { 26734 var styleSheetLoader = getStyleSheetLoader$1(editor); 26735 var fontCss = getFontCss(editor); 26736 var css = editor.contentCSS; 26737 var removeCss = function () { 26738 styleSheetLoader.unloadAll(css); 26739 if (!editor.inline) { 26740 editor.ui.styleSheetLoader.unloadAll(fontCss); 26741 } 26742 }; 26743 var loaded = function () { 26744 if (editor.removed) { 26745 removeCss(); 26746 } else { 26747 editor.on('remove', removeCss); 26748 } 26749 }; 26750 if (editor.contentStyles.length > 0) { 26751 var contentCssText_1 = ''; 26752 Tools.each(editor.contentStyles, function (style) { 26753 contentCssText_1 += style + '\r\n'; 26754 }); 26755 editor.dom.addStyle(contentCssText_1); 26756 } 26757 var allStylesheets = promiseObj.all(makeStylesheetLoadingPromises(editor, css, fontCss)).then(loaded).catch(loaded); 26758 if (editor.settings.content_style) { 26759 appendStyle(editor, editor.settings.content_style); 26760 } 26761 return allStylesheets; 26762 }; 26763 var preInit = function (editor) { 26764 var settings = editor.settings, doc = editor.getDoc(), body = editor.getBody(); 26765 firePreInit(editor); 26766 if (!settings.browser_spellcheck && !settings.gecko_spellcheck) { 26767 doc.body.spellcheck = false; 26768 DOM$6.setAttrib(body, 'spellcheck', 'false'); 26769 } 26770 editor.quirks = Quirks(editor); 26771 firePostRender(editor); 26772 var directionality = getDirectionality(editor); 26773 if (directionality !== undefined) { 26774 body.dir = directionality; 26775 } 26776 if (settings.protect) { 26777 editor.on('BeforeSetContent', function (e) { 26778 Tools.each(settings.protect, function (pattern) { 26779 e.content = e.content.replace(pattern, function (str) { 26780 return '<!--mce:protected ' + escape(str) + '-->'; 26781 }); 26782 }); 26783 }); 26784 } 26785 editor.on('SetContent', function () { 26786 editor.addVisual(editor.getBody()); 26787 }); 26788 editor.on('compositionstart compositionend', function (e) { 26789 editor.composing = e.type === 'compositionstart'; 26790 }); 26791 }; 26792 var loadInitialContent = function (editor) { 26793 if (!isRtc(editor)) { 26794 editor.load({ 26795 initial: true, 26796 format: 'html' 26797 }); 26798 } 26799 editor.startContent = editor.getContent({ format: 'raw' }); 26800 }; 26801 var initEditorWithInitialContent = function (editor) { 26802 if (editor.removed !== true) { 26803 loadInitialContent(editor); 26804 initEditor(editor); 26805 } 26806 }; 26807 var initContentBody = function (editor, skipWrite) { 26808 var settings = editor.settings; 26809 var targetElm = editor.getElement(); 26810 var doc = editor.getDoc(); 26811 if (!settings.inline) { 26812 editor.getElement().style.visibility = editor.orgVisibility; 26813 } 26814 if (!skipWrite && !editor.inline) { 26815 doc.open(); 26816 doc.write(editor.iframeHTML); 26817 doc.close(); 26818 } 26819 if (editor.inline) { 26820 DOM$6.addClass(targetElm, 'mce-content-body'); 26821 editor.contentDocument = doc = document; 26822 editor.contentWindow = window; 26823 editor.bodyElement = targetElm; 26824 editor.contentAreaContainer = targetElm; 26825 } 26826 var body = editor.getBody(); 26827 body.disabled = true; 26828 editor.readonly = !!settings.readonly; 26829 if (!editor.readonly) { 26830 if (editor.inline && DOM$6.getStyle(body, 'position', true) === 'static') { 26831 body.style.position = 'relative'; 26832 } 26833 body.contentEditable = editor.getParam('content_editable_state', true); 26834 } 26835 body.disabled = false; 26836 editor.editorUpload = EditorUpload(editor); 26837 editor.schema = Schema(mkSchemaSettings(editor)); 26838 editor.dom = DOMUtils(doc, { 26839 keep_values: true, 26840 url_converter: editor.convertURL, 26841 url_converter_scope: editor, 26842 hex_colors: settings.force_hex_style_colors, 26843 update_styles: true, 26844 root_element: editor.inline ? editor.getBody() : null, 26845 collect: function () { 26846 return editor.inline; 26847 }, 26848 schema: editor.schema, 26849 contentCssCors: shouldUseContentCssCors(editor), 26850 referrerPolicy: getReferrerPolicy(editor), 26851 onSetAttrib: function (e) { 26852 editor.fire('SetAttrib', e); 26853 } 26854 }); 26855 editor.parser = createParser(editor); 26856 editor.serializer = DomSerializer(mkSerializerSettings(editor), editor); 26857 editor.selection = EditorSelection(editor.dom, editor.getWin(), editor.serializer, editor); 26858 editor.annotator = Annotator(editor); 26859 editor.formatter = Formatter(editor); 26860 editor.undoManager = UndoManager(editor); 26861 editor._nodeChangeDispatcher = new NodeChange(editor); 26862 editor._selectionOverrides = SelectionOverrides(editor); 26863 setup$e(editor); 26864 setup$3(editor); 26865 if (!isRtc(editor)) { 26866 setup$2(editor); 26867 } 26868 var caret = setup$4(editor); 26869 setup$f(editor, caret); 26870 setup$d(editor); 26871 setup$g(editor); 26872 var setupRtcThunk = setup$i(editor); 26873 preInit(editor); 26874 setupRtcThunk.fold(function () { 26875 loadContentCss(editor).then(function () { 26876 return initEditorWithInitialContent(editor); 26877 }); 26878 }, function (setupRtc) { 26879 editor.setProgressState(true); 26880 loadContentCss(editor).then(function () { 26881 setupRtc().then(function (_rtcMode) { 26882 editor.setProgressState(false); 26883 initEditorWithInitialContent(editor); 26884 }, function (err) { 26885 editor.notificationManager.open({ 26886 type: 'error', 26887 text: String(err) 26888 }); 26889 initEditorWithInitialContent(editor); 26890 }); 26891 }); 26892 }); 26893 }; 26894 26895 var DOM$5 = DOMUtils.DOM; 26896 var relaxDomain = function (editor, ifr) { 26897 if (document.domain !== window.location.hostname && Env.browser.isIE()) { 26898 var bodyUuid = uuid('mce'); 26899 editor[bodyUuid] = function () { 26900 initContentBody(editor); 26901 }; 26902 var domainRelaxUrl = 'javascript:(function(){' + 'document.open();document.domain="' + document.domain + '";' + 'var ed = window.parent.tinymce.get("' + editor.id + '");document.write(ed.iframeHTML);' + 'document.close();ed.' + bodyUuid + '(true);})()'; 26903 DOM$5.setAttrib(ifr, 'src', domainRelaxUrl); 26904 return true; 26905 } 26906 return false; 26907 }; 26908 var createIframeElement = function (id, title, height, customAttrs) { 26909 var iframe = SugarElement.fromTag('iframe'); 26910 setAll$1(iframe, customAttrs); 26911 setAll$1(iframe, { 26912 id: id + '_ifr', 26913 frameBorder: '0', 26914 allowTransparency: 'true', 26915 title: title 26916 }); 26917 add$1(iframe, 'tox-edit-area__iframe'); 26918 return iframe; 26919 }; 26920 var getIframeHtml = function (editor) { 26921 var iframeHTML = getDocType(editor) + '<html><head>'; 26922 if (getDocumentBaseUrl(editor) !== editor.documentBaseUrl) { 26923 iframeHTML += '<base href="' + editor.documentBaseURI.getURI() + '" />'; 26924 } 26925 iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; 26926 var bodyId = getBodyId(editor); 26927 var bodyClass = getBodyClass(editor); 26928 var translatedAriaText = editor.translate(getIframeAriaText(editor)); 26929 if (getContentSecurityPolicy(editor)) { 26930 iframeHTML += '<meta http-equiv="Content-Security-Policy" content="' + getContentSecurityPolicy(editor) + '" />'; 26931 } 26932 iframeHTML += '</head>' + ('<body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '" data-id="' + editor.id + '" aria-label="' + translatedAriaText + '">') + '<br>' + '</body></html>'; 26933 return iframeHTML; 26934 }; 26935 var createIframe = function (editor, o) { 26936 var iframeTitle = editor.translate('Rich Text Area'); 26937 var ifr = createIframeElement(editor.id, iframeTitle, o.height, getIframeAttrs(editor)).dom; 26938 ifr.onload = function () { 26939 ifr.onload = null; 26940 editor.fire('load'); 26941 }; 26942 var isDomainRelaxed = relaxDomain(editor, ifr); 26943 editor.contentAreaContainer = o.iframeContainer; 26944 editor.iframeElement = ifr; 26945 editor.iframeHTML = getIframeHtml(editor); 26946 DOM$5.add(o.iframeContainer, ifr); 26947 return isDomainRelaxed; 26948 }; 26949 var init$1 = function (editor, boxInfo) { 26950 var isDomainRelaxed = createIframe(editor, boxInfo); 26951 if (boxInfo.editorContainer) { 26952 DOM$5.get(boxInfo.editorContainer).style.display = editor.orgDisplay; 26953 editor.hidden = DOM$5.isHidden(boxInfo.editorContainer); 26954 } 26955 editor.getElement().style.display = 'none'; 26956 DOM$5.setAttrib(editor.id, 'aria-hidden', 'true'); 26957 if (!isDomainRelaxed) { 26958 initContentBody(editor); 26959 } 26960 }; 26961 26962 var DOM$4 = DOMUtils.DOM; 26963 var initPlugin = function (editor, initializedPlugins, plugin) { 26964 var Plugin = PluginManager.get(plugin); 26965 var pluginUrl = PluginManager.urls[plugin] || editor.documentBaseUrl.replace(/\/$/, ''); 26966 plugin = Tools.trim(plugin); 26967 if (Plugin && Tools.inArray(initializedPlugins, plugin) === -1) { 26968 Tools.each(PluginManager.dependencies(plugin), function (dep) { 26969 initPlugin(editor, initializedPlugins, dep); 26970 }); 26971 if (editor.plugins[plugin]) { 26972 return; 26973 } 26974 try { 26975 var pluginInstance = new Plugin(editor, pluginUrl, editor.$); 26976 editor.plugins[plugin] = pluginInstance; 26977 if (pluginInstance.init) { 26978 pluginInstance.init(editor, pluginUrl); 26979 initializedPlugins.push(plugin); 26980 } 26981 } catch (e) { 26982 pluginInitError(editor, plugin, e); 26983 } 26984 } 26985 }; 26986 var trimLegacyPrefix = function (name) { 26987 return name.replace(/^\-/, ''); 26988 }; 26989 var initPlugins = function (editor) { 26990 var initializedPlugins = []; 26991 Tools.each(getPlugins(editor).split(/[ ,]/), function (name) { 26992 initPlugin(editor, initializedPlugins, trimLegacyPrefix(name)); 26993 }); 26994 }; 26995 var initIcons = function (editor) { 26996 var iconPackName = Tools.trim(getIconPackName(editor)); 26997 var currentIcons = editor.ui.registry.getAll().icons; 26998 var loadIcons = __assign(__assign({}, IconManager.get('default').icons), IconManager.get(iconPackName).icons); 26999 each$j(loadIcons, function (svgData, icon) { 27000 if (!has$2(currentIcons, icon)) { 27001 editor.ui.registry.addIcon(icon, svgData); 27002 } 27003 }); 27004 }; 27005 var initTheme = function (editor) { 27006 var theme = getTheme(editor); 27007 if (isString$1(theme)) { 27008 editor.settings.theme = trimLegacyPrefix(theme); 27009 var Theme = ThemeManager.get(theme); 27010 editor.theme = new Theme(editor, ThemeManager.urls[theme]); 27011 if (editor.theme.init) { 27012 editor.theme.init(editor, ThemeManager.urls[theme] || editor.documentBaseUrl.replace(/\/$/, ''), editor.$); 27013 } 27014 } else { 27015 editor.theme = {}; 27016 } 27017 }; 27018 var renderFromLoadedTheme = function (editor) { 27019 return editor.theme.renderUI(); 27020 }; 27021 var renderFromThemeFunc = function (editor) { 27022 var elm = editor.getElement(); 27023 var theme = getTheme(editor); 27024 var info = theme(editor, elm); 27025 if (info.editorContainer.nodeType) { 27026 info.editorContainer.id = info.editorContainer.id || editor.id + '_parent'; 27027 } 27028 if (info.iframeContainer && info.iframeContainer.nodeType) { 27029 info.iframeContainer.id = info.iframeContainer.id || editor.id + '_iframecontainer'; 27030 } 27031 info.height = info.iframeHeight ? info.iframeHeight : elm.offsetHeight; 27032 return info; 27033 }; 27034 var createThemeFalseResult = function (element) { 27035 return { 27036 editorContainer: element, 27037 iframeContainer: element, 27038 api: {} 27039 }; 27040 }; 27041 var renderThemeFalseIframe = function (targetElement) { 27042 var iframeContainer = DOM$4.create('div'); 27043 DOM$4.insertAfter(iframeContainer, targetElement); 27044 return createThemeFalseResult(iframeContainer); 27045 }; 27046 var renderThemeFalse = function (editor) { 27047 var targetElement = editor.getElement(); 27048 return editor.inline ? createThemeFalseResult(null) : renderThemeFalseIframe(targetElement); 27049 }; 27050 var renderThemeUi = function (editor) { 27051 var elm = editor.getElement(); 27052 editor.orgDisplay = elm.style.display; 27053 if (isString$1(getTheme(editor))) { 27054 return renderFromLoadedTheme(editor); 27055 } else if (isFunction(getTheme(editor))) { 27056 return renderFromThemeFunc(editor); 27057 } else { 27058 return renderThemeFalse(editor); 27059 } 27060 }; 27061 var augmentEditorUiApi = function (editor, api) { 27062 var uiApiFacade = { 27063 show: Optional.from(api.show).getOr(noop), 27064 hide: Optional.from(api.hide).getOr(noop), 27065 disable: Optional.from(api.disable).getOr(noop), 27066 isDisabled: Optional.from(api.isDisabled).getOr(never), 27067 enable: function () { 27068 if (!editor.mode.isReadOnly()) { 27069 Optional.from(api.enable).map(call); 27070 } 27071 } 27072 }; 27073 editor.ui = __assign(__assign({}, editor.ui), uiApiFacade); 27074 }; 27075 var init = function (editor) { 27076 editor.fire('ScriptsLoaded'); 27077 initIcons(editor); 27078 initTheme(editor); 27079 initPlugins(editor); 27080 var renderInfo = renderThemeUi(editor); 27081 augmentEditorUiApi(editor, Optional.from(renderInfo.api).getOr({})); 27082 var boxInfo = { 27083 editorContainer: renderInfo.editorContainer, 27084 iframeContainer: renderInfo.iframeContainer 27085 }; 27086 editor.editorContainer = boxInfo.editorContainer ? boxInfo.editorContainer : null; 27087 appendContentCssFromSettings(editor); 27088 if (editor.inline) { 27089 return initContentBody(editor); 27090 } else { 27091 return init$1(editor, boxInfo); 27092 } 27093 }; 27094 27095 var DOM$3 = DOMUtils.DOM; 27096 var hasSkipLoadPrefix = function (name) { 27097 return name.charAt(0) === '-'; 27098 }; 27099 var loadLanguage = function (scriptLoader, editor) { 27100 var languageCode = getLanguageCode(editor); 27101 var languageUrl = getLanguageUrl(editor); 27102 if (I18n.hasCode(languageCode) === false && languageCode !== 'en') { 27103 var url_1 = languageUrl !== '' ? languageUrl : editor.editorManager.baseURL + '/langs/' + languageCode + '.js'; 27104 scriptLoader.add(url_1, noop, undefined, function () { 27105 languageLoadError(editor, url_1, languageCode); 27106 }); 27107 } 27108 }; 27109 var loadTheme = function (scriptLoader, editor, suffix, callback) { 27110 var theme = getTheme(editor); 27111 if (isString$1(theme)) { 27112 if (!hasSkipLoadPrefix(theme) && !has$2(ThemeManager.urls, theme)) { 27113 var themeUrl = getThemeUrl(editor); 27114 if (themeUrl) { 27115 ThemeManager.load(theme, editor.documentBaseURI.toAbsolute(themeUrl)); 27116 } else { 27117 ThemeManager.load(theme, 'themes/' + theme + '/theme' + suffix + '.js'); 27118 } 27119 } 27120 scriptLoader.loadQueue(function () { 27121 ThemeManager.waitFor(theme, callback); 27122 }); 27123 } else { 27124 callback(); 27125 } 27126 }; 27127 var getIconsUrlMetaFromUrl = function (editor) { 27128 return Optional.from(getIconsUrl(editor)).filter(function (url) { 27129 return url.length > 0; 27130 }).map(function (url) { 27131 return { 27132 url: url, 27133 name: Optional.none() 27134 }; 27135 }); 27136 }; 27137 var getIconsUrlMetaFromName = function (editor, name, suffix) { 27138 return Optional.from(name).filter(function (name) { 27139 return name.length > 0 && !IconManager.has(name); 27140 }).map(function (name) { 27141 return { 27142 url: editor.editorManager.baseURL + '/icons/' + name + '/icons' + suffix + '.js', 27143 name: Optional.some(name) 27144 }; 27145 }); 27146 }; 27147 var loadIcons = function (scriptLoader, editor, suffix) { 27148 var defaultIconsUrl = getIconsUrlMetaFromName(editor, 'default', suffix); 27149 var customIconsUrl = getIconsUrlMetaFromUrl(editor).orThunk(function () { 27150 return getIconsUrlMetaFromName(editor, getIconPackName(editor), ''); 27151 }); 27152 each$k(cat([ 27153 defaultIconsUrl, 27154 customIconsUrl 27155 ]), function (urlMeta) { 27156 scriptLoader.add(urlMeta.url, noop, undefined, function () { 27157 iconsLoadError(editor, urlMeta.url, urlMeta.name.getOrUndefined()); 27158 }); 27159 }); 27160 }; 27161 var loadPlugins = function (editor, suffix) { 27162 Tools.each(getExternalPlugins$1(editor), function (url, name) { 27163 PluginManager.load(name, url, noop, undefined, function () { 27164 pluginLoadError(editor, url, name); 27165 }); 27166 editor.settings.plugins += ' ' + name; 27167 }); 27168 Tools.each(getPlugins(editor).split(/[ ,]/), function (plugin) { 27169 plugin = Tools.trim(plugin); 27170 if (plugin && !PluginManager.urls[plugin]) { 27171 if (hasSkipLoadPrefix(plugin)) { 27172 plugin = plugin.substr(1, plugin.length); 27173 var dependencies = PluginManager.dependencies(plugin); 27174 Tools.each(dependencies, function (depPlugin) { 27175 var defaultSettings = { 27176 prefix: 'plugins/', 27177 resource: depPlugin, 27178 suffix: '/plugin' + suffix + '.js' 27179 }; 27180 var dep = PluginManager.createUrl(defaultSettings, depPlugin); 27181 PluginManager.load(dep.resource, dep, noop, undefined, function () { 27182 pluginLoadError(editor, dep.prefix + dep.resource + dep.suffix, dep.resource); 27183 }); 27184 }); 27185 } else { 27186 var url_2 = { 27187 prefix: 'plugins/', 27188 resource: plugin, 27189 suffix: '/plugin' + suffix + '.js' 27190 }; 27191 PluginManager.load(plugin, url_2, noop, undefined, function () { 27192 pluginLoadError(editor, url_2.prefix + url_2.resource + url_2.suffix, plugin); 27193 }); 27194 } 27195 } 27196 }); 27197 }; 27198 var loadScripts = function (editor, suffix) { 27199 var scriptLoader = ScriptLoader.ScriptLoader; 27200 loadTheme(scriptLoader, editor, suffix, function () { 27201 loadLanguage(scriptLoader, editor); 27202 loadIcons(scriptLoader, editor, suffix); 27203 loadPlugins(editor, suffix); 27204 scriptLoader.loadQueue(function () { 27205 if (!editor.removed) { 27206 init(editor); 27207 } 27208 }, editor, function () { 27209 if (!editor.removed) { 27210 init(editor); 27211 } 27212 }); 27213 }); 27214 }; 27215 var getStyleSheetLoader = function (element, editor) { 27216 return instance.forElement(element, { 27217 contentCssCors: hasContentCssCors(editor), 27218 referrerPolicy: getReferrerPolicy(editor) 27219 }); 27220 }; 27221 var render = function (editor) { 27222 var id = editor.id; 27223 I18n.setCode(getLanguageCode(editor)); 27224 var readyHandler = function () { 27225 DOM$3.unbind(window, 'ready', readyHandler); 27226 editor.render(); 27227 }; 27228 if (!EventUtils.Event.domLoaded) { 27229 DOM$3.bind(window, 'ready', readyHandler); 27230 return; 27231 } 27232 if (!editor.getElement()) { 27233 return; 27234 } 27235 if (!Env.contentEditable) { 27236 return; 27237 } 27238 var element = SugarElement.fromDom(editor.getElement()); 27239 var snapshot = clone$3(element); 27240 editor.on('remove', function () { 27241 eachr(element.dom.attributes, function (attr) { 27242 return remove$6(element, attr.name); 27243 }); 27244 setAll$1(element, snapshot); 27245 }); 27246 editor.ui.styleSheetLoader = getStyleSheetLoader(element, editor); 27247 if (!isInline(editor)) { 27248 editor.orgVisibility = editor.getElement().style.visibility; 27249 editor.getElement().style.visibility = 'hidden'; 27250 } else { 27251 editor.inline = true; 27252 } 27253 var form = editor.getElement().form || DOM$3.getParent(id, 'form'); 27254 if (form) { 27255 editor.formElement = form; 27256 if (hasHiddenInput(editor) && !isTextareaOrInput(editor.getElement())) { 27257 DOM$3.insertAfter(DOM$3.create('input', { 27258 type: 'hidden', 27259 name: id 27260 }), id); 27261 editor.hasHiddenInput = true; 27262 } 27263 editor.formEventDelegate = function (e) { 27264 editor.fire(e.type, e); 27265 }; 27266 DOM$3.bind(form, 'submit reset', editor.formEventDelegate); 27267 editor.on('reset', function () { 27268 editor.resetContent(); 27269 }); 27270 if (shouldPatchSubmit(editor) && !form.submit.nodeType && !form.submit.length && !form._mceOldSubmit) { 27271 form._mceOldSubmit = form.submit; 27272 form.submit = function () { 27273 editor.editorManager.triggerSave(); 27274 editor.setDirty(false); 27275 return form._mceOldSubmit(form); 27276 }; 27277 } 27278 } 27279 editor.windowManager = WindowManager(editor); 27280 editor.notificationManager = NotificationManager(editor); 27281 if (isEncodingXml(editor)) { 27282 editor.on('GetContent', function (e) { 27283 if (e.save) { 27284 e.content = DOM$3.encode(e.content); 27285 } 27286 }); 27287 } 27288 if (shouldAddFormSubmitTrigger(editor)) { 27289 editor.on('submit', function () { 27290 if (editor.initialized) { 27291 editor.save(); 27292 } 27293 }); 27294 } 27295 if (shouldAddUnloadTrigger(editor)) { 27296 editor._beforeUnload = function () { 27297 if (editor.initialized && !editor.destroyed && !editor.isHidden()) { 27298 editor.save({ 27299 format: 'raw', 27300 no_events: true, 27301 set_dirty: false 27302 }); 27303 } 27304 }; 27305 editor.editorManager.on('BeforeUnload', editor._beforeUnload); 27306 } 27307 editor.editorManager.add(editor); 27308 loadScripts(editor, editor.suffix); 27309 }; 27310 27311 var addVisual = function (editor, elm) { 27312 return addVisual$1(editor, elm); 27313 }; 27314 27315 var legacyPropNames = { 27316 'font-size': 'size', 27317 'font-family': 'face' 27318 }; 27319 var getSpecifiedFontProp = function (propName, rootElm, elm) { 27320 var getProperty = function (elm) { 27321 return getRaw(elm, propName).orThunk(function () { 27322 if (name(elm) === 'font') { 27323 return get$9(legacyPropNames, propName).bind(function (legacyPropName) { 27324 return getOpt(elm, legacyPropName); 27325 }); 27326 } else { 27327 return Optional.none(); 27328 } 27329 }); 27330 }; 27331 var isRoot = function (elm) { 27332 return eq(SugarElement.fromDom(rootElm), elm); 27333 }; 27334 return closest$1(SugarElement.fromDom(elm), function (elm) { 27335 return getProperty(elm); 27336 }, isRoot); 27337 }; 27338 var normalizeFontFamily = function (fontFamily) { 27339 return fontFamily.replace(/[\'\"\\]/g, '').replace(/,\s+/g, ','); 27340 }; 27341 var getComputedFontProp = function (propName, elm) { 27342 return Optional.from(DOMUtils.DOM.getStyle(elm, propName, true)); 27343 }; 27344 var getFontProp = function (propName) { 27345 return function (rootElm, elm) { 27346 return Optional.from(elm).map(SugarElement.fromDom).filter(isElement$6).bind(function (element) { 27347 return getSpecifiedFontProp(propName, rootElm, element.dom).or(getComputedFontProp(propName, element.dom)); 27348 }).getOr(''); 27349 }; 27350 }; 27351 var getFontSize = getFontProp('font-size'); 27352 var getFontFamily = compose(normalizeFontFamily, getFontProp('font-family')); 27353 27354 var findFirstCaretElement = function (editor) { 27355 return firstPositionIn(editor.getBody()).map(function (caret) { 27356 var container = caret.container(); 27357 return isText$7(container) ? container.parentNode : container; 27358 }); 27359 }; 27360 var getCaretElement = function (editor) { 27361 return Optional.from(editor.selection.getRng()).bind(function (rng) { 27362 var root = editor.getBody(); 27363 var atStartOfNode = rng.startContainer === root && rng.startOffset === 0; 27364 return atStartOfNode ? Optional.none() : Optional.from(editor.selection.getStart(true)); 27365 }); 27366 }; 27367 var bindRange = function (editor, binder) { 27368 return getCaretElement(editor).orThunk(curry(findFirstCaretElement, editor)).map(SugarElement.fromDom).filter(isElement$6).bind(binder); 27369 }; 27370 var mapRange = function (editor, mapper) { 27371 return bindRange(editor, compose1(Optional.some, mapper)); 27372 }; 27373 27374 var fromFontSizeNumber = function (editor, value) { 27375 if (/^[0-9.]+$/.test(value)) { 27376 var fontSizeNumber = parseInt(value, 10); 27377 if (fontSizeNumber >= 1 && fontSizeNumber <= 7) { 27378 var fontSizes = getFontStyleValues(editor); 27379 var fontClasses = getFontSizeClasses(editor); 27380 if (fontClasses) { 27381 return fontClasses[fontSizeNumber - 1] || value; 27382 } else { 27383 return fontSizes[fontSizeNumber - 1] || value; 27384 } 27385 } else { 27386 return value; 27387 } 27388 } else { 27389 return value; 27390 } 27391 }; 27392 var normalizeFontNames = function (font) { 27393 var fonts = font.split(/\s*,\s*/); 27394 return map$3(fonts, function (font) { 27395 if (font.indexOf(' ') !== -1 && !(startsWith(font, '"') || startsWith(font, '\''))) { 27396 return '\'' + font + '\''; 27397 } else { 27398 return font; 27399 } 27400 }).join(','); 27401 }; 27402 var fontNameAction = function (editor, value) { 27403 var font = fromFontSizeNumber(editor, value); 27404 editor.formatter.toggle('fontname', { value: normalizeFontNames(font) }); 27405 editor.nodeChanged(); 27406 }; 27407 var fontNameQuery = function (editor) { 27408 return mapRange(editor, function (elm) { 27409 return getFontFamily(editor.getBody(), elm.dom); 27410 }).getOr(''); 27411 }; 27412 var fontSizeAction = function (editor, value) { 27413 editor.formatter.toggle('fontsize', { value: fromFontSizeNumber(editor, value) }); 27414 editor.nodeChanged(); 27415 }; 27416 var fontSizeQuery = function (editor) { 27417 return mapRange(editor, function (elm) { 27418 return getFontSize(editor.getBody(), elm.dom); 27419 }).getOr(''); 27420 }; 27421 27422 var lineHeightQuery = function (editor) { 27423 return mapRange(editor, function (elm) { 27424 var root = SugarElement.fromDom(editor.getBody()); 27425 var specifiedStyle = closest$1(elm, function (elm) { 27426 return getRaw(elm, 'line-height'); 27427 }, curry(eq, root)); 27428 var computedStyle = function () { 27429 var lineHeight = parseFloat(get$5(elm, 'line-height')); 27430 var fontSize = parseFloat(get$5(elm, 'font-size')); 27431 return String(lineHeight / fontSize); 27432 }; 27433 return specifiedStyle.getOrThunk(computedStyle); 27434 }).getOr(''); 27435 }; 27436 var lineHeightAction = function (editor, lineHeight) { 27437 editor.formatter.toggle('lineheight', { value: String(lineHeight) }); 27438 editor.nodeChanged(); 27439 }; 27440 27441 var processValue = function (value) { 27442 if (typeof value !== 'string') { 27443 var details = Tools.extend({ 27444 paste: value.paste, 27445 data: { paste: value.paste } 27446 }, value); 27447 return { 27448 content: value.content, 27449 details: details 27450 }; 27451 } 27452 return { 27453 content: value, 27454 details: {} 27455 }; 27456 }; 27457 var insertAtCaret = function (editor, value) { 27458 var result = processValue(value); 27459 insertContent(editor, result.content, result.details); 27460 }; 27461 27462 var each$4 = Tools.each; 27463 var map = Tools.map, inArray = Tools.inArray; 27464 var EditorCommands = function () { 27465 function EditorCommands(editor) { 27466 this.commands = { 27467 state: {}, 27468 exec: {}, 27469 value: {} 27470 }; 27471 this.editor = editor; 27472 this.setupCommands(editor); 27473 } 27474 EditorCommands.prototype.execCommand = function (command, ui, value, args) { 27475 var func, state = false; 27476 var self = this; 27477 if (self.editor.removed) { 27478 return; 27479 } 27480 if (command.toLowerCase() !== 'mcefocus') { 27481 if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(command) && (!args || !args.skip_focus)) { 27482 self.editor.focus(); 27483 } else { 27484 restore(self.editor); 27485 } 27486 } 27487 args = self.editor.fire('BeforeExecCommand', { 27488 command: command, 27489 ui: ui, 27490 value: value 27491 }); 27492 if (args.isDefaultPrevented()) { 27493 return false; 27494 } 27495 var customCommand = command.toLowerCase(); 27496 if (func = self.commands.exec[customCommand]) { 27497 func(customCommand, ui, value); 27498 self.editor.fire('ExecCommand', { 27499 command: command, 27500 ui: ui, 27501 value: value 27502 }); 27503 return true; 27504 } 27505 each$4(this.editor.plugins, function (p) { 27506 if (p.execCommand && p.execCommand(command, ui, value)) { 27507 self.editor.fire('ExecCommand', { 27508 command: command, 27509 ui: ui, 27510 value: value 27511 }); 27512 state = true; 27513 return false; 27514 } 27515 }); 27516 if (state) { 27517 return state; 27518 } 27519 if (self.editor.theme && self.editor.theme.execCommand && self.editor.theme.execCommand(command, ui, value)) { 27520 self.editor.fire('ExecCommand', { 27521 command: command, 27522 ui: ui, 27523 value: value 27524 }); 27525 return true; 27526 } 27527 try { 27528 state = self.editor.getDoc().execCommand(command, ui, value); 27529 } catch (ex) { 27530 } 27531 if (state) { 27532 self.editor.fire('ExecCommand', { 27533 command: command, 27534 ui: ui, 27535 value: value 27536 }); 27537 return true; 27538 } 27539 return false; 27540 }; 27541 EditorCommands.prototype.queryCommandState = function (command) { 27542 var func; 27543 if (this.editor.quirks.isHidden() || this.editor.removed) { 27544 return; 27545 } 27546 command = command.toLowerCase(); 27547 if (func = this.commands.state[command]) { 27548 return func(command); 27549 } 27550 try { 27551 return this.editor.getDoc().queryCommandState(command); 27552 } catch (ex) { 27553 } 27554 return false; 27555 }; 27556 EditorCommands.prototype.queryCommandValue = function (command) { 27557 var func; 27558 if (this.editor.quirks.isHidden() || this.editor.removed) { 27559 return; 27560 } 27561 command = command.toLowerCase(); 27562 if (func = this.commands.value[command]) { 27563 return func(command); 27564 } 27565 try { 27566 return this.editor.getDoc().queryCommandValue(command); 27567 } catch (ex) { 27568 } 27569 }; 27570 EditorCommands.prototype.addCommands = function (commandList, type) { 27571 if (type === void 0) { 27572 type = 'exec'; 27573 } 27574 var self = this; 27575 each$4(commandList, function (callback, command) { 27576 each$4(command.toLowerCase().split(','), function (command) { 27577 self.commands[type][command] = callback; 27578 }); 27579 }); 27580 }; 27581 EditorCommands.prototype.addCommand = function (command, callback, scope) { 27582 var _this = this; 27583 command = command.toLowerCase(); 27584 this.commands.exec[command] = function (command, ui, value, args) { 27585 return callback.call(scope || _this.editor, ui, value, args); 27586 }; 27587 }; 27588 EditorCommands.prototype.queryCommandSupported = function (command) { 27589 command = command.toLowerCase(); 27590 if (this.commands.exec[command]) { 27591 return true; 27592 } 27593 try { 27594 return this.editor.getDoc().queryCommandSupported(command); 27595 } catch (ex) { 27596 } 27597 return false; 27598 }; 27599 EditorCommands.prototype.addQueryStateHandler = function (command, callback, scope) { 27600 var _this = this; 27601 command = command.toLowerCase(); 27602 this.commands.state[command] = function () { 27603 return callback.call(scope || _this.editor); 27604 }; 27605 }; 27606 EditorCommands.prototype.addQueryValueHandler = function (command, callback, scope) { 27607 var _this = this; 27608 command = command.toLowerCase(); 27609 this.commands.value[command] = function () { 27610 return callback.call(scope || _this.editor); 27611 }; 27612 }; 27613 EditorCommands.prototype.hasCustomCommand = function (command) { 27614 command = command.toLowerCase(); 27615 return !!this.commands.exec[command]; 27616 }; 27617 EditorCommands.prototype.execNativeCommand = function (command, ui, value) { 27618 if (ui === undefined) { 27619 ui = false; 27620 } 27621 if (value === undefined) { 27622 value = null; 27623 } 27624 return this.editor.getDoc().execCommand(command, ui, value); 27625 }; 27626 EditorCommands.prototype.isFormatMatch = function (name) { 27627 return this.editor.formatter.match(name); 27628 }; 27629 EditorCommands.prototype.toggleFormat = function (name, value) { 27630 this.editor.formatter.toggle(name, value); 27631 this.editor.nodeChanged(); 27632 }; 27633 EditorCommands.prototype.storeSelection = function (type) { 27634 this.selectionBookmark = this.editor.selection.getBookmark(type); 27635 }; 27636 EditorCommands.prototype.restoreSelection = function () { 27637 this.editor.selection.moveToBookmark(this.selectionBookmark); 27638 }; 27639 EditorCommands.prototype.setupCommands = function (editor) { 27640 var self = this; 27641 this.addCommands({ 27642 'mceResetDesignMode,mceBeginUndoLevel': noop, 27643 'mceEndUndoLevel,mceAddUndoLevel': function () { 27644 editor.undoManager.add(); 27645 }, 27646 'mceFocus': function (_command, _ui, value) { 27647 focus(editor, value); 27648 }, 27649 'Cut,Copy,Paste': function (command) { 27650 var doc = editor.getDoc(); 27651 var failed; 27652 try { 27653 self.execNativeCommand(command); 27654 } catch (ex) { 27655 failed = true; 27656 } 27657 if (command === 'paste' && !doc.queryCommandEnabled(command)) { 27658 failed = true; 27659 } 27660 if (failed || !doc.queryCommandSupported(command)) { 27661 var msg = editor.translate('Your browser doesn\'t support direct access to the clipboard. ' + 'Please use the Ctrl+X/C/V keyboard shortcuts instead.'); 27662 if (Env.mac) { 27663 msg = msg.replace(/Ctrl\+/g, '\u2318+'); 27664 } 27665 editor.notificationManager.open({ 27666 text: msg, 27667 type: 'error' 27668 }); 27669 } 27670 }, 27671 'unlink': function () { 27672 if (editor.selection.isCollapsed()) { 27673 var elm = editor.dom.getParent(editor.selection.getStart(), 'a'); 27674 if (elm) { 27675 editor.dom.remove(elm, true); 27676 } 27677 return; 27678 } 27679 editor.formatter.remove('link'); 27680 }, 27681 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone': function (command) { 27682 var align = command.substring(7); 27683 if (align === 'full') { 27684 align = 'justify'; 27685 } 27686 each$4('left,center,right,justify'.split(','), function (name) { 27687 if (align !== name) { 27688 editor.formatter.remove('align' + name); 27689 } 27690 }); 27691 if (align !== 'none') { 27692 self.toggleFormat('align' + align); 27693 } 27694 }, 27695 'InsertUnorderedList,InsertOrderedList': function (command) { 27696 var listParent; 27697 self.execNativeCommand(command); 27698 var listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul'); 27699 if (listElm) { 27700 listParent = listElm.parentNode; 27701 if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) { 27702 self.storeSelection(); 27703 editor.dom.split(listParent, listElm); 27704 self.restoreSelection(); 27705 } 27706 } 27707 }, 27708 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (command) { 27709 self.toggleFormat(command); 27710 }, 27711 'ForeColor,HiliteColor': function (command, ui, value) { 27712 self.toggleFormat(command, { value: value }); 27713 }, 27714 'FontName': function (command, ui, value) { 27715 fontNameAction(editor, value); 27716 }, 27717 'FontSize': function (command, ui, value) { 27718 fontSizeAction(editor, value); 27719 }, 27720 'LineHeight': function (command, ui, value) { 27721 lineHeightAction(editor, value); 27722 }, 27723 'Lang': function (command, ui, lang) { 27724 self.toggleFormat(command, { 27725 value: lang.code, 27726 customValue: lang.customCode 27727 }); 27728 }, 27729 'RemoveFormat': function (command) { 27730 editor.formatter.remove(command); 27731 }, 27732 'mceBlockQuote': function () { 27733 self.toggleFormat('blockquote'); 27734 }, 27735 'FormatBlock': function (command, ui, value) { 27736 return self.toggleFormat(value || 'p'); 27737 }, 27738 'mceCleanup': function () { 27739 var bookmark = editor.selection.getBookmark(); 27740 editor.setContent(editor.getContent()); 27741 editor.selection.moveToBookmark(bookmark); 27742 }, 27743 'mceRemoveNode': function (command, ui, value) { 27744 var node = value || editor.selection.getNode(); 27745 if (node !== editor.getBody()) { 27746 self.storeSelection(); 27747 editor.dom.remove(node, true); 27748 self.restoreSelection(); 27749 } 27750 }, 27751 'mceSelectNodeDepth': function (command, ui, value) { 27752 var counter = 0; 27753 editor.dom.getParent(editor.selection.getNode(), function (node) { 27754 if (node.nodeType === 1 && counter++ === value) { 27755 editor.selection.select(node); 27756 return false; 27757 } 27758 }, editor.getBody()); 27759 }, 27760 'mceSelectNode': function (command, ui, value) { 27761 editor.selection.select(value); 27762 }, 27763 'mceInsertContent': function (command, ui, value) { 27764 insertAtCaret(editor, value); 27765 }, 27766 'mceInsertRawHTML': function (command, ui, value) { 27767 editor.selection.setContent('tiny_mce_marker'); 27768 var content = editor.getContent(); 27769 editor.setContent(content.replace(/tiny_mce_marker/g, function () { 27770 return value; 27771 })); 27772 }, 27773 'mceInsertNewLine': function (command, ui, value) { 27774 insert(editor, value); 27775 }, 27776 'mceToggleFormat': function (command, ui, value) { 27777 self.toggleFormat(value); 27778 }, 27779 'mceSetContent': function (command, ui, value) { 27780 editor.setContent(value); 27781 }, 27782 'Indent,Outdent': function (command) { 27783 handle(editor, command); 27784 }, 27785 'mceRepaint': noop, 27786 'InsertHorizontalRule': function () { 27787 editor.execCommand('mceInsertContent', false, '<hr />'); 27788 }, 27789 'mceToggleVisualAid': function () { 27790 editor.hasVisual = !editor.hasVisual; 27791 editor.addVisual(); 27792 }, 27793 'mceReplaceContent': function (command, ui, value) { 27794 editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, editor.selection.getContent({ format: 'text' }))); 27795 }, 27796 'mceInsertLink': function (command, ui, value) { 27797 if (typeof value === 'string') { 27798 value = { href: value }; 27799 } 27800 var anchor = editor.dom.getParent(editor.selection.getNode(), 'a'); 27801 value.href = value.href.replace(/ /g, '%20'); 27802 if (!anchor || !value.href) { 27803 editor.formatter.remove('link'); 27804 } 27805 if (value.href) { 27806 editor.formatter.apply('link', value, anchor); 27807 } 27808 }, 27809 'selectAll': function () { 27810 var editingHost = editor.dom.getParent(editor.selection.getStart(), isContentEditableTrue$4); 27811 if (editingHost) { 27812 var rng = editor.dom.createRng(); 27813 rng.selectNodeContents(editingHost); 27814 editor.selection.setRng(rng); 27815 } 27816 }, 27817 'mceNewDocument': function () { 27818 editor.setContent(''); 27819 }, 27820 'InsertLineBreak': function (command, ui, value) { 27821 insert$1(editor, value); 27822 return true; 27823 } 27824 }); 27825 var alignStates = function (name) { 27826 return function () { 27827 var selection = editor.selection; 27828 var nodes = selection.isCollapsed() ? [editor.dom.getParent(selection.getNode(), editor.dom.isBlock)] : selection.getSelectedBlocks(); 27829 var matches = map(nodes, function (node) { 27830 return !!editor.formatter.matchNode(node, name); 27831 }); 27832 return inArray(matches, true) !== -1; 27833 }; 27834 }; 27835 self.addCommands({ 27836 'JustifyLeft': alignStates('alignleft'), 27837 'JustifyCenter': alignStates('aligncenter'), 27838 'JustifyRight': alignStates('alignright'), 27839 'JustifyFull': alignStates('alignjustify'), 27840 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (command) { 27841 return self.isFormatMatch(command); 27842 }, 27843 'mceBlockQuote': function () { 27844 return self.isFormatMatch('blockquote'); 27845 }, 27846 'Outdent': function () { 27847 return canOutdent(editor); 27848 }, 27849 'InsertUnorderedList,InsertOrderedList': function (command) { 27850 var list = editor.dom.getParent(editor.selection.getNode(), 'ul,ol'); 27851 return list && (command === 'insertunorderedlist' && list.tagName === 'UL' || command === 'insertorderedlist' && list.tagName === 'OL'); 27852 } 27853 }, 'state'); 27854 self.addCommands({ 27855 Undo: function () { 27856 editor.undoManager.undo(); 27857 }, 27858 Redo: function () { 27859 editor.undoManager.redo(); 27860 } 27861 }); 27862 self.addQueryValueHandler('FontName', function () { 27863 return fontNameQuery(editor); 27864 }, this); 27865 self.addQueryValueHandler('FontSize', function () { 27866 return fontSizeQuery(editor); 27867 }, this); 27868 self.addQueryValueHandler('LineHeight', function () { 27869 return lineHeightQuery(editor); 27870 }, this); 27871 }; 27872 return EditorCommands; 27873 }(); 27874 27875 var internalContentEditableAttr = 'data-mce-contenteditable'; 27876 var toggleClass = function (elm, cls, state) { 27877 if (has(elm, cls) && state === false) { 27878 remove$3(elm, cls); 27879 } else if (state) { 27880 add$1(elm, cls); 27881 } 27882 }; 27883 var setEditorCommandState = function (editor, cmd, state) { 27884 try { 27885 editor.getDoc().execCommand(cmd, false, String(state)); 27886 } catch (ex) { 27887 } 27888 }; 27889 var setContentEditable = function (elm, state) { 27890 elm.dom.contentEditable = state ? 'true' : 'false'; 27891 }; 27892 var switchOffContentEditableTrue = function (elm) { 27893 each$k(descendants(elm, '*[contenteditable="true"]'), function (elm) { 27894 set$1(elm, internalContentEditableAttr, 'true'); 27895 setContentEditable(elm, false); 27896 }); 27897 }; 27898 var switchOnContentEditableTrue = function (elm) { 27899 each$k(descendants(elm, '*[' + internalContentEditableAttr + '="true"]'), function (elm) { 27900 remove$6(elm, internalContentEditableAttr); 27901 setContentEditable(elm, true); 27902 }); 27903 }; 27904 var removeFakeSelection = function (editor) { 27905 Optional.from(editor.selection.getNode()).each(function (elm) { 27906 elm.removeAttribute('data-mce-selected'); 27907 }); 27908 }; 27909 var restoreFakeSelection = function (editor) { 27910 editor.selection.setRng(editor.selection.getRng()); 27911 }; 27912 var toggleReadOnly = function (editor, state) { 27913 var body = SugarElement.fromDom(editor.getBody()); 27914 toggleClass(body, 'mce-content-readonly', state); 27915 if (state) { 27916 editor.selection.controlSelection.hideResizeRect(); 27917 editor._selectionOverrides.hideFakeCaret(); 27918 removeFakeSelection(editor); 27919 editor.readonly = true; 27920 setContentEditable(body, false); 27921 switchOffContentEditableTrue(body); 27922 } else { 27923 editor.readonly = false; 27924 setContentEditable(body, true); 27925 switchOnContentEditableTrue(body); 27926 setEditorCommandState(editor, 'StyleWithCSS', false); 27927 setEditorCommandState(editor, 'enableInlineTableEditing', false); 27928 setEditorCommandState(editor, 'enableObjectResizing', false); 27929 if (hasEditorOrUiFocus(editor)) { 27930 editor.focus(); 27931 } 27932 restoreFakeSelection(editor); 27933 editor.nodeChanged(); 27934 } 27935 }; 27936 var isReadOnly = function (editor) { 27937 return editor.readonly; 27938 }; 27939 var registerFilters = function (editor) { 27940 editor.parser.addAttributeFilter('contenteditable', function (nodes) { 27941 if (isReadOnly(editor)) { 27942 each$k(nodes, function (node) { 27943 node.attr(internalContentEditableAttr, node.attr('contenteditable')); 27944 node.attr('contenteditable', 'false'); 27945 }); 27946 } 27947 }); 27948 editor.serializer.addAttributeFilter(internalContentEditableAttr, function (nodes) { 27949 if (isReadOnly(editor)) { 27950 each$k(nodes, function (node) { 27951 node.attr('contenteditable', node.attr(internalContentEditableAttr)); 27952 }); 27953 } 27954 }); 27955 editor.serializer.addTempAttr(internalContentEditableAttr); 27956 }; 27957 var registerReadOnlyContentFilters = function (editor) { 27958 if (editor.serializer) { 27959 registerFilters(editor); 27960 } else { 27961 editor.on('PreInit', function () { 27962 registerFilters(editor); 27963 }); 27964 } 27965 }; 27966 var isClickEvent = function (e) { 27967 return e.type === 'click'; 27968 }; 27969 var getAnchorHrefOpt = function (editor, elm) { 27970 var isRoot = function (elm) { 27971 return eq(elm, SugarElement.fromDom(editor.getBody())); 27972 }; 27973 return closest$2(elm, 'a', isRoot).bind(function (a) { 27974 return getOpt(a, 'href'); 27975 }); 27976 }; 27977 var processReadonlyEvents = function (editor, e) { 27978 if (isClickEvent(e) && !VK.metaKeyPressed(e)) { 27979 var elm = SugarElement.fromDom(e.target); 27980 getAnchorHrefOpt(editor, elm).each(function (href) { 27981 e.preventDefault(); 27982 if (/^#/.test(href)) { 27983 var targetEl = editor.dom.select(href + ',[name="' + removeLeading(href, '#') + '"]'); 27984 if (targetEl.length) { 27985 editor.selection.scrollIntoView(targetEl[0], true); 27986 } 27987 } else { 27988 window.open(href, '_blank', 'rel=noopener noreferrer,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes,scrollbars=yes'); 27989 } 27990 }); 27991 } 27992 }; 27993 var registerReadOnlySelectionBlockers = function (editor) { 27994 editor.on('ShowCaret', function (e) { 27995 if (isReadOnly(editor)) { 27996 e.preventDefault(); 27997 } 27998 }); 27999 editor.on('ObjectSelected', function (e) { 28000 if (isReadOnly(editor)) { 28001 e.preventDefault(); 28002 } 28003 }); 28004 }; 28005 28006 var nativeEvents = Tools.makeMap('focus blur focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange ' + 'mouseout mouseenter mouseleave wheel keydown keypress keyup input beforeinput contextmenu dragstart dragend dragover ' + 'draggesture dragdrop drop drag submit ' + 'compositionstart compositionend compositionupdate touchstart touchmove touchend touchcancel', ' '); 28007 var EventDispatcher = function () { 28008 function EventDispatcher(settings) { 28009 this.bindings = {}; 28010 this.settings = settings || {}; 28011 this.scope = this.settings.scope || this; 28012 this.toggleEvent = this.settings.toggleEvent || never; 28013 } 28014 EventDispatcher.isNative = function (name) { 28015 return !!nativeEvents[name.toLowerCase()]; 28016 }; 28017 EventDispatcher.prototype.fire = function (name, args) { 28018 var lcName = name.toLowerCase(); 28019 var event = normalize$3(lcName, args || {}, this.scope); 28020 if (this.settings.beforeFire) { 28021 this.settings.beforeFire(event); 28022 } 28023 var handlers = this.bindings[lcName]; 28024 if (handlers) { 28025 for (var i = 0, l = handlers.length; i < l; i++) { 28026 var callback = handlers[i]; 28027 if (callback.removed) { 28028 continue; 28029 } 28030 if (callback.once) { 28031 this.off(lcName, callback.func); 28032 } 28033 if (event.isImmediatePropagationStopped()) { 28034 return event; 28035 } 28036 if (callback.func.call(this.scope, event) === false) { 28037 event.preventDefault(); 28038 return event; 28039 } 28040 } 28041 } 28042 return event; 28043 }; 28044 EventDispatcher.prototype.on = function (name, callback, prepend, extra) { 28045 if (callback === false) { 28046 callback = never; 28047 } 28048 if (callback) { 28049 var wrappedCallback = { 28050 func: callback, 28051 removed: false 28052 }; 28053 if (extra) { 28054 Tools.extend(wrappedCallback, extra); 28055 } 28056 var names = name.toLowerCase().split(' '); 28057 var i = names.length; 28058 while (i--) { 28059 var currentName = names[i]; 28060 var handlers = this.bindings[currentName]; 28061 if (!handlers) { 28062 handlers = []; 28063 this.toggleEvent(currentName, true); 28064 } 28065 if (prepend) { 28066 handlers = __spreadArray([wrappedCallback], handlers, true); 28067 } else { 28068 handlers = __spreadArray(__spreadArray([], handlers, true), [wrappedCallback], false); 28069 } 28070 this.bindings[currentName] = handlers; 28071 } 28072 } 28073 return this; 28074 }; 28075 EventDispatcher.prototype.off = function (name, callback) { 28076 var _this = this; 28077 if (name) { 28078 var names = name.toLowerCase().split(' '); 28079 var i = names.length; 28080 while (i--) { 28081 var currentName = names[i]; 28082 var handlers = this.bindings[currentName]; 28083 if (!currentName) { 28084 each$j(this.bindings, function (_value, bindingName) { 28085 _this.toggleEvent(bindingName, false); 28086 delete _this.bindings[bindingName]; 28087 }); 28088 return this; 28089 } 28090 if (handlers) { 28091 if (!callback) { 28092 handlers.length = 0; 28093 } else { 28094 var filteredHandlers = partition(handlers, function (handler) { 28095 return handler.func === callback; 28096 }); 28097 handlers = filteredHandlers.fail; 28098 this.bindings[currentName] = handlers; 28099 each$k(filteredHandlers.pass, function (handler) { 28100 handler.removed = true; 28101 }); 28102 } 28103 if (!handlers.length) { 28104 this.toggleEvent(name, false); 28105 delete this.bindings[currentName]; 28106 } 28107 } 28108 } 28109 } else { 28110 each$j(this.bindings, function (_value, name) { 28111 _this.toggleEvent(name, false); 28112 }); 28113 this.bindings = {}; 28114 } 28115 return this; 28116 }; 28117 EventDispatcher.prototype.once = function (name, callback, prepend) { 28118 return this.on(name, callback, prepend, { once: true }); 28119 }; 28120 EventDispatcher.prototype.has = function (name) { 28121 name = name.toLowerCase(); 28122 return !(!this.bindings[name] || this.bindings[name].length === 0); 28123 }; 28124 return EventDispatcher; 28125 }(); 28126 28127 var getEventDispatcher = function (obj) { 28128 if (!obj._eventDispatcher) { 28129 obj._eventDispatcher = new EventDispatcher({ 28130 scope: obj, 28131 toggleEvent: function (name, state) { 28132 if (EventDispatcher.isNative(name) && obj.toggleNativeEvent) { 28133 obj.toggleNativeEvent(name, state); 28134 } 28135 } 28136 }); 28137 } 28138 return obj._eventDispatcher; 28139 }; 28140 var Observable = { 28141 fire: function (name, args, bubble) { 28142 var self = this; 28143 if (self.removed && name !== 'remove' && name !== 'detach') { 28144 return args; 28145 } 28146 var dispatcherArgs = getEventDispatcher(self).fire(name, args); 28147 if (bubble !== false && self.parent) { 28148 var parent_1 = self.parent(); 28149 while (parent_1 && !dispatcherArgs.isPropagationStopped()) { 28150 parent_1.fire(name, dispatcherArgs, false); 28151 parent_1 = parent_1.parent(); 28152 } 28153 } 28154 return dispatcherArgs; 28155 }, 28156 on: function (name, callback, prepend) { 28157 return getEventDispatcher(this).on(name, callback, prepend); 28158 }, 28159 off: function (name, callback) { 28160 return getEventDispatcher(this).off(name, callback); 28161 }, 28162 once: function (name, callback) { 28163 return getEventDispatcher(this).once(name, callback); 28164 }, 28165 hasEventListeners: function (name) { 28166 return getEventDispatcher(this).has(name); 28167 } 28168 }; 28169 28170 var DOM$2 = DOMUtils.DOM; 28171 var customEventRootDelegates; 28172 var getEventTarget = function (editor, eventName) { 28173 if (eventName === 'selectionchange') { 28174 return editor.getDoc(); 28175 } 28176 if (!editor.inline && /^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(eventName)) { 28177 return editor.getDoc().documentElement; 28178 } 28179 var eventRoot = getEventRoot(editor); 28180 if (eventRoot) { 28181 if (!editor.eventRoot) { 28182 editor.eventRoot = DOM$2.select(eventRoot)[0]; 28183 } 28184 return editor.eventRoot; 28185 } 28186 return editor.getBody(); 28187 }; 28188 var isListening = function (editor) { 28189 return !editor.hidden && !isReadOnly(editor); 28190 }; 28191 var fireEvent = function (editor, eventName, e) { 28192 if (isListening(editor)) { 28193 editor.fire(eventName, e); 28194 } else if (isReadOnly(editor)) { 28195 processReadonlyEvents(editor, e); 28196 } 28197 }; 28198 var bindEventDelegate = function (editor, eventName) { 28199 var delegate; 28200 if (!editor.delegates) { 28201 editor.delegates = {}; 28202 } 28203 if (editor.delegates[eventName] || editor.removed) { 28204 return; 28205 } 28206 var eventRootElm = getEventTarget(editor, eventName); 28207 if (getEventRoot(editor)) { 28208 if (!customEventRootDelegates) { 28209 customEventRootDelegates = {}; 28210 editor.editorManager.on('removeEditor', function () { 28211 if (!editor.editorManager.activeEditor) { 28212 if (customEventRootDelegates) { 28213 each$j(customEventRootDelegates, function (_value, name) { 28214 editor.dom.unbind(getEventTarget(editor, name)); 28215 }); 28216 customEventRootDelegates = null; 28217 } 28218 } 28219 }); 28220 } 28221 if (customEventRootDelegates[eventName]) { 28222 return; 28223 } 28224 delegate = function (e) { 28225 var target = e.target; 28226 var editors = editor.editorManager.get(); 28227 var i = editors.length; 28228 while (i--) { 28229 var body = editors[i].getBody(); 28230 if (body === target || DOM$2.isChildOf(target, body)) { 28231 fireEvent(editors[i], eventName, e); 28232 } 28233 } 28234 }; 28235 customEventRootDelegates[eventName] = delegate; 28236 DOM$2.bind(eventRootElm, eventName, delegate); 28237 } else { 28238 delegate = function (e) { 28239 fireEvent(editor, eventName, e); 28240 }; 28241 DOM$2.bind(eventRootElm, eventName, delegate); 28242 editor.delegates[eventName] = delegate; 28243 } 28244 }; 28245 var EditorObservable = __assign(__assign({}, Observable), { 28246 bindPendingEventDelegates: function () { 28247 var self = this; 28248 Tools.each(self._pendingNativeEvents, function (name) { 28249 bindEventDelegate(self, name); 28250 }); 28251 }, 28252 toggleNativeEvent: function (name, state) { 28253 var self = this; 28254 if (name === 'focus' || name === 'blur') { 28255 return; 28256 } 28257 if (self.removed) { 28258 return; 28259 } 28260 if (state) { 28261 if (self.initialized) { 28262 bindEventDelegate(self, name); 28263 } else { 28264 if (!self._pendingNativeEvents) { 28265 self._pendingNativeEvents = [name]; 28266 } else { 28267 self._pendingNativeEvents.push(name); 28268 } 28269 } 28270 } else if (self.initialized) { 28271 self.dom.unbind(getEventTarget(self, name), name, self.delegates[name]); 28272 delete self.delegates[name]; 28273 } 28274 }, 28275 unbindAllNativeEvents: function () { 28276 var self = this; 28277 var body = self.getBody(); 28278 var dom = self.dom; 28279 if (self.delegates) { 28280 each$j(self.delegates, function (value, name) { 28281 self.dom.unbind(getEventTarget(self, name), name, value); 28282 }); 28283 delete self.delegates; 28284 } 28285 if (!self.inline && body && dom) { 28286 body.onload = null; 28287 dom.unbind(self.getWin()); 28288 dom.unbind(self.getDoc()); 28289 } 28290 if (dom) { 28291 dom.unbind(body); 28292 dom.unbind(self.getContainer()); 28293 } 28294 } 28295 }); 28296 28297 var defaultModes = [ 28298 'design', 28299 'readonly' 28300 ]; 28301 var switchToMode = function (editor, activeMode, availableModes, mode) { 28302 var oldMode = availableModes[activeMode.get()]; 28303 var newMode = availableModes[mode]; 28304 try { 28305 newMode.activate(); 28306 } catch (e) { 28307 console.error('problem while activating editor mode ' + mode + ':', e); 28308 return; 28309 } 28310 oldMode.deactivate(); 28311 if (oldMode.editorReadOnly !== newMode.editorReadOnly) { 28312 toggleReadOnly(editor, newMode.editorReadOnly); 28313 } 28314 activeMode.set(mode); 28315 fireSwitchMode(editor, mode); 28316 }; 28317 var setMode = function (editor, availableModes, activeMode, mode) { 28318 if (mode === activeMode.get()) { 28319 return; 28320 } else if (!has$2(availableModes, mode)) { 28321 throw new Error('Editor mode \'' + mode + '\' is invalid'); 28322 } 28323 if (editor.initialized) { 28324 switchToMode(editor, activeMode, availableModes, mode); 28325 } else { 28326 editor.on('init', function () { 28327 return switchToMode(editor, activeMode, availableModes, mode); 28328 }); 28329 } 28330 }; 28331 var registerMode = function (availableModes, mode, api) { 28332 var _a; 28333 if (contains$3(defaultModes, mode)) { 28334 throw new Error('Cannot override default mode ' + mode); 28335 } 28336 return __assign(__assign({}, availableModes), (_a = {}, _a[mode] = __assign(__assign({}, api), { 28337 deactivate: function () { 28338 try { 28339 api.deactivate(); 28340 } catch (e) { 28341 console.error('problem while deactivating editor mode ' + mode + ':', e); 28342 } 28343 } 28344 }), _a)); 28345 }; 28346 28347 var create$4 = function (editor) { 28348 var activeMode = Cell('design'); 28349 var availableModes = Cell({ 28350 design: { 28351 activate: noop, 28352 deactivate: noop, 28353 editorReadOnly: false 28354 }, 28355 readonly: { 28356 activate: noop, 28357 deactivate: noop, 28358 editorReadOnly: true 28359 } 28360 }); 28361 registerReadOnlyContentFilters(editor); 28362 registerReadOnlySelectionBlockers(editor); 28363 return { 28364 isReadOnly: function () { 28365 return isReadOnly(editor); 28366 }, 28367 set: function (mode) { 28368 return setMode(editor, availableModes.get(), activeMode, mode); 28369 }, 28370 get: function () { 28371 return activeMode.get(); 28372 }, 28373 register: function (mode, api) { 28374 availableModes.set(registerMode(availableModes.get(), mode, api)); 28375 } 28376 }; 28377 }; 28378 28379 var each$3 = Tools.each, explode$1 = Tools.explode; 28380 var keyCodeLookup = { 28381 f1: 112, 28382 f2: 113, 28383 f3: 114, 28384 f4: 115, 28385 f5: 116, 28386 f6: 117, 28387 f7: 118, 28388 f8: 119, 28389 f9: 120, 28390 f10: 121, 28391 f11: 122, 28392 f12: 123 28393 }; 28394 var modifierNames = Tools.makeMap('alt,ctrl,shift,meta,access'); 28395 var parseShortcut = function (pattern) { 28396 var key; 28397 var shortcut = {}; 28398 each$3(explode$1(pattern.toLowerCase(), '+'), function (value) { 28399 if (value in modifierNames) { 28400 shortcut[value] = true; 28401 } else { 28402 if (/^[0-9]{2,}$/.test(value)) { 28403 shortcut.keyCode = parseInt(value, 10); 28404 } else { 28405 shortcut.charCode = value.charCodeAt(0); 28406 shortcut.keyCode = keyCodeLookup[value] || value.toUpperCase().charCodeAt(0); 28407 } 28408 } 28409 }); 28410 var id = [shortcut.keyCode]; 28411 for (key in modifierNames) { 28412 if (shortcut[key]) { 28413 id.push(key); 28414 } else { 28415 shortcut[key] = false; 28416 } 28417 } 28418 shortcut.id = id.join(','); 28419 if (shortcut.access) { 28420 shortcut.alt = true; 28421 if (Env.mac) { 28422 shortcut.ctrl = true; 28423 } else { 28424 shortcut.shift = true; 28425 } 28426 } 28427 if (shortcut.meta) { 28428 if (Env.mac) { 28429 shortcut.meta = true; 28430 } else { 28431 shortcut.ctrl = true; 28432 shortcut.meta = false; 28433 } 28434 } 28435 return shortcut; 28436 }; 28437 var Shortcuts = function () { 28438 function Shortcuts(editor) { 28439 this.shortcuts = {}; 28440 this.pendingPatterns = []; 28441 this.editor = editor; 28442 var self = this; 28443 editor.on('keyup keypress keydown', function (e) { 28444 if ((self.hasModifier(e) || self.isFunctionKey(e)) && !e.isDefaultPrevented()) { 28445 each$3(self.shortcuts, function (shortcut) { 28446 if (self.matchShortcut(e, shortcut)) { 28447 self.pendingPatterns = shortcut.subpatterns.slice(0); 28448 if (e.type === 'keydown') { 28449 self.executeShortcutAction(shortcut); 28450 } 28451 return true; 28452 } 28453 }); 28454 if (self.matchShortcut(e, self.pendingPatterns[0])) { 28455 if (self.pendingPatterns.length === 1) { 28456 if (e.type === 'keydown') { 28457 self.executeShortcutAction(self.pendingPatterns[0]); 28458 } 28459 } 28460 self.pendingPatterns.shift(); 28461 } 28462 } 28463 }); 28464 } 28465 Shortcuts.prototype.add = function (pattern, desc, cmdFunc, scope) { 28466 var self = this; 28467 var func = self.normalizeCommandFunc(cmdFunc); 28468 each$3(explode$1(Tools.trim(pattern)), function (pattern) { 28469 var shortcut = self.createShortcut(pattern, desc, func, scope); 28470 self.shortcuts[shortcut.id] = shortcut; 28471 }); 28472 return true; 28473 }; 28474 Shortcuts.prototype.remove = function (pattern) { 28475 var shortcut = this.createShortcut(pattern); 28476 if (this.shortcuts[shortcut.id]) { 28477 delete this.shortcuts[shortcut.id]; 28478 return true; 28479 } 28480 return false; 28481 }; 28482 Shortcuts.prototype.normalizeCommandFunc = function (cmdFunc) { 28483 var self = this; 28484 var cmd = cmdFunc; 28485 if (typeof cmd === 'string') { 28486 return function () { 28487 self.editor.execCommand(cmd, false, null); 28488 }; 28489 } else if (Tools.isArray(cmd)) { 28490 return function () { 28491 self.editor.execCommand(cmd[0], cmd[1], cmd[2]); 28492 }; 28493 } else { 28494 return cmd; 28495 } 28496 }; 28497 Shortcuts.prototype.createShortcut = function (pattern, desc, cmdFunc, scope) { 28498 var shortcuts = Tools.map(explode$1(pattern, '>'), parseShortcut); 28499 shortcuts[shortcuts.length - 1] = Tools.extend(shortcuts[shortcuts.length - 1], { 28500 func: cmdFunc, 28501 scope: scope || this.editor 28502 }); 28503 return Tools.extend(shortcuts[0], { 28504 desc: this.editor.translate(desc), 28505 subpatterns: shortcuts.slice(1) 28506 }); 28507 }; 28508 Shortcuts.prototype.hasModifier = function (e) { 28509 return e.altKey || e.ctrlKey || e.metaKey; 28510 }; 28511 Shortcuts.prototype.isFunctionKey = function (e) { 28512 return e.type === 'keydown' && e.keyCode >= 112 && e.keyCode <= 123; 28513 }; 28514 Shortcuts.prototype.matchShortcut = function (e, shortcut) { 28515 if (!shortcut) { 28516 return false; 28517 } 28518 if (shortcut.ctrl !== e.ctrlKey || shortcut.meta !== e.metaKey) { 28519 return false; 28520 } 28521 if (shortcut.alt !== e.altKey || shortcut.shift !== e.shiftKey) { 28522 return false; 28523 } 28524 if (e.keyCode === shortcut.keyCode || e.charCode && e.charCode === shortcut.charCode) { 28525 e.preventDefault(); 28526 return true; 28527 } 28528 return false; 28529 }; 28530 Shortcuts.prototype.executeShortcutAction = function (shortcut) { 28531 return shortcut.func ? shortcut.func.call(shortcut.scope) : null; 28532 }; 28533 return Shortcuts; 28534 }(); 28535 28536 var create$3 = function () { 28537 var buttons = {}; 28538 var menuItems = {}; 28539 var popups = {}; 28540 var icons = {}; 28541 var contextMenus = {}; 28542 var contextToolbars = {}; 28543 var sidebars = {}; 28544 var add = function (collection, type) { 28545 return function (name, spec) { 28546 return collection[name.toLowerCase()] = __assign(__assign({}, spec), { type: type }); 28547 }; 28548 }; 28549 var addIcon = function (name, svgData) { 28550 return icons[name.toLowerCase()] = svgData; 28551 }; 28552 return { 28553 addButton: add(buttons, 'button'), 28554 addGroupToolbarButton: add(buttons, 'grouptoolbarbutton'), 28555 addToggleButton: add(buttons, 'togglebutton'), 28556 addMenuButton: add(buttons, 'menubutton'), 28557 addSplitButton: add(buttons, 'splitbutton'), 28558 addMenuItem: add(menuItems, 'menuitem'), 28559 addNestedMenuItem: add(menuItems, 'nestedmenuitem'), 28560 addToggleMenuItem: add(menuItems, 'togglemenuitem'), 28561 addAutocompleter: add(popups, 'autocompleter'), 28562 addContextMenu: add(contextMenus, 'contextmenu'), 28563 addContextToolbar: add(contextToolbars, 'contexttoolbar'), 28564 addContextForm: add(contextToolbars, 'contextform'), 28565 addSidebar: add(sidebars, 'sidebar'), 28566 addIcon: addIcon, 28567 getAll: function () { 28568 return { 28569 buttons: buttons, 28570 menuItems: menuItems, 28571 icons: icons, 28572 popups: popups, 28573 contextMenus: contextMenus, 28574 contextToolbars: contextToolbars, 28575 sidebars: sidebars 28576 }; 28577 } 28578 }; 28579 }; 28580 28581 var registry = function () { 28582 var bridge = create$3(); 28583 return { 28584 addAutocompleter: bridge.addAutocompleter, 28585 addButton: bridge.addButton, 28586 addContextForm: bridge.addContextForm, 28587 addContextMenu: bridge.addContextMenu, 28588 addContextToolbar: bridge.addContextToolbar, 28589 addIcon: bridge.addIcon, 28590 addMenuButton: bridge.addMenuButton, 28591 addMenuItem: bridge.addMenuItem, 28592 addNestedMenuItem: bridge.addNestedMenuItem, 28593 addSidebar: bridge.addSidebar, 28594 addSplitButton: bridge.addSplitButton, 28595 addToggleButton: bridge.addToggleButton, 28596 addGroupToolbarButton: bridge.addGroupToolbarButton, 28597 addToggleMenuItem: bridge.addToggleMenuItem, 28598 getAll: bridge.getAll 28599 }; 28600 }; 28601 28602 var DOM$1 = DOMUtils.DOM; 28603 var extend$3 = Tools.extend, each$2 = Tools.each; 28604 var resolve = Tools.resolve; 28605 var ie = Env.ie; 28606 var Editor = function () { 28607 function Editor(id, settings, editorManager) { 28608 var _this = this; 28609 this.plugins = {}; 28610 this.contentCSS = []; 28611 this.contentStyles = []; 28612 this.loadedCSS = {}; 28613 this.isNotDirty = false; 28614 this.editorManager = editorManager; 28615 this.documentBaseUrl = editorManager.documentBaseURL; 28616 extend$3(this, EditorObservable); 28617 this.settings = getEditorSettings(this, id, this.documentBaseUrl, editorManager.defaultSettings, settings); 28618 if (this.settings.suffix) { 28619 editorManager.suffix = this.settings.suffix; 28620 } 28621 this.suffix = editorManager.suffix; 28622 if (this.settings.base_url) { 28623 editorManager._setBaseUrl(this.settings.base_url); 28624 } 28625 this.baseUri = editorManager.baseURI; 28626 if (this.settings.referrer_policy) { 28627 ScriptLoader.ScriptLoader._setReferrerPolicy(this.settings.referrer_policy); 28628 DOMUtils.DOM.styleSheetLoader._setReferrerPolicy(this.settings.referrer_policy); 28629 } 28630 AddOnManager.languageLoad = this.settings.language_load; 28631 AddOnManager.baseURL = editorManager.baseURL; 28632 this.id = id; 28633 this.setDirty(false); 28634 this.documentBaseURI = new URI(this.settings.document_base_url, { base_uri: this.baseUri }); 28635 this.baseURI = this.baseUri; 28636 this.inline = !!this.settings.inline; 28637 this.shortcuts = new Shortcuts(this); 28638 this.editorCommands = new EditorCommands(this); 28639 if (this.settings.cache_suffix) { 28640 Env.cacheSuffix = this.settings.cache_suffix.replace(/^[\?\&]+/, ''); 28641 } 28642 this.ui = { 28643 registry: registry(), 28644 styleSheetLoader: undefined, 28645 show: noop, 28646 hide: noop, 28647 enable: noop, 28648 disable: noop, 28649 isDisabled: never 28650 }; 28651 var self = this; 28652 var modeInstance = create$4(self); 28653 this.mode = modeInstance; 28654 this.setMode = modeInstance.set; 28655 editorManager.fire('SetupEditor', { editor: this }); 28656 this.execCallback('setup', this); 28657 this.$ = DomQuery.overrideDefaults(function () { 28658 return { 28659 context: _this.inline ? _this.getBody() : _this.getDoc(), 28660 element: _this.getBody() 28661 }; 28662 }); 28663 } 28664 Editor.prototype.render = function () { 28665 render(this); 28666 }; 28667 Editor.prototype.focus = function (skipFocus) { 28668 this.execCommand('mceFocus', false, skipFocus); 28669 }; 28670 Editor.prototype.hasFocus = function () { 28671 return hasFocus(this); 28672 }; 28673 Editor.prototype.execCallback = function (name) { 28674 var x = []; 28675 for (var _i = 1; _i < arguments.length; _i++) { 28676 x[_i - 1] = arguments[_i]; 28677 } 28678 var self = this; 28679 var callback = self.settings[name], scope; 28680 if (!callback) { 28681 return; 28682 } 28683 if (self.callbackLookup && (scope = self.callbackLookup[name])) { 28684 callback = scope.func; 28685 scope = scope.scope; 28686 } 28687 if (typeof callback === 'string') { 28688 scope = callback.replace(/\.\w+$/, ''); 28689 scope = scope ? resolve(scope) : 0; 28690 callback = resolve(callback); 28691 self.callbackLookup = self.callbackLookup || {}; 28692 self.callbackLookup[name] = { 28693 func: callback, 28694 scope: scope 28695 }; 28696 } 28697 return callback.apply(scope || self, x); 28698 }; 28699 Editor.prototype.translate = function (text) { 28700 return I18n.translate(text); 28701 }; 28702 Editor.prototype.getParam = function (name, defaultVal, type) { 28703 return getParam(this, name, defaultVal, type); 28704 }; 28705 Editor.prototype.hasPlugin = function (name, loaded) { 28706 var hasPlugin = contains$3(getPlugins(this).split(/[ ,]/), name); 28707 if (hasPlugin) { 28708 return loaded ? PluginManager.get(name) !== undefined : true; 28709 } else { 28710 return false; 28711 } 28712 }; 28713 Editor.prototype.nodeChanged = function (args) { 28714 this._nodeChangeDispatcher.nodeChanged(args); 28715 }; 28716 Editor.prototype.addCommand = function (name, callback, scope) { 28717 this.editorCommands.addCommand(name, callback, scope); 28718 }; 28719 Editor.prototype.addQueryStateHandler = function (name, callback, scope) { 28720 this.editorCommands.addQueryStateHandler(name, callback, scope); 28721 }; 28722 Editor.prototype.addQueryValueHandler = function (name, callback, scope) { 28723 this.editorCommands.addQueryValueHandler(name, callback, scope); 28724 }; 28725 Editor.prototype.addShortcut = function (pattern, desc, cmdFunc, scope) { 28726 this.shortcuts.add(pattern, desc, cmdFunc, scope); 28727 }; 28728 Editor.prototype.execCommand = function (cmd, ui, value, args) { 28729 return this.editorCommands.execCommand(cmd, ui, value, args); 28730 }; 28731 Editor.prototype.queryCommandState = function (cmd) { 28732 return this.editorCommands.queryCommandState(cmd); 28733 }; 28734 Editor.prototype.queryCommandValue = function (cmd) { 28735 return this.editorCommands.queryCommandValue(cmd); 28736 }; 28737 Editor.prototype.queryCommandSupported = function (cmd) { 28738 return this.editorCommands.queryCommandSupported(cmd); 28739 }; 28740 Editor.prototype.show = function () { 28741 var self = this; 28742 if (self.hidden) { 28743 self.hidden = false; 28744 if (self.inline) { 28745 self.getBody().contentEditable = 'true'; 28746 } else { 28747 DOM$1.show(self.getContainer()); 28748 DOM$1.hide(self.id); 28749 } 28750 self.load(); 28751 self.fire('show'); 28752 } 28753 }; 28754 Editor.prototype.hide = function () { 28755 var self = this, doc = self.getDoc(); 28756 if (!self.hidden) { 28757 if (ie && doc && !self.inline) { 28758 doc.execCommand('SelectAll'); 28759 } 28760 self.save(); 28761 if (self.inline) { 28762 self.getBody().contentEditable = 'false'; 28763 if (self === self.editorManager.focusedEditor) { 28764 self.editorManager.focusedEditor = null; 28765 } 28766 } else { 28767 DOM$1.hide(self.getContainer()); 28768 DOM$1.setStyle(self.id, 'display', self.orgDisplay); 28769 } 28770 self.hidden = true; 28771 self.fire('hide'); 28772 } 28773 }; 28774 Editor.prototype.isHidden = function () { 28775 return !!this.hidden; 28776 }; 28777 Editor.prototype.setProgressState = function (state, time) { 28778 this.fire('ProgressState', { 28779 state: state, 28780 time: time 28781 }); 28782 }; 28783 Editor.prototype.load = function (args) { 28784 var self = this; 28785 var elm = self.getElement(), html; 28786 if (self.removed) { 28787 return ''; 28788 } 28789 if (elm) { 28790 args = args || {}; 28791 args.load = true; 28792 var value = isTextareaOrInput(elm) ? elm.value : elm.innerHTML; 28793 html = self.setContent(value, args); 28794 args.element = elm; 28795 if (!args.no_events) { 28796 self.fire('LoadContent', args); 28797 } 28798 args.element = elm = null; 28799 return html; 28800 } 28801 }; 28802 Editor.prototype.save = function (args) { 28803 var self = this; 28804 var elm = self.getElement(), html, form; 28805 if (!elm || !self.initialized || self.removed) { 28806 return; 28807 } 28808 args = args || {}; 28809 args.save = true; 28810 args.element = elm; 28811 html = args.content = self.getContent(args); 28812 if (!args.no_events) { 28813 self.fire('SaveContent', args); 28814 } 28815 if (args.format === 'raw') { 28816 self.fire('RawSaveContent', args); 28817 } 28818 html = args.content; 28819 if (!isTextareaOrInput(elm)) { 28820 if (args.is_removing || !self.inline) { 28821 elm.innerHTML = html; 28822 } 28823 if (form = DOM$1.getParent(self.id, 'form')) { 28824 each$2(form.elements, function (elm) { 28825 if (elm.name === self.id) { 28826 elm.value = html; 28827 return false; 28828 } 28829 }); 28830 } 28831 } else { 28832 elm.value = html; 28833 } 28834 args.element = elm = null; 28835 if (args.set_dirty !== false) { 28836 self.setDirty(false); 28837 } 28838 return html; 28839 }; 28840 Editor.prototype.setContent = function (content, args) { 28841 return setContent(this, content, args); 28842 }; 28843 Editor.prototype.getContent = function (args) { 28844 return getContent(this, args); 28845 }; 28846 Editor.prototype.insertContent = function (content, args) { 28847 if (args) { 28848 content = extend$3({ content: content }, args); 28849 } 28850 this.execCommand('mceInsertContent', false, content); 28851 }; 28852 Editor.prototype.resetContent = function (initialContent) { 28853 if (initialContent === undefined) { 28854 setContent(this, this.startContent, { format: 'raw' }); 28855 } else { 28856 setContent(this, initialContent); 28857 } 28858 this.undoManager.reset(); 28859 this.setDirty(false); 28860 this.nodeChanged(); 28861 }; 28862 Editor.prototype.isDirty = function () { 28863 return !this.isNotDirty; 28864 }; 28865 Editor.prototype.setDirty = function (state) { 28866 var oldState = !this.isNotDirty; 28867 this.isNotDirty = !state; 28868 if (state && state !== oldState) { 28869 this.fire('dirty'); 28870 } 28871 }; 28872 Editor.prototype.getContainer = function () { 28873 var self = this; 28874 if (!self.container) { 28875 self.container = DOM$1.get(self.editorContainer || self.id + '_parent'); 28876 } 28877 return self.container; 28878 }; 28879 Editor.prototype.getContentAreaContainer = function () { 28880 return this.contentAreaContainer; 28881 }; 28882 Editor.prototype.getElement = function () { 28883 if (!this.targetElm) { 28884 this.targetElm = DOM$1.get(this.id); 28885 } 28886 return this.targetElm; 28887 }; 28888 Editor.prototype.getWin = function () { 28889 var self = this; 28890 var elm; 28891 if (!self.contentWindow) { 28892 elm = self.iframeElement; 28893 if (elm) { 28894 self.contentWindow = elm.contentWindow; 28895 } 28896 } 28897 return self.contentWindow; 28898 }; 28899 Editor.prototype.getDoc = function () { 28900 var self = this; 28901 var win; 28902 if (!self.contentDocument) { 28903 win = self.getWin(); 28904 if (win) { 28905 self.contentDocument = win.document; 28906 } 28907 } 28908 return self.contentDocument; 28909 }; 28910 Editor.prototype.getBody = function () { 28911 var doc = this.getDoc(); 28912 return this.bodyElement || (doc ? doc.body : null); 28913 }; 28914 Editor.prototype.convertURL = function (url, name, elm) { 28915 var self = this, settings = self.settings; 28916 if (settings.urlconverter_callback) { 28917 return self.execCallback('urlconverter_callback', url, elm, true, name); 28918 } 28919 if (!settings.convert_urls || elm && elm.nodeName === 'LINK' || url.indexOf('file:') === 0 || url.length === 0) { 28920 return url; 28921 } 28922 if (settings.relative_urls) { 28923 return self.documentBaseURI.toRelative(url); 28924 } 28925 url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host); 28926 return url; 28927 }; 28928 Editor.prototype.addVisual = function (elm) { 28929 addVisual(this, elm); 28930 }; 28931 Editor.prototype.remove = function () { 28932 remove(this); 28933 }; 28934 Editor.prototype.destroy = function (automatic) { 28935 destroy(this, automatic); 28936 }; 28937 Editor.prototype.uploadImages = function (callback) { 28938 return this.editorUpload.uploadImages(callback); 28939 }; 28940 Editor.prototype._scanForImages = function () { 28941 return this.editorUpload.scanForImages(); 28942 }; 28943 Editor.prototype.addButton = function () { 28944 throw new Error('editor.addButton has been removed in tinymce 5x, use editor.ui.registry.addButton or editor.ui.registry.addToggleButton or editor.ui.registry.addSplitButton instead'); 28945 }; 28946 Editor.prototype.addSidebar = function () { 28947 throw new Error('editor.addSidebar has been removed in tinymce 5x, use editor.ui.registry.addSidebar instead'); 28948 }; 28949 Editor.prototype.addMenuItem = function () { 28950 throw new Error('editor.addMenuItem has been removed in tinymce 5x, use editor.ui.registry.addMenuItem instead'); 28951 }; 28952 Editor.prototype.addContextToolbar = function () { 28953 throw new Error('editor.addContextToolbar has been removed in tinymce 5x, use editor.ui.registry.addContextToolbar instead'); 28954 }; 28955 return Editor; 28956 }(); 28957 28958 var DOM = DOMUtils.DOM; 28959 var explode = Tools.explode, each$1 = Tools.each, extend$2 = Tools.extend; 28960 var instanceCounter = 0, boundGlobalEvents = false; 28961 var beforeUnloadDelegate; 28962 var legacyEditors = []; 28963 var editors = []; 28964 var isValidLegacyKey = function (id) { 28965 return id !== 'length'; 28966 }; 28967 var globalEventDelegate = function (e) { 28968 var type = e.type; 28969 each$1(EditorManager.get(), function (editor) { 28970 switch (type) { 28971 case 'scroll': 28972 editor.fire('ScrollWindow', e); 28973 break; 28974 case 'resize': 28975 editor.fire('ResizeWindow', e); 28976 break; 28977 } 28978 }); 28979 }; 28980 var toggleGlobalEvents = function (state) { 28981 if (state !== boundGlobalEvents) { 28982 if (state) { 28983 DomQuery(window).on('resize scroll', globalEventDelegate); 28984 } else { 28985 DomQuery(window).off('resize scroll', globalEventDelegate); 28986 } 28987 boundGlobalEvents = state; 28988 } 28989 }; 28990 var removeEditorFromList = function (targetEditor) { 28991 var oldEditors = editors; 28992 delete legacyEditors[targetEditor.id]; 28993 for (var i = 0; i < legacyEditors.length; i++) { 28994 if (legacyEditors[i] === targetEditor) { 28995 legacyEditors.splice(i, 1); 28996 break; 28997 } 28998 } 28999 editors = filter$4(editors, function (editor) { 29000 return targetEditor !== editor; 29001 }); 29002 if (EditorManager.activeEditor === targetEditor) { 29003 EditorManager.activeEditor = editors.length > 0 ? editors[0] : null; 29004 } 29005 if (EditorManager.focusedEditor === targetEditor) { 29006 EditorManager.focusedEditor = null; 29007 } 29008 return oldEditors.length !== editors.length; 29009 }; 29010 var purgeDestroyedEditor = function (editor) { 29011 if (editor && editor.initialized && !(editor.getContainer() || editor.getBody()).parentNode) { 29012 removeEditorFromList(editor); 29013 editor.unbindAllNativeEvents(); 29014 editor.destroy(true); 29015 editor.removed = true; 29016 editor = null; 29017 } 29018 return editor; 29019 }; 29020 var isQuirksMode = document.compatMode !== 'CSS1Compat'; 29021 var EditorManager = __assign(__assign({}, Observable), { 29022 baseURI: null, 29023 baseURL: null, 29024 defaultSettings: {}, 29025 documentBaseURL: null, 29026 suffix: null, 29027 $: DomQuery, 29028 majorVersion: '5', 29029 minorVersion: '10.5', 29030 releaseDate: '2022-05-25', 29031 editors: legacyEditors, 29032 i18n: I18n, 29033 activeEditor: null, 29034 focusedEditor: null, 29035 settings: {}, 29036 setup: function () { 29037 var self = this; 29038 var baseURL, documentBaseURL, suffix = ''; 29039 documentBaseURL = URI.getDocumentBaseUrl(document.location); 29040 if (/^[^:]+:\/\/\/?[^\/]+\//.test(documentBaseURL)) { 29041 documentBaseURL = documentBaseURL.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, ''); 29042 if (!/[\/\\]$/.test(documentBaseURL)) { 29043 documentBaseURL += '/'; 29044 } 29045 } 29046 var preInit = window.tinymce || window.tinyMCEPreInit; 29047 if (preInit) { 29048 baseURL = preInit.base || preInit.baseURL; 29049 suffix = preInit.suffix; 29050 } else { 29051 var scripts = document.getElementsByTagName('script'); 29052 for (var i = 0; i < scripts.length; i++) { 29053 var src = scripts[i].src || ''; 29054 if (src === '') { 29055 continue; 29056 } 29057 var srcScript = src.substring(src.lastIndexOf('/')); 29058 if (/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(src)) { 29059 if (srcScript.indexOf('.min') !== -1) { 29060 suffix = '.min'; 29061 } 29062 baseURL = src.substring(0, src.lastIndexOf('/')); 29063 break; 29064 } 29065 } 29066 if (!baseURL && document.currentScript) { 29067 var src = document.currentScript.src; 29068 if (src.indexOf('.min') !== -1) { 29069 suffix = '.min'; 29070 } 29071 baseURL = src.substring(0, src.lastIndexOf('/')); 29072 } 29073 } 29074 self.baseURL = new URI(documentBaseURL).toAbsolute(baseURL); 29075 self.documentBaseURL = documentBaseURL; 29076 self.baseURI = new URI(self.baseURL); 29077 self.suffix = suffix; 29078 setup$l(self); 29079 }, 29080 overrideDefaults: function (defaultSettings) { 29081 var baseUrl = defaultSettings.base_url; 29082 if (baseUrl) { 29083 this._setBaseUrl(baseUrl); 29084 } 29085 var suffix = defaultSettings.suffix; 29086 if (defaultSettings.suffix) { 29087 this.suffix = suffix; 29088 } 29089 this.defaultSettings = defaultSettings; 29090 var pluginBaseUrls = defaultSettings.plugin_base_urls; 29091 if (pluginBaseUrls !== undefined) { 29092 each$j(pluginBaseUrls, function (pluginBaseUrl, pluginName) { 29093 AddOnManager.PluginManager.urls[pluginName] = pluginBaseUrl; 29094 }); 29095 } 29096 }, 29097 init: function (settings) { 29098 var self = this; 29099 var result; 29100 var invalidInlineTargets = Tools.makeMap('area base basefont br col frame hr img input isindex link meta param embed source wbr track ' + 'colgroup option table tbody tfoot thead tr th td script noscript style textarea video audio iframe object menu', ' '); 29101 var isInvalidInlineTarget = function (settings, elm) { 29102 return settings.inline && elm.tagName.toLowerCase() in invalidInlineTargets; 29103 }; 29104 var createId = function (elm) { 29105 var id = elm.id; 29106 if (!id) { 29107 id = get$9(elm, 'name').filter(function (name) { 29108 return !DOM.get(name); 29109 }).getOrThunk(DOM.uniqueId); 29110 elm.setAttribute('id', id); 29111 } 29112 return id; 29113 }; 29114 var execCallback = function (name) { 29115 var callback = settings[name]; 29116 if (!callback) { 29117 return; 29118 } 29119 return callback.apply(self, []); 29120 }; 29121 var hasClass = function (elm, className) { 29122 return className.constructor === RegExp ? className.test(elm.className) : DOM.hasClass(elm, className); 29123 }; 29124 var findTargets = function (settings) { 29125 var targets = []; 29126 if (Env.browser.isIE() && Env.browser.version.major < 11) { 29127 initError('TinyMCE does not support the browser you are using. For a list of supported' + ' browsers please see: https://www.tinymce.com/docs/get-started/system-requirements/'); 29128 return []; 29129 } else if (isQuirksMode) { 29130 initError('Failed to initialize the editor as the document is not in standards mode. ' + 'TinyMCE requires standards mode.'); 29131 return []; 29132 } 29133 if (settings.types) { 29134 each$1(settings.types, function (type) { 29135 targets = targets.concat(DOM.select(type.selector)); 29136 }); 29137 return targets; 29138 } else if (settings.selector) { 29139 return DOM.select(settings.selector); 29140 } else if (settings.target) { 29141 return [settings.target]; 29142 } 29143 switch (settings.mode) { 29144 case 'exact': 29145 var l = settings.elements || ''; 29146 if (l.length > 0) { 29147 each$1(explode(l), function (id) { 29148 var elm = DOM.get(id); 29149 if (elm) { 29150 targets.push(elm); 29151 } else { 29152 each$1(document.forms, function (f) { 29153 each$1(f.elements, function (e) { 29154 if (e.name === id) { 29155 id = 'mce_editor_' + instanceCounter++; 29156 DOM.setAttrib(e, 'id', id); 29157 targets.push(e); 29158 } 29159 }); 29160 }); 29161 } 29162 }); 29163 } 29164 break; 29165 case 'textareas': 29166 case 'specific_textareas': 29167 each$1(DOM.select('textarea'), function (elm) { 29168 if (settings.editor_deselector && hasClass(elm, settings.editor_deselector)) { 29169 return; 29170 } 29171 if (!settings.editor_selector || hasClass(elm, settings.editor_selector)) { 29172 targets.push(elm); 29173 } 29174 }); 29175 break; 29176 } 29177 return targets; 29178 }; 29179 var provideResults = function (editors) { 29180 result = editors; 29181 }; 29182 var initEditors = function () { 29183 var initCount = 0; 29184 var editors = []; 29185 var targets; 29186 var createEditor = function (id, settings, targetElm) { 29187 var editor = new Editor(id, settings, self); 29188 editors.push(editor); 29189 editor.on('init', function () { 29190 if (++initCount === targets.length) { 29191 provideResults(editors); 29192 } 29193 }); 29194 editor.targetElm = editor.targetElm || targetElm; 29195 editor.render(); 29196 }; 29197 DOM.unbind(window, 'ready', initEditors); 29198 execCallback('onpageload'); 29199 targets = DomQuery.unique(findTargets(settings)); 29200 if (settings.types) { 29201 each$1(settings.types, function (type) { 29202 Tools.each(targets, function (elm) { 29203 if (DOM.is(elm, type.selector)) { 29204 createEditor(createId(elm), extend$2({}, settings, type), elm); 29205 return false; 29206 } 29207 return true; 29208 }); 29209 }); 29210 return; 29211 } 29212 Tools.each(targets, function (elm) { 29213 purgeDestroyedEditor(self.get(elm.id)); 29214 }); 29215 targets = Tools.grep(targets, function (elm) { 29216 return !self.get(elm.id); 29217 }); 29218 if (targets.length === 0) { 29219 provideResults([]); 29220 } else { 29221 each$1(targets, function (elm) { 29222 if (isInvalidInlineTarget(settings, elm)) { 29223 initError('Could not initialize inline editor on invalid inline target element', elm); 29224 } else { 29225 createEditor(createId(elm), settings, elm); 29226 } 29227 }); 29228 } 29229 }; 29230 self.settings = settings; 29231 DOM.bind(window, 'ready', initEditors); 29232 return new promiseObj(function (resolve) { 29233 if (result) { 29234 resolve(result); 29235 } else { 29236 provideResults = function (editors) { 29237 resolve(editors); 29238 }; 29239 } 29240 }); 29241 }, 29242 get: function (id) { 29243 if (arguments.length === 0) { 29244 return editors.slice(0); 29245 } else if (isString$1(id)) { 29246 return find$3(editors, function (editor) { 29247 return editor.id === id; 29248 }).getOr(null); 29249 } else if (isNumber(id)) { 29250 return editors[id] ? editors[id] : null; 29251 } else { 29252 return null; 29253 } 29254 }, 29255 add: function (editor) { 29256 var self = this; 29257 var existingEditor = legacyEditors[editor.id]; 29258 if (existingEditor === editor) { 29259 return editor; 29260 } 29261 if (self.get(editor.id) === null) { 29262 if (isValidLegacyKey(editor.id)) { 29263 legacyEditors[editor.id] = editor; 29264 } 29265 legacyEditors.push(editor); 29266 editors.push(editor); 29267 } 29268 toggleGlobalEvents(true); 29269 self.activeEditor = editor; 29270 self.fire('AddEditor', { editor: editor }); 29271 if (!beforeUnloadDelegate) { 29272 beforeUnloadDelegate = function (e) { 29273 var event = self.fire('BeforeUnload'); 29274 if (event.returnValue) { 29275 e.preventDefault(); 29276 e.returnValue = event.returnValue; 29277 return event.returnValue; 29278 } 29279 }; 29280 window.addEventListener('beforeunload', beforeUnloadDelegate); 29281 } 29282 return editor; 29283 }, 29284 createEditor: function (id, settings) { 29285 return this.add(new Editor(id, settings, this)); 29286 }, 29287 remove: function (selector) { 29288 var self = this; 29289 var i, editor; 29290 if (!selector) { 29291 for (i = editors.length - 1; i >= 0; i--) { 29292 self.remove(editors[i]); 29293 } 29294 return; 29295 } 29296 if (isString$1(selector)) { 29297 each$1(DOM.select(selector), function (elm) { 29298 editor = self.get(elm.id); 29299 if (editor) { 29300 self.remove(editor); 29301 } 29302 }); 29303 return; 29304 } 29305 editor = selector; 29306 if (isNull(self.get(editor.id))) { 29307 return null; 29308 } 29309 if (removeEditorFromList(editor)) { 29310 self.fire('RemoveEditor', { editor: editor }); 29311 } 29312 if (editors.length === 0) { 29313 window.removeEventListener('beforeunload', beforeUnloadDelegate); 29314 } 29315 editor.remove(); 29316 toggleGlobalEvents(editors.length > 0); 29317 return editor; 29318 }, 29319 execCommand: function (cmd, ui, value) { 29320 var self = this, editor = self.get(value); 29321 switch (cmd) { 29322 case 'mceAddEditor': 29323 if (!self.get(value)) { 29324 new Editor(value, self.settings, self).render(); 29325 } 29326 return true; 29327 case 'mceRemoveEditor': 29328 if (editor) { 29329 editor.remove(); 29330 } 29331 return true; 29332 case 'mceToggleEditor': 29333 if (!editor) { 29334 self.execCommand('mceAddEditor', false, value); 29335 return true; 29336 } 29337 if (editor.isHidden()) { 29338 editor.show(); 29339 } else { 29340 editor.hide(); 29341 } 29342 return true; 29343 } 29344 if (self.activeEditor) { 29345 return self.activeEditor.execCommand(cmd, ui, value); 29346 } 29347 return false; 29348 }, 29349 triggerSave: function () { 29350 each$1(editors, function (editor) { 29351 editor.save(); 29352 }); 29353 }, 29354 addI18n: function (code, items) { 29355 I18n.add(code, items); 29356 }, 29357 translate: function (text) { 29358 return I18n.translate(text); 29359 }, 29360 setActive: function (editor) { 29361 var activeEditor = this.activeEditor; 29362 if (this.activeEditor !== editor) { 29363 if (activeEditor) { 29364 activeEditor.fire('deactivate', { relatedTarget: editor }); 29365 } 29366 editor.fire('activate', { relatedTarget: activeEditor }); 29367 } 29368 this.activeEditor = editor; 29369 }, 29370 _setBaseUrl: function (baseUrl) { 29371 this.baseURL = new URI(this.documentBaseURL).toAbsolute(baseUrl.replace(/\/+$/, '')); 29372 this.baseURI = new URI(this.baseURL); 29373 } 29374 }); 29375 EditorManager.setup(); 29376 29377 var min$1 = Math.min, max$1 = Math.max, round$1 = Math.round; 29378 var relativePosition = function (rect, targetRect, rel) { 29379 var x = targetRect.x; 29380 var y = targetRect.y; 29381 var w = rect.w; 29382 var h = rect.h; 29383 var targetW = targetRect.w; 29384 var targetH = targetRect.h; 29385 var relChars = (rel || '').split(''); 29386 if (relChars[0] === 'b') { 29387 y += targetH; 29388 } 29389 if (relChars[1] === 'r') { 29390 x += targetW; 29391 } 29392 if (relChars[0] === 'c') { 29393 y += round$1(targetH / 2); 29394 } 29395 if (relChars[1] === 'c') { 29396 x += round$1(targetW / 2); 29397 } 29398 if (relChars[3] === 'b') { 29399 y -= h; 29400 } 29401 if (relChars[4] === 'r') { 29402 x -= w; 29403 } 29404 if (relChars[3] === 'c') { 29405 y -= round$1(h / 2); 29406 } 29407 if (relChars[4] === 'c') { 29408 x -= round$1(w / 2); 29409 } 29410 return create$2(x, y, w, h); 29411 }; 29412 var findBestRelativePosition = function (rect, targetRect, constrainRect, rels) { 29413 var pos, i; 29414 for (i = 0; i < rels.length; i++) { 29415 pos = relativePosition(rect, targetRect, rels[i]); 29416 if (pos.x >= constrainRect.x && pos.x + pos.w <= constrainRect.w + constrainRect.x && pos.y >= constrainRect.y && pos.y + pos.h <= constrainRect.h + constrainRect.y) { 29417 return rels[i]; 29418 } 29419 } 29420 return null; 29421 }; 29422 var inflate = function (rect, w, h) { 29423 return create$2(rect.x - w, rect.y - h, rect.w + w * 2, rect.h + h * 2); 29424 }; 29425 var intersect = function (rect, cropRect) { 29426 var x1 = max$1(rect.x, cropRect.x); 29427 var y1 = max$1(rect.y, cropRect.y); 29428 var x2 = min$1(rect.x + rect.w, cropRect.x + cropRect.w); 29429 var y2 = min$1(rect.y + rect.h, cropRect.y + cropRect.h); 29430 if (x2 - x1 < 0 || y2 - y1 < 0) { 29431 return null; 29432 } 29433 return create$2(x1, y1, x2 - x1, y2 - y1); 29434 }; 29435 var clamp = function (rect, clampRect, fixedSize) { 29436 var x1 = rect.x; 29437 var y1 = rect.y; 29438 var x2 = rect.x + rect.w; 29439 var y2 = rect.y + rect.h; 29440 var cx2 = clampRect.x + clampRect.w; 29441 var cy2 = clampRect.y + clampRect.h; 29442 var underflowX1 = max$1(0, clampRect.x - x1); 29443 var underflowY1 = max$1(0, clampRect.y - y1); 29444 var overflowX2 = max$1(0, x2 - cx2); 29445 var overflowY2 = max$1(0, y2 - cy2); 29446 x1 += underflowX1; 29447 y1 += underflowY1; 29448 if (fixedSize) { 29449 x2 += underflowX1; 29450 y2 += underflowY1; 29451 x1 -= overflowX2; 29452 y1 -= overflowY2; 29453 } 29454 x2 -= overflowX2; 29455 y2 -= overflowY2; 29456 return create$2(x1, y1, x2 - x1, y2 - y1); 29457 }; 29458 var create$2 = function (x, y, w, h) { 29459 return { 29460 x: x, 29461 y: y, 29462 w: w, 29463 h: h 29464 }; 29465 }; 29466 var fromClientRect = function (clientRect) { 29467 return create$2(clientRect.left, clientRect.top, clientRect.width, clientRect.height); 29468 }; 29469 var Rect = { 29470 inflate: inflate, 29471 relativePosition: relativePosition, 29472 findBestRelativePosition: findBestRelativePosition, 29473 intersect: intersect, 29474 clamp: clamp, 29475 create: create$2, 29476 fromClientRect: fromClientRect 29477 }; 29478 29479 var awaiter = function (resolveCb, rejectCb, timeout) { 29480 if (timeout === void 0) { 29481 timeout = 1000; 29482 } 29483 var done = false; 29484 var timer = null; 29485 var complete = function (completer) { 29486 return function () { 29487 var args = []; 29488 for (var _i = 0; _i < arguments.length; _i++) { 29489 args[_i] = arguments[_i]; 29490 } 29491 if (!done) { 29492 done = true; 29493 if (timer !== null) { 29494 clearTimeout(timer); 29495 timer = null; 29496 } 29497 completer.apply(null, args); 29498 } 29499 }; 29500 }; 29501 var resolve = complete(resolveCb); 29502 var reject = complete(rejectCb); 29503 var start = function () { 29504 var args = []; 29505 for (var _i = 0; _i < arguments.length; _i++) { 29506 args[_i] = arguments[_i]; 29507 } 29508 if (!done && timer === null) { 29509 timer = setTimeout(function () { 29510 return reject.apply(null, args); 29511 }, timeout); 29512 } 29513 }; 29514 return { 29515 start: start, 29516 resolve: resolve, 29517 reject: reject 29518 }; 29519 }; 29520 var create$1 = function () { 29521 var tasks = {}; 29522 var resultFns = {}; 29523 var load = function (id, url) { 29524 var loadErrMsg = 'Script at URL "' + url + '" failed to load'; 29525 var runErrMsg = 'Script at URL "' + url + '" did not call `tinymce.Resource.add(\'' + id + '\', data)` within 1 second'; 29526 if (tasks[id] !== undefined) { 29527 return tasks[id]; 29528 } else { 29529 var task = new promiseObj(function (resolve, reject) { 29530 var waiter = awaiter(resolve, reject); 29531 resultFns[id] = waiter.resolve; 29532 ScriptLoader.ScriptLoader.loadScript(url, function () { 29533 return waiter.start(runErrMsg); 29534 }, function () { 29535 return waiter.reject(loadErrMsg); 29536 }); 29537 }); 29538 tasks[id] = task; 29539 return task; 29540 } 29541 }; 29542 var add = function (id, data) { 29543 if (resultFns[id] !== undefined) { 29544 resultFns[id](data); 29545 delete resultFns[id]; 29546 } 29547 tasks[id] = promiseObj.resolve(data); 29548 }; 29549 return { 29550 load: load, 29551 add: add 29552 }; 29553 }; 29554 var Resource = create$1(); 29555 29556 var each = Tools.each, extend$1 = Tools.extend; 29557 var extendClass, initializing; 29558 var Class = function () { 29559 }; 29560 Class.extend = extendClass = function (props) { 29561 var self = this; 29562 var _super = self.prototype; 29563 var Class = function () { 29564 var i, mixins, mixin; 29565 var self = this; 29566 if (!initializing) { 29567 if (self.init) { 29568 self.init.apply(self, arguments); 29569 } 29570 mixins = self.Mixins; 29571 if (mixins) { 29572 i = mixins.length; 29573 while (i--) { 29574 mixin = mixins[i]; 29575 if (mixin.init) { 29576 mixin.init.apply(self, arguments); 29577 } 29578 } 29579 } 29580 } 29581 }; 29582 var dummy = function () { 29583 return this; 29584 }; 29585 var createMethod = function (name, fn) { 29586 return function () { 29587 var self = this; 29588 var tmp = self._super; 29589 self._super = _super[name]; 29590 var ret = fn.apply(self, arguments); 29591 self._super = tmp; 29592 return ret; 29593 }; 29594 }; 29595 initializing = true; 29596 var prototype = new self(); 29597 initializing = false; 29598 if (props.Mixins) { 29599 each(props.Mixins, function (mixin) { 29600 for (var name_1 in mixin) { 29601 if (name_1 !== 'init') { 29602 props[name_1] = mixin[name_1]; 29603 } 29604 } 29605 }); 29606 if (_super.Mixins) { 29607 props.Mixins = _super.Mixins.concat(props.Mixins); 29608 } 29609 } 29610 if (props.Methods) { 29611 each(props.Methods.split(','), function (name) { 29612 props[name] = dummy; 29613 }); 29614 } 29615 if (props.Properties) { 29616 each(props.Properties.split(','), function (name) { 29617 var fieldName = '_' + name; 29618 props[name] = function (value) { 29619 var self = this; 29620 if (value !== undefined) { 29621 self[fieldName] = value; 29622 return self; 29623 } 29624 return self[fieldName]; 29625 }; 29626 }); 29627 } 29628 if (props.Statics) { 29629 each(props.Statics, function (func, name) { 29630 Class[name] = func; 29631 }); 29632 } 29633 if (props.Defaults && _super.Defaults) { 29634 props.Defaults = extend$1({}, _super.Defaults, props.Defaults); 29635 } 29636 each$j(props, function (member, name) { 29637 if (typeof member === 'function' && _super[name]) { 29638 prototype[name] = createMethod(name, member); 29639 } else { 29640 prototype[name] = member; 29641 } 29642 }); 29643 Class.prototype = prototype; 29644 Class.constructor = Class; 29645 Class.extend = extendClass; 29646 return Class; 29647 }; 29648 29649 var min = Math.min, max = Math.max, round = Math.round; 29650 var Color = function (value) { 29651 var self = {}; 29652 var r = 0, g = 0, b = 0; 29653 var rgb2hsv = function (r, g, b) { 29654 var h, s, v; 29655 h = 0; 29656 s = 0; 29657 v = 0; 29658 r = r / 255; 29659 g = g / 255; 29660 b = b / 255; 29661 var minRGB = min(r, min(g, b)); 29662 var maxRGB = max(r, max(g, b)); 29663 if (minRGB === maxRGB) { 29664 v = minRGB; 29665 return { 29666 h: 0, 29667 s: 0, 29668 v: v * 100 29669 }; 29670 } 29671 var d = r === minRGB ? g - b : b === minRGB ? r - g : b - r; 29672 h = r === minRGB ? 3 : b === minRGB ? 1 : 5; 29673 h = 60 * (h - d / (maxRGB - minRGB)); 29674 s = (maxRGB - minRGB) / maxRGB; 29675 v = maxRGB; 29676 return { 29677 h: round(h), 29678 s: round(s * 100), 29679 v: round(v * 100) 29680 }; 29681 }; 29682 var hsvToRgb = function (hue, saturation, brightness) { 29683 hue = (parseInt(hue, 10) || 0) % 360; 29684 saturation = parseInt(saturation, 10) / 100; 29685 brightness = parseInt(brightness, 10) / 100; 29686 saturation = max(0, min(saturation, 1)); 29687 brightness = max(0, min(brightness, 1)); 29688 if (saturation === 0) { 29689 r = g = b = round(255 * brightness); 29690 return; 29691 } 29692 var side = hue / 60; 29693 var chroma = brightness * saturation; 29694 var x = chroma * (1 - Math.abs(side % 2 - 1)); 29695 var match = brightness - chroma; 29696 switch (Math.floor(side)) { 29697 case 0: 29698 r = chroma; 29699 g = x; 29700 b = 0; 29701 break; 29702 case 1: 29703 r = x; 29704 g = chroma; 29705 b = 0; 29706 break; 29707 case 2: 29708 r = 0; 29709 g = chroma; 29710 b = x; 29711 break; 29712 case 3: 29713 r = 0; 29714 g = x; 29715 b = chroma; 29716 break; 29717 case 4: 29718 r = x; 29719 g = 0; 29720 b = chroma; 29721 break; 29722 case 5: 29723 r = chroma; 29724 g = 0; 29725 b = x; 29726 break; 29727 default: 29728 r = g = b = 0; 29729 } 29730 r = round(255 * (r + match)); 29731 g = round(255 * (g + match)); 29732 b = round(255 * (b + match)); 29733 }; 29734 var toHex = function () { 29735 var hex = function (val) { 29736 val = parseInt(val, 10).toString(16); 29737 return val.length > 1 ? val : '0' + val; 29738 }; 29739 return '#' + hex(r) + hex(g) + hex(b); 29740 }; 29741 var toRgb = function () { 29742 return { 29743 r: r, 29744 g: g, 29745 b: b 29746 }; 29747 }; 29748 var toHsv = function () { 29749 return rgb2hsv(r, g, b); 29750 }; 29751 var parse = function (value) { 29752 var matches; 29753 if (typeof value === 'object') { 29754 if ('r' in value) { 29755 r = value.r; 29756 g = value.g; 29757 b = value.b; 29758 } else if ('v' in value) { 29759 hsvToRgb(value.h, value.s, value.v); 29760 } 29761 } else { 29762 if (matches = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(value)) { 29763 r = parseInt(matches[1], 10); 29764 g = parseInt(matches[2], 10); 29765 b = parseInt(matches[3], 10); 29766 } else if (matches = /#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(value)) { 29767 r = parseInt(matches[1], 16); 29768 g = parseInt(matches[2], 16); 29769 b = parseInt(matches[3], 16); 29770 } else if (matches = /#([0-F])([0-F])([0-F])/gi.exec(value)) { 29771 r = parseInt(matches[1] + matches[1], 16); 29772 g = parseInt(matches[2] + matches[2], 16); 29773 b = parseInt(matches[3] + matches[3], 16); 29774 } 29775 } 29776 r = r < 0 ? 0 : r > 255 ? 255 : r; 29777 g = g < 0 ? 0 : g > 255 ? 255 : g; 29778 b = b < 0 ? 0 : b > 255 ? 255 : b; 29779 return self; 29780 }; 29781 if (value) { 29782 parse(value); 29783 } 29784 self.toRgb = toRgb; 29785 self.toHsv = toHsv; 29786 self.toHex = toHex; 29787 self.parse = parse; 29788 return self; 29789 }; 29790 29791 var serialize = function (obj) { 29792 var data = JSON.stringify(obj); 29793 if (!isString$1(data)) { 29794 return data; 29795 } 29796 return data.replace(/[\u0080-\uFFFF]/g, function (match) { 29797 var hexCode = match.charCodeAt(0).toString(16); 29798 return '\\u' + '0000'.substring(hexCode.length) + hexCode; 29799 }); 29800 }; 29801 var JSONUtils = { 29802 serialize: serialize, 29803 parse: function (text) { 29804 try { 29805 return JSON.parse(text); 29806 } catch (ex) { 29807 } 29808 } 29809 }; 29810 29811 var JSONP = { 29812 callbacks: {}, 29813 count: 0, 29814 send: function (settings) { 29815 var self = this, dom = DOMUtils.DOM, count = settings.count !== undefined ? settings.count : self.count; 29816 var id = 'tinymce_jsonp_' + count; 29817 self.callbacks[count] = function (json) { 29818 dom.remove(id); 29819 delete self.callbacks[count]; 29820 settings.callback(json); 29821 }; 29822 dom.add(dom.doc.body, 'script', { 29823 id: id, 29824 src: settings.url, 29825 type: 'text/javascript' 29826 }); 29827 self.count++; 29828 } 29829 }; 29830 29831 var XHR = __assign(__assign({}, Observable), { 29832 send: function (settings) { 29833 var xhr, count = 0; 29834 var ready = function () { 29835 if (!settings.async || xhr.readyState === 4 || count++ > 10000) { 29836 if (settings.success && count < 10000 && xhr.status === 200) { 29837 settings.success.call(settings.success_scope, '' + xhr.responseText, xhr, settings); 29838 } else if (settings.error) { 29839 settings.error.call(settings.error_scope, count > 10000 ? 'TIMED_OUT' : 'GENERAL', xhr, settings); 29840 } 29841 xhr = null; 29842 } else { 29843 Delay.setTimeout(ready, 10); 29844 } 29845 }; 29846 settings.scope = settings.scope || this; 29847 settings.success_scope = settings.success_scope || settings.scope; 29848 settings.error_scope = settings.error_scope || settings.scope; 29849 settings.async = settings.async !== false; 29850 settings.data = settings.data || ''; 29851 XHR.fire('beforeInitialize', { settings: settings }); 29852 xhr = new XMLHttpRequest(); 29853 if (xhr.overrideMimeType) { 29854 xhr.overrideMimeType(settings.content_type); 29855 } 29856 xhr.open(settings.type || (settings.data ? 'POST' : 'GET'), settings.url, settings.async); 29857 if (settings.crossDomain) { 29858 xhr.withCredentials = true; 29859 } 29860 if (settings.content_type) { 29861 xhr.setRequestHeader('Content-Type', settings.content_type); 29862 } 29863 if (settings.requestheaders) { 29864 Tools.each(settings.requestheaders, function (header) { 29865 xhr.setRequestHeader(header.key, header.value); 29866 }); 29867 } 29868 xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 29869 xhr = XHR.fire('beforeSend', { 29870 xhr: xhr, 29871 settings: settings 29872 }).xhr; 29873 xhr.send(settings.data); 29874 if (!settings.async) { 29875 return ready(); 29876 } 29877 Delay.setTimeout(ready, 10); 29878 } 29879 }); 29880 29881 var extend = Tools.extend; 29882 var JSONRequest = function () { 29883 function JSONRequest(settings) { 29884 this.settings = extend({}, settings); 29885 this.count = 0; 29886 } 29887 JSONRequest.sendRPC = function (o) { 29888 return new JSONRequest().send(o); 29889 }; 29890 JSONRequest.prototype.send = function (args) { 29891 var ecb = args.error, scb = args.success; 29892 var xhrArgs = extend(this.settings, args); 29893 xhrArgs.success = function (c, x) { 29894 c = JSONUtils.parse(c); 29895 if (typeof c === 'undefined') { 29896 c = { error: 'JSON Parse error.' }; 29897 } 29898 if (c.error) { 29899 ecb.call(xhrArgs.error_scope || xhrArgs.scope, c.error, x); 29900 } else { 29901 scb.call(xhrArgs.success_scope || xhrArgs.scope, c.result); 29902 } 29903 }; 29904 xhrArgs.error = function (ty, x) { 29905 if (ecb) { 29906 ecb.call(xhrArgs.error_scope || xhrArgs.scope, ty, x); 29907 } 29908 }; 29909 xhrArgs.data = JSONUtils.serialize({ 29910 id: args.id || 'c' + this.count++, 29911 method: args.method, 29912 params: args.params 29913 }); 29914 xhrArgs.content_type = 'application/json'; 29915 XHR.send(xhrArgs); 29916 }; 29917 return JSONRequest; 29918 }(); 29919 29920 var create = function () { 29921 return function () { 29922 var data = {}; 29923 var keys = []; 29924 var storage = { 29925 getItem: function (key) { 29926 var item = data[key]; 29927 return item ? item : null; 29928 }, 29929 setItem: function (key, value) { 29930 keys.push(key); 29931 data[key] = String(value); 29932 }, 29933 key: function (index) { 29934 return keys[index]; 29935 }, 29936 removeItem: function (key) { 29937 keys = keys.filter(function (k) { 29938 return k === key; 29939 }); 29940 delete data[key]; 29941 }, 29942 clear: function () { 29943 keys = []; 29944 data = {}; 29945 }, 29946 length: 0 29947 }; 29948 Object.defineProperty(storage, 'length', { 29949 get: function () { 29950 return keys.length; 29951 }, 29952 configurable: false, 29953 enumerable: false 29954 }); 29955 return storage; 29956 }(); 29957 }; 29958 29959 var localStorage; 29960 try { 29961 var test = '__storage_test__'; 29962 localStorage = window.localStorage; 29963 localStorage.setItem(test, test); 29964 localStorage.removeItem(test); 29965 } catch (e) { 29966 localStorage = create(); 29967 } 29968 var LocalStorage = localStorage; 29969 29970 var publicApi = { 29971 geom: { Rect: Rect }, 29972 util: { 29973 Promise: promiseObj, 29974 Delay: Delay, 29975 Tools: Tools, 29976 VK: VK, 29977 URI: URI, 29978 Class: Class, 29979 EventDispatcher: EventDispatcher, 29980 Observable: Observable, 29981 I18n: I18n, 29982 XHR: XHR, 29983 JSON: JSONUtils, 29984 JSONRequest: JSONRequest, 29985 JSONP: JSONP, 29986 LocalStorage: LocalStorage, 29987 Color: Color, 29988 ImageUploader: ImageUploader 29989 }, 29990 dom: { 29991 EventUtils: EventUtils, 29992 Sizzle: Sizzle, 29993 DomQuery: DomQuery, 29994 TreeWalker: DomTreeWalker, 29995 TextSeeker: TextSeeker, 29996 DOMUtils: DOMUtils, 29997 ScriptLoader: ScriptLoader, 29998 RangeUtils: RangeUtils, 29999 Serializer: DomSerializer, 30000 StyleSheetLoader: StyleSheetLoader, 30001 ControlSelection: ControlSelection, 30002 BookmarkManager: BookmarkManager, 30003 Selection: EditorSelection, 30004 Event: EventUtils.Event 30005 }, 30006 html: { 30007 Styles: Styles, 30008 Entities: Entities, 30009 Node: AstNode, 30010 Schema: Schema, 30011 SaxParser: SaxParser, 30012 DomParser: DomParser, 30013 Writer: Writer, 30014 Serializer: HtmlSerializer 30015 }, 30016 Env: Env, 30017 AddOnManager: AddOnManager, 30018 Annotator: Annotator, 30019 Formatter: Formatter, 30020 UndoManager: UndoManager, 30021 EditorCommands: EditorCommands, 30022 WindowManager: WindowManager, 30023 NotificationManager: NotificationManager, 30024 EditorObservable: EditorObservable, 30025 Shortcuts: Shortcuts, 30026 Editor: Editor, 30027 FocusManager: FocusManager, 30028 EditorManager: EditorManager, 30029 DOM: DOMUtils.DOM, 30030 ScriptLoader: ScriptLoader.ScriptLoader, 30031 PluginManager: PluginManager, 30032 ThemeManager: ThemeManager, 30033 IconManager: IconManager, 30034 Resource: Resource, 30035 trim: Tools.trim, 30036 isArray: Tools.isArray, 30037 is: Tools.is, 30038 toArray: Tools.toArray, 30039 makeMap: Tools.makeMap, 30040 each: Tools.each, 30041 map: Tools.map, 30042 grep: Tools.grep, 30043 inArray: Tools.inArray, 30044 extend: Tools.extend, 30045 create: Tools.create, 30046 walk: Tools.walk, 30047 createNS: Tools.createNS, 30048 resolve: Tools.resolve, 30049 explode: Tools.explode, 30050 _addCacheSuffix: Tools._addCacheSuffix, 30051 isOpera: Env.opera, 30052 isWebKit: Env.webkit, 30053 isIE: Env.ie, 30054 isGecko: Env.gecko, 30055 isMac: Env.mac 30056 }; 30057 var tinymce = Tools.extend(EditorManager, publicApi); 30058 30059 var exportToModuleLoaders = function (tinymce) { 30060 if (typeof module === 'object') { 30061 try { 30062 module.exports = tinymce; 30063 } catch (_) { 30064 } 30065 } 30066 }; 30067 var exportToWindowGlobal = function (tinymce) { 30068 window.tinymce = tinymce; 30069 window.tinyMCE = tinymce; 30070 }; 30071 exportToWindowGlobal(tinymce); 30072 exportToModuleLoaders(tinymce); 30073 30074 }());
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |