UNPKG

tinymce

Version:

Web based JavaScript HTML WYSIWYG editor control.

1,250 lines (1,195 loc) 104 kB
/** * TinyMCE version 7.9.0 (2025-05-15) */ (function () { 'use strict'; var global$7 = tinymce.util.Tools.resolve('tinymce.PluginManager'); /* eslint-disable @typescript-eslint/no-wrapper-object-types */ const hasProto = (v, constructor, predicate) => { var _a; if (predicate(v, constructor.prototype)) { return true; } else { // String-based fallback time return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name; } }; const typeOf = (x) => { const t = typeof x; if (x === null) { return 'null'; } else if (t === 'object' && Array.isArray(x)) { return 'array'; } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) { return 'string'; } else { return t; } }; const isType$1 = (type) => (value) => typeOf(value) === type; const isSimpleType = (type) => (value) => typeof value === type; const isString = isType$1('string'); const isObject = isType$1('object'); const isArray = isType$1('array'); const isBoolean = isSimpleType('boolean'); const isNullable = (a) => a === null || a === undefined; const isNonNullable = (a) => !isNullable(a); const isFunction = isSimpleType('function'); const isNumber = isSimpleType('number'); const noop = () => { }; /** Compose two unary functions. Similar to compose, but avoids using Function.prototype.apply. */ const compose1 = (fbc, fab) => (a) => fbc(fab(a)); const constant = (value) => { return () => { return value; }; }; const tripleEquals = (a, b) => { return a === b; }; // eslint-disable-next-line prefer-arrow/prefer-arrow-functions function curry(fn, ...initialArgs) { return (...restArgs) => { const all = initialArgs.concat(restArgs); return fn.apply(null, all); }; } const not = (f) => (t) => !f(t); const never = constant(false); /** * The `Optional` type represents a value (of any type) that potentially does * not exist. Any `Optional<T>` can either be a `Some<T>` (in which case the * value does exist) or a `None` (in which case the value does not exist). This * module defines a whole lot of FP-inspired utility functions for dealing with * `Optional` objects. * * Comparison with null or undefined: * - We don't get fancy null coalescing operators with `Optional` * - We do get fancy helper functions with `Optional` * - `Optional` support nesting, and allow for the type to still be nullable (or * another `Optional`) * - There is no option to turn off strict-optional-checks like there is for * strict-null-checks */ class Optional { // The internal representation has a `tag` and a `value`, but both are // private: able to be console.logged, but not able to be accessed by code constructor(tag, value) { this.tag = tag; this.value = value; } // --- Identities --- /** * Creates a new `Optional<T>` that **does** contain a value. */ static some(value) { return new Optional(true, value); } /** * Create a new `Optional<T>` that **does not** contain a value. `T` can be * any type because we don't actually have a `T`. */ static none() { return Optional.singletonNone; } /** * Perform a transform on an `Optional` type. Regardless of whether this * `Optional` contains a value or not, `fold` will return a value of type `U`. * If this `Optional` does not contain a value, the `U` will be created by * calling `onNone`. If this `Optional` does contain a value, the `U` will be * created by calling `onSome`. * * For the FP enthusiasts in the room, this function: * 1. Could be used to implement all of the functions below * 2. Forms a catamorphism */ fold(onNone, onSome) { if (this.tag) { return onSome(this.value); } else { return onNone(); } } /** * Determine if this `Optional` object contains a value. */ isSome() { return this.tag; } /** * Determine if this `Optional` object **does not** contain a value. */ isNone() { return !this.tag; } // --- Functor (name stolen from Haskell / maths) --- /** * Perform a transform on an `Optional` object, **if** there is a value. If * you provide a function to turn a T into a U, this is the function you use * to turn an `Optional<T>` into an `Optional<U>`. If this **does** contain * a value then the output will also contain a value (that value being the * output of `mapper(this.value)`), and if this **does not** contain a value * then neither will the output. */ map(mapper) { if (this.tag) { return Optional.some(mapper(this.value)); } else { return Optional.none(); } } // --- Monad (name stolen from Haskell / maths) --- /** * Perform a transform on an `Optional` object, **if** there is a value. * Unlike `map`, here the transform itself also returns an `Optional`. */ bind(binder) { if (this.tag) { return binder(this.value); } else { return Optional.none(); } } // --- Traversable (name stolen from Haskell / maths) --- /** * For a given predicate, this function finds out if there **exists** a value * inside this `Optional` object that meets the predicate. In practice, this * means that for `Optional`s that do not contain a value it returns false (as * no predicate-meeting value exists). */ exists(predicate) { return this.tag && predicate(this.value); } /** * For a given predicate, this function finds out if **all** the values inside * this `Optional` object meet the predicate. In practice, this means that * for `Optional`s that do not contain a value it returns true (as all 0 * objects do meet the predicate). */ forall(predicate) { return !this.tag || predicate(this.value); } filter(predicate) { if (!this.tag || predicate(this.value)) { return this; } else { return Optional.none(); } } // --- Getters --- /** * Get the value out of the inside of the `Optional` object, using a default * `replacement` value if the provided `Optional` object does not contain a * value. */ getOr(replacement) { return this.tag ? this.value : replacement; } /** * Get the value out of the inside of the `Optional` object, using a default * `replacement` value if the provided `Optional` object does not contain a * value. Unlike `getOr`, in this method the `replacement` object is also * `Optional` - meaning that this method will always return an `Optional`. */ or(replacement) { return this.tag ? this : replacement; } /** * Get the value out of the inside of the `Optional` object, using a default * `replacement` value if the provided `Optional` object does not contain a * value. Unlike `getOr`, in this method the `replacement` value is * "thunked" - that is to say that you don't pass a value to `getOrThunk`, you * pass a function which (if called) will **return** the `value` you want to * use. */ getOrThunk(thunk) { return this.tag ? this.value : thunk(); } /** * Get the value out of the inside of the `Optional` object, using a default * `replacement` value if the provided Optional object does not contain a * value. * * Unlike `or`, in this method the `replacement` value is "thunked" - that is * to say that you don't pass a value to `orThunk`, you pass a function which * (if called) will **return** the `value` you want to use. * * Unlike `getOrThunk`, in this method the `replacement` value is also * `Optional`, meaning that this method will always return an `Optional`. */ orThunk(thunk) { return this.tag ? this : thunk(); } /** * Get the value out of the inside of the `Optional` object, throwing an * exception if the provided `Optional` object does not contain a value. * * WARNING: * You should only be using this function if you know that the `Optional` * object **is not** empty (otherwise you're throwing exceptions in production * code, which is bad). * * In tests this is more acceptable. * * Prefer other methods to this, such as `.each`. */ getOrDie(message) { if (!this.tag) { throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None'); } else { return this.value; } } // --- Interop with null and undefined --- /** * Creates an `Optional` value from a nullable (or undefined-able) input. * Null, or undefined, is converted to `None`, and anything else is converted * to `Some`. */ static from(value) { return isNonNullable(value) ? Optional.some(value) : Optional.none(); } /** * Converts an `Optional` to a nullable type, by getting the value if it * exists, or returning `null` if it does not. */ getOrNull() { return this.tag ? this.value : null; } /** * Converts an `Optional` to an undefined-able type, by getting the value if * it exists, or returning `undefined` if it does not. */ getOrUndefined() { return this.value; } // --- Utilities --- /** * If the `Optional` contains a value, perform an action on that value. * Unlike the rest of the methods on this type, `.each` has side-effects. If * you want to transform an `Optional<T>` **into** something, then this is not * the method for you. If you want to use an `Optional<T>` to **do** * something, then this is the method for you - provided you're okay with not * doing anything in the case where the `Optional` doesn't have a value inside * it. If you're not sure whether your use-case fits into transforming * **into** something or **doing** something, check whether it has a return * value. If it does, you should be performing a transform. */ each(worker) { if (this.tag) { worker(this.value); } } /** * Turn the `Optional` object into an array that contains all of the values * stored inside the `Optional`. In practice, this means the output will have * either 0 or 1 elements. */ toArray() { return this.tag ? [this.value] : []; } /** * Turn the `Optional` object into a string for debugging or printing. Not * recommended for production code, but good for debugging. Also note that * these days an `Optional` object can be logged to the console directly, and * its inner value (if it exists) will be visible. */ toString() { return this.tag ? `some(${this.value})` : 'none()'; } } // Sneaky optimisation: every instance of Optional.none is identical, so just // reuse the same object Optional.singletonNone = new Optional(false); /* eslint-disable @typescript-eslint/unbound-method */ const nativeSlice = Array.prototype.slice; const nativeIndexOf = Array.prototype.indexOf; const nativePush = Array.prototype.push; /* eslint-enable */ const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t); const contains$1 = (xs, x) => rawIndexOf(xs, x) > -1; const exists = (xs, pred) => { for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (pred(x, i)) { return true; } } return false; }; const map = (xs, f) => { // pre-allocating array size when it's guaranteed to be known // http://jsperf.com/push-allocated-vs-dynamic/22 const len = xs.length; const r = new Array(len); for (let i = 0; i < len; i++) { const x = xs[i]; r[i] = f(x, i); } return r; }; // Unwound implementing other functions in terms of each. // The code size is roughly the same, and it should allow for better optimisation. // const each = function<T, U>(xs: T[], f: (x: T, i?: number, xs?: T[]) => void): void { const each$1 = (xs, f) => { for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; f(x, i); } }; const filter$1 = (xs, pred) => { const r = []; for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (pred(x, i)) { r.push(x); } } return r; }; /* * Groups an array into contiguous arrays of like elements. Whether an element is like or not depends on f. * * f is a function that derives a value from an element - e.g. true or false, or a string. * Elements are like if this function generates the same value for them (according to ===). * * * Order of the elements is preserved. Arr.flatten() on the result will return the original list, as with Haskell groupBy function. * For a good explanation, see the group function (which is a special case of groupBy) * http://hackage.haskell.org/package/base-4.7.0.0/docs/Data-List.html#v:group */ const groupBy = (xs, f) => { if (xs.length === 0) { return []; } else { let wasType = f(xs[0]); // initial case for matching const r = []; let group = []; for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; const type = f(x); if (type !== wasType) { r.push(group); group = []; } wasType = type; group.push(x); } if (group.length !== 0) { r.push(group); } return r; } }; const foldl = (xs, f, acc) => { each$1(xs, (x, i) => { acc = f(acc, x, i); }); return acc; }; const findUntil = (xs, pred, until) => { for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (pred(x, i)) { return Optional.some(x); } else if (until(x, i)) { break; } } return Optional.none(); }; const find = (xs, pred) => { return findUntil(xs, pred, never); }; const flatten = (xs) => { // Note, this is possible because push supports multiple arguments: // http://jsperf.com/concat-push/6 // Note that in the past, concat() would silently work (very slowly) for array-like objects. // With this change it will throw an error. const r = []; for (let i = 0, len = xs.length; i < len; ++i) { // Ensure that each value is an array itself if (!isArray(xs[i])) { throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs); } nativePush.apply(r, xs[i]); } return r; }; const bind = (xs, f) => flatten(map(xs, f)); const reverse = (xs) => { const r = nativeSlice.call(xs, 0); r.reverse(); return r; }; const get$1 = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none(); const head = (xs) => get$1(xs, 0); const last = (xs) => get$1(xs, xs.length - 1); const unique = (xs, comparator) => { const r = []; const isDuplicated = isFunction(comparator) ? (x) => exists(r, (i) => comparator(i, x)) : (x) => contains$1(r, x); for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (!isDuplicated(x)) { r.push(x); } } return r; }; // There are many variations of Object iteration that are faster than the 'for-in' style: // http://jsperf.com/object-keys-iteration/107 // // Use the native keys if it is available (IE9+), otherwise fall back to manually filtering const keys = Object.keys; const each = (obj, f) => { const props = keys(obj); for (let k = 0, len = props.length; k < len; k++) { const i = props[k]; const x = obj[i]; f(x, i); } }; const objAcc = (r) => (x, i) => { r[i] = x; }; const internalFilter = (obj, pred, onTrue, onFalse) => { each(obj, (x, i) => { (pred(x, i) ? onTrue : onFalse)(x, i); }); }; const filter = (obj, pred) => { const t = {}; internalFilter(obj, pred, objAcc(t), noop); return t; }; const Cell = (initial) => { let value = initial; const get = () => { return value; }; const set = (v) => { value = v; }; return { get, set }; }; // Use window object as the global if it's available since CSP will block script evals // eslint-disable-next-line @typescript-eslint/no-implied-eval const Global = typeof window !== 'undefined' ? window : Function('return this;')(); /** * **Is** the value stored inside this Optional object equal to `rhs`? */ const is$2 = (lhs, rhs, comparator = tripleEquals) => lhs.exists((left) => comparator(left, rhs)); /** * Are these two Optional objects equal? Equality here means either they're both * `Some` (and the values are equal under the comparator) or they're both `None`. */ const equals = (lhs, rhs, comparator = tripleEquals) => lift2(lhs, rhs, comparator).getOr(lhs.isNone() && rhs.isNone()); /* Notes on the lift functions: - We used to have a generic liftN, but we were concerned about its type-safety, and the below variants were faster in microbenchmarks. - The getOrDie calls are partial functions, but are checked beforehand. This is faster and more convenient (but less safe) than folds. - && is used instead of a loop for simplicity and performance. */ const lift2 = (oa, ob, f) => oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none(); /** path :: ([String], JsObj?) -> JsObj */ const path = (parts, scope) => { let o = scope !== undefined && scope !== null ? scope : Global; for (let i = 0; i < parts.length && o !== undefined && o !== null; ++i) { o = o[parts[i]]; } return o; }; /** resolve :: (String, JsObj?) -> JsObj */ const resolve = (p, scope) => { const parts = p.split('.'); return path(parts, scope); }; const blank = (r) => (s) => s.replace(r, ''); /** removes all leading and trailing spaces */ const trim = blank(/^\s+|\s+$/g); const isNotEmpty = (s) => s.length > 0; const isEmpty$2 = (s) => !isNotEmpty(s); const zeroWidth = '\uFEFF'; const isZwsp = (char) => char === zeroWidth; const fromHtml = (html, scope) => { const doc = scope || document; const div = doc.createElement('div'); div.innerHTML = html; if (!div.hasChildNodes() || div.childNodes.length > 1) { const message = 'HTML does not have a single root node'; // eslint-disable-next-line no-console console.error(message, html); throw new Error(message); } return fromDom$1(div.childNodes[0]); }; const fromTag = (tag, scope) => { const doc = scope || document; const node = doc.createElement(tag); return fromDom$1(node); }; const fromText = (text, scope) => { const doc = scope || document; const node = doc.createTextNode(text); return fromDom$1(node); }; const fromDom$1 = (node) => { // TODO: Consider removing this check, but left atm for safety if (node === null || node === undefined) { throw new Error('Node cannot be null or undefined'); } return { dom: node }; }; const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$1); // tslint:disable-next-line:variable-name const SugarElement = { fromHtml, fromTag, fromText, fromDom: fromDom$1, fromPoint }; const COMMENT = 8; const DOCUMENT_FRAGMENT = 11; const ELEMENT = 1; const TEXT = 3; const is$1 = (element, selector) => { const dom = element.dom; if (dom.nodeType !== ELEMENT) { return false; } else { const elem = dom; if (elem.matches !== undefined) { return elem.matches(selector); } else if (elem.msMatchesSelector !== undefined) { return elem.msMatchesSelector(selector); } else if (elem.webkitMatchesSelector !== undefined) { return elem.webkitMatchesSelector(selector); } else if (elem.mozMatchesSelector !== undefined) { // cast to any as mozMatchesSelector doesn't exist in TS DOM lib return elem.mozMatchesSelector(selector); } else { throw new Error('Browser lacks native selectors'); } // unfortunately we can't throw this on startup :( } }; const eq = (e1, e2) => e1.dom === e2.dom; // Returns: true if node e1 contains e2, otherwise false. // (returns false if e1===e2: A node does not contain itself). const contains = (e1, e2) => { const d1 = e1.dom; const d2 = e2.dom; return d1 === d2 ? false : d1.contains(d2); }; const is = is$1; const unsafe = (name, scope) => { return resolve(name, scope); }; const getOrDie = (name, scope) => { const actual = unsafe(name, scope); if (actual === undefined || actual === null) { throw new Error(name + ' not available on this browser'); } return actual; }; const getPrototypeOf = Object.getPrototypeOf; /* * IE9 and above * * MDN no use on this one, but here's the link anyway: * https://developer.mozilla.org/en/docs/Web/API/HTMLElement */ const sandHTMLElement = (scope) => { return getOrDie('HTMLElement', scope); }; const isPrototypeOf = (x) => { // use Resolve to get the window object for x and just return undefined if it can't find it. // undefined scope later triggers using the global window. const scope = resolve('ownerDocument.defaultView', x); // TINY-7374: We can't rely on looking at the owner window HTMLElement as the element may have // been constructed in a different window and then appended to the current window document. return isObject(x) && (sandHTMLElement(scope).prototype.isPrototypeOf(x) || /^HTML\w*Element$/.test(getPrototypeOf(x).constructor.name)); }; const name = (element) => { const r = element.dom.nodeName; return r.toLowerCase(); }; const type = (element) => element.dom.nodeType; const isType = (t) => (element) => type(element) === t; const isComment = (element) => type(element) === COMMENT || name(element) === '#comment'; const isHTMLElement = (element) => isElement$1(element) && isPrototypeOf(element.dom); const isElement$1 = isType(ELEMENT); const isText = isType(TEXT); const isDocumentFragment = isType(DOCUMENT_FRAGMENT); const isTag = (tag) => (e) => isElement$1(e) && name(e) === tag; const parent = (element) => Optional.from(element.dom.parentNode).map(SugarElement.fromDom); const parentElement = (element) => Optional.from(element.dom.parentElement).map(SugarElement.fromDom); const nextSibling = (element) => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom); const children = (element) => map(element.dom.childNodes, SugarElement.fromDom); const child = (element, index) => { const cs = element.dom.childNodes; return Optional.from(cs[index]).map(SugarElement.fromDom); }; const firstChild = (element) => child(element, 0); const lastChild = (element) => child(element, element.dom.childNodes.length - 1); /** * Is the element a ShadowRoot? * * Note: this is insufficient to test if any element is a shadow root, but it is sufficient to differentiate between * a Document and a ShadowRoot. */ const isShadowRoot = (dos) => isDocumentFragment(dos) && isNonNullable(dos.dom.host); const getRootNode = (e) => SugarElement.fromDom(e.dom.getRootNode()); /** If this element is in a ShadowRoot, return it. */ const getShadowRoot = (e) => { const r = getRootNode(e); return isShadowRoot(r) ? Optional.some(r) : Optional.none(); }; /** Return the host of a ShadowRoot. * * This function will throw if Shadow DOM is unsupported in the browser, or if the host is null. * If you actually have a ShadowRoot, this shouldn't happen. */ const getShadowHost = (e) => SugarElement.fromDom(e.dom.host); const before$1 = (marker, element) => { const parent$1 = parent(marker); parent$1.each((v) => { v.dom.insertBefore(element.dom, marker.dom); }); }; const after = (marker, element) => { const sibling = nextSibling(marker); sibling.fold(() => { const parent$1 = parent(marker); parent$1.each((v) => { append$1(v, element); }); }, (v) => { before$1(v, element); }); }; const prepend = (parent, element) => { const firstChild$1 = firstChild(parent); firstChild$1.fold(() => { append$1(parent, element); }, (v) => { parent.dom.insertBefore(element.dom, v.dom); }); }; const append$1 = (parent, element) => { parent.dom.appendChild(element.dom); }; const before = (marker, elements) => { each$1(elements, (x) => { before$1(marker, x); }); }; const append = (parent, elements) => { each$1(elements, (x) => { append$1(parent, x); }); }; const rawSet = (dom, key, value) => { /* * JQuery coerced everything to a string, and silently did nothing on text node/null/undefined. * * We fail on those invalid cases, only allowing numbers and booleans. */ if (isString(value) || isBoolean(value) || isNumber(value)) { dom.setAttribute(key, value + ''); } else { // eslint-disable-next-line no-console console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom); throw new Error('Attribute value was not simple'); } }; const setAll = (element, attrs) => { const dom = element.dom; each(attrs, (v, k) => { rawSet(dom, k, v); }); }; const clone$1 = (element) => foldl(element.dom.attributes, (acc, attr) => { acc[attr.name] = attr.value; return acc; }, {}); const empty = (element) => { // shortcut "empty node" trick. Requires IE 9. element.dom.textContent = ''; // If the contents was a single empty text node, the above doesn't remove it. But, it's still faster in general // than removing every child node manually. // The following is (probably) safe for performance as 99.9% of the time the trick works and // Traverse.children will return an empty array. each$1(children(element), (rogue) => { remove(rogue); }); }; const remove = (element) => { const dom = element.dom; if (dom.parentNode !== null) { dom.parentNode.removeChild(dom); } }; const clone = (original, isDeep) => SugarElement.fromDom(original.dom.cloneNode(isDeep)); /** Deep clone - everything copied including children */ const deep = (original) => clone(original, true); /** Shallow clone, with a new tag */ const shallowAs = (original, tag) => { const nu = SugarElement.fromTag(tag); const attributes = clone$1(original); setAll(nu, attributes); return nu; }; /** Change the tag name, but keep all children */ const mutate = (original, tag) => { const nu = shallowAs(original, tag); after(original, nu); const children$1 = children(original); append(nu, children$1); remove(original); return nu; }; const fromDom = (nodes) => map(nodes, SugarElement.fromDom); // some elements, such as mathml, don't have style attributes // others, such as angular elements, have style attributes that aren't a CSSStyleDeclaration const isSupported = (dom) => // eslint-disable-next-line @typescript-eslint/unbound-method dom.style !== undefined && isFunction(dom.style.getPropertyValue); // Node.contains() is very, very, very good performance // http://jsperf.com/closest-vs-contains/5 const inBody = (element) => { // Technically this is only required on IE, where contains() returns false for text nodes. // But it's cheap enough to run everywhere and Sugar doesn't have platform detection (yet). const dom = isText(element) ? element.dom.parentNode : element.dom; // use ownerDocument.body to ensure this works inside iframes. // Normally contains is bad because an element "contains" itself, but here we want that. if (dom === undefined || dom === null || dom.ownerDocument === null) { return false; } const doc = dom.ownerDocument; return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost)); }; const internalSet = (dom, property, value) => { // This is going to hurt. Apologies. // JQuery coerces numbers to pixels for certain property names, and other times lets numbers through. // we're going to be explicit; strings only. if (!isString(value)) { // eslint-disable-next-line no-console console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom); throw new Error('CSS value must be a string: ' + value); } // removed: support for dom().style[property] where prop is camel case instead of normal property name if (isSupported(dom)) { dom.style.setProperty(property, value); } }; const set = (element, property, value) => { const dom = element.dom; internalSet(dom, property, value); }; const fromElements = (elements, scope) => { const doc = scope || document; const fragment = doc.createDocumentFragment(); each$1(elements, (element) => { fragment.appendChild(element.dom); }); return SugarElement.fromDom(fragment); }; var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => { if (is(scope, a)) { return Optional.some(scope); } else if (isFunction(isRoot) && isRoot(scope)) { return Optional.none(); } else { return ancestor(scope, a, isRoot); } }; const ancestor$3 = (scope, predicate, isRoot) => { let element = scope.dom; const stop = isFunction(isRoot) ? isRoot : never; while (element.parentNode) { element = element.parentNode; const el = SugarElement.fromDom(element); if (predicate(el)) { return Optional.some(el); } else if (stop(el)) { break; } } return Optional.none(); }; const closest$2 = (scope, predicate, isRoot) => { // This is required to avoid ClosestOrAncestor passing the predicate to itself const is = (s, test) => test(s); return ClosestOrAncestor(is, ancestor$3, scope, predicate, isRoot); }; const ancestor$2 = (scope, selector, isRoot) => ancestor$3(scope, (e) => is$1(e, selector), isRoot); // Returns Some(closest ancestor element (sugared)) matching 'selector' up to isRoot, or None() otherwise const closest$1 = (scope, selector, isRoot) => { const is = (element, selector) => is$1(element, selector); return ClosestOrAncestor(is, ancestor$2, scope, selector, isRoot); }; const closest = (target) => closest$1(target, '[contenteditable]'); const isEditable = (element, assumeEditable = false) => { if (inBody(element)) { return element.dom.isContentEditable; } else { // Find the closest contenteditable element and check if it's editable return closest(element).fold(constant(assumeEditable), (editable) => getRaw(editable) === 'true'); } }; const getRaw = (element) => element.dom.contentEditable; const ancestor$1 = (scope, predicate, isRoot) => ancestor$3(scope, predicate, isRoot).isSome(); const ancestor = (element, target) => ancestor$1(element, curry(eq, target)); var global$6 = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils'); var global$5 = tinymce.util.Tools.resolve('tinymce.dom.TreeWalker'); var global$4 = tinymce.util.Tools.resolve('tinymce.util.VK'); var global$3 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils'); var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools'); const matchNodeName = (name) => (node) => isNonNullable(node) && node.nodeName.toLowerCase() === name; const matchNodeNames = (regex) => (node) => isNonNullable(node) && regex.test(node.nodeName); const isTextNode$1 = (node) => isNonNullable(node) && node.nodeType === 3; const isElement = (node) => isNonNullable(node) && node.nodeType === 1; const isListNode = matchNodeNames(/^(OL|UL|DL)$/); const isOlUlNode = matchNodeNames(/^(OL|UL)$/); const isOlNode = matchNodeName('ol'); const isListItemNode = matchNodeNames(/^(LI|DT|DD)$/); const isDlItemNode = matchNodeNames(/^(DT|DD)$/); const isTableCellNode = matchNodeNames(/^(TH|TD)$/); const isBr = matchNodeName('br'); const isFirstChild = (node) => { var _a; return ((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild) === node; }; const isTextBlock = (editor, node) => isNonNullable(node) && node.nodeName in editor.schema.getTextBlockElements(); const isBlock = (node, blockElements) => isNonNullable(node) && node.nodeName in blockElements; const isVoid = (editor, node) => isNonNullable(node) && node.nodeName in editor.schema.getVoidElements(); const isBogusBr = (dom, node) => { if (!isBr(node)) { return false; } return dom.isBlock(node.nextSibling) && !isBr(node.previousSibling); }; const isEmpty$1 = (dom, elm, keepBookmarks) => { const empty = dom.isEmpty(elm); if (keepBookmarks && dom.select('span[data-mce-type=bookmark]', elm).length > 0) { return false; } return empty; }; const isChildOfBody = (dom, elm) => dom.isChildOf(elm, dom.getRoot()); const option = (name) => (editor) => editor.options.get(name); const register$3 = (editor) => { const registerOption = editor.options.register; registerOption('lists_indent_on_tab', { processor: 'boolean', default: true }); }; const shouldIndentOnTab = option('lists_indent_on_tab'); const getForcedRootBlock = option('forced_root_block'); const getForcedRootBlockAttrs = option('forced_root_block_attrs'); const createTextBlock = (editor, contentNode, attrs = {}) => { const dom = editor.dom; const blockElements = editor.schema.getBlockElements(); const fragment = dom.createFragment(); const blockName = getForcedRootBlock(editor); const blockAttrs = getForcedRootBlockAttrs(editor); let node; let textBlock; let hasContentNode = false; textBlock = dom.create(blockName, { ...blockAttrs, ...(attrs.style ? { style: attrs.style } : {}) }); if (!isBlock(contentNode.firstChild, blockElements)) { fragment.appendChild(textBlock); } while ((node = contentNode.firstChild)) { const nodeName = node.nodeName; if (!hasContentNode && (nodeName !== 'SPAN' || node.getAttribute('data-mce-type') !== 'bookmark')) { hasContentNode = true; } if (isBlock(node, blockElements)) { fragment.appendChild(node); textBlock = null; } else { if (!textBlock) { textBlock = dom.create(blockName, blockAttrs); fragment.appendChild(textBlock); } textBlock.appendChild(node); } } // BR is needed in empty blocks if (!hasContentNode && textBlock) { textBlock.appendChild(dom.create('br', { 'data-mce-bogus': '1' })); } return fragment; }; const DOM$2 = global$3.DOM; const splitList = (editor, list, li) => { const removeAndKeepBookmarks = (targetNode) => { const parent = targetNode.parentNode; if (parent) { global$2.each(bookmarks, (node) => { parent.insertBefore(node, li.parentNode); }); } DOM$2.remove(targetNode); }; const bookmarks = DOM$2.select('span[data-mce-type="bookmark"]', list); const newBlock = createTextBlock(editor, li); const tmpRng = DOM$2.createRng(); tmpRng.setStartAfter(li); tmpRng.setEndAfter(list); const fragment = tmpRng.extractContents(); for (let node = fragment.firstChild; node; node = node.firstChild) { if (node.nodeName === 'LI' && editor.dom.isEmpty(node)) { DOM$2.remove(node); break; } } if (!editor.dom.isEmpty(fragment)) { DOM$2.insertAfter(fragment, list); } DOM$2.insertAfter(newBlock, list); const parent = li.parentElement; if (parent && isEmpty$1(editor.dom, parent)) { removeAndKeepBookmarks(parent); } DOM$2.remove(li); if (isEmpty$1(editor.dom, list)) { DOM$2.remove(list); } }; const isDescriptionDetail = isTag('dd'); const isDescriptionTerm = isTag('dt'); const outdentDlItem = (editor, item) => { if (isDescriptionDetail(item)) { mutate(item, 'dt'); } else if (isDescriptionTerm(item)) { parentElement(item).each((dl) => splitList(editor, dl.dom, item.dom)); } }; const indentDlItem = (item) => { if (isDescriptionTerm(item)) { mutate(item, 'dd'); } }; const dlIndentation = (editor, indentation, dlItems) => { if (indentation === "Indent" /* Indentation.Indent */) { each$1(dlItems, indentDlItem); } else { each$1(dlItems, (item) => outdentDlItem(editor, item)); } }; const getNormalizedPoint = (container, offset) => { if (isTextNode$1(container)) { return { container, offset }; } const node = global$6.getNode(container, offset); if (isTextNode$1(node)) { return { container: node, offset: offset >= container.childNodes.length ? node.data.length : 0 }; } else if (node.previousSibling && isTextNode$1(node.previousSibling)) { return { container: node.previousSibling, offset: node.previousSibling.data.length }; } else if (node.nextSibling && isTextNode$1(node.nextSibling)) { return { container: node.nextSibling, offset: 0 }; } return { container, offset }; }; const normalizeRange = (rng) => { const outRng = rng.cloneRange(); const rangeStart = getNormalizedPoint(rng.startContainer, rng.startOffset); outRng.setStart(rangeStart.container, rangeStart.offset); const rangeEnd = getNormalizedPoint(rng.endContainer, rng.endOffset); outRng.setEnd(rangeEnd.container, rangeEnd.offset); return outRng; }; const listNames = ['OL', 'UL', 'DL']; const listSelector = listNames.join(','); const getParentList = (editor, node) => { const selectionStart = node || editor.selection.getStart(true); return editor.dom.getParent(selectionStart, listSelector, getClosestListHost(editor, selectionStart)); }; const isParentListSelected = (parentList, selectedBlocks) => isNonNullable(parentList) && selectedBlocks.length === 1 && selectedBlocks[0] === parentList; const findSubLists = (parentList) => filter$1(parentList.querySelectorAll(listSelector), isListNode); const getSelectedSubLists = (editor) => { const parentList = getParentList(editor); const selectedBlocks = editor.selection.getSelectedBlocks(); if (isParentListSelected(parentList, selectedBlocks)) { return findSubLists(parentList); } else { return filter$1(selectedBlocks, (elm) => { return isListNode(elm) && parentList !== elm; }); } }; const findParentListItemsNodes = (editor, elms) => { const listItemsElms = global$2.map(elms, (elm) => { const parentLi = editor.dom.getParent(elm, 'li,dd,dt', getClosestListHost(editor, elm)); return parentLi ? parentLi : elm; }); return unique(listItemsElms); }; const getSelectedListItems = (editor) => { const selectedBlocks = editor.selection.getSelectedBlocks(); return filter$1(findParentListItemsNodes(editor, selectedBlocks), isListItemNode); }; const getSelectedDlItems = (editor) => filter$1(getSelectedListItems(editor), isDlItemNode); const getClosestEditingHost = (editor, elm) => { const parentTableCell = editor.dom.getParents(elm, 'TD,TH'); return parentTableCell.length > 0 ? parentTableCell[0] : editor.getBody(); }; const isListHost = (schema, node) => !isListNode(node) && !isListItemNode(node) && exists(listNames, (listName) => schema.isValidChild(node.nodeName, listName)); const getClosestListHost = (editor, elm) => { const parentBlocks = editor.dom.getParents(elm, editor.dom.isBlock); const isNotForcedRootBlock = (elm) => elm.nodeName.toLowerCase() !== getForcedRootBlock(editor); const parentBlock = find(parentBlocks, (elm) => isNotForcedRootBlock(elm) && isListHost(editor.schema, elm)); return parentBlock.getOr(editor.getBody()); }; const isListInsideAnLiWithFirstAndLastNotListElement = (list) => parent(list).exists((parent) => isListItemNode(parent.dom) && firstChild(parent).exists((firstChild) => !isListNode(firstChild.dom)) && lastChild(parent).exists((lastChild) => !isListNode(lastChild.dom))); const findLastParentListNode = (editor, elm) => { const parentLists = editor.dom.getParents(elm, 'ol,ul', getClosestListHost(editor, elm)); return last(parentLists); }; const getSelectedLists = (editor) => { const firstList = findLastParentListNode(editor, editor.selection.getStart()); const subsequentLists = filter$1(editor.selection.getSelectedBlocks(), isOlUlNode); return firstList.toArray().concat(subsequentLists); }; const getParentLists = (editor) => { const elm = editor.selection.getStart(); return editor.dom.getParents(elm, 'ol,ul', getClosestListHost(editor, elm)); }; const getSelectedListRoots = (editor) => { const selectedLists = getSelectedLists(editor); const parentLists = getParentLists(editor); return find(parentLists, (p) => isListInsideAnLiWithFirstAndLastNotListElement(SugarElement.fromDom(p))).fold(() => getUniqueListRoots(editor, selectedLists), (l) => [l]); }; const getUniqueListRoots = (editor, lists) => { const listRoots = map(lists, (list) => findLastParentListNode(editor, list).getOr(list)); return unique(listRoots); }; const isCustomList = (list) => /\btox\-/.test(list.className); const inList = (parents, listName) => findUntil(parents, isListNode, isTableCellNode) .exists((list) => list.nodeName === listName && !isCustomList(list)); // Advlist/core/ListUtils.ts - Duplicated in Advlist plugin const isWithinNonEditable = (editor, element) => element !== null && !editor.dom.isEditable(element); const selectionIsWithinNonEditableList = (editor) => { const parentList = getParentList(editor); return isWithinNonEditable(editor, parentList) || !editor.selection.isEditable(); }; const isWithinNonEditableList = (editor, element) => { const parentList = editor.dom.getParent(element, 'ol,ul,dl'); return isWithinNonEditable(editor, parentList) || !editor.selection.isEditable(); }; const setNodeChangeHandler = (editor, nodeChangeHandler) => { const initialNode = editor.selection.getNode(); // Set the initial state nodeChangeHandler({ parents: editor.dom.getParents(initialNode), element: initialNode }); editor.on('NodeChange', nodeChangeHandler); return () => editor.off('NodeChange', nodeChangeHandler); }; const fireListEvent = (editor, action, element) => editor.dispatch('ListMutation', { action, element }); const isList = (el) => is(el, 'OL,UL'); const isListItem = (el) => is(el, 'LI'); const hasFirstChildList = (el) => firstChild(el).exists(isList); const hasLastChildList = (el) => lastChild(el).exists(isList); const isEntryList = (entry) => 'listAttributes' in entry; const isEntryComment = (entry) => 'isComment' in entry; const isEntryFragment = (entry) => 'isFragment' in entry; const isIndented = (entry) => entry.depth > 0; const isSelected = (entry) => entry.isSelected; const cloneItemContent = (li) => { const children$1 = children(li); const content = hasLastChildList(li) ? children$1.slice(0, -1) : children$1; return map(content, deep); }; const createEntry = (li, depth, isSelected) => parent(li).filter(isElement$1).map((list) => ({ depth, dirty: false, isSelected, content: cloneItemContent(li), itemAttributes: clone$1(li), listAttributes: clone$1(list), listType: name(list), isInPreviousLi: false })); const joinSegment = (parent, child) => { append$1(parent.item, child.list); }; const joinSegments = (segments) => { for (let i = 1; i < segments.length; i++) { joinSegment(segments[i - 1], segments[i]); } }; const appendSegments = (head$1, tail) => { lift2(last(head$1), head(tail), joinSegment); }; const createSegment = (scope, listType) => { const segment = { list: SugarElement.fromTag(listType, scope), item: SugarElement.fromTag('li', scope) }; append$1(segment.list, segment.item); return segment; }; const createSegments = (scope, entry, size) => { const segments = []; for (let i = 0; i < size; i++) { segments.push(createSegment(scope, isEntryList(entry) ? entry.listType : entry.parentListType)); } return segments; }; const populateSegments = (segments, entry) => { for (let i = 0; i < segments.length - 1; i++) { set(segments[i].item, 'list-style-type', 'none'); } last(segments).each((segment) => { if (isEntryList(entry)) {