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