@liveblocks/core 3.1.1 → 3.1.2-url1

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 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.1.1";
9
+ var PKG_VERSION = "3.1.2-url1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1087,6 +1087,9 @@ function quote(input) {
1087
1087
  }
1088
1088
 
1089
1089
  // src/lib/url.ts
1090
+ var PLACEHOLDER_BASE_URL = "https://localhost:9999";
1091
+ var ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;
1092
+ var TRAILING_SLASH_URL_REGEX = /\/(?:(?:\?|#).*)?$/;
1090
1093
  function toURLSearchParams(params) {
1091
1094
  const result = new URLSearchParams();
1092
1095
  for (const [key, value] of Object.entries(params)) {
@@ -1108,6 +1111,53 @@ function url(strings, ...values2) {
1108
1111
  (result, str, i) => result + encodeURIComponent(_nullishCoalesce(values2[i - 1], () => ( ""))) + str
1109
1112
  );
1110
1113
  }
1114
+ function sanitizeUrl(url2) {
1115
+ if (url2.startsWith("www.")) {
1116
+ url2 = "https://" + url2;
1117
+ }
1118
+ try {
1119
+ const isAbsolute = ABSOLUTE_URL_REGEX.test(url2);
1120
+ const urlObject = new URL(
1121
+ url2,
1122
+ isAbsolute ? void 0 : PLACEHOLDER_BASE_URL
1123
+ );
1124
+ if (urlObject.protocol !== "http:" && urlObject.protocol !== "https:") {
1125
+ return null;
1126
+ }
1127
+ const hasTrailingSlash = TRAILING_SLASH_URL_REGEX.test(url2);
1128
+ const sanitizedUrl = (
1129
+ // 1. Origin, only for absolute URLs
1130
+ (isAbsolute ? urlObject.origin : "") + // 2. Pathname, with a trailing slash if the original URL had one
1131
+ (urlObject.pathname === "/" ? (
1132
+ // 2.a. Domain-only URLs, they always have their pathname set to "/"
1133
+ hasTrailingSlash ? "/" : ""
1134
+ ) : (
1135
+ // 2.b. URLs with a path
1136
+ hasTrailingSlash && !urlObject.pathname.endsWith("/") ? urlObject.pathname + "/" : urlObject.pathname
1137
+ )) + // 3. Search params
1138
+ urlObject.search + // 4. Hash
1139
+ urlObject.hash
1140
+ );
1141
+ return sanitizedUrl !== "" ? sanitizedUrl : null;
1142
+ } catch (e4) {
1143
+ return null;
1144
+ }
1145
+ }
1146
+ function generateUrl(url2, params, hash) {
1147
+ const isAbsolute = ABSOLUTE_URL_REGEX.test(url2);
1148
+ const urlObject = new URL(url2, isAbsolute ? void 0 : PLACEHOLDER_BASE_URL);
1149
+ if (params !== void 0) {
1150
+ for (const [param, value] of Object.entries(params)) {
1151
+ if (value) {
1152
+ urlObject.searchParams.set(param, String(value));
1153
+ }
1154
+ }
1155
+ }
1156
+ if (!urlObject.hash && hash !== void 0) {
1157
+ urlObject.hash = `#${hash}`;
1158
+ }
1159
+ return isAbsolute ? urlObject.href : urlObject.href.replace(PLACEHOLDER_BASE_URL, "");
1160
+ }
1111
1161
 
1112
1162
  // src/api-client.ts
1113
1163
  function createApiClient({
@@ -2099,7 +2149,7 @@ var HttpClient = class {
2099
2149
  let body;
2100
2150
  try {
2101
2151
  body = await response.json();
2102
- } catch (e4) {
2152
+ } catch (e5) {
2103
2153
  body = {};
2104
2154
  }
2105
2155
  return body;
@@ -3228,7 +3278,7 @@ var ManagedSocket = class {
3228
3278
  getStatus() {
3229
3279
  try {
3230
3280
  return toNewConnectionStatus(this.#machine);
3231
- } catch (e5) {
3281
+ } catch (e6) {
3232
3282
  return "initial";
3233
3283
  }
3234
3284
  }
@@ -3794,8 +3844,8 @@ function createStore_forTools() {
3794
3844
  return DerivedSignal.from(() => {
3795
3845
  return (
3796
3846
  // A tool that's registered and scoped to a specific chat ID...
3797
- _nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _57 => _57.get, 'call', _58 => _58()]), () => ( // ...or a globally registered tool
3798
- toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
3847
+ _nullishCoalesce(_optionalChain([(chatId !== void 0 ? _optionalChain([toolsByChatId\u03A3, 'access', _57 => _57.get, 'call', _58 => _58(chatId), 'optionalAccess', _59 => _59.get, 'call', _60 => _60(name)]) : void 0), 'optionalAccess', _61 => _61.get, 'call', _62 => _62()]), () => ( // ...or a globally registered tool
3848
+ _optionalChain([toolsByChatId\u03A3, 'access', _63 => _63.getOrCreate, 'call', _64 => _64(kWILDCARD), 'access', _65 => _65.get, 'call', _66 => _66(name), 'optionalAccess', _67 => _67.get, 'call', _68 => _68()])))
3799
3849
  );
3800
3850
  });
3801
3851
  });
@@ -3824,8 +3874,8 @@ function createStore_forTools() {
3824
3874
  const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
3825
3875
  const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
3826
3876
  return Array.from([
3827
- ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _59 => _59.entries, 'call', _60 => _60()]), () => ( [])),
3828
- ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _61 => _61.entries, 'call', _62 => _62()]), () => ( []))
3877
+ ..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _69 => _69.entries, 'call', _70 => _70()]), () => ( [])),
3878
+ ..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _71 => _71.entries, 'call', _72 => _72()]), () => ( []))
3829
3879
  ]).flatMap(([name, tool\u03A3]) => {
3830
3880
  const tool = tool\u03A3.get();
3831
3881
  return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
@@ -3926,7 +3976,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
3926
3976
  } else {
3927
3977
  continue;
3928
3978
  }
3929
- const executeFn = _optionalChain([toolsStore, 'access', _63 => _63.getTool\u03A3, 'call', _64 => _64(toolInvocation.name, message.chatId), 'access', _65 => _65.get, 'call', _66 => _66(), 'optionalAccess', _67 => _67.execute]);
3979
+ const executeFn = _optionalChain([toolsStore, 'access', _73 => _73.getTool\u03A3, 'call', _74 => _74(toolInvocation.name, message.chatId), 'access', _75 => _75.get, 'call', _76 => _76(), 'optionalAccess', _77 => _77.execute]);
3930
3980
  if (executeFn) {
3931
3981
  (async () => {
3932
3982
  const result = await executeFn(toolInvocation.args, {
@@ -4021,8 +4071,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
4021
4071
  const spine = [];
4022
4072
  let lastVisitedMessage = null;
4023
4073
  for (const message2 of pool.walkUp(leaf.id)) {
4024
- const prev = _nullishCoalesce(_optionalChain([first, 'call', _68 => _68(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _69 => _69.id]), () => ( null));
4025
- const next = _nullishCoalesce(_optionalChain([first, 'call', _70 => _70(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _71 => _71.id]), () => ( null));
4074
+ const prev = _nullishCoalesce(_optionalChain([first, 'call', _78 => _78(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _79 => _79.id]), () => ( null));
4075
+ const next = _nullishCoalesce(_optionalChain([first, 'call', _80 => _80(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _81 => _81.id]), () => ( null));
4026
4076
  if (!message2.deletedAt || prev || next) {
4027
4077
  const node = {
4028
4078
  ...message2,
@@ -4215,7 +4265,7 @@ function createAi(config) {
4215
4265
  if ("event" in msg) {
4216
4266
  switch (msg.event) {
4217
4267
  case "cmd-failed":
4218
- _optionalChain([pendingCmd, 'optionalAccess', _72 => _72.reject, 'call', _73 => _73(new Error(msg.error))]);
4268
+ _optionalChain([pendingCmd, 'optionalAccess', _82 => _82.reject, 'call', _83 => _83(new Error(msg.error))]);
4219
4269
  break;
4220
4270
  case "delta": {
4221
4271
  const { id, delta } = msg;
@@ -4297,7 +4347,7 @@ function createAi(config) {
4297
4347
  return assertNever(msg, "Unhandled case");
4298
4348
  }
4299
4349
  }
4300
- _optionalChain([pendingCmd, 'optionalAccess', _74 => _74.resolve, 'call', _75 => _75(msg)]);
4350
+ _optionalChain([pendingCmd, 'optionalAccess', _84 => _84.resolve, 'call', _85 => _85(msg)]);
4301
4351
  }
4302
4352
  managedSocket.events.onMessage.subscribe(handleServerMessage);
4303
4353
  managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
@@ -4381,9 +4431,9 @@ function createAi(config) {
4381
4431
  invocationId,
4382
4432
  result,
4383
4433
  generationOptions: {
4384
- copilotId: _optionalChain([options, 'optionalAccess', _76 => _76.copilotId]),
4385
- stream: _optionalChain([options, 'optionalAccess', _77 => _77.stream]),
4386
- timeout: _optionalChain([options, 'optionalAccess', _78 => _78.timeout]),
4434
+ copilotId: _optionalChain([options, 'optionalAccess', _86 => _86.copilotId]),
4435
+ stream: _optionalChain([options, 'optionalAccess', _87 => _87.stream]),
4436
+ timeout: _optionalChain([options, 'optionalAccess', _88 => _88.timeout]),
4387
4437
  // Knowledge and tools aren't coming from the options, but retrieved
4388
4438
  // from the global context
4389
4439
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -4419,9 +4469,9 @@ function createAi(config) {
4419
4469
  sourceMessage: userMessage,
4420
4470
  targetMessageId,
4421
4471
  generationOptions: {
4422
- copilotId: _optionalChain([options, 'optionalAccess', _79 => _79.copilotId]),
4423
- stream: _optionalChain([options, 'optionalAccess', _80 => _80.stream]),
4424
- timeout: _optionalChain([options, 'optionalAccess', _81 => _81.timeout]),
4472
+ copilotId: _optionalChain([options, 'optionalAccess', _89 => _89.copilotId]),
4473
+ stream: _optionalChain([options, 'optionalAccess', _90 => _90.stream]),
4474
+ timeout: _optionalChain([options, 'optionalAccess', _91 => _91.timeout]),
4425
4475
  // Knowledge and tools aren't coming from the options, but retrieved
4426
4476
  // from the global context
4427
4477
  knowledge: knowledge.length > 0 ? knowledge : void 0,
@@ -4523,7 +4573,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4523
4573
  return void 0;
4524
4574
  }
4525
4575
  async function makeAuthRequest(options) {
4526
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _82 => _82.polyfills, 'optionalAccess', _83 => _83.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4576
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _92 => _92.polyfills, 'optionalAccess', _93 => _93.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
4527
4577
  if (authentication.type === "private") {
4528
4578
  if (fetcher === void 0) {
4529
4579
  throw new StopRetrying(
@@ -4539,7 +4589,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4539
4589
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
4540
4590
  );
4541
4591
  }
4542
- _optionalChain([onAuthenticate, 'optionalCall', _84 => _84(parsed.parsed)]);
4592
+ _optionalChain([onAuthenticate, 'optionalCall', _94 => _94(parsed.parsed)]);
4543
4593
  return parsed;
4544
4594
  }
4545
4595
  if (authentication.type === "custom") {
@@ -4547,7 +4597,7 @@ function createAuthManager(authOptions, onAuthenticate) {
4547
4597
  if (response && typeof response === "object") {
4548
4598
  if (typeof response.token === "string") {
4549
4599
  const parsed = parseAuthToken(response.token);
4550
- _optionalChain([onAuthenticate, 'optionalCall', _85 => _85(parsed.parsed)]);
4600
+ _optionalChain([onAuthenticate, 'optionalCall', _95 => _95(parsed.parsed)]);
4551
4601
  return parsed;
4552
4602
  } else if (typeof response.error === "string") {
4553
4603
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -4705,7 +4755,7 @@ function sendToPanel(message, options) {
4705
4755
  ...message,
4706
4756
  source: "liveblocks-devtools-client"
4707
4757
  };
4708
- if (!(_optionalChain([options, 'optionalAccess', _86 => _86.force]) || _bridgeActive)) {
4758
+ if (!(_optionalChain([options, 'optionalAccess', _96 => _96.force]) || _bridgeActive)) {
4709
4759
  return;
4710
4760
  }
4711
4761
  window.postMessage(fullMsg, "*");
@@ -4713,7 +4763,7 @@ function sendToPanel(message, options) {
4713
4763
  var eventSource = makeEventSource();
4714
4764
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
4715
4765
  window.addEventListener("message", (event) => {
4716
- if (event.source === window && _optionalChain([event, 'access', _87 => _87.data, 'optionalAccess', _88 => _88.source]) === "liveblocks-devtools-panel") {
4766
+ if (event.source === window && _optionalChain([event, 'access', _97 => _97.data, 'optionalAccess', _98 => _98.source]) === "liveblocks-devtools-panel") {
4717
4767
  eventSource.notify(event.data);
4718
4768
  } else {
4719
4769
  }
@@ -4855,7 +4905,7 @@ function fullSync(room) {
4855
4905
  msg: "room::sync::full",
4856
4906
  roomId: room.id,
4857
4907
  status: room.getStatus(),
4858
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _89 => _89.toTreeNode, 'call', _90 => _90("root"), 'access', _91 => _91.payload]), () => ( null)),
4908
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _99 => _99.toTreeNode, 'call', _100 => _100("root"), 'access', _101 => _101.payload]), () => ( null)),
4859
4909
  me,
4860
4910
  others
4861
4911
  });
@@ -5146,7 +5196,7 @@ function createManagedPool(roomId, options) {
5146
5196
  generateId: () => `${getCurrentConnectionId()}:${clock++}`,
5147
5197
  generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
5148
5198
  dispatch(ops, reverse, storageUpdates) {
5149
- _optionalChain([onDispatch, 'optionalCall', _92 => _92(ops, reverse, storageUpdates)]);
5199
+ _optionalChain([onDispatch, 'optionalCall', _102 => _102(ops, reverse, storageUpdates)]);
5150
5200
  },
5151
5201
  assertStorageIsWritable: () => {
5152
5202
  if (!isStorageWritable()) {
@@ -5373,7 +5423,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
5373
5423
  return [
5374
5424
  {
5375
5425
  type: 8 /* CREATE_REGISTER */,
5376
- opId: _optionalChain([pool, 'optionalAccess', _93 => _93.generateOpId, 'call', _94 => _94()]),
5426
+ opId: _optionalChain([pool, 'optionalAccess', _103 => _103.generateOpId, 'call', _104 => _104()]),
5377
5427
  id: this._id,
5378
5428
  parentId,
5379
5429
  parentKey,
@@ -5479,7 +5529,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5479
5529
  const ops = [];
5480
5530
  const op = {
5481
5531
  id: this._id,
5482
- opId: _optionalChain([pool, 'optionalAccess', _95 => _95.generateOpId, 'call', _96 => _96()]),
5532
+ opId: _optionalChain([pool, 'optionalAccess', _105 => _105.generateOpId, 'call', _106 => _106()]),
5483
5533
  type: 2 /* CREATE_LIST */,
5484
5534
  parentId,
5485
5535
  parentKey
@@ -5750,7 +5800,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5750
5800
  #applyInsertUndoRedo(op) {
5751
5801
  const { id, parentKey: key } = op;
5752
5802
  const child = creationOpToLiveNode(op);
5753
- if (_optionalChain([this, 'access', _97 => _97._pool, 'optionalAccess', _98 => _98.getNode, 'call', _99 => _99(id)]) !== void 0) {
5803
+ if (_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.getNode, 'call', _109 => _109(id)]) !== void 0) {
5754
5804
  return { modified: false };
5755
5805
  }
5756
5806
  child._attach(id, nn(this._pool));
@@ -5758,8 +5808,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
5758
5808
  const existingItemIndex = this._indexOfPosition(key);
5759
5809
  let newKey = key;
5760
5810
  if (existingItemIndex !== -1) {
5761
- const before2 = _optionalChain([this, 'access', _100 => _100.#items, 'access', _101 => _101[existingItemIndex], 'optionalAccess', _102 => _102._parentPos]);
5762
- const after2 = _optionalChain([this, 'access', _103 => _103.#items, 'access', _104 => _104[existingItemIndex + 1], 'optionalAccess', _105 => _105._parentPos]);
5811
+ const before2 = _optionalChain([this, 'access', _110 => _110.#items, 'access', _111 => _111[existingItemIndex], 'optionalAccess', _112 => _112._parentPos]);
5812
+ const after2 = _optionalChain([this, 'access', _113 => _113.#items, 'access', _114 => _114[existingItemIndex + 1], 'optionalAccess', _115 => _115._parentPos]);
5763
5813
  newKey = makePosition(before2, after2);
5764
5814
  child._setParentLink(this, newKey);
5765
5815
  }
@@ -5773,7 +5823,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5773
5823
  #applySetUndoRedo(op) {
5774
5824
  const { id, parentKey: key } = op;
5775
5825
  const child = creationOpToLiveNode(op);
5776
- if (_optionalChain([this, 'access', _106 => _106._pool, 'optionalAccess', _107 => _107.getNode, 'call', _108 => _108(id)]) !== void 0) {
5826
+ if (_optionalChain([this, 'access', _116 => _116._pool, 'optionalAccess', _117 => _117.getNode, 'call', _118 => _118(id)]) !== void 0) {
5777
5827
  return { modified: false };
5778
5828
  }
5779
5829
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -5894,7 +5944,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5894
5944
  } else {
5895
5945
  this.#items[existingItemIndex]._setParentLink(
5896
5946
  this,
5897
- makePosition(newKey, _optionalChain([this, 'access', _109 => _109.#items, 'access', _110 => _110[existingItemIndex + 1], 'optionalAccess', _111 => _111._parentPos]))
5947
+ makePosition(newKey, _optionalChain([this, 'access', _119 => _119.#items, 'access', _120 => _120[existingItemIndex + 1], 'optionalAccess', _121 => _121._parentPos]))
5898
5948
  );
5899
5949
  const previousIndex = this.#items.indexOf(child);
5900
5950
  child._setParentLink(this, newKey);
@@ -5919,7 +5969,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5919
5969
  if (existingItemIndex !== -1) {
5920
5970
  this.#items[existingItemIndex]._setParentLink(
5921
5971
  this,
5922
- makePosition(newKey, _optionalChain([this, 'access', _112 => _112.#items, 'access', _113 => _113[existingItemIndex + 1], 'optionalAccess', _114 => _114._parentPos]))
5972
+ makePosition(newKey, _optionalChain([this, 'access', _122 => _122.#items, 'access', _123 => _123[existingItemIndex + 1], 'optionalAccess', _124 => _124._parentPos]))
5923
5973
  );
5924
5974
  }
5925
5975
  child._setParentLink(this, newKey);
@@ -5938,7 +5988,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5938
5988
  if (existingItemIndex !== -1) {
5939
5989
  this.#items[existingItemIndex]._setParentLink(
5940
5990
  this,
5941
- makePosition(newKey, _optionalChain([this, 'access', _115 => _115.#items, 'access', _116 => _116[existingItemIndex + 1], 'optionalAccess', _117 => _117._parentPos]))
5991
+ makePosition(newKey, _optionalChain([this, 'access', _125 => _125.#items, 'access', _126 => _126[existingItemIndex + 1], 'optionalAccess', _127 => _127._parentPos]))
5942
5992
  );
5943
5993
  }
5944
5994
  child._setParentLink(this, newKey);
@@ -5965,7 +6015,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
5965
6015
  if (existingItemIndex !== -1) {
5966
6016
  this.#items[existingItemIndex]._setParentLink(
5967
6017
  this,
5968
- makePosition(newKey, _optionalChain([this, 'access', _118 => _118.#items, 'access', _119 => _119[existingItemIndex + 1], 'optionalAccess', _120 => _120._parentPos]))
6018
+ makePosition(newKey, _optionalChain([this, 'access', _128 => _128.#items, 'access', _129 => _129[existingItemIndex + 1], 'optionalAccess', _130 => _130._parentPos]))
5969
6019
  );
5970
6020
  }
5971
6021
  child._setParentLink(this, newKey);
@@ -6023,7 +6073,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6023
6073
  * @param element The element to add to the end of the LiveList.
6024
6074
  */
6025
6075
  push(element) {
6026
- _optionalChain([this, 'access', _121 => _121._pool, 'optionalAccess', _122 => _122.assertStorageIsWritable, 'call', _123 => _123()]);
6076
+ _optionalChain([this, 'access', _131 => _131._pool, 'optionalAccess', _132 => _132.assertStorageIsWritable, 'call', _133 => _133()]);
6027
6077
  return this.insert(element, this.length);
6028
6078
  }
6029
6079
  /**
@@ -6032,7 +6082,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6032
6082
  * @param index The index at which you want to insert the element.
6033
6083
  */
6034
6084
  insert(element, index) {
6035
- _optionalChain([this, 'access', _124 => _124._pool, 'optionalAccess', _125 => _125.assertStorageIsWritable, 'call', _126 => _126()]);
6085
+ _optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
6036
6086
  if (index < 0 || index > this.#items.length) {
6037
6087
  throw new Error(
6038
6088
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -6062,7 +6112,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6062
6112
  * @param targetIndex The index where the element should be after moving.
6063
6113
  */
6064
6114
  move(index, targetIndex) {
6065
- _optionalChain([this, 'access', _127 => _127._pool, 'optionalAccess', _128 => _128.assertStorageIsWritable, 'call', _129 => _129()]);
6115
+ _optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
6066
6116
  if (targetIndex < 0) {
6067
6117
  throw new Error("targetIndex cannot be less than 0");
6068
6118
  }
@@ -6120,7 +6170,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6120
6170
  * @param index The index of the element to delete
6121
6171
  */
6122
6172
  delete(index) {
6123
- _optionalChain([this, 'access', _130 => _130._pool, 'optionalAccess', _131 => _131.assertStorageIsWritable, 'call', _132 => _132()]);
6173
+ _optionalChain([this, 'access', _140 => _140._pool, 'optionalAccess', _141 => _141.assertStorageIsWritable, 'call', _142 => _142()]);
6124
6174
  if (index < 0 || index >= this.#items.length) {
6125
6175
  throw new Error(
6126
6176
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6153,7 +6203,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6153
6203
  }
6154
6204
  }
6155
6205
  clear() {
6156
- _optionalChain([this, 'access', _133 => _133._pool, 'optionalAccess', _134 => _134.assertStorageIsWritable, 'call', _135 => _135()]);
6206
+ _optionalChain([this, 'access', _143 => _143._pool, 'optionalAccess', _144 => _144.assertStorageIsWritable, 'call', _145 => _145()]);
6157
6207
  if (this._pool) {
6158
6208
  const ops = [];
6159
6209
  const reverseOps = [];
@@ -6187,7 +6237,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6187
6237
  }
6188
6238
  }
6189
6239
  set(index, item) {
6190
- _optionalChain([this, 'access', _136 => _136._pool, 'optionalAccess', _137 => _137.assertStorageIsWritable, 'call', _138 => _138()]);
6240
+ _optionalChain([this, 'access', _146 => _146._pool, 'optionalAccess', _147 => _147.assertStorageIsWritable, 'call', _148 => _148()]);
6191
6241
  if (index < 0 || index >= this.#items.length) {
6192
6242
  throw new Error(
6193
6243
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -6333,7 +6383,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6333
6383
  #shiftItemPosition(index, key) {
6334
6384
  const shiftedPosition = makePosition(
6335
6385
  key,
6336
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _139 => _139.#items, 'access', _140 => _140[index + 1], 'optionalAccess', _141 => _141._parentPos]) : void 0
6386
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _149 => _149.#items, 'access', _150 => _150[index + 1], 'optionalAccess', _151 => _151._parentPos]) : void 0
6337
6387
  );
6338
6388
  this.#items[index]._setParentLink(this, shiftedPosition);
6339
6389
  }
@@ -6458,7 +6508,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6458
6508
  const ops = [];
6459
6509
  const op = {
6460
6510
  id: this._id,
6461
- opId: _optionalChain([pool, 'optionalAccess', _142 => _142.generateOpId, 'call', _143 => _143()]),
6511
+ opId: _optionalChain([pool, 'optionalAccess', _152 => _152.generateOpId, 'call', _153 => _153()]),
6462
6512
  type: 7 /* CREATE_MAP */,
6463
6513
  parentId,
6464
6514
  parentKey
@@ -6593,7 +6643,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6593
6643
  * @param value The value of the element to add. Should be serializable to JSON.
6594
6644
  */
6595
6645
  set(key, value) {
6596
- _optionalChain([this, 'access', _144 => _144._pool, 'optionalAccess', _145 => _145.assertStorageIsWritable, 'call', _146 => _146()]);
6646
+ _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
6597
6647
  const oldValue = this.#map.get(key);
6598
6648
  if (oldValue) {
6599
6649
  oldValue._detach();
@@ -6639,7 +6689,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
6639
6689
  * @returns true if an element existed and has been removed, or false if the element does not exist.
6640
6690
  */
6641
6691
  delete(key) {
6642
- _optionalChain([this, 'access', _147 => _147._pool, 'optionalAccess', _148 => _148.assertStorageIsWritable, 'call', _149 => _149()]);
6692
+ _optionalChain([this, 'access', _157 => _157._pool, 'optionalAccess', _158 => _158.assertStorageIsWritable, 'call', _159 => _159()]);
6643
6693
  const item = this.#map.get(key);
6644
6694
  if (item === void 0) {
6645
6695
  return false;
@@ -6829,7 +6879,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
6829
6879
  if (this._id === void 0) {
6830
6880
  throw new Error("Cannot serialize item is not attached");
6831
6881
  }
6832
- const opId = _optionalChain([pool, 'optionalAccess', _150 => _150.generateOpId, 'call', _151 => _151()]);
6882
+ const opId = _optionalChain([pool, 'optionalAccess', _160 => _160.generateOpId, 'call', _161 => _161()]);
6833
6883
  const ops = [];
6834
6884
  const op = {
6835
6885
  type: 4 /* CREATE_OBJECT */,
@@ -7101,7 +7151,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7101
7151
  * @param value The value of the property to add
7102
7152
  */
7103
7153
  set(key, value) {
7104
- _optionalChain([this, 'access', _152 => _152._pool, 'optionalAccess', _153 => _153.assertStorageIsWritable, 'call', _154 => _154()]);
7154
+ _optionalChain([this, 'access', _162 => _162._pool, 'optionalAccess', _163 => _163.assertStorageIsWritable, 'call', _164 => _164()]);
7105
7155
  this.update({ [key]: value });
7106
7156
  }
7107
7157
  /**
@@ -7116,7 +7166,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7116
7166
  * @param key The key of the property to delete
7117
7167
  */
7118
7168
  delete(key) {
7119
- _optionalChain([this, 'access', _155 => _155._pool, 'optionalAccess', _156 => _156.assertStorageIsWritable, 'call', _157 => _157()]);
7169
+ _optionalChain([this, 'access', _165 => _165._pool, 'optionalAccess', _166 => _166.assertStorageIsWritable, 'call', _167 => _167()]);
7120
7170
  const keyAsString = key;
7121
7171
  const oldValue = this.#map.get(keyAsString);
7122
7172
  if (oldValue === void 0) {
@@ -7169,7 +7219,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7169
7219
  * @param patch The object used to overrides properties
7170
7220
  */
7171
7221
  update(patch) {
7172
- _optionalChain([this, 'access', _158 => _158._pool, 'optionalAccess', _159 => _159.assertStorageIsWritable, 'call', _160 => _160()]);
7222
+ _optionalChain([this, 'access', _168 => _168._pool, 'optionalAccess', _169 => _169.assertStorageIsWritable, 'call', _170 => _170()]);
7173
7223
  if (_LiveObject.detectLargeObjects) {
7174
7224
  const data = {};
7175
7225
  for (const [key, value] of this.#map) {
@@ -7915,15 +7965,15 @@ function installBackgroundTabSpy() {
7915
7965
  const doc = typeof document !== "undefined" ? document : void 0;
7916
7966
  const inBackgroundSince = { current: null };
7917
7967
  function onVisibilityChange() {
7918
- if (_optionalChain([doc, 'optionalAccess', _161 => _161.visibilityState]) === "hidden") {
7968
+ if (_optionalChain([doc, 'optionalAccess', _171 => _171.visibilityState]) === "hidden") {
7919
7969
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
7920
7970
  } else {
7921
7971
  inBackgroundSince.current = null;
7922
7972
  }
7923
7973
  }
7924
- _optionalChain([doc, 'optionalAccess', _162 => _162.addEventListener, 'call', _163 => _163("visibilitychange", onVisibilityChange)]);
7974
+ _optionalChain([doc, 'optionalAccess', _172 => _172.addEventListener, 'call', _173 => _173("visibilitychange", onVisibilityChange)]);
7925
7975
  const unsub = () => {
7926
- _optionalChain([doc, 'optionalAccess', _164 => _164.removeEventListener, 'call', _165 => _165("visibilitychange", onVisibilityChange)]);
7976
+ _optionalChain([doc, 'optionalAccess', _174 => _174.removeEventListener, 'call', _175 => _175("visibilitychange", onVisibilityChange)]);
7927
7977
  };
7928
7978
  return [inBackgroundSince, unsub];
7929
7979
  }
@@ -8103,7 +8153,7 @@ function createRoom(options, config) {
8103
8153
  }
8104
8154
  }
8105
8155
  function isStorageWritable() {
8106
- const scopes = _optionalChain([context, 'access', _166 => _166.dynamicSessionInfoSig, 'access', _167 => _167.get, 'call', _168 => _168(), 'optionalAccess', _169 => _169.scopes]);
8156
+ const scopes = _optionalChain([context, 'access', _176 => _176.dynamicSessionInfoSig, 'access', _177 => _177.get, 'call', _178 => _178(), 'optionalAccess', _179 => _179.scopes]);
8107
8157
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
8108
8158
  }
8109
8159
  const eventHub = {
@@ -8220,7 +8270,7 @@ function createRoom(options, config) {
8220
8270
  }
8221
8271
  case "experimental-fallback-to-http": {
8222
8272
  warn("Message is too large for websockets, so sending over HTTP instead");
8223
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _170 => _170.dynamicSessionInfoSig, 'access', _171 => _171.get, 'call', _172 => _172(), 'optionalAccess', _173 => _173.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8273
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _180 => _180.dynamicSessionInfoSig, 'access', _181 => _181.get, 'call', _182 => _182(), 'optionalAccess', _183 => _183.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
8224
8274
  void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
8225
8275
  if (!resp.ok && resp.status === 403) {
8226
8276
  managedSocket.reconnect();
@@ -8271,7 +8321,7 @@ function createRoom(options, config) {
8271
8321
  } else {
8272
8322
  context.root = LiveObject._fromItems(message.items, context.pool);
8273
8323
  }
8274
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _174 => _174.get, 'call', _175 => _175(), 'optionalAccess', _176 => _176.canWrite]), () => ( true));
8324
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _184 => _184.get, 'call', _185 => _185(), 'optionalAccess', _186 => _186.canWrite]), () => ( true));
8275
8325
  const stackSizeBefore = context.undoStack.length;
8276
8326
  for (const key in context.initialStorage) {
8277
8327
  if (context.root.get(key) === void 0) {
@@ -8474,7 +8524,7 @@ function createRoom(options, config) {
8474
8524
  }
8475
8525
  context.myPresence.patch(patch);
8476
8526
  if (context.activeBatch) {
8477
- if (_optionalChain([options2, 'optionalAccess', _177 => _177.addToHistory])) {
8527
+ if (_optionalChain([options2, 'optionalAccess', _187 => _187.addToHistory])) {
8478
8528
  context.activeBatch.reverseOps.pushLeft({
8479
8529
  type: "presence",
8480
8530
  data: oldValues
@@ -8483,7 +8533,7 @@ function createRoom(options, config) {
8483
8533
  context.activeBatch.updates.presence = true;
8484
8534
  } else {
8485
8535
  flushNowOrSoon();
8486
- if (_optionalChain([options2, 'optionalAccess', _178 => _178.addToHistory])) {
8536
+ if (_optionalChain([options2, 'optionalAccess', _188 => _188.addToHistory])) {
8487
8537
  addToUndoStack([{ type: "presence", data: oldValues }]);
8488
8538
  }
8489
8539
  notify({ presence: true });
@@ -8680,7 +8730,7 @@ function createRoom(options, config) {
8680
8730
  if (process.env.NODE_ENV !== "production") {
8681
8731
  const traces = /* @__PURE__ */ new Set();
8682
8732
  for (const opId of message.opIds) {
8683
- const trace = _optionalChain([context, 'access', _179 => _179.opStackTraces, 'optionalAccess', _180 => _180.get, 'call', _181 => _181(opId)]);
8733
+ const trace = _optionalChain([context, 'access', _189 => _189.opStackTraces, 'optionalAccess', _190 => _190.get, 'call', _191 => _191(opId)]);
8684
8734
  if (trace) {
8685
8735
  traces.add(trace);
8686
8736
  }
@@ -8814,7 +8864,7 @@ ${Array.from(traces).join("\n\n")}`
8814
8864
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
8815
8865
  createOrUpdateRootFromMessage(message);
8816
8866
  applyAndSendOps(unacknowledgedOps);
8817
- _optionalChain([_resolveStoragePromise, 'optionalCall', _182 => _182()]);
8867
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _192 => _192()]);
8818
8868
  notifyStorageStatus();
8819
8869
  eventHub.storageDidLoad.notify();
8820
8870
  }
@@ -9035,8 +9085,8 @@ ${Array.from(traces).join("\n\n")}`
9035
9085
  async function getThreads(options2) {
9036
9086
  return httpClient.getThreads({
9037
9087
  roomId,
9038
- query: _optionalChain([options2, 'optionalAccess', _183 => _183.query]),
9039
- cursor: _optionalChain([options2, 'optionalAccess', _184 => _184.cursor])
9088
+ query: _optionalChain([options2, 'optionalAccess', _193 => _193.query]),
9089
+ cursor: _optionalChain([options2, 'optionalAccess', _194 => _194.cursor])
9040
9090
  });
9041
9091
  }
9042
9092
  async function getThread(threadId) {
@@ -9143,7 +9193,7 @@ ${Array.from(traces).join("\n\n")}`
9143
9193
  function getSubscriptionSettings(options2) {
9144
9194
  return httpClient.getSubscriptionSettings({
9145
9195
  roomId,
9146
- signal: _optionalChain([options2, 'optionalAccess', _185 => _185.signal])
9196
+ signal: _optionalChain([options2, 'optionalAccess', _195 => _195.signal])
9147
9197
  });
9148
9198
  }
9149
9199
  function updateSubscriptionSettings(settings) {
@@ -9165,7 +9215,7 @@ ${Array.from(traces).join("\n\n")}`
9165
9215
  {
9166
9216
  [kInternal]: {
9167
9217
  get presenceBuffer() {
9168
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _186 => _186.buffer, 'access', _187 => _187.presenceUpdates, 'optionalAccess', _188 => _188.data]), () => ( null)));
9218
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _196 => _196.buffer, 'access', _197 => _197.presenceUpdates, 'optionalAccess', _198 => _198.data]), () => ( null)));
9169
9219
  },
9170
9220
  // prettier-ignore
9171
9221
  get undoStack() {
@@ -9180,9 +9230,9 @@ ${Array.from(traces).join("\n\n")}`
9180
9230
  return context.yjsProvider;
9181
9231
  },
9182
9232
  setYjsProvider(newProvider) {
9183
- _optionalChain([context, 'access', _189 => _189.yjsProvider, 'optionalAccess', _190 => _190.off, 'call', _191 => _191("status", yjsStatusDidChange)]);
9233
+ _optionalChain([context, 'access', _199 => _199.yjsProvider, 'optionalAccess', _200 => _200.off, 'call', _201 => _201("status", yjsStatusDidChange)]);
9184
9234
  context.yjsProvider = newProvider;
9185
- _optionalChain([newProvider, 'optionalAccess', _192 => _192.on, 'call', _193 => _193("status", yjsStatusDidChange)]);
9235
+ _optionalChain([newProvider, 'optionalAccess', _202 => _202.on, 'call', _203 => _203("status", yjsStatusDidChange)]);
9186
9236
  context.yjsProviderDidChange.notify();
9187
9237
  },
9188
9238
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -9228,7 +9278,7 @@ ${Array.from(traces).join("\n\n")}`
9228
9278
  source.dispose();
9229
9279
  }
9230
9280
  eventHub.roomWillDestroy.notify();
9231
- _optionalChain([context, 'access', _194 => _194.yjsProvider, 'optionalAccess', _195 => _195.off, 'call', _196 => _196("status", yjsStatusDidChange)]);
9281
+ _optionalChain([context, 'access', _204 => _204.yjsProvider, 'optionalAccess', _205 => _205.off, 'call', _206 => _206("status", yjsStatusDidChange)]);
9232
9282
  syncSourceForStorage.destroy();
9233
9283
  syncSourceForYjs.destroy();
9234
9284
  uninstallBgTabSpy();
@@ -9378,7 +9428,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
9378
9428
  }
9379
9429
  if (isLiveNode(first)) {
9380
9430
  const node = first;
9381
- if (_optionalChain([options, 'optionalAccess', _197 => _197.isDeep])) {
9431
+ if (_optionalChain([options, 'optionalAccess', _207 => _207.isDeep])) {
9382
9432
  const storageCallback = second;
9383
9433
  return subscribeToLiveStructureDeeply(node, storageCallback);
9384
9434
  } else {
@@ -9457,8 +9507,8 @@ function createClient(options) {
9457
9507
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
9458
9508
  currentUserId.set(() => userId);
9459
9509
  });
9460
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _198 => _198.polyfills, 'optionalAccess', _199 => _199.fetch]) || /* istanbul ignore next */
9461
- _optionalChain([globalThis, 'access', _200 => _200.fetch, 'optionalAccess', _201 => _201.bind, 'call', _202 => _202(globalThis)]);
9510
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.fetch]) || /* istanbul ignore next */
9511
+ _optionalChain([globalThis, 'access', _210 => _210.fetch, 'optionalAccess', _211 => _211.bind, 'call', _212 => _212(globalThis)]);
9462
9512
  const httpClient = createApiClient({
9463
9513
  baseUrl,
9464
9514
  fetchPolyfill,
@@ -9476,7 +9526,7 @@ function createClient(options) {
9476
9526
  delegates: {
9477
9527
  createSocket: makeCreateSocketDelegateForAi(
9478
9528
  baseUrl,
9479
- _optionalChain([clientOptions, 'access', _203 => _203.polyfills, 'optionalAccess', _204 => _204.WebSocket])
9529
+ _optionalChain([clientOptions, 'access', _213 => _213.polyfills, 'optionalAccess', _214 => _214.WebSocket])
9480
9530
  ),
9481
9531
  authenticate: async () => {
9482
9532
  const resp = await authManager.getAuthValue({
@@ -9544,7 +9594,7 @@ function createClient(options) {
9544
9594
  createSocket: makeCreateSocketDelegateForRoom(
9545
9595
  roomId,
9546
9596
  baseUrl,
9547
- _optionalChain([clientOptions, 'access', _205 => _205.polyfills, 'optionalAccess', _206 => _206.WebSocket])
9597
+ _optionalChain([clientOptions, 'access', _215 => _215.polyfills, 'optionalAccess', _216 => _216.WebSocket])
9548
9598
  ),
9549
9599
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
9550
9600
  })),
@@ -9567,7 +9617,7 @@ function createClient(options) {
9567
9617
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
9568
9618
  if (shouldConnect) {
9569
9619
  if (typeof atob === "undefined") {
9570
- if (_optionalChain([clientOptions, 'access', _207 => _207.polyfills, 'optionalAccess', _208 => _208.atob]) === void 0) {
9620
+ if (_optionalChain([clientOptions, 'access', _217 => _217.polyfills, 'optionalAccess', _218 => _218.atob]) === void 0) {
9571
9621
  throw new Error(
9572
9622
  "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"
9573
9623
  );
@@ -9579,7 +9629,7 @@ function createClient(options) {
9579
9629
  return leaseRoom(newRoomDetails);
9580
9630
  }
9581
9631
  function getRoom(roomId) {
9582
- const room = _optionalChain([roomsById, 'access', _209 => _209.get, 'call', _210 => _210(roomId), 'optionalAccess', _211 => _211.room]);
9632
+ const room = _optionalChain([roomsById, 'access', _219 => _219.get, 'call', _220 => _220(roomId), 'optionalAccess', _221 => _221.room]);
9583
9633
  return room ? room : null;
9584
9634
  }
9585
9635
  function logout() {
@@ -9599,7 +9649,7 @@ function createClient(options) {
9599
9649
  const batchedResolveUsers = new Batch(
9600
9650
  async (batchedUserIds) => {
9601
9651
  const userIds = batchedUserIds.flat();
9602
- const users = await _optionalChain([resolveUsers, 'optionalCall', _212 => _212({ userIds })]);
9652
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _222 => _222({ userIds })]);
9603
9653
  warnIfNoResolveUsers();
9604
9654
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
9605
9655
  },
@@ -9617,7 +9667,7 @@ function createClient(options) {
9617
9667
  const batchedResolveRoomsInfo = new Batch(
9618
9668
  async (batchedRoomIds) => {
9619
9669
  const roomIds = batchedRoomIds.flat();
9620
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _213 => _213({ roomIds })]);
9670
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _223 => _223({ roomIds })]);
9621
9671
  warnIfNoResolveRoomsInfo();
9622
9672
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
9623
9673
  },
@@ -9670,7 +9720,7 @@ function createClient(options) {
9670
9720
  }
9671
9721
  };
9672
9722
  const win = typeof window !== "undefined" ? window : void 0;
9673
- _optionalChain([win, 'optionalAccess', _214 => _214.addEventListener, 'call', _215 => _215("beforeunload", maybePreventClose)]);
9723
+ _optionalChain([win, 'optionalAccess', _224 => _224.addEventListener, 'call', _225 => _225("beforeunload", maybePreventClose)]);
9674
9724
  }
9675
9725
  async function getNotificationSettings(options2) {
9676
9726
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -9809,7 +9859,7 @@ var commentBodyElementsTypes = {
9809
9859
  mention: "inline"
9810
9860
  };
9811
9861
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9812
- if (!body || !_optionalChain([body, 'optionalAccess', _216 => _216.content])) {
9862
+ if (!body || !_optionalChain([body, 'optionalAccess', _226 => _226.content])) {
9813
9863
  return;
9814
9864
  }
9815
9865
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -9819,13 +9869,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
9819
9869
  for (const block of body.content) {
9820
9870
  if (type === "all" || type === "block") {
9821
9871
  if (guard(block)) {
9822
- _optionalChain([visitor, 'optionalCall', _217 => _217(block)]);
9872
+ _optionalChain([visitor, 'optionalCall', _227 => _227(block)]);
9823
9873
  }
9824
9874
  }
9825
9875
  if (type === "all" || type === "inline") {
9826
9876
  for (const inline of block.children) {
9827
9877
  if (guard(inline)) {
9828
- _optionalChain([visitor, 'optionalCall', _218 => _218(inline)]);
9878
+ _optionalChain([visitor, 'optionalCall', _228 => _228(inline)]);
9829
9879
  }
9830
9880
  }
9831
9881
  }
@@ -9859,7 +9909,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
9859
9909
  userIds
9860
9910
  });
9861
9911
  for (const [index, userId] of userIds.entries()) {
9862
- const user = _optionalChain([users, 'optionalAccess', _219 => _219[index]]);
9912
+ const user = _optionalChain([users, 'optionalAccess', _229 => _229[index]]);
9863
9913
  if (user) {
9864
9914
  resolvedUsers.set(userId, user);
9865
9915
  }
@@ -9973,20 +10023,12 @@ var MarkdownSafeString = class {
9973
10023
  function markdown(strings, ...values2) {
9974
10024
  return new MarkdownSafeString(strings, values2);
9975
10025
  }
9976
- function toAbsoluteUrl(url2) {
9977
- if (url2.startsWith("http://") || url2.startsWith("https://")) {
9978
- return url2;
9979
- } else if (url2.startsWith("www.")) {
9980
- return "https://" + url2;
9981
- }
9982
- return;
9983
- }
9984
10026
  var stringifyCommentBodyPlainElements = {
9985
10027
  paragraph: ({ children }) => children,
9986
10028
  text: ({ element }) => element.text,
9987
10029
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
9988
10030
  mention: ({ element, user }) => {
9989
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _220 => _220.name]), () => ( element.id))}`;
10031
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _230 => _230.name]), () => ( element.id))}`;
9990
10032
  }
9991
10033
  };
9992
10034
  var stringifyCommentBodyHtmlElements = {
@@ -10016,7 +10058,7 @@ var stringifyCommentBodyHtmlElements = {
10016
10058
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
10017
10059
  },
10018
10060
  mention: ({ element, user }) => {
10019
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _221 => _221.name]) ? html`${_optionalChain([user, 'optionalAccess', _222 => _222.name])}` : element.id}</span>`;
10061
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _231 => _231.name]) ? html`${_optionalChain([user, 'optionalAccess', _232 => _232.name])}` : element.id}</span>`;
10020
10062
  }
10021
10063
  };
10022
10064
  var stringifyCommentBodyMarkdownElements = {
@@ -10046,19 +10088,19 @@ var stringifyCommentBodyMarkdownElements = {
10046
10088
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
10047
10089
  },
10048
10090
  mention: ({ element, user }) => {
10049
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _223 => _223.name]), () => ( element.id))}`;
10091
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _233 => _233.name]), () => ( element.id))}`;
10050
10092
  }
10051
10093
  };
10052
10094
  async function stringifyCommentBody(body, options) {
10053
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _224 => _224.format]), () => ( "plain"));
10054
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _225 => _225.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10095
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _234 => _234.format]), () => ( "plain"));
10096
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _235 => _235.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
10055
10097
  const elements = {
10056
10098
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
10057
- ..._optionalChain([options, 'optionalAccess', _226 => _226.elements])
10099
+ ..._optionalChain([options, 'optionalAccess', _236 => _236.elements])
10058
10100
  };
10059
10101
  const resolvedUsers = await resolveUsersInCommentBody(
10060
10102
  body,
10061
- _optionalChain([options, 'optionalAccess', _227 => _227.resolveUsers])
10103
+ _optionalChain([options, 'optionalAccess', _237 => _237.resolveUsers])
10062
10104
  );
10063
10105
  const blocks = body.content.flatMap((block, blockIndex) => {
10064
10106
  switch (block.type) {
@@ -10076,11 +10118,22 @@ async function stringifyCommentBody(body, options) {
10076
10118
  ] : [];
10077
10119
  }
10078
10120
  if (isCommentBodyLink(inline)) {
10121
+ const href = sanitizeUrl(inline.url);
10122
+ if (href === null) {
10123
+ return [
10124
+ elements.text(
10125
+ {
10126
+ element: { text: _nullishCoalesce(inline.text, () => ( inline.url)) }
10127
+ },
10128
+ inlineIndex
10129
+ )
10130
+ ];
10131
+ }
10079
10132
  return [
10080
10133
  elements.link(
10081
10134
  {
10082
10135
  element: inline,
10083
- href: _nullishCoalesce(toAbsoluteUrl(inline.url), () => ( inline.url))
10136
+ href
10084
10137
  },
10085
10138
  inlineIndex
10086
10139
  )
@@ -10105,22 +10158,6 @@ async function stringifyCommentBody(body, options) {
10105
10158
  return blocks.join(separator);
10106
10159
  }
10107
10160
 
10108
- // src/comments/comment-url.ts
10109
- var PLACEHOLDER_BASE_URL = "https://localhost:9999";
10110
- var ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;
10111
- function generateCommentUrl({
10112
- roomUrl,
10113
- commentId
10114
- }) {
10115
- const isAbsolute = ABSOLUTE_URL_REGEX.test(roomUrl);
10116
- const urlObject = new URL(
10117
- roomUrl,
10118
- isAbsolute ? void 0 : PLACEHOLDER_BASE_URL
10119
- );
10120
- urlObject.hash = `#${commentId}`;
10121
- return isAbsolute ? urlObject.href : urlObject.href.replace(PLACEHOLDER_BASE_URL, "");
10122
- }
10123
-
10124
10161
  // src/crdts/utils.ts
10125
10162
  function toPlainLson(lson) {
10126
10163
  if (lson instanceof LiveObject) {
@@ -10349,12 +10386,12 @@ function legacy_patchImmutableNode(state, path, update) {
10349
10386
  }
10350
10387
  const newState = Object.assign({}, state);
10351
10388
  for (const key in update.updates) {
10352
- if (_optionalChain([update, 'access', _228 => _228.updates, 'access', _229 => _229[key], 'optionalAccess', _230 => _230.type]) === "update") {
10389
+ if (_optionalChain([update, 'access', _238 => _238.updates, 'access', _239 => _239[key], 'optionalAccess', _240 => _240.type]) === "update") {
10353
10390
  const val = update.node.get(key);
10354
10391
  if (val !== void 0) {
10355
10392
  newState[key] = lsonToJson(val);
10356
10393
  }
10357
- } else if (_optionalChain([update, 'access', _231 => _231.updates, 'access', _232 => _232[key], 'optionalAccess', _233 => _233.type]) === "delete") {
10394
+ } else if (_optionalChain([update, 'access', _241 => _241.updates, 'access', _242 => _242[key], 'optionalAccess', _243 => _243.type]) === "delete") {
10358
10395
  delete newState[key];
10359
10396
  }
10360
10397
  }
@@ -10415,12 +10452,12 @@ function legacy_patchImmutableNode(state, path, update) {
10415
10452
  }
10416
10453
  const newState = Object.assign({}, state);
10417
10454
  for (const key in update.updates) {
10418
- if (_optionalChain([update, 'access', _234 => _234.updates, 'access', _235 => _235[key], 'optionalAccess', _236 => _236.type]) === "update") {
10455
+ if (_optionalChain([update, 'access', _244 => _244.updates, 'access', _245 => _245[key], 'optionalAccess', _246 => _246.type]) === "update") {
10419
10456
  const value = update.node.get(key);
10420
10457
  if (value !== void 0) {
10421
10458
  newState[key] = lsonToJson(value);
10422
10459
  }
10423
- } else if (_optionalChain([update, 'access', _237 => _237.updates, 'access', _238 => _238[key], 'optionalAccess', _239 => _239.type]) === "delete") {
10460
+ } else if (_optionalChain([update, 'access', _247 => _247.updates, 'access', _248 => _248[key], 'optionalAccess', _249 => _249.type]) === "delete") {
10424
10461
  delete newState[key];
10425
10462
  }
10426
10463
  }
@@ -10500,9 +10537,9 @@ function makePoller(callback, intervalMs, options) {
10500
10537
  const startTime = performance.now();
10501
10538
  const doc = typeof document !== "undefined" ? document : void 0;
10502
10539
  const win = typeof window !== "undefined" ? window : void 0;
10503
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _240 => _240.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10540
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _250 => _250.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
10504
10541
  const context = {
10505
- inForeground: _optionalChain([doc, 'optionalAccess', _241 => _241.visibilityState]) !== "hidden",
10542
+ inForeground: _optionalChain([doc, 'optionalAccess', _251 => _251.visibilityState]) !== "hidden",
10506
10543
  lastSuccessfulPollAt: startTime,
10507
10544
  count: 0,
10508
10545
  backoff: 0
@@ -10583,11 +10620,11 @@ function makePoller(callback, intervalMs, options) {
10583
10620
  pollNowIfStale();
10584
10621
  }
10585
10622
  function onVisibilityChange() {
10586
- setInForeground(_optionalChain([doc, 'optionalAccess', _242 => _242.visibilityState]) !== "hidden");
10623
+ setInForeground(_optionalChain([doc, 'optionalAccess', _252 => _252.visibilityState]) !== "hidden");
10587
10624
  }
10588
- _optionalChain([doc, 'optionalAccess', _243 => _243.addEventListener, 'call', _244 => _244("visibilitychange", onVisibilityChange)]);
10589
- _optionalChain([win, 'optionalAccess', _245 => _245.addEventListener, 'call', _246 => _246("online", onVisibilityChange)]);
10590
- _optionalChain([win, 'optionalAccess', _247 => _247.addEventListener, 'call', _248 => _248("focus", pollNowIfStale)]);
10625
+ _optionalChain([doc, 'optionalAccess', _253 => _253.addEventListener, 'call', _254 => _254("visibilitychange", onVisibilityChange)]);
10626
+ _optionalChain([win, 'optionalAccess', _255 => _255.addEventListener, 'call', _256 => _256("online", onVisibilityChange)]);
10627
+ _optionalChain([win, 'optionalAccess', _257 => _257.addEventListener, 'call', _258 => _258("focus", pollNowIfStale)]);
10591
10628
  fsm.start();
10592
10629
  return {
10593
10630
  inc,
@@ -10715,5 +10752,5 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
10715
10752
 
10716
10753
 
10717
10754
 
10718
- exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; 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.ackOp = ackOp; 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.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; 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.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; 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.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
10755
+ exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; 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.ackOp = ackOp; 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.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; 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.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; 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.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; 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.withTimeout = withTimeout;
10719
10756
  //# sourceMappingURL=index.cjs.map