UNPKG

342 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Slate = {}));
5})(this, (function (exports) { 'use strict';
6
7 // eslint-disable-next-line no-redeclare
8 var PathRef = {
9 transform: function transform(ref, op) {
10 var current = ref.current,
11 affinity = ref.affinity;
12 if (current == null) {
13 return;
14 }
15 var path = Path.transform(current, op, {
16 affinity: affinity
17 });
18 ref.current = path;
19 if (path == null) {
20 ref.unref();
21 }
22 }
23 };
24
25 // eslint-disable-next-line no-redeclare
26 var PointRef = {
27 transform: function transform(ref, op) {
28 var current = ref.current,
29 affinity = ref.affinity;
30 if (current == null) {
31 return;
32 }
33 var point = Point.transform(current, op, {
34 affinity: affinity
35 });
36 ref.current = point;
37 if (point == null) {
38 ref.unref();
39 }
40 }
41 };
42
43 // eslint-disable-next-line no-redeclare
44 var RangeRef = {
45 transform: function transform(ref, op) {
46 var current = ref.current,
47 affinity = ref.affinity;
48 if (current == null) {
49 return;
50 }
51 var path = Range.transform(current, op, {
52 affinity: affinity
53 });
54 ref.current = path;
55 if (path == null) {
56 ref.unref();
57 }
58 }
59 };
60
61 var DIRTY_PATHS = new WeakMap();
62 var DIRTY_PATH_KEYS = new WeakMap();
63 var FLUSHING = new WeakMap();
64 var NORMALIZING = new WeakMap();
65 var PATH_REFS = new WeakMap();
66 var POINT_REFS = new WeakMap();
67 var RANGE_REFS = new WeakMap();
68
69 function unwrapExports (x) {
70 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
71 }
72
73 function createCommonjsModule(fn, module) {
74 return module = { exports: {} }, fn(module, module.exports), module.exports;
75 }
76
77 var arrayLikeToArray = createCommonjsModule(function (module) {
78 function _arrayLikeToArray(arr, len) {
79 if (len == null || len > arr.length) len = arr.length;
80 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
81 return arr2;
82 }
83 module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
84 });
85
86 unwrapExports(arrayLikeToArray);
87
88 var arrayWithoutHoles = createCommonjsModule(function (module) {
89 function _arrayWithoutHoles(arr) {
90 if (Array.isArray(arr)) return arrayLikeToArray(arr);
91 }
92 module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
93 });
94
95 unwrapExports(arrayWithoutHoles);
96
97 var iterableToArray = createCommonjsModule(function (module) {
98 function _iterableToArray(iter) {
99 if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
100 }
101 module.exports = _iterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
102 });
103
104 unwrapExports(iterableToArray);
105
106 var unsupportedIterableToArray = createCommonjsModule(function (module) {
107 function _unsupportedIterableToArray(o, minLen) {
108 if (!o) return;
109 if (typeof o === "string") return arrayLikeToArray(o, minLen);
110 var n = Object.prototype.toString.call(o).slice(8, -1);
111 if (n === "Object" && o.constructor) n = o.constructor.name;
112 if (n === "Map" || n === "Set") return Array.from(o);
113 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
114 }
115 module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
116 });
117
118 unwrapExports(unsupportedIterableToArray);
119
120 var nonIterableSpread = createCommonjsModule(function (module) {
121 function _nonIterableSpread() {
122 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
123 }
124 module.exports = _nonIterableSpread, module.exports.__esModule = true, module.exports["default"] = module.exports;
125 });
126
127 unwrapExports(nonIterableSpread);
128
129 var toConsumableArray = createCommonjsModule(function (module) {
130 function _toConsumableArray(arr) {
131 return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread();
132 }
133 module.exports = _toConsumableArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
134 });
135
136 var _toConsumableArray = unwrapExports(toConsumableArray);
137
138 // eslint-disable-next-line no-redeclare
139 var Path = {
140 ancestors: function ancestors(path) {
141 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
142 var _options$reverse = options.reverse,
143 reverse = _options$reverse === void 0 ? false : _options$reverse;
144 var paths = Path.levels(path, options);
145 if (reverse) {
146 paths = paths.slice(1);
147 } else {
148 paths = paths.slice(0, -1);
149 }
150 return paths;
151 },
152 common: function common(path, another) {
153 var common = [];
154 for (var i = 0; i < path.length && i < another.length; i++) {
155 var av = path[i];
156 var bv = another[i];
157 if (av !== bv) {
158 break;
159 }
160 common.push(av);
161 }
162 return common;
163 },
164 compare: function compare(path, another) {
165 var min = Math.min(path.length, another.length);
166 for (var i = 0; i < min; i++) {
167 if (path[i] < another[i]) return -1;
168 if (path[i] > another[i]) return 1;
169 }
170 return 0;
171 },
172 endsAfter: function endsAfter(path, another) {
173 var i = path.length - 1;
174 var as = path.slice(0, i);
175 var bs = another.slice(0, i);
176 var av = path[i];
177 var bv = another[i];
178 return Path.equals(as, bs) && av > bv;
179 },
180 endsAt: function endsAt(path, another) {
181 var i = path.length;
182 var as = path.slice(0, i);
183 var bs = another.slice(0, i);
184 return Path.equals(as, bs);
185 },
186 endsBefore: function endsBefore(path, another) {
187 var i = path.length - 1;
188 var as = path.slice(0, i);
189 var bs = another.slice(0, i);
190 var av = path[i];
191 var bv = another[i];
192 return Path.equals(as, bs) && av < bv;
193 },
194 equals: function equals(path, another) {
195 return path.length === another.length && path.every(function (n, i) {
196 return n === another[i];
197 });
198 },
199 hasPrevious: function hasPrevious(path) {
200 return path[path.length - 1] > 0;
201 },
202 isAfter: function isAfter(path, another) {
203 return Path.compare(path, another) === 1;
204 },
205 isAncestor: function isAncestor(path, another) {
206 return path.length < another.length && Path.compare(path, another) === 0;
207 },
208 isBefore: function isBefore(path, another) {
209 return Path.compare(path, another) === -1;
210 },
211 isChild: function isChild(path, another) {
212 return path.length === another.length + 1 && Path.compare(path, another) === 0;
213 },
214 isCommon: function isCommon(path, another) {
215 return path.length <= another.length && Path.compare(path, another) === 0;
216 },
217 isDescendant: function isDescendant(path, another) {
218 return path.length > another.length && Path.compare(path, another) === 0;
219 },
220 isParent: function isParent(path, another) {
221 return path.length + 1 === another.length && Path.compare(path, another) === 0;
222 },
223 isPath: function isPath(value) {
224 return Array.isArray(value) && (value.length === 0 || typeof value[0] === 'number');
225 },
226 isSibling: function isSibling(path, another) {
227 if (path.length !== another.length) {
228 return false;
229 }
230 var as = path.slice(0, -1);
231 var bs = another.slice(0, -1);
232 var al = path[path.length - 1];
233 var bl = another[another.length - 1];
234 return al !== bl && Path.equals(as, bs);
235 },
236 levels: function levels(path) {
237 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
238 var _options$reverse2 = options.reverse,
239 reverse = _options$reverse2 === void 0 ? false : _options$reverse2;
240 var list = [];
241 for (var i = 0; i <= path.length; i++) {
242 list.push(path.slice(0, i));
243 }
244 if (reverse) {
245 list.reverse();
246 }
247 return list;
248 },
249 next: function next(path) {
250 if (path.length === 0) {
251 throw new Error("Cannot get the next path of a root path [".concat(path, "], because it has no next index."));
252 }
253 var last = path[path.length - 1];
254 return path.slice(0, -1).concat(last + 1);
255 },
256 operationCanTransformPath: function operationCanTransformPath(operation) {
257 switch (operation.type) {
258 case 'insert_node':
259 case 'remove_node':
260 case 'merge_node':
261 case 'split_node':
262 case 'move_node':
263 return true;
264 default:
265 return false;
266 }
267 },
268 parent: function parent(path) {
269 if (path.length === 0) {
270 throw new Error("Cannot get the parent path of the root path [".concat(path, "]."));
271 }
272 return path.slice(0, -1);
273 },
274 previous: function previous(path) {
275 if (path.length === 0) {
276 throw new Error("Cannot get the previous path of a root path [".concat(path, "], because it has no previous index."));
277 }
278 var last = path[path.length - 1];
279 if (last <= 0) {
280 throw new Error("Cannot get the previous path of a first child path [".concat(path, "] because it would result in a negative index."));
281 }
282 return path.slice(0, -1).concat(last - 1);
283 },
284 relative: function relative(path, ancestor) {
285 if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) {
286 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."));
287 }
288 return path.slice(ancestor.length);
289 },
290 transform: function transform(path, operation) {
291 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
292 if (!path) return null;
293 // PERF: use destructing instead of immer
294 var p = _toConsumableArray(path);
295 var _options$affinity = options.affinity,
296 affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
297 // PERF: Exit early if the operation is guaranteed not to have an effect.
298 if (path.length === 0) {
299 return p;
300 }
301 switch (operation.type) {
302 case 'insert_node':
303 {
304 var op = operation.path;
305 if (Path.equals(op, p) || Path.endsBefore(op, p) || Path.isAncestor(op, p)) {
306 p[op.length - 1] += 1;
307 }
308 break;
309 }
310 case 'remove_node':
311 {
312 var _op = operation.path;
313 if (Path.equals(_op, p) || Path.isAncestor(_op, p)) {
314 return null;
315 } else if (Path.endsBefore(_op, p)) {
316 p[_op.length - 1] -= 1;
317 }
318 break;
319 }
320 case 'merge_node':
321 {
322 var _op2 = operation.path,
323 position = operation.position;
324 if (Path.equals(_op2, p) || Path.endsBefore(_op2, p)) {
325 p[_op2.length - 1] -= 1;
326 } else if (Path.isAncestor(_op2, p)) {
327 p[_op2.length - 1] -= 1;
328 p[_op2.length] += position;
329 }
330 break;
331 }
332 case 'split_node':
333 {
334 var _op3 = operation.path,
335 _position = operation.position;
336 if (Path.equals(_op3, p)) {
337 if (affinity === 'forward') {
338 p[p.length - 1] += 1;
339 } else if (affinity === 'backward') ; else {
340 return null;
341 }
342 } else if (Path.endsBefore(_op3, p)) {
343 p[_op3.length - 1] += 1;
344 } else if (Path.isAncestor(_op3, p) && path[_op3.length] >= _position) {
345 p[_op3.length - 1] += 1;
346 p[_op3.length] -= _position;
347 }
348 break;
349 }
350 case 'move_node':
351 {
352 var _op4 = operation.path,
353 onp = operation.newPath;
354 // If the old and new path are the same, it's a no-op.
355 if (Path.equals(_op4, onp)) {
356 return p;
357 }
358 if (Path.isAncestor(_op4, p) || Path.equals(_op4, p)) {
359 var copy = onp.slice();
360 if (Path.endsBefore(_op4, onp) && _op4.length < onp.length) {
361 copy[_op4.length - 1] -= 1;
362 }
363 return copy.concat(p.slice(_op4.length));
364 } else if (Path.isSibling(_op4, onp) && (Path.isAncestor(onp, p) || Path.equals(onp, p))) {
365 if (Path.endsBefore(_op4, p)) {
366 p[_op4.length - 1] -= 1;
367 } else {
368 p[_op4.length - 1] += 1;
369 }
370 } else if (Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p)) {
371 if (Path.endsBefore(_op4, p)) {
372 p[_op4.length - 1] -= 1;
373 }
374 p[onp.length - 1] += 1;
375 } else if (Path.endsBefore(_op4, p)) {
376 if (Path.equals(onp, p)) {
377 p[onp.length - 1] += 1;
378 }
379 p[_op4.length - 1] -= 1;
380 }
381 break;
382 }
383 }
384 return p;
385 }
386 };
387
388 var _typeof_1 = createCommonjsModule(function (module) {
389 function _typeof(o) {
390 "@babel/helpers - typeof";
391
392 return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
393 return typeof o;
394 } : function (o) {
395 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
396 }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(o);
397 }
398 module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
399 });
400
401 unwrapExports(_typeof_1);
402
403 var toPrimitive = createCommonjsModule(function (module) {
404 var _typeof = _typeof_1["default"];
405 function _toPrimitive(input, hint) {
406 if (_typeof(input) !== "object" || input === null) return input;
407 var prim = input[Symbol.toPrimitive];
408 if (prim !== undefined) {
409 var res = prim.call(input, hint || "default");
410 if (_typeof(res) !== "object") return res;
411 throw new TypeError("@@toPrimitive must return a primitive value.");
412 }
413 return (hint === "string" ? String : Number)(input);
414 }
415 module.exports = _toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
416 });
417
418 unwrapExports(toPrimitive);
419
420 var toPropertyKey = createCommonjsModule(function (module) {
421 var _typeof = _typeof_1["default"];
422
423 function _toPropertyKey(arg) {
424 var key = toPrimitive(arg, "string");
425 return _typeof(key) === "symbol" ? key : String(key);
426 }
427 module.exports = _toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
428 });
429
430 unwrapExports(toPropertyKey);
431
432 var defineProperty = createCommonjsModule(function (module) {
433 function _defineProperty(obj, key, value) {
434 key = toPropertyKey(key);
435 if (key in obj) {
436 Object.defineProperty(obj, key, {
437 value: value,
438 enumerable: true,
439 configurable: true,
440 writable: true
441 });
442 } else {
443 obj[key] = value;
444 }
445 return obj;
446 }
447 module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
448 });
449
450 var _defineProperty = unwrapExports(defineProperty);
451
452 var arrayWithHoles = createCommonjsModule(function (module) {
453 function _arrayWithHoles(arr) {
454 if (Array.isArray(arr)) return arr;
455 }
456 module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
457 });
458
459 unwrapExports(arrayWithHoles);
460
461 var iterableToArrayLimit = createCommonjsModule(function (module) {
462 function _iterableToArrayLimit(r, l) {
463 var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
464 if (null != t) {
465 var e,
466 n,
467 i,
468 u,
469 a = [],
470 f = !0,
471 o = !1;
472 try {
473 if (i = (t = t.call(r)).next, 0 === l) {
474 if (Object(t) !== t) return;
475 f = !1;
476 } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
477 } catch (r) {
478 o = !0, n = r;
479 } finally {
480 try {
481 if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
482 } finally {
483 if (o) throw n;
484 }
485 }
486 return a;
487 }
488 }
489 module.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports["default"] = module.exports;
490 });
491
492 unwrapExports(iterableToArrayLimit);
493
494 var nonIterableRest = createCommonjsModule(function (module) {
495 function _nonIterableRest() {
496 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
497 }
498 module.exports = _nonIterableRest, module.exports.__esModule = true, module.exports["default"] = module.exports;
499 });
500
501 unwrapExports(nonIterableRest);
502
503 var slicedToArray = createCommonjsModule(function (module) {
504 function _slicedToArray(arr, i) {
505 return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
506 }
507 module.exports = _slicedToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
508 });
509
510 var _slicedToArray = unwrapExports(slicedToArray);
511
512 var __defProp = Object.defineProperty;
513 var __getOwnPropSymbols = Object.getOwnPropertySymbols;
514 var __hasOwnProp = Object.prototype.hasOwnProperty;
515 var __propIsEnum = Object.prototype.propertyIsEnumerable;
516 var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
517 var __spreadValues = (a, b) => {
518 for (var prop in b || (b = {}))
519 if (__hasOwnProp.call(b, prop))
520 __defNormalProp(a, prop, b[prop]);
521 if (__getOwnPropSymbols)
522 for (var prop of __getOwnPropSymbols(b)) {
523 if (__propIsEnum.call(b, prop))
524 __defNormalProp(a, prop, b[prop]);
525 }
526 return a;
527 };
528
529 // src/utils/env.ts
530 var NOTHING = Symbol.for("immer-nothing");
531 var DRAFTABLE = Symbol.for("immer-draftable");
532 var DRAFT_STATE = Symbol.for("immer-state");
533
534 // src/utils/errors.ts
535 var errors = [
536 // All error codes, starting by 0:
537 function(plugin) {
538 return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
539 },
540 function(thing) {
541 return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
542 },
543 "This object has been frozen and should not be mutated",
544 function(data) {
545 return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
546 },
547 "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
548 "Immer forbids circular references",
549 "The first or second argument to `produce` must be a function",
550 "The third argument to `produce` must be a function or undefined",
551 "First argument to `createDraft` must be a plain object, an array, or an immerable object",
552 "First argument to `finishDraft` must be a draft returned by `createDraft`",
553 function(thing) {
554 return `'current' expects a draft, got: ${thing}`;
555 },
556 "Object.defineProperty() cannot be used on an Immer draft",
557 "Object.setPrototypeOf() cannot be used on an Immer draft",
558 "Immer only supports deleting array indices",
559 "Immer only supports setting array indices and the 'length' property",
560 function(thing) {
561 return `'original' expects a draft, got: ${thing}`;
562 }
563 // Note: if more errors are added, the errorOffset in Patches.ts should be increased
564 // See Patches.ts for additional errors
565 ] ;
566 function die(error, ...args) {
567 {
568 const e = errors[error];
569 const msg = typeof e === "function" ? e.apply(null, args) : e;
570 throw new Error(`[Immer] ${msg}`);
571 }
572 }
573
574 // src/utils/common.ts
575 var getPrototypeOf = Object.getPrototypeOf;
576 function isDraft(value) {
577 return !!value && !!value[DRAFT_STATE];
578 }
579 function isDraftable(value) {
580 var _a;
581 if (!value)
582 return false;
583 return isPlainObject$1(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_a = value.constructor) == null ? void 0 : _a[DRAFTABLE]) || isMap(value) || isSet(value);
584 }
585 var objectCtorString = Object.prototype.constructor.toString();
586 function isPlainObject$1(value) {
587 if (!value || typeof value !== "object")
588 return false;
589 const proto = getPrototypeOf(value);
590 if (proto === null) {
591 return true;
592 }
593 const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
594 if (Ctor === Object)
595 return true;
596 return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
597 }
598 function each(obj, iter) {
599 if (getArchtype(obj) === 0 /* Object */) {
600 Object.entries(obj).forEach(([key, value]) => {
601 iter(key, value, obj);
602 });
603 } else {
604 obj.forEach((entry, index) => iter(index, entry, obj));
605 }
606 }
607 function getArchtype(thing) {
608 const state = thing[DRAFT_STATE];
609 return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
610 }
611 function has(thing, prop) {
612 return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
613 }
614 function set(thing, propOrOldValue, value) {
615 const t = getArchtype(thing);
616 if (t === 2 /* Map */)
617 thing.set(propOrOldValue, value);
618 else if (t === 3 /* Set */) {
619 thing.add(value);
620 } else
621 thing[propOrOldValue] = value;
622 }
623 function is(x, y) {
624 if (x === y) {
625 return x !== 0 || 1 / x === 1 / y;
626 } else {
627 return x !== x && y !== y;
628 }
629 }
630 function isMap(target) {
631 return target instanceof Map;
632 }
633 function isSet(target) {
634 return target instanceof Set;
635 }
636 function latest(state) {
637 return state.copy_ || state.base_;
638 }
639 function shallowCopy(base, strict) {
640 if (isMap(base)) {
641 return new Map(base);
642 }
643 if (isSet(base)) {
644 return new Set(base);
645 }
646 if (Array.isArray(base))
647 return Array.prototype.slice.call(base);
648 if (!strict && isPlainObject$1(base)) {
649 if (!getPrototypeOf(base)) {
650 const obj = /* @__PURE__ */ Object.create(null);
651 return Object.assign(obj, base);
652 }
653 return __spreadValues({}, base);
654 }
655 const descriptors = Object.getOwnPropertyDescriptors(base);
656 delete descriptors[DRAFT_STATE];
657 let keys = Reflect.ownKeys(descriptors);
658 for (let i = 0; i < keys.length; i++) {
659 const key = keys[i];
660 const desc = descriptors[key];
661 if (desc.writable === false) {
662 desc.writable = true;
663 desc.configurable = true;
664 }
665 if (desc.get || desc.set)
666 descriptors[key] = {
667 configurable: true,
668 writable: true,
669 // could live with !!desc.set as well here...
670 enumerable: desc.enumerable,
671 value: base[key]
672 };
673 }
674 return Object.create(getPrototypeOf(base), descriptors);
675 }
676 function freeze(obj, deep = false) {
677 if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
678 return obj;
679 if (getArchtype(obj) > 1) {
680 obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
681 }
682 Object.freeze(obj);
683 if (deep)
684 each(obj, (_key, value) => freeze(value, true));
685 return obj;
686 }
687 function dontMutateFrozenCollections() {
688 die(2);
689 }
690 function isFrozen(obj) {
691 return Object.isFrozen(obj);
692 }
693
694 // src/utils/plugins.ts
695 var plugins = {};
696 function getPlugin(pluginKey) {
697 const plugin = plugins[pluginKey];
698 if (!plugin) {
699 die(0, pluginKey);
700 }
701 return plugin;
702 }
703
704 // src/core/scope.ts
705 var currentScope;
706 function getCurrentScope() {
707 return currentScope;
708 }
709 function createScope(parent_, immer_) {
710 return {
711 drafts_: [],
712 parent_,
713 immer_,
714 // Whenever the modified draft contains a draft from another scope, we
715 // need to prevent auto-freezing so the unowned draft can be finalized.
716 canAutoFreeze_: true,
717 unfinalizedDrafts_: 0
718 };
719 }
720 function usePatchesInScope(scope, patchListener) {
721 if (patchListener) {
722 getPlugin("Patches");
723 scope.patches_ = [];
724 scope.inversePatches_ = [];
725 scope.patchListener_ = patchListener;
726 }
727 }
728 function revokeScope(scope) {
729 leaveScope(scope);
730 scope.drafts_.forEach(revokeDraft);
731 scope.drafts_ = null;
732 }
733 function leaveScope(scope) {
734 if (scope === currentScope) {
735 currentScope = scope.parent_;
736 }
737 }
738 function enterScope(immer2) {
739 return currentScope = createScope(currentScope, immer2);
740 }
741 function revokeDraft(draft) {
742 const state = draft[DRAFT_STATE];
743 if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
744 state.revoke_();
745 else
746 state.revoked_ = true;
747 }
748
749 // src/core/finalize.ts
750 function processResult(result, scope) {
751 scope.unfinalizedDrafts_ = scope.drafts_.length;
752 const baseDraft = scope.drafts_[0];
753 const isReplaced = result !== void 0 && result !== baseDraft;
754 if (isReplaced) {
755 if (baseDraft[DRAFT_STATE].modified_) {
756 revokeScope(scope);
757 die(4);
758 }
759 if (isDraftable(result)) {
760 result = finalize(scope, result);
761 if (!scope.parent_)
762 maybeFreeze(scope, result);
763 }
764 if (scope.patches_) {
765 getPlugin("Patches").generateReplacementPatches_(
766 baseDraft[DRAFT_STATE].base_,
767 result,
768 scope.patches_,
769 scope.inversePatches_
770 );
771 }
772 } else {
773 result = finalize(scope, baseDraft, []);
774 }
775 revokeScope(scope);
776 if (scope.patches_) {
777 scope.patchListener_(scope.patches_, scope.inversePatches_);
778 }
779 return result !== NOTHING ? result : void 0;
780 }
781 function finalize(rootScope, value, path) {
782 if (isFrozen(value))
783 return value;
784 const state = value[DRAFT_STATE];
785 if (!state) {
786 each(
787 value,
788 (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path));
789 return value;
790 }
791 if (state.scope_ !== rootScope)
792 return value;
793 if (!state.modified_) {
794 maybeFreeze(rootScope, state.base_, true);
795 return state.base_;
796 }
797 if (!state.finalized_) {
798 state.finalized_ = true;
799 state.scope_.unfinalizedDrafts_--;
800 const result = state.copy_;
801 let resultEach = result;
802 let isSet2 = false;
803 if (state.type_ === 3 /* Set */) {
804 resultEach = new Set(result);
805 result.clear();
806 isSet2 = true;
807 }
808 each(
809 resultEach,
810 (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
811 );
812 maybeFreeze(rootScope, result, false);
813 if (path && rootScope.patches_) {
814 getPlugin("Patches").generatePatches_(
815 state,
816 path,
817 rootScope.patches_,
818 rootScope.inversePatches_
819 );
820 }
821 }
822 return state.copy_;
823 }
824 function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
825 if (childValue === targetObject)
826 die(5);
827 if (isDraft(childValue)) {
828 const path = rootPath && parentState && parentState.type_ !== 3 /* Set */ && // Set objects are atomic since they have no keys.
829 !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
830 const res = finalize(rootScope, childValue, path);
831 set(targetObject, prop, res);
832 if (isDraft(res)) {
833 rootScope.canAutoFreeze_ = false;
834 } else
835 return;
836 } else if (targetIsSet) {
837 targetObject.add(childValue);
838 }
839 if (isDraftable(childValue) && !isFrozen(childValue)) {
840 if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
841 return;
842 }
843 finalize(rootScope, childValue);
844 if (!parentState || !parentState.scope_.parent_)
845 maybeFreeze(rootScope, childValue);
846 }
847 }
848 function maybeFreeze(scope, value, deep = false) {
849 if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
850 freeze(value, deep);
851 }
852 }
853
854 // src/core/proxy.ts
855 function createProxyProxy(base, parent) {
856 const isArray = Array.isArray(base);
857 const state = {
858 type_: isArray ? 1 /* Array */ : 0 /* Object */,
859 // Track which produce call this is associated with.
860 scope_: parent ? parent.scope_ : getCurrentScope(),
861 // True for both shallow and deep changes.
862 modified_: false,
863 // Used during finalization.
864 finalized_: false,
865 // Track which properties have been assigned (true) or deleted (false).
866 assigned_: {},
867 // The parent draft state.
868 parent_: parent,
869 // The base state.
870 base_: base,
871 // The base proxy.
872 draft_: null,
873 // set below
874 // The base copy with any updated values.
875 copy_: null,
876 // Called by the `produce` function.
877 revoke_: null,
878 isManual_: false
879 };
880 let target = state;
881 let traps = objectTraps;
882 if (isArray) {
883 target = [state];
884 traps = arrayTraps;
885 }
886 const { revoke, proxy } = Proxy.revocable(target, traps);
887 state.draft_ = proxy;
888 state.revoke_ = revoke;
889 return proxy;
890 }
891 var objectTraps = {
892 get(state, prop) {
893 if (prop === DRAFT_STATE)
894 return state;
895 const source = latest(state);
896 if (!has(source, prop)) {
897 return readPropFromProto(state, source, prop);
898 }
899 const value = source[prop];
900 if (state.finalized_ || !isDraftable(value)) {
901 return value;
902 }
903 if (value === peek(state.base_, prop)) {
904 prepareCopy(state);
905 return state.copy_[prop] = createProxy(value, state);
906 }
907 return value;
908 },
909 has(state, prop) {
910 return prop in latest(state);
911 },
912 ownKeys(state) {
913 return Reflect.ownKeys(latest(state));
914 },
915 set(state, prop, value) {
916 const desc = getDescriptorFromProto(latest(state), prop);
917 if (desc == null ? void 0 : desc.set) {
918 desc.set.call(state.draft_, value);
919 return true;
920 }
921 if (!state.modified_) {
922 const current2 = peek(latest(state), prop);
923 const currentState = current2 == null ? void 0 : current2[DRAFT_STATE];
924 if (currentState && currentState.base_ === value) {
925 state.copy_[prop] = value;
926 state.assigned_[prop] = false;
927 return true;
928 }
929 if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
930 return true;
931 prepareCopy(state);
932 markChanged(state);
933 }
934 if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
935 (value !== void 0 || prop in state.copy_) || // special case: NaN
936 Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
937 return true;
938 state.copy_[prop] = value;
939 state.assigned_[prop] = true;
940 return true;
941 },
942 deleteProperty(state, prop) {
943 if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
944 state.assigned_[prop] = false;
945 prepareCopy(state);
946 markChanged(state);
947 } else {
948 delete state.assigned_[prop];
949 }
950 if (state.copy_) {
951 delete state.copy_[prop];
952 }
953 return true;
954 },
955 // Note: We never coerce `desc.value` into an Immer draft, because we can't make
956 // the same guarantee in ES5 mode.
957 getOwnPropertyDescriptor(state, prop) {
958 const owner = latest(state);
959 const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
960 if (!desc)
961 return desc;
962 return {
963 writable: true,
964 configurable: state.type_ !== 1 /* Array */ || prop !== "length",
965 enumerable: desc.enumerable,
966 value: owner[prop]
967 };
968 },
969 defineProperty() {
970 die(11);
971 },
972 getPrototypeOf(state) {
973 return getPrototypeOf(state.base_);
974 },
975 setPrototypeOf() {
976 die(12);
977 }
978 };
979 var arrayTraps = {};
980 each(objectTraps, (key, fn) => {
981 arrayTraps[key] = function() {
982 arguments[0] = arguments[0][0];
983 return fn.apply(this, arguments);
984 };
985 });
986 arrayTraps.deleteProperty = function(state, prop) {
987 if (isNaN(parseInt(prop)))
988 die(13);
989 return arrayTraps.set.call(this, state, prop, void 0);
990 };
991 arrayTraps.set = function(state, prop, value) {
992 if (prop !== "length" && isNaN(parseInt(prop)))
993 die(14);
994 return objectTraps.set.call(this, state[0], prop, value, state[0]);
995 };
996 function peek(draft, prop) {
997 const state = draft[DRAFT_STATE];
998 const source = state ? latest(state) : draft;
999 return source[prop];
1000 }
1001 function readPropFromProto(state, source, prop) {
1002 var _a;
1003 const desc = getDescriptorFromProto(source, prop);
1004 return desc ? `value` in desc ? desc.value : (
1005 // This is a very special case, if the prop is a getter defined by the
1006 // prototype, we should invoke it with the draft as context!
1007 (_a = desc.get) == null ? void 0 : _a.call(state.draft_)
1008 ) : void 0;
1009 }
1010 function getDescriptorFromProto(source, prop) {
1011 if (!(prop in source))
1012 return void 0;
1013 let proto = getPrototypeOf(source);
1014 while (proto) {
1015 const desc = Object.getOwnPropertyDescriptor(proto, prop);
1016 if (desc)
1017 return desc;
1018 proto = getPrototypeOf(proto);
1019 }
1020 return void 0;
1021 }
1022 function markChanged(state) {
1023 if (!state.modified_) {
1024 state.modified_ = true;
1025 if (state.parent_) {
1026 markChanged(state.parent_);
1027 }
1028 }
1029 }
1030 function prepareCopy(state) {
1031 if (!state.copy_) {
1032 state.copy_ = shallowCopy(
1033 state.base_,
1034 state.scope_.immer_.useStrictShallowCopy_
1035 );
1036 }
1037 }
1038
1039 // src/core/immerClass.ts
1040 var Immer2 = class {
1041 constructor(config) {
1042 this.autoFreeze_ = true;
1043 this.useStrictShallowCopy_ = false;
1044 /**
1045 * The `produce` function takes a value and a "recipe function" (whose
1046 * return value often depends on the base state). The recipe function is
1047 * free to mutate its first argument however it wants. All mutations are
1048 * only ever applied to a __copy__ of the base state.
1049 *
1050 * Pass only a function to create a "curried producer" which relieves you
1051 * from passing the recipe function every time.
1052 *
1053 * Only plain objects and arrays are made mutable. All other objects are
1054 * considered uncopyable.
1055 *
1056 * Note: This function is __bound__ to its `Immer` instance.
1057 *
1058 * @param {any} base - the initial state
1059 * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
1060 * @param {Function} patchListener - optional function that will be called with all the patches produced here
1061 * @returns {any} a new state, or the initial state if nothing was modified
1062 */
1063 this.produce = (base, recipe, patchListener) => {
1064 if (typeof base === "function" && typeof recipe !== "function") {
1065 const defaultBase = recipe;
1066 recipe = base;
1067 const self = this;
1068 return function curriedProduce(base2 = defaultBase, ...args) {
1069 return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
1070 };
1071 }
1072 if (typeof recipe !== "function")
1073 die(6);
1074 if (patchListener !== void 0 && typeof patchListener !== "function")
1075 die(7);
1076 let result;
1077 if (isDraftable(base)) {
1078 const scope = enterScope(this);
1079 const proxy = createProxy(base, void 0);
1080 let hasError = true;
1081 try {
1082 result = recipe(proxy);
1083 hasError = false;
1084 } finally {
1085 if (hasError)
1086 revokeScope(scope);
1087 else
1088 leaveScope(scope);
1089 }
1090 usePatchesInScope(scope, patchListener);
1091 return processResult(result, scope);
1092 } else if (!base || typeof base !== "object") {
1093 result = recipe(base);
1094 if (result === void 0)
1095 result = base;
1096 if (result === NOTHING)
1097 result = void 0;
1098 if (this.autoFreeze_)
1099 freeze(result, true);
1100 if (patchListener) {
1101 const p = [];
1102 const ip = [];
1103 getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
1104 patchListener(p, ip);
1105 }
1106 return result;
1107 } else
1108 die(1, base);
1109 };
1110 this.produceWithPatches = (base, recipe) => {
1111 if (typeof base === "function") {
1112 return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
1113 }
1114 let patches, inversePatches;
1115 const result = this.produce(base, recipe, (p, ip) => {
1116 patches = p;
1117 inversePatches = ip;
1118 });
1119 return [result, patches, inversePatches];
1120 };
1121 if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean")
1122 this.setAutoFreeze(config.autoFreeze);
1123 if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean")
1124 this.setUseStrictShallowCopy(config.useStrictShallowCopy);
1125 }
1126 createDraft(base) {
1127 if (!isDraftable(base))
1128 die(8);
1129 if (isDraft(base))
1130 base = current(base);
1131 const scope = enterScope(this);
1132 const proxy = createProxy(base, void 0);
1133 proxy[DRAFT_STATE].isManual_ = true;
1134 leaveScope(scope);
1135 return proxy;
1136 }
1137 finishDraft(draft, patchListener) {
1138 const state = draft && draft[DRAFT_STATE];
1139 if (!state || !state.isManual_)
1140 die(9);
1141 const { scope_: scope } = state;
1142 usePatchesInScope(scope, patchListener);
1143 return processResult(void 0, scope);
1144 }
1145 /**
1146 * Pass true to automatically freeze all copies created by Immer.
1147 *
1148 * By default, auto-freezing is enabled.
1149 */
1150 setAutoFreeze(value) {
1151 this.autoFreeze_ = value;
1152 }
1153 /**
1154 * Pass true to enable strict shallow copy.
1155 *
1156 * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
1157 */
1158 setUseStrictShallowCopy(value) {
1159 this.useStrictShallowCopy_ = value;
1160 }
1161 applyPatches(base, patches) {
1162 let i;
1163 for (i = patches.length - 1; i >= 0; i--) {
1164 const patch = patches[i];
1165 if (patch.path.length === 0 && patch.op === "replace") {
1166 base = patch.value;
1167 break;
1168 }
1169 }
1170 if (i > -1) {
1171 patches = patches.slice(i + 1);
1172 }
1173 const applyPatchesImpl = getPlugin("Patches").applyPatches_;
1174 if (isDraft(base)) {
1175 return applyPatchesImpl(base, patches);
1176 }
1177 return this.produce(
1178 base,
1179 (draft) => applyPatchesImpl(draft, patches)
1180 );
1181 }
1182 };
1183 function createProxy(value, parent) {
1184 const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
1185 const scope = parent ? parent.scope_ : getCurrentScope();
1186 scope.drafts_.push(draft);
1187 return draft;
1188 }
1189
1190 // src/core/current.ts
1191 function current(value) {
1192 if (!isDraft(value))
1193 die(10, value);
1194 return currentImpl(value);
1195 }
1196 function currentImpl(value) {
1197 if (!isDraftable(value) || isFrozen(value))
1198 return value;
1199 const state = value[DRAFT_STATE];
1200 let copy;
1201 if (state) {
1202 if (!state.modified_)
1203 return state.base_;
1204 state.finalized_ = true;
1205 copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
1206 } else {
1207 copy = shallowCopy(value, true);
1208 }
1209 each(copy, (key, childValue) => {
1210 set(copy, key, currentImpl(childValue));
1211 });
1212 if (state) {
1213 state.finalized_ = false;
1214 }
1215 return copy;
1216 }
1217
1218 // src/immer.ts
1219 var immer = new Immer2();
1220 var produce = immer.produce;
1221 immer.produceWithPatches.bind(
1222 immer
1223 );
1224 immer.setAutoFreeze.bind(immer);
1225 immer.setUseStrictShallowCopy.bind(immer);
1226 immer.applyPatches.bind(immer);
1227 var createDraft = immer.createDraft.bind(immer);
1228 var finishDraft = immer.finishDraft.bind(immer);
1229
1230 function ownKeys$e(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; }
1231 function _objectSpread$e(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$e(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$e(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1232 function _createForOfIteratorHelper$m(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$m(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; } } }; }
1233 function _unsupportedIterableToArray$m(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$m(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$m(o, minLen); }
1234 function _arrayLikeToArray$m(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; }
1235 var applyToDraft = function applyToDraft(editor, selection, op) {
1236 switch (op.type) {
1237 case 'insert_node':
1238 {
1239 var path = op.path,
1240 node = op.node;
1241 var parent = Node.parent(editor, path);
1242 var index = path[path.length - 1];
1243 if (index > parent.children.length) {
1244 throw new Error("Cannot apply an \"insert_node\" operation at path [".concat(path, "] because the destination is past the end of the node."));
1245 }
1246 parent.children.splice(index, 0, node);
1247 if (selection) {
1248 var _iterator = _createForOfIteratorHelper$m(Range.points(selection)),
1249 _step;
1250 try {
1251 for (_iterator.s(); !(_step = _iterator.n()).done;) {
1252 var _step$value = _slicedToArray(_step.value, 2),
1253 point = _step$value[0],
1254 key = _step$value[1];
1255 selection[key] = Point.transform(point, op);
1256 }
1257 } catch (err) {
1258 _iterator.e(err);
1259 } finally {
1260 _iterator.f();
1261 }
1262 }
1263 break;
1264 }
1265 case 'insert_text':
1266 {
1267 var _path = op.path,
1268 offset = op.offset,
1269 text = op.text;
1270 if (text.length === 0) break;
1271 var _node = Node.leaf(editor, _path);
1272 var before = _node.text.slice(0, offset);
1273 var after = _node.text.slice(offset);
1274 _node.text = before + text + after;
1275 if (selection) {
1276 var _iterator2 = _createForOfIteratorHelper$m(Range.points(selection)),
1277 _step2;
1278 try {
1279 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1280 var _step2$value = _slicedToArray(_step2.value, 2),
1281 _point = _step2$value[0],
1282 _key = _step2$value[1];
1283 selection[_key] = Point.transform(_point, op);
1284 }
1285 } catch (err) {
1286 _iterator2.e(err);
1287 } finally {
1288 _iterator2.f();
1289 }
1290 }
1291 break;
1292 }
1293 case 'merge_node':
1294 {
1295 var _path2 = op.path;
1296 var _node2 = Node.get(editor, _path2);
1297 var prevPath = Path.previous(_path2);
1298 var prev = Node.get(editor, prevPath);
1299 var _parent = Node.parent(editor, _path2);
1300 var _index = _path2[_path2.length - 1];
1301 if (Text.isText(_node2) && Text.isText(prev)) {
1302 prev.text += _node2.text;
1303 } else if (!Text.isText(_node2) && !Text.isText(prev)) {
1304 var _prev$children;
1305 (_prev$children = prev.children).push.apply(_prev$children, _toConsumableArray(_node2.children));
1306 } else {
1307 throw new Error("Cannot apply a \"merge_node\" operation at path [".concat(_path2, "] to nodes of different interfaces: ").concat(Scrubber.stringify(_node2), " ").concat(Scrubber.stringify(prev)));
1308 }
1309 _parent.children.splice(_index, 1);
1310 if (selection) {
1311 var _iterator3 = _createForOfIteratorHelper$m(Range.points(selection)),
1312 _step3;
1313 try {
1314 for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1315 var _step3$value = _slicedToArray(_step3.value, 2),
1316 _point2 = _step3$value[0],
1317 _key2 = _step3$value[1];
1318 selection[_key2] = Point.transform(_point2, op);
1319 }
1320 } catch (err) {
1321 _iterator3.e(err);
1322 } finally {
1323 _iterator3.f();
1324 }
1325 }
1326 break;
1327 }
1328 case 'move_node':
1329 {
1330 var _path3 = op.path,
1331 newPath = op.newPath;
1332 if (Path.isAncestor(_path3, newPath)) {
1333 throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
1334 }
1335 var _node3 = Node.get(editor, _path3);
1336 var _parent2 = Node.parent(editor, _path3);
1337 var _index2 = _path3[_path3.length - 1];
1338 // This is tricky, but since the `path` and `newPath` both refer to
1339 // the same snapshot in time, there's a mismatch. After either
1340 // removing the original position, the second step's path can be out
1341 // of date. So instead of using the `op.newPath` directly, we
1342 // transform `op.path` to ascertain what the `newPath` would be after
1343 // the operation was applied.
1344 _parent2.children.splice(_index2, 1);
1345 var truePath = Path.transform(_path3, op);
1346 var newParent = Node.get(editor, Path.parent(truePath));
1347 var newIndex = truePath[truePath.length - 1];
1348 newParent.children.splice(newIndex, 0, _node3);
1349 if (selection) {
1350 var _iterator4 = _createForOfIteratorHelper$m(Range.points(selection)),
1351 _step4;
1352 try {
1353 for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1354 var _step4$value = _slicedToArray(_step4.value, 2),
1355 _point3 = _step4$value[0],
1356 _key3 = _step4$value[1];
1357 selection[_key3] = Point.transform(_point3, op);
1358 }
1359 } catch (err) {
1360 _iterator4.e(err);
1361 } finally {
1362 _iterator4.f();
1363 }
1364 }
1365 break;
1366 }
1367 case 'remove_node':
1368 {
1369 var _path4 = op.path;
1370 var _index3 = _path4[_path4.length - 1];
1371 var _parent3 = Node.parent(editor, _path4);
1372 _parent3.children.splice(_index3, 1);
1373 // Transform all the points in the value, but if the point was in the
1374 // node that was removed we need to update the range or remove it.
1375 if (selection) {
1376 var _iterator5 = _createForOfIteratorHelper$m(Range.points(selection)),
1377 _step5;
1378 try {
1379 for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1380 var _step5$value = _slicedToArray(_step5.value, 2),
1381 _point4 = _step5$value[0],
1382 _key4 = _step5$value[1];
1383 var result = Point.transform(_point4, op);
1384 if (selection != null && result != null) {
1385 selection[_key4] = result;
1386 } else {
1387 var _prev = void 0;
1388 var next = void 0;
1389 var _iterator6 = _createForOfIteratorHelper$m(Node.texts(editor)),
1390 _step6;
1391 try {
1392 for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1393 var _step6$value = _slicedToArray(_step6.value, 2),
1394 n = _step6$value[0],
1395 p = _step6$value[1];
1396 if (Path.compare(p, _path4) === -1) {
1397 _prev = [n, p];
1398 } else {
1399 next = [n, p];
1400 break;
1401 }
1402 }
1403 } catch (err) {
1404 _iterator6.e(err);
1405 } finally {
1406 _iterator6.f();
1407 }
1408 var preferNext = false;
1409 if (_prev && next) {
1410 if (Path.equals(next[1], _path4)) {
1411 preferNext = !Path.hasPrevious(next[1]);
1412 } else {
1413 preferNext = Path.common(_prev[1], _path4).length < Path.common(next[1], _path4).length;
1414 }
1415 }
1416 if (_prev && !preferNext) {
1417 _point4.path = _prev[1];
1418 _point4.offset = _prev[0].text.length;
1419 } else if (next) {
1420 _point4.path = next[1];
1421 _point4.offset = 0;
1422 } else {
1423 selection = null;
1424 }
1425 }
1426 }
1427 } catch (err) {
1428 _iterator5.e(err);
1429 } finally {
1430 _iterator5.f();
1431 }
1432 }
1433 break;
1434 }
1435 case 'remove_text':
1436 {
1437 var _path5 = op.path,
1438 _offset = op.offset,
1439 _text = op.text;
1440 if (_text.length === 0) break;
1441 var _node4 = Node.leaf(editor, _path5);
1442 var _before = _node4.text.slice(0, _offset);
1443 var _after = _node4.text.slice(_offset + _text.length);
1444 _node4.text = _before + _after;
1445 if (selection) {
1446 var _iterator7 = _createForOfIteratorHelper$m(Range.points(selection)),
1447 _step7;
1448 try {
1449 for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1450 var _step7$value = _slicedToArray(_step7.value, 2),
1451 _point5 = _step7$value[0],
1452 _key5 = _step7$value[1];
1453 selection[_key5] = Point.transform(_point5, op);
1454 }
1455 } catch (err) {
1456 _iterator7.e(err);
1457 } finally {
1458 _iterator7.f();
1459 }
1460 }
1461 break;
1462 }
1463 case 'set_node':
1464 {
1465 var _path6 = op.path,
1466 properties = op.properties,
1467 newProperties = op.newProperties;
1468 if (_path6.length === 0) {
1469 throw new Error("Cannot set properties on the root node!");
1470 }
1471 var _node5 = Node.get(editor, _path6);
1472 for (var _key6 in newProperties) {
1473 if (_key6 === 'children' || _key6 === 'text') {
1474 throw new Error("Cannot set the \"".concat(_key6, "\" property of nodes!"));
1475 }
1476 var value = newProperties[_key6];
1477 if (value == null) {
1478 delete _node5[_key6];
1479 } else {
1480 _node5[_key6] = value;
1481 }
1482 }
1483 // properties that were previously defined, but are now missing, must be deleted
1484 for (var _key7 in properties) {
1485 if (!newProperties.hasOwnProperty(_key7)) {
1486 delete _node5[_key7];
1487 }
1488 }
1489 break;
1490 }
1491 case 'set_selection':
1492 {
1493 var _newProperties = op.newProperties;
1494 if (_newProperties == null) {
1495 selection = _newProperties;
1496 } else {
1497 if (selection == null) {
1498 if (!Range.isRange(_newProperties)) {
1499 throw new Error("Cannot apply an incomplete \"set_selection\" operation properties ".concat(Scrubber.stringify(_newProperties), " when there is no current selection."));
1500 }
1501 selection = _objectSpread$e({}, _newProperties);
1502 }
1503 for (var _key8 in _newProperties) {
1504 var _value = _newProperties[_key8];
1505 if (_value == null) {
1506 if (_key8 === 'anchor' || _key8 === 'focus') {
1507 throw new Error("Cannot remove the \"".concat(_key8, "\" selection property"));
1508 }
1509 delete selection[_key8];
1510 } else {
1511 selection[_key8] = _value;
1512 }
1513 }
1514 }
1515 break;
1516 }
1517 case 'split_node':
1518 {
1519 var _path7 = op.path,
1520 position = op.position,
1521 _properties = op.properties;
1522 if (_path7.length === 0) {
1523 throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
1524 }
1525 var _node6 = Node.get(editor, _path7);
1526 var _parent4 = Node.parent(editor, _path7);
1527 var _index4 = _path7[_path7.length - 1];
1528 var newNode;
1529 if (Text.isText(_node6)) {
1530 var _before2 = _node6.text.slice(0, position);
1531 var _after2 = _node6.text.slice(position);
1532 _node6.text = _before2;
1533 newNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
1534 text: _after2
1535 });
1536 } else {
1537 var _before3 = _node6.children.slice(0, position);
1538 var _after3 = _node6.children.slice(position);
1539 _node6.children = _before3;
1540 newNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
1541 children: _after3
1542 });
1543 }
1544 _parent4.children.splice(_index4 + 1, 0, newNode);
1545 if (selection) {
1546 var _iterator8 = _createForOfIteratorHelper$m(Range.points(selection)),
1547 _step8;
1548 try {
1549 for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1550 var _step8$value = _slicedToArray(_step8.value, 2),
1551 _point6 = _step8$value[0],
1552 _key9 = _step8$value[1];
1553 selection[_key9] = Point.transform(_point6, op);
1554 }
1555 } catch (err) {
1556 _iterator8.e(err);
1557 } finally {
1558 _iterator8.f();
1559 }
1560 }
1561 break;
1562 }
1563 }
1564 return selection;
1565 };
1566 // eslint-disable-next-line no-redeclare
1567 var GeneralTransforms = {
1568 transform: function transform(editor, op) {
1569 editor.children = createDraft(editor.children);
1570 var selection = editor.selection && createDraft(editor.selection);
1571 try {
1572 selection = applyToDraft(editor, selection, op);
1573 } finally {
1574 editor.children = finishDraft(editor.children);
1575 if (selection) {
1576 editor.selection = isDraft(selection) ? finishDraft(selection) : selection;
1577 } else {
1578 editor.selection = null;
1579 }
1580 }
1581 }
1582 };
1583
1584 // eslint-disable-next-line no-redeclare
1585 var NodeTransforms = {
1586 insertNodes: function insertNodes(editor, nodes, options) {
1587 editor.insertNodes(nodes, options);
1588 },
1589 liftNodes: function liftNodes(editor, options) {
1590 editor.liftNodes(options);
1591 },
1592 mergeNodes: function mergeNodes(editor, options) {
1593 editor.mergeNodes(options);
1594 },
1595 moveNodes: function moveNodes(editor, options) {
1596 editor.moveNodes(options);
1597 },
1598 removeNodes: function removeNodes(editor, options) {
1599 editor.removeNodes(options);
1600 },
1601 setNodes: function setNodes(editor, props, options) {
1602 editor.setNodes(props, options);
1603 },
1604 splitNodes: function splitNodes(editor, options) {
1605 editor.splitNodes(options);
1606 },
1607 unsetNodes: function unsetNodes(editor, props, options) {
1608 editor.unsetNodes(props, options);
1609 },
1610 unwrapNodes: function unwrapNodes(editor, options) {
1611 editor.unwrapNodes(options);
1612 },
1613 wrapNodes: function wrapNodes(editor, element, options) {
1614 editor.wrapNodes(element, options);
1615 }
1616 };
1617
1618 // eslint-disable-next-line no-redeclare
1619 var SelectionTransforms = {
1620 collapse: function collapse(editor, options) {
1621 editor.collapse(options);
1622 },
1623 deselect: function deselect(editor) {
1624 editor.deselect();
1625 },
1626 move: function move(editor, options) {
1627 editor.move(options);
1628 },
1629 select: function select(editor, target) {
1630 editor.select(target);
1631 },
1632 setPoint: function setPoint(editor, props, options) {
1633 editor.setPoint(props, options);
1634 },
1635 setSelection: function setSelection(editor, props) {
1636 editor.setSelection(props);
1637 }
1638 };
1639
1640 /*!
1641 * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
1642 *
1643 * Copyright (c) 2014-2017, Jon Schlinkert.
1644 * Released under the MIT License.
1645 */
1646
1647 function isObject(o) {
1648 return Object.prototype.toString.call(o) === '[object Object]';
1649 }
1650
1651 function isPlainObject(o) {
1652 var ctor,prot;
1653
1654 if (isObject(o) === false) return false;
1655
1656 // If has modified constructor
1657 ctor = o.constructor;
1658 if (ctor === undefined) return true;
1659
1660 // If has modified prototype
1661 prot = ctor.prototype;
1662 if (isObject(prot) === false) return false;
1663
1664 // If constructor does not have an Object-specific method
1665 if (prot.hasOwnProperty('isPrototypeOf') === false) {
1666 return false;
1667 }
1668
1669 // Most likely a plain Object
1670 return true;
1671 }
1672
1673 /*
1674 Custom deep equal comparison for Slate nodes.
1675
1676 We don't need general purpose deep equality;
1677 Slate only supports plain values, Arrays, and nested objects.
1678 Complex values nested inside Arrays are not supported.
1679
1680 Slate objects are designed to be serialised, so
1681 missing keys are deliberately normalised to undefined.
1682 */
1683 var isDeepEqual = function isDeepEqual(node, another) {
1684 for (var key in node) {
1685 var a = node[key];
1686 var b = another[key];
1687 if (isPlainObject(a) && isPlainObject(b)) {
1688 if (!isDeepEqual(a, b)) return false;
1689 } else if (Array.isArray(a) && Array.isArray(b)) {
1690 if (a.length !== b.length) return false;
1691 for (var i = 0; i < a.length; i++) {
1692 if (a[i] !== b[i]) return false;
1693 }
1694 } else if (a !== b) {
1695 return false;
1696 }
1697 }
1698 /*
1699 Deep object equality is only necessary in one direction; in the reverse direction
1700 we are only looking for keys that are missing.
1701 As above, undefined keys are normalised to missing.
1702 */
1703 for (var _key in another) {
1704 if (node[_key] === undefined && another[_key] !== undefined) {
1705 return false;
1706 }
1707 }
1708 return true;
1709 };
1710
1711 var objectWithoutPropertiesLoose = createCommonjsModule(function (module) {
1712 function _objectWithoutPropertiesLoose(source, excluded) {
1713 if (source == null) return {};
1714 var target = {};
1715 var sourceKeys = Object.keys(source);
1716 var key, i;
1717 for (i = 0; i < sourceKeys.length; i++) {
1718 key = sourceKeys[i];
1719 if (excluded.indexOf(key) >= 0) continue;
1720 target[key] = source[key];
1721 }
1722 return target;
1723 }
1724 module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
1725 });
1726
1727 unwrapExports(objectWithoutPropertiesLoose);
1728
1729 var objectWithoutProperties = createCommonjsModule(function (module) {
1730 function _objectWithoutProperties(source, excluded) {
1731 if (source == null) return {};
1732 var target = objectWithoutPropertiesLoose(source, excluded);
1733 var key, i;
1734 if (Object.getOwnPropertySymbols) {
1735 var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
1736 for (i = 0; i < sourceSymbolKeys.length; i++) {
1737 key = sourceSymbolKeys[i];
1738 if (excluded.indexOf(key) >= 0) continue;
1739 if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
1740 target[key] = source[key];
1741 }
1742 }
1743 return target;
1744 }
1745 module.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports["default"] = module.exports;
1746 });
1747
1748 var _objectWithoutProperties = unwrapExports(objectWithoutProperties);
1749
1750 var regeneratorRuntime$1 = createCommonjsModule(function (module) {
1751 var _typeof = _typeof_1["default"];
1752 function _regeneratorRuntime() {
1753 module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
1754 return e;
1755 }, module.exports.__esModule = true, module.exports["default"] = module.exports;
1756 var t,
1757 e = {},
1758 r = Object.prototype,
1759 n = r.hasOwnProperty,
1760 o = Object.defineProperty || function (t, e, r) {
1761 t[e] = r.value;
1762 },
1763 i = "function" == typeof Symbol ? Symbol : {},
1764 a = i.iterator || "@@iterator",
1765 c = i.asyncIterator || "@@asyncIterator",
1766 u = i.toStringTag || "@@toStringTag";
1767 function define(t, e, r) {
1768 return Object.defineProperty(t, e, {
1769 value: r,
1770 enumerable: !0,
1771 configurable: !0,
1772 writable: !0
1773 }), t[e];
1774 }
1775 try {
1776 define({}, "");
1777 } catch (t) {
1778 define = function define(t, e, r) {
1779 return t[e] = r;
1780 };
1781 }
1782 function wrap(t, e, r, n) {
1783 var i = e && e.prototype instanceof Generator ? e : Generator,
1784 a = Object.create(i.prototype),
1785 c = new Context(n || []);
1786 return o(a, "_invoke", {
1787 value: makeInvokeMethod(t, r, c)
1788 }), a;
1789 }
1790 function tryCatch(t, e, r) {
1791 try {
1792 return {
1793 type: "normal",
1794 arg: t.call(e, r)
1795 };
1796 } catch (t) {
1797 return {
1798 type: "throw",
1799 arg: t
1800 };
1801 }
1802 }
1803 e.wrap = wrap;
1804 var h = "suspendedStart",
1805 l = "suspendedYield",
1806 f = "executing",
1807 s = "completed",
1808 y = {};
1809 function Generator() {}
1810 function GeneratorFunction() {}
1811 function GeneratorFunctionPrototype() {}
1812 var p = {};
1813 define(p, a, function () {
1814 return this;
1815 });
1816 var d = Object.getPrototypeOf,
1817 v = d && d(d(values([])));
1818 v && v !== r && n.call(v, a) && (p = v);
1819 var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
1820 function defineIteratorMethods(t) {
1821 ["next", "throw", "return"].forEach(function (e) {
1822 define(t, e, function (t) {
1823 return this._invoke(e, t);
1824 });
1825 });
1826 }
1827 function AsyncIterator(t, e) {
1828 function invoke(r, o, i, a) {
1829 var c = tryCatch(t[r], t, o);
1830 if ("throw" !== c.type) {
1831 var u = c.arg,
1832 h = u.value;
1833 return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
1834 invoke("next", t, i, a);
1835 }, function (t) {
1836 invoke("throw", t, i, a);
1837 }) : e.resolve(h).then(function (t) {
1838 u.value = t, i(u);
1839 }, function (t) {
1840 return invoke("throw", t, i, a);
1841 });
1842 }
1843 a(c.arg);
1844 }
1845 var r;
1846 o(this, "_invoke", {
1847 value: function value(t, n) {
1848 function callInvokeWithMethodAndArg() {
1849 return new e(function (e, r) {
1850 invoke(t, n, e, r);
1851 });
1852 }
1853 return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1854 }
1855 });
1856 }
1857 function makeInvokeMethod(e, r, n) {
1858 var o = h;
1859 return function (i, a) {
1860 if (o === f) throw new Error("Generator is already running");
1861 if (o === s) {
1862 if ("throw" === i) throw a;
1863 return {
1864 value: t,
1865 done: !0
1866 };
1867 }
1868 for (n.method = i, n.arg = a;;) {
1869 var c = n.delegate;
1870 if (c) {
1871 var u = maybeInvokeDelegate(c, n);
1872 if (u) {
1873 if (u === y) continue;
1874 return u;
1875 }
1876 }
1877 if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
1878 if (o === h) throw o = s, n.arg;
1879 n.dispatchException(n.arg);
1880 } else "return" === n.method && n.abrupt("return", n.arg);
1881 o = f;
1882 var p = tryCatch(e, r, n);
1883 if ("normal" === p.type) {
1884 if (o = n.done ? s : l, p.arg === y) continue;
1885 return {
1886 value: p.arg,
1887 done: n.done
1888 };
1889 }
1890 "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
1891 }
1892 };
1893 }
1894 function maybeInvokeDelegate(e, r) {
1895 var n = r.method,
1896 o = e.iterator[n];
1897 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;
1898 var i = tryCatch(o, e.iterator, r.arg);
1899 if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
1900 var a = i.arg;
1901 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);
1902 }
1903 function pushTryEntry(t) {
1904 var e = {
1905 tryLoc: t[0]
1906 };
1907 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
1908 }
1909 function resetTryEntry(t) {
1910 var e = t.completion || {};
1911 e.type = "normal", delete e.arg, t.completion = e;
1912 }
1913 function Context(t) {
1914 this.tryEntries = [{
1915 tryLoc: "root"
1916 }], t.forEach(pushTryEntry, this), this.reset(!0);
1917 }
1918 function values(e) {
1919 if (e || "" === e) {
1920 var r = e[a];
1921 if (r) return r.call(e);
1922 if ("function" == typeof e.next) return e;
1923 if (!isNaN(e.length)) {
1924 var o = -1,
1925 i = function next() {
1926 for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
1927 return next.value = t, next.done = !0, next;
1928 };
1929 return i.next = i;
1930 }
1931 }
1932 throw new TypeError(_typeof(e) + " is not iterable");
1933 }
1934 return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
1935 value: GeneratorFunctionPrototype,
1936 configurable: !0
1937 }), o(GeneratorFunctionPrototype, "constructor", {
1938 value: GeneratorFunction,
1939 configurable: !0
1940 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
1941 var e = "function" == typeof t && t.constructor;
1942 return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
1943 }, e.mark = function (t) {
1944 return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
1945 }, e.awrap = function (t) {
1946 return {
1947 __await: t
1948 };
1949 }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
1950 return this;
1951 }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
1952 void 0 === i && (i = Promise);
1953 var a = new AsyncIterator(wrap(t, r, n, o), i);
1954 return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
1955 return t.done ? t.value : a.next();
1956 });
1957 }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
1958 return this;
1959 }), define(g, "toString", function () {
1960 return "[object Generator]";
1961 }), e.keys = function (t) {
1962 var e = Object(t),
1963 r = [];
1964 for (var n in e) r.push(n);
1965 return r.reverse(), function next() {
1966 for (; r.length;) {
1967 var t = r.pop();
1968 if (t in e) return next.value = t, next.done = !1, next;
1969 }
1970 return next.done = !0, next;
1971 };
1972 }, e.values = values, Context.prototype = {
1973 constructor: Context,
1974 reset: function reset(e) {
1975 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);
1976 },
1977 stop: function stop() {
1978 this.done = !0;
1979 var t = this.tryEntries[0].completion;
1980 if ("throw" === t.type) throw t.arg;
1981 return this.rval;
1982 },
1983 dispatchException: function dispatchException(e) {
1984 if (this.done) throw e;
1985 var r = this;
1986 function handle(n, o) {
1987 return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
1988 }
1989 for (var o = this.tryEntries.length - 1; o >= 0; --o) {
1990 var i = this.tryEntries[o],
1991 a = i.completion;
1992 if ("root" === i.tryLoc) return handle("end");
1993 if (i.tryLoc <= this.prev) {
1994 var c = n.call(i, "catchLoc"),
1995 u = n.call(i, "finallyLoc");
1996 if (c && u) {
1997 if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
1998 if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
1999 } else if (c) {
2000 if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
2001 } else {
2002 if (!u) throw new Error("try statement without catch or finally");
2003 if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
2004 }
2005 }
2006 }
2007 },
2008 abrupt: function abrupt(t, e) {
2009 for (var r = this.tryEntries.length - 1; r >= 0; --r) {
2010 var o = this.tryEntries[r];
2011 if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
2012 var i = o;
2013 break;
2014 }
2015 }
2016 i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
2017 var a = i ? i.completion : {};
2018 return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
2019 },
2020 complete: function complete(t, e) {
2021 if ("throw" === t.type) throw t.arg;
2022 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;
2023 },
2024 finish: function finish(t) {
2025 for (var e = this.tryEntries.length - 1; e >= 0; --e) {
2026 var r = this.tryEntries[e];
2027 if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
2028 }
2029 },
2030 "catch": function _catch(t) {
2031 for (var e = this.tryEntries.length - 1; e >= 0; --e) {
2032 var r = this.tryEntries[e];
2033 if (r.tryLoc === t) {
2034 var n = r.completion;
2035 if ("throw" === n.type) {
2036 var o = n.arg;
2037 resetTryEntry(r);
2038 }
2039 return o;
2040 }
2041 }
2042 throw new Error("illegal catch attempt");
2043 },
2044 delegateYield: function delegateYield(e, r, n) {
2045 return this.delegate = {
2046 iterator: values(e),
2047 resultName: r,
2048 nextLoc: n
2049 }, "next" === this.method && (this.arg = t), y;
2050 }
2051 }, e;
2052 }
2053 module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
2054 });
2055
2056 unwrapExports(regeneratorRuntime$1);
2057
2058 // TODO(Babel 8): Remove this file.
2059
2060 var runtime = regeneratorRuntime$1();
2061 var regenerator = runtime;
2062
2063 // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
2064 try {
2065 regeneratorRuntime = runtime;
2066 } catch (accidentalStrictMode) {
2067 if (typeof globalThis === "object") {
2068 globalThis.regeneratorRuntime = runtime;
2069 } else {
2070 Function("r", "regeneratorRuntime = r")(runtime);
2071 }
2072 }
2073
2074 var _excluded$4 = ["anchor", "focus"];
2075 function ownKeys$d(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; }
2076 function _objectSpread$d(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$d(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$d(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2077 // eslint-disable-next-line no-redeclare
2078 var Range = {
2079 edges: function edges(range) {
2080 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2081 var _options$reverse = options.reverse,
2082 reverse = _options$reverse === void 0 ? false : _options$reverse;
2083 var anchor = range.anchor,
2084 focus = range.focus;
2085 return Range.isBackward(range) === reverse ? [anchor, focus] : [focus, anchor];
2086 },
2087 end: function end(range) {
2088 var _Range$edges = Range.edges(range),
2089 _Range$edges2 = _slicedToArray(_Range$edges, 2),
2090 end = _Range$edges2[1];
2091 return end;
2092 },
2093 equals: function equals(range, another) {
2094 return Point.equals(range.anchor, another.anchor) && Point.equals(range.focus, another.focus);
2095 },
2096 includes: function includes(range, target) {
2097 if (Range.isRange(target)) {
2098 if (Range.includes(range, target.anchor) || Range.includes(range, target.focus)) {
2099 return true;
2100 }
2101 var _Range$edges3 = Range.edges(range),
2102 _Range$edges4 = _slicedToArray(_Range$edges3, 2),
2103 rs = _Range$edges4[0],
2104 re = _Range$edges4[1];
2105 var _Range$edges5 = Range.edges(target),
2106 _Range$edges6 = _slicedToArray(_Range$edges5, 2),
2107 ts = _Range$edges6[0],
2108 te = _Range$edges6[1];
2109 return Point.isBefore(rs, ts) && Point.isAfter(re, te);
2110 }
2111 var _Range$edges7 = Range.edges(range),
2112 _Range$edges8 = _slicedToArray(_Range$edges7, 2),
2113 start = _Range$edges8[0],
2114 end = _Range$edges8[1];
2115 var isAfterStart = false;
2116 var isBeforeEnd = false;
2117 if (Point.isPoint(target)) {
2118 isAfterStart = Point.compare(target, start) >= 0;
2119 isBeforeEnd = Point.compare(target, end) <= 0;
2120 } else {
2121 isAfterStart = Path.compare(target, start.path) >= 0;
2122 isBeforeEnd = Path.compare(target, end.path) <= 0;
2123 }
2124 return isAfterStart && isBeforeEnd;
2125 },
2126 intersection: function intersection(range, another) {
2127 range.anchor;
2128 range.focus;
2129 var rest = _objectWithoutProperties(range, _excluded$4);
2130 var _Range$edges9 = Range.edges(range),
2131 _Range$edges10 = _slicedToArray(_Range$edges9, 2),
2132 s1 = _Range$edges10[0],
2133 e1 = _Range$edges10[1];
2134 var _Range$edges11 = Range.edges(another),
2135 _Range$edges12 = _slicedToArray(_Range$edges11, 2),
2136 s2 = _Range$edges12[0],
2137 e2 = _Range$edges12[1];
2138 var start = Point.isBefore(s1, s2) ? s2 : s1;
2139 var end = Point.isBefore(e1, e2) ? e1 : e2;
2140 if (Point.isBefore(end, start)) {
2141 return null;
2142 } else {
2143 return _objectSpread$d({
2144 anchor: start,
2145 focus: end
2146 }, rest);
2147 }
2148 },
2149 isBackward: function isBackward(range) {
2150 var anchor = range.anchor,
2151 focus = range.focus;
2152 return Point.isAfter(anchor, focus);
2153 },
2154 isCollapsed: function isCollapsed(range) {
2155 var anchor = range.anchor,
2156 focus = range.focus;
2157 return Point.equals(anchor, focus);
2158 },
2159 isExpanded: function isExpanded(range) {
2160 return !Range.isCollapsed(range);
2161 },
2162 isForward: function isForward(range) {
2163 return !Range.isBackward(range);
2164 },
2165 isRange: function isRange(value) {
2166 return isPlainObject(value) && Point.isPoint(value.anchor) && Point.isPoint(value.focus);
2167 },
2168 points: /*#__PURE__*/regenerator.mark(function points(range) {
2169 return regenerator.wrap(function points$(_context) {
2170 while (1) switch (_context.prev = _context.next) {
2171 case 0:
2172 _context.next = 2;
2173 return [range.anchor, 'anchor'];
2174 case 2:
2175 _context.next = 4;
2176 return [range.focus, 'focus'];
2177 case 4:
2178 case "end":
2179 return _context.stop();
2180 }
2181 }, points);
2182 }),
2183 start: function start(range) {
2184 var _Range$edges13 = Range.edges(range),
2185 _Range$edges14 = _slicedToArray(_Range$edges13, 1),
2186 start = _Range$edges14[0];
2187 return start;
2188 },
2189 transform: function transform(range, op) {
2190 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2191 return produce(range, function (r) {
2192 if (r === null) {
2193 return null;
2194 }
2195 var _options$affinity = options.affinity,
2196 affinity = _options$affinity === void 0 ? 'inward' : _options$affinity;
2197 var affinityAnchor;
2198 var affinityFocus;
2199 if (affinity === 'inward') {
2200 // If the range is collapsed, make sure to use the same affinity to
2201 // avoid the two points passing each other and expanding in the opposite
2202 // direction
2203 var isCollapsed = Range.isCollapsed(r);
2204 if (Range.isForward(r)) {
2205 affinityAnchor = 'forward';
2206 affinityFocus = isCollapsed ? affinityAnchor : 'backward';
2207 } else {
2208 affinityAnchor = 'backward';
2209 affinityFocus = isCollapsed ? affinityAnchor : 'forward';
2210 }
2211 } else if (affinity === 'outward') {
2212 if (Range.isForward(r)) {
2213 affinityAnchor = 'backward';
2214 affinityFocus = 'forward';
2215 } else {
2216 affinityAnchor = 'forward';
2217 affinityFocus = 'backward';
2218 }
2219 } else {
2220 affinityAnchor = affinity;
2221 affinityFocus = affinity;
2222 }
2223 var anchor = Point.transform(r.anchor, op, {
2224 affinity: affinityAnchor
2225 });
2226 var focus = Point.transform(r.focus, op, {
2227 affinity: affinityFocus
2228 });
2229 if (!anchor || !focus) {
2230 return null;
2231 }
2232 r.anchor = anchor;
2233 r.focus = focus;
2234 });
2235 }
2236 };
2237
2238 /**
2239 * Shared the function with isElementType utility
2240 */
2241 var isElement = function isElement(value) {
2242 return isPlainObject(value) && Node.isNodeList(value.children) && !Editor.isEditor(value);
2243 };
2244 // eslint-disable-next-line no-redeclare
2245 var Element = {
2246 isAncestor: function isAncestor(value) {
2247 return isPlainObject(value) && Node.isNodeList(value.children);
2248 },
2249 isElement: isElement,
2250 isElementList: function isElementList(value) {
2251 return Array.isArray(value) && value.every(function (val) {
2252 return Element.isElement(val);
2253 });
2254 },
2255 isElementProps: function isElementProps(props) {
2256 return props.children !== undefined;
2257 },
2258 isElementType: function isElementType(value, elementVal) {
2259 var elementKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'type';
2260 return isElement(value) && value[elementKey] === elementVal;
2261 },
2262 matches: function matches(element, props) {
2263 for (var key in props) {
2264 if (key === 'children') {
2265 continue;
2266 }
2267 if (element[key] !== props[key]) {
2268 return false;
2269 }
2270 }
2271 return true;
2272 }
2273 };
2274
2275 var _excluded$3 = ["children"],
2276 _excluded2$3 = ["text"];
2277 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; } } }; }
2278 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); }
2279 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; }
2280 var IS_NODE_LIST_CACHE = new WeakMap();
2281 // eslint-disable-next-line no-redeclare
2282 var Node = {
2283 ancestor: function ancestor(root, path) {
2284 var node = Node.get(root, path);
2285 if (Text.isText(node)) {
2286 throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(Scrubber.stringify(node)));
2287 }
2288 return node;
2289 },
2290 ancestors: function ancestors(root, path) {
2291 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2292 return /*#__PURE__*/regenerator.mark(function _callee() {
2293 var _iterator, _step, p, n, entry;
2294 return regenerator.wrap(function _callee$(_context) {
2295 while (1) switch (_context.prev = _context.next) {
2296 case 0:
2297 _iterator = _createForOfIteratorHelper$l(Path.ancestors(path, options));
2298 _context.prev = 1;
2299 _iterator.s();
2300 case 3:
2301 if ((_step = _iterator.n()).done) {
2302 _context.next = 11;
2303 break;
2304 }
2305 p = _step.value;
2306 n = Node.ancestor(root, p);
2307 entry = [n, p];
2308 _context.next = 9;
2309 return entry;
2310 case 9:
2311 _context.next = 3;
2312 break;
2313 case 11:
2314 _context.next = 16;
2315 break;
2316 case 13:
2317 _context.prev = 13;
2318 _context.t0 = _context["catch"](1);
2319 _iterator.e(_context.t0);
2320 case 16:
2321 _context.prev = 16;
2322 _iterator.f();
2323 return _context.finish(16);
2324 case 19:
2325 case "end":
2326 return _context.stop();
2327 }
2328 }, _callee, null, [[1, 13, 16, 19]]);
2329 })();
2330 },
2331 child: function child(root, index) {
2332 if (Text.isText(root)) {
2333 throw new Error("Cannot get the child of a text node: ".concat(Scrubber.stringify(root)));
2334 }
2335 var c = root.children[index];
2336 if (c == null) {
2337 throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(Scrubber.stringify(root)));
2338 }
2339 return c;
2340 },
2341 children: function children(root, path) {
2342 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2343 return /*#__PURE__*/regenerator.mark(function _callee2() {
2344 var _options$reverse, reverse, ancestor, children, index, child, childPath;
2345 return regenerator.wrap(function _callee2$(_context2) {
2346 while (1) switch (_context2.prev = _context2.next) {
2347 case 0:
2348 _options$reverse = options.reverse, reverse = _options$reverse === void 0 ? false : _options$reverse;
2349 ancestor = Node.ancestor(root, path);
2350 children = ancestor.children;
2351 index = reverse ? children.length - 1 : 0;
2352 case 4:
2353 if (!(reverse ? index >= 0 : index < children.length)) {
2354 _context2.next = 12;
2355 break;
2356 }
2357 child = Node.child(ancestor, index);
2358 childPath = path.concat(index);
2359 _context2.next = 9;
2360 return [child, childPath];
2361 case 9:
2362 index = reverse ? index - 1 : index + 1;
2363 _context2.next = 4;
2364 break;
2365 case 12:
2366 case "end":
2367 return _context2.stop();
2368 }
2369 }, _callee2);
2370 })();
2371 },
2372 common: function common(root, path, another) {
2373 var p = Path.common(path, another);
2374 var n = Node.get(root, p);
2375 return [n, p];
2376 },
2377 descendant: function descendant(root, path) {
2378 var node = Node.get(root, path);
2379 if (Editor.isEditor(node)) {
2380 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)));
2381 }
2382 return node;
2383 },
2384 descendants: function descendants(root) {
2385 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2386 return /*#__PURE__*/regenerator.mark(function _callee3() {
2387 var _iterator2, _step2, _step2$value, node, path;
2388 return regenerator.wrap(function _callee3$(_context3) {
2389 while (1) switch (_context3.prev = _context3.next) {
2390 case 0:
2391 _iterator2 = _createForOfIteratorHelper$l(Node.nodes(root, options));
2392 _context3.prev = 1;
2393 _iterator2.s();
2394 case 3:
2395 if ((_step2 = _iterator2.n()).done) {
2396 _context3.next = 10;
2397 break;
2398 }
2399 _step2$value = _slicedToArray(_step2.value, 2), node = _step2$value[0], path = _step2$value[1];
2400 if (!(path.length !== 0)) {
2401 _context3.next = 8;
2402 break;
2403 }
2404 _context3.next = 8;
2405 return [node, path];
2406 case 8:
2407 _context3.next = 3;
2408 break;
2409 case 10:
2410 _context3.next = 15;
2411 break;
2412 case 12:
2413 _context3.prev = 12;
2414 _context3.t0 = _context3["catch"](1);
2415 _iterator2.e(_context3.t0);
2416 case 15:
2417 _context3.prev = 15;
2418 _iterator2.f();
2419 return _context3.finish(15);
2420 case 18:
2421 case "end":
2422 return _context3.stop();
2423 }
2424 }, _callee3, null, [[1, 12, 15, 18]]);
2425 })();
2426 },
2427 elements: function elements(root) {
2428 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2429 return /*#__PURE__*/regenerator.mark(function _callee4() {
2430 var _iterator3, _step3, _step3$value, node, path;
2431 return regenerator.wrap(function _callee4$(_context4) {
2432 while (1) switch (_context4.prev = _context4.next) {
2433 case 0:
2434 _iterator3 = _createForOfIteratorHelper$l(Node.nodes(root, options));
2435 _context4.prev = 1;
2436 _iterator3.s();
2437 case 3:
2438 if ((_step3 = _iterator3.n()).done) {
2439 _context4.next = 10;
2440 break;
2441 }
2442 _step3$value = _slicedToArray(_step3.value, 2), node = _step3$value[0], path = _step3$value[1];
2443 if (!Element.isElement(node)) {
2444 _context4.next = 8;
2445 break;
2446 }
2447 _context4.next = 8;
2448 return [node, path];
2449 case 8:
2450 _context4.next = 3;
2451 break;
2452 case 10:
2453 _context4.next = 15;
2454 break;
2455 case 12:
2456 _context4.prev = 12;
2457 _context4.t0 = _context4["catch"](1);
2458 _iterator3.e(_context4.t0);
2459 case 15:
2460 _context4.prev = 15;
2461 _iterator3.f();
2462 return _context4.finish(15);
2463 case 18:
2464 case "end":
2465 return _context4.stop();
2466 }
2467 }, _callee4, null, [[1, 12, 15, 18]]);
2468 })();
2469 },
2470 extractProps: function extractProps(node) {
2471 if (Element.isAncestor(node)) {
2472 node.children;
2473 var properties = _objectWithoutProperties(node, _excluded$3);
2474 return properties;
2475 } else {
2476 node.text;
2477 var _properties = _objectWithoutProperties(node, _excluded2$3);
2478 return _properties;
2479 }
2480 },
2481 first: function first(root, path) {
2482 var p = path.slice();
2483 var n = Node.get(root, p);
2484 while (n) {
2485 if (Text.isText(n) || n.children.length === 0) {
2486 break;
2487 } else {
2488 n = n.children[0];
2489 p.push(0);
2490 }
2491 }
2492 return [n, p];
2493 },
2494 fragment: function fragment(root, range) {
2495 if (Text.isText(root)) {
2496 throw new Error("Cannot get a fragment starting from a root text node: ".concat(Scrubber.stringify(root)));
2497 }
2498 var newRoot = produce({
2499 children: root.children
2500 }, function (r) {
2501 var _Range$edges = Range.edges(range),
2502 _Range$edges2 = _slicedToArray(_Range$edges, 2),
2503 start = _Range$edges2[0],
2504 end = _Range$edges2[1];
2505 var nodeEntries = Node.nodes(r, {
2506 reverse: true,
2507 pass: function pass(_ref) {
2508 var _ref2 = _slicedToArray(_ref, 2),
2509 path = _ref2[1];
2510 return !Range.includes(range, path);
2511 }
2512 });
2513 var _iterator4 = _createForOfIteratorHelper$l(nodeEntries),
2514 _step4;
2515 try {
2516 for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2517 var _step4$value = _slicedToArray(_step4.value, 2),
2518 path = _step4$value[1];
2519 if (!Range.includes(range, path)) {
2520 var parent = Node.parent(r, path);
2521 var index = path[path.length - 1];
2522 parent.children.splice(index, 1);
2523 }
2524 if (Path.equals(path, end.path)) {
2525 var leaf = Node.leaf(r, path);
2526 leaf.text = leaf.text.slice(0, end.offset);
2527 }
2528 if (Path.equals(path, start.path)) {
2529 var _leaf = Node.leaf(r, path);
2530 _leaf.text = _leaf.text.slice(start.offset);
2531 }
2532 }
2533 } catch (err) {
2534 _iterator4.e(err);
2535 } finally {
2536 _iterator4.f();
2537 }
2538 if (Editor.isEditor(r)) {
2539 r.selection = null;
2540 }
2541 });
2542 return newRoot.children;
2543 },
2544 get: function get(root, path) {
2545 var node = root;
2546 for (var i = 0; i < path.length; i++) {
2547 var p = path[i];
2548 if (Text.isText(node) || !node.children[p]) {
2549 throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(Scrubber.stringify(root)));
2550 }
2551 node = node.children[p];
2552 }
2553 return node;
2554 },
2555 has: function has(root, path) {
2556 var node = root;
2557 for (var i = 0; i < path.length; i++) {
2558 var p = path[i];
2559 if (Text.isText(node) || !node.children[p]) {
2560 return false;
2561 }
2562 node = node.children[p];
2563 }
2564 return true;
2565 },
2566 isNode: function isNode(value) {
2567 return Text.isText(value) || Element.isElement(value) || Editor.isEditor(value);
2568 },
2569 isNodeList: function isNodeList(value) {
2570 if (!Array.isArray(value)) {
2571 return false;
2572 }
2573 var cachedResult = IS_NODE_LIST_CACHE.get(value);
2574 if (cachedResult !== undefined) {
2575 return cachedResult;
2576 }
2577 var isNodeList = value.every(function (val) {
2578 return Node.isNode(val);
2579 });
2580 IS_NODE_LIST_CACHE.set(value, isNodeList);
2581 return isNodeList;
2582 },
2583 last: function last(root, path) {
2584 var p = path.slice();
2585 var n = Node.get(root, p);
2586 while (n) {
2587 if (Text.isText(n) || n.children.length === 0) {
2588 break;
2589 } else {
2590 var i = n.children.length - 1;
2591 n = n.children[i];
2592 p.push(i);
2593 }
2594 }
2595 return [n, p];
2596 },
2597 leaf: function leaf(root, path) {
2598 var node = Node.get(root, path);
2599 if (!Text.isText(node)) {
2600 throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
2601 }
2602 return node;
2603 },
2604 levels: function levels(root, path) {
2605 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2606 return /*#__PURE__*/regenerator.mark(function _callee5() {
2607 var _iterator5, _step5, p, n;
2608 return regenerator.wrap(function _callee5$(_context5) {
2609 while (1) switch (_context5.prev = _context5.next) {
2610 case 0:
2611 _iterator5 = _createForOfIteratorHelper$l(Path.levels(path, options));
2612 _context5.prev = 1;
2613 _iterator5.s();
2614 case 3:
2615 if ((_step5 = _iterator5.n()).done) {
2616 _context5.next = 10;
2617 break;
2618 }
2619 p = _step5.value;
2620 n = Node.get(root, p);
2621 _context5.next = 8;
2622 return [n, p];
2623 case 8:
2624 _context5.next = 3;
2625 break;
2626 case 10:
2627 _context5.next = 15;
2628 break;
2629 case 12:
2630 _context5.prev = 12;
2631 _context5.t0 = _context5["catch"](1);
2632 _iterator5.e(_context5.t0);
2633 case 15:
2634 _context5.prev = 15;
2635 _iterator5.f();
2636 return _context5.finish(15);
2637 case 18:
2638 case "end":
2639 return _context5.stop();
2640 }
2641 }, _callee5, null, [[1, 12, 15, 18]]);
2642 })();
2643 },
2644 matches: function matches(node, props) {
2645 return Element.isElement(node) && Element.isElementProps(props) && Element.matches(node, props) || Text.isText(node) && Text.isTextProps(props) && Text.matches(node, props);
2646 },
2647 nodes: function nodes(root) {
2648 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2649 return /*#__PURE__*/regenerator.mark(function _callee6() {
2650 var pass, _options$reverse2, reverse, _options$from, from, to, visited, p, n, nextIndex, newPath, _newPath;
2651 return regenerator.wrap(function _callee6$(_context6) {
2652 while (1) switch (_context6.prev = _context6.next) {
2653 case 0:
2654 pass = options.pass, _options$reverse2 = options.reverse, reverse = _options$reverse2 === void 0 ? false : _options$reverse2;
2655 _options$from = options.from, from = _options$from === void 0 ? [] : _options$from, to = options.to;
2656 visited = new Set();
2657 p = [];
2658 n = root;
2659 case 5:
2660 if (!(to && (reverse ? Path.isBefore(p, to) : Path.isAfter(p, to)))) {
2661 _context6.next = 8;
2662 break;
2663 }
2664 return _context6.abrupt("break", 36);
2665 case 8:
2666 if (visited.has(n)) {
2667 _context6.next = 11;
2668 break;
2669 }
2670 _context6.next = 11;
2671 return [n, p];
2672 case 11:
2673 if (!(!visited.has(n) && !Text.isText(n) && n.children.length !== 0 && (pass == null || pass([n, p]) === false))) {
2674 _context6.next = 18;
2675 break;
2676 }
2677 visited.add(n);
2678 nextIndex = reverse ? n.children.length - 1 : 0;
2679 if (Path.isAncestor(p, from)) {
2680 nextIndex = from[p.length];
2681 }
2682 p = p.concat(nextIndex);
2683 n = Node.get(root, p);
2684 return _context6.abrupt("continue", 5);
2685 case 18:
2686 if (!(p.length === 0)) {
2687 _context6.next = 20;
2688 break;
2689 }
2690 return _context6.abrupt("break", 36);
2691 case 20:
2692 if (reverse) {
2693 _context6.next = 26;
2694 break;
2695 }
2696 newPath = Path.next(p);
2697 if (!Node.has(root, newPath)) {
2698 _context6.next = 26;
2699 break;
2700 }
2701 p = newPath;
2702 n = Node.get(root, p);
2703 return _context6.abrupt("continue", 5);
2704 case 26:
2705 if (!(reverse && p[p.length - 1] !== 0)) {
2706 _context6.next = 31;
2707 break;
2708 }
2709 _newPath = Path.previous(p);
2710 p = _newPath;
2711 n = Node.get(root, p);
2712 return _context6.abrupt("continue", 5);
2713 case 31:
2714 // Otherwise we're going upward...
2715 p = Path.parent(p);
2716 n = Node.get(root, p);
2717 visited.add(n);
2718 _context6.next = 5;
2719 break;
2720 case 36:
2721 case "end":
2722 return _context6.stop();
2723 }
2724 }, _callee6);
2725 })();
2726 },
2727 parent: function parent(root, path) {
2728 var parentPath = Path.parent(path);
2729 var p = Node.get(root, parentPath);
2730 if (Text.isText(p)) {
2731 throw new Error("Cannot get the parent of path [".concat(path, "] because it does not exist in the root."));
2732 }
2733 return p;
2734 },
2735 string: function string(node) {
2736 if (Text.isText(node)) {
2737 return node.text;
2738 } else {
2739 return node.children.map(Node.string).join('');
2740 }
2741 },
2742 texts: function texts(root) {
2743 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2744 return /*#__PURE__*/regenerator.mark(function _callee7() {
2745 var _iterator6, _step6, _step6$value, node, path;
2746 return regenerator.wrap(function _callee7$(_context7) {
2747 while (1) switch (_context7.prev = _context7.next) {
2748 case 0:
2749 _iterator6 = _createForOfIteratorHelper$l(Node.nodes(root, options));
2750 _context7.prev = 1;
2751 _iterator6.s();
2752 case 3:
2753 if ((_step6 = _iterator6.n()).done) {
2754 _context7.next = 10;
2755 break;
2756 }
2757 _step6$value = _slicedToArray(_step6.value, 2), node = _step6$value[0], path = _step6$value[1];
2758 if (!Text.isText(node)) {
2759 _context7.next = 8;
2760 break;
2761 }
2762 _context7.next = 8;
2763 return [node, path];
2764 case 8:
2765 _context7.next = 3;
2766 break;
2767 case 10:
2768 _context7.next = 15;
2769 break;
2770 case 12:
2771 _context7.prev = 12;
2772 _context7.t0 = _context7["catch"](1);
2773 _iterator6.e(_context7.t0);
2774 case 15:
2775 _context7.prev = 15;
2776 _iterator6.f();
2777 return _context7.finish(15);
2778 case 18:
2779 case "end":
2780 return _context7.stop();
2781 }
2782 }, _callee7, null, [[1, 12, 15, 18]]);
2783 })();
2784 }
2785 };
2786
2787 function ownKeys$c(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; }
2788 function _objectSpread$c(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$c(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2789 // eslint-disable-next-line no-redeclare
2790 var Operation = {
2791 isNodeOperation: function isNodeOperation(value) {
2792 return Operation.isOperation(value) && value.type.endsWith('_node');
2793 },
2794 isOperation: function isOperation(value) {
2795 if (!isPlainObject(value)) {
2796 return false;
2797 }
2798 switch (value.type) {
2799 case 'insert_node':
2800 return Path.isPath(value.path) && Node.isNode(value.node);
2801 case 'insert_text':
2802 return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
2803 case 'merge_node':
2804 return typeof value.position === 'number' && Path.isPath(value.path) && isPlainObject(value.properties);
2805 case 'move_node':
2806 return Path.isPath(value.path) && Path.isPath(value.newPath);
2807 case 'remove_node':
2808 return Path.isPath(value.path) && Node.isNode(value.node);
2809 case 'remove_text':
2810 return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
2811 case 'set_node':
2812 return Path.isPath(value.path) && isPlainObject(value.properties) && isPlainObject(value.newProperties);
2813 case 'set_selection':
2814 return value.properties === null && Range.isRange(value.newProperties) || value.newProperties === null && Range.isRange(value.properties) || isPlainObject(value.properties) && isPlainObject(value.newProperties);
2815 case 'split_node':
2816 return Path.isPath(value.path) && typeof value.position === 'number' && isPlainObject(value.properties);
2817 default:
2818 return false;
2819 }
2820 },
2821 isOperationList: function isOperationList(value) {
2822 return Array.isArray(value) && value.every(function (val) {
2823 return Operation.isOperation(val);
2824 });
2825 },
2826 isSelectionOperation: function isSelectionOperation(value) {
2827 return Operation.isOperation(value) && value.type.endsWith('_selection');
2828 },
2829 isTextOperation: function isTextOperation(value) {
2830 return Operation.isOperation(value) && value.type.endsWith('_text');
2831 },
2832 inverse: function inverse(op) {
2833 switch (op.type) {
2834 case 'insert_node':
2835 {
2836 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2837 type: 'remove_node'
2838 });
2839 }
2840 case 'insert_text':
2841 {
2842 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2843 type: 'remove_text'
2844 });
2845 }
2846 case 'merge_node':
2847 {
2848 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2849 type: 'split_node',
2850 path: Path.previous(op.path)
2851 });
2852 }
2853 case 'move_node':
2854 {
2855 var newPath = op.newPath,
2856 path = op.path;
2857 // PERF: in this case the move operation is a no-op anyways.
2858 if (Path.equals(newPath, path)) {
2859 return op;
2860 }
2861 // If the move happens completely within a single parent the path and
2862 // newPath are stable with respect to each other.
2863 if (Path.isSibling(path, newPath)) {
2864 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2865 path: newPath,
2866 newPath: path
2867 });
2868 }
2869 // If the move does not happen within a single parent it is possible
2870 // for the move to impact the true path to the location where the node
2871 // was removed from and where it was inserted. We have to adjust for this
2872 // and find the original path. We can accomplish this (only in non-sibling)
2873 // moves by looking at the impact of the move operation on the node
2874 // after the original move path.
2875 var inversePath = Path.transform(path, op);
2876 var inverseNewPath = Path.transform(Path.next(path), op);
2877 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2878 path: inversePath,
2879 newPath: inverseNewPath
2880 });
2881 }
2882 case 'remove_node':
2883 {
2884 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2885 type: 'insert_node'
2886 });
2887 }
2888 case 'remove_text':
2889 {
2890 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2891 type: 'insert_text'
2892 });
2893 }
2894 case 'set_node':
2895 {
2896 var properties = op.properties,
2897 newProperties = op.newProperties;
2898 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2899 properties: newProperties,
2900 newProperties: properties
2901 });
2902 }
2903 case 'set_selection':
2904 {
2905 var _properties = op.properties,
2906 _newProperties = op.newProperties;
2907 if (_properties == null) {
2908 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2909 properties: _newProperties,
2910 newProperties: null
2911 });
2912 } else if (_newProperties == null) {
2913 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2914 properties: null,
2915 newProperties: _properties
2916 });
2917 } else {
2918 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2919 properties: _newProperties,
2920 newProperties: _properties
2921 });
2922 }
2923 }
2924 case 'split_node':
2925 {
2926 return _objectSpread$c(_objectSpread$c({}, op), {}, {
2927 type: 'merge_node',
2928 path: Path.next(op.path)
2929 });
2930 }
2931 }
2932 }
2933 };
2934
2935 var IS_EDITOR_CACHE = new WeakMap();
2936 var isEditor = function isEditor(value) {
2937 var cachedIsEditor = IS_EDITOR_CACHE.get(value);
2938 if (cachedIsEditor !== undefined) {
2939 return cachedIsEditor;
2940 }
2941 if (!isPlainObject(value)) {
2942 return false;
2943 }
2944 var isEditor = typeof value.addMark === 'function' && typeof value.apply === 'function' && typeof value.deleteFragment === 'function' && typeof value.insertBreak === 'function' && typeof value.insertSoftBreak === 'function' && typeof value.insertFragment === 'function' && typeof value.insertNode === 'function' && typeof value.insertText === 'function' && typeof value.isElementReadOnly === 'function' && typeof value.isInline === 'function' && typeof value.isSelectable === 'function' && typeof value.isVoid === 'function' && typeof value.normalizeNode === 'function' && typeof value.onChange === 'function' && typeof value.removeMark === 'function' && typeof value.getDirtyPaths === 'function' && (value.marks === null || isPlainObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.children) && Operation.isOperationList(value.operations);
2945 IS_EDITOR_CACHE.set(value, isEditor);
2946 return isEditor;
2947 };
2948
2949 // eslint-disable-next-line no-redeclare
2950 var Editor = {
2951 above: function above(editor, options) {
2952 return editor.above(options);
2953 },
2954 addMark: function addMark(editor, key, value) {
2955 editor.addMark(key, value);
2956 },
2957 after: function after(editor, at, options) {
2958 return editor.after(at, options);
2959 },
2960 before: function before(editor, at, options) {
2961 return editor.before(at, options);
2962 },
2963 deleteBackward: function deleteBackward(editor) {
2964 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2965 var _options$unit = options.unit,
2966 unit = _options$unit === void 0 ? 'character' : _options$unit;
2967 editor.deleteBackward(unit);
2968 },
2969 deleteForward: function deleteForward(editor) {
2970 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2971 var _options$unit2 = options.unit,
2972 unit = _options$unit2 === void 0 ? 'character' : _options$unit2;
2973 editor.deleteForward(unit);
2974 },
2975 deleteFragment: function deleteFragment(editor, options) {
2976 editor.deleteFragment(options);
2977 },
2978 edges: function edges(editor, at) {
2979 return editor.edges(at);
2980 },
2981 elementReadOnly: function elementReadOnly(editor) {
2982 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2983 return editor.elementReadOnly(options);
2984 },
2985 end: function end(editor, at) {
2986 return editor.end(at);
2987 },
2988 first: function first(editor, at) {
2989 return editor.first(at);
2990 },
2991 fragment: function fragment(editor, at) {
2992 return editor.fragment(at);
2993 },
2994 hasBlocks: function hasBlocks(editor, element) {
2995 return editor.hasBlocks(element);
2996 },
2997 hasInlines: function hasInlines(editor, element) {
2998 return editor.hasInlines(element);
2999 },
3000 hasPath: function hasPath(editor, path) {
3001 return editor.hasPath(path);
3002 },
3003 hasTexts: function hasTexts(editor, element) {
3004 return editor.hasTexts(element);
3005 },
3006 insertBreak: function insertBreak(editor) {
3007 editor.insertBreak();
3008 },
3009 insertFragment: function insertFragment(editor, fragment, options) {
3010 editor.insertFragment(fragment, options);
3011 },
3012 insertNode: function insertNode(editor, node) {
3013 editor.insertNode(node);
3014 },
3015 insertSoftBreak: function insertSoftBreak(editor) {
3016 editor.insertSoftBreak();
3017 },
3018 insertText: function insertText(editor, text) {
3019 editor.insertText(text);
3020 },
3021 isBlock: function isBlock(editor, value) {
3022 return editor.isBlock(value);
3023 },
3024 isEdge: function isEdge(editor, point, at) {
3025 return editor.isEdge(point, at);
3026 },
3027 isEditor: function isEditor$1(value) {
3028 return isEditor(value);
3029 },
3030 isElementReadOnly: function isElementReadOnly(editor, element) {
3031 return editor.isElementReadOnly(element);
3032 },
3033 isEmpty: function isEmpty(editor, element) {
3034 return editor.isEmpty(element);
3035 },
3036 isEnd: function isEnd(editor, point, at) {
3037 return editor.isEnd(point, at);
3038 },
3039 isInline: function isInline(editor, value) {
3040 return editor.isInline(value);
3041 },
3042 isNormalizing: function isNormalizing(editor) {
3043 return editor.isNormalizing();
3044 },
3045 isSelectable: function isSelectable(editor, value) {
3046 return editor.isSelectable(value);
3047 },
3048 isStart: function isStart(editor, point, at) {
3049 return editor.isStart(point, at);
3050 },
3051 isVoid: function isVoid(editor, value) {
3052 return editor.isVoid(value);
3053 },
3054 last: function last(editor, at) {
3055 return editor.last(at);
3056 },
3057 leaf: function leaf(editor, at, options) {
3058 return editor.leaf(at, options);
3059 },
3060 levels: function levels(editor, options) {
3061 return editor.levels(options);
3062 },
3063 marks: function marks(editor) {
3064 return editor.getMarks();
3065 },
3066 next: function next(editor, options) {
3067 return editor.next(options);
3068 },
3069 node: function node(editor, at, options) {
3070 return editor.node(at, options);
3071 },
3072 nodes: function nodes(editor, options) {
3073 return editor.nodes(options);
3074 },
3075 normalize: function normalize(editor, options) {
3076 editor.normalize(options);
3077 },
3078 parent: function parent(editor, at, options) {
3079 return editor.parent(at, options);
3080 },
3081 path: function path(editor, at, options) {
3082 return editor.path(at, options);
3083 },
3084 pathRef: function pathRef(editor, path, options) {
3085 return editor.pathRef(path, options);
3086 },
3087 pathRefs: function pathRefs(editor) {
3088 return editor.pathRefs();
3089 },
3090 point: function point(editor, at, options) {
3091 return editor.point(at, options);
3092 },
3093 pointRef: function pointRef(editor, point, options) {
3094 return editor.pointRef(point, options);
3095 },
3096 pointRefs: function pointRefs(editor) {
3097 return editor.pointRefs();
3098 },
3099 positions: function positions(editor, options) {
3100 return editor.positions(options);
3101 },
3102 previous: function previous(editor, options) {
3103 return editor.previous(options);
3104 },
3105 range: function range(editor, at, to) {
3106 return editor.range(at, to);
3107 },
3108 rangeRef: function rangeRef(editor, range, options) {
3109 return editor.rangeRef(range, options);
3110 },
3111 rangeRefs: function rangeRefs(editor) {
3112 return editor.rangeRefs();
3113 },
3114 removeMark: function removeMark(editor, key) {
3115 editor.removeMark(key);
3116 },
3117 setNormalizing: function setNormalizing(editor, isNormalizing) {
3118 editor.setNormalizing(isNormalizing);
3119 },
3120 start: function start(editor, at) {
3121 return editor.start(at);
3122 },
3123 string: function string(editor, at, options) {
3124 return editor.string(at, options);
3125 },
3126 unhangRange: function unhangRange(editor, range, options) {
3127 return editor.unhangRange(range, options);
3128 },
3129 "void": function _void(editor, options) {
3130 return editor["void"](options);
3131 },
3132 withoutNormalizing: function withoutNormalizing(editor, fn) {
3133 editor.withoutNormalizing(fn);
3134 },
3135 shouldMergeNodesRemovePrevNode: function shouldMergeNodesRemovePrevNode(editor, prevNode, curNode) {
3136 return editor.shouldMergeNodesRemovePrevNode(prevNode, curNode);
3137 }
3138 };
3139
3140 // eslint-disable-next-line no-redeclare
3141 var Location = {
3142 isLocation: function isLocation(value) {
3143 return Path.isPath(value) || Point.isPoint(value) || Range.isRange(value);
3144 }
3145 };
3146 // eslint-disable-next-line no-redeclare
3147 var Span = {
3148 isSpan: function isSpan(value) {
3149 return Array.isArray(value) && value.length === 2 && value.every(Path.isPath);
3150 }
3151 };
3152
3153 function ownKeys$b(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; }
3154 function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3155 // eslint-disable-next-line no-redeclare
3156 var Point = {
3157 compare: function compare(point, another) {
3158 var result = Path.compare(point.path, another.path);
3159 if (result === 0) {
3160 if (point.offset < another.offset) return -1;
3161 if (point.offset > another.offset) return 1;
3162 return 0;
3163 }
3164 return result;
3165 },
3166 isAfter: function isAfter(point, another) {
3167 return Point.compare(point, another) === 1;
3168 },
3169 isBefore: function isBefore(point, another) {
3170 return Point.compare(point, another) === -1;
3171 },
3172 equals: function equals(point, another) {
3173 // PERF: ensure the offsets are equal first since they are cheaper to check.
3174 return point.offset === another.offset && Path.equals(point.path, another.path);
3175 },
3176 isPoint: function isPoint(value) {
3177 return isPlainObject(value) && typeof value.offset === 'number' && Path.isPath(value.path);
3178 },
3179 transform: function transform(point, op) {
3180 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
3181 return produce(point, function (p) {
3182 if (p === null) {
3183 return null;
3184 }
3185 var _options$affinity = options.affinity,
3186 affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
3187 var path = p.path,
3188 offset = p.offset;
3189 switch (op.type) {
3190 case 'insert_node':
3191 case 'move_node':
3192 {
3193 p.path = Path.transform(path, op, options);
3194 break;
3195 }
3196 case 'insert_text':
3197 {
3198 if (Path.equals(op.path, path) && (op.offset < offset || op.offset === offset && affinity === 'forward')) {
3199 p.offset += op.text.length;
3200 }
3201 break;
3202 }
3203 case 'merge_node':
3204 {
3205 if (Path.equals(op.path, path)) {
3206 p.offset += op.position;
3207 }
3208 p.path = Path.transform(path, op, options);
3209 break;
3210 }
3211 case 'remove_text':
3212 {
3213 if (Path.equals(op.path, path) && op.offset <= offset) {
3214 p.offset -= Math.min(offset - op.offset, op.text.length);
3215 }
3216 break;
3217 }
3218 case 'remove_node':
3219 {
3220 if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) {
3221 return null;
3222 }
3223 p.path = Path.transform(path, op, options);
3224 break;
3225 }
3226 case 'split_node':
3227 {
3228 if (Path.equals(op.path, path)) {
3229 if (op.position === offset && affinity == null) {
3230 return null;
3231 } else if (op.position < offset || op.position === offset && affinity === 'forward') {
3232 p.offset -= op.position;
3233 p.path = Path.transform(path, op, _objectSpread$b(_objectSpread$b({}, options), {}, {
3234 affinity: 'forward'
3235 }));
3236 }
3237 } else {
3238 p.path = Path.transform(path, op, options);
3239 }
3240 break;
3241 }
3242 }
3243 });
3244 }
3245 };
3246
3247 var _scrubber = undefined;
3248 /**
3249 * This interface implements a stringify() function, which is used by Slate
3250 * internally when generating exceptions containing end user data. Developers
3251 * using Slate may call Scrubber.setScrubber() to alter the behavior of this
3252 * stringify() function.
3253 *
3254 * For example, to prevent the cleartext logging of 'text' fields within Nodes:
3255 *
3256 * import { Scrubber } from 'slate';
3257 * Scrubber.setScrubber((key, val) => {
3258 * if (key === 'text') return '...scrubbed...'
3259 * return val
3260 * });
3261 *
3262 */
3263 // eslint-disable-next-line no-redeclare
3264 var Scrubber = {
3265 setScrubber: function setScrubber(scrubber) {
3266 _scrubber = scrubber;
3267 },
3268 stringify: function stringify(value) {
3269 return JSON.stringify(value, _scrubber);
3270 }
3271 };
3272
3273 var _excluded$2 = ["text"],
3274 _excluded2$2 = ["anchor", "focus"];
3275 function _createForOfIteratorHelper$k(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$k(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; } } }; }
3276 function _unsupportedIterableToArray$k(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$k(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$k(o, minLen); }
3277 function _arrayLikeToArray$k(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; }
3278 function ownKeys$a(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; }
3279 function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3280 // eslint-disable-next-line no-redeclare
3281 var Text = {
3282 equals: function equals(text, another) {
3283 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
3284 var _options$loose = options.loose,
3285 loose = _options$loose === void 0 ? false : _options$loose;
3286 function omitText(obj) {
3287 obj.text;
3288 var rest = _objectWithoutProperties(obj, _excluded$2);
3289 return rest;
3290 }
3291 return isDeepEqual(loose ? omitText(text) : text, loose ? omitText(another) : another);
3292 },
3293 isText: function isText(value) {
3294 return isPlainObject(value) && typeof value.text === 'string';
3295 },
3296 isTextList: function isTextList(value) {
3297 return Array.isArray(value) && value.every(function (val) {
3298 return Text.isText(val);
3299 });
3300 },
3301 isTextProps: function isTextProps(props) {
3302 return props.text !== undefined;
3303 },
3304 matches: function matches(text, props) {
3305 for (var key in props) {
3306 if (key === 'text') {
3307 continue;
3308 }
3309 if (!text.hasOwnProperty(key) || text[key] !== props[key]) {
3310 return false;
3311 }
3312 }
3313 return true;
3314 },
3315 decorations: function decorations(node, _decorations) {
3316 var leaves = [_objectSpread$a({}, node)];
3317 var _iterator = _createForOfIteratorHelper$k(_decorations),
3318 _step;
3319 try {
3320 for (_iterator.s(); !(_step = _iterator.n()).done;) {
3321 var dec = _step.value;
3322 var anchor = dec.anchor,
3323 focus = dec.focus,
3324 rest = _objectWithoutProperties(dec, _excluded2$2);
3325 var _Range$edges = Range.edges(dec),
3326 _Range$edges2 = _slicedToArray(_Range$edges, 2),
3327 start = _Range$edges2[0],
3328 end = _Range$edges2[1];
3329 var next = [];
3330 var leafEnd = 0;
3331 var decorationStart = start.offset;
3332 var decorationEnd = end.offset;
3333 var _iterator2 = _createForOfIteratorHelper$k(leaves),
3334 _step2;
3335 try {
3336 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3337 var leaf = _step2.value;
3338 var length = leaf.text.length;
3339 var leafStart = leafEnd;
3340 leafEnd += length;
3341 // If the range encompasses the entire leaf, add the range.
3342 if (decorationStart <= leafStart && leafEnd <= decorationEnd) {
3343 Object.assign(leaf, rest);
3344 next.push(leaf);
3345 continue;
3346 }
3347 // If the range expanded and match the leaf, or starts after, or ends before it, continue.
3348 if (decorationStart !== decorationEnd && (decorationStart === leafEnd || decorationEnd === leafStart) || decorationStart > leafEnd || decorationEnd < leafStart || decorationEnd === leafStart && leafStart !== 0) {
3349 next.push(leaf);
3350 continue;
3351 }
3352 // Otherwise we need to split the leaf, at the start, end, or both,
3353 // and add the range to the middle intersecting section. Do the end
3354 // split first since we don't need to update the offset that way.
3355 var middle = leaf;
3356 var before = void 0;
3357 var after = void 0;
3358 if (decorationEnd < leafEnd) {
3359 var off = decorationEnd - leafStart;
3360 after = _objectSpread$a(_objectSpread$a({}, middle), {}, {
3361 text: middle.text.slice(off)
3362 });
3363 middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
3364 text: middle.text.slice(0, off)
3365 });
3366 }
3367 if (decorationStart > leafStart) {
3368 var _off = decorationStart - leafStart;
3369 before = _objectSpread$a(_objectSpread$a({}, middle), {}, {
3370 text: middle.text.slice(0, _off)
3371 });
3372 middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
3373 text: middle.text.slice(_off)
3374 });
3375 }
3376 Object.assign(middle, rest);
3377 if (before) {
3378 next.push(before);
3379 }
3380 next.push(middle);
3381 if (after) {
3382 next.push(after);
3383 }
3384 }
3385 } catch (err) {
3386 _iterator2.e(err);
3387 } finally {
3388 _iterator2.f();
3389 }
3390 leaves = next;
3391 }
3392 } catch (err) {
3393 _iterator.e(err);
3394 } finally {
3395 _iterator.f();
3396 }
3397 return leaves;
3398 }
3399 };
3400
3401 /**
3402 * Get the default location to insert content into the editor.
3403 * By default, use the selection as the target location. But if there is
3404 * no selection, insert at the end of the document since that is such a
3405 * common use case when inserting from a non-selected state.
3406 */
3407 var getDefaultInsertLocation = function getDefaultInsertLocation(editor) {
3408 if (editor.selection) {
3409 return editor.selection;
3410 } else if (editor.children.length > 0) {
3411 return Editor.end(editor, []);
3412 } else {
3413 return [0];
3414 }
3415 };
3416
3417 var matchPath = function matchPath(editor, path) {
3418 var _Editor$node = Editor.node(editor, path),
3419 _Editor$node2 = _slicedToArray(_Editor$node, 1),
3420 node = _Editor$node2[0];
3421 return function (n) {
3422 return n === node;
3423 };
3424 };
3425
3426 function _createForOfIteratorHelper$j(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$j(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; } } }; }
3427 function _unsupportedIterableToArray$j(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$j(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$j(o, minLen); }
3428 function _arrayLikeToArray$j(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; }
3429 // Character (grapheme cluster) boundaries are determined according to
3430 // the default grapheme cluster boundary specification, extended grapheme clusters variant[1].
3431 //
3432 // References:
3433 //
3434 // [1] https://www.unicode.org/reports/tr29/#Default_Grapheme_Cluster_Table
3435 // [2] https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakProperty.txt
3436 // [3] https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.html
3437 // [4] https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.txt
3438 /**
3439 * Get the distance to the end of the first character in a string of text.
3440 */
3441 var getCharacterDistance = function getCharacterDistance(str) {
3442 var isRTL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3443 var isLTR = !isRTL;
3444 var codepoints = isRTL ? codepointsIteratorRTL(str) : str;
3445 var left = CodepointType.None;
3446 var right = CodepointType.None;
3447 var distance = 0;
3448 // Evaluation of these conditions are deferred.
3449 var gb11 = null; // Is GB11 applicable?
3450 var gb12Or13 = null; // Is GB12 or GB13 applicable?
3451 var _iterator = _createForOfIteratorHelper$j(codepoints),
3452 _step;
3453 try {
3454 for (_iterator.s(); !(_step = _iterator.n()).done;) {
3455 var _char = _step.value;
3456 var code = _char.codePointAt(0);
3457 if (!code) break;
3458 var type = getCodepointType(_char, code);
3459 var _ref = isLTR ? [right, type] : [type, left];
3460 var _ref2 = _slicedToArray(_ref, 2);
3461 left = _ref2[0];
3462 right = _ref2[1];
3463 if (intersects(left, CodepointType.ZWJ) && intersects(right, CodepointType.ExtPict)) {
3464 if (isLTR) {
3465 gb11 = endsWithEmojiZWJ(str.substring(0, distance));
3466 } else {
3467 gb11 = endsWithEmojiZWJ(str.substring(0, str.length - distance));
3468 }
3469 if (!gb11) break;
3470 }
3471 if (intersects(left, CodepointType.RI) && intersects(right, CodepointType.RI)) {
3472 if (gb12Or13 !== null) {
3473 gb12Or13 = !gb12Or13;
3474 } else {
3475 if (isLTR) {
3476 gb12Or13 = true;
3477 } else {
3478 gb12Or13 = endsWithOddNumberOfRIs(str.substring(0, str.length - distance));
3479 }
3480 }
3481 if (!gb12Or13) break;
3482 }
3483 if (left !== CodepointType.None && right !== CodepointType.None && isBoundaryPair(left, right)) {
3484 break;
3485 }
3486 distance += _char.length;
3487 }
3488 } catch (err) {
3489 _iterator.e(err);
3490 } finally {
3491 _iterator.f();
3492 }
3493 return distance || 1;
3494 };
3495 var SPACE = /\s/;
3496 var PUNCTUATION = /[\u002B\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/;
3497 var CHAMELEON = /['\u2018\u2019]/;
3498 /**
3499 * Get the distance to the end of the first word in a string of text.
3500 */
3501 var getWordDistance = function getWordDistance(text) {
3502 var isRTL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3503 var dist = 0;
3504 var started = false;
3505 while (text.length > 0) {
3506 var charDist = getCharacterDistance(text, isRTL);
3507 var _splitByCharacterDist = splitByCharacterDistance(text, charDist, isRTL),
3508 _splitByCharacterDist2 = _slicedToArray(_splitByCharacterDist, 2),
3509 _char2 = _splitByCharacterDist2[0],
3510 remaining = _splitByCharacterDist2[1];
3511 if (isWordCharacter(_char2, remaining, isRTL)) {
3512 started = true;
3513 dist += charDist;
3514 } else if (!started) {
3515 dist += charDist;
3516 } else {
3517 break;
3518 }
3519 text = remaining;
3520 }
3521 return dist;
3522 };
3523 /**
3524 * Split a string in two parts at a given distance starting from the end when
3525 * `isRTL` is set to `true`.
3526 */
3527 var splitByCharacterDistance = function splitByCharacterDistance(str, dist, isRTL) {
3528 if (isRTL) {
3529 var at = str.length - dist;
3530 return [str.slice(at, str.length), str.slice(0, at)];
3531 }
3532 return [str.slice(0, dist), str.slice(dist)];
3533 };
3534 /**
3535 * Check if a character is a word character. The `remaining` argument is used
3536 * because sometimes you must read subsequent characters to truly determine it.
3537 */
3538 var isWordCharacter = function isWordCharacter(_char3, remaining) {
3539 var isRTL = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3540 if (SPACE.test(_char3)) {
3541 return false;
3542 }
3543 // Chameleons count as word characters as long as they're in a word, so
3544 // recurse to see if the next one is a word character or not.
3545 if (CHAMELEON.test(_char3)) {
3546 var charDist = getCharacterDistance(remaining, isRTL);
3547 var _splitByCharacterDist3 = splitByCharacterDistance(remaining, charDist, isRTL),
3548 _splitByCharacterDist4 = _slicedToArray(_splitByCharacterDist3, 2),
3549 nextChar = _splitByCharacterDist4[0],
3550 nextRemaining = _splitByCharacterDist4[1];
3551 if (isWordCharacter(nextChar, nextRemaining, isRTL)) {
3552 return true;
3553 }
3554 }
3555 if (PUNCTUATION.test(_char3)) {
3556 return false;
3557 }
3558 return true;
3559 };
3560 /**
3561 * Iterate on codepoints from right to left.
3562 */
3563 var codepointsIteratorRTL = /*#__PURE__*/regenerator.mark(function codepointsIteratorRTL(str) {
3564 var end, i, char1, char2;
3565 return regenerator.wrap(function codepointsIteratorRTL$(_context) {
3566 while (1) switch (_context.prev = _context.next) {
3567 case 0:
3568 end = str.length - 1;
3569 i = 0;
3570 case 2:
3571 if (!(i < str.length)) {
3572 _context.next = 16;
3573 break;
3574 }
3575 char1 = str.charAt(end - i);
3576 if (!isLowSurrogate(char1.charCodeAt(0))) {
3577 _context.next = 11;
3578 break;
3579 }
3580 char2 = str.charAt(end - i - 1);
3581 if (!isHighSurrogate(char2.charCodeAt(0))) {
3582 _context.next = 11;
3583 break;
3584 }
3585 _context.next = 9;
3586 return char2 + char1;
3587 case 9:
3588 i++;
3589 return _context.abrupt("continue", 13);
3590 case 11:
3591 _context.next = 13;
3592 return char1;
3593 case 13:
3594 i++;
3595 _context.next = 2;
3596 break;
3597 case 16:
3598 case "end":
3599 return _context.stop();
3600 }
3601 }, codepointsIteratorRTL);
3602 });
3603 /**
3604 * Is `charCode` a high surrogate.
3605 *
3606 * https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates
3607 */
3608 var isHighSurrogate = function isHighSurrogate(charCode) {
3609 return charCode >= 0xd800 && charCode <= 0xdbff;
3610 };
3611 /**
3612 * Is `charCode` a low surrogate.
3613 *
3614 * https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates
3615 */
3616 var isLowSurrogate = function isLowSurrogate(charCode) {
3617 return charCode >= 0xdc00 && charCode <= 0xdfff;
3618 };
3619 var CodepointType;
3620 (function (CodepointType) {
3621 CodepointType[CodepointType["None"] = 0] = "None";
3622 CodepointType[CodepointType["Extend"] = 1] = "Extend";
3623 CodepointType[CodepointType["ZWJ"] = 2] = "ZWJ";
3624 CodepointType[CodepointType["RI"] = 4] = "RI";
3625 CodepointType[CodepointType["Prepend"] = 8] = "Prepend";
3626 CodepointType[CodepointType["SpacingMark"] = 16] = "SpacingMark";
3627 CodepointType[CodepointType["L"] = 32] = "L";
3628 CodepointType[CodepointType["V"] = 64] = "V";
3629 CodepointType[CodepointType["T"] = 128] = "T";
3630 CodepointType[CodepointType["LV"] = 256] = "LV";
3631 CodepointType[CodepointType["LVT"] = 512] = "LVT";
3632 CodepointType[CodepointType["ExtPict"] = 1024] = "ExtPict";
3633 CodepointType[CodepointType["Any"] = 2048] = "Any";
3634 })(CodepointType || (CodepointType = {}));
3635 var reExtend = /^(?:[\u0300-\u036F\u0483-\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\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0898-\u089F\u08CA-\u08E1\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962\u0963\u0981\u09BC\u09BE\u09C1-\u09C4\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01\u0A02\u0A3C\u0A41\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7\u0AC8\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01\u0B3C\u0B3E\u0B3F\u0B41-\u0B44\u0B4D\u0B55-\u0B57\u0B62\u0B63\u0B82\u0BBE\u0BC0\u0BCD\u0BD7\u0C00\u0C04\u0C3C\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81\u0CBC\u0CBF\u0CC2\u0CC6\u0CCC\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00\u0D01\u0D3B\u0D3C\u0D3E\u0D41-\u0D44\u0D4D\u0D57\u0D62\u0D63\u0D81\u0DCA\u0DCF\u0DD2-\u0DD4\u0DD6\u0DDF\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECE\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\u1733\u1752\u1753\u1772\u1773\u17B4\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u180F\u1885\u1886\u18A9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193B\u1A17\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ACE\u1B00-\u1B03\u1B34-\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-\u1DFF\u200C\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA825\uA826\uA82C\uA8C4\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9BD\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]|\uD800[\uDDFD\uDEE0\uDF76-\uDF7A]|\uD802[\uDE01-\uDE03\uDE05\uDE06\uDE0C-\uDE0F\uDE38-\uDE3A\uDE3F\uDEE5\uDEE6]|\uD803[\uDD24-\uDD27\uDEAB\uDEAC\uDEFD-\uDEFF\uDF46-\uDF50\uDF82-\uDF85]|\uD804[\uDC01\uDC38-\uDC46\uDC70\uDC73\uDC74\uDC7F-\uDC81\uDCB3-\uDCB6\uDCB9\uDCBA\uDCC2\uDD00-\uDD02\uDD27-\uDD2B\uDD2D-\uDD34\uDD73\uDD80\uDD81\uDDB6-\uDDBE\uDDC9-\uDDCC\uDDCF\uDE2F-\uDE31\uDE34\uDE36\uDE37\uDE3E\uDE41\uDEDF\uDEE3-\uDEEA\uDF00\uDF01\uDF3B\uDF3C\uDF3E\uDF40\uDF57\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC38-\uDC3F\uDC42-\uDC44\uDC46\uDC5E\uDCB0\uDCB3-\uDCB8\uDCBA\uDCBD\uDCBF\uDCC0\uDCC2\uDCC3\uDDAF\uDDB2-\uDDB5\uDDBC\uDDBD\uDDBF\uDDC0\uDDDC\uDDDD\uDE33-\uDE3A\uDE3D\uDE3F\uDE40\uDEAB\uDEAD\uDEB0-\uDEB5\uDEB7\uDF1D-\uDF1F\uDF22-\uDF25\uDF27-\uDF2B]|\uD806[\uDC2F-\uDC37\uDC39\uDC3A\uDD30\uDD3B\uDD3C\uDD3E\uDD43\uDDD4-\uDDD7\uDDDA\uDDDB\uDDE0\uDE01-\uDE0A\uDE33-\uDE38\uDE3B-\uDE3E\uDE47\uDE51-\uDE56\uDE59-\uDE5B\uDE8A-\uDE96\uDE98\uDE99]|\uD807[\uDC30-\uDC36\uDC38-\uDC3D\uDC3F\uDC92-\uDCA7\uDCAA-\uDCB0\uDCB2\uDCB3\uDCB5\uDCB6\uDD31-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD45\uDD47\uDD90\uDD91\uDD95\uDD97\uDEF3\uDEF4\uDF00\uDF01\uDF36-\uDF3A\uDF40\uDF42]|\uD80D[\uDC40\uDC47-\uDC55]|\uD81A[\uDEF0-\uDEF4\uDF30-\uDF36]|\uD81B[\uDF4F\uDF8F-\uDF92\uDFE4]|\uD82F[\uDC9D\uDC9E]|\uD833[\uDF00-\uDF2D\uDF30-\uDF46]|\uD834[\uDD65\uDD67-\uDD69\uDD6E-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A\uDC8F\uDD30-\uDD36\uDEAE\uDEEC-\uDEEF]|\uD839[\uDCEC-\uDCEF]|\uD83A[\uDCD0-\uDCD6\uDD44-\uDD4A]|\uD83C[\uDFFB-\uDFFF]|\uDB40[\uDC20-\uDC7F\uDD00-\uDDEF])$/;
3636 var rePrepend = /^(?:[\u0600-\u0605\u06DD\u070F\u0890\u0891\u08E2\u0D4E]|\uD804[\uDCBD\uDCCD\uDDC2\uDDC3]|\uD806[\uDD3F\uDD41\uDE3A\uDE84-\uDE89]|\uD807\uDD46)$/;
3637 var reSpacingMark = /^(?:[\u0903\u093B\u093E-\u0940\u0949-\u094C\u094E\u094F\u0982\u0983\u09BF\u09C0\u09C7\u09C8\u09CB\u09CC\u0A03\u0A3E-\u0A40\u0A83\u0ABE-\u0AC0\u0AC9\u0ACB\u0ACC\u0B02\u0B03\u0B40\u0B47\u0B48\u0B4B\u0B4C\u0BBF\u0BC1\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0C01-\u0C03\u0C41-\u0C44\u0C82\u0C83\u0CBE\u0CC0\u0CC1\u0CC3\u0CC4\u0CC7\u0CC8\u0CCA\u0CCB\u0D02\u0D03\u0D3F\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D82\u0D83\u0DD0\u0DD1\u0DD8-\u0DDE\u0DF2\u0DF3\u0E33\u0EB3\u0F3E\u0F3F\u0F7F\u1031\u103B\u103C\u1056\u1057\u1084\u1715\u1734\u17B6\u17BE-\u17C5\u17C7\u17C8\u1923-\u1926\u1929-\u192B\u1930\u1931\u1933-\u1938\u1A19\u1A1A\u1A55\u1A57\u1A6D-\u1A72\u1B04\u1B3B\u1B3D-\u1B41\u1B43\u1B44\u1B82\u1BA1\u1BA6\u1BA7\u1BAA\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2\u1BF3\u1C24-\u1C2B\u1C34\u1C35\u1CE1\u1CF7\uA823\uA824\uA827\uA880\uA881\uA8B4-\uA8C3\uA952\uA953\uA983\uA9B4\uA9B5\uA9BA\uA9BB\uA9BE-\uA9C0\uAA2F\uAA30\uAA33\uAA34\uAA4D\uAAEB\uAAEE\uAAEF\uAAF5\uABE3\uABE4\uABE6\uABE7\uABE9\uABEA\uABEC]|\uD804[\uDC00\uDC02\uDC82\uDCB0-\uDCB2\uDCB7\uDCB8\uDD2C\uDD45\uDD46\uDD82\uDDB3-\uDDB5\uDDBF\uDDC0\uDDCE\uDE2C-\uDE2E\uDE32\uDE33\uDE35\uDEE0-\uDEE2\uDF02\uDF03\uDF3F\uDF41-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF62\uDF63]|\uD805[\uDC35-\uDC37\uDC40\uDC41\uDC45\uDCB1\uDCB2\uDCB9\uDCBB\uDCBC\uDCBE\uDCC1\uDDB0\uDDB1\uDDB8-\uDDBB\uDDBE\uDE30-\uDE32\uDE3B\uDE3C\uDE3E\uDEAC\uDEAE\uDEAF\uDEB6\uDF26]|\uD806[\uDC2C-\uDC2E\uDC38\uDD31-\uDD35\uDD37\uDD38\uDD3D\uDD40\uDD42\uDDD1-\uDDD3\uDDDC-\uDDDF\uDDE4\uDE39\uDE57\uDE58\uDE97]|\uD807[\uDC2F\uDC3E\uDCA9\uDCB1\uDCB4\uDD8A-\uDD8E\uDD93\uDD94\uDD96\uDEF5\uDEF6]|\uD81B[\uDF51-\uDF87\uDFF0\uDFF1]|\uD834[\uDD66\uDD6D])$/;
3638 var reL = /^[\u1100-\u115F\uA960-\uA97C]$/;
3639 var reV = /^[\u1160-\u11A7\uD7B0-\uD7C6]$/;
3640 var reT = /^[\u11A8-\u11FF\uD7CB-\uD7FB]$/;
3641 var reLV = /^[\uAC00\uAC1C\uAC38\uAC54\uAC70\uAC8C\uACA8\uACC4\uACE0\uACFC\uAD18\uAD34\uAD50\uAD6C\uAD88\uADA4\uADC0\uADDC\uADF8\uAE14\uAE30\uAE4C\uAE68\uAE84\uAEA0\uAEBC\uAED8\uAEF4\uAF10\uAF2C\uAF48\uAF64\uAF80\uAF9C\uAFB8\uAFD4\uAFF0\uB00C\uB028\uB044\uB060\uB07C\uB098\uB0B4\uB0D0\uB0EC\uB108\uB124\uB140\uB15C\uB178\uB194\uB1B0\uB1CC\uB1E8\uB204\uB220\uB23C\uB258\uB274\uB290\uB2AC\uB2C8\uB2E4\uB300\uB31C\uB338\uB354\uB370\uB38C\uB3A8\uB3C4\uB3E0\uB3FC\uB418\uB434\uB450\uB46C\uB488\uB4A4\uB4C0\uB4DC\uB4F8\uB514\uB530\uB54C\uB568\uB584\uB5A0\uB5BC\uB5D8\uB5F4\uB610\uB62C\uB648\uB664\uB680\uB69C\uB6B8\uB6D4\uB6F0\uB70C\uB728\uB744\uB760\uB77C\uB798\uB7B4\uB7D0\uB7EC\uB808\uB824\uB840\uB85C\uB878\uB894\uB8B0\uB8CC\uB8E8\uB904\uB920\uB93C\uB958\uB974\uB990\uB9AC\uB9C8\uB9E4\uBA00\uBA1C\uBA38\uBA54\uBA70\uBA8C\uBAA8\uBAC4\uBAE0\uBAFC\uBB18\uBB34\uBB50\uBB6C\uBB88\uBBA4\uBBC0\uBBDC\uBBF8\uBC14\uBC30\uBC4C\uBC68\uBC84\uBCA0\uBCBC\uBCD8\uBCF4\uBD10\uBD2C\uBD48\uBD64\uBD80\uBD9C\uBDB8\uBDD4\uBDF0\uBE0C\uBE28\uBE44\uBE60\uBE7C\uBE98\uBEB4\uBED0\uBEEC\uBF08\uBF24\uBF40\uBF5C\uBF78\uBF94\uBFB0\uBFCC\uBFE8\uC004\uC020\uC03C\uC058\uC074\uC090\uC0AC\uC0C8\uC0E4\uC100\uC11C\uC138\uC154\uC170\uC18C\uC1A8\uC1C4\uC1E0\uC1FC\uC218\uC234\uC250\uC26C\uC288\uC2A4\uC2C0\uC2DC\uC2F8\uC314\uC330\uC34C\uC368\uC384\uC3A0\uC3BC\uC3D8\uC3F4\uC410\uC42C\uC448\uC464\uC480\uC49C\uC4B8\uC4D4\uC4F0\uC50C\uC528\uC544\uC560\uC57C\uC598\uC5B4\uC5D0\uC5EC\uC608\uC624\uC640\uC65C\uC678\uC694\uC6B0\uC6CC\uC6E8\uC704\uC720\uC73C\uC758\uC774\uC790\uC7AC\uC7C8\uC7E4\uC800\uC81C\uC838\uC854\uC870\uC88C\uC8A8\uC8C4\uC8E0\uC8FC\uC918\uC934\uC950\uC96C\uC988\uC9A4\uC9C0\uC9DC\uC9F8\uCA14\uCA30\uCA4C\uCA68\uCA84\uCAA0\uCABC\uCAD8\uCAF4\uCB10\uCB2C\uCB48\uCB64\uCB80\uCB9C\uCBB8\uCBD4\uCBF0\uCC0C\uCC28\uCC44\uCC60\uCC7C\uCC98\uCCB4\uCCD0\uCCEC\uCD08\uCD24\uCD40\uCD5C\uCD78\uCD94\uCDB0\uCDCC\uCDE8\uCE04\uCE20\uCE3C\uCE58\uCE74\uCE90\uCEAC\uCEC8\uCEE4\uCF00\uCF1C\uCF38\uCF54\uCF70\uCF8C\uCFA8\uCFC4\uCFE0\uCFFC\uD018\uD034\uD050\uD06C\uD088\uD0A4\uD0C0\uD0DC\uD0F8\uD114\uD130\uD14C\uD168\uD184\uD1A0\uD1BC\uD1D8\uD1F4\uD210\uD22C\uD248\uD264\uD280\uD29C\uD2B8\uD2D4\uD2F0\uD30C\uD328\uD344\uD360\uD37C\uD398\uD3B4\uD3D0\uD3EC\uD408\uD424\uD440\uD45C\uD478\uD494\uD4B0\uD4CC\uD4E8\uD504\uD520\uD53C\uD558\uD574\uD590\uD5AC\uD5C8\uD5E4\uD600\uD61C\uD638\uD654\uD670\uD68C\uD6A8\uD6C4\uD6E0\uD6FC\uD718\uD734\uD750\uD76C\uD788]$/;
3642 var reLVT = /^[\uAC01-\uAC1B\uAC1D-\uAC37\uAC39-\uAC53\uAC55-\uAC6F\uAC71-\uAC8B\uAC8D-\uACA7\uACA9-\uACC3\uACC5-\uACDF\uACE1-\uACFB\uACFD-\uAD17\uAD19-\uAD33\uAD35-\uAD4F\uAD51-\uAD6B\uAD6D-\uAD87\uAD89-\uADA3\uADA5-\uADBF\uADC1-\uADDB\uADDD-\uADF7\uADF9-\uAE13\uAE15-\uAE2F\uAE31-\uAE4B\uAE4D-\uAE67\uAE69-\uAE83\uAE85-\uAE9F\uAEA1-\uAEBB\uAEBD-\uAED7\uAED9-\uAEF3\uAEF5-\uAF0F\uAF11-\uAF2B\uAF2D-\uAF47\uAF49-\uAF63\uAF65-\uAF7F\uAF81-\uAF9B\uAF9D-\uAFB7\uAFB9-\uAFD3\uAFD5-\uAFEF\uAFF1-\uB00B\uB00D-\uB027\uB029-\uB043\uB045-\uB05F\uB061-\uB07B\uB07D-\uB097\uB099-\uB0B3\uB0B5-\uB0CF\uB0D1-\uB0EB\uB0ED-\uB107\uB109-\uB123\uB125-\uB13F\uB141-\uB15B\uB15D-\uB177\uB179-\uB193\uB195-\uB1AF\uB1B1-\uB1CB\uB1CD-\uB1E7\uB1E9-\uB203\uB205-\uB21F\uB221-\uB23B\uB23D-\uB257\uB259-\uB273\uB275-\uB28F\uB291-\uB2AB\uB2AD-\uB2C7\uB2C9-\uB2E3\uB2E5-\uB2FF\uB301-\uB31B\uB31D-\uB337\uB339-\uB353\uB355-\uB36F\uB371-\uB38B\uB38D-\uB3A7\uB3A9-\uB3C3\uB3C5-\uB3DF\uB3E1-\uB3FB\uB3FD-\uB417\uB419-\uB433\uB435-\uB44F\uB451-\uB46B\uB46D-\uB487\uB489-\uB4A3\uB4A5-\uB4BF\uB4C1-\uB4DB\uB4DD-\uB4F7\uB4F9-\uB513\uB515-\uB52F\uB531-\uB54B\uB54D-\uB567\uB569-\uB583\uB585-\uB59F\uB5A1-\uB5BB\uB5BD-\uB5D7\uB5D9-\uB5F3\uB5F5-\uB60F\uB611-\uB62B\uB62D-\uB647\uB649-\uB663\uB665-\uB67F\uB681-\uB69B\uB69D-\uB6B7\uB6B9-\uB6D3\uB6D5-\uB6EF\uB6F1-\uB70B\uB70D-\uB727\uB729-\uB743\uB745-\uB75F\uB761-\uB77B\uB77D-\uB797\uB799-\uB7B3\uB7B5-\uB7CF\uB7D1-\uB7EB\uB7ED-\uB807\uB809-\uB823\uB825-\uB83F\uB841-\uB85B\uB85D-\uB877\uB879-\uB893\uB895-\uB8AF\uB8B1-\uB8CB\uB8CD-\uB8E7\uB8E9-\uB903\uB905-\uB91F\uB921-\uB93B\uB93D-\uB957\uB959-\uB973\uB975-\uB98F\uB991-\uB9AB\uB9AD-\uB9C7\uB9C9-\uB9E3\uB9E5-\uB9FF\uBA01-\uBA1B\uBA1D-\uBA37\uBA39-\uBA53\uBA55-\uBA6F\uBA71-\uBA8B\uBA8D-\uBAA7\uBAA9-\uBAC3\uBAC5-\uBADF\uBAE1-\uBAFB\uBAFD-\uBB17\uBB19-\uBB33\uBB35-\uBB4F\uBB51-\uBB6B\uBB6D-\uBB87\uBB89-\uBBA3\uBBA5-\uBBBF\uBBC1-\uBBDB\uBBDD-\uBBF7\uBBF9-\uBC13\uBC15-\uBC2F\uBC31-\uBC4B\uBC4D-\uBC67\uBC69-\uBC83\uBC85-\uBC9F\uBCA1-\uBCBB\uBCBD-\uBCD7\uBCD9-\uBCF3\uBCF5-\uBD0F\uBD11-\uBD2B\uBD2D-\uBD47\uBD49-\uBD63\uBD65-\uBD7F\uBD81-\uBD9B\uBD9D-\uBDB7\uBDB9-\uBDD3\uBDD5-\uBDEF\uBDF1-\uBE0B\uBE0D-\uBE27\uBE29-\uBE43\uBE45-\uBE5F\uBE61-\uBE7B\uBE7D-\uBE97\uBE99-\uBEB3\uBEB5-\uBECF\uBED1-\uBEEB\uBEED-\uBF07\uBF09-\uBF23\uBF25-\uBF3F\uBF41-\uBF5B\uBF5D-\uBF77\uBF79-\uBF93\uBF95-\uBFAF\uBFB1-\uBFCB\uBFCD-\uBFE7\uBFE9-\uC003\uC005-\uC01F\uC021-\uC03B\uC03D-\uC057\uC059-\uC073\uC075-\uC08F\uC091-\uC0AB\uC0AD-\uC0C7\uC0C9-\uC0E3\uC0E5-\uC0FF\uC101-\uC11B\uC11D-\uC137\uC139-\uC153\uC155-\uC16F\uC171-\uC18B\uC18D-\uC1A7\uC1A9-\uC1C3\uC1C5-\uC1DF\uC1E1-\uC1FB\uC1FD-\uC217\uC219-\uC233\uC235-\uC24F\uC251-\uC26B\uC26D-\uC287\uC289-\uC2A3\uC2A5-\uC2BF\uC2C1-\uC2DB\uC2DD-\uC2F7\uC2F9-\uC313\uC315-\uC32F\uC331-\uC34B\uC34D-\uC367\uC369-\uC383\uC385-\uC39F\uC3A1-\uC3BB\uC3BD-\uC3D7\uC3D9-\uC3F3\uC3F5-\uC40F\uC411-\uC42B\uC42D-\uC447\uC449-\uC463\uC465-\uC47F\uC481-\uC49B\uC49D-\uC4B7\uC4B9-\uC4D3\uC4D5-\uC4EF\uC4F1-\uC50B\uC50D-\uC527\uC529-\uC543\uC545-\uC55F\uC561-\uC57B\uC57D-\uC597\uC599-\uC5B3\uC5B5-\uC5CF\uC5D1-\uC5EB\uC5ED-\uC607\uC609-\uC623\uC625-\uC63F\uC641-\uC65B\uC65D-\uC677\uC679-\uC693\uC695-\uC6AF\uC6B1-\uC6CB\uC6CD-\uC6E7\uC6E9-\uC703\uC705-\uC71F\uC721-\uC73B\uC73D-\uC757\uC759-\uC773\uC775-\uC78F\uC791-\uC7AB\uC7AD-\uC7C7\uC7C9-\uC7E3\uC7E5-\uC7FF\uC801-\uC81B\uC81D-\uC837\uC839-\uC853\uC855-\uC86F\uC871-\uC88B\uC88D-\uC8A7\uC8A9-\uC8C3\uC8C5-\uC8DF\uC8E1-\uC8FB\uC8FD-\uC917\uC919-\uC933\uC935-\uC94F\uC951-\uC96B\uC96D-\uC987\uC989-\uC9A3\uC9A5-\uC9BF\uC9C1-\uC9DB\uC9DD-\uC9F7\uC9F9-\uCA13\uCA15-\uCA2F\uCA31-\uCA4B\uCA4D-\uCA67\uCA69-\uCA83\uCA85-\uCA9F\uCAA1-\uCABB\uCABD-\uCAD7\uCAD9-\uCAF3\uCAF5-\uCB0F\uCB11-\uCB2B\uCB2D-\uCB47\uCB49-\uCB63\uCB65-\uCB7F\uCB81-\uCB9B\uCB9D-\uCBB7\uCBB9-\uCBD3\uCBD5-\uCBEF\uCBF1-\uCC0B\uCC0D-\uCC27\uCC29-\uCC43\uCC45-\uCC5F\uCC61-\uCC7B\uCC7D-\uCC97\uCC99-\uCCB3\uCCB5-\uCCCF\uCCD1-\uCCEB\uCCED-\uCD07\uCD09-\uCD23\uCD25-\uCD3F\uCD41-\uCD5B\uCD5D-\uCD77\uCD79-\uCD93\uCD95-\uCDAF\uCDB1-\uCDCB\uCDCD-\uCDE7\uCDE9-\uCE03\uCE05-\uCE1F\uCE21-\uCE3B\uCE3D-\uCE57\uCE59-\uCE73\uCE75-\uCE8F\uCE91-\uCEAB\uCEAD-\uCEC7\uCEC9-\uCEE3\uCEE5-\uCEFF\uCF01-\uCF1B\uCF1D-\uCF37\uCF39-\uCF53\uCF55-\uCF6F\uCF71-\uCF8B\uCF8D-\uCFA7\uCFA9-\uCFC3\uCFC5-\uCFDF\uCFE1-\uCFFB\uCFFD-\uD017\uD019-\uD033\uD035-\uD04F\uD051-\uD06B\uD06D-\uD087\uD089-\uD0A3\uD0A5-\uD0BF\uD0C1-\uD0DB\uD0DD-\uD0F7\uD0F9-\uD113\uD115-\uD12F\uD131-\uD14B\uD14D-\uD167\uD169-\uD183\uD185-\uD19F\uD1A1-\uD1BB\uD1BD-\uD1D7\uD1D9-\uD1F3\uD1F5-\uD20F\uD211-\uD22B\uD22D-\uD247\uD249-\uD263\uD265-\uD27F\uD281-\uD29B\uD29D-\uD2B7\uD2B9-\uD2D3\uD2D5-\uD2EF\uD2F1-\uD30B\uD30D-\uD327\uD329-\uD343\uD345-\uD35F\uD361-\uD37B\uD37D-\uD397\uD399-\uD3B3\uD3B5-\uD3CF\uD3D1-\uD3EB\uD3ED-\uD407\uD409-\uD423\uD425-\uD43F\uD441-\uD45B\uD45D-\uD477\uD479-\uD493\uD495-\uD4AF\uD4B1-\uD4CB\uD4CD-\uD4E7\uD4E9-\uD503\uD505-\uD51F\uD521-\uD53B\uD53D-\uD557\uD559-\uD573\uD575-\uD58F\uD591-\uD5AB\uD5AD-\uD5C7\uD5C9-\uD5E3\uD5E5-\uD5FF\uD601-\uD61B\uD61D-\uD637\uD639-\uD653\uD655-\uD66F\uD671-\uD68B\uD68D-\uD6A7\uD6A9-\uD6C3\uD6C5-\uD6DF\uD6E1-\uD6FB\uD6FD-\uD717\uD719-\uD733\uD735-\uD74F\uD751-\uD76B\uD76D-\uD787\uD789-\uD7A3]$/;
3643 var reExtPict = /^(?:[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u2388\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2605\u2607-\u2612\u2614-\u2685\u2690-\u2705\u2708-\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763-\u2767\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC00-\uDCFF\uDD0D-\uDD0F\uDD2F\uDD6C-\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDAD-\uDDE5\uDE01-\uDE0F\uDE1A\uDE2F\uDE32-\uDE3A\uDE3C-\uDE3F\uDE49-\uDFFA]|\uD83D[\uDC00-\uDD3D\uDD46-\uDE4F\uDE80-\uDEFF\uDF74-\uDF7F\uDFD5-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE-\uDCFF\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDEFF]|\uD83F[\uDC00-\uDFFD])$/;
3644 var getCodepointType = function getCodepointType(_char4, code) {
3645 var type = CodepointType.Any;
3646 if (_char4.search(reExtend) !== -1) {
3647 type |= CodepointType.Extend;
3648 }
3649 if (code === 0x200d) {
3650 type |= CodepointType.ZWJ;
3651 }
3652 if (code >= 0x1f1e6 && code <= 0x1f1ff) {
3653 type |= CodepointType.RI;
3654 }
3655 if (_char4.search(rePrepend) !== -1) {
3656 type |= CodepointType.Prepend;
3657 }
3658 if (_char4.search(reSpacingMark) !== -1) {
3659 type |= CodepointType.SpacingMark;
3660 }
3661 if (_char4.search(reL) !== -1) {
3662 type |= CodepointType.L;
3663 }
3664 if (_char4.search(reV) !== -1) {
3665 type |= CodepointType.V;
3666 }
3667 if (_char4.search(reT) !== -1) {
3668 type |= CodepointType.T;
3669 }
3670 if (_char4.search(reLV) !== -1) {
3671 type |= CodepointType.LV;
3672 }
3673 if (_char4.search(reLVT) !== -1) {
3674 type |= CodepointType.LVT;
3675 }
3676 if (_char4.search(reExtPict) !== -1) {
3677 type |= CodepointType.ExtPict;
3678 }
3679 return type;
3680 };
3681 function intersects(x, y) {
3682 return (x & y) !== 0;
3683 }
3684 var NonBoundaryPairs = [
3685 // GB6
3686 [CodepointType.L, CodepointType.L | CodepointType.V | CodepointType.LV | CodepointType.LVT],
3687 // GB7
3688 [CodepointType.LV | CodepointType.V, CodepointType.V | CodepointType.T],
3689 // GB8
3690 [CodepointType.LVT | CodepointType.T, CodepointType.T],
3691 // GB9
3692 [CodepointType.Any, CodepointType.Extend | CodepointType.ZWJ],
3693 // GB9a
3694 [CodepointType.Any, CodepointType.SpacingMark],
3695 // GB9b
3696 [CodepointType.Prepend, CodepointType.Any],
3697 // GB11
3698 [CodepointType.ZWJ, CodepointType.ExtPict],
3699 // GB12 and GB13
3700 [CodepointType.RI, CodepointType.RI]];
3701 function isBoundaryPair(left, right) {
3702 return NonBoundaryPairs.findIndex(function (r) {
3703 return intersects(left, r[0]) && intersects(right, r[1]);
3704 }) === -1;
3705 }
3706 var endingEmojiZWJ = /(?:[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u2388\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2605\u2607-\u2612\u2614-\u2685\u2690-\u2705\u2708-\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763-\u2767\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC00-\uDCFF\uDD0D-\uDD0F\uDD2F\uDD6C-\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDAD-\uDDE5\uDE01-\uDE0F\uDE1A\uDE2F\uDE32-\uDE3A\uDE3C-\uDE3F\uDE49-\uDFFA]|\uD83D[\uDC00-\uDD3D\uDD46-\uDE4F\uDE80-\uDEFF\uDF74-\uDF7F\uDFD5-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE-\uDCFF\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDEFF]|\uD83F[\uDC00-\uDFFD])(?:[\u0300-\u036F\u0483-\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\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0898-\u089F\u08CA-\u08E1\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962\u0963\u0981\u09BC\u09BE\u09C1-\u09C4\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01\u0A02\u0A3C\u0A41\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7\u0AC8\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01\u0B3C\u0B3E\u0B3F\u0B41-\u0B44\u0B4D\u0B55-\u0B57\u0B62\u0B63\u0B82\u0BBE\u0BC0\u0BCD\u0BD7\u0C00\u0C04\u0C3C\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81\u0CBC\u0CBF\u0CC2\u0CC6\u0CCC\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00\u0D01\u0D3B\u0D3C\u0D3E\u0D41-\u0D44\u0D4D\u0D57\u0D62\u0D63\u0D81\u0DCA\u0DCF\u0DD2-\u0DD4\u0DD6\u0DDF\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECE\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\u1733\u1752\u1753\u1772\u1773\u17B4\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u180F\u1885\u1886\u18A9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193B\u1A17\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ACE\u1B00-\u1B03\u1B34-\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-\u1DFF\u200C\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA825\uA826\uA82C\uA8C4\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9BD\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]|\uD800[\uDDFD\uDEE0\uDF76-\uDF7A]|\uD802[\uDE01-\uDE03\uDE05\uDE06\uDE0C-\uDE0F\uDE38-\uDE3A\uDE3F\uDEE5\uDEE6]|\uD803[\uDD24-\uDD27\uDEAB\uDEAC\uDEFD-\uDEFF\uDF46-\uDF50\uDF82-\uDF85]|\uD804[\uDC01\uDC38-\uDC46\uDC70\uDC73\uDC74\uDC7F-\uDC81\uDCB3-\uDCB6\uDCB9\uDCBA\uDCC2\uDD00-\uDD02\uDD27-\uDD2B\uDD2D-\uDD34\uDD73\uDD80\uDD81\uDDB6-\uDDBE\uDDC9-\uDDCC\uDDCF\uDE2F-\uDE31\uDE34\uDE36\uDE37\uDE3E\uDE41\uDEDF\uDEE3-\uDEEA\uDF00\uDF01\uDF3B\uDF3C\uDF3E\uDF40\uDF57\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC38-\uDC3F\uDC42-\uDC44\uDC46\uDC5E\uDCB0\uDCB3-\uDCB8\uDCBA\uDCBD\uDCBF\uDCC0\uDCC2\uDCC3\uDDAF\uDDB2-\uDDB5\uDDBC\uDDBD\uDDBF\uDDC0\uDDDC\uDDDD\uDE33-\uDE3A\uDE3D\uDE3F\uDE40\uDEAB\uDEAD\uDEB0-\uDEB5\uDEB7\uDF1D-\uDF1F\uDF22-\uDF25\uDF27-\uDF2B]|\uD806[\uDC2F-\uDC37\uDC39\uDC3A\uDD30\uDD3B\uDD3C\uDD3E\uDD43\uDDD4-\uDDD7\uDDDA\uDDDB\uDDE0\uDE01-\uDE0A\uDE33-\uDE38\uDE3B-\uDE3E\uDE47\uDE51-\uDE56\uDE59-\uDE5B\uDE8A-\uDE96\uDE98\uDE99]|\uD807[\uDC30-\uDC36\uDC38-\uDC3D\uDC3F\uDC92-\uDCA7\uDCAA-\uDCB0\uDCB2\uDCB3\uDCB5\uDCB6\uDD31-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD45\uDD47\uDD90\uDD91\uDD95\uDD97\uDEF3\uDEF4\uDF00\uDF01\uDF36-\uDF3A\uDF40\uDF42]|\uD80D[\uDC40\uDC47-\uDC55]|\uD81A[\uDEF0-\uDEF4\uDF30-\uDF36]|\uD81B[\uDF4F\uDF8F-\uDF92\uDFE4]|\uD82F[\uDC9D\uDC9E]|\uD833[\uDF00-\uDF2D\uDF30-\uDF46]|\uD834[\uDD65\uDD67-\uDD69\uDD6E-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A\uDC8F\uDD30-\uDD36\uDEAE\uDEEC-\uDEEF]|\uD839[\uDCEC-\uDCEF]|\uD83A[\uDCD0-\uDCD6\uDD44-\uDD4A]|\uD83C[\uDFFB-\uDFFF]|\uDB40[\uDC20-\uDC7F\uDD00-\uDDEF])*\u200D$/;
3707 var endsWithEmojiZWJ = function endsWithEmojiZWJ(str) {
3708 return str.search(endingEmojiZWJ) !== -1;
3709 };
3710 var endingRIs = /(?:\uD83C[\uDDE6-\uDDFF])+$/g;
3711 var endsWithOddNumberOfRIs = function endsWithOddNumberOfRIs(str) {
3712 var match = str.match(endingRIs);
3713 if (match === null) {
3714 return false;
3715 } else {
3716 // A RI is represented by a surrogate pair.
3717 var numRIs = match[0].length / 2;
3718 return numRIs % 2 === 1;
3719 }
3720 };
3721
3722 // eslint-disable-next-line no-redeclare
3723 var TextTransforms = {
3724 "delete": function _delete(editor, options) {
3725 editor["delete"](options);
3726 },
3727 insertFragment: function insertFragment(editor, fragment, options) {
3728 editor.insertFragment(fragment, options);
3729 },
3730 insertText: function insertText(editor, text) {
3731 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
3732 Editor.withoutNormalizing(editor, function () {
3733 var _options$voids = options.voids,
3734 voids = _options$voids === void 0 ? false : _options$voids;
3735 var _options$at = options.at,
3736 at = _options$at === void 0 ? getDefaultInsertLocation(editor) : _options$at;
3737 if (Path.isPath(at)) {
3738 at = Editor.range(editor, at);
3739 }
3740 if (Range.isRange(at)) {
3741 if (Range.isCollapsed(at)) {
3742 at = at.anchor;
3743 } else {
3744 var end = Range.end(at);
3745 if (!voids && Editor["void"](editor, {
3746 at: end
3747 })) {
3748 return;
3749 }
3750 var start = Range.start(at);
3751 var startRef = Editor.pointRef(editor, start);
3752 var endRef = Editor.pointRef(editor, end);
3753 Transforms["delete"](editor, {
3754 at: at,
3755 voids: voids
3756 });
3757 var startPoint = startRef.unref();
3758 var endPoint = endRef.unref();
3759 at = startPoint || endPoint;
3760 Transforms.setSelection(editor, {
3761 anchor: at,
3762 focus: at
3763 });
3764 }
3765 }
3766 if (!voids && Editor["void"](editor, {
3767 at: at
3768 }) || Editor.elementReadOnly(editor, {
3769 at: at
3770 })) {
3771 return;
3772 }
3773 var _at = at,
3774 path = _at.path,
3775 offset = _at.offset;
3776 if (text.length > 0) editor.apply({
3777 type: 'insert_text',
3778 path: path,
3779 offset: offset,
3780 text: text
3781 });
3782 });
3783 }
3784 };
3785
3786 function ownKeys$9(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; }
3787 function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3788 var Transforms = _objectSpread$9(_objectSpread$9(_objectSpread$9(_objectSpread$9({}, GeneralTransforms), NodeTransforms), SelectionTransforms), TextTransforms);
3789
3790 // perf
3791 var BATCHING_DIRTY_PATHS = new WeakMap();
3792 var isBatchingDirtyPaths = function isBatchingDirtyPaths(editor) {
3793 return BATCHING_DIRTY_PATHS.get(editor) || false;
3794 };
3795 var batchDirtyPaths = function batchDirtyPaths(editor, fn, update) {
3796 var value = BATCHING_DIRTY_PATHS.get(editor) || false;
3797 BATCHING_DIRTY_PATHS.set(editor, true);
3798 try {
3799 fn();
3800 update();
3801 } finally {
3802 BATCHING_DIRTY_PATHS.set(editor, value);
3803 }
3804 };
3805
3806 function _createForOfIteratorHelper$i(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$i(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; } } }; }
3807 function _unsupportedIterableToArray$i(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$i(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$i(o, minLen); }
3808 function _arrayLikeToArray$i(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; }
3809 /**
3810 * update editor dirty paths
3811 *
3812 * @param newDirtyPaths: Path[]; new dirty paths
3813 * @param transform: (p: Path) => Path | null; how to transform existing dirty paths
3814 */
3815 function updateDirtyPaths(editor, newDirtyPaths, transform) {
3816 var oldDirtyPaths = DIRTY_PATHS.get(editor) || [];
3817 var oldDirtyPathKeys = DIRTY_PATH_KEYS.get(editor) || new Set();
3818 var dirtyPaths;
3819 var dirtyPathKeys;
3820 var add = function add(path) {
3821 if (path) {
3822 var key = path.join(',');
3823 if (!dirtyPathKeys.has(key)) {
3824 dirtyPathKeys.add(key);
3825 dirtyPaths.push(path);
3826 }
3827 }
3828 };
3829 if (transform) {
3830 dirtyPaths = [];
3831 dirtyPathKeys = new Set();
3832 var _iterator = _createForOfIteratorHelper$i(oldDirtyPaths),
3833 _step;
3834 try {
3835 for (_iterator.s(); !(_step = _iterator.n()).done;) {
3836 var path = _step.value;
3837 var newPath = transform(path);
3838 add(newPath);
3839 }
3840 } catch (err) {
3841 _iterator.e(err);
3842 } finally {
3843 _iterator.f();
3844 }
3845 } else {
3846 dirtyPaths = oldDirtyPaths;
3847 dirtyPathKeys = oldDirtyPathKeys;
3848 }
3849 var _iterator2 = _createForOfIteratorHelper$i(newDirtyPaths),
3850 _step2;
3851 try {
3852 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3853 var _path = _step2.value;
3854 add(_path);
3855 }
3856 } catch (err) {
3857 _iterator2.e(err);
3858 } finally {
3859 _iterator2.f();
3860 }
3861 DIRTY_PATHS.set(editor, dirtyPaths);
3862 DIRTY_PATH_KEYS.set(editor, dirtyPathKeys);
3863 }
3864
3865 function _createForOfIteratorHelper$h(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$h(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; } } }; }
3866 function _unsupportedIterableToArray$h(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$h(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$h(o, minLen); }
3867 function _arrayLikeToArray$h(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; }
3868 var apply = function apply(editor, op) {
3869 var _iterator = _createForOfIteratorHelper$h(Editor.pathRefs(editor)),
3870 _step;
3871 try {
3872 for (_iterator.s(); !(_step = _iterator.n()).done;) {
3873 var ref = _step.value;
3874 PathRef.transform(ref, op);
3875 }
3876 } catch (err) {
3877 _iterator.e(err);
3878 } finally {
3879 _iterator.f();
3880 }
3881 var _iterator2 = _createForOfIteratorHelper$h(Editor.pointRefs(editor)),
3882 _step2;
3883 try {
3884 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3885 var _ref = _step2.value;
3886 PointRef.transform(_ref, op);
3887 }
3888 } catch (err) {
3889 _iterator2.e(err);
3890 } finally {
3891 _iterator2.f();
3892 }
3893 var _iterator3 = _createForOfIteratorHelper$h(Editor.rangeRefs(editor)),
3894 _step3;
3895 try {
3896 for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
3897 var _ref2 = _step3.value;
3898 RangeRef.transform(_ref2, op);
3899 }
3900 // update dirty paths
3901 } catch (err) {
3902 _iterator3.e(err);
3903 } finally {
3904 _iterator3.f();
3905 }
3906 if (!isBatchingDirtyPaths(editor)) {
3907 var transform = Path.operationCanTransformPath(op) ? function (p) {
3908 return Path.transform(p, op);
3909 } : undefined;
3910 updateDirtyPaths(editor, editor.getDirtyPaths(op), transform);
3911 }
3912 Transforms.transform(editor, op);
3913 editor.operations.push(op);
3914 Editor.normalize(editor, {
3915 operation: op
3916 });
3917 // Clear any formats applied to the cursor if the selection changes.
3918 if (op.type === 'set_selection') {
3919 editor.marks = null;
3920 }
3921 if (!FLUSHING.get(editor)) {
3922 FLUSHING.set(editor, true);
3923 Promise.resolve().then(function () {
3924 FLUSHING.set(editor, false);
3925 editor.onChange({
3926 operation: op
3927 });
3928 editor.operations = [];
3929 });
3930 }
3931 };
3932
3933 function _createForOfIteratorHelper$g(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$g(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; } } }; }
3934 function _unsupportedIterableToArray$g(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$g(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$g(o, minLen); }
3935 function _arrayLikeToArray$g(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; }
3936 /**
3937 * Get the "dirty" paths generated from an operation.
3938 */
3939 var getDirtyPaths = function getDirtyPaths(editor, op) {
3940 switch (op.type) {
3941 case 'insert_text':
3942 case 'remove_text':
3943 case 'set_node':
3944 {
3945 var path = op.path;
3946 return Path.levels(path);
3947 }
3948 case 'insert_node':
3949 {
3950 var node = op.node,
3951 _path = op.path;
3952 var levels = Path.levels(_path);
3953 var descendants = Text.isText(node) ? [] : Array.from(Node.nodes(node), function (_ref) {
3954 var _ref2 = _slicedToArray(_ref, 2),
3955 p = _ref2[1];
3956 return _path.concat(p);
3957 });
3958 return [].concat(_toConsumableArray(levels), _toConsumableArray(descendants));
3959 }
3960 case 'merge_node':
3961 {
3962 var _path2 = op.path;
3963 var ancestors = Path.ancestors(_path2);
3964 var previousPath = Path.previous(_path2);
3965 return [].concat(_toConsumableArray(ancestors), [previousPath]);
3966 }
3967 case 'move_node':
3968 {
3969 var _path3 = op.path,
3970 newPath = op.newPath;
3971 if (Path.equals(_path3, newPath)) {
3972 return [];
3973 }
3974 var oldAncestors = [];
3975 var newAncestors = [];
3976 var _iterator = _createForOfIteratorHelper$g(Path.ancestors(_path3)),
3977 _step;
3978 try {
3979 for (_iterator.s(); !(_step = _iterator.n()).done;) {
3980 var ancestor = _step.value;
3981 var p = Path.transform(ancestor, op);
3982 oldAncestors.push(p);
3983 }
3984 } catch (err) {
3985 _iterator.e(err);
3986 } finally {
3987 _iterator.f();
3988 }
3989 var _iterator2 = _createForOfIteratorHelper$g(Path.ancestors(newPath)),
3990 _step2;
3991 try {
3992 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3993 var _ancestor = _step2.value;
3994 var _p = Path.transform(_ancestor, op);
3995 newAncestors.push(_p);
3996 }
3997 } catch (err) {
3998 _iterator2.e(err);
3999 } finally {
4000 _iterator2.f();
4001 }
4002 var newParent = newAncestors[newAncestors.length - 1];
4003 var newIndex = newPath[newPath.length - 1];
4004 var resultPath = newParent.concat(newIndex);
4005 return [].concat(oldAncestors, newAncestors, [resultPath]);
4006 }
4007 case 'remove_node':
4008 {
4009 var _path4 = op.path;
4010 var _ancestors = Path.ancestors(_path4);
4011 return _toConsumableArray(_ancestors);
4012 }
4013 case 'split_node':
4014 {
4015 var _path5 = op.path;
4016 var _levels = Path.levels(_path5);
4017 var nextPath = Path.next(_path5);
4018 return [].concat(_toConsumableArray(_levels), [nextPath]);
4019 }
4020 default:
4021 {
4022 return [];
4023 }
4024 }
4025 };
4026
4027 var getFragment = function getFragment(editor) {
4028 var selection = editor.selection;
4029 if (selection) {
4030 return Node.fragment(editor, selection);
4031 }
4032 return [];
4033 };
4034
4035 var normalizeNode = function normalizeNode(editor, entry) {
4036 var _entry = _slicedToArray(entry, 2),
4037 node = _entry[0],
4038 path = _entry[1];
4039 // There are no core normalizations for text nodes.
4040 if (Text.isText(node)) {
4041 return;
4042 }
4043 // Ensure that block and inline nodes have at least one text child.
4044 if (Element.isElement(node) && node.children.length === 0) {
4045 var child = {
4046 text: ''
4047 };
4048 Transforms.insertNodes(editor, child, {
4049 at: path.concat(0),
4050 voids: true
4051 });
4052 return;
4053 }
4054 // Determine whether the node should have block or inline children.
4055 var shouldHaveInlines = Editor.isEditor(node) ? false : Element.isElement(node) && (editor.isInline(node) || node.children.length === 0 || Text.isText(node.children[0]) || editor.isInline(node.children[0]));
4056 // Since we'll be applying operations while iterating, keep track of an
4057 // index that accounts for any added/removed nodes.
4058 var n = 0;
4059 for (var i = 0; i < node.children.length; i++, n++) {
4060 var currentNode = Node.get(editor, path);
4061 if (Text.isText(currentNode)) continue;
4062 var _child = currentNode.children[n];
4063 var prev = currentNode.children[n - 1];
4064 var isLast = i === node.children.length - 1;
4065 var isInlineOrText = Text.isText(_child) || Element.isElement(_child) && editor.isInline(_child);
4066 // Only allow block nodes in the top-level children and parent blocks
4067 // that only contain block nodes. Similarly, only allow inline nodes in
4068 // other inline nodes, or parent blocks that only contain inlines and
4069 // text.
4070 if (isInlineOrText !== shouldHaveInlines) {
4071 Transforms.removeNodes(editor, {
4072 at: path.concat(n),
4073 voids: true
4074 });
4075 n--;
4076 } else if (Element.isElement(_child)) {
4077 // Ensure that inline nodes are surrounded by text nodes.
4078 if (editor.isInline(_child)) {
4079 if (prev == null || !Text.isText(prev)) {
4080 var newChild = {
4081 text: ''
4082 };
4083 Transforms.insertNodes(editor, newChild, {
4084 at: path.concat(n),
4085 voids: true
4086 });
4087 n++;
4088 } else if (isLast) {
4089 var _newChild = {
4090 text: ''
4091 };
4092 Transforms.insertNodes(editor, _newChild, {
4093 at: path.concat(n + 1),
4094 voids: true
4095 });
4096 n++;
4097 }
4098 }
4099 } else {
4100 // If the child is not a text node, and doesn't have a `children` field,
4101 // then we have an invalid node that will upset slate.
4102 //
4103 // eg: `{ type: 'some_node' }`.
4104 //
4105 // To prevent slate from breaking, we can add the `children` field,
4106 // and now that it is valid, we can to many more operations easily,
4107 // such as extend normalizers to fix erronous structure.
4108 if (!Text.isText(_child) && !('children' in _child)) {
4109 var elementChild = _child;
4110 elementChild.children = [];
4111 }
4112 // Merge adjacent text nodes that are empty or match.
4113 if (prev != null && Text.isText(prev)) {
4114 if (Text.equals(_child, prev, {
4115 loose: true
4116 })) {
4117 Transforms.mergeNodes(editor, {
4118 at: path.concat(n),
4119 voids: true
4120 });
4121 n--;
4122 } else if (prev.text === '') {
4123 Transforms.removeNodes(editor, {
4124 at: path.concat(n - 1),
4125 voids: true
4126 });
4127 n--;
4128 } else if (_child.text === '') {
4129 Transforms.removeNodes(editor, {
4130 at: path.concat(n),
4131 voids: true
4132 });
4133 n--;
4134 }
4135 }
4136 }
4137 }
4138 };
4139
4140 var shouldNormalize = function shouldNormalize(editor, _ref) {
4141 var iteration = _ref.iteration,
4142 initialDirtyPathsLength = _ref.initialDirtyPathsLength;
4143 var maxIterations = initialDirtyPathsLength * 42; // HACK: better way?
4144 if (iteration > maxIterations) {
4145 throw new Error("Could not completely normalize the editor after ".concat(maxIterations, " iterations! This is usually due to incorrect normalization logic that leaves a node in an invalid state."));
4146 }
4147 return true;
4148 };
4149
4150 function _createForOfIteratorHelper$f(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$f(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; } } }; }
4151 function _unsupportedIterableToArray$f(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$f(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$f(o, minLen); }
4152 function _arrayLikeToArray$f(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; }
4153 var above = function above(editor) {
4154 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4155 var _options$voids = options.voids,
4156 voids = _options$voids === void 0 ? false : _options$voids,
4157 _options$mode = options.mode,
4158 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
4159 _options$at = options.at,
4160 at = _options$at === void 0 ? editor.selection : _options$at,
4161 match = options.match;
4162 if (!at) {
4163 return;
4164 }
4165 var path = Editor.path(editor, at);
4166 var reverse = mode === 'lowest';
4167 var _iterator = _createForOfIteratorHelper$f(Editor.levels(editor, {
4168 at: path,
4169 voids: voids,
4170 match: match,
4171 reverse: reverse
4172 })),
4173 _step;
4174 try {
4175 for (_iterator.s(); !(_step = _iterator.n()).done;) {
4176 var _step$value = _slicedToArray(_step.value, 2),
4177 n = _step$value[0],
4178 p = _step$value[1];
4179 if (Text.isText(n)) continue;
4180 if (Range.isRange(at)) {
4181 if (Path.isAncestor(p, at.anchor.path) && Path.isAncestor(p, at.focus.path)) {
4182 return [n, p];
4183 }
4184 } else {
4185 if (!Path.equals(path, p)) {
4186 return [n, p];
4187 }
4188 }
4189 }
4190 } catch (err) {
4191 _iterator.e(err);
4192 } finally {
4193 _iterator.f();
4194 }
4195 };
4196
4197 function ownKeys$8(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; }
4198 function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4199 var addMark = function addMark(editor, key, value) {
4200 var selection = editor.selection;
4201 if (selection) {
4202 var match = function match(node, path) {
4203 if (!Text.isText(node)) {
4204 return false; // marks can only be applied to text
4205 }
4206
4207 var _Editor$parent = Editor.parent(editor, path),
4208 _Editor$parent2 = _slicedToArray(_Editor$parent, 2),
4209 parentNode = _Editor$parent2[0];
4210 _Editor$parent2[1];
4211 return !editor.isVoid(parentNode) || editor.markableVoid(parentNode);
4212 };
4213 var expandedSelection = Range.isExpanded(selection);
4214 var markAcceptingVoidSelected = false;
4215 if (!expandedSelection) {
4216 var _Editor$node = Editor.node(editor, selection),
4217 _Editor$node2 = _slicedToArray(_Editor$node, 2),
4218 selectedNode = _Editor$node2[0],
4219 selectedPath = _Editor$node2[1];
4220 if (selectedNode && match(selectedNode, selectedPath)) {
4221 var _Editor$parent3 = Editor.parent(editor, selectedPath),
4222 _Editor$parent4 = _slicedToArray(_Editor$parent3, 1),
4223 parentNode = _Editor$parent4[0];
4224 markAcceptingVoidSelected = parentNode && editor.markableVoid(parentNode);
4225 }
4226 }
4227 if (expandedSelection || markAcceptingVoidSelected) {
4228 Transforms.setNodes(editor, _defineProperty({}, key, value), {
4229 match: match,
4230 split: true,
4231 voids: true
4232 });
4233 } else {
4234 var marks = _objectSpread$8(_objectSpread$8({}, Editor.marks(editor) || {}), {}, _defineProperty({}, key, value));
4235 editor.marks = marks;
4236 if (!FLUSHING.get(editor)) {
4237 editor.onChange();
4238 }
4239 }
4240 }
4241 };
4242
4243 function ownKeys$7(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; }
4244 function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4245 function _createForOfIteratorHelper$e(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$e(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; } } }; }
4246 function _unsupportedIterableToArray$e(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$e(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$e(o, minLen); }
4247 function _arrayLikeToArray$e(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; }
4248 var after = function after(editor, at) {
4249 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4250 var anchor = Editor.point(editor, at, {
4251 edge: 'end'
4252 });
4253 var focus = Editor.end(editor, []);
4254 var range = {
4255 anchor: anchor,
4256 focus: focus
4257 };
4258 var _options$distance = options.distance,
4259 distance = _options$distance === void 0 ? 1 : _options$distance;
4260 var d = 0;
4261 var target;
4262 var _iterator = _createForOfIteratorHelper$e(Editor.positions(editor, _objectSpread$7(_objectSpread$7({}, options), {}, {
4263 at: range
4264 }))),
4265 _step;
4266 try {
4267 for (_iterator.s(); !(_step = _iterator.n()).done;) {
4268 var p = _step.value;
4269 if (d > distance) {
4270 break;
4271 }
4272 if (d !== 0) {
4273 target = p;
4274 }
4275 d++;
4276 }
4277 } catch (err) {
4278 _iterator.e(err);
4279 } finally {
4280 _iterator.f();
4281 }
4282 return target;
4283 };
4284
4285 function ownKeys$6(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; }
4286 function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4287 function _createForOfIteratorHelper$d(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$d(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; } } }; }
4288 function _unsupportedIterableToArray$d(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$d(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$d(o, minLen); }
4289 function _arrayLikeToArray$d(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; }
4290 var before = function before(editor, at) {
4291 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4292 var anchor = Editor.start(editor, []);
4293 var focus = Editor.point(editor, at, {
4294 edge: 'start'
4295 });
4296 var range = {
4297 anchor: anchor,
4298 focus: focus
4299 };
4300 var _options$distance = options.distance,
4301 distance = _options$distance === void 0 ? 1 : _options$distance;
4302 var d = 0;
4303 var target;
4304 var _iterator = _createForOfIteratorHelper$d(Editor.positions(editor, _objectSpread$6(_objectSpread$6({}, options), {}, {
4305 at: range,
4306 reverse: true
4307 }))),
4308 _step;
4309 try {
4310 for (_iterator.s(); !(_step = _iterator.n()).done;) {
4311 var p = _step.value;
4312 if (d > distance) {
4313 break;
4314 }
4315 if (d !== 0) {
4316 target = p;
4317 }
4318 d++;
4319 }
4320 } catch (err) {
4321 _iterator.e(err);
4322 } finally {
4323 _iterator.f();
4324 }
4325 return target;
4326 };
4327
4328 var deleteBackward = function deleteBackward(editor, unit) {
4329 var selection = editor.selection;
4330 if (selection && Range.isCollapsed(selection)) {
4331 Transforms["delete"](editor, {
4332 unit: unit,
4333 reverse: true
4334 });
4335 }
4336 };
4337
4338 var deleteForward = function deleteForward(editor, unit) {
4339 var selection = editor.selection;
4340 if (selection && Range.isCollapsed(selection)) {
4341 Transforms["delete"](editor, {
4342 unit: unit
4343 });
4344 }
4345 };
4346
4347 var deleteFragment = function deleteFragment(editor) {
4348 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
4349 _ref$direction = _ref.direction,
4350 direction = _ref$direction === void 0 ? 'forward' : _ref$direction;
4351 var selection = editor.selection;
4352 if (selection && Range.isExpanded(selection)) {
4353 Transforms["delete"](editor, {
4354 reverse: direction === 'backward'
4355 });
4356 }
4357 };
4358
4359 var edges = function edges(editor, at) {
4360 return [Editor.start(editor, at), Editor.end(editor, at)];
4361 };
4362
4363 function ownKeys$5(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; }
4364 function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4365 var elementReadOnly = function elementReadOnly(editor) {
4366 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4367 return Editor.above(editor, _objectSpread$5(_objectSpread$5({}, options), {}, {
4368 match: function match(n) {
4369 return Element.isElement(n) && Editor.isElementReadOnly(editor, n);
4370 }
4371 }));
4372 };
4373
4374 var end = function end(editor, at) {
4375 return Editor.point(editor, at, {
4376 edge: 'end'
4377 });
4378 };
4379
4380 var first = function first(editor, at) {
4381 var path = Editor.path(editor, at, {
4382 edge: 'start'
4383 });
4384 return Editor.node(editor, path);
4385 };
4386
4387 var fragment = function fragment(editor, at) {
4388 var range = Editor.range(editor, at);
4389 return Node.fragment(editor, range);
4390 };
4391
4392 function ownKeys$4(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; }
4393 function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4394 var getVoid = function getVoid(editor) {
4395 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4396 return Editor.above(editor, _objectSpread$4(_objectSpread$4({}, options), {}, {
4397 match: function match(n) {
4398 return Element.isElement(n) && Editor.isVoid(editor, n);
4399 }
4400 }));
4401 };
4402
4403 var hasBlocks = function hasBlocks(editor, element) {
4404 return element.children.some(function (n) {
4405 return Element.isElement(n) && Editor.isBlock(editor, n);
4406 });
4407 };
4408
4409 var hasInlines = function hasInlines(editor, element) {
4410 return element.children.some(function (n) {
4411 return Text.isText(n) || Editor.isInline(editor, n);
4412 });
4413 };
4414
4415 var hasPath = function hasPath(editor, path) {
4416 return Node.has(editor, path);
4417 };
4418
4419 var hasTexts = function hasTexts(editor, element) {
4420 return element.children.every(function (n) {
4421 return Text.isText(n);
4422 });
4423 };
4424
4425 var insertBreak = function insertBreak(editor) {
4426 Transforms.splitNodes(editor, {
4427 always: true
4428 });
4429 };
4430
4431 var insertNode = function insertNode(editor, node, options) {
4432 Transforms.insertNodes(editor, node, options);
4433 };
4434
4435 var insertSoftBreak = function insertSoftBreak(editor) {
4436 Transforms.splitNodes(editor, {
4437 always: true
4438 });
4439 };
4440
4441 function ownKeys$3(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; }
4442 function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4443 var insertText = function insertText(editor, text) {
4444 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4445 var selection = editor.selection,
4446 marks = editor.marks;
4447 if (selection) {
4448 if (marks) {
4449 var node = _objectSpread$3({
4450 text: text
4451 }, marks);
4452 Transforms.insertNodes(editor, node, {
4453 at: options.at,
4454 voids: options.voids
4455 });
4456 } else {
4457 Transforms.insertText(editor, text, options);
4458 }
4459 editor.marks = null;
4460 }
4461 };
4462
4463 var isBlock = function isBlock(editor, value) {
4464 return !editor.isInline(value);
4465 };
4466
4467 var isEdge = function isEdge(editor, point, at) {
4468 return Editor.isStart(editor, point, at) || Editor.isEnd(editor, point, at);
4469 };
4470
4471 var isEmpty = function isEmpty(editor, element) {
4472 var children = element.children;
4473 var _children = _slicedToArray(children, 1),
4474 first = _children[0];
4475 return children.length === 0 || children.length === 1 && Text.isText(first) && first.text === '' && !editor.isVoid(element);
4476 };
4477
4478 var isEnd = function isEnd(editor, point, at) {
4479 var end = Editor.end(editor, at);
4480 return Point.equals(point, end);
4481 };
4482
4483 var isNormalizing = function isNormalizing(editor) {
4484 var isNormalizing = NORMALIZING.get(editor);
4485 return isNormalizing === undefined ? true : isNormalizing;
4486 };
4487
4488 var isStart = function isStart(editor, point, at) {
4489 // PERF: If the offset isn't `0` we know it's not the start.
4490 if (point.offset !== 0) {
4491 return false;
4492 }
4493 var start = Editor.start(editor, at);
4494 return Point.equals(point, start);
4495 };
4496
4497 var last = function last(editor, at) {
4498 var path = Editor.path(editor, at, {
4499 edge: 'end'
4500 });
4501 return Editor.node(editor, path);
4502 };
4503
4504 var leaf = function leaf(editor, at) {
4505 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4506 var path = Editor.path(editor, at, options);
4507 var node = Node.leaf(editor, path);
4508 return [node, path];
4509 };
4510
4511 function _createForOfIteratorHelper$c(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$c(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; } } }; }
4512 function _unsupportedIterableToArray$c(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$c(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$c(o, minLen); }
4513 function _arrayLikeToArray$c(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; }
4514 function levels(editor) {
4515 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4516 return /*#__PURE__*/regenerator.mark(function _callee() {
4517 var _options$at, at, _options$reverse, reverse, _options$voids, voids, match, levels, path, _iterator, _step, _step$value, n, p;
4518 return regenerator.wrap(function _callee$(_context) {
4519 while (1) switch (_context.prev = _context.next) {
4520 case 0:
4521 _options$at = options.at, at = _options$at === void 0 ? editor.selection : _options$at, _options$reverse = options.reverse, reverse = _options$reverse === void 0 ? false : _options$reverse, _options$voids = options.voids, voids = _options$voids === void 0 ? false : _options$voids;
4522 match = options.match;
4523 if (match == null) {
4524 match = function match() {
4525 return true;
4526 };
4527 }
4528 if (at) {
4529 _context.next = 5;
4530 break;
4531 }
4532 return _context.abrupt("return");
4533 case 5:
4534 levels = [];
4535 path = Editor.path(editor, at);
4536 _iterator = _createForOfIteratorHelper$c(Node.levels(editor, path));
4537 _context.prev = 8;
4538 _iterator.s();
4539 case 10:
4540 if ((_step = _iterator.n()).done) {
4541 _context.next = 19;
4542 break;
4543 }
4544 _step$value = _slicedToArray(_step.value, 2), n = _step$value[0], p = _step$value[1];
4545 if (match(n, p)) {
4546 _context.next = 14;
4547 break;
4548 }
4549 return _context.abrupt("continue", 17);
4550 case 14:
4551 levels.push([n, p]);
4552 if (!(!voids && Element.isElement(n) && Editor.isVoid(editor, n))) {
4553 _context.next = 17;
4554 break;
4555 }
4556 return _context.abrupt("break", 19);
4557 case 17:
4558 _context.next = 10;
4559 break;
4560 case 19:
4561 _context.next = 24;
4562 break;
4563 case 21:
4564 _context.prev = 21;
4565 _context.t0 = _context["catch"](8);
4566 _iterator.e(_context.t0);
4567 case 24:
4568 _context.prev = 24;
4569 _iterator.f();
4570 return _context.finish(24);
4571 case 27:
4572 if (reverse) {
4573 levels.reverse();
4574 }
4575 return _context.delegateYield(levels, "t1", 29);
4576 case 29:
4577 case "end":
4578 return _context.stop();
4579 }
4580 }, _callee, null, [[8, 21, 24, 27]]);
4581 })();
4582 }
4583
4584 var _excluded$1 = ["text"],
4585 _excluded2$1 = ["text"];
4586 var marks = function marks(editor) {
4587 var marks = editor.marks,
4588 selection = editor.selection;
4589 if (!selection) {
4590 return null;
4591 }
4592 var anchor = selection.anchor,
4593 focus = selection.focus;
4594 if (marks) {
4595 return marks;
4596 }
4597 if (Range.isExpanded(selection)) {
4598 /**
4599 * COMPAT: Make sure hanging ranges (caused by double clicking in Firefox)
4600 * do not adversely affect the returned marks.
4601 */
4602 var isEnd = Editor.isEnd(editor, anchor, anchor.path);
4603 if (isEnd) {
4604 var after = Editor.after(editor, anchor);
4605 if (after) {
4606 anchor = after;
4607 }
4608 }
4609 var _Editor$nodes = Editor.nodes(editor, {
4610 match: Text.isText,
4611 at: {
4612 anchor: anchor,
4613 focus: focus
4614 }
4615 }),
4616 _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
4617 match = _Editor$nodes2[0];
4618 if (match) {
4619 var _match = _slicedToArray(match, 1),
4620 _node = _match[0];
4621 _node.text;
4622 var _rest = _objectWithoutProperties(_node, _excluded$1);
4623 return _rest;
4624 } else {
4625 return {};
4626 }
4627 }
4628 var _anchor = anchor,
4629 path = _anchor.path;
4630 var _Editor$leaf = Editor.leaf(editor, path),
4631 _Editor$leaf2 = _slicedToArray(_Editor$leaf, 1),
4632 node = _Editor$leaf2[0];
4633 if (anchor.offset === 0) {
4634 var prev = Editor.previous(editor, {
4635 at: path,
4636 match: Text.isText
4637 });
4638 var markedVoid = Editor.above(editor, {
4639 match: function match(n) {
4640 return Element.isElement(n) && Editor.isVoid(editor, n) && editor.markableVoid(n);
4641 }
4642 });
4643 if (!markedVoid) {
4644 var block = Editor.above(editor, {
4645 match: function match(n) {
4646 return Element.isElement(n) && Editor.isBlock(editor, n);
4647 }
4648 });
4649 if (prev && block) {
4650 var _prev = _slicedToArray(prev, 2),
4651 prevNode = _prev[0],
4652 prevPath = _prev[1];
4653 var _block = _slicedToArray(block, 2),
4654 blockPath = _block[1];
4655 if (Path.isAncestor(blockPath, prevPath)) {
4656 node = prevNode;
4657 }
4658 }
4659 }
4660 }
4661 var _node2 = node;
4662 _node2.text;
4663 var rest = _objectWithoutProperties(_node2, _excluded2$1);
4664 return rest;
4665 };
4666
4667 var next = function next(editor) {
4668 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4669 var _options$mode = options.mode,
4670 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
4671 _options$voids = options.voids,
4672 voids = _options$voids === void 0 ? false : _options$voids;
4673 var match = options.match,
4674 _options$at = options.at,
4675 at = _options$at === void 0 ? editor.selection : _options$at;
4676 if (!at) {
4677 return;
4678 }
4679 var pointAfterLocation = Editor.after(editor, at, {
4680 voids: voids
4681 });
4682 if (!pointAfterLocation) return;
4683 var _Editor$last = Editor.last(editor, []),
4684 _Editor$last2 = _slicedToArray(_Editor$last, 2),
4685 to = _Editor$last2[1];
4686 var span = [pointAfterLocation.path, to];
4687 if (Path.isPath(at) && at.length === 0) {
4688 throw new Error("Cannot get the next node from the root node!");
4689 }
4690 if (match == null) {
4691 if (Path.isPath(at)) {
4692 var _Editor$parent = Editor.parent(editor, at),
4693 _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
4694 parent = _Editor$parent2[0];
4695 match = function match(n) {
4696 return parent.children.includes(n);
4697 };
4698 } else {
4699 match = function match() {
4700 return true;
4701 };
4702 }
4703 }
4704 var _Editor$nodes = Editor.nodes(editor, {
4705 at: span,
4706 match: match,
4707 mode: mode,
4708 voids: voids
4709 }),
4710 _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
4711 next = _Editor$nodes2[0];
4712 return next;
4713 };
4714
4715 var node = function node(editor, at) {
4716 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4717 var path = Editor.path(editor, at, options);
4718 var node = Node.get(editor, path);
4719 return [node, path];
4720 };
4721
4722 function _createForOfIteratorHelper$b(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$b(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; } } }; }
4723 function _unsupportedIterableToArray$b(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$b(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$b(o, minLen); }
4724 function _arrayLikeToArray$b(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; }
4725 function nodes(editor) {
4726 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4727 return /*#__PURE__*/regenerator.mark(function _callee() {
4728 var _options$at, at, _options$mode, mode, _options$universal, universal, _options$reverse, reverse, _options$voids, voids, _options$ignoreNonSel, ignoreNonSelectable, match, from, to, first, last, nodeEntries, matches, hit, _iterator, _step, _step$value, node, path, isLower, emit;
4729 return regenerator.wrap(function _callee$(_context) {
4730 while (1) switch (_context.prev = _context.next) {
4731 case 0:
4732 _options$at = options.at, at = _options$at === void 0 ? editor.selection : _options$at, _options$mode = options.mode, mode = _options$mode === void 0 ? 'all' : _options$mode, _options$universal = options.universal, universal = _options$universal === void 0 ? false : _options$universal, _options$reverse = options.reverse, reverse = _options$reverse === void 0 ? false : _options$reverse, _options$voids = options.voids, voids = _options$voids === void 0 ? false : _options$voids, _options$ignoreNonSel = options.ignoreNonSelectable, ignoreNonSelectable = _options$ignoreNonSel === void 0 ? false : _options$ignoreNonSel;
4733 match = options.match;
4734 if (!match) {
4735 match = function match() {
4736 return true;
4737 };
4738 }
4739 if (at) {
4740 _context.next = 5;
4741 break;
4742 }
4743 return _context.abrupt("return");
4744 case 5:
4745 if (Span.isSpan(at)) {
4746 from = at[0];
4747 to = at[1];
4748 } else {
4749 first = Editor.path(editor, at, {
4750 edge: 'start'
4751 });
4752 last = Editor.path(editor, at, {
4753 edge: 'end'
4754 });
4755 from = reverse ? last : first;
4756 to = reverse ? first : last;
4757 }
4758 nodeEntries = Node.nodes(editor, {
4759 reverse: reverse,
4760 from: from,
4761 to: to,
4762 pass: function pass(_ref) {
4763 var _ref2 = _slicedToArray(_ref, 1),
4764 node = _ref2[0];
4765 if (!Element.isElement(node)) return false;
4766 if (!voids && (Editor.isVoid(editor, node) || Editor.isElementReadOnly(editor, node))) return true;
4767 if (ignoreNonSelectable && !Editor.isSelectable(editor, node)) return true;
4768 return false;
4769 }
4770 });
4771 matches = [];
4772 _iterator = _createForOfIteratorHelper$b(nodeEntries);
4773 _context.prev = 9;
4774 _iterator.s();
4775 case 11:
4776 if ((_step = _iterator.n()).done) {
4777 _context.next = 38;
4778 break;
4779 }
4780 _step$value = _slicedToArray(_step.value, 2), node = _step$value[0], path = _step$value[1];
4781 if (!(ignoreNonSelectable && Element.isElement(node) && !Editor.isSelectable(editor, node))) {
4782 _context.next = 15;
4783 break;
4784 }
4785 return _context.abrupt("continue", 36);
4786 case 15:
4787 isLower = hit && Path.compare(path, hit[1]) === 0; // In highest mode any node lower than the last hit is not a match.
4788 if (!(mode === 'highest' && isLower)) {
4789 _context.next = 18;
4790 break;
4791 }
4792 return _context.abrupt("continue", 36);
4793 case 18:
4794 if (match(node, path)) {
4795 _context.next = 24;
4796 break;
4797 }
4798 if (!(universal && !isLower && Text.isText(node))) {
4799 _context.next = 23;
4800 break;
4801 }
4802 return _context.abrupt("return");
4803 case 23:
4804 return _context.abrupt("continue", 36);
4805 case 24:
4806 if (!(mode === 'lowest' && isLower)) {
4807 _context.next = 27;
4808 break;
4809 }
4810 hit = [node, path];
4811 return _context.abrupt("continue", 36);
4812 case 27:
4813 // In lowest mode we emit the last hit, once it's guaranteed lowest.
4814 emit = mode === 'lowest' ? hit : [node, path];
4815 if (!emit) {
4816 _context.next = 35;
4817 break;
4818 }
4819 if (!universal) {
4820 _context.next = 33;
4821 break;
4822 }
4823 matches.push(emit);
4824 _context.next = 35;
4825 break;
4826 case 33:
4827 _context.next = 35;
4828 return emit;
4829 case 35:
4830 hit = [node, path];
4831 case 36:
4832 _context.next = 11;
4833 break;
4834 case 38:
4835 _context.next = 43;
4836 break;
4837 case 40:
4838 _context.prev = 40;
4839 _context.t0 = _context["catch"](9);
4840 _iterator.e(_context.t0);
4841 case 43:
4842 _context.prev = 43;
4843 _iterator.f();
4844 return _context.finish(43);
4845 case 46:
4846 if (!(mode === 'lowest' && hit)) {
4847 _context.next = 53;
4848 break;
4849 }
4850 if (!universal) {
4851 _context.next = 51;
4852 break;
4853 }
4854 matches.push(hit);
4855 _context.next = 53;
4856 break;
4857 case 51:
4858 _context.next = 53;
4859 return hit;
4860 case 53:
4861 if (!universal) {
4862 _context.next = 55;
4863 break;
4864 }
4865 return _context.delegateYield(matches, "t1", 55);
4866 case 55:
4867 case "end":
4868 return _context.stop();
4869 }
4870 }, _callee, null, [[9, 40, 43, 46]]);
4871 })();
4872 }
4873
4874 function _createForOfIteratorHelper$a(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$a(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; } } }; }
4875 function _unsupportedIterableToArray$a(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$a(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$a(o, minLen); }
4876 function _arrayLikeToArray$a(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; }
4877 var normalize = function normalize(editor) {
4878 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4879 var _options$force = options.force,
4880 force = _options$force === void 0 ? false : _options$force,
4881 operation = options.operation;
4882 var getDirtyPaths = function getDirtyPaths(editor) {
4883 return DIRTY_PATHS.get(editor) || [];
4884 };
4885 var getDirtyPathKeys = function getDirtyPathKeys(editor) {
4886 return DIRTY_PATH_KEYS.get(editor) || new Set();
4887 };
4888 var popDirtyPath = function popDirtyPath(editor) {
4889 var path = getDirtyPaths(editor).pop();
4890 var key = path.join(',');
4891 getDirtyPathKeys(editor)["delete"](key);
4892 return path;
4893 };
4894 if (!Editor.isNormalizing(editor)) {
4895 return;
4896 }
4897 if (force) {
4898 var allPaths = Array.from(Node.nodes(editor), function (_ref) {
4899 var _ref2 = _slicedToArray(_ref, 2),
4900 p = _ref2[1];
4901 return p;
4902 });
4903 var allPathKeys = new Set(allPaths.map(function (p) {
4904 return p.join(',');
4905 }));
4906 DIRTY_PATHS.set(editor, allPaths);
4907 DIRTY_PATH_KEYS.set(editor, allPathKeys);
4908 }
4909 if (getDirtyPaths(editor).length === 0) {
4910 return;
4911 }
4912 Editor.withoutNormalizing(editor, function () {
4913 /*
4914 Fix dirty elements with no children.
4915 editor.normalizeNode() does fix this, but some normalization fixes also require it to work.
4916 Running an initial pass avoids the catch-22 race condition.
4917 */
4918 var _iterator = _createForOfIteratorHelper$a(getDirtyPaths(editor)),
4919 _step;
4920 try {
4921 for (_iterator.s(); !(_step = _iterator.n()).done;) {
4922 var _dirtyPath = _step.value;
4923 if (Node.has(editor, _dirtyPath)) {
4924 var _entry = Editor.node(editor, _dirtyPath);
4925 var _entry2 = _slicedToArray(_entry, 2),
4926 node = _entry2[0],
4927 _ = _entry2[1];
4928 /*
4929 The default normalizer inserts an empty text node in this scenario, but it can be customised.
4930 So there is some risk here.
4931 As long as the normalizer only inserts child nodes for this case it is safe to do in any order;
4932 by definition adding children to an empty node can't cause other paths to change.
4933 */
4934 if (Element.isElement(node) && node.children.length === 0) {
4935 editor.normalizeNode(_entry, {
4936 operation: operation
4937 });
4938 }
4939 }
4940 }
4941 } catch (err) {
4942 _iterator.e(err);
4943 } finally {
4944 _iterator.f();
4945 }
4946 var dirtyPaths = getDirtyPaths(editor);
4947 var initialDirtyPathsLength = dirtyPaths.length;
4948 var iteration = 0;
4949 while (dirtyPaths.length !== 0) {
4950 if (!editor.shouldNormalize({
4951 dirtyPaths: dirtyPaths,
4952 iteration: iteration,
4953 initialDirtyPathsLength: initialDirtyPathsLength,
4954 operation: operation
4955 })) {
4956 return;
4957 }
4958 var dirtyPath = popDirtyPath(editor);
4959 // If the node doesn't exist in the tree, it does not need to be normalized.
4960 if (Node.has(editor, dirtyPath)) {
4961 var entry = Editor.node(editor, dirtyPath);
4962 editor.normalizeNode(entry, {
4963 operation: operation
4964 });
4965 }
4966 iteration++;
4967 dirtyPaths = getDirtyPaths(editor);
4968 }
4969 });
4970 };
4971
4972 var parent = function parent(editor, at) {
4973 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4974 var path = Editor.path(editor, at, options);
4975 var parentPath = Path.parent(path);
4976 var entry = Editor.node(editor, parentPath);
4977 return entry;
4978 };
4979
4980 var pathRef = function pathRef(editor, path) {
4981 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4982 var _options$affinity = options.affinity,
4983 affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
4984 var ref = {
4985 current: path,
4986 affinity: affinity,
4987 unref: function unref() {
4988 var current = ref.current;
4989 var pathRefs = Editor.pathRefs(editor);
4990 pathRefs["delete"](ref);
4991 ref.current = null;
4992 return current;
4993 }
4994 };
4995 var refs = Editor.pathRefs(editor);
4996 refs.add(ref);
4997 return ref;
4998 };
4999
5000 var pathRefs = function pathRefs(editor) {
5001 var refs = PATH_REFS.get(editor);
5002 if (!refs) {
5003 refs = new Set();
5004 PATH_REFS.set(editor, refs);
5005 }
5006 return refs;
5007 };
5008
5009 var path = function path(editor, at) {
5010 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5011 var depth = options.depth,
5012 edge = options.edge;
5013 if (Path.isPath(at)) {
5014 if (edge === 'start') {
5015 var _Node$first = Node.first(editor, at),
5016 _Node$first2 = _slicedToArray(_Node$first, 2),
5017 firstPath = _Node$first2[1];
5018 at = firstPath;
5019 } else if (edge === 'end') {
5020 var _Node$last = Node.last(editor, at),
5021 _Node$last2 = _slicedToArray(_Node$last, 2),
5022 lastPath = _Node$last2[1];
5023 at = lastPath;
5024 }
5025 }
5026 if (Range.isRange(at)) {
5027 if (edge === 'start') {
5028 at = Range.start(at);
5029 } else if (edge === 'end') {
5030 at = Range.end(at);
5031 } else {
5032 at = Path.common(at.anchor.path, at.focus.path);
5033 }
5034 }
5035 if (Point.isPoint(at)) {
5036 at = at.path;
5037 }
5038 if (depth != null) {
5039 at = at.slice(0, depth);
5040 }
5041 return at;
5042 };
5043
5044 var pointRef = function pointRef(editor, point) {
5045 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5046 var _options$affinity = options.affinity,
5047 affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
5048 var ref = {
5049 current: point,
5050 affinity: affinity,
5051 unref: function unref() {
5052 var current = ref.current;
5053 var pointRefs = Editor.pointRefs(editor);
5054 pointRefs["delete"](ref);
5055 ref.current = null;
5056 return current;
5057 }
5058 };
5059 var refs = Editor.pointRefs(editor);
5060 refs.add(ref);
5061 return ref;
5062 };
5063
5064 var pointRefs = function pointRefs(editor) {
5065 var refs = POINT_REFS.get(editor);
5066 if (!refs) {
5067 refs = new Set();
5068 POINT_REFS.set(editor, refs);
5069 }
5070 return refs;
5071 };
5072
5073 var point = function point(editor, at) {
5074 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5075 var _options$edge = options.edge,
5076 edge = _options$edge === void 0 ? 'start' : _options$edge;
5077 if (Path.isPath(at)) {
5078 var path;
5079 if (edge === 'end') {
5080 var _Node$last = Node.last(editor, at),
5081 _Node$last2 = _slicedToArray(_Node$last, 2),
5082 lastPath = _Node$last2[1];
5083 path = lastPath;
5084 } else {
5085 var _Node$first = Node.first(editor, at),
5086 _Node$first2 = _slicedToArray(_Node$first, 2),
5087 firstPath = _Node$first2[1];
5088 path = firstPath;
5089 }
5090 var node = Node.get(editor, path);
5091 if (!Text.isText(node)) {
5092 throw new Error("Cannot get the ".concat(edge, " point in the node at path [").concat(at, "] because it has no ").concat(edge, " text node."));
5093 }
5094 return {
5095 path: path,
5096 offset: edge === 'end' ? node.text.length : 0
5097 };
5098 }
5099 if (Range.isRange(at)) {
5100 var _Range$edges = Range.edges(at),
5101 _Range$edges2 = _slicedToArray(_Range$edges, 2),
5102 start = _Range$edges2[0],
5103 end = _Range$edges2[1];
5104 return edge === 'start' ? start : end;
5105 }
5106 return at;
5107 };
5108
5109 function _createForOfIteratorHelper$9(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$9(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; } } }; }
5110 function _unsupportedIterableToArray$9(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$9(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$9(o, minLen); }
5111 function _arrayLikeToArray$9(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; }
5112 function positions(editor) {
5113 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5114 return /*#__PURE__*/regenerator.mark(function _callee() {
5115 var _options$at, at, _options$unit, unit, _options$reverse, reverse, _options$voids, voids, _options$ignoreNonSel, ignoreNonSelectable, range, _Range$edges, _Range$edges2, start, end, first, isNewBlock, blockText, distance, leafTextRemaining, leafTextOffset, _iterator, _step, _step$value, node, path, e, s, isFirst, calcDistance;
5116 return regenerator.wrap(function _callee$(_context) {
5117 while (1) switch (_context.prev = _context.next) {
5118 case 0:
5119 calcDistance = function _calcDistance(text, unit, reverse) {
5120 if (unit === 'character') {
5121 return getCharacterDistance(text, reverse);
5122 } else if (unit === 'word') {
5123 return getWordDistance(text, reverse);
5124 } else if (unit === 'line' || unit === 'block') {
5125 return text.length;
5126 }
5127 return 1;
5128 };
5129 _options$at = options.at, at = _options$at === void 0 ? editor.selection : _options$at, _options$unit = options.unit, unit = _options$unit === void 0 ? 'offset' : _options$unit, _options$reverse = options.reverse, reverse = _options$reverse === void 0 ? false : _options$reverse, _options$voids = options.voids, voids = _options$voids === void 0 ? false : _options$voids, _options$ignoreNonSel = options.ignoreNonSelectable, ignoreNonSelectable = _options$ignoreNonSel === void 0 ? false : _options$ignoreNonSel;
5130 if (at) {
5131 _context.next = 4;
5132 break;
5133 }
5134 return _context.abrupt("return");
5135 case 4:
5136 /**
5137 * Algorithm notes:
5138 *
5139 * Each step `distance` is dynamic depending on the underlying text
5140 * and the `unit` specified. Each step, e.g., a line or word, may
5141 * span multiple text nodes, so we iterate through the text both on
5142 * two levels in step-sync:
5143 *
5144 * `leafText` stores the text on a text leaf level, and is advanced
5145 * through using the counters `leafTextOffset` and `leafTextRemaining`.
5146 *
5147 * `blockText` stores the text on a block level, and is shortened
5148 * by `distance` every time it is advanced.
5149 *
5150 * We only maintain a window of one blockText and one leafText because
5151 * a block node always appears before all of its leaf nodes.
5152 */
5153 range = Editor.range(editor, at);
5154 _Range$edges = Range.edges(range), _Range$edges2 = _slicedToArray(_Range$edges, 2), start = _Range$edges2[0], end = _Range$edges2[1];
5155 first = reverse ? end : start;
5156 isNewBlock = false;
5157 blockText = '';
5158 distance = 0; // Distance for leafText to catch up to blockText.
5159 leafTextRemaining = 0;
5160 leafTextOffset = 0; // Iterate through all nodes in range, grabbing entire textual content
5161 // of block nodes in blockText, and text nodes in leafText.
5162 // Exploits the fact that nodes are sequenced in such a way that we first
5163 // encounter the block node, then all of its text nodes, so when iterating
5164 // through the blockText and leafText we just need to remember a window of
5165 // one block node and leaf node, respectively.
5166 _iterator = _createForOfIteratorHelper$9(Editor.nodes(editor, {
5167 at: at,
5168 reverse: reverse,
5169 voids: voids,
5170 ignoreNonSelectable: ignoreNonSelectable
5171 }));
5172 _context.prev = 13;
5173 _iterator.s();
5174 case 15:
5175 if ((_step = _iterator.n()).done) {
5176 _context.next = 50;
5177 break;
5178 }
5179 _step$value = _slicedToArray(_step.value, 2), node = _step$value[0], path = _step$value[1];
5180 if (!Element.isElement(node)) {
5181 _context.next = 25;
5182 break;
5183 }
5184 if (!(!voids && (editor.isVoid(node) || editor.isElementReadOnly(node)))) {
5185 _context.next = 22;
5186 break;
5187 }
5188 _context.next = 21;
5189 return Editor.start(editor, path);
5190 case 21:
5191 return _context.abrupt("continue", 48);
5192 case 22:
5193 if (!editor.isInline(node)) {
5194 _context.next = 24;
5195 break;
5196 }
5197 return _context.abrupt("continue", 48);
5198 case 24:
5199 // Block element node - set `blockText` to its text content.
5200 if (Editor.hasInlines(editor, node)) {
5201 // We always exhaust block nodes before encountering a new one:
5202 // console.assert(blockText === '',
5203 // `blockText='${blockText}' - `+
5204 // `not exhausted before new block node`, path)
5205 // Ensure range considered is capped to `range`, in the
5206 // start/end edge cases where block extends beyond range.
5207 // Equivalent to this, but presumably more performant:
5208 // blockRange = Editor.range(editor, ...Editor.edges(editor, path))
5209 // blockRange = Range.intersection(range, blockRange) // intersect
5210 // blockText = Editor.string(editor, blockRange, { voids })
5211 e = Path.isAncestor(path, end.path) ? end : Editor.end(editor, path);
5212 s = Path.isAncestor(path, start.path) ? start : Editor.start(editor, path);
5213 blockText = Editor.string(editor, {
5214 anchor: s,
5215 focus: e
5216 }, {
5217 voids: voids
5218 });
5219 isNewBlock = true;
5220 }
5221 case 25:
5222 if (!Text.isText(node)) {
5223 _context.next = 48;
5224 break;
5225 }
5226 isFirst = Path.equals(path, first.path); // Proof that we always exhaust text nodes before encountering a new one:
5227 // console.assert(leafTextRemaining <= 0,
5228 // `leafTextRemaining=${leafTextRemaining} - `+
5229 // `not exhausted before new leaf text node`, path)
5230 // Reset `leafText` counters for new text node.
5231 if (isFirst) {
5232 leafTextRemaining = reverse ? first.offset : node.text.length - first.offset;
5233 leafTextOffset = first.offset; // Works for reverse too.
5234 } else {
5235 leafTextRemaining = node.text.length;
5236 leafTextOffset = reverse ? leafTextRemaining : 0;
5237 }
5238 // Yield position at the start of node (potentially).
5239 if (!(isFirst || isNewBlock || unit === 'offset')) {
5240 _context.next = 32;
5241 break;
5242 }
5243 _context.next = 31;
5244 return {
5245 path: path,
5246 offset: leafTextOffset
5247 };
5248 case 31:
5249 isNewBlock = false;
5250 case 32:
5251 if (!(distance === 0)) {
5252 _context.next = 38;
5253 break;
5254 }
5255 if (!(blockText === '')) {
5256 _context.next = 36;
5257 break;
5258 }
5259 return _context.abrupt("break", 48);
5260 case 36:
5261 distance = calcDistance(blockText, unit, reverse);
5262 // Split the string at the previously found distance and use the
5263 // remaining string for the next iteration.
5264 blockText = splitByCharacterDistance(blockText, distance, reverse)[1];
5265 case 38:
5266 // Advance `leafText` by the current `distance`.
5267 leafTextOffset = reverse ? leafTextOffset - distance : leafTextOffset + distance;
5268 leafTextRemaining = leafTextRemaining - distance;
5269 // If `leafText` is exhausted, break to get a new leaf node
5270 // and set distance to the overflow amount, so we'll (maybe)
5271 // catch up to blockText in the next leaf text node.
5272 if (!(leafTextRemaining < 0)) {
5273 _context.next = 43;
5274 break;
5275 }
5276 distance = -leafTextRemaining;
5277 return _context.abrupt("break", 48);
5278 case 43:
5279 // Successfully walked `distance` offsets through `leafText`
5280 // to catch up with `blockText`, so we can reset `distance`
5281 // and yield this position in this node.
5282 distance = 0;
5283 _context.next = 46;
5284 return {
5285 path: path,
5286 offset: leafTextOffset
5287 };
5288 case 46:
5289 _context.next = 32;
5290 break;
5291 case 48:
5292 _context.next = 15;
5293 break;
5294 case 50:
5295 _context.next = 55;
5296 break;
5297 case 52:
5298 _context.prev = 52;
5299 _context.t0 = _context["catch"](13);
5300 _iterator.e(_context.t0);
5301 case 55:
5302 _context.prev = 55;
5303 _iterator.f();
5304 return _context.finish(55);
5305 case 58:
5306 case "end":
5307 return _context.stop();
5308 }
5309 }, _callee, null, [[13, 52, 55, 58]]);
5310 })();
5311 }
5312
5313 var previous = function previous(editor) {
5314 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5315 var _options$mode = options.mode,
5316 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
5317 _options$voids = options.voids,
5318 voids = _options$voids === void 0 ? false : _options$voids;
5319 var match = options.match,
5320 _options$at = options.at,
5321 at = _options$at === void 0 ? editor.selection : _options$at;
5322 if (!at) {
5323 return;
5324 }
5325 var pointBeforeLocation = Editor.before(editor, at, {
5326 voids: voids
5327 });
5328 if (!pointBeforeLocation) {
5329 return;
5330 }
5331 var _Editor$first = Editor.first(editor, []),
5332 _Editor$first2 = _slicedToArray(_Editor$first, 2),
5333 to = _Editor$first2[1];
5334 // The search location is from the start of the document to the path of
5335 // the point before the location passed in
5336 var span = [pointBeforeLocation.path, to];
5337 if (Path.isPath(at) && at.length === 0) {
5338 throw new Error("Cannot get the previous node from the root node!");
5339 }
5340 if (match == null) {
5341 if (Path.isPath(at)) {
5342 var _Editor$parent = Editor.parent(editor, at),
5343 _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
5344 parent = _Editor$parent2[0];
5345 match = function match(n) {
5346 return parent.children.includes(n);
5347 };
5348 } else {
5349 match = function match() {
5350 return true;
5351 };
5352 }
5353 }
5354 var _Editor$nodes = Editor.nodes(editor, {
5355 reverse: true,
5356 at: span,
5357 match: match,
5358 mode: mode,
5359 voids: voids
5360 }),
5361 _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
5362 previous = _Editor$nodes2[0];
5363 return previous;
5364 };
5365
5366 var rangeRef = function rangeRef(editor, range) {
5367 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5368 var _options$affinity = options.affinity,
5369 affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
5370 var ref = {
5371 current: range,
5372 affinity: affinity,
5373 unref: function unref() {
5374 var current = ref.current;
5375 var rangeRefs = Editor.rangeRefs(editor);
5376 rangeRefs["delete"](ref);
5377 ref.current = null;
5378 return current;
5379 }
5380 };
5381 var refs = Editor.rangeRefs(editor);
5382 refs.add(ref);
5383 return ref;
5384 };
5385
5386 var rangeRefs = function rangeRefs(editor) {
5387 var refs = RANGE_REFS.get(editor);
5388 if (!refs) {
5389 refs = new Set();
5390 RANGE_REFS.set(editor, refs);
5391 }
5392 return refs;
5393 };
5394
5395 var range = function range(editor, at, to) {
5396 if (Range.isRange(at) && !to) {
5397 return at;
5398 }
5399 var start = Editor.start(editor, at);
5400 var end = Editor.end(editor, to || at);
5401 return {
5402 anchor: start,
5403 focus: end
5404 };
5405 };
5406
5407 function ownKeys$2(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; }
5408 function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5409 var removeMark = function removeMark(editor, key) {
5410 var selection = editor.selection;
5411 if (selection) {
5412 var match = function match(node, path) {
5413 if (!Text.isText(node)) {
5414 return false; // marks can only be applied to text
5415 }
5416
5417 var _Editor$parent = Editor.parent(editor, path),
5418 _Editor$parent2 = _slicedToArray(_Editor$parent, 2),
5419 parentNode = _Editor$parent2[0];
5420 _Editor$parent2[1];
5421 return !editor.isVoid(parentNode) || editor.markableVoid(parentNode);
5422 };
5423 var expandedSelection = Range.isExpanded(selection);
5424 var markAcceptingVoidSelected = false;
5425 if (!expandedSelection) {
5426 var _Editor$node = Editor.node(editor, selection),
5427 _Editor$node2 = _slicedToArray(_Editor$node, 2),
5428 selectedNode = _Editor$node2[0],
5429 selectedPath = _Editor$node2[1];
5430 if (selectedNode && match(selectedNode, selectedPath)) {
5431 var _Editor$parent3 = Editor.parent(editor, selectedPath),
5432 _Editor$parent4 = _slicedToArray(_Editor$parent3, 1),
5433 parentNode = _Editor$parent4[0];
5434 markAcceptingVoidSelected = parentNode && editor.markableVoid(parentNode);
5435 }
5436 }
5437 if (expandedSelection || markAcceptingVoidSelected) {
5438 Transforms.unsetNodes(editor, key, {
5439 match: match,
5440 split: true,
5441 voids: true
5442 });
5443 } else {
5444 var marks = _objectSpread$2({}, Editor.marks(editor) || {});
5445 delete marks[key];
5446 editor.marks = marks;
5447 if (!FLUSHING.get(editor)) {
5448 editor.onChange();
5449 }
5450 }
5451 }
5452 };
5453
5454 var setNormalizing = function setNormalizing(editor, isNormalizing) {
5455 NORMALIZING.set(editor, isNormalizing);
5456 };
5457
5458 var start = function start(editor, at) {
5459 return Editor.point(editor, at, {
5460 edge: 'start'
5461 });
5462 };
5463
5464 function _createForOfIteratorHelper$8(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$8(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; } } }; }
5465 function _unsupportedIterableToArray$8(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$8(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$8(o, minLen); }
5466 function _arrayLikeToArray$8(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; }
5467 var string = function string(editor, at) {
5468 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5469 var _options$voids = options.voids,
5470 voids = _options$voids === void 0 ? false : _options$voids;
5471 var range = Editor.range(editor, at);
5472 var _Range$edges = Range.edges(range),
5473 _Range$edges2 = _slicedToArray(_Range$edges, 2),
5474 start = _Range$edges2[0],
5475 end = _Range$edges2[1];
5476 var text = '';
5477 var _iterator = _createForOfIteratorHelper$8(Editor.nodes(editor, {
5478 at: range,
5479 match: Text.isText,
5480 voids: voids
5481 })),
5482 _step;
5483 try {
5484 for (_iterator.s(); !(_step = _iterator.n()).done;) {
5485 var _step$value = _slicedToArray(_step.value, 2),
5486 node = _step$value[0],
5487 path = _step$value[1];
5488 var t = node.text;
5489 if (Path.equals(path, end.path)) {
5490 t = t.slice(0, end.offset);
5491 }
5492 if (Path.equals(path, start.path)) {
5493 t = t.slice(start.offset);
5494 }
5495 text += t;
5496 }
5497 } catch (err) {
5498 _iterator.e(err);
5499 } finally {
5500 _iterator.f();
5501 }
5502 return text;
5503 };
5504
5505 function _createForOfIteratorHelper$7(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$7(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; } } }; }
5506 function _unsupportedIterableToArray$7(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$7(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$7(o, minLen); }
5507 function _arrayLikeToArray$7(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; }
5508 var unhangRange = function unhangRange(editor, range) {
5509 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5510 var _options$voids = options.voids,
5511 voids = _options$voids === void 0 ? false : _options$voids;
5512 var _Range$edges = Range.edges(range),
5513 _Range$edges2 = _slicedToArray(_Range$edges, 2),
5514 start = _Range$edges2[0],
5515 end = _Range$edges2[1];
5516 // PERF: exit early if we can guarantee that the range isn't hanging.
5517 if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range) || Path.hasPrevious(end.path)) {
5518 return range;
5519 }
5520 var endBlock = Editor.above(editor, {
5521 at: end,
5522 match: function match(n) {
5523 return Element.isElement(n) && Editor.isBlock(editor, n);
5524 },
5525 voids: voids
5526 });
5527 var blockPath = endBlock ? endBlock[1] : [];
5528 var first = Editor.start(editor, start);
5529 var before = {
5530 anchor: first,
5531 focus: end
5532 };
5533 var skip = true;
5534 var _iterator = _createForOfIteratorHelper$7(Editor.nodes(editor, {
5535 at: before,
5536 match: Text.isText,
5537 reverse: true,
5538 voids: voids
5539 })),
5540 _step;
5541 try {
5542 for (_iterator.s(); !(_step = _iterator.n()).done;) {
5543 var _step$value = _slicedToArray(_step.value, 2),
5544 node = _step$value[0],
5545 path = _step$value[1];
5546 if (skip) {
5547 skip = false;
5548 continue;
5549 }
5550 if (node.text !== '' || Path.isBefore(path, blockPath)) {
5551 end = {
5552 path: path,
5553 offset: node.text.length
5554 };
5555 break;
5556 }
5557 }
5558 } catch (err) {
5559 _iterator.e(err);
5560 } finally {
5561 _iterator.f();
5562 }
5563 return {
5564 anchor: start,
5565 focus: end
5566 };
5567 };
5568
5569 var withoutNormalizing = function withoutNormalizing(editor, fn) {
5570 var value = Editor.isNormalizing(editor);
5571 Editor.setNormalizing(editor, false);
5572 try {
5573 fn();
5574 } finally {
5575 Editor.setNormalizing(editor, value);
5576 }
5577 Editor.normalize(editor);
5578 };
5579
5580 var shouldMergeNodesRemovePrevNode = function shouldMergeNodesRemovePrevNode(editor, _ref, _ref2) {
5581 var _ref3 = _slicedToArray(_ref, 2),
5582 prevNode = _ref3[0],
5583 prevPath = _ref3[1];
5584 var _ref4 = _slicedToArray(_ref2, 2);
5585 _ref4[0];
5586 _ref4[1];
5587 // If the target node that we're merging with is empty, remove it instead
5588 // of merging the two. This is a common rich text editor behavior to
5589 // prevent losing formatting when deleting entire nodes when you have a
5590 // hanging selection.
5591 // if prevNode is first child in parent,don't remove it.
5592 return Element.isElement(prevNode) && Editor.isEmpty(editor, prevNode) || Text.isText(prevNode) && prevNode.text === '' && prevPath[prevPath.length - 1] !== 0;
5593 };
5594
5595 function _createForOfIteratorHelper$6(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$6(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; } } }; }
5596 function _unsupportedIterableToArray$6(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$6(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$6(o, minLen); }
5597 function _arrayLikeToArray$6(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; }
5598 var deleteText = function deleteText(editor) {
5599 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5600 Editor.withoutNormalizing(editor, function () {
5601 var _Editor$void, _Editor$void2;
5602 var _options$reverse = options.reverse,
5603 reverse = _options$reverse === void 0 ? false : _options$reverse,
5604 _options$unit = options.unit,
5605 unit = _options$unit === void 0 ? 'character' : _options$unit,
5606 _options$distance = options.distance,
5607 distance = _options$distance === void 0 ? 1 : _options$distance,
5608 _options$voids = options.voids,
5609 voids = _options$voids === void 0 ? false : _options$voids;
5610 var _options$at = options.at,
5611 at = _options$at === void 0 ? editor.selection : _options$at,
5612 _options$hanging = options.hanging,
5613 hanging = _options$hanging === void 0 ? false : _options$hanging;
5614 if (!at) {
5615 return;
5616 }
5617 var isCollapsed = false;
5618 if (Range.isRange(at) && Range.isCollapsed(at)) {
5619 isCollapsed = true;
5620 at = at.anchor;
5621 }
5622 if (Point.isPoint(at)) {
5623 var furthestVoid = Editor["void"](editor, {
5624 at: at,
5625 mode: 'highest'
5626 });
5627 if (!voids && furthestVoid) {
5628 var _furthestVoid = _slicedToArray(furthestVoid, 2),
5629 voidPath = _furthestVoid[1];
5630 at = voidPath;
5631 } else {
5632 var opts = {
5633 unit: unit,
5634 distance: distance
5635 };
5636 var target = reverse ? Editor.before(editor, at, opts) || Editor.start(editor, []) : Editor.after(editor, at, opts) || Editor.end(editor, []);
5637 at = {
5638 anchor: at,
5639 focus: target
5640 };
5641 hanging = true;
5642 }
5643 }
5644 if (Path.isPath(at)) {
5645 Transforms.removeNodes(editor, {
5646 at: at,
5647 voids: voids
5648 });
5649 return;
5650 }
5651 if (Range.isCollapsed(at)) {
5652 return;
5653 }
5654 if (!hanging) {
5655 var _Range$edges = Range.edges(at),
5656 _Range$edges2 = _slicedToArray(_Range$edges, 2),
5657 _end = _Range$edges2[1];
5658 var endOfDoc = Editor.end(editor, []);
5659 if (!Point.equals(_end, endOfDoc)) {
5660 at = Editor.unhangRange(editor, at, {
5661 voids: voids
5662 });
5663 }
5664 }
5665 var _Range$edges3 = Range.edges(at),
5666 _Range$edges4 = _slicedToArray(_Range$edges3, 2),
5667 start = _Range$edges4[0],
5668 end = _Range$edges4[1];
5669 var startBlock = Editor.above(editor, {
5670 match: function match(n) {
5671 return Element.isElement(n) && Editor.isBlock(editor, n);
5672 },
5673 at: start,
5674 voids: voids
5675 });
5676 var endBlock = Editor.above(editor, {
5677 match: function match(n) {
5678 return Element.isElement(n) && Editor.isBlock(editor, n);
5679 },
5680 at: end,
5681 voids: voids
5682 });
5683 var isAcrossBlocks = startBlock && endBlock && !Path.equals(startBlock[1], endBlock[1]);
5684 var isSingleText = Path.equals(start.path, end.path);
5685 var startNonEditable = voids ? null : (_Editor$void = Editor["void"](editor, {
5686 at: start,
5687 mode: 'highest'
5688 })) !== null && _Editor$void !== void 0 ? _Editor$void : Editor.elementReadOnly(editor, {
5689 at: start,
5690 mode: 'highest'
5691 });
5692 var endNonEditable = voids ? null : (_Editor$void2 = Editor["void"](editor, {
5693 at: end,
5694 mode: 'highest'
5695 })) !== null && _Editor$void2 !== void 0 ? _Editor$void2 : Editor.elementReadOnly(editor, {
5696 at: end,
5697 mode: 'highest'
5698 });
5699 // If the start or end points are inside an inline void, nudge them out.
5700 if (startNonEditable) {
5701 var before = Editor.before(editor, start);
5702 if (before && startBlock && Path.isAncestor(startBlock[1], before.path)) {
5703 start = before;
5704 }
5705 }
5706 if (endNonEditable) {
5707 var after = Editor.after(editor, end);
5708 if (after && endBlock && Path.isAncestor(endBlock[1], after.path)) {
5709 end = after;
5710 }
5711 }
5712 // Get the highest nodes that are completely inside the range, as well as
5713 // the start and end nodes.
5714 var matches = [];
5715 var lastPath;
5716 var _iterator = _createForOfIteratorHelper$6(Editor.nodes(editor, {
5717 at: at,
5718 voids: voids
5719 })),
5720 _step;
5721 try {
5722 for (_iterator.s(); !(_step = _iterator.n()).done;) {
5723 var entry = _step.value;
5724 var _entry = _slicedToArray(entry, 2),
5725 _node2 = _entry[0],
5726 _path2 = _entry[1];
5727 if (lastPath && Path.compare(_path2, lastPath) === 0) {
5728 continue;
5729 }
5730 if (!voids && Element.isElement(_node2) && (Editor.isVoid(editor, _node2) || Editor.isElementReadOnly(editor, _node2)) || !Path.isCommon(_path2, start.path) && !Path.isCommon(_path2, end.path)) {
5731 matches.push(entry);
5732 lastPath = _path2;
5733 }
5734 }
5735 } catch (err) {
5736 _iterator.e(err);
5737 } finally {
5738 _iterator.f();
5739 }
5740 var pathRefs = Array.from(matches, function (_ref) {
5741 var _ref2 = _slicedToArray(_ref, 2),
5742 p = _ref2[1];
5743 return Editor.pathRef(editor, p);
5744 });
5745 var startRef = Editor.pointRef(editor, start);
5746 var endRef = Editor.pointRef(editor, end);
5747 var removedText = '';
5748 if (!isSingleText && !startNonEditable) {
5749 var _point = startRef.current;
5750 var _Editor$leaf = Editor.leaf(editor, _point),
5751 _Editor$leaf2 = _slicedToArray(_Editor$leaf, 1),
5752 node = _Editor$leaf2[0];
5753 var path = _point.path;
5754 var _start = start,
5755 offset = _start.offset;
5756 var text = node.text.slice(offset);
5757 if (text.length > 0) {
5758 editor.apply({
5759 type: 'remove_text',
5760 path: path,
5761 offset: offset,
5762 text: text
5763 });
5764 removedText = text;
5765 }
5766 }
5767 pathRefs.reverse().map(function (r) {
5768 return r.unref();
5769 }).filter(function (r) {
5770 return r !== null;
5771 }).forEach(function (p) {
5772 return Transforms.removeNodes(editor, {
5773 at: p,
5774 voids: voids
5775 });
5776 });
5777 if (!endNonEditable) {
5778 var _point2 = endRef.current;
5779 var _Editor$leaf3 = Editor.leaf(editor, _point2),
5780 _Editor$leaf4 = _slicedToArray(_Editor$leaf3, 1),
5781 _node = _Editor$leaf4[0];
5782 var _path = _point2.path;
5783 var _offset = isSingleText ? start.offset : 0;
5784 var _text = _node.text.slice(_offset, end.offset);
5785 if (_text.length > 0) {
5786 editor.apply({
5787 type: 'remove_text',
5788 path: _path,
5789 offset: _offset,
5790 text: _text
5791 });
5792 removedText = _text;
5793 }
5794 }
5795 if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
5796 Transforms.mergeNodes(editor, {
5797 at: endRef.current,
5798 hanging: true,
5799 voids: voids
5800 });
5801 }
5802 // For Thai script, deleting N character(s) backward should delete
5803 // N code point(s) instead of an entire grapheme cluster.
5804 // Therefore, the remaining code points should be inserted back.
5805 if (isCollapsed && reverse && unit === 'character' && removedText.length > 1 && removedText.match(/[\u0E00-\u0E7F]+/)) {
5806 Transforms.insertText(editor, removedText.slice(0, removedText.length - distance));
5807 }
5808 var startUnref = startRef.unref();
5809 var endUnref = endRef.unref();
5810 var point = reverse ? startUnref || endUnref : endUnref || startUnref;
5811 if (options.at == null && point) {
5812 Transforms.select(editor, point);
5813 }
5814 });
5815 };
5816
5817 function _createForOfIteratorHelper$5(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$5(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; } } }; }
5818 function _unsupportedIterableToArray$5(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$5(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$5(o, minLen); }
5819 function _arrayLikeToArray$5(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; }
5820 var insertFragment = function insertFragment(editor, fragment) {
5821 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5822 Editor.withoutNormalizing(editor, function () {
5823 var _options$hanging = options.hanging,
5824 hanging = _options$hanging === void 0 ? false : _options$hanging,
5825 _options$voids = options.voids,
5826 voids = _options$voids === void 0 ? false : _options$voids;
5827 var _options$at = options.at,
5828 at = _options$at === void 0 ? getDefaultInsertLocation(editor) : _options$at,
5829 _options$batchDirty = options.batchDirty,
5830 batchDirty = _options$batchDirty === void 0 ? true : _options$batchDirty;
5831 if (!fragment.length) {
5832 return;
5833 }
5834 if (Range.isRange(at)) {
5835 if (!hanging) {
5836 at = Editor.unhangRange(editor, at, {
5837 voids: voids
5838 });
5839 }
5840 if (Range.isCollapsed(at)) {
5841 at = at.anchor;
5842 } else {
5843 var _Range$edges = Range.edges(at),
5844 _Range$edges2 = _slicedToArray(_Range$edges, 2),
5845 end = _Range$edges2[1];
5846 if (!voids && Editor["void"](editor, {
5847 at: end
5848 })) {
5849 return;
5850 }
5851 var pointRef = Editor.pointRef(editor, end);
5852 Transforms["delete"](editor, {
5853 at: at
5854 });
5855 at = pointRef.unref();
5856 }
5857 } else if (Path.isPath(at)) {
5858 at = Editor.start(editor, at);
5859 }
5860 if (!voids && Editor["void"](editor, {
5861 at: at
5862 })) {
5863 return;
5864 }
5865 // If the insert point is at the edge of an inline node, move it outside
5866 // instead since it will need to be split otherwise.
5867 var inlineElementMatch = Editor.above(editor, {
5868 at: at,
5869 match: function match(n) {
5870 return Element.isElement(n) && Editor.isInline(editor, n);
5871 },
5872 mode: 'highest',
5873 voids: voids
5874 });
5875 if (inlineElementMatch) {
5876 var _inlineElementMatch = _slicedToArray(inlineElementMatch, 2),
5877 _inlinePath = _inlineElementMatch[1];
5878 if (Editor.isEnd(editor, at, _inlinePath)) {
5879 var after = Editor.after(editor, _inlinePath);
5880 at = after;
5881 } else if (Editor.isStart(editor, at, _inlinePath)) {
5882 var before = Editor.before(editor, _inlinePath);
5883 at = before;
5884 }
5885 }
5886 var blockMatch = Editor.above(editor, {
5887 match: function match(n) {
5888 return Element.isElement(n) && Editor.isBlock(editor, n);
5889 },
5890 at: at,
5891 voids: voids
5892 });
5893 var _blockMatch = _slicedToArray(blockMatch, 2),
5894 blockPath = _blockMatch[1];
5895 var isBlockStart = Editor.isStart(editor, at, blockPath);
5896 var isBlockEnd = Editor.isEnd(editor, at, blockPath);
5897 var isBlockEmpty = isBlockStart && isBlockEnd;
5898 var mergeStart = !isBlockStart || isBlockStart && isBlockEnd;
5899 var mergeEnd = !isBlockEnd;
5900 var _Node$first = Node.first({
5901 children: fragment
5902 }, []),
5903 _Node$first2 = _slicedToArray(_Node$first, 2),
5904 firstPath = _Node$first2[1];
5905 var _Node$last = Node.last({
5906 children: fragment
5907 }, []),
5908 _Node$last2 = _slicedToArray(_Node$last, 2),
5909 lastPath = _Node$last2[1];
5910 var matches = [];
5911 var matcher = function matcher(_ref) {
5912 var _ref2 = _slicedToArray(_ref, 2),
5913 n = _ref2[0],
5914 p = _ref2[1];
5915 var isRoot = p.length === 0;
5916 if (isRoot) {
5917 return false;
5918 }
5919 if (isBlockEmpty) {
5920 return true;
5921 }
5922 if (mergeStart && Path.isAncestor(p, firstPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
5923 return false;
5924 }
5925 if (mergeEnd && Path.isAncestor(p, lastPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
5926 return false;
5927 }
5928 return true;
5929 };
5930 var _iterator = _createForOfIteratorHelper$5(Node.nodes({
5931 children: fragment
5932 }, {
5933 pass: matcher
5934 })),
5935 _step;
5936 try {
5937 for (_iterator.s(); !(_step = _iterator.n()).done;) {
5938 var entry = _step.value;
5939 if (matcher(entry)) {
5940 matches.push(entry);
5941 }
5942 }
5943 } catch (err) {
5944 _iterator.e(err);
5945 } finally {
5946 _iterator.f();
5947 }
5948 var starts = [];
5949 var middles = [];
5950 var ends = [];
5951 var starting = true;
5952 var hasBlocks = false;
5953 for (var _i = 0, _matches = matches; _i < _matches.length; _i++) {
5954 var _matches$_i = _slicedToArray(_matches[_i], 1),
5955 node = _matches$_i[0];
5956 if (Element.isElement(node) && !editor.isInline(node)) {
5957 starting = false;
5958 hasBlocks = true;
5959 middles.push(node);
5960 } else if (starting) {
5961 starts.push(node);
5962 } else {
5963 ends.push(node);
5964 }
5965 }
5966 var _Editor$nodes = Editor.nodes(editor, {
5967 at: at,
5968 match: function match(n) {
5969 return Text.isText(n) || Editor.isInline(editor, n);
5970 },
5971 mode: 'highest',
5972 voids: voids
5973 }),
5974 _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
5975 inlineMatch = _Editor$nodes2[0];
5976 var _inlineMatch = _slicedToArray(inlineMatch, 2),
5977 inlinePath = _inlineMatch[1];
5978 var isInlineStart = Editor.isStart(editor, at, inlinePath);
5979 var isInlineEnd = Editor.isEnd(editor, at, inlinePath);
5980 var middleRef = Editor.pathRef(editor, isBlockEnd && !ends.length ? Path.next(blockPath) : blockPath);
5981 var endRef = Editor.pathRef(editor, isInlineEnd ? Path.next(inlinePath) : inlinePath);
5982 Transforms.splitNodes(editor, {
5983 at: at,
5984 match: function match(n) {
5985 return hasBlocks ? Element.isElement(n) && Editor.isBlock(editor, n) : Text.isText(n) || Editor.isInline(editor, n);
5986 },
5987 mode: hasBlocks ? 'lowest' : 'highest',
5988 always: hasBlocks && (!isBlockStart || starts.length > 0) && (!isBlockEnd || ends.length > 0),
5989 voids: voids
5990 });
5991 var startRef = Editor.pathRef(editor, !isInlineStart || isInlineStart && isInlineEnd ? Path.next(inlinePath) : inlinePath);
5992 Transforms.insertNodes(editor, starts, {
5993 at: startRef.current,
5994 match: function match(n) {
5995 return Text.isText(n) || Editor.isInline(editor, n);
5996 },
5997 mode: 'highest',
5998 voids: voids,
5999 batchDirty: batchDirty
6000 });
6001 if (isBlockEmpty && !starts.length && middles.length && !ends.length) {
6002 Transforms["delete"](editor, {
6003 at: blockPath,
6004 voids: voids
6005 });
6006 }
6007 Transforms.insertNodes(editor, middles, {
6008 at: middleRef.current,
6009 match: function match(n) {
6010 return Element.isElement(n) && Editor.isBlock(editor, n);
6011 },
6012 mode: 'lowest',
6013 voids: voids,
6014 batchDirty: batchDirty
6015 });
6016 Transforms.insertNodes(editor, ends, {
6017 at: endRef.current,
6018 match: function match(n) {
6019 return Text.isText(n) || Editor.isInline(editor, n);
6020 },
6021 mode: 'highest',
6022 voids: voids,
6023 batchDirty: batchDirty
6024 });
6025 if (!options.at) {
6026 var path;
6027 if (ends.length > 0 && endRef.current) {
6028 path = Path.previous(endRef.current);
6029 } else if (middles.length > 0 && middleRef.current) {
6030 path = Path.previous(middleRef.current);
6031 } else if (startRef.current) {
6032 path = Path.previous(startRef.current);
6033 }
6034 if (path) {
6035 var _end = Editor.end(editor, path);
6036 Transforms.select(editor, _end);
6037 }
6038 }
6039 startRef.unref();
6040 middleRef.unref();
6041 endRef.unref();
6042 });
6043 };
6044
6045 var collapse = function collapse(editor) {
6046 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6047 var _options$edge = options.edge,
6048 edge = _options$edge === void 0 ? 'anchor' : _options$edge;
6049 var selection = editor.selection;
6050 if (!selection) {
6051 return;
6052 } else if (edge === 'anchor') {
6053 Transforms.select(editor, selection.anchor);
6054 } else if (edge === 'focus') {
6055 Transforms.select(editor, selection.focus);
6056 } else if (edge === 'start') {
6057 var _Range$edges = Range.edges(selection),
6058 _Range$edges2 = _slicedToArray(_Range$edges, 1),
6059 start = _Range$edges2[0];
6060 Transforms.select(editor, start);
6061 } else if (edge === 'end') {
6062 var _Range$edges3 = Range.edges(selection),
6063 _Range$edges4 = _slicedToArray(_Range$edges3, 2),
6064 end = _Range$edges4[1];
6065 Transforms.select(editor, end);
6066 }
6067 };
6068
6069 var deselect = function deselect(editor) {
6070 var selection = editor.selection;
6071 if (selection) {
6072 editor.apply({
6073 type: 'set_selection',
6074 properties: selection,
6075 newProperties: null
6076 });
6077 }
6078 };
6079
6080 var move = function move(editor) {
6081 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6082 var selection = editor.selection;
6083 var _options$distance = options.distance,
6084 distance = _options$distance === void 0 ? 1 : _options$distance,
6085 _options$unit = options.unit,
6086 unit = _options$unit === void 0 ? 'character' : _options$unit,
6087 _options$reverse = options.reverse,
6088 reverse = _options$reverse === void 0 ? false : _options$reverse;
6089 var _options$edge = options.edge,
6090 edge = _options$edge === void 0 ? null : _options$edge;
6091 if (!selection) {
6092 return;
6093 }
6094 if (edge === 'start') {
6095 edge = Range.isBackward(selection) ? 'focus' : 'anchor';
6096 }
6097 if (edge === 'end') {
6098 edge = Range.isBackward(selection) ? 'anchor' : 'focus';
6099 }
6100 var anchor = selection.anchor,
6101 focus = selection.focus;
6102 var opts = {
6103 distance: distance,
6104 unit: unit,
6105 ignoreNonSelectable: true
6106 };
6107 var props = {};
6108 if (edge == null || edge === 'anchor') {
6109 var point = reverse ? Editor.before(editor, anchor, opts) : Editor.after(editor, anchor, opts);
6110 if (point) {
6111 props.anchor = point;
6112 }
6113 }
6114 if (edge == null || edge === 'focus') {
6115 var _point = reverse ? Editor.before(editor, focus, opts) : Editor.after(editor, focus, opts);
6116 if (_point) {
6117 props.focus = _point;
6118 }
6119 }
6120 Transforms.setSelection(editor, props);
6121 };
6122
6123 var select = function select(editor, target) {
6124 var selection = editor.selection;
6125 target = Editor.range(editor, target);
6126 if (selection) {
6127 Transforms.setSelection(editor, target);
6128 return;
6129 }
6130 if (!Range.isRange(target)) {
6131 throw new Error("When setting the selection and the current selection is `null` you must provide at least an `anchor` and `focus`, but you passed: ".concat(Scrubber.stringify(target)));
6132 }
6133 editor.apply({
6134 type: 'set_selection',
6135 properties: selection,
6136 newProperties: target
6137 });
6138 };
6139
6140 function ownKeys$1(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; }
6141 function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6142 var setPoint = function setPoint(editor, props) {
6143 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6144 var selection = editor.selection;
6145 var _options$edge = options.edge,
6146 edge = _options$edge === void 0 ? 'both' : _options$edge;
6147 if (!selection) {
6148 return;
6149 }
6150 if (edge === 'start') {
6151 edge = Range.isBackward(selection) ? 'focus' : 'anchor';
6152 }
6153 if (edge === 'end') {
6154 edge = Range.isBackward(selection) ? 'anchor' : 'focus';
6155 }
6156 var anchor = selection.anchor,
6157 focus = selection.focus;
6158 var point = edge === 'anchor' ? anchor : focus;
6159 Transforms.setSelection(editor, _defineProperty({}, edge === 'anchor' ? 'anchor' : 'focus', _objectSpread$1(_objectSpread$1({}, point), props)));
6160 };
6161
6162 var setSelection = function setSelection(editor, props) {
6163 var selection = editor.selection;
6164 var oldProps = {};
6165 var newProps = {};
6166 if (!selection) {
6167 return;
6168 }
6169 for (var k in props) {
6170 if (k === 'anchor' && props.anchor != null && !Point.equals(props.anchor, selection.anchor) || k === 'focus' && props.focus != null && !Point.equals(props.focus, selection.focus) || k !== 'anchor' && k !== 'focus' && props[k] !== selection[k]) {
6171 oldProps[k] = selection[k];
6172 newProps[k] = props[k];
6173 }
6174 }
6175 if (Object.keys(oldProps).length > 0) {
6176 editor.apply({
6177 type: 'set_selection',
6178 properties: oldProps,
6179 newProperties: newProps
6180 });
6181 }
6182 };
6183
6184 function _createForOfIteratorHelper$4(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$4(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; } } }; }
6185 function _unsupportedIterableToArray$4(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$4(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$4(o, minLen); }
6186 function _arrayLikeToArray$4(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; }
6187 var insertNodes = function insertNodes(editor, nodes) {
6188 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6189 Editor.withoutNormalizing(editor, function () {
6190 var _options$hanging = options.hanging,
6191 hanging = _options$hanging === void 0 ? false : _options$hanging,
6192 _options$voids = options.voids,
6193 voids = _options$voids === void 0 ? false : _options$voids,
6194 _options$mode = options.mode,
6195 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
6196 _options$batchDirty = options.batchDirty,
6197 batchDirty = _options$batchDirty === void 0 ? true : _options$batchDirty;
6198 var at = options.at,
6199 match = options.match,
6200 select = options.select;
6201 if (Node.isNode(nodes)) {
6202 nodes = [nodes];
6203 }
6204 if (nodes.length === 0) {
6205 return;
6206 }
6207 var _nodes = nodes,
6208 _nodes2 = _slicedToArray(_nodes, 1),
6209 node = _nodes2[0];
6210 if (!at) {
6211 at = getDefaultInsertLocation(editor);
6212 if (select !== false) {
6213 select = true;
6214 }
6215 }
6216 if (select == null) {
6217 select = false;
6218 }
6219 if (Range.isRange(at)) {
6220 if (!hanging) {
6221 at = Editor.unhangRange(editor, at, {
6222 voids: voids
6223 });
6224 }
6225 if (Range.isCollapsed(at)) {
6226 at = at.anchor;
6227 } else {
6228 var _Range$edges = Range.edges(at),
6229 _Range$edges2 = _slicedToArray(_Range$edges, 2),
6230 end = _Range$edges2[1];
6231 var pointRef = Editor.pointRef(editor, end);
6232 Transforms["delete"](editor, {
6233 at: at
6234 });
6235 at = pointRef.unref();
6236 }
6237 }
6238 if (Point.isPoint(at)) {
6239 if (match == null) {
6240 if (Text.isText(node)) {
6241 match = function match(n) {
6242 return Text.isText(n);
6243 };
6244 } else if (editor.isInline(node)) {
6245 match = function match(n) {
6246 return Text.isText(n) || Editor.isInline(editor, n);
6247 };
6248 } else {
6249 match = function match(n) {
6250 return Element.isElement(n) && Editor.isBlock(editor, n);
6251 };
6252 }
6253 }
6254 var _Editor$nodes = Editor.nodes(editor, {
6255 at: at.path,
6256 match: match,
6257 mode: mode,
6258 voids: voids
6259 }),
6260 _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
6261 entry = _Editor$nodes2[0];
6262 if (entry) {
6263 var _entry = _slicedToArray(entry, 2),
6264 matchPath = _entry[1];
6265 var pathRef = Editor.pathRef(editor, matchPath);
6266 var isAtEnd = Editor.isEnd(editor, at, matchPath);
6267 Transforms.splitNodes(editor, {
6268 at: at,
6269 match: match,
6270 mode: mode,
6271 voids: voids
6272 });
6273 var path = pathRef.unref();
6274 at = isAtEnd ? Path.next(path) : path;
6275 } else {
6276 return;
6277 }
6278 }
6279 var parentPath = Path.parent(at);
6280 var index = at[at.length - 1];
6281 if (!voids && Editor["void"](editor, {
6282 at: parentPath
6283 })) {
6284 return;
6285 }
6286 if (batchDirty) {
6287 // PERF: batch update dirty paths
6288 // batched ops used to transform existing dirty paths
6289 var batchedOps = [];
6290 var newDirtyPaths = Path.levels(parentPath);
6291 batchDirtyPaths(editor, function () {
6292 var _iterator = _createForOfIteratorHelper$4(nodes),
6293 _step;
6294 try {
6295 var _loop = function _loop() {
6296 var node = _step.value;
6297 var path = parentPath.concat(index);
6298 index++;
6299 var op = {
6300 type: 'insert_node',
6301 path: path,
6302 node: node
6303 };
6304 editor.apply(op);
6305 at = Path.next(at);
6306 batchedOps.push(op);
6307 if (!Text.isText) {
6308 newDirtyPaths.push(path);
6309 } else {
6310 newDirtyPaths.push.apply(newDirtyPaths, _toConsumableArray(Array.from(Node.nodes(node), function (_ref) {
6311 var _ref2 = _slicedToArray(_ref, 2),
6312 p = _ref2[1];
6313 return path.concat(p);
6314 })));
6315 }
6316 };
6317 for (_iterator.s(); !(_step = _iterator.n()).done;) {
6318 _loop();
6319 }
6320 } catch (err) {
6321 _iterator.e(err);
6322 } finally {
6323 _iterator.f();
6324 }
6325 }, function () {
6326 updateDirtyPaths(editor, newDirtyPaths, function (p) {
6327 var newPath = p;
6328 for (var _i = 0, _batchedOps = batchedOps; _i < _batchedOps.length; _i++) {
6329 var op = _batchedOps[_i];
6330 if (Path.operationCanTransformPath(op)) {
6331 newPath = Path.transform(newPath, op);
6332 if (!newPath) {
6333 return null;
6334 }
6335 }
6336 }
6337 return newPath;
6338 });
6339 });
6340 } else {
6341 var _iterator2 = _createForOfIteratorHelper$4(nodes),
6342 _step2;
6343 try {
6344 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6345 var _node = _step2.value;
6346 var _path = parentPath.concat(index);
6347 index++;
6348 editor.apply({
6349 type: 'insert_node',
6350 path: _path,
6351 node: _node
6352 });
6353 at = Path.next(at);
6354 }
6355 } catch (err) {
6356 _iterator2.e(err);
6357 } finally {
6358 _iterator2.f();
6359 }
6360 }
6361 at = Path.previous(at);
6362 if (select) {
6363 var point = Editor.end(editor, at);
6364 if (point) {
6365 Transforms.select(editor, point);
6366 }
6367 }
6368 });
6369 };
6370
6371 var liftNodes = function liftNodes(editor) {
6372 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6373 Editor.withoutNormalizing(editor, function () {
6374 var _options$at = options.at,
6375 at = _options$at === void 0 ? editor.selection : _options$at,
6376 _options$mode = options.mode,
6377 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
6378 _options$voids = options.voids,
6379 voids = _options$voids === void 0 ? false : _options$voids;
6380 var match = options.match;
6381 if (match == null) {
6382 match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
6383 return Element.isElement(n) && Editor.isBlock(editor, n);
6384 };
6385 }
6386 if (!at) {
6387 return;
6388 }
6389 var matches = Editor.nodes(editor, {
6390 at: at,
6391 match: match,
6392 mode: mode,
6393 voids: voids
6394 });
6395 var pathRefs = Array.from(matches, function (_ref) {
6396 var _ref2 = _slicedToArray(_ref, 2),
6397 p = _ref2[1];
6398 return Editor.pathRef(editor, p);
6399 });
6400 for (var _i = 0, _pathRefs = pathRefs; _i < _pathRefs.length; _i++) {
6401 var pathRef = _pathRefs[_i];
6402 var path = pathRef.unref();
6403 if (path.length < 2) {
6404 throw new Error("Cannot lift node at a path [".concat(path, "] because it has a depth of less than `2`."));
6405 }
6406 var parentNodeEntry = Editor.node(editor, Path.parent(path));
6407 var _parentNodeEntry = _slicedToArray(parentNodeEntry, 2),
6408 parent = _parentNodeEntry[0],
6409 parentPath = _parentNodeEntry[1];
6410 var index = path[path.length - 1];
6411 var length = parent.children.length;
6412 if (length === 1) {
6413 var toPath = Path.next(parentPath);
6414 Transforms.moveNodes(editor, {
6415 at: path,
6416 to: toPath,
6417 voids: voids
6418 });
6419 Transforms.removeNodes(editor, {
6420 at: parentPath,
6421 voids: voids
6422 });
6423 } else if (index === 0) {
6424 Transforms.moveNodes(editor, {
6425 at: path,
6426 to: parentPath,
6427 voids: voids
6428 });
6429 } else if (index === length - 1) {
6430 var _toPath = Path.next(parentPath);
6431 Transforms.moveNodes(editor, {
6432 at: path,
6433 to: _toPath,
6434 voids: voids
6435 });
6436 } else {
6437 var splitPath = Path.next(path);
6438 var _toPath2 = Path.next(parentPath);
6439 Transforms.splitNodes(editor, {
6440 at: splitPath,
6441 voids: voids
6442 });
6443 Transforms.moveNodes(editor, {
6444 at: path,
6445 to: _toPath2,
6446 voids: voids
6447 });
6448 }
6449 }
6450 });
6451 };
6452
6453 var _excluded = ["text"],
6454 _excluded2 = ["children"];
6455 var hasSingleChildNest = function hasSingleChildNest(editor, node) {
6456 if (Element.isElement(node)) {
6457 var element = node;
6458 if (Editor.isVoid(editor, node)) {
6459 return true;
6460 } else if (element.children.length === 1) {
6461 return hasSingleChildNest(editor, element.children[0]);
6462 } else {
6463 return false;
6464 }
6465 } else if (Editor.isEditor(node)) {
6466 return false;
6467 } else {
6468 return true;
6469 }
6470 };
6471 var mergeNodes = function mergeNodes(editor) {
6472 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6473 Editor.withoutNormalizing(editor, function () {
6474 var match = options.match,
6475 _options$at = options.at,
6476 at = _options$at === void 0 ? editor.selection : _options$at;
6477 var _options$hanging = options.hanging,
6478 hanging = _options$hanging === void 0 ? false : _options$hanging,
6479 _options$voids = options.voids,
6480 voids = _options$voids === void 0 ? false : _options$voids,
6481 _options$mode = options.mode,
6482 mode = _options$mode === void 0 ? 'lowest' : _options$mode;
6483 if (!at) {
6484 return;
6485 }
6486 if (match == null) {
6487 if (Path.isPath(at)) {
6488 var _Editor$parent = Editor.parent(editor, at),
6489 _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
6490 parent = _Editor$parent2[0];
6491 match = function match(n) {
6492 return parent.children.includes(n);
6493 };
6494 } else {
6495 match = function match(n) {
6496 return Element.isElement(n) && Editor.isBlock(editor, n);
6497 };
6498 }
6499 }
6500 if (!hanging && Range.isRange(at)) {
6501 at = Editor.unhangRange(editor, at, {
6502 voids: voids
6503 });
6504 }
6505 if (Range.isRange(at)) {
6506 if (Range.isCollapsed(at)) {
6507 at = at.anchor;
6508 } else {
6509 var _Range$edges = Range.edges(at),
6510 _Range$edges2 = _slicedToArray(_Range$edges, 2),
6511 end = _Range$edges2[1];
6512 var pointRef = Editor.pointRef(editor, end);
6513 Transforms["delete"](editor, {
6514 at: at
6515 });
6516 at = pointRef.unref();
6517 if (options.at == null) {
6518 Transforms.select(editor, at);
6519 }
6520 }
6521 }
6522 var _Editor$nodes = Editor.nodes(editor, {
6523 at: at,
6524 match: match,
6525 voids: voids,
6526 mode: mode
6527 }),
6528 _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
6529 current = _Editor$nodes2[0];
6530 var prev = Editor.previous(editor, {
6531 at: at,
6532 match: match,
6533 voids: voids,
6534 mode: mode
6535 });
6536 if (!current || !prev) {
6537 return;
6538 }
6539 var _current = _slicedToArray(current, 2),
6540 node = _current[0],
6541 path = _current[1];
6542 var _prev = _slicedToArray(prev, 2),
6543 prevNode = _prev[0],
6544 prevPath = _prev[1];
6545 if (path.length === 0 || prevPath.length === 0) {
6546 return;
6547 }
6548 var newPath = Path.next(prevPath);
6549 var commonPath = Path.common(path, prevPath);
6550 var isPreviousSibling = Path.isSibling(path, prevPath);
6551 var levels = Array.from(Editor.levels(editor, {
6552 at: path
6553 }), function (_ref) {
6554 var _ref2 = _slicedToArray(_ref, 1),
6555 n = _ref2[0];
6556 return n;
6557 }).slice(commonPath.length).slice(0, -1);
6558 // Determine if the merge will leave an ancestor of the path empty as a
6559 // result, in which case we'll want to remove it after merging.
6560 var emptyAncestor = Editor.above(editor, {
6561 at: path,
6562 mode: 'highest',
6563 match: function match(n) {
6564 return levels.includes(n) && hasSingleChildNest(editor, n);
6565 }
6566 });
6567 var emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
6568 var properties;
6569 var position;
6570 // Ensure that the nodes are equivalent, and figure out what the position
6571 // and extra properties of the merge will be.
6572 if (Text.isText(node) && Text.isText(prevNode)) {
6573 node.text;
6574 var rest = _objectWithoutProperties(node, _excluded);
6575 position = prevNode.text.length;
6576 properties = rest;
6577 } else if (Element.isElement(node) && Element.isElement(prevNode)) {
6578 node.children;
6579 var _rest = _objectWithoutProperties(node, _excluded2);
6580 position = prevNode.children.length;
6581 properties = _rest;
6582 } else {
6583 throw new Error("Cannot merge the node at path [".concat(path, "] with the previous sibling because it is not the same kind: ").concat(Scrubber.stringify(node), " ").concat(Scrubber.stringify(prevNode)));
6584 }
6585 // If the node isn't already the next sibling of the previous node, move
6586 // it so that it is before merging.
6587 if (!isPreviousSibling) {
6588 Transforms.moveNodes(editor, {
6589 at: path,
6590 to: newPath,
6591 voids: voids
6592 });
6593 }
6594 // If there was going to be an empty ancestor of the node that was merged,
6595 // we remove it from the tree.
6596 if (emptyRef) {
6597 Transforms.removeNodes(editor, {
6598 at: emptyRef.current,
6599 voids: voids
6600 });
6601 }
6602 if (Editor.shouldMergeNodesRemovePrevNode(editor, prev, current)) {
6603 Transforms.removeNodes(editor, {
6604 at: prevPath,
6605 voids: voids
6606 });
6607 } else {
6608 editor.apply({
6609 type: 'merge_node',
6610 path: newPath,
6611 position: position,
6612 properties: properties
6613 });
6614 }
6615 if (emptyRef) {
6616 emptyRef.unref();
6617 }
6618 });
6619 };
6620
6621 var moveNodes = function moveNodes(editor, options) {
6622 Editor.withoutNormalizing(editor, function () {
6623 var to = options.to,
6624 _options$at = options.at,
6625 at = _options$at === void 0 ? editor.selection : _options$at,
6626 _options$mode = options.mode,
6627 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
6628 _options$voids = options.voids,
6629 voids = _options$voids === void 0 ? false : _options$voids;
6630 var match = options.match;
6631 if (!at) {
6632 return;
6633 }
6634 if (match == null) {
6635 match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
6636 return Element.isElement(n) && Editor.isBlock(editor, n);
6637 };
6638 }
6639 var toRef = Editor.pathRef(editor, to);
6640 var targets = Editor.nodes(editor, {
6641 at: at,
6642 match: match,
6643 mode: mode,
6644 voids: voids
6645 });
6646 var pathRefs = Array.from(targets, function (_ref) {
6647 var _ref2 = _slicedToArray(_ref, 2),
6648 p = _ref2[1];
6649 return Editor.pathRef(editor, p);
6650 });
6651 for (var _i = 0, _pathRefs = pathRefs; _i < _pathRefs.length; _i++) {
6652 var pathRef = _pathRefs[_i];
6653 var path = pathRef.unref();
6654 var newPath = toRef.current;
6655 if (path.length !== 0) {
6656 editor.apply({
6657 type: 'move_node',
6658 path: path,
6659 newPath: newPath
6660 });
6661 }
6662 if (toRef.current && Path.isSibling(newPath, path) && Path.isAfter(newPath, path)) {
6663 // When performing a sibling move to a later index, the path at the destination is shifted
6664 // to before the insertion point instead of after. To ensure our group of nodes are inserted
6665 // in the correct order we increment toRef to account for that
6666 toRef.current = Path.next(toRef.current);
6667 }
6668 }
6669 toRef.unref();
6670 });
6671 };
6672
6673 var removeNodes = function removeNodes(editor) {
6674 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6675 Editor.withoutNormalizing(editor, function () {
6676 var _options$hanging = options.hanging,
6677 hanging = _options$hanging === void 0 ? false : _options$hanging,
6678 _options$voids = options.voids,
6679 voids = _options$voids === void 0 ? false : _options$voids,
6680 _options$mode = options.mode,
6681 mode = _options$mode === void 0 ? 'lowest' : _options$mode;
6682 var _options$at = options.at,
6683 at = _options$at === void 0 ? editor.selection : _options$at,
6684 match = options.match;
6685 if (!at) {
6686 return;
6687 }
6688 if (match == null) {
6689 match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
6690 return Element.isElement(n) && Editor.isBlock(editor, n);
6691 };
6692 }
6693 if (!hanging && Range.isRange(at)) {
6694 at = Editor.unhangRange(editor, at, {
6695 voids: voids
6696 });
6697 }
6698 var depths = Editor.nodes(editor, {
6699 at: at,
6700 match: match,
6701 mode: mode,
6702 voids: voids
6703 });
6704 var pathRefs = Array.from(depths, function (_ref) {
6705 var _ref2 = _slicedToArray(_ref, 2),
6706 p = _ref2[1];
6707 return Editor.pathRef(editor, p);
6708 });
6709 for (var _i = 0, _pathRefs = pathRefs; _i < _pathRefs.length; _i++) {
6710 var pathRef = _pathRefs[_i];
6711 var path = pathRef.unref();
6712 if (path) {
6713 var _Editor$node = Editor.node(editor, path),
6714 _Editor$node2 = _slicedToArray(_Editor$node, 1),
6715 node = _Editor$node2[0];
6716 editor.apply({
6717 type: 'remove_node',
6718 path: path,
6719 node: node
6720 });
6721 }
6722 }
6723 });
6724 };
6725
6726 function _createForOfIteratorHelper$3(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$3(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; } } }; }
6727 function _unsupportedIterableToArray$3(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$3(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$3(o, minLen); }
6728 function _arrayLikeToArray$3(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; }
6729 var setNodes = function setNodes(editor, props) {
6730 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6731 Editor.withoutNormalizing(editor, function () {
6732 var match = options.match,
6733 _options$at = options.at,
6734 at = _options$at === void 0 ? editor.selection : _options$at,
6735 compare = options.compare,
6736 merge = options.merge;
6737 var _options$hanging = options.hanging,
6738 hanging = _options$hanging === void 0 ? false : _options$hanging,
6739 _options$mode = options.mode,
6740 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
6741 _options$split = options.split,
6742 split = _options$split === void 0 ? false : _options$split,
6743 _options$voids = options.voids,
6744 voids = _options$voids === void 0 ? false : _options$voids;
6745 if (!at) {
6746 return;
6747 }
6748 if (match == null) {
6749 match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
6750 return Element.isElement(n) && Editor.isBlock(editor, n);
6751 };
6752 }
6753 if (!hanging && Range.isRange(at)) {
6754 at = Editor.unhangRange(editor, at, {
6755 voids: voids
6756 });
6757 }
6758 if (split && Range.isRange(at)) {
6759 if (Range.isCollapsed(at) && Editor.leaf(editor, at.anchor)[0].text.length > 0) {
6760 // If the range is collapsed in a non-empty node and 'split' is true, there's nothing to
6761 // set that won't get normalized away
6762 return;
6763 }
6764 var rangeRef = Editor.rangeRef(editor, at, {
6765 affinity: 'inward'
6766 });
6767 var _Range$edges = Range.edges(at),
6768 _Range$edges2 = _slicedToArray(_Range$edges, 2),
6769 start = _Range$edges2[0],
6770 end = _Range$edges2[1];
6771 var splitMode = mode === 'lowest' ? 'lowest' : 'highest';
6772 var endAtEndOfNode = Editor.isEnd(editor, end, end.path);
6773 Transforms.splitNodes(editor, {
6774 at: end,
6775 match: match,
6776 mode: splitMode,
6777 voids: voids,
6778 always: !endAtEndOfNode
6779 });
6780 var startAtStartOfNode = Editor.isStart(editor, start, start.path);
6781 Transforms.splitNodes(editor, {
6782 at: start,
6783 match: match,
6784 mode: splitMode,
6785 voids: voids,
6786 always: !startAtStartOfNode
6787 });
6788 at = rangeRef.unref();
6789 if (options.at == null) {
6790 Transforms.select(editor, at);
6791 }
6792 }
6793 if (!compare) {
6794 compare = function compare(prop, nodeProp) {
6795 return prop !== nodeProp;
6796 };
6797 }
6798 var _iterator = _createForOfIteratorHelper$3(Editor.nodes(editor, {
6799 at: at,
6800 match: match,
6801 mode: mode,
6802 voids: voids
6803 })),
6804 _step;
6805 try {
6806 for (_iterator.s(); !(_step = _iterator.n()).done;) {
6807 var _step$value = _slicedToArray(_step.value, 2),
6808 node = _step$value[0],
6809 path = _step$value[1];
6810 var properties = {};
6811 // FIXME: is this correct?
6812 var newProperties = {};
6813 // You can't set properties on the editor node.
6814 if (path.length === 0) {
6815 continue;
6816 }
6817 var hasChanges = false;
6818 for (var k in props) {
6819 if (k === 'children' || k === 'text') {
6820 continue;
6821 }
6822 if (compare(props[k], node[k])) {
6823 hasChanges = true;
6824 // Omit new properties from the old properties list
6825 if (node.hasOwnProperty(k)) properties[k] = node[k];
6826 // Omit properties that have been removed from the new properties list
6827 if (merge) {
6828 if (props[k] != null) newProperties[k] = merge(node[k], props[k]);
6829 } else {
6830 if (props[k] != null) newProperties[k] = props[k];
6831 }
6832 }
6833 }
6834 if (hasChanges) {
6835 editor.apply({
6836 type: 'set_node',
6837 path: path,
6838 properties: properties,
6839 newProperties: newProperties
6840 });
6841 }
6842 }
6843 } catch (err) {
6844 _iterator.e(err);
6845 } finally {
6846 _iterator.f();
6847 }
6848 });
6849 };
6850
6851 function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(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; } } }; }
6852 function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(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$2(o, minLen); }
6853 function _arrayLikeToArray$2(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; }
6854 /**
6855 * Convert a range into a point by deleting it's content.
6856 */
6857 var deleteRange = function deleteRange(editor, range) {
6858 if (Range.isCollapsed(range)) {
6859 return range.anchor;
6860 } else {
6861 var _Range$edges = Range.edges(range),
6862 _Range$edges2 = _slicedToArray(_Range$edges, 2),
6863 end = _Range$edges2[1];
6864 var pointRef = Editor.pointRef(editor, end);
6865 Transforms["delete"](editor, {
6866 at: range
6867 });
6868 return pointRef.unref();
6869 }
6870 };
6871 var splitNodes = function splitNodes(editor) {
6872 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6873 Editor.withoutNormalizing(editor, function () {
6874 var _options$mode = options.mode,
6875 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
6876 _options$voids = options.voids,
6877 voids = _options$voids === void 0 ? false : _options$voids;
6878 var match = options.match,
6879 _options$at = options.at,
6880 at = _options$at === void 0 ? editor.selection : _options$at,
6881 _options$height = options.height,
6882 height = _options$height === void 0 ? 0 : _options$height,
6883 _options$always = options.always,
6884 always = _options$always === void 0 ? false : _options$always;
6885 if (match == null) {
6886 match = function match(n) {
6887 return Element.isElement(n) && Editor.isBlock(editor, n);
6888 };
6889 }
6890 if (Range.isRange(at)) {
6891 at = deleteRange(editor, at);
6892 }
6893 // If the target is a path, the default height-skipping and position
6894 // counters need to account for us potentially splitting at a non-leaf.
6895 if (Path.isPath(at)) {
6896 var path = at;
6897 var point = Editor.point(editor, path);
6898 var _Editor$parent = Editor.parent(editor, path),
6899 _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
6900 parent = _Editor$parent2[0];
6901 match = function match(n) {
6902 return n === parent;
6903 };
6904 height = point.path.length - path.length + 1;
6905 at = point;
6906 always = true;
6907 }
6908 if (!at) {
6909 return;
6910 }
6911 var beforeRef = Editor.pointRef(editor, at, {
6912 affinity: 'backward'
6913 });
6914 var afterRef;
6915 try {
6916 var _Editor$nodes = Editor.nodes(editor, {
6917 at: at,
6918 match: match,
6919 mode: mode,
6920 voids: voids
6921 }),
6922 _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
6923 highest = _Editor$nodes2[0];
6924 if (!highest) {
6925 return;
6926 }
6927 var voidMatch = Editor["void"](editor, {
6928 at: at,
6929 mode: 'highest'
6930 });
6931 var nudge = 0;
6932 if (!voids && voidMatch) {
6933 var _voidMatch = _slicedToArray(voidMatch, 2),
6934 voidNode = _voidMatch[0],
6935 voidPath = _voidMatch[1];
6936 if (Element.isElement(voidNode) && editor.isInline(voidNode)) {
6937 var after = Editor.after(editor, voidPath);
6938 if (!after) {
6939 var text = {
6940 text: ''
6941 };
6942 var afterPath = Path.next(voidPath);
6943 Transforms.insertNodes(editor, text, {
6944 at: afterPath,
6945 voids: voids
6946 });
6947 after = Editor.point(editor, afterPath);
6948 }
6949 at = after;
6950 always = true;
6951 }
6952 var siblingHeight = at.path.length - voidPath.length;
6953 height = siblingHeight + 1;
6954 always = true;
6955 }
6956 afterRef = Editor.pointRef(editor, at);
6957 var depth = at.path.length - height;
6958 var _highest = _slicedToArray(highest, 2),
6959 highestPath = _highest[1];
6960 var lowestPath = at.path.slice(0, depth);
6961 var position = height === 0 ? at.offset : at.path[depth] + nudge;
6962 var _iterator = _createForOfIteratorHelper$2(Editor.levels(editor, {
6963 at: lowestPath,
6964 reverse: true,
6965 voids: voids
6966 })),
6967 _step;
6968 try {
6969 for (_iterator.s(); !(_step = _iterator.n()).done;) {
6970 var _step$value = _slicedToArray(_step.value, 2),
6971 node = _step$value[0],
6972 _path = _step$value[1];
6973 var split = false;
6974 if (_path.length < highestPath.length || _path.length === 0 || !voids && Element.isElement(node) && Editor.isVoid(editor, node)) {
6975 break;
6976 }
6977 var _point2 = beforeRef.current;
6978 var isEnd = Editor.isEnd(editor, _point2, _path);
6979 if (always || !beforeRef || !Editor.isEdge(editor, _point2, _path)) {
6980 split = true;
6981 var properties = Node.extractProps(node);
6982 editor.apply({
6983 type: 'split_node',
6984 path: _path,
6985 position: position,
6986 properties: properties
6987 });
6988 }
6989 position = _path[_path.length - 1] + (split || isEnd ? 1 : 0);
6990 }
6991 } catch (err) {
6992 _iterator.e(err);
6993 } finally {
6994 _iterator.f();
6995 }
6996 if (options.at == null) {
6997 var _point = afterRef.current || Editor.end(editor, []);
6998 Transforms.select(editor, _point);
6999 }
7000 } finally {
7001 var _afterRef;
7002 beforeRef.unref();
7003 (_afterRef = afterRef) === null || _afterRef === void 0 || _afterRef.unref();
7004 }
7005 });
7006 };
7007
7008 function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(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; } } }; }
7009 function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(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$1(o, minLen); }
7010 function _arrayLikeToArray$1(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; }
7011 var unsetNodes = function unsetNodes(editor, props) {
7012 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7013 if (!Array.isArray(props)) {
7014 props = [props];
7015 }
7016 var obj = {};
7017 var _iterator = _createForOfIteratorHelper$1(props),
7018 _step;
7019 try {
7020 for (_iterator.s(); !(_step = _iterator.n()).done;) {
7021 var key = _step.value;
7022 obj[key] = null;
7023 }
7024 } catch (err) {
7025 _iterator.e(err);
7026 } finally {
7027 _iterator.f();
7028 }
7029 Transforms.setNodes(editor, obj, options);
7030 };
7031
7032 function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(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; } } }; }
7033 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); }
7034 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; }
7035 var unwrapNodes = function unwrapNodes(editor) {
7036 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7037 Editor.withoutNormalizing(editor, function () {
7038 var _options$mode = options.mode,
7039 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
7040 _options$split = options.split,
7041 split = _options$split === void 0 ? false : _options$split,
7042 _options$voids = options.voids,
7043 voids = _options$voids === void 0 ? false : _options$voids;
7044 var _options$at = options.at,
7045 at = _options$at === void 0 ? editor.selection : _options$at,
7046 match = options.match;
7047 if (!at) {
7048 return;
7049 }
7050 if (match == null) {
7051 match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
7052 return Element.isElement(n) && Editor.isBlock(editor, n);
7053 };
7054 }
7055 if (Path.isPath(at)) {
7056 at = Editor.range(editor, at);
7057 }
7058 var rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null;
7059 var matches = Editor.nodes(editor, {
7060 at: at,
7061 match: match,
7062 mode: mode,
7063 voids: voids
7064 });
7065 var pathRefs = Array.from(matches, function (_ref) {
7066 var _ref2 = _slicedToArray(_ref, 2),
7067 p = _ref2[1];
7068 return Editor.pathRef(editor, p);
7069 }
7070 // unwrapNode will call liftNode which does not support splitting the node when nested.
7071 // If we do not reverse the order and call it from top to the bottom, it will remove all blocks
7072 // that wrap target node. So we reverse the order.
7073 ).reverse();
7074 var _iterator = _createForOfIteratorHelper(pathRefs),
7075 _step;
7076 try {
7077 var _loop = function _loop() {
7078 var pathRef = _step.value;
7079 var path = pathRef.unref();
7080 var _Editor$node = Editor.node(editor, path),
7081 _Editor$node2 = _slicedToArray(_Editor$node, 1),
7082 node = _Editor$node2[0];
7083 var range = Editor.range(editor, path);
7084 if (split && rangeRef) {
7085 range = Range.intersection(rangeRef.current, range);
7086 }
7087 Transforms.liftNodes(editor, {
7088 at: range,
7089 match: function match(n) {
7090 return Element.isAncestor(node) && node.children.includes(n);
7091 },
7092 voids: voids
7093 });
7094 };
7095 for (_iterator.s(); !(_step = _iterator.n()).done;) {
7096 _loop();
7097 }
7098 } catch (err) {
7099 _iterator.e(err);
7100 } finally {
7101 _iterator.f();
7102 }
7103 if (rangeRef) {
7104 rangeRef.unref();
7105 }
7106 });
7107 };
7108
7109 function ownKeys(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; }
7110 function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7111 var wrapNodes = function wrapNodes(editor, element) {
7112 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7113 Editor.withoutNormalizing(editor, function () {
7114 var _options$mode = options.mode,
7115 mode = _options$mode === void 0 ? 'lowest' : _options$mode,
7116 _options$split = options.split,
7117 split = _options$split === void 0 ? false : _options$split,
7118 _options$voids = options.voids,
7119 voids = _options$voids === void 0 ? false : _options$voids;
7120 var match = options.match,
7121 _options$at = options.at,
7122 at = _options$at === void 0 ? editor.selection : _options$at;
7123 if (!at) {
7124 return;
7125 }
7126 if (match == null) {
7127 if (Path.isPath(at)) {
7128 match = matchPath(editor, at);
7129 } else if (editor.isInline(element)) {
7130 match = function match(n) {
7131 return Element.isElement(n) && Editor.isInline(editor, n) || Text.isText(n);
7132 };
7133 } else {
7134 match = function match(n) {
7135 return Element.isElement(n) && Editor.isBlock(editor, n);
7136 };
7137 }
7138 }
7139 if (split && Range.isRange(at)) {
7140 var _Range$edges = Range.edges(at),
7141 _Range$edges2 = _slicedToArray(_Range$edges, 2),
7142 start = _Range$edges2[0],
7143 end = _Range$edges2[1];
7144 var rangeRef = Editor.rangeRef(editor, at, {
7145 affinity: 'inward'
7146 });
7147 Transforms.splitNodes(editor, {
7148 at: end,
7149 match: match,
7150 voids: voids
7151 });
7152 Transforms.splitNodes(editor, {
7153 at: start,
7154 match: match,
7155 voids: voids
7156 });
7157 at = rangeRef.unref();
7158 if (options.at == null) {
7159 Transforms.select(editor, at);
7160 }
7161 }
7162 var roots = Array.from(Editor.nodes(editor, {
7163 at: at,
7164 match: editor.isInline(element) ? function (n) {
7165 return Element.isElement(n) && Editor.isBlock(editor, n);
7166 } : function (n) {
7167 return Editor.isEditor(n);
7168 },
7169 mode: 'lowest',
7170 voids: voids
7171 }));
7172 var _loop = function _loop() {
7173 var _roots$_i = _slicedToArray(_roots[_i], 2),
7174 rootPath = _roots$_i[1];
7175 var a = Range.isRange(at) ? Range.intersection(at, Editor.range(editor, rootPath)) : at;
7176 if (!a) {
7177 return 0; // continue
7178 }
7179 var matches = Array.from(Editor.nodes(editor, {
7180 at: a,
7181 match: match,
7182 mode: mode,
7183 voids: voids
7184 }));
7185 if (matches.length > 0) {
7186 var first = matches[0];
7187 var last = matches[matches.length - 1];
7188 var _first = _slicedToArray(first, 2),
7189 firstPath = _first[1];
7190 var _last = _slicedToArray(last, 2),
7191 lastPath = _last[1];
7192 if (firstPath.length === 0 && lastPath.length === 0) {
7193 // if there's no matching parent - usually means the node is an editor - don't do anything
7194 return 0; // continue
7195 }
7196 var commonPath = Path.equals(firstPath, lastPath) ? Path.parent(firstPath) : Path.common(firstPath, lastPath);
7197 var range = Editor.range(editor, firstPath, lastPath);
7198 var commonNodeEntry = Editor.node(editor, commonPath);
7199 var _commonNodeEntry = _slicedToArray(commonNodeEntry, 1),
7200 commonNode = _commonNodeEntry[0];
7201 var depth = commonPath.length + 1;
7202 var wrapperPath = Path.next(lastPath.slice(0, depth));
7203 var wrapper = _objectSpread(_objectSpread({}, element), {}, {
7204 children: []
7205 });
7206 Transforms.insertNodes(editor, wrapper, {
7207 at: wrapperPath,
7208 voids: voids
7209 });
7210 Transforms.moveNodes(editor, {
7211 at: range,
7212 match: function match(n) {
7213 return Element.isAncestor(commonNode) && commonNode.children.includes(n);
7214 },
7215 to: wrapperPath.concat(0),
7216 voids: voids
7217 });
7218 }
7219 },
7220 _ret;
7221 for (var _i = 0, _roots = roots; _i < _roots.length; _i++) {
7222 _ret = _loop();
7223 if (_ret === 0) continue;
7224 }
7225 });
7226 };
7227
7228 /**
7229 * Create a new Slate `Editor` object.
7230 */
7231 var createEditor = function createEditor() {
7232 var editor = {
7233 children: [],
7234 operations: [],
7235 selection: null,
7236 marks: null,
7237 isElementReadOnly: function isElementReadOnly() {
7238 return false;
7239 },
7240 isInline: function isInline() {
7241 return false;
7242 },
7243 isSelectable: function isSelectable() {
7244 return true;
7245 },
7246 isVoid: function isVoid() {
7247 return false;
7248 },
7249 markableVoid: function markableVoid() {
7250 return false;
7251 },
7252 onChange: function onChange() {},
7253 // Core
7254 apply: function apply$1() {
7255 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7256 args[_key] = arguments[_key];
7257 }
7258 return apply.apply(void 0, [editor].concat(args));
7259 },
7260 // Editor
7261 addMark: function addMark$1() {
7262 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
7263 args[_key2] = arguments[_key2];
7264 }
7265 return addMark.apply(void 0, [editor].concat(args));
7266 },
7267 deleteBackward: function deleteBackward$1() {
7268 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
7269 args[_key3] = arguments[_key3];
7270 }
7271 return deleteBackward.apply(void 0, [editor].concat(args));
7272 },
7273 deleteForward: function deleteForward$1() {
7274 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
7275 args[_key4] = arguments[_key4];
7276 }
7277 return deleteForward.apply(void 0, [editor].concat(args));
7278 },
7279 deleteFragment: function deleteFragment$1() {
7280 for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
7281 args[_key5] = arguments[_key5];
7282 }
7283 return deleteFragment.apply(void 0, [editor].concat(args));
7284 },
7285 getFragment: function getFragment$1() {
7286 for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
7287 args[_key6] = arguments[_key6];
7288 }
7289 return getFragment.apply(void 0, [editor].concat(args));
7290 },
7291 insertBreak: function insertBreak$1() {
7292 for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
7293 args[_key7] = arguments[_key7];
7294 }
7295 return insertBreak.apply(void 0, [editor].concat(args));
7296 },
7297 insertSoftBreak: function insertSoftBreak$1() {
7298 for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
7299 args[_key8] = arguments[_key8];
7300 }
7301 return insertSoftBreak.apply(void 0, [editor].concat(args));
7302 },
7303 insertFragment: function insertFragment$1() {
7304 for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
7305 args[_key9] = arguments[_key9];
7306 }
7307 return insertFragment.apply(void 0, [editor].concat(args));
7308 },
7309 insertNode: function insertNode$1() {
7310 for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
7311 args[_key10] = arguments[_key10];
7312 }
7313 return insertNode.apply(void 0, [editor].concat(args));
7314 },
7315 insertText: function insertText$1() {
7316 for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
7317 args[_key11] = arguments[_key11];
7318 }
7319 return insertText.apply(void 0, [editor].concat(args));
7320 },
7321 normalizeNode: function normalizeNode$1() {
7322 for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
7323 args[_key12] = arguments[_key12];
7324 }
7325 return normalizeNode.apply(void 0, [editor].concat(args));
7326 },
7327 removeMark: function removeMark$1() {
7328 for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
7329 args[_key13] = arguments[_key13];
7330 }
7331 return removeMark.apply(void 0, [editor].concat(args));
7332 },
7333 getDirtyPaths: function getDirtyPaths$1() {
7334 for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
7335 args[_key14] = arguments[_key14];
7336 }
7337 return getDirtyPaths.apply(void 0, [editor].concat(args));
7338 },
7339 shouldNormalize: function shouldNormalize$1() {
7340 for (var _len15 = arguments.length, args = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
7341 args[_key15] = arguments[_key15];
7342 }
7343 return shouldNormalize.apply(void 0, [editor].concat(args));
7344 },
7345 // Editor interface
7346 above: function above$1() {
7347 for (var _len16 = arguments.length, args = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
7348 args[_key16] = arguments[_key16];
7349 }
7350 return above.apply(void 0, [editor].concat(args));
7351 },
7352 after: function after$1() {
7353 for (var _len17 = arguments.length, args = new Array(_len17), _key17 = 0; _key17 < _len17; _key17++) {
7354 args[_key17] = arguments[_key17];
7355 }
7356 return after.apply(void 0, [editor].concat(args));
7357 },
7358 before: function before$1() {
7359 for (var _len18 = arguments.length, args = new Array(_len18), _key18 = 0; _key18 < _len18; _key18++) {
7360 args[_key18] = arguments[_key18];
7361 }
7362 return before.apply(void 0, [editor].concat(args));
7363 },
7364 collapse: function collapse$1() {
7365 for (var _len19 = arguments.length, args = new Array(_len19), _key19 = 0; _key19 < _len19; _key19++) {
7366 args[_key19] = arguments[_key19];
7367 }
7368 return collapse.apply(void 0, [editor].concat(args));
7369 },
7370 "delete": function _delete() {
7371 for (var _len20 = arguments.length, args = new Array(_len20), _key20 = 0; _key20 < _len20; _key20++) {
7372 args[_key20] = arguments[_key20];
7373 }
7374 return deleteText.apply(void 0, [editor].concat(args));
7375 },
7376 deselect: function deselect$1() {
7377 for (var _len21 = arguments.length, args = new Array(_len21), _key21 = 0; _key21 < _len21; _key21++) {
7378 args[_key21] = arguments[_key21];
7379 }
7380 return deselect.apply(void 0, [editor].concat(args));
7381 },
7382 edges: function edges$1() {
7383 for (var _len22 = arguments.length, args = new Array(_len22), _key22 = 0; _key22 < _len22; _key22++) {
7384 args[_key22] = arguments[_key22];
7385 }
7386 return edges.apply(void 0, [editor].concat(args));
7387 },
7388 elementReadOnly: function elementReadOnly$1() {
7389 for (var _len23 = arguments.length, args = new Array(_len23), _key23 = 0; _key23 < _len23; _key23++) {
7390 args[_key23] = arguments[_key23];
7391 }
7392 return elementReadOnly.apply(void 0, [editor].concat(args));
7393 },
7394 end: function end$1() {
7395 for (var _len24 = arguments.length, args = new Array(_len24), _key24 = 0; _key24 < _len24; _key24++) {
7396 args[_key24] = arguments[_key24];
7397 }
7398 return end.apply(void 0, [editor].concat(args));
7399 },
7400 first: function first$1() {
7401 for (var _len25 = arguments.length, args = new Array(_len25), _key25 = 0; _key25 < _len25; _key25++) {
7402 args[_key25] = arguments[_key25];
7403 }
7404 return first.apply(void 0, [editor].concat(args));
7405 },
7406 fragment: function fragment$1() {
7407 for (var _len26 = arguments.length, args = new Array(_len26), _key26 = 0; _key26 < _len26; _key26++) {
7408 args[_key26] = arguments[_key26];
7409 }
7410 return fragment.apply(void 0, [editor].concat(args));
7411 },
7412 getMarks: function getMarks() {
7413 for (var _len27 = arguments.length, args = new Array(_len27), _key27 = 0; _key27 < _len27; _key27++) {
7414 args[_key27] = arguments[_key27];
7415 }
7416 return marks.apply(void 0, [editor].concat(args));
7417 },
7418 hasBlocks: function hasBlocks$1() {
7419 for (var _len28 = arguments.length, args = new Array(_len28), _key28 = 0; _key28 < _len28; _key28++) {
7420 args[_key28] = arguments[_key28];
7421 }
7422 return hasBlocks.apply(void 0, [editor].concat(args));
7423 },
7424 hasInlines: function hasInlines$1() {
7425 for (var _len29 = arguments.length, args = new Array(_len29), _key29 = 0; _key29 < _len29; _key29++) {
7426 args[_key29] = arguments[_key29];
7427 }
7428 return hasInlines.apply(void 0, [editor].concat(args));
7429 },
7430 hasPath: function hasPath$1() {
7431 for (var _len30 = arguments.length, args = new Array(_len30), _key30 = 0; _key30 < _len30; _key30++) {
7432 args[_key30] = arguments[_key30];
7433 }
7434 return hasPath.apply(void 0, [editor].concat(args));
7435 },
7436 hasTexts: function hasTexts$1() {
7437 for (var _len31 = arguments.length, args = new Array(_len31), _key31 = 0; _key31 < _len31; _key31++) {
7438 args[_key31] = arguments[_key31];
7439 }
7440 return hasTexts.apply(void 0, [editor].concat(args));
7441 },
7442 insertNodes: function insertNodes$1() {
7443 for (var _len32 = arguments.length, args = new Array(_len32), _key32 = 0; _key32 < _len32; _key32++) {
7444 args[_key32] = arguments[_key32];
7445 }
7446 return insertNodes.apply(void 0, [editor].concat(args));
7447 },
7448 isBlock: function isBlock$1() {
7449 for (var _len33 = arguments.length, args = new Array(_len33), _key33 = 0; _key33 < _len33; _key33++) {
7450 args[_key33] = arguments[_key33];
7451 }
7452 return isBlock.apply(void 0, [editor].concat(args));
7453 },
7454 isEdge: function isEdge$1() {
7455 for (var _len34 = arguments.length, args = new Array(_len34), _key34 = 0; _key34 < _len34; _key34++) {
7456 args[_key34] = arguments[_key34];
7457 }
7458 return isEdge.apply(void 0, [editor].concat(args));
7459 },
7460 isEmpty: function isEmpty$1() {
7461 for (var _len35 = arguments.length, args = new Array(_len35), _key35 = 0; _key35 < _len35; _key35++) {
7462 args[_key35] = arguments[_key35];
7463 }
7464 return isEmpty.apply(void 0, [editor].concat(args));
7465 },
7466 isEnd: function isEnd$1() {
7467 for (var _len36 = arguments.length, args = new Array(_len36), _key36 = 0; _key36 < _len36; _key36++) {
7468 args[_key36] = arguments[_key36];
7469 }
7470 return isEnd.apply(void 0, [editor].concat(args));
7471 },
7472 isNormalizing: function isNormalizing$1() {
7473 for (var _len37 = arguments.length, args = new Array(_len37), _key37 = 0; _key37 < _len37; _key37++) {
7474 args[_key37] = arguments[_key37];
7475 }
7476 return isNormalizing.apply(void 0, [editor].concat(args));
7477 },
7478 isStart: function isStart$1() {
7479 for (var _len38 = arguments.length, args = new Array(_len38), _key38 = 0; _key38 < _len38; _key38++) {
7480 args[_key38] = arguments[_key38];
7481 }
7482 return isStart.apply(void 0, [editor].concat(args));
7483 },
7484 last: function last$1() {
7485 for (var _len39 = arguments.length, args = new Array(_len39), _key39 = 0; _key39 < _len39; _key39++) {
7486 args[_key39] = arguments[_key39];
7487 }
7488 return last.apply(void 0, [editor].concat(args));
7489 },
7490 leaf: function leaf$1() {
7491 for (var _len40 = arguments.length, args = new Array(_len40), _key40 = 0; _key40 < _len40; _key40++) {
7492 args[_key40] = arguments[_key40];
7493 }
7494 return leaf.apply(void 0, [editor].concat(args));
7495 },
7496 levels: function levels$1() {
7497 for (var _len41 = arguments.length, args = new Array(_len41), _key41 = 0; _key41 < _len41; _key41++) {
7498 args[_key41] = arguments[_key41];
7499 }
7500 return levels.apply(void 0, [editor].concat(args));
7501 },
7502 liftNodes: function liftNodes$1() {
7503 for (var _len42 = arguments.length, args = new Array(_len42), _key42 = 0; _key42 < _len42; _key42++) {
7504 args[_key42] = arguments[_key42];
7505 }
7506 return liftNodes.apply(void 0, [editor].concat(args));
7507 },
7508 mergeNodes: function mergeNodes$1() {
7509 for (var _len43 = arguments.length, args = new Array(_len43), _key43 = 0; _key43 < _len43; _key43++) {
7510 args[_key43] = arguments[_key43];
7511 }
7512 return mergeNodes.apply(void 0, [editor].concat(args));
7513 },
7514 move: function move$1() {
7515 for (var _len44 = arguments.length, args = new Array(_len44), _key44 = 0; _key44 < _len44; _key44++) {
7516 args[_key44] = arguments[_key44];
7517 }
7518 return move.apply(void 0, [editor].concat(args));
7519 },
7520 moveNodes: function moveNodes$1() {
7521 for (var _len45 = arguments.length, args = new Array(_len45), _key45 = 0; _key45 < _len45; _key45++) {
7522 args[_key45] = arguments[_key45];
7523 }
7524 return moveNodes.apply(void 0, [editor].concat(args));
7525 },
7526 next: function next$1() {
7527 for (var _len46 = arguments.length, args = new Array(_len46), _key46 = 0; _key46 < _len46; _key46++) {
7528 args[_key46] = arguments[_key46];
7529 }
7530 return next.apply(void 0, [editor].concat(args));
7531 },
7532 node: function node$1() {
7533 for (var _len47 = arguments.length, args = new Array(_len47), _key47 = 0; _key47 < _len47; _key47++) {
7534 args[_key47] = arguments[_key47];
7535 }
7536 return node.apply(void 0, [editor].concat(args));
7537 },
7538 nodes: function nodes$1() {
7539 for (var _len48 = arguments.length, args = new Array(_len48), _key48 = 0; _key48 < _len48; _key48++) {
7540 args[_key48] = arguments[_key48];
7541 }
7542 return nodes.apply(void 0, [editor].concat(args));
7543 },
7544 normalize: function normalize$1() {
7545 for (var _len49 = arguments.length, args = new Array(_len49), _key49 = 0; _key49 < _len49; _key49++) {
7546 args[_key49] = arguments[_key49];
7547 }
7548 return normalize.apply(void 0, [editor].concat(args));
7549 },
7550 parent: function parent$1() {
7551 for (var _len50 = arguments.length, args = new Array(_len50), _key50 = 0; _key50 < _len50; _key50++) {
7552 args[_key50] = arguments[_key50];
7553 }
7554 return parent.apply(void 0, [editor].concat(args));
7555 },
7556 path: function path$1() {
7557 for (var _len51 = arguments.length, args = new Array(_len51), _key51 = 0; _key51 < _len51; _key51++) {
7558 args[_key51] = arguments[_key51];
7559 }
7560 return path.apply(void 0, [editor].concat(args));
7561 },
7562 pathRef: function pathRef$1() {
7563 for (var _len52 = arguments.length, args = new Array(_len52), _key52 = 0; _key52 < _len52; _key52++) {
7564 args[_key52] = arguments[_key52];
7565 }
7566 return pathRef.apply(void 0, [editor].concat(args));
7567 },
7568 pathRefs: function pathRefs$1() {
7569 for (var _len53 = arguments.length, args = new Array(_len53), _key53 = 0; _key53 < _len53; _key53++) {
7570 args[_key53] = arguments[_key53];
7571 }
7572 return pathRefs.apply(void 0, [editor].concat(args));
7573 },
7574 point: function point$1() {
7575 for (var _len54 = arguments.length, args = new Array(_len54), _key54 = 0; _key54 < _len54; _key54++) {
7576 args[_key54] = arguments[_key54];
7577 }
7578 return point.apply(void 0, [editor].concat(args));
7579 },
7580 pointRef: function pointRef$1() {
7581 for (var _len55 = arguments.length, args = new Array(_len55), _key55 = 0; _key55 < _len55; _key55++) {
7582 args[_key55] = arguments[_key55];
7583 }
7584 return pointRef.apply(void 0, [editor].concat(args));
7585 },
7586 pointRefs: function pointRefs$1() {
7587 for (var _len56 = arguments.length, args = new Array(_len56), _key56 = 0; _key56 < _len56; _key56++) {
7588 args[_key56] = arguments[_key56];
7589 }
7590 return pointRefs.apply(void 0, [editor].concat(args));
7591 },
7592 positions: function positions$1() {
7593 for (var _len57 = arguments.length, args = new Array(_len57), _key57 = 0; _key57 < _len57; _key57++) {
7594 args[_key57] = arguments[_key57];
7595 }
7596 return positions.apply(void 0, [editor].concat(args));
7597 },
7598 previous: function previous$1() {
7599 for (var _len58 = arguments.length, args = new Array(_len58), _key58 = 0; _key58 < _len58; _key58++) {
7600 args[_key58] = arguments[_key58];
7601 }
7602 return previous.apply(void 0, [editor].concat(args));
7603 },
7604 range: function range$1() {
7605 for (var _len59 = arguments.length, args = new Array(_len59), _key59 = 0; _key59 < _len59; _key59++) {
7606 args[_key59] = arguments[_key59];
7607 }
7608 return range.apply(void 0, [editor].concat(args));
7609 },
7610 rangeRef: function rangeRef$1() {
7611 for (var _len60 = arguments.length, args = new Array(_len60), _key60 = 0; _key60 < _len60; _key60++) {
7612 args[_key60] = arguments[_key60];
7613 }
7614 return rangeRef.apply(void 0, [editor].concat(args));
7615 },
7616 rangeRefs: function rangeRefs$1() {
7617 for (var _len61 = arguments.length, args = new Array(_len61), _key61 = 0; _key61 < _len61; _key61++) {
7618 args[_key61] = arguments[_key61];
7619 }
7620 return rangeRefs.apply(void 0, [editor].concat(args));
7621 },
7622 removeNodes: function removeNodes$1() {
7623 for (var _len62 = arguments.length, args = new Array(_len62), _key62 = 0; _key62 < _len62; _key62++) {
7624 args[_key62] = arguments[_key62];
7625 }
7626 return removeNodes.apply(void 0, [editor].concat(args));
7627 },
7628 select: function select$1() {
7629 for (var _len63 = arguments.length, args = new Array(_len63), _key63 = 0; _key63 < _len63; _key63++) {
7630 args[_key63] = arguments[_key63];
7631 }
7632 return select.apply(void 0, [editor].concat(args));
7633 },
7634 setNodes: function setNodes$1() {
7635 for (var _len64 = arguments.length, args = new Array(_len64), _key64 = 0; _key64 < _len64; _key64++) {
7636 args[_key64] = arguments[_key64];
7637 }
7638 return setNodes.apply(void 0, [editor].concat(args));
7639 },
7640 setNormalizing: function setNormalizing$1() {
7641 for (var _len65 = arguments.length, args = new Array(_len65), _key65 = 0; _key65 < _len65; _key65++) {
7642 args[_key65] = arguments[_key65];
7643 }
7644 return setNormalizing.apply(void 0, [editor].concat(args));
7645 },
7646 setPoint: function setPoint$1() {
7647 for (var _len66 = arguments.length, args = new Array(_len66), _key66 = 0; _key66 < _len66; _key66++) {
7648 args[_key66] = arguments[_key66];
7649 }
7650 return setPoint.apply(void 0, [editor].concat(args));
7651 },
7652 setSelection: function setSelection$1() {
7653 for (var _len67 = arguments.length, args = new Array(_len67), _key67 = 0; _key67 < _len67; _key67++) {
7654 args[_key67] = arguments[_key67];
7655 }
7656 return setSelection.apply(void 0, [editor].concat(args));
7657 },
7658 splitNodes: function splitNodes$1() {
7659 for (var _len68 = arguments.length, args = new Array(_len68), _key68 = 0; _key68 < _len68; _key68++) {
7660 args[_key68] = arguments[_key68];
7661 }
7662 return splitNodes.apply(void 0, [editor].concat(args));
7663 },
7664 start: function start$1() {
7665 for (var _len69 = arguments.length, args = new Array(_len69), _key69 = 0; _key69 < _len69; _key69++) {
7666 args[_key69] = arguments[_key69];
7667 }
7668 return start.apply(void 0, [editor].concat(args));
7669 },
7670 string: function string$1() {
7671 for (var _len70 = arguments.length, args = new Array(_len70), _key70 = 0; _key70 < _len70; _key70++) {
7672 args[_key70] = arguments[_key70];
7673 }
7674 return string.apply(void 0, [editor].concat(args));
7675 },
7676 unhangRange: function unhangRange$1() {
7677 for (var _len71 = arguments.length, args = new Array(_len71), _key71 = 0; _key71 < _len71; _key71++) {
7678 args[_key71] = arguments[_key71];
7679 }
7680 return unhangRange.apply(void 0, [editor].concat(args));
7681 },
7682 unsetNodes: function unsetNodes$1() {
7683 for (var _len72 = arguments.length, args = new Array(_len72), _key72 = 0; _key72 < _len72; _key72++) {
7684 args[_key72] = arguments[_key72];
7685 }
7686 return unsetNodes.apply(void 0, [editor].concat(args));
7687 },
7688 unwrapNodes: function unwrapNodes$1() {
7689 for (var _len73 = arguments.length, args = new Array(_len73), _key73 = 0; _key73 < _len73; _key73++) {
7690 args[_key73] = arguments[_key73];
7691 }
7692 return unwrapNodes.apply(void 0, [editor].concat(args));
7693 },
7694 "void": function _void() {
7695 for (var _len74 = arguments.length, args = new Array(_len74), _key74 = 0; _key74 < _len74; _key74++) {
7696 args[_key74] = arguments[_key74];
7697 }
7698 return getVoid.apply(void 0, [editor].concat(args));
7699 },
7700 withoutNormalizing: function withoutNormalizing$1() {
7701 for (var _len75 = arguments.length, args = new Array(_len75), _key75 = 0; _key75 < _len75; _key75++) {
7702 args[_key75] = arguments[_key75];
7703 }
7704 return withoutNormalizing.apply(void 0, [editor].concat(args));
7705 },
7706 wrapNodes: function wrapNodes$1() {
7707 for (var _len76 = arguments.length, args = new Array(_len76), _key76 = 0; _key76 < _len76; _key76++) {
7708 args[_key76] = arguments[_key76];
7709 }
7710 return wrapNodes.apply(void 0, [editor].concat(args));
7711 },
7712 shouldMergeNodesRemovePrevNode: function shouldMergeNodesRemovePrevNode$1() {
7713 for (var _len77 = arguments.length, args = new Array(_len77), _key77 = 0; _key77 < _len77; _key77++) {
7714 args[_key77] = arguments[_key77];
7715 }
7716 return shouldMergeNodesRemovePrevNode.apply(void 0, [editor].concat(args));
7717 }
7718 };
7719 return editor;
7720 };
7721
7722 exports.Editor = Editor;
7723 exports.Element = Element;
7724 exports.Location = Location;
7725 exports.Node = Node;
7726 exports.Operation = Operation;
7727 exports.Path = Path;
7728 exports.PathRef = PathRef;
7729 exports.Point = Point;
7730 exports.PointRef = PointRef;
7731 exports.Range = Range;
7732 exports.RangeRef = RangeRef;
7733 exports.Scrubber = Scrubber;
7734 exports.Span = Span;
7735 exports.Text = Text;
7736 exports.Transforms = Transforms;
7737 exports.above = above;
7738 exports.addMark = addMark;
7739 exports.after = after;
7740 exports.apply = apply;
7741 exports.before = before;
7742 exports.collapse = collapse;
7743 exports.createEditor = createEditor;
7744 exports.deleteBackward = deleteBackward;
7745 exports.deleteForward = deleteForward;
7746 exports.deleteFragment = deleteFragment;
7747 exports.deleteText = deleteText;
7748 exports.deselect = deselect;
7749 exports.edges = edges;
7750 exports.elementReadOnly = elementReadOnly;
7751 exports.end = end;
7752 exports.first = first;
7753 exports.fragment = fragment;
7754 exports.getDirtyPaths = getDirtyPaths;
7755 exports.getFragment = getFragment;
7756 exports.getVoid = getVoid;
7757 exports.hasBlocks = hasBlocks;
7758 exports.hasInlines = hasInlines;
7759 exports.hasPath = hasPath;
7760 exports.hasTexts = hasTexts;
7761 exports.insertBreak = insertBreak;
7762 exports.insertFragment = insertFragment;
7763 exports.insertNode = insertNode;
7764 exports.insertNodes = insertNodes;
7765 exports.insertSoftBreak = insertSoftBreak;
7766 exports.insertText = insertText;
7767 exports.isBlock = isBlock;
7768 exports.isEdge = isEdge;
7769 exports.isEditor = isEditor;
7770 exports.isEmpty = isEmpty;
7771 exports.isEnd = isEnd;
7772 exports.isNormalizing = isNormalizing;
7773 exports.isStart = isStart;
7774 exports.last = last;
7775 exports.leaf = leaf;
7776 exports.levels = levels;
7777 exports.liftNodes = liftNodes;
7778 exports.marks = marks;
7779 exports.mergeNodes = mergeNodes;
7780 exports.move = move;
7781 exports.moveNodes = moveNodes;
7782 exports.next = next;
7783 exports.node = node;
7784 exports.nodes = nodes;
7785 exports.normalize = normalize;
7786 exports.normalizeNode = normalizeNode;
7787 exports.parent = parent;
7788 exports.path = path;
7789 exports.pathRef = pathRef;
7790 exports.pathRefs = pathRefs;
7791 exports.point = point;
7792 exports.pointRef = pointRef;
7793 exports.pointRefs = pointRefs;
7794 exports.positions = positions;
7795 exports.previous = previous;
7796 exports.range = range;
7797 exports.rangeRef = rangeRef;
7798 exports.rangeRefs = rangeRefs;
7799 exports.removeMark = removeMark;
7800 exports.removeNodes = removeNodes;
7801 exports.select = select;
7802 exports.setNodes = setNodes;
7803 exports.setNormalizing = setNormalizing;
7804 exports.setPoint = setPoint;
7805 exports.setSelection = setSelection;
7806 exports.shouldMergeNodesRemovePrevNode = shouldMergeNodesRemovePrevNode;
7807 exports.shouldNormalize = shouldNormalize;
7808 exports.splitNodes = splitNodes;
7809 exports.start = start;
7810 exports.string = string;
7811 exports.unhangRange = unhangRange;
7812 exports.unsetNodes = unsetNodes;
7813 exports.unwrapNodes = unwrapNodes;
7814 exports.withoutNormalizing = withoutNormalizing;
7815 exports.wrapNodes = wrapNodes;
7816
7817}));