@wangeditor-next/yjs 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,1719 +1,2 @@
1
- import { Text, Node, Path, Editor, Transforms } from 'slate'
2
- import * as Y from 'yjs'
3
-
4
- /******************************************************************************
5
- Copyright (c) Microsoft Corporation.
6
-
7
- Permission to use, copy, modify, and/or distribute this software for any
8
- purpose with or without fee is hereby granted.
9
-
10
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
- PERFORMANCE OF THIS SOFTWARE.
17
- ***************************************************************************** */
18
-
19
- var __assign = function () {
20
- __assign =
21
- Object.assign ||
22
- function __assign(t) {
23
- for (var s, i = 1, n = arguments.length; i < n; i++) {
24
- s = arguments[i]
25
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]
26
- }
27
- return t
28
- }
29
- return __assign.apply(this, arguments)
30
- }
31
-
32
- function __rest(s, e) {
33
- var t = {}
34
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]
35
- if (s != null && typeof Object.getOwnPropertySymbols === 'function')
36
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
37
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
38
- t[p[i]] = s[p[i]]
39
- }
40
- return t
41
- }
42
-
43
- function __values(o) {
44
- var s = typeof Symbol === 'function' && Symbol.iterator,
45
- m = s && o[s],
46
- i = 0
47
- if (m) return m.call(o)
48
- if (o && typeof o.length === 'number')
49
- return {
50
- next: function () {
51
- if (o && i >= o.length) o = void 0
52
- return { value: o && o[i++], done: !o }
53
- },
54
- }
55
- throw new TypeError(s ? 'Object is not iterable.' : 'Symbol.iterator is not defined.')
56
- }
57
-
58
- function __read(o, n) {
59
- var m = typeof Symbol === 'function' && o[Symbol.iterator]
60
- if (!m) return o
61
- var i = m.call(o),
62
- r,
63
- ar = [],
64
- e
65
- try {
66
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value)
67
- } catch (error) {
68
- e = { error: error }
69
- } finally {
70
- try {
71
- if (r && !r.done && (m = i['return'])) m.call(i)
72
- } finally {
73
- if (e) throw e.error
74
- }
75
- }
76
- return ar
77
- }
78
-
79
- function __spreadArray(to, from, pack) {
80
- if (pack || arguments.length === 2)
81
- for (var i = 0, l = from.length, ar; i < l; i++) {
82
- if (ar || !(i in from)) {
83
- if (!ar) ar = Array.prototype.slice.call(from, 0, i)
84
- ar[i] = from[i]
85
- }
86
- }
87
- return to.concat(ar || Array.prototype.slice.call(from))
88
- }
89
-
90
- typeof SuppressedError === 'function'
91
- ? SuppressedError
92
- : function (error, suppressed, message) {
93
- var e = new Error(message)
94
- return (e.name = 'SuppressedError'), (e.error = error), (e.suppressed = suppressed), e
95
- }
96
-
97
- function isObject(o) {
98
- return Object.prototype.toString.call(o) === '[object Object]'
99
- }
100
- function isPlainObject(o) {
101
- if (!isObject(o)) {
102
- return false
103
- }
104
- // If has modified constructor
105
- var ctor = o.constructor
106
- if (ctor === undefined) {
107
- return true
108
- }
109
- // If has modified prototype
110
- var prot = ctor.prototype
111
- if (isObject(prot) === false) {
112
- return false
113
- }
114
- // If constructor does not have an Object-specific method
115
- if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOfOf')) {
116
- return false
117
- }
118
- // Most likely a plain Object
119
- return true
120
- }
121
- // Slates deep equality function: https://github.com/ianstormtaylor/slate/blob/68aff89e892fe15a16314398ff052ade6068900b/packages/slate/src/utils/deep-equal.ts#L13
122
- // We have to match slates deepEquals behavior to merge insert deltas in the same way slate does.
123
- function deepEquals(node, another) {
124
- // eslint-disable-next-line guard-for-in
125
- for (var key in node) {
126
- var a = node[key]
127
- var b = another[key]
128
- if (isPlainObject(a) && isPlainObject(b)) {
129
- if (!deepEquals(a, b)) {
130
- return false
131
- }
132
- } else if (Array.isArray(a) && Array.isArray(b)) {
133
- if (a.length !== b.length) return false
134
- for (var i = 0; i < a.length; i++) {
135
- if (a[i] !== b[i]) {
136
- return false
137
- }
138
- }
139
- } else if (a !== b) {
140
- return false
141
- }
142
- }
143
- for (var key in another) {
144
- if (node[key] === undefined && another[key] !== undefined) {
145
- return false
146
- }
147
- }
148
- return true
149
- }
150
- function pick(obj) {
151
- var keys = []
152
- for (var _i = 1; _i < arguments.length; _i++) {
153
- keys[_i - 1] = arguments[_i]
154
- }
155
- return Object.fromEntries(
156
- Object.entries(obj).filter(function (_a) {
157
- var _b = __read(_a, 1),
158
- key = _b[0]
159
- return keys.includes(key)
160
- })
161
- )
162
- }
163
- function omit(obj) {
164
- var keys = []
165
- for (var _i = 1; _i < arguments.length; _i++) {
166
- keys[_i - 1] = arguments[_i]
167
- }
168
- return Object.fromEntries(
169
- Object.entries(obj).filter(function (_a) {
170
- var _b = __read(_a, 1),
171
- key = _b[0]
172
- return !keys.includes(key)
173
- })
174
- )
175
- }
176
- function omitNullEntries(obj) {
177
- return Object.fromEntries(
178
- Object.entries(obj).filter(function (_a) {
179
- var _b = __read(_a, 2),
180
- value = _b[1]
181
- return value !== null
182
- })
183
- )
184
- }
185
-
186
- function normalizeInsertDelta(delta) {
187
- var e_1, _a
188
- var _b, _c
189
- var normalized = []
190
- try {
191
- for (
192
- var delta_1 = __values(delta), delta_1_1 = delta_1.next();
193
- !delta_1_1.done;
194
- delta_1_1 = delta_1.next()
195
- ) {
196
- var element = delta_1_1.value
197
- if (typeof element.insert === 'string' && element.insert.length === 0) {
198
- continue
199
- }
200
- var prev = normalized[normalized.length - 1]
201
- if (!prev || typeof prev.insert !== 'string' || typeof element.insert !== 'string') {
202
- normalized.push(element)
203
- continue
204
- }
205
- var merge =
206
- prev.attributes === element.attributes ||
207
- (!prev.attributes === !element.attributes &&
208
- deepEquals(
209
- (_b = prev.attributes) !== null && _b !== void 0 ? _b : {},
210
- (_c = element.attributes) !== null && _c !== void 0 ? _c : {}
211
- ))
212
- if (merge) {
213
- prev.insert += element.insert
214
- continue
215
- }
216
- normalized.push(element)
217
- }
218
- } catch (e_1_1) {
219
- e_1 = { error: e_1_1 }
220
- } finally {
221
- try {
222
- if (delta_1_1 && !delta_1_1.done && (_a = delta_1.return)) _a.call(delta_1)
223
- } finally {
224
- if (e_1) throw e_1.error
225
- }
226
- }
227
- return normalized
228
- }
229
- function yTextToInsertDelta(yText) {
230
- return normalizeInsertDelta(yText.toDelta())
231
- }
232
- function getInsertLength(_a) {
233
- var insert = _a.insert
234
- return typeof insert === 'string' ? insert.length : 1
235
- }
236
- function getInsertDeltaLength(delta) {
237
- return delta.reduce(function (curr, element) {
238
- return curr + getInsertLength(element)
239
- }, 0)
240
- }
241
- function sliceInsertDelta(delta, start, length) {
242
- if (length < 1) {
243
- return []
244
- }
245
- var currentOffset = 0
246
- var sliced = []
247
- var end = start + length
248
- for (var i = 0; i < delta.length; i++) {
249
- if (currentOffset >= end) {
250
- break
251
- }
252
- var element = delta[i]
253
- var elementLength = getInsertLength(element)
254
- if (currentOffset + elementLength <= start) {
255
- currentOffset += elementLength
256
- continue
257
- }
258
- if (typeof element.insert !== 'string') {
259
- currentOffset += elementLength
260
- sliced.push(element)
261
- continue
262
- }
263
- var startOffset = Math.max(0, start - currentOffset)
264
- var endOffset = Math.min(elementLength, elementLength - (currentOffset + elementLength - end))
265
- sliced.push(
266
- __assign(__assign({}, element), { insert: element.insert.slice(startOffset, endOffset) })
267
- )
268
- currentOffset += elementLength
269
- }
270
- return sliced
271
- }
272
-
273
- function getProperties(node) {
274
- return omit(node, Text.isText(node) ? 'text' : 'children')
275
- }
276
-
277
- function yTextToSlateElement(yText) {
278
- var delta = yTextToInsertDelta(yText)
279
- var children = delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }]
280
- return __assign(__assign({}, yText.getAttributes()), { children: children })
281
- }
282
- function deltaInsertToSlateNode(insert) {
283
- if (typeof insert.insert === 'string') {
284
- return __assign(__assign({}, insert.attributes), { text: insert.insert })
285
- }
286
- return yTextToSlateElement(insert.insert)
287
- }
288
- function slateNodesToInsertDelta(nodes) {
289
- return nodes.map(function (node) {
290
- if (Text.isText(node)) {
291
- return { insert: node.text, attributes: getProperties(node) }
292
- }
293
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
294
- return { insert: slateElementToYText(node) }
295
- })
296
- }
297
- function slateElementToYText(_a) {
298
- var children = _a.children,
299
- attributes = __rest(_a, ['children'])
300
- var yElement = new Y.XmlText()
301
- Object.entries(attributes).forEach(function (_a) {
302
- var _b = __read(_a, 2),
303
- key = _b[0],
304
- value = _b[1]
305
- yElement.setAttribute(key, value)
306
- })
307
- yElement.applyDelta(slateNodesToInsertDelta(children), { sanitize: false })
308
- return yElement
309
- }
310
-
311
- function getSlateNodeYLength(node) {
312
- if (!node) {
313
- return 0
314
- }
315
- return Text.isText(node) ? node.text.length : 1
316
- }
317
- function slatePathOffsetToYOffset(element, pathOffset) {
318
- return element.children.slice(0, pathOffset).reduce(function (yOffset, node) {
319
- return yOffset + getSlateNodeYLength(node)
320
- }, 0)
321
- }
322
- function getYTarget(yRoot, slateRoot, path) {
323
- var _a
324
- if (path.length === 0) {
325
- throw new Error('Path has to a have a length >= 1')
326
- }
327
- if (Text.isText(slateRoot)) {
328
- throw new Error('Cannot descent into slate text')
329
- }
330
- var _b = __read(path),
331
- pathOffset = _b[0],
332
- childPath = _b.slice(1)
333
- var yOffset = slatePathOffsetToYOffset(slateRoot, pathOffset)
334
- var targetNode = slateRoot.children[pathOffset]
335
- var delta = yTextToInsertDelta(yRoot)
336
- var targetLength = getSlateNodeYLength(targetNode)
337
- var targetDelta = sliceInsertDelta(delta, yOffset, targetLength)
338
- if (targetDelta.length > 1) {
339
- throw new Error("Path doesn't match yText, yTarget spans multiple nodes")
340
- }
341
- var yTarget = (_a = targetDelta[0]) === null || _a === void 0 ? void 0 : _a.insert
342
- if (childPath.length > 0) {
343
- if (!(yTarget instanceof Y.XmlText)) {
344
- throw new Error("Path doesn't match yText, cannot descent into non-yText")
345
- }
346
- return getYTarget(yTarget, targetNode, childPath)
347
- }
348
- return {
349
- yParent: yRoot,
350
- textRange: { start: yOffset, end: yOffset + targetLength },
351
- yTarget: yTarget instanceof Y.XmlText ? yTarget : undefined,
352
- slateParent: slateRoot,
353
- slateTarget: targetNode,
354
- targetDelta: targetDelta,
355
- }
356
- }
357
- function yOffsetToSlateOffsets(parent, yOffset, opts) {
358
- if (opts === void 0) {
359
- opts = {}
360
- }
361
- var _a = opts.assoc,
362
- assoc = _a === void 0 ? 0 : _a,
363
- _b = opts.insert,
364
- insert = _b === void 0 ? false : _b
365
- var currentOffset = 0
366
- var lastNonEmptyPathOffset = 0
367
- for (var pathOffset = 0; pathOffset < parent.children.length; pathOffset++) {
368
- var child_1 = parent.children[pathOffset]
369
- var nodeLength = Text.isText(child_1) ? child_1.text.length : 1
370
- if (nodeLength > 0) {
371
- lastNonEmptyPathOffset = pathOffset
372
- }
373
- var endOffset = currentOffset + nodeLength
374
- if (nodeLength > 0 && (assoc >= 0 ? endOffset > yOffset : endOffset >= yOffset)) {
375
- return [pathOffset, yOffset - currentOffset]
376
- }
377
- currentOffset += nodeLength
378
- }
379
- if (yOffset > currentOffset + (insert ? 1 : 0)) {
380
- throw new Error('yOffset out of bounds')
381
- }
382
- if (insert) {
383
- return [parent.children.length, 0]
384
- }
385
- var child = parent.children[lastNonEmptyPathOffset]
386
- var textOffset = Text.isText(child) ? child.text.length : 1
387
- return [lastNonEmptyPathOffset, textOffset]
388
- }
389
- function getSlatePath(sharedRoot, slateRoot, yText) {
390
- var yNodePath = [yText]
391
- while (yNodePath[0] !== sharedRoot) {
392
- var yParent = yNodePath[0].parent
393
- if (!yParent) {
394
- throw new Error("yText isn't a descendant of root element")
395
- }
396
- if (!(yParent instanceof Y.XmlText)) {
397
- throw new Error('Unexpected y parent type')
398
- }
399
- yNodePath.unshift(yParent)
400
- }
401
- if (yNodePath.length < 2) {
402
- return []
403
- }
404
- var slateParent = slateRoot
405
- return yNodePath.reduce(function (path, yParent, idx) {
406
- var e_1, _a
407
- var yChild = yNodePath[idx + 1]
408
- if (!yChild) {
409
- return path
410
- }
411
- var yOffset = 0
412
- var currentDelta = yTextToInsertDelta(yParent)
413
- try {
414
- for (
415
- var currentDelta_1 = __values(currentDelta), currentDelta_1_1 = currentDelta_1.next();
416
- !currentDelta_1_1.done;
417
- currentDelta_1_1 = currentDelta_1.next()
418
- ) {
419
- var element = currentDelta_1_1.value
420
- if (element.insert === yChild) {
421
- break
422
- }
423
- yOffset += typeof element.insert === 'string' ? element.insert.length : 1
424
- }
425
- } catch (e_1_1) {
426
- e_1 = { error: e_1_1 }
427
- } finally {
428
- try {
429
- if (currentDelta_1_1 && !currentDelta_1_1.done && (_a = currentDelta_1.return))
430
- _a.call(currentDelta_1)
431
- } finally {
432
- if (e_1) throw e_1.error
433
- }
434
- }
435
- if (Text.isText(slateParent)) {
436
- throw new Error('Cannot descent into slate text')
437
- }
438
- var _b = __read(yOffsetToSlateOffsets(slateParent, yOffset), 1),
439
- pathOffset = _b[0]
440
- slateParent = slateParent.children[pathOffset]
441
- return path.concat(pathOffset)
442
- }, [])
443
- }
444
-
445
- function applyDelta(node, slatePath, delta) {
446
- var ops = []
447
- var yOffset = delta.reduce(function (length, change) {
448
- if ('retain' in change) {
449
- return length + change.retain
450
- }
451
- if ('delete' in change) {
452
- return length + change.delete
453
- }
454
- return length
455
- }, 0)
456
- // Apply changes in reverse order to avoid path changes.
457
- delta.reverse().forEach(function (change) {
458
- var _a
459
- if ('attributes' in change && 'retain' in change) {
460
- var _b = __read(yOffsetToSlateOffsets(node, yOffset - change.retain), 2),
461
- startPathOffset = _b[0],
462
- startTextOffset = _b[1]
463
- var _c = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2),
464
- endPathOffset = _c[0],
465
- endTextOffset = _c[1]
466
- for (var pathOffset = endPathOffset; pathOffset >= startPathOffset; pathOffset--) {
467
- var child = node.children[pathOffset]
468
- var childPath = __spreadArray(__spreadArray([], __read(slatePath)), [pathOffset])
469
- if (!Text.isText(child)) {
470
- // Ignore attribute updates on non-text nodes (which are backed by Y.XmlText)
471
- // to be consistent with deltaInsertToSlateNode. Y.XmlText attributes don't show
472
- // up in deltas but in key changes (YEvent.changes.keys).
473
- continue
474
- }
475
- var newProperties = change.attributes
476
- var properties = pick.apply(
477
- void 0,
478
- __spreadArray([node], __read(Object.keys(change.attributes)))
479
- )
480
- if (pathOffset === startPathOffset || pathOffset === endPathOffset) {
481
- var start = pathOffset === startPathOffset ? startTextOffset : 0
482
- var end = pathOffset === endPathOffset ? endTextOffset : child.text.length
483
- if (end !== child.text.length) {
484
- ops.push({
485
- type: 'split_node',
486
- path: childPath,
487
- position: end,
488
- properties: getProperties(child),
489
- })
490
- }
491
- if (start !== 0) {
492
- ops.push({
493
- type: 'split_node',
494
- path: childPath,
495
- position: start,
496
- properties: omitNullEntries(
497
- __assign(__assign({}, getProperties(child)), newProperties)
498
- ),
499
- })
500
- continue
501
- }
502
- }
503
- ops.push({
504
- type: 'set_node',
505
- newProperties: newProperties,
506
- path: childPath,
507
- properties: properties,
508
- })
509
- }
510
- }
511
- if ('retain' in change) {
512
- yOffset -= change.retain
513
- }
514
- if ('delete' in change) {
515
- var _d = __read(yOffsetToSlateOffsets(node, yOffset - change.delete), 2),
516
- startPathOffset = _d[0],
517
- startTextOffset = _d[1]
518
- var _e = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2),
519
- endPathOffset = _e[0],
520
- endTextOffset = _e[1]
521
- for (
522
- var pathOffset = endTextOffset === 0 ? endPathOffset - 1 : endPathOffset;
523
- pathOffset >= startPathOffset;
524
- pathOffset--
525
- ) {
526
- var child = node.children[pathOffset]
527
- var childPath = __spreadArray(__spreadArray([], __read(slatePath)), [pathOffset])
528
- if (
529
- Text.isText(child) &&
530
- (pathOffset === startPathOffset || pathOffset === endPathOffset)
531
- ) {
532
- var start = pathOffset === startPathOffset ? startTextOffset : 0
533
- var end = pathOffset === endPathOffset ? endTextOffset : child.text.length
534
- ops.push({
535
- type: 'remove_text',
536
- offset: start,
537
- text: child.text.slice(start, end),
538
- path: childPath,
539
- })
540
- yOffset -= end - start
541
- continue
542
- }
543
- ops.push({
544
- type: 'remove_node',
545
- node: child,
546
- path: childPath,
547
- })
548
- yOffset -= getSlateNodeYLength(child)
549
- }
550
- return
551
- }
552
- if ('insert' in change) {
553
- var _f = __read(
554
- yOffsetToSlateOffsets(node, yOffset, {
555
- insert: true,
556
- }),
557
- 2
558
- ),
559
- pathOffset = _f[0],
560
- textOffset = _f[1]
561
- var child = node.children[pathOffset]
562
- var childPath = __spreadArray(__spreadArray([], __read(slatePath)), [pathOffset])
563
- if (Text.isText(child)) {
564
- var lastOp = ops[ops.length - 1]
565
- /**
566
- * The props that exist at the current path
567
- * Since we're not actually using slate to update the node
568
- * this is a simulation
569
- */
570
- var currentProps =
571
- lastOp != null && lastOp.type === 'insert_node' ? lastOp.node : getProperties(child)
572
- var lastPath = []
573
- if (
574
- lastOp != null &&
575
- (lastOp.type === 'insert_node' ||
576
- lastOp.type === 'insert_text' ||
577
- lastOp.type === 'split_node' ||
578
- lastOp.type === 'set_node')
579
- ) {
580
- lastPath = lastOp.path
581
- }
582
- /**
583
- * If the insert is a string and the attributes are the same as the
584
- * props at the current path, we can just insert a text node
585
- */
586
- if (
587
- typeof change.insert === 'string' &&
588
- deepEquals((_a = change.attributes) !== null && _a !== void 0 ? _a : {}, currentProps) &&
589
- Path.equals(childPath, lastPath)
590
- ) {
591
- return ops.push({
592
- type: 'insert_text',
593
- offset: textOffset,
594
- text: change.insert,
595
- path: childPath,
596
- })
597
- }
598
- var toInsert = deltaInsertToSlateNode(change)
599
- if (textOffset === 0) {
600
- return ops.push({
601
- type: 'insert_node',
602
- path: childPath,
603
- node: toInsert,
604
- })
605
- }
606
- if (textOffset < child.text.length) {
607
- ops.push({
608
- type: 'split_node',
609
- path: childPath,
610
- position: textOffset,
611
- properties: getProperties(child),
612
- })
613
- }
614
- return ops.push({
615
- type: 'insert_node',
616
- path: Path.next(childPath),
617
- node: toInsert,
618
- })
619
- }
620
- return ops.push({
621
- type: 'insert_node',
622
- path: childPath,
623
- node: deltaInsertToSlateNode(change),
624
- })
625
- }
626
- })
627
- return ops
628
- }
629
- function translateYTextEvent(sharedRoot, editor, event) {
630
- var target = event.target,
631
- changes = event.changes
632
- var delta = event.delta
633
- if (!(target instanceof Y.XmlText)) {
634
- throw new Error('Unexpected target node type')
635
- }
636
- var ops = []
637
- var slatePath = getSlatePath(sharedRoot, editor, target)
638
- var targetElement = Node.get(editor, slatePath)
639
- if (Text.isText(targetElement)) {
640
- throw new Error('Cannot apply yTextEvent to text node')
641
- }
642
- var keyChanges = Array.from(changes.keys.entries())
643
- if (slatePath.length > 0 && keyChanges.length > 0) {
644
- var newProperties = Object.fromEntries(
645
- keyChanges.map(function (_a) {
646
- var _b = __read(_a, 2),
647
- key = _b[0],
648
- info = _b[1]
649
- return [key, info.action === 'delete' ? null : target.getAttribute(key)]
650
- })
651
- )
652
- var properties = Object.fromEntries(
653
- keyChanges.map(function (_a) {
654
- var _b = __read(_a, 1),
655
- key = _b[0]
656
- return [key, targetElement[key]]
657
- })
658
- )
659
- ops.push({
660
- type: 'set_node',
661
- newProperties: newProperties,
662
- properties: properties,
663
- path: slatePath,
664
- })
665
- }
666
- if (delta.length > 0) {
667
- ops.push.apply(ops, __spreadArray([], __read(applyDelta(targetElement, slatePath, delta))))
668
- }
669
- return ops
670
- }
671
-
672
- /**
673
- * Translate a yjs event into slate operations. The editor state has to match the
674
- * yText state before the event occurred.
675
- *
676
- * @param sharedType
677
- * @param op
678
- */
679
- function translateYjsEvent(sharedRoot, editor, event) {
680
- if (event instanceof Y.YTextEvent) {
681
- return translateYTextEvent(sharedRoot, editor, event)
682
- }
683
- throw new Error('Unexpected Y event type')
684
- }
685
- /**
686
- * Translates yjs events into slate operations and applies them to the editor. The
687
- * editor state has to match the yText state before the events occurred.
688
- *
689
- * @param sharedRoot
690
- * @param editor
691
- * @param events
692
- */
693
- function applyYjsEvents(sharedRoot, editor, events) {
694
- Editor.withoutNormalizing(editor, function () {
695
- events.forEach(function (event) {
696
- translateYjsEvent(sharedRoot, editor, event).forEach(function (op) {
697
- editor.apply(op)
698
- })
699
- })
700
- })
701
- }
702
-
703
- function insertNode(sharedRoot, slateRoot, op) {
704
- var _a = getYTarget(sharedRoot, slateRoot, op.path),
705
- yParent = _a.yParent,
706
- textRange = _a.textRange
707
- if (Text.isText(op.node)) {
708
- return yParent.insert(textRange.start, op.node.text, getProperties(op.node))
709
- }
710
- yParent.insertEmbed(textRange.start, slateElementToYText(op.node))
711
- }
712
-
713
- function cloneInsertDeltaDeep(delta) {
714
- return delta.map(function (element) {
715
- if (typeof element.insert === 'string') {
716
- return element
717
- }
718
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
719
- return __assign(__assign({}, element), { insert: cloneDeep(element.insert) })
720
- })
721
- }
722
- function cloneDeep(yText) {
723
- var clone = new Y.XmlText()
724
- var attributes = yText.getAttributes()
725
- Object.entries(attributes).forEach(function (_a) {
726
- var _b = __read(_a, 2),
727
- key = _b[0],
728
- value = _b[1]
729
- clone.setAttribute(key, value)
730
- })
731
- clone.applyDelta(cloneInsertDeltaDeep(yTextToInsertDelta(yText)), {
732
- sanitize: false,
733
- })
734
- return clone
735
- }
736
-
737
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
738
- function assertDocumentAttachment(sharedType) {
739
- if (!sharedType.doc) {
740
- throw new Error("shared type isn't attached to a document")
741
- }
742
- }
743
-
744
- var STORED_POSITION_PREFIX = '__slateYjsStoredPosition_'
745
- function slatePointToRelativePosition(sharedRoot, slateRoot, point) {
746
- var _a = getYTarget(sharedRoot, slateRoot, point.path),
747
- yTarget = _a.yTarget,
748
- yParent = _a.yParent,
749
- textRange = _a.textRange
750
- if (yTarget) {
751
- throw new Error('Slate point points to a non-text element inside sharedRoot')
752
- }
753
- var index = textRange.start + point.offset
754
- return Y.createRelativePositionFromTypeIndex(yParent, index, index === textRange.end ? -1 : 0)
755
- }
756
- function absolutePositionToSlatePoint(sharedRoot, slateRoot, _a) {
757
- var type = _a.type,
758
- index = _a.index,
759
- assoc = _a.assoc
760
- if (!(type instanceof Y.XmlText)) {
761
- throw new Error('Absolute position points to a non-XMLText')
762
- }
763
- var parentPath = getSlatePath(sharedRoot, slateRoot, type)
764
- var parent = Node.get(slateRoot, parentPath)
765
- if (Text.isText(parent)) {
766
- throw new Error("Absolute position doesn't match slateRoot, cannot descent into text")
767
- }
768
- var _b = __read(
769
- yOffsetToSlateOffsets(parent, index, {
770
- assoc: assoc,
771
- }),
772
- 2
773
- ),
774
- pathOffset = _b[0],
775
- textOffset = _b[1]
776
- var target = parent.children[pathOffset]
777
- if (!Text.isText(target)) {
778
- return null
779
- }
780
- return {
781
- path: __spreadArray(__spreadArray([], __read(parentPath)), [pathOffset]),
782
- offset: textOffset,
783
- }
784
- }
785
- function relativePositionToSlatePoint(sharedRoot, slateRoot, pos) {
786
- if (!sharedRoot.doc) {
787
- throw new Error("sharedRoot isn't attach to a yDoc")
788
- }
789
- var absPos = Y.createAbsolutePositionFromRelativePosition(pos, sharedRoot.doc)
790
- return absPos && absolutePositionToSlatePoint(sharedRoot, slateRoot, absPos)
791
- }
792
- function getStoredPosition(sharedRoot, key) {
793
- var rawPosition = sharedRoot.getAttribute(STORED_POSITION_PREFIX + key)
794
- if (!rawPosition) {
795
- return null
796
- }
797
- return Y.decodeRelativePosition(rawPosition)
798
- }
799
- function getStoredPositions(sharedRoot) {
800
- return Object.fromEntries(
801
- Object.entries(sharedRoot.getAttributes())
802
- .filter(function (_a) {
803
- var _b = __read(_a, 1),
804
- key = _b[0]
805
- return key.startsWith(STORED_POSITION_PREFIX)
806
- })
807
- .map(function (_a) {
808
- var _b = __read(_a, 2),
809
- key = _b[0],
810
- position = _b[1]
811
- return [
812
- key.slice(STORED_POSITION_PREFIX.length),
813
- Y.createRelativePositionFromJSON(position),
814
- ]
815
- })
816
- )
817
- }
818
- function getStoredPositionsAbsolute(sharedRoot) {
819
- assertDocumentAttachment(sharedRoot)
820
- return Object.fromEntries(
821
- Object.entries(sharedRoot.getAttributes())
822
- .filter(function (_a) {
823
- var _b = __read(_a, 1),
824
- key = _b[0]
825
- return key.startsWith(STORED_POSITION_PREFIX)
826
- })
827
- .map(function (_a) {
828
- var _b = __read(_a, 2),
829
- key = _b[0],
830
- position = _b[1]
831
- return [
832
- key.slice(STORED_POSITION_PREFIX.length),
833
- Y.createAbsolutePositionFromRelativePosition(
834
- Y.decodeRelativePosition(position),
835
- sharedRoot.doc
836
- ),
837
- ]
838
- })
839
- .filter(function (_a) {
840
- var _b = __read(_a, 2),
841
- position = _b[1]
842
- return position
843
- })
844
- )
845
- }
846
- function removeStoredPosition(sharedRoot, key) {
847
- sharedRoot.removeAttribute(STORED_POSITION_PREFIX + key)
848
- }
849
- function setStoredPosition(sharedRoot, key, position) {
850
- sharedRoot.setAttribute(STORED_POSITION_PREFIX + key, Y.encodeRelativePosition(position))
851
- }
852
- function getAbsolutePositionsInTextRange(absolutePositions, yTarget, textRange) {
853
- return Object.fromEntries(
854
- Object.entries(absolutePositions).filter(function (_a) {
855
- var _b = __read(_a, 2),
856
- position = _b[1]
857
- if (position.type !== yTarget) {
858
- return false
859
- }
860
- if (!textRange) {
861
- return true
862
- }
863
- return position.assoc >= 0
864
- ? position.index >= textRange.start && position.index < textRange.end
865
- : position.index > textRange.start && position.index >= textRange.end
866
- })
867
- )
868
- }
869
- function getAbsolutePositionsInYText(absolutePositions, yText, parentPath) {
870
- var _a
871
- if (parentPath === void 0) {
872
- parentPath = ''
873
- }
874
- var positions =
875
- ((_a = {}), (_a[parentPath] = getAbsolutePositionsInTextRange(absolutePositions, yText)), _a)
876
- var insertDelta = yTextToInsertDelta(yText)
877
- insertDelta.forEach(function (_a, i) {
878
- var insert = _a.insert
879
- if (insert instanceof Y.XmlText) {
880
- Object.assign(
881
- positions,
882
- getAbsolutePositionsInYText(
883
- absolutePositions,
884
- insert,
885
- parentPath ? parentPath + '.' + i : i.toString()
886
- )
887
- )
888
- }
889
- })
890
- return positions
891
- }
892
- function getStoredPositionsInDeltaAbsolute(sharedRoot, yText, delta, deltaOffset) {
893
- if (deltaOffset === void 0) {
894
- deltaOffset = 0
895
- }
896
- var absolutePositions = getStoredPositionsAbsolute(sharedRoot)
897
- var positions = {
898
- '': getAbsolutePositionsInTextRange(absolutePositions, yText, {
899
- start: deltaOffset,
900
- end: deltaOffset + getInsertDeltaLength(delta),
901
- }),
902
- }
903
- delta.forEach(function (_a, i) {
904
- var insert = _a.insert
905
- if (insert instanceof Y.XmlText) {
906
- Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, i.toString()))
907
- }
908
- })
909
- return positions
910
- }
911
- function restoreStoredPositionsWithDeltaAbsolute(
912
- sharedRoot,
913
- yText,
914
- absolutePositions,
915
- delta,
916
- newDeltaOffset,
917
- previousDeltaOffset,
918
- path
919
- ) {
920
- if (newDeltaOffset === void 0) {
921
- newDeltaOffset = 0
922
- }
923
- if (previousDeltaOffset === void 0) {
924
- previousDeltaOffset = 0
925
- }
926
- if (path === void 0) {
927
- path = ''
928
- }
929
- var toRestore = absolutePositions[path]
930
- if (toRestore) {
931
- Object.entries(toRestore).forEach(function (_a) {
932
- var _b = __read(_a, 2),
933
- key = _b[0],
934
- position = _b[1]
935
- setStoredPosition(
936
- sharedRoot,
937
- key,
938
- Y.createRelativePositionFromTypeIndex(
939
- yText,
940
- position.index - previousDeltaOffset + newDeltaOffset,
941
- position.assoc
942
- )
943
- )
944
- })
945
- }
946
- delta.forEach(function (_a, i) {
947
- var insert = _a.insert
948
- if (insert instanceof Y.XmlText) {
949
- restoreStoredPositionsWithDeltaAbsolute(
950
- sharedRoot,
951
- insert,
952
- absolutePositions,
953
- yTextToInsertDelta(insert),
954
- 0,
955
- 0,
956
- path ? path + '.' + i : i.toString()
957
- )
958
- }
959
- })
960
- }
961
- function slateRangeToRelativeRange(sharedRoot, slateRoot, range) {
962
- return {
963
- anchor: slatePointToRelativePosition(sharedRoot, slateRoot, range.anchor),
964
- focus: slatePointToRelativePosition(sharedRoot, slateRoot, range.focus),
965
- }
966
- }
967
- function relativeRangeToSlateRange(sharedRoot, slateRoot, range) {
968
- var anchor = relativePositionToSlatePoint(sharedRoot, slateRoot, range.anchor)
969
- if (!anchor) {
970
- return null
971
- }
972
- var focus = relativePositionToSlatePoint(sharedRoot, slateRoot, range.focus)
973
- if (!focus) {
974
- return null
975
- }
976
- return { anchor: anchor, focus: focus }
977
- }
978
-
979
- function mergeNode(sharedRoot, slateRoot, op) {
980
- var target = getYTarget(sharedRoot, slateRoot, op.path)
981
- var prev = getYTarget(target.yParent, target.slateParent, Path.previous(op.path.slice(-1)))
982
- if (!target.yTarget !== !prev.yTarget) {
983
- throw new Error('Cannot merge y text with y element')
984
- }
985
- if (!prev.yTarget || !target.yTarget) {
986
- var parent_1 = target.yParent,
987
- textRange = target.textRange,
988
- slateTarget = target.slateTarget
989
- if (!slateTarget) {
990
- throw new Error('Expected Slate target node for merge op.')
991
- }
992
- var prevSibling = Node.get(slateRoot, Path.previous(op.path))
993
- if (!Text.isText(prevSibling)) {
994
- throw new Error('Path points to Y.Text but not a Slate text node.')
995
- }
996
- var targetProps = getProperties(slateTarget)
997
- var prevSiblingProps_1 = getProperties(prevSibling)
998
- var unsetProps = Object.keys(targetProps).reduce(function (acc, key) {
999
- var _a
1000
- var prevSiblingHasProp = key in prevSiblingProps_1
1001
- return prevSiblingHasProp
1002
- ? acc
1003
- : __assign(__assign({}, acc), ((_a = {}), (_a[key] = null), _a))
1004
- }, {})
1005
- return parent_1.format(
1006
- textRange.start,
1007
- textRange.end - textRange.start,
1008
- __assign(__assign({}, unsetProps), prevSiblingProps_1)
1009
- )
1010
- }
1011
- var deltaApplyYOffset = prev.yTarget.length
1012
- var targetDelta = yTextToInsertDelta(target.yTarget)
1013
- var clonedDelta = cloneInsertDeltaDeep(targetDelta)
1014
- var storedPositions = getStoredPositionsInDeltaAbsolute(
1015
- sharedRoot,
1016
- target.yTarget,
1017
- targetDelta,
1018
- deltaApplyYOffset
1019
- )
1020
- var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(clonedDelta))
1021
- prev.yTarget.applyDelta(applyDelta, {
1022
- sanitize: false,
1023
- })
1024
- target.yParent.delete(target.textRange.start, target.textRange.end - target.textRange.start)
1025
- restoreStoredPositionsWithDeltaAbsolute(
1026
- sharedRoot,
1027
- prev.yTarget,
1028
- storedPositions,
1029
- clonedDelta,
1030
- deltaApplyYOffset
1031
- )
1032
- }
1033
-
1034
- function moveNode(sharedRoot, slateRoot, op) {
1035
- var newParentPath = Path.parent(op.newPath)
1036
- var newPathOffset = op.newPath[op.newPath.length - 1]
1037
- var parent = Node.get(slateRoot, newParentPath)
1038
- if (Text.isText(parent)) {
1039
- throw new Error('Cannot move slate node into text element')
1040
- }
1041
- var normalizedNewPath = __spreadArray(__spreadArray([], __read(newParentPath)), [
1042
- Math.min(newPathOffset, parent.children.length),
1043
- ])
1044
- var origin = getYTarget(sharedRoot, slateRoot, op.path)
1045
- var target = getYTarget(sharedRoot, slateRoot, normalizedNewPath)
1046
- var insertDelta = cloneInsertDeltaDeep(origin.targetDelta)
1047
- var storedPositions = getStoredPositionsInDeltaAbsolute(
1048
- sharedRoot,
1049
- origin.yParent,
1050
- origin.targetDelta
1051
- )
1052
- origin.yParent.delete(origin.textRange.start, origin.textRange.end - origin.textRange.start)
1053
- var targetLength = getInsertDeltaLength(yTextToInsertDelta(target.yParent))
1054
- var deltaApplyYOffset = Math.min(target.textRange.start, targetLength)
1055
- var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(insertDelta))
1056
- target.yParent.applyDelta(applyDelta, { sanitize: false })
1057
- restoreStoredPositionsWithDeltaAbsolute(
1058
- sharedRoot,
1059
- target.yParent,
1060
- storedPositions,
1061
- insertDelta,
1062
- deltaApplyYOffset,
1063
- origin.textRange.start
1064
- )
1065
- }
1066
-
1067
- function removeNode(sharedRoot, slateRoot, op) {
1068
- var _a = getYTarget(sharedRoot, slateRoot, op.path),
1069
- parent = _a.yParent,
1070
- textRange = _a.textRange
1071
- parent.delete(textRange.start, textRange.end - textRange.start)
1072
- }
1073
-
1074
- function setNode(sharedRoot, slateRoot, op) {
1075
- var _a = getYTarget(sharedRoot, slateRoot, op.path),
1076
- yTarget = _a.yTarget,
1077
- textRange = _a.textRange,
1078
- yParent = _a.yParent
1079
- if (yTarget) {
1080
- Object.entries(op.newProperties).forEach(function (_a) {
1081
- var _b = __read(_a, 2),
1082
- key = _b[0],
1083
- value = _b[1]
1084
- if (value === null) {
1085
- return yTarget.removeAttribute(key)
1086
- }
1087
- yTarget.setAttribute(key, value)
1088
- })
1089
- return Object.entries(op.properties).forEach(function (_a) {
1090
- var _b = __read(_a, 1),
1091
- key = _b[0]
1092
- if (!Object.prototype.hasOwnProperty.call(op.newProperties, key)) {
1093
- yTarget.removeAttribute(key)
1094
- }
1095
- })
1096
- }
1097
- var unset = Object.fromEntries(
1098
- Object.keys(op.properties).map(function (key) {
1099
- return [key, null]
1100
- })
1101
- )
1102
- var newProperties = __assign(__assign({}, unset), op.newProperties)
1103
- yParent.format(textRange.start, textRange.end - textRange.start, newProperties)
1104
- }
1105
-
1106
- function splitNode(sharedRoot, slateRoot, op) {
1107
- var target = getYTarget(sharedRoot, slateRoot, op.path)
1108
- if (!target.slateTarget) {
1109
- throw new Error('Y target without corresponding slate node')
1110
- }
1111
- if (!target.yTarget) {
1112
- if (!Text.isText(target.slateTarget)) {
1113
- throw new Error('Mismatch node type between y target and slate node')
1114
- }
1115
- var unset_1 = {}
1116
- target.targetDelta.forEach(function (element) {
1117
- if (element.attributes) {
1118
- Object.keys(element.attributes).forEach(function (key) {
1119
- unset_1[key] = null
1120
- })
1121
- }
1122
- })
1123
- return target.yParent.format(
1124
- target.textRange.start,
1125
- target.textRange.end - target.textRange.start,
1126
- __assign(__assign({}, unset_1), op.properties)
1127
- )
1128
- }
1129
- if (Text.isText(target.slateTarget)) {
1130
- throw new Error('Mismatch node type between y target and slate node')
1131
- }
1132
- var splitTarget = getYTarget(target.yTarget, target.slateTarget, [op.position])
1133
- var ySplitOffset = target.slateTarget.children
1134
- .slice(0, op.position)
1135
- .reduce(function (length, child) {
1136
- return length + getSlateNodeYLength(child)
1137
- }, 0)
1138
- var length = target.slateTarget.children.reduce(function (current, child) {
1139
- return current + getSlateNodeYLength(child)
1140
- }, 0)
1141
- var splitDelta = sliceInsertDelta(
1142
- yTextToInsertDelta(target.yTarget),
1143
- ySplitOffset,
1144
- length - ySplitOffset
1145
- )
1146
- var clonedDelta = cloneInsertDeltaDeep(splitDelta)
1147
- var storedPositions = getStoredPositionsInDeltaAbsolute(
1148
- sharedRoot,
1149
- target.yTarget,
1150
- splitDelta,
1151
- ySplitOffset
1152
- )
1153
- var toInsert = new Y.XmlText()
1154
- toInsert.applyDelta(clonedDelta, {
1155
- sanitize: false,
1156
- })
1157
- Object.entries(op.properties).forEach(function (_a) {
1158
- var _b = __read(_a, 2),
1159
- key = _b[0],
1160
- value = _b[1]
1161
- toInsert.setAttribute(key, value)
1162
- })
1163
- target.yTarget.delete(
1164
- splitTarget.textRange.start,
1165
- target.yTarget.length - splitTarget.textRange.start
1166
- )
1167
- target.yParent.insertEmbed(target.textRange.end, toInsert)
1168
- restoreStoredPositionsWithDeltaAbsolute(
1169
- sharedRoot,
1170
- toInsert,
1171
- storedPositions,
1172
- clonedDelta,
1173
- 0,
1174
- ySplitOffset
1175
- )
1176
- }
1177
-
1178
- var NODE_MAPPER = {
1179
- insert_node: insertNode,
1180
- remove_node: removeNode,
1181
- set_node: setNode,
1182
- merge_node: mergeNode,
1183
- move_node: moveNode,
1184
- split_node: splitNode,
1185
- }
1186
-
1187
- function insertText(sharedRoot, slateRoot, op) {
1188
- var _a = getYTarget(sharedRoot, slateRoot, op.path),
1189
- target = _a.yParent,
1190
- textRange = _a.textRange
1191
- var targetNode = Node.get(slateRoot, op.path)
1192
- if (!Text.isText(targetNode)) {
1193
- throw new Error('Cannot insert text into non-text node')
1194
- }
1195
- target.insert(textRange.start + op.offset, op.text, getProperties(targetNode))
1196
- }
1197
-
1198
- function removeText(sharedRoot, slateRoot, op) {
1199
- var _a = getYTarget(sharedRoot, slateRoot, op.path),
1200
- target = _a.yParent,
1201
- textRange = _a.textRange
1202
- target.delete(textRange.start + op.offset, op.text.length)
1203
- }
1204
-
1205
- var TEXT_MAPPER = {
1206
- insert_text: insertText,
1207
- remove_text: removeText,
1208
- }
1209
-
1210
- // eslint-disable-next-line @typescript-eslint/no-empty-function
1211
- var NOOP = function () {}
1212
- var opMappers = __assign(__assign(__assign({}, TEXT_MAPPER), NODE_MAPPER), { set_selection: NOOP })
1213
- function applySlateOp(sharedRoot, slateRoot, op) {
1214
- var apply = opMappers[op.type]
1215
- if (!apply) {
1216
- throw new Error('Unknown operation: ' + op.type)
1217
- }
1218
- apply(sharedRoot, slateRoot, op)
1219
- }
1220
-
1221
- var DEFAULT_LOCAL_ORIGIN = Symbol('slate-yjs-operation')
1222
- var DEFAULT_POSITION_STORAGE_ORIGIN = Symbol('slate-yjs-position-storage')
1223
- var ORIGIN = new WeakMap()
1224
- var LOCAL_CHANGES = new WeakMap()
1225
- var CONNECTED = new WeakSet()
1226
- var YjsEditor = {
1227
- isYjsEditor: function (value) {
1228
- return (
1229
- Editor.isEditor(value) &&
1230
- value.sharedRoot instanceof Y.XmlText &&
1231
- 'localOrigin' in value &&
1232
- 'positionStorageOrigin' in value &&
1233
- typeof value.applyRemoteEvents === 'function' &&
1234
- typeof value.storeLocalChange === 'function' &&
1235
- typeof value.flushLocalChanges === 'function' &&
1236
- typeof value.isLocalOrigin === 'function' &&
1237
- typeof value.connect === 'function' &&
1238
- typeof value.disconnect === 'function'
1239
- )
1240
- },
1241
- localChanges: function (editor) {
1242
- var _a
1243
- return (_a = LOCAL_CHANGES.get(editor)) !== null && _a !== void 0 ? _a : []
1244
- },
1245
- applyRemoteEvents: function (editor, events, origin) {
1246
- editor.applyRemoteEvents(events, origin)
1247
- },
1248
- storeLocalChange: function (editor, op) {
1249
- editor.storeLocalChange(op)
1250
- },
1251
- flushLocalChanges: function (editor) {
1252
- editor.flushLocalChanges()
1253
- },
1254
- connected: function (editor) {
1255
- return CONNECTED.has(editor)
1256
- },
1257
- connect: function (editor) {
1258
- editor.connect()
1259
- },
1260
- disconnect: function (editor) {
1261
- editor.disconnect()
1262
- },
1263
- isLocal: function (editor) {
1264
- return editor.isLocalOrigin(YjsEditor.origin(editor))
1265
- },
1266
- origin: function (editor) {
1267
- var origin = ORIGIN.get(editor)
1268
- return origin !== undefined ? origin : editor.localOrigin
1269
- },
1270
- withOrigin: function (editor, origin, fn) {
1271
- var prev = YjsEditor.origin(editor)
1272
- ORIGIN.set(editor, origin)
1273
- fn()
1274
- ORIGIN.set(editor, prev)
1275
- },
1276
- storePosition: function (editor, key, point) {
1277
- var sharedRoot = editor.sharedRoot,
1278
- locationStorageOrigin = editor.positionStorageOrigin
1279
- assertDocumentAttachment(sharedRoot)
1280
- var position = slatePointToRelativePosition(sharedRoot, editor, point)
1281
- sharedRoot.doc.transact(function () {
1282
- setStoredPosition(sharedRoot, key, position)
1283
- }, locationStorageOrigin)
1284
- },
1285
- removeStoredPosition: function (editor, key) {
1286
- var sharedRoot = editor.sharedRoot,
1287
- locationStorageOrigin = editor.positionStorageOrigin
1288
- assertDocumentAttachment(sharedRoot)
1289
- sharedRoot.doc.transact(function () {
1290
- removeStoredPosition(sharedRoot, key)
1291
- }, locationStorageOrigin)
1292
- },
1293
- position: function (editor, key) {
1294
- var position = getStoredPosition(editor.sharedRoot, key)
1295
- if (!position) {
1296
- return undefined
1297
- }
1298
- return relativePositionToSlatePoint(editor.sharedRoot, editor, position)
1299
- },
1300
- storedPositionsRelative: function (editor) {
1301
- return getStoredPositions(editor.sharedRoot)
1302
- },
1303
- }
1304
- function withYjs(sharedRoot, options) {
1305
- if (options === void 0) {
1306
- options = {}
1307
- }
1308
- return function (editor) {
1309
- var _a, _b
1310
- var e = editor
1311
- e.sharedRoot = sharedRoot
1312
- e.localOrigin = (_a = options.localOrigin) !== null && _a !== void 0 ? _a : DEFAULT_LOCAL_ORIGIN
1313
- e.positionStorageOrigin =
1314
- (_b = options.positionStorageOrigin) !== null && _b !== void 0
1315
- ? _b
1316
- : DEFAULT_POSITION_STORAGE_ORIGIN
1317
- e.applyRemoteEvents = function (events, origin) {
1318
- YjsEditor.flushLocalChanges(e)
1319
- Editor.withoutNormalizing(e, function () {
1320
- YjsEditor.withOrigin(e, origin, function () {
1321
- applyYjsEvents(e.sharedRoot, e, events)
1322
- })
1323
- })
1324
- }
1325
- e.isLocalOrigin = function (origin) {
1326
- return origin === e.localOrigin
1327
- }
1328
- var handleYEvents = function (events, transaction) {
1329
- if (e.isLocalOrigin(transaction.origin)) {
1330
- return
1331
- }
1332
- YjsEditor.applyRemoteEvents(e, events, transaction.origin)
1333
- }
1334
- var autoConnectTimeoutId = null
1335
- if (options.autoConnect) {
1336
- autoConnectTimeoutId = setTimeout(function () {
1337
- autoConnectTimeoutId = null
1338
- YjsEditor.connect(e)
1339
- })
1340
- }
1341
- e.connect = function () {
1342
- if (YjsEditor.connected(e)) {
1343
- throw new Error('already connected')
1344
- }
1345
- e.sharedRoot.observeDeep(handleYEvents)
1346
- var content = yTextToSlateElement(e.sharedRoot)
1347
- e.children = content.children
1348
- CONNECTED.add(e)
1349
- Editor.normalize(editor, { force: true })
1350
- if (!editor.operations.length) {
1351
- editor.onChange()
1352
- }
1353
- }
1354
- e.disconnect = function () {
1355
- if (autoConnectTimeoutId) {
1356
- clearTimeout(autoConnectTimeoutId)
1357
- }
1358
- YjsEditor.flushLocalChanges(e)
1359
- e.sharedRoot.unobserveDeep(handleYEvents)
1360
- CONNECTED.delete(e)
1361
- }
1362
- e.storeLocalChange = function (op) {
1363
- LOCAL_CHANGES.set(
1364
- e,
1365
- __spreadArray(__spreadArray([], __read(YjsEditor.localChanges(e))), [
1366
- { op: op, doc: editor.children, origin: YjsEditor.origin(e) },
1367
- ])
1368
- )
1369
- }
1370
- e.flushLocalChanges = function () {
1371
- assertDocumentAttachment(e.sharedRoot)
1372
- var localChanges = YjsEditor.localChanges(e)
1373
- LOCAL_CHANGES.delete(e)
1374
- var txGroups = []
1375
- localChanges.forEach(function (change) {
1376
- var currentGroup = txGroups[txGroups.length - 1]
1377
- if (currentGroup && currentGroup[0].origin === change.origin) {
1378
- return currentGroup.push(change)
1379
- }
1380
- txGroups.push([change])
1381
- })
1382
- txGroups.forEach(function (txGroup) {
1383
- assertDocumentAttachment(e.sharedRoot)
1384
- e.sharedRoot.doc.transact(function () {
1385
- txGroup.forEach(function (change) {
1386
- assertDocumentAttachment(e.sharedRoot)
1387
- applySlateOp(e.sharedRoot, { children: change.doc }, change.op)
1388
- })
1389
- }, txGroup[0].origin)
1390
- })
1391
- }
1392
- var apply = e.apply,
1393
- onChange = e.onChange
1394
- e.apply = function (op) {
1395
- if (YjsEditor.connected(e) && YjsEditor.isLocal(e)) {
1396
- YjsEditor.storeLocalChange(e, op)
1397
- }
1398
- apply(op)
1399
- }
1400
- e.onChange = function () {
1401
- if (YjsEditor.connected(e)) {
1402
- YjsEditor.flushLocalChanges(e)
1403
- }
1404
- onChange()
1405
- }
1406
- return e
1407
- }
1408
- }
1409
-
1410
- var LAST_SELECTION = new WeakMap()
1411
- var DEFAULT_WITHOUT_SAVING_ORIGIN = Symbol('slate-yjs-history-without-saving')
1412
- var YHistoryEditor = {
1413
- isYHistoryEditor: function (value) {
1414
- return (
1415
- YjsEditor.isYjsEditor(value) &&
1416
- value.undoManager instanceof Y.UndoManager &&
1417
- typeof value.undo === 'function' &&
1418
- typeof value.redo === 'function' &&
1419
- 'withoutSavingOrigin' in value
1420
- )
1421
- },
1422
- canUndo: function (editor) {
1423
- return editor.undoManager.undoStack.length > 0
1424
- },
1425
- canRedo: function (editor) {
1426
- return editor.undoManager.redoStack.length > 0
1427
- },
1428
- isSaving: function (editor) {
1429
- return editor.undoManager.trackedOrigins.has(YjsEditor.origin(editor))
1430
- },
1431
- withoutSaving: function (editor, fn) {
1432
- YjsEditor.withOrigin(editor, editor.withoutSavingOrigin, fn)
1433
- },
1434
- }
1435
- function withYHistory(options) {
1436
- if (options === void 0) {
1437
- options = {}
1438
- }
1439
- return function (editor) {
1440
- var e = editor
1441
- // 将 trackedOrigins 的初始化放到 editor 被传入之后
1442
- var _a = options.withoutSavingOrigin,
1443
- withoutSavingOrigin = _a === void 0 ? DEFAULT_WITHOUT_SAVING_ORIGIN : _a,
1444
- _b = options.trackedOrigins,
1445
- trackedOrigins = _b === void 0 ? new Set([e.localOrigin]) : _b,
1446
- restOptions = __rest(options, ['withoutSavingOrigin', 'trackedOrigins'])
1447
- var undoManager = new Y.UndoManager(
1448
- e.sharedRoot,
1449
- __assign({ trackedOrigins: trackedOrigins }, restOptions)
1450
- )
1451
- e.undoManager = undoManager
1452
- e.withoutSavingOrigin = withoutSavingOrigin
1453
- var onChange = e.onChange,
1454
- isLocalOrigin = e.isLocalOrigin
1455
- e.onChange = function () {
1456
- onChange()
1457
- LAST_SELECTION.set(e, e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection))
1458
- }
1459
- e.isLocalOrigin = function (origin) {
1460
- return origin === e.withoutSavingOrigin || isLocalOrigin(origin)
1461
- }
1462
- var handleStackItemAdded = function (_a) {
1463
- var stackItem = _a.stackItem
1464
- stackItem.meta.set(
1465
- 'selection',
1466
- e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection)
1467
- )
1468
- stackItem.meta.set('selectionBefore', LAST_SELECTION.get(e))
1469
- }
1470
- var handleStackItemUpdated = function (_a) {
1471
- var stackItem = _a.stackItem
1472
- stackItem.meta.set(
1473
- 'selection',
1474
- e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection)
1475
- )
1476
- }
1477
- var handleStackItemPopped = function (_a) {
1478
- var stackItem = _a.stackItem,
1479
- type = _a.type
1480
- // TODO: Change once https://github.com/yjs/yjs/issues/353 is resolved
1481
- var inverseStack = type === 'undo' ? e.undoManager.redoStack : e.undoManager.undoStack
1482
- var inverseItem = inverseStack[inverseStack.length - 1]
1483
- if (inverseItem) {
1484
- inverseItem.meta.set('selection', stackItem.meta.get('selectionBefore'))
1485
- inverseItem.meta.set('selectionBefore', stackItem.meta.get('selection'))
1486
- }
1487
- var relativeSelection = stackItem.meta.get('selectionBefore')
1488
- if (!relativeSelection) {
1489
- return
1490
- }
1491
- var selection = relativeRangeToSlateRange(e.sharedRoot, e, relativeSelection)
1492
- if (!selection) {
1493
- return
1494
- }
1495
- Transforms.select(e, selection)
1496
- }
1497
- var connect = e.connect,
1498
- disconnect = e.disconnect
1499
- e.connect = function () {
1500
- connect()
1501
- e.undoManager.on('stack-item-added', handleStackItemAdded)
1502
- e.undoManager.on('stack-item-popped', handleStackItemPopped)
1503
- e.undoManager.on('stack-item-updated', handleStackItemUpdated)
1504
- }
1505
- e.disconnect = function () {
1506
- e.undoManager.off('stack-item-added', handleStackItemAdded)
1507
- e.undoManager.off('stack-item-popped', handleStackItemPopped)
1508
- e.undoManager.off('stack-item-updated', handleStackItemUpdated)
1509
- disconnect()
1510
- }
1511
- e.undo = function () {
1512
- if (YjsEditor.connected(e)) {
1513
- YjsEditor.flushLocalChanges(e)
1514
- e.undoManager.undo()
1515
- }
1516
- }
1517
- e.redo = function () {
1518
- if (YjsEditor.connected(e)) {
1519
- YjsEditor.flushLocalChanges(e)
1520
- e.undoManager.redo()
1521
- }
1522
- }
1523
- return e
1524
- }
1525
- }
1526
-
1527
- var CURSOR_CHANGE_EVENT_LISTENERS = new WeakMap()
1528
- var CursorEditor = {
1529
- isCursorEditor: function (value) {
1530
- return (
1531
- YjsEditor.isYjsEditor(value) &&
1532
- value.awareness &&
1533
- typeof value.cursorDataField === 'string' &&
1534
- typeof value.selectionStateField === 'string' &&
1535
- typeof value.sendCursorPosition === 'function' &&
1536
- typeof value.sendCursorData === 'function'
1537
- )
1538
- },
1539
- sendCursorPosition: function (editor, range) {
1540
- if (range === void 0) {
1541
- range = editor.selection
1542
- }
1543
- editor.sendCursorPosition(range)
1544
- },
1545
- sendCursorData: function (editor, data) {
1546
- editor.sendCursorData(data)
1547
- },
1548
- on: function (editor, event, handler) {
1549
- var _a
1550
- if (event !== 'change') {
1551
- return
1552
- }
1553
- var listeners =
1554
- (_a = CURSOR_CHANGE_EVENT_LISTENERS.get(editor)) !== null && _a !== void 0 ? _a : new Set()
1555
- listeners.add(handler)
1556
- if (editor) CURSOR_CHANGE_EVENT_LISTENERS.set(editor, listeners)
1557
- },
1558
- off: function (editor, event, listener) {
1559
- if (event !== 'change') {
1560
- return
1561
- }
1562
- var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(editor)
1563
- if (listeners) {
1564
- listeners.delete(listener)
1565
- }
1566
- },
1567
- cursorState: function (editor, clientId) {
1568
- var _a
1569
- if (clientId === editor.awareness.clientID || !YjsEditor.connected(editor)) {
1570
- return null
1571
- }
1572
- var state = editor.awareness.getStates().get(clientId)
1573
- if (!state) {
1574
- return null
1575
- }
1576
- return {
1577
- relativeSelection:
1578
- (_a = state[editor.selectionStateField]) !== null && _a !== void 0 ? _a : null,
1579
- data: state[editor.cursorDataField],
1580
- clientId: clientId,
1581
- }
1582
- },
1583
- cursorStates: function (editor) {
1584
- if (!YjsEditor.connected(editor)) {
1585
- return {}
1586
- }
1587
- return Object.fromEntries(
1588
- Array.from(editor.awareness.getStates().entries(), function (_a) {
1589
- var _b = __read(_a, 2),
1590
- id = _b[0],
1591
- state = _b[1]
1592
- // Ignore own state
1593
- if (id === editor.awareness.clientID || !state) {
1594
- return null
1595
- }
1596
- return [
1597
- id,
1598
- {
1599
- relativeSelection: state[editor.selectionStateField],
1600
- data: state[editor.cursorDataField],
1601
- },
1602
- ]
1603
- }).filter(Array.isArray)
1604
- )
1605
- },
1606
- }
1607
- function withCursors(awareness, options) {
1608
- if (options === void 0) {
1609
- options = {}
1610
- }
1611
- return function (editor) {
1612
- var _a = options.cursorStateField,
1613
- selectionStateField = _a === void 0 ? 'selection' : _a,
1614
- _b = options.cursorDataField,
1615
- cursorDataField = _b === void 0 ? 'data' : _b,
1616
- _c = options.autoSend,
1617
- autoSend = _c === void 0 ? true : _c,
1618
- data = options.data
1619
- var e = editor
1620
- e.awareness = awareness
1621
- e.cursorDataField = cursorDataField
1622
- e.selectionStateField = selectionStateField
1623
- e.sendCursorData = function (cursorData) {
1624
- e.awareness.setLocalStateField(e.cursorDataField, cursorData)
1625
- }
1626
- e.sendCursorPosition = function (range) {
1627
- var localState = e.awareness.getLocalState()
1628
- var currentRange =
1629
- localState === null || localState === void 0 ? void 0 : localState[selectionStateField]
1630
- if (!range) {
1631
- if (currentRange) {
1632
- e.awareness.setLocalStateField(e.selectionStateField, null)
1633
- }
1634
- return
1635
- }
1636
- var _a = slateRangeToRelativeRange(e.sharedRoot, e, range),
1637
- anchor = _a.anchor,
1638
- focus = _a.focus
1639
- if (
1640
- !currentRange ||
1641
- !Y.compareRelativePositions(anchor, currentRange) ||
1642
- !Y.compareRelativePositions(focus, currentRange)
1643
- ) {
1644
- e.awareness.setLocalStateField(e.selectionStateField, { anchor: anchor, focus: focus })
1645
- }
1646
- }
1647
- var awarenessChangeListener = function (yEvent) {
1648
- var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(e)
1649
- if (!listeners) {
1650
- return
1651
- }
1652
- var localId = e.awareness.clientID
1653
- var event = {
1654
- added: yEvent.added.filter(function (id) {
1655
- return id !== localId
1656
- }),
1657
- removed: yEvent.removed.filter(function (id) {
1658
- return id !== localId
1659
- }),
1660
- updated: yEvent.updated.filter(function (id) {
1661
- return id !== localId
1662
- }),
1663
- }
1664
- if (event.added.length > 0 || event.removed.length > 0 || event.updated.length > 0) {
1665
- listeners.forEach(function (listener) {
1666
- return listener(event)
1667
- })
1668
- }
1669
- }
1670
- var connect = e.connect,
1671
- disconnect = e.disconnect
1672
- e.connect = function () {
1673
- connect()
1674
- e.awareness.on('change', awarenessChangeListener)
1675
- awarenessChangeListener({
1676
- removed: [],
1677
- added: Array.from(e.awareness.getStates().keys()),
1678
- updated: [],
1679
- })
1680
- if (autoSend) {
1681
- if (data) {
1682
- CursorEditor.sendCursorData(e, data)
1683
- }
1684
- var onChange_1 = e.onChange
1685
- e.onChange = function () {
1686
- onChange_1()
1687
- if (YjsEditor.connected(e)) {
1688
- CursorEditor.sendCursorPosition(e)
1689
- }
1690
- }
1691
- }
1692
- }
1693
- e.disconnect = function () {
1694
- e.awareness.off('change', awarenessChangeListener)
1695
- awarenessChangeListener({
1696
- removed: Array.from(e.awareness.getStates().keys()),
1697
- added: [],
1698
- updated: [],
1699
- })
1700
- disconnect()
1701
- }
1702
- return e
1703
- }
1704
- }
1705
-
1706
- export {
1707
- CursorEditor,
1708
- YHistoryEditor,
1709
- YjsEditor,
1710
- relativePositionToSlatePoint,
1711
- relativeRangeToSlateRange,
1712
- slateNodesToInsertDelta,
1713
- slatePointToRelativePosition,
1714
- slateRangeToRelativeRange,
1715
- withCursors,
1716
- withYHistory,
1717
- withYjs,
1718
- yTextToSlateElement,
1719
- }
1
+ import{Text as t,Node as e,Path as n,Editor as r,Transforms as o}from"slate";import*as i from"yjs";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(t){var e={exports:{}};return t(e,e.exports),e.exports}var c,s,f=function(t){return t&&t.Math===Math&&t},l=f("object"==typeof globalThis&&globalThis)||f("object"==typeof window&&window)||f("object"==typeof self&&self)||f("object"==typeof a&&a)||f("object"==typeof a&&a)||function(){return this}()||Function("return this")(),d=function(t){try{return!!t()}catch(t){return!0}},h=!d((function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})),p=!d((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),v=Function.prototype.call,g=p?v.bind(v):function(){return v.apply(v,arguments)},y={}.propertyIsEnumerable,b=Object.getOwnPropertyDescriptor,m=b&&!y.call({1:2},1)?function(t){var e=b(this,t);return!!e&&e.enumerable}:y,w={f:m},O=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},S=Function.prototype,x=S.call,E=p&&S.bind.bind(x,x),j=p?E:function(t){return function(){return x.apply(t,arguments)}},T=j({}.toString),P=j("".slice),R=function(t){return P(T(t),8,-1)},A=Object,k=j("".split),C=d((function(){return!A("z").propertyIsEnumerable(0)}))?function(t){return"String"===R(t)?k(t,""):A(t)}:A,L=function(t){return null==t},F=TypeError,_=function(t){if(L(t))throw new F("Can't call method on "+t);return t},M=function(t){return C(_(t))},D="object"==typeof document&&document.all,I=void 0===D&&void 0!==D?function(t){return"function"==typeof t||t===D}:function(t){return"function"==typeof t},z=function(t){return"object"==typeof t?null!==t:I(t)},N=function(t,e){return arguments.length<2?(n=l[t],I(n)?n:void 0):l[t]&&l[t][e];var n},W=j({}.isPrototypeOf),X=l.navigator,G=X&&X.userAgent,B=G?String(G):"",U=l.process,Y=l.Deno,V=U&&U.versions||Y&&Y.version,$=V&&V.v8;$&&(s=(c=$.split("."))[0]>0&&c[0]<4?1:+(c[0]+c[1])),!s&&B&&(!(c=B.match(/Edge\/(\d+)/))||c[1]>=74)&&(c=B.match(/Chrome\/(\d+)/))&&(s=+c[1]);var q=s,H=l.String,J=!!Object.getOwnPropertySymbols&&!d((function(){var t=Symbol("symbol detection");return!H(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&q&&q<41})),K=J&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Q=Object,Z=K?function(t){return"symbol"==typeof t}:function(t){var e=N("Symbol");return I(e)&&W(e.prototype,Q(t))},tt=String,et=function(t){try{return tt(t)}catch(t){return"Object"}},nt=TypeError,rt=function(t){if(I(t))return t;throw new nt(et(t)+" is not a function")},ot=function(t,e){var n=t[e];return L(n)?void 0:rt(n)},it=TypeError,at=Object.defineProperty,ut=function(t,e){try{at(l,t,{value:e,configurable:!0,writable:!0})}catch(n){l[t]=e}return e},ct=u((function(t){var e="__core-js_shared__",n=t.exports=l[e]||ut(e,{});(n.versions||(n.versions=[])).push({version:"3.38.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.1/LICENSE",source:"https://github.com/zloirock/core-js"})})),st=function(t,e){return ct[t]||(ct[t]=e||{})},ft=Object,lt=function(t){return ft(_(t))},dt=j({}.hasOwnProperty),ht=Object.hasOwn||function(t,e){return dt(lt(t),e)},pt=0,vt=Math.random(),gt=j(1..toString),yt=function(t){return"Symbol("+(void 0===t?"":t)+")_"+gt(++pt+vt,36)},bt=l.Symbol,mt=st("wks"),wt=K?bt.for||bt:bt&&bt.withoutSetter||yt,Ot=function(t){return ht(mt,t)||(mt[t]=J&&ht(bt,t)?bt[t]:wt("Symbol."+t)),mt[t]},St=TypeError,xt=Ot("toPrimitive"),Et=function(t,e){if(!z(t)||Z(t))return t;var n,r=ot(t,xt);if(r){if(void 0===e&&(e="default"),n=g(r,t,e),!z(n)||Z(n))return n;throw new St("Can't convert object to primitive value")}return void 0===e&&(e="number"),function(t,e){var n,r;if("string"===e&&I(n=t.toString)&&!z(r=g(n,t)))return r;if(I(n=t.valueOf)&&!z(r=g(n,t)))return r;if("string"!==e&&I(n=t.toString)&&!z(r=g(n,t)))return r;throw new it("Can't convert object to primitive value")}(t,e)},jt=function(t){var e=Et(t,"string");return Z(e)?e:e+""},Tt=l.document,Pt=z(Tt)&&z(Tt.createElement),Rt=function(t){return Pt?Tt.createElement(t):{}},At=!h&&!d((function(){return 7!==Object.defineProperty(Rt("div"),"a",{get:function(){return 7}}).a})),kt=Object.getOwnPropertyDescriptor,Ct={f:h?kt:function(t,e){if(t=M(t),e=jt(e),At)try{return kt(t,e)}catch(t){}if(ht(t,e))return O(!g(w.f,t,e),t[e])}},Lt=h&&d((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Ft=String,_t=TypeError,Mt=function(t){if(z(t))return t;throw new _t(Ft(t)+" is not an object")},Dt=TypeError,It=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Nt="enumerable",Wt="configurable",Xt="writable",Gt={f:h?Lt?function(t,e,n){if(Mt(t),e=jt(e),Mt(n),"function"==typeof t&&"prototype"===e&&"value"in n&&Xt in n&&!n[Xt]){var r=zt(t,e);r&&r[Xt]&&(t[e]=n.value,n={configurable:Wt in n?n[Wt]:r[Wt],enumerable:Nt in n?n[Nt]:r[Nt],writable:!1})}return It(t,e,n)}:It:function(t,e,n){if(Mt(t),e=jt(e),Mt(n),At)try{return It(t,e,n)}catch(t){}if("get"in n||"set"in n)throw new Dt("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},Bt=h?function(t,e,n){return Gt.f(t,e,O(1,n))}:function(t,e,n){return t[e]=n,t},Ut=Function.prototype,Yt=h&&Object.getOwnPropertyDescriptor,Vt=ht(Ut,"name"),$t={EXISTS:Vt,PROPER:Vt&&"something"===function(){}.name,CONFIGURABLE:Vt&&(!h||h&&Yt(Ut,"name").configurable)},qt=j(Function.toString);I(ct.inspectSource)||(ct.inspectSource=function(t){return qt(t)});var Ht,Jt,Kt,Qt=ct.inspectSource,Zt=l.WeakMap,te=I(Zt)&&/native code/.test(String(Zt)),ee=st("keys"),ne=function(t){return ee[t]||(ee[t]=yt(t))},re={},oe="Object already initialized",ie=l.TypeError,ae=l.WeakMap;if(te||ct.state){var ue=ct.state||(ct.state=new ae);ue.get=ue.get,ue.has=ue.has,ue.set=ue.set,Ht=function(t,e){if(ue.has(t))throw new ie(oe);return e.facade=t,ue.set(t,e),e},Jt=function(t){return ue.get(t)||{}},Kt=function(t){return ue.has(t)}}else{var ce=ne("state");re[ce]=!0,Ht=function(t,e){if(ht(t,ce))throw new ie(oe);return e.facade=t,Bt(t,ce,e),e},Jt=function(t){return ht(t,ce)?t[ce]:{}},Kt=function(t){return ht(t,ce)}}var se={set:Ht,get:Jt,has:Kt,enforce:function(t){return Kt(t)?Jt(t):Ht(t,{})},getterFor:function(t){return function(e){var n;if(!z(e)||(n=Jt(e)).type!==t)throw new ie("Incompatible receiver, "+t+" required");return n}}},fe=u((function(t){var e=$t.CONFIGURABLE,n=se.enforce,r=se.get,o=String,i=Object.defineProperty,a=j("".slice),u=j("".replace),c=j([].join),s=h&&!d((function(){return 8!==i((function(){}),"length",{value:8}).length})),f=String(String).split("String"),l=t.exports=function(t,r,l){"Symbol("===a(o(r),0,7)&&(r="["+u(o(r),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),l&&l.getter&&(r="get "+r),l&&l.setter&&(r="set "+r),(!ht(t,"name")||e&&t.name!==r)&&(h?i(t,"name",{value:r,configurable:!0}):t.name=r),s&&l&&ht(l,"arity")&&t.length!==l.arity&&i(t,"length",{value:l.arity});try{l&&ht(l,"constructor")&&l.constructor?h&&i(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var d=n(t);return ht(d,"source")||(d.source=c(f,"string"==typeof r?r:"")),t};Function.prototype.toString=l((function(){return I(this)&&r(this).source||Qt(this)}),"toString")})),le=function(t,e,n,r){r||(r={});var o=r.enumerable,i=void 0!==r.name?r.name:e;if(I(n)&&fe(n,i,r),r.global)o?t[e]=n:ut(e,n);else{try{r.unsafe?t[e]&&(o=!0):delete t[e]}catch(t){}o?t[e]=n:Gt.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},de=Math.ceil,he=Math.floor,pe=Math.trunc||function(t){var e=+t;return(e>0?he:de)(e)},ve=function(t){var e=+t;return e!=e||0===e?0:pe(e)},ge=Math.max,ye=Math.min,be=function(t,e){var n=ve(t);return n<0?ge(n+e,0):ye(n,e)},me=Math.min,we=function(t){var e=ve(t);return e>0?me(e,9007199254740991):0},Oe=function(t){return we(t.length)},Se=function(t){return function(e,n,r){var o=M(e),i=Oe(o);if(0===i)return!t&&-1;var a,u=be(r,i);if(t&&n!=n){for(;i>u;)if((a=o[u++])!=a)return!0}else for(;i>u;u++)if((t||u in o)&&o[u]===n)return t||u||0;return!t&&-1}},xe={includes:Se(!0),indexOf:Se(!1)},Ee=xe.indexOf,je=j([].push),Te=function(t,e){var n,r=M(t),o=0,i=[];for(n in r)!ht(re,n)&&ht(r,n)&&je(i,n);for(;e.length>o;)ht(r,n=e[o++])&&(~Ee(i,n)||je(i,n));return i},Pe=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Re=Pe.concat("length","prototype"),Ae={f:Object.getOwnPropertyNames||function(t){return Te(t,Re)}},ke={f:Object.getOwnPropertySymbols},Ce=j([].concat),Le=N("Reflect","ownKeys")||function(t){var e=Ae.f(Mt(t)),n=ke.f;return n?Ce(e,n(t)):e},Fe=function(t,e,n){for(var r=Le(e),o=Gt.f,i=Ct.f,a=0;a<r.length;a++){var u=r[a];ht(t,u)||n&&ht(n,u)||o(t,u,i(e,u))}},_e=/#|\.prototype\./,Me=function(t,e){var n=Ie[De(t)];return n===Ne||n!==ze&&(I(e)?d(e):!!e)},De=Me.normalize=function(t){return String(t).replace(_e,".").toLowerCase()},Ie=Me.data={},ze=Me.NATIVE="N",Ne=Me.POLYFILL="P",We=Me,Xe=Ct.f,Ge=function(t,e){var n,r,o,i,a,u=t.target,c=t.global,s=t.stat;if(n=c?l:s?l[u]||ut(u,{}):l[u]&&l[u].prototype)for(r in e){if(i=e[r],o=t.dontCallGetSet?(a=Xe(n,r))&&a.value:n[r],!We(c?r:u+(s?".":"#")+r,t.forced)&&void 0!==o){if(typeof i==typeof o)continue;Fe(i,o)}(t.sham||o&&o.sham)&&Bt(i,"sham",!0),le(n,r,i,t)}},Be={};Be[Ot("toStringTag")]="z";var Ue,Ye="[object z]"===String(Be),Ve=Ot("toStringTag"),$e=Object,qe="Arguments"===R(function(){return arguments}()),He=Ye?R:function(t){var e,n,r;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=$e(t),Ve))?n:qe?R(e):"Object"===(r=R(e))&&I(e.callee)?"Arguments":r},Je=String,Ke=function(t){if("Symbol"===He(t))throw new TypeError("Cannot convert a Symbol value to a string");return Je(t)},Qe=Object.keys||function(t){return Te(t,Pe)},Ze=h&&!Lt?Object.defineProperties:function(t,e){Mt(t);for(var n,r=M(e),o=Qe(e),i=o.length,a=0;i>a;)Gt.f(t,n=o[a++],r[n]);return t},tn={f:Ze},en=N("document","documentElement"),nn="prototype",rn="script",on=ne("IE_PROTO"),an=function(){},un=function(t){return"<"+rn+">"+t+"</"+rn+">"},cn=function(t){t.write(un("")),t.close();var e=t.parentWindow.Object;return t=null,e},sn=function(){try{Ue=new ActiveXObject("htmlfile")}catch(t){}var t,e,n;sn="undefined"!=typeof document?document.domain&&Ue?cn(Ue):(e=Rt("iframe"),n="java"+rn+":",e.style.display="none",en.appendChild(e),e.src=String(n),(t=e.contentWindow.document).open(),t.write(un("document.F=Object")),t.close(),t.F):cn(Ue);for(var r=Pe.length;r--;)delete sn[nn][Pe[r]];return sn()};re[on]=!0;var fn=Object.create||function(t,e){var n;return null!==t?(an[nn]=Mt(t),n=new an,an[nn]=null,n[on]=t):n=sn(),void 0===e?n:tn.f(n,e)},ln=j([].slice),dn=Ae.f,hn="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],pn={f:function(t){return hn&&"Window"===R(t)?function(t){try{return dn(t)}catch(t){return ln(hn)}}(t):dn(M(t))}},vn=function(t,e,n){return n.get&&fe(n.get,e,{getter:!0}),n.set&&fe(n.set,e,{setter:!0}),Gt.f(t,e,n)},gn={f:Ot},yn=l,bn=Gt.f,mn=Gt.f,wn=Ot("toStringTag"),On=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ht(t,wn)&&mn(t,wn,{configurable:!0,value:e})},Sn=function(t){if("Function"===R(t))return j(t)},xn=Sn(Sn.bind),En=function(t,e){return rt(t),void 0===e?t:p?xn(t,e):function(){return t.apply(e,arguments)}},jn=Array.isArray||function(t){return"Array"===R(t)},Tn=function(){},Pn=N("Reflect","construct"),Rn=/^\s*(?:class|function)\b/,An=j(Rn.exec),kn=!Rn.test(Tn),Cn=function(t){if(!I(t))return!1;try{return Pn(Tn,[],t),!0}catch(t){return!1}},Ln=function(t){if(!I(t))return!1;switch(He(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return kn||!!An(Rn,Qt(t))}catch(t){return!0}};Ln.sham=!0;var Fn=!Pn||d((function(){var t;return Cn(Cn.call)||!Cn(Object)||!Cn((function(){t=!0}))||t}))?Ln:Cn,_n=Ot("species"),Mn=Array,Dn=function(t,e){return new(function(t){var e;return jn(t)&&(e=t.constructor,(Fn(e)&&(e===Mn||jn(e.prototype))||z(e)&&null===(e=e[_n]))&&(e=void 0)),void 0===e?Mn:e}(t))(0===e?0:e)},In=j([].push),zn=function(t){var e=1===t,n=2===t,r=3===t,o=4===t,i=6===t,a=7===t,u=5===t||i;return function(c,s,f,l){for(var d,h,p=lt(c),v=C(p),g=Oe(v),y=En(s,f),b=0,m=l||Dn,w=e?m(c,g):n||a?m(c,0):void 0;g>b;b++)if((u||b in v)&&(h=y(d=v[b],b,p),t))if(e)w[b]=h;else if(h)switch(t){case 3:return!0;case 5:return d;case 6:return b;case 2:In(w,d)}else switch(t){case 4:return!1;case 7:In(w,d)}return i?-1:r||o?o:w}},Nn={forEach:zn(0),map:zn(1),filter:zn(2),some:zn(3),every:zn(4),find:zn(5),findIndex:zn(6),filterReject:zn(7)},Wn=Nn.forEach,Xn=ne("hidden"),Gn="Symbol",Bn="prototype",Un=se.set,Yn=se.getterFor(Gn),Vn=Object[Bn],$n=l.Symbol,qn=$n&&$n[Bn],Hn=l.RangeError,Jn=l.TypeError,Kn=l.QObject,Qn=Ct.f,Zn=Gt.f,tr=pn.f,er=w.f,nr=j([].push),rr=st("symbols"),or=st("op-symbols"),ir=st("wks"),ar=!Kn||!Kn[Bn]||!Kn[Bn].findChild,ur=function(t,e,n){var r=Qn(Vn,e);r&&delete Vn[e],Zn(t,e,n),r&&t!==Vn&&Zn(Vn,e,r)},cr=h&&d((function(){return 7!==fn(Zn({},"a",{get:function(){return Zn(this,"a",{value:7}).a}})).a}))?ur:Zn,sr=function(t,e){var n=rr[t]=fn(qn);return Un(n,{type:Gn,tag:t,description:e}),h||(n.description=e),n},fr=function(t,e,n){t===Vn&&fr(or,e,n),Mt(t);var r=jt(e);return Mt(n),ht(rr,r)?(n.enumerable?(ht(t,Xn)&&t[Xn][r]&&(t[Xn][r]=!1),n=fn(n,{enumerable:O(0,!1)})):(ht(t,Xn)||Zn(t,Xn,O(1,fn(null))),t[Xn][r]=!0),cr(t,r,n)):Zn(t,r,n)},lr=function(t,e){Mt(t);var n=M(e),r=Qe(n).concat(vr(n));return Wn(r,(function(e){h&&!g(dr,n,e)||fr(t,e,n[e])})),t},dr=function(t){var e=jt(t),n=g(er,this,e);return!(this===Vn&&ht(rr,e)&&!ht(or,e))&&(!(n||!ht(this,e)||!ht(rr,e)||ht(this,Xn)&&this[Xn][e])||n)},hr=function(t,e){var n=M(t),r=jt(e);if(n!==Vn||!ht(rr,r)||ht(or,r)){var o=Qn(n,r);return!o||!ht(rr,r)||ht(n,Xn)&&n[Xn][r]||(o.enumerable=!0),o}},pr=function(t){var e=tr(M(t)),n=[];return Wn(e,(function(t){ht(rr,t)||ht(re,t)||nr(n,t)})),n},vr=function(t){var e=t===Vn,n=tr(e?or:M(t)),r=[];return Wn(n,(function(t){!ht(rr,t)||e&&!ht(Vn,t)||nr(r,rr[t])})),r};J||(qn=($n=function(){if(W(qn,this))throw new Jn("Symbol is not a constructor");var t=arguments.length&&void 0!==arguments[0]?Ke(arguments[0]):void 0,e=yt(t),n=function(t){var r=void 0===this?l:this;r===Vn&&g(n,or,t),ht(r,Xn)&&ht(r[Xn],e)&&(r[Xn][e]=!1);var o=O(1,t);try{cr(r,e,o)}catch(t){if(!(t instanceof Hn))throw t;ur(r,e,o)}};return h&&ar&&cr(Vn,e,{configurable:!0,set:n}),sr(e,t)})[Bn],le(qn,"toString",(function(){return Yn(this).tag})),le($n,"withoutSetter",(function(t){return sr(yt(t),t)})),w.f=dr,Gt.f=fr,tn.f=lr,Ct.f=hr,Ae.f=pn.f=pr,ke.f=vr,gn.f=function(t){return sr(Ot(t),t)},h&&(vn(qn,"description",{configurable:!0,get:function(){return Yn(this).description}}),le(Vn,"propertyIsEnumerable",dr,{unsafe:!0}))),Ge({global:!0,constructor:!0,wrap:!0,forced:!J,sham:!J},{Symbol:$n}),Wn(Qe(ir),(function(t){!function(t){var e=yn.Symbol||(yn.Symbol={});ht(e,t)||bn(e,t,{value:gn.f(t)})}(t)})),Ge({target:Gn,stat:!0,forced:!J},{useSetter:function(){ar=!0},useSimple:function(){ar=!1}}),Ge({target:"Object",stat:!0,forced:!J,sham:!h},{create:function(t,e){return void 0===e?fn(t):lr(fn(t),e)},defineProperty:fr,defineProperties:lr,getOwnPropertyDescriptor:hr}),Ge({target:"Object",stat:!0,forced:!J},{getOwnPropertyNames:pr}),function(){var t=N("Symbol"),e=t&&t.prototype,n=e&&e.valueOf,r=Ot("toPrimitive");e&&!e[r]&&le(e,r,(function(t){return g(n,this)}),{arity:1})}(),On($n,Gn),re[Xn]=!0;var gr=J&&!!Symbol.for&&!!Symbol.keyFor,yr=st("string-to-symbol-registry"),br=st("symbol-to-string-registry");Ge({target:"Symbol",stat:!0,forced:!gr},{for:function(t){var e=Ke(t);if(ht(yr,e))return yr[e];var n=N("Symbol")(e);return yr[e]=n,br[n]=e,n}});var mr=st("symbol-to-string-registry");Ge({target:"Symbol",stat:!0,forced:!gr},{keyFor:function(t){if(!Z(t))throw new TypeError(et(t)+" is not a symbol");if(ht(mr,t))return mr[t]}});var wr=Function.prototype,Or=wr.apply,Sr=wr.call,xr="object"==typeof Reflect&&Reflect.apply||(p?Sr.bind(Or):function(){return Sr.apply(Or,arguments)}),Er=j([].push),jr=String,Tr=N("JSON","stringify"),Pr=j(/./.exec),Rr=j("".charAt),Ar=j("".charCodeAt),kr=j("".replace),Cr=j(1..toString),Lr=/[\uD800-\uDFFF]/g,Fr=/^[\uD800-\uDBFF]$/,_r=/^[\uDC00-\uDFFF]$/,Mr=!J||d((function(){var t=N("Symbol")("stringify detection");return"[null]"!==Tr([t])||"{}"!==Tr({a:t})||"{}"!==Tr(Object(t))})),Dr=d((function(){return'"\\udf06\\ud834"'!==Tr("\udf06\ud834")||'"\\udead"'!==Tr("\udead")})),Ir=function(t,e){var n=ln(arguments),r=function(t){if(I(t))return t;if(jn(t)){for(var e=t.length,n=[],r=0;r<e;r++){var o=t[r];"string"==typeof o?Er(n,o):"number"!=typeof o&&"Number"!==R(o)&&"String"!==R(o)||Er(n,Ke(o))}var i=n.length,a=!0;return function(t,e){if(a)return a=!1,e;if(jn(this))return e;for(var r=0;r<i;r++)if(n[r]===t)return e}}}(e);if(I(r)||void 0!==t&&!Z(t))return n[1]=function(t,e){if(I(r)&&(e=g(r,this,jr(t),e)),!Z(e))return e},xr(Tr,null,n)},zr=function(t,e,n){var r=Rr(n,e-1),o=Rr(n,e+1);return Pr(Fr,t)&&!Pr(_r,o)||Pr(_r,t)&&!Pr(Fr,r)?"\\u"+Cr(Ar(t,0),16):t};Tr&&Ge({target:"JSON",stat:!0,arity:3,forced:Mr||Dr},{stringify:function(t,e,n){var r=ln(arguments),o=xr(Mr?Ir:Tr,null,r);return Dr&&"string"==typeof o?kr(o,Lr,zr):o}});var Nr=!J||d((function(){ke.f(1)}));Ge({target:"Object",stat:!0,forced:Nr},{getOwnPropertySymbols:function(t){var e=ke.f;return e?e(lt(t)):[]}});var Wr=l.Symbol,Xr=Wr&&Wr.prototype;if(h&&I(Wr)&&(!("description"in Xr)||void 0!==Wr().description)){var Gr={},Br=function(){var t=arguments.length<1||void 0===arguments[0]?void 0:Ke(arguments[0]),e=W(Xr,this)?new Wr(t):void 0===t?Wr():Wr(t);return""===t&&(Gr[e]=!0),e};Fe(Br,Wr),Br.prototype=Xr,Xr.constructor=Br;var Ur="Symbol(description detection)"===String(Wr("description detection")),Yr=j(Xr.valueOf),Vr=j(Xr.toString),$r=/^Symbol\((.*)\)[^)]+$/,qr=j("".replace),Hr=j("".slice);vn(Xr,"description",{configurable:!0,get:function(){var t=Yr(this);if(ht(Gr,t))return"";var e=Vr(t),n=Ur?Hr(e,7,-1):qr(e,$r,"$1");return""===n?void 0:n}}),Ge({global:!0,constructor:!0,forced:!0},{Symbol:Br})}var Jr=Gt.f,Kr=Ot("unscopables"),Qr=Array.prototype;void 0===Qr[Kr]&&Jr(Qr,Kr,{configurable:!0,value:fn(null)});var Zr,to,eo,no=function(t){Qr[Kr][t]=!0},ro={},oo=!d((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),io=ne("IE_PROTO"),ao=Object,uo=ao.prototype,co=oo?ao.getPrototypeOf:function(t){var e=lt(t);if(ht(e,io))return e[io];var n=e.constructor;return I(n)&&e instanceof n?n.prototype:e instanceof ao?uo:null},so=Ot("iterator"),fo=!1;[].keys&&("next"in(eo=[].keys())?(to=co(co(eo)))!==Object.prototype&&(Zr=to):fo=!0);var lo=!z(Zr)||d((function(){var t={};return Zr[so].call(t)!==t}));lo&&(Zr={}),I(Zr[so])||le(Zr,so,(function(){return this}));var ho={IteratorPrototype:Zr,BUGGY_SAFARI_ITERATORS:fo},po=ho.IteratorPrototype,vo=function(){return this},go=String,yo=TypeError,bo=function(t){if(function(t){return z(t)||null===t}(t))return t;throw new yo("Can't set "+go(t)+" as a prototype")},mo=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,n={};try{(t=function(t,e,n){try{return j(rt(Object.getOwnPropertyDescriptor(t,e)[n]))}catch(t){}}(Object.prototype,"__proto__","set"))(n,[]),e=n instanceof Array}catch(t){}return function(n,r){return _(n),bo(r),z(n)?(e?t(n,r):n.__proto__=r,n):n}}():void 0),wo=$t.PROPER,Oo=$t.CONFIGURABLE,So=ho.IteratorPrototype,xo=ho.BUGGY_SAFARI_ITERATORS,Eo=Ot("iterator"),jo="keys",To="values",Po="entries",Ro=function(){return this},Ao=function(t,e,n,r,o,i,a){!function(t,e,n,r){var o=e+" Iterator";t.prototype=fn(po,{next:O(+!r,n)}),On(t,o,!1),ro[o]=vo}(n,e,r);var u,c,s,f=function(t){if(t===o&&v)return v;if(!xo&&t&&t in h)return h[t];switch(t){case jo:case To:case Po:return function(){return new n(this,t)}}return function(){return new n(this)}},l=e+" Iterator",d=!1,h=t.prototype,p=h[Eo]||h["@@iterator"]||o&&h[o],v=!xo&&p||f(o),y="Array"===e&&h.entries||p;if(y&&(u=co(y.call(new t)))!==Object.prototype&&u.next&&(co(u)!==So&&(mo?mo(u,So):I(u[Eo])||le(u,Eo,Ro)),On(u,l,!0)),wo&&o===To&&p&&p.name!==To&&(Oo?Bt(h,"name",To):(d=!0,v=function(){return g(p,this)})),o)if(c={values:f(To),keys:i?v:f(jo),entries:f(Po)},a)for(s in c)(xo||d||!(s in h))&&le(h,s,c[s]);else Ge({target:e,proto:!0,forced:xo||d},c);return h[Eo]!==v&&le(h,Eo,v,{name:o}),ro[e]=v,c},ko=function(t,e){return{value:t,done:e}},Co=Gt.f,Lo="Array Iterator",Fo=se.set,_o=se.getterFor(Lo),Mo=Ao(Array,"Array",(function(t,e){Fo(this,{type:Lo,target:M(t),index:0,kind:e})}),(function(){var t=_o(this),e=t.target,n=t.index++;if(!e||n>=e.length)return t.target=null,ko(void 0,!0);switch(t.kind){case"keys":return ko(n,!1);case"values":return ko(e[n],!1)}return ko([n,e[n]],!1)}),"values"),Do=ro.Arguments=ro.Array;if(no("keys"),no("values"),no("entries"),h&&"values"!==Do.name)try{Co(Do,"name",{value:"values"})}catch(t){}var Io=Ye?{}.toString:function(){return"[object "+He(this)+"]"};Ye||le(Object.prototype,"toString",Io,{unsafe:!0});var zo=j("".charAt),No=j("".charCodeAt),Wo=j("".slice),Xo=function(t){return function(e,n){var r,o,i=Ke(_(e)),a=ve(n),u=i.length;return a<0||a>=u?t?"":void 0:(r=No(i,a))<55296||r>56319||a+1===u||(o=No(i,a+1))<56320||o>57343?t?zo(i,a):r:t?Wo(i,a,a+2):o-56320+(r-55296<<10)+65536}},Go={codeAt:Xo(!1),charAt:Xo(!0)}.charAt,Bo="String Iterator",Uo=se.set,Yo=se.getterFor(Bo);Ao(String,"String",(function(t){Uo(this,{type:Bo,string:Ke(t),index:0})}),(function(){var t,e=Yo(this),n=e.string,r=e.index;return r>=n.length?ko(void 0,!0):(t=Go(n,r),e.index+=t.length,ko(t,!1))}));var Vo=!d((function(){return Object.isExtensible(Object.preventExtensions({}))})),$o=function(t,e,n){for(var r in e)le(t,r,e[r],n);return t},qo=d((function(){if("function"==typeof ArrayBuffer){var t=new ArrayBuffer(8);Object.isExtensible(t)&&Object.defineProperty(t,"a",{value:8})}})),Ho=Object.isExtensible,Jo=d((function(){Ho(1)}))||qo?function(t){return!!z(t)&&((!qo||"ArrayBuffer"!==R(t))&&(!Ho||Ho(t)))}:Ho,Ko=u((function(t){var e=Gt.f,n=!1,r=yt("meta"),o=0,i=function(t){e(t,r,{value:{objectID:"O"+o++,weakData:{}}})},a=t.exports={enable:function(){a.enable=function(){},n=!0;var t=Ae.f,e=j([].splice),o={};o[r]=1,t(o).length&&(Ae.f=function(n){for(var o=t(n),i=0,a=o.length;i<a;i++)if(o[i]===r){e(o,i,1);break}return o},Ge({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:pn.f}))},fastKey:function(t,e){if(!z(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!ht(t,r)){if(!Jo(t))return"F";if(!e)return"E";i(t)}return t[r].objectID},getWeakData:function(t,e){if(!ht(t,r)){if(!Jo(t))return!0;if(!e)return!1;i(t)}return t[r].weakData},onFreeze:function(t){return Vo&&n&&Jo(t)&&!ht(t,r)&&i(t),t}};re[r]=!0})),Qo=Ot("iterator"),Zo=Array.prototype,ti=function(t){return void 0!==t&&(ro.Array===t||Zo[Qo]===t)},ei=Ot("iterator"),ni=function(t){if(!L(t))return ot(t,ei)||ot(t,"@@iterator")||ro[He(t)]},ri=TypeError,oi=function(t,e){var n=arguments.length<2?ni(t):e;if(rt(n))return Mt(g(n,t));throw new ri(et(t)+" is not iterable")},ii=function(t,e,n){var r,o;Mt(t);try{if(!(r=ot(t,"return"))){if("throw"===e)throw n;return n}r=g(r,t)}catch(t){o=!0,r=t}if("throw"===e)throw n;if(o)throw r;return Mt(r),n},ai=TypeError,ui=function(t,e){this.stopped=t,this.result=e},ci=ui.prototype,si=function(t,e,n){var r,o,i,a,u,c,s,f=n&&n.that,l=!(!n||!n.AS_ENTRIES),d=!(!n||!n.IS_RECORD),h=!(!n||!n.IS_ITERATOR),p=!(!n||!n.INTERRUPTED),v=En(e,f),y=function(t){return r&&ii(r,"normal",t),new ui(!0,t)},b=function(t){return l?(Mt(t),p?v(t[0],t[1],y):v(t[0],t[1])):p?v(t,y):v(t)};if(d)r=t.iterator;else if(h)r=t;else{if(!(o=ni(t)))throw new ai(et(t)+" is not iterable");if(ti(o)){for(i=0,a=Oe(t);a>i;i++)if((u=b(t[i]))&&W(ci,u))return u;return new ui(!1)}r=oi(t,o)}for(c=d?t.next:r.next;!(s=g(c,r)).done;){try{u=b(s.value)}catch(t){ii(r,"throw",t)}if("object"==typeof u&&u&&W(ci,u))return u}return new ui(!1)},fi=TypeError,li=function(t,e){if(W(e,t))return t;throw new fi("Incorrect invocation")},di=Ot("iterator"),hi=!1;try{var pi=0,vi={next:function(){return{done:!!pi++}},return:function(){hi=!0}};vi[di]=function(){return this},Array.from(vi,(function(){throw 2}))}catch(t){}var gi=function(t,e){try{if(!e&&!hi)return!1}catch(t){return!1}var n=!1;try{var r={};r[di]=function(){return{next:function(){return{done:n=!0}}}},t(r)}catch(t){}return n},yi=function(t,e,n){var r=-1!==t.indexOf("Map"),o=-1!==t.indexOf("Weak"),i=r?"set":"add",a=l[t],u=a&&a.prototype,c=a,s={},f=function(t){var e=j(u[t]);le(u,t,"add"===t?function(t){return e(this,0===t?0:t),this}:"delete"===t?function(t){return!(o&&!z(t))&&e(this,0===t?0:t)}:"get"===t?function(t){return o&&!z(t)?void 0:e(this,0===t?0:t)}:"has"===t?function(t){return!(o&&!z(t))&&e(this,0===t?0:t)}:function(t,n){return e(this,0===t?0:t,n),this})};if(We(t,!I(a)||!(o||u.forEach&&!d((function(){(new a).entries().next()})))))c=n.getConstructor(e,t,r,i),Ko.enable();else if(We(t,!0)){var h=new c,p=h[i](o?{}:-0,1)!==h,v=d((function(){h.has(1)})),g=gi((function(t){new a(t)})),y=!o&&d((function(){for(var t=new a,e=5;e--;)t[i](e,e);return!t.has(-0)}));g||((c=e((function(t,e){li(t,u);var n=function(t,e,n){var r,o;return mo&&I(r=e.constructor)&&r!==n&&z(o=r.prototype)&&o!==n.prototype&&mo(t,o),t}(new a,t,c);return L(e)||si(e,n[i],{that:n,AS_ENTRIES:r}),n}))).prototype=u,u.constructor=c),(v||y)&&(f("delete"),f("has"),r&&f("get")),(y||p)&&f(i),o&&u.clear&&delete u.clear}return s[t]=c,Ge({global:!0,constructor:!0,forced:c!==a},s),On(c,t),o||n.setStrong(c,t,r),c},bi=Ko.getWeakData,mi=se.set,wi=se.getterFor,Oi=Nn.find,Si=Nn.findIndex,xi=j([].splice),Ei=0,ji=function(t){return t.frozen||(t.frozen=new Ti)},Ti=function(){this.entries=[]},Pi=function(t,e){return Oi(t.entries,(function(t){return t[0]===e}))};Ti.prototype={get:function(t){var e=Pi(this,t);if(e)return e[1]},has:function(t){return!!Pi(this,t)},set:function(t,e){var n=Pi(this,t);n?n[1]=e:this.entries.push([t,e])},delete:function(t){var e=Si(this.entries,(function(e){return e[0]===t}));return~e&&xi(this.entries,e,1),!!~e}};var Ri,Ai={getConstructor:function(t,e,n,r){var o=t((function(t,o){li(t,i),mi(t,{type:e,id:Ei++,frozen:null}),L(o)||si(o,t[r],{that:t,AS_ENTRIES:n})})),i=o.prototype,a=wi(e),u=function(t,e,n){var r=a(t),o=bi(Mt(e),!0);return!0===o?ji(r).set(e,n):o[r.id]=n,t};return $o(i,{delete:function(t){var e=a(this);if(!z(t))return!1;var n=bi(t);return!0===n?ji(e).delete(t):n&&ht(n,e.id)&&delete n[e.id]},has:function(t){var e=a(this);if(!z(t))return!1;var n=bi(t);return!0===n?ji(e).has(t):n&&ht(n,e.id)}}),$o(i,n?{get:function(t){var e=a(this);if(z(t)){var n=bi(t);if(!0===n)return ji(e).get(t);if(n)return n[e.id]}},set:function(t,e){return u(this,t,e)}}:{add:function(t){return u(this,t,!0)}}),o}},ki=se.enforce,Ci=Object,Li=Array.isArray,Fi=Ci.isExtensible,_i=Ci.isFrozen,Mi=Ci.isSealed,Di=Ci.freeze,Ii=Ci.seal,zi=!l.ActiveXObject&&"ActiveXObject"in l,Ni=function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}},Wi=yi("WeakMap",Ni,Ai),Xi=Wi.prototype,Gi=j(Xi.set);if(te)if(zi){Ri=Ai.getConstructor(Ni,"WeakMap",!0),Ko.enable();var Bi=j(Xi.delete),Ui=j(Xi.has),Yi=j(Xi.get);$o(Xi,{delete:function(t){if(z(t)&&!Fi(t)){var e=ki(this);return e.frozen||(e.frozen=new Ri),Bi(this,t)||e.frozen.delete(t)}return Bi(this,t)},has:function(t){if(z(t)&&!Fi(t)){var e=ki(this);return e.frozen||(e.frozen=new Ri),Ui(this,t)||e.frozen.has(t)}return Ui(this,t)},get:function(t){if(z(t)&&!Fi(t)){var e=ki(this);return e.frozen||(e.frozen=new Ri),Ui(this,t)?Yi(this,t):e.frozen.get(t)}return Yi(this,t)},set:function(t,e){if(z(t)&&!Fi(t)){var n=ki(this);n.frozen||(n.frozen=new Ri),Ui(this,t)?Gi(this,t,e):n.frozen.set(t,e)}else Gi(this,t,e);return this}})}else Vo&&d((function(){var t=Di([]);return Gi(new Wi,t,1),!_i(t)}))&&$o(Xi,{set:function(t,e){var n;return Li(t)&&(_i(t)?n=Di:Mi(t)&&(n=Ii)),Gi(this,t,e),n&&n(t),this}});yi("WeakSet",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),Ai);var Vi,$i,qi={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},Hi=Rt("span").classList,Ji=Hi&&Hi.constructor&&Hi.constructor.prototype,Ki=Ji===Object.prototype?void 0:Ji,Qi=Nn.forEach,Zi=!!($i=[]["forEach"])&&d((function(){$i.call(null,Vi||function(){return 1},1)}))?[].forEach:function(t){return Qi(this,t,arguments.length>1?arguments[1]:void 0)},ta=function(t){if(t&&t.forEach!==Zi)try{Bt(t,"forEach",Zi)}catch(e){t.forEach=Zi}};for(var ea in qi)qi[ea]&&ta(l[ea]&&l[ea].prototype);ta(Ki);var na=Ot("iterator"),ra=Mo.values,oa=function(t,e){if(t){if(t[na]!==ra)try{Bt(t,na,ra)}catch(e){t[na]=ra}if(On(t,e,!0),qi[e])for(var n in Mo)if(t[n]!==Mo[n])try{Bt(t,n,Mo[n])}catch(e){t[n]=Mo[n]}}};for(var ia in qi)oa(l[ia]&&l[ia].prototype,ia);oa(Ki,"DOMTokenList");var aa=function(){return aa=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},aa.apply(this,arguments)};function ua(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function ca(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function sa(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function fa(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var la=function(t,e,n,r){try{return r?e(Mt(n)[0],n[1]):e(n)}catch(e){ii(t,"throw",e)}},da=function(t,e,n){h?Gt.f(t,e,O(0,n)):t[e]=n},ha=Array,pa=!gi((function(t){Array.from(t)}));Ge({target:"Array",stat:!0,forced:pa},{from:function(t){var e=lt(t),n=Fn(this),r=arguments.length,o=r>1?arguments[1]:void 0,i=void 0!==o;i&&(o=En(o,r>2?arguments[2]:void 0));var a,u,c,s,f,l,d=ni(e),h=0;if(!d||this===ha&&ti(d))for(a=Oe(e),u=n?new this(a):ha(a);a>h;h++)l=i?o(e[h],h):e[h],da(u,h,l);else for(u=n?new this:[],f=(s=oi(e,d)).next;!(c=g(f,s)).done;h++)l=i?la(s,o,[c.value,h],!0):c.value,da(u,h,l);return u.length=h,u}});var va=Ot("species"),ga=function(t){return q>=51||!d((function(){var e=[];return(e.constructor={})[va]=function(){return{foo:1}},1!==e[t](Boolean).foo}))},ya=Nn.map,ba=ga("map");Ge({target:"Array",proto:!0,forced:!ba},{map:function(t){return ya(this,t,arguments.length>1?arguments[1]:void 0)}});var ma=ga("slice"),wa=Ot("species"),Oa=Array,Sa=Math.max;Ge({target:"Array",proto:!0,forced:!ma},{slice:function(t,e){var n,r,o,i=M(this),a=Oe(i),u=be(t,a),c=be(void 0===e?a:e,a);if(jn(i)&&(n=i.constructor,(Fn(n)&&(n===Oa||jn(n.prototype))||z(n)&&null===(n=n[wa]))&&(n=void 0),n===Oa||void 0===n))return ln(i,u,c);for(r=new(void 0===n?Oa:n)(Sa(c-u,0)),o=0;u<c;u++,o++)u in i&&da(r,o,i[u]);return r.length=o,r}}),Ge({target:"Object",stat:!0},{fromEntries:function(t){var e={};return si(t,(function(t,n){da(e,t,n)}),{AS_ENTRIES:!0}),e}});var xa=d((function(){Qe(1)}));Ge({target:"Object",stat:!0,forced:xa},{keys:function(t){return Qe(lt(t))}});var Ea=w.f,ja=j(Ea),Ta=j([].push),Pa=h&&d((function(){var t=Object.create(null);return t[2]=2,!ja(t,2)})),Ra=function(t){return function(e){for(var n,r=M(e),o=Qe(r),i=Pa&&null===co(r),a=o.length,u=0,c=[];a>u;)n=o[u++],h&&!(i?n in r:ja(r,n))||Ta(c,t?[n,r[n]]:r[n]);return c}},Aa={entries:Ra(!0),values:Ra(!1)}.entries;Ge({target:"Object",stat:!0},{entries:function(t){return Aa(t)}});var ka=Nn.filter,Ca=ga("filter");Ge({target:"Array",proto:!0,forced:!Ca},{filter:function(t){return ka(this,t,arguments.length>1?arguments[1]:void 0)}});var La=xe.includes,Fa=d((function(){return!Array(1).includes()}));Ge({target:"Array",proto:!0,forced:Fa},{includes:function(t){return La(this,t,arguments.length>1?arguments[1]:void 0)}}),no("includes");var _a=function(){var t=Mt(this),e="";return t.hasIndices&&(e+="d"),t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.unicodeSets&&(e+="v"),t.sticky&&(e+="y"),e},Ma=RegExp.prototype,Da=$t.PROPER,Ia="toString",za=RegExp.prototype,Na=za[Ia],Wa=d((function(){return"/a/b"!==Na.call({source:"a",flags:"b"})})),Xa=Da&&Na.name!==Ia;function Ga(t){return"[object Object]"===Object.prototype.toString.call(t)}function Ba(t){if(!Ga(t))return!1;var e=t.constructor;if(void 0===e)return!0;var n=e.prototype;return!1!==Ga(n)&&!Object.prototype.hasOwnProperty.call(n,"isPrototypeOfOf")}function Ua(t,e){for(var n in t){var r=t[n],o=e[n];if(Ba(r)&&Ba(o)){if(!Ua(r,o))return!1}else if(Array.isArray(r)&&Array.isArray(o)){if(r.length!==o.length)return!1;for(var i=0;i<r.length;i+=1)if(r[i]!==o[i])return!1}else if(r!==o)return!1}for(var n in e)if(void 0===t[n]&&void 0!==e[n])return!1;return!0}function Ya(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=sa(t,1)[0];return e.includes(n)})))}function Va(t){return function(t){var e,n,r,o,i=[];try{for(var a=ca(t),u=a.next();!u.done;u=a.next()){var c=u.value;if("string"!=typeof c.insert||0!==c.insert.length){var s=i[i.length-1];s&&"string"==typeof s.insert&&"string"==typeof c.insert&&(s.attributes===c.attributes||!s.attributes==!c.attributes&&Ua(null!==(r=s.attributes)&&void 0!==r?r:{},null!==(o=c.attributes)&&void 0!==o?o:{}))?s.insert+=c.insert:i.push(c)}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return i}(t.toDelta())}function $a(t){var e=t.insert;return"string"==typeof e?e.length:1}function qa(t){return t.reduce((function(t,e){return t+$a(e)}),0)}function Ha(t,e,n){if(n<1)return[];for(var r=0,o=[],i=e+n,a=0;a<t.length&&!(r>=i);a++){var u=t[a],c=$a(u);if(r+c<=e)r+=c;else if("string"==typeof u.insert){var s=Math.max(0,e-r),f=Math.min(c,c-(r+c-i));o.push(aa(aa({},u),{insert:u.insert.slice(s,f)})),r+=c}else r+=c,o.push(u)}return o}function Ja(e){return function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=sa(t,1)[0];return!e.includes(n)})))}(e,t.isText(e)?"text":"children")}function Ka(t){var e=Va(t),n=e.length>0?e.map(Qa):[{text:""}];return aa(aa({},t.getAttributes()),{children:n})}function Qa(t){return"string"==typeof t.insert?aa(aa({},t.attributes),{text:t.insert}):Ka(t.insert)}function Za(e){return e.map((function(e){return t.isText(e)?{insert:e.text,attributes:Ja(e)}:{insert:tu(e)}}))}function tu(t){var e=t.children,n=ua(t,["children"]),r=new i.XmlText;return Object.entries(n).forEach((function(t){var e=sa(t,2),n=e[0],o=e[1];r.setAttribute(n,o)})),r.applyDelta(Za(e),{sanitize:!1}),r}(Wa||Xa)&&le(za,Ia,(function(){var t=Mt(this),e=Ke(t.source),n=Ke(function(t){var e=t.flags;return void 0!==e||"flags"in Ma||ht(t,"flags")||!W(Ma,t)?e:g(_a,t)}(t));return"/"+e+"/"+n}),{unsafe:!0});var eu=TypeError,nu=function(t){if(t>9007199254740991)throw eu("Maximum allowed index exceeded");return t},ru=Ot("isConcatSpreadable"),ou=q>=51||!d((function(){var t=[];return t[ru]=!1,t.concat()[0]!==t})),iu=function(t){if(!z(t))return!1;var e=t[ru];return void 0!==e?!!e:jn(t)},au=!ou||!ga("concat");function uu(e){return e?t.isText(e)?e.text.length:1:0}function cu(e,n,r){var o;if(0===r.length)throw new Error("Path has to a have a length >= 1");if(t.isText(n))throw new Error("Cannot descent into slate text");var a=sa(r),u=a[0],c=a.slice(1),s=function(t,e){return t.children.slice(0,e).reduce((function(t,e){return t+uu(e)}),0)}(n,u),f=n.children[u],l=Va(e),d=uu(f),h=Ha(l,s,d);if(h.length>1)throw new Error("Path doesn't match yText, yTarget spans multiple nodes");var p=null===(o=h[0])||void 0===o?void 0:o.insert;if(c.length>0){if(!(p instanceof i.XmlText))throw new Error("Path doesn't match yText, cannot descent into non-yText");return cu(p,f,c)}return{yParent:e,textRange:{start:s,end:s+d},yTarget:p instanceof i.XmlText?p:void 0,slateParent:n,slateTarget:f,targetDelta:h}}function su(e,n,r){void 0===r&&(r={});for(var o=r.assoc,i=void 0===o?0:o,a=r.insert,u=void 0!==a&&a,c=0,s=0,f=0;f<e.children.length;f++){var l=e.children[f],d=t.isText(l)?l.text.length:1;d>0&&(s=f);var h=c+d;if(d>0&&(i>=0?h>n:h>=n))return[f,n-c];c+=d}if(n>c+(u?1:0))throw new Error("yOffset out of bounds");if(u)return[e.children.length,0];var p=e.children[s];return[s,t.isText(p)?p.text.length:1]}function fu(e,n,r){for(var o=[r];o[0]!==e;){var a=o[0].parent;if(!a)throw new Error("yText isn't a descendant of root element");if(!(a instanceof i.XmlText))throw new Error("Unexpected y parent type");o.unshift(a)}if(o.length<2)return[];var u=n;return o.reduce((function(e,n,r){var i,a,c=o[r+1];if(!c)return e;var s=0,f=Va(n);try{for(var l=ca(f),d=l.next();!d.done;d=l.next()){var h=d.value;if(h.insert===c)break;s+="string"==typeof h.insert?h.insert.length:1}}catch(t){i={error:t}}finally{try{d&&!d.done&&(a=l.return)&&a.call(l)}finally{if(i)throw i.error}}if(t.isText(u))throw new Error("Cannot descent into slate text");var p=sa(su(u,s),1)[0];return u=u.children[p],e.concat(p)}),[])}function lu(r,o,a){var u=a.target,c=a.changes,s=a.delta;if(!(u instanceof i.XmlText))throw new Error("Unexpected target node type");var f=[],l=fu(r,o,u),d=e.get(o,l);if(t.isText(d))throw new Error("Cannot apply yTextEvent to text node");var h=Array.from(c.keys.entries());if(l.length>0&&h.length>0){var p=Object.fromEntries(h.map((function(t){var e=sa(t,2),n=e[0];return[n,"delete"===e[1].action?null:u.getAttribute(n)]}))),v=Object.fromEntries(h.map((function(t){var e=sa(t,1)[0];return[e,d[e]]})));f.push({type:"set_node",newProperties:p,properties:v,path:l})}return s.length>0&&f.push.apply(f,fa([],sa(function(e,r,o){var i=[],a=o.reduce((function(t,e){return"retain"in e?t+e.retain:"delete"in e?t+e.delete:t}),0);return o.reverse().forEach((function(o){var u,c;if("attributes"in o&&"retain"in o)for(var s=sa(su(e,a-o.retain),2),f=s[0],l=s[1],d=sa(su(e,a,{assoc:-1}),2),h=d[0],p=d[1],v=h;v>=f;v--){var g=e.children[v],y=fa(fa([],sa(r),!1),[v],!1);if(t.isText(g)){var b=o.attributes,m=Ya.apply(void 0,fa([e],sa(Object.keys(o.attributes)),!1));if(v===f||v===h){var w=v===f?l:0;if((x=v===h?p:g.text.length)!==g.text.length&&i.push({type:"split_node",path:y,position:x,properties:Ja(g)}),0!==w){i.push({type:"split_node",path:y,position:w,properties:(c=aa(aa({},Ja(g)),b),Object.fromEntries(Object.entries(c).filter((function(t){return null!==sa(t,2)[1]}))))});continue}}i.push({type:"set_node",newProperties:b,path:y,properties:m})}}if("retain"in o&&(a-=o.retain),"delete"in o){var O=sa(su(e,a-o.delete),2),S=(f=O[0],l=O[1],sa(su(e,a,{assoc:-1}),2));for(h=S[0],v=0===(p=S[1])?h-1:h;v>=f;v--)if(g=e.children[v],y=fa(fa([],sa(r),!1),[v],!1),!t.isText(g)||v!==f&&v!==h)i.push({type:"remove_node",node:g,path:y}),a-=uu(g);else{w=v===f?l:0;var x=v===h?p:g.text.length;i.push({type:"remove_text",offset:w,text:g.text.slice(w,x),path:y}),a-=x-w}}else if("insert"in o){var E=sa(su(e,a,{insert:!0}),2),j=(v=E[0],E[1]);if(g=e.children[v],y=fa(fa([],sa(r),!1),[v],!1),t.isText(g)){var T=i[i.length-1],P=null!=T&&"insert_node"===T.type?T.node:Ja(g),R=[];if(null==T||"insert_node"!==T.type&&"insert_text"!==T.type&&"split_node"!==T.type&&"set_node"!==T.type||(R=T.path),"string"==typeof o.insert&&Ua(null!==(u=o.attributes)&&void 0!==u?u:{},P)&&n.equals(y,R))return i.push({type:"insert_text",offset:j,text:o.insert,path:y});var A=Qa(o);return 0===j?i.push({type:"insert_node",path:y,node:A}):(j<g.text.length&&i.push({type:"split_node",path:y,position:j,properties:Ja(g)}),i.push({type:"insert_node",path:n.next(y),node:A}))}return i.push({type:"insert_node",path:y,node:Qa(o)})}})),i}(d,l,s)),!1)),f}function du(t,e,n){r.withoutNormalizing(e,(function(){n.forEach((function(n){(function(t,e,n){if(n instanceof i.YTextEvent)return lu(t,e,n);throw new Error("Unexpected Y event type")})(t,e,n).forEach((function(t){e.apply(t)}))}))}))}function hu(t){return t.map((function(t){return"string"==typeof t.insert?t:aa(aa({},t),{insert:pu(t.insert)})}))}function pu(t){var e=new i.XmlText,n=t.getAttributes();return Object.entries(n).forEach((function(t){var n=sa(t,2),r=n[0],o=n[1];e.setAttribute(r,o)})),e.applyDelta(hu(Va(t)),{sanitize:!1}),e}Ge({target:"Array",proto:!0,arity:1,forced:au},{concat:function(t){var e,n,r,o,i,a=lt(this),u=Dn(a,0),c=0;for(e=-1,r=arguments.length;e<r;e++)if(iu(i=-1===e?a:arguments[e]))for(o=Oe(i),nu(c+o),n=0;n<o;n++,c++)n in i&&da(u,c,i[n]);else nu(c+1),da(u,c++,i);return u.length=c,u}});var vu=Object.assign,gu=Object.defineProperty,yu=j([].concat),bu=!vu||d((function(){if(h&&1!==vu({b:1},vu(gu({},"a",{enumerable:!0,get:function(){gu(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var t={},e={},n=Symbol("assign detection"),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach((function(t){e[t]=t})),7!==vu({},t)[n]||Qe(vu({},e)).join("")!==r}))?function(t,e){for(var n=lt(t),r=arguments.length,o=1,i=ke.f,a=w.f;r>o;)for(var u,c=C(arguments[o++]),s=i?yu(Qe(c),i(c)):Qe(c),f=s.length,l=0;f>l;)u=s[l++],h&&!g(a,c,u)||(n[u]=c[u]);return n}:vu;Ge({target:"Object",stat:!0,arity:2,forced:Object.assign!==bu},{assign:bu});var mu,wu=Ot("match"),Ou=TypeError,Su=function(t){if(function(t){var e;return z(t)&&(void 0!==(e=t[wu])?!!e:"RegExp"===R(t))}(t))throw new Ou("The method doesn't accept regular expressions");return t},xu=Ot("match"),Eu=Ct.f,ju=Sn("".slice),Tu=Math.min,Pu=function(t){var e=/./;try{"/./"[t](e)}catch(n){try{return e[xu]=!1,"/./"[t](e)}catch(t){}}return!1}("startsWith"),Ru=!(Pu||(mu=Eu(String.prototype,"startsWith"),!mu||mu.writable));Ge({target:"String",proto:!0,forced:!Ru&&!Pu},{startsWith:function(t){var e=Ke(_(this));Su(t);var n=we(Tu(arguments.length>1?arguments[1]:void 0,e.length)),r=Ke(t);return ju(e,n,n+r.length)===r}});var Au=/"/g,ku=j("".replace);function Cu(t){if(!t.doc)throw new Error("shared type isn't attached to a document")}Ge({target:"String",proto:!0,forced:function(t){return d((function(){var e=""[t]('"');return e!==e.toLowerCase()||e.split('"').length>3}))}("anchor")},{anchor:function(t){return e="a",n="name",r=t,o=Ke(_(this)),i="<"+e,""!==n&&(i+=" "+n+'="'+ku(Ke(r),Au,"&quot;")+'"'),i+">"+o+"</"+e+">";var e,n,r,o,i}});var Lu="__slateYjsStoredPosition_";function Fu(t,e,n){var r=cu(t,e,n.path),o=r.yTarget,a=r.yParent,u=r.textRange;if(o)throw new Error("Slate point points to a non-text element inside sharedRoot");var c=u.start+n.offset;return i.createRelativePositionFromTypeIndex(a,c,c===u.end?-1:0)}function _u(n,r,o){if(!n.doc)throw new Error("sharedRoot isn't attach to a yDoc");var a=i.createAbsolutePositionFromRelativePosition(o,n.doc);return a&&function(n,r,o){var a=o.type,u=o.index,c=o.assoc;if(!(a instanceof i.XmlText))throw new Error("Absolute position points to a non-XMLText");var s=fu(n,r,a),f=e.get(r,s);if(t.isText(f))throw new Error("Absolute position doesn't match slateRoot, cannot descent into text");var l=sa(su(f,u,{assoc:c}),2),d=l[0],h=l[1],p=f.children[d];return t.isText(p)?{path:fa(fa([],sa(s),!1),[d],!1),offset:h}:null}(n,r,a)}function Mu(t,e,n){t.setAttribute(Lu+e,i.encodeRelativePosition(n))}function Du(t,e,n){return Object.fromEntries(Object.entries(t).filter((function(t){var r=sa(t,2)[1];return r.type===e&&(!n||(r.assoc>=0?r.index>=n.start&&r.index<n.end:r.index>n.start&&r.index>=n.end))})))}function Iu(t,e,n){var r;void 0===n&&(n="");var o=((r={})[n]=Du(t,e),r);return Va(e).forEach((function(e,r){var a=e.insert;a instanceof i.XmlText&&Object.assign(o,Iu(t,a,n?"".concat(n,".").concat(r):r.toString()))})),o}function zu(t,e,n,r){void 0===r&&(r=0);var o=function(t){return Cu(t),Object.fromEntries(Object.entries(t.getAttributes()).filter((function(t){return sa(t,1)[0].startsWith(Lu)})).map((function(e){var n=sa(e,2),r=n[0],o=n[1];return[r.slice(Lu.length),i.createAbsolutePositionFromRelativePosition(i.decodeRelativePosition(o),t.doc)]})).filter((function(t){return sa(t,2)[1]})))}(t),a={"":Du(o,e,{start:r,end:r+qa(n)})};return n.forEach((function(t,e){var n=t.insert;n instanceof i.XmlText&&Object.assign(a,Iu(o,n,e.toString()))})),a}function Nu(t,e,n,r,o,a,u){void 0===o&&(o=0),void 0===a&&(a=0),void 0===u&&(u="");var c=n[u];c&&Object.entries(c).forEach((function(n){var r=sa(n,2),u=r[0],c=r[1];Mu(t,u,i.createRelativePositionFromTypeIndex(e,c.index-a+o,c.assoc))})),r.forEach((function(e,r){var o=e.insert;o instanceof i.XmlText&&Nu(t,o,n,Va(o),0,0,u?"".concat(u,".").concat(r):r.toString())}))}function Wu(t,e,n){return{anchor:Fu(t,e,n.anchor),focus:Fu(t,e,n.focus)}}function Xu(t,e,n){var r=_u(t,e,n.anchor);if(!r)return null;var o=_u(t,e,n.focus);return o?{anchor:r,focus:o}:null}var Gu={insert_node:function(e,n,r){var o=cu(e,n,r.path),i=o.yParent,a=o.textRange;if(t.isText(r.node))return i.insert(a.start,r.node.text,Ja(r.node));i.insertEmbed(a.start,tu(r.node))},remove_node:function(t,e,n){var r=cu(t,e,n.path),o=r.yParent,i=r.textRange;o.delete(i.start,i.end-i.start)},set_node:function(t,e,n){var r=cu(t,e,n.path),o=r.yTarget,i=r.textRange,a=r.yParent;if(o)return Object.entries(n.newProperties).forEach((function(t){var e=sa(t,2),n=e[0],r=e[1];if(null===r)return o.removeAttribute(n);o.setAttribute(n,r)})),Object.entries(n.properties).forEach((function(t){var e=sa(t,1)[0];Object.prototype.hasOwnProperty.call(n.newProperties,e)||o.removeAttribute(e)}));var u=Object.fromEntries(Object.keys(n.properties).map((function(t){return[t,null]}))),c=aa(aa({},u),n.newProperties);a.format(i.start,i.end-i.start,c)},merge_node:function(r,o,i){var a=cu(r,o,i.path),u=cu(a.yParent,a.slateParent,n.previous(i.path.slice(-1)));if(!a.yTarget!=!u.yTarget)throw new Error("Cannot merge y text with y element");if(!u.yTarget||!a.yTarget){var c=a.yParent,s=a.textRange,f=a.slateTarget;if(!f)throw new Error("Expected Slate target node for merge op.");var l=e.get(o,n.previous(i.path));if(!t.isText(l))throw new Error("Path points to Y.Text but not a Slate text node.");var d=Ja(f),h=Ja(l),p=Object.keys(d).reduce((function(t,e){var n;return e in h?t:aa(aa({},t),((n={})[e]=null,n))}),{});return c.format(s.start,s.end-s.start,aa(aa({},p),h))}var v=u.yTarget.length,g=Va(a.yTarget),y=hu(g),b=zu(r,a.yTarget,g,v),m=fa([{retain:v}],sa(y),!1);u.yTarget.applyDelta(m,{sanitize:!1}),a.yParent.delete(a.textRange.start,a.textRange.end-a.textRange.start),Nu(r,u.yTarget,b,y,v)},move_node:function(r,o,i){var a=n.parent(i.newPath),u=i.newPath[i.newPath.length-1],c=e.get(o,a);if(t.isText(c))throw new Error("Cannot move slate node into text element");var s=fa(fa([],sa(a),!1),[Math.min(u,c.children.length)],!1),f=cu(r,o,i.path),l=cu(r,o,s),d=hu(f.targetDelta),h=zu(r,f.yParent,f.targetDelta);f.yParent.delete(f.textRange.start,f.textRange.end-f.textRange.start);var p=qa(Va(l.yParent)),v=Math.min(l.textRange.start,p),g=fa([{retain:v}],sa(d),!1);l.yParent.applyDelta(g,{sanitize:!1}),Nu(r,l.yParent,h,d,v,f.textRange.start)},split_node:function(e,n,r){var o=cu(e,n,r.path);if(!o.slateTarget)throw new Error("Y target without corresponding slate node");if(!o.yTarget){if(!t.isText(o.slateTarget))throw new Error("Mismatch node type between y target and slate node");var a={};return o.targetDelta.forEach((function(t){t.attributes&&Object.keys(t.attributes).forEach((function(t){a[t]=null}))})),o.yParent.format(o.textRange.start,o.textRange.end-o.textRange.start,aa(aa({},a),r.properties))}if(t.isText(o.slateTarget))throw new Error("Mismatch node type between y target and slate node");var u=cu(o.yTarget,o.slateTarget,[r.position]),c=o.slateTarget.children.slice(0,r.position).reduce((function(t,e){return t+uu(e)}),0),s=o.slateTarget.children.reduce((function(t,e){return t+uu(e)}),0),f=Ha(Va(o.yTarget),c,s-c),l=hu(f),d=zu(e,o.yTarget,f,c),h=new i.XmlText;h.applyDelta(l,{sanitize:!1}),Object.entries(r.properties).forEach((function(t){var e=sa(t,2),n=e[0],r=e[1];h.setAttribute(n,r)})),o.yTarget.delete(u.textRange.start,o.yTarget.length-u.textRange.start),o.yParent.insertEmbed(o.textRange.end,h),Nu(e,h,d,l,0,c)}};var Bu=aa(aa(aa({},{insert_text:function(n,r,o){var i=cu(n,r,o.path),a=i.yParent,u=i.textRange,c=e.get(r,o.path);if(!t.isText(c))throw new Error("Cannot insert text into non-text node");a.insert(u.start+o.offset,o.text,Ja(c))},remove_text:function(t,e,n){var r=cu(t,e,n.path),o=r.yParent,i=r.textRange;o.delete(i.start+n.offset,n.text.length)}}),Gu),{set_selection:function(){}});var Uu=Symbol("slate-yjs-operation"),Yu=Symbol("slate-yjs-position-storage"),Vu=new WeakMap,$u=new WeakMap,qu=new WeakSet,Hu={isYjsEditor:function(t){return r.isEditor(t)&&t.sharedRoot instanceof i.XmlText&&"localOrigin"in t&&"positionStorageOrigin"in t&&"function"==typeof t.applyRemoteEvents&&"function"==typeof t.storeLocalChange&&"function"==typeof t.flushLocalChanges&&"function"==typeof t.isLocalOrigin&&"function"==typeof t.connect&&"function"==typeof t.disconnect},localChanges:function(t){var e;return null!==(e=$u.get(t))&&void 0!==e?e:[]},applyRemoteEvents:function(t,e,n){t.applyRemoteEvents(e,n)},storeLocalChange:function(t,e){t.storeLocalChange(e)},flushLocalChanges:function(t){t.flushLocalChanges()},connected:function(t){return qu.has(t)},connect:function(t){t.connect()},disconnect:function(t){t.disconnect()},isLocal:function(t){return t.isLocalOrigin(Hu.origin(t))},origin:function(t){var e=Vu.get(t);return void 0!==e?e:t.localOrigin},withOrigin:function(t,e,n){var r=Hu.origin(t);Vu.set(t,e),n(),Vu.set(t,r)},storePosition:function(t,e,n){var r=t.sharedRoot,o=t.positionStorageOrigin;Cu(r);var i=Fu(r,t,n);r.doc.transact((function(){Mu(r,e,i)}),o)},removeStoredPosition:function(t,e){var n=t.sharedRoot,r=t.positionStorageOrigin;Cu(n),n.doc.transact((function(){!function(t,e){t.removeAttribute(Lu+e)}(n,e)}),r)},position:function(t,e){var n=function(t,e){var n=t.getAttribute(Lu+e);return n?i.decodeRelativePosition(n):null}(t.sharedRoot,e);if(n)return _u(t.sharedRoot,t,n)},storedPositionsRelative:function(t){return e=t.sharedRoot,Object.fromEntries(Object.entries(e.getAttributes()).filter((function(t){return sa(t,1)[0].startsWith(Lu)})).map((function(t){var e=sa(t,2),n=e[0],r=e[1];return[n.slice(Lu.length),i.createRelativePositionFromJSON(r)]})));var e}};function Ju(t,e){return void 0===e&&(e={}),function(n){var o,i,a=n;a.sharedRoot=t,a.localOrigin=null!==(o=e.localOrigin)&&void 0!==o?o:Uu,a.positionStorageOrigin=null!==(i=e.positionStorageOrigin)&&void 0!==i?i:Yu,a.applyRemoteEvents=function(t,e){Hu.flushLocalChanges(a),r.withoutNormalizing(a,(function(){Hu.withOrigin(a,e,(function(){du(a.sharedRoot,a,t)}))}))},a.isLocalOrigin=function(t){return t===a.localOrigin};var u=function(t,e){a.isLocalOrigin(e.origin)||Hu.applyRemoteEvents(a,t,e.origin)},c=null;e.autoConnect&&(c=setTimeout((function(){c=null,Hu.connect(a)}))),a.connect=function(){if(Hu.connected(a))throw new Error("already connected");a.sharedRoot.observeDeep(u);var t=Ka(a.sharedRoot);a.children=t.children,qu.add(a),r.normalize(n,{force:!0}),n.operations.length||n.onChange()},a.disconnect=function(){c&&clearTimeout(c),Hu.flushLocalChanges(a),a.sharedRoot.unobserveDeep(u),qu.delete(a)},a.storeLocalChange=function(t){$u.set(a,fa(fa([],sa(Hu.localChanges(a)),!1),[{op:t,doc:n.children,origin:Hu.origin(a)}],!1))},a.flushLocalChanges=function(){Cu(a.sharedRoot);var t=Hu.localChanges(a);$u.delete(a);var e=[];t.forEach((function(t){var n=e[e.length-1];if(n&&n[0].origin===t.origin)return n.push(t);e.push([t])})),e.forEach((function(t){Cu(a.sharedRoot),a.sharedRoot.doc.transact((function(){t.forEach((function(t){Cu(a.sharedRoot),function(t,e,n){var r=Bu[n.type];if(!r)throw new Error("Unknown operation: ".concat(n.type));r(t,e,n)}(a.sharedRoot,{children:t.doc},t.op)}))}),t[0].origin)}))};var s=a.apply,f=a.onChange;return a.apply=function(t){Hu.connected(a)&&Hu.isLocal(a)&&Hu.storeLocalChange(a,t),s(t)},a.onChange=function(){Hu.connected(a)&&Hu.flushLocalChanges(a),f()},a}}var Ku=Ot("species"),Qu=Ko.fastKey,Zu=se.set,tc=se.getterFor,ec={getConstructor:function(t,e,n,r){var o=t((function(t,o){li(t,i),Zu(t,{type:e,index:fn(null),first:null,last:null,size:0}),h||(t.size=0),L(o)||si(o,t[r],{that:t,AS_ENTRIES:n})})),i=o.prototype,a=tc(e),u=function(t,e,n){var r,o,i=a(t),u=c(t,e);return u?u.value=n:(i.last=u={index:o=Qu(e,!0),key:e,value:n,previous:r=i.last,next:null,removed:!1},i.first||(i.first=u),r&&(r.next=u),h?i.size++:t.size++,"F"!==o&&(i.index[o]=u)),t},c=function(t,e){var n,r=a(t),o=Qu(e);if("F"!==o)return r.index[o];for(n=r.first;n;n=n.next)if(n.key===e)return n};return $o(i,{clear:function(){for(var t=a(this),e=t.first;e;)e.removed=!0,e.previous&&(e.previous=e.previous.next=null),e=e.next;t.first=t.last=null,t.index=fn(null),h?t.size=0:this.size=0},delete:function(t){var e=this,n=a(e),r=c(e,t);if(r){var o=r.next,i=r.previous;delete n.index[r.index],r.removed=!0,i&&(i.next=o),o&&(o.previous=i),n.first===r&&(n.first=o),n.last===r&&(n.last=i),h?n.size--:e.size--}return!!r},forEach:function(t){for(var e,n=a(this),r=En(t,arguments.length>1?arguments[1]:void 0);e=e?e.next:n.first;)for(r(e.value,e.key,this);e&&e.removed;)e=e.previous},has:function(t){return!!c(this,t)}}),$o(i,n?{get:function(t){var e=c(this,t);return e&&e.value},set:function(t,e){return u(this,0===t?0:t,e)}}:{add:function(t){return u(this,t=0===t?0:t,t)}}),h&&vn(i,"size",{configurable:!0,get:function(){return a(this).size}}),o},setStrong:function(t,e,n){var r=e+" Iterator",o=tc(e),i=tc(r);Ao(t,e,(function(t,e){Zu(this,{type:r,target:t,state:o(t),kind:e,last:null})}),(function(){for(var t=i(this),e=t.kind,n=t.last;n&&n.removed;)n=n.previous;return t.target&&(t.last=n=n?n.next:t.state.first)?ko("keys"===e?n.key:"values"===e?n.value:[n.key,n.value],!1):(t.target=null,ko(void 0,!0))}),n?"entries":"values",!n,!0),function(t){var e=N(t);h&&e&&!e[Ku]&&vn(e,Ku,{configurable:!0,get:function(){return this}})}(e)}};yi("Set",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),ec);var nc=new WeakMap,rc=Symbol("slate-yjs-history-without-saving"),oc={isYHistoryEditor:function(t){return Hu.isYjsEditor(t)&&t.undoManager instanceof i.UndoManager&&"function"==typeof t.undo&&"function"==typeof t.redo&&"withoutSavingOrigin"in t},canUndo:function(t){return t.undoManager.undoStack.length>0},canRedo:function(t){return t.undoManager.redoStack.length>0},isSaving:function(t){return t.undoManager.trackedOrigins.has(Hu.origin(t))},withoutSaving:function(t,e){Hu.withOrigin(t,t.withoutSavingOrigin,e)}};function ic(t){return void 0===t&&(t={}),function(e){var n=e,r=t.withoutSavingOrigin,a=void 0===r?rc:r,u=t.trackedOrigins,c=void 0===u?new Set([n.localOrigin]):u,s=ua(t,["withoutSavingOrigin","trackedOrigins"]),f=new i.UndoManager(n.sharedRoot,aa({trackedOrigins:c},s));n.undoManager=f,n.withoutSavingOrigin=a;var l=n.onChange,d=n.isLocalOrigin;n.onChange=function(){l(),nc.set(n,n.selection&&Wu(n.sharedRoot,n,n.selection))},n.isLocalOrigin=function(t){return t===n.withoutSavingOrigin||d(t)};var h=function(t){var e=t.stackItem;e.meta.set("selection",n.selection&&Wu(n.sharedRoot,n,n.selection)),e.meta.set("selectionBefore",nc.get(n))},p=function(t){t.stackItem.meta.set("selection",n.selection&&Wu(n.sharedRoot,n,n.selection))},v=function(t){var e=t.stackItem,r="undo"===t.type?n.undoManager.redoStack:n.undoManager.undoStack,i=r[r.length-1];i&&(i.meta.set("selection",e.meta.get("selectionBefore")),i.meta.set("selectionBefore",e.meta.get("selection")));var a=e.meta.get("selectionBefore");if(a){var u=Xu(n.sharedRoot,n,a);u&&o.select(n,u)}},g=n.connect,y=n.disconnect;return n.connect=function(){g(),n.undoManager.on("stack-item-added",h),n.undoManager.on("stack-item-popped",v),n.undoManager.on("stack-item-updated",p)},n.disconnect=function(){n.undoManager.off("stack-item-added",h),n.undoManager.off("stack-item-popped",v),n.undoManager.off("stack-item-updated",p),y()},n.undo=function(){Hu.connected(n)&&(Hu.flushLocalChanges(n),n.undoManager.undo())},n.redo=function(){Hu.connected(n)&&(Hu.flushLocalChanges(n),n.undoManager.redo())},n}}var ac=new WeakMap,uc={isCursorEditor:function(t){return Hu.isYjsEditor(t)&&t.awareness&&"string"==typeof t.cursorDataField&&"string"==typeof t.selectionStateField&&"function"==typeof t.sendCursorPosition&&"function"==typeof t.sendCursorData},sendCursorPosition:function(t,e){void 0===e&&(e=t.selection),t.sendCursorPosition(e)},sendCursorData:function(t,e){t.sendCursorData(e)},on:function(t,e,n){var r;if("change"===e){var o=null!==(r=ac.get(t))&&void 0!==r?r:new Set;o.add(n),t&&ac.set(t,o)}},off:function(t,e,n){if("change"===e){var r=ac.get(t);r&&r.delete(n)}},cursorState:function(t,e){var n;if(e===t.awareness.clientID||!Hu.connected(t))return null;var r=t.awareness.getStates().get(e);return r?{relativeSelection:null!==(n=r[t.selectionStateField])&&void 0!==n?n:null,data:r[t.cursorDataField],clientId:e}:null},cursorStates:function(t){return Hu.connected(t)?Object.fromEntries(Array.from(t.awareness.getStates().entries(),(function(e){var n=sa(e,2),r=n[0],o=n[1];return r!==t.awareness.clientID&&o?[r,{relativeSelection:o[t.selectionStateField],data:o[t.cursorDataField]}]:null})).filter(Array.isArray)):{}}};function cc(t,e){return void 0===e&&(e={}),function(n){var r=e.cursorStateField,o=void 0===r?"selection":r,a=e.cursorDataField,u=void 0===a?"data":a,c=e.autoSend,s=void 0===c||c,f=e.data,l=n;l.awareness=t,l.cursorDataField=u,l.selectionStateField=o,l.sendCursorData=function(t){l.awareness.setLocalStateField(l.cursorDataField,t)},l.sendCursorPosition=function(t){var e=l.awareness.getLocalState(),n=null==e?void 0:e[o];if(t){var r=Wu(l.sharedRoot,l,t),a=r.anchor,u=r.focus;n&&i.compareRelativePositions(a,n)&&i.compareRelativePositions(u,n)||l.awareness.setLocalStateField(l.selectionStateField,{anchor:a,focus:u})}else n&&l.awareness.setLocalStateField(l.selectionStateField,null)};var d=function(t){var e=ac.get(l);if(e){var n=l.awareness.clientID,r={added:t.added.filter((function(t){return t!==n})),removed:t.removed.filter((function(t){return t!==n})),updated:t.updated.filter((function(t){return t!==n}))};(r.added.length>0||r.removed.length>0||r.updated.length>0)&&e.forEach((function(t){return t(r)}))}},h=l.connect,p=l.disconnect;return l.connect=function(){if(h(),l.awareness.on("change",d),d({removed:[],added:Array.from(l.awareness.getStates().keys()),updated:[]}),s){f&&uc.sendCursorData(l,f);var t=l.onChange;l.onChange=function(){t(),Hu.connected(l)&&uc.sendCursorPosition(l)}}},l.disconnect=function(){l.awareness.off("change",d),d({removed:Array.from(l.awareness.getStates().keys()),added:[],updated:[]}),p()},l}}export{uc as CursorEditor,oc as YHistoryEditor,Hu as YjsEditor,_u as relativePositionToSlatePoint,Xu as relativeRangeToSlateRange,Za as slateNodesToInsertDelta,Fu as slatePointToRelativePosition,Wu as slateRangeToRelativeRange,cc as withCursors,ic as withYHistory,Ju as withYjs,Ka as yTextToSlateElement};
2
+ //# sourceMappingURL=index.esm.js.map