UNPKG

slate

Version:

A completely customizable framework for building rich text editors.

1,300 lines (1,250 loc) 328 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Slate = {})); })(this, (function (exports) { 'use strict'; // eslint-disable-next-line no-redeclare var PathRef = { transform: function transform(ref, op) { var current = ref.current, affinity = ref.affinity; if (current == null) { return; } var path = Path.transform(current, op, { affinity: affinity }); ref.current = path; if (path == null) { ref.unref(); } } }; // eslint-disable-next-line no-redeclare var PointRef = { transform: function transform(ref, op) { var current = ref.current, affinity = ref.affinity; if (current == null) { return; } var point = Point.transform(current, op, { affinity: affinity }); ref.current = point; if (point == null) { ref.unref(); } } }; // eslint-disable-next-line no-redeclare var RangeRef = { transform: function transform(ref, op) { var current = ref.current, affinity = ref.affinity; if (current == null) { return; } var path = Range.transform(current, op, { affinity: affinity }); ref.current = path; if (path == null) { ref.unref(); } } }; var DIRTY_PATHS = new WeakMap(); var DIRTY_PATH_KEYS = new WeakMap(); var FLUSHING = new WeakMap(); var NORMALIZING = new WeakMap(); var PATH_REFS = new WeakMap(); var POINT_REFS = new WeakMap(); var RANGE_REFS = new WeakMap(); function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var arrayLikeToArray = createCommonjsModule(function (module) { function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(arrayLikeToArray); var arrayWithoutHoles = createCommonjsModule(function (module) { function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return arrayLikeToArray(arr); } module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(arrayWithoutHoles); var iterableToArray = createCommonjsModule(function (module) { function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } module.exports = _iterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(iterableToArray); var unsupportedIterableToArray = createCommonjsModule(function (module) { function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen); } module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(unsupportedIterableToArray); var nonIterableSpread = createCommonjsModule(function (module) { function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } module.exports = _nonIterableSpread, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(nonIterableSpread); var toConsumableArray = createCommonjsModule(function (module) { function _toConsumableArray(arr) { return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread(); } module.exports = _toConsumableArray, module.exports.__esModule = true, module.exports["default"] = module.exports; }); var _toConsumableArray = unwrapExports(toConsumableArray); // eslint-disable-next-line no-redeclare var Path = { ancestors: function ancestors(path) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var _options$reverse = options.reverse, reverse = _options$reverse === void 0 ? false : _options$reverse; var paths = Path.levels(path, options); if (reverse) { paths = paths.slice(1); } else { paths = paths.slice(0, -1); } return paths; }, common: function common(path, another) { var common = []; for (var i = 0; i < path.length && i < another.length; i++) { var av = path[i]; var bv = another[i]; if (av !== bv) { break; } common.push(av); } return common; }, compare: function compare(path, another) { var min = Math.min(path.length, another.length); for (var i = 0; i < min; i++) { if (path[i] < another[i]) return -1; if (path[i] > another[i]) return 1; } return 0; }, endsAfter: function endsAfter(path, another) { var i = path.length - 1; var as = path.slice(0, i); var bs = another.slice(0, i); var av = path[i]; var bv = another[i]; return Path.equals(as, bs) && av > bv; }, endsAt: function endsAt(path, another) { var i = path.length; var as = path.slice(0, i); var bs = another.slice(0, i); return Path.equals(as, bs); }, endsBefore: function endsBefore(path, another) { var i = path.length - 1; var as = path.slice(0, i); var bs = another.slice(0, i); var av = path[i]; var bv = another[i]; return Path.equals(as, bs) && av < bv; }, equals: function equals(path, another) { return path.length === another.length && path.every(function (n, i) { return n === another[i]; }); }, hasPrevious: function hasPrevious(path) { return path[path.length - 1] > 0; }, isAfter: function isAfter(path, another) { return Path.compare(path, another) === 1; }, isAncestor: function isAncestor(path, another) { return path.length < another.length && Path.compare(path, another) === 0; }, isBefore: function isBefore(path, another) { return Path.compare(path, another) === -1; }, isChild: function isChild(path, another) { return path.length === another.length + 1 && Path.compare(path, another) === 0; }, isCommon: function isCommon(path, another) { return path.length <= another.length && Path.compare(path, another) === 0; }, isDescendant: function isDescendant(path, another) { return path.length > another.length && Path.compare(path, another) === 0; }, isParent: function isParent(path, another) { return path.length + 1 === another.length && Path.compare(path, another) === 0; }, isPath: function isPath(value) { return Array.isArray(value) && (value.length === 0 || typeof value[0] === 'number'); }, isSibling: function isSibling(path, another) { if (path.length !== another.length) { return false; } var as = path.slice(0, -1); var bs = another.slice(0, -1); var al = path[path.length - 1]; var bl = another[another.length - 1]; return al !== bl && Path.equals(as, bs); }, levels: function levels(path) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var _options$reverse2 = options.reverse, reverse = _options$reverse2 === void 0 ? false : _options$reverse2; var list = []; for (var i = 0; i <= path.length; i++) { list.push(path.slice(0, i)); } if (reverse) { list.reverse(); } return list; }, next: function next(path) { if (path.length === 0) { throw new Error("Cannot get the next path of a root path [".concat(path, "], because it has no next index.")); } var last = path[path.length - 1]; return path.slice(0, -1).concat(last + 1); }, operationCanTransformPath: function operationCanTransformPath(operation) { switch (operation.type) { case 'insert_node': case 'remove_node': case 'merge_node': case 'split_node': case 'move_node': return true; default: return false; } }, parent: function parent(path) { if (path.length === 0) { throw new Error("Cannot get the parent path of the root path [".concat(path, "].")); } return path.slice(0, -1); }, previous: function previous(path) { if (path.length === 0) { throw new Error("Cannot get the previous path of a root path [".concat(path, "], because it has no previous index.")); } var last = path[path.length - 1]; if (last <= 0) { throw new Error("Cannot get the previous path of a first child path [".concat(path, "] because it would result in a negative index.")); } return path.slice(0, -1).concat(last - 1); }, relative: function relative(path, ancestor) { if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) { throw new Error("Cannot get the relative path of [".concat(path, "] inside ancestor [").concat(ancestor, "], because it is not above or equal to the path.")); } return path.slice(ancestor.length); }, transform: function transform(path, operation) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!path) return null; // PERF: use destructing instead of immer var p = _toConsumableArray(path); var _options$affinity = options.affinity, affinity = _options$affinity === void 0 ? 'forward' : _options$affinity; // PERF: Exit early if the operation is guaranteed not to have an effect. if (path.length === 0) { return p; } switch (operation.type) { case 'insert_node': { var op = operation.path; if (Path.equals(op, p) || Path.endsBefore(op, p) || Path.isAncestor(op, p)) { p[op.length - 1] += 1; } break; } case 'remove_node': { var _op = operation.path; if (Path.equals(_op, p) || Path.isAncestor(_op, p)) { return null; } else if (Path.endsBefore(_op, p)) { p[_op.length - 1] -= 1; } break; } case 'merge_node': { var _op2 = operation.path, position = operation.position; if (Path.equals(_op2, p) || Path.endsBefore(_op2, p)) { p[_op2.length - 1] -= 1; } else if (Path.isAncestor(_op2, p)) { p[_op2.length - 1] -= 1; p[_op2.length] += position; } break; } case 'split_node': { var _op3 = operation.path, _position = operation.position; if (Path.equals(_op3, p)) { if (affinity === 'forward') { p[p.length - 1] += 1; } else if (affinity === 'backward') ; else { return null; } } else if (Path.endsBefore(_op3, p)) { p[_op3.length - 1] += 1; } else if (Path.isAncestor(_op3, p) && path[_op3.length] >= _position) { p[_op3.length - 1] += 1; p[_op3.length] -= _position; } break; } case 'move_node': { var _op4 = operation.path, onp = operation.newPath; // If the old and new path are the same, it's a no-op. if (Path.equals(_op4, onp)) { return p; } if (Path.isAncestor(_op4, p) || Path.equals(_op4, p)) { var copy = onp.slice(); if (Path.endsBefore(_op4, onp) && _op4.length < onp.length) { copy[_op4.length - 1] -= 1; } return copy.concat(p.slice(_op4.length)); } else if (Path.isSibling(_op4, onp) && (Path.isAncestor(onp, p) || Path.equals(onp, p))) { if (Path.endsBefore(_op4, p)) { p[_op4.length - 1] -= 1; } else { p[_op4.length - 1] += 1; } } else if (Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p)) { if (Path.endsBefore(_op4, p)) { p[_op4.length - 1] -= 1; } p[onp.length - 1] += 1; } else if (Path.endsBefore(_op4, p)) { if (Path.equals(onp, p)) { p[onp.length - 1] += 1; } p[_op4.length - 1] -= 1; } break; } } return p; } }; var _typeof_1 = createCommonjsModule(function (module) { function _typeof(o) { "@babel/helpers - typeof"; return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(o); } module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports; }); var _typeof = unwrapExports(_typeof_1); var toPrimitive = createCommonjsModule(function (module) { var _typeof = _typeof_1["default"]; function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } module.exports = _toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(toPrimitive); var toPropertyKey = createCommonjsModule(function (module) { var _typeof = _typeof_1["default"]; function _toPropertyKey(arg) { var key = toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } module.exports = _toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(toPropertyKey); var defineProperty = createCommonjsModule(function (module) { function _defineProperty(obj, key, value) { key = toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports; }); var _defineProperty = unwrapExports(defineProperty); var arrayWithHoles = createCommonjsModule(function (module) { function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(arrayWithHoles); var iterableToArrayLimit = createCommonjsModule(function (module) { function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } module.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(iterableToArrayLimit); var nonIterableRest = createCommonjsModule(function (module) { function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } module.exports = _nonIterableRest, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(nonIterableRest); var slicedToArray = createCommonjsModule(function (module) { function _slicedToArray(arr, i) { return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest(); } module.exports = _slicedToArray, module.exports.__esModule = true, module.exports["default"] = module.exports; }); var _slicedToArray = unwrapExports(slicedToArray); var objectWithoutPropertiesLoose = createCommonjsModule(function (module) { function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(objectWithoutPropertiesLoose); var objectWithoutProperties = createCommonjsModule(function (module) { function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } module.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports["default"] = module.exports; }); var _objectWithoutProperties = unwrapExports(objectWithoutProperties); var regeneratorRuntime$1 = createCommonjsModule(function (module) { var _typeof = _typeof_1["default"]; function _regeneratorRuntime() { module.exports = _regeneratorRuntime = function _regeneratorRuntime() { return e; }, module.exports.__esModule = true, module.exports["default"] = module.exports; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports; }); unwrapExports(regeneratorRuntime$1); // TODO(Babel 8): Remove this file. var runtime = regeneratorRuntime$1(); var regenerator = runtime; // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736= try { regeneratorRuntime = runtime; } catch (accidentalStrictMode) { if (typeof globalThis === "object") { globalThis.regeneratorRuntime = runtime; } else { Function("r", "regeneratorRuntime = r")(runtime); } } var _excluded$4 = ["anchor", "focus"]; function ownKeys$g(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread$g(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$g(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$g(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // eslint-disable-next-line no-redeclare var Range = { edges: function edges(range) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var _options$reverse = options.reverse, reverse = _options$reverse === void 0 ? false : _options$reverse; var anchor = range.anchor, focus = range.focus; return Range.isBackward(range) === reverse ? [anchor, focus] : [focus, anchor]; }, end: function end(range) { var _Range$edges = Range.edges(range), _Range$edges2 = _slicedToArray(_Range$edges, 2), end = _Range$edges2[1]; return end; }, equals: function equals(range, another) { return Point.equals(range.anchor, another.anchor) && Point.equals(range.focus, another.focus); }, surrounds: function surrounds(range, target) { var intersectionRange = Range.intersection(range, target); if (!intersectionRange) { return false; } return Range.equals(intersectionRange, target); }, includes: function includes(range, target) { if (Range.isRange(target)) { if (Range.includes(range, target.anchor) || Range.includes(range, target.focus)) { return true; } var _Range$edges3 = Range.edges(range), _Range$edges4 = _slicedToArray(_Range$edges3, 2), rs = _Range$edges4[0], re = _Range$edges4[1]; var _Range$edges5 = Range.edges(target), _Range$edges6 = _slicedToArray(_Range$edges5, 2), ts = _Range$edges6[0], te = _Range$edges6[1]; return Point.isBefore(rs, ts) && Point.isAfter(re, te); } var _Range$edges7 = Range.edges(range), _Range$edges8 = _slicedToArray(_Range$edges7, 2), start = _Range$edges8[0], end = _Range$edges8[1]; var isAfterStart = false; var isBeforeEnd = false; if (Point.isPoint(target)) { isAfterStart = Point.compare(target, start) >= 0; isBeforeEnd = Point.compare(target, end) <= 0; } else { isAfterStart = Path.compare(target, start.path) >= 0; isBeforeEnd = Path.compare(target, end.path) <= 0; } return isAfterStart && isBeforeEnd; }, intersection: function intersection(range, another) { range.anchor; range.focus; var rest = _objectWithoutProperties(range, _excluded$4); var _Range$edges9 = Range.edges(range), _Range$edges10 = _slicedToArray(_Range$edges9, 2), s1 = _Range$edges10[0], e1 = _Range$edges10[1]; var _Range$edges11 = Range.edges(another), _Range$edges12 = _slicedToArray(_Range$edges11, 2), s2 = _Range$edges12[0], e2 = _Range$edges12[1]; var start = Point.isBefore(s1, s2) ? s2 : s1; var end = Point.isBefore(e1, e2) ? e1 : e2; if (Point.isBefore(end, start)) { return null; } else { return _objectSpread$g({ anchor: start, focus: end }, rest); } }, isBackward: function isBackward(range) { var anchor = range.anchor, focus = range.focus; return Point.isAfter(anchor, focus); }, isCollapsed: function isCollapsed(range) { var anchor = range.anchor, focus = range.focus; return Point.equals(anchor, focus); }, isExpanded: function isExpanded(range) { return !Range.isCollapsed(range); }, isForward: function isForward(range) { return !Range.isBackward(range); }, isRange: function isRange(value) { return isObject(value) && Point.isPoint(value.anchor) && Point.isPoint(value.focus); }, points: /*#__PURE__*/regenerator.mark(function points(range) { return regenerator.wrap(function points$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.next = 2; return [range.anchor, 'anchor']; case 2: _context.next = 4; return [range.focus, 'focus']; case 4: case "end": return _context.stop(); } }, points); }), start: function start(range) { var _Range$edges13 = Range.edges(range), _Range$edges14 = _slicedToArray(_Range$edges13, 1), start = _Range$edges14[0]; return start; }, transform: function transform(range, op) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (range === null) { return null; } var _options$affinity = options.affinity, affinity = _options$affinity === void 0 ? 'inward' : _options$affinity; var affinityAnchor; var affinityFocus; if (affinity === 'inward') { // If the range is collapsed, make sure to use the same affinity to // avoid the two points passing each other and expanding in the opposite // direction var isCollapsed = Range.isCollapsed(range); if (Range.isForward(range)) { affinityAnchor = 'forward'; affinityFocus = isCollapsed ? affinityAnchor : 'backward'; } else { affinityAnchor = 'backward'; affinityFocus = isCollapsed ? affinityAnchor : 'forward'; } } else if (affinity === 'outward') { if (Range.isForward(range)) { affinityAnchor = 'backward'; affinityFocus = 'forward'; } else { affinityAnchor = 'forward'; affinityFocus = 'backward'; } } else { affinityAnchor = affinity; affinityFocus = affinity; } var anchor = Point.transform(range.anchor, op, { affinity: affinityAnchor }); var focus = Point.transform(range.focus, op, { affinity: affinityFocus }); if (!anchor || !focus) { return null; } return { anchor: anchor, focus: focus }; } }; /** * Shared the function with isElementType utility */ var isElement = function isElement(value) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref$deep = _ref.deep, deep = _ref$deep === void 0 ? false : _ref$deep; if (!isObject(value)) return false; // PERF: No need to use the full Editor.isEditor here var isEditor = typeof value.apply === 'function'; if (isEditor) return false; var isChildrenValid = deep ? Node.isNodeList(value.children) : Array.isArray(value.children); return isChildrenValid; }; // eslint-disable-next-line no-redeclare var Element = { isAncestor: function isAncestor(value) { var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref2$deep = _ref2.deep, deep = _ref2$deep === void 0 ? false : _ref2$deep; return isObject(value) && Node.isNodeList(value.children, { deep: deep }); }, isElement: isElement, isElementList: function isElementList(value) { var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref3$deep = _ref3.deep, deep = _ref3$deep === void 0 ? false : _ref3$deep; return Array.isArray(value) && value.every(function (val) { return Element.isElement(val, { deep: deep }); }); }, isElementProps: function isElementProps(props) { return props.children !== undefined; }, isElementType: function isElementType(value, elementVal) { var elementKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'type'; return isElement(value) && value[elementKey] === elementVal; }, matches: function matches(element, props) { for (var key in props) { if (key === 'children') { continue; } if (element[key] !== props[key]) { return false; } } return true; } }; var _excluded$3 = ["children"], _excluded2$3 = ["text"]; function ownKeys$f(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread$f(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$f(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$f(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _createForOfIteratorHelper$l(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$l(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray$l(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$l(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$l(o, minLen); } function _arrayLikeToArray$l(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } // eslint-disable-next-line no-redeclare var Node = { ancestor: function ancestor(root, path) { var node = Node.get(root, path); if (Text.isText(node)) { throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(Scrubber.stringify(node))); } return node; }, ancestors: function ancestors(root, path) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return /*#__PURE__*/regenerator.mark(function _callee() { var _iterator, _step, p, n, entry; return regenerator.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _iterator = _createForOfIteratorHelper$l(Path.ancestors(path, options)); _context.prev = 1; _iterator.s(); case 3: if ((_step = _iterator.n()).done) { _context.next = 11; break; } p = _step.value; n = Node.ancestor(root, p); entry = [n, p]; _context.next = 9; return entry; case 9: _context.next = 3; break; case 11: _context.next = 16; break; case 13: _context.prev = 13; _context.t0 = _context["catch"](1); _iterator.e(_context.t0); case 16: _context.prev = 16; _iterator.f(); return _context.finish(16); case 19: case "end": return _context.stop(); } }, _callee, null, [[1, 13, 16, 19]]); })(); }, child: function child(root, index) { if (Text.isText(root)) { throw new Error("Cannot get the child of a text node: ".concat(Scrubber.stringify(root))); } var c = root.children[index]; if (c == null) { throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(Scrubber.stringify(root))); } return c; }, children: function children(root, path) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return /*#__PURE__*/regenerator.mark(function _callee2() { var _options$reverse, reverse, ancestor, children, index, child, childPath; return regenerator.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _options$reverse = options.reverse, reverse = _options$reverse === void 0 ? false : _options$reverse; ancestor = Node.ancestor(root, path); children = ancestor.children; index = reverse ? children.length - 1 : 0; case 4: if (!(reverse ? index >= 0 : index < children.length)) { _context2.next = 12; break; } child = Node.child(ancestor, index); childPath = path.concat(index); _context2.next = 9; return [child, childPath]; case 9: index = reverse ? index - 1 : index + 1; _context2.next = 4; break; case 12: case "end": return _context2.stop(); } }, _callee2); })(); }, common: function common(root, path, another) { var p = Path.common(path, another); var n = Node.get(root, p); return [n, p]; }, descendant: function descendant(root, path) { var node = Node.get(root, path); if (Editor.isEditor(node)) { throw new Error("Cannot get the descendant node at path [".concat(path, "] because it refers to the root editor node instead: ").concat(Scrubber.stringify(node))); } return node; }, descendants: function descendants(root) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return /*#__PURE__*/regenerator.mark(function _callee3() { var _iterator2, _step2, _step2$value, node, path; return regenerator.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _iterator2 = _createForOfIteratorHelper$l(Node.nodes(root, options)); _context3.prev = 1; _iterator2.s(); case 3: if ((_step2 = _iterator2.n()).done) { _context3.next = 10; break; } _step2$value = _slicedToArray(_step2.value, 2), node = _step2$value[0], path = _step2$value[1]; if (!(path.length !== 0)) { _context3.next = 8; break; } _context3.next = 8; return [node, path]; case 8: _context3.next = 3; break; case 10: _context3.next = 15; break; case 12: _context3.prev = 12; _context3.t0 = _context3["catch"](1); _iterator2.e(_context3.t0); case 15: _context3.prev = 15; _iterator2.f(); return _context3.finish(15); case 18: case "end": return _context3.stop(); } }, _callee3, null, [[1, 12, 15, 18]]); })(); }, elements: function elements(root) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return /*#__PURE__*/regenerator.mark(function _callee4() { var _iterator3, _step3, _step3$value, node, path; return regenerator.wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _iterator3 = _createForOfIteratorHelper$l(Node.nodes(root, options)); _context4.prev = 1; _iterator3.s(); case 3: if ((_step3 = _iterator3.n()).done) { _context4.next = 10; break; } _step3$value = _slicedToArray(_step3.value, 2), node = _step3$value[0], path = _step3$value[1]; if (!Element.isElement(node)) { _context4.next = 8; break; } _context4.next = 8; return [node, path]; case 8: _context4.next = 3; break; case 10: _context4.next = 15; break; case 12: _context4.prev = 12; _context4.t0 = _context4["catch"](1); _iterator3.e(_context4.t0); case 15: _context4.prev = 15; _iterator3.f(); return _context4.finish(15); case 18: case "end": return _context4.stop(); } }, _callee4, null, [[1, 12, 15, 18]]); })(); }, extractProps: function extractProps(node) { if (Element.isAncestor(node)) { node.children;