@liveblocks/core 3.23.1-exp1 → 3.23.1-exp3
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/index.cjs +399 -251
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +180 -167
- package/dist/index.d.ts +180 -167
- package/dist/index.js +326 -178
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.23.1-
|
|
9
|
+
var PKG_VERSION = "3.23.1-exp3";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -1107,7 +1107,6 @@ function* nodeStreamToCompactNodes(nodes) {
|
|
|
1107
1107
|
|
|
1108
1108
|
// src/internal.ts
|
|
1109
1109
|
var kInternal = /* @__PURE__ */ Symbol();
|
|
1110
|
-
var kStorageUpdateSource = /* @__PURE__ */ Symbol();
|
|
1111
1110
|
|
|
1112
1111
|
// src/lib/position.ts
|
|
1113
1112
|
var MIN_CODE = 32;
|
|
@@ -1288,6 +1287,18 @@ function asPos(str) {
|
|
|
1288
1287
|
return isPos(str) ? str : convertToPos(str);
|
|
1289
1288
|
}
|
|
1290
1289
|
|
|
1290
|
+
// src/crdts/StorageUpdates.ts
|
|
1291
|
+
var REMOTE = freeze({ origin: "remote" });
|
|
1292
|
+
var LOCAL_EDIT = freeze({ origin: "local", via: "edit" });
|
|
1293
|
+
var LOCAL_UNDO = freeze({ origin: "local", via: "undo" });
|
|
1294
|
+
var LOCAL_REDO = freeze({ origin: "local", via: "redo" });
|
|
1295
|
+
function toUpdateSource(source) {
|
|
1296
|
+
return source.origin === "remote" ? source : (
|
|
1297
|
+
// Removes `optimistic` field, which is not public
|
|
1298
|
+
{ origin: "local", via: source.via }
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1291
1302
|
// src/crdts/UnacknowledgedOps.ts
|
|
1292
1303
|
var UnacknowledgedOps = class {
|
|
1293
1304
|
// opId -> op
|
|
@@ -1496,11 +1507,14 @@ var AbstractCrdt = class {
|
|
|
1496
1507
|
}
|
|
1497
1508
|
}
|
|
1498
1509
|
/** @internal */
|
|
1499
|
-
_apply(op,
|
|
1510
|
+
_apply(op, source) {
|
|
1500
1511
|
switch (op.type) {
|
|
1501
1512
|
case OpCode.DELETE_CRDT: {
|
|
1502
1513
|
if (this.parent.type === "HasParent") {
|
|
1503
|
-
return this.parent.node._detachChild(
|
|
1514
|
+
return this.parent.node._detachChild(
|
|
1515
|
+
crdtAsLiveNode(this),
|
|
1516
|
+
toUpdateSource(source)
|
|
1517
|
+
);
|
|
1504
1518
|
}
|
|
1505
1519
|
return { modified: false };
|
|
1506
1520
|
}
|
|
@@ -1690,8 +1704,8 @@ var LiveFile = class _LiveFile extends AbstractCrdt {
|
|
|
1690
1704
|
throw new Error("A LiveFile node cannot have children");
|
|
1691
1705
|
}
|
|
1692
1706
|
/** @internal */
|
|
1693
|
-
_apply(op,
|
|
1694
|
-
return super._apply(op,
|
|
1707
|
+
_apply(op, source) {
|
|
1708
|
+
return super._apply(op, source);
|
|
1695
1709
|
}
|
|
1696
1710
|
/** @internal */
|
|
1697
1711
|
_toTreeNode(key) {
|
|
@@ -6911,8 +6925,8 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
6911
6925
|
throw new Error("Method not implemented.");
|
|
6912
6926
|
}
|
|
6913
6927
|
/** @internal */
|
|
6914
|
-
_apply(op,
|
|
6915
|
-
return super._apply(op,
|
|
6928
|
+
_apply(op, source) {
|
|
6929
|
+
return super._apply(op, source);
|
|
6916
6930
|
}
|
|
6917
6931
|
/** @internal */
|
|
6918
6932
|
_toTreeNode(key) {
|
|
@@ -7073,7 +7087,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7073
7087
|
item._detach();
|
|
7074
7088
|
}
|
|
7075
7089
|
}
|
|
7076
|
-
#
|
|
7090
|
+
#applyRemoteSet(op) {
|
|
7077
7091
|
if (this._pool === void 0) {
|
|
7078
7092
|
throw new Error("Can't attach child if managed pool is not present");
|
|
7079
7093
|
}
|
|
@@ -7091,9 +7105,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7091
7105
|
itemWithSamePosition._detach();
|
|
7092
7106
|
this.#items.add(child);
|
|
7093
7107
|
return {
|
|
7094
|
-
modified: makeUpdate(
|
|
7095
|
-
|
|
7096
|
-
|
|
7108
|
+
modified: makeUpdate(
|
|
7109
|
+
this,
|
|
7110
|
+
[setDelta(indexOfItemWithSamePosition, child)],
|
|
7111
|
+
REMOTE
|
|
7112
|
+
),
|
|
7097
7113
|
reverse: []
|
|
7098
7114
|
};
|
|
7099
7115
|
} else {
|
|
@@ -7104,20 +7120,22 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7104
7120
|
setDelta(indexOfItemWithSamePosition, child)
|
|
7105
7121
|
];
|
|
7106
7122
|
const deleteDelta2 = this.#detachItemAssociatedToSetOperation(
|
|
7107
|
-
op.deletedId
|
|
7123
|
+
op.deletedId,
|
|
7124
|
+
REMOTE
|
|
7108
7125
|
);
|
|
7109
7126
|
if (deleteDelta2) {
|
|
7110
7127
|
delta.push(deleteDelta2);
|
|
7111
7128
|
}
|
|
7112
7129
|
return {
|
|
7113
|
-
modified: makeUpdate(this, delta),
|
|
7130
|
+
modified: makeUpdate(this, delta, REMOTE),
|
|
7114
7131
|
reverse: []
|
|
7115
7132
|
};
|
|
7116
7133
|
}
|
|
7117
7134
|
} else {
|
|
7118
7135
|
const updates = [];
|
|
7119
7136
|
const deleteDelta2 = this.#detachItemAssociatedToSetOperation(
|
|
7120
|
-
op.deletedId
|
|
7137
|
+
op.deletedId,
|
|
7138
|
+
REMOTE
|
|
7121
7139
|
);
|
|
7122
7140
|
if (deleteDelta2) {
|
|
7123
7141
|
updates.push(deleteDelta2);
|
|
@@ -7126,29 +7144,32 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7126
7144
|
updates.push(insertDelta(this._indexOfPosition(key), child));
|
|
7127
7145
|
return {
|
|
7128
7146
|
reverse: [],
|
|
7129
|
-
modified: makeUpdate(this, updates)
|
|
7147
|
+
modified: makeUpdate(this, updates, REMOTE)
|
|
7130
7148
|
};
|
|
7131
7149
|
}
|
|
7132
7150
|
}
|
|
7133
|
-
#applySetAck(op) {
|
|
7151
|
+
#applySetAck(op, source) {
|
|
7134
7152
|
if (this._pool === void 0) {
|
|
7135
7153
|
throw new Error("Can't attach child if managed pool is not present");
|
|
7136
7154
|
}
|
|
7137
7155
|
const delta = [];
|
|
7138
|
-
const deletedDelta = this.#detachItemAssociatedToSetOperation(
|
|
7156
|
+
const deletedDelta = this.#detachItemAssociatedToSetOperation(
|
|
7157
|
+
op.deletedId,
|
|
7158
|
+
source
|
|
7159
|
+
);
|
|
7139
7160
|
if (deletedDelta) {
|
|
7140
7161
|
delta.push(deletedDelta);
|
|
7141
7162
|
}
|
|
7142
7163
|
const unacknowledgedOpId = this.#unacknowledgedSetOpIdAt(op.parentKey);
|
|
7143
7164
|
if (unacknowledgedOpId !== void 0 && unacknowledgedOpId !== op.opId) {
|
|
7144
|
-
return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
|
|
7165
|
+
return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta, source), reverse: [] };
|
|
7145
7166
|
}
|
|
7146
7167
|
const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
|
|
7147
7168
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
7148
7169
|
if (existingItem !== void 0) {
|
|
7149
7170
|
if (existingItem._parentKey === op.parentKey) {
|
|
7150
7171
|
return {
|
|
7151
|
-
modified: delta.length > 0 ? makeUpdate(this, delta) : false,
|
|
7172
|
+
modified: delta.length > 0 ? makeUpdate(this, delta, source) : false,
|
|
7152
7173
|
reverse: []
|
|
7153
7174
|
};
|
|
7154
7175
|
}
|
|
@@ -7166,7 +7187,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7166
7187
|
delta.push(moveDelta(prevIndex, newIndex, existingItem));
|
|
7167
7188
|
}
|
|
7168
7189
|
return {
|
|
7169
|
-
modified: delta.length > 0 ? makeUpdate(this, delta) : false,
|
|
7190
|
+
modified: delta.length > 0 ? makeUpdate(this, delta, source) : false,
|
|
7170
7191
|
reverse: []
|
|
7171
7192
|
};
|
|
7172
7193
|
} else {
|
|
@@ -7176,11 +7197,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7176
7197
|
this.#implicitlyDeletedItems.delete(orphan);
|
|
7177
7198
|
const recreatedItemIndex = this.#insert(orphan);
|
|
7178
7199
|
return {
|
|
7179
|
-
modified: makeUpdate(
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7200
|
+
modified: makeUpdate(
|
|
7201
|
+
this,
|
|
7202
|
+
[
|
|
7203
|
+
// If there is an item at this position, update is a set, else it's an insert
|
|
7204
|
+
indexOfItemWithSamePosition === -1 ? insertDelta(recreatedItemIndex, orphan) : setDelta(recreatedItemIndex, orphan),
|
|
7205
|
+
...delta
|
|
7206
|
+
],
|
|
7207
|
+
source
|
|
7208
|
+
),
|
|
7184
7209
|
reverse: []
|
|
7185
7210
|
};
|
|
7186
7211
|
} else {
|
|
@@ -7195,11 +7220,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7195
7220
|
op.parentKey
|
|
7196
7221
|
);
|
|
7197
7222
|
return {
|
|
7198
|
-
modified: makeUpdate(
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7223
|
+
modified: makeUpdate(
|
|
7224
|
+
this,
|
|
7225
|
+
[
|
|
7226
|
+
// If there is an item at this position, update is a set, else it's an insert
|
|
7227
|
+
indexOfItemWithSamePosition === -1 ? insertDelta(newIndex, newItem) : setDelta(newIndex, newItem),
|
|
7228
|
+
...delta
|
|
7229
|
+
],
|
|
7230
|
+
source
|
|
7231
|
+
),
|
|
7203
7232
|
reverse: []
|
|
7204
7233
|
};
|
|
7205
7234
|
}
|
|
@@ -7208,7 +7237,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7208
7237
|
/**
|
|
7209
7238
|
* Returns the update delta of the deletion or null
|
|
7210
7239
|
*/
|
|
7211
|
-
#detachItemAssociatedToSetOperation(deletedId) {
|
|
7240
|
+
#detachItemAssociatedToSetOperation(deletedId, source) {
|
|
7212
7241
|
if (deletedId === void 0 || this._pool === void 0) {
|
|
7213
7242
|
return null;
|
|
7214
7243
|
}
|
|
@@ -7216,7 +7245,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7216
7245
|
if (deletedItem === void 0) {
|
|
7217
7246
|
return null;
|
|
7218
7247
|
}
|
|
7219
|
-
const result = this._detachChild(deletedItem);
|
|
7248
|
+
const result = this._detachChild(deletedItem, source);
|
|
7220
7249
|
if (result.modified === false) {
|
|
7221
7250
|
return null;
|
|
7222
7251
|
}
|
|
@@ -7234,10 +7263,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7234
7263
|
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
7235
7264
|
const bumpDeltas = this.#bumpUnackedPushesAbove(key);
|
|
7236
7265
|
return {
|
|
7237
|
-
modified: makeUpdate(
|
|
7238
|
-
|
|
7239
|
-
...bumpDeltas
|
|
7240
|
-
|
|
7266
|
+
modified: makeUpdate(
|
|
7267
|
+
this,
|
|
7268
|
+
[insertDelta(newIndex, newItem), ...bumpDeltas],
|
|
7269
|
+
REMOTE
|
|
7270
|
+
),
|
|
7241
7271
|
reverse: []
|
|
7242
7272
|
};
|
|
7243
7273
|
}
|
|
@@ -7318,7 +7348,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7318
7348
|
}
|
|
7319
7349
|
return deltas;
|
|
7320
7350
|
}
|
|
7321
|
-
#applyInsertAck(op) {
|
|
7351
|
+
#applyInsertAck(op, source) {
|
|
7322
7352
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
7323
7353
|
const key = asPos(op.parentKey);
|
|
7324
7354
|
const itemIndexAtPosition = this._indexOfPosition(key);
|
|
@@ -7340,9 +7370,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7340
7370
|
return { modified: false };
|
|
7341
7371
|
}
|
|
7342
7372
|
return {
|
|
7343
|
-
modified: makeUpdate(
|
|
7344
|
-
|
|
7345
|
-
|
|
7373
|
+
modified: makeUpdate(
|
|
7374
|
+
this,
|
|
7375
|
+
[moveDelta(oldPositionIndex, newIndex, existingItem)],
|
|
7376
|
+
source
|
|
7377
|
+
),
|
|
7346
7378
|
reverse: []
|
|
7347
7379
|
};
|
|
7348
7380
|
}
|
|
@@ -7354,7 +7386,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7354
7386
|
this.#insert(orphan);
|
|
7355
7387
|
const newIndex = this._indexOfPosition(key);
|
|
7356
7388
|
return {
|
|
7357
|
-
modified: makeUpdate(this, [insertDelta(newIndex, orphan)]),
|
|
7389
|
+
modified: makeUpdate(this, [insertDelta(newIndex, orphan)], source),
|
|
7358
7390
|
reverse: []
|
|
7359
7391
|
};
|
|
7360
7392
|
} else {
|
|
@@ -7363,13 +7395,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7363
7395
|
}
|
|
7364
7396
|
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
7365
7397
|
return {
|
|
7366
|
-
modified: makeUpdate(this, [insertDelta(newIndex, newItem)]),
|
|
7398
|
+
modified: makeUpdate(this, [insertDelta(newIndex, newItem)], source),
|
|
7367
7399
|
reverse: []
|
|
7368
7400
|
};
|
|
7369
7401
|
}
|
|
7370
7402
|
}
|
|
7371
7403
|
}
|
|
7372
|
-
#
|
|
7404
|
+
#applyLocalInsert(op, source) {
|
|
7373
7405
|
const { id, parentKey: key } = op;
|
|
7374
7406
|
const child = creationOpToLiveNode(op);
|
|
7375
7407
|
if (_optionalChain([this, 'access', _151 => _151._pool, 'optionalAccess', _152 => _152.getNode, 'call', _153 => _153(id)]) !== void 0) {
|
|
@@ -7388,11 +7420,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7388
7420
|
this.#insert(child);
|
|
7389
7421
|
const newIndex = this._indexOfPosition(newKey);
|
|
7390
7422
|
return {
|
|
7391
|
-
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
7423
|
+
modified: makeUpdate(this, [insertDelta(newIndex, child)], source),
|
|
7392
7424
|
reverse: [{ type: OpCode.DELETE_CRDT, id }]
|
|
7393
7425
|
};
|
|
7394
7426
|
}
|
|
7395
|
-
#
|
|
7427
|
+
#applyLocalSet(op, source) {
|
|
7396
7428
|
const { id, parentKey: key } = op;
|
|
7397
7429
|
const child = creationOpToLiveNode(op);
|
|
7398
7430
|
if (_optionalChain([this, 'access', _162 => _162._pool, 'optionalAccess', _163 => _163.getNode, 'call', _164 => _164(id)]) !== void 0) {
|
|
@@ -7414,46 +7446,48 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7414
7446
|
);
|
|
7415
7447
|
const delta = [setDelta(indexOfItemWithSameKey, child)];
|
|
7416
7448
|
const deletedDelta = this.#detachItemAssociatedToSetOperation(
|
|
7417
|
-
op.deletedId
|
|
7449
|
+
op.deletedId,
|
|
7450
|
+
source
|
|
7418
7451
|
);
|
|
7419
7452
|
if (deletedDelta) {
|
|
7420
7453
|
delta.push(deletedDelta);
|
|
7421
7454
|
}
|
|
7422
7455
|
return {
|
|
7423
|
-
modified: makeUpdate(this, delta),
|
|
7456
|
+
modified: makeUpdate(this, delta, source),
|
|
7424
7457
|
reverse
|
|
7425
7458
|
};
|
|
7426
7459
|
} else {
|
|
7427
7460
|
this.#insert(child);
|
|
7428
|
-
this.#detachItemAssociatedToSetOperation(op.deletedId);
|
|
7461
|
+
this.#detachItemAssociatedToSetOperation(op.deletedId, source);
|
|
7429
7462
|
const newIndex = this._indexOfPosition(newKey);
|
|
7430
7463
|
return {
|
|
7431
7464
|
reverse: [{ type: OpCode.DELETE_CRDT, id }],
|
|
7432
|
-
modified: makeUpdate(this, [insertDelta(newIndex, child)])
|
|
7465
|
+
modified: makeUpdate(this, [insertDelta(newIndex, child)], source)
|
|
7433
7466
|
};
|
|
7434
7467
|
}
|
|
7435
7468
|
}
|
|
7436
7469
|
/** @internal */
|
|
7437
|
-
_attachChild(op,
|
|
7470
|
+
_attachChild(op, opSource) {
|
|
7471
|
+
const source = toUpdateSource(opSource);
|
|
7438
7472
|
if (this._pool === void 0) {
|
|
7439
7473
|
throw new Error("Can't attach child if managed pool is not present");
|
|
7440
7474
|
}
|
|
7441
7475
|
let result;
|
|
7442
7476
|
if (op.intent === "set") {
|
|
7443
|
-
if (
|
|
7444
|
-
result = this.#
|
|
7445
|
-
} else if (
|
|
7446
|
-
result = this.#applySetAck(op);
|
|
7477
|
+
if (opSource.origin === "remote") {
|
|
7478
|
+
result = this.#applyRemoteSet(op);
|
|
7479
|
+
} else if (!opSource.optimistic) {
|
|
7480
|
+
result = this.#applySetAck(op, source);
|
|
7447
7481
|
} else {
|
|
7448
|
-
result = this.#
|
|
7482
|
+
result = this.#applyLocalSet(op, source);
|
|
7449
7483
|
}
|
|
7450
7484
|
} else {
|
|
7451
|
-
if (
|
|
7485
|
+
if (opSource.origin === "remote") {
|
|
7452
7486
|
result = this.#applyRemoteInsert(op);
|
|
7453
|
-
} else if (
|
|
7454
|
-
result = this.#applyInsertAck(op);
|
|
7487
|
+
} else if (!opSource.optimistic) {
|
|
7488
|
+
result = this.#applyInsertAck(op, source);
|
|
7455
7489
|
} else {
|
|
7456
|
-
result = this.#
|
|
7490
|
+
result = this.#applyLocalInsert(op, source);
|
|
7457
7491
|
}
|
|
7458
7492
|
}
|
|
7459
7493
|
if (result.modified !== false) {
|
|
@@ -7462,7 +7496,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7462
7496
|
return result;
|
|
7463
7497
|
}
|
|
7464
7498
|
/** @internal */
|
|
7465
|
-
_detachChild(child) {
|
|
7499
|
+
_detachChild(child, source) {
|
|
7466
7500
|
if (child) {
|
|
7467
7501
|
const parentKey = nn(child._parentKey);
|
|
7468
7502
|
const reverse = child._toOps(nn(this._id), parentKey);
|
|
@@ -7477,19 +7511,23 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7477
7511
|
this.invalidate();
|
|
7478
7512
|
child._detach();
|
|
7479
7513
|
return {
|
|
7480
|
-
modified: makeUpdate(
|
|
7514
|
+
modified: makeUpdate(
|
|
7515
|
+
this,
|
|
7516
|
+
[deleteDelta(indexToDelete, previousNode)],
|
|
7517
|
+
source
|
|
7518
|
+
),
|
|
7481
7519
|
reverse
|
|
7482
7520
|
};
|
|
7483
7521
|
}
|
|
7484
7522
|
return { modified: false };
|
|
7485
7523
|
}
|
|
7486
|
-
#
|
|
7524
|
+
#applyRemoteSetChildKey(newKey, child) {
|
|
7487
7525
|
if (this.#implicitlyDeletedItems.has(child)) {
|
|
7488
7526
|
this.#implicitlyDeletedItems.delete(child);
|
|
7489
7527
|
child._setParentLink(this, newKey);
|
|
7490
7528
|
const newIndex = this.#insert(child);
|
|
7491
7529
|
return {
|
|
7492
|
-
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
7530
|
+
modified: makeUpdate(this, [insertDelta(newIndex, child)], REMOTE),
|
|
7493
7531
|
reverse: []
|
|
7494
7532
|
};
|
|
7495
7533
|
}
|
|
@@ -7510,7 +7548,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7510
7548
|
};
|
|
7511
7549
|
}
|
|
7512
7550
|
return {
|
|
7513
|
-
modified: makeUpdate(
|
|
7551
|
+
modified: makeUpdate(
|
|
7552
|
+
this,
|
|
7553
|
+
[moveDelta(previousIndex, newIndex, child)],
|
|
7554
|
+
REMOTE
|
|
7555
|
+
),
|
|
7514
7556
|
reverse: []
|
|
7515
7557
|
};
|
|
7516
7558
|
} else {
|
|
@@ -7527,12 +7569,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7527
7569
|
};
|
|
7528
7570
|
}
|
|
7529
7571
|
return {
|
|
7530
|
-
modified: makeUpdate(
|
|
7572
|
+
modified: makeUpdate(
|
|
7573
|
+
this,
|
|
7574
|
+
[moveDelta(previousIndex, newIndex, child)],
|
|
7575
|
+
REMOTE
|
|
7576
|
+
),
|
|
7531
7577
|
reverse: []
|
|
7532
7578
|
};
|
|
7533
7579
|
}
|
|
7534
7580
|
}
|
|
7535
|
-
#applySetChildKeyAck(newKey, child) {
|
|
7581
|
+
#applySetChildKeyAck(newKey, child, source) {
|
|
7536
7582
|
const previousKey = nn(child._parentKey);
|
|
7537
7583
|
if (this.#implicitlyDeletedItems.has(child)) {
|
|
7538
7584
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
@@ -7551,7 +7597,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7551
7597
|
child._setParentLink(this, newKey);
|
|
7552
7598
|
const newIndex = this.#insert(child);
|
|
7553
7599
|
return {
|
|
7554
|
-
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
7600
|
+
modified: makeUpdate(this, [insertDelta(newIndex, child)], source),
|
|
7555
7601
|
reverse: []
|
|
7556
7602
|
};
|
|
7557
7603
|
} else {
|
|
@@ -7579,15 +7625,17 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7579
7625
|
};
|
|
7580
7626
|
} else {
|
|
7581
7627
|
return {
|
|
7582
|
-
modified: makeUpdate(
|
|
7583
|
-
|
|
7584
|
-
|
|
7628
|
+
modified: makeUpdate(
|
|
7629
|
+
this,
|
|
7630
|
+
[moveDelta(previousIndex, newIndex, child)],
|
|
7631
|
+
source
|
|
7632
|
+
),
|
|
7585
7633
|
reverse: []
|
|
7586
7634
|
};
|
|
7587
7635
|
}
|
|
7588
7636
|
}
|
|
7589
7637
|
}
|
|
7590
|
-
#
|
|
7638
|
+
#applyLocalSetChildKey(newKey, child, source) {
|
|
7591
7639
|
const previousKey = nn(child._parentKey);
|
|
7592
7640
|
const previousIndex = this.#items.findIndex((item) => item === child);
|
|
7593
7641
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
@@ -7606,7 +7654,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7606
7654
|
};
|
|
7607
7655
|
}
|
|
7608
7656
|
return {
|
|
7609
|
-
modified: makeUpdate(
|
|
7657
|
+
modified: makeUpdate(
|
|
7658
|
+
this,
|
|
7659
|
+
[moveDelta(previousIndex, newIndex, child)],
|
|
7660
|
+
source
|
|
7661
|
+
),
|
|
7610
7662
|
reverse: [
|
|
7611
7663
|
{
|
|
7612
7664
|
type: OpCode.SET_PARENT_KEY,
|
|
@@ -7617,18 +7669,19 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7617
7669
|
};
|
|
7618
7670
|
}
|
|
7619
7671
|
/** @internal */
|
|
7620
|
-
_setChildKey(newKey, child,
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7672
|
+
_setChildKey(newKey, child, opSource) {
|
|
7673
|
+
const source = toUpdateSource(opSource);
|
|
7674
|
+
if (opSource.origin === "remote") {
|
|
7675
|
+
return this.#applyRemoteSetChildKey(newKey, child);
|
|
7676
|
+
} else if (!opSource.optimistic) {
|
|
7677
|
+
return this.#applySetChildKeyAck(newKey, child, source);
|
|
7625
7678
|
} else {
|
|
7626
|
-
return this.#
|
|
7679
|
+
return this.#applyLocalSetChildKey(newKey, child, source);
|
|
7627
7680
|
}
|
|
7628
7681
|
}
|
|
7629
7682
|
/** @internal */
|
|
7630
|
-
_apply(op,
|
|
7631
|
-
return super._apply(op,
|
|
7683
|
+
_apply(op, source) {
|
|
7684
|
+
return super._apply(op, source);
|
|
7632
7685
|
}
|
|
7633
7686
|
/** @internal */
|
|
7634
7687
|
_serialize() {
|
|
@@ -7689,7 +7742,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7689
7742
|
intent === "push" ? addIntentToRootOp(ops, "push") : ops,
|
|
7690
7743
|
[{ type: OpCode.DELETE_CRDT, id }],
|
|
7691
7744
|
/* @__PURE__ */ new Map([
|
|
7692
|
-
[this._id, makeUpdate(this, [insertDelta(index, value)])]
|
|
7745
|
+
[this._id, makeUpdate(this, [insertDelta(index, value)], LOCAL_EDIT)]
|
|
7693
7746
|
])
|
|
7694
7747
|
);
|
|
7695
7748
|
}
|
|
@@ -7730,7 +7783,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7730
7783
|
this.#updateItemPositionAt(index, position);
|
|
7731
7784
|
if (this._pool && this._id) {
|
|
7732
7785
|
const storageUpdates = /* @__PURE__ */ new Map([
|
|
7733
|
-
[
|
|
7786
|
+
[
|
|
7787
|
+
this._id,
|
|
7788
|
+
makeUpdate(this, [moveDelta(index, targetIndex, item)], LOCAL_EDIT)
|
|
7789
|
+
]
|
|
7734
7790
|
]);
|
|
7735
7791
|
this._pool.dispatch(
|
|
7736
7792
|
[
|
|
@@ -7773,7 +7829,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7773
7829
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7774
7830
|
storageUpdates.set(
|
|
7775
7831
|
nn(this._id),
|
|
7776
|
-
makeUpdate(this, [deleteDelta(index, item)])
|
|
7832
|
+
makeUpdate(this, [deleteDelta(index, item)], LOCAL_EDIT)
|
|
7777
7833
|
);
|
|
7778
7834
|
this._pool.dispatch(
|
|
7779
7835
|
[
|
|
@@ -7813,7 +7869,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7813
7869
|
this.#items.clear();
|
|
7814
7870
|
this.invalidate();
|
|
7815
7871
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7816
|
-
storageUpdates.set(
|
|
7872
|
+
storageUpdates.set(
|
|
7873
|
+
nn(this._id),
|
|
7874
|
+
makeUpdate(this, updateDelta, LOCAL_EDIT)
|
|
7875
|
+
);
|
|
7817
7876
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
7818
7877
|
} else {
|
|
7819
7878
|
for (const item of this.#items) {
|
|
@@ -7843,7 +7902,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7843
7902
|
const id = this._pool.generateId();
|
|
7844
7903
|
value._attach(id, this._pool);
|
|
7845
7904
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7846
|
-
storageUpdates.set(
|
|
7905
|
+
storageUpdates.set(
|
|
7906
|
+
this._id,
|
|
7907
|
+
makeUpdate(this, [setDelta(index, value)], LOCAL_EDIT)
|
|
7908
|
+
);
|
|
7847
7909
|
const ops = addIntentToRootOp(
|
|
7848
7910
|
value._toOpsWithOpId(this._id, position, this._pool),
|
|
7849
7911
|
"set",
|
|
@@ -8016,11 +8078,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
8016
8078
|
);
|
|
8017
8079
|
}
|
|
8018
8080
|
};
|
|
8019
|
-
function makeUpdate(liveList, deltaUpdates) {
|
|
8081
|
+
function makeUpdate(liveList, deltaUpdates, source) {
|
|
8020
8082
|
return {
|
|
8021
8083
|
node: liveList,
|
|
8022
8084
|
type: "LiveList",
|
|
8023
|
-
updates: deltaUpdates
|
|
8085
|
+
updates: deltaUpdates,
|
|
8086
|
+
source
|
|
8024
8087
|
};
|
|
8025
8088
|
}
|
|
8026
8089
|
function setDelta(index, item) {
|
|
@@ -8139,7 +8202,9 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
8139
8202
|
if (this._pool.getNode(id) !== void 0) {
|
|
8140
8203
|
return { modified: false };
|
|
8141
8204
|
}
|
|
8142
|
-
if (source ===
|
|
8205
|
+
if (source.origin === "remote") {
|
|
8206
|
+
this.#unacknowledgedSet.delete(key);
|
|
8207
|
+
} else if (!source.optimistic) {
|
|
8143
8208
|
const lastUpdateOpId = this.#unacknowledgedSet.get(key);
|
|
8144
8209
|
if (lastUpdateOpId === opId) {
|
|
8145
8210
|
this.#unacknowledgedSet.delete(key);
|
|
@@ -8147,8 +8212,6 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
8147
8212
|
} else if (lastUpdateOpId !== void 0) {
|
|
8148
8213
|
return { modified: false };
|
|
8149
8214
|
}
|
|
8150
|
-
} else if (source === 1 /* THEIRS */) {
|
|
8151
|
-
this.#unacknowledgedSet.delete(key);
|
|
8152
8215
|
}
|
|
8153
8216
|
const previousValue = this.#map.get(key);
|
|
8154
8217
|
let reverse;
|
|
@@ -8167,7 +8230,8 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
8167
8230
|
modified: {
|
|
8168
8231
|
node: this,
|
|
8169
8232
|
type: "LiveMap",
|
|
8170
|
-
updates: { [key]: { type: "update" } }
|
|
8233
|
+
updates: { [key]: { type: "update" } },
|
|
8234
|
+
source: toUpdateSource(source)
|
|
8171
8235
|
},
|
|
8172
8236
|
reverse
|
|
8173
8237
|
};
|
|
@@ -8180,7 +8244,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
8180
8244
|
}
|
|
8181
8245
|
}
|
|
8182
8246
|
/** @internal */
|
|
8183
|
-
_detachChild(child) {
|
|
8247
|
+
_detachChild(child, source) {
|
|
8184
8248
|
const id = nn(this._id);
|
|
8185
8249
|
const parentKey = nn(child._parentKey);
|
|
8186
8250
|
const reverse = child._toOps(id, parentKey);
|
|
@@ -8199,7 +8263,8 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
8199
8263
|
type: "delete",
|
|
8200
8264
|
deletedItem: liveNodeToLson(child)
|
|
8201
8265
|
}
|
|
8202
|
-
}
|
|
8266
|
+
},
|
|
8267
|
+
source
|
|
8203
8268
|
};
|
|
8204
8269
|
return { modified: storageUpdate, reverse };
|
|
8205
8270
|
}
|
|
@@ -8248,7 +8313,8 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
8248
8313
|
storageUpdates.set(this._id, {
|
|
8249
8314
|
node: this,
|
|
8250
8315
|
type: "LiveMap",
|
|
8251
|
-
updates: { [key]: { type: "update" } }
|
|
8316
|
+
updates: { [key]: { type: "update" } },
|
|
8317
|
+
source: LOCAL_EDIT
|
|
8252
8318
|
});
|
|
8253
8319
|
const ops = item._toOpsWithOpId(this._id, key, this._pool);
|
|
8254
8320
|
this.#unacknowledgedSet.set(key, nn(ops[0].opId));
|
|
@@ -8297,7 +8363,8 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
8297
8363
|
type: "delete",
|
|
8298
8364
|
deletedItem: liveNodeToLson(item)
|
|
8299
8365
|
}
|
|
8300
|
-
}
|
|
8366
|
+
},
|
|
8367
|
+
source: LOCAL_EDIT
|
|
8301
8368
|
});
|
|
8302
8369
|
this._pool.dispatch(
|
|
8303
8370
|
[
|
|
@@ -8662,7 +8729,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8662
8729
|
}
|
|
8663
8730
|
return { modified: false };
|
|
8664
8731
|
}
|
|
8665
|
-
if (source ===
|
|
8732
|
+
if (source.origin === "local" && source.optimistic) {
|
|
8666
8733
|
this.#unackedOpsByKey.set(key, nn(opId));
|
|
8667
8734
|
} else if (this.#unackedOpsByKey.get(key) === void 0) {
|
|
8668
8735
|
} else if (this.#unackedOpsByKey.get(key) === opId) {
|
|
@@ -8700,12 +8767,13 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8700
8767
|
modified: {
|
|
8701
8768
|
node: this,
|
|
8702
8769
|
type: "LiveObject",
|
|
8703
|
-
updates: { [key]: { type: "update" } }
|
|
8770
|
+
updates: { [key]: { type: "update" } },
|
|
8771
|
+
source: toUpdateSource(source)
|
|
8704
8772
|
}
|
|
8705
8773
|
};
|
|
8706
8774
|
}
|
|
8707
8775
|
/** @internal */
|
|
8708
|
-
_detachChild(child) {
|
|
8776
|
+
_detachChild(child, source) {
|
|
8709
8777
|
if (child) {
|
|
8710
8778
|
const id = nn(this._id);
|
|
8711
8779
|
const parentKey = nn(child._parentKey);
|
|
@@ -8723,7 +8791,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8723
8791
|
type: "LiveObject",
|
|
8724
8792
|
updates: {
|
|
8725
8793
|
[parentKey]: { type: "delete", deletedItem }
|
|
8726
|
-
}
|
|
8794
|
+
},
|
|
8795
|
+
source
|
|
8727
8796
|
};
|
|
8728
8797
|
return { modified: storageUpdate, reverse };
|
|
8729
8798
|
}
|
|
@@ -8739,13 +8808,13 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8739
8808
|
}
|
|
8740
8809
|
}
|
|
8741
8810
|
/** @internal */
|
|
8742
|
-
_apply(op,
|
|
8811
|
+
_apply(op, source) {
|
|
8743
8812
|
if (op.type === OpCode.UPDATE_OBJECT) {
|
|
8744
|
-
return this.#applyUpdate(op,
|
|
8813
|
+
return this.#applyUpdate(op, source);
|
|
8745
8814
|
} else if (op.type === OpCode.DELETE_OBJECT_KEY) {
|
|
8746
|
-
return this.#applyDeleteObjectKey(op,
|
|
8815
|
+
return this.#applyDeleteObjectKey(op, source);
|
|
8747
8816
|
}
|
|
8748
|
-
return super._apply(op,
|
|
8817
|
+
return super._apply(op, source);
|
|
8749
8818
|
}
|
|
8750
8819
|
/** @internal */
|
|
8751
8820
|
_serialize() {
|
|
@@ -8769,7 +8838,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8769
8838
|
};
|
|
8770
8839
|
}
|
|
8771
8840
|
}
|
|
8772
|
-
#applyUpdate(op,
|
|
8841
|
+
#applyUpdate(op, source) {
|
|
8773
8842
|
let isModified = false;
|
|
8774
8843
|
const id = nn(this._id);
|
|
8775
8844
|
const reverse = [];
|
|
@@ -8797,7 +8866,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8797
8866
|
if (value === void 0) {
|
|
8798
8867
|
continue;
|
|
8799
8868
|
}
|
|
8800
|
-
if (
|
|
8869
|
+
if (source.origin === "local" && source.optimistic) {
|
|
8801
8870
|
this.#unackedOpsByKey.set(key, nn(op.opId));
|
|
8802
8871
|
} else if (this.#unackedOpsByKey.get(key) === void 0) {
|
|
8803
8872
|
isModified = true;
|
|
@@ -8824,18 +8893,19 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8824
8893
|
modified: {
|
|
8825
8894
|
node: this,
|
|
8826
8895
|
type: "LiveObject",
|
|
8827
|
-
updates: updateDelta
|
|
8896
|
+
updates: updateDelta,
|
|
8897
|
+
source: toUpdateSource(source)
|
|
8828
8898
|
},
|
|
8829
8899
|
reverse
|
|
8830
8900
|
} : { modified: false };
|
|
8831
8901
|
}
|
|
8832
|
-
#applyDeleteObjectKey(op,
|
|
8902
|
+
#applyDeleteObjectKey(op, source) {
|
|
8833
8903
|
const key = op.key;
|
|
8834
8904
|
const oldValue = this.#synced.get(key);
|
|
8835
8905
|
if (oldValue === void 0) {
|
|
8836
8906
|
return { modified: false };
|
|
8837
8907
|
}
|
|
8838
|
-
if (!
|
|
8908
|
+
if (!(source.origin === "local" && source.optimistic) && this.#unackedOpsByKey.get(key) !== void 0) {
|
|
8839
8909
|
return { modified: false };
|
|
8840
8910
|
}
|
|
8841
8911
|
const id = nn(this._id);
|
|
@@ -8861,7 +8931,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8861
8931
|
type: "LiveObject",
|
|
8862
8932
|
updates: {
|
|
8863
8933
|
[op.key]: { type: "delete", deletedItem: oldValue }
|
|
8864
|
-
}
|
|
8934
|
+
},
|
|
8935
|
+
source: toUpdateSource(source)
|
|
8865
8936
|
},
|
|
8866
8937
|
reverse
|
|
8867
8938
|
};
|
|
@@ -8907,7 +8978,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8907
8978
|
updates: {
|
|
8908
8979
|
..._optionalChain([existing, 'optionalAccess', _228 => _228.updates]),
|
|
8909
8980
|
[key]: { type: "update" }
|
|
8910
|
-
}
|
|
8981
|
+
},
|
|
8982
|
+
source: LOCAL_EDIT
|
|
8911
8983
|
});
|
|
8912
8984
|
this._pool.dispatch(ops, reverse, storageUpdates);
|
|
8913
8985
|
}
|
|
@@ -8941,7 +9013,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8941
9013
|
type: "delete",
|
|
8942
9014
|
deletedItem: oldValue2
|
|
8943
9015
|
}
|
|
8944
|
-
}
|
|
9016
|
+
},
|
|
9017
|
+
source: LOCAL_EDIT
|
|
8945
9018
|
});
|
|
8946
9019
|
return [[], [], storageUpdates2];
|
|
8947
9020
|
}
|
|
@@ -8989,7 +9062,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8989
9062
|
type: "LiveObject",
|
|
8990
9063
|
updates: {
|
|
8991
9064
|
[key]: { type: "delete", deletedItem: oldValue }
|
|
8992
|
-
}
|
|
9065
|
+
},
|
|
9066
|
+
source: LOCAL_EDIT
|
|
8993
9067
|
});
|
|
8994
9068
|
return [ops, reverse, storageUpdates];
|
|
8995
9069
|
}
|
|
@@ -9127,7 +9201,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
9127
9201
|
storageUpdates.set(this._id, {
|
|
9128
9202
|
node: this,
|
|
9129
9203
|
type: "LiveObject",
|
|
9130
|
-
updates: updateDelta
|
|
9204
|
+
updates: updateDelta,
|
|
9205
|
+
source: LOCAL_EDIT
|
|
9131
9206
|
});
|
|
9132
9207
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
9133
9208
|
}
|
|
@@ -9289,6 +9364,31 @@ function clipRange(index, length, contentLength) {
|
|
|
9289
9364
|
);
|
|
9290
9365
|
return { index: clippedIndex, length: clippedEnd - clippedIndex };
|
|
9291
9366
|
}
|
|
9367
|
+
function isInSurrogatePair(text, index) {
|
|
9368
|
+
const previous = text.charCodeAt(index - 1);
|
|
9369
|
+
const next = text.charCodeAt(index);
|
|
9370
|
+
return previous >= 55296 && previous <= 56319 && next >= 56320 && next <= 57343;
|
|
9371
|
+
}
|
|
9372
|
+
function clipIndexToCodePointBoundary(text, index) {
|
|
9373
|
+
const clippedIndex = Math.max(0, Math.min(index, text.length));
|
|
9374
|
+
return isInSurrogatePair(text, clippedIndex) ? clippedIndex - 1 : clippedIndex;
|
|
9375
|
+
}
|
|
9376
|
+
function clipRangeToCodePointBoundaries(text, index, length) {
|
|
9377
|
+
const clipped = clipRange(index, length, text.length);
|
|
9378
|
+
if (clipped.length === 0) {
|
|
9379
|
+
return {
|
|
9380
|
+
index: clipIndexToCodePointBoundary(text, clipped.index),
|
|
9381
|
+
length: 0
|
|
9382
|
+
};
|
|
9383
|
+
}
|
|
9384
|
+
const clippedEnd = clipped.index + clipped.length;
|
|
9385
|
+
const normalizedIndex = isInSurrogatePair(text, clipped.index) ? clipped.index - 1 : clipped.index;
|
|
9386
|
+
const normalizedEnd = isInSurrogatePair(text, clippedEnd) ? clippedEnd + 1 : clippedEnd;
|
|
9387
|
+
return {
|
|
9388
|
+
index: normalizedIndex,
|
|
9389
|
+
length: normalizedEnd - normalizedIndex
|
|
9390
|
+
};
|
|
9391
|
+
}
|
|
9292
9392
|
function applyInsert(segments, index, text, attributes) {
|
|
9293
9393
|
if (text.length === 0) {
|
|
9294
9394
|
return normalizeSegments(segments);
|
|
@@ -9638,6 +9738,34 @@ function applyLiveTextOperations(data, ops) {
|
|
|
9638
9738
|
applyTextOperationsToSegments(dataToSegments(data), ops)
|
|
9639
9739
|
);
|
|
9640
9740
|
}
|
|
9741
|
+
function normalizeLiveTextOperations(data, operations) {
|
|
9742
|
+
let shadow = dataToSegments(data);
|
|
9743
|
+
const normalized = [];
|
|
9744
|
+
for (const operation of operations) {
|
|
9745
|
+
const text = shadow.map((segment) => segment.text).join("");
|
|
9746
|
+
let normalizedOperation;
|
|
9747
|
+
if (operation.type === "insert") {
|
|
9748
|
+
normalizedOperation = {
|
|
9749
|
+
...operation,
|
|
9750
|
+
index: clipIndexToCodePointBoundary(text, operation.index)
|
|
9751
|
+
};
|
|
9752
|
+
} else {
|
|
9753
|
+
const range = clipRangeToCodePointBoundaries(
|
|
9754
|
+
text,
|
|
9755
|
+
operation.index,
|
|
9756
|
+
operation.length
|
|
9757
|
+
);
|
|
9758
|
+
normalizedOperation = {
|
|
9759
|
+
...operation,
|
|
9760
|
+
index: range.index,
|
|
9761
|
+
length: range.length
|
|
9762
|
+
};
|
|
9763
|
+
}
|
|
9764
|
+
normalized.push(normalizedOperation);
|
|
9765
|
+
shadow = applyTextOperationsToSegments(shadow, [normalizedOperation]);
|
|
9766
|
+
}
|
|
9767
|
+
return normalized;
|
|
9768
|
+
}
|
|
9641
9769
|
function invertTextOperations(segments, ops) {
|
|
9642
9770
|
let shadow = [...segments];
|
|
9643
9771
|
const reverse = [];
|
|
@@ -9770,21 +9898,21 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9770
9898
|
throw new Error("LiveText cannot contain child nodes");
|
|
9771
9899
|
}
|
|
9772
9900
|
/** @internal */
|
|
9773
|
-
_apply(op,
|
|
9901
|
+
_apply(op, source) {
|
|
9774
9902
|
if (op.type !== OpCode.UPDATE_TEXT) {
|
|
9775
|
-
return super._apply(op,
|
|
9903
|
+
return super._apply(op, source);
|
|
9776
9904
|
}
|
|
9777
|
-
if (
|
|
9778
|
-
return this.#applyLocal(op);
|
|
9905
|
+
if (source.origin === "local" && source.optimistic) {
|
|
9906
|
+
return this.#applyLocal(op, toUpdateSource(source));
|
|
9779
9907
|
}
|
|
9780
9908
|
if (op.opId !== void 0 && op.opId === this.#inFlightOpId) {
|
|
9781
|
-
return this.#applyAck(op);
|
|
9909
|
+
return this.#applyAck(op, toUpdateSource(source));
|
|
9782
9910
|
}
|
|
9783
9911
|
if (op.opId !== void 0 && this.#acceptedOps.some((entry) => entry.opId === op.opId)) {
|
|
9784
9912
|
this.#version = Math.max(this.#version, _nullishCoalesce(op.version, () => ( op.baseVersion + 1)));
|
|
9785
9913
|
return { modified: false };
|
|
9786
9914
|
}
|
|
9787
|
-
return this.#applyRemote(op);
|
|
9915
|
+
return this.#applyRemote(op, toUpdateSource(source));
|
|
9788
9916
|
}
|
|
9789
9917
|
/**
|
|
9790
9918
|
* Inserts text at the given index.
|
|
@@ -9800,7 +9928,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9800
9928
|
* text.insert(0, "Say: ", { italic: true });
|
|
9801
9929
|
*/
|
|
9802
9930
|
insert(index, text, attributes) {
|
|
9803
|
-
const clippedIndex =
|
|
9931
|
+
const clippedIndex = clipIndexToCodePointBoundary(this.toString(), index);
|
|
9804
9932
|
this.#dispatch([{ type: "insert", index: clippedIndex, text, attributes }]);
|
|
9805
9933
|
}
|
|
9806
9934
|
/**
|
|
@@ -9811,7 +9939,11 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9811
9939
|
* text.delete(5, 6); // "Hello"
|
|
9812
9940
|
*/
|
|
9813
9941
|
delete(index, length) {
|
|
9814
|
-
const clipped =
|
|
9942
|
+
const clipped = clipRangeToCodePointBoundaries(
|
|
9943
|
+
this.toString(),
|
|
9944
|
+
index,
|
|
9945
|
+
length
|
|
9946
|
+
);
|
|
9815
9947
|
if (clipped.length === 0) {
|
|
9816
9948
|
return;
|
|
9817
9949
|
}
|
|
@@ -9827,7 +9959,11 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9827
9959
|
* text.replace(0, 5, "Hi"); // "Hi world"
|
|
9828
9960
|
*/
|
|
9829
9961
|
replace(index, length, text, attributes) {
|
|
9830
|
-
const clipped =
|
|
9962
|
+
const clipped = clipRangeToCodePointBoundaries(
|
|
9963
|
+
this.toString(),
|
|
9964
|
+
index,
|
|
9965
|
+
length
|
|
9966
|
+
);
|
|
9831
9967
|
const ops = [];
|
|
9832
9968
|
if (clipped.length > 0) {
|
|
9833
9969
|
ops.push({
|
|
@@ -9920,7 +10056,11 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9920
10056
|
* text.format(0, 5, { bold: null });
|
|
9921
10057
|
*/
|
|
9922
10058
|
format(index, length, attributes) {
|
|
9923
|
-
const clipped =
|
|
10059
|
+
const clipped = clipRangeToCodePointBoundaries(
|
|
10060
|
+
this.toString(),
|
|
10061
|
+
index,
|
|
10062
|
+
length
|
|
10063
|
+
);
|
|
9924
10064
|
if (clipped.length === 0) {
|
|
9925
10065
|
return;
|
|
9926
10066
|
}
|
|
@@ -9954,7 +10094,8 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9954
10094
|
type: "LiveText",
|
|
9955
10095
|
node: this,
|
|
9956
10096
|
version: this.#version,
|
|
9957
|
-
updates: changes
|
|
10097
|
+
updates: changes,
|
|
10098
|
+
source: LOCAL_EDIT
|
|
9958
10099
|
}
|
|
9959
10100
|
]
|
|
9960
10101
|
]);
|
|
@@ -9984,7 +10125,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9984
10125
|
* A local replay of an existing wire op: an undo/redo frame, or an
|
|
9985
10126
|
* unacknowledged op re-sent after a reconnect.
|
|
9986
10127
|
*/
|
|
9987
|
-
#applyLocal(op) {
|
|
10128
|
+
#applyLocal(op, source) {
|
|
9988
10129
|
const mutableOp = op;
|
|
9989
10130
|
if (op.opId !== void 0 && op.opId === this.#inFlightOpId) {
|
|
9990
10131
|
this.#inFlightOps = [...this.#inFlightOps, ...this.#queuedOps];
|
|
@@ -10020,12 +10161,13 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
10020
10161
|
type: "LiveText",
|
|
10021
10162
|
node: this,
|
|
10022
10163
|
version: this.#version,
|
|
10023
|
-
updates: changes
|
|
10164
|
+
updates: changes,
|
|
10165
|
+
source
|
|
10024
10166
|
}
|
|
10025
10167
|
};
|
|
10026
10168
|
}
|
|
10027
10169
|
/** Server acknowledgement of our in-flight op. */
|
|
10028
|
-
#applyAck(op) {
|
|
10170
|
+
#applyAck(op, source) {
|
|
10029
10171
|
const ackedVersion = _nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)));
|
|
10030
10172
|
const predicted = this.#inFlightOps;
|
|
10031
10173
|
const opId = this.#inFlightOpId;
|
|
@@ -10047,7 +10189,8 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
10047
10189
|
type: "LiveText",
|
|
10048
10190
|
node: this,
|
|
10049
10191
|
version: ackedVersion,
|
|
10050
|
-
updates: rebuilt.changes
|
|
10192
|
+
updates: rebuilt.changes,
|
|
10193
|
+
source
|
|
10051
10194
|
}
|
|
10052
10195
|
};
|
|
10053
10196
|
}
|
|
@@ -10058,7 +10201,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
10058
10201
|
return result;
|
|
10059
10202
|
}
|
|
10060
10203
|
/** An accepted op from another client (or a server-fabricated fix op). */
|
|
10061
|
-
#applyRemote(op) {
|
|
10204
|
+
#applyRemote(op, source) {
|
|
10062
10205
|
const version = _nullishCoalesce(op.version, () => ( this.#version + 1));
|
|
10063
10206
|
this.#confirmed = applyTextOperationsToSegments(this.#confirmed, op.ops);
|
|
10064
10207
|
const [overInFlight, inFlight] = transformTextOperationsX(
|
|
@@ -10087,7 +10230,8 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
10087
10230
|
type: "LiveText",
|
|
10088
10231
|
node: this,
|
|
10089
10232
|
version: this.#version,
|
|
10090
|
-
updates: changes
|
|
10233
|
+
updates: changes,
|
|
10234
|
+
source
|
|
10091
10235
|
}
|
|
10092
10236
|
};
|
|
10093
10237
|
}
|
|
@@ -10171,7 +10315,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
10171
10315
|
*
|
|
10172
10316
|
* @internal
|
|
10173
10317
|
*/
|
|
10174
|
-
_resyncText(data, version) {
|
|
10318
|
+
_resyncText(data, version, source) {
|
|
10175
10319
|
this.#confirmed = dataToSegments(data);
|
|
10176
10320
|
this.#version = version;
|
|
10177
10321
|
this.#acceptedOps = [];
|
|
@@ -10183,7 +10327,8 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
10183
10327
|
type: "LiveText",
|
|
10184
10328
|
node: this,
|
|
10185
10329
|
version: this.#version,
|
|
10186
|
-
updates: rebuilt.changes
|
|
10330
|
+
updates: rebuilt.changes,
|
|
10331
|
+
source
|
|
10187
10332
|
};
|
|
10188
10333
|
}
|
|
10189
10334
|
/**
|
|
@@ -10697,37 +10842,30 @@ function mergeTextStorageUpdates(first, second) {
|
|
|
10697
10842
|
updates: first.updates.concat(second.updates)
|
|
10698
10843
|
};
|
|
10699
10844
|
}
|
|
10845
|
+
function mergeUpdateSources(first, second) {
|
|
10846
|
+
if (first.origin === "remote" || second.origin === "remote") {
|
|
10847
|
+
return REMOTE;
|
|
10848
|
+
}
|
|
10849
|
+
if (second.via !== "edit") return second;
|
|
10850
|
+
if (first.via !== "edit") return first;
|
|
10851
|
+
return LOCAL_EDIT;
|
|
10852
|
+
}
|
|
10700
10853
|
function mergeStorageUpdates(first, second) {
|
|
10701
10854
|
if (first === void 0) {
|
|
10702
10855
|
return second;
|
|
10703
10856
|
}
|
|
10704
|
-
|
|
10857
|
+
const source = mergeUpdateSources(first.source, second.source);
|
|
10705
10858
|
if (first.type === "LiveObject" && second.type === "LiveObject") {
|
|
10706
|
-
|
|
10859
|
+
return { ...mergeObjectStorageUpdates(first, second), source };
|
|
10707
10860
|
} else if (first.type === "LiveMap" && second.type === "LiveMap") {
|
|
10708
|
-
|
|
10861
|
+
return { ...mergeMapStorageUpdates(first, second), source };
|
|
10709
10862
|
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
10710
|
-
|
|
10863
|
+
return { ...mergeListStorageUpdates(first, second), source };
|
|
10711
10864
|
} else if (first.type === "LiveText" && second.type === "LiveText") {
|
|
10712
|
-
|
|
10865
|
+
return { ...mergeTextStorageUpdates(first, second), source };
|
|
10713
10866
|
} else {
|
|
10714
|
-
|
|
10715
|
-
}
|
|
10716
|
-
const sa = first[kStorageUpdateSource];
|
|
10717
|
-
const sb = second[kStorageUpdateSource];
|
|
10718
|
-
if (sa !== void 0 || sb !== void 0) {
|
|
10719
|
-
if (_optionalChain([sa, 'optionalAccess', _245 => _245.origin]) === "remote" || _optionalChain([sb, 'optionalAccess', _246 => _246.origin]) === "remote") {
|
|
10720
|
-
merged[kStorageUpdateSource] = { origin: "remote" };
|
|
10721
|
-
} else if (_optionalChain([sa, 'optionalAccess', _247 => _247.via]) === "history" || _optionalChain([sb, 'optionalAccess', _248 => _248.via]) === "history") {
|
|
10722
|
-
const historySource = _optionalChain([sb, 'optionalAccess', _249 => _249.via]) === "history" ? sb : _optionalChain([sa, 'optionalAccess', _250 => _250.via]) === "history" ? sa : void 0;
|
|
10723
|
-
if (_optionalChain([historySource, 'optionalAccess', _251 => _251.via]) === "history") {
|
|
10724
|
-
merged[kStorageUpdateSource] = historySource;
|
|
10725
|
-
}
|
|
10726
|
-
} else {
|
|
10727
|
-
merged[kStorageUpdateSource] = { origin: "local", via: "mutation" };
|
|
10728
|
-
}
|
|
10867
|
+
return { ...second, source };
|
|
10729
10868
|
}
|
|
10730
|
-
return merged;
|
|
10731
10869
|
}
|
|
10732
10870
|
|
|
10733
10871
|
// src/devtools/bridge.ts
|
|
@@ -10743,7 +10881,7 @@ function sendToPanel(message, options) {
|
|
|
10743
10881
|
...message,
|
|
10744
10882
|
source: "liveblocks-devtools-client"
|
|
10745
10883
|
};
|
|
10746
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
10884
|
+
if (!(_optionalChain([options, 'optionalAccess', _245 => _245.force]) || _bridgeActive)) {
|
|
10747
10885
|
return;
|
|
10748
10886
|
}
|
|
10749
10887
|
window.postMessage(fullMsg, "*");
|
|
@@ -10751,7 +10889,7 @@ function sendToPanel(message, options) {
|
|
|
10751
10889
|
var eventSource = makeEventSource();
|
|
10752
10890
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
10753
10891
|
window.addEventListener("message", (event) => {
|
|
10754
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
10892
|
+
if (event.source === window && _optionalChain([event, 'access', _246 => _246.data, 'optionalAccess', _247 => _247.source]) === "liveblocks-devtools-panel") {
|
|
10755
10893
|
eventSource.notify(event.data);
|
|
10756
10894
|
} else {
|
|
10757
10895
|
}
|
|
@@ -10893,7 +11031,7 @@ function fullSync(room) {
|
|
|
10893
11031
|
msg: "room::sync::full",
|
|
10894
11032
|
roomId: room.id,
|
|
10895
11033
|
status: room.getStatus(),
|
|
10896
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
11034
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _248 => _248.toTreeNode, 'call', _249 => _249("root"), 'access', _250 => _250.payload]), () => ( null)),
|
|
10897
11035
|
me,
|
|
10898
11036
|
others
|
|
10899
11037
|
});
|
|
@@ -11580,15 +11718,15 @@ function installBackgroundTabSpy() {
|
|
|
11580
11718
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
11581
11719
|
const inBackgroundSince = { current: null };
|
|
11582
11720
|
function onVisibilityChange() {
|
|
11583
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
11721
|
+
if (_optionalChain([doc, 'optionalAccess', _251 => _251.visibilityState]) === "hidden") {
|
|
11584
11722
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
11585
11723
|
} else {
|
|
11586
11724
|
inBackgroundSince.current = null;
|
|
11587
11725
|
}
|
|
11588
11726
|
}
|
|
11589
|
-
_optionalChain([doc, 'optionalAccess',
|
|
11727
|
+
_optionalChain([doc, 'optionalAccess', _252 => _252.addEventListener, 'call', _253 => _253("visibilitychange", onVisibilityChange)]);
|
|
11590
11728
|
const unsub = () => {
|
|
11591
|
-
_optionalChain([doc, 'optionalAccess',
|
|
11729
|
+
_optionalChain([doc, 'optionalAccess', _254 => _254.removeEventListener, 'call', _255 => _255("visibilitychange", onVisibilityChange)]);
|
|
11592
11730
|
};
|
|
11593
11731
|
return [inBackgroundSince, unsub];
|
|
11594
11732
|
}
|
|
@@ -11612,7 +11750,7 @@ function makeNodeMapBuffer() {
|
|
|
11612
11750
|
function topLevelKeysOf(nodes) {
|
|
11613
11751
|
const keys2 = /* @__PURE__ */ new Set();
|
|
11614
11752
|
const root = nodes.get("root");
|
|
11615
|
-
for (const key in _optionalChain([root, 'optionalAccess',
|
|
11753
|
+
for (const key in _optionalChain([root, 'optionalAccess', _256 => _256.data])) {
|
|
11616
11754
|
keys2.add(key);
|
|
11617
11755
|
}
|
|
11618
11756
|
for (const node of nodes.values()) {
|
|
@@ -11771,9 +11909,6 @@ function createRoom(options, config) {
|
|
|
11771
11909
|
}
|
|
11772
11910
|
});
|
|
11773
11911
|
function onDispatch(ops, reverse, storageUpdates, options2) {
|
|
11774
|
-
for (const value of storageUpdates.values()) {
|
|
11775
|
-
value[kStorageUpdateSource] = { origin: "local", via: "mutation" };
|
|
11776
|
-
}
|
|
11777
11912
|
if (context.activeBatch) {
|
|
11778
11913
|
for (const op of ops) {
|
|
11779
11914
|
context.activeBatch.ops.push(op);
|
|
@@ -11788,14 +11923,14 @@ function createRoom(options, config) {
|
|
|
11788
11923
|
);
|
|
11789
11924
|
}
|
|
11790
11925
|
context.activeBatch.reverseOps.pushLeft(reverse);
|
|
11791
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
11926
|
+
if (_optionalChain([options2, 'optionalAccess', _257 => _257.clearRedoStack])) {
|
|
11792
11927
|
context.activeBatch.clearRedoStack = true;
|
|
11793
11928
|
}
|
|
11794
11929
|
} else {
|
|
11795
11930
|
if (reverse.length > 0) {
|
|
11796
11931
|
addToUndoStack(reverse);
|
|
11797
11932
|
}
|
|
11798
|
-
if (_nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
11933
|
+
if (_nullishCoalesce(_optionalChain([options2, 'optionalAccess', _258 => _258.clearRedoStack]), () => ( ops.length > 0))) {
|
|
11799
11934
|
clearRedoStack();
|
|
11800
11935
|
}
|
|
11801
11936
|
if (ops.length > 0) {
|
|
@@ -11805,7 +11940,7 @@ function createRoom(options, config) {
|
|
|
11805
11940
|
}
|
|
11806
11941
|
}
|
|
11807
11942
|
function isStorageWritable() {
|
|
11808
|
-
const permissionMatrix = _optionalChain([context, 'access',
|
|
11943
|
+
const permissionMatrix = _optionalChain([context, 'access', _259 => _259.dynamicSessionInfoSig, 'access', _260 => _260.get, 'call', _261 => _261(), 'optionalAccess', _262 => _262.permissionMatrix]);
|
|
11809
11944
|
return permissionMatrix !== void 0 ? hasPermissionAccess(permissionMatrix, "storage", "write") : true;
|
|
11810
11945
|
}
|
|
11811
11946
|
const eventHub = {
|
|
@@ -11923,7 +12058,7 @@ function createRoom(options, config) {
|
|
|
11923
12058
|
if (crdt.type === CrdtType.TEXT) {
|
|
11924
12059
|
const node = context.pool.nodes.get(id);
|
|
11925
12060
|
if (node !== void 0 && isLiveText(node)) {
|
|
11926
|
-
const update = node._resyncText(crdt.data, crdt.version);
|
|
12061
|
+
const update = node._resyncText(crdt.data, crdt.version, REMOTE);
|
|
11927
12062
|
if (update !== void 0) {
|
|
11928
12063
|
result.updates.storageUpdates.set(
|
|
11929
12064
|
id,
|
|
@@ -11943,7 +12078,7 @@ function createRoom(options, config) {
|
|
|
11943
12078
|
context.pool
|
|
11944
12079
|
);
|
|
11945
12080
|
}
|
|
11946
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
12081
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _263 => _263.get, 'call', _264 => _264(), 'optionalAccess', _265 => _265.canWrite]), () => ( true));
|
|
11947
12082
|
const serverTopLevelKeys = topLevelKeysOf(nodes);
|
|
11948
12083
|
const root = context.root;
|
|
11949
12084
|
disableHistory(() => {
|
|
@@ -12026,7 +12161,10 @@ function createRoom(options, config) {
|
|
|
12026
12161
|
eventHub.myPresence.notify(context.myPresence.get());
|
|
12027
12162
|
}
|
|
12028
12163
|
if (storageUpdates !== void 0 && storageUpdates.size > 0) {
|
|
12029
|
-
const updates2 = Array.from(storageUpdates.values())
|
|
12164
|
+
const updates2 = Array.from(storageUpdates.values(), (update) => ({
|
|
12165
|
+
...update,
|
|
12166
|
+
source: toUpdateSource(update.source)
|
|
12167
|
+
}));
|
|
12030
12168
|
eventHub.storageBatch.notify(updates2);
|
|
12031
12169
|
}
|
|
12032
12170
|
notifyStorageStatus();
|
|
@@ -12040,7 +12178,16 @@ function createRoom(options, config) {
|
|
|
12040
12178
|
"Internal. Tried to get connection id but connection was never open"
|
|
12041
12179
|
);
|
|
12042
12180
|
}
|
|
12043
|
-
|
|
12181
|
+
const viaByOpId = /* @__PURE__ */ new Map();
|
|
12182
|
+
function viaOfAckedOp(opId) {
|
|
12183
|
+
const via = viaByOpId.get(opId);
|
|
12184
|
+
if (via === void 0) {
|
|
12185
|
+
return "edit";
|
|
12186
|
+
}
|
|
12187
|
+
viaByOpId.delete(opId);
|
|
12188
|
+
return via;
|
|
12189
|
+
}
|
|
12190
|
+
function applyLocalOps(frames, localSource = LOCAL_EDIT) {
|
|
12044
12191
|
const [pframes, ops] = partition(
|
|
12045
12192
|
frames,
|
|
12046
12193
|
(f) => f.type === "presence"
|
|
@@ -12083,12 +12230,17 @@ function createRoom(options, config) {
|
|
|
12083
12230
|
const opsWithOpIds = remappedOps.map(
|
|
12084
12231
|
(op) => op.opId === void 0 ? { ...op, opId: context.pool.generateOpId() } : op
|
|
12085
12232
|
);
|
|
12233
|
+
if (localSource.via !== "edit") {
|
|
12234
|
+
for (const op of opsWithOpIds) {
|
|
12235
|
+
viaByOpId.set(op.opId, localSource.via);
|
|
12236
|
+
}
|
|
12237
|
+
}
|
|
12086
12238
|
const { reverse, updates } = applyOps(
|
|
12087
12239
|
pframes,
|
|
12088
12240
|
opsWithOpIds,
|
|
12089
12241
|
/* isLocal */
|
|
12090
12242
|
true,
|
|
12091
|
-
|
|
12243
|
+
localSource
|
|
12092
12244
|
);
|
|
12093
12245
|
return { opsToEmit: opsWithOpIds, reverse, updates };
|
|
12094
12246
|
}
|
|
@@ -12100,7 +12252,7 @@ function createRoom(options, config) {
|
|
|
12100
12252
|
false
|
|
12101
12253
|
);
|
|
12102
12254
|
}
|
|
12103
|
-
function applyOps(pframes, ops, isLocal,
|
|
12255
|
+
function applyOps(pframes, ops, isLocal, localSource = LOCAL_EDIT) {
|
|
12104
12256
|
const output = {
|
|
12105
12257
|
reverse: new Deque(),
|
|
12106
12258
|
storageUpdates: /* @__PURE__ */ new Map(),
|
|
@@ -12129,16 +12281,19 @@ function createRoom(options, config) {
|
|
|
12129
12281
|
for (const op of ops) {
|
|
12130
12282
|
let source;
|
|
12131
12283
|
if (isLocal) {
|
|
12132
|
-
source =
|
|
12284
|
+
source = { ...localSource, optimistic: true };
|
|
12133
12285
|
} else if (op.opId !== void 0) {
|
|
12134
12286
|
context.unacknowledgedOps.delete(op.opId);
|
|
12135
|
-
source =
|
|
12287
|
+
source = {
|
|
12288
|
+
origin: "local",
|
|
12289
|
+
via: viaOfAckedOp(op.opId),
|
|
12290
|
+
optimistic: false
|
|
12291
|
+
};
|
|
12136
12292
|
} else {
|
|
12137
|
-
source =
|
|
12293
|
+
source = REMOTE;
|
|
12138
12294
|
}
|
|
12139
12295
|
const applyOpResult = applyOp(op, source);
|
|
12140
12296
|
if (applyOpResult.modified) {
|
|
12141
|
-
applyOpResult.modified[kStorageUpdateSource] = source === 1 /* THEIRS */ ? { origin: "remote" } : localStorageUpdateSource;
|
|
12142
12297
|
const nodeId = applyOpResult.modified.node._id;
|
|
12143
12298
|
if (!(nodeId && createdNodeIds.has(nodeId))) {
|
|
12144
12299
|
output.storageUpdates.set(
|
|
@@ -12176,7 +12331,7 @@ function createRoom(options, config) {
|
|
|
12176
12331
|
if (node === void 0) {
|
|
12177
12332
|
return { modified: false };
|
|
12178
12333
|
}
|
|
12179
|
-
return node._apply(op, source
|
|
12334
|
+
return node._apply(op, source);
|
|
12180
12335
|
}
|
|
12181
12336
|
case OpCode.SET_PARENT_KEY: {
|
|
12182
12337
|
const node = context.pool.nodes.get(op.id);
|
|
@@ -12231,7 +12386,7 @@ function createRoom(options, config) {
|
|
|
12231
12386
|
}
|
|
12232
12387
|
context.myPresence.patch(patch);
|
|
12233
12388
|
if (context.activeBatch) {
|
|
12234
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
12389
|
+
if (_optionalChain([options2, 'optionalAccess', _266 => _266.addToHistory])) {
|
|
12235
12390
|
context.activeBatch.reverseOps.pushLeft({
|
|
12236
12391
|
type: "presence",
|
|
12237
12392
|
data: oldValues
|
|
@@ -12240,7 +12395,7 @@ function createRoom(options, config) {
|
|
|
12240
12395
|
context.activeBatch.updates.presence = true;
|
|
12241
12396
|
} else {
|
|
12242
12397
|
flushNowOrSoon();
|
|
12243
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
12398
|
+
if (_optionalChain([options2, 'optionalAccess', _267 => _267.addToHistory])) {
|
|
12244
12399
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
12245
12400
|
}
|
|
12246
12401
|
notify({ presence: true });
|
|
@@ -12419,11 +12574,11 @@ function createRoom(options, config) {
|
|
|
12419
12574
|
break;
|
|
12420
12575
|
}
|
|
12421
12576
|
case ServerMsgCode.STORAGE_CHUNK:
|
|
12422
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
12577
|
+
_optionalChain([stopwatch, 'optionalAccess', _268 => _268.lap, 'call', _269 => _269()]);
|
|
12423
12578
|
nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
|
|
12424
12579
|
break;
|
|
12425
12580
|
case ServerMsgCode.STORAGE_STREAM_END: {
|
|
12426
|
-
const timing = _optionalChain([stopwatch, 'optionalAccess',
|
|
12581
|
+
const timing = _optionalChain([stopwatch, 'optionalAccess', _270 => _270.stop, 'call', _271 => _271()]);
|
|
12427
12582
|
if (timing) {
|
|
12428
12583
|
const ms = (v) => `${v.toFixed(1)}ms`;
|
|
12429
12584
|
const rest = timing.laps.slice(1);
|
|
@@ -12469,6 +12624,7 @@ function createRoom(options, config) {
|
|
|
12469
12624
|
const rejectedOp = context.unacknowledgedOps.get(opId);
|
|
12470
12625
|
context.unacknowledgedOps.delete(opId);
|
|
12471
12626
|
context.buffer.storageOperations = context.buffer.storageOperations.filter((op) => op.opId !== opId);
|
|
12627
|
+
viaByOpId.delete(opId);
|
|
12472
12628
|
if (rejectedOp !== void 0 && rejectedOp.type === OpCode.UPDATE_TEXT) {
|
|
12473
12629
|
const node = context.pool.nodes.get(rejectedOp.id);
|
|
12474
12630
|
if (node !== void 0 && isLiveText(node)) {
|
|
@@ -12579,11 +12735,11 @@ function createRoom(options, config) {
|
|
|
12579
12735
|
} else if (pendingFeedsRequests.has(requestId)) {
|
|
12580
12736
|
const pending = pendingFeedsRequests.get(requestId);
|
|
12581
12737
|
pendingFeedsRequests.delete(requestId);
|
|
12582
|
-
_optionalChain([pending, 'optionalAccess',
|
|
12738
|
+
_optionalChain([pending, 'optionalAccess', _272 => _272.reject, 'call', _273 => _273(err)]);
|
|
12583
12739
|
} else if (pendingFeedMessagesRequests.has(requestId)) {
|
|
12584
12740
|
const pending = pendingFeedMessagesRequests.get(requestId);
|
|
12585
12741
|
pendingFeedMessagesRequests.delete(requestId);
|
|
12586
|
-
_optionalChain([pending, 'optionalAccess',
|
|
12742
|
+
_optionalChain([pending, 'optionalAccess', _274 => _274.reject, 'call', _275 => _275(err)]);
|
|
12587
12743
|
}
|
|
12588
12744
|
eventHub.feeds.notify(message);
|
|
12589
12745
|
break;
|
|
@@ -12737,10 +12893,10 @@ function createRoom(options, config) {
|
|
|
12737
12893
|
timeoutId,
|
|
12738
12894
|
kind,
|
|
12739
12895
|
feedId,
|
|
12740
|
-
messageId: _optionalChain([options2, 'optionalAccess',
|
|
12741
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
12896
|
+
messageId: _optionalChain([options2, 'optionalAccess', _276 => _276.messageId]),
|
|
12897
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _277 => _277.expectedClientMessageId])
|
|
12742
12898
|
});
|
|
12743
|
-
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess',
|
|
12899
|
+
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess', _278 => _278.expectedClientMessageId]) === void 0) {
|
|
12744
12900
|
const q = _nullishCoalesce(pendingAddMessageFifoByFeed.get(feedId), () => ( []));
|
|
12745
12901
|
q.push(requestId);
|
|
12746
12902
|
pendingAddMessageFifoByFeed.set(feedId, q);
|
|
@@ -12791,10 +12947,10 @@ function createRoom(options, config) {
|
|
|
12791
12947
|
}
|
|
12792
12948
|
if (!matched) {
|
|
12793
12949
|
const q = pendingAddMessageFifoByFeed.get(message.feedId);
|
|
12794
|
-
const headId = _optionalChain([q, 'optionalAccess',
|
|
12950
|
+
const headId = _optionalChain([q, 'optionalAccess', _279 => _279[0]]);
|
|
12795
12951
|
if (headId !== void 0) {
|
|
12796
12952
|
const pending = pendingFeedMutations.get(headId);
|
|
12797
|
-
if (_optionalChain([pending, 'optionalAccess',
|
|
12953
|
+
if (_optionalChain([pending, 'optionalAccess', _280 => _280.kind]) === "add-message" && pending.expectedClientMessageId === void 0) {
|
|
12798
12954
|
settleFeedMutation(headId, "ok");
|
|
12799
12955
|
}
|
|
12800
12956
|
}
|
|
@@ -12830,7 +12986,7 @@ function createRoom(options, config) {
|
|
|
12830
12986
|
const unacknowledgedOps2 = [...context.unacknowledgedOps.values()];
|
|
12831
12987
|
createOrUpdateRootFromMessage(nodes);
|
|
12832
12988
|
applyAndSendOfflineOps(unacknowledgedOps2);
|
|
12833
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
12989
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _281 => _281()]);
|
|
12834
12990
|
notifyStorageStatus();
|
|
12835
12991
|
eventHub.storageDidLoad.notify();
|
|
12836
12992
|
}
|
|
@@ -12839,7 +12995,7 @@ function createRoom(options, config) {
|
|
|
12839
12995
|
if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
12840
12996
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
12841
12997
|
nodeMapBuffer.take();
|
|
12842
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
12998
|
+
_optionalChain([stopwatch, 'optionalAccess', _282 => _282.start, 'call', _283 => _283()]);
|
|
12843
12999
|
}
|
|
12844
13000
|
}
|
|
12845
13001
|
function startLoadingStorage() {
|
|
@@ -12893,10 +13049,10 @@ function createRoom(options, config) {
|
|
|
12893
13049
|
const message = {
|
|
12894
13050
|
type: ClientMsgCode.FETCH_FEEDS,
|
|
12895
13051
|
requestId,
|
|
12896
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
12897
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
12898
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
12899
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
13052
|
+
cursor: _optionalChain([options2, 'optionalAccess', _284 => _284.cursor]),
|
|
13053
|
+
since: _optionalChain([options2, 'optionalAccess', _285 => _285.since]),
|
|
13054
|
+
limit: _optionalChain([options2, 'optionalAccess', _286 => _286.limit]),
|
|
13055
|
+
metadata: _optionalChain([options2, 'optionalAccess', _287 => _287.metadata])
|
|
12900
13056
|
};
|
|
12901
13057
|
context.buffer.messages.push(message);
|
|
12902
13058
|
flushNowOrSoon();
|
|
@@ -12916,9 +13072,9 @@ function createRoom(options, config) {
|
|
|
12916
13072
|
type: ClientMsgCode.FETCH_FEED_MESSAGES,
|
|
12917
13073
|
requestId,
|
|
12918
13074
|
feedId,
|
|
12919
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
12920
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
12921
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
13075
|
+
cursor: _optionalChain([options2, 'optionalAccess', _288 => _288.cursor]),
|
|
13076
|
+
since: _optionalChain([options2, 'optionalAccess', _289 => _289.since]),
|
|
13077
|
+
limit: _optionalChain([options2, 'optionalAccess', _290 => _290.limit])
|
|
12922
13078
|
};
|
|
12923
13079
|
context.buffer.messages.push(message);
|
|
12924
13080
|
flushNowOrSoon();
|
|
@@ -12937,8 +13093,8 @@ function createRoom(options, config) {
|
|
|
12937
13093
|
type: ClientMsgCode.ADD_FEED,
|
|
12938
13094
|
requestId,
|
|
12939
13095
|
feedId,
|
|
12940
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
12941
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
13096
|
+
metadata: _optionalChain([options2, 'optionalAccess', _291 => _291.metadata]),
|
|
13097
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _292 => _292.createdAt])
|
|
12942
13098
|
};
|
|
12943
13099
|
context.buffer.messages.push(message);
|
|
12944
13100
|
flushNowOrSoon();
|
|
@@ -12972,15 +13128,15 @@ function createRoom(options, config) {
|
|
|
12972
13128
|
function addFeedMessage(feedId, data, options2) {
|
|
12973
13129
|
const requestId = nanoid();
|
|
12974
13130
|
const promise = registerFeedMutation(requestId, "add-message", feedId, {
|
|
12975
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
13131
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _293 => _293.id])
|
|
12976
13132
|
});
|
|
12977
13133
|
const message = {
|
|
12978
13134
|
type: ClientMsgCode.ADD_FEED_MESSAGE,
|
|
12979
13135
|
requestId,
|
|
12980
13136
|
feedId,
|
|
12981
13137
|
data,
|
|
12982
|
-
id: _optionalChain([options2, 'optionalAccess',
|
|
12983
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
13138
|
+
id: _optionalChain([options2, 'optionalAccess', _294 => _294.id]),
|
|
13139
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _295 => _295.createdAt])
|
|
12984
13140
|
};
|
|
12985
13141
|
context.buffer.messages.push(message);
|
|
12986
13142
|
flushNowOrSoon();
|
|
@@ -12997,7 +13153,7 @@ function createRoom(options, config) {
|
|
|
12997
13153
|
feedId,
|
|
12998
13154
|
messageId,
|
|
12999
13155
|
data,
|
|
13000
|
-
updatedAt: _optionalChain([options2, 'optionalAccess',
|
|
13156
|
+
updatedAt: _optionalChain([options2, 'optionalAccess', _296 => _296.updatedAt])
|
|
13001
13157
|
};
|
|
13002
13158
|
context.buffer.messages.push(message);
|
|
13003
13159
|
flushNowOrSoon();
|
|
@@ -13027,11 +13183,7 @@ function createRoom(options, config) {
|
|
|
13027
13183
|
return;
|
|
13028
13184
|
}
|
|
13029
13185
|
context.pausedHistory = null;
|
|
13030
|
-
const result = applyLocalOps(item.frames,
|
|
13031
|
-
origin: "local",
|
|
13032
|
-
via: "history",
|
|
13033
|
-
action: "undo"
|
|
13034
|
-
});
|
|
13186
|
+
const result = applyLocalOps(item.frames, LOCAL_UNDO);
|
|
13035
13187
|
context.redoStack.push({ id: item.id, frames: result.reverse });
|
|
13036
13188
|
notifyPrivateHistory({ action: "undo", id: item.id });
|
|
13037
13189
|
notify(result.updates);
|
|
@@ -13050,11 +13202,7 @@ function createRoom(options, config) {
|
|
|
13050
13202
|
return;
|
|
13051
13203
|
}
|
|
13052
13204
|
context.pausedHistory = null;
|
|
13053
|
-
const result = applyLocalOps(item.frames,
|
|
13054
|
-
origin: "local",
|
|
13055
|
-
via: "history",
|
|
13056
|
-
action: "redo"
|
|
13057
|
-
});
|
|
13205
|
+
const result = applyLocalOps(item.frames, LOCAL_REDO);
|
|
13058
13206
|
context.undoStack.push({ id: item.id, frames: result.reverse });
|
|
13059
13207
|
notifyPrivateHistory({ action: "redo", id: item.id });
|
|
13060
13208
|
notify(result.updates);
|
|
@@ -13215,8 +13363,8 @@ function createRoom(options, config) {
|
|
|
13215
13363
|
async function getThreads(options2) {
|
|
13216
13364
|
return httpClient.getThreads({
|
|
13217
13365
|
roomId,
|
|
13218
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
13219
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
13366
|
+
query: _optionalChain([options2, 'optionalAccess', _297 => _297.query]),
|
|
13367
|
+
cursor: _optionalChain([options2, 'optionalAccess', _298 => _298.cursor])
|
|
13220
13368
|
});
|
|
13221
13369
|
}
|
|
13222
13370
|
async function getThread(threadId) {
|
|
@@ -13349,7 +13497,7 @@ function createRoom(options, config) {
|
|
|
13349
13497
|
function getSubscriptionSettings(options2) {
|
|
13350
13498
|
return httpClient.getSubscriptionSettings({
|
|
13351
13499
|
roomId,
|
|
13352
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
13500
|
+
signal: _optionalChain([options2, 'optionalAccess', _299 => _299.signal])
|
|
13353
13501
|
});
|
|
13354
13502
|
}
|
|
13355
13503
|
function updateSubscriptionSettings(settings) {
|
|
@@ -13371,7 +13519,7 @@ function createRoom(options, config) {
|
|
|
13371
13519
|
{
|
|
13372
13520
|
[kInternal]: {
|
|
13373
13521
|
get presenceBuffer() {
|
|
13374
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
13522
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _300 => _300.buffer, 'access', _301 => _301.presenceUpdates, 'optionalAccess', _302 => _302.data]), () => ( null)));
|
|
13375
13523
|
},
|
|
13376
13524
|
// prettier-ignore
|
|
13377
13525
|
get undoStack() {
|
|
@@ -13401,15 +13549,15 @@ function createRoom(options, config) {
|
|
|
13401
13549
|
return context.yjsProvider;
|
|
13402
13550
|
},
|
|
13403
13551
|
setYjsProvider(newProvider) {
|
|
13404
|
-
_optionalChain([context, 'access',
|
|
13552
|
+
_optionalChain([context, 'access', _303 => _303.yjsProvider, 'optionalAccess', _304 => _304.off, 'call', _305 => _305("status", yjsStatusDidChange)]);
|
|
13405
13553
|
context.yjsProvider = newProvider;
|
|
13406
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
13554
|
+
_optionalChain([newProvider, 'optionalAccess', _306 => _306.on, 'call', _307 => _307("status", yjsStatusDidChange)]);
|
|
13407
13555
|
context.yjsProviderDidChange.notify();
|
|
13408
13556
|
},
|
|
13409
13557
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
13410
13558
|
// send metadata when using a text editor
|
|
13411
13559
|
reportTextEditor,
|
|
13412
|
-
getPermissionMatrix: () => _optionalChain([context, 'access',
|
|
13560
|
+
getPermissionMatrix: () => _optionalChain([context, 'access', _308 => _308.dynamicSessionInfoSig, 'access', _309 => _309.get, 'call', _310 => _310(), 'optionalAccess', _311 => _311.permissionMatrix]),
|
|
13413
13561
|
// create a text mention when using a text editor
|
|
13414
13562
|
createTextMention,
|
|
13415
13563
|
// delete a text mention when using a text editor
|
|
@@ -13472,7 +13620,7 @@ ${dumpPool(
|
|
|
13472
13620
|
source.dispose();
|
|
13473
13621
|
}
|
|
13474
13622
|
eventHub.roomWillDestroy.notify();
|
|
13475
|
-
_optionalChain([context, 'access',
|
|
13623
|
+
_optionalChain([context, 'access', _312 => _312.yjsProvider, 'optionalAccess', _313 => _313.off, 'call', _314 => _314("status", yjsStatusDidChange)]);
|
|
13476
13624
|
syncSourceForStorage.destroy();
|
|
13477
13625
|
syncSourceForYjs.destroy();
|
|
13478
13626
|
uninstallBgTabSpy();
|
|
@@ -13636,7 +13784,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
13636
13784
|
}
|
|
13637
13785
|
if (isLiveNode(first)) {
|
|
13638
13786
|
const node = first;
|
|
13639
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
13787
|
+
if (_optionalChain([options, 'optionalAccess', _315 => _315.isDeep])) {
|
|
13640
13788
|
const storageCallback = second;
|
|
13641
13789
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
13642
13790
|
} else {
|
|
@@ -13726,8 +13874,8 @@ function createClient(options) {
|
|
|
13726
13874
|
const authManager = createAuthManager(options, (token) => {
|
|
13727
13875
|
currentUserId.set(() => token.uid);
|
|
13728
13876
|
});
|
|
13729
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
13730
|
-
_optionalChain([globalThis, 'access',
|
|
13877
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _316 => _316.polyfills, 'optionalAccess', _317 => _317.fetch]) || /* istanbul ignore next */
|
|
13878
|
+
_optionalChain([globalThis, 'access', _318 => _318.fetch, 'optionalAccess', _319 => _319.bind, 'call', _320 => _320(globalThis)]);
|
|
13731
13879
|
const httpClient = createApiClient({
|
|
13732
13880
|
baseUrl,
|
|
13733
13881
|
fetchPolyfill,
|
|
@@ -13744,7 +13892,7 @@ function createClient(options) {
|
|
|
13744
13892
|
delegates: {
|
|
13745
13893
|
createSocket: makeCreateSocketDelegateForAi(
|
|
13746
13894
|
baseUrl,
|
|
13747
|
-
_optionalChain([clientOptions, 'access',
|
|
13895
|
+
_optionalChain([clientOptions, 'access', _321 => _321.polyfills, 'optionalAccess', _322 => _322.WebSocket])
|
|
13748
13896
|
),
|
|
13749
13897
|
authenticate: async () => {
|
|
13750
13898
|
const resp = await authManager.getAuthValue({
|
|
@@ -13815,7 +13963,7 @@ function createClient(options) {
|
|
|
13815
13963
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
13816
13964
|
roomId,
|
|
13817
13965
|
baseUrl,
|
|
13818
|
-
_optionalChain([clientOptions, 'access',
|
|
13966
|
+
_optionalChain([clientOptions, 'access', _323 => _323.polyfills, 'optionalAccess', _324 => _324.WebSocket])
|
|
13819
13967
|
),
|
|
13820
13968
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
13821
13969
|
})),
|
|
@@ -13837,7 +13985,7 @@ function createClient(options) {
|
|
|
13837
13985
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
13838
13986
|
if (shouldConnect) {
|
|
13839
13987
|
if (typeof atob === "undefined") {
|
|
13840
|
-
if (_optionalChain([clientOptions, 'access',
|
|
13988
|
+
if (_optionalChain([clientOptions, 'access', _325 => _325.polyfills, 'optionalAccess', _326 => _326.atob]) === void 0) {
|
|
13841
13989
|
throw new Error(
|
|
13842
13990
|
"You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
|
|
13843
13991
|
);
|
|
@@ -13849,7 +13997,7 @@ function createClient(options) {
|
|
|
13849
13997
|
return leaseRoom(newRoomDetails);
|
|
13850
13998
|
}
|
|
13851
13999
|
function getRoom(roomId) {
|
|
13852
|
-
const room = _optionalChain([roomsById, 'access',
|
|
14000
|
+
const room = _optionalChain([roomsById, 'access', _327 => _327.get, 'call', _328 => _328(roomId), 'optionalAccess', _329 => _329.room]);
|
|
13853
14001
|
return room ? room : null;
|
|
13854
14002
|
}
|
|
13855
14003
|
function logout() {
|
|
@@ -13865,7 +14013,7 @@ function createClient(options) {
|
|
|
13865
14013
|
const batchedResolveUsers = new Batch(
|
|
13866
14014
|
async (batchedUserIds) => {
|
|
13867
14015
|
const userIds = batchedUserIds.flat();
|
|
13868
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
14016
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _330 => _330({ userIds })]);
|
|
13869
14017
|
warnOnceIf(
|
|
13870
14018
|
!resolveUsers,
|
|
13871
14019
|
"Set the resolveUsers option in createClient to specify user info."
|
|
@@ -13882,7 +14030,7 @@ function createClient(options) {
|
|
|
13882
14030
|
const batchedResolveRoomsInfo = new Batch(
|
|
13883
14031
|
async (batchedRoomIds) => {
|
|
13884
14032
|
const roomIds = batchedRoomIds.flat();
|
|
13885
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
14033
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _331 => _331({ roomIds })]);
|
|
13886
14034
|
warnOnceIf(
|
|
13887
14035
|
!resolveRoomsInfo,
|
|
13888
14036
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
@@ -13899,7 +14047,7 @@ function createClient(options) {
|
|
|
13899
14047
|
const batchedResolveGroupsInfo = new Batch(
|
|
13900
14048
|
async (batchedGroupIds) => {
|
|
13901
14049
|
const groupIds = batchedGroupIds.flat();
|
|
13902
|
-
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall',
|
|
14050
|
+
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _332 => _332({ groupIds })]);
|
|
13903
14051
|
warnOnceIf(
|
|
13904
14052
|
!resolveGroupsInfo,
|
|
13905
14053
|
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
@@ -13958,7 +14106,7 @@ function createClient(options) {
|
|
|
13958
14106
|
}
|
|
13959
14107
|
};
|
|
13960
14108
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
13961
|
-
_optionalChain([win, 'optionalAccess',
|
|
14109
|
+
_optionalChain([win, 'optionalAccess', _333 => _333.addEventListener, 'call', _334 => _334("beforeunload", maybePreventClose)]);
|
|
13962
14110
|
}
|
|
13963
14111
|
async function getNotificationSettings(options2) {
|
|
13964
14112
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -14086,7 +14234,7 @@ var commentBodyElementsTypes = {
|
|
|
14086
14234
|
mention: "inline"
|
|
14087
14235
|
};
|
|
14088
14236
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
14089
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
14237
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _335 => _335.content])) {
|
|
14090
14238
|
return;
|
|
14091
14239
|
}
|
|
14092
14240
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -14096,13 +14244,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
14096
14244
|
for (const block of body.content) {
|
|
14097
14245
|
if (type === "all" || type === "block") {
|
|
14098
14246
|
if (guard(block)) {
|
|
14099
|
-
_optionalChain([visitor, 'optionalCall',
|
|
14247
|
+
_optionalChain([visitor, 'optionalCall', _336 => _336(block)]);
|
|
14100
14248
|
}
|
|
14101
14249
|
}
|
|
14102
14250
|
if (type === "all" || type === "inline") {
|
|
14103
14251
|
for (const inline of block.children) {
|
|
14104
14252
|
if (guard(inline)) {
|
|
14105
|
-
_optionalChain([visitor, 'optionalCall',
|
|
14253
|
+
_optionalChain([visitor, 'optionalCall', _337 => _337(inline)]);
|
|
14106
14254
|
}
|
|
14107
14255
|
}
|
|
14108
14256
|
}
|
|
@@ -14272,7 +14420,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
14272
14420
|
text: ({ element }) => element.text,
|
|
14273
14421
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
14274
14422
|
mention: ({ element, user, group }) => {
|
|
14275
|
-
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
14423
|
+
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _338 => _338.name]), () => ( _optionalChain([group, 'optionalAccess', _339 => _339.name]))), () => ( element.id))}`;
|
|
14276
14424
|
}
|
|
14277
14425
|
};
|
|
14278
14426
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -14302,7 +14450,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
14302
14450
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
14303
14451
|
},
|
|
14304
14452
|
mention: ({ element, user, group }) => {
|
|
14305
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
14453
|
+
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _340 => _340.name]) ? html`${_optionalChain([user, 'optionalAccess', _341 => _341.name])}` : _optionalChain([group, 'optionalAccess', _342 => _342.name]) ? html`${_optionalChain([group, 'optionalAccess', _343 => _343.name])}` : element.id}</span>`;
|
|
14306
14454
|
}
|
|
14307
14455
|
};
|
|
14308
14456
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -14332,20 +14480,20 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
14332
14480
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
14333
14481
|
},
|
|
14334
14482
|
mention: ({ element, user, group }) => {
|
|
14335
|
-
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
14483
|
+
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _344 => _344.name]), () => ( _optionalChain([group, 'optionalAccess', _345 => _345.name]))), () => ( element.id))}`;
|
|
14336
14484
|
}
|
|
14337
14485
|
};
|
|
14338
14486
|
async function stringifyCommentBody(body, options) {
|
|
14339
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
14340
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
14487
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _346 => _346.format]), () => ( "plain"));
|
|
14488
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _347 => _347.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
14341
14489
|
const elements = {
|
|
14342
14490
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
14343
|
-
..._optionalChain([options, 'optionalAccess',
|
|
14491
|
+
..._optionalChain([options, 'optionalAccess', _348 => _348.elements])
|
|
14344
14492
|
};
|
|
14345
14493
|
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
14346
14494
|
body,
|
|
14347
|
-
_optionalChain([options, 'optionalAccess',
|
|
14348
|
-
_optionalChain([options, 'optionalAccess',
|
|
14495
|
+
_optionalChain([options, 'optionalAccess', _349 => _349.resolveUsers]),
|
|
14496
|
+
_optionalChain([options, 'optionalAccess', _350 => _350.resolveGroupsInfo])
|
|
14349
14497
|
);
|
|
14350
14498
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
14351
14499
|
switch (block.type) {
|
|
@@ -14491,9 +14639,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
14491
14639
|
const startTime = performance.now();
|
|
14492
14640
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
14493
14641
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
14494
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
14642
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _351 => _351.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
14495
14643
|
const context = {
|
|
14496
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
14644
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _352 => _352.visibilityState]) !== "hidden",
|
|
14497
14645
|
lastSuccessfulPollAt: startTime,
|
|
14498
14646
|
count: 0,
|
|
14499
14647
|
backoff: 0
|
|
@@ -14574,11 +14722,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
14574
14722
|
pollNowIfStale();
|
|
14575
14723
|
}
|
|
14576
14724
|
function onVisibilityChange() {
|
|
14577
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
14725
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _353 => _353.visibilityState]) !== "hidden");
|
|
14578
14726
|
}
|
|
14579
|
-
_optionalChain([doc, 'optionalAccess',
|
|
14580
|
-
_optionalChain([win, 'optionalAccess',
|
|
14581
|
-
_optionalChain([win, 'optionalAccess',
|
|
14727
|
+
_optionalChain([doc, 'optionalAccess', _354 => _354.addEventListener, 'call', _355 => _355("visibilitychange", onVisibilityChange)]);
|
|
14728
|
+
_optionalChain([win, 'optionalAccess', _356 => _356.addEventListener, 'call', _357 => _357("online", onVisibilityChange)]);
|
|
14729
|
+
_optionalChain([win, 'optionalAccess', _358 => _358.addEventListener, 'call', _359 => _359("focus", pollNowIfStale)]);
|
|
14582
14730
|
fsm.start();
|
|
14583
14731
|
return {
|
|
14584
14732
|
inc,
|
|
@@ -14732,5 +14880,5 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
14732
14880
|
|
|
14733
14881
|
|
|
14734
14882
|
|
|
14735
|
-
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.FeedRequestErrorCode = FeedRequestErrorCode; exports.HttpError = HttpError; exports.LiveFile = LiveFile; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveText = LiveText; exports.LiveblocksError = LiveblocksError; exports.MENTION_CHARACTER = MENTION_CHARACTER; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.applyLiveTextOperations = applyLiveTextOperations; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactNodesToNodeStream = compactNodesToNodeStream; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createStorageFileId = createStorageFileId; exports.createThreadId = createThreadId; exports.deepLiveify = deepLiveify; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getLiveFileId = getLiveFileId; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.hasPermissionAccess = hasPermissionAccess; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isFileStorageNode = isFileStorageNode; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isListStorageNode = isListStorageNode; exports.isLiveNode = isLiveNode; exports.isMapStorageNode = isMapStorageNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isObjectStorageNode = isObjectStorageNode; exports.isPlainObject = isPlainObject; exports.isRegisterStorageNode = isRegisterStorageNode; exports.isRootStorageNode = isRootStorageNode; exports.isStartsWithOperator = isStartsWithOperator; exports.isTextStorageNode = isTextStorageNode; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.
|
|
14883
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.FeedRequestErrorCode = FeedRequestErrorCode; exports.HttpError = HttpError; exports.LiveFile = LiveFile; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveText = LiveText; exports.LiveblocksError = LiveblocksError; exports.MENTION_CHARACTER = MENTION_CHARACTER; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.applyLiveTextOperations = applyLiveTextOperations; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactNodesToNodeStream = compactNodesToNodeStream; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createStorageFileId = createStorageFileId; exports.createThreadId = createThreadId; exports.deepLiveify = deepLiveify; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getLiveFileId = getLiveFileId; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.hasPermissionAccess = hasPermissionAccess; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isFileStorageNode = isFileStorageNode; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isListStorageNode = isListStorageNode; exports.isLiveNode = isLiveNode; exports.isMapStorageNode = isMapStorageNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isObjectStorageNode = isObjectStorageNode; exports.isPlainObject = isPlainObject; exports.isRegisterStorageNode = isRegisterStorageNode; exports.isRootStorageNode = isRootStorageNode; exports.isStartsWithOperator = isStartsWithOperator; exports.isTextStorageNode = isTextStorageNode; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.mergeRoomPermissionScopes = mergeRoomPermissionScopes; exports.nanoid = nanoid; exports.nn = nn; exports.nodeStreamToCompactNodes = nodeStreamToCompactNodes; exports.normalizeLiveTextOperations = normalizeLiveTextOperations; exports.normalizeRoomAccesses = normalizeRoomAccesses; exports.normalizeRoomPermissions = normalizeRoomPermissions; exports.normalizeUpdateRoomAccesses = normalizeUpdateRoomAccesses; exports.objectToQuery = objectToQuery; exports.patchNotificationSettings = patchNotificationSettings; exports.permissionMatrixFromScopes = permissionMatrixFromScopes; exports.raise = raise; exports.resolveMentionsInCommentBody = resolveMentionsInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.transformTextOperations = transformTextOperations; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.validatePermissionsSet = validatePermissionsSet; exports.wait = wait; exports.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
|
|
14736
14884
|
//# sourceMappingURL=index.cjs.map
|