@liveblocks/core 2.0.3 → 2.0.4

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.mjs 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.0.3";
9
+ var PKG_VERSION = "2.0.4";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -5212,6 +5212,11 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5212
5212
  });
5213
5213
  return convertToThreadData(thread);
5214
5214
  }
5215
+ async function deleteThread({ threadId }) {
5216
+ await fetchJson(`/threads/${encodeURIComponent(threadId)}`, {
5217
+ method: "DELETE"
5218
+ });
5219
+ }
5215
5220
  async function editThreadMetadata({
5216
5221
  metadata,
5217
5222
  threadId
@@ -5318,6 +5323,7 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5318
5323
  getThreads,
5319
5324
  getThread,
5320
5325
  createThread,
5326
+ deleteThread,
5321
5327
  editThreadMetadata,
5322
5328
  createComment,
5323
5329
  editComment,
@@ -5688,10 +5694,17 @@ function createRoom(options, config) {
5688
5694
  } else {
5689
5695
  context.root = LiveObject._fromItems(message.items, pool);
5690
5696
  }
5697
+ const canWrite = self.current?.canWrite ?? true;
5691
5698
  const stackSizeBefore = context.undoStack.length;
5692
5699
  for (const key in context.initialStorage) {
5693
5700
  if (context.root.get(key) === void 0) {
5694
- context.root.set(key, cloneLson(context.initialStorage[key]));
5701
+ if (canWrite) {
5702
+ context.root.set(key, cloneLson(context.initialStorage[key]));
5703
+ } else {
5704
+ warn(
5705
+ `Attempted to populate missing storage key '${key}', but current user has no write access`
5706
+ );
5707
+ }
5695
5708
  }
5696
5709
  }
5697
5710
  context.undoStack.length = stackSizeBefore;
@@ -6894,6 +6907,19 @@ function applyOptimisticUpdates(state) {
6894
6907
  );
6895
6908
  break;
6896
6909
  }
6910
+ case "delete-thread": {
6911
+ const thread = result.threads[optimisticUpdate.threadId];
6912
+ if (thread === void 0) {
6913
+ break;
6914
+ }
6915
+ result.threads[optimisticUpdate.threadId] = {
6916
+ ...result.threads[optimisticUpdate.threadId],
6917
+ deletedAt: optimisticUpdate.deletedAt,
6918
+ updatedAt: optimisticUpdate.deletedAt,
6919
+ comments: []
6920
+ };
6921
+ break;
6922
+ }
6897
6923
  case "add-reaction": {
6898
6924
  const thread = result.threads[optimisticUpdate.threadId];
6899
6925
  if (thread === void 0) {