@wangeditor-next/yjs 0.1.2 → 0.1.4
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/applyToYjs/types.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +2 -1719
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -1438
- package/dist/index.js.map +1 -1
- package/dist/module/custom-types.d.ts +11 -11
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/withCursors.d.ts +6 -6
- package/dist/plugins/withYHistory.d.ts +2 -2
- package/dist/plugins/withYjs.d.ts +3 -3
- package/dist/utils/object.d.ts +4 -4
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,1719 +1,2 @@
|
|
|
1
|
-
import { Text, Node, Path, Editor, Transforms } from 'slate'
|
|
2
|
-
|
|
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*as t from"yjs";import{Text as e,Node as n,Path as r,Editor as o,Transforms as i}from"slate";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=function(t){if("Function"===R(t))return j(t)},Ue=Be(Be.bind),Ye=function(t,e){return rt(t),void 0===e?t:p?Ue(t,e):function(){return t.apply(e,arguments)}},Ve=Array.isArray||function(t){return"Array"===R(t)},$e={};$e[Ot("toStringTag")]="z";var qe="[object z]"===String($e),He=Ot("toStringTag"),Je=Object,Ke="Arguments"===R(function(){return arguments}()),Qe=qe?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=Je(t),He))?n:Ke?R(e):"Object"===(r=R(e))&&I(e.callee)?"Arguments":r},Ze=function(){},tn=N("Reflect","construct"),en=/^\s*(?:class|function)\b/,nn=j(en.exec),rn=!en.test(Ze),on=function(t){if(!I(t))return!1;try{return tn(Ze,[],t),!0}catch(t){return!1}},an=function(t){if(!I(t))return!1;switch(Qe(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return rn||!!nn(en,Qt(t))}catch(t){return!0}};an.sham=!0;var un=!tn||d((function(){var t;return on(on.call)||!on(Object)||!on((function(){t=!0}))||t}))?an:on,cn=Ot("species"),sn=Array,fn=function(t,e){return new(function(t){var e;return Ve(t)&&(e=t.constructor,(un(e)&&(e===sn||Ve(e.prototype))||z(e)&&null===(e=e[cn]))&&(e=void 0)),void 0===e?sn:e}(t))(0===e?0:e)},ln=j([].push),dn=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=Ye(s,f),b=0,m=l||fn,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:ln(w,d)}else switch(t){case 4:return!1;case 7:ln(w,d)}return i?-1:r||o?o:w}},hn={forEach:dn(0),map:dn(1),filter:dn(2),some:dn(3),every:dn(4),find:dn(5),findIndex:dn(6),filterReject:dn(7)},pn=Ot("species"),vn=function(t){return q>=51||!d((function(){var e=[];return(e.constructor={})[pn]=function(){return{foo:1}},1!==e[t](Boolean).foo}))},gn=hn.filter,yn=vn("filter");Ge({target:"Array",proto:!0,forced:!yn},{filter:function(t){return gn(this,t,arguments.length>1?arguments[1]:void 0)}});var bn=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},mn=function(t,e,n,r){try{return r?e(Mt(n)[0],n[1]):e(n)}catch(e){bn(t,"throw",e)}},wn={},On=Ot("iterator"),Sn=Array.prototype,xn=function(t){return void 0!==t&&(wn.Array===t||Sn[On]===t)},En=function(t,e,n){h?Gt.f(t,e,O(0,n)):t[e]=n},jn=Ot("iterator"),Tn=function(t){if(!L(t))return ot(t,jn)||ot(t,"@@iterator")||wn[Qe(t)]},Pn=TypeError,Rn=function(t,e){var n=arguments.length<2?Tn(t):e;if(rt(n))return Mt(g(n,t));throw new Pn(et(t)+" is not iterable")},An=Array,kn=Ot("iterator"),Cn=!1;try{var Ln=0,Fn={next:function(){return{done:!!Ln++}},return:function(){Cn=!0}};Fn[kn]=function(){return this},Array.from(Fn,(function(){throw 2}))}catch(t){}var _n=function(t,e){try{if(!e&&!Cn)return!1}catch(t){return!1}var n=!1;try{var r={};r[kn]=function(){return{next:function(){return{done:n=!0}}}},t(r)}catch(t){}return n},Mn=!_n((function(t){Array.from(t)}));Ge({target:"Array",stat:!0,forced:Mn},{from:function(t){var e=lt(t),n=un(this),r=arguments.length,o=r>1?arguments[1]:void 0,i=void 0!==o;i&&(o=Ye(o,r>2?arguments[2]:void 0));var a,u,c,s,f,l,d=Tn(e),h=0;if(!d||this===An&&xn(d))for(a=Oe(e),u=n?new this(a):An(a);a>h;h++)l=i?o(e[h],h):e[h],En(u,h,l);else for(u=n?new this:[],f=(s=Rn(e,d)).next;!(c=g(f,s)).done;h++)l=i?mn(s,o,[c.value,h],!0):c.value,En(u,h,l);return u.length=h,u}});var Dn,In=Object.keys||function(t){return Te(t,Pe)},zn=h&&!Lt?Object.defineProperties:function(t,e){Mt(t);for(var n,r=M(e),o=In(e),i=o.length,a=0;i>a;)Gt.f(t,n=o[a++],r[n]);return t},Nn={f:zn},Wn=N("document","documentElement"),Xn="prototype",Gn="script",Bn=ne("IE_PROTO"),Un=function(){},Yn=function(t){return"<"+Gn+">"+t+"</"+Gn+">"},Vn=function(t){t.write(Yn("")),t.close();var e=t.parentWindow.Object;return t=null,e},$n=function(){try{Dn=new ActiveXObject("htmlfile")}catch(t){}var t,e,n;$n="undefined"!=typeof document?document.domain&&Dn?Vn(Dn):(e=Rt("iframe"),n="java"+Gn+":",e.style.display="none",Wn.appendChild(e),e.src=String(n),(t=e.contentWindow.document).open(),t.write(Yn("document.F=Object")),t.close(),t.F):Vn(Dn);for(var r=Pe.length;r--;)delete $n[Xn][Pe[r]];return $n()};re[Bn]=!0;var qn=Object.create||function(t,e){var n;return null!==t?(Un[Xn]=Mt(t),n=new Un,Un[Xn]=null,n[Bn]=t):n=$n(),void 0===e?n:Nn.f(n,e)},Hn=Gt.f,Jn=Ot("unscopables"),Kn=Array.prototype;void 0===Kn[Jn]&&Hn(Kn,Jn,{configurable:!0,value:qn(null)});var Qn,Zn,tr,er=function(t){Kn[Jn][t]=!0},nr=!d((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),rr=ne("IE_PROTO"),or=Object,ir=or.prototype,ar=nr?or.getPrototypeOf:function(t){var e=lt(t);if(ht(e,rr))return e[rr];var n=e.constructor;return I(n)&&e instanceof n?n.prototype:e instanceof or?ir:null},ur=Ot("iterator"),cr=!1;[].keys&&("next"in(tr=[].keys())?(Zn=ar(ar(tr)))!==Object.prototype&&(Qn=Zn):cr=!0);var sr=!z(Qn)||d((function(){var t={};return Qn[ur].call(t)!==t}));sr&&(Qn={}),I(Qn[ur])||le(Qn,ur,(function(){return this}));var fr={IteratorPrototype:Qn,BUGGY_SAFARI_ITERATORS:cr},lr=Gt.f,dr=Ot("toStringTag"),hr=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ht(t,dr)&&lr(t,dr,{configurable:!0,value:e})},pr=fr.IteratorPrototype,vr=function(){return this},gr=String,yr=TypeError,br=function(t){if(function(t){return z(t)||null===t}(t))return t;throw new yr("Can't set "+gr(t)+" as a prototype")},mr=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),br(r),z(n)?(e?t(n,r):n.__proto__=r,n):n}}():void 0),wr=$t.PROPER,Or=$t.CONFIGURABLE,Sr=fr.IteratorPrototype,xr=fr.BUGGY_SAFARI_ITERATORS,Er=Ot("iterator"),jr="keys",Tr="values",Pr="entries",Rr=function(){return this},Ar=function(t,e,n,r,o,i,a){!function(t,e,n,r){var o=e+" Iterator";t.prototype=qn(pr,{next:O(+!r,n)}),hr(t,o,!1),wn[o]=vr}(n,e,r);var u,c,s,f=function(t){if(t===o&&v)return v;if(!xr&&t&&t in h)return h[t];switch(t){case jr:case Tr:case Pr:return function(){return new n(this,t)}}return function(){return new n(this)}},l=e+" Iterator",d=!1,h=t.prototype,p=h[Er]||h["@@iterator"]||o&&h[o],v=!xr&&p||f(o),y="Array"===e&&h.entries||p;if(y&&(u=ar(y.call(new t)))!==Object.prototype&&u.next&&(ar(u)!==Sr&&(mr?mr(u,Sr):I(u[Er])||le(u,Er,Rr)),hr(u,l,!0)),wr&&o===Tr&&p&&p.name!==Tr&&(Or?Bt(h,"name",Tr):(d=!0,v=function(){return g(p,this)})),o)if(c={values:f(Tr),keys:i?v:f(jr),entries:f(Pr)},a)for(s in c)(xr||d||!(s in h))&&le(h,s,c[s]);else Ge({target:e,proto:!0,forced:xr||d},c);return h[Er]!==v&&le(h,Er,v,{name:o}),wn[e]=v,c},kr=function(t,e){return{value:t,done:e}},Cr=Gt.f,Lr="Array Iterator",Fr=se.set,_r=se.getterFor(Lr),Mr=Ar(Array,"Array",(function(t,e){Fr(this,{type:Lr,target:M(t),index:0,kind:e})}),(function(){var t=_r(this),e=t.target,n=t.index++;if(!e||n>=e.length)return t.target=null,kr(void 0,!0);switch(t.kind){case"keys":return kr(n,!1);case"values":return kr(e[n],!1)}return kr([n,e[n]],!1)}),"values"),Dr=wn.Arguments=wn.Array;if(er("keys"),er("values"),er("entries"),h&&"values"!==Dr.name)try{Cr(Dr,"name",{value:"values"})}catch(t){}var Ir=TypeError,zr=function(t,e){this.stopped=t,this.result=e},Nr=zr.prototype,Wr=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=Ye(e,f),y=function(t){return r&&bn(r,"normal",t),new zr(!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=Tn(t)))throw new Ir(et(t)+" is not iterable");if(xn(o)){for(i=0,a=Oe(t);a>i;i++)if((u=b(t[i]))&&W(Nr,u))return u;return new zr(!1)}r=Rn(t,o)}for(c=d?t.next:r.next;!(s=g(c,r)).done;){try{u=b(s.value)}catch(t){bn(r,"throw",t)}if("object"==typeof u&&u&&W(Nr,u))return u}return new zr(!1)};Ge({target:"Object",stat:!0},{fromEntries:function(t){var e={};return Wr(t,(function(t,n){En(e,t,n)}),{AS_ENTRIES:!0}),e}});var Xr=qe?{}.toString:function(){return"[object "+Qe(this)+"]"};qe||le(Object.prototype,"toString",Xr,{unsafe:!0});var Gr=j([].slice),Br=Ae.f,Ur="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],Yr={f:function(t){return Ur&&"Window"===R(t)?function(t){try{return Br(t)}catch(t){return Gr(Ur)}}(t):Br(M(t))}},Vr=d((function(){if("function"==typeof ArrayBuffer){var t=new ArrayBuffer(8);Object.isExtensible(t)&&Object.defineProperty(t,"a",{value:8})}})),$r=Object.isExtensible,qr=d((function(){$r(1)}))||Vr?function(t){return!!z(t)&&((!Vr||"ArrayBuffer"!==R(t))&&(!$r||$r(t)))}:$r,Hr=!d((function(){return Object.isExtensible(Object.preventExtensions({}))})),Jr=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:Yr.f}))},fastKey:function(t,e){if(!z(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!ht(t,r)){if(!qr(t))return"F";if(!e)return"E";i(t)}return t[r].objectID},getWeakData:function(t,e){if(!ht(t,r)){if(!qr(t))return!0;if(!e)return!1;i(t)}return t[r].weakData},onFreeze:function(t){return Hr&&n&&qr(t)&&!ht(t,r)&&i(t),t}};re[r]=!0})),Kr=TypeError,Qr=function(t,e){if(W(e,t))return t;throw new Kr("Incorrect invocation")},Zr=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),Jr.enable();else if(We(t,!0)){var h=new c,p=h[i](o?{}:-0,1)!==h,v=d((function(){h.has(1)})),g=_n((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){Qr(t,u);var n=function(t,e,n){var r,o;return mr&&I(r=e.constructor)&&r!==n&&z(o=r.prototype)&&o!==n.prototype&&mr(t,o),t}(new a,t,c);return L(e)||Wr(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),hr(c,t),o||n.setStrong(c,t,r),c},to=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)},eo=function(t,e,n){for(var r in e)le(t,r,e[r],n);return t},no=Ot("species"),ro=Jr.fastKey,oo=se.set,io=se.getterFor,ao={getConstructor:function(t,e,n,r){var o=t((function(t,o){Qr(t,i),oo(t,{type:e,index:qn(null),first:null,last:null,size:0}),h||(t.size=0),L(o)||Wr(o,t[r],{that:t,AS_ENTRIES:n})})),i=o.prototype,a=io(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=ro(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=ro(e);if("F"!==o)return r.index[o];for(n=r.first;n;n=n.next)if(n.key===e)return n};return eo(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=qn(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=Ye(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)}}),eo(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&&to(i,"size",{configurable:!0,get:function(){return a(this).size}}),o},setStrong:function(t,e,n){var r=e+" Iterator",o=io(e),i=io(r);Ar(t,e,(function(t,e){oo(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)?kr("keys"===e?n.key:"values"===e?n.value:[n.key,n.value],!1):(t.target=null,kr(void 0,!0))}),n?"entries":"values",!n,!0),function(t){var e=N(t);h&&e&&!e[no]&&to(e,no,{configurable:!0,get:function(){return this}})}(e)}};Zr("Set",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),ao);var uo=String,co=function(t){if("Symbol"===Qe(t))throw new TypeError("Cannot convert a Symbol value to a string");return uo(t)},so=j("".charAt),fo=j("".charCodeAt),lo=j("".slice),ho=function(t){return function(e,n){var r,o,i=co(_(e)),a=ve(n),u=i.length;return a<0||a>=u?t?"":void 0:(r=fo(i,a))<55296||r>56319||a+1===u||(o=fo(i,a+1))<56320||o>57343?t?so(i,a):r:t?lo(i,a,a+2):o-56320+(r-55296<<10)+65536}},po={codeAt:ho(!1),charAt:ho(!0)}.charAt,vo="String Iterator",go=se.set,yo=se.getterFor(vo);Ar(String,"String",(function(t){go(this,{type:vo,string:co(t),index:0})}),(function(){var t,e=yo(this),n=e.string,r=e.index;return r>=n.length?kr(void 0,!0):(t=po(n,r),e.index+=t.length,kr(t,!1))}));var bo,mo=/"/g,wo=j("".replace);Ge({target:"String",proto:!0,forced:(bo="anchor",d((function(){var t=""[bo]('"');return t!==t.toLowerCase()||t.split('"').length>3})))},{anchor:function(t){return e="a",n="name",r=t,o=co(_(this)),i="<"+e,""!==n&&(i+=" "+n+'="'+wo(co(r),mo,""")+'"'),i+">"+o+"</"+e+">";var e,n,r,o,i}});var Oo=Jr.getWeakData,So=se.set,xo=se.getterFor,Eo=hn.find,jo=hn.findIndex,To=j([].splice),Po=0,Ro=function(t){return t.frozen||(t.frozen=new Ao)},Ao=function(){this.entries=[]},ko=function(t,e){return Eo(t.entries,(function(t){return t[0]===e}))};Ao.prototype={get:function(t){var e=ko(this,t);if(e)return e[1]},has:function(t){return!!ko(this,t)},set:function(t,e){var n=ko(this,t);n?n[1]=e:this.entries.push([t,e])},delete:function(t){var e=jo(this.entries,(function(e){return e[0]===t}));return~e&&To(this.entries,e,1),!!~e}};var Co,Lo={getConstructor:function(t,e,n,r){var o=t((function(t,o){Qr(t,i),So(t,{type:e,id:Po++,frozen:null}),L(o)||Wr(o,t[r],{that:t,AS_ENTRIES:n})})),i=o.prototype,a=xo(e),u=function(t,e,n){var r=a(t),o=Oo(Mt(e),!0);return!0===o?Ro(r).set(e,n):o[r.id]=n,t};return eo(i,{delete:function(t){var e=a(this);if(!z(t))return!1;var n=Oo(t);return!0===n?Ro(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=Oo(t);return!0===n?Ro(e).has(t):n&&ht(n,e.id)}}),eo(i,n?{get:function(t){var e=a(this);if(z(t)){var n=Oo(t);if(!0===n)return Ro(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}},Fo=se.enforce,_o=Object,Mo=Array.isArray,Do=_o.isExtensible,Io=_o.isFrozen,zo=_o.isSealed,No=_o.freeze,Wo=_o.seal,Xo=!l.ActiveXObject&&"ActiveXObject"in l,Go=function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}},Bo=Zr("WeakMap",Go,Lo),Uo=Bo.prototype,Yo=j(Uo.set);if(te)if(Xo){Co=Lo.getConstructor(Go,"WeakMap",!0),Jr.enable();var Vo=j(Uo.delete),$o=j(Uo.has),qo=j(Uo.get);eo(Uo,{delete:function(t){if(z(t)&&!Do(t)){var e=Fo(this);return e.frozen||(e.frozen=new Co),Vo(this,t)||e.frozen.delete(t)}return Vo(this,t)},has:function(t){if(z(t)&&!Do(t)){var e=Fo(this);return e.frozen||(e.frozen=new Co),$o(this,t)||e.frozen.has(t)}return $o(this,t)},get:function(t){if(z(t)&&!Do(t)){var e=Fo(this);return e.frozen||(e.frozen=new Co),$o(this,t)?qo(this,t):e.frozen.get(t)}return qo(this,t)},set:function(t,e){if(z(t)&&!Do(t)){var n=Fo(this);n.frozen||(n.frozen=new Co),$o(this,t)?Yo(this,t,e):n.frozen.set(t,e)}else Yo(this,t,e);return this}})}else Hr&&d((function(){var t=No([]);return Yo(new Bo,t,1),!Io(t)}))&&eo(Uo,{set:function(t,e){var n;return Mo(t)&&(Io(t)?n=No:zo(t)&&(n=Wo)),Yo(this,t,e),n&&n(t),this}});var Ho={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},Jo=Rt("span").classList,Ko=Jo&&Jo.constructor&&Jo.constructor.prototype,Qo=Ko===Object.prototype?void 0:Ko,Zo=hn.forEach,ti=function(t,e){var n=[][t];return!!n&&d((function(){n.call(null,e||function(){return 1},1)}))}("forEach"),ei=ti?[].forEach:function(t){return Zo(this,t,arguments.length>1?arguments[1]:void 0)},ni=function(t){if(t&&t.forEach!==ei)try{Bt(t,"forEach",ei)}catch(e){t.forEach=ei}};for(var ri in Ho)Ho[ri]&&ni(l[ri]&&l[ri].prototype);ni(Qo);var oi=Ot("iterator"),ii=Mr.values,ai=function(t,e){if(t){if(t[oi]!==ii)try{Bt(t,oi,ii)}catch(e){t[oi]=ii}if(hr(t,e,!0),Ho[e])for(var n in Mr)if(t[n]!==Mr[n])try{Bt(t,n,Mr[n])}catch(e){t[n]=Mr[n]}}};for(var ui in Ho)ai(l[ui]&&l[ui].prototype,ui);ai(Qo,"DOMTokenList");var ci=function(){return ci=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},ci.apply(this,arguments)};function si(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 fi(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 li(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 di(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 hi=TypeError,pi=function(t){if(t>9007199254740991)throw hi("Maximum allowed index exceeded");return t},vi=Ot("isConcatSpreadable"),gi=q>=51||!d((function(){var t=[];return t[vi]=!1,t.concat()[0]!==t})),yi=function(t){if(!z(t))return!1;var e=t[vi];return void 0!==e?!!e:Ve(t)},bi=!gi||!vn("concat");Ge({target:"Array",proto:!0,arity:1,forced:bi},{concat:function(t){var e,n,r,o,i,a=lt(this),u=fn(a,0),c=0;for(e=-1,r=arguments.length;e<r;e++)if(yi(i=-1===e?a:arguments[e]))for(o=Oe(i),pi(c+o),n=0;n<o;n++,c++)n in i&&En(u,c,i[n]);else pi(c+1),En(u,c++,i);return u.length=c,u}});var mi=hn.map,wi=vn("map");Ge({target:"Array",proto:!0,forced:!wi},{map:function(t){return mi(this,t,arguments.length>1?arguments[1]:void 0)}});var Oi=vn("slice"),Si=Ot("species"),xi=Array,Ei=Math.max;Ge({target:"Array",proto:!0,forced:!Oi},{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(Ve(i)&&(n=i.constructor,(un(n)&&(n===xi||Ve(n.prototype))||z(n)&&null===(n=n[Si]))&&(n=void 0),n===xi||void 0===n))return Gr(i,u,c);for(r=new(void 0===n?xi:n)(Ei(c-u,0)),o=0;u<c;u++,o++)u in i&&En(r,o,i[u]);return r.length=o,r}});var ji=Object.assign,Ti=Object.defineProperty,Pi=j([].concat),Ri=!ji||d((function(){if(h&&1!==ji({b:1},ji(Ti({},"a",{enumerable:!0,get:function(){Ti(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!==ji({},t)[n]||In(ji({},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?Pi(In(c),i(c)):In(c),f=s.length,l=0;f>l;)u=s[l++],h&&!g(a,c,u)||(n[u]=c[u]);return n}:ji;Ge({target:"Object",stat:!0,arity:2,forced:Object.assign!==Ri},{assign:Ri});var Ai=w.f,ki=j(Ai),Ci=j([].push),Li=h&&d((function(){var t=Object.create(null);return t[2]=2,!ki(t,2)})),Fi=function(t){return function(e){for(var n,r=M(e),o=In(r),i=Li&&null===ar(r),a=o.length,u=0,c=[];a>u;)n=o[u++],h&&!(i?n in r:ki(r,n))||Ci(c,t?[n,r[n]]:r[n]);return c}},_i={entries:Fi(!0),values:Fi(!1)}.entries;Ge({target:"Object",stat:!0},{entries:function(t){return _i(t)}});var Mi=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},Di=RegExp.prototype,Ii=$t.PROPER,zi="toString",Ni=RegExp.prototype,Wi=Ni[zi],Xi=d((function(){return"/a/b"!==Wi.call({source:"a",flags:"b"})})),Gi=Ii&&Wi.name!==zi;(Xi||Gi)&&le(Ni,zi,(function(){var t=Mt(this),e=co(t.source),n=co(function(t){var e=t.flags;return void 0!==e||"flags"in Di||ht(t,"flags")||!W(Di,t)?e:g(Mi,t)}(t));return"/"+e+"/"+n}),{unsafe:!0});var Bi,Ui=Ot("match"),Yi=TypeError,Vi=function(t){if(function(t){var e;return z(t)&&(void 0!==(e=t[Ui])?!!e:"RegExp"===R(t))}(t))throw new Yi("The method doesn't accept regular expressions");return t},$i=Ot("match"),qi=Ct.f,Hi=Be("".slice),Ji=Math.min,Ki=function(t){var e=/./;try{"/./"[t](e)}catch(n){try{return e[$i]=!1,"/./"[t](e)}catch(t){}}return!1}("startsWith"),Qi=!(Ki||(Bi=qi(String.prototype,"startsWith"),!Bi||Bi.writable));Ge({target:"String",proto:!0,forced:!Qi&&!Ki},{startsWith:function(t){var e=co(_(this));Vi(t);var n=we(Ji(arguments.length>1?arguments[1]:void 0,e.length)),r=co(t);return Hi(e,n,n+r.length)===r}});var Zi=xe.includes,ta=d((function(){return!Array(1).includes()}));function ea(t){return"[object Object]"===Object.prototype.toString.call(t)}function na(t){if(!ea(t))return!1;var e=t.constructor;if(void 0===e)return!0;var n=e.prototype;return!1!==ea(n)&&!Object.prototype.hasOwnProperty.call(n,"isPrototypeOfOf")}function ra(t,e){for(var n in t){var r=t[n],o=e[n];if(na(r)&&na(o)){if(!ra(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 oa(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=li(t,1)[0];return e.includes(n)})))}function ia(t){return function(t){var e,n,r,o,i=[];try{for(var a=fi(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&&ra(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 aa(t){var e=t.insert;return"string"==typeof e?e.length:1}function ua(t){return t.reduce((function(t,e){return t+aa(e)}),0)}function ca(t,e,n){if(n<1)return[];for(var r=0,o=[],i=e+n,a=0;a<t.length&&!(r>=i);a+=1){var u=t[a],c=aa(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(ci(ci({},u),{insert:u.insert.slice(s,f)})),r+=c}else r+=c,o.push(u)}return o}function sa(t){return t?e.isText(t)?t.text.length:1:0}function fa(n,r,o){var i;if(0===o.length)throw new Error("Path has to a have a length >= 1");if(e.isText(r))throw new Error("Cannot descent into slate text");var a=li(o),u=a[0],c=a.slice(1),s=function(t,e){return t.children.slice(0,e).reduce((function(t,e){return t+sa(e)}),0)}(r,u),f=r.children[u],l=ia(n),d=sa(f),h=ca(l,s,d);if(h.length>1)throw new Error("Path doesn't match yText, yTarget spans multiple nodes");var p=null===(i=h[0])||void 0===i?void 0:i.insert;if(c.length>0){if(!(p instanceof t.XmlText))throw new Error("Path doesn't match yText, cannot descent into non-yText");return fa(p,f,c)}return{yParent:n,textRange:{start:s,end:s+d},yTarget:p instanceof t.XmlText?p:void 0,slateParent:r,slateTarget:f,targetDelta:h}}function la(t,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<t.children.length;f+=1){var l=t.children[f],d=e.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[t.children.length,0];var p=t.children[s];return[s,e.isText(p)?p.text.length:1]}function da(n,r,o){for(var i=[o];i[0]!==n;){var a=i[0].parent;if(!a)throw new Error("yText isn't a descendant of root element");if(!(a instanceof t.XmlText))throw new Error("Unexpected y parent type");i.unshift(a)}if(i.length<2)return[];var u=r;return i.reduce((function(t,n,r){var o,a,c=i[r+1];if(!c)return t;var s=0,f=ia(n);try{for(var l=fi(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){o={error:t}}finally{try{d&&!d.done&&(a=l.return)&&a.call(l)}finally{if(o)throw o.error}}if(e.isText(u))throw new Error("Cannot descent into slate text");var p=li(la(u,s),1)[0];return u=u.children[p],t.concat(p)}),[])}function ha(t){if(!t.doc)throw new Error("shared type isn't attached to a document")}Ge({target:"Array",proto:!0,forced:ta},{includes:function(t){return Zi(this,t,arguments.length>1?arguments[1]:void 0)}}),er("includes");var pa="__slateYjsStoredPosition_";function va(e,n,r){var o=fa(e,n,r.path),i=o.yTarget,a=o.yParent,u=o.textRange;if(i)throw new Error("Slate point points to a non-text element inside sharedRoot");var c=u.start+r.offset;return t.createRelativePositionFromTypeIndex(a,c,c===u.end?-1:0)}function ga(r,o,i){if(!r.doc)throw new Error("sharedRoot isn't attach to a yDoc");var a=t.createAbsolutePositionFromRelativePosition(i,r.doc);return a&&function(r,o,i){var a=i.type,u=i.index,c=i.assoc;if(!(a instanceof t.XmlText))throw new Error("Absolute position points to a non-XMLText");var s=da(r,o,a),f=n.get(o,s);if(e.isText(f))throw new Error("Absolute position doesn't match slateRoot, cannot descent into text");var l=li(la(f,u,{assoc:c}),2),d=l[0],h=l[1],p=f.children[d];return e.isText(p)?{path:di(di([],li(s),!1),[d],!1),offset:h}:null}(r,o,a)}function ya(e,n,r){e.setAttribute(pa+n,t.encodeRelativePosition(r))}function ba(t,e,n){return Object.fromEntries(Object.entries(t).filter((function(t){var r=li(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 ma(e,n,r){var o;void 0===r&&(r="");var i=((o={})[r]=ba(e,n),o);return ia(n).forEach((function(n,o){var a=n.insert;a instanceof t.XmlText&&Object.assign(i,ma(e,a,r?"".concat(r,".").concat(o):o.toString()))})),i}function wa(e,n,r,o){void 0===o&&(o=0);var i=function(e){return ha(e),Object.fromEntries(Object.entries(e.getAttributes()).filter((function(t){return li(t,1)[0].startsWith(pa)})).map((function(n){var r=li(n,2),o=r[0],i=r[1];return[o.slice(pa.length),t.createAbsolutePositionFromRelativePosition(t.decodeRelativePosition(i),e.doc)]})).filter((function(t){return li(t,2)[1]})))}(e),a={"":ba(i,n,{start:o,end:o+ua(r)})};return r.forEach((function(e,n){var r=e.insert;r instanceof t.XmlText&&Object.assign(a,ma(i,r,n.toString()))})),a}function Oa(e,n,r,o,i,a,u){void 0===i&&(i=0),void 0===a&&(a=0),void 0===u&&(u="");var c=r[u];c&&Object.entries(c).forEach((function(r){var o=li(r,2),u=o[0],c=o[1];ya(e,u,t.createRelativePositionFromTypeIndex(n,c.index-a+i,c.assoc))})),o.forEach((function(n,o){var i=n.insert;i instanceof t.XmlText&&Oa(e,i,r,ia(i),0,0,u?"".concat(u,".").concat(o):o.toString())}))}function Sa(t,e,n){return{anchor:va(t,e,n.anchor),focus:va(t,e,n.focus)}}function xa(t,e,n){var r=ga(t,e,n.anchor);if(!r)return null;var o=ga(t,e,n.focus);return o?{anchor:r,focus:o}:null}var Ea={f:Ot},ja=l,Ta=Gt.f,Pa=hn.forEach,Ra=ne("hidden"),Aa="Symbol",ka="prototype",Ca=se.set,La=se.getterFor(Aa),Fa=Object[ka],_a=l.Symbol,Ma=_a&&_a[ka],Da=l.RangeError,Ia=l.TypeError,za=l.QObject,Na=Ct.f,Wa=Gt.f,Xa=Yr.f,Ga=w.f,Ba=j([].push),Ua=st("symbols"),Ya=st("op-symbols"),Va=st("wks"),$a=!za||!za[ka]||!za[ka].findChild,qa=function(t,e,n){var r=Na(Fa,e);r&&delete Fa[e],Wa(t,e,n),r&&t!==Fa&&Wa(Fa,e,r)},Ha=h&&d((function(){return 7!==qn(Wa({},"a",{get:function(){return Wa(this,"a",{value:7}).a}})).a}))?qa:Wa,Ja=function(t,e){var n=Ua[t]=qn(Ma);return Ca(n,{type:Aa,tag:t,description:e}),h||(n.description=e),n},Ka=function(t,e,n){t===Fa&&Ka(Ya,e,n),Mt(t);var r=jt(e);return Mt(n),ht(Ua,r)?(n.enumerable?(ht(t,Ra)&&t[Ra][r]&&(t[Ra][r]=!1),n=qn(n,{enumerable:O(0,!1)})):(ht(t,Ra)||Wa(t,Ra,O(1,qn(null))),t[Ra][r]=!0),Ha(t,r,n)):Wa(t,r,n)},Qa=function(t,e){Mt(t);var n=M(e),r=In(n).concat(nu(n));return Pa(r,(function(e){h&&!g(Za,n,e)||Ka(t,e,n[e])})),t},Za=function(t){var e=jt(t),n=g(Ga,this,e);return!(this===Fa&&ht(Ua,e)&&!ht(Ya,e))&&(!(n||!ht(this,e)||!ht(Ua,e)||ht(this,Ra)&&this[Ra][e])||n)},tu=function(t,e){var n=M(t),r=jt(e);if(n!==Fa||!ht(Ua,r)||ht(Ya,r)){var o=Na(n,r);return!o||!ht(Ua,r)||ht(n,Ra)&&n[Ra][r]||(o.enumerable=!0),o}},eu=function(t){var e=Xa(M(t)),n=[];return Pa(e,(function(t){ht(Ua,t)||ht(re,t)||Ba(n,t)})),n},nu=function(t){var e=t===Fa,n=Xa(e?Ya:M(t)),r=[];return Pa(n,(function(t){!ht(Ua,t)||e&&!ht(Fa,t)||Ba(r,Ua[t])})),r};J||(_a=function(){if(W(Ma,this))throw new Ia("Symbol is not a constructor");var t=arguments.length&&void 0!==arguments[0]?co(arguments[0]):void 0,e=yt(t),n=function(t){var r=void 0===this?l:this;r===Fa&&g(n,Ya,t),ht(r,Ra)&&ht(r[Ra],e)&&(r[Ra][e]=!1);var o=O(1,t);try{Ha(r,e,o)}catch(t){if(!(t instanceof Da))throw t;qa(r,e,o)}};return h&&$a&&Ha(Fa,e,{configurable:!0,set:n}),Ja(e,t)},Ma=_a[ka],le(Ma,"toString",(function(){return La(this).tag})),le(_a,"withoutSetter",(function(t){return Ja(yt(t),t)})),w.f=Za,Gt.f=Ka,Nn.f=Qa,Ct.f=tu,Ae.f=Yr.f=eu,ke.f=nu,Ea.f=function(t){return Ja(Ot(t),t)},h&&(to(Ma,"description",{configurable:!0,get:function(){return La(this).description}}),le(Fa,"propertyIsEnumerable",Za,{unsafe:!0}))),Ge({global:!0,constructor:!0,wrap:!0,forced:!J,sham:!J},{Symbol:_a}),Pa(In(Va),(function(t){!function(t){var e=ja.Symbol||(ja.Symbol={});ht(e,t)||Ta(e,t,{value:Ea.f(t)})}(t)})),Ge({target:Aa,stat:!0,forced:!J},{useSetter:function(){$a=!0},useSimple:function(){$a=!1}}),Ge({target:"Object",stat:!0,forced:!J,sham:!h},{create:function(t,e){return void 0===e?qn(t):Qa(qn(t),e)},defineProperty:Ka,defineProperties:Qa,getOwnPropertyDescriptor:tu}),Ge({target:"Object",stat:!0,forced:!J},{getOwnPropertyNames:eu}),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})}(),hr(_a,Aa),re[Ra]=!0;var ru=J&&!!Symbol.for&&!!Symbol.keyFor,ou=st("string-to-symbol-registry"),iu=st("symbol-to-string-registry");Ge({target:"Symbol",stat:!0,forced:!ru},{for:function(t){var e=co(t);if(ht(ou,e))return ou[e];var n=N("Symbol")(e);return ou[e]=n,iu[n]=e,n}});var au=st("symbol-to-string-registry");Ge({target:"Symbol",stat:!0,forced:!ru},{keyFor:function(t){if(!Z(t))throw new TypeError(et(t)+" is not a symbol");if(ht(au,t))return au[t]}});var uu=Function.prototype,cu=uu.apply,su=uu.call,fu="object"==typeof Reflect&&Reflect.apply||(p?su.bind(cu):function(){return su.apply(cu,arguments)}),lu=j([].push),du=String,hu=N("JSON","stringify"),pu=j(/./.exec),vu=j("".charAt),gu=j("".charCodeAt),yu=j("".replace),bu=j(1..toString),mu=/[\uD800-\uDFFF]/g,wu=/^[\uD800-\uDBFF]$/,Ou=/^[\uDC00-\uDFFF]$/,Su=!J||d((function(){var t=N("Symbol")("stringify detection");return"[null]"!==hu([t])||"{}"!==hu({a:t})||"{}"!==hu(Object(t))})),xu=d((function(){return'"\\udf06\\ud834"'!==hu("\udf06\ud834")||'"\\udead"'!==hu("\udead")})),Eu=function(t,e){var n=Gr(arguments),r=function(t){if(I(t))return t;if(Ve(t)){for(var e=t.length,n=[],r=0;r<e;r++){var o=t[r];"string"==typeof o?lu(n,o):"number"!=typeof o&&"Number"!==R(o)&&"String"!==R(o)||lu(n,co(o))}var i=n.length,a=!0;return function(t,e){if(a)return a=!1,e;if(Ve(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,du(t),e)),!Z(e))return e},fu(hu,null,n)},ju=function(t,e,n){var r=vu(n,e-1),o=vu(n,e+1);return pu(wu,t)&&!pu(Ou,o)||pu(Ou,t)&&!pu(wu,r)?"\\u"+bu(gu(t,0),16):t};hu&&Ge({target:"JSON",stat:!0,arity:3,forced:Su||xu},{stringify:function(t,e,n){var r=Gr(arguments),o=fu(Su?Eu:hu,null,r);return xu&&"string"==typeof o?yu(o,mu,ju):o}});var Tu=!J||d((function(){ke.f(1)}));Ge({target:"Object",stat:!0,forced:Tu},{getOwnPropertySymbols:function(t){var e=ke.f;return e?e(lt(t)):[]}});var Pu=l.Symbol,Ru=Pu&&Pu.prototype;if(h&&I(Pu)&&(!("description"in Ru)||void 0!==Pu().description)){var Au={},ku=function(){var t=arguments.length<1||void 0===arguments[0]?void 0:co(arguments[0]),e=W(Ru,this)?new Pu(t):void 0===t?Pu():Pu(t);return""===t&&(Au[e]=!0),e};Fe(ku,Pu),ku.prototype=Ru,Ru.constructor=ku;var Cu="Symbol(description detection)"===String(Pu("description detection")),Lu=j(Ru.valueOf),Fu=j(Ru.toString),_u=/^Symbol\((.*)\)[^)]+$/,Mu=j("".replace),Du=j("".slice);to(Ru,"description",{configurable:!0,get:function(){var t=Lu(this);if(ht(Au,t))return"";var e=Fu(t),n=Cu?Du(e,7,-1):Mu(e,_u,"$1");return""===n?void 0:n}}),Ge({global:!0,constructor:!0,forced:!0},{Symbol:ku})}Zr("WeakSet",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),Lo);var Iu=d((function(){In(1)}));function zu(t){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=li(t,1)[0];return!e.includes(n)})))}(t,e.isText(t)?"text":"children")}function Nu(t){var e=ia(t),n=e.length>0?e.map(Wu):[{text:""}];return ci(ci({},t.getAttributes()),{children:n})}function Wu(t){return"string"==typeof t.insert?ci(ci({},t.attributes),{text:t.insert}):Nu(t.insert)}function Xu(t){return t.map((function(t){return e.isText(t)?{insert:t.text,attributes:zu(t)}:{insert:Gu(t)}}))}function Gu(e){var n=e.children,r=si(e,["children"]),o=new t.XmlText;return Object.entries(r).forEach((function(t){var e=li(t,2),n=e[0],r=e[1];o.setAttribute(n,r)})),o.applyDelta(Xu(n),{sanitize:!1}),o}function Bu(o,i,a){var u=a.target,c=a.changes,s=a.delta;if(!(u instanceof t.XmlText))throw new Error("Unexpected target node type");var f=[],l=da(o,i,u),d=n.get(i,l);if(e.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=li(t,2),n=e[0];return[n,"delete"===e[1].action?null:u.getAttribute(n)]}))),v=Object.fromEntries(h.map((function(t){var e=li(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,di([],li(function(t,n,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=li(la(t,a-o.retain),2),f=s[0],l=s[1],d=li(la(t,a,{assoc:-1}),2),h=d[0],p=d[1],v=h;v>=f;v-=1){var g=t.children[v],y=di(di([],li(n),!1),[v],!1);if(e.isText(g)){var b=o.attributes,m=oa.apply(void 0,di([t],li(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:zu(g)}),0!==w){i.push({type:"split_node",path:y,position:w,properties:(c=ci(ci({},zu(g)),b),Object.fromEntries(Object.entries(c).filter((function(t){return null!==li(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=li(la(t,a-o.delete),2),S=(f=O[0],l=O[1],li(la(t,a,{assoc:-1}),2));for(h=S[0],v=0===(p=S[1])?h-1:h;v>=f;v-=1)if(g=t.children[v],y=di(di([],li(n),!1),[v],!1),!e.isText(g)||v!==f&&v!==h)i.push({type:"remove_node",node:g,path:y}),a-=sa(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=li(la(t,a,{insert:!0}),2),j=(v=E[0],E[1]);if(g=t.children[v],y=di(di([],li(n),!1),[v],!1),e.isText(g)){var T=i[i.length-1],P=null!=T&&"insert_node"===T.type?T.node:zu(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&&ra(null!==(u=o.attributes)&&void 0!==u?u:{},P)&&r.equals(y,R))return i.push({type:"insert_text",offset:j,text:o.insert,path:y});var A=Wu(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:zu(g)}),i.push({type:"insert_node",path:r.next(y),node:A}))}return i.push({type:"insert_node",path:y,node:Wu(o)})}})),i}(d,l,s)),!1)),f}function Uu(e,n,r){o.withoutNormalizing(n,(function(){r.forEach((function(r){(function(e,n,r){if(r instanceof t.YTextEvent)return Bu(e,n,r);throw new Error("Unexpected Y event type")})(e,n,r).forEach((function(t){n.apply(t)}))}))}))}function Yu(t){return t.map((function(t){return"string"==typeof t.insert?t:ci(ci({},t),{insert:Vu(t.insert)})}))}function Vu(e){var n=new t.XmlText,r=e.getAttributes();return Object.entries(r).forEach((function(t){var e=li(t,2),r=e[0],o=e[1];n.setAttribute(r,o)})),n.applyDelta(Yu(ia(e)),{sanitize:!1}),n}Ge({target:"Object",stat:!0,forced:Iu},{keys:function(t){return In(lt(t))}});var $u={insert_node:function(t,n,r){var o=fa(t,n,r.path),i=o.yParent,a=o.textRange;if(e.isText(r.node))return i.insert(a.start,r.node.text,zu(r.node));i.insertEmbed(a.start,Gu(r.node))},remove_node:function(t,e,n){var r=fa(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=fa(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=li(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=li(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=ci(ci({},u),n.newProperties);a.format(i.start,i.end-i.start,c)},merge_node:function(t,o,i){var a=fa(t,o,i.path),u=fa(a.yParent,a.slateParent,r.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=n.get(o,r.previous(i.path));if(!e.isText(l))throw new Error("Path points to Y.Text but not a Slate text node.");var d=zu(f),h=zu(l),p=Object.keys(d).reduce((function(t,e){var n;return e in h?t:ci(ci({},t),((n={})[e]=null,n))}),{});return c.format(s.start,s.end-s.start,ci(ci({},p),h))}var v=u.yTarget.length,g=ia(a.yTarget),y=Yu(g),b=wa(t,a.yTarget,g,v),m=di([{retain:v}],li(y),!1);u.yTarget.applyDelta(m,{sanitize:!1}),a.yParent.delete(a.textRange.start,a.textRange.end-a.textRange.start),Oa(t,u.yTarget,b,y,v)},move_node:function(t,o,i){var a=r.parent(i.newPath),u=i.newPath[i.newPath.length-1],c=n.get(o,a);if(e.isText(c))throw new Error("Cannot move slate node into text element");var s=di(di([],li(a),!1),[Math.min(u,c.children.length)],!1),f=fa(t,o,i.path),l=fa(t,o,s),d=Yu(f.targetDelta),h=wa(t,f.yParent,f.targetDelta);f.yParent.delete(f.textRange.start,f.textRange.end-f.textRange.start);var p=ua(ia(l.yParent)),v=Math.min(l.textRange.start,p),g=di([{retain:v}],li(d),!1);l.yParent.applyDelta(g,{sanitize:!1}),Oa(t,l.yParent,h,d,v,f.textRange.start)},split_node:function(n,r,o){var i=fa(n,r,o.path);if(!i.slateTarget)throw new Error("Y target without corresponding slate node");if(!i.yTarget){if(!e.isText(i.slateTarget))throw new Error("Mismatch node type between y target and slate node");var a={};return i.targetDelta.forEach((function(t){t.attributes&&Object.keys(t.attributes).forEach((function(t){a[t]=null}))})),i.yParent.format(i.textRange.start,i.textRange.end-i.textRange.start,ci(ci({},a),o.properties))}if(e.isText(i.slateTarget))throw new Error("Mismatch node type between y target and slate node");var u=fa(i.yTarget,i.slateTarget,[o.position]),c=i.slateTarget.children.slice(0,o.position).reduce((function(t,e){return t+sa(e)}),0),s=i.slateTarget.children.reduce((function(t,e){return t+sa(e)}),0),f=ca(ia(i.yTarget),c,s-c),l=Yu(f),d=wa(n,i.yTarget,f,c),h=new t.XmlText;h.applyDelta(l,{sanitize:!1}),Object.entries(o.properties).forEach((function(t){var e=li(t,2),n=e[0],r=e[1];h.setAttribute(n,r)})),i.yTarget.delete(u.textRange.start,i.yTarget.length-u.textRange.start),i.yParent.insertEmbed(i.textRange.end,h),Oa(n,h,d,l,0,c)}};var qu=ci(ci(ci({},{insert_text:function(t,r,o){var i=fa(t,r,o.path),a=i.yParent,u=i.textRange,c=n.get(r,o.path);if(!e.isText(c))throw new Error("Cannot insert text into non-text node");a.insert(u.start+o.offset,o.text,zu(c))},remove_text:function(t,e,n){var r=fa(t,e,n.path),o=r.yParent,i=r.textRange;o.delete(i.start+n.offset,n.text.length)}}),$u),{set_selection:function(){}});var Hu=Symbol("slate-yjs-operation"),Ju=Symbol("slate-yjs-position-storage"),Ku=new WeakMap,Qu=new WeakMap,Zu=new WeakSet,tc={isYjsEditor:function(e){return o.isEditor(e)&&e.sharedRoot instanceof t.XmlText&&"localOrigin"in e&&"positionStorageOrigin"in e&&"function"==typeof e.applyRemoteEvents&&"function"==typeof e.storeLocalChange&&"function"==typeof e.flushLocalChanges&&"function"==typeof e.isLocalOrigin&&"function"==typeof e.connect&&"function"==typeof e.disconnect},localChanges:function(t){var e;return null!==(e=Qu.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 Zu.has(t)},connect:function(t){t.connect()},disconnect:function(t){t.disconnect()},isLocal:function(t){return t.isLocalOrigin(tc.origin(t))},origin:function(t){var e=Ku.get(t);return void 0!==e?e:t.localOrigin},withOrigin:function(t,e,n){var r=tc.origin(t);Ku.set(t,e),n(),Ku.set(t,r)},storePosition:function(t,e,n){var r=t.sharedRoot,o=t.positionStorageOrigin;ha(r);var i=va(r,t,n);r.doc.transact((function(){ya(r,e,i)}),o)},removeStoredPosition:function(t,e){var n=t.sharedRoot,r=t.positionStorageOrigin;ha(n),n.doc.transact((function(){!function(t,e){t.removeAttribute(pa+e)}(n,e)}),r)},position:function(e,n){var r=function(e,n){var r=e.getAttribute(pa+n);return r?t.decodeRelativePosition(r):null}(e.sharedRoot,n);if(r)return ga(e.sharedRoot,e,r)},storedPositionsRelative:function(e){return n=e.sharedRoot,Object.fromEntries(Object.entries(n.getAttributes()).filter((function(t){return li(t,1)[0].startsWith(pa)})).map((function(e){var n=li(e,2),r=n[0],o=n[1];return[r.slice(pa.length),t.createRelativePositionFromJSON(o)]})));var n}};function ec(t,e){return void 0===e&&(e={}),function(n){var r,i,a=n;a.sharedRoot=t,a.localOrigin=null!==(r=e.localOrigin)&&void 0!==r?r:Hu,a.positionStorageOrigin=null!==(i=e.positionStorageOrigin)&&void 0!==i?i:Ju,a.applyRemoteEvents=function(t,e){tc.flushLocalChanges(a),o.withoutNormalizing(a,(function(){tc.withOrigin(a,e,(function(){Uu(a.sharedRoot,a,t)}))}))},a.isLocalOrigin=function(t){return t===a.localOrigin};var u=function(t,e){a.isLocalOrigin(e.origin)||tc.applyRemoteEvents(a,t,e.origin)},c=null;e.autoConnect&&(c=setTimeout((function(){c=null,tc.connect(a)}))),a.connect=function(){if(tc.connected(a))throw new Error("already connected");a.sharedRoot.observeDeep(u);var t=Nu(a.sharedRoot);a.children=t.children,Zu.add(a),o.normalize(n,{force:!0}),n.operations.length||n.onChange()},a.disconnect=function(){c&&clearTimeout(c),tc.flushLocalChanges(a),a.sharedRoot.unobserveDeep(u),Zu.delete(a)},a.storeLocalChange=function(t){Qu.set(a,di(di([],li(tc.localChanges(a)),!1),[{op:t,doc:n.children,origin:tc.origin(a)}],!1))},a.flushLocalChanges=function(){ha(a.sharedRoot);var t=tc.localChanges(a);Qu.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){ha(a.sharedRoot),a.sharedRoot.doc.transact((function(){t.forEach((function(t){ha(a.sharedRoot),function(t,e,n){var r=qu[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){tc.connected(a)&&tc.isLocal(a)&&tc.storeLocalChange(a,t),s(t)},a.onChange=function(){tc.connected(a)&&tc.flushLocalChanges(a),f()},a}}var nc=new WeakMap,rc={isCursorEditor:function(t){return tc.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=nc.get(t))&&void 0!==r?r:new Set;o.add(n),t&&nc.set(t,o)}},off:function(t,e,n){if("change"===e){var r=nc.get(t);r&&r.delete(n)}},cursorState:function(t,e){var n;if(e===t.awareness.clientID||!tc.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 tc.connected(t)?Object.fromEntries(Array.from(t.awareness.getStates().entries(),(function(e){var n=li(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 oc(e,n){return void 0===n&&(n={}),function(r){var o=n.cursorStateField,i=void 0===o?"selection":o,a=n.cursorDataField,u=void 0===a?"data":a,c=n.autoSend,s=void 0===c||c,f=n.data,l=r;l.awareness=e,l.cursorDataField=u,l.selectionStateField=i,l.sendCursorData=function(t){l.awareness.setLocalStateField(l.cursorDataField,t)},l.sendCursorPosition=function(e){var n=l.awareness.getLocalState(),r=null==n?void 0:n[i];if(e){var o=Sa(l.sharedRoot,l,e),a=o.anchor,u=o.focus;r&&t.compareRelativePositions(a,r)&&t.compareRelativePositions(u,r)||l.awareness.setLocalStateField(l.selectionStateField,{anchor:a,focus:u})}else r&&l.awareness.setLocalStateField(l.selectionStateField,null)};var d=function(t){var e=nc.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&&rc.sendCursorData(l,f);var t=l.onChange;l.onChange=function(){t(),tc.connected(l)&&rc.sendCursorPosition(l)}}},l.disconnect=function(){l.awareness.off("change",d),d({removed:Array.from(l.awareness.getStates().keys()),added:[],updated:[]}),p()},l}}var ic=new WeakMap,ac=Symbol("slate-yjs-history-without-saving"),uc={isYHistoryEditor:function(e){return tc.isYjsEditor(e)&&e.undoManager instanceof t.UndoManager&&"function"==typeof e.undo&&"function"==typeof e.redo&&"withoutSavingOrigin"in e},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(tc.origin(t))},withoutSaving:function(t,e){tc.withOrigin(t,t.withoutSavingOrigin,e)}};function cc(e){return void 0===e&&(e={}),function(n){var r=n,o=e.withoutSavingOrigin,a=void 0===o?ac:o,u=e.trackedOrigins,c=void 0===u?new Set([r.localOrigin]):u,s=si(e,["withoutSavingOrigin","trackedOrigins"]),f=new t.UndoManager(r.sharedRoot,ci({trackedOrigins:c},s));r.undoManager=f,r.withoutSavingOrigin=a;var l=r.onChange,d=r.isLocalOrigin;r.onChange=function(){l(),ic.set(r,r.selection&&Sa(r.sharedRoot,r,r.selection))},r.isLocalOrigin=function(t){return t===r.withoutSavingOrigin||d(t)};var h=function(t){var e=t.stackItem;e.meta.set("selection",r.selection&&Sa(r.sharedRoot,r,r.selection)),e.meta.set("selectionBefore",ic.get(r))},p=function(t){t.stackItem.meta.set("selection",r.selection&&Sa(r.sharedRoot,r,r.selection))},v=function(t){var e=t.stackItem,n="undo"===t.type?r.undoManager.redoStack:r.undoManager.undoStack,o=n[n.length-1];o&&(o.meta.set("selection",e.meta.get("selectionBefore")),o.meta.set("selectionBefore",e.meta.get("selection")));var a=e.meta.get("selectionBefore");if(a){var u=xa(r.sharedRoot,r,a);u&&i.select(r,u)}},g=r.connect,y=r.disconnect;return r.connect=function(){g(),r.undoManager.on("stack-item-added",h),r.undoManager.on("stack-item-popped",v),r.undoManager.on("stack-item-updated",p)},r.disconnect=function(){r.undoManager.off("stack-item-added",h),r.undoManager.off("stack-item-popped",v),r.undoManager.off("stack-item-updated",p),y()},r.undo=function(){tc.connected(r)&&(tc.flushLocalChanges(r),r.undoManager.undo())},r.redo=function(){tc.connected(r)&&(tc.flushLocalChanges(r),r.undoManager.redo())},r}}export{rc as CursorEditor,uc as YHistoryEditor,tc as YjsEditor,ga as relativePositionToSlatePoint,xa as relativeRangeToSlateRange,Xu as slateNodesToInsertDelta,va as slatePointToRelativePosition,Sa as slateRangeToRelativeRange,oc as withCursors,cc as withYHistory,ec as withYjs,Nu as yTextToSlateElement};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|