@charisol/plexo-sdk 1.0.15 → 1.0.16

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.
Files changed (2) hide show
  1. package/dist/compiler.js +88 -38
  2. package/package.json +1 -1
package/dist/compiler.js CHANGED
@@ -291,50 +291,100 @@ 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 = (e) => {
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 r = e.style || {}, i = t(e.type === "form_container" ? {
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
- ...r
299
- } : r), a = e.attributes || {};
323
+ ...i
324
+ } : i), c = e.attributes || {};
300
325
  switch (e.type) {
301
- case "heading": return `<h2 style="margin-top: 0; margin-bottom: 8px; ${i}">${a.text || "Heading"}</h2>`;
302
- case "paragraph": return `<p style="margin-top: 0; margin-bottom: 12px; ${i}">${a.text || "Paragraph text content."}</p>`;
303
- case "text": return `<div style="${i}">${a.text || ""}</div>`;
304
- case "button": return `<div style="text-align: ${r.textAlign || "center"};"><a href="${a.href || "#"}" target="${a.openInNewTab ? "_blank" : "_self"}" style="display: inline-block; text-decoration: none; ${i}">${a.text || "Button"}</a></div>`;
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 = r.textAlign === "center" ? "margin: 0 auto; display: block;" : r.textAlign === "right" ? "margin-left: auto; display: block;" : "display: inline-block;";
307
- return `<img src="${a.src || "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe"}" alt="${a.alt || ""}" style="${i} ${e}" />`;
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: ${r.borderWidth || "1px"} ${r.borderStyle || "solid"} ${r.borderColor || "#334155"}; ${i}" />`;
310
- case "spacer": return `<div style="height: ${r.height || "24px"};"></div>`;
311
- case "card": return `<div style="${i}">
312
- <h3 style="margin-top: 0; margin-bottom: 8px; color: #ffffff;">${a.title || "Card Title"}</h3>
313
- <p style="margin: 0; color: #94a3b8; font-size: 14px;">${a.description || "Card description."}</p>
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>`;
315
365
  default: return `<!-- Unsupported block ${e.type} -->`;
316
366
  }
317
- }, o = (n) => {
367
+ }, c = (n) => {
318
368
  if (!n || typeof n != "object") return "";
319
369
  let r = e(n);
320
370
  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 o = t(r.style || {}), s = i("id", r.htmlId), c = i("class", r.htmlClass), l = `\n <!-- ROW START: ${r.id || "row"} -->`;
322
- l += `\n <div${s}${c} class="plexo-row" style="display: flex; flex-wrap: wrap; margin-left: -8px; margin-right: -8px; ${o}">`;
371
+ let a = t(r.style || {}), o = i("id", r.htmlId), c = i("class", r.htmlClass), l = `\n <!-- ROW START: ${r.id || "row"} -->`;
372
+ l += `\n <div${o}${c} class="plexo-row" style="display: flex; flex-wrap: wrap; margin-left: -8px; margin-right: -8px; ${a}">`;
323
373
  let u = Array.isArray(r.columns) ? r.columns : [];
324
374
  for (let e of u) {
325
375
  if (!e) continue;
326
- let n = t(e.styles || e.style || {}), r = i("id", e.attrs?.htmlId), o = e.attrs?.htmlClass ? ` ${e.attrs.htmlClass}` : "";
327
- l += `\n <!-- COLUMN START: ${e.id || "col"} -->`, l += `\n <div${r} class="plexo-col${o}" style="box-sizing: border-box; padding-left: 8px; padding-right: 8px; width: ${e.width || "100%"}; ${n}">`;
328
- let s = Array.isArray(e.elements) ? e.elements : [];
329
- for (let e of s) {
376
+ let n = t(e.styles || e.style || {}), r = i("id", e.attrs?.htmlId), a = e.attrs?.htmlClass ? ` ${e.attrs.htmlClass}` : "";
377
+ l += `\n <!-- COLUMN START: ${e.id || "col"} -->`, l += `\n <div${r} class="plexo-col${a}" style="box-sizing: border-box; padding-left: 8px; padding-right: 8px; width: ${e.width || "100%"}; ${n}">`;
378
+ let o = Array.isArray(e.elements) ? e.elements : [];
379
+ for (let e of o) {
330
380
  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), o = i("class", n);
332
- l += `\n <div${r}${o} style="margin-bottom: 16px;">`, l += `\n ${a(e)}`, l += "\n </div>";
381
+ 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);
382
+ l += `\n <div${r}${a} style="margin-bottom: 16px;">`, l += `\n ${s(e)}`, l += "\n </div>";
333
383
  }
334
384
  l += "\n </div>";
335
385
  }
