@liveblocks/core 1.8.0 → 1.8.2
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.d.mts +93 -3
- package/dist/index.d.ts +93 -3
- package/dist/index.js +320 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +319 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -2007,8 +2007,8 @@ declare function assert(condition: boolean, errmsg: string): asserts condition;
|
|
|
2007
2007
|
*/
|
|
2008
2008
|
declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
|
|
2009
2009
|
|
|
2010
|
-
declare type PromiseOrNot<T> = T | Promise<T>;
|
|
2011
|
-
declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot<T>;
|
|
2010
|
+
declare type PromiseOrNot$1<T> = T | Promise<T>;
|
|
2011
|
+
declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot$1<T>;
|
|
2012
2012
|
declare type AsyncCacheOptions<T, E> = {
|
|
2013
2013
|
isStateEqual?: (a: AsyncState<T, E>, b: AsyncState<T, E>) => boolean;
|
|
2014
2014
|
};
|
|
@@ -2435,6 +2435,96 @@ declare namespace protocol {
|
|
|
2435
2435
|
};
|
|
2436
2436
|
}
|
|
2437
2437
|
|
|
2438
|
+
declare type PromiseOrNot<T> = T | Promise<T>;
|
|
2439
|
+
declare type CommentBodyResolveUsersArgs = {
|
|
2440
|
+
/**
|
|
2441
|
+
* The ID of the users to resolve.
|
|
2442
|
+
*/
|
|
2443
|
+
userIds: string[];
|
|
2444
|
+
};
|
|
2445
|
+
declare type CommentBodyParagraphElementArgs = {
|
|
2446
|
+
/**
|
|
2447
|
+
* The paragraph element.
|
|
2448
|
+
*/
|
|
2449
|
+
element: CommentBodyParagraph;
|
|
2450
|
+
/**
|
|
2451
|
+
* The text content of the paragraph.
|
|
2452
|
+
*/
|
|
2453
|
+
children: string;
|
|
2454
|
+
};
|
|
2455
|
+
declare type CommentBodyTextElementArgs = {
|
|
2456
|
+
/**
|
|
2457
|
+
* The text element.
|
|
2458
|
+
*/
|
|
2459
|
+
element: CommentBodyText;
|
|
2460
|
+
};
|
|
2461
|
+
declare type CommentBodyLinkElementArgs = {
|
|
2462
|
+
/**
|
|
2463
|
+
* The link element.
|
|
2464
|
+
*/
|
|
2465
|
+
element: CommentBodyLink;
|
|
2466
|
+
/**
|
|
2467
|
+
* The absolute URL of the link.
|
|
2468
|
+
*/
|
|
2469
|
+
href: string;
|
|
2470
|
+
};
|
|
2471
|
+
declare type CommentBodyMentionElementArgs<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
2472
|
+
/**
|
|
2473
|
+
* The mention element.
|
|
2474
|
+
*/
|
|
2475
|
+
element: CommentBodyMention;
|
|
2476
|
+
/**
|
|
2477
|
+
* The mention's user info, if the `resolvedUsers` option was provided.
|
|
2478
|
+
*/
|
|
2479
|
+
user?: TUserMeta["info"];
|
|
2480
|
+
};
|
|
2481
|
+
declare type StringifyCommentBodyElements<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
2482
|
+
/**
|
|
2483
|
+
* The element used to display paragraphs.
|
|
2484
|
+
*/
|
|
2485
|
+
paragraph: (args: CommentBodyParagraphElementArgs, index: number) => string;
|
|
2486
|
+
/**
|
|
2487
|
+
* The element used to display text elements.
|
|
2488
|
+
*/
|
|
2489
|
+
text: (args: CommentBodyTextElementArgs, index: number) => string;
|
|
2490
|
+
/**
|
|
2491
|
+
* The element used to display links.
|
|
2492
|
+
*/
|
|
2493
|
+
link: (args: CommentBodyLinkElementArgs, index: number) => string;
|
|
2494
|
+
/**
|
|
2495
|
+
* The element used to display mentions.
|
|
2496
|
+
*/
|
|
2497
|
+
mention: (args: CommentBodyMentionElementArgs<TUserMeta>, index: number) => string;
|
|
2498
|
+
};
|
|
2499
|
+
declare type StringifyCommentBodyOptions<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
2500
|
+
/**
|
|
2501
|
+
* Which format to convert the comment to.
|
|
2502
|
+
*/
|
|
2503
|
+
format?: "plain" | "html" | "markdown";
|
|
2504
|
+
/**
|
|
2505
|
+
* The elements used to customize the resulting string. Each element has
|
|
2506
|
+
* priority over the defaults inherited from the `format` option.
|
|
2507
|
+
*/
|
|
2508
|
+
elements?: Partial<StringifyCommentBodyElements<TUserMeta>>;
|
|
2509
|
+
/**
|
|
2510
|
+
* The separator used between paragraphs.
|
|
2511
|
+
*/
|
|
2512
|
+
separator?: string;
|
|
2513
|
+
/**
|
|
2514
|
+
* A function that returns user info from user IDs.
|
|
2515
|
+
*/
|
|
2516
|
+
resolveUsers?: (args: CommentBodyResolveUsersArgs) => PromiseOrNot<(TUserMeta["info"] | undefined)[] | undefined>;
|
|
2517
|
+
};
|
|
2518
|
+
/**
|
|
2519
|
+
* Get an array of each user's ID that has been mentioned in a `CommentBody`.
|
|
2520
|
+
*/
|
|
2521
|
+
declare function getMentionedIdsFromCommentBody(body: CommentBody): string[];
|
|
2522
|
+
/**
|
|
2523
|
+
* Convert a `CommentBody` into either a plain string,
|
|
2524
|
+
* Markdown, HTML, or a custom format.
|
|
2525
|
+
*/
|
|
2526
|
+
declare function stringifyCommentBody<TUserMeta extends BaseUserMeta = BaseUserMeta>(body: CommentBody, options?: StringifyCommentBodyOptions<TUserMeta>): Promise<string>;
|
|
2527
|
+
|
|
2438
2528
|
/**
|
|
2439
2529
|
* Helper type to help users adopt to Lson types from interface definitions.
|
|
2440
2530
|
* You should only use this to wrap interfaces you don't control. For more
|
|
@@ -2447,4 +2537,4 @@ declare type EnsureJson<T> = [
|
|
|
2447
2537
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
2448
2538
|
};
|
|
2449
2539
|
|
|
2450
|
-
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, Brand, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CommentsApiError, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IUserInfo, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
|
2540
|
+
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, Brand, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyResolveUsersArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentReaction, CommentsApi, CommentsApiError, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IUserInfo, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, getMentionedIdsFromCommentBody, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, stringifyCommentBody, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
package/dist/index.d.ts
CHANGED
|
@@ -2007,8 +2007,8 @@ declare function assert(condition: boolean, errmsg: string): asserts condition;
|
|
|
2007
2007
|
*/
|
|
2008
2008
|
declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
|
|
2009
2009
|
|
|
2010
|
-
declare type PromiseOrNot<T> = T | Promise<T>;
|
|
2011
|
-
declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot<T>;
|
|
2010
|
+
declare type PromiseOrNot$1<T> = T | Promise<T>;
|
|
2011
|
+
declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot$1<T>;
|
|
2012
2012
|
declare type AsyncCacheOptions<T, E> = {
|
|
2013
2013
|
isStateEqual?: (a: AsyncState<T, E>, b: AsyncState<T, E>) => boolean;
|
|
2014
2014
|
};
|
|
@@ -2435,6 +2435,96 @@ declare namespace protocol {
|
|
|
2435
2435
|
};
|
|
2436
2436
|
}
|
|
2437
2437
|
|
|
2438
|
+
declare type PromiseOrNot<T> = T | Promise<T>;
|
|
2439
|
+
declare type CommentBodyResolveUsersArgs = {
|
|
2440
|
+
/**
|
|
2441
|
+
* The ID of the users to resolve.
|
|
2442
|
+
*/
|
|
2443
|
+
userIds: string[];
|
|
2444
|
+
};
|
|
2445
|
+
declare type CommentBodyParagraphElementArgs = {
|
|
2446
|
+
/**
|
|
2447
|
+
* The paragraph element.
|
|
2448
|
+
*/
|
|
2449
|
+
element: CommentBodyParagraph;
|
|
2450
|
+
/**
|
|
2451
|
+
* The text content of the paragraph.
|
|
2452
|
+
*/
|
|
2453
|
+
children: string;
|
|
2454
|
+
};
|
|
2455
|
+
declare type CommentBodyTextElementArgs = {
|
|
2456
|
+
/**
|
|
2457
|
+
* The text element.
|
|
2458
|
+
*/
|
|
2459
|
+
element: CommentBodyText;
|
|
2460
|
+
};
|
|
2461
|
+
declare type CommentBodyLinkElementArgs = {
|
|
2462
|
+
/**
|
|
2463
|
+
* The link element.
|
|
2464
|
+
*/
|
|
2465
|
+
element: CommentBodyLink;
|
|
2466
|
+
/**
|
|
2467
|
+
* The absolute URL of the link.
|
|
2468
|
+
*/
|
|
2469
|
+
href: string;
|
|
2470
|
+
};
|
|
2471
|
+
declare type CommentBodyMentionElementArgs<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
2472
|
+
/**
|
|
2473
|
+
* The mention element.
|
|
2474
|
+
*/
|
|
2475
|
+
element: CommentBodyMention;
|
|
2476
|
+
/**
|
|
2477
|
+
* The mention's user info, if the `resolvedUsers` option was provided.
|
|
2478
|
+
*/
|
|
2479
|
+
user?: TUserMeta["info"];
|
|
2480
|
+
};
|
|
2481
|
+
declare type StringifyCommentBodyElements<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
2482
|
+
/**
|
|
2483
|
+
* The element used to display paragraphs.
|
|
2484
|
+
*/
|
|
2485
|
+
paragraph: (args: CommentBodyParagraphElementArgs, index: number) => string;
|
|
2486
|
+
/**
|
|
2487
|
+
* The element used to display text elements.
|
|
2488
|
+
*/
|
|
2489
|
+
text: (args: CommentBodyTextElementArgs, index: number) => string;
|
|
2490
|
+
/**
|
|
2491
|
+
* The element used to display links.
|
|
2492
|
+
*/
|
|
2493
|
+
link: (args: CommentBodyLinkElementArgs, index: number) => string;
|
|
2494
|
+
/**
|
|
2495
|
+
* The element used to display mentions.
|
|
2496
|
+
*/
|
|
2497
|
+
mention: (args: CommentBodyMentionElementArgs<TUserMeta>, index: number) => string;
|
|
2498
|
+
};
|
|
2499
|
+
declare type StringifyCommentBodyOptions<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
2500
|
+
/**
|
|
2501
|
+
* Which format to convert the comment to.
|
|
2502
|
+
*/
|
|
2503
|
+
format?: "plain" | "html" | "markdown";
|
|
2504
|
+
/**
|
|
2505
|
+
* The elements used to customize the resulting string. Each element has
|
|
2506
|
+
* priority over the defaults inherited from the `format` option.
|
|
2507
|
+
*/
|
|
2508
|
+
elements?: Partial<StringifyCommentBodyElements<TUserMeta>>;
|
|
2509
|
+
/**
|
|
2510
|
+
* The separator used between paragraphs.
|
|
2511
|
+
*/
|
|
2512
|
+
separator?: string;
|
|
2513
|
+
/**
|
|
2514
|
+
* A function that returns user info from user IDs.
|
|
2515
|
+
*/
|
|
2516
|
+
resolveUsers?: (args: CommentBodyResolveUsersArgs) => PromiseOrNot<(TUserMeta["info"] | undefined)[] | undefined>;
|
|
2517
|
+
};
|
|
2518
|
+
/**
|
|
2519
|
+
* Get an array of each user's ID that has been mentioned in a `CommentBody`.
|
|
2520
|
+
*/
|
|
2521
|
+
declare function getMentionedIdsFromCommentBody(body: CommentBody): string[];
|
|
2522
|
+
/**
|
|
2523
|
+
* Convert a `CommentBody` into either a plain string,
|
|
2524
|
+
* Markdown, HTML, or a custom format.
|
|
2525
|
+
*/
|
|
2526
|
+
declare function stringifyCommentBody<TUserMeta extends BaseUserMeta = BaseUserMeta>(body: CommentBody, options?: StringifyCommentBodyOptions<TUserMeta>): Promise<string>;
|
|
2527
|
+
|
|
2438
2528
|
/**
|
|
2439
2529
|
* Helper type to help users adopt to Lson types from interface definitions.
|
|
2440
2530
|
* You should only use this to wrap interfaces you don't control. For more
|
|
@@ -2447,4 +2537,4 @@ declare type EnsureJson<T> = [
|
|
|
2447
2537
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
2448
2538
|
};
|
|
2449
2539
|
|
|
2450
|
-
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, Brand, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CommentsApiError, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IUserInfo, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
|
2540
|
+
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, Brand, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyResolveUsersArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentReaction, CommentsApi, CommentsApiError, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IUserInfo, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, getMentionedIdsFromCommentBody, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, stringifyCommentBody, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
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 = "1.8.
|
|
9
|
+
var PKG_VERSION = "1.8.2";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3065,7 +3065,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3065
3065
|
_optionalChain([this, 'access', _82 => _82._pool, 'optionalAccess', _83 => _83.assertStorageIsWritable, 'call', _84 => _84()]);
|
|
3066
3066
|
if (index < 0 || index >= this._items.length) {
|
|
3067
3067
|
throw new Error(
|
|
3068
|
-
`Cannot delete list item at index "
|
|
3068
|
+
`Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
3069
3069
|
);
|
|
3070
3070
|
}
|
|
3071
3071
|
const item = this._items[index];
|
|
@@ -5751,7 +5751,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5751
5751
|
return returnValue;
|
|
5752
5752
|
}
|
|
5753
5753
|
function pauseHistory() {
|
|
5754
|
-
context.pausedHistory
|
|
5754
|
+
if (context.pausedHistory === null) {
|
|
5755
|
+
context.pausedHistory = [];
|
|
5756
|
+
}
|
|
5755
5757
|
}
|
|
5756
5758
|
function resumeHistory() {
|
|
5757
5759
|
const historyOps = context.pausedHistory;
|
|
@@ -6168,10 +6170,9 @@ function toPlainLson(lson) {
|
|
|
6168
6170
|
return {
|
|
6169
6171
|
liveblocksType: "LiveObject",
|
|
6170
6172
|
data: Object.fromEntries(
|
|
6171
|
-
Object.entries(lson.toObject()).
|
|
6172
|
-
key,
|
|
6173
|
-
|
|
6174
|
-
])
|
|
6173
|
+
Object.entries(lson.toObject()).flatMap(
|
|
6174
|
+
([key, value]) => value !== void 0 ? [[key, toPlainLson(value)]] : []
|
|
6175
|
+
)
|
|
6175
6176
|
)
|
|
6176
6177
|
};
|
|
6177
6178
|
} else if (lson instanceof LiveMap) {
|
|
@@ -6753,6 +6754,315 @@ function stringify(object, ...args) {
|
|
|
6753
6754
|
return JSON.stringify(sortedObject, ...args);
|
|
6754
6755
|
}
|
|
6755
6756
|
|
|
6757
|
+
// src/comments/comment-body.ts
|
|
6758
|
+
function isCommentBodyParagraph(element) {
|
|
6759
|
+
return "type" in element && element.type === "mention";
|
|
6760
|
+
}
|
|
6761
|
+
function isCommentBodyText(element) {
|
|
6762
|
+
return "text" in element && typeof element.text === "string";
|
|
6763
|
+
}
|
|
6764
|
+
function isCommentBodyMention(element) {
|
|
6765
|
+
return "type" in element && element.type === "mention";
|
|
6766
|
+
}
|
|
6767
|
+
function isCommentBodyLink(element) {
|
|
6768
|
+
return "type" in element && element.type === "link";
|
|
6769
|
+
}
|
|
6770
|
+
var commentBodyElementsGuards = {
|
|
6771
|
+
paragraph: isCommentBodyParagraph,
|
|
6772
|
+
text: isCommentBodyText,
|
|
6773
|
+
link: isCommentBodyLink,
|
|
6774
|
+
mention: isCommentBodyMention
|
|
6775
|
+
};
|
|
6776
|
+
var commentBodyElementsTypes = {
|
|
6777
|
+
paragraph: "block",
|
|
6778
|
+
text: "inline",
|
|
6779
|
+
link: "inline",
|
|
6780
|
+
mention: "inline"
|
|
6781
|
+
};
|
|
6782
|
+
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
6783
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _164 => _164.content])) {
|
|
6784
|
+
return;
|
|
6785
|
+
}
|
|
6786
|
+
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
6787
|
+
const type = element ? commentBodyElementsTypes[element] : "all";
|
|
6788
|
+
const guard = element ? commentBodyElementsGuards[element] : () => true;
|
|
6789
|
+
const visitor = typeof elementOrVisitor === "function" ? elementOrVisitor : possiblyVisitor;
|
|
6790
|
+
for (const block of body.content) {
|
|
6791
|
+
if (type === "all" || type === "block") {
|
|
6792
|
+
if (guard(block)) {
|
|
6793
|
+
_optionalChain([visitor, 'optionalCall', _165 => _165(block)]);
|
|
6794
|
+
}
|
|
6795
|
+
}
|
|
6796
|
+
if (type === "all" || type === "inline") {
|
|
6797
|
+
for (const inline of block.children) {
|
|
6798
|
+
if (guard(inline)) {
|
|
6799
|
+
_optionalChain([visitor, 'optionalCall', _166 => _166(inline)]);
|
|
6800
|
+
}
|
|
6801
|
+
}
|
|
6802
|
+
}
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6805
|
+
function getMentionedIdsFromCommentBody(body) {
|
|
6806
|
+
const mentionedIds = /* @__PURE__ */ new Set();
|
|
6807
|
+
traverseCommentBody(
|
|
6808
|
+
body,
|
|
6809
|
+
"mention",
|
|
6810
|
+
(mention) => mentionedIds.add(mention.id)
|
|
6811
|
+
);
|
|
6812
|
+
return Array.from(mentionedIds);
|
|
6813
|
+
}
|
|
6814
|
+
async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
6815
|
+
const resolvedUsers = /* @__PURE__ */ new Map();
|
|
6816
|
+
if (!resolveUsers) {
|
|
6817
|
+
return resolvedUsers;
|
|
6818
|
+
}
|
|
6819
|
+
const userIds = getMentionedIdsFromCommentBody(body);
|
|
6820
|
+
const users = await resolveUsers({
|
|
6821
|
+
userIds
|
|
6822
|
+
});
|
|
6823
|
+
for (const [index, userId] of userIds.entries()) {
|
|
6824
|
+
const user = _optionalChain([users, 'optionalAccess', _167 => _167[index]]);
|
|
6825
|
+
if (user) {
|
|
6826
|
+
resolvedUsers.set(userId, user);
|
|
6827
|
+
}
|
|
6828
|
+
}
|
|
6829
|
+
return resolvedUsers;
|
|
6830
|
+
}
|
|
6831
|
+
var htmlEscapables = {
|
|
6832
|
+
"&": "&",
|
|
6833
|
+
"<": "<",
|
|
6834
|
+
">": ">",
|
|
6835
|
+
'"': """,
|
|
6836
|
+
"'": "'"
|
|
6837
|
+
};
|
|
6838
|
+
var htmlEscapablesRegex = new RegExp(
|
|
6839
|
+
Object.keys(htmlEscapables).map((entity) => `\\${entity}`).join("|"),
|
|
6840
|
+
"g"
|
|
6841
|
+
);
|
|
6842
|
+
function htmlSafe(value) {
|
|
6843
|
+
return new HtmlSafeString([String(value)], []);
|
|
6844
|
+
}
|
|
6845
|
+
function joinHtml(strings) {
|
|
6846
|
+
if (strings.length <= 0) {
|
|
6847
|
+
return new HtmlSafeString([""], []);
|
|
6848
|
+
}
|
|
6849
|
+
return new HtmlSafeString(
|
|
6850
|
+
["", ...Array(strings.length - 1).fill(""), ""],
|
|
6851
|
+
strings
|
|
6852
|
+
);
|
|
6853
|
+
}
|
|
6854
|
+
function escapeHtml(value) {
|
|
6855
|
+
if (value instanceof HtmlSafeString) {
|
|
6856
|
+
return value.toString();
|
|
6857
|
+
}
|
|
6858
|
+
if (Array.isArray(value)) {
|
|
6859
|
+
return joinHtml(value).toString();
|
|
6860
|
+
}
|
|
6861
|
+
return String(value).replace(
|
|
6862
|
+
htmlEscapablesRegex,
|
|
6863
|
+
(character) => htmlEscapables[character]
|
|
6864
|
+
);
|
|
6865
|
+
}
|
|
6866
|
+
var HtmlSafeString = class {
|
|
6867
|
+
constructor(strings, values) {
|
|
6868
|
+
this._strings = strings;
|
|
6869
|
+
this._values = values;
|
|
6870
|
+
}
|
|
6871
|
+
toString() {
|
|
6872
|
+
return this._strings.reduce((result, str, i) => {
|
|
6873
|
+
return result + escapeHtml(nn(this._values[i - 1])) + str;
|
|
6874
|
+
});
|
|
6875
|
+
}
|
|
6876
|
+
};
|
|
6877
|
+
function html(strings, ...values) {
|
|
6878
|
+
return new HtmlSafeString(strings, values);
|
|
6879
|
+
}
|
|
6880
|
+
var markdownEscapables = {
|
|
6881
|
+
_: "\\_",
|
|
6882
|
+
"*": "\\*",
|
|
6883
|
+
"#": "\\#",
|
|
6884
|
+
"`": "\\`",
|
|
6885
|
+
"~": "\\~",
|
|
6886
|
+
"!": "\\!",
|
|
6887
|
+
"|": "\\|",
|
|
6888
|
+
"(": "\\(",
|
|
6889
|
+
")": "\\)",
|
|
6890
|
+
"{": "\\{",
|
|
6891
|
+
"}": "\\}",
|
|
6892
|
+
"[": "\\[",
|
|
6893
|
+
"]": "\\]"
|
|
6894
|
+
};
|
|
6895
|
+
var markdownEscapablesRegex = new RegExp(
|
|
6896
|
+
Object.keys(markdownEscapables).map((entity) => `\\${entity}`).join("|"),
|
|
6897
|
+
"g"
|
|
6898
|
+
);
|
|
6899
|
+
function joinMarkdown(strings) {
|
|
6900
|
+
if (strings.length <= 0) {
|
|
6901
|
+
return new MarkdownSafeString([""], []);
|
|
6902
|
+
}
|
|
6903
|
+
return new MarkdownSafeString(
|
|
6904
|
+
["", ...Array(strings.length - 1).fill(""), ""],
|
|
6905
|
+
strings
|
|
6906
|
+
);
|
|
6907
|
+
}
|
|
6908
|
+
function escapeMarkdown(value) {
|
|
6909
|
+
if (value instanceof MarkdownSafeString) {
|
|
6910
|
+
return value.toString();
|
|
6911
|
+
}
|
|
6912
|
+
if (Array.isArray(value)) {
|
|
6913
|
+
return joinMarkdown(value).toString();
|
|
6914
|
+
}
|
|
6915
|
+
return String(value).replace(
|
|
6916
|
+
markdownEscapablesRegex,
|
|
6917
|
+
(character) => markdownEscapables[character]
|
|
6918
|
+
);
|
|
6919
|
+
}
|
|
6920
|
+
var MarkdownSafeString = class {
|
|
6921
|
+
constructor(strings, values) {
|
|
6922
|
+
this._strings = strings;
|
|
6923
|
+
this._values = values;
|
|
6924
|
+
}
|
|
6925
|
+
toString() {
|
|
6926
|
+
return this._strings.reduce((result, str, i) => {
|
|
6927
|
+
return result + escapeMarkdown(nn(this._values[i - 1])) + str;
|
|
6928
|
+
});
|
|
6929
|
+
}
|
|
6930
|
+
};
|
|
6931
|
+
function markdown(strings, ...values) {
|
|
6932
|
+
return new MarkdownSafeString(strings, values);
|
|
6933
|
+
}
|
|
6934
|
+
function toAbsoluteUrl(url) {
|
|
6935
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
6936
|
+
return url;
|
|
6937
|
+
} else if (url.startsWith("www.")) {
|
|
6938
|
+
return "https://" + url;
|
|
6939
|
+
}
|
|
6940
|
+
return;
|
|
6941
|
+
}
|
|
6942
|
+
var stringifyCommentBodyPlainElements = {
|
|
6943
|
+
paragraph: ({ children }) => children,
|
|
6944
|
+
text: ({ element }) => element.text,
|
|
6945
|
+
link: ({ element }) => element.url,
|
|
6946
|
+
mention: ({ element, user }) => {
|
|
6947
|
+
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _168 => _168.name]), () => ( element.id))}`;
|
|
6948
|
+
}
|
|
6949
|
+
};
|
|
6950
|
+
var stringifyCommentBodyHtmlElements = {
|
|
6951
|
+
paragraph: ({ children }) => {
|
|
6952
|
+
return children ? html`<p>${htmlSafe(children)}</p>` : children;
|
|
6953
|
+
},
|
|
6954
|
+
text: ({ element }) => {
|
|
6955
|
+
let children = element.text;
|
|
6956
|
+
if (!children) {
|
|
6957
|
+
return children;
|
|
6958
|
+
}
|
|
6959
|
+
if (element.bold) {
|
|
6960
|
+
children = html`<strong>${children}</strong>`;
|
|
6961
|
+
}
|
|
6962
|
+
if (element.italic) {
|
|
6963
|
+
children = html`<em>${children}</em>`;
|
|
6964
|
+
}
|
|
6965
|
+
if (element.strikethrough) {
|
|
6966
|
+
children = html`<s>${children}</s>`;
|
|
6967
|
+
}
|
|
6968
|
+
if (element.code) {
|
|
6969
|
+
children = html`<code>${children}</code>`;
|
|
6970
|
+
}
|
|
6971
|
+
return children;
|
|
6972
|
+
},
|
|
6973
|
+
link: ({ element, href }) => {
|
|
6974
|
+
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.url}</a>`;
|
|
6975
|
+
},
|
|
6976
|
+
mention: ({ element, user }) => {
|
|
6977
|
+
return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _169 => _169.name]), () => ( element.id))}</span>`;
|
|
6978
|
+
}
|
|
6979
|
+
};
|
|
6980
|
+
var stringifyCommentBodyMarkdownElements = {
|
|
6981
|
+
paragraph: ({ children }) => {
|
|
6982
|
+
return children;
|
|
6983
|
+
},
|
|
6984
|
+
text: ({ element }) => {
|
|
6985
|
+
let children = element.text;
|
|
6986
|
+
if (!children) {
|
|
6987
|
+
return children;
|
|
6988
|
+
}
|
|
6989
|
+
if (element.bold) {
|
|
6990
|
+
children = markdown`**${children}**`;
|
|
6991
|
+
}
|
|
6992
|
+
if (element.italic) {
|
|
6993
|
+
children = markdown`_${children}_`;
|
|
6994
|
+
}
|
|
6995
|
+
if (element.strikethrough) {
|
|
6996
|
+
children = markdown`~~${children}~~`;
|
|
6997
|
+
}
|
|
6998
|
+
if (element.code) {
|
|
6999
|
+
children = markdown`\`${children}\``;
|
|
7000
|
+
}
|
|
7001
|
+
return children;
|
|
7002
|
+
},
|
|
7003
|
+
link: ({ element, href }) => {
|
|
7004
|
+
return markdown`[${element.url}](${href})`;
|
|
7005
|
+
},
|
|
7006
|
+
mention: ({ element, user }) => {
|
|
7007
|
+
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _170 => _170.name]), () => ( element.id))}`;
|
|
7008
|
+
}
|
|
7009
|
+
};
|
|
7010
|
+
async function stringifyCommentBody(body, options) {
|
|
7011
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _171 => _171.format]), () => ( "plain"));
|
|
7012
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _172 => _172.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
7013
|
+
const elements = {
|
|
7014
|
+
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
7015
|
+
..._optionalChain([options, 'optionalAccess', _173 => _173.elements])
|
|
7016
|
+
};
|
|
7017
|
+
const resolvedUsers = await resolveUsersInCommentBody(
|
|
7018
|
+
body,
|
|
7019
|
+
_optionalChain([options, 'optionalAccess', _174 => _174.resolveUsers])
|
|
7020
|
+
);
|
|
7021
|
+
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
7022
|
+
switch (block.type) {
|
|
7023
|
+
case "paragraph": {
|
|
7024
|
+
const inlines = block.children.flatMap((inline, inlineIndex) => {
|
|
7025
|
+
if (isCommentBodyMention(inline)) {
|
|
7026
|
+
return inline.id ? [
|
|
7027
|
+
elements.mention(
|
|
7028
|
+
{
|
|
7029
|
+
element: inline,
|
|
7030
|
+
user: resolvedUsers.get(inline.id)
|
|
7031
|
+
},
|
|
7032
|
+
inlineIndex
|
|
7033
|
+
)
|
|
7034
|
+
] : [];
|
|
7035
|
+
}
|
|
7036
|
+
if (isCommentBodyLink(inline)) {
|
|
7037
|
+
return [
|
|
7038
|
+
elements.link(
|
|
7039
|
+
{
|
|
7040
|
+
element: inline,
|
|
7041
|
+
href: _nullishCoalesce(toAbsoluteUrl(inline.url), () => ( inline.url))
|
|
7042
|
+
},
|
|
7043
|
+
inlineIndex
|
|
7044
|
+
)
|
|
7045
|
+
];
|
|
7046
|
+
}
|
|
7047
|
+
if (isCommentBodyText(inline)) {
|
|
7048
|
+
return [elements.text({ element: inline }, inlineIndex)];
|
|
7049
|
+
}
|
|
7050
|
+
return [];
|
|
7051
|
+
});
|
|
7052
|
+
return [
|
|
7053
|
+
elements.paragraph(
|
|
7054
|
+
{ element: block, children: inlines.join("") },
|
|
7055
|
+
blockIndex
|
|
7056
|
+
)
|
|
7057
|
+
];
|
|
7058
|
+
}
|
|
7059
|
+
default:
|
|
7060
|
+
return [];
|
|
7061
|
+
}
|
|
7062
|
+
});
|
|
7063
|
+
return blocks.join(separator);
|
|
7064
|
+
}
|
|
7065
|
+
|
|
6756
7066
|
// src/index.ts
|
|
6757
7067
|
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
6758
7068
|
|
|
@@ -6800,5 +7110,7 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
6800
7110
|
|
|
6801
7111
|
|
|
6802
7112
|
|
|
6803
|
-
|
|
7113
|
+
|
|
7114
|
+
|
|
7115
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.cloneLson = cloneLson; exports.console = fancy_console_exports; exports.createAsyncCache = createAsyncCache; exports.createClient = createClient; exports.createCommentsApi = createCommentsApi; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
|
|
6804
7116
|
//# sourceMappingURL=index.js.map
|