@liveblocks/node 3.18.5 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +405 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +381 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
|
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/node";
|
|
6
|
-
var PKG_VERSION = "3.
|
|
6
|
+
var PKG_VERSION = "3.19.1";
|
|
7
7
|
var PKG_FORMAT = "cjs";
|
|
8
8
|
|
|
9
9
|
// src/client.ts
|
|
@@ -358,7 +358,7 @@ var Liveblocks = class {
|
|
|
358
358
|
method: "POST",
|
|
359
359
|
headers,
|
|
360
360
|
body: JSON.stringify(json),
|
|
361
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
361
|
+
signal: _optionalChain([options, 'optionalAccess', _2 => _2.signal])
|
|
362
362
|
});
|
|
363
363
|
xwarn(res, "POST", path);
|
|
364
364
|
return res;
|
|
@@ -374,7 +374,7 @@ var Liveblocks = class {
|
|
|
374
374
|
method: "PATCH",
|
|
375
375
|
headers,
|
|
376
376
|
body: JSON.stringify(json),
|
|
377
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
377
|
+
signal: _optionalChain([options, 'optionalAccess', _3 => _3.signal])
|
|
378
378
|
});
|
|
379
379
|
xwarn(res, "PATCH", path);
|
|
380
380
|
return res;
|
|
@@ -390,7 +390,7 @@ var Liveblocks = class {
|
|
|
390
390
|
method: "PUT",
|
|
391
391
|
headers,
|
|
392
392
|
body,
|
|
393
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
393
|
+
signal: _optionalChain([options, 'optionalAccess', _4 => _4.signal])
|
|
394
394
|
});
|
|
395
395
|
xwarn(res, "PUT", path);
|
|
396
396
|
return res;
|
|
@@ -404,7 +404,7 @@ var Liveblocks = class {
|
|
|
404
404
|
const res = await fetch(url3, {
|
|
405
405
|
method: "DELETE",
|
|
406
406
|
headers,
|
|
407
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
407
|
+
signal: _optionalChain([options, 'optionalAccess', _5 => _5.signal])
|
|
408
408
|
});
|
|
409
409
|
xwarn(res, "DELETE", path);
|
|
410
410
|
return res;
|
|
@@ -418,7 +418,7 @@ var Liveblocks = class {
|
|
|
418
418
|
const res = await fetch(url3, {
|
|
419
419
|
method: "GET",
|
|
420
420
|
headers,
|
|
421
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
421
|
+
signal: _optionalChain([options, 'optionalAccess', _6 => _6.signal])
|
|
422
422
|
});
|
|
423
423
|
xwarn(res, "GET", path);
|
|
424
424
|
return res;
|
|
@@ -449,8 +449,8 @@ var Liveblocks = class {
|
|
|
449
449
|
return new Session(
|
|
450
450
|
this.#post.bind(this),
|
|
451
451
|
userId,
|
|
452
|
-
_optionalChain([options, 'optionalAccess',
|
|
453
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
452
|
+
_optionalChain([options, 'optionalAccess', _7 => _7.userInfo]),
|
|
453
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.organizationId]), () => ( _optionalChain([options, 'optionalAccess', _9 => _9.tenantId]))),
|
|
454
454
|
this.#localDev
|
|
455
455
|
);
|
|
456
456
|
}
|
|
@@ -500,7 +500,7 @@ var Liveblocks = class {
|
|
|
500
500
|
const body = {
|
|
501
501
|
userId,
|
|
502
502
|
groupIds,
|
|
503
|
-
userInfo: _optionalChain([options, 'optionalAccess',
|
|
503
|
+
userInfo: _optionalChain([options, 'optionalAccess', _10 => _10.userInfo])
|
|
504
504
|
};
|
|
505
505
|
if (organizationId !== void 0) {
|
|
506
506
|
body.organizationId = organizationId;
|
|
@@ -586,7 +586,7 @@ var Liveblocks = class {
|
|
|
586
586
|
*/
|
|
587
587
|
async *iterRooms(criteria, options) {
|
|
588
588
|
const { signal } = _nullishCoalesce(options, () => ( {}));
|
|
589
|
-
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
589
|
+
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.pageSize]), () => ( 40)), 20);
|
|
590
590
|
let cursor = void 0;
|
|
591
591
|
while (true) {
|
|
592
592
|
const { nextCursor, data } = await this.getRooms(
|
|
@@ -635,7 +635,7 @@ var Liveblocks = class {
|
|
|
635
635
|
body.organizationId = tenantId;
|
|
636
636
|
}
|
|
637
637
|
const res = await this.#post(
|
|
638
|
-
_optionalChain([options, 'optionalAccess',
|
|
638
|
+
_optionalChain([options, 'optionalAccess', _12 => _12.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
|
|
639
639
|
body,
|
|
640
640
|
options
|
|
641
641
|
);
|
|
@@ -1091,7 +1091,7 @@ var Liveblocks = class {
|
|
|
1091
1091
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
|
|
1092
1092
|
{
|
|
1093
1093
|
...data,
|
|
1094
|
-
createdAt: _optionalChain([data, 'access',
|
|
1094
|
+
createdAt: _optionalChain([data, 'access', _13 => _13.createdAt, 'optionalAccess', _14 => _14.toISOString, 'call', _15 => _15()])
|
|
1095
1095
|
},
|
|
1096
1096
|
options
|
|
1097
1097
|
);
|
|
@@ -1117,7 +1117,7 @@ var Liveblocks = class {
|
|
|
1117
1117
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
1118
1118
|
{
|
|
1119
1119
|
body: data.body,
|
|
1120
|
-
editedAt: _optionalChain([data, 'access',
|
|
1120
|
+
editedAt: _optionalChain([data, 'access', _16 => _16.editedAt, 'optionalAccess', _17 => _17.toISOString, 'call', _18 => _18()]),
|
|
1121
1121
|
metadata: data.metadata
|
|
1122
1122
|
},
|
|
1123
1123
|
options
|
|
@@ -1185,7 +1185,7 @@ var Liveblocks = class {
|
|
|
1185
1185
|
...data,
|
|
1186
1186
|
comment: {
|
|
1187
1187
|
...data.comment,
|
|
1188
|
-
createdAt: _optionalChain([data, 'access',
|
|
1188
|
+
createdAt: _optionalChain([data, 'access', _19 => _19.comment, 'access', _20 => _20.createdAt, 'optionalAccess', _21 => _21.toISOString, 'call', _22 => _22()])
|
|
1189
1189
|
}
|
|
1190
1190
|
},
|
|
1191
1191
|
options
|
|
@@ -1308,7 +1308,7 @@ var Liveblocks = class {
|
|
|
1308
1308
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
|
|
1309
1309
|
{
|
|
1310
1310
|
...data,
|
|
1311
|
-
updatedAt: _optionalChain([data, 'access',
|
|
1311
|
+
updatedAt: _optionalChain([data, 'access', _23 => _23.updatedAt, 'optionalAccess', _24 => _24.toISOString, 'call', _25 => _25()])
|
|
1312
1312
|
},
|
|
1313
1313
|
options
|
|
1314
1314
|
);
|
|
@@ -1334,7 +1334,7 @@ var Liveblocks = class {
|
|
|
1334
1334
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/metadata`,
|
|
1335
1335
|
{
|
|
1336
1336
|
...data,
|
|
1337
|
-
updatedAt: _optionalChain([data, 'access',
|
|
1337
|
+
updatedAt: _optionalChain([data, 'access', _26 => _26.updatedAt, 'optionalAccess', _27 => _27.toISOString, 'call', _28 => _28()])
|
|
1338
1338
|
},
|
|
1339
1339
|
options
|
|
1340
1340
|
);
|
|
@@ -1360,7 +1360,7 @@ var Liveblocks = class {
|
|
|
1360
1360
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
|
|
1361
1361
|
{
|
|
1362
1362
|
...data,
|
|
1363
|
-
createdAt: _optionalChain([data, 'access',
|
|
1363
|
+
createdAt: _optionalChain([data, 'access', _29 => _29.createdAt, 'optionalAccess', _30 => _30.toISOString, 'call', _31 => _31()])
|
|
1364
1364
|
},
|
|
1365
1365
|
options
|
|
1366
1366
|
);
|
|
@@ -1386,7 +1386,7 @@ var Liveblocks = class {
|
|
|
1386
1386
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
|
|
1387
1387
|
{
|
|
1388
1388
|
...data,
|
|
1389
|
-
removedAt: _optionalChain([data, 'access',
|
|
1389
|
+
removedAt: _optionalChain([data, 'access', _32 => _32.removedAt, 'optionalAccess', _33 => _33.toISOString, 'call', _34 => _34()])
|
|
1390
1390
|
},
|
|
1391
1391
|
options
|
|
1392
1392
|
);
|
|
@@ -1467,7 +1467,7 @@ var Liveblocks = class {
|
|
|
1467
1467
|
*/
|
|
1468
1468
|
async *iterInboxNotifications(criteria, options) {
|
|
1469
1469
|
const { signal } = _nullishCoalesce(options, () => ( {}));
|
|
1470
|
-
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1470
|
+
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _35 => _35.pageSize]), () => ( 50)), 10);
|
|
1471
1471
|
let cursor = void 0;
|
|
1472
1472
|
while (true) {
|
|
1473
1473
|
const { nextCursor, data } = await this.getInboxNotifications(
|
|
@@ -1814,7 +1814,7 @@ var Liveblocks = class {
|
|
|
1814
1814
|
async getGroups(params, options) {
|
|
1815
1815
|
const res = await this.#get(
|
|
1816
1816
|
_core.url`/v2/groups`,
|
|
1817
|
-
{ startingAfter: _optionalChain([params, 'optionalAccess',
|
|
1817
|
+
{ startingAfter: _optionalChain([params, 'optionalAccess', _36 => _36.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _37 => _37.limit]) },
|
|
1818
1818
|
options
|
|
1819
1819
|
);
|
|
1820
1820
|
if (!res.ok) {
|
|
@@ -1876,7 +1876,7 @@ var Liveblocks = class {
|
|
|
1876
1876
|
async massMutateStorage(criteria, callback, massOptions) {
|
|
1877
1877
|
const concurrency = _core.checkBounds.call(void 0,
|
|
1878
1878
|
"concurrency",
|
|
1879
|
-
_nullishCoalesce(_optionalChain([massOptions, 'optionalAccess',
|
|
1879
|
+
_nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _38 => _38.concurrency]), () => ( 8)),
|
|
1880
1880
|
1,
|
|
1881
1881
|
20
|
|
1882
1882
|
);
|
|
@@ -1892,7 +1892,7 @@ var Liveblocks = class {
|
|
|
1892
1892
|
}
|
|
1893
1893
|
async #_mutateOneRoom(roomId, room, callback, options) {
|
|
1894
1894
|
const debounceInterval = 200;
|
|
1895
|
-
const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess',
|
|
1895
|
+
const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _39 => _39.signal]));
|
|
1896
1896
|
let opsBuffer = [];
|
|
1897
1897
|
let outstandingFlush$ = void 0;
|
|
1898
1898
|
let lastFlush = performance.now();
|
|
@@ -1958,7 +1958,7 @@ var Liveblocks = class {
|
|
|
1958
1958
|
const res = await this.#post(
|
|
1959
1959
|
_core.url`/v2/rooms/${roomId}/send-message`,
|
|
1960
1960
|
{ messages },
|
|
1961
|
-
{ signal: _optionalChain([options, 'optionalAccess',
|
|
1961
|
+
{ signal: _optionalChain([options, 'optionalAccess', _40 => _40.signal]) }
|
|
1962
1962
|
);
|
|
1963
1963
|
if (!res.ok) {
|
|
1964
1964
|
throw await LiveblocksError.from(res);
|
|
@@ -2095,7 +2095,7 @@ var Liveblocks = class {
|
|
|
2095
2095
|
"Content-Type": params.file.type,
|
|
2096
2096
|
"Content-Length": String(params.file.size)
|
|
2097
2097
|
},
|
|
2098
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
2098
|
+
signal: _optionalChain([options, 'optionalAccess', _41 => _41.signal])
|
|
2099
2099
|
}
|
|
2100
2100
|
);
|
|
2101
2101
|
if (!res.ok) {
|
|
@@ -2457,6 +2457,385 @@ ${this.details}`;
|
|
|
2457
2457
|
}
|
|
2458
2458
|
};
|
|
2459
2459
|
|
|
2460
|
+
// src/comment-body.ts
|
|
2461
|
+
|
|
2462
|
+
|
|
2463
|
+
|
|
2464
|
+
|
|
2465
|
+
|
|
2466
|
+
|
|
2467
|
+
var _marked = require('marked');
|
|
2468
|
+
var MENTION_REGEX = /(^|[^A-Za-z0-9_.-])@([A-Za-z0-9_][A-Za-z0-9_.@-]*)/g;
|
|
2469
|
+
var MENTION_TRAILING_PUNCTUATION_REGEX = /[.-]/;
|
|
2470
|
+
var WHITESPACE_REGEX = /\s/;
|
|
2471
|
+
var MarkedCustomTokenizer = class extends _marked.Tokenizer {
|
|
2472
|
+
url(src) {
|
|
2473
|
+
const token = super.url(src);
|
|
2474
|
+
if (_optionalChain([token, 'optionalAccess', _42 => _42.href, 'access', _43 => _43.startsWith, 'call', _44 => _44("mailto:")])) {
|
|
2475
|
+
return void 0;
|
|
2476
|
+
}
|
|
2477
|
+
return token;
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
function assertTokens(_) {
|
|
2481
|
+
}
|
|
2482
|
+
function tokenizeMarkdown(markdown) {
|
|
2483
|
+
return new (0, _marked.Lexer)({ gfm: true, tokenizer: new MarkedCustomTokenizer() }).lex(
|
|
2484
|
+
markdown
|
|
2485
|
+
);
|
|
2486
|
+
}
|
|
2487
|
+
function toCommentBodyText(text, formatting) {
|
|
2488
|
+
return {
|
|
2489
|
+
text,
|
|
2490
|
+
...formatting
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
function appendPlainText(inlines, text, formatting) {
|
|
2494
|
+
if (text.length === 0) {
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2497
|
+
inlines.push(toCommentBodyText(text, formatting));
|
|
2498
|
+
}
|
|
2499
|
+
function listIndent(listDepth) {
|
|
2500
|
+
return " ".repeat(listDepth);
|
|
2501
|
+
}
|
|
2502
|
+
function blockquotePrefix(blockquoteDepth) {
|
|
2503
|
+
return blockquoteDepth > 0 ? "> ".repeat(blockquoteDepth) : "";
|
|
2504
|
+
}
|
|
2505
|
+
function listMarker(ordered, start, index) {
|
|
2506
|
+
if (!ordered) {
|
|
2507
|
+
return "- ";
|
|
2508
|
+
}
|
|
2509
|
+
const firstItemNumber = start === "" ? 1 : start;
|
|
2510
|
+
return `${firstItemNumber + index}. `;
|
|
2511
|
+
}
|
|
2512
|
+
function taskListPrefix(item) {
|
|
2513
|
+
if (!item.task) {
|
|
2514
|
+
return "";
|
|
2515
|
+
}
|
|
2516
|
+
return item.checked ? "[x] " : "[ ] ";
|
|
2517
|
+
}
|
|
2518
|
+
function prependTextToParagraph(paragraph, textPrefix) {
|
|
2519
|
+
if (textPrefix.length === 0) {
|
|
2520
|
+
return paragraph;
|
|
2521
|
+
}
|
|
2522
|
+
return {
|
|
2523
|
+
...paragraph,
|
|
2524
|
+
children: [{ text: textPrefix }, ...paragraph.children]
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
function appendTextWithMentions(inlines, text, formatting) {
|
|
2528
|
+
let cursor = 0;
|
|
2529
|
+
for (const match of text.matchAll(MENTION_REGEX)) {
|
|
2530
|
+
const prefix = _nullishCoalesce(match[1], () => ( ""));
|
|
2531
|
+
const rawId = match[2];
|
|
2532
|
+
if (match.index === void 0 || rawId === void 0) {
|
|
2533
|
+
continue;
|
|
2534
|
+
}
|
|
2535
|
+
const atSignIndex = match.index + prefix.length;
|
|
2536
|
+
const idStart = atSignIndex + 1;
|
|
2537
|
+
let idEnd = idStart + rawId.length;
|
|
2538
|
+
while (idEnd > idStart && MENTION_TRAILING_PUNCTUATION_REGEX.test(text.charAt(idEnd - 1)) && (idEnd === text.length || WHITESPACE_REGEX.test(text.charAt(idEnd)))) {
|
|
2539
|
+
idEnd -= 1;
|
|
2540
|
+
}
|
|
2541
|
+
if (atSignIndex > cursor) {
|
|
2542
|
+
inlines.push(
|
|
2543
|
+
toCommentBodyText(text.slice(cursor, atSignIndex), formatting)
|
|
2544
|
+
);
|
|
2545
|
+
}
|
|
2546
|
+
inlines.push({
|
|
2547
|
+
type: "mention",
|
|
2548
|
+
kind: "user",
|
|
2549
|
+
id: text.slice(idStart, idEnd)
|
|
2550
|
+
});
|
|
2551
|
+
cursor = idEnd;
|
|
2552
|
+
}
|
|
2553
|
+
if (cursor < text.length) {
|
|
2554
|
+
inlines.push(toCommentBodyText(text.slice(cursor), formatting));
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
function appendFormattedInlinesFromTokens(inlines, tokens, formatting) {
|
|
2558
|
+
inlines.push(...tokensToCommentBodyInlines(tokens, formatting));
|
|
2559
|
+
}
|
|
2560
|
+
function tableAlignmentMarker(alignment) {
|
|
2561
|
+
switch (alignment) {
|
|
2562
|
+
case "left":
|
|
2563
|
+
return ":---";
|
|
2564
|
+
case "center":
|
|
2565
|
+
return ":---:";
|
|
2566
|
+
case "right":
|
|
2567
|
+
return "---:";
|
|
2568
|
+
default:
|
|
2569
|
+
return "---";
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
function tableToMarkdownRows(table) {
|
|
2573
|
+
const rows = [table.header, ...table.rows];
|
|
2574
|
+
const markdownRows = rows.map((row) => {
|
|
2575
|
+
const cells = row.map((cell) => tokensToPlainText(cell.tokens));
|
|
2576
|
+
return `| ${cells.join(" | ")} |`;
|
|
2577
|
+
});
|
|
2578
|
+
if (markdownRows.length === 0) {
|
|
2579
|
+
return [];
|
|
2580
|
+
}
|
|
2581
|
+
const separatorRow = `| ${table.align.map(tableAlignmentMarker).join(" | ")} |`;
|
|
2582
|
+
return [markdownRows[0], separatorRow, ...markdownRows.slice(1)].filter(
|
|
2583
|
+
(row) => row !== void 0
|
|
2584
|
+
);
|
|
2585
|
+
}
|
|
2586
|
+
function tokensToPlainText(tokens, listDepth = 0) {
|
|
2587
|
+
assertTokens(tokens);
|
|
2588
|
+
return tokens.map((t) => tokenToPlainText(t, listDepth)).join("");
|
|
2589
|
+
}
|
|
2590
|
+
function tokenToPlainText(token, listDepth = 0) {
|
|
2591
|
+
switch (token.type) {
|
|
2592
|
+
case "escape":
|
|
2593
|
+
case "html":
|
|
2594
|
+
case "codespan":
|
|
2595
|
+
case "text": {
|
|
2596
|
+
return token.text;
|
|
2597
|
+
}
|
|
2598
|
+
case "br": {
|
|
2599
|
+
return "\n";
|
|
2600
|
+
}
|
|
2601
|
+
case "strong":
|
|
2602
|
+
case "em":
|
|
2603
|
+
case "del":
|
|
2604
|
+
case "link": {
|
|
2605
|
+
return tokensToPlainText(token.tokens, 0);
|
|
2606
|
+
}
|
|
2607
|
+
case "image": {
|
|
2608
|
+
return token.text || token.href;
|
|
2609
|
+
}
|
|
2610
|
+
case "paragraph":
|
|
2611
|
+
case "heading": {
|
|
2612
|
+
return tokensToPlainText(token.tokens, listDepth);
|
|
2613
|
+
}
|
|
2614
|
+
case "blockquote": {
|
|
2615
|
+
return tokensToPlainText(token.tokens, listDepth);
|
|
2616
|
+
}
|
|
2617
|
+
case "list": {
|
|
2618
|
+
return token.items.map(
|
|
2619
|
+
(item, index) => listItemToText(item, token.ordered, token.start, index, listDepth)
|
|
2620
|
+
).join("\n");
|
|
2621
|
+
}
|
|
2622
|
+
case "list_item": {
|
|
2623
|
+
return tokensToPlainText(token.tokens, listDepth);
|
|
2624
|
+
}
|
|
2625
|
+
case "code": {
|
|
2626
|
+
return token.text;
|
|
2627
|
+
}
|
|
2628
|
+
case "table": {
|
|
2629
|
+
return tableToMarkdownRows(token).join("\n");
|
|
2630
|
+
}
|
|
2631
|
+
case "space":
|
|
2632
|
+
case "hr": {
|
|
2633
|
+
return "";
|
|
2634
|
+
}
|
|
2635
|
+
default: {
|
|
2636
|
+
return "";
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
function listItemToText(item, ordered, start, index, listDepth) {
|
|
2641
|
+
const indent = listIndent(listDepth);
|
|
2642
|
+
const marker = listMarker(ordered, start, index);
|
|
2643
|
+
const prefix = indent + marker + taskListPrefix(item);
|
|
2644
|
+
return `${prefix}${tokensToPlainText(item.tokens, listDepth + 1)}`;
|
|
2645
|
+
}
|
|
2646
|
+
function tokensToCommentBodyInlines(tokens, formatting = {}) {
|
|
2647
|
+
assertTokens(tokens);
|
|
2648
|
+
const inlines = [];
|
|
2649
|
+
for (const token of tokens) {
|
|
2650
|
+
switch (token.type) {
|
|
2651
|
+
case "escape":
|
|
2652
|
+
case "html":
|
|
2653
|
+
case "text": {
|
|
2654
|
+
if (token.type === "text" && _optionalChain([token, 'access', _45 => _45.tokens, 'optionalAccess', _46 => _46.length])) {
|
|
2655
|
+
appendFormattedInlinesFromTokens(inlines, token.tokens, formatting);
|
|
2656
|
+
} else {
|
|
2657
|
+
appendTextWithMentions(inlines, token.text, formatting);
|
|
2658
|
+
}
|
|
2659
|
+
break;
|
|
2660
|
+
}
|
|
2661
|
+
case "br": {
|
|
2662
|
+
inlines.push(toCommentBodyText("\n", formatting));
|
|
2663
|
+
break;
|
|
2664
|
+
}
|
|
2665
|
+
case "strong": {
|
|
2666
|
+
appendFormattedInlinesFromTokens(inlines, token.tokens, {
|
|
2667
|
+
...formatting,
|
|
2668
|
+
bold: true
|
|
2669
|
+
});
|
|
2670
|
+
break;
|
|
2671
|
+
}
|
|
2672
|
+
case "em": {
|
|
2673
|
+
appendFormattedInlinesFromTokens(inlines, token.tokens, {
|
|
2674
|
+
...formatting,
|
|
2675
|
+
italic: true
|
|
2676
|
+
});
|
|
2677
|
+
break;
|
|
2678
|
+
}
|
|
2679
|
+
case "del": {
|
|
2680
|
+
appendFormattedInlinesFromTokens(inlines, token.tokens, {
|
|
2681
|
+
...formatting,
|
|
2682
|
+
strikethrough: true
|
|
2683
|
+
});
|
|
2684
|
+
break;
|
|
2685
|
+
}
|
|
2686
|
+
case "codespan": {
|
|
2687
|
+
inlines.push(
|
|
2688
|
+
toCommentBodyText(token.text, {
|
|
2689
|
+
...formatting,
|
|
2690
|
+
code: true
|
|
2691
|
+
})
|
|
2692
|
+
);
|
|
2693
|
+
break;
|
|
2694
|
+
}
|
|
2695
|
+
case "link": {
|
|
2696
|
+
const href = _core.sanitizeUrl.call(void 0, token.href);
|
|
2697
|
+
const text = tokensToPlainText(token.tokens, 0);
|
|
2698
|
+
if (href === null) {
|
|
2699
|
+
appendPlainText(inlines, text, formatting);
|
|
2700
|
+
break;
|
|
2701
|
+
}
|
|
2702
|
+
inlines.push({
|
|
2703
|
+
type: "link",
|
|
2704
|
+
url: href,
|
|
2705
|
+
text
|
|
2706
|
+
});
|
|
2707
|
+
break;
|
|
2708
|
+
}
|
|
2709
|
+
case "image": {
|
|
2710
|
+
appendPlainText(inlines, token.raw, formatting);
|
|
2711
|
+
break;
|
|
2712
|
+
}
|
|
2713
|
+
default: {
|
|
2714
|
+
const text = tokenToPlainText(token, 0);
|
|
2715
|
+
if (text) {
|
|
2716
|
+
appendTextWithMentions(inlines, text, formatting);
|
|
2717
|
+
}
|
|
2718
|
+
break;
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
return inlines;
|
|
2723
|
+
}
|
|
2724
|
+
function tokenToCommentBodyParagraphs(token, listDepth = 0, blockquoteDepth = 0) {
|
|
2725
|
+
switch (token.type) {
|
|
2726
|
+
case "space":
|
|
2727
|
+
case "hr": {
|
|
2728
|
+
return [];
|
|
2729
|
+
}
|
|
2730
|
+
case "paragraph":
|
|
2731
|
+
case "heading": {
|
|
2732
|
+
const children = tokensToCommentBodyInlines(token.tokens);
|
|
2733
|
+
if (children.length === 0) {
|
|
2734
|
+
return [];
|
|
2735
|
+
}
|
|
2736
|
+
const headingPrefix = token.type === "heading" ? `${"#".repeat(token.depth)} ` : "";
|
|
2737
|
+
return [
|
|
2738
|
+
prependTextToParagraph(
|
|
2739
|
+
{
|
|
2740
|
+
type: "paragraph",
|
|
2741
|
+
children
|
|
2742
|
+
},
|
|
2743
|
+
blockquotePrefix(blockquoteDepth) + headingPrefix
|
|
2744
|
+
)
|
|
2745
|
+
];
|
|
2746
|
+
}
|
|
2747
|
+
case "blockquote": {
|
|
2748
|
+
return tokensToCommentBodyParagraphs(
|
|
2749
|
+
token.tokens,
|
|
2750
|
+
listDepth,
|
|
2751
|
+
blockquoteDepth + 1
|
|
2752
|
+
);
|
|
2753
|
+
}
|
|
2754
|
+
case "list": {
|
|
2755
|
+
const indent = listIndent(listDepth);
|
|
2756
|
+
const quotePrefix = blockquotePrefix(blockquoteDepth);
|
|
2757
|
+
return token.items.flatMap((item, index) => {
|
|
2758
|
+
const marker = listMarker(token.ordered, token.start, index);
|
|
2759
|
+
const listPrefix = indent + marker + taskListPrefix(item);
|
|
2760
|
+
const paragraphs = tokensToCommentBodyParagraphs(
|
|
2761
|
+
item.tokens,
|
|
2762
|
+
listDepth + 1,
|
|
2763
|
+
0
|
|
2764
|
+
);
|
|
2765
|
+
const [firstParagraph, ...remainingParagraphs] = paragraphs;
|
|
2766
|
+
if (!firstParagraph) {
|
|
2767
|
+
return [
|
|
2768
|
+
{
|
|
2769
|
+
type: "paragraph",
|
|
2770
|
+
children: [{ text: quotePrefix + listPrefix }]
|
|
2771
|
+
}
|
|
2772
|
+
];
|
|
2773
|
+
}
|
|
2774
|
+
const firstParagraphWithPrefixes = prependTextToParagraph(
|
|
2775
|
+
firstParagraph,
|
|
2776
|
+
quotePrefix + listPrefix
|
|
2777
|
+
);
|
|
2778
|
+
const remainingParagraphsWithQuotePrefix = remainingParagraphs.map(
|
|
2779
|
+
(paragraph) => prependTextToParagraph(paragraph, quotePrefix)
|
|
2780
|
+
);
|
|
2781
|
+
return [
|
|
2782
|
+
firstParagraphWithPrefixes,
|
|
2783
|
+
...remainingParagraphsWithQuotePrefix
|
|
2784
|
+
];
|
|
2785
|
+
});
|
|
2786
|
+
}
|
|
2787
|
+
case "list_item": {
|
|
2788
|
+
return tokensToCommentBodyParagraphs(
|
|
2789
|
+
token.tokens,
|
|
2790
|
+
listDepth,
|
|
2791
|
+
blockquoteDepth
|
|
2792
|
+
);
|
|
2793
|
+
}
|
|
2794
|
+
case "code": {
|
|
2795
|
+
return [
|
|
2796
|
+
prependTextToParagraph(
|
|
2797
|
+
{
|
|
2798
|
+
type: "paragraph",
|
|
2799
|
+
children: [{ text: token.text }]
|
|
2800
|
+
},
|
|
2801
|
+
blockquotePrefix(blockquoteDepth)
|
|
2802
|
+
)
|
|
2803
|
+
];
|
|
2804
|
+
}
|
|
2805
|
+
case "table": {
|
|
2806
|
+
const quotePrefix = blockquotePrefix(blockquoteDepth);
|
|
2807
|
+
return tableToMarkdownRows(token).map((row) => ({
|
|
2808
|
+
type: "paragraph",
|
|
2809
|
+
children: [{ text: quotePrefix + row }]
|
|
2810
|
+
}));
|
|
2811
|
+
}
|
|
2812
|
+
default: {
|
|
2813
|
+
const inlines = tokensToCommentBodyInlines([token]);
|
|
2814
|
+
return inlines.length > 0 ? [
|
|
2815
|
+
prependTextToParagraph(
|
|
2816
|
+
{
|
|
2817
|
+
type: "paragraph",
|
|
2818
|
+
children: inlines
|
|
2819
|
+
},
|
|
2820
|
+
blockquotePrefix(blockquoteDepth)
|
|
2821
|
+
)
|
|
2822
|
+
] : [];
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
function tokensToCommentBodyParagraphs(tokens, listDepth = 0, blockquoteDepth = 0) {
|
|
2827
|
+
assertTokens(tokens);
|
|
2828
|
+
return tokens.flatMap(
|
|
2829
|
+
(token) => tokenToCommentBodyParagraphs(token, listDepth, blockquoteDepth)
|
|
2830
|
+
);
|
|
2831
|
+
}
|
|
2832
|
+
function markdownToCommentBody(markdown) {
|
|
2833
|
+
return {
|
|
2834
|
+
version: 1,
|
|
2835
|
+
content: tokensToCommentBodyParagraphs(tokenizeMarkdown(markdown))
|
|
2836
|
+
};
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2460
2839
|
// src/webhooks.ts
|
|
2461
2840
|
var _base64 = require('@stablelib/base64'); var base64 = _interopRequireWildcard(_base64);
|
|
2462
2841
|
var _fastsha256 = require('fast-sha256'); var sha256 = _interopRequireWildcard(_fastsha256);
|
|
@@ -2625,5 +3004,6 @@ _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
2625
3004
|
|
|
2626
3005
|
|
|
2627
3006
|
|
|
2628
|
-
|
|
3007
|
+
|
|
3008
|
+
exports.LiveList = _core.LiveList; exports.LiveMap = _core.LiveMap; exports.LiveObject = _core.LiveObject; exports.Liveblocks = Liveblocks; exports.LiveblocksError = LiveblocksError; exports.WebhookHandler = WebhookHandler; exports.getMentionsFromCommentBody = _core.getMentionsFromCommentBody; exports.isCustomNotificationEvent = isCustomNotificationEvent; exports.isNotificationChannelEnabled = _core.isNotificationChannelEnabled; exports.isTextMentionNotificationEvent = isTextMentionNotificationEvent; exports.isThreadNotificationEvent = isThreadNotificationEvent; exports.markdownToCommentBody = markdownToCommentBody; exports.stringifyCommentBody = _core.stringifyCommentBody;
|
|
2629
3009
|
//# sourceMappingURL=index.cjs.map
|