@liveblocks/core 3.19.5-rc1 → 3.20.0-exp1
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 +792 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +122 -10
- package/dist/index.d.ts +122 -10
- package/dist/index.js +722 -11
- 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.
|
|
9
|
+
var PKG_VERSION = "3.20.0-exp1";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -5511,7 +5511,9 @@ var OpCode = Object.freeze({
|
|
|
5511
5511
|
DELETE_CRDT: 5,
|
|
5512
5512
|
DELETE_OBJECT_KEY: 6,
|
|
5513
5513
|
CREATE_MAP: 7,
|
|
5514
|
-
CREATE_REGISTER: 8
|
|
5514
|
+
CREATE_REGISTER: 8,
|
|
5515
|
+
CREATE_TEXT: 9,
|
|
5516
|
+
UPDATE_TEXT: 10
|
|
5515
5517
|
});
|
|
5516
5518
|
function isIgnoredOp(op) {
|
|
5517
5519
|
return op.type === OpCode.DELETE_CRDT && op.id === "ACK";
|
|
@@ -5525,7 +5527,8 @@ var CrdtType = Object.freeze({
|
|
|
5525
5527
|
OBJECT: 0,
|
|
5526
5528
|
LIST: 1,
|
|
5527
5529
|
MAP: 2,
|
|
5528
|
-
REGISTER: 3
|
|
5530
|
+
REGISTER: 3,
|
|
5531
|
+
TEXT: 4
|
|
5529
5532
|
});
|
|
5530
5533
|
function isRootStorageNode(node) {
|
|
5531
5534
|
return node[0] === "root";
|
|
@@ -5542,6 +5545,9 @@ function isMapStorageNode(node) {
|
|
|
5542
5545
|
function isRegisterStorageNode(node) {
|
|
5543
5546
|
return node[1].type === CrdtType.REGISTER;
|
|
5544
5547
|
}
|
|
5548
|
+
function isTextStorageNode(node) {
|
|
5549
|
+
return node[1].type === CrdtType.TEXT;
|
|
5550
|
+
}
|
|
5545
5551
|
function isCompactRootNode(node) {
|
|
5546
5552
|
return node[0] === "root";
|
|
5547
5553
|
}
|
|
@@ -5564,6 +5570,9 @@ function* compactNodesToNodeStream(compactNodes) {
|
|
|
5564
5570
|
case CrdtType.REGISTER:
|
|
5565
5571
|
yield [cnode[0], { type: CrdtType.REGISTER, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
5566
5572
|
break;
|
|
5573
|
+
case CrdtType.TEXT:
|
|
5574
|
+
yield [cnode[0], { type: CrdtType.TEXT, parentId: cnode[2], parentKey: cnode[3], data: cnode[4], version: cnode[5] }];
|
|
5575
|
+
break;
|
|
5567
5576
|
default:
|
|
5568
5577
|
}
|
|
5569
5578
|
}
|
|
@@ -5592,6 +5601,17 @@ function* nodeStreamToCompactNodes(nodes) {
|
|
|
5592
5601
|
const id = node[0];
|
|
5593
5602
|
const crdt = node[1];
|
|
5594
5603
|
yield [id, CrdtType.REGISTER, crdt.parentId, crdt.parentKey, crdt.data];
|
|
5604
|
+
} else if (isTextStorageNode(node)) {
|
|
5605
|
+
const id = node[0];
|
|
5606
|
+
const crdt = node[1];
|
|
5607
|
+
yield [
|
|
5608
|
+
id,
|
|
5609
|
+
CrdtType.TEXT,
|
|
5610
|
+
crdt.parentId,
|
|
5611
|
+
crdt.parentKey,
|
|
5612
|
+
crdt.data,
|
|
5613
|
+
crdt.version
|
|
5614
|
+
];
|
|
5595
5615
|
} else {
|
|
5596
5616
|
}
|
|
5597
5617
|
}
|
|
@@ -7928,6 +7948,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7928
7948
|
const id = nn(this._id);
|
|
7929
7949
|
const parentKey = nn(child._parentKey);
|
|
7930
7950
|
const reverse = child._toOps(id, parentKey);
|
|
7951
|
+
const deletedItem = liveNodeToLson(child);
|
|
7931
7952
|
for (const [key, value] of this.#synced) {
|
|
7932
7953
|
if (value === child) {
|
|
7933
7954
|
this.#synced.delete(key);
|
|
@@ -7939,7 +7960,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7939
7960
|
node: this,
|
|
7940
7961
|
type: "LiveObject",
|
|
7941
7962
|
updates: {
|
|
7942
|
-
[parentKey]: { type: "delete" }
|
|
7963
|
+
[parentKey]: { type: "delete", deletedItem }
|
|
7943
7964
|
}
|
|
7944
7965
|
};
|
|
7945
7966
|
return { modified: storageUpdate, reverse };
|
|
@@ -8426,6 +8447,581 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8426
8447
|
}
|
|
8427
8448
|
}, _class2.__initStatic(), _class2);
|
|
8428
8449
|
|
|
8450
|
+
// src/crdts/liveTextOps.ts
|
|
8451
|
+
function attributesEqual(left, right) {
|
|
8452
|
+
if (left === right) {
|
|
8453
|
+
return true;
|
|
8454
|
+
}
|
|
8455
|
+
if (left === void 0 || right === void 0) {
|
|
8456
|
+
return false;
|
|
8457
|
+
}
|
|
8458
|
+
const leftKeys = Object.keys(left);
|
|
8459
|
+
const rightKeys = Object.keys(right);
|
|
8460
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
8461
|
+
return false;
|
|
8462
|
+
}
|
|
8463
|
+
for (const key of leftKeys) {
|
|
8464
|
+
if (left[key] !== right[key]) {
|
|
8465
|
+
return false;
|
|
8466
|
+
}
|
|
8467
|
+
}
|
|
8468
|
+
return true;
|
|
8469
|
+
}
|
|
8470
|
+
function cloneAttributes(attributes) {
|
|
8471
|
+
return attributes === void 0 ? void 0 : freeze({ ...attributes });
|
|
8472
|
+
}
|
|
8473
|
+
function normalizeSegments(segments) {
|
|
8474
|
+
const normalized = [];
|
|
8475
|
+
for (const segment of segments) {
|
|
8476
|
+
if (segment.text.length === 0) {
|
|
8477
|
+
continue;
|
|
8478
|
+
}
|
|
8479
|
+
const last = normalized.at(-1);
|
|
8480
|
+
const attributes = cloneAttributes(segment.attributes);
|
|
8481
|
+
if (last !== void 0 && attributesEqual(last.attributes, attributes)) {
|
|
8482
|
+
last.text += segment.text;
|
|
8483
|
+
} else {
|
|
8484
|
+
normalized.push({ text: segment.text, attributes });
|
|
8485
|
+
}
|
|
8486
|
+
}
|
|
8487
|
+
return normalized;
|
|
8488
|
+
}
|
|
8489
|
+
function deltaToSegments(delta) {
|
|
8490
|
+
return normalizeSegments(
|
|
8491
|
+
delta.map((item) => ({
|
|
8492
|
+
text: item.text,
|
|
8493
|
+
attributes: item.attributes
|
|
8494
|
+
}))
|
|
8495
|
+
);
|
|
8496
|
+
}
|
|
8497
|
+
function segmentsToDelta(segments) {
|
|
8498
|
+
return segments.map(
|
|
8499
|
+
(segment) => segment.attributes === void 0 ? { text: segment.text } : { text: segment.text, attributes: { ...segment.attributes } }
|
|
8500
|
+
);
|
|
8501
|
+
}
|
|
8502
|
+
function textLength(segments) {
|
|
8503
|
+
return segments.reduce((sum, segment) => sum + segment.text.length, 0);
|
|
8504
|
+
}
|
|
8505
|
+
function splitSegmentsAt(segments, index) {
|
|
8506
|
+
const result = [];
|
|
8507
|
+
let offset = 0;
|
|
8508
|
+
for (const segment of segments) {
|
|
8509
|
+
const end = offset + segment.text.length;
|
|
8510
|
+
if (index > offset && index < end) {
|
|
8511
|
+
const before2 = segment.text.slice(0, index - offset);
|
|
8512
|
+
const after2 = segment.text.slice(index - offset);
|
|
8513
|
+
result.push({ text: before2, attributes: segment.attributes });
|
|
8514
|
+
result.push({ text: after2, attributes: segment.attributes });
|
|
8515
|
+
} else {
|
|
8516
|
+
result.push({ text: segment.text, attributes: segment.attributes });
|
|
8517
|
+
}
|
|
8518
|
+
offset = end;
|
|
8519
|
+
}
|
|
8520
|
+
return result;
|
|
8521
|
+
}
|
|
8522
|
+
function clipRange(index, length, contentLength) {
|
|
8523
|
+
const clippedIndex = Math.max(0, Math.min(index, contentLength));
|
|
8524
|
+
const clippedEnd = Math.max(
|
|
8525
|
+
clippedIndex,
|
|
8526
|
+
Math.min(index + length, contentLength)
|
|
8527
|
+
);
|
|
8528
|
+
return { index: clippedIndex, length: clippedEnd - clippedIndex };
|
|
8529
|
+
}
|
|
8530
|
+
function applyInsert(segments, index, text, attributes) {
|
|
8531
|
+
if (text.length === 0) {
|
|
8532
|
+
return normalizeSegments(segments);
|
|
8533
|
+
}
|
|
8534
|
+
const split = splitSegmentsAt(segments, index);
|
|
8535
|
+
const result = [];
|
|
8536
|
+
let offset = 0;
|
|
8537
|
+
let inserted = false;
|
|
8538
|
+
for (const segment of split) {
|
|
8539
|
+
if (!inserted && offset === index) {
|
|
8540
|
+
result.push({ text, attributes });
|
|
8541
|
+
inserted = true;
|
|
8542
|
+
}
|
|
8543
|
+
result.push(segment);
|
|
8544
|
+
offset += segment.text.length;
|
|
8545
|
+
}
|
|
8546
|
+
if (!inserted) {
|
|
8547
|
+
result.push({ text, attributes });
|
|
8548
|
+
}
|
|
8549
|
+
return normalizeSegments(result);
|
|
8550
|
+
}
|
|
8551
|
+
function extractDeletedSegments(segments, index, length) {
|
|
8552
|
+
const split = splitSegmentsAt(
|
|
8553
|
+
splitSegmentsAt(segments, index),
|
|
8554
|
+
index + length
|
|
8555
|
+
);
|
|
8556
|
+
const deleted = [];
|
|
8557
|
+
let offset = 0;
|
|
8558
|
+
for (const segment of split) {
|
|
8559
|
+
const end = offset + segment.text.length;
|
|
8560
|
+
if (offset >= index && end <= index + length) {
|
|
8561
|
+
deleted.push({
|
|
8562
|
+
text: segment.text,
|
|
8563
|
+
attributes: segment.attributes
|
|
8564
|
+
});
|
|
8565
|
+
}
|
|
8566
|
+
offset = end;
|
|
8567
|
+
}
|
|
8568
|
+
return normalizeSegments(deleted);
|
|
8569
|
+
}
|
|
8570
|
+
function applyDelete(segments, index, length) {
|
|
8571
|
+
const deletedSegments = extractDeletedSegments(segments, index, length);
|
|
8572
|
+
const split = splitSegmentsAt(
|
|
8573
|
+
splitSegmentsAt(segments, index),
|
|
8574
|
+
index + length
|
|
8575
|
+
);
|
|
8576
|
+
const result = [];
|
|
8577
|
+
let offset = 0;
|
|
8578
|
+
let deletedText = "";
|
|
8579
|
+
for (const segment of split) {
|
|
8580
|
+
const end = offset + segment.text.length;
|
|
8581
|
+
if (offset >= index && end <= index + length) {
|
|
8582
|
+
deletedText += segment.text;
|
|
8583
|
+
} else {
|
|
8584
|
+
result.push(segment);
|
|
8585
|
+
}
|
|
8586
|
+
offset = end;
|
|
8587
|
+
}
|
|
8588
|
+
return {
|
|
8589
|
+
segments: normalizeSegments(result),
|
|
8590
|
+
deletedText,
|
|
8591
|
+
deletedSegments
|
|
8592
|
+
};
|
|
8593
|
+
}
|
|
8594
|
+
function applyFormat(segments, index, length, attributes) {
|
|
8595
|
+
const split = splitSegmentsAt(
|
|
8596
|
+
splitSegmentsAt(segments, index),
|
|
8597
|
+
index + length
|
|
8598
|
+
);
|
|
8599
|
+
const result = [];
|
|
8600
|
+
let offset = 0;
|
|
8601
|
+
for (const segment of split) {
|
|
8602
|
+
const end = offset + segment.text.length;
|
|
8603
|
+
if (offset >= index && end <= index + length) {
|
|
8604
|
+
const nextAttributes = {
|
|
8605
|
+
..._nullishCoalesce(segment.attributes, () => ( {}))
|
|
8606
|
+
};
|
|
8607
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
8608
|
+
if (value === null) {
|
|
8609
|
+
delete nextAttributes[key];
|
|
8610
|
+
} else {
|
|
8611
|
+
nextAttributes[key] = value;
|
|
8612
|
+
}
|
|
8613
|
+
}
|
|
8614
|
+
result.push({
|
|
8615
|
+
text: segment.text,
|
|
8616
|
+
attributes: Object.keys(nextAttributes).length === 0 ? void 0 : freeze(nextAttributes)
|
|
8617
|
+
});
|
|
8618
|
+
} else {
|
|
8619
|
+
result.push(segment);
|
|
8620
|
+
}
|
|
8621
|
+
offset = end;
|
|
8622
|
+
}
|
|
8623
|
+
return normalizeSegments(result);
|
|
8624
|
+
}
|
|
8625
|
+
function formatReverseOperations(segments, index, length, patch) {
|
|
8626
|
+
const split = splitSegmentsAt(
|
|
8627
|
+
splitSegmentsAt(segments, index),
|
|
8628
|
+
index + length
|
|
8629
|
+
);
|
|
8630
|
+
const result = [];
|
|
8631
|
+
let offset = 0;
|
|
8632
|
+
for (const segment of split) {
|
|
8633
|
+
const end = offset + segment.text.length;
|
|
8634
|
+
if (offset >= index && end <= index + length) {
|
|
8635
|
+
const attributes = {};
|
|
8636
|
+
for (const key of Object.keys(patch)) {
|
|
8637
|
+
attributes[key] = _nullishCoalesce(_optionalChain([segment, 'access', _213 => _213.attributes, 'optionalAccess', _214 => _214[key]]), () => ( null));
|
|
8638
|
+
}
|
|
8639
|
+
result.push({
|
|
8640
|
+
type: "format",
|
|
8641
|
+
index: offset,
|
|
8642
|
+
length: segment.text.length,
|
|
8643
|
+
attributes
|
|
8644
|
+
});
|
|
8645
|
+
}
|
|
8646
|
+
offset = end;
|
|
8647
|
+
}
|
|
8648
|
+
return result;
|
|
8649
|
+
}
|
|
8650
|
+
function mapIndexThroughOperation(index, op) {
|
|
8651
|
+
if (op.type === "insert") {
|
|
8652
|
+
return op.index <= index ? index + op.text.length : index;
|
|
8653
|
+
} else if (op.type === "delete") {
|
|
8654
|
+
if (op.index >= index) {
|
|
8655
|
+
return index;
|
|
8656
|
+
}
|
|
8657
|
+
return Math.max(op.index, index - op.length);
|
|
8658
|
+
} else {
|
|
8659
|
+
return index;
|
|
8660
|
+
}
|
|
8661
|
+
}
|
|
8662
|
+
function mapTextIndexThroughOperations(index, ops) {
|
|
8663
|
+
let mapped = index;
|
|
8664
|
+
for (const op of ops) {
|
|
8665
|
+
mapped = mapIndexThroughOperation(mapped, op);
|
|
8666
|
+
}
|
|
8667
|
+
return mapped;
|
|
8668
|
+
}
|
|
8669
|
+
function rebaseTextOperations(ops, acceptedOps) {
|
|
8670
|
+
return ops.map((op) => {
|
|
8671
|
+
if (op.type === "insert") {
|
|
8672
|
+
return {
|
|
8673
|
+
...op,
|
|
8674
|
+
index: mapTextIndexThroughOperations(op.index, acceptedOps)
|
|
8675
|
+
};
|
|
8676
|
+
} else if (op.type === "delete" || op.type === "format") {
|
|
8677
|
+
const start = mapTextIndexThroughOperations(op.index, acceptedOps);
|
|
8678
|
+
const end = mapTextIndexThroughOperations(
|
|
8679
|
+
op.index + op.length,
|
|
8680
|
+
acceptedOps
|
|
8681
|
+
);
|
|
8682
|
+
return { ...op, index: start, length: Math.max(0, end - start) };
|
|
8683
|
+
} else {
|
|
8684
|
+
return op;
|
|
8685
|
+
}
|
|
8686
|
+
});
|
|
8687
|
+
}
|
|
8688
|
+
function applyTextOperationsToSegments(segments, ops) {
|
|
8689
|
+
let next = [...segments];
|
|
8690
|
+
for (const op of ops) {
|
|
8691
|
+
if (op.type === "insert") {
|
|
8692
|
+
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8693
|
+
next = applyInsert(next, index, op.text, op.attributes);
|
|
8694
|
+
} else if (op.type === "delete") {
|
|
8695
|
+
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8696
|
+
const clipped = clipRange(index, op.length, textLength(next));
|
|
8697
|
+
next = applyDelete(next, clipped.index, clipped.length).segments;
|
|
8698
|
+
} else {
|
|
8699
|
+
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8700
|
+
const clipped = clipRange(index, op.length, textLength(next));
|
|
8701
|
+
next = applyFormat(next, clipped.index, clipped.length, op.attributes);
|
|
8702
|
+
}
|
|
8703
|
+
}
|
|
8704
|
+
return next;
|
|
8705
|
+
}
|
|
8706
|
+
function applyLiveTextOperations(delta, ops) {
|
|
8707
|
+
return segmentsToDelta(applyTextOperationsToSegments(deltaToSegments(delta), ops));
|
|
8708
|
+
}
|
|
8709
|
+
function invertTextOperations(segments, ops) {
|
|
8710
|
+
let shadow = [...segments];
|
|
8711
|
+
const reverse = [];
|
|
8712
|
+
for (const op of ops) {
|
|
8713
|
+
if (op.type === "insert") {
|
|
8714
|
+
shadow = applyInsert(shadow, op.index, op.text, op.attributes);
|
|
8715
|
+
reverse.unshift({
|
|
8716
|
+
type: "delete",
|
|
8717
|
+
index: op.index,
|
|
8718
|
+
length: op.text.length
|
|
8719
|
+
});
|
|
8720
|
+
} else if (op.type === "delete") {
|
|
8721
|
+
const deletedSegments = extractDeletedSegments(
|
|
8722
|
+
shadow,
|
|
8723
|
+
op.index,
|
|
8724
|
+
op.length
|
|
8725
|
+
);
|
|
8726
|
+
shadow = applyDelete(shadow, op.index, op.length).segments;
|
|
8727
|
+
const inserts = [];
|
|
8728
|
+
let insertIndex = op.index;
|
|
8729
|
+
for (const segment of deletedSegments) {
|
|
8730
|
+
inserts.push({
|
|
8731
|
+
type: "insert",
|
|
8732
|
+
index: insertIndex,
|
|
8733
|
+
text: segment.text,
|
|
8734
|
+
attributes: segment.attributes
|
|
8735
|
+
});
|
|
8736
|
+
insertIndex += segment.text.length;
|
|
8737
|
+
}
|
|
8738
|
+
for (let index = inserts.length - 1; index >= 0; index--) {
|
|
8739
|
+
reverse.unshift(inserts[index]);
|
|
8740
|
+
}
|
|
8741
|
+
} else {
|
|
8742
|
+
const inverse = formatReverseOperations(
|
|
8743
|
+
shadow,
|
|
8744
|
+
op.index,
|
|
8745
|
+
op.length,
|
|
8746
|
+
op.attributes
|
|
8747
|
+
);
|
|
8748
|
+
shadow = applyFormat(shadow, op.index, op.length, op.attributes);
|
|
8749
|
+
reverse.unshift(...inverse.reverse());
|
|
8750
|
+
}
|
|
8751
|
+
}
|
|
8752
|
+
return reverse;
|
|
8753
|
+
}
|
|
8754
|
+
|
|
8755
|
+
// src/crdts/LiveText.ts
|
|
8756
|
+
var LiveText = class _LiveText extends AbstractCrdt {
|
|
8757
|
+
#segments;
|
|
8758
|
+
#version;
|
|
8759
|
+
#pendingOps;
|
|
8760
|
+
constructor(textOrDelta = "", version = 0) {
|
|
8761
|
+
super();
|
|
8762
|
+
this.#segments = typeof textOrDelta === "string" ? textOrDelta.length === 0 ? [] : [{ text: textOrDelta }] : deltaToSegments(textOrDelta);
|
|
8763
|
+
this.#version = version;
|
|
8764
|
+
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8765
|
+
}
|
|
8766
|
+
get version() {
|
|
8767
|
+
return this.#version;
|
|
8768
|
+
}
|
|
8769
|
+
get length() {
|
|
8770
|
+
return this.toString().length;
|
|
8771
|
+
}
|
|
8772
|
+
/** @internal */
|
|
8773
|
+
static _deserialize([id, item], _parentToChildren, pool) {
|
|
8774
|
+
const text = new _LiveText(item.data, item.version);
|
|
8775
|
+
text._attach(id, pool);
|
|
8776
|
+
return text;
|
|
8777
|
+
}
|
|
8778
|
+
/** @internal */
|
|
8779
|
+
_toOps(parentId, parentKey) {
|
|
8780
|
+
if (this._id === void 0) {
|
|
8781
|
+
throw new Error("Cannot serialize LiveText if it is not attached");
|
|
8782
|
+
}
|
|
8783
|
+
return [
|
|
8784
|
+
{
|
|
8785
|
+
type: OpCode.CREATE_TEXT,
|
|
8786
|
+
id: this._id,
|
|
8787
|
+
parentId,
|
|
8788
|
+
parentKey,
|
|
8789
|
+
data: this.toDelta(),
|
|
8790
|
+
version: this.#version
|
|
8791
|
+
}
|
|
8792
|
+
];
|
|
8793
|
+
}
|
|
8794
|
+
/** @internal */
|
|
8795
|
+
_serialize() {
|
|
8796
|
+
if (this.parent.type !== "HasParent") {
|
|
8797
|
+
throw new Error("Cannot serialize LiveText if parent is missing");
|
|
8798
|
+
}
|
|
8799
|
+
return {
|
|
8800
|
+
type: CrdtType.TEXT,
|
|
8801
|
+
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8802
|
+
parentKey: this.parent.key,
|
|
8803
|
+
data: this.toDelta(),
|
|
8804
|
+
version: this.#version
|
|
8805
|
+
};
|
|
8806
|
+
}
|
|
8807
|
+
/** @internal */
|
|
8808
|
+
_attachChild(_op) {
|
|
8809
|
+
throw new Error("LiveText cannot contain child nodes");
|
|
8810
|
+
}
|
|
8811
|
+
/** @internal */
|
|
8812
|
+
_detachChild(_crdt) {
|
|
8813
|
+
throw new Error("LiveText cannot contain child nodes");
|
|
8814
|
+
}
|
|
8815
|
+
/** @internal */
|
|
8816
|
+
_apply(op, isLocal) {
|
|
8817
|
+
if (op.type !== OpCode.UPDATE_TEXT) {
|
|
8818
|
+
return super._apply(op, isLocal);
|
|
8819
|
+
}
|
|
8820
|
+
if (isLocal) {
|
|
8821
|
+
this.#pendingOps.set(nn(op.opId), op.ops);
|
|
8822
|
+
return this.#applyOperations(op.ops, _nullishCoalesce(op.version, () => ( this.#version)));
|
|
8823
|
+
}
|
|
8824
|
+
if (op.opId !== void 0) {
|
|
8825
|
+
const pending2 = this.#pendingOps.get(op.opId);
|
|
8826
|
+
this.#pendingOps.delete(op.opId);
|
|
8827
|
+
const otherPending = Array.from(this.#pendingOps.values()).flat();
|
|
8828
|
+
if (pending2 !== void 0 && otherPending.length > 0) {
|
|
8829
|
+
this.#segments = applyTextOperationsToSegments(
|
|
8830
|
+
this.#segments,
|
|
8831
|
+
invertTextOperations(this.#segments, pending2)
|
|
8832
|
+
);
|
|
8833
|
+
const ops2 = rebaseTextOperations(op.ops, otherPending);
|
|
8834
|
+
return this.#applyOperations(
|
|
8835
|
+
ops2,
|
|
8836
|
+
_nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)))
|
|
8837
|
+
);
|
|
8838
|
+
}
|
|
8839
|
+
this.#version = _nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)));
|
|
8840
|
+
return { modified: false };
|
|
8841
|
+
}
|
|
8842
|
+
const pending = Array.from(this.#pendingOps.values()).flat();
|
|
8843
|
+
const ops = pending.length > 0 ? rebaseTextOperations(op.ops, pending) : op.ops;
|
|
8844
|
+
return this.#applyOperations(ops, _nullishCoalesce(op.version, () => ( this.#version + 1)));
|
|
8845
|
+
}
|
|
8846
|
+
insert(index, text, attributes) {
|
|
8847
|
+
const clippedIndex = Math.max(0, Math.min(index, this.length));
|
|
8848
|
+
this.#dispatch([{ type: "insert", index: clippedIndex, text, attributes }]);
|
|
8849
|
+
}
|
|
8850
|
+
delete(index, length) {
|
|
8851
|
+
const clipped = clipRange(index, length, this.length);
|
|
8852
|
+
if (clipped.length === 0) {
|
|
8853
|
+
return;
|
|
8854
|
+
}
|
|
8855
|
+
this.#dispatch([
|
|
8856
|
+
{ type: "delete", index: clipped.index, length: clipped.length }
|
|
8857
|
+
]);
|
|
8858
|
+
}
|
|
8859
|
+
replace(index, length, text, attributes) {
|
|
8860
|
+
const clipped = clipRange(index, length, this.length);
|
|
8861
|
+
const ops = [];
|
|
8862
|
+
if (clipped.length > 0) {
|
|
8863
|
+
ops.push({
|
|
8864
|
+
type: "delete",
|
|
8865
|
+
index: clipped.index,
|
|
8866
|
+
length: clipped.length
|
|
8867
|
+
});
|
|
8868
|
+
}
|
|
8869
|
+
if (text.length > 0) {
|
|
8870
|
+
ops.push({ type: "insert", index: clipped.index, text, attributes });
|
|
8871
|
+
}
|
|
8872
|
+
this.#dispatch(ops);
|
|
8873
|
+
}
|
|
8874
|
+
format(index, length, attributes) {
|
|
8875
|
+
const clipped = clipRange(index, length, this.length);
|
|
8876
|
+
if (clipped.length === 0) {
|
|
8877
|
+
return;
|
|
8878
|
+
}
|
|
8879
|
+
this.#dispatch([
|
|
8880
|
+
{
|
|
8881
|
+
type: "format",
|
|
8882
|
+
index: clipped.index,
|
|
8883
|
+
length: clipped.length,
|
|
8884
|
+
attributes
|
|
8885
|
+
}
|
|
8886
|
+
]);
|
|
8887
|
+
}
|
|
8888
|
+
#dispatch(ops) {
|
|
8889
|
+
if (ops.length === 0) {
|
|
8890
|
+
return;
|
|
8891
|
+
}
|
|
8892
|
+
_optionalChain([this, 'access', _215 => _215._pool, 'optionalAccess', _216 => _216.assertStorageIsWritable, 'call', _217 => _217()]);
|
|
8893
|
+
const baseVersion = this.#version;
|
|
8894
|
+
const reverse = this._pool !== void 0 && this._id !== void 0 ? this.#invertOperations(ops) : [];
|
|
8895
|
+
const changes = this.#applyOperationsLocally(ops);
|
|
8896
|
+
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8897
|
+
const opId = this._pool.generateOpId();
|
|
8898
|
+
this.#pendingOps.set(opId, ops);
|
|
8899
|
+
this._pool.dispatch(
|
|
8900
|
+
[
|
|
8901
|
+
{
|
|
8902
|
+
type: OpCode.UPDATE_TEXT,
|
|
8903
|
+
id: this._id,
|
|
8904
|
+
opId,
|
|
8905
|
+
baseVersion,
|
|
8906
|
+
ops: [...ops]
|
|
8907
|
+
}
|
|
8908
|
+
],
|
|
8909
|
+
reverse,
|
|
8910
|
+
/* @__PURE__ */ new Map([
|
|
8911
|
+
[
|
|
8912
|
+
this._id,
|
|
8913
|
+
{
|
|
8914
|
+
type: "LiveText",
|
|
8915
|
+
node: this,
|
|
8916
|
+
version: this.#version,
|
|
8917
|
+
updates: changes
|
|
8918
|
+
}
|
|
8919
|
+
]
|
|
8920
|
+
])
|
|
8921
|
+
);
|
|
8922
|
+
}
|
|
8923
|
+
}
|
|
8924
|
+
#applyOperations(ops, version) {
|
|
8925
|
+
const reverse = this.#invertOperations(ops);
|
|
8926
|
+
const changes = this.#applyOperationsLocally(ops);
|
|
8927
|
+
this.#version = Math.max(this.#version, version);
|
|
8928
|
+
return {
|
|
8929
|
+
reverse,
|
|
8930
|
+
modified: {
|
|
8931
|
+
type: "LiveText",
|
|
8932
|
+
node: this,
|
|
8933
|
+
version: this.#version,
|
|
8934
|
+
updates: changes
|
|
8935
|
+
}
|
|
8936
|
+
};
|
|
8937
|
+
}
|
|
8938
|
+
#applyOperationsLocally(ops) {
|
|
8939
|
+
const changes = [];
|
|
8940
|
+
for (const op of ops) {
|
|
8941
|
+
if (op.type === "insert") {
|
|
8942
|
+
this.#segments = applyInsert(
|
|
8943
|
+
this.#segments,
|
|
8944
|
+
op.index,
|
|
8945
|
+
op.text,
|
|
8946
|
+
op.attributes
|
|
8947
|
+
);
|
|
8948
|
+
changes.push({
|
|
8949
|
+
type: "insert",
|
|
8950
|
+
index: op.index,
|
|
8951
|
+
text: op.text,
|
|
8952
|
+
attributes: op.attributes
|
|
8953
|
+
});
|
|
8954
|
+
} else if (op.type === "delete") {
|
|
8955
|
+
const result = applyDelete(this.#segments, op.index, op.length);
|
|
8956
|
+
this.#segments = result.segments;
|
|
8957
|
+
changes.push({
|
|
8958
|
+
type: "delete",
|
|
8959
|
+
index: op.index,
|
|
8960
|
+
length: op.length,
|
|
8961
|
+
deletedText: result.deletedText
|
|
8962
|
+
});
|
|
8963
|
+
} else {
|
|
8964
|
+
this.#segments = applyFormat(
|
|
8965
|
+
this.#segments,
|
|
8966
|
+
op.index,
|
|
8967
|
+
op.length,
|
|
8968
|
+
op.attributes
|
|
8969
|
+
);
|
|
8970
|
+
changes.push({
|
|
8971
|
+
type: "format",
|
|
8972
|
+
index: op.index,
|
|
8973
|
+
length: op.length,
|
|
8974
|
+
attributes: op.attributes
|
|
8975
|
+
});
|
|
8976
|
+
}
|
|
8977
|
+
}
|
|
8978
|
+
this.invalidate();
|
|
8979
|
+
return changes;
|
|
8980
|
+
}
|
|
8981
|
+
#invertOperations(ops) {
|
|
8982
|
+
return [
|
|
8983
|
+
{
|
|
8984
|
+
type: OpCode.UPDATE_TEXT,
|
|
8985
|
+
id: nn(this._id),
|
|
8986
|
+
baseVersion: this.#version,
|
|
8987
|
+
ops: invertTextOperations(this.#segments, ops)
|
|
8988
|
+
}
|
|
8989
|
+
];
|
|
8990
|
+
}
|
|
8991
|
+
toString() {
|
|
8992
|
+
return this.#segments.map((segment) => segment.text).join("");
|
|
8993
|
+
}
|
|
8994
|
+
toDelta() {
|
|
8995
|
+
return segmentsToDelta(this.#segments);
|
|
8996
|
+
}
|
|
8997
|
+
toJSON() {
|
|
8998
|
+
return super.toJSON();
|
|
8999
|
+
}
|
|
9000
|
+
/** @internal */
|
|
9001
|
+
_toJSON() {
|
|
9002
|
+
return this.toDelta();
|
|
9003
|
+
}
|
|
9004
|
+
/** @internal */
|
|
9005
|
+
_toTreeNode(key) {
|
|
9006
|
+
return {
|
|
9007
|
+
type: "LiveText",
|
|
9008
|
+
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
9009
|
+
key,
|
|
9010
|
+
payload: [
|
|
9011
|
+
{
|
|
9012
|
+
type: "Json",
|
|
9013
|
+
id: `${_nullishCoalesce(this._id, () => ( nanoid()))}:text`,
|
|
9014
|
+
key: "text",
|
|
9015
|
+
payload: this.toString()
|
|
9016
|
+
}
|
|
9017
|
+
]
|
|
9018
|
+
};
|
|
9019
|
+
}
|
|
9020
|
+
clone() {
|
|
9021
|
+
return new _LiveText(this.toDelta(), this.#version);
|
|
9022
|
+
}
|
|
9023
|
+
};
|
|
9024
|
+
|
|
8429
9025
|
// src/crdts/liveblocks-helpers.ts
|
|
8430
9026
|
function creationOpToLiveNode(op) {
|
|
8431
9027
|
return lsonToLiveNode(creationOpToLson(op));
|
|
@@ -8440,6 +9036,8 @@ function creationOpToLson(op) {
|
|
|
8440
9036
|
return new LiveMap();
|
|
8441
9037
|
case OpCode.CREATE_LIST:
|
|
8442
9038
|
return new LiveList([]);
|
|
9039
|
+
case OpCode.CREATE_TEXT:
|
|
9040
|
+
return new LiveText(op.data, op.version);
|
|
8443
9041
|
default:
|
|
8444
9042
|
return assertNever(op, "Unknown creation Op");
|
|
8445
9043
|
}
|
|
@@ -8462,6 +9060,8 @@ function deserialize(node, parentToChildren, pool) {
|
|
|
8462
9060
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
8463
9061
|
} else if (isRegisterStorageNode(node)) {
|
|
8464
9062
|
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
9063
|
+
} else if (isTextStorageNode(node)) {
|
|
9064
|
+
return LiveText._deserialize(node, parentToChildren, pool);
|
|
8465
9065
|
} else {
|
|
8466
9066
|
throw new Error("Unexpected CRDT type");
|
|
8467
9067
|
}
|
|
@@ -8475,12 +9075,14 @@ function deserializeToLson(node, parentToChildren, pool) {
|
|
|
8475
9075
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
8476
9076
|
} else if (isRegisterStorageNode(node)) {
|
|
8477
9077
|
return node[1].data;
|
|
9078
|
+
} else if (isTextStorageNode(node)) {
|
|
9079
|
+
return LiveText._deserialize(node, parentToChildren, pool);
|
|
8478
9080
|
} else {
|
|
8479
9081
|
throw new Error("Unexpected CRDT type");
|
|
8480
9082
|
}
|
|
8481
9083
|
}
|
|
8482
9084
|
function isLiveStructure(value) {
|
|
8483
|
-
return isLiveList(value) || isLiveMap(value) || isLiveObject(value);
|
|
9085
|
+
return isLiveList(value) || isLiveMap(value) || isLiveObject(value) || isLiveText(value);
|
|
8484
9086
|
}
|
|
8485
9087
|
function isLiveNode(value) {
|
|
8486
9088
|
return isLiveStructure(value) || isLiveRegister(value);
|
|
@@ -8494,6 +9096,9 @@ function isLiveMap(value) {
|
|
|
8494
9096
|
function isLiveObject(value) {
|
|
8495
9097
|
return value instanceof LiveObject;
|
|
8496
9098
|
}
|
|
9099
|
+
function isLiveText(value) {
|
|
9100
|
+
return value instanceof LiveText;
|
|
9101
|
+
}
|
|
8497
9102
|
function isLiveRegister(value) {
|
|
8498
9103
|
return value instanceof LiveRegister;
|
|
8499
9104
|
}
|
|
@@ -8503,14 +9108,14 @@ function cloneLson(value) {
|
|
|
8503
9108
|
function liveNodeToLson(obj) {
|
|
8504
9109
|
if (obj instanceof LiveRegister) {
|
|
8505
9110
|
return obj.data;
|
|
8506
|
-
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject) {
|
|
9111
|
+
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject || obj instanceof LiveText) {
|
|
8507
9112
|
return obj;
|
|
8508
9113
|
} else {
|
|
8509
9114
|
return assertNever(obj, "Unknown AbstractCrdt");
|
|
8510
9115
|
}
|
|
8511
9116
|
}
|
|
8512
9117
|
function lsonToLiveNode(value) {
|
|
8513
|
-
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList) {
|
|
9118
|
+
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList || value instanceof LiveText) {
|
|
8514
9119
|
return value;
|
|
8515
9120
|
} else {
|
|
8516
9121
|
return new LiveRegister(value);
|
|
@@ -8541,6 +9146,35 @@ function dumpPool(pool) {
|
|
|
8541
9146
|
(r) => ` ${r.id} parent=${r.parentId} key=${r.key || "\u2014"} ${r.value}`
|
|
8542
9147
|
).join("\n");
|
|
8543
9148
|
}
|
|
9149
|
+
function isJsonEq(a, b) {
|
|
9150
|
+
if (a === b) {
|
|
9151
|
+
return true;
|
|
9152
|
+
}
|
|
9153
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
9154
|
+
return false;
|
|
9155
|
+
}
|
|
9156
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
9157
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
9158
|
+
return false;
|
|
9159
|
+
}
|
|
9160
|
+
for (let i = 0; i < a.length; i++) {
|
|
9161
|
+
if (!isJsonEq(a[i], b[i])) {
|
|
9162
|
+
return false;
|
|
9163
|
+
}
|
|
9164
|
+
}
|
|
9165
|
+
return true;
|
|
9166
|
+
}
|
|
9167
|
+
const aKeys = Object.keys(a);
|
|
9168
|
+
if (aKeys.length !== Object.keys(b).length) {
|
|
9169
|
+
return false;
|
|
9170
|
+
}
|
|
9171
|
+
for (const key of aKeys) {
|
|
9172
|
+
if (!isJsonEq(a[key], b[key])) {
|
|
9173
|
+
return false;
|
|
9174
|
+
}
|
|
9175
|
+
}
|
|
9176
|
+
return true;
|
|
9177
|
+
}
|
|
8544
9178
|
function getTreesDiffOperations(currentItems, newItems) {
|
|
8545
9179
|
const ops = [];
|
|
8546
9180
|
currentItems.forEach((_, id) => {
|
|
@@ -8552,11 +9186,59 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8552
9186
|
const currentCrdt = currentItems.get(id);
|
|
8553
9187
|
if (currentCrdt) {
|
|
8554
9188
|
if (crdt.type === CrdtType.OBJECT) {
|
|
8555
|
-
if (currentCrdt.type !== CrdtType.OBJECT
|
|
9189
|
+
if (currentCrdt.type !== CrdtType.OBJECT) {
|
|
9190
|
+
ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
|
|
9191
|
+
} else {
|
|
9192
|
+
const changed = /* @__PURE__ */ new Map();
|
|
9193
|
+
for (const key of Object.keys(crdt.data)) {
|
|
9194
|
+
const value = crdt.data[key];
|
|
9195
|
+
if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
|
|
9196
|
+
changed.set(key, value);
|
|
9197
|
+
}
|
|
9198
|
+
}
|
|
9199
|
+
if (changed.size > 0) {
|
|
9200
|
+
ops.push({
|
|
9201
|
+
type: OpCode.UPDATE_OBJECT,
|
|
9202
|
+
id,
|
|
9203
|
+
data: Object.fromEntries(changed)
|
|
9204
|
+
});
|
|
9205
|
+
}
|
|
9206
|
+
for (const key of Object.keys(currentCrdt.data)) {
|
|
9207
|
+
if (!(key in crdt.data)) {
|
|
9208
|
+
ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
9209
|
+
}
|
|
9210
|
+
}
|
|
9211
|
+
}
|
|
9212
|
+
}
|
|
9213
|
+
if (crdt.type === CrdtType.TEXT) {
|
|
9214
|
+
if (currentCrdt.type !== CrdtType.TEXT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data) || crdt.version !== currentCrdt.version) {
|
|
8556
9215
|
ops.push({
|
|
8557
|
-
type: OpCode.
|
|
9216
|
+
type: OpCode.UPDATE_TEXT,
|
|
8558
9217
|
id,
|
|
8559
|
-
|
|
9218
|
+
baseVersion: currentCrdt.type === CrdtType.TEXT ? currentCrdt.version : 0,
|
|
9219
|
+
version: crdt.version,
|
|
9220
|
+
ops: [
|
|
9221
|
+
{
|
|
9222
|
+
type: "delete",
|
|
9223
|
+
index: 0,
|
|
9224
|
+
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9225
|
+
(sum, item) => sum + item.text.length,
|
|
9226
|
+
0
|
|
9227
|
+
) : 0
|
|
9228
|
+
},
|
|
9229
|
+
...crdt.data.map(
|
|
9230
|
+
(item, index, items) => item.attributes === void 0 ? {
|
|
9231
|
+
type: "insert",
|
|
9232
|
+
index: items.slice(0, index).reduce((sum, item2) => sum + item2.text.length, 0),
|
|
9233
|
+
text: item.text
|
|
9234
|
+
} : {
|
|
9235
|
+
type: "insert",
|
|
9236
|
+
index: items.slice(0, index).reduce((sum, item2) => sum + item2.text.length, 0),
|
|
9237
|
+
text: item.text,
|
|
9238
|
+
attributes: item.attributes
|
|
9239
|
+
}
|
|
9240
|
+
)
|
|
9241
|
+
]
|
|
8560
9242
|
});
|
|
8561
9243
|
}
|
|
8562
9244
|
}
|
|
@@ -8608,6 +9290,16 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8608
9290
|
parentKey: crdt.parentKey
|
|
8609
9291
|
});
|
|
8610
9292
|
break;
|
|
9293
|
+
case CrdtType.TEXT:
|
|
9294
|
+
ops.push({
|
|
9295
|
+
type: OpCode.CREATE_TEXT,
|
|
9296
|
+
id,
|
|
9297
|
+
parentId: crdt.parentId,
|
|
9298
|
+
parentKey: crdt.parentKey,
|
|
9299
|
+
data: crdt.data,
|
|
9300
|
+
version: crdt.version
|
|
9301
|
+
});
|
|
9302
|
+
break;
|
|
8611
9303
|
}
|
|
8612
9304
|
}
|
|
8613
9305
|
});
|
|
@@ -8640,6 +9332,12 @@ function mergeListStorageUpdates(first, second) {
|
|
|
8640
9332
|
updates: updates.concat(second.updates)
|
|
8641
9333
|
};
|
|
8642
9334
|
}
|
|
9335
|
+
function mergeTextStorageUpdates(first, second) {
|
|
9336
|
+
return {
|
|
9337
|
+
...second,
|
|
9338
|
+
updates: first.updates.concat(second.updates)
|
|
9339
|
+
};
|
|
9340
|
+
}
|
|
8643
9341
|
function mergeStorageUpdates(first, second) {
|
|
8644
9342
|
if (first === void 0) {
|
|
8645
9343
|
return second;
|
|
@@ -8650,6 +9348,8 @@ function mergeStorageUpdates(first, second) {
|
|
|
8650
9348
|
return mergeMapStorageUpdates(first, second);
|
|
8651
9349
|
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
8652
9350
|
return mergeListStorageUpdates(first, second);
|
|
9351
|
+
} else if (first.type === "LiveText" && second.type === "LiveText") {
|
|
9352
|
+
return mergeTextStorageUpdates(first, second);
|
|
8653
9353
|
} else {
|
|
8654
9354
|
}
|
|
8655
9355
|
return second;
|
|
@@ -8668,7 +9368,7 @@ function sendToPanel(message, options) {
|
|
|
8668
9368
|
...message,
|
|
8669
9369
|
source: "liveblocks-devtools-client"
|
|
8670
9370
|
};
|
|
8671
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
9371
|
+
if (!(_optionalChain([options, 'optionalAccess', _218 => _218.force]) || _bridgeActive)) {
|
|
8672
9372
|
return;
|
|
8673
9373
|
}
|
|
8674
9374
|
window.postMessage(fullMsg, "*");
|
|
@@ -8676,7 +9376,7 @@ function sendToPanel(message, options) {
|
|
|
8676
9376
|
var eventSource = makeEventSource();
|
|
8677
9377
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
8678
9378
|
window.addEventListener("message", (event) => {
|
|
8679
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
9379
|
+
if (event.source === window && _optionalChain([event, 'access', _219 => _219.data, 'optionalAccess', _220 => _220.source]) === "liveblocks-devtools-panel") {
|
|
8680
9380
|
eventSource.notify(event.data);
|
|
8681
9381
|
} else {
|
|
8682
9382
|
}
|
|
@@ -8818,7 +9518,7 @@ function fullSync(room) {
|
|
|
8818
9518
|
msg: "room::sync::full",
|
|
8819
9519
|
roomId: room.id,
|
|
8820
9520
|
status: room.getStatus(),
|
|
8821
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
9521
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _221 => _221.toTreeNode, 'call', _222 => _222("root"), 'access', _223 => _223.payload]), () => ( null)),
|
|
8822
9522
|
me,
|
|
8823
9523
|
others
|
|
8824
9524
|
});
|
|
@@ -9497,15 +10197,15 @@ function installBackgroundTabSpy() {
|
|
|
9497
10197
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
9498
10198
|
const inBackgroundSince = { current: null };
|
|
9499
10199
|
function onVisibilityChange() {
|
|
9500
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
10200
|
+
if (_optionalChain([doc, 'optionalAccess', _224 => _224.visibilityState]) === "hidden") {
|
|
9501
10201
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
9502
10202
|
} else {
|
|
9503
10203
|
inBackgroundSince.current = null;
|
|
9504
10204
|
}
|
|
9505
10205
|
}
|
|
9506
|
-
_optionalChain([doc, 'optionalAccess',
|
|
10206
|
+
_optionalChain([doc, 'optionalAccess', _225 => _225.addEventListener, 'call', _226 => _226("visibilitychange", onVisibilityChange)]);
|
|
9507
10207
|
const unsub = () => {
|
|
9508
|
-
_optionalChain([doc, 'optionalAccess',
|
|
10208
|
+
_optionalChain([doc, 'optionalAccess', _227 => _227.removeEventListener, 'call', _228 => _228("visibilitychange", onVisibilityChange)]);
|
|
9509
10209
|
};
|
|
9510
10210
|
return [inBackgroundSince, unsub];
|
|
9511
10211
|
}
|
|
@@ -9698,7 +10398,7 @@ function createRoom(options, config) {
|
|
|
9698
10398
|
}
|
|
9699
10399
|
}
|
|
9700
10400
|
function isStorageWritable() {
|
|
9701
|
-
const scopes = _optionalChain([context, 'access',
|
|
10401
|
+
const scopes = _optionalChain([context, 'access', _229 => _229.dynamicSessionInfoSig, 'access', _230 => _230.get, 'call', _231 => _231(), 'optionalAccess', _232 => _232.scopes]);
|
|
9702
10402
|
return scopes !== void 0 ? canWriteStorage(scopes) : true;
|
|
9703
10403
|
}
|
|
9704
10404
|
const eventHub = {
|
|
@@ -9806,7 +10506,7 @@ function createRoom(options, config) {
|
|
|
9806
10506
|
context.pool
|
|
9807
10507
|
);
|
|
9808
10508
|
}
|
|
9809
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
10509
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _233 => _233.get, 'call', _234 => _234(), 'optionalAccess', _235 => _235.canWrite]), () => ( true));
|
|
9810
10510
|
const root = context.root;
|
|
9811
10511
|
disableHistory(() => {
|
|
9812
10512
|
for (const key in context.initialStorage) {
|
|
@@ -9938,7 +10638,7 @@ function createRoom(options, config) {
|
|
|
9938
10638
|
);
|
|
9939
10639
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
9940
10640
|
}
|
|
9941
|
-
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
10641
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT || op.type === OpCode.CREATE_TEXT) {
|
|
9942
10642
|
createdNodeIds.add(op.id);
|
|
9943
10643
|
}
|
|
9944
10644
|
}
|
|
@@ -9958,6 +10658,7 @@ function createRoom(options, config) {
|
|
|
9958
10658
|
switch (op.type) {
|
|
9959
10659
|
case OpCode.DELETE_OBJECT_KEY:
|
|
9960
10660
|
case OpCode.UPDATE_OBJECT:
|
|
10661
|
+
case OpCode.UPDATE_TEXT:
|
|
9961
10662
|
case OpCode.DELETE_CRDT: {
|
|
9962
10663
|
const node = context.pool.nodes.get(op.id);
|
|
9963
10664
|
if (node === void 0) {
|
|
@@ -9982,6 +10683,7 @@ function createRoom(options, config) {
|
|
|
9982
10683
|
case OpCode.CREATE_OBJECT:
|
|
9983
10684
|
case OpCode.CREATE_LIST:
|
|
9984
10685
|
case OpCode.CREATE_MAP:
|
|
10686
|
+
case OpCode.CREATE_TEXT:
|
|
9985
10687
|
case OpCode.CREATE_REGISTER: {
|
|
9986
10688
|
if (op.parentId === void 0) {
|
|
9987
10689
|
return { modified: false };
|
|
@@ -10012,7 +10714,7 @@ function createRoom(options, config) {
|
|
|
10012
10714
|
}
|
|
10013
10715
|
context.myPresence.patch(patch);
|
|
10014
10716
|
if (context.activeBatch) {
|
|
10015
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10717
|
+
if (_optionalChain([options2, 'optionalAccess', _236 => _236.addToHistory])) {
|
|
10016
10718
|
context.activeBatch.reverseOps.pushLeft({
|
|
10017
10719
|
type: "presence",
|
|
10018
10720
|
data: oldValues
|
|
@@ -10021,7 +10723,7 @@ function createRoom(options, config) {
|
|
|
10021
10723
|
context.activeBatch.updates.presence = true;
|
|
10022
10724
|
} else {
|
|
10023
10725
|
flushNowOrSoon();
|
|
10024
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10726
|
+
if (_optionalChain([options2, 'optionalAccess', _237 => _237.addToHistory])) {
|
|
10025
10727
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
10026
10728
|
}
|
|
10027
10729
|
notify({ presence: true });
|
|
@@ -10198,11 +10900,11 @@ function createRoom(options, config) {
|
|
|
10198
10900
|
break;
|
|
10199
10901
|
}
|
|
10200
10902
|
case ServerMsgCode.STORAGE_CHUNK:
|
|
10201
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
10903
|
+
_optionalChain([stopwatch, 'optionalAccess', _238 => _238.lap, 'call', _239 => _239()]);
|
|
10202
10904
|
nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
|
|
10203
10905
|
break;
|
|
10204
10906
|
case ServerMsgCode.STORAGE_STREAM_END: {
|
|
10205
|
-
const timing = _optionalChain([stopwatch, 'optionalAccess',
|
|
10907
|
+
const timing = _optionalChain([stopwatch, 'optionalAccess', _240 => _240.stop, 'call', _241 => _241()]);
|
|
10206
10908
|
if (timing) {
|
|
10207
10909
|
const ms = (v) => `${v.toFixed(1)}ms`;
|
|
10208
10910
|
const rest = timing.laps.slice(1);
|
|
@@ -10337,11 +11039,11 @@ function createRoom(options, config) {
|
|
|
10337
11039
|
} else if (pendingFeedsRequests.has(requestId)) {
|
|
10338
11040
|
const pending = pendingFeedsRequests.get(requestId);
|
|
10339
11041
|
pendingFeedsRequests.delete(requestId);
|
|
10340
|
-
_optionalChain([pending, 'optionalAccess',
|
|
11042
|
+
_optionalChain([pending, 'optionalAccess', _242 => _242.reject, 'call', _243 => _243(err)]);
|
|
10341
11043
|
} else if (pendingFeedMessagesRequests.has(requestId)) {
|
|
10342
11044
|
const pending = pendingFeedMessagesRequests.get(requestId);
|
|
10343
11045
|
pendingFeedMessagesRequests.delete(requestId);
|
|
10344
|
-
_optionalChain([pending, 'optionalAccess',
|
|
11046
|
+
_optionalChain([pending, 'optionalAccess', _244 => _244.reject, 'call', _245 => _245(err)]);
|
|
10345
11047
|
}
|
|
10346
11048
|
eventHub.feeds.notify(message);
|
|
10347
11049
|
break;
|
|
@@ -10495,10 +11197,10 @@ function createRoom(options, config) {
|
|
|
10495
11197
|
timeoutId,
|
|
10496
11198
|
kind,
|
|
10497
11199
|
feedId,
|
|
10498
|
-
messageId: _optionalChain([options2, 'optionalAccess',
|
|
10499
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
11200
|
+
messageId: _optionalChain([options2, 'optionalAccess', _246 => _246.messageId]),
|
|
11201
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _247 => _247.expectedClientMessageId])
|
|
10500
11202
|
});
|
|
10501
|
-
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess',
|
|
11203
|
+
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess', _248 => _248.expectedClientMessageId]) === void 0) {
|
|
10502
11204
|
const q = _nullishCoalesce(pendingAddMessageFifoByFeed.get(feedId), () => ( []));
|
|
10503
11205
|
q.push(requestId);
|
|
10504
11206
|
pendingAddMessageFifoByFeed.set(feedId, q);
|
|
@@ -10549,10 +11251,10 @@ function createRoom(options, config) {
|
|
|
10549
11251
|
}
|
|
10550
11252
|
if (!matched) {
|
|
10551
11253
|
const q = pendingAddMessageFifoByFeed.get(message.feedId);
|
|
10552
|
-
const headId = _optionalChain([q, 'optionalAccess',
|
|
11254
|
+
const headId = _optionalChain([q, 'optionalAccess', _249 => _249[0]]);
|
|
10553
11255
|
if (headId !== void 0) {
|
|
10554
11256
|
const pending = pendingFeedMutations.get(headId);
|
|
10555
|
-
if (_optionalChain([pending, 'optionalAccess',
|
|
11257
|
+
if (_optionalChain([pending, 'optionalAccess', _250 => _250.kind]) === "add-message" && pending.expectedClientMessageId === void 0) {
|
|
10556
11258
|
settleFeedMutation(headId, "ok");
|
|
10557
11259
|
}
|
|
10558
11260
|
}
|
|
@@ -10588,7 +11290,7 @@ function createRoom(options, config) {
|
|
|
10588
11290
|
const unacknowledgedOps2 = [...context.unacknowledgedOps.values()];
|
|
10589
11291
|
createOrUpdateRootFromMessage(nodes);
|
|
10590
11292
|
applyAndSendOfflineOps(unacknowledgedOps2);
|
|
10591
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
11293
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _251 => _251()]);
|
|
10592
11294
|
notifyStorageStatus();
|
|
10593
11295
|
eventHub.storageDidLoad.notify();
|
|
10594
11296
|
}
|
|
@@ -10606,7 +11308,7 @@ function createRoom(options, config) {
|
|
|
10606
11308
|
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
10607
11309
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
10608
11310
|
nodeMapBuffer.take();
|
|
10609
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
11311
|
+
_optionalChain([stopwatch, 'optionalAccess', _252 => _252.start, 'call', _253 => _253()]);
|
|
10610
11312
|
}
|
|
10611
11313
|
if (options2.flush) {
|
|
10612
11314
|
flushNowOrSoon();
|
|
@@ -10662,10 +11364,10 @@ function createRoom(options, config) {
|
|
|
10662
11364
|
const message = {
|
|
10663
11365
|
type: ClientMsgCode.FETCH_FEEDS,
|
|
10664
11366
|
requestId,
|
|
10665
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10666
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
10667
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
10668
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
11367
|
+
cursor: _optionalChain([options2, 'optionalAccess', _254 => _254.cursor]),
|
|
11368
|
+
since: _optionalChain([options2, 'optionalAccess', _255 => _255.since]),
|
|
11369
|
+
limit: _optionalChain([options2, 'optionalAccess', _256 => _256.limit]),
|
|
11370
|
+
metadata: _optionalChain([options2, 'optionalAccess', _257 => _257.metadata])
|
|
10669
11371
|
};
|
|
10670
11372
|
context.buffer.messages.push(message);
|
|
10671
11373
|
flushNowOrSoon();
|
|
@@ -10685,9 +11387,9 @@ function createRoom(options, config) {
|
|
|
10685
11387
|
type: ClientMsgCode.FETCH_FEED_MESSAGES,
|
|
10686
11388
|
requestId,
|
|
10687
11389
|
feedId,
|
|
10688
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10689
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
10690
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
11390
|
+
cursor: _optionalChain([options2, 'optionalAccess', _258 => _258.cursor]),
|
|
11391
|
+
since: _optionalChain([options2, 'optionalAccess', _259 => _259.since]),
|
|
11392
|
+
limit: _optionalChain([options2, 'optionalAccess', _260 => _260.limit])
|
|
10691
11393
|
};
|
|
10692
11394
|
context.buffer.messages.push(message);
|
|
10693
11395
|
flushNowOrSoon();
|
|
@@ -10706,8 +11408,8 @@ function createRoom(options, config) {
|
|
|
10706
11408
|
type: ClientMsgCode.ADD_FEED,
|
|
10707
11409
|
requestId,
|
|
10708
11410
|
feedId,
|
|
10709
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
10710
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
11411
|
+
metadata: _optionalChain([options2, 'optionalAccess', _261 => _261.metadata]),
|
|
11412
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _262 => _262.createdAt])
|
|
10711
11413
|
};
|
|
10712
11414
|
context.buffer.messages.push(message);
|
|
10713
11415
|
flushNowOrSoon();
|
|
@@ -10741,15 +11443,15 @@ function createRoom(options, config) {
|
|
|
10741
11443
|
function addFeedMessage(feedId, data, options2) {
|
|
10742
11444
|
const requestId = nanoid();
|
|
10743
11445
|
const promise = registerFeedMutation(requestId, "add-message", feedId, {
|
|
10744
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
11446
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _263 => _263.id])
|
|
10745
11447
|
});
|
|
10746
11448
|
const message = {
|
|
10747
11449
|
type: ClientMsgCode.ADD_FEED_MESSAGE,
|
|
10748
11450
|
requestId,
|
|
10749
11451
|
feedId,
|
|
10750
11452
|
data,
|
|
10751
|
-
id: _optionalChain([options2, 'optionalAccess',
|
|
10752
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
11453
|
+
id: _optionalChain([options2, 'optionalAccess', _264 => _264.id]),
|
|
11454
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _265 => _265.createdAt])
|
|
10753
11455
|
};
|
|
10754
11456
|
context.buffer.messages.push(message);
|
|
10755
11457
|
flushNowOrSoon();
|
|
@@ -10766,7 +11468,7 @@ function createRoom(options, config) {
|
|
|
10766
11468
|
feedId,
|
|
10767
11469
|
messageId,
|
|
10768
11470
|
data,
|
|
10769
|
-
updatedAt: _optionalChain([options2, 'optionalAccess',
|
|
11471
|
+
updatedAt: _optionalChain([options2, 'optionalAccess', _266 => _266.updatedAt])
|
|
10770
11472
|
};
|
|
10771
11473
|
context.buffer.messages.push(message);
|
|
10772
11474
|
flushNowOrSoon();
|
|
@@ -10973,8 +11675,8 @@ function createRoom(options, config) {
|
|
|
10973
11675
|
async function getThreads(options2) {
|
|
10974
11676
|
return httpClient.getThreads({
|
|
10975
11677
|
roomId,
|
|
10976
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
10977
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
11678
|
+
query: _optionalChain([options2, 'optionalAccess', _267 => _267.query]),
|
|
11679
|
+
cursor: _optionalChain([options2, 'optionalAccess', _268 => _268.cursor])
|
|
10978
11680
|
});
|
|
10979
11681
|
}
|
|
10980
11682
|
async function getThread(threadId) {
|
|
@@ -11096,7 +11798,7 @@ function createRoom(options, config) {
|
|
|
11096
11798
|
function getSubscriptionSettings(options2) {
|
|
11097
11799
|
return httpClient.getSubscriptionSettings({
|
|
11098
11800
|
roomId,
|
|
11099
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
11801
|
+
signal: _optionalChain([options2, 'optionalAccess', _269 => _269.signal])
|
|
11100
11802
|
});
|
|
11101
11803
|
}
|
|
11102
11804
|
function updateSubscriptionSettings(settings) {
|
|
@@ -11118,7 +11820,7 @@ function createRoom(options, config) {
|
|
|
11118
11820
|
{
|
|
11119
11821
|
[kInternal]: {
|
|
11120
11822
|
get presenceBuffer() {
|
|
11121
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
11823
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _270 => _270.buffer, 'access', _271 => _271.presenceUpdates, 'optionalAccess', _272 => _272.data]), () => ( null)));
|
|
11122
11824
|
},
|
|
11123
11825
|
// prettier-ignore
|
|
11124
11826
|
get undoStack() {
|
|
@@ -11133,9 +11835,9 @@ function createRoom(options, config) {
|
|
|
11133
11835
|
return context.yjsProvider;
|
|
11134
11836
|
},
|
|
11135
11837
|
setYjsProvider(newProvider) {
|
|
11136
|
-
_optionalChain([context, 'access',
|
|
11838
|
+
_optionalChain([context, 'access', _273 => _273.yjsProvider, 'optionalAccess', _274 => _274.off, 'call', _275 => _275("status", yjsStatusDidChange)]);
|
|
11137
11839
|
context.yjsProvider = newProvider;
|
|
11138
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
11840
|
+
_optionalChain([newProvider, 'optionalAccess', _276 => _276.on, 'call', _277 => _277("status", yjsStatusDidChange)]);
|
|
11139
11841
|
context.yjsProviderDidChange.notify();
|
|
11140
11842
|
},
|
|
11141
11843
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -11193,7 +11895,7 @@ ${dumpPool(context.pool)}`;
|
|
|
11193
11895
|
source.dispose();
|
|
11194
11896
|
}
|
|
11195
11897
|
eventHub.roomWillDestroy.notify();
|
|
11196
|
-
_optionalChain([context, 'access',
|
|
11898
|
+
_optionalChain([context, 'access', _278 => _278.yjsProvider, 'optionalAccess', _279 => _279.off, 'call', _280 => _280("status", yjsStatusDidChange)]);
|
|
11197
11899
|
syncSourceForStorage.destroy();
|
|
11198
11900
|
syncSourceForYjs.destroy();
|
|
11199
11901
|
uninstallBgTabSpy();
|
|
@@ -11353,7 +12055,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
11353
12055
|
}
|
|
11354
12056
|
if (isLiveNode(first)) {
|
|
11355
12057
|
const node = first;
|
|
11356
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
12058
|
+
if (_optionalChain([options, 'optionalAccess', _281 => _281.isDeep])) {
|
|
11357
12059
|
const storageCallback = second;
|
|
11358
12060
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
11359
12061
|
} else {
|
|
@@ -11439,8 +12141,8 @@ function createClient(options) {
|
|
|
11439
12141
|
const authManager = createAuthManager(options, (token) => {
|
|
11440
12142
|
currentUserId.set(() => token.uid);
|
|
11441
12143
|
});
|
|
11442
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
11443
|
-
_optionalChain([globalThis, 'access',
|
|
12144
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _282 => _282.polyfills, 'optionalAccess', _283 => _283.fetch]) || /* istanbul ignore next */
|
|
12145
|
+
_optionalChain([globalThis, 'access', _284 => _284.fetch, 'optionalAccess', _285 => _285.bind, 'call', _286 => _286(globalThis)]);
|
|
11444
12146
|
const httpClient = createApiClient({
|
|
11445
12147
|
baseUrl,
|
|
11446
12148
|
fetchPolyfill,
|
|
@@ -11458,7 +12160,7 @@ function createClient(options) {
|
|
|
11458
12160
|
delegates: {
|
|
11459
12161
|
createSocket: makeCreateSocketDelegateForAi(
|
|
11460
12162
|
baseUrl,
|
|
11461
|
-
_optionalChain([clientOptions, 'access',
|
|
12163
|
+
_optionalChain([clientOptions, 'access', _287 => _287.polyfills, 'optionalAccess', _288 => _288.WebSocket])
|
|
11462
12164
|
),
|
|
11463
12165
|
authenticate: async () => {
|
|
11464
12166
|
const resp = await authManager.getAuthValue({
|
|
@@ -11528,7 +12230,7 @@ function createClient(options) {
|
|
|
11528
12230
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
11529
12231
|
roomId,
|
|
11530
12232
|
baseUrl,
|
|
11531
|
-
_optionalChain([clientOptions, 'access',
|
|
12233
|
+
_optionalChain([clientOptions, 'access', _289 => _289.polyfills, 'optionalAccess', _290 => _290.WebSocket])
|
|
11532
12234
|
),
|
|
11533
12235
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
11534
12236
|
})),
|
|
@@ -11551,7 +12253,7 @@ function createClient(options) {
|
|
|
11551
12253
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
11552
12254
|
if (shouldConnect) {
|
|
11553
12255
|
if (typeof atob === "undefined") {
|
|
11554
|
-
if (_optionalChain([clientOptions, 'access',
|
|
12256
|
+
if (_optionalChain([clientOptions, 'access', _291 => _291.polyfills, 'optionalAccess', _292 => _292.atob]) === void 0) {
|
|
11555
12257
|
throw new Error(
|
|
11556
12258
|
"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"
|
|
11557
12259
|
);
|
|
@@ -11563,7 +12265,7 @@ function createClient(options) {
|
|
|
11563
12265
|
return leaseRoom(newRoomDetails);
|
|
11564
12266
|
}
|
|
11565
12267
|
function getRoom(roomId) {
|
|
11566
|
-
const room = _optionalChain([roomsById, 'access',
|
|
12268
|
+
const room = _optionalChain([roomsById, 'access', _293 => _293.get, 'call', _294 => _294(roomId), 'optionalAccess', _295 => _295.room]);
|
|
11567
12269
|
return room ? room : null;
|
|
11568
12270
|
}
|
|
11569
12271
|
function logout() {
|
|
@@ -11579,7 +12281,7 @@ function createClient(options) {
|
|
|
11579
12281
|
const batchedResolveUsers = new Batch(
|
|
11580
12282
|
async (batchedUserIds) => {
|
|
11581
12283
|
const userIds = batchedUserIds.flat();
|
|
11582
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
12284
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _296 => _296({ userIds })]);
|
|
11583
12285
|
warnOnceIf(
|
|
11584
12286
|
!resolveUsers,
|
|
11585
12287
|
"Set the resolveUsers option in createClient to specify user info."
|
|
@@ -11596,7 +12298,7 @@ function createClient(options) {
|
|
|
11596
12298
|
const batchedResolveRoomsInfo = new Batch(
|
|
11597
12299
|
async (batchedRoomIds) => {
|
|
11598
12300
|
const roomIds = batchedRoomIds.flat();
|
|
11599
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
12301
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _297 => _297({ roomIds })]);
|
|
11600
12302
|
warnOnceIf(
|
|
11601
12303
|
!resolveRoomsInfo,
|
|
11602
12304
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
@@ -11613,7 +12315,7 @@ function createClient(options) {
|
|
|
11613
12315
|
const batchedResolveGroupsInfo = new Batch(
|
|
11614
12316
|
async (batchedGroupIds) => {
|
|
11615
12317
|
const groupIds = batchedGroupIds.flat();
|
|
11616
|
-
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall',
|
|
12318
|
+
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _298 => _298({ groupIds })]);
|
|
11617
12319
|
warnOnceIf(
|
|
11618
12320
|
!resolveGroupsInfo,
|
|
11619
12321
|
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
@@ -11672,7 +12374,7 @@ function createClient(options) {
|
|
|
11672
12374
|
}
|
|
11673
12375
|
};
|
|
11674
12376
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
11675
|
-
_optionalChain([win, 'optionalAccess',
|
|
12377
|
+
_optionalChain([win, 'optionalAccess', _299 => _299.addEventListener, 'call', _300 => _300("beforeunload", maybePreventClose)]);
|
|
11676
12378
|
}
|
|
11677
12379
|
async function getNotificationSettings(options2) {
|
|
11678
12380
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -11800,7 +12502,7 @@ var commentBodyElementsTypes = {
|
|
|
11800
12502
|
mention: "inline"
|
|
11801
12503
|
};
|
|
11802
12504
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
11803
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
12505
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _301 => _301.content])) {
|
|
11804
12506
|
return;
|
|
11805
12507
|
}
|
|
11806
12508
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -11810,13 +12512,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
11810
12512
|
for (const block of body.content) {
|
|
11811
12513
|
if (type === "all" || type === "block") {
|
|
11812
12514
|
if (guard(block)) {
|
|
11813
|
-
_optionalChain([visitor, 'optionalCall',
|
|
12515
|
+
_optionalChain([visitor, 'optionalCall', _302 => _302(block)]);
|
|
11814
12516
|
}
|
|
11815
12517
|
}
|
|
11816
12518
|
if (type === "all" || type === "inline") {
|
|
11817
12519
|
for (const inline of block.children) {
|
|
11818
12520
|
if (guard(inline)) {
|
|
11819
|
-
_optionalChain([visitor, 'optionalCall',
|
|
12521
|
+
_optionalChain([visitor, 'optionalCall', _303 => _303(inline)]);
|
|
11820
12522
|
}
|
|
11821
12523
|
}
|
|
11822
12524
|
}
|
|
@@ -11986,7 +12688,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
11986
12688
|
text: ({ element }) => element.text,
|
|
11987
12689
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
11988
12690
|
mention: ({ element, user, group }) => {
|
|
11989
|
-
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
12691
|
+
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _304 => _304.name]), () => ( _optionalChain([group, 'optionalAccess', _305 => _305.name]))), () => ( element.id))}`;
|
|
11990
12692
|
}
|
|
11991
12693
|
};
|
|
11992
12694
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -12016,7 +12718,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
12016
12718
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
12017
12719
|
},
|
|
12018
12720
|
mention: ({ element, user, group }) => {
|
|
12019
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
12721
|
+
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _306 => _306.name]) ? html`${_optionalChain([user, 'optionalAccess', _307 => _307.name])}` : _optionalChain([group, 'optionalAccess', _308 => _308.name]) ? html`${_optionalChain([group, 'optionalAccess', _309 => _309.name])}` : element.id}</span>`;
|
|
12020
12722
|
}
|
|
12021
12723
|
};
|
|
12022
12724
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -12046,20 +12748,20 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
12046
12748
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
12047
12749
|
},
|
|
12048
12750
|
mention: ({ element, user, group }) => {
|
|
12049
|
-
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
12751
|
+
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _310 => _310.name]), () => ( _optionalChain([group, 'optionalAccess', _311 => _311.name]))), () => ( element.id))}`;
|
|
12050
12752
|
}
|
|
12051
12753
|
};
|
|
12052
12754
|
async function stringifyCommentBody(body, options) {
|
|
12053
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12054
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12755
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _312 => _312.format]), () => ( "plain"));
|
|
12756
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _313 => _313.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
12055
12757
|
const elements = {
|
|
12056
12758
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
12057
|
-
..._optionalChain([options, 'optionalAccess',
|
|
12759
|
+
..._optionalChain([options, 'optionalAccess', _314 => _314.elements])
|
|
12058
12760
|
};
|
|
12059
12761
|
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
12060
12762
|
body,
|
|
12061
|
-
_optionalChain([options, 'optionalAccess',
|
|
12062
|
-
_optionalChain([options, 'optionalAccess',
|
|
12763
|
+
_optionalChain([options, 'optionalAccess', _315 => _315.resolveUsers]),
|
|
12764
|
+
_optionalChain([options, 'optionalAccess', _316 => _316.resolveGroupsInfo])
|
|
12063
12765
|
);
|
|
12064
12766
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
12065
12767
|
switch (block.type) {
|
|
@@ -12141,6 +12843,12 @@ function toPlainLson(lson) {
|
|
|
12141
12843
|
liveblocksType: "LiveList",
|
|
12142
12844
|
data: [...lson].map((item) => toPlainLson(item))
|
|
12143
12845
|
};
|
|
12846
|
+
} else if (lson instanceof LiveText) {
|
|
12847
|
+
return {
|
|
12848
|
+
liveblocksType: "LiveText",
|
|
12849
|
+
data: lson.toDelta(),
|
|
12850
|
+
version: lson.version
|
|
12851
|
+
};
|
|
12144
12852
|
} else {
|
|
12145
12853
|
return lson;
|
|
12146
12854
|
}
|
|
@@ -12194,9 +12902,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
12194
12902
|
const startTime = performance.now();
|
|
12195
12903
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
12196
12904
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
12197
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12905
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _317 => _317.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
12198
12906
|
const context = {
|
|
12199
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
12907
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _318 => _318.visibilityState]) !== "hidden",
|
|
12200
12908
|
lastSuccessfulPollAt: startTime,
|
|
12201
12909
|
count: 0,
|
|
12202
12910
|
backoff: 0
|
|
@@ -12277,11 +12985,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
12277
12985
|
pollNowIfStale();
|
|
12278
12986
|
}
|
|
12279
12987
|
function onVisibilityChange() {
|
|
12280
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
12988
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _319 => _319.visibilityState]) !== "hidden");
|
|
12281
12989
|
}
|
|
12282
|
-
_optionalChain([doc, 'optionalAccess',
|
|
12283
|
-
_optionalChain([win, 'optionalAccess',
|
|
12284
|
-
_optionalChain([win, 'optionalAccess',
|
|
12990
|
+
_optionalChain([doc, 'optionalAccess', _320 => _320.addEventListener, 'call', _321 => _321("visibilitychange", onVisibilityChange)]);
|
|
12991
|
+
_optionalChain([win, 'optionalAccess', _322 => _322.addEventListener, 'call', _323 => _323("online", onVisibilityChange)]);
|
|
12992
|
+
_optionalChain([win, 'optionalAccess', _324 => _324.addEventListener, 'call', _325 => _325("focus", pollNowIfStale)]);
|
|
12285
12993
|
fsm.start();
|
|
12286
12994
|
return {
|
|
12287
12995
|
inc,
|
|
@@ -12418,5 +13126,8 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
12418
13126
|
|
|
12419
13127
|
|
|
12420
13128
|
|
|
12421
|
-
|
|
13129
|
+
|
|
13130
|
+
|
|
13131
|
+
|
|
13132
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.FeedRequestErrorCode = FeedRequestErrorCode; exports.HttpError = HttpError; 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.createThreadId = createThreadId; 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.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; 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.nanoid = nanoid; exports.nn = nn; exports.nodeStreamToCompactNodes = nodeStreamToCompactNodes; exports.objectToQuery = objectToQuery; exports.patchNotificationSettings = patchNotificationSettings; 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.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
|
|
12422
13133
|
//# sourceMappingURL=index.cjs.map
|