@liveblocks/core 2.7.0-versions2 → 2.7.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.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.7.0-versions2";
9
+ var PKG_VERSION = "2.7.1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -590,6 +590,18 @@ function isPlainObject(blob) {
590
590
  function entries(obj) {
591
591
  return Object.entries(obj);
592
592
  }
593
+ function mapValues(obj, mapFn) {
594
+ const result = {};
595
+ for (const pair of Object.entries(obj)) {
596
+ const key = pair[0];
597
+ if (key === "__proto__") {
598
+ continue;
599
+ }
600
+ const value = pair[1];
601
+ result[key] = mapFn(value, key);
602
+ }
603
+ return result;
604
+ }
593
605
  function tryParseJson(rawMessage) {
594
606
  try {
595
607
  return JSON.parse(rawMessage);
@@ -1899,24 +1911,47 @@ function createBatchStore(callback, options) {
1899
1911
 
1900
1912
  // src/lib/create-store.ts
1901
1913
  function createStore(initialState) {
1914
+ let notifyImmediately = true;
1915
+ let dirty = false;
1902
1916
  let state = initialState;
1903
1917
  const subscribers = /* @__PURE__ */ new Set();
1904
1918
  function get() {
1905
1919
  return state;
1906
1920
  }
1907
1921
  function set(callback) {
1908
- const newState = callback(state);
1909
- if (state === newState) {
1922
+ const oldState = state;
1923
+ const newState = callback(oldState);
1924
+ if (newState !== oldState) {
1925
+ state = newState;
1926
+ dirty = true;
1927
+ }
1928
+ if (notifyImmediately) {
1929
+ notify();
1930
+ }
1931
+ }
1932
+ function notify() {
1933
+ if (!dirty) {
1910
1934
  return;
1911
1935
  }
1912
- state = newState;
1936
+ dirty = false;
1913
1937
  for (const subscriber of subscribers) {
1914
1938
  subscriber(state);
1915
1939
  }
1916
1940
  }
1941
+ function batch(cb) {
1942
+ if (notifyImmediately === false) {
1943
+ return cb();
1944
+ }
1945
+ notifyImmediately = false;
1946
+ try {
1947
+ cb();
1948
+ } finally {
1949
+ notifyImmediately = true;
1950
+ notify();
1951
+ }
1952
+ }
1917
1953
  function subscribe(callback) {
1918
1954
  subscribers.add(callback);
1919
- callback(state);
1920
1955
  return () => {
1921
1956
  subscribers.delete(callback);
1922
1957
  };
@@ -1924,6 +1959,7 @@ function createStore(initialState) {
1924
1959
  return {
1925
1960
  get,
1926
1961
  set,
1962
+ batch,
1927
1963
  subscribe
1928
1964
  };
1929
1965
  }
@@ -2152,8 +2188,14 @@ function createNotificationsApi({
2152
2188
  }
2153
2189
  );
2154
2190
  }
2155
- async function getThreads() {
2156
- const json = await fetchJson("/threads", void 0, {});
2191
+ async function getThreads(options) {
2192
+ let query;
2193
+ if (_optionalChain([options, 'optionalAccess', _46 => _46.query])) {
2194
+ query = objectToQuery(options.query);
2195
+ }
2196
+ const json = await fetchJson("/threads", void 0, {
2197
+ query
2198
+ });
2157
2199
  return {
2158
2200
  threads: json.threads.map(convertToThreadData),
2159
2201
  inboxNotifications: json.inboxNotifications.map(
@@ -2163,8 +2205,13 @@ function createNotificationsApi({
2163
2205
  };
2164
2206
  }
2165
2207
  async function getThreadsSince(options) {
2208
+ let query;
2209
+ if (_optionalChain([options, 'optionalAccess', _47 => _47.query])) {
2210
+ query = objectToQuery(options.query);
2211
+ }
2166
2212
  const json = await fetchJson("/threads", void 0, {
2167
- since: options.since.toISOString()
2213
+ since: options.since.toISOString(),
2214
+ query
2168
2215
  });
2169
2216
  return {
2170
2217
  threads: {
@@ -2562,7 +2609,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
2562
2609
  return [
2563
2610
  {
2564
2611
  type: 8 /* CREATE_REGISTER */,
2565
- opId: _optionalChain([pool, 'optionalAccess', _46 => _46.generateOpId, 'call', _47 => _47()]),
2612
+ opId: _optionalChain([pool, 'optionalAccess', _48 => _48.generateOpId, 'call', _49 => _49()]),
2566
2613
  id: this._id,
2567
2614
  parentId,
2568
2615
  parentKey,
@@ -2664,7 +2711,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2664
2711
  const ops = [];
2665
2712
  const op = {
2666
2713
  id: this._id,
2667
- opId: _optionalChain([pool, 'optionalAccess', _48 => _48.generateOpId, 'call', _49 => _49()]),
2714
+ opId: _optionalChain([pool, 'optionalAccess', _50 => _50.generateOpId, 'call', _51 => _51()]),
2668
2715
  type: 2 /* CREATE_LIST */,
2669
2716
  parentId,
2670
2717
  parentKey
@@ -2941,7 +2988,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2941
2988
  _applyInsertUndoRedo(op) {
2942
2989
  const { id, parentKey: key } = op;
2943
2990
  const child = creationOpToLiveNode(op);
2944
- if (_optionalChain([this, 'access', _50 => _50._pool, 'optionalAccess', _51 => _51.getNode, 'call', _52 => _52(id)]) !== void 0) {
2991
+ if (_optionalChain([this, 'access', _52 => _52._pool, 'optionalAccess', _53 => _53.getNode, 'call', _54 => _54(id)]) !== void 0) {
2945
2992
  return { modified: false };
2946
2993
  }
2947
2994
  child._attach(id, nn(this._pool));
@@ -2949,8 +2996,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
2949
2996
  const existingItemIndex = this._indexOfPosition(key);
2950
2997
  let newKey = key;
2951
2998
  if (existingItemIndex !== -1) {
2952
- const before2 = _optionalChain([this, 'access', _53 => _53._items, 'access', _54 => _54[existingItemIndex], 'optionalAccess', _55 => _55._parentPos]);
2953
- const after2 = _optionalChain([this, 'access', _56 => _56._items, 'access', _57 => _57[existingItemIndex + 1], 'optionalAccess', _58 => _58._parentPos]);
2999
+ const before2 = _optionalChain([this, 'access', _55 => _55._items, 'access', _56 => _56[existingItemIndex], 'optionalAccess', _57 => _57._parentPos]);
3000
+ const after2 = _optionalChain([this, 'access', _58 => _58._items, 'access', _59 => _59[existingItemIndex + 1], 'optionalAccess', _60 => _60._parentPos]);
2954
3001
  newKey = makePosition(before2, after2);
2955
3002
  child._setParentLink(this, newKey);
2956
3003
  }
@@ -2965,7 +3012,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2965
3012
  _applySetUndoRedo(op) {
2966
3013
  const { id, parentKey: key } = op;
2967
3014
  const child = creationOpToLiveNode(op);
2968
- if (_optionalChain([this, 'access', _59 => _59._pool, 'optionalAccess', _60 => _60.getNode, 'call', _61 => _61(id)]) !== void 0) {
3015
+ if (_optionalChain([this, 'access', _61 => _61._pool, 'optionalAccess', _62 => _62.getNode, 'call', _63 => _63(id)]) !== void 0) {
2969
3016
  return { modified: false };
2970
3017
  }
2971
3018
  this._unacknowledgedSets.set(key, nn(op.opId));
@@ -3087,7 +3134,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3087
3134
  } else {
3088
3135
  this._items[existingItemIndex]._setParentLink(
3089
3136
  this,
3090
- makePosition(newKey, _optionalChain([this, 'access', _62 => _62._items, 'access', _63 => _63[existingItemIndex + 1], 'optionalAccess', _64 => _64._parentPos]))
3137
+ makePosition(newKey, _optionalChain([this, 'access', _64 => _64._items, 'access', _65 => _65[existingItemIndex + 1], 'optionalAccess', _66 => _66._parentPos]))
3091
3138
  );
3092
3139
  const previousIndex = this._items.indexOf(child);
3093
3140
  child._setParentLink(this, newKey);
@@ -3113,7 +3160,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3113
3160
  if (existingItemIndex !== -1) {
3114
3161
  this._items[existingItemIndex]._setParentLink(
3115
3162
  this,
3116
- makePosition(newKey, _optionalChain([this, 'access', _65 => _65._items, 'access', _66 => _66[existingItemIndex + 1], 'optionalAccess', _67 => _67._parentPos]))
3163
+ makePosition(newKey, _optionalChain([this, 'access', _67 => _67._items, 'access', _68 => _68[existingItemIndex + 1], 'optionalAccess', _69 => _69._parentPos]))
3117
3164
  );
3118
3165
  }
3119
3166
  child._setParentLink(this, newKey);
@@ -3132,7 +3179,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3132
3179
  if (existingItemIndex !== -1) {
3133
3180
  this._items[existingItemIndex]._setParentLink(
3134
3181
  this,
3135
- makePosition(newKey, _optionalChain([this, 'access', _68 => _68._items, 'access', _69 => _69[existingItemIndex + 1], 'optionalAccess', _70 => _70._parentPos]))
3182
+ makePosition(newKey, _optionalChain([this, 'access', _70 => _70._items, 'access', _71 => _71[existingItemIndex + 1], 'optionalAccess', _72 => _72._parentPos]))
3136
3183
  );
3137
3184
  }
3138
3185
  child._setParentLink(this, newKey);
@@ -3160,7 +3207,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3160
3207
  if (existingItemIndex !== -1) {
3161
3208
  this._items[existingItemIndex]._setParentLink(
3162
3209
  this,
3163
- makePosition(newKey, _optionalChain([this, 'access', _71 => _71._items, 'access', _72 => _72[existingItemIndex + 1], 'optionalAccess', _73 => _73._parentPos]))
3210
+ makePosition(newKey, _optionalChain([this, 'access', _73 => _73._items, 'access', _74 => _74[existingItemIndex + 1], 'optionalAccess', _75 => _75._parentPos]))
3164
3211
  );
3165
3212
  }
3166
3213
  child._setParentLink(this, newKey);
@@ -3218,7 +3265,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3218
3265
  * @param element The element to add to the end of the LiveList.
3219
3266
  */
3220
3267
  push(element) {
3221
- _optionalChain([this, 'access', _74 => _74._pool, 'optionalAccess', _75 => _75.assertStorageIsWritable, 'call', _76 => _76()]);
3268
+ _optionalChain([this, 'access', _76 => _76._pool, 'optionalAccess', _77 => _77.assertStorageIsWritable, 'call', _78 => _78()]);
3222
3269
  return this.insert(element, this.length);
3223
3270
  }
3224
3271
  /**
@@ -3227,7 +3274,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3227
3274
  * @param index The index at which you want to insert the element.
3228
3275
  */
3229
3276
  insert(element, index) {
3230
- _optionalChain([this, 'access', _77 => _77._pool, 'optionalAccess', _78 => _78.assertStorageIsWritable, 'call', _79 => _79()]);
3277
+ _optionalChain([this, 'access', _79 => _79._pool, 'optionalAccess', _80 => _80.assertStorageIsWritable, 'call', _81 => _81()]);
3231
3278
  if (index < 0 || index > this._items.length) {
3232
3279
  throw new Error(
3233
3280
  `Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
@@ -3257,7 +3304,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3257
3304
  * @param targetIndex The index where the element should be after moving.
3258
3305
  */
3259
3306
  move(index, targetIndex) {
3260
- _optionalChain([this, 'access', _80 => _80._pool, 'optionalAccess', _81 => _81.assertStorageIsWritable, 'call', _82 => _82()]);
3307
+ _optionalChain([this, 'access', _82 => _82._pool, 'optionalAccess', _83 => _83.assertStorageIsWritable, 'call', _84 => _84()]);
3261
3308
  if (targetIndex < 0) {
3262
3309
  throw new Error("targetIndex cannot be less than 0");
3263
3310
  }
@@ -3315,7 +3362,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3315
3362
  * @param index The index of the element to delete
3316
3363
  */
3317
3364
  delete(index) {
3318
- _optionalChain([this, 'access', _83 => _83._pool, 'optionalAccess', _84 => _84.assertStorageIsWritable, 'call', _85 => _85()]);
3365
+ _optionalChain([this, 'access', _85 => _85._pool, 'optionalAccess', _86 => _86.assertStorageIsWritable, 'call', _87 => _87()]);
3319
3366
  if (index < 0 || index >= this._items.length) {
3320
3367
  throw new Error(
3321
3368
  `Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
@@ -3348,7 +3395,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3348
3395
  }
3349
3396
  }
3350
3397
  clear() {
3351
- _optionalChain([this, 'access', _86 => _86._pool, 'optionalAccess', _87 => _87.assertStorageIsWritable, 'call', _88 => _88()]);
3398
+ _optionalChain([this, 'access', _88 => _88._pool, 'optionalAccess', _89 => _89.assertStorageIsWritable, 'call', _90 => _90()]);
3352
3399
  if (this._pool) {
3353
3400
  const ops = [];
3354
3401
  const reverseOps = [];
@@ -3382,7 +3429,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3382
3429
  }
3383
3430
  }
3384
3431
  set(index, item) {
3385
- _optionalChain([this, 'access', _89 => _89._pool, 'optionalAccess', _90 => _90.assertStorageIsWritable, 'call', _91 => _91()]);
3432
+ _optionalChain([this, 'access', _91 => _91._pool, 'optionalAccess', _92 => _92.assertStorageIsWritable, 'call', _93 => _93()]);
3386
3433
  if (index < 0 || index >= this._items.length) {
3387
3434
  throw new Error(
3388
3435
  `Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
@@ -3530,7 +3577,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3530
3577
  _shiftItemPosition(index, key) {
3531
3578
  const shiftedPosition = makePosition(
3532
3579
  key,
3533
- this._items.length > index + 1 ? _optionalChain([this, 'access', _92 => _92._items, 'access', _93 => _93[index + 1], 'optionalAccess', _94 => _94._parentPos]) : void 0
3580
+ this._items.length > index + 1 ? _optionalChain([this, 'access', _94 => _94._items, 'access', _95 => _95[index + 1], 'optionalAccess', _96 => _96._parentPos]) : void 0
3534
3581
  );
3535
3582
  this._items[index]._setParentLink(this, shiftedPosition);
3536
3583
  }
@@ -3659,7 +3706,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
3659
3706
  const ops = [];
3660
3707
  const op = {
3661
3708
  id: this._id,
3662
- opId: _optionalChain([pool, 'optionalAccess', _95 => _95.generateOpId, 'call', _96 => _96()]),
3709
+ opId: _optionalChain([pool, 'optionalAccess', _97 => _97.generateOpId, 'call', _98 => _98()]),
3663
3710
  type: 7 /* CREATE_MAP */,
3664
3711
  parentId,
3665
3712
  parentKey
@@ -3806,7 +3853,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
3806
3853
  * @param value The value of the element to add. Should be serializable to JSON.
3807
3854
  */
3808
3855
  set(key, value) {
3809
- _optionalChain([this, 'access', _97 => _97._pool, 'optionalAccess', _98 => _98.assertStorageIsWritable, 'call', _99 => _99()]);
3856
+ _optionalChain([this, 'access', _99 => _99._pool, 'optionalAccess', _100 => _100.assertStorageIsWritable, 'call', _101 => _101()]);
3810
3857
  const oldValue = this._map.get(key);
3811
3858
  if (oldValue) {
3812
3859
  oldValue._detach();
@@ -3852,7 +3899,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
3852
3899
  * @returns true if an element existed and has been removed, or false if the element does not exist.
3853
3900
  */
3854
3901
  delete(key) {
3855
- _optionalChain([this, 'access', _100 => _100._pool, 'optionalAccess', _101 => _101.assertStorageIsWritable, 'call', _102 => _102()]);
3902
+ _optionalChain([this, 'access', _102 => _102._pool, 'optionalAccess', _103 => _103.assertStorageIsWritable, 'call', _104 => _104()]);
3856
3903
  const item = this._map.get(key);
3857
3904
  if (item === void 0) {
3858
3905
  return false;
@@ -4030,7 +4077,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
4030
4077
  if (this._id === void 0) {
4031
4078
  throw new Error("Cannot serialize item is not attached");
4032
4079
  }
4033
- const opId = _optionalChain([pool, 'optionalAccess', _103 => _103.generateOpId, 'call', _104 => _104()]);
4080
+ const opId = _optionalChain([pool, 'optionalAccess', _105 => _105.generateOpId, 'call', _106 => _106()]);
4034
4081
  const ops = [];
4035
4082
  const op = {
4036
4083
  type: 4 /* CREATE_OBJECT */,
@@ -4308,7 +4355,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
4308
4355
  * @param value The value of the property to add
4309
4356
  */
4310
4357
  set(key, value) {
4311
- _optionalChain([this, 'access', _105 => _105._pool, 'optionalAccess', _106 => _106.assertStorageIsWritable, 'call', _107 => _107()]);
4358
+ _optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.assertStorageIsWritable, 'call', _109 => _109()]);
4312
4359
  this.update({ [key]: value });
4313
4360
  }
4314
4361
  /**
@@ -4323,7 +4370,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
4323
4370
  * @param key The key of the property to delete
4324
4371
  */
4325
4372
  delete(key) {
4326
- _optionalChain([this, 'access', _108 => _108._pool, 'optionalAccess', _109 => _109.assertStorageIsWritable, 'call', _110 => _110()]);
4373
+ _optionalChain([this, 'access', _110 => _110._pool, 'optionalAccess', _111 => _111.assertStorageIsWritable, 'call', _112 => _112()]);
4327
4374
  const keyAsString = key;
4328
4375
  const oldValue = this._map.get(keyAsString);
4329
4376
  if (oldValue === void 0) {
@@ -4376,7 +4423,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
4376
4423
  * @param patch The object used to overrides properties
4377
4424
  */
4378
4425
  update(patch) {
4379
- _optionalChain([this, 'access', _111 => _111._pool, 'optionalAccess', _112 => _112.assertStorageIsWritable, 'call', _113 => _113()]);
4426
+ _optionalChain([this, 'access', _113 => _113._pool, 'optionalAccess', _114 => _114.assertStorageIsWritable, 'call', _115 => _115()]);
4380
4427
  if (this._pool === void 0 || this._id === void 0) {
4381
4428
  for (const key in patch) {
4382
4429
  const newValue = patch[key];
@@ -5152,15 +5199,15 @@ function installBackgroundTabSpy() {
5152
5199
  const doc = typeof document !== "undefined" ? document : void 0;
5153
5200
  const inBackgroundSince = { current: null };
5154
5201
  function onVisibilityChange() {
5155
- if (_optionalChain([doc, 'optionalAccess', _114 => _114.visibilityState]) === "hidden") {
5202
+ if (_optionalChain([doc, 'optionalAccess', _116 => _116.visibilityState]) === "hidden") {
5156
5203
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
5157
5204
  } else {
5158
5205
  inBackgroundSince.current = null;
5159
5206
  }
5160
5207
  }
5161
- _optionalChain([doc, 'optionalAccess', _115 => _115.addEventListener, 'call', _116 => _116("visibilitychange", onVisibilityChange)]);
5208
+ _optionalChain([doc, 'optionalAccess', _117 => _117.addEventListener, 'call', _118 => _118("visibilitychange", onVisibilityChange)]);
5162
5209
  const unsub = () => {
5163
- _optionalChain([doc, 'optionalAccess', _117 => _117.removeEventListener, 'call', _118 => _118("visibilitychange", onVisibilityChange)]);
5210
+ _optionalChain([doc, 'optionalAccess', _119 => _119.removeEventListener, 'call', _120 => _120("visibilitychange", onVisibilityChange)]);
5164
5211
  };
5165
5212
  return [inBackgroundSince, unsub];
5166
5213
  }
@@ -5363,7 +5410,7 @@ function createRoom(options, config) {
5363
5410
  }
5364
5411
  },
5365
5412
  assertStorageIsWritable: () => {
5366
- const scopes = _optionalChain([context, 'access', _119 => _119.dynamicSessionInfo, 'access', _120 => _120.current, 'optionalAccess', _121 => _121.scopes]);
5413
+ const scopes = _optionalChain([context, 'access', _121 => _121.dynamicSessionInfo, 'access', _122 => _122.current, 'optionalAccess', _123 => _123.scopes]);
5367
5414
  if (scopes === void 0) {
5368
5415
  return;
5369
5416
  }
@@ -5397,12 +5444,12 @@ function createRoom(options, config) {
5397
5444
  `/v2/c/rooms/${encodeURIComponent(roomId)}${endpoint}`,
5398
5445
  params
5399
5446
  );
5400
- const fetcher = _optionalChain([config, 'access', _122 => _122.polyfills, 'optionalAccess', _123 => _123.fetch]) || /* istanbul ignore next */
5447
+ const fetcher = _optionalChain([config, 'access', _124 => _124.polyfills, 'optionalAccess', _125 => _125.fetch]) || /* istanbul ignore next */
5401
5448
  fetch;
5402
5449
  return await fetcher(url, {
5403
5450
  ...options2,
5404
5451
  headers: {
5405
- ..._optionalChain([options2, 'optionalAccess', _124 => _124.headers]),
5452
+ ..._optionalChain([options2, 'optionalAccess', _126 => _126.headers]),
5406
5453
  Authorization: `Bearer ${getAuthBearerHeaderFromAuthValue(authValue)}`
5407
5454
  }
5408
5455
  });
@@ -5498,7 +5545,7 @@ function createRoom(options, config) {
5498
5545
  }
5499
5546
  function sendMessages(messages) {
5500
5547
  const serializedPayload = JSON.stringify(messages);
5501
- const nonce = _optionalChain([context, 'access', _125 => _125.dynamicSessionInfo, 'access', _126 => _126.current, 'optionalAccess', _127 => _127.nonce]);
5548
+ const nonce = _optionalChain([context, 'access', _127 => _127.dynamicSessionInfo, 'access', _128 => _128.current, 'optionalAccess', _129 => _129.nonce]);
5502
5549
  if (config.unstable_fallbackToHTTP && nonce) {
5503
5550
  const size = new TextEncoder().encode(serializedPayload).length;
5504
5551
  if (size > MAX_SOCKET_MESSAGE_SIZE) {
@@ -5560,7 +5607,7 @@ function createRoom(options, config) {
5560
5607
  } else {
5561
5608
  context.root = LiveObject._fromItems(message.items, pool);
5562
5609
  }
5563
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _128 => _128.current, 'optionalAccess', _129 => _129.canWrite]), () => ( true));
5610
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _130 => _130.current, 'optionalAccess', _131 => _131.canWrite]), () => ( true));
5564
5611
  const stackSizeBefore = context.undoStack.length;
5565
5612
  for (const key in context.initialStorage) {
5566
5613
  if (context.root.get(key) === void 0) {
@@ -5765,7 +5812,7 @@ function createRoom(options, config) {
5765
5812
  }
5766
5813
  context.myPresence.patch(patch);
5767
5814
  if (context.activeBatch) {
5768
- if (_optionalChain([options2, 'optionalAccess', _130 => _130.addToHistory])) {
5815
+ if (_optionalChain([options2, 'optionalAccess', _132 => _132.addToHistory])) {
5769
5816
  context.activeBatch.reverseOps.unshift({
5770
5817
  type: "presence",
5771
5818
  data: oldValues
@@ -5775,7 +5822,7 @@ function createRoom(options, config) {
5775
5822
  } else {
5776
5823
  flushNowOrSoon();
5777
5824
  batchUpdates(() => {
5778
- if (_optionalChain([options2, 'optionalAccess', _131 => _131.addToHistory])) {
5825
+ if (_optionalChain([options2, 'optionalAccess', _133 => _133.addToHistory])) {
5779
5826
  addToUndoStack(
5780
5827
  [{ type: "presence", data: oldValues }],
5781
5828
  doNotBatchUpdates
@@ -5973,7 +6020,7 @@ function createRoom(options, config) {
5973
6020
  if (process.env.NODE_ENV !== "production") {
5974
6021
  const traces = /* @__PURE__ */ new Set();
5975
6022
  for (const opId of message.opIds) {
5976
- const trace = _optionalChain([context, 'access', _132 => _132.opStackTraces, 'optionalAccess', _133 => _133.get, 'call', _134 => _134(opId)]);
6023
+ const trace = _optionalChain([context, 'access', _134 => _134.opStackTraces, 'optionalAccess', _135 => _135.get, 'call', _136 => _136(opId)]);
5977
6024
  if (trace) {
5978
6025
  traces.add(trace);
5979
6026
  }
@@ -6107,7 +6154,7 @@ ${Array.from(traces).join("\n\n")}`
6107
6154
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
6108
6155
  createOrUpdateRootFromMessage(message, doNotBatchUpdates);
6109
6156
  applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
6110
- _optionalChain([_resolveStoragePromise, 'optionalCall', _135 => _135()]);
6157
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _137 => _137()]);
6111
6158
  notifyStorageStatus();
6112
6159
  eventHub.storageDidLoad.notify();
6113
6160
  }
@@ -6358,7 +6405,7 @@ ${Array.from(traces).join("\n\n")}`
6358
6405
  const response = await fetchCommentsApi(
6359
6406
  "/threads",
6360
6407
  {
6361
- since: _optionalChain([options2, 'optionalAccess', _136 => _136.since, 'optionalAccess', _137 => _137.toISOString, 'call', _138 => _138()])
6408
+ since: _optionalChain([options2, 'optionalAccess', _138 => _138.since, 'optionalAccess', _139 => _139.toISOString, 'call', _140 => _140()])
6362
6409
  },
6363
6410
  {
6364
6411
  headers: {
@@ -6399,7 +6446,7 @@ ${Array.from(traces).join("\n\n")}`
6399
6446
  }
6400
6447
  async function getThreads(options2) {
6401
6448
  let query;
6402
- if (_optionalChain([options2, 'optionalAccess', _139 => _139.query])) {
6449
+ if (_optionalChain([options2, 'optionalAccess', _141 => _141.query])) {
6403
6450
  query = objectToQuery(options2.query);
6404
6451
  }
6405
6452
  const response = await fetchCommentsApi(
@@ -6552,7 +6599,7 @@ ${Array.from(traces).join("\n\n")}`
6552
6599
  );
6553
6600
  return convertToCommentData(comment);
6554
6601
  }
6555
- async function deleteComment2({
6602
+ async function deleteComment({
6556
6603
  threadId,
6557
6604
  commentId
6558
6605
  }) {
@@ -6565,7 +6612,7 @@ ${Array.from(traces).join("\n\n")}`
6565
6612
  }
6566
6613
  );
6567
6614
  }
6568
- async function addReaction2({
6615
+ async function addReaction({
6569
6616
  threadId,
6570
6617
  commentId,
6571
6618
  emoji
@@ -6584,7 +6631,7 @@ ${Array.from(traces).join("\n\n")}`
6584
6631
  );
6585
6632
  return convertToCommentUserReaction(reaction);
6586
6633
  }
6587
- async function removeReaction2({
6634
+ async function removeReaction({
6588
6635
  threadId,
6589
6636
  commentId,
6590
6637
  emoji
@@ -6674,7 +6721,7 @@ ${Array.from(traces).join("\n\n")}`
6674
6721
  {
6675
6722
  [kInternal]: {
6676
6723
  get presenceBuffer() {
6677
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _140 => _140.buffer, 'access', _141 => _141.presenceUpdates, 'optionalAccess', _142 => _142.data]), () => ( null)));
6724
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _142 => _142.buffer, 'access', _143 => _143.presenceUpdates, 'optionalAccess', _144 => _144.data]), () => ( null)));
6678
6725
  },
6679
6726
  // prettier-ignore
6680
6727
  get undoStack() {
@@ -6765,9 +6812,9 @@ ${Array.from(traces).join("\n\n")}`
6765
6812
  markThreadAsUnresolved,
6766
6813
  createComment,
6767
6814
  editComment,
6768
- deleteComment: deleteComment2,
6769
- addReaction: addReaction2,
6770
- removeReaction: removeReaction2,
6815
+ deleteComment,
6816
+ addReaction,
6817
+ removeReaction,
6771
6818
  // Notifications
6772
6819
  getNotificationSettings,
6773
6820
  updateNotificationSettings,
@@ -6854,7 +6901,7 @@ function makeClassicSubscribeFn(events) {
6854
6901
  }
6855
6902
  if (isLiveNode(first)) {
6856
6903
  const node = first;
6857
- if (_optionalChain([options, 'optionalAccess', _143 => _143.isDeep])) {
6904
+ if (_optionalChain([options, 'optionalAccess', _145 => _145.isDeep])) {
6858
6905
  const storageCallback = second;
6859
6906
  return subscribeToLiveStructureDeeply(node, storageCallback);
6860
6907
  } else {
@@ -6900,533 +6947,6 @@ function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
6900
6947
  };
6901
6948
  }
6902
6949
 
6903
- // src/store.ts
6904
- function createClientStore() {
6905
- const store = createStore({
6906
- threads: {},
6907
- queries: {},
6908
- optimisticUpdates: [],
6909
- inboxNotifications: {},
6910
- notificationSettings: {},
6911
- versions: {}
6912
- });
6913
- const optimisticUpdatesEventSource = makeEventSource();
6914
- return {
6915
- ...store,
6916
- deleteThread(threadId) {
6917
- store.set((state) => {
6918
- return {
6919
- ...state,
6920
- threads: deleteKeyImmutable(state.threads, threadId),
6921
- inboxNotifications: Object.fromEntries(
6922
- Object.entries(state.inboxNotifications).filter(
6923
- ([_id, notification]) => notification.kind === "thread" && notification.threadId === threadId
6924
- )
6925
- )
6926
- };
6927
- });
6928
- },
6929
- updateThreadAndNotification(thread, inboxNotification) {
6930
- store.set((state) => {
6931
- const existingThread = state.threads[thread.id];
6932
- return {
6933
- ...state,
6934
- threads: existingThread === void 0 || compareThreads(thread, existingThread) === 1 ? { ...state.threads, [thread.id]: thread } : state.threads,
6935
- inboxNotifications: inboxNotification === void 0 ? state.inboxNotifications : {
6936
- ...state.inboxNotifications,
6937
- [inboxNotification.id]: inboxNotification
6938
- }
6939
- };
6940
- });
6941
- },
6942
- updateRoomVersions(roomId, versions, queryKey) {
6943
- store.set((state) => ({
6944
- ...state,
6945
- versions: {
6946
- ...state.versions,
6947
- [roomId]: versions
6948
- },
6949
- queries: queryKey !== void 0 ? {
6950
- ...state.queries,
6951
- [queryKey]: { isLoading: false, data: void 0 }
6952
- } : state.queries
6953
- }));
6954
- },
6955
- updateThreadsAndNotifications(threads, inboxNotifications, deletedThreads, deletedInboxNotifications, queryKey) {
6956
- store.set((state) => ({
6957
- ...state,
6958
- threads: applyThreadUpdates(state.threads, {
6959
- newThreads: threads,
6960
- deletedThreads
6961
- }),
6962
- inboxNotifications: applyNotificationsUpdates(
6963
- state.inboxNotifications,
6964
- {
6965
- newInboxNotifications: inboxNotifications,
6966
- deletedNotifications: deletedInboxNotifications
6967
- }
6968
- ),
6969
- queries: queryKey !== void 0 ? {
6970
- ...state.queries,
6971
- [queryKey]: { isLoading: false, data: void 0 }
6972
- } : state.queries
6973
- }));
6974
- },
6975
- updateRoomInboxNotificationSettings(roomId, settings, queryKey) {
6976
- store.set((state) => ({
6977
- ...state,
6978
- notificationSettings: {
6979
- ...state.notificationSettings,
6980
- [roomId]: settings
6981
- },
6982
- queries: {
6983
- ...state.queries,
6984
- [queryKey]: { isLoading: false, data: void 0 }
6985
- }
6986
- }));
6987
- },
6988
- pushOptimisticUpdate(optimisticUpdate) {
6989
- optimisticUpdatesEventSource.notify(optimisticUpdate);
6990
- store.set((state) => ({
6991
- ...state,
6992
- optimisticUpdates: [...state.optimisticUpdates, optimisticUpdate]
6993
- }));
6994
- },
6995
- setQueryState(queryKey, queryState) {
6996
- store.set((state) => ({
6997
- ...state,
6998
- queries: {
6999
- ...state.queries,
7000
- [queryKey]: queryState
7001
- }
7002
- }));
7003
- },
7004
- optimisticUpdatesEventSource
7005
- };
7006
- }
7007
- function deleteKeyImmutable(record, key) {
7008
- if (Object.prototype.hasOwnProperty.call(record, key)) {
7009
- const { [key]: _toDelete, ...rest } = record;
7010
- return rest;
7011
- }
7012
- return record;
7013
- }
7014
- function compareThreads(thread1, thread2) {
7015
- if (thread1.updatedAt && thread2.updatedAt) {
7016
- return thread1.updatedAt > thread2.updatedAt ? 1 : thread1.updatedAt < thread2.updatedAt ? -1 : 0;
7017
- } else if (thread1.updatedAt || thread2.updatedAt) {
7018
- return thread1.updatedAt ? 1 : -1;
7019
- }
7020
- if (thread1.createdAt > thread2.createdAt) {
7021
- return 1;
7022
- } else if (thread1.createdAt < thread2.createdAt) {
7023
- return -1;
7024
- }
7025
- return 0;
7026
- }
7027
- function applyOptimisticUpdates(state) {
7028
- const result = {
7029
- threads: {
7030
- ...state.threads
7031
- },
7032
- inboxNotifications: {
7033
- ...state.inboxNotifications
7034
- },
7035
- notificationSettings: {
7036
- ...state.notificationSettings
7037
- }
7038
- };
7039
- for (const optimisticUpdate of state.optimisticUpdates) {
7040
- switch (optimisticUpdate.type) {
7041
- case "create-thread": {
7042
- result.threads[optimisticUpdate.thread.id] = optimisticUpdate.thread;
7043
- break;
7044
- }
7045
- case "edit-thread-metadata": {
7046
- const thread = result.threads[optimisticUpdate.threadId];
7047
- if (thread === void 0) {
7048
- break;
7049
- }
7050
- if (thread.deletedAt !== void 0) {
7051
- break;
7052
- }
7053
- if (thread.updatedAt !== void 0 && thread.updatedAt > optimisticUpdate.updatedAt) {
7054
- break;
7055
- }
7056
- result.threads[thread.id] = {
7057
- ...thread,
7058
- updatedAt: optimisticUpdate.updatedAt,
7059
- metadata: {
7060
- ...thread.metadata,
7061
- ...optimisticUpdate.metadata
7062
- }
7063
- };
7064
- break;
7065
- }
7066
- case "mark-thread-as-resolved": {
7067
- const thread = result.threads[optimisticUpdate.threadId];
7068
- if (thread === void 0) {
7069
- break;
7070
- }
7071
- if (thread.deletedAt !== void 0) {
7072
- break;
7073
- }
7074
- result.threads[thread.id] = {
7075
- ...thread,
7076
- resolved: true
7077
- };
7078
- break;
7079
- }
7080
- case "mark-thread-as-unresolved": {
7081
- const thread = result.threads[optimisticUpdate.threadId];
7082
- if (thread === void 0) {
7083
- break;
7084
- }
7085
- if (thread.deletedAt !== void 0) {
7086
- break;
7087
- }
7088
- result.threads[thread.id] = {
7089
- ...thread,
7090
- resolved: false
7091
- };
7092
- break;
7093
- }
7094
- case "create-comment": {
7095
- const thread = result.threads[optimisticUpdate.comment.threadId];
7096
- if (thread === void 0) {
7097
- break;
7098
- }
7099
- result.threads[thread.id] = upsertComment(
7100
- thread,
7101
- optimisticUpdate.comment
7102
- );
7103
- const inboxNotification = Object.values(result.inboxNotifications).find(
7104
- (notification) => notification.kind === "thread" && notification.threadId === thread.id
7105
- );
7106
- if (inboxNotification === void 0) {
7107
- break;
7108
- }
7109
- result.inboxNotifications[inboxNotification.id] = {
7110
- ...inboxNotification,
7111
- notifiedAt: optimisticUpdate.comment.createdAt,
7112
- readAt: optimisticUpdate.comment.createdAt
7113
- };
7114
- break;
7115
- }
7116
- case "edit-comment": {
7117
- const thread = result.threads[optimisticUpdate.comment.threadId];
7118
- if (thread === void 0) {
7119
- break;
7120
- }
7121
- result.threads[thread.id] = upsertComment(
7122
- thread,
7123
- optimisticUpdate.comment
7124
- );
7125
- break;
7126
- }
7127
- case "delete-comment": {
7128
- const thread = result.threads[optimisticUpdate.threadId];
7129
- if (thread === void 0) {
7130
- break;
7131
- }
7132
- result.threads[thread.id] = deleteComment(
7133
- thread,
7134
- optimisticUpdate.commentId,
7135
- optimisticUpdate.deletedAt
7136
- );
7137
- break;
7138
- }
7139
- case "delete-thread": {
7140
- const thread = result.threads[optimisticUpdate.threadId];
7141
- if (thread === void 0) {
7142
- break;
7143
- }
7144
- result.threads[optimisticUpdate.threadId] = {
7145
- ...result.threads[optimisticUpdate.threadId],
7146
- deletedAt: optimisticUpdate.deletedAt,
7147
- updatedAt: optimisticUpdate.deletedAt,
7148
- comments: []
7149
- };
7150
- break;
7151
- }
7152
- case "add-reaction": {
7153
- const thread = result.threads[optimisticUpdate.threadId];
7154
- if (thread === void 0) {
7155
- break;
7156
- }
7157
- result.threads[thread.id] = addReaction(
7158
- thread,
7159
- optimisticUpdate.commentId,
7160
- optimisticUpdate.reaction
7161
- );
7162
- break;
7163
- }
7164
- case "remove-reaction": {
7165
- const thread = result.threads[optimisticUpdate.threadId];
7166
- if (thread === void 0) {
7167
- break;
7168
- }
7169
- result.threads[thread.id] = removeReaction(
7170
- thread,
7171
- optimisticUpdate.commentId,
7172
- optimisticUpdate.emoji,
7173
- optimisticUpdate.userId,
7174
- optimisticUpdate.removedAt
7175
- );
7176
- break;
7177
- }
7178
- case "mark-inbox-notification-as-read": {
7179
- result.inboxNotifications[optimisticUpdate.inboxNotificationId] = {
7180
- ...state.inboxNotifications[optimisticUpdate.inboxNotificationId],
7181
- readAt: optimisticUpdate.readAt
7182
- };
7183
- break;
7184
- }
7185
- case "mark-all-inbox-notifications-as-read": {
7186
- for (const id in result.inboxNotifications) {
7187
- result.inboxNotifications[id] = {
7188
- ...result.inboxNotifications[id],
7189
- readAt: optimisticUpdate.readAt
7190
- };
7191
- }
7192
- break;
7193
- }
7194
- case "delete-inbox-notification": {
7195
- const {
7196
- [optimisticUpdate.inboxNotificationId]: _,
7197
- ...inboxNotifications
7198
- } = result.inboxNotifications;
7199
- result.inboxNotifications = inboxNotifications;
7200
- break;
7201
- }
7202
- case "delete-all-inbox-notifications": {
7203
- result.inboxNotifications = {};
7204
- break;
7205
- }
7206
- case "update-notification-settings": {
7207
- result.notificationSettings[optimisticUpdate.roomId] = {
7208
- ...result.notificationSettings[optimisticUpdate.roomId],
7209
- ...optimisticUpdate.settings
7210
- };
7211
- }
7212
- }
7213
- }
7214
- return result;
7215
- }
7216
- function applyThreadUpdates(existingThreads, updates) {
7217
- const updatedThreads = { ...existingThreads };
7218
- updates.newThreads.forEach((thread) => {
7219
- const existingThread = updatedThreads[thread.id];
7220
- if (existingThread) {
7221
- const result = compareThreads(existingThread, thread);
7222
- if (result === 1) return;
7223
- }
7224
- updatedThreads[thread.id] = thread;
7225
- });
7226
- updates.deletedThreads.forEach(({ id, deletedAt }) => {
7227
- const existingThread = updatedThreads[id];
7228
- if (existingThread === void 0) return;
7229
- existingThread.deletedAt = deletedAt;
7230
- existingThread.updatedAt = deletedAt;
7231
- existingThread.comments = [];
7232
- });
7233
- return updatedThreads;
7234
- }
7235
- function applyNotificationsUpdates(existingInboxNotifications, updates) {
7236
- const updatedInboxNotifications = { ...existingInboxNotifications };
7237
- updates.newInboxNotifications.forEach((notification) => {
7238
- const existingNotification = updatedInboxNotifications[notification.id];
7239
- if (existingNotification) {
7240
- const result = compareInboxNotifications(
7241
- existingNotification,
7242
- notification
7243
- );
7244
- if (result === 1) return;
7245
- }
7246
- updatedInboxNotifications[notification.id] = notification;
7247
- });
7248
- updates.deletedNotifications.forEach(
7249
- ({ id }) => delete updatedInboxNotifications[id]
7250
- );
7251
- return updatedInboxNotifications;
7252
- }
7253
- function compareInboxNotifications(inboxNotificationA, inboxNotificationB) {
7254
- if (inboxNotificationA.notifiedAt > inboxNotificationB.notifiedAt) {
7255
- return 1;
7256
- } else if (inboxNotificationA.notifiedAt < inboxNotificationB.notifiedAt) {
7257
- return -1;
7258
- }
7259
- if (inboxNotificationA.readAt && inboxNotificationB.readAt) {
7260
- return inboxNotificationA.readAt > inboxNotificationB.readAt ? 1 : inboxNotificationA.readAt < inboxNotificationB.readAt ? -1 : 0;
7261
- } else if (inboxNotificationA.readAt || inboxNotificationB.readAt) {
7262
- return inboxNotificationA.readAt ? 1 : -1;
7263
- }
7264
- return 0;
7265
- }
7266
- function upsertComment(thread, comment) {
7267
- if (thread.deletedAt !== void 0) {
7268
- return thread;
7269
- }
7270
- if (comment.threadId !== thread.id) {
7271
- warn(
7272
- `Comment ${comment.id} does not belong to thread ${thread.id}`
7273
- );
7274
- return thread;
7275
- }
7276
- const existingComment = thread.comments.find(
7277
- (existingComment2) => existingComment2.id === comment.id
7278
- );
7279
- if (existingComment === void 0) {
7280
- const updatedAt = new Date(
7281
- Math.max(_optionalChain([thread, 'access', _144 => _144.updatedAt, 'optionalAccess', _145 => _145.getTime, 'call', _146 => _146()]) || 0, comment.createdAt.getTime())
7282
- );
7283
- const updatedThread = {
7284
- ...thread,
7285
- updatedAt,
7286
- comments: [...thread.comments, comment]
7287
- };
7288
- return updatedThread;
7289
- }
7290
- if (existingComment.deletedAt !== void 0) {
7291
- return thread;
7292
- }
7293
- if (existingComment.editedAt === void 0 || comment.editedAt === void 0 || existingComment.editedAt <= comment.editedAt) {
7294
- const updatedComments = thread.comments.map(
7295
- (existingComment2) => existingComment2.id === comment.id ? comment : existingComment2
7296
- );
7297
- const updatedThread = {
7298
- ...thread,
7299
- updatedAt: new Date(
7300
- Math.max(
7301
- _optionalChain([thread, 'access', _147 => _147.updatedAt, 'optionalAccess', _148 => _148.getTime, 'call', _149 => _149()]) || 0,
7302
- _optionalChain([comment, 'access', _150 => _150.editedAt, 'optionalAccess', _151 => _151.getTime, 'call', _152 => _152()]) || comment.createdAt.getTime()
7303
- )
7304
- ),
7305
- comments: updatedComments
7306
- };
7307
- return updatedThread;
7308
- }
7309
- return thread;
7310
- }
7311
- function deleteComment(thread, commentId, deletedAt) {
7312
- if (thread.deletedAt !== void 0) {
7313
- return thread;
7314
- }
7315
- const existingComment = thread.comments.find(
7316
- (comment) => comment.id === commentId
7317
- );
7318
- if (existingComment === void 0) {
7319
- return thread;
7320
- }
7321
- if (existingComment.deletedAt !== void 0) {
7322
- return thread;
7323
- }
7324
- const updatedComments = thread.comments.map(
7325
- (comment) => comment.id === commentId ? {
7326
- ...comment,
7327
- deletedAt,
7328
- body: void 0
7329
- } : comment
7330
- );
7331
- if (!updatedComments.some((comment) => comment.deletedAt === void 0)) {
7332
- return {
7333
- ...thread,
7334
- deletedAt,
7335
- updatedAt: deletedAt,
7336
- comments: []
7337
- };
7338
- }
7339
- return {
7340
- ...thread,
7341
- updatedAt: deletedAt,
7342
- comments: updatedComments
7343
- };
7344
- }
7345
- function addReaction(thread, commentId, reaction) {
7346
- if (thread.deletedAt !== void 0) {
7347
- return thread;
7348
- }
7349
- const existingComment = thread.comments.find(
7350
- (comment) => comment.id === commentId
7351
- );
7352
- if (existingComment === void 0) {
7353
- return thread;
7354
- }
7355
- if (existingComment.deletedAt !== void 0) {
7356
- return thread;
7357
- }
7358
- const updatedComments = thread.comments.map(
7359
- (comment) => comment.id === commentId ? {
7360
- ...comment,
7361
- reactions: upsertReaction(comment.reactions, reaction)
7362
- } : comment
7363
- );
7364
- return {
7365
- ...thread,
7366
- updatedAt: new Date(
7367
- Math.max(reaction.createdAt.getTime(), _optionalChain([thread, 'access', _153 => _153.updatedAt, 'optionalAccess', _154 => _154.getTime, 'call', _155 => _155()]) || 0)
7368
- ),
7369
- comments: updatedComments
7370
- };
7371
- }
7372
- function removeReaction(thread, commentId, emoji, userId, removedAt) {
7373
- if (thread.deletedAt !== void 0) {
7374
- return thread;
7375
- }
7376
- const existingComment = thread.comments.find(
7377
- (comment) => comment.id === commentId
7378
- );
7379
- if (existingComment === void 0) {
7380
- return thread;
7381
- }
7382
- if (existingComment.deletedAt !== void 0) {
7383
- return thread;
7384
- }
7385
- const updatedComments = thread.comments.map(
7386
- (comment) => comment.id === commentId ? {
7387
- ...comment,
7388
- reactions: comment.reactions.map(
7389
- (reaction) => reaction.emoji === emoji ? {
7390
- ...reaction,
7391
- users: reaction.users.filter((user) => user.id !== userId)
7392
- } : reaction
7393
- ).filter((reaction) => reaction.users.length > 0)
7394
- // Remove reactions with no users left
7395
- } : comment
7396
- );
7397
- return {
7398
- ...thread,
7399
- updatedAt: new Date(
7400
- Math.max(removedAt.getTime(), _optionalChain([thread, 'access', _156 => _156.updatedAt, 'optionalAccess', _157 => _157.getTime, 'call', _158 => _158()]) || 0)
7401
- ),
7402
- comments: updatedComments
7403
- };
7404
- }
7405
- function upsertReaction(reactions, reaction) {
7406
- const existingReaction = reactions.find(
7407
- (existingReaction2) => existingReaction2.emoji === reaction.emoji
7408
- );
7409
- if (existingReaction === void 0) {
7410
- return [
7411
- ...reactions,
7412
- {
7413
- emoji: reaction.emoji,
7414
- createdAt: reaction.createdAt,
7415
- users: [{ id: reaction.userId }]
7416
- }
7417
- ];
7418
- }
7419
- if (existingReaction.users.some((user) => user.id === reaction.userId) === false) {
7420
- return reactions.map(
7421
- (existingReaction2) => existingReaction2.emoji === reaction.emoji ? {
7422
- ...existingReaction2,
7423
- users: [...existingReaction2.users, { id: reaction.userId }]
7424
- } : existingReaction2
7425
- );
7426
- }
7427
- return reactions;
7428
- }
7429
-
7430
6950
  // src/client.ts
7431
6951
  var MIN_THROTTLE = 16;
7432
6952
  var MAX_THROTTLE = 1e3;
@@ -7508,12 +7028,12 @@ function createClient(options) {
7508
7028
  createSocket: makeCreateSocketDelegateForRoom(
7509
7029
  roomId,
7510
7030
  baseUrl,
7511
- _optionalChain([clientOptions, 'access', _159 => _159.polyfills, 'optionalAccess', _160 => _160.WebSocket])
7031
+ _optionalChain([clientOptions, 'access', _146 => _146.polyfills, 'optionalAccess', _147 => _147.WebSocket])
7512
7032
  ),
7513
7033
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
7514
7034
  })),
7515
7035
  enableDebugLogging: clientOptions.enableDebugLogging,
7516
- unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _161 => _161.unstable_batchedUpdates]),
7036
+ unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _148 => _148.unstable_batchedUpdates]),
7517
7037
  baseUrl,
7518
7038
  unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
7519
7039
  unstable_streamData: !!clientOptions.unstable_streamData
@@ -7529,7 +7049,7 @@ function createClient(options) {
7529
7049
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
7530
7050
  if (shouldConnect) {
7531
7051
  if (typeof atob === "undefined") {
7532
- if (_optionalChain([clientOptions, 'access', _162 => _162.polyfills, 'optionalAccess', _163 => _163.atob]) === void 0) {
7052
+ if (_optionalChain([clientOptions, 'access', _149 => _149.polyfills, 'optionalAccess', _150 => _150.atob]) === void 0) {
7533
7053
  throw new Error(
7534
7054
  "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"
7535
7055
  );
@@ -7541,7 +7061,7 @@ function createClient(options) {
7541
7061
  return leaseRoom(newRoomDetails);
7542
7062
  }
7543
7063
  function getRoom(roomId) {
7544
- const room = _optionalChain([roomsById, 'access', _164 => _164.get, 'call', _165 => _165(roomId), 'optionalAccess', _166 => _166.room]);
7064
+ const room = _optionalChain([roomsById, 'access', _151 => _151.get, 'call', _152 => _152(roomId), 'optionalAccess', _153 => _153.room]);
7545
7065
  return room ? room : null;
7546
7066
  }
7547
7067
  function logout() {
@@ -7565,12 +7085,11 @@ function createClient(options) {
7565
7085
  getThreadsSince
7566
7086
  } = createNotificationsApi({
7567
7087
  baseUrl,
7568
- fetcher: _optionalChain([clientOptions, 'access', _167 => _167.polyfills, 'optionalAccess', _168 => _168.fetch]) || /* istanbul ignore next */
7088
+ fetcher: _optionalChain([clientOptions, 'access', _154 => _154.polyfills, 'optionalAccess', _155 => _155.fetch]) || /* istanbul ignore next */
7569
7089
  fetch,
7570
7090
  authManager,
7571
7091
  currentUserIdStore
7572
7092
  });
7573
- const cacheStore = createClientStore();
7574
7093
  const resolveUsers = clientOptions.resolveUsers;
7575
7094
  const warnIfNoResolveUsers = createDevelopmentWarning(
7576
7095
  () => !resolveUsers,
@@ -7579,7 +7098,7 @@ function createClient(options) {
7579
7098
  const usersStore = createBatchStore(
7580
7099
  async (batchedUserIds) => {
7581
7100
  const userIds = batchedUserIds.flat();
7582
- const users = await _optionalChain([resolveUsers, 'optionalCall', _169 => _169({ userIds })]);
7101
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _156 => _156({ userIds })]);
7583
7102
  warnIfNoResolveUsers();
7584
7103
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
7585
7104
  },
@@ -7593,7 +7112,7 @@ function createClient(options) {
7593
7112
  const roomsInfoStore = createBatchStore(
7594
7113
  async (batchedRoomIds) => {
7595
7114
  const roomIds = batchedRoomIds.flat();
7596
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _170 => _170({ roomIds })]);
7115
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _157 => _157({ roomIds })]);
7597
7116
  warnIfNoResolveRoomsInfo();
7598
7117
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
7599
7118
  },
@@ -7616,7 +7135,6 @@ function createClient(options) {
7616
7135
  [kInternal]: {
7617
7136
  currentUserIdStore,
7618
7137
  resolveMentionSuggestions: clientOptions.resolveMentionSuggestions,
7619
- cacheStore,
7620
7138
  usersStore,
7621
7139
  roomsInfoStore,
7622
7140
  getRoomIds() {
@@ -7709,7 +7227,7 @@ var commentBodyElementsTypes = {
7709
7227
  mention: "inline"
7710
7228
  };
7711
7229
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
7712
- if (!body || !_optionalChain([body, 'optionalAccess', _171 => _171.content])) {
7230
+ if (!body || !_optionalChain([body, 'optionalAccess', _158 => _158.content])) {
7713
7231
  return;
7714
7232
  }
7715
7233
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -7719,13 +7237,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
7719
7237
  for (const block of body.content) {
7720
7238
  if (type === "all" || type === "block") {
7721
7239
  if (guard(block)) {
7722
- _optionalChain([visitor, 'optionalCall', _172 => _172(block)]);
7240
+ _optionalChain([visitor, 'optionalCall', _159 => _159(block)]);
7723
7241
  }
7724
7242
  }
7725
7243
  if (type === "all" || type === "inline") {
7726
7244
  for (const inline of block.children) {
7727
7245
  if (guard(inline)) {
7728
- _optionalChain([visitor, 'optionalCall', _173 => _173(inline)]);
7246
+ _optionalChain([visitor, 'optionalCall', _160 => _160(inline)]);
7729
7247
  }
7730
7248
  }
7731
7249
  }
@@ -7750,7 +7268,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
7750
7268
  userIds
7751
7269
  });
7752
7270
  for (const [index, userId] of userIds.entries()) {
7753
- const user = _optionalChain([users, 'optionalAccess', _174 => _174[index]]);
7271
+ const user = _optionalChain([users, 'optionalAccess', _161 => _161[index]]);
7754
7272
  if (user) {
7755
7273
  resolvedUsers.set(userId, user);
7756
7274
  }
@@ -7873,7 +7391,7 @@ var stringifyCommentBodyPlainElements = {
7873
7391
  text: ({ element }) => element.text,
7874
7392
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
7875
7393
  mention: ({ element, user }) => {
7876
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _175 => _175.name]), () => ( element.id))}`;
7394
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _162 => _162.name]), () => ( element.id))}`;
7877
7395
  }
7878
7396
  };
7879
7397
  var stringifyCommentBodyHtmlElements = {
@@ -7903,7 +7421,7 @@ var stringifyCommentBodyHtmlElements = {
7903
7421
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${_nullishCoalesce(element.text, () => ( element.url))}</a>`;
7904
7422
  },
7905
7423
  mention: ({ element, user }) => {
7906
- return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _176 => _176.name]), () => ( element.id))}</span>`;
7424
+ return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _163 => _163.name]), () => ( element.id))}</span>`;
7907
7425
  }
7908
7426
  };
7909
7427
  var stringifyCommentBodyMarkdownElements = {
@@ -7933,19 +7451,19 @@ var stringifyCommentBodyMarkdownElements = {
7933
7451
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
7934
7452
  },
7935
7453
  mention: ({ element, user }) => {
7936
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _177 => _177.name]), () => ( element.id))}`;
7454
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _164 => _164.name]), () => ( element.id))}`;
7937
7455
  }
7938
7456
  };
7939
7457
  async function stringifyCommentBody(body, options) {
7940
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _178 => _178.format]), () => ( "plain"));
7941
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _179 => _179.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
7458
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _165 => _165.format]), () => ( "plain"));
7459
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _166 => _166.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
7942
7460
  const elements = {
7943
7461
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
7944
- ..._optionalChain([options, 'optionalAccess', _180 => _180.elements])
7462
+ ..._optionalChain([options, 'optionalAccess', _167 => _167.elements])
7945
7463
  };
