email-builder-utils 1.1.15 → 1.1.20

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.
@@ -1 +1 @@
1
- {"version":3,"file":"convertJsonToHtml.d.ts","sourceRoot":"","sources":["../../src/utils/convertJsonToHtml.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAU,UAAU,GAAG,oBA+EpD,CAAC"}
1
+ {"version":3,"file":"convertJsonToHtml.d.ts","sourceRoot":"","sources":["../../src/utils/convertJsonToHtml.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAU,UAAU,GAAG,oBAgFpD,CAAC"}
@@ -40,6 +40,7 @@ const convertJsonToHtml = async (jsonData) => {
40
40
  <center>
41
41
  <table
42
42
  class="responsive-table"
43
+ bgcolor="${canvasColor}"
43
44
  style="
44
45
  font-family: ${fontFamily};
45
46
  margin: 0 auto;
@@ -7,6 +7,7 @@ interface BlockJsonProps {
7
7
  text: string;
8
8
  altText: string;
9
9
  imageUrl: string;
10
+ responsive?: boolean;
10
11
  }
11
12
  interface IBlockData {
12
13
  type: BlockType;
@@ -1 +1 @@
1
- {"version":3,"file":"jsonToHTML.d.ts","sourceRoot":"","sources":["../../src/utils/jsonToHTML.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AASrC,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE;QACJ,KAAK,EAAE,cAAc,CAAC;QACtB,KAAK,EAAE,GAAG,CAAC;QACX,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;KAC7B,CAAC;CACH;AAYD,eAAO,MAAM,gBAAgB,kDAAkD,CAAC;AA2DhF,wBAAsB,aAAa,CACjC,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,GAAG,EACb,aAAa,EAAE,MAAM,mBAkBtB"}
1
+ {"version":3,"file":"jsonToHTML.d.ts","sourceRoot":"","sources":["../../src/utils/jsonToHTML.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AASrC,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE;QACJ,KAAK,EAAE,cAAc,CAAC;QACtB,KAAK,EAAE,GAAG,CAAC;QACX,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;KAC7B,CAAC;CACH;AAYD,eAAO,MAAM,gBAAgB,kDAAkD,CAAC;AA2DhF,wBAAsB,aAAa,CACjC,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,GAAG,EACb,aAAa,EAAE,MAAM,mBAkBtB"}
@@ -111,15 +111,40 @@ function convertSpacerBlockToHtml(blockData) {
111
111
  });
112
112
  return appendOutlookSupport(``, styles);
113
113
  }
114
+ // function convertTextBlock(blockData: IBlockData) {
115
+ // const { style, props } = blockData.data;
116
+ // const styles = buildStyles(style, {
117
+ // perChanges: [],
118
+ // pxChanges: allPxAttributes,
119
+ // });
120
+ // const text = props.text || "";
121
+ // const navigateToUrl = props.navigateToUrl || "";
122
+ // const textContent = appendOutlookSupport(
123
+ // text.replaceAll(/\n/g, "<br>"),
124
+ // styles
125
+ // );
126
+ // return navigateToUrl
127
+ // ? `<a href="${navigateToUrl}" rel="noreferrer noopener" style="color:inherit; text-decoration:none; cursor:pointer;">${textContent}</a>`
128
+ // : textContent;
129
+ // }
114
130
  function convertTextBlock(blockData) {
115
131
  const { style, props } = blockData.data;
116
- const styles = buildStyles(style, {
132
+ const { width, backgroundColor, padding, borderRadius, borderStyle, borderColor, borderWidth, textContainerBackgroundColor, textContainerPadding, ...rest } = style;
133
+ const textBoxStyle = { width, backgroundColor, padding, borderRadius, borderStyle, borderColor, borderWidth };
134
+ const convertedTextStyle = buildStyles(textBoxStyle, {
135
+ perChanges: [],
136
+ pxChanges: allPxAttributes,
137
+ });
138
+ const styles = buildStyles({ padding: textContainerPadding, backgroundColor: textContainerBackgroundColor, ...rest }, {
117
139
  perChanges: [],
118
140
  pxChanges: allPxAttributes,
119
141
  });
120
- const text = props.text || "";
142
+ const sanitizedText = (props.text ?? "")
143
+ .replaceAll(/<p>/g, "<div>")
144
+ .replaceAll(/<\/p>/g, "</div>");
121
145
  const navigateToUrl = props.navigateToUrl || "";
122
- const textContent = appendOutlookSupport(text.replaceAll(/\n/g, "<br>"), styles);
146
+ const convertedTextBox = `<div style="display: inline-block; max-width: 100%; box-sizing: border-box; ${convertedTextStyle}">${sanitizedText.replaceAll(/\n/g, "<br>")}</div>`;
147
+ const textContent = appendOutlookSupport(convertedTextBox, styles);
123
148
  return navigateToUrl
124
149
  ? `<a href="${navigateToUrl}" rel="noreferrer noopener" style="color:inherit; text-decoration:none; cursor:pointer;">${textContent}</a>`
125
150
  : textContent;
@@ -237,7 +262,7 @@ function convertButtonBlock(blockData) {
237
262
  perChanges: [],
238
263
  pxChanges: allPxAttributes,
239
264
  });
240
- const convertedStyles = buildStyles(rest, {
265
+ const convertedStyles = buildStyles({ maxWidth: "100%", boxSizing: "border-box", ...rest }, {
241
266
  perChanges: [],
242
267
  pxChanges: allPxAttributes,
243
268
  });
@@ -247,7 +272,7 @@ function convertButtonBlock(blockData) {
247
272
  }
248
273
  async function convertGridBlock(blockData, rootData, cellWidthInPx) {
249
274
  const { style = {}, childrenIds = [], props } = blockData.data;
250
- const { columns = 1, cellWidths = [] } = props;
275
+ const { columns = 1, cellWidths = [], responsive = true } = props;
251
276
  const { columnGap = 0, ...restStyle } = style;
252
277
  const tableStyles = buildStyles(restStyle, {
253
278
  perChanges: [],
@@ -271,20 +296,18 @@ async function convertGridBlock(blockData, rootData, cellWidthInPx) {
271
296
  const child = rootData[childId];
272
297
  const { style: cellStyle = {} } = child.data || {};
273
298
  const verticalAlign = cellStyle.verticalAlign || "top";
274
- const childHtml = child
275
- ? await convertGridCellBlock(child, rootData, widthPercent, cellWidthInPx)
276
- : "";
299
+ const { html: childHtml, styles } = await convertGridCellBlock(child, rootData, widthPercent, cellWidthInPx);
277
300
  html += `
278
- <td
279
- width="${widthPercent}%"
280
- class="stack-column"
281
- style="vertical-align:${verticalAlign}; padding:0; word-break:break-word;"
282
- >
283
- ${childHtml}
284
- </td>`;
301
+ <td
302
+ width="${widthPercent}%"
303
+ ${responsive ? 'class="stack-column"' : ""}
304
+ style="vertical-align:${verticalAlign}; padding:0; word-break:break-word; ${styles}"
305
+ >
306
+ ${childHtml}
307
+ </td>`;
285
308
  }
286
309
  else {
287
- html += `<td width="${widthPercent}%" class="stack-column" style="padding:0;"></td>`;
310
+ html += `<td width="${widthPercent}%" ${responsive ? 'class="stack-column"' : ""} style="padding:0;"></td>`;
288
311
  }
289
312
  }
290
313
  html += "</tr>";
@@ -306,20 +329,8 @@ async function convertGridCellBlock(blockData, rootData, cellWidthPercent, paren
306
329
  innerHtmlParts.push(await convertToHtml(child, rootData, cellWidthPx));
307
330
  }
308
331
  }
309
- const innerContent = innerHtmlParts.join("");
310
- return `
311
- <table
312
- role="presentation"
313
- border="0"
314
- cellpadding="0"
315
- cellspacing="0"
316
- width="100%"
317
- style="border-collapse:collapse;table-layout:fixed;${styles}"
318
- >
319
- <tr>
320
- <td style="padding:0;">
321
- ${innerContent}
322
- </td>
323
- </tr>
324
- </table>`;
332
+ return {
333
+ html: innerHtmlParts.join(""),
334
+ styles,
335
+ };
325
336
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-builder-utils",
3
- "version": "1.1.15",
3
+ "version": "1.1.20",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [