@liveblocks/emails 2.21.0-emails2 → 2.21.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.d.cts CHANGED
@@ -1,16 +1,9 @@
1
- import { BaseUserMeta, DU, ResolveUsersArgs, Awaitable, DRI, CommentBodyParagraph, CommentBodyText, CommentBodyLink, CommentBodyMention } from '@liveblocks/core';
1
+ import { CommentBodyText, CommentBodyLink, BaseUserMeta, DU, CommentBodyMention, ResolveUsersArgs, Awaitable, DRI, CommentBody } from '@liveblocks/core';
2
2
  export { ResolveUsersArgs } from '@liveblocks/core';
3
3
  import { ReactNode, ComponentType } from 'react';
4
4
  import { Properties } from 'csstype';
5
5
  import { Liveblocks, TextMentionNotificationEvent, ThreadNotificationEvent } from '@liveblocks/node';
6
6
 
7
- type ResolveRoomInfoArgs = {
8
- /**
9
- * The ID of the room to resolve
10
- */
11
- roomId: string;
12
- };
13
-
14
7
  /**
15
8
  * CSS properties object.
16
9
  * Type alias for DX purposes.
@@ -18,6 +11,97 @@ type ResolveRoomInfoArgs = {
18
11
  */
19
12
  type CSSProperties = Properties;
20
13
 
14
+ type CommentBodyContainerComponentProps = {
15
+ /**
16
+ * The blocks of the comment body
17
+ */
18
+ children: ReactNode;
19
+ };
20
+ type CommentBodyParagraphComponentProps = {
21
+ /**
22
+ * The text content of the paragraph.
23
+ */
24
+ children: ReactNode;
25
+ };
26
+ type CommentBodyTextComponentProps = {
27
+ /**
28
+ * The text element.
29
+ */
30
+ element: CommentBodyText;
31
+ };
32
+ type CommentBodyLinkComponentProps = {
33
+ /**
34
+ * The link element.
35
+ */
36
+ element: CommentBodyLink;
37
+ /**
38
+ * The absolute URL of the link.
39
+ */
40
+ href: string;
41
+ };
42
+ type CommentBodyMentionComponentProps<U extends BaseUserMeta = DU> = {
43
+ /**
44
+ * The mention element.
45
+ */
46
+ element: CommentBodyMention;
47
+ /**
48
+ * The mention's user info, if the `resolvedUsers` option was provided.
49
+ */
50
+ user?: U["info"];
51
+ };
52
+ type ConvertCommentBodyAsReactComponents<U extends BaseUserMeta = DU> = {
53
+ /**
54
+ *
55
+ * The component used to act as a container to wrap comment body blocks,
56
+ */
57
+ Container: ComponentType<CommentBodyContainerComponentProps>;
58
+ /**
59
+ * The component used to display paragraphs.
60
+ */
61
+ Paragraph: ComponentType<CommentBodyParagraphComponentProps>;
62
+ /**
63
+ * The component used to display text elements.
64
+ */
65
+ Text: ComponentType<CommentBodyTextComponentProps>;
66
+ /**
67
+ * The component used to display links.
68
+ */
69
+ Link: ComponentType<CommentBodyLinkComponentProps>;
70
+ /**
71
+ * The component used to display mentions.
72
+ */
73
+ Mention: ComponentType<CommentBodyMentionComponentProps<U>>;
74
+ };
75
+ type ConvertCommentBodyAsHtmlStyles = {
76
+ /**
77
+ * The default inline CSS styles used to display paragraphs.
78
+ */
79
+ paragraph: CSSProperties;
80
+ /**
81
+ * The default inline CSS styles used to display text `<strong />` elements.
82
+ */
83
+ strong: CSSProperties;
84
+ /**
85
+ * The default inline CSS styles used to display text `<code />` elements.
86
+ */
87
+ code: CSSProperties;
88
+ /**
89
+ * The default inline CSS styles used to display links.
90
+ */
91
+ mention: CSSProperties;
92
+ /**
93
+ * The default inline CSS styles used to display mentions.
94
+ */
95
+ link: CSSProperties;
96
+ };
97
+
98
+ type ResolveRoomInfoArgs = {
99
+ /**
100
+ * The ID of the room to resolve
101
+ */
102
+ roomId: string;
103
+ };
104
+
21
105
  /**
22
106
  * Liveblocks Text Editor
23
107
  *
@@ -209,149 +293,52 @@ type TextMentionNotificationEmailDataAsHtml = TextMentionNotificationEmailData<B
209
293
  */
210
294
  declare function prepareTextMentionNotificationEmailAsHtml(client: Liveblocks, event: TextMentionNotificationEvent, options?: PrepareTextMentionNotificationEmailAsHtmlOptions<BaseUserMeta>): Promise<TextMentionNotificationEmailDataAsHtml | null>;
211
295
 
212
- type CommentBodyContainerElementArgs<T> = {
213
- /**
214
- * The blocks of the comment body
215
- */
216
- children: T[];
217
- };
218
- type CommentBodyParagraphElementArgs<T> = {
219
- /**
220
- * The paragraph element.
221
- */
222
- element: CommentBodyParagraph;
223
- /**
224
- * The text content of the paragraph.
225
- */
226
- children: T[];
227
- };
228
- type CommentBodyTextElementArgs = {
229
- /**
230
- * The text element.
231
- */
232
- element: CommentBodyText;
233
- };
234
- type CommentBodyLinkElementArgs = {
235
- /**
236
- * The link element.
237
- */
238
- element: CommentBodyLink;
239
- /**
240
- * The absolute URL of the link.
241
- */
242
- href: string;
243
- };
244
- type CommentBodyMentionElementArgs<U extends BaseUserMeta = DU> = {
245
- /**
246
- * The mention element.
247
- */
248
- element: CommentBodyMention;
249
- /**
250
- * The mention's user info, if the `resolvedUsers` option was provided.
251
- */
252
- user?: U["info"];
253
- };
254
- /**
255
- * Protocol:
256
- * Comment body elements to be converted to a custom format `T`
257
- */
258
- type ConvertCommentBodyElements<T, U extends BaseUserMeta = DU> = {
259
- /**
260
- * The container element used to display comment body blocks.
261
- */
262
- container: (args: CommentBodyContainerElementArgs<T>) => T;
263
- /**
264
- * The paragraph element used to display paragraphs.
265
- */
266
- paragraph: (args: CommentBodyParagraphElementArgs<T>, index: number) => T;
267
- /**
268
- * The text element used to display text elements.
269
- */
270
- text: (args: CommentBodyTextElementArgs, index: number) => T;
271
- /**
272
- * The link element used to display links.
273
- */
274
- link: (args: CommentBodyLinkElementArgs, index: number) => T;
275
- /**
276
- * The mention element used to display mentions.
277
- */
278
- mention: (args: CommentBodyMentionElementArgs<U>, index: number) => T;
279
- };
280
-
281
- type CommentEmailData<BodyType, U extends BaseUserMeta = DU> = {
296
+ type CommentEmailBaseData = {
282
297
  id: string;
283
298
  threadId: string;
284
299
  roomId: string;
300
+ userId: string;
285
301
  createdAt: Date;
286
302
  url?: string;
303
+ rawBody: CommentBody;
304
+ };
305
+ type PrepareThreadNotificationEmailBaseDataOptions = {
306
+ /**
307
+ * A function that returns room info from room IDs.
308
+ */
309
+ resolveRoomInfo?: (args: ResolveRoomInfoArgs) => Awaitable<DRI | undefined>;
310
+ };
311
+ type CommentEmailAsHtmlData<U extends BaseUserMeta = DU> = Omit<CommentEmailBaseData, "userId" | "rawBody"> & {
312
+ author: U;
313
+ htmlBody: string;
314
+ };
315
+ type CommentEmailAsReactData<U extends BaseUserMeta = DU> = Omit<CommentEmailBaseData, "userId" | "rawBody"> & {
287
316
  author: U;
288
- body: BodyType;
317
+ reactBody: ReactNode;
289
318
  };
290
- type ThreadNotificationEmailData<BodyType, U extends BaseUserMeta = DU, C extends CommentEmailData<BodyType, U> = CommentEmailData<BodyType, U>> = ({
319
+ type ThreadNotificationEmailUnreadRepliesData<U extends BaseUserMeta, C extends CommentEmailAsHtmlData<U> | CommentEmailAsReactData<U>> = {
291
320
  type: "unreadReplies";
292
321
  comments: C[];
293
- } | {
322
+ };
323
+ type ThreadNotificationEmailUnreadMentionsData<U extends BaseUserMeta, C extends CommentEmailAsHtmlData<U> | CommentEmailAsReactData<U>> = {
294
324
  type: "unreadMention";
295
325
  comment: C;
296
- }) & {
297
- roomInfo: DRI;
298
- };
299
- type CommentEmailAsHtmlData<U extends BaseUserMeta = DU> = CommentEmailData<string, U> & {
300
- /** @deprecated Use `body` property instead. */
301
- htmlBody: string;
302
326
  };
303
- type CommentEmailAsReactData<U extends BaseUserMeta = DU> = CommentEmailData<ReactNode, U> & {
304
- /** @deprecated Use `body` property instead. */
305
- reactBody: ReactNode;
327
+ type ThreadNotificationEmailData<U extends BaseUserMeta, C extends CommentEmailAsHtmlData<U> | CommentEmailAsReactData<U>> = (ThreadNotificationEmailUnreadRepliesData<U, C> | ThreadNotificationEmailUnreadMentionsData<U, C>) & {
328
+ roomInfo: DRI;
306
329
  };
307
- type PrepareThreadNotificationEmailOptions<BodyType, U extends BaseUserMeta = DU> = {
308
- /**
309
- * A function that returns room info from room IDs.
310
- */
311
- resolveRoomInfo?: (args: ResolveRoomInfoArgs) => Awaitable<DRI | undefined>;
330
+ type PrepareThreadNotificationEmailAsHtmlOptions<U extends BaseUserMeta = DU> = PrepareThreadNotificationEmailBaseDataOptions & {
312
331
  /**
313
332
  * A function that returns info from user IDs.
314
333
  */
315
334
  resolveUsers?: (args: ResolveUsersArgs) => Awaitable<(U["info"] | undefined)[] | undefined>;
316
- /**
317
- * Comments body elements customizations.
318
- */
319
- elements: ConvertCommentBodyElements<BodyType, U>;
320
- };
321
- /**
322
- * The styles used to customize the html elements in the resulting html safe string.
323
- * Each styles has priority over the base styles inherited.
324
- */
325
- type ConvertCommentBodyAsHtmlStyles = {
326
- /**
327
- * The default inline CSS styles used to display paragraphs.
328
- */
329
- paragraph: CSSProperties;
330
- /**
331
- * The default inline CSS styles used to display text `<strong />` elements.
332
- */
333
- strong: CSSProperties;
334
- /**
335
- * The default inline CSS styles used to display text `<code />` elements.
336
- */
337
- code: CSSProperties;
338
- /**
339
- * The default inline CSS styles used to display links.
340
- */
341
- mention: CSSProperties;
342
- /**
343
- * The default inline CSS styles used to display mentions.
344
- */
345
- link: CSSProperties;
346
- };
347
- type PrepareThreadNotificationEmailAsHtmlOptions<BodyType, U extends BaseUserMeta = DU> = Omit<PrepareThreadNotificationEmailOptions<BodyType, U>, "elements"> & {
348
335
  /**
349
336
  * The styles used to customize the html elements in the resulting html safe string inside a comment body.
350
337
  * Each styles has priority over the base styles inherited.
351
338
  */
352
339
  styles?: Partial<ConvertCommentBodyAsHtmlStyles>;
353
340
  };
354
- type ThreadNotificationEmailDataAsHtml<U extends BaseUserMeta = DU> = ThreadNotificationEmailData<string, U, CommentEmailAsHtmlData<U>>;
341
+ type ThreadNotificationEmailDataAsHtml = ThreadNotificationEmailData<BaseUserMeta, CommentEmailAsHtmlData>;
355
342
  /**
356
343
  * Prepares data from a `ThreadNotificationEvent` and convert comment bodies as an html safe string.
357
344
  *
@@ -378,76 +365,19 @@ type ThreadNotificationEmailDataAsHtml<U extends BaseUserMeta = DU> = ThreadNoti
378
365
  * )
379
366
  *
380
367
  */
381
- declare function prepareThreadNotificationEmailAsHtml(client: Liveblocks, event: ThreadNotificationEvent, options?: PrepareThreadNotificationEmailAsHtmlOptions<string, BaseUserMeta>): Promise<ThreadNotificationEmailDataAsHtml | null>;
382
- type CommentBodyContainerComponentProps = {
383
- /**
384
- * The blocks of the comment body
385
- */
386
- children: ReactNode;
387
- };
388
- type CommentBodyParagraphComponentProps = {
389
- /**
390
- * The text content of the paragraph.
391
- */
392
- children: ReactNode;
393
- };
394
- type CommentBodyTextComponentProps = {
395
- /**
396
- * The text element.
397
- */
398
- element: CommentBodyText;
399
- };
400
- type CommentBodyLinkComponentProps = {
401
- /**
402
- * The link element.
403
- */
404
- element: CommentBodyLink;
405
- /**
406
- * The absolute URL of the link.
407
- */
408
- href: string;
409
- };
410
- type CommentBodyMentionComponentProps<U extends BaseUserMeta = DU> = {
368
+ declare function prepareThreadNotificationEmailAsHtml(client: Liveblocks, event: ThreadNotificationEvent, options?: PrepareThreadNotificationEmailAsHtmlOptions<BaseUserMeta>): Promise<ThreadNotificationEmailDataAsHtml | null>;
369
+ type PrepareThreadNotificationEmailAsReactOptions<U extends BaseUserMeta = DU> = PrepareThreadNotificationEmailBaseDataOptions & {
411
370
  /**
412
- * The mention element.
413
- */
414
- element: CommentBodyMention;
415
- /**
416
- * The mention's user info, if the `resolvedUsers` option was provided.
417
- */
418
- user?: U["info"];
419
- };
420
- type ConvertCommentBodyAsReactComponents<U extends BaseUserMeta = DU> = {
421
- /**
422
- *
423
- * The component used to act as a container to wrap comment body blocks,
424
- */
425
- Container: ComponentType<CommentBodyContainerComponentProps>;
426
- /**
427
- * The component used to display paragraphs.
428
- */
429
- Paragraph: ComponentType<CommentBodyParagraphComponentProps>;
430
- /**
431
- * The component used to display text elements.
432
- */
433
- Text: ComponentType<CommentBodyTextComponentProps>;
434
- /**
435
- * The component used to display links.
436
- */
437
- Link: ComponentType<CommentBodyLinkComponentProps>;
438
- /**
439
- * The component used to display mentions.
371
+ * A function that returns info from user IDs.
440
372
  */
441
- Mention: ComponentType<CommentBodyMentionComponentProps<U>>;
442
- };
443
- type PrepareThreadNotificationEmailAsReactOptions<BodyType, U extends BaseUserMeta = DU> = Omit<PrepareThreadNotificationEmailOptions<BodyType, U>, "elements"> & {
373
+ resolveUsers?: (args: ResolveUsersArgs) => Awaitable<(U["info"] | undefined)[] | undefined>;
444
374
  /**
445
375
  * The components used to customize the resulting React nodes inside a comment body.
446
376
  * Each components has priority over the base components inherited internally defined.
447
377
  */
448
378
  components?: Partial<ConvertCommentBodyAsReactComponents<U>>;
449
379
  };
450
- type ThreadNotificationEmailDataAsReact<U extends BaseUserMeta = DU> = ThreadNotificationEmailData<ReactNode, U, CommentEmailAsReactData<U>>;
380
+ type ThreadNotificationEmailDataAsReact = ThreadNotificationEmailData<BaseUserMeta, CommentEmailAsReactData>;
451
381
  /**
452
382
  * Prepares data from a `ThreadNotificationEvent` and convert comment bodies as React nodes.
453
383
  *