domma-cms 0.36.2 → 0.36.4
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/admin/css/admin.css +1 -1
- package/admin/js/lib/card-builder.js +3 -3
- package/admin/js/lib/editor-folding.js +1 -1
- package/admin/js/lib/effects-builder.js +2 -2
- package/admin/js/lib/markdown-toolbar.js +3 -3
- package/admin/js/lib/shortcode-context-menu.js +4 -4
- package/admin/js/lib/shortcode-modal.js +1 -1
- package/admin/js/lib/shortcode-registry.js +1 -1
- package/admin/js/lib/timeline-builder.js +2 -2
- package/admin/js/templates/form-editor.html +17 -16
- package/admin/js/views/actions-list.js +1 -1
- package/admin/js/views/api-endpoint-editor.js +3 -3
- package/admin/js/views/api-endpoints.js +2 -2
- package/admin/js/views/api-tokens.js +4 -4
- package/admin/js/views/blocks.js +5 -5
- package/admin/js/views/collection-editor.js +4 -4
- package/admin/js/views/collection-entries.js +1 -1
- package/admin/js/views/component-editor.js +1 -1
- package/admin/js/views/components.js +2 -2
- package/admin/js/views/effects.js +1 -1
- package/admin/js/views/form-editor.js +7 -7
- package/admin/js/views/form-submissions.js +1 -1
- package/admin/js/views/forms.js +1 -1
- package/admin/js/views/layouts.js +1 -1
- package/admin/js/views/login.js +1 -1
- package/admin/js/views/menu-editor.js +8 -8
- package/admin/js/views/menu-locations.js +1 -1
- package/admin/js/views/menus.js +3 -3
- package/admin/js/views/my-profile.js +1 -1
- package/admin/js/views/notifications.js +1 -1
- package/admin/js/views/page-editor.js +29 -29
- package/admin/js/views/project-detail.js +1 -1
- package/admin/js/views/project-editor.js +1 -1
- package/admin/js/views/project-settings.js +1 -1
- package/admin/js/views/projects.js +2 -2
- package/admin/js/views/user-editor.js +1 -1
- package/admin/js/views/view-editor.js +1 -1
- package/admin/js/views/view-preview.js +1 -1
- package/admin/js/views/views-list.js +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{apiRequest as
|
|
2
|
-
`).filter(
|
|
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)=>ce(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"?de(n,o,e):n.type==="spacer"?pe(n,o,e):me(n,o,e);t.appendChild(l)})}}function de(e,t,s){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:2px dashed var(--dm-border,#444);border-radius:6px;overflow:hidden;margin-bottom:.5rem;background:var(--dm-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:color-mix(in srgb, var(--dm-text-muted) 20%, transparent);color:var(--dm-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(--dm-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(--dm-border,#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 pe(e,t,s){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px dashed var(--dm-border,#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(--dm-border,#444);";const a=document.createElement("span");a.textContent="Spacer",a.style.cssText="font-size:.7rem;color:var(--dm-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(--dm-border,#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 me(e,t,s){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px solid var(--dm-border,#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(--dm-card-header-bg,rgba(255,255,255,.04));cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent=Y(e.type),l.style.cssText="font-size:.7rem;padding:.15rem .45rem;border-radius:999px;background:color-mix(in srgb, var(--dm-primary) 14%, transparent);color:var(--dm-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(--dm-danger,#ef4444);flex-shrink:0;",o.appendChild(p)}if(K(e.logic)){const p=document.createElement("span");p.textContent="\u26A1",p.title="Has conditional logic",p.style.cssText="font-size:.75rem;color:var(--dm-primary,#6366f1);flex-shrink:0;",o.appendChild(p)}o.appendChild(i),o.addEventListener("click",()=>{m.style.display=m.style.display==="none"?"":"none"});const m=ue(e,t,a);return m.style.display="none",n.appendChild(o),n.appendChild(m),n}function ue(e,t,s){const n=document.createElement("div");n.className="fb-field-body",n.style.cssText="padding:.8rem;border-top:1px solid var(--dm-border,#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([Te("Type",`fb-type-${t}`,G,e.type||"string"),le("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)"),le("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=W(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=Y(u.value))}const g=n.querySelector(".fb-field-extras");g&&g.remove();const h=Z(u.value,e,t);h&&n.appendChild(h)});const d=Z(e.type,e,t);return d&&n.appendChild(d),n.appendChild(ve(e,t)),n}const fe=[{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"}],Q=new Set(["is_empty","is_not_empty"]);function j(e){const t=document.createElement("p");return t.textContent=e,t.style.cssText="font-size:.75rem;font-weight:700;color:var(--dm-text-muted,#888);margin:.6rem 0 .3rem;text-transform:uppercase;letter-spacing:.04em;",t}function P(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(--dm-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;",fe.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&&Q.has(e.operator)&&(r.style.display="none"),c.addEventListener("change",()=>{r.style.display=Q.has(c.value)?"none":""});const m=document.createElement("span");m.textContent="\u2192",m.style.cssText="font-size:.73rem;color:var(--dm-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 be(e,t,s){const n=document.createElement("div");n.dataset.logicSection="visibility",n.appendChild(j("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(P(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(P(null,p,u,"fb-logic-vis-then","visible"))),n.appendChild(d)}return n}function he(e,t,s){const n=document.createElement("div");n.dataset.logicSection="requirement",n.appendChild(j("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(P(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(P(null,i,c,"fb-logic-req-then","true"))),n.appendChild(r)}return n}function X(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 ge(e,t,s){const n=document.createElement("div");n.dataset.logicSection="validation",n.appendChild(j("Custom Validation"));const o=document.createElement("div");o.className="fb-logic-val-rules",(e||[]).forEach(a=>o.appendChild(X(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(X(null))),n.appendChild(l),n}function ye(e,t,s){const n=document.createElement("div");n.dataset.logicSection="cascade",n.appendChild(j("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(--dm-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(--dm-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`,
|
|
5
|
-
`),n.appendChild(m),n.appendChild(p),n}function ve(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(--dm-border,#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(--dm-text-muted,#888);",a.textContent="\u26A1 Conditional Logic";const i=K(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(be(s.visibility||{},t,n)),r.appendChild(he(s.requirement||{},t,n)),r.appendChild(ge(s.validation||[],t,n));const m=document.getElementById(`fb-type-${t}`)?.value||e.type;return H.has(m)&&r.appendChild(ye(s.cascade||{},t,n)),o.appendChild(r),o}function Z(e,t,s){const n=document.createElement("div");return n.className="fb-field-extras",e==="chooser"?(n.appendChild(xe(t,s)),n.appendChild(Ee(t.options||[],s))):(H.has(e)&&n.appendChild(Ne(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 ee(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-background, #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 _(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 te(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 U(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 xe(e,t){const s=document.createElement("div");s.style.cssText="margin-top:.5rem; display:flex; flex-direction:column; gap:.4rem;";const n=ee("Layout");n.body.appendChild(v([_(`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."),te(`fb-chooser-multiple-${t}`,"Multi-select",!!e.multiple,"Off = single (radio); on = multi (checkbox).")])),n.body.appendChild(v([_(`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=ee("Visual");return o.body.appendChild(v([U(`fb-chooser-accent-${t}`,"Accent",e.accent||"","primary / success / #ec4899","Selected highlight colour \u2014 semantic name or any CSS colour."),_(`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([te(`fb-chooser-glow-${t}`,"Glow on selected",!!e.glow,"Soft outer glow."),U(`fb-chooser-glow-colour-${t}`,"Glow colour",e.glowColour||"","defaults to accent","Optional; semantic name or CSS colour.")])),o.body.appendChild(v([_(`fb-chooser-shadow-${t}`,"Shadow",e.shadow||"none",[["none","None"],["sm","Small"],["md","Medium"],["lg","Large"],["xl","Extra Large"]],"Drop shadow on every option."),U(`fb-chooser-shadow-colour-${t}`,"Shadow colour",e.shadowColour||"","rgba(0,0,0,0.1)","Optional shadow tint.")])),s.appendChild(o.wrap),s}function Ce(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-background-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(),ne(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(),ne(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-ghost btn-sm",p.title="Remove option",p.innerHTML='<span data-icon="x"></span>',p.addEventListener("click",S=>{S.preventDefault(),Se(t,s,n)}),l.appendChild(p),Domma.icons.scan(p),o.appendChild(l);const u=document.createElement("div");u.style.cssText="display:flex; gap:.4rem;";const d=ie("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,I])=>{const A=document.createElement("option");A.value=S,A.textContent=I,(e.badge?.type||"")===S&&(A.selected=!0),k.appendChild(A)}),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 Ee(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.innerHTML='<span data-icon="plus"></span> Add option',n.appendChild(l),s.appendChild(n),Domma.icons.scan(l);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=we(t);(c.length?c:e||[]).forEach((m,p)=>{a.appendChild(Ce(m,t,p,i))})};return l.addEventListener("click",c=>{c.preventDefault(),ke(t,i)}),i(),s}function we(e){const t=b[e];return!t||!Array.isArray(t.options)?[]:t.options}function J(e){return b[e]?(Array.isArray(b[e].options)||(b[e].options=[]),b[e].options):[]}function ke(e,t){D(e),J(e).push({value:"new",label:"New option"}),t()}function Se(e,t,s){D(e),J(e).splice(t,1),s()}function ne(e,t,s,n){D(e);const o=J(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 Te(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 le(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 Ne(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
|
|
1
|
+
import{apiRequest as A}from"/admin/js/api.js";import{makeIconInput as ue}from"/admin/js/lib/shortcode-modal.js";const X=[{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"}],G=new Set(["select","radio","checkbox-group","chooser"]);let g=[],q=null,P=null,M=null,W={};function w(e,n,s=14){e.textContent="";const t=document.createElement("span");return t.setAttribute("data-icon",n),t.setAttribute("data-icon-size",String(s)),t.style.cssText="display:inline-flex;align-items:center;vertical-align:middle;",e.appendChild(t),window.I?.scan?.(e),e}function D(e,n,s,t=14){return w(e,n,t),e.appendChild(document.createTextNode(" "+s)),e}let _=null,Z=null;function Q(){clearTimeout(Z),Z=setTimeout(()=>{_&&_()},350)}function ee(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")}function te(e){return X.find(n=>n.value===e)?.label||e}function ne(e){return e?!!(e.visibility?.conditions?.length||e.requirement?.conditions?.length||e.validation?.length||e.cascade?.sourceField):!1}function fe(e){const n={...g[e]};if(n.type==="spacer")return n;if(n.type==="page-break"){const h=document.getElementById(`fb-pb-label-${e}`),b=document.getElementById(`fb-pb-desc-${e}`);return h&&(n.label=h.value.trim()||n.label),b&&(n.description=b.value.trim()),n}const s=document.getElementById(`fb-label-${e}`),t=document.getElementById(`fb-name-${e}`),o=document.getElementById(`fb-type-${e}`),l=document.getElementById(`fb-required-${e}`),i=document.getElementById(`fb-placeholder-${e}`),p=document.getElementById(`fb-helper-${e}`),r=document.getElementById(`fb-tooltip-${e}`);if(s&&(n.label=s.value.trim()||n.label),t&&(n.name=t.value.trim()||n.name),o&&(n.type=o.value||n.type),l&&(n.required=l.checked),i&&(n.placeholder=i.value.trim()),p&&(n.helper=p.value.trim()),r&&(n.tooltip=r.value.trim()),n.type==="chooser"){const h=document.getElementById(`fb-chooser-variant-${e}`)?.value;h&&(n.variant=h);const b=document.getElementById(`fb-chooser-multiple-${e}`);b&&(n.multiple=b.checked);const v=document.getElementById(`fb-chooser-density-${e}`)?.value;v&&(n.density=v);const C=document.getElementById(`fb-chooser-columns-${e}`)?.value;C!==""&&C!==void 0&&(n.columns=parseInt(C,10)||3);const x=document.getElementById(`fb-chooser-accent-${e}`)?.value.trim();x?n.accent=x:delete n.accent;const k=document.getElementById(`fb-chooser-accent-style-${e}`)?.value;k?n.accentStyle=k:delete n.accentStyle;const z=document.getElementById(`fb-chooser-glow-${e}`);z&&(n.glow=z.checked);const B=document.getElementById(`fb-chooser-glow-colour-${e}`)?.value.trim();B?n.glowColour=B:delete n.glowColour;const N=document.getElementById(`fb-chooser-shadow-${e}`)?.value;N&&N!=="none"?n.shadow=N:delete n.shadow;const O=document.getElementById(`fb-chooser-shadow-colour-${e}`)?.value.trim();O?n.shadowColour=O:delete n.shadowColour,J(e),g[e]&&Array.isArray(g[e].options)&&(n.options=g[e].options)}else if(G.has(n.type)){const h=document.getElementById(`fb-options-${e}`);h&&(n.options=h.value.split(`
|
|
2
|
+
`).filter(b=>b.trim()).map(b=>{const[v,...C]=b.split(":");return{value:v.trim(),label:C.join(":").trim()||v.trim()}}))}if(n.type==="textarea"){const h=parseInt(document.getElementById(`fb-rows-${e}`)?.value,10);h>0&&(n.formConfig={...n.formConfig||{},rows:h})}const a=document.getElementById(`fb-span-${e}`),d=document.getElementById(`fb-fullwidth-${e}`);if(a||d){const h={...n.formConfig||{}};if(d?.checked)h.span="full";else{const b=parseInt(a?.value,10);b>1?h.span=b:delete h.span}n.formConfig=Object.keys(h).length?h:void 0}const c=document.getElementById(`fb-minlength-${e}`)?.value;c&&(n.minLength=parseInt(c,10));const u=document.getElementById(`fb-maxlength-${e}`)?.value;u&&(n.maxLength=parseInt(u,10));const m=document.getElementById(`fb-min-${e}`)?.value;m!==""&&m!==void 0&&(n.min=parseFloat(m));const f=document.getElementById(`fb-max-${e}`)?.value;f!==""&&f!==void 0&&(n.max=parseFloat(f));const y=he(e);return y?n.logic=y:delete n.logic,n}function he(e){const n=document.querySelector(`.fb-field-card[data-index="${e}"]`);if(!n)return;const s=n.querySelector(".fb-field-logic");if(!s)return;const t={};let o=!1;const l=s.querySelector('[data-logic-section="visibility"]');if(l){const a=l.querySelector(".fb-logic-vis-default"),d=l.querySelector(".fb-logic-vis-transition"),c=Array.from(l.querySelectorAll(".fb-logic-cond-row")).map(f=>{const y=f.querySelector(".fb-logic-cond-field"),h=f.querySelector(".fb-logic-cond-op"),b=f.querySelector(".fb-logic-cond-val"),v=f.querySelector(".fb-logic-vis-then");return y?.value?{when:{all:[{field:y.value,operator:h.value,value:b.value}]},then:v.value}:null}).filter(Boolean),u=a?.value||"visible",m=d?.value||"none";(u!=="visible"||c.length>0||m!=="none")&&(t.visibility={default:u,conditions:c},m!=="none"&&(t.visibility.transition=m),o=!0)}const i=s.querySelector('[data-logic-section="requirement"]');if(i){const a=i.querySelector(".fb-logic-req-default"),d=Array.from(i.querySelectorAll(".fb-logic-cond-row")).map(c=>{const u=c.querySelector(".fb-logic-cond-field"),m=c.querySelector(".fb-logic-cond-op"),f=c.querySelector(".fb-logic-cond-val"),y=c.querySelector(".fb-logic-req-then");return u?.value?{when:{all:[{field:u.value,operator:m.value,value:f.value}]},then:y.value==="true"}:null}).filter(Boolean);d.length>0&&(t.requirement={default:a?.checked===!0,conditions:d},o=!0)}const p=s.querySelector('[data-logic-section="validation"]');if(p){const a=Array.from(p.querySelectorAll(".fb-logic-val-rule")).map(d=>{const c=d.querySelector(".fb-logic-val-type"),u=d.querySelector(".fb-logic-val-pattern"),m=d.querySelector(".fb-logic-val-flags"),f=d.querySelector(".fb-logic-val-message");if(!u?.value.trim())return null;const y=c?.value||"regex",h={type:y,message:f?.value.trim()||"Invalid value."};return y==="regex"?(h.pattern=u.value.trim(),m?.value.trim()&&(h.flags=m.value.trim())):h.field=u.value.trim(),h}).filter(Boolean);a.length>0&&(t.validation=a,o=!0)}const r=s.querySelector('[data-logic-section="cascade"]');if(r){const a=r.querySelector(".fb-logic-cascade-source"),d=r.querySelector(".fb-logic-cascade-mapping"),c=r.querySelector(".fb-logic-cascade-defaults"),u=a?.value?.trim();if(u){let m={};try{m=JSON.parse(d?.value||"{}")}catch{}const f=(c?.value||"").split(`
|
|
3
|
+
`).filter(y=>y.trim()).map(y=>{const[h,...b]=y.split(":");return{value:h.trim(),label:b.join(":").trim()||h.trim()}});t.cascade={sourceField:u,mapping:m,defaultOptions:f},o=!0}}return o?t:void 0}function $(){g=g.map((e,n)=>fe(n))}let I=null;function be(e,n,s){const t=e.firstElementChild;if(!t)return;const o=document.createElement("span");o.setAttribute("data-icon","menu"),o.setAttribute("data-icon-size","13"),o.title="Drag to reorder",o.style.cssText="cursor:grab;opacity:.35;flex-shrink:0;display:inline-flex;align-items:center;",t.insertBefore(o,t.firstChild),window.I?.scan?.(t),t.draggable=!0,t.addEventListener("dragstart",l=>{I=n,l.dataTransfer.effectAllowed="move",e.style.opacity="0.4"}),t.addEventListener("dragend",()=>{e.style.opacity="",document.querySelectorAll("#fields-list .fb-field-card").forEach(l=>l.classList.remove("fb-drag-over"))}),e.addEventListener("dragover",l=>{I!=null&&(l.preventDefault(),l.dataTransfer.dropEffect="move",document.querySelectorAll("#fields-list .fb-field-card").forEach(i=>i.classList.remove("fb-drag-over")),e.classList.add("fb-drag-over"))}),e.addEventListener("dragleave",()=>e.classList.remove("fb-drag-over")),e.addEventListener("drop",l=>{if(l.preventDefault(),e.classList.remove("fb-drag-over"),I==null||I===n){I=null;return}$();const[i]=g.splice(I,1);g.splice(n,0,i),I=null,L(s)})}function L(e){const n=e.find("#fields-list").get(0),s=e.find("#fields-empty-msg").get(0);if(n){if(Array.from(n.querySelectorAll(".fb-field-card")).forEach(t=>t.remove()),g.length===0){s&&(s.style.display=""),Q();return}s&&(s.style.display="none"),g.forEach((t,o)=>{const l=t.type==="page-break"?ge(t,o,e):t.type==="spacer"?ye(t,o,e):ve(t,o,e);be(l,o,e),n.appendChild(l)}),Q()}}function ge(e,n,s){const t=document.createElement("div");t.className="fb-field-card",t.dataset.index=n,t.style.cssText="border:2px dashed var(--dm-border,#444);border-radius:6px;overflow:hidden;margin-bottom:.5rem;background:var(--dm-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:color-mix(in srgb, var(--dm-text-muted) 20%, transparent);color:var(--dm-text-muted,#888);white-space:nowrap;flex-shrink:0;font-style:italic;";const i=document.createElement("span");i.textContent=e.label||"Untitled Step",i.style.cssText="flex:1;font-weight:600;font-size:.9rem;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dm-text-muted,#888);";const p=document.createElement("div");p.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;";const r=document.createElement("button");r.className="btn btn-xs btn-ghost",r.title="Edit step",w(r,"more-horizontal"),r.addEventListener("click",m=>{m.stopPropagation(),d.style.display=d.style.display==="none"?"":"none"}),p.appendChild(r);const a=document.createElement("button");a.className="btn btn-xs btn-ghost",a.style.cssText="line-height:1;opacity:.6;",a.title="Remove page break",w(a,"x"),a.addEventListener("click",async m=>{m.stopPropagation(),await E.confirm("Remove this page break?")&&($(),g.splice(n,1),L(s))}),p.appendChild(a),o.appendChild(l),o.appendChild(i),o.appendChild(p),o.addEventListener("click",()=>{d.style.display=d.style.display==="none"?"":"none"});const d=document.createElement("div");d.className="fb-field-body",d.style.cssText="padding:.8rem;border-top:1px dashed var(--dm-border,#444);display:none;";const c=S([T("Step Title",`fb-pb-label-${n}`,"text",e.label||"","Shown as the wizard step heading"),T("Step Description",`fb-pb-desc-${n}`,"text",e.description||"","Optional sub-heading")]),u=c.querySelector(`#fb-pb-label-${n}`);return u&&u.addEventListener("input",()=>{i.textContent=u.value||"Untitled Step"}),d.appendChild(c),t.appendChild(o),t.appendChild(d),t}function ye(e,n,s){const t=document.createElement("div");t.className="fb-field-card",t.dataset.index=n,t.style.cssText="border:1px dashed var(--dm-border,#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(--dm-border,#444);";const i=document.createElement("span");i.textContent="Spacer",i.style.cssText="font-size:.7rem;color:var(--dm-text-muted,#888);white-space:nowrap;padding:0 .4rem;font-style:italic;";const p=document.createElement("div");p.style.cssText="flex:1;height:1px;background:var(--dm-border,#444);";const r=document.createElement("div");r.style.cssText="display:flex;gap:.25rem;flex-shrink:0;";const a=document.createElement("button");return a.className="btn btn-xs btn-ghost",a.style.cssText="line-height:1;opacity:.6;",a.title="Remove spacer",w(a,"x"),a.addEventListener("click",async d=>{d.stopPropagation(),$(),g.splice(n,1),L(s)}),r.appendChild(a),o.appendChild(l),o.appendChild(i),o.appendChild(p),o.appendChild(r),t.appendChild(o),t}function ve(e,n,s){const t=document.createElement("div");t.className="fb-field-card",t.dataset.index=n,t.style.cssText="border:1px solid var(--dm-border,#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(--dm-card-header-bg,rgba(255,255,255,.04));cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent=te(e.type),l.style.cssText="font-size:.7rem;padding:.15rem .45rem;border-radius:999px;background:color-mix(in srgb, var(--dm-primary) 14%, transparent);color:var(--dm-primary,#6366f1);white-space:nowrap;flex-shrink:0;";const i=document.createElement("span");i.textContent=e.label||"(unlabelled)",i.style.cssText="flex:1;font-weight:600;font-size:.9rem;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;";const p=document.createElement("div");p.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;";const r=document.createElement("button");r.className="btn btn-xs btn-ghost",r.title="Edit field",w(r,"more-horizontal"),r.addEventListener("click",c=>{c.stopPropagation(),d.style.display=d.style.display==="none"?"":"none"}),p.appendChild(r);const a=document.createElement("button");if(a.className="btn btn-xs btn-ghost",a.style.cssText="line-height:1;opacity:.6;",a.title="Remove field",w(a,"x"),a.addEventListener("click",async c=>{c.stopPropagation(),await E.confirm("Remove this field?")&&($(),g.splice(n,1),L(s))}),p.appendChild(a),o.appendChild(l),o.appendChild(i),e.required){const c=document.createElement("span");c.textContent="required",c.style.cssText="font-size:.7rem;color:var(--dm-danger,#ef4444);flex-shrink:0;",o.appendChild(c)}if(ne(e.logic)){const c=document.createElement("span");w(c,"zap"),c.title="Has conditional logic",c.style.cssText="font-size:.75rem;color:var(--dm-primary,#6366f1);flex-shrink:0;",o.appendChild(c)}o.appendChild(p),o.addEventListener("click",()=>{d.style.display=d.style.display==="none"?"":"none"});const d=xe(e,n,i);return d.style.display="none",t.appendChild(o),t.appendChild(d),t}function xe(e,n,s){const t=document.createElement("div");t.className="fb-field-body",t.style.cssText="padding:.8rem;border-top:1px solid var(--dm-border,#333);";const o=S([T("Label",`fb-label-${n}`,"text",e.label||"","Shown above the field"),T("Field Name",`fb-name-${n}`,"text",e.name||"","Used as data key")]),l=S([Ie("Type",`fb-type-${n}`,X,e.type||"string"),re("Required",`fb-required-${n}`,e.required||!1)]),i=S([T("Placeholder",`fb-placeholder-${n}`,"text",e.placeholder||"","Hint text inside the field")]),p=S([T("Helper Text",`fb-helper-${n}`,"text",e.helper||"","Shown below the field"),T("Tooltip",`fb-tooltip-${n}`,"text",e.tooltip||"","Shown on hover via a help icon next to the label")]),r=e.formConfig?.span,a=S([T("Column Span",`fb-span-${n}`,"number",r&&r!=="full"?String(r):"1","Columns to span (grid only)"),re("Full Width",`fb-fullwidth-${n}`,r==="full")]);a.classList.add("fb-grid-row"),a.style.display=document.getElementById("setting-layout")?.value==="grid"?"flex":"none",t.appendChild(o),t.appendChild(l),t.appendChild(i),t.appendChild(p),t.appendChild(a);const d=t.querySelector(`#fb-label-${n}`),c=t.querySelector(`#fb-name-${n}`);d&&d.addEventListener("input",()=>{s&&(s.textContent=d.value||"(unlabelled)"),c&&!c.dataset.manuallyEdited&&(c.value=ee(d.value))}),c&&c.addEventListener("input",()=>{c.dataset.manuallyEdited="1"});const u=t.querySelector(`#fb-type-${n}`);u&&u.addEventListener("change",()=>{const f=t.closest(".fb-field-card");if(f){const b=f.querySelector("span");b&&(b.textContent=te(u.value))}const y=t.querySelector(".fb-field-extras");y&&y.remove();const h=ae(u.value,e,n);h&&t.appendChild(h)});const m=ae(e.type,e,n);return m&&t.appendChild(m),t.appendChild(ke(e,n)),t}const Ce=[{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"}],le=new Set(["is_empty","is_not_empty"]);function V(e){const n=document.createElement("p");return n.textContent=e,n.style.cssText="font-size:.75rem;font-weight:700;color:var(--dm-text-muted,#888);margin:.6rem 0 .3rem;text-transform:uppercase;letter-spacing:.04em;",n}function H(e,n,s,t,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 i=document.createElement("span");i.textContent="When",i.style.cssText="font-size:.73rem;color:var(--dm-text-muted,#888);flex-shrink:0;";const p=document.createElement("select");p.className="form-select fb-logic-cond-field",p.style.cssText="flex:1 1 140px;min-width:140px;",n.forEach(m=>{const f=document.createElement("option");f.value=m.value,f.textContent=m.label,e&&m.value===e.field&&(f.selected=!0),p.appendChild(f)});const r=document.createElement("select");r.className="form-select fb-logic-cond-op",r.style.cssText="flex:1 1 160px;min-width:140px;",Ce.forEach(m=>{const f=document.createElement("option");f.value=m.value,f.textContent=m.label,e&&m.value===e.operator&&(f.selected=!0),r.appendChild(f)});const a=document.createElement("input");a.type="text",a.className="form-input fb-logic-cond-val",a.placeholder="value",a.style.cssText="flex:1 1 120px;min-width:100px;",a.value=e?.value||"",e&&le.has(e.operator)&&(a.style.display="none"),r.addEventListener("change",()=>{a.style.display=le.has(r.value)?"none":""});const d=document.createElement("span");w(d,"arrow-right"),d.style.cssText="font-size:.73rem;color:var(--dm-text-muted,#888);flex-shrink:0;";const c=document.createElement("select");c.className=`form-select ${t}`,c.style.cssText="flex:1 1 140px;min-width:120px;",s.forEach(m=>{const f=document.createElement("option");f.value=m.value,f.textContent=m.label,m.value===o&&(f.selected=!0),c.appendChild(f)});const u=document.createElement("button");return u.type="button",u.className="btn btn-xs btn-ghost",u.style.cssText="line-height:1;opacity:.6;",w(u,"x"),u.style.flexShrink="0",u.addEventListener("click",()=>l.remove()),l.appendChild(i),l.appendChild(p),l.appendChild(r),l.appendChild(a),l.appendChild(d),l.appendChild(c),l.appendChild(u),l}function Ee(e,n,s){const t=document.createElement("div");t.dataset.logicSection="visibility",t.appendChild(V("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 i=document.createElement("select");i.className="form-select fb-logic-vis-default",i.style.cssText="max-width:240px;",[{value:"visible",label:"Visible"},{value:"hidden",label:"Hidden"}].forEach(m=>{const f=document.createElement("option");f.value=m.value,f.textContent=m.label,m.value===(e.default||"visible")&&(f.selected=!0),i.appendChild(f)}),o.appendChild(l),o.appendChild(i),t.appendChild(o);const p=document.createElement("div");p.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.4rem;";const r=document.createElement("span");r.textContent="Transition:",r.style.cssText="font-size:.8rem;flex-shrink:0;";const a=document.createElement("select");a.className="form-select fb-logic-vis-transition",a.style.cssText="max-width:240px;",[{value:"none",label:"None (instant)"},{value:"fade",label:"Fade"},{value:"slide",label:"Slide"},{value:"scale",label:"Scale"}].forEach(m=>{const f=document.createElement("option");f.value=m.value,f.textContent=m.label,m.value===(e.transition||"none")&&(f.selected=!0),a.appendChild(f)}),p.appendChild(r),p.appendChild(a),t.appendChild(p);const d=document.createElement("div");d.className="fb-logic-vis-rules";const c=s.map(m=>({value:m.name,label:m.label||m.name})),u=[{value:"visible",label:"Show"},{value:"hidden",label:"Hide"}];if((e.conditions||[]).forEach(m=>{const f=(m.when?.all||m.when?.any||[])[0],y=m.then==="hidden"?"hidden":"visible";c.length>0&&d.appendChild(H(f,c,u,"fb-logic-vis-then",y))}),t.appendChild(d),c.length>0){const m=document.createElement("button");m.type="button",m.className="btn btn-xs btn-ghost",m.style.cssText="font-size:.73rem;margin-top:.2rem;",D(m,"plus","Add visibility rule"),m.addEventListener("click",()=>d.appendChild(H(null,c,u,"fb-logic-vis-then","visible"))),t.appendChild(m)}return t}function we(e,n,s){const t=document.createElement("div");t.dataset.logicSection="requirement",t.appendChild(V("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")),t.appendChild(o);const i=document.createElement("div");i.className="fb-logic-req-rules";const p=s.map(a=>({value:a.name,label:a.label||a.name})),r=[{value:"true",label:"Make required"},{value:"false",label:"Make optional"}];if((e.conditions||[]).forEach(a=>{const d=(a.when?.all||a.when?.any||[])[0],c=a.then===!0?"true":"false";p.length>0&&i.appendChild(H(d,p,r,"fb-logic-req-then",c))}),t.appendChild(i),p.length>0){const a=document.createElement("button");a.type="button",a.className="btn btn-xs btn-ghost",a.style.cssText="font-size:.73rem;margin-top:.2rem;",D(a,"plus","Add requirement rule"),a.addEventListener("click",()=>i.appendChild(H(null,p,r,"fb-logic-req-then","true"))),t.appendChild(a)}return t}function oe(e){const n=document.createElement("div");n.className="fb-logic-val-rule",n.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(p=>{const r=document.createElement("option");r.value=p.value,r.textContent=p.label,p.value===(e?.type||"regex")&&(r.selected=!0),s.appendChild(r)});const t=document.createElement("input");t.type="text",t.className="form-input fb-logic-val-pattern",t.placeholder=e?.type==="match"?"field name":"pattern",t.value=e?.pattern||e?.field||"",t.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":"",t.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 i=document.createElement("button");return i.type="button",i.className="btn btn-xs btn-ghost",i.style.cssText="line-height:1;opacity:.6;",w(i,"x"),i.style.flexShrink="0",i.addEventListener("click",()=>n.remove()),n.appendChild(s),n.appendChild(t),n.appendChild(o),n.appendChild(l),n.appendChild(i),n}function Se(e,n,s){const t=document.createElement("div");t.dataset.logicSection="validation",t.appendChild(V("Custom Validation"));const o=document.createElement("div");o.className="fb-logic-val-rules",(e||[]).forEach(i=>o.appendChild(oe(i))),t.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;",D(l,"plus","Add validation rule"),l.addEventListener("click",()=>o.appendChild(oe(null))),t.appendChild(l),t}function Te(e,n,s){const t=document.createElement("div");t.dataset.logicSection="cascade",t.appendChild(V("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 i=document.createElement("select");i.className="form-select fb-logic-cascade-source",i.style.cssText="flex:1;";const p=document.createElement("option");p.value="",p.textContent="\u2014 none \u2014",i.appendChild(p),s.forEach(u=>{const m=document.createElement("option");m.value=u.name,m.textContent=u.label||u.name,u.name===e.sourceField&&(m.selected=!0),i.appendChild(m)}),o.appendChild(l),o.appendChild(i),t.appendChild(o);const r=document.createElement("p");r.textContent='Mapping JSON \u2014 {"value":[{"value":"...","label":"..."}]}',r.style.cssText="font-size:.73rem;color:var(--dm-text-muted,#888);margin:.3rem 0 .2rem;";const a=document.createElement("textarea");a.className="form-input fb-logic-cascade-mapping",a.rows=4,a.style.cssText="font-family:monospace;",a.placeholder='{"uk": [{"value": "london", "label": "London"}]}',a.value=e.mapping?JSON.stringify(e.mapping,null,2):"",t.appendChild(r),t.appendChild(a);const d=document.createElement("p");d.textContent="Default options (one per line: value:Label)",d.style.cssText="font-size:.73rem;color:var(--dm-text-muted,#888);margin:.3rem 0 .2rem;";const c=document.createElement("textarea");return c.className="form-input fb-logic-cascade-defaults",c.rows=3,c.style.cssText="font-family:monospace;",c.placeholder=`option1:Option 1
|
|
4
|
+
option2:Option 2`,c.value=(e.defaultOptions||[]).map(u=>{const m=typeof u=="string"?u:u.value??"",f=typeof u=="string"?u:u.label??m;return m===f?m:`${m}:${f}`}).join(`
|
|
5
|
+
`),t.appendChild(d),t.appendChild(c),t}function ke(e,n){const s=e.logic||{},t=g.filter((c,u)=>u!==n&&c.type!=="page-break"&&c.type!=="spacer"),o=document.createElement("div");o.className="fb-field-logic",o.style.cssText="margin-top:.75rem;border-top:1px solid var(--dm-border,#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 i=document.createElement("span");i.style.cssText="font-size:.8rem;font-weight:600;color:var(--dm-text-muted,#888);",i.textContent="\u26A1 Conditional Logic";const p=ne(s),r=document.createElement("button");r.type="button",r.className="btn btn-xs btn-ghost",w(r,p?"chevron-down":"chevron-right",12);const a=document.createElement("div");a.className="fb-logic-body",a.style.cssText="padding:.25rem 0 .25rem;"+(p?"":"display:none;"),l.addEventListener("click",()=>{const c=a.style.display==="none";a.style.display=c?"":"none",w(r,c?"chevron-down":"chevron-right",12)}),l.appendChild(i),l.appendChild(r),o.appendChild(l),a.appendChild(Ee(s.visibility||{},n,t)),a.appendChild(we(s.requirement||{},n,t)),a.appendChild(Se(s.validation||[],n,t));const d=document.getElementById(`fb-type-${n}`)?.value||e.type;return G.has(d)&&a.appendChild(Te(s.cascade||{},n,t)),o.appendChild(a),o}function ae(e,n,s){const t=document.createElement("div");return t.className="fb-field-extras",e==="chooser"?(t.appendChild(Ne(n,s)),t.appendChild($e(n.options||[],s))):(G.has(e)&&t.appendChild(Ae(n.options||[],s)),e==="textarea"&&t.appendChild(S([T("Rows",`fb-rows-${s}`,"number",n.formConfig?.rows||4,"Height of textarea")])),(e==="string"||e==="textarea")&&t.appendChild(S([T("Min Length",`fb-minlength-${s}`,"number",n.minLength||"",""),T("Max Length",`fb-maxlength-${s}`,"number",n.maxLength||"","")])),e==="number"&&t.appendChild(S([T("Min",`fb-min-${s}`,"number",n.min??"",""),T("Max",`fb-max-${s}`,"number",n.max??"","")]))),t.children.length?t:null}function se(e){const n=document.createElement("div");n.className="fb-chooser-section",n.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-background, #f9fafb) 60%, transparent); font-weight:600; font-size:.82rem; border-bottom:1px solid var(--dm-border, #e5e7eb);",s.textContent=e,n.appendChild(s);const t=document.createElement("div");return t.className="fb-chooser-section-body",t.style.cssText="padding:.55rem .6rem; display:flex; flex-direction:column; gap:.45rem;",n.appendChild(t),{wrap:n,body:t}}function U(e,n,s,t,o){const l=document.createElement("div");l.style.flex="1";const i=document.createElement("label");i.htmlFor=e,i.className="form-label",i.textContent=n,i.style.fontSize=".8rem";const p=document.createElement("select");if(p.id=e,p.className="form-input",t.forEach(([r,a])=>{const d=document.createElement("option");d.value=r,d.textContent=a,String(r)===String(s)&&(d.selected=!0),p.appendChild(d)}),l.appendChild(i),l.appendChild(p),o){const r=document.createElement("p");r.className="form-hint text-muted",r.textContent=o,r.style.cssText="font-size:.72rem;margin-top:.2rem;",l.appendChild(r)}return l}function ie(e,n,s,t){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 i=document.createElement("input");if(i.id=e,i.type="checkbox",i.checked=!!s,l.appendChild(i),l.appendChild(document.createTextNode(" "+n)),o.appendChild(l),t){const p=document.createElement("p");p.className="form-hint text-muted",p.textContent=t,p.style.cssText="font-size:.72rem;margin-top:.2rem;",o.appendChild(p)}return o}function Y(e,n,s,t,o){const l=document.createElement("div");l.style.flex="1";const i=document.createElement("label");i.htmlFor=e,i.className="form-label",i.textContent=n,i.style.fontSize=".8rem",l.appendChild(i);const p=document.createElement("div");p.style.cssText="display:flex;gap:.4rem;align-items:stretch;";const r=document.createElement("input");r.id=e,r.type="text",r.className="form-input",r.value=s||"",t&&(r.placeholder=t),r.style.flex="1";const a=document.createElement("input");a.type="color",a.title="Pick a colour",a.style.cssText="width:36px;height:auto;padding:0;border:1px solid var(--dm-border,#e5e7eb);border-radius:4px;cursor:pointer;";const d=String(r.value).match(/^#[0-9a-fA-F]{3,8}$/);if(a.value=d?r.value:"#000000",a.addEventListener("input",()=>{r.value=a.value,r.dispatchEvent(new Event("input",{bubbles:!0}))}),p.appendChild(r),p.appendChild(a),l.appendChild(p),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 Ne(e,n){const s=document.createElement("div");s.style.cssText="margin-top:.5rem; display:flex; flex-direction:column; gap:.4rem;";const t=se("Layout");t.body.appendChild(S([U(`fb-chooser-variant-${n}`,"Variant",e.variant||"card",[["card","Card \u2014 rich tiles"],["chip","Chip \u2014 compact pills"]],"Card supports description and grid columns; chips wrap."),ie(`fb-chooser-multiple-${n}`,"Multi-select",!!e.multiple,"Off = single (radio); on = multi (checkbox).")])),t.body.appendChild(S([U(`fb-chooser-density-${n}`,"Density",e.density||"comfortable",[["comfortable","Comfortable"],["compact","Compact"]],"Compact strips description (card variant only)."),T("Columns",`fb-chooser-columns-${n}`,"number",e.columns||3,"Card grid (1\u20136). Ignored for chips.")])),s.appendChild(t.wrap);const o=se("Visual");return o.body.appendChild(S([Y(`fb-chooser-accent-${n}`,"Accent",e.accent||"","primary / success / #ec4899","Selected highlight colour \u2014 semantic name or any CSS colour."),U(`fb-chooser-accent-style-${n}`,"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(S([ie(`fb-chooser-glow-${n}`,"Glow on selected",!!e.glow,"Soft outer glow."),Y(`fb-chooser-glow-colour-${n}`,"Glow colour",e.glowColour||"","defaults to accent","Optional; semantic name or CSS colour.")])),o.body.appendChild(S([U(`fb-chooser-shadow-${n}`,"Shadow",e.shadow||"none",[["none","None"],["sm","Small"],["md","Medium"],["lg","Large"],["xl","Extra Large"]],"Drop shadow on every option."),Y(`fb-chooser-shadow-colour-${n}`,"Shadow colour",e.shadowColour||"","rgba(0,0,0,0.1)","Optional shadow tint.")])),s.appendChild(o.wrap),s}function qe(e,n,s,t){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-background-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 i=document.createElement("div");i.style.cssText="display:flex; flex-direction:column; gap:1px;";const p=document.createElement("button");p.type="button",p.className="btn btn-xs btn-ghost",p.title="Move up",w(p,"arrow-up"),p.addEventListener("click",N=>{N.preventDefault(),ce(n,s,-1,t)});const r=document.createElement("button");r.type="button",r.className="btn btn-xs btn-ghost",r.title="Move down",w(r,"arrow-down"),r.addEventListener("click",N=>{N.preventDefault(),ce(n,s,1,t)}),i.appendChild(p),i.appendChild(r),l.appendChild(i);const a=document.createElement("input");a.type="text",a.className="form-input fb-chooser-opt-value",a.placeholder="value",a.value=e.value||"",a.style.flex="1",l.appendChild(a);const d=document.createElement("input");d.type="text",d.className="form-input fb-chooser-opt-label",d.placeholder="label (visible to users)",d.value=e.label||"",d.style.flex="2",l.appendChild(d);const c=document.createElement("button");c.type="button",c.className="btn btn-xs btn-ghost",c.style.cssText="line-height:1;opacity:.6;",c.title="Remove option",w(c,"x"),c.addEventListener("click",N=>{N.preventDefault(),Be(n,s,t)}),l.appendChild(c),o.appendChild(l);const u=document.createElement("div");u.style.cssText="display:flex; gap:.4rem;";const m=ue("icon name (optional)",e.icon||"");m.input.classList.add("fb-chooser-opt-icon"),m.el.style.flex="1",u.appendChild(m.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 y=document.createElement("div");y.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",y.appendChild(h);const b=document.createElement("input");b.type="text",b.className="form-input fb-chooser-opt-badge-text",b.placeholder="badge text",b.value=e.badge?.text||"",b.style.flex="1",y.appendChild(b);const v=document.createElement("select");v.className="form-input fb-chooser-opt-badge-type",v.style.flex="1",[["","no badge"],["primary","primary"],["success","success"],["info","info"],["warning","warning"],["danger","danger"]].forEach(([N,O])=>{const j=document.createElement("option");j.value=N,j.textContent=O,(e.badge?.type||"")===N&&(j.selected=!0),v.appendChild(j)}),y.appendChild(v),o.appendChild(y);const C=document.createElement("div");C.style.cssText="display:flex; gap:1rem; font-size:.8rem;";const x=document.createElement("label");x.style.cssText="display:inline-flex;align-items:center;gap:.3rem;";const k=document.createElement("input");k.type="checkbox",k.className="fb-chooser-opt-recommended",k.checked=!!e.recommended,x.appendChild(k),x.appendChild(document.createTextNode(" Recommended")),C.appendChild(x);const z=document.createElement("label");z.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,z.appendChild(B),z.appendChild(document.createTextNode(" Disabled")),C.appendChild(z),o.appendChild(C),o}function $e(e,n){const s=document.createElement("div");s.style.cssText="margin-top:.5rem;";const t=document.createElement("div");t.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;",t.appendChild(o);const l=document.createElement("button");l.type="button",l.className="btn btn-xs btn-ghost",D(l,"plus","Add option"),t.appendChild(l),s.appendChild(t);const i=document.createElement("div");i.className="fb-chooser-options-list",i.id=`fb-chooser-options-${n}`,i.style.cssText="display:flex; flex-direction:column; gap:.4rem;",s.appendChild(i);const p=()=>{i.replaceChildren();const r=Le(n);(r.length?r:e||[]).forEach((d,c)=>{i.appendChild(qe(d,n,c,p))})};return l.addEventListener("click",r=>{r.preventDefault(),ze(n,p)}),p(),s}function Le(e){const n=g[e];return!n||!Array.isArray(n.options)?[]:n.options}function K(e){return g[e]?(Array.isArray(g[e].options)||(g[e].options=[]),g[e].options):[]}function ze(e,n){J(e),K(e).push({value:"new",label:"New option"}),n()}function Be(e,n,s){J(e),K(e).splice(n,1),s()}function ce(e,n,s,t){J(e);const o=K(e),l=n+s;if(l<0||l>=o.length)return;const[i]=o.splice(n,1);o.splice(l,0,i),t()}function J(e){const n=document.getElementById(`fb-chooser-options-${e}`);if(!n)return;const s=n.querySelectorAll(".fb-chooser-option-row"),t=[];s.forEach(o=>{const l={value:o.querySelector(".fb-chooser-opt-value")?.value.trim()||"",label:o.querySelector(".fb-chooser-opt-label")?.value.trim()||""},i=o.querySelector(".fb-chooser-opt-icon")?.value.trim();i&&(l.icon=i);const p=o.querySelector(".fb-chooser-opt-description")?.value.trim();p&&(l.description=p);const r=o.querySelector(".fb-chooser-opt-tooltip")?.value.trim();r&&(l.tooltip=r);const a=o.querySelector(".fb-chooser-opt-badge-text")?.value.trim(),d=o.querySelector(".fb-chooser-opt-badge-type")?.value;(a||d)&&(l.badge={},a&&(l.badge.text=a),d&&(l.badge.type=d)),o.querySelector(".fb-chooser-opt-recommended")?.checked&&(l.recommended=!0),o.querySelector(".fb-chooser-opt-disabled")?.checked&&(l.disabled=!0),t.push(l)}),g[e]&&(g[e].options=t)}function S(e){const n=document.createElement("div");return n.style.cssText="display:flex;gap:.75rem;margin-bottom:.6rem;",e.forEach(s=>{s&&n.appendChild(s)}),n}function T(e,n,s,t,o){const l=document.createElement("div");l.style.flex="1";const i=document.createElement("label");i.htmlFor=n,i.className="form-label",i.textContent=e,i.style.fontSize=".8rem";const p=document.createElement("input");if(p.id=n,p.type=s||"text",p.className="form-input",p.value=t??"",l.appendChild(i),l.appendChild(p),o){const r=document.createElement("p");r.className="form-hint text-muted",r.textContent=o,r.style.cssText="font-size:.73rem;margin-top:.2rem;",l.appendChild(r)}return l}function Ie(e,n,s,t){const o=document.createElement("div");o.style.flex="1";const l=document.createElement("label");l.htmlFor=n,l.className="form-label",l.textContent=e,l.style.fontSize=".8rem";const i=document.createElement("select");return i.id=n,i.className="form-select",s.forEach(p=>{const r=document.createElement("option");r.value=p.value,r.textContent=p.label,p.value===t&&(r.selected=!0),i.appendChild(r)}),o.appendChild(l),o.appendChild(i),o}function re(e,n,s){const t=document.createElement("div");t.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=n,l.type="checkbox",l.checked=s,o.appendChild(l),o.appendChild(document.createTextNode(e)),t.appendChild(o),t}function Ae(e,n){const s=document.createElement("div");s.style.cssText="margin-top:.4rem;";const t=document.createElement("p");t.textContent="Options (one per line: value or value:Label)",t.style.cssText="font-size:.8rem;font-weight:600;margin-bottom:.3rem;";const o=document.createElement("textarea");return o.id=`fb-options-${n}`,o.className="form-input",o.rows=4,o.placeholder=`yes:Yes
|
|
6
6
|
no:No
|
|
7
|
-
maybe:Maybe`,o.value=(e||[]).map(l=>{const
|
|
8
|
-
`),o.style.fontFamily="monospace",s.appendChild(
|
|
7
|
+
maybe:Maybe`,o.value=(e||[]).map(l=>{const i=typeof l=="string"?l:l.value??"",p=typeof l=="string"?l:l.label??i;return i===p?i:`${i}:${p}`}).join(`
|
|
8
|
+
`),o.style.fontFamily="monospace",s.appendChild(t),s.appendChild(o),s}function de(e){const n=e.find("#field-project").val()||"";return $(),{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}:{},meta:{...W||{},project:n||null},fields:g,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()},...P!==null&&{collection:P}}}}function Fe(e){const n=[];let s=[],t="Step 1",o="";return e.forEach(l=>{l.type==="page-break"?(n.push({title:t,description:o,fields:s}),s=[],t=l.label||`Step ${n.length+1}`,o=l.description||""):l.type!=="spacer"&&s.push(l)}),(s.length||n.length===0)&&n.push({title:t,description:o,fields:s}),n}function pe(e,n){const s={};return e.forEach(t=>{if(t.type==="page-break"||t.type==="spacer")return;const o={...t.formConfig||{}};o.span==="full"&&n&&(o.span=n);const i={type:t.type==="checkbox"?"boolean":t.type==="date"?"string":t.type,label:t.label,required:t.required,options:t.options,formConfig:{...t.placeholder&&{placeholder:t.placeholder},...t.helper&&{helperText:t.helper},...t.tooltip&&{tooltip:t.tooltip},...o}};t.type==="chooser"&&(t.variant&&(i.variant=t.variant),t.multiple&&(i.multiple=!0),t.density&&(i.density=t.density),t.columns&&(i.columns=t.columns),t.accent&&(i.accent=t.accent),t.accentStyle&&(i.accentStyle=t.accentStyle),t.glow&&(i.glow=!0),t.glowColour&&(i.glowColour=t.glowColour),t.shadow&&(i.shadow=t.shadow),t.shadowColour&&(i.shadowColour=t.shadowColour)),s[t.name]=i}),s}function me(e,n){const s=typeof e=="string"?document.querySelector(e):e;s&&(n||[]).forEach(t=>{if(t.type!=="date"||!t.name)return;const o=s.querySelector(`[name="${t.name}"]`);o&&o.type!=="date"&&(o.type="date")})}export const formEditorView={templateUrl:"/admin/js/templates/form-editor.html",async onMount(e){g=[],q=null,P=null;const n=window.location.hash.match(/\/forms\/edit\/([^/?#]+)/);q=n?n[1]:null;let s=null;const t=E.loader(e.get(0),{type:"dots"});if(q)try{s=await A(`/forms/${q}`),g=s.fields||[],P=s.actions?.collection??null}catch{E.toast("Could not load form.",{type:"error"})}W={};try{const a=await A("/projects").catch(()=>[]),d=e.find("#field-project").get(0);d&&(Array.isArray(a)?a:[]).forEach(c=>{const u=document.createElement("option");u.value=c.slug,u.textContent=c.name||c.slug,d.appendChild(u)})}catch{}if(t.destroy(),s?e.find("#editor-title").get(0).textContent=`Edit: ${s.title}`:e.find("#editor-title").get(0).textContent="New Form",q||e.find("#field-title").get(0).addEventListener("input",function(){e.find("#field-slug").val(ee(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),W=s.meta||{},e.find("#field-project").val(s.meta?.project||"");const a=s.settings||{};e.find("#setting-submit-text").val(a.submitText||"Submit"),e.find("#setting-success-message").val(a.successMessage||""),e.find("#setting-layout").val(a.layout||"stacked"),e.find("#setting-columns").val(a.columns||2),e.find("#setting-submit-span").val(a.submitSpan||""),e.find("#columns-group").get(0).style.display=a.layout==="grid"?"":"none",e.find("#setting-honeypot").prop("checked",a.honeypot!==!1),e.find("#setting-rate-limit").val(a.rateLimitPerMinute||3),e.find("#setting-success-redirect").val(a.successRedirect||"");const d=s.actions?.email||{};e.find("#action-email-enabled").prop("checked",d.enabled||!1),e.find("#action-email-recipients").val(d.recipients||""),e.find("#action-email-subject-prefix").val(d.subjectPrefix||"");const c=s.actions?.webhook||{};e.find("#action-webhook-enabled").prop("checked",c.enabled||!1),e.find("#action-webhook-url").val(c.url||""),e.find("#action-webhook-method").val(c.method||"POST")}const o=s?.settings?.actionSlug||"";try{const a=await A("/actions").catch(()=>[]),d=e.find("#action-cms-slug").get(0);if((Array.isArray(a)?a:[]).forEach(c=>{const u=document.createElement("option");u.value=c.slug,u.textContent=c.title||c.slug,c.slug===o&&(u.selected=!0),d.appendChild(u)}),!a.length){const c=document.createElement("option");c.value="",c.textContent="No actions available",c.disabled=!0,d.appendChild(c)}}catch{}e.find("#setting-layout").get(0)?.addEventListener("change",function(){const a=this.value==="grid";e.find("#columns-group").get(0).style.display=a?"":"none",document.querySelectorAll(".fb-grid-row").forEach(d=>{d.style.display=a?"flex":"none"})}),L(e);const l=e.find("#add-element-menu").get(0);e.find("#add-element-btn").get(0).addEventListener("click",a=>{a.stopPropagation(),l.style.display=l.style.display==="none"?"":"none"}),M&&document.removeEventListener("click",M),M=()=>{l&&(l.style.display="none")},document.addEventListener("click",M),e.find("#add-field-btn").get(0).addEventListener("click",()=>{l&&(l.style.display="none"),$();const a=g.length;g.push({name:`field_${a+1}`,type:"string",label:"New Field",required:!1,placeholder:""}),L(e);const d=e.find("#fields-list").get(0)?.lastElementChild;if(d){const c=d.querySelector(".fb-field-body");c&&(c.style.display="")}}),e.find("#add-spacer-btn").get(0).addEventListener("click",()=>{l&&(l.style.display="none"),$(),g.push({type:"spacer"}),L(e)}),e.find("#add-page-break-btn").get(0).addEventListener("click",()=>{l&&(l.style.display="none"),$();const a=g.filter(d=>d.type==="page-break").length+2;g.push({type:"page-break",label:`Step ${a}`,description:""}),L(e)}),e.find("#save-form-btn").get(0).addEventListener("click",async()=>{const a=de(e);if(!a.title){E.toast("Please enter a form title.",{type:"error"});return}try{q?(await A(`/forms/${q}`,{method:"PUT",body:JSON.stringify(a)}),E.toast("Form saved.",{type:"success"})):(q=(await A("/forms",{method:"POST",body:JSON.stringify(a)})).slug,R.navigate(`/forms/edit/${q}`),E.toast("Form created.",{type:"success"}))}catch(d){E.toast(d.message||"Failed to save form.",{type:"error"})}}),_=()=>{const a=de(e),d=e.find("#preview-container").get(0);if(!d)return;const c=e.find("#preview-test-result").get(0),u=e.find("#preview-test-badge").get(0);c&&(c.style.display="none",c.textContent=""),u&&(u.style.display=q?"":"none"),e.find("#preview-card").get(0).style.display="",d.textContent="";const m=document.createElement("div");m.id="fb-preview-form",d.appendChild(m);const f=q?async h=>{c&&(c.style.display="none",c.textContent="");try{const b=await fetch(`/api/forms/submit/${q}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)}),v=await b.json();if(!b.ok)throw new Error(v.error||"Submission failed.");c&&(c.textContent=v.message||a.settings?.successMessage||"Submitted successfully.",c.style.cssText="display:block;margin-top:.75rem;padding:.6rem .9rem;border-radius:6px;font-size:.9rem;background:color-mix(in srgb, var(--dm-success) 12%, transparent);color:var(--dm-success,#22c55e);"),E.toast("Test submission stored.",{type:"success"})}catch(b){c&&(c.textContent=b.message,c.style.cssText="display:block;margin-top:.75rem;padding:.6rem .9rem;border-radius:6px;font-size:.9rem;background:color-mix(in srgb, var(--dm-danger) 12%, transparent);color:var(--dm-danger,#ef4444);"),E.toast(b.message,{type:"error"})}return!1}:()=>!1,y=a.fields.some(h=>h.type==="page-break");if(typeof F<"u"){const h=a.settings?.columns||2,b=a.settings?.layout||"stacked";if(y&&F.wizard){const v=Fe(a.fields).map(C=>({title:C.title,description:C.description,fields:pe(C.fields,h)}));F.wizard("#fb-preview-form",{schema:{steps:v},onSubmit:f}),me("#fb-preview-form",a.fields)}else if(F.render){const v=pe(a.fields,h),C={};if(a.fields.forEach(x=>{if(!(!x.name||x.type==="page-break"||x.type==="spacer")&&(x.type==="select"||x.type==="multiselect")&&x.required){const k=(x.options||[])[0];k&&(C[x.name]=typeof k=="object"?k.value:k)}}),F.render("#fb-preview-form",v,C,{submitText:a.settings?.submitText||"Submit",layout:b,columns:h,onSubmit:f}),b==="grid"&&a.settings?.submitSpan==="full"){const x=document.querySelector("#fb-preview-form .form-buttons");x&&x.classList.add("col-span-full")}me("#fb-preview-form",a.fields)}window.FormLogicEngine&&a.fields.some(v=>v.logic)&&requestAnimationFrame(()=>{new window.FormLogicEngine.FormLogicRuntime({fields:a.fields},m).init()})}else{const h=document.createElement("p");h.textContent=`${a.fields.filter(b=>b.type!=="page-break").length} field(s): ${a.fields.filter(b=>b.type!=="page-break").map(b=>b.label).join(", ")}`,h.style.cssText="color:var(--dm-text-muted);font-style:italic;",m.appendChild(h)}},_();const i=e.find("#editor-tabs").get(0),p=e.find("#preview-card").get(0),r=a=>{p&&p.contains(a.target)||Q()};i&&(i.addEventListener("input",r),i.addEventListener("change",r))}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{apiRequest as
|
|
1
|
+
import{apiRequest as x}from"/admin/js/api.js";let c=null,k=[],r=[];export const formSubmissionsView={templateUrl:"/admin/js/templates/form-submissions.html",async onMount(t){const l=window.location.hash.match(/\/forms\/([^/?#]+)\/submissions/);if(c=l?l[1]:null,!c){E.toast("No form selected.",{type:"error"});return}const u=E.loader(t.get(0),{type:"dots"});try{const n=await x(`/forms/${c}`);k=(n.fields||[]).filter(s=>s.type!=="page-break"),t.find("#submissions-title").get(0).textContent=`${n.title} \u2014 Submissions`}catch{E.toast("Could not load form definition.",{type:"error"})}try{await A(t)}finally{u.destroy()}t.find("#export-btn").off("click").on("click",()=>{const n=E.slideover({title:"Export Submissions",size:"sm",position:"right"}),s=document.createElement("div");s.style.cssText="padding:1.25rem;display:flex;flex-direction:column;gap:1rem;";function i(p,y,f,g){const C=document.createElement("div");C.style.cssText="display:flex;flex-direction:column;gap:.4rem;";const b=document.createElement("button");b.className="btn btn-ghost",b.style.cssText="justify-content:flex-start;gap:.5rem;";const L=document.createElement("span");return L.setAttribute("data-icon",y),b.appendChild(L),b.appendChild(document.createTextNode(" "+p)),b.addEventListener("click",()=>{fetch(f,{headers:{Authorization:"Bearer "+(S.get("auth_token")||"")}}).then(w=>w.blob()).then(w=>{const h=document.createElement("a");h.href=URL.createObjectURL(w),h.download=g,document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(h.href),n.close()}).catch(()=>E.toast("Export failed.",{type:"error"}))}),C.appendChild(b),C}s.appendChild(i("Export as CSV","file-text",`/api/forms/${c}/submissions/export`,`${c}-submissions.csv`)),s.appendChild(i("Export as JSON","code",`/api/forms/${c}/submissions/export/json`,`${c}-submissions.json`)),n.setContent(s),Domma.icons.scan(s),n.open()}),t.find("#clear-all-btn").off("click").on("click",async()=>{if(await E.confirm("Delete all submissions? This cannot be undone."))try{await x(`/forms/${c}/submissions`,{method:"DELETE"}),r=[],E.toast("All submissions cleared.",{type:"success"}),v([],t)}catch{E.toast("Failed to clear submissions.",{type:"error"})}});const d=t.find("#sub-search").get(0),o=t.find("#sub-date-from").get(0),e=t.find("#sub-date-to").get(0);function a(){const n=d?.value.toLowerCase()||"",s=o?.value?new Date(o.value):null,i=e?.value?new Date(e.value+"T23:59:59"):null,p=r.filter(y=>{if(n&&!Object.values(y.data||{}).map(g=>String(g).toLowerCase()).some(g=>g.includes(n)))return!1;if(s||i){const f=y.meta?.createdAt?new Date(y.meta.createdAt):null;if(!f||s&&f<s||i&&f>i)return!1}return!0});v(p,t)}d&&d.addEventListener("input",a),o&&o.addEventListener("change",a),e&&e.addEventListener("change",a),Domma.icons.scan()}};async function A(t){try{r=await x(`/forms/${c}/submissions`)}catch{r=[],E.toast("Could not load submissions.",{type:"error"})}v(r,t)}function v(t,m){const l=m.find("#sub-count").get(0);l&&(t.length===r.length?l.textContent=`${r.length} submission${r.length!==1?"s":""}`:l.textContent=`Showing ${t.length} of ${r.length}`);const d=[...k.map(e=>({key:`data.${e.name}`,title:e.label||e.name,render:(a,n)=>{const s=n.data?.[e.name]??"",i=String(s),p=document.createElement("span");return p.title=i,p.textContent=i.length>80?i.slice(0,80)+"\u2026":i,p.outerHTML}})),{key:"meta",title:"Date",render:e=>D(e?.createdAt).format("DD MMM YYYY HH:mm")},{key:"id",title:"",render:e=>{const a=document.createElement("button");return a.className="btn btn-sm btn-danger js-delete-submission",a.dataset.id=e,a.setAttribute("data-tooltip","Delete"),a.innerHTML='<span data-icon="trash"></span>',a.outerHTML}}];T.create("#submissions-table",{data:t,columns:d,emptyMessage:"No submissions yet."});const o=document.querySelector("#submissions-table");o&&(o.querySelectorAll(".js-delete-submission").forEach(e=>{e.addEventListener("click",async a=>{a.stopPropagation();const n=e.dataset.id;if(await E.confirm("Delete this submission?"))try{await x(`/forms/${c}/submissions/${n}`,{method:"DELETE"}),r=r.filter(i=>i.id!==n),E.toast("Submission deleted.",{type:"success"}),v(r,m)}catch{E.toast("Failed to delete submission.",{type:"error"})}})}),o.querySelectorAll("tbody tr").forEach((e,a)=>{const n=t[a];n&&(e.style.cursor="pointer",e.addEventListener("click",s=>{s.target.closest(".js-delete-submission")||M(n)}))}),Domma.icons.scan(o),o.querySelectorAll("[data-tooltip]").forEach(e=>{E.tooltip(e,{content:e.getAttribute("data-tooltip"),position:"top"})}))}function M(t){const m=document.createElement("div"),l=document.createElement("div");l.style.cssText="display:flex;flex-direction:column;gap:.75rem;margin-bottom:1.25rem;",k.forEach(o=>{const e=t.data?.[o.name];if(e==null||e==="")return;const a=document.createElement("div");a.style.cssText="border-bottom:1px solid var(--dm-border,#333);padding-bottom:.6rem;";const n=document.createElement("strong");n.textContent=o.label||o.name,n.style.cssText="display:block;font-size:.8rem;color:var(--dm-text-muted,#888);margin-bottom:.2rem;";const s=document.createElement("p");s.textContent=String(e),s.style.cssText="margin:0;word-break:break-word;",a.appendChild(n),a.appendChild(s),l.appendChild(a)});const u=document.createElement("div");if(u.style.cssText="font-size:.8rem;color:var(--dm-text-muted,#888);display:flex;flex-direction:column;gap:.3rem;border-top:1px solid var(--dm-border,#333);padding-top:.75rem;",t.meta?.createdAt){const o=document.createElement("span");o.textContent=`Submitted: ${D(t.meta.createdAt).format("DD MMM YYYY HH:mm")}`,u.appendChild(o)}if(t.meta?.ip){const o=document.createElement("span");o.textContent=`IP: ${t.meta.ip}`,u.appendChild(o)}m.appendChild(l),m.appendChild(u);const d=E.modal({title:"Submission Details",size:"md"});d.element.appendChild(m),d.open()}
|
package/admin/js/views/forms.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{apiRequest as p}from"/admin/js/api.js";import{filterByProject as b,getProjectFromHash as h}from"/admin/js/lib/project-context.js";function u(
|
|
1
|
+
import{apiRequest as p}from"/admin/js/api.js";import{filterByProject as b,getProjectFromHash as h}from"/admin/js/lib/project-context.js";function u(i){return String(i).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}export const formsView={templateUrl:"/admin/js/templates/forms.html",async onMount(i){await g(i),i.find("#create-form-btn").off("click").on("click",()=>{const d=E.modal({title:"Create Form",size:"sm"}),r=document.createElement("div");r.style.cssText="padding:.25rem 0 .5rem;";const l=document.createElement("div");F.create({title:{type:"string",label:"Form Title",placeholder:"e.g. Contact, Feedback\u2026",required:!0}},{},{showSubmitButton:!1}).renderTo(l),r.appendChild(l);const e=document.createElement("div");e.style.cssText="display:flex;justify-content:flex-end;gap:.5rem;margin-top:.75rem;";const n=document.createElement("button");n.className="btn btn-ghost",n.textContent="Cancel";const s=document.createElement("button");s.className="btn btn-primary",s.textContent="Create",e.appendChild(n),e.appendChild(s),r.appendChild(e),d.element.appendChild(r),d.open();const t=l.querySelector('input[name="title"]');setTimeout(()=>t?.focus(),50);async function a(){const o=t?.value.trim();if(o)try{const c=await p("/forms",{method:"POST",body:JSON.stringify({title:o})});d.close(),R.navigate(`/forms/edit/${c.slug}`)}catch(c){E.toast(c.message||"Failed to create form.",{type:"error"})}}n.addEventListener("click",()=>d.close()),s.addEventListener("click",a),t?.addEventListener("keydown",o=>{o.key==="Enter"&&a()})}),i.find("#test-email-btn").off("click").on("click",async()=>{const r=(window.__CMS_SITE__?.smtp||{}).fromAddress||"",l=E.modal({title:"Send Test Email",size:"sm"}),e=document.createElement("div");e.style.cssText="padding:.25rem 0 .5rem;";const n=document.createElement("div");n.className="mb-3";const s=document.createElement("label");s.className="form-label",s.textContent="Send to";const t=document.createElement("input");t.type="email",t.className="form-input",t.value=r,t.placeholder="test@example.com",n.appendChild(s),n.appendChild(t),e.appendChild(n);const a=document.createElement("p");a.className="text-muted",a.style.cssText="font-size:.8rem;margin-bottom:.75rem;",a.textContent="SMTP settings are configured in Site Settings.",e.appendChild(a);const o=document.createElement("div");o.style.cssText="display:flex;justify-content:flex-end;gap:.5rem;margin-top:.75rem;";const c=document.createElement("button");c.className="btn btn-ghost",c.textContent="Cancel";const m=document.createElement("button");m.className="btn btn-primary",m.textContent="Send",o.appendChild(c),o.appendChild(m),e.appendChild(o),l.element.appendChild(e),l.open(),setTimeout(()=>t?.focus(),50),c.addEventListener("click",()=>l.close()),m.addEventListener("click",async()=>{const f=t.value.trim();if(f){m.disabled=!0;try{await p("/forms/test-email",{method:"POST",body:JSON.stringify({to:f})}),l.close(),E.toast("Test email sent.",{type:"success"})}catch(y){E.toast(y.message||"Failed to send test email.",{type:"error"})}finally{m.disabled=!1}}})}),Domma.icons.scan()}};async function g(i){const d=E.loader(i.get(0),{type:"dots"});let r=[];try{r=await p("/forms")}catch{E.toast("Could not load forms.",{type:"error"})}finally{d.destroy()}const l=h();l&&(r=b(r,l)),T.create("#forms-table",{data:r,columns:[{key:"title",title:"Title",render:(e,n)=>{const s=document.createElement("span");s.style.cssText="display:inline-flex;align-items:center;gap:.4rem;flex-wrap:wrap;";const t=document.createElement("a");if(t.href=`#/forms/edit/${u(n.slug)}`,t.textContent=e,t.style.fontWeight="600",s.appendChild(t),n.plugin){const a=document.createElement("span");a.className="badge badge-outline",a.textContent=n.plugin,a.title=`Managed by the ${n.plugin} plugin`,a.style.cssText="font-size:0.65rem;padding:1px 6px;color:var(--dm-warning,#d97706);border-color:var(--dm-warning,#d97706);flex-shrink:0;",s.appendChild(a)}return s.outerHTML}},{key:"slug",title:"Slug",render:e=>{const n=document.createElement("code");return n.textContent=e,n.outerHTML}},{key:"fields",title:"Field Count",render:e=>String(e?.length??0)},{key:"submissionCount",title:"Submission Count",render:e=>String(e??0)},{key:"slug",title:"Actions",render:(e,n)=>{const s=document.createElement("div");s.style.cssText="display:flex;gap:.4rem;justify-content:flex-end;";const t=document.createElement("a");t.href=`#/forms/edit/${u(e)}`,t.className="btn btn-sm btn-ghost",t.setAttribute("data-tooltip","Edit"),t.innerHTML='<span data-icon="edit"></span>';const a=document.createElement("a");a.href=`#/forms/${u(e)}/submissions`,a.className="btn btn-sm btn-ghost",a.setAttribute("data-tooltip","Submissions"),a.innerHTML='<span data-icon="inbox"></span>';const o=document.createElement("button");return o.className="btn btn-sm btn-danger js-delete-form",o.dataset.slug=e,o.dataset.plugin=n.plugin||"",o.setAttribute("data-tooltip","Delete"),o.innerHTML='<span data-icon="trash"></span>',s.appendChild(t),s.appendChild(a),s.appendChild(o),s.outerHTML}}],emptyMessage:'No forms yet. Click "Create Form" to get started.'}),document.querySelectorAll(".js-delete-form").forEach(e=>{e.addEventListener("click",async()=>{const n=e.dataset.slug,s=e.dataset.plugin,t=s?`This form is managed by the <strong>${s}</strong> plugin. Deleting it may cause the plugin to malfunction. Continue?`:`Delete form "${n}" and all its submissions? This cannot be undone.`;if(await E.confirm(t))try{await p(`/forms/${n}`,{method:"DELETE"}),E.toast("Form deleted.",{type:"success"}),await g(i)}catch{E.toast("Failed to delete form.",{type:"error"})}})}),Domma.icons.scan(),document.querySelectorAll("#forms-table [data-tooltip]").forEach(e=>{E.tooltip(e,{content:e.getAttribute("data-tooltip"),position:"top"})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{api as f}from"../api.js";const N={narrow:"Narrow",normal:"Normal",wide:"Wide",full:"Full"},B="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;margin-bottom:.25rem;",S="width:100%;padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;box-sizing:border-box;";function x(n,
|
|
1
|
+
import{api as f}from"../api.js";const N={narrow:"Narrow",normal:"Normal",wide:"Wide",full:"Full"},B="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;margin-bottom:.25rem;",S="width:100%;padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;box-sizing:border-box;";function x(n,t){const e=document.createElement("div");e.style.cssText="display:flex;flex-direction:column;gap:.25rem;";const a=document.createElement("label");return a.style.cssText=B,a.textContent=n,e.appendChild(a),e.appendChild(t),e}function L(n,t){const e=document.createElement("input");return e.type="text",e.placeholder=n||"",e.value=t||"",e.style.cssText=S,e}function k(n,t){const e=document.createElement("label");e.style.cssText="display:flex;align-items:center;gap:.5rem;cursor:pointer;";const a=document.createElement("input");a.type="checkbox",a.checked=!!t;const o=document.createElement("span");return o.style.cssText="font-size:.9em;color:var(--dm-text,#eee);",o.textContent=n,e.appendChild(a),e.appendChild(o),{wrap:e,cb:a}}function F(n){const t=document.createElement("select");return t.style.cssText=S,[["narrow","Narrow (768px)"],["normal","Normal (1100px)"],["wide","Wide (75% of viewport, max 2000px)"],["full","Full width"]].forEach(([e,a])=>{const o=document.createElement("option");o.value=e,o.textContent=a,e===(n||"normal")&&(o.selected=!0),t.appendChild(o)}),t}function D(n){const t=document.createElement("div");t.style.cssText="display:flex;align-items:center;gap:.5rem;flex-wrap:wrap;";const e=document.createElement("input");e.type="color",e.value=n||"#ffffff",e.disabled=!n,e.style.cssText="width:38px;height:32px;padding:2px;border:1px solid var(--dm-border,#333);border-radius:4px;background:transparent;cursor:pointer;";const a=document.createElement("span");a.style.cssText="font-size:.85em;color:var(--dm-text-muted,#aaa);min-width:4rem;",a.textContent=n||"None";const o=document.createElement("button");o.type="button",o.textContent="Choose",o.style.cssText="padding:.25rem .6rem;font-size:.8em;background:transparent;border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text-muted,#aaa);cursor:pointer;";const r=document.createElement("button");return r.type="button",r.textContent="Clear",r.style.cssText=o.style.cssText,r.disabled=!n,o.addEventListener("click",()=>{e.disabled=!1,r.disabled=!1,e.click()}),e.addEventListener("input",()=>{a.textContent=e.value,r.disabled=!1}),r.addEventListener("click",()=>{e.value="#ffffff",e.disabled=!0,r.disabled=!0,a.textContent="None"}),t.appendChild(e),t.appendChild(a),t.appendChild(o),t.appendChild(r),{wrap:t,getValue(){return e.disabled?"":e.value}}}function O(n,t,e){const a=document.createElement("div");a.className="card preset-card",a.style.cssText="cursor:pointer;transition:box-shadow .15s;",a.addEventListener("mouseenter",()=>{a.style.boxShadow="0 0 0 2px var(--dm-primary,#4f7fff)"}),a.addEventListener("mouseleave",()=>{a.style.boxShadow=""}),a.addEventListener("click",()=>e(n,t));const o=document.createElement("div");o.className="card-header",o.style.cssText="display:flex;align-items:center;gap:.5rem;flex-wrap:wrap;";const r=document.createElement("strong");if(r.textContent=t.label||n,o.appendChild(r),t.builtin){const s=document.createElement("span");s.className="badge",s.textContent="built-in",s.style.cssText="font-size:.65rem;",o.appendChild(s)}const d=document.createElement("span");d.className="badge badge-outline",d.textContent=N[t.width]||"Normal",d.style.cssText="margin-left:auto;font-size:.65rem;",o.appendChild(d),a.appendChild(o);const c=document.createElement("div");if(c.className="card-body",t.description){const s=document.createElement("p");s.className="text-muted",s.style.cssText="font-size:.85em;margin:0 0 .5rem;",s.textContent=t.description,c.appendChild(s)}const l=document.createElement("div");if(l.style.cssText="display:flex;gap:.75rem;flex-wrap:wrap;",[["Navbar",t.navbar],["Footer",t.footer],["Sidebar",t.sidebar]].forEach(([s,u])=>{const p=document.createElement("span");p.style.cssText=`font-size:.75em;color:${u?"var(--dm-success,#4caf50)":"var(--dm-text-muted,#666)"};display:flex;align-items:center;gap:.25rem;`,p.textContent=(u?"\u25CF ":"\u25CB ")+s,l.appendChild(p)}),c.appendChild(l),t.bgColor){const s=document.createElement("span");s.title=t.bgColor,s.style.cssText=`display:inline-block;width:14px;height:14px;border-radius:3px;background:${t.bgColor};border:1px solid var(--dm-border,#333);margin-top:.4rem;vertical-align:middle;`,c.appendChild(s)}return a.appendChild(c),a}function z(n,t,e,a,o){const r=E.slideover({title:e?"New Layout":"Edit Layout",size:"md"}),d=document.createElement("div");d.style.cssText="display:flex;flex-direction:column;gap:1rem;padding:1rem;";const c=L("e.g. Dark Landing",t.label||""),l=L("Optional description",t.description||""),s=F(t.width),u=k("Show Navbar",t.navbar!==!1),p=k("Show Footer",t.footer!==!1),g=k("Show Sidebar",t.sidebar===!0),C=D(t.bgColor||""),b=L("https://...",t.bgImage||""),v=L("e.g. no-hero wide-content",t.class||"");d.appendChild(x("Label",c)),d.appendChild(x("Description",l)),d.appendChild(x("Width",s));const y=document.createElement("div");y.style.cssText="display:flex;gap:1.5rem;flex-wrap:wrap;",y.appendChild(u.wrap),y.appendChild(p.wrap),y.appendChild(g.wrap),d.appendChild(y),d.appendChild(x("Background Colour",C.wrap)),d.appendChild(x("Background Image URL",b)),d.appendChild(x("Custom CSS Class",v));const w=document.createElement("div");w.style.cssText="display:flex;gap:.5rem;flex-wrap:wrap;padding-top:.5rem;border-top:1px solid var(--dm-border,#333);";const h=document.createElement("button");if(h.type="button",h.className="btn btn-primary",h.textContent="Save",w.appendChild(h),!e&&!t.builtin){const i=document.createElement("button");i.type="button",i.className="btn btn-danger",i.style.marginLeft="auto",i.textContent="Delete",i.addEventListener("click",async()=>{if(await E.confirm(`Delete the "${t.label||n}" layout?`))try{await f.layouts.remove(n),E.toast("Layout deleted.",{type:"success"}),r.close(),o(n)}catch(m){E.toast(m?.message||"Failed to delete layout.",{type:"error"})}}),w.appendChild(i)}d.appendChild(w),h.addEventListener("click",async()=>{const i=c.value.trim();if(!i){E.toast("Label is required.",{type:"warning"});return}const T={label:i,description:l.value.trim(),width:s.value,navbar:u.cb.checked,footer:p.cb.checked,sidebar:g.cb.checked,bgColor:C.getValue(),bgImage:b.value.trim(),class:v.value.trim()};try{let m;e?m=await f.layouts.create(T):m=await f.layouts.update(n,T),E.toast("Layout saved.",{type:"success"}),r.close(),a(e?m.key:n,m.preset||{...t,...T})}catch(m){E.toast(m?.message||"Failed to save layout.",{type:"error"})}}),r.setContent(d),r.open()}export const layoutsView={templateUrl:"/admin/js/templates/layouts.html",async onMount(n){E.tabs(n.find("#layouts-tabs").get(0));const t=E.loader(n.get(0),{type:"dots"});let e=await f.layouts.get().catch(()=>({}));const a=await f.layouts.getOptions().catch(()=>({spacerSize:8,spacerClass:""}));t.destroy();const o=n.find("#presets-grid");function r(){o.empty();const l=o.get(0);Object.entries(e).forEach(([s,u])=>{const p=O(s,u,(g,C)=>{z(g,C,!1,(b,v)=>{e[b]={...e[b],...v},r()},b=>{delete e[b],r()})});l.appendChild(p)}),I.scan(l)}r(),n.find("#create-layout-btn").on("click",()=>{z(null,{},!0,(l,s)=>{if(!l){E.toast("Layout saved but key missing \u2014 please refresh.",{type:"warning"});return}e[l]=s,r()},()=>{})});const d=n.find("#spacer-size-input"),c=n.find("#spacer-class-input");d.val(a.spacerSize??8),c.val(a.spacerClass??""),n.find("#save-options-btn").on("click",async()=>{const l=parseInt(d.val(),10)||8,s=c.val().trim();try{await f.layouts.saveOptions({spacerSize:l,spacerClass:s}),E.toast("Layout options saved.",{type:"success"})}catch{E.toast("Failed to save layout options.",{type:"error"})}})}};
|
package/admin/js/views/login.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{api as o,isAuthenticated as u,setAuthData as l}from"../api.js";import{THEMES as p}from"../lib/themes.js";const f={name:{type:"string",required:!0,minLength:2,label:"Full Name",formConfig:{placeholder:"Your name",autocomplete:"name"}},email:{type:"email",required:!0,label:"Email Address",formConfig:{placeholder:"admin@example.com",autocomplete:"email"}},password:{type:"password",required:!0,minLength:8,label:"Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"new-password",tooltip:"Minimum 8 characters"}}},h={email:{type:"email",required:!0,label:"Email Address",formConfig:{placeholder:"you@example.com",autocomplete:"email"}},password:{type:"password",required:!0,label:"Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"current-password"}}};export const loginView={templateUrl:"/admin/js/templates/login.html",async onMount(e){if(u()){R.navigate("/");return}const a=window.location.hash,t=a.match(/[?&]token=([a-f0-9]{64})/);if(a.startsWith("#/reset-password")&&t){r(e,"reset"),S(e,t[1]),Domma.icons.scan();return}if(a.startsWith("#/reset-password")){R.navigate("/login");return}let s=!1;try{s=(await o.auth.setupStatus()).needsSetup}catch{E.toast("Could not reach the server.",{type:"error"})}s?(r(e,"setup"),y(e)):(r(e,"login"),k(e)),Domma.icons.scan()}};const g={email:{type:"email",required:!0,label:"Email Address",formConfig:{placeholder:"you@example.com",autocomplete:"email"}}},b={password:{type:"password",required:!0,minLength:8,label:"New Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"new-password",tooltip:"Minimum 8 characters"}},confirmPassword:{type:"password",required:!0,label:"Confirm Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"new-password"}}},w=["setup","onboarding-site","onboarding-theme","onboarding-done","login","forgot","forgot-success","reset"];function r(e,a){w.forEach(t=>e.find(`#${t}-panel`).hide()),e.find(`#${a}-panel`).show(),Domma.icons.scan()}function d(e,a,t){e.find(`#${a}`).text(t).show()}function y(e){F.render("#setup-form-container",f,{},{layout:"stacked",submitText:"Create admin account",onSubmit:async a=>{try{const t=await o.auth.setup(a);l(t),r(e,"onboarding-site"),v(e)}catch(t){return E.toast(t.message||"Setup failed. Please try again.",{type:"error"}),!1}}})}function v(e){e.find("#ob-site-skip").on("click",a=>{a.preventDefault(),r(e,"onboarding-theme"),c(e),m(e)}),e.find("#ob-site-btn").on("click",async()=>{e.find("#ob-site-error").hide();const a=e.find("#ob-title").val().trim(),t=e.find("#ob-tagline").val().trim(),s=e.find("#ob-site-btn").prop("disabled",!0).text("Saving\u2026");try{const i=await o.settings.get();await o.settings.save({...i,title:a||i.title,tagline:t||i.tagline,seo:{...i.seo||{},defaultTitle:a||i.seo&&i.seo.defaultTitle}});const n=await o.navigation.get();await o.navigation.save({...n,brand:{...n.brand||{},text:a||n.brand.text}}),r(e,"onboarding-theme"),c(e),m(e)}catch(i){d(e,"ob-site-error",i.message||"Could not save site details.")}finally{s.prop("disabled",!1).text("Continue")}})}function c(e){const a=e.find("#theme-grid").empty();p.forEach(t=>{const s=$(`
|
|
1
|
+
import{api as o,isAuthenticated as u,setAuthData as l}from"../api.js";import{THEMES as p}from"../lib/themes.js";const f={name:{type:"string",required:!0,minLength:2,label:"Full Name",formConfig:{placeholder:"Your name",autocomplete:"name"}},email:{type:"email",required:!0,label:"Email Address",formConfig:{placeholder:"admin@example.com",autocomplete:"email"}},password:{type:"password",required:!0,minLength:8,label:"Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"new-password",tooltip:"Minimum 8 characters"}}},h={email:{type:"email",required:!0,label:"Email Address",formConfig:{placeholder:"you@example.com",autocomplete:"email"}},password:{type:"password",required:!0,label:"Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"current-password"}}};export const loginView={templateUrl:"/admin/js/templates/login.html",async onMount(e){if(u()){R.navigate("/");return}const a=window.location.hash,t=a.match(/[?&]token=([a-f0-9]{64})/);if(a.startsWith("#/reset-password")&&t){r(e,"reset"),S(e,t[1]),Domma.icons.scan();return}if(a.startsWith("#/reset-password")){R.navigate("/login");return}let s=!1;const i=E.loader(e.get(0),{type:"dots"});try{s=(await o.auth.setupStatus()).needsSetup}catch{E.toast("Could not reach the server.",{type:"error"})}finally{i.destroy()}s?(r(e,"setup"),y(e)):(r(e,"login"),k(e)),Domma.icons.scan()}};const g={email:{type:"email",required:!0,label:"Email Address",formConfig:{placeholder:"you@example.com",autocomplete:"email"}}},b={password:{type:"password",required:!0,minLength:8,label:"New Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"new-password",tooltip:"Minimum 8 characters"}},confirmPassword:{type:"password",required:!0,label:"Confirm Password",formConfig:{placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",autocomplete:"new-password"}}},w=["setup","onboarding-site","onboarding-theme","onboarding-done","login","forgot","forgot-success","reset"];function r(e,a){w.forEach(t=>e.find(`#${t}-panel`).hide()),e.find(`#${a}-panel`).show(),Domma.icons.scan()}function d(e,a,t){e.find(`#${a}`).text(t).show()}function y(e){F.render("#setup-form-container",f,{},{layout:"stacked",submitText:"Create admin account",onSubmit:async a=>{try{const t=await o.auth.setup(a);l(t),r(e,"onboarding-site"),v(e)}catch(t){return E.toast(t.message||"Setup failed. Please try again.",{type:"error"}),!1}}})}function v(e){e.find("#ob-site-skip").on("click",a=>{a.preventDefault(),r(e,"onboarding-theme"),c(e),m(e)}),e.find("#ob-site-btn").on("click",async()=>{e.find("#ob-site-error").hide();const a=e.find("#ob-title").val().trim(),t=e.find("#ob-tagline").val().trim(),s=e.find("#ob-site-btn").prop("disabled",!0).text("Saving\u2026");try{const i=await o.settings.get();await o.settings.save({...i,title:a||i.title,tagline:t||i.tagline,seo:{...i.seo||{},defaultTitle:a||i.seo&&i.seo.defaultTitle}});const n=await o.navigation.get();await o.navigation.save({...n,brand:{...n.brand||{},text:a||n.brand.text}}),r(e,"onboarding-theme"),c(e),m(e)}catch(i){d(e,"ob-site-error",i.message||"Could not save site details.")}finally{s.prop("disabled",!1).text("Continue")}})}function c(e){const a=e.find("#theme-grid").empty();p.forEach(t=>{const s=$(`
|
|
2
2
|
<div class="theme-swatch" data-theme="${t.id}" title="${t.id}">
|
|
3
3
|
<div class="theme-swatch-preview" style="background:${t.bg}">
|
|
4
4
|
<div class="theme-swatch-accent" style="background:${t.primary}"></div>
|