@scalar/use-codemirror 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +263 -3120
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -4,2920 +4,8 @@ var __publicField = (obj, key, value) => {
|
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
|
+
import * as Y from "yjs";
|
|
7
8
|
import { ref, watch, onBeforeUnmount, toValue, computed, defineComponent, toRef, openBlock, createElementBlock } from "vue";
|
|
8
|
-
const create$4 = () => /* @__PURE__ */ new Map();
|
|
9
|
-
const copy = (m) => {
|
|
10
|
-
const r2 = create$4();
|
|
11
|
-
m.forEach((v, k) => {
|
|
12
|
-
r2.set(k, v);
|
|
13
|
-
});
|
|
14
|
-
return r2;
|
|
15
|
-
};
|
|
16
|
-
const setIfUndefined = (map2, key, createT) => {
|
|
17
|
-
let set = map2.get(key);
|
|
18
|
-
if (set === void 0) {
|
|
19
|
-
map2.set(key, set = createT());
|
|
20
|
-
}
|
|
21
|
-
return set;
|
|
22
|
-
};
|
|
23
|
-
const map = (m, f) => {
|
|
24
|
-
const res = [];
|
|
25
|
-
for (const [key, value] of m) {
|
|
26
|
-
res.push(f(value, key));
|
|
27
|
-
}
|
|
28
|
-
return res;
|
|
29
|
-
};
|
|
30
|
-
const any = (m, f) => {
|
|
31
|
-
for (const [key, value] of m) {
|
|
32
|
-
if (f(value, key)) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
};
|
|
38
|
-
const create$3 = () => /* @__PURE__ */ new Set();
|
|
39
|
-
const appendTo = (dest, src) => {
|
|
40
|
-
for (let i = 0; i < src.length; i++) {
|
|
41
|
-
dest.push(src[i]);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const from$1 = Array.from;
|
|
45
|
-
const some = (arr, f) => {
|
|
46
|
-
for (let i = 0; i < arr.length; i++) {
|
|
47
|
-
if (f(arr[i], i, arr)) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
};
|
|
53
|
-
const isArray = Array.isArray;
|
|
54
|
-
class Observable {
|
|
55
|
-
constructor() {
|
|
56
|
-
this._observers = create$4();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @param {N} name
|
|
60
|
-
* @param {function} f
|
|
61
|
-
*/
|
|
62
|
-
on(name2, f) {
|
|
63
|
-
setIfUndefined(this._observers, name2, create$3).add(f);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @param {N} name
|
|
67
|
-
* @param {function} f
|
|
68
|
-
*/
|
|
69
|
-
once(name2, f) {
|
|
70
|
-
const _f2 = (...args) => {
|
|
71
|
-
this.off(name2, _f2);
|
|
72
|
-
f(...args);
|
|
73
|
-
};
|
|
74
|
-
this.on(name2, _f2);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @param {N} name
|
|
78
|
-
* @param {function} f
|
|
79
|
-
*/
|
|
80
|
-
off(name2, f) {
|
|
81
|
-
const observers2 = this._observers.get(name2);
|
|
82
|
-
if (observers2 !== void 0) {
|
|
83
|
-
observers2.delete(f);
|
|
84
|
-
if (observers2.size === 0) {
|
|
85
|
-
this._observers.delete(name2);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Emit a named event. All registered event listeners that listen to the
|
|
91
|
-
* specified name will receive the event.
|
|
92
|
-
*
|
|
93
|
-
* @todo This should catch exceptions
|
|
94
|
-
*
|
|
95
|
-
* @param {N} name The event name.
|
|
96
|
-
* @param {Array<any>} args The arguments that are applied to the event listener.
|
|
97
|
-
*/
|
|
98
|
-
emit(name2, args) {
|
|
99
|
-
return from$1((this._observers.get(name2) || create$4()).values()).forEach((f) => f(...args));
|
|
100
|
-
}
|
|
101
|
-
destroy() {
|
|
102
|
-
this._observers = create$4();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const floor = Math.floor;
|
|
106
|
-
const abs = Math.abs;
|
|
107
|
-
const min = (a, b) => a < b ? a : b;
|
|
108
|
-
const max = (a, b) => a > b ? a : b;
|
|
109
|
-
const isNegativeZero = (n) => n !== 0 ? n < 0 : 1 / n < 0;
|
|
110
|
-
const BIT1 = 1;
|
|
111
|
-
const BIT2 = 2;
|
|
112
|
-
const BIT3 = 4;
|
|
113
|
-
const BIT4 = 8;
|
|
114
|
-
const BIT6 = 32;
|
|
115
|
-
const BIT7 = 64;
|
|
116
|
-
const BIT8 = 128;
|
|
117
|
-
const BITS5 = 31;
|
|
118
|
-
const BITS6 = 63;
|
|
119
|
-
const BITS7 = 127;
|
|
120
|
-
const BITS31 = 2147483647;
|
|
121
|
-
const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor(num) === num);
|
|
122
|
-
const toLowerCase = (s) => s.toLowerCase();
|
|
123
|
-
const trimLeftRegex = /^\s*/g;
|
|
124
|
-
const trimLeft = (s) => s.replace(trimLeftRegex, "");
|
|
125
|
-
const fromCamelCaseRegex = /([A-Z])/g;
|
|
126
|
-
const fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, (match2) => `${separator}${toLowerCase(match2)}`));
|
|
127
|
-
const _encodeUtf8Polyfill = (str) => {
|
|
128
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
129
|
-
const len = encodedString.length;
|
|
130
|
-
const buf = new Uint8Array(len);
|
|
131
|
-
for (let i = 0; i < len; i++) {
|
|
132
|
-
buf[i] = /** @type {number} */
|
|
133
|
-
encodedString.codePointAt(i);
|
|
134
|
-
}
|
|
135
|
-
return buf;
|
|
136
|
-
};
|
|
137
|
-
const utf8TextEncoder = (
|
|
138
|
-
/** @type {TextEncoder} */
|
|
139
|
-
typeof TextEncoder !== "undefined" ? new TextEncoder() : null
|
|
140
|
-
);
|
|
141
|
-
const _encodeUtf8Native = (str) => utf8TextEncoder.encode(str);
|
|
142
|
-
const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill;
|
|
143
|
-
let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
144
|
-
if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {
|
|
145
|
-
utf8TextDecoder = null;
|
|
146
|
-
}
|
|
147
|
-
class Encoder {
|
|
148
|
-
constructor() {
|
|
149
|
-
this.cpos = 0;
|
|
150
|
-
this.cbuf = new Uint8Array(100);
|
|
151
|
-
this.bufs = [];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const createEncoder = () => new Encoder();
|
|
155
|
-
const length = (encoder) => {
|
|
156
|
-
let len = encoder.cpos;
|
|
157
|
-
for (let i = 0; i < encoder.bufs.length; i++) {
|
|
158
|
-
len += encoder.bufs[i].length;
|
|
159
|
-
}
|
|
160
|
-
return len;
|
|
161
|
-
};
|
|
162
|
-
const toUint8Array = (encoder) => {
|
|
163
|
-
const uint8arr = new Uint8Array(length(encoder));
|
|
164
|
-
let curPos = 0;
|
|
165
|
-
for (let i = 0; i < encoder.bufs.length; i++) {
|
|
166
|
-
const d = encoder.bufs[i];
|
|
167
|
-
uint8arr.set(d, curPos);
|
|
168
|
-
curPos += d.length;
|
|
169
|
-
}
|
|
170
|
-
uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
|
|
171
|
-
return uint8arr;
|
|
172
|
-
};
|
|
173
|
-
const verifyLen = (encoder, len) => {
|
|
174
|
-
const bufferLen = encoder.cbuf.length;
|
|
175
|
-
if (bufferLen - encoder.cpos < len) {
|
|
176
|
-
encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos));
|
|
177
|
-
encoder.cbuf = new Uint8Array(max(bufferLen, len) * 2);
|
|
178
|
-
encoder.cpos = 0;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
const write = (encoder, num) => {
|
|
182
|
-
const bufferLen = encoder.cbuf.length;
|
|
183
|
-
if (encoder.cpos === bufferLen) {
|
|
184
|
-
encoder.bufs.push(encoder.cbuf);
|
|
185
|
-
encoder.cbuf = new Uint8Array(bufferLen * 2);
|
|
186
|
-
encoder.cpos = 0;
|
|
187
|
-
}
|
|
188
|
-
encoder.cbuf[encoder.cpos++] = num;
|
|
189
|
-
};
|
|
190
|
-
const writeUint8 = write;
|
|
191
|
-
const writeVarUint = (encoder, num) => {
|
|
192
|
-
while (num > BITS7) {
|
|
193
|
-
write(encoder, BIT8 | BITS7 & num);
|
|
194
|
-
num = floor(num / 128);
|
|
195
|
-
}
|
|
196
|
-
write(encoder, BITS7 & num);
|
|
197
|
-
};
|
|
198
|
-
const writeVarInt = (encoder, num) => {
|
|
199
|
-
const isNegative = isNegativeZero(num);
|
|
200
|
-
if (isNegative) {
|
|
201
|
-
num = -num;
|
|
202
|
-
}
|
|
203
|
-
write(encoder, (num > BITS6 ? BIT8 : 0) | (isNegative ? BIT7 : 0) | BITS6 & num);
|
|
204
|
-
num = floor(num / 64);
|
|
205
|
-
while (num > 0) {
|
|
206
|
-
write(encoder, (num > BITS7 ? BIT8 : 0) | BITS7 & num);
|
|
207
|
-
num = floor(num / 128);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
const _strBuffer = new Uint8Array(3e4);
|
|
211
|
-
const _maxStrBSize = _strBuffer.length / 3;
|
|
212
|
-
const _writeVarStringNative = (encoder, str) => {
|
|
213
|
-
if (str.length < _maxStrBSize) {
|
|
214
|
-
const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
|
|
215
|
-
writeVarUint(encoder, written);
|
|
216
|
-
for (let i = 0; i < written; i++) {
|
|
217
|
-
write(encoder, _strBuffer[i]);
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
writeVarUint8Array(encoder, encodeUtf8(str));
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
const _writeVarStringPolyfill = (encoder, str) => {
|
|
224
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
225
|
-
const len = encodedString.length;
|
|
226
|
-
writeVarUint(encoder, len);
|
|
227
|
-
for (let i = 0; i < len; i++) {
|
|
228
|
-
write(
|
|
229
|
-
encoder,
|
|
230
|
-
/** @type {number} */
|
|
231
|
-
encodedString.codePointAt(i)
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
const writeVarString = utf8TextEncoder && /** @type {any} */
|
|
236
|
-
utf8TextEncoder.encodeInto ? _writeVarStringNative : _writeVarStringPolyfill;
|
|
237
|
-
const writeUint8Array = (encoder, uint8Array) => {
|
|
238
|
-
const bufferLen = encoder.cbuf.length;
|
|
239
|
-
const cpos = encoder.cpos;
|
|
240
|
-
const leftCopyLen = min(bufferLen - cpos, uint8Array.length);
|
|
241
|
-
const rightCopyLen = uint8Array.length - leftCopyLen;
|
|
242
|
-
encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos);
|
|
243
|
-
encoder.cpos += leftCopyLen;
|
|
244
|
-
if (rightCopyLen > 0) {
|
|
245
|
-
encoder.bufs.push(encoder.cbuf);
|
|
246
|
-
encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen));
|
|
247
|
-
encoder.cbuf.set(uint8Array.subarray(leftCopyLen));
|
|
248
|
-
encoder.cpos = rightCopyLen;
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
const writeVarUint8Array = (encoder, uint8Array) => {
|
|
252
|
-
writeVarUint(encoder, uint8Array.byteLength);
|
|
253
|
-
writeUint8Array(encoder, uint8Array);
|
|
254
|
-
};
|
|
255
|
-
const writeOnDataView = (encoder, len) => {
|
|
256
|
-
verifyLen(encoder, len);
|
|
257
|
-
const dview = new DataView(encoder.cbuf.buffer, encoder.cpos, len);
|
|
258
|
-
encoder.cpos += len;
|
|
259
|
-
return dview;
|
|
260
|
-
};
|
|
261
|
-
const writeFloat32 = (encoder, num) => writeOnDataView(encoder, 4).setFloat32(0, num, false);
|
|
262
|
-
const writeFloat64 = (encoder, num) => writeOnDataView(encoder, 8).setFloat64(0, num, false);
|
|
263
|
-
const writeBigInt64 = (encoder, num) => (
|
|
264
|
-
/** @type {any} */
|
|
265
|
-
writeOnDataView(encoder, 8).setBigInt64(0, num, false)
|
|
266
|
-
);
|
|
267
|
-
const floatTestBed = new DataView(new ArrayBuffer(4));
|
|
268
|
-
const isFloat32 = (num) => {
|
|
269
|
-
floatTestBed.setFloat32(0, num);
|
|
270
|
-
return floatTestBed.getFloat32(0) === num;
|
|
271
|
-
};
|
|
272
|
-
const writeAny = (encoder, data) => {
|
|
273
|
-
switch (typeof data) {
|
|
274
|
-
case "string":
|
|
275
|
-
write(encoder, 119);
|
|
276
|
-
writeVarString(encoder, data);
|
|
277
|
-
break;
|
|
278
|
-
case "number":
|
|
279
|
-
if (isInteger(data) && abs(data) <= BITS31) {
|
|
280
|
-
write(encoder, 125);
|
|
281
|
-
writeVarInt(encoder, data);
|
|
282
|
-
} else if (isFloat32(data)) {
|
|
283
|
-
write(encoder, 124);
|
|
284
|
-
writeFloat32(encoder, data);
|
|
285
|
-
} else {
|
|
286
|
-
write(encoder, 123);
|
|
287
|
-
writeFloat64(encoder, data);
|
|
288
|
-
}
|
|
289
|
-
break;
|
|
290
|
-
case "bigint":
|
|
291
|
-
write(encoder, 122);
|
|
292
|
-
writeBigInt64(encoder, data);
|
|
293
|
-
break;
|
|
294
|
-
case "object":
|
|
295
|
-
if (data === null) {
|
|
296
|
-
write(encoder, 126);
|
|
297
|
-
} else if (isArray(data)) {
|
|
298
|
-
write(encoder, 117);
|
|
299
|
-
writeVarUint(encoder, data.length);
|
|
300
|
-
for (let i = 0; i < data.length; i++) {
|
|
301
|
-
writeAny(encoder, data[i]);
|
|
302
|
-
}
|
|
303
|
-
} else if (data instanceof Uint8Array) {
|
|
304
|
-
write(encoder, 116);
|
|
305
|
-
writeVarUint8Array(encoder, data);
|
|
306
|
-
} else {
|
|
307
|
-
write(encoder, 118);
|
|
308
|
-
const keys = Object.keys(data);
|
|
309
|
-
writeVarUint(encoder, keys.length);
|
|
310
|
-
for (let i = 0; i < keys.length; i++) {
|
|
311
|
-
const key = keys[i];
|
|
312
|
-
writeVarString(encoder, key);
|
|
313
|
-
writeAny(encoder, data[key]);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
break;
|
|
317
|
-
case "boolean":
|
|
318
|
-
write(encoder, data ? 120 : 121);
|
|
319
|
-
break;
|
|
320
|
-
default:
|
|
321
|
-
write(encoder, 127);
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
class RleEncoder extends Encoder {
|
|
325
|
-
/**
|
|
326
|
-
* @param {function(Encoder, T):void} writer
|
|
327
|
-
*/
|
|
328
|
-
constructor(writer) {
|
|
329
|
-
super();
|
|
330
|
-
this.w = writer;
|
|
331
|
-
this.s = null;
|
|
332
|
-
this.count = 0;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* @param {T} v
|
|
336
|
-
*/
|
|
337
|
-
write(v) {
|
|
338
|
-
if (this.s === v) {
|
|
339
|
-
this.count++;
|
|
340
|
-
} else {
|
|
341
|
-
if (this.count > 0) {
|
|
342
|
-
writeVarUint(this, this.count - 1);
|
|
343
|
-
}
|
|
344
|
-
this.count = 1;
|
|
345
|
-
this.w(this, v);
|
|
346
|
-
this.s = v;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
const flushUintOptRleEncoder = (encoder) => {
|
|
351
|
-
if (encoder.count > 0) {
|
|
352
|
-
writeVarInt(encoder.encoder, encoder.count === 1 ? encoder.s : -encoder.s);
|
|
353
|
-
if (encoder.count > 1) {
|
|
354
|
-
writeVarUint(encoder.encoder, encoder.count - 2);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
class UintOptRleEncoder {
|
|
359
|
-
constructor() {
|
|
360
|
-
this.encoder = new Encoder();
|
|
361
|
-
this.s = 0;
|
|
362
|
-
this.count = 0;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* @param {number} v
|
|
366
|
-
*/
|
|
367
|
-
write(v) {
|
|
368
|
-
if (this.s === v) {
|
|
369
|
-
this.count++;
|
|
370
|
-
} else {
|
|
371
|
-
flushUintOptRleEncoder(this);
|
|
372
|
-
this.count = 1;
|
|
373
|
-
this.s = v;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Flush the encoded state and transform this to a Uint8Array.
|
|
378
|
-
*
|
|
379
|
-
* Note that this should only be called once.
|
|
380
|
-
*/
|
|
381
|
-
toUint8Array() {
|
|
382
|
-
flushUintOptRleEncoder(this);
|
|
383
|
-
return toUint8Array(this.encoder);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
const flushIntDiffOptRleEncoder = (encoder) => {
|
|
387
|
-
if (encoder.count > 0) {
|
|
388
|
-
const encodedDiff = encoder.diff * 2 + (encoder.count === 1 ? 0 : 1);
|
|
389
|
-
writeVarInt(encoder.encoder, encodedDiff);
|
|
390
|
-
if (encoder.count > 1) {
|
|
391
|
-
writeVarUint(encoder.encoder, encoder.count - 2);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
class IntDiffOptRleEncoder {
|
|
396
|
-
constructor() {
|
|
397
|
-
this.encoder = new Encoder();
|
|
398
|
-
this.s = 0;
|
|
399
|
-
this.count = 0;
|
|
400
|
-
this.diff = 0;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* @param {number} v
|
|
404
|
-
*/
|
|
405
|
-
write(v) {
|
|
406
|
-
if (this.diff === v - this.s) {
|
|
407
|
-
this.s = v;
|
|
408
|
-
this.count++;
|
|
409
|
-
} else {
|
|
410
|
-
flushIntDiffOptRleEncoder(this);
|
|
411
|
-
this.count = 1;
|
|
412
|
-
this.diff = v - this.s;
|
|
413
|
-
this.s = v;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Flush the encoded state and transform this to a Uint8Array.
|
|
418
|
-
*
|
|
419
|
-
* Note that this should only be called once.
|
|
420
|
-
*/
|
|
421
|
-
toUint8Array() {
|
|
422
|
-
flushIntDiffOptRleEncoder(this);
|
|
423
|
-
return toUint8Array(this.encoder);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
class StringEncoder {
|
|
427
|
-
constructor() {
|
|
428
|
-
this.sarr = [];
|
|
429
|
-
this.s = "";
|
|
430
|
-
this.lensE = new UintOptRleEncoder();
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* @param {string} string
|
|
434
|
-
*/
|
|
435
|
-
write(string2) {
|
|
436
|
-
this.s += string2;
|
|
437
|
-
if (this.s.length > 19) {
|
|
438
|
-
this.sarr.push(this.s);
|
|
439
|
-
this.s = "";
|
|
440
|
-
}
|
|
441
|
-
this.lensE.write(string2.length);
|
|
442
|
-
}
|
|
443
|
-
toUint8Array() {
|
|
444
|
-
const encoder = new Encoder();
|
|
445
|
-
this.sarr.push(this.s);
|
|
446
|
-
this.s = "";
|
|
447
|
-
writeVarString(encoder, this.sarr.join(""));
|
|
448
|
-
writeUint8Array(encoder, this.lensE.toUint8Array());
|
|
449
|
-
return toUint8Array(encoder);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
const create$2 = (s) => new Error(s);
|
|
453
|
-
const methodUnimplemented = () => {
|
|
454
|
-
throw create$2("Method unimplemented");
|
|
455
|
-
};
|
|
456
|
-
const unexpectedCase = () => {
|
|
457
|
-
throw create$2("Unexpected case");
|
|
458
|
-
};
|
|
459
|
-
const getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
460
|
-
const uint32 = () => getRandomValues(new Uint32Array(1))[0];
|
|
461
|
-
const getUnixTime = Date.now;
|
|
462
|
-
const undefinedToNull = (v) => v === void 0 ? null : v;
|
|
463
|
-
class VarStoragePolyfill {
|
|
464
|
-
constructor() {
|
|
465
|
-
this.map = /* @__PURE__ */ new Map();
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* @param {string} key
|
|
469
|
-
* @param {any} newValue
|
|
470
|
-
*/
|
|
471
|
-
setItem(key, newValue) {
|
|
472
|
-
this.map.set(key, newValue);
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* @param {string} key
|
|
476
|
-
*/
|
|
477
|
-
getItem(key) {
|
|
478
|
-
return this.map.get(key);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
let _localStorage = new VarStoragePolyfill();
|
|
482
|
-
let usePolyfill = true;
|
|
483
|
-
try {
|
|
484
|
-
if (typeof localStorage !== "undefined" && localStorage) {
|
|
485
|
-
_localStorage = localStorage;
|
|
486
|
-
usePolyfill = false;
|
|
487
|
-
}
|
|
488
|
-
} catch (e) {
|
|
489
|
-
}
|
|
490
|
-
const varStorage = _localStorage;
|
|
491
|
-
const callAll = (fs, args, i = 0) => {
|
|
492
|
-
try {
|
|
493
|
-
for (; i < fs.length; i++) {
|
|
494
|
-
fs[i](...args);
|
|
495
|
-
}
|
|
496
|
-
} finally {
|
|
497
|
-
if (i < fs.length) {
|
|
498
|
-
callAll(fs, args, i + 1);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
const isOneOf = (value, options) => options.includes(value);
|
|
503
|
-
const isNode = typeof process !== "undefined" && process.release && /node|io\.js/.test(process.release.name) && Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
504
|
-
let params;
|
|
505
|
-
const computeParams = () => {
|
|
506
|
-
if (params === void 0) {
|
|
507
|
-
if (isNode) {
|
|
508
|
-
params = create$4();
|
|
509
|
-
const pargs = process.argv;
|
|
510
|
-
let currParamName = null;
|
|
511
|
-
for (let i = 0; i < pargs.length; i++) {
|
|
512
|
-
const parg = pargs[i];
|
|
513
|
-
if (parg[0] === "-") {
|
|
514
|
-
if (currParamName !== null) {
|
|
515
|
-
params.set(currParamName, "");
|
|
516
|
-
}
|
|
517
|
-
currParamName = parg;
|
|
518
|
-
} else {
|
|
519
|
-
if (currParamName !== null) {
|
|
520
|
-
params.set(currParamName, parg);
|
|
521
|
-
currParamName = null;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (currParamName !== null) {
|
|
526
|
-
params.set(currParamName, "");
|
|
527
|
-
}
|
|
528
|
-
} else if (typeof location === "object") {
|
|
529
|
-
params = create$4();
|
|
530
|
-
(location.search || "?").slice(1).split("&").forEach((kv) => {
|
|
531
|
-
if (kv.length !== 0) {
|
|
532
|
-
const [key, value] = kv.split("=");
|
|
533
|
-
params.set(`--${fromCamelCase(key, "-")}`, value);
|
|
534
|
-
params.set(`-${fromCamelCase(key, "-")}`, value);
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
} else {
|
|
538
|
-
params = create$4();
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
return params;
|
|
542
|
-
};
|
|
543
|
-
const hasParam = (name2) => computeParams().has(name2);
|
|
544
|
-
const getVariable = (name2) => isNode ? undefinedToNull(process.env[name2.toUpperCase()]) : undefinedToNull(varStorage.getItem(name2));
|
|
545
|
-
const hasConf = (name2) => hasParam("--" + name2) || getVariable(name2) !== null;
|
|
546
|
-
hasConf("production");
|
|
547
|
-
const forceColor = isNode && isOneOf(process.env.FORCE_COLOR, ["true", "1", "2"]);
|
|
548
|
-
const supportsColor = !hasParam("no-colors") && (!isNode || process.stdout.isTTY || forceColor) && (!isNode || hasParam("color") || forceColor || getVariable("COLORTERM") !== null || (getVariable("TERM") || "").includes("color"));
|
|
549
|
-
class Pair {
|
|
550
|
-
/**
|
|
551
|
-
* @param {L} left
|
|
552
|
-
* @param {R} right
|
|
553
|
-
*/
|
|
554
|
-
constructor(left, right) {
|
|
555
|
-
this.left = left;
|
|
556
|
-
this.right = right;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
const create$1 = (left, right) => new Pair(left, right);
|
|
560
|
-
const forEach = (arr, f) => arr.forEach((p) => f(p.left, p.right));
|
|
561
|
-
const doc$1 = (
|
|
562
|
-
/** @type {Document} */
|
|
563
|
-
typeof document !== "undefined" ? document : {}
|
|
564
|
-
);
|
|
565
|
-
const createElement = (name2) => doc$1.createElement(name2);
|
|
566
|
-
const createDocumentFragment = () => doc$1.createDocumentFragment();
|
|
567
|
-
const createTextNode = (text2) => doc$1.createTextNode(text2);
|
|
568
|
-
typeof DOMParser !== "undefined" ? new DOMParser() : null;
|
|
569
|
-
const setAttributes = (el, attrs) => {
|
|
570
|
-
forEach(attrs, (key, value) => {
|
|
571
|
-
if (value === false) {
|
|
572
|
-
el.removeAttribute(key);
|
|
573
|
-
} else if (value === true) {
|
|
574
|
-
el.setAttribute(key, "");
|
|
575
|
-
} else {
|
|
576
|
-
el.setAttribute(key, value);
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
return el;
|
|
580
|
-
};
|
|
581
|
-
const fragment = (children) => {
|
|
582
|
-
const fragment2 = createDocumentFragment();
|
|
583
|
-
for (let i = 0; i < children.length; i++) {
|
|
584
|
-
appendChild(fragment2, children[i]);
|
|
585
|
-
}
|
|
586
|
-
return fragment2;
|
|
587
|
-
};
|
|
588
|
-
const append = (parent, nodes) => {
|
|
589
|
-
appendChild(parent, fragment(nodes));
|
|
590
|
-
return parent;
|
|
591
|
-
};
|
|
592
|
-
const element = (name2, attrs = [], children = []) => append(setAttributes(createElement(name2), attrs), children);
|
|
593
|
-
const text = createTextNode;
|
|
594
|
-
const mapToStyleString = (m) => map(m, (value, key) => `${key}:${value};`).join("");
|
|
595
|
-
const appendChild = (parent, child) => parent.appendChild(child);
|
|
596
|
-
doc$1.ELEMENT_NODE;
|
|
597
|
-
doc$1.TEXT_NODE;
|
|
598
|
-
doc$1.CDATA_SECTION_NODE;
|
|
599
|
-
doc$1.COMMENT_NODE;
|
|
600
|
-
doc$1.DOCUMENT_NODE;
|
|
601
|
-
doc$1.DOCUMENT_TYPE_NODE;
|
|
602
|
-
doc$1.DOCUMENT_FRAGMENT_NODE;
|
|
603
|
-
const create = Symbol;
|
|
604
|
-
const BOLD = create();
|
|
605
|
-
const UNBOLD = create();
|
|
606
|
-
const BLUE = create();
|
|
607
|
-
const GREY = create();
|
|
608
|
-
const GREEN = create();
|
|
609
|
-
const RED = create();
|
|
610
|
-
const PURPLE = create();
|
|
611
|
-
const ORANGE = create();
|
|
612
|
-
const UNCOLOR = create();
|
|
613
|
-
const computeNoColorLoggingArgs = (args) => {
|
|
614
|
-
const logArgs = [];
|
|
615
|
-
let i = 0;
|
|
616
|
-
for (; i < args.length; i++) {
|
|
617
|
-
const arg = args[i];
|
|
618
|
-
if (arg.constructor === String || arg.constructor === Number)
|
|
619
|
-
;
|
|
620
|
-
else if (arg.constructor === Object) {
|
|
621
|
-
logArgs.push(JSON.stringify(arg));
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
return logArgs;
|
|
625
|
-
};
|
|
626
|
-
const _browserStyleMap = {
|
|
627
|
-
[BOLD]: create$1("font-weight", "bold"),
|
|
628
|
-
[UNBOLD]: create$1("font-weight", "normal"),
|
|
629
|
-
[BLUE]: create$1("color", "blue"),
|
|
630
|
-
[GREEN]: create$1("color", "green"),
|
|
631
|
-
[GREY]: create$1("color", "grey"),
|
|
632
|
-
[RED]: create$1("color", "red"),
|
|
633
|
-
[PURPLE]: create$1("color", "purple"),
|
|
634
|
-
[ORANGE]: create$1("color", "orange"),
|
|
635
|
-
// not well supported in chrome when debugging node with inspector - TODO: deprecate
|
|
636
|
-
[UNCOLOR]: create$1("color", "black")
|
|
637
|
-
};
|
|
638
|
-
const computeBrowserLoggingArgs = (args) => {
|
|
639
|
-
const strBuilder = [];
|
|
640
|
-
const styles = [];
|
|
641
|
-
const currentStyle = create$4();
|
|
642
|
-
let logArgs = [];
|
|
643
|
-
let i = 0;
|
|
644
|
-
for (; i < args.length; i++) {
|
|
645
|
-
const arg = args[i];
|
|
646
|
-
const style = _browserStyleMap[arg];
|
|
647
|
-
if (style !== void 0) {
|
|
648
|
-
currentStyle.set(style.left, style.right);
|
|
649
|
-
} else {
|
|
650
|
-
if (arg.constructor === String || arg.constructor === Number) {
|
|
651
|
-
const style2 = mapToStyleString(currentStyle);
|
|
652
|
-
if (i > 0 || style2.length > 0) {
|
|
653
|
-
strBuilder.push("%c" + arg);
|
|
654
|
-
styles.push(style2);
|
|
655
|
-
} else {
|
|
656
|
-
strBuilder.push(arg);
|
|
657
|
-
}
|
|
658
|
-
} else {
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
if (i > 0) {
|
|
664
|
-
logArgs = styles;
|
|
665
|
-
logArgs.unshift(strBuilder.join(""));
|
|
666
|
-
}
|
|
667
|
-
for (; i < args.length; i++) {
|
|
668
|
-
const arg = args[i];
|
|
669
|
-
if (!(arg instanceof Symbol)) {
|
|
670
|
-
logArgs.push(arg);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
return logArgs;
|
|
674
|
-
};
|
|
675
|
-
const computeLoggingArgs = supportsColor ? computeBrowserLoggingArgs : computeNoColorLoggingArgs;
|
|
676
|
-
const print$1 = (...args) => {
|
|
677
|
-
console.log(...computeLoggingArgs(args));
|
|
678
|
-
vconsoles.forEach((vc) => vc.print(args));
|
|
679
|
-
};
|
|
680
|
-
const warn = (...args) => {
|
|
681
|
-
console.warn(...computeLoggingArgs(args));
|
|
682
|
-
args.unshift(ORANGE);
|
|
683
|
-
vconsoles.forEach((vc) => vc.print(args));
|
|
684
|
-
};
|
|
685
|
-
const vconsoles = create$3();
|
|
686
|
-
class DeleteItem {
|
|
687
|
-
/**
|
|
688
|
-
* @param {number} clock
|
|
689
|
-
* @param {number} len
|
|
690
|
-
*/
|
|
691
|
-
constructor(clock, len) {
|
|
692
|
-
this.clock = clock;
|
|
693
|
-
this.len = len;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
class DeleteSet {
|
|
697
|
-
constructor() {
|
|
698
|
-
this.clients = /* @__PURE__ */ new Map();
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
const iterateDeletedStructs = (transaction, ds, f) => ds.clients.forEach((deletes, clientid) => {
|
|
702
|
-
const structs = (
|
|
703
|
-
/** @type {Array<GC|Item>} */
|
|
704
|
-
transaction.doc.store.clients.get(clientid)
|
|
705
|
-
);
|
|
706
|
-
for (let i = 0; i < deletes.length; i++) {
|
|
707
|
-
const del = deletes[i];
|
|
708
|
-
iterateStructs(transaction, structs, del.clock, del.len, f);
|
|
709
|
-
}
|
|
710
|
-
});
|
|
711
|
-
const findIndexDS = (dis, clock) => {
|
|
712
|
-
let left = 0;
|
|
713
|
-
let right = dis.length - 1;
|
|
714
|
-
while (left <= right) {
|
|
715
|
-
const midindex = floor((left + right) / 2);
|
|
716
|
-
const mid = dis[midindex];
|
|
717
|
-
const midclock = mid.clock;
|
|
718
|
-
if (midclock <= clock) {
|
|
719
|
-
if (clock < midclock + mid.len) {
|
|
720
|
-
return midindex;
|
|
721
|
-
}
|
|
722
|
-
left = midindex + 1;
|
|
723
|
-
} else {
|
|
724
|
-
right = midindex - 1;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
return null;
|
|
728
|
-
};
|
|
729
|
-
const isDeleted = (ds, id2) => {
|
|
730
|
-
const dis = ds.clients.get(id2.client);
|
|
731
|
-
return dis !== void 0 && findIndexDS(dis, id2.clock) !== null;
|
|
732
|
-
};
|
|
733
|
-
const sortAndMergeDeleteSet = (ds) => {
|
|
734
|
-
ds.clients.forEach((dels) => {
|
|
735
|
-
dels.sort((a, b) => a.clock - b.clock);
|
|
736
|
-
let i, j;
|
|
737
|
-
for (i = 1, j = 1; i < dels.length; i++) {
|
|
738
|
-
const left = dels[j - 1];
|
|
739
|
-
const right = dels[i];
|
|
740
|
-
if (left.clock + left.len >= right.clock) {
|
|
741
|
-
left.len = max(left.len, right.clock + right.len - left.clock);
|
|
742
|
-
} else {
|
|
743
|
-
if (j < i) {
|
|
744
|
-
dels[j] = right;
|
|
745
|
-
}
|
|
746
|
-
j++;
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
dels.length = j;
|
|
750
|
-
});
|
|
751
|
-
};
|
|
752
|
-
const mergeDeleteSets = (dss) => {
|
|
753
|
-
const merged = new DeleteSet();
|
|
754
|
-
for (let dssI = 0; dssI < dss.length; dssI++) {
|
|
755
|
-
dss[dssI].clients.forEach((delsLeft, client) => {
|
|
756
|
-
if (!merged.clients.has(client)) {
|
|
757
|
-
const dels = delsLeft.slice();
|
|
758
|
-
for (let i = dssI + 1; i < dss.length; i++) {
|
|
759
|
-
appendTo(dels, dss[i].clients.get(client) || []);
|
|
760
|
-
}
|
|
761
|
-
merged.clients.set(client, dels);
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
sortAndMergeDeleteSet(merged);
|
|
766
|
-
return merged;
|
|
767
|
-
};
|
|
768
|
-
const addToDeleteSet = (ds, client, clock, length2) => {
|
|
769
|
-
setIfUndefined(ds.clients, client, () => (
|
|
770
|
-
/** @type {Array<DeleteItem>} */
|
|
771
|
-
[]
|
|
772
|
-
)).push(new DeleteItem(clock, length2));
|
|
773
|
-
};
|
|
774
|
-
const writeDeleteSet = (encoder, ds) => {
|
|
775
|
-
writeVarUint(encoder.restEncoder, ds.clients.size);
|
|
776
|
-
from$1(ds.clients.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, dsitems]) => {
|
|
777
|
-
encoder.resetDsCurVal();
|
|
778
|
-
writeVarUint(encoder.restEncoder, client);
|
|
779
|
-
const len = dsitems.length;
|
|
780
|
-
writeVarUint(encoder.restEncoder, len);
|
|
781
|
-
for (let i = 0; i < len; i++) {
|
|
782
|
-
const item = dsitems[i];
|
|
783
|
-
encoder.writeDsClock(item.clock);
|
|
784
|
-
encoder.writeDsLen(item.len);
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
};
|
|
788
|
-
const generateNewClientId = uint32;
|
|
789
|
-
class DSEncoderV1 {
|
|
790
|
-
constructor() {
|
|
791
|
-
this.restEncoder = createEncoder();
|
|
792
|
-
}
|
|
793
|
-
toUint8Array() {
|
|
794
|
-
return toUint8Array(this.restEncoder);
|
|
795
|
-
}
|
|
796
|
-
resetDsCurVal() {
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* @param {number} clock
|
|
800
|
-
*/
|
|
801
|
-
writeDsClock(clock) {
|
|
802
|
-
writeVarUint(this.restEncoder, clock);
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* @param {number} len
|
|
806
|
-
*/
|
|
807
|
-
writeDsLen(len) {
|
|
808
|
-
writeVarUint(this.restEncoder, len);
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
class UpdateEncoderV1 extends DSEncoderV1 {
|
|
812
|
-
/**
|
|
813
|
-
* @param {ID} id
|
|
814
|
-
*/
|
|
815
|
-
writeLeftID(id2) {
|
|
816
|
-
writeVarUint(this.restEncoder, id2.client);
|
|
817
|
-
writeVarUint(this.restEncoder, id2.clock);
|
|
818
|
-
}
|
|
819
|
-
/**
|
|
820
|
-
* @param {ID} id
|
|
821
|
-
*/
|
|
822
|
-
writeRightID(id2) {
|
|
823
|
-
writeVarUint(this.restEncoder, id2.client);
|
|
824
|
-
writeVarUint(this.restEncoder, id2.clock);
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Use writeClient and writeClock instead of writeID if possible.
|
|
828
|
-
* @param {number} client
|
|
829
|
-
*/
|
|
830
|
-
writeClient(client) {
|
|
831
|
-
writeVarUint(this.restEncoder, client);
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* @param {number} info An unsigned 8-bit integer
|
|
835
|
-
*/
|
|
836
|
-
writeInfo(info) {
|
|
837
|
-
writeUint8(this.restEncoder, info);
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* @param {string} s
|
|
841
|
-
*/
|
|
842
|
-
writeString(s) {
|
|
843
|
-
writeVarString(this.restEncoder, s);
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* @param {boolean} isYKey
|
|
847
|
-
*/
|
|
848
|
-
writeParentInfo(isYKey) {
|
|
849
|
-
writeVarUint(this.restEncoder, isYKey ? 1 : 0);
|
|
850
|
-
}
|
|
851
|
-
/**
|
|
852
|
-
* @param {number} info An unsigned 8-bit integer
|
|
853
|
-
*/
|
|
854
|
-
writeTypeRef(info) {
|
|
855
|
-
writeVarUint(this.restEncoder, info);
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Write len of a struct - well suited for Opt RLE encoder.
|
|
859
|
-
*
|
|
860
|
-
* @param {number} len
|
|
861
|
-
*/
|
|
862
|
-
writeLen(len) {
|
|
863
|
-
writeVarUint(this.restEncoder, len);
|
|
864
|
-
}
|
|
865
|
-
/**
|
|
866
|
-
* @param {any} any
|
|
867
|
-
*/
|
|
868
|
-
writeAny(any2) {
|
|
869
|
-
writeAny(this.restEncoder, any2);
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* @param {Uint8Array} buf
|
|
873
|
-
*/
|
|
874
|
-
writeBuf(buf) {
|
|
875
|
-
writeVarUint8Array(this.restEncoder, buf);
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* @param {any} embed
|
|
879
|
-
*/
|
|
880
|
-
writeJSON(embed) {
|
|
881
|
-
writeVarString(this.restEncoder, JSON.stringify(embed));
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* @param {string} key
|
|
885
|
-
*/
|
|
886
|
-
writeKey(key) {
|
|
887
|
-
writeVarString(this.restEncoder, key);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
class DSEncoderV2 {
|
|
891
|
-
constructor() {
|
|
892
|
-
this.restEncoder = createEncoder();
|
|
893
|
-
this.dsCurrVal = 0;
|
|
894
|
-
}
|
|
895
|
-
toUint8Array() {
|
|
896
|
-
return toUint8Array(this.restEncoder);
|
|
897
|
-
}
|
|
898
|
-
resetDsCurVal() {
|
|
899
|
-
this.dsCurrVal = 0;
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* @param {number} clock
|
|
903
|
-
*/
|
|
904
|
-
writeDsClock(clock) {
|
|
905
|
-
const diff = clock - this.dsCurrVal;
|
|
906
|
-
this.dsCurrVal = clock;
|
|
907
|
-
writeVarUint(this.restEncoder, diff);
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* @param {number} len
|
|
911
|
-
*/
|
|
912
|
-
writeDsLen(len) {
|
|
913
|
-
if (len === 0) {
|
|
914
|
-
unexpectedCase();
|
|
915
|
-
}
|
|
916
|
-
writeVarUint(this.restEncoder, len - 1);
|
|
917
|
-
this.dsCurrVal += len;
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
class UpdateEncoderV2 extends DSEncoderV2 {
|
|
921
|
-
constructor() {
|
|
922
|
-
super();
|
|
923
|
-
this.keyMap = /* @__PURE__ */ new Map();
|
|
924
|
-
this.keyClock = 0;
|
|
925
|
-
this.keyClockEncoder = new IntDiffOptRleEncoder();
|
|
926
|
-
this.clientEncoder = new UintOptRleEncoder();
|
|
927
|
-
this.leftClockEncoder = new IntDiffOptRleEncoder();
|
|
928
|
-
this.rightClockEncoder = new IntDiffOptRleEncoder();
|
|
929
|
-
this.infoEncoder = new RleEncoder(writeUint8);
|
|
930
|
-
this.stringEncoder = new StringEncoder();
|
|
931
|
-
this.parentInfoEncoder = new RleEncoder(writeUint8);
|
|
932
|
-
this.typeRefEncoder = new UintOptRleEncoder();
|
|
933
|
-
this.lenEncoder = new UintOptRleEncoder();
|
|
934
|
-
}
|
|
935
|
-
toUint8Array() {
|
|
936
|
-
const encoder = createEncoder();
|
|
937
|
-
writeVarUint(encoder, 0);
|
|
938
|
-
writeVarUint8Array(encoder, this.keyClockEncoder.toUint8Array());
|
|
939
|
-
writeVarUint8Array(encoder, this.clientEncoder.toUint8Array());
|
|
940
|
-
writeVarUint8Array(encoder, this.leftClockEncoder.toUint8Array());
|
|
941
|
-
writeVarUint8Array(encoder, this.rightClockEncoder.toUint8Array());
|
|
942
|
-
writeVarUint8Array(encoder, toUint8Array(this.infoEncoder));
|
|
943
|
-
writeVarUint8Array(encoder, this.stringEncoder.toUint8Array());
|
|
944
|
-
writeVarUint8Array(encoder, toUint8Array(this.parentInfoEncoder));
|
|
945
|
-
writeVarUint8Array(encoder, this.typeRefEncoder.toUint8Array());
|
|
946
|
-
writeVarUint8Array(encoder, this.lenEncoder.toUint8Array());
|
|
947
|
-
writeUint8Array(encoder, toUint8Array(this.restEncoder));
|
|
948
|
-
return toUint8Array(encoder);
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* @param {ID} id
|
|
952
|
-
*/
|
|
953
|
-
writeLeftID(id2) {
|
|
954
|
-
this.clientEncoder.write(id2.client);
|
|
955
|
-
this.leftClockEncoder.write(id2.clock);
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* @param {ID} id
|
|
959
|
-
*/
|
|
960
|
-
writeRightID(id2) {
|
|
961
|
-
this.clientEncoder.write(id2.client);
|
|
962
|
-
this.rightClockEncoder.write(id2.clock);
|
|
963
|
-
}
|
|
964
|
-
/**
|
|
965
|
-
* @param {number} client
|
|
966
|
-
*/
|
|
967
|
-
writeClient(client) {
|
|
968
|
-
this.clientEncoder.write(client);
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* @param {number} info An unsigned 8-bit integer
|
|
972
|
-
*/
|
|
973
|
-
writeInfo(info) {
|
|
974
|
-
this.infoEncoder.write(info);
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* @param {string} s
|
|
978
|
-
*/
|
|
979
|
-
writeString(s) {
|
|
980
|
-
this.stringEncoder.write(s);
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* @param {boolean} isYKey
|
|
984
|
-
*/
|
|
985
|
-
writeParentInfo(isYKey) {
|
|
986
|
-
this.parentInfoEncoder.write(isYKey ? 1 : 0);
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* @param {number} info An unsigned 8-bit integer
|
|
990
|
-
*/
|
|
991
|
-
writeTypeRef(info) {
|
|
992
|
-
this.typeRefEncoder.write(info);
|
|
993
|
-
}
|
|
994
|
-
/**
|
|
995
|
-
* Write len of a struct - well suited for Opt RLE encoder.
|
|
996
|
-
*
|
|
997
|
-
* @param {number} len
|
|
998
|
-
*/
|
|
999
|
-
writeLen(len) {
|
|
1000
|
-
this.lenEncoder.write(len);
|
|
1001
|
-
}
|
|
1002
|
-
/**
|
|
1003
|
-
* @param {any} any
|
|
1004
|
-
*/
|
|
1005
|
-
writeAny(any2) {
|
|
1006
|
-
writeAny(this.restEncoder, any2);
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* @param {Uint8Array} buf
|
|
1010
|
-
*/
|
|
1011
|
-
writeBuf(buf) {
|
|
1012
|
-
writeVarUint8Array(this.restEncoder, buf);
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* This is mainly here for legacy purposes.
|
|
1016
|
-
*
|
|
1017
|
-
* Initial we incoded objects using JSON. Now we use the much faster lib0/any-encoder. This method mainly exists for legacy purposes for the v1 encoder.
|
|
1018
|
-
*
|
|
1019
|
-
* @param {any} embed
|
|
1020
|
-
*/
|
|
1021
|
-
writeJSON(embed) {
|
|
1022
|
-
writeAny(this.restEncoder, embed);
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Property keys are often reused. For example, in y-prosemirror the key `bold` might
|
|
1026
|
-
* occur very often. For a 3d application, the key `position` might occur very often.
|
|
1027
|
-
*
|
|
1028
|
-
* We cache these keys in a Map and refer to them via a unique number.
|
|
1029
|
-
*
|
|
1030
|
-
* @param {string} key
|
|
1031
|
-
*/
|
|
1032
|
-
writeKey(key) {
|
|
1033
|
-
const clock = this.keyMap.get(key);
|
|
1034
|
-
if (clock === void 0) {
|
|
1035
|
-
this.keyClockEncoder.write(this.keyClock++);
|
|
1036
|
-
this.stringEncoder.write(key);
|
|
1037
|
-
} else {
|
|
1038
|
-
this.keyClockEncoder.write(clock);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
const writeStructs = (encoder, structs, client, clock) => {
|
|
1043
|
-
clock = max(clock, structs[0].id.clock);
|
|
1044
|
-
const startNewStructs = findIndexSS(structs, clock);
|
|
1045
|
-
writeVarUint(encoder.restEncoder, structs.length - startNewStructs);
|
|
1046
|
-
encoder.writeClient(client);
|
|
1047
|
-
writeVarUint(encoder.restEncoder, clock);
|
|
1048
|
-
const firstStruct = structs[startNewStructs];
|
|
1049
|
-
firstStruct.write(encoder, clock - firstStruct.id.clock);
|
|
1050
|
-
for (let i = startNewStructs + 1; i < structs.length; i++) {
|
|
1051
|
-
structs[i].write(encoder, 0);
|
|
1052
|
-
}
|
|
1053
|
-
};
|
|
1054
|
-
const writeClientsStructs = (encoder, store, _sm) => {
|
|
1055
|
-
const sm = /* @__PURE__ */ new Map();
|
|
1056
|
-
_sm.forEach((clock, client) => {
|
|
1057
|
-
if (getState(store, client) > clock) {
|
|
1058
|
-
sm.set(client, clock);
|
|
1059
|
-
}
|
|
1060
|
-
});
|
|
1061
|
-
getStateVector(store).forEach((_clock, client) => {
|
|
1062
|
-
if (!_sm.has(client)) {
|
|
1063
|
-
sm.set(client, 0);
|
|
1064
|
-
}
|
|
1065
|
-
});
|
|
1066
|
-
writeVarUint(encoder.restEncoder, sm.size);
|
|
1067
|
-
from$1(sm.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {
|
|
1068
|
-
writeStructs(
|
|
1069
|
-
encoder,
|
|
1070
|
-
/** @type {Array<GC|Item>} */
|
|
1071
|
-
store.clients.get(client),
|
|
1072
|
-
client,
|
|
1073
|
-
clock
|
|
1074
|
-
);
|
|
1075
|
-
});
|
|
1076
|
-
};
|
|
1077
|
-
const writeStructsFromTransaction = (encoder, transaction) => writeClientsStructs(encoder, transaction.doc.store, transaction.beforeState);
|
|
1078
|
-
const callEventHandlerListeners = (eventHandler, arg0, arg1) => callAll(eventHandler.l, [arg0, arg1]);
|
|
1079
|
-
class ID {
|
|
1080
|
-
/**
|
|
1081
|
-
* @param {number} client client id
|
|
1082
|
-
* @param {number} clock unique per client id, continuous number
|
|
1083
|
-
*/
|
|
1084
|
-
constructor(client, clock) {
|
|
1085
|
-
this.client = client;
|
|
1086
|
-
this.clock = clock;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
const compareIDs = (a, b) => a === b || a !== null && b !== null && a.client === b.client && a.clock === b.clock;
|
|
1090
|
-
const createID = (client, clock) => new ID(client, clock);
|
|
1091
|
-
const findRootTypeKey = (type) => {
|
|
1092
|
-
for (const [key, value] of type.doc.share.entries()) {
|
|
1093
|
-
if (value === type) {
|
|
1094
|
-
return key;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
throw unexpectedCase();
|
|
1098
|
-
};
|
|
1099
|
-
const isParentOf = (parent, child) => {
|
|
1100
|
-
while (child !== null) {
|
|
1101
|
-
if (child.parent === parent) {
|
|
1102
|
-
return true;
|
|
1103
|
-
}
|
|
1104
|
-
child = /** @type {AbstractType<any>} */
|
|
1105
|
-
child.parent._item;
|
|
1106
|
-
}
|
|
1107
|
-
return false;
|
|
1108
|
-
};
|
|
1109
|
-
class RelativePosition {
|
|
1110
|
-
/**
|
|
1111
|
-
* @param {ID|null} type
|
|
1112
|
-
* @param {string|null} tname
|
|
1113
|
-
* @param {ID|null} item
|
|
1114
|
-
* @param {number} assoc
|
|
1115
|
-
*/
|
|
1116
|
-
constructor(type, tname, item, assoc = 0) {
|
|
1117
|
-
this.type = type;
|
|
1118
|
-
this.tname = tname;
|
|
1119
|
-
this.item = item;
|
|
1120
|
-
this.assoc = assoc;
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
const relativePositionToJSON = (rpos) => {
|
|
1124
|
-
const json2 = {};
|
|
1125
|
-
if (rpos.type) {
|
|
1126
|
-
json2.type = rpos.type;
|
|
1127
|
-
}
|
|
1128
|
-
if (rpos.tname) {
|
|
1129
|
-
json2.tname = rpos.tname;
|
|
1130
|
-
}
|
|
1131
|
-
if (rpos.item) {
|
|
1132
|
-
json2.item = rpos.item;
|
|
1133
|
-
}
|
|
1134
|
-
if (rpos.assoc != null) {
|
|
1135
|
-
json2.assoc = rpos.assoc;
|
|
1136
|
-
}
|
|
1137
|
-
return json2;
|
|
1138
|
-
};
|
|
1139
|
-
const createRelativePositionFromJSON = (json2) => new RelativePosition(json2.type == null ? null : createID(json2.type.client, json2.type.clock), json2.tname || null, json2.item == null ? null : createID(json2.item.client, json2.item.clock), json2.assoc == null ? 0 : json2.assoc);
|
|
1140
|
-
class AbsolutePosition {
|
|
1141
|
-
/**
|
|
1142
|
-
* @param {AbstractType<any>} type
|
|
1143
|
-
* @param {number} index
|
|
1144
|
-
* @param {number} [assoc]
|
|
1145
|
-
*/
|
|
1146
|
-
constructor(type, index, assoc = 0) {
|
|
1147
|
-
this.type = type;
|
|
1148
|
-
this.index = index;
|
|
1149
|
-
this.assoc = assoc;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
const createAbsolutePosition = (type, index, assoc = 0) => new AbsolutePosition(type, index, assoc);
|
|
1153
|
-
const createRelativePosition = (type, item, assoc) => {
|
|
1154
|
-
let typeid = null;
|
|
1155
|
-
let tname = null;
|
|
1156
|
-
if (type._item === null) {
|
|
1157
|
-
tname = findRootTypeKey(type);
|
|
1158
|
-
} else {
|
|
1159
|
-
typeid = createID(type._item.id.client, type._item.id.clock);
|
|
1160
|
-
}
|
|
1161
|
-
return new RelativePosition(typeid, tname, item, assoc);
|
|
1162
|
-
};
|
|
1163
|
-
const createRelativePositionFromTypeIndex = (type, index, assoc = 0) => {
|
|
1164
|
-
let t2 = type._start;
|
|
1165
|
-
if (assoc < 0) {
|
|
1166
|
-
if (index === 0) {
|
|
1167
|
-
return createRelativePosition(type, null, assoc);
|
|
1168
|
-
}
|
|
1169
|
-
index--;
|
|
1170
|
-
}
|
|
1171
|
-
while (t2 !== null) {
|
|
1172
|
-
if (!t2.deleted && t2.countable) {
|
|
1173
|
-
if (t2.length > index) {
|
|
1174
|
-
return createRelativePosition(type, createID(t2.id.client, t2.id.clock + index), assoc);
|
|
1175
|
-
}
|
|
1176
|
-
index -= t2.length;
|
|
1177
|
-
}
|
|
1178
|
-
if (t2.right === null && assoc < 0) {
|
|
1179
|
-
return createRelativePosition(type, t2.lastId, assoc);
|
|
1180
|
-
}
|
|
1181
|
-
t2 = t2.right;
|
|
1182
|
-
}
|
|
1183
|
-
return createRelativePosition(type, null, assoc);
|
|
1184
|
-
};
|
|
1185
|
-
const createAbsolutePositionFromRelativePosition = (rpos, doc2) => {
|
|
1186
|
-
const store = doc2.store;
|
|
1187
|
-
const rightID = rpos.item;
|
|
1188
|
-
const typeID = rpos.type;
|
|
1189
|
-
const tname = rpos.tname;
|
|
1190
|
-
const assoc = rpos.assoc;
|
|
1191
|
-
let type = null;
|
|
1192
|
-
let index = 0;
|
|
1193
|
-
if (rightID !== null) {
|
|
1194
|
-
if (getState(store, rightID.client) <= rightID.clock) {
|
|
1195
|
-
return null;
|
|
1196
|
-
}
|
|
1197
|
-
const res = followRedone(store, rightID);
|
|
1198
|
-
const right = res.item;
|
|
1199
|
-
if (!(right instanceof Item)) {
|
|
1200
|
-
return null;
|
|
1201
|
-
}
|
|
1202
|
-
type = /** @type {AbstractType<any>} */
|
|
1203
|
-
right.parent;
|
|
1204
|
-
if (type._item === null || !type._item.deleted) {
|
|
1205
|
-
index = right.deleted || !right.countable ? 0 : res.diff + (assoc >= 0 ? 0 : 1);
|
|
1206
|
-
let n = right.left;
|
|
1207
|
-
while (n !== null) {
|
|
1208
|
-
if (!n.deleted && n.countable) {
|
|
1209
|
-
index += n.length;
|
|
1210
|
-
}
|
|
1211
|
-
n = n.left;
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
} else {
|
|
1215
|
-
if (tname !== null) {
|
|
1216
|
-
type = doc2.get(tname);
|
|
1217
|
-
} else if (typeID !== null) {
|
|
1218
|
-
if (getState(store, typeID.client) <= typeID.clock) {
|
|
1219
|
-
return null;
|
|
1220
|
-
}
|
|
1221
|
-
const { item } = followRedone(store, typeID);
|
|
1222
|
-
if (item instanceof Item && item.content instanceof ContentType) {
|
|
1223
|
-
type = item.content.type;
|
|
1224
|
-
} else {
|
|
1225
|
-
return null;
|
|
1226
|
-
}
|
|
1227
|
-
} else {
|
|
1228
|
-
throw unexpectedCase();
|
|
1229
|
-
}
|
|
1230
|
-
if (assoc >= 0) {
|
|
1231
|
-
index = type._length;
|
|
1232
|
-
} else {
|
|
1233
|
-
index = 0;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
return createAbsolutePosition(type, index, rpos.assoc);
|
|
1237
|
-
};
|
|
1238
|
-
const compareRelativePositions = (a, b) => a === b || a !== null && b !== null && a.tname === b.tname && compareIDs(a.item, b.item) && compareIDs(a.type, b.type) && a.assoc === b.assoc;
|
|
1239
|
-
const getStateVector = (store) => {
|
|
1240
|
-
const sm = /* @__PURE__ */ new Map();
|
|
1241
|
-
store.clients.forEach((structs, client) => {
|
|
1242
|
-
const struct = structs[structs.length - 1];
|
|
1243
|
-
sm.set(client, struct.id.clock + struct.length);
|
|
1244
|
-
});
|
|
1245
|
-
return sm;
|
|
1246
|
-
};
|
|
1247
|
-
const getState = (store, client) => {
|
|
1248
|
-
const structs = store.clients.get(client);
|
|
1249
|
-
if (structs === void 0) {
|
|
1250
|
-
return 0;
|
|
1251
|
-
}
|
|
1252
|
-
const lastStruct = structs[structs.length - 1];
|
|
1253
|
-
return lastStruct.id.clock + lastStruct.length;
|
|
1254
|
-
};
|
|
1255
|
-
const addStruct = (store, struct) => {
|
|
1256
|
-
let structs = store.clients.get(struct.id.client);
|
|
1257
|
-
if (structs === void 0) {
|
|
1258
|
-
structs = [];
|
|
1259
|
-
store.clients.set(struct.id.client, structs);
|
|
1260
|
-
} else {
|
|
1261
|
-
const lastStruct = structs[structs.length - 1];
|
|
1262
|
-
if (lastStruct.id.clock + lastStruct.length !== struct.id.clock) {
|
|
1263
|
-
throw unexpectedCase();
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
structs.push(struct);
|
|
1267
|
-
};
|
|
1268
|
-
const findIndexSS = (structs, clock) => {
|
|
1269
|
-
let left = 0;
|
|
1270
|
-
let right = structs.length - 1;
|
|
1271
|
-
let mid = structs[right];
|
|
1272
|
-
let midclock = mid.id.clock;
|
|
1273
|
-
if (midclock === clock) {
|
|
1274
|
-
return right;
|
|
1275
|
-
}
|
|
1276
|
-
let midindex = floor(clock / (midclock + mid.length - 1) * right);
|
|
1277
|
-
while (left <= right) {
|
|
1278
|
-
mid = structs[midindex];
|
|
1279
|
-
midclock = mid.id.clock;
|
|
1280
|
-
if (midclock <= clock) {
|
|
1281
|
-
if (clock < midclock + mid.length) {
|
|
1282
|
-
return midindex;
|
|
1283
|
-
}
|
|
1284
|
-
left = midindex + 1;
|
|
1285
|
-
} else {
|
|
1286
|
-
right = midindex - 1;
|
|
1287
|
-
}
|
|
1288
|
-
midindex = floor((left + right) / 2);
|
|
1289
|
-
}
|
|
1290
|
-
throw unexpectedCase();
|
|
1291
|
-
};
|
|
1292
|
-
const find$1 = (store, id2) => {
|
|
1293
|
-
const structs = store.clients.get(id2.client);
|
|
1294
|
-
return structs[findIndexSS(structs, id2.clock)];
|
|
1295
|
-
};
|
|
1296
|
-
const getItem = (
|
|
1297
|
-
/** @type {function(StructStore,ID):Item} */
|
|
1298
|
-
find$1
|
|
1299
|
-
);
|
|
1300
|
-
const findIndexCleanStart = (transaction, structs, clock) => {
|
|
1301
|
-
const index = findIndexSS(structs, clock);
|
|
1302
|
-
const struct = structs[index];
|
|
1303
|
-
if (struct.id.clock < clock && struct instanceof Item) {
|
|
1304
|
-
structs.splice(index + 1, 0, splitItem(transaction, struct, clock - struct.id.clock));
|
|
1305
|
-
return index + 1;
|
|
1306
|
-
}
|
|
1307
|
-
return index;
|
|
1308
|
-
};
|
|
1309
|
-
const getItemCleanStart = (transaction, id2) => {
|
|
1310
|
-
const structs = (
|
|
1311
|
-
/** @type {Array<Item>} */
|
|
1312
|
-
transaction.doc.store.clients.get(id2.client)
|
|
1313
|
-
);
|
|
1314
|
-
return structs[findIndexCleanStart(transaction, structs, id2.clock)];
|
|
1315
|
-
};
|
|
1316
|
-
const getItemCleanEnd = (transaction, store, id2) => {
|
|
1317
|
-
const structs = store.clients.get(id2.client);
|
|
1318
|
-
const index = findIndexSS(structs, id2.clock);
|
|
1319
|
-
const struct = structs[index];
|
|
1320
|
-
if (id2.clock !== struct.id.clock + struct.length - 1 && struct.constructor !== GC) {
|
|
1321
|
-
structs.splice(index + 1, 0, splitItem(transaction, struct, id2.clock - struct.id.clock + 1));
|
|
1322
|
-
}
|
|
1323
|
-
return struct;
|
|
1324
|
-
};
|
|
1325
|
-
const replaceStruct = (store, struct, newStruct) => {
|
|
1326
|
-
const structs = (
|
|
1327
|
-
/** @type {Array<GC|Item>} */
|
|
1328
|
-
store.clients.get(struct.id.client)
|
|
1329
|
-
);
|
|
1330
|
-
structs[findIndexSS(structs, struct.id.clock)] = newStruct;
|
|
1331
|
-
};
|
|
1332
|
-
const iterateStructs = (transaction, structs, clockStart, len, f) => {
|
|
1333
|
-
if (len === 0) {
|
|
1334
|
-
return;
|
|
1335
|
-
}
|
|
1336
|
-
const clockEnd = clockStart + len;
|
|
1337
|
-
let index = findIndexCleanStart(transaction, structs, clockStart);
|
|
1338
|
-
let struct;
|
|
1339
|
-
do {
|
|
1340
|
-
struct = structs[index++];
|
|
1341
|
-
if (clockEnd < struct.id.clock + struct.length) {
|
|
1342
|
-
findIndexCleanStart(transaction, structs, clockEnd);
|
|
1343
|
-
}
|
|
1344
|
-
f(struct);
|
|
1345
|
-
} while (index < structs.length && structs[index].id.clock < clockEnd);
|
|
1346
|
-
};
|
|
1347
|
-
let Transaction$1 = class Transaction {
|
|
1348
|
-
/**
|
|
1349
|
-
* @param {Doc} doc
|
|
1350
|
-
* @param {any} origin
|
|
1351
|
-
* @param {boolean} local
|
|
1352
|
-
*/
|
|
1353
|
-
constructor(doc2, origin, local) {
|
|
1354
|
-
this.doc = doc2;
|
|
1355
|
-
this.deleteSet = new DeleteSet();
|
|
1356
|
-
this.beforeState = getStateVector(doc2.store);
|
|
1357
|
-
this.afterState = /* @__PURE__ */ new Map();
|
|
1358
|
-
this.changed = /* @__PURE__ */ new Map();
|
|
1359
|
-
this.changedParentTypes = /* @__PURE__ */ new Map();
|
|
1360
|
-
this._mergeStructs = [];
|
|
1361
|
-
this.origin = origin;
|
|
1362
|
-
this.meta = /* @__PURE__ */ new Map();
|
|
1363
|
-
this.local = local;
|
|
1364
|
-
this.subdocsAdded = /* @__PURE__ */ new Set();
|
|
1365
|
-
this.subdocsRemoved = /* @__PURE__ */ new Set();
|
|
1366
|
-
this.subdocsLoaded = /* @__PURE__ */ new Set();
|
|
1367
|
-
this._needFormattingCleanup = false;
|
|
1368
|
-
}
|
|
1369
|
-
};
|
|
1370
|
-
const writeUpdateMessageFromTransaction = (encoder, transaction) => {
|
|
1371
|
-
if (transaction.deleteSet.clients.size === 0 && !any(transaction.afterState, (clock, client) => transaction.beforeState.get(client) !== clock)) {
|
|
1372
|
-
return false;
|
|
1373
|
-
}
|
|
1374
|
-
sortAndMergeDeleteSet(transaction.deleteSet);
|
|
1375
|
-
writeStructsFromTransaction(encoder, transaction);
|
|
1376
|
-
writeDeleteSet(encoder, transaction.deleteSet);
|
|
1377
|
-
return true;
|
|
1378
|
-
};
|
|
1379
|
-
const addChangedTypeToTransaction = (transaction, type, parentSub) => {
|
|
1380
|
-
const item = type._item;
|
|
1381
|
-
if (item === null || item.id.clock < (transaction.beforeState.get(item.id.client) || 0) && !item.deleted) {
|
|
1382
|
-
setIfUndefined(transaction.changed, type, create$3).add(parentSub);
|
|
1383
|
-
}
|
|
1384
|
-
};
|
|
1385
|
-
const tryToMergeWithLefts = (structs, pos) => {
|
|
1386
|
-
let right = structs[pos];
|
|
1387
|
-
let left = structs[pos - 1];
|
|
1388
|
-
let i = pos;
|
|
1389
|
-
for (; i > 0; right = left, left = structs[--i - 1]) {
|
|
1390
|
-
if (left.deleted === right.deleted && left.constructor === right.constructor) {
|
|
1391
|
-
if (left.mergeWith(right)) {
|
|
1392
|
-
if (right instanceof Item && right.parentSub !== null && /** @type {AbstractType<any>} */
|
|
1393
|
-
right.parent._map.get(right.parentSub) === right) {
|
|
1394
|
-
right.parent._map.set(
|
|
1395
|
-
right.parentSub,
|
|
1396
|
-
/** @type {Item} */
|
|
1397
|
-
left
|
|
1398
|
-
);
|
|
1399
|
-
}
|
|
1400
|
-
continue;
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
break;
|
|
1404
|
-
}
|
|
1405
|
-
const merged = pos - i;
|
|
1406
|
-
if (merged) {
|
|
1407
|
-
structs.splice(pos + 1 - merged, merged);
|
|
1408
|
-
}
|
|
1409
|
-
return merged;
|
|
1410
|
-
};
|
|
1411
|
-
const tryGcDeleteSet = (ds, store, gcFilter) => {
|
|
1412
|
-
for (const [client, deleteItems] of ds.clients.entries()) {
|
|
1413
|
-
const structs = (
|
|
1414
|
-
/** @type {Array<GC|Item>} */
|
|
1415
|
-
store.clients.get(client)
|
|
1416
|
-
);
|
|
1417
|
-
for (let di = deleteItems.length - 1; di >= 0; di--) {
|
|
1418
|
-
const deleteItem = deleteItems[di];
|
|
1419
|
-
const endDeleteItemClock = deleteItem.clock + deleteItem.len;
|
|
1420
|
-
for (let si = findIndexSS(structs, deleteItem.clock), struct = structs[si]; si < structs.length && struct.id.clock < endDeleteItemClock; struct = structs[++si]) {
|
|
1421
|
-
const struct2 = structs[si];
|
|
1422
|
-
if (deleteItem.clock + deleteItem.len <= struct2.id.clock) {
|
|
1423
|
-
break;
|
|
1424
|
-
}
|
|
1425
|
-
if (struct2 instanceof Item && struct2.deleted && !struct2.keep && gcFilter(struct2)) {
|
|
1426
|
-
struct2.gc(store, false);
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
};
|
|
1432
|
-
const tryMergeDeleteSet = (ds, store) => {
|
|
1433
|
-
ds.clients.forEach((deleteItems, client) => {
|
|
1434
|
-
const structs = (
|
|
1435
|
-
/** @type {Array<GC|Item>} */
|
|
1436
|
-
store.clients.get(client)
|
|
1437
|
-
);
|
|
1438
|
-
for (let di = deleteItems.length - 1; di >= 0; di--) {
|
|
1439
|
-
const deleteItem = deleteItems[di];
|
|
1440
|
-
const mostRightIndexToCheck = min(structs.length - 1, 1 + findIndexSS(structs, deleteItem.clock + deleteItem.len - 1));
|
|
1441
|
-
for (let si = mostRightIndexToCheck, struct = structs[si]; si > 0 && struct.id.clock >= deleteItem.clock; struct = structs[si]) {
|
|
1442
|
-
si -= 1 + tryToMergeWithLefts(structs, si);
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
});
|
|
1446
|
-
};
|
|
1447
|
-
const cleanupTransactions = (transactionCleanups, i) => {
|
|
1448
|
-
if (i < transactionCleanups.length) {
|
|
1449
|
-
const transaction = transactionCleanups[i];
|
|
1450
|
-
const doc2 = transaction.doc;
|
|
1451
|
-
const store = doc2.store;
|
|
1452
|
-
const ds = transaction.deleteSet;
|
|
1453
|
-
const mergeStructs = transaction._mergeStructs;
|
|
1454
|
-
try {
|
|
1455
|
-
sortAndMergeDeleteSet(ds);
|
|
1456
|
-
transaction.afterState = getStateVector(transaction.doc.store);
|
|
1457
|
-
doc2.emit("beforeObserverCalls", [transaction, doc2]);
|
|
1458
|
-
const fs = [];
|
|
1459
|
-
transaction.changed.forEach(
|
|
1460
|
-
(subs, itemtype) => fs.push(() => {
|
|
1461
|
-
if (itemtype._item === null || !itemtype._item.deleted) {
|
|
1462
|
-
itemtype._callObserver(transaction, subs);
|
|
1463
|
-
}
|
|
1464
|
-
})
|
|
1465
|
-
);
|
|
1466
|
-
fs.push(() => {
|
|
1467
|
-
transaction.changedParentTypes.forEach((events, type) => {
|
|
1468
|
-
if (type._dEH.l.length > 0 && (type._item === null || !type._item.deleted)) {
|
|
1469
|
-
events = events.filter(
|
|
1470
|
-
(event) => event.target._item === null || !event.target._item.deleted
|
|
1471
|
-
);
|
|
1472
|
-
events.forEach((event) => {
|
|
1473
|
-
event.currentTarget = type;
|
|
1474
|
-
event._path = null;
|
|
1475
|
-
});
|
|
1476
|
-
events.sort((event1, event2) => event1.path.length - event2.path.length);
|
|
1477
|
-
callEventHandlerListeners(type._dEH, events, transaction);
|
|
1478
|
-
}
|
|
1479
|
-
});
|
|
1480
|
-
});
|
|
1481
|
-
fs.push(() => doc2.emit("afterTransaction", [transaction, doc2]));
|
|
1482
|
-
callAll(fs, []);
|
|
1483
|
-
if (transaction._needFormattingCleanup) {
|
|
1484
|
-
cleanupYTextAfterTransaction(transaction);
|
|
1485
|
-
}
|
|
1486
|
-
} finally {
|
|
1487
|
-
if (doc2.gc) {
|
|
1488
|
-
tryGcDeleteSet(ds, store, doc2.gcFilter);
|
|
1489
|
-
}
|
|
1490
|
-
tryMergeDeleteSet(ds, store);
|
|
1491
|
-
transaction.afterState.forEach((clock, client) => {
|
|
1492
|
-
const beforeClock = transaction.beforeState.get(client) || 0;
|
|
1493
|
-
if (beforeClock !== clock) {
|
|
1494
|
-
const structs = (
|
|
1495
|
-
/** @type {Array<GC|Item>} */
|
|
1496
|
-
store.clients.get(client)
|
|
1497
|
-
);
|
|
1498
|
-
const firstChangePos = max(findIndexSS(structs, beforeClock), 1);
|
|
1499
|
-
for (let i2 = structs.length - 1; i2 >= firstChangePos; ) {
|
|
1500
|
-
i2 -= 1 + tryToMergeWithLefts(structs, i2);
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
});
|
|
1504
|
-
for (let i2 = mergeStructs.length - 1; i2 >= 0; i2--) {
|
|
1505
|
-
const { client, clock } = mergeStructs[i2].id;
|
|
1506
|
-
const structs = (
|
|
1507
|
-
/** @type {Array<GC|Item>} */
|
|
1508
|
-
store.clients.get(client)
|
|
1509
|
-
);
|
|
1510
|
-
const replacedStructPos = findIndexSS(structs, clock);
|
|
1511
|
-
if (replacedStructPos + 1 < structs.length) {
|
|
1512
|
-
if (tryToMergeWithLefts(structs, replacedStructPos + 1) > 1) {
|
|
1513
|
-
continue;
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
if (replacedStructPos > 0) {
|
|
1517
|
-
tryToMergeWithLefts(structs, replacedStructPos);
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
if (!transaction.local && transaction.afterState.get(doc2.clientID) !== transaction.beforeState.get(doc2.clientID)) {
|
|
1521
|
-
print$1(ORANGE, BOLD, "[yjs] ", UNBOLD, RED, "Changed the client-id because another client seems to be using it.");
|
|
1522
|
-
doc2.clientID = generateNewClientId();
|
|
1523
|
-
}
|
|
1524
|
-
doc2.emit("afterTransactionCleanup", [transaction, doc2]);
|
|
1525
|
-
if (doc2._observers.has("update")) {
|
|
1526
|
-
const encoder = new UpdateEncoderV1();
|
|
1527
|
-
const hasContent = writeUpdateMessageFromTransaction(encoder, transaction);
|
|
1528
|
-
if (hasContent) {
|
|
1529
|
-
doc2.emit("update", [encoder.toUint8Array(), transaction.origin, doc2, transaction]);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
if (doc2._observers.has("updateV2")) {
|
|
1533
|
-
const encoder = new UpdateEncoderV2();
|
|
1534
|
-
const hasContent = writeUpdateMessageFromTransaction(encoder, transaction);
|
|
1535
|
-
if (hasContent) {
|
|
1536
|
-
doc2.emit("updateV2", [encoder.toUint8Array(), transaction.origin, doc2, transaction]);
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
const { subdocsAdded, subdocsLoaded, subdocsRemoved } = transaction;
|
|
1540
|
-
if (subdocsAdded.size > 0 || subdocsRemoved.size > 0 || subdocsLoaded.size > 0) {
|
|
1541
|
-
subdocsAdded.forEach((subdoc) => {
|
|
1542
|
-
subdoc.clientID = doc2.clientID;
|
|
1543
|
-
if (subdoc.collectionid == null) {
|
|
1544
|
-
subdoc.collectionid = doc2.collectionid;
|
|
1545
|
-
}
|
|
1546
|
-
doc2.subdocs.add(subdoc);
|
|
1547
|
-
});
|
|
1548
|
-
subdocsRemoved.forEach((subdoc) => doc2.subdocs.delete(subdoc));
|
|
1549
|
-
doc2.emit("subdocs", [{ loaded: subdocsLoaded, added: subdocsAdded, removed: subdocsRemoved }, doc2, transaction]);
|
|
1550
|
-
subdocsRemoved.forEach((subdoc) => subdoc.destroy());
|
|
1551
|
-
}
|
|
1552
|
-
if (transactionCleanups.length <= i + 1) {
|
|
1553
|
-
doc2._transactionCleanups = [];
|
|
1554
|
-
doc2.emit("afterAllTransactions", [doc2, transactionCleanups]);
|
|
1555
|
-
} else {
|
|
1556
|
-
cleanupTransactions(transactionCleanups, i + 1);
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
};
|
|
1561
|
-
const transact = (doc2, f, origin = null, local = true) => {
|
|
1562
|
-
const transactionCleanups = doc2._transactionCleanups;
|
|
1563
|
-
let initialCall = false;
|
|
1564
|
-
let result = null;
|
|
1565
|
-
if (doc2._transaction === null) {
|
|
1566
|
-
initialCall = true;
|
|
1567
|
-
doc2._transaction = new Transaction$1(doc2, origin, local);
|
|
1568
|
-
transactionCleanups.push(doc2._transaction);
|
|
1569
|
-
if (transactionCleanups.length === 1) {
|
|
1570
|
-
doc2.emit("beforeAllTransactions", [doc2]);
|
|
1571
|
-
}
|
|
1572
|
-
doc2.emit("beforeTransaction", [doc2._transaction, doc2]);
|
|
1573
|
-
}
|
|
1574
|
-
try {
|
|
1575
|
-
result = f(doc2._transaction);
|
|
1576
|
-
} finally {
|
|
1577
|
-
if (initialCall) {
|
|
1578
|
-
const finishCleanup = doc2._transaction === transactionCleanups[0];
|
|
1579
|
-
doc2._transaction = null;
|
|
1580
|
-
if (finishCleanup) {
|
|
1581
|
-
cleanupTransactions(transactionCleanups, 0);
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
return result;
|
|
1586
|
-
};
|
|
1587
|
-
class StackItem {
|
|
1588
|
-
/**
|
|
1589
|
-
* @param {DeleteSet} deletions
|
|
1590
|
-
* @param {DeleteSet} insertions
|
|
1591
|
-
*/
|
|
1592
|
-
constructor(deletions, insertions) {
|
|
1593
|
-
this.insertions = insertions;
|
|
1594
|
-
this.deletions = deletions;
|
|
1595
|
-
this.meta = /* @__PURE__ */ new Map();
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
const clearUndoManagerStackItem = (tr, um, stackItem) => {
|
|
1599
|
-
iterateDeletedStructs(tr, stackItem.deletions, (item) => {
|
|
1600
|
-
if (item instanceof Item && um.scope.some((type) => isParentOf(type, item))) {
|
|
1601
|
-
keepItem(item, false);
|
|
1602
|
-
}
|
|
1603
|
-
});
|
|
1604
|
-
};
|
|
1605
|
-
const popStackItem = (undoManager, stack, eventType) => {
|
|
1606
|
-
let result = null;
|
|
1607
|
-
let _tr = null;
|
|
1608
|
-
const doc2 = undoManager.doc;
|
|
1609
|
-
const scope = undoManager.scope;
|
|
1610
|
-
transact(doc2, (transaction) => {
|
|
1611
|
-
while (stack.length > 0 && result === null) {
|
|
1612
|
-
const store = doc2.store;
|
|
1613
|
-
const stackItem = (
|
|
1614
|
-
/** @type {StackItem} */
|
|
1615
|
-
stack.pop()
|
|
1616
|
-
);
|
|
1617
|
-
const itemsToRedo = /* @__PURE__ */ new Set();
|
|
1618
|
-
const itemsToDelete = [];
|
|
1619
|
-
let performedChange = false;
|
|
1620
|
-
iterateDeletedStructs(transaction, stackItem.insertions, (struct) => {
|
|
1621
|
-
if (struct instanceof Item) {
|
|
1622
|
-
if (struct.redone !== null) {
|
|
1623
|
-
let { item, diff } = followRedone(store, struct.id);
|
|
1624
|
-
if (diff > 0) {
|
|
1625
|
-
item = getItemCleanStart(transaction, createID(item.id.client, item.id.clock + diff));
|
|
1626
|
-
}
|
|
1627
|
-
struct = item;
|
|
1628
|
-
}
|
|
1629
|
-
if (!struct.deleted && scope.some((type) => isParentOf(
|
|
1630
|
-
type,
|
|
1631
|
-
/** @type {Item} */
|
|
1632
|
-
struct
|
|
1633
|
-
))) {
|
|
1634
|
-
itemsToDelete.push(struct);
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
});
|
|
1638
|
-
iterateDeletedStructs(transaction, stackItem.deletions, (struct) => {
|
|
1639
|
-
if (struct instanceof Item && scope.some((type) => isParentOf(type, struct)) && // Never redo structs in stackItem.insertions because they were created and deleted in the same capture interval.
|
|
1640
|
-
!isDeleted(stackItem.insertions, struct.id)) {
|
|
1641
|
-
itemsToRedo.add(struct);
|
|
1642
|
-
}
|
|
1643
|
-
});
|
|
1644
|
-
itemsToRedo.forEach((struct) => {
|
|
1645
|
-
performedChange = redoItem(transaction, struct, itemsToRedo, stackItem.insertions, undoManager.ignoreRemoteMapChanges, undoManager) !== null || performedChange;
|
|
1646
|
-
});
|
|
1647
|
-
for (let i = itemsToDelete.length - 1; i >= 0; i--) {
|
|
1648
|
-
const item = itemsToDelete[i];
|
|
1649
|
-
if (undoManager.deleteFilter(item)) {
|
|
1650
|
-
item.delete(transaction);
|
|
1651
|
-
performedChange = true;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
result = performedChange ? stackItem : null;
|
|
1655
|
-
}
|
|
1656
|
-
transaction.changed.forEach((subProps, type) => {
|
|
1657
|
-
if (subProps.has(null) && type._searchMarker) {
|
|
1658
|
-
type._searchMarker.length = 0;
|
|
1659
|
-
}
|
|
1660
|
-
});
|
|
1661
|
-
_tr = transaction;
|
|
1662
|
-
}, undoManager);
|
|
1663
|
-
if (result != null) {
|
|
1664
|
-
const changedParentTypes = _tr.changedParentTypes;
|
|
1665
|
-
undoManager.emit("stack-item-popped", [{ stackItem: result, type: eventType, changedParentTypes }, undoManager]);
|
|
1666
|
-
}
|
|
1667
|
-
return result;
|
|
1668
|
-
};
|
|
1669
|
-
class UndoManager extends Observable {
|
|
1670
|
-
/**
|
|
1671
|
-
* @param {AbstractType<any>|Array<AbstractType<any>>} typeScope Accepts either a single type, or an array of types
|
|
1672
|
-
* @param {UndoManagerOptions} options
|
|
1673
|
-
*/
|
|
1674
|
-
constructor(typeScope, {
|
|
1675
|
-
captureTimeout = 500,
|
|
1676
|
-
captureTransaction = (_tr) => true,
|
|
1677
|
-
deleteFilter = () => true,
|
|
1678
|
-
trackedOrigins = /* @__PURE__ */ new Set([null]),
|
|
1679
|
-
ignoreRemoteMapChanges = false,
|
|
1680
|
-
doc: doc2 = (
|
|
1681
|
-
/** @type {Doc} */
|
|
1682
|
-
isArray(typeScope) ? typeScope[0].doc : typeScope.doc
|
|
1683
|
-
)
|
|
1684
|
-
} = {}) {
|
|
1685
|
-
super();
|
|
1686
|
-
this.scope = [];
|
|
1687
|
-
this.doc = doc2;
|
|
1688
|
-
this.addToScope(typeScope);
|
|
1689
|
-
this.deleteFilter = deleteFilter;
|
|
1690
|
-
trackedOrigins.add(this);
|
|
1691
|
-
this.trackedOrigins = trackedOrigins;
|
|
1692
|
-
this.captureTransaction = captureTransaction;
|
|
1693
|
-
this.undoStack = [];
|
|
1694
|
-
this.redoStack = [];
|
|
1695
|
-
this.undoing = false;
|
|
1696
|
-
this.redoing = false;
|
|
1697
|
-
this.lastChange = 0;
|
|
1698
|
-
this.ignoreRemoteMapChanges = ignoreRemoteMapChanges;
|
|
1699
|
-
this.captureTimeout = captureTimeout;
|
|
1700
|
-
this.afterTransactionHandler = (transaction) => {
|
|
1701
|
-
if (!this.captureTransaction(transaction) || !this.scope.some((type) => transaction.changedParentTypes.has(type)) || !this.trackedOrigins.has(transaction.origin) && (!transaction.origin || !this.trackedOrigins.has(transaction.origin.constructor))) {
|
|
1702
|
-
return;
|
|
1703
|
-
}
|
|
1704
|
-
const undoing = this.undoing;
|
|
1705
|
-
const redoing = this.redoing;
|
|
1706
|
-
const stack = undoing ? this.redoStack : this.undoStack;
|
|
1707
|
-
if (undoing) {
|
|
1708
|
-
this.stopCapturing();
|
|
1709
|
-
} else if (!redoing) {
|
|
1710
|
-
this.clear(false, true);
|
|
1711
|
-
}
|
|
1712
|
-
const insertions = new DeleteSet();
|
|
1713
|
-
transaction.afterState.forEach((endClock, client) => {
|
|
1714
|
-
const startClock = transaction.beforeState.get(client) || 0;
|
|
1715
|
-
const len = endClock - startClock;
|
|
1716
|
-
if (len > 0) {
|
|
1717
|
-
addToDeleteSet(insertions, client, startClock, len);
|
|
1718
|
-
}
|
|
1719
|
-
});
|
|
1720
|
-
const now = getUnixTime();
|
|
1721
|
-
let didAdd = false;
|
|
1722
|
-
if (this.lastChange > 0 && now - this.lastChange < this.captureTimeout && stack.length > 0 && !undoing && !redoing) {
|
|
1723
|
-
const lastOp = stack[stack.length - 1];
|
|
1724
|
-
lastOp.deletions = mergeDeleteSets([lastOp.deletions, transaction.deleteSet]);
|
|
1725
|
-
lastOp.insertions = mergeDeleteSets([lastOp.insertions, insertions]);
|
|
1726
|
-
} else {
|
|
1727
|
-
stack.push(new StackItem(transaction.deleteSet, insertions));
|
|
1728
|
-
didAdd = true;
|
|
1729
|
-
}
|
|
1730
|
-
if (!undoing && !redoing) {
|
|
1731
|
-
this.lastChange = now;
|
|
1732
|
-
}
|
|
1733
|
-
iterateDeletedStructs(
|
|
1734
|
-
transaction,
|
|
1735
|
-
transaction.deleteSet,
|
|
1736
|
-
/** @param {Item|GC} item */
|
|
1737
|
-
(item) => {
|
|
1738
|
-
if (item instanceof Item && this.scope.some((type) => isParentOf(type, item))) {
|
|
1739
|
-
keepItem(item, true);
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
);
|
|
1743
|
-
const changeEvent = [{ stackItem: stack[stack.length - 1], origin: transaction.origin, type: undoing ? "redo" : "undo", changedParentTypes: transaction.changedParentTypes }, this];
|
|
1744
|
-
if (didAdd) {
|
|
1745
|
-
this.emit("stack-item-added", changeEvent);
|
|
1746
|
-
} else {
|
|
1747
|
-
this.emit("stack-item-updated", changeEvent);
|
|
1748
|
-
}
|
|
1749
|
-
};
|
|
1750
|
-
this.doc.on("afterTransaction", this.afterTransactionHandler);
|
|
1751
|
-
this.doc.on("destroy", () => {
|
|
1752
|
-
this.destroy();
|
|
1753
|
-
});
|
|
1754
|
-
}
|
|
1755
|
-
/**
|
|
1756
|
-
* @param {Array<AbstractType<any>> | AbstractType<any>} ytypes
|
|
1757
|
-
*/
|
|
1758
|
-
addToScope(ytypes) {
|
|
1759
|
-
ytypes = isArray(ytypes) ? ytypes : [ytypes];
|
|
1760
|
-
ytypes.forEach((ytype) => {
|
|
1761
|
-
if (this.scope.every((yt) => yt !== ytype)) {
|
|
1762
|
-
if (ytype.doc !== this.doc)
|
|
1763
|
-
warn("[yjs#509] Not same Y.Doc");
|
|
1764
|
-
this.scope.push(ytype);
|
|
1765
|
-
}
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
/**
|
|
1769
|
-
* @param {any} origin
|
|
1770
|
-
*/
|
|
1771
|
-
addTrackedOrigin(origin) {
|
|
1772
|
-
this.trackedOrigins.add(origin);
|
|
1773
|
-
}
|
|
1774
|
-
/**
|
|
1775
|
-
* @param {any} origin
|
|
1776
|
-
*/
|
|
1777
|
-
removeTrackedOrigin(origin) {
|
|
1778
|
-
this.trackedOrigins.delete(origin);
|
|
1779
|
-
}
|
|
1780
|
-
clear(clearUndoStack = true, clearRedoStack = true) {
|
|
1781
|
-
if (clearUndoStack && this.canUndo() || clearRedoStack && this.canRedo()) {
|
|
1782
|
-
this.doc.transact((tr) => {
|
|
1783
|
-
if (clearUndoStack) {
|
|
1784
|
-
this.undoStack.forEach((item) => clearUndoManagerStackItem(tr, this, item));
|
|
1785
|
-
this.undoStack = [];
|
|
1786
|
-
}
|
|
1787
|
-
if (clearRedoStack) {
|
|
1788
|
-
this.redoStack.forEach((item) => clearUndoManagerStackItem(tr, this, item));
|
|
1789
|
-
this.redoStack = [];
|
|
1790
|
-
}
|
|
1791
|
-
this.emit("stack-cleared", [{ undoStackCleared: clearUndoStack, redoStackCleared: clearRedoStack }]);
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
/**
|
|
1796
|
-
* UndoManager merges Undo-StackItem if they are created within time-gap
|
|
1797
|
-
* smaller than `options.captureTimeout`. Call `um.stopCapturing()` so that the next
|
|
1798
|
-
* StackItem won't be merged.
|
|
1799
|
-
*
|
|
1800
|
-
*
|
|
1801
|
-
* @example
|
|
1802
|
-
* // without stopCapturing
|
|
1803
|
-
* ytext.insert(0, 'a')
|
|
1804
|
-
* ytext.insert(1, 'b')
|
|
1805
|
-
* um.undo()
|
|
1806
|
-
* ytext.toString() // => '' (note that 'ab' was removed)
|
|
1807
|
-
* // with stopCapturing
|
|
1808
|
-
* ytext.insert(0, 'a')
|
|
1809
|
-
* um.stopCapturing()
|
|
1810
|
-
* ytext.insert(0, 'b')
|
|
1811
|
-
* um.undo()
|
|
1812
|
-
* ytext.toString() // => 'a' (note that only 'b' was removed)
|
|
1813
|
-
*
|
|
1814
|
-
*/
|
|
1815
|
-
stopCapturing() {
|
|
1816
|
-
this.lastChange = 0;
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Undo last changes on type.
|
|
1820
|
-
*
|
|
1821
|
-
* @return {StackItem?} Returns StackItem if a change was applied
|
|
1822
|
-
*/
|
|
1823
|
-
undo() {
|
|
1824
|
-
this.undoing = true;
|
|
1825
|
-
let res;
|
|
1826
|
-
try {
|
|
1827
|
-
res = popStackItem(this, this.undoStack, "undo");
|
|
1828
|
-
} finally {
|
|
1829
|
-
this.undoing = false;
|
|
1830
|
-
}
|
|
1831
|
-
return res;
|
|
1832
|
-
}
|
|
1833
|
-
/**
|
|
1834
|
-
* Redo last undo operation.
|
|
1835
|
-
*
|
|
1836
|
-
* @return {StackItem?} Returns StackItem if a change was applied
|
|
1837
|
-
*/
|
|
1838
|
-
redo() {
|
|
1839
|
-
this.redoing = true;
|
|
1840
|
-
let res;
|
|
1841
|
-
try {
|
|
1842
|
-
res = popStackItem(this, this.redoStack, "redo");
|
|
1843
|
-
} finally {
|
|
1844
|
-
this.redoing = false;
|
|
1845
|
-
}
|
|
1846
|
-
return res;
|
|
1847
|
-
}
|
|
1848
|
-
/**
|
|
1849
|
-
* Are undo steps available?
|
|
1850
|
-
*
|
|
1851
|
-
* @return {boolean} `true` if undo is possible
|
|
1852
|
-
*/
|
|
1853
|
-
canUndo() {
|
|
1854
|
-
return this.undoStack.length > 0;
|
|
1855
|
-
}
|
|
1856
|
-
/**
|
|
1857
|
-
* Are redo steps available?
|
|
1858
|
-
*
|
|
1859
|
-
* @return {boolean} `true` if redo is possible
|
|
1860
|
-
*/
|
|
1861
|
-
canRedo() {
|
|
1862
|
-
return this.redoStack.length > 0;
|
|
1863
|
-
}
|
|
1864
|
-
destroy() {
|
|
1865
|
-
this.trackedOrigins.delete(this);
|
|
1866
|
-
this.doc.off("afterTransaction", this.afterTransactionHandler);
|
|
1867
|
-
super.destroy();
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
const updateCurrentAttributes = (currentAttributes, format) => {
|
|
1871
|
-
const { key, value } = format;
|
|
1872
|
-
if (value === null) {
|
|
1873
|
-
currentAttributes.delete(key);
|
|
1874
|
-
} else {
|
|
1875
|
-
currentAttributes.set(key, value);
|
|
1876
|
-
}
|
|
1877
|
-
};
|
|
1878
|
-
const cleanupFormattingGap = (transaction, start2, curr, startAttributes, currAttributes) => {
|
|
1879
|
-
let end = start2;
|
|
1880
|
-
const endFormats = create$4();
|
|
1881
|
-
while (end && (!end.countable || end.deleted)) {
|
|
1882
|
-
if (!end.deleted && end.content.constructor === ContentFormat) {
|
|
1883
|
-
const cf = (
|
|
1884
|
-
/** @type {ContentFormat} */
|
|
1885
|
-
end.content
|
|
1886
|
-
);
|
|
1887
|
-
endFormats.set(cf.key, cf);
|
|
1888
|
-
}
|
|
1889
|
-
end = end.right;
|
|
1890
|
-
}
|
|
1891
|
-
let cleanups = 0;
|
|
1892
|
-
let reachedCurr = false;
|
|
1893
|
-
while (start2 !== end) {
|
|
1894
|
-
if (curr === start2) {
|
|
1895
|
-
reachedCurr = true;
|
|
1896
|
-
}
|
|
1897
|
-
if (!start2.deleted) {
|
|
1898
|
-
const content2 = start2.content;
|
|
1899
|
-
switch (content2.constructor) {
|
|
1900
|
-
case ContentFormat: {
|
|
1901
|
-
const { key, value } = (
|
|
1902
|
-
/** @type {ContentFormat} */
|
|
1903
|
-
content2
|
|
1904
|
-
);
|
|
1905
|
-
const startAttrValue = startAttributes.get(key) || null;
|
|
1906
|
-
if (endFormats.get(key) !== content2 || startAttrValue === value) {
|
|
1907
|
-
start2.delete(transaction);
|
|
1908
|
-
cleanups++;
|
|
1909
|
-
if (!reachedCurr && (currAttributes.get(key) || null) === value && startAttrValue !== value) {
|
|
1910
|
-
if (startAttrValue === null) {
|
|
1911
|
-
currAttributes.delete(key);
|
|
1912
|
-
} else {
|
|
1913
|
-
currAttributes.set(key, startAttrValue);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
if (!reachedCurr && !start2.deleted) {
|
|
1918
|
-
updateCurrentAttributes(
|
|
1919
|
-
currAttributes,
|
|
1920
|
-
/** @type {ContentFormat} */
|
|
1921
|
-
content2
|
|
1922
|
-
);
|
|
1923
|
-
}
|
|
1924
|
-
break;
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
start2 = /** @type {Item} */
|
|
1929
|
-
start2.right;
|
|
1930
|
-
}
|
|
1931
|
-
return cleanups;
|
|
1932
|
-
};
|
|
1933
|
-
const cleanupContextlessFormattingGap = (transaction, item) => {
|
|
1934
|
-
while (item && item.right && (item.right.deleted || !item.right.countable)) {
|
|
1935
|
-
item = item.right;
|
|
1936
|
-
}
|
|
1937
|
-
const attrs = /* @__PURE__ */ new Set();
|
|
1938
|
-
while (item && (item.deleted || !item.countable)) {
|
|
1939
|
-
if (!item.deleted && item.content.constructor === ContentFormat) {
|
|
1940
|
-
const key = (
|
|
1941
|
-
/** @type {ContentFormat} */
|
|
1942
|
-
item.content.key
|
|
1943
|
-
);
|
|
1944
|
-
if (attrs.has(key)) {
|
|
1945
|
-
item.delete(transaction);
|
|
1946
|
-
} else {
|
|
1947
|
-
attrs.add(key);
|
|
1948
|
-
}
|
|
1949
|
-
}
|
|
1950
|
-
item = item.left;
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
const cleanupYTextFormatting = (type) => {
|
|
1954
|
-
let res = 0;
|
|
1955
|
-
transact(
|
|
1956
|
-
/** @type {Doc} */
|
|
1957
|
-
type.doc,
|
|
1958
|
-
(transaction) => {
|
|
1959
|
-
let start2 = (
|
|
1960
|
-
/** @type {Item} */
|
|
1961
|
-
type._start
|
|
1962
|
-
);
|
|
1963
|
-
let end = type._start;
|
|
1964
|
-
let startAttributes = create$4();
|
|
1965
|
-
const currentAttributes = copy(startAttributes);
|
|
1966
|
-
while (end) {
|
|
1967
|
-
if (end.deleted === false) {
|
|
1968
|
-
switch (end.content.constructor) {
|
|
1969
|
-
case ContentFormat:
|
|
1970
|
-
updateCurrentAttributes(
|
|
1971
|
-
currentAttributes,
|
|
1972
|
-
/** @type {ContentFormat} */
|
|
1973
|
-
end.content
|
|
1974
|
-
);
|
|
1975
|
-
break;
|
|
1976
|
-
default:
|
|
1977
|
-
res += cleanupFormattingGap(transaction, start2, end, startAttributes, currentAttributes);
|
|
1978
|
-
startAttributes = copy(currentAttributes);
|
|
1979
|
-
start2 = end;
|
|
1980
|
-
break;
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
end = end.right;
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
);
|
|
1987
|
-
return res;
|
|
1988
|
-
};
|
|
1989
|
-
const cleanupYTextAfterTransaction = (transaction) => {
|
|
1990
|
-
const needFullCleanup = /* @__PURE__ */ new Set();
|
|
1991
|
-
const doc2 = transaction.doc;
|
|
1992
|
-
for (const [client, afterClock] of transaction.afterState.entries()) {
|
|
1993
|
-
const clock = transaction.beforeState.get(client) || 0;
|
|
1994
|
-
if (afterClock === clock) {
|
|
1995
|
-
continue;
|
|
1996
|
-
}
|
|
1997
|
-
iterateStructs(
|
|
1998
|
-
transaction,
|
|
1999
|
-
/** @type {Array<Item|GC>} */
|
|
2000
|
-
doc2.store.clients.get(client),
|
|
2001
|
-
clock,
|
|
2002
|
-
afterClock,
|
|
2003
|
-
(item) => {
|
|
2004
|
-
if (!item.deleted && /** @type {Item} */
|
|
2005
|
-
item.content.constructor === ContentFormat && item.constructor !== GC) {
|
|
2006
|
-
needFullCleanup.add(
|
|
2007
|
-
/** @type {any} */
|
|
2008
|
-
item.parent
|
|
2009
|
-
);
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
);
|
|
2013
|
-
}
|
|
2014
|
-
transact(doc2, (t2) => {
|
|
2015
|
-
iterateDeletedStructs(transaction, transaction.deleteSet, (item) => {
|
|
2016
|
-
if (item instanceof GC || !/** @type {YText} */
|
|
2017
|
-
item.parent._hasFormatting || needFullCleanup.has(
|
|
2018
|
-
/** @type {YText} */
|
|
2019
|
-
item.parent
|
|
2020
|
-
)) {
|
|
2021
|
-
return;
|
|
2022
|
-
}
|
|
2023
|
-
const parent = (
|
|
2024
|
-
/** @type {YText} */
|
|
2025
|
-
item.parent
|
|
2026
|
-
);
|
|
2027
|
-
if (item.content.constructor === ContentFormat) {
|
|
2028
|
-
needFullCleanup.add(parent);
|
|
2029
|
-
} else {
|
|
2030
|
-
cleanupContextlessFormattingGap(t2, item);
|
|
2031
|
-
}
|
|
2032
|
-
});
|
|
2033
|
-
for (const yText of needFullCleanup) {
|
|
2034
|
-
cleanupYTextFormatting(yText);
|
|
2035
|
-
}
|
|
2036
|
-
});
|
|
2037
|
-
};
|
|
2038
|
-
class AbstractStruct {
|
|
2039
|
-
/**
|
|
2040
|
-
* @param {ID} id
|
|
2041
|
-
* @param {number} length
|
|
2042
|
-
*/
|
|
2043
|
-
constructor(id2, length2) {
|
|
2044
|
-
this.id = id2;
|
|
2045
|
-
this.length = length2;
|
|
2046
|
-
}
|
|
2047
|
-
/**
|
|
2048
|
-
* @type {boolean}
|
|
2049
|
-
*/
|
|
2050
|
-
get deleted() {
|
|
2051
|
-
throw methodUnimplemented();
|
|
2052
|
-
}
|
|
2053
|
-
/**
|
|
2054
|
-
* Merge this struct with the item to the right.
|
|
2055
|
-
* This method is already assuming that `this.id.clock + this.length === this.id.clock`.
|
|
2056
|
-
* Also this method does *not* remove right from StructStore!
|
|
2057
|
-
* @param {AbstractStruct} right
|
|
2058
|
-
* @return {boolean} wether this merged with right
|
|
2059
|
-
*/
|
|
2060
|
-
mergeWith(right) {
|
|
2061
|
-
return false;
|
|
2062
|
-
}
|
|
2063
|
-
/**
|
|
2064
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.
|
|
2065
|
-
* @param {number} offset
|
|
2066
|
-
* @param {number} encodingRef
|
|
2067
|
-
*/
|
|
2068
|
-
write(encoder, offset, encodingRef) {
|
|
2069
|
-
throw methodUnimplemented();
|
|
2070
|
-
}
|
|
2071
|
-
/**
|
|
2072
|
-
* @param {Transaction} transaction
|
|
2073
|
-
* @param {number} offset
|
|
2074
|
-
*/
|
|
2075
|
-
integrate(transaction, offset) {
|
|
2076
|
-
throw methodUnimplemented();
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
const structGCRefNumber = 0;
|
|
2080
|
-
class GC extends AbstractStruct {
|
|
2081
|
-
get deleted() {
|
|
2082
|
-
return true;
|
|
2083
|
-
}
|
|
2084
|
-
delete() {
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* @param {GC} right
|
|
2088
|
-
* @return {boolean}
|
|
2089
|
-
*/
|
|
2090
|
-
mergeWith(right) {
|
|
2091
|
-
if (this.constructor !== right.constructor) {
|
|
2092
|
-
return false;
|
|
2093
|
-
}
|
|
2094
|
-
this.length += right.length;
|
|
2095
|
-
return true;
|
|
2096
|
-
}
|
|
2097
|
-
/**
|
|
2098
|
-
* @param {Transaction} transaction
|
|
2099
|
-
* @param {number} offset
|
|
2100
|
-
*/
|
|
2101
|
-
integrate(transaction, offset) {
|
|
2102
|
-
if (offset > 0) {
|
|
2103
|
-
this.id.clock += offset;
|
|
2104
|
-
this.length -= offset;
|
|
2105
|
-
}
|
|
2106
|
-
addStruct(transaction.doc.store, this);
|
|
2107
|
-
}
|
|
2108
|
-
/**
|
|
2109
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
2110
|
-
* @param {number} offset
|
|
2111
|
-
*/
|
|
2112
|
-
write(encoder, offset) {
|
|
2113
|
-
encoder.writeInfo(structGCRefNumber);
|
|
2114
|
-
encoder.writeLen(this.length - offset);
|
|
2115
|
-
}
|
|
2116
|
-
/**
|
|
2117
|
-
* @param {Transaction} transaction
|
|
2118
|
-
* @param {StructStore} store
|
|
2119
|
-
* @return {null | number}
|
|
2120
|
-
*/
|
|
2121
|
-
getMissing(transaction, store) {
|
|
2122
|
-
return null;
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
class ContentDeleted {
|
|
2126
|
-
/**
|
|
2127
|
-
* @param {number} len
|
|
2128
|
-
*/
|
|
2129
|
-
constructor(len) {
|
|
2130
|
-
this.len = len;
|
|
2131
|
-
}
|
|
2132
|
-
/**
|
|
2133
|
-
* @return {number}
|
|
2134
|
-
*/
|
|
2135
|
-
getLength() {
|
|
2136
|
-
return this.len;
|
|
2137
|
-
}
|
|
2138
|
-
/**
|
|
2139
|
-
* @return {Array<any>}
|
|
2140
|
-
*/
|
|
2141
|
-
getContent() {
|
|
2142
|
-
return [];
|
|
2143
|
-
}
|
|
2144
|
-
/**
|
|
2145
|
-
* @return {boolean}
|
|
2146
|
-
*/
|
|
2147
|
-
isCountable() {
|
|
2148
|
-
return false;
|
|
2149
|
-
}
|
|
2150
|
-
/**
|
|
2151
|
-
* @return {ContentDeleted}
|
|
2152
|
-
*/
|
|
2153
|
-
copy() {
|
|
2154
|
-
return new ContentDeleted(this.len);
|
|
2155
|
-
}
|
|
2156
|
-
/**
|
|
2157
|
-
* @param {number} offset
|
|
2158
|
-
* @return {ContentDeleted}
|
|
2159
|
-
*/
|
|
2160
|
-
splice(offset) {
|
|
2161
|
-
const right = new ContentDeleted(this.len - offset);
|
|
2162
|
-
this.len = offset;
|
|
2163
|
-
return right;
|
|
2164
|
-
}
|
|
2165
|
-
/**
|
|
2166
|
-
* @param {ContentDeleted} right
|
|
2167
|
-
* @return {boolean}
|
|
2168
|
-
*/
|
|
2169
|
-
mergeWith(right) {
|
|
2170
|
-
this.len += right.len;
|
|
2171
|
-
return true;
|
|
2172
|
-
}
|
|
2173
|
-
/**
|
|
2174
|
-
* @param {Transaction} transaction
|
|
2175
|
-
* @param {Item} item
|
|
2176
|
-
*/
|
|
2177
|
-
integrate(transaction, item) {
|
|
2178
|
-
addToDeleteSet(transaction.deleteSet, item.id.client, item.id.clock, this.len);
|
|
2179
|
-
item.markDeleted();
|
|
2180
|
-
}
|
|
2181
|
-
/**
|
|
2182
|
-
* @param {Transaction} transaction
|
|
2183
|
-
*/
|
|
2184
|
-
delete(transaction) {
|
|
2185
|
-
}
|
|
2186
|
-
/**
|
|
2187
|
-
* @param {StructStore} store
|
|
2188
|
-
*/
|
|
2189
|
-
gc(store) {
|
|
2190
|
-
}
|
|
2191
|
-
/**
|
|
2192
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
2193
|
-
* @param {number} offset
|
|
2194
|
-
*/
|
|
2195
|
-
write(encoder, offset) {
|
|
2196
|
-
encoder.writeLen(this.len - offset);
|
|
2197
|
-
}
|
|
2198
|
-
/**
|
|
2199
|
-
* @return {number}
|
|
2200
|
-
*/
|
|
2201
|
-
getRef() {
|
|
2202
|
-
return 1;
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
class ContentFormat {
|
|
2206
|
-
/**
|
|
2207
|
-
* @param {string} key
|
|
2208
|
-
* @param {Object} value
|
|
2209
|
-
*/
|
|
2210
|
-
constructor(key, value) {
|
|
2211
|
-
this.key = key;
|
|
2212
|
-
this.value = value;
|
|
2213
|
-
}
|
|
2214
|
-
/**
|
|
2215
|
-
* @return {number}
|
|
2216
|
-
*/
|
|
2217
|
-
getLength() {
|
|
2218
|
-
return 1;
|
|
2219
|
-
}
|
|
2220
|
-
/**
|
|
2221
|
-
* @return {Array<any>}
|
|
2222
|
-
*/
|
|
2223
|
-
getContent() {
|
|
2224
|
-
return [];
|
|
2225
|
-
}
|
|
2226
|
-
/**
|
|
2227
|
-
* @return {boolean}
|
|
2228
|
-
*/
|
|
2229
|
-
isCountable() {
|
|
2230
|
-
return false;
|
|
2231
|
-
}
|
|
2232
|
-
/**
|
|
2233
|
-
* @return {ContentFormat}
|
|
2234
|
-
*/
|
|
2235
|
-
copy() {
|
|
2236
|
-
return new ContentFormat(this.key, this.value);
|
|
2237
|
-
}
|
|
2238
|
-
/**
|
|
2239
|
-
* @param {number} _offset
|
|
2240
|
-
* @return {ContentFormat}
|
|
2241
|
-
*/
|
|
2242
|
-
splice(_offset) {
|
|
2243
|
-
throw methodUnimplemented();
|
|
2244
|
-
}
|
|
2245
|
-
/**
|
|
2246
|
-
* @param {ContentFormat} _right
|
|
2247
|
-
* @return {boolean}
|
|
2248
|
-
*/
|
|
2249
|
-
mergeWith(_right) {
|
|
2250
|
-
return false;
|
|
2251
|
-
}
|
|
2252
|
-
/**
|
|
2253
|
-
* @param {Transaction} _transaction
|
|
2254
|
-
* @param {Item} item
|
|
2255
|
-
*/
|
|
2256
|
-
integrate(_transaction, item) {
|
|
2257
|
-
const p = (
|
|
2258
|
-
/** @type {YText} */
|
|
2259
|
-
item.parent
|
|
2260
|
-
);
|
|
2261
|
-
p._searchMarker = null;
|
|
2262
|
-
p._hasFormatting = true;
|
|
2263
|
-
}
|
|
2264
|
-
/**
|
|
2265
|
-
* @param {Transaction} transaction
|
|
2266
|
-
*/
|
|
2267
|
-
delete(transaction) {
|
|
2268
|
-
}
|
|
2269
|
-
/**
|
|
2270
|
-
* @param {StructStore} store
|
|
2271
|
-
*/
|
|
2272
|
-
gc(store) {
|
|
2273
|
-
}
|
|
2274
|
-
/**
|
|
2275
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
2276
|
-
* @param {number} offset
|
|
2277
|
-
*/
|
|
2278
|
-
write(encoder, offset) {
|
|
2279
|
-
encoder.writeKey(this.key);
|
|
2280
|
-
encoder.writeJSON(this.value);
|
|
2281
|
-
}
|
|
2282
|
-
/**
|
|
2283
|
-
* @return {number}
|
|
2284
|
-
*/
|
|
2285
|
-
getRef() {
|
|
2286
|
-
return 6;
|
|
2287
|
-
}
|
|
2288
|
-
}
|
|
2289
|
-
class ContentType {
|
|
2290
|
-
/**
|
|
2291
|
-
* @param {AbstractType<any>} type
|
|
2292
|
-
*/
|
|
2293
|
-
constructor(type) {
|
|
2294
|
-
this.type = type;
|
|
2295
|
-
}
|
|
2296
|
-
/**
|
|
2297
|
-
* @return {number}
|
|
2298
|
-
*/
|
|
2299
|
-
getLength() {
|
|
2300
|
-
return 1;
|
|
2301
|
-
}
|
|
2302
|
-
/**
|
|
2303
|
-
* @return {Array<any>}
|
|
2304
|
-
*/
|
|
2305
|
-
getContent() {
|
|
2306
|
-
return [this.type];
|
|
2307
|
-
}
|
|
2308
|
-
/**
|
|
2309
|
-
* @return {boolean}
|
|
2310
|
-
*/
|
|
2311
|
-
isCountable() {
|
|
2312
|
-
return true;
|
|
2313
|
-
}
|
|
2314
|
-
/**
|
|
2315
|
-
* @return {ContentType}
|
|
2316
|
-
*/
|
|
2317
|
-
copy() {
|
|
2318
|
-
return new ContentType(this.type._copy());
|
|
2319
|
-
}
|
|
2320
|
-
/**
|
|
2321
|
-
* @param {number} offset
|
|
2322
|
-
* @return {ContentType}
|
|
2323
|
-
*/
|
|
2324
|
-
splice(offset) {
|
|
2325
|
-
throw methodUnimplemented();
|
|
2326
|
-
}
|
|
2327
|
-
/**
|
|
2328
|
-
* @param {ContentType} right
|
|
2329
|
-
* @return {boolean}
|
|
2330
|
-
*/
|
|
2331
|
-
mergeWith(right) {
|
|
2332
|
-
return false;
|
|
2333
|
-
}
|
|
2334
|
-
/**
|
|
2335
|
-
* @param {Transaction} transaction
|
|
2336
|
-
* @param {Item} item
|
|
2337
|
-
*/
|
|
2338
|
-
integrate(transaction, item) {
|
|
2339
|
-
this.type._integrate(transaction.doc, item);
|
|
2340
|
-
}
|
|
2341
|
-
/**
|
|
2342
|
-
* @param {Transaction} transaction
|
|
2343
|
-
*/
|
|
2344
|
-
delete(transaction) {
|
|
2345
|
-
let item = this.type._start;
|
|
2346
|
-
while (item !== null) {
|
|
2347
|
-
if (!item.deleted) {
|
|
2348
|
-
item.delete(transaction);
|
|
2349
|
-
} else if (item.id.clock < (transaction.beforeState.get(item.id.client) || 0)) {
|
|
2350
|
-
transaction._mergeStructs.push(item);
|
|
2351
|
-
}
|
|
2352
|
-
item = item.right;
|
|
2353
|
-
}
|
|
2354
|
-
this.type._map.forEach((item2) => {
|
|
2355
|
-
if (!item2.deleted) {
|
|
2356
|
-
item2.delete(transaction);
|
|
2357
|
-
} else if (item2.id.clock < (transaction.beforeState.get(item2.id.client) || 0)) {
|
|
2358
|
-
transaction._mergeStructs.push(item2);
|
|
2359
|
-
}
|
|
2360
|
-
});
|
|
2361
|
-
transaction.changed.delete(this.type);
|
|
2362
|
-
}
|
|
2363
|
-
/**
|
|
2364
|
-
* @param {StructStore} store
|
|
2365
|
-
*/
|
|
2366
|
-
gc(store) {
|
|
2367
|
-
let item = this.type._start;
|
|
2368
|
-
while (item !== null) {
|
|
2369
|
-
item.gc(store, true);
|
|
2370
|
-
item = item.right;
|
|
2371
|
-
}
|
|
2372
|
-
this.type._start = null;
|
|
2373
|
-
this.type._map.forEach(
|
|
2374
|
-
/** @param {Item | null} item */
|
|
2375
|
-
(item2) => {
|
|
2376
|
-
while (item2 !== null) {
|
|
2377
|
-
item2.gc(store, true);
|
|
2378
|
-
item2 = item2.left;
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
);
|
|
2382
|
-
this.type._map = /* @__PURE__ */ new Map();
|
|
2383
|
-
}
|
|
2384
|
-
/**
|
|
2385
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
2386
|
-
* @param {number} offset
|
|
2387
|
-
*/
|
|
2388
|
-
write(encoder, offset) {
|
|
2389
|
-
this.type._write(encoder);
|
|
2390
|
-
}
|
|
2391
|
-
/**
|
|
2392
|
-
* @return {number}
|
|
2393
|
-
*/
|
|
2394
|
-
getRef() {
|
|
2395
|
-
return 7;
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
const followRedone = (store, id2) => {
|
|
2399
|
-
let nextID2 = id2;
|
|
2400
|
-
let diff = 0;
|
|
2401
|
-
let item;
|
|
2402
|
-
do {
|
|
2403
|
-
if (diff > 0) {
|
|
2404
|
-
nextID2 = createID(nextID2.client, nextID2.clock + diff);
|
|
2405
|
-
}
|
|
2406
|
-
item = getItem(store, nextID2);
|
|
2407
|
-
diff = nextID2.clock - item.id.clock;
|
|
2408
|
-
nextID2 = item.redone;
|
|
2409
|
-
} while (nextID2 !== null && item instanceof Item);
|
|
2410
|
-
return {
|
|
2411
|
-
item,
|
|
2412
|
-
diff
|
|
2413
|
-
};
|
|
2414
|
-
};
|
|
2415
|
-
const keepItem = (item, keep) => {
|
|
2416
|
-
while (item !== null && item.keep !== keep) {
|
|
2417
|
-
item.keep = keep;
|
|
2418
|
-
item = /** @type {AbstractType<any>} */
|
|
2419
|
-
item.parent._item;
|
|
2420
|
-
}
|
|
2421
|
-
};
|
|
2422
|
-
const splitItem = (transaction, leftItem, diff) => {
|
|
2423
|
-
const { client, clock } = leftItem.id;
|
|
2424
|
-
const rightItem = new Item(
|
|
2425
|
-
createID(client, clock + diff),
|
|
2426
|
-
leftItem,
|
|
2427
|
-
createID(client, clock + diff - 1),
|
|
2428
|
-
leftItem.right,
|
|
2429
|
-
leftItem.rightOrigin,
|
|
2430
|
-
leftItem.parent,
|
|
2431
|
-
leftItem.parentSub,
|
|
2432
|
-
leftItem.content.splice(diff)
|
|
2433
|
-
);
|
|
2434
|
-
if (leftItem.deleted) {
|
|
2435
|
-
rightItem.markDeleted();
|
|
2436
|
-
}
|
|
2437
|
-
if (leftItem.keep) {
|
|
2438
|
-
rightItem.keep = true;
|
|
2439
|
-
}
|
|
2440
|
-
if (leftItem.redone !== null) {
|
|
2441
|
-
rightItem.redone = createID(leftItem.redone.client, leftItem.redone.clock + diff);
|
|
2442
|
-
}
|
|
2443
|
-
leftItem.right = rightItem;
|
|
2444
|
-
if (rightItem.right !== null) {
|
|
2445
|
-
rightItem.right.left = rightItem;
|
|
2446
|
-
}
|
|
2447
|
-
transaction._mergeStructs.push(rightItem);
|
|
2448
|
-
if (rightItem.parentSub !== null && rightItem.right === null) {
|
|
2449
|
-
rightItem.parent._map.set(rightItem.parentSub, rightItem);
|
|
2450
|
-
}
|
|
2451
|
-
leftItem.length = diff;
|
|
2452
|
-
return rightItem;
|
|
2453
|
-
};
|
|
2454
|
-
const isDeletedByUndoStack = (stack, id2) => some(
|
|
2455
|
-
stack,
|
|
2456
|
-
/** @param {StackItem} s */
|
|
2457
|
-
(s) => isDeleted(s.deletions, id2)
|
|
2458
|
-
);
|
|
2459
|
-
const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) => {
|
|
2460
|
-
const doc2 = transaction.doc;
|
|
2461
|
-
const store = doc2.store;
|
|
2462
|
-
const ownClientID = doc2.clientID;
|
|
2463
|
-
const redone = item.redone;
|
|
2464
|
-
if (redone !== null) {
|
|
2465
|
-
return getItemCleanStart(transaction, redone);
|
|
2466
|
-
}
|
|
2467
|
-
let parentItem = (
|
|
2468
|
-
/** @type {AbstractType<any>} */
|
|
2469
|
-
item.parent._item
|
|
2470
|
-
);
|
|
2471
|
-
let left = null;
|
|
2472
|
-
let right;
|
|
2473
|
-
if (parentItem !== null && parentItem.deleted === true) {
|
|
2474
|
-
if (parentItem.redone === null && (!redoitems.has(parentItem) || redoItem(transaction, parentItem, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) === null)) {
|
|
2475
|
-
return null;
|
|
2476
|
-
}
|
|
2477
|
-
while (parentItem.redone !== null) {
|
|
2478
|
-
parentItem = getItemCleanStart(transaction, parentItem.redone);
|
|
2479
|
-
}
|
|
2480
|
-
}
|
|
2481
|
-
const parentType = parentItem === null ? (
|
|
2482
|
-
/** @type {AbstractType<any>} */
|
|
2483
|
-
item.parent
|
|
2484
|
-
) : (
|
|
2485
|
-
/** @type {ContentType} */
|
|
2486
|
-
parentItem.content.type
|
|
2487
|
-
);
|
|
2488
|
-
if (item.parentSub === null) {
|
|
2489
|
-
left = item.left;
|
|
2490
|
-
right = item;
|
|
2491
|
-
while (left !== null) {
|
|
2492
|
-
let leftTrace = left;
|
|
2493
|
-
while (leftTrace !== null && /** @type {AbstractType<any>} */
|
|
2494
|
-
leftTrace.parent._item !== parentItem) {
|
|
2495
|
-
leftTrace = leftTrace.redone === null ? null : getItemCleanStart(transaction, leftTrace.redone);
|
|
2496
|
-
}
|
|
2497
|
-
if (leftTrace !== null && /** @type {AbstractType<any>} */
|
|
2498
|
-
leftTrace.parent._item === parentItem) {
|
|
2499
|
-
left = leftTrace;
|
|
2500
|
-
break;
|
|
2501
|
-
}
|
|
2502
|
-
left = left.left;
|
|
2503
|
-
}
|
|
2504
|
-
while (right !== null) {
|
|
2505
|
-
let rightTrace = right;
|
|
2506
|
-
while (rightTrace !== null && /** @type {AbstractType<any>} */
|
|
2507
|
-
rightTrace.parent._item !== parentItem) {
|
|
2508
|
-
rightTrace = rightTrace.redone === null ? null : getItemCleanStart(transaction, rightTrace.redone);
|
|
2509
|
-
}
|
|
2510
|
-
if (rightTrace !== null && /** @type {AbstractType<any>} */
|
|
2511
|
-
rightTrace.parent._item === parentItem) {
|
|
2512
|
-
right = rightTrace;
|
|
2513
|
-
break;
|
|
2514
|
-
}
|
|
2515
|
-
right = right.right;
|
|
2516
|
-
}
|
|
2517
|
-
} else {
|
|
2518
|
-
right = null;
|
|
2519
|
-
if (item.right && !ignoreRemoteMapChanges) {
|
|
2520
|
-
left = item;
|
|
2521
|
-
while (left !== null && left.right !== null && (left.right.redone || isDeleted(itemsToDelete, left.right.id) || isDeletedByUndoStack(um.undoStack, left.right.id) || isDeletedByUndoStack(um.redoStack, left.right.id))) {
|
|
2522
|
-
left = left.right;
|
|
2523
|
-
while (left.redone)
|
|
2524
|
-
left = getItemCleanStart(transaction, left.redone);
|
|
2525
|
-
}
|
|
2526
|
-
if (left && left.right !== null) {
|
|
2527
|
-
return null;
|
|
2528
|
-
}
|
|
2529
|
-
} else {
|
|
2530
|
-
left = parentType._map.get(item.parentSub) || null;
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
const nextClock = getState(store, ownClientID);
|
|
2534
|
-
const nextId = createID(ownClientID, nextClock);
|
|
2535
|
-
const redoneItem = new Item(
|
|
2536
|
-
nextId,
|
|
2537
|
-
left,
|
|
2538
|
-
left && left.lastId,
|
|
2539
|
-
right,
|
|
2540
|
-
right && right.id,
|
|
2541
|
-
parentType,
|
|
2542
|
-
item.parentSub,
|
|
2543
|
-
item.content.copy()
|
|
2544
|
-
);
|
|
2545
|
-
item.redone = nextId;
|
|
2546
|
-
keepItem(redoneItem, true);
|
|
2547
|
-
redoneItem.integrate(transaction, 0);
|
|
2548
|
-
return redoneItem;
|
|
2549
|
-
};
|
|
2550
|
-
class Item extends AbstractStruct {
|
|
2551
|
-
/**
|
|
2552
|
-
* @param {ID} id
|
|
2553
|
-
* @param {Item | null} left
|
|
2554
|
-
* @param {ID | null} origin
|
|
2555
|
-
* @param {Item | null} right
|
|
2556
|
-
* @param {ID | null} rightOrigin
|
|
2557
|
-
* @param {AbstractType<any>|ID|null} parent Is a type if integrated, is null if it is possible to copy parent from left or right, is ID before integration to search for it.
|
|
2558
|
-
* @param {string | null} parentSub
|
|
2559
|
-
* @param {AbstractContent} content
|
|
2560
|
-
*/
|
|
2561
|
-
constructor(id2, left, origin, right, rightOrigin, parent, parentSub, content2) {
|
|
2562
|
-
super(id2, content2.getLength());
|
|
2563
|
-
this.origin = origin;
|
|
2564
|
-
this.left = left;
|
|
2565
|
-
this.right = right;
|
|
2566
|
-
this.rightOrigin = rightOrigin;
|
|
2567
|
-
this.parent = parent;
|
|
2568
|
-
this.parentSub = parentSub;
|
|
2569
|
-
this.redone = null;
|
|
2570
|
-
this.content = content2;
|
|
2571
|
-
this.info = this.content.isCountable() ? BIT2 : 0;
|
|
2572
|
-
}
|
|
2573
|
-
/**
|
|
2574
|
-
* This is used to mark the item as an indexed fast-search marker
|
|
2575
|
-
*
|
|
2576
|
-
* @type {boolean}
|
|
2577
|
-
*/
|
|
2578
|
-
set marker(isMarked) {
|
|
2579
|
-
if ((this.info & BIT4) > 0 !== isMarked) {
|
|
2580
|
-
this.info ^= BIT4;
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
get marker() {
|
|
2584
|
-
return (this.info & BIT4) > 0;
|
|
2585
|
-
}
|
|
2586
|
-
/**
|
|
2587
|
-
* If true, do not garbage collect this Item.
|
|
2588
|
-
*/
|
|
2589
|
-
get keep() {
|
|
2590
|
-
return (this.info & BIT1) > 0;
|
|
2591
|
-
}
|
|
2592
|
-
set keep(doKeep) {
|
|
2593
|
-
if (this.keep !== doKeep) {
|
|
2594
|
-
this.info ^= BIT1;
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
|
-
get countable() {
|
|
2598
|
-
return (this.info & BIT2) > 0;
|
|
2599
|
-
}
|
|
2600
|
-
/**
|
|
2601
|
-
* Whether this item was deleted or not.
|
|
2602
|
-
* @type {Boolean}
|
|
2603
|
-
*/
|
|
2604
|
-
get deleted() {
|
|
2605
|
-
return (this.info & BIT3) > 0;
|
|
2606
|
-
}
|
|
2607
|
-
set deleted(doDelete) {
|
|
2608
|
-
if (this.deleted !== doDelete) {
|
|
2609
|
-
this.info ^= BIT3;
|
|
2610
|
-
}
|
|
2611
|
-
}
|
|
2612
|
-
markDeleted() {
|
|
2613
|
-
this.info |= BIT3;
|
|
2614
|
-
}
|
|
2615
|
-
/**
|
|
2616
|
-
* Return the creator clientID of the missing op or define missing items and return null.
|
|
2617
|
-
*
|
|
2618
|
-
* @param {Transaction} transaction
|
|
2619
|
-
* @param {StructStore} store
|
|
2620
|
-
* @return {null | number}
|
|
2621
|
-
*/
|
|
2622
|
-
getMissing(transaction, store) {
|
|
2623
|
-
if (this.origin && this.origin.client !== this.id.client && this.origin.clock >= getState(store, this.origin.client)) {
|
|
2624
|
-
return this.origin.client;
|
|
2625
|
-
}
|
|
2626
|
-
if (this.rightOrigin && this.rightOrigin.client !== this.id.client && this.rightOrigin.clock >= getState(store, this.rightOrigin.client)) {
|
|
2627
|
-
return this.rightOrigin.client;
|
|
2628
|
-
}
|
|
2629
|
-
if (this.parent && this.parent.constructor === ID && this.id.client !== this.parent.client && this.parent.clock >= getState(store, this.parent.client)) {
|
|
2630
|
-
return this.parent.client;
|
|
2631
|
-
}
|
|
2632
|
-
if (this.origin) {
|
|
2633
|
-
this.left = getItemCleanEnd(transaction, store, this.origin);
|
|
2634
|
-
this.origin = this.left.lastId;
|
|
2635
|
-
}
|
|
2636
|
-
if (this.rightOrigin) {
|
|
2637
|
-
this.right = getItemCleanStart(transaction, this.rightOrigin);
|
|
2638
|
-
this.rightOrigin = this.right.id;
|
|
2639
|
-
}
|
|
2640
|
-
if (this.left && this.left.constructor === GC || this.right && this.right.constructor === GC) {
|
|
2641
|
-
this.parent = null;
|
|
2642
|
-
} else if (!this.parent) {
|
|
2643
|
-
if (this.left && this.left.constructor === Item) {
|
|
2644
|
-
this.parent = this.left.parent;
|
|
2645
|
-
this.parentSub = this.left.parentSub;
|
|
2646
|
-
}
|
|
2647
|
-
if (this.right && this.right.constructor === Item) {
|
|
2648
|
-
this.parent = this.right.parent;
|
|
2649
|
-
this.parentSub = this.right.parentSub;
|
|
2650
|
-
}
|
|
2651
|
-
} else if (this.parent.constructor === ID) {
|
|
2652
|
-
const parentItem = getItem(store, this.parent);
|
|
2653
|
-
if (parentItem.constructor === GC) {
|
|
2654
|
-
this.parent = null;
|
|
2655
|
-
} else {
|
|
2656
|
-
this.parent = /** @type {ContentType} */
|
|
2657
|
-
parentItem.content.type;
|
|
2658
|
-
}
|
|
2659
|
-
}
|
|
2660
|
-
return null;
|
|
2661
|
-
}
|
|
2662
|
-
/**
|
|
2663
|
-
* @param {Transaction} transaction
|
|
2664
|
-
* @param {number} offset
|
|
2665
|
-
*/
|
|
2666
|
-
integrate(transaction, offset) {
|
|
2667
|
-
if (offset > 0) {
|
|
2668
|
-
this.id.clock += offset;
|
|
2669
|
-
this.left = getItemCleanEnd(transaction, transaction.doc.store, createID(this.id.client, this.id.clock - 1));
|
|
2670
|
-
this.origin = this.left.lastId;
|
|
2671
|
-
this.content = this.content.splice(offset);
|
|
2672
|
-
this.length -= offset;
|
|
2673
|
-
}
|
|
2674
|
-
if (this.parent) {
|
|
2675
|
-
if (!this.left && (!this.right || this.right.left !== null) || this.left && this.left.right !== this.right) {
|
|
2676
|
-
let left = this.left;
|
|
2677
|
-
let o;
|
|
2678
|
-
if (left !== null) {
|
|
2679
|
-
o = left.right;
|
|
2680
|
-
} else if (this.parentSub !== null) {
|
|
2681
|
-
o = /** @type {AbstractType<any>} */
|
|
2682
|
-
this.parent._map.get(this.parentSub) || null;
|
|
2683
|
-
while (o !== null && o.left !== null) {
|
|
2684
|
-
o = o.left;
|
|
2685
|
-
}
|
|
2686
|
-
} else {
|
|
2687
|
-
o = /** @type {AbstractType<any>} */
|
|
2688
|
-
this.parent._start;
|
|
2689
|
-
}
|
|
2690
|
-
const conflictingItems = /* @__PURE__ */ new Set();
|
|
2691
|
-
const itemsBeforeOrigin = /* @__PURE__ */ new Set();
|
|
2692
|
-
while (o !== null && o !== this.right) {
|
|
2693
|
-
itemsBeforeOrigin.add(o);
|
|
2694
|
-
conflictingItems.add(o);
|
|
2695
|
-
if (compareIDs(this.origin, o.origin)) {
|
|
2696
|
-
if (o.id.client < this.id.client) {
|
|
2697
|
-
left = o;
|
|
2698
|
-
conflictingItems.clear();
|
|
2699
|
-
} else if (compareIDs(this.rightOrigin, o.rightOrigin)) {
|
|
2700
|
-
break;
|
|
2701
|
-
}
|
|
2702
|
-
} else if (o.origin !== null && itemsBeforeOrigin.has(getItem(transaction.doc.store, o.origin))) {
|
|
2703
|
-
if (!conflictingItems.has(getItem(transaction.doc.store, o.origin))) {
|
|
2704
|
-
left = o;
|
|
2705
|
-
conflictingItems.clear();
|
|
2706
|
-
}
|
|
2707
|
-
} else {
|
|
2708
|
-
break;
|
|
2709
|
-
}
|
|
2710
|
-
o = o.right;
|
|
2711
|
-
}
|
|
2712
|
-
this.left = left;
|
|
2713
|
-
}
|
|
2714
|
-
if (this.left !== null) {
|
|
2715
|
-
const right = this.left.right;
|
|
2716
|
-
this.right = right;
|
|
2717
|
-
this.left.right = this;
|
|
2718
|
-
} else {
|
|
2719
|
-
let r2;
|
|
2720
|
-
if (this.parentSub !== null) {
|
|
2721
|
-
r2 = /** @type {AbstractType<any>} */
|
|
2722
|
-
this.parent._map.get(this.parentSub) || null;
|
|
2723
|
-
while (r2 !== null && r2.left !== null) {
|
|
2724
|
-
r2 = r2.left;
|
|
2725
|
-
}
|
|
2726
|
-
} else {
|
|
2727
|
-
r2 = /** @type {AbstractType<any>} */
|
|
2728
|
-
this.parent._start;
|
|
2729
|
-
this.parent._start = this;
|
|
2730
|
-
}
|
|
2731
|
-
this.right = r2;
|
|
2732
|
-
}
|
|
2733
|
-
if (this.right !== null) {
|
|
2734
|
-
this.right.left = this;
|
|
2735
|
-
} else if (this.parentSub !== null) {
|
|
2736
|
-
this.parent._map.set(this.parentSub, this);
|
|
2737
|
-
if (this.left !== null) {
|
|
2738
|
-
this.left.delete(transaction);
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
if (this.parentSub === null && this.countable && !this.deleted) {
|
|
2742
|
-
this.parent._length += this.length;
|
|
2743
|
-
}
|
|
2744
|
-
addStruct(transaction.doc.store, this);
|
|
2745
|
-
this.content.integrate(transaction, this);
|
|
2746
|
-
addChangedTypeToTransaction(
|
|
2747
|
-
transaction,
|
|
2748
|
-
/** @type {AbstractType<any>} */
|
|
2749
|
-
this.parent,
|
|
2750
|
-
this.parentSub
|
|
2751
|
-
);
|
|
2752
|
-
if (
|
|
2753
|
-
/** @type {AbstractType<any>} */
|
|
2754
|
-
this.parent._item !== null && /** @type {AbstractType<any>} */
|
|
2755
|
-
this.parent._item.deleted || this.parentSub !== null && this.right !== null
|
|
2756
|
-
) {
|
|
2757
|
-
this.delete(transaction);
|
|
2758
|
-
}
|
|
2759
|
-
} else {
|
|
2760
|
-
new GC(this.id, this.length).integrate(transaction, 0);
|
|
2761
|
-
}
|
|
2762
|
-
}
|
|
2763
|
-
/**
|
|
2764
|
-
* Returns the next non-deleted item
|
|
2765
|
-
*/
|
|
2766
|
-
get next() {
|
|
2767
|
-
let n = this.right;
|
|
2768
|
-
while (n !== null && n.deleted) {
|
|
2769
|
-
n = n.right;
|
|
2770
|
-
}
|
|
2771
|
-
return n;
|
|
2772
|
-
}
|
|
2773
|
-
/**
|
|
2774
|
-
* Returns the previous non-deleted item
|
|
2775
|
-
*/
|
|
2776
|
-
get prev() {
|
|
2777
|
-
let n = this.left;
|
|
2778
|
-
while (n !== null && n.deleted) {
|
|
2779
|
-
n = n.left;
|
|
2780
|
-
}
|
|
2781
|
-
return n;
|
|
2782
|
-
}
|
|
2783
|
-
/**
|
|
2784
|
-
* Computes the last content address of this Item.
|
|
2785
|
-
*/
|
|
2786
|
-
get lastId() {
|
|
2787
|
-
return this.length === 1 ? this.id : createID(this.id.client, this.id.clock + this.length - 1);
|
|
2788
|
-
}
|
|
2789
|
-
/**
|
|
2790
|
-
* Try to merge two items
|
|
2791
|
-
*
|
|
2792
|
-
* @param {Item} right
|
|
2793
|
-
* @return {boolean}
|
|
2794
|
-
*/
|
|
2795
|
-
mergeWith(right) {
|
|
2796
|
-
if (this.constructor === right.constructor && compareIDs(right.origin, this.lastId) && this.right === right && compareIDs(this.rightOrigin, right.rightOrigin) && this.id.client === right.id.client && this.id.clock + this.length === right.id.clock && this.deleted === right.deleted && this.redone === null && right.redone === null && this.content.constructor === right.content.constructor && this.content.mergeWith(right.content)) {
|
|
2797
|
-
const searchMarker = (
|
|
2798
|
-
/** @type {AbstractType<any>} */
|
|
2799
|
-
this.parent._searchMarker
|
|
2800
|
-
);
|
|
2801
|
-
if (searchMarker) {
|
|
2802
|
-
searchMarker.forEach((marker) => {
|
|
2803
|
-
if (marker.p === right) {
|
|
2804
|
-
marker.p = this;
|
|
2805
|
-
if (!this.deleted && this.countable) {
|
|
2806
|
-
marker.index -= this.length;
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
});
|
|
2810
|
-
}
|
|
2811
|
-
if (right.keep) {
|
|
2812
|
-
this.keep = true;
|
|
2813
|
-
}
|
|
2814
|
-
this.right = right.right;
|
|
2815
|
-
if (this.right !== null) {
|
|
2816
|
-
this.right.left = this;
|
|
2817
|
-
}
|
|
2818
|
-
this.length += right.length;
|
|
2819
|
-
return true;
|
|
2820
|
-
}
|
|
2821
|
-
return false;
|
|
2822
|
-
}
|
|
2823
|
-
/**
|
|
2824
|
-
* Mark this Item as deleted.
|
|
2825
|
-
*
|
|
2826
|
-
* @param {Transaction} transaction
|
|
2827
|
-
*/
|
|
2828
|
-
delete(transaction) {
|
|
2829
|
-
if (!this.deleted) {
|
|
2830
|
-
const parent = (
|
|
2831
|
-
/** @type {AbstractType<any>} */
|
|
2832
|
-
this.parent
|
|
2833
|
-
);
|
|
2834
|
-
if (this.countable && this.parentSub === null) {
|
|
2835
|
-
parent._length -= this.length;
|
|
2836
|
-
}
|
|
2837
|
-
this.markDeleted();
|
|
2838
|
-
addToDeleteSet(transaction.deleteSet, this.id.client, this.id.clock, this.length);
|
|
2839
|
-
addChangedTypeToTransaction(transaction, parent, this.parentSub);
|
|
2840
|
-
this.content.delete(transaction);
|
|
2841
|
-
}
|
|
2842
|
-
}
|
|
2843
|
-
/**
|
|
2844
|
-
* @param {StructStore} store
|
|
2845
|
-
* @param {boolean} parentGCd
|
|
2846
|
-
*/
|
|
2847
|
-
gc(store, parentGCd) {
|
|
2848
|
-
if (!this.deleted) {
|
|
2849
|
-
throw unexpectedCase();
|
|
2850
|
-
}
|
|
2851
|
-
this.content.gc(store);
|
|
2852
|
-
if (parentGCd) {
|
|
2853
|
-
replaceStruct(store, this, new GC(this.id, this.length));
|
|
2854
|
-
} else {
|
|
2855
|
-
this.content = new ContentDeleted(this.length);
|
|
2856
|
-
}
|
|
2857
|
-
}
|
|
2858
|
-
/**
|
|
2859
|
-
* Transform the properties of this type to binary and write it to an
|
|
2860
|
-
* BinaryEncoder.
|
|
2861
|
-
*
|
|
2862
|
-
* This is called when this Item is sent to a remote peer.
|
|
2863
|
-
*
|
|
2864
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.
|
|
2865
|
-
* @param {number} offset
|
|
2866
|
-
*/
|
|
2867
|
-
write(encoder, offset) {
|
|
2868
|
-
const origin = offset > 0 ? createID(this.id.client, this.id.clock + offset - 1) : this.origin;
|
|
2869
|
-
const rightOrigin = this.rightOrigin;
|
|
2870
|
-
const parentSub = this.parentSub;
|
|
2871
|
-
const info = this.content.getRef() & BITS5 | (origin === null ? 0 : BIT8) | // origin is defined
|
|
2872
|
-
(rightOrigin === null ? 0 : BIT7) | // right origin is defined
|
|
2873
|
-
(parentSub === null ? 0 : BIT6);
|
|
2874
|
-
encoder.writeInfo(info);
|
|
2875
|
-
if (origin !== null) {
|
|
2876
|
-
encoder.writeLeftID(origin);
|
|
2877
|
-
}
|
|
2878
|
-
if (rightOrigin !== null) {
|
|
2879
|
-
encoder.writeRightID(rightOrigin);
|
|
2880
|
-
}
|
|
2881
|
-
if (origin === null && rightOrigin === null) {
|
|
2882
|
-
const parent = (
|
|
2883
|
-
/** @type {AbstractType<any>} */
|
|
2884
|
-
this.parent
|
|
2885
|
-
);
|
|
2886
|
-
if (parent._item !== void 0) {
|
|
2887
|
-
const parentItem = parent._item;
|
|
2888
|
-
if (parentItem === null) {
|
|
2889
|
-
const ykey = findRootTypeKey(parent);
|
|
2890
|
-
encoder.writeParentInfo(true);
|
|
2891
|
-
encoder.writeString(ykey);
|
|
2892
|
-
} else {
|
|
2893
|
-
encoder.writeParentInfo(false);
|
|
2894
|
-
encoder.writeLeftID(parentItem.id);
|
|
2895
|
-
}
|
|
2896
|
-
} else if (parent.constructor === String) {
|
|
2897
|
-
encoder.writeParentInfo(true);
|
|
2898
|
-
encoder.writeString(parent);
|
|
2899
|
-
} else if (parent.constructor === ID) {
|
|
2900
|
-
encoder.writeParentInfo(false);
|
|
2901
|
-
encoder.writeLeftID(parent);
|
|
2902
|
-
} else {
|
|
2903
|
-
unexpectedCase();
|
|
2904
|
-
}
|
|
2905
|
-
if (parentSub !== null) {
|
|
2906
|
-
encoder.writeString(parentSub);
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
2909
|
-
this.content.write(encoder, offset);
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
const glo = (
|
|
2913
|
-
/** @type {any} */
|
|
2914
|
-
typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {}
|
|
2915
|
-
);
|
|
2916
|
-
const importIdentifier = "__ $YJS$ __";
|
|
2917
|
-
if (glo[importIdentifier] === true) {
|
|
2918
|
-
console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");
|
|
2919
|
-
}
|
|
2920
|
-
glo[importIdentifier] = true;
|
|
2921
9
|
class Text {
|
|
2922
10
|
/**
|
|
2923
11
|
Get the line description around the given position.
|
|
@@ -3068,10 +156,10 @@ class Text {
|
|
|
3068
156
|
}
|
|
3069
157
|
}
|
|
3070
158
|
class TextLeaf extends Text {
|
|
3071
|
-
constructor(text2,
|
|
159
|
+
constructor(text2, length = textLength(text2)) {
|
|
3072
160
|
super();
|
|
3073
161
|
this.text = text2;
|
|
3074
|
-
this.length =
|
|
162
|
+
this.length = length;
|
|
3075
163
|
}
|
|
3076
164
|
get lines() {
|
|
3077
165
|
return this.text.length;
|
|
@@ -3150,10 +238,10 @@ class TextLeaf extends Text {
|
|
|
3150
238
|
}
|
|
3151
239
|
}
|
|
3152
240
|
class TextNode extends Text {
|
|
3153
|
-
constructor(children,
|
|
241
|
+
constructor(children, length) {
|
|
3154
242
|
super();
|
|
3155
243
|
this.children = children;
|
|
3156
|
-
this.length =
|
|
244
|
+
this.length = length;
|
|
3157
245
|
this.lines = 0;
|
|
3158
246
|
for (let child of children)
|
|
3159
247
|
this.lines += child.lines;
|
|
@@ -3189,9 +277,9 @@ class TextNode extends Text {
|
|
|
3189
277
|
let updated = child.replace(from2 - pos, to - pos, text2);
|
|
3190
278
|
let totalLines = this.lines - child.lines + updated.lines;
|
|
3191
279
|
if (updated.lines < totalLines >> 5 - 1 && updated.lines > totalLines >> 5 + 1) {
|
|
3192
|
-
let
|
|
3193
|
-
|
|
3194
|
-
return new TextNode(
|
|
280
|
+
let copy = this.children.slice();
|
|
281
|
+
copy[i] = updated;
|
|
282
|
+
return new TextNode(copy, this.length - (to - from2) + text2.length);
|
|
3195
283
|
}
|
|
3196
284
|
return super.replace(pos, end, updated);
|
|
3197
285
|
}
|
|
@@ -3219,18 +307,18 @@ class TextNode extends Text {
|
|
|
3219
307
|
scanIdentical(other, dir) {
|
|
3220
308
|
if (!(other instanceof TextNode))
|
|
3221
309
|
return 0;
|
|
3222
|
-
let
|
|
310
|
+
let length = 0;
|
|
3223
311
|
let [iA, iB, eA, eB] = dir > 0 ? [0, 0, this.children.length, other.children.length] : [this.children.length - 1, other.children.length - 1, -1, -1];
|
|
3224
312
|
for (; ; iA += dir, iB += dir) {
|
|
3225
313
|
if (iA == eA || iB == eB)
|
|
3226
|
-
return
|
|
314
|
+
return length;
|
|
3227
315
|
let chA = this.children[iA], chB = other.children[iB];
|
|
3228
316
|
if (chA != chB)
|
|
3229
|
-
return
|
|
3230
|
-
|
|
317
|
+
return length + chA.scanIdentical(chB, dir);
|
|
318
|
+
length += chA.length + 1;
|
|
3231
319
|
}
|
|
3232
320
|
}
|
|
3233
|
-
static from(children,
|
|
321
|
+
static from(children, length = children.reduce((l, ch) => l + ch.length + 1, -1)) {
|
|
3234
322
|
let lines = 0;
|
|
3235
323
|
for (let ch of children)
|
|
3236
324
|
lines += ch.lines;
|
|
@@ -3238,7 +326,7 @@ class TextNode extends Text {
|
|
|
3238
326
|
let flat = [];
|
|
3239
327
|
for (let ch of children)
|
|
3240
328
|
ch.flatten(flat);
|
|
3241
|
-
return new TextLeaf(flat,
|
|
329
|
+
return new TextLeaf(flat, length);
|
|
3242
330
|
}
|
|
3243
331
|
let chunk = Math.max(
|
|
3244
332
|
32,
|
|
@@ -3276,15 +364,15 @@ class TextNode extends Text {
|
|
|
3276
364
|
for (let child of children)
|
|
3277
365
|
add(child);
|
|
3278
366
|
flush();
|
|
3279
|
-
return chunked.length == 1 ? chunked[0] : new TextNode(chunked,
|
|
367
|
+
return chunked.length == 1 ? chunked[0] : new TextNode(chunked, length);
|
|
3280
368
|
}
|
|
3281
369
|
}
|
|
3282
370
|
Text.empty = /* @__PURE__ */ new TextLeaf([""], 0);
|
|
3283
371
|
function textLength(text2) {
|
|
3284
|
-
let
|
|
372
|
+
let length = -1;
|
|
3285
373
|
for (let line of text2)
|
|
3286
|
-
|
|
3287
|
-
return
|
|
374
|
+
length += line.length + 1;
|
|
375
|
+
return length;
|
|
3288
376
|
}
|
|
3289
377
|
function appendText(text2, target, from2 = 0, to = 1e9) {
|
|
3290
378
|
for (let pos = 0, i = 0, first = true; i < text2.length && pos <= to; i++) {
|
|
@@ -3857,14 +945,14 @@ class ChangeSet extends ChangeDesc {
|
|
|
3857
945
|
Create a change set for the given changes, for a document of the
|
|
3858
946
|
given length, using `lineSep` as line separator.
|
|
3859
947
|
*/
|
|
3860
|
-
static of(changes,
|
|
948
|
+
static of(changes, length, lineSep) {
|
|
3861
949
|
let sections = [], inserted = [], pos = 0;
|
|
3862
950
|
let total = null;
|
|
3863
951
|
function flush(force = false) {
|
|
3864
952
|
if (!force && !sections.length)
|
|
3865
953
|
return;
|
|
3866
|
-
if (pos <
|
|
3867
|
-
addSection(sections,
|
|
954
|
+
if (pos < length)
|
|
955
|
+
addSection(sections, length - pos, -1);
|
|
3868
956
|
let set = new ChangeSet(sections, inserted);
|
|
3869
957
|
total = total ? total.compose(set.map(total)) : set;
|
|
3870
958
|
sections = [];
|
|
@@ -3876,14 +964,14 @@ class ChangeSet extends ChangeDesc {
|
|
|
3876
964
|
for (let sub of spec)
|
|
3877
965
|
process2(sub);
|
|
3878
966
|
} else if (spec instanceof ChangeSet) {
|
|
3879
|
-
if (spec.length !=
|
|
3880
|
-
throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${
|
|
967
|
+
if (spec.length != length)
|
|
968
|
+
throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${length})`);
|
|
3881
969
|
flush();
|
|
3882
970
|
total = total ? total.compose(spec.map(total)) : spec;
|
|
3883
971
|
} else {
|
|
3884
972
|
let { from: from2, to = from2, insert: insert2 } = spec;
|
|
3885
|
-
if (from2 > to || from2 < 0 || to >
|
|
3886
|
-
throw new RangeError(`Invalid change range ${from2} to ${to} (in doc of length ${
|
|
973
|
+
if (from2 > to || from2 < 0 || to > length)
|
|
974
|
+
throw new RangeError(`Invalid change range ${from2} to ${to} (in doc of length ${length})`);
|
|
3887
975
|
let insText = !insert2 ? Text.empty : typeof insert2 == "string" ? Text.of(insert2.split(lineSep || DefaultSplit)) : insert2;
|
|
3888
976
|
let insLen = insText.length;
|
|
3889
977
|
if (from2 == to && insLen == 0)
|
|
@@ -3904,8 +992,8 @@ class ChangeSet extends ChangeDesc {
|
|
|
3904
992
|
/**
|
|
3905
993
|
Create an empty changeset of the given length.
|
|
3906
994
|
*/
|
|
3907
|
-
static empty(
|
|
3908
|
-
return new ChangeSet(
|
|
995
|
+
static empty(length) {
|
|
996
|
+
return new ChangeSet(length ? [length, -1] : [], []);
|
|
3909
997
|
}
|
|
3910
998
|
/**
|
|
3911
999
|
Create a changeset from its JSON representation (as produced by
|
|
@@ -4853,8 +1941,8 @@ class StateEffectType {
|
|
|
4853
1941
|
/**
|
|
4854
1942
|
@internal
|
|
4855
1943
|
*/
|
|
4856
|
-
constructor(
|
|
4857
|
-
this.map =
|
|
1944
|
+
constructor(map) {
|
|
1945
|
+
this.map = map;
|
|
4858
1946
|
}
|
|
4859
1947
|
/**
|
|
4860
1948
|
Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
|
|
@@ -4914,7 +2002,7 @@ class StateEffect {
|
|
|
4914
2002
|
}
|
|
4915
2003
|
StateEffect.reconfigure = /* @__PURE__ */ StateEffect.define();
|
|
4916
2004
|
StateEffect.appendConfig = /* @__PURE__ */ StateEffect.define();
|
|
4917
|
-
class
|
|
2005
|
+
class Transaction {
|
|
4918
2006
|
constructor(startState, changes, selection, effects, annotations, scrollIntoView2) {
|
|
4919
2007
|
this.startState = startState;
|
|
4920
2008
|
this.changes = changes;
|
|
@@ -4926,14 +2014,14 @@ class Transaction2 {
|
|
|
4926
2014
|
this._state = null;
|
|
4927
2015
|
if (selection)
|
|
4928
2016
|
checkSelection(selection, changes.newLength);
|
|
4929
|
-
if (!annotations.some((a) => a.type ==
|
|
4930
|
-
this.annotations = annotations.concat(
|
|
2017
|
+
if (!annotations.some((a) => a.type == Transaction.time))
|
|
2018
|
+
this.annotations = annotations.concat(Transaction.time.of(Date.now()));
|
|
4931
2019
|
}
|
|
4932
2020
|
/**
|
|
4933
2021
|
@internal
|
|
4934
2022
|
*/
|
|
4935
2023
|
static create(startState, changes, selection, effects, annotations, scrollIntoView2) {
|
|
4936
|
-
return new
|
|
2024
|
+
return new Transaction(startState, changes, selection, effects, annotations, scrollIntoView2);
|
|
4937
2025
|
}
|
|
4938
2026
|
/**
|
|
4939
2027
|
The new document produced by the transaction. Contrary to
|
|
@@ -4998,14 +2086,14 @@ class Transaction2 {
|
|
|
4998
2086
|
`"select.pointer"` will match it.
|
|
4999
2087
|
*/
|
|
5000
2088
|
isUserEvent(event) {
|
|
5001
|
-
let e = this.annotation(
|
|
2089
|
+
let e = this.annotation(Transaction.userEvent);
|
|
5002
2090
|
return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
|
|
5003
2091
|
}
|
|
5004
2092
|
}
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
2093
|
+
Transaction.time = /* @__PURE__ */ Annotation.define();
|
|
2094
|
+
Transaction.userEvent = /* @__PURE__ */ Annotation.define();
|
|
2095
|
+
Transaction.addToHistory = /* @__PURE__ */ Annotation.define();
|
|
2096
|
+
Transaction.remote = /* @__PURE__ */ Annotation.define();
|
|
5009
2097
|
function joinRanges(a, b) {
|
|
5010
2098
|
let result = [];
|
|
5011
2099
|
for (let iA = 0, iB = 0; ; ) {
|
|
@@ -5047,7 +2135,7 @@ function mergeTransaction(a, b, sequential) {
|
|
|
5047
2135
|
function resolveTransactionInner(state, spec, docSize) {
|
|
5048
2136
|
let sel = spec.selection, annotations = asArray$1(spec.annotations);
|
|
5049
2137
|
if (spec.userEvent)
|
|
5050
|
-
annotations = annotations.concat(
|
|
2138
|
+
annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));
|
|
5051
2139
|
return {
|
|
5052
2140
|
changes: spec.changes instanceof ChangeSet ? spec.changes : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),
|
|
5053
2141
|
selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),
|
|
@@ -5066,7 +2154,7 @@ function resolveTransaction(state, specs, filter) {
|
|
|
5066
2154
|
let seq = !!specs[i].sequential;
|
|
5067
2155
|
s = mergeTransaction(s, resolveTransactionInner(state, specs[i], seq ? s.changes.newLength : state.doc.length), seq);
|
|
5068
2156
|
}
|
|
5069
|
-
let tr =
|
|
2157
|
+
let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);
|
|
5070
2158
|
return extendTransaction(filter ? filterTransaction(tr) : tr);
|
|
5071
2159
|
}
|
|
5072
2160
|
function filterTransaction(tr) {
|
|
@@ -5091,14 +2179,14 @@ function filterTransaction(tr) {
|
|
|
5091
2179
|
changes = filtered.changes;
|
|
5092
2180
|
back = filtered.filtered.mapDesc(filtered.changes).invertedDesc;
|
|
5093
2181
|
}
|
|
5094
|
-
tr =
|
|
2182
|
+
tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
|
|
5095
2183
|
}
|
|
5096
2184
|
let filters = state.facet(transactionFilter);
|
|
5097
2185
|
for (let i = filters.length - 1; i >= 0; i--) {
|
|
5098
2186
|
let filtered = filters[i](tr);
|
|
5099
|
-
if (filtered instanceof
|
|
2187
|
+
if (filtered instanceof Transaction)
|
|
5100
2188
|
tr = filtered;
|
|
5101
|
-
else if (Array.isArray(filtered) && filtered.length == 1 && filtered[0] instanceof
|
|
2189
|
+
else if (Array.isArray(filtered) && filtered.length == 1 && filtered[0] instanceof Transaction)
|
|
5102
2190
|
tr = filtered[0];
|
|
5103
2191
|
else
|
|
5104
2192
|
tr = resolveTransaction(state, asArray$1(filtered), false);
|
|
@@ -5112,7 +2200,7 @@ function extendTransaction(tr) {
|
|
|
5112
2200
|
if (extension && Object.keys(extension).length)
|
|
5113
2201
|
spec = mergeTransaction(spec, resolveTransactionInner(state, extension, tr.changes.newLength), true);
|
|
5114
2202
|
}
|
|
5115
|
-
return spec == tr ? tr :
|
|
2203
|
+
return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
|
|
5116
2204
|
}
|
|
5117
2205
|
const none = [];
|
|
5118
2206
|
function asArray$1(value) {
|
|
@@ -5392,9 +2480,9 @@ class EditorState {
|
|
|
5392
2480
|
literal dollar sign.
|
|
5393
2481
|
*/
|
|
5394
2482
|
phrase(phrase, ...insert2) {
|
|
5395
|
-
for (let
|
|
5396
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
5397
|
-
phrase =
|
|
2483
|
+
for (let map of this.facet(EditorState.phrases))
|
|
2484
|
+
if (Object.prototype.hasOwnProperty.call(map, phrase)) {
|
|
2485
|
+
phrase = map[phrase];
|
|
5398
2486
|
break;
|
|
5399
2487
|
}
|
|
5400
2488
|
if (insert2.length)
|
|
@@ -5453,7 +2541,7 @@ class EditorState {
|
|
|
5453
2541
|
this returns null.
|
|
5454
2542
|
*/
|
|
5455
2543
|
wordAt(pos) {
|
|
5456
|
-
let { text: text2, from: from2, length
|
|
2544
|
+
let { text: text2, from: from2, length } = this.doc.lineAt(pos);
|
|
5457
2545
|
let cat = this.charCategorizer(pos);
|
|
5458
2546
|
let start2 = pos - from2, end = pos - from2;
|
|
5459
2547
|
while (start2 > 0) {
|
|
@@ -5462,7 +2550,7 @@ class EditorState {
|
|
|
5462
2550
|
break;
|
|
5463
2551
|
start2 = prev;
|
|
5464
2552
|
}
|
|
5465
|
-
while (end <
|
|
2553
|
+
while (end < length) {
|
|
5466
2554
|
let next = findClusterBreak(text2, end);
|
|
5467
2555
|
if (cat(text2.slice(end, next)) != CharCategory.Word)
|
|
5468
2556
|
break;
|
|
@@ -5755,7 +2843,7 @@ class RangeSet {
|
|
|
5755
2843
|
let sharedChunks = findSharedChunks(a, b, textDiff);
|
|
5756
2844
|
let sideA = new SpanCursor(a, sharedChunks, minPointSize);
|
|
5757
2845
|
let sideB = new SpanCursor(b, sharedChunks, minPointSize);
|
|
5758
|
-
textDiff.iterGaps((fromA, fromB,
|
|
2846
|
+
textDiff.iterGaps((fromA, fromB, length) => compare(sideA, fromA, sideB, fromB, length, comparator));
|
|
5759
2847
|
if (textDiff.empty && textDiff.length == 0)
|
|
5760
2848
|
compare(sideA, 0, sideB, 0, 0, comparator);
|
|
5761
2849
|
}
|
|
@@ -6220,10 +3308,10 @@ class SpanCursor {
|
|
|
6220
3308
|
return open;
|
|
6221
3309
|
}
|
|
6222
3310
|
}
|
|
6223
|
-
function compare(a, startA, b, startB,
|
|
3311
|
+
function compare(a, startA, b, startB, length, comparator) {
|
|
6224
3312
|
a.goto(startA);
|
|
6225
3313
|
b.goto(startB);
|
|
6226
|
-
let endB = startB +
|
|
3314
|
+
let endB = startB + length;
|
|
6227
3315
|
let pos = startB, dPos = startB - startA;
|
|
6228
3316
|
for (; ; ) {
|
|
6229
3317
|
let diff = a.to + dPos - b.to || a.endSide - b.endSide;
|
|
@@ -7167,14 +4255,14 @@ function mergeChildrenInto(parent, from2, to, insert2, openStart, openEnd) {
|
|
|
7167
4255
|
replaceRange(parent, fromI, fromOff, toI, toOff, insert2, 0, openStart, openEnd);
|
|
7168
4256
|
}
|
|
7169
4257
|
let nav = typeof navigator != "undefined" ? navigator : { userAgent: "", vendor: "", platform: "" };
|
|
7170
|
-
let doc = typeof document != "undefined" ? document : { documentElement: { style: {} } };
|
|
4258
|
+
let doc$1 = typeof document != "undefined" ? document : { documentElement: { style: {} } };
|
|
7171
4259
|
const ie_edge = /* @__PURE__ */ /Edge\/(\d+)/.exec(nav.userAgent);
|
|
7172
4260
|
const ie_upto10 = /* @__PURE__ */ /MSIE \d/.test(nav.userAgent);
|
|
7173
4261
|
const ie_11up = /* @__PURE__ */ /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(nav.userAgent);
|
|
7174
4262
|
const ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
7175
4263
|
const gecko = !ie && /* @__PURE__ */ /gecko\/(\d+)/i.test(nav.userAgent);
|
|
7176
4264
|
const chrome = !ie && /* @__PURE__ */ /Chrome\/(\d+)/.exec(nav.userAgent);
|
|
7177
|
-
const webkit = "webkitFontSmoothing" in doc.documentElement.style;
|
|
4265
|
+
const webkit = "webkitFontSmoothing" in doc$1.documentElement.style;
|
|
7178
4266
|
const safari = !ie && /* @__PURE__ */ /Apple Computer/.test(nav.vendor);
|
|
7179
4267
|
const ios = safari && (/* @__PURE__ */ /Mobile\/\w+/.test(nav.userAgent) || nav.maxTouchPoints > 2);
|
|
7180
4268
|
var browser = {
|
|
@@ -7182,7 +4270,7 @@ var browser = {
|
|
|
7182
4270
|
windows: /* @__PURE__ */ /Win/.test(nav.platform),
|
|
7183
4271
|
linux: /* @__PURE__ */ /Linux|X11/.test(nav.platform),
|
|
7184
4272
|
ie,
|
|
7185
|
-
ie_version: ie_upto10 ? doc.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0,
|
|
4273
|
+
ie_version: ie_upto10 ? doc$1.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0,
|
|
7186
4274
|
gecko,
|
|
7187
4275
|
gecko_version: gecko ? +(/* @__PURE__ */ /Firefox\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
7188
4276
|
chrome: !!chrome,
|
|
@@ -7192,7 +4280,7 @@ var browser = {
|
|
|
7192
4280
|
webkit,
|
|
7193
4281
|
safari,
|
|
7194
4282
|
webkit_version: webkit ? +(/* @__PURE__ */ /\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0,
|
|
7195
|
-
tabSize: doc.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"
|
|
4283
|
+
tabSize: doc$1.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"
|
|
7196
4284
|
};
|
|
7197
4285
|
const MaxJoinLen = 256;
|
|
7198
4286
|
class TextView extends ContentView {
|
|
@@ -7247,11 +4335,11 @@ class TextView extends ContentView {
|
|
|
7247
4335
|
}
|
|
7248
4336
|
}
|
|
7249
4337
|
class MarkView extends ContentView {
|
|
7250
|
-
constructor(mark, children = [],
|
|
4338
|
+
constructor(mark, children = [], length = 0) {
|
|
7251
4339
|
super();
|
|
7252
4340
|
this.mark = mark;
|
|
7253
4341
|
this.children = children;
|
|
7254
|
-
this.length =
|
|
4342
|
+
this.length = length;
|
|
7255
4343
|
for (let ch of children)
|
|
7256
4344
|
ch.setParent(this);
|
|
7257
4345
|
}
|
|
@@ -7298,13 +4386,13 @@ class MarkView extends ContentView {
|
|
|
7298
4386
|
off = end;
|
|
7299
4387
|
i++;
|
|
7300
4388
|
}
|
|
7301
|
-
let
|
|
4389
|
+
let length = this.length - from2;
|
|
7302
4390
|
this.length = from2;
|
|
7303
4391
|
if (detachFrom > -1) {
|
|
7304
4392
|
this.children.length = detachFrom;
|
|
7305
4393
|
this.markDirty();
|
|
7306
4394
|
}
|
|
7307
|
-
return new MarkView(this.mark, result,
|
|
4395
|
+
return new MarkView(this.mark, result, length);
|
|
7308
4396
|
}
|
|
7309
4397
|
domAtPos(pos) {
|
|
7310
4398
|
return inlineDOMAtPos(this, pos);
|
|
@@ -7314,16 +4402,16 @@ class MarkView extends ContentView {
|
|
|
7314
4402
|
}
|
|
7315
4403
|
}
|
|
7316
4404
|
function textCoords(text2, pos, side) {
|
|
7317
|
-
let
|
|
7318
|
-
if (pos >
|
|
7319
|
-
pos =
|
|
4405
|
+
let length = text2.nodeValue.length;
|
|
4406
|
+
if (pos > length)
|
|
4407
|
+
pos = length;
|
|
7320
4408
|
let from2 = pos, to = pos, flatten2 = 0;
|
|
7321
|
-
if (pos == 0 && side < 0 || pos ==
|
|
4409
|
+
if (pos == 0 && side < 0 || pos == length && side >= 0) {
|
|
7322
4410
|
if (!(browser.chrome || browser.gecko)) {
|
|
7323
4411
|
if (pos) {
|
|
7324
4412
|
from2--;
|
|
7325
4413
|
flatten2 = 1;
|
|
7326
|
-
} else if (to <
|
|
4414
|
+
} else if (to < length) {
|
|
7327
4415
|
to++;
|
|
7328
4416
|
flatten2 = -1;
|
|
7329
4417
|
}
|
|
@@ -7331,7 +4419,7 @@ function textCoords(text2, pos, side) {
|
|
|
7331
4419
|
} else {
|
|
7332
4420
|
if (side < 0)
|
|
7333
4421
|
from2--;
|
|
7334
|
-
else if (to <
|
|
4422
|
+
else if (to < length)
|
|
7335
4423
|
to++;
|
|
7336
4424
|
}
|
|
7337
4425
|
let rects = textRange(text2, from2, to).getClientRects();
|
|
@@ -7343,13 +4431,13 @@ function textCoords(text2, pos, side) {
|
|
|
7343
4431
|
return flatten2 ? flattenRect(rect, flatten2 < 0) : rect || null;
|
|
7344
4432
|
}
|
|
7345
4433
|
class WidgetView extends ContentView {
|
|
7346
|
-
static create(widget,
|
|
7347
|
-
return new WidgetView(widget,
|
|
4434
|
+
static create(widget, length, side) {
|
|
4435
|
+
return new WidgetView(widget, length, side);
|
|
7348
4436
|
}
|
|
7349
|
-
constructor(widget,
|
|
4437
|
+
constructor(widget, length, side) {
|
|
7350
4438
|
super();
|
|
7351
4439
|
this.widget = widget;
|
|
7352
|
-
this.length =
|
|
4440
|
+
this.length = length;
|
|
7353
4441
|
this.side = side;
|
|
7354
4442
|
this.prevWidget = null;
|
|
7355
4443
|
}
|
|
@@ -7771,10 +4859,10 @@ class LineView extends ContentView {
|
|
|
7771
4859
|
}
|
|
7772
4860
|
}
|
|
7773
4861
|
class BlockWidgetView extends ContentView {
|
|
7774
|
-
constructor(widget,
|
|
4862
|
+
constructor(widget, length, deco) {
|
|
7775
4863
|
super();
|
|
7776
4864
|
this.widget = widget;
|
|
7777
|
-
this.length =
|
|
4865
|
+
this.length = length;
|
|
7778
4866
|
this.deco = deco;
|
|
7779
4867
|
this.breakAfter = 0;
|
|
7780
4868
|
this.prevWidget = null;
|
|
@@ -8147,8 +5235,8 @@ class ContentBuilder {
|
|
|
8147
5235
|
if (!this.posCovered() && !(openEnd && this.content.length && this.content[this.content.length - 1] instanceof BlockWidgetView))
|
|
8148
5236
|
this.getLine();
|
|
8149
5237
|
}
|
|
8150
|
-
buildText(
|
|
8151
|
-
while (
|
|
5238
|
+
buildText(length, active, openStart) {
|
|
5239
|
+
while (length > 0) {
|
|
8152
5240
|
if (this.textOff == this.text.length) {
|
|
8153
5241
|
let { value, lineBreak, done } = this.cursor.next(this.skip);
|
|
8154
5242
|
this.skip = 0;
|
|
@@ -8164,7 +5252,7 @@ class ContentBuilder {
|
|
|
8164
5252
|
this.flushBuffer();
|
|
8165
5253
|
this.curLine = null;
|
|
8166
5254
|
this.atCursorPos = true;
|
|
8167
|
-
|
|
5255
|
+
length--;
|
|
8168
5256
|
continue;
|
|
8169
5257
|
} else {
|
|
8170
5258
|
this.text = value;
|
|
@@ -8173,7 +5261,7 @@ class ContentBuilder {
|
|
|
8173
5261
|
}
|
|
8174
5262
|
let take = Math.min(
|
|
8175
5263
|
this.text.length - this.textOff,
|
|
8176
|
-
|
|
5264
|
+
length,
|
|
8177
5265
|
512
|
|
8178
5266
|
/* T.Chunk */
|
|
8179
5267
|
);
|
|
@@ -8181,7 +5269,7 @@ class ContentBuilder {
|
|
|
8181
5269
|
this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart);
|
|
8182
5270
|
this.atCursorPos = true;
|
|
8183
5271
|
this.textOff += take;
|
|
8184
|
-
|
|
5272
|
+
length -= take;
|
|
8185
5273
|
openStart = 0;
|
|
8186
5274
|
}
|
|
8187
5275
|
}
|
|
@@ -8598,8 +5686,8 @@ function computeOrder(line, direction, isolates) {
|
|
|
8598
5686
|
computeSectionOrder(line, level, level, isolates, 0, line.length, order);
|
|
8599
5687
|
return order;
|
|
8600
5688
|
}
|
|
8601
|
-
function trivialOrder(
|
|
8602
|
-
return [new BidiSpan(0,
|
|
5689
|
+
function trivialOrder(length) {
|
|
5690
|
+
return [new BidiSpan(0, length, 0)];
|
|
8603
5691
|
}
|
|
8604
5692
|
let movedOver = "";
|
|
8605
5693
|
function moveVisually(line, order, dir, start2, forward) {
|
|
@@ -10620,10 +7708,10 @@ class HeightOracle {
|
|
|
10620
7708
|
lines += Math.max(0, Math.ceil((to - from2 - lines * this.lineLength * 0.5) / this.lineLength));
|
|
10621
7709
|
return this.lineHeight * lines;
|
|
10622
7710
|
}
|
|
10623
|
-
heightForLine(
|
|
7711
|
+
heightForLine(length) {
|
|
10624
7712
|
if (!this.lineWrapping)
|
|
10625
7713
|
return this.lineHeight;
|
|
10626
|
-
let lines = 1 + Math.max(0, Math.ceil((
|
|
7714
|
+
let lines = 1 + Math.max(0, Math.ceil((length - this.lineLength) / (this.lineLength - 5)));
|
|
10627
7715
|
return lines * this.lineHeight;
|
|
10628
7716
|
}
|
|
10629
7717
|
setDoc(doc2) {
|
|
@@ -10681,9 +7769,9 @@ class BlockInfo {
|
|
|
10681
7769
|
/**
|
|
10682
7770
|
@internal
|
|
10683
7771
|
*/
|
|
10684
|
-
constructor(from2,
|
|
7772
|
+
constructor(from2, length, top2, height, _content) {
|
|
10685
7773
|
this.from = from2;
|
|
10686
|
-
this.length =
|
|
7774
|
+
this.length = length;
|
|
10687
7775
|
this.top = top2;
|
|
10688
7776
|
this.height = height;
|
|
10689
7777
|
this._content = _content;
|
|
@@ -10737,8 +7825,8 @@ var QueryType = /* @__PURE__ */ function(QueryType2) {
|
|
|
10737
7825
|
}(QueryType || (QueryType = {}));
|
|
10738
7826
|
const Epsilon = 1e-3;
|
|
10739
7827
|
class HeightMap {
|
|
10740
|
-
constructor(
|
|
10741
|
-
this.length =
|
|
7828
|
+
constructor(length, height, flags = 2) {
|
|
7829
|
+
this.length = length;
|
|
10742
7830
|
this.height = height;
|
|
10743
7831
|
this.flags = flags;
|
|
10744
7832
|
}
|
|
@@ -10845,8 +7933,8 @@ class HeightMap {
|
|
|
10845
7933
|
}
|
|
10846
7934
|
HeightMap.prototype.size = 1;
|
|
10847
7935
|
class HeightMapBlock extends HeightMap {
|
|
10848
|
-
constructor(
|
|
10849
|
-
super(
|
|
7936
|
+
constructor(length, height, deco) {
|
|
7937
|
+
super(length, height);
|
|
10850
7938
|
this.deco = deco;
|
|
10851
7939
|
}
|
|
10852
7940
|
blockAt(_height, _oracle, top2, offset) {
|
|
@@ -10870,8 +7958,8 @@ class HeightMapBlock extends HeightMap {
|
|
|
10870
7958
|
}
|
|
10871
7959
|
}
|
|
10872
7960
|
class HeightMapText extends HeightMapBlock {
|
|
10873
|
-
constructor(
|
|
10874
|
-
super(
|
|
7961
|
+
constructor(length, height) {
|
|
7962
|
+
super(length, height, null);
|
|
10875
7963
|
this.collapsed = 0;
|
|
10876
7964
|
this.widgetHeight = 0;
|
|
10877
7965
|
this.breaks = 0;
|
|
@@ -10906,8 +7994,8 @@ class HeightMapText extends HeightMapBlock {
|
|
|
10906
7994
|
}
|
|
10907
7995
|
}
|
|
10908
7996
|
class HeightMapGap extends HeightMap {
|
|
10909
|
-
constructor(
|
|
10910
|
-
super(
|
|
7997
|
+
constructor(length) {
|
|
7998
|
+
super(length, 0);
|
|
10911
7999
|
}
|
|
10912
8000
|
heightMetrics(oracle, offset) {
|
|
10913
8001
|
let firstLine = oracle.doc.lineAt(offset).number, lastLine = oracle.doc.lineAt(offset + this.length).number;
|
|
@@ -10932,8 +8020,8 @@ class HeightMapGap extends HeightMap {
|
|
|
10932
8020
|
return new BlockInfo(line.from, line.length, lineTop, lineHeight, 0);
|
|
10933
8021
|
} else {
|
|
10934
8022
|
let line = Math.max(0, Math.min(lastLine - firstLine, Math.floor((height - top2) / perLine)));
|
|
10935
|
-
let { from: from2, length
|
|
10936
|
-
return new BlockInfo(from2,
|
|
8023
|
+
let { from: from2, length } = oracle.doc.line(firstLine + line);
|
|
8024
|
+
return new BlockInfo(from2, length, top2 + perLine * line, perLine, 0);
|
|
10937
8025
|
}
|
|
10938
8026
|
}
|
|
10939
8027
|
lineAt(value, type, oracle, top2, offset) {
|
|
@@ -11236,13 +8324,13 @@ class NodeBuilder {
|
|
|
11236
8324
|
if (deco && deco.endSide > 0)
|
|
11237
8325
|
this.covering = block;
|
|
11238
8326
|
}
|
|
11239
|
-
addLineDeco(height, breaks,
|
|
8327
|
+
addLineDeco(height, breaks, length) {
|
|
11240
8328
|
let line = this.ensureLine();
|
|
11241
|
-
line.length +=
|
|
11242
|
-
line.collapsed +=
|
|
8329
|
+
line.length += length;
|
|
8330
|
+
line.collapsed += length;
|
|
11243
8331
|
line.widgetHeight = Math.max(line.widgetHeight, height);
|
|
11244
8332
|
line.breaks += breaks;
|
|
11245
|
-
this.writtenTo = this.pos = this.pos +
|
|
8333
|
+
this.writtenTo = this.pos = this.pos + length;
|
|
11246
8334
|
}
|
|
11247
8335
|
finish(from2) {
|
|
11248
8336
|
let last = this.nodes.length == 0 ? null : this.nodes[this.nodes.length - 1];
|
|
@@ -11560,21 +8648,21 @@ class ViewState {
|
|
|
11560
8648
|
}
|
|
11561
8649
|
getViewport(bias, scrollTarget) {
|
|
11562
8650
|
let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1e3 / 2));
|
|
11563
|
-
let
|
|
8651
|
+
let map = this.heightMap, oracle = this.heightOracle;
|
|
11564
8652
|
let { visibleTop, visibleBottom } = this;
|
|
11565
|
-
let viewport = new Viewport(
|
|
8653
|
+
let viewport = new Viewport(map.lineAt(visibleTop - marginTop * 1e3, QueryType.ByHeight, oracle, 0, 0).from, map.lineAt(visibleBottom + (1 - marginTop) * 1e3, QueryType.ByHeight, oracle, 0, 0).to);
|
|
11566
8654
|
if (scrollTarget) {
|
|
11567
8655
|
let { head } = scrollTarget.range;
|
|
11568
8656
|
if (head < viewport.from || head > viewport.to) {
|
|
11569
8657
|
let viewHeight = Math.min(this.editorHeight, this.pixelViewport.bottom - this.pixelViewport.top);
|
|
11570
|
-
let block =
|
|
8658
|
+
let block = map.lineAt(head, QueryType.ByPos, oracle, 0, 0), topPos;
|
|
11571
8659
|
if (scrollTarget.y == "center")
|
|
11572
8660
|
topPos = (block.top + block.bottom) / 2 - viewHeight / 2;
|
|
11573
8661
|
else if (scrollTarget.y == "start" || scrollTarget.y == "nearest" && head < viewport.from)
|
|
11574
8662
|
topPos = block.top;
|
|
11575
8663
|
else
|
|
11576
8664
|
topPos = block.bottom - viewHeight;
|
|
11577
|
-
viewport = new Viewport(
|
|
8665
|
+
viewport = new Viewport(map.lineAt(topPos - 1e3 / 2, QueryType.ByHeight, oracle, 0, 0).from, map.lineAt(topPos + viewHeight + 1e3 / 2, QueryType.ByHeight, oracle, 0, 0).to);
|
|
11578
8666
|
}
|
|
11579
8667
|
}
|
|
11580
8668
|
return viewport;
|
|
@@ -12203,10 +9291,10 @@ class DOMReader {
|
|
|
12203
9291
|
if (point.node == node && node.childNodes[point.offset] == next)
|
|
12204
9292
|
point.pos = this.text.length;
|
|
12205
9293
|
}
|
|
12206
|
-
findPointInside(node,
|
|
9294
|
+
findPointInside(node, length) {
|
|
12207
9295
|
for (let point of this.points)
|
|
12208
9296
|
if (node.nodeType == 3 ? point.node == node : node.contains(point.node))
|
|
12209
|
-
point.pos = this.text.length + (isAtEnd(node, point.node, point.offset) ?
|
|
9297
|
+
point.pos = this.text.length + (isAtEnd(node, point.node, point.offset) ? length : 0);
|
|
12210
9298
|
}
|
|
12211
9299
|
}
|
|
12212
9300
|
function isAtEnd(parent, node, offset) {
|
|
@@ -12946,7 +10034,7 @@ class EditorView {
|
|
|
12946
10034
|
this.requestMeasure();
|
|
12947
10035
|
}
|
|
12948
10036
|
dispatch(...input) {
|
|
12949
|
-
let trs = input.length == 1 && input[0] instanceof
|
|
10037
|
+
let trs = input.length == 1 && input[0] instanceof Transaction ? input : input.length == 1 && Array.isArray(input[0]) ? input[0] : [this.state.update(...input)];
|
|
12950
10038
|
this.dispatchTransactions(trs, this);
|
|
12951
10039
|
}
|
|
12952
10040
|
/**
|
|
@@ -13817,10 +10905,10 @@ const keymap = /* @__PURE__ */ Facet.define({ enables: handleKeyEvents });
|
|
|
13817
10905
|
const Keymaps = /* @__PURE__ */ new WeakMap();
|
|
13818
10906
|
function getKeymap(state) {
|
|
13819
10907
|
let bindings = state.facet(keymap);
|
|
13820
|
-
let
|
|
13821
|
-
if (!
|
|
13822
|
-
Keymaps.set(bindings,
|
|
13823
|
-
return
|
|
10908
|
+
let map = Keymaps.get(bindings);
|
|
10909
|
+
if (!map)
|
|
10910
|
+
Keymaps.set(bindings, map = buildKeymap(bindings.reduce((a, b) => a.concat(b), [])));
|
|
10911
|
+
return map;
|
|
13824
10912
|
}
|
|
13825
10913
|
let storedPrefix = null;
|
|
13826
10914
|
const PrefixTimeout = 4e3;
|
|
@@ -13890,7 +10978,7 @@ function buildKeymap(bindings, platform = currentPlatform) {
|
|
|
13890
10978
|
}
|
|
13891
10979
|
return bound;
|
|
13892
10980
|
}
|
|
13893
|
-
function runHandlers(
|
|
10981
|
+
function runHandlers(map, event, view, scope) {
|
|
13894
10982
|
let name2 = keyName(event);
|
|
13895
10983
|
let charCode = codePointAt(name2, 0), isChar = codePointSize(charCode) == name2.length && name2 != " ";
|
|
13896
10984
|
let prefix = "", handled = false, prevented = false, stopPropagation = false;
|
|
@@ -13921,7 +11009,7 @@ function runHandlers(map2, event, view, scope) {
|
|
|
13921
11009
|
}
|
|
13922
11010
|
return false;
|
|
13923
11011
|
};
|
|
13924
|
-
let scopeObj =
|
|
11012
|
+
let scopeObj = map[scope], baseName, shiftName;
|
|
13925
11013
|
if (scopeObj) {
|
|
13926
11014
|
if (runFor(scopeObj[prefix + modifiers(name2, event, !isChar)])) {
|
|
13927
11015
|
handled = true;
|
|
@@ -14470,8 +11558,8 @@ class YRange {
|
|
|
14470
11558
|
*/
|
|
14471
11559
|
toJSON() {
|
|
14472
11560
|
return {
|
|
14473
|
-
yanchor: relativePositionToJSON(this.yanchor),
|
|
14474
|
-
yhead: relativePositionToJSON(this.yhead)
|
|
11561
|
+
yanchor: Y.relativePositionToJSON(this.yanchor),
|
|
11562
|
+
yhead: Y.relativePositionToJSON(this.yhead)
|
|
14475
11563
|
};
|
|
14476
11564
|
}
|
|
14477
11565
|
/**
|
|
@@ -14479,14 +11567,14 @@ class YRange {
|
|
|
14479
11567
|
* @return {YRange}
|
|
14480
11568
|
*/
|
|
14481
11569
|
static fromJSON(json2) {
|
|
14482
|
-
return new YRange(createRelativePositionFromJSON(json2.yanchor), createRelativePositionFromJSON(json2.yhead));
|
|
11570
|
+
return new YRange(Y.createRelativePositionFromJSON(json2.yanchor), Y.createRelativePositionFromJSON(json2.yhead));
|
|
14483
11571
|
}
|
|
14484
11572
|
}
|
|
14485
11573
|
class YSyncConfig {
|
|
14486
11574
|
constructor(ytext, awareness) {
|
|
14487
11575
|
this.ytext = ytext;
|
|
14488
11576
|
this.awareness = awareness;
|
|
14489
|
-
this.undoManager = new UndoManager(ytext);
|
|
11577
|
+
this.undoManager = new Y.UndoManager(ytext);
|
|
14490
11578
|
}
|
|
14491
11579
|
/**
|
|
14492
11580
|
* Helper function to transform an absolute index position to a Yjs-based relative position
|
|
@@ -14516,13 +11604,13 @@ class YSyncConfig {
|
|
|
14516
11604
|
* @param {number} [assoc]
|
|
14517
11605
|
*/
|
|
14518
11606
|
toYPos(pos, assoc = 0) {
|
|
14519
|
-
return createRelativePositionFromTypeIndex(this.ytext, pos, assoc);
|
|
11607
|
+
return Y.createRelativePositionFromTypeIndex(this.ytext, pos, assoc);
|
|
14520
11608
|
}
|
|
14521
11609
|
/**
|
|
14522
11610
|
* @param {Y.RelativePosition | Object} rpos
|
|
14523
11611
|
*/
|
|
14524
11612
|
fromYPos(rpos) {
|
|
14525
|
-
const pos = createAbsolutePositionFromRelativePosition(createRelativePositionFromJSON(rpos), this.ytext.doc);
|
|
11613
|
+
const pos = Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(rpos), this.ytext.doc);
|
|
14526
11614
|
if (pos == null || pos.type !== this.ytext) {
|
|
14527
11615
|
throw new Error("[y-codemirror] The position you want to retrieve was created by a different document");
|
|
14528
11616
|
}
|
|
@@ -14615,6 +11703,61 @@ class YSyncPluginValue {
|
|
|
14615
11703
|
}
|
|
14616
11704
|
}
|
|
14617
11705
|
const ySync = ViewPlugin.fromClass(YSyncPluginValue);
|
|
11706
|
+
class Pair {
|
|
11707
|
+
/**
|
|
11708
|
+
* @param {L} left
|
|
11709
|
+
* @param {R} right
|
|
11710
|
+
*/
|
|
11711
|
+
constructor(left, right) {
|
|
11712
|
+
this.left = left;
|
|
11713
|
+
this.right = right;
|
|
11714
|
+
}
|
|
11715
|
+
}
|
|
11716
|
+
const create = (left, right) => new Pair(left, right);
|
|
11717
|
+
const forEach = (arr, f) => arr.forEach((p) => f(p.left, p.right));
|
|
11718
|
+
const doc = (
|
|
11719
|
+
/** @type {Document} */
|
|
11720
|
+
typeof document !== "undefined" ? document : {}
|
|
11721
|
+
);
|
|
11722
|
+
const createElement = (name2) => doc.createElement(name2);
|
|
11723
|
+
const createDocumentFragment = () => doc.createDocumentFragment();
|
|
11724
|
+
const createTextNode = (text2) => doc.createTextNode(text2);
|
|
11725
|
+
typeof DOMParser !== "undefined" ? new DOMParser() : null;
|
|
11726
|
+
const setAttributes = (el, attrs) => {
|
|
11727
|
+
forEach(attrs, (key, value) => {
|
|
11728
|
+
if (value === false) {
|
|
11729
|
+
el.removeAttribute(key);
|
|
11730
|
+
} else if (value === true) {
|
|
11731
|
+
el.setAttribute(key, "");
|
|
11732
|
+
} else {
|
|
11733
|
+
el.setAttribute(key, value);
|
|
11734
|
+
}
|
|
11735
|
+
});
|
|
11736
|
+
return el;
|
|
11737
|
+
};
|
|
11738
|
+
const fragment = (children) => {
|
|
11739
|
+
const fragment2 = createDocumentFragment();
|
|
11740
|
+
for (let i = 0; i < children.length; i++) {
|
|
11741
|
+
appendChild(fragment2, children[i]);
|
|
11742
|
+
}
|
|
11743
|
+
return fragment2;
|
|
11744
|
+
};
|
|
11745
|
+
const append = (parent, nodes) => {
|
|
11746
|
+
appendChild(parent, fragment(nodes));
|
|
11747
|
+
return parent;
|
|
11748
|
+
};
|
|
11749
|
+
const element = (name2, attrs = [], children = []) => append(setAttributes(createElement(name2), attrs), children);
|
|
11750
|
+
const text = createTextNode;
|
|
11751
|
+
const appendChild = (parent, child) => parent.appendChild(child);
|
|
11752
|
+
doc.ELEMENT_NODE;
|
|
11753
|
+
doc.TEXT_NODE;
|
|
11754
|
+
doc.CDATA_SECTION_NODE;
|
|
11755
|
+
doc.COMMENT_NODE;
|
|
11756
|
+
doc.DOCUMENT_NODE;
|
|
11757
|
+
doc.DOCUMENT_TYPE_NODE;
|
|
11758
|
+
doc.DOCUMENT_FRAGMENT_NODE;
|
|
11759
|
+
const min = (a, b) => a < b ? a : b;
|
|
11760
|
+
const max = (a, b) => a > b ? a : b;
|
|
14618
11761
|
const yRemoteSelectionsTheme = EditorView.baseTheme({
|
|
14619
11762
|
".cm-ySelection": {},
|
|
14620
11763
|
".cm-yLineSelection": {
|
|
@@ -14685,14 +11828,14 @@ class YRemoteCaretWidget extends WidgetType {
|
|
|
14685
11828
|
toDOM() {
|
|
14686
11829
|
return (
|
|
14687
11830
|
/** @type {HTMLElement} */
|
|
14688
|
-
element("span", [create
|
|
11831
|
+
element("span", [create("class", "cm-ySelectionCaret"), create("style", `background-color: ${this.color}; border-color: ${this.color}`)], [
|
|
14689
11832
|
text(""),
|
|
14690
11833
|
element("div", [
|
|
14691
|
-
create
|
|
11834
|
+
create("class", "cm-ySelectionCaretDot")
|
|
14692
11835
|
]),
|
|
14693
11836
|
text(""),
|
|
14694
11837
|
element("div", [
|
|
14695
|
-
create
|
|
11838
|
+
create("class", "cm-ySelectionInfo")
|
|
14696
11839
|
], [
|
|
14697
11840
|
text(this.name)
|
|
14698
11841
|
]),
|
|
@@ -14750,12 +11893,12 @@ class YRemoteSelectionsPluginValue {
|
|
|
14750
11893
|
if (localAwarenessState != null) {
|
|
14751
11894
|
const hasFocus = update.view.hasFocus && update.view.dom.ownerDocument.hasFocus();
|
|
14752
11895
|
const sel = hasFocus ? update.state.selection.main : null;
|
|
14753
|
-
const currentAnchor = localAwarenessState.cursor == null ? null : createRelativePositionFromJSON(localAwarenessState.cursor.anchor);
|
|
14754
|
-
const currentHead = localAwarenessState.cursor == null ? null : createRelativePositionFromJSON(localAwarenessState.cursor.head);
|
|
11896
|
+
const currentAnchor = localAwarenessState.cursor == null ? null : Y.createRelativePositionFromJSON(localAwarenessState.cursor.anchor);
|
|
11897
|
+
const currentHead = localAwarenessState.cursor == null ? null : Y.createRelativePositionFromJSON(localAwarenessState.cursor.head);
|
|
14755
11898
|
if (sel != null) {
|
|
14756
|
-
const anchor = createRelativePositionFromTypeIndex(ytext, sel.anchor);
|
|
14757
|
-
const head = createRelativePositionFromTypeIndex(ytext, sel.head);
|
|
14758
|
-
if (localAwarenessState.cursor == null || !compareRelativePositions(currentAnchor, anchor) || !compareRelativePositions(currentHead, head)) {
|
|
11899
|
+
const anchor = Y.createRelativePositionFromTypeIndex(ytext, sel.anchor);
|
|
11900
|
+
const head = Y.createRelativePositionFromTypeIndex(ytext, sel.head);
|
|
11901
|
+
if (localAwarenessState.cursor == null || !Y.compareRelativePositions(currentAnchor, anchor) || !Y.compareRelativePositions(currentHead, head)) {
|
|
14759
11902
|
awareness.setLocalStateField("cursor", {
|
|
14760
11903
|
anchor,
|
|
14761
11904
|
head
|
|
@@ -14773,8 +11916,8 @@ class YRemoteSelectionsPluginValue {
|
|
|
14773
11916
|
if (cursor == null || cursor.anchor == null || cursor.head == null) {
|
|
14774
11917
|
return;
|
|
14775
11918
|
}
|
|
14776
|
-
const anchor = createAbsolutePositionFromRelativePosition(cursor.anchor, ydoc);
|
|
14777
|
-
const head = createAbsolutePositionFromRelativePosition(cursor.head, ydoc);
|
|
11919
|
+
const anchor = Y.createAbsolutePositionFromRelativePosition(cursor.anchor, ydoc);
|
|
11920
|
+
const head = Y.createAbsolutePositionFromRelativePosition(cursor.head, ydoc);
|
|
14778
11921
|
if (anchor == null || head == null || anchor.type !== ytext || head.type !== ytext) {
|
|
14779
11922
|
return;
|
|
14780
11923
|
}
|
|
@@ -14938,7 +12081,7 @@ class YUndoManagerPluginValue {
|
|
|
14938
12081
|
const yUndoManager = ViewPlugin.fromClass(YUndoManagerPluginValue);
|
|
14939
12082
|
const undo = ({ state, dispatch }) => state.facet(yUndoManagerFacet).undo() || true;
|
|
14940
12083
|
const redo = ({ state, dispatch }) => state.facet(yUndoManagerFacet).redo() || true;
|
|
14941
|
-
const yCollab = (ytext, awareness, { undoManager = new UndoManager(ytext) } = {}) => {
|
|
12084
|
+
const yCollab = (ytext, awareness, { undoManager = new Y.UndoManager(ytext) } = {}) => {
|
|
14942
12085
|
const ySyncConfig = new YSyncConfig(ytext, awareness);
|
|
14943
12086
|
const plugins = [
|
|
14944
12087
|
ySyncFacet.of(ySyncConfig),
|
|
@@ -15113,11 +12256,11 @@ class NodeType {
|
|
|
15113
12256
|
names, separated by spaces, in a single property name to map
|
|
15114
12257
|
multiple node names to a single value.
|
|
15115
12258
|
*/
|
|
15116
|
-
static match(
|
|
12259
|
+
static match(map) {
|
|
15117
12260
|
let direct = /* @__PURE__ */ Object.create(null);
|
|
15118
|
-
for (let prop in
|
|
12261
|
+
for (let prop in map)
|
|
15119
12262
|
for (let name2 of prop.split(" "))
|
|
15120
|
-
direct[name2] =
|
|
12263
|
+
direct[name2] = map[prop];
|
|
15121
12264
|
return (node) => {
|
|
15122
12265
|
for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
|
|
15123
12266
|
let found = direct[i < 0 ? node.name : groups[i]];
|
|
@@ -15179,11 +12322,11 @@ class Tree {
|
|
|
15179
12322
|
/**
|
|
15180
12323
|
Construct a new tree. See also [`Tree.build`](#common.Tree^build).
|
|
15181
12324
|
*/
|
|
15182
|
-
constructor(type, children, positions,
|
|
12325
|
+
constructor(type, children, positions, length, props) {
|
|
15183
12326
|
this.type = type;
|
|
15184
12327
|
this.children = children;
|
|
15185
12328
|
this.positions = positions;
|
|
15186
|
-
this.length =
|
|
12329
|
+
this.length = length;
|
|
15187
12330
|
this.props = null;
|
|
15188
12331
|
if (props && props.length) {
|
|
15189
12332
|
this.props = /* @__PURE__ */ Object.create(null);
|
|
@@ -15327,7 +12470,7 @@ class Tree {
|
|
|
15327
12470
|
[`NodeType.none`](#common.NodeType^none).
|
|
15328
12471
|
*/
|
|
15329
12472
|
balance(config = {}) {
|
|
15330
|
-
return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions,
|
|
12473
|
+
return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new Tree(this.type, children, positions, length, this.propValues), config.makeTree || ((children, positions, length) => new Tree(NodeType.none, children, positions, length)));
|
|
15331
12474
|
}
|
|
15332
12475
|
/**
|
|
15333
12476
|
Build a tree from a postfix-ordered buffer of node information,
|
|
@@ -15369,9 +12512,9 @@ class TreeBuffer {
|
|
|
15369
12512
|
/**
|
|
15370
12513
|
Create a tree buffer.
|
|
15371
12514
|
*/
|
|
15372
|
-
constructor(buffer,
|
|
12515
|
+
constructor(buffer, length, set) {
|
|
15373
12516
|
this.buffer = buffer;
|
|
15374
|
-
this.length =
|
|
12517
|
+
this.length = length;
|
|
15375
12518
|
this.set = set;
|
|
15376
12519
|
}
|
|
15377
12520
|
/**
|
|
@@ -15428,15 +12571,15 @@ class TreeBuffer {
|
|
|
15428
12571
|
*/
|
|
15429
12572
|
slice(startI, endI, from2) {
|
|
15430
12573
|
let b = this.buffer;
|
|
15431
|
-
let
|
|
12574
|
+
let copy = new Uint16Array(endI - startI), len = 0;
|
|
15432
12575
|
for (let i = startI, j = 0; i < endI; ) {
|
|
15433
|
-
|
|
15434
|
-
|
|
15435
|
-
let to =
|
|
15436
|
-
|
|
12576
|
+
copy[j++] = b[i++];
|
|
12577
|
+
copy[j++] = b[i++] - from2;
|
|
12578
|
+
let to = copy[j++] = b[i++] - from2;
|
|
12579
|
+
copy[j++] = b[i++] - startI;
|
|
15437
12580
|
len = Math.max(len, to);
|
|
15438
12581
|
}
|
|
15439
|
-
return new TreeBuffer(
|
|
12582
|
+
return new TreeBuffer(copy, len, this.set);
|
|
15440
12583
|
}
|
|
15441
12584
|
}
|
|
15442
12585
|
function checkSide(side, pos, from2, to) {
|
|
@@ -16296,15 +13439,15 @@ function buildTree(data) {
|
|
|
16296
13439
|
}
|
|
16297
13440
|
}
|
|
16298
13441
|
function makeBalanced(type) {
|
|
16299
|
-
return (children2, positions2,
|
|
13442
|
+
return (children2, positions2, length2) => {
|
|
16300
13443
|
let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
|
|
16301
13444
|
if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
|
|
16302
|
-
if (!lastI && last.type == type && last.length ==
|
|
13445
|
+
if (!lastI && last.type == type && last.length == length2)
|
|
16303
13446
|
return last;
|
|
16304
13447
|
if (lookAheadProp = last.prop(NodeProp.lookAhead))
|
|
16305
13448
|
lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
|
|
16306
13449
|
}
|
|
16307
|
-
return makeTree(type, children2, positions2,
|
|
13450
|
+
return makeTree(type, children2, positions2, length2, lookAhead2);
|
|
16308
13451
|
};
|
|
16309
13452
|
}
|
|
16310
13453
|
function makeRepeatLeaf(children2, positions2, base2, i, from2, to, type, lookAhead2) {
|
|
@@ -16316,7 +13459,7 @@ function buildTree(data) {
|
|
|
16316
13459
|
children2.push(makeTree(nodeSet2.types[type], localChildren, localPositions, to - from2, lookAhead2 - to));
|
|
16317
13460
|
positions2.push(from2 - base2);
|
|
16318
13461
|
}
|
|
16319
|
-
function makeTree(type, children2, positions2,
|
|
13462
|
+
function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
|
|
16320
13463
|
if (contextHash) {
|
|
16321
13464
|
let pair2 = [NodeProp.contextHash, contextHash];
|
|
16322
13465
|
props = props ? [pair2].concat(props) : [pair2];
|
|
@@ -16325,7 +13468,7 @@ function buildTree(data) {
|
|
|
16325
13468
|
let pair2 = [NodeProp.lookAhead, lookAhead2];
|
|
16326
13469
|
props = props ? [pair2].concat(props) : [pair2];
|
|
16327
13470
|
}
|
|
16328
|
-
return new Tree(type, children2, positions2,
|
|
13471
|
+
return new Tree(type, children2, positions2, length2, props);
|
|
16329
13472
|
}
|
|
16330
13473
|
function findBufferSize(maxSize, inRepeat) {
|
|
16331
13474
|
let fork = cursor.fork();
|
|
@@ -16395,8 +13538,8 @@ function buildTree(data) {
|
|
|
16395
13538
|
let children = [], positions = [];
|
|
16396
13539
|
while (cursor.pos > 0)
|
|
16397
13540
|
takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1, 0);
|
|
16398
|
-
let
|
|
16399
|
-
return new Tree(types2[data.topID], children.reverse(), positions.reverse(),
|
|
13541
|
+
let length = (_a2 = data.length) !== null && _a2 !== void 0 ? _a2 : children.length ? positions[0] + children[0].length : 0;
|
|
13542
|
+
return new Tree(types2[data.topID], children.reverse(), positions.reverse(), length);
|
|
16400
13543
|
}
|
|
16401
13544
|
const nodeSizeCache = /* @__PURE__ */ new WeakMap();
|
|
16402
13545
|
function nodeSize(balanceType, node) {
|
|
@@ -16416,7 +13559,7 @@ function nodeSize(balanceType, node) {
|
|
|
16416
13559
|
}
|
|
16417
13560
|
return size;
|
|
16418
13561
|
}
|
|
16419
|
-
function balanceRange(balanceType, children, positions, from2, to, start2,
|
|
13562
|
+
function balanceRange(balanceType, children, positions, from2, to, start2, length, mkTop, mkTree) {
|
|
16420
13563
|
let total = 0;
|
|
16421
13564
|
for (let i = from2; i < to; i++)
|
|
16422
13565
|
total += nodeSize(balanceType, children[i]);
|
|
@@ -16443,14 +13586,14 @@ function balanceRange(balanceType, children, positions, from2, to, start2, lengt
|
|
|
16443
13586
|
}
|
|
16444
13587
|
localChildren.push(children2[groupFrom]);
|
|
16445
13588
|
} else {
|
|
16446
|
-
let
|
|
16447
|
-
localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart,
|
|
13589
|
+
let length2 = positions2[i - 1] + children2[i - 1].length - groupStart;
|
|
13590
|
+
localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length2, null, mkTree));
|
|
16448
13591
|
}
|
|
16449
13592
|
localPositions.push(groupStart + offset - start2);
|
|
16450
13593
|
}
|
|
16451
13594
|
}
|
|
16452
13595
|
divide(children, positions, from2, to, 0);
|
|
16453
|
-
return (mkTop || mkTree)(localChildren, localPositions,
|
|
13596
|
+
return (mkTop || mkTree)(localChildren, localPositions, length);
|
|
16454
13597
|
}
|
|
16455
13598
|
class NodeWeakMap {
|
|
16456
13599
|
constructor() {
|
|
@@ -16807,7 +13950,7 @@ function materialize(cursor) {
|
|
|
16807
13950
|
} while (!cursor.tree);
|
|
16808
13951
|
let base2 = cursor.tree, i = base2.children.indexOf(buffer);
|
|
16809
13952
|
let buf = base2.children[i], b = buf.buffer, newStack = [i];
|
|
16810
|
-
function split(startI, endI, type, innerOffset,
|
|
13953
|
+
function split(startI, endI, type, innerOffset, length, stackPos) {
|
|
16811
13954
|
let targetI = stack[stackPos];
|
|
16812
13955
|
let children = [], positions = [];
|
|
16813
13956
|
sliceBuf(buf, startI, targetI, children, positions, innerOffset);
|
|
@@ -16817,7 +13960,7 @@ function materialize(cursor) {
|
|
|
16817
13960
|
children.push(child);
|
|
16818
13961
|
positions.push(from2 - innerOffset);
|
|
16819
13962
|
sliceBuf(buf, b[targetI + 3], endI, children, positions, innerOffset);
|
|
16820
|
-
return new Tree(type, children, positions,
|
|
13963
|
+
return new Tree(type, children, positions, length);
|
|
16821
13964
|
}
|
|
16822
13965
|
base2.children[i] = split(0, b.length, NodeType.none, 0, buf.length, stack.length - 1);
|
|
16823
13966
|
for (let index of newStack) {
|
|
@@ -16912,7 +14055,7 @@ let FragmentCursor$1 = class FragmentCursor {
|
|
|
16912
14055
|
}
|
|
16913
14056
|
};
|
|
16914
14057
|
function punchRanges(outer, ranges) {
|
|
16915
|
-
let
|
|
14058
|
+
let copy = null, current = ranges;
|
|
16916
14059
|
for (let i = 1, j = 0; i < outer.length; i++) {
|
|
16917
14060
|
let gapFrom = outer[i - 1].to, gapTo = outer[i].from;
|
|
16918
14061
|
for (; j < current.length; j++) {
|
|
@@ -16921,16 +14064,16 @@ function punchRanges(outer, ranges) {
|
|
|
16921
14064
|
break;
|
|
16922
14065
|
if (r2.to <= gapFrom)
|
|
16923
14066
|
continue;
|
|
16924
|
-
if (!
|
|
16925
|
-
current =
|
|
14067
|
+
if (!copy)
|
|
14068
|
+
current = copy = ranges.slice();
|
|
16926
14069
|
if (r2.from < gapFrom) {
|
|
16927
|
-
|
|
14070
|
+
copy[j] = new Range2(r2.from, gapFrom);
|
|
16928
14071
|
if (r2.to > gapTo)
|
|
16929
|
-
|
|
14072
|
+
copy.splice(j + 1, 0, new Range2(gapTo, r2.to));
|
|
16930
14073
|
} else if (r2.to > gapTo) {
|
|
16931
|
-
|
|
14074
|
+
copy[j--] = new Range2(gapTo, r2.to);
|
|
16932
14075
|
} else {
|
|
16933
|
-
|
|
14076
|
+
copy.splice(j--, 1);
|
|
16934
14077
|
}
|
|
16935
14078
|
}
|
|
16936
14079
|
}
|
|
@@ -17142,13 +14285,13 @@ class Rule {
|
|
|
17142
14285
|
}
|
|
17143
14286
|
Rule.empty = new Rule([], 2, null);
|
|
17144
14287
|
function tagHighlighter(tags2, options) {
|
|
17145
|
-
let
|
|
14288
|
+
let map = /* @__PURE__ */ Object.create(null);
|
|
17146
14289
|
for (let style of tags2) {
|
|
17147
14290
|
if (!Array.isArray(style.tag))
|
|
17148
|
-
|
|
14291
|
+
map[style.tag.id] = style.class;
|
|
17149
14292
|
else
|
|
17150
14293
|
for (let tag of style.tag)
|
|
17151
|
-
|
|
14294
|
+
map[tag.id] = style.class;
|
|
17152
14295
|
}
|
|
17153
14296
|
let { scope, all = null } = options || {};
|
|
17154
14297
|
return {
|
|
@@ -17156,7 +14299,7 @@ function tagHighlighter(tags2, options) {
|
|
|
17156
14299
|
let cls = all;
|
|
17157
14300
|
for (let tag of tags3) {
|
|
17158
14301
|
for (let sub of tag.set) {
|
|
17159
|
-
let tagClass =
|
|
14302
|
+
let tagClass = map[sub.id];
|
|
17160
14303
|
if (tagClass) {
|
|
17161
14304
|
cls = cls ? cls + " " + tagClass : tagClass;
|
|
17162
14305
|
break;
|
|
@@ -19639,10 +16782,10 @@ class Stack {
|
|
|
19639
16782
|
@internal
|
|
19640
16783
|
*/
|
|
19641
16784
|
recoverByDelete(next, nextEnd) {
|
|
19642
|
-
let
|
|
19643
|
-
if (
|
|
16785
|
+
let isNode = next <= this.p.parser.maxNode;
|
|
16786
|
+
if (isNode)
|
|
19644
16787
|
this.storeNode(next, this.pos, nextEnd, 4);
|
|
19645
|
-
this.storeNode(0, this.pos, nextEnd,
|
|
16788
|
+
this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
|
|
19646
16789
|
this.pos = this.reducePos = nextEnd;
|
|
19647
16790
|
this.score -= 190;
|
|
19648
16791
|
}
|
|
@@ -21043,42 +18186,42 @@ class LRParser extends Parser {
|
|
|
21043
18186
|
kept from the original parser.
|
|
21044
18187
|
*/
|
|
21045
18188
|
configure(config) {
|
|
21046
|
-
let
|
|
18189
|
+
let copy = Object.assign(Object.create(LRParser.prototype), this);
|
|
21047
18190
|
if (config.props)
|
|
21048
|
-
|
|
18191
|
+
copy.nodeSet = this.nodeSet.extend(...config.props);
|
|
21049
18192
|
if (config.top) {
|
|
21050
18193
|
let info = this.topRules[config.top];
|
|
21051
18194
|
if (!info)
|
|
21052
18195
|
throw new RangeError(`Invalid top rule name ${config.top}`);
|
|
21053
|
-
|
|
18196
|
+
copy.top = info;
|
|
21054
18197
|
}
|
|
21055
18198
|
if (config.tokenizers)
|
|
21056
|
-
|
|
18199
|
+
copy.tokenizers = this.tokenizers.map((t2) => {
|
|
21057
18200
|
let found = config.tokenizers.find((r2) => r2.from == t2);
|
|
21058
18201
|
return found ? found.to : t2;
|
|
21059
18202
|
});
|
|
21060
18203
|
if (config.specializers) {
|
|
21061
|
-
|
|
21062
|
-
|
|
18204
|
+
copy.specializers = this.specializers.slice();
|
|
18205
|
+
copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
|
|
21063
18206
|
let found = config.specializers.find((r2) => r2.from == s.external);
|
|
21064
18207
|
if (!found)
|
|
21065
18208
|
return s;
|
|
21066
18209
|
let spec = Object.assign(Object.assign({}, s), { external: found.to });
|
|
21067
|
-
|
|
18210
|
+
copy.specializers[i] = getSpecializer(spec);
|
|
21068
18211
|
return spec;
|
|
21069
18212
|
});
|
|
21070
18213
|
}
|
|
21071
18214
|
if (config.contextTracker)
|
|
21072
|
-
|
|
18215
|
+
copy.context = config.contextTracker;
|
|
21073
18216
|
if (config.dialect)
|
|
21074
|
-
|
|
18217
|
+
copy.dialect = this.parseDialect(config.dialect);
|
|
21075
18218
|
if (config.strict != null)
|
|
21076
|
-
|
|
18219
|
+
copy.strict = config.strict;
|
|
21077
18220
|
if (config.wrap)
|
|
21078
|
-
|
|
18221
|
+
copy.wrappers = copy.wrappers.concat(config.wrap);
|
|
21079
18222
|
if (config.bufferLength != null)
|
|
21080
|
-
|
|
21081
|
-
return
|
|
18223
|
+
copy.bufferLength = config.bufferLength;
|
|
18224
|
+
return copy;
|
|
21082
18225
|
}
|
|
21083
18226
|
/**
|
|
21084
18227
|
Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
|
|
@@ -24148,7 +21291,7 @@ const jsonLanguage = /* @__PURE__ */ LRLanguage.define({
|
|
|
24148
21291
|
function json() {
|
|
24149
21292
|
return new LanguageSupport(jsonLanguage);
|
|
24150
21293
|
}
|
|
24151
|
-
const castOpen = 1, HeredocString = 2, interpolatedStringContent = 263, EscapeSequence = 3, afterInterpolation = 264, automaticSemicolon = 265, eof$1 = 266, abstract = 4, and = 5, array = 6, as = 7, Boolean$1 = 8, _break = 9, _case = 10, _catch = 11, clone = 12, _const = 13, _continue = 14, _default = 15, declare = 16, _do = 17, echo = 18, _else = 19, elseif = 20, enddeclare = 21, endfor = 22, endforeach = 23, endif = 24, endswitch = 25, endwhile = 26, _enum = 27, _extends = 28, final = 29, _finally = 30, fn = 31, _for = 32, foreach = 33, from = 34, _function = 35, global
|
|
21294
|
+
const castOpen = 1, HeredocString = 2, interpolatedStringContent = 263, EscapeSequence = 3, afterInterpolation = 264, automaticSemicolon = 265, eof$1 = 266, abstract = 4, and = 5, array = 6, as = 7, Boolean$1 = 8, _break = 9, _case = 10, _catch = 11, clone = 12, _const = 13, _continue = 14, _default = 15, declare = 16, _do = 17, echo = 18, _else = 19, elseif = 20, enddeclare = 21, endfor = 22, endforeach = 23, endif = 24, endswitch = 25, endwhile = 26, _enum = 27, _extends = 28, final = 29, _finally = 30, fn = 31, _for = 32, foreach = 33, from = 34, _function = 35, global = 36, goto = 37, _if = 38, _implements = 39, include = 40, include_once = 41, _instanceof = 42, insteadof = 43, _interface = 44, list = 45, match = 46, namespace = 47, _new = 48, _null = 49, or = 50, print = 51, _require = 52, require_once = 53, _return = 54, _switch = 55, _throw = 56, trait = 57, _try = 58, unset = 59, use = 60, _var = 61, Visibility = 62, _while = 63, xor = 64, _yield = 65;
|
|
24152
21295
|
const keywordMap = {
|
|
24153
21296
|
abstract,
|
|
24154
21297
|
and,
|
|
@@ -24183,7 +21326,7 @@ const keywordMap = {
|
|
|
24183
21326
|
foreach,
|
|
24184
21327
|
from,
|
|
24185
21328
|
function: _function,
|
|
24186
|
-
global
|
|
21329
|
+
global,
|
|
24187
21330
|
goto,
|
|
24188
21331
|
if: _if,
|
|
24189
21332
|
implements: _implements,
|
|
@@ -29303,11 +26446,11 @@ const variables = () => ViewPlugin.fromClass(
|
|
|
29303
26446
|
)
|
|
29304
26447
|
}
|
|
29305
26448
|
);
|
|
29306
|
-
const hasProvider = (
|
|
29307
|
-
const useCodeMirror = (
|
|
26449
|
+
const hasProvider = (params) => "provider" in params && !!toValue(params.provider);
|
|
26450
|
+
const useCodeMirror = (params) => {
|
|
29308
26451
|
const codeMirror = ref(null);
|
|
29309
26452
|
watch(
|
|
29310
|
-
|
|
26453
|
+
params.codeMirrorRef,
|
|
29311
26454
|
() => {
|
|
29312
26455
|
var _a2;
|
|
29313
26456
|
(_a2 = codeMirror.value) == null ? void 0 : _a2.destroy();
|
|
@@ -29320,38 +26463,38 @@ const useCodeMirror = (params2) => {
|
|
|
29320
26463
|
return (_a2 = codeMirror.value) == null ? void 0 : _a2.destroy();
|
|
29321
26464
|
});
|
|
29322
26465
|
function mountCodeMirror() {
|
|
29323
|
-
if (
|
|
29324
|
-
const provider = hasProvider(
|
|
26466
|
+
if (params.codeMirrorRef.value) {
|
|
26467
|
+
const provider = hasProvider(params) ? toValue(params.provider) : null;
|
|
29325
26468
|
const extensions = getCodeMirrorExtensions({
|
|
29326
26469
|
...extensionConfig.value,
|
|
29327
26470
|
provider
|
|
29328
26471
|
});
|
|
29329
26472
|
codeMirror.value = new EditorView({
|
|
29330
|
-
parent:
|
|
26473
|
+
parent: params.codeMirrorRef.value,
|
|
29331
26474
|
extensions
|
|
29332
26475
|
});
|
|
29333
|
-
if (!hasProvider(
|
|
29334
|
-
setCodeMirrorContent(toValue(
|
|
26476
|
+
if (!hasProvider(params))
|
|
26477
|
+
setCodeMirrorContent(toValue(params.content));
|
|
29335
26478
|
}
|
|
29336
26479
|
}
|
|
29337
26480
|
const extensionConfig = computed(() => ({
|
|
29338
|
-
onChange:
|
|
29339
|
-
onBlur:
|
|
29340
|
-
onFocus:
|
|
29341
|
-
languages: toValue(
|
|
29342
|
-
classes: toValue(
|
|
29343
|
-
readOnly: toValue(
|
|
29344
|
-
lineNumbers: toValue(
|
|
29345
|
-
withVariables: toValue(
|
|
29346
|
-
disableEnter: toValue(
|
|
29347
|
-
withoutTheme: toValue(
|
|
29348
|
-
additionalExtensions: toValue(
|
|
26481
|
+
onChange: params.onChange,
|
|
26482
|
+
onBlur: params.onBlur,
|
|
26483
|
+
onFocus: params.onFocus,
|
|
26484
|
+
languages: toValue(params.languages),
|
|
26485
|
+
classes: toValue(params.classes),
|
|
26486
|
+
readOnly: toValue(params.readOnly),
|
|
26487
|
+
lineNumbers: toValue(params.lineNumbers),
|
|
26488
|
+
withVariables: toValue(params.withVariables),
|
|
26489
|
+
disableEnter: toValue(params.withVariables),
|
|
26490
|
+
withoutTheme: toValue(params.withoutTheme),
|
|
26491
|
+
additionalExtensions: toValue(params.extensions)
|
|
29349
26492
|
}));
|
|
29350
26493
|
watch(
|
|
29351
|
-
() => hasProvider(
|
|
26494
|
+
() => hasProvider(params) ? toValue(params.provider) : null,
|
|
29352
26495
|
() => {
|
|
29353
26496
|
var _a2;
|
|
29354
|
-
if (hasProvider(
|
|
26497
|
+
if (hasProvider(params)) {
|
|
29355
26498
|
(_a2 = codeMirror.value) == null ? void 0 : _a2.destroy();
|
|
29356
26499
|
mountCodeMirror();
|
|
29357
26500
|
}
|
|
@@ -29363,7 +26506,7 @@ const useCodeMirror = (params2) => {
|
|
|
29363
26506
|
if (!codeMirror.value)
|
|
29364
26507
|
return;
|
|
29365
26508
|
else {
|
|
29366
|
-
const provider = hasProvider(
|
|
26509
|
+
const provider = hasProvider(params) ? toValue(params.provider) : null;
|
|
29367
26510
|
const extensions = getCodeMirrorExtensions({
|
|
29368
26511
|
...extensionConfig.value,
|
|
29369
26512
|
provider
|
|
@@ -29395,11 +26538,11 @@ const useCodeMirror = (params2) => {
|
|
|
29395
26538
|
});
|
|
29396
26539
|
};
|
|
29397
26540
|
watch(
|
|
29398
|
-
() => toValue(
|
|
26541
|
+
() => toValue(params.content),
|
|
29399
26542
|
() => {
|
|
29400
|
-
if (hasProvider(
|
|
26543
|
+
if (hasProvider(params))
|
|
29401
26544
|
return;
|
|
29402
|
-
setCodeMirrorContent(toValue(
|
|
26545
|
+
setCodeMirrorContent(toValue(params.content));
|
|
29403
26546
|
},
|
|
29404
26547
|
{ immediate: true }
|
|
29405
26548
|
);
|