@charisol/plexo-sdk 1.0.21 → 1.0.23
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 +74 -73
- package/dist/index.js +11423 -11415
- package/dist/plexo-sdk.css +1 -1
- package/dist/utilities/compiler.d.ts +7 -0
- package/dist/utilities/playground.interfaces.d.ts +9 -0
- package/package.json +2 -1
package/dist/compiler.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//#region src/utilities/compiler.ts
|
|
2
|
-
|
|
2
|
+
var e = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif";
|
|
3
|
+
function t(e) {
|
|
3
4
|
if (!e || typeof e != "object") return null;
|
|
4
5
|
if (Array.isArray(e.columns) && e.columns.length > 0) return e;
|
|
5
6
|
let t = (e.type || "").toLowerCase(), n = e.props || e.content || e.attributes || e.data || e.payload || e, r = e.style || {};
|
|
@@ -253,7 +254,7 @@ function e(e) {
|
|
|
253
254
|
}
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
|
-
var
|
|
257
|
+
var n = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter(([e, t]) => t != null && t !== "").map(([e, t]) => {
|
|
257
258
|
let n = e.replace(/([A-Z])/g, "-$1").toLowerCase(), r = t;
|
|
258
259
|
return typeof t == "number" && [
|
|
259
260
|
"padding",
|
|
@@ -264,7 +265,7 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
264
265
|
"width",
|
|
265
266
|
"height"
|
|
266
267
|
].some((t) => e.toLowerCase().includes(t)) && (r = `${t}px`), `${n}: ${r};`;
|
|
267
|
-
}).join(" "),
|
|
268
|
+
}).join(" "), r = () => ({
|
|
268
269
|
backgroundColor: "#ffffff",
|
|
269
270
|
borderRadius: "20px",
|
|
270
271
|
width: "100%",
|
|
@@ -287,11 +288,11 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
287
288
|
buttonPaddingRight: "14px",
|
|
288
289
|
buttonFontSize: "13px",
|
|
289
290
|
buttonFontWeight: "700"
|
|
290
|
-
}),
|
|
291
|
+
}), i = (e) => (e || "").replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"), a = (e, t) => {
|
|
291
292
|
if (typeof t != "string") return "";
|
|
292
293
|
let n = t.trim();
|
|
293
|
-
return n ? ` ${e}="${
|
|
294
|
-
},
|
|
294
|
+
return n ? ` ${e}="${i(n)}"` : "";
|
|
295
|
+
}, o = [
|
|
295
296
|
"fieldSpacing",
|
|
296
297
|
"buttonBackgroundColor",
|
|
297
298
|
"buttonTextColor",
|
|
@@ -302,9 +303,9 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
302
303
|
"buttonPaddingRight",
|
|
303
304
|
"buttonFontSize",
|
|
304
305
|
"buttonFontWeight"
|
|
305
|
-
],
|
|
306
|
+
], s = (e) => {
|
|
306
307
|
if (!e || typeof e != "object") return "";
|
|
307
|
-
let
|
|
308
|
+
let t = e.kind || "text", r = i(e.name || e.label || "field"), a = e.required ? " required" : "", o = n({
|
|
308
309
|
fontSize: e.fontSize,
|
|
309
310
|
borderRadius: e.borderRadius,
|
|
310
311
|
borderWidth: e.borderWidth,
|
|
@@ -312,38 +313,38 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
312
313
|
borderStyle: "solid",
|
|
313
314
|
color: e.inputTextColor
|
|
314
315
|
}), 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
|
|
316
|
+
return t === "textarea" ? `${s}<textarea name="${r}" placeholder="${i(e.placeholder || "")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${o}"${a}></textarea>` : t === "select" ? `${s}<select name="${r}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${o}"${a}>${(Array.isArray(e.options) ? e.options : []).map((e) => `<option value="${i(e?.value ?? "")}">${e?.label ?? e?.value ?? ""}</option>`).join("")}</select>` : t === "radio" || t === "checkbox" ? `${s}<div style="display: flex; flex-wrap: wrap; gap: 8px;">${(Array.isArray(e.options) && e.options.length > 0 ? e.options : [{
|
|
316
317
|
label: e.label || "Option",
|
|
317
318
|
value: e.name || "option"
|
|
318
|
-
}]).map((
|
|
319
|
-
},
|
|
319
|
+
}]).map((n) => `<label style="display: inline-flex; align-items: center; gap: 6px; font-size: ${e.fontSize || "12px"};"><input type="${t}" name="${r}" value="${i(n?.value ?? "")}" />${n?.label ?? n?.value ?? ""}</label>`).join("")}</div>` : `${s}<input type="${i(t)}" name="${r}" placeholder="${i(e.placeholder || "")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${o}"${a} />`;
|
|
320
|
+
}, c = (e) => {
|
|
320
321
|
if (!e || typeof e != "object") return "";
|
|
321
|
-
let
|
|
322
|
-
...
|
|
323
|
-
...
|
|
324
|
-
} :
|
|
322
|
+
let t = e.style || {}, a = n(e.type === "form_container" ? {
|
|
323
|
+
...r(),
|
|
324
|
+
...t
|
|
325
|
+
} : t), c = e.attributes || {};
|
|
325
326
|
switch (e.type) {
|
|
326
|
-
case "heading": return `<h2 style="margin-top: 0; margin-bottom: 8px; ${
|
|
327
|
-
case "paragraph": return `<p style="margin-top: 0; margin-bottom: 12px; ${
|
|
328
|
-
case "text": return `<div style="${
|
|
329
|
-
case "button": return `<div style="text-align: ${
|
|
327
|
+
case "heading": return `<h2 style="margin-top: 0; margin-bottom: 8px; ${a}">${c.text || "Heading"}</h2>`;
|
|
328
|
+
case "paragraph": return `<p style="margin-top: 0; margin-bottom: 12px; ${a}">${c.text || "Paragraph text content."}</p>`;
|
|
329
|
+
case "text": return `<div style="${a}">${c.text || ""}</div>`;
|
|
330
|
+
case "button": return `<div style="text-align: ${t.textAlign || "center"};"><a href="${c.href || "#"}" target="${c.openInNewTab ? "_blank" : "_self"}" style="display: inline-block; text-decoration: none; ${a}">${c.text || "Button"}</a></div>`;
|
|
330
331
|
case "image": {
|
|
331
|
-
let e =
|
|
332
|
-
return `<img src="${c.src || "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe"}" alt="${c.alt || ""}" style="${
|
|
332
|
+
let e = t.textAlign === "center" ? "margin: 0 auto; display: block;" : t.textAlign === "right" ? "margin-left: auto; display: block;" : "display: inline-block;";
|
|
333
|
+
return `<img src="${c.src || "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe"}" alt="${c.alt || ""}" style="${a} ${e}" />`;
|
|
333
334
|
}
|
|
334
|
-
case "divider": return `<hr style="border: 0; border-top: ${
|
|
335
|
-
case "spacer": return `<div style="height: ${
|
|
336
|
-
case "card": return `<div style="${
|
|
335
|
+
case "divider": return `<hr style="border: 0; border-top: ${t.borderWidth || "1px"} ${t.borderStyle || "solid"} ${t.borderColor || "#334155"}; ${a}" />`;
|
|
336
|
+
case "spacer": return `<div style="height: ${t.height || "24px"};"></div>`;
|
|
337
|
+
case "card": return `<div style="${a}">
|
|
337
338
|
<h3 style="margin-top: 0; margin-bottom: 8px; color: #ffffff;">${c.title || "Card Title"}</h3>
|
|
338
339
|
<p style="margin: 0; color: #94a3b8; font-size: 14px;">${c.description || "Card description."}</p>
|
|
339
340
|
</div>`;
|
|
340
341
|
case "form_container": {
|
|
341
342
|
let e = {
|
|
342
|
-
...
|
|
343
|
-
...
|
|
344
|
-
},
|
|
345
|
-
for (let t of Object.keys(e))
|
|
346
|
-
let l =
|
|
343
|
+
...r(),
|
|
344
|
+
...t
|
|
345
|
+
}, a = {};
|
|
346
|
+
for (let t of Object.keys(e)) o.includes(t) || (a[t] = e[t]);
|
|
347
|
+
let l = n(a), u = Array.isArray(c.fields) ? c.fields : [], d = e.fieldSpacing || "12px", f = u.map((e) => `<div style="margin-bottom: ${d};">${s(e)}</div>`).join(""), p = n({
|
|
347
348
|
backgroundColor: e.buttonBackgroundColor,
|
|
348
349
|
color: e.buttonTextColor,
|
|
349
350
|
borderRadius: e.buttonBorderRadius,
|
|
@@ -354,48 +355,48 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
354
355
|
fontSize: e.buttonFontSize,
|
|
355
356
|
fontWeight: e.buttonFontWeight
|
|
356
357
|
});
|
|
357
|
-
return `<form action="${
|
|
358
|
+
return `<form action="${i(c.actionUrl || c.action || "#")}" method="${i(c.method || "POST")}" style="${l}">${f}<button type="submit" style="border: 0; cursor: pointer; ${p}">${c.submitLabel || "Submit"}</button></form>`;
|
|
358
359
|
}
|
|
359
360
|
case "input": {
|
|
360
|
-
let e = c.inputType || c.type || "text", t =
|
|
361
|
-
return `<input type="${
|
|
361
|
+
let e = c.inputType || c.type || "text", t = i(c.name || c.fieldName || "field"), n = i(c.placeholder || ""), r = c.required ? " required" : "";
|
|
362
|
+
return `<input type="${i(e)}" name="${t}" placeholder="${n}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${a}"${r} />`;
|
|
362
363
|
}
|
|
363
|
-
case "textarea": return `<textarea name="${
|
|
364
|
-
case "select": return `<select name="${
|
|
365
|
-
case "html": return `<div style="${
|
|
364
|
+
case "textarea": return `<textarea name="${i(c.name || c.fieldName || "field")}" placeholder="${i(c.placeholder || "")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${a}"${c.required ? " required" : ""}></textarea>`;
|
|
365
|
+
case "select": return `<select name="${i(c.name || c.fieldName || "field")}" style="width: 100%; box-sizing: border-box; padding: 10px 12px; ${a}"${c.required ? " required" : ""}>${(Array.isArray(c.options) ? c.options : []).map((e) => `<option value="${i(e?.value ?? "")}">${e?.label ?? e?.value ?? ""}</option>`).join("")}</select>`;
|
|
366
|
+
case "html": return `<div style="${a}">${c.htmlContent || c.text || ""}</div>`;
|
|
366
367
|
default: return `<!-- Unsupported block ${e.type} -->`;
|
|
367
368
|
}
|
|
368
|
-
},
|
|
369
|
-
if (!
|
|
370
|
-
let r = e
|
|
371
|
-
if (!r) return `\n <!-- ROW SKIPPED (type="${typeof
|
|
372
|
-
let
|
|
373
|
-
u += `\n <div${o}${
|
|
369
|
+
}, l = (e) => {
|
|
370
|
+
if (!e || typeof e != "object") return "";
|
|
371
|
+
let r = t(e);
|
|
372
|
+
if (!r) return `\n <!-- ROW SKIPPED (type="${typeof e.type == "string" ? e.type : "unknown"}"${e.id ? `, id="${e.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. -->`;
|
|
373
|
+
let i = n(r.style || {}), o = a("id", r.htmlId), s = a("class", r.htmlClass), u = `\n <!-- ROW START: ${r.id || "row"} -->`;
|
|
374
|
+
u += `\n <div${o}${s} class="plexo-row" style="display: flex; flex-wrap: wrap; margin-left: -8px; margin-right: -8px; ${i}">`;
|
|
374
375
|
let d = Array.isArray(r.columns) ? r.columns : [];
|
|
375
376
|
for (let e of d) {
|
|
376
377
|
if (!e) continue;
|
|
377
|
-
let
|
|
378
|
-
u += `\n <!-- COLUMN START: ${e.id || "col"} -->`, u += `\n <div${r} class="plexo-col${
|
|
378
|
+
let t = n(e.styles || e.style || {}), r = a("id", e.attrs?.htmlId), i = e.attrs?.htmlClass ? ` ${e.attrs.htmlClass}` : "";
|
|
379
|
+
u += `\n <!-- COLUMN START: ${e.id || "col"} -->`, u += `\n <div${r} class="plexo-col${i}" style="box-sizing: border-box; padding-left: 8px; padding-right: 8px; width: ${e.width || "100%"}; ${t}">`;
|
|
379
380
|
let o = Array.isArray(e.elements) ? e.elements : [];
|
|
380
381
|
for (let e of o) {
|
|
381
382
|
if (!e) continue;
|
|
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 =
|
|
383
|
-
u += `\n <div${r}${
|
|
383
|
+
let t = e.attributes || {}, n = typeof t.htmlClassNames == "string" ? t.htmlClassNames : typeof t.htmlClass == "string" ? t.htmlClass : typeof t.className == "string" ? t.className : "", r = a("id", t.htmlId), i = a("class", n), o = e.style?.display, s = o === "inline-block" || o === "inline" || o === "inline-flex" ? `margin-bottom: 16px; display: ${o}; vertical-align: top;` : "margin-bottom: 16px;";
|
|
384
|
+
u += `\n <div${r}${i} style="${s}">`, u += `\n ${c(e)}`, u += "\n </div>";
|
|
384
385
|
}
|
|
385
|
-
let
|
|
386
|
-
for (let e of
|
|
386
|
+
let s = Array.isArray(e.nestedRows) ? e.nestedRows : [];
|
|
387
|
+
for (let e of s) u += l(e);
|
|
387
388
|
u += "\n </div>";
|
|
388
389
|
}
|
|
389
390
|
return u += "\n </div>", u;
|
|
390
|
-
},
|
|
391
|
-
if (!
|
|
392
|
-
let
|
|
393
|
-
style:
|
|
394
|
-
rows:
|
|
391
|
+
}, u = (t) => {
|
|
392
|
+
if (!t || typeof t != "object") return "<!-- Empty template -->";
|
|
393
|
+
let r = t.designJson || t.template || t, o = r.body || (Array.isArray(r.rows) ? {
|
|
394
|
+
style: r.style || {},
|
|
395
|
+
rows: r.rows
|
|
395
396
|
} : {
|
|
396
397
|
style: {},
|
|
397
398
|
rows: []
|
|
398
|
-
}),
|
|
399
|
+
}), s = { ...o.style || {} };
|
|
399
400
|
for (let e of [
|
|
400
401
|
"backgroundColor",
|
|
401
402
|
"background",
|
|
@@ -403,25 +404,25 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
403
404
|
"textColor",
|
|
404
405
|
"fontFamily",
|
|
405
406
|
"htmlTitle"
|
|
406
|
-
])
|
|
407
|
-
|
|
408
|
-
let
|
|
407
|
+
]) s[e] === void 0 && (o[e] === void 0 ? r[e] !== void 0 && (s[e] = r[e]) : s[e] = o[e]);
|
|
408
|
+
s.backgroundColor && !s.background ? s.background = s.backgroundColor : s.background && !s.backgroundColor && (s.backgroundColor = s.background), s.textColor && !s.color && (s.color = s.textColor);
|
|
409
|
+
let c = [
|
|
409
410
|
"htmlTitle",
|
|
410
411
|
"htmlId",
|
|
411
412
|
"htmlClass",
|
|
412
413
|
"customCss",
|
|
413
414
|
"customJs",
|
|
414
415
|
"textColor"
|
|
415
|
-
],
|
|
416
|
-
for (let e of Object.keys(
|
|
417
|
-
let
|
|
416
|
+
], u = {};
|
|
417
|
+
for (let e of Object.keys(s)) c.includes(e) || (u[e] = s[e]);
|
|
418
|
+
let d = n(u), f = typeof s.htmlTitle == "string" && s.htmlTitle.trim() ? s.htmlTitle.trim() : typeof t?.name == "string" && t.name.trim() ? t.name.trim() : "Plexo Rendered Page", p = a("id", s.htmlId), m = a("class", s.htmlClass), h = typeof s.customCss == "string" && s.customCss.trim() ? s.customCss.trim() : "", g = typeof s.customJs == "string" && s.customJs.trim() ? s.customJs.trim() : "", _ = `<!DOCTYPE html>
|
|
418
419
|
<html>
|
|
419
420
|
<head>
|
|
420
421
|
<meta charset="utf-8">
|
|
421
|
-
<title>${
|
|
422
|
+
<title>${i(f)}</title>
|
|
422
423
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
423
424
|
<style>
|
|
424
|
-
body { margin: 0; font-family:
|
|
425
|
+
body { margin: 0; font-family: ${e}; }
|
|
425
426
|
.plexo-row {
|
|
426
427
|
display: flex;
|
|
427
428
|
flex-wrap: wrap;
|
|
@@ -437,24 +438,24 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
|
|
|
437
438
|
}
|
|
438
439
|
}
|
|
439
440
|
</style>
|
|
440
|
-
${
|
|
441
|
+
${h ? `<style>\n${h}\n </style>` : ""}
|
|
441
442
|
</head>
|
|
442
|
-
<body${
|
|
443
|
-
<div style="max-width: 1200px; margin: 0 auto; width: 100%;">`,
|
|
444
|
-
for (let e of
|
|
445
|
-
return
|
|
446
|
-
${
|
|
443
|
+
<body${p}${m} style="${d}">
|
|
444
|
+
<div style="max-width: 1200px; margin: 0 auto; width: 100%;">`, v = Array.isArray(o.rows) ? o.rows : Array.isArray(r.rows) ? r.rows : Array.isArray(t.rows) ? t.rows : [];
|
|
445
|
+
for (let e of v) _ += l(e);
|
|
446
|
+
return _ += `\n </div>
|
|
447
|
+
${g ? ` <script>\n${g}\n <\/script>` : ""}
|
|
447
448
|
</body>
|
|
448
|
-
</html>`,
|
|
449
|
+
</html>`, _;
|
|
449
450
|
};
|
|
450
|
-
function u(e) {
|
|
451
|
-
return l(e).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
452
|
-
}
|
|
453
451
|
function d(e) {
|
|
454
|
-
return
|
|
452
|
+
return u(e).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
455
453
|
}
|
|
456
454
|
function f(e) {
|
|
455
|
+
return u(e);
|
|
456
|
+
}
|
|
457
|
+
function p(e) {
|
|
457
458
|
return e;
|
|
458
459
|
}
|
|
459
460
|
//#endregion
|
|
460
|
-
export {
|
|
461
|
+
export { e as DEFAULT_BODY_FONT_FAMILY, u as compileToHTML, f as compileToHTMLWithStrataAuto, d as compileToPlainText, t as convertSectionRowToPlexoRow, p as injectStrataBundle };
|