@liveblocks/core 2.18.3 → 2.18.4-uns2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.mjs → index.cjs} +351 -271
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +73 -9
- package/dist/index.d.ts +73 -9
- package/dist/index.js +350 -270
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
2
|
var __export = (target, all) => {
|
|
3
3
|
for (var name in all)
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -6,8 +6,8 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "2.18.
|
|
10
|
-
var PKG_FORMAT = "
|
|
9
|
+
var PKG_VERSION = "2.18.4-uns2";
|
|
10
|
+
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
13
13
|
var g = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
@@ -187,6 +187,12 @@ function keys(obj) {
|
|
|
187
187
|
function values(obj) {
|
|
188
188
|
return Object.values(obj);
|
|
189
189
|
}
|
|
190
|
+
function create(obj, descriptors) {
|
|
191
|
+
if (typeof descriptors !== "undefined") {
|
|
192
|
+
return Object.create(obj, descriptors);
|
|
193
|
+
}
|
|
194
|
+
return Object.create(obj);
|
|
195
|
+
}
|
|
190
196
|
function mapValues(obj, mapFn) {
|
|
191
197
|
const result = {};
|
|
192
198
|
for (const pair of Object.entries(obj)) {
|
|
@@ -266,8 +272,8 @@ function memoizeOnSuccess(factoryFn) {
|
|
|
266
272
|
|
|
267
273
|
// src/lib/autoRetry.ts
|
|
268
274
|
var HttpError = class _HttpError extends Error {
|
|
269
|
-
|
|
270
|
-
|
|
275
|
+
response;
|
|
276
|
+
details;
|
|
271
277
|
constructor(message, response, details) {
|
|
272
278
|
super(message);
|
|
273
279
|
this.name = "HttpError";
|
|
@@ -278,7 +284,7 @@ var HttpError = class _HttpError extends Error {
|
|
|
278
284
|
let bodyAsText;
|
|
279
285
|
try {
|
|
280
286
|
bodyAsText = await response.text();
|
|
281
|
-
} catch
|
|
287
|
+
} catch {
|
|
282
288
|
}
|
|
283
289
|
const bodyAsJson = bodyAsText ? tryParseJson(bodyAsText) : void 0;
|
|
284
290
|
let bodyAsJsonObject;
|
|
@@ -286,8 +292,8 @@ var HttpError = class _HttpError extends Error {
|
|
|
286
292
|
bodyAsJsonObject = bodyAsJson;
|
|
287
293
|
}
|
|
288
294
|
let message = "";
|
|
289
|
-
message ||= typeof
|
|
290
|
-
message ||= typeof
|
|
295
|
+
message ||= typeof bodyAsJsonObject?.message === "string" ? bodyAsJsonObject.message : "";
|
|
296
|
+
message ||= typeof bodyAsJsonObject?.error === "string" ? bodyAsJsonObject.error : "";
|
|
291
297
|
if (bodyAsJson === void 0) {
|
|
292
298
|
message ||= bodyAsText || "";
|
|
293
299
|
}
|
|
@@ -295,7 +301,7 @@ var HttpError = class _HttpError extends Error {
|
|
|
295
301
|
let path;
|
|
296
302
|
try {
|
|
297
303
|
path = new URL(response.url).pathname;
|
|
298
|
-
} catch
|
|
304
|
+
} catch {
|
|
299
305
|
}
|
|
300
306
|
message += path !== void 0 ? ` (got status ${response.status} from ${path})` : ` (got status ${response.status})`;
|
|
301
307
|
const details = bodyAsJsonObject;
|
|
@@ -324,7 +330,7 @@ async function autoRetry(promiseFn, maxTries, backoff, shouldStopRetrying = DONT
|
|
|
324
330
|
throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
|
|
325
331
|
}
|
|
326
332
|
}
|
|
327
|
-
const delay =
|
|
333
|
+
const delay = backoff[attempt - 1] ?? fallbackBackoff;
|
|
328
334
|
warn(
|
|
329
335
|
`Attempt ${attempt} was unsuccessful. Retrying in ${delay} milliseconds.`
|
|
330
336
|
);
|
|
@@ -369,7 +375,7 @@ function makeEventSource() {
|
|
|
369
375
|
res(event);
|
|
370
376
|
}
|
|
371
377
|
});
|
|
372
|
-
}).finally(() =>
|
|
378
|
+
}).finally(() => unsub?.());
|
|
373
379
|
}
|
|
374
380
|
function notify(event) {
|
|
375
381
|
let called = false;
|
|
@@ -486,12 +492,12 @@ function merge(target, patch) {
|
|
|
486
492
|
}
|
|
487
493
|
var AbstractSignal = class {
|
|
488
494
|
/** @internal */
|
|
489
|
-
|
|
495
|
+
equals;
|
|
490
496
|
#eventSource;
|
|
491
497
|
/** @internal */
|
|
492
|
-
|
|
498
|
+
[kSinks];
|
|
493
499
|
constructor(equals) {
|
|
494
|
-
this.equals =
|
|
500
|
+
this.equals = equals ?? Object.is;
|
|
495
501
|
this.#eventSource = makeEventSource();
|
|
496
502
|
this[kSinks] = /* @__PURE__ */ new Set();
|
|
497
503
|
this.get = this.get.bind(this);
|
|
@@ -560,7 +566,7 @@ var Signal = class extends AbstractSignal {
|
|
|
560
566
|
this.#value = "(disposed)";
|
|
561
567
|
}
|
|
562
568
|
get() {
|
|
563
|
-
|
|
569
|
+
trackedReads?.add(this);
|
|
564
570
|
return this.#value;
|
|
565
571
|
}
|
|
566
572
|
set(newValue) {
|
|
@@ -670,7 +676,7 @@ var DerivedSignal = class _DerivedSignal extends AbstractSignal {
|
|
|
670
676
|
if (this.#dirty) {
|
|
671
677
|
this.#recompute();
|
|
672
678
|
}
|
|
673
|
-
|
|
679
|
+
trackedReads?.add(this);
|
|
674
680
|
return this.#prevValue;
|
|
675
681
|
}
|
|
676
682
|
/**
|
|
@@ -700,7 +706,7 @@ var MutableSignal = class extends AbstractSignal {
|
|
|
700
706
|
this.#state = "(disposed)";
|
|
701
707
|
}
|
|
702
708
|
get() {
|
|
703
|
-
|
|
709
|
+
trackedReads?.add(this);
|
|
704
710
|
return this.#state;
|
|
705
711
|
}
|
|
706
712
|
/**
|
|
@@ -747,10 +753,10 @@ function stringifyOrLog(value) {
|
|
|
747
753
|
// src/lib/batch.ts
|
|
748
754
|
var DEFAULT_SIZE = 50;
|
|
749
755
|
var BatchCall = class {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
756
|
+
input;
|
|
757
|
+
resolve;
|
|
758
|
+
reject;
|
|
759
|
+
promise;
|
|
754
760
|
constructor(input) {
|
|
755
761
|
this.input = input;
|
|
756
762
|
const { promise, resolve, reject } = Promise_withResolvers();
|
|
@@ -759,16 +765,16 @@ var BatchCall = class {
|
|
|
759
765
|
this.reject = reject;
|
|
760
766
|
}
|
|
761
767
|
};
|
|
762
|
-
var Batch =
|
|
768
|
+
var Batch = class {
|
|
763
769
|
#queue = [];
|
|
764
770
|
#callback;
|
|
765
771
|
#size;
|
|
766
772
|
#delay;
|
|
767
773
|
#delayTimeoutId;
|
|
768
|
-
|
|
769
|
-
constructor(callback, options) {
|
|
774
|
+
error = false;
|
|
775
|
+
constructor(callback, options) {
|
|
770
776
|
this.#callback = callback;
|
|
771
|
-
this.#size =
|
|
777
|
+
this.#size = options.size ?? DEFAULT_SIZE;
|
|
772
778
|
this.#delay = options.delay;
|
|
773
779
|
}
|
|
774
780
|
#clearDelayTimeout() {
|
|
@@ -795,7 +801,7 @@ var Batch = (_class = class {
|
|
|
795
801
|
const results = await this.#callback(inputs);
|
|
796
802
|
this.error = false;
|
|
797
803
|
calls.forEach((call, index) => {
|
|
798
|
-
const result =
|
|
804
|
+
const result = results?.[index];
|
|
799
805
|
if (!Array.isArray(results)) {
|
|
800
806
|
call.reject(new Error("Callback must return an array."));
|
|
801
807
|
} else if (calls.length !== results.length) {
|
|
@@ -834,7 +840,7 @@ var Batch = (_class = class {
|
|
|
834
840
|
this.error = false;
|
|
835
841
|
this.#clearDelayTimeout();
|
|
836
842
|
}
|
|
837
|
-
}
|
|
843
|
+
};
|
|
838
844
|
function createBatchStore(batch2) {
|
|
839
845
|
const signal = new MutableSignal(/* @__PURE__ */ new Map());
|
|
840
846
|
function getCacheKey(args) {
|
|
@@ -950,7 +956,7 @@ var DefaultMap = class extends Map {
|
|
|
950
956
|
if (super.has(key)) {
|
|
951
957
|
return super.get(key);
|
|
952
958
|
} else {
|
|
953
|
-
const fn =
|
|
959
|
+
const fn = defaultFn ?? this.#defaultFn ?? raise("DefaultMap used without a factory function");
|
|
954
960
|
const value = fn(key);
|
|
955
961
|
this.set(key, value);
|
|
956
962
|
return value;
|
|
@@ -1075,7 +1081,7 @@ function urljoin(baseUrl, path, params) {
|
|
|
1075
1081
|
}
|
|
1076
1082
|
function url(strings, ...values2) {
|
|
1077
1083
|
return strings.reduce(
|
|
1078
|
-
(result, str, i) => result + encodeURIComponent(
|
|
1084
|
+
(result, str, i) => result + encodeURIComponent(values2[i - 1] ?? "") + str
|
|
1079
1085
|
);
|
|
1080
1086
|
}
|
|
1081
1087
|
|
|
@@ -1163,8 +1169,8 @@ function createApiClient({
|
|
|
1163
1169
|
}
|
|
1164
1170
|
}
|
|
1165
1171
|
async function createThread(options) {
|
|
1166
|
-
const commentId =
|
|
1167
|
-
const threadId =
|
|
1172
|
+
const commentId = options.commentId ?? createCommentId();
|
|
1173
|
+
const threadId = options.threadId ?? createThreadId();
|
|
1168
1174
|
const thread = await httpClient.post(
|
|
1169
1175
|
url`/v2/c/rooms/${options.roomId}/threads`,
|
|
1170
1176
|
await authManager.getAuthValue({
|
|
@@ -1228,7 +1234,7 @@ function createApiClient({
|
|
|
1228
1234
|
);
|
|
1229
1235
|
}
|
|
1230
1236
|
async function createComment(options) {
|
|
1231
|
-
const commentId =
|
|
1237
|
+
const commentId = options.commentId ?? createCommentId();
|
|
1232
1238
|
const comment = await httpClient.post(
|
|
1233
1239
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments`,
|
|
1234
1240
|
await authManager.getAuthValue({
|
|
@@ -1312,11 +1318,11 @@ function createApiClient({
|
|
|
1312
1318
|
`Upload of attachment ${options.attachment.id} was aborted.`,
|
|
1313
1319
|
"AbortError"
|
|
1314
1320
|
) : void 0;
|
|
1315
|
-
if (
|
|
1321
|
+
if (abortSignal?.aborted) {
|
|
1316
1322
|
throw abortError;
|
|
1317
1323
|
}
|
|
1318
1324
|
const handleRetryError = (err) => {
|
|
1319
|
-
if (
|
|
1325
|
+
if (abortSignal?.aborted) {
|
|
1320
1326
|
throw abortError;
|
|
1321
1327
|
}
|
|
1322
1328
|
if (err instanceof HttpError && err.status === 413) {
|
|
@@ -1388,7 +1394,7 @@ function createApiClient({
|
|
|
1388
1394
|
try {
|
|
1389
1395
|
uploadId = createMultiPartUpload.uploadId;
|
|
1390
1396
|
const parts = splitFileIntoParts(attachment.file);
|
|
1391
|
-
if (
|
|
1397
|
+
if (abortSignal?.aborted) {
|
|
1392
1398
|
throw abortError;
|
|
1393
1399
|
}
|
|
1394
1400
|
const batches = chunk(parts, 5);
|
|
@@ -1415,7 +1421,7 @@ function createApiClient({
|
|
|
1415
1421
|
}
|
|
1416
1422
|
uploadedParts.push(...await Promise.all(uploadedPartsPromises));
|
|
1417
1423
|
}
|
|
1418
|
-
if (
|
|
1424
|
+
if (abortSignal?.aborted) {
|
|
1419
1425
|
throw abortError;
|
|
1420
1426
|
}
|
|
1421
1427
|
const sortedUploadedParts = uploadedParts.sort(
|
|
@@ -1431,7 +1437,7 @@ function createApiClient({
|
|
|
1431
1437
|
{ signal: abortSignal }
|
|
1432
1438
|
);
|
|
1433
1439
|
} catch (error3) {
|
|
1434
|
-
if (uploadId &&
|
|
1440
|
+
if (uploadId && error3?.name && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
|
|
1435
1441
|
try {
|
|
1436
1442
|
await httpClient.rawDelete(
|
|
1437
1443
|
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}`,
|
|
@@ -1460,7 +1466,7 @@ function createApiClient({
|
|
|
1460
1466
|
{ attachmentIds }
|
|
1461
1467
|
);
|
|
1462
1468
|
return urls.map(
|
|
1463
|
-
(url2) =>
|
|
1469
|
+
(url2) => url2 ?? new Error("There was an error while getting this attachment's URL")
|
|
1464
1470
|
);
|
|
1465
1471
|
},
|
|
1466
1472
|
{ delay: 50 }
|
|
@@ -1661,7 +1667,7 @@ function createApiClient({
|
|
|
1661
1667
|
url`/v2/c/inbox-notifications`,
|
|
1662
1668
|
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
1663
1669
|
{
|
|
1664
|
-
cursor:
|
|
1670
|
+
cursor: options?.cursor,
|
|
1665
1671
|
limit: PAGE_SIZE
|
|
1666
1672
|
}
|
|
1667
1673
|
);
|
|
@@ -1748,7 +1754,7 @@ function createApiClient({
|
|
|
1748
1754
|
url`/v2/c/notification-settings`,
|
|
1749
1755
|
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
1750
1756
|
void 0,
|
|
1751
|
-
{ signal:
|
|
1757
|
+
{ signal: options?.signal }
|
|
1752
1758
|
);
|
|
1753
1759
|
}
|
|
1754
1760
|
async function updateUserNotificationSettings(settings) {
|
|
@@ -1760,7 +1766,7 @@ function createApiClient({
|
|
|
1760
1766
|
}
|
|
1761
1767
|
async function getUserThreads_experimental(options) {
|
|
1762
1768
|
let query;
|
|
1763
|
-
if (
|
|
1769
|
+
if (options?.query) {
|
|
1764
1770
|
query = objectToQuery(options.query);
|
|
1765
1771
|
}
|
|
1766
1772
|
const PAGE_SIZE = 50;
|
|
@@ -1768,7 +1774,7 @@ function createApiClient({
|
|
|
1768
1774
|
url`/v2/c/threads`,
|
|
1769
1775
|
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
1770
1776
|
{
|
|
1771
|
-
cursor:
|
|
1777
|
+
cursor: options?.cursor,
|
|
1772
1778
|
query,
|
|
1773
1779
|
limit: PAGE_SIZE
|
|
1774
1780
|
}
|
|
@@ -1897,7 +1903,7 @@ var HttpClient = class {
|
|
|
1897
1903
|
// These headers are default, but can be overriden by custom headers
|
|
1898
1904
|
"Content-Type": "application/json; charset=utf-8",
|
|
1899
1905
|
// Possible header overrides
|
|
1900
|
-
...
|
|
1906
|
+
...options?.headers,
|
|
1901
1907
|
// Cannot be overriden by custom headers
|
|
1902
1908
|
Authorization: `Bearer ${getBearerTokenFromAuthValue(authValue)}`,
|
|
1903
1909
|
"X-LB-Client": PKG_VERSION || "dev"
|
|
@@ -1926,7 +1932,7 @@ var HttpClient = class {
|
|
|
1926
1932
|
let body;
|
|
1927
1933
|
try {
|
|
1928
1934
|
body = await response.json();
|
|
1929
|
-
} catch
|
|
1935
|
+
} catch {
|
|
1930
1936
|
body = {};
|
|
1931
1937
|
}
|
|
1932
1938
|
return body;
|
|
@@ -2102,7 +2108,7 @@ var SafeContext = class {
|
|
|
2102
2108
|
};
|
|
2103
2109
|
var nextId = 1;
|
|
2104
2110
|
var FSM = class {
|
|
2105
|
-
|
|
2111
|
+
id;
|
|
2106
2112
|
// Indicates whether this state machine is still being configured, has
|
|
2107
2113
|
// started, or has terminated
|
|
2108
2114
|
#runningState;
|
|
@@ -2111,7 +2117,7 @@ var FSM = class {
|
|
|
2111
2117
|
#currentStateOrNull;
|
|
2112
2118
|
#allowedTransitions;
|
|
2113
2119
|
#eventHub;
|
|
2114
|
-
|
|
2120
|
+
events;
|
|
2115
2121
|
//
|
|
2116
2122
|
// The cleanup stack is a stack of (optional) callback functions that will
|
|
2117
2123
|
// be run when exiting the current state. If a state (or state group) does
|
|
@@ -2372,7 +2378,7 @@ var FSM = class {
|
|
|
2372
2378
|
});
|
|
2373
2379
|
}
|
|
2374
2380
|
#getTargetFn(eventName) {
|
|
2375
|
-
return
|
|
2381
|
+
return this.#allowedTransitions.get(this.currentState)?.get(eventName);
|
|
2376
2382
|
}
|
|
2377
2383
|
/**
|
|
2378
2384
|
* Exits the current state, and executes any necessary cleanup functions.
|
|
@@ -2387,9 +2393,9 @@ var FSM = class {
|
|
|
2387
2393
|
#exit(levels) {
|
|
2388
2394
|
this.#eventHub.willExitState.notify(this.currentState);
|
|
2389
2395
|
this.#currentContext.allowPatching((patchableContext) => {
|
|
2390
|
-
levels =
|
|
2396
|
+
levels = levels ?? this.#cleanupStack.length;
|
|
2391
2397
|
for (let i = 0; i < levels; i++) {
|
|
2392
|
-
|
|
2398
|
+
this.#cleanupStack.pop()?.(patchableContext);
|
|
2393
2399
|
}
|
|
2394
2400
|
});
|
|
2395
2401
|
}
|
|
@@ -2400,12 +2406,12 @@ var FSM = class {
|
|
|
2400
2406
|
#enter(levels) {
|
|
2401
2407
|
const enterPatterns = patterns(
|
|
2402
2408
|
this.currentState,
|
|
2403
|
-
|
|
2409
|
+
levels ?? this.currentState.split(".").length + 1
|
|
2404
2410
|
);
|
|
2405
2411
|
this.#currentContext.allowPatching((patchableContext) => {
|
|
2406
2412
|
for (const pattern of enterPatterns) {
|
|
2407
2413
|
const enterFn = this.#enterFns.get(pattern);
|
|
2408
|
-
const cleanupFn =
|
|
2414
|
+
const cleanupFn = enterFn?.(patchableContext);
|
|
2409
2415
|
if (typeof cleanupFn === "function") {
|
|
2410
2416
|
this.#cleanupStack.push(cleanupFn);
|
|
2411
2417
|
} else {
|
|
@@ -2566,7 +2572,7 @@ var StopRetrying = class extends Error {
|
|
|
2566
2572
|
}
|
|
2567
2573
|
};
|
|
2568
2574
|
function nextBackoffDelay(currentDelay, delays) {
|
|
2569
|
-
return
|
|
2575
|
+
return delays.find((delay) => delay > currentDelay) ?? delays[delays.length - 1];
|
|
2570
2576
|
}
|
|
2571
2577
|
function increaseBackoffDelay(context) {
|
|
2572
2578
|
context.patch({
|
|
@@ -2799,7 +2805,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
2799
2805
|
}
|
|
2800
2806
|
function waitForActorId(event) {
|
|
2801
2807
|
const serverMsg = tryParseJson(event.data);
|
|
2802
|
-
if (
|
|
2808
|
+
if (serverMsg?.type === 104 /* ROOM_STATE */) {
|
|
2803
2809
|
didReceiveActor();
|
|
2804
2810
|
}
|
|
2805
2811
|
}
|
|
@@ -2908,12 +2914,12 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
2908
2914
|
const sendHeartbeat = {
|
|
2909
2915
|
target: "@ok.awaiting-pong",
|
|
2910
2916
|
effect: (ctx) => {
|
|
2911
|
-
|
|
2917
|
+
ctx.socket?.send("ping");
|
|
2912
2918
|
}
|
|
2913
2919
|
};
|
|
2914
2920
|
const maybeHeartbeat = () => {
|
|
2915
2921
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
2916
|
-
const canZombie =
|
|
2922
|
+
const canZombie = doc?.visibilityState === "hidden" && delegates.canZombie();
|
|
2917
2923
|
return canZombie ? "@idle.zombie" : sendHeartbeat;
|
|
2918
2924
|
};
|
|
2919
2925
|
machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
|
|
@@ -2952,7 +2958,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
2952
2958
|
// socket, or not. So always check to see if the socket is still OPEN or
|
|
2953
2959
|
// not. When still OPEN, don't transition.
|
|
2954
2960
|
EXPLICIT_SOCKET_ERROR: (_, context) => {
|
|
2955
|
-
if (
|
|
2961
|
+
if (context.socket?.readyState === 1) {
|
|
2956
2962
|
return null;
|
|
2957
2963
|
}
|
|
2958
2964
|
return {
|
|
@@ -2995,7 +3001,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
2995
3001
|
if (typeof document !== "undefined") {
|
|
2996
3002
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
2997
3003
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
2998
|
-
const root =
|
|
3004
|
+
const root = win ?? doc;
|
|
2999
3005
|
machine.onEnter("*", (ctx) => {
|
|
3000
3006
|
function onNetworkOffline() {
|
|
3001
3007
|
machine.send({ type: "NAVIGATOR_OFFLINE" });
|
|
@@ -3004,17 +3010,17 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
3004
3010
|
machine.send({ type: "NAVIGATOR_ONLINE" });
|
|
3005
3011
|
}
|
|
3006
3012
|
function onVisibilityChange() {
|
|
3007
|
-
if (
|
|
3013
|
+
if (doc?.visibilityState === "visible") {
|
|
3008
3014
|
machine.send({ type: "WINDOW_GOT_FOCUS" });
|
|
3009
3015
|
}
|
|
3010
3016
|
}
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3017
|
+
win?.addEventListener("online", onNetworkBackOnline);
|
|
3018
|
+
win?.addEventListener("offline", onNetworkOffline);
|
|
3019
|
+
root?.addEventListener("visibilitychange", onVisibilityChange);
|
|
3014
3020
|
return () => {
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3021
|
+
root?.removeEventListener("visibilitychange", onVisibilityChange);
|
|
3022
|
+
win?.removeEventListener("online", onNetworkBackOnline);
|
|
3023
|
+
win?.removeEventListener("offline", onNetworkOffline);
|
|
3018
3024
|
teardownSocket(ctx.socket);
|
|
3019
3025
|
};
|
|
3020
3026
|
});
|
|
@@ -3042,7 +3048,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
3042
3048
|
var ManagedSocket = class {
|
|
3043
3049
|
#machine;
|
|
3044
3050
|
#cleanups;
|
|
3045
|
-
|
|
3051
|
+
events;
|
|
3046
3052
|
constructor(delegates, enableDebugLogging = false, waitForActorId = true) {
|
|
3047
3053
|
const { machine, events, cleanups } = createConnectionStateMachine(
|
|
3048
3054
|
delegates,
|
|
@@ -3055,7 +3061,7 @@ var ManagedSocket = class {
|
|
|
3055
3061
|
getStatus() {
|
|
3056
3062
|
try {
|
|
3057
3063
|
return toNewConnectionStatus(this.#machine);
|
|
3058
|
-
} catch
|
|
3064
|
+
} catch {
|
|
3059
3065
|
return "initial";
|
|
3060
3066
|
}
|
|
3061
3067
|
}
|
|
@@ -3103,7 +3109,7 @@ var ManagedSocket = class {
|
|
|
3103
3109
|
* message if this is somehow impossible.
|
|
3104
3110
|
*/
|
|
3105
3111
|
send(data) {
|
|
3106
|
-
const socket =
|
|
3112
|
+
const socket = this.#machine.context?.socket;
|
|
3107
3113
|
if (socket === null) {
|
|
3108
3114
|
warn("Cannot send: not connected yet", data);
|
|
3109
3115
|
} else if (socket.readyState !== 1) {
|
|
@@ -3207,7 +3213,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
3207
3213
|
return void 0;
|
|
3208
3214
|
}
|
|
3209
3215
|
async function makeAuthRequest(options) {
|
|
3210
|
-
const fetcher =
|
|
3216
|
+
const fetcher = authOptions.polyfills?.fetch ?? (typeof window === "undefined" ? void 0 : window.fetch);
|
|
3211
3217
|
if (authentication.type === "private") {
|
|
3212
3218
|
if (fetcher === void 0) {
|
|
3213
3219
|
throw new StopRetrying(
|
|
@@ -3223,7 +3229,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
3223
3229
|
"The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
|
|
3224
3230
|
);
|
|
3225
3231
|
}
|
|
3226
|
-
|
|
3232
|
+
onAuthenticate?.(parsed.parsed);
|
|
3227
3233
|
return parsed;
|
|
3228
3234
|
}
|
|
3229
3235
|
if (authentication.type === "custom") {
|
|
@@ -3231,7 +3237,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
3231
3237
|
if (response && typeof response === "object") {
|
|
3232
3238
|
if (typeof response.token === "string") {
|
|
3233
3239
|
const parsed = parseAuthToken(response.token);
|
|
3234
|
-
|
|
3240
|
+
onAuthenticate?.(parsed.parsed);
|
|
3235
3241
|
return parsed;
|
|
3236
3242
|
} else if (typeof response.error === "string") {
|
|
3237
3243
|
const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
|
|
@@ -3392,7 +3398,7 @@ function sendToPanel(message, options) {
|
|
|
3392
3398
|
...message,
|
|
3393
3399
|
source: "liveblocks-devtools-client"
|
|
3394
3400
|
};
|
|
3395
|
-
if (!(
|
|
3401
|
+
if (!(options?.force || _bridgeActive)) {
|
|
3396
3402
|
return;
|
|
3397
3403
|
}
|
|
3398
3404
|
window.postMessage(fullMsg, "*");
|
|
@@ -3400,7 +3406,7 @@ function sendToPanel(message, options) {
|
|
|
3400
3406
|
var eventSource = makeEventSource();
|
|
3401
3407
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
3402
3408
|
window.addEventListener("message", (event) => {
|
|
3403
|
-
if (event.source === window &&
|
|
3409
|
+
if (event.source === window && event.data?.source === "liveblocks-devtools-panel") {
|
|
3404
3410
|
eventSource.notify(event.data);
|
|
3405
3411
|
} else {
|
|
3406
3412
|
}
|
|
@@ -3444,7 +3450,7 @@ function setupDevTools(getAllRooms) {
|
|
|
3444
3450
|
}
|
|
3445
3451
|
var unsubsByRoomId = /* @__PURE__ */ new Map();
|
|
3446
3452
|
function stopSyncStream(roomId) {
|
|
3447
|
-
const unsubs =
|
|
3453
|
+
const unsubs = unsubsByRoomId.get(roomId) ?? [];
|
|
3448
3454
|
unsubsByRoomId.delete(roomId);
|
|
3449
3455
|
for (const unsub of unsubs) {
|
|
3450
3456
|
unsub();
|
|
@@ -3542,7 +3548,7 @@ function fullSync(room) {
|
|
|
3542
3548
|
msg: "room::sync::full",
|
|
3543
3549
|
roomId: room.id,
|
|
3544
3550
|
status: room.getStatus(),
|
|
3545
|
-
storage:
|
|
3551
|
+
storage: root?.toTreeNode("root").payload ?? null,
|
|
3546
3552
|
me,
|
|
3547
3553
|
others
|
|
3548
3554
|
});
|
|
@@ -3597,6 +3603,73 @@ function unlinkDevTools(roomId) {
|
|
|
3597
3603
|
});
|
|
3598
3604
|
}
|
|
3599
3605
|
|
|
3606
|
+
// src/protocol/UserNotificationSettings.ts
|
|
3607
|
+
var kPrivate = Symbol("user-notification-settings-private");
|
|
3608
|
+
function createUserNotificationSettings(plain) {
|
|
3609
|
+
const channels = [
|
|
3610
|
+
"email",
|
|
3611
|
+
"slack",
|
|
3612
|
+
"teams",
|
|
3613
|
+
"webPush"
|
|
3614
|
+
];
|
|
3615
|
+
const descriptors = {
|
|
3616
|
+
[kPrivate]: {
|
|
3617
|
+
value: {
|
|
3618
|
+
__plain__: plain
|
|
3619
|
+
},
|
|
3620
|
+
enumerable: false
|
|
3621
|
+
}
|
|
3622
|
+
};
|
|
3623
|
+
for (const channel of channels) {
|
|
3624
|
+
descriptors[channel] = {
|
|
3625
|
+
enumerable: true,
|
|
3626
|
+
/**
|
|
3627
|
+
* In the TypeScript standard library definitions, the built-in interface for a property descriptor
|
|
3628
|
+
* does not include a specialized type for the “this” context in the getter or setter functions.
|
|
3629
|
+
* As a result, both the get and set methods implicitly have this: any.
|
|
3630
|
+
* The reason is that property descriptors in JavaScript are used across various objects with
|
|
3631
|
+
* no enforced shape for this. And so the standard library definitions have to remain as broad as possible
|
|
3632
|
+
* to support any valid JavaScript usage (e.g `Object.defineProperty`).
|
|
3633
|
+
*
|
|
3634
|
+
* So we can safely tells that this getter is typed as `this: UserNotificationSettings` because we're
|
|
3635
|
+
* creating a well known shaped object → `UserNotificationSettings`.
|
|
3636
|
+
*/
|
|
3637
|
+
get() {
|
|
3638
|
+
const value = this[kPrivate].__plain__[channel];
|
|
3639
|
+
if (typeof value === "undefined") {
|
|
3640
|
+
error2(
|
|
3641
|
+
`In order to use the '${channel}' channel, please set up your project first. For more information https://liveblocks.io/docs/errors/enable-a-notification-channel`
|
|
3642
|
+
);
|
|
3643
|
+
return null;
|
|
3644
|
+
}
|
|
3645
|
+
return value;
|
|
3646
|
+
}
|
|
3647
|
+
};
|
|
3648
|
+
}
|
|
3649
|
+
return create(null, descriptors);
|
|
3650
|
+
}
|
|
3651
|
+
function patchUserNotificationSettings(existing, patch) {
|
|
3652
|
+
const outcoming = createUserNotificationSettings({
|
|
3653
|
+
...existing[kPrivate].__plain__
|
|
3654
|
+
});
|
|
3655
|
+
for (const channel of keys(patch)) {
|
|
3656
|
+
const updates = patch[channel];
|
|
3657
|
+
if (updates !== void 0) {
|
|
3658
|
+
const kindUpdates = Object.fromEntries(
|
|
3659
|
+
entries(updates).filter(([, value]) => value !== void 0)
|
|
3660
|
+
);
|
|
3661
|
+
outcoming[kPrivate].__plain__[channel] = {
|
|
3662
|
+
...outcoming[kPrivate].__plain__[channel],
|
|
3663
|
+
...kindUpdates
|
|
3664
|
+
};
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
return outcoming;
|
|
3668
|
+
}
|
|
3669
|
+
function isNotificationChannelEnabled(settings) {
|
|
3670
|
+
return settings !== null ? values(settings).every((enabled) => enabled === true) : false;
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3600
3673
|
// src/lib/position.ts
|
|
3601
3674
|
var MIN_CODE = 32;
|
|
3602
3675
|
var MAX_CODE = 126;
|
|
@@ -3966,7 +4039,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
3966
4039
|
return [
|
|
3967
4040
|
{
|
|
3968
4041
|
type: 8 /* CREATE_REGISTER */,
|
|
3969
|
-
opId:
|
|
4042
|
+
opId: pool?.generateOpId(),
|
|
3970
4043
|
id: this._id,
|
|
3971
4044
|
parentId,
|
|
3972
4045
|
parentKey,
|
|
@@ -4002,7 +4075,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
4002
4075
|
_toTreeNode(key) {
|
|
4003
4076
|
return {
|
|
4004
4077
|
type: "Json",
|
|
4005
|
-
id:
|
|
4078
|
+
id: this._id ?? nanoid(),
|
|
4006
4079
|
key,
|
|
4007
4080
|
payload: this.#data
|
|
4008
4081
|
};
|
|
@@ -4072,7 +4145,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4072
4145
|
const ops = [];
|
|
4073
4146
|
const op = {
|
|
4074
4147
|
id: this._id,
|
|
4075
|
-
opId:
|
|
4148
|
+
opId: pool?.generateOpId(),
|
|
4076
4149
|
type: 2 /* CREATE_LIST */,
|
|
4077
4150
|
parentId,
|
|
4078
4151
|
parentKey
|
|
@@ -4343,7 +4416,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4343
4416
|
#applyInsertUndoRedo(op) {
|
|
4344
4417
|
const { id, parentKey: key } = op;
|
|
4345
4418
|
const child = creationOpToLiveNode(op);
|
|
4346
|
-
if (
|
|
4419
|
+
if (this._pool?.getNode(id) !== void 0) {
|
|
4347
4420
|
return { modified: false };
|
|
4348
4421
|
}
|
|
4349
4422
|
child._attach(id, nn(this._pool));
|
|
@@ -4351,8 +4424,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4351
4424
|
const existingItemIndex = this._indexOfPosition(key);
|
|
4352
4425
|
let newKey = key;
|
|
4353
4426
|
if (existingItemIndex !== -1) {
|
|
4354
|
-
const before2 =
|
|
4355
|
-
const after2 =
|
|
4427
|
+
const before2 = this.#items[existingItemIndex]?._parentPos;
|
|
4428
|
+
const after2 = this.#items[existingItemIndex + 1]?._parentPos;
|
|
4356
4429
|
newKey = makePosition(before2, after2);
|
|
4357
4430
|
child._setParentLink(this, newKey);
|
|
4358
4431
|
}
|
|
@@ -4366,7 +4439,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4366
4439
|
#applySetUndoRedo(op) {
|
|
4367
4440
|
const { id, parentKey: key } = op;
|
|
4368
4441
|
const child = creationOpToLiveNode(op);
|
|
4369
|
-
if (
|
|
4442
|
+
if (this._pool?.getNode(id) !== void 0) {
|
|
4370
4443
|
return { modified: false };
|
|
4371
4444
|
}
|
|
4372
4445
|
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -4487,7 +4560,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4487
4560
|
} else {
|
|
4488
4561
|
this.#items[existingItemIndex]._setParentLink(
|
|
4489
4562
|
this,
|
|
4490
|
-
makePosition(newKey,
|
|
4563
|
+
makePosition(newKey, this.#items[existingItemIndex + 1]?._parentPos)
|
|
4491
4564
|
);
|
|
4492
4565
|
const previousIndex = this.#items.indexOf(child);
|
|
4493
4566
|
child._setParentLink(this, newKey);
|
|
@@ -4512,7 +4585,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4512
4585
|
if (existingItemIndex !== -1) {
|
|
4513
4586
|
this.#items[existingItemIndex]._setParentLink(
|
|
4514
4587
|
this,
|
|
4515
|
-
makePosition(newKey,
|
|
4588
|
+
makePosition(newKey, this.#items[existingItemIndex + 1]?._parentPos)
|
|
4516
4589
|
);
|
|
4517
4590
|
}
|
|
4518
4591
|
child._setParentLink(this, newKey);
|
|
@@ -4531,7 +4604,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4531
4604
|
if (existingItemIndex !== -1) {
|
|
4532
4605
|
this.#items[existingItemIndex]._setParentLink(
|
|
4533
4606
|
this,
|
|
4534
|
-
makePosition(newKey,
|
|
4607
|
+
makePosition(newKey, this.#items[existingItemIndex + 1]?._parentPos)
|
|
4535
4608
|
);
|
|
4536
4609
|
}
|
|
4537
4610
|
child._setParentLink(this, newKey);
|
|
@@ -4558,7 +4631,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4558
4631
|
if (existingItemIndex !== -1) {
|
|
4559
4632
|
this.#items[existingItemIndex]._setParentLink(
|
|
4560
4633
|
this,
|
|
4561
|
-
makePosition(newKey,
|
|
4634
|
+
makePosition(newKey, this.#items[existingItemIndex + 1]?._parentPos)
|
|
4562
4635
|
);
|
|
4563
4636
|
}
|
|
4564
4637
|
child._setParentLink(this, newKey);
|
|
@@ -4616,7 +4689,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4616
4689
|
* @param element The element to add to the end of the LiveList.
|
|
4617
4690
|
*/
|
|
4618
4691
|
push(element) {
|
|
4619
|
-
|
|
4692
|
+
this._pool?.assertStorageIsWritable();
|
|
4620
4693
|
return this.insert(element, this.length);
|
|
4621
4694
|
}
|
|
4622
4695
|
/**
|
|
@@ -4625,7 +4698,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4625
4698
|
* @param index The index at which you want to insert the element.
|
|
4626
4699
|
*/
|
|
4627
4700
|
insert(element, index) {
|
|
4628
|
-
|
|
4701
|
+
this._pool?.assertStorageIsWritable();
|
|
4629
4702
|
if (index < 0 || index > this.#items.length) {
|
|
4630
4703
|
throw new Error(
|
|
4631
4704
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
@@ -4655,7 +4728,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4655
4728
|
* @param targetIndex The index where the element should be after moving.
|
|
4656
4729
|
*/
|
|
4657
4730
|
move(index, targetIndex) {
|
|
4658
|
-
|
|
4731
|
+
this._pool?.assertStorageIsWritable();
|
|
4659
4732
|
if (targetIndex < 0) {
|
|
4660
4733
|
throw new Error("targetIndex cannot be less than 0");
|
|
4661
4734
|
}
|
|
@@ -4713,7 +4786,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4713
4786
|
* @param index The index of the element to delete
|
|
4714
4787
|
*/
|
|
4715
4788
|
delete(index) {
|
|
4716
|
-
|
|
4789
|
+
this._pool?.assertStorageIsWritable();
|
|
4717
4790
|
if (index < 0 || index >= this.#items.length) {
|
|
4718
4791
|
throw new Error(
|
|
4719
4792
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -4746,7 +4819,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4746
4819
|
}
|
|
4747
4820
|
}
|
|
4748
4821
|
clear() {
|
|
4749
|
-
|
|
4822
|
+
this._pool?.assertStorageIsWritable();
|
|
4750
4823
|
if (this._pool) {
|
|
4751
4824
|
const ops = [];
|
|
4752
4825
|
const reverseOps = [];
|
|
@@ -4780,7 +4853,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4780
4853
|
}
|
|
4781
4854
|
}
|
|
4782
4855
|
set(index, item) {
|
|
4783
|
-
|
|
4856
|
+
this._pool?.assertStorageIsWritable();
|
|
4784
4857
|
if (index < 0 || index >= this.#items.length) {
|
|
4785
4858
|
throw new Error(
|
|
4786
4859
|
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -4926,7 +4999,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4926
4999
|
#shiftItemPosition(index, key) {
|
|
4927
5000
|
const shiftedPosition = makePosition(
|
|
4928
5001
|
key,
|
|
4929
|
-
this.#items.length > index + 1 ?
|
|
5002
|
+
this.#items.length > index + 1 ? this.#items[index + 1]?._parentPos : void 0
|
|
4930
5003
|
);
|
|
4931
5004
|
this.#items[index]._setParentLink(this, shiftedPosition);
|
|
4932
5005
|
}
|
|
@@ -4934,7 +5007,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4934
5007
|
_toTreeNode(key) {
|
|
4935
5008
|
return {
|
|
4936
5009
|
type: "LiveList",
|
|
4937
|
-
id:
|
|
5010
|
+
id: this._id ?? nanoid(),
|
|
4938
5011
|
key,
|
|
4939
5012
|
payload: this.#items.map(
|
|
4940
5013
|
(item, index) => item.toTreeNode(index.toString())
|
|
@@ -5051,7 +5124,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
5051
5124
|
const ops = [];
|
|
5052
5125
|
const op = {
|
|
5053
5126
|
id: this._id,
|
|
5054
|
-
opId:
|
|
5127
|
+
opId: pool?.generateOpId(),
|
|
5055
5128
|
type: 7 /* CREATE_MAP */,
|
|
5056
5129
|
parentId,
|
|
5057
5130
|
parentKey
|
|
@@ -5186,7 +5259,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
5186
5259
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
5187
5260
|
*/
|
|
5188
5261
|
set(key, value) {
|
|
5189
|
-
|
|
5262
|
+
this._pool?.assertStorageIsWritable();
|
|
5190
5263
|
const oldValue = this.#map.get(key);
|
|
5191
5264
|
if (oldValue) {
|
|
5192
5265
|
oldValue._detach();
|
|
@@ -5232,7 +5305,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
5232
5305
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
5233
5306
|
*/
|
|
5234
5307
|
delete(key) {
|
|
5235
|
-
|
|
5308
|
+
this._pool?.assertStorageIsWritable();
|
|
5236
5309
|
const item = this.#map.get(key);
|
|
5237
5310
|
if (item === void 0) {
|
|
5238
5311
|
return false;
|
|
@@ -5335,7 +5408,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
5335
5408
|
_toTreeNode(key) {
|
|
5336
5409
|
return {
|
|
5337
5410
|
type: "LiveMap",
|
|
5338
|
-
id:
|
|
5411
|
+
id: this._id ?? nanoid(),
|
|
5339
5412
|
key,
|
|
5340
5413
|
payload: Array.from(this.#map.entries()).map(
|
|
5341
5414
|
([key2, val]) => val.toTreeNode(key2)
|
|
@@ -5411,7 +5484,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5411
5484
|
if (this._id === void 0) {
|
|
5412
5485
|
throw new Error("Cannot serialize item is not attached");
|
|
5413
5486
|
}
|
|
5414
|
-
const opId =
|
|
5487
|
+
const opId = pool?.generateOpId();
|
|
5415
5488
|
const ops = [];
|
|
5416
5489
|
const op = {
|
|
5417
5490
|
type: 4 /* CREATE_OBJECT */,
|
|
@@ -5683,7 +5756,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5683
5756
|
* @param value The value of the property to add
|
|
5684
5757
|
*/
|
|
5685
5758
|
set(key, value) {
|
|
5686
|
-
|
|
5759
|
+
this._pool?.assertStorageIsWritable();
|
|
5687
5760
|
this.update({ [key]: value });
|
|
5688
5761
|
}
|
|
5689
5762
|
/**
|
|
@@ -5698,7 +5771,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5698
5771
|
* @param key The key of the property to delete
|
|
5699
5772
|
*/
|
|
5700
5773
|
delete(key) {
|
|
5701
|
-
|
|
5774
|
+
this._pool?.assertStorageIsWritable();
|
|
5702
5775
|
const keyAsString = key;
|
|
5703
5776
|
const oldValue = this.#map.get(keyAsString);
|
|
5704
5777
|
if (oldValue === void 0) {
|
|
@@ -5751,7 +5824,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5751
5824
|
* @param patch The object used to overrides properties
|
|
5752
5825
|
*/
|
|
5753
5826
|
update(patch) {
|
|
5754
|
-
|
|
5827
|
+
this._pool?.assertStorageIsWritable();
|
|
5755
5828
|
if (this._pool === void 0 || this._id === void 0) {
|
|
5756
5829
|
for (const key in patch) {
|
|
5757
5830
|
const newValue = patch[key];
|
|
@@ -5841,7 +5914,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5841
5914
|
}
|
|
5842
5915
|
/** @internal */
|
|
5843
5916
|
_toTreeNode(key) {
|
|
5844
|
-
const nodeId =
|
|
5917
|
+
const nodeId = this._id ?? nanoid();
|
|
5845
5918
|
return {
|
|
5846
5919
|
type: "LiveObject",
|
|
5847
5920
|
id: nodeId,
|
|
@@ -6237,7 +6310,7 @@ var ManagedOthers = class {
|
|
|
6237
6310
|
#internal;
|
|
6238
6311
|
#userCache;
|
|
6239
6312
|
// The "clean" signal that is exposed to the outside world
|
|
6240
|
-
|
|
6313
|
+
signal;
|
|
6241
6314
|
constructor() {
|
|
6242
6315
|
this.#internal = new MutableSignal({
|
|
6243
6316
|
connections: /* @__PURE__ */ new Map(),
|
|
@@ -6359,7 +6432,7 @@ var ManagedOthers = class {
|
|
|
6359
6432
|
|
|
6360
6433
|
// src/types/LiveblocksError.ts
|
|
6361
6434
|
var LiveblocksError = class _LiveblocksError extends Error {
|
|
6362
|
-
|
|
6435
|
+
context;
|
|
6363
6436
|
constructor(message, context, cause) {
|
|
6364
6437
|
super(message, { cause });
|
|
6365
6438
|
this.context = context;
|
|
@@ -6460,15 +6533,15 @@ function installBackgroundTabSpy() {
|
|
|
6460
6533
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
6461
6534
|
const inBackgroundSince = { current: null };
|
|
6462
6535
|
function onVisibilityChange() {
|
|
6463
|
-
if (
|
|
6464
|
-
inBackgroundSince.current =
|
|
6536
|
+
if (doc?.visibilityState === "hidden") {
|
|
6537
|
+
inBackgroundSince.current = inBackgroundSince.current ?? Date.now();
|
|
6465
6538
|
} else {
|
|
6466
6539
|
inBackgroundSince.current = null;
|
|
6467
6540
|
}
|
|
6468
6541
|
}
|
|
6469
|
-
|
|
6542
|
+
doc?.addEventListener("visibilitychange", onVisibilityChange);
|
|
6470
6543
|
const unsub = () => {
|
|
6471
|
-
|
|
6544
|
+
doc?.removeEventListener("visibilitychange", onVisibilityChange);
|
|
6472
6545
|
};
|
|
6473
6546
|
return [inBackgroundSince, unsub];
|
|
6474
6547
|
}
|
|
@@ -6653,7 +6726,7 @@ function createRoom(options, config) {
|
|
|
6653
6726
|
}
|
|
6654
6727
|
},
|
|
6655
6728
|
assertStorageIsWritable: () => {
|
|
6656
|
-
const scopes =
|
|
6729
|
+
const scopes = context.dynamicSessionInfoSig.get()?.scopes;
|
|
6657
6730
|
if (scopes === void 0) {
|
|
6658
6731
|
return;
|
|
6659
6732
|
}
|
|
@@ -6761,7 +6834,7 @@ function createRoom(options, config) {
|
|
|
6761
6834
|
return new TextEncoder().encode(text).length >= MAX_SOCKET_MESSAGE_SIZE;
|
|
6762
6835
|
}
|
|
6763
6836
|
function sendMessages(messages) {
|
|
6764
|
-
const strategy =
|
|
6837
|
+
const strategy = config.largeMessageStrategy ?? "default";
|
|
6765
6838
|
const text = stringifyOrLog(messages);
|
|
6766
6839
|
if (!isTooBigForWebSocket(text)) {
|
|
6767
6840
|
return managedSocket.send(text);
|
|
@@ -6780,7 +6853,7 @@ function createRoom(options, config) {
|
|
|
6780
6853
|
}
|
|
6781
6854
|
case "experimental-fallback-to-http": {
|
|
6782
6855
|
warn("Message is too large for websockets, so sending over HTTP instead");
|
|
6783
|
-
const nonce =
|
|
6856
|
+
const nonce = context.dynamicSessionInfoSig.get()?.nonce ?? raise("Session is not authorized to send message over HTTP");
|
|
6784
6857
|
void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
|
|
6785
6858
|
if (!resp.ok && resp.status === 403) {
|
|
6786
6859
|
managedSocket.reconnect();
|
|
@@ -6831,7 +6904,7 @@ function createRoom(options, config) {
|
|
|
6831
6904
|
} else {
|
|
6832
6905
|
context.root = LiveObject._fromItems(message.items, pool);
|
|
6833
6906
|
}
|
|
6834
|
-
const canWrite =
|
|
6907
|
+
const canWrite = self.get()?.canWrite ?? true;
|
|
6835
6908
|
const stackSizeBefore = context.undoStack.length;
|
|
6836
6909
|
for (const key in context.initialStorage) {
|
|
6837
6910
|
if (context.root.get(key) === void 0) {
|
|
@@ -6881,7 +6954,7 @@ function createRoom(options, config) {
|
|
|
6881
6954
|
eventHub.others.notify({ ...event, others });
|
|
6882
6955
|
}
|
|
6883
6956
|
}
|
|
6884
|
-
if (
|
|
6957
|
+
if (updates.presence ?? false) {
|
|
6885
6958
|
notifySelfChanged();
|
|
6886
6959
|
eventHub.myPresence.notify(context.myPresence.get());
|
|
6887
6960
|
}
|
|
@@ -7034,7 +7107,7 @@ function createRoom(options, config) {
|
|
|
7034
7107
|
}
|
|
7035
7108
|
context.myPresence.patch(patch);
|
|
7036
7109
|
if (context.activeBatch) {
|
|
7037
|
-
if (
|
|
7110
|
+
if (options2?.addToHistory) {
|
|
7038
7111
|
context.activeBatch.reverseOps.pushLeft({
|
|
7039
7112
|
type: "presence",
|
|
7040
7113
|
data: oldValues
|
|
@@ -7043,7 +7116,7 @@ function createRoom(options, config) {
|
|
|
7043
7116
|
context.activeBatch.updates.presence = true;
|
|
7044
7117
|
} else {
|
|
7045
7118
|
flushNowOrSoon();
|
|
7046
|
-
if (
|
|
7119
|
+
if (options2?.addToHistory) {
|
|
7047
7120
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
7048
7121
|
}
|
|
7049
7122
|
notify({ presence: true });
|
|
@@ -7192,7 +7265,7 @@ function createRoom(options, config) {
|
|
|
7192
7265
|
const others = context.others.get();
|
|
7193
7266
|
eventHub.customEvent.notify({
|
|
7194
7267
|
connectionId: message.actor,
|
|
7195
|
-
user: message.actor < 0 ? null :
|
|
7268
|
+
user: message.actor < 0 ? null : others.find((u) => u.connectionId === message.actor) ?? null,
|
|
7196
7269
|
event: message.event
|
|
7197
7270
|
});
|
|
7198
7271
|
break;
|
|
@@ -7240,7 +7313,7 @@ function createRoom(options, config) {
|
|
|
7240
7313
|
if (process.env.NODE_ENV !== "production") {
|
|
7241
7314
|
const traces = /* @__PURE__ */ new Set();
|
|
7242
7315
|
for (const opId of message.opIds) {
|
|
7243
|
-
const trace =
|
|
7316
|
+
const trace = context.opStackTraces?.get(opId);
|
|
7244
7317
|
if (trace) {
|
|
7245
7318
|
traces.add(trace);
|
|
7246
7319
|
}
|
|
@@ -7374,7 +7447,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7374
7447
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
7375
7448
|
createOrUpdateRootFromMessage(message);
|
|
7376
7449
|
applyAndSendOps(unacknowledgedOps);
|
|
7377
|
-
|
|
7450
|
+
_resolveStoragePromise?.();
|
|
7378
7451
|
notifyStorageStatus();
|
|
7379
7452
|
eventHub.storageDidLoad.notify();
|
|
7380
7453
|
}
|
|
@@ -7597,8 +7670,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7597
7670
|
async function getThreads(options2) {
|
|
7598
7671
|
return httpClient.getThreads({
|
|
7599
7672
|
roomId,
|
|
7600
|
-
query:
|
|
7601
|
-
cursor:
|
|
7673
|
+
query: options2?.query,
|
|
7674
|
+
cursor: options2?.cursor
|
|
7602
7675
|
});
|
|
7603
7676
|
}
|
|
7604
7677
|
async function getThread(threadId) {
|
|
@@ -7699,7 +7772,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7699
7772
|
function getNotificationSettings(options2) {
|
|
7700
7773
|
return httpClient.getNotificationSettings({
|
|
7701
7774
|
roomId,
|
|
7702
|
-
signal:
|
|
7775
|
+
signal: options2?.signal
|
|
7703
7776
|
});
|
|
7704
7777
|
}
|
|
7705
7778
|
function updateNotificationSettings(settings) {
|
|
@@ -7721,7 +7794,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7721
7794
|
{
|
|
7722
7795
|
[kInternal]: {
|
|
7723
7796
|
get presenceBuffer() {
|
|
7724
|
-
return deepClone(
|
|
7797
|
+
return deepClone(context.buffer.presenceUpdates?.data ?? null);
|
|
7725
7798
|
},
|
|
7726
7799
|
// prettier-ignore
|
|
7727
7800
|
get undoStack() {
|
|
@@ -7736,9 +7809,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7736
7809
|
return context.yjsProvider;
|
|
7737
7810
|
},
|
|
7738
7811
|
setYjsProvider(newProvider) {
|
|
7739
|
-
|
|
7812
|
+
context.yjsProvider?.off("status", yjsStatusDidChange);
|
|
7740
7813
|
context.yjsProvider = newProvider;
|
|
7741
|
-
|
|
7814
|
+
newProvider?.on("status", yjsStatusDidChange);
|
|
7742
7815
|
context.yjsProviderDidChange.notify();
|
|
7743
7816
|
},
|
|
7744
7817
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -7784,7 +7857,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7784
7857
|
source[Symbol.dispose]();
|
|
7785
7858
|
}
|
|
7786
7859
|
eventHub.roomWillDestroy.notify();
|
|
7787
|
-
|
|
7860
|
+
context.yjsProvider?.off("status", yjsStatusDidChange);
|
|
7788
7861
|
syncSourceForStorage.destroy();
|
|
7789
7862
|
syncSourceForYjs.destroy();
|
|
7790
7863
|
uninstallBgTabSpy();
|
|
@@ -7930,7 +8003,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
7930
8003
|
}
|
|
7931
8004
|
if (isLiveNode(first)) {
|
|
7932
8005
|
const node = first;
|
|
7933
|
-
if (
|
|
8006
|
+
if (options?.isDeep) {
|
|
7934
8007
|
const storageCallback = second;
|
|
7935
8008
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
7936
8009
|
} else {
|
|
@@ -7954,7 +8027,7 @@ function makeAuthDelegateForRoom(roomId, authManager) {
|
|
|
7954
8027
|
}
|
|
7955
8028
|
function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
|
|
7956
8029
|
return (authValue) => {
|
|
7957
|
-
const ws =
|
|
8030
|
+
const ws = WebSocketPolyfill ?? (typeof WebSocket === "undefined" ? void 0 : WebSocket);
|
|
7958
8031
|
if (ws === void 0) {
|
|
7959
8032
|
throw new StopRetrying(
|
|
7960
8033
|
"To use Liveblocks client in a non-DOM environment, you need to provide a WebSocket polyfill."
|
|
@@ -7996,9 +8069,9 @@ function getBaseUrl(baseUrl) {
|
|
|
7996
8069
|
}
|
|
7997
8070
|
function createClient(options) {
|
|
7998
8071
|
const clientOptions = options;
|
|
7999
|
-
const throttleDelay = getThrottle(
|
|
8072
|
+
const throttleDelay = getThrottle(clientOptions.throttle ?? DEFAULT_THROTTLE);
|
|
8000
8073
|
const lostConnectionTimeout = getLostConnectionTimeout(
|
|
8001
|
-
|
|
8074
|
+
clientOptions.lostConnectionTimeout ?? DEFAULT_LOST_CONNECTION_TIMEOUT
|
|
8002
8075
|
);
|
|
8003
8076
|
const backgroundKeepAliveTimeout = getBackgroundKeepAliveTimeout(
|
|
8004
8077
|
clientOptions.backgroundKeepAliveTimeout
|
|
@@ -8009,8 +8082,8 @@ function createClient(options) {
|
|
|
8009
8082
|
const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
|
|
8010
8083
|
currentUserId.set(() => userId);
|
|
8011
8084
|
});
|
|
8012
|
-
const fetchPolyfill =
|
|
8013
|
-
|
|
8085
|
+
const fetchPolyfill = clientOptions.polyfills?.fetch || /* istanbul ignore next */
|
|
8086
|
+
globalThis.fetch?.bind(globalThis);
|
|
8014
8087
|
const httpClient = createApiClient({
|
|
8015
8088
|
baseUrl,
|
|
8016
8089
|
fetchPolyfill,
|
|
@@ -8046,9 +8119,9 @@ function createClient(options) {
|
|
|
8046
8119
|
if (existing !== void 0) {
|
|
8047
8120
|
return leaseRoom(existing);
|
|
8048
8121
|
}
|
|
8049
|
-
const options2 =
|
|
8050
|
-
const initialPresence =
|
|
8051
|
-
const initialStorage =
|
|
8122
|
+
const options2 = args[0] ?? {};
|
|
8123
|
+
const initialPresence = (typeof options2.initialPresence === "function" ? options2.initialPresence(roomId) : options2.initialPresence) ?? {};
|
|
8124
|
+
const initialStorage = (typeof options2.initialStorage === "function" ? options2.initialStorage(roomId) : options2.initialStorage) ?? {};
|
|
8052
8125
|
const newRoom = createRoom(
|
|
8053
8126
|
{ initialPresence, initialStorage },
|
|
8054
8127
|
{
|
|
@@ -8057,18 +8130,18 @@ function createClient(options) {
|
|
|
8057
8130
|
lostConnectionTimeout,
|
|
8058
8131
|
backgroundKeepAliveTimeout,
|
|
8059
8132
|
polyfills: clientOptions.polyfills,
|
|
8060
|
-
delegates:
|
|
8133
|
+
delegates: clientOptions.mockedDelegates ?? {
|
|
8061
8134
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
8062
8135
|
roomId,
|
|
8063
8136
|
baseUrl,
|
|
8064
|
-
|
|
8137
|
+
clientOptions.polyfills?.WebSocket
|
|
8065
8138
|
),
|
|
8066
8139
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
8067
|
-
}
|
|
8140
|
+
},
|
|
8068
8141
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
8069
8142
|
baseUrl,
|
|
8070
8143
|
errorEventSource: liveblocksErrorSource,
|
|
8071
|
-
largeMessageStrategy:
|
|
8144
|
+
largeMessageStrategy: clientOptions.largeMessageStrategy ?? (clientOptions.unstable_fallbackToHTTP ? "experimental-fallback-to-http" : void 0),
|
|
8072
8145
|
unstable_streamData: !!clientOptions.unstable_streamData,
|
|
8073
8146
|
roomHttpClient: httpClient,
|
|
8074
8147
|
createSyncSource
|
|
@@ -8081,10 +8154,10 @@ function createClient(options) {
|
|
|
8081
8154
|
roomsById.set(roomId, newRoomDetails);
|
|
8082
8155
|
setupDevTools(() => Array.from(roomsById.keys()));
|
|
8083
8156
|
linkDevTools(roomId, newRoom);
|
|
8084
|
-
const shouldConnect =
|
|
8157
|
+
const shouldConnect = options2.autoConnect ?? true;
|
|
8085
8158
|
if (shouldConnect) {
|
|
8086
8159
|
if (typeof atob === "undefined") {
|
|
8087
|
-
if (
|
|
8160
|
+
if (clientOptions.polyfills?.atob === void 0) {
|
|
8088
8161
|
throw new Error(
|
|
8089
8162
|
"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"
|
|
8090
8163
|
);
|
|
@@ -8096,7 +8169,7 @@ function createClient(options) {
|
|
|
8096
8169
|
return leaseRoom(newRoomDetails);
|
|
8097
8170
|
}
|
|
8098
8171
|
function getRoom(roomId) {
|
|
8099
|
-
const room =
|
|
8172
|
+
const room = roomsById.get(roomId)?.room;
|
|
8100
8173
|
return room ? room : null;
|
|
8101
8174
|
}
|
|
8102
8175
|
function logout() {
|
|
@@ -8116,9 +8189,9 @@ function createClient(options) {
|
|
|
8116
8189
|
const batchedResolveUsers = new Batch(
|
|
8117
8190
|
async (batchedUserIds) => {
|
|
8118
8191
|
const userIds = batchedUserIds.flat();
|
|
8119
|
-
const users = await
|
|
8192
|
+
const users = await resolveUsers?.({ userIds });
|
|
8120
8193
|
warnIfNoResolveUsers();
|
|
8121
|
-
return
|
|
8194
|
+
return users ?? userIds.map(() => void 0);
|
|
8122
8195
|
},
|
|
8123
8196
|
{ delay: RESOLVE_USERS_BATCH_DELAY }
|
|
8124
8197
|
);
|
|
@@ -8134,9 +8207,9 @@ function createClient(options) {
|
|
|
8134
8207
|
const batchedResolveRoomsInfo = new Batch(
|
|
8135
8208
|
async (batchedRoomIds) => {
|
|
8136
8209
|
const roomIds = batchedRoomIds.flat();
|
|
8137
|
-
const roomsInfo = await
|
|
8210
|
+
const roomsInfo = await resolveRoomsInfo?.({ roomIds });
|
|
8138
8211
|
warnIfNoResolveRoomsInfo();
|
|
8139
|
-
return
|
|
8212
|
+
return roomsInfo ?? roomIds.map(() => void 0);
|
|
8140
8213
|
},
|
|
8141
8214
|
{ delay: RESOLVE_ROOMS_INFO_BATCH_DELAY }
|
|
8142
8215
|
);
|
|
@@ -8187,7 +8260,17 @@ function createClient(options) {
|
|
|
8187
8260
|
}
|
|
8188
8261
|
};
|
|
8189
8262
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
8190
|
-
|
|
8263
|
+
win?.addEventListener("beforeunload", maybePreventClose);
|
|
8264
|
+
}
|
|
8265
|
+
async function getNotificationSettings(options2) {
|
|
8266
|
+
const plainSettings = await httpClient.getUserNotificationSettings(options2);
|
|
8267
|
+
const settings = createUserNotificationSettings(plainSettings);
|
|
8268
|
+
return settings;
|
|
8269
|
+
}
|
|
8270
|
+
async function updateNotificationSettings(settings) {
|
|
8271
|
+
const plainSettings = await httpClient.updateUserNotificationSettings(settings);
|
|
8272
|
+
const settingsObject = createUserNotificationSettings(plainSettings);
|
|
8273
|
+
return settingsObject;
|
|
8191
8274
|
}
|
|
8192
8275
|
const client = Object.defineProperty(
|
|
8193
8276
|
{
|
|
@@ -8202,9 +8285,9 @@ function createClient(options) {
|
|
|
8202
8285
|
markInboxNotificationAsRead: httpClient.markInboxNotificationAsRead,
|
|
8203
8286
|
deleteAllInboxNotifications: httpClient.deleteAllInboxNotifications,
|
|
8204
8287
|
deleteInboxNotification: httpClient.deleteInboxNotification,
|
|
8205
|
-
// Public
|
|
8206
|
-
getNotificationSettings
|
|
8207
|
-
updateNotificationSettings
|
|
8288
|
+
// Public user notification settings API
|
|
8289
|
+
getNotificationSettings,
|
|
8290
|
+
updateNotificationSettings,
|
|
8208
8291
|
// Advanced resolvers APIs
|
|
8209
8292
|
resolvers: {
|
|
8210
8293
|
invalidateUsers: invalidateResolvedUsers,
|
|
@@ -8249,7 +8332,7 @@ function createClient(options) {
|
|
|
8249
8332
|
function checkBounds(option, value, min, max, recommendedMin) {
|
|
8250
8333
|
if (typeof value !== "number" || value < min || max !== void 0 && value > max) {
|
|
8251
8334
|
throw new Error(
|
|
8252
|
-
max !== void 0 ? `${option} should be between ${
|
|
8335
|
+
max !== void 0 ? `${option} should be between ${recommendedMin ?? min} and ${max}.` : `${option} should be at least ${recommendedMin ?? min}.`
|
|
8253
8336
|
);
|
|
8254
8337
|
}
|
|
8255
8338
|
return value;
|
|
@@ -8315,7 +8398,7 @@ var commentBodyElementsTypes = {
|
|
|
8315
8398
|
mention: "inline"
|
|
8316
8399
|
};
|
|
8317
8400
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
8318
|
-
if (!body || !
|
|
8401
|
+
if (!body || !body?.content) {
|
|
8319
8402
|
return;
|
|
8320
8403
|
}
|
|
8321
8404
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -8325,13 +8408,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
8325
8408
|
for (const block of body.content) {
|
|
8326
8409
|
if (type === "all" || type === "block") {
|
|
8327
8410
|
if (guard(block)) {
|
|
8328
|
-
|
|
8411
|
+
visitor?.(block);
|
|
8329
8412
|
}
|
|
8330
8413
|
}
|
|
8331
8414
|
if (type === "all" || type === "inline") {
|
|
8332
8415
|
for (const inline of block.children) {
|
|
8333
8416
|
if (guard(inline)) {
|
|
8334
|
-
|
|
8417
|
+
visitor?.(inline);
|
|
8335
8418
|
}
|
|
8336
8419
|
}
|
|
8337
8420
|
}
|
|
@@ -8356,7 +8439,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
|
8356
8439
|
userIds
|
|
8357
8440
|
});
|
|
8358
8441
|
for (const [index, userId] of userIds.entries()) {
|
|
8359
|
-
const user =
|
|
8442
|
+
const user = users?.[index];
|
|
8360
8443
|
if (user) {
|
|
8361
8444
|
resolvedUsers.set(userId, user);
|
|
8362
8445
|
}
|
|
@@ -8481,9 +8564,9 @@ function toAbsoluteUrl(url2) {
|
|
|
8481
8564
|
var stringifyCommentBodyPlainElements = {
|
|
8482
8565
|
paragraph: ({ children }) => children,
|
|
8483
8566
|
text: ({ element }) => element.text,
|
|
8484
|
-
link: ({ element }) =>
|
|
8567
|
+
link: ({ element }) => element.text ?? element.url,
|
|
8485
8568
|
mention: ({ element, user }) => {
|
|
8486
|
-
return `@${
|
|
8569
|
+
return `@${user?.name ?? element.id}`;
|
|
8487
8570
|
}
|
|
8488
8571
|
};
|
|
8489
8572
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -8513,7 +8596,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
8513
8596
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
8514
8597
|
},
|
|
8515
8598
|
mention: ({ element, user }) => {
|
|
8516
|
-
return html`<span data-mention>@${
|
|
8599
|
+
return html`<span data-mention>@${user?.name ? html`${user?.name}` : element.id}</span>`;
|
|
8517
8600
|
}
|
|
8518
8601
|
};
|
|
8519
8602
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -8540,22 +8623,22 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
8540
8623
|
return children;
|
|
8541
8624
|
},
|
|
8542
8625
|
link: ({ element, href }) => {
|
|
8543
|
-
return markdown`[${
|
|
8626
|
+
return markdown`[${element.text ?? element.url}](${href})`;
|
|
8544
8627
|
},
|
|
8545
8628
|
mention: ({ element, user }) => {
|
|
8546
|
-
return markdown`@${
|
|
8629
|
+
return markdown`@${user?.name ?? element.id}`;
|
|
8547
8630
|
}
|
|
8548
8631
|
};
|
|
8549
8632
|
async function stringifyCommentBody(body, options) {
|
|
8550
|
-
const format =
|
|
8551
|
-
const separator =
|
|
8633
|
+
const format = options?.format ?? "plain";
|
|
8634
|
+
const separator = options?.separator ?? (format === "markdown" ? "\n\n" : "\n");
|
|
8552
8635
|
const elements = {
|
|
8553
8636
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
8554
|
-
...
|
|
8637
|
+
...options?.elements
|
|
8555
8638
|
};
|
|
8556
8639
|
const resolvedUsers = await resolveUsersInCommentBody(
|
|
8557
8640
|
body,
|
|
8558
|
-
|
|
8641
|
+
options?.resolveUsers
|
|
8559
8642
|
);
|
|
8560
8643
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
8561
8644
|
switch (block.type) {
|
|
@@ -8577,7 +8660,7 @@ async function stringifyCommentBody(body, options) {
|
|
|
8577
8660
|
elements.link(
|
|
8578
8661
|
{
|
|
8579
8662
|
element: inline,
|
|
8580
|
-
href:
|
|
8663
|
+
href: toAbsoluteUrl(inline.url) ?? inline.url
|
|
8581
8664
|
},
|
|
8582
8665
|
inlineIndex
|
|
8583
8666
|
)
|
|
@@ -8846,12 +8929,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
8846
8929
|
}
|
|
8847
8930
|
const newState = Object.assign({}, state);
|
|
8848
8931
|
for (const key in update.updates) {
|
|
8849
|
-
if (
|
|
8932
|
+
if (update.updates[key]?.type === "update") {
|
|
8850
8933
|
const val = update.node.get(key);
|
|
8851
8934
|
if (val !== void 0) {
|
|
8852
8935
|
newState[key] = lsonToJson(val);
|
|
8853
8936
|
}
|
|
8854
|
-
} else if (
|
|
8937
|
+
} else if (update.updates[key]?.type === "delete") {
|
|
8855
8938
|
delete newState[key];
|
|
8856
8939
|
}
|
|
8857
8940
|
}
|
|
@@ -8912,12 +8995,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
8912
8995
|
}
|
|
8913
8996
|
const newState = Object.assign({}, state);
|
|
8914
8997
|
for (const key in update.updates) {
|
|
8915
|
-
if (
|
|
8998
|
+
if (update.updates[key]?.type === "update") {
|
|
8916
8999
|
const value = update.node.get(key);
|
|
8917
9000
|
if (value !== void 0) {
|
|
8918
9001
|
newState[key] = lsonToJson(value);
|
|
8919
9002
|
}
|
|
8920
|
-
} else if (
|
|
9003
|
+
} else if (update.updates[key]?.type === "delete") {
|
|
8921
9004
|
delete newState[key];
|
|
8922
9005
|
}
|
|
8923
9006
|
}
|
|
@@ -8988,9 +9071,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
8988
9071
|
const startTime = performance.now();
|
|
8989
9072
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
8990
9073
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
8991
|
-
const maxStaleTimeMs =
|
|
9074
|
+
const maxStaleTimeMs = options?.maxStaleTimeMs ?? Number.POSITIVE_INFINITY;
|
|
8992
9075
|
const context = {
|
|
8993
|
-
inForeground:
|
|
9076
|
+
inForeground: doc?.visibilityState !== "hidden",
|
|
8994
9077
|
lastSuccessfulPollAt: startTime,
|
|
8995
9078
|
count: 0,
|
|
8996
9079
|
backoff: 0
|
|
@@ -9032,7 +9115,7 @@ function makePoller(callback, intervalMs, options) {
|
|
|
9032
9115
|
return {
|
|
9033
9116
|
target: mayPoll() ? "@enabled" : "@idle",
|
|
9034
9117
|
effect: () => {
|
|
9035
|
-
context.backoff =
|
|
9118
|
+
context.backoff = BACKOFF_DELAYS2.find((delay) => delay > context.backoff) ?? BACKOFF_DELAYS2[BACKOFF_DELAYS2.length - 1];
|
|
9036
9119
|
}
|
|
9037
9120
|
};
|
|
9038
9121
|
},
|
|
@@ -9068,11 +9151,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
9068
9151
|
pollNowIfStale();
|
|
9069
9152
|
}
|
|
9070
9153
|
function onVisibilityChange() {
|
|
9071
|
-
setInForeground(
|
|
9154
|
+
setInForeground(doc?.visibilityState !== "hidden");
|
|
9072
9155
|
}
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9156
|
+
doc?.addEventListener("visibilitychange", onVisibilityChange);
|
|
9157
|
+
win?.addEventListener("online", onVisibilityChange);
|
|
9158
|
+
win?.addEventListener("focus", pollNowIfStale);
|
|
9076
9159
|
fsm.start();
|
|
9077
9160
|
return {
|
|
9078
9161
|
inc,
|
|
@@ -9194,11 +9277,6 @@ var SortedList = class _SortedList {
|
|
|
9194
9277
|
}
|
|
9195
9278
|
};
|
|
9196
9279
|
|
|
9197
|
-
// src/protocol/UserNotificationSettings.ts
|
|
9198
|
-
function isNotificationChannelEnabled(settings) {
|
|
9199
|
-
return values(settings).every((enabled) => enabled === true);
|
|
9200
|
-
}
|
|
9201
|
-
|
|
9202
9280
|
// src/types/Others.ts
|
|
9203
9281
|
var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
|
|
9204
9282
|
TextEditorType2["Lexical"] = "lexical";
|
|
@@ -9210,94 +9288,96 @@ var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
|
|
|
9210
9288
|
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
9211
9289
|
var CommentsApiError = HttpError;
|
|
9212
9290
|
var NotificationsApiError = HttpError;
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9291
|
+
export {
|
|
9292
|
+
ClientMsgCode,
|
|
9293
|
+
CommentsApiError,
|
|
9294
|
+
CrdtType,
|
|
9295
|
+
DefaultMap,
|
|
9296
|
+
DerivedSignal,
|
|
9297
|
+
HttpError,
|
|
9298
|
+
LiveList,
|
|
9299
|
+
LiveMap,
|
|
9300
|
+
LiveObject,
|
|
9301
|
+
LiveblocksError,
|
|
9302
|
+
MutableSignal,
|
|
9303
|
+
NotificationsApiError,
|
|
9304
|
+
OpCode,
|
|
9305
|
+
Permission,
|
|
9306
|
+
Promise_withResolvers,
|
|
9307
|
+
ServerMsgCode,
|
|
9308
|
+
Signal,
|
|
9309
|
+
SortedList,
|
|
9310
|
+
TextEditorType,
|
|
9311
|
+
WebsocketCloseCodes,
|
|
9312
|
+
ackOp,
|
|
9313
|
+
asPos,
|
|
9314
|
+
assert,
|
|
9315
|
+
assertNever,
|
|
9316
|
+
autoRetry,
|
|
9317
|
+
b64decode,
|
|
9318
|
+
batch,
|
|
9319
|
+
chunk,
|
|
9320
|
+
cloneLson,
|
|
9321
|
+
compactObject,
|
|
9322
|
+
fancy_console_exports as console,
|
|
9323
|
+
convertToCommentData,
|
|
9324
|
+
convertToCommentUserReaction,
|
|
9325
|
+
convertToInboxNotificationData,
|
|
9326
|
+
convertToThreadData,
|
|
9327
|
+
createClient,
|
|
9328
|
+
createCommentAttachmentId,
|
|
9329
|
+
createCommentId,
|
|
9330
|
+
createInboxNotificationId,
|
|
9331
|
+
createThreadId,
|
|
9332
|
+
createUserNotificationSettings,
|
|
9333
|
+
deprecate,
|
|
9334
|
+
deprecateIf,
|
|
9335
|
+
detectDupes,
|
|
9336
|
+
entries,
|
|
9337
|
+
errorIf,
|
|
9338
|
+
freeze,
|
|
9339
|
+
generateCommentUrl,
|
|
9340
|
+
getMentionedIdsFromCommentBody,
|
|
9341
|
+
html,
|
|
9342
|
+
htmlSafe,
|
|
9343
|
+
isChildCrdt,
|
|
9344
|
+
isCommentBodyLink,
|
|
9345
|
+
isCommentBodyMention,
|
|
9346
|
+
isCommentBodyText,
|
|
9347
|
+
isJsonArray,
|
|
9348
|
+
isJsonObject,
|
|
9349
|
+
isJsonScalar,
|
|
9350
|
+
isLiveNode,
|
|
9351
|
+
isNotificationChannelEnabled,
|
|
9352
|
+
isPlainObject,
|
|
9353
|
+
isRootCrdt,
|
|
9354
|
+
isStartsWithOperator,
|
|
9355
|
+
kInternal,
|
|
9356
|
+
keys,
|
|
9357
|
+
legacy_patchImmutableObject,
|
|
9358
|
+
lsonToJson,
|
|
9359
|
+
makeEventSource,
|
|
9360
|
+
makePoller,
|
|
9361
|
+
makePosition,
|
|
9362
|
+
mapValues,
|
|
9363
|
+
memoizeOnSuccess,
|
|
9364
|
+
nanoid,
|
|
9365
|
+
nn,
|
|
9366
|
+
objectToQuery,
|
|
9367
|
+
patchLiveObjectKey,
|
|
9368
|
+
patchUserNotificationSettings,
|
|
9369
|
+
raise,
|
|
9370
|
+
resolveUsersInCommentBody,
|
|
9371
|
+
shallow,
|
|
9372
|
+
stableStringify,
|
|
9373
|
+
stringifyCommentBody,
|
|
9374
|
+
throwUsageError,
|
|
9375
|
+
toAbsoluteUrl,
|
|
9376
|
+
toPlainLson,
|
|
9377
|
+
tryParseJson,
|
|
9378
|
+
url,
|
|
9379
|
+
urljoin,
|
|
9380
|
+
wait,
|
|
9381
|
+
withTimeout
|
|
9382
|
+
};
|
|
9303
9383
|
//# sourceMappingURL=index.js.map
|