@liveblocks/core 3.14.0-types2 → 3.14.0
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 +548 -377
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +171 -103
- package/dist/index.d.ts +171 -103
- package/dist/index.js +440 -269
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
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.14.0
|
|
9
|
+
var PKG_VERSION = "3.14.0";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -567,6 +567,9 @@ var SortedList = class _SortedList {
|
|
|
567
567
|
this.#lt = lt;
|
|
568
568
|
this.#data = alreadySortedList;
|
|
569
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Creates an empty SortedList with the given "less than" function.
|
|
572
|
+
*/
|
|
570
573
|
static with(lt) {
|
|
571
574
|
return _SortedList.fromAlreadySorted([], lt);
|
|
572
575
|
}
|
|
@@ -588,10 +591,12 @@ var SortedList = class _SortedList {
|
|
|
588
591
|
}
|
|
589
592
|
/**
|
|
590
593
|
* Adds a new item to the sorted list, such that it remains sorted.
|
|
594
|
+
* Returns the index where the item was inserted.
|
|
591
595
|
*/
|
|
592
596
|
add(value) {
|
|
593
597
|
const idx = bisectRight(this.#data, value, this.#lt);
|
|
594
598
|
this.#data.splice(idx, 0, value);
|
|
599
|
+
return idx;
|
|
595
600
|
}
|
|
596
601
|
/**
|
|
597
602
|
* Removes all values from the sorted list, making it empty again.
|
|
@@ -636,6 +641,60 @@ var SortedList = class _SortedList {
|
|
|
636
641
|
}
|
|
637
642
|
return false;
|
|
638
643
|
}
|
|
644
|
+
/**
|
|
645
|
+
* Removes the item at the given index.
|
|
646
|
+
* Returns the removed item, or undefined if index is out of bounds.
|
|
647
|
+
*/
|
|
648
|
+
removeAt(index) {
|
|
649
|
+
if (index < 0 || index >= this.#data.length) {
|
|
650
|
+
return void 0;
|
|
651
|
+
}
|
|
652
|
+
const [removed] = this.#data.splice(index, 1);
|
|
653
|
+
return removed;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Repositions an item to maintain sorted order after its sort key has
|
|
657
|
+
* been mutated in-place. For example:
|
|
658
|
+
*
|
|
659
|
+
* const item = sorted.at(3);
|
|
660
|
+
* item.updatedAt = new Date(); // mutate the item's sort key in-place
|
|
661
|
+
* sorted.reposition(item); // restore sorted order
|
|
662
|
+
*
|
|
663
|
+
* Returns the new index of the item. Throws if the item is not in the list.
|
|
664
|
+
*
|
|
665
|
+
* Semantically equivalent to remove(value) + add(value), but optimized
|
|
666
|
+
* to avoid array shifting when the item only moves a short distance.
|
|
667
|
+
*/
|
|
668
|
+
reposition(value) {
|
|
669
|
+
const oldIdx = this.#data.indexOf(value);
|
|
670
|
+
if (oldIdx < 0) {
|
|
671
|
+
throw new Error("Cannot reposition item that is not in the list");
|
|
672
|
+
}
|
|
673
|
+
const prev = this.#data[oldIdx - 1];
|
|
674
|
+
const next = this.#data[oldIdx + 1];
|
|
675
|
+
const validLeft = prev === void 0 || this.#lt(prev, value);
|
|
676
|
+
const validRight = next === void 0 || this.#lt(value, next);
|
|
677
|
+
if (validLeft && validRight) {
|
|
678
|
+
return oldIdx;
|
|
679
|
+
}
|
|
680
|
+
let newIdx = oldIdx;
|
|
681
|
+
while (newIdx > 0 && this.#lt(value, this.#data[newIdx - 1])) {
|
|
682
|
+
this.#data[newIdx] = this.#data[newIdx - 1];
|
|
683
|
+
newIdx--;
|
|
684
|
+
}
|
|
685
|
+
if (newIdx < oldIdx) {
|
|
686
|
+
this.#data[newIdx] = value;
|
|
687
|
+
return newIdx;
|
|
688
|
+
}
|
|
689
|
+
while (newIdx < this.#data.length - 1 && !this.#lt(value, this.#data[newIdx + 1])) {
|
|
690
|
+
this.#data[newIdx] = this.#data[newIdx + 1];
|
|
691
|
+
newIdx++;
|
|
692
|
+
}
|
|
693
|
+
if (newIdx !== oldIdx) {
|
|
694
|
+
this.#data[newIdx] = value;
|
|
695
|
+
}
|
|
696
|
+
return newIdx;
|
|
697
|
+
}
|
|
639
698
|
at(index) {
|
|
640
699
|
return this.#data[index];
|
|
641
700
|
}
|
|
@@ -2221,19 +2280,6 @@ function createApiClient({
|
|
|
2221
2280
|
);
|
|
2222
2281
|
return await result.json();
|
|
2223
2282
|
}
|
|
2224
|
-
async function sendMessagesOverHTTP(options) {
|
|
2225
|
-
return httpClient.rawPost(
|
|
2226
|
-
url`/v2/c/rooms/${options.roomId}/send-message`,
|
|
2227
|
-
await authManager.getAuthValue({
|
|
2228
|
-
requestedScope: "room:read",
|
|
2229
|
-
roomId: options.roomId
|
|
2230
|
-
}),
|
|
2231
|
-
{
|
|
2232
|
-
nonce: options.nonce,
|
|
2233
|
-
messages: options.messages
|
|
2234
|
-
}
|
|
2235
|
-
);
|
|
2236
|
-
}
|
|
2237
2283
|
async function getInboxNotifications(options) {
|
|
2238
2284
|
const PAGE_SIZE = 50;
|
|
2239
2285
|
let query;
|
|
@@ -2482,7 +2528,6 @@ function createApiClient({
|
|
|
2482
2528
|
getChatAttachmentUrl,
|
|
2483
2529
|
// Room storage
|
|
2484
2530
|
streamStorage,
|
|
2485
|
-
sendMessagesOverHTTP,
|
|
2486
2531
|
// Notifications
|
|
2487
2532
|
getInboxNotifications,
|
|
2488
2533
|
getInboxNotificationsSince,
|
|
@@ -2540,7 +2585,7 @@ var HttpClient = class {
|
|
|
2540
2585
|
raise("This client can only be used to make /v2/c/* requests");
|
|
2541
2586
|
}
|
|
2542
2587
|
const url2 = urljoin(this.#baseUrl, endpoint, params);
|
|
2543
|
-
|
|
2588
|
+
const response = await this.#fetchPolyfill(url2, {
|
|
2544
2589
|
...options,
|
|
2545
2590
|
headers: {
|
|
2546
2591
|
// These headers are default, but can be overriden by custom headers
|
|
@@ -2552,6 +2597,17 @@ var HttpClient = class {
|
|
|
2552
2597
|
"X-LB-Client": PKG_VERSION || "dev"
|
|
2553
2598
|
}
|
|
2554
2599
|
});
|
|
2600
|
+
const xwarn = response.headers.get("X-LB-Warn");
|
|
2601
|
+
if (xwarn) {
|
|
2602
|
+
const method = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _30 => _30.method, 'optionalAccess', _31 => _31.toUpperCase, 'call', _32 => _32()]), () => ( "GET"));
|
|
2603
|
+
const msg = `${xwarn} (${method} ${endpoint})`;
|
|
2604
|
+
if (response.ok) {
|
|
2605
|
+
warn(msg);
|
|
2606
|
+
} else {
|
|
2607
|
+
error2(msg);
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
return response;
|
|
2555
2611
|
}
|
|
2556
2612
|
/**
|
|
2557
2613
|
* Constructs, makes the HTTP request, and handles the response by parsing
|
|
@@ -3014,7 +3070,7 @@ var FSM = class {
|
|
|
3014
3070
|
});
|
|
3015
3071
|
}
|
|
3016
3072
|
#getTargetFn(eventName) {
|
|
3017
|
-
return _optionalChain([this, 'access',
|
|
3073
|
+
return _optionalChain([this, 'access', _33 => _33.#allowedTransitions, 'access', _34 => _34.get, 'call', _35 => _35(this.currentState), 'optionalAccess', _36 => _36.get, 'call', _37 => _37(eventName)]);
|
|
3018
3074
|
}
|
|
3019
3075
|
/**
|
|
3020
3076
|
* Exits the current state, and executes any necessary cleanup functions.
|
|
@@ -3033,7 +3089,7 @@ var FSM = class {
|
|
|
3033
3089
|
this.#currentContext.allowPatching((patchableContext) => {
|
|
3034
3090
|
levels = _nullishCoalesce(levels, () => ( this.#cleanupStack.length));
|
|
3035
3091
|
for (let i = 0; i < levels; i++) {
|
|
3036
|
-
_optionalChain([this, 'access',
|
|
3092
|
+
_optionalChain([this, 'access', _38 => _38.#cleanupStack, 'access', _39 => _39.pop, 'call', _40 => _40(), 'optionalCall', _41 => _41(patchableContext)]);
|
|
3037
3093
|
const entryTime = this.#entryTimesStack.pop();
|
|
3038
3094
|
if (entryTime !== void 0 && // ...but avoid computing state names if nobody is listening
|
|
3039
3095
|
this.#eventHub.didExitState.count() > 0) {
|
|
@@ -3061,7 +3117,7 @@ var FSM = class {
|
|
|
3061
3117
|
this.#currentContext.allowPatching((patchableContext) => {
|
|
3062
3118
|
for (const pattern of enterPatterns) {
|
|
3063
3119
|
const enterFn = this.#enterFns.get(pattern);
|
|
3064
|
-
const cleanupFn = _optionalChain([enterFn, 'optionalCall',
|
|
3120
|
+
const cleanupFn = _optionalChain([enterFn, 'optionalCall', _42 => _42(patchableContext)]);
|
|
3065
3121
|
if (typeof cleanupFn === "function") {
|
|
3066
3122
|
this.#cleanupStack.push(cleanupFn);
|
|
3067
3123
|
} else {
|
|
@@ -3144,6 +3200,11 @@ var ServerMsgCode = Object.freeze({
|
|
|
3144
3200
|
ROOM_STATE: 104,
|
|
3145
3201
|
// For Storage
|
|
3146
3202
|
STORAGE_STATE_V7: 200,
|
|
3203
|
+
// Only sent in V7
|
|
3204
|
+
STORAGE_CHUNK: 210,
|
|
3205
|
+
// Used in V8+
|
|
3206
|
+
STORAGE_STREAM_END: 211,
|
|
3207
|
+
// Used in V8+
|
|
3147
3208
|
UPDATE_STORAGE: 201,
|
|
3148
3209
|
// For Yjs Docs
|
|
3149
3210
|
UPDATE_YDOC: 300,
|
|
@@ -3461,7 +3522,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
3461
3522
|
}
|
|
3462
3523
|
function waitForActorId(event) {
|
|
3463
3524
|
const serverMsg = tryParseJson(event.data);
|
|
3464
|
-
if (_optionalChain([serverMsg, 'optionalAccess',
|
|
3525
|
+
if (_optionalChain([serverMsg, 'optionalAccess', _43 => _43.type]) === ServerMsgCode.ROOM_STATE) {
|
|
3465
3526
|
if (options.enableDebugLogging && socketOpenAt !== null) {
|
|
3466
3527
|
const elapsed = performance.now() - socketOpenAt;
|
|
3467
3528
|
warn(
|
|
@@ -3583,12 +3644,12 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
3583
3644
|
const sendHeartbeat = {
|
|
3584
3645
|
target: "@ok.awaiting-pong",
|
|
3585
3646
|
effect: (ctx) => {
|
|
3586
|
-
_optionalChain([ctx, 'access',
|
|
3647
|
+
_optionalChain([ctx, 'access', _44 => _44.socket, 'optionalAccess', _45 => _45.send, 'call', _46 => _46("ping")]);
|
|
3587
3648
|
}
|
|
3588
3649
|
};
|
|
3589
3650
|
const maybeHeartbeat = () => {
|
|
3590
3651
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
3591
|
-
const canZombie = _optionalChain([doc, 'optionalAccess',
|
|
3652
|
+
const canZombie = _optionalChain([doc, 'optionalAccess', _47 => _47.visibilityState]) === "hidden" && delegates.canZombie();
|
|
3592
3653
|
return canZombie ? "@idle.zombie" : sendHeartbeat;
|
|
3593
3654
|
};
|
|
3594
3655
|
machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
|
|
@@ -3627,7 +3688,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
3627
3688
|
// socket, or not. So always check to see if the socket is still OPEN or
|
|
3628
3689
|
// not. When still OPEN, don't transition.
|
|
3629
3690
|
EXPLICIT_SOCKET_ERROR: (_, context) => {
|
|
3630
|
-
if (_optionalChain([context, 'access',
|
|
3691
|
+
if (_optionalChain([context, 'access', _48 => _48.socket, 'optionalAccess', _49 => _49.readyState]) === 1) {
|
|
3631
3692
|
return null;
|
|
3632
3693
|
}
|
|
3633
3694
|
return {
|
|
@@ -3679,17 +3740,17 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
3679
3740
|
machine.send({ type: "NAVIGATOR_ONLINE" });
|
|
3680
3741
|
}
|
|
3681
3742
|
function onVisibilityChange() {
|
|
3682
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
3743
|
+
if (_optionalChain([doc, 'optionalAccess', _50 => _50.visibilityState]) === "visible") {
|
|
3683
3744
|
machine.send({ type: "WINDOW_GOT_FOCUS" });
|
|
3684
3745
|
}
|
|
3685
3746
|
}
|
|
3686
|
-
_optionalChain([win, 'optionalAccess',
|
|
3687
|
-
_optionalChain([win, 'optionalAccess',
|
|
3688
|
-
_optionalChain([root, 'optionalAccess',
|
|
3747
|
+
_optionalChain([win, 'optionalAccess', _51 => _51.addEventListener, 'call', _52 => _52("online", onNetworkBackOnline)]);
|
|
3748
|
+
_optionalChain([win, 'optionalAccess', _53 => _53.addEventListener, 'call', _54 => _54("offline", onNetworkOffline)]);
|
|
3749
|
+
_optionalChain([root, 'optionalAccess', _55 => _55.addEventListener, 'call', _56 => _56("visibilitychange", onVisibilityChange)]);
|
|
3689
3750
|
return () => {
|
|
3690
|
-
_optionalChain([root, 'optionalAccess',
|
|
3691
|
-
_optionalChain([win, 'optionalAccess',
|
|
3692
|
-
_optionalChain([win, 'optionalAccess',
|
|
3751
|
+
_optionalChain([root, 'optionalAccess', _57 => _57.removeEventListener, 'call', _58 => _58("visibilitychange", onVisibilityChange)]);
|
|
3752
|
+
_optionalChain([win, 'optionalAccess', _59 => _59.removeEventListener, 'call', _60 => _60("online", onNetworkBackOnline)]);
|
|
3753
|
+
_optionalChain([win, 'optionalAccess', _61 => _61.removeEventListener, 'call', _62 => _62("offline", onNetworkOffline)]);
|
|
3693
3754
|
teardownSocket(ctx.socket);
|
|
3694
3755
|
};
|
|
3695
3756
|
});
|
|
@@ -3778,7 +3839,7 @@ var ManagedSocket = class {
|
|
|
3778
3839
|
* message if this is somehow impossible.
|
|
3779
3840
|
*/
|
|
3780
3841
|
send(data) {
|
|
3781
|
-
const socket = _optionalChain([this, 'access',
|
|
3842
|
+
const socket = _optionalChain([this, 'access', _63 => _63.#machine, 'access', _64 => _64.context, 'optionalAccess', _65 => _65.socket]);
|
|
3782
3843
|
if (socket === null) {
|
|
3783
3844
|
warn("Cannot send: not connected yet", data);
|
|
3784
3845
|
} else if (socket.readyState !== 1) {
|
|
@@ -4240,7 +4301,7 @@ function createStore_forKnowledge() {
|
|
|
4240
4301
|
}
|
|
4241
4302
|
function getKnowledgeForChat(chatId) {
|
|
4242
4303
|
const globalKnowledge = knowledgeByChatId.getOrCreate(kWILDCARD).get();
|
|
4243
|
-
const scopedKnowledge = _nullishCoalesce(_optionalChain([knowledgeByChatId, 'access',
|
|
4304
|
+
const scopedKnowledge = _nullishCoalesce(_optionalChain([knowledgeByChatId, 'access', _66 => _66.get, 'call', _67 => _67(chatId), 'optionalAccess', _68 => _68.get, 'call', _69 => _69()]), () => ( []));
|
|
4244
4305
|
return [...globalKnowledge, ...scopedKnowledge];
|
|
4245
4306
|
}
|
|
4246
4307
|
return {
|
|
@@ -4265,7 +4326,7 @@ function createStore_forTools() {
|
|
|
4265
4326
|
return DerivedSignal.from(() => {
|
|
4266
4327
|
return (
|
|
4267
4328
|
// A tool that's registered and scoped to a specific chat ID...
|
|
4268
|
-
_nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess',
|
|
4329
|
+
_nullishCoalesce(_optionalChain([(chatId !== void 0 ? toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name) : void 0), 'optionalAccess', _70 => _70.get, 'call', _71 => _71()]), () => ( // ...or a globally registered tool
|
|
4269
4330
|
toolsByChatId\u03A3.getOrCreate(kWILDCARD).getOrCreate(name).get()))
|
|
4270
4331
|
);
|
|
4271
4332
|
});
|
|
@@ -4295,8 +4356,8 @@ function createStore_forTools() {
|
|
|
4295
4356
|
const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
|
|
4296
4357
|
const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
|
|
4297
4358
|
return Array.from([
|
|
4298
|
-
..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess',
|
|
4299
|
-
..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess',
|
|
4359
|
+
..._nullishCoalesce(_optionalChain([globalTools\u03A3, 'optionalAccess', _72 => _72.entries, 'call', _73 => _73()]), () => ( [])),
|
|
4360
|
+
..._nullishCoalesce(_optionalChain([scopedTools\u03A3, 'optionalAccess', _74 => _74.entries, 'call', _75 => _75()]), () => ( []))
|
|
4300
4361
|
]).flatMap(([name, tool\u03A3]) => {
|
|
4301
4362
|
const tool = tool\u03A3.get();
|
|
4302
4363
|
return tool && (_nullishCoalesce(tool.enabled, () => ( true))) ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
|
|
@@ -4399,7 +4460,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
|
|
|
4399
4460
|
} else {
|
|
4400
4461
|
continue;
|
|
4401
4462
|
}
|
|
4402
|
-
const executeFn = _optionalChain([toolsStore, 'access',
|
|
4463
|
+
const executeFn = _optionalChain([toolsStore, 'access', _76 => _76.getTool\u03A3, 'call', _77 => _77(toolInvocation.name, message.chatId), 'access', _78 => _78.get, 'call', _79 => _79(), 'optionalAccess', _80 => _80.execute]);
|
|
4403
4464
|
if (executeFn) {
|
|
4404
4465
|
(async () => {
|
|
4405
4466
|
const result = await executeFn(toolInvocation.args, {
|
|
@@ -4498,8 +4559,8 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
|
|
|
4498
4559
|
const spine = [];
|
|
4499
4560
|
let lastVisitedMessage = null;
|
|
4500
4561
|
for (const message2 of pool.walkUp(leaf.id)) {
|
|
4501
|
-
const prev = _nullishCoalesce(_optionalChain([first, 'call',
|
|
4502
|
-
const next = _nullishCoalesce(_optionalChain([first, 'call',
|
|
4562
|
+
const prev = _nullishCoalesce(_optionalChain([first, 'call', _81 => _81(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _82 => _82.id]), () => ( null));
|
|
4563
|
+
const next = _nullishCoalesce(_optionalChain([first, 'call', _83 => _83(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _84 => _84.id]), () => ( null));
|
|
4503
4564
|
if (!message2.deletedAt || prev || next) {
|
|
4504
4565
|
const node = {
|
|
4505
4566
|
...message2,
|
|
@@ -4565,7 +4626,7 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
|
|
|
4565
4626
|
const latest = pool.sorted.findRight(
|
|
4566
4627
|
(m) => m.role === "assistant" && !m.deletedAt
|
|
4567
4628
|
);
|
|
4568
|
-
return _optionalChain([latest, 'optionalAccess',
|
|
4629
|
+
return _optionalChain([latest, 'optionalAccess', _85 => _85.copilotId]);
|
|
4569
4630
|
}
|
|
4570
4631
|
return {
|
|
4571
4632
|
// Readers
|
|
@@ -4596,11 +4657,11 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
|
|
|
4596
4657
|
*getAutoExecutingMessageIds() {
|
|
4597
4658
|
for (const messageId of myMessages) {
|
|
4598
4659
|
const message = getMessageById(messageId);
|
|
4599
|
-
if (_optionalChain([message, 'optionalAccess',
|
|
4660
|
+
if (_optionalChain([message, 'optionalAccess', _86 => _86.role]) === "assistant" && message.status === "awaiting-tool") {
|
|
4600
4661
|
const isAutoExecuting = message.contentSoFar.some((part) => {
|
|
4601
4662
|
if (part.type === "tool-invocation" && part.stage === "executing") {
|
|
4602
4663
|
const tool = toolsStore.getTool\u03A3(part.name, message.chatId).get();
|
|
4603
|
-
return typeof _optionalChain([tool, 'optionalAccess',
|
|
4664
|
+
return typeof _optionalChain([tool, 'optionalAccess', _87 => _87.execute]) === "function";
|
|
4604
4665
|
}
|
|
4605
4666
|
return false;
|
|
4606
4667
|
});
|
|
@@ -4748,7 +4809,7 @@ function createAi(config) {
|
|
|
4748
4809
|
flushPendingDeltas();
|
|
4749
4810
|
switch (msg.event) {
|
|
4750
4811
|
case "cmd-failed":
|
|
4751
|
-
_optionalChain([pendingCmd, 'optionalAccess',
|
|
4812
|
+
_optionalChain([pendingCmd, 'optionalAccess', _88 => _88.reject, 'call', _89 => _89(new Error(msg.error))]);
|
|
4752
4813
|
break;
|
|
4753
4814
|
case "settle": {
|
|
4754
4815
|
context.messagesStore.upsert(msg.message);
|
|
@@ -4825,7 +4886,7 @@ function createAi(config) {
|
|
|
4825
4886
|
return assertNever(msg, "Unhandled case");
|
|
4826
4887
|
}
|
|
4827
4888
|
}
|
|
4828
|
-
_optionalChain([pendingCmd, 'optionalAccess',
|
|
4889
|
+
_optionalChain([pendingCmd, 'optionalAccess', _90 => _90.resolve, 'call', _91 => _91(msg)]);
|
|
4829
4890
|
}
|
|
4830
4891
|
managedSocket.events.onMessage.subscribe(handleServerMessage);
|
|
4831
4892
|
managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
|
|
@@ -4901,9 +4962,9 @@ function createAi(config) {
|
|
|
4901
4962
|
invocationId,
|
|
4902
4963
|
result,
|
|
4903
4964
|
generationOptions: {
|
|
4904
|
-
copilotId: _optionalChain([options, 'optionalAccess',
|
|
4905
|
-
stream: _optionalChain([options, 'optionalAccess',
|
|
4906
|
-
timeout: _optionalChain([options, 'optionalAccess',
|
|
4965
|
+
copilotId: _optionalChain([options, 'optionalAccess', _92 => _92.copilotId]),
|
|
4966
|
+
stream: _optionalChain([options, 'optionalAccess', _93 => _93.stream]),
|
|
4967
|
+
timeout: _optionalChain([options, 'optionalAccess', _94 => _94.timeout]),
|
|
4907
4968
|
// Knowledge and tools aren't coming from the options, but retrieved
|
|
4908
4969
|
// from the global context
|
|
4909
4970
|
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
@@ -4921,7 +4982,7 @@ function createAi(config) {
|
|
|
4921
4982
|
}
|
|
4922
4983
|
}
|
|
4923
4984
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
4924
|
-
_optionalChain([win, 'optionalAccess',
|
|
4985
|
+
_optionalChain([win, 'optionalAccess', _95 => _95.addEventListener, 'call', _96 => _96("beforeunload", handleBeforeUnload, { once: true })]);
|
|
4925
4986
|
return Object.defineProperty(
|
|
4926
4987
|
{
|
|
4927
4988
|
[kInternal]: {
|
|
@@ -4940,7 +5001,7 @@ function createAi(config) {
|
|
|
4940
5001
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4941
5002
|
askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
|
|
4942
5003
|
const knowledge = context.knowledgeStore.getKnowledgeForChat(chatId);
|
|
4943
|
-
const requestKnowledge = _optionalChain([options, 'optionalAccess',
|
|
5004
|
+
const requestKnowledge = _optionalChain([options, 'optionalAccess', _97 => _97.knowledge]) || [];
|
|
4944
5005
|
const combinedKnowledge = [...knowledge, ...requestKnowledge];
|
|
4945
5006
|
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4946
5007
|
messagesStore.markMine(targetMessageId);
|
|
@@ -4950,9 +5011,9 @@ function createAi(config) {
|
|
|
4950
5011
|
sourceMessage: userMessage,
|
|
4951
5012
|
targetMessageId,
|
|
4952
5013
|
generationOptions: {
|
|
4953
|
-
copilotId: _optionalChain([options, 'optionalAccess',
|
|
4954
|
-
stream: _optionalChain([options, 'optionalAccess',
|
|
4955
|
-
timeout: _optionalChain([options, 'optionalAccess',
|
|
5014
|
+
copilotId: _optionalChain([options, 'optionalAccess', _98 => _98.copilotId]),
|
|
5015
|
+
stream: _optionalChain([options, 'optionalAccess', _99 => _99.stream]),
|
|
5016
|
+
timeout: _optionalChain([options, 'optionalAccess', _100 => _100.timeout]),
|
|
4956
5017
|
// Combine global knowledge with request-specific knowledge
|
|
4957
5018
|
knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
|
|
4958
5019
|
tools: tools.length > 0 ? tools : void 0
|
|
@@ -5024,7 +5085,7 @@ function replaceOrAppend(content, newItem, keyFn, now2) {
|
|
|
5024
5085
|
}
|
|
5025
5086
|
}
|
|
5026
5087
|
function closePart(prevPart, endedAt) {
|
|
5027
|
-
if (_optionalChain([prevPart, 'optionalAccess',
|
|
5088
|
+
if (_optionalChain([prevPart, 'optionalAccess', _101 => _101.type]) === "reasoning") {
|
|
5028
5089
|
prevPart.endedAt ??= endedAt;
|
|
5029
5090
|
}
|
|
5030
5091
|
}
|
|
@@ -5039,7 +5100,7 @@ function patchContentWithDelta(content, delta) {
|
|
|
5039
5100
|
const lastPart = parts[parts.length - 1];
|
|
5040
5101
|
switch (delta.type) {
|
|
5041
5102
|
case "text-delta":
|
|
5042
|
-
if (_optionalChain([lastPart, 'optionalAccess',
|
|
5103
|
+
if (_optionalChain([lastPart, 'optionalAccess', _102 => _102.type]) === "text") {
|
|
5043
5104
|
lastPart.text += delta.textDelta;
|
|
5044
5105
|
} else {
|
|
5045
5106
|
closePart(lastPart, now2);
|
|
@@ -5047,7 +5108,7 @@ function patchContentWithDelta(content, delta) {
|
|
|
5047
5108
|
}
|
|
5048
5109
|
break;
|
|
5049
5110
|
case "reasoning-delta":
|
|
5050
|
-
if (_optionalChain([lastPart, 'optionalAccess',
|
|
5111
|
+
if (_optionalChain([lastPart, 'optionalAccess', _103 => _103.type]) === "reasoning") {
|
|
5051
5112
|
lastPart.text += delta.textDelta;
|
|
5052
5113
|
} else {
|
|
5053
5114
|
closePart(lastPart, now2);
|
|
@@ -5067,8 +5128,8 @@ function patchContentWithDelta(content, delta) {
|
|
|
5067
5128
|
break;
|
|
5068
5129
|
}
|
|
5069
5130
|
case "tool-delta": {
|
|
5070
|
-
if (_optionalChain([lastPart, 'optionalAccess',
|
|
5071
|
-
_optionalChain([lastPart, 'access',
|
|
5131
|
+
if (_optionalChain([lastPart, 'optionalAccess', _104 => _104.type]) === "tool-invocation" && lastPart.stage === "receiving") {
|
|
5132
|
+
_optionalChain([lastPart, 'access', _105 => _105.__appendDelta, 'optionalCall', _106 => _106(delta.delta)]);
|
|
5072
5133
|
}
|
|
5073
5134
|
break;
|
|
5074
5135
|
}
|
|
@@ -5217,7 +5278,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5217
5278
|
return void 0;
|
|
5218
5279
|
}
|
|
5219
5280
|
async function makeAuthRequest(options) {
|
|
5220
|
-
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access',
|
|
5281
|
+
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _107 => _107.polyfills, 'optionalAccess', _108 => _108.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
|
|
5221
5282
|
if (authentication.type === "private") {
|
|
5222
5283
|
if (fetcher === void 0) {
|
|
5223
5284
|
throw new StopRetrying(
|
|
@@ -5233,7 +5294,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5233
5294
|
"The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
|
|
5234
5295
|
);
|
|
5235
5296
|
}
|
|
5236
|
-
_optionalChain([onAuthenticate, 'optionalCall',
|
|
5297
|
+
_optionalChain([onAuthenticate, 'optionalCall', _109 => _109(parsed.parsed)]);
|
|
5237
5298
|
return parsed;
|
|
5238
5299
|
}
|
|
5239
5300
|
if (authentication.type === "custom") {
|
|
@@ -5241,7 +5302,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5241
5302
|
if (response && typeof response === "object") {
|
|
5242
5303
|
if (typeof response.token === "string") {
|
|
5243
5304
|
const parsed = parseAuthToken(response.token);
|
|
5244
|
-
_optionalChain([onAuthenticate, 'optionalCall',
|
|
5305
|
+
_optionalChain([onAuthenticate, 'optionalCall', _110 => _110(parsed.parsed)]);
|
|
5245
5306
|
return parsed;
|
|
5246
5307
|
} else if (typeof response.error === "string") {
|
|
5247
5308
|
const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
|
|
@@ -5398,7 +5459,7 @@ function sendToPanel(message, options) {
|
|
|
5398
5459
|
...message,
|
|
5399
5460
|
source: "liveblocks-devtools-client"
|
|
5400
5461
|
};
|
|
5401
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
5462
|
+
if (!(_optionalChain([options, 'optionalAccess', _111 => _111.force]) || _bridgeActive)) {
|
|
5402
5463
|
return;
|
|
5403
5464
|
}
|
|
5404
5465
|
window.postMessage(fullMsg, "*");
|
|
@@ -5406,7 +5467,7 @@ function sendToPanel(message, options) {
|
|
|
5406
5467
|
var eventSource = makeEventSource();
|
|
5407
5468
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
5408
5469
|
window.addEventListener("message", (event) => {
|
|
5409
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
5470
|
+
if (event.source === window && _optionalChain([event, 'access', _112 => _112.data, 'optionalAccess', _113 => _113.source]) === "liveblocks-devtools-panel") {
|
|
5410
5471
|
eventSource.notify(event.data);
|
|
5411
5472
|
} else {
|
|
5412
5473
|
}
|
|
@@ -5548,7 +5609,7 @@ function fullSync(room) {
|
|
|
5548
5609
|
msg: "room::sync::full",
|
|
5549
5610
|
roomId: room.id,
|
|
5550
5611
|
status: room.getStatus(),
|
|
5551
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
5612
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _114 => _114.toTreeNode, 'call', _115 => _115("root"), 'access', _116 => _116.payload]), () => ( null)),
|
|
5552
5613
|
me,
|
|
5553
5614
|
others
|
|
5554
5615
|
});
|
|
@@ -5893,16 +5954,68 @@ function before(pos) {
|
|
|
5893
5954
|
}
|
|
5894
5955
|
return ONE;
|
|
5895
5956
|
}
|
|
5957
|
+
var VIEWPORT_START = 2;
|
|
5958
|
+
var VIEWPORT_STEP = 3;
|
|
5896
5959
|
function after(pos) {
|
|
5897
|
-
for (let i = 0; i
|
|
5960
|
+
for (let i = 0; i < pos.length; i++) {
|
|
5898
5961
|
const code = pos.charCodeAt(i);
|
|
5899
|
-
if (code
|
|
5900
|
-
|
|
5962
|
+
if (code < MIN_CODE || code > MAX_CODE) {
|
|
5963
|
+
return pos + ONE;
|
|
5901
5964
|
}
|
|
5902
|
-
|
|
5965
|
+
}
|
|
5966
|
+
while (pos.length > 1 && pos.charCodeAt(pos.length - 1) === MIN_CODE) {
|
|
5967
|
+
pos = pos.slice(0, -1);
|
|
5968
|
+
}
|
|
5969
|
+
if (pos.length === 0 || pos === ZERO) {
|
|
5970
|
+
return ONE;
|
|
5971
|
+
}
|
|
5972
|
+
let viewport = VIEWPORT_START;
|
|
5973
|
+
if (pos.length > VIEWPORT_START) {
|
|
5974
|
+
viewport = VIEWPORT_START + Math.ceil((pos.length - VIEWPORT_START) / VIEWPORT_STEP) * VIEWPORT_STEP;
|
|
5975
|
+
}
|
|
5976
|
+
const result = incrementWithinViewport(pos, viewport);
|
|
5977
|
+
if (result !== null) {
|
|
5978
|
+
return result;
|
|
5979
|
+
}
|
|
5980
|
+
viewport += VIEWPORT_STEP;
|
|
5981
|
+
const extendedResult = incrementWithinViewport(pos, viewport);
|
|
5982
|
+
if (extendedResult !== null) {
|
|
5983
|
+
return extendedResult;
|
|
5903
5984
|
}
|
|
5904
5985
|
return pos + ONE;
|
|
5905
5986
|
}
|
|
5987
|
+
function incrementWithinViewport(pos, viewport) {
|
|
5988
|
+
const digits = [];
|
|
5989
|
+
for (let i = 0; i < viewport; i++) {
|
|
5990
|
+
if (i < pos.length) {
|
|
5991
|
+
digits.push(pos.charCodeAt(i) - MIN_CODE);
|
|
5992
|
+
} else {
|
|
5993
|
+
digits.push(0);
|
|
5994
|
+
}
|
|
5995
|
+
}
|
|
5996
|
+
let carry = 1;
|
|
5997
|
+
for (let i = viewport - 1; i >= 0 && carry; i--) {
|
|
5998
|
+
const sum = digits[i] + carry;
|
|
5999
|
+
if (sum >= NUM_DIGITS) {
|
|
6000
|
+
digits[i] = 0;
|
|
6001
|
+
carry = 1;
|
|
6002
|
+
} else {
|
|
6003
|
+
digits[i] = sum;
|
|
6004
|
+
carry = 0;
|
|
6005
|
+
}
|
|
6006
|
+
}
|
|
6007
|
+
if (carry) {
|
|
6008
|
+
return null;
|
|
6009
|
+
}
|
|
6010
|
+
let result = "";
|
|
6011
|
+
for (const d of digits) {
|
|
6012
|
+
result += String.fromCharCode(d + MIN_CODE);
|
|
6013
|
+
}
|
|
6014
|
+
while (result.length > 1 && result.charCodeAt(result.length - 1) === MIN_CODE) {
|
|
6015
|
+
result = result.slice(0, -1);
|
|
6016
|
+
}
|
|
6017
|
+
return result;
|
|
6018
|
+
}
|
|
5906
6019
|
function between(lo, hi) {
|
|
5907
6020
|
if (lo < hi) {
|
|
5908
6021
|
return _between(lo, hi);
|
|
@@ -6011,7 +6124,7 @@ function createManagedPool(roomId, options) {
|
|
|
6011
6124
|
generateId: () => `${getCurrentConnectionId()}:${clock++}`,
|
|
6012
6125
|
generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
|
|
6013
6126
|
dispatch(ops, reverse, storageUpdates) {
|
|
6014
|
-
_optionalChain([onDispatch, 'optionalCall',
|
|
6127
|
+
_optionalChain([onDispatch, 'optionalCall', _117 => _117(ops, reverse, storageUpdates)]);
|
|
6015
6128
|
},
|
|
6016
6129
|
assertStorageIsWritable: () => {
|
|
6017
6130
|
if (!isStorageWritable()) {
|
|
@@ -6232,6 +6345,60 @@ function isMapStorageNode(node) {
|
|
|
6232
6345
|
function isRegisterStorageNode(node) {
|
|
6233
6346
|
return node[1].type === CrdtType.REGISTER;
|
|
6234
6347
|
}
|
|
6348
|
+
function isCompactRootNode(node) {
|
|
6349
|
+
return node[0] === "root";
|
|
6350
|
+
}
|
|
6351
|
+
function* compactNodesToNodeStream(compactNodes) {
|
|
6352
|
+
for (const cnode of compactNodes) {
|
|
6353
|
+
if (isCompactRootNode(cnode)) {
|
|
6354
|
+
yield [cnode[0], { type: CrdtType.OBJECT, data: cnode[1] }];
|
|
6355
|
+
continue;
|
|
6356
|
+
}
|
|
6357
|
+
switch (cnode[1]) {
|
|
6358
|
+
case CrdtType.OBJECT:
|
|
6359
|
+
yield [cnode[0], { type: CrdtType.OBJECT, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
6360
|
+
break;
|
|
6361
|
+
case CrdtType.LIST:
|
|
6362
|
+
yield [cnode[0], { type: CrdtType.LIST, parentId: cnode[2], parentKey: cnode[3] }];
|
|
6363
|
+
break;
|
|
6364
|
+
case CrdtType.MAP:
|
|
6365
|
+
yield [cnode[0], { type: CrdtType.MAP, parentId: cnode[2], parentKey: cnode[3] }];
|
|
6366
|
+
break;
|
|
6367
|
+
case CrdtType.REGISTER:
|
|
6368
|
+
yield [cnode[0], { type: CrdtType.REGISTER, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
6369
|
+
break;
|
|
6370
|
+
default:
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
}
|
|
6374
|
+
function* nodeStreamToCompactNodes(nodes) {
|
|
6375
|
+
for (const node of nodes) {
|
|
6376
|
+
if (isObjectStorageNode(node)) {
|
|
6377
|
+
if (isRootStorageNode(node)) {
|
|
6378
|
+
const id = node[0];
|
|
6379
|
+
const crdt = node[1];
|
|
6380
|
+
yield [id, crdt.data];
|
|
6381
|
+
} else {
|
|
6382
|
+
const id = node[0];
|
|
6383
|
+
const crdt = node[1];
|
|
6384
|
+
yield [id, CrdtType.OBJECT, crdt.parentId, crdt.parentKey, crdt.data];
|
|
6385
|
+
}
|
|
6386
|
+
} else if (isListStorageNode(node)) {
|
|
6387
|
+
const id = node[0];
|
|
6388
|
+
const crdt = node[1];
|
|
6389
|
+
yield [id, CrdtType.LIST, crdt.parentId, crdt.parentKey];
|
|
6390
|
+
} else if (isMapStorageNode(node)) {
|
|
6391
|
+
const id = node[0];
|
|
6392
|
+
const crdt = node[1];
|
|
6393
|
+
yield [id, CrdtType.MAP, crdt.parentId, crdt.parentKey];
|
|
6394
|
+
} else if (isRegisterStorageNode(node)) {
|
|
6395
|
+
const id = node[0];
|
|
6396
|
+
const crdt = node[1];
|
|
6397
|
+
yield [id, CrdtType.REGISTER, crdt.parentId, crdt.parentKey, crdt.data];
|
|
6398
|
+
} else {
|
|
6399
|
+
}
|
|
6400
|
+
}
|
|
6401
|
+
}
|
|
6235
6402
|
|
|
6236
6403
|
// src/crdts/LiveRegister.ts
|
|
6237
6404
|
var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
@@ -6309,29 +6476,27 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
6309
6476
|
};
|
|
6310
6477
|
|
|
6311
6478
|
// src/crdts/LiveList.ts
|
|
6312
|
-
function
|
|
6313
|
-
|
|
6314
|
-
const posB = itemB._parentPos;
|
|
6315
|
-
return posA === posB ? 0 : posA < posB ? -1 : 1;
|
|
6479
|
+
function childNodeLt(a, b) {
|
|
6480
|
+
return a._parentPos < b._parentPos;
|
|
6316
6481
|
}
|
|
6317
6482
|
var LiveList = class _LiveList extends AbstractCrdt {
|
|
6318
|
-
// TODO: Naive array at first, find a better data structure. Maybe an Order statistics tree?
|
|
6319
6483
|
#items;
|
|
6320
6484
|
#implicitlyDeletedItems;
|
|
6321
6485
|
#unacknowledgedSets;
|
|
6322
6486
|
constructor(items) {
|
|
6323
6487
|
super();
|
|
6324
|
-
this.#items = [];
|
|
6325
6488
|
this.#implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
|
|
6326
6489
|
this.#unacknowledgedSets = /* @__PURE__ */ new Map();
|
|
6327
|
-
|
|
6490
|
+
const nodes = [];
|
|
6491
|
+
let lastPos;
|
|
6328
6492
|
for (const item of items) {
|
|
6329
|
-
const
|
|
6493
|
+
const pos = makePosition(lastPos);
|
|
6330
6494
|
const node = lsonToLiveNode(item);
|
|
6331
|
-
node._setParentLink(this,
|
|
6332
|
-
|
|
6333
|
-
|
|
6495
|
+
node._setParentLink(this, pos);
|
|
6496
|
+
nodes.push(node);
|
|
6497
|
+
lastPos = pos;
|
|
6334
6498
|
}
|
|
6499
|
+
this.#items = SortedList.fromAlreadySorted(nodes, childNodeLt);
|
|
6335
6500
|
}
|
|
6336
6501
|
/** @internal */
|
|
6337
6502
|
static _deserialize([id, _], parentToChildren, pool) {
|
|
@@ -6345,7 +6510,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6345
6510
|
const crdt = node[1];
|
|
6346
6511
|
const child = deserialize(node, parentToChildren, pool);
|
|
6347
6512
|
child._setParentLink(list, crdt.parentKey);
|
|
6348
|
-
list
|
|
6513
|
+
list.#insert(child);
|
|
6349
6514
|
}
|
|
6350
6515
|
return list;
|
|
6351
6516
|
}
|
|
@@ -6376,24 +6541,40 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6376
6541
|
item._toOps(this._id, parentKey2),
|
|
6377
6542
|
void 0
|
|
6378
6543
|
);
|
|
6379
|
-
|
|
6544
|
+
for (const childOp of childOps) {
|
|
6545
|
+
ops.push(childOp);
|
|
6546
|
+
}
|
|
6380
6547
|
}
|
|
6381
6548
|
return ops;
|
|
6382
6549
|
}
|
|
6383
6550
|
/**
|
|
6384
|
-
*
|
|
6385
|
-
*
|
|
6386
|
-
* Adds a new item into the sorted list, in the correct position.
|
|
6551
|
+
* Inserts a new child into the list in the correct location (binary search
|
|
6552
|
+
* finds correct position efficiently). Returns the insertion index.
|
|
6387
6553
|
*/
|
|
6388
|
-
|
|
6389
|
-
this.#items.
|
|
6390
|
-
this.
|
|
6554
|
+
#insert(childNode) {
|
|
6555
|
+
const index = this.#items.add(childNode);
|
|
6556
|
+
this.invalidate();
|
|
6557
|
+
return index;
|
|
6391
6558
|
}
|
|
6392
|
-
/**
|
|
6393
|
-
|
|
6394
|
-
|
|
6559
|
+
/**
|
|
6560
|
+
* Updates an item's position and repositions it in the sorted list.
|
|
6561
|
+
* Encapsulates the remove -> mutate -> add cycle needed when changing sort keys.
|
|
6562
|
+
*
|
|
6563
|
+
* IMPORTANT: Item must exist in this list. List count remains unchanged.
|
|
6564
|
+
*/
|
|
6565
|
+
#updateItemPosition(item, newKey) {
|
|
6566
|
+
item._setParentLink(this, newKey);
|
|
6567
|
+
this.#items.reposition(item);
|
|
6395
6568
|
this.invalidate();
|
|
6396
6569
|
}
|
|
6570
|
+
/**
|
|
6571
|
+
* Updates an item's position by index. Safer than #updateItemPosition when you have
|
|
6572
|
+
* an index, as it ensures the item exists and is from this list.
|
|
6573
|
+
*/
|
|
6574
|
+
#updateItemPositionAt(index, newKey) {
|
|
6575
|
+
const item = nn(this.#items.at(index));
|
|
6576
|
+
this.#updateItemPosition(item, newKey);
|
|
6577
|
+
}
|
|
6397
6578
|
/** @internal */
|
|
6398
6579
|
_indexOfPosition(position) {
|
|
6399
6580
|
return this.#items.findIndex(
|
|
@@ -6425,10 +6606,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6425
6606
|
const deletedId = op.deletedId;
|
|
6426
6607
|
const indexOfItemWithSamePosition = this._indexOfPosition(key);
|
|
6427
6608
|
if (indexOfItemWithSamePosition !== -1) {
|
|
6428
|
-
const itemWithSamePosition =
|
|
6609
|
+
const itemWithSamePosition = nn(
|
|
6610
|
+
this.#items.removeAt(indexOfItemWithSamePosition)
|
|
6611
|
+
);
|
|
6429
6612
|
if (itemWithSamePosition._id === deletedId) {
|
|
6430
6613
|
itemWithSamePosition._detach();
|
|
6431
|
-
this.#items
|
|
6614
|
+
this.#items.add(child);
|
|
6432
6615
|
return {
|
|
6433
6616
|
modified: makeUpdate(this, [
|
|
6434
6617
|
setDelta(indexOfItemWithSamePosition, child)
|
|
@@ -6437,7 +6620,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6437
6620
|
};
|
|
6438
6621
|
} else {
|
|
6439
6622
|
this.#implicitlyDeletedItems.add(itemWithSamePosition);
|
|
6440
|
-
this.#items
|
|
6623
|
+
this.#items.remove(itemWithSamePosition);
|
|
6624
|
+
this.#items.add(child);
|
|
6441
6625
|
const delta = [
|
|
6442
6626
|
setDelta(indexOfItemWithSamePosition, child)
|
|
6443
6627
|
];
|
|
@@ -6460,7 +6644,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6460
6644
|
if (deleteDelta2) {
|
|
6461
6645
|
updates.push(deleteDelta2);
|
|
6462
6646
|
}
|
|
6463
|
-
this
|
|
6647
|
+
this.#insert(child);
|
|
6464
6648
|
updates.push(insertDelta(this._indexOfPosition(key), child));
|
|
6465
6649
|
return {
|
|
6466
6650
|
reverse: [],
|
|
@@ -6495,16 +6679,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6495
6679
|
};
|
|
6496
6680
|
}
|
|
6497
6681
|
if (indexOfItemWithSamePosition !== -1) {
|
|
6498
|
-
|
|
6499
|
-
this.#items
|
|
6682
|
+
const itemAtPosition = nn(
|
|
6683
|
+
this.#items.removeAt(indexOfItemWithSamePosition)
|
|
6500
6684
|
);
|
|
6501
|
-
|
|
6502
|
-
delta.push(deleteDelta(indexOfItemWithSamePosition,
|
|
6685
|
+
this.#implicitlyDeletedItems.add(itemAtPosition);
|
|
6686
|
+
delta.push(deleteDelta(indexOfItemWithSamePosition, itemAtPosition));
|
|
6503
6687
|
}
|
|
6504
|
-
const prevIndex = this.#items.
|
|
6505
|
-
existingItem
|
|
6506
|
-
this.
|
|
6507
|
-
const newIndex = this.#items.indexOf(existingItem);
|
|
6688
|
+
const prevIndex = this.#items.findIndex((item) => item === existingItem);
|
|
6689
|
+
this.#updateItemPosition(existingItem, op.parentKey);
|
|
6690
|
+
const newIndex = this.#items.findIndex((item) => item === existingItem);
|
|
6508
6691
|
if (newIndex !== prevIndex) {
|
|
6509
6692
|
delta.push(moveDelta(prevIndex, newIndex, existingItem));
|
|
6510
6693
|
}
|
|
@@ -6517,8 +6700,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6517
6700
|
if (orphan && this.#implicitlyDeletedItems.has(orphan)) {
|
|
6518
6701
|
orphan._setParentLink(this, op.parentKey);
|
|
6519
6702
|
this.#implicitlyDeletedItems.delete(orphan);
|
|
6520
|
-
this
|
|
6521
|
-
const recreatedItemIndex = this.#items.indexOf(orphan);
|
|
6703
|
+
const recreatedItemIndex = this.#insert(orphan);
|
|
6522
6704
|
return {
|
|
6523
6705
|
modified: makeUpdate(this, [
|
|
6524
6706
|
// If there is an item at this position, update is a set, else it's an insert
|
|
@@ -6529,7 +6711,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6529
6711
|
};
|
|
6530
6712
|
} else {
|
|
6531
6713
|
if (indexOfItemWithSamePosition !== -1) {
|
|
6532
|
-
this.#items.
|
|
6714
|
+
nn(this.#items.removeAt(indexOfItemWithSamePosition));
|
|
6533
6715
|
}
|
|
6534
6716
|
const { newItem, newIndex } = this.#createAttachItemAndSort(
|
|
6535
6717
|
op,
|
|
@@ -6588,12 +6770,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6588
6770
|
modified: false
|
|
6589
6771
|
};
|
|
6590
6772
|
} else {
|
|
6591
|
-
const oldPositionIndex = this.#items.
|
|
6773
|
+
const oldPositionIndex = this.#items.findIndex(
|
|
6774
|
+
(item) => item === existingItem
|
|
6775
|
+
);
|
|
6592
6776
|
if (itemIndexAtPosition !== -1) {
|
|
6593
6777
|
this.#shiftItemPosition(itemIndexAtPosition, key);
|
|
6594
6778
|
}
|
|
6595
|
-
existingItem
|
|
6596
|
-
this._sortItems();
|
|
6779
|
+
this.#updateItemPosition(existingItem, key);
|
|
6597
6780
|
const newIndex = this._indexOfPosition(key);
|
|
6598
6781
|
if (newIndex === oldPositionIndex) {
|
|
6599
6782
|
return { modified: false };
|
|
@@ -6610,7 +6793,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6610
6793
|
if (orphan && this.#implicitlyDeletedItems.has(orphan)) {
|
|
6611
6794
|
orphan._setParentLink(this, key);
|
|
6612
6795
|
this.#implicitlyDeletedItems.delete(orphan);
|
|
6613
|
-
this
|
|
6796
|
+
this.#insert(orphan);
|
|
6614
6797
|
const newIndex = this._indexOfPosition(key);
|
|
6615
6798
|
return {
|
|
6616
6799
|
modified: makeUpdate(this, [insertDelta(newIndex, orphan)]),
|
|
@@ -6631,7 +6814,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6631
6814
|
#applyInsertUndoRedo(op) {
|
|
6632
6815
|
const { id, parentKey: key } = op;
|
|
6633
6816
|
const child = creationOpToLiveNode(op);
|
|
6634
|
-
if (_optionalChain([this, 'access',
|
|
6817
|
+
if (_optionalChain([this, 'access', _118 => _118._pool, 'optionalAccess', _119 => _119.getNode, 'call', _120 => _120(id)]) !== void 0) {
|
|
6635
6818
|
return { modified: false };
|
|
6636
6819
|
}
|
|
6637
6820
|
child._attach(id, nn(this._pool));
|
|
@@ -6639,12 +6822,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6639
6822
|
const existingItemIndex = this._indexOfPosition(key);
|
|
6640
6823
|
let newKey = key;
|
|
6641
6824
|
if (existingItemIndex !== -1) {
|
|
6642
|
-
const before2 = _optionalChain([this, 'access',
|
|
6643
|
-
const after2 = _optionalChain([this, 'access',
|
|
6825
|
+
const before2 = _optionalChain([this, 'access', _121 => _121.#items, 'access', _122 => _122.at, 'call', _123 => _123(existingItemIndex), 'optionalAccess', _124 => _124._parentPos]);
|
|
6826
|
+
const after2 = _optionalChain([this, 'access', _125 => _125.#items, 'access', _126 => _126.at, 'call', _127 => _127(existingItemIndex + 1), 'optionalAccess', _128 => _128._parentPos]);
|
|
6644
6827
|
newKey = makePosition(before2, after2);
|
|
6645
6828
|
child._setParentLink(this, newKey);
|
|
6646
6829
|
}
|
|
6647
|
-
this
|
|
6830
|
+
this.#insert(child);
|
|
6648
6831
|
const newIndex = this._indexOfPosition(newKey);
|
|
6649
6832
|
return {
|
|
6650
6833
|
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
@@ -6654,7 +6837,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6654
6837
|
#applySetUndoRedo(op) {
|
|
6655
6838
|
const { id, parentKey: key } = op;
|
|
6656
6839
|
const child = creationOpToLiveNode(op);
|
|
6657
|
-
if (_optionalChain([this, 'access',
|
|
6840
|
+
if (_optionalChain([this, 'access', _129 => _129._pool, 'optionalAccess', _130 => _130.getNode, 'call', _131 => _131(id)]) !== void 0) {
|
|
6658
6841
|
return { modified: false };
|
|
6659
6842
|
}
|
|
6660
6843
|
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -6663,9 +6846,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6663
6846
|
child._setParentLink(this, key);
|
|
6664
6847
|
const newKey = key;
|
|
6665
6848
|
if (indexOfItemWithSameKey !== -1) {
|
|
6666
|
-
const existingItem = this.#items
|
|
6849
|
+
const existingItem = this.#items.at(indexOfItemWithSameKey);
|
|
6667
6850
|
existingItem._detach();
|
|
6668
|
-
this.#items
|
|
6851
|
+
this.#items.remove(existingItem);
|
|
6852
|
+
this.#items.add(child);
|
|
6669
6853
|
const reverse = HACK_addIntentAndDeletedIdToOperation(
|
|
6670
6854
|
existingItem._toOps(nn(this._id), key),
|
|
6671
6855
|
op.id
|
|
@@ -6682,7 +6866,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6682
6866
|
reverse
|
|
6683
6867
|
};
|
|
6684
6868
|
} else {
|
|
6685
|
-
this
|
|
6869
|
+
this.#insert(child);
|
|
6686
6870
|
this.#detachItemAssociatedToSetOperation(op.deletedId);
|
|
6687
6871
|
const newIndex = this._indexOfPosition(newKey);
|
|
6688
6872
|
return {
|
|
@@ -6724,13 +6908,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6724
6908
|
if (child) {
|
|
6725
6909
|
const parentKey = nn(child._parentKey);
|
|
6726
6910
|
const reverse = child._toOps(nn(this._id), parentKey);
|
|
6727
|
-
const indexToDelete = this.#items.
|
|
6911
|
+
const indexToDelete = this.#items.findIndex((item) => item === child);
|
|
6728
6912
|
if (indexToDelete === -1) {
|
|
6729
6913
|
return {
|
|
6730
6914
|
modified: false
|
|
6731
6915
|
};
|
|
6732
6916
|
}
|
|
6733
|
-
const
|
|
6917
|
+
const previousNode = this.#items.at(indexToDelete);
|
|
6918
|
+
this.#items.remove(child);
|
|
6734
6919
|
this.invalidate();
|
|
6735
6920
|
child._detach();
|
|
6736
6921
|
return {
|
|
@@ -6744,8 +6929,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6744
6929
|
if (this.#implicitlyDeletedItems.has(child)) {
|
|
6745
6930
|
this.#implicitlyDeletedItems.delete(child);
|
|
6746
6931
|
child._setParentLink(this, newKey);
|
|
6747
|
-
this
|
|
6748
|
-
const newIndex = this.#items.indexOf(child);
|
|
6932
|
+
const newIndex = this.#insert(child);
|
|
6749
6933
|
return {
|
|
6750
6934
|
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
6751
6935
|
reverse: []
|
|
@@ -6759,10 +6943,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6759
6943
|
}
|
|
6760
6944
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
6761
6945
|
if (existingItemIndex === -1) {
|
|
6762
|
-
const previousIndex = this.#items.
|
|
6763
|
-
child
|
|
6764
|
-
this.
|
|
6765
|
-
const newIndex = this.#items.indexOf(child);
|
|
6946
|
+
const previousIndex = this.#items.findIndex((item) => item === child);
|
|
6947
|
+
this.#updateItemPosition(child, newKey);
|
|
6948
|
+
const newIndex = this.#items.findIndex((item) => item === child);
|
|
6766
6949
|
if (newIndex === previousIndex) {
|
|
6767
6950
|
return {
|
|
6768
6951
|
modified: false
|
|
@@ -6773,14 +6956,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6773
6956
|
reverse: []
|
|
6774
6957
|
};
|
|
6775
6958
|
} else {
|
|
6776
|
-
this.#
|
|
6777
|
-
|
|
6778
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6959
|
+
this.#updateItemPositionAt(
|
|
6960
|
+
existingItemIndex,
|
|
6961
|
+
makePosition(newKey, _optionalChain([this, 'access', _132 => _132.#items, 'access', _133 => _133.at, 'call', _134 => _134(existingItemIndex + 1), 'optionalAccess', _135 => _135._parentPos]))
|
|
6779
6962
|
);
|
|
6780
|
-
const previousIndex = this.#items.
|
|
6781
|
-
child
|
|
6782
|
-
this.
|
|
6783
|
-
const newIndex = this.#items.indexOf(child);
|
|
6963
|
+
const previousIndex = this.#items.findIndex((item) => item === child);
|
|
6964
|
+
this.#updateItemPosition(child, newKey);
|
|
6965
|
+
const newIndex = this.#items.findIndex((item) => item === child);
|
|
6784
6966
|
if (newIndex === previousIndex) {
|
|
6785
6967
|
return {
|
|
6786
6968
|
modified: false
|
|
@@ -6798,14 +6980,18 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6798
6980
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
6799
6981
|
this.#implicitlyDeletedItems.delete(child);
|
|
6800
6982
|
if (existingItemIndex !== -1) {
|
|
6801
|
-
this.#items
|
|
6983
|
+
const existingItem = this.#items.at(existingItemIndex);
|
|
6984
|
+
existingItem._setParentLink(
|
|
6802
6985
|
this,
|
|
6803
|
-
makePosition(
|
|
6986
|
+
makePosition(
|
|
6987
|
+
newKey,
|
|
6988
|
+
_optionalChain([this, 'access', _136 => _136.#items, 'access', _137 => _137.at, 'call', _138 => _138(existingItemIndex + 1), 'optionalAccess', _139 => _139._parentPos])
|
|
6989
|
+
)
|
|
6804
6990
|
);
|
|
6991
|
+
this.#items.reposition(existingItem);
|
|
6805
6992
|
}
|
|
6806
6993
|
child._setParentLink(this, newKey);
|
|
6807
|
-
this
|
|
6808
|
-
const newIndex = this.#items.indexOf(child);
|
|
6994
|
+
const newIndex = this.#insert(child);
|
|
6809
6995
|
return {
|
|
6810
6996
|
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
6811
6997
|
reverse: []
|
|
@@ -6816,17 +7002,19 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6816
7002
|
modified: false
|
|
6817
7003
|
};
|
|
6818
7004
|
}
|
|
6819
|
-
const previousIndex = this.#items.
|
|
7005
|
+
const previousIndex = this.#items.findIndex((item) => item === child);
|
|
6820
7006
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
6821
7007
|
if (existingItemIndex !== -1) {
|
|
6822
|
-
this.#
|
|
6823
|
-
|
|
6824
|
-
makePosition(
|
|
7008
|
+
this.#updateItemPositionAt(
|
|
7009
|
+
existingItemIndex,
|
|
7010
|
+
makePosition(
|
|
7011
|
+
newKey,
|
|
7012
|
+
_optionalChain([this, 'access', _140 => _140.#items, 'access', _141 => _141.at, 'call', _142 => _142(existingItemIndex + 1), 'optionalAccess', _143 => _143._parentPos])
|
|
7013
|
+
)
|
|
6825
7014
|
);
|
|
6826
7015
|
}
|
|
6827
|
-
child
|
|
6828
|
-
this.
|
|
6829
|
-
const newIndex = this.#items.indexOf(child);
|
|
7016
|
+
this.#updateItemPosition(child, newKey);
|
|
7017
|
+
const newIndex = this.#items.findIndex((item) => item === child);
|
|
6830
7018
|
if (previousIndex === newIndex) {
|
|
6831
7019
|
return {
|
|
6832
7020
|
modified: false
|
|
@@ -6843,18 +7031,17 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6843
7031
|
}
|
|
6844
7032
|
#applySetChildKeyUndoRedo(newKey, child) {
|
|
6845
7033
|
const previousKey = nn(child._parentKey);
|
|
6846
|
-
const previousIndex = this.#items.
|
|
7034
|
+
const previousIndex = this.#items.findIndex((item) => item === child);
|
|
6847
7035
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
6848
7036
|
let actualNewKey = newKey;
|
|
6849
7037
|
if (existingItemIndex !== -1) {
|
|
6850
7038
|
actualNewKey = makePosition(
|
|
6851
7039
|
newKey,
|
|
6852
|
-
_optionalChain([this, 'access',
|
|
7040
|
+
_optionalChain([this, 'access', _144 => _144.#items, 'access', _145 => _145.at, 'call', _146 => _146(existingItemIndex + 1), 'optionalAccess', _147 => _147._parentPos])
|
|
6853
7041
|
);
|
|
6854
7042
|
}
|
|
6855
|
-
child
|
|
6856
|
-
this.
|
|
6857
|
-
const newIndex = this.#items.indexOf(child);
|
|
7043
|
+
this.#updateItemPosition(child, actualNewKey);
|
|
7044
|
+
const newIndex = this.#items.findIndex((item) => item === child);
|
|
6858
7045
|
if (previousIndex === newIndex) {
|
|
6859
7046
|
return {
|
|
6860
7047
|
modified: false
|
|
@@ -6907,7 +7094,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6907
7094
|
* @param element The element to add to the end of the LiveList.
|
|
6908
7095
|
*/
|
|
6909
7096
|
push(element) {
|
|
6910
|
-
_optionalChain([this, 'access',
|
|
7097
|
+
_optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
|
|
6911
7098
|
return this.insert(element, this.length);
|
|
6912
7099
|
}
|
|
6913
7100
|
/**
|
|
@@ -6916,18 +7103,18 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6916
7103
|
* @param index The index at which you want to insert the element.
|
|
6917
7104
|
*/
|
|
6918
7105
|
insert(element, index) {
|
|
6919
|
-
_optionalChain([this, 'access',
|
|
7106
|
+
_optionalChain([this, 'access', _151 => _151._pool, 'optionalAccess', _152 => _152.assertStorageIsWritable, 'call', _153 => _153()]);
|
|
6920
7107
|
if (index < 0 || index > this.#items.length) {
|
|
6921
7108
|
throw new Error(
|
|
6922
7109
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
6923
7110
|
);
|
|
6924
7111
|
}
|
|
6925
|
-
const before2 = this.#items
|
|
6926
|
-
const after2 = this.#items
|
|
7112
|
+
const before2 = _optionalChain([this, 'access', _154 => _154.#items, 'access', _155 => _155.at, 'call', _156 => _156(index - 1), 'optionalAccess', _157 => _157._parentPos]);
|
|
7113
|
+
const after2 = _optionalChain([this, 'access', _158 => _158.#items, 'access', _159 => _159.at, 'call', _160 => _160(index), 'optionalAccess', _161 => _161._parentPos]);
|
|
6927
7114
|
const position = makePosition(before2, after2);
|
|
6928
7115
|
const value = lsonToLiveNode(element);
|
|
6929
7116
|
value._setParentLink(this, position);
|
|
6930
|
-
this
|
|
7117
|
+
this.#insert(value);
|
|
6931
7118
|
if (this._pool && this._id) {
|
|
6932
7119
|
const id = this._pool.generateId();
|
|
6933
7120
|
value._attach(id, this._pool);
|
|
@@ -6946,7 +7133,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6946
7133
|
* @param targetIndex The index where the element should be after moving.
|
|
6947
7134
|
*/
|
|
6948
7135
|
move(index, targetIndex) {
|
|
6949
|
-
_optionalChain([this, 'access',
|
|
7136
|
+
_optionalChain([this, 'access', _162 => _162._pool, 'optionalAccess', _163 => _163.assertStorageIsWritable, 'call', _164 => _164()]);
|
|
6950
7137
|
if (targetIndex < 0) {
|
|
6951
7138
|
throw new Error("targetIndex cannot be less than 0");
|
|
6952
7139
|
}
|
|
@@ -6964,17 +7151,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6964
7151
|
let beforePosition = null;
|
|
6965
7152
|
let afterPosition = null;
|
|
6966
7153
|
if (index < targetIndex) {
|
|
6967
|
-
afterPosition = targetIndex === this.#items.length - 1 ? void 0 : this.#items
|
|
6968
|
-
beforePosition = this.#items
|
|
7154
|
+
afterPosition = targetIndex === this.#items.length - 1 ? void 0 : _optionalChain([this, 'access', _165 => _165.#items, 'access', _166 => _166.at, 'call', _167 => _167(targetIndex + 1), 'optionalAccess', _168 => _168._parentPos]);
|
|
7155
|
+
beforePosition = this.#items.at(targetIndex)._parentPos;
|
|
6969
7156
|
} else {
|
|
6970
|
-
afterPosition = this.#items
|
|
6971
|
-
beforePosition = targetIndex === 0 ? void 0 : this.#items
|
|
7157
|
+
afterPosition = this.#items.at(targetIndex)._parentPos;
|
|
7158
|
+
beforePosition = targetIndex === 0 ? void 0 : _optionalChain([this, 'access', _169 => _169.#items, 'access', _170 => _170.at, 'call', _171 => _171(targetIndex - 1), 'optionalAccess', _172 => _172._parentPos]);
|
|
6972
7159
|
}
|
|
6973
7160
|
const position = makePosition(beforePosition, afterPosition);
|
|
6974
|
-
const item = this.#items
|
|
7161
|
+
const item = this.#items.at(index);
|
|
6975
7162
|
const previousPosition = item._getParentKeyOrThrow();
|
|
6976
|
-
|
|
6977
|
-
this._sortItems();
|
|
7163
|
+
this.#updateItemPositionAt(index, position);
|
|
6978
7164
|
if (this._pool && this._id) {
|
|
6979
7165
|
const storageUpdates = /* @__PURE__ */ new Map([
|
|
6980
7166
|
[this._id, makeUpdate(this, [moveDelta(index, targetIndex, item)])]
|
|
@@ -7004,15 +7190,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7004
7190
|
* @param index The index of the element to delete
|
|
7005
7191
|
*/
|
|
7006
7192
|
delete(index) {
|
|
7007
|
-
_optionalChain([this, 'access',
|
|
7193
|
+
_optionalChain([this, 'access', _173 => _173._pool, 'optionalAccess', _174 => _174.assertStorageIsWritable, 'call', _175 => _175()]);
|
|
7008
7194
|
if (index < 0 || index >= this.#items.length) {
|
|
7009
7195
|
throw new Error(
|
|
7010
7196
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
7011
7197
|
);
|
|
7012
7198
|
}
|
|
7013
|
-
const item = this.#items
|
|
7199
|
+
const item = this.#items.at(index);
|
|
7014
7200
|
item._detach();
|
|
7015
|
-
|
|
7201
|
+
this.#items.remove(item);
|
|
7016
7202
|
this.invalidate();
|
|
7017
7203
|
if (this._pool) {
|
|
7018
7204
|
const childRecordId = item._id;
|
|
@@ -7020,7 +7206,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7020
7206
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7021
7207
|
storageUpdates.set(
|
|
7022
7208
|
nn(this._id),
|
|
7023
|
-
makeUpdate(this, [deleteDelta(index,
|
|
7209
|
+
makeUpdate(this, [deleteDelta(index, item)])
|
|
7024
7210
|
);
|
|
7025
7211
|
this._pool.dispatch(
|
|
7026
7212
|
[
|
|
@@ -7037,7 +7223,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7037
7223
|
}
|
|
7038
7224
|
}
|
|
7039
7225
|
clear() {
|
|
7040
|
-
_optionalChain([this, 'access',
|
|
7226
|
+
_optionalChain([this, 'access', _176 => _176._pool, 'optionalAccess', _177 => _177.assertStorageIsWritable, 'call', _178 => _178()]);
|
|
7041
7227
|
if (this._pool) {
|
|
7042
7228
|
const ops = [];
|
|
7043
7229
|
const reverseOps = [];
|
|
@@ -7057,7 +7243,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7057
7243
|
updateDelta.push(deleteDelta(0, item));
|
|
7058
7244
|
}
|
|
7059
7245
|
}
|
|
7060
|
-
this.#items
|
|
7246
|
+
this.#items.clear();
|
|
7061
7247
|
this.invalidate();
|
|
7062
7248
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7063
7249
|
storageUpdates.set(nn(this._id), makeUpdate(this, updateDelta));
|
|
@@ -7066,24 +7252,25 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7066
7252
|
for (const item of this.#items) {
|
|
7067
7253
|
item._detach();
|
|
7068
7254
|
}
|
|
7069
|
-
this.#items
|
|
7255
|
+
this.#items.clear();
|
|
7070
7256
|
this.invalidate();
|
|
7071
7257
|
}
|
|
7072
7258
|
}
|
|
7073
7259
|
set(index, item) {
|
|
7074
|
-
_optionalChain([this, 'access',
|
|
7260
|
+
_optionalChain([this, 'access', _179 => _179._pool, 'optionalAccess', _180 => _180.assertStorageIsWritable, 'call', _181 => _181()]);
|
|
7075
7261
|
if (index < 0 || index >= this.#items.length) {
|
|
7076
7262
|
throw new Error(
|
|
7077
7263
|
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
7078
7264
|
);
|
|
7079
7265
|
}
|
|
7080
|
-
const existingItem = this.#items
|
|
7266
|
+
const existingItem = this.#items.at(index);
|
|
7081
7267
|
const position = existingItem._getParentKeyOrThrow();
|
|
7082
7268
|
const existingId = existingItem._id;
|
|
7083
7269
|
existingItem._detach();
|
|
7084
7270
|
const value = lsonToLiveNode(item);
|
|
7085
7271
|
value._setParentLink(this, position);
|
|
7086
|
-
this.#items
|
|
7272
|
+
this.#items.remove(existingItem);
|
|
7273
|
+
this.#items.add(value);
|
|
7087
7274
|
this.invalidate();
|
|
7088
7275
|
if (this._pool && this._id) {
|
|
7089
7276
|
const id = this._pool.generateId();
|
|
@@ -7106,11 +7293,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7106
7293
|
* Returns an Array of all the elements in the LiveList.
|
|
7107
7294
|
*/
|
|
7108
7295
|
toArray() {
|
|
7109
|
-
return this.#items
|
|
7110
|
-
(entry) => liveNodeToLson(entry)
|
|
7111
|
-
// ^^^^^^^^
|
|
7112
|
-
// FIXME! This isn't safe.
|
|
7113
|
-
);
|
|
7296
|
+
return Array.from(this.#items, (entry) => liveNodeToLson(entry));
|
|
7114
7297
|
}
|
|
7115
7298
|
/**
|
|
7116
7299
|
* Tests whether all elements pass the test implemented by the provided function.
|
|
@@ -7160,7 +7343,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7160
7343
|
if (index < 0 || index >= this.#items.length) {
|
|
7161
7344
|
return void 0;
|
|
7162
7345
|
}
|
|
7163
|
-
|
|
7346
|
+
const item = this.#items.at(index);
|
|
7347
|
+
return item ? liveNodeToLson(item) : void 0;
|
|
7164
7348
|
}
|
|
7165
7349
|
/**
|
|
7166
7350
|
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
|
|
@@ -7186,14 +7370,20 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7186
7370
|
* @returns An array with each element being the result of the callback function.
|
|
7187
7371
|
*/
|
|
7188
7372
|
map(callback) {
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7373
|
+
const result = [];
|
|
7374
|
+
let i = 0;
|
|
7375
|
+
for (const entry of this.#items) {
|
|
7376
|
+
result.push(
|
|
7377
|
+
callback(
|
|
7378
|
+
liveNodeToLson(entry),
|
|
7379
|
+
// ^^^^^^^^
|
|
7380
|
+
// FIXME! This isn't safe.
|
|
7381
|
+
i
|
|
7382
|
+
)
|
|
7383
|
+
);
|
|
7384
|
+
i++;
|
|
7385
|
+
}
|
|
7386
|
+
return result;
|
|
7197
7387
|
}
|
|
7198
7388
|
/**
|
|
7199
7389
|
* Tests whether at least one element in the LiveList passes the test implemented by the provided function.
|
|
@@ -7210,26 +7400,30 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7210
7400
|
const newItem = creationOpToLiveNode(op);
|
|
7211
7401
|
newItem._attach(op.id, nn(this._pool));
|
|
7212
7402
|
newItem._setParentLink(this, key);
|
|
7213
|
-
this
|
|
7403
|
+
this.#insert(newItem);
|
|
7214
7404
|
const newIndex = this._indexOfPosition(key);
|
|
7215
7405
|
return { newItem, newIndex };
|
|
7216
7406
|
}
|
|
7217
7407
|
#shiftItemPosition(index, key) {
|
|
7218
7408
|
const shiftedPosition = makePosition(
|
|
7219
7409
|
key,
|
|
7220
|
-
this.#items.length > index + 1 ? _optionalChain([this, 'access',
|
|
7410
|
+
this.#items.length > index + 1 ? _optionalChain([this, 'access', _182 => _182.#items, 'access', _183 => _183.at, 'call', _184 => _184(index + 1), 'optionalAccess', _185 => _185._parentPos]) : void 0
|
|
7221
7411
|
);
|
|
7222
|
-
this.#
|
|
7412
|
+
this.#updateItemPositionAt(index, shiftedPosition);
|
|
7223
7413
|
}
|
|
7224
7414
|
/** @internal */
|
|
7225
7415
|
_toTreeNode(key) {
|
|
7416
|
+
const payload = [];
|
|
7417
|
+
let index = 0;
|
|
7418
|
+
for (const item of this.#items) {
|
|
7419
|
+
payload.push(item.toTreeNode(index.toString()));
|
|
7420
|
+
index++;
|
|
7421
|
+
}
|
|
7226
7422
|
return {
|
|
7227
7423
|
type: "LiveList",
|
|
7228
7424
|
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
7229
7425
|
key,
|
|
7230
|
-
payload
|
|
7231
|
-
(item, index) => item.toTreeNode(index.toString())
|
|
7232
|
-
)
|
|
7426
|
+
payload
|
|
7233
7427
|
};
|
|
7234
7428
|
}
|
|
7235
7429
|
toImmutable() {
|
|
@@ -7237,11 +7431,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7237
7431
|
}
|
|
7238
7432
|
/** @internal */
|
|
7239
7433
|
_toImmutable() {
|
|
7240
|
-
const result = this.#items
|
|
7434
|
+
const result = Array.from(this.#items, (node) => node.toImmutable());
|
|
7241
7435
|
return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
|
|
7242
7436
|
}
|
|
7243
7437
|
clone() {
|
|
7244
|
-
return new _LiveList(
|
|
7438
|
+
return new _LiveList(
|
|
7439
|
+
Array.from(this.#items, (item) => item.clone())
|
|
7440
|
+
);
|
|
7245
7441
|
}
|
|
7246
7442
|
};
|
|
7247
7443
|
var LiveListIterator = class {
|
|
@@ -7348,7 +7544,9 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7348
7544
|
};
|
|
7349
7545
|
ops.push(op);
|
|
7350
7546
|
for (const [key, value] of this.#map) {
|
|
7351
|
-
|
|
7547
|
+
for (const childOp of value._toOps(this._id, key)) {
|
|
7548
|
+
ops.push(childOp);
|
|
7549
|
+
}
|
|
7352
7550
|
}
|
|
7353
7551
|
return ops;
|
|
7354
7552
|
}
|
|
@@ -7482,7 +7680,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7482
7680
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
7483
7681
|
*/
|
|
7484
7682
|
set(key, value) {
|
|
7485
|
-
_optionalChain([this, 'access',
|
|
7683
|
+
_optionalChain([this, 'access', _186 => _186._pool, 'optionalAccess', _187 => _187.assertStorageIsWritable, 'call', _188 => _188()]);
|
|
7486
7684
|
const oldValue = this.#map.get(key);
|
|
7487
7685
|
if (oldValue) {
|
|
7488
7686
|
oldValue._detach();
|
|
@@ -7528,7 +7726,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7528
7726
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
7529
7727
|
*/
|
|
7530
7728
|
delete(key) {
|
|
7531
|
-
_optionalChain([this, 'access',
|
|
7729
|
+
_optionalChain([this, 'access', _189 => _189._pool, 'optionalAccess', _190 => _190.assertStorageIsWritable, 'call', _191 => _191()]);
|
|
7532
7730
|
const item = this.#map.get(key);
|
|
7533
7731
|
if (item === void 0) {
|
|
7534
7732
|
return false;
|
|
@@ -7711,8 +7909,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7711
7909
|
return [root, parentToChildren];
|
|
7712
7910
|
}
|
|
7713
7911
|
/** @private Do not use this API directly */
|
|
7714
|
-
static _fromItems(
|
|
7715
|
-
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(
|
|
7912
|
+
static _fromItems(nodes, pool) {
|
|
7913
|
+
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(nodes);
|
|
7716
7914
|
return _LiveObject._deserialize(
|
|
7717
7915
|
["root", root],
|
|
7718
7916
|
parentToChildren,
|
|
@@ -7747,7 +7945,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7747
7945
|
ops.push(op);
|
|
7748
7946
|
for (const [key, value] of this.#map) {
|
|
7749
7947
|
if (isLiveNode(value)) {
|
|
7750
|
-
|
|
7948
|
+
for (const childOp of value._toOps(this._id, key)) {
|
|
7949
|
+
ops.push(childOp);
|
|
7950
|
+
}
|
|
7751
7951
|
} else {
|
|
7752
7952
|
op.data[key] = value;
|
|
7753
7953
|
}
|
|
@@ -7916,7 +8116,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7916
8116
|
for (const key in op.data) {
|
|
7917
8117
|
const oldValue = this.#map.get(key);
|
|
7918
8118
|
if (isLiveNode(oldValue)) {
|
|
7919
|
-
|
|
8119
|
+
for (const childOp of oldValue._toOps(id, key)) {
|
|
8120
|
+
reverse.push(childOp);
|
|
8121
|
+
}
|
|
7920
8122
|
oldValue._detach();
|
|
7921
8123
|
} else if (oldValue !== void 0) {
|
|
7922
8124
|
reverseUpdate.data[key] = oldValue;
|
|
@@ -8009,7 +8211,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8009
8211
|
* @param value The value of the property to add
|
|
8010
8212
|
*/
|
|
8011
8213
|
set(key, value) {
|
|
8012
|
-
_optionalChain([this, 'access',
|
|
8214
|
+
_optionalChain([this, 'access', _192 => _192._pool, 'optionalAccess', _193 => _193.assertStorageIsWritable, 'call', _194 => _194()]);
|
|
8013
8215
|
this.update({ [key]: value });
|
|
8014
8216
|
}
|
|
8015
8217
|
/**
|
|
@@ -8024,7 +8226,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8024
8226
|
* @param key The key of the property to delete
|
|
8025
8227
|
*/
|
|
8026
8228
|
delete(key) {
|
|
8027
|
-
_optionalChain([this, 'access',
|
|
8229
|
+
_optionalChain([this, 'access', _195 => _195._pool, 'optionalAccess', _196 => _196.assertStorageIsWritable, 'call', _197 => _197()]);
|
|
8028
8230
|
const keyAsString = key;
|
|
8029
8231
|
const oldValue = this.#map.get(keyAsString);
|
|
8030
8232
|
if (oldValue === void 0) {
|
|
@@ -8079,7 +8281,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8079
8281
|
* @param patch The object used to overrides properties
|
|
8080
8282
|
*/
|
|
8081
8283
|
update(patch) {
|
|
8082
|
-
_optionalChain([this, 'access',
|
|
8284
|
+
_optionalChain([this, 'access', _198 => _198._pool, 'optionalAccess', _199 => _199.assertStorageIsWritable, 'call', _200 => _200()]);
|
|
8083
8285
|
if (_LiveObject.detectLargeObjects) {
|
|
8084
8286
|
const data = {};
|
|
8085
8287
|
for (const [key, value] of this.#map) {
|
|
@@ -8140,7 +8342,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8140
8342
|
}
|
|
8141
8343
|
const oldValue = this.#map.get(key);
|
|
8142
8344
|
if (isLiveNode(oldValue)) {
|
|
8143
|
-
|
|
8345
|
+
for (const childOp of oldValue._toOps(this._id, key)) {
|
|
8346
|
+
reverseOps.push(childOp);
|
|
8347
|
+
}
|
|
8144
8348
|
oldValue._detach();
|
|
8145
8349
|
} else if (oldValue === void 0) {
|
|
8146
8350
|
reverseOps.push({ type: OpCode.DELETE_OBJECT_KEY, id: this._id, key });
|
|
@@ -8161,7 +8365,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8161
8365
|
if (createCrdtOp) {
|
|
8162
8366
|
this.#unackedOpsByKey.set(key, nn(createCrdtOp.opId));
|
|
8163
8367
|
}
|
|
8164
|
-
|
|
8368
|
+
for (const childOp of newAttachChildOps) {
|
|
8369
|
+
ops.push(childOp);
|
|
8370
|
+
}
|
|
8165
8371
|
} else {
|
|
8166
8372
|
updatedProps[key] = newValue;
|
|
8167
8373
|
this.#unackedOpsByKey.set(key, opId);
|
|
@@ -8322,10 +8528,7 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8322
8528
|
const ops = [];
|
|
8323
8529
|
currentItems.forEach((_, id) => {
|
|
8324
8530
|
if (!newItems.get(id)) {
|
|
8325
|
-
ops.push({
|
|
8326
|
-
type: OpCode.DELETE_CRDT,
|
|
8327
|
-
id
|
|
8328
|
-
});
|
|
8531
|
+
ops.push({ type: OpCode.DELETE_CRDT, id });
|
|
8329
8532
|
}
|
|
8330
8533
|
});
|
|
8331
8534
|
newItems.forEach((crdt, id) => {
|
|
@@ -8538,6 +8741,29 @@ function isJsonObject(data) {
|
|
|
8538
8741
|
return !isJsonScalar(data) && !isJsonArray(data);
|
|
8539
8742
|
}
|
|
8540
8743
|
|
|
8744
|
+
// src/lib/stopwatch.ts
|
|
8745
|
+
function makeStopWatch() {
|
|
8746
|
+
let startTime = 0;
|
|
8747
|
+
let lastLapTime = 0;
|
|
8748
|
+
let laps;
|
|
8749
|
+
function start() {
|
|
8750
|
+
laps = [];
|
|
8751
|
+
startTime = performance.now();
|
|
8752
|
+
lastLapTime = startTime;
|
|
8753
|
+
}
|
|
8754
|
+
function lap(now2 = performance.now()) {
|
|
8755
|
+
laps.push(now2 - lastLapTime);
|
|
8756
|
+
lastLapTime = now2;
|
|
8757
|
+
}
|
|
8758
|
+
function stop() {
|
|
8759
|
+
const endTime = performance.now();
|
|
8760
|
+
lap(endTime);
|
|
8761
|
+
const total = endTime - startTime;
|
|
8762
|
+
return { total, laps };
|
|
8763
|
+
}
|
|
8764
|
+
return { start, lap, stop };
|
|
8765
|
+
}
|
|
8766
|
+
|
|
8541
8767
|
// src/protocol/ClientMsg.ts
|
|
8542
8768
|
var ClientMsgCode = Object.freeze({
|
|
8543
8769
|
// For Presence
|
|
@@ -8790,7 +9016,6 @@ function defaultMessageFromContext(context) {
|
|
|
8790
9016
|
}
|
|
8791
9017
|
|
|
8792
9018
|
// src/room.ts
|
|
8793
|
-
var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 512;
|
|
8794
9019
|
function makeIdFactory(connectionId) {
|
|
8795
9020
|
let count = 0;
|
|
8796
9021
|
return () => `${connectionId}:${count++}`;
|
|
@@ -8813,18 +9038,35 @@ function installBackgroundTabSpy() {
|
|
|
8813
9038
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
8814
9039
|
const inBackgroundSince = { current: null };
|
|
8815
9040
|
function onVisibilityChange() {
|
|
8816
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
9041
|
+
if (_optionalChain([doc, 'optionalAccess', _201 => _201.visibilityState]) === "hidden") {
|
|
8817
9042
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
8818
9043
|
} else {
|
|
8819
9044
|
inBackgroundSince.current = null;
|
|
8820
9045
|
}
|
|
8821
9046
|
}
|
|
8822
|
-
_optionalChain([doc, 'optionalAccess',
|
|
9047
|
+
_optionalChain([doc, 'optionalAccess', _202 => _202.addEventListener, 'call', _203 => _203("visibilitychange", onVisibilityChange)]);
|
|
8823
9048
|
const unsub = () => {
|
|
8824
|
-
_optionalChain([doc, 'optionalAccess',
|
|
9049
|
+
_optionalChain([doc, 'optionalAccess', _204 => _204.removeEventListener, 'call', _205 => _205("visibilitychange", onVisibilityChange)]);
|
|
8825
9050
|
};
|
|
8826
9051
|
return [inBackgroundSince, unsub];
|
|
8827
9052
|
}
|
|
9053
|
+
function makeNodeMapBuffer() {
|
|
9054
|
+
let map = /* @__PURE__ */ new Map();
|
|
9055
|
+
return {
|
|
9056
|
+
/** Append a "page" of nodes to the current NodeMap buffer. */
|
|
9057
|
+
append(chunk2) {
|
|
9058
|
+
for (const [id, node] of chunk2) {
|
|
9059
|
+
map.set(id, node);
|
|
9060
|
+
}
|
|
9061
|
+
},
|
|
9062
|
+
/** Return the contents of the current NodeMap buffer, and create a fresh new one. */
|
|
9063
|
+
take() {
|
|
9064
|
+
const result = map;
|
|
9065
|
+
map = /* @__PURE__ */ new Map();
|
|
9066
|
+
return result;
|
|
9067
|
+
}
|
|
9068
|
+
};
|
|
9069
|
+
}
|
|
8828
9070
|
function createRoom(options, config) {
|
|
8829
9071
|
const roomId = config.roomId;
|
|
8830
9072
|
const initialPresence = options.initialPresence;
|
|
@@ -8885,6 +9127,8 @@ function createRoom(options, config) {
|
|
|
8885
9127
|
activeBatch: null,
|
|
8886
9128
|
unacknowledgedOps: /* @__PURE__ */ new Map()
|
|
8887
9129
|
};
|
|
9130
|
+
const nodeMapBuffer = makeNodeMapBuffer();
|
|
9131
|
+
const stopwatch = config.enableDebugLogging ? makeStopWatch() : void 0;
|
|
8888
9132
|
let lastTokenKey;
|
|
8889
9133
|
function onStatusDidChange(newStatus) {
|
|
8890
9134
|
const authValue = managedSocket.authValue;
|
|
@@ -8989,7 +9233,7 @@ function createRoom(options, config) {
|
|
|
8989
9233
|
}
|
|
8990
9234
|
}
|
|
8991
9235
|
function isStorageWritable() {
|
|
8992
|
-
const scopes = _optionalChain([context, 'access',
|
|
9236
|
+
const scopes = _optionalChain([context, 'access', _206 => _206.dynamicSessionInfoSig, 'access', _207 => _207.get, 'call', _208 => _208(), 'optionalAccess', _209 => _209.scopes]);
|
|
8993
9237
|
return scopes !== void 0 ? canWriteStorage(scopes) : true;
|
|
8994
9238
|
}
|
|
8995
9239
|
const eventHub = {
|
|
@@ -9039,100 +9283,8 @@ function createRoom(options, config) {
|
|
|
9039
9283
|
...options2
|
|
9040
9284
|
});
|
|
9041
9285
|
}
|
|
9042
|
-
function* chunkOps(msg) {
|
|
9043
|
-
const { ops, ...rest } = msg;
|
|
9044
|
-
if (ops.length < 2) {
|
|
9045
|
-
throw new Error("Cannot split ops into smaller chunks");
|
|
9046
|
-
}
|
|
9047
|
-
const mid = Math.floor(ops.length / 2);
|
|
9048
|
-
const firstHalf = ops.slice(0, mid);
|
|
9049
|
-
const secondHalf = ops.slice(mid);
|
|
9050
|
-
for (const halfOps of [firstHalf, secondHalf]) {
|
|
9051
|
-
const half = { ops: halfOps, ...rest };
|
|
9052
|
-
const text = stringifyOrLog([half]);
|
|
9053
|
-
if (!isTooBigForWebSocket(text)) {
|
|
9054
|
-
yield text;
|
|
9055
|
-
} else {
|
|
9056
|
-
yield* chunkOps(half);
|
|
9057
|
-
}
|
|
9058
|
-
}
|
|
9059
|
-
}
|
|
9060
|
-
function* chunkMessages(messages) {
|
|
9061
|
-
if (messages.length < 2) {
|
|
9062
|
-
if (messages[0].type === ClientMsgCode.UPDATE_STORAGE) {
|
|
9063
|
-
yield* chunkOps(messages[0]);
|
|
9064
|
-
return;
|
|
9065
|
-
} else {
|
|
9066
|
-
throw new Error(
|
|
9067
|
-
"Cannot split into chunks smaller than the allowed message size"
|
|
9068
|
-
);
|
|
9069
|
-
}
|
|
9070
|
-
}
|
|
9071
|
-
const mid = Math.floor(messages.length / 2);
|
|
9072
|
-
const firstHalf = messages.slice(0, mid);
|
|
9073
|
-
const secondHalf = messages.slice(mid);
|
|
9074
|
-
for (const half of [firstHalf, secondHalf]) {
|
|
9075
|
-
const text = stringifyOrLog(half);
|
|
9076
|
-
if (!isTooBigForWebSocket(text)) {
|
|
9077
|
-
yield text;
|
|
9078
|
-
} else {
|
|
9079
|
-
yield* chunkMessages(half);
|
|
9080
|
-
}
|
|
9081
|
-
}
|
|
9082
|
-
}
|
|
9083
|
-
function isTooBigForWebSocket(text) {
|
|
9084
|
-
if (text.length * 4 < MAX_SOCKET_MESSAGE_SIZE) {
|
|
9085
|
-
return false;
|
|
9086
|
-
}
|
|
9087
|
-
return new TextEncoder().encode(text).length >= MAX_SOCKET_MESSAGE_SIZE;
|
|
9088
|
-
}
|
|
9089
9286
|
function sendMessages(messages) {
|
|
9090
|
-
|
|
9091
|
-
const text = stringifyOrLog(messages);
|
|
9092
|
-
if (!isTooBigForWebSocket(text)) {
|
|
9093
|
-
return managedSocket.send(text);
|
|
9094
|
-
}
|
|
9095
|
-
switch (strategy) {
|
|
9096
|
-
case "default": {
|
|
9097
|
-
const type = "LARGE_MESSAGE_ERROR";
|
|
9098
|
-
const err = new LiveblocksError("Message is too large for websockets", {
|
|
9099
|
-
type
|
|
9100
|
-
});
|
|
9101
|
-
const didNotify = config.errorEventSource.notify(err);
|
|
9102
|
-
if (!didNotify) {
|
|
9103
|
-
error2(
|
|
9104
|
-
"Message is too large for websockets. Configure largeMessageStrategy option or useErrorListener to handle this."
|
|
9105
|
-
);
|
|
9106
|
-
}
|
|
9107
|
-
return;
|
|
9108
|
-
}
|
|
9109
|
-
case "split": {
|
|
9110
|
-
warn("Message is too large for websockets, splitting into smaller chunks");
|
|
9111
|
-
for (const chunk2 of chunkMessages(messages)) {
|
|
9112
|
-
managedSocket.send(chunk2);
|
|
9113
|
-
}
|
|
9114
|
-
return;
|
|
9115
|
-
}
|
|
9116
|
-
// NOTE: This strategy is experimental as it will not work in all situations.
|
|
9117
|
-
// It should only be used for broadcasting, presence updates, but isn't suitable
|
|
9118
|
-
// for Storage or Yjs updates yet (because through this channel the server does
|
|
9119
|
-
// not respond with acks or rejections, causing the client's reported status to
|
|
9120
|
-
// be stuck in "synchronizing" forever).
|
|
9121
|
-
case "experimental-fallback-to-http": {
|
|
9122
|
-
warn("Message is too large for websockets, so sending over HTTP instead");
|
|
9123
|
-
const nonce = _nullishCoalesce(_optionalChain([context, 'access', _184 => _184.dynamicSessionInfoSig, 'access', _185 => _185.get, 'call', _186 => _186(), 'optionalAccess', _187 => _187.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
|
|
9124
|
-
void httpClient.sendMessagesOverHTTP({ roomId, nonce, messages }).then((resp) => {
|
|
9125
|
-
if (!resp.ok && resp.status === 403) {
|
|
9126
|
-
managedSocket.reconnect();
|
|
9127
|
-
}
|
|
9128
|
-
}).catch((err) => {
|
|
9129
|
-
error2(
|
|
9130
|
-
`Failed to deliver message over HTTP: ${String(err)}`
|
|
9131
|
-
);
|
|
9132
|
-
});
|
|
9133
|
-
return;
|
|
9134
|
-
}
|
|
9135
|
-
}
|
|
9287
|
+
managedSocket.send(stringifyOrLog(messages));
|
|
9136
9288
|
}
|
|
9137
9289
|
const self = DerivedSignal.from(
|
|
9138
9290
|
context.staticSessionInfoSig,
|
|
@@ -9166,16 +9318,25 @@ function createRoom(options, config) {
|
|
|
9166
9318
|
self,
|
|
9167
9319
|
(me) => me !== null ? userToTreeNode("Me", me) : null
|
|
9168
9320
|
);
|
|
9169
|
-
function createOrUpdateRootFromMessage(
|
|
9170
|
-
if (
|
|
9321
|
+
function createOrUpdateRootFromMessage(nodes) {
|
|
9322
|
+
if (nodes.size === 0) {
|
|
9171
9323
|
throw new Error("Internal error: cannot load storage without items");
|
|
9172
9324
|
}
|
|
9173
9325
|
if (context.root !== void 0) {
|
|
9174
|
-
|
|
9326
|
+
const currentItems = /* @__PURE__ */ new Map();
|
|
9327
|
+
for (const [id, crdt] of context.pool.nodes) {
|
|
9328
|
+
currentItems.set(id, crdt._serialize());
|
|
9329
|
+
}
|
|
9330
|
+
const ops = getTreesDiffOperations(currentItems, nodes);
|
|
9331
|
+
const result = applyRemoteOps(ops);
|
|
9332
|
+
notify(result.updates);
|
|
9175
9333
|
} else {
|
|
9176
|
-
context.root = LiveObject._fromItems(
|
|
9334
|
+
context.root = LiveObject._fromItems(
|
|
9335
|
+
nodes,
|
|
9336
|
+
context.pool
|
|
9337
|
+
);
|
|
9177
9338
|
}
|
|
9178
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
9339
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _210 => _210.get, 'call', _211 => _211(), 'optionalAccess', _212 => _212.canWrite]), () => ( true));
|
|
9179
9340
|
const stackSizeBefore = context.undoStack.length;
|
|
9180
9341
|
for (const key in context.initialStorage) {
|
|
9181
9342
|
if (context.root.get(key) === void 0) {
|
|
@@ -9190,21 +9351,6 @@ function createRoom(options, config) {
|
|
|
9190
9351
|
}
|
|
9191
9352
|
context.undoStack.length = stackSizeBefore;
|
|
9192
9353
|
}
|
|
9193
|
-
function updateRoot(items) {
|
|
9194
|
-
if (context.root === void 0) {
|
|
9195
|
-
return;
|
|
9196
|
-
}
|
|
9197
|
-
const currentItems = /* @__PURE__ */ new Map();
|
|
9198
|
-
for (const [id, crdt] of context.pool.nodes) {
|
|
9199
|
-
currentItems.set(id, crdt._serialize());
|
|
9200
|
-
}
|
|
9201
|
-
const ops = getTreesDiffOperations(
|
|
9202
|
-
currentItems,
|
|
9203
|
-
new Map(items)
|
|
9204
|
-
);
|
|
9205
|
-
const result = applyRemoteOps(ops);
|
|
9206
|
-
notify(result.updates);
|
|
9207
|
-
}
|
|
9208
9354
|
function _addToRealUndoStack(frames) {
|
|
9209
9355
|
if (context.undoStack.length >= 50) {
|
|
9210
9356
|
context.undoStack.shift();
|
|
@@ -9394,7 +9540,7 @@ function createRoom(options, config) {
|
|
|
9394
9540
|
}
|
|
9395
9541
|
context.myPresence.patch(patch);
|
|
9396
9542
|
if (context.activeBatch) {
|
|
9397
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
9543
|
+
if (_optionalChain([options2, 'optionalAccess', _213 => _213.addToHistory])) {
|
|
9398
9544
|
context.activeBatch.reverseOps.pushLeft({
|
|
9399
9545
|
type: "presence",
|
|
9400
9546
|
data: oldValues
|
|
@@ -9403,7 +9549,7 @@ function createRoom(options, config) {
|
|
|
9403
9549
|
context.activeBatch.updates.presence = true;
|
|
9404
9550
|
} else {
|
|
9405
9551
|
flushNowOrSoon();
|
|
9406
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
9552
|
+
if (_optionalChain([options2, 'optionalAccess', _214 => _214.addToHistory])) {
|
|
9407
9553
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
9408
9554
|
}
|
|
9409
9555
|
notify({ presence: true });
|
|
@@ -9576,8 +9722,26 @@ function createRoom(options, config) {
|
|
|
9576
9722
|
updates.others.push(onRoomStateMessage(message));
|
|
9577
9723
|
break;
|
|
9578
9724
|
}
|
|
9579
|
-
case ServerMsgCode.
|
|
9580
|
-
|
|
9725
|
+
case ServerMsgCode.STORAGE_CHUNK:
|
|
9726
|
+
_optionalChain([stopwatch, 'optionalAccess', _215 => _215.lap, 'call', _216 => _216()]);
|
|
9727
|
+
nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
|
|
9728
|
+
break;
|
|
9729
|
+
case ServerMsgCode.STORAGE_STREAM_END: {
|
|
9730
|
+
const timing = _optionalChain([stopwatch, 'optionalAccess', _217 => _217.stop, 'call', _218 => _218()]);
|
|
9731
|
+
if (timing) {
|
|
9732
|
+
const ms = (v) => `${v.toFixed(1)}ms`;
|
|
9733
|
+
const rest = timing.laps.slice(1);
|
|
9734
|
+
warn(
|
|
9735
|
+
`Storage chunk arrival: ${[
|
|
9736
|
+
`total=${ms(timing.total)}`,
|
|
9737
|
+
`first=${ms(timing.laps[0])}`,
|
|
9738
|
+
`rest.n=${rest.length}`,
|
|
9739
|
+
`rest.avg=${ms(rest.reduce((a, b) => a + b, 0) / rest.length)}`,
|
|
9740
|
+
`rest.max=${ms(rest.reduce((a, b) => Math.max(a, b), 0))}`
|
|
9741
|
+
].join(", ")}`
|
|
9742
|
+
);
|
|
9743
|
+
}
|
|
9744
|
+
processInitialStorage(nodeMapBuffer.take());
|
|
9581
9745
|
break;
|
|
9582
9746
|
}
|
|
9583
9747
|
case ServerMsgCode.UPDATE_STORAGE: {
|
|
@@ -9619,6 +9783,8 @@ function createRoom(options, config) {
|
|
|
9619
9783
|
eventHub.comments.notify(message);
|
|
9620
9784
|
break;
|
|
9621
9785
|
}
|
|
9786
|
+
case ServerMsgCode.STORAGE_STATE_V7:
|
|
9787
|
+
// No longer used in V8
|
|
9622
9788
|
default:
|
|
9623
9789
|
break;
|
|
9624
9790
|
}
|
|
@@ -9720,18 +9886,20 @@ function createRoom(options, config) {
|
|
|
9720
9886
|
}
|
|
9721
9887
|
let _getStorage$ = null;
|
|
9722
9888
|
let _resolveStoragePromise = null;
|
|
9723
|
-
function processInitialStorage(
|
|
9889
|
+
function processInitialStorage(nodes) {
|
|
9724
9890
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
9725
|
-
createOrUpdateRootFromMessage(
|
|
9891
|
+
createOrUpdateRootFromMessage(nodes);
|
|
9726
9892
|
applyAndSendOfflineOps(unacknowledgedOps);
|
|
9727
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
9893
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _219 => _219()]);
|
|
9728
9894
|
notifyStorageStatus();
|
|
9729
9895
|
eventHub.storageDidLoad.notify();
|
|
9730
9896
|
}
|
|
9731
9897
|
async function streamStorage() {
|
|
9732
9898
|
if (!managedSocket.authValue) return;
|
|
9733
|
-
const
|
|
9734
|
-
|
|
9899
|
+
const nodes = new Map(
|
|
9900
|
+
await httpClient.streamStorage({ roomId })
|
|
9901
|
+
);
|
|
9902
|
+
processInitialStorage(nodes);
|
|
9735
9903
|
}
|
|
9736
9904
|
function refreshStorage(options2) {
|
|
9737
9905
|
const messages = context.buffer.messages;
|
|
@@ -9739,6 +9907,8 @@ function createRoom(options, config) {
|
|
|
9739
9907
|
void streamStorage();
|
|
9740
9908
|
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
9741
9909
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
9910
|
+
nodeMapBuffer.take();
|
|
9911
|
+
_optionalChain([stopwatch, 'optionalAccess', _220 => _220.start, 'call', _221 => _221()]);
|
|
9742
9912
|
}
|
|
9743
9913
|
if (options2.flush) {
|
|
9744
9914
|
flushNowOrSoon();
|
|
@@ -9941,8 +10111,8 @@ function createRoom(options, config) {
|
|
|
9941
10111
|
async function getThreads(options2) {
|
|
9942
10112
|
return httpClient.getThreads({
|
|
9943
10113
|
roomId,
|
|
9944
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
9945
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10114
|
+
query: _optionalChain([options2, 'optionalAccess', _222 => _222.query]),
|
|
10115
|
+
cursor: _optionalChain([options2, 'optionalAccess', _223 => _223.cursor])
|
|
9946
10116
|
});
|
|
9947
10117
|
}
|
|
9948
10118
|
async function getThread(threadId) {
|
|
@@ -10064,7 +10234,7 @@ function createRoom(options, config) {
|
|
|
10064
10234
|
function getSubscriptionSettings(options2) {
|
|
10065
10235
|
return httpClient.getSubscriptionSettings({
|
|
10066
10236
|
roomId,
|
|
10067
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
10237
|
+
signal: _optionalChain([options2, 'optionalAccess', _224 => _224.signal])
|
|
10068
10238
|
});
|
|
10069
10239
|
}
|
|
10070
10240
|
function updateSubscriptionSettings(settings) {
|
|
@@ -10086,7 +10256,7 @@ function createRoom(options, config) {
|
|
|
10086
10256
|
{
|
|
10087
10257
|
[kInternal]: {
|
|
10088
10258
|
get presenceBuffer() {
|
|
10089
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
10259
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _225 => _225.buffer, 'access', _226 => _226.presenceUpdates, 'optionalAccess', _227 => _227.data]), () => ( null)));
|
|
10090
10260
|
},
|
|
10091
10261
|
// prettier-ignore
|
|
10092
10262
|
get undoStack() {
|
|
@@ -10101,9 +10271,9 @@ function createRoom(options, config) {
|
|
|
10101
10271
|
return context.yjsProvider;
|
|
10102
10272
|
},
|
|
10103
10273
|
setYjsProvider(newProvider) {
|
|
10104
|
-
_optionalChain([context, 'access',
|
|
10274
|
+
_optionalChain([context, 'access', _228 => _228.yjsProvider, 'optionalAccess', _229 => _229.off, 'call', _230 => _230("status", yjsStatusDidChange)]);
|
|
10105
10275
|
context.yjsProvider = newProvider;
|
|
10106
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
10276
|
+
_optionalChain([newProvider, 'optionalAccess', _231 => _231.on, 'call', _232 => _232("status", yjsStatusDidChange)]);
|
|
10107
10277
|
context.yjsProviderDidChange.notify();
|
|
10108
10278
|
},
|
|
10109
10279
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -10149,7 +10319,7 @@ function createRoom(options, config) {
|
|
|
10149
10319
|
source.dispose();
|
|
10150
10320
|
}
|
|
10151
10321
|
eventHub.roomWillDestroy.notify();
|
|
10152
|
-
_optionalChain([context, 'access',
|
|
10322
|
+
_optionalChain([context, 'access', _233 => _233.yjsProvider, 'optionalAccess', _234 => _234.off, 'call', _235 => _235("status", yjsStatusDidChange)]);
|
|
10153
10323
|
syncSourceForStorage.destroy();
|
|
10154
10324
|
syncSourceForYjs.destroy();
|
|
10155
10325
|
uninstallBgTabSpy();
|
|
@@ -10300,7 +10470,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
10300
10470
|
}
|
|
10301
10471
|
if (isLiveNode(first)) {
|
|
10302
10472
|
const node = first;
|
|
10303
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
10473
|
+
if (_optionalChain([options, 'optionalAccess', _236 => _236.isDeep])) {
|
|
10304
10474
|
const storageCallback = second;
|
|
10305
10475
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
10306
10476
|
} else {
|
|
@@ -10332,7 +10502,7 @@ function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill, eng
|
|
|
10332
10502
|
}
|
|
10333
10503
|
const url2 = new URL(baseUrl);
|
|
10334
10504
|
url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
|
|
10335
|
-
url2.pathname = "/
|
|
10505
|
+
url2.pathname = "/v8";
|
|
10336
10506
|
url2.searchParams.set("roomId", roomId);
|
|
10337
10507
|
if (authValue.type === "secret") {
|
|
10338
10508
|
url2.searchParams.set("tok", authValue.token.raw);
|
|
@@ -10382,8 +10552,8 @@ function createClient(options) {
|
|
|
10382
10552
|
const authManager = createAuthManager(options, (token) => {
|
|
10383
10553
|
currentUserId.set(() => token.uid);
|
|
10384
10554
|
});
|
|
10385
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
10386
|
-
_optionalChain([globalThis, 'access',
|
|
10555
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _237 => _237.polyfills, 'optionalAccess', _238 => _238.fetch]) || /* istanbul ignore next */
|
|
10556
|
+
_optionalChain([globalThis, 'access', _239 => _239.fetch, 'optionalAccess', _240 => _240.bind, 'call', _241 => _241(globalThis)]);
|
|
10387
10557
|
const httpClient = createApiClient({
|
|
10388
10558
|
baseUrl,
|
|
10389
10559
|
fetchPolyfill,
|
|
@@ -10401,7 +10571,7 @@ function createClient(options) {
|
|
|
10401
10571
|
delegates: {
|
|
10402
10572
|
createSocket: makeCreateSocketDelegateForAi(
|
|
10403
10573
|
baseUrl,
|
|
10404
|
-
_optionalChain([clientOptions, 'access',
|
|
10574
|
+
_optionalChain([clientOptions, 'access', _242 => _242.polyfills, 'optionalAccess', _243 => _243.WebSocket])
|
|
10405
10575
|
),
|
|
10406
10576
|
authenticate: async () => {
|
|
10407
10577
|
const resp = await authManager.getAuthValue({
|
|
@@ -10461,7 +10631,7 @@ function createClient(options) {
|
|
|
10461
10631
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
10462
10632
|
roomId,
|
|
10463
10633
|
baseUrl,
|
|
10464
|
-
_optionalChain([clientOptions, 'access',
|
|
10634
|
+
_optionalChain([clientOptions, 'access', _244 => _244.polyfills, 'optionalAccess', _245 => _245.WebSocket]),
|
|
10465
10635
|
options2.engine
|
|
10466
10636
|
),
|
|
10467
10637
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
@@ -10469,7 +10639,6 @@ function createClient(options) {
|
|
|
10469
10639
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
10470
10640
|
baseUrl,
|
|
10471
10641
|
errorEventSource: liveblocksErrorSource,
|
|
10472
|
-
largeMessageStrategy: clientOptions.largeMessageStrategy,
|
|
10473
10642
|
unstable_streamData: !!clientOptions.unstable_streamData,
|
|
10474
10643
|
roomHttpClient: httpClient,
|
|
10475
10644
|
createSyncSource,
|
|
@@ -10486,7 +10655,7 @@ function createClient(options) {
|
|
|
10486
10655
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
10487
10656
|
if (shouldConnect) {
|
|
10488
10657
|
if (typeof atob === "undefined") {
|
|
10489
|
-
if (_optionalChain([clientOptions, 'access',
|
|
10658
|
+
if (_optionalChain([clientOptions, 'access', _246 => _246.polyfills, 'optionalAccess', _247 => _247.atob]) === void 0) {
|
|
10490
10659
|
throw new Error(
|
|
10491
10660
|
"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"
|
|
10492
10661
|
);
|
|
@@ -10498,7 +10667,7 @@ function createClient(options) {
|
|
|
10498
10667
|
return leaseRoom(newRoomDetails);
|
|
10499
10668
|
}
|
|
10500
10669
|
function getRoom(roomId) {
|
|
10501
|
-
const room = _optionalChain([roomsById, 'access',
|
|
10670
|
+
const room = _optionalChain([roomsById, 'access', _248 => _248.get, 'call', _249 => _249(roomId), 'optionalAccess', _250 => _250.room]);
|
|
10502
10671
|
return room ? room : null;
|
|
10503
10672
|
}
|
|
10504
10673
|
function logout() {
|
|
@@ -10514,7 +10683,7 @@ function createClient(options) {
|
|
|
10514
10683
|
const batchedResolveUsers = new Batch(
|
|
10515
10684
|
async (batchedUserIds) => {
|
|
10516
10685
|
const userIds = batchedUserIds.flat();
|
|
10517
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
10686
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _251 => _251({ userIds })]);
|
|
10518
10687
|
warnOnceIf(
|
|
10519
10688
|
!resolveUsers,
|
|
10520
10689
|
"Set the resolveUsers option in createClient to specify user info."
|
|
@@ -10531,7 +10700,7 @@ function createClient(options) {
|
|
|
10531
10700
|
const batchedResolveRoomsInfo = new Batch(
|
|
10532
10701
|
async (batchedRoomIds) => {
|
|
10533
10702
|
const roomIds = batchedRoomIds.flat();
|
|
10534
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
10703
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _252 => _252({ roomIds })]);
|
|
10535
10704
|
warnOnceIf(
|
|
10536
10705
|
!resolveRoomsInfo,
|
|
10537
10706
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
@@ -10548,7 +10717,7 @@ function createClient(options) {
|
|
|
10548
10717
|
const batchedResolveGroupsInfo = new Batch(
|
|
10549
10718
|
async (batchedGroupIds) => {
|
|
10550
10719
|
const groupIds = batchedGroupIds.flat();
|
|
10551
|
-
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall',
|
|
10720
|
+
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _253 => _253({ groupIds })]);
|
|
10552
10721
|
warnOnceIf(
|
|
10553
10722
|
!resolveGroupsInfo,
|
|
10554
10723
|
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
@@ -10604,7 +10773,7 @@ function createClient(options) {
|
|
|
10604
10773
|
}
|
|
10605
10774
|
};
|
|
10606
10775
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
10607
|
-
_optionalChain([win, 'optionalAccess',
|
|
10776
|
+
_optionalChain([win, 'optionalAccess', _254 => _254.addEventListener, 'call', _255 => _255("beforeunload", maybePreventClose)]);
|
|
10608
10777
|
}
|
|
10609
10778
|
async function getNotificationSettings(options2) {
|
|
10610
10779
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -10731,7 +10900,7 @@ var commentBodyElementsTypes = {
|
|
|
10731
10900
|
mention: "inline"
|
|
10732
10901
|
};
|
|
10733
10902
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
10734
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
10903
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _256 => _256.content])) {
|
|
10735
10904
|
return;
|
|
10736
10905
|
}
|
|
10737
10906
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -10741,13 +10910,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
10741
10910
|
for (const block of body.content) {
|
|
10742
10911
|
if (type === "all" || type === "block") {
|
|
10743
10912
|
if (guard(block)) {
|
|
10744
|
-
_optionalChain([visitor, 'optionalCall',
|
|
10913
|
+
_optionalChain([visitor, 'optionalCall', _257 => _257(block)]);
|
|
10745
10914
|
}
|
|
10746
10915
|
}
|
|
10747
10916
|
if (type === "all" || type === "inline") {
|
|
10748
10917
|
for (const inline of block.children) {
|
|
10749
10918
|
if (guard(inline)) {
|
|
10750
|
-
_optionalChain([visitor, 'optionalCall',
|
|
10919
|
+
_optionalChain([visitor, 'optionalCall', _258 => _258(inline)]);
|
|
10751
10920
|
}
|
|
10752
10921
|
}
|
|
10753
10922
|
}
|
|
@@ -10917,7 +11086,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
10917
11086
|
text: ({ element }) => element.text,
|
|
10918
11087
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
10919
11088
|
mention: ({ element, user, group }) => {
|
|
10920
|
-
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
11089
|
+
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _259 => _259.name]), () => ( _optionalChain([group, 'optionalAccess', _260 => _260.name]))), () => ( element.id))}`;
|
|
10921
11090
|
}
|
|
10922
11091
|
};
|
|
10923
11092
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -10947,7 +11116,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
10947
11116
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
10948
11117
|
},
|
|
10949
11118
|
mention: ({ element, user, group }) => {
|
|
10950
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
11119
|
+
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _261 => _261.name]) ? html`${_optionalChain([user, 'optionalAccess', _262 => _262.name])}` : _optionalChain([group, 'optionalAccess', _263 => _263.name]) ? html`${_optionalChain([group, 'optionalAccess', _264 => _264.name])}` : element.id}</span>`;
|
|
10951
11120
|
}
|
|
10952
11121
|
};
|
|
10953
11122
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -10977,20 +11146,20 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
10977
11146
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
10978
11147
|
},
|
|
10979
11148
|
mention: ({ element, user, group }) => {
|
|
10980
|
-
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
11149
|
+
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _265 => _265.name]), () => ( _optionalChain([group, 'optionalAccess', _266 => _266.name]))), () => ( element.id))}`;
|
|
10981
11150
|
}
|
|
10982
11151
|
};
|
|
10983
11152
|
async function stringifyCommentBody(body, options) {
|
|
10984
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
10985
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
11153
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _267 => _267.format]), () => ( "plain"));
|
|
11154
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _268 => _268.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
10986
11155
|
const elements = {
|
|
10987
11156
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
10988
|
-
..._optionalChain([options, 'optionalAccess',
|
|
11157
|
+
..._optionalChain([options, 'optionalAccess', _269 => _269.elements])
|
|
10989
11158
|
};
|
|
10990
11159
|
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
10991
11160
|
body,
|
|
10992
|
-
_optionalChain([options, 'optionalAccess',
|
|
10993
|
-
_optionalChain([options, 'optionalAccess',
|
|
11161
|
+
_optionalChain([options, 'optionalAccess', _270 => _270.resolveUsers]),
|
|
11162
|
+
_optionalChain([options, 'optionalAccess', _271 => _271.resolveGroupsInfo])
|
|
10994
11163
|
);
|
|
10995
11164
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
10996
11165
|
switch (block.type) {
|
|
@@ -11277,12 +11446,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
11277
11446
|
}
|
|
11278
11447
|
const newState = Object.assign({}, state);
|
|
11279
11448
|
for (const key in update.updates) {
|
|
11280
|
-
if (_optionalChain([update, 'access',
|
|
11449
|
+
if (_optionalChain([update, 'access', _272 => _272.updates, 'access', _273 => _273[key], 'optionalAccess', _274 => _274.type]) === "update") {
|
|
11281
11450
|
const val = update.node.get(key);
|
|
11282
11451
|
if (val !== void 0) {
|
|
11283
11452
|
newState[key] = lsonToJson(val);
|
|
11284
11453
|
}
|
|
11285
|
-
} else if (_optionalChain([update, 'access',
|
|
11454
|
+
} else if (_optionalChain([update, 'access', _275 => _275.updates, 'access', _276 => _276[key], 'optionalAccess', _277 => _277.type]) === "delete") {
|
|
11286
11455
|
delete newState[key];
|
|
11287
11456
|
}
|
|
11288
11457
|
}
|
|
@@ -11343,12 +11512,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
11343
11512
|
}
|
|
11344
11513
|
const newState = Object.assign({}, state);
|
|
11345
11514
|
for (const key in update.updates) {
|
|
11346
|
-
if (_optionalChain([update, 'access',
|
|
11515
|
+
if (_optionalChain([update, 'access', _278 => _278.updates, 'access', _279 => _279[key], 'optionalAccess', _280 => _280.type]) === "update") {
|
|
11347
11516
|
const value = update.node.get(key);
|
|
11348
11517
|
if (value !== void 0) {
|
|
11349
11518
|
newState[key] = lsonToJson(value);
|
|
11350
11519
|
}
|
|
11351
|
-
} else if (_optionalChain([update, 'access',
|
|
11520
|
+
} else if (_optionalChain([update, 'access', _281 => _281.updates, 'access', _282 => _282[key], 'optionalAccess', _283 => _283.type]) === "delete") {
|
|
11352
11521
|
delete newState[key];
|
|
11353
11522
|
}
|
|
11354
11523
|
}
|
|
@@ -11428,9 +11597,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
11428
11597
|
const startTime = performance.now();
|
|
11429
11598
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
11430
11599
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
11431
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
11600
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _284 => _284.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
11432
11601
|
const context = {
|
|
11433
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
11602
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _285 => _285.visibilityState]) !== "hidden",
|
|
11434
11603
|
lastSuccessfulPollAt: startTime,
|
|
11435
11604
|
count: 0,
|
|
11436
11605
|
backoff: 0
|
|
@@ -11511,11 +11680,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
11511
11680
|
pollNowIfStale();
|
|
11512
11681
|
}
|
|
11513
11682
|
function onVisibilityChange() {
|
|
11514
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
11683
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _286 => _286.visibilityState]) !== "hidden");
|
|
11515
11684
|
}
|
|
11516
|
-
_optionalChain([doc, 'optionalAccess',
|
|
11517
|
-
_optionalChain([win, 'optionalAccess',
|
|
11518
|
-
_optionalChain([win, 'optionalAccess',
|
|
11685
|
+
_optionalChain([doc, 'optionalAccess', _287 => _287.addEventListener, 'call', _288 => _288("visibilitychange", onVisibilityChange)]);
|
|
11686
|
+
_optionalChain([win, 'optionalAccess', _289 => _289.addEventListener, 'call', _290 => _290("online", onVisibilityChange)]);
|
|
11687
|
+
_optionalChain([win, 'optionalAccess', _291 => _291.addEventListener, 'call', _292 => _292("focus", pollNowIfStale)]);
|
|
11519
11688
|
fsm.start();
|
|
11520
11689
|
return {
|
|
11521
11690
|
inc,
|
|
@@ -11652,5 +11821,7 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
11652
11821
|
|
|
11653
11822
|
|
|
11654
11823
|
|
|
11655
|
-
|
|
11824
|
+
|
|
11825
|
+
|
|
11826
|
+
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.MENTION_CHARACTER = MENTION_CHARACTER; 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.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.compactNodesToNodeStream = compactNodesToNodeStream; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToGroupData = convertToGroupData; 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.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isListStorageNode = isListStorageNode; exports.isLiveNode = isLiveNode; exports.isMapStorageNode = isMapStorageNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isObjectStorageNode = isObjectStorageNode; exports.isPlainObject = isPlainObject; exports.isRegisterStorageNode = isRegisterStorageNode; exports.isRootStorageNode = isRootStorageNode; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; 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.nodeStreamToCompactNodes = nodeStreamToCompactNodes; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveMentionsInCommentBody = resolveMentionsInCommentBody; 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.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
|
|
11656
11827
|
//# sourceMappingURL=index.cjs.map
|