@charisol/plexo-sdk 1.0.15 → 1.0.17
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/compiler.js +95 -42
- package/dist/compilerClient.js +2 -2
- package/dist/index.js +1164 -1051
- package/package.json +1 -1
package/dist/compiler.js
CHANGED
|
@@ -291,50 +291,103 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
291
291
|
if (typeof t != "string") return "";
|
|
292
292
|
let n = t.trim();
|
|
293
293
|
return n ? ` ${e}="${r(n)}"` : "";
|
|
294
|
-
}, a =
|
|
294
|
+
}, a = [
|
|
295
|
+
"fieldSpacing",
|
|
296
|
+
"buttonBackgroundColor",
|
|
297
|
+
"buttonTextColor",
|
|
298
|
+
"buttonBorderRadius",
|
|
299
|
+
"buttonPaddingTop",
|
|
300
|
+
"buttonPaddingBottom",
|
|
301
|
+
"buttonPaddingLeft",
|
|
302
|
+
"buttonPaddingRight",
|
|
303
|
+
"buttonFontSize",
|
|
304
|
+
"buttonFontWeight"
|
|
305
|
+
], o = (e) => {
|
|
295
306
|
if (!e || typeof e != "object") return "";
|
|
296
|
-
let
|
|
307
|
+
let n = e.kind || "text", i = r(e.name || e.label || "field"), a = e.required ? " required" : "", o = t({
|
|
308
|
+
fontSize: e.fontSize,
|
|
309
|
+
borderRadius: e.borderRadius,
|
|
310
|
+
borderWidth: e.borderWidth,
|
|
311
|
+
borderColor: e.borderColor,
|
|
312
|
+
borderStyle: "solid",
|
|
313
|
+
color: e.inputTextColor
|
|
314
|
+
}), s = e.showLabel === !1 ? "" : `<label style="display: block; margin-bottom: 4px; font-size: ${e.fontSize || "12px"}; font-weight: ${e.labelFontWeight || "700"}; color: ${e.labelColor || "inherit"};">${e.label || ""}${e.required ? " <span style=\"color:#e11d48;\">*</span>" : ""}</label>`;
|
|
315
|
+
return n === "textarea" ? `${s}<textarea name="${i}" placeholder="${r(e.placeholder || "")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${o}"${a}></textarea>` : n === "select" ? `${s}<select name="${i}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${o}"${a}>${(Array.isArray(e.options) ? e.options : []).map((e) => `<option value="${r(e?.value ?? "")}">${e?.label ?? e?.value ?? ""}</option>`).join("")}</select>` : n === "radio" || n === "checkbox" ? `${s}<div style="display: flex; flex-wrap: wrap; gap: 8px;">${(Array.isArray(e.options) && e.options.length > 0 ? e.options : [{
|
|
316
|
+
label: e.label || "Option",
|
|
317
|
+
value: e.name || "option"
|
|
318
|
+
}]).map((t) => `<label style="display: inline-flex; align-items: center; gap: 6px; font-size: ${e.fontSize || "12px"};"><input type="${n}" name="${i}" value="${r(t?.value ?? "")}" />${t?.label ?? t?.value ?? ""}</label>`).join("")}</div>` : `${s}<input type="${r(n)}" name="${i}" placeholder="${r(e.placeholder || "")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${o}"${a} />`;
|
|
319
|
+
}, s = (e) => {
|
|
320
|
+
if (!e || typeof e != "object") return "";
|
|
321
|
+
let i = e.style || {}, s = t(e.type === "form_container" ? {
|
|
297
322
|
...n(),
|
|
298
|
-
...
|
|
299
|
-
} :
|
|
323
|
+
...i
|
|
324
|
+
} : i), c = e.attributes || {};
|
|
300
325
|
switch (e.type) {
|
|
301
|
-
case "heading": return `<h2 style="margin-top: 0; margin-bottom: 8px; ${
|
|
302
|
-
case "paragraph": return `<p style="margin-top: 0; margin-bottom: 12px; ${
|
|
303
|
-
case "text": return `<div style="${
|
|
304
|
-
case "button": return `<div style="text-align: ${
|
|
326
|
+
case "heading": return `<h2 style="margin-top: 0; margin-bottom: 8px; ${s}">${c.text || "Heading"}</h2>`;
|
|
327
|
+
case "paragraph": return `<p style="margin-top: 0; margin-bottom: 12px; ${s}">${c.text || "Paragraph text content."}</p>`;
|
|
328
|
+
case "text": return `<div style="${s}">${c.text || ""}</div>`;
|
|
329
|
+
case "button": return `<div style="text-align: ${i.textAlign || "center"};"><a href="${c.href || "#"}" target="${c.openInNewTab ? "_blank" : "_self"}" style="display: inline-block; text-decoration: none; ${s}">${c.text || "Button"}</a></div>`;
|
|
305
330
|
case "image": {
|
|
306
|
-
let e =
|
|
307
|
-
return `<img src="${
|
|
331
|
+
let e = i.textAlign === "center" ? "margin: 0 auto; display: block;" : i.textAlign === "right" ? "margin-left: auto; display: block;" : "display: inline-block;";
|
|
332
|
+
return `<img src="${c.src || "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe"}" alt="${c.alt || ""}" style="${s} ${e}" />`;
|
|
308
333
|
}
|
|
309
|
-
case "divider": return `<hr style="border: 0; border-top: ${
|
|
310
|
-
case "spacer": return `<div style="height: ${
|
|
311
|
-
case "card": return `<div style="${
|
|
312
|
-
<h3 style="margin-top: 0; margin-bottom: 8px; color: #ffffff;">${
|
|
313
|
-
<p style="margin: 0; color: #94a3b8; font-size: 14px;">${
|
|
334
|
+
case "divider": return `<hr style="border: 0; border-top: ${i.borderWidth || "1px"} ${i.borderStyle || "solid"} ${i.borderColor || "#334155"}; ${s}" />`;
|
|
335
|
+
case "spacer": return `<div style="height: ${i.height || "24px"};"></div>`;
|
|
336
|
+
case "card": return `<div style="${s}">
|
|
337
|
+
<h3 style="margin-top: 0; margin-bottom: 8px; color: #ffffff;">${c.title || "Card Title"}</h3>
|
|
338
|
+
<p style="margin: 0; color: #94a3b8; font-size: 14px;">${c.description || "Card description."}</p>
|
|
314
339
|
</div>`;
|
|
340
|
+
case "form_container": {
|
|
341
|
+
let e = {
|
|
342
|
+
...n(),
|
|
343
|
+
...i
|
|
344
|
+
}, s = {};
|
|
345
|
+
for (let t of Object.keys(e)) a.includes(t) || (s[t] = e[t]);
|
|
346
|
+
let l = t(s), u = Array.isArray(c.fields) ? c.fields : [], d = e.fieldSpacing || "12px", f = u.map((e) => `<div style="margin-bottom: ${d};">${o(e)}</div>`).join(""), p = t({
|
|
347
|
+
backgroundColor: e.buttonBackgroundColor,
|
|
348
|
+
color: e.buttonTextColor,
|
|
349
|
+
borderRadius: e.buttonBorderRadius,
|
|
350
|
+
paddingTop: e.buttonPaddingTop,
|
|
351
|
+
paddingBottom: e.buttonPaddingBottom,
|
|
352
|
+
paddingLeft: e.buttonPaddingLeft,
|
|
353
|
+
paddingRight: e.buttonPaddingRight,
|
|
354
|
+
fontSize: e.buttonFontSize,
|
|
355
|
+
fontWeight: e.buttonFontWeight
|
|
356
|
+
});
|
|
357
|
+
return `<form action="${r(c.actionUrl || c.action || "#")}" method="${r(c.method || "POST")}" style="${l}">${f}<button type="submit" style="border: 0; cursor: pointer; ${p}">${c.submitLabel || "Submit"}</button></form>`;
|
|
358
|
+
}
|
|
359
|
+
case "input": {
|
|
360
|
+
let e = c.inputType || c.type || "text", t = r(c.name || c.fieldName || "field"), n = r(c.placeholder || ""), i = c.required ? " required" : "";
|
|
361
|
+
return `<input type="${r(e)}" name="${t}" placeholder="${n}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${s}"${i} />`;
|
|
362
|
+
}
|
|
363
|
+
case "textarea": return `<textarea name="${r(c.name || c.fieldName || "field")}" placeholder="${r(c.placeholder || "")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${s}"${c.required ? " required" : ""}></textarea>`;
|
|
364
|
+
case "select": return `<select name="${r(c.name || c.fieldName || "field")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${s}"${c.required ? " required" : ""}>${(Array.isArray(c.options) ? c.options : []).map((e) => `<option value="${r(e?.value ?? "")}">${e?.label ?? e?.value ?? ""}</option>`).join("")}</select>`;
|
|
365
|
+
case "html": return `<div style="${s}">${c.htmlContent || c.text || ""}</div>`;
|
|
315
366
|
default: return `<!-- Unsupported block ${e.type} -->`;
|
|
316
367
|
}
|
|
317
|
-
},
|
|
368
|
+
}, c = (n) => {
|
|
318
369
|
if (!n || typeof n != "object") return "";
|
|
319
370
|
let r = e(n);
|
|
320
371
|
if (!r) return `\n <!-- ROW SKIPPED (type="${typeof n.type == "string" ? n.type : "unknown"}"${n.id ? `, id="${n.id}"` : ""}): this row has no 'columns' array and its shorthand content (e.g. a list of items/links) can't be auto-converted without losing data. Provide a fully hydrated row with 'columns' and 'elements' instead. -->`;
|
|
321
|
-
let
|
|
322
|
-
|
|
323
|
-
let
|
|
324
|
-
for (let e of
|
|
372
|
+
let a = t(r.style || {}), o = i("id", r.htmlId), l = i("class", r.htmlClass), u = `\n <!-- ROW START: ${r.id || "row"} -->`;
|
|
373
|
+
u += `\n <div${o}${l} class="plexo-row" style="display: flex; flex-wrap: wrap; margin-left: -8px; margin-right: -8px; ${a}">`;
|
|
374
|
+
let d = Array.isArray(r.columns) ? r.columns : [];
|
|
375
|
+
for (let e of d) {
|
|
325
376
|
if (!e) continue;
|
|
326
|
-
let n = t(e.styles || e.style || {}), r = i("id", e.attrs?.htmlId),
|
|
327
|
-
|
|
328
|
-
let
|
|
329
|
-
for (let e of
|
|
377
|
+
let n = t(e.styles || e.style || {}), r = i("id", e.attrs?.htmlId), a = e.attrs?.htmlClass ? ` ${e.attrs.htmlClass}` : "";
|
|
378
|
+
u += `\n <!-- COLUMN START: ${e.id || "col"} -->`, u += `\n <div${r} class="plexo-col${a}" style="box-sizing: border-box; padding-left: 8px; padding-right: 8px; width: ${e.width || "100%"}; ${n}">`;
|
|
379
|
+
let o = Array.isArray(e.elements) ? e.elements : [];
|
|
380
|
+
for (let e of o) {
|
|
330
381
|
if (!e) continue;
|
|
331
|
-
let t = e.attributes || {}, n = typeof t.htmlClassNames == "string" ? t.htmlClassNames : typeof t.htmlClass == "string" ? t.htmlClass : typeof t.className == "string" ? t.className : "", r = i("id", t.htmlId),
|
|
332
|
-
|
|
382
|
+
let t = e.attributes || {}, n = typeof t.htmlClassNames == "string" ? t.htmlClassNames : typeof t.htmlClass == "string" ? t.htmlClass : typeof t.className == "string" ? t.className : "", r = i("id", t.htmlId), a = i("class", n), o = e.style?.display, c = o === "inline-block" || o === "inline" || o === "inline-flex" ? `margin-bottom: 16px; display: ${o}; vertical-align: top;` : "margin-bottom: 16px;";
|
|
383
|
+
u += `\n <div${r}${a} style="${c}">`, u += `\n ${s(e)}`, u += "\n </div>";
|
|
333
384
|
}
|
|
334
|
-
l
|
|
385
|
+
let l = Array.isArray(e.nestedRows) ? e.nestedRows : [];
|
|
386
|
+
for (let e of l) u += c(e);
|
|
387
|
+
u += "\n </div>";
|
|
335
388
|
}
|
|
336
|
-
return
|
|
337
|
-
},
|
|
389
|
+
return u += "\n </div>", u;
|
|
390
|
+
}, l = (e) => {
|
|
338
391
|
if (!e || typeof e != "object") return "<!-- Empty template -->";
|
|
339
392
|
let n = e.designJson || e.template || e, a = n.body || (Array.isArray(n.rows) ? {
|
|
340
393
|
style: n.style || {},
|
|
@@ -342,7 +395,7 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
342
395
|
} : {
|
|
343
396
|
style: {},
|
|
344
397
|
rows: []
|
|
345
|
-
}),
|
|
398
|
+
}), o = { ...a.style || {} };
|
|
346
399
|
for (let e of [
|
|
347
400
|
"backgroundColor",
|
|
348
401
|
"background",
|
|
@@ -350,9 +403,9 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
350
403
|
"textColor",
|
|
351
404
|
"fontFamily",
|
|
352
405
|
"htmlTitle"
|
|
353
|
-
])
|
|
354
|
-
|
|
355
|
-
let
|
|
406
|
+
]) o[e] === void 0 && (a[e] === void 0 ? n[e] !== void 0 && (o[e] = n[e]) : o[e] = a[e]);
|
|
407
|
+
o.backgroundColor && !o.background ? o.background = o.backgroundColor : o.background && !o.backgroundColor && (o.backgroundColor = o.background), o.textColor && !o.color && (o.color = o.textColor);
|
|
408
|
+
let s = [
|
|
356
409
|
"htmlTitle",
|
|
357
410
|
"htmlId",
|
|
358
411
|
"htmlClass",
|
|
@@ -360,8 +413,8 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
360
413
|
"customJs",
|
|
361
414
|
"textColor"
|
|
362
415
|
], l = {};
|
|
363
|
-
for (let e of Object.keys(
|
|
364
|
-
let u = t(l), d = typeof
|
|
416
|
+
for (let e of Object.keys(o)) s.includes(e) || (l[e] = o[e]);
|
|
417
|
+
let u = t(l), d = typeof o.htmlTitle == "string" && o.htmlTitle.trim() ? o.htmlTitle.trim() : typeof e?.name == "string" && e.name.trim() ? e.name.trim() : "Plexo Rendered Page", f = i("id", o.htmlId), p = i("class", o.htmlClass), m = typeof o.customCss == "string" && o.customCss.trim() ? o.customCss.trim() : "", h = typeof o.customJs == "string" && o.customJs.trim() ? o.customJs.trim() : "", g = `<!DOCTYPE html>
|
|
365
418
|
<html>
|
|
366
419
|
<head>
|
|
367
420
|
<meta charset="utf-8">
|
|
@@ -388,20 +441,20 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
388
441
|
</head>
|
|
389
442
|
<body${f}${p} style="${u}">
|
|
390
443
|
<div style="max-width: 1200px; margin: 0 auto; width: 100%;">`, _ = Array.isArray(a.rows) ? a.rows : Array.isArray(n.rows) ? n.rows : Array.isArray(e.rows) ? e.rows : [];
|
|
391
|
-
for (let e of _) g +=
|
|
444
|
+
for (let e of _) g += c(e);
|
|
392
445
|
return g += `\n </div>
|
|
393
446
|
${h ? ` <script>\n${h}\n <\/script>` : ""}
|
|
394
447
|
</body>
|
|
395
448
|
</html>`, g;
|
|
396
449
|
};
|
|
397
|
-
function
|
|
398
|
-
return
|
|
450
|
+
function u(e) {
|
|
451
|
+
return l(e).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
399
452
|
}
|
|
400
|
-
function
|
|
401
|
-
return
|
|
453
|
+
function d(e) {
|
|
454
|
+
return l(e);
|
|
402
455
|
}
|
|
403
|
-
function
|
|
456
|
+
function f(e) {
|
|
404
457
|
return e;
|
|
405
458
|
}
|
|
406
459
|
//#endregion
|
|
407
|
-
export {
|
|
460
|
+
export { l as compileToHTML, d as compileToHTMLWithStrataAuto, u as compileToPlainText, e as convertSectionRowToPlexoRow, f as injectStrataBundle };
|
package/dist/compilerClient.js
CHANGED
|
@@ -51,8 +51,8 @@ var e = /* @__PURE__ */ new Set([
|
|
|
51
51
|
let n = e.elements.map((e) => s(e, r)).join("");
|
|
52
52
|
return `<mj-column width="${t(e.width || "100%")}">${n}</mj-column>`;
|
|
53
53
|
}
|
|
54
|
-
let i = n(e.styles || {}), a = e.elements.map((e) => s(e, r)).join("");
|
|
55
|
-
return `<div style="width:${t(e.width || "100%")};${i}">${a}</div>`;
|
|
54
|
+
let i = n(e.styles || {}), a = e.elements.map((e) => s(e, r)).join(""), o = (Array.isArray(e.nestedRows) ? e.nestedRows : []).map((e) => l(e, r)).join("");
|
|
55
|
+
return `<div style="width:${t(e.width || "100%")};${i}">${a}${o}</div>`;
|
|
56
56
|
}, l = (e, t) => t === "email" ? `<mj-section css-class="${e.style?.hideOnDesktop ? "desktop-hide" : ""}">${e.columns.map((e) => c(e, t)).join("")}</mj-section>` : `<section style="display:flex;flex-wrap:wrap;${n(e.style || {})}">${e.columns.map((e) => c(e, t)).join("")}</section>`, u = (e, t) => {
|
|
57
57
|
let r = (e.body?.rows || []).map((e) => l(e, t)).join(""), i = n(e.body?.style || {});
|
|
58
58
|
return t === "email" ? `<mjml><mj-head><mj-style>.desktop-hide { display:none !important; max-height:0; overflow:hidden; }</mj-style></mj-head><mj-body><mj-section><mj-column><mj-wrapper css-class="email-root" padding="0"><mj-text css-class="preheader" padding="0" font-size="1px" color="#ffffff"> </mj-text></mj-wrapper></mj-column></mj-section>${r}</mj-body></mjml>` : `<!doctype html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /></head><body style="${i}"><main>${r}</main></body></html>`;
|