@charisol/plexo-sdk 1.0.14 → 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.
- package/dist/compiler.js +88 -38
- package/dist/compilerClient.js +1 -1
- package/dist/index.js +38 -1
- package/dist/utilities/playground.interfaces.d.ts +1 -1
- 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 =
|
|
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>`;
|
|
315
365
|
default: return `<!-- Unsupported block ${e.type} -->`;
|
|
316
366
|
}
|
|
317
|
-
},
|
|
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
|
|
322
|
-
l += `\n <div${
|
|
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),
|
|
327
|
-
l += `\n <!-- COLUMN START: ${e.id || "col"} -->`, l += `\n <div${r} class="plexo-col${
|
|
328
|
-
let
|
|
329
|
-
for (let e of
|
|
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),
|
|
332
|
-
l += `\n <div${r}${
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
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
|
-
])
|
|
354
|
-
|
|
355
|
-
let
|
|
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(
|
|
364
|
-
let u = t(l), d = typeof
|
|
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 +=
|
|
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
|
|
398
|
-
return
|
|
447
|
+
function u(e) {
|
|
448
|
+
return l(e).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
399
449
|
}
|
|
400
|
-
function
|
|
401
|
-
return
|
|
450
|
+
function d(e) {
|
|
451
|
+
return l(e);
|
|
402
452
|
}
|
|
403
|
-
function
|
|
453
|
+
function f(e) {
|
|
404
454
|
return e;
|
|
405
455
|
}
|
|
406
456
|
//#endregion
|
|
407
|
-
export {
|
|
457
|
+
export { l as compileToHTML, d as compileToHTMLWithStrataAuto, u as compileToPlainText, e as convertSectionRowToPlexoRow, f as injectStrataBundle };
|
package/dist/compilerClient.js
CHANGED
|
@@ -13,7 +13,7 @@ var e = /* @__PURE__ */ new Set([
|
|
|
13
13
|
}, a = (e, a) => {
|
|
14
14
|
let o = i(e, a), s = n(e.style || {}), c = r(o.htmlClassNames, o.htmlClass, o.validationClass, o.validationClassName), l = t(o.name || o.fieldName || "field"), u = t(o.placeholder || ""), d = o.required ? " required" : "";
|
|
15
15
|
if (a === "email") return `<mj-table><tr><td style="padding:10px 12px;border:1px solid #d1d5db;border-radius:6px;color:#64748b;${s}">${u || l}</td></tr></mj-table>`;
|
|
16
|
-
let f = t(o.inputType || (e.type === "input" ? o.
|
|
16
|
+
let f = t(o.inputType || o.type || (e.type === "input" ? o.kind || "text" : e.type)), p = o.htmlId ? ` id="${t(o.htmlId)}"` : "", m = c ? ` class="${t(c)}"` : "";
|
|
17
17
|
return e.type === "textarea" ? `<textarea${p}${m} name="${l}" placeholder="${u}" style="${s}"${d}>${t(o.value || "")}</textarea>` : e.type === "select" ? `<select${p}${m} name="${l}" style="${s}"${d}>${(o.options || []).map((e) => `<option value="${t(e.value)}">${t(e.label)}</option>`).join("")}</select>` : `<input${p}${m} type="${f}" name="${l}" placeholder="${u}" value="${t(o.value || "")}" style="${s}"${d} />`;
|
|
18
18
|
}, o = (e, o) => {
|
|
19
19
|
let s = i(e, o), c = n(e.style || {}), l = r(s.htmlClassNames, s.htmlClass), u = s.htmlId ? ` id="${t(s.htmlId)}"` : "", d = l ? ` class="${t(l)}"` : "", f = t(s.actionUrl || s.action || "#"), p = t(s.method || "POST"), m = s.fields || [], h = t(s.submitLabel || "Submit");
|
package/dist/index.js
CHANGED
|
@@ -827,6 +827,14 @@ var A = [
|
|
|
827
827
|
label: "Email",
|
|
828
828
|
value: "email"
|
|
829
829
|
},
|
|
830
|
+
{
|
|
831
|
+
label: "Number",
|
|
832
|
+
value: "number"
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
label: "Date",
|
|
836
|
+
value: "date"
|
|
837
|
+
},
|
|
830
838
|
{
|
|
831
839
|
label: "Textarea",
|
|
832
840
|
value: "textarea"
|
|
@@ -1370,6 +1378,31 @@ var A = [
|
|
|
1370
1378
|
borderRadius: "12px",
|
|
1371
1379
|
borderWidth: "1px",
|
|
1372
1380
|
borderColor: "#e2e8f0"
|
|
1381
|
+
} : e === "number" ? {
|
|
1382
|
+
id: t,
|
|
1383
|
+
kind: e,
|
|
1384
|
+
name: "number",
|
|
1385
|
+
label: "Number",
|
|
1386
|
+
showLabel: !0,
|
|
1387
|
+
inheritStylesFromPrevious: !1,
|
|
1388
|
+
placeholder: "0",
|
|
1389
|
+
fontSize: "13px",
|
|
1390
|
+
labelFontWeight: "700",
|
|
1391
|
+
borderRadius: "12px",
|
|
1392
|
+
borderWidth: "1px",
|
|
1393
|
+
borderColor: "#e2e8f0"
|
|
1394
|
+
} : e === "date" ? {
|
|
1395
|
+
id: t,
|
|
1396
|
+
kind: e,
|
|
1397
|
+
name: "date",
|
|
1398
|
+
label: "Date",
|
|
1399
|
+
showLabel: !0,
|
|
1400
|
+
inheritStylesFromPrevious: !1,
|
|
1401
|
+
fontSize: "13px",
|
|
1402
|
+
labelFontWeight: "700",
|
|
1403
|
+
borderRadius: "12px",
|
|
1404
|
+
borderWidth: "1px",
|
|
1405
|
+
borderColor: "#e2e8f0"
|
|
1373
1406
|
} : e === "textarea" ? {
|
|
1374
1407
|
id: t,
|
|
1375
1408
|
kind: e,
|
|
@@ -48159,7 +48192,11 @@ var oP = (e) => {
|
|
|
48159
48192
|
}) : /* @__PURE__ */ E("span", { className: `flex h-3.5 w-3.5 items-center justify-center border border-slate-350 ${n.kind === "radio" ? "rounded-full" : "rounded-sm"}` }), e.label]
|
|
48160
48193
|
}, e.value))
|
|
48161
48194
|
}) : /* @__PURE__ */ E("input", {
|
|
48162
|
-
type:
|
|
48195
|
+
type: [
|
|
48196
|
+
"email",
|
|
48197
|
+
"number",
|
|
48198
|
+
"date"
|
|
48199
|
+
].includes(n.kind) ? n.kind : "text",
|
|
48163
48200
|
placeholder: n.placeholder || "Type here",
|
|
48164
48201
|
className: `w-full border bg-white px-3.5 py-3 outline-none ${_ ? "" : "pointer-events-none"}`,
|
|
48165
48202
|
style: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { ColumnJSON, ElementJSON, RowJSON, TemplateJSON } from './types';
|
|
3
3
|
export type StockProvider = 'all' | 'unsplash' | 'pexels' | 'pixabay';
|
|
4
|
-
export type FormFieldKind = 'text' | 'email' | 'textarea' | 'select' | 'radio' | 'checkbox';
|
|
4
|
+
export type FormFieldKind = 'text' | 'email' | 'number' | 'date' | 'textarea' | 'select' | 'radio' | 'checkbox';
|
|
5
5
|
export interface StockImageResult {
|
|
6
6
|
id: string;
|
|
7
7
|
src: string;
|
package/package.json
CHANGED