@yorkie-js/react 0.6.12 → 0.6.14
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 +369 -76
- package/dist/yorkie-js-react.es.js.map +1 -1
- package/dist/yorkie-js-react.js +369 -76
- package/dist/yorkie-js-react.js.map +1 -1
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { createContext, useMemo, useState, useEffect, useContext, useCallback } from "react";
|
|
7
7
|
const name$1 = "@yorkie-js/react";
|
|
8
|
-
const version$1 = "0.6.
|
|
8
|
+
const version$1 = "0.6.14";
|
|
9
9
|
const pkg$1 = {
|
|
10
10
|
name: name$1,
|
|
11
11
|
version: version$1
|
|
@@ -6090,15 +6090,39 @@ const _Project = class _Project extends Message {
|
|
|
6090
6090
|
*/
|
|
6091
6091
|
__publicField(this, "authWebhookMethods", []);
|
|
6092
6092
|
/**
|
|
6093
|
-
* @generated from field: string
|
|
6093
|
+
* @generated from field: string event_webhook_url = 7;
|
|
6094
|
+
*/
|
|
6095
|
+
__publicField(this, "eventWebhookUrl", "");
|
|
6096
|
+
/**
|
|
6097
|
+
* @generated from field: repeated string event_webhook_events = 8;
|
|
6098
|
+
*/
|
|
6099
|
+
__publicField(this, "eventWebhookEvents", []);
|
|
6100
|
+
/**
|
|
6101
|
+
* @generated from field: string client_deactivate_threshold = 9;
|
|
6094
6102
|
*/
|
|
6095
6103
|
__publicField(this, "clientDeactivateThreshold", "");
|
|
6096
6104
|
/**
|
|
6097
|
-
* @generated from field:
|
|
6105
|
+
* @generated from field: int32 max_subscribers_per_document = 10;
|
|
6106
|
+
*/
|
|
6107
|
+
__publicField(this, "maxSubscribersPerDocument", 0);
|
|
6108
|
+
/**
|
|
6109
|
+
* @generated from field: int32 max_attachments_per_document = 11;
|
|
6110
|
+
*/
|
|
6111
|
+
__publicField(this, "maxAttachmentsPerDocument", 0);
|
|
6112
|
+
/**
|
|
6113
|
+
* @generated from field: int32 max_size_per_document = 15;
|
|
6114
|
+
*/
|
|
6115
|
+
__publicField(this, "maxSizePerDocument", 0);
|
|
6116
|
+
/**
|
|
6117
|
+
* @generated from field: repeated string allowed_origins = 14;
|
|
6118
|
+
*/
|
|
6119
|
+
__publicField(this, "allowedOrigins", []);
|
|
6120
|
+
/**
|
|
6121
|
+
* @generated from field: google.protobuf.Timestamp created_at = 12;
|
|
6098
6122
|
*/
|
|
6099
6123
|
__publicField(this, "createdAt");
|
|
6100
6124
|
/**
|
|
6101
|
-
* @generated from field: google.protobuf.Timestamp updated_at =
|
|
6125
|
+
* @generated from field: google.protobuf.Timestamp updated_at = 13;
|
|
6102
6126
|
*/
|
|
6103
6127
|
__publicField(this, "updatedAt");
|
|
6104
6128
|
proto3.util.initPartial(data, this);
|
|
@@ -6157,13 +6181,43 @@ __publicField(_Project, "fields", proto3.util.newFieldList(() => [
|
|
|
6157
6181
|
{ no: 6, name: "auth_webhook_methods", kind: "scalar", T: 9, repeated: true },
|
|
6158
6182
|
{
|
|
6159
6183
|
no: 7,
|
|
6184
|
+
name: "event_webhook_url",
|
|
6185
|
+
kind: "scalar",
|
|
6186
|
+
T: 9
|
|
6187
|
+
/* ScalarType.STRING */
|
|
6188
|
+
},
|
|
6189
|
+
{ no: 8, name: "event_webhook_events", kind: "scalar", T: 9, repeated: true },
|
|
6190
|
+
{
|
|
6191
|
+
no: 9,
|
|
6160
6192
|
name: "client_deactivate_threshold",
|
|
6161
6193
|
kind: "scalar",
|
|
6162
6194
|
T: 9
|
|
6163
6195
|
/* ScalarType.STRING */
|
|
6164
6196
|
},
|
|
6165
|
-
{
|
|
6166
|
-
|
|
6197
|
+
{
|
|
6198
|
+
no: 10,
|
|
6199
|
+
name: "max_subscribers_per_document",
|
|
6200
|
+
kind: "scalar",
|
|
6201
|
+
T: 5
|
|
6202
|
+
/* ScalarType.INT32 */
|
|
6203
|
+
},
|
|
6204
|
+
{
|
|
6205
|
+
no: 11,
|
|
6206
|
+
name: "max_attachments_per_document",
|
|
6207
|
+
kind: "scalar",
|
|
6208
|
+
T: 5
|
|
6209
|
+
/* ScalarType.INT32 */
|
|
6210
|
+
},
|
|
6211
|
+
{
|
|
6212
|
+
no: 15,
|
|
6213
|
+
name: "max_size_per_document",
|
|
6214
|
+
kind: "scalar",
|
|
6215
|
+
T: 5
|
|
6216
|
+
/* ScalarType.INT32 */
|
|
6217
|
+
},
|
|
6218
|
+
{ no: 14, name: "allowed_origins", kind: "scalar", T: 9, repeated: true },
|
|
6219
|
+
{ no: 12, name: "created_at", kind: "message", T: Timestamp },
|
|
6220
|
+
{ no: 13, name: "updated_at", kind: "message", T: Timestamp }
|
|
6167
6221
|
]));
|
|
6168
6222
|
let Project = _Project;
|
|
6169
6223
|
const _UpdatableProjectFields = class _UpdatableProjectFields extends Message {
|
|
@@ -6182,9 +6236,33 @@ const _UpdatableProjectFields = class _UpdatableProjectFields extends Message {
|
|
|
6182
6236
|
*/
|
|
6183
6237
|
__publicField(this, "authWebhookMethods");
|
|
6184
6238
|
/**
|
|
6185
|
-
* @generated from field: google.protobuf.StringValue
|
|
6239
|
+
* @generated from field: google.protobuf.StringValue event_webhook_url = 4;
|
|
6240
|
+
*/
|
|
6241
|
+
__publicField(this, "eventWebhookUrl");
|
|
6242
|
+
/**
|
|
6243
|
+
* @generated from field: yorkie.v1.UpdatableProjectFields.EventWebhookEvents event_webhook_events = 5;
|
|
6244
|
+
*/
|
|
6245
|
+
__publicField(this, "eventWebhookEvents");
|
|
6246
|
+
/**
|
|
6247
|
+
* @generated from field: google.protobuf.StringValue client_deactivate_threshold = 6;
|
|
6186
6248
|
*/
|
|
6187
6249
|
__publicField(this, "clientDeactivateThreshold");
|
|
6250
|
+
/**
|
|
6251
|
+
* @generated from field: google.protobuf.Int32Value max_subscribers_per_document = 7;
|
|
6252
|
+
*/
|
|
6253
|
+
__publicField(this, "maxSubscribersPerDocument");
|
|
6254
|
+
/**
|
|
6255
|
+
* @generated from field: google.protobuf.Int32Value max_attachments_per_document = 8;
|
|
6256
|
+
*/
|
|
6257
|
+
__publicField(this, "maxAttachmentsPerDocument");
|
|
6258
|
+
/**
|
|
6259
|
+
* @generated from field: google.protobuf.Int32Value max_size_per_document = 10;
|
|
6260
|
+
*/
|
|
6261
|
+
__publicField(this, "maxSizePerDocument");
|
|
6262
|
+
/**
|
|
6263
|
+
* @generated from field: yorkie.v1.UpdatableProjectFields.AllowedOrigins allowed_origins = 9;
|
|
6264
|
+
*/
|
|
6265
|
+
__publicField(this, "allowedOrigins");
|
|
6188
6266
|
proto3.util.initPartial(data, this);
|
|
6189
6267
|
}
|
|
6190
6268
|
static fromBinary(bytes, options) {
|
|
@@ -6206,7 +6284,13 @@ __publicField(_UpdatableProjectFields, "fields", proto3.util.newFieldList(() =>
|
|
|
6206
6284
|
{ no: 1, name: "name", kind: "message", T: StringValue },
|
|
6207
6285
|
{ no: 2, name: "auth_webhook_url", kind: "message", T: StringValue },
|
|
6208
6286
|
{ no: 3, name: "auth_webhook_methods", kind: "message", T: UpdatableProjectFields_AuthWebhookMethods },
|
|
6209
|
-
{ no: 4, name: "
|
|
6287
|
+
{ no: 4, name: "event_webhook_url", kind: "message", T: StringValue },
|
|
6288
|
+
{ no: 5, name: "event_webhook_events", kind: "message", T: UpdatableProjectFields_EventWebhookEvents },
|
|
6289
|
+
{ no: 6, name: "client_deactivate_threshold", kind: "message", T: StringValue },
|
|
6290
|
+
{ no: 7, name: "max_subscribers_per_document", kind: "message", T: Int32Value },
|
|
6291
|
+
{ no: 8, name: "max_attachments_per_document", kind: "message", T: Int32Value },
|
|
6292
|
+
{ no: 10, name: "max_size_per_document", kind: "message", T: Int32Value },
|
|
6293
|
+
{ no: 9, name: "allowed_origins", kind: "message", T: UpdatableProjectFields_AllowedOrigins }
|
|
6210
6294
|
]));
|
|
6211
6295
|
let UpdatableProjectFields = _UpdatableProjectFields;
|
|
6212
6296
|
const _UpdatableProjectFields_AuthWebhookMethods = class _UpdatableProjectFields_AuthWebhookMethods extends Message {
|
|
@@ -6237,6 +6321,62 @@ __publicField(_UpdatableProjectFields_AuthWebhookMethods, "fields", proto3.util.
|
|
|
6237
6321
|
{ no: 1, name: "methods", kind: "scalar", T: 9, repeated: true }
|
|
6238
6322
|
]));
|
|
6239
6323
|
let UpdatableProjectFields_AuthWebhookMethods = _UpdatableProjectFields_AuthWebhookMethods;
|
|
6324
|
+
const _UpdatableProjectFields_EventWebhookEvents = class _UpdatableProjectFields_EventWebhookEvents extends Message {
|
|
6325
|
+
constructor(data) {
|
|
6326
|
+
super();
|
|
6327
|
+
/**
|
|
6328
|
+
* @generated from field: repeated string events = 1;
|
|
6329
|
+
*/
|
|
6330
|
+
__publicField(this, "events", []);
|
|
6331
|
+
proto3.util.initPartial(data, this);
|
|
6332
|
+
}
|
|
6333
|
+
static fromBinary(bytes, options) {
|
|
6334
|
+
return new _UpdatableProjectFields_EventWebhookEvents().fromBinary(bytes, options);
|
|
6335
|
+
}
|
|
6336
|
+
static fromJson(jsonValue, options) {
|
|
6337
|
+
return new _UpdatableProjectFields_EventWebhookEvents().fromJson(jsonValue, options);
|
|
6338
|
+
}
|
|
6339
|
+
static fromJsonString(jsonString, options) {
|
|
6340
|
+
return new _UpdatableProjectFields_EventWebhookEvents().fromJsonString(jsonString, options);
|
|
6341
|
+
}
|
|
6342
|
+
static equals(a, b) {
|
|
6343
|
+
return proto3.util.equals(_UpdatableProjectFields_EventWebhookEvents, a, b);
|
|
6344
|
+
}
|
|
6345
|
+
};
|
|
6346
|
+
__publicField(_UpdatableProjectFields_EventWebhookEvents, "runtime", proto3);
|
|
6347
|
+
__publicField(_UpdatableProjectFields_EventWebhookEvents, "typeName", "yorkie.v1.UpdatableProjectFields.EventWebhookEvents");
|
|
6348
|
+
__publicField(_UpdatableProjectFields_EventWebhookEvents, "fields", proto3.util.newFieldList(() => [
|
|
6349
|
+
{ no: 1, name: "events", kind: "scalar", T: 9, repeated: true }
|
|
6350
|
+
]));
|
|
6351
|
+
let UpdatableProjectFields_EventWebhookEvents = _UpdatableProjectFields_EventWebhookEvents;
|
|
6352
|
+
const _UpdatableProjectFields_AllowedOrigins = class _UpdatableProjectFields_AllowedOrigins extends Message {
|
|
6353
|
+
constructor(data) {
|
|
6354
|
+
super();
|
|
6355
|
+
/**
|
|
6356
|
+
* @generated from field: repeated string origins = 1;
|
|
6357
|
+
*/
|
|
6358
|
+
__publicField(this, "origins", []);
|
|
6359
|
+
proto3.util.initPartial(data, this);
|
|
6360
|
+
}
|
|
6361
|
+
static fromBinary(bytes, options) {
|
|
6362
|
+
return new _UpdatableProjectFields_AllowedOrigins().fromBinary(bytes, options);
|
|
6363
|
+
}
|
|
6364
|
+
static fromJson(jsonValue, options) {
|
|
6365
|
+
return new _UpdatableProjectFields_AllowedOrigins().fromJson(jsonValue, options);
|
|
6366
|
+
}
|
|
6367
|
+
static fromJsonString(jsonString, options) {
|
|
6368
|
+
return new _UpdatableProjectFields_AllowedOrigins().fromJsonString(jsonString, options);
|
|
6369
|
+
}
|
|
6370
|
+
static equals(a, b) {
|
|
6371
|
+
return proto3.util.equals(_UpdatableProjectFields_AllowedOrigins, a, b);
|
|
6372
|
+
}
|
|
6373
|
+
};
|
|
6374
|
+
__publicField(_UpdatableProjectFields_AllowedOrigins, "runtime", proto3);
|
|
6375
|
+
__publicField(_UpdatableProjectFields_AllowedOrigins, "typeName", "yorkie.v1.UpdatableProjectFields.AllowedOrigins");
|
|
6376
|
+
__publicField(_UpdatableProjectFields_AllowedOrigins, "fields", proto3.util.newFieldList(() => [
|
|
6377
|
+
{ no: 1, name: "origins", kind: "scalar", T: 9, repeated: true }
|
|
6378
|
+
]));
|
|
6379
|
+
let UpdatableProjectFields_AllowedOrigins = _UpdatableProjectFields_AllowedOrigins;
|
|
6240
6380
|
const _DocumentSummary = class _DocumentSummary extends Message {
|
|
6241
6381
|
constructor(data) {
|
|
6242
6382
|
super();
|
|
@@ -6793,6 +6933,10 @@ const _AttachDocumentResponse = class _AttachDocumentResponse extends Message {
|
|
|
6793
6933
|
* @generated from field: string document_id = 1;
|
|
6794
6934
|
*/
|
|
6795
6935
|
__publicField(this, "documentId", "");
|
|
6936
|
+
/**
|
|
6937
|
+
* @generated from field: int32 max_size_per_document = 3;
|
|
6938
|
+
*/
|
|
6939
|
+
__publicField(this, "maxSizePerDocument", 0);
|
|
6796
6940
|
/**
|
|
6797
6941
|
* @generated from field: yorkie.v1.ChangePack change_pack = 2;
|
|
6798
6942
|
*/
|
|
@@ -6822,6 +6966,13 @@ __publicField(_AttachDocumentResponse, "fields", proto3.util.newFieldList(() =>
|
|
|
6822
6966
|
T: 9
|
|
6823
6967
|
/* ScalarType.STRING */
|
|
6824
6968
|
},
|
|
6969
|
+
{
|
|
6970
|
+
no: 3,
|
|
6971
|
+
name: "max_size_per_document",
|
|
6972
|
+
kind: "scalar",
|
|
6973
|
+
T: 5
|
|
6974
|
+
/* ScalarType.INT32 */
|
|
6975
|
+
},
|
|
6825
6976
|
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 }
|
|
6826
6977
|
]));
|
|
6827
6978
|
let AttachDocumentResponse = _AttachDocumentResponse;
|
|
@@ -7592,6 +7743,7 @@ var Code = /* @__PURE__ */ ((Code2) => {
|
|
|
7592
7743
|
Code2["ErrDocumentNotAttached"] = "ErrDocumentNotAttached";
|
|
7593
7744
|
Code2["ErrDocumentNotDetached"] = "ErrDocumentNotDetached";
|
|
7594
7745
|
Code2["ErrDocumentRemoved"] = "ErrDocumentRemoved";
|
|
7746
|
+
Code2["ErrDocumentSizeExceedsLimit"] = "ErrDocumentSizeExceedsLimit";
|
|
7595
7747
|
Code2["ErrInvalidObjectKey"] = "ErrInvalidObjectKey";
|
|
7596
7748
|
Code2["ErrInvalidArgument"] = "ErrInvalidArgument";
|
|
7597
7749
|
Code2["ErrNotInitialized"] = "ErrNotInitialized";
|
|
@@ -10976,6 +11128,23 @@ const parseObjectValues = (attrs) => {
|
|
|
10976
11128
|
}
|
|
10977
11129
|
return attributes;
|
|
10978
11130
|
};
|
|
11131
|
+
function totalDocSize(d) {
|
|
11132
|
+
if (!d) return 0;
|
|
11133
|
+
return totalDataSize(d.live) + totalDataSize(d.gc);
|
|
11134
|
+
}
|
|
11135
|
+
function totalDataSize(d) {
|
|
11136
|
+
return d.data + d.meta;
|
|
11137
|
+
}
|
|
11138
|
+
function addDataSizes(target, ...others) {
|
|
11139
|
+
for (const other of others) {
|
|
11140
|
+
target.data += other.data;
|
|
11141
|
+
target.meta += other.meta;
|
|
11142
|
+
}
|
|
11143
|
+
}
|
|
11144
|
+
function subDataSize(target, other) {
|
|
11145
|
+
target.data -= other.data;
|
|
11146
|
+
target.meta -= other.meta;
|
|
11147
|
+
}
|
|
10979
11148
|
class CRDTTextValue {
|
|
10980
11149
|
constructor(content) {
|
|
10981
11150
|
__publicField(this, "attributes");
|
|
@@ -11111,7 +11280,7 @@ class CRDTText extends CRDTElement {
|
|
|
11111
11280
|
crdtTextValue.setAttr(k, v, editedAt);
|
|
11112
11281
|
}
|
|
11113
11282
|
}
|
|
11114
|
-
const [caretPos, pairs, valueChanges] = this.rgaTreeSplit.edit(
|
|
11283
|
+
const [caretPos, pairs, diff, valueChanges] = this.rgaTreeSplit.edit(
|
|
11115
11284
|
range,
|
|
11116
11285
|
editedAt,
|
|
11117
11286
|
crdtTextValue,
|
|
@@ -11129,7 +11298,7 @@ class CRDTText extends CRDTElement {
|
|
|
11129
11298
|
type: "content"
|
|
11130
11299
|
/* Content */
|
|
11131
11300
|
}));
|
|
11132
|
-
return [changes, pairs, [caretPos, caretPos]];
|
|
11301
|
+
return [changes, pairs, diff, [caretPos, caretPos]];
|
|
11133
11302
|
}
|
|
11134
11303
|
/**
|
|
11135
11304
|
* `setStyle` applies the style of the given range.
|
|
@@ -11142,11 +11311,16 @@ class CRDTText extends CRDTElement {
|
|
|
11142
11311
|
* @internal
|
|
11143
11312
|
*/
|
|
11144
11313
|
setStyle(range, attributes, editedAt, versionVector) {
|
|
11145
|
-
const
|
|
11146
|
-
const [,
|
|
11314
|
+
const diff = { data: 0, meta: 0 };
|
|
11315
|
+
const [, diffTo, toRight] = this.rgaTreeSplit.findNodeWithSplit(
|
|
11316
|
+
range[1],
|
|
11317
|
+
editedAt
|
|
11318
|
+
);
|
|
11319
|
+
const [, diffFrom, fromRight] = this.rgaTreeSplit.findNodeWithSplit(
|
|
11147
11320
|
range[0],
|
|
11148
11321
|
editedAt
|
|
11149
11322
|
);
|
|
11323
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
11150
11324
|
const changes = [];
|
|
11151
11325
|
const nodes = this.rgaTreeSplit.findBetween(fromRight, toRight);
|
|
11152
11326
|
const toBeStyleds = [];
|
|
@@ -11182,9 +11356,13 @@ class CRDTText extends CRDTElement {
|
|
|
11182
11356
|
if (prev !== void 0) {
|
|
11183
11357
|
pairs.push({ parent: node.getValue(), child: prev });
|
|
11184
11358
|
}
|
|
11359
|
+
const curr = node.getValue().getAttrs().getNodeMapByKey().get(key);
|
|
11360
|
+
if (curr !== void 0) {
|
|
11361
|
+
addDataSizes(diff, curr.getDataSize());
|
|
11362
|
+
}
|
|
11185
11363
|
}
|
|
11186
11364
|
}
|
|
11187
|
-
return [pairs, changes];
|
|
11365
|
+
return [pairs, diff, changes];
|
|
11188
11366
|
}
|
|
11189
11367
|
/**
|
|
11190
11368
|
* `indexRangeToPosRange` returns the position range of the given index range.
|
|
@@ -11373,13 +11551,14 @@ class EditOperation extends Operation {
|
|
|
11373
11551
|
);
|
|
11374
11552
|
}
|
|
11375
11553
|
const text = parentObject;
|
|
11376
|
-
const [changes, pairs] = text.edit(
|
|
11554
|
+
const [changes, pairs, diff] = text.edit(
|
|
11377
11555
|
[this.fromPos, this.toPos],
|
|
11378
11556
|
this.content,
|
|
11379
11557
|
this.getExecutedAt(),
|
|
11380
11558
|
Object.fromEntries(this.attributes),
|
|
11381
11559
|
versionVector
|
|
11382
11560
|
);
|
|
11561
|
+
root.acc(diff);
|
|
11383
11562
|
for (const pair of pairs) {
|
|
11384
11563
|
root.registerGCPair(pair);
|
|
11385
11564
|
}
|
|
@@ -11476,12 +11655,13 @@ class StyleOperation extends Operation {
|
|
|
11476
11655
|
);
|
|
11477
11656
|
}
|
|
11478
11657
|
const text = parentObject;
|
|
11479
|
-
const [pairs, changes] = text.setStyle(
|
|
11658
|
+
const [pairs, diff, changes] = text.setStyle(
|
|
11480
11659
|
[this.fromPos, this.toPos],
|
|
11481
11660
|
this.attributes ? Object.fromEntries(this.attributes) : {},
|
|
11482
11661
|
this.getExecutedAt(),
|
|
11483
11662
|
versionVector
|
|
11484
11663
|
);
|
|
11664
|
+
root.acc(diff);
|
|
11485
11665
|
for (const pair of pairs) {
|
|
11486
11666
|
root.registerGCPair(pair);
|
|
11487
11667
|
}
|
|
@@ -11635,19 +11815,23 @@ class IndexTreeNode {
|
|
|
11635
11815
|
* `splitText` splits the given node at the given offset.
|
|
11636
11816
|
*/
|
|
11637
11817
|
splitText(offset, absOffset) {
|
|
11818
|
+
const diff = { data: 0, meta: 0 };
|
|
11638
11819
|
if (offset === 0 || offset === this.size) {
|
|
11639
|
-
return;
|
|
11820
|
+
return [void 0, diff];
|
|
11640
11821
|
}
|
|
11641
11822
|
const leftValue = this.value.slice(0, offset);
|
|
11642
11823
|
const rightValue = this.value.slice(offset);
|
|
11643
11824
|
if (!rightValue.length) {
|
|
11644
|
-
return;
|
|
11825
|
+
return [void 0, diff];
|
|
11645
11826
|
}
|
|
11827
|
+
const prvSize = this.getDataSize();
|
|
11646
11828
|
this.value = leftValue;
|
|
11647
11829
|
const rightNode = this.cloneText(offset + absOffset);
|
|
11648
11830
|
rightNode.value = rightValue;
|
|
11649
11831
|
this.parent.insertAfterInternal(rightNode, this);
|
|
11650
|
-
|
|
11832
|
+
addDataSizes(diff, this.getDataSize(), rightNode.getDataSize());
|
|
11833
|
+
subDataSize(diff, prvSize);
|
|
11834
|
+
return [rightNode, diff];
|
|
11651
11835
|
}
|
|
11652
11836
|
/**
|
|
11653
11837
|
* `children` returns the children of the node.
|
|
@@ -11762,6 +11946,8 @@ class IndexTreeNode {
|
|
|
11762
11946
|
* `splitElement` splits the given element at the given offset.
|
|
11763
11947
|
*/
|
|
11764
11948
|
splitElement(offset, issueTimeTicket) {
|
|
11949
|
+
const diff = { data: 0, meta: 0 };
|
|
11950
|
+
const prvSize = this.getDataSize();
|
|
11765
11951
|
const clone = this.cloneElement(issueTimeTicket);
|
|
11766
11952
|
this.parent.insertAfterInternal(clone, this);
|
|
11767
11953
|
clone.updateAncestorsSize();
|
|
@@ -11780,7 +11966,9 @@ class IndexTreeNode {
|
|
|
11780
11966
|
for (const child of clone._children) {
|
|
11781
11967
|
child.parent = clone;
|
|
11782
11968
|
}
|
|
11783
|
-
|
|
11969
|
+
addDataSizes(diff, this.getDataSize(), clone.getDataSize());
|
|
11970
|
+
subDataSize(diff, prvSize);
|
|
11971
|
+
return [clone, diff];
|
|
11784
11972
|
}
|
|
11785
11973
|
/**
|
|
11786
11974
|
* `insertAfterInternal` inserts the given node after the given child.
|
|
@@ -12773,7 +12961,7 @@ class CRDTTreeNode extends IndexTreeNode {
|
|
|
12773
12961
|
* `split` splits the given offset of this node.
|
|
12774
12962
|
*/
|
|
12775
12963
|
split(tree, offset, issueTimeTicket) {
|
|
12776
|
-
const split = this.isText ? this.splitText(offset, this.id.getOffset()) : this.splitElement(offset, issueTimeTicket);
|
|
12964
|
+
const [split, diff] = this.isText ? this.splitText(offset, this.id.getOffset()) : this.splitElement(offset, issueTimeTicket);
|
|
12777
12965
|
if (split) {
|
|
12778
12966
|
split.insPrevID = this.id;
|
|
12779
12967
|
if (this.insNextID) {
|
|
@@ -12784,7 +12972,7 @@ class CRDTTreeNode extends IndexTreeNode {
|
|
|
12784
12972
|
this.insNextID = split.id;
|
|
12785
12973
|
tree.registerNode(split);
|
|
12786
12974
|
}
|
|
12787
|
-
return split;
|
|
12975
|
+
return [split, diff];
|
|
12788
12976
|
}
|
|
12789
12977
|
/**
|
|
12790
12978
|
* `getCreatedAt` returns the creation time of this element.
|
|
@@ -12975,15 +13163,17 @@ class CRDTTree extends CRDTElement {
|
|
|
12975
13163
|
* for concurrent insertion.
|
|
12976
13164
|
*/
|
|
12977
13165
|
findNodesAndSplitText(pos, editedAt) {
|
|
13166
|
+
let diff = { data: 0, meta: 0 };
|
|
12978
13167
|
const [parent, leftSibling] = pos.toTreeNodePair(this);
|
|
12979
13168
|
let leftNode = leftSibling;
|
|
12980
13169
|
const isLeftMost = parent === leftNode;
|
|
12981
13170
|
const realParent = leftNode.parent && !isLeftMost ? leftNode.parent : parent;
|
|
12982
13171
|
if (leftNode.isText) {
|
|
12983
|
-
leftNode.split(
|
|
13172
|
+
const [, splitedDiff] = leftNode.split(
|
|
12984
13173
|
this,
|
|
12985
13174
|
pos.getLeftSiblingID().getOffset() - leftNode.id.getOffset()
|
|
12986
13175
|
);
|
|
13176
|
+
diff = splitedDiff;
|
|
12987
13177
|
}
|
|
12988
13178
|
if (editedAt) {
|
|
12989
13179
|
const allChildren = realParent.allChildren;
|
|
@@ -12996,17 +13186,22 @@ class CRDTTree extends CRDTElement {
|
|
|
12996
13186
|
leftNode = next;
|
|
12997
13187
|
}
|
|
12998
13188
|
}
|
|
12999
|
-
return [realParent, leftNode];
|
|
13189
|
+
return [[realParent, leftNode], diff];
|
|
13000
13190
|
}
|
|
13001
13191
|
/**
|
|
13002
13192
|
* `style` applies the given attributes of the given range.
|
|
13003
13193
|
*/
|
|
13004
13194
|
style(range, attributes, editedAt, versionVector) {
|
|
13005
|
-
const
|
|
13195
|
+
const diff = { data: 0, meta: 0 };
|
|
13196
|
+
const [[fromParent, fromLeft], diffFrom] = this.findNodesAndSplitText(
|
|
13006
13197
|
range[0],
|
|
13007
13198
|
editedAt
|
|
13008
13199
|
);
|
|
13009
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(
|
|
13200
|
+
const [[toParent, toLeft], diffTo] = this.findNodesAndSplitText(
|
|
13201
|
+
range[1],
|
|
13202
|
+
editedAt
|
|
13203
|
+
);
|
|
13204
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
13010
13205
|
const changes = [];
|
|
13011
13206
|
const attrs = attributes ? parseObjectValues(attributes) : {};
|
|
13012
13207
|
const pairs = [];
|
|
@@ -13015,7 +13210,8 @@ class CRDTTree extends CRDTElement {
|
|
|
13015
13210
|
fromLeft,
|
|
13016
13211
|
toParent,
|
|
13017
13212
|
toLeft,
|
|
13018
|
-
([node]) => {
|
|
13213
|
+
([node, tokenType]) => {
|
|
13214
|
+
var _a2;
|
|
13019
13215
|
const actorID = node.getCreatedAt().getActorID();
|
|
13020
13216
|
let clientLamportAtChange = MaxLamport;
|
|
13021
13217
|
if (versionVector != void 0) {
|
|
@@ -13051,20 +13247,31 @@ class CRDTTree extends CRDTElement {
|
|
|
13051
13247
|
pairs.push({ parent: node, child: prev });
|
|
13052
13248
|
}
|
|
13053
13249
|
}
|
|
13250
|
+
for (const [key] of Object.entries(attrs)) {
|
|
13251
|
+
const curr = (_a2 = node.attrs) == null ? void 0 : _a2.getNodeMapByKey().get(key);
|
|
13252
|
+
if (curr !== void 0 && tokenType !== TokenType.End) {
|
|
13253
|
+
addDataSizes(diff, curr.getDataSize());
|
|
13254
|
+
}
|
|
13255
|
+
}
|
|
13054
13256
|
}
|
|
13055
13257
|
}
|
|
13056
13258
|
);
|
|
13057
|
-
return [pairs, changes];
|
|
13259
|
+
return [pairs, changes, diff];
|
|
13058
13260
|
}
|
|
13059
13261
|
/**
|
|
13060
13262
|
* `removeStyle` removes the given attributes of the given range.
|
|
13061
13263
|
*/
|
|
13062
13264
|
removeStyle(range, attributesToRemove, editedAt, versionVector) {
|
|
13063
|
-
const
|
|
13265
|
+
const diff = { data: 0, meta: 0 };
|
|
13266
|
+
const [[fromParent, fromLeft], diffFrom] = this.findNodesAndSplitText(
|
|
13064
13267
|
range[0],
|
|
13065
13268
|
editedAt
|
|
13066
13269
|
);
|
|
13067
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(
|
|
13270
|
+
const [[toParent, toLeft], diffTo] = this.findNodesAndSplitText(
|
|
13271
|
+
range[1],
|
|
13272
|
+
editedAt
|
|
13273
|
+
);
|
|
13274
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
13068
13275
|
const changes = [];
|
|
13069
13276
|
const pairs = [];
|
|
13070
13277
|
this.traverseInPosRange(
|
|
@@ -13102,18 +13309,23 @@ class CRDTTree extends CRDTElement {
|
|
|
13102
13309
|
}
|
|
13103
13310
|
}
|
|
13104
13311
|
);
|
|
13105
|
-
return [pairs, changes];
|
|
13312
|
+
return [pairs, changes, diff];
|
|
13106
13313
|
}
|
|
13107
13314
|
/**
|
|
13108
13315
|
* `edit` edits the tree with the given range and content.
|
|
13109
13316
|
* If the content is undefined, the range will be removed.
|
|
13110
13317
|
*/
|
|
13111
13318
|
edit(range, contents, splitLevel, editedAt, issueTimeTicket, versionVector) {
|
|
13112
|
-
const
|
|
13319
|
+
const diff = { data: 0, meta: 0 };
|
|
13320
|
+
const [[fromParent, fromLeft], diffFrom] = this.findNodesAndSplitText(
|
|
13113
13321
|
range[0],
|
|
13114
13322
|
editedAt
|
|
13115
13323
|
);
|
|
13116
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(
|
|
13324
|
+
const [[toParent, toLeft], diffTo] = this.findNodesAndSplitText(
|
|
13325
|
+
range[1],
|
|
13326
|
+
editedAt
|
|
13327
|
+
);
|
|
13328
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
13117
13329
|
const fromIdx = this.toIndex(fromParent, fromLeft);
|
|
13118
13330
|
const fromPath = this.toPath(fromParent, fromLeft);
|
|
13119
13331
|
const nodesToBeRemoved = [];
|
|
@@ -13192,6 +13404,8 @@ class CRDTTree extends CRDTElement {
|
|
|
13192
13404
|
if (fromParent.isRemoved) {
|
|
13193
13405
|
node.remove(editedAt);
|
|
13194
13406
|
pairs.push({ parent: this, child: node });
|
|
13407
|
+
} else {
|
|
13408
|
+
addDataSizes(diff, node.getDataSize());
|
|
13195
13409
|
}
|
|
13196
13410
|
this.nodeMapByID.put(node.id, node);
|
|
13197
13411
|
});
|
|
@@ -13216,7 +13430,7 @@ class CRDTTree extends CRDTElement {
|
|
|
13216
13430
|
}
|
|
13217
13431
|
}
|
|
13218
13432
|
}
|
|
13219
|
-
return [changes, pairs];
|
|
13433
|
+
return [changes, pairs, diff];
|
|
13220
13434
|
}
|
|
13221
13435
|
/**
|
|
13222
13436
|
* `editT` edits the given range with the given value.
|
|
@@ -13495,16 +13709,16 @@ class CRDTTree extends CRDTElement {
|
|
|
13495
13709
|
* `posRangeToPathRange` converts the given position range to the path range.
|
|
13496
13710
|
*/
|
|
13497
13711
|
posRangeToPathRange(range) {
|
|
13498
|
-
const [fromParent, fromLeft] = this.findNodesAndSplitText(range[0]);
|
|
13499
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(range[1]);
|
|
13712
|
+
const [[fromParent, fromLeft]] = this.findNodesAndSplitText(range[0]);
|
|
13713
|
+
const [[toParent, toLeft]] = this.findNodesAndSplitText(range[1]);
|
|
13500
13714
|
return [this.toPath(fromParent, fromLeft), this.toPath(toParent, toLeft)];
|
|
13501
13715
|
}
|
|
13502
13716
|
/**
|
|
13503
13717
|
* `posRangeToIndexRange` converts the given position range to the path range.
|
|
13504
13718
|
*/
|
|
13505
13719
|
posRangeToIndexRange(range) {
|
|
13506
|
-
const [fromParent, fromLeft] = this.findNodesAndSplitText(range[0]);
|
|
13507
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(range[1]);
|
|
13720
|
+
const [[fromParent, fromLeft]] = this.findNodesAndSplitText(range[0]);
|
|
13721
|
+
const [[toParent, toLeft]] = this.findNodesAndSplitText(range[1]);
|
|
13508
13722
|
return [this.toIndex(fromParent, fromLeft), this.toIndex(toParent, toLeft)];
|
|
13509
13723
|
}
|
|
13510
13724
|
/**
|
|
@@ -13699,7 +13913,7 @@ class TreeEditOperation extends Operation {
|
|
|
13699
13913
|
}
|
|
13700
13914
|
const editedAt = this.getExecutedAt();
|
|
13701
13915
|
const tree = parentObject;
|
|
13702
|
-
const [changes, pairs] = tree.edit(
|
|
13916
|
+
const [changes, pairs, diff] = tree.edit(
|
|
13703
13917
|
[this.fromPos, this.toPos],
|
|
13704
13918
|
(_a2 = this.contents) == null ? void 0 : _a2.map((content) => content.deepcopy()),
|
|
13705
13919
|
this.splitLevel,
|
|
@@ -13725,6 +13939,7 @@ class TreeEditOperation extends Operation {
|
|
|
13725
13939
|
})(),
|
|
13726
13940
|
versionVector
|
|
13727
13941
|
);
|
|
13942
|
+
root.acc(diff);
|
|
13728
13943
|
for (const pair of pairs) {
|
|
13729
13944
|
root.registerGCPair(pair);
|
|
13730
13945
|
}
|
|
@@ -14779,8 +14994,16 @@ class RGATreeSplit {
|
|
|
14779
14994
|
* @returns `[RGATreeSplitPos, Array<GCPair>, Array<Change>]`
|
|
14780
14995
|
*/
|
|
14781
14996
|
edit(range, editedAt, value, versionVector) {
|
|
14782
|
-
const
|
|
14783
|
-
const [
|
|
14997
|
+
const diff = { data: 0, meta: 0 };
|
|
14998
|
+
const [toLeft, diffTo, toRight] = this.findNodeWithSplit(
|
|
14999
|
+
range[1],
|
|
15000
|
+
editedAt
|
|
15001
|
+
);
|
|
15002
|
+
const [fromLeft, diffFrom, fromRight] = this.findNodeWithSplit(
|
|
15003
|
+
range[0],
|
|
15004
|
+
editedAt
|
|
15005
|
+
);
|
|
15006
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
14784
15007
|
const nodesToDelete = this.findBetween(fromRight, toRight);
|
|
14785
15008
|
const [changes, removedNodes] = this.deleteNodes(
|
|
14786
15009
|
nodesToDelete,
|
|
@@ -14795,6 +15018,7 @@ class RGATreeSplit {
|
|
|
14795
15018
|
fromLeft,
|
|
14796
15019
|
RGATreeSplitNode.create(RGATreeSplitNodeID.of(editedAt, 0), value)
|
|
14797
15020
|
);
|
|
15021
|
+
addDataSizes(diff, inserted.getDataSize());
|
|
14798
15022
|
if (changes.length && changes[changes.length - 1].from === idx) {
|
|
14799
15023
|
changes[changes.length - 1].value = value;
|
|
14800
15024
|
} else {
|
|
@@ -14814,7 +15038,7 @@ class RGATreeSplit {
|
|
|
14814
15038
|
for (const [, removedNode] of removedNodes) {
|
|
14815
15039
|
pairs.push({ parent: this, child: removedNode });
|
|
14816
15040
|
}
|
|
14817
|
-
return [caretPos, pairs, changes];
|
|
15041
|
+
return [caretPos, pairs, diff, changes];
|
|
14818
15042
|
}
|
|
14819
15043
|
/**
|
|
14820
15044
|
* `indexToPos` finds RGATreeSplitPos of given offset.
|
|
@@ -14953,11 +15177,11 @@ class RGATreeSplit {
|
|
|
14953
15177
|
const absoluteID = pos.getAbsoluteID();
|
|
14954
15178
|
let node = this.findFloorNodePreferToLeft(absoluteID);
|
|
14955
15179
|
const relativeOffset = absoluteID.getOffset() - node.getID().getOffset();
|
|
14956
|
-
this.splitNode(node, relativeOffset);
|
|
15180
|
+
const [, diff] = this.splitNode(node, relativeOffset);
|
|
14957
15181
|
while (node.hasNext() && node.getNext().getCreatedAt().after(editedAt)) {
|
|
14958
15182
|
node = node.getNext();
|
|
14959
15183
|
}
|
|
14960
|
-
return [node, node.getNext()];
|
|
15184
|
+
return [node, diff, node.getNext()];
|
|
14961
15185
|
}
|
|
14962
15186
|
findFloorNodePreferToLeft(id) {
|
|
14963
15187
|
let node = this.findFloorNode(id);
|
|
@@ -14998,6 +15222,7 @@ class RGATreeSplit {
|
|
|
14998
15222
|
return nodes;
|
|
14999
15223
|
}
|
|
15000
15224
|
splitNode(node, offset) {
|
|
15225
|
+
const diff = { data: 0, meta: 0 };
|
|
15001
15226
|
if (offset > node.getContentLength()) {
|
|
15002
15227
|
throw new YorkieError(
|
|
15003
15228
|
Code.ErrInvalidArgument,
|
|
@@ -15005,10 +15230,11 @@ class RGATreeSplit {
|
|
|
15005
15230
|
);
|
|
15006
15231
|
}
|
|
15007
15232
|
if (offset === 0) {
|
|
15008
|
-
return node;
|
|
15233
|
+
return [node, diff];
|
|
15009
15234
|
} else if (offset === node.getContentLength()) {
|
|
15010
|
-
return node.getNext();
|
|
15235
|
+
return [node.getNext(), diff];
|
|
15011
15236
|
}
|
|
15237
|
+
const prvSize = node.getDataSize();
|
|
15012
15238
|
const splitNode = node.split(offset);
|
|
15013
15239
|
this.treeByIndex.updateWeight(splitNode);
|
|
15014
15240
|
this.insertAfter(node, splitNode);
|
|
@@ -15017,7 +15243,9 @@ class RGATreeSplit {
|
|
|
15017
15243
|
insNext.setInsPrev(splitNode);
|
|
15018
15244
|
}
|
|
15019
15245
|
splitNode.setInsPrev(node);
|
|
15020
|
-
|
|
15246
|
+
addDataSizes(diff, node.getDataSize(), splitNode.getDataSize());
|
|
15247
|
+
subDataSize(diff, prvSize);
|
|
15248
|
+
return [splitNode, diff];
|
|
15021
15249
|
}
|
|
15022
15250
|
deleteNodes(candidates, editedAt, versionVector) {
|
|
15023
15251
|
if (!candidates.length) {
|
|
@@ -15486,10 +15714,11 @@ class TreeStyleOperation extends Operation {
|
|
|
15486
15714
|
const tree = parentObject;
|
|
15487
15715
|
let changes;
|
|
15488
15716
|
let pairs;
|
|
15717
|
+
let diff = { data: 0, meta: 0 };
|
|
15489
15718
|
if (this.attributes.size) {
|
|
15490
15719
|
const attributes = {};
|
|
15491
15720
|
[...this.attributes].forEach(([key, value]) => attributes[key] = value);
|
|
15492
|
-
[pairs, changes] = tree.style(
|
|
15721
|
+
[pairs, changes, diff] = tree.style(
|
|
15493
15722
|
[this.fromPos, this.toPos],
|
|
15494
15723
|
attributes,
|
|
15495
15724
|
this.getExecutedAt(),
|
|
@@ -15497,13 +15726,14 @@ class TreeStyleOperation extends Operation {
|
|
|
15497
15726
|
);
|
|
15498
15727
|
} else {
|
|
15499
15728
|
const attributesToRemove = this.attributesToRemove;
|
|
15500
|
-
[pairs, changes] = tree.removeStyle(
|
|
15729
|
+
[pairs, changes, diff] = tree.removeStyle(
|
|
15501
15730
|
[this.fromPos, this.toPos],
|
|
15502
15731
|
attributesToRemove,
|
|
15503
15732
|
this.getExecutedAt(),
|
|
15504
15733
|
versionVector
|
|
15505
15734
|
);
|
|
15506
15735
|
}
|
|
15736
|
+
root.acc(diff);
|
|
15507
15737
|
for (const pair of pairs) {
|
|
15508
15738
|
root.registerGCPair(pair);
|
|
15509
15739
|
}
|
|
@@ -17019,7 +17249,7 @@ class ChangeContext {
|
|
|
17019
17249
|
* document for the next change.returns the next ID of this context.
|
|
17020
17250
|
*/
|
|
17021
17251
|
getNextID() {
|
|
17022
|
-
if (this.
|
|
17252
|
+
if (this.isPresenceOnlyChange()) {
|
|
17023
17253
|
return this.prevID.next(true).setLamport(this.prevID.getLamport()).setVersionVector(this.prevID.getVersionVector());
|
|
17024
17254
|
}
|
|
17025
17255
|
return this.nextID;
|
|
@@ -17028,7 +17258,7 @@ class ChangeContext {
|
|
|
17028
17258
|
* `toChange` creates a new instance of Change in this context.
|
|
17029
17259
|
*/
|
|
17030
17260
|
toChange() {
|
|
17031
|
-
const id = this.
|
|
17261
|
+
const id = this.isPresenceOnlyChange() ? this.prevID.next(true) : this.nextID;
|
|
17032
17262
|
return Change.create({
|
|
17033
17263
|
id,
|
|
17034
17264
|
operations: this.operations,
|
|
@@ -17036,6 +17266,13 @@ class ChangeContext {
|
|
|
17036
17266
|
message: this.message
|
|
17037
17267
|
});
|
|
17038
17268
|
}
|
|
17269
|
+
/**
|
|
17270
|
+
* `isPresenceOnlyChange` returns whether this context is only for presence
|
|
17271
|
+
* change or not.
|
|
17272
|
+
*/
|
|
17273
|
+
isPresenceOnlyChange() {
|
|
17274
|
+
return this.operations.length === 0;
|
|
17275
|
+
}
|
|
17039
17276
|
/**
|
|
17040
17277
|
* `hasChange` returns whether this context has change or not.
|
|
17041
17278
|
*/
|
|
@@ -17084,6 +17321,12 @@ class ChangeContext {
|
|
|
17084
17321
|
getLastTimeTicket() {
|
|
17085
17322
|
return this.nextID.createTimeTicket(this.delimiter);
|
|
17086
17323
|
}
|
|
17324
|
+
/**
|
|
17325
|
+
* `acc` accumulates the given DataSize to Live size of the root.
|
|
17326
|
+
*/
|
|
17327
|
+
acc(diff) {
|
|
17328
|
+
this.root.acc(diff);
|
|
17329
|
+
}
|
|
17087
17330
|
}
|
|
17088
17331
|
class CRDTRoot {
|
|
17089
17332
|
constructor(rootObject) {
|
|
@@ -17107,10 +17350,15 @@ class CRDTRoot {
|
|
|
17107
17350
|
* element itself and its parent.
|
|
17108
17351
|
*/
|
|
17109
17352
|
__publicField(this, "gcPairMap");
|
|
17353
|
+
/**
|
|
17354
|
+
* `docSize` is a structure that represents the size of the document.
|
|
17355
|
+
*/
|
|
17356
|
+
__publicField(this, "docSize");
|
|
17110
17357
|
this.rootObject = rootObject;
|
|
17111
17358
|
this.elementPairMapByCreatedAt = /* @__PURE__ */ new Map();
|
|
17112
17359
|
this.gcElementSetByCreatedAt = /* @__PURE__ */ new Set();
|
|
17113
17360
|
this.gcPairMap = /* @__PURE__ */ new Map();
|
|
17361
|
+
this.docSize = { live: { data: 0, meta: 0 }, gc: { data: 0, meta: 0 } };
|
|
17114
17362
|
this.registerElement(rootObject, void 0);
|
|
17115
17363
|
rootObject.getDescendants((elem) => {
|
|
17116
17364
|
if (elem.getRemovedAt()) {
|
|
@@ -17187,9 +17435,14 @@ class CRDTRoot {
|
|
|
17187
17435
|
parent,
|
|
17188
17436
|
element
|
|
17189
17437
|
});
|
|
17438
|
+
addDataSizes(this.docSize.live, element.getDataSize());
|
|
17190
17439
|
if (element instanceof CRDTContainer) {
|
|
17191
|
-
element.getDescendants((elem,
|
|
17192
|
-
this.
|
|
17440
|
+
element.getDescendants((elem, par) => {
|
|
17441
|
+
this.elementPairMapByCreatedAt.set(elem.getCreatedAt().toIDString(), {
|
|
17442
|
+
parent: par,
|
|
17443
|
+
element: elem
|
|
17444
|
+
});
|
|
17445
|
+
addDataSizes(this.docSize.live, elem.getDataSize());
|
|
17193
17446
|
return false;
|
|
17194
17447
|
});
|
|
17195
17448
|
}
|
|
@@ -17201,6 +17454,7 @@ class CRDTRoot {
|
|
|
17201
17454
|
let count = 0;
|
|
17202
17455
|
const deregisterElementInternal = (elem) => {
|
|
17203
17456
|
const createdAt = elem.getCreatedAt().toIDString();
|
|
17457
|
+
subDataSize(this.docSize.gc, elem.getDataSize());
|
|
17204
17458
|
this.elementPairMapByCreatedAt.delete(createdAt);
|
|
17205
17459
|
this.gcElementSetByCreatedAt.delete(createdAt);
|
|
17206
17460
|
count++;
|
|
@@ -17218,6 +17472,9 @@ class CRDTRoot {
|
|
|
17218
17472
|
* `registerRemovedElement` registers the given element to the hash set.
|
|
17219
17473
|
*/
|
|
17220
17474
|
registerRemovedElement(element) {
|
|
17475
|
+
addDataSizes(this.docSize.gc, element.getDataSize());
|
|
17476
|
+
subDataSize(this.docSize.live, element.getDataSize());
|
|
17477
|
+
this.docSize.live.meta += TimeTicketSize;
|
|
17221
17478
|
this.gcElementSetByCreatedAt.add(element.getCreatedAt().toIDString());
|
|
17222
17479
|
}
|
|
17223
17480
|
/**
|
|
@@ -17230,6 +17487,12 @@ class CRDTRoot {
|
|
|
17230
17487
|
return;
|
|
17231
17488
|
}
|
|
17232
17489
|
this.gcPairMap.set(pair.child.toIDString(), pair);
|
|
17490
|
+
const size = this.gcPairMap.get(pair.child.toIDString()).child.getDataSize();
|
|
17491
|
+
addDataSizes(this.docSize.gc, size);
|
|
17492
|
+
subDataSize(this.docSize.live, size);
|
|
17493
|
+
if (!(pair.child instanceof RHTNode)) {
|
|
17494
|
+
this.docSize.live.meta += TimeTicketSize;
|
|
17495
|
+
}
|
|
17233
17496
|
}
|
|
17234
17497
|
/**
|
|
17235
17498
|
* `getElementMapSize` returns the size of element map.
|
|
@@ -17270,22 +17533,7 @@ class CRDTRoot {
|
|
|
17270
17533
|
* `getDocSize` returns the size of the document.
|
|
17271
17534
|
*/
|
|
17272
17535
|
getDocSize() {
|
|
17273
|
-
|
|
17274
|
-
for (const [createdAt, value] of this.elementPairMapByCreatedAt) {
|
|
17275
|
-
if (this.gcElementSetByCreatedAt.has(createdAt)) {
|
|
17276
|
-
docSize.gc.data += value.element.getDataSize().data;
|
|
17277
|
-
docSize.gc.meta += value.element.getDataSize().meta;
|
|
17278
|
-
} else {
|
|
17279
|
-
docSize.live.data += value.element.getDataSize().data;
|
|
17280
|
-
docSize.live.meta += value.element.getDataSize().meta;
|
|
17281
|
-
}
|
|
17282
|
-
}
|
|
17283
|
-
for (const pair of this.gcPairMap.values()) {
|
|
17284
|
-
const size = pair.child.getDataSize();
|
|
17285
|
-
docSize.gc.data += size.data;
|
|
17286
|
-
docSize.gc.meta += size.meta;
|
|
17287
|
-
}
|
|
17288
|
-
return docSize;
|
|
17536
|
+
return this.docSize;
|
|
17289
17537
|
}
|
|
17290
17538
|
/**
|
|
17291
17539
|
* `deepcopy` copies itself deeply.
|
|
@@ -17339,6 +17587,12 @@ class CRDTRoot {
|
|
|
17339
17587
|
gcElements: this.getGarbageElementSetSize()
|
|
17340
17588
|
};
|
|
17341
17589
|
}
|
|
17590
|
+
/**
|
|
17591
|
+
* `acc` accumulates the given DataSize to Live.
|
|
17592
|
+
*/
|
|
17593
|
+
acc(diff) {
|
|
17594
|
+
addDataSizes(this.docSize.live, diff);
|
|
17595
|
+
}
|
|
17342
17596
|
}
|
|
17343
17597
|
function createJSONObject(context, target) {
|
|
17344
17598
|
const objectProxy = new ObjectProxy(context);
|
|
@@ -17956,12 +18210,13 @@ class Text {
|
|
|
17956
18210
|
}
|
|
17957
18211
|
const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
|
|
17958
18212
|
const ticket = this.context.issueTimeTicket();
|
|
17959
|
-
const [, pairs, rangeAfterEdit] = this.text.edit(
|
|
18213
|
+
const [, pairs, diff, rangeAfterEdit] = this.text.edit(
|
|
17960
18214
|
range,
|
|
17961
18215
|
content,
|
|
17962
18216
|
ticket,
|
|
17963
18217
|
attrs
|
|
17964
18218
|
);
|
|
18219
|
+
this.context.acc(diff);
|
|
17965
18220
|
for (const pair of pairs) {
|
|
17966
18221
|
this.context.registerGCPair(pair);
|
|
17967
18222
|
}
|
|
@@ -18015,7 +18270,8 @@ class Text {
|
|
|
18015
18270
|
}
|
|
18016
18271
|
const attrs = stringifyObjectValues(attributes);
|
|
18017
18272
|
const ticket = this.context.issueTimeTicket();
|
|
18018
|
-
const [pairs] = this.text.setStyle(range, attrs, ticket);
|
|
18273
|
+
const [pairs, diff] = this.text.setStyle(range, attrs, ticket);
|
|
18274
|
+
this.context.acc(diff);
|
|
18019
18275
|
for (const pair of pairs) {
|
|
18020
18276
|
this.context.registerGCPair(pair);
|
|
18021
18277
|
}
|
|
@@ -18558,7 +18814,8 @@ class Tree {
|
|
|
18558
18814
|
const [fromPos, toPos] = this.tree.pathToPosRange(path);
|
|
18559
18815
|
const ticket = this.context.issueTimeTicket();
|
|
18560
18816
|
const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
|
|
18561
|
-
const [pairs] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18817
|
+
const [pairs, , diff] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18818
|
+
this.context.acc(diff);
|
|
18562
18819
|
for (const pair of pairs) {
|
|
18563
18820
|
this.context.registerGCPair(pair);
|
|
18564
18821
|
}
|
|
@@ -18592,7 +18849,8 @@ class Tree {
|
|
|
18592
18849
|
const toPos = this.tree.findPos(toIdx);
|
|
18593
18850
|
const ticket = this.context.issueTimeTicket();
|
|
18594
18851
|
const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
|
|
18595
|
-
const [pairs] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18852
|
+
const [pairs, , diff] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18853
|
+
this.context.acc(diff);
|
|
18596
18854
|
for (const pair of pairs) {
|
|
18597
18855
|
this.context.registerGCPair(pair);
|
|
18598
18856
|
}
|
|
@@ -18625,11 +18883,12 @@ class Tree {
|
|
|
18625
18883
|
const fromPos = this.tree.findPos(fromIdx);
|
|
18626
18884
|
const toPos = this.tree.findPos(toIdx);
|
|
18627
18885
|
const ticket = this.context.issueTimeTicket();
|
|
18628
|
-
const [pairs] = this.tree.removeStyle(
|
|
18886
|
+
const [pairs, , diff] = this.tree.removeStyle(
|
|
18629
18887
|
[fromPos, toPos],
|
|
18630
18888
|
attributesToRemove,
|
|
18631
18889
|
ticket
|
|
18632
18890
|
);
|
|
18891
|
+
this.context.acc(diff);
|
|
18633
18892
|
for (const pair of pairs) {
|
|
18634
18893
|
this.context.registerGCPair(pair);
|
|
18635
18894
|
}
|
|
@@ -18672,13 +18931,14 @@ class Tree {
|
|
|
18672
18931
|
} else {
|
|
18673
18932
|
crdtNodes = contents.map((content) => content && createCRDTTreeNode(this.context, content)).filter((a) => a);
|
|
18674
18933
|
}
|
|
18675
|
-
const [, pairs] = this.tree.edit(
|
|
18934
|
+
const [, pairs, diff] = this.tree.edit(
|
|
18676
18935
|
[fromPos, toPos],
|
|
18677
18936
|
crdtNodes.length ? crdtNodes.map((crdtNode) => crdtNode == null ? void 0 : crdtNode.deepcopy()) : void 0,
|
|
18678
18937
|
splitLevel,
|
|
18679
18938
|
ticket,
|
|
18680
18939
|
() => this.context.issueTimeTicket()
|
|
18681
18940
|
);
|
|
18941
|
+
this.context.acc(diff);
|
|
18682
18942
|
for (const pair of pairs) {
|
|
18683
18943
|
this.context.registerGCPair(pair);
|
|
18684
18944
|
}
|
|
@@ -19253,6 +19513,7 @@ class Document {
|
|
|
19253
19513
|
__publicField(this, "changeID");
|
|
19254
19514
|
__publicField(this, "checkpoint");
|
|
19255
19515
|
__publicField(this, "localChanges");
|
|
19516
|
+
__publicField(this, "maxSizeLimit");
|
|
19256
19517
|
__publicField(this, "root");
|
|
19257
19518
|
__publicField(this, "clone");
|
|
19258
19519
|
__publicField(this, "eventStream");
|
|
@@ -19285,6 +19546,7 @@ class Document {
|
|
|
19285
19546
|
this.changeID = InitialChangeID;
|
|
19286
19547
|
this.checkpoint = InitialCheckpoint;
|
|
19287
19548
|
this.localChanges = [];
|
|
19549
|
+
this.maxSizeLimit = 0;
|
|
19288
19550
|
this.eventStream = createObservable((observer) => {
|
|
19289
19551
|
this.eventStreamObserver = observer;
|
|
19290
19552
|
});
|
|
@@ -19304,6 +19566,7 @@ class Document {
|
|
|
19304
19566
|
* `update` executes the given updater to update this document.
|
|
19305
19567
|
*/
|
|
19306
19568
|
update(updater, message) {
|
|
19569
|
+
var _a2;
|
|
19307
19570
|
if (this.getStatus() === "removed") {
|
|
19308
19571
|
throw new YorkieError(Code.ErrDocumentRemoved, `${this.key} is removed`);
|
|
19309
19572
|
}
|
|
@@ -19334,6 +19597,14 @@ class Document {
|
|
|
19334
19597
|
} finally {
|
|
19335
19598
|
this.isUpdating = false;
|
|
19336
19599
|
}
|
|
19600
|
+
const size = totalDocSize((_a2 = this.clone) == null ? void 0 : _a2.root.getDocSize());
|
|
19601
|
+
if (!context.isPresenceOnlyChange() && this.maxSizeLimit > 0 && this.maxSizeLimit < size) {
|
|
19602
|
+
this.clone = void 0;
|
|
19603
|
+
throw new YorkieError(
|
|
19604
|
+
Code.ErrDocumentSizeExceedsLimit,
|
|
19605
|
+
`document size exceeded: ${size} > ${this.maxSizeLimit}`
|
|
19606
|
+
);
|
|
19607
|
+
}
|
|
19337
19608
|
if (context.hasChange()) {
|
|
19338
19609
|
if (logger.isEnabled(LogLevel.Trivial)) {
|
|
19339
19610
|
logger.trivial(`trying to update a local change: ${this.toJSON()}`);
|
|
@@ -19728,7 +19999,13 @@ class Document {
|
|
|
19728
19999
|
return this.status;
|
|
19729
20000
|
}
|
|
19730
20001
|
/**
|
|
19731
|
-
* `getClone`
|
|
20002
|
+
* `getClone` returns this clone.
|
|
20003
|
+
*/
|
|
20004
|
+
getClone() {
|
|
20005
|
+
return this.clone;
|
|
20006
|
+
}
|
|
20007
|
+
/**
|
|
20008
|
+
* `getCloneRoot` returns clone object.
|
|
19732
20009
|
*
|
|
19733
20010
|
* @internal
|
|
19734
20011
|
*/
|
|
@@ -19756,6 +20033,18 @@ class Document {
|
|
|
19756
20033
|
getDocSize() {
|
|
19757
20034
|
return this.root.getDocSize();
|
|
19758
20035
|
}
|
|
20036
|
+
/**
|
|
20037
|
+
* `getMaxSizePerDocument` gets the maximum size of this document.
|
|
20038
|
+
*/
|
|
20039
|
+
getMaxSizePerDocument() {
|
|
20040
|
+
return this.maxSizeLimit;
|
|
20041
|
+
}
|
|
20042
|
+
/**
|
|
20043
|
+
* `setMaxSizePerDocument` sets the maximum size of this document.
|
|
20044
|
+
*/
|
|
20045
|
+
setMaxSizePerDocument(size) {
|
|
20046
|
+
this.maxSizeLimit = size;
|
|
20047
|
+
}
|
|
19759
20048
|
/**
|
|
19760
20049
|
* `garbageCollect` purges elements that were removed before the given time.
|
|
19761
20050
|
*
|
|
@@ -20457,7 +20746,7 @@ function createAuthInterceptor(apiKey, token) {
|
|
|
20457
20746
|
};
|
|
20458
20747
|
}
|
|
20459
20748
|
const name = "@yorkie-js/sdk";
|
|
20460
|
-
const version = "0.6.
|
|
20749
|
+
const version = "0.6.14";
|
|
20461
20750
|
const pkg = {
|
|
20462
20751
|
name,
|
|
20463
20752
|
version
|
|
@@ -20687,6 +20976,10 @@ class Client {
|
|
|
20687
20976
|
},
|
|
20688
20977
|
{ headers: { "x-shard-key": `${this.apiKey}/${doc.getKey()}` } }
|
|
20689
20978
|
);
|
|
20979
|
+
const maxSize = res.maxSizePerDocument ?? 0;
|
|
20980
|
+
if (maxSize > 0) {
|
|
20981
|
+
doc.setMaxSizePerDocument(res.maxSizePerDocument);
|
|
20982
|
+
}
|
|
20690
20983
|
const pack = converter.fromChangePack(res.changePack);
|
|
20691
20984
|
doc.applyChangePack(pack);
|
|
20692
20985
|
if (doc.getStatus() === DocStatus.Removed) {
|