@hocuspocus/provider 4.0.0-rc.5 → 4.0.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hocuspocus-provider.cjs +61 -1167
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +24 -1131
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/index.d.ts +10 -162
- package/package.json +3 -3
|
@@ -27,1005 +27,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
29
|
let _hocuspocus_common = require("@hocuspocus/common");
|
|
30
|
+
let y_protocols_awareness = require("y-protocols/awareness");
|
|
31
|
+
y_protocols_awareness = __toESM(y_protocols_awareness);
|
|
30
32
|
let yjs = require("yjs");
|
|
31
33
|
yjs = __toESM(yjs);
|
|
32
34
|
let _lifeomic_attempt = require("@lifeomic/attempt");
|
|
35
|
+
let lib0_decoding = require("lib0/decoding");
|
|
36
|
+
let lib0_encoding = require("lib0/encoding");
|
|
37
|
+
lib0_encoding = __toESM(lib0_encoding);
|
|
38
|
+
let lib0_time = require("lib0/time");
|
|
39
|
+
lib0_time = __toESM(lib0_time);
|
|
40
|
+
let y_protocols_sync = require("y-protocols/sync");
|
|
41
|
+
y_protocols_sync = __toESM(y_protocols_sync);
|
|
33
42
|
|
|
34
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/math.js
|
|
35
|
-
/**
|
|
36
|
-
* Common Math expressions.
|
|
37
|
-
*
|
|
38
|
-
* @module math
|
|
39
|
-
*/
|
|
40
|
-
const floor = Math.floor;
|
|
41
|
-
/**
|
|
42
|
-
* @function
|
|
43
|
-
* @param {number} a
|
|
44
|
-
* @param {number} b
|
|
45
|
-
* @return {number} The smaller element of a and b
|
|
46
|
-
*/
|
|
47
|
-
const min = (a, b) => a < b ? a : b;
|
|
48
|
-
/**
|
|
49
|
-
* @function
|
|
50
|
-
* @param {number} a
|
|
51
|
-
* @param {number} b
|
|
52
|
-
* @return {number} The bigger element of a and b
|
|
53
|
-
*/
|
|
54
|
-
const max = (a, b) => a > b ? a : b;
|
|
55
|
-
const isNaN$1 = Number.isNaN;
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/binary.js
|
|
59
|
-
const BIT7 = 64;
|
|
60
|
-
const BIT8 = 128;
|
|
61
|
-
const BIT18 = 1 << 17;
|
|
62
|
-
const BIT19 = 1 << 18;
|
|
63
|
-
const BIT20 = 1 << 19;
|
|
64
|
-
const BIT21 = 1 << 20;
|
|
65
|
-
const BIT22 = 1 << 21;
|
|
66
|
-
const BIT23 = 1 << 22;
|
|
67
|
-
const BIT24 = 1 << 23;
|
|
68
|
-
const BIT25 = 1 << 24;
|
|
69
|
-
const BIT26 = 1 << 25;
|
|
70
|
-
const BIT27 = 1 << 26;
|
|
71
|
-
const BIT28 = 1 << 27;
|
|
72
|
-
const BIT29 = 1 << 28;
|
|
73
|
-
const BIT30 = 1 << 29;
|
|
74
|
-
const BIT31 = 1 << 30;
|
|
75
|
-
const BIT32 = 1 << 31;
|
|
76
|
-
const BITS6 = 63;
|
|
77
|
-
const BITS7 = 127;
|
|
78
|
-
const BITS17 = BIT18 - 1;
|
|
79
|
-
const BITS18 = BIT19 - 1;
|
|
80
|
-
const BITS19 = BIT20 - 1;
|
|
81
|
-
const BITS20 = BIT21 - 1;
|
|
82
|
-
const BITS21 = BIT22 - 1;
|
|
83
|
-
const BITS22 = BIT23 - 1;
|
|
84
|
-
const BITS23 = BIT24 - 1;
|
|
85
|
-
const BITS24 = BIT25 - 1;
|
|
86
|
-
const BITS25 = BIT26 - 1;
|
|
87
|
-
const BITS26 = BIT27 - 1;
|
|
88
|
-
const BITS27 = BIT28 - 1;
|
|
89
|
-
const BITS28 = BIT29 - 1;
|
|
90
|
-
const BITS29 = BIT30 - 1;
|
|
91
|
-
const BITS30 = BIT31 - 1;
|
|
92
|
-
/**
|
|
93
|
-
* @type {number}
|
|
94
|
-
*/
|
|
95
|
-
const BITS31 = 2147483647;
|
|
96
|
-
/**
|
|
97
|
-
* @type {number}
|
|
98
|
-
*/
|
|
99
|
-
const BITS32 = 4294967295;
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/number.js
|
|
103
|
-
/**
|
|
104
|
-
* Utility helpers for working with numbers.
|
|
105
|
-
*
|
|
106
|
-
* @module number
|
|
107
|
-
*/
|
|
108
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
109
|
-
const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER;
|
|
110
|
-
const LOWEST_INT32 = 1 << 31;
|
|
111
|
-
const HIGHEST_INT32 = BITS31;
|
|
112
|
-
const HIGHEST_UINT32 = BITS32;
|
|
113
|
-
/* c8 ignore next */
|
|
114
|
-
const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor(num) === num);
|
|
115
|
-
const isNaN = Number.isNaN;
|
|
116
|
-
const parseInt = Number.parseInt;
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/set.js
|
|
120
|
-
/**
|
|
121
|
-
* Utility module to work with sets.
|
|
122
|
-
*
|
|
123
|
-
* @module set
|
|
124
|
-
*/
|
|
125
|
-
const create$2 = () => /* @__PURE__ */ new Set();
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/array.js
|
|
129
|
-
/**
|
|
130
|
-
* Transforms something array-like to an actual Array.
|
|
131
|
-
*
|
|
132
|
-
* @function
|
|
133
|
-
* @template T
|
|
134
|
-
* @param {ArrayLike<T>|Iterable<T>} arraylike
|
|
135
|
-
* @return {T}
|
|
136
|
-
*/
|
|
137
|
-
const from = Array.from;
|
|
138
|
-
const isArray$1 = Array.isArray;
|
|
139
|
-
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/string.js
|
|
142
|
-
/**
|
|
143
|
-
* Utility module to work with strings.
|
|
144
|
-
*
|
|
145
|
-
* @module string
|
|
146
|
-
*/
|
|
147
|
-
const fromCharCode = String.fromCharCode;
|
|
148
|
-
const fromCodePoint = String.fromCodePoint;
|
|
149
|
-
/**
|
|
150
|
-
* The largest utf16 character.
|
|
151
|
-
* Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
|
|
152
|
-
*/
|
|
153
|
-
const MAX_UTF16_CHARACTER = fromCharCode(65535);
|
|
154
|
-
/**
|
|
155
|
-
* @param {string} str
|
|
156
|
-
* @return {Uint8Array<ArrayBuffer>}
|
|
157
|
-
*/
|
|
158
|
-
const _encodeUtf8Polyfill = (str) => {
|
|
159
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
160
|
-
const len = encodedString.length;
|
|
161
|
-
const buf = new Uint8Array(len);
|
|
162
|
-
for (let i = 0; i < len; i++) buf[i] = encodedString.codePointAt(i);
|
|
163
|
-
return buf;
|
|
164
|
-
};
|
|
165
|
-
/* c8 ignore next */
|
|
166
|
-
const utf8TextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null;
|
|
167
|
-
/**
|
|
168
|
-
* @param {string} str
|
|
169
|
-
* @return {Uint8Array<ArrayBuffer>}
|
|
170
|
-
*/
|
|
171
|
-
const _encodeUtf8Native = (str) => utf8TextEncoder.encode(str);
|
|
172
|
-
/**
|
|
173
|
-
* @param {string} str
|
|
174
|
-
* @return {Uint8Array}
|
|
175
|
-
*/
|
|
176
|
-
/* c8 ignore next */
|
|
177
|
-
const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill;
|
|
178
|
-
/* c8 ignore next */
|
|
179
|
-
let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8", {
|
|
180
|
-
fatal: true,
|
|
181
|
-
ignoreBOM: true
|
|
182
|
-
});
|
|
183
|
-
/* c8 ignore start */
|
|
184
|
-
if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1)
|
|
185
|
-
/* c8 ignore next */
|
|
186
|
-
utf8TextDecoder = null;
|
|
187
|
-
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/encoding.js
|
|
190
|
-
/**
|
|
191
|
-
* Efficient schema-less binary encoding with support for variable length encoding.
|
|
192
|
-
*
|
|
193
|
-
* Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.
|
|
194
|
-
*
|
|
195
|
-
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
196
|
-
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
197
|
-
* which is also used in Protocol Buffers.
|
|
198
|
-
*
|
|
199
|
-
* ```js
|
|
200
|
-
* // encoding step
|
|
201
|
-
* const encoder = encoding.createEncoder()
|
|
202
|
-
* encoding.writeVarUint(encoder, 256)
|
|
203
|
-
* encoding.writeVarString(encoder, 'Hello world!')
|
|
204
|
-
* const buf = encoding.toUint8Array(encoder)
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* ```js
|
|
208
|
-
* // decoding step
|
|
209
|
-
* const decoder = decoding.createDecoder(buf)
|
|
210
|
-
* decoding.readVarUint(decoder) // => 256
|
|
211
|
-
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
212
|
-
* decoding.hasContent(decoder) // => false - all data is read
|
|
213
|
-
* ```
|
|
214
|
-
*
|
|
215
|
-
* @module encoding
|
|
216
|
-
*/
|
|
217
|
-
/**
|
|
218
|
-
* A BinaryEncoder handles the encoding to an Uint8Array.
|
|
219
|
-
*/
|
|
220
|
-
var Encoder = class {
|
|
221
|
-
constructor() {
|
|
222
|
-
this.cpos = 0;
|
|
223
|
-
this.cbuf = new Uint8Array(100);
|
|
224
|
-
/**
|
|
225
|
-
* @type {Array<Uint8Array>}
|
|
226
|
-
*/
|
|
227
|
-
this.bufs = [];
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* @function
|
|
232
|
-
* @return {Encoder}
|
|
233
|
-
*/
|
|
234
|
-
const createEncoder = () => new Encoder();
|
|
235
|
-
/**
|
|
236
|
-
* The current length of the encoded data.
|
|
237
|
-
*
|
|
238
|
-
* @function
|
|
239
|
-
* @param {Encoder} encoder
|
|
240
|
-
* @return {number}
|
|
241
|
-
*/
|
|
242
|
-
const length = (encoder) => {
|
|
243
|
-
let len = encoder.cpos;
|
|
244
|
-
for (let i = 0; i < encoder.bufs.length; i++) len += encoder.bufs[i].length;
|
|
245
|
-
return len;
|
|
246
|
-
};
|
|
247
|
-
/**
|
|
248
|
-
* Transform to Uint8Array.
|
|
249
|
-
*
|
|
250
|
-
* @function
|
|
251
|
-
* @param {Encoder} encoder
|
|
252
|
-
* @return {Uint8Array<ArrayBuffer>} The created ArrayBuffer.
|
|
253
|
-
*/
|
|
254
|
-
const toUint8Array = (encoder) => {
|
|
255
|
-
const uint8arr = new Uint8Array(length(encoder));
|
|
256
|
-
let curPos = 0;
|
|
257
|
-
for (let i = 0; i < encoder.bufs.length; i++) {
|
|
258
|
-
const d = encoder.bufs[i];
|
|
259
|
-
uint8arr.set(d, curPos);
|
|
260
|
-
curPos += d.length;
|
|
261
|
-
}
|
|
262
|
-
uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
|
|
263
|
-
return uint8arr;
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* Write one byte to the encoder.
|
|
267
|
-
*
|
|
268
|
-
* @function
|
|
269
|
-
* @param {Encoder} encoder
|
|
270
|
-
* @param {number} num The byte that is to be encoded.
|
|
271
|
-
*/
|
|
272
|
-
const write = (encoder, num) => {
|
|
273
|
-
const bufferLen = encoder.cbuf.length;
|
|
274
|
-
if (encoder.cpos === bufferLen) {
|
|
275
|
-
encoder.bufs.push(encoder.cbuf);
|
|
276
|
-
encoder.cbuf = new Uint8Array(bufferLen * 2);
|
|
277
|
-
encoder.cpos = 0;
|
|
278
|
-
}
|
|
279
|
-
encoder.cbuf[encoder.cpos++] = num;
|
|
280
|
-
};
|
|
281
|
-
/**
|
|
282
|
-
* Write a variable length unsigned integer. Max encodable integer is 2^53.
|
|
283
|
-
*
|
|
284
|
-
* @function
|
|
285
|
-
* @param {Encoder} encoder
|
|
286
|
-
* @param {number} num The number that is to be encoded.
|
|
287
|
-
*/
|
|
288
|
-
const writeVarUint = (encoder, num) => {
|
|
289
|
-
while (num > BITS7) {
|
|
290
|
-
write(encoder, BIT8 | BITS7 & num);
|
|
291
|
-
num = floor(num / 128);
|
|
292
|
-
}
|
|
293
|
-
write(encoder, BITS7 & num);
|
|
294
|
-
};
|
|
295
|
-
/**
|
|
296
|
-
* A cache to store strings temporarily
|
|
297
|
-
*/
|
|
298
|
-
const _strBuffer = new Uint8Array(3e4);
|
|
299
|
-
const _maxStrBSize = _strBuffer.length / 3;
|
|
300
|
-
/**
|
|
301
|
-
* Write a variable length string.
|
|
302
|
-
*
|
|
303
|
-
* @function
|
|
304
|
-
* @param {Encoder} encoder
|
|
305
|
-
* @param {String} str The string that is to be encoded.
|
|
306
|
-
*/
|
|
307
|
-
const _writeVarStringNative = (encoder, str) => {
|
|
308
|
-
if (str.length < _maxStrBSize) {
|
|
309
|
-
/* c8 ignore next */
|
|
310
|
-
const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
|
|
311
|
-
writeVarUint(encoder, written);
|
|
312
|
-
for (let i = 0; i < written; i++) write(encoder, _strBuffer[i]);
|
|
313
|
-
} else writeVarUint8Array(encoder, encodeUtf8(str));
|
|
314
|
-
};
|
|
315
|
-
/**
|
|
316
|
-
* Write a variable length string.
|
|
317
|
-
*
|
|
318
|
-
* @function
|
|
319
|
-
* @param {Encoder} encoder
|
|
320
|
-
* @param {String} str The string that is to be encoded.
|
|
321
|
-
*/
|
|
322
|
-
const _writeVarStringPolyfill = (encoder, str) => {
|
|
323
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
324
|
-
const len = encodedString.length;
|
|
325
|
-
writeVarUint(encoder, len);
|
|
326
|
-
for (let i = 0; i < len; i++) write(encoder, encodedString.codePointAt(i));
|
|
327
|
-
};
|
|
328
|
-
/**
|
|
329
|
-
* Write a variable length string.
|
|
330
|
-
*
|
|
331
|
-
* @function
|
|
332
|
-
* @param {Encoder} encoder
|
|
333
|
-
* @param {String} str The string that is to be encoded.
|
|
334
|
-
*/
|
|
335
|
-
/* c8 ignore next */
|
|
336
|
-
const writeVarString = utf8TextEncoder && utf8TextEncoder.encodeInto ? _writeVarStringNative : _writeVarStringPolyfill;
|
|
337
|
-
/**
|
|
338
|
-
* Append fixed-length Uint8Array to the encoder.
|
|
339
|
-
*
|
|
340
|
-
* @function
|
|
341
|
-
* @param {Encoder} encoder
|
|
342
|
-
* @param {Uint8Array} uint8Array
|
|
343
|
-
*/
|
|
344
|
-
const writeUint8Array = (encoder, uint8Array) => {
|
|
345
|
-
const bufferLen = encoder.cbuf.length;
|
|
346
|
-
const cpos = encoder.cpos;
|
|
347
|
-
const leftCopyLen = min(bufferLen - cpos, uint8Array.length);
|
|
348
|
-
const rightCopyLen = uint8Array.length - leftCopyLen;
|
|
349
|
-
encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos);
|
|
350
|
-
encoder.cpos += leftCopyLen;
|
|
351
|
-
if (rightCopyLen > 0) {
|
|
352
|
-
encoder.bufs.push(encoder.cbuf);
|
|
353
|
-
encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen));
|
|
354
|
-
encoder.cbuf.set(uint8Array.subarray(leftCopyLen));
|
|
355
|
-
encoder.cpos = rightCopyLen;
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
/**
|
|
359
|
-
* Append an Uint8Array to Encoder.
|
|
360
|
-
*
|
|
361
|
-
* @function
|
|
362
|
-
* @param {Encoder} encoder
|
|
363
|
-
* @param {Uint8Array} uint8Array
|
|
364
|
-
*/
|
|
365
|
-
const writeVarUint8Array = (encoder, uint8Array) => {
|
|
366
|
-
writeVarUint(encoder, uint8Array.byteLength);
|
|
367
|
-
writeUint8Array(encoder, uint8Array);
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
//#endregion
|
|
371
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/error.js
|
|
372
|
-
/**
|
|
373
|
-
* Error helpers.
|
|
374
|
-
*
|
|
375
|
-
* @module error
|
|
376
|
-
*/
|
|
377
|
-
/**
|
|
378
|
-
* @param {string} s
|
|
379
|
-
* @return {Error}
|
|
380
|
-
*/
|
|
381
|
-
/* c8 ignore next */
|
|
382
|
-
const create$1 = (s) => new Error(s);
|
|
383
|
-
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/decoding.js
|
|
386
|
-
/**
|
|
387
|
-
* Efficient schema-less binary decoding with support for variable length encoding.
|
|
388
|
-
*
|
|
389
|
-
* Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.
|
|
390
|
-
*
|
|
391
|
-
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
392
|
-
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
393
|
-
* which is also used in Protocol Buffers.
|
|
394
|
-
*
|
|
395
|
-
* ```js
|
|
396
|
-
* // encoding step
|
|
397
|
-
* const encoder = encoding.createEncoder()
|
|
398
|
-
* encoding.writeVarUint(encoder, 256)
|
|
399
|
-
* encoding.writeVarString(encoder, 'Hello world!')
|
|
400
|
-
* const buf = encoding.toUint8Array(encoder)
|
|
401
|
-
* ```
|
|
402
|
-
*
|
|
403
|
-
* ```js
|
|
404
|
-
* // decoding step
|
|
405
|
-
* const decoder = decoding.createDecoder(buf)
|
|
406
|
-
* decoding.readVarUint(decoder) // => 256
|
|
407
|
-
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
408
|
-
* decoding.hasContent(decoder) // => false - all data is read
|
|
409
|
-
* ```
|
|
410
|
-
*
|
|
411
|
-
* @module decoding
|
|
412
|
-
*/
|
|
413
|
-
const errorUnexpectedEndOfArray = create$1("Unexpected end of array");
|
|
414
|
-
const errorIntegerOutOfRange = create$1("Integer out of Range");
|
|
415
|
-
/**
|
|
416
|
-
* A Decoder handles the decoding of an Uint8Array.
|
|
417
|
-
* @template {ArrayBufferLike} [Buf=ArrayBufferLike]
|
|
418
|
-
*/
|
|
419
|
-
var Decoder = class {
|
|
420
|
-
/**
|
|
421
|
-
* @param {Uint8Array<Buf>} uint8Array Binary data to decode
|
|
422
|
-
*/
|
|
423
|
-
constructor(uint8Array) {
|
|
424
|
-
/**
|
|
425
|
-
* Decoding target.
|
|
426
|
-
*
|
|
427
|
-
* @type {Uint8Array<Buf>}
|
|
428
|
-
*/
|
|
429
|
-
this.arr = uint8Array;
|
|
430
|
-
/**
|
|
431
|
-
* Current decoding position.
|
|
432
|
-
*
|
|
433
|
-
* @type {number}
|
|
434
|
-
*/
|
|
435
|
-
this.pos = 0;
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
/**
|
|
439
|
-
* @function
|
|
440
|
-
* @template {ArrayBufferLike} Buf
|
|
441
|
-
* @param {Uint8Array<Buf>} uint8Array
|
|
442
|
-
* @return {Decoder<Buf>}
|
|
443
|
-
*/
|
|
444
|
-
const createDecoder = (uint8Array) => new Decoder(uint8Array);
|
|
445
|
-
/**
|
|
446
|
-
* Create an Uint8Array view of the next `len` bytes and advance the position by `len`.
|
|
447
|
-
*
|
|
448
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
449
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
450
|
-
*
|
|
451
|
-
* @function
|
|
452
|
-
* @template {ArrayBufferLike} Buf
|
|
453
|
-
* @param {Decoder<Buf>} decoder The decoder instance
|
|
454
|
-
* @param {number} len The length of bytes to read
|
|
455
|
-
* @return {Uint8Array<Buf>}
|
|
456
|
-
*/
|
|
457
|
-
const readUint8Array = (decoder, len) => {
|
|
458
|
-
const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
|
|
459
|
-
decoder.pos += len;
|
|
460
|
-
return view;
|
|
461
|
-
};
|
|
462
|
-
/**
|
|
463
|
-
* Read variable length Uint8Array.
|
|
464
|
-
*
|
|
465
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
466
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
467
|
-
*
|
|
468
|
-
* @function
|
|
469
|
-
* @template {ArrayBufferLike} Buf
|
|
470
|
-
* @param {Decoder<Buf>} decoder
|
|
471
|
-
* @return {Uint8Array<Buf>}
|
|
472
|
-
*/
|
|
473
|
-
const readVarUint8Array = (decoder) => readUint8Array(decoder, readVarUint(decoder));
|
|
474
|
-
/**
|
|
475
|
-
* Read one byte as unsigned integer.
|
|
476
|
-
* @function
|
|
477
|
-
* @param {Decoder} decoder The decoder instance
|
|
478
|
-
* @return {number} Unsigned 8-bit integer
|
|
479
|
-
*/
|
|
480
|
-
const readUint8 = (decoder) => decoder.arr[decoder.pos++];
|
|
481
|
-
/**
|
|
482
|
-
* Read unsigned integer (32bit) with variable length.
|
|
483
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
484
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
485
|
-
* * numbers < 2^14 is stored in two bylength
|
|
486
|
-
*
|
|
487
|
-
* @function
|
|
488
|
-
* @param {Decoder} decoder
|
|
489
|
-
* @return {number} An unsigned integer.length
|
|
490
|
-
*/
|
|
491
|
-
const readVarUint = (decoder) => {
|
|
492
|
-
let num = 0;
|
|
493
|
-
let mult = 1;
|
|
494
|
-
const len = decoder.arr.length;
|
|
495
|
-
while (decoder.pos < len) {
|
|
496
|
-
const r = decoder.arr[decoder.pos++];
|
|
497
|
-
num = num + (r & BITS7) * mult;
|
|
498
|
-
mult *= 128;
|
|
499
|
-
if (r < BIT8) return num;
|
|
500
|
-
/* c8 ignore start */
|
|
501
|
-
if (num > MAX_SAFE_INTEGER) throw errorIntegerOutOfRange;
|
|
502
|
-
}
|
|
503
|
-
throw errorUnexpectedEndOfArray;
|
|
504
|
-
};
|
|
505
|
-
/**
|
|
506
|
-
* Read signed integer (32bit) with variable length.
|
|
507
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
508
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
509
|
-
* * numbers < 2^14 is stored in two bylength
|
|
510
|
-
* @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.
|
|
511
|
-
*
|
|
512
|
-
* @function
|
|
513
|
-
* @param {Decoder} decoder
|
|
514
|
-
* @return {number} An unsigned integer.length
|
|
515
|
-
*/
|
|
516
|
-
const readVarInt = (decoder) => {
|
|
517
|
-
let r = decoder.arr[decoder.pos++];
|
|
518
|
-
let num = r & BITS6;
|
|
519
|
-
let mult = 64;
|
|
520
|
-
const sign = (r & BIT7) > 0 ? -1 : 1;
|
|
521
|
-
if ((r & BIT8) === 0) return sign * num;
|
|
522
|
-
const len = decoder.arr.length;
|
|
523
|
-
while (decoder.pos < len) {
|
|
524
|
-
r = decoder.arr[decoder.pos++];
|
|
525
|
-
num = num + (r & BITS7) * mult;
|
|
526
|
-
mult *= 128;
|
|
527
|
-
if (r < BIT8) return sign * num;
|
|
528
|
-
/* c8 ignore start */
|
|
529
|
-
if (num > MAX_SAFE_INTEGER) throw errorIntegerOutOfRange;
|
|
530
|
-
}
|
|
531
|
-
throw errorUnexpectedEndOfArray;
|
|
532
|
-
};
|
|
533
|
-
/**
|
|
534
|
-
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
535
|
-
* Better not modify this anymore..
|
|
536
|
-
*
|
|
537
|
-
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
538
|
-
* when String.fromCodePoint is fed with all characters as arguments.
|
|
539
|
-
* But most environments have a maximum number of arguments per functions.
|
|
540
|
-
* For effiency reasons we apply a maximum of 10000 characters at once.
|
|
541
|
-
*
|
|
542
|
-
* @function
|
|
543
|
-
* @param {Decoder} decoder
|
|
544
|
-
* @return {String} The read String.
|
|
545
|
-
*/
|
|
546
|
-
/* c8 ignore start */
|
|
547
|
-
const _readVarStringPolyfill = (decoder) => {
|
|
548
|
-
let remainingLen = readVarUint(decoder);
|
|
549
|
-
if (remainingLen === 0) return "";
|
|
550
|
-
else {
|
|
551
|
-
let encodedString = String.fromCodePoint(readUint8(decoder));
|
|
552
|
-
if (--remainingLen < 100) while (remainingLen--) encodedString += String.fromCodePoint(readUint8(decoder));
|
|
553
|
-
else while (remainingLen > 0) {
|
|
554
|
-
const nextLen = remainingLen < 1e4 ? remainingLen : 1e4;
|
|
555
|
-
const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen);
|
|
556
|
-
decoder.pos += nextLen;
|
|
557
|
-
encodedString += String.fromCodePoint.apply(null, bytes);
|
|
558
|
-
remainingLen -= nextLen;
|
|
559
|
-
}
|
|
560
|
-
return decodeURIComponent(escape(encodedString));
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
/* c8 ignore stop */
|
|
564
|
-
/**
|
|
565
|
-
* @function
|
|
566
|
-
* @param {Decoder} decoder
|
|
567
|
-
* @return {String} The read String
|
|
568
|
-
*/
|
|
569
|
-
const _readVarStringNative = (decoder) => utf8TextDecoder.decode(readVarUint8Array(decoder));
|
|
570
|
-
/**
|
|
571
|
-
* Read string of variable length
|
|
572
|
-
* * varUint is used to store the length of the string
|
|
573
|
-
*
|
|
574
|
-
* @function
|
|
575
|
-
* @param {Decoder} decoder
|
|
576
|
-
* @return {String} The read String
|
|
577
|
-
*
|
|
578
|
-
*/
|
|
579
|
-
/* c8 ignore next */
|
|
580
|
-
const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
581
|
-
/**
|
|
582
|
-
* Look ahead and read varString without incrementing position
|
|
583
|
-
*
|
|
584
|
-
* @function
|
|
585
|
-
* @param {Decoder} decoder
|
|
586
|
-
* @return {string}
|
|
587
|
-
*/
|
|
588
|
-
const peekVarString = (decoder) => {
|
|
589
|
-
const pos = decoder.pos;
|
|
590
|
-
const s = readVarString(decoder);
|
|
591
|
-
decoder.pos = pos;
|
|
592
|
-
return s;
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
//#endregion
|
|
596
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/time.js
|
|
597
|
-
/**
|
|
598
|
-
* Return current unix time.
|
|
599
|
-
*
|
|
600
|
-
* @return {number}
|
|
601
|
-
*/
|
|
602
|
-
const getUnixTime = Date.now;
|
|
603
|
-
|
|
604
|
-
//#endregion
|
|
605
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/map.js
|
|
606
|
-
/**
|
|
607
|
-
* Utility module to work with key-value stores.
|
|
608
|
-
*
|
|
609
|
-
* @module map
|
|
610
|
-
*/
|
|
611
|
-
/**
|
|
612
|
-
* @template K
|
|
613
|
-
* @template V
|
|
614
|
-
* @typedef {Map<K,V>} GlobalMap
|
|
615
|
-
*/
|
|
616
|
-
/**
|
|
617
|
-
* Creates a new Map instance.
|
|
618
|
-
*
|
|
619
|
-
* @function
|
|
620
|
-
* @return {Map<any, any>}
|
|
621
|
-
*
|
|
622
|
-
* @function
|
|
623
|
-
*/
|
|
624
|
-
const create = () => /* @__PURE__ */ new Map();
|
|
625
|
-
/**
|
|
626
|
-
* Get map property. Create T if property is undefined and set T on map.
|
|
627
|
-
*
|
|
628
|
-
* ```js
|
|
629
|
-
* const listeners = map.setIfUndefined(events, 'eventName', set.create)
|
|
630
|
-
* listeners.add(listener)
|
|
631
|
-
* ```
|
|
632
|
-
*
|
|
633
|
-
* @function
|
|
634
|
-
* @template {Map<any, any>} MAP
|
|
635
|
-
* @template {MAP extends Map<any,infer V> ? function():V : unknown} CF
|
|
636
|
-
* @param {MAP} map
|
|
637
|
-
* @param {MAP extends Map<infer K,any> ? K : unknown} key
|
|
638
|
-
* @param {CF} createT
|
|
639
|
-
* @return {ReturnType<CF>}
|
|
640
|
-
*/
|
|
641
|
-
const setIfUndefined = (map, key, createT) => {
|
|
642
|
-
let set = map.get(key);
|
|
643
|
-
if (set === void 0) map.set(key, set = createT());
|
|
644
|
-
return set;
|
|
645
|
-
};
|
|
646
|
-
|
|
647
|
-
//#endregion
|
|
648
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/observable.js
|
|
649
|
-
/**
|
|
650
|
-
* Observable class prototype.
|
|
651
|
-
*
|
|
652
|
-
* @module observable
|
|
653
|
-
*/
|
|
654
|
-
/* c8 ignore start */
|
|
655
|
-
/**
|
|
656
|
-
* Handles named events.
|
|
657
|
-
*
|
|
658
|
-
* @deprecated
|
|
659
|
-
* @template N
|
|
660
|
-
*/
|
|
661
|
-
var Observable = class {
|
|
662
|
-
constructor() {
|
|
663
|
-
/**
|
|
664
|
-
* Some desc.
|
|
665
|
-
* @type {Map<N, any>}
|
|
666
|
-
*/
|
|
667
|
-
this._observers = create();
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* @param {N} name
|
|
671
|
-
* @param {function} f
|
|
672
|
-
*/
|
|
673
|
-
on(name, f) {
|
|
674
|
-
setIfUndefined(this._observers, name, create$2).add(f);
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
|
-
* @param {N} name
|
|
678
|
-
* @param {function} f
|
|
679
|
-
*/
|
|
680
|
-
once(name, f) {
|
|
681
|
-
/**
|
|
682
|
-
* @param {...any} args
|
|
683
|
-
*/
|
|
684
|
-
const _f = (...args) => {
|
|
685
|
-
this.off(name, _f);
|
|
686
|
-
f(...args);
|
|
687
|
-
};
|
|
688
|
-
this.on(name, _f);
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* @param {N} name
|
|
692
|
-
* @param {function} f
|
|
693
|
-
*/
|
|
694
|
-
off(name, f) {
|
|
695
|
-
const observers = this._observers.get(name);
|
|
696
|
-
if (observers !== void 0) {
|
|
697
|
-
observers.delete(f);
|
|
698
|
-
if (observers.size === 0) this._observers.delete(name);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Emit a named event. All registered event listeners that listen to the
|
|
703
|
-
* specified name will receive the event.
|
|
704
|
-
*
|
|
705
|
-
* @todo This should catch exceptions
|
|
706
|
-
*
|
|
707
|
-
* @param {N} name The event name.
|
|
708
|
-
* @param {Array<any>} args The arguments that are applied to the event listener.
|
|
709
|
-
*/
|
|
710
|
-
emit(name, args) {
|
|
711
|
-
return from((this._observers.get(name) || create()).values()).forEach((f) => f(...args));
|
|
712
|
-
}
|
|
713
|
-
destroy() {
|
|
714
|
-
this._observers = create();
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
|
-
/* c8 ignore end */
|
|
718
|
-
|
|
719
|
-
//#endregion
|
|
720
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/trait/equality.js
|
|
721
|
-
const EqualityTraitSymbol = Symbol("Equality");
|
|
722
|
-
|
|
723
|
-
//#endregion
|
|
724
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/object.js
|
|
725
|
-
/**
|
|
726
|
-
* @param {Object<string,any>} obj
|
|
727
|
-
*/
|
|
728
|
-
const keys = Object.keys;
|
|
729
|
-
/**
|
|
730
|
-
* @param {Object<string,any>} obj
|
|
731
|
-
* @return {number}
|
|
732
|
-
*/
|
|
733
|
-
const size = (obj) => keys(obj).length;
|
|
734
|
-
/**
|
|
735
|
-
* Calls `Object.prototype.hasOwnProperty`.
|
|
736
|
-
*
|
|
737
|
-
* @param {any} obj
|
|
738
|
-
* @param {string|number|symbol} key
|
|
739
|
-
* @return {boolean}
|
|
740
|
-
*/
|
|
741
|
-
const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
742
|
-
|
|
743
|
-
//#endregion
|
|
744
|
-
//#region node_modules/.pnpm/lib0@0.2.117/node_modules/lib0/function.js
|
|
745
|
-
/**
|
|
746
|
-
* Common functions and function call helpers.
|
|
747
|
-
*
|
|
748
|
-
* @module function
|
|
749
|
-
*/
|
|
750
|
-
/* c8 ignore start */
|
|
751
|
-
/**
|
|
752
|
-
* @param {any} a
|
|
753
|
-
* @param {any} b
|
|
754
|
-
* @return {boolean}
|
|
755
|
-
*/
|
|
756
|
-
const equalityDeep = (a, b) => {
|
|
757
|
-
if (a === b) return true;
|
|
758
|
-
if (a == null || b == null || a.constructor !== b.constructor && (a.constructor || Object) !== (b.constructor || Object)) return false;
|
|
759
|
-
if (a[EqualityTraitSymbol] != null) return a[EqualityTraitSymbol](b);
|
|
760
|
-
switch (a.constructor) {
|
|
761
|
-
case ArrayBuffer:
|
|
762
|
-
a = new Uint8Array(a);
|
|
763
|
-
b = new Uint8Array(b);
|
|
764
|
-
case Uint8Array:
|
|
765
|
-
if (a.byteLength !== b.byteLength) return false;
|
|
766
|
-
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
767
|
-
break;
|
|
768
|
-
case Set:
|
|
769
|
-
if (a.size !== b.size) return false;
|
|
770
|
-
for (const value of a) if (!b.has(value)) return false;
|
|
771
|
-
break;
|
|
772
|
-
case Map:
|
|
773
|
-
if (a.size !== b.size) return false;
|
|
774
|
-
for (const key of a.keys()) if (!b.has(key) || !equalityDeep(a.get(key), b.get(key))) return false;
|
|
775
|
-
break;
|
|
776
|
-
case void 0:
|
|
777
|
-
case Object:
|
|
778
|
-
if (size(a) !== size(b)) return false;
|
|
779
|
-
for (const key in a) if (!hasProperty(a, key) || !equalityDeep(a[key], b[key])) return false;
|
|
780
|
-
break;
|
|
781
|
-
case Array:
|
|
782
|
-
if (a.length !== b.length) return false;
|
|
783
|
-
for (let i = 0; i < a.length; i++) if (!equalityDeep(a[i], b[i])) return false;
|
|
784
|
-
break;
|
|
785
|
-
default: return false;
|
|
786
|
-
}
|
|
787
|
-
return true;
|
|
788
|
-
};
|
|
789
|
-
/* c8 ignore stop */
|
|
790
|
-
const isArray = isArray$1;
|
|
791
|
-
|
|
792
|
-
//#endregion
|
|
793
|
-
//#region node_modules/.pnpm/y-protocols@1.0.7_yjs@13.6.29/node_modules/y-protocols/awareness.js
|
|
794
|
-
/**
|
|
795
|
-
* @module awareness-protocol
|
|
796
|
-
*/
|
|
797
|
-
const outdatedTimeout = 3e4;
|
|
798
|
-
/**
|
|
799
|
-
* @typedef {Object} MetaClientState
|
|
800
|
-
* @property {number} MetaClientState.clock
|
|
801
|
-
* @property {number} MetaClientState.lastUpdated unix timestamp
|
|
802
|
-
*/
|
|
803
|
-
/**
|
|
804
|
-
* The Awareness class implements a simple shared state protocol that can be used for non-persistent data like awareness information
|
|
805
|
-
* (cursor, username, status, ..). Each client can update its own local state and listen to state changes of
|
|
806
|
-
* remote clients. Every client may set a state of a remote peer to `null` to mark the client as offline.
|
|
807
|
-
*
|
|
808
|
-
* Each client is identified by a unique client id (something we borrow from `doc.clientID`). A client can override
|
|
809
|
-
* its own state by propagating a message with an increasing timestamp (`clock`). If such a message is received, it is
|
|
810
|
-
* applied if the known state of that client is older than the new state (`clock < newClock`). If a client thinks that
|
|
811
|
-
* a remote client is offline, it may propagate a message with
|
|
812
|
-
* `{ clock: currentClientClock, state: null, client: remoteClient }`. If such a
|
|
813
|
-
* message is received, and the known clock of that client equals the received clock, it will override the state with `null`.
|
|
814
|
-
*
|
|
815
|
-
* Before a client disconnects, it should propagate a `null` state with an updated clock.
|
|
816
|
-
*
|
|
817
|
-
* Awareness states must be updated every 30 seconds. Otherwise the Awareness instance will delete the client state.
|
|
818
|
-
*
|
|
819
|
-
* @extends {Observable<string>}
|
|
820
|
-
*/
|
|
821
|
-
var Awareness = class extends Observable {
|
|
822
|
-
/**
|
|
823
|
-
* @param {Y.Doc} doc
|
|
824
|
-
*/
|
|
825
|
-
constructor(doc) {
|
|
826
|
-
super();
|
|
827
|
-
this.doc = doc;
|
|
828
|
-
/**
|
|
829
|
-
* @type {number}
|
|
830
|
-
*/
|
|
831
|
-
this.clientID = doc.clientID;
|
|
832
|
-
/**
|
|
833
|
-
* Maps from client id to client state
|
|
834
|
-
* @type {Map<number, Object<string, any>>}
|
|
835
|
-
*/
|
|
836
|
-
this.states = /* @__PURE__ */ new Map();
|
|
837
|
-
/**
|
|
838
|
-
* @type {Map<number, MetaClientState>}
|
|
839
|
-
*/
|
|
840
|
-
this.meta = /* @__PURE__ */ new Map();
|
|
841
|
-
this._checkInterval = setInterval(() => {
|
|
842
|
-
const now = getUnixTime();
|
|
843
|
-
if (this.getLocalState() !== null && outdatedTimeout / 2 <= now - this.meta.get(this.clientID).lastUpdated) this.setLocalState(this.getLocalState());
|
|
844
|
-
/**
|
|
845
|
-
* @type {Array<number>}
|
|
846
|
-
*/
|
|
847
|
-
const remove = [];
|
|
848
|
-
this.meta.forEach((meta, clientid) => {
|
|
849
|
-
if (clientid !== this.clientID && outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) remove.push(clientid);
|
|
850
|
-
});
|
|
851
|
-
if (remove.length > 0) removeAwarenessStates(this, remove, "timeout");
|
|
852
|
-
}, floor(outdatedTimeout / 10));
|
|
853
|
-
doc.on("destroy", () => {
|
|
854
|
-
this.destroy();
|
|
855
|
-
});
|
|
856
|
-
this.setLocalState({});
|
|
857
|
-
}
|
|
858
|
-
destroy() {
|
|
859
|
-
this.emit("destroy", [this]);
|
|
860
|
-
this.setLocalState(null);
|
|
861
|
-
super.destroy();
|
|
862
|
-
clearInterval(this._checkInterval);
|
|
863
|
-
}
|
|
864
|
-
/**
|
|
865
|
-
* @return {Object<string,any>|null}
|
|
866
|
-
*/
|
|
867
|
-
getLocalState() {
|
|
868
|
-
return this.states.get(this.clientID) || null;
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* @param {Object<string,any>|null} state
|
|
872
|
-
*/
|
|
873
|
-
setLocalState(state) {
|
|
874
|
-
const clientID = this.clientID;
|
|
875
|
-
const currLocalMeta = this.meta.get(clientID);
|
|
876
|
-
const clock = currLocalMeta === void 0 ? 0 : currLocalMeta.clock + 1;
|
|
877
|
-
const prevState = this.states.get(clientID);
|
|
878
|
-
if (state === null) this.states.delete(clientID);
|
|
879
|
-
else this.states.set(clientID, state);
|
|
880
|
-
this.meta.set(clientID, {
|
|
881
|
-
clock,
|
|
882
|
-
lastUpdated: getUnixTime()
|
|
883
|
-
});
|
|
884
|
-
const added = [];
|
|
885
|
-
const updated = [];
|
|
886
|
-
const filteredUpdated = [];
|
|
887
|
-
const removed = [];
|
|
888
|
-
if (state === null) removed.push(clientID);
|
|
889
|
-
else if (prevState == null) {
|
|
890
|
-
if (state != null) added.push(clientID);
|
|
891
|
-
} else {
|
|
892
|
-
updated.push(clientID);
|
|
893
|
-
if (!equalityDeep(prevState, state)) filteredUpdated.push(clientID);
|
|
894
|
-
}
|
|
895
|
-
if (added.length > 0 || filteredUpdated.length > 0 || removed.length > 0) this.emit("change", [{
|
|
896
|
-
added,
|
|
897
|
-
updated: filteredUpdated,
|
|
898
|
-
removed
|
|
899
|
-
}, "local"]);
|
|
900
|
-
this.emit("update", [{
|
|
901
|
-
added,
|
|
902
|
-
updated,
|
|
903
|
-
removed
|
|
904
|
-
}, "local"]);
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* @param {string} field
|
|
908
|
-
* @param {any} value
|
|
909
|
-
*/
|
|
910
|
-
setLocalStateField(field, value) {
|
|
911
|
-
const state = this.getLocalState();
|
|
912
|
-
if (state !== null) this.setLocalState({
|
|
913
|
-
...state,
|
|
914
|
-
[field]: value
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* @return {Map<number,Object<string,any>>}
|
|
919
|
-
*/
|
|
920
|
-
getStates() {
|
|
921
|
-
return this.states;
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
/**
|
|
925
|
-
* Mark (remote) clients as inactive and remove them from the list of active peers.
|
|
926
|
-
* This change will be propagated to remote clients.
|
|
927
|
-
*
|
|
928
|
-
* @param {Awareness} awareness
|
|
929
|
-
* @param {Array<number>} clients
|
|
930
|
-
* @param {any} origin
|
|
931
|
-
*/
|
|
932
|
-
const removeAwarenessStates = (awareness, clients, origin) => {
|
|
933
|
-
const removed = [];
|
|
934
|
-
for (let i = 0; i < clients.length; i++) {
|
|
935
|
-
const clientID = clients[i];
|
|
936
|
-
if (awareness.states.has(clientID)) {
|
|
937
|
-
awareness.states.delete(clientID);
|
|
938
|
-
if (clientID === awareness.clientID) {
|
|
939
|
-
const curMeta = awareness.meta.get(clientID);
|
|
940
|
-
awareness.meta.set(clientID, {
|
|
941
|
-
clock: curMeta.clock + 1,
|
|
942
|
-
lastUpdated: getUnixTime()
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
removed.push(clientID);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
if (removed.length > 0) {
|
|
949
|
-
awareness.emit("change", [{
|
|
950
|
-
added: [],
|
|
951
|
-
updated: [],
|
|
952
|
-
removed
|
|
953
|
-
}, origin]);
|
|
954
|
-
awareness.emit("update", [{
|
|
955
|
-
added: [],
|
|
956
|
-
updated: [],
|
|
957
|
-
removed
|
|
958
|
-
}, origin]);
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
/**
|
|
962
|
-
* @param {Awareness} awareness
|
|
963
|
-
* @param {Array<number>} clients
|
|
964
|
-
* @return {Uint8Array}
|
|
965
|
-
*/
|
|
966
|
-
const encodeAwarenessUpdate = (awareness, clients, states = awareness.states) => {
|
|
967
|
-
const len = clients.length;
|
|
968
|
-
const encoder = createEncoder();
|
|
969
|
-
writeVarUint(encoder, len);
|
|
970
|
-
for (let i = 0; i < len; i++) {
|
|
971
|
-
const clientID = clients[i];
|
|
972
|
-
const state = states.get(clientID) || null;
|
|
973
|
-
const clock = awareness.meta.get(clientID).clock;
|
|
974
|
-
writeVarUint(encoder, clientID);
|
|
975
|
-
writeVarUint(encoder, clock);
|
|
976
|
-
writeVarString(encoder, JSON.stringify(state));
|
|
977
|
-
}
|
|
978
|
-
return toUint8Array(encoder);
|
|
979
|
-
};
|
|
980
|
-
/**
|
|
981
|
-
* @param {Awareness} awareness
|
|
982
|
-
* @param {Uint8Array} update
|
|
983
|
-
* @param {any} origin This will be added to the emitted change event
|
|
984
|
-
*/
|
|
985
|
-
const applyAwarenessUpdate = (awareness, update, origin) => {
|
|
986
|
-
const decoder = createDecoder(update);
|
|
987
|
-
const timestamp = getUnixTime();
|
|
988
|
-
const added = [];
|
|
989
|
-
const updated = [];
|
|
990
|
-
const filteredUpdated = [];
|
|
991
|
-
const removed = [];
|
|
992
|
-
const len = readVarUint(decoder);
|
|
993
|
-
for (let i = 0; i < len; i++) {
|
|
994
|
-
const clientID = readVarUint(decoder);
|
|
995
|
-
let clock = readVarUint(decoder);
|
|
996
|
-
const state = JSON.parse(readVarString(decoder));
|
|
997
|
-
const clientMeta = awareness.meta.get(clientID);
|
|
998
|
-
const prevState = awareness.states.get(clientID);
|
|
999
|
-
const currClock = clientMeta === void 0 ? 0 : clientMeta.clock;
|
|
1000
|
-
if (currClock < clock || currClock === clock && state === null && awareness.states.has(clientID)) {
|
|
1001
|
-
if (state === null) if (clientID === awareness.clientID && awareness.getLocalState() != null) clock++;
|
|
1002
|
-
else awareness.states.delete(clientID);
|
|
1003
|
-
else awareness.states.set(clientID, state);
|
|
1004
|
-
awareness.meta.set(clientID, {
|
|
1005
|
-
clock,
|
|
1006
|
-
lastUpdated: timestamp
|
|
1007
|
-
});
|
|
1008
|
-
if (clientMeta === void 0 && state !== null) added.push(clientID);
|
|
1009
|
-
else if (clientMeta !== void 0 && state === null) removed.push(clientID);
|
|
1010
|
-
else if (state !== null) {
|
|
1011
|
-
if (!equalityDeep(state, prevState)) filteredUpdated.push(clientID);
|
|
1012
|
-
updated.push(clientID);
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
if (added.length > 0 || filteredUpdated.length > 0 || removed.length > 0) awareness.emit("change", [{
|
|
1017
|
-
added,
|
|
1018
|
-
updated: filteredUpdated,
|
|
1019
|
-
removed
|
|
1020
|
-
}, origin]);
|
|
1021
|
-
if (added.length > 0 || updated.length > 0 || removed.length > 0) awareness.emit("update", [{
|
|
1022
|
-
added,
|
|
1023
|
-
updated,
|
|
1024
|
-
removed
|
|
1025
|
-
}, origin]);
|
|
1026
|
-
};
|
|
1027
|
-
|
|
1028
|
-
//#endregion
|
|
1029
43
|
//#region packages/provider/src/EventEmitter.ts
|
|
1030
44
|
var EventEmitter = class {
|
|
1031
45
|
constructor() {
|
|
@@ -1057,32 +71,32 @@ var EventEmitter = class {
|
|
|
1057
71
|
var IncomingMessage = class {
|
|
1058
72
|
constructor(data) {
|
|
1059
73
|
this.data = data;
|
|
1060
|
-
this.encoder = createEncoder();
|
|
1061
|
-
this.decoder = createDecoder(new Uint8Array(this.data));
|
|
74
|
+
this.encoder = (0, lib0_encoding.createEncoder)();
|
|
75
|
+
this.decoder = (0, lib0_decoding.createDecoder)(new Uint8Array(this.data));
|
|
1062
76
|
}
|
|
1063
77
|
peekVarString() {
|
|
1064
|
-
return peekVarString(this.decoder);
|
|
78
|
+
return (0, lib0_decoding.peekVarString)(this.decoder);
|
|
1065
79
|
}
|
|
1066
80
|
readVarUint() {
|
|
1067
|
-
return readVarUint(this.decoder);
|
|
81
|
+
return (0, lib0_decoding.readVarUint)(this.decoder);
|
|
1068
82
|
}
|
|
1069
83
|
readVarString() {
|
|
1070
|
-
return readVarString(this.decoder);
|
|
84
|
+
return (0, lib0_decoding.readVarString)(this.decoder);
|
|
1071
85
|
}
|
|
1072
86
|
readVarUint8Array() {
|
|
1073
|
-
return readVarUint8Array(this.decoder);
|
|
87
|
+
return (0, lib0_decoding.readVarUint8Array)(this.decoder);
|
|
1074
88
|
}
|
|
1075
89
|
writeVarUint(type) {
|
|
1076
|
-
return writeVarUint(this.encoder, type);
|
|
90
|
+
return (0, lib0_encoding.writeVarUint)(this.encoder, type);
|
|
1077
91
|
}
|
|
1078
92
|
writeVarString(string) {
|
|
1079
|
-
return writeVarString(this.encoder, string);
|
|
93
|
+
return (0, lib0_encoding.writeVarString)(this.encoder, string);
|
|
1080
94
|
}
|
|
1081
95
|
writeVarUint8Array(data) {
|
|
1082
|
-
return writeVarUint8Array(this.encoder, data);
|
|
96
|
+
return (0, lib0_encoding.writeVarUint8Array)(this.encoder, data);
|
|
1083
97
|
}
|
|
1084
98
|
length() {
|
|
1085
|
-
return length(this.encoder);
|
|
99
|
+
return (0, lib0_encoding.length)(this.encoder);
|
|
1086
100
|
}
|
|
1087
101
|
};
|
|
1088
102
|
|
|
@@ -1111,13 +125,13 @@ let WebSocketStatus = /* @__PURE__ */ function(WebSocketStatus) {
|
|
|
1111
125
|
//#region packages/provider/src/OutgoingMessage.ts
|
|
1112
126
|
var OutgoingMessage = class {
|
|
1113
127
|
constructor() {
|
|
1114
|
-
this.encoder = createEncoder();
|
|
128
|
+
this.encoder = (0, lib0_encoding.createEncoder)();
|
|
1115
129
|
}
|
|
1116
130
|
get(args) {
|
|
1117
131
|
return args.encoder;
|
|
1118
132
|
}
|
|
1119
133
|
toUint8Array() {
|
|
1120
|
-
return toUint8Array(this.encoder);
|
|
134
|
+
return (0, lib0_encoding.toUint8Array)(this.encoder);
|
|
1121
135
|
}
|
|
1122
136
|
};
|
|
1123
137
|
|
|
@@ -1130,8 +144,8 @@ var CloseMessage = class extends OutgoingMessage {
|
|
|
1130
144
|
this.description = "Ask the server to close the connection";
|
|
1131
145
|
}
|
|
1132
146
|
get(args) {
|
|
1133
|
-
writeVarString(this.encoder, args.documentName);
|
|
1134
|
-
writeVarUint(this.encoder, this.type);
|
|
147
|
+
lib0_encoding.writeVarString(this.encoder, args.documentName);
|
|
148
|
+
lib0_encoding.writeVarUint(this.encoder, this.type);
|
|
1135
149
|
return this.encoder;
|
|
1136
150
|
}
|
|
1137
151
|
};
|
|
@@ -1320,7 +334,7 @@ var HocuspocusProviderWebsocket = class HocuspocusProviderWebsocket extends Even
|
|
|
1320
334
|
}
|
|
1321
335
|
onMessage(event) {
|
|
1322
336
|
this.resolveConnectionAttempt();
|
|
1323
|
-
this.lastMessageReceived = getUnixTime();
|
|
337
|
+
this.lastMessageReceived = lib0_time.getUnixTime();
|
|
1324
338
|
const data = new Uint8Array(event.data);
|
|
1325
339
|
if (data.length === 1 && data[0] === MessageType.Ping) {
|
|
1326
340
|
this.sendPong();
|
|
@@ -1333,9 +347,9 @@ var HocuspocusProviderWebsocket = class HocuspocusProviderWebsocket extends Even
|
|
|
1333
347
|
* Send application-level Pong response to server Ping
|
|
1334
348
|
*/
|
|
1335
349
|
sendPong() {
|
|
1336
|
-
const encoder = createEncoder();
|
|
1337
|
-
writeVarUint(encoder, MessageType.Pong);
|
|
1338
|
-
this.send(toUint8Array(encoder));
|
|
350
|
+
const encoder = lib0_encoding.createEncoder();
|
|
351
|
+
lib0_encoding.writeVarUint(encoder, MessageType.Pong);
|
|
352
|
+
this.send(lib0_encoding.toUint8Array(encoder));
|
|
1339
353
|
}
|
|
1340
354
|
resolveConnectionAttempt() {
|
|
1341
355
|
if (this.connectionAttempt) {
|
|
@@ -1358,7 +372,7 @@ var HocuspocusProviderWebsocket = class HocuspocusProviderWebsocket extends Even
|
|
|
1358
372
|
checkConnection() {
|
|
1359
373
|
if (this.status !== WebSocketStatus.Connected) return;
|
|
1360
374
|
if (!this.lastMessageReceived) return;
|
|
1361
|
-
if (this.configuration.messageReconnectTimeout >= getUnixTime() - this.lastMessageReceived) return;
|
|
375
|
+
if (this.configuration.messageReconnectTimeout >= lib0_time.getUnixTime() - this.lastMessageReceived) return;
|
|
1362
376
|
this.closeTries += 1;
|
|
1363
377
|
if (this.closeTries > 2) {
|
|
1364
378
|
this.onClose({ event: {
|
|
@@ -1392,10 +406,10 @@ var HocuspocusProviderWebsocket = class HocuspocusProviderWebsocket extends Even
|
|
|
1392
406
|
}
|
|
1393
407
|
parseQueuedMessage(message) {
|
|
1394
408
|
try {
|
|
1395
|
-
const decoder = createDecoder(message);
|
|
409
|
+
const decoder = (0, lib0_decoding.createDecoder)(message);
|
|
1396
410
|
return {
|
|
1397
|
-
documentName: readVarString(decoder),
|
|
1398
|
-
messageType: readVarUint(decoder)
|
|
411
|
+
documentName: (0, lib0_decoding.readVarString)(decoder),
|
|
412
|
+
messageType: (0, lib0_decoding.readVarUint)(decoder)
|
|
1399
413
|
};
|
|
1400
414
|
} catch {
|
|
1401
415
|
return null;
|
|
@@ -1438,126 +452,6 @@ var HocuspocusProviderWebsocket = class HocuspocusProviderWebsocket extends Even
|
|
|
1438
452
|
}
|
|
1439
453
|
};
|
|
1440
454
|
|
|
1441
|
-
//#endregion
|
|
1442
|
-
//#region node_modules/.pnpm/y-protocols@1.0.7_yjs@13.6.29/node_modules/y-protocols/sync.js
|
|
1443
|
-
/**
|
|
1444
|
-
* @module sync-protocol
|
|
1445
|
-
*/
|
|
1446
|
-
/**
|
|
1447
|
-
* @typedef {Map<number, number>} StateMap
|
|
1448
|
-
*/
|
|
1449
|
-
/**
|
|
1450
|
-
* Core Yjs defines two message types:
|
|
1451
|
-
* • YjsSyncStep1: Includes the State Set of the sending client. When received, the client should reply with YjsSyncStep2.
|
|
1452
|
-
* • YjsSyncStep2: Includes all missing structs and the complete delete set. When received, the client is assured that it
|
|
1453
|
-
* received all information from the remote client.
|
|
1454
|
-
*
|
|
1455
|
-
* In a peer-to-peer network, you may want to introduce a SyncDone message type. Both parties should initiate the connection
|
|
1456
|
-
* with SyncStep1. When a client received SyncStep2, it should reply with SyncDone. When the local client received both
|
|
1457
|
-
* SyncStep2 and SyncDone, it is assured that it is synced to the remote client.
|
|
1458
|
-
*
|
|
1459
|
-
* In a client-server model, you want to handle this differently: The client should initiate the connection with SyncStep1.
|
|
1460
|
-
* When the server receives SyncStep1, it should reply with SyncStep2 immediately followed by SyncStep1. The client replies
|
|
1461
|
-
* with SyncStep2 when it receives SyncStep1. Optionally the server may send a SyncDone after it received SyncStep2, so the
|
|
1462
|
-
* client knows that the sync is finished. There are two reasons for this more elaborated sync model: 1. This protocol can
|
|
1463
|
-
* easily be implemented on top of http and websockets. 2. The server should only reply to requests, and not initiate them.
|
|
1464
|
-
* Therefore it is necessary that the client initiates the sync.
|
|
1465
|
-
*
|
|
1466
|
-
* Construction of a message:
|
|
1467
|
-
* [messageType : varUint, message definition..]
|
|
1468
|
-
*
|
|
1469
|
-
* Note: A message does not include information about the room name. This must to be handled by the upper layer protocol!
|
|
1470
|
-
*
|
|
1471
|
-
* stringify[messageType] stringifies a message definition (messageType is already read from the bufffer)
|
|
1472
|
-
*/
|
|
1473
|
-
const messageYjsSyncStep1 = 0;
|
|
1474
|
-
const messageYjsSyncStep2 = 1;
|
|
1475
|
-
const messageYjsUpdate = 2;
|
|
1476
|
-
/**
|
|
1477
|
-
* Create a sync step 1 message based on the state of the current shared document.
|
|
1478
|
-
*
|
|
1479
|
-
* @param {encoding.Encoder} encoder
|
|
1480
|
-
* @param {Y.Doc} doc
|
|
1481
|
-
*/
|
|
1482
|
-
const writeSyncStep1 = (encoder, doc) => {
|
|
1483
|
-
writeVarUint(encoder, messageYjsSyncStep1);
|
|
1484
|
-
const sv = yjs.encodeStateVector(doc);
|
|
1485
|
-
writeVarUint8Array(encoder, sv);
|
|
1486
|
-
};
|
|
1487
|
-
/**
|
|
1488
|
-
* @param {encoding.Encoder} encoder
|
|
1489
|
-
* @param {Y.Doc} doc
|
|
1490
|
-
* @param {Uint8Array} [encodedStateVector]
|
|
1491
|
-
*/
|
|
1492
|
-
const writeSyncStep2 = (encoder, doc, encodedStateVector) => {
|
|
1493
|
-
writeVarUint(encoder, messageYjsSyncStep2);
|
|
1494
|
-
writeVarUint8Array(encoder, yjs.encodeStateAsUpdate(doc, encodedStateVector));
|
|
1495
|
-
};
|
|
1496
|
-
/**
|
|
1497
|
-
* Read SyncStep1 message and reply with SyncStep2.
|
|
1498
|
-
*
|
|
1499
|
-
* @param {decoding.Decoder} decoder The reply to the received message
|
|
1500
|
-
* @param {encoding.Encoder} encoder The received message
|
|
1501
|
-
* @param {Y.Doc} doc
|
|
1502
|
-
*/
|
|
1503
|
-
const readSyncStep1 = (decoder, encoder, doc) => writeSyncStep2(encoder, doc, readVarUint8Array(decoder));
|
|
1504
|
-
/**
|
|
1505
|
-
* Read and apply Structs and then DeleteStore to a y instance.
|
|
1506
|
-
*
|
|
1507
|
-
* @param {decoding.Decoder} decoder
|
|
1508
|
-
* @param {Y.Doc} doc
|
|
1509
|
-
* @param {any} transactionOrigin
|
|
1510
|
-
* @param {(error:Error)=>any} [errorHandler]
|
|
1511
|
-
*/
|
|
1512
|
-
const readSyncStep2 = (decoder, doc, transactionOrigin, errorHandler) => {
|
|
1513
|
-
try {
|
|
1514
|
-
yjs.applyUpdate(doc, readVarUint8Array(decoder), transactionOrigin);
|
|
1515
|
-
} catch (error) {
|
|
1516
|
-
if (errorHandler != null) errorHandler(error);
|
|
1517
|
-
console.error("Caught error while handling a Yjs update", error);
|
|
1518
|
-
}
|
|
1519
|
-
};
|
|
1520
|
-
/**
|
|
1521
|
-
* @param {encoding.Encoder} encoder
|
|
1522
|
-
* @param {Uint8Array} update
|
|
1523
|
-
*/
|
|
1524
|
-
const writeUpdate = (encoder, update) => {
|
|
1525
|
-
writeVarUint(encoder, messageYjsUpdate);
|
|
1526
|
-
writeVarUint8Array(encoder, update);
|
|
1527
|
-
};
|
|
1528
|
-
/**
|
|
1529
|
-
* Read and apply Structs and then DeleteStore to a y instance.
|
|
1530
|
-
*
|
|
1531
|
-
* @param {decoding.Decoder} decoder
|
|
1532
|
-
* @param {Y.Doc} doc
|
|
1533
|
-
* @param {any} transactionOrigin
|
|
1534
|
-
* @param {(error:Error)=>any} [errorHandler]
|
|
1535
|
-
*/
|
|
1536
|
-
const readUpdate = readSyncStep2;
|
|
1537
|
-
/**
|
|
1538
|
-
* @param {decoding.Decoder} decoder A message received from another client
|
|
1539
|
-
* @param {encoding.Encoder} encoder The reply message. Does not need to be sent if empty.
|
|
1540
|
-
* @param {Y.Doc} doc
|
|
1541
|
-
* @param {any} transactionOrigin
|
|
1542
|
-
* @param {(error:Error)=>any} [errorHandler] Optional error handler that catches errors when reading Yjs messages.
|
|
1543
|
-
*/
|
|
1544
|
-
const readSyncMessage = (decoder, encoder, doc, transactionOrigin, errorHandler) => {
|
|
1545
|
-
const messageType = readVarUint(decoder);
|
|
1546
|
-
switch (messageType) {
|
|
1547
|
-
case messageYjsSyncStep1:
|
|
1548
|
-
readSyncStep1(decoder, encoder, doc);
|
|
1549
|
-
break;
|
|
1550
|
-
case messageYjsSyncStep2:
|
|
1551
|
-
readSyncStep2(decoder, doc, transactionOrigin, errorHandler);
|
|
1552
|
-
break;
|
|
1553
|
-
case messageYjsUpdate:
|
|
1554
|
-
readUpdate(decoder, doc, transactionOrigin, errorHandler);
|
|
1555
|
-
break;
|
|
1556
|
-
default: throw new Error("Unknown message type");
|
|
1557
|
-
}
|
|
1558
|
-
return messageType;
|
|
1559
|
-
};
|
|
1560
|
-
|
|
1561
455
|
//#endregion
|
|
1562
456
|
//#region packages/provider/src/MessageReceiver.ts
|
|
1563
457
|
var MessageReceiver = class {
|
|
@@ -1582,15 +476,15 @@ var MessageReceiver = class {
|
|
|
1582
476
|
this.applyQueryAwarenessMessage(provider);
|
|
1583
477
|
break;
|
|
1584
478
|
case MessageType.Stateless:
|
|
1585
|
-
provider.receiveStateless(readVarString(message.decoder));
|
|
479
|
+
provider.receiveStateless((0, lib0_decoding.readVarString)(message.decoder));
|
|
1586
480
|
break;
|
|
1587
481
|
case MessageType.SyncStatus:
|
|
1588
|
-
this.applySyncStatusMessage(provider, readVarInt(message.decoder) === 1);
|
|
482
|
+
this.applySyncStatusMessage(provider, (0, lib0_decoding.readVarInt)(message.decoder) === 1);
|
|
1589
483
|
break;
|
|
1590
484
|
case MessageType.CLOSE: {
|
|
1591
485
|
const event = {
|
|
1592
486
|
code: 1e3,
|
|
1593
|
-
reason: readVarString(message.decoder)
|
|
487
|
+
reason: (0, lib0_decoding.readVarString)(message.decoder)
|
|
1594
488
|
};
|
|
1595
489
|
provider.onClose();
|
|
1596
490
|
provider.configuration.onClose({ event });
|
|
@@ -1604,8 +498,8 @@ var MessageReceiver = class {
|
|
|
1604
498
|
applySyncMessage(provider, emitSynced) {
|
|
1605
499
|
const { message } = this;
|
|
1606
500
|
message.writeVarUint(MessageType.Sync);
|
|
1607
|
-
const syncMessageType = readSyncMessage(message.decoder, message.encoder, provider.document, provider);
|
|
1608
|
-
if (emitSynced && syncMessageType === messageYjsSyncStep2) provider.synced = true;
|
|
501
|
+
const syncMessageType = (0, y_protocols_sync.readSyncMessage)(message.decoder, message.encoder, provider.document, provider);
|
|
502
|
+
if (emitSynced && syncMessageType === y_protocols_sync.messageYjsSyncStep2) provider.synced = true;
|
|
1609
503
|
}
|
|
1610
504
|
applySyncStatusMessage(provider, applied) {
|
|
1611
505
|
if (applied) provider.decrementUnsyncedChanges();
|
|
@@ -1613,7 +507,7 @@ var MessageReceiver = class {
|
|
|
1613
507
|
applyAwarenessMessage(provider) {
|
|
1614
508
|
if (!provider.awareness) return;
|
|
1615
509
|
const { message } = this;
|
|
1616
|
-
applyAwarenessUpdate(provider.awareness, message.readVarUint8Array(), provider);
|
|
510
|
+
y_protocols_awareness.applyAwarenessUpdate(provider.awareness, message.readVarUint8Array(), provider);
|
|
1617
511
|
}
|
|
1618
512
|
applyAuthMessage(provider) {
|
|
1619
513
|
const { message } = this;
|
|
@@ -1623,7 +517,7 @@ var MessageReceiver = class {
|
|
|
1623
517
|
if (!provider.awareness) return;
|
|
1624
518
|
const { message } = this;
|
|
1625
519
|
message.writeVarUint(MessageType.Awareness);
|
|
1626
|
-
message.writeVarUint8Array(encodeAwarenessUpdate(provider.awareness, Array.from(provider.awareness.getStates().keys())));
|
|
520
|
+
message.writeVarUint8Array(y_protocols_awareness.encodeAwarenessUpdate(provider.awareness, Array.from(provider.awareness.getStates().keys())));
|
|
1627
521
|
}
|
|
1628
522
|
};
|
|
1629
523
|
|
|
@@ -1635,7 +529,7 @@ var MessageSender = class {
|
|
|
1635
529
|
this.encoder = this.message.get(args);
|
|
1636
530
|
}
|
|
1637
531
|
create() {
|
|
1638
|
-
return toUint8Array(this.encoder);
|
|
532
|
+
return (0, lib0_encoding.toUint8Array)(this.encoder);
|
|
1639
533
|
}
|
|
1640
534
|
send(webSocket) {
|
|
1641
535
|
webSocket?.send(this.create());
|
|
@@ -1644,7 +538,7 @@ var MessageSender = class {
|
|
|
1644
538
|
|
|
1645
539
|
//#endregion
|
|
1646
540
|
//#region packages/provider/src/version.ts
|
|
1647
|
-
const version = "4.0.0-rc.
|
|
541
|
+
const version = "4.0.0-rc.7";
|
|
1648
542
|
|
|
1649
543
|
//#endregion
|
|
1650
544
|
//#region packages/provider/src/OutgoingMessages/AuthenticationMessage.ts
|
|
@@ -1656,10 +550,10 @@ var AuthenticationMessage = class extends OutgoingMessage {
|
|
|
1656
550
|
}
|
|
1657
551
|
get(args) {
|
|
1658
552
|
if (typeof args.token === "undefined") throw new Error("The authentication message requires `token` as an argument.");
|
|
1659
|
-
writeVarString(this.encoder, args.documentName);
|
|
1660
|
-
writeVarUint(this.encoder, this.type);
|
|
553
|
+
(0, lib0_encoding.writeVarString)(this.encoder, args.documentName);
|
|
554
|
+
(0, lib0_encoding.writeVarUint)(this.encoder, this.type);
|
|
1661
555
|
(0, _hocuspocus_common.writeAuthentication)(this.encoder, args.token);
|
|
1662
|
-
writeVarString(this.encoder, version);
|
|
556
|
+
(0, lib0_encoding.writeVarString)(this.encoder, version);
|
|
1663
557
|
return this.encoder;
|
|
1664
558
|
}
|
|
1665
559
|
};
|
|
@@ -1675,12 +569,12 @@ var AwarenessMessage = class extends OutgoingMessage {
|
|
|
1675
569
|
get(args) {
|
|
1676
570
|
if (typeof args.awareness === "undefined") throw new Error("The awareness message requires awareness as an argument");
|
|
1677
571
|
if (typeof args.clients === "undefined") throw new Error("The awareness message requires clients as an argument");
|
|
1678
|
-
writeVarString(this.encoder, args.documentName);
|
|
1679
|
-
writeVarUint(this.encoder, this.type);
|
|
572
|
+
lib0_encoding.writeVarString(this.encoder, args.documentName);
|
|
573
|
+
lib0_encoding.writeVarUint(this.encoder, this.type);
|
|
1680
574
|
let awarenessUpdate;
|
|
1681
|
-
if (args.states === void 0) awarenessUpdate = encodeAwarenessUpdate(args.awareness, args.clients);
|
|
1682
|
-
else awarenessUpdate = encodeAwarenessUpdate(args.awareness, args.clients, args.states);
|
|
1683
|
-
writeVarUint8Array(this.encoder, awarenessUpdate);
|
|
575
|
+
if (args.states === void 0) awarenessUpdate = (0, y_protocols_awareness.encodeAwarenessUpdate)(args.awareness, args.clients);
|
|
576
|
+
else awarenessUpdate = (0, y_protocols_awareness.encodeAwarenessUpdate)(args.awareness, args.clients, args.states);
|
|
577
|
+
lib0_encoding.writeVarUint8Array(this.encoder, awarenessUpdate);
|
|
1684
578
|
return this.encoder;
|
|
1685
579
|
}
|
|
1686
580
|
};
|
|
@@ -1694,9 +588,9 @@ var StatelessMessage = class extends OutgoingMessage {
|
|
|
1694
588
|
this.description = "A stateless message";
|
|
1695
589
|
}
|
|
1696
590
|
get(args) {
|
|
1697
|
-
writeVarString(this.encoder, args.documentName);
|
|
1698
|
-
writeVarUint(this.encoder, this.type);
|
|
1699
|
-
writeVarString(this.encoder, args.payload ?? "");
|
|
591
|
+
(0, lib0_encoding.writeVarString)(this.encoder, args.documentName);
|
|
592
|
+
(0, lib0_encoding.writeVarUint)(this.encoder, this.type);
|
|
593
|
+
(0, lib0_encoding.writeVarString)(this.encoder, args.payload ?? "");
|
|
1700
594
|
return this.encoder;
|
|
1701
595
|
}
|
|
1702
596
|
};
|
|
@@ -1711,9 +605,9 @@ var SyncStepOneMessage = class extends OutgoingMessage {
|
|
|
1711
605
|
}
|
|
1712
606
|
get(args) {
|
|
1713
607
|
if (typeof args.document === "undefined") throw new Error("The sync step one message requires document as an argument");
|
|
1714
|
-
writeVarString(this.encoder, args.documentName);
|
|
1715
|
-
writeVarUint(this.encoder, this.type);
|
|
1716
|
-
writeSyncStep1(this.encoder, args.document);
|
|
608
|
+
lib0_encoding.writeVarString(this.encoder, args.documentName);
|
|
609
|
+
lib0_encoding.writeVarUint(this.encoder, this.type);
|
|
610
|
+
y_protocols_sync.writeSyncStep1(this.encoder, args.document);
|
|
1717
611
|
return this.encoder;
|
|
1718
612
|
}
|
|
1719
613
|
};
|
|
@@ -1727,9 +621,9 @@ var UpdateMessage = class extends OutgoingMessage {
|
|
|
1727
621
|
this.description = "A document update";
|
|
1728
622
|
}
|
|
1729
623
|
get(args) {
|
|
1730
|
-
writeVarString(this.encoder, args.documentName);
|
|
1731
|
-
writeVarUint(this.encoder, this.type);
|
|
1732
|
-
writeUpdate(this.encoder, args.update);
|
|
624
|
+
(0, lib0_encoding.writeVarString)(this.encoder, args.documentName);
|
|
625
|
+
(0, lib0_encoding.writeVarUint)(this.encoder, this.type);
|
|
626
|
+
(0, y_protocols_sync.writeUpdate)(this.encoder, args.update);
|
|
1733
627
|
return this.encoder;
|
|
1734
628
|
}
|
|
1735
629
|
};
|
|
@@ -1796,7 +690,7 @@ var HocuspocusProvider = class extends EventEmitter {
|
|
|
1796
690
|
this.forwardDestroy = () => this.emit("destroy");
|
|
1797
691
|
this.setConfiguration(configuration);
|
|
1798
692
|
this.configuration.document = configuration.document ? configuration.document : new yjs.Doc();
|
|
1799
|
-
this.configuration.awareness = configuration.awareness !== void 0 ? configuration.awareness : new Awareness(this.document);
|
|
693
|
+
this.configuration.awareness = configuration.awareness !== void 0 ? configuration.awareness : new y_protocols_awareness.Awareness(this.document);
|
|
1800
694
|
this.on("open", this.configuration.onOpen);
|
|
1801
695
|
this.on("message", this.configuration.onMessage);
|
|
1802
696
|
this.on("outgoingMessage", this.configuration.onOutgoingMessage);
|
|
@@ -1863,7 +757,7 @@ var HocuspocusProvider = class extends EventEmitter {
|
|
|
1863
757
|
});
|
|
1864
758
|
}
|
|
1865
759
|
pageHide() {
|
|
1866
|
-
if (this.awareness) removeAwarenessStates(this.awareness, [this.document.clientID], "page hide");
|
|
760
|
+
if (this.awareness) (0, y_protocols_awareness.removeAwarenessStates)(this.awareness, [this.document.clientID], "page hide");
|
|
1867
761
|
}
|
|
1868
762
|
registerEventListeners() {
|
|
1869
763
|
if (typeof window === "undefined" || !("addEventListener" in window)) return;
|
|
@@ -1970,13 +864,13 @@ var HocuspocusProvider = class extends EventEmitter {
|
|
|
1970
864
|
onClose() {
|
|
1971
865
|
this.isAuthenticated = false;
|
|
1972
866
|
this.synced = false;
|
|
1973
|
-
if (this.awareness) removeAwarenessStates(this.awareness, Array.from(this.awareness.getStates().keys()).filter((client) => client !== this.document.clientID), this);
|
|
867
|
+
if (this.awareness) (0, y_protocols_awareness.removeAwarenessStates)(this.awareness, Array.from(this.awareness.getStates().keys()).filter((client) => client !== this.document.clientID), this);
|
|
1974
868
|
}
|
|
1975
869
|
destroy() {
|
|
1976
870
|
this.emit("destroy");
|
|
1977
871
|
if (this.intervals.forceSync) clearInterval(this.intervals.forceSync);
|
|
1978
872
|
if (this.awareness) {
|
|
1979
|
-
removeAwarenessStates(this.awareness, [this.document.clientID], "provider destroy");
|
|
873
|
+
(0, y_protocols_awareness.removeAwarenessStates)(this.awareness, [this.document.clientID], "provider destroy");
|
|
1980
874
|
this.awareness.off("update", this.boundAwarenessUpdateHandler);
|
|
1981
875
|
this.awareness.destroy();
|
|
1982
876
|
}
|