7946
7464
  const resolvedUsers = await resolveUsersInCommentBody(
7947
7465
  body,
7948
- _optionalChain([options, 'optionalAccess', _181 => _181.resolveUsers])
7466
+ _optionalChain([options, 'optionalAccess', _168 => _168.resolveUsers])
7949
7467
  );
7950
7468
  const blocks = body.content.flatMap((block, blockIndex) => {
7951
7469
  switch (block.type) {
@@ -8220,12 +7738,12 @@ function legacy_patchImmutableNode(state, path, update) {
8220
7738
  }
8221
7739
  const newState = Object.assign({}, state);
8222
7740
  for (const key in update.updates) {
8223
- if (_optionalChain([update, 'access', _182 => _182.updates, 'access', _183 => _183[key], 'optionalAccess', _184 => _184.type]) === "update") {
7741
+ if (_optionalChain([update, 'access', _169 => _169.updates, 'access', _170 => _170[key], 'optionalAccess', _171 => _171.type]) === "update") {
8224
7742
  const val = update.node.get(key);
8225
7743
  if (val !== void 0) {
8226
7744
  newState[key] = lsonToJson(val);
8227
7745
  }
8228
- } else if (_optionalChain([update, 'access', _185 => _185.updates, 'access', _186 => _186[key], 'optionalAccess', _187 => _187.type]) === "delete") {
7746
+ } else if (_optionalChain([update, 'access', _172 => _172.updates, 'access', _173 => _173[key], 'optionalAccess', _174 => _174.type]) === "delete") {
8229
7747
  delete newState[key];
8230
7748
  }
8231
7749
  }
@@ -8286,12 +7804,12 @@ function legacy_patchImmutableNode(state, path, update) {
8286
7804
  }
8287
7805
  const newState = Object.assign({}, state);
8288
7806
  for (const key in update.updates) {
8289
- if (_optionalChain([update, 'access', _188 => _188.updates, 'access', _189 => _189[key], 'optionalAccess', _190 => _190.type]) === "update") {
7807
+ if (_optionalChain([update, 'access', _175 => _175.updates, 'access', _176 => _176[key], 'optionalAccess', _177 => _177.type]) === "update") {
8290
7808
  const value = update.node.get(key);
8291
7809
  if (value !== void 0) {
8292
7810
  newState[key] = lsonToJson(value);
8293
7811
  }
8294
- } else if (_optionalChain([update, 'access', _191 => _191.updates, 'access', _192 => _192[key], 'optionalAccess', _193 => _193.type]) === "delete") {
7812
+ } else if (_optionalChain([update, 'access', _178 => _178.updates, 'access', _179 => _179[key], 'optionalAccess', _180 => _180.type]) === "delete") {
8295
7813
  delete newState[key];
8296
7814
  }
8297
7815
  }
@@ -8458,7 +7976,7 @@ function shallowArray(xs, ys) {
8458
7976
  return true;
8459
7977
  }
8460
7978
  function shallowObj(objA, objB) {
8461
- if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null || Object.prototype.toString.call(objA) !== "[object Object]" || Object.prototype.toString.call(objB) !== "[object Object]") {
7979
+ if (!isPlainObject(objA) || !isPlainObject(objB)) {
8462
7980
  return false;
8463
7981
  }
8464
7982
  const keysA = Object.keys(objA);
@@ -8548,7 +8066,5 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
8548
8066
 
8549
8067
 
8550
8068
 
8551
-
8552
-
8553
- exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.addReaction = addReaction; exports.applyOptimisticUpdates = applyOptimisticUpdates; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.cloneLson = cloneLson; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createThreadId = createThreadId; exports.deleteComment = deleteComment; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.kInternal = kInternal; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.removeReaction = removeReaction; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.upsertComment = upsertComment; exports.wait = wait; exports.withTimeout = withTimeout;
8069
+ exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createStore = createStore; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.kInternal = kInternal; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.wait = wait; exports.withTimeout = withTimeout;
8554
8070
  //# sourceMappingURL=index.js.map