domma-cms 0.16.0 → 0.18.0
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/CLAUDE.md +2 -0
- package/admin/css/dashboard.css +1 -0
- package/admin/dist/domma/domma-tools.css +3 -3
- package/admin/dist/domma/domma-tools.min.js +4 -4
- package/admin/index.html +2 -1
- package/admin/js/api.js +1 -1
- package/admin/js/app.js +1 -1
- package/admin/js/lib/card-builder.js +3 -3
- package/admin/js/lib/effects-builder.js +1 -1
- package/admin/js/lib/markdown-toolbar.js +5 -5
- package/admin/js/templates/dashboard/activity-feed.html +3 -0
- package/admin/js/templates/dashboard/cache.html +32 -0
- package/admin/js/templates/dashboard/health-detail.html +2 -0
- package/admin/js/templates/dashboard/journeys.html +17 -0
- package/admin/js/templates/dashboard/kpi-strip.html +34 -0
- package/admin/js/templates/dashboard/spike-feed.html +3 -0
- package/admin/js/templates/dashboard/top-pages.html +3 -0
- package/admin/js/templates/dashboard/traffic-chart.html +3 -0
- package/admin/js/templates/dashboard.html +26 -44
- package/admin/js/templates/settings.html +26 -0
- package/admin/js/views/block-editor-enhance.js +1 -1
- package/admin/js/views/dashboard/lib/escape.js +1 -0
- package/admin/js/views/dashboard/widgets/activity-feed.js +1 -0
- package/admin/js/views/dashboard/widgets/cache.js +1 -0
- package/admin/js/views/dashboard/widgets/health-detail.js +1 -0
- package/admin/js/views/dashboard/widgets/journeys.js +1 -0
- package/admin/js/views/dashboard/widgets/kpi-strip.js +1 -0
- package/admin/js/views/dashboard/widgets/spike-feed.js +6 -0
- package/admin/js/views/dashboard/widgets/top-pages.js +1 -0
- package/admin/js/views/dashboard/widgets/traffic-chart.js +1 -0
- package/admin/js/views/dashboard.js +1 -1
- package/admin/js/views/form-editor.js +7 -7
- package/admin/js/views/index.js +1 -1
- package/admin/js/views/page-editor.js +42 -37
- package/admin/js/views/settings.js +3 -3
- package/config/cache.json +4 -0
- package/config/cache.json.example +12 -0
- package/config/plugins.json +3 -0
- package/package.json +2 -2
- package/plugins/analytics/daily.json +5 -0
- package/plugins/analytics/journeys.json +10 -0
- package/plugins/analytics/lifetime.json +25 -0
- package/plugins/analytics/plugin.js +231 -16
- package/plugins/analytics/public/inject-body.html +26 -2
- package/public/js/forms.js +1 -1
- package/public/js/site.js +1 -1
- package/server/config.js +12 -1
- package/server/routes/api/cache.js +57 -0
- package/server/routes/api/dashboard.js +239 -0
- package/server/routes/api/navigation.js +2 -0
- package/server/routes/api/settings.js +3 -0
- package/server/routes/public.js +11 -3
- package/server/server.js +18 -3
- package/server/services/blocks.js +3 -0
- package/server/services/cache/drivers/MemoryDriver.js +118 -0
- package/server/services/cache/drivers/NoneDriver.js +12 -0
- package/server/services/cache/index.js +229 -0
- package/server/services/cache/lru.js +61 -0
- package/server/services/collections.js +17 -4
- package/server/services/content.js +7 -2
- package/server/services/email.js +60 -20
- package/server/services/forms.js +3 -0
- package/server/services/health.js +282 -0
- package/server/services/markdown.js +25 -15
- package/server/services/plugins.js +37 -5
- package/server/services/views.js +4 -0
- package/server/templates/page.html +130 -130
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{apiRequest as
|
|
2
|
-
`).filter(y=>y.trim()).map(y=>{const[
|
|
3
|
-
`).filter(h=>h.trim()).map(h=>{const[g,...y]=h.split(":");return{value:g.trim(),label:y.join(":").trim()||g.trim()}});n.cascade={sourceField:u,mapping:i,defaultOptions:f},a=!0}}return a?n:void 0}function v(){b=b.map((e,t)=>V(t))}function x(e){const t=e.find("#fields-list").get(0),o=e.find("#fields-empty-msg").get(0);if(t){if(Array.from(t.querySelectorAll(".fb-field-card")).forEach(n=>n.remove()),b.length===0){o&&(o.style.display="");return}o&&(o.style.display="none"),b.forEach((n,a)=>{const l=n.type==="page-break"?Y(n,a,e):n.type==="spacer"?G(n,a,e):K(n,a,e);t.appendChild(l)})}}function Y(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:2px dashed var(--border-color,#444);border-radius:6px;overflow:hidden;margin-bottom:.5rem;background:var(--card-bg,rgba(255,255,255,.02));";const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.6rem .8rem;cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent="\u2014 Page Break \u2014",l.style.cssText="font-size:.7rem;padding:.15rem .5rem;border-radius:999px;background:rgba(120,120,120,.2);color:var(--text-muted,#888);white-space:nowrap;flex-shrink:0;font-style:italic;";const c=document.createElement("span");c.textContent=e.label||"Untitled Step",c.style.cssText="flex:1;font-weight:600;font-size:.9rem;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text-muted,#888);";const s=document.createElement("div");if(s.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;",t>0){const i=document.createElement("button");i.className="btn btn-xs btn-ghost",i.title="Move up",i.textContent="\u2191",i.addEventListener("click",f=>{f.stopPropagation(),v(),[b[t-1],b[t]]=[b[t],b[t-1]],x(o)}),s.appendChild(i)}if(t<b.length-1){const i=document.createElement("button");i.className="btn btn-xs btn-ghost",i.title="Move down",i.textContent="\u2193",i.addEventListener("click",f=>{f.stopPropagation(),v(),[b[t],b[t+1]]=[b[t+1],b[t]],x(o)}),s.appendChild(i)}const p=document.createElement("button");p.className="btn btn-xs btn-ghost",p.title="Edit step",p.textContent="\u22EF",p.addEventListener("click",i=>{i.stopPropagation(),m.style.display=m.style.display==="none"?"":"none"}),s.appendChild(p);const d=document.createElement("button");d.className="btn btn-xs btn-danger",d.title="Remove page break",d.textContent="\u2715",d.addEventListener("click",async i=>{i.stopPropagation(),await E.confirm("Remove this page break?")&&(v(),b.splice(t,1),x(o))}),s.appendChild(d),a.appendChild(l),a.appendChild(c),a.appendChild(s),a.addEventListener("click",()=>{m.style.display=m.style.display==="none"?"":"none"});const m=document.createElement("div");m.className="fb-field-body",m.style.cssText="padding:.8rem;border-top:1px dashed var(--border-color,#444);display:none;";const r=k([C("Step Title",`fb-pb-label-${t}`,"text",e.label||"","Shown as the wizard step heading"),C("Step Description",`fb-pb-desc-${t}`,"text",e.description||"","Optional sub-heading")]),u=r.querySelector(`#fb-pb-label-${t}`);return u&&u.addEventListener("input",()=>{c.textContent=u.value||"Untitled Step"}),m.appendChild(r),n.appendChild(a),n.appendChild(m),n}function G(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px dashed var(--border-color,#444);border-radius:6px;margin-bottom:.5rem;background:transparent;";const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.4rem .8rem;";const l=document.createElement("div");l.style.cssText="flex:1;height:1px;background:var(--border-color,#444);";const c=document.createElement("span");c.textContent="Spacer",c.style.cssText="font-size:.7rem;color:var(--text-muted,#888);white-space:nowrap;padding:0 .4rem;font-style:italic;";const s=document.createElement("div");s.style.cssText="flex:1;height:1px;background:var(--border-color,#444);";const p=document.createElement("div");if(p.style.cssText="display:flex;gap:.25rem;flex-shrink:0;",t>0){const m=document.createElement("button");m.className="btn btn-xs btn-ghost",m.title="Move up",m.textContent="\u2191",m.addEventListener("click",r=>{r.stopPropagation(),v(),[b[t-1],b[t]]=[b[t],b[t-1]],x(o)}),p.appendChild(m)}if(t<b.length-1){const m=document.createElement("button");m.className="btn btn-xs btn-ghost",m.title="Move down",m.textContent="\u2193",m.addEventListener("click",r=>{r.stopPropagation(),v(),[b[t],b[t+1]]=[b[t+1],b[t]],x(o)}),p.appendChild(m)}const d=document.createElement("button");return d.className="btn btn-xs btn-danger",d.title="Remove spacer",d.textContent="\u2715",d.addEventListener("click",async m=>{m.stopPropagation(),v(),b.splice(t,1),x(o)}),p.appendChild(d),a.appendChild(l),a.appendChild(c),a.appendChild(s),a.appendChild(p),n.appendChild(a),n}function K(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px solid var(--border-color,#333);border-radius:6px;overflow:hidden;margin-bottom:.5rem;";const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.6rem .8rem;background:var(--card-header-bg,rgba(255,255,255,.04));cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent=P(e.type),l.style.cssText="font-size:.7rem;padding:.15rem .45rem;border-radius:999px;background:var(--primary-soft,rgba(99,102,241,.15));color:var(--primary,#6366f1);white-space:nowrap;flex-shrink:0;";const c=document.createElement("span");c.textContent=e.label||"(unlabelled)",c.style.cssText="flex:1;font-weight:600;font-size:.9rem;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;";const s=document.createElement("div");if(s.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;",t>0){const r=document.createElement("button");r.className="btn btn-xs btn-ghost",r.title="Move up",r.textContent="\u2191",r.addEventListener("click",u=>{u.stopPropagation(),v(),[b[t-1],b[t]]=[b[t],b[t-1]],x(o)}),s.appendChild(r)}if(t<b.length-1){const r=document.createElement("button");r.className="btn btn-xs btn-ghost",r.title="Move down",r.textContent="\u2193",r.addEventListener("click",u=>{u.stopPropagation(),v(),[b[t],b[t+1]]=[b[t+1],b[t]],x(o)}),s.appendChild(r)}const p=document.createElement("button");p.className="btn btn-xs btn-ghost",p.title="Edit field",p.textContent="\u22EF",p.addEventListener("click",r=>{r.stopPropagation(),m.style.display=m.style.display==="none"?"":"none"}),s.appendChild(p);const d=document.createElement("button");if(d.className="btn btn-xs btn-danger",d.title="Remove field",d.textContent="\u2715",d.addEventListener("click",async r=>{r.stopPropagation(),await E.confirm("Remove this field?")&&(v(),b.splice(t,1),x(o))}),s.appendChild(d),a.appendChild(l),a.appendChild(c),e.required){const r=document.createElement("span");r.textContent="required",r.style.cssText="font-size:.7rem;color:var(--danger,#ef4444);flex-shrink:0;",a.appendChild(r)}if(M(e.logic)){const r=document.createElement("span");r.textContent="\u26A1",r.title="Has conditional logic",r.style.cssText="font-size:.75rem;color:var(--primary,#6366f1);flex-shrink:0;",a.appendChild(r)}a.appendChild(s),a.addEventListener("click",()=>{m.style.display=m.style.display==="none"?"":"none"});const m=Q(e,t,c);return m.style.display="none",n.appendChild(a),n.appendChild(m),n}function Q(e,t,o){const n=document.createElement("div");n.className="fb-field-body",n.style.cssText="padding:.8rem;border-top:1px solid var(--border-color,#333);";const a=k([C("Label",`fb-label-${t}`,"text",e.label||"","Shown above the field"),C("Field Name",`fb-name-${t}`,"text",e.name||"","Used as data key")]),l=k([ae("Type",`fb-type-${t}`,B,e.type||"string"),j("Required",`fb-required-${t}`,e.required||!1)]),c=k([C("Placeholder",`fb-placeholder-${t}`,"text",e.placeholder||"","Hint text inside the field")]),s=k([C("Helper Text",`fb-helper-${t}`,"text",e.helper||"","Shown below the field"),C("Tooltip",`fb-tooltip-${t}`,"text",e.tooltip||"","Shown on hover via a help icon next to the label")]),p=e.formConfig?.span,d=k([C("Column Span",`fb-span-${t}`,"number",p&&p!=="full"?String(p):"1","Columns to span (grid only)"),j("Full Width",`fb-fullwidth-${t}`,p==="full")]);d.classList.add("fb-grid-row"),d.style.display=document.getElementById("setting-layout")?.value==="grid"?"flex":"none",n.appendChild(a),n.appendChild(l),n.appendChild(c),n.appendChild(s),n.appendChild(d);const m=n.querySelector(`#fb-label-${t}`),r=n.querySelector(`#fb-name-${t}`);m&&m.addEventListener("input",()=>{o&&(o.textContent=m.value||"(unlabelled)"),r&&!r.dataset.manuallyEdited&&(r.value=I(m.value))}),r&&r.addEventListener("input",()=>{r.dataset.manuallyEdited="1"});const u=n.querySelector(`#fb-type-${t}`);u&&u.addEventListener("change",()=>{const f=n.closest(".fb-field-card");if(f){const y=f.querySelector("span");y&&(y.textContent=P(u.value))}const h=n.querySelector(".fb-field-extras");h&&h.remove();const g=O(u.value,e,t);g&&n.appendChild(g)});const i=O(e.type,e,t);return i&&n.appendChild(i),n.appendChild(le(e,t)),n}const X=[{value:"equals",label:"equals"},{value:"not_equals",label:"does not equal"},{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},{value:"starts_with",label:"starts with"},{value:"ends_with",label:"ends with"},{value:"greater_than",label:"is greater than"},{value:"less_than",label:"is less than"},{value:"is_empty",label:"is empty"},{value:"is_not_empty",label:"is not empty"},{value:"in",label:"is one of (comma sep)"},{value:"not_in",label:"is not one of (comma sep)"},{value:"matches_regex",label:"matches regex"}],_=new Set(["is_empty","is_not_empty"]);function $(e){const t=document.createElement("p");return t.textContent=e,t.style.cssText="font-size:.75rem;font-weight:700;color:var(--text-muted,#888);margin:.6rem 0 .3rem;text-transform:uppercase;letter-spacing:.04em;",t}function L(e,t,o,n,a){const l=document.createElement("div");l.className="fb-logic-cond-row",l.style.cssText="display:flex;gap:.35rem;align-items:center;margin-bottom:.35rem;flex-wrap:wrap;";const c=document.createElement("span");c.textContent="When",c.style.cssText="font-size:.73rem;color:var(--text-muted,#888);flex-shrink:0;";const s=document.createElement("select");s.className="form-select fb-logic-cond-field",s.style.cssText="flex:1 1 140px;min-width:140px;",t.forEach(i=>{const f=document.createElement("option");f.value=i.value,f.textContent=i.label,e&&i.value===e.field&&(f.selected=!0),s.appendChild(f)});const p=document.createElement("select");p.className="form-select fb-logic-cond-op",p.style.cssText="flex:1 1 160px;min-width:140px;",X.forEach(i=>{const f=document.createElement("option");f.value=i.value,f.textContent=i.label,e&&i.value===e.operator&&(f.selected=!0),p.appendChild(f)});const d=document.createElement("input");d.type="text",d.className="form-input fb-logic-cond-val",d.placeholder="value",d.style.cssText="flex:1 1 120px;min-width:100px;",d.value=e?.value||"",e&&_.has(e.operator)&&(d.style.display="none"),p.addEventListener("change",()=>{d.style.display=_.has(p.value)?"none":""});const m=document.createElement("span");m.textContent="\u2192",m.style.cssText="font-size:.73rem;color:var(--text-muted,#888);flex-shrink:0;";const r=document.createElement("select");r.className=`form-select ${n}`,r.style.cssText="flex:1 1 140px;min-width:120px;",o.forEach(i=>{const f=document.createElement("option");f.value=i.value,f.textContent=i.label,i.value===a&&(f.selected=!0),r.appendChild(f)});const u=document.createElement("button");return u.type="button",u.className="btn btn-xs btn-danger",u.textContent="\u2715",u.style.flexShrink="0",u.addEventListener("click",()=>l.remove()),l.appendChild(c),l.appendChild(s),l.appendChild(p),l.appendChild(d),l.appendChild(m),l.appendChild(r),l.appendChild(u),l}function Z(e,t,o){const n=document.createElement("div");n.dataset.logicSection="visibility",n.appendChild($("Visibility"));const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.4rem;";const l=document.createElement("span");l.textContent="Default:",l.style.cssText="font-size:.8rem;flex-shrink:0;";const c=document.createElement("select");c.className="form-select fb-logic-vis-default",c.style.cssText="max-width:240px;",[{value:"visible",label:"Visible"},{value:"hidden",label:"Hidden"}].forEach(i=>{const f=document.createElement("option");f.value=i.value,f.textContent=i.label,i.value===(e.default||"visible")&&(f.selected=!0),c.appendChild(f)}),a.appendChild(l),a.appendChild(c),n.appendChild(a);const s=document.createElement("div");s.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.4rem;";const p=document.createElement("span");p.textContent="Transition:",p.style.cssText="font-size:.8rem;flex-shrink:0;";const d=document.createElement("select");d.className="form-select fb-logic-vis-transition",d.style.cssText="max-width:240px;",[{value:"none",label:"None (instant)"},{value:"fade",label:"Fade"},{value:"slide",label:"Slide"},{value:"scale",label:"Scale"}].forEach(i=>{const f=document.createElement("option");f.value=i.value,f.textContent=i.label,i.value===(e.transition||"none")&&(f.selected=!0),d.appendChild(f)}),s.appendChild(p),s.appendChild(d),n.appendChild(s);const m=document.createElement("div");m.className="fb-logic-vis-rules";const r=o.map(i=>({value:i.name,label:i.label||i.name})),u=[{value:"visible",label:"Show"},{value:"hidden",label:"Hide"}];if((e.conditions||[]).forEach(i=>{const f=(i.when?.all||i.when?.any||[])[0],h=i.then==="hidden"?"hidden":"visible";r.length>0&&m.appendChild(L(f,r,u,"fb-logic-vis-then",h))}),n.appendChild(m),r.length>0){const i=document.createElement("button");i.type="button",i.className="btn btn-xs btn-ghost",i.style.cssText="font-size:.73rem;margin-top:.2rem;",i.textContent="+ Add visibility rule",i.addEventListener("click",()=>m.appendChild(L(null,r,u,"fb-logic-vis-then","visible"))),n.appendChild(i)}return n}function ee(e,t,o){const n=document.createElement("div");n.dataset.logicSection="requirement",n.appendChild($("Conditional Requirement"));const a=document.createElement("label");a.style.cssText="display:flex;align-items:center;gap:.4rem;font-size:.8rem;cursor:pointer;margin-bottom:.4rem;";const l=document.createElement("input");l.type="checkbox",l.className="fb-logic-req-default",l.checked=e.default===!0,a.appendChild(l),a.appendChild(document.createTextNode("Required by default")),n.appendChild(a);const c=document.createElement("div");c.className="fb-logic-req-rules";const s=o.map(d=>({value:d.name,label:d.label||d.name})),p=[{value:"true",label:"Make required"},{value:"false",label:"Make optional"}];if((e.conditions||[]).forEach(d=>{const m=(d.when?.all||d.when?.any||[])[0],r=d.then===!0?"true":"false";s.length>0&&c.appendChild(L(m,s,p,"fb-logic-req-then",r))}),n.appendChild(c),s.length>0){const d=document.createElement("button");d.type="button",d.className="btn btn-xs btn-ghost",d.style.cssText="font-size:.73rem;margin-top:.2rem;",d.textContent="+ Add requirement rule",d.addEventListener("click",()=>c.appendChild(L(null,s,p,"fb-logic-req-then","true"))),n.appendChild(d)}return n}function A(e){const t=document.createElement("div");t.className="fb-logic-val-rule",t.style.cssText="display:flex;gap:.35rem;align-items:center;margin-bottom:.35rem;flex-wrap:wrap;";const o=document.createElement("select");o.className="form-select fb-logic-val-type",o.style.cssText="flex:0 0 140px;",[{value:"regex",label:"Regex"},{value:"match",label:"Match field"}].forEach(s=>{const p=document.createElement("option");p.value=s.value,p.textContent=s.label,s.value===(e?.type||"regex")&&(p.selected=!0),o.appendChild(p)});const n=document.createElement("input");n.type="text",n.className="form-input fb-logic-val-pattern",n.placeholder=e?.type==="match"?"field name":"pattern",n.value=e?.pattern||e?.field||"",n.style.cssText="flex:3;";const a=document.createElement("input");a.type="text",a.className="form-input fb-logic-val-flags",a.placeholder="flags",a.value=e?.flags||"",a.style.cssText="flex:0 0 55px;",e?.type==="match"&&(a.style.display="none"),o.addEventListener("change",()=>{a.style.display=o.value==="match"?"none":"",n.placeholder=o.value==="match"?"field name":"pattern"});const l=document.createElement("input");l.type="text",l.className="form-input fb-logic-val-message",l.placeholder="Error message",l.value=e?.message||"",l.style.cssText="flex:4;";const c=document.createElement("button");return c.type="button",c.className="btn btn-xs btn-danger",c.textContent="\u2715",c.style.flexShrink="0",c.addEventListener("click",()=>t.remove()),t.appendChild(o),t.appendChild(n),t.appendChild(a),t.appendChild(l),t.appendChild(c),t}function te(e,t,o){const n=document.createElement("div");n.dataset.logicSection="validation",n.appendChild($("Custom Validation"));const a=document.createElement("div");a.className="fb-logic-val-rules",(e||[]).forEach(c=>a.appendChild(A(c))),n.appendChild(a);const l=document.createElement("button");return l.type="button",l.className="btn btn-xs btn-ghost",l.style.cssText="font-size:.73rem;margin-top:.2rem;",l.textContent="+ Add validation rule",l.addEventListener("click",()=>a.appendChild(A(null))),n.appendChild(l),n}function ne(e,t,o){const n=document.createElement("div");n.dataset.logicSection="cascade",n.appendChild($("Cascade Options"));const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.5rem;";const l=document.createElement("span");l.textContent="Source field:",l.style.cssText="font-size:.8rem;flex-shrink:0;";const c=document.createElement("select");c.className="form-select fb-logic-cascade-source",c.style.cssText="flex:1;";const s=document.createElement("option");s.value="",s.textContent="\u2014 none \u2014",c.appendChild(s),o.forEach(u=>{const i=document.createElement("option");i.value=u.name,i.textContent=u.label||u.name,u.name===e.sourceField&&(i.selected=!0),c.appendChild(i)}),a.appendChild(l),a.appendChild(c),n.appendChild(a);const p=document.createElement("p");p.textContent='Mapping JSON \u2014 {"value":[{"value":"...","label":"..."}]}',p.style.cssText="font-size:.73rem;color:var(--text-muted,#888);margin:.3rem 0 .2rem;";const d=document.createElement("textarea");d.className="form-input fb-logic-cascade-mapping",d.rows=4,d.style.cssText="font-family:monospace;",d.placeholder='{"uk": [{"value": "london", "label": "London"}]}',d.value=e.mapping?JSON.stringify(e.mapping,null,2):"",n.appendChild(p),n.appendChild(d);const m=document.createElement("p");m.textContent="Default options (one per line: value:Label)",m.style.cssText="font-size:.73rem;color:var(--text-muted,#888);margin:.3rem 0 .2rem;";const r=document.createElement("textarea");return r.className="form-input fb-logic-cascade-defaults",r.rows=3,r.style.cssText="font-family:monospace;",r.placeholder=`option1:Option 1
|
|
4
|
-
option2:Option 2`,
|
|
5
|
-
`),n.appendChild(m),n.appendChild(r),n}function le(e,t){const o=e.logic||{},n=b.filter((r,u)=>u!==t&&r.type!=="page-break"&&r.type!=="spacer"),a=document.createElement("div");a.className="fb-field-logic",a.style.cssText="margin-top:.75rem;border-top:1px solid var(--border-color,#333);padding-top:.5rem;";const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;justify-content:space-between;cursor:pointer;padding:.15rem 0;";const c=document.createElement("span");c.style.cssText="font-size:.8rem;font-weight:600;color:var(--text-muted,#888);",c.textContent="\u26A1 Conditional Logic";const s=M(o),p=document.createElement("button");p.type="button",p.className="btn btn-xs btn-ghost",p.textContent=s?"\u25BE":"\u25B8";const d=document.createElement("div");d.className="fb-logic-body",d.style.cssText="padding:.25rem 0 .25rem;"+(s?"":"display:none;"),l.addEventListener("click",()=>{const r=d.style.display==="none";d.style.display=r?"":"none",p.textContent=r?"\u25BE":"\u25B8"}),l.appendChild(c),l.appendChild(p),a.appendChild(l),d.appendChild(Z(o.visibility||{},t,n)),d.appendChild(ee(o.requirement||{},t,n)),d.appendChild(te(o.validation||[],t,n));const m=document.getElementById(`fb-type-${t}`)?.value||e.type;return z.has(m)&&d.appendChild(ne(o.cascade||{},t,n)),a.appendChild(d),a}function O(e,t,o){const n=document.createElement("div");return n.className="fb-field-extras",z.has(e)&&n.appendChild(oe(t.options||[],o)),e==="textarea"&&n.appendChild(k([C("Rows",`fb-rows-${o}`,"number",t.formConfig?.rows||4,"Height of textarea")])),(e==="string"||e==="textarea")&&n.appendChild(k([C("Min Length",`fb-minlength-${o}`,"number",t.minLength||"",""),C("Max Length",`fb-maxlength-${o}`,"number",t.maxLength||"","")])),e==="number"&&n.appendChild(k([C("Min",`fb-min-${o}`,"number",t.min??"",""),C("Max",`fb-max-${o}`,"number",t.max??"","")])),n.children.length?n:null}function k(e){const t=document.createElement("div");return t.style.cssText="display:flex;gap:.75rem;margin-bottom:.6rem;",e.forEach(o=>{o&&t.appendChild(o)}),t}function C(e,t,o,n,a){const l=document.createElement("div");l.style.flex="1";const c=document.createElement("label");c.htmlFor=t,c.className="form-label",c.textContent=e,c.style.fontSize=".8rem";const s=document.createElement("input");if(s.id=t,s.type=o||"text",s.className="form-input",s.value=n??"",l.appendChild(c),l.appendChild(s),a){const p=document.createElement("p");p.className="form-hint text-muted",p.textContent=a,p.style.cssText="font-size:.73rem;margin-top:.2rem;",l.appendChild(p)}return l}function ae(e,t,o,n){const a=document.createElement("div");a.style.flex="1";const l=document.createElement("label");l.htmlFor=t,l.className="form-label",l.textContent=e,l.style.fontSize=".8rem";const c=document.createElement("select");return c.id=t,c.className="form-select",o.forEach(s=>{const p=document.createElement("option");p.value=s.value,p.textContent=s.label,s.value===n&&(p.selected=!0),c.appendChild(p)}),a.appendChild(l),a.appendChild(c),a}function j(e,t,o){const n=document.createElement("div");n.style.cssText="flex:0;min-width:80px;display:flex;flex-direction:column;justify-content:flex-end;";const a=document.createElement("label");a.style.cssText="display:flex;align-items:center;gap:.4rem;cursor:pointer;font-size:.8rem;white-space:nowrap;";const l=document.createElement("input");return l.id=t,l.type="checkbox",l.checked=o,a.appendChild(l),a.appendChild(document.createTextNode(e)),n.appendChild(a),n}function oe(e,t){const o=document.createElement("div");o.style.cssText="margin-top:.4rem;";const n=document.createElement("p");n.textContent="Options (one per line: value or value:Label)",n.style.cssText="font-size:.8rem;font-weight:600;margin-bottom:.3rem;";const a=document.createElement("textarea");return a.id=`fb-options-${t}`,a.className="form-input",a.rows=4,a.placeholder=`yes:Yes
|
|
1
|
+
import{apiRequest as O}from"/admin/js/api.js";import{makeIconInput as se}from"/admin/js/lib/shortcode-modal.js";const J=[{value:"string",label:"Text (single line)"},{value:"email",label:"Email"},{value:"tel",label:"Phone"},{value:"number",label:"Number"},{value:"textarea",label:"Textarea (multi-line)"},{value:"select",label:"Dropdown (select)"},{value:"radio",label:"Radio buttons"},{value:"checkbox",label:"Single checkbox"},{value:"checkbox-group",label:"Checkbox group"},{value:"chooser",label:"Chooser (visual options)"},{value:"date",label:"Date"},{value:"time",label:"Time"},{value:"url",label:"URL"},{value:"password",label:"Password"},{value:"file",label:"File upload"},{value:"hidden",label:"Hidden field"}],V=new Set(["select","radio","checkbox-group","chooser"]);let b=[],T=null,A=null,M=null;function G(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")}function W(e){return J.find(t=>t.value===e)?.label||e}function Y(e){return e?!!(e.visibility?.conditions?.length||e.requirement?.conditions?.length||e.validation?.length||e.cascade?.sourceField):!1}function ie(e){const t={...b[e]};if(t.type==="spacer")return t;if(t.type==="page-break"){const h=document.getElementById(`fb-pb-label-${e}`),y=document.getElementById(`fb-pb-desc-${e}`);return h&&(t.label=h.value.trim()||t.label),y&&(t.description=y.value.trim()),t}const s=document.getElementById(`fb-label-${e}`),n=document.getElementById(`fb-name-${e}`),o=document.getElementById(`fb-type-${e}`),l=document.getElementById(`fb-required-${e}`),a=document.getElementById(`fb-placeholder-${e}`),i=document.getElementById(`fb-helper-${e}`),c=document.getElementById(`fb-tooltip-${e}`);if(s&&(t.label=s.value.trim()||t.label),n&&(t.name=n.value.trim()||t.name),o&&(t.type=o.value||t.type),l&&(t.required=l.checked),a&&(t.placeholder=a.value.trim()),i&&(t.helper=i.value.trim()),c&&(t.tooltip=c.value.trim()),t.type==="chooser"){const h=document.getElementById(`fb-chooser-variant-${e}`)?.value;h&&(t.variant=h);const y=document.getElementById(`fb-chooser-multiple-${e}`);y&&(t.multiple=y.checked);const k=document.getElementById(`fb-chooser-density-${e}`)?.value;k&&(t.density=k);const N=document.getElementById(`fb-chooser-columns-${e}`)?.value;N!==""&&N!==void 0&&(t.columns=parseInt(N,10)||3);const q=document.getElementById(`fb-chooser-accent-${e}`)?.value.trim();q?t.accent=q:delete t.accent;const $=document.getElementById(`fb-chooser-accent-style-${e}`)?.value;$?t.accentStyle=$:delete t.accentStyle;const L=document.getElementById(`fb-chooser-glow-${e}`);L&&(t.glow=L.checked);const B=document.getElementById(`fb-chooser-glow-colour-${e}`)?.value.trim();B?t.glowColour=B:delete t.glowColour;const S=document.getElementById(`fb-chooser-shadow-${e}`)?.value;S&&S!=="none"?t.shadow=S:delete t.shadow;const z=document.getElementById(`fb-chooser-shadow-colour-${e}`)?.value.trim();z?t.shadowColour=z:delete t.shadowColour,D(e),b[e]&&Array.isArray(b[e].options)&&(t.options=b[e].options)}else if(V.has(t.type)){const h=document.getElementById(`fb-options-${e}`);h&&(t.options=h.value.split(`
|
|
2
|
+
`).filter(y=>y.trim()).map(y=>{const[k,...N]=y.split(":");return{value:k.trim(),label:N.join(":").trim()||k.trim()}}))}if(t.type==="textarea"){const h=parseInt(document.getElementById(`fb-rows-${e}`)?.value,10);h>0&&(t.formConfig={...t.formConfig||{},rows:h})}const r=document.getElementById(`fb-span-${e}`),m=document.getElementById(`fb-fullwidth-${e}`);if(r||m){const h={...t.formConfig||{}};if(m?.checked)h.span="full";else{const y=parseInt(r?.value,10);y>1?h.span=y:delete h.span}t.formConfig=Object.keys(h).length?h:void 0}const p=document.getElementById(`fb-minlength-${e}`)?.value;p&&(t.minLength=parseInt(p,10));const u=document.getElementById(`fb-maxlength-${e}`)?.value;u&&(t.maxLength=parseInt(u,10));const d=document.getElementById(`fb-min-${e}`)?.value;d!==""&&d!==void 0&&(t.min=parseFloat(d));const f=document.getElementById(`fb-max-${e}`)?.value;f!==""&&f!==void 0&&(t.max=parseFloat(f));const g=ce(e);return g?t.logic=g:delete t.logic,t}function ce(e){const t=document.querySelector(`.fb-field-card[data-index="${e}"]`);if(!t)return;const s=t.querySelector(".fb-field-logic");if(!s)return;const n={};let o=!1;const l=s.querySelector('[data-logic-section="visibility"]');if(l){const r=l.querySelector(".fb-logic-vis-default"),m=l.querySelector(".fb-logic-vis-transition"),p=Array.from(l.querySelectorAll(".fb-logic-cond-row")).map(f=>{const g=f.querySelector(".fb-logic-cond-field"),h=f.querySelector(".fb-logic-cond-op"),y=f.querySelector(".fb-logic-cond-val"),k=f.querySelector(".fb-logic-vis-then");return g?.value?{when:{all:[{field:g.value,operator:h.value,value:y.value}]},then:k.value}:null}).filter(Boolean),u=r?.value||"visible",d=m?.value||"none";(u!=="visible"||p.length>0||d!=="none")&&(n.visibility={default:u,conditions:p},d!=="none"&&(n.visibility.transition=d),o=!0)}const a=s.querySelector('[data-logic-section="requirement"]');if(a){const r=a.querySelector(".fb-logic-req-default"),m=Array.from(a.querySelectorAll(".fb-logic-cond-row")).map(p=>{const u=p.querySelector(".fb-logic-cond-field"),d=p.querySelector(".fb-logic-cond-op"),f=p.querySelector(".fb-logic-cond-val"),g=p.querySelector(".fb-logic-req-then");return u?.value?{when:{all:[{field:u.value,operator:d.value,value:f.value}]},then:g.value==="true"}:null}).filter(Boolean);m.length>0&&(n.requirement={default:r?.checked===!0,conditions:m},o=!0)}const i=s.querySelector('[data-logic-section="validation"]');if(i){const r=Array.from(i.querySelectorAll(".fb-logic-val-rule")).map(m=>{const p=m.querySelector(".fb-logic-val-type"),u=m.querySelector(".fb-logic-val-pattern"),d=m.querySelector(".fb-logic-val-flags"),f=m.querySelector(".fb-logic-val-message");if(!u?.value.trim())return null;const g=p?.value||"regex",h={type:g,message:f?.value.trim()||"Invalid value."};return g==="regex"?(h.pattern=u.value.trim(),d?.value.trim()&&(h.flags=d.value.trim())):h.field=u.value.trim(),h}).filter(Boolean);r.length>0&&(n.validation=r,o=!0)}const c=s.querySelector('[data-logic-section="cascade"]');if(c){const r=c.querySelector(".fb-logic-cascade-source"),m=c.querySelector(".fb-logic-cascade-mapping"),p=c.querySelector(".fb-logic-cascade-defaults"),u=r?.value?.trim();if(u){let d={};try{d=JSON.parse(m?.value||"{}")}catch{}const f=(p?.value||"").split(`
|
|
3
|
+
`).filter(g=>g.trim()).map(g=>{const[h,...y]=g.split(":");return{value:h.trim(),label:y.join(":").trim()||h.trim()}});n.cascade={sourceField:u,mapping:d,defaultOptions:f},o=!0}}return o?n:void 0}function C(){b=b.map((e,t)=>ie(t))}function w(e){const t=e.find("#fields-list").get(0),s=e.find("#fields-empty-msg").get(0);if(t){if(Array.from(t.querySelectorAll(".fb-field-card")).forEach(n=>n.remove()),b.length===0){s&&(s.style.display="");return}s&&(s.style.display="none"),b.forEach((n,o)=>{const l=n.type==="page-break"?re(n,o,e):n.type==="spacer"?de(n,o,e):pe(n,o,e);t.appendChild(l)})}}function re(e,t,s){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:2px dashed var(--border-color,#444);border-radius:6px;overflow:hidden;margin-bottom:.5rem;background:var(--card-bg,rgba(255,255,255,.02));";const o=document.createElement("div");o.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.6rem .8rem;cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent="\u2014 Page Break \u2014",l.style.cssText="font-size:.7rem;padding:.15rem .5rem;border-radius:999px;background:rgba(120,120,120,.2);color:var(--text-muted,#888);white-space:nowrap;flex-shrink:0;font-style:italic;";const a=document.createElement("span");a.textContent=e.label||"Untitled Step",a.style.cssText="flex:1;font-weight:600;font-size:.9rem;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text-muted,#888);";const i=document.createElement("div");if(i.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;",t>0){const d=document.createElement("button");d.className="btn btn-xs btn-ghost",d.title="Move up",d.textContent="\u2191",d.addEventListener("click",f=>{f.stopPropagation(),C(),[b[t-1],b[t]]=[b[t],b[t-1]],w(s)}),i.appendChild(d)}if(t<b.length-1){const d=document.createElement("button");d.className="btn btn-xs btn-ghost",d.title="Move down",d.textContent="\u2193",d.addEventListener("click",f=>{f.stopPropagation(),C(),[b[t],b[t+1]]=[b[t+1],b[t]],w(s)}),i.appendChild(d)}const c=document.createElement("button");c.className="btn btn-xs btn-ghost",c.title="Edit step",c.textContent="\u22EF",c.addEventListener("click",d=>{d.stopPropagation(),m.style.display=m.style.display==="none"?"":"none"}),i.appendChild(c);const r=document.createElement("button");r.className="btn btn-xs btn-danger",r.title="Remove page break",r.textContent="\u2715",r.addEventListener("click",async d=>{d.stopPropagation(),await E.confirm("Remove this page break?")&&(C(),b.splice(t,1),w(s))}),i.appendChild(r),o.appendChild(l),o.appendChild(a),o.appendChild(i),o.addEventListener("click",()=>{m.style.display=m.style.display==="none"?"":"none"});const m=document.createElement("div");m.className="fb-field-body",m.style.cssText="padding:.8rem;border-top:1px dashed var(--border-color,#444);display:none;";const p=v([x("Step Title",`fb-pb-label-${t}`,"text",e.label||"","Shown as the wizard step heading"),x("Step Description",`fb-pb-desc-${t}`,"text",e.description||"","Optional sub-heading")]),u=p.querySelector(`#fb-pb-label-${t}`);return u&&u.addEventListener("input",()=>{a.textContent=u.value||"Untitled Step"}),m.appendChild(p),n.appendChild(o),n.appendChild(m),n}function de(e,t,s){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px dashed var(--border-color,#444);border-radius:6px;margin-bottom:.5rem;background:transparent;";const o=document.createElement("div");o.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.4rem .8rem;";const l=document.createElement("div");l.style.cssText="flex:1;height:1px;background:var(--border-color,#444);";const a=document.createElement("span");a.textContent="Spacer",a.style.cssText="font-size:.7rem;color:var(--text-muted,#888);white-space:nowrap;padding:0 .4rem;font-style:italic;";const i=document.createElement("div");i.style.cssText="flex:1;height:1px;background:var(--border-color,#444);";const c=document.createElement("div");if(c.style.cssText="display:flex;gap:.25rem;flex-shrink:0;",t>0){const m=document.createElement("button");m.className="btn btn-xs btn-ghost",m.title="Move up",m.textContent="\u2191",m.addEventListener("click",p=>{p.stopPropagation(),C(),[b[t-1],b[t]]=[b[t],b[t-1]],w(s)}),c.appendChild(m)}if(t<b.length-1){const m=document.createElement("button");m.className="btn btn-xs btn-ghost",m.title="Move down",m.textContent="\u2193",m.addEventListener("click",p=>{p.stopPropagation(),C(),[b[t],b[t+1]]=[b[t+1],b[t]],w(s)}),c.appendChild(m)}const r=document.createElement("button");return r.className="btn btn-xs btn-danger",r.title="Remove spacer",r.textContent="\u2715",r.addEventListener("click",async m=>{m.stopPropagation(),C(),b.splice(t,1),w(s)}),c.appendChild(r),o.appendChild(l),o.appendChild(a),o.appendChild(i),o.appendChild(c),n.appendChild(o),n}function pe(e,t,s){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px solid var(--border-color,#333);border-radius:6px;overflow:hidden;margin-bottom:.5rem;";const o=document.createElement("div");o.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.6rem .8rem;background:var(--card-header-bg,rgba(255,255,255,.04));cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent=W(e.type),l.style.cssText="font-size:.7rem;padding:.15rem .45rem;border-radius:999px;background:var(--primary-soft,rgba(99,102,241,.15));color:var(--primary,#6366f1);white-space:nowrap;flex-shrink:0;";const a=document.createElement("span");a.textContent=e.label||"(unlabelled)",a.style.cssText="flex:1;font-weight:600;font-size:.9rem;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;";const i=document.createElement("div");if(i.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;",t>0){const p=document.createElement("button");p.className="btn btn-xs btn-ghost",p.title="Move up",p.textContent="\u2191",p.addEventListener("click",u=>{u.stopPropagation(),C(),[b[t-1],b[t]]=[b[t],b[t-1]],w(s)}),i.appendChild(p)}if(t<b.length-1){const p=document.createElement("button");p.className="btn btn-xs btn-ghost",p.title="Move down",p.textContent="\u2193",p.addEventListener("click",u=>{u.stopPropagation(),C(),[b[t],b[t+1]]=[b[t+1],b[t]],w(s)}),i.appendChild(p)}const c=document.createElement("button");c.className="btn btn-xs btn-ghost",c.title="Edit field",c.textContent="\u22EF",c.addEventListener("click",p=>{p.stopPropagation(),m.style.display=m.style.display==="none"?"":"none"}),i.appendChild(c);const r=document.createElement("button");if(r.className="btn btn-xs btn-danger",r.title="Remove field",r.textContent="\u2715",r.addEventListener("click",async p=>{p.stopPropagation(),await E.confirm("Remove this field?")&&(C(),b.splice(t,1),w(s))}),i.appendChild(r),o.appendChild(l),o.appendChild(a),e.required){const p=document.createElement("span");p.textContent="required",p.style.cssText="font-size:.7rem;color:var(--danger,#ef4444);flex-shrink:0;",o.appendChild(p)}if(Y(e.logic)){const p=document.createElement("span");p.textContent="\u26A1",p.title="Has conditional logic",p.style.cssText="font-size:.75rem;color:var(--primary,#6366f1);flex-shrink:0;",o.appendChild(p)}o.appendChild(i),o.addEventListener("click",()=>{m.style.display=m.style.display==="none"?"":"none"});const m=me(e,t,a);return m.style.display="none",n.appendChild(o),n.appendChild(m),n}function me(e,t,s){const n=document.createElement("div");n.className="fb-field-body",n.style.cssText="padding:.8rem;border-top:1px solid var(--border-color,#333);";const o=v([x("Label",`fb-label-${t}`,"text",e.label||"","Shown above the field"),x("Field Name",`fb-name-${t}`,"text",e.name||"","Used as data key")]),l=v([Se("Type",`fb-type-${t}`,J,e.type||"string"),ne("Required",`fb-required-${t}`,e.required||!1)]),a=v([x("Placeholder",`fb-placeholder-${t}`,"text",e.placeholder||"","Hint text inside the field")]),i=v([x("Helper Text",`fb-helper-${t}`,"text",e.helper||"","Shown below the field"),x("Tooltip",`fb-tooltip-${t}`,"text",e.tooltip||"","Shown on hover via a help icon next to the label")]),c=e.formConfig?.span,r=v([x("Column Span",`fb-span-${t}`,"number",c&&c!=="full"?String(c):"1","Columns to span (grid only)"),ne("Full Width",`fb-fullwidth-${t}`,c==="full")]);r.classList.add("fb-grid-row"),r.style.display=document.getElementById("setting-layout")?.value==="grid"?"flex":"none",n.appendChild(o),n.appendChild(l),n.appendChild(a),n.appendChild(i),n.appendChild(r);const m=n.querySelector(`#fb-label-${t}`),p=n.querySelector(`#fb-name-${t}`);m&&m.addEventListener("input",()=>{s&&(s.textContent=m.value||"(unlabelled)"),p&&!p.dataset.manuallyEdited&&(p.value=G(m.value))}),p&&p.addEventListener("input",()=>{p.dataset.manuallyEdited="1"});const u=n.querySelector(`#fb-type-${t}`);u&&u.addEventListener("change",()=>{const f=n.closest(".fb-field-card");if(f){const y=f.querySelector("span");y&&(y.textContent=W(u.value))}const g=n.querySelector(".fb-field-extras");g&&g.remove();const h=X(u.value,e,t);h&&n.appendChild(h)});const d=X(e.type,e,t);return d&&n.appendChild(d),n.appendChild(ye(e,t)),n}const ue=[{value:"equals",label:"equals"},{value:"not_equals",label:"does not equal"},{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},{value:"starts_with",label:"starts with"},{value:"ends_with",label:"ends with"},{value:"greater_than",label:"is greater than"},{value:"less_than",label:"is less than"},{value:"is_empty",label:"is empty"},{value:"is_not_empty",label:"is not empty"},{value:"in",label:"is one of (comma sep)"},{value:"not_in",label:"is not one of (comma sep)"},{value:"matches_regex",label:"matches regex"}],K=new Set(["is_empty","is_not_empty"]);function P(e){const t=document.createElement("p");return t.textContent=e,t.style.cssText="font-size:.75rem;font-weight:700;color:var(--text-muted,#888);margin:.6rem 0 .3rem;text-transform:uppercase;letter-spacing:.04em;",t}function _(e,t,s,n,o){const l=document.createElement("div");l.className="fb-logic-cond-row",l.style.cssText="display:flex;gap:.35rem;align-items:center;margin-bottom:.35rem;flex-wrap:wrap;";const a=document.createElement("span");a.textContent="When",a.style.cssText="font-size:.73rem;color:var(--text-muted,#888);flex-shrink:0;";const i=document.createElement("select");i.className="form-select fb-logic-cond-field",i.style.cssText="flex:1 1 140px;min-width:140px;",t.forEach(d=>{const f=document.createElement("option");f.value=d.value,f.textContent=d.label,e&&d.value===e.field&&(f.selected=!0),i.appendChild(f)});const c=document.createElement("select");c.className="form-select fb-logic-cond-op",c.style.cssText="flex:1 1 160px;min-width:140px;",ue.forEach(d=>{const f=document.createElement("option");f.value=d.value,f.textContent=d.label,e&&d.value===e.operator&&(f.selected=!0),c.appendChild(f)});const r=document.createElement("input");r.type="text",r.className="form-input fb-logic-cond-val",r.placeholder="value",r.style.cssText="flex:1 1 120px;min-width:100px;",r.value=e?.value||"",e&&K.has(e.operator)&&(r.style.display="none"),c.addEventListener("change",()=>{r.style.display=K.has(c.value)?"none":""});const m=document.createElement("span");m.textContent="\u2192",m.style.cssText="font-size:.73rem;color:var(--text-muted,#888);flex-shrink:0;";const p=document.createElement("select");p.className=`form-select ${n}`,p.style.cssText="flex:1 1 140px;min-width:120px;",s.forEach(d=>{const f=document.createElement("option");f.value=d.value,f.textContent=d.label,d.value===o&&(f.selected=!0),p.appendChild(f)});const u=document.createElement("button");return u.type="button",u.className="btn btn-xs btn-danger",u.textContent="\u2715",u.style.flexShrink="0",u.addEventListener("click",()=>l.remove()),l.appendChild(a),l.appendChild(i),l.appendChild(c),l.appendChild(r),l.appendChild(m),l.appendChild(p),l.appendChild(u),l}function fe(e,t,s){const n=document.createElement("div");n.dataset.logicSection="visibility",n.appendChild(P("Visibility"));const o=document.createElement("div");o.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.4rem;";const l=document.createElement("span");l.textContent="Default:",l.style.cssText="font-size:.8rem;flex-shrink:0;";const a=document.createElement("select");a.className="form-select fb-logic-vis-default",a.style.cssText="max-width:240px;",[{value:"visible",label:"Visible"},{value:"hidden",label:"Hidden"}].forEach(d=>{const f=document.createElement("option");f.value=d.value,f.textContent=d.label,d.value===(e.default||"visible")&&(f.selected=!0),a.appendChild(f)}),o.appendChild(l),o.appendChild(a),n.appendChild(o);const i=document.createElement("div");i.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.4rem;";const c=document.createElement("span");c.textContent="Transition:",c.style.cssText="font-size:.8rem;flex-shrink:0;";const r=document.createElement("select");r.className="form-select fb-logic-vis-transition",r.style.cssText="max-width:240px;",[{value:"none",label:"None (instant)"},{value:"fade",label:"Fade"},{value:"slide",label:"Slide"},{value:"scale",label:"Scale"}].forEach(d=>{const f=document.createElement("option");f.value=d.value,f.textContent=d.label,d.value===(e.transition||"none")&&(f.selected=!0),r.appendChild(f)}),i.appendChild(c),i.appendChild(r),n.appendChild(i);const m=document.createElement("div");m.className="fb-logic-vis-rules";const p=s.map(d=>({value:d.name,label:d.label||d.name})),u=[{value:"visible",label:"Show"},{value:"hidden",label:"Hide"}];if((e.conditions||[]).forEach(d=>{const f=(d.when?.all||d.when?.any||[])[0],g=d.then==="hidden"?"hidden":"visible";p.length>0&&m.appendChild(_(f,p,u,"fb-logic-vis-then",g))}),n.appendChild(m),p.length>0){const d=document.createElement("button");d.type="button",d.className="btn btn-xs btn-ghost",d.style.cssText="font-size:.73rem;margin-top:.2rem;",d.textContent="+ Add visibility rule",d.addEventListener("click",()=>m.appendChild(_(null,p,u,"fb-logic-vis-then","visible"))),n.appendChild(d)}return n}function be(e,t,s){const n=document.createElement("div");n.dataset.logicSection="requirement",n.appendChild(P("Conditional Requirement"));const o=document.createElement("label");o.style.cssText="display:flex;align-items:center;gap:.4rem;font-size:.8rem;cursor:pointer;margin-bottom:.4rem;";const l=document.createElement("input");l.type="checkbox",l.className="fb-logic-req-default",l.checked=e.default===!0,o.appendChild(l),o.appendChild(document.createTextNode("Required by default")),n.appendChild(o);const a=document.createElement("div");a.className="fb-logic-req-rules";const i=s.map(r=>({value:r.name,label:r.label||r.name})),c=[{value:"true",label:"Make required"},{value:"false",label:"Make optional"}];if((e.conditions||[]).forEach(r=>{const m=(r.when?.all||r.when?.any||[])[0],p=r.then===!0?"true":"false";i.length>0&&a.appendChild(_(m,i,c,"fb-logic-req-then",p))}),n.appendChild(a),i.length>0){const r=document.createElement("button");r.type="button",r.className="btn btn-xs btn-ghost",r.style.cssText="font-size:.73rem;margin-top:.2rem;",r.textContent="+ Add requirement rule",r.addEventListener("click",()=>a.appendChild(_(null,i,c,"fb-logic-req-then","true"))),n.appendChild(r)}return n}function Q(e){const t=document.createElement("div");t.className="fb-logic-val-rule",t.style.cssText="display:flex;gap:.35rem;align-items:center;margin-bottom:.35rem;flex-wrap:wrap;";const s=document.createElement("select");s.className="form-select fb-logic-val-type",s.style.cssText="flex:0 0 140px;",[{value:"regex",label:"Regex"},{value:"match",label:"Match field"}].forEach(i=>{const c=document.createElement("option");c.value=i.value,c.textContent=i.label,i.value===(e?.type||"regex")&&(c.selected=!0),s.appendChild(c)});const n=document.createElement("input");n.type="text",n.className="form-input fb-logic-val-pattern",n.placeholder=e?.type==="match"?"field name":"pattern",n.value=e?.pattern||e?.field||"",n.style.cssText="flex:3;";const o=document.createElement("input");o.type="text",o.className="form-input fb-logic-val-flags",o.placeholder="flags",o.value=e?.flags||"",o.style.cssText="flex:0 0 55px;",e?.type==="match"&&(o.style.display="none"),s.addEventListener("change",()=>{o.style.display=s.value==="match"?"none":"",n.placeholder=s.value==="match"?"field name":"pattern"});const l=document.createElement("input");l.type="text",l.className="form-input fb-logic-val-message",l.placeholder="Error message",l.value=e?.message||"",l.style.cssText="flex:4;";const a=document.createElement("button");return a.type="button",a.className="btn btn-xs btn-danger",a.textContent="\u2715",a.style.flexShrink="0",a.addEventListener("click",()=>t.remove()),t.appendChild(s),t.appendChild(n),t.appendChild(o),t.appendChild(l),t.appendChild(a),t}function he(e,t,s){const n=document.createElement("div");n.dataset.logicSection="validation",n.appendChild(P("Custom Validation"));const o=document.createElement("div");o.className="fb-logic-val-rules",(e||[]).forEach(a=>o.appendChild(Q(a))),n.appendChild(o);const l=document.createElement("button");return l.type="button",l.className="btn btn-xs btn-ghost",l.style.cssText="font-size:.73rem;margin-top:.2rem;",l.textContent="+ Add validation rule",l.addEventListener("click",()=>o.appendChild(Q(null))),n.appendChild(l),n}function ge(e,t,s){const n=document.createElement("div");n.dataset.logicSection="cascade",n.appendChild(P("Cascade Options"));const o=document.createElement("div");o.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.5rem;";const l=document.createElement("span");l.textContent="Source field:",l.style.cssText="font-size:.8rem;flex-shrink:0;";const a=document.createElement("select");a.className="form-select fb-logic-cascade-source",a.style.cssText="flex:1;";const i=document.createElement("option");i.value="",i.textContent="\u2014 none \u2014",a.appendChild(i),s.forEach(u=>{const d=document.createElement("option");d.value=u.name,d.textContent=u.label||u.name,u.name===e.sourceField&&(d.selected=!0),a.appendChild(d)}),o.appendChild(l),o.appendChild(a),n.appendChild(o);const c=document.createElement("p");c.textContent='Mapping JSON \u2014 {"value":[{"value":"...","label":"..."}]}',c.style.cssText="font-size:.73rem;color:var(--text-muted,#888);margin:.3rem 0 .2rem;";const r=document.createElement("textarea");r.className="form-input fb-logic-cascade-mapping",r.rows=4,r.style.cssText="font-family:monospace;",r.placeholder='{"uk": [{"value": "london", "label": "London"}]}',r.value=e.mapping?JSON.stringify(e.mapping,null,2):"",n.appendChild(c),n.appendChild(r);const m=document.createElement("p");m.textContent="Default options (one per line: value:Label)",m.style.cssText="font-size:.73rem;color:var(--text-muted,#888);margin:.3rem 0 .2rem;";const p=document.createElement("textarea");return p.className="form-input fb-logic-cascade-defaults",p.rows=3,p.style.cssText="font-family:monospace;",p.placeholder=`option1:Option 1
|
|
4
|
+
option2:Option 2`,p.value=(e.defaultOptions||[]).map(u=>{const d=typeof u=="string"?u:u.value??"",f=typeof u=="string"?u:u.label??d;return d===f?d:`${d}:${f}`}).join(`
|
|
5
|
+
`),n.appendChild(m),n.appendChild(p),n}function ye(e,t){const s=e.logic||{},n=b.filter((p,u)=>u!==t&&p.type!=="page-break"&&p.type!=="spacer"),o=document.createElement("div");o.className="fb-field-logic",o.style.cssText="margin-top:.75rem;border-top:1px solid var(--border-color,#333);padding-top:.5rem;";const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;justify-content:space-between;cursor:pointer;padding:.15rem 0;";const a=document.createElement("span");a.style.cssText="font-size:.8rem;font-weight:600;color:var(--text-muted,#888);",a.textContent="\u26A1 Conditional Logic";const i=Y(s),c=document.createElement("button");c.type="button",c.className="btn btn-xs btn-ghost",c.textContent=i?"\u25BE":"\u25B8";const r=document.createElement("div");r.className="fb-logic-body",r.style.cssText="padding:.25rem 0 .25rem;"+(i?"":"display:none;"),l.addEventListener("click",()=>{const p=r.style.display==="none";r.style.display=p?"":"none",c.textContent=p?"\u25BE":"\u25B8"}),l.appendChild(a),l.appendChild(c),o.appendChild(l),r.appendChild(fe(s.visibility||{},t,n)),r.appendChild(be(s.requirement||{},t,n)),r.appendChild(he(s.validation||[],t,n));const m=document.getElementById(`fb-type-${t}`)?.value||e.type;return V.has(m)&&r.appendChild(ge(s.cascade||{},t,n)),o.appendChild(r),o}function X(e,t,s){const n=document.createElement("div");return n.className="fb-field-extras",e==="chooser"?(n.appendChild(ve(t,s)),n.appendChild(Ce(t.options||[],s))):(V.has(e)&&n.appendChild(Te(t.options||[],s)),e==="textarea"&&n.appendChild(v([x("Rows",`fb-rows-${s}`,"number",t.formConfig?.rows||4,"Height of textarea")])),(e==="string"||e==="textarea")&&n.appendChild(v([x("Min Length",`fb-minlength-${s}`,"number",t.minLength||"",""),x("Max Length",`fb-maxlength-${s}`,"number",t.maxLength||"","")])),e==="number"&&n.appendChild(v([x("Min",`fb-min-${s}`,"number",t.min??"",""),x("Max",`fb-max-${s}`,"number",t.max??"","")]))),n.children.length?n:null}function Z(e){const t=document.createElement("div");t.className="fb-chooser-section",t.style.cssText="border:1px solid var(--dm-border, #e5e7eb); border-radius:6px; margin-top:.5rem; overflow:hidden;";const s=document.createElement("div");s.style.cssText="padding:.4rem .6rem; background:color-mix(in srgb, var(--dm-bg, #f9fafb) 60%, transparent); font-weight:600; font-size:.82rem; border-bottom:1px solid var(--dm-border, #e5e7eb);",s.textContent=e,t.appendChild(s);const n=document.createElement("div");return n.className="fb-chooser-section-body",n.style.cssText="padding:.55rem .6rem; display:flex; flex-direction:column; gap:.45rem;",t.appendChild(n),{wrap:t,body:n}}function j(e,t,s,n,o){const l=document.createElement("div");l.style.flex="1";const a=document.createElement("label");a.htmlFor=e,a.className="form-label",a.textContent=t,a.style.fontSize=".8rem";const i=document.createElement("select");if(i.id=e,i.className="form-input",n.forEach(([c,r])=>{const m=document.createElement("option");m.value=c,m.textContent=r,String(c)===String(s)&&(m.selected=!0),i.appendChild(m)}),l.appendChild(a),l.appendChild(i),o){const c=document.createElement("p");c.className="form-hint text-muted",c.textContent=o,c.style.cssText="font-size:.72rem;margin-top:.2rem;",l.appendChild(c)}return l}function ee(e,t,s,n){const o=document.createElement("div");o.style.flex="1";const l=document.createElement("label");l.style.cssText="display:inline-flex;align-items:center;gap:.4rem;font-size:.82rem;";const a=document.createElement("input");if(a.id=e,a.type="checkbox",a.checked=!!s,l.appendChild(a),l.appendChild(document.createTextNode(" "+t)),o.appendChild(l),n){const i=document.createElement("p");i.className="form-hint text-muted",i.textContent=n,i.style.cssText="font-size:.72rem;margin-top:.2rem;",o.appendChild(i)}return o}function H(e,t,s,n,o){const l=document.createElement("div");l.style.flex="1";const a=document.createElement("label");a.htmlFor=e,a.className="form-label",a.textContent=t,a.style.fontSize=".8rem",l.appendChild(a);const i=document.createElement("div");i.style.cssText="display:flex;gap:.4rem;align-items:stretch;";const c=document.createElement("input");c.id=e,c.type="text",c.className="form-input",c.value=s||"",n&&(c.placeholder=n),c.style.flex="1";const r=document.createElement("input");r.type="color",r.title="Pick a colour",r.style.cssText="width:36px;height:auto;padding:0;border:1px solid var(--dm-border,#e5e7eb);border-radius:4px;cursor:pointer;";const m=String(c.value).match(/^#[0-9a-fA-F]{3,8}$/);if(r.value=m?c.value:"#000000",r.addEventListener("input",()=>{c.value=r.value,c.dispatchEvent(new Event("input",{bubbles:!0}))}),i.appendChild(c),i.appendChild(r),l.appendChild(i),o){const p=document.createElement("p");p.className="form-hint text-muted",p.textContent=o,p.style.cssText="font-size:.72rem;margin-top:.2rem;",l.appendChild(p)}return l}function ve(e,t){const s=document.createElement("div");s.style.cssText="margin-top:.5rem; display:flex; flex-direction:column; gap:.4rem;";const n=Z("Layout");n.body.appendChild(v([j(`fb-chooser-variant-${t}`,"Variant",e.variant||"card",[["card","Card \u2014 rich tiles"],["chip","Chip \u2014 compact pills"]],"Card supports description and grid columns; chips wrap."),ee(`fb-chooser-multiple-${t}`,"Multi-select",!!e.multiple,"Off = single (radio); on = multi (checkbox).")])),n.body.appendChild(v([j(`fb-chooser-density-${t}`,"Density",e.density||"comfortable",[["comfortable","Comfortable"],["compact","Compact"]],"Compact strips description (card variant only)."),x("Columns",`fb-chooser-columns-${t}`,"number",e.columns||3,"Card grid (1\u20136). Ignored for chips.")])),s.appendChild(n.wrap);const o=Z("Visual");return o.body.appendChild(v([H(`fb-chooser-accent-${t}`,"Accent",e.accent||"","primary / success / #ec4899","Selected highlight colour \u2014 semantic name or any CSS colour."),j(`fb-chooser-accent-style-${t}`,"Accent style",e.accentStyle||"border",[["border","Border (default)"],["solid","Solid"],["glow","Glow"],["overlay","Overlay"],["underline","Underline"]],"Visual treatment of the selected state.")])),o.body.appendChild(v([ee(`fb-chooser-glow-${t}`,"Glow on selected",!!e.glow,"Soft outer glow."),H(`fb-chooser-glow-colour-${t}`,"Glow colour",e.glowColour||"","defaults to accent","Optional; semantic name or CSS colour.")])),o.body.appendChild(v([j(`fb-chooser-shadow-${t}`,"Shadow",e.shadow||"none",[["none","None"],["sm","Small"],["md","Medium"],["lg","Large"],["xl","Extra Large"]],"Drop shadow on every option."),H(`fb-chooser-shadow-colour-${t}`,"Shadow colour",e.shadowColour||"","rgba(0,0,0,0.1)","Optional shadow tint.")])),s.appendChild(o.wrap),s}function xe(e,t,s,n){const o=document.createElement("div");o.className="fb-chooser-option-row",o.dataset.optIdx=String(s),o.style.cssText="border:1px solid var(--dm-border,#e5e7eb); border-radius:4px; padding:.5rem; background:var(--dm-bg-alt, color-mix(in srgb, var(--dm-card-bg, #fff) 92%, var(--dm-text, #111))); display:flex; flex-direction:column; gap:.35rem;";const l=document.createElement("div");l.style.cssText="display:flex; gap:.4rem; align-items:center;";const a=document.createElement("div");a.style.cssText="display:flex; flex-direction:column; gap:1px;";const i=document.createElement("button");i.type="button",i.className="btn btn-secondary btn-sm",i.style.padding=".1rem .3rem",i.title="Move up",i.textContent="\u25B2",i.addEventListener("click",S=>{S.preventDefault(),te(t,s,-1,n)});const c=document.createElement("button");c.type="button",c.className="btn btn-secondary btn-sm",c.style.padding=".1rem .3rem",c.title="Move down",c.textContent="\u25BC",c.addEventListener("click",S=>{S.preventDefault(),te(t,s,1,n)}),a.appendChild(i),a.appendChild(c),l.appendChild(a);const r=document.createElement("input");r.type="text",r.className="form-input fb-chooser-opt-value",r.placeholder="value",r.value=e.value||"",r.style.flex="1",l.appendChild(r);const m=document.createElement("input");m.type="text",m.className="form-input fb-chooser-opt-label",m.placeholder="label (visible to users)",m.value=e.label||"",m.style.flex="2",l.appendChild(m);const p=document.createElement("button");p.type="button",p.className="btn btn-secondary btn-sm",p.title="Remove option",p.textContent="\u2715",p.addEventListener("click",S=>{S.preventDefault(),ke(t,s,n)}),l.appendChild(p),o.appendChild(l);const u=document.createElement("div");u.style.cssText="display:flex; gap:.4rem;";const d=se("icon name (optional)",e.icon||"");d.input.classList.add("fb-chooser-opt-icon"),d.el.style.flex="1",u.appendChild(d.el);const f=document.createElement("input");f.type="text",f.className="form-input fb-chooser-opt-description",f.placeholder="description (card + comfortable only)",f.value=e.description||"",f.style.flex="2",u.appendChild(f),o.appendChild(u);const g=document.createElement("div");g.style.cssText="display:flex; gap:.4rem;";const h=document.createElement("input");h.type="text",h.className="form-input fb-chooser-opt-tooltip",h.placeholder="tooltip (hover hint)",h.value=e.tooltip||"",h.style.flex="2",g.appendChild(h);const y=document.createElement("input");y.type="text",y.className="form-input fb-chooser-opt-badge-text",y.placeholder="badge text",y.value=e.badge?.text||"",y.style.flex="1",g.appendChild(y);const k=document.createElement("select");k.className="form-input fb-chooser-opt-badge-type",k.style.flex="1",[["","no badge"],["primary","primary"],["success","success"],["info","info"],["warning","warning"],["danger","danger"]].forEach(([S,z])=>{const I=document.createElement("option");I.value=S,I.textContent=z,(e.badge?.type||"")===S&&(I.selected=!0),k.appendChild(I)}),g.appendChild(k),o.appendChild(g);const N=document.createElement("div");N.style.cssText="display:flex; gap:1rem; font-size:.8rem;";const q=document.createElement("label");q.style.cssText="display:inline-flex;align-items:center;gap:.3rem;";const $=document.createElement("input");$.type="checkbox",$.className="fb-chooser-opt-recommended",$.checked=!!e.recommended,q.appendChild($),q.appendChild(document.createTextNode(" Recommended")),N.appendChild(q);const L=document.createElement("label");L.style.cssText="display:inline-flex;align-items:center;gap:.3rem;";const B=document.createElement("input");return B.type="checkbox",B.className="fb-chooser-opt-disabled",B.checked=!!e.disabled,L.appendChild(B),L.appendChild(document.createTextNode(" Disabled")),N.appendChild(L),o.appendChild(N),o}function Ce(e,t){const s=document.createElement("div");s.style.cssText="margin-top:.5rem;";const n=document.createElement("div");n.style.cssText="display:flex; align-items:center; justify-content:space-between; margin-bottom:.4rem;";const o=document.createElement("p");o.textContent="Options",o.style.cssText="font-size:.85rem;font-weight:600;margin:0;",n.appendChild(o);const l=document.createElement("button");l.type="button",l.className="btn btn-secondary btn-sm",l.textContent="+ Add option",n.appendChild(l),s.appendChild(n);const a=document.createElement("div");a.className="fb-chooser-options-list",a.id=`fb-chooser-options-${t}`,a.style.cssText="display:flex; flex-direction:column; gap:.4rem;",s.appendChild(a);const i=()=>{a.replaceChildren();const c=Ee(t);(c.length?c:e||[]).forEach((m,p)=>{a.appendChild(xe(m,t,p,i))})};return l.addEventListener("click",c=>{c.preventDefault(),we(t,i)}),i(),s}function Ee(e){const t=b[e];return!t||!Array.isArray(t.options)?[]:t.options}function U(e){return b[e]?(Array.isArray(b[e].options)||(b[e].options=[]),b[e].options):[]}function we(e,t){D(e),U(e).push({value:"new",label:"New option"}),t()}function ke(e,t,s){D(e),U(e).splice(t,1),s()}function te(e,t,s,n){D(e);const o=U(e),l=t+s;if(l<0||l>=o.length)return;const[a]=o.splice(t,1);o.splice(l,0,a),n()}function D(e){const t=document.getElementById(`fb-chooser-options-${e}`);if(!t)return;const s=t.querySelectorAll(".fb-chooser-option-row"),n=[];s.forEach(o=>{const l={value:o.querySelector(".fb-chooser-opt-value")?.value.trim()||"",label:o.querySelector(".fb-chooser-opt-label")?.value.trim()||""},a=o.querySelector(".fb-chooser-opt-icon")?.value.trim();a&&(l.icon=a);const i=o.querySelector(".fb-chooser-opt-description")?.value.trim();i&&(l.description=i);const c=o.querySelector(".fb-chooser-opt-tooltip")?.value.trim();c&&(l.tooltip=c);const r=o.querySelector(".fb-chooser-opt-badge-text")?.value.trim(),m=o.querySelector(".fb-chooser-opt-badge-type")?.value;(r||m)&&(l.badge={},r&&(l.badge.text=r),m&&(l.badge.type=m)),o.querySelector(".fb-chooser-opt-recommended")?.checked&&(l.recommended=!0),o.querySelector(".fb-chooser-opt-disabled")?.checked&&(l.disabled=!0),n.push(l)}),b[e]&&(b[e].options=n)}function v(e){const t=document.createElement("div");return t.style.cssText="display:flex;gap:.75rem;margin-bottom:.6rem;",e.forEach(s=>{s&&t.appendChild(s)}),t}function x(e,t,s,n,o){const l=document.createElement("div");l.style.flex="1";const a=document.createElement("label");a.htmlFor=t,a.className="form-label",a.textContent=e,a.style.fontSize=".8rem";const i=document.createElement("input");if(i.id=t,i.type=s||"text",i.className="form-input",i.value=n??"",l.appendChild(a),l.appendChild(i),o){const c=document.createElement("p");c.className="form-hint text-muted",c.textContent=o,c.style.cssText="font-size:.73rem;margin-top:.2rem;",l.appendChild(c)}return l}function Se(e,t,s,n){const o=document.createElement("div");o.style.flex="1";const l=document.createElement("label");l.htmlFor=t,l.className="form-label",l.textContent=e,l.style.fontSize=".8rem";const a=document.createElement("select");return a.id=t,a.className="form-select",s.forEach(i=>{const c=document.createElement("option");c.value=i.value,c.textContent=i.label,i.value===n&&(c.selected=!0),a.appendChild(c)}),o.appendChild(l),o.appendChild(a),o}function ne(e,t,s){const n=document.createElement("div");n.style.cssText="flex:0;min-width:80px;display:flex;flex-direction:column;justify-content:flex-end;";const o=document.createElement("label");o.style.cssText="display:flex;align-items:center;gap:.4rem;cursor:pointer;font-size:.8rem;white-space:nowrap;";const l=document.createElement("input");return l.id=t,l.type="checkbox",l.checked=s,o.appendChild(l),o.appendChild(document.createTextNode(e)),n.appendChild(o),n}function Te(e,t){const s=document.createElement("div");s.style.cssText="margin-top:.4rem;";const n=document.createElement("p");n.textContent="Options (one per line: value or value:Label)",n.style.cssText="font-size:.8rem;font-weight:600;margin-bottom:.3rem;";const o=document.createElement("textarea");return o.id=`fb-options-${t}`,o.className="form-input",o.rows=4,o.placeholder=`yes:Yes
|
|
6
6
|
no:No
|
|
7
|
-
maybe:Maybe`,
|
|
8
|
-
`),
|
|
7
|
+
maybe:Maybe`,o.value=(e||[]).map(l=>{const a=typeof l=="string"?l:l.value??"",i=typeof l=="string"?l:l.label??a;return a===i?a:`${a}:${i}`}).join(`
|
|
8
|
+
`),o.style.fontFamily="monospace",s.appendChild(n),s.appendChild(o),s}function le(e){return C(),{title:e.find("#field-title").val().trim(),slug:e.find("#field-slug").val().trim(),description:e.find("#field-description").val().trim(),...e.find("#field-bundled").is(":checked")?{bundled:!0}:{},fields:b,settings:{submitText:e.find("#setting-submit-text").val().trim()||"Submit",successMessage:e.find("#setting-success-message").val().trim()||"Thank you.",layout:e.find("#setting-layout").val()||"stacked",columns:parseInt(e.find("#setting-columns").val(),10)||2,submitSpan:e.find("#setting-submit-span").val()||"",honeypot:e.find("#setting-honeypot").prop("checked"),rateLimitPerMinute:parseInt(e.find("#setting-rate-limit").val(),10)||3,successRedirect:e.find("#setting-success-redirect").val().trim()||null,actionSlug:e.find("#action-cms-slug").val()||null},actions:{email:{enabled:e.find("#action-email-enabled").prop("checked"),recipients:e.find("#action-email-recipients").val().trim(),subjectPrefix:e.find("#action-email-subject-prefix").val().trim()},webhook:{enabled:e.find("#action-webhook-enabled").prop("checked"),url:e.find("#action-webhook-url").val().trim(),method:e.find("#action-webhook-method").val()},...A!==null&&{collection:A}}}}function Ne(e){const t=[];let s=[],n="Step 1",o="";return e.forEach(l=>{l.type==="page-break"?(t.push({title:n,description:o,fields:s}),s=[],n=l.label||`Step ${t.length+1}`,o=l.description||""):l.type!=="spacer"&&s.push(l)}),(s.length||t.length===0)&&t.push({title:n,description:o,fields:s}),t}function oe(e,t){const s={};return e.forEach(n=>{if(n.type==="page-break"||n.type==="spacer")return;const o={...n.formConfig||{}};o.span==="full"&&t&&(o.span=t);const a={type:n.type==="checkbox"?"boolean":n.type==="date"?"string":n.type,label:n.label,required:n.required,options:n.options,formConfig:{...n.placeholder&&{placeholder:n.placeholder},...n.helper&&{helperText:n.helper},...n.tooltip&&{tooltip:n.tooltip},...o}};n.type==="chooser"&&(n.variant&&(a.variant=n.variant),n.multiple&&(a.multiple=!0),n.density&&(a.density=n.density),n.columns&&(a.columns=n.columns),n.accent&&(a.accent=n.accent),n.accentStyle&&(a.accentStyle=n.accentStyle),n.glow&&(a.glow=!0),n.glowColour&&(a.glowColour=n.glowColour),n.shadow&&(a.shadow=n.shadow),n.shadowColour&&(a.shadowColour=n.shadowColour)),s[n.name]=a}),s}function ae(e,t){const s=typeof e=="string"?document.querySelector(e):e;s&&(t||[]).forEach(n=>{if(n.type!=="date"||!n.name)return;const o=s.querySelector(`[name="${n.name}"]`);o&&o.type!=="date"&&(o.type="date")})}export const formEditorView={templateUrl:"/admin/js/templates/form-editor.html",async onMount(e){b=[],T=null,A=null;const t=window.location.hash.match(/\/forms\/edit\/([^/?#]+)/);T=t?t[1]:null;let s=null;if(T)try{s=await O(`/forms/${T}`),b=s.fields||[],A=s.actions?.collection??null}catch{E.toast("Could not load form.",{type:"error"})}if(s?e.find("#editor-title").get(0).textContent=`Edit: ${s.title}`:e.find("#editor-title").get(0).textContent="New Form",T||e.find("#field-title").get(0).addEventListener("input",function(){e.find("#field-slug").val(G(this.value))}),E.tabs(e.find("#editor-tabs").get(0)),s){e.find("#field-title").val(s.title),e.find("#field-slug").val(s.slug),e.find("#field-description").val(s.description||""),e.find("#field-bundled").prop("checked",!!s.bundled);const l=s.settings||{};e.find("#setting-submit-text").val(l.submitText||"Submit"),e.find("#setting-success-message").val(l.successMessage||""),e.find("#setting-layout").val(l.layout||"stacked"),e.find("#setting-columns").val(l.columns||2),e.find("#setting-submit-span").val(l.submitSpan||""),e.find("#columns-group").get(0).style.display=l.layout==="grid"?"":"none",e.find("#setting-honeypot").prop("checked",l.honeypot!==!1),e.find("#setting-rate-limit").val(l.rateLimitPerMinute||3),e.find("#setting-success-redirect").val(l.successRedirect||"");const a=s.actions?.email||{};e.find("#action-email-enabled").prop("checked",a.enabled||!1),e.find("#action-email-recipients").val(a.recipients||""),e.find("#action-email-subject-prefix").val(a.subjectPrefix||"");const i=s.actions?.webhook||{};e.find("#action-webhook-enabled").prop("checked",i.enabled||!1),e.find("#action-webhook-url").val(i.url||""),e.find("#action-webhook-method").val(i.method||"POST")}const n=s?.settings?.actionSlug||"";try{const l=await O("/actions").catch(()=>[]),a=e.find("#action-cms-slug").get(0);if((Array.isArray(l)?l:[]).forEach(i=>{const c=document.createElement("option");c.value=i.slug,c.textContent=i.title||i.slug,i.slug===n&&(c.selected=!0),a.appendChild(c)}),!l.length){const i=document.createElement("option");i.value="",i.textContent="No actions available",i.disabled=!0,a.appendChild(i)}}catch{}e.find("#setting-layout").get(0)?.addEventListener("change",function(){const l=this.value==="grid";e.find("#columns-group").get(0).style.display=l?"":"none",document.querySelectorAll(".fb-grid-row").forEach(a=>{a.style.display=l?"flex":"none"})}),w(e);const o=e.find("#add-element-menu").get(0);e.find("#add-element-btn").get(0).addEventListener("click",l=>{l.stopPropagation(),o.style.display=o.style.display==="none"?"":"none"}),M&&document.removeEventListener("click",M),M=()=>{o&&(o.style.display="none")},document.addEventListener("click",M),e.find("#add-field-btn").get(0).addEventListener("click",()=>{o&&(o.style.display="none"),C();const l=b.length;b.push({name:`field_${l+1}`,type:"string",label:"New Field",required:!1,placeholder:""}),w(e);const a=e.find("#fields-list").get(0)?.lastElementChild;if(a){const i=a.querySelector(".fb-field-body");i&&(i.style.display="")}}),e.find("#add-spacer-btn").get(0).addEventListener("click",()=>{o&&(o.style.display="none"),C(),b.push({type:"spacer"}),w(e)}),e.find("#add-page-break-btn").get(0).addEventListener("click",()=>{o&&(o.style.display="none"),C();const l=b.filter(a=>a.type==="page-break").length+2;b.push({type:"page-break",label:`Step ${l}`,description:""}),w(e)}),e.find("#save-form-btn").get(0).addEventListener("click",async()=>{const l=le(e);if(!l.title){E.toast("Please enter a form title.",{type:"error"});return}try{T?(await O(`/forms/${T}`,{method:"PUT",body:JSON.stringify(l)}),E.toast("Form saved.",{type:"success"})):(T=(await O("/forms",{method:"POST",body:JSON.stringify(l)})).slug,R.navigate(`/forms/edit/${T}`),E.toast("Form created.",{type:"success"}))}catch(a){E.toast(a.message||"Failed to save form.",{type:"error"})}}),e.find("#preview-btn").get(0).addEventListener("click",()=>{const l=le(e),a=e.find("#preview-container").get(0);if(!a)return;const i=e.find("#preview-test-result").get(0),c=e.find("#preview-test-badge").get(0);i&&(i.style.display="none",i.textContent=""),c&&(c.style.display=T?"":"none"),e.find("#preview-card").get(0).style.display="",a.textContent="";const r=document.createElement("div");r.id="fb-preview-form",a.appendChild(r);const m=T?async u=>{i&&(i.style.display="none",i.textContent="");try{const d=await fetch(`/api/forms/submit/${T}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}),f=await d.json();if(!d.ok)throw new Error(f.error||"Submission failed.");i&&(i.textContent=f.message||l.settings?.successMessage||"Submitted successfully.",i.style.cssText="display:block;margin-top:.75rem;padding:.6rem .9rem;border-radius:6px;font-size:.9rem;background:rgba(34,197,94,.12);color:var(--success,#22c55e);"),E.toast("Test submission stored.",{type:"success"})}catch(d){i&&(i.textContent=d.message,i.style.cssText="display:block;margin-top:.75rem;padding:.6rem .9rem;border-radius:6px;font-size:.9rem;background:rgba(239,68,68,.12);color:var(--danger,#ef4444);"),E.toast(d.message,{type:"error"})}return!1}:()=>!1,p=l.fields.some(u=>u.type==="page-break");if(typeof F<"u"){const u=l.settings?.columns||2,d=l.settings?.layout||"stacked";if(p&&F.wizard){const f=Ne(l.fields).map(g=>({title:g.title,description:g.description,fields:oe(g.fields,u)}));F.wizard("#fb-preview-form",{schema:{steps:f},onSubmit:m}),ae("#fb-preview-form",l.fields)}else if(F.render){const f=oe(l.fields,u),g={};if(l.fields.forEach(h=>{if(!(!h.name||h.type==="page-break"||h.type==="spacer")&&(h.type==="select"||h.type==="multiselect")&&h.required){const y=(h.options||[])[0];y&&(g[h.name]=typeof y=="object"?y.value:y)}}),F.render("#fb-preview-form",f,g,{submitText:l.settings?.submitText||"Submit",layout:d,columns:u,onSubmit:m}),d==="grid"&&l.settings?.submitSpan==="full"){const h=document.querySelector("#fb-preview-form .form-buttons");h&&h.classList.add("col-span-full")}ae("#fb-preview-form",l.fields)}window.FormLogicEngine&&l.fields.some(f=>f.logic)&&requestAnimationFrame(()=>{new window.FormLogicEngine.FormLogicRuntime({fields:l.fields},r).init()})}else{const u=document.createElement("p");u.textContent=`${l.fields.filter(d=>d.type!=="page-break").length} field(s): ${l.fields.filter(d=>d.type!=="page-break").map(d=>d.label).join(", ")}`,u.style.cssText="color:var(--muted);font-style:italic;",r.appendChild(u)}e.find("#preview-card").get(0).scrollIntoView({behavior:"smooth",block:"start"})})}};
|
package/admin/js/views/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dashboardView as o}from"./dashboard.js";import{pagesView as i}from"./pages.js";import{pageEditorView as r}from"./page-editor.js
|
|
1
|
+
import{dashboardView as o}from"./dashboard.js";import{pagesView as i}from"./pages.js";import{pageEditorView as r}from"./page-editor.js";import{settingsView as t}from"./settings.js";import{navigationView as e}from"./navigation.js";import{notificationsView as m}from"./notifications.js";import{layoutsView as s}from"./layouts.js";import{mediaView as f}from"./media.js";import{loginView as p}from"./login.js";import{usersView as w}from"./users.js";import{userEditorView as n}from"./user-editor.js";import{pluginsView as c}from"./plugins.js";import{documentationView as V}from"./documentation.js";import{tutorialsView as l}from"./tutorials.js";import{apiReferenceView as a}from"./api-reference.js";import{collectionsView as d}from"./collections.js";import{collectionEditorView as E}from"./collection-editor.js";import{collectionEntriesView as u}from"./collection-entries.js";import{formsView as g}from"./forms.js";import{formEditorView as v}from"./form-editor.js";import{formSubmissionsView as b}from"./form-submissions.js";import{viewsListView as k}from"./views-list.js";import{viewEditorView as y}from"./view-editor.js";import{viewPreviewView as L}from"./view-preview.js";import{actionsListView as P}from"./actions-list.js";import{actionEditorView as h}from"./action-editor.js";import{proDocsView as D}from"./pro-docs.js";import{blocksView as R}from"./blocks.js";import{blockEditorView as S}from"./block-editor.js";import"./block-editor-enhance.js";import{componentsView as x}from"./components.js";import{componentEditorView as j}from"./component-editor.js";import{myProfileView as q}from"./my-profile.js";import{rolesView as z}from"./roles.js";import{roleEditorView as A}from"./role-editor.js";import{effectsView as B}from"./effects.js";export const views={dashboard:o,pages:i,pageEditor:r,settings:t,navigation:e,layouts:s,media:f,login:p,users:w,userEditor:n,plugins:c,documentation:V,tutorials:l,apiReference:a,collections:d,collectionEditor:E,collectionEntries:u,forms:g,formEditor:v,formSubmissions:b,viewsList:k,viewEditor:y,viewPreview:L,actionsList:P,actionEditor:h,proDocs:D,blocks:R,blockEditor:S,components:x,componentEditor:j,myProfile:q,roles:z,roleEditor:A,effects:B,notifications:m};
|