@liveblocks/core 3.19.5-rc1 → 3.20.0-exp2
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 +794 -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 +724 -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-exp2";
|
|
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,583 @@ 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(
|
|
8708
|
+
applyTextOperationsToSegments(deltaToSegments(delta), ops)
|
|
8709
|
+
);
|
|
8710
|
+
}
|
|
8711
|
+
function invertTextOperations(segments, ops) {
|
|
8712
|
+
let shadow = [...segments];
|
|
8713
|
+
const reverse = [];
|
|
8714
|
+
for (const op of ops) {
|
|
8715
|
+
if (op.type === "insert") {
|
|
8716
|
+
shadow = applyInsert(shadow, op.index, op.text, op.attributes);
|
|
8717
|
+
reverse.unshift({
|
|
8718
|
+
type: "delete",
|
|
8719
|
+
index: op.index,
|
|
8720
|
+
length: op.text.length
|
|
8721
|
+
});
|
|
8722
|
+
} else if (op.type === "delete") {
|
|
8723
|
+
const deletedSegments = extractDeletedSegments(
|
|
8724
|
+
shadow,
|
|
8725
|
+
op.index,
|
|
8726
|
+
op.length
|
|
8727
|
+
);
|
|
8728
|
+
shadow = applyDelete(shadow, op.index, op.length).segments;
|
|
8729
|
+
const inserts = [];
|
|
8730
|
+
let insertIndex = op.index;
|
|
8731
|
+
for (const segment of deletedSegments) {
|
|
8732
|
+
inserts.push({
|
|
8733
|
+
type: "insert",
|
|
8734
|
+
index: insertIndex,
|
|
8735
|
+
text: segment.text,
|
|
8736
|
+
attributes: segment.attributes
|
|
8737
|
+
});
|
|
8738
|
+
insertIndex += segment.text.length;
|
|
8739
|
+
}
|
|
8740
|
+
for (let index = inserts.length - 1; index >= 0; index--) {
|
|
8741
|
+
reverse.unshift(inserts[index]);
|
|
8742
|
+
}
|
|
8743
|
+
} else {
|
|
8744
|
+
const inverse = formatReverseOperations(
|
|
8745
|
+
shadow,
|
|
8746
|
+
op.index,
|
|
8747
|
+
op.length,
|
|
8748
|
+
op.attributes
|
|
8749
|
+
);
|
|
8750
|
+
shadow = applyFormat(shadow, op.index, op.length, op.attributes);
|
|
8751
|
+
reverse.unshift(...inverse.reverse());
|
|
8752
|
+
}
|
|
8753
|
+
}
|
|
8754
|
+
return reverse;
|
|
8755
|
+
}
|
|
8756
|
+
|
|
8757
|
+
// src/crdts/LiveText.ts
|
|
8758
|
+
var LiveText = class _LiveText extends AbstractCrdt {
|
|
8759
|
+
#segments;
|
|
8760
|
+
#version;
|
|
8761
|
+
#pendingOps;
|
|
8762
|
+
constructor(textOrDelta = "", version = 0) {
|
|
8763
|
+
super();
|
|
8764
|
+
this.#segments = typeof textOrDelta === "string" ? textOrDelta.length === 0 ? [] : [{ text: textOrDelta }] : deltaToSegments(textOrDelta);
|
|
8765
|
+
this.#version = version;
|
|
8766
|
+
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8767
|
+
}
|
|
8768
|
+
get version() {
|
|
8769
|
+
return this.#version;
|
|
8770
|
+
}
|
|
8771
|
+
get length() {
|
|
8772
|
+
return this.toString().length;
|
|
8773
|
+
}
|
|
8774
|
+
/** @internal */
|
|
8775
|
+
static _deserialize([id, item], _parentToChildren, pool) {
|
|
8776
|
+
const text = new _LiveText(item.data, item.version);
|
|
8777
|
+
text._attach(id, pool);
|
|
8778
|
+
return text;
|
|
8779
|
+
}
|
|
8780
|
+
/** @internal */
|
|
8781
|
+
_toOps(parentId, parentKey) {
|
|
8782
|
+
if (this._id === void 0) {
|
|
8783
|
+
throw new Error("Cannot serialize LiveText if it is not attached");
|
|
8784
|
+
}
|
|
8785
|
+
return [
|
|
8786
|
+
{
|
|
8787
|
+
type: OpCode.CREATE_TEXT,
|
|
8788
|
+
id: this._id,
|
|
8789
|
+
parentId,
|
|
8790
|
+
parentKey,
|
|
8791
|
+
data: this.toDelta(),
|
|
8792
|
+
version: this.#version
|
|
8793
|
+
}
|
|
8794
|
+
];
|
|
8795
|
+
}
|
|
8796
|
+
/** @internal */
|
|
8797
|
+
_serialize() {
|
|
8798
|
+
if (this.parent.type !== "HasParent") {
|
|
8799
|
+
throw new Error("Cannot serialize LiveText if parent is missing");
|
|
8800
|
+
}
|
|
8801
|
+
return {
|
|
8802
|
+
type: CrdtType.TEXT,
|
|
8803
|
+
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8804
|
+
parentKey: this.parent.key,
|
|
8805
|
+
data: this.toDelta(),
|
|
8806
|
+
version: this.#version
|
|
8807
|
+
};
|
|
8808
|
+
}
|
|
8809
|
+
/** @internal */
|
|
8810
|
+
_attachChild(_op) {
|
|
8811
|
+
throw new Error("LiveText cannot contain child nodes");
|
|
8812
|
+
}
|
|
8813
|
+
/** @internal */
|
|
8814
|
+
_detachChild(_crdt) {
|
|
8815
|
+
throw new Error("LiveText cannot contain child nodes");
|
|
8816
|
+
}
|
|
8817
|
+
/** @internal */
|
|
8818
|
+
_apply(op, isLocal) {
|
|
8819
|
+
if (op.type !== OpCode.UPDATE_TEXT) {
|
|
8820
|
+
return super._apply(op, isLocal);
|
|
8821
|
+
}
|
|
8822
|
+
if (isLocal) {
|
|
8823
|
+
this.#pendingOps.set(nn(op.opId), op.ops);
|
|
8824
|
+
return this.#applyOperations(op.ops, _nullishCoalesce(op.version, () => ( this.#version)));
|
|
8825
|
+
}
|
|
8826
|
+
if (op.opId !== void 0) {
|
|
8827
|
+
const pending2 = this.#pendingOps.get(op.opId);
|
|
8828
|
+
this.#pendingOps.delete(op.opId);
|
|
8829
|
+
const otherPending = Array.from(this.#pendingOps.values()).flat();
|
|
8830
|
+
if (pending2 !== void 0 && otherPending.length > 0) {
|
|
8831
|
+
this.#segments = applyTextOperationsToSegments(
|
|
8832
|
+
this.#segments,
|
|
8833
|
+
invertTextOperations(this.#segments, pending2)
|
|
8834
|
+
);
|
|
8835
|
+
const ops2 = rebaseTextOperations(op.ops, otherPending);
|
|
8836
|
+
return this.#applyOperations(
|
|
8837
|
+
ops2,
|
|
8838
|
+
_nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)))
|
|
8839
|
+
);
|
|
8840
|
+
}
|
|
8841
|
+
this.#version = _nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)));
|
|
8842
|
+
return { modified: false };
|
|
8843
|
+
}
|
|
8844
|
+
const pending = Array.from(this.#pendingOps.values()).flat();
|
|
8845
|
+
const ops = pending.length > 0 ? rebaseTextOperations(op.ops, pending) : op.ops;
|
|
8846
|
+
return this.#applyOperations(ops, _nullishCoalesce(op.version, () => ( this.#version + 1)));
|
|
8847
|
+
}
|
|
8848
|
+
insert(index, text, attributes) {
|
|
8849
|
+
const clippedIndex = Math.max(0, Math.min(index, this.length));
|
|
8850
|
+
this.#dispatch([{ type: "insert", index: clippedIndex, text, attributes }]);
|
|
8851
|
+
}
|
|
8852
|
+
delete(index, length) {
|
|
8853
|
+
const clipped = clipRange(index, length, this.length);
|
|
8854
|
+
if (clipped.length === 0) {
|
|
8855
|
+
return;
|
|
8856
|
+
}
|
|
8857
|
+
this.#dispatch([
|
|
8858
|
+
{ type: "delete", index: clipped.index, length: clipped.length }
|
|
8859
|
+
]);
|
|
8860
|
+
}
|
|
8861
|
+
replace(index, length, text, attributes) {
|
|
8862
|
+
const clipped = clipRange(index, length, this.length);
|
|
8863
|
+
const ops = [];
|
|
8864
|
+
if (clipped.length > 0) {
|
|
8865
|
+
ops.push({
|
|
8866
|
+
type: "delete",
|
|
8867
|
+
index: clipped.index,
|
|
8868
|
+
length: clipped.length
|
|
8869
|
+
});
|
|
8870
|
+
}
|
|
8871
|
+
if (text.length > 0) {
|
|
8872
|
+
ops.push({ type: "insert", index: clipped.index, text, attributes });
|
|
8873
|
+
}
|
|
8874
|
+
this.#dispatch(ops);
|
|
8875
|
+
}
|
|
8876
|
+
format(index, length, attributes) {
|
|
8877
|
+
const clipped = clipRange(index, length, this.length);
|
|
8878
|
+
if (clipped.length === 0) {
|
|
8879
|
+
return;
|
|
8880
|
+
}
|
|
8881
|
+
this.#dispatch([
|
|
8882
|
+
{
|
|
8883
|
+
type: "format",
|
|
8884
|
+
index: clipped.index,
|
|
8885
|
+
length: clipped.length,
|
|
8886
|
+
attributes
|
|
8887
|
+
}
|
|
8888
|
+
]);
|
|
8889
|
+
}
|
|
8890
|
+
#dispatch(ops) {
|
|
8891
|
+
if (ops.length === 0) {
|
|
8892
|
+
return;
|
|
8893
|
+
}
|
|
8894
|
+
_optionalChain([this, 'access', _215 => _215._pool, 'optionalAccess', _216 => _216.assertStorageIsWritable, 'call', _217 => _217()]);
|
|
8895
|
+
const baseVersion = this.#version;
|
|
8896
|
+
const reverse = this._pool !== void 0 && this._id !== void 0 ? this.#invertOperations(ops) : [];
|
|
8897
|
+
const changes = this.#applyOperationsLocally(ops);
|
|
8898
|
+
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8899
|
+
const opId = this._pool.generateOpId();
|
|
8900
|
+
this.#pendingOps.set(opId, ops);
|
|
8901
|
+
this._pool.dispatch(
|
|
8902
|
+
[
|
|
8903
|
+
{
|
|
8904
|
+
type: OpCode.UPDATE_TEXT,
|
|
8905
|
+
id: this._id,
|
|
8906
|
+
opId,
|
|
8907
|
+
baseVersion,
|
|
8908
|
+
ops: [...ops]
|
|
8909
|
+
}
|
|
8910
|
+
],
|
|
8911
|
+
reverse,
|
|
8912
|
+
/* @__PURE__ */ new Map([
|
|
8913
|
+
[
|
|
8914
|
+
this._id,
|
|
8915
|
+
{
|
|
8916
|
+
type: "LiveText",
|
|
8917
|
+
node: this,
|
|
8918
|
+
version: this.#version,
|
|
8919
|
+
updates: changes
|
|
8920
|
+
}
|
|
8921
|
+
]
|
|
8922
|
+
])
|
|
8923
|
+
);
|
|
8924
|
+
}
|
|
8925
|
+
}
|
|
8926
|
+
#applyOperations(ops, version) {
|
|
8927
|
+
const reverse = this.#invertOperations(ops);
|
|
8928
|
+
const changes = this.#applyOperationsLocally(ops);
|
|
8929
|
+
this.#version = Math.max(this.#version, version);
|
|
8930
|
+
return {
|
|
8931
|
+
reverse,
|
|
8932
|
+
modified: {
|
|
8933
|
+
type: "LiveText",
|
|
8934
|
+
node: this,
|
|
8935
|
+
version: this.#version,
|
|
8936
|
+
updates: changes
|
|
8937
|
+
}
|
|
8938
|
+
};
|
|
8939
|
+
}
|
|
8940
|
+
#applyOperationsLocally(ops) {
|
|
8941
|
+
const changes = [];
|
|
8942
|
+
for (const op of ops) {
|
|
8943
|
+
if (op.type === "insert") {
|
|
8944
|
+
this.#segments = applyInsert(
|
|
8945
|
+
this.#segments,
|
|
8946
|
+
op.index,
|
|
8947
|
+
op.text,
|
|
8948
|
+
op.attributes
|
|
8949
|
+
);
|
|
8950
|
+
changes.push({
|
|
8951
|
+
type: "insert",
|
|
8952
|
+
index: op.index,
|
|
8953
|
+
text: op.text,
|
|
8954
|
+
attributes: op.attributes
|
|
8955
|
+
});
|
|
8956
|
+
} else if (op.type === "delete") {
|
|
8957
|
+
const result = applyDelete(this.#segments, op.index, op.length);
|
|
8958
|
+
this.#segments = result.segments;
|
|
8959
|
+
changes.push({
|
|
8960
|
+
type: "delete",
|
|
8961
|
+
index: op.index,
|
|
8962
|
+
length: op.length,
|
|
8963
|
+
deletedText: result.deletedText
|
|
8964
|
+
});
|
|
8965
|
+
} else {
|
|
8966
|
+
this.#segments = applyFormat(
|
|
8967
|
+
this.#segments,
|
|
8968
|
+
op.index,
|
|
8969
|
+
op.length,
|
|
8970
|
+
op.attributes
|
|
8971
|
+
);
|
|
8972
|
+
changes.push({
|
|
8973
|
+
type: "format",
|
|
8974
|
+
index: op.index,
|
|
8975
|
+
length: op.length,
|
|
8976
|
+
attributes: op.attributes
|
|
8977
|
+
});
|
|
8978
|
+
}
|
|
8979
|
+
}
|
|
8980
|
+
this.invalidate();
|
|
8981
|
+
return changes;
|
|
8982
|
+
}
|
|
8983
|
+
#invertOperations(ops) {
|
|
8984
|
+
return [
|
|
8985
|
+
{
|
|
8986
|
+
type: OpCode.UPDATE_TEXT,
|
|
8987
|
+
id: nn(this._id),
|
|
8988
|
+
baseVersion: this.#version,
|
|
8989
|
+
ops: invertTextOperations(this.#segments, ops)
|
|
8990
|
+
}
|
|
8991
|
+
];
|
|
8992
|
+
}
|
|
8993
|
+
toString() {
|
|
8994
|
+
return this.#segments.map((segment) => segment.text).join("");
|
|
8995
|
+
}
|
|
8996
|
+
toDelta() {
|
|
8997
|
+
return segmentsToDelta(this.#segments);
|
|
8998
|
+
}
|
|
8999
|
+
toJSON() {
|
|
9000
|
+
return super.toJSON();
|
|
9001
|
+
}
|
|
9002
|
+
/** @internal */
|
|
9003
|
+
_toJSON() {
|
|
9004
|
+
return this.toDelta();
|
|
9005
|
+
}
|
|
9006
|
+
/** @internal */
|
|
9007
|
+
_toTreeNode(key) {
|
|
9008
|
+
return {
|
|
9009
|
+
type: "LiveText",
|
|
9010
|
+
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
9011
|
+
key,
|
|
9012
|
+
payload: [
|
|
9013
|
+
{
|
|
9014
|
+
type: "Json",
|
|
9015
|
+
id: `${_nullishCoalesce(this._id, () => ( nanoid()))}:text`,
|
|
9016
|
+
key: "text",
|
|
9017
|
+
payload: this.toString()
|
|
9018
|
+
}
|
|
9019
|
+
]
|
|
9020
|
+
};
|
|
9021
|
+
}
|
|
9022
|
+
clone() {
|
|
9023
|
+
return new _LiveText(this.toDelta(), this.#version);
|
|
9024
|
+
}
|
|
9025
|
+
};
|
|
9026
|
+
|
|
8429
9027
|
// src/crdts/liveblocks-helpers.ts
|
|
8430
9028
|
function creationOpToLiveNode(op) {
|
|
8431
9029
|
return lsonToLiveNode(creationOpToLson(op));
|
|
@@ -8440,6 +9038,8 @@ function creationOpToLson(op) {
|
|
|
8440
9038
|
return new LiveMap();
|
|
8441
9039
|
case OpCode.CREATE_LIST:
|
|
8442
9040
|
return new LiveList([]);
|
|
9041
|
+
case OpCode.CREATE_TEXT:
|
|
9042
|
+
return new LiveText(op.data, op.version);
|
|
8443
9043
|
default:
|
|
8444
9044
|
return assertNever(op, "Unknown creation Op");
|
|
8445
9045
|
}
|
|
@@ -8462,6 +9062,8 @@ function deserialize(node, parentToChildren, pool) {
|
|
|
8462
9062
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
8463
9063
|
} else if (isRegisterStorageNode(node)) {
|
|
8464
9064
|
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
9065
|
+
} else if (isTextStorageNode(node)) {
|
|
9066
|
+
return LiveText._deserialize(node, parentToChildren, pool);
|
|
8465
9067
|
} else {
|
|
8466
9068
|
throw new Error("Unexpected CRDT type");
|
|
8467
9069
|
}
|
|
@@ -8475,12 +9077,14 @@ function deserializeToLson(node, parentToChildren, pool) {
|
|
|
8475
9077
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
8476
9078
|
} else if (isRegisterStorageNode(node)) {
|
|
8477
9079
|
return node[1].data;
|
|
9080
|
+
} else if (isTextStorageNode(node)) {
|
|
9081
|
+
return LiveText._deserialize(node, parentToChildren, pool);
|
|
8478
9082
|
} else {
|
|
8479
9083
|
throw new Error("Unexpected CRDT type");
|
|
8480
9084
|
}
|
|
8481
9085
|
}
|
|
8482
9086
|
function isLiveStructure(value) {
|
|
8483
|
-
return isLiveList(value) || isLiveMap(value) || isLiveObject(value);
|
|
9087
|
+
return isLiveList(value) || isLiveMap(value) || isLiveObject(value) || isLiveText(value);
|
|
8484
9088
|
}
|
|
8485
9089
|
function isLiveNode(value) {
|
|
8486
9090
|
return isLiveStructure(value) || isLiveRegister(value);
|
|
@@ -8494,6 +9098,9 @@ function isLiveMap(value) {
|
|
|
8494
9098
|
function isLiveObject(value) {
|
|
8495
9099
|
return value instanceof LiveObject;
|
|
8496
9100
|
}
|
|
9101
|
+
function isLiveText(value) {
|
|
9102
|
+
return value instanceof LiveText;
|
|
9103
|
+
}
|
|
8497
9104
|
function isLiveRegister(value) {
|
|
8498
9105
|
return value instanceof LiveRegister;
|
|
8499
9106
|
}
|
|
@@ -8503,14 +9110,14 @@ function cloneLson(value) {
|
|
|
8503
9110
|
function liveNodeToLson(obj) {
|
|
8504
9111
|
if (obj instanceof LiveRegister) {
|
|
8505
9112
|
return obj.data;
|
|
8506
|
-
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject) {
|
|
9113
|
+
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject || obj instanceof LiveText) {
|
|
8507
9114
|
return obj;
|
|
8508
9115
|
} else {
|
|
8509
9116
|
return assertNever(obj, "Unknown AbstractCrdt");
|
|
8510
9117
|
}
|
|
8511
9118
|
}
|
|
8512
9119
|
function lsonToLiveNode(value) {
|
|
8513
|
-
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList) {
|
|
9120
|
+
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList || value instanceof LiveText) {
|
|
8514
9121
|
return value;
|
|
8515
9122
|
} else {
|
|
8516
9123
|
return new LiveRegister(value);
|
|
@@ -8541,6 +9148,35 @@ function dumpPool(pool) {
|
|
|
8541
9148
|
(r) => ` ${r.id} parent=${r.parentId} key=${r.key || "\u2014"} ${r.value}`
|
|
8542
9149
|
).join("\n");
|
|
8543
9150
|
}
|
|
9151
|
+
function isJsonEq(a, b) {
|
|
9152
|
+
if (a === b) {
|
|
9153
|
+
return true;
|
|
9154
|
+
}
|
|
9155
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
9156
|
+
return false;
|
|
9157
|
+
}
|
|
9158
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
9159
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
9160
|
+
return false;
|
|
9161
|
+
}
|
|
9162
|
+
for (let i = 0; i < a.length; i++) {
|
|
9163
|
+
if (!isJsonEq(a[i], b[i])) {
|
|
9164
|
+
return false;
|
|
9165
|
+
}
|
|
9166
|
+
}
|
|
9167
|
+
return true;
|
|
9168
|
+
}
|
|
9169
|
+
const aKeys = Object.keys(a);
|
|
9170
|
+
if (aKeys.length !== Object.keys(b).length) {
|
|
9171
|
+
return false;
|
|
9172
|
+
}
|
|
9173
|
+
for (const key of aKeys) {
|
|
9174
|
+
if (!isJsonEq(a[key], b[key])) {
|
|
9175
|
+
return false;
|
|
9176
|
+
}
|
|
9177
|
+
}
|
|
9178
|
+
return true;
|
|
9179
|
+
}
|
|
8544
9180
|
function getTreesDiffOperations(currentItems, newItems) {
|
|
8545
9181
|
const ops = [];
|
|
8546
9182
|
currentItems.forEach((_, id) => {
|
|
@@ -8552,11 +9188,59 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8552
9188
|
const currentCrdt = currentItems.get(id);
|
|
8553
9189
|
if (currentCrdt) {
|
|
8554
9190
|
if (crdt.type === CrdtType.OBJECT) {
|
|
8555
|
-
if (currentCrdt.type !== CrdtType.OBJECT
|
|
9191
|
+
if (currentCrdt.type !== CrdtType.OBJECT) {
|
|
9192
|
+
ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
|
|
9193
|
+
} else {
|
|
9194
|
+
const changed = /* @__PURE__ */ new Map();
|
|
9195
|
+
for (const key of Object.keys(crdt.data)) {
|
|
9196
|
+
const value = crdt.data[key];
|
|
9197
|
+
if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
|
|
9198
|
+
changed.set(key, value);
|
|
9199
|
+
}
|
|
9200
|
+
}
|
|
9201
|
+
if (changed.size > 0) {
|
|
9202
|
+
ops.push({
|
|
9203
|
+
type: OpCode.UPDATE_OBJECT,
|
|
9204
|
+
id,
|
|
9205
|
+
data: Object.fromEntries(changed)
|
|
9206
|
+
});
|
|
9207
|
+
}
|
|
9208
|
+
for (const key of Object.keys(currentCrdt.data)) {
|
|
9209
|
+
if (!(key in crdt.data)) {
|
|
9210
|
+
ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
9211
|
+
}
|
|
9212
|
+
}
|
|
9213
|
+
}
|
|
9214
|
+
}
|
|
9215
|
+
if (crdt.type === CrdtType.TEXT) {
|
|
9216
|
+
if (currentCrdt.type !== CrdtType.TEXT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data) || crdt.version !== currentCrdt.version) {
|
|
8556
9217
|
ops.push({
|
|
8557
|
-
type: OpCode.
|
|
9218
|
+
type: OpCode.UPDATE_TEXT,
|
|
8558
9219
|
id,
|
|
8559
|
-
|
|
9220
|
+
baseVersion: currentCrdt.type === CrdtType.TEXT ? currentCrdt.version : 0,
|
|
9221
|
+
version: crdt.version,
|
|
9222
|
+
ops: [
|
|
9223
|
+
{
|
|
9224
|
+
type: "delete",
|
|
9225
|
+
index: 0,
|
|
9226
|
+
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9227
|
+
(sum, item) => sum + item.text.length,
|
|
9228
|
+
0
|
|
9229
|
+
) : 0
|
|
9230
|
+
},
|
|
9231
|
+
...crdt.data.map(
|
|
9232
|
+
(item, index, items) => item.attributes === void 0 ? {
|
|
9233
|
+
type: "insert",
|
|
9234
|
+
index: items.slice(0, index).reduce((sum, item2) => sum + item2.text.length, 0),
|
|
9235
|
+
text: item.text
|
|
9236
|
+
} : {
|
|
9237
|
+
type: "insert",
|
|
9238
|
+
index: items.slice(0, index).reduce((sum, item2) => sum + item2.text.length, 0),
|
|
9239
|
+
text: item.text,
|
|
9240
|
+
attributes: item.attributes
|
|
9241
|
+
}
|
|
9242
|
+
)
|
|
9243
|
+
]
|
|
8560
9244
|
});
|
|
8561
9245
|
}
|
|
8562
9246
|
}
|
|
@@ -8608,6 +9292,16 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8608
9292
|
parentKey: crdt.parentKey
|
|
8609
9293
|
});
|
|
8610
9294
|
break;
|
|
9295
|
+
case CrdtType.TEXT:
|
|
9296
|
+
ops.push({
|
|
9297
|
+
type: OpCode.CREATE_TEXT,
|
|
9298
|
+
id,
|
|
9299
|
+
parentId: crdt.parentId,
|
|
9300
|
+
parentKey: crdt.parentKey,
|
|
9301
|
+
data: crdt.data,
|
|
9302
|
+
version: crdt.version
|
|
9303
|
+
});
|
|
9304
|
+
break;
|
|
8611
9305
|
}
|
|
8612
9306
|
}
|
|
8613
9307
|
});
|
|
@@ -8640,6 +9334,12 @@ function mergeListStorageUpdates(first, second) {
|
|
|
8640
9334
|
updates: updates.concat(second.updates)
|
|
8641
9335
|
};
|
|
8642
9336
|
}
|
|
9337
|
+
function mergeTextStorageUpdates(first, second) {
|
|
9338
|
+
return {
|
|
9339
|
+
...second,
|
|
9340
|
+
updates: first.updates.concat(second.updates)
|
|
9341
|
+
};
|
|
9342
|
+
}
|
|
8643
9343
|
function mergeStorageUpdates(first, second) {
|
|
8644
9344
|
if (first === void 0) {
|
|
8645
9345
|
return second;
|
|
@@ -8650,6 +9350,8 @@ function mergeStorageUpdates(first, second) {
|
|
|
8650
9350
|
return mergeMapStorageUpdates(first, second);
|
|
8651
9351
|
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
8652
9352
|
return mergeListStorageUpdates(first, second);
|
|
9353
|
+
} else if (first.type === "LiveText" && second.type === "LiveText") {
|
|
9354
|
+
return mergeTextStorageUpdates(first, second);
|
|
8653
9355
|
} else {
|
|
8654
9356
|
}
|
|
8655
9357
|
return second;
|
|
@@ -8668,7 +9370,7 @@ function sendToPanel(message, options) {
|
|
|
8668
9370
|
...message,
|
|
8669
9371
|
source: "liveblocks-devtools-client"
|
|
8670
9372
|
};
|
|
8671
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
9373
|
+
if (!(_optionalChain([options, 'optionalAccess', _218 => _218.force]) || _bridgeActive)) {
|
|
8672
9374
|
return;
|
|
8673
9375
|
}
|
|
8674
9376
|
window.postMessage(fullMsg, "*");
|
|
@@ -8676,7 +9378,7 @@ function sendToPanel(message, options) {
|
|
|
8676
9378
|
var eventSource = makeEventSource();
|
|
8677
9379
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
8678
9380
|
window.addEventListener("message", (event) => {
|
|
8679
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
9381
|
+
if (event.source === window && _optionalChain([event, 'access', _219 => _219.data, 'optionalAccess', _220 => _220.source]) === "liveblocks-devtools-panel") {
|
|
8680
9382
|
eventSource.notify(event.data);
|
|
8681
9383
|
} else {
|
|
8682
9384
|
}
|
|
@@ -8818,7 +9520,7 @@ function fullSync(room) {
|
|
|
8818
9520
|
msg: "room::sync::full",
|
|
8819
9521
|
roomId: room.id,
|
|
8820
9522
|
status: room.getStatus(),
|
|
8821
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
9523
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _221 => _221.toTreeNode, 'call', _222 => _222("root"), 'access', _223 => _223.payload]), () => ( null)),
|
|
8822
9524
|
me,
|
|
8823
9525
|
others
|
|
8824
9526
|
});
|
|
@@ -9497,15 +10199,15 @@ function installBackgroundTabSpy() {
|
|
|
9497
10199
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
9498
10200
|
const inBackgroundSince = { current: null };
|
|
9499
10201
|
function onVisibilityChange() {
|
|
9500
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
10202
|
+
if (_optionalChain([doc, 'optionalAccess', _224 => _224.visibilityState]) === "hidden") {
|
|
9501
10203
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
9502
10204
|
} else {
|
|
9503
10205
|
inBackgroundSince.current = null;
|
|
9504
10206
|
}
|
|
9505
10207
|
}
|
|
9506
|
-
_optionalChain([doc, 'optionalAccess',
|
|
10208
|
+
_optionalChain([doc, 'optionalAccess', _225 => _225.addEventListener, 'call', _226 => _226("visibilitychange", onVisibilityChange)]);
|
|
9507
10209
|
const unsub = () => {
|
|
9508
|
-
_optionalChain([doc, 'optionalAccess',
|
|
10210
|
+
_optionalChain([doc, 'optionalAccess', _227 => _227.removeEventListener, 'call', _228 => _228("visibilitychange", onVisibilityChange)]);
|
|
9509
10211
|
};
|
|
9510
10212
|
return [inBackgroundSince, unsub];
|
|
9511
10213
|
}
|
|
@@ -9698,7 +10400,7 @@ function createRoom(options, config) {
|
|
|
9698
10400
|
}
|
|
9699
10401
|
}
|
|
9700
10402
|
function isStorageWritable() {
|
|
9701
|
-
const scopes = _optionalChain([context, 'access',
|
|
10403
|
+
const scopes = _optionalChain([context, 'access', _229 => _229.dynamicSessionInfoSig, 'access', _230 => _230.get, 'call', _231 => _231(), 'optionalAccess', _232 => _232.scopes]);
|
|
9702
10404
|
return scopes !== void 0 ? canWriteStorage(scopes) : true;
|
|
9703
10405
|
}
|
|
9704
10406
|
const eventHub = {
|
|
@@ -9806,7 +10508,7 @@ function createRoom(options, config) {
|
|
|
9806
10508
|
context.pool
|
|
9807
10509
|
);
|
|
9808
10510
|
}
|
|
9809
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
10511
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _233 => _233.get, 'call', _234 => _234(), 'optionalAccess', _235 => _235.canWrite]), () => ( true));
|
|
9810
10512
|
const root = context.root;
|
|
9811
10513
|
disableHistory(() => {
|
|
9812
10514
|
for (const key in context.initialStorage) {
|
|
@@ -9938,7 +10640,7 @@ function createRoom(options, config) {
|
|
|
9938
10640
|
);
|
|
9939
10641
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
9940
10642
|
}
|
|
9941
|
-
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
10643
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT || op.type === OpCode.CREATE_TEXT) {
|
|
9942
10644
|
createdNodeIds.add(op.id);
|
|
9943
10645
|
}
|
|
9944
10646
|
}
|
|
@@ -9958,6 +10660,7 @@ function createRoom(options, config) {
|
|
|
9958
10660
|
switch (op.type) {
|
|
9959
10661
|
case OpCode.DELETE_OBJECT_KEY:
|
|
9960
10662
|
case OpCode.UPDATE_OBJECT:
|
|
10663
|
+
case OpCode.UPDATE_TEXT:
|
|
9961
10664
|
case OpCode.DELETE_CRDT: {
|
|
9962
10665
|
const node = context.pool.nodes.get(op.id);
|
|
9963
10666
|
if (node === void 0) {
|
|
@@ -9982,6 +10685,7 @@ function createRoom(options, config) {
|
|
|
9982
10685
|
case OpCode.CREATE_OBJECT:
|
|
9983
10686
|
case OpCode.CREATE_LIST:
|
|
9984
10687
|
case OpCode.CREATE_MAP:
|
|
10688
|
+
case OpCode.CREATE_TEXT:
|
|
9985
10689
|
case OpCode.CREATE_REGISTER: {
|
|
9986
10690
|
if (op.parentId === void 0) {
|
|
9987
10691
|
return { modified: false };
|
|
@@ -10012,7 +10716,7 @@ function createRoom(options, config) {
|
|
|
10012
10716
|
}
|
|
10013
10717
|
context.myPresence.patch(patch);
|
|
10014
10718
|
if (context.activeBatch) {
|
|
10015
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10719
|
+
if (_optionalChain([options2, 'optionalAccess', _236 => _236.addToHistory])) {
|
|
10016
10720
|
context.activeBatch.reverseOps.pushLeft({
|
|
10017
10721
|
type: "presence",
|
|
10018
10722
|
data: oldValues
|
|
@@ -10021,7 +10725,7 @@ function createRoom(options, config) {
|
|
|
10021
10725
|
context.activeBatch.updates.presence = true;
|
|
10022
10726
|
} else {
|
|
10023
10727
|
flushNowOrSoon();
|
|
10024
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10728
|
+
if (_optionalChain([options2, 'optionalAccess', _237 => _237.addToHistory])) {
|
|
10025
10729
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
10026
10730
|
}
|
|
10027
10731
|
notify({ presence: true });
|
|
@@ -10198,11 +10902,11 @@ function createRoom(options, config) {
|
|
|
10198
10902
|
break;
|
|
10199
10903
|
}
|
|
10200
10904
|
case ServerMsgCode.STORAGE_CHUNK:
|
|
10201
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
10905
|
+
_optionalChain([stopwatch, 'optionalAccess', _238 => _238.lap, 'call', _239 => _239()]);
|
|
10202
10906
|
nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
|
|
10203
10907
|
break;
|
|
10204
10908
|
case ServerMsgCode.STORAGE_STREAM_END: {
|
|
10205
|
-
const timing = _optionalChain([stopwatch, 'optionalAccess',
|
|
10909
|
+
const timing = _optionalChain([stopwatch, 'optionalAccess', _240 => _240.stop, 'call', _241 => _241()]);
|
|
10206
10910
|
if (timing) {
|
|
10207
10911
|
const ms = (v) => `${v.toFixed(1)}ms`;
|
|
10208
10912
|
const rest = timing.laps.slice(1);
|
|
@@ -10337,11 +11041,11 @@ function createRoom(options, config) {
|
|
|
10337
11041
|
} else if (pendingFeedsRequests.has(requestId)) {
|
|
10338
11042
|
const pending = pendingFeedsRequests.get(requestId);
|
|
10339
11043
|
pendingFeedsRequests.delete(requestId);
|
|
10340
|
-
_optionalChain([pending, 'optionalAccess',
|
|
11044
|
+
_optionalChain([pending, 'optionalAccess', _242 => _242.reject, 'call', _243 => _243(err)]);
|
|
10341
11045
|
} else if (pendingFeedMessagesRequests.has(requestId)) {
|
|
10342
11046
|
const pending = pendingFeedMessagesRequests.get(requestId);
|
|
10343
11047
|
pendingFeedMessagesRequests.delete(requestId);
|
|
10344
|
-
_optionalChain([pending, 'optionalAccess',
|
|
11048
|
+
_optionalChain([pending, 'optionalAccess', _244 => _244.reject, 'call', _245 => _245(err)]);
|
|
10345
11049
|
}
|
|
10346
11050
|
eventHub.feeds.notify(message);
|
|
10347
11051
|
break;
|
|
@@ -10495,10 +11199,10 @@ function createRoom(options, config) {
|
|
|
10495
11199
|
timeoutId,
|
|
10496
11200
|
kind,
|
|
10497
11201
|
feedId,
|
|
10498
|
-
messageId: _optionalChain([options2, 'optionalAccess',
|
|
10499
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
11202
|
+
messageId: _optionalChain([options2, 'optionalAccess', _246 => _246.messageId]),
|
|
11203
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _247 => _247.expectedClientMessageId])
|
|
10500
11204
|
});
|
|
10501
|
-
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess',
|
|
11205
|
+
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess', _248 => _248.expectedClientMessageId]) === void 0) {
|
|
10502
11206
|
const q = _nullishCoalesce(pendingAddMessageFifoByFeed.get(feedId), () => ( []));
|
|
10503
11207
|
q.push(requestId);
|
|
10504
11208
|
pendingAddMessageFifoByFeed.set(feedId, q);
|
|
@@ -10549,10 +11253,10 @@ function createRoom(options, config) {
|
|
|
10549
11253
|
}
|
|
10550
11254
|
if (!matched) {
|
|
10551
11255
|
const q = pendingAddMessageFifoByFeed.get(message.feedId);
|
|
10552
|
-
const headId = _optionalChain([q, 'optionalAccess',
|
|
11256
|
+
const headId = _optionalChain([q, 'optionalAccess', _249 => _249[0]]);
|
|
10553
11257
|
if (headId !== void 0) {
|
|
10554
11258
|
const pending = pendingFeedMutations.get(headId);
|
|
10555
|
-
if (_optionalChain([pending, 'optionalAccess',
|
|
11259
|
+
if (_optionalChain([pending, 'optionalAccess', _250 => _250.kind]) === "add-message" && pending.expectedClientMessageId === void 0) {
|
|
10556
11260
|
settleFeedMutation(headId, "ok");
|
|
10557
11261
|
}
|
|
10558
11262
|
}
|
|
@@ -10588,7 +11292,7 @@ function createRoom(options, config) {
|
|
|
10588
11292
|
const unacknowledgedOps2 = [...context.unacknowledgedOps.values()];
|
|
10589
11293
|
createOrUpdateRootFromMessage(nodes);
|
|
10590
11294
|
applyAndSendOfflineOps(unacknowledgedOps2);
|
|
10591
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
11295
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _251 => _251()]);
|
|
10592
11296
|
notifyStorageStatus();
|
|
10593
11297
|
eventHub.storageDidLoad.notify();
|
|
10594
11298
|
}
|
|
@@ -10606,7 +11310,7 @@ function createRoom(options, config) {
|
|
|
10606
11310
|
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
10607
11311
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
10608
11312
|
nodeMapBuffer.take();
|
|
10609
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
11313
|
+
_optionalChain([stopwatch, 'optionalAccess', _252 => _252.start, 'call', _253 => _253()]);
|
|
10610
11314
|
}
|
|
10611
11315
|
if (options2.flush) {
|
|
10612
11316
|
flushNowOrSoon();
|
|
@@ -10662,10 +11366,10 @@ function createRoom(options, config) {
|
|
|
10662
11366
|
const message = {
|
|
10663
11367
|
type: ClientMsgCode.FETCH_FEEDS,
|
|
10664
11368
|
requestId,
|
|
10665
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10666
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
10667
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
10668
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
11369
|
+
cursor: _optionalChain([options2, 'optionalAccess', _254 => _254.cursor]),
|
|
11370
|
+
since: _optionalChain([options2, 'optionalAccess', _255 => _255.since]),
|
|
11371
|
+
limit: _optionalChain([options2, 'optionalAccess', _256 => _256.limit]),
|
|
11372
|
+
metadata: _optionalChain([options2, 'optionalAccess', _257 => _257.metadata])
|
|
10669
11373
|
};
|
|
10670
11374
|
context.buffer.messages.push(message);
|
|
10671
11375
|
flushNowOrSoon();
|
|
@@ -10685,9 +11389,9 @@ function createRoom(options, config) {
|
|
|
10685
11389
|
type: ClientMsgCode.FETCH_FEED_MESSAGES,
|
|
10686
11390
|
requestId,
|
|
10687
11391
|
feedId,
|
|
10688
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10689
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
10690
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
11392
|
+
cursor: _optionalChain([options2, 'optionalAccess', _258 => _258.cursor]),
|
|
11393
|
+
since: _optionalChain([options2, 'optionalAccess', _259 => _259.since]),
|
|
11394
|
+
limit: _optionalChain([options2, 'optionalAccess', _260 => _260.limit])
|
|
10691
11395
|
};
|
|
10692
11396
|
context.buffer.messages.push(message);
|
|
10693
11397
|
flushNowOrSoon();
|
|
@@ -10706,8 +11410,8 @@ function createRoom(options, config) {
|
|
|
10706
11410
|
type: ClientMsgCode.ADD_FEED,
|
|
10707
11411
|
requestId,
|
|
10708
11412
|
feedId,
|
|
10709
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
10710
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
11413
|
+
metadata: _optionalChain([options2, 'optionalAccess', _261 => _261.metadata]),
|
|
11414
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _262 => _262.createdAt])
|
|
10711
11415
|
};
|
|
10712
11416
|
context.buffer.messages.push(message);
|
|
10713
11417
|
flushNowOrSoon();
|
|
@@ -10741,15 +11445,15 @@ function createRoom(options, config) {
|
|
|
10741
11445
|
function addFeedMessage(feedId, data, options2) {
|
|
10742
11446
|
const requestId = nanoid();
|
|
10743
11447
|
const promise = registerFeedMutation(requestId, "add-message", feedId, {
|
|
10744
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
11448
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _263 => _263.id])
|
|
10745
11449
|
});
|
|
10746
11450
|
const message = {
|
|
10747
11451
|
type: ClientMsgCode.ADD_FEED_MESSAGE,
|
|
10748
11452
|
requestId,
|
|
10749
11453
|
feedId,
|
|
10750
11454
|
data,
|
|
10751
|
-
id: _optionalChain([options2, 'optionalAccess',
|
|
10752
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
11455
|
+
id: _optionalChain([options2, 'optionalAccess', _264 => _264.id]),
|
|
11456
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _265 => _265.createdAt])
|
|
10753
11457
|
};
|
|
10754
11458
|
context.buffer.messages.push(message);
|
|
10755
11459
|
flushNowOrSoon();
|
|
@@ -10766,7 +11470,7 @@ function createRoom(options, config) {
|
|
|
10766
11470
|
feedId,
|
|
10767
11471
|
messageId,
|
|
10768
11472
|
data,
|
|
10769
|
-
updatedAt: _optionalChain([options2, 'optionalAccess',
|
|
11473
|
+
updatedAt: _optionalChain([options2, 'optionalAccess', _266 => _266.updatedAt])
|
|
10770
11474
|
};
|
|
10771
11475
|
context.buffer.messages.push(message);
|
|
10772
11476
|
flushNowOrSoon();
|
|
@@ -10973,8 +11677,8 @@ function createRoom(options, config) {
|
|
|
10973
11677
|
async function getThreads(options2) {
|
|
10974
11678
|
return httpClient.getThreads({
|
|
10975
11679
|
roomId,
|
|
10976
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
10977
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
11680
|
+
query: _optionalChain([options2, 'optionalAccess', _267 => _267.query]),
|
|
11681
|
+
cursor: _optionalChain([options2, 'optionalAccess', _268 => _268.cursor])
|
|
10978
11682
|
});
|
|
10979
11683
|
}
|
|
10980
11684
|
async function getThread(threadId) {
|
|
@@ -11096,7 +11800,7 @@ function createRoom(options, config) {
|
|
|
11096
11800
|
function getSubscriptionSettings(options2) {
|
|
11097
11801
|
return httpClient.getSubscriptionSettings({
|
|
11098
11802
|
roomId,
|
|
11099
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
11803
|
+
signal: _optionalChain([options2, 'optionalAccess', _269 => _269.signal])
|
|
11100
11804
|
});
|
|
11101
11805
|
}
|
|
11102
11806
|
function updateSubscriptionSettings(settings) {
|
|
@@ -11118,7 +11822,7 @@ function createRoom(options, config) {
|
|
|
11118
11822
|
{
|
|
11119
11823
|
[kInternal]: {
|
|
11120
11824
|
get presenceBuffer() {
|
|
11121
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
11825
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _270 => _270.buffer, 'access', _271 => _271.presenceUpdates, 'optionalAccess', _272 => _272.data]), () => ( null)));
|
|
11122
11826
|
},
|
|
11123
11827
|
// prettier-ignore
|
|
11124
11828
|
get undoStack() {
|
|
@@ -11133,9 +11837,9 @@ function createRoom(options, config) {
|
|
|
11133
11837
|
return context.yjsProvider;
|
|
11134
11838
|
},
|
|
11135
11839
|
setYjsProvider(newProvider) {
|
|
11136
|
-
_optionalChain([context, 'access',
|
|
11840
|
+
_optionalChain([context, 'access', _273 => _273.yjsProvider, 'optionalAccess', _274 => _274.off, 'call', _275 => _275("status", yjsStatusDidChange)]);
|
|
11137
11841
|
context.yjsProvider = newProvider;
|
|
11138
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
11842
|
+
_optionalChain([newProvider, 'optionalAccess', _276 => _276.on, 'call', _277 => _277("status", yjsStatusDidChange)]);
|
|
11139
11843
|
context.yjsProviderDidChange.notify();
|
|
11140
11844
|
},
|
|
11141
11845
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -11193,7 +11897,7 @@ ${dumpPool(context.pool)}`;
|
|
|
11193
11897
|
source.dispose();
|
|
11194
11898
|
}
|
|
11195
11899
|
eventHub.roomWillDestroy.notify();
|
|
11196
|
-
_optionalChain([context, 'access',
|
|
11900
|
+
_optionalChain([context, 'access', _278 => _278.yjsProvider, 'optionalAccess', _279 => _279.off, 'call', _280 => _280("status", yjsStatusDidChange)]);
|
|
11197
11901
|
syncSourceForStorage.destroy();
|
|
11198
11902
|
syncSourceForYjs.destroy();
|
|
11199
11903
|
uninstallBgTabSpy();
|
|
@@ -11353,7 +12057,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
11353
12057
|
}
|
|
11354
12058
|
if (isLiveNode(first)) {
|
|
11355
12059
|
const node = first;
|
|
11356
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
12060
|
+
if (_optionalChain([options, 'optionalAccess', _281 => _281.isDeep])) {
|
|
11357
12061
|
const storageCallback = second;
|
|
11358
12062
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
11359
12063
|
} else {
|
|
@@ -11439,8 +12143,8 @@ function createClient(options) {
|
|
|
11439
12143
|
const authManager = createAuthManager(options, (token) => {
|
|
11440
12144
|
currentUserId.set(() => token.uid);
|
|
11441
12145
|
});
|
|
11442
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
11443
|
-
_optionalChain([globalThis, 'access',
|
|
12146
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _282 => _282.polyfills, 'optionalAccess', _283 => _283.fetch]) || /* istanbul ignore next */
|
|
12147
|
+
_optionalChain([globalThis, 'access', _284 => _284.fetch, 'optionalAccess', _285 => _285.bind, 'call', _286 => _286(globalThis)]);
|
|
11444
12148
|
const httpClient = createApiClient({
|
|
11445
12149
|
baseUrl,
|
|
11446
12150
|
fetchPolyfill,
|
|
@@ -11458,7 +12162,7 @@ function createClient(options) {
|
|
|
11458
12162
|
delegates: {
|
|
11459
12163
|
createSocket: makeCreateSocketDelegateForAi(
|
|
11460
12164
|
baseUrl,
|
|
11461
|
-
_optionalChain([clientOptions, 'access',
|
|
12165
|
+
_optionalChain([clientOptions, 'access', _287 => _287.polyfills, 'optionalAccess', _288 => _288.WebSocket])
|
|
11462
12166
|
),
|
|
11463
12167
|
authenticate: async () => {
|
|
11464
12168
|
const resp = await authManager.getAuthValue({
|
|
@@ -11528,7 +12232,7 @@ function createClient(options) {
|
|
|
11528
12232
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
11529
12233
|
roomId,
|
|
11530
12234
|
baseUrl,
|
|
11531
|
-
_optionalChain([clientOptions, 'access',
|
|
12235
|
+
_optionalChain([clientOptions, 'access', _289 => _289.polyfills, 'optionalAccess', _290 => _290.WebSocket])
|
|
11532
12236
|
),
|
|
11533
12237
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
11534
12238
|
})),
|
|
@@ -11551,7 +12255,7 @@ function createClient(options) {
|
|
|
11551
12255
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
11552
12256
|
if (shouldConnect) {
|
|
11553
12257
|
if (typeof atob === "undefined") {
|
|
11554
|
-
if (_optionalChain([clientOptions, 'access',
|
|
12258
|
+
if (_optionalChain([clientOptions, 'access', _291 => _291.polyfills, 'optionalAccess', _292 => _292.atob]) === void 0) {
|
|
11555
12259
|
throw new Error(
|
|
11556
12260
|
"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
12261
|
);
|
|
@@ -11563,7 +12267,7 @@ function createClient(options) {
|
|
|
11563
12267
|
return leaseRoom(newRoomDetails);
|
|
11564
12268
|
}
|
|
11565
12269
|
function getRoom(roomId) {
|
|
11566
|
-
const room = _optionalChain([roomsById, 'access',
|
|
12270
|
+
const room = _optionalChain([roomsById, 'access', _293 => _293.get, 'call', _294 => _294(roomId), 'optionalAccess', _295 => _295.room]);
|
|
11567
12271
|
return room ? room : null;
|
|
11568
12272
|
}
|
|
11569
12273
|
function logout() {
|
|
@@ -11579,7 +12283,7 @@ function createClient(options) {
|
|
|
11579
12283
|
const batchedResolveUsers = new Batch(
|
|
11580
12284
|
async (batchedUserIds) => {
|
|
11581
12285
|
const userIds = batchedUserIds.flat();
|
|
11582
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
12286
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _296 => _296({ userIds })]);
|
|
11583
12287
|
warnOnceIf(
|
|
11584
12288
|
!resolveUsers,
|
|
11585
12289
|
"Set the resolveUsers option in createClient to specify user info."
|
|
@@ -11596,7 +12300,7 @@ function createClient(options) {
|
|
|
11596
12300
|
const batchedResolveRoomsInfo = new Batch(
|
|
11597
12301
|
async (batchedRoomIds) => {
|
|
11598
12302
|
const roomIds = batchedRoomIds.flat();
|
|
11599
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
12303
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _297 => _297({ roomIds })]);
|
|
11600
12304
|
warnOnceIf(
|
|
11601
12305
|
!resolveRoomsInfo,
|
|
11602
12306
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
@@ -11613,7 +12317,7 @@ function createClient(options) {
|
|
|
11613
12317
|
const batchedResolveGroupsInfo = new Batch(
|
|
11614
12318
|
async (batchedGroupIds) => {
|
|
11615
12319
|
const groupIds = batchedGroupIds.flat();
|
|
11616
|
-
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall',
|
|
12320
|
+
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _298 => _298({ groupIds })]);
|
|
11617
12321
|
warnOnceIf(
|
|
11618
12322
|
!resolveGroupsInfo,
|
|
11619
12323
|
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
@@ -11672,7 +12376,7 @@ function createClient(options) {
|
|
|
11672
12376
|
}
|
|
11673
12377
|
};
|
|
11674
12378
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
11675
|
-
_optionalChain([win, 'optionalAccess',
|
|
12379
|
+
_optionalChain([win, 'optionalAccess', _299 => _299.addEventListener, 'call', _300 => _300("beforeunload", maybePreventClose)]);
|
|
11676
12380
|
}
|
|
11677
12381
|
async function getNotificationSettings(options2) {
|
|
11678
12382
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -11800,7 +12504,7 @@ var commentBodyElementsTypes = {
|
|
|
11800
12504
|
mention: "inline"
|
|
11801
12505
|
};
|
|
11802
12506
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
11803
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
12507
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _301 => _301.content])) {
|
|
11804
12508
|
return;
|
|
11805
12509
|
}
|
|
11806
12510
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -11810,13 +12514,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
11810
12514
|
for (const block of body.content) {
|
|
11811
12515
|
if (type === "all" || type === "block") {
|
|
11812
12516
|
if (guard(block)) {
|
|
11813
|
-
_optionalChain([visitor, 'optionalCall',
|
|
12517
|
+
_optionalChain([visitor, 'optionalCall', _302 => _302(block)]);
|
|
11814
12518
|
}
|
|
11815
12519
|
}
|
|
11816
12520
|
if (type === "all" || type === "inline") {
|
|
11817
12521
|
for (const inline of block.children) {
|
|
11818
12522
|
if (guard(inline)) {
|
|
11819
|
-
_optionalChain([visitor, 'optionalCall',
|
|
12523
|
+
_optionalChain([visitor, 'optionalCall', _303 => _303(inline)]);
|
|
11820
12524
|
}
|
|
11821
12525
|
}
|
|
11822
12526
|
}
|
|
@@ -11986,7 +12690,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
11986
12690
|
text: ({ element }) => element.text,
|
|
11987
12691
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
11988
12692
|
mention: ({ element, user, group }) => {
|
|
11989
|
-
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
12693
|
+
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _304 => _304.name]), () => ( _optionalChain([group, 'optionalAccess', _305 => _305.name]))), () => ( element.id))}`;
|
|
11990
12694
|
}
|
|
11991
12695
|
};
|
|
11992
12696
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -12016,7 +12720,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
12016
12720
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
12017
12721
|
},
|
|
12018
12722
|
mention: ({ element, user, group }) => {
|
|
12019
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
12723
|
+
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
12724
|
}
|
|
12021
12725
|
};
|
|
12022
12726
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -12046,20 +12750,20 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
12046
12750
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
12047
12751
|
},
|
|
12048
12752
|
mention: ({ element, user, group }) => {
|
|
12049
|
-
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
12753
|
+
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _310 => _310.name]), () => ( _optionalChain([group, 'optionalAccess', _311 => _311.name]))), () => ( element.id))}`;
|
|
12050
12754
|
}
|
|
12051
12755
|
};
|
|
12052
12756
|
async function stringifyCommentBody(body, options) {
|
|
12053
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12054
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12757
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _312 => _312.format]), () => ( "plain"));
|
|
12758
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _313 => _313.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
12055
12759
|
const elements = {
|
|
12056
12760
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
12057
|
-
..._optionalChain([options, 'optionalAccess',
|
|
12761
|
+
..._optionalChain([options, 'optionalAccess', _314 => _314.elements])
|
|
12058
12762
|
};
|
|
12059
12763
|
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
12060
12764
|
body,
|
|
12061
|
-
_optionalChain([options, 'optionalAccess',
|
|
12062
|
-
_optionalChain([options, 'optionalAccess',
|
|
12765
|
+
_optionalChain([options, 'optionalAccess', _315 => _315.resolveUsers]),
|
|
12766
|
+
_optionalChain([options, 'optionalAccess', _316 => _316.resolveGroupsInfo])
|
|
12063
12767
|
);
|
|
12064
12768
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
12065
12769
|
switch (block.type) {
|
|
@@ -12141,6 +12845,12 @@ function toPlainLson(lson) {
|
|
|
12141
12845
|
liveblocksType: "LiveList",
|
|
12142
12846
|
data: [...lson].map((item) => toPlainLson(item))
|
|
12143
12847
|
};
|
|
12848
|
+
} else if (lson instanceof LiveText) {
|
|
12849
|
+
return {
|
|
12850
|
+
liveblocksType: "LiveText",
|
|
12851
|
+
data: lson.toDelta(),
|
|
12852
|
+
version: lson.version
|
|
12853
|
+
};
|
|
12144
12854
|
} else {
|
|
12145
12855
|
return lson;
|
|
12146
12856
|
}
|
|
@@ -12194,9 +12904,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
12194
12904
|
const startTime = performance.now();
|
|
12195
12905
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
12196
12906
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
12197
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12907
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _317 => _317.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
12198
12908
|
const context = {
|
|
12199
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
12909
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _318 => _318.visibilityState]) !== "hidden",
|
|
12200
12910
|
lastSuccessfulPollAt: startTime,
|
|
12201
12911
|
count: 0,
|
|
12202
12912
|
backoff: 0
|
|
@@ -12277,11 +12987,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
12277
12987
|
pollNowIfStale();
|
|
12278
12988
|
}
|
|
12279
12989
|
function onVisibilityChange() {
|
|
12280
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
12990
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _319 => _319.visibilityState]) !== "hidden");
|
|
12281
12991
|
}
|
|
12282
|
-
_optionalChain([doc, 'optionalAccess',
|
|
12283
|
-
_optionalChain([win, 'optionalAccess',
|
|
12284
|
-
_optionalChain([win, 'optionalAccess',
|
|
12992
|
+
_optionalChain([doc, 'optionalAccess', _320 => _320.addEventListener, 'call', _321 => _321("visibilitychange", onVisibilityChange)]);
|
|
12993
|
+
_optionalChain([win, 'optionalAccess', _322 => _322.addEventListener, 'call', _323 => _323("online", onVisibilityChange)]);
|
|
12994
|
+
_optionalChain([win, 'optionalAccess', _324 => _324.addEventListener, 'call', _325 => _325("focus", pollNowIfStale)]);
|
|
12285
12995
|
fsm.start();
|
|
12286
12996
|
return {
|
|
12287
12997
|
inc,
|
|
@@ -12418,5 +13128,8 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
12418
13128
|
|
|
12419
13129
|
|
|
12420
13130
|
|
|
12421
|
-
|
|
13131
|
+
|
|
13132
|
+
|
|
13133
|
+
|
|
13134
|
+
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
13135
|
//# sourceMappingURL=index.cjs.map
|