@liveblocks/core 2.21.0 → 2.22.1
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 +160 -133
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -42
- package/dist/index.d.ts +118 -42
- package/dist/index.js +89 -62
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
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 = "2.
|
|
9
|
+
var PKG_VERSION = "2.22.1";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3821,6 +3821,35 @@ function isAckOp(op) {
|
|
|
3821
3821
|
}
|
|
3822
3822
|
|
|
3823
3823
|
// src/crdts/AbstractCrdt.ts
|
|
3824
|
+
function createManagedPool(roomId, options) {
|
|
3825
|
+
const {
|
|
3826
|
+
getCurrentConnectionId,
|
|
3827
|
+
onDispatch,
|
|
3828
|
+
isStorageWritable = () => true
|
|
3829
|
+
} = options;
|
|
3830
|
+
let clock = 0;
|
|
3831
|
+
let opClock = 0;
|
|
3832
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
3833
|
+
return {
|
|
3834
|
+
roomId,
|
|
3835
|
+
nodes,
|
|
3836
|
+
getNode: (id) => nodes.get(id),
|
|
3837
|
+
addNode: (id, node) => void nodes.set(id, node),
|
|
3838
|
+
deleteNode: (id) => void nodes.delete(id),
|
|
3839
|
+
generateId: () => `${getCurrentConnectionId()}:${clock++}`,
|
|
3840
|
+
generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
|
|
3841
|
+
dispatch(ops, reverse, storageUpdates) {
|
|
3842
|
+
onDispatch?.(ops, reverse, storageUpdates);
|
|
3843
|
+
},
|
|
3844
|
+
assertStorageIsWritable: () => {
|
|
3845
|
+
if (!isStorageWritable()) {
|
|
3846
|
+
throw new Error(
|
|
3847
|
+
"Cannot write to storage with a read only user, please ensure the user has write permissions"
|
|
3848
|
+
);
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
};
|
|
3852
|
+
}
|
|
3824
3853
|
function crdtAsLiveNode(value) {
|
|
3825
3854
|
return value;
|
|
3826
3855
|
}
|
|
@@ -5456,7 +5485,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5456
5485
|
}
|
|
5457
5486
|
return [root, parentToChildren];
|
|
5458
5487
|
}
|
|
5459
|
-
/** @
|
|
5488
|
+
/** @private Do not use this API directly */
|
|
5460
5489
|
static _fromItems(items, pool) {
|
|
5461
5490
|
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(items);
|
|
5462
5491
|
return _LiveObject._deserialize(
|
|
@@ -6544,6 +6573,7 @@ function installBackgroundTabSpy() {
|
|
|
6544
6573
|
return [inBackgroundSince, unsub];
|
|
6545
6574
|
}
|
|
6546
6575
|
function createRoom(options, config) {
|
|
6576
|
+
const roomId = config.roomId;
|
|
6547
6577
|
const initialPresence = options.initialPresence;
|
|
6548
6578
|
const initialStorage = options.initialStorage;
|
|
6549
6579
|
const httpClient = config.roomHttpClient;
|
|
@@ -6590,9 +6620,11 @@ function createRoom(options, config) {
|
|
|
6590
6620
|
yjsProvider: void 0,
|
|
6591
6621
|
yjsProviderDidChange: makeEventSource(),
|
|
6592
6622
|
// Storage
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6623
|
+
pool: createManagedPool(roomId, {
|
|
6624
|
+
getCurrentConnectionId,
|
|
6625
|
+
onDispatch,
|
|
6626
|
+
isStorageWritable
|
|
6627
|
+
}),
|
|
6596
6628
|
root: void 0,
|
|
6597
6629
|
undoStack: [],
|
|
6598
6630
|
redoStack: [],
|
|
@@ -6683,59 +6715,42 @@ function createRoom(options, config) {
|
|
|
6683
6715
|
}
|
|
6684
6716
|
}
|
|
6685
6717
|
});
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
deleteNode: (id) => void context.nodes.delete(id),
|
|
6691
|
-
generateId: () => `${getConnectionId()}:${context.clock++}`,
|
|
6692
|
-
generateOpId: () => `${getConnectionId()}:${context.opClock++}`,
|
|
6693
|
-
dispatch(ops, reverse, storageUpdates) {
|
|
6694
|
-
const activeBatch = context.activeBatch;
|
|
6695
|
-
if (process.env.NODE_ENV !== "production") {
|
|
6696
|
-
const stackTrace = captureStackTrace("Storage mutation", this.dispatch);
|
|
6697
|
-
if (stackTrace) {
|
|
6698
|
-
for (const op of ops) {
|
|
6699
|
-
if (op.opId) {
|
|
6700
|
-
nn(context.opStackTraces).set(op.opId, stackTrace);
|
|
6701
|
-
}
|
|
6702
|
-
}
|
|
6703
|
-
}
|
|
6704
|
-
}
|
|
6705
|
-
if (activeBatch) {
|
|
6718
|
+
function onDispatch(ops, reverse, storageUpdates) {
|
|
6719
|
+
if (process.env.NODE_ENV !== "production") {
|
|
6720
|
+
const stackTrace = captureStackTrace("Storage mutation", onDispatch);
|
|
6721
|
+
if (stackTrace) {
|
|
6706
6722
|
for (const op of ops) {
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
activeBatch.updates.storageUpdates.set(
|
|
6711
|
-
key,
|
|
6712
|
-
mergeStorageUpdates(
|
|
6713
|
-
activeBatch.updates.storageUpdates.get(key),
|
|
6714
|
-
value
|
|
6715
|
-
)
|
|
6716
|
-
);
|
|
6723
|
+
if (op.opId) {
|
|
6724
|
+
nn(context.opStackTraces).set(op.opId, stackTrace);
|
|
6725
|
+
}
|
|
6717
6726
|
}
|
|
6718
|
-
activeBatch.reverseOps.pushLeft(reverse);
|
|
6719
|
-
} else {
|
|
6720
|
-
addToUndoStack(reverse);
|
|
6721
|
-
context.redoStack.length = 0;
|
|
6722
|
-
dispatchOps(ops);
|
|
6723
|
-
notify({ storageUpdates });
|
|
6724
6727
|
}
|
|
6725
|
-
}
|
|
6726
|
-
|
|
6727
|
-
const
|
|
6728
|
-
|
|
6729
|
-
return;
|
|
6728
|
+
}
|
|
6729
|
+
if (context.activeBatch) {
|
|
6730
|
+
for (const op of ops) {
|
|
6731
|
+
context.activeBatch.ops.push(op);
|
|
6730
6732
|
}
|
|
6731
|
-
const
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6733
|
+
for (const [key, value] of storageUpdates) {
|
|
6734
|
+
context.activeBatch.updates.storageUpdates.set(
|
|
6735
|
+
key,
|
|
6736
|
+
mergeStorageUpdates(
|
|
6737
|
+
context.activeBatch.updates.storageUpdates.get(key),
|
|
6738
|
+
value
|
|
6739
|
+
)
|
|
6735
6740
|
);
|
|
6736
6741
|
}
|
|
6742
|
+
context.activeBatch.reverseOps.pushLeft(reverse);
|
|
6743
|
+
} else {
|
|
6744
|
+
addToUndoStack(reverse);
|
|
6745
|
+
context.redoStack.length = 0;
|
|
6746
|
+
dispatchOps(ops);
|
|
6747
|
+
notify({ storageUpdates });
|
|
6737
6748
|
}
|
|
6738
|
-
}
|
|
6749
|
+
}
|
|
6750
|
+
function isStorageWritable() {
|
|
6751
|
+
const scopes = context.dynamicSessionInfoSig.get()?.scopes;
|
|
6752
|
+
return scopes !== void 0 ? canWriteStorage(scopes) : true;
|
|
6753
|
+
}
|
|
6739
6754
|
const eventHub = {
|
|
6740
6755
|
status: makeEventSource(),
|
|
6741
6756
|
// New/recommended API
|
|
@@ -6752,7 +6767,6 @@ function createRoom(options, config) {
|
|
|
6752
6767
|
comments: makeEventSource(),
|
|
6753
6768
|
roomWillDestroy: makeEventSource()
|
|
6754
6769
|
};
|
|
6755
|
-
const roomId = config.roomId;
|
|
6756
6770
|
async function createTextMention(userId, mentionId) {
|
|
6757
6771
|
return httpClient.createTextMention({ roomId, userId, mentionId });
|
|
6758
6772
|
}
|
|
@@ -6900,7 +6914,7 @@ function createRoom(options, config) {
|
|
|
6900
6914
|
if (context.root !== void 0) {
|
|
6901
6915
|
updateRoot(message.items);
|
|
6902
6916
|
} else {
|
|
6903
|
-
context.root = LiveObject._fromItems(message.items, pool);
|
|
6917
|
+
context.root = LiveObject._fromItems(message.items, context.pool);
|
|
6904
6918
|
}
|
|
6905
6919
|
const canWrite = self.get()?.canWrite ?? true;
|
|
6906
6920
|
const stackSizeBefore = context.undoStack.length;
|
|
@@ -6922,7 +6936,7 @@ function createRoom(options, config) {
|
|
|
6922
6936
|
return;
|
|
6923
6937
|
}
|
|
6924
6938
|
const currentItems = /* @__PURE__ */ new Map();
|
|
6925
|
-
for (const [id, node] of context.nodes) {
|
|
6939
|
+
for (const [id, node] of context.pool.nodes) {
|
|
6926
6940
|
currentItems.set(id, node._serialize());
|
|
6927
6941
|
}
|
|
6928
6942
|
const ops = getTreesDiffOperations(currentItems, new Map(items));
|
|
@@ -6962,7 +6976,7 @@ function createRoom(options, config) {
|
|
|
6962
6976
|
}
|
|
6963
6977
|
notifyStorageStatus();
|
|
6964
6978
|
}
|
|
6965
|
-
function
|
|
6979
|
+
function getCurrentConnectionId() {
|
|
6966
6980
|
const info = context.dynamicSessionInfoSig.get();
|
|
6967
6981
|
if (info) {
|
|
6968
6982
|
return info.actor;
|
|
@@ -6980,7 +6994,7 @@ function createRoom(options, config) {
|
|
|
6980
6994
|
const createdNodeIds = /* @__PURE__ */ new Set();
|
|
6981
6995
|
const ops = rawOps.map((op) => {
|
|
6982
6996
|
if (op.type !== "presence" && !op.opId) {
|
|
6983
|
-
return { ...op, opId: pool.generateOpId() };
|
|
6997
|
+
return { ...op, opId: context.pool.generateOpId() };
|
|
6984
6998
|
} else {
|
|
6985
6999
|
return op;
|
|
6986
7000
|
}
|
|
@@ -7052,14 +7066,14 @@ function createRoom(options, config) {
|
|
|
7052
7066
|
case 6 /* DELETE_OBJECT_KEY */:
|
|
7053
7067
|
case 3 /* UPDATE_OBJECT */:
|
|
7054
7068
|
case 5 /* DELETE_CRDT */: {
|
|
7055
|
-
const node = context.nodes.get(op.id);
|
|
7069
|
+
const node = context.pool.nodes.get(op.id);
|
|
7056
7070
|
if (node === void 0) {
|
|
7057
7071
|
return { modified: false };
|
|
7058
7072
|
}
|
|
7059
7073
|
return node._apply(op, source === 0 /* UNDOREDO_RECONNECT */);
|
|
7060
7074
|
}
|
|
7061
7075
|
case 1 /* SET_PARENT_KEY */: {
|
|
7062
|
-
const node = context.nodes.get(op.id);
|
|
7076
|
+
const node = context.pool.nodes.get(op.id);
|
|
7063
7077
|
if (node === void 0) {
|
|
7064
7078
|
return { modified: false };
|
|
7065
7079
|
}
|
|
@@ -7079,7 +7093,7 @@ function createRoom(options, config) {
|
|
|
7079
7093
|
if (op.parentId === void 0) {
|
|
7080
7094
|
return { modified: false };
|
|
7081
7095
|
}
|
|
7082
|
-
const parentNode = context.nodes.get(op.parentId);
|
|
7096
|
+
const parentNode = context.pool.nodes.get(op.parentId);
|
|
7083
7097
|
if (parentNode === void 0) {
|
|
7084
7098
|
return { modified: false };
|
|
7085
7099
|
}
|
|
@@ -7800,7 +7814,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7800
7814
|
},
|
|
7801
7815
|
// prettier-ignore
|
|
7802
7816
|
get nodeCount() {
|
|
7803
|
-
return context.nodes.size;
|
|
7817
|
+
return context.pool.nodes.size;
|
|
7804
7818
|
},
|
|
7805
7819
|
// prettier-ignore
|
|
7806
7820
|
getYjsProvider() {
|
|
@@ -7840,9 +7854,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7840
7854
|
},
|
|
7841
7855
|
attachmentUrlsStore: httpClient.getOrCreateAttachmentUrlsStore(roomId)
|
|
7842
7856
|
},
|
|
7843
|
-
id:
|
|
7857
|
+
id: roomId,
|
|
7844
7858
|
subscribe: makeClassicSubscribeFn(
|
|
7845
|
-
|
|
7859
|
+
roomId,
|
|
7846
7860
|
events,
|
|
7847
7861
|
config.errorEventSource
|
|
7848
7862
|
),
|
|
@@ -9030,6 +9044,15 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
9030
9044
|
}
|
|
9031
9045
|
}
|
|
9032
9046
|
|
|
9047
|
+
// src/lib/abortController.ts
|
|
9048
|
+
function makeAbortController(externalSignal) {
|
|
9049
|
+
const ctl = new AbortController();
|
|
9050
|
+
return {
|
|
9051
|
+
signal: externalSignal ? AbortSignal.any([ctl.signal, externalSignal]) : ctl.signal,
|
|
9052
|
+
abort: ctl.abort.bind(ctl)
|
|
9053
|
+
};
|
|
9054
|
+
}
|
|
9055
|
+
|
|
9033
9056
|
// src/lib/deprecation.ts
|
|
9034
9057
|
var _emittedDeprecationWarnings = /* @__PURE__ */ new Set();
|
|
9035
9058
|
function deprecate(message, key = message) {
|
|
@@ -9279,6 +9302,7 @@ var SortedList = class _SortedList {
|
|
|
9279
9302
|
var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
|
|
9280
9303
|
TextEditorType2["Lexical"] = "lexical";
|
|
9281
9304
|
TextEditorType2["TipTap"] = "tiptap";
|
|
9305
|
+
TextEditorType2["BlockNote"] = "blocknote";
|
|
9282
9306
|
return TextEditorType2;
|
|
9283
9307
|
})(TextEditorType || {});
|
|
9284
9308
|
|
|
@@ -9314,6 +9338,7 @@ export {
|
|
|
9314
9338
|
autoRetry,
|
|
9315
9339
|
b64decode,
|
|
9316
9340
|
batch,
|
|
9341
|
+
checkBounds,
|
|
9317
9342
|
chunk,
|
|
9318
9343
|
cloneLson,
|
|
9319
9344
|
compactObject,
|
|
@@ -9326,6 +9351,7 @@ export {
|
|
|
9326
9351
|
createCommentAttachmentId,
|
|
9327
9352
|
createCommentId,
|
|
9328
9353
|
createInboxNotificationId,
|
|
9354
|
+
createManagedPool,
|
|
9329
9355
|
createThreadId,
|
|
9330
9356
|
createUserNotificationSettings,
|
|
9331
9357
|
deprecate,
|
|
@@ -9354,6 +9380,7 @@ export {
|
|
|
9354
9380
|
keys,
|
|
9355
9381
|
legacy_patchImmutableObject,
|
|
9356
9382
|
lsonToJson,
|
|
9383
|
+
makeAbortController,
|
|
9357
9384
|
makeEventSource,
|
|
9358
9385
|
makePoller,
|
|
9359
9386
|
makePosition,
|