@yorkie-js/react 0.6.34 → 0.6.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/yorkie-js-react.es.js +504 -349
- package/dist/yorkie-js-react.es.js.map +1 -1
- package/dist/yorkie-js-react.js +504 -349
- package/dist/yorkie-js-react.js.map +1 -1
- package/package.json +2 -2
package/dist/yorkie-js-react.js
CHANGED
|
@@ -7846,6 +7846,95 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7846
7846
|
{ no: 1, name: "change_pack", kind: "message", T: ChangePack$1 }
|
|
7847
7847
|
]));
|
|
7848
7848
|
let PushPullChangesResponse = _PushPullChangesResponse;
|
|
7849
|
+
const _BroadcastRequest = class _BroadcastRequest extends Message {
|
|
7850
|
+
constructor(data) {
|
|
7851
|
+
super();
|
|
7852
|
+
/**
|
|
7853
|
+
* @generated from field: string client_id = 1;
|
|
7854
|
+
*/
|
|
7855
|
+
__publicField(this, "clientId", "");
|
|
7856
|
+
/**
|
|
7857
|
+
* @generated from field: string document_id = 2;
|
|
7858
|
+
*/
|
|
7859
|
+
__publicField(this, "documentId", "");
|
|
7860
|
+
/**
|
|
7861
|
+
* @generated from field: string topic = 3;
|
|
7862
|
+
*/
|
|
7863
|
+
__publicField(this, "topic", "");
|
|
7864
|
+
/**
|
|
7865
|
+
* @generated from field: bytes payload = 4;
|
|
7866
|
+
*/
|
|
7867
|
+
__publicField(this, "payload", new Uint8Array(0));
|
|
7868
|
+
proto3.util.initPartial(data, this);
|
|
7869
|
+
}
|
|
7870
|
+
static fromBinary(bytes, options) {
|
|
7871
|
+
return new _BroadcastRequest().fromBinary(bytes, options);
|
|
7872
|
+
}
|
|
7873
|
+
static fromJson(jsonValue, options) {
|
|
7874
|
+
return new _BroadcastRequest().fromJson(jsonValue, options);
|
|
7875
|
+
}
|
|
7876
|
+
static fromJsonString(jsonString, options) {
|
|
7877
|
+
return new _BroadcastRequest().fromJsonString(jsonString, options);
|
|
7878
|
+
}
|
|
7879
|
+
static equals(a, b) {
|
|
7880
|
+
return proto3.util.equals(_BroadcastRequest, a, b);
|
|
7881
|
+
}
|
|
7882
|
+
};
|
|
7883
|
+
__publicField(_BroadcastRequest, "runtime", proto3);
|
|
7884
|
+
__publicField(_BroadcastRequest, "typeName", "yorkie.v1.BroadcastRequest");
|
|
7885
|
+
__publicField(_BroadcastRequest, "fields", proto3.util.newFieldList(() => [
|
|
7886
|
+
{
|
|
7887
|
+
no: 1,
|
|
7888
|
+
name: "client_id",
|
|
7889
|
+
kind: "scalar",
|
|
7890
|
+
T: 9
|
|
7891
|
+
/* ScalarType.STRING */
|
|
7892
|
+
},
|
|
7893
|
+
{
|
|
7894
|
+
no: 2,
|
|
7895
|
+
name: "document_id",
|
|
7896
|
+
kind: "scalar",
|
|
7897
|
+
T: 9
|
|
7898
|
+
/* ScalarType.STRING */
|
|
7899
|
+
},
|
|
7900
|
+
{
|
|
7901
|
+
no: 3,
|
|
7902
|
+
name: "topic",
|
|
7903
|
+
kind: "scalar",
|
|
7904
|
+
T: 9
|
|
7905
|
+
/* ScalarType.STRING */
|
|
7906
|
+
},
|
|
7907
|
+
{
|
|
7908
|
+
no: 4,
|
|
7909
|
+
name: "payload",
|
|
7910
|
+
kind: "scalar",
|
|
7911
|
+
T: 12
|
|
7912
|
+
/* ScalarType.BYTES */
|
|
7913
|
+
}
|
|
7914
|
+
]));
|
|
7915
|
+
let BroadcastRequest = _BroadcastRequest;
|
|
7916
|
+
const _BroadcastResponse = class _BroadcastResponse extends Message {
|
|
7917
|
+
constructor(data) {
|
|
7918
|
+
super();
|
|
7919
|
+
proto3.util.initPartial(data, this);
|
|
7920
|
+
}
|
|
7921
|
+
static fromBinary(bytes, options) {
|
|
7922
|
+
return new _BroadcastResponse().fromBinary(bytes, options);
|
|
7923
|
+
}
|
|
7924
|
+
static fromJson(jsonValue, options) {
|
|
7925
|
+
return new _BroadcastResponse().fromJson(jsonValue, options);
|
|
7926
|
+
}
|
|
7927
|
+
static fromJsonString(jsonString, options) {
|
|
7928
|
+
return new _BroadcastResponse().fromJsonString(jsonString, options);
|
|
7929
|
+
}
|
|
7930
|
+
static equals(a, b) {
|
|
7931
|
+
return proto3.util.equals(_BroadcastResponse, a, b);
|
|
7932
|
+
}
|
|
7933
|
+
};
|
|
7934
|
+
__publicField(_BroadcastResponse, "runtime", proto3);
|
|
7935
|
+
__publicField(_BroadcastResponse, "typeName", "yorkie.v1.BroadcastResponse");
|
|
7936
|
+
__publicField(_BroadcastResponse, "fields", proto3.util.newFieldList(() => []));
|
|
7937
|
+
let BroadcastResponse = _BroadcastResponse;
|
|
7849
7938
|
const _AttachPresenceRequest = class _AttachPresenceRequest extends Message {
|
|
7850
7939
|
constructor(data) {
|
|
7851
7940
|
super();
|
|
@@ -8085,6 +8174,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
8085
8174
|
const _RefreshPresenceResponse = class _RefreshPresenceResponse extends Message {
|
|
8086
8175
|
constructor(data) {
|
|
8087
8176
|
super();
|
|
8177
|
+
/**
|
|
8178
|
+
* @generated from field: int64 count = 1;
|
|
8179
|
+
*/
|
|
8180
|
+
__publicField(this, "count", protoInt64.zero);
|
|
8088
8181
|
proto3.util.initPartial(data, this);
|
|
8089
8182
|
}
|
|
8090
8183
|
static fromBinary(bytes, options) {
|
|
@@ -8102,7 +8195,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
8102
8195
|
};
|
|
8103
8196
|
__publicField(_RefreshPresenceResponse, "runtime", proto3);
|
|
8104
8197
|
__publicField(_RefreshPresenceResponse, "typeName", "yorkie.v1.RefreshPresenceResponse");
|
|
8105
|
-
__publicField(_RefreshPresenceResponse, "fields", proto3.util.newFieldList(() => [
|
|
8198
|
+
__publicField(_RefreshPresenceResponse, "fields", proto3.util.newFieldList(() => [
|
|
8199
|
+
{
|
|
8200
|
+
no: 1,
|
|
8201
|
+
name: "count",
|
|
8202
|
+
kind: "scalar",
|
|
8203
|
+
T: 3
|
|
8204
|
+
/* ScalarType.INT64 */
|
|
8205
|
+
}
|
|
8206
|
+
]));
|
|
8106
8207
|
let RefreshPresenceResponse = _RefreshPresenceResponse;
|
|
8107
8208
|
const _WatchPresenceRequest = class _WatchPresenceRequest extends Message {
|
|
8108
8209
|
constructor(data) {
|
|
@@ -8223,95 +8324,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
8223
8324
|
}
|
|
8224
8325
|
]));
|
|
8225
8326
|
let WatchPresenceInitialized = _WatchPresenceInitialized;
|
|
8226
|
-
const _BroadcastRequest = class _BroadcastRequest extends Message {
|
|
8227
|
-
constructor(data) {
|
|
8228
|
-
super();
|
|
8229
|
-
/**
|
|
8230
|
-
* @generated from field: string client_id = 1;
|
|
8231
|
-
*/
|
|
8232
|
-
__publicField(this, "clientId", "");
|
|
8233
|
-
/**
|
|
8234
|
-
* @generated from field: string document_id = 2;
|
|
8235
|
-
*/
|
|
8236
|
-
__publicField(this, "documentId", "");
|
|
8237
|
-
/**
|
|
8238
|
-
* @generated from field: string topic = 3;
|
|
8239
|
-
*/
|
|
8240
|
-
__publicField(this, "topic", "");
|
|
8241
|
-
/**
|
|
8242
|
-
* @generated from field: bytes payload = 4;
|
|
8243
|
-
*/
|
|
8244
|
-
__publicField(this, "payload", new Uint8Array(0));
|
|
8245
|
-
proto3.util.initPartial(data, this);
|
|
8246
|
-
}
|
|
8247
|
-
static fromBinary(bytes, options) {
|
|
8248
|
-
return new _BroadcastRequest().fromBinary(bytes, options);
|
|
8249
|
-
}
|
|
8250
|
-
static fromJson(jsonValue, options) {
|
|
8251
|
-
return new _BroadcastRequest().fromJson(jsonValue, options);
|
|
8252
|
-
}
|
|
8253
|
-
static fromJsonString(jsonString, options) {
|
|
8254
|
-
return new _BroadcastRequest().fromJsonString(jsonString, options);
|
|
8255
|
-
}
|
|
8256
|
-
static equals(a, b) {
|
|
8257
|
-
return proto3.util.equals(_BroadcastRequest, a, b);
|
|
8258
|
-
}
|
|
8259
|
-
};
|
|
8260
|
-
__publicField(_BroadcastRequest, "runtime", proto3);
|
|
8261
|
-
__publicField(_BroadcastRequest, "typeName", "yorkie.v1.BroadcastRequest");
|
|
8262
|
-
__publicField(_BroadcastRequest, "fields", proto3.util.newFieldList(() => [
|
|
8263
|
-
{
|
|
8264
|
-
no: 1,
|
|
8265
|
-
name: "client_id",
|
|
8266
|
-
kind: "scalar",
|
|
8267
|
-
T: 9
|
|
8268
|
-
/* ScalarType.STRING */
|
|
8269
|
-
},
|
|
8270
|
-
{
|
|
8271
|
-
no: 2,
|
|
8272
|
-
name: "document_id",
|
|
8273
|
-
kind: "scalar",
|
|
8274
|
-
T: 9
|
|
8275
|
-
/* ScalarType.STRING */
|
|
8276
|
-
},
|
|
8277
|
-
{
|
|
8278
|
-
no: 3,
|
|
8279
|
-
name: "topic",
|
|
8280
|
-
kind: "scalar",
|
|
8281
|
-
T: 9
|
|
8282
|
-
/* ScalarType.STRING */
|
|
8283
|
-
},
|
|
8284
|
-
{
|
|
8285
|
-
no: 4,
|
|
8286
|
-
name: "payload",
|
|
8287
|
-
kind: "scalar",
|
|
8288
|
-
T: 12
|
|
8289
|
-
/* ScalarType.BYTES */
|
|
8290
|
-
}
|
|
8291
|
-
]));
|
|
8292
|
-
let BroadcastRequest = _BroadcastRequest;
|
|
8293
|
-
const _BroadcastResponse = class _BroadcastResponse extends Message {
|
|
8294
|
-
constructor(data) {
|
|
8295
|
-
super();
|
|
8296
|
-
proto3.util.initPartial(data, this);
|
|
8297
|
-
}
|
|
8298
|
-
static fromBinary(bytes, options) {
|
|
8299
|
-
return new _BroadcastResponse().fromBinary(bytes, options);
|
|
8300
|
-
}
|
|
8301
|
-
static fromJson(jsonValue, options) {
|
|
8302
|
-
return new _BroadcastResponse().fromJson(jsonValue, options);
|
|
8303
|
-
}
|
|
8304
|
-
static fromJsonString(jsonString, options) {
|
|
8305
|
-
return new _BroadcastResponse().fromJsonString(jsonString, options);
|
|
8306
|
-
}
|
|
8307
|
-
static equals(a, b) {
|
|
8308
|
-
return proto3.util.equals(_BroadcastResponse, a, b);
|
|
8309
|
-
}
|
|
8310
|
-
};
|
|
8311
|
-
__publicField(_BroadcastResponse, "runtime", proto3);
|
|
8312
|
-
__publicField(_BroadcastResponse, "typeName", "yorkie.v1.BroadcastResponse");
|
|
8313
|
-
__publicField(_BroadcastResponse, "fields", proto3.util.newFieldList(() => []));
|
|
8314
|
-
let BroadcastResponse = _BroadcastResponse;
|
|
8315
8327
|
const YorkieService = {
|
|
8316
8328
|
typeName: "yorkie.v1.YorkieService",
|
|
8317
8329
|
methods: {
|
|
@@ -8378,6 +8390,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
8378
8390
|
O: WatchDocumentResponse,
|
|
8379
8391
|
kind: MethodKind.ServerStreaming
|
|
8380
8392
|
},
|
|
8393
|
+
/**
|
|
8394
|
+
* @generated from rpc yorkie.v1.YorkieService.Broadcast
|
|
8395
|
+
*/
|
|
8396
|
+
broadcast: {
|
|
8397
|
+
name: "Broadcast",
|
|
8398
|
+
I: BroadcastRequest,
|
|
8399
|
+
O: BroadcastResponse,
|
|
8400
|
+
kind: MethodKind.Unary
|
|
8401
|
+
},
|
|
8381
8402
|
/**
|
|
8382
8403
|
* @generated from rpc yorkie.v1.YorkieService.AttachPresence
|
|
8383
8404
|
*/
|
|
@@ -8413,15 +8434,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
8413
8434
|
I: WatchPresenceRequest,
|
|
8414
8435
|
O: WatchPresenceResponse,
|
|
8415
8436
|
kind: MethodKind.ServerStreaming
|
|
8416
|
-
},
|
|
8417
|
-
/**
|
|
8418
|
-
* @generated from rpc yorkie.v1.YorkieService.Broadcast
|
|
8419
|
-
*/
|
|
8420
|
-
broadcast: {
|
|
8421
|
-
name: "Broadcast",
|
|
8422
|
-
I: BroadcastRequest,
|
|
8423
|
-
O: BroadcastResponse,
|
|
8424
|
-
kind: MethodKind.Unary
|
|
8425
8437
|
}
|
|
8426
8438
|
}
|
|
8427
8439
|
};
|
|
@@ -9130,9 +9142,30 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
9130
9142
|
}
|
|
9131
9143
|
return node;
|
|
9132
9144
|
}
|
|
9145
|
+
/**
|
|
9146
|
+
* `deepcopy` creates a deep copy of this ElementRHT.
|
|
9147
|
+
*/
|
|
9148
|
+
deepcopy() {
|
|
9149
|
+
const clone = ElementRHT.create();
|
|
9150
|
+
for (const [, node] of this.nodeMapByCreatedAt) {
|
|
9151
|
+
clone.nodeMapByCreatedAt.set(
|
|
9152
|
+
node.getValue().getCreatedAt().toIDString(),
|
|
9153
|
+
ElementRHTNode.of(node.getStrKey(), node.getValue().deepcopy())
|
|
9154
|
+
);
|
|
9155
|
+
}
|
|
9156
|
+
for (const [key, node] of this.nodeMapByKey) {
|
|
9157
|
+
clone.nodeMapByKey.set(
|
|
9158
|
+
key,
|
|
9159
|
+
clone.nodeMapByCreatedAt.get(
|
|
9160
|
+
node.getValue().getCreatedAt().toIDString()
|
|
9161
|
+
)
|
|
9162
|
+
);
|
|
9163
|
+
}
|
|
9164
|
+
return clone;
|
|
9165
|
+
}
|
|
9133
9166
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
9134
9167
|
*[Symbol.iterator]() {
|
|
9135
|
-
for (const [, node] of this.
|
|
9168
|
+
for (const [, node] of this.nodeMapByCreatedAt) {
|
|
9136
9169
|
yield node;
|
|
9137
9170
|
}
|
|
9138
9171
|
}
|
|
@@ -9266,12 +9299,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
9266
9299
|
*/
|
|
9267
9300
|
toSortedJSON() {
|
|
9268
9301
|
var _a2;
|
|
9269
|
-
const keys =
|
|
9302
|
+
const keys = /* @__PURE__ */ new Set();
|
|
9270
9303
|
for (const [key] of this) {
|
|
9271
|
-
keys.
|
|
9304
|
+
keys.add(key);
|
|
9272
9305
|
}
|
|
9273
9306
|
const json = [];
|
|
9274
|
-
for (const key of keys.sort()) {
|
|
9307
|
+
for (const key of Array.from(keys).sort()) {
|
|
9275
9308
|
const node = (_a2 = this.memberNodes.get(key)) == null ? void 0 : _a2.getValue();
|
|
9276
9309
|
json.push(`"${escapeString(key)}":${node.toSortedJSON()}`);
|
|
9277
9310
|
}
|
|
@@ -9288,14 +9321,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
9288
9321
|
*/
|
|
9289
9322
|
deepcopy() {
|
|
9290
9323
|
const clone = CRDTObject.create(this.getCreatedAt());
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
node.getValue().deepcopy(),
|
|
9295
|
-
this.getPositionedAt()
|
|
9296
|
-
);
|
|
9297
|
-
}
|
|
9298
|
-
clone.remove(this.getRemovedAt());
|
|
9324
|
+
clone.memberNodes = this.memberNodes.deepcopy();
|
|
9325
|
+
clone.setRemovedAt(this.getRemovedAt());
|
|
9326
|
+
clone.setMovedAt(this.getMovedAt());
|
|
9299
9327
|
return clone;
|
|
9300
9328
|
}
|
|
9301
9329
|
/**
|
|
@@ -9316,14 +9344,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
9316
9344
|
* `[Symbol.iterator]` returns an iterator for the entries in this object.
|
|
9317
9345
|
*/
|
|
9318
9346
|
*[Symbol.iterator]() {
|
|
9319
|
-
const keySet = /* @__PURE__ */ new Set();
|
|
9320
9347
|
for (const node of this.memberNodes) {
|
|
9321
|
-
if (
|
|
9322
|
-
|
|
9323
|
-
if (!node.isRemoved()) {
|
|
9324
|
-
yield [node.getStrKey(), node.getValue()];
|
|
9325
|
-
}
|
|
9348
|
+
if (node.isRemoved()) {
|
|
9349
|
+
continue;
|
|
9326
9350
|
}
|
|
9351
|
+
yield [node.getStrKey(), node.getValue()];
|
|
9327
9352
|
}
|
|
9328
9353
|
}
|
|
9329
9354
|
}
|
|
@@ -11539,7 +11564,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11539
11564
|
node.getValue().deepcopy()
|
|
11540
11565
|
);
|
|
11541
11566
|
}
|
|
11542
|
-
clone.
|
|
11567
|
+
clone.setRemovedAt(this.getRemovedAt());
|
|
11568
|
+
clone.setMovedAt(this.getMovedAt());
|
|
11543
11569
|
return clone;
|
|
11544
11570
|
}
|
|
11545
11571
|
}
|
|
@@ -12548,12 +12574,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12548
12574
|
* `deepcopy` copies itself deeply.
|
|
12549
12575
|
*/
|
|
12550
12576
|
deepcopy() {
|
|
12551
|
-
const
|
|
12577
|
+
const clone = new CRDTText(
|
|
12552
12578
|
this.rgaTreeSplit.deepcopy(),
|
|
12553
12579
|
this.getCreatedAt()
|
|
12554
12580
|
);
|
|
12555
|
-
|
|
12556
|
-
|
|
12581
|
+
clone.setRemovedAt(this.getRemovedAt());
|
|
12582
|
+
clone.setMovedAt(this.getMovedAt());
|
|
12583
|
+
return clone;
|
|
12557
12584
|
}
|
|
12558
12585
|
/**
|
|
12559
12586
|
* `findIndexesFromRange` returns pair of integer offsets of the given range.
|
|
@@ -12784,15 +12811,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12784
12811
|
const ElementPaddingSize = 2;
|
|
12785
12812
|
const DefaultRootType = "root";
|
|
12786
12813
|
const DefaultTextType = "text";
|
|
12787
|
-
function addSizeOfLeftSiblings(parent, offset) {
|
|
12814
|
+
function addSizeOfLeftSiblings(parent, offset, includeRemoved = false) {
|
|
12788
12815
|
let acc = 0;
|
|
12789
|
-
const siblings = parent.children;
|
|
12816
|
+
const siblings = includeRemoved ? parent.allChildren : parent.children;
|
|
12790
12817
|
for (let i = 0; i < offset; i++) {
|
|
12791
12818
|
const leftSibling = siblings[i];
|
|
12792
|
-
if (!leftSibling || leftSibling.isRemoved) {
|
|
12819
|
+
if (!leftSibling || !includeRemoved && leftSibling.isRemoved) {
|
|
12793
12820
|
continue;
|
|
12794
12821
|
}
|
|
12795
|
-
acc += leftSibling.paddedSize;
|
|
12822
|
+
acc += leftSibling.paddedSize(includeRemoved);
|
|
12796
12823
|
}
|
|
12797
12824
|
return acc;
|
|
12798
12825
|
}
|
|
@@ -12801,44 +12828,55 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12801
12828
|
__publicField(this, "type");
|
|
12802
12829
|
__publicField(this, "parent");
|
|
12803
12830
|
__publicField(this, "_children");
|
|
12804
|
-
__publicField(this, "
|
|
12831
|
+
__publicField(this, "visibleSize");
|
|
12832
|
+
__publicField(this, "totalSize");
|
|
12805
12833
|
this.type = type;
|
|
12806
|
-
this.
|
|
12834
|
+
this.visibleSize = 0;
|
|
12835
|
+
this.totalSize = 0;
|
|
12807
12836
|
this._children = children;
|
|
12808
12837
|
if (this.isText && this._children.length > 0) {
|
|
12809
12838
|
throw new YorkieError(Code.ErrRefused, "Text node cannot have children");
|
|
12810
12839
|
}
|
|
12811
12840
|
}
|
|
12812
12841
|
/**
|
|
12813
|
-
* `updateAncestorsSize` updates the size of the ancestors.
|
|
12814
|
-
* the size of the node is changed.
|
|
12842
|
+
* `updateAncestorsSize` updates the size of the ancestors.
|
|
12843
|
+
* It is used when the size of the node is changed.
|
|
12844
|
+
* If includeRemoved is true, it updates ancestors totalSize including removed nodes.
|
|
12815
12845
|
*/
|
|
12816
|
-
updateAncestorsSize() {
|
|
12846
|
+
updateAncestorsSize(delta, includeRemoved = false) {
|
|
12817
12847
|
let parent = this.parent;
|
|
12818
|
-
const sign = this.isRemoved ? -1 : 1;
|
|
12819
12848
|
while (parent) {
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
|
|
12849
|
+
if (includeRemoved) {
|
|
12850
|
+
parent.totalSize += delta;
|
|
12851
|
+
} else {
|
|
12852
|
+
parent.visibleSize += delta;
|
|
12853
|
+
if (parent.isRemoved) {
|
|
12854
|
+
break;
|
|
12855
|
+
}
|
|
12823
12856
|
}
|
|
12824
12857
|
parent = parent.parent;
|
|
12825
12858
|
}
|
|
12826
12859
|
}
|
|
12827
12860
|
/**
|
|
12828
|
-
* `
|
|
12861
|
+
* `UpdateDescendantsSize` updates the size of the descendants. It is used when
|
|
12829
12862
|
* the tree is newly created and the size of the descendants is not calculated.
|
|
12863
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
12830
12864
|
*/
|
|
12831
|
-
updateDescendantsSize() {
|
|
12865
|
+
updateDescendantsSize(includeRemoved = false) {
|
|
12832
12866
|
let size = 0;
|
|
12833
12867
|
for (const child of this._children) {
|
|
12834
|
-
const childSize = child.updateDescendantsSize();
|
|
12835
|
-
if (child.isRemoved) {
|
|
12868
|
+
const childSize = child.updateDescendantsSize(includeRemoved);
|
|
12869
|
+
if (!includeRemoved && child.isRemoved) {
|
|
12836
12870
|
continue;
|
|
12837
12871
|
}
|
|
12838
12872
|
size += childSize;
|
|
12839
12873
|
}
|
|
12840
|
-
|
|
12841
|
-
|
|
12874
|
+
if (includeRemoved) {
|
|
12875
|
+
this.totalSize += size;
|
|
12876
|
+
} else {
|
|
12877
|
+
this.visibleSize += size;
|
|
12878
|
+
}
|
|
12879
|
+
return this.paddedSize(includeRemoved);
|
|
12842
12880
|
}
|
|
12843
12881
|
/**
|
|
12844
12882
|
* `isText` returns true if the node is a text node.
|
|
@@ -12847,10 +12885,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12847
12885
|
return this.type === DefaultTextType;
|
|
12848
12886
|
}
|
|
12849
12887
|
/**
|
|
12850
|
-
* `paddedSize` returns the
|
|
12888
|
+
* `paddedSize` returns the length of the node including padding.
|
|
12889
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
12851
12890
|
*/
|
|
12852
|
-
|
|
12853
|
-
|
|
12891
|
+
paddedSize(includeRemoved = false) {
|
|
12892
|
+
let size = this.visibleSize;
|
|
12893
|
+
if (includeRemoved) {
|
|
12894
|
+
size = this.totalSize;
|
|
12895
|
+
}
|
|
12896
|
+
if (!this.isText) {
|
|
12897
|
+
size += ElementPaddingSize;
|
|
12898
|
+
}
|
|
12899
|
+
return size;
|
|
12854
12900
|
}
|
|
12855
12901
|
/**
|
|
12856
12902
|
* `isAncenstorOf` returns true if the node is an ancestor of the given node.
|
|
@@ -12885,7 +12931,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12885
12931
|
*/
|
|
12886
12932
|
splitText(offset, absOffset) {
|
|
12887
12933
|
const diff = { data: 0, meta: 0 };
|
|
12888
|
-
if (offset === 0 || offset === this.
|
|
12934
|
+
if (offset === 0 || offset === this.visibleSize) {
|
|
12889
12935
|
return [void 0, diff];
|
|
12890
12936
|
}
|
|
12891
12937
|
const leftValue = this.value.slice(0, offset);
|
|
@@ -12943,7 +12989,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12943
12989
|
this._children.push(...newNode);
|
|
12944
12990
|
for (const node of newNode) {
|
|
12945
12991
|
node.parent = this;
|
|
12946
|
-
node.updateAncestorsSize();
|
|
12992
|
+
node.updateAncestorsSize(node.paddedSize());
|
|
12993
|
+
node.updateAncestorsSize(node.paddedSize(true), true);
|
|
12947
12994
|
}
|
|
12948
12995
|
}
|
|
12949
12996
|
/**
|
|
@@ -12971,7 +13018,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12971
13018
|
throw new YorkieError(Code.ErrInvalidArgument, "child not found");
|
|
12972
13019
|
}
|
|
12973
13020
|
this.insertAtInternal(newNode, offset);
|
|
12974
|
-
newNode.updateAncestorsSize();
|
|
13021
|
+
newNode.updateAncestorsSize(newNode.paddedSize());
|
|
13022
|
+
newNode.updateAncestorsSize(newNode.paddedSize(true), true);
|
|
12975
13023
|
}
|
|
12976
13024
|
/**
|
|
12977
13025
|
* `insertAfter` inserts the given node after the given child.
|
|
@@ -12985,7 +13033,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12985
13033
|
throw new YorkieError(Code.ErrInvalidArgument, "child not found");
|
|
12986
13034
|
}
|
|
12987
13035
|
this.insertAtInternal(newNode, offset + 1);
|
|
12988
|
-
newNode.updateAncestorsSize();
|
|
13036
|
+
newNode.updateAncestorsSize(newNode.paddedSize());
|
|
13037
|
+
newNode.updateAncestorsSize(newNode.paddedSize(true), true);
|
|
12989
13038
|
}
|
|
12990
13039
|
/**
|
|
12991
13040
|
* `insertAt` inserts the given node at the given offset.
|
|
@@ -12995,10 +13044,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12995
13044
|
throw new YorkieError(Code.ErrRefused, "Text node cannot have children");
|
|
12996
13045
|
}
|
|
12997
13046
|
this.insertAtInternal(newNode, offset);
|
|
12998
|
-
newNode.updateAncestorsSize();
|
|
13047
|
+
newNode.updateAncestorsSize(newNode.paddedSize());
|
|
13048
|
+
newNode.updateAncestorsSize(newNode.paddedSize(true), true);
|
|
12999
13049
|
}
|
|
13000
13050
|
/**
|
|
13001
13051
|
* `removeChild` removes the given child.
|
|
13052
|
+
* In this method, the child is physically removed from the tree.
|
|
13002
13053
|
*/
|
|
13003
13054
|
removeChild(child) {
|
|
13004
13055
|
if (this.isText) {
|
|
@@ -13009,6 +13060,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13009
13060
|
throw new YorkieError(Code.ErrInvalidArgument, "child not found");
|
|
13010
13061
|
}
|
|
13011
13062
|
this._children.splice(offset, 1);
|
|
13063
|
+
child.updateAncestorsSize(-child.paddedSize(true), true);
|
|
13012
13064
|
child.parent = void 0;
|
|
13013
13065
|
}
|
|
13014
13066
|
/**
|
|
@@ -13019,17 +13071,26 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13019
13071
|
const prvSize = this.getDataSize();
|
|
13020
13072
|
const clone = this.cloneElement(issueTimeTicket);
|
|
13021
13073
|
this.parent.insertAfterInternal(clone, this);
|
|
13022
|
-
clone.updateAncestorsSize();
|
|
13074
|
+
clone.updateAncestorsSize(clone.paddedSize());
|
|
13075
|
+
clone.updateAncestorsSize(clone.paddedSize(true), true);
|
|
13023
13076
|
const leftChildren = this.children.slice(0, offset);
|
|
13024
13077
|
const rightChildren = this.children.slice(offset);
|
|
13025
13078
|
this._children = leftChildren;
|
|
13026
13079
|
clone._children = rightChildren;
|
|
13027
|
-
this.
|
|
13028
|
-
(acc, child) => acc + child.paddedSize,
|
|
13080
|
+
this.visibleSize = this._children.reduce(
|
|
13081
|
+
(acc, child) => acc + child.paddedSize(),
|
|
13082
|
+
0
|
|
13083
|
+
);
|
|
13084
|
+
this.totalSize = this._children.reduce(
|
|
13085
|
+
(acc, child) => acc + child.paddedSize(true),
|
|
13086
|
+
0
|
|
13087
|
+
);
|
|
13088
|
+
clone.visibleSize = clone._children.reduce(
|
|
13089
|
+
(acc, child) => acc + child.paddedSize(true),
|
|
13029
13090
|
0
|
|
13030
13091
|
);
|
|
13031
|
-
clone.
|
|
13032
|
-
(acc, child) => acc + child.paddedSize,
|
|
13092
|
+
clone.totalSize = clone._children.reduce(
|
|
13093
|
+
(acc, child) => acc + child.paddedSize(true),
|
|
13033
13094
|
0
|
|
13034
13095
|
);
|
|
13035
13096
|
for (const child of clone._children) {
|
|
@@ -13066,12 +13127,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13066
13127
|
}
|
|
13067
13128
|
/**
|
|
13068
13129
|
* findOffset returns the offset of the given node in the children.
|
|
13069
|
-
*
|
|
13130
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
13070
13131
|
*/
|
|
13071
|
-
findOffset(node) {
|
|
13132
|
+
findOffset(node, includeRemoved = false) {
|
|
13072
13133
|
if (this.isText) {
|
|
13073
13134
|
throw new YorkieError(Code.ErrRefused, "Text node cannot have children");
|
|
13074
13135
|
}
|
|
13136
|
+
if (includeRemoved) {
|
|
13137
|
+
return this._children.indexOf(node);
|
|
13138
|
+
}
|
|
13075
13139
|
if (node.isRemoved) {
|
|
13076
13140
|
const index = this._children.indexOf(node);
|
|
13077
13141
|
const refined = this.allChildren.splice(0, index).filter((node2) => !node2.isRemoved).length;
|
|
@@ -13116,35 +13180,38 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13116
13180
|
TokenType2["Text"] = "Text";
|
|
13117
13181
|
return TokenType2;
|
|
13118
13182
|
})(TokenType || {});
|
|
13119
|
-
function tokensBetween(root, from, to, callback) {
|
|
13183
|
+
function tokensBetween(root, from, to, callback, includeRemoved = false) {
|
|
13120
13184
|
if (from > to) {
|
|
13121
13185
|
throw new YorkieError(
|
|
13122
13186
|
Code.ErrInvalidArgument,
|
|
13123
13187
|
`from is greater than to: ${from} > ${to}`
|
|
13124
13188
|
);
|
|
13125
13189
|
}
|
|
13126
|
-
|
|
13190
|
+
const rootSize = includeRemoved ? root.totalSize : root.visibleSize;
|
|
13191
|
+
if (from > rootSize) {
|
|
13127
13192
|
throw new YorkieError(
|
|
13128
13193
|
Code.ErrInvalidArgument,
|
|
13129
|
-
`from is out of range: ${from} > ${
|
|
13194
|
+
`from is out of range: ${from} > ${rootSize}`
|
|
13130
13195
|
);
|
|
13131
13196
|
}
|
|
13132
|
-
if (to >
|
|
13197
|
+
if (to > rootSize) {
|
|
13133
13198
|
throw new YorkieError(
|
|
13134
13199
|
Code.ErrInvalidArgument,
|
|
13135
|
-
`to is out of range: ${to} > ${
|
|
13200
|
+
`to is out of range: ${to} > ${rootSize}`
|
|
13136
13201
|
);
|
|
13137
13202
|
}
|
|
13138
13203
|
if (from === to) {
|
|
13139
13204
|
return;
|
|
13140
13205
|
}
|
|
13141
13206
|
let pos = 0;
|
|
13142
|
-
|
|
13143
|
-
|
|
13207
|
+
const children = includeRemoved ? root._children : root.children;
|
|
13208
|
+
for (const child of children) {
|
|
13209
|
+
if (from - child.paddedSize(includeRemoved) < pos && pos < to) {
|
|
13144
13210
|
const fromChild = child.isText ? from - pos : from - pos - 1;
|
|
13145
13211
|
const toChild = child.isText ? to - pos : to - pos - 1;
|
|
13212
|
+
const childSize = includeRemoved ? child.totalSize : child.visibleSize;
|
|
13146
13213
|
const startContained = !child.isText && fromChild < 0;
|
|
13147
|
-
const endContained = !child.isText && toChild >
|
|
13214
|
+
const endContained = !child.isText && toChild > childSize;
|
|
13148
13215
|
if (child.isText || startContained) {
|
|
13149
13216
|
callback(
|
|
13150
13217
|
[
|
|
@@ -13158,8 +13225,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13158
13225
|
tokensBetween(
|
|
13159
13226
|
child,
|
|
13160
13227
|
Math.max(0, fromChild),
|
|
13161
|
-
Math.min(toChild,
|
|
13162
|
-
callback
|
|
13228
|
+
Math.min(toChild, childSize),
|
|
13229
|
+
callback,
|
|
13230
|
+
includeRemoved
|
|
13163
13231
|
);
|
|
13164
13232
|
if (endContained) {
|
|
13165
13233
|
callback([
|
|
@@ -13169,7 +13237,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13169
13237
|
], endContained);
|
|
13170
13238
|
}
|
|
13171
13239
|
}
|
|
13172
|
-
pos += child.paddedSize;
|
|
13240
|
+
pos += child.paddedSize(includeRemoved);
|
|
13173
13241
|
}
|
|
13174
13242
|
}
|
|
13175
13243
|
function traverse(node, callback, depth = 0) {
|
|
@@ -13185,10 +13253,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13185
13253
|
callback(node, depth);
|
|
13186
13254
|
}
|
|
13187
13255
|
function findTreePos(node, index, preferText = true) {
|
|
13188
|
-
if (index > node.
|
|
13256
|
+
if (index > node.visibleSize) {
|
|
13189
13257
|
throw new YorkieError(
|
|
13190
13258
|
Code.ErrInvalidArgument,
|
|
13191
|
-
`index is out of range: ${index} > ${node.
|
|
13259
|
+
`index is out of range: ${index} > ${node.visibleSize}`
|
|
13192
13260
|
);
|
|
13193
13261
|
}
|
|
13194
13262
|
if (node.isText) {
|
|
@@ -13197,20 +13265,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13197
13265
|
let offset = 0;
|
|
13198
13266
|
let pos = 0;
|
|
13199
13267
|
for (const child of node.children) {
|
|
13200
|
-
if (preferText && child.isText && child.
|
|
13268
|
+
if (preferText && child.isText && child.visibleSize >= index - pos) {
|
|
13201
13269
|
return findTreePos(child, index - pos, preferText);
|
|
13202
13270
|
}
|
|
13203
13271
|
if (index === pos) {
|
|
13204
13272
|
return { node, offset };
|
|
13205
13273
|
}
|
|
13206
|
-
if (!preferText && child.paddedSize === index - pos) {
|
|
13274
|
+
if (!preferText && child.paddedSize() === index - pos) {
|
|
13207
13275
|
return { node, offset: offset + 1 };
|
|
13208
13276
|
}
|
|
13209
|
-
if (child.paddedSize > index - pos) {
|
|
13277
|
+
if (child.paddedSize() > index - pos) {
|
|
13210
13278
|
const skipOpenSize = 1;
|
|
13211
13279
|
return findTreePos(child, index - pos - skipOpenSize, preferText);
|
|
13212
13280
|
}
|
|
13213
|
-
pos += child.paddedSize;
|
|
13281
|
+
pos += child.paddedSize();
|
|
13214
13282
|
offset += 1;
|
|
13215
13283
|
}
|
|
13216
13284
|
return { node, offset };
|
|
@@ -13222,13 +13290,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13222
13290
|
return findLeftmost(node.children[0]);
|
|
13223
13291
|
}
|
|
13224
13292
|
function findTextPos(node, pathElement) {
|
|
13225
|
-
if (node.
|
|
13293
|
+
if (node.visibleSize < pathElement) {
|
|
13226
13294
|
throw new YorkieError(Code.ErrInvalidArgument, "unacceptable path");
|
|
13227
13295
|
}
|
|
13228
13296
|
for (let i = 0; i < node.children.length; i++) {
|
|
13229
13297
|
const child = node.children[i];
|
|
13230
|
-
if (child.
|
|
13231
|
-
pathElement -= child.
|
|
13298
|
+
if (child.visibleSize < pathElement) {
|
|
13299
|
+
pathElement -= child.visibleSize;
|
|
13232
13300
|
} else {
|
|
13233
13301
|
node = child;
|
|
13234
13302
|
break;
|
|
@@ -13243,9 +13311,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13243
13311
|
}
|
|
13244
13312
|
/**
|
|
13245
13313
|
* `tokensBetween` returns the tokens between the given range.
|
|
13314
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
13246
13315
|
*/
|
|
13247
|
-
tokensBetween(from, to, callback) {
|
|
13248
|
-
tokensBetween(this.root, from, to, callback);
|
|
13316
|
+
tokensBetween(from, to, callback, includeRemoved = false) {
|
|
13317
|
+
tokensBetween(this.root, from, to, callback, includeRemoved);
|
|
13249
13318
|
}
|
|
13250
13319
|
/**
|
|
13251
13320
|
* `traverse` traverses the tree with postorder traversal.
|
|
@@ -13344,7 +13413,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13344
13413
|
* `getSize` returns the size of the tree.
|
|
13345
13414
|
*/
|
|
13346
13415
|
get size() {
|
|
13347
|
-
return this.root.
|
|
13416
|
+
return this.root.visibleSize;
|
|
13348
13417
|
}
|
|
13349
13418
|
/**
|
|
13350
13419
|
* `findPostorderRight` finds right node of the given tree position with
|
|
@@ -13353,7 +13422,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13353
13422
|
findPostorderRight(treePos) {
|
|
13354
13423
|
const { node, offset } = treePos;
|
|
13355
13424
|
if (node.isText) {
|
|
13356
|
-
if (node.
|
|
13425
|
+
if (node.visibleSize === offset) {
|
|
13357
13426
|
const nextSibling = node.nextSibling;
|
|
13358
13427
|
if (nextSibling) {
|
|
13359
13428
|
return nextSibling;
|
|
@@ -13369,8 +13438,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13369
13438
|
}
|
|
13370
13439
|
/**
|
|
13371
13440
|
* `indexOf` returns the index of the given tree position.
|
|
13441
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
13372
13442
|
*/
|
|
13373
|
-
indexOf(pos) {
|
|
13443
|
+
indexOf(pos, includeRemoved = false) {
|
|
13374
13444
|
let { node } = pos;
|
|
13375
13445
|
const { offset } = pos;
|
|
13376
13446
|
let size = 0;
|
|
@@ -13378,22 +13448,22 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13378
13448
|
if (node.isText) {
|
|
13379
13449
|
size += offset;
|
|
13380
13450
|
const parent = node.parent;
|
|
13381
|
-
const offsetOfNode = parent.findOffset(node);
|
|
13451
|
+
const offsetOfNode = parent.findOffset(node, includeRemoved);
|
|
13382
13452
|
if (offsetOfNode === -1) {
|
|
13383
13453
|
throw new YorkieError(Code.ErrInvalidArgument, "invalid pos");
|
|
13384
13454
|
}
|
|
13385
|
-
size += addSizeOfLeftSiblings(parent, offsetOfNode);
|
|
13455
|
+
size += addSizeOfLeftSiblings(parent, offsetOfNode, includeRemoved);
|
|
13386
13456
|
node = node.parent;
|
|
13387
13457
|
} else {
|
|
13388
|
-
size += addSizeOfLeftSiblings(node, offset);
|
|
13458
|
+
size += addSizeOfLeftSiblings(node, offset, includeRemoved);
|
|
13389
13459
|
}
|
|
13390
13460
|
while (node == null ? void 0 : node.parent) {
|
|
13391
13461
|
const parent = node.parent;
|
|
13392
|
-
const offsetOfNode = parent.findOffset(node);
|
|
13462
|
+
const offsetOfNode = parent.findOffset(node, includeRemoved);
|
|
13393
13463
|
if (offsetOfNode === -1) {
|
|
13394
13464
|
throw new YorkieError(Code.ErrInvalidArgument, "invalid pos");
|
|
13395
13465
|
}
|
|
13396
|
-
size += addSizeOfLeftSiblings(parent, offsetOfNode);
|
|
13466
|
+
size += addSizeOfLeftSiblings(parent, offsetOfNode, includeRemoved);
|
|
13397
13467
|
depth++;
|
|
13398
13468
|
node = node.parent;
|
|
13399
13469
|
}
|
|
@@ -13950,7 +14020,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13950
14020
|
const clone = new CRDTTreeNode(this.id, this.type);
|
|
13951
14021
|
clone.removedAt = this.removedAt;
|
|
13952
14022
|
clone._value = this._value;
|
|
13953
|
-
clone.
|
|
14023
|
+
clone.visibleSize = this.visibleSize;
|
|
14024
|
+
clone.totalSize = this.totalSize;
|
|
13954
14025
|
clone.attrs = (_a2 = this.attrs) == null ? void 0 : _a2.deepcopy();
|
|
13955
14026
|
clone._children = this._children.map((child) => {
|
|
13956
14027
|
const childClone = child.deepcopy();
|
|
@@ -13984,7 +14055,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13984
14055
|
);
|
|
13985
14056
|
}
|
|
13986
14057
|
this._value = v;
|
|
13987
|
-
this.
|
|
14058
|
+
this.visibleSize = v.length;
|
|
14059
|
+
this.totalSize = v.length;
|
|
13988
14060
|
}
|
|
13989
14061
|
/**
|
|
13990
14062
|
* `isRemoved` returns whether the node is removed or not.
|
|
@@ -13996,13 +14068,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13996
14068
|
* `remove` marks the node as removed.
|
|
13997
14069
|
*/
|
|
13998
14070
|
remove(removedAt) {
|
|
13999
|
-
|
|
14000
|
-
if (!this.removedAt || this.removedAt.compare(removedAt) > 0) {
|
|
14071
|
+
if (!this.removedAt) {
|
|
14001
14072
|
this.removedAt = removedAt;
|
|
14073
|
+
this.updateAncestorsSize(-this.paddedSize());
|
|
14074
|
+
return true;
|
|
14002
14075
|
}
|
|
14003
|
-
if (
|
|
14004
|
-
this.
|
|
14076
|
+
if (removedAt.after(this.removedAt)) {
|
|
14077
|
+
this.removedAt = removedAt;
|
|
14005
14078
|
}
|
|
14079
|
+
return false;
|
|
14006
14080
|
}
|
|
14007
14081
|
/**
|
|
14008
14082
|
* `cloneText` clones this text node with the given offset.
|
|
@@ -14060,9 +14134,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14060
14134
|
/**
|
|
14061
14135
|
* `canDelete` checks if node is able to delete.
|
|
14062
14136
|
*/
|
|
14063
|
-
canDelete(editedAt,
|
|
14064
|
-
|
|
14065
|
-
|
|
14137
|
+
canDelete(editedAt, creationKnown, tombstoneKnown) {
|
|
14138
|
+
if (!creationKnown) {
|
|
14139
|
+
return false;
|
|
14140
|
+
}
|
|
14141
|
+
if (!this.removedAt) {
|
|
14142
|
+
return true;
|
|
14143
|
+
}
|
|
14144
|
+
if (!tombstoneKnown && (editedAt == null ? void 0 : editedAt.after(this.removedAt))) {
|
|
14145
|
+
return true;
|
|
14146
|
+
}
|
|
14147
|
+
return false;
|
|
14066
14148
|
}
|
|
14067
14149
|
/**
|
|
14068
14150
|
* `canStyle` checks if node is able to style.
|
|
@@ -14101,7 +14183,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14101
14183
|
getDataSize() {
|
|
14102
14184
|
const dataSize = { data: 0, meta: 0 };
|
|
14103
14185
|
if (this.isText) {
|
|
14104
|
-
dataSize.data += this.
|
|
14186
|
+
dataSize.data += this.visibleSize * 2;
|
|
14105
14187
|
}
|
|
14106
14188
|
if (this.id) {
|
|
14107
14189
|
dataSize.meta += TimeTicketSize;
|
|
@@ -14178,14 +14260,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14178
14260
|
return {
|
|
14179
14261
|
type: currentNode.type,
|
|
14180
14262
|
value: currentNode.value,
|
|
14181
|
-
|
|
14263
|
+
visibleSize: currentNode.visibleSize,
|
|
14182
14264
|
isRemoved: currentNode.isRemoved
|
|
14183
14265
|
};
|
|
14184
14266
|
}
|
|
14185
14267
|
return {
|
|
14186
14268
|
type: node.type,
|
|
14187
14269
|
children: node.children.map(toTestTreeNode),
|
|
14188
|
-
|
|
14270
|
+
visibleSize: node.visibleSize,
|
|
14189
14271
|
isRemoved: node.isRemoved
|
|
14190
14272
|
};
|
|
14191
14273
|
}
|
|
@@ -14413,18 +14495,25 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14413
14495
|
toBeMovedToFromParents.push(child);
|
|
14414
14496
|
}
|
|
14415
14497
|
}
|
|
14416
|
-
const
|
|
14417
|
-
let
|
|
14418
|
-
|
|
14419
|
-
|
|
14498
|
+
const isLocal = versionVector === void 0;
|
|
14499
|
+
let creationKnown = false;
|
|
14500
|
+
const createdAtVV = versionVector == null ? void 0 : versionVector.get(
|
|
14501
|
+
node.id.getCreatedAt().getActorID()
|
|
14502
|
+
);
|
|
14503
|
+
creationKnown = isLocal || createdAtVV !== void 0 && createdAtVV >= node.id.getCreatedAt().getLamport();
|
|
14504
|
+
let tombstoneKnown = false;
|
|
14505
|
+
if (node.removedAt) {
|
|
14506
|
+
const removedAtVV = versionVector == null ? void 0 : versionVector.get(node.removedAt.getActorID());
|
|
14507
|
+
tombstoneKnown = isLocal || removedAtVV !== void 0 && removedAtVV >= node.removedAt.getLamport();
|
|
14420
14508
|
}
|
|
14421
|
-
if (node.canDelete(editedAt,
|
|
14509
|
+
if (node.canDelete(editedAt, creationKnown, tombstoneKnown) || nodesToBeRemoved.includes(node.parent)) {
|
|
14422
14510
|
if (tokenType === TokenType.Text || tokenType === TokenType.Start) {
|
|
14423
14511
|
nodesToBeRemoved.push(node);
|
|
14424
14512
|
}
|
|
14425
14513
|
tokensToBeRemoved.push([node, tokenType]);
|
|
14426
14514
|
}
|
|
14427
|
-
}
|
|
14515
|
+
},
|
|
14516
|
+
true
|
|
14428
14517
|
);
|
|
14429
14518
|
const changes = this.makeDeletionChanges(
|
|
14430
14519
|
tokensToBeRemoved,
|
|
@@ -14510,7 +14599,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14510
14599
|
editT(range, contents, splitLevel, editedAt, issueTimeTicket) {
|
|
14511
14600
|
const fromPos = this.findPos(range[0]);
|
|
14512
14601
|
const toPos = this.findPos(range[1]);
|
|
14513
|
-
this.edit(
|
|
14602
|
+
return this.edit(
|
|
14514
14603
|
[fromPos, toPos],
|
|
14515
14604
|
contents,
|
|
14516
14605
|
splitLevel,
|
|
@@ -14670,7 +14759,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14670
14759
|
const nodeInfo = {
|
|
14671
14760
|
type: node.type,
|
|
14672
14761
|
parent: parentNode == null ? void 0 : parentNode.id.toTestString(),
|
|
14673
|
-
size: node.
|
|
14762
|
+
size: node.visibleSize,
|
|
14674
14763
|
id: node.id.toTestString(),
|
|
14675
14764
|
removedAt: (_a2 = node.removedAt) == null ? void 0 : _a2.toTestString(),
|
|
14676
14765
|
insPrev: (_b2 = node.insPrevID) == null ? void 0 : _b2.toTestString(),
|
|
@@ -14717,7 +14806,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14717
14806
|
*/
|
|
14718
14807
|
deepcopy() {
|
|
14719
14808
|
const root = this.getRoot();
|
|
14720
|
-
|
|
14809
|
+
const tree = new CRDTTree(root.deepcopy(), this.getCreatedAt());
|
|
14810
|
+
tree.setRemovedAt(this.getRemovedAt());
|
|
14811
|
+
tree.setMovedAt(this.getMovedAt());
|
|
14812
|
+
return tree;
|
|
14721
14813
|
}
|
|
14722
14814
|
/**
|
|
14723
14815
|
* `toPath` converts the given CRDTTreeNodeID to the path of the tree.
|
|
@@ -14731,13 +14823,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14731
14823
|
}
|
|
14732
14824
|
/**
|
|
14733
14825
|
* `toIndex` converts the given CRDTTreeNodeID to the index of the tree.
|
|
14826
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
14734
14827
|
*/
|
|
14735
|
-
toIndex(parentNode, leftNode) {
|
|
14736
|
-
const treePos = this.toTreePos(parentNode, leftNode);
|
|
14828
|
+
toIndex(parentNode, leftNode, includeRemoved = false) {
|
|
14829
|
+
const treePos = this.toTreePos(parentNode, leftNode, includeRemoved);
|
|
14737
14830
|
if (!treePos) {
|
|
14738
14831
|
return -1;
|
|
14739
14832
|
}
|
|
14740
|
-
return this.indexTree.indexOf(treePos);
|
|
14833
|
+
return this.indexTree.indexOf(treePos, includeRemoved);
|
|
14741
14834
|
}
|
|
14742
14835
|
/**
|
|
14743
14836
|
* `indexToPath` converts the given tree index to path.
|
|
@@ -14790,26 +14883,28 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14790
14883
|
}
|
|
14791
14884
|
/**
|
|
14792
14885
|
* `traverseInPosRange` traverses the tree in the given position range.
|
|
14886
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
14793
14887
|
*/
|
|
14794
|
-
traverseInPosRange(fromParent, fromLeft, toParent, toLeft, callback) {
|
|
14795
|
-
const fromIdx = this.toIndex(fromParent, fromLeft);
|
|
14796
|
-
const toIdx = this.toIndex(toParent, toLeft);
|
|
14797
|
-
|
|
14888
|
+
traverseInPosRange(fromParent, fromLeft, toParent, toLeft, callback, includeRemoved = false) {
|
|
14889
|
+
const fromIdx = this.toIndex(fromParent, fromLeft, includeRemoved);
|
|
14890
|
+
const toIdx = this.toIndex(toParent, toLeft, includeRemoved);
|
|
14891
|
+
this.indexTree.tokensBetween(fromIdx, toIdx, callback, includeRemoved);
|
|
14798
14892
|
}
|
|
14799
14893
|
/**
|
|
14800
14894
|
* `toTreePos` converts the given nodes to the position of the IndexTree.
|
|
14895
|
+
* If includeRemoved is true, it includes removed nodes in the calculation.
|
|
14801
14896
|
*/
|
|
14802
|
-
toTreePos(parentNode, leftNode) {
|
|
14897
|
+
toTreePos(parentNode, leftNode, includeRemoved = false) {
|
|
14803
14898
|
if (!parentNode || !leftNode) {
|
|
14804
14899
|
return;
|
|
14805
14900
|
}
|
|
14806
|
-
if (parentNode.isRemoved) {
|
|
14901
|
+
if (!includeRemoved && parentNode.isRemoved) {
|
|
14807
14902
|
let childNode;
|
|
14808
14903
|
while (parentNode.isRemoved) {
|
|
14809
14904
|
childNode = parentNode;
|
|
14810
14905
|
parentNode = childNode.parent;
|
|
14811
14906
|
}
|
|
14812
|
-
const offset2 = parentNode.findOffset(childNode);
|
|
14907
|
+
const offset2 = parentNode.findOffset(childNode, includeRemoved);
|
|
14813
14908
|
return {
|
|
14814
14909
|
node: parentNode,
|
|
14815
14910
|
offset: offset2
|
|
@@ -14821,12 +14916,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14821
14916
|
offset: 0
|
|
14822
14917
|
};
|
|
14823
14918
|
}
|
|
14824
|
-
let offset = parentNode.findOffset(leftNode);
|
|
14825
|
-
if (!leftNode.isRemoved) {
|
|
14919
|
+
let offset = parentNode.findOffset(leftNode, includeRemoved);
|
|
14920
|
+
if (includeRemoved || !leftNode.isRemoved) {
|
|
14826
14921
|
if (leftNode.isText) {
|
|
14827
14922
|
return {
|
|
14828
14923
|
node: leftNode,
|
|
14829
|
-
offset: leftNode.paddedSize
|
|
14924
|
+
offset: leftNode.paddedSize(includeRemoved)
|
|
14830
14925
|
};
|
|
14831
14926
|
}
|
|
14832
14927
|
offset++;
|
|
@@ -15969,13 +16064,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
15969
16064
|
/**
|
|
15970
16065
|
* `canDelete` checks if node is able to delete.
|
|
15971
16066
|
*/
|
|
15972
|
-
canRemove(creationKnown) {
|
|
16067
|
+
canRemove(editedAt, creationKnown, tombstoneKnown) {
|
|
15973
16068
|
if (!creationKnown) {
|
|
15974
16069
|
return false;
|
|
15975
16070
|
}
|
|
15976
16071
|
if (!this.removedAt) {
|
|
15977
16072
|
return true;
|
|
15978
16073
|
}
|
|
16074
|
+
if (!tombstoneKnown && (editedAt == null ? void 0 : editedAt.after(this.removedAt))) {
|
|
16075
|
+
return true;
|
|
16076
|
+
}
|
|
15979
16077
|
return false;
|
|
15980
16078
|
}
|
|
15981
16079
|
/**
|
|
@@ -15994,12 +16092,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
15994
16092
|
/**
|
|
15995
16093
|
* `remove` removes the node of the given edited time.
|
|
15996
16094
|
*/
|
|
15997
|
-
remove(removedAt
|
|
16095
|
+
remove(removedAt) {
|
|
15998
16096
|
if (!this.removedAt) {
|
|
15999
16097
|
this.removedAt = removedAt;
|
|
16000
16098
|
return;
|
|
16001
16099
|
}
|
|
16002
|
-
if (
|
|
16100
|
+
if (removedAt.after(this.removedAt)) {
|
|
16003
16101
|
this.removedAt = removedAt;
|
|
16004
16102
|
}
|
|
16005
16103
|
}
|
|
@@ -16336,13 +16434,31 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16336
16434
|
if (!candidates.length) {
|
|
16337
16435
|
return [[], /* @__PURE__ */ new Map()];
|
|
16338
16436
|
}
|
|
16339
|
-
const isLocal = vector === void 0;
|
|
16437
|
+
const isLocal = vector === void 0 || vector.size() === 0;
|
|
16340
16438
|
const nodesToRemove = [];
|
|
16341
16439
|
const nodesToKeep = [];
|
|
16342
16440
|
const [leftEdge, rightEdge] = this.findEdgesOfCandidates(candidates);
|
|
16343
16441
|
nodesToKeep.push(leftEdge);
|
|
16344
16442
|
for (const node of candidates) {
|
|
16345
|
-
|
|
16443
|
+
let creationKnown = false;
|
|
16444
|
+
if (isLocal) {
|
|
16445
|
+
creationKnown = true;
|
|
16446
|
+
} else {
|
|
16447
|
+
const createdAtVV = vector == null ? void 0 : vector.get(node.getCreatedAt().getActorID());
|
|
16448
|
+
if (createdAtVV && createdAtVV >= node.getCreatedAt().getLamport()) {
|
|
16449
|
+
creationKnown = true;
|
|
16450
|
+
}
|
|
16451
|
+
}
|
|
16452
|
+
let tombstoneKnown = false;
|
|
16453
|
+
if (node.getRemovedAt()) {
|
|
16454
|
+
const removedAtVV = vector == null ? void 0 : vector.get(node.getRemovedAt().getActorID());
|
|
16455
|
+
if (isLocal) {
|
|
16456
|
+
tombstoneKnown = true;
|
|
16457
|
+
} else if (removedAtVV && removedAtVV >= node.getRemovedAt().getLamport()) {
|
|
16458
|
+
tombstoneKnown = true;
|
|
16459
|
+
}
|
|
16460
|
+
}
|
|
16461
|
+
if (node.canRemove(editedAt, creationKnown, tombstoneKnown)) {
|
|
16346
16462
|
nodesToRemove.push(node);
|
|
16347
16463
|
} else {
|
|
16348
16464
|
nodesToKeep.push(node);
|
|
@@ -16353,10 +16469,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16353
16469
|
const removedNodes = /* @__PURE__ */ new Map();
|
|
16354
16470
|
for (const node of nodesToRemove) {
|
|
16355
16471
|
removedNodes.set(node.getID().toIDString(), node);
|
|
16356
|
-
node.remove(
|
|
16357
|
-
editedAt,
|
|
16358
|
-
node.isRemoved() && (isLocal || vector.afterOrEqual(node.getRemovedAt()))
|
|
16359
|
-
);
|
|
16472
|
+
node.remove(editedAt);
|
|
16360
16473
|
}
|
|
16361
16474
|
this.deleteIndexNodes(nodesToKeep);
|
|
16362
16475
|
return [changes, removedNodes];
|
|
@@ -16538,13 +16651,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16538
16651
|
* `deepcopy` copies itself deeply.
|
|
16539
16652
|
*/
|
|
16540
16653
|
deepcopy() {
|
|
16541
|
-
const
|
|
16654
|
+
const clone = CRDTCounter.create(
|
|
16542
16655
|
this.valueType,
|
|
16543
16656
|
this.value,
|
|
16544
16657
|
this.getCreatedAt()
|
|
16545
16658
|
);
|
|
16546
|
-
|
|
16547
|
-
|
|
16659
|
+
clone.setRemovedAt(this.getRemovedAt());
|
|
16660
|
+
clone.setMovedAt(this.getMovedAt());
|
|
16661
|
+
return clone;
|
|
16548
16662
|
}
|
|
16549
16663
|
/**
|
|
16550
16664
|
* `getType` returns the type of the value.
|
|
@@ -17721,6 +17835,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17721
17835
|
depthTable.set(pbTreeNodes[i].depth, nodes[i]);
|
|
17722
17836
|
}
|
|
17723
17837
|
root.updateDescendantsSize();
|
|
17838
|
+
root.updateDescendantsSize(true);
|
|
17724
17839
|
return CRDTTree.create(root, InitialTimeTicket).getRoot();
|
|
17725
17840
|
}
|
|
17726
17841
|
function fromRHT(pbRHT) {
|
|
@@ -18208,108 +18323,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
18208
18323
|
return v.toString(16);
|
|
18209
18324
|
});
|
|
18210
18325
|
}
|
|
18211
|
-
class Attachment {
|
|
18212
|
-
constructor(reconnectStreamDelay, resource, resourceID, syncMode, unsubscribeBroadcastEvent) {
|
|
18213
|
-
__publicField(this, "resource");
|
|
18214
|
-
__publicField(this, "resourceID");
|
|
18215
|
-
__publicField(this, "syncMode");
|
|
18216
|
-
__publicField(this, "changeEventReceived");
|
|
18217
|
-
__publicField(this, "lastHeartbeatTime");
|
|
18218
|
-
__publicField(this, "reconnectStreamDelay");
|
|
18219
|
-
__publicField(this, "cancelled");
|
|
18220
|
-
__publicField(this, "watchStream");
|
|
18221
|
-
__publicField(this, "watchLoopTimerID");
|
|
18222
|
-
__publicField(this, "watchAbortController");
|
|
18223
|
-
__publicField(this, "unsubscribeBroadcastEvent");
|
|
18224
|
-
this.reconnectStreamDelay = reconnectStreamDelay;
|
|
18225
|
-
this.resource = resource;
|
|
18226
|
-
this.resourceID = resourceID;
|
|
18227
|
-
this.syncMode = syncMode;
|
|
18228
|
-
this.changeEventReceived = syncMode !== void 0 ? false : void 0;
|
|
18229
|
-
this.lastHeartbeatTime = Date.now();
|
|
18230
|
-
this.cancelled = false;
|
|
18231
|
-
this.unsubscribeBroadcastEvent = unsubscribeBroadcastEvent;
|
|
18232
|
-
}
|
|
18233
|
-
/**
|
|
18234
|
-
* `changeSyncMode` changes the sync mode of the document.
|
|
18235
|
-
*/
|
|
18236
|
-
changeSyncMode(syncMode) {
|
|
18237
|
-
this.syncMode = syncMode;
|
|
18238
|
-
}
|
|
18239
|
-
/**
|
|
18240
|
-
* `needRealtimeSync` returns whether the resource needs to be synced in real time.
|
|
18241
|
-
* Only applicable to Document resources with syncMode defined.
|
|
18242
|
-
*/
|
|
18243
|
-
needRealtimeSync() {
|
|
18244
|
-
if (this.syncMode === void 0) {
|
|
18245
|
-
return false;
|
|
18246
|
-
}
|
|
18247
|
-
if (this.syncMode === SyncMode.RealtimeSyncOff) {
|
|
18248
|
-
return false;
|
|
18249
|
-
}
|
|
18250
|
-
if (this.syncMode === SyncMode.RealtimePushOnly) {
|
|
18251
|
-
return this.resource.hasLocalChanges();
|
|
18252
|
-
}
|
|
18253
|
-
return this.syncMode !== SyncMode.Manual && (this.resource.hasLocalChanges() || (this.changeEventReceived ?? false));
|
|
18254
|
-
}
|
|
18255
|
-
/**
|
|
18256
|
-
* `needSync` determines if the attachment needs sync.
|
|
18257
|
-
* This includes both document sync and presence heartbeat.
|
|
18258
|
-
*/
|
|
18259
|
-
needSync(heartbeatInterval) {
|
|
18260
|
-
if (this.syncMode !== void 0) {
|
|
18261
|
-
return this.needRealtimeSync();
|
|
18262
|
-
}
|
|
18263
|
-
return Date.now() - this.lastHeartbeatTime >= heartbeatInterval;
|
|
18264
|
-
}
|
|
18265
|
-
/**
|
|
18266
|
-
* `updateHeartbeatTime` updates the last heartbeat time.
|
|
18267
|
-
*/
|
|
18268
|
-
updateHeartbeatTime() {
|
|
18269
|
-
this.lastHeartbeatTime = Date.now();
|
|
18270
|
-
}
|
|
18271
|
-
/**
|
|
18272
|
-
* `runWatchLoop` runs the watch loop.
|
|
18273
|
-
*/
|
|
18274
|
-
async runWatchLoop(watchStreamCreator) {
|
|
18275
|
-
const doLoop = async () => {
|
|
18276
|
-
if (this.watchStream) {
|
|
18277
|
-
return Promise.resolve();
|
|
18278
|
-
}
|
|
18279
|
-
if (this.watchLoopTimerID) {
|
|
18280
|
-
clearTimeout(this.watchLoopTimerID);
|
|
18281
|
-
this.watchLoopTimerID = void 0;
|
|
18282
|
-
}
|
|
18283
|
-
try {
|
|
18284
|
-
[this.watchStream, this.watchAbortController] = await watchStreamCreator(() => {
|
|
18285
|
-
this.watchStream = void 0;
|
|
18286
|
-
this.watchAbortController = void 0;
|
|
18287
|
-
if (!this.cancelled) {
|
|
18288
|
-
this.watchLoopTimerID = setTimeout(
|
|
18289
|
-
doLoop,
|
|
18290
|
-
this.reconnectStreamDelay
|
|
18291
|
-
);
|
|
18292
|
-
}
|
|
18293
|
-
});
|
|
18294
|
-
} catch {
|
|
18295
|
-
}
|
|
18296
|
-
};
|
|
18297
|
-
await doLoop();
|
|
18298
|
-
}
|
|
18299
|
-
/**
|
|
18300
|
-
* `cancelWatchStream` cancels the watch stream.
|
|
18301
|
-
*/
|
|
18302
|
-
cancelWatchStream() {
|
|
18303
|
-
this.cancelled = true;
|
|
18304
|
-
if (this.watchStream && this.watchAbortController) {
|
|
18305
|
-
this.watchAbortController.abort();
|
|
18306
|
-
this.watchStream = void 0;
|
|
18307
|
-
this.watchAbortController = void 0;
|
|
18308
|
-
}
|
|
18309
|
-
clearTimeout(this.watchLoopTimerID);
|
|
18310
|
-
this.watchLoopTimerID = void 0;
|
|
18311
|
-
}
|
|
18312
|
-
}
|
|
18313
18326
|
const Noop = () => {
|
|
18314
18327
|
};
|
|
18315
18328
|
class ObserverProxy {
|
|
@@ -20642,6 +20655,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20642
20655
|
acc(diff) {
|
|
20643
20656
|
addDataSizes(this.docSize.live, diff);
|
|
20644
20657
|
}
|
|
20658
|
+
/**
|
|
20659
|
+
* `getGCElementPairs` returns an iterator for all GC element pairs.
|
|
20660
|
+
* This is similar to Go's GCElementPairMap() functionality.
|
|
20661
|
+
*/
|
|
20662
|
+
*getGCElementPairs() {
|
|
20663
|
+
for (const createdAt of this.gcElementSetByCreatedAt) {
|
|
20664
|
+
const pair = this.elementPairMapByCreatedAt.get(createdAt);
|
|
20665
|
+
if (pair) {
|
|
20666
|
+
yield pair;
|
|
20667
|
+
}
|
|
20668
|
+
}
|
|
20669
|
+
}
|
|
20645
20670
|
}
|
|
20646
20671
|
class DocPresence {
|
|
20647
20672
|
constructor(changeContext, presence) {
|
|
@@ -21596,6 +21621,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
21596
21621
|
getGarbageLen() {
|
|
21597
21622
|
return this.root.getGarbageLen();
|
|
21598
21623
|
}
|
|
21624
|
+
/**
|
|
21625
|
+
* `getRootCRDT` returns the CRDTRoot for testing purposes.
|
|
21626
|
+
* This method is intended for internal testing only.
|
|
21627
|
+
*/
|
|
21628
|
+
getRootCRDT() {
|
|
21629
|
+
return this.root;
|
|
21630
|
+
}
|
|
21599
21631
|
/**
|
|
21600
21632
|
* `getGarbageLenFromClone` returns the length of elements should be purged from clone.
|
|
21601
21633
|
*/
|
|
@@ -22169,6 +22201,108 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22169
22201
|
this.publish(events);
|
|
22170
22202
|
}
|
|
22171
22203
|
}
|
|
22204
|
+
class Attachment {
|
|
22205
|
+
constructor(reconnectStreamDelay, resource, resourceID, syncMode, unsubscribeBroadcastEvent) {
|
|
22206
|
+
__publicField(this, "resource");
|
|
22207
|
+
__publicField(this, "resourceID");
|
|
22208
|
+
__publicField(this, "syncMode");
|
|
22209
|
+
__publicField(this, "changeEventReceived");
|
|
22210
|
+
__publicField(this, "lastHeartbeatTime");
|
|
22211
|
+
__publicField(this, "reconnectStreamDelay");
|
|
22212
|
+
__publicField(this, "cancelled");
|
|
22213
|
+
__publicField(this, "watchStream");
|
|
22214
|
+
__publicField(this, "watchLoopTimerID");
|
|
22215
|
+
__publicField(this, "watchAbortController");
|
|
22216
|
+
__publicField(this, "unsubscribeBroadcastEvent");
|
|
22217
|
+
this.reconnectStreamDelay = reconnectStreamDelay;
|
|
22218
|
+
this.resource = resource;
|
|
22219
|
+
this.resourceID = resourceID;
|
|
22220
|
+
this.syncMode = syncMode;
|
|
22221
|
+
this.changeEventReceived = syncMode !== void 0 ? false : void 0;
|
|
22222
|
+
this.lastHeartbeatTime = Date.now();
|
|
22223
|
+
this.cancelled = false;
|
|
22224
|
+
this.unsubscribeBroadcastEvent = unsubscribeBroadcastEvent;
|
|
22225
|
+
}
|
|
22226
|
+
/**
|
|
22227
|
+
* `changeSyncMode` changes the sync mode of the document.
|
|
22228
|
+
*/
|
|
22229
|
+
changeSyncMode(syncMode) {
|
|
22230
|
+
this.syncMode = syncMode;
|
|
22231
|
+
}
|
|
22232
|
+
/**
|
|
22233
|
+
* `needRealtimeSync` returns whether the resource needs to be synced in real time.
|
|
22234
|
+
* Only applicable to Document resources with syncMode defined.
|
|
22235
|
+
*/
|
|
22236
|
+
needRealtimeSync() {
|
|
22237
|
+
if (this.syncMode === SyncMode.RealtimeSyncOff) {
|
|
22238
|
+
return false;
|
|
22239
|
+
}
|
|
22240
|
+
if (this.syncMode === SyncMode.RealtimePushOnly) {
|
|
22241
|
+
return this.resource.hasLocalChanges();
|
|
22242
|
+
}
|
|
22243
|
+
return this.syncMode !== SyncMode.Manual && (this.resource.hasLocalChanges() || (this.changeEventReceived ?? false));
|
|
22244
|
+
}
|
|
22245
|
+
/**
|
|
22246
|
+
* `needSync` determines if the attachment needs sync.
|
|
22247
|
+
* This includes both document sync and presence heartbeat.
|
|
22248
|
+
*/
|
|
22249
|
+
needSync(heartbeatInterval) {
|
|
22250
|
+
if (this.resource instanceof Document) {
|
|
22251
|
+
return this.needRealtimeSync();
|
|
22252
|
+
}
|
|
22253
|
+
if (this.syncMode === SyncMode.Manual) {
|
|
22254
|
+
return false;
|
|
22255
|
+
}
|
|
22256
|
+
return Date.now() - this.lastHeartbeatTime >= heartbeatInterval;
|
|
22257
|
+
}
|
|
22258
|
+
/**
|
|
22259
|
+
* `updateHeartbeatTime` updates the last heartbeat time.
|
|
22260
|
+
*/
|
|
22261
|
+
updateHeartbeatTime() {
|
|
22262
|
+
this.lastHeartbeatTime = Date.now();
|
|
22263
|
+
}
|
|
22264
|
+
/**
|
|
22265
|
+
* `runWatchLoop` runs the watch loop.
|
|
22266
|
+
*/
|
|
22267
|
+
async runWatchLoop(watchStreamCreator) {
|
|
22268
|
+
const doLoop = async () => {
|
|
22269
|
+
if (this.watchStream) {
|
|
22270
|
+
return Promise.resolve();
|
|
22271
|
+
}
|
|
22272
|
+
if (this.watchLoopTimerID) {
|
|
22273
|
+
clearTimeout(this.watchLoopTimerID);
|
|
22274
|
+
this.watchLoopTimerID = void 0;
|
|
22275
|
+
}
|
|
22276
|
+
try {
|
|
22277
|
+
[this.watchStream, this.watchAbortController] = await watchStreamCreator(() => {
|
|
22278
|
+
this.watchStream = void 0;
|
|
22279
|
+
this.watchAbortController = void 0;
|
|
22280
|
+
if (!this.cancelled) {
|
|
22281
|
+
this.watchLoopTimerID = setTimeout(
|
|
22282
|
+
doLoop,
|
|
22283
|
+
this.reconnectStreamDelay
|
|
22284
|
+
);
|
|
22285
|
+
}
|
|
22286
|
+
});
|
|
22287
|
+
} catch {
|
|
22288
|
+
}
|
|
22289
|
+
};
|
|
22290
|
+
await doLoop();
|
|
22291
|
+
}
|
|
22292
|
+
/**
|
|
22293
|
+
* `cancelWatchStream` cancels the watch stream.
|
|
22294
|
+
*/
|
|
22295
|
+
cancelWatchStream() {
|
|
22296
|
+
this.cancelled = true;
|
|
22297
|
+
if (this.watchStream && this.watchAbortController) {
|
|
22298
|
+
this.watchAbortController.abort();
|
|
22299
|
+
this.watchStream = void 0;
|
|
22300
|
+
this.watchAbortController = void 0;
|
|
22301
|
+
}
|
|
22302
|
+
clearTimeout(this.watchLoopTimerID);
|
|
22303
|
+
this.watchLoopTimerID = void 0;
|
|
22304
|
+
}
|
|
22305
|
+
}
|
|
22172
22306
|
function createAuthInterceptor(apiKey, token) {
|
|
22173
22307
|
let currentToken = token;
|
|
22174
22308
|
const setToken = (token2) => {
|
|
@@ -22189,7 +22323,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22189
22323
|
};
|
|
22190
22324
|
}
|
|
22191
22325
|
const name$1 = "@yorkie-js/sdk";
|
|
22192
|
-
const version$1 = "0.6.
|
|
22326
|
+
const version$1 = "0.6.35";
|
|
22193
22327
|
const pkg$1 = {
|
|
22194
22328
|
name: name$1,
|
|
22195
22329
|
version: version$1
|
|
@@ -22511,7 +22645,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22511
22645
|
*/
|
|
22512
22646
|
attach(resource, opts) {
|
|
22513
22647
|
if (resource instanceof Presence) {
|
|
22514
|
-
return this.attachPresence(resource);
|
|
22648
|
+
return this.attachPresence(resource, opts);
|
|
22515
22649
|
} else {
|
|
22516
22650
|
return this.attachDocument(resource, opts);
|
|
22517
22651
|
}
|
|
@@ -22676,7 +22810,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22676
22810
|
* `attach` attaches the given presence counter to this client.
|
|
22677
22811
|
* It tells the server that this client will track the presence count.
|
|
22678
22812
|
*/
|
|
22679
|
-
async attachPresence(presence) {
|
|
22813
|
+
async attachPresence(presence, opts = {}) {
|
|
22680
22814
|
if (!this.isActive()) {
|
|
22681
22815
|
throw new YorkieError(
|
|
22682
22816
|
Code.ErrClientNotActivated,
|
|
@@ -22702,15 +22836,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22702
22836
|
presence.setPresenceID(res.presenceId);
|
|
22703
22837
|
presence.updateCount(Number(res.count), 0);
|
|
22704
22838
|
presence.applyStatus(PresenceStatus.Attached);
|
|
22839
|
+
const syncMode = opts.isRealtime !== false ? "realtime" : "manual";
|
|
22705
22840
|
const attachment = new Attachment(
|
|
22706
22841
|
this.reconnectStreamDelay,
|
|
22707
22842
|
presence,
|
|
22708
|
-
res.presenceId
|
|
22843
|
+
res.presenceId,
|
|
22844
|
+
syncMode
|
|
22709
22845
|
);
|
|
22710
22846
|
this.attachmentMap.set(presence.getKey(), attachment);
|
|
22711
|
-
|
|
22847
|
+
if (syncMode === "realtime") {
|
|
22848
|
+
await this.runWatchLoop(presence.getKey());
|
|
22849
|
+
}
|
|
22712
22850
|
logger.info(
|
|
22713
|
-
`[AP] c:"${this.getKey()}" attaches p:"${presence.getKey()}" count:${presence.getCount()}`
|
|
22851
|
+
`[AP] c:"${this.getKey()}" attaches p:"${presence.getKey()}" mode:${syncMode} count:${presence.getCount()}`
|
|
22714
22852
|
);
|
|
22715
22853
|
return presence;
|
|
22716
22854
|
} catch (err) {
|
|
@@ -22798,23 +22936,39 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22798
22936
|
return doc;
|
|
22799
22937
|
}
|
|
22800
22938
|
/**
|
|
22801
|
-
* `sync`
|
|
22802
|
-
* receives changes of the remote replica from the server then apply them to
|
|
22803
|
-
* local documents.
|
|
22939
|
+
* `sync` implementation that handles both Document and Presence.
|
|
22804
22940
|
*/
|
|
22805
|
-
sync(
|
|
22941
|
+
sync(resource) {
|
|
22806
22942
|
if (!this.isActive()) {
|
|
22807
22943
|
throw new YorkieError(
|
|
22808
22944
|
Code.ErrClientNotActivated,
|
|
22809
22945
|
`${this.key} is not active`
|
|
22810
22946
|
);
|
|
22811
22947
|
}
|
|
22812
|
-
if (
|
|
22813
|
-
const attachment = this.attachmentMap.get(
|
|
22948
|
+
if (resource instanceof Presence) {
|
|
22949
|
+
const attachment = this.attachmentMap.get(
|
|
22950
|
+
resource.getKey()
|
|
22951
|
+
);
|
|
22952
|
+
if (!attachment) {
|
|
22953
|
+
throw new YorkieError(
|
|
22954
|
+
Code.ErrDocumentNotAttached,
|
|
22955
|
+
`${resource.getKey()} is not attached`
|
|
22956
|
+
);
|
|
22957
|
+
}
|
|
22958
|
+
return this.enqueueTask(async () => {
|
|
22959
|
+
return this.syncInternal(attachment).catch(async (err) => {
|
|
22960
|
+
logger.error(`[SY] c:"${this.getKey()}" err :`, err);
|
|
22961
|
+
await this.handleConnectError(err);
|
|
22962
|
+
throw err;
|
|
22963
|
+
});
|
|
22964
|
+
});
|
|
22965
|
+
}
|
|
22966
|
+
if (resource instanceof Document) {
|
|
22967
|
+
const attachment = this.attachmentMap.get(resource.getKey());
|
|
22814
22968
|
if (!attachment) {
|
|
22815
22969
|
throw new YorkieError(
|
|
22816
22970
|
Code.ErrDocumentNotAttached,
|
|
22817
|
-
`${
|
|
22971
|
+
`${resource.getKey()} is not attached`
|
|
22818
22972
|
);
|
|
22819
22973
|
}
|
|
22820
22974
|
return this.enqueueTask(async () => {
|
|
@@ -23336,7 +23490,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23336
23490
|
const { resource } = attachment;
|
|
23337
23491
|
if (resource instanceof Presence) {
|
|
23338
23492
|
try {
|
|
23339
|
-
await this.rpcClient.refreshPresence(
|
|
23493
|
+
const res = await this.rpcClient.refreshPresence(
|
|
23340
23494
|
{
|
|
23341
23495
|
clientId: this.id,
|
|
23342
23496
|
presenceId: resource.getPresenceID(),
|
|
@@ -23348,9 +23502,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23348
23502
|
}
|
|
23349
23503
|
}
|
|
23350
23504
|
);
|
|
23505
|
+
resource.updateCount(Number(res.count), 0);
|
|
23351
23506
|
attachment.updateHeartbeatTime();
|
|
23352
23507
|
logger.debug(
|
|
23353
|
-
`[RP] c:"${this.getKey()}" refreshes p:"${resource.getKey()}"`
|
|
23508
|
+
`[RP] c:"${this.getKey()}" refreshes p:"${resource.getKey()}" mode:${attachment.syncMode}`
|
|
23354
23509
|
);
|
|
23355
23510
|
} catch (err) {
|
|
23356
23511
|
logger.error(`[RP] c:"${this.getKey()}" err :`, err);
|
|
@@ -23484,7 +23639,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23484
23639
|
};
|
|
23485
23640
|
}
|
|
23486
23641
|
const name = "@yorkie-js/react";
|
|
23487
|
-
const version = "0.6.
|
|
23642
|
+
const version = "0.6.35";
|
|
23488
23643
|
const pkg = {
|
|
23489
23644
|
name,
|
|
23490
23645
|
version
|