@liveblocks/core 3.6.2 → 3.7.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 +324 -204
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -14
- package/dist/index.d.ts +135 -14
- package/dist/index.js +201 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.
|
|
9
|
+
var PKG_VERSION = "3.7.0";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -851,6 +851,38 @@ function convertToSubscriptionDeleteInfo(data) {
|
|
|
851
851
|
deletedAt
|
|
852
852
|
};
|
|
853
853
|
}
|
|
854
|
+
function convertToGroupData(data) {
|
|
855
|
+
const createdAt = new Date(data.createdAt);
|
|
856
|
+
const updatedAt = new Date(data.updatedAt);
|
|
857
|
+
const members = data.members.map((member) => ({
|
|
858
|
+
...member,
|
|
859
|
+
addedAt: new Date(member.addedAt)
|
|
860
|
+
}));
|
|
861
|
+
return {
|
|
862
|
+
...data,
|
|
863
|
+
createdAt,
|
|
864
|
+
updatedAt,
|
|
865
|
+
members
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// src/lib/assert.ts
|
|
870
|
+
function assertNever(_value, errmsg) {
|
|
871
|
+
throw new Error(errmsg);
|
|
872
|
+
}
|
|
873
|
+
function assert(condition, errmsg) {
|
|
874
|
+
if (process.env.NODE_ENV !== "production") {
|
|
875
|
+
if (!condition) {
|
|
876
|
+
const err = new Error(errmsg);
|
|
877
|
+
err.name = "Assertion failure";
|
|
878
|
+
throw err;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function nn(value, errmsg = "Expected value to be non-nullable") {
|
|
883
|
+
assert(value !== null && value !== void 0, errmsg);
|
|
884
|
+
return value;
|
|
885
|
+
}
|
|
854
886
|
|
|
855
887
|
// src/lib/fancy-console.ts
|
|
856
888
|
var fancy_console_exports = {};
|
|
@@ -1095,9 +1127,15 @@ function createBatchStore(batch2) {
|
|
|
1095
1127
|
function getCacheKey(args) {
|
|
1096
1128
|
return stableStringify(args);
|
|
1097
1129
|
}
|
|
1098
|
-
function update(
|
|
1130
|
+
function update(entryOrEntries) {
|
|
1099
1131
|
signal.mutate((cache) => {
|
|
1100
|
-
|
|
1132
|
+
if (Array.isArray(entryOrEntries)) {
|
|
1133
|
+
for (const entry of entryOrEntries) {
|
|
1134
|
+
cache.set(entry.key, entry.state);
|
|
1135
|
+
}
|
|
1136
|
+
} else {
|
|
1137
|
+
cache.set(entryOrEntries.key, entryOrEntries.state);
|
|
1138
|
+
}
|
|
1101
1139
|
});
|
|
1102
1140
|
}
|
|
1103
1141
|
function invalidate(inputs) {
|
|
@@ -1118,21 +1156,34 @@ function createBatchStore(batch2) {
|
|
|
1118
1156
|
return;
|
|
1119
1157
|
}
|
|
1120
1158
|
try {
|
|
1121
|
-
update(cacheKey, { isLoading: true });
|
|
1159
|
+
update({ key: cacheKey, state: { isLoading: true } });
|
|
1122
1160
|
const result = await batch2.get(input);
|
|
1123
|
-
update(cacheKey, { isLoading: false, data: result });
|
|
1161
|
+
update({ key: cacheKey, state: { isLoading: false, data: result } });
|
|
1124
1162
|
} catch (error3) {
|
|
1125
|
-
update(
|
|
1126
|
-
|
|
1127
|
-
error: error3
|
|
1163
|
+
update({
|
|
1164
|
+
key: cacheKey,
|
|
1165
|
+
state: { isLoading: false, error: error3 }
|
|
1128
1166
|
});
|
|
1129
1167
|
}
|
|
1130
1168
|
}
|
|
1169
|
+
function setData(entries2) {
|
|
1170
|
+
update(
|
|
1171
|
+
entries2.map((entry) => ({
|
|
1172
|
+
key: getCacheKey(entry[0]),
|
|
1173
|
+
state: { isLoading: false, data: entry[1] }
|
|
1174
|
+
}))
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1131
1177
|
function getItemState(input) {
|
|
1132
1178
|
const cacheKey = getCacheKey(input);
|
|
1133
1179
|
const cache = signal.get();
|
|
1134
1180
|
return cache.get(cacheKey);
|
|
1135
1181
|
}
|
|
1182
|
+
function getData(input) {
|
|
1183
|
+
const cacheKey = getCacheKey(input);
|
|
1184
|
+
const cache = signal.get();
|
|
1185
|
+
return cache.get(cacheKey)?.data;
|
|
1186
|
+
}
|
|
1136
1187
|
function _cacheKeys() {
|
|
1137
1188
|
const cache = signal.get();
|
|
1138
1189
|
return [...cache.keys()];
|
|
@@ -1140,7 +1191,9 @@ function createBatchStore(batch2) {
|
|
|
1140
1191
|
return {
|
|
1141
1192
|
subscribe: signal.subscribe,
|
|
1142
1193
|
enqueue,
|
|
1194
|
+
setData,
|
|
1143
1195
|
getItemState,
|
|
1196
|
+
getData,
|
|
1144
1197
|
invalidate,
|
|
1145
1198
|
batch: batch2,
|
|
1146
1199
|
_cacheKeys
|
|
@@ -1962,6 +2015,9 @@ function createApiClient({
|
|
|
1962
2015
|
return batch2.get(options.inboxNotificationId);
|
|
1963
2016
|
}
|
|
1964
2017
|
async function createTextMention(options) {
|
|
2018
|
+
if (options.mention.kind !== "user" && options.mention.kind !== "group") {
|
|
2019
|
+
return assertNever(options.mention, "Unexpected mention kind");
|
|
2020
|
+
}
|
|
1965
2021
|
await httpClient.rawPost(
|
|
1966
2022
|
url`/v2/c/rooms/${options.roomId}/text-mentions`,
|
|
1967
2023
|
await authManager.getAuthValue({
|
|
@@ -1969,7 +2025,9 @@ function createApiClient({
|
|
|
1969
2025
|
roomId: options.roomId
|
|
1970
2026
|
}),
|
|
1971
2027
|
{
|
|
1972
|
-
userId: options.
|
|
2028
|
+
userId: options.mention.kind === "user" ? options.mention.id : void 0,
|
|
2029
|
+
groupId: options.mention.kind === "group" ? options.mention.id : void 0,
|
|
2030
|
+
userIds: options.mention.kind === "group" ? options.mention.userIds : void 0,
|
|
1973
2031
|
mentionId: options.mentionId
|
|
1974
2032
|
}
|
|
1975
2033
|
);
|
|
@@ -2100,14 +2158,21 @@ function createApiClient({
|
|
|
2100
2158
|
}
|
|
2101
2159
|
async function getInboxNotifications(options) {
|
|
2102
2160
|
const PAGE_SIZE = 50;
|
|
2161
|
+
let query;
|
|
2162
|
+
if (options?.query) {
|
|
2163
|
+
query = objectToQuery(options.query);
|
|
2164
|
+
}
|
|
2103
2165
|
const json = await httpClient.get(
|
|
2104
2166
|
url`/v2/c/inbox-notifications`,
|
|
2105
2167
|
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
2106
2168
|
{
|
|
2107
2169
|
cursor: options?.cursor,
|
|
2108
|
-
limit: PAGE_SIZE
|
|
2170
|
+
limit: PAGE_SIZE,
|
|
2171
|
+
query
|
|
2109
2172
|
}
|
|
2110
2173
|
);
|
|
2174
|
+
const groups = json.groups.map(convertToGroupData);
|
|
2175
|
+
groupsStore.setData(groups.map((group) => [group.id, group]));
|
|
2111
2176
|
return {
|
|
2112
2177
|
inboxNotifications: json.inboxNotifications.map(
|
|
2113
2178
|
convertToInboxNotificationData
|
|
@@ -2119,10 +2184,14 @@ function createApiClient({
|
|
|
2119
2184
|
};
|
|
2120
2185
|
}
|
|
2121
2186
|
async function getInboxNotificationsSince(options) {
|
|
2187
|
+
let query;
|
|
2188
|
+
if (options?.query) {
|
|
2189
|
+
query = objectToQuery(options.query);
|
|
2190
|
+
}
|
|
2122
2191
|
const json = await httpClient.get(
|
|
2123
2192
|
url`/v2/c/inbox-notifications/delta`,
|
|
2124
2193
|
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
2125
|
-
{ since: options.since.toISOString() },
|
|
2194
|
+
{ since: options.since.toISOString(), query },
|
|
2126
2195
|
{ signal: options.signal }
|
|
2127
2196
|
);
|
|
2128
2197
|
return {
|
|
@@ -2258,6 +2327,28 @@ function createApiClient({
|
|
|
2258
2327
|
permissionHints: json.meta.permissionHints
|
|
2259
2328
|
};
|
|
2260
2329
|
}
|
|
2330
|
+
const batchedGetGroups = new Batch(
|
|
2331
|
+
async (batchedGroupIds) => {
|
|
2332
|
+
const groupIds = batchedGroupIds.flat();
|
|
2333
|
+
const { groups: plainGroups } = await httpClient.post(
|
|
2334
|
+
url`/v2/c/groups/find`,
|
|
2335
|
+
await authManager.getAuthValue({
|
|
2336
|
+
requestedScope: "comments:read"
|
|
2337
|
+
}),
|
|
2338
|
+
{ groupIds }
|
|
2339
|
+
);
|
|
2340
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2341
|
+
for (const group of plainGroups) {
|
|
2342
|
+
groups.set(group.id, convertToGroupData(group));
|
|
2343
|
+
}
|
|
2344
|
+
return groupIds.map((groupId) => groups.get(groupId));
|
|
2345
|
+
},
|
|
2346
|
+
{ delay: 50 }
|
|
2347
|
+
);
|
|
2348
|
+
const groupsStore = createBatchStore(batchedGetGroups);
|
|
2349
|
+
function getGroup(groupId) {
|
|
2350
|
+
return batchedGetGroups.get(groupId);
|
|
2351
|
+
}
|
|
2261
2352
|
return {
|
|
2262
2353
|
// Room threads
|
|
2263
2354
|
getThreads,
|
|
@@ -2311,6 +2402,9 @@ function createApiClient({
|
|
|
2311
2402
|
// User threads
|
|
2312
2403
|
getUserThreads_experimental,
|
|
2313
2404
|
getUserThreadsSince_experimental,
|
|
2405
|
+
// Groups
|
|
2406
|
+
groupsStore,
|
|
2407
|
+
getGroup,
|
|
2314
2408
|
// AI
|
|
2315
2409
|
executeContextualPrompt
|
|
2316
2410
|
};
|
|
@@ -2468,24 +2562,6 @@ var HttpClient = class {
|
|
|
2468
2562
|
}
|
|
2469
2563
|
};
|
|
2470
2564
|
|
|
2471
|
-
// src/lib/assert.ts
|
|
2472
|
-
function assertNever(_value, errmsg) {
|
|
2473
|
-
throw new Error(errmsg);
|
|
2474
|
-
}
|
|
2475
|
-
function assert(condition, errmsg) {
|
|
2476
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2477
|
-
if (!condition) {
|
|
2478
|
-
const err = new Error(errmsg);
|
|
2479
|
-
err.name = "Assertion failure";
|
|
2480
|
-
throw err;
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
function nn(value, errmsg = "Expected value to be non-nullable") {
|
|
2485
|
-
assert(value !== null && value !== void 0, errmsg);
|
|
2486
|
-
return value;
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
2565
|
// src/lib/fsm.ts
|
|
2490
2566
|
function distance(state1, state2) {
|
|
2491
2567
|
if (state1 === state2) {
|
|
@@ -4025,7 +4101,7 @@ function patchContentWithDelta(content, delta) {
|
|
|
4025
4101
|
closePart(lastPart, now2);
|
|
4026
4102
|
content.push({
|
|
4027
4103
|
type: "reasoning",
|
|
4028
|
-
text: delta.textDelta
|
|
4104
|
+
text: delta.textDelta,
|
|
4029
4105
|
startedAt: now2
|
|
4030
4106
|
});
|
|
4031
4107
|
}
|
|
@@ -5121,6 +5197,7 @@ async function fetchAuthEndpoint(fetch, endpoint, body) {
|
|
|
5121
5197
|
|
|
5122
5198
|
// src/constants.ts
|
|
5123
5199
|
var DEFAULT_BASE_URL = "https://api.liveblocks.io";
|
|
5200
|
+
var MENTION_CHARACTER = "@";
|
|
5124
5201
|
|
|
5125
5202
|
// src/devtools/bridge.ts
|
|
5126
5203
|
var _bridgeActive = false;
|
|
@@ -5340,6 +5417,22 @@ function unlinkDevTools(roomId) {
|
|
|
5340
5417
|
});
|
|
5341
5418
|
}
|
|
5342
5419
|
|
|
5420
|
+
// src/lib/warnings.ts
|
|
5421
|
+
var _emittedWarnings = /* @__PURE__ */ new Set();
|
|
5422
|
+
function warnOnce(message, key = message) {
|
|
5423
|
+
if (process.env.NODE_ENV !== "production") {
|
|
5424
|
+
if (!_emittedWarnings.has(key)) {
|
|
5425
|
+
_emittedWarnings.add(key);
|
|
5426
|
+
warn(message);
|
|
5427
|
+
}
|
|
5428
|
+
}
|
|
5429
|
+
}
|
|
5430
|
+
function warnOnceIf(condition, message, key = message) {
|
|
5431
|
+
if (typeof condition === "function" ? condition() : condition) {
|
|
5432
|
+
warnOnce(message, key);
|
|
5433
|
+
}
|
|
5434
|
+
}
|
|
5435
|
+
|
|
5343
5436
|
// src/protocol/NotificationSettings.ts
|
|
5344
5437
|
var kPlain = Symbol("notification-settings-plain");
|
|
5345
5438
|
function createNotificationSettings(plain) {
|
|
@@ -8555,8 +8648,8 @@ function createRoom(options, config) {
|
|
|
8555
8648
|
comments: makeEventSource(),
|
|
8556
8649
|
roomWillDestroy: makeEventSource()
|
|
8557
8650
|
};
|
|
8558
|
-
async function createTextMention(
|
|
8559
|
-
return httpClient.createTextMention({ roomId,
|
|
8651
|
+
async function createTextMention(mentionId, mention) {
|
|
8652
|
+
return httpClient.createTextMention({ roomId, mentionId, mention });
|
|
8560
8653
|
}
|
|
8561
8654
|
async function deleteTextMention(mentionId) {
|
|
8562
8655
|
return httpClient.deleteTextMention({ roomId, mentionId });
|
|
@@ -9877,6 +9970,7 @@ var MAX_LOST_CONNECTION_TIMEOUT = 3e4;
|
|
|
9877
9970
|
var DEFAULT_LOST_CONNECTION_TIMEOUT = 5e3;
|
|
9878
9971
|
var RESOLVE_USERS_BATCH_DELAY = 50;
|
|
9879
9972
|
var RESOLVE_ROOMS_INFO_BATCH_DELAY = 50;
|
|
9973
|
+
var RESOLVE_GROUPS_INFO_BATCH_DELAY = 50;
|
|
9880
9974
|
function getBaseUrl(baseUrl) {
|
|
9881
9975
|
if (typeof baseUrl === "string" && baseUrl.startsWith("http")) {
|
|
9882
9976
|
return baseUrl;
|
|
@@ -10034,15 +10128,14 @@ function createClient(options) {
|
|
|
10034
10128
|
}
|
|
10035
10129
|
}
|
|
10036
10130
|
const resolveUsers = clientOptions.resolveUsers;
|
|
10037
|
-
const warnIfNoResolveUsers = createDevelopmentWarning(
|
|
10038
|
-
() => !resolveUsers,
|
|
10039
|
-
"Set the resolveUsers option in createClient to specify user info."
|
|
10040
|
-
);
|
|
10041
10131
|
const batchedResolveUsers = new Batch(
|
|
10042
10132
|
async (batchedUserIds) => {
|
|
10043
10133
|
const userIds = batchedUserIds.flat();
|
|
10044
10134
|
const users = await resolveUsers?.({ userIds });
|
|
10045
|
-
|
|
10135
|
+
warnOnceIf(
|
|
10136
|
+
!resolveUsers,
|
|
10137
|
+
"Set the resolveUsers option in createClient to specify user info."
|
|
10138
|
+
);
|
|
10046
10139
|
return users ?? userIds.map(() => void 0);
|
|
10047
10140
|
},
|
|
10048
10141
|
{ delay: RESOLVE_USERS_BATCH_DELAY }
|
|
@@ -10052,15 +10145,14 @@ function createClient(options) {
|
|
|
10052
10145
|
usersStore.invalidate(userIds);
|
|
10053
10146
|
}
|
|
10054
10147
|
const resolveRoomsInfo = clientOptions.resolveRoomsInfo;
|
|
10055
|
-
const warnIfNoResolveRoomsInfo = createDevelopmentWarning(
|
|
10056
|
-
() => !resolveRoomsInfo,
|
|
10057
|
-
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
10058
|
-
);
|
|
10059
10148
|
const batchedResolveRoomsInfo = new Batch(
|
|
10060
10149
|
async (batchedRoomIds) => {
|
|
10061
10150
|
const roomIds = batchedRoomIds.flat();
|
|
10062
10151
|
const roomsInfo = await resolveRoomsInfo?.({ roomIds });
|
|
10063
|
-
|
|
10152
|
+
warnOnceIf(
|
|
10153
|
+
!resolveRoomsInfo,
|
|
10154
|
+
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
10155
|
+
);
|
|
10064
10156
|
return roomsInfo ?? roomIds.map(() => void 0);
|
|
10065
10157
|
},
|
|
10066
10158
|
{ delay: RESOLVE_ROOMS_INFO_BATCH_DELAY }
|
|
@@ -10069,6 +10161,23 @@ function createClient(options) {
|
|
|
10069
10161
|
function invalidateResolvedRoomsInfo(roomIds) {
|
|
10070
10162
|
roomsInfoStore.invalidate(roomIds);
|
|
10071
10163
|
}
|
|
10164
|
+
const resolveGroupsInfo = clientOptions.resolveGroupsInfo;
|
|
10165
|
+
const batchedResolveGroupsInfo = new Batch(
|
|
10166
|
+
async (batchedGroupIds) => {
|
|
10167
|
+
const groupIds = batchedGroupIds.flat();
|
|
10168
|
+
const groupsInfo = await resolveGroupsInfo?.({ groupIds });
|
|
10169
|
+
warnOnceIf(
|
|
10170
|
+
!resolveGroupsInfo,
|
|
10171
|
+
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
10172
|
+
);
|
|
10173
|
+
return groupsInfo ?? groupIds.map(() => void 0);
|
|
10174
|
+
},
|
|
10175
|
+
{ delay: RESOLVE_GROUPS_INFO_BATCH_DELAY }
|
|
10176
|
+
);
|
|
10177
|
+
const groupsInfoStore = createBatchStore(batchedResolveGroupsInfo);
|
|
10178
|
+
function invalidateResolvedGroupsInfo(groupIds) {
|
|
10179
|
+
groupsInfoStore.invalidate(groupIds);
|
|
10180
|
+
}
|
|
10072
10181
|
const mentionSuggestionsCache = /* @__PURE__ */ new Map();
|
|
10073
10182
|
function invalidateResolvedMentionSuggestions() {
|
|
10074
10183
|
mentionSuggestionsCache.clear();
|
|
@@ -10144,6 +10253,7 @@ function createClient(options) {
|
|
|
10144
10253
|
resolvers: {
|
|
10145
10254
|
invalidateUsers: invalidateResolvedUsers,
|
|
10146
10255
|
invalidateRoomsInfo: invalidateResolvedRoomsInfo,
|
|
10256
|
+
invalidateGroupsInfo: invalidateResolvedGroupsInfo,
|
|
10147
10257
|
invalidateMentionSuggestions: invalidateResolvedMentionSuggestions
|
|
10148
10258
|
},
|
|
10149
10259
|
getSyncStatus,
|
|
@@ -10159,6 +10269,7 @@ function createClient(options) {
|
|
|
10159
10269
|
resolveMentionSuggestions: clientOptions.resolveMentionSuggestions,
|
|
10160
10270
|
usersStore,
|
|
10161
10271
|
roomsInfoStore,
|
|
10272
|
+
groupsInfoStore,
|
|
10162
10273
|
getRoomIds() {
|
|
10163
10274
|
return Array.from(roomsById.keys());
|
|
10164
10275
|
},
|
|
@@ -10210,20 +10321,6 @@ function getLostConnectionTimeout(value) {
|
|
|
10210
10321
|
RECOMMENDED_MIN_LOST_CONNECTION_TIMEOUT
|
|
10211
10322
|
);
|
|
10212
10323
|
}
|
|
10213
|
-
function createDevelopmentWarning(condition, ...args) {
|
|
10214
|
-
let hasWarned = false;
|
|
10215
|
-
if (process.env.NODE_ENV !== "production") {
|
|
10216
|
-
return () => {
|
|
10217
|
-
if (!hasWarned && (typeof condition === "function" ? condition() : condition)) {
|
|
10218
|
-
warn(...args);
|
|
10219
|
-
hasWarned = true;
|
|
10220
|
-
}
|
|
10221
|
-
};
|
|
10222
|
-
} else {
|
|
10223
|
-
return () => {
|
|
10224
|
-
};
|
|
10225
|
-
}
|
|
10226
|
-
}
|
|
10227
10324
|
|
|
10228
10325
|
// src/comments/comment-body.ts
|
|
10229
10326
|
function isCommentBodyParagraph(element) {
|
|
@@ -10288,25 +10385,42 @@ function getMentionsFromCommentBody(body, predicate) {
|
|
|
10288
10385
|
});
|
|
10289
10386
|
return mentions;
|
|
10290
10387
|
}
|
|
10291
|
-
async function
|
|
10388
|
+
async function resolveMentionsInCommentBody(body, resolveUsers, resolveGroupsInfo) {
|
|
10292
10389
|
const resolvedUsers = /* @__PURE__ */ new Map();
|
|
10293
|
-
|
|
10294
|
-
|
|
10390
|
+
const resolvedGroupsInfo = /* @__PURE__ */ new Map();
|
|
10391
|
+
if (!resolveUsers && !resolveGroupsInfo) {
|
|
10392
|
+
return {
|
|
10393
|
+
users: resolvedUsers,
|
|
10394
|
+
groups: resolvedGroupsInfo
|
|
10395
|
+
};
|
|
10295
10396
|
}
|
|
10296
|
-
const
|
|
10297
|
-
|
|
10298
|
-
|
|
10299
|
-
|
|
10300
|
-
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
const
|
|
10305
|
-
|
|
10306
|
-
|
|
10397
|
+
const mentions = getMentionsFromCommentBody(body);
|
|
10398
|
+
const userIds = mentions.filter((mention) => mention.kind === "user").map((mention) => mention.id);
|
|
10399
|
+
const groupIds = mentions.filter((mention) => mention.kind === "group").map((mention) => mention.id);
|
|
10400
|
+
const [users, groups] = await Promise.all([
|
|
10401
|
+
resolveUsers && userIds.length > 0 ? resolveUsers({ userIds }) : void 0,
|
|
10402
|
+
resolveGroupsInfo && groupIds.length > 0 ? resolveGroupsInfo({ groupIds }) : void 0
|
|
10403
|
+
]);
|
|
10404
|
+
if (users) {
|
|
10405
|
+
for (const [index, userId] of userIds.entries()) {
|
|
10406
|
+
const user = users[index];
|
|
10407
|
+
if (user) {
|
|
10408
|
+
resolvedUsers.set(userId, user);
|
|
10409
|
+
}
|
|
10410
|
+
}
|
|
10411
|
+
}
|
|
10412
|
+
if (groups) {
|
|
10413
|
+
for (const [index, groupId] of groupIds.entries()) {
|
|
10414
|
+
const group = groups[index];
|
|
10415
|
+
if (group) {
|
|
10416
|
+
resolvedGroupsInfo.set(groupId, group);
|
|
10417
|
+
}
|
|
10307
10418
|
}
|
|
10308
10419
|
}
|
|
10309
|
-
return
|
|
10420
|
+
return {
|
|
10421
|
+
users: resolvedUsers,
|
|
10422
|
+
groups: resolvedGroupsInfo
|
|
10423
|
+
};
|
|
10310
10424
|
}
|
|
10311
10425
|
var htmlEscapables = {
|
|
10312
10426
|
"&": "&",
|
|
@@ -10419,8 +10533,8 @@ var stringifyCommentBodyPlainElements = {
|
|
|
10419
10533
|
paragraph: ({ children }) => children,
|
|
10420
10534
|
text: ({ element }) => element.text,
|
|
10421
10535
|
link: ({ element }) => element.text ?? element.url,
|
|
10422
|
-
mention: ({ element, user }) => {
|
|
10423
|
-
return `@${user?.name ?? element.id}`;
|
|
10536
|
+
mention: ({ element, user, group }) => {
|
|
10537
|
+
return `@${user?.name ?? group?.name ?? element.id}`;
|
|
10424
10538
|
}
|
|
10425
10539
|
};
|
|
10426
10540
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -10449,8 +10563,8 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
10449
10563
|
link: ({ element, href }) => {
|
|
10450
10564
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
10451
10565
|
},
|
|
10452
|
-
mention: ({ element, user }) => {
|
|
10453
|
-
return html`<span data-mention>@${user?.name ? html`${user?.name}` : element.id}</span>`;
|
|
10566
|
+
mention: ({ element, user, group }) => {
|
|
10567
|
+
return html`<span data-mention>@${user?.name ? html`${user?.name}` : group?.name ? html`${group?.name}` : element.id}</span>`;
|
|
10454
10568
|
}
|
|
10455
10569
|
};
|
|
10456
10570
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -10479,8 +10593,8 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
10479
10593
|
link: ({ element, href }) => {
|
|
10480
10594
|
return markdown`[${element.text ?? element.url}](${href})`;
|
|
10481
10595
|
},
|
|
10482
|
-
mention: ({ element, user }) => {
|
|
10483
|
-
return markdown`@${user?.name ?? element.id}`;
|
|
10596
|
+
mention: ({ element, user, group }) => {
|
|
10597
|
+
return markdown`@${user?.name ?? group?.name ?? element.id}`;
|
|
10484
10598
|
}
|
|
10485
10599
|
};
|
|
10486
10600
|
async function stringifyCommentBody(body, options) {
|
|
@@ -10490,9 +10604,10 @@ async function stringifyCommentBody(body, options) {
|
|
|
10490
10604
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
10491
10605
|
...options?.elements
|
|
10492
10606
|
};
|
|
10493
|
-
const resolvedUsers = await
|
|
10607
|
+
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
10494
10608
|
body,
|
|
10495
|
-
options?.resolveUsers
|
|
10609
|
+
options?.resolveUsers,
|
|
10610
|
+
options?.resolveGroupsInfo
|
|
10496
10611
|
);
|
|
10497
10612
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
10498
10613
|
switch (block.type) {
|
|
@@ -10503,7 +10618,8 @@ async function stringifyCommentBody(body, options) {
|
|
|
10503
10618
|
elements.mention(
|
|
10504
10619
|
{
|
|
10505
10620
|
element: inline,
|
|
10506
|
-
user: resolvedUsers.get(inline.id)
|
|
10621
|
+
user: inline.kind === "user" ? resolvedUsers.get(inline.id) : void 0,
|
|
10622
|
+
group: inline.kind === "group" ? resolvedGroupsInfo.get(inline.id) : void 0
|
|
10507
10623
|
},
|
|
10508
10624
|
inlineIndex
|
|
10509
10625
|
)
|
|
@@ -11057,6 +11173,7 @@ export {
|
|
|
11057
11173
|
LiveMap,
|
|
11058
11174
|
LiveObject,
|
|
11059
11175
|
LiveblocksError,
|
|
11176
|
+
MENTION_CHARACTER,
|
|
11060
11177
|
MutableSignal,
|
|
11061
11178
|
OpCode,
|
|
11062
11179
|
Permission,
|
|
@@ -11080,6 +11197,7 @@ export {
|
|
|
11080
11197
|
fancy_console_exports as console,
|
|
11081
11198
|
convertToCommentData,
|
|
11082
11199
|
convertToCommentUserReaction,
|
|
11200
|
+
convertToGroupData,
|
|
11083
11201
|
convertToInboxNotificationData,
|
|
11084
11202
|
convertToSubscriptionData,
|
|
11085
11203
|
convertToThreadData,
|
|
@@ -11133,7 +11251,7 @@ export {
|
|
|
11133
11251
|
patchLiveObjectKey,
|
|
11134
11252
|
patchNotificationSettings,
|
|
11135
11253
|
raise,
|
|
11136
|
-
|
|
11254
|
+
resolveMentionsInCommentBody,
|
|
11137
11255
|
sanitizeUrl,
|
|
11138
11256
|
shallow,
|
|
11139
11257
|
shallow2,
|
|
@@ -11145,6 +11263,8 @@ export {
|
|
|
11145
11263
|
url,
|
|
11146
11264
|
urljoin,
|
|
11147
11265
|
wait,
|
|
11266
|
+
warnOnce,
|
|
11267
|
+
warnOnceIf,
|
|
11148
11268
|
withTimeout
|
|
11149
11269
|
};
|
|
11150
11270
|
//# sourceMappingURL=index.js.map
|