@richscripts/richtexteditor 2.4.1 → 2.5.0
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/package.json +4 -2
- package/richtexteditor/all_plugins.js +2861 -935
- package/richtexteditor/all_plugins.min.js +58 -58
- package/richtexteditor/plugins/accessibilitychecker.js +186 -1
- package/richtexteditor/plugins/aitoolkit.js +1 -1
- package/richtexteditor/plugins/all_plugins.js +2861 -935
- package/richtexteditor/plugins/all_plugins.min.js +58 -58
- package/richtexteditor/plugins/crdt-engine.js +2201 -198
- package/richtexteditor/plugins/crdt-engine.min.js +5 -5
- package/richtexteditor/plugins/gapcursor.js +365 -0
- package/richtexteditor/plugins/imageeditor.js +30 -3
- package/richtexteditor/plugins/importstyles.js +312 -0
- package/richtexteditor/plugins/insertcode.js +81 -4
- package/richtexteditor/plugins/insertemoji.js +302 -229
- package/richtexteditor/plugins/insertgallery.js +34 -6
- package/richtexteditor/plugins/keyboarda11y.js +27 -1
- package/richtexteditor/plugins/multiroot.js +269 -0
- package/richtexteditor/plugins/revisionhistory.js +5 -0
- package/richtexteditor/plugins/sanitizer.js +24 -0
- package/richtexteditor/plugins/textpartlanguage.js +504 -0
- package/richtexteditor/plugins/trackedchanges.js +716 -689
- package/richtexteditor/plugins/wordexport.js +1 -1
- package/richtexteditor/rte-config.js +2 -2
- package/richtexteditor/rte.js +55 -51
- package/richtexteditor/rte_theme_default.css +151 -83
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* RichTextEditor CRDT engine. */
|
|
1
|
+
/* RichTextEditor CRDT engine — bundled for rte.js consumption. See https://richtexteditor.com/docs/crdt-internals.aspx */
|
|
2
2
|
"use strict";
|
|
3
3
|
(() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
|
-
var
|
|
14
|
-
__export(
|
|
13
|
+
var index_exports = {};
|
|
14
|
+
__export(index_exports, {
|
|
15
15
|
BLOCK_TAGS: () => BLOCK_TAGS,
|
|
16
16
|
INLINE_MARK_TAGS: () => INLINE_MARK_TAGS,
|
|
17
17
|
LEAF_TAGS: () => LEAF_TAGS,
|
|
@@ -30,7 +30,115 @@
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
// src/types.ts
|
|
33
|
-
var LOCAL_ORIGIN = Symbol.for("rte.crdt.local");
|
|
33
|
+
var LOCAL_ORIGIN = /* @__PURE__ */ Symbol.for("rte.crdt.local");
|
|
34
|
+
|
|
35
|
+
// node_modules/yjs/dist/yjs.mjs
|
|
36
|
+
var yjs_exports = {};
|
|
37
|
+
__export(yjs_exports, {
|
|
38
|
+
AbsolutePosition: () => AbsolutePosition,
|
|
39
|
+
AbstractConnector: () => AbstractConnector,
|
|
40
|
+
AbstractStruct: () => AbstractStruct,
|
|
41
|
+
AbstractType: () => AbstractType,
|
|
42
|
+
Array: () => YArray,
|
|
43
|
+
ContentAny: () => ContentAny,
|
|
44
|
+
ContentBinary: () => ContentBinary,
|
|
45
|
+
ContentDeleted: () => ContentDeleted,
|
|
46
|
+
ContentDoc: () => ContentDoc,
|
|
47
|
+
ContentEmbed: () => ContentEmbed,
|
|
48
|
+
ContentFormat: () => ContentFormat,
|
|
49
|
+
ContentJSON: () => ContentJSON,
|
|
50
|
+
ContentString: () => ContentString,
|
|
51
|
+
ContentType: () => ContentType,
|
|
52
|
+
Doc: () => Doc,
|
|
53
|
+
GC: () => GC,
|
|
54
|
+
ID: () => ID,
|
|
55
|
+
Item: () => Item,
|
|
56
|
+
Map: () => YMap,
|
|
57
|
+
PermanentUserData: () => PermanentUserData,
|
|
58
|
+
RelativePosition: () => RelativePosition,
|
|
59
|
+
Skip: () => Skip,
|
|
60
|
+
Snapshot: () => Snapshot,
|
|
61
|
+
Text: () => YText,
|
|
62
|
+
Transaction: () => Transaction,
|
|
63
|
+
UndoManager: () => UndoManager,
|
|
64
|
+
UpdateDecoderV1: () => UpdateDecoderV1,
|
|
65
|
+
UpdateDecoderV2: () => UpdateDecoderV2,
|
|
66
|
+
UpdateEncoderV1: () => UpdateEncoderV1,
|
|
67
|
+
UpdateEncoderV2: () => UpdateEncoderV2,
|
|
68
|
+
XmlElement: () => YXmlElement,
|
|
69
|
+
XmlFragment: () => YXmlFragment,
|
|
70
|
+
XmlHook: () => YXmlHook,
|
|
71
|
+
XmlText: () => YXmlText,
|
|
72
|
+
YArrayEvent: () => YArrayEvent,
|
|
73
|
+
YEvent: () => YEvent,
|
|
74
|
+
YMapEvent: () => YMapEvent,
|
|
75
|
+
YTextEvent: () => YTextEvent,
|
|
76
|
+
YXmlEvent: () => YXmlEvent,
|
|
77
|
+
applyUpdate: () => applyUpdate,
|
|
78
|
+
applyUpdateV2: () => applyUpdateV2,
|
|
79
|
+
cleanupYTextFormatting: () => cleanupYTextFormatting,
|
|
80
|
+
compareIDs: () => compareIDs,
|
|
81
|
+
compareRelativePositions: () => compareRelativePositions,
|
|
82
|
+
convertUpdateFormatV1ToV2: () => convertUpdateFormatV1ToV2,
|
|
83
|
+
convertUpdateFormatV2ToV1: () => convertUpdateFormatV2ToV1,
|
|
84
|
+
createAbsolutePositionFromRelativePosition: () => createAbsolutePositionFromRelativePosition,
|
|
85
|
+
createDeleteSet: () => createDeleteSet,
|
|
86
|
+
createDeleteSetFromStructStore: () => createDeleteSetFromStructStore,
|
|
87
|
+
createDocFromSnapshot: () => createDocFromSnapshot,
|
|
88
|
+
createID: () => createID,
|
|
89
|
+
createRelativePositionFromJSON: () => createRelativePositionFromJSON,
|
|
90
|
+
createRelativePositionFromTypeIndex: () => createRelativePositionFromTypeIndex,
|
|
91
|
+
createSnapshot: () => createSnapshot,
|
|
92
|
+
decodeRelativePosition: () => decodeRelativePosition,
|
|
93
|
+
decodeSnapshot: () => decodeSnapshot,
|
|
94
|
+
decodeSnapshotV2: () => decodeSnapshotV2,
|
|
95
|
+
decodeStateVector: () => decodeStateVector,
|
|
96
|
+
decodeUpdate: () => decodeUpdate,
|
|
97
|
+
decodeUpdateV2: () => decodeUpdateV2,
|
|
98
|
+
diffUpdate: () => diffUpdate,
|
|
99
|
+
diffUpdateV2: () => diffUpdateV2,
|
|
100
|
+
emptySnapshot: () => emptySnapshot,
|
|
101
|
+
encodeRelativePosition: () => encodeRelativePosition,
|
|
102
|
+
encodeSnapshot: () => encodeSnapshot,
|
|
103
|
+
encodeSnapshotV2: () => encodeSnapshotV2,
|
|
104
|
+
encodeStateAsUpdate: () => encodeStateAsUpdate,
|
|
105
|
+
encodeStateAsUpdateV2: () => encodeStateAsUpdateV2,
|
|
106
|
+
encodeStateVector: () => encodeStateVector,
|
|
107
|
+
encodeStateVectorFromUpdate: () => encodeStateVectorFromUpdate,
|
|
108
|
+
encodeStateVectorFromUpdateV2: () => encodeStateVectorFromUpdateV2,
|
|
109
|
+
equalDeleteSets: () => equalDeleteSets,
|
|
110
|
+
equalSnapshots: () => equalSnapshots,
|
|
111
|
+
findIndexSS: () => findIndexSS,
|
|
112
|
+
findRootTypeKey: () => findRootTypeKey,
|
|
113
|
+
getItem: () => getItem,
|
|
114
|
+
getItemCleanEnd: () => getItemCleanEnd,
|
|
115
|
+
getItemCleanStart: () => getItemCleanStart,
|
|
116
|
+
getState: () => getState,
|
|
117
|
+
getTypeChildren: () => getTypeChildren,
|
|
118
|
+
isDeleted: () => isDeleted,
|
|
119
|
+
isParentOf: () => isParentOf,
|
|
120
|
+
iterateDeletedStructs: () => iterateDeletedStructs,
|
|
121
|
+
logType: () => logType,
|
|
122
|
+
logUpdate: () => logUpdate,
|
|
123
|
+
logUpdateV2: () => logUpdateV2,
|
|
124
|
+
mergeDeleteSets: () => mergeDeleteSets,
|
|
125
|
+
mergeUpdates: () => mergeUpdates,
|
|
126
|
+
mergeUpdatesV2: () => mergeUpdatesV2,
|
|
127
|
+
obfuscateUpdate: () => obfuscateUpdate,
|
|
128
|
+
obfuscateUpdateV2: () => obfuscateUpdateV2,
|
|
129
|
+
parseUpdateMeta: () => parseUpdateMeta,
|
|
130
|
+
parseUpdateMetaV2: () => parseUpdateMetaV2,
|
|
131
|
+
readUpdate: () => readUpdate,
|
|
132
|
+
readUpdateV2: () => readUpdateV2,
|
|
133
|
+
relativePositionToJSON: () => relativePositionToJSON,
|
|
134
|
+
snapshot: () => snapshot,
|
|
135
|
+
snapshotContainsUpdate: () => snapshotContainsUpdate,
|
|
136
|
+
transact: () => transact,
|
|
137
|
+
tryGc: () => tryGc,
|
|
138
|
+
typeListToArraySnapshot: () => typeListToArraySnapshot,
|
|
139
|
+
typeMapGetAllSnapshot: () => typeMapGetAllSnapshot,
|
|
140
|
+
typeMapGetSnapshot: () => typeMapGetSnapshot
|
|
141
|
+
});
|
|
34
142
|
|
|
35
143
|
// node_modules/lib0/map.js
|
|
36
144
|
var create = () => /* @__PURE__ */ new Map();
|
|
@@ -170,6 +278,57 @@
|
|
|
170
278
|
this._observers = create();
|
|
171
279
|
}
|
|
172
280
|
};
|
|
281
|
+
var Observable = class {
|
|
282
|
+
constructor() {
|
|
283
|
+
this._observers = create();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* @param {N} name
|
|
287
|
+
* @param {function} f
|
|
288
|
+
*/
|
|
289
|
+
on(name, f) {
|
|
290
|
+
setIfUndefined(this._observers, name, create2).add(f);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* @param {N} name
|
|
294
|
+
* @param {function} f
|
|
295
|
+
*/
|
|
296
|
+
once(name, f) {
|
|
297
|
+
const _f = (...args2) => {
|
|
298
|
+
this.off(name, _f);
|
|
299
|
+
f(...args2);
|
|
300
|
+
};
|
|
301
|
+
this.on(name, _f);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* @param {N} name
|
|
305
|
+
* @param {function} f
|
|
306
|
+
*/
|
|
307
|
+
off(name, f) {
|
|
308
|
+
const observers = this._observers.get(name);
|
|
309
|
+
if (observers !== void 0) {
|
|
310
|
+
observers.delete(f);
|
|
311
|
+
if (observers.size === 0) {
|
|
312
|
+
this._observers.delete(name);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Emit a named event. All registered event listeners that listen to the
|
|
318
|
+
* specified name will receive the event.
|
|
319
|
+
*
|
|
320
|
+
* @todo This should catch exceptions
|
|
321
|
+
*
|
|
322
|
+
* @param {N} name The event name.
|
|
323
|
+
* @param {Array<any>} args The arguments that are applied to the event listener.
|
|
324
|
+
*/
|
|
325
|
+
emit(name, args2) {
|
|
326
|
+
return from((this._observers.get(name) || create()).values()).forEach((f) => f(...args2));
|
|
327
|
+
}
|
|
328
|
+
destroy() {
|
|
329
|
+
this._observers = create();
|
|
330
|
+
}
|
|
331
|
+
};
|
|
173
332
|
|
|
174
333
|
// node_modules/lib0/math.js
|
|
175
334
|
var floor = Math.floor;
|
|
@@ -351,6 +510,7 @@
|
|
|
351
510
|
};
|
|
352
511
|
var writeVarString = utf8TextEncoder && /** @type {any} */
|
|
353
512
|
utf8TextEncoder.encodeInto ? _writeVarStringNative : _writeVarStringPolyfill;
|
|
513
|
+
var writeBinaryEncoder = (encoder, append2) => writeUint8Array(encoder, toUint8Array(append2));
|
|
354
514
|
var writeUint8Array = (encoder, uint8Array) => {
|
|
355
515
|
const bufferLen = encoder.cbuf.length;
|
|
356
516
|
const cpos = encoder.cpos;
|
|
@@ -667,6 +827,157 @@
|
|
|
667
827
|
utf8TextDecoder.decode(readVarUint8Array(decoder))
|
|
668
828
|
);
|
|
669
829
|
var readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
830
|
+
var readFromDataView = (decoder, len) => {
|
|
831
|
+
const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len);
|
|
832
|
+
decoder.pos += len;
|
|
833
|
+
return dv;
|
|
834
|
+
};
|
|
835
|
+
var readFloat32 = (decoder) => readFromDataView(decoder, 4).getFloat32(0, false);
|
|
836
|
+
var readFloat64 = (decoder) => readFromDataView(decoder, 8).getFloat64(0, false);
|
|
837
|
+
var readBigInt64 = (decoder) => (
|
|
838
|
+
/** @type {any} */
|
|
839
|
+
readFromDataView(decoder, 8).getBigInt64(0, false)
|
|
840
|
+
);
|
|
841
|
+
var readAnyLookupTable = [
|
|
842
|
+
(decoder) => void 0,
|
|
843
|
+
// CASE 127: undefined
|
|
844
|
+
(decoder) => null,
|
|
845
|
+
// CASE 126: null
|
|
846
|
+
readVarInt,
|
|
847
|
+
// CASE 125: integer
|
|
848
|
+
readFloat32,
|
|
849
|
+
// CASE 124: float32
|
|
850
|
+
readFloat64,
|
|
851
|
+
// CASE 123: float64
|
|
852
|
+
readBigInt64,
|
|
853
|
+
// CASE 122: bigint
|
|
854
|
+
(decoder) => false,
|
|
855
|
+
// CASE 121: boolean (false)
|
|
856
|
+
(decoder) => true,
|
|
857
|
+
// CASE 120: boolean (true)
|
|
858
|
+
readVarString,
|
|
859
|
+
// CASE 119: string
|
|
860
|
+
(decoder) => {
|
|
861
|
+
const len = readVarUint(decoder);
|
|
862
|
+
const obj = {};
|
|
863
|
+
for (let i = 0; i < len; i++) {
|
|
864
|
+
const key = readVarString(decoder);
|
|
865
|
+
obj[key] = readAny(decoder);
|
|
866
|
+
}
|
|
867
|
+
return obj;
|
|
868
|
+
},
|
|
869
|
+
(decoder) => {
|
|
870
|
+
const len = readVarUint(decoder);
|
|
871
|
+
const arr = [];
|
|
872
|
+
for (let i = 0; i < len; i++) {
|
|
873
|
+
arr.push(readAny(decoder));
|
|
874
|
+
}
|
|
875
|
+
return arr;
|
|
876
|
+
},
|
|
877
|
+
readVarUint8Array
|
|
878
|
+
// CASE 116: Uint8Array
|
|
879
|
+
];
|
|
880
|
+
var readAny = (decoder) => readAnyLookupTable[127 - readUint8(decoder)](decoder);
|
|
881
|
+
var RleDecoder = class extends Decoder {
|
|
882
|
+
/**
|
|
883
|
+
* @param {Uint8Array} uint8Array
|
|
884
|
+
* @param {function(Decoder):T} reader
|
|
885
|
+
*/
|
|
886
|
+
constructor(uint8Array, reader) {
|
|
887
|
+
super(uint8Array);
|
|
888
|
+
this.reader = reader;
|
|
889
|
+
this.s = null;
|
|
890
|
+
this.count = 0;
|
|
891
|
+
}
|
|
892
|
+
read() {
|
|
893
|
+
if (this.count === 0) {
|
|
894
|
+
this.s = this.reader(this);
|
|
895
|
+
if (hasContent(this)) {
|
|
896
|
+
this.count = readVarUint(this) + 1;
|
|
897
|
+
} else {
|
|
898
|
+
this.count = -1;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
this.count--;
|
|
902
|
+
return (
|
|
903
|
+
/** @type {T} */
|
|
904
|
+
this.s
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
var UintOptRleDecoder = class extends Decoder {
|
|
909
|
+
/**
|
|
910
|
+
* @param {Uint8Array} uint8Array
|
|
911
|
+
*/
|
|
912
|
+
constructor(uint8Array) {
|
|
913
|
+
super(uint8Array);
|
|
914
|
+
this.s = 0;
|
|
915
|
+
this.count = 0;
|
|
916
|
+
}
|
|
917
|
+
read() {
|
|
918
|
+
if (this.count === 0) {
|
|
919
|
+
this.s = readVarInt(this);
|
|
920
|
+
const isNegative = isNegativeZero(this.s);
|
|
921
|
+
this.count = 1;
|
|
922
|
+
if (isNegative) {
|
|
923
|
+
this.s = -this.s;
|
|
924
|
+
this.count = readVarUint(this) + 2;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
this.count--;
|
|
928
|
+
return (
|
|
929
|
+
/** @type {number} */
|
|
930
|
+
this.s
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
var IntDiffOptRleDecoder = class extends Decoder {
|
|
935
|
+
/**
|
|
936
|
+
* @param {Uint8Array} uint8Array
|
|
937
|
+
*/
|
|
938
|
+
constructor(uint8Array) {
|
|
939
|
+
super(uint8Array);
|
|
940
|
+
this.s = 0;
|
|
941
|
+
this.count = 0;
|
|
942
|
+
this.diff = 0;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* @return {number}
|
|
946
|
+
*/
|
|
947
|
+
read() {
|
|
948
|
+
if (this.count === 0) {
|
|
949
|
+
const diff = readVarInt(this);
|
|
950
|
+
const hasCount = diff & 1;
|
|
951
|
+
this.diff = floor(diff / 2);
|
|
952
|
+
this.count = 1;
|
|
953
|
+
if (hasCount) {
|
|
954
|
+
this.count = readVarUint(this) + 2;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
this.s += this.diff;
|
|
958
|
+
this.count--;
|
|
959
|
+
return this.s;
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
var StringDecoder = class {
|
|
963
|
+
/**
|
|
964
|
+
* @param {Uint8Array} uint8Array
|
|
965
|
+
*/
|
|
966
|
+
constructor(uint8Array) {
|
|
967
|
+
this.decoder = new UintOptRleDecoder(uint8Array);
|
|
968
|
+
this.str = readVarString(this.decoder);
|
|
969
|
+
this.spos = 0;
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* @return {string}
|
|
973
|
+
*/
|
|
974
|
+
read() {
|
|
975
|
+
const end = this.spos + this.decoder.read();
|
|
976
|
+
const res = this.str.slice(this.spos, end);
|
|
977
|
+
this.spos = end;
|
|
978
|
+
return res;
|
|
979
|
+
}
|
|
980
|
+
};
|
|
670
981
|
|
|
671
982
|
// node_modules/lib0/webcrypto.js
|
|
672
983
|
var subtle = crypto.subtle;
|
|
@@ -725,7 +1036,7 @@
|
|
|
725
1036
|
var varStorage = _localStorage;
|
|
726
1037
|
|
|
727
1038
|
// node_modules/lib0/trait/equality.js
|
|
728
|
-
var EqualityTraitSymbol = Symbol("Equality");
|
|
1039
|
+
var EqualityTraitSymbol = /* @__PURE__ */ Symbol("Equality");
|
|
729
1040
|
var equals = (a, b) => {
|
|
730
1041
|
var _a;
|
|
731
1042
|
return a === b || !!((_a = a == null ? void 0 : a[EqualityTraitSymbol]) == null ? void 0 : _a.call(a, b)) || false;
|
|
@@ -780,6 +1091,7 @@
|
|
|
780
1091
|
}
|
|
781
1092
|
}
|
|
782
1093
|
};
|
|
1094
|
+
var id = (a) => a;
|
|
783
1095
|
var equalityDeep = (a, b) => {
|
|
784
1096
|
if (a === b) {
|
|
785
1097
|
return true;
|
|
@@ -909,6 +1221,14 @@
|
|
|
909
1221
|
var supportsColor = forceColor || !hasParam("--no-colors") && // @todo deprecate --no-colors
|
|
910
1222
|
!hasConf("no-color") && (!isNode || process.stdout.isTTY) && (!isNode || hasParam("--color") || getVariable("COLORTERM") !== null || (getVariable("TERM") || "").includes("color"));
|
|
911
1223
|
|
|
1224
|
+
// node_modules/lib0/buffer.js
|
|
1225
|
+
var createUint8ArrayFromLen = (len) => new Uint8Array(len);
|
|
1226
|
+
var copyUint8Array = (uint8Array) => {
|
|
1227
|
+
const newBuf = createUint8ArrayFromLen(uint8Array.byteLength);
|
|
1228
|
+
newBuf.set(uint8Array);
|
|
1229
|
+
return newBuf;
|
|
1230
|
+
};
|
|
1231
|
+
|
|
912
1232
|
// node_modules/lib0/pair.js
|
|
913
1233
|
var Pair = class {
|
|
914
1234
|
/**
|
|
@@ -939,7 +1259,7 @@
|
|
|
939
1259
|
var oneOf = (gen, array) => array[int31(gen, 0, array.length - 1)];
|
|
940
1260
|
|
|
941
1261
|
// node_modules/lib0/schema.js
|
|
942
|
-
var schemaSymbol = Symbol("0schema");
|
|
1262
|
+
var schemaSymbol = /* @__PURE__ */ Symbol("0schema");
|
|
943
1263
|
var ValidationError = class {
|
|
944
1264
|
constructor() {
|
|
945
1265
|
this._rerrs = [];
|
|
@@ -1217,7 +1537,7 @@
|
|
|
1217
1537
|
}
|
|
1218
1538
|
};
|
|
1219
1539
|
var $$stringTemplate = $constructedBy($StringTemplate);
|
|
1220
|
-
var isOptionalSymbol = Symbol("optional");
|
|
1540
|
+
var isOptionalSymbol = /* @__PURE__ */ Symbol("optional");
|
|
1221
1541
|
var $Optional = class extends Schema {
|
|
1222
1542
|
/**
|
|
1223
1543
|
* @param {S} shape
|
|
@@ -1838,6 +2158,17 @@ ${err.toString()}`);
|
|
|
1838
2158
|
});
|
|
1839
2159
|
|
|
1840
2160
|
// node_modules/yjs/dist/yjs.mjs
|
|
2161
|
+
var AbstractConnector = class extends ObservableV2 {
|
|
2162
|
+
/**
|
|
2163
|
+
* @param {Doc} ydoc
|
|
2164
|
+
* @param {any} awareness
|
|
2165
|
+
*/
|
|
2166
|
+
constructor(ydoc, awareness) {
|
|
2167
|
+
super();
|
|
2168
|
+
this.doc = ydoc;
|
|
2169
|
+
this.awareness = awareness;
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
1841
2172
|
var DeleteItem = class {
|
|
1842
2173
|
/**
|
|
1843
2174
|
* @param {number} clock
|
|
@@ -1930,6 +2261,29 @@ ${err.toString()}`);
|
|
|
1930
2261
|
)).push(new DeleteItem(clock, length2));
|
|
1931
2262
|
};
|
|
1932
2263
|
var createDeleteSet = () => new DeleteSet();
|
|
2264
|
+
var createDeleteSetFromStructStore = (ss) => {
|
|
2265
|
+
const ds = createDeleteSet();
|
|
2266
|
+
ss.clients.forEach((structs, client) => {
|
|
2267
|
+
const dsitems = [];
|
|
2268
|
+
for (let i = 0; i < structs.length; i++) {
|
|
2269
|
+
const struct = structs[i];
|
|
2270
|
+
if (struct.deleted) {
|
|
2271
|
+
const clock = struct.id.clock;
|
|
2272
|
+
let len = struct.length;
|
|
2273
|
+
if (i + 1 < structs.length) {
|
|
2274
|
+
for (let next = structs[i + 1]; i + 1 < structs.length && next.deleted; next = structs[++i + 1]) {
|
|
2275
|
+
len += next.length;
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
dsitems.push(new DeleteItem(clock, len));
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
if (dsitems.length > 0) {
|
|
2282
|
+
ds.clients.set(client, dsitems);
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
return ds;
|
|
2286
|
+
};
|
|
1933
2287
|
var writeDeleteSet = (encoder, ds) => {
|
|
1934
2288
|
writeVarUint(encoder.restEncoder, ds.clients.size);
|
|
1935
2289
|
from(ds.clients.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, dsitems]) => {
|
|
@@ -1944,6 +2298,91 @@ ${err.toString()}`);
|
|
|
1944
2298
|
}
|
|
1945
2299
|
});
|
|
1946
2300
|
};
|
|
2301
|
+
var readDeleteSet = (decoder) => {
|
|
2302
|
+
const ds = new DeleteSet();
|
|
2303
|
+
const numClients = readVarUint(decoder.restDecoder);
|
|
2304
|
+
for (let i = 0; i < numClients; i++) {
|
|
2305
|
+
decoder.resetDsCurVal();
|
|
2306
|
+
const client = readVarUint(decoder.restDecoder);
|
|
2307
|
+
const numberOfDeletes = readVarUint(decoder.restDecoder);
|
|
2308
|
+
if (numberOfDeletes > 0) {
|
|
2309
|
+
const dsField = setIfUndefined(ds.clients, client, () => (
|
|
2310
|
+
/** @type {Array<DeleteItem>} */
|
|
2311
|
+
[]
|
|
2312
|
+
));
|
|
2313
|
+
for (let i2 = 0; i2 < numberOfDeletes; i2++) {
|
|
2314
|
+
dsField.push(new DeleteItem(decoder.readDsClock(), decoder.readDsLen()));
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
return ds;
|
|
2319
|
+
};
|
|
2320
|
+
var readAndApplyDeleteSet = (decoder, transaction, store) => {
|
|
2321
|
+
const unappliedDS = new DeleteSet();
|
|
2322
|
+
const numClients = readVarUint(decoder.restDecoder);
|
|
2323
|
+
for (let i = 0; i < numClients; i++) {
|
|
2324
|
+
decoder.resetDsCurVal();
|
|
2325
|
+
const client = readVarUint(decoder.restDecoder);
|
|
2326
|
+
const numberOfDeletes = readVarUint(decoder.restDecoder);
|
|
2327
|
+
const structs = store.clients.get(client) || [];
|
|
2328
|
+
const state = getState(store, client);
|
|
2329
|
+
for (let i2 = 0; i2 < numberOfDeletes; i2++) {
|
|
2330
|
+
const clock = decoder.readDsClock();
|
|
2331
|
+
const clockEnd = clock + decoder.readDsLen();
|
|
2332
|
+
if (clock < state) {
|
|
2333
|
+
if (state < clockEnd) {
|
|
2334
|
+
addToDeleteSet(unappliedDS, client, state, clockEnd - state);
|
|
2335
|
+
}
|
|
2336
|
+
let index = findIndexSS(structs, clock);
|
|
2337
|
+
let struct = structs[index];
|
|
2338
|
+
if (!struct.deleted && struct.id.clock < clock) {
|
|
2339
|
+
structs.splice(index + 1, 0, splitItem(transaction, struct, clock - struct.id.clock));
|
|
2340
|
+
index++;
|
|
2341
|
+
}
|
|
2342
|
+
while (index < structs.length) {
|
|
2343
|
+
struct = structs[index++];
|
|
2344
|
+
if (struct.id.clock < clockEnd) {
|
|
2345
|
+
if (!struct.deleted) {
|
|
2346
|
+
if (clockEnd < struct.id.clock + struct.length) {
|
|
2347
|
+
structs.splice(index, 0, splitItem(transaction, struct, clockEnd - struct.id.clock));
|
|
2348
|
+
}
|
|
2349
|
+
struct.delete(transaction);
|
|
2350
|
+
}
|
|
2351
|
+
} else {
|
|
2352
|
+
break;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
} else {
|
|
2356
|
+
addToDeleteSet(unappliedDS, client, clock, clockEnd - clock);
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
if (unappliedDS.clients.size > 0) {
|
|
2361
|
+
const ds = new UpdateEncoderV2();
|
|
2362
|
+
writeVarUint(ds.restEncoder, 0);
|
|
2363
|
+
writeDeleteSet(ds, unappliedDS);
|
|
2364
|
+
return ds.toUint8Array();
|
|
2365
|
+
}
|
|
2366
|
+
return null;
|
|
2367
|
+
};
|
|
2368
|
+
var equalDeleteSets = (ds1, ds2) => {
|
|
2369
|
+
if (ds1.clients.size !== ds2.clients.size) return false;
|
|
2370
|
+
for (const [client, deleteItems1] of ds1.clients.entries()) {
|
|
2371
|
+
const deleteItems2 = (
|
|
2372
|
+
/** @type {Array<import('../internals.js').DeleteItem>} */
|
|
2373
|
+
ds2.clients.get(client)
|
|
2374
|
+
);
|
|
2375
|
+
if (deleteItems2 === void 0 || deleteItems1.length !== deleteItems2.length) return false;
|
|
2376
|
+
for (let i = 0; i < deleteItems1.length; i++) {
|
|
2377
|
+
const di1 = deleteItems1[i];
|
|
2378
|
+
const di2 = deleteItems2[i];
|
|
2379
|
+
if (di1.clock !== di2.clock || di1.len !== di2.len) {
|
|
2380
|
+
return false;
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
return true;
|
|
2385
|
+
};
|
|
1947
2386
|
var generateNewClientId = uint32;
|
|
1948
2387
|
var Doc = class _Doc extends ObservableV2 {
|
|
1949
2388
|
/**
|
|
@@ -2212,6 +2651,242 @@ ${err.toString()}`);
|
|
|
2212
2651
|
super.destroy();
|
|
2213
2652
|
}
|
|
2214
2653
|
};
|
|
2654
|
+
var DSDecoderV1 = class {
|
|
2655
|
+
/**
|
|
2656
|
+
* @param {decoding.Decoder} decoder
|
|
2657
|
+
*/
|
|
2658
|
+
constructor(decoder) {
|
|
2659
|
+
this.restDecoder = decoder;
|
|
2660
|
+
}
|
|
2661
|
+
resetDsCurVal() {
|
|
2662
|
+
}
|
|
2663
|
+
/**
|
|
2664
|
+
* @return {number}
|
|
2665
|
+
*/
|
|
2666
|
+
readDsClock() {
|
|
2667
|
+
return readVarUint(this.restDecoder);
|
|
2668
|
+
}
|
|
2669
|
+
/**
|
|
2670
|
+
* @return {number}
|
|
2671
|
+
*/
|
|
2672
|
+
readDsLen() {
|
|
2673
|
+
return readVarUint(this.restDecoder);
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2676
|
+
var UpdateDecoderV1 = class extends DSDecoderV1 {
|
|
2677
|
+
/**
|
|
2678
|
+
* @return {ID}
|
|
2679
|
+
*/
|
|
2680
|
+
readLeftID() {
|
|
2681
|
+
return createID(readVarUint(this.restDecoder), readVarUint(this.restDecoder));
|
|
2682
|
+
}
|
|
2683
|
+
/**
|
|
2684
|
+
* @return {ID}
|
|
2685
|
+
*/
|
|
2686
|
+
readRightID() {
|
|
2687
|
+
return createID(readVarUint(this.restDecoder), readVarUint(this.restDecoder));
|
|
2688
|
+
}
|
|
2689
|
+
/**
|
|
2690
|
+
* Read the next client id.
|
|
2691
|
+
* Use this in favor of readID whenever possible to reduce the number of objects created.
|
|
2692
|
+
*/
|
|
2693
|
+
readClient() {
|
|
2694
|
+
return readVarUint(this.restDecoder);
|
|
2695
|
+
}
|
|
2696
|
+
/**
|
|
2697
|
+
* @return {number} info An unsigned 8-bit integer
|
|
2698
|
+
*/
|
|
2699
|
+
readInfo() {
|
|
2700
|
+
return readUint8(this.restDecoder);
|
|
2701
|
+
}
|
|
2702
|
+
/**
|
|
2703
|
+
* @return {string}
|
|
2704
|
+
*/
|
|
2705
|
+
readString() {
|
|
2706
|
+
return readVarString(this.restDecoder);
|
|
2707
|
+
}
|
|
2708
|
+
/**
|
|
2709
|
+
* @return {boolean} isKey
|
|
2710
|
+
*/
|
|
2711
|
+
readParentInfo() {
|
|
2712
|
+
return readVarUint(this.restDecoder) === 1;
|
|
2713
|
+
}
|
|
2714
|
+
/**
|
|
2715
|
+
* @return {number} info An unsigned 8-bit integer
|
|
2716
|
+
*/
|
|
2717
|
+
readTypeRef() {
|
|
2718
|
+
return readVarUint(this.restDecoder);
|
|
2719
|
+
}
|
|
2720
|
+
/**
|
|
2721
|
+
* Write len of a struct - well suited for Opt RLE encoder.
|
|
2722
|
+
*
|
|
2723
|
+
* @return {number} len
|
|
2724
|
+
*/
|
|
2725
|
+
readLen() {
|
|
2726
|
+
return readVarUint(this.restDecoder);
|
|
2727
|
+
}
|
|
2728
|
+
/**
|
|
2729
|
+
* @return {any}
|
|
2730
|
+
*/
|
|
2731
|
+
readAny() {
|
|
2732
|
+
return readAny(this.restDecoder);
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* @return {Uint8Array}
|
|
2736
|
+
*/
|
|
2737
|
+
readBuf() {
|
|
2738
|
+
return copyUint8Array(readVarUint8Array(this.restDecoder));
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* Legacy implementation uses JSON parse. We use any-decoding in v2.
|
|
2742
|
+
*
|
|
2743
|
+
* @return {any}
|
|
2744
|
+
*/
|
|
2745
|
+
readJSON() {
|
|
2746
|
+
return JSON.parse(readVarString(this.restDecoder));
|
|
2747
|
+
}
|
|
2748
|
+
/**
|
|
2749
|
+
* @return {string}
|
|
2750
|
+
*/
|
|
2751
|
+
readKey() {
|
|
2752
|
+
return readVarString(this.restDecoder);
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
var DSDecoderV2 = class {
|
|
2756
|
+
/**
|
|
2757
|
+
* @param {decoding.Decoder} decoder
|
|
2758
|
+
*/
|
|
2759
|
+
constructor(decoder) {
|
|
2760
|
+
this.dsCurrVal = 0;
|
|
2761
|
+
this.restDecoder = decoder;
|
|
2762
|
+
}
|
|
2763
|
+
resetDsCurVal() {
|
|
2764
|
+
this.dsCurrVal = 0;
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2767
|
+
* @return {number}
|
|
2768
|
+
*/
|
|
2769
|
+
readDsClock() {
|
|
2770
|
+
this.dsCurrVal += readVarUint(this.restDecoder);
|
|
2771
|
+
return this.dsCurrVal;
|
|
2772
|
+
}
|
|
2773
|
+
/**
|
|
2774
|
+
* @return {number}
|
|
2775
|
+
*/
|
|
2776
|
+
readDsLen() {
|
|
2777
|
+
const diff = readVarUint(this.restDecoder) + 1;
|
|
2778
|
+
this.dsCurrVal += diff;
|
|
2779
|
+
return diff;
|
|
2780
|
+
}
|
|
2781
|
+
};
|
|
2782
|
+
var UpdateDecoderV2 = class extends DSDecoderV2 {
|
|
2783
|
+
/**
|
|
2784
|
+
* @param {decoding.Decoder} decoder
|
|
2785
|
+
*/
|
|
2786
|
+
constructor(decoder) {
|
|
2787
|
+
super(decoder);
|
|
2788
|
+
this.keys = [];
|
|
2789
|
+
readVarUint(decoder);
|
|
2790
|
+
this.keyClockDecoder = new IntDiffOptRleDecoder(readVarUint8Array(decoder));
|
|
2791
|
+
this.clientDecoder = new UintOptRleDecoder(readVarUint8Array(decoder));
|
|
2792
|
+
this.leftClockDecoder = new IntDiffOptRleDecoder(readVarUint8Array(decoder));
|
|
2793
|
+
this.rightClockDecoder = new IntDiffOptRleDecoder(readVarUint8Array(decoder));
|
|
2794
|
+
this.infoDecoder = new RleDecoder(readVarUint8Array(decoder), readUint8);
|
|
2795
|
+
this.stringDecoder = new StringDecoder(readVarUint8Array(decoder));
|
|
2796
|
+
this.parentInfoDecoder = new RleDecoder(readVarUint8Array(decoder), readUint8);
|
|
2797
|
+
this.typeRefDecoder = new UintOptRleDecoder(readVarUint8Array(decoder));
|
|
2798
|
+
this.lenDecoder = new UintOptRleDecoder(readVarUint8Array(decoder));
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2801
|
+
* @return {ID}
|
|
2802
|
+
*/
|
|
2803
|
+
readLeftID() {
|
|
2804
|
+
return new ID(this.clientDecoder.read(), this.leftClockDecoder.read());
|
|
2805
|
+
}
|
|
2806
|
+
/**
|
|
2807
|
+
* @return {ID}
|
|
2808
|
+
*/
|
|
2809
|
+
readRightID() {
|
|
2810
|
+
return new ID(this.clientDecoder.read(), this.rightClockDecoder.read());
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Read the next client id.
|
|
2814
|
+
* Use this in favor of readID whenever possible to reduce the number of objects created.
|
|
2815
|
+
*/
|
|
2816
|
+
readClient() {
|
|
2817
|
+
return this.clientDecoder.read();
|
|
2818
|
+
}
|
|
2819
|
+
/**
|
|
2820
|
+
* @return {number} info An unsigned 8-bit integer
|
|
2821
|
+
*/
|
|
2822
|
+
readInfo() {
|
|
2823
|
+
return (
|
|
2824
|
+
/** @type {number} */
|
|
2825
|
+
this.infoDecoder.read()
|
|
2826
|
+
);
|
|
2827
|
+
}
|
|
2828
|
+
/**
|
|
2829
|
+
* @return {string}
|
|
2830
|
+
*/
|
|
2831
|
+
readString() {
|
|
2832
|
+
return this.stringDecoder.read();
|
|
2833
|
+
}
|
|
2834
|
+
/**
|
|
2835
|
+
* @return {boolean}
|
|
2836
|
+
*/
|
|
2837
|
+
readParentInfo() {
|
|
2838
|
+
return this.parentInfoDecoder.read() === 1;
|
|
2839
|
+
}
|
|
2840
|
+
/**
|
|
2841
|
+
* @return {number} An unsigned 8-bit integer
|
|
2842
|
+
*/
|
|
2843
|
+
readTypeRef() {
|
|
2844
|
+
return this.typeRefDecoder.read();
|
|
2845
|
+
}
|
|
2846
|
+
/**
|
|
2847
|
+
* Write len of a struct - well suited for Opt RLE encoder.
|
|
2848
|
+
*
|
|
2849
|
+
* @return {number}
|
|
2850
|
+
*/
|
|
2851
|
+
readLen() {
|
|
2852
|
+
return this.lenDecoder.read();
|
|
2853
|
+
}
|
|
2854
|
+
/**
|
|
2855
|
+
* @return {any}
|
|
2856
|
+
*/
|
|
2857
|
+
readAny() {
|
|
2858
|
+
return readAny(this.restDecoder);
|
|
2859
|
+
}
|
|
2860
|
+
/**
|
|
2861
|
+
* @return {Uint8Array}
|
|
2862
|
+
*/
|
|
2863
|
+
readBuf() {
|
|
2864
|
+
return readVarUint8Array(this.restDecoder);
|
|
2865
|
+
}
|
|
2866
|
+
/**
|
|
2867
|
+
* This is mainly here for legacy purposes.
|
|
2868
|
+
*
|
|
2869
|
+
* 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.
|
|
2870
|
+
*
|
|
2871
|
+
* @return {any}
|
|
2872
|
+
*/
|
|
2873
|
+
readJSON() {
|
|
2874
|
+
return readAny(this.restDecoder);
|
|
2875
|
+
}
|
|
2876
|
+
/**
|
|
2877
|
+
* @return {string}
|
|
2878
|
+
*/
|
|
2879
|
+
readKey() {
|
|
2880
|
+
const keyClock = this.keyClockDecoder.read();
|
|
2881
|
+
if (keyClock < this.keys.length) {
|
|
2882
|
+
return this.keys[keyClock];
|
|
2883
|
+
} else {
|
|
2884
|
+
const key = this.stringDecoder.read();
|
|
2885
|
+
this.keys.push(key);
|
|
2886
|
+
return key;
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
};
|
|
2215
2890
|
var DSEncoderV1 = class {
|
|
2216
2891
|
constructor() {
|
|
2217
2892
|
this.restEncoder = createEncoder();
|
|
@@ -2500,7 +3175,285 @@ ${err.toString()}`);
|
|
|
2500
3175
|
);
|
|
2501
3176
|
});
|
|
2502
3177
|
};
|
|
3178
|
+
var readClientsStructRefs = (decoder, doc2) => {
|
|
3179
|
+
const clientRefs = create();
|
|
3180
|
+
const numOfStateUpdates = readVarUint(decoder.restDecoder);
|
|
3181
|
+
for (let i = 0; i < numOfStateUpdates; i++) {
|
|
3182
|
+
const numberOfStructs = readVarUint(decoder.restDecoder);
|
|
3183
|
+
const refs = new Array(numberOfStructs);
|
|
3184
|
+
const client = decoder.readClient();
|
|
3185
|
+
let clock = readVarUint(decoder.restDecoder);
|
|
3186
|
+
clientRefs.set(client, { i: 0, refs });
|
|
3187
|
+
for (let i2 = 0; i2 < numberOfStructs; i2++) {
|
|
3188
|
+
const info = decoder.readInfo();
|
|
3189
|
+
switch (BITS5 & info) {
|
|
3190
|
+
case 0: {
|
|
3191
|
+
const len = decoder.readLen();
|
|
3192
|
+
refs[i2] = new GC(createID(client, clock), len);
|
|
3193
|
+
clock += len;
|
|
3194
|
+
break;
|
|
3195
|
+
}
|
|
3196
|
+
case 10: {
|
|
3197
|
+
const len = readVarUint(decoder.restDecoder);
|
|
3198
|
+
refs[i2] = new Skip(createID(client, clock), len);
|
|
3199
|
+
clock += len;
|
|
3200
|
+
break;
|
|
3201
|
+
}
|
|
3202
|
+
default: {
|
|
3203
|
+
const cantCopyParentInfo = (info & (BIT7 | BIT8)) === 0;
|
|
3204
|
+
const struct = new Item(
|
|
3205
|
+
createID(client, clock),
|
|
3206
|
+
null,
|
|
3207
|
+
// left
|
|
3208
|
+
(info & BIT8) === BIT8 ? decoder.readLeftID() : null,
|
|
3209
|
+
// origin
|
|
3210
|
+
null,
|
|
3211
|
+
// right
|
|
3212
|
+
(info & BIT7) === BIT7 ? decoder.readRightID() : null,
|
|
3213
|
+
// right origin
|
|
3214
|
+
cantCopyParentInfo ? decoder.readParentInfo() ? doc2.get(decoder.readString()) : decoder.readLeftID() : null,
|
|
3215
|
+
// parent
|
|
3216
|
+
cantCopyParentInfo && (info & BIT6) === BIT6 ? decoder.readString() : null,
|
|
3217
|
+
// parentSub
|
|
3218
|
+
readItemContent(decoder, info)
|
|
3219
|
+
// item content
|
|
3220
|
+
);
|
|
3221
|
+
refs[i2] = struct;
|
|
3222
|
+
clock += struct.length;
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
return clientRefs;
|
|
3228
|
+
};
|
|
3229
|
+
var integrateStructs = (transaction, store, clientsStructRefs) => {
|
|
3230
|
+
const stack = [];
|
|
3231
|
+
let clientsStructRefsIds = from(clientsStructRefs.keys()).sort((a, b) => a - b);
|
|
3232
|
+
if (clientsStructRefsIds.length === 0) {
|
|
3233
|
+
return null;
|
|
3234
|
+
}
|
|
3235
|
+
const getNextStructTarget = () => {
|
|
3236
|
+
if (clientsStructRefsIds.length === 0) {
|
|
3237
|
+
return null;
|
|
3238
|
+
}
|
|
3239
|
+
let nextStructsTarget = (
|
|
3240
|
+
/** @type {{i:number,refs:Array<GC|Item>}} */
|
|
3241
|
+
clientsStructRefs.get(clientsStructRefsIds[clientsStructRefsIds.length - 1])
|
|
3242
|
+
);
|
|
3243
|
+
while (nextStructsTarget.refs.length === nextStructsTarget.i) {
|
|
3244
|
+
clientsStructRefsIds.pop();
|
|
3245
|
+
if (clientsStructRefsIds.length > 0) {
|
|
3246
|
+
nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */
|
|
3247
|
+
clientsStructRefs.get(clientsStructRefsIds[clientsStructRefsIds.length - 1]);
|
|
3248
|
+
} else {
|
|
3249
|
+
return null;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
return nextStructsTarget;
|
|
3253
|
+
};
|
|
3254
|
+
let curStructsTarget = getNextStructTarget();
|
|
3255
|
+
if (curStructsTarget === null) {
|
|
3256
|
+
return null;
|
|
3257
|
+
}
|
|
3258
|
+
const restStructs = new StructStore();
|
|
3259
|
+
const missingSV = /* @__PURE__ */ new Map();
|
|
3260
|
+
const updateMissingSv = (client, clock) => {
|
|
3261
|
+
const mclock = missingSV.get(client);
|
|
3262
|
+
if (mclock == null || mclock > clock) {
|
|
3263
|
+
missingSV.set(client, clock);
|
|
3264
|
+
}
|
|
3265
|
+
};
|
|
3266
|
+
let stackHead = (
|
|
3267
|
+
/** @type {any} */
|
|
3268
|
+
curStructsTarget.refs[
|
|
3269
|
+
/** @type {any} */
|
|
3270
|
+
curStructsTarget.i++
|
|
3271
|
+
]
|
|
3272
|
+
);
|
|
3273
|
+
const state = /* @__PURE__ */ new Map();
|
|
3274
|
+
const addStackToRestSS = () => {
|
|
3275
|
+
for (const item of stack) {
|
|
3276
|
+
const client = item.id.client;
|
|
3277
|
+
const inapplicableItems = clientsStructRefs.get(client);
|
|
3278
|
+
if (inapplicableItems) {
|
|
3279
|
+
inapplicableItems.i--;
|
|
3280
|
+
restStructs.clients.set(client, inapplicableItems.refs.slice(inapplicableItems.i));
|
|
3281
|
+
clientsStructRefs.delete(client);
|
|
3282
|
+
inapplicableItems.i = 0;
|
|
3283
|
+
inapplicableItems.refs = [];
|
|
3284
|
+
} else {
|
|
3285
|
+
restStructs.clients.set(client, [item]);
|
|
3286
|
+
}
|
|
3287
|
+
clientsStructRefsIds = clientsStructRefsIds.filter((c) => c !== client);
|
|
3288
|
+
}
|
|
3289
|
+
stack.length = 0;
|
|
3290
|
+
};
|
|
3291
|
+
while (true) {
|
|
3292
|
+
if (stackHead.constructor !== Skip) {
|
|
3293
|
+
const localClock = setIfUndefined(state, stackHead.id.client, () => getState(store, stackHead.id.client));
|
|
3294
|
+
const offset = localClock - stackHead.id.clock;
|
|
3295
|
+
if (offset < 0) {
|
|
3296
|
+
stack.push(stackHead);
|
|
3297
|
+
updateMissingSv(stackHead.id.client, stackHead.id.clock - 1);
|
|
3298
|
+
addStackToRestSS();
|
|
3299
|
+
} else {
|
|
3300
|
+
const missing = stackHead.getMissing(transaction, store);
|
|
3301
|
+
if (missing !== null) {
|
|
3302
|
+
stack.push(stackHead);
|
|
3303
|
+
const structRefs = clientsStructRefs.get(
|
|
3304
|
+
/** @type {number} */
|
|
3305
|
+
missing
|
|
3306
|
+
) || { refs: [], i: 0 };
|
|
3307
|
+
if (structRefs.refs.length === structRefs.i) {
|
|
3308
|
+
updateMissingSv(
|
|
3309
|
+
/** @type {number} */
|
|
3310
|
+
missing,
|
|
3311
|
+
getState(store, missing)
|
|
3312
|
+
);
|
|
3313
|
+
addStackToRestSS();
|
|
3314
|
+
} else {
|
|
3315
|
+
stackHead = structRefs.refs[structRefs.i++];
|
|
3316
|
+
continue;
|
|
3317
|
+
}
|
|
3318
|
+
} else if (offset === 0 || offset < stackHead.length) {
|
|
3319
|
+
stackHead.integrate(transaction, offset);
|
|
3320
|
+
state.set(stackHead.id.client, stackHead.id.clock + stackHead.length);
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
if (stack.length > 0) {
|
|
3325
|
+
stackHead = /** @type {GC|Item} */
|
|
3326
|
+
stack.pop();
|
|
3327
|
+
} else if (curStructsTarget !== null && curStructsTarget.i < curStructsTarget.refs.length) {
|
|
3328
|
+
stackHead = /** @type {GC|Item} */
|
|
3329
|
+
curStructsTarget.refs[curStructsTarget.i++];
|
|
3330
|
+
} else {
|
|
3331
|
+
curStructsTarget = getNextStructTarget();
|
|
3332
|
+
if (curStructsTarget === null) {
|
|
3333
|
+
break;
|
|
3334
|
+
} else {
|
|
3335
|
+
stackHead = /** @type {GC|Item} */
|
|
3336
|
+
curStructsTarget.refs[curStructsTarget.i++];
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
if (restStructs.clients.size > 0) {
|
|
3341
|
+
const encoder = new UpdateEncoderV2();
|
|
3342
|
+
writeClientsStructs(encoder, restStructs, /* @__PURE__ */ new Map());
|
|
3343
|
+
writeVarUint(encoder.restEncoder, 0);
|
|
3344
|
+
return { missing: missingSV, update: encoder.toUint8Array() };
|
|
3345
|
+
}
|
|
3346
|
+
return null;
|
|
3347
|
+
};
|
|
2503
3348
|
var writeStructsFromTransaction = (encoder, transaction) => writeClientsStructs(encoder, transaction.doc.store, transaction.beforeState);
|
|
3349
|
+
var readUpdateV2 = (decoder, ydoc, transactionOrigin, structDecoder = new UpdateDecoderV2(decoder)) => transact(ydoc, (transaction) => {
|
|
3350
|
+
transaction.local = false;
|
|
3351
|
+
let retry = false;
|
|
3352
|
+
const doc2 = transaction.doc;
|
|
3353
|
+
const store = doc2.store;
|
|
3354
|
+
const ss = readClientsStructRefs(structDecoder, doc2);
|
|
3355
|
+
const restStructs = integrateStructs(transaction, store, ss);
|
|
3356
|
+
const pending = store.pendingStructs;
|
|
3357
|
+
if (pending) {
|
|
3358
|
+
for (const [client, clock] of pending.missing) {
|
|
3359
|
+
if (clock < getState(store, client)) {
|
|
3360
|
+
retry = true;
|
|
3361
|
+
break;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
if (restStructs) {
|
|
3365
|
+
for (const [client, clock] of restStructs.missing) {
|
|
3366
|
+
const mclock = pending.missing.get(client);
|
|
3367
|
+
if (mclock == null || mclock > clock) {
|
|
3368
|
+
pending.missing.set(client, clock);
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
pending.update = mergeUpdatesV2([pending.update, restStructs.update]);
|
|
3372
|
+
}
|
|
3373
|
+
} else {
|
|
3374
|
+
store.pendingStructs = restStructs;
|
|
3375
|
+
}
|
|
3376
|
+
const dsRest = readAndApplyDeleteSet(structDecoder, transaction, store);
|
|
3377
|
+
if (store.pendingDs) {
|
|
3378
|
+
const pendingDSUpdate = new UpdateDecoderV2(createDecoder(store.pendingDs));
|
|
3379
|
+
readVarUint(pendingDSUpdate.restDecoder);
|
|
3380
|
+
const dsRest2 = readAndApplyDeleteSet(pendingDSUpdate, transaction, store);
|
|
3381
|
+
if (dsRest && dsRest2) {
|
|
3382
|
+
store.pendingDs = mergeUpdatesV2([dsRest, dsRest2]);
|
|
3383
|
+
} else {
|
|
3384
|
+
store.pendingDs = dsRest || dsRest2;
|
|
3385
|
+
}
|
|
3386
|
+
} else {
|
|
3387
|
+
store.pendingDs = dsRest;
|
|
3388
|
+
}
|
|
3389
|
+
if (retry) {
|
|
3390
|
+
const update = (
|
|
3391
|
+
/** @type {{update: Uint8Array}} */
|
|
3392
|
+
store.pendingStructs.update
|
|
3393
|
+
);
|
|
3394
|
+
store.pendingStructs = null;
|
|
3395
|
+
applyUpdateV2(transaction.doc, update);
|
|
3396
|
+
}
|
|
3397
|
+
}, transactionOrigin, false);
|
|
3398
|
+
var readUpdate = (decoder, ydoc, transactionOrigin) => readUpdateV2(decoder, ydoc, transactionOrigin, new UpdateDecoderV1(decoder));
|
|
3399
|
+
var applyUpdateV2 = (ydoc, update, transactionOrigin, YDecoder = UpdateDecoderV2) => {
|
|
3400
|
+
const decoder = createDecoder(update);
|
|
3401
|
+
readUpdateV2(decoder, ydoc, transactionOrigin, new YDecoder(decoder));
|
|
3402
|
+
};
|
|
3403
|
+
var applyUpdate = (ydoc, update, transactionOrigin) => applyUpdateV2(ydoc, update, transactionOrigin, UpdateDecoderV1);
|
|
3404
|
+
var writeStateAsUpdate = (encoder, doc2, targetStateVector = /* @__PURE__ */ new Map()) => {
|
|
3405
|
+
writeClientsStructs(encoder, doc2.store, targetStateVector);
|
|
3406
|
+
writeDeleteSet(encoder, createDeleteSetFromStructStore(doc2.store));
|
|
3407
|
+
};
|
|
3408
|
+
var encodeStateAsUpdateV2 = (doc2, encodedTargetStateVector = new Uint8Array([0]), encoder = new UpdateEncoderV2()) => {
|
|
3409
|
+
const targetStateVector = decodeStateVector(encodedTargetStateVector);
|
|
3410
|
+
writeStateAsUpdate(encoder, doc2, targetStateVector);
|
|
3411
|
+
const updates = [encoder.toUint8Array()];
|
|
3412
|
+
if (doc2.store.pendingDs) {
|
|
3413
|
+
updates.push(doc2.store.pendingDs);
|
|
3414
|
+
}
|
|
3415
|
+
if (doc2.store.pendingStructs) {
|
|
3416
|
+
updates.push(diffUpdateV2(doc2.store.pendingStructs.update, encodedTargetStateVector));
|
|
3417
|
+
}
|
|
3418
|
+
if (updates.length > 1) {
|
|
3419
|
+
if (encoder.constructor === UpdateEncoderV1) {
|
|
3420
|
+
return mergeUpdates(updates.map((update, i) => i === 0 ? update : convertUpdateFormatV2ToV1(update)));
|
|
3421
|
+
} else if (encoder.constructor === UpdateEncoderV2) {
|
|
3422
|
+
return mergeUpdatesV2(updates);
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
return updates[0];
|
|
3426
|
+
};
|
|
3427
|
+
var encodeStateAsUpdate = (doc2, encodedTargetStateVector) => encodeStateAsUpdateV2(doc2, encodedTargetStateVector, new UpdateEncoderV1());
|
|
3428
|
+
var readStateVector = (decoder) => {
|
|
3429
|
+
const ss = /* @__PURE__ */ new Map();
|
|
3430
|
+
const ssLength = readVarUint(decoder.restDecoder);
|
|
3431
|
+
for (let i = 0; i < ssLength; i++) {
|
|
3432
|
+
const client = readVarUint(decoder.restDecoder);
|
|
3433
|
+
const clock = readVarUint(decoder.restDecoder);
|
|
3434
|
+
ss.set(client, clock);
|
|
3435
|
+
}
|
|
3436
|
+
return ss;
|
|
3437
|
+
};
|
|
3438
|
+
var decodeStateVector = (decodedState) => readStateVector(new DSDecoderV1(createDecoder(decodedState)));
|
|
3439
|
+
var writeStateVector = (encoder, sv) => {
|
|
3440
|
+
writeVarUint(encoder.restEncoder, sv.size);
|
|
3441
|
+
from(sv.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {
|
|
3442
|
+
writeVarUint(encoder.restEncoder, client);
|
|
3443
|
+
writeVarUint(encoder.restEncoder, clock);
|
|
3444
|
+
});
|
|
3445
|
+
return encoder;
|
|
3446
|
+
};
|
|
3447
|
+
var writeDocumentStateVector = (encoder, doc2) => writeStateVector(encoder, getStateVector(doc2.store));
|
|
3448
|
+
var encodeStateVectorV2 = (doc2, encoder = new DSEncoderV2()) => {
|
|
3449
|
+
if (doc2 instanceof Map) {
|
|
3450
|
+
writeStateVector(encoder, doc2);
|
|
3451
|
+
} else {
|
|
3452
|
+
writeDocumentStateVector(encoder, doc2);
|
|
3453
|
+
}
|
|
3454
|
+
return encoder.toUint8Array();
|
|
3455
|
+
};
|
|
3456
|
+
var encodeStateVector = (doc2) => encodeStateVectorV2(doc2, new DSEncoderV1());
|
|
2504
3457
|
var EventHandler = class {
|
|
2505
3458
|
constructor() {
|
|
2506
3459
|
this.l = [];
|
|
@@ -2552,6 +3505,132 @@ ${err.toString()}`);
|
|
|
2552
3505
|
}
|
|
2553
3506
|
return false;
|
|
2554
3507
|
};
|
|
3508
|
+
var logType = (type) => {
|
|
3509
|
+
const res = [];
|
|
3510
|
+
let n = type._start;
|
|
3511
|
+
while (n) {
|
|
3512
|
+
res.push(n);
|
|
3513
|
+
n = n.right;
|
|
3514
|
+
}
|
|
3515
|
+
console.log("Children: ", res);
|
|
3516
|
+
console.log("Children content: ", res.filter((m) => !m.deleted).map((m) => m.content));
|
|
3517
|
+
};
|
|
3518
|
+
var PermanentUserData = class {
|
|
3519
|
+
/**
|
|
3520
|
+
* @param {Doc} doc
|
|
3521
|
+
* @param {YMap<any>} [storeType]
|
|
3522
|
+
*/
|
|
3523
|
+
constructor(doc2, storeType = doc2.getMap("users")) {
|
|
3524
|
+
const dss = /* @__PURE__ */ new Map();
|
|
3525
|
+
this.yusers = storeType;
|
|
3526
|
+
this.doc = doc2;
|
|
3527
|
+
this.clients = /* @__PURE__ */ new Map();
|
|
3528
|
+
this.dss = dss;
|
|
3529
|
+
const initUser = (user, userDescription) => {
|
|
3530
|
+
const ds = user.get("ds");
|
|
3531
|
+
const ids = user.get("ids");
|
|
3532
|
+
const addClientId = (
|
|
3533
|
+
/** @param {number} clientid */
|
|
3534
|
+
(clientid) => this.clients.set(clientid, userDescription)
|
|
3535
|
+
);
|
|
3536
|
+
ds.observe(
|
|
3537
|
+
/** @param {YArrayEvent<any>} event */
|
|
3538
|
+
(event) => {
|
|
3539
|
+
event.changes.added.forEach((item) => {
|
|
3540
|
+
item.content.getContent().forEach((encodedDs) => {
|
|
3541
|
+
if (encodedDs instanceof Uint8Array) {
|
|
3542
|
+
this.dss.set(userDescription, mergeDeleteSets([this.dss.get(userDescription) || createDeleteSet(), readDeleteSet(new DSDecoderV1(createDecoder(encodedDs)))]));
|
|
3543
|
+
}
|
|
3544
|
+
});
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
);
|
|
3548
|
+
this.dss.set(userDescription, mergeDeleteSets(ds.map((encodedDs) => readDeleteSet(new DSDecoderV1(createDecoder(encodedDs))))));
|
|
3549
|
+
ids.observe(
|
|
3550
|
+
/** @param {YArrayEvent<any>} event */
|
|
3551
|
+
(event) => event.changes.added.forEach((item) => item.content.getContent().forEach(addClientId))
|
|
3552
|
+
);
|
|
3553
|
+
ids.forEach(addClientId);
|
|
3554
|
+
};
|
|
3555
|
+
storeType.observe((event) => {
|
|
3556
|
+
event.keysChanged.forEach(
|
|
3557
|
+
(userDescription) => initUser(storeType.get(userDescription), userDescription)
|
|
3558
|
+
);
|
|
3559
|
+
});
|
|
3560
|
+
storeType.forEach(initUser);
|
|
3561
|
+
}
|
|
3562
|
+
/**
|
|
3563
|
+
* @param {Doc} doc
|
|
3564
|
+
* @param {number} clientid
|
|
3565
|
+
* @param {string} userDescription
|
|
3566
|
+
* @param {Object} conf
|
|
3567
|
+
* @param {function(Transaction, DeleteSet):boolean} [conf.filter]
|
|
3568
|
+
*/
|
|
3569
|
+
setUserMapping(doc2, clientid, userDescription, { filter = () => true } = {}) {
|
|
3570
|
+
const users = this.yusers;
|
|
3571
|
+
let user = users.get(userDescription);
|
|
3572
|
+
if (!user) {
|
|
3573
|
+
user = new YMap();
|
|
3574
|
+
user.set("ids", new YArray());
|
|
3575
|
+
user.set("ds", new YArray());
|
|
3576
|
+
users.set(userDescription, user);
|
|
3577
|
+
}
|
|
3578
|
+
user.get("ids").push([clientid]);
|
|
3579
|
+
users.observe((_event) => {
|
|
3580
|
+
setTimeout(() => {
|
|
3581
|
+
const userOverwrite = users.get(userDescription);
|
|
3582
|
+
if (userOverwrite !== user) {
|
|
3583
|
+
user = userOverwrite;
|
|
3584
|
+
this.clients.forEach((_userDescription, clientid2) => {
|
|
3585
|
+
if (userDescription === _userDescription) {
|
|
3586
|
+
user.get("ids").push([clientid2]);
|
|
3587
|
+
}
|
|
3588
|
+
});
|
|
3589
|
+
const encoder = new DSEncoderV1();
|
|
3590
|
+
const ds = this.dss.get(userDescription);
|
|
3591
|
+
if (ds) {
|
|
3592
|
+
writeDeleteSet(encoder, ds);
|
|
3593
|
+
user.get("ds").push([encoder.toUint8Array()]);
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
}, 0);
|
|
3597
|
+
});
|
|
3598
|
+
doc2.on(
|
|
3599
|
+
"afterTransaction",
|
|
3600
|
+
/** @param {Transaction} transaction */
|
|
3601
|
+
(transaction) => {
|
|
3602
|
+
setTimeout(() => {
|
|
3603
|
+
const yds = user.get("ds");
|
|
3604
|
+
const ds = transaction.deleteSet;
|
|
3605
|
+
if (transaction.local && ds.clients.size > 0 && filter(transaction, ds)) {
|
|
3606
|
+
const encoder = new DSEncoderV1();
|
|
3607
|
+
writeDeleteSet(encoder, ds);
|
|
3608
|
+
yds.push([encoder.toUint8Array()]);
|
|
3609
|
+
}
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
);
|
|
3613
|
+
}
|
|
3614
|
+
/**
|
|
3615
|
+
* @param {number} clientid
|
|
3616
|
+
* @return {any}
|
|
3617
|
+
*/
|
|
3618
|
+
getUserByClientId(clientid) {
|
|
3619
|
+
return this.clients.get(clientid) || null;
|
|
3620
|
+
}
|
|
3621
|
+
/**
|
|
3622
|
+
* @param {ID} id
|
|
3623
|
+
* @return {string | null}
|
|
3624
|
+
*/
|
|
3625
|
+
getUserByDeletedId(id2) {
|
|
3626
|
+
for (const [userDescription, ds] of this.dss.entries()) {
|
|
3627
|
+
if (isDeleted(ds, id2)) {
|
|
3628
|
+
return userDescription;
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
return null;
|
|
3632
|
+
}
|
|
3633
|
+
};
|
|
2555
3634
|
var RelativePosition = class {
|
|
2556
3635
|
/**
|
|
2557
3636
|
* @param {ID|null} type
|
|
@@ -2566,6 +3645,26 @@ ${err.toString()}`);
|
|
|
2566
3645
|
this.assoc = assoc;
|
|
2567
3646
|
}
|
|
2568
3647
|
};
|
|
3648
|
+
var relativePositionToJSON = (rpos) => {
|
|
3649
|
+
const json = {};
|
|
3650
|
+
if (rpos.type) {
|
|
3651
|
+
json.type = rpos.type;
|
|
3652
|
+
}
|
|
3653
|
+
if (rpos.tname) {
|
|
3654
|
+
json.tname = rpos.tname;
|
|
3655
|
+
}
|
|
3656
|
+
if (rpos.item) {
|
|
3657
|
+
json.item = rpos.item;
|
|
3658
|
+
}
|
|
3659
|
+
if (rpos.assoc != null) {
|
|
3660
|
+
json.assoc = rpos.assoc;
|
|
3661
|
+
}
|
|
3662
|
+
return json;
|
|
3663
|
+
};
|
|
3664
|
+
var createRelativePositionFromJSON = (json) => {
|
|
3665
|
+
var _a;
|
|
3666
|
+
return new RelativePosition(json.type == null ? null : createID(json.type.client, json.type.clock), (_a = json.tname) != null ? _a : null, json.item == null ? null : createID(json.item.client, json.item.clock), json.assoc == null ? 0 : json.assoc);
|
|
3667
|
+
};
|
|
2569
3668
|
var AbsolutePosition = class {
|
|
2570
3669
|
/**
|
|
2571
3670
|
* @param {AbstractType<any>} type
|
|
@@ -2711,35 +3810,122 @@ ${err.toString()}`);
|
|
|
2711
3810
|
index = 0;
|
|
2712
3811
|
}
|
|
2713
3812
|
}
|
|
2714
|
-
return createAbsolutePosition(type, index, rpos.assoc);
|
|
3813
|
+
return createAbsolutePosition(type, index, rpos.assoc);
|
|
3814
|
+
};
|
|
3815
|
+
var 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;
|
|
3816
|
+
var Snapshot = class {
|
|
3817
|
+
/**
|
|
3818
|
+
* @param {DeleteSet} ds
|
|
3819
|
+
* @param {Map<number,number>} sv state map
|
|
3820
|
+
*/
|
|
3821
|
+
constructor(ds, sv) {
|
|
3822
|
+
this.ds = ds;
|
|
3823
|
+
this.sv = sv;
|
|
3824
|
+
}
|
|
3825
|
+
};
|
|
3826
|
+
var equalSnapshots = (snap1, snap2) => {
|
|
3827
|
+
const ds1 = snap1.ds.clients;
|
|
3828
|
+
const ds2 = snap2.ds.clients;
|
|
3829
|
+
const sv1 = snap1.sv;
|
|
3830
|
+
const sv2 = snap2.sv;
|
|
3831
|
+
if (sv1.size !== sv2.size || ds1.size !== ds2.size) {
|
|
3832
|
+
return false;
|
|
3833
|
+
}
|
|
3834
|
+
for (const [key, value] of sv1.entries()) {
|
|
3835
|
+
if (sv2.get(key) !== value) {
|
|
3836
|
+
return false;
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
for (const [client, dsitems1] of ds1.entries()) {
|
|
3840
|
+
const dsitems2 = ds2.get(client) || [];
|
|
3841
|
+
if (dsitems1.length !== dsitems2.length) {
|
|
3842
|
+
return false;
|
|
3843
|
+
}
|
|
3844
|
+
for (let i = 0; i < dsitems1.length; i++) {
|
|
3845
|
+
const dsitem1 = dsitems1[i];
|
|
3846
|
+
const dsitem2 = dsitems2[i];
|
|
3847
|
+
if (dsitem1.clock !== dsitem2.clock || dsitem1.len !== dsitem2.len) {
|
|
3848
|
+
return false;
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
return true;
|
|
2715
3853
|
};
|
|
2716
|
-
var
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
}
|
|
3854
|
+
var encodeSnapshotV2 = (snapshot2, encoder = new DSEncoderV2()) => {
|
|
3855
|
+
writeDeleteSet(encoder, snapshot2.ds);
|
|
3856
|
+
writeStateVector(encoder, snapshot2.sv);
|
|
3857
|
+
return encoder.toUint8Array();
|
|
3858
|
+
};
|
|
3859
|
+
var encodeSnapshot = (snapshot2) => encodeSnapshotV2(snapshot2, new DSEncoderV1());
|
|
3860
|
+
var decodeSnapshotV2 = (buf, decoder = new DSDecoderV2(createDecoder(buf))) => {
|
|
3861
|
+
return new Snapshot(readDeleteSet(decoder), readStateVector(decoder));
|
|
2725
3862
|
};
|
|
3863
|
+
var decodeSnapshot = (buf) => decodeSnapshotV2(buf, new DSDecoderV1(createDecoder(buf)));
|
|
2726
3864
|
var createSnapshot = (ds, sm) => new Snapshot(ds, sm);
|
|
2727
3865
|
var emptySnapshot = createSnapshot(createDeleteSet(), /* @__PURE__ */ new Map());
|
|
2728
|
-
var
|
|
2729
|
-
var
|
|
3866
|
+
var snapshot = (doc2) => createSnapshot(createDeleteSetFromStructStore(doc2.store), getStateVector(doc2.store));
|
|
3867
|
+
var isVisible = (item, snapshot2) => snapshot2 === void 0 ? !item.deleted : snapshot2.sv.has(item.id.client) && (snapshot2.sv.get(item.id.client) || 0) > item.id.clock && !isDeleted(snapshot2.ds, item.id);
|
|
3868
|
+
var splitSnapshotAffectedStructs = (transaction, snapshot2) => {
|
|
2730
3869
|
const meta = setIfUndefined(transaction.meta, splitSnapshotAffectedStructs, create2);
|
|
2731
3870
|
const store = transaction.doc.store;
|
|
2732
|
-
if (!meta.has(
|
|
2733
|
-
|
|
3871
|
+
if (!meta.has(snapshot2)) {
|
|
3872
|
+
snapshot2.sv.forEach((clock, client) => {
|
|
2734
3873
|
if (clock < getState(store, client)) {
|
|
2735
3874
|
getItemCleanStart(transaction, createID(client, clock));
|
|
2736
3875
|
}
|
|
2737
3876
|
});
|
|
2738
|
-
iterateDeletedStructs(transaction,
|
|
3877
|
+
iterateDeletedStructs(transaction, snapshot2.ds, (_item) => {
|
|
3878
|
+
});
|
|
3879
|
+
meta.add(snapshot2);
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3882
|
+
var createDocFromSnapshot = (originDoc, snapshot2, newDoc = new Doc()) => {
|
|
3883
|
+
if (originDoc.gc) {
|
|
3884
|
+
throw new Error("Garbage-collection must be disabled in `originDoc`!");
|
|
3885
|
+
}
|
|
3886
|
+
const { sv, ds } = snapshot2;
|
|
3887
|
+
const encoder = new UpdateEncoderV2();
|
|
3888
|
+
originDoc.transact((transaction) => {
|
|
3889
|
+
let size2 = 0;
|
|
3890
|
+
sv.forEach((clock) => {
|
|
3891
|
+
if (clock > 0) {
|
|
3892
|
+
size2++;
|
|
3893
|
+
}
|
|
2739
3894
|
});
|
|
2740
|
-
|
|
3895
|
+
writeVarUint(encoder.restEncoder, size2);
|
|
3896
|
+
for (const [client, clock] of sv) {
|
|
3897
|
+
if (clock === 0) {
|
|
3898
|
+
continue;
|
|
3899
|
+
}
|
|
3900
|
+
if (clock < getState(originDoc.store, client)) {
|
|
3901
|
+
getItemCleanStart(transaction, createID(client, clock));
|
|
3902
|
+
}
|
|
3903
|
+
const structs = originDoc.store.clients.get(client) || [];
|
|
3904
|
+
const lastStructIndex = findIndexSS(structs, clock - 1);
|
|
3905
|
+
writeVarUint(encoder.restEncoder, lastStructIndex + 1);
|
|
3906
|
+
encoder.writeClient(client);
|
|
3907
|
+
writeVarUint(encoder.restEncoder, 0);
|
|
3908
|
+
for (let i = 0; i <= lastStructIndex; i++) {
|
|
3909
|
+
structs[i].write(encoder, 0);
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
writeDeleteSet(encoder, ds);
|
|
3913
|
+
});
|
|
3914
|
+
applyUpdateV2(newDoc, encoder.toUint8Array(), "snapshot");
|
|
3915
|
+
return newDoc;
|
|
3916
|
+
};
|
|
3917
|
+
var snapshotContainsUpdateV2 = (snapshot2, update, YDecoder = UpdateDecoderV2) => {
|
|
3918
|
+
const updateDecoder = new YDecoder(createDecoder(update));
|
|
3919
|
+
const lazyDecoder = new LazyStructReader(updateDecoder, false);
|
|
3920
|
+
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
|
|
3921
|
+
if ((snapshot2.sv.get(curr.id.client) || 0) < curr.id.clock + curr.length) {
|
|
3922
|
+
return false;
|
|
3923
|
+
}
|
|
2741
3924
|
}
|
|
3925
|
+
const mergedDS = mergeDeleteSets([snapshot2.ds, readDeleteSet(updateDecoder)]);
|
|
3926
|
+
return equalDeleteSets(snapshot2.ds, mergedDS);
|
|
2742
3927
|
};
|
|
3928
|
+
var snapshotContainsUpdate = (snapshot2, update) => snapshotContainsUpdateV2(snapshot2, update, UpdateDecoderV1);
|
|
2743
3929
|
var StructStore = class {
|
|
2744
3930
|
constructor() {
|
|
2745
3931
|
this.clients = /* @__PURE__ */ new Map();
|
|
@@ -2955,6 +4141,10 @@ ${err.toString()}`);
|
|
|
2955
4141
|
}
|
|
2956
4142
|
});
|
|
2957
4143
|
};
|
|
4144
|
+
var tryGc = (ds, store, gcFilter) => {
|
|
4145
|
+
tryGcDeleteSet(ds, store, gcFilter);
|
|
4146
|
+
tryMergeDeleteSet(ds, store);
|
|
4147
|
+
};
|
|
2958
4148
|
var cleanupTransactions = (transactionCleanups, i) => {
|
|
2959
4149
|
if (i < transactionCleanups.length) {
|
|
2960
4150
|
const transaction = transactionCleanups[i];
|
|
@@ -3403,6 +4593,493 @@ ${err.toString()}`);
|
|
|
3403
4593
|
super.destroy();
|
|
3404
4594
|
}
|
|
3405
4595
|
};
|
|
4596
|
+
function* lazyStructReaderGenerator(decoder) {
|
|
4597
|
+
const numOfStateUpdates = readVarUint(decoder.restDecoder);
|
|
4598
|
+
for (let i = 0; i < numOfStateUpdates; i++) {
|
|
4599
|
+
const numberOfStructs = readVarUint(decoder.restDecoder);
|
|
4600
|
+
const client = decoder.readClient();
|
|
4601
|
+
let clock = readVarUint(decoder.restDecoder);
|
|
4602
|
+
for (let i2 = 0; i2 < numberOfStructs; i2++) {
|
|
4603
|
+
const info = decoder.readInfo();
|
|
4604
|
+
if (info === 10) {
|
|
4605
|
+
const len = readVarUint(decoder.restDecoder);
|
|
4606
|
+
yield new Skip(createID(client, clock), len);
|
|
4607
|
+
clock += len;
|
|
4608
|
+
} else if ((BITS5 & info) !== 0) {
|
|
4609
|
+
const cantCopyParentInfo = (info & (BIT7 | BIT8)) === 0;
|
|
4610
|
+
const struct = new Item(
|
|
4611
|
+
createID(client, clock),
|
|
4612
|
+
null,
|
|
4613
|
+
// left
|
|
4614
|
+
(info & BIT8) === BIT8 ? decoder.readLeftID() : null,
|
|
4615
|
+
// origin
|
|
4616
|
+
null,
|
|
4617
|
+
// right
|
|
4618
|
+
(info & BIT7) === BIT7 ? decoder.readRightID() : null,
|
|
4619
|
+
// right origin
|
|
4620
|
+
// @ts-ignore Force writing a string here.
|
|
4621
|
+
cantCopyParentInfo ? decoder.readParentInfo() ? decoder.readString() : decoder.readLeftID() : null,
|
|
4622
|
+
// parent
|
|
4623
|
+
cantCopyParentInfo && (info & BIT6) === BIT6 ? decoder.readString() : null,
|
|
4624
|
+
// parentSub
|
|
4625
|
+
readItemContent(decoder, info)
|
|
4626
|
+
// item content
|
|
4627
|
+
);
|
|
4628
|
+
yield struct;
|
|
4629
|
+
clock += struct.length;
|
|
4630
|
+
} else {
|
|
4631
|
+
const len = decoder.readLen();
|
|
4632
|
+
yield new GC(createID(client, clock), len);
|
|
4633
|
+
clock += len;
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
var LazyStructReader = class {
|
|
4639
|
+
/**
|
|
4640
|
+
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
|
4641
|
+
* @param {boolean} filterSkips
|
|
4642
|
+
*/
|
|
4643
|
+
constructor(decoder, filterSkips) {
|
|
4644
|
+
this.gen = lazyStructReaderGenerator(decoder);
|
|
4645
|
+
this.curr = null;
|
|
4646
|
+
this.done = false;
|
|
4647
|
+
this.filterSkips = filterSkips;
|
|
4648
|
+
this.next();
|
|
4649
|
+
}
|
|
4650
|
+
/**
|
|
4651
|
+
* @return {Item | GC | Skip |null}
|
|
4652
|
+
*/
|
|
4653
|
+
next() {
|
|
4654
|
+
do {
|
|
4655
|
+
this.curr = this.gen.next().value || null;
|
|
4656
|
+
} while (this.filterSkips && this.curr !== null && this.curr.constructor === Skip);
|
|
4657
|
+
return this.curr;
|
|
4658
|
+
}
|
|
4659
|
+
};
|
|
4660
|
+
var logUpdate = (update) => logUpdateV2(update, UpdateDecoderV1);
|
|
4661
|
+
var logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {
|
|
4662
|
+
const structs = [];
|
|
4663
|
+
const updateDecoder = new YDecoder(createDecoder(update));
|
|
4664
|
+
const lazyDecoder = new LazyStructReader(updateDecoder, false);
|
|
4665
|
+
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
|
|
4666
|
+
structs.push(curr);
|
|
4667
|
+
}
|
|
4668
|
+
print("Structs: ", structs);
|
|
4669
|
+
const ds = readDeleteSet(updateDecoder);
|
|
4670
|
+
print("DeleteSet: ", ds);
|
|
4671
|
+
};
|
|
4672
|
+
var decodeUpdate = (update) => decodeUpdateV2(update, UpdateDecoderV1);
|
|
4673
|
+
var decodeUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {
|
|
4674
|
+
const structs = [];
|
|
4675
|
+
const updateDecoder = new YDecoder(createDecoder(update));
|
|
4676
|
+
const lazyDecoder = new LazyStructReader(updateDecoder, false);
|
|
4677
|
+
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
|
|
4678
|
+
structs.push(curr);
|
|
4679
|
+
}
|
|
4680
|
+
return {
|
|
4681
|
+
structs,
|
|
4682
|
+
ds: readDeleteSet(updateDecoder)
|
|
4683
|
+
};
|
|
4684
|
+
};
|
|
4685
|
+
var LazyStructWriter = class {
|
|
4686
|
+
/**
|
|
4687
|
+
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
4688
|
+
*/
|
|
4689
|
+
constructor(encoder) {
|
|
4690
|
+
this.currClient = 0;
|
|
4691
|
+
this.startClock = 0;
|
|
4692
|
+
this.written = 0;
|
|
4693
|
+
this.encoder = encoder;
|
|
4694
|
+
this.clientStructs = [];
|
|
4695
|
+
}
|
|
4696
|
+
};
|
|
4697
|
+
var mergeUpdates = (updates) => mergeUpdatesV2(updates, UpdateDecoderV1, UpdateEncoderV1);
|
|
4698
|
+
var encodeStateVectorFromUpdateV2 = (update, YEncoder = DSEncoderV2, YDecoder = UpdateDecoderV2) => {
|
|
4699
|
+
const encoder = new YEncoder();
|
|
4700
|
+
const updateDecoder = new LazyStructReader(new YDecoder(createDecoder(update)), false);
|
|
4701
|
+
let curr = updateDecoder.curr;
|
|
4702
|
+
if (curr !== null) {
|
|
4703
|
+
let size2 = 0;
|
|
4704
|
+
let currClient = curr.id.client;
|
|
4705
|
+
let stopCounting = curr.id.clock !== 0;
|
|
4706
|
+
let currClock = stopCounting ? 0 : curr.id.clock + curr.length;
|
|
4707
|
+
for (; curr !== null; curr = updateDecoder.next()) {
|
|
4708
|
+
if (currClient !== curr.id.client) {
|
|
4709
|
+
if (currClock !== 0) {
|
|
4710
|
+
size2++;
|
|
4711
|
+
writeVarUint(encoder.restEncoder, currClient);
|
|
4712
|
+
writeVarUint(encoder.restEncoder, currClock);
|
|
4713
|
+
}
|
|
4714
|
+
currClient = curr.id.client;
|
|
4715
|
+
currClock = 0;
|
|
4716
|
+
stopCounting = curr.id.clock !== 0;
|
|
4717
|
+
}
|
|
4718
|
+
if (curr.constructor === Skip) {
|
|
4719
|
+
stopCounting = true;
|
|
4720
|
+
}
|
|
4721
|
+
if (!stopCounting) {
|
|
4722
|
+
currClock = curr.id.clock + curr.length;
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
|
+
if (currClock !== 0) {
|
|
4726
|
+
size2++;
|
|
4727
|
+
writeVarUint(encoder.restEncoder, currClient);
|
|
4728
|
+
writeVarUint(encoder.restEncoder, currClock);
|
|
4729
|
+
}
|
|
4730
|
+
const enc = createEncoder();
|
|
4731
|
+
writeVarUint(enc, size2);
|
|
4732
|
+
writeBinaryEncoder(enc, encoder.restEncoder);
|
|
4733
|
+
encoder.restEncoder = enc;
|
|
4734
|
+
return encoder.toUint8Array();
|
|
4735
|
+
} else {
|
|
4736
|
+
writeVarUint(encoder.restEncoder, 0);
|
|
4737
|
+
return encoder.toUint8Array();
|
|
4738
|
+
}
|
|
4739
|
+
};
|
|
4740
|
+
var encodeStateVectorFromUpdate = (update) => encodeStateVectorFromUpdateV2(update, DSEncoderV1, UpdateDecoderV1);
|
|
4741
|
+
var parseUpdateMetaV2 = (update, YDecoder = UpdateDecoderV2) => {
|
|
4742
|
+
const from2 = /* @__PURE__ */ new Map();
|
|
4743
|
+
const to = /* @__PURE__ */ new Map();
|
|
4744
|
+
const updateDecoder = new LazyStructReader(new YDecoder(createDecoder(update)), false);
|
|
4745
|
+
let curr = updateDecoder.curr;
|
|
4746
|
+
if (curr !== null) {
|
|
4747
|
+
let currClient = curr.id.client;
|
|
4748
|
+
let currClock = curr.id.clock;
|
|
4749
|
+
from2.set(currClient, currClock);
|
|
4750
|
+
for (; curr !== null; curr = updateDecoder.next()) {
|
|
4751
|
+
if (currClient !== curr.id.client) {
|
|
4752
|
+
to.set(currClient, currClock);
|
|
4753
|
+
from2.set(curr.id.client, curr.id.clock);
|
|
4754
|
+
currClient = curr.id.client;
|
|
4755
|
+
}
|
|
4756
|
+
currClock = curr.id.clock + curr.length;
|
|
4757
|
+
}
|
|
4758
|
+
to.set(currClient, currClock);
|
|
4759
|
+
}
|
|
4760
|
+
return { from: from2, to };
|
|
4761
|
+
};
|
|
4762
|
+
var parseUpdateMeta = (update) => parseUpdateMetaV2(update, UpdateDecoderV1);
|
|
4763
|
+
var sliceStruct = (left, diff) => {
|
|
4764
|
+
if (left.constructor === GC) {
|
|
4765
|
+
const { client, clock } = left.id;
|
|
4766
|
+
return new GC(createID(client, clock + diff), left.length - diff);
|
|
4767
|
+
} else if (left.constructor === Skip) {
|
|
4768
|
+
const { client, clock } = left.id;
|
|
4769
|
+
return new Skip(createID(client, clock + diff), left.length - diff);
|
|
4770
|
+
} else {
|
|
4771
|
+
const leftItem = (
|
|
4772
|
+
/** @type {Item} */
|
|
4773
|
+
left
|
|
4774
|
+
);
|
|
4775
|
+
const { client, clock } = leftItem.id;
|
|
4776
|
+
return new Item(
|
|
4777
|
+
createID(client, clock + diff),
|
|
4778
|
+
null,
|
|
4779
|
+
createID(client, clock + diff - 1),
|
|
4780
|
+
null,
|
|
4781
|
+
leftItem.rightOrigin,
|
|
4782
|
+
leftItem.parent,
|
|
4783
|
+
leftItem.parentSub,
|
|
4784
|
+
leftItem.content.splice(diff)
|
|
4785
|
+
);
|
|
4786
|
+
}
|
|
4787
|
+
};
|
|
4788
|
+
var mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => {
|
|
4789
|
+
if (updates.length === 1) {
|
|
4790
|
+
return updates[0];
|
|
4791
|
+
}
|
|
4792
|
+
const updateDecoders = updates.map((update) => new YDecoder(createDecoder(update)));
|
|
4793
|
+
let lazyStructDecoders = updateDecoders.map((decoder) => new LazyStructReader(decoder, true));
|
|
4794
|
+
let currWrite = null;
|
|
4795
|
+
const updateEncoder = new YEncoder();
|
|
4796
|
+
const lazyStructEncoder = new LazyStructWriter(updateEncoder);
|
|
4797
|
+
while (true) {
|
|
4798
|
+
lazyStructDecoders = lazyStructDecoders.filter((dec) => dec.curr !== null);
|
|
4799
|
+
lazyStructDecoders.sort(
|
|
4800
|
+
/** @type {function(any,any):number} */
|
|
4801
|
+
(dec1, dec2) => {
|
|
4802
|
+
if (dec1.curr.id.client === dec2.curr.id.client) {
|
|
4803
|
+
const clockDiff = dec1.curr.id.clock - dec2.curr.id.clock;
|
|
4804
|
+
if (clockDiff === 0) {
|
|
4805
|
+
return dec1.curr.constructor === dec2.curr.constructor ? 0 : dec1.curr.constructor === Skip ? 1 : -1;
|
|
4806
|
+
} else {
|
|
4807
|
+
return clockDiff;
|
|
4808
|
+
}
|
|
4809
|
+
} else {
|
|
4810
|
+
return dec2.curr.id.client - dec1.curr.id.client;
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
);
|
|
4814
|
+
if (lazyStructDecoders.length === 0) {
|
|
4815
|
+
break;
|
|
4816
|
+
}
|
|
4817
|
+
const currDecoder = lazyStructDecoders[0];
|
|
4818
|
+
const firstClient = (
|
|
4819
|
+
/** @type {Item | GC} */
|
|
4820
|
+
currDecoder.curr.id.client
|
|
4821
|
+
);
|
|
4822
|
+
if (currWrite !== null) {
|
|
4823
|
+
let curr = (
|
|
4824
|
+
/** @type {Item | GC | null} */
|
|
4825
|
+
currDecoder.curr
|
|
4826
|
+
);
|
|
4827
|
+
let iterated = false;
|
|
4828
|
+
while (curr !== null && curr.id.clock + curr.length <= currWrite.struct.id.clock + currWrite.struct.length && curr.id.client >= currWrite.struct.id.client) {
|
|
4829
|
+
curr = currDecoder.next();
|
|
4830
|
+
iterated = true;
|
|
4831
|
+
}
|
|
4832
|
+
if (curr === null || // current decoder is empty
|
|
4833
|
+
curr.id.client !== firstClient || // check whether there is another decoder that has has updates from `firstClient`
|
|
4834
|
+
iterated && curr.id.clock > currWrite.struct.id.clock + currWrite.struct.length) {
|
|
4835
|
+
continue;
|
|
4836
|
+
}
|
|
4837
|
+
if (firstClient !== currWrite.struct.id.client) {
|
|
4838
|
+
writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset);
|
|
4839
|
+
currWrite = { struct: curr, offset: 0 };
|
|
4840
|
+
currDecoder.next();
|
|
4841
|
+
} else {
|
|
4842
|
+
if (currWrite.struct.id.clock + currWrite.struct.length < curr.id.clock) {
|
|
4843
|
+
if (currWrite.struct.constructor === Skip) {
|
|
4844
|
+
currWrite.struct.length = curr.id.clock + curr.length - currWrite.struct.id.clock;
|
|
4845
|
+
} else {
|
|
4846
|
+
writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset);
|
|
4847
|
+
const diff = curr.id.clock - currWrite.struct.id.clock - currWrite.struct.length;
|
|
4848
|
+
const struct = new Skip(createID(firstClient, currWrite.struct.id.clock + currWrite.struct.length), diff);
|
|
4849
|
+
currWrite = { struct, offset: 0 };
|
|
4850
|
+
}
|
|
4851
|
+
} else {
|
|
4852
|
+
const diff = currWrite.struct.id.clock + currWrite.struct.length - curr.id.clock;
|
|
4853
|
+
if (diff > 0) {
|
|
4854
|
+
if (currWrite.struct.constructor === Skip) {
|
|
4855
|
+
currWrite.struct.length -= diff;
|
|
4856
|
+
} else {
|
|
4857
|
+
curr = sliceStruct(curr, diff);
|
|
4858
|
+
}
|
|
4859
|
+
}
|
|
4860
|
+
if (!currWrite.struct.mergeWith(
|
|
4861
|
+
/** @type {any} */
|
|
4862
|
+
curr
|
|
4863
|
+
)) {
|
|
4864
|
+
writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset);
|
|
4865
|
+
currWrite = { struct: curr, offset: 0 };
|
|
4866
|
+
currDecoder.next();
|
|
4867
|
+
}
|
|
4868
|
+
}
|
|
4869
|
+
}
|
|
4870
|
+
} else {
|
|
4871
|
+
currWrite = { struct: (
|
|
4872
|
+
/** @type {Item | GC} */
|
|
4873
|
+
currDecoder.curr
|
|
4874
|
+
), offset: 0 };
|
|
4875
|
+
currDecoder.next();
|
|
4876
|
+
}
|
|
4877
|
+
for (let next = currDecoder.curr; next !== null && next.id.client === firstClient && next.id.clock === currWrite.struct.id.clock + currWrite.struct.length && next.constructor !== Skip; next = currDecoder.next()) {
|
|
4878
|
+
writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset);
|
|
4879
|
+
currWrite = { struct: next, offset: 0 };
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
if (currWrite !== null) {
|
|
4883
|
+
writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset);
|
|
4884
|
+
currWrite = null;
|
|
4885
|
+
}
|
|
4886
|
+
finishLazyStructWriting(lazyStructEncoder);
|
|
4887
|
+
const dss = updateDecoders.map((decoder) => readDeleteSet(decoder));
|
|
4888
|
+
const ds = mergeDeleteSets(dss);
|
|
4889
|
+
writeDeleteSet(updateEncoder, ds);
|
|
4890
|
+
return updateEncoder.toUint8Array();
|
|
4891
|
+
};
|
|
4892
|
+
var diffUpdateV2 = (update, sv, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => {
|
|
4893
|
+
const state = decodeStateVector(sv);
|
|
4894
|
+
const encoder = new YEncoder();
|
|
4895
|
+
const lazyStructWriter = new LazyStructWriter(encoder);
|
|
4896
|
+
const decoder = new YDecoder(createDecoder(update));
|
|
4897
|
+
const reader = new LazyStructReader(decoder, false);
|
|
4898
|
+
while (reader.curr) {
|
|
4899
|
+
const curr = reader.curr;
|
|
4900
|
+
const currClient = curr.id.client;
|
|
4901
|
+
const svClock = state.get(currClient) || 0;
|
|
4902
|
+
if (reader.curr.constructor === Skip) {
|
|
4903
|
+
reader.next();
|
|
4904
|
+
continue;
|
|
4905
|
+
}
|
|
4906
|
+
if (curr.id.clock + curr.length > svClock) {
|
|
4907
|
+
writeStructToLazyStructWriter(lazyStructWriter, curr, max(svClock - curr.id.clock, 0));
|
|
4908
|
+
reader.next();
|
|
4909
|
+
while (reader.curr && reader.curr.id.client === currClient) {
|
|
4910
|
+
writeStructToLazyStructWriter(lazyStructWriter, reader.curr, 0);
|
|
4911
|
+
reader.next();
|
|
4912
|
+
}
|
|
4913
|
+
} else {
|
|
4914
|
+
while (reader.curr && reader.curr.id.client === currClient && reader.curr.id.clock + reader.curr.length <= svClock) {
|
|
4915
|
+
reader.next();
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
4919
|
+
finishLazyStructWriting(lazyStructWriter);
|
|
4920
|
+
const ds = readDeleteSet(decoder);
|
|
4921
|
+
writeDeleteSet(encoder, ds);
|
|
4922
|
+
return encoder.toUint8Array();
|
|
4923
|
+
};
|
|
4924
|
+
var diffUpdate = (update, sv) => diffUpdateV2(update, sv, UpdateDecoderV1, UpdateEncoderV1);
|
|
4925
|
+
var flushLazyStructWriter = (lazyWriter) => {
|
|
4926
|
+
if (lazyWriter.written > 0) {
|
|
4927
|
+
lazyWriter.clientStructs.push({ written: lazyWriter.written, restEncoder: toUint8Array(lazyWriter.encoder.restEncoder) });
|
|
4928
|
+
lazyWriter.encoder.restEncoder = createEncoder();
|
|
4929
|
+
lazyWriter.written = 0;
|
|
4930
|
+
}
|
|
4931
|
+
};
|
|
4932
|
+
var writeStructToLazyStructWriter = (lazyWriter, struct, offset) => {
|
|
4933
|
+
if (lazyWriter.written > 0 && lazyWriter.currClient !== struct.id.client) {
|
|
4934
|
+
flushLazyStructWriter(lazyWriter);
|
|
4935
|
+
}
|
|
4936
|
+
if (lazyWriter.written === 0) {
|
|
4937
|
+
lazyWriter.currClient = struct.id.client;
|
|
4938
|
+
lazyWriter.encoder.writeClient(struct.id.client);
|
|
4939
|
+
writeVarUint(lazyWriter.encoder.restEncoder, struct.id.clock + offset);
|
|
4940
|
+
}
|
|
4941
|
+
struct.write(lazyWriter.encoder, offset);
|
|
4942
|
+
lazyWriter.written++;
|
|
4943
|
+
};
|
|
4944
|
+
var finishLazyStructWriting = (lazyWriter) => {
|
|
4945
|
+
flushLazyStructWriter(lazyWriter);
|
|
4946
|
+
const restEncoder = lazyWriter.encoder.restEncoder;
|
|
4947
|
+
writeVarUint(restEncoder, lazyWriter.clientStructs.length);
|
|
4948
|
+
for (let i = 0; i < lazyWriter.clientStructs.length; i++) {
|
|
4949
|
+
const partStructs = lazyWriter.clientStructs[i];
|
|
4950
|
+
writeVarUint(restEncoder, partStructs.written);
|
|
4951
|
+
writeUint8Array(restEncoder, partStructs.restEncoder);
|
|
4952
|
+
}
|
|
4953
|
+
};
|
|
4954
|
+
var convertUpdateFormat = (update, blockTransformer, YDecoder, YEncoder) => {
|
|
4955
|
+
const updateDecoder = new YDecoder(createDecoder(update));
|
|
4956
|
+
const lazyDecoder = new LazyStructReader(updateDecoder, false);
|
|
4957
|
+
const updateEncoder = new YEncoder();
|
|
4958
|
+
const lazyWriter = new LazyStructWriter(updateEncoder);
|
|
4959
|
+
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
|
|
4960
|
+
writeStructToLazyStructWriter(lazyWriter, blockTransformer(curr), 0);
|
|
4961
|
+
}
|
|
4962
|
+
finishLazyStructWriting(lazyWriter);
|
|
4963
|
+
const ds = readDeleteSet(updateDecoder);
|
|
4964
|
+
writeDeleteSet(updateEncoder, ds);
|
|
4965
|
+
return updateEncoder.toUint8Array();
|
|
4966
|
+
};
|
|
4967
|
+
var createObfuscator = ({ formatting = true, subdocs = true, yxml = true } = {}) => {
|
|
4968
|
+
let i = 0;
|
|
4969
|
+
const mapKeyCache = create();
|
|
4970
|
+
const nodeNameCache = create();
|
|
4971
|
+
const formattingKeyCache = create();
|
|
4972
|
+
const formattingValueCache = create();
|
|
4973
|
+
formattingValueCache.set(null, null);
|
|
4974
|
+
return (block) => {
|
|
4975
|
+
switch (block.constructor) {
|
|
4976
|
+
case GC:
|
|
4977
|
+
case Skip:
|
|
4978
|
+
return block;
|
|
4979
|
+
case Item: {
|
|
4980
|
+
const item = (
|
|
4981
|
+
/** @type {Item} */
|
|
4982
|
+
block
|
|
4983
|
+
);
|
|
4984
|
+
const content = item.content;
|
|
4985
|
+
switch (content.constructor) {
|
|
4986
|
+
case ContentDeleted:
|
|
4987
|
+
break;
|
|
4988
|
+
case ContentType: {
|
|
4989
|
+
if (yxml) {
|
|
4990
|
+
const type = (
|
|
4991
|
+
/** @type {ContentType} */
|
|
4992
|
+
content.type
|
|
4993
|
+
);
|
|
4994
|
+
if (type instanceof YXmlElement) {
|
|
4995
|
+
type.nodeName = setIfUndefined(nodeNameCache, type.nodeName, () => "node-" + i);
|
|
4996
|
+
}
|
|
4997
|
+
if (type instanceof YXmlHook) {
|
|
4998
|
+
type.hookName = setIfUndefined(nodeNameCache, type.hookName, () => "hook-" + i);
|
|
4999
|
+
}
|
|
5000
|
+
}
|
|
5001
|
+
break;
|
|
5002
|
+
}
|
|
5003
|
+
case ContentAny: {
|
|
5004
|
+
const c = (
|
|
5005
|
+
/** @type {ContentAny} */
|
|
5006
|
+
content
|
|
5007
|
+
);
|
|
5008
|
+
c.arr = c.arr.map(() => i);
|
|
5009
|
+
break;
|
|
5010
|
+
}
|
|
5011
|
+
case ContentBinary: {
|
|
5012
|
+
const c = (
|
|
5013
|
+
/** @type {ContentBinary} */
|
|
5014
|
+
content
|
|
5015
|
+
);
|
|
5016
|
+
c.content = new Uint8Array([i]);
|
|
5017
|
+
break;
|
|
5018
|
+
}
|
|
5019
|
+
case ContentDoc: {
|
|
5020
|
+
const c = (
|
|
5021
|
+
/** @type {ContentDoc} */
|
|
5022
|
+
content
|
|
5023
|
+
);
|
|
5024
|
+
if (subdocs) {
|
|
5025
|
+
c.opts = {};
|
|
5026
|
+
c.doc.guid = i + "";
|
|
5027
|
+
}
|
|
5028
|
+
break;
|
|
5029
|
+
}
|
|
5030
|
+
case ContentEmbed: {
|
|
5031
|
+
const c = (
|
|
5032
|
+
/** @type {ContentEmbed} */
|
|
5033
|
+
content
|
|
5034
|
+
);
|
|
5035
|
+
c.embed = {};
|
|
5036
|
+
break;
|
|
5037
|
+
}
|
|
5038
|
+
case ContentFormat: {
|
|
5039
|
+
const c = (
|
|
5040
|
+
/** @type {ContentFormat} */
|
|
5041
|
+
content
|
|
5042
|
+
);
|
|
5043
|
+
if (formatting) {
|
|
5044
|
+
c.key = setIfUndefined(formattingKeyCache, c.key, () => i + "");
|
|
5045
|
+
c.value = setIfUndefined(formattingValueCache, c.value, () => ({ i }));
|
|
5046
|
+
}
|
|
5047
|
+
break;
|
|
5048
|
+
}
|
|
5049
|
+
case ContentJSON: {
|
|
5050
|
+
const c = (
|
|
5051
|
+
/** @type {ContentJSON} */
|
|
5052
|
+
content
|
|
5053
|
+
);
|
|
5054
|
+
c.arr = c.arr.map(() => i);
|
|
5055
|
+
break;
|
|
5056
|
+
}
|
|
5057
|
+
case ContentString: {
|
|
5058
|
+
const c = (
|
|
5059
|
+
/** @type {ContentString} */
|
|
5060
|
+
content
|
|
5061
|
+
);
|
|
5062
|
+
c.str = repeat(i % 10 + "", c.str.length);
|
|
5063
|
+
break;
|
|
5064
|
+
}
|
|
5065
|
+
default:
|
|
5066
|
+
unexpectedCase();
|
|
5067
|
+
}
|
|
5068
|
+
if (item.parentSub) {
|
|
5069
|
+
item.parentSub = setIfUndefined(mapKeyCache, item.parentSub, () => i + "");
|
|
5070
|
+
}
|
|
5071
|
+
i++;
|
|
5072
|
+
return block;
|
|
5073
|
+
}
|
|
5074
|
+
default:
|
|
5075
|
+
unexpectedCase();
|
|
5076
|
+
}
|
|
5077
|
+
};
|
|
5078
|
+
};
|
|
5079
|
+
var obfuscateUpdate = (update, opts) => convertUpdateFormat(update, createObfuscator(opts), UpdateDecoderV1, UpdateEncoderV1);
|
|
5080
|
+
var obfuscateUpdateV2 = (update, opts) => convertUpdateFormat(update, createObfuscator(opts), UpdateDecoderV2, UpdateEncoderV2);
|
|
5081
|
+
var convertUpdateFormatV1ToV2 = (update) => convertUpdateFormat(update, id, UpdateDecoderV1, UpdateEncoderV2);
|
|
5082
|
+
var convertUpdateFormatV2ToV1 = (update) => convertUpdateFormat(update, id, UpdateDecoderV2, UpdateEncoderV1);
|
|
3406
5083
|
var errorComputeChanges = "You must not compute changes after the event-handler fired.";
|
|
3407
5084
|
var YEvent = class {
|
|
3408
5085
|
/**
|
|
@@ -3729,6 +5406,17 @@ ${err.toString()}`);
|
|
|
3729
5406
|
}
|
|
3730
5407
|
}
|
|
3731
5408
|
};
|
|
5409
|
+
var getTypeChildren = (t) => {
|
|
5410
|
+
var _a;
|
|
5411
|
+
(_a = t.doc) != null ? _a : warnPrematureAccess();
|
|
5412
|
+
let s = t._start;
|
|
5413
|
+
const arr = [];
|
|
5414
|
+
while (s) {
|
|
5415
|
+
arr.push(s);
|
|
5416
|
+
s = s.right;
|
|
5417
|
+
}
|
|
5418
|
+
return arr;
|
|
5419
|
+
};
|
|
3732
5420
|
var callTypeObservers = (type, transaction, event) => {
|
|
3733
5421
|
const changedType = type;
|
|
3734
5422
|
const changedParentTypes = transaction.changedParentTypes;
|
|
@@ -3903,6 +5591,20 @@ ${err.toString()}`);
|
|
|
3903
5591
|
}
|
|
3904
5592
|
return cs;
|
|
3905
5593
|
};
|
|
5594
|
+
var typeListToArraySnapshot = (type, snapshot2) => {
|
|
5595
|
+
const cs = [];
|
|
5596
|
+
let n = type._start;
|
|
5597
|
+
while (n !== null) {
|
|
5598
|
+
if (n.countable && isVisible(n, snapshot2)) {
|
|
5599
|
+
const c = n.content.getContent();
|
|
5600
|
+
for (let i = 0; i < c.length; i++) {
|
|
5601
|
+
cs.push(c[i]);
|
|
5602
|
+
}
|
|
5603
|
+
}
|
|
5604
|
+
n = n.right;
|
|
5605
|
+
}
|
|
5606
|
+
return cs;
|
|
5607
|
+
};
|
|
3906
5608
|
var typeListForEach = (type, f) => {
|
|
3907
5609
|
var _a;
|
|
3908
5610
|
let index = 0;
|
|
@@ -4193,14 +5895,21 @@ ${err.toString()}`);
|
|
|
4193
5895
|
const val = parent._map.get(key);
|
|
4194
5896
|
return val !== void 0 && !val.deleted;
|
|
4195
5897
|
};
|
|
4196
|
-
var
|
|
5898
|
+
var typeMapGetSnapshot = (parent, key, snapshot2) => {
|
|
5899
|
+
let v = parent._map.get(key) || null;
|
|
5900
|
+
while (v !== null && (!snapshot2.sv.has(v.id.client) || v.id.clock >= (snapshot2.sv.get(v.id.client) || 0))) {
|
|
5901
|
+
v = v.left;
|
|
5902
|
+
}
|
|
5903
|
+
return v !== null && isVisible(v, snapshot2) ? v.content.getContent()[v.length - 1] : void 0;
|
|
5904
|
+
};
|
|
5905
|
+
var typeMapGetAllSnapshot = (parent, snapshot2) => {
|
|
4197
5906
|
const res = {};
|
|
4198
5907
|
parent._map.forEach((value, key) => {
|
|
4199
5908
|
let v = value;
|
|
4200
|
-
while (v !== null && (!
|
|
5909
|
+
while (v !== null && (!snapshot2.sv.has(v.id.client) || v.id.clock >= (snapshot2.sv.get(v.id.client) || 0))) {
|
|
4201
5910
|
v = v.left;
|
|
4202
5911
|
}
|
|
4203
|
-
if (v !== null && isVisible(v,
|
|
5912
|
+
if (v !== null && isVisible(v, snapshot2)) {
|
|
4204
5913
|
res[key] = v.content.getContent()[v.length - 1];
|
|
4205
5914
|
}
|
|
4206
5915
|
});
|
|
@@ -4439,6 +6148,7 @@ ${err.toString()}`);
|
|
|
4439
6148
|
encoder.writeTypeRef(YArrayRefID);
|
|
4440
6149
|
}
|
|
4441
6150
|
};
|
|
6151
|
+
var readYArray = (_decoder) => new YArray();
|
|
4442
6152
|
var YMapEvent = class extends YEvent {
|
|
4443
6153
|
/**
|
|
4444
6154
|
* @param {YMap<T>} ymap The YArray that changed.
|
|
@@ -4679,6 +6389,7 @@ ${err.toString()}`);
|
|
|
4679
6389
|
encoder.writeTypeRef(YMapRefID);
|
|
4680
6390
|
}
|
|
4681
6391
|
};
|
|
6392
|
+
var readYMap = (_decoder) => new YMap();
|
|
4682
6393
|
var equalAttrs = (a, b) => a === b || typeof a === "object" && typeof b === "object" && a && b && equalFlat(a, b);
|
|
4683
6394
|
var ItemTextListPosition = class {
|
|
4684
6395
|
/**
|
|
@@ -5461,7 +7172,7 @@ ${err.toString()}`);
|
|
|
5461
7172
|
*
|
|
5462
7173
|
* @public
|
|
5463
7174
|
*/
|
|
5464
|
-
toDelta(
|
|
7175
|
+
toDelta(snapshot2, prevSnapshot, computeYChange) {
|
|
5465
7176
|
var _a;
|
|
5466
7177
|
(_a = this.doc) != null ? _a : warnPrematureAccess();
|
|
5467
7178
|
const ops = [];
|
|
@@ -5490,11 +7201,11 @@ ${err.toString()}`);
|
|
|
5490
7201
|
}
|
|
5491
7202
|
const computeDelta = () => {
|
|
5492
7203
|
while (n !== null) {
|
|
5493
|
-
if (isVisible(n,
|
|
7204
|
+
if (isVisible(n, snapshot2) || prevSnapshot !== void 0 && isVisible(n, prevSnapshot)) {
|
|
5494
7205
|
switch (n.content.constructor) {
|
|
5495
7206
|
case ContentString: {
|
|
5496
7207
|
const cur = currentAttributes.get("ychange");
|
|
5497
|
-
if (
|
|
7208
|
+
if (snapshot2 !== void 0 && !isVisible(n, snapshot2)) {
|
|
5498
7209
|
if (cur === void 0 || cur.user !== n.id.client || cur.type !== "removed") {
|
|
5499
7210
|
packStr();
|
|
5500
7211
|
currentAttributes.set("ychange", computeYChange ? computeYChange("removed", n.id) : { type: "removed" });
|
|
@@ -5532,7 +7243,7 @@ ${err.toString()}`);
|
|
|
5532
7243
|
break;
|
|
5533
7244
|
}
|
|
5534
7245
|
case ContentFormat:
|
|
5535
|
-
if (isVisible(n,
|
|
7246
|
+
if (isVisible(n, snapshot2)) {
|
|
5536
7247
|
packStr();
|
|
5537
7248
|
updateCurrentAttributes(
|
|
5538
7249
|
currentAttributes,
|
|
@@ -5547,10 +7258,10 @@ ${err.toString()}`);
|
|
|
5547
7258
|
}
|
|
5548
7259
|
packStr();
|
|
5549
7260
|
};
|
|
5550
|
-
if (
|
|
7261
|
+
if (snapshot2 || prevSnapshot) {
|
|
5551
7262
|
transact(doc2, (transaction) => {
|
|
5552
|
-
if (
|
|
5553
|
-
splitSnapshotAffectedStructs(transaction,
|
|
7263
|
+
if (snapshot2) {
|
|
7264
|
+
splitSnapshotAffectedStructs(transaction, snapshot2);
|
|
5554
7265
|
}
|
|
5555
7266
|
if (prevSnapshot) {
|
|
5556
7267
|
splitSnapshotAffectedStructs(transaction, prevSnapshot);
|
|
@@ -5734,6 +7445,7 @@ ${err.toString()}`);
|
|
|
5734
7445
|
encoder.writeTypeRef(YTextRefID);
|
|
5735
7446
|
}
|
|
5736
7447
|
};
|
|
7448
|
+
var readYText = (_decoder) => new YText();
|
|
5737
7449
|
var YXmlTreeWalker = class {
|
|
5738
7450
|
/**
|
|
5739
7451
|
* @param {YXmlFragment | YXmlElement} root
|
|
@@ -6083,6 +7795,7 @@ ${err.toString()}`);
|
|
|
6083
7795
|
encoder.writeTypeRef(YXmlFragmentRefID);
|
|
6084
7796
|
}
|
|
6085
7797
|
};
|
|
7798
|
+
var readYXmlFragment = (_decoder) => new YXmlFragment();
|
|
6086
7799
|
var YXmlElement = class _YXmlElement extends YXmlFragment {
|
|
6087
7800
|
constructor(nodeName = "UNDEFINED") {
|
|
6088
7801
|
super();
|
|
@@ -6252,16 +7965,111 @@ ${err.toString()}`);
|
|
|
6252
7965
|
/**
|
|
6253
7966
|
* Returns all attribute name/value pairs in a JSON Object.
|
|
6254
7967
|
*
|
|
6255
|
-
* @param {Snapshot} [snapshot]
|
|
6256
|
-
* @return {{ [Key in Extract<keyof KV,string>]?: KV[Key]}} A JSON Object that describes the attributes.
|
|
7968
|
+
* @param {Snapshot} [snapshot]
|
|
7969
|
+
* @return {{ [Key in Extract<keyof KV,string>]?: KV[Key]}} A JSON Object that describes the attributes.
|
|
7970
|
+
*
|
|
7971
|
+
* @public
|
|
7972
|
+
*/
|
|
7973
|
+
getAttributes(snapshot2) {
|
|
7974
|
+
return (
|
|
7975
|
+
/** @type {any} */
|
|
7976
|
+
snapshot2 ? typeMapGetAllSnapshot(this, snapshot2) : typeMapGetAll(this)
|
|
7977
|
+
);
|
|
7978
|
+
}
|
|
7979
|
+
/**
|
|
7980
|
+
* Creates a Dom Element that mirrors this YXmlElement.
|
|
7981
|
+
*
|
|
7982
|
+
* @param {Document} [_document=document] The document object (you must define
|
|
7983
|
+
* this when calling this method in
|
|
7984
|
+
* nodejs)
|
|
7985
|
+
* @param {Object<string, any>} [hooks={}] Optional property to customize how hooks
|
|
7986
|
+
* are presented in the DOM
|
|
7987
|
+
* @param {any} [binding] You should not set this property. This is
|
|
7988
|
+
* used if DomBinding wants to create a
|
|
7989
|
+
* association to the created DOM type.
|
|
7990
|
+
* @return {Node} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}
|
|
7991
|
+
*
|
|
7992
|
+
* @public
|
|
7993
|
+
*/
|
|
7994
|
+
toDOM(_document = document, hooks = {}, binding) {
|
|
7995
|
+
const dom = _document.createElement(this.nodeName);
|
|
7996
|
+
const attrs = this.getAttributes();
|
|
7997
|
+
for (const key in attrs) {
|
|
7998
|
+
const value = attrs[key];
|
|
7999
|
+
if (typeof value === "string") {
|
|
8000
|
+
dom.setAttribute(key, value);
|
|
8001
|
+
}
|
|
8002
|
+
}
|
|
8003
|
+
typeListForEach(this, (yxml) => {
|
|
8004
|
+
dom.appendChild(yxml.toDOM(_document, hooks, binding));
|
|
8005
|
+
});
|
|
8006
|
+
if (binding !== void 0) {
|
|
8007
|
+
binding._createAssociation(dom, this);
|
|
8008
|
+
}
|
|
8009
|
+
return dom;
|
|
8010
|
+
}
|
|
8011
|
+
/**
|
|
8012
|
+
* Transform the properties of this type to binary and write it to an
|
|
8013
|
+
* BinaryEncoder.
|
|
8014
|
+
*
|
|
8015
|
+
* This is called when this Item is sent to a remote peer.
|
|
8016
|
+
*
|
|
8017
|
+
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.
|
|
8018
|
+
*/
|
|
8019
|
+
_write(encoder) {
|
|
8020
|
+
encoder.writeTypeRef(YXmlElementRefID);
|
|
8021
|
+
encoder.writeKey(this.nodeName);
|
|
8022
|
+
}
|
|
8023
|
+
};
|
|
8024
|
+
var readYXmlElement = (decoder) => new YXmlElement(decoder.readKey());
|
|
8025
|
+
var YXmlEvent = class extends YEvent {
|
|
8026
|
+
/**
|
|
8027
|
+
* @param {YXmlElement|YXmlText|YXmlFragment} target The target on which the event is created.
|
|
8028
|
+
* @param {Set<string|null>} subs The set of changed attributes. `null` is included if the
|
|
8029
|
+
* child list changed.
|
|
8030
|
+
* @param {Transaction} transaction The transaction instance with which the
|
|
8031
|
+
* change was created.
|
|
8032
|
+
*/
|
|
8033
|
+
constructor(target, subs, transaction) {
|
|
8034
|
+
super(target, transaction);
|
|
8035
|
+
this.childListChanged = false;
|
|
8036
|
+
this.attributesChanged = /* @__PURE__ */ new Set();
|
|
8037
|
+
subs.forEach((sub) => {
|
|
8038
|
+
if (sub === null) {
|
|
8039
|
+
this.childListChanged = true;
|
|
8040
|
+
} else {
|
|
8041
|
+
this.attributesChanged.add(sub);
|
|
8042
|
+
}
|
|
8043
|
+
});
|
|
8044
|
+
}
|
|
8045
|
+
};
|
|
8046
|
+
var YXmlHook = class _YXmlHook extends YMap {
|
|
8047
|
+
/**
|
|
8048
|
+
* @param {string} hookName nodeName of the Dom Node.
|
|
8049
|
+
*/
|
|
8050
|
+
constructor(hookName) {
|
|
8051
|
+
super();
|
|
8052
|
+
this.hookName = hookName;
|
|
8053
|
+
}
|
|
8054
|
+
/**
|
|
8055
|
+
* Creates an Item with the same effect as this Item (without position effect)
|
|
8056
|
+
*/
|
|
8057
|
+
_copy() {
|
|
8058
|
+
return new _YXmlHook(this.hookName);
|
|
8059
|
+
}
|
|
8060
|
+
/**
|
|
8061
|
+
* Makes a copy of this data type that can be included somewhere else.
|
|
8062
|
+
*
|
|
8063
|
+
* Note that the content is only readable _after_ it has been included somewhere in the Ydoc.
|
|
6257
8064
|
*
|
|
6258
|
-
* @
|
|
8065
|
+
* @return {YXmlHook}
|
|
6259
8066
|
*/
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
);
|
|
8067
|
+
clone() {
|
|
8068
|
+
const el = new _YXmlHook(this.hookName);
|
|
8069
|
+
this.forEach((value, key) => {
|
|
8070
|
+
el.set(key, value);
|
|
8071
|
+
});
|
|
8072
|
+
return el;
|
|
6265
8073
|
}
|
|
6266
8074
|
/**
|
|
6267
8075
|
* Creates a Dom Element that mirrors this YXmlElement.
|
|
@@ -6269,27 +8077,24 @@ ${err.toString()}`);
|
|
|
6269
8077
|
* @param {Document} [_document=document] The document object (you must define
|
|
6270
8078
|
* this when calling this method in
|
|
6271
8079
|
* nodejs)
|
|
6272
|
-
* @param {Object
|
|
8080
|
+
* @param {Object.<string, any>} [hooks] Optional property to customize how hooks
|
|
6273
8081
|
* are presented in the DOM
|
|
6274
8082
|
* @param {any} [binding] You should not set this property. This is
|
|
6275
8083
|
* used if DomBinding wants to create a
|
|
6276
|
-
* association to the created DOM type
|
|
6277
|
-
* @return {
|
|
8084
|
+
* association to the created DOM type
|
|
8085
|
+
* @return {Element} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}
|
|
6278
8086
|
*
|
|
6279
8087
|
* @public
|
|
6280
8088
|
*/
|
|
6281
8089
|
toDOM(_document = document, hooks = {}, binding) {
|
|
6282
|
-
const
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
}
|
|
8090
|
+
const hook = hooks[this.hookName];
|
|
8091
|
+
let dom;
|
|
8092
|
+
if (hook !== void 0) {
|
|
8093
|
+
dom = hook.createDom(this);
|
|
8094
|
+
} else {
|
|
8095
|
+
dom = document.createElement(this.hookName);
|
|
6289
8096
|
}
|
|
6290
|
-
|
|
6291
|
-
dom.appendChild(yxml.toDOM(_document, hooks, binding));
|
|
6292
|
-
});
|
|
8097
|
+
dom.setAttribute("data-yjs-hook", this.hookName);
|
|
6293
8098
|
if (binding !== void 0) {
|
|
6294
8099
|
binding._createAssociation(dom, this);
|
|
6295
8100
|
}
|
|
@@ -6304,31 +8109,11 @@ ${err.toString()}`);
|
|
|
6304
8109
|
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.
|
|
6305
8110
|
*/
|
|
6306
8111
|
_write(encoder) {
|
|
6307
|
-
encoder.writeTypeRef(
|
|
6308
|
-
encoder.writeKey(this.
|
|
6309
|
-
}
|
|
6310
|
-
};
|
|
6311
|
-
var YXmlEvent = class extends YEvent {
|
|
6312
|
-
/**
|
|
6313
|
-
* @param {YXmlElement|YXmlText|YXmlFragment} target The target on which the event is created.
|
|
6314
|
-
* @param {Set<string|null>} subs The set of changed attributes. `null` is included if the
|
|
6315
|
-
* child list changed.
|
|
6316
|
-
* @param {Transaction} transaction The transaction instance with which the
|
|
6317
|
-
* change was created.
|
|
6318
|
-
*/
|
|
6319
|
-
constructor(target, subs, transaction) {
|
|
6320
|
-
super(target, transaction);
|
|
6321
|
-
this.childListChanged = false;
|
|
6322
|
-
this.attributesChanged = /* @__PURE__ */ new Set();
|
|
6323
|
-
subs.forEach((sub) => {
|
|
6324
|
-
if (sub === null) {
|
|
6325
|
-
this.childListChanged = true;
|
|
6326
|
-
} else {
|
|
6327
|
-
this.attributesChanged.add(sub);
|
|
6328
|
-
}
|
|
6329
|
-
});
|
|
8112
|
+
encoder.writeTypeRef(YXmlHookRefID);
|
|
8113
|
+
encoder.writeKey(this.hookName);
|
|
6330
8114
|
}
|
|
6331
8115
|
};
|
|
8116
|
+
var readYXmlHook = (decoder) => new YXmlHook(decoder.readKey());
|
|
6332
8117
|
var YXmlText = class _YXmlText extends YText {
|
|
6333
8118
|
/**
|
|
6334
8119
|
* @type {YXmlElement|YXmlText|null}
|
|
@@ -6431,6 +8216,7 @@ ${err.toString()}`);
|
|
|
6431
8216
|
encoder.writeTypeRef(YXmlTextRefID);
|
|
6432
8217
|
}
|
|
6433
8218
|
};
|
|
8219
|
+
var readYXmlText = (decoder) => new YXmlText();
|
|
6434
8220
|
var AbstractStruct = class {
|
|
6435
8221
|
/**
|
|
6436
8222
|
* @param {ID} id
|
|
@@ -6593,6 +8379,7 @@ ${err.toString()}`);
|
|
|
6593
8379
|
return 3;
|
|
6594
8380
|
}
|
|
6595
8381
|
};
|
|
8382
|
+
var readContentBinary = (decoder) => new ContentBinary(decoder.readBuf());
|
|
6596
8383
|
var ContentDeleted = class _ContentDeleted {
|
|
6597
8384
|
/**
|
|
6598
8385
|
* @param {number} len
|
|
@@ -6673,6 +8460,7 @@ ${err.toString()}`);
|
|
|
6673
8460
|
return 1;
|
|
6674
8461
|
}
|
|
6675
8462
|
};
|
|
8463
|
+
var readContentDeleted = (decoder) => new ContentDeleted(decoder.readLen());
|
|
6676
8464
|
var createDocFromOpts = (guid, opts) => new Doc({ guid, ...opts, shouldLoad: opts.shouldLoad || opts.autoLoad || false });
|
|
6677
8465
|
var ContentDoc = class _ContentDoc {
|
|
6678
8466
|
/**
|
|
@@ -6774,6 +8562,7 @@ ${err.toString()}`);
|
|
|
6774
8562
|
return 9;
|
|
6775
8563
|
}
|
|
6776
8564
|
};
|
|
8565
|
+
var readContentDoc = (decoder) => new ContentDoc(createDocFromOpts(decoder.readString(), decoder.readAny()));
|
|
6777
8566
|
var ContentEmbed = class _ContentEmbed {
|
|
6778
8567
|
/**
|
|
6779
8568
|
* @param {Object} embed
|
|
@@ -6849,6 +8638,7 @@ ${err.toString()}`);
|
|
|
6849
8638
|
return 5;
|
|
6850
8639
|
}
|
|
6851
8640
|
};
|
|
8641
|
+
var readContentEmbed = (decoder) => new ContentEmbed(decoder.readJSON());
|
|
6852
8642
|
var ContentFormat = class _ContentFormat {
|
|
6853
8643
|
/**
|
|
6854
8644
|
* @param {string} key
|
|
@@ -6933,6 +8723,103 @@ ${err.toString()}`);
|
|
|
6933
8723
|
return 6;
|
|
6934
8724
|
}
|
|
6935
8725
|
};
|
|
8726
|
+
var readContentFormat = (decoder) => new ContentFormat(decoder.readKey(), decoder.readJSON());
|
|
8727
|
+
var ContentJSON = class _ContentJSON {
|
|
8728
|
+
/**
|
|
8729
|
+
* @param {Array<any>} arr
|
|
8730
|
+
*/
|
|
8731
|
+
constructor(arr) {
|
|
8732
|
+
this.arr = arr;
|
|
8733
|
+
}
|
|
8734
|
+
/**
|
|
8735
|
+
* @return {number}
|
|
8736
|
+
*/
|
|
8737
|
+
getLength() {
|
|
8738
|
+
return this.arr.length;
|
|
8739
|
+
}
|
|
8740
|
+
/**
|
|
8741
|
+
* @return {Array<any>}
|
|
8742
|
+
*/
|
|
8743
|
+
getContent() {
|
|
8744
|
+
return this.arr;
|
|
8745
|
+
}
|
|
8746
|
+
/**
|
|
8747
|
+
* @return {boolean}
|
|
8748
|
+
*/
|
|
8749
|
+
isCountable() {
|
|
8750
|
+
return true;
|
|
8751
|
+
}
|
|
8752
|
+
/**
|
|
8753
|
+
* @return {ContentJSON}
|
|
8754
|
+
*/
|
|
8755
|
+
copy() {
|
|
8756
|
+
return new _ContentJSON(this.arr);
|
|
8757
|
+
}
|
|
8758
|
+
/**
|
|
8759
|
+
* @param {number} offset
|
|
8760
|
+
* @return {ContentJSON}
|
|
8761
|
+
*/
|
|
8762
|
+
splice(offset) {
|
|
8763
|
+
const right = new _ContentJSON(this.arr.slice(offset));
|
|
8764
|
+
this.arr = this.arr.slice(0, offset);
|
|
8765
|
+
return right;
|
|
8766
|
+
}
|
|
8767
|
+
/**
|
|
8768
|
+
* @param {ContentJSON} right
|
|
8769
|
+
* @return {boolean}
|
|
8770
|
+
*/
|
|
8771
|
+
mergeWith(right) {
|
|
8772
|
+
this.arr = this.arr.concat(right.arr);
|
|
8773
|
+
return true;
|
|
8774
|
+
}
|
|
8775
|
+
/**
|
|
8776
|
+
* @param {Transaction} transaction
|
|
8777
|
+
* @param {Item} item
|
|
8778
|
+
*/
|
|
8779
|
+
integrate(transaction, item) {
|
|
8780
|
+
}
|
|
8781
|
+
/**
|
|
8782
|
+
* @param {Transaction} transaction
|
|
8783
|
+
*/
|
|
8784
|
+
delete(transaction) {
|
|
8785
|
+
}
|
|
8786
|
+
/**
|
|
8787
|
+
* @param {StructStore} store
|
|
8788
|
+
*/
|
|
8789
|
+
gc(store) {
|
|
8790
|
+
}
|
|
8791
|
+
/**
|
|
8792
|
+
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
8793
|
+
* @param {number} offset
|
|
8794
|
+
*/
|
|
8795
|
+
write(encoder, offset) {
|
|
8796
|
+
const len = this.arr.length;
|
|
8797
|
+
encoder.writeLen(len - offset);
|
|
8798
|
+
for (let i = offset; i < len; i++) {
|
|
8799
|
+
const c = this.arr[i];
|
|
8800
|
+
encoder.writeString(c === void 0 ? "undefined" : JSON.stringify(c));
|
|
8801
|
+
}
|
|
8802
|
+
}
|
|
8803
|
+
/**
|
|
8804
|
+
* @return {number}
|
|
8805
|
+
*/
|
|
8806
|
+
getRef() {
|
|
8807
|
+
return 2;
|
|
8808
|
+
}
|
|
8809
|
+
};
|
|
8810
|
+
var readContentJSON = (decoder) => {
|
|
8811
|
+
const len = decoder.readLen();
|
|
8812
|
+
const cs = [];
|
|
8813
|
+
for (let i = 0; i < len; i++) {
|
|
8814
|
+
const c = decoder.readString();
|
|
8815
|
+
if (c === "undefined") {
|
|
8816
|
+
cs.push(void 0);
|
|
8817
|
+
} else {
|
|
8818
|
+
cs.push(JSON.parse(c));
|
|
8819
|
+
}
|
|
8820
|
+
}
|
|
8821
|
+
return new ContentJSON(cs);
|
|
8822
|
+
};
|
|
6936
8823
|
var isDevMode = getVariable("node_env") === "development";
|
|
6937
8824
|
var ContentAny = class _ContentAny {
|
|
6938
8825
|
/**
|
|
@@ -7018,6 +8905,14 @@ ${err.toString()}`);
|
|
|
7018
8905
|
return 8;
|
|
7019
8906
|
}
|
|
7020
8907
|
};
|
|
8908
|
+
var readContentAny = (decoder) => {
|
|
8909
|
+
const len = decoder.readLen();
|
|
8910
|
+
const cs = [];
|
|
8911
|
+
for (let i = 0; i < len; i++) {
|
|
8912
|
+
cs.push(decoder.readAny());
|
|
8913
|
+
}
|
|
8914
|
+
return new ContentAny(cs);
|
|
8915
|
+
};
|
|
7021
8916
|
var ContentString = class _ContentString {
|
|
7022
8917
|
/**
|
|
7023
8918
|
* @param {string} str
|
|
@@ -7101,11 +8996,22 @@ ${err.toString()}`);
|
|
|
7101
8996
|
return 4;
|
|
7102
8997
|
}
|
|
7103
8998
|
};
|
|
8999
|
+
var readContentString = (decoder) => new ContentString(decoder.readString());
|
|
9000
|
+
var typeRefs = [
|
|
9001
|
+
readYArray,
|
|
9002
|
+
readYMap,
|
|
9003
|
+
readYText,
|
|
9004
|
+
readYXmlElement,
|
|
9005
|
+
readYXmlFragment,
|
|
9006
|
+
readYXmlHook,
|
|
9007
|
+
readYXmlText
|
|
9008
|
+
];
|
|
7104
9009
|
var YArrayRefID = 0;
|
|
7105
9010
|
var YMapRefID = 1;
|
|
7106
9011
|
var YTextRefID = 2;
|
|
7107
9012
|
var YXmlElementRefID = 3;
|
|
7108
9013
|
var YXmlFragmentRefID = 4;
|
|
9014
|
+
var YXmlHookRefID = 5;
|
|
7109
9015
|
var YXmlTextRefID = 6;
|
|
7110
9016
|
var ContentType = class _ContentType {
|
|
7111
9017
|
/**
|
|
@@ -7216,6 +9122,7 @@ ${err.toString()}`);
|
|
|
7216
9122
|
return 7;
|
|
7217
9123
|
}
|
|
7218
9124
|
};
|
|
9125
|
+
var readContentType = (decoder) => new ContentType(typeRefs[decoder.readTypeRef()](decoder));
|
|
7219
9126
|
var followRedone = (store, id2) => {
|
|
7220
9127
|
let nextID = id2;
|
|
7221
9128
|
let diff = 0;
|
|
@@ -7728,6 +9635,77 @@ ${err.toString()}`);
|
|
|
7728
9635
|
this.content.write(encoder, offset);
|
|
7729
9636
|
}
|
|
7730
9637
|
};
|
|
9638
|
+
var readItemContent = (decoder, info) => contentRefs[info & BITS5](decoder);
|
|
9639
|
+
var contentRefs = [
|
|
9640
|
+
() => {
|
|
9641
|
+
unexpectedCase();
|
|
9642
|
+
},
|
|
9643
|
+
// GC is not ItemContent
|
|
9644
|
+
readContentDeleted,
|
|
9645
|
+
// 1
|
|
9646
|
+
readContentJSON,
|
|
9647
|
+
// 2
|
|
9648
|
+
readContentBinary,
|
|
9649
|
+
// 3
|
|
9650
|
+
readContentString,
|
|
9651
|
+
// 4
|
|
9652
|
+
readContentEmbed,
|
|
9653
|
+
// 5
|
|
9654
|
+
readContentFormat,
|
|
9655
|
+
// 6
|
|
9656
|
+
readContentType,
|
|
9657
|
+
// 7
|
|
9658
|
+
readContentAny,
|
|
9659
|
+
// 8
|
|
9660
|
+
readContentDoc,
|
|
9661
|
+
// 9
|
|
9662
|
+
() => {
|
|
9663
|
+
unexpectedCase();
|
|
9664
|
+
}
|
|
9665
|
+
// 10 - Skip is not ItemContent
|
|
9666
|
+
];
|
|
9667
|
+
var structSkipRefNumber = 10;
|
|
9668
|
+
var Skip = class extends AbstractStruct {
|
|
9669
|
+
get deleted() {
|
|
9670
|
+
return true;
|
|
9671
|
+
}
|
|
9672
|
+
delete() {
|
|
9673
|
+
}
|
|
9674
|
+
/**
|
|
9675
|
+
* @param {Skip} right
|
|
9676
|
+
* @return {boolean}
|
|
9677
|
+
*/
|
|
9678
|
+
mergeWith(right) {
|
|
9679
|
+
if (this.constructor !== right.constructor) {
|
|
9680
|
+
return false;
|
|
9681
|
+
}
|
|
9682
|
+
this.length += right.length;
|
|
9683
|
+
return true;
|
|
9684
|
+
}
|
|
9685
|
+
/**
|
|
9686
|
+
* @param {Transaction} transaction
|
|
9687
|
+
* @param {number} offset
|
|
9688
|
+
*/
|
|
9689
|
+
integrate(transaction, offset) {
|
|
9690
|
+
unexpectedCase();
|
|
9691
|
+
}
|
|
9692
|
+
/**
|
|
9693
|
+
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
9694
|
+
* @param {number} offset
|
|
9695
|
+
*/
|
|
9696
|
+
write(encoder, offset) {
|
|
9697
|
+
encoder.writeInfo(structSkipRefNumber);
|
|
9698
|
+
writeVarUint(encoder.restEncoder, this.length - offset);
|
|
9699
|
+
}
|
|
9700
|
+
/**
|
|
9701
|
+
* @param {Transaction} transaction
|
|
9702
|
+
* @param {StructStore} store
|
|
9703
|
+
* @return {null | number}
|
|
9704
|
+
*/
|
|
9705
|
+
getMissing(transaction, store) {
|
|
9706
|
+
return null;
|
|
9707
|
+
}
|
|
9708
|
+
};
|
|
7731
9709
|
var glo = (
|
|
7732
9710
|
/** @type {any} */
|
|
7733
9711
|
typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {}
|
|
@@ -7830,49 +9808,6 @@ ${err.toString()}`);
|
|
|
7830
9808
|
|
|
7831
9809
|
// src/render.ts
|
|
7832
9810
|
var HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
7833
|
-
// --- dual-Yjs interop (CRITICAL) -------------------------------------------
|
|
7834
|
-
// crdt-engine bundles its own copy of Yjs, but the app supplies the Y.Doc
|
|
7835
|
-
// (and provider) from a SEPARATE Yjs instance (CDN UMD/ESM). Inserting nodes
|
|
7836
|
-
// built with the bundled Yjs classes into the app's doc throws
|
|
7837
|
-
// "Unexpected content type in insert operation", and reading app-built remote
|
|
7838
|
-
// nodes via `instanceof <bundled class>` silently fails. We therefore:
|
|
7839
|
-
// (a) construct nodes with the APP's Yjs constructors (resolved at attach),
|
|
7840
|
-
// (b) detect node kinds by duck-typing instead of instanceof.
|
|
7841
|
-
var __appXmlText = null;
|
|
7842
|
-
var __appXmlElement = null;
|
|
7843
|
-
function setAppYjs(Y) {
|
|
7844
|
-
if (Y && typeof Y.XmlText === "function" && typeof Y.XmlElement === "function") {
|
|
7845
|
-
__appXmlText = Y.XmlText;
|
|
7846
|
-
__appXmlElement = Y.XmlElement;
|
|
7847
|
-
return true;
|
|
7848
|
-
}
|
|
7849
|
-
return false;
|
|
7850
|
-
}
|
|
7851
|
-
function resolveAppYjs(options) {
|
|
7852
|
-
if (options && setAppYjs(options.Y)) return;
|
|
7853
|
-
if (typeof window !== "undefined" && setAppYjs(window.Y)) return;
|
|
7854
|
-
// Fallback: bundled classes (only correct when the app's doc was created
|
|
7855
|
-
// from this same bundled Yjs, e.g. RichTextEditorCrdt.Y).
|
|
7856
|
-
__appXmlText = YXmlText;
|
|
7857
|
-
__appXmlElement = YXmlElement;
|
|
7858
|
-
}
|
|
7859
|
-
function mkYText(s) {
|
|
7860
|
-
return new (__appXmlText || YXmlText)(s);
|
|
7861
|
-
}
|
|
7862
|
-
function mkYElement(tag) {
|
|
7863
|
-
return new (__appXmlElement || YXmlElement)(tag);
|
|
7864
|
-
}
|
|
7865
|
-
function isYXmlElementLike(n) {
|
|
7866
|
-
return !!n && typeof n.nodeName === "string" && typeof n.getAttributes === "function";
|
|
7867
|
-
}
|
|
7868
|
-
function isYXmlTextLike(n) {
|
|
7869
|
-
return !!n && typeof n.toDelta === "function" && typeof n.nodeName !== "string";
|
|
7870
|
-
}
|
|
7871
|
-
function hostHasMeaningfulContent(host) {
|
|
7872
|
-
if (!host) return false;
|
|
7873
|
-
if (host.textContent && host.textContent.trim().length > 0) return true;
|
|
7874
|
-
return !!host.querySelector && !!host.querySelector("img,table,hr,video,iframe,figure,ul,ol,blockquote,pre");
|
|
7875
|
-
}
|
|
7876
9811
|
function renderFragmentToHost(fragment, host) {
|
|
7877
9812
|
while (host.firstChild) {
|
|
7878
9813
|
host.removeChild(host.firstChild);
|
|
@@ -7891,10 +9826,10 @@ ${err.toString()}`);
|
|
|
7891
9826
|
}
|
|
7892
9827
|
}
|
|
7893
9828
|
function renderYNodeToDom(node, doc2) {
|
|
7894
|
-
if (
|
|
9829
|
+
if (node instanceof YXmlText) {
|
|
7895
9830
|
return renderYTextToDom(node, doc2);
|
|
7896
9831
|
}
|
|
7897
|
-
if (
|
|
9832
|
+
if (node instanceof YXmlElement) {
|
|
7898
9833
|
return renderYElementToDom(node, doc2);
|
|
7899
9834
|
}
|
|
7900
9835
|
return null;
|
|
@@ -8188,11 +10123,11 @@ ${err.toString()}`);
|
|
|
8188
10123
|
for (let i = 0; i < path.length - 1; i++) {
|
|
8189
10124
|
const idx = path[i];
|
|
8190
10125
|
const child = cursor.get(idx);
|
|
8191
|
-
if (!
|
|
10126
|
+
if (!(child instanceof YXmlElement)) return null;
|
|
8192
10127
|
cursor = child;
|
|
8193
10128
|
}
|
|
8194
10129
|
const last2 = cursor.get(path[path.length - 1]);
|
|
8195
|
-
if (
|
|
10130
|
+
if (last2 instanceof YXmlText) return last2;
|
|
8196
10131
|
return null;
|
|
8197
10132
|
}
|
|
8198
10133
|
function locateYElement(domEl, opts) {
|
|
@@ -8201,10 +10136,10 @@ ${err.toString()}`);
|
|
|
8201
10136
|
let cursor = opts.fragment;
|
|
8202
10137
|
for (const idx of path) {
|
|
8203
10138
|
const child = cursor.get(idx);
|
|
8204
|
-
if (!
|
|
10139
|
+
if (!(child instanceof YXmlElement)) return null;
|
|
8205
10140
|
cursor = child;
|
|
8206
10141
|
}
|
|
8207
|
-
return
|
|
10142
|
+
return cursor instanceof YXmlElement ? cursor : null;
|
|
8208
10143
|
}
|
|
8209
10144
|
function pathFromHost2(host, target) {
|
|
8210
10145
|
const path = [];
|
|
@@ -8254,7 +10189,7 @@ ${err.toString()}`);
|
|
|
8254
10189
|
}
|
|
8255
10190
|
function buildYNodeFromDomChild(node) {
|
|
8256
10191
|
if (node.nodeType === 3) {
|
|
8257
|
-
const t =
|
|
10192
|
+
const t = new YXmlText(node.data);
|
|
8258
10193
|
return { node: t, marked: [] };
|
|
8259
10194
|
}
|
|
8260
10195
|
if (node.nodeType !== 1) return null;
|
|
@@ -8262,7 +10197,7 @@ ${err.toString()}`);
|
|
|
8262
10197
|
const tag = el.tagName.toLowerCase();
|
|
8263
10198
|
const kind = classify(tag);
|
|
8264
10199
|
if (kind === "mark") return null;
|
|
8265
|
-
const yel =
|
|
10200
|
+
const yel = new YXmlElement(tag);
|
|
8266
10201
|
for (const attr of Array.from(el.attributes)) {
|
|
8267
10202
|
yel.setAttribute(attr.name, attr.value);
|
|
8268
10203
|
}
|
|
@@ -8281,7 +10216,7 @@ ${err.toString()}`);
|
|
|
8281
10216
|
let buffer = null;
|
|
8282
10217
|
const flushText = () => {
|
|
8283
10218
|
if (buffer && buffer.str.length > 0) {
|
|
8284
|
-
const yt =
|
|
10219
|
+
const yt = new YXmlText(buffer.str);
|
|
8285
10220
|
result.children.push(yt);
|
|
8286
10221
|
if (buffer.ranges.length > 0) {
|
|
8287
10222
|
result.marked.push({ text: yt, ranges: buffer.ranges });
|
|
@@ -8313,7 +10248,7 @@ ${err.toString()}`);
|
|
|
8313
10248
|
}
|
|
8314
10249
|
flushText();
|
|
8315
10250
|
if (kind === "leaf") {
|
|
8316
|
-
const leaf =
|
|
10251
|
+
const leaf = new YXmlElement(tag);
|
|
8317
10252
|
for (const attr of Array.from(el.attributes)) {
|
|
8318
10253
|
leaf.setAttribute(attr.name, attr.value);
|
|
8319
10254
|
}
|
|
@@ -8437,7 +10372,6 @@ ${err.toString()}`);
|
|
|
8437
10372
|
// src/binding.ts
|
|
8438
10373
|
function attachCrdtBinding(options) {
|
|
8439
10374
|
var _a, _b, _c;
|
|
8440
|
-
resolveAppYjs(options);
|
|
8441
10375
|
const fragmentName = (_a = options.fragmentName) != null ? _a : "default";
|
|
8442
10376
|
const fragment = options.ydoc.getXmlFragment(fragmentName);
|
|
8443
10377
|
const awareness = (_c = options.awareness) != null ? _c : (_b = options.provider) == null ? void 0 : _b.awareness;
|
|
@@ -8447,74 +10381,14 @@ ${err.toString()}`);
|
|
|
8447
10381
|
fragment,
|
|
8448
10382
|
isApplyingRemote: () => applyingRemote
|
|
8449
10383
|
});
|
|
8450
|
-
// Initial reconciliation (provider/seed aware). Without this, attaching to
|
|
8451
|
-
// an EMPTY shared doc renders the empty fragment over the editor, silently
|
|
8452
|
-
// WIPING any existing content. Instead: if the shared doc already has
|
|
8453
|
-
// content, render it (remote wins); if it's empty but this editor has
|
|
8454
|
-
// content, SEED the shared doc from it (first writer); otherwise normalize.
|
|
8455
|
-
// Gated on provider sync so we never seed over not-yet-synced remote state.
|
|
8456
|
-
const hostHadContent = hostHasMeaningfulContent(options.editable);
|
|
8457
|
-
let reconciled = false;
|
|
8458
|
-
let syncTimer = null;
|
|
8459
|
-
const reconcileInitial = () => {
|
|
8460
|
-
if (reconciled) return;
|
|
8461
|
-
reconciled = true;
|
|
8462
|
-
if (syncTimer != null) {
|
|
8463
|
-
try {
|
|
8464
|
-
clearTimeout(syncTimer);
|
|
8465
|
-
} catch (e) {
|
|
8466
|
-
}
|
|
8467
|
-
syncTimer = null;
|
|
8468
|
-
}
|
|
8469
|
-
applyingRemote = true;
|
|
8470
|
-
try {
|
|
8471
|
-
if (fragment.length > 0) {
|
|
8472
|
-
renderFragmentToHost(fragment, options.editable);
|
|
8473
|
-
} else if (hostHadContent && options.seedFromHost !== false) {
|
|
8474
|
-
const seedDoc = fragment.doc;
|
|
8475
|
-
if (seedDoc) {
|
|
8476
|
-
seedDoc.transact(() => rebuildFragmentFromEditable({ editable: options.editable, fragment }), LOCAL_ORIGIN);
|
|
8477
|
-
}
|
|
8478
|
-
} else {
|
|
8479
|
-
renderFragmentToHost(fragment, options.editable);
|
|
8480
|
-
}
|
|
8481
|
-
} finally {
|
|
8482
|
-
observerHandle.drainPending();
|
|
8483
|
-
applyingRemote = false;
|
|
8484
|
-
}
|
|
8485
|
-
};
|
|
8486
|
-
let unsubscribeSync = () => {
|
|
8487
|
-
};
|
|
8488
10384
|
applyingRemote = true;
|
|
8489
|
-
|
|
8490
|
-
|
|
8491
|
-
|
|
8492
|
-
|
|
8493
|
-
|
|
8494
|
-
if (state === void 0 || state) reconcileInitial();
|
|
8495
|
-
};
|
|
8496
|
-
_provider.on("sync", onSync);
|
|
8497
|
-
_provider.on("synced", onSync);
|
|
8498
|
-
unsubscribeSync = () => {
|
|
8499
|
-
try {
|
|
8500
|
-
if (typeof _provider.off === "function") {
|
|
8501
|
-
_provider.off("sync", onSync);
|
|
8502
|
-
_provider.off("synced", onSync);
|
|
8503
|
-
}
|
|
8504
|
-
} catch (e) {
|
|
8505
|
-
}
|
|
8506
|
-
};
|
|
8507
|
-
if (typeof setTimeout === "function") {
|
|
8508
|
-
syncTimer = setTimeout(reconcileInitial, 3e3);
|
|
8509
|
-
} else {
|
|
8510
|
-
reconcileInitial();
|
|
8511
|
-
}
|
|
8512
|
-
} else {
|
|
8513
|
-
reconcileInitial();
|
|
10385
|
+
try {
|
|
10386
|
+
renderFragmentToHost(fragment, options.editable);
|
|
10387
|
+
} finally {
|
|
10388
|
+
observerHandle.drainPending();
|
|
10389
|
+
applyingRemote = false;
|
|
8514
10390
|
}
|
|
8515
10391
|
const onUpdate = (_update, origin) => {
|
|
8516
|
-
if (!reconciled) return;
|
|
8517
|
-
if (origin === LOCAL_ORIGIN) return;
|
|
8518
10392
|
if (origin === LOCAL_ORIGIN) return;
|
|
8519
10393
|
const captured = captureSelection(options.editable);
|
|
8520
10394
|
applyingRemote = true;
|
|
@@ -8532,7 +10406,7 @@ ${err.toString()}`);
|
|
|
8532
10406
|
};
|
|
8533
10407
|
const unsubscribeLocal = () => observerHandle.disconnect();
|
|
8534
10408
|
const unsubscribeAwareness = subscribeAwarenessStub(awareness, options.initialAwareness);
|
|
8535
|
-
let cleanups = [unsubscribeRemote, unsubscribeLocal, unsubscribeAwareness
|
|
10409
|
+
let cleanups = [unsubscribeRemote, unsubscribeLocal, unsubscribeAwareness];
|
|
8536
10410
|
return {
|
|
8537
10411
|
ydoc: options.ydoc,
|
|
8538
10412
|
fragment,
|
|
@@ -8898,8 +10772,137 @@ ${err.toString()}`);
|
|
|
8898
10772
|
return fragment;
|
|
8899
10773
|
}
|
|
8900
10774
|
|
|
10775
|
+
// node_modules/y-protocols/awareness.js
|
|
10776
|
+
var outdatedTimeout = 3e4;
|
|
10777
|
+
var Awareness = class extends Observable {
|
|
10778
|
+
/**
|
|
10779
|
+
* @param {Y.Doc} doc
|
|
10780
|
+
*/
|
|
10781
|
+
constructor(doc2) {
|
|
10782
|
+
super();
|
|
10783
|
+
this.doc = doc2;
|
|
10784
|
+
this.clientID = doc2.clientID;
|
|
10785
|
+
this.states = /* @__PURE__ */ new Map();
|
|
10786
|
+
this.meta = /* @__PURE__ */ new Map();
|
|
10787
|
+
this._checkInterval = /** @type {any} */
|
|
10788
|
+
setInterval(() => {
|
|
10789
|
+
const now = getUnixTime();
|
|
10790
|
+
if (this.getLocalState() !== null && outdatedTimeout / 2 <= now - /** @type {{lastUpdated:number}} */
|
|
10791
|
+
this.meta.get(this.clientID).lastUpdated) {
|
|
10792
|
+
this.setLocalState(this.getLocalState());
|
|
10793
|
+
}
|
|
10794
|
+
const remove = [];
|
|
10795
|
+
this.meta.forEach((meta, clientid) => {
|
|
10796
|
+
if (clientid !== this.clientID && outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) {
|
|
10797
|
+
remove.push(clientid);
|
|
10798
|
+
}
|
|
10799
|
+
});
|
|
10800
|
+
if (remove.length > 0) {
|
|
10801
|
+
removeAwarenessStates(this, remove, "timeout");
|
|
10802
|
+
}
|
|
10803
|
+
}, floor(outdatedTimeout / 10));
|
|
10804
|
+
doc2.on("destroy", () => {
|
|
10805
|
+
this.destroy();
|
|
10806
|
+
});
|
|
10807
|
+
this.setLocalState({});
|
|
10808
|
+
}
|
|
10809
|
+
destroy() {
|
|
10810
|
+
this.emit("destroy", [this]);
|
|
10811
|
+
this.setLocalState(null);
|
|
10812
|
+
super.destroy();
|
|
10813
|
+
clearInterval(this._checkInterval);
|
|
10814
|
+
}
|
|
10815
|
+
/**
|
|
10816
|
+
* @return {Object<string,any>|null}
|
|
10817
|
+
*/
|
|
10818
|
+
getLocalState() {
|
|
10819
|
+
return this.states.get(this.clientID) || null;
|
|
10820
|
+
}
|
|
10821
|
+
/**
|
|
10822
|
+
* @param {Object<string,any>|null} state
|
|
10823
|
+
*/
|
|
10824
|
+
setLocalState(state) {
|
|
10825
|
+
const clientID = this.clientID;
|
|
10826
|
+
const currLocalMeta = this.meta.get(clientID);
|
|
10827
|
+
const clock = currLocalMeta === void 0 ? 0 : currLocalMeta.clock + 1;
|
|
10828
|
+
const prevState = this.states.get(clientID);
|
|
10829
|
+
if (state === null) {
|
|
10830
|
+
this.states.delete(clientID);
|
|
10831
|
+
} else {
|
|
10832
|
+
this.states.set(clientID, state);
|
|
10833
|
+
}
|
|
10834
|
+
this.meta.set(clientID, {
|
|
10835
|
+
clock,
|
|
10836
|
+
lastUpdated: getUnixTime()
|
|
10837
|
+
});
|
|
10838
|
+
const added = [];
|
|
10839
|
+
const updated = [];
|
|
10840
|
+
const filteredUpdated = [];
|
|
10841
|
+
const removed = [];
|
|
10842
|
+
if (state === null) {
|
|
10843
|
+
removed.push(clientID);
|
|
10844
|
+
} else if (prevState == null) {
|
|
10845
|
+
if (state != null) {
|
|
10846
|
+
added.push(clientID);
|
|
10847
|
+
}
|
|
10848
|
+
} else {
|
|
10849
|
+
updated.push(clientID);
|
|
10850
|
+
if (!equalityDeep(prevState, state)) {
|
|
10851
|
+
filteredUpdated.push(clientID);
|
|
10852
|
+
}
|
|
10853
|
+
}
|
|
10854
|
+
if (added.length > 0 || filteredUpdated.length > 0 || removed.length > 0) {
|
|
10855
|
+
this.emit("change", [{ added, updated: filteredUpdated, removed }, "local"]);
|
|
10856
|
+
}
|
|
10857
|
+
this.emit("update", [{ added, updated, removed }, "local"]);
|
|
10858
|
+
}
|
|
10859
|
+
/**
|
|
10860
|
+
* @param {string} field
|
|
10861
|
+
* @param {any} value
|
|
10862
|
+
*/
|
|
10863
|
+
setLocalStateField(field, value) {
|
|
10864
|
+
const state = this.getLocalState();
|
|
10865
|
+
if (state !== null) {
|
|
10866
|
+
this.setLocalState({
|
|
10867
|
+
...state,
|
|
10868
|
+
[field]: value
|
|
10869
|
+
});
|
|
10870
|
+
}
|
|
10871
|
+
}
|
|
10872
|
+
/**
|
|
10873
|
+
* @return {Map<number,Object<string,any>>}
|
|
10874
|
+
*/
|
|
10875
|
+
getStates() {
|
|
10876
|
+
return this.states;
|
|
10877
|
+
}
|
|
10878
|
+
};
|
|
10879
|
+
var removeAwarenessStates = (awareness, clients, origin) => {
|
|
10880
|
+
const removed = [];
|
|
10881
|
+
for (let i = 0; i < clients.length; i++) {
|
|
10882
|
+
const clientID = clients[i];
|
|
10883
|
+
if (awareness.states.has(clientID)) {
|
|
10884
|
+
awareness.states.delete(clientID);
|
|
10885
|
+
if (clientID === awareness.clientID) {
|
|
10886
|
+
const curMeta = (
|
|
10887
|
+
/** @type {MetaClientState} */
|
|
10888
|
+
awareness.meta.get(clientID)
|
|
10889
|
+
);
|
|
10890
|
+
awareness.meta.set(clientID, {
|
|
10891
|
+
clock: curMeta.clock + 1,
|
|
10892
|
+
lastUpdated: getUnixTime()
|
|
10893
|
+
});
|
|
10894
|
+
}
|
|
10895
|
+
removed.push(clientID);
|
|
10896
|
+
}
|
|
10897
|
+
}
|
|
10898
|
+
if (removed.length > 0) {
|
|
10899
|
+
awareness.emit("change", [{ added: [], updated: [], removed }, origin]);
|
|
10900
|
+
awareness.emit("update", [{ added: [], updated: [], removed }, origin]);
|
|
10901
|
+
}
|
|
10902
|
+
};
|
|
10903
|
+
|
|
8901
10904
|
// src/global-shim.ts
|
|
8902
10905
|
if (typeof window !== "undefined") {
|
|
8903
|
-
window.RichTextEditorCrdt =
|
|
10906
|
+
window.RichTextEditorCrdt = Object.assign({}, index_exports, { Y: yjs_exports, Awareness });
|
|
8904
10907
|
}
|
|
8905
10908
|
})();
|