1 | 'use strict';
|
2 |
|
3 | var isPlainObject = require('is-plain-object');
|
4 | var immer = require('immer');
|
5 |
|
6 |
|
7 | var PathRef = {
|
8 | transform: function transform(ref, op) {
|
9 | var current = ref.current,
|
10 | affinity = ref.affinity;
|
11 | if (current == null) {
|
12 | return;
|
13 | }
|
14 | var path = Path.transform(current, op, {
|
15 | affinity: affinity
|
16 | });
|
17 | ref.current = path;
|
18 | if (path == null) {
|
19 | ref.unref();
|
20 | }
|
21 | }
|
22 | };
|
23 |
|
24 |
|
25 | var PointRef = {
|
26 | transform: function transform(ref, op) {
|
27 | var current = ref.current,
|
28 | affinity = ref.affinity;
|
29 | if (current == null) {
|
30 | return;
|
31 | }
|
32 | var point = Point.transform(current, op, {
|
33 | affinity: affinity
|
34 | });
|
35 | ref.current = point;
|
36 | if (point == null) {
|
37 | ref.unref();
|
38 | }
|
39 | }
|
40 | };
|
41 |
|
42 |
|
43 | var RangeRef = {
|
44 | transform: function transform(ref, op) {
|
45 | var current = ref.current,
|
46 | affinity = ref.affinity;
|
47 | if (current == null) {
|
48 | return;
|
49 | }
|
50 | var path = Range.transform(current, op, {
|
51 | affinity: affinity
|
52 | });
|
53 | ref.current = path;
|
54 | if (path == null) {
|
55 | ref.unref();
|
56 | }
|
57 | }
|
58 | };
|
59 |
|
60 | var DIRTY_PATHS = new WeakMap();
|
61 | var DIRTY_PATH_KEYS = new WeakMap();
|
62 | var FLUSHING = new WeakMap();
|
63 | var NORMALIZING = new WeakMap();
|
64 | var PATH_REFS = new WeakMap();
|
65 | var POINT_REFS = new WeakMap();
|
66 | var RANGE_REFS = new WeakMap();
|
67 |
|
68 | function unwrapExports (x) {
|
69 | return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
70 | }
|
71 |
|
72 | function createCommonjsModule(fn, module) {
|
73 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
74 | }
|
75 |
|
76 | var arrayLikeToArray = createCommonjsModule(function (module) {
|
77 | function _arrayLikeToArray(arr, len) {
|
78 | if (len == null || len > arr.length) len = arr.length;
|
79 | for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
80 | return arr2;
|
81 | }
|
82 | module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
83 | });
|
84 |
|
85 | unwrapExports(arrayLikeToArray);
|
86 |
|
87 | var arrayWithoutHoles = createCommonjsModule(function (module) {
|
88 | function _arrayWithoutHoles(arr) {
|
89 | if (Array.isArray(arr)) return arrayLikeToArray(arr);
|
90 | }
|
91 | module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
92 | });
|
93 |
|
94 | unwrapExports(arrayWithoutHoles);
|
95 |
|
96 | var iterableToArray = createCommonjsModule(function (module) {
|
97 | function _iterableToArray(iter) {
|
98 | if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
99 | }
|
100 | module.exports = _iterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
101 | });
|
102 |
|
103 | unwrapExports(iterableToArray);
|
104 |
|
105 | var unsupportedIterableToArray = createCommonjsModule(function (module) {
|
106 | function _unsupportedIterableToArray(o, minLen) {
|
107 | if (!o) return;
|
108 | if (typeof o === "string") return arrayLikeToArray(o, minLen);
|
109 | var n = Object.prototype.toString.call(o).slice(8, -1);
|
110 | if (n === "Object" && o.constructor) n = o.constructor.name;
|
111 | if (n === "Map" || n === "Set") return Array.from(o);
|
112 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
|
113 | }
|
114 | module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
115 | });
|
116 |
|
117 | unwrapExports(unsupportedIterableToArray);
|
118 |
|
119 | var nonIterableSpread = createCommonjsModule(function (module) {
|
120 | function _nonIterableSpread() {
|
121 | throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
122 | }
|
123 | module.exports = _nonIterableSpread, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
124 | });
|
125 |
|
126 | unwrapExports(nonIterableSpread);
|
127 |
|
128 | var toConsumableArray = createCommonjsModule(function (module) {
|
129 | function _toConsumableArray(arr) {
|
130 | return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread();
|
131 | }
|
132 | module.exports = _toConsumableArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
133 | });
|
134 |
|
135 | var _toConsumableArray = unwrapExports(toConsumableArray);
|
136 |
|
137 |
|
138 | var Path = {
|
139 | ancestors: function ancestors(path) {
|
140 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
141 | var _options$reverse = options.reverse,
|
142 | reverse = _options$reverse === void 0 ? false : _options$reverse;
|
143 | var paths = Path.levels(path, options);
|
144 | if (reverse) {
|
145 | paths = paths.slice(1);
|
146 | } else {
|
147 | paths = paths.slice(0, -1);
|
148 | }
|
149 | return paths;
|
150 | },
|
151 | common: function common(path, another) {
|
152 | var common = [];
|
153 | for (var i = 0; i < path.length && i < another.length; i++) {
|
154 | var av = path[i];
|
155 | var bv = another[i];
|
156 | if (av !== bv) {
|
157 | break;
|
158 | }
|
159 | common.push(av);
|
160 | }
|
161 | return common;
|
162 | },
|
163 | compare: function compare(path, another) {
|
164 | var min = Math.min(path.length, another.length);
|
165 | for (var i = 0; i < min; i++) {
|
166 | if (path[i] < another[i]) return -1;
|
167 | if (path[i] > another[i]) return 1;
|
168 | }
|
169 | return 0;
|
170 | },
|
171 | endsAfter: function endsAfter(path, another) {
|
172 | var i = path.length - 1;
|
173 | var as = path.slice(0, i);
|
174 | var bs = another.slice(0, i);
|
175 | var av = path[i];
|
176 | var bv = another[i];
|
177 | return Path.equals(as, bs) && av > bv;
|
178 | },
|
179 | endsAt: function endsAt(path, another) {
|
180 | var i = path.length;
|
181 | var as = path.slice(0, i);
|
182 | var bs = another.slice(0, i);
|
183 | return Path.equals(as, bs);
|
184 | },
|
185 | endsBefore: function endsBefore(path, another) {
|
186 | var i = path.length - 1;
|
187 | var as = path.slice(0, i);
|
188 | var bs = another.slice(0, i);
|
189 | var av = path[i];
|
190 | var bv = another[i];
|
191 | return Path.equals(as, bs) && av < bv;
|
192 | },
|
193 | equals: function equals(path, another) {
|
194 | return path.length === another.length && path.every(function (n, i) {
|
195 | return n === another[i];
|
196 | });
|
197 | },
|
198 | hasPrevious: function hasPrevious(path) {
|
199 | return path[path.length - 1] > 0;
|
200 | },
|
201 | isAfter: function isAfter(path, another) {
|
202 | return Path.compare(path, another) === 1;
|
203 | },
|
204 | isAncestor: function isAncestor(path, another) {
|
205 | return path.length < another.length && Path.compare(path, another) === 0;
|
206 | },
|
207 | isBefore: function isBefore(path, another) {
|
208 | return Path.compare(path, another) === -1;
|
209 | },
|
210 | isChild: function isChild(path, another) {
|
211 | return path.length === another.length + 1 && Path.compare(path, another) === 0;
|
212 | },
|
213 | isCommon: function isCommon(path, another) {
|
214 | return path.length <= another.length && Path.compare(path, another) === 0;
|
215 | },
|
216 | isDescendant: function isDescendant(path, another) {
|
217 | return path.length > another.length && Path.compare(path, another) === 0;
|
218 | },
|
219 | isParent: function isParent(path, another) {
|
220 | return path.length + 1 === another.length && Path.compare(path, another) === 0;
|
221 | },
|
222 | isPath: function isPath(value) {
|
223 | return Array.isArray(value) && (value.length === 0 || typeof value[0] === 'number');
|
224 | },
|
225 | isSibling: function isSibling(path, another) {
|
226 | if (path.length !== another.length) {
|
227 | return false;
|
228 | }
|
229 | var as = path.slice(0, -1);
|
230 | var bs = another.slice(0, -1);
|
231 | var al = path[path.length - 1];
|
232 | var bl = another[another.length - 1];
|
233 | return al !== bl && Path.equals(as, bs);
|
234 | },
|
235 | levels: function levels(path) {
|
236 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
237 | var _options$reverse2 = options.reverse,
|
238 | reverse = _options$reverse2 === void 0 ? false : _options$reverse2;
|
239 | var list = [];
|
240 | for (var i = 0; i <= path.length; i++) {
|
241 | list.push(path.slice(0, i));
|
242 | }
|
243 | if (reverse) {
|
244 | list.reverse();
|
245 | }
|
246 | return list;
|
247 | },
|
248 | next: function next(path) {
|
249 | if (path.length === 0) {
|
250 | throw new Error("Cannot get the next path of a root path [".concat(path, "], because it has no next index."));
|
251 | }
|
252 | var last = path[path.length - 1];
|
253 | return path.slice(0, -1).concat(last + 1);
|
254 | },
|
255 | operationCanTransformPath: function operationCanTransformPath(operation) {
|
256 | switch (operation.type) {
|
257 | case 'insert_node':
|
258 | case 'remove_node':
|
259 | case 'merge_node':
|
260 | case 'split_node':
|
261 | case 'move_node':
|
262 | return true;
|
263 | default:
|
264 | return false;
|
265 | }
|
266 | },
|
267 | parent: function parent(path) {
|
268 | if (path.length === 0) {
|
269 | throw new Error("Cannot get the parent path of the root path [".concat(path, "]."));
|
270 | }
|
271 | return path.slice(0, -1);
|
272 | },
|
273 | previous: function previous(path) {
|
274 | if (path.length === 0) {
|
275 | throw new Error("Cannot get the previous path of a root path [".concat(path, "], because it has no previous index."));
|
276 | }
|
277 | var last = path[path.length - 1];
|
278 | if (last <= 0) {
|
279 | throw new Error("Cannot get the previous path of a first child path [".concat(path, "] because it would result in a negative index."));
|
280 | }
|
281 | return path.slice(0, -1).concat(last - 1);
|
282 | },
|
283 | relative: function relative(path, ancestor) {
|
284 | if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) {
|
285 | 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."));
|
286 | }
|
287 | return path.slice(ancestor.length);
|
288 | },
|
289 | transform: function transform(path, operation) {
|
290 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
291 | if (!path) return null;
|
292 |
|
293 | var p = _toConsumableArray(path);
|
294 | var _options$affinity = options.affinity,
|
295 | affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
|
296 |
|
297 | if (path.length === 0) {
|
298 | return p;
|
299 | }
|
300 | switch (operation.type) {
|
301 | case 'insert_node':
|
302 | {
|
303 | var op = operation.path;
|
304 | if (Path.equals(op, p) || Path.endsBefore(op, p) || Path.isAncestor(op, p)) {
|
305 | p[op.length - 1] += 1;
|
306 | }
|
307 | break;
|
308 | }
|
309 | case 'remove_node':
|
310 | {
|
311 | var _op = operation.path;
|
312 | if (Path.equals(_op, p) || Path.isAncestor(_op, p)) {
|
313 | return null;
|
314 | } else if (Path.endsBefore(_op, p)) {
|
315 | p[_op.length - 1] -= 1;
|
316 | }
|
317 | break;
|
318 | }
|
319 | case 'merge_node':
|
320 | {
|
321 | var _op2 = operation.path,
|
322 | position = operation.position;
|
323 | if (Path.equals(_op2, p) || Path.endsBefore(_op2, p)) {
|
324 | p[_op2.length - 1] -= 1;
|
325 | } else if (Path.isAncestor(_op2, p)) {
|
326 | p[_op2.length - 1] -= 1;
|
327 | p[_op2.length] += position;
|
328 | }
|
329 | break;
|
330 | }
|
331 | case 'split_node':
|
332 | {
|
333 | var _op3 = operation.path,
|
334 | _position = operation.position;
|
335 | if (Path.equals(_op3, p)) {
|
336 | if (affinity === 'forward') {
|
337 | p[p.length - 1] += 1;
|
338 | } else if (affinity === 'backward') ; else {
|
339 | return null;
|
340 | }
|
341 | } else if (Path.endsBefore(_op3, p)) {
|
342 | p[_op3.length - 1] += 1;
|
343 | } else if (Path.isAncestor(_op3, p) && path[_op3.length] >= _position) {
|
344 | p[_op3.length - 1] += 1;
|
345 | p[_op3.length] -= _position;
|
346 | }
|
347 | break;
|
348 | }
|
349 | case 'move_node':
|
350 | {
|
351 | var _op4 = operation.path,
|
352 | onp = operation.newPath;
|
353 |
|
354 | if (Path.equals(_op4, onp)) {
|
355 | return p;
|
356 | }
|
357 | if (Path.isAncestor(_op4, p) || Path.equals(_op4, p)) {
|
358 | var copy = onp.slice();
|
359 | if (Path.endsBefore(_op4, onp) && _op4.length < onp.length) {
|
360 | copy[_op4.length - 1] -= 1;
|
361 | }
|
362 | return copy.concat(p.slice(_op4.length));
|
363 | } else if (Path.isSibling(_op4, onp) && (Path.isAncestor(onp, p) || Path.equals(onp, p))) {
|
364 | if (Path.endsBefore(_op4, p)) {
|
365 | p[_op4.length - 1] -= 1;
|
366 | } else {
|
367 | p[_op4.length - 1] += 1;
|
368 | }
|
369 | } else if (Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p)) {
|
370 | if (Path.endsBefore(_op4, p)) {
|
371 | p[_op4.length - 1] -= 1;
|
372 | }
|
373 | p[onp.length - 1] += 1;
|
374 | } else if (Path.endsBefore(_op4, p)) {
|
375 | if (Path.equals(onp, p)) {
|
376 | p[onp.length - 1] += 1;
|
377 | }
|
378 | p[_op4.length - 1] -= 1;
|
379 | }
|
380 | break;
|
381 | }
|
382 | }
|
383 | return p;
|
384 | }
|
385 | };
|
386 |
|
387 | var _typeof_1 = createCommonjsModule(function (module) {
|
388 | function _typeof(o) {
|
389 | "@babel/helpers - typeof";
|
390 |
|
391 | return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
392 | return typeof o;
|
393 | } : function (o) {
|
394 | return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
395 | }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(o);
|
396 | }
|
397 | module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
398 | });
|
399 |
|
400 | unwrapExports(_typeof_1);
|
401 |
|
402 | var toPrimitive = createCommonjsModule(function (module) {
|
403 | var _typeof = _typeof_1["default"];
|
404 | function _toPrimitive(input, hint) {
|
405 | if (_typeof(input) !== "object" || input === null) return input;
|
406 | var prim = input[Symbol.toPrimitive];
|
407 | if (prim !== undefined) {
|
408 | var res = prim.call(input, hint || "default");
|
409 | if (_typeof(res) !== "object") return res;
|
410 | throw new TypeError("@@toPrimitive must return a primitive value.");
|
411 | }
|
412 | return (hint === "string" ? String : Number)(input);
|
413 | }
|
414 | module.exports = _toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
415 | });
|
416 |
|
417 | unwrapExports(toPrimitive);
|
418 |
|
419 | var toPropertyKey = createCommonjsModule(function (module) {
|
420 | var _typeof = _typeof_1["default"];
|
421 |
|
422 | function _toPropertyKey(arg) {
|
423 | var key = toPrimitive(arg, "string");
|
424 | return _typeof(key) === "symbol" ? key : String(key);
|
425 | }
|
426 | module.exports = _toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
427 | });
|
428 |
|
429 | unwrapExports(toPropertyKey);
|
430 |
|
431 | var defineProperty = createCommonjsModule(function (module) {
|
432 | function _defineProperty(obj, key, value) {
|
433 | key = toPropertyKey(key);
|
434 | if (key in obj) {
|
435 | Object.defineProperty(obj, key, {
|
436 | value: value,
|
437 | enumerable: true,
|
438 | configurable: true,
|
439 | writable: true
|
440 | });
|
441 | } else {
|
442 | obj[key] = value;
|
443 | }
|
444 | return obj;
|
445 | }
|
446 | module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
447 | });
|
448 |
|
449 | var _defineProperty = unwrapExports(defineProperty);
|
450 |
|
451 | var arrayWithHoles = createCommonjsModule(function (module) {
|
452 | function _arrayWithHoles(arr) {
|
453 | if (Array.isArray(arr)) return arr;
|
454 | }
|
455 | module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
456 | });
|
457 |
|
458 | unwrapExports(arrayWithHoles);
|
459 |
|
460 | var iterableToArrayLimit = createCommonjsModule(function (module) {
|
461 | function _iterableToArrayLimit(r, l) {
|
462 | var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
463 | if (null != t) {
|
464 | var e,
|
465 | n,
|
466 | i,
|
467 | u,
|
468 | a = [],
|
469 | f = !0,
|
470 | o = !1;
|
471 | try {
|
472 | if (i = (t = t.call(r)).next, 0 === l) {
|
473 | if (Object(t) !== t) return;
|
474 | f = !1;
|
475 | } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
476 | } catch (r) {
|
477 | o = !0, n = r;
|
478 | } finally {
|
479 | try {
|
480 | if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
|
481 | } finally {
|
482 | if (o) throw n;
|
483 | }
|
484 | }
|
485 | return a;
|
486 | }
|
487 | }
|
488 | module.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
489 | });
|
490 |
|
491 | unwrapExports(iterableToArrayLimit);
|
492 |
|
493 | var nonIterableRest = createCommonjsModule(function (module) {
|
494 | function _nonIterableRest() {
|
495 | throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
496 | }
|
497 | module.exports = _nonIterableRest, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
498 | });
|
499 |
|
500 | unwrapExports(nonIterableRest);
|
501 |
|
502 | var slicedToArray = createCommonjsModule(function (module) {
|
503 | function _slicedToArray(arr, i) {
|
504 | return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
|
505 | }
|
506 | module.exports = _slicedToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
507 | });
|
508 |
|
509 | var _slicedToArray = unwrapExports(slicedToArray);
|
510 |
|
511 | 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; }
|
512 | 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; }
|
513 | 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; } } }; }
|
514 | 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); }
|
515 | 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; }
|
516 | var applyToDraft = function applyToDraft(editor, selection, op) {
|
517 | switch (op.type) {
|
518 | case 'insert_node':
|
519 | {
|
520 | var path = op.path,
|
521 | node = op.node;
|
522 | var parent = Node.parent(editor, path);
|
523 | var index = path[path.length - 1];
|
524 | if (index > parent.children.length) {
|
525 | throw new Error("Cannot apply an \"insert_node\" operation at path [".concat(path, "] because the destination is past the end of the node."));
|
526 | }
|
527 | parent.children.splice(index, 0, node);
|
528 | if (selection) {
|
529 | var _iterator = _createForOfIteratorHelper$m(Range.points(selection)),
|
530 | _step;
|
531 | try {
|
532 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
533 | var _step$value = _slicedToArray(_step.value, 2),
|
534 | point = _step$value[0],
|
535 | key = _step$value[1];
|
536 | selection[key] = Point.transform(point, op);
|
537 | }
|
538 | } catch (err) {
|
539 | _iterator.e(err);
|
540 | } finally {
|
541 | _iterator.f();
|
542 | }
|
543 | }
|
544 | break;
|
545 | }
|
546 | case 'insert_text':
|
547 | {
|
548 | var _path = op.path,
|
549 | offset = op.offset,
|
550 | text = op.text;
|
551 | if (text.length === 0) break;
|
552 | var _node = Node.leaf(editor, _path);
|
553 | var before = _node.text.slice(0, offset);
|
554 | var after = _node.text.slice(offset);
|
555 | _node.text = before + text + after;
|
556 | if (selection) {
|
557 | var _iterator2 = _createForOfIteratorHelper$m(Range.points(selection)),
|
558 | _step2;
|
559 | try {
|
560 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
561 | var _step2$value = _slicedToArray(_step2.value, 2),
|
562 | _point = _step2$value[0],
|
563 | _key = _step2$value[1];
|
564 | selection[_key] = Point.transform(_point, op);
|
565 | }
|
566 | } catch (err) {
|
567 | _iterator2.e(err);
|
568 | } finally {
|
569 | _iterator2.f();
|
570 | }
|
571 | }
|
572 | break;
|
573 | }
|
574 | case 'merge_node':
|
575 | {
|
576 | var _path2 = op.path;
|
577 | var _node2 = Node.get(editor, _path2);
|
578 | var prevPath = Path.previous(_path2);
|
579 | var prev = Node.get(editor, prevPath);
|
580 | var _parent = Node.parent(editor, _path2);
|
581 | var _index = _path2[_path2.length - 1];
|
582 | if (Text.isText(_node2) && Text.isText(prev)) {
|
583 | prev.text += _node2.text;
|
584 | } else if (!Text.isText(_node2) && !Text.isText(prev)) {
|
585 | var _prev$children;
|
586 | (_prev$children = prev.children).push.apply(_prev$children, _toConsumableArray(_node2.children));
|
587 | } else {
|
588 | 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)));
|
589 | }
|
590 | _parent.children.splice(_index, 1);
|
591 | if (selection) {
|
592 | var _iterator3 = _createForOfIteratorHelper$m(Range.points(selection)),
|
593 | _step3;
|
594 | try {
|
595 | for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
596 | var _step3$value = _slicedToArray(_step3.value, 2),
|
597 | _point2 = _step3$value[0],
|
598 | _key2 = _step3$value[1];
|
599 | selection[_key2] = Point.transform(_point2, op);
|
600 | }
|
601 | } catch (err) {
|
602 | _iterator3.e(err);
|
603 | } finally {
|
604 | _iterator3.f();
|
605 | }
|
606 | }
|
607 | break;
|
608 | }
|
609 | case 'move_node':
|
610 | {
|
611 | var _path3 = op.path,
|
612 | newPath = op.newPath;
|
613 | if (Path.isAncestor(_path3, newPath)) {
|
614 | throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
|
615 | }
|
616 | var _node3 = Node.get(editor, _path3);
|
617 | var _parent2 = Node.parent(editor, _path3);
|
618 | var _index2 = _path3[_path3.length - 1];
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 | _parent2.children.splice(_index2, 1);
|
626 | var truePath = Path.transform(_path3, op);
|
627 | var newParent = Node.get(editor, Path.parent(truePath));
|
628 | var newIndex = truePath[truePath.length - 1];
|
629 | newParent.children.splice(newIndex, 0, _node3);
|
630 | if (selection) {
|
631 | var _iterator4 = _createForOfIteratorHelper$m(Range.points(selection)),
|
632 | _step4;
|
633 | try {
|
634 | for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
635 | var _step4$value = _slicedToArray(_step4.value, 2),
|
636 | _point3 = _step4$value[0],
|
637 | _key3 = _step4$value[1];
|
638 | selection[_key3] = Point.transform(_point3, op);
|
639 | }
|
640 | } catch (err) {
|
641 | _iterator4.e(err);
|
642 | } finally {
|
643 | _iterator4.f();
|
644 | }
|
645 | }
|
646 | break;
|
647 | }
|
648 | case 'remove_node':
|
649 | {
|
650 | var _path4 = op.path;
|
651 | var _index3 = _path4[_path4.length - 1];
|
652 | var _parent3 = Node.parent(editor, _path4);
|
653 | _parent3.children.splice(_index3, 1);
|
654 |
|
655 |
|
656 | if (selection) {
|
657 | var _iterator5 = _createForOfIteratorHelper$m(Range.points(selection)),
|
658 | _step5;
|
659 | try {
|
660 | for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
661 | var _step5$value = _slicedToArray(_step5.value, 2),
|
662 | _point4 = _step5$value[0],
|
663 | _key4 = _step5$value[1];
|
664 | var result = Point.transform(_point4, op);
|
665 | if (selection != null && result != null) {
|
666 | selection[_key4] = result;
|
667 | } else {
|
668 | var _prev = void 0;
|
669 | var next = void 0;
|
670 | var _iterator6 = _createForOfIteratorHelper$m(Node.texts(editor)),
|
671 | _step6;
|
672 | try {
|
673 | for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
674 | var _step6$value = _slicedToArray(_step6.value, 2),
|
675 | n = _step6$value[0],
|
676 | p = _step6$value[1];
|
677 | if (Path.compare(p, _path4) === -1) {
|
678 | _prev = [n, p];
|
679 | } else {
|
680 | next = [n, p];
|
681 | break;
|
682 | }
|
683 | }
|
684 | } catch (err) {
|
685 | _iterator6.e(err);
|
686 | } finally {
|
687 | _iterator6.f();
|
688 | }
|
689 | var preferNext = false;
|
690 | if (_prev && next) {
|
691 | if (Path.equals(next[1], _path4)) {
|
692 | preferNext = !Path.hasPrevious(next[1]);
|
693 | } else {
|
694 | preferNext = Path.common(_prev[1], _path4).length < Path.common(next[1], _path4).length;
|
695 | }
|
696 | }
|
697 | if (_prev && !preferNext) {
|
698 | _point4.path = _prev[1];
|
699 | _point4.offset = _prev[0].text.length;
|
700 | } else if (next) {
|
701 | _point4.path = next[1];
|
702 | _point4.offset = 0;
|
703 | } else {
|
704 | selection = null;
|
705 | }
|
706 | }
|
707 | }
|
708 | } catch (err) {
|
709 | _iterator5.e(err);
|
710 | } finally {
|
711 | _iterator5.f();
|
712 | }
|
713 | }
|
714 | break;
|
715 | }
|
716 | case 'remove_text':
|
717 | {
|
718 | var _path5 = op.path,
|
719 | _offset = op.offset,
|
720 | _text = op.text;
|
721 | if (_text.length === 0) break;
|
722 | var _node4 = Node.leaf(editor, _path5);
|
723 | var _before = _node4.text.slice(0, _offset);
|
724 | var _after = _node4.text.slice(_offset + _text.length);
|
725 | _node4.text = _before + _after;
|
726 | if (selection) {
|
727 | var _iterator7 = _createForOfIteratorHelper$m(Range.points(selection)),
|
728 | _step7;
|
729 | try {
|
730 | for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
731 | var _step7$value = _slicedToArray(_step7.value, 2),
|
732 | _point5 = _step7$value[0],
|
733 | _key5 = _step7$value[1];
|
734 | selection[_key5] = Point.transform(_point5, op);
|
735 | }
|
736 | } catch (err) {
|
737 | _iterator7.e(err);
|
738 | } finally {
|
739 | _iterator7.f();
|
740 | }
|
741 | }
|
742 | break;
|
743 | }
|
744 | case 'set_node':
|
745 | {
|
746 | var _path6 = op.path,
|
747 | properties = op.properties,
|
748 | newProperties = op.newProperties;
|
749 | if (_path6.length === 0) {
|
750 | throw new Error("Cannot set properties on the root node!");
|
751 | }
|
752 | var _node5 = Node.get(editor, _path6);
|
753 | for (var _key6 in newProperties) {
|
754 | if (_key6 === 'children' || _key6 === 'text') {
|
755 | throw new Error("Cannot set the \"".concat(_key6, "\" property of nodes!"));
|
756 | }
|
757 | var value = newProperties[_key6];
|
758 | if (value == null) {
|
759 | delete _node5[_key6];
|
760 | } else {
|
761 | _node5[_key6] = value;
|
762 | }
|
763 | }
|
764 |
|
765 | for (var _key7 in properties) {
|
766 | if (!newProperties.hasOwnProperty(_key7)) {
|
767 | delete _node5[_key7];
|
768 | }
|
769 | }
|
770 | break;
|
771 | }
|
772 | case 'set_selection':
|
773 | {
|
774 | var _newProperties = op.newProperties;
|
775 | if (_newProperties == null) {
|
776 | selection = _newProperties;
|
777 | } else {
|
778 | if (selection == null) {
|
779 | if (!Range.isRange(_newProperties)) {
|
780 | throw new Error("Cannot apply an incomplete \"set_selection\" operation properties ".concat(Scrubber.stringify(_newProperties), " when there is no current selection."));
|
781 | }
|
782 | selection = _objectSpread$e({}, _newProperties);
|
783 | }
|
784 | for (var _key8 in _newProperties) {
|
785 | var _value = _newProperties[_key8];
|
786 | if (_value == null) {
|
787 | if (_key8 === 'anchor' || _key8 === 'focus') {
|
788 | throw new Error("Cannot remove the \"".concat(_key8, "\" selection property"));
|
789 | }
|
790 | delete selection[_key8];
|
791 | } else {
|
792 | selection[_key8] = _value;
|
793 | }
|
794 | }
|
795 | }
|
796 | break;
|
797 | }
|
798 | case 'split_node':
|
799 | {
|
800 | var _path7 = op.path,
|
801 | position = op.position,
|
802 | _properties = op.properties;
|
803 | if (_path7.length === 0) {
|
804 | throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
|
805 | }
|
806 | var _node6 = Node.get(editor, _path7);
|
807 | var _parent4 = Node.parent(editor, _path7);
|
808 | var _index4 = _path7[_path7.length - 1];
|
809 | var newNode;
|
810 | if (Text.isText(_node6)) {
|
811 | var _before2 = _node6.text.slice(0, position);
|
812 | var _after2 = _node6.text.slice(position);
|
813 | _node6.text = _before2;
|
814 | newNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
815 | text: _after2
|
816 | });
|
817 | } else {
|
818 | var _before3 = _node6.children.slice(0, position);
|
819 | var _after3 = _node6.children.slice(position);
|
820 | _node6.children = _before3;
|
821 | newNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
822 | children: _after3
|
823 | });
|
824 | }
|
825 | _parent4.children.splice(_index4 + 1, 0, newNode);
|
826 | if (selection) {
|
827 | var _iterator8 = _createForOfIteratorHelper$m(Range.points(selection)),
|
828 | _step8;
|
829 | try {
|
830 | for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
831 | var _step8$value = _slicedToArray(_step8.value, 2),
|
832 | _point6 = _step8$value[0],
|
833 | _key9 = _step8$value[1];
|
834 | selection[_key9] = Point.transform(_point6, op);
|
835 | }
|
836 | } catch (err) {
|
837 | _iterator8.e(err);
|
838 | } finally {
|
839 | _iterator8.f();
|
840 | }
|
841 | }
|
842 | break;
|
843 | }
|
844 | }
|
845 | return selection;
|
846 | };
|
847 |
|
848 | var GeneralTransforms = {
|
849 | transform: function transform(editor, op) {
|
850 | editor.children = immer.createDraft(editor.children);
|
851 | var selection = editor.selection && immer.createDraft(editor.selection);
|
852 | try {
|
853 | selection = applyToDraft(editor, selection, op);
|
854 | } finally {
|
855 | editor.children = immer.finishDraft(editor.children);
|
856 | if (selection) {
|
857 | editor.selection = immer.isDraft(selection) ? immer.finishDraft(selection) : selection;
|
858 | } else {
|
859 | editor.selection = null;
|
860 | }
|
861 | }
|
862 | }
|
863 | };
|
864 |
|
865 |
|
866 | var NodeTransforms = {
|
867 | insertNodes: function insertNodes(editor, nodes, options) {
|
868 | editor.insertNodes(nodes, options);
|
869 | },
|
870 | liftNodes: function liftNodes(editor, options) {
|
871 | editor.liftNodes(options);
|
872 | },
|
873 | mergeNodes: function mergeNodes(editor, options) {
|
874 | editor.mergeNodes(options);
|
875 | },
|
876 | moveNodes: function moveNodes(editor, options) {
|
877 | editor.moveNodes(options);
|
878 | },
|
879 | removeNodes: function removeNodes(editor, options) {
|
880 | editor.removeNodes(options);
|
881 | },
|
882 | setNodes: function setNodes(editor, props, options) {
|
883 | editor.setNodes(props, options);
|
884 | },
|
885 | splitNodes: function splitNodes(editor, options) {
|
886 | editor.splitNodes(options);
|
887 | },
|
888 | unsetNodes: function unsetNodes(editor, props, options) {
|
889 | editor.unsetNodes(props, options);
|
890 | },
|
891 | unwrapNodes: function unwrapNodes(editor, options) {
|
892 | editor.unwrapNodes(options);
|
893 | },
|
894 | wrapNodes: function wrapNodes(editor, element, options) {
|
895 | editor.wrapNodes(element, options);
|
896 | }
|
897 | };
|
898 |
|
899 |
|
900 | var SelectionTransforms = {
|
901 | collapse: function collapse(editor, options) {
|
902 | editor.collapse(options);
|
903 | },
|
904 | deselect: function deselect(editor) {
|
905 | editor.deselect();
|
906 | },
|
907 | move: function move(editor, options) {
|
908 | editor.move(options);
|
909 | },
|
910 | select: function select(editor, target) {
|
911 | editor.select(target);
|
912 | },
|
913 | setPoint: function setPoint(editor, props, options) {
|
914 | editor.setPoint(props, options);
|
915 | },
|
916 | setSelection: function setSelection(editor, props) {
|
917 | editor.setSelection(props);
|
918 | }
|
919 | };
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 | var isDeepEqual = function isDeepEqual(node, another) {
|
932 | for (var key in node) {
|
933 | var a = node[key];
|
934 | var b = another[key];
|
935 | if (isPlainObject.isPlainObject(a) && isPlainObject.isPlainObject(b)) {
|
936 | if (!isDeepEqual(a, b)) return false;
|
937 | } else if (Array.isArray(a) && Array.isArray(b)) {
|
938 | if (a.length !== b.length) return false;
|
939 | for (var i = 0; i < a.length; i++) {
|
940 | if (a[i] !== b[i]) return false;
|
941 | }
|
942 | } else if (a !== b) {
|
943 | return false;
|
944 | }
|
945 | }
|
946 | |
947 |
|
948 |
|
949 |
|
950 |
|
951 | for (var _key in another) {
|
952 | if (node[_key] === undefined && another[_key] !== undefined) {
|
953 | return false;
|
954 | }
|
955 | }
|
956 | return true;
|
957 | };
|
958 |
|
959 | var objectWithoutPropertiesLoose = createCommonjsModule(function (module) {
|
960 | function _objectWithoutPropertiesLoose(source, excluded) {
|
961 | if (source == null) return {};
|
962 | var target = {};
|
963 | var sourceKeys = Object.keys(source);
|
964 | var key, i;
|
965 | for (i = 0; i < sourceKeys.length; i++) {
|
966 | key = sourceKeys[i];
|
967 | if (excluded.indexOf(key) >= 0) continue;
|
968 | target[key] = source[key];
|
969 | }
|
970 | return target;
|
971 | }
|
972 | module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
973 | });
|
974 |
|
975 | unwrapExports(objectWithoutPropertiesLoose);
|
976 |
|
977 | var objectWithoutProperties = createCommonjsModule(function (module) {
|
978 | function _objectWithoutProperties(source, excluded) {
|
979 | if (source == null) return {};
|
980 | var target = objectWithoutPropertiesLoose(source, excluded);
|
981 | var key, i;
|
982 | if (Object.getOwnPropertySymbols) {
|
983 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
984 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
985 | key = sourceSymbolKeys[i];
|
986 | if (excluded.indexOf(key) >= 0) continue;
|
987 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
988 | target[key] = source[key];
|
989 | }
|
990 | }
|
991 | return target;
|
992 | }
|
993 | module.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
994 | });
|
995 |
|
996 | var _objectWithoutProperties = unwrapExports(objectWithoutProperties);
|
997 |
|
998 | var _excluded$4 = ["anchor", "focus"];
|
999 | 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; }
|
1000 | 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; }
|
1001 |
|
1002 | var Range = {
|
1003 | edges: function edges(range) {
|
1004 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1005 | var _options$reverse = options.reverse,
|
1006 | reverse = _options$reverse === void 0 ? false : _options$reverse;
|
1007 | var anchor = range.anchor,
|
1008 | focus = range.focus;
|
1009 | return Range.isBackward(range) === reverse ? [anchor, focus] : [focus, anchor];
|
1010 | },
|
1011 | end: function end(range) {
|
1012 | var _Range$edges = Range.edges(range),
|
1013 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
1014 | end = _Range$edges2[1];
|
1015 | return end;
|
1016 | },
|
1017 | equals: function equals(range, another) {
|
1018 | return Point.equals(range.anchor, another.anchor) && Point.equals(range.focus, another.focus);
|
1019 | },
|
1020 | includes: function includes(range, target) {
|
1021 | if (Range.isRange(target)) {
|
1022 | if (Range.includes(range, target.anchor) || Range.includes(range, target.focus)) {
|
1023 | return true;
|
1024 | }
|
1025 | var _Range$edges3 = Range.edges(range),
|
1026 | _Range$edges4 = _slicedToArray(_Range$edges3, 2),
|
1027 | rs = _Range$edges4[0],
|
1028 | re = _Range$edges4[1];
|
1029 | var _Range$edges5 = Range.edges(target),
|
1030 | _Range$edges6 = _slicedToArray(_Range$edges5, 2),
|
1031 | ts = _Range$edges6[0],
|
1032 | te = _Range$edges6[1];
|
1033 | return Point.isBefore(rs, ts) && Point.isAfter(re, te);
|
1034 | }
|
1035 | var _Range$edges7 = Range.edges(range),
|
1036 | _Range$edges8 = _slicedToArray(_Range$edges7, 2),
|
1037 | start = _Range$edges8[0],
|
1038 | end = _Range$edges8[1];
|
1039 | var isAfterStart = false;
|
1040 | var isBeforeEnd = false;
|
1041 | if (Point.isPoint(target)) {
|
1042 | isAfterStart = Point.compare(target, start) >= 0;
|
1043 | isBeforeEnd = Point.compare(target, end) <= 0;
|
1044 | } else {
|
1045 | isAfterStart = Path.compare(target, start.path) >= 0;
|
1046 | isBeforeEnd = Path.compare(target, end.path) <= 0;
|
1047 | }
|
1048 | return isAfterStart && isBeforeEnd;
|
1049 | },
|
1050 | intersection: function intersection(range, another) {
|
1051 | range.anchor;
|
1052 | range.focus;
|
1053 | var rest = _objectWithoutProperties(range, _excluded$4);
|
1054 | var _Range$edges9 = Range.edges(range),
|
1055 | _Range$edges10 = _slicedToArray(_Range$edges9, 2),
|
1056 | s1 = _Range$edges10[0],
|
1057 | e1 = _Range$edges10[1];
|
1058 | var _Range$edges11 = Range.edges(another),
|
1059 | _Range$edges12 = _slicedToArray(_Range$edges11, 2),
|
1060 | s2 = _Range$edges12[0],
|
1061 | e2 = _Range$edges12[1];
|
1062 | var start = Point.isBefore(s1, s2) ? s2 : s1;
|
1063 | var end = Point.isBefore(e1, e2) ? e1 : e2;
|
1064 | if (Point.isBefore(end, start)) {
|
1065 | return null;
|
1066 | } else {
|
1067 | return _objectSpread$d({
|
1068 | anchor: start,
|
1069 | focus: end
|
1070 | }, rest);
|
1071 | }
|
1072 | },
|
1073 | isBackward: function isBackward(range) {
|
1074 | var anchor = range.anchor,
|
1075 | focus = range.focus;
|
1076 | return Point.isAfter(anchor, focus);
|
1077 | },
|
1078 | isCollapsed: function isCollapsed(range) {
|
1079 | var anchor = range.anchor,
|
1080 | focus = range.focus;
|
1081 | return Point.equals(anchor, focus);
|
1082 | },
|
1083 | isExpanded: function isExpanded(range) {
|
1084 | return !Range.isCollapsed(range);
|
1085 | },
|
1086 | isForward: function isForward(range) {
|
1087 | return !Range.isBackward(range);
|
1088 | },
|
1089 | isRange: function isRange(value) {
|
1090 | return isPlainObject.isPlainObject(value) && Point.isPoint(value.anchor) && Point.isPoint(value.focus);
|
1091 | },
|
1092 | points: function* points(range) {
|
1093 | yield [range.anchor, 'anchor'];
|
1094 | yield [range.focus, 'focus'];
|
1095 | },
|
1096 | start: function start(range) {
|
1097 | var _Range$edges13 = Range.edges(range),
|
1098 | _Range$edges14 = _slicedToArray(_Range$edges13, 1),
|
1099 | start = _Range$edges14[0];
|
1100 | return start;
|
1101 | },
|
1102 | transform: function transform(range, op) {
|
1103 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1104 | return immer.produce(range, function (r) {
|
1105 | if (r === null) {
|
1106 | return null;
|
1107 | }
|
1108 | var _options$affinity = options.affinity,
|
1109 | affinity = _options$affinity === void 0 ? 'inward' : _options$affinity;
|
1110 | var affinityAnchor;
|
1111 | var affinityFocus;
|
1112 | if (affinity === 'inward') {
|
1113 |
|
1114 |
|
1115 |
|
1116 | var isCollapsed = Range.isCollapsed(r);
|
1117 | if (Range.isForward(r)) {
|
1118 | affinityAnchor = 'forward';
|
1119 | affinityFocus = isCollapsed ? affinityAnchor : 'backward';
|
1120 | } else {
|
1121 | affinityAnchor = 'backward';
|
1122 | affinityFocus = isCollapsed ? affinityAnchor : 'forward';
|
1123 | }
|
1124 | } else if (affinity === 'outward') {
|
1125 | if (Range.isForward(r)) {
|
1126 | affinityAnchor = 'backward';
|
1127 | affinityFocus = 'forward';
|
1128 | } else {
|
1129 | affinityAnchor = 'forward';
|
1130 | affinityFocus = 'backward';
|
1131 | }
|
1132 | } else {
|
1133 | affinityAnchor = affinity;
|
1134 | affinityFocus = affinity;
|
1135 | }
|
1136 | var anchor = Point.transform(r.anchor, op, {
|
1137 | affinity: affinityAnchor
|
1138 | });
|
1139 | var focus = Point.transform(r.focus, op, {
|
1140 | affinity: affinityFocus
|
1141 | });
|
1142 | if (!anchor || !focus) {
|
1143 | return null;
|
1144 | }
|
1145 | r.anchor = anchor;
|
1146 | r.focus = focus;
|
1147 | });
|
1148 | }
|
1149 | };
|
1150 |
|
1151 |
|
1152 |
|
1153 |
|
1154 | var isElement = function isElement(value) {
|
1155 | return isPlainObject.isPlainObject(value) && Node.isNodeList(value.children) && !Editor.isEditor(value);
|
1156 | };
|
1157 |
|
1158 | var Element = {
|
1159 | isAncestor: function isAncestor(value) {
|
1160 | return isPlainObject.isPlainObject(value) && Node.isNodeList(value.children);
|
1161 | },
|
1162 | isElement: isElement,
|
1163 | isElementList: function isElementList(value) {
|
1164 | return Array.isArray(value) && value.every(function (val) {
|
1165 | return Element.isElement(val);
|
1166 | });
|
1167 | },
|
1168 | isElementProps: function isElementProps(props) {
|
1169 | return props.children !== undefined;
|
1170 | },
|
1171 | isElementType: function isElementType(value, elementVal) {
|
1172 | var elementKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'type';
|
1173 | return isElement(value) && value[elementKey] === elementVal;
|
1174 | },
|
1175 | matches: function matches(element, props) {
|
1176 | for (var key in props) {
|
1177 | if (key === 'children') {
|
1178 | continue;
|
1179 | }
|
1180 | if (element[key] !== props[key]) {
|
1181 | return false;
|
1182 | }
|
1183 | }
|
1184 | return true;
|
1185 | }
|
1186 | };
|
1187 |
|
1188 | var _excluded$3 = ["children"],
|
1189 | _excluded2$3 = ["text"];
|
1190 | 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; } } }; }
|
1191 | 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); }
|
1192 | 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; }
|
1193 | var IS_NODE_LIST_CACHE = new WeakMap();
|
1194 |
|
1195 | var Node = {
|
1196 | ancestor: function ancestor(root, path) {
|
1197 | var node = Node.get(root, path);
|
1198 | if (Text.isText(node)) {
|
1199 | throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(Scrubber.stringify(node)));
|
1200 | }
|
1201 | return node;
|
1202 | },
|
1203 | ancestors: function ancestors(root, path) {
|
1204 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1205 | return function* () {
|
1206 | var _iterator = _createForOfIteratorHelper$l(Path.ancestors(path, options)),
|
1207 | _step;
|
1208 | try {
|
1209 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
1210 | var p = _step.value;
|
1211 | var n = Node.ancestor(root, p);
|
1212 | var entry = [n, p];
|
1213 | yield entry;
|
1214 | }
|
1215 | } catch (err) {
|
1216 | _iterator.e(err);
|
1217 | } finally {
|
1218 | _iterator.f();
|
1219 | }
|
1220 | }();
|
1221 | },
|
1222 | child: function child(root, index) {
|
1223 | if (Text.isText(root)) {
|
1224 | throw new Error("Cannot get the child of a text node: ".concat(Scrubber.stringify(root)));
|
1225 | }
|
1226 | var c = root.children[index];
|
1227 | if (c == null) {
|
1228 | throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(Scrubber.stringify(root)));
|
1229 | }
|
1230 | return c;
|
1231 | },
|
1232 | children: function children(root, path) {
|
1233 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1234 | return function* () {
|
1235 | var _options$reverse = options.reverse,
|
1236 | reverse = _options$reverse === void 0 ? false : _options$reverse;
|
1237 | var ancestor = Node.ancestor(root, path);
|
1238 | var children = ancestor.children;
|
1239 | var index = reverse ? children.length - 1 : 0;
|
1240 | while (reverse ? index >= 0 : index < children.length) {
|
1241 | var child = Node.child(ancestor, index);
|
1242 | var childPath = path.concat(index);
|
1243 | yield [child, childPath];
|
1244 | index = reverse ? index - 1 : index + 1;
|
1245 | }
|
1246 | }();
|
1247 | },
|
1248 | common: function common(root, path, another) {
|
1249 | var p = Path.common(path, another);
|
1250 | var n = Node.get(root, p);
|
1251 | return [n, p];
|
1252 | },
|
1253 | descendant: function descendant(root, path) {
|
1254 | var node = Node.get(root, path);
|
1255 | if (Editor.isEditor(node)) {
|
1256 | 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)));
|
1257 | }
|
1258 | return node;
|
1259 | },
|
1260 | descendants: function descendants(root) {
|
1261 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1262 | return function* () {
|
1263 | var _iterator2 = _createForOfIteratorHelper$l(Node.nodes(root, options)),
|
1264 | _step2;
|
1265 | try {
|
1266 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
1267 | var _step2$value = _slicedToArray(_step2.value, 2),
|
1268 | node = _step2$value[0],
|
1269 | path = _step2$value[1];
|
1270 | if (path.length !== 0) {
|
1271 |
|
1272 |
|
1273 | yield [node, path];
|
1274 | }
|
1275 | }
|
1276 | } catch (err) {
|
1277 | _iterator2.e(err);
|
1278 | } finally {
|
1279 | _iterator2.f();
|
1280 | }
|
1281 | }();
|
1282 | },
|
1283 | elements: function elements(root) {
|
1284 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1285 | return function* () {
|
1286 | var _iterator3 = _createForOfIteratorHelper$l(Node.nodes(root, options)),
|
1287 | _step3;
|
1288 | try {
|
1289 | for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
1290 | var _step3$value = _slicedToArray(_step3.value, 2),
|
1291 | node = _step3$value[0],
|
1292 | path = _step3$value[1];
|
1293 | if (Element.isElement(node)) {
|
1294 | yield [node, path];
|
1295 | }
|
1296 | }
|
1297 | } catch (err) {
|
1298 | _iterator3.e(err);
|
1299 | } finally {
|
1300 | _iterator3.f();
|
1301 | }
|
1302 | }();
|
1303 | },
|
1304 | extractProps: function extractProps(node) {
|
1305 | if (Element.isAncestor(node)) {
|
1306 | node.children;
|
1307 | var properties = _objectWithoutProperties(node, _excluded$3);
|
1308 | return properties;
|
1309 | } else {
|
1310 | node.text;
|
1311 | var _properties = _objectWithoutProperties(node, _excluded2$3);
|
1312 | return _properties;
|
1313 | }
|
1314 | },
|
1315 | first: function first(root, path) {
|
1316 | var p = path.slice();
|
1317 | var n = Node.get(root, p);
|
1318 | while (n) {
|
1319 | if (Text.isText(n) || n.children.length === 0) {
|
1320 | break;
|
1321 | } else {
|
1322 | n = n.children[0];
|
1323 | p.push(0);
|
1324 | }
|
1325 | }
|
1326 | return [n, p];
|
1327 | },
|
1328 | fragment: function fragment(root, range) {
|
1329 | if (Text.isText(root)) {
|
1330 | throw new Error("Cannot get a fragment starting from a root text node: ".concat(Scrubber.stringify(root)));
|
1331 | }
|
1332 | var newRoot = immer.produce({
|
1333 | children: root.children
|
1334 | }, function (r) {
|
1335 | var _Range$edges = Range.edges(range),
|
1336 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
1337 | start = _Range$edges2[0],
|
1338 | end = _Range$edges2[1];
|
1339 | var nodeEntries = Node.nodes(r, {
|
1340 | reverse: true,
|
1341 | pass: function pass(_ref) {
|
1342 | var _ref2 = _slicedToArray(_ref, 2),
|
1343 | path = _ref2[1];
|
1344 | return !Range.includes(range, path);
|
1345 | }
|
1346 | });
|
1347 | var _iterator4 = _createForOfIteratorHelper$l(nodeEntries),
|
1348 | _step4;
|
1349 | try {
|
1350 | for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
1351 | var _step4$value = _slicedToArray(_step4.value, 2),
|
1352 | path = _step4$value[1];
|
1353 | if (!Range.includes(range, path)) {
|
1354 | var parent = Node.parent(r, path);
|
1355 | var index = path[path.length - 1];
|
1356 | parent.children.splice(index, 1);
|
1357 | }
|
1358 | if (Path.equals(path, end.path)) {
|
1359 | var leaf = Node.leaf(r, path);
|
1360 | leaf.text = leaf.text.slice(0, end.offset);
|
1361 | }
|
1362 | if (Path.equals(path, start.path)) {
|
1363 | var _leaf = Node.leaf(r, path);
|
1364 | _leaf.text = _leaf.text.slice(start.offset);
|
1365 | }
|
1366 | }
|
1367 | } catch (err) {
|
1368 | _iterator4.e(err);
|
1369 | } finally {
|
1370 | _iterator4.f();
|
1371 | }
|
1372 | if (Editor.isEditor(r)) {
|
1373 | r.selection = null;
|
1374 | }
|
1375 | });
|
1376 | return newRoot.children;
|
1377 | },
|
1378 | get: function get(root, path) {
|
1379 | var node = root;
|
1380 | for (var i = 0; i < path.length; i++) {
|
1381 | var p = path[i];
|
1382 | if (Text.isText(node) || !node.children[p]) {
|
1383 | throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(Scrubber.stringify(root)));
|
1384 | }
|
1385 | node = node.children[p];
|
1386 | }
|
1387 | return node;
|
1388 | },
|
1389 | has: function has(root, path) {
|
1390 | var node = root;
|
1391 | for (var i = 0; i < path.length; i++) {
|
1392 | var p = path[i];
|
1393 | if (Text.isText(node) || !node.children[p]) {
|
1394 | return false;
|
1395 | }
|
1396 | node = node.children[p];
|
1397 | }
|
1398 | return true;
|
1399 | },
|
1400 | isNode: function isNode(value) {
|
1401 | return Text.isText(value) || Element.isElement(value) || Editor.isEditor(value);
|
1402 | },
|
1403 | isNodeList: function isNodeList(value) {
|
1404 | if (!Array.isArray(value)) {
|
1405 | return false;
|
1406 | }
|
1407 | var cachedResult = IS_NODE_LIST_CACHE.get(value);
|
1408 | if (cachedResult !== undefined) {
|
1409 | return cachedResult;
|
1410 | }
|
1411 | var isNodeList = value.every(function (val) {
|
1412 | return Node.isNode(val);
|
1413 | });
|
1414 | IS_NODE_LIST_CACHE.set(value, isNodeList);
|
1415 | return isNodeList;
|
1416 | },
|
1417 | last: function last(root, path) {
|
1418 | var p = path.slice();
|
1419 | var n = Node.get(root, p);
|
1420 | while (n) {
|
1421 | if (Text.isText(n) || n.children.length === 0) {
|
1422 | break;
|
1423 | } else {
|
1424 | var i = n.children.length - 1;
|
1425 | n = n.children[i];
|
1426 | p.push(i);
|
1427 | }
|
1428 | }
|
1429 | return [n, p];
|
1430 | },
|
1431 | leaf: function leaf(root, path) {
|
1432 | var node = Node.get(root, path);
|
1433 | if (!Text.isText(node)) {
|
1434 | throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
|
1435 | }
|
1436 | return node;
|
1437 | },
|
1438 | levels: function levels(root, path) {
|
1439 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1440 | return function* () {
|
1441 | var _iterator5 = _createForOfIteratorHelper$l(Path.levels(path, options)),
|
1442 | _step5;
|
1443 | try {
|
1444 | for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
1445 | var p = _step5.value;
|
1446 | var n = Node.get(root, p);
|
1447 | yield [n, p];
|
1448 | }
|
1449 | } catch (err) {
|
1450 | _iterator5.e(err);
|
1451 | } finally {
|
1452 | _iterator5.f();
|
1453 | }
|
1454 | }();
|
1455 | },
|
1456 | matches: function matches(node, props) {
|
1457 | return Element.isElement(node) && Element.isElementProps(props) && Element.matches(node, props) || Text.isText(node) && Text.isTextProps(props) && Text.matches(node, props);
|
1458 | },
|
1459 | nodes: function nodes(root) {
|
1460 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1461 | return function* () {
|
1462 | var pass = options.pass,
|
1463 | _options$reverse2 = options.reverse,
|
1464 | reverse = _options$reverse2 === void 0 ? false : _options$reverse2;
|
1465 | var _options$from = options.from,
|
1466 | from = _options$from === void 0 ? [] : _options$from,
|
1467 | to = options.to;
|
1468 | var visited = new Set();
|
1469 | var p = [];
|
1470 | var n = root;
|
1471 | while (true) {
|
1472 | if (to && (reverse ? Path.isBefore(p, to) : Path.isAfter(p, to))) {
|
1473 | break;
|
1474 | }
|
1475 | if (!visited.has(n)) {
|
1476 | yield [n, p];
|
1477 | }
|
1478 |
|
1479 | if (!visited.has(n) && !Text.isText(n) && n.children.length !== 0 && (pass == null || pass([n, p]) === false)) {
|
1480 | visited.add(n);
|
1481 | var nextIndex = reverse ? n.children.length - 1 : 0;
|
1482 | if (Path.isAncestor(p, from)) {
|
1483 | nextIndex = from[p.length];
|
1484 | }
|
1485 | p = p.concat(nextIndex);
|
1486 | n = Node.get(root, p);
|
1487 | continue;
|
1488 | }
|
1489 |
|
1490 | if (p.length === 0) {
|
1491 | break;
|
1492 | }
|
1493 |
|
1494 | if (!reverse) {
|
1495 | var newPath = Path.next(p);
|
1496 | if (Node.has(root, newPath)) {
|
1497 | p = newPath;
|
1498 | n = Node.get(root, p);
|
1499 | continue;
|
1500 | }
|
1501 | }
|
1502 |
|
1503 | if (reverse && p[p.length - 1] !== 0) {
|
1504 | var _newPath = Path.previous(p);
|
1505 | p = _newPath;
|
1506 | n = Node.get(root, p);
|
1507 | continue;
|
1508 | }
|
1509 |
|
1510 | p = Path.parent(p);
|
1511 | n = Node.get(root, p);
|
1512 | visited.add(n);
|
1513 | }
|
1514 | }();
|
1515 | },
|
1516 | parent: function parent(root, path) {
|
1517 | var parentPath = Path.parent(path);
|
1518 | var p = Node.get(root, parentPath);
|
1519 | if (Text.isText(p)) {
|
1520 | throw new Error("Cannot get the parent of path [".concat(path, "] because it does not exist in the root."));
|
1521 | }
|
1522 | return p;
|
1523 | },
|
1524 | string: function string(node) {
|
1525 | if (Text.isText(node)) {
|
1526 | return node.text;
|
1527 | } else {
|
1528 | return node.children.map(Node.string).join('');
|
1529 | }
|
1530 | },
|
1531 | texts: function texts(root) {
|
1532 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1533 | return function* () {
|
1534 | var _iterator6 = _createForOfIteratorHelper$l(Node.nodes(root, options)),
|
1535 | _step6;
|
1536 | try {
|
1537 | for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
1538 | var _step6$value = _slicedToArray(_step6.value, 2),
|
1539 | node = _step6$value[0],
|
1540 | path = _step6$value[1];
|
1541 | if (Text.isText(node)) {
|
1542 | yield [node, path];
|
1543 | }
|
1544 | }
|
1545 | } catch (err) {
|
1546 | _iterator6.e(err);
|
1547 | } finally {
|
1548 | _iterator6.f();
|
1549 | }
|
1550 | }();
|
1551 | }
|
1552 | };
|
1553 |
|
1554 | 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; }
|
1555 | 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; }
|
1556 |
|
1557 | var Operation = {
|
1558 | isNodeOperation: function isNodeOperation(value) {
|
1559 | return Operation.isOperation(value) && value.type.endsWith('_node');
|
1560 | },
|
1561 | isOperation: function isOperation(value) {
|
1562 | if (!isPlainObject.isPlainObject(value)) {
|
1563 | return false;
|
1564 | }
|
1565 | switch (value.type) {
|
1566 | case 'insert_node':
|
1567 | return Path.isPath(value.path) && Node.isNode(value.node);
|
1568 | case 'insert_text':
|
1569 | return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
|
1570 | case 'merge_node':
|
1571 | return typeof value.position === 'number' && Path.isPath(value.path) && isPlainObject.isPlainObject(value.properties);
|
1572 | case 'move_node':
|
1573 | return Path.isPath(value.path) && Path.isPath(value.newPath);
|
1574 | case 'remove_node':
|
1575 | return Path.isPath(value.path) && Node.isNode(value.node);
|
1576 | case 'remove_text':
|
1577 | return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
|
1578 | case 'set_node':
|
1579 | return Path.isPath(value.path) && isPlainObject.isPlainObject(value.properties) && isPlainObject.isPlainObject(value.newProperties);
|
1580 | case 'set_selection':
|
1581 | return value.properties === null && Range.isRange(value.newProperties) || value.newProperties === null && Range.isRange(value.properties) || isPlainObject.isPlainObject(value.properties) && isPlainObject.isPlainObject(value.newProperties);
|
1582 | case 'split_node':
|
1583 | return Path.isPath(value.path) && typeof value.position === 'number' && isPlainObject.isPlainObject(value.properties);
|
1584 | default:
|
1585 | return false;
|
1586 | }
|
1587 | },
|
1588 | isOperationList: function isOperationList(value) {
|
1589 | return Array.isArray(value) && value.every(function (val) {
|
1590 | return Operation.isOperation(val);
|
1591 | });
|
1592 | },
|
1593 | isSelectionOperation: function isSelectionOperation(value) {
|
1594 | return Operation.isOperation(value) && value.type.endsWith('_selection');
|
1595 | },
|
1596 | isTextOperation: function isTextOperation(value) {
|
1597 | return Operation.isOperation(value) && value.type.endsWith('_text');
|
1598 | },
|
1599 | inverse: function inverse(op) {
|
1600 | switch (op.type) {
|
1601 | case 'insert_node':
|
1602 | {
|
1603 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1604 | type: 'remove_node'
|
1605 | });
|
1606 | }
|
1607 | case 'insert_text':
|
1608 | {
|
1609 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1610 | type: 'remove_text'
|
1611 | });
|
1612 | }
|
1613 | case 'merge_node':
|
1614 | {
|
1615 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1616 | type: 'split_node',
|
1617 | path: Path.previous(op.path)
|
1618 | });
|
1619 | }
|
1620 | case 'move_node':
|
1621 | {
|
1622 | var newPath = op.newPath,
|
1623 | path = op.path;
|
1624 |
|
1625 | if (Path.equals(newPath, path)) {
|
1626 | return op;
|
1627 | }
|
1628 |
|
1629 |
|
1630 | if (Path.isSibling(path, newPath)) {
|
1631 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1632 | path: newPath,
|
1633 | newPath: path
|
1634 | });
|
1635 | }
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 | var inversePath = Path.transform(path, op);
|
1643 | var inverseNewPath = Path.transform(Path.next(path), op);
|
1644 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1645 | path: inversePath,
|
1646 | newPath: inverseNewPath
|
1647 | });
|
1648 | }
|
1649 | case 'remove_node':
|
1650 | {
|
1651 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1652 | type: 'insert_node'
|
1653 | });
|
1654 | }
|
1655 | case 'remove_text':
|
1656 | {
|
1657 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1658 | type: 'insert_text'
|
1659 | });
|
1660 | }
|
1661 | case 'set_node':
|
1662 | {
|
1663 | var properties = op.properties,
|
1664 | newProperties = op.newProperties;
|
1665 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1666 | properties: newProperties,
|
1667 | newProperties: properties
|
1668 | });
|
1669 | }
|
1670 | case 'set_selection':
|
1671 | {
|
1672 | var _properties = op.properties,
|
1673 | _newProperties = op.newProperties;
|
1674 | if (_properties == null) {
|
1675 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1676 | properties: _newProperties,
|
1677 | newProperties: null
|
1678 | });
|
1679 | } else if (_newProperties == null) {
|
1680 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1681 | properties: null,
|
1682 | newProperties: _properties
|
1683 | });
|
1684 | } else {
|
1685 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1686 | properties: _newProperties,
|
1687 | newProperties: _properties
|
1688 | });
|
1689 | }
|
1690 | }
|
1691 | case 'split_node':
|
1692 | {
|
1693 | return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
1694 | type: 'merge_node',
|
1695 | path: Path.next(op.path)
|
1696 | });
|
1697 | }
|
1698 | }
|
1699 | }
|
1700 | };
|
1701 |
|
1702 | var IS_EDITOR_CACHE = new WeakMap();
|
1703 | var isEditor = function isEditor(value) {
|
1704 | var cachedIsEditor = IS_EDITOR_CACHE.get(value);
|
1705 | if (cachedIsEditor !== undefined) {
|
1706 | return cachedIsEditor;
|
1707 | }
|
1708 | if (!isPlainObject.isPlainObject(value)) {
|
1709 | return false;
|
1710 | }
|
1711 | 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.isPlainObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.children) && Operation.isOperationList(value.operations);
|
1712 | IS_EDITOR_CACHE.set(value, isEditor);
|
1713 | return isEditor;
|
1714 | };
|
1715 |
|
1716 |
|
1717 | var Editor = {
|
1718 | above: function above(editor, options) {
|
1719 | return editor.above(options);
|
1720 | },
|
1721 | addMark: function addMark(editor, key, value) {
|
1722 | editor.addMark(key, value);
|
1723 | },
|
1724 | after: function after(editor, at, options) {
|
1725 | return editor.after(at, options);
|
1726 | },
|
1727 | before: function before(editor, at, options) {
|
1728 | return editor.before(at, options);
|
1729 | },
|
1730 | deleteBackward: function deleteBackward(editor) {
|
1731 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1732 | var _options$unit = options.unit,
|
1733 | unit = _options$unit === void 0 ? 'character' : _options$unit;
|
1734 | editor.deleteBackward(unit);
|
1735 | },
|
1736 | deleteForward: function deleteForward(editor) {
|
1737 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1738 | var _options$unit2 = options.unit,
|
1739 | unit = _options$unit2 === void 0 ? 'character' : _options$unit2;
|
1740 | editor.deleteForward(unit);
|
1741 | },
|
1742 | deleteFragment: function deleteFragment(editor, options) {
|
1743 | editor.deleteFragment(options);
|
1744 | },
|
1745 | edges: function edges(editor, at) {
|
1746 | return editor.edges(at);
|
1747 | },
|
1748 | elementReadOnly: function elementReadOnly(editor) {
|
1749 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1750 | return editor.elementReadOnly(options);
|
1751 | },
|
1752 | end: function end(editor, at) {
|
1753 | return editor.end(at);
|
1754 | },
|
1755 | first: function first(editor, at) {
|
1756 | return editor.first(at);
|
1757 | },
|
1758 | fragment: function fragment(editor, at) {
|
1759 | return editor.fragment(at);
|
1760 | },
|
1761 | hasBlocks: function hasBlocks(editor, element) {
|
1762 | return editor.hasBlocks(element);
|
1763 | },
|
1764 | hasInlines: function hasInlines(editor, element) {
|
1765 | return editor.hasInlines(element);
|
1766 | },
|
1767 | hasPath: function hasPath(editor, path) {
|
1768 | return editor.hasPath(path);
|
1769 | },
|
1770 | hasTexts: function hasTexts(editor, element) {
|
1771 | return editor.hasTexts(element);
|
1772 | },
|
1773 | insertBreak: function insertBreak(editor) {
|
1774 | editor.insertBreak();
|
1775 | },
|
1776 | insertFragment: function insertFragment(editor, fragment, options) {
|
1777 | editor.insertFragment(fragment, options);
|
1778 | },
|
1779 | insertNode: function insertNode(editor, node) {
|
1780 | editor.insertNode(node);
|
1781 | },
|
1782 | insertSoftBreak: function insertSoftBreak(editor) {
|
1783 | editor.insertSoftBreak();
|
1784 | },
|
1785 | insertText: function insertText(editor, text) {
|
1786 | editor.insertText(text);
|
1787 | },
|
1788 | isBlock: function isBlock(editor, value) {
|
1789 | return editor.isBlock(value);
|
1790 | },
|
1791 | isEdge: function isEdge(editor, point, at) {
|
1792 | return editor.isEdge(point, at);
|
1793 | },
|
1794 | isEditor: function isEditor$1(value) {
|
1795 | return isEditor(value);
|
1796 | },
|
1797 | isElementReadOnly: function isElementReadOnly(editor, element) {
|
1798 | return editor.isElementReadOnly(element);
|
1799 | },
|
1800 | isEmpty: function isEmpty(editor, element) {
|
1801 | return editor.isEmpty(element);
|
1802 | },
|
1803 | isEnd: function isEnd(editor, point, at) {
|
1804 | return editor.isEnd(point, at);
|
1805 | },
|
1806 | isInline: function isInline(editor, value) {
|
1807 | return editor.isInline(value);
|
1808 | },
|
1809 | isNormalizing: function isNormalizing(editor) {
|
1810 | return editor.isNormalizing();
|
1811 | },
|
1812 | isSelectable: function isSelectable(editor, value) {
|
1813 | return editor.isSelectable(value);
|
1814 | },
|
1815 | isStart: function isStart(editor, point, at) {
|
1816 | return editor.isStart(point, at);
|
1817 | },
|
1818 | isVoid: function isVoid(editor, value) {
|
1819 | return editor.isVoid(value);
|
1820 | },
|
1821 | last: function last(editor, at) {
|
1822 | return editor.last(at);
|
1823 | },
|
1824 | leaf: function leaf(editor, at, options) {
|
1825 | return editor.leaf(at, options);
|
1826 | },
|
1827 | levels: function levels(editor, options) {
|
1828 | return editor.levels(options);
|
1829 | },
|
1830 | marks: function marks(editor) {
|
1831 | return editor.getMarks();
|
1832 | },
|
1833 | next: function next(editor, options) {
|
1834 | return editor.next(options);
|
1835 | },
|
1836 | node: function node(editor, at, options) {
|
1837 | return editor.node(at, options);
|
1838 | },
|
1839 | nodes: function nodes(editor, options) {
|
1840 | return editor.nodes(options);
|
1841 | },
|
1842 | normalize: function normalize(editor, options) {
|
1843 | editor.normalize(options);
|
1844 | },
|
1845 | parent: function parent(editor, at, options) {
|
1846 | return editor.parent(at, options);
|
1847 | },
|
1848 | path: function path(editor, at, options) {
|
1849 | return editor.path(at, options);
|
1850 | },
|
1851 | pathRef: function pathRef(editor, path, options) {
|
1852 | return editor.pathRef(path, options);
|
1853 | },
|
1854 | pathRefs: function pathRefs(editor) {
|
1855 | return editor.pathRefs();
|
1856 | },
|
1857 | point: function point(editor, at, options) {
|
1858 | return editor.point(at, options);
|
1859 | },
|
1860 | pointRef: function pointRef(editor, point, options) {
|
1861 | return editor.pointRef(point, options);
|
1862 | },
|
1863 | pointRefs: function pointRefs(editor) {
|
1864 | return editor.pointRefs();
|
1865 | },
|
1866 | positions: function positions(editor, options) {
|
1867 | return editor.positions(options);
|
1868 | },
|
1869 | previous: function previous(editor, options) {
|
1870 | return editor.previous(options);
|
1871 | },
|
1872 | range: function range(editor, at, to) {
|
1873 | return editor.range(at, to);
|
1874 | },
|
1875 | rangeRef: function rangeRef(editor, range, options) {
|
1876 | return editor.rangeRef(range, options);
|
1877 | },
|
1878 | rangeRefs: function rangeRefs(editor) {
|
1879 | return editor.rangeRefs();
|
1880 | },
|
1881 | removeMark: function removeMark(editor, key) {
|
1882 | editor.removeMark(key);
|
1883 | },
|
1884 | setNormalizing: function setNormalizing(editor, isNormalizing) {
|
1885 | editor.setNormalizing(isNormalizing);
|
1886 | },
|
1887 | start: function start(editor, at) {
|
1888 | return editor.start(at);
|
1889 | },
|
1890 | string: function string(editor, at, options) {
|
1891 | return editor.string(at, options);
|
1892 | },
|
1893 | unhangRange: function unhangRange(editor, range, options) {
|
1894 | return editor.unhangRange(range, options);
|
1895 | },
|
1896 | "void": function _void(editor, options) {
|
1897 | return editor["void"](options);
|
1898 | },
|
1899 | withoutNormalizing: function withoutNormalizing(editor, fn) {
|
1900 | editor.withoutNormalizing(fn);
|
1901 | },
|
1902 | shouldMergeNodesRemovePrevNode: function shouldMergeNodesRemovePrevNode(editor, prevNode, curNode) {
|
1903 | return editor.shouldMergeNodesRemovePrevNode(prevNode, curNode);
|
1904 | }
|
1905 | };
|
1906 |
|
1907 |
|
1908 | var Location = {
|
1909 | isLocation: function isLocation(value) {
|
1910 | return Path.isPath(value) || Point.isPoint(value) || Range.isRange(value);
|
1911 | }
|
1912 | };
|
1913 |
|
1914 | var Span = {
|
1915 | isSpan: function isSpan(value) {
|
1916 | return Array.isArray(value) && value.length === 2 && value.every(Path.isPath);
|
1917 | }
|
1918 | };
|
1919 |
|
1920 | 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; }
|
1921 | 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; }
|
1922 |
|
1923 | var Point = {
|
1924 | compare: function compare(point, another) {
|
1925 | var result = Path.compare(point.path, another.path);
|
1926 | if (result === 0) {
|
1927 | if (point.offset < another.offset) return -1;
|
1928 | if (point.offset > another.offset) return 1;
|
1929 | return 0;
|
1930 | }
|
1931 | return result;
|
1932 | },
|
1933 | isAfter: function isAfter(point, another) {
|
1934 | return Point.compare(point, another) === 1;
|
1935 | },
|
1936 | isBefore: function isBefore(point, another) {
|
1937 | return Point.compare(point, another) === -1;
|
1938 | },
|
1939 | equals: function equals(point, another) {
|
1940 |
|
1941 | return point.offset === another.offset && Path.equals(point.path, another.path);
|
1942 | },
|
1943 | isPoint: function isPoint(value) {
|
1944 | return isPlainObject.isPlainObject(value) && typeof value.offset === 'number' && Path.isPath(value.path);
|
1945 | },
|
1946 | transform: function transform(point, op) {
|
1947 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1948 | return immer.produce(point, function (p) {
|
1949 | if (p === null) {
|
1950 | return null;
|
1951 | }
|
1952 | var _options$affinity = options.affinity,
|
1953 | affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
|
1954 | var path = p.path,
|
1955 | offset = p.offset;
|
1956 | switch (op.type) {
|
1957 | case 'insert_node':
|
1958 | case 'move_node':
|
1959 | {
|
1960 | p.path = Path.transform(path, op, options);
|
1961 | break;
|
1962 | }
|
1963 | case 'insert_text':
|
1964 | {
|
1965 | if (Path.equals(op.path, path) && (op.offset < offset || op.offset === offset && affinity === 'forward')) {
|
1966 | p.offset += op.text.length;
|
1967 | }
|
1968 | break;
|
1969 | }
|
1970 | case 'merge_node':
|
1971 | {
|
1972 | if (Path.equals(op.path, path)) {
|
1973 | p.offset += op.position;
|
1974 | }
|
1975 | p.path = Path.transform(path, op, options);
|
1976 | break;
|
1977 | }
|
1978 | case 'remove_text':
|
1979 | {
|
1980 | if (Path.equals(op.path, path) && op.offset <= offset) {
|
1981 | p.offset -= Math.min(offset - op.offset, op.text.length);
|
1982 | }
|
1983 | break;
|
1984 | }
|
1985 | case 'remove_node':
|
1986 | {
|
1987 | if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) {
|
1988 | return null;
|
1989 | }
|
1990 | p.path = Path.transform(path, op, options);
|
1991 | break;
|
1992 | }
|
1993 | case 'split_node':
|
1994 | {
|
1995 | if (Path.equals(op.path, path)) {
|
1996 | if (op.position === offset && affinity == null) {
|
1997 | return null;
|
1998 | } else if (op.position < offset || op.position === offset && affinity === 'forward') {
|
1999 | p.offset -= op.position;
|
2000 | p.path = Path.transform(path, op, _objectSpread$b(_objectSpread$b({}, options), {}, {
|
2001 | affinity: 'forward'
|
2002 | }));
|
2003 | }
|
2004 | } else {
|
2005 | p.path = Path.transform(path, op, options);
|
2006 | }
|
2007 | break;
|
2008 | }
|
2009 | }
|
2010 | });
|
2011 | }
|
2012 | };
|
2013 |
|
2014 | var _scrubber = undefined;
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 |
|
2023 |
|
2024 |
|
2025 |
|
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 | var Scrubber = {
|
2032 | setScrubber: function setScrubber(scrubber) {
|
2033 | _scrubber = scrubber;
|
2034 | },
|
2035 | stringify: function stringify(value) {
|
2036 | return JSON.stringify(value, _scrubber);
|
2037 | }
|
2038 | };
|
2039 |
|
2040 | var _excluded$2 = ["text"],
|
2041 | _excluded2$2 = ["anchor", "focus"];
|
2042 | 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; } } }; }
|
2043 | 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); }
|
2044 | 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; }
|
2045 | 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; }
|
2046 | 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; }
|
2047 |
|
2048 | var Text = {
|
2049 | equals: function equals(text, another) {
|
2050 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
2051 | var _options$loose = options.loose,
|
2052 | loose = _options$loose === void 0 ? false : _options$loose;
|
2053 | function omitText(obj) {
|
2054 | obj.text;
|
2055 | var rest = _objectWithoutProperties(obj, _excluded$2);
|
2056 | return rest;
|
2057 | }
|
2058 | return isDeepEqual(loose ? omitText(text) : text, loose ? omitText(another) : another);
|
2059 | },
|
2060 | isText: function isText(value) {
|
2061 | return isPlainObject.isPlainObject(value) && typeof value.text === 'string';
|
2062 | },
|
2063 | isTextList: function isTextList(value) {
|
2064 | return Array.isArray(value) && value.every(function (val) {
|
2065 | return Text.isText(val);
|
2066 | });
|
2067 | },
|
2068 | isTextProps: function isTextProps(props) {
|
2069 | return props.text !== undefined;
|
2070 | },
|
2071 | matches: function matches(text, props) {
|
2072 | for (var key in props) {
|
2073 | if (key === 'text') {
|
2074 | continue;
|
2075 | }
|
2076 | if (!text.hasOwnProperty(key) || text[key] !== props[key]) {
|
2077 | return false;
|
2078 | }
|
2079 | }
|
2080 | return true;
|
2081 | },
|
2082 | decorations: function decorations(node, _decorations) {
|
2083 | var leaves = [_objectSpread$a({}, node)];
|
2084 | var _iterator = _createForOfIteratorHelper$k(_decorations),
|
2085 | _step;
|
2086 | try {
|
2087 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2088 | var dec = _step.value;
|
2089 | var anchor = dec.anchor,
|
2090 | focus = dec.focus,
|
2091 | rest = _objectWithoutProperties(dec, _excluded2$2);
|
2092 | var _Range$edges = Range.edges(dec),
|
2093 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
2094 | start = _Range$edges2[0],
|
2095 | end = _Range$edges2[1];
|
2096 | var next = [];
|
2097 | var leafEnd = 0;
|
2098 | var decorationStart = start.offset;
|
2099 | var decorationEnd = end.offset;
|
2100 | var _iterator2 = _createForOfIteratorHelper$k(leaves),
|
2101 | _step2;
|
2102 | try {
|
2103 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
2104 | var leaf = _step2.value;
|
2105 | var length = leaf.text.length;
|
2106 | var leafStart = leafEnd;
|
2107 | leafEnd += length;
|
2108 |
|
2109 | if (decorationStart <= leafStart && leafEnd <= decorationEnd) {
|
2110 | Object.assign(leaf, rest);
|
2111 | next.push(leaf);
|
2112 | continue;
|
2113 | }
|
2114 |
|
2115 | if (decorationStart !== decorationEnd && (decorationStart === leafEnd || decorationEnd === leafStart) || decorationStart > leafEnd || decorationEnd < leafStart || decorationEnd === leafStart && leafStart !== 0) {
|
2116 | next.push(leaf);
|
2117 | continue;
|
2118 | }
|
2119 |
|
2120 |
|
2121 |
|
2122 | var middle = leaf;
|
2123 | var before = void 0;
|
2124 | var after = void 0;
|
2125 | if (decorationEnd < leafEnd) {
|
2126 | var off = decorationEnd - leafStart;
|
2127 | after = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
2128 | text: middle.text.slice(off)
|
2129 | });
|
2130 | middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
2131 | text: middle.text.slice(0, off)
|
2132 | });
|
2133 | }
|
2134 | if (decorationStart > leafStart) {
|
2135 | var _off = decorationStart - leafStart;
|
2136 | before = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
2137 | text: middle.text.slice(0, _off)
|
2138 | });
|
2139 | middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
2140 | text: middle.text.slice(_off)
|
2141 | });
|
2142 | }
|
2143 | Object.assign(middle, rest);
|
2144 | if (before) {
|
2145 | next.push(before);
|
2146 | }
|
2147 | next.push(middle);
|
2148 | if (after) {
|
2149 | next.push(after);
|
2150 | }
|
2151 | }
|
2152 | } catch (err) {
|
2153 | _iterator2.e(err);
|
2154 | } finally {
|
2155 | _iterator2.f();
|
2156 | }
|
2157 | leaves = next;
|
2158 | }
|
2159 | } catch (err) {
|
2160 | _iterator.e(err);
|
2161 | } finally {
|
2162 | _iterator.f();
|
2163 | }
|
2164 | return leaves;
|
2165 | }
|
2166 | };
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 | var getDefaultInsertLocation = function getDefaultInsertLocation(editor) {
|
2175 | if (editor.selection) {
|
2176 | return editor.selection;
|
2177 | } else if (editor.children.length > 0) {
|
2178 | return Editor.end(editor, []);
|
2179 | } else {
|
2180 | return [0];
|
2181 | }
|
2182 | };
|
2183 |
|
2184 | var matchPath = function matchPath(editor, path) {
|
2185 | var _Editor$node = Editor.node(editor, path),
|
2186 | _Editor$node2 = _slicedToArray(_Editor$node, 1),
|
2187 | node = _Editor$node2[0];
|
2188 | return function (n) {
|
2189 | return n === node;
|
2190 | };
|
2191 | };
|
2192 |
|
2193 | 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; } } }; }
|
2194 | 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); }
|
2195 | 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; }
|
2196 |
|
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
|
2204 |
|
2205 |
|
2206 |
|
2207 |
|
2208 | var getCharacterDistance = function getCharacterDistance(str) {
|
2209 | var isRTL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
2210 | var isLTR = !isRTL;
|
2211 | var codepoints = isRTL ? codepointsIteratorRTL(str) : str;
|
2212 | var left = CodepointType.None;
|
2213 | var right = CodepointType.None;
|
2214 | var distance = 0;
|
2215 |
|
2216 | var gb11 = null;
|
2217 | var gb12Or13 = null;
|
2218 | var _iterator = _createForOfIteratorHelper$j(codepoints),
|
2219 | _step;
|
2220 | try {
|
2221 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2222 | var _char = _step.value;
|
2223 | var code = _char.codePointAt(0);
|
2224 | if (!code) break;
|
2225 | var type = getCodepointType(_char, code);
|
2226 | var _ref = isLTR ? [right, type] : [type, left];
|
2227 | var _ref2 = _slicedToArray(_ref, 2);
|
2228 | left = _ref2[0];
|
2229 | right = _ref2[1];
|
2230 | if (intersects(left, CodepointType.ZWJ) && intersects(right, CodepointType.ExtPict)) {
|
2231 | if (isLTR) {
|
2232 | gb11 = endsWithEmojiZWJ(str.substring(0, distance));
|
2233 | } else {
|
2234 | gb11 = endsWithEmojiZWJ(str.substring(0, str.length - distance));
|
2235 | }
|
2236 | if (!gb11) break;
|
2237 | }
|
2238 | if (intersects(left, CodepointType.RI) && intersects(right, CodepointType.RI)) {
|
2239 | if (gb12Or13 !== null) {
|
2240 | gb12Or13 = !gb12Or13;
|
2241 | } else {
|
2242 | if (isLTR) {
|
2243 | gb12Or13 = true;
|
2244 | } else {
|
2245 | gb12Or13 = endsWithOddNumberOfRIs(str.substring(0, str.length - distance));
|
2246 | }
|
2247 | }
|
2248 | if (!gb12Or13) break;
|
2249 | }
|
2250 | if (left !== CodepointType.None && right !== CodepointType.None && isBoundaryPair(left, right)) {
|
2251 | break;
|
2252 | }
|
2253 | distance += _char.length;
|
2254 | }
|
2255 | } catch (err) {
|
2256 | _iterator.e(err);
|
2257 | } finally {
|
2258 | _iterator.f();
|
2259 | }
|
2260 | return distance || 1;
|
2261 | };
|
2262 | var SPACE = /\s/;
|
2263 | 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]/;
|
2264 | var CHAMELEON = /['\u2018\u2019]/;
|
2265 |
|
2266 |
|
2267 |
|
2268 | var getWordDistance = function getWordDistance(text) {
|
2269 | var isRTL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
2270 | var dist = 0;
|
2271 | var started = false;
|
2272 | while (text.length > 0) {
|
2273 | var charDist = getCharacterDistance(text, isRTL);
|
2274 | var _splitByCharacterDist = splitByCharacterDistance(text, charDist, isRTL),
|
2275 | _splitByCharacterDist2 = _slicedToArray(_splitByCharacterDist, 2),
|
2276 | _char2 = _splitByCharacterDist2[0],
|
2277 | remaining = _splitByCharacterDist2[1];
|
2278 | if (isWordCharacter(_char2, remaining, isRTL)) {
|
2279 | started = true;
|
2280 | dist += charDist;
|
2281 | } else if (!started) {
|
2282 | dist += charDist;
|
2283 | } else {
|
2284 | break;
|
2285 | }
|
2286 | text = remaining;
|
2287 | }
|
2288 | return dist;
|
2289 | };
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 | var splitByCharacterDistance = function splitByCharacterDistance(str, dist, isRTL) {
|
2295 | if (isRTL) {
|
2296 | var at = str.length - dist;
|
2297 | return [str.slice(at, str.length), str.slice(0, at)];
|
2298 | }
|
2299 | return [str.slice(0, dist), str.slice(dist)];
|
2300 | };
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 | var isWordCharacter = function isWordCharacter(_char3, remaining) {
|
2306 | var isRTL = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
2307 | if (SPACE.test(_char3)) {
|
2308 | return false;
|
2309 | }
|
2310 |
|
2311 |
|
2312 | if (CHAMELEON.test(_char3)) {
|
2313 | var charDist = getCharacterDistance(remaining, isRTL);
|
2314 | var _splitByCharacterDist3 = splitByCharacterDistance(remaining, charDist, isRTL),
|
2315 | _splitByCharacterDist4 = _slicedToArray(_splitByCharacterDist3, 2),
|
2316 | nextChar = _splitByCharacterDist4[0],
|
2317 | nextRemaining = _splitByCharacterDist4[1];
|
2318 | if (isWordCharacter(nextChar, nextRemaining, isRTL)) {
|
2319 | return true;
|
2320 | }
|
2321 | }
|
2322 | if (PUNCTUATION.test(_char3)) {
|
2323 | return false;
|
2324 | }
|
2325 | return true;
|
2326 | };
|
2327 |
|
2328 |
|
2329 |
|
2330 | var codepointsIteratorRTL = function* codepointsIteratorRTL(str) {
|
2331 | var end = str.length - 1;
|
2332 | for (var i = 0; i < str.length; i++) {
|
2333 | var char1 = str.charAt(end - i);
|
2334 | if (isLowSurrogate(char1.charCodeAt(0))) {
|
2335 | var char2 = str.charAt(end - i - 1);
|
2336 | if (isHighSurrogate(char2.charCodeAt(0))) {
|
2337 | yield char2 + char1;
|
2338 | i++;
|
2339 | continue;
|
2340 | }
|
2341 | }
|
2342 | yield char1;
|
2343 | }
|
2344 | };
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 |
|
2350 | var isHighSurrogate = function isHighSurrogate(charCode) {
|
2351 | return charCode >= 0xd800 && charCode <= 0xdbff;
|
2352 | };
|
2353 |
|
2354 |
|
2355 |
|
2356 |
|
2357 |
|
2358 | var isLowSurrogate = function isLowSurrogate(charCode) {
|
2359 | return charCode >= 0xdc00 && charCode <= 0xdfff;
|
2360 | };
|
2361 | var CodepointType;
|
2362 | (function (CodepointType) {
|
2363 | CodepointType[CodepointType["None"] = 0] = "None";
|
2364 | CodepointType[CodepointType["Extend"] = 1] = "Extend";
|
2365 | CodepointType[CodepointType["ZWJ"] = 2] = "ZWJ";
|
2366 | CodepointType[CodepointType["RI"] = 4] = "RI";
|
2367 | CodepointType[CodepointType["Prepend"] = 8] = "Prepend";
|
2368 | CodepointType[CodepointType["SpacingMark"] = 16] = "SpacingMark";
|
2369 | CodepointType[CodepointType["L"] = 32] = "L";
|
2370 | CodepointType[CodepointType["V"] = 64] = "V";
|
2371 | CodepointType[CodepointType["T"] = 128] = "T";
|
2372 | CodepointType[CodepointType["LV"] = 256] = "LV";
|
2373 | CodepointType[CodepointType["LVT"] = 512] = "LVT";
|
2374 | CodepointType[CodepointType["ExtPict"] = 1024] = "ExtPict";
|
2375 | CodepointType[CodepointType["Any"] = 2048] = "Any";
|
2376 | })(CodepointType || (CodepointType = {}));
|
2377 | 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])$/;
|
2378 | var rePrepend = /^(?:[\u0600-\u0605\u06DD\u070F\u0890\u0891\u08E2\u0D4E]|\uD804[\uDCBD\uDCCD\uDDC2\uDDC3]|\uD806[\uDD3F\uDD41\uDE3A\uDE84-\uDE89]|\uD807\uDD46)$/;
|
2379 | 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])$/;
|
2380 | var reL = /^[\u1100-\u115F\uA960-\uA97C]$/;
|
2381 | var reV = /^[\u1160-\u11A7\uD7B0-\uD7C6]$/;
|
2382 | var reT = /^[\u11A8-\u11FF\uD7CB-\uD7FB]$/;
|
2383 | 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]$/;
|
2384 | 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]$/;
|
2385 | 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])$/;
|
2386 | var getCodepointType = function getCodepointType(_char4, code) {
|
2387 | var type = CodepointType.Any;
|
2388 | if (_char4.search(reExtend) !== -1) {
|
2389 | type |= CodepointType.Extend;
|
2390 | }
|
2391 | if (code === 0x200d) {
|
2392 | type |= CodepointType.ZWJ;
|
2393 | }
|
2394 | if (code >= 0x1f1e6 && code <= 0x1f1ff) {
|
2395 | type |= CodepointType.RI;
|
2396 | }
|
2397 | if (_char4.search(rePrepend) !== -1) {
|
2398 | type |= CodepointType.Prepend;
|
2399 | }
|
2400 | if (_char4.search(reSpacingMark) !== -1) {
|
2401 | type |= CodepointType.SpacingMark;
|
2402 | }
|
2403 | if (_char4.search(reL) !== -1) {
|
2404 | type |= CodepointType.L;
|
2405 | }
|
2406 | if (_char4.search(reV) !== -1) {
|
2407 | type |= CodepointType.V;
|
2408 | }
|
2409 | if (_char4.search(reT) !== -1) {
|
2410 | type |= CodepointType.T;
|
2411 | }
|
2412 | if (_char4.search(reLV) !== -1) {
|
2413 | type |= CodepointType.LV;
|
2414 | }
|
2415 | if (_char4.search(reLVT) !== -1) {
|
2416 | type |= CodepointType.LVT;
|
2417 | }
|
2418 | if (_char4.search(reExtPict) !== -1) {
|
2419 | type |= CodepointType.ExtPict;
|
2420 | }
|
2421 | return type;
|
2422 | };
|
2423 | function intersects(x, y) {
|
2424 | return (x & y) !== 0;
|
2425 | }
|
2426 | var NonBoundaryPairs = [
|
2427 |
|
2428 | [CodepointType.L, CodepointType.L | CodepointType.V | CodepointType.LV | CodepointType.LVT],
|
2429 |
|
2430 | [CodepointType.LV | CodepointType.V, CodepointType.V | CodepointType.T],
|
2431 |
|
2432 | [CodepointType.LVT | CodepointType.T, CodepointType.T],
|
2433 |
|
2434 | [CodepointType.Any, CodepointType.Extend | CodepointType.ZWJ],
|
2435 |
|
2436 | [CodepointType.Any, CodepointType.SpacingMark],
|
2437 |
|
2438 | [CodepointType.Prepend, CodepointType.Any],
|
2439 |
|
2440 | [CodepointType.ZWJ, CodepointType.ExtPict],
|
2441 |
|
2442 | [CodepointType.RI, CodepointType.RI]];
|
2443 | function isBoundaryPair(left, right) {
|
2444 | return NonBoundaryPairs.findIndex(function (r) {
|
2445 | return intersects(left, r[0]) && intersects(right, r[1]);
|
2446 | }) === -1;
|
2447 | }
|
2448 | 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$/;
|
2449 | var endsWithEmojiZWJ = function endsWithEmojiZWJ(str) {
|
2450 | return str.search(endingEmojiZWJ) !== -1;
|
2451 | };
|
2452 | var endingRIs = /(?:\uD83C[\uDDE6-\uDDFF])+$/g;
|
2453 | var endsWithOddNumberOfRIs = function endsWithOddNumberOfRIs(str) {
|
2454 | var match = str.match(endingRIs);
|
2455 | if (match === null) {
|
2456 | return false;
|
2457 | } else {
|
2458 |
|
2459 | var numRIs = match[0].length / 2;
|
2460 | return numRIs % 2 === 1;
|
2461 | }
|
2462 | };
|
2463 |
|
2464 |
|
2465 | var TextTransforms = {
|
2466 | "delete": function _delete(editor, options) {
|
2467 | editor["delete"](options);
|
2468 | },
|
2469 | insertFragment: function insertFragment(editor, fragment, options) {
|
2470 | editor.insertFragment(fragment, options);
|
2471 | },
|
2472 | insertText: function insertText(editor, text) {
|
2473 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
2474 | Editor.withoutNormalizing(editor, function () {
|
2475 | var _options$voids = options.voids,
|
2476 | voids = _options$voids === void 0 ? false : _options$voids;
|
2477 | var _options$at = options.at,
|
2478 | at = _options$at === void 0 ? getDefaultInsertLocation(editor) : _options$at;
|
2479 | if (Path.isPath(at)) {
|
2480 | at = Editor.range(editor, at);
|
2481 | }
|
2482 | if (Range.isRange(at)) {
|
2483 | if (Range.isCollapsed(at)) {
|
2484 | at = at.anchor;
|
2485 | } else {
|
2486 | var end = Range.end(at);
|
2487 | if (!voids && Editor["void"](editor, {
|
2488 | at: end
|
2489 | })) {
|
2490 | return;
|
2491 | }
|
2492 | var start = Range.start(at);
|
2493 | var startRef = Editor.pointRef(editor, start);
|
2494 | var endRef = Editor.pointRef(editor, end);
|
2495 | Transforms["delete"](editor, {
|
2496 | at: at,
|
2497 | voids: voids
|
2498 | });
|
2499 | var startPoint = startRef.unref();
|
2500 | var endPoint = endRef.unref();
|
2501 | at = startPoint || endPoint;
|
2502 | Transforms.setSelection(editor, {
|
2503 | anchor: at,
|
2504 | focus: at
|
2505 | });
|
2506 | }
|
2507 | }
|
2508 | if (!voids && Editor["void"](editor, {
|
2509 | at: at
|
2510 | }) || Editor.elementReadOnly(editor, {
|
2511 | at: at
|
2512 | })) {
|
2513 | return;
|
2514 | }
|
2515 | var _at = at,
|
2516 | path = _at.path,
|
2517 | offset = _at.offset;
|
2518 | if (text.length > 0) editor.apply({
|
2519 | type: 'insert_text',
|
2520 | path: path,
|
2521 | offset: offset,
|
2522 | text: text
|
2523 | });
|
2524 | });
|
2525 | }
|
2526 | };
|
2527 |
|
2528 | 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; }
|
2529 | 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; }
|
2530 | var Transforms = _objectSpread$9(_objectSpread$9(_objectSpread$9(_objectSpread$9({}, GeneralTransforms), NodeTransforms), SelectionTransforms), TextTransforms);
|
2531 |
|
2532 |
|
2533 | var BATCHING_DIRTY_PATHS = new WeakMap();
|
2534 | var isBatchingDirtyPaths = function isBatchingDirtyPaths(editor) {
|
2535 | return BATCHING_DIRTY_PATHS.get(editor) || false;
|
2536 | };
|
2537 | var batchDirtyPaths = function batchDirtyPaths(editor, fn, update) {
|
2538 | var value = BATCHING_DIRTY_PATHS.get(editor) || false;
|
2539 | BATCHING_DIRTY_PATHS.set(editor, true);
|
2540 | try {
|
2541 | fn();
|
2542 | update();
|
2543 | } finally {
|
2544 | BATCHING_DIRTY_PATHS.set(editor, value);
|
2545 | }
|
2546 | };
|
2547 |
|
2548 | 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; } } }; }
|
2549 | 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); }
|
2550 | 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; }
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 | function updateDirtyPaths(editor, newDirtyPaths, transform) {
|
2558 | var oldDirtyPaths = DIRTY_PATHS.get(editor) || [];
|
2559 | var oldDirtyPathKeys = DIRTY_PATH_KEYS.get(editor) || new Set();
|
2560 | var dirtyPaths;
|
2561 | var dirtyPathKeys;
|
2562 | var add = function add(path) {
|
2563 | if (path) {
|
2564 | var key = path.join(',');
|
2565 | if (!dirtyPathKeys.has(key)) {
|
2566 | dirtyPathKeys.add(key);
|
2567 | dirtyPaths.push(path);
|
2568 | }
|
2569 | }
|
2570 | };
|
2571 | if (transform) {
|
2572 | dirtyPaths = [];
|
2573 | dirtyPathKeys = new Set();
|
2574 | var _iterator = _createForOfIteratorHelper$i(oldDirtyPaths),
|
2575 | _step;
|
2576 | try {
|
2577 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2578 | var path = _step.value;
|
2579 | var newPath = transform(path);
|
2580 | add(newPath);
|
2581 | }
|
2582 | } catch (err) {
|
2583 | _iterator.e(err);
|
2584 | } finally {
|
2585 | _iterator.f();
|
2586 | }
|
2587 | } else {
|
2588 | dirtyPaths = oldDirtyPaths;
|
2589 | dirtyPathKeys = oldDirtyPathKeys;
|
2590 | }
|
2591 | var _iterator2 = _createForOfIteratorHelper$i(newDirtyPaths),
|
2592 | _step2;
|
2593 | try {
|
2594 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
2595 | var _path = _step2.value;
|
2596 | add(_path);
|
2597 | }
|
2598 | } catch (err) {
|
2599 | _iterator2.e(err);
|
2600 | } finally {
|
2601 | _iterator2.f();
|
2602 | }
|
2603 | DIRTY_PATHS.set(editor, dirtyPaths);
|
2604 | DIRTY_PATH_KEYS.set(editor, dirtyPathKeys);
|
2605 | }
|
2606 |
|
2607 | 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; } } }; }
|
2608 | 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); }
|
2609 | 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; }
|
2610 | var apply = function apply(editor, op) {
|
2611 | var _iterator = _createForOfIteratorHelper$h(Editor.pathRefs(editor)),
|
2612 | _step;
|
2613 | try {
|
2614 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2615 | var ref = _step.value;
|
2616 | PathRef.transform(ref, op);
|
2617 | }
|
2618 | } catch (err) {
|
2619 | _iterator.e(err);
|
2620 | } finally {
|
2621 | _iterator.f();
|
2622 | }
|
2623 | var _iterator2 = _createForOfIteratorHelper$h(Editor.pointRefs(editor)),
|
2624 | _step2;
|
2625 | try {
|
2626 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
2627 | var _ref = _step2.value;
|
2628 | PointRef.transform(_ref, op);
|
2629 | }
|
2630 | } catch (err) {
|
2631 | _iterator2.e(err);
|
2632 | } finally {
|
2633 | _iterator2.f();
|
2634 | }
|
2635 | var _iterator3 = _createForOfIteratorHelper$h(Editor.rangeRefs(editor)),
|
2636 | _step3;
|
2637 | try {
|
2638 | for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
2639 | var _ref2 = _step3.value;
|
2640 | RangeRef.transform(_ref2, op);
|
2641 | }
|
2642 |
|
2643 | } catch (err) {
|
2644 | _iterator3.e(err);
|
2645 | } finally {
|
2646 | _iterator3.f();
|
2647 | }
|
2648 | if (!isBatchingDirtyPaths(editor)) {
|
2649 | var transform = Path.operationCanTransformPath(op) ? function (p) {
|
2650 | return Path.transform(p, op);
|
2651 | } : undefined;
|
2652 | updateDirtyPaths(editor, editor.getDirtyPaths(op), transform);
|
2653 | }
|
2654 | Transforms.transform(editor, op);
|
2655 | editor.operations.push(op);
|
2656 | Editor.normalize(editor, {
|
2657 | operation: op
|
2658 | });
|
2659 |
|
2660 | if (op.type === 'set_selection') {
|
2661 | editor.marks = null;
|
2662 | }
|
2663 | if (!FLUSHING.get(editor)) {
|
2664 | FLUSHING.set(editor, true);
|
2665 | Promise.resolve().then(function () {
|
2666 | FLUSHING.set(editor, false);
|
2667 | editor.onChange({
|
2668 | operation: op
|
2669 | });
|
2670 | editor.operations = [];
|
2671 | });
|
2672 | }
|
2673 | };
|
2674 |
|
2675 | 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; } } }; }
|
2676 | 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); }
|
2677 | 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; }
|
2678 |
|
2679 |
|
2680 |
|
2681 | var getDirtyPaths = function getDirtyPaths(editor, op) {
|
2682 | switch (op.type) {
|
2683 | case 'insert_text':
|
2684 | case 'remove_text':
|
2685 | case 'set_node':
|
2686 | {
|
2687 | var path = op.path;
|
2688 | return Path.levels(path);
|
2689 | }
|
2690 | case 'insert_node':
|
2691 | {
|
2692 | var node = op.node,
|
2693 | _path = op.path;
|
2694 | var levels = Path.levels(_path);
|
2695 | var descendants = Text.isText(node) ? [] : Array.from(Node.nodes(node), function (_ref) {
|
2696 | var _ref2 = _slicedToArray(_ref, 2),
|
2697 | p = _ref2[1];
|
2698 | return _path.concat(p);
|
2699 | });
|
2700 | return [].concat(_toConsumableArray(levels), _toConsumableArray(descendants));
|
2701 | }
|
2702 | case 'merge_node':
|
2703 | {
|
2704 | var _path2 = op.path;
|
2705 | var ancestors = Path.ancestors(_path2);
|
2706 | var previousPath = Path.previous(_path2);
|
2707 | return [].concat(_toConsumableArray(ancestors), [previousPath]);
|
2708 | }
|
2709 | case 'move_node':
|
2710 | {
|
2711 | var _path3 = op.path,
|
2712 | newPath = op.newPath;
|
2713 | if (Path.equals(_path3, newPath)) {
|
2714 | return [];
|
2715 | }
|
2716 | var oldAncestors = [];
|
2717 | var newAncestors = [];
|
2718 | var _iterator = _createForOfIteratorHelper$g(Path.ancestors(_path3)),
|
2719 | _step;
|
2720 | try {
|
2721 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2722 | var ancestor = _step.value;
|
2723 | var p = Path.transform(ancestor, op);
|
2724 | oldAncestors.push(p);
|
2725 | }
|
2726 | } catch (err) {
|
2727 | _iterator.e(err);
|
2728 | } finally {
|
2729 | _iterator.f();
|
2730 | }
|
2731 | var _iterator2 = _createForOfIteratorHelper$g(Path.ancestors(newPath)),
|
2732 | _step2;
|
2733 | try {
|
2734 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
2735 | var _ancestor = _step2.value;
|
2736 | var _p = Path.transform(_ancestor, op);
|
2737 | newAncestors.push(_p);
|
2738 | }
|
2739 | } catch (err) {
|
2740 | _iterator2.e(err);
|
2741 | } finally {
|
2742 | _iterator2.f();
|
2743 | }
|
2744 | var newParent = newAncestors[newAncestors.length - 1];
|
2745 | var newIndex = newPath[newPath.length - 1];
|
2746 | var resultPath = newParent.concat(newIndex);
|
2747 | return [].concat(oldAncestors, newAncestors, [resultPath]);
|
2748 | }
|
2749 | case 'remove_node':
|
2750 | {
|
2751 | var _path4 = op.path;
|
2752 | var _ancestors = Path.ancestors(_path4);
|
2753 | return _toConsumableArray(_ancestors);
|
2754 | }
|
2755 | case 'split_node':
|
2756 | {
|
2757 | var _path5 = op.path;
|
2758 | var _levels = Path.levels(_path5);
|
2759 | var nextPath = Path.next(_path5);
|
2760 | return [].concat(_toConsumableArray(_levels), [nextPath]);
|
2761 | }
|
2762 | default:
|
2763 | {
|
2764 | return [];
|
2765 | }
|
2766 | }
|
2767 | };
|
2768 |
|
2769 | var getFragment = function getFragment(editor) {
|
2770 | var selection = editor.selection;
|
2771 | if (selection) {
|
2772 | return Node.fragment(editor, selection);
|
2773 | }
|
2774 | return [];
|
2775 | };
|
2776 |
|
2777 | var normalizeNode = function normalizeNode(editor, entry) {
|
2778 | var _entry = _slicedToArray(entry, 2),
|
2779 | node = _entry[0],
|
2780 | path = _entry[1];
|
2781 |
|
2782 | if (Text.isText(node)) {
|
2783 | return;
|
2784 | }
|
2785 |
|
2786 | if (Element.isElement(node) && node.children.length === 0) {
|
2787 | var child = {
|
2788 | text: ''
|
2789 | };
|
2790 | Transforms.insertNodes(editor, child, {
|
2791 | at: path.concat(0),
|
2792 | voids: true
|
2793 | });
|
2794 | return;
|
2795 | }
|
2796 |
|
2797 | 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]));
|
2798 |
|
2799 |
|
2800 | var n = 0;
|
2801 | for (var i = 0; i < node.children.length; i++, n++) {
|
2802 | var currentNode = Node.get(editor, path);
|
2803 | if (Text.isText(currentNode)) continue;
|
2804 | var _child = currentNode.children[n];
|
2805 | var prev = currentNode.children[n - 1];
|
2806 | var isLast = i === node.children.length - 1;
|
2807 | var isInlineOrText = Text.isText(_child) || Element.isElement(_child) && editor.isInline(_child);
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 | if (isInlineOrText !== shouldHaveInlines) {
|
2813 | Transforms.removeNodes(editor, {
|
2814 | at: path.concat(n),
|
2815 | voids: true
|
2816 | });
|
2817 | n--;
|
2818 | } else if (Element.isElement(_child)) {
|
2819 |
|
2820 | if (editor.isInline(_child)) {
|
2821 | if (prev == null || !Text.isText(prev)) {
|
2822 | var newChild = {
|
2823 | text: ''
|
2824 | };
|
2825 | Transforms.insertNodes(editor, newChild, {
|
2826 | at: path.concat(n),
|
2827 | voids: true
|
2828 | });
|
2829 | n++;
|
2830 | } else if (isLast) {
|
2831 | var _newChild = {
|
2832 | text: ''
|
2833 | };
|
2834 | Transforms.insertNodes(editor, _newChild, {
|
2835 | at: path.concat(n + 1),
|
2836 | voids: true
|
2837 | });
|
2838 | n++;
|
2839 | }
|
2840 | }
|
2841 | } else {
|
2842 |
|
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 | if (!Text.isText(_child) && !('children' in _child)) {
|
2851 | var elementChild = _child;
|
2852 | elementChild.children = [];
|
2853 | }
|
2854 |
|
2855 | if (prev != null && Text.isText(prev)) {
|
2856 | if (Text.equals(_child, prev, {
|
2857 | loose: true
|
2858 | })) {
|
2859 | Transforms.mergeNodes(editor, {
|
2860 | at: path.concat(n),
|
2861 | voids: true
|
2862 | });
|
2863 | n--;
|
2864 | } else if (prev.text === '') {
|
2865 | Transforms.removeNodes(editor, {
|
2866 | at: path.concat(n - 1),
|
2867 | voids: true
|
2868 | });
|
2869 | n--;
|
2870 | } else if (_child.text === '') {
|
2871 | Transforms.removeNodes(editor, {
|
2872 | at: path.concat(n),
|
2873 | voids: true
|
2874 | });
|
2875 | n--;
|
2876 | }
|
2877 | }
|
2878 | }
|
2879 | }
|
2880 | };
|
2881 |
|
2882 | var shouldNormalize = function shouldNormalize(editor, _ref) {
|
2883 | var iteration = _ref.iteration,
|
2884 | initialDirtyPathsLength = _ref.initialDirtyPathsLength;
|
2885 | var maxIterations = initialDirtyPathsLength * 42;
|
2886 | if (iteration > maxIterations) {
|
2887 | 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."));
|
2888 | }
|
2889 | return true;
|
2890 | };
|
2891 |
|
2892 | 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; } } }; }
|
2893 | 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); }
|
2894 | 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; }
|
2895 | var above = function above(editor) {
|
2896 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
2897 | var _options$voids = options.voids,
|
2898 | voids = _options$voids === void 0 ? false : _options$voids,
|
2899 | _options$mode = options.mode,
|
2900 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
2901 | _options$at = options.at,
|
2902 | at = _options$at === void 0 ? editor.selection : _options$at,
|
2903 | match = options.match;
|
2904 | if (!at) {
|
2905 | return;
|
2906 | }
|
2907 | var path = Editor.path(editor, at);
|
2908 | var reverse = mode === 'lowest';
|
2909 | var _iterator = _createForOfIteratorHelper$f(Editor.levels(editor, {
|
2910 | at: path,
|
2911 | voids: voids,
|
2912 | match: match,
|
2913 | reverse: reverse
|
2914 | })),
|
2915 | _step;
|
2916 | try {
|
2917 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2918 | var _step$value = _slicedToArray(_step.value, 2),
|
2919 | n = _step$value[0],
|
2920 | p = _step$value[1];
|
2921 | if (Text.isText(n)) continue;
|
2922 | if (Range.isRange(at)) {
|
2923 | if (Path.isAncestor(p, at.anchor.path) && Path.isAncestor(p, at.focus.path)) {
|
2924 | return [n, p];
|
2925 | }
|
2926 | } else {
|
2927 | if (!Path.equals(path, p)) {
|
2928 | return [n, p];
|
2929 | }
|
2930 | }
|
2931 | }
|
2932 | } catch (err) {
|
2933 | _iterator.e(err);
|
2934 | } finally {
|
2935 | _iterator.f();
|
2936 | }
|
2937 | };
|
2938 |
|
2939 | 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; }
|
2940 | 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; }
|
2941 | var addMark = function addMark(editor, key, value) {
|
2942 | var selection = editor.selection;
|
2943 | if (selection) {
|
2944 | var match = function match(node, path) {
|
2945 | if (!Text.isText(node)) {
|
2946 | return false;
|
2947 | }
|
2948 |
|
2949 | var _Editor$parent = Editor.parent(editor, path),
|
2950 | _Editor$parent2 = _slicedToArray(_Editor$parent, 2),
|
2951 | parentNode = _Editor$parent2[0];
|
2952 | _Editor$parent2[1];
|
2953 | return !editor.isVoid(parentNode) || editor.markableVoid(parentNode);
|
2954 | };
|
2955 | var expandedSelection = Range.isExpanded(selection);
|
2956 | var markAcceptingVoidSelected = false;
|
2957 | if (!expandedSelection) {
|
2958 | var _Editor$node = Editor.node(editor, selection),
|
2959 | _Editor$node2 = _slicedToArray(_Editor$node, 2),
|
2960 | selectedNode = _Editor$node2[0],
|
2961 | selectedPath = _Editor$node2[1];
|
2962 | if (selectedNode && match(selectedNode, selectedPath)) {
|
2963 | var _Editor$parent3 = Editor.parent(editor, selectedPath),
|
2964 | _Editor$parent4 = _slicedToArray(_Editor$parent3, 1),
|
2965 | parentNode = _Editor$parent4[0];
|
2966 | markAcceptingVoidSelected = parentNode && editor.markableVoid(parentNode);
|
2967 | }
|
2968 | }
|
2969 | if (expandedSelection || markAcceptingVoidSelected) {
|
2970 | Transforms.setNodes(editor, _defineProperty({}, key, value), {
|
2971 | match: match,
|
2972 | split: true,
|
2973 | voids: true
|
2974 | });
|
2975 | } else {
|
2976 | var marks = _objectSpread$8(_objectSpread$8({}, Editor.marks(editor) || {}), {}, _defineProperty({}, key, value));
|
2977 | editor.marks = marks;
|
2978 | if (!FLUSHING.get(editor)) {
|
2979 | editor.onChange();
|
2980 | }
|
2981 | }
|
2982 | }
|
2983 | };
|
2984 |
|
2985 | 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; }
|
2986 | 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; }
|
2987 | 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; } } }; }
|
2988 | 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); }
|
2989 | 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; }
|
2990 | var after = function after(editor, at) {
|
2991 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
2992 | var anchor = Editor.point(editor, at, {
|
2993 | edge: 'end'
|
2994 | });
|
2995 | var focus = Editor.end(editor, []);
|
2996 | var range = {
|
2997 | anchor: anchor,
|
2998 | focus: focus
|
2999 | };
|
3000 | var _options$distance = options.distance,
|
3001 | distance = _options$distance === void 0 ? 1 : _options$distance;
|
3002 | var d = 0;
|
3003 | var target;
|
3004 | var _iterator = _createForOfIteratorHelper$e(Editor.positions(editor, _objectSpread$7(_objectSpread$7({}, options), {}, {
|
3005 | at: range
|
3006 | }))),
|
3007 | _step;
|
3008 | try {
|
3009 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
3010 | var p = _step.value;
|
3011 | if (d > distance) {
|
3012 | break;
|
3013 | }
|
3014 | if (d !== 0) {
|
3015 | target = p;
|
3016 | }
|
3017 | d++;
|
3018 | }
|
3019 | } catch (err) {
|
3020 | _iterator.e(err);
|
3021 | } finally {
|
3022 | _iterator.f();
|
3023 | }
|
3024 | return target;
|
3025 | };
|
3026 |
|
3027 | 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; }
|
3028 | 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; }
|
3029 | 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; } } }; }
|
3030 | 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); }
|
3031 | 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; }
|
3032 | var before = function before(editor, at) {
|
3033 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3034 | var anchor = Editor.start(editor, []);
|
3035 | var focus = Editor.point(editor, at, {
|
3036 | edge: 'start'
|
3037 | });
|
3038 | var range = {
|
3039 | anchor: anchor,
|
3040 | focus: focus
|
3041 | };
|
3042 | var _options$distance = options.distance,
|
3043 | distance = _options$distance === void 0 ? 1 : _options$distance;
|
3044 | var d = 0;
|
3045 | var target;
|
3046 | var _iterator = _createForOfIteratorHelper$d(Editor.positions(editor, _objectSpread$6(_objectSpread$6({}, options), {}, {
|
3047 | at: range,
|
3048 | reverse: true
|
3049 | }))),
|
3050 | _step;
|
3051 | try {
|
3052 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
3053 | var p = _step.value;
|
3054 | if (d > distance) {
|
3055 | break;
|
3056 | }
|
3057 | if (d !== 0) {
|
3058 | target = p;
|
3059 | }
|
3060 | d++;
|
3061 | }
|
3062 | } catch (err) {
|
3063 | _iterator.e(err);
|
3064 | } finally {
|
3065 | _iterator.f();
|
3066 | }
|
3067 | return target;
|
3068 | };
|
3069 |
|
3070 | var deleteBackward = function deleteBackward(editor, unit) {
|
3071 | var selection = editor.selection;
|
3072 | if (selection && Range.isCollapsed(selection)) {
|
3073 | Transforms["delete"](editor, {
|
3074 | unit: unit,
|
3075 | reverse: true
|
3076 | });
|
3077 | }
|
3078 | };
|
3079 |
|
3080 | var deleteForward = function deleteForward(editor, unit) {
|
3081 | var selection = editor.selection;
|
3082 | if (selection && Range.isCollapsed(selection)) {
|
3083 | Transforms["delete"](editor, {
|
3084 | unit: unit
|
3085 | });
|
3086 | }
|
3087 | };
|
3088 |
|
3089 | var deleteFragment = function deleteFragment(editor) {
|
3090 | var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
3091 | _ref$direction = _ref.direction,
|
3092 | direction = _ref$direction === void 0 ? 'forward' : _ref$direction;
|
3093 | var selection = editor.selection;
|
3094 | if (selection && Range.isExpanded(selection)) {
|
3095 | Transforms["delete"](editor, {
|
3096 | reverse: direction === 'backward'
|
3097 | });
|
3098 | }
|
3099 | };
|
3100 |
|
3101 | var edges = function edges(editor, at) {
|
3102 | return [Editor.start(editor, at), Editor.end(editor, at)];
|
3103 | };
|
3104 |
|
3105 | 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; }
|
3106 | 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; }
|
3107 | var elementReadOnly = function elementReadOnly(editor) {
|
3108 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3109 | return Editor.above(editor, _objectSpread$5(_objectSpread$5({}, options), {}, {
|
3110 | match: function match(n) {
|
3111 | return Element.isElement(n) && Editor.isElementReadOnly(editor, n);
|
3112 | }
|
3113 | }));
|
3114 | };
|
3115 |
|
3116 | var end = function end(editor, at) {
|
3117 | return Editor.point(editor, at, {
|
3118 | edge: 'end'
|
3119 | });
|
3120 | };
|
3121 |
|
3122 | var first = function first(editor, at) {
|
3123 | var path = Editor.path(editor, at, {
|
3124 | edge: 'start'
|
3125 | });
|
3126 | return Editor.node(editor, path);
|
3127 | };
|
3128 |
|
3129 | var fragment = function fragment(editor, at) {
|
3130 | var range = Editor.range(editor, at);
|
3131 | return Node.fragment(editor, range);
|
3132 | };
|
3133 |
|
3134 | 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; }
|
3135 | 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; }
|
3136 | var getVoid = function getVoid(editor) {
|
3137 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3138 | return Editor.above(editor, _objectSpread$4(_objectSpread$4({}, options), {}, {
|
3139 | match: function match(n) {
|
3140 | return Element.isElement(n) && Editor.isVoid(editor, n);
|
3141 | }
|
3142 | }));
|
3143 | };
|
3144 |
|
3145 | var hasBlocks = function hasBlocks(editor, element) {
|
3146 | return element.children.some(function (n) {
|
3147 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
3148 | });
|
3149 | };
|
3150 |
|
3151 | var hasInlines = function hasInlines(editor, element) {
|
3152 | return element.children.some(function (n) {
|
3153 | return Text.isText(n) || Editor.isInline(editor, n);
|
3154 | });
|
3155 | };
|
3156 |
|
3157 | var hasPath = function hasPath(editor, path) {
|
3158 | return Node.has(editor, path);
|
3159 | };
|
3160 |
|
3161 | var hasTexts = function hasTexts(editor, element) {
|
3162 | return element.children.every(function (n) {
|
3163 | return Text.isText(n);
|
3164 | });
|
3165 | };
|
3166 |
|
3167 | var insertBreak = function insertBreak(editor) {
|
3168 | Transforms.splitNodes(editor, {
|
3169 | always: true
|
3170 | });
|
3171 | };
|
3172 |
|
3173 | var insertNode = function insertNode(editor, node, options) {
|
3174 | Transforms.insertNodes(editor, node, options);
|
3175 | };
|
3176 |
|
3177 | var insertSoftBreak = function insertSoftBreak(editor) {
|
3178 | Transforms.splitNodes(editor, {
|
3179 | always: true
|
3180 | });
|
3181 | };
|
3182 |
|
3183 | 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; }
|
3184 | 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; }
|
3185 | var insertText = function insertText(editor, text) {
|
3186 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3187 | var selection = editor.selection,
|
3188 | marks = editor.marks;
|
3189 | if (selection) {
|
3190 | if (marks) {
|
3191 | var node = _objectSpread$3({
|
3192 | text: text
|
3193 | }, marks);
|
3194 | Transforms.insertNodes(editor, node, {
|
3195 | at: options.at,
|
3196 | voids: options.voids
|
3197 | });
|
3198 | } else {
|
3199 | Transforms.insertText(editor, text, options);
|
3200 | }
|
3201 | editor.marks = null;
|
3202 | }
|
3203 | };
|
3204 |
|
3205 | var isBlock = function isBlock(editor, value) {
|
3206 | return !editor.isInline(value);
|
3207 | };
|
3208 |
|
3209 | var isEdge = function isEdge(editor, point, at) {
|
3210 | return Editor.isStart(editor, point, at) || Editor.isEnd(editor, point, at);
|
3211 | };
|
3212 |
|
3213 | var isEmpty = function isEmpty(editor, element) {
|
3214 | var children = element.children;
|
3215 | var _children = _slicedToArray(children, 1),
|
3216 | first = _children[0];
|
3217 | return children.length === 0 || children.length === 1 && Text.isText(first) && first.text === '' && !editor.isVoid(element);
|
3218 | };
|
3219 |
|
3220 | var isEnd = function isEnd(editor, point, at) {
|
3221 | var end = Editor.end(editor, at);
|
3222 | return Point.equals(point, end);
|
3223 | };
|
3224 |
|
3225 | var isNormalizing = function isNormalizing(editor) {
|
3226 | var isNormalizing = NORMALIZING.get(editor);
|
3227 | return isNormalizing === undefined ? true : isNormalizing;
|
3228 | };
|
3229 |
|
3230 | var isStart = function isStart(editor, point, at) {
|
3231 |
|
3232 | if (point.offset !== 0) {
|
3233 | return false;
|
3234 | }
|
3235 | var start = Editor.start(editor, at);
|
3236 | return Point.equals(point, start);
|
3237 | };
|
3238 |
|
3239 | var last = function last(editor, at) {
|
3240 | var path = Editor.path(editor, at, {
|
3241 | edge: 'end'
|
3242 | });
|
3243 | return Editor.node(editor, path);
|
3244 | };
|
3245 |
|
3246 | var leaf = function leaf(editor, at) {
|
3247 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3248 | var path = Editor.path(editor, at, options);
|
3249 | var node = Node.leaf(editor, path);
|
3250 | return [node, path];
|
3251 | };
|
3252 |
|
3253 | 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; } } }; }
|
3254 | 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); }
|
3255 | 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; }
|
3256 | function levels(editor) {
|
3257 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3258 | return function* () {
|
3259 | var _options$at = options.at,
|
3260 | at = _options$at === void 0 ? editor.selection : _options$at,
|
3261 | _options$reverse = options.reverse,
|
3262 | reverse = _options$reverse === void 0 ? false : _options$reverse,
|
3263 | _options$voids = options.voids,
|
3264 | voids = _options$voids === void 0 ? false : _options$voids;
|
3265 | var match = options.match;
|
3266 | if (match == null) {
|
3267 | match = function match() {
|
3268 | return true;
|
3269 | };
|
3270 | }
|
3271 | if (!at) {
|
3272 | return;
|
3273 | }
|
3274 | var levels = [];
|
3275 | var path = Editor.path(editor, at);
|
3276 | var _iterator = _createForOfIteratorHelper$c(Node.levels(editor, path)),
|
3277 | _step;
|
3278 | try {
|
3279 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
3280 | var _step$value = _slicedToArray(_step.value, 2),
|
3281 | n = _step$value[0],
|
3282 | p = _step$value[1];
|
3283 | if (!match(n, p)) {
|
3284 | continue;
|
3285 | }
|
3286 | levels.push([n, p]);
|
3287 | if (!voids && Element.isElement(n) && Editor.isVoid(editor, n)) {
|
3288 | break;
|
3289 | }
|
3290 | }
|
3291 | } catch (err) {
|
3292 | _iterator.e(err);
|
3293 | } finally {
|
3294 | _iterator.f();
|
3295 | }
|
3296 | if (reverse) {
|
3297 | levels.reverse();
|
3298 | }
|
3299 | yield* levels;
|
3300 | }();
|
3301 | }
|
3302 |
|
3303 | var _excluded$1 = ["text"],
|
3304 | _excluded2$1 = ["text"];
|
3305 | var marks = function marks(editor) {
|
3306 | var marks = editor.marks,
|
3307 | selection = editor.selection;
|
3308 | if (!selection) {
|
3309 | return null;
|
3310 | }
|
3311 | var anchor = selection.anchor,
|
3312 | focus = selection.focus;
|
3313 | if (marks) {
|
3314 | return marks;
|
3315 | }
|
3316 | if (Range.isExpanded(selection)) {
|
3317 | |
3318 |
|
3319 |
|
3320 |
|
3321 | var isEnd = Editor.isEnd(editor, anchor, anchor.path);
|
3322 | if (isEnd) {
|
3323 | var after = Editor.after(editor, anchor);
|
3324 | if (after) {
|
3325 | anchor = after;
|
3326 | }
|
3327 | }
|
3328 | var _Editor$nodes = Editor.nodes(editor, {
|
3329 | match: Text.isText,
|
3330 | at: {
|
3331 | anchor: anchor,
|
3332 | focus: focus
|
3333 | }
|
3334 | }),
|
3335 | _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
3336 | match = _Editor$nodes2[0];
|
3337 | if (match) {
|
3338 | var _match = _slicedToArray(match, 1),
|
3339 | _node = _match[0];
|
3340 | _node.text;
|
3341 | var _rest = _objectWithoutProperties(_node, _excluded$1);
|
3342 | return _rest;
|
3343 | } else {
|
3344 | return {};
|
3345 | }
|
3346 | }
|
3347 | var _anchor = anchor,
|
3348 | path = _anchor.path;
|
3349 | var _Editor$leaf = Editor.leaf(editor, path),
|
3350 | _Editor$leaf2 = _slicedToArray(_Editor$leaf, 1),
|
3351 | node = _Editor$leaf2[0];
|
3352 | if (anchor.offset === 0) {
|
3353 | var prev = Editor.previous(editor, {
|
3354 | at: path,
|
3355 | match: Text.isText
|
3356 | });
|
3357 | var markedVoid = Editor.above(editor, {
|
3358 | match: function match(n) {
|
3359 | return Element.isElement(n) && Editor.isVoid(editor, n) && editor.markableVoid(n);
|
3360 | }
|
3361 | });
|
3362 | if (!markedVoid) {
|
3363 | var block = Editor.above(editor, {
|
3364 | match: function match(n) {
|
3365 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
3366 | }
|
3367 | });
|
3368 | if (prev && block) {
|
3369 | var _prev = _slicedToArray(prev, 2),
|
3370 | prevNode = _prev[0],
|
3371 | prevPath = _prev[1];
|
3372 | var _block = _slicedToArray(block, 2),
|
3373 | blockPath = _block[1];
|
3374 | if (Path.isAncestor(blockPath, prevPath)) {
|
3375 | node = prevNode;
|
3376 | }
|
3377 | }
|
3378 | }
|
3379 | }
|
3380 | var _node2 = node;
|
3381 | _node2.text;
|
3382 | var rest = _objectWithoutProperties(_node2, _excluded2$1);
|
3383 | return rest;
|
3384 | };
|
3385 |
|
3386 | var next = function next(editor) {
|
3387 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3388 | var _options$mode = options.mode,
|
3389 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
3390 | _options$voids = options.voids,
|
3391 | voids = _options$voids === void 0 ? false : _options$voids;
|
3392 | var match = options.match,
|
3393 | _options$at = options.at,
|
3394 | at = _options$at === void 0 ? editor.selection : _options$at;
|
3395 | if (!at) {
|
3396 | return;
|
3397 | }
|
3398 | var pointAfterLocation = Editor.after(editor, at, {
|
3399 | voids: voids
|
3400 | });
|
3401 | if (!pointAfterLocation) return;
|
3402 | var _Editor$last = Editor.last(editor, []),
|
3403 | _Editor$last2 = _slicedToArray(_Editor$last, 2),
|
3404 | to = _Editor$last2[1];
|
3405 | var span = [pointAfterLocation.path, to];
|
3406 | if (Path.isPath(at) && at.length === 0) {
|
3407 | throw new Error("Cannot get the next node from the root node!");
|
3408 | }
|
3409 | if (match == null) {
|
3410 | if (Path.isPath(at)) {
|
3411 | var _Editor$parent = Editor.parent(editor, at),
|
3412 | _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
|
3413 | parent = _Editor$parent2[0];
|
3414 | match = function match(n) {
|
3415 | return parent.children.includes(n);
|
3416 | };
|
3417 | } else {
|
3418 | match = function match() {
|
3419 | return true;
|
3420 | };
|
3421 | }
|
3422 | }
|
3423 | var _Editor$nodes = Editor.nodes(editor, {
|
3424 | at: span,
|
3425 | match: match,
|
3426 | mode: mode,
|
3427 | voids: voids
|
3428 | }),
|
3429 | _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
3430 | next = _Editor$nodes2[0];
|
3431 | return next;
|
3432 | };
|
3433 |
|
3434 | var node = function node(editor, at) {
|
3435 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3436 | var path = Editor.path(editor, at, options);
|
3437 | var node = Node.get(editor, path);
|
3438 | return [node, path];
|
3439 | };
|
3440 |
|
3441 | 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; } } }; }
|
3442 | 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); }
|
3443 | 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; }
|
3444 | function nodes(editor) {
|
3445 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3446 | return function* () {
|
3447 | var _options$at = options.at,
|
3448 | at = _options$at === void 0 ? editor.selection : _options$at,
|
3449 | _options$mode = options.mode,
|
3450 | mode = _options$mode === void 0 ? 'all' : _options$mode,
|
3451 | _options$universal = options.universal,
|
3452 | universal = _options$universal === void 0 ? false : _options$universal,
|
3453 | _options$reverse = options.reverse,
|
3454 | reverse = _options$reverse === void 0 ? false : _options$reverse,
|
3455 | _options$voids = options.voids,
|
3456 | voids = _options$voids === void 0 ? false : _options$voids,
|
3457 | _options$ignoreNonSel = options.ignoreNonSelectable,
|
3458 | ignoreNonSelectable = _options$ignoreNonSel === void 0 ? false : _options$ignoreNonSel;
|
3459 | var match = options.match;
|
3460 | if (!match) {
|
3461 | match = function match() {
|
3462 | return true;
|
3463 | };
|
3464 | }
|
3465 | if (!at) {
|
3466 | return;
|
3467 | }
|
3468 | var from;
|
3469 | var to;
|
3470 | if (Span.isSpan(at)) {
|
3471 | from = at[0];
|
3472 | to = at[1];
|
3473 | } else {
|
3474 | var first = Editor.path(editor, at, {
|
3475 | edge: 'start'
|
3476 | });
|
3477 | var last = Editor.path(editor, at, {
|
3478 | edge: 'end'
|
3479 | });
|
3480 | from = reverse ? last : first;
|
3481 | to = reverse ? first : last;
|
3482 | }
|
3483 | var nodeEntries = Node.nodes(editor, {
|
3484 | reverse: reverse,
|
3485 | from: from,
|
3486 | to: to,
|
3487 | pass: function pass(_ref) {
|
3488 | var _ref2 = _slicedToArray(_ref, 1),
|
3489 | node = _ref2[0];
|
3490 | if (!Element.isElement(node)) return false;
|
3491 | if (!voids && (Editor.isVoid(editor, node) || Editor.isElementReadOnly(editor, node))) return true;
|
3492 | if (ignoreNonSelectable && !Editor.isSelectable(editor, node)) return true;
|
3493 | return false;
|
3494 | }
|
3495 | });
|
3496 | var matches = [];
|
3497 | var hit;
|
3498 | var _iterator = _createForOfIteratorHelper$b(nodeEntries),
|
3499 | _step;
|
3500 | try {
|
3501 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
3502 | var _step$value = _slicedToArray(_step.value, 2),
|
3503 | node = _step$value[0],
|
3504 | path = _step$value[1];
|
3505 | if (ignoreNonSelectable && Element.isElement(node) && !Editor.isSelectable(editor, node)) {
|
3506 | continue;
|
3507 | }
|
3508 | var isLower = hit && Path.compare(path, hit[1]) === 0;
|
3509 |
|
3510 | if (mode === 'highest' && isLower) {
|
3511 | continue;
|
3512 | }
|
3513 | if (!match(node, path)) {
|
3514 |
|
3515 |
|
3516 |
|
3517 | if (universal && !isLower && Text.isText(node)) {
|
3518 | return;
|
3519 | } else {
|
3520 | continue;
|
3521 | }
|
3522 | }
|
3523 |
|
3524 | if (mode === 'lowest' && isLower) {
|
3525 | hit = [node, path];
|
3526 | continue;
|
3527 | }
|
3528 |
|
3529 | var emit = mode === 'lowest' ? hit : [node, path];
|
3530 | if (emit) {
|
3531 | if (universal) {
|
3532 | matches.push(emit);
|
3533 | } else {
|
3534 | yield emit;
|
3535 | }
|
3536 | }
|
3537 | hit = [node, path];
|
3538 | }
|
3539 |
|
3540 | } catch (err) {
|
3541 | _iterator.e(err);
|
3542 | } finally {
|
3543 | _iterator.f();
|
3544 | }
|
3545 | if (mode === 'lowest' && hit) {
|
3546 | if (universal) {
|
3547 | matches.push(hit);
|
3548 | } else {
|
3549 | yield hit;
|
3550 | }
|
3551 | }
|
3552 |
|
3553 |
|
3554 | if (universal) {
|
3555 | yield* matches;
|
3556 | }
|
3557 | }();
|
3558 | }
|
3559 |
|
3560 | 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; } } }; }
|
3561 | 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); }
|
3562 | 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; }
|
3563 | var normalize = function normalize(editor) {
|
3564 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3565 | var _options$force = options.force,
|
3566 | force = _options$force === void 0 ? false : _options$force,
|
3567 | operation = options.operation;
|
3568 | var getDirtyPaths = function getDirtyPaths(editor) {
|
3569 | return DIRTY_PATHS.get(editor) || [];
|
3570 | };
|
3571 | var getDirtyPathKeys = function getDirtyPathKeys(editor) {
|
3572 | return DIRTY_PATH_KEYS.get(editor) || new Set();
|
3573 | };
|
3574 | var popDirtyPath = function popDirtyPath(editor) {
|
3575 | var path = getDirtyPaths(editor).pop();
|
3576 | var key = path.join(',');
|
3577 | getDirtyPathKeys(editor)["delete"](key);
|
3578 | return path;
|
3579 | };
|
3580 | if (!Editor.isNormalizing(editor)) {
|
3581 | return;
|
3582 | }
|
3583 | if (force) {
|
3584 | var allPaths = Array.from(Node.nodes(editor), function (_ref) {
|
3585 | var _ref2 = _slicedToArray(_ref, 2),
|
3586 | p = _ref2[1];
|
3587 | return p;
|
3588 | });
|
3589 | var allPathKeys = new Set(allPaths.map(function (p) {
|
3590 | return p.join(',');
|
3591 | }));
|
3592 | DIRTY_PATHS.set(editor, allPaths);
|
3593 | DIRTY_PATH_KEYS.set(editor, allPathKeys);
|
3594 | }
|
3595 | if (getDirtyPaths(editor).length === 0) {
|
3596 | return;
|
3597 | }
|
3598 | Editor.withoutNormalizing(editor, function () {
|
3599 | |
3600 |
|
3601 |
|
3602 |
|
3603 |
|
3604 | var _iterator = _createForOfIteratorHelper$a(getDirtyPaths(editor)),
|
3605 | _step;
|
3606 | try {
|
3607 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
3608 | var _dirtyPath = _step.value;
|
3609 | if (Node.has(editor, _dirtyPath)) {
|
3610 | var _entry = Editor.node(editor, _dirtyPath);
|
3611 | var _entry2 = _slicedToArray(_entry, 2),
|
3612 | node = _entry2[0],
|
3613 | _ = _entry2[1];
|
3614 | |
3615 |
|
3616 |
|
3617 |
|
3618 |
|
3619 |
|
3620 | if (Element.isElement(node) && node.children.length === 0) {
|
3621 | editor.normalizeNode(_entry, {
|
3622 | operation: operation
|
3623 | });
|
3624 | }
|
3625 | }
|
3626 | }
|
3627 | } catch (err) {
|
3628 | _iterator.e(err);
|
3629 | } finally {
|
3630 | _iterator.f();
|
3631 | }
|
3632 | var dirtyPaths = getDirtyPaths(editor);
|
3633 | var initialDirtyPathsLength = dirtyPaths.length;
|
3634 | var iteration = 0;
|
3635 | while (dirtyPaths.length !== 0) {
|
3636 | if (!editor.shouldNormalize({
|
3637 | dirtyPaths: dirtyPaths,
|
3638 | iteration: iteration,
|
3639 | initialDirtyPathsLength: initialDirtyPathsLength,
|
3640 | operation: operation
|
3641 | })) {
|
3642 | return;
|
3643 | }
|
3644 | var dirtyPath = popDirtyPath(editor);
|
3645 |
|
3646 | if (Node.has(editor, dirtyPath)) {
|
3647 | var entry = Editor.node(editor, dirtyPath);
|
3648 | editor.normalizeNode(entry, {
|
3649 | operation: operation
|
3650 | });
|
3651 | }
|
3652 | iteration++;
|
3653 | dirtyPaths = getDirtyPaths(editor);
|
3654 | }
|
3655 | });
|
3656 | };
|
3657 |
|
3658 | var parent = function parent(editor, at) {
|
3659 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3660 | var path = Editor.path(editor, at, options);
|
3661 | var parentPath = Path.parent(path);
|
3662 | var entry = Editor.node(editor, parentPath);
|
3663 | return entry;
|
3664 | };
|
3665 |
|
3666 | var pathRef = function pathRef(editor, path) {
|
3667 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3668 | var _options$affinity = options.affinity,
|
3669 | affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
|
3670 | var ref = {
|
3671 | current: path,
|
3672 | affinity: affinity,
|
3673 | unref: function unref() {
|
3674 | var current = ref.current;
|
3675 | var pathRefs = Editor.pathRefs(editor);
|
3676 | pathRefs["delete"](ref);
|
3677 | ref.current = null;
|
3678 | return current;
|
3679 | }
|
3680 | };
|
3681 | var refs = Editor.pathRefs(editor);
|
3682 | refs.add(ref);
|
3683 | return ref;
|
3684 | };
|
3685 |
|
3686 | var pathRefs = function pathRefs(editor) {
|
3687 | var refs = PATH_REFS.get(editor);
|
3688 | if (!refs) {
|
3689 | refs = new Set();
|
3690 | PATH_REFS.set(editor, refs);
|
3691 | }
|
3692 | return refs;
|
3693 | };
|
3694 |
|
3695 | var path = function path(editor, at) {
|
3696 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3697 | var depth = options.depth,
|
3698 | edge = options.edge;
|
3699 | if (Path.isPath(at)) {
|
3700 | if (edge === 'start') {
|
3701 | var _Node$first = Node.first(editor, at),
|
3702 | _Node$first2 = _slicedToArray(_Node$first, 2),
|
3703 | firstPath = _Node$first2[1];
|
3704 | at = firstPath;
|
3705 | } else if (edge === 'end') {
|
3706 | var _Node$last = Node.last(editor, at),
|
3707 | _Node$last2 = _slicedToArray(_Node$last, 2),
|
3708 | lastPath = _Node$last2[1];
|
3709 | at = lastPath;
|
3710 | }
|
3711 | }
|
3712 | if (Range.isRange(at)) {
|
3713 | if (edge === 'start') {
|
3714 | at = Range.start(at);
|
3715 | } else if (edge === 'end') {
|
3716 | at = Range.end(at);
|
3717 | } else {
|
3718 | at = Path.common(at.anchor.path, at.focus.path);
|
3719 | }
|
3720 | }
|
3721 | if (Point.isPoint(at)) {
|
3722 | at = at.path;
|
3723 | }
|
3724 | if (depth != null) {
|
3725 | at = at.slice(0, depth);
|
3726 | }
|
3727 | return at;
|
3728 | };
|
3729 |
|
3730 | var pointRef = function pointRef(editor, point) {
|
3731 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3732 | var _options$affinity = options.affinity,
|
3733 | affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
|
3734 | var ref = {
|
3735 | current: point,
|
3736 | affinity: affinity,
|
3737 | unref: function unref() {
|
3738 | var current = ref.current;
|
3739 | var pointRefs = Editor.pointRefs(editor);
|
3740 | pointRefs["delete"](ref);
|
3741 | ref.current = null;
|
3742 | return current;
|
3743 | }
|
3744 | };
|
3745 | var refs = Editor.pointRefs(editor);
|
3746 | refs.add(ref);
|
3747 | return ref;
|
3748 | };
|
3749 |
|
3750 | var pointRefs = function pointRefs(editor) {
|
3751 | var refs = POINT_REFS.get(editor);
|
3752 | if (!refs) {
|
3753 | refs = new Set();
|
3754 | POINT_REFS.set(editor, refs);
|
3755 | }
|
3756 | return refs;
|
3757 | };
|
3758 |
|
3759 | var point = function point(editor, at) {
|
3760 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
3761 | var _options$edge = options.edge,
|
3762 | edge = _options$edge === void 0 ? 'start' : _options$edge;
|
3763 | if (Path.isPath(at)) {
|
3764 | var path;
|
3765 | if (edge === 'end') {
|
3766 | var _Node$last = Node.last(editor, at),
|
3767 | _Node$last2 = _slicedToArray(_Node$last, 2),
|
3768 | lastPath = _Node$last2[1];
|
3769 | path = lastPath;
|
3770 | } else {
|
3771 | var _Node$first = Node.first(editor, at),
|
3772 | _Node$first2 = _slicedToArray(_Node$first, 2),
|
3773 | firstPath = _Node$first2[1];
|
3774 | path = firstPath;
|
3775 | }
|
3776 | var node = Node.get(editor, path);
|
3777 | if (!Text.isText(node)) {
|
3778 | throw new Error("Cannot get the ".concat(edge, " point in the node at path [").concat(at, "] because it has no ").concat(edge, " text node."));
|
3779 | }
|
3780 | return {
|
3781 | path: path,
|
3782 | offset: edge === 'end' ? node.text.length : 0
|
3783 | };
|
3784 | }
|
3785 | if (Range.isRange(at)) {
|
3786 | var _Range$edges = Range.edges(at),
|
3787 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
3788 | start = _Range$edges2[0],
|
3789 | end = _Range$edges2[1];
|
3790 | return edge === 'start' ? start : end;
|
3791 | }
|
3792 | return at;
|
3793 | };
|
3794 |
|
3795 | 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; } } }; }
|
3796 | 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); }
|
3797 | 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; }
|
3798 | function positions(editor) {
|
3799 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3800 | return function* () {
|
3801 | var _options$at = options.at,
|
3802 | at = _options$at === void 0 ? editor.selection : _options$at,
|
3803 | _options$unit = options.unit,
|
3804 | unit = _options$unit === void 0 ? 'offset' : _options$unit,
|
3805 | _options$reverse = options.reverse,
|
3806 | reverse = _options$reverse === void 0 ? false : _options$reverse,
|
3807 | _options$voids = options.voids,
|
3808 | voids = _options$voids === void 0 ? false : _options$voids,
|
3809 | _options$ignoreNonSel = options.ignoreNonSelectable,
|
3810 | ignoreNonSelectable = _options$ignoreNonSel === void 0 ? false : _options$ignoreNonSel;
|
3811 | if (!at) {
|
3812 | return;
|
3813 | }
|
3814 | |
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 |
|
3825 |
|
3826 |
|
3827 |
|
3828 |
|
3829 |
|
3830 |
|
3831 | var range = Editor.range(editor, at);
|
3832 | var _Range$edges = Range.edges(range),
|
3833 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
3834 | start = _Range$edges2[0],
|
3835 | end = _Range$edges2[1];
|
3836 | var first = reverse ? end : start;
|
3837 | var isNewBlock = false;
|
3838 | var blockText = '';
|
3839 | var distance = 0;
|
3840 | var leafTextRemaining = 0;
|
3841 | var leafTextOffset = 0;
|
3842 |
|
3843 |
|
3844 |
|
3845 |
|
3846 |
|
3847 |
|
3848 | var _iterator = _createForOfIteratorHelper$9(Editor.nodes(editor, {
|
3849 | at: at,
|
3850 | reverse: reverse,
|
3851 | voids: voids,
|
3852 | ignoreNonSelectable: ignoreNonSelectable
|
3853 | })),
|
3854 | _step;
|
3855 | try {
|
3856 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
3857 | var _step$value = _slicedToArray(_step.value, 2),
|
3858 | node = _step$value[0],
|
3859 | path = _step$value[1];
|
3860 | |
3861 |
|
3862 |
|
3863 | if (Element.isElement(node)) {
|
3864 |
|
3865 |
|
3866 |
|
3867 | if (!voids && (editor.isVoid(node) || editor.isElementReadOnly(node))) {
|
3868 | yield Editor.start(editor, path);
|
3869 | continue;
|
3870 | }
|
3871 |
|
3872 |
|
3873 |
|
3874 | if (editor.isInline(node)) continue;
|
3875 |
|
3876 | if (Editor.hasInlines(editor, node)) {
|
3877 |
|
3878 |
|
3879 |
|
3880 |
|
3881 |
|
3882 |
|
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 | var e = Path.isAncestor(path, end.path) ? end : Editor.end(editor, path);
|
3888 | var s = Path.isAncestor(path, start.path) ? start : Editor.start(editor, path);
|
3889 | blockText = Editor.string(editor, {
|
3890 | anchor: s,
|
3891 | focus: e
|
3892 | }, {
|
3893 | voids: voids
|
3894 | });
|
3895 | isNewBlock = true;
|
3896 | }
|
3897 | }
|
3898 | |
3899 |
|
3900 |
|
3901 |
|
3902 | if (Text.isText(node)) {
|
3903 | var isFirst = Path.equals(path, first.path);
|
3904 |
|
3905 |
|
3906 |
|
3907 |
|
3908 |
|
3909 | if (isFirst) {
|
3910 | leafTextRemaining = reverse ? first.offset : node.text.length - first.offset;
|
3911 | leafTextOffset = first.offset;
|
3912 | } else {
|
3913 | leafTextRemaining = node.text.length;
|
3914 | leafTextOffset = reverse ? leafTextRemaining : 0;
|
3915 | }
|
3916 |
|
3917 | if (isFirst || isNewBlock || unit === 'offset') {
|
3918 | yield {
|
3919 | path: path,
|
3920 | offset: leafTextOffset
|
3921 | };
|
3922 | isNewBlock = false;
|
3923 | }
|
3924 |
|
3925 | while (true) {
|
3926 |
|
3927 |
|
3928 |
|
3929 | if (distance === 0) {
|
3930 | if (blockText === '') break;
|
3931 | distance = calcDistance(blockText, unit, reverse);
|
3932 |
|
3933 |
|
3934 | blockText = splitByCharacterDistance(blockText, distance, reverse)[1];
|
3935 | }
|
3936 |
|
3937 | leafTextOffset = reverse ? leafTextOffset - distance : leafTextOffset + distance;
|
3938 | leafTextRemaining = leafTextRemaining - distance;
|
3939 |
|
3940 |
|
3941 |
|
3942 | if (leafTextRemaining < 0) {
|
3943 | distance = -leafTextRemaining;
|
3944 | break;
|
3945 | }
|
3946 |
|
3947 |
|
3948 |
|
3949 | distance = 0;
|
3950 | yield {
|
3951 | path: path,
|
3952 | offset: leafTextOffset
|
3953 | };
|
3954 | }
|
3955 | }
|
3956 | }
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 | } catch (err) {
|
3963 | _iterator.e(err);
|
3964 | } finally {
|
3965 | _iterator.f();
|
3966 | }
|
3967 | function calcDistance(text, unit, reverse) {
|
3968 | if (unit === 'character') {
|
3969 | return getCharacterDistance(text, reverse);
|
3970 | } else if (unit === 'word') {
|
3971 | return getWordDistance(text, reverse);
|
3972 | } else if (unit === 'line' || unit === 'block') {
|
3973 | return text.length;
|
3974 | }
|
3975 | return 1;
|
3976 | }
|
3977 | }();
|
3978 | }
|
3979 |
|
3980 | var previous = function previous(editor) {
|
3981 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3982 | var _options$mode = options.mode,
|
3983 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
3984 | _options$voids = options.voids,
|
3985 | voids = _options$voids === void 0 ? false : _options$voids;
|
3986 | var match = options.match,
|
3987 | _options$at = options.at,
|
3988 | at = _options$at === void 0 ? editor.selection : _options$at;
|
3989 | if (!at) {
|
3990 | return;
|
3991 | }
|
3992 | var pointBeforeLocation = Editor.before(editor, at, {
|
3993 | voids: voids
|
3994 | });
|
3995 | if (!pointBeforeLocation) {
|
3996 | return;
|
3997 | }
|
3998 | var _Editor$first = Editor.first(editor, []),
|
3999 | _Editor$first2 = _slicedToArray(_Editor$first, 2),
|
4000 | to = _Editor$first2[1];
|
4001 |
|
4002 |
|
4003 | var span = [pointBeforeLocation.path, to];
|
4004 | if (Path.isPath(at) && at.length === 0) {
|
4005 | throw new Error("Cannot get the previous node from the root node!");
|
4006 | }
|
4007 | if (match == null) {
|
4008 | if (Path.isPath(at)) {
|
4009 | var _Editor$parent = Editor.parent(editor, at),
|
4010 | _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
|
4011 | parent = _Editor$parent2[0];
|
4012 | match = function match(n) {
|
4013 | return parent.children.includes(n);
|
4014 | };
|
4015 | } else {
|
4016 | match = function match() {
|
4017 | return true;
|
4018 | };
|
4019 | }
|
4020 | }
|
4021 | var _Editor$nodes = Editor.nodes(editor, {
|
4022 | reverse: true,
|
4023 | at: span,
|
4024 | match: match,
|
4025 | mode: mode,
|
4026 | voids: voids
|
4027 | }),
|
4028 | _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
4029 | previous = _Editor$nodes2[0];
|
4030 | return previous;
|
4031 | };
|
4032 |
|
4033 | var rangeRef = function rangeRef(editor, range) {
|
4034 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
4035 | var _options$affinity = options.affinity,
|
4036 | affinity = _options$affinity === void 0 ? 'forward' : _options$affinity;
|
4037 | var ref = {
|
4038 | current: range,
|
4039 | affinity: affinity,
|
4040 | unref: function unref() {
|
4041 | var current = ref.current;
|
4042 | var rangeRefs = Editor.rangeRefs(editor);
|
4043 | rangeRefs["delete"](ref);
|
4044 | ref.current = null;
|
4045 | return current;
|
4046 | }
|
4047 | };
|
4048 | var refs = Editor.rangeRefs(editor);
|
4049 | refs.add(ref);
|
4050 | return ref;
|
4051 | };
|
4052 |
|
4053 | var rangeRefs = function rangeRefs(editor) {
|
4054 | var refs = RANGE_REFS.get(editor);
|
4055 | if (!refs) {
|
4056 | refs = new Set();
|
4057 | RANGE_REFS.set(editor, refs);
|
4058 | }
|
4059 | return refs;
|
4060 | };
|
4061 |
|
4062 | var range = function range(editor, at, to) {
|
4063 | if (Range.isRange(at) && !to) {
|
4064 | return at;
|
4065 | }
|
4066 | var start = Editor.start(editor, at);
|
4067 | var end = Editor.end(editor, to || at);
|
4068 | return {
|
4069 | anchor: start,
|
4070 | focus: end
|
4071 | };
|
4072 | };
|
4073 |
|
4074 | 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; }
|
4075 | 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; }
|
4076 | var removeMark = function removeMark(editor, key) {
|
4077 | var selection = editor.selection;
|
4078 | if (selection) {
|
4079 | var match = function match(node, path) {
|
4080 | if (!Text.isText(node)) {
|
4081 | return false;
|
4082 | }
|
4083 |
|
4084 | var _Editor$parent = Editor.parent(editor, path),
|
4085 | _Editor$parent2 = _slicedToArray(_Editor$parent, 2),
|
4086 | parentNode = _Editor$parent2[0];
|
4087 | _Editor$parent2[1];
|
4088 | return !editor.isVoid(parentNode) || editor.markableVoid(parentNode);
|
4089 | };
|
4090 | var expandedSelection = Range.isExpanded(selection);
|
4091 | var markAcceptingVoidSelected = false;
|
4092 | if (!expandedSelection) {
|
4093 | var _Editor$node = Editor.node(editor, selection),
|
4094 | _Editor$node2 = _slicedToArray(_Editor$node, 2),
|
4095 | selectedNode = _Editor$node2[0],
|
4096 | selectedPath = _Editor$node2[1];
|
4097 | if (selectedNode && match(selectedNode, selectedPath)) {
|
4098 | var _Editor$parent3 = Editor.parent(editor, selectedPath),
|
4099 | _Editor$parent4 = _slicedToArray(_Editor$parent3, 1),
|
4100 | parentNode = _Editor$parent4[0];
|
4101 | markAcceptingVoidSelected = parentNode && editor.markableVoid(parentNode);
|
4102 | }
|
4103 | }
|
4104 | if (expandedSelection || markAcceptingVoidSelected) {
|
4105 | Transforms.unsetNodes(editor, key, {
|
4106 | match: match,
|
4107 | split: true,
|
4108 | voids: true
|
4109 | });
|
4110 | } else {
|
4111 | var marks = _objectSpread$2({}, Editor.marks(editor) || {});
|
4112 | delete marks[key];
|
4113 | editor.marks = marks;
|
4114 | if (!FLUSHING.get(editor)) {
|
4115 | editor.onChange();
|
4116 | }
|
4117 | }
|
4118 | }
|
4119 | };
|
4120 |
|
4121 | var setNormalizing = function setNormalizing(editor, isNormalizing) {
|
4122 | NORMALIZING.set(editor, isNormalizing);
|
4123 | };
|
4124 |
|
4125 | var start = function start(editor, at) {
|
4126 | return Editor.point(editor, at, {
|
4127 | edge: 'start'
|
4128 | });
|
4129 | };
|
4130 |
|
4131 | 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; } } }; }
|
4132 | 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); }
|
4133 | 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; }
|
4134 | var string = function string(editor, at) {
|
4135 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
4136 | var _options$voids = options.voids,
|
4137 | voids = _options$voids === void 0 ? false : _options$voids;
|
4138 | var range = Editor.range(editor, at);
|
4139 | var _Range$edges = Range.edges(range),
|
4140 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
4141 | start = _Range$edges2[0],
|
4142 | end = _Range$edges2[1];
|
4143 | var text = '';
|
4144 | var _iterator = _createForOfIteratorHelper$8(Editor.nodes(editor, {
|
4145 | at: range,
|
4146 | match: Text.isText,
|
4147 | voids: voids
|
4148 | })),
|
4149 | _step;
|
4150 | try {
|
4151 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
4152 | var _step$value = _slicedToArray(_step.value, 2),
|
4153 | node = _step$value[0],
|
4154 | path = _step$value[1];
|
4155 | var t = node.text;
|
4156 | if (Path.equals(path, end.path)) {
|
4157 | t = t.slice(0, end.offset);
|
4158 | }
|
4159 | if (Path.equals(path, start.path)) {
|
4160 | t = t.slice(start.offset);
|
4161 | }
|
4162 | text += t;
|
4163 | }
|
4164 | } catch (err) {
|
4165 | _iterator.e(err);
|
4166 | } finally {
|
4167 | _iterator.f();
|
4168 | }
|
4169 | return text;
|
4170 | };
|
4171 |
|
4172 | 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; } } }; }
|
4173 | 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); }
|
4174 | 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; }
|
4175 | var unhangRange = function unhangRange(editor, range) {
|
4176 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
4177 | var _options$voids = options.voids,
|
4178 | voids = _options$voids === void 0 ? false : _options$voids;
|
4179 | var _Range$edges = Range.edges(range),
|
4180 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
4181 | start = _Range$edges2[0],
|
4182 | end = _Range$edges2[1];
|
4183 |
|
4184 | if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range) || Path.hasPrevious(end.path)) {
|
4185 | return range;
|
4186 | }
|
4187 | var endBlock = Editor.above(editor, {
|
4188 | at: end,
|
4189 | match: function match(n) {
|
4190 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
4191 | },
|
4192 | voids: voids
|
4193 | });
|
4194 | var blockPath = endBlock ? endBlock[1] : [];
|
4195 | var first = Editor.start(editor, start);
|
4196 | var before = {
|
4197 | anchor: first,
|
4198 | focus: end
|
4199 | };
|
4200 | var skip = true;
|
4201 | var _iterator = _createForOfIteratorHelper$7(Editor.nodes(editor, {
|
4202 | at: before,
|
4203 | match: Text.isText,
|
4204 | reverse: true,
|
4205 | voids: voids
|
4206 | })),
|
4207 | _step;
|
4208 | try {
|
4209 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
4210 | var _step$value = _slicedToArray(_step.value, 2),
|
4211 | node = _step$value[0],
|
4212 | path = _step$value[1];
|
4213 | if (skip) {
|
4214 | skip = false;
|
4215 | continue;
|
4216 | }
|
4217 | if (node.text !== '' || Path.isBefore(path, blockPath)) {
|
4218 | end = {
|
4219 | path: path,
|
4220 | offset: node.text.length
|
4221 | };
|
4222 | break;
|
4223 | }
|
4224 | }
|
4225 | } catch (err) {
|
4226 | _iterator.e(err);
|
4227 | } finally {
|
4228 | _iterator.f();
|
4229 | }
|
4230 | return {
|
4231 | anchor: start,
|
4232 | focus: end
|
4233 | };
|
4234 | };
|
4235 |
|
4236 | var withoutNormalizing = function withoutNormalizing(editor, fn) {
|
4237 | var value = Editor.isNormalizing(editor);
|
4238 | Editor.setNormalizing(editor, false);
|
4239 | try {
|
4240 | fn();
|
4241 | } finally {
|
4242 | Editor.setNormalizing(editor, value);
|
4243 | }
|
4244 | Editor.normalize(editor);
|
4245 | };
|
4246 |
|
4247 | var shouldMergeNodesRemovePrevNode = function shouldMergeNodesRemovePrevNode(editor, _ref, _ref2) {
|
4248 | var _ref3 = _slicedToArray(_ref, 2),
|
4249 | prevNode = _ref3[0],
|
4250 | prevPath = _ref3[1];
|
4251 | var _ref4 = _slicedToArray(_ref2, 2);
|
4252 | _ref4[0];
|
4253 | _ref4[1];
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 | return Element.isElement(prevNode) && Editor.isEmpty(editor, prevNode) || Text.isText(prevNode) && prevNode.text === '' && prevPath[prevPath.length - 1] !== 0;
|
4260 | };
|
4261 |
|
4262 | 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; } } }; }
|
4263 | 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); }
|
4264 | 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; }
|
4265 | var deleteText = function deleteText(editor) {
|
4266 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
4267 | Editor.withoutNormalizing(editor, function () {
|
4268 | var _Editor$void, _Editor$void2;
|
4269 | var _options$reverse = options.reverse,
|
4270 | reverse = _options$reverse === void 0 ? false : _options$reverse,
|
4271 | _options$unit = options.unit,
|
4272 | unit = _options$unit === void 0 ? 'character' : _options$unit,
|
4273 | _options$distance = options.distance,
|
4274 | distance = _options$distance === void 0 ? 1 : _options$distance,
|
4275 | _options$voids = options.voids,
|
4276 | voids = _options$voids === void 0 ? false : _options$voids;
|
4277 | var _options$at = options.at,
|
4278 | at = _options$at === void 0 ? editor.selection : _options$at,
|
4279 | _options$hanging = options.hanging,
|
4280 | hanging = _options$hanging === void 0 ? false : _options$hanging;
|
4281 | if (!at) {
|
4282 | return;
|
4283 | }
|
4284 | var isCollapsed = false;
|
4285 | if (Range.isRange(at) && Range.isCollapsed(at)) {
|
4286 | isCollapsed = true;
|
4287 | at = at.anchor;
|
4288 | }
|
4289 | if (Point.isPoint(at)) {
|
4290 | var furthestVoid = Editor["void"](editor, {
|
4291 | at: at,
|
4292 | mode: 'highest'
|
4293 | });
|
4294 | if (!voids && furthestVoid) {
|
4295 | var _furthestVoid = _slicedToArray(furthestVoid, 2),
|
4296 | voidPath = _furthestVoid[1];
|
4297 | at = voidPath;
|
4298 | } else {
|
4299 | var opts = {
|
4300 | unit: unit,
|
4301 | distance: distance
|
4302 | };
|
4303 | var target = reverse ? Editor.before(editor, at, opts) || Editor.start(editor, []) : Editor.after(editor, at, opts) || Editor.end(editor, []);
|
4304 | at = {
|
4305 | anchor: at,
|
4306 | focus: target
|
4307 | };
|
4308 | hanging = true;
|
4309 | }
|
4310 | }
|
4311 | if (Path.isPath(at)) {
|
4312 | Transforms.removeNodes(editor, {
|
4313 | at: at,
|
4314 | voids: voids
|
4315 | });
|
4316 | return;
|
4317 | }
|
4318 | if (Range.isCollapsed(at)) {
|
4319 | return;
|
4320 | }
|
4321 | if (!hanging) {
|
4322 | var _Range$edges = Range.edges(at),
|
4323 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
4324 | _end = _Range$edges2[1];
|
4325 | var endOfDoc = Editor.end(editor, []);
|
4326 | if (!Point.equals(_end, endOfDoc)) {
|
4327 | at = Editor.unhangRange(editor, at, {
|
4328 | voids: voids
|
4329 | });
|
4330 | }
|
4331 | }
|
4332 | var _Range$edges3 = Range.edges(at),
|
4333 | _Range$edges4 = _slicedToArray(_Range$edges3, 2),
|
4334 | start = _Range$edges4[0],
|
4335 | end = _Range$edges4[1];
|
4336 | var startBlock = Editor.above(editor, {
|
4337 | match: function match(n) {
|
4338 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
4339 | },
|
4340 | at: start,
|
4341 | voids: voids
|
4342 | });
|
4343 | var endBlock = Editor.above(editor, {
|
4344 | match: function match(n) {
|
4345 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
4346 | },
|
4347 | at: end,
|
4348 | voids: voids
|
4349 | });
|
4350 | var isAcrossBlocks = startBlock && endBlock && !Path.equals(startBlock[1], endBlock[1]);
|
4351 | var isSingleText = Path.equals(start.path, end.path);
|
4352 | var startNonEditable = voids ? null : (_Editor$void = Editor["void"](editor, {
|
4353 | at: start,
|
4354 | mode: 'highest'
|
4355 | })) !== null && _Editor$void !== void 0 ? _Editor$void : Editor.elementReadOnly(editor, {
|
4356 | at: start,
|
4357 | mode: 'highest'
|
4358 | });
|
4359 | var endNonEditable = voids ? null : (_Editor$void2 = Editor["void"](editor, {
|
4360 | at: end,
|
4361 | mode: 'highest'
|
4362 | })) !== null && _Editor$void2 !== void 0 ? _Editor$void2 : Editor.elementReadOnly(editor, {
|
4363 | at: end,
|
4364 | mode: 'highest'
|
4365 | });
|
4366 |
|
4367 | if (startNonEditable) {
|
4368 | var before = Editor.before(editor, start);
|
4369 | if (before && startBlock && Path.isAncestor(startBlock[1], before.path)) {
|
4370 | start = before;
|
4371 | }
|
4372 | }
|
4373 | if (endNonEditable) {
|
4374 | var after = Editor.after(editor, end);
|
4375 | if (after && endBlock && Path.isAncestor(endBlock[1], after.path)) {
|
4376 | end = after;
|
4377 | }
|
4378 | }
|
4379 |
|
4380 |
|
4381 | var matches = [];
|
4382 | var lastPath;
|
4383 | var _iterator = _createForOfIteratorHelper$6(Editor.nodes(editor, {
|
4384 | at: at,
|
4385 | voids: voids
|
4386 | })),
|
4387 | _step;
|
4388 | try {
|
4389 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
4390 | var entry = _step.value;
|
4391 | var _entry = _slicedToArray(entry, 2),
|
4392 | _node2 = _entry[0],
|
4393 | _path2 = _entry[1];
|
4394 | if (lastPath && Path.compare(_path2, lastPath) === 0) {
|
4395 | continue;
|
4396 | }
|
4397 | if (!voids && Element.isElement(_node2) && (Editor.isVoid(editor, _node2) || Editor.isElementReadOnly(editor, _node2)) || !Path.isCommon(_path2, start.path) && !Path.isCommon(_path2, end.path)) {
|
4398 | matches.push(entry);
|
4399 | lastPath = _path2;
|
4400 | }
|
4401 | }
|
4402 | } catch (err) {
|
4403 | _iterator.e(err);
|
4404 | } finally {
|
4405 | _iterator.f();
|
4406 | }
|
4407 | var pathRefs = Array.from(matches, function (_ref) {
|
4408 | var _ref2 = _slicedToArray(_ref, 2),
|
4409 | p = _ref2[1];
|
4410 | return Editor.pathRef(editor, p);
|
4411 | });
|
4412 | var startRef = Editor.pointRef(editor, start);
|
4413 | var endRef = Editor.pointRef(editor, end);
|
4414 | var removedText = '';
|
4415 | if (!isSingleText && !startNonEditable) {
|
4416 | var _point = startRef.current;
|
4417 | var _Editor$leaf = Editor.leaf(editor, _point),
|
4418 | _Editor$leaf2 = _slicedToArray(_Editor$leaf, 1),
|
4419 | node = _Editor$leaf2[0];
|
4420 | var path = _point.path;
|
4421 | var _start = start,
|
4422 | offset = _start.offset;
|
4423 | var text = node.text.slice(offset);
|
4424 | if (text.length > 0) {
|
4425 | editor.apply({
|
4426 | type: 'remove_text',
|
4427 | path: path,
|
4428 | offset: offset,
|
4429 | text: text
|
4430 | });
|
4431 | removedText = text;
|
4432 | }
|
4433 | }
|
4434 | pathRefs.reverse().map(function (r) {
|
4435 | return r.unref();
|
4436 | }).filter(function (r) {
|
4437 | return r !== null;
|
4438 | }).forEach(function (p) {
|
4439 | return Transforms.removeNodes(editor, {
|
4440 | at: p,
|
4441 | voids: voids
|
4442 | });
|
4443 | });
|
4444 | if (!endNonEditable) {
|
4445 | var _point2 = endRef.current;
|
4446 | var _Editor$leaf3 = Editor.leaf(editor, _point2),
|
4447 | _Editor$leaf4 = _slicedToArray(_Editor$leaf3, 1),
|
4448 | _node = _Editor$leaf4[0];
|
4449 | var _path = _point2.path;
|
4450 | var _offset = isSingleText ? start.offset : 0;
|
4451 | var _text = _node.text.slice(_offset, end.offset);
|
4452 | if (_text.length > 0) {
|
4453 | editor.apply({
|
4454 | type: 'remove_text',
|
4455 | path: _path,
|
4456 | offset: _offset,
|
4457 | text: _text
|
4458 | });
|
4459 | removedText = _text;
|
4460 | }
|
4461 | }
|
4462 | if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
|
4463 | Transforms.mergeNodes(editor, {
|
4464 | at: endRef.current,
|
4465 | hanging: true,
|
4466 | voids: voids
|
4467 | });
|
4468 | }
|
4469 |
|
4470 |
|
4471 |
|
4472 | if (isCollapsed && reverse && unit === 'character' && removedText.length > 1 && removedText.match(/[\u0E00-\u0E7F]+/)) {
|
4473 | Transforms.insertText(editor, removedText.slice(0, removedText.length - distance));
|
4474 | }
|
4475 | var startUnref = startRef.unref();
|
4476 | var endUnref = endRef.unref();
|
4477 | var point = reverse ? startUnref || endUnref : endUnref || startUnref;
|
4478 | if (options.at == null && point) {
|
4479 | Transforms.select(editor, point);
|
4480 | }
|
4481 | });
|
4482 | };
|
4483 |
|
4484 | 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; } } }; }
|
4485 | 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); }
|
4486 | 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; }
|
4487 | var insertFragment = function insertFragment(editor, fragment) {
|
4488 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
4489 | Editor.withoutNormalizing(editor, function () {
|
4490 | var _options$hanging = options.hanging,
|
4491 | hanging = _options$hanging === void 0 ? false : _options$hanging,
|
4492 | _options$voids = options.voids,
|
4493 | voids = _options$voids === void 0 ? false : _options$voids;
|
4494 | var _options$at = options.at,
|
4495 | at = _options$at === void 0 ? getDefaultInsertLocation(editor) : _options$at,
|
4496 | _options$batchDirty = options.batchDirty,
|
4497 | batchDirty = _options$batchDirty === void 0 ? true : _options$batchDirty;
|
4498 | if (!fragment.length) {
|
4499 | return;
|
4500 | }
|
4501 | if (Range.isRange(at)) {
|
4502 | if (!hanging) {
|
4503 | at = Editor.unhangRange(editor, at, {
|
4504 | voids: voids
|
4505 | });
|
4506 | }
|
4507 | if (Range.isCollapsed(at)) {
|
4508 | at = at.anchor;
|
4509 | } else {
|
4510 | var _Range$edges = Range.edges(at),
|
4511 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
4512 | end = _Range$edges2[1];
|
4513 | if (!voids && Editor["void"](editor, {
|
4514 | at: end
|
4515 | })) {
|
4516 | return;
|
4517 | }
|
4518 | var pointRef = Editor.pointRef(editor, end);
|
4519 | Transforms["delete"](editor, {
|
4520 | at: at
|
4521 | });
|
4522 | at = pointRef.unref();
|
4523 | }
|
4524 | } else if (Path.isPath(at)) {
|
4525 | at = Editor.start(editor, at);
|
4526 | }
|
4527 | if (!voids && Editor["void"](editor, {
|
4528 | at: at
|
4529 | })) {
|
4530 | return;
|
4531 | }
|
4532 |
|
4533 |
|
4534 | var inlineElementMatch = Editor.above(editor, {
|
4535 | at: at,
|
4536 | match: function match(n) {
|
4537 | return Element.isElement(n) && Editor.isInline(editor, n);
|
4538 | },
|
4539 | mode: 'highest',
|
4540 | voids: voids
|
4541 | });
|
4542 | if (inlineElementMatch) {
|
4543 | var _inlineElementMatch = _slicedToArray(inlineElementMatch, 2),
|
4544 | _inlinePath = _inlineElementMatch[1];
|
4545 | if (Editor.isEnd(editor, at, _inlinePath)) {
|
4546 | var after = Editor.after(editor, _inlinePath);
|
4547 | at = after;
|
4548 | } else if (Editor.isStart(editor, at, _inlinePath)) {
|
4549 | var before = Editor.before(editor, _inlinePath);
|
4550 | at = before;
|
4551 | }
|
4552 | }
|
4553 | var blockMatch = Editor.above(editor, {
|
4554 | match: function match(n) {
|
4555 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
4556 | },
|
4557 | at: at,
|
4558 | voids: voids
|
4559 | });
|
4560 | var _blockMatch = _slicedToArray(blockMatch, 2),
|
4561 | blockPath = _blockMatch[1];
|
4562 | var isBlockStart = Editor.isStart(editor, at, blockPath);
|
4563 | var isBlockEnd = Editor.isEnd(editor, at, blockPath);
|
4564 | var isBlockEmpty = isBlockStart && isBlockEnd;
|
4565 | var mergeStart = !isBlockStart || isBlockStart && isBlockEnd;
|
4566 | var mergeEnd = !isBlockEnd;
|
4567 | var _Node$first = Node.first({
|
4568 | children: fragment
|
4569 | }, []),
|
4570 | _Node$first2 = _slicedToArray(_Node$first, 2),
|
4571 | firstPath = _Node$first2[1];
|
4572 | var _Node$last = Node.last({
|
4573 | children: fragment
|
4574 | }, []),
|
4575 | _Node$last2 = _slicedToArray(_Node$last, 2),
|
4576 | lastPath = _Node$last2[1];
|
4577 | var matches = [];
|
4578 | var matcher = function matcher(_ref) {
|
4579 | var _ref2 = _slicedToArray(_ref, 2),
|
4580 | n = _ref2[0],
|
4581 | p = _ref2[1];
|
4582 | var isRoot = p.length === 0;
|
4583 | if (isRoot) {
|
4584 | return false;
|
4585 | }
|
4586 | if (isBlockEmpty) {
|
4587 | return true;
|
4588 | }
|
4589 | if (mergeStart && Path.isAncestor(p, firstPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
|
4590 | return false;
|
4591 | }
|
4592 | if (mergeEnd && Path.isAncestor(p, lastPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
|
4593 | return false;
|
4594 | }
|
4595 | return true;
|
4596 | };
|
4597 | var _iterator = _createForOfIteratorHelper$5(Node.nodes({
|
4598 | children: fragment
|
4599 | }, {
|
4600 | pass: matcher
|
4601 | })),
|
4602 | _step;
|
4603 | try {
|
4604 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
4605 | var entry = _step.value;
|
4606 | if (matcher(entry)) {
|
4607 | matches.push(entry);
|
4608 | }
|
4609 | }
|
4610 | } catch (err) {
|
4611 | _iterator.e(err);
|
4612 | } finally {
|
4613 | _iterator.f();
|
4614 | }
|
4615 | var starts = [];
|
4616 | var middles = [];
|
4617 | var ends = [];
|
4618 | var starting = true;
|
4619 | var hasBlocks = false;
|
4620 | for (var _i = 0, _matches = matches; _i < _matches.length; _i++) {
|
4621 | var _matches$_i = _slicedToArray(_matches[_i], 1),
|
4622 | node = _matches$_i[0];
|
4623 | if (Element.isElement(node) && !editor.isInline(node)) {
|
4624 | starting = false;
|
4625 | hasBlocks = true;
|
4626 | middles.push(node);
|
4627 | } else if (starting) {
|
4628 | starts.push(node);
|
4629 | } else {
|
4630 | ends.push(node);
|
4631 | }
|
4632 | }
|
4633 | var _Editor$nodes = Editor.nodes(editor, {
|
4634 | at: at,
|
4635 | match: function match(n) {
|
4636 | return Text.isText(n) || Editor.isInline(editor, n);
|
4637 | },
|
4638 | mode: 'highest',
|
4639 | voids: voids
|
4640 | }),
|
4641 | _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
4642 | inlineMatch = _Editor$nodes2[0];
|
4643 | var _inlineMatch = _slicedToArray(inlineMatch, 2),
|
4644 | inlinePath = _inlineMatch[1];
|
4645 | var isInlineStart = Editor.isStart(editor, at, inlinePath);
|
4646 | var isInlineEnd = Editor.isEnd(editor, at, inlinePath);
|
4647 | var middleRef = Editor.pathRef(editor, isBlockEnd && !ends.length ? Path.next(blockPath) : blockPath);
|
4648 | var endRef = Editor.pathRef(editor, isInlineEnd ? Path.next(inlinePath) : inlinePath);
|
4649 | Transforms.splitNodes(editor, {
|
4650 | at: at,
|
4651 | match: function match(n) {
|
4652 | return hasBlocks ? Element.isElement(n) && Editor.isBlock(editor, n) : Text.isText(n) || Editor.isInline(editor, n);
|
4653 | },
|
4654 | mode: hasBlocks ? 'lowest' : 'highest',
|
4655 | always: hasBlocks && (!isBlockStart || starts.length > 0) && (!isBlockEnd || ends.length > 0),
|
4656 | voids: voids
|
4657 | });
|
4658 | var startRef = Editor.pathRef(editor, !isInlineStart || isInlineStart && isInlineEnd ? Path.next(inlinePath) : inlinePath);
|
4659 | Transforms.insertNodes(editor, starts, {
|
4660 | at: startRef.current,
|
4661 | match: function match(n) {
|
4662 | return Text.isText(n) || Editor.isInline(editor, n);
|
4663 | },
|
4664 | mode: 'highest',
|
4665 | voids: voids,
|
4666 | batchDirty: batchDirty
|
4667 | });
|
4668 | if (isBlockEmpty && !starts.length && middles.length && !ends.length) {
|
4669 | Transforms["delete"](editor, {
|
4670 | at: blockPath,
|
4671 | voids: voids
|
4672 | });
|
4673 | }
|
4674 | Transforms.insertNodes(editor, middles, {
|
4675 | at: middleRef.current,
|
4676 | match: function match(n) {
|
4677 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
4678 | },
|
4679 | mode: 'lowest',
|
4680 | voids: voids,
|
4681 | batchDirty: batchDirty
|
4682 | });
|
4683 | Transforms.insertNodes(editor, ends, {
|
4684 | at: endRef.current,
|
4685 | match: function match(n) {
|
4686 | return Text.isText(n) || Editor.isInline(editor, n);
|
4687 | },
|
4688 | mode: 'highest',
|
4689 | voids: voids,
|
4690 | batchDirty: batchDirty
|
4691 | });
|
4692 | if (!options.at) {
|
4693 | var path;
|
4694 | if (ends.length > 0 && endRef.current) {
|
4695 | path = Path.previous(endRef.current);
|
4696 | } else if (middles.length > 0 && middleRef.current) {
|
4697 | path = Path.previous(middleRef.current);
|
4698 | } else if (startRef.current) {
|
4699 | path = Path.previous(startRef.current);
|
4700 | }
|
4701 | if (path) {
|
4702 | var _end = Editor.end(editor, path);
|
4703 | Transforms.select(editor, _end);
|
4704 | }
|
4705 | }
|
4706 | startRef.unref();
|
4707 | middleRef.unref();
|
4708 | endRef.unref();
|
4709 | });
|
4710 | };
|
4711 |
|
4712 | var collapse = function collapse(editor) {
|
4713 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
4714 | var _options$edge = options.edge,
|
4715 | edge = _options$edge === void 0 ? 'anchor' : _options$edge;
|
4716 | var selection = editor.selection;
|
4717 | if (!selection) {
|
4718 | return;
|
4719 | } else if (edge === 'anchor') {
|
4720 | Transforms.select(editor, selection.anchor);
|
4721 | } else if (edge === 'focus') {
|
4722 | Transforms.select(editor, selection.focus);
|
4723 | } else if (edge === 'start') {
|
4724 | var _Range$edges = Range.edges(selection),
|
4725 | _Range$edges2 = _slicedToArray(_Range$edges, 1),
|
4726 | start = _Range$edges2[0];
|
4727 | Transforms.select(editor, start);
|
4728 | } else if (edge === 'end') {
|
4729 | var _Range$edges3 = Range.edges(selection),
|
4730 | _Range$edges4 = _slicedToArray(_Range$edges3, 2),
|
4731 | end = _Range$edges4[1];
|
4732 | Transforms.select(editor, end);
|
4733 | }
|
4734 | };
|
4735 |
|
4736 | var deselect = function deselect(editor) {
|
4737 | var selection = editor.selection;
|
4738 | if (selection) {
|
4739 | editor.apply({
|
4740 | type: 'set_selection',
|
4741 | properties: selection,
|
4742 | newProperties: null
|
4743 | });
|
4744 | }
|
4745 | };
|
4746 |
|
4747 | var move = function move(editor) {
|
4748 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
4749 | var selection = editor.selection;
|
4750 | var _options$distance = options.distance,
|
4751 | distance = _options$distance === void 0 ? 1 : _options$distance,
|
4752 | _options$unit = options.unit,
|
4753 | unit = _options$unit === void 0 ? 'character' : _options$unit,
|
4754 | _options$reverse = options.reverse,
|
4755 | reverse = _options$reverse === void 0 ? false : _options$reverse;
|
4756 | var _options$edge = options.edge,
|
4757 | edge = _options$edge === void 0 ? null : _options$edge;
|
4758 | if (!selection) {
|
4759 | return;
|
4760 | }
|
4761 | if (edge === 'start') {
|
4762 | edge = Range.isBackward(selection) ? 'focus' : 'anchor';
|
4763 | }
|
4764 | if (edge === 'end') {
|
4765 | edge = Range.isBackward(selection) ? 'anchor' : 'focus';
|
4766 | }
|
4767 | var anchor = selection.anchor,
|
4768 | focus = selection.focus;
|
4769 | var opts = {
|
4770 | distance: distance,
|
4771 | unit: unit,
|
4772 | ignoreNonSelectable: true
|
4773 | };
|
4774 | var props = {};
|
4775 | if (edge == null || edge === 'anchor') {
|
4776 | var point = reverse ? Editor.before(editor, anchor, opts) : Editor.after(editor, anchor, opts);
|
4777 | if (point) {
|
4778 | props.anchor = point;
|
4779 | }
|
4780 | }
|
4781 | if (edge == null || edge === 'focus') {
|
4782 | var _point = reverse ? Editor.before(editor, focus, opts) : Editor.after(editor, focus, opts);
|
4783 | if (_point) {
|
4784 | props.focus = _point;
|
4785 | }
|
4786 | }
|
4787 | Transforms.setSelection(editor, props);
|
4788 | };
|
4789 |
|
4790 | var select = function select(editor, target) {
|
4791 | var selection = editor.selection;
|
4792 | target = Editor.range(editor, target);
|
4793 | if (selection) {
|
4794 | Transforms.setSelection(editor, target);
|
4795 | return;
|
4796 | }
|
4797 | if (!Range.isRange(target)) {
|
4798 | 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)));
|
4799 | }
|
4800 | editor.apply({
|
4801 | type: 'set_selection',
|
4802 | properties: selection,
|
4803 | newProperties: target
|
4804 | });
|
4805 | };
|
4806 |
|
4807 | 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; }
|
4808 | 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; }
|
4809 | var setPoint = function setPoint(editor, props) {
|
4810 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
4811 | var selection = editor.selection;
|
4812 | var _options$edge = options.edge,
|
4813 | edge = _options$edge === void 0 ? 'both' : _options$edge;
|
4814 | if (!selection) {
|
4815 | return;
|
4816 | }
|
4817 | if (edge === 'start') {
|
4818 | edge = Range.isBackward(selection) ? 'focus' : 'anchor';
|
4819 | }
|
4820 | if (edge === 'end') {
|
4821 | edge = Range.isBackward(selection) ? 'anchor' : 'focus';
|
4822 | }
|
4823 | var anchor = selection.anchor,
|
4824 | focus = selection.focus;
|
4825 | var point = edge === 'anchor' ? anchor : focus;
|
4826 | Transforms.setSelection(editor, _defineProperty({}, edge === 'anchor' ? 'anchor' : 'focus', _objectSpread$1(_objectSpread$1({}, point), props)));
|
4827 | };
|
4828 |
|
4829 | var setSelection = function setSelection(editor, props) {
|
4830 | var selection = editor.selection;
|
4831 | var oldProps = {};
|
4832 | var newProps = {};
|
4833 | if (!selection) {
|
4834 | return;
|
4835 | }
|
4836 | for (var k in props) {
|
4837 | 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]) {
|
4838 | oldProps[k] = selection[k];
|
4839 | newProps[k] = props[k];
|
4840 | }
|
4841 | }
|
4842 | if (Object.keys(oldProps).length > 0) {
|
4843 | editor.apply({
|
4844 | type: 'set_selection',
|
4845 | properties: oldProps,
|
4846 | newProperties: newProps
|
4847 | });
|
4848 | }
|
4849 | };
|
4850 |
|
4851 | 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; } } }; }
|
4852 | 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); }
|
4853 | 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; }
|
4854 | var insertNodes = function insertNodes(editor, nodes) {
|
4855 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
4856 | Editor.withoutNormalizing(editor, function () {
|
4857 | var _options$hanging = options.hanging,
|
4858 | hanging = _options$hanging === void 0 ? false : _options$hanging,
|
4859 | _options$voids = options.voids,
|
4860 | voids = _options$voids === void 0 ? false : _options$voids,
|
4861 | _options$mode = options.mode,
|
4862 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
4863 | _options$batchDirty = options.batchDirty,
|
4864 | batchDirty = _options$batchDirty === void 0 ? true : _options$batchDirty;
|
4865 | var at = options.at,
|
4866 | match = options.match,
|
4867 | select = options.select;
|
4868 | if (Node.isNode(nodes)) {
|
4869 | nodes = [nodes];
|
4870 | }
|
4871 | if (nodes.length === 0) {
|
4872 | return;
|
4873 | }
|
4874 | var _nodes = nodes,
|
4875 | _nodes2 = _slicedToArray(_nodes, 1),
|
4876 | node = _nodes2[0];
|
4877 | if (!at) {
|
4878 | at = getDefaultInsertLocation(editor);
|
4879 | if (select !== false) {
|
4880 | select = true;
|
4881 | }
|
4882 | }
|
4883 | if (select == null) {
|
4884 | select = false;
|
4885 | }
|
4886 | if (Range.isRange(at)) {
|
4887 | if (!hanging) {
|
4888 | at = Editor.unhangRange(editor, at, {
|
4889 | voids: voids
|
4890 | });
|
4891 | }
|
4892 | if (Range.isCollapsed(at)) {
|
4893 | at = at.anchor;
|
4894 | } else {
|
4895 | var _Range$edges = Range.edges(at),
|
4896 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
4897 | end = _Range$edges2[1];
|
4898 | var pointRef = Editor.pointRef(editor, end);
|
4899 | Transforms["delete"](editor, {
|
4900 | at: at
|
4901 | });
|
4902 | at = pointRef.unref();
|
4903 | }
|
4904 | }
|
4905 | if (Point.isPoint(at)) {
|
4906 | if (match == null) {
|
4907 | if (Text.isText(node)) {
|
4908 | match = function match(n) {
|
4909 | return Text.isText(n);
|
4910 | };
|
4911 | } else if (editor.isInline(node)) {
|
4912 | match = function match(n) {
|
4913 | return Text.isText(n) || Editor.isInline(editor, n);
|
4914 | };
|
4915 | } else {
|
4916 | match = function match(n) {
|
4917 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
4918 | };
|
4919 | }
|
4920 | }
|
4921 | var _Editor$nodes = Editor.nodes(editor, {
|
4922 | at: at.path,
|
4923 | match: match,
|
4924 | mode: mode,
|
4925 | voids: voids
|
4926 | }),
|
4927 | _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
4928 | entry = _Editor$nodes2[0];
|
4929 | if (entry) {
|
4930 | var _entry = _slicedToArray(entry, 2),
|
4931 | matchPath = _entry[1];
|
4932 | var pathRef = Editor.pathRef(editor, matchPath);
|
4933 | var isAtEnd = Editor.isEnd(editor, at, matchPath);
|
4934 | Transforms.splitNodes(editor, {
|
4935 | at: at,
|
4936 | match: match,
|
4937 | mode: mode,
|
4938 | voids: voids
|
4939 | });
|
4940 | var path = pathRef.unref();
|
4941 | at = isAtEnd ? Path.next(path) : path;
|
4942 | } else {
|
4943 | return;
|
4944 | }
|
4945 | }
|
4946 | var parentPath = Path.parent(at);
|
4947 | var index = at[at.length - 1];
|
4948 | if (!voids && Editor["void"](editor, {
|
4949 | at: parentPath
|
4950 | })) {
|
4951 | return;
|
4952 | }
|
4953 | if (batchDirty) {
|
4954 |
|
4955 |
|
4956 | var batchedOps = [];
|
4957 | var newDirtyPaths = Path.levels(parentPath);
|
4958 | batchDirtyPaths(editor, function () {
|
4959 | var _iterator = _createForOfIteratorHelper$4(nodes),
|
4960 | _step;
|
4961 | try {
|
4962 | var _loop = function _loop() {
|
4963 | var node = _step.value;
|
4964 | var path = parentPath.concat(index);
|
4965 | index++;
|
4966 | var op = {
|
4967 | type: 'insert_node',
|
4968 | path: path,
|
4969 | node: node
|
4970 | };
|
4971 | editor.apply(op);
|
4972 | at = Path.next(at);
|
4973 | batchedOps.push(op);
|
4974 | if (!Text.isText) {
|
4975 | newDirtyPaths.push(path);
|
4976 | } else {
|
4977 | newDirtyPaths.push.apply(newDirtyPaths, _toConsumableArray(Array.from(Node.nodes(node), function (_ref) {
|
4978 | var _ref2 = _slicedToArray(_ref, 2),
|
4979 | p = _ref2[1];
|
4980 | return path.concat(p);
|
4981 | })));
|
4982 | }
|
4983 | };
|
4984 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
4985 | _loop();
|
4986 | }
|
4987 | } catch (err) {
|
4988 | _iterator.e(err);
|
4989 | } finally {
|
4990 | _iterator.f();
|
4991 | }
|
4992 | }, function () {
|
4993 | updateDirtyPaths(editor, newDirtyPaths, function (p) {
|
4994 | var newPath = p;
|
4995 | for (var _i = 0, _batchedOps = batchedOps; _i < _batchedOps.length; _i++) {
|
4996 | var op = _batchedOps[_i];
|
4997 | if (Path.operationCanTransformPath(op)) {
|
4998 | newPath = Path.transform(newPath, op);
|
4999 | if (!newPath) {
|
5000 | return null;
|
5001 | }
|
5002 | }
|
5003 | }
|
5004 | return newPath;
|
5005 | });
|
5006 | });
|
5007 | } else {
|
5008 | var _iterator2 = _createForOfIteratorHelper$4(nodes),
|
5009 | _step2;
|
5010 | try {
|
5011 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
5012 | var _node = _step2.value;
|
5013 | var _path = parentPath.concat(index);
|
5014 | index++;
|
5015 | editor.apply({
|
5016 | type: 'insert_node',
|
5017 | path: _path,
|
5018 | node: _node
|
5019 | });
|
5020 | at = Path.next(at);
|
5021 | }
|
5022 | } catch (err) {
|
5023 | _iterator2.e(err);
|
5024 | } finally {
|
5025 | _iterator2.f();
|
5026 | }
|
5027 | }
|
5028 | at = Path.previous(at);
|
5029 | if (select) {
|
5030 | var point = Editor.end(editor, at);
|
5031 | if (point) {
|
5032 | Transforms.select(editor, point);
|
5033 | }
|
5034 | }
|
5035 | });
|
5036 | };
|
5037 |
|
5038 | var liftNodes = function liftNodes(editor) {
|
5039 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
5040 | Editor.withoutNormalizing(editor, function () {
|
5041 | var _options$at = options.at,
|
5042 | at = _options$at === void 0 ? editor.selection : _options$at,
|
5043 | _options$mode = options.mode,
|
5044 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
5045 | _options$voids = options.voids,
|
5046 | voids = _options$voids === void 0 ? false : _options$voids;
|
5047 | var match = options.match;
|
5048 | if (match == null) {
|
5049 | match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
|
5050 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5051 | };
|
5052 | }
|
5053 | if (!at) {
|
5054 | return;
|
5055 | }
|
5056 | var matches = Editor.nodes(editor, {
|
5057 | at: at,
|
5058 | match: match,
|
5059 | mode: mode,
|
5060 | voids: voids
|
5061 | });
|
5062 | var pathRefs = Array.from(matches, function (_ref) {
|
5063 | var _ref2 = _slicedToArray(_ref, 2),
|
5064 | p = _ref2[1];
|
5065 | return Editor.pathRef(editor, p);
|
5066 | });
|
5067 | for (var _i = 0, _pathRefs = pathRefs; _i < _pathRefs.length; _i++) {
|
5068 | var pathRef = _pathRefs[_i];
|
5069 | var path = pathRef.unref();
|
5070 | if (path.length < 2) {
|
5071 | throw new Error("Cannot lift node at a path [".concat(path, "] because it has a depth of less than `2`."));
|
5072 | }
|
5073 | var parentNodeEntry = Editor.node(editor, Path.parent(path));
|
5074 | var _parentNodeEntry = _slicedToArray(parentNodeEntry, 2),
|
5075 | parent = _parentNodeEntry[0],
|
5076 | parentPath = _parentNodeEntry[1];
|
5077 | var index = path[path.length - 1];
|
5078 | var length = parent.children.length;
|
5079 | if (length === 1) {
|
5080 | var toPath = Path.next(parentPath);
|
5081 | Transforms.moveNodes(editor, {
|
5082 | at: path,
|
5083 | to: toPath,
|
5084 | voids: voids
|
5085 | });
|
5086 | Transforms.removeNodes(editor, {
|
5087 | at: parentPath,
|
5088 | voids: voids
|
5089 | });
|
5090 | } else if (index === 0) {
|
5091 | Transforms.moveNodes(editor, {
|
5092 | at: path,
|
5093 | to: parentPath,
|
5094 | voids: voids
|
5095 | });
|
5096 | } else if (index === length - 1) {
|
5097 | var _toPath = Path.next(parentPath);
|
5098 | Transforms.moveNodes(editor, {
|
5099 | at: path,
|
5100 | to: _toPath,
|
5101 | voids: voids
|
5102 | });
|
5103 | } else {
|
5104 | var splitPath = Path.next(path);
|
5105 | var _toPath2 = Path.next(parentPath);
|
5106 | Transforms.splitNodes(editor, {
|
5107 | at: splitPath,
|
5108 | voids: voids
|
5109 | });
|
5110 | Transforms.moveNodes(editor, {
|
5111 | at: path,
|
5112 | to: _toPath2,
|
5113 | voids: voids
|
5114 | });
|
5115 | }
|
5116 | }
|
5117 | });
|
5118 | };
|
5119 |
|
5120 | var _excluded = ["text"],
|
5121 | _excluded2 = ["children"];
|
5122 | var hasSingleChildNest = function hasSingleChildNest(editor, node) {
|
5123 | if (Element.isElement(node)) {
|
5124 | var element = node;
|
5125 | if (Editor.isVoid(editor, node)) {
|
5126 | return true;
|
5127 | } else if (element.children.length === 1) {
|
5128 | return hasSingleChildNest(editor, element.children[0]);
|
5129 | } else {
|
5130 | return false;
|
5131 | }
|
5132 | } else if (Editor.isEditor(node)) {
|
5133 | return false;
|
5134 | } else {
|
5135 | return true;
|
5136 | }
|
5137 | };
|
5138 | var mergeNodes = function mergeNodes(editor) {
|
5139 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
5140 | Editor.withoutNormalizing(editor, function () {
|
5141 | var match = options.match,
|
5142 | _options$at = options.at,
|
5143 | at = _options$at === void 0 ? editor.selection : _options$at;
|
5144 | var _options$hanging = options.hanging,
|
5145 | hanging = _options$hanging === void 0 ? false : _options$hanging,
|
5146 | _options$voids = options.voids,
|
5147 | voids = _options$voids === void 0 ? false : _options$voids,
|
5148 | _options$mode = options.mode,
|
5149 | mode = _options$mode === void 0 ? 'lowest' : _options$mode;
|
5150 | if (!at) {
|
5151 | return;
|
5152 | }
|
5153 | if (match == null) {
|
5154 | if (Path.isPath(at)) {
|
5155 | var _Editor$parent = Editor.parent(editor, at),
|
5156 | _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
|
5157 | parent = _Editor$parent2[0];
|
5158 | match = function match(n) {
|
5159 | return parent.children.includes(n);
|
5160 | };
|
5161 | } else {
|
5162 | match = function match(n) {
|
5163 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5164 | };
|
5165 | }
|
5166 | }
|
5167 | if (!hanging && Range.isRange(at)) {
|
5168 | at = Editor.unhangRange(editor, at, {
|
5169 | voids: voids
|
5170 | });
|
5171 | }
|
5172 | if (Range.isRange(at)) {
|
5173 | if (Range.isCollapsed(at)) {
|
5174 | at = at.anchor;
|
5175 | } else {
|
5176 | var _Range$edges = Range.edges(at),
|
5177 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
5178 | end = _Range$edges2[1];
|
5179 | var pointRef = Editor.pointRef(editor, end);
|
5180 | Transforms["delete"](editor, {
|
5181 | at: at
|
5182 | });
|
5183 | at = pointRef.unref();
|
5184 | if (options.at == null) {
|
5185 | Transforms.select(editor, at);
|
5186 | }
|
5187 | }
|
5188 | }
|
5189 | var _Editor$nodes = Editor.nodes(editor, {
|
5190 | at: at,
|
5191 | match: match,
|
5192 | voids: voids,
|
5193 | mode: mode
|
5194 | }),
|
5195 | _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
5196 | current = _Editor$nodes2[0];
|
5197 | var prev = Editor.previous(editor, {
|
5198 | at: at,
|
5199 | match: match,
|
5200 | voids: voids,
|
5201 | mode: mode
|
5202 | });
|
5203 | if (!current || !prev) {
|
5204 | return;
|
5205 | }
|
5206 | var _current = _slicedToArray(current, 2),
|
5207 | node = _current[0],
|
5208 | path = _current[1];
|
5209 | var _prev = _slicedToArray(prev, 2),
|
5210 | prevNode = _prev[0],
|
5211 | prevPath = _prev[1];
|
5212 | if (path.length === 0 || prevPath.length === 0) {
|
5213 | return;
|
5214 | }
|
5215 | var newPath = Path.next(prevPath);
|
5216 | var commonPath = Path.common(path, prevPath);
|
5217 | var isPreviousSibling = Path.isSibling(path, prevPath);
|
5218 | var levels = Array.from(Editor.levels(editor, {
|
5219 | at: path
|
5220 | }), function (_ref) {
|
5221 | var _ref2 = _slicedToArray(_ref, 1),
|
5222 | n = _ref2[0];
|
5223 | return n;
|
5224 | }).slice(commonPath.length).slice(0, -1);
|
5225 |
|
5226 |
|
5227 | var emptyAncestor = Editor.above(editor, {
|
5228 | at: path,
|
5229 | mode: 'highest',
|
5230 | match: function match(n) {
|
5231 | return levels.includes(n) && hasSingleChildNest(editor, n);
|
5232 | }
|
5233 | });
|
5234 | var emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
|
5235 | var properties;
|
5236 | var position;
|
5237 |
|
5238 |
|
5239 | if (Text.isText(node) && Text.isText(prevNode)) {
|
5240 | node.text;
|
5241 | var rest = _objectWithoutProperties(node, _excluded);
|
5242 | position = prevNode.text.length;
|
5243 | properties = rest;
|
5244 | } else if (Element.isElement(node) && Element.isElement(prevNode)) {
|
5245 | node.children;
|
5246 | var _rest = _objectWithoutProperties(node, _excluded2);
|
5247 | position = prevNode.children.length;
|
5248 | properties = _rest;
|
5249 | } else {
|
5250 | 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)));
|
5251 | }
|
5252 |
|
5253 |
|
5254 | if (!isPreviousSibling) {
|
5255 | Transforms.moveNodes(editor, {
|
5256 | at: path,
|
5257 | to: newPath,
|
5258 | voids: voids
|
5259 | });
|
5260 | }
|
5261 |
|
5262 |
|
5263 | if (emptyRef) {
|
5264 | Transforms.removeNodes(editor, {
|
5265 | at: emptyRef.current,
|
5266 | voids: voids
|
5267 | });
|
5268 | }
|
5269 | if (Editor.shouldMergeNodesRemovePrevNode(editor, prev, current)) {
|
5270 | Transforms.removeNodes(editor, {
|
5271 | at: prevPath,
|
5272 | voids: voids
|
5273 | });
|
5274 | } else {
|
5275 | editor.apply({
|
5276 | type: 'merge_node',
|
5277 | path: newPath,
|
5278 | position: position,
|
5279 | properties: properties
|
5280 | });
|
5281 | }
|
5282 | if (emptyRef) {
|
5283 | emptyRef.unref();
|
5284 | }
|
5285 | });
|
5286 | };
|
5287 |
|
5288 | var moveNodes = function moveNodes(editor, options) {
|
5289 | Editor.withoutNormalizing(editor, function () {
|
5290 | var to = options.to,
|
5291 | _options$at = options.at,
|
5292 | at = _options$at === void 0 ? editor.selection : _options$at,
|
5293 | _options$mode = options.mode,
|
5294 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
5295 | _options$voids = options.voids,
|
5296 | voids = _options$voids === void 0 ? false : _options$voids;
|
5297 | var match = options.match;
|
5298 | if (!at) {
|
5299 | return;
|
5300 | }
|
5301 | if (match == null) {
|
5302 | match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
|
5303 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5304 | };
|
5305 | }
|
5306 | var toRef = Editor.pathRef(editor, to);
|
5307 | var targets = Editor.nodes(editor, {
|
5308 | at: at,
|
5309 | match: match,
|
5310 | mode: mode,
|
5311 | voids: voids
|
5312 | });
|
5313 | var pathRefs = Array.from(targets, function (_ref) {
|
5314 | var _ref2 = _slicedToArray(_ref, 2),
|
5315 | p = _ref2[1];
|
5316 | return Editor.pathRef(editor, p);
|
5317 | });
|
5318 | for (var _i = 0, _pathRefs = pathRefs; _i < _pathRefs.length; _i++) {
|
5319 | var pathRef = _pathRefs[_i];
|
5320 | var path = pathRef.unref();
|
5321 | var newPath = toRef.current;
|
5322 | if (path.length !== 0) {
|
5323 | editor.apply({
|
5324 | type: 'move_node',
|
5325 | path: path,
|
5326 | newPath: newPath
|
5327 | });
|
5328 | }
|
5329 | if (toRef.current && Path.isSibling(newPath, path) && Path.isAfter(newPath, path)) {
|
5330 |
|
5331 |
|
5332 |
|
5333 | toRef.current = Path.next(toRef.current);
|
5334 | }
|
5335 | }
|
5336 | toRef.unref();
|
5337 | });
|
5338 | };
|
5339 |
|
5340 | var removeNodes = function removeNodes(editor) {
|
5341 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
5342 | Editor.withoutNormalizing(editor, function () {
|
5343 | var _options$hanging = options.hanging,
|
5344 | hanging = _options$hanging === void 0 ? false : _options$hanging,
|
5345 | _options$voids = options.voids,
|
5346 | voids = _options$voids === void 0 ? false : _options$voids,
|
5347 | _options$mode = options.mode,
|
5348 | mode = _options$mode === void 0 ? 'lowest' : _options$mode;
|
5349 | var _options$at = options.at,
|
5350 | at = _options$at === void 0 ? editor.selection : _options$at,
|
5351 | match = options.match;
|
5352 | if (!at) {
|
5353 | return;
|
5354 | }
|
5355 | if (match == null) {
|
5356 | match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
|
5357 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5358 | };
|
5359 | }
|
5360 | if (!hanging && Range.isRange(at)) {
|
5361 | at = Editor.unhangRange(editor, at, {
|
5362 | voids: voids
|
5363 | });
|
5364 | }
|
5365 | var depths = Editor.nodes(editor, {
|
5366 | at: at,
|
5367 | match: match,
|
5368 | mode: mode,
|
5369 | voids: voids
|
5370 | });
|
5371 | var pathRefs = Array.from(depths, function (_ref) {
|
5372 | var _ref2 = _slicedToArray(_ref, 2),
|
5373 | p = _ref2[1];
|
5374 | return Editor.pathRef(editor, p);
|
5375 | });
|
5376 | for (var _i = 0, _pathRefs = pathRefs; _i < _pathRefs.length; _i++) {
|
5377 | var pathRef = _pathRefs[_i];
|
5378 | var path = pathRef.unref();
|
5379 | if (path) {
|
5380 | var _Editor$node = Editor.node(editor, path),
|
5381 | _Editor$node2 = _slicedToArray(_Editor$node, 1),
|
5382 | node = _Editor$node2[0];
|
5383 | editor.apply({
|
5384 | type: 'remove_node',
|
5385 | path: path,
|
5386 | node: node
|
5387 | });
|
5388 | }
|
5389 | }
|
5390 | });
|
5391 | };
|
5392 |
|
5393 | 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; } } }; }
|
5394 | 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); }
|
5395 | 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; }
|
5396 | var setNodes = function setNodes(editor, props) {
|
5397 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
5398 | Editor.withoutNormalizing(editor, function () {
|
5399 | var match = options.match,
|
5400 | _options$at = options.at,
|
5401 | at = _options$at === void 0 ? editor.selection : _options$at,
|
5402 | compare = options.compare,
|
5403 | merge = options.merge;
|
5404 | var _options$hanging = options.hanging,
|
5405 | hanging = _options$hanging === void 0 ? false : _options$hanging,
|
5406 | _options$mode = options.mode,
|
5407 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
5408 | _options$split = options.split,
|
5409 | split = _options$split === void 0 ? false : _options$split,
|
5410 | _options$voids = options.voids,
|
5411 | voids = _options$voids === void 0 ? false : _options$voids;
|
5412 | if (!at) {
|
5413 | return;
|
5414 | }
|
5415 | if (match == null) {
|
5416 | match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
|
5417 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5418 | };
|
5419 | }
|
5420 | if (!hanging && Range.isRange(at)) {
|
5421 | at = Editor.unhangRange(editor, at, {
|
5422 | voids: voids
|
5423 | });
|
5424 | }
|
5425 | if (split && Range.isRange(at)) {
|
5426 | if (Range.isCollapsed(at) && Editor.leaf(editor, at.anchor)[0].text.length > 0) {
|
5427 |
|
5428 |
|
5429 | return;
|
5430 | }
|
5431 | var rangeRef = Editor.rangeRef(editor, at, {
|
5432 | affinity: 'inward'
|
5433 | });
|
5434 | var _Range$edges = Range.edges(at),
|
5435 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
5436 | start = _Range$edges2[0],
|
5437 | end = _Range$edges2[1];
|
5438 | var splitMode = mode === 'lowest' ? 'lowest' : 'highest';
|
5439 | var endAtEndOfNode = Editor.isEnd(editor, end, end.path);
|
5440 | Transforms.splitNodes(editor, {
|
5441 | at: end,
|
5442 | match: match,
|
5443 | mode: splitMode,
|
5444 | voids: voids,
|
5445 | always: !endAtEndOfNode
|
5446 | });
|
5447 | var startAtStartOfNode = Editor.isStart(editor, start, start.path);
|
5448 | Transforms.splitNodes(editor, {
|
5449 | at: start,
|
5450 | match: match,
|
5451 | mode: splitMode,
|
5452 | voids: voids,
|
5453 | always: !startAtStartOfNode
|
5454 | });
|
5455 | at = rangeRef.unref();
|
5456 | if (options.at == null) {
|
5457 | Transforms.select(editor, at);
|
5458 | }
|
5459 | }
|
5460 | if (!compare) {
|
5461 | compare = function compare(prop, nodeProp) {
|
5462 | return prop !== nodeProp;
|
5463 | };
|
5464 | }
|
5465 | var _iterator = _createForOfIteratorHelper$3(Editor.nodes(editor, {
|
5466 | at: at,
|
5467 | match: match,
|
5468 | mode: mode,
|
5469 | voids: voids
|
5470 | })),
|
5471 | _step;
|
5472 | try {
|
5473 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
5474 | var _step$value = _slicedToArray(_step.value, 2),
|
5475 | node = _step$value[0],
|
5476 | path = _step$value[1];
|
5477 | var properties = {};
|
5478 |
|
5479 | var newProperties = {};
|
5480 |
|
5481 | if (path.length === 0) {
|
5482 | continue;
|
5483 | }
|
5484 | var hasChanges = false;
|
5485 | for (var k in props) {
|
5486 | if (k === 'children' || k === 'text') {
|
5487 | continue;
|
5488 | }
|
5489 | if (compare(props[k], node[k])) {
|
5490 | hasChanges = true;
|
5491 |
|
5492 | if (node.hasOwnProperty(k)) properties[k] = node[k];
|
5493 |
|
5494 | if (merge) {
|
5495 | if (props[k] != null) newProperties[k] = merge(node[k], props[k]);
|
5496 | } else {
|
5497 | if (props[k] != null) newProperties[k] = props[k];
|
5498 | }
|
5499 | }
|
5500 | }
|
5501 | if (hasChanges) {
|
5502 | editor.apply({
|
5503 | type: 'set_node',
|
5504 | path: path,
|
5505 | properties: properties,
|
5506 | newProperties: newProperties
|
5507 | });
|
5508 | }
|
5509 | }
|
5510 | } catch (err) {
|
5511 | _iterator.e(err);
|
5512 | } finally {
|
5513 | _iterator.f();
|
5514 | }
|
5515 | });
|
5516 | };
|
5517 |
|
5518 | 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; } } }; }
|
5519 | 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); }
|
5520 | 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; }
|
5521 |
|
5522 |
|
5523 |
|
5524 | var deleteRange = function deleteRange(editor, range) {
|
5525 | if (Range.isCollapsed(range)) {
|
5526 | return range.anchor;
|
5527 | } else {
|
5528 | var _Range$edges = Range.edges(range),
|
5529 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
5530 | end = _Range$edges2[1];
|
5531 | var pointRef = Editor.pointRef(editor, end);
|
5532 | Transforms["delete"](editor, {
|
5533 | at: range
|
5534 | });
|
5535 | return pointRef.unref();
|
5536 | }
|
5537 | };
|
5538 | var splitNodes = function splitNodes(editor) {
|
5539 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
5540 | Editor.withoutNormalizing(editor, function () {
|
5541 | var _options$mode = options.mode,
|
5542 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
5543 | _options$voids = options.voids,
|
5544 | voids = _options$voids === void 0 ? false : _options$voids;
|
5545 | var match = options.match,
|
5546 | _options$at = options.at,
|
5547 | at = _options$at === void 0 ? editor.selection : _options$at,
|
5548 | _options$height = options.height,
|
5549 | height = _options$height === void 0 ? 0 : _options$height,
|
5550 | _options$always = options.always,
|
5551 | always = _options$always === void 0 ? false : _options$always;
|
5552 | if (match == null) {
|
5553 | match = function match(n) {
|
5554 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5555 | };
|
5556 | }
|
5557 | if (Range.isRange(at)) {
|
5558 | at = deleteRange(editor, at);
|
5559 | }
|
5560 |
|
5561 |
|
5562 | if (Path.isPath(at)) {
|
5563 | var path = at;
|
5564 | var point = Editor.point(editor, path);
|
5565 | var _Editor$parent = Editor.parent(editor, path),
|
5566 | _Editor$parent2 = _slicedToArray(_Editor$parent, 1),
|
5567 | parent = _Editor$parent2[0];
|
5568 | match = function match(n) {
|
5569 | return n === parent;
|
5570 | };
|
5571 | height = point.path.length - path.length + 1;
|
5572 | at = point;
|
5573 | always = true;
|
5574 | }
|
5575 | if (!at) {
|
5576 | return;
|
5577 | }
|
5578 | var beforeRef = Editor.pointRef(editor, at, {
|
5579 | affinity: 'backward'
|
5580 | });
|
5581 | var afterRef;
|
5582 | try {
|
5583 | var _Editor$nodes = Editor.nodes(editor, {
|
5584 | at: at,
|
5585 | match: match,
|
5586 | mode: mode,
|
5587 | voids: voids
|
5588 | }),
|
5589 | _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
5590 | highest = _Editor$nodes2[0];
|
5591 | if (!highest) {
|
5592 | return;
|
5593 | }
|
5594 | var voidMatch = Editor["void"](editor, {
|
5595 | at: at,
|
5596 | mode: 'highest'
|
5597 | });
|
5598 | var nudge = 0;
|
5599 | if (!voids && voidMatch) {
|
5600 | var _voidMatch = _slicedToArray(voidMatch, 2),
|
5601 | voidNode = _voidMatch[0],
|
5602 | voidPath = _voidMatch[1];
|
5603 | if (Element.isElement(voidNode) && editor.isInline(voidNode)) {
|
5604 | var after = Editor.after(editor, voidPath);
|
5605 | if (!after) {
|
5606 | var text = {
|
5607 | text: ''
|
5608 | };
|
5609 | var afterPath = Path.next(voidPath);
|
5610 | Transforms.insertNodes(editor, text, {
|
5611 | at: afterPath,
|
5612 | voids: voids
|
5613 | });
|
5614 | after = Editor.point(editor, afterPath);
|
5615 | }
|
5616 | at = after;
|
5617 | always = true;
|
5618 | }
|
5619 | var siblingHeight = at.path.length - voidPath.length;
|
5620 | height = siblingHeight + 1;
|
5621 | always = true;
|
5622 | }
|
5623 | afterRef = Editor.pointRef(editor, at);
|
5624 | var depth = at.path.length - height;
|
5625 | var _highest = _slicedToArray(highest, 2),
|
5626 | highestPath = _highest[1];
|
5627 | var lowestPath = at.path.slice(0, depth);
|
5628 | var position = height === 0 ? at.offset : at.path[depth] + nudge;
|
5629 | var _iterator = _createForOfIteratorHelper$2(Editor.levels(editor, {
|
5630 | at: lowestPath,
|
5631 | reverse: true,
|
5632 | voids: voids
|
5633 | })),
|
5634 | _step;
|
5635 | try {
|
5636 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
5637 | var _step$value = _slicedToArray(_step.value, 2),
|
5638 | node = _step$value[0],
|
5639 | _path = _step$value[1];
|
5640 | var split = false;
|
5641 | if (_path.length < highestPath.length || _path.length === 0 || !voids && Element.isElement(node) && Editor.isVoid(editor, node)) {
|
5642 | break;
|
5643 | }
|
5644 | var _point2 = beforeRef.current;
|
5645 | var isEnd = Editor.isEnd(editor, _point2, _path);
|
5646 | if (always || !beforeRef || !Editor.isEdge(editor, _point2, _path)) {
|
5647 | split = true;
|
5648 | var properties = Node.extractProps(node);
|
5649 | editor.apply({
|
5650 | type: 'split_node',
|
5651 | path: _path,
|
5652 | position: position,
|
5653 | properties: properties
|
5654 | });
|
5655 | }
|
5656 | position = _path[_path.length - 1] + (split || isEnd ? 1 : 0);
|
5657 | }
|
5658 | } catch (err) {
|
5659 | _iterator.e(err);
|
5660 | } finally {
|
5661 | _iterator.f();
|
5662 | }
|
5663 | if (options.at == null) {
|
5664 | var _point = afterRef.current || Editor.end(editor, []);
|
5665 | Transforms.select(editor, _point);
|
5666 | }
|
5667 | } finally {
|
5668 | var _afterRef;
|
5669 | beforeRef.unref();
|
5670 | (_afterRef = afterRef) === null || _afterRef === void 0 || _afterRef.unref();
|
5671 | }
|
5672 | });
|
5673 | };
|
5674 |
|
5675 | 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; } } }; }
|
5676 | 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); }
|
5677 | 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; }
|
5678 | var unsetNodes = function unsetNodes(editor, props) {
|
5679 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
5680 | if (!Array.isArray(props)) {
|
5681 | props = [props];
|
5682 | }
|
5683 | var obj = {};
|
5684 | var _iterator = _createForOfIteratorHelper$1(props),
|
5685 | _step;
|
5686 | try {
|
5687 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
5688 | var key = _step.value;
|
5689 | obj[key] = null;
|
5690 | }
|
5691 | } catch (err) {
|
5692 | _iterator.e(err);
|
5693 | } finally {
|
5694 | _iterator.f();
|
5695 | }
|
5696 | Transforms.setNodes(editor, obj, options);
|
5697 | };
|
5698 |
|
5699 | 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; } } }; }
|
5700 | 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); }
|
5701 | 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; }
|
5702 | var unwrapNodes = function unwrapNodes(editor) {
|
5703 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
5704 | Editor.withoutNormalizing(editor, function () {
|
5705 | var _options$mode = options.mode,
|
5706 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
5707 | _options$split = options.split,
|
5708 | split = _options$split === void 0 ? false : _options$split,
|
5709 | _options$voids = options.voids,
|
5710 | voids = _options$voids === void 0 ? false : _options$voids;
|
5711 | var _options$at = options.at,
|
5712 | at = _options$at === void 0 ? editor.selection : _options$at,
|
5713 | match = options.match;
|
5714 | if (!at) {
|
5715 | return;
|
5716 | }
|
5717 | if (match == null) {
|
5718 | match = Path.isPath(at) ? matchPath(editor, at) : function (n) {
|
5719 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5720 | };
|
5721 | }
|
5722 | if (Path.isPath(at)) {
|
5723 | at = Editor.range(editor, at);
|
5724 | }
|
5725 | var rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null;
|
5726 | var matches = Editor.nodes(editor, {
|
5727 | at: at,
|
5728 | match: match,
|
5729 | mode: mode,
|
5730 | voids: voids
|
5731 | });
|
5732 | var pathRefs = Array.from(matches, function (_ref) {
|
5733 | var _ref2 = _slicedToArray(_ref, 2),
|
5734 | p = _ref2[1];
|
5735 | return Editor.pathRef(editor, p);
|
5736 | }
|
5737 |
|
5738 |
|
5739 |
|
5740 | ).reverse();
|
5741 | var _iterator = _createForOfIteratorHelper(pathRefs),
|
5742 | _step;
|
5743 | try {
|
5744 | var _loop = function _loop() {
|
5745 | var pathRef = _step.value;
|
5746 | var path = pathRef.unref();
|
5747 | var _Editor$node = Editor.node(editor, path),
|
5748 | _Editor$node2 = _slicedToArray(_Editor$node, 1),
|
5749 | node = _Editor$node2[0];
|
5750 | var range = Editor.range(editor, path);
|
5751 | if (split && rangeRef) {
|
5752 | range = Range.intersection(rangeRef.current, range);
|
5753 | }
|
5754 | Transforms.liftNodes(editor, {
|
5755 | at: range,
|
5756 | match: function match(n) {
|
5757 | return Element.isAncestor(node) && node.children.includes(n);
|
5758 | },
|
5759 | voids: voids
|
5760 | });
|
5761 | };
|
5762 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
5763 | _loop();
|
5764 | }
|
5765 | } catch (err) {
|
5766 | _iterator.e(err);
|
5767 | } finally {
|
5768 | _iterator.f();
|
5769 | }
|
5770 | if (rangeRef) {
|
5771 | rangeRef.unref();
|
5772 | }
|
5773 | });
|
5774 | };
|
5775 |
|
5776 | 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; }
|
5777 | 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; }
|
5778 | var wrapNodes = function wrapNodes(editor, element) {
|
5779 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
5780 | Editor.withoutNormalizing(editor, function () {
|
5781 | var _options$mode = options.mode,
|
5782 | mode = _options$mode === void 0 ? 'lowest' : _options$mode,
|
5783 | _options$split = options.split,
|
5784 | split = _options$split === void 0 ? false : _options$split,
|
5785 | _options$voids = options.voids,
|
5786 | voids = _options$voids === void 0 ? false : _options$voids;
|
5787 | var match = options.match,
|
5788 | _options$at = options.at,
|
5789 | at = _options$at === void 0 ? editor.selection : _options$at;
|
5790 | if (!at) {
|
5791 | return;
|
5792 | }
|
5793 | if (match == null) {
|
5794 | if (Path.isPath(at)) {
|
5795 | match = matchPath(editor, at);
|
5796 | } else if (editor.isInline(element)) {
|
5797 | match = function match(n) {
|
5798 | return Element.isElement(n) && Editor.isInline(editor, n) || Text.isText(n);
|
5799 | };
|
5800 | } else {
|
5801 | match = function match(n) {
|
5802 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5803 | };
|
5804 | }
|
5805 | }
|
5806 | if (split && Range.isRange(at)) {
|
5807 | var _Range$edges = Range.edges(at),
|
5808 | _Range$edges2 = _slicedToArray(_Range$edges, 2),
|
5809 | start = _Range$edges2[0],
|
5810 | end = _Range$edges2[1];
|
5811 | var rangeRef = Editor.rangeRef(editor, at, {
|
5812 | affinity: 'inward'
|
5813 | });
|
5814 | Transforms.splitNodes(editor, {
|
5815 | at: end,
|
5816 | match: match,
|
5817 | voids: voids
|
5818 | });
|
5819 | Transforms.splitNodes(editor, {
|
5820 | at: start,
|
5821 | match: match,
|
5822 | voids: voids
|
5823 | });
|
5824 | at = rangeRef.unref();
|
5825 | if (options.at == null) {
|
5826 | Transforms.select(editor, at);
|
5827 | }
|
5828 | }
|
5829 | var roots = Array.from(Editor.nodes(editor, {
|
5830 | at: at,
|
5831 | match: editor.isInline(element) ? function (n) {
|
5832 | return Element.isElement(n) && Editor.isBlock(editor, n);
|
5833 | } : function (n) {
|
5834 | return Editor.isEditor(n);
|
5835 | },
|
5836 | mode: 'lowest',
|
5837 | voids: voids
|
5838 | }));
|
5839 | var _loop = function _loop() {
|
5840 | var _roots$_i = _slicedToArray(_roots[_i], 2),
|
5841 | rootPath = _roots$_i[1];
|
5842 | var a = Range.isRange(at) ? Range.intersection(at, Editor.range(editor, rootPath)) : at;
|
5843 | if (!a) {
|
5844 | return 0;
|
5845 | }
|
5846 | var matches = Array.from(Editor.nodes(editor, {
|
5847 | at: a,
|
5848 | match: match,
|
5849 | mode: mode,
|
5850 | voids: voids
|
5851 | }));
|
5852 | if (matches.length > 0) {
|
5853 | var first = matches[0];
|
5854 | var last = matches[matches.length - 1];
|
5855 | var _first = _slicedToArray(first, 2),
|
5856 | firstPath = _first[1];
|
5857 | var _last = _slicedToArray(last, 2),
|
5858 | lastPath = _last[1];
|
5859 | if (firstPath.length === 0 && lastPath.length === 0) {
|
5860 |
|
5861 | return 0;
|
5862 | }
|
5863 | var commonPath = Path.equals(firstPath, lastPath) ? Path.parent(firstPath) : Path.common(firstPath, lastPath);
|
5864 | var range = Editor.range(editor, firstPath, lastPath);
|
5865 | var commonNodeEntry = Editor.node(editor, commonPath);
|
5866 | var _commonNodeEntry = _slicedToArray(commonNodeEntry, 1),
|
5867 | commonNode = _commonNodeEntry[0];
|
5868 | var depth = commonPath.length + 1;
|
5869 | var wrapperPath = Path.next(lastPath.slice(0, depth));
|
5870 | var wrapper = _objectSpread(_objectSpread({}, element), {}, {
|
5871 | children: []
|
5872 | });
|
5873 | Transforms.insertNodes(editor, wrapper, {
|
5874 | at: wrapperPath,
|
5875 | voids: voids
|
5876 | });
|
5877 | Transforms.moveNodes(editor, {
|
5878 | at: range,
|
5879 | match: function match(n) {
|
5880 | return Element.isAncestor(commonNode) && commonNode.children.includes(n);
|
5881 | },
|
5882 | to: wrapperPath.concat(0),
|
5883 | voids: voids
|
5884 | });
|
5885 | }
|
5886 | },
|
5887 | _ret;
|
5888 | for (var _i = 0, _roots = roots; _i < _roots.length; _i++) {
|
5889 | _ret = _loop();
|
5890 | if (_ret === 0) continue;
|
5891 | }
|
5892 | });
|
5893 | };
|
5894 |
|
5895 |
|
5896 |
|
5897 |
|
5898 | var createEditor = function createEditor() {
|
5899 | var editor = {
|
5900 | children: [],
|
5901 | operations: [],
|
5902 | selection: null,
|
5903 | marks: null,
|
5904 | isElementReadOnly: function isElementReadOnly() {
|
5905 | return false;
|
5906 | },
|
5907 | isInline: function isInline() {
|
5908 | return false;
|
5909 | },
|
5910 | isSelectable: function isSelectable() {
|
5911 | return true;
|
5912 | },
|
5913 | isVoid: function isVoid() {
|
5914 | return false;
|
5915 | },
|
5916 | markableVoid: function markableVoid() {
|
5917 | return false;
|
5918 | },
|
5919 | onChange: function onChange() {},
|
5920 |
|
5921 | apply: function apply$1() {
|
5922 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
5923 | args[_key] = arguments[_key];
|
5924 | }
|
5925 | return apply.apply(void 0, [editor].concat(args));
|
5926 | },
|
5927 |
|
5928 | addMark: function addMark$1() {
|
5929 | for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
5930 | args[_key2] = arguments[_key2];
|
5931 | }
|
5932 | return addMark.apply(void 0, [editor].concat(args));
|
5933 | },
|
5934 | deleteBackward: function deleteBackward$1() {
|
5935 | for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
5936 | args[_key3] = arguments[_key3];
|
5937 | }
|
5938 | return deleteBackward.apply(void 0, [editor].concat(args));
|
5939 | },
|
5940 | deleteForward: function deleteForward$1() {
|
5941 | for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
5942 | args[_key4] = arguments[_key4];
|
5943 | }
|
5944 | return deleteForward.apply(void 0, [editor].concat(args));
|
5945 | },
|
5946 | deleteFragment: function deleteFragment$1() {
|
5947 | for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
5948 | args[_key5] = arguments[_key5];
|
5949 | }
|
5950 | return deleteFragment.apply(void 0, [editor].concat(args));
|
5951 | },
|
5952 | getFragment: function getFragment$1() {
|
5953 | for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
5954 | args[_key6] = arguments[_key6];
|
5955 | }
|
5956 | return getFragment.apply(void 0, [editor].concat(args));
|
5957 | },
|
5958 | insertBreak: function insertBreak$1() {
|
5959 | for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
5960 | args[_key7] = arguments[_key7];
|
5961 | }
|
5962 | return insertBreak.apply(void 0, [editor].concat(args));
|
5963 | },
|
5964 | insertSoftBreak: function insertSoftBreak$1() {
|
5965 | for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
5966 | args[_key8] = arguments[_key8];
|
5967 | }
|
5968 | return insertSoftBreak.apply(void 0, [editor].concat(args));
|
5969 | },
|
5970 | insertFragment: function insertFragment$1() {
|
5971 | for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
5972 | args[_key9] = arguments[_key9];
|
5973 | }
|
5974 | return insertFragment.apply(void 0, [editor].concat(args));
|
5975 | },
|
5976 | insertNode: function insertNode$1() {
|
5977 | for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
|
5978 | args[_key10] = arguments[_key10];
|
5979 | }
|
5980 | return insertNode.apply(void 0, [editor].concat(args));
|
5981 | },
|
5982 | insertText: function insertText$1() {
|
5983 | for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
|
5984 | args[_key11] = arguments[_key11];
|
5985 | }
|
5986 | return insertText.apply(void 0, [editor].concat(args));
|
5987 | },
|
5988 | normalizeNode: function normalizeNode$1() {
|
5989 | for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
|
5990 | args[_key12] = arguments[_key12];
|
5991 | }
|
5992 | return normalizeNode.apply(void 0, [editor].concat(args));
|
5993 | },
|
5994 | removeMark: function removeMark$1() {
|
5995 | for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
|
5996 | args[_key13] = arguments[_key13];
|
5997 | }
|
5998 | return removeMark.apply(void 0, [editor].concat(args));
|
5999 | },
|
6000 | getDirtyPaths: function getDirtyPaths$1() {
|
6001 | for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
|
6002 | args[_key14] = arguments[_key14];
|
6003 | }
|
6004 | return getDirtyPaths.apply(void 0, [editor].concat(args));
|
6005 | },
|
6006 | shouldNormalize: function shouldNormalize$1() {
|
6007 | for (var _len15 = arguments.length, args = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
|
6008 | args[_key15] = arguments[_key15];
|
6009 | }
|
6010 | return shouldNormalize.apply(void 0, [editor].concat(args));
|
6011 | },
|
6012 |
|
6013 | above: function above$1() {
|
6014 | for (var _len16 = arguments.length, args = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
|
6015 | args[_key16] = arguments[_key16];
|
6016 | }
|
6017 | return above.apply(void 0, [editor].concat(args));
|
6018 | },
|
6019 | after: function after$1() {
|
6020 | for (var _len17 = arguments.length, args = new Array(_len17), _key17 = 0; _key17 < _len17; _key17++) {
|
6021 | args[_key17] = arguments[_key17];
|
6022 | }
|
6023 | return after.apply(void 0, [editor].concat(args));
|
6024 | },
|
6025 | before: function before$1() {
|
6026 | for (var _len18 = arguments.length, args = new Array(_len18), _key18 = 0; _key18 < _len18; _key18++) {
|
6027 | args[_key18] = arguments[_key18];
|
6028 | }
|
6029 | return before.apply(void 0, [editor].concat(args));
|
6030 | },
|
6031 | collapse: function collapse$1() {
|
6032 | for (var _len19 = arguments.length, args = new Array(_len19), _key19 = 0; _key19 < _len19; _key19++) {
|
6033 | args[_key19] = arguments[_key19];
|
6034 | }
|
6035 | return collapse.apply(void 0, [editor].concat(args));
|
6036 | },
|
6037 | "delete": function _delete() {
|
6038 | for (var _len20 = arguments.length, args = new Array(_len20), _key20 = 0; _key20 < _len20; _key20++) {
|
6039 | args[_key20] = arguments[_key20];
|
6040 | }
|
6041 | return deleteText.apply(void 0, [editor].concat(args));
|
6042 | },
|
6043 | deselect: function deselect$1() {
|
6044 | for (var _len21 = arguments.length, args = new Array(_len21), _key21 = 0; _key21 < _len21; _key21++) {
|
6045 | args[_key21] = arguments[_key21];
|
6046 | }
|
6047 | return deselect.apply(void 0, [editor].concat(args));
|
6048 | },
|
6049 | edges: function edges$1() {
|
6050 | for (var _len22 = arguments.length, args = new Array(_len22), _key22 = 0; _key22 < _len22; _key22++) {
|
6051 | args[_key22] = arguments[_key22];
|
6052 | }
|
6053 | return edges.apply(void 0, [editor].concat(args));
|
6054 | },
|
6055 | elementReadOnly: function elementReadOnly$1() {
|
6056 | for (var _len23 = arguments.length, args = new Array(_len23), _key23 = 0; _key23 < _len23; _key23++) {
|
6057 | args[_key23] = arguments[_key23];
|
6058 | }
|
6059 | return elementReadOnly.apply(void 0, [editor].concat(args));
|
6060 | },
|
6061 | end: function end$1() {
|
6062 | for (var _len24 = arguments.length, args = new Array(_len24), _key24 = 0; _key24 < _len24; _key24++) {
|
6063 | args[_key24] = arguments[_key24];
|
6064 | }
|
6065 | return end.apply(void 0, [editor].concat(args));
|
6066 | },
|
6067 | first: function first$1() {
|
6068 | for (var _len25 = arguments.length, args = new Array(_len25), _key25 = 0; _key25 < _len25; _key25++) {
|
6069 | args[_key25] = arguments[_key25];
|
6070 | }
|
6071 | return first.apply(void 0, [editor].concat(args));
|
6072 | },
|
6073 | fragment: function fragment$1() {
|
6074 | for (var _len26 = arguments.length, args = new Array(_len26), _key26 = 0; _key26 < _len26; _key26++) {
|
6075 | args[_key26] = arguments[_key26];
|
6076 | }
|
6077 | return fragment.apply(void 0, [editor].concat(args));
|
6078 | },
|
6079 | getMarks: function getMarks() {
|
6080 | for (var _len27 = arguments.length, args = new Array(_len27), _key27 = 0; _key27 < _len27; _key27++) {
|
6081 | args[_key27] = arguments[_key27];
|
6082 | }
|
6083 | return marks.apply(void 0, [editor].concat(args));
|
6084 | },
|
6085 | hasBlocks: function hasBlocks$1() {
|
6086 | for (var _len28 = arguments.length, args = new Array(_len28), _key28 = 0; _key28 < _len28; _key28++) {
|
6087 | args[_key28] = arguments[_key28];
|
6088 | }
|
6089 | return hasBlocks.apply(void 0, [editor].concat(args));
|
6090 | },
|
6091 | hasInlines: function hasInlines$1() {
|
6092 | for (var _len29 = arguments.length, args = new Array(_len29), _key29 = 0; _key29 < _len29; _key29++) {
|
6093 | args[_key29] = arguments[_key29];
|
6094 | }
|
6095 | return hasInlines.apply(void 0, [editor].concat(args));
|
6096 | },
|
6097 | hasPath: function hasPath$1() {
|
6098 | for (var _len30 = arguments.length, args = new Array(_len30), _key30 = 0; _key30 < _len30; _key30++) {
|
6099 | args[_key30] = arguments[_key30];
|
6100 | }
|
6101 | return hasPath.apply(void 0, [editor].concat(args));
|
6102 | },
|
6103 | hasTexts: function hasTexts$1() {
|
6104 | for (var _len31 = arguments.length, args = new Array(_len31), _key31 = 0; _key31 < _len31; _key31++) {
|
6105 | args[_key31] = arguments[_key31];
|
6106 | }
|
6107 | return hasTexts.apply(void 0, [editor].concat(args));
|
6108 | },
|
6109 | insertNodes: function insertNodes$1() {
|
6110 | for (var _len32 = arguments.length, args = new Array(_len32), _key32 = 0; _key32 < _len32; _key32++) {
|
6111 | args[_key32] = arguments[_key32];
|
6112 | }
|
6113 | return insertNodes.apply(void 0, [editor].concat(args));
|
6114 | },
|
6115 | isBlock: function isBlock$1() {
|
6116 | for (var _len33 = arguments.length, args = new Array(_len33), _key33 = 0; _key33 < _len33; _key33++) {
|
6117 | args[_key33] = arguments[_key33];
|
6118 | }
|
6119 | return isBlock.apply(void 0, [editor].concat(args));
|
6120 | },
|
6121 | isEdge: function isEdge$1() {
|
6122 | for (var _len34 = arguments.length, args = new Array(_len34), _key34 = 0; _key34 < _len34; _key34++) {
|
6123 | args[_key34] = arguments[_key34];
|
6124 | }
|
6125 | return isEdge.apply(void 0, [editor].concat(args));
|
6126 | },
|
6127 | isEmpty: function isEmpty$1() {
|
6128 | for (var _len35 = arguments.length, args = new Array(_len35), _key35 = 0; _key35 < _len35; _key35++) {
|
6129 | args[_key35] = arguments[_key35];
|
6130 | }
|
6131 | return isEmpty.apply(void 0, [editor].concat(args));
|
6132 | },
|
6133 | isEnd: function isEnd$1() {
|
6134 | for (var _len36 = arguments.length, args = new Array(_len36), _key36 = 0; _key36 < _len36; _key36++) {
|
6135 | args[_key36] = arguments[_key36];
|
6136 | }
|
6137 | return isEnd.apply(void 0, [editor].concat(args));
|
6138 | },
|
6139 | isNormalizing: function isNormalizing$1() {
|
6140 | for (var _len37 = arguments.length, args = new Array(_len37), _key37 = 0; _key37 < _len37; _key37++) {
|
6141 | args[_key37] = arguments[_key37];
|
6142 | }
|
6143 | return isNormalizing.apply(void 0, [editor].concat(args));
|
6144 | },
|
6145 | isStart: function isStart$1() {
|
6146 | for (var _len38 = arguments.length, args = new Array(_len38), _key38 = 0; _key38 < _len38; _key38++) {
|
6147 | args[_key38] = arguments[_key38];
|
6148 | }
|
6149 | return isStart.apply(void 0, [editor].concat(args));
|
6150 | },
|
6151 | last: function last$1() {
|
6152 | for (var _len39 = arguments.length, args = new Array(_len39), _key39 = 0; _key39 < _len39; _key39++) {
|
6153 | args[_key39] = arguments[_key39];
|
6154 | }
|
6155 | return last.apply(void 0, [editor].concat(args));
|
6156 | },
|
6157 | leaf: function leaf$1() {
|
6158 | for (var _len40 = arguments.length, args = new Array(_len40), _key40 = 0; _key40 < _len40; _key40++) {
|
6159 | args[_key40] = arguments[_key40];
|
6160 | }
|
6161 | return leaf.apply(void 0, [editor].concat(args));
|
6162 | },
|
6163 | levels: function levels$1() {
|
6164 | for (var _len41 = arguments.length, args = new Array(_len41), _key41 = 0; _key41 < _len41; _key41++) {
|
6165 | args[_key41] = arguments[_key41];
|
6166 | }
|
6167 | return levels.apply(void 0, [editor].concat(args));
|
6168 | },
|
6169 | liftNodes: function liftNodes$1() {
|
6170 | for (var _len42 = arguments.length, args = new Array(_len42), _key42 = 0; _key42 < _len42; _key42++) {
|
6171 | args[_key42] = arguments[_key42];
|
6172 | }
|
6173 | return liftNodes.apply(void 0, [editor].concat(args));
|
6174 | },
|
6175 | mergeNodes: function mergeNodes$1() {
|
6176 | for (var _len43 = arguments.length, args = new Array(_len43), _key43 = 0; _key43 < _len43; _key43++) {
|
6177 | args[_key43] = arguments[_key43];
|
6178 | }
|
6179 | return mergeNodes.apply(void 0, [editor].concat(args));
|
6180 | },
|
6181 | move: function move$1() {
|
6182 | for (var _len44 = arguments.length, args = new Array(_len44), _key44 = 0; _key44 < _len44; _key44++) {
|
6183 | args[_key44] = arguments[_key44];
|
6184 | }
|
6185 | return move.apply(void 0, [editor].concat(args));
|
6186 | },
|
6187 | moveNodes: function moveNodes$1() {
|
6188 | for (var _len45 = arguments.length, args = new Array(_len45), _key45 = 0; _key45 < _len45; _key45++) {
|
6189 | args[_key45] = arguments[_key45];
|
6190 | }
|
6191 | return moveNodes.apply(void 0, [editor].concat(args));
|
6192 | },
|
6193 | next: function next$1() {
|
6194 | for (var _len46 = arguments.length, args = new Array(_len46), _key46 = 0; _key46 < _len46; _key46++) {
|
6195 | args[_key46] = arguments[_key46];
|
6196 | }
|
6197 | return next.apply(void 0, [editor].concat(args));
|
6198 | },
|
6199 | node: function node$1() {
|
6200 | for (var _len47 = arguments.length, args = new Array(_len47), _key47 = 0; _key47 < _len47; _key47++) {
|
6201 | args[_key47] = arguments[_key47];
|
6202 | }
|
6203 | return node.apply(void 0, [editor].concat(args));
|
6204 | },
|
6205 | nodes: function nodes$1() {
|
6206 | for (var _len48 = arguments.length, args = new Array(_len48), _key48 = 0; _key48 < _len48; _key48++) {
|
6207 | args[_key48] = arguments[_key48];
|
6208 | }
|
6209 | return nodes.apply(void 0, [editor].concat(args));
|
6210 | },
|
6211 | normalize: function normalize$1() {
|
6212 | for (var _len49 = arguments.length, args = new Array(_len49), _key49 = 0; _key49 < _len49; _key49++) {
|
6213 | args[_key49] = arguments[_key49];
|
6214 | }
|
6215 | return normalize.apply(void 0, [editor].concat(args));
|
6216 | },
|
6217 | parent: function parent$1() {
|
6218 | for (var _len50 = arguments.length, args = new Array(_len50), _key50 = 0; _key50 < _len50; _key50++) {
|
6219 | args[_key50] = arguments[_key50];
|
6220 | }
|
6221 | return parent.apply(void 0, [editor].concat(args));
|
6222 | },
|
6223 | path: function path$1() {
|
6224 | for (var _len51 = arguments.length, args = new Array(_len51), _key51 = 0; _key51 < _len51; _key51++) {
|
6225 | args[_key51] = arguments[_key51];
|
6226 | }
|
6227 | return path.apply(void 0, [editor].concat(args));
|
6228 | },
|
6229 | pathRef: function pathRef$1() {
|
6230 | for (var _len52 = arguments.length, args = new Array(_len52), _key52 = 0; _key52 < _len52; _key52++) {
|
6231 | args[_key52] = arguments[_key52];
|
6232 | }
|
6233 | return pathRef.apply(void 0, [editor].concat(args));
|
6234 | },
|
6235 | pathRefs: function pathRefs$1() {
|
6236 | for (var _len53 = arguments.length, args = new Array(_len53), _key53 = 0; _key53 < _len53; _key53++) {
|
6237 | args[_key53] = arguments[_key53];
|
6238 | }
|
6239 | return pathRefs.apply(void 0, [editor].concat(args));
|
6240 | },
|
6241 | point: function point$1() {
|
6242 | for (var _len54 = arguments.length, args = new Array(_len54), _key54 = 0; _key54 < _len54; _key54++) {
|
6243 | args[_key54] = arguments[_key54];
|
6244 | }
|
6245 | return point.apply(void 0, [editor].concat(args));
|
6246 | },
|
6247 | pointRef: function pointRef$1() {
|
6248 | for (var _len55 = arguments.length, args = new Array(_len55), _key55 = 0; _key55 < _len55; _key55++) {
|
6249 | args[_key55] = arguments[_key55];
|
6250 | }
|
6251 | return pointRef.apply(void 0, [editor].concat(args));
|
6252 | },
|
6253 | pointRefs: function pointRefs$1() {
|
6254 | for (var _len56 = arguments.length, args = new Array(_len56), _key56 = 0; _key56 < _len56; _key56++) {
|
6255 | args[_key56] = arguments[_key56];
|
6256 | }
|
6257 | return pointRefs.apply(void 0, [editor].concat(args));
|
6258 | },
|
6259 | positions: function positions$1() {
|
6260 | for (var _len57 = arguments.length, args = new Array(_len57), _key57 = 0; _key57 < _len57; _key57++) {
|
6261 | args[_key57] = arguments[_key57];
|
6262 | }
|
6263 | return positions.apply(void 0, [editor].concat(args));
|
6264 | },
|
6265 | previous: function previous$1() {
|
6266 | for (var _len58 = arguments.length, args = new Array(_len58), _key58 = 0; _key58 < _len58; _key58++) {
|
6267 | args[_key58] = arguments[_key58];
|
6268 | }
|
6269 | return previous.apply(void 0, [editor].concat(args));
|
6270 | },
|
6271 | range: function range$1() {
|
6272 | for (var _len59 = arguments.length, args = new Array(_len59), _key59 = 0; _key59 < _len59; _key59++) {
|
6273 | args[_key59] = arguments[_key59];
|
6274 | }
|
6275 | return range.apply(void 0, [editor].concat(args));
|
6276 | },
|
6277 | rangeRef: function rangeRef$1() {
|
6278 | for (var _len60 = arguments.length, args = new Array(_len60), _key60 = 0; _key60 < _len60; _key60++) {
|
6279 | args[_key60] = arguments[_key60];
|
6280 | }
|
6281 | return rangeRef.apply(void 0, [editor].concat(args));
|
6282 | },
|
6283 | rangeRefs: function rangeRefs$1() {
|
6284 | for (var _len61 = arguments.length, args = new Array(_len61), _key61 = 0; _key61 < _len61; _key61++) {
|
6285 | args[_key61] = arguments[_key61];
|
6286 | }
|
6287 | return rangeRefs.apply(void 0, [editor].concat(args));
|
6288 | },
|
6289 | removeNodes: function removeNodes$1() {
|
6290 | for (var _len62 = arguments.length, args = new Array(_len62), _key62 = 0; _key62 < _len62; _key62++) {
|
6291 | args[_key62] = arguments[_key62];
|
6292 | }
|
6293 | return removeNodes.apply(void 0, [editor].concat(args));
|
6294 | },
|
6295 | select: function select$1() {
|
6296 | for (var _len63 = arguments.length, args = new Array(_len63), _key63 = 0; _key63 < _len63; _key63++) {
|
6297 | args[_key63] = arguments[_key63];
|
6298 | }
|
6299 | return select.apply(void 0, [editor].concat(args));
|
6300 | },
|
6301 | setNodes: function setNodes$1() {
|
6302 | for (var _len64 = arguments.length, args = new Array(_len64), _key64 = 0; _key64 < _len64; _key64++) {
|
6303 | args[_key64] = arguments[_key64];
|
6304 | }
|
6305 | return setNodes.apply(void 0, [editor].concat(args));
|
6306 | },
|
6307 | setNormalizing: function setNormalizing$1() {
|
6308 | for (var _len65 = arguments.length, args = new Array(_len65), _key65 = 0; _key65 < _len65; _key65++) {
|
6309 | args[_key65] = arguments[_key65];
|
6310 | }
|
6311 | return setNormalizing.apply(void 0, [editor].concat(args));
|
6312 | },
|
6313 | setPoint: function setPoint$1() {
|
6314 | for (var _len66 = arguments.length, args = new Array(_len66), _key66 = 0; _key66 < _len66; _key66++) {
|
6315 | args[_key66] = arguments[_key66];
|
6316 | }
|
6317 | return setPoint.apply(void 0, [editor].concat(args));
|
6318 | },
|
6319 | setSelection: function setSelection$1() {
|
6320 | for (var _len67 = arguments.length, args = new Array(_len67), _key67 = 0; _key67 < _len67; _key67++) {
|
6321 | args[_key67] = arguments[_key67];
|
6322 | }
|
6323 | return setSelection.apply(void 0, [editor].concat(args));
|
6324 | },
|
6325 | splitNodes: function splitNodes$1() {
|
6326 | for (var _len68 = arguments.length, args = new Array(_len68), _key68 = 0; _key68 < _len68; _key68++) {
|
6327 | args[_key68] = arguments[_key68];
|
6328 | }
|
6329 | return splitNodes.apply(void 0, [editor].concat(args));
|
6330 | },
|
6331 | start: function start$1() {
|
6332 | for (var _len69 = arguments.length, args = new Array(_len69), _key69 = 0; _key69 < _len69; _key69++) {
|
6333 | args[_key69] = arguments[_key69];
|
6334 | }
|
6335 | return start.apply(void 0, [editor].concat(args));
|
6336 | },
|
6337 | string: function string$1() {
|
6338 | for (var _len70 = arguments.length, args = new Array(_len70), _key70 = 0; _key70 < _len70; _key70++) {
|
6339 | args[_key70] = arguments[_key70];
|
6340 | }
|
6341 | return string.apply(void 0, [editor].concat(args));
|
6342 | },
|
6343 | unhangRange: function unhangRange$1() {
|
6344 | for (var _len71 = arguments.length, args = new Array(_len71), _key71 = 0; _key71 < _len71; _key71++) {
|
6345 | args[_key71] = arguments[_key71];
|
6346 | }
|
6347 | return unhangRange.apply(void 0, [editor].concat(args));
|
6348 | },
|
6349 | unsetNodes: function unsetNodes$1() {
|
6350 | for (var _len72 = arguments.length, args = new Array(_len72), _key72 = 0; _key72 < _len72; _key72++) {
|
6351 | args[_key72] = arguments[_key72];
|
6352 | }
|
6353 | return unsetNodes.apply(void 0, [editor].concat(args));
|
6354 | },
|
6355 | unwrapNodes: function unwrapNodes$1() {
|
6356 | for (var _len73 = arguments.length, args = new Array(_len73), _key73 = 0; _key73 < _len73; _key73++) {
|
6357 | args[_key73] = arguments[_key73];
|
6358 | }
|
6359 | return unwrapNodes.apply(void 0, [editor].concat(args));
|
6360 | },
|
6361 | "void": function _void() {
|
6362 | for (var _len74 = arguments.length, args = new Array(_len74), _key74 = 0; _key74 < _len74; _key74++) {
|
6363 | args[_key74] = arguments[_key74];
|
6364 | }
|
6365 | return getVoid.apply(void 0, [editor].concat(args));
|
6366 | },
|
6367 | withoutNormalizing: function withoutNormalizing$1() {
|
6368 | for (var _len75 = arguments.length, args = new Array(_len75), _key75 = 0; _key75 < _len75; _key75++) {
|
6369 | args[_key75] = arguments[_key75];
|
6370 | }
|
6371 | return withoutNormalizing.apply(void 0, [editor].concat(args));
|
6372 | },
|
6373 | wrapNodes: function wrapNodes$1() {
|
6374 | for (var _len76 = arguments.length, args = new Array(_len76), _key76 = 0; _key76 < _len76; _key76++) {
|
6375 | args[_key76] = arguments[_key76];
|
6376 | }
|
6377 | return wrapNodes.apply(void 0, [editor].concat(args));
|
6378 | },
|
6379 | shouldMergeNodesRemovePrevNode: function shouldMergeNodesRemovePrevNode$1() {
|
6380 | for (var _len77 = arguments.length, args = new Array(_len77), _key77 = 0; _key77 < _len77; _key77++) {
|
6381 | args[_key77] = arguments[_key77];
|
6382 | }
|
6383 | return shouldMergeNodesRemovePrevNode.apply(void 0, [editor].concat(args));
|
6384 | }
|
6385 | };
|
6386 | return editor;
|
6387 | };
|
6388 |
|
6389 | exports.Editor = Editor;
|
6390 | exports.Element = Element;
|
6391 | exports.Location = Location;
|
6392 | exports.Node = Node;
|
6393 | exports.Operation = Operation;
|
6394 | exports.Path = Path;
|
6395 | exports.PathRef = PathRef;
|
6396 | exports.Point = Point;
|
6397 | exports.PointRef = PointRef;
|
6398 | exports.Range = Range;
|
6399 | exports.RangeRef = RangeRef;
|
6400 | exports.Scrubber = Scrubber;
|
6401 | exports.Span = Span;
|
6402 | exports.Text = Text;
|
6403 | exports.Transforms = Transforms;
|
6404 | exports.above = above;
|
6405 | exports.addMark = addMark;
|
6406 | exports.after = after;
|
6407 | exports.apply = apply;
|
6408 | exports.before = before;
|
6409 | exports.collapse = collapse;
|
6410 | exports.createEditor = createEditor;
|
6411 | exports.deleteBackward = deleteBackward;
|
6412 | exports.deleteForward = deleteForward;
|
6413 | exports.deleteFragment = deleteFragment;
|
6414 | exports.deleteText = deleteText;
|
6415 | exports.deselect = deselect;
|
6416 | exports.edges = edges;
|
6417 | exports.elementReadOnly = elementReadOnly;
|
6418 | exports.end = end;
|
6419 | exports.first = first;
|
6420 | exports.fragment = fragment;
|
6421 | exports.getDirtyPaths = getDirtyPaths;
|
6422 | exports.getFragment = getFragment;
|
6423 | exports.getVoid = getVoid;
|
6424 | exports.hasBlocks = hasBlocks;
|
6425 | exports.hasInlines = hasInlines;
|
6426 | exports.hasPath = hasPath;
|
6427 | exports.hasTexts = hasTexts;
|
6428 | exports.insertBreak = insertBreak;
|
6429 | exports.insertFragment = insertFragment;
|
6430 | exports.insertNode = insertNode;
|
6431 | exports.insertNodes = insertNodes;
|
6432 | exports.insertSoftBreak = insertSoftBreak;
|
6433 | exports.insertText = insertText;
|
6434 | exports.isBlock = isBlock;
|
6435 | exports.isEdge = isEdge;
|
6436 | exports.isEditor = isEditor;
|
6437 | exports.isEmpty = isEmpty;
|
6438 | exports.isEnd = isEnd;
|
6439 | exports.isNormalizing = isNormalizing;
|
6440 | exports.isStart = isStart;
|
6441 | exports.last = last;
|
6442 | exports.leaf = leaf;
|
6443 | exports.levels = levels;
|
6444 | exports.liftNodes = liftNodes;
|
6445 | exports.marks = marks;
|
6446 | exports.mergeNodes = mergeNodes;
|
6447 | exports.move = move;
|
6448 | exports.moveNodes = moveNodes;
|
6449 | exports.next = next;
|
6450 | exports.node = node;
|
6451 | exports.nodes = nodes;
|
6452 | exports.normalize = normalize;
|
6453 | exports.normalizeNode = normalizeNode;
|
6454 | exports.parent = parent;
|
6455 | exports.path = path;
|
6456 | exports.pathRef = pathRef;
|
6457 | exports.pathRefs = pathRefs;
|
6458 | exports.point = point;
|
6459 | exports.pointRef = pointRef;
|
6460 | exports.pointRefs = pointRefs;
|
6461 | exports.positions = positions;
|
6462 | exports.previous = previous;
|
6463 | exports.range = range;
|
6464 | exports.rangeRef = rangeRef;
|
6465 | exports.rangeRefs = rangeRefs;
|
6466 | exports.removeMark = removeMark;
|
6467 | exports.removeNodes = removeNodes;
|
6468 | exports.select = select;
|
6469 | exports.setNodes = setNodes;
|
6470 | exports.setNormalizing = setNormalizing;
|
6471 | exports.setPoint = setPoint;
|
6472 | exports.setSelection = setSelection;
|
6473 | exports.shouldMergeNodesRemovePrevNode = shouldMergeNodesRemovePrevNode;
|
6474 | exports.shouldNormalize = shouldNormalize;
|
6475 | exports.splitNodes = splitNodes;
|
6476 | exports.start = start;
|
6477 | exports.string = string;
|
6478 | exports.unhangRange = unhangRange;
|
6479 | exports.unsetNodes = unsetNodes;
|
6480 | exports.unwrapNodes = unwrapNodes;
|
6481 | exports.withoutNormalizing = withoutNormalizing;
|
6482 | exports.wrapNodes = wrapNodes;
|
6483 |
|