336
386
  return l += "\n </div>", l;
337
- }, s = (e) => {
387
+ }, l = (e) => {
338
388
  if (!e || typeof e != "object") return "<!-- Empty template -->";
339
389
  let n = e.designJson || e.template || e, a = n.body || (Array.isArray(n.rows) ? {
340
390
  style: n.style || {},
@@ -342,7 +392,7 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
342
392
  } : {
343
393
  style: {},
344
394
  rows: []
345
- }), s = { ...a.style || {} };
395
+ }), o = { ...a.style || {} };
346
396
  for (let e of [
347
397
  "backgroundColor",
348
398
  "background",
@@ -350,9 +400,9 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
350
400
  "textColor",
351
401
  "fontFamily",
352
402
  "htmlTitle"
353
- ]) s[e] === void 0 && (a[e] === void 0 ? n[e] !== void 0 && (s[e] = n[e]) : s[e] = a[e]);
354
- s.backgroundColor && !s.background ? s.background = s.backgroundColor : s.background && !s.backgroundColor && (s.backgroundColor = s.background), s.textColor && !s.color && (s.color = s.textColor);
355
- let c = [
403
+ ]) o[e] === void 0 && (a[e] === void 0 ? n[e] !== void 0 && (o[e] = n[e]) : o[e] = a[e]);
404
+ o.backgroundColor && !o.background ? o.background = o.backgroundColor : o.background && !o.backgroundColor && (o.backgroundColor = o.background), o.textColor && !o.color && (o.color = o.textColor);
405
+ let s = [
356
406
  "htmlTitle",
357
407
  "htmlId",
358
408
  "htmlClass",
@@ -360,8 +410,8 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
360
410
  "customJs",
361
411
  "textColor"
362
412
  ], l = {};
363
- for (let e of Object.keys(s)) c.includes(e) || (l[e] = s[e]);
364
- let u = t(l), d = typeof s.htmlTitle == "string" && s.htmlTitle.trim() ? s.htmlTitle.trim() : typeof e?.name == "string" && e.name.trim() ? e.name.trim() : "Plexo Rendered Page", f = i("id", s.htmlId), p = i("class", s.htmlClass), m = typeof s.customCss == "string" && s.customCss.trim() ? s.customCss.trim() : "", h = typeof s.customJs == "string" && s.customJs.trim() ? s.customJs.trim() : "", g = `<!DOCTYPE html>
413
+ for (let e of Object.keys(o)) s.includes(e) || (l[e] = o[e]);
414
+ 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
415
  <html>
366
416
  <head>
367
417
  <meta charset="utf-8">
@@ -388,20 +438,20 @@ var t = (e = {}) => !e || typeof e != "object" ? "" : Object.entries(e).filter((
388
438
  </head>
389
439
  <body${f}${p} style="${u}">
390
440
  <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 += o(e);
441
+ for (let e of _) g += c(e);
392
442
  return g += `\n </div>
393
443
  ${h ? ` <script>\n${h}\n <\/script>` : ""}
394
444
  </body>
395
445
  </html>`, g;
396
446
  };
397
- function c(e) {
398
- return s(e).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
447
+ function u(e) {
448
+ return l(e).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
399
449
  }
400
- function l(e) {
401
- return s(e);
450
+ function d(e) {
451
+ return l(e);
402
452
  }
403
- function u(e) {
453
+ function f(e) {
404
454
  return e;
405
455
  }
406
456
  //#endregion
407
- export { s as compileToHTML, l as compileToHTMLWithStrataAuto, c as compileToPlainText, e as convertSectionRowToPlexoRow, u as injectStrataBundle };
457
+ export { l as compileToHTML, d as compileToHTMLWithStrataAuto, u as compileToPlainText, e as convertSectionRowToPlexoRow, f as injectStrataBundle };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@charisol/plexo-sdk",
3
3
  "private": false,
4
- "version": "1.0.15",
4
+ "version": "1.0.16",
5
5
  "description": "Plexo visual email and landing page builder SDK — drag-and-drop template editor with AI integration.",
6
6
  "keywords": [
7
7
  "email-builder",