@liveblocks/emails 2.21.0-emails2 → 2.21.0-emails3

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,4 +1,4 @@
1
- import { BaseUserMeta, DU, ResolveUsersArgs, Awaitable, DRI, CommentBodyParagraph, CommentBodyText, CommentBodyLink, CommentBodyMention } from '@liveblocks/core';
1
+ import { BaseUserMeta, DU, ResolveUsersArgs, Awaitable, DRI, CommentBodyText, CommentBodyLink, CommentBodyMention } from '@liveblocks/core';
2
2
  export { ResolveUsersArgs } from '@liveblocks/core';
3
3
  import { ReactNode, ComponentType } from 'react';
4
4
  import { Properties } from 'csstype';
@@ -209,75 +209,6 @@ type TextMentionNotificationEmailDataAsHtml = TextMentionNotificationEmailData<B
209
209
  */
210
210
  declare function prepareTextMentionNotificationEmailAsHtml(client: Liveblocks, event: TextMentionNotificationEvent, options?: PrepareTextMentionNotificationEmailAsHtmlOptions<BaseUserMeta>): Promise<TextMentionNotificationEmailDataAsHtml | null>;
211
211
 
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
212
  type CommentEmailData<BodyType, U extends BaseUserMeta = DU> = {
282
213
  id: string;
283
214
  threadId: string;
@@ -304,7 +235,7 @@ type CommentEmailAsReactData<U extends BaseUserMeta = DU> = CommentEmailData<Rea
304
235
  /** @deprecated Use `body` property instead. */
305
236
  reactBody: ReactNode;
306
237
  };
307
- type PrepareThreadNotificationEmailOptions<BodyType, U extends BaseUserMeta = DU> = {
238
+ type PrepareThreadNotificationEmailOptions<U extends BaseUserMeta = DU> = {
308
239
  /**
309
240
  * A function that returns room info from room IDs.
310
241
  */
@@ -313,10 +244,6 @@ type PrepareThreadNotificationEmailOptions<BodyType, U extends BaseUserMeta = DU
313
244
  * A function that returns info from user IDs.
314
245
  */
315
246
  resolveUsers?: (args: ResolveUsersArgs) => Awaitable<(U["info"] | undefined)[] | undefined>;
316
- /**
317
- * Comments body elements customizations.
318
- */
319
- elements: ConvertCommentBodyElements<BodyType, U>;
320
247
  };
321
248
  /**
322
249
  * The styles used to customize the html elements in the resulting html safe string.
@@ -344,7 +271,7 @@ type ConvertCommentBodyAsHtmlStyles = {
344
271
  */
345
272
  link: CSSProperties;
346
273
  };
347
- type PrepareThreadNotificationEmailAsHtmlOptions<BodyType, U extends BaseUserMeta = DU> = Omit<PrepareThreadNotificationEmailOptions<BodyType, U>, "elements"> & {
274
+ type PrepareThreadNotificationEmailAsHtmlOptions<U extends BaseUserMeta = DU> = PrepareThreadNotificationEmailOptions<U> & {
348
275
  /**
349
276
  * The styles used to customize the html elements in the resulting html safe string inside a comment body.
350
277
  * Each styles has priority over the base styles inherited.
@@ -378,7 +305,7 @@ type ThreadNotificationEmailDataAsHtml<U extends BaseUserMeta = DU> = ThreadNoti
378
305
  * )
379
306
  *
380
307
  */
381
- declare function prepareThreadNotificationEmailAsHtml(client: Liveblocks, event: ThreadNotificationEvent, options?: PrepareThreadNotificationEmailAsHtmlOptions<string, BaseUserMeta>): Promise<ThreadNotificationEmailDataAsHtml | null>;
308
+ declare function prepareThreadNotificationEmailAsHtml(client: Liveblocks, event: ThreadNotificationEvent, options?: PrepareThreadNotificationEmailAsHtmlOptions<BaseUserMeta>): Promise<ThreadNotificationEmailDataAsHtml | null>;
382
309
  type CommentBodyContainerComponentProps = {
383
310
  /**
384
311
  * The blocks of the comment body
@@ -440,7 +367,7 @@ type ConvertCommentBodyAsReactComponents<U extends BaseUserMeta = DU> = {
440
367
  */
441
368
  Mention: ComponentType<CommentBodyMentionComponentProps<U>>;
442
369
  };
443
- type PrepareThreadNotificationEmailAsReactOptions<BodyType, U extends BaseUserMeta = DU> = Omit<PrepareThreadNotificationEmailOptions<BodyType, U>, "elements"> & {
370
+ type PrepareThreadNotificationEmailAsReactOptions<U extends BaseUserMeta = DU> = PrepareThreadNotificationEmailOptions<U> & {
444
371
  /**
445
372
  * The components used to customize the resulting React nodes inside a comment body.
446
373
  * Each components has priority over the base components inherited internally defined.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseUserMeta, DU, ResolveUsersArgs, Awaitable, DRI, CommentBodyParagraph, CommentBodyText, CommentBodyLink, CommentBodyMention } from '@liveblocks/core';
1
+ import { BaseUserMeta, DU, ResolveUsersArgs, Awaitable, DRI, CommentBodyText, CommentBodyLink, CommentBodyMention } from '@liveblocks/core';
2
2
  export { ResolveUsersArgs } from '@liveblocks/core';
3
3
  import { ReactNode, ComponentType } from 'react';
4
4
  import { Properties } from 'csstype';
@@ -209,75 +209,6 @@ type TextMentionNotificationEmailDataAsHtml = TextMentionNotificationEmailData<B
209
209
  */
210
210
  declare function prepareTextMentionNotificationEmailAsHtml(client: Liveblocks, event: TextMentionNotificationEvent, options?: PrepareTextMentionNotificationEmailAsHtmlOptions<BaseUserMeta>): Promise<TextMentionNotificationEmailDataAsHtml | null>;
211
211
 
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
212
  type CommentEmailData<BodyType, U extends BaseUserMeta = DU> = {
282
213
  id: string;
283
214
  threadId: string;
@@ -304,7 +235,7 @@ type CommentEmailAsReactData<U extends BaseUserMeta = DU> = CommentEmailData<Rea
304
235
  /** @deprecated Use `body` property instead. */
305
236
  reactBody: ReactNode;
306
237
  };
307
- type PrepareThreadNotificationEmailOptions<BodyType, U extends BaseUserMeta = DU> = {
238
+ type PrepareThreadNotificationEmailOptions<U extends BaseUserMeta = DU> = {
308
239
  /**
309
240
  * A function that returns room info from room IDs.
310
241
  */
@@ -313,10 +244,6 @@ type PrepareThreadNotificationEmailOptions<BodyType, U extends BaseUserMeta = DU
313
244
  * A function that returns info from user IDs.
314
245
  */
315
246
  resolveUsers?: (args: ResolveUsersArgs) => Awaitable<(U["info"] | undefined)[] | undefined>;
316
- /**
317
- * Comments body elements customizations.
318
- */
319
- elements: ConvertCommentBodyElements<BodyType, U>;
320
247
  };
321
248
  /**
322
249
  * The styles used to customize the html elements in the resulting html safe string.
@@ -344,7 +271,7 @@ type ConvertCommentBodyAsHtmlStyles = {
344
271
  */
345
272
  link: CSSProperties;
346
273
  };
347
- type PrepareThreadNotificationEmailAsHtmlOptions<BodyType, U extends BaseUserMeta = DU> = Omit<PrepareThreadNotificationEmailOptions<BodyType, U>, "elements"> & {
274
+ type PrepareThreadNotificationEmailAsHtmlOptions<U extends BaseUserMeta = DU> = PrepareThreadNotificationEmailOptions<U> & {
348
275
  /**
349
276
  * The styles used to customize the html elements in the resulting html safe string inside a comment body.
350
277
  * Each styles has priority over the base styles inherited.
@@ -378,7 +305,7 @@ type ThreadNotificationEmailDataAsHtml<U extends BaseUserMeta = DU> = ThreadNoti
378
305
  * )
379
306
  *
380
307
  */
381
- declare function prepareThreadNotificationEmailAsHtml(client: Liveblocks, event: ThreadNotificationEvent, options?: PrepareThreadNotificationEmailAsHtmlOptions<string, BaseUserMeta>): Promise<ThreadNotificationEmailDataAsHtml | null>;
308
+ declare function prepareThreadNotificationEmailAsHtml(client: Liveblocks, event: ThreadNotificationEvent, options?: PrepareThreadNotificationEmailAsHtmlOptions<BaseUserMeta>): Promise<ThreadNotificationEmailDataAsHtml | null>;
382
309
  type CommentBodyContainerComponentProps = {
383
310
  /**
384
311
  * The blocks of the comment body
@@ -440,7 +367,7 @@ type ConvertCommentBodyAsReactComponents<U extends BaseUserMeta = DU> = {
440
367
  */
441
368
  Mention: ComponentType<CommentBodyMentionComponentProps<U>>;
442
369
  };
443
- type PrepareThreadNotificationEmailAsReactOptions<BodyType, U extends BaseUserMeta = DU> = Omit<PrepareThreadNotificationEmailOptions<BodyType, U>, "elements"> & {
370
+ type PrepareThreadNotificationEmailAsReactOptions<U extends BaseUserMeta = DU> = PrepareThreadNotificationEmailOptions<U> & {
444
371
  /**
445
372
  * The components used to customize the resulting React nodes inside a comment body.
446
373
  * Each components has priority over the base components inherited internally defined.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { detectDupes } from "@liveblocks/core";
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/emails";
6
- var PKG_VERSION = "2.21.0-emails2";
6
+ var PKG_VERSION = "2.21.0-emails3";
7
7
  var PKG_FORMAT = "esm";
8
8
 
9
9
  // ../../node_modules/lib0/map.js
@@ -8500,7 +8500,7 @@ var extractThreadNotificationData = async ({
8500
8500
  comments: unreadComments
8501
8501
  };
8502
8502
  };
8503
- async function prepareThreadNotificationEmail(client, event, options) {
8503
+ async function prepareThreadNotificationEmail(client, event, options, elements, callerName) {
8504
8504
  const data = await extractThreadNotificationData({ client, event });
8505
8505
  if (data === null) {
8506
8506
  return null;
@@ -8512,7 +8512,7 @@ async function prepareThreadNotificationEmail(client, event, options) {
8512
8512
  };
8513
8513
  const batchUsersResolver = createBatchUsersResolver({
8514
8514
  resolveUsers: options.resolveUsers,
8515
- callerName: "prepareThreadNotificationEmail"
8515
+ callerName
8516
8516
  });
8517
8517
  switch (data.type) {
8518
8518
  case "unreadMention": {
@@ -8523,7 +8523,7 @@ async function prepareThreadNotificationEmail(client, event, options) {
8523
8523
  });
8524
8524
  const commentBodyPromise = convertCommentBody(comment.body, {
8525
8525
  resolveUsers: batchUsersResolver.resolveUsers,
8526
- elements: options.elements
8526
+ elements
8527
8527
  });
8528
8528
  await batchUsersResolver.resolve();
8529
8529
  const [authorsInfo, commentBody] = await Promise.all([
@@ -8561,7 +8561,7 @@ async function prepareThreadNotificationEmail(client, event, options) {
8561
8561
  const commentBodiesPromises = comments.map(
8562
8562
  (c) => convertCommentBody(c.body, {
8563
8563
  resolveUsers: batchUsersResolver.resolveUsers,
8564
- elements: options.elements
8564
+ elements
8565
8565
  })
8566
8566
  );
8567
8567
  await batchUsersResolver.resolve();
@@ -8623,40 +8623,41 @@ async function prepareThreadNotificationEmailAsHtml(client, event, options = {})
8623
8623
  event,
8624
8624
  {
8625
8625
  resolveUsers: options.resolveUsers,
8626
- resolveRoomInfo: options.resolveRoomInfo,
8627
- elements: {
8628
- container: ({ children }) => children.join("\n"),
8629
- paragraph: ({ children }) => {
8630
- const unsafe = children.join("");
8631
- return unsafe ? html2`<p style="${toInlineCSSString(styles.paragraph)}">${htmlSafe2(unsafe)}</p>` : unsafe;
8632
- },
8633
- text: ({ element }) => {
8634
- let children = element.text;
8635
- if (!children) {
8636
- return html2`${children}`;
8637
- }
8638
- if (element.bold) {
8639
- children = html2`<strong style="${toInlineCSSString(styles.strong)}">${children}</strong>`;
8640
- }
8641
- if (element.italic) {
8642
- children = html2`<em>${children}</em>`;
8643
- }
8644
- if (element.strikethrough) {
8645
- children = html2`<s>${children}</s>`;
8646
- }
8647
- if (element.code) {
8648
- children = html2`<code style="${toInlineCSSString(styles.code)}">${children}</code>`;
8649
- }
8626
+ resolveRoomInfo: options.resolveRoomInfo
8627
+ },
8628
+ {
8629
+ container: ({ children }) => children.join("\n"),
8630
+ paragraph: ({ children }) => {
8631
+ const unsafe = children.join("");
8632
+ return unsafe ? html2`<p style="${toInlineCSSString(styles.paragraph)}">${htmlSafe2(unsafe)}</p>` : unsafe;
8633
+ },
8634
+ text: ({ element }) => {
8635
+ let children = element.text;
8636
+ if (!children) {
8650
8637
  return html2`${children}`;
8651
- },
8652
- link: ({ element, href }) => {
8653
- return html2`<a href="${href}" target="_blank" rel="noopener noreferrer" style="${toInlineCSSString(styles.link)}">${element.text ? html2`${element.text}` : element.url}</a>`;
8654
- },
8655
- mention: ({ element, user }) => {
8656
- return html2`<span data-mention style="${toInlineCSSString(styles.mention)}">${MENTION_CHARACTER}${user?.name ? html2`${user?.name}` : element.id}</span>`;
8657
8638
  }
8639
+ if (element.bold) {
8640
+ children = html2`<strong style="${toInlineCSSString(styles.strong)}">${children}</strong>`;
8641
+ }
8642
+ if (element.italic) {
8643
+ children = html2`<em>${children}</em>`;
8644
+ }
8645
+ if (element.strikethrough) {
8646
+ children = html2`<s>${children}</s>`;
8647
+ }
8648
+ if (element.code) {
8649
+ children = html2`<code style="${toInlineCSSString(styles.code)}">${children}</code>`;
8650
+ }
8651
+ return html2`${children}`;
8652
+ },
8653
+ link: ({ element, href }) => {
8654
+ return html2`<a href="${href}" target="_blank" rel="noopener noreferrer" style="${toInlineCSSString(styles.link)}">${element.text ? html2`${element.text}` : element.url}</a>`;
8655
+ },
8656
+ mention: ({ element, user }) => {
8657
+ return html2`<span data-mention style="${toInlineCSSString(styles.mention)}">${MENTION_CHARACTER}${user?.name ? html2`${user?.name}` : element.id}</span>`;
8658
8658
  }
8659
- }
8659
+ },
8660
+ "prepareThreadNotificationEmailAsHtml"
8660
8661
  );
8661
8662
  if (data === null) {
8662
8663
  return null;
@@ -8711,35 +8712,36 @@ async function prepareThreadNotificationEmailAsReact(client, event, options = {}
8711
8712
  event,
8712
8713
  {
8713
8714
  resolveUsers: options.resolveUsers,
8714
- resolveRoomInfo: options.resolveRoomInfo,
8715
- elements: {
8716
- container: ({ children }) => /* @__PURE__ */ jsx2(Components.Container, { children }, "lb-comment-body-container"),
8717
- paragraph: ({ children }, index) => /* @__PURE__ */ jsx2(Components.Paragraph, { children }, `lb-comment-body-paragraph-${index}`),
8718
- text: ({ element }, index) => /* @__PURE__ */ jsx2(
8719
- Components.Text,
8720
- {
8721
- element
8722
- },
8723
- `lb-comment-body-text-${index}`
8724
- ),
8725
- link: ({ element, href }, index) => /* @__PURE__ */ jsx2(
8726
- Components.Link,
8727
- {
8728
- element,
8729
- href
8730
- },
8731
- `lb-comment-body-link-${index}`
8732
- ),
8733
- mention: ({ element, user }, index) => element.id ? /* @__PURE__ */ jsx2(
8734
- Components.Mention,
8735
- {
8736
- element,
8737
- user
8738
- },
8739
- `lb-comment-body-mention-${index}`
8740
- ) : null
8741
- }
8742
- }
8715
+ resolveRoomInfo: options.resolveRoomInfo
8716
+ },
8717
+ {
8718
+ container: ({ children }) => /* @__PURE__ */ jsx2(Components.Container, { children }, "lb-comment-body-container"),
8719
+ paragraph: ({ children }, index) => /* @__PURE__ */ jsx2(Components.Paragraph, { children }, `lb-comment-body-paragraph-${index}`),
8720
+ text: ({ element }, index) => /* @__PURE__ */ jsx2(
8721
+ Components.Text,
8722
+ {
8723
+ element
8724
+ },
8725
+ `lb-comment-body-text-${index}`
8726
+ ),
8727
+ link: ({ element, href }, index) => /* @__PURE__ */ jsx2(
8728
+ Components.Link,
8729
+ {
8730
+ element,
8731
+ href
8732
+ },
8733
+ `lb-comment-body-link-${index}`
8734
+ ),
8735
+ mention: ({ element, user }, index) => element.id ? /* @__PURE__ */ jsx2(
8736
+ Components.Mention,
8737
+ {
8738
+ element,
8739
+ user
8740
+ },
8741
+ `lb-comment-body-mention-${index}`
8742
+ ) : null
8743
+ },
8744
+ "prepareThreadNotificationEmailAsReact"
8743
8745
  );
8744
8746
  if (data === null) {
8745
8747
  return null;