domma-cms 0.99.0 → 0.100.1

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.
@@ -1,8 +1,8 @@
1
- import{apiRequest as ie}from"/admin/js/api.js";import{makeIconInput as et}from"/admin/js/lib/shortcode-modal.js";import{enhancePickerFields as tt}from"/public/js/forms.js";import{buildWizardSteps as jt}from"/public/js/form-steps.mjs";import{addBannerAction as qe}from"../lib/plugin-chrome.js";import{helpPopovers as Vt}from"../lib/help-popover.js";import{openMenuAt as nt,sidebarCount as Gt}from"../lib/tool-kit.js";import{draftKey as se,draftOf as Ht,duplicateField as Wt,fieldTitle as $e,fingerprint as lt,leavingEditor as at,moveField as ot,restoreDraft as Ut,snapshotOf as Ae}from"../lib/form-editor-arrange.js";import{fmtDateTime as Jt}from"../lib/dates.js";const it=[{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:"icon",label:"Icon (icon picker)"},{value:"image",label:"Image (media library)"},{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"}],Fe=new Set(["select","radio","checkbox-group","chooser"]);let w=[],fe=[],q=null,he=null,ne=null,be={};function A(e,t,o=14){e.textContent="";const n=document.createElement("span");return n.setAttribute("data-icon",t),n.setAttribute("data-icon-size",String(o)),n.style.cssText="display:inline-flex;align-items:center;vertical-align:middle;",e.appendChild(n),window.I?.scan?.(e),e}function re(e,t,o,n=14){return A(e,t,n),e.appendChild(document.createTextNode(" "+o)),e}function Ie(e){const t=document.createElement("span");return t.setAttribute("data-icon","help-circle"),t.setAttribute("data-icon-size","12"),t.style.cssText="display:inline-flex;align-items:center;vertical-align:middle;margin-left:.3rem;opacity:.55;cursor:help;",t.title=e,window.I?.scan?.(t),requestAnimationFrame(()=>{try{t.parentNode&&typeof E<"u"&&E.tooltip&&(t.removeAttribute("title"),E.tooltip(t,{content:e,position:"top"}))}catch{}}),t}let ge=null,st=null,Be=null,ce=null;function Oe(){Be?.(),clearTimeout(st),st=setTimeout(()=>{ge&&ge()},350)}function rt(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")}function ct(e){return it.find(t=>t.value===e)?.label||e}function dt(e){return(e||[]).some(t=>t.logic||Array.isArray(t.triggers)&&t.triggers.length)}function pt(e){return e?!!(e.visibility?.conditions?.length||e.requirement?.conditions?.length||e.validation?.length||e.cascade?.sourceField):!1}function Kt(e){const t={...w[e]};if(t.type==="spacer")return t;if(t.type==="page-break"){const m=document.getElementById(`fb-pb-label-${e}`),x=document.getElementById(`fb-pb-desc-${e}`);return m&&(t.label=m.value.trim()||t.label),x&&(t.description=x.value.trim()),t}const o=document.getElementById(`fb-label-${e}`),n=document.getElementById(`fb-name-${e}`),l=document.getElementById(`fb-type-${e}`),a=document.getElementById(`fb-required-${e}`),i=document.getElementById(`fb-placeholder-${e}`),r=document.getElementById(`fb-helper-${e}`),c=document.getElementById(`fb-tooltip-${e}`);if(o&&(t.label=o.value.trim()||t.label),n&&(t.name=n.value.trim()||t.name),l&&(t.type=l.value||t.type),a&&(t.required=a.checked),i&&(t.placeholder=i.value.trim()),r&&(t.helper=r.value.trim()),c&&(t.tooltip=c.value.trim()),t.type==="chooser"){const m=document.getElementById(`fb-chooser-variant-${e}`)?.value;m&&(t.variant=m);const x=document.getElementById(`fb-chooser-multiple-${e}`);x&&(t.multiple=x.checked);const N=document.getElementById(`fb-chooser-density-${e}`)?.value;N&&(t.density=N);const T=document.getElementById(`fb-chooser-columns-${e}`)?.value;T!==""&&T!==void 0&&(t.columns=parseInt(T,10)||3);const I=document.getElementById(`fb-chooser-accent-${e}`)?.value.trim();I?t.accent=I:delete t.accent;const B=document.getElementById(`fb-chooser-accent-style-${e}`)?.value;B?t.accentStyle=B:delete t.accentStyle;const G=document.getElementById(`fb-chooser-glow-${e}`);G&&(t.glow=G.checked);const O=document.getElementById(`fb-chooser-glow-colour-${e}`)?.value.trim();O?t.glowColour=O:delete t.glowColour;const X=document.getElementById(`fb-chooser-shadow-${e}`)?.value;X&&X!=="none"?t.shadow=X:delete t.shadow;const W=document.getElementById(`fb-chooser-shadow-colour-${e}`)?.value.trim();W?t.shadowColour=W:delete t.shadowColour,we(e),w[e]&&Array.isArray(w[e].options)&&(t.options=w[e].options)}else if(Fe.has(t.type)){["variant","density","columns","accent","accentStyle","glow","glowColour","shadow","shadowColour"].forEach(x=>delete t[x]),t.type!=="checkbox-group"&&t.type!=="multiselect"&&delete t.multiple;const m=document.getElementById(`fb-options-${e}`);m&&(t.options=m.value.split(`
2
- `).filter(x=>x.trim()).map(x=>{const[N,...T]=x.split(":");return{value:N.trim(),label:T.join(":").trim()||N.trim()}}))}for(const m of["prefix","suffix"]){const x=document.getElementById(`fb-${m}-icon-${e}`),N=document.getElementById(`fb-${m}-text-${e}`),T={...t.formConfig||{}};if(x||N){const I=x?.value.trim()||"",B=N?.value.trim()||"";I&&/^[a-z0-9-]+$/i.test(I)?T[m]={icon:I}:B?T[m]={text:B.slice(0,24)}:delete T[m]}else Lt.includes(t.type)||delete T[m];t.formConfig=Object.keys(T).length?T:void 0}if(t.type==="textarea"){const m=parseInt(document.getElementById(`fb-rows-${e}`)?.value,10);m>0&&(t.formConfig={...t.formConfig||{},rows:m})}const s=document.getElementById(`fb-span-${e}`),d=document.getElementById(`fb-fullwidth-${e}`);if(s||d){const m={...t.formConfig||{}};if(d?.checked)m.span="full";else{const x=parseInt(s?.value,10);x>1?m.span=x:delete m.span}t.formConfig=Object.keys(m).length?m:void 0}const u=document.getElementById(`fb-minlength-${e}`)?.value;u&&(t.minLength=parseInt(u,10));const b=document.getElementById(`fb-maxlength-${e}`)?.value;b&&(t.maxLength=parseInt(b,10));const y=document.getElementById(`fb-min-${e}`)?.value;y!==""&&y!==void 0&&(t.min=parseFloat(y));const f=document.getElementById(`fb-max-${e}`)?.value;f!==""&&f!==void 0&&(t.max=parseFloat(f));const h=Yt(e);h?t.logic=h:delete t.logic;const k=bn(e);return k?t.triggers=k:delete t.triggers,t}function Yt(e){const t=document.querySelector(`.fb-field-card[data-index="${e}"]`);if(!t)return;const o=t.querySelector(".fb-field-logic");if(!o)return;const n={};let l=!1;const a=o.querySelector('[data-logic-section="visibility"]');if(a){const s=a.querySelector(".fb-logic-vis-default"),d=a.querySelector(".fb-logic-vis-transition"),u=Array.from(a.querySelectorAll(".fb-logic-cond-row")).map(h=>{const k=h.querySelector(".fb-logic-cond-field"),m=h.querySelector(".fb-logic-cond-op"),x=h.querySelector(".fb-logic-cond-val"),N=h.querySelector(".fb-logic-vis-then");return k?.value?{when:{all:[{field:k.value,operator:m.value,value:x.value}]},then:N.value}:null}).filter(Boolean),b=s?.value||"visible",y=d?.value||"none",f=parseInt(a.querySelector(".fb-logic-vis-duration")?.value||"",10);(b!=="visible"||u.length>0||y!=="none")&&(n.visibility={default:b,conditions:u},y!=="none"&&(n.visibility.transition=y),y!=="none"&&Number.isFinite(f)&&(n.visibility.duration=f),l=!0)}const i=o.querySelector('[data-logic-section="requirement"]');if(i){const s=i.querySelector(".fb-logic-req-default"),d=Array.from(i.querySelectorAll(".fb-logic-cond-row")).map(u=>{const b=u.querySelector(".fb-logic-cond-field"),y=u.querySelector(".fb-logic-cond-op"),f=u.querySelector(".fb-logic-cond-val"),h=u.querySelector(".fb-logic-req-then");return b?.value?{when:{all:[{field:b.value,operator:y.value,value:f.value}]},then:h.value==="true"}:null}).filter(Boolean);d.length>0&&(n.requirement={default:s?.checked===!0,conditions:d},l=!0)}const r=o.querySelector('[data-logic-section="validation"]');if(r){const s=Array.from(r.querySelectorAll(".fb-logic-val-rule")).map(d=>{const u=d.querySelector(".fb-logic-val-type"),b=d.querySelector(".fb-logic-val-pattern"),y=d.querySelector(".fb-logic-val-flags"),f=d.querySelector(".fb-logic-val-message");if(!b?.value.trim())return null;const h=u?.value||"regex",k={type:h,message:f?.value.trim()||"Invalid value."};return h==="regex"?(k.pattern=b.value.trim(),y?.value.trim()&&(k.flags=y.value.trim())):k.field=b.value.trim(),k}).filter(Boolean);s.length>0&&(n.validation=s,l=!0)}const c=o.querySelector('[data-logic-section="cascade"]');if(c){const s=c.querySelector(".fb-logic-cascade-source"),d=c.querySelector(".fb-logic-cascade-mapping"),u=c.querySelector(".fb-logic-cascade-defaults"),b=s?.value?.trim();if(b){let y={};try{y=JSON.parse(d?.value||"{}")}catch{}const f=(u?.value||"").split(`
3
- `).filter(h=>h.trim()).map(h=>{const[k,...m]=h.split(":");return{value:k.trim(),label:m.join(":").trim()||k.trim()}});n.cascade={sourceField:b,mapping:y,defaultOptions:f},l=!0}}return l?n:void 0}function D(){w=w.map((e,t)=>Kt(t))}function Qt(e){const t=e.firstElementChild;if(!t||t.querySelector(".fb-drag-grip"))return;const o=document.createElement("span");o.className="fb-drag-grip",o.setAttribute("data-icon","grip-vertical"),o.setAttribute("data-icon-size","16"),o.title="Drag to reorder",t.insertBefore(o,t.firstChild),window.I?.scan?.(t)}function Q(e){const t=e.find("#fields-list").get(0),o=e.find("#fields-empty-msg").get(0);if(t){if(Array.from(t.querySelectorAll(".fb-field-card")).forEach(n=>n.remove()),w.length===0){o&&(o.style.display=""),ce?.(t),Oe();return}o&&(o.style.display="none"),w.forEach((n,l)=>{const a=n.type==="page-break"?Xt(n,l,e):n.type==="spacer"?Zt(n,l,e):en(n,l,e);Qt(a),t.appendChild(a)}),ce?.(t),Oe()}}function Xt(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:2px dashed var(--dm-border);border-radius:8px;overflow:hidden;margin-bottom:.75rem;background:var(--dm-card-bg);";const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.6rem .8rem;cursor:pointer;user-select:none;";const a=document.createElement("span");a.textContent="- Page Break -",a.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);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);";const r=document.createElement("div");r.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;";const c=document.createElement("button");c.className="btn btn-xs btn-ghost",c.title="Edit step",A(c,"more-horizontal"),c.addEventListener("click",y=>{y.stopPropagation(),d.style.display=d.style.display==="none"?"":"none"}),r.appendChild(c);const s=document.createElement("button");s.className="btn btn-xs btn-ghost",s.style.cssText="line-height:1;opacity:.6;",s.title="Remove page break",A(s,"x"),s.addEventListener("click",async y=>{y.stopPropagation(),await E.confirm("Remove this page break?")&&(D(),w.splice(t,1),Q(o))}),r.appendChild(s),l.appendChild(a),l.appendChild(i),l.appendChild(r),l.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);display:none;";const u=_([V("Step Title",`fb-pb-label-${t}`,"text",e.label||"","Shown as the wizard step heading"),V("Step Description",`fb-pb-desc-${t}`,"text",e.description||"","Optional sub-heading")]),b=u.querySelector(`#fb-pb-label-${t}`);return b&&b.addEventListener("input",()=>{i.textContent=b.value||"Untitled Step"}),d.appendChild(u),n.appendChild(l),n.appendChild(d),n}function Zt(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px dashed var(--dm-border);border-radius:6px;margin-bottom:.5rem;background:transparent;";const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.4rem .8rem;";const a=document.createElement("div");a.style.cssText="flex:1;height:1px;background:var(--dm-border);";const i=document.createElement("span");i.textContent="Spacer",i.style.cssText="font-size:.7rem;color:var(--dm-text-muted);white-space:nowrap;padding:0 .4rem;font-style:italic;";const r=document.createElement("div");r.style.cssText="flex:1;height:1px;background:var(--dm-border);";const c=document.createElement("div");c.style.cssText="display:flex;gap:.25rem;flex-shrink:0;";const s=document.createElement("button");return s.className="btn btn-xs btn-ghost",s.style.cssText="line-height:1;opacity:.6;",s.title="Remove spacer",A(s,"x"),s.addEventListener("click",async d=>{d.stopPropagation(),D(),w.splice(t,1),Q(o)}),c.appendChild(s),l.appendChild(a),l.appendChild(i),l.appendChild(r),l.appendChild(c),n.appendChild(l),n}function en(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px solid var(--dm-border);border-radius:8px;overflow:hidden;margin-bottom:.75rem;background:var(--dm-card-bg);box-shadow:var(--dm-shadow-sm);";const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.65rem .85rem;background:var(--dm-card-header-bg);cursor:pointer;user-select:none;";const a=document.createElement("span");a.textContent=ct(e.type),a.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);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 r=document.createElement("div");r.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;";const c=document.createElement("button");c.className="btn btn-xs btn-ghost",c.title="Edit field",A(c,"more-horizontal"),c.addEventListener("click",u=>{u.stopPropagation(),d.style.display=d.style.display==="none"?"":"none"}),r.appendChild(c);const s=document.createElement("button");if(s.className="btn btn-xs btn-ghost",s.style.cssText="line-height:1;opacity:.6;",s.title="Remove field",A(s,"x"),s.addEventListener("click",async u=>{u.stopPropagation(),await E.confirm("Remove this field?")&&(D(),w.splice(t,1),Q(o))}),r.appendChild(s),l.appendChild(a),l.appendChild(i),e.required){const u=document.createElement("span");u.textContent="required",u.style.cssText="font-size:.7rem;color:var(--dm-danger);flex-shrink:0;",l.appendChild(u)}if(pt(e.logic)){const u=document.createElement("span");A(u,"zap"),u.title="Has conditional logic",u.style.cssText="font-size:.75rem;color:var(--dm-primary);flex-shrink:0;",l.appendChild(u)}l.appendChild(r),l.addEventListener("click",()=>{d.style.display=d.style.display==="none"?"":"none"});const d=tn(e,t,i);return d.style.display="none",n.appendChild(l),n.appendChild(d),n}function tn(e,t,o){const n=document.createElement("div");n.className="fb-field-body",n.style.cssText="padding:1rem .9rem;border-top:1px solid var(--dm-border);";const l=_([V("Label",`fb-label-${t}`,"text",e.label||"","Shown above the field"),V("Field Name",`fb-name-${t}`,"text",e.name||"","Used as data key")]),a=_([Sn("Type",`fb-type-${t}`,it,e.type||"string"),Ft("Required",`fb-required-${t}`,e.required||!1)]),i=_([V("Placeholder",`fb-placeholder-${t}`,"text",e.placeholder||"","Hint text inside the field")]),r=_([V("Helper Text",`fb-helper-${t}`,"text",e.helper||"","Shown below the field"),V("Tooltip",`fb-tooltip-${t}`,"text",e.tooltip||"","Shown on hover via a help icon next to the label")]),c=e.formConfig?.span,s=_([V("Column Span",`fb-span-${t}`,"number",c&&c!=="full"?String(c):"1","Columns to span (grid only)"),Ft("Full Width",`fb-fullwidth-${t}`,c==="full")]);s.classList.add("fb-grid-row"),s.style.display=document.getElementById("setting-layout")?.value==="grid"?"flex":"none",n.appendChild(l),n.appendChild(a),n.appendChild(i),n.appendChild(r),n.appendChild(s);const d=n.querySelector(`#fb-label-${t}`),u=n.querySelector(`#fb-name-${t}`);d&&d.addEventListener("input",()=>{o&&(o.textContent=d.value||"(unlabelled)"),u&&!u.dataset.manuallyEdited&&(u.value=rt(d.value))}),u&&u.addEventListener("input",()=>{u.dataset.manuallyEdited="1"});const b=n.querySelector(`#fb-type-${t}`);b&&b.addEventListener("change",()=>{const f=n.closest(".fb-field-card");if(f){const m=f.querySelector("span");m&&(m.textContent=ct(b.value))}const h=n.querySelector(".fb-field-extras");h&&h.remove();const k=Nt(b.value,e,t);k&&n.appendChild(k)});const y=Nt(e.type,e,t);return y&&n.appendChild(y),n.appendChild(sn(e,t)),n.appendChild(fn(e,t)),n}const ye=[{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"}],Re=new Set(["is_empty","is_not_empty"]),ut={equals:"includes",not_equals:"does not include",contains:"any value contains",not_contains:"no value contains",starts_with:"any value starts with",ends_with:"any value ends with",greater_than:"any value is greater than",less_than:"any value is less than",is_empty:"nothing selected",is_not_empty:"something selected",in:"includes one of (comma sep)",not_in:"includes none of (comma sep)",matches_regex:"any value matches regex"};function Me(e){return!!e&&(e.type==="checkbox-group"||!!e.multiple)}function ve(e){const t=document.createElement("p");return t.textContent=e,t.style.cssText="font-size:.75rem;font-weight:700;color:var(--dm-text-muted);margin:0 0 .7rem;text-transform:uppercase;letter-spacing:.06em;",t}function xe(e,t,o,n,l){const a=document.createElement("div");a.className="fb-logic-cond-row",a.style.cssText="display:flex;gap:.55rem;align-items:center;margin-bottom:.6rem;flex-wrap:wrap;";const i=document.createElement("span");i.textContent="When",i.style.cssText="font-size:.73rem;color:var(--dm-text-muted);flex-shrink:0;";const r=document.createElement("select");r.className="form-select fb-logic-cond-field",r.style.cssText="flex:1 1 140px;min-width:140px;",t.forEach(f=>{const h=document.createElement("option");h.value=f.value,h.textContent=f.label,e&&f.value===e.field&&(h.selected=!0),r.appendChild(h)});const c=document.createElement("select");c.className="form-select fb-logic-cond-op",c.style.cssText="flex:1 1 160px;min-width:140px;",ye.forEach(f=>{const h=document.createElement("option");h.value=f.value,h.textContent=f.label,e&&f.value===e.operator&&(h.selected=!0),c.appendChild(h)});const s=()=>{const f=t.find(h=>h.value===r.value);Array.from(c.options).forEach(h=>{const k=ye.find(m=>m.value===h.value);h.textContent=f?.multi&&ut[h.value]||k?.label||h.value})};s(),r.addEventListener("change",s);const d=document.createElement("input");d.type="text",d.className="form-input fb-logic-cond-val",d.placeholder="value",d.style.cssText="flex:1 1 120px;min-width:100px;",d.value=e?.value||"",e&&Re.has(e.operator)&&(d.style.display="none"),c.addEventListener("change",()=>{d.style.display=Re.has(c.value)?"none":""});const u=document.createElement("span");A(u,"arrow-right"),u.style.cssText="font-size:.73rem;color:var(--dm-text-muted);flex-shrink:0;";const b=document.createElement("select");b.className=`form-select ${n}`,b.style.cssText="flex:1 1 140px;min-width:120px;",o.forEach(f=>{const h=document.createElement("option");h.value=f.value,h.textContent=f.label,f.value===l&&(h.selected=!0),b.appendChild(h)});const y=document.createElement("button");return y.type="button",y.className="btn btn-xs btn-ghost",y.style.cssText="line-height:1;opacity:.6;",A(y,"x"),y.style.flexShrink="0",y.addEventListener("click",()=>a.remove()),a.appendChild(i),a.appendChild(r),a.appendChild(c),a.appendChild(d),a.appendChild(u),a.appendChild(b),a.appendChild(y),a}function nn(e,t,o){const n=document.createElement("div");n.dataset.logicSection="visibility",n.appendChild(ve("Visibility"));const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:.6rem;margin-bottom:.65rem;flex-wrap:wrap;";const a=document.createElement("span");a.textContent="Default:",a.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 x=document.createElement("option");x.value=m.value,x.textContent=m.label,m.value===(e.default||"visible")&&(x.selected=!0),i.appendChild(x)}),l.appendChild(a),l.appendChild(i),n.appendChild(l);const r=document.createElement("div");r.style.cssText="display:flex;align-items:center;gap:.6rem;margin-bottom:.65rem;flex-wrap:wrap;";const c=document.createElement("span");c.textContent="Transition:",c.style.cssText="font-size:.8rem;flex-shrink:0;";const s=document.createElement("select");s.className="form-select fb-logic-vis-transition",s.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 x=document.createElement("option");x.value=m.value,x.textContent=m.label,m.value===(e.transition||"none")&&(x.selected=!0),s.appendChild(x)}),r.appendChild(c),r.appendChild(s),n.appendChild(r);const d=document.createElement("div");d.style.cssText="display:flex;align-items:center;gap:.6rem;margin-bottom:.65rem;flex-wrap:wrap;";const u=document.createElement("span");u.textContent="Speed:",u.style.cssText="font-size:.8rem;flex-shrink:0;";const b=document.createElement("select");b.className="form-select fb-logic-vis-duration",b.style.cssText="max-width:240px;",[{value:"",label:"Default"},{value:"120",label:"Very fast (120ms)"},{value:"200",label:"Fast (200ms)"},{value:"350",label:"Medium (350ms)"},{value:"600",label:"Slow (600ms)"},{value:"1000",label:"Very slow (1s)"}].forEach(m=>{const x=document.createElement("option");x.value=m.value,x.textContent=m.label,m.value===String(e.duration??"")&&(x.selected=!0),b.appendChild(x)}),d.appendChild(u),d.appendChild(b),n.appendChild(d);const y=()=>{d.style.display=s.value==="none"?"none":""};y(),s.addEventListener("change",y);const f=document.createElement("div");f.className="fb-logic-vis-rules";const h=o.map(m=>({value:m.name,label:m.label||m.name,multi:Me(m)})),k=[{value:"visible",label:"Show"},{value:"hidden",label:"Hide"}];if((e.conditions||[]).forEach(m=>{const x=(m.when?.all||m.when?.any||[])[0],N=m.then==="hidden"?"hidden":"visible";h.length>0&&f.appendChild(xe(x,h,k,"fb-logic-vis-then",N))}),n.appendChild(f),h.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:.35rem;",re(m,"plus","Add visibility rule"),m.addEventListener("click",()=>f.appendChild(xe(null,h,k,"fb-logic-vis-then","visible"))),n.appendChild(m)}return n}function ln(e,t,o){const n=document.createElement("div");n.dataset.logicSection="requirement",n.appendChild(ve("Conditional Requirement"));const l=document.createElement("label");l.style.cssText="display:flex;align-items:center;gap:.5rem;font-size:.8rem;cursor:pointer;margin-bottom:.65rem;";const a=document.createElement("input");a.type="checkbox",a.className="fb-logic-req-default",a.checked=e.default===!0,l.appendChild(a),l.appendChild(document.createTextNode("Required by default")),n.appendChild(l);const i=document.createElement("div");i.className="fb-logic-req-rules";const r=o.map(s=>({value:s.name,label:s.label||s.name,multi:Me(s)})),c=[{value:"true",label:"Make required"},{value:"false",label:"Make optional"}];if((e.conditions||[]).forEach(s=>{const d=(s.when?.all||s.when?.any||[])[0],u=s.then===!0?"true":"false";r.length>0&&i.appendChild(xe(d,r,c,"fb-logic-req-then",u))}),n.appendChild(i),r.length>0){const s=document.createElement("button");s.type="button",s.className="btn btn-xs btn-ghost",s.style.cssText="font-size:.73rem;margin-top:.35rem;",re(s,"plus","Add requirement rule"),s.addEventListener("click",()=>i.appendChild(xe(null,r,c,"fb-logic-req-then","true"))),n.appendChild(s)}return n}function mt(e){const t=document.createElement("div");t.className="fb-logic-val-rule",t.style.cssText="display:flex;gap:.55rem;align-items:center;margin-bottom:.6rem;flex-wrap:wrap;";const o=document.createElement("select");o.className="form-select fb-logic-val-type",o.style.cssText="flex:0 0 140px;",[{value:"regex",label:"Regex"},{value:"match",label:"Match field"}].forEach(r=>{const c=document.createElement("option");c.value=r.value,c.textContent=r.label,r.value===(e?.type||"regex")&&(c.selected=!0),o.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 l=document.createElement("input");l.type="text",l.className="form-input fb-logic-val-flags",l.placeholder="flags",l.value=e?.flags||"",l.style.cssText="flex:0 0 55px;",e?.type==="match"&&(l.style.display="none"),o.addEventListener("change",()=>{l.style.display=o.value==="match"?"none":"",n.placeholder=o.value==="match"?"field name":"pattern"});const a=document.createElement("input");a.type="text",a.className="form-input fb-logic-val-message",a.placeholder="Error message",a.value=e?.message||"",a.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;",A(i,"x"),i.style.flexShrink="0",i.addEventListener("click",()=>t.remove()),t.appendChild(o),t.appendChild(n),t.appendChild(l),t.appendChild(a),t.appendChild(i),t}function an(e,t,o){const n=document.createElement("div");n.dataset.logicSection="validation",n.appendChild(ve("Custom Validation"));const l=document.createElement("div");l.className="fb-logic-val-rules",(e||[]).forEach(i=>l.appendChild(mt(i))),n.appendChild(l);const a=document.createElement("button");return a.type="button",a.className="btn btn-xs btn-ghost",a.style.cssText="font-size:.73rem;margin-top:.35rem;",re(a,"plus","Add validation rule"),a.addEventListener("click",()=>l.appendChild(mt(null))),n.appendChild(a),n}function on(e,t,o){const n=document.createElement("div");n.dataset.logicSection="cascade",n.appendChild(ve("Cascade Options")),n.lastChild.appendChild(Ie("Make this field's options depend on another field. When the source field changes, the options here are replaced by the mapping entry for its value; if nothing matches, the default options below are shown."));const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.5rem;";const a=document.createElement("span");a.textContent="Source field:",a.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 r=document.createElement("option");r.value="",r.textContent="- none -",i.appendChild(r),o.forEach(b=>{const y=document.createElement("option");y.value=b.name,y.textContent=b.label||b.name,b.name===e.sourceField&&(y.selected=!0),i.appendChild(y)}),l.appendChild(a),l.appendChild(i),n.appendChild(l);const c=document.createElement("p");c.textContent='Mapping JSON - {"value":[{"value":"...","label":"..."}]}',c.appendChild(Ie(`Each key is a value of the source field; its list becomes this field's options when that value is picked. Example: {"uk":[{"value":"london","label":"London"}]} shows London when the source is "uk".`)),c.style.cssText="font-size:.73rem;color:var(--dm-text-muted);margin:.3rem 0 .2rem;";const s=document.createElement("textarea");s.className="form-input fb-logic-cascade-mapping",s.rows=4,s.style.cssText="font-family:monospace;",s.placeholder='{"uk": [{"value": "london", "label": "London"}]}',s.value=e.mapping?JSON.stringify(e.mapping,null,2):"",n.appendChild(c),n.appendChild(s);const d=document.createElement("p");d.textContent="Default options (one per line: value:Label)",d.appendChild(Ie("Shown before the source field has a value, or when its value has no mapping entry.")),d.style.cssText="font-size:.73rem;color:var(--dm-text-muted);margin:.3rem 0 .2rem;";const u=document.createElement("textarea");return u.className="form-input fb-logic-cascade-defaults",u.rows=3,u.style.cssText="font-family:monospace;",u.placeholder=`option1:Option 1
4
- option2:Option 2`,u.value=(e.defaultOptions||[]).map(b=>{const y=typeof b=="string"?b:b.value??"",f=typeof b=="string"?b:b.label??y;return y===f?y:`${y}:${f}`}).join(`
5
- `),n.appendChild(d),n.appendChild(u),n}function sn(e,t){const o=e.logic||{},n=w.filter((u,b)=>b!==t&&u.type!=="page-break"&&u.type!=="spacer"),l=document.createElement("div");l.className="fb-field-logic",l.style.cssText="margin-top:.75rem;border-top:1px solid var(--dm-border);padding-top:.5rem;";const a=document.createElement("div");a.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);",i.textContent="\u26A1 Conditional Logic";const r=pt(o),c=document.createElement("button");c.type="button",c.className="btn btn-xs btn-ghost",A(c,r?"chevron-down":"chevron-right",12);const s=document.createElement("div");s.className="fb-logic-body",s.style.cssText="padding:.25rem 0 .25rem;"+(r?"":"display:none;"),a.addEventListener("click",()=>{const u=s.style.display==="none";s.style.display=u?"":"none",A(c,u?"chevron-down":"chevron-right",12)}),a.appendChild(i),a.appendChild(c),l.appendChild(a),s.appendChild(nn(o.visibility||{},t,n)),s.appendChild(ln(o.requirement||{},t,n)),s.appendChild(an(o.validation||[],t,n));const d=document.getElementById(`fb-type-${t}`)?.value||e.type;return Fe.has(d)&&s.appendChild(on(o.cascade||{},t,n)),l.appendChild(s),l}const de=[{value:"banner",label:"Show a banner",kind:"state",params:["message","level","position","dismissible"],placeholder:"e.g. You must be 18 or over to continue."},{value:"toast",label:"Show a toast",kind:"event",params:["message","level"],placeholder:"e.g. Thanks - carry on."},{value:"hide-fields",label:"Hide fields",kind:"state",params:["target"]},{value:"disable-fields",label:"Disable fields",kind:"state",params:["target"]},{value:"require-fields",label:"Make fields required",kind:"state",params:["target"]},{value:"block-submit",label:"Block submission",kind:"state",params:["message"],messageLabel:"Reason, shown under the button",placeholder:'Blank: "This form cannot be submitted yet."'},{value:"end-form",label:"End the form here",kind:"state",params:["message","finish","finishLabel","doneMessage","record"],messageLabel:"Message shown in place of the rest",placeholder:"e.g. Sorry - you must be 18 or over to apply."},{value:"goto-step",label:"Jump to a wizard step",kind:"event",params:["step"]},{value:"redirect",label:"Redirect after submit",kind:"event",params:["url"]},{value:"celebrate",label:"Celebrate",kind:"event",params:["theme","intensity"]},{value:"run-action",label:"Run a CMS action",kind:"event",params:["slug"]},{value:"notify",label:"Notify the admins",kind:"event",params:["message","level"],messageLabel:"Notification title",placeholder:"Blank: titled after the form",noOnce:!0,kindText:"when the form is submitted"}],Ce=[{value:"info",label:"Info"},{value:"success",label:"Success"},{value:"warning",label:"Warning"},{value:"error",label:"Error"}],ft=[{value:"field-below",label:"Below this field"},{value:"field-above",label:"Above this field"},{value:"form-top",label:"Top of the form"}],ht=[{value:"rest",label:"The rest of the form"},{value:"all",label:"Every other field"},{value:"listed",label:"Chosen fields"}],bt=[{value:"auto",label:"Whatever is in season"},{value:"christmas",label:"Christmas"},{value:"halloween",label:"Halloween"},{value:"valentines",label:"Valentine's Day"},{value:"guy-fawkes",label:"Guy Fawkes Night"},{value:"st-patricks",label:"St Patrick's Day"},{value:"st-andrews",label:"St Andrew's Day"},{value:"st-davids",label:"St David's Day"},{value:"st-georges",label:"St George's Day"}];function gt(e,t=!1){const o=(i,r)=>({value:i.name,label:`${i.label||i.name}${r?" (this field)":""}`,multi:Me(i)}),n=i=>i&&i.type!=="page-break"&&i.type!=="spacer"&&i.name,l=w.filter((i,r)=>r!==e&&n(i)).map(i=>o(i,!1)),a=w[e];return t&&n(a)?[o(a,!0),...l]:l}function J(e,t,o){const n=document.createElement("select");return n.className=`form-select ${e}`,t.forEach(l=>{const a=document.createElement("option");a.value=l.value,a.textContent=l.label,l.value===o&&(a.selected=!0),n.appendChild(a)}),n}function le(e,t,o){const n=document.createElement("input");return n.type="text",n.className=`form-input ${e}`,n.value=t==null?"":String(t),o&&(n.placeholder=o),n}function ze(e,t){const o=document.createElement("button");return o.type="button",o.className="btn btn-xs btn-ghost fb-trig-remove",t&&(o.title=t,o.setAttribute("aria-label",t)),A(o,"x"),o.addEventListener("click",n=>{n.stopPropagation(),e()}),o}function j(e,t,{full:o=!1,hint:n=""}={}){const l=document.createElement("label");l.className=`fb-trig-f${o?" fb-trig-f--full":""}`;const a=document.createElement("span");if(a.className="fb-trig-f-label",a.textContent=e,l.appendChild(a),l.appendChild(t),n){const i=document.createElement("span");i.className="fb-trig-f-hint",i.textContent=n,l.appendChild(i)}return l}function pe(e,t,o,n){const l=document.createElement("label");l.className="fb-trig-check",n&&(l.title=n);const a=document.createElement("input");return a.type="checkbox",a.className=`form-check ${e}`,a.checked=!!t,l.appendChild(a),l.appendChild(document.createTextNode(o)),l}function yt(e,t){const o=document.createElement("div");o.className="fb-trig-cond-row";const n=J("fb-trig-cond-field",t,e?.field),l=J("fb-trig-cond-op",ye,e?.operator),a=le("fb-trig-cond-val",e?.value,"value"),i=()=>{const c=t.find(s=>s.value===n.value);Array.from(l.options).forEach(s=>{const d=ye.find(u=>u.value===s.value);s.textContent=c?.multi&&ut[s.value]||d?.label||s.value})},r=()=>{a.hidden=Re.has(l.value)};return i(),r(),n.addEventListener("change",i),l.addEventListener("change",r),o.appendChild(n),o.appendChild(l),o.appendChild(a),o.appendChild(ze(()=>o.remove(),"Remove condition")),o}const vt=["banner","toast","block-submit","end-form"],xt=["password","file","image","signature"],rn="Put an answer in with {{field_name}} - e.g. Hello {{name}}. Pick one from Insert field.";function cn(){try{D()}catch{}return w.filter(e=>e&&e.name&&e.type!=="page-break"&&e.type!=="spacer"&&!xt.includes(e.type))}function Ct(e,t,o){const n=le(e,t,o),l=document.createElement("span");l.className="fb-token-row";const a=document.createElement("select");a.className="form-input fb-token-pick",a.title="Insert an answer into the message",a.setAttribute("aria-label","Insert a field's answer into the message");const i=()=>{a.replaceChildren(new Option("Insert field",""));for(const r of cn())a.appendChild(new Option(`${r.label||r.name} ({{${r.name}}})`,r.name))};return i(),a.addEventListener("focus",i),a.addEventListener("mousedown",i),a.addEventListener("change",()=>{const r=a.value;if(a.value="",!r)return;const c=`{{${r}}}`,s=n.selectionStart??n.value.length,d=n.selectionEnd??s;n.value=n.value.slice(0,s)+c+n.value.slice(d),n.focus(),n.setSelectionRange(s+c.length,s+c.length),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0}))}),l.append(n,a),l}function dn(e){const t=window.FormLogicEngine;if(!t?.triggerTokens)return[];const o=new Map((e||[]).filter(l=>l&&l.name).map(l=>[l.name,l])),n=new Set;for(const l of e||[])for(const a of l?.triggers||[])for(const i of[...a.then||[],...a.otherwise||[]])if(vt.includes(i?.type))for(const r of[...t.triggerTokens(i.message),...t.triggerTokens(i.doneMessage)]){const c=o.get(r);(!c||xt.includes(c.type))&&n.add(r)}return[...n]}function Et(e,t){const o=document.createElement("div");o.className="fb-trig-params";const n=de.find(c=>c.value===(e.type||"banner"));if(!n)return o;const l=document.createElement("div");l.className="fb-trig-grid";const a=document.createElement("div");a.className="fb-trig-opts";const i=[];for(const c of n.params)switch(c){case"message":l.appendChild(vt.includes(n.value)?j(n.messageLabel||"Message",Ct("fb-trig-p-message",e.message,n.placeholder||""),{full:!0,hint:rn}):j(n.messageLabel||"Message",le("fb-trig-p-message",e.message,n.placeholder||""),{full:!0}));break;case"finish":a.appendChild(pe("fb-trig-p-finish-on",e.finish!==!1,"Let the visitor finish (send the answers given so far)",'Untick to stop the form dead: the submit button is disabled and nothing is sent, so nothing is saved and "Notify the admins" cannot fire.'));break;case"finishLabel":{const s=j("Button text",le("fb-trig-p-finish",e.finishLabel,"Finish"));i.push(s),l.appendChild(s);break}case"doneMessage":{const s=j("Closing message",Ct("fb-trig-p-done",e.doneMessage,"Blank: the form's own success message"));i.push(s),l.appendChild(s);break}case"record":{const s=pe("fb-trig-p-record",e.record!==!1,"Save the answers given so far",`Untick to keep nothing: no submission is stored and the form's email, webhook and actions do not run. A "Notify the admins" action still fires.`);i.push(s),a.appendChild(s);break}case"level":l.appendChild(j(n.value==="notify"?"Severity":"Level",J("fb-trig-p-level",Ce,e.level||"info")));break;case"position":l.appendChild(j("Where",J("fb-trig-p-position",ft,e.position||"field-below")));break;case"dismissible":a.appendChild(pe("fb-trig-p-dismissible",e.dismissible!==!1,"The visitor can dismiss it"));break;case"target":{const s=J("fb-trig-p-target",ht,e.target||(e.fields?.length?"listed":"rest")),d=document.createElement("select");d.className="form-select fb-trig-p-fields",d.multiple=!0,d.size=4;const u=new Set(e.fields||[]);gt(t).forEach(f=>{const h=document.createElement("option");h.value=f.value,h.textContent=f.label,u.has(f.value)&&(h.selected=!0),d.appendChild(h)});const b=j("Fields",d,{hint:"Ctrl/Cmd-click to pick several"}),y=()=>{b.hidden=s.value!=="listed"};y(),s.addEventListener("change",y),l.appendChild(j("Which fields",s)),l.appendChild(b);break}case"step":{const s=le("fb-trig-p-step",e.step,"0");s.type="number",s.min="0",l.appendChild(j("Step",s,{hint:"Counting from 0"}));break}case"url":l.appendChild(j("Send them to",le("fb-trig-p-url",e.url,"/thank-you"),{full:!0}));break;case"theme":l.appendChild(j("Theme",J("fb-trig-p-theme",bt,e.theme||"auto")));break;case"intensity":l.appendChild(j("Intensity",J("fb-trig-p-intensity",[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}],e.intensity||"medium")));break;case"slug":{const s=[{value:"",label:fe.length?"Choose an action":"No actions available"}].concat(fe.map(d=>({value:d.slug,label:d.title||d.slug})));l.appendChild(j("Action",J("fb-trig-p-slug",s,e.slug||""),{full:!0}));break}default:break}n.kind==="event"&&!n.noOnce&&a.appendChild(pe("fb-trig-p-once",!!e.once,"Only once","Fire the first time only, rather than every time the answer swings back."));const r=a.querySelector(".fb-trig-p-finish-on");if(r){const c=()=>i.forEach(s=>{s.hidden=!r.checked});c(),r.addEventListener("change",c)}return l.children.length&&o.appendChild(l),a.children.length&&o.appendChild(a),o}function pn(e){return e?.kindText?e.kindText:e?.kind==="event"?"once, when it becomes true":"while it is true"}const un=(e,t=48)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e,ae=(e,t)=>e.find(o=>o.value===t)?.label||t;function mn(e){if(!e)return"";const t=[],o=l=>l?`"${un(l)}"`:"",n=()=>e.target==="listed"?e.fields?.length?e.fields.join(", "):"no fields chosen":ae(ht,e.target||"rest").toLowerCase();switch(e.type){case"banner":t.push(o(e.message)||"No message yet",ae(Ce,e.level||"info"),ae(ft,e.position||"field-below").toLowerCase());break;case"toast":t.push(o(e.message)||"No message yet",ae(Ce,e.level||"info"));break;case"hide-fields":case"disable-fields":case"require-fields":t.push(n());break;case"block-submit":t.push(o(e.message)||"the standard reason");break;case"end-form":t.push(o(e.message)||"no message"),e.finish===!1?t.push("submit disabled"):t.push(`button "${e.finishLabel||"Finish"}"`,e.record===!1?"saves nothing":"saves the answers");break;case"goto-step":t.push(Number.isFinite(e.step)?`step ${e.step}`:"no step yet");break;case"redirect":t.push(e.url||"no address yet");break;case"celebrate":t.push(ae(bt,e.theme||"auto"),`${e.intensity||"medium"} intensity`);break;case"run-action":t.push(e.slug?fe.find(l=>l.slug===e.slug)?.title||e.slug:"no action chosen");break;case"notify":t.push(o(e.message)||"titled after the form",ae(Ce,e.level||"info"));break;default:break}return e.once&&t.push("only once"),t.filter(Boolean).join(" \xB7 ")}function De(e,t,{open:o=!1}={}){const n=document.createElement("div");n.className="fb-trig-action-row";const l=document.createElement("div");l.className="fb-trig-action-head",l.tabIndex=0,l.setAttribute("role","button");const a=document.createElement("span");a.className="fb-trig-chevron";const i=document.createElement("span");i.className="fb-trig-action-main";const r=document.createElement("strong"),c=document.createElement("small");c.className="fb-trig-action-summary",i.append(r,c);const s=document.createElement("span");s.className="fb-trig-kind",l.append(a,i,s,ze(()=>n.remove(),"Remove action"));const d=document.createElement("div");d.className="fb-trig-action-body";const u=J("fb-trig-action-type",de,e.type||"banner");d.appendChild(j("Action",u,{full:!0})),d.appendChild(Et(e,t));const b=()=>{const f=de.find(h=>h.value===u.value);r.textContent=f?.label||u.value,s.textContent=pn(f),s.classList.toggle("fb-trig-kind--event",f?.kind==="event"),c.textContent=mn(Tt(n))},y=f=>{d.hidden=!f,n.classList.toggle("is-open",f),l.setAttribute("aria-expanded",String(f)),A(a,f?"chevron-down":"chevron-right",12)};return l.addEventListener("click",()=>y(d.hidden)),l.addEventListener("keydown",f=>{f.target!==l||f.key!=="Enter"&&f.key!==" "||(f.preventDefault(),y(d.hidden))}),u.addEventListener("change",()=>{const f=Et({type:u.value},t);d.replaceChild(f,d.querySelector(".fb-trig-params")),b(),window.I?.scan?.()}),d.addEventListener("input",b),d.addEventListener("change",b),n.append(l,d),y(o),b(),n}function wt(e,t,o){const n=document.createElement("section");n.className=`fb-trig-sec fb-trig-sec--${e}`;const l=document.createElement("div");l.className="fb-trig-sec-head";const a=document.createElement("span");if(a.className="fb-trig-sec-title",a.textContent=t,l.appendChild(a),o){const i=document.createElement("span");i.className="fb-trig-sec-hint",i.textContent=o,l.appendChild(i)}return n.appendChild(l),n}function _e(e,t){const o=document.createElement("button");return o.type="button",o.className="btn btn-xs btn-ghost fb-trig-add",re(o,"plus",e,12),o.addEventListener("click",t),o}function kt(e,t,o,n){const a=wt(e,t,e==="then"?"What happens while the answers match.":"What happens while they do not. Leave empty for nothing.");a.classList.add("fb-trig-branch"),a.dataset.branch=e;const i=document.createElement("div");return i.className="fb-trig-action-list",(o||[]).forEach(r=>i.appendChild(De(r,n))),a.appendChild(i),a.appendChild(_e("Add action",()=>{i.appendChild(De({type:"banner"},n,{open:!0})),window.I?.scan?.()})),a}function St(e,t,o){const n=gt(t,!0),l=document.createElement("div");l.className="fb-trig-card",l.dataset.triggerId=e.id||`trg-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;const a=document.createElement("div");a.className="fb-trig-card-head";const i=document.createElement("span");i.className="fb-trig-card-title",i.textContent=`Trigger ${o+1}`,a.appendChild(i);const r=pe("fb-trig-enabled",e.enabled!==!1,"Enabled","Untick to keep the trigger but switch it off.");if(a.appendChild(r),a.appendChild(ze(()=>l.remove(),"Remove trigger")),l.appendChild(a),!n.length){const u=document.createElement("p");return u.className="fb-trig-empty",u.textContent="Give this field a name first - a trigger tests an answer, and it needs something to test.",l.appendChild(u),l}const c=wt("when","When");c.querySelector(".fb-trig-sec-head").appendChild(J("fb-trig-match",[{value:"all",label:"all of these are true"},{value:"any",label:"any of these is true"}],Array.isArray(e.when?.any)?"any":"all"));const s=document.createElement("div");s.className="fb-trig-cond-list";const d=e.when?.all||e.when?.any||[];return(d.length?d:[{}]).forEach(u=>s.appendChild(yt(u,n))),c.appendChild(s),c.appendChild(_e("Add condition",()=>{s.appendChild(yt({},n)),window.I?.scan?.()})),l.appendChild(c),l.appendChild(kt("then","Then",e.then,t)),l.appendChild(kt("otherwise","Otherwise",e.otherwise,t)),l}function fn(e,t){const o=Array.isArray(e.triggers)?e.triggers:[],n=document.createElement("div");n.className="fb-field-triggers";const l=document.createElement("div");l.className="fb-trig-panel-head";const a=document.createElement("span");a.className="fb-trig-panel-title",a.textContent=`\u{1F3AF} Triggers${o.length?` (${o.length})`:""}`;const i=document.createElement("button");i.type="button",i.className="btn btn-xs btn-ghost",A(i,o.length?"chevron-down":"chevron-right",12);const r=document.createElement("div");r.className="fb-triggers-body",r.hidden=!o.length,l.addEventListener("click",()=>{r.hidden=!r.hidden,A(i,r.hidden?"chevron-right":"chevron-down",12)});const c=document.createElement("p");c.className="fb-trig-blurb",c.textContent="Do something to the form when the answers meet a condition - show a banner or toast, hide, disable or require other fields, refuse the submit, end the form early, notify the admins, jump to a step, or celebrate.",r.appendChild(c);const s=document.createElement("div");return s.className="fb-trig-list",o.forEach((d,u)=>s.appendChild(St(d,t,u))),r.appendChild(s),r.appendChild(_e("Add trigger",()=>{const d=St({enabled:!0,then:[]},t,s.children.length);s.appendChild(d),d.querySelector('.fb-trig-branch[data-branch="then"] .fb-trig-action-list')?.appendChild(De({type:"banner"},t,{open:!0})),window.I?.scan?.()})),l.appendChild(a),l.appendChild(i),n.appendChild(l),n.appendChild(r),n}function Tt(e){const t=e.querySelector(".fb-trig-action-type")?.value,o=de.find(a=>a.value===t);if(!o)return null;const n={type:t},l=a=>e.querySelector(a)?.value?.trim()||"";for(const a of o.params)switch(a){case"message":n.message=l(".fb-trig-p-message");break;case"finishLabel":{const i=l(".fb-trig-p-finish");i&&(n.finishLabel=i);break}case"doneMessage":{const i=l(".fb-trig-p-done");i&&(n.doneMessage=i);break}case"finish":e.querySelector(".fb-trig-p-finish-on")?.checked||(n.finish=!1);break;case"record":e.querySelector(".fb-trig-p-record")?.checked||(n.record=!1);break;case"level":n.level=l(".fb-trig-p-level")||"info";break;case"position":n.position=l(".fb-trig-p-position")||"field-below";break;case"dismissible":n.dismissible=!!e.querySelector(".fb-trig-p-dismissible")?.checked;break;case"target":{const i=l(".fb-trig-p-target")||"rest";n.target=i,i==="listed"&&(n.fields=Array.from(e.querySelectorAll(".fb-trig-p-fields option")).filter(r=>r.selected).map(r=>r.value));break}case"step":{const i=parseInt(l(".fb-trig-p-step"),10);Number.isFinite(i)&&(n.step=i);break}case"url":n.url=l(".fb-trig-p-url");break;case"theme":n.theme=l(".fb-trig-p-theme")||"auto";break;case"intensity":n.intensity=l(".fb-trig-p-intensity")||"medium";break;case"slug":n.slug=l(".fb-trig-p-slug");break;default:break}return o.kind==="event"&&!o.noOnce&&e.querySelector(".fb-trig-p-once")?.checked&&(n.once=!0),n}function hn(e){const t=Tt(e);if(!t)return null;const o=de.find(a=>a.value===t.type),n=t.type,l=["block-submit","end-form","notify"].includes(o.value);return o.params.includes("message")&&!t.message&&!l?(delete t.message,null):(l&&!t.message&&delete t.message,n==="redirect"&&!t.url||n==="run-action"&&!t.slug?null:t)}function bn(e){const o=document.querySelector(`.fb-field-card[data-index="${e}"]`)?.querySelector(".fb-field-triggers");if(!o)return;const n=[];return o.querySelectorAll(".fb-trig-card").forEach(l=>{const a=Array.from(l.querySelectorAll(".fb-trig-cond-row")).map(u=>{const b=u.querySelector(".fb-trig-cond-field")?.value,y=u.querySelector(".fb-trig-cond-op")?.value;if(!b||!y)return null;const f=u.querySelector(".fb-trig-cond-val")?.value??"";return{field:b,operator:y,value:f}}).filter(Boolean);if(!a.length)return;const i=u=>Array.from(l.querySelectorAll(`.fb-trig-branch[data-branch="${u}"] .fb-trig-action-row`)).map(hn).filter(Boolean),r=i("then"),c=i("otherwise");if(!r.length&&!c.length)return;const s=l.querySelector(".fb-trig-match")?.value==="any"?"any":"all",d={id:l.dataset.triggerId,enabled:!!l.querySelector(".fb-trig-enabled")?.checked,when:{[s]:a}};r.length&&(d.then=r),c.length&&(d.otherwise=c),n.push(d)}),n.length?n:void 0}function Nt(e,t,o){const n=document.createElement("div");return n.className="fb-field-extras",e==="chooser"?(n.appendChild(vn(t,o)),n.appendChild(Cn(t.options||[],o))):(Fe.has(e)&&n.appendChild(Tn(t.options||[],o)),e==="textarea"&&n.appendChild(_([V("Rows",`fb-rows-${o}`,"number",t.formConfig?.rows||4,"Height of textarea")])),(e==="string"||e==="textarea")&&n.appendChild(_([V("Min Length",`fb-minlength-${o}`,"number",t.minLength||"",""),V("Max Length",`fb-maxlength-${o}`,"number",t.maxLength||"","")])),e==="number"&&n.appendChild(_([V("Min",`fb-min-${o}`,"number",t.min??"",""),V("Max",`fb-max-${o}`,"number",t.max??"","")]))),Lt.includes(e)&&n.appendChild(yn(t,o)),n.children.length?n:null}const Lt=["string","email","tel","number","url","date","time","password","select","textarea"];function gn(e){return e?typeof e=="string"?{icon:"",text:e}:{icon:e.icon||"",text:e.icon?"":e.text??""}:{icon:"",text:""}}function yn(e,t){const o=document.createElement("div");o.className="fb-addons";const n=(a,i)=>{const r=gn(e.formConfig?.[a]),c=document.createElement("div");c.style.flex="1";const s=document.createElement("span");s.className="form-label",s.style.fontSize=".8rem",s.textContent=i;const d=et("Icon, e.g. search",r.icon);d.input.id=`fb-${a}-icon-${t}`,d.input.setAttribute("aria-label",`${i}: icon`);const u=document.createElement("input");return u.type="text",u.className="form-input",u.id=`fb-${a}-text-${t}`,u.value=r.text,u.placeholder="or text, e.g. \xA3 or kg",u.maxLength=24,u.setAttribute("aria-label",`${i}: text`),u.style.marginTop=".35rem",d.input.addEventListener("input",()=>{d.input.value.trim()&&(u.value="")}),u.addEventListener("input",()=>{u.value.trim()&&(d.input.value="")}),c.append(s,d.el,u),c};o.appendChild(_([n("prefix","Before the field"),n("suffix","After the field")]));const l=document.createElement("p");return l.className="form-hint text-muted",l.style.cssText="font-size:.73rem;margin:-.4rem 0 .75rem;",l.textContent="An icon or a short text joined to the start or end of the input, like \xA3 before a price or kg after a weight. Leave both empty for none.",o.appendChild(l),o}function qt(e){const t=document.createElement("div");t.className="fb-chooser-section",t.style.cssText="border:1px solid var(--dm-border); border-radius:6px; margin-top:.5rem; overflow:hidden;";const o=document.createElement("div");o.style.cssText="padding:.4rem .6rem; background:color-mix(in srgb, var(--dm-background) 60%, transparent); font-weight:600; font-size:.82rem; border-bottom:1px solid var(--dm-border);",o.textContent=e,t.appendChild(o);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 Ee(e,t,o,n,l){const a=document.createElement("div");a.style.flex="1";const i=document.createElement("label");i.htmlFor=e,i.className="form-label",i.textContent=t,i.style.fontSize=".8rem";const r=document.createElement("select");if(r.id=e,r.className="form-input",n.forEach(([c,s])=>{const d=document.createElement("option");d.value=c,d.textContent=s,String(c)===String(o)&&(d.selected=!0),r.appendChild(d)}),a.appendChild(i),a.appendChild(r),l){const c=document.createElement("p");c.className="form-hint text-muted",c.textContent=l,c.style.cssText="font-size:.72rem;margin-top:.2rem;",a.appendChild(c)}return a}function $t(e,t,o,n){const l=document.createElement("div");l.style.flex="1";const a=document.createElement("label");a.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=!!o,a.appendChild(i),a.appendChild(document.createTextNode(" "+t)),l.appendChild(a),n){const r=document.createElement("p");r.className="form-hint text-muted",r.textContent=n,r.style.cssText="font-size:.72rem;margin-top:.2rem;",l.appendChild(r)}return l}function Pe(e,t,o,n,l){const a=document.createElement("div");a.style.flex="1";const i=document.createElement("label");i.htmlFor=e,i.className="form-label",i.textContent=t,i.style.fontSize=".8rem",a.appendChild(i);const r=document.createElement("div");r.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=o||"",n&&(c.placeholder=n),c.style.flex="1";const s=document.createElement("input");s.type="color",s.title="Pick a colour",s.style.cssText="width:36px;height:auto;padding:0;border:1px solid var(--dm-border);border-radius:4px;cursor:pointer;";const d=String(c.value).match(/^#[0-9a-fA-F]{3,8}$/);if(s.value=d?c.value:"#000000",s.addEventListener("input",()=>{c.value=s.value,c.dispatchEvent(new Event("input",{bubbles:!0}))}),r.appendChild(c),r.appendChild(s),a.appendChild(r),l){const u=document.createElement("p");u.className="form-hint text-muted",u.textContent=l,u.style.cssText="font-size:.72rem;margin-top:.2rem;",a.appendChild(u)}return a}function vn(e,t){const o=document.createElement("div");o.style.cssText="margin-top:.5rem; display:flex; flex-direction:column; gap:.4rem;";const n=qt("Layout");n.body.appendChild(_([Ee(`fb-chooser-variant-${t}`,"Variant",e.variant||"card",[["card","Card - rich tiles"],["chip","Chip - compact pills"]],"Card supports description and grid columns; chips wrap."),$t(`fb-chooser-multiple-${t}`,"Multi-select",!!e.multiple,"Off = single (radio); on = multi (checkbox).")])),n.body.appendChild(_([Ee(`fb-chooser-density-${t}`,"Density",e.density||"comfortable",[["comfortable","Comfortable"],["compact","Compact"]],"Compact strips description (card variant only)."),V("Columns",`fb-chooser-columns-${t}`,"number",e.columns||3,"Card grid (1-6). Ignored for chips.")])),o.appendChild(n.wrap);const l=qt("Visual");return l.body.appendChild(_([Pe(`fb-chooser-accent-${t}`,"Accent",e.accent||"","primary / success / #ec4899","Selected highlight colour - semantic name or any CSS colour."),Ee(`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.")])),l.body.appendChild(_([$t(`fb-chooser-glow-${t}`,"Glow on selected",!!e.glow,"Soft outer glow."),Pe(`fb-chooser-glow-colour-${t}`,"Glow colour",e.glowColour||"","defaults to accent","Optional; semantic name or CSS colour.")])),l.body.appendChild(_([Ee(`fb-chooser-shadow-${t}`,"Shadow",e.shadow||"none",[["none","None"],["sm","Small"],["md","Medium"],["lg","Large"],["xl","Extra Large"]],"Drop shadow on every option."),Pe(`fb-chooser-shadow-colour-${t}`,"Shadow colour",e.shadowColour||"","rgba(0,0,0,0.1)","Optional shadow tint.")])),o.appendChild(l.wrap),o}function xn(e,t,o,n){const l=document.createElement("div");l.className="fb-chooser-option-row",l.dataset.optIdx=String(o),l.style.cssText="border:1px solid var(--dm-border); border-radius:4px; padding:.5rem; background:var(--dm-background-alt); display:flex; flex-direction:column; gap:.35rem;";const a=document.createElement("div");a.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 r=document.createElement("button");r.type="button",r.className="btn btn-xs btn-ghost",r.title="Move up",A(r,"arrow-up"),r.addEventListener("click",O=>{O.preventDefault(),At(t,o,-1,n)});const c=document.createElement("button");c.type="button",c.className="btn btn-xs btn-ghost",c.title="Move down",A(c,"arrow-down"),c.addEventListener("click",O=>{O.preventDefault(),At(t,o,1,n)}),i.appendChild(r),i.appendChild(c),a.appendChild(i);const s=document.createElement("input");s.type="text",s.className="form-input fb-chooser-opt-value",s.placeholder="value",s.value=e.value||"",s.style.flex="1",a.appendChild(s);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",a.appendChild(d);const u=document.createElement("button");u.type="button",u.className="btn btn-xs btn-ghost",u.style.cssText="line-height:1;opacity:.6;",u.title="Remove option",A(u,"x"),u.addEventListener("click",O=>{O.preventDefault(),kn(t,o,n)}),a.appendChild(u),l.appendChild(a);const b=document.createElement("div");b.style.cssText="display:flex; gap:.4rem;";const y=et("icon name (optional)",e.icon||"");y.input.classList.add("fb-chooser-opt-icon"),y.el.style.flex="1",b.appendChild(y.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",b.appendChild(f),l.appendChild(b);const h=document.createElement("div");h.style.cssText="display:flex; gap:.4rem;";const k=document.createElement("input");k.type="text",k.className="form-input fb-chooser-opt-tooltip",k.placeholder="tooltip (hover hint)",k.value=e.tooltip||"",k.style.flex="2",h.appendChild(k);const m=document.createElement("input");m.type="text",m.className="form-input fb-chooser-opt-badge-text",m.placeholder="badge text",m.value=e.badge?.text||"",m.style.flex="1",h.appendChild(m);const x=document.createElement("select");x.className="form-input fb-chooser-opt-badge-type",x.style.flex="1",[["","no badge"],["primary","primary"],["success","success"],["info","info"],["warning","warning"],["danger","danger"]].forEach(([O,X])=>{const W=document.createElement("option");W.value=O,W.textContent=X,(e.badge?.type||"")===O&&(W.selected=!0),x.appendChild(W)}),h.appendChild(x),l.appendChild(h);const N=document.createElement("div");N.style.cssText="display:flex; gap:1rem; font-size:.8rem;";const T=document.createElement("label");T.style.cssText="display:inline-flex;align-items:center;gap:.3rem;";const I=document.createElement("input");I.type="checkbox",I.className="fb-chooser-opt-recommended",I.checked=!!e.recommended,T.appendChild(I),T.appendChild(document.createTextNode(" Recommended")),N.appendChild(T);const B=document.createElement("label");B.style.cssText="display:inline-flex;align-items:center;gap:.3rem;";const G=document.createElement("input");return G.type="checkbox",G.className="fb-chooser-opt-disabled",G.checked=!!e.disabled,B.appendChild(G),B.appendChild(document.createTextNode(" Disabled")),N.appendChild(B),l.appendChild(N),l}function Cn(e,t){const o=document.createElement("div");o.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 l=document.createElement("p");l.textContent="Options",l.style.cssText="font-size:.85rem;font-weight:600;margin:0;",n.appendChild(l);const a=document.createElement("button");a.type="button",a.className="btn btn-xs btn-ghost",re(a,"plus","Add option"),n.appendChild(a),o.appendChild(n);const i=document.createElement("div");i.className="fb-chooser-options-list",i.id=`fb-chooser-options-${t}`,i.style.cssText="display:flex; flex-direction:column; gap:.4rem;",o.appendChild(i);const r=()=>{i.replaceChildren();const c=En(t);(c.length?c:e||[]).forEach((d,u)=>{i.appendChild(xn(d,t,u,r))})};return a.addEventListener("click",c=>{c.preventDefault(),wn(t,r)}),r(),o}function En(e){const t=w[e];return!t||!Array.isArray(t.options)?[]:t.options}function je(e){return w[e]?(Array.isArray(w[e].options)||(w[e].options=[]),w[e].options):[]}function wn(e,t){we(e),je(e).push({value:"new",label:"New option"}),t()}function kn(e,t,o){we(e),je(e).splice(t,1),o()}function At(e,t,o,n){we(e);const l=je(e),a=t+o;if(a<0||a>=l.length)return;const[i]=l.splice(t,1);l.splice(a,0,i),n()}function we(e){const t=document.getElementById(`fb-chooser-options-${e}`);if(!t)return;const o=t.querySelectorAll(".fb-chooser-option-row"),n=[];o.forEach(l=>{const a={value:l.querySelector(".fb-chooser-opt-value")?.value.trim()||"",label:l.querySelector(".fb-chooser-opt-label")?.value.trim()||""},i=l.querySelector(".fb-chooser-opt-icon")?.value.trim();i&&(a.icon=i);const r=l.querySelector(".fb-chooser-opt-description")?.value.trim();r&&(a.description=r);const c=l.querySelector(".fb-chooser-opt-tooltip")?.value.trim();c&&(a.tooltip=c);const s=l.querySelector(".fb-chooser-opt-badge-text")?.value.trim(),d=l.querySelector(".fb-chooser-opt-badge-type")?.value;(s||d)&&(a.badge={},s&&(a.badge.text=s),d&&(a.badge.type=d)),l.querySelector(".fb-chooser-opt-recommended")?.checked&&(a.recommended=!0),l.querySelector(".fb-chooser-opt-disabled")?.checked&&(a.disabled=!0),n.push(a)}),w[e]&&(w[e].options=n)}function _(e){const t=document.createElement("div");return t.style.cssText="display:flex;gap:.85rem;margin-bottom:.75rem;",e.forEach(o=>{o&&t.appendChild(o)}),t}function V(e,t,o,n,l){const a=document.createElement("div");a.style.flex="1";const i=document.createElement("label");i.htmlFor=t,i.className="form-label",i.textContent=e,i.style.fontSize=".8rem";const r=document.createElement("input");if(r.id=t,r.type=o||"text",r.className="form-input",r.value=n??"",a.appendChild(i),a.appendChild(r),l){const c=document.createElement("p");c.className="form-hint text-muted",c.textContent=l,c.style.cssText="font-size:.73rem;margin-top:.35rem;",a.appendChild(c)}return a}function Sn(e,t,o,n){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("select");return i.id=t,i.className="form-select",o.forEach(r=>{const c=document.createElement("option");c.value=r.value,c.textContent=r.label,r.value===n&&(c.selected=!0),i.appendChild(c)}),l.appendChild(a),l.appendChild(i),l}function Ft(e,t,o){const n=document.createElement("div");n.style.cssText="flex:0;min-width:80px;display:flex;flex-direction:column;justify-content:flex-end;";const l=document.createElement("label");l.style.cssText="display:flex;align-items:center;gap:.4rem;cursor:pointer;font-size:.8rem;white-space:nowrap;";const a=document.createElement("input");return a.id=t,a.type="checkbox",a.checked=o,l.appendChild(a),l.appendChild(document.createTextNode(e)),n.appendChild(l),n}function Tn(e,t){const o=document.createElement("div");o.style.cssText="margin-top:.4rem;";const n=document.createElement("p");n.textContent="Options (one per line: value or value:Label)",n.style.cssText="font-size:.8rem;font-weight:600;margin-bottom:.3rem;";const l=document.createElement("textarea");return l.id=`fb-options-${t}`,l.className="form-input",l.rows=4,l.placeholder=`yes:Yes
1
+ import{apiRequest as ie}from"/admin/js/api.js";import{makeIconInput as $e}from"/admin/js/lib/shortcode-modal.js";import{enhancePickerFields as nt}from"/public/js/forms.js";import{buildWizardSteps as Ht}from"/public/js/form-steps.mjs";import{applySubmitButtons as Ut,applyWizardButtons as Jt,buttonSettingsProblems as Kt,resolveSubmitAlign as at}from"/public/js/form-submit.mjs";import{addBannerAction as qe}from"../lib/plugin-chrome.js";import{helpPopovers as Yt}from"../lib/help-popover.js";import{openMenuAt as lt,sidebarCount as Xt}from"../lib/tool-kit.js";import{draftKey as se,draftOf as Qt,duplicateField as Zt,fieldTitle as Ae,fingerprint as ot,leavingEditor as it,moveField as st,restoreDraft as en,snapshotOf as Be}from"../lib/form-editor-arrange.js";import{fmtDateTime as tn}from"../lib/dates.js";const rt=[{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:"icon",label:"Icon (icon picker)"},{value:"image",label:"Image (media library)"},{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"}],Fe=new Set(["select","radio","checkbox-group","chooser"]);let w=[],fe=[],A=null,he=null,ne=null,be={};function B(e,t,o=14){e.textContent="";const n=document.createElement("span");return n.setAttribute("data-icon",t),n.setAttribute("data-icon-size",String(o)),n.style.cssText="display:inline-flex;align-items:center;vertical-align:middle;",e.appendChild(n),window.I?.scan?.(e),e}function re(e,t,o,n=14){return B(e,t,n),e.appendChild(document.createTextNode(" "+o)),e}function Ie(e){const t=document.createElement("span");return t.setAttribute("data-icon","help-circle"),t.setAttribute("data-icon-size","12"),t.style.cssText="display:inline-flex;align-items:center;vertical-align:middle;margin-left:.3rem;opacity:.55;cursor:help;",t.title=e,window.I?.scan?.(t),requestAnimationFrame(()=>{try{t.parentNode&&typeof E<"u"&&E.tooltip&&(t.removeAttribute("title"),E.tooltip(t,{content:e,position:"top"}))}catch{}}),t}let ge=null,ct=null,Oe=null,ce=null;function ze(){Oe?.(),clearTimeout(ct),ct=setTimeout(()=>{ge&&ge()},350)}function dt(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")}function ut(e){return rt.find(t=>t.value===e)?.label||e}function pt(e){return(e||[]).some(t=>t.logic||Array.isArray(t.triggers)&&t.triggers.length)}function mt(e){return e?!!(e.visibility?.conditions?.length||e.requirement?.conditions?.length||e.validation?.length||e.cascade?.sourceField):!1}function nn(e){const t={...w[e]};if(t.type==="spacer")return t;if(t.type==="page-break"){const m=document.getElementById(`fb-pb-label-${e}`),x=document.getElementById(`fb-pb-desc-${e}`);return m&&(t.label=m.value.trim()||t.label),x&&(t.description=x.value.trim()),t}const o=document.getElementById(`fb-label-${e}`),n=document.getElementById(`fb-name-${e}`),a=document.getElementById(`fb-type-${e}`),l=document.getElementById(`fb-required-${e}`),i=document.getElementById(`fb-placeholder-${e}`),r=document.getElementById(`fb-helper-${e}`),c=document.getElementById(`fb-tooltip-${e}`);if(o&&(t.label=o.value.trim()||t.label),n&&(t.name=n.value.trim()||t.name),a&&(t.type=a.value||t.type),l&&(t.required=l.checked),i&&(t.placeholder=i.value.trim()),r&&(t.helper=r.value.trim()),c&&(t.tooltip=c.value.trim()),t.type==="chooser"){const m=document.getElementById(`fb-chooser-variant-${e}`)?.value;m&&(t.variant=m);const x=document.getElementById(`fb-chooser-multiple-${e}`);x&&(t.multiple=x.checked);const N=document.getElementById(`fb-chooser-density-${e}`)?.value;N&&(t.density=N);const L=document.getElementById(`fb-chooser-columns-${e}`)?.value;L!==""&&L!==void 0&&(t.columns=parseInt(L,10)||3);const I=document.getElementById(`fb-chooser-accent-${e}`)?.value.trim();I?t.accent=I:delete t.accent;const O=document.getElementById(`fb-chooser-accent-style-${e}`)?.value;O?t.accentStyle=O:delete t.accentStyle;const V=document.getElementById(`fb-chooser-glow-${e}`);V&&(t.glow=V.checked);const z=document.getElementById(`fb-chooser-glow-colour-${e}`)?.value.trim();z?t.glowColour=z:delete t.glowColour;const Q=document.getElementById(`fb-chooser-shadow-${e}`)?.value;Q&&Q!=="none"?t.shadow=Q:delete t.shadow;const W=document.getElementById(`fb-chooser-shadow-colour-${e}`)?.value.trim();W?t.shadowColour=W:delete t.shadowColour,we(e),w[e]&&Array.isArray(w[e].options)&&(t.options=w[e].options)}else if(Fe.has(t.type)){["variant","density","columns","accent","accentStyle","glow","glowColour","shadow","shadowColour"].forEach(x=>delete t[x]),t.type!=="checkbox-group"&&t.type!=="multiselect"&&delete t.multiple;const m=document.getElementById(`fb-options-${e}`);m&&(t.options=m.value.split(`
2
+ `).filter(x=>x.trim()).map(x=>{const[N,...L]=x.split(":");return{value:N.trim(),label:L.join(":").trim()||N.trim()}}))}for(const m of["prefix","suffix"]){const x=document.getElementById(`fb-${m}-icon-${e}`),N=document.getElementById(`fb-${m}-text-${e}`),L={...t.formConfig||{}};if(x||N){const I=x?.value.trim()||"",O=N?.value.trim()||"";I&&/^[a-z0-9-]+$/i.test(I)?L[m]={icon:I}:O?L[m]={text:O.slice(0,24)}:delete L[m]}else qt.includes(t.type)||delete L[m];t.formConfig=Object.keys(L).length?L:void 0}{const m={...t.formConfig||{}};for(const x of At){const N=document.getElementById(`fb-extra-${x.key}-${e}`);N&&x.types.includes(t.type)?N.checked?m[x.key]=!0:delete m[x.key]:x.types.includes(t.type)||delete m[x.key]}t.formConfig=Object.keys(m).length?m:void 0}if(t.type==="textarea"){const m=parseInt(document.getElementById(`fb-rows-${e}`)?.value,10);m>0&&(t.formConfig={...t.formConfig||{},rows:m})}const s=document.getElementById(`fb-span-${e}`),d=document.getElementById(`fb-fullwidth-${e}`);if(s||d){const m={...t.formConfig||{}};if(d?.checked)m.span="full";else{const x=parseInt(s?.value,10);x>1?m.span=x:delete m.span}t.formConfig=Object.keys(m).length?m:void 0}const p=document.getElementById(`fb-minlength-${e}`)?.value;p&&(t.minLength=parseInt(p,10));const f=document.getElementById(`fb-maxlength-${e}`)?.value;f&&(t.maxLength=parseInt(f,10));const y=document.getElementById(`fb-min-${e}`)?.value;y!==""&&y!==void 0&&(t.min=parseFloat(y));const h=document.getElementById(`fb-max-${e}`)?.value;h!==""&&h!==void 0&&(t.max=parseFloat(h));const b=an(e);b?t.logic=b:delete t.logic;const k=wn(e);return k?t.triggers=k:delete t.triggers,t}function an(e){const t=document.querySelector(`.fb-field-card[data-index="${e}"]`);if(!t)return;const o=t.querySelector(".fb-field-logic");if(!o)return;const n={};let a=!1;const l=o.querySelector('[data-logic-section="visibility"]');if(l){const s=l.querySelector(".fb-logic-vis-default"),d=l.querySelector(".fb-logic-vis-transition"),p=Array.from(l.querySelectorAll(".fb-logic-cond-row")).map(b=>{const k=b.querySelector(".fb-logic-cond-field"),m=b.querySelector(".fb-logic-cond-op"),x=b.querySelector(".fb-logic-cond-val"),N=b.querySelector(".fb-logic-vis-then");return k?.value?{when:{all:[{field:k.value,operator:m.value,value:x.value}]},then:N.value}:null}).filter(Boolean),f=s?.value||"visible",y=d?.value||"none",h=parseInt(l.querySelector(".fb-logic-vis-duration")?.value||"",10);(f!=="visible"||p.length>0||y!=="none")&&(n.visibility={default:f,conditions:p},y!=="none"&&(n.visibility.transition=y),y!=="none"&&Number.isFinite(h)&&(n.visibility.duration=h),a=!0)}const i=o.querySelector('[data-logic-section="requirement"]');if(i){const s=i.querySelector(".fb-logic-req-default"),d=Array.from(i.querySelectorAll(".fb-logic-cond-row")).map(p=>{const f=p.querySelector(".fb-logic-cond-field"),y=p.querySelector(".fb-logic-cond-op"),h=p.querySelector(".fb-logic-cond-val"),b=p.querySelector(".fb-logic-req-then");return f?.value?{when:{all:[{field:f.value,operator:y.value,value:h.value}]},then:b.value==="true"}:null}).filter(Boolean);d.length>0&&(n.requirement={default:s?.checked===!0,conditions:d},a=!0)}const r=o.querySelector('[data-logic-section="validation"]');if(r){const s=Array.from(r.querySelectorAll(".fb-logic-val-rule")).map(d=>{const p=d.querySelector(".fb-logic-val-type"),f=d.querySelector(".fb-logic-val-pattern"),y=d.querySelector(".fb-logic-val-flags"),h=d.querySelector(".fb-logic-val-message");if(!f?.value.trim())return null;const b=p?.value||"regex",k={type:b,message:h?.value.trim()||"Invalid value."};return b==="regex"?(k.pattern=f.value.trim(),y?.value.trim()&&(k.flags=y.value.trim())):k.field=f.value.trim(),k}).filter(Boolean);s.length>0&&(n.validation=s,a=!0)}const c=o.querySelector('[data-logic-section="cascade"]');if(c){const s=c.querySelector(".fb-logic-cascade-source"),d=c.querySelector(".fb-logic-cascade-mapping"),p=c.querySelector(".fb-logic-cascade-defaults"),f=s?.value?.trim();if(f){let y={};try{y=JSON.parse(d?.value||"{}")}catch{}const h=(p?.value||"").split(`
3
+ `).filter(b=>b.trim()).map(b=>{const[k,...m]=b.split(":");return{value:k.trim(),label:m.join(":").trim()||k.trim()}});n.cascade={sourceField:f,mapping:y,defaultOptions:h},a=!0}}return a?n:void 0}function _(){w=w.map((e,t)=>nn(t))}function ln(e){const t=e.firstElementChild;if(!t||t.querySelector(".fb-drag-grip"))return;const o=document.createElement("span");o.className="fb-drag-grip",o.setAttribute("data-icon","grip-vertical"),o.setAttribute("data-icon-size","16"),o.title="Drag to reorder",t.insertBefore(o,t.firstChild),window.I?.scan?.(t)}function X(e){const t=e.find("#fields-list").get(0),o=e.find("#fields-empty-msg").get(0);if(t){if(Array.from(t.querySelectorAll(".fb-field-card")).forEach(n=>n.remove()),w.length===0){o&&(o.style.display=""),ce?.(t),ze();return}o&&(o.style.display="none"),w.forEach((n,a)=>{const l=n.type==="page-break"?on(n,a,e):n.type==="spacer"?sn(n,a,e):rn(n,a,e);ln(l),t.appendChild(l)}),ce?.(t),ze()}}function on(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:2px dashed var(--dm-border);border-radius:8px;overflow:hidden;margin-bottom:.75rem;background:var(--dm-card-bg);";const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.6rem .8rem;cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent="- Page Break -",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);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);";const r=document.createElement("div");r.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;";const c=document.createElement("button");c.className="btn btn-xs btn-ghost",c.title="Edit step",B(c,"more-horizontal"),c.addEventListener("click",y=>{y.stopPropagation(),d.style.display=d.style.display==="none"?"":"none"}),r.appendChild(c);const s=document.createElement("button");s.className="btn btn-xs btn-ghost",s.style.cssText="line-height:1;opacity:.6;",s.title="Remove page break",B(s,"x"),s.addEventListener("click",async y=>{y.stopPropagation(),await E.confirm("Remove this page break?")&&(_(),w.splice(t,1),X(o))}),r.appendChild(s),a.appendChild(l),a.appendChild(i),a.appendChild(r),a.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);display:none;";const p=D([j("Step Title",`fb-pb-label-${t}`,"text",e.label||"","Shown as the wizard step heading"),j("Step Description",`fb-pb-desc-${t}`,"text",e.description||"","Optional sub-heading")]),f=p.querySelector(`#fb-pb-label-${t}`);return f&&f.addEventListener("input",()=>{i.textContent=f.value||"Untitled Step"}),d.appendChild(p),n.appendChild(a),n.appendChild(d),n}function sn(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px dashed var(--dm-border);border-radius:6px;margin-bottom:.5rem;background:transparent;";const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.4rem .8rem;";const l=document.createElement("div");l.style.cssText="flex:1;height:1px;background:var(--dm-border);";const i=document.createElement("span");i.textContent="Spacer",i.style.cssText="font-size:.7rem;color:var(--dm-text-muted);white-space:nowrap;padding:0 .4rem;font-style:italic;";const r=document.createElement("div");r.style.cssText="flex:1;height:1px;background:var(--dm-border);";const c=document.createElement("div");c.style.cssText="display:flex;gap:.25rem;flex-shrink:0;";const s=document.createElement("button");return s.className="btn btn-xs btn-ghost",s.style.cssText="line-height:1;opacity:.6;",s.title="Remove spacer",B(s,"x"),s.addEventListener("click",async d=>{d.stopPropagation(),_(),w.splice(t,1),X(o)}),c.appendChild(s),a.appendChild(l),a.appendChild(i),a.appendChild(r),a.appendChild(c),n.appendChild(a),n}function rn(e,t,o){const n=document.createElement("div");n.className="fb-field-card",n.dataset.index=t,n.style.cssText="border:1px solid var(--dm-border);border-radius:8px;overflow:hidden;margin-bottom:.75rem;background:var(--dm-card-bg);box-shadow:var(--dm-shadow-sm);";const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.65rem .85rem;background:var(--dm-card-header-bg);cursor:pointer;user-select:none;";const l=document.createElement("span");l.textContent=ut(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);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 r=document.createElement("div");r.style.cssText="display:flex;gap:.25rem;flex-shrink:0;margin-left:.5rem;";const c=document.createElement("button");c.className="btn btn-xs btn-ghost",c.title="Edit field",B(c,"more-horizontal"),c.addEventListener("click",p=>{p.stopPropagation(),d.style.display=d.style.display==="none"?"":"none"}),r.appendChild(c);const s=document.createElement("button");if(s.className="btn btn-xs btn-ghost",s.style.cssText="line-height:1;opacity:.6;",s.title="Remove field",B(s,"x"),s.addEventListener("click",async p=>{p.stopPropagation(),await E.confirm("Remove this field?")&&(_(),w.splice(t,1),X(o))}),r.appendChild(s),a.appendChild(l),a.appendChild(i),e.required){const p=document.createElement("span");p.textContent="required",p.style.cssText="font-size:.7rem;color:var(--dm-danger);flex-shrink:0;",a.appendChild(p)}if(mt(e.logic)){const p=document.createElement("span");B(p,"zap"),p.title="Has conditional logic",p.style.cssText="font-size:.75rem;color:var(--dm-primary);flex-shrink:0;",a.appendChild(p)}a.appendChild(r),a.addEventListener("click",()=>{d.style.display=d.style.display==="none"?"":"none"});const d=cn(e,t,i);return d.style.display="none",n.appendChild(a),n.appendChild(d),n}function cn(e,t,o){const n=document.createElement("div");n.className="fb-field-body",n.style.cssText="padding:1rem .9rem;border-top:1px solid var(--dm-border);";const a=D([j("Label",`fb-label-${t}`,"text",e.label||"","Shown above the field"),j("Field Name",`fb-name-${t}`,"text",e.name||"","Used as data key")]),l=D([Bn("Type",`fb-type-${t}`,rt,e.type||"string"),Ge("Required",`fb-required-${t}`,e.required||!1)]),i=D([j("Placeholder",`fb-placeholder-${t}`,"text",e.placeholder||"","Hint text inside the field")]),r=D([j("Helper Text",`fb-helper-${t}`,"text",e.helper||"","Shown below the field"),j("Tooltip",`fb-tooltip-${t}`,"text",e.tooltip||"","Shown on hover via a help icon next to the label")]),c=e.formConfig?.span,s=D([j("Column Span",`fb-span-${t}`,"number",c&&c!=="full"?String(c):"1","Columns to span (grid only)"),Ge("Full Width",`fb-fullwidth-${t}`,c==="full")]);s.classList.add("fb-grid-row"),s.style.display=document.getElementById("setting-layout")?.value==="grid"?"flex":"none",n.appendChild(a),n.appendChild(l),n.appendChild(i),n.appendChild(r),n.appendChild(s);const d=n.querySelector(`#fb-label-${t}`),p=n.querySelector(`#fb-name-${t}`);d&&d.addEventListener("input",()=>{o&&(o.textContent=d.value||"(unlabelled)"),p&&!p.dataset.manuallyEdited&&(p.value=dt(d.value))}),p&&p.addEventListener("input",()=>{p.dataset.manuallyEdited="1"});const f=n.querySelector(`#fb-type-${t}`);f&&f.addEventListener("change",()=>{const h=n.closest(".fb-field-card");if(h){const m=h.querySelector("span");m&&(m.textContent=ut(f.value))}const b=n.querySelector(".fb-field-extras");b&&b.remove();const k=$t(f.value,e,t);k&&n.appendChild(k)});const y=$t(e.type,e,t);return y&&n.appendChild(y),n.appendChild(fn(e,t)),n.appendChild(Cn(e,t)),n}const ye=[{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"}],Re=new Set(["is_empty","is_not_empty"]),ft={equals:"includes",not_equals:"does not include",contains:"any value contains",not_contains:"no value contains",starts_with:"any value starts with",ends_with:"any value ends with",greater_than:"any value is greater than",less_than:"any value is less than",is_empty:"nothing selected",is_not_empty:"something selected",in:"includes one of (comma sep)",not_in:"includes none of (comma sep)",matches_regex:"any value matches regex"};function Me(e){return!!e&&(e.type==="checkbox-group"||!!e.multiple)}function ve(e){const t=document.createElement("p");return t.textContent=e,t.style.cssText="font-size:.75rem;font-weight:700;color:var(--dm-text-muted);margin:0 0 .7rem;text-transform:uppercase;letter-spacing:.06em;",t}function xe(e,t,o,n,a){const l=document.createElement("div");l.className="fb-logic-cond-row",l.style.cssText="display:flex;gap:.55rem;align-items:center;margin-bottom:.6rem;flex-wrap:wrap;";const i=document.createElement("span");i.textContent="When",i.style.cssText="font-size:.73rem;color:var(--dm-text-muted);flex-shrink:0;";const r=document.createElement("select");r.className="form-select fb-logic-cond-field",r.style.cssText="flex:1 1 140px;min-width:140px;",t.forEach(h=>{const b=document.createElement("option");b.value=h.value,b.textContent=h.label,e&&h.value===e.field&&(b.selected=!0),r.appendChild(b)});const c=document.createElement("select");c.className="form-select fb-logic-cond-op",c.style.cssText="flex:1 1 160px;min-width:140px;",ye.forEach(h=>{const b=document.createElement("option");b.value=h.value,b.textContent=h.label,e&&h.value===e.operator&&(b.selected=!0),c.appendChild(b)});const s=()=>{const h=t.find(b=>b.value===r.value);Array.from(c.options).forEach(b=>{const k=ye.find(m=>m.value===b.value);b.textContent=h?.multi&&ft[b.value]||k?.label||b.value})};s(),r.addEventListener("change",s);const d=document.createElement("input");d.type="text",d.className="form-input fb-logic-cond-val",d.placeholder="value",d.style.cssText="flex:1 1 120px;min-width:100px;",d.value=e?.value||"",e&&Re.has(e.operator)&&(d.style.display="none"),c.addEventListener("change",()=>{d.style.display=Re.has(c.value)?"none":""});const p=document.createElement("span");B(p,"arrow-right"),p.style.cssText="font-size:.73rem;color:var(--dm-text-muted);flex-shrink:0;";const f=document.createElement("select");f.className=`form-select ${n}`,f.style.cssText="flex:1 1 140px;min-width:120px;",o.forEach(h=>{const b=document.createElement("option");b.value=h.value,b.textContent=h.label,h.value===a&&(b.selected=!0),f.appendChild(b)});const y=document.createElement("button");return y.type="button",y.className="btn btn-xs btn-ghost",y.style.cssText="line-height:1;opacity:.6;",B(y,"x"),y.style.flexShrink="0",y.addEventListener("click",()=>l.remove()),l.appendChild(i),l.appendChild(r),l.appendChild(c),l.appendChild(d),l.appendChild(p),l.appendChild(f),l.appendChild(y),l}function dn(e,t,o){const n=document.createElement("div");n.dataset.logicSection="visibility",n.appendChild(ve("Visibility"));const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.6rem;margin-bottom:.65rem;flex-wrap:wrap;";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 x=document.createElement("option");x.value=m.value,x.textContent=m.label,m.value===(e.default||"visible")&&(x.selected=!0),i.appendChild(x)}),a.appendChild(l),a.appendChild(i),n.appendChild(a);const r=document.createElement("div");r.style.cssText="display:flex;align-items:center;gap:.6rem;margin-bottom:.65rem;flex-wrap:wrap;";const c=document.createElement("span");c.textContent="Transition:",c.style.cssText="font-size:.8rem;flex-shrink:0;";const s=document.createElement("select");s.className="form-select fb-logic-vis-transition",s.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 x=document.createElement("option");x.value=m.value,x.textContent=m.label,m.value===(e.transition||"none")&&(x.selected=!0),s.appendChild(x)}),r.appendChild(c),r.appendChild(s),n.appendChild(r);const d=document.createElement("div");d.style.cssText="display:flex;align-items:center;gap:.6rem;margin-bottom:.65rem;flex-wrap:wrap;";const p=document.createElement("span");p.textContent="Speed:",p.style.cssText="font-size:.8rem;flex-shrink:0;";const f=document.createElement("select");f.className="form-select fb-logic-vis-duration",f.style.cssText="max-width:240px;",[{value:"",label:"Default"},{value:"120",label:"Very fast (120ms)"},{value:"200",label:"Fast (200ms)"},{value:"350",label:"Medium (350ms)"},{value:"600",label:"Slow (600ms)"},{value:"1000",label:"Very slow (1s)"}].forEach(m=>{const x=document.createElement("option");x.value=m.value,x.textContent=m.label,m.value===String(e.duration??"")&&(x.selected=!0),f.appendChild(x)}),d.appendChild(p),d.appendChild(f),n.appendChild(d);const y=()=>{d.style.display=s.value==="none"?"none":""};y(),s.addEventListener("change",y);const h=document.createElement("div");h.className="fb-logic-vis-rules";const b=o.map(m=>({value:m.name,label:m.label||m.name,multi:Me(m)})),k=[{value:"visible",label:"Show"},{value:"hidden",label:"Hide"}];if((e.conditions||[]).forEach(m=>{const x=(m.when?.all||m.when?.any||[])[0],N=m.then==="hidden"?"hidden":"visible";b.length>0&&h.appendChild(xe(x,b,k,"fb-logic-vis-then",N))}),n.appendChild(h),b.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:.35rem;",re(m,"plus","Add visibility rule"),m.addEventListener("click",()=>h.appendChild(xe(null,b,k,"fb-logic-vis-then","visible"))),n.appendChild(m)}return n}function un(e,t,o){const n=document.createElement("div");n.dataset.logicSection="requirement",n.appendChild(ve("Conditional Requirement"));const a=document.createElement("label");a.style.cssText="display:flex;align-items:center;gap:.5rem;font-size:.8rem;cursor:pointer;margin-bottom:.65rem;";const l=document.createElement("input");l.type="checkbox",l.className="fb-logic-req-default",l.checked=e.default===!0,a.appendChild(l),a.appendChild(document.createTextNode("Required by default")),n.appendChild(a);const i=document.createElement("div");i.className="fb-logic-req-rules";const r=o.map(s=>({value:s.name,label:s.label||s.name,multi:Me(s)})),c=[{value:"true",label:"Make required"},{value:"false",label:"Make optional"}];if((e.conditions||[]).forEach(s=>{const d=(s.when?.all||s.when?.any||[])[0],p=s.then===!0?"true":"false";r.length>0&&i.appendChild(xe(d,r,c,"fb-logic-req-then",p))}),n.appendChild(i),r.length>0){const s=document.createElement("button");s.type="button",s.className="btn btn-xs btn-ghost",s.style.cssText="font-size:.73rem;margin-top:.35rem;",re(s,"plus","Add requirement rule"),s.addEventListener("click",()=>i.appendChild(xe(null,r,c,"fb-logic-req-then","true"))),n.appendChild(s)}return n}function ht(e){const t=document.createElement("div");t.className="fb-logic-val-rule",t.style.cssText="display:flex;gap:.55rem;align-items:center;margin-bottom:.6rem;flex-wrap:wrap;";const o=document.createElement("select");o.className="form-select fb-logic-val-type",o.style.cssText="flex:0 0 140px;",[{value:"regex",label:"Regex"},{value:"match",label:"Match field"}].forEach(r=>{const c=document.createElement("option");c.value=r.value,c.textContent=r.label,r.value===(e?.type||"regex")&&(c.selected=!0),o.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 a=document.createElement("input");a.type="text",a.className="form-input fb-logic-val-flags",a.placeholder="flags",a.value=e?.flags||"",a.style.cssText="flex:0 0 55px;",e?.type==="match"&&(a.style.display="none"),o.addEventListener("change",()=>{a.style.display=o.value==="match"?"none":"",n.placeholder=o.value==="match"?"field name":"pattern"});const l=document.createElement("input");l.type="text",l.className="form-input fb-logic-val-message",l.placeholder="Error message",l.value=e?.message||"",l.style.cssText="flex:4;";const i=document.createElement("button");return i.type="button",i.className="btn btn-xs btn-ghost",i.style.cssText="line-height:1;opacity:.6;",B(i,"x"),i.style.flexShrink="0",i.addEventListener("click",()=>t.remove()),t.appendChild(o),t.appendChild(n),t.appendChild(a),t.appendChild(l),t.appendChild(i),t}function pn(e,t,o){const n=document.createElement("div");n.dataset.logicSection="validation",n.appendChild(ve("Custom Validation"));const a=document.createElement("div");a.className="fb-logic-val-rules",(e||[]).forEach(i=>a.appendChild(ht(i))),n.appendChild(a);const l=document.createElement("button");return l.type="button",l.className="btn btn-xs btn-ghost",l.style.cssText="font-size:.73rem;margin-top:.35rem;",re(l,"plus","Add validation rule"),l.addEventListener("click",()=>a.appendChild(ht(null))),n.appendChild(l),n}function mn(e,t,o){const n=document.createElement("div");n.dataset.logicSection="cascade",n.appendChild(ve("Cascade Options")),n.lastChild.appendChild(Ie("Make this field's options depend on another field. When the source field changes, the options here are replaced by the mapping entry for its value; if nothing matches, the default options below are shown."));const a=document.createElement("div");a.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.5rem;";const l=document.createElement("span");l.textContent="Source field:",l.style.cssText="font-size:.8rem;flex-shrink:0;";const i=document.createElement("select");i.className="form-select fb-logic-cascade-source",i.style.cssText="flex:1;";const r=document.createElement("option");r.value="",r.textContent="- none -",i.appendChild(r),o.forEach(f=>{const y=document.createElement("option");y.value=f.name,y.textContent=f.label||f.name,f.name===e.sourceField&&(y.selected=!0),i.appendChild(y)}),a.appendChild(l),a.appendChild(i),n.appendChild(a);const c=document.createElement("p");c.textContent='Mapping JSON - {"value":[{"value":"...","label":"..."}]}',c.appendChild(Ie(`Each key is a value of the source field; its list becomes this field's options when that value is picked. Example: {"uk":[{"value":"london","label":"London"}]} shows London when the source is "uk".`)),c.style.cssText="font-size:.73rem;color:var(--dm-text-muted);margin:.3rem 0 .2rem;";const s=document.createElement("textarea");s.className="form-input fb-logic-cascade-mapping",s.rows=4,s.style.cssText="font-family:monospace;",s.placeholder='{"uk": [{"value": "london", "label": "London"}]}',s.value=e.mapping?JSON.stringify(e.mapping,null,2):"",n.appendChild(c),n.appendChild(s);const d=document.createElement("p");d.textContent="Default options (one per line: value:Label)",d.appendChild(Ie("Shown before the source field has a value, or when its value has no mapping entry.")),d.style.cssText="font-size:.73rem;color:var(--dm-text-muted);margin:.3rem 0 .2rem;";const p=document.createElement("textarea");return p.className="form-input fb-logic-cascade-defaults",p.rows=3,p.style.cssText="font-family:monospace;",p.placeholder=`option1:Option 1
4
+ option2:Option 2`,p.value=(e.defaultOptions||[]).map(f=>{const y=typeof f=="string"?f:f.value??"",h=typeof f=="string"?f:f.label??y;return y===h?y:`${y}:${h}`}).join(`
5
+ `),n.appendChild(d),n.appendChild(p),n}function fn(e,t){const o=e.logic||{},n=w.filter((p,f)=>f!==t&&p.type!=="page-break"&&p.type!=="spacer"),a=document.createElement("div");a.className="fb-field-logic",a.style.cssText="margin-top:.75rem;border-top:1px solid var(--dm-border);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);",i.textContent="\u26A1 Conditional Logic";const r=mt(o),c=document.createElement("button");c.type="button",c.className="btn btn-xs btn-ghost",B(c,r?"chevron-down":"chevron-right",12);const s=document.createElement("div");s.className="fb-logic-body",s.style.cssText="padding:.25rem 0 .25rem;"+(r?"":"display:none;"),l.addEventListener("click",()=>{const p=s.style.display==="none";s.style.display=p?"":"none",B(c,p?"chevron-down":"chevron-right",12)}),l.appendChild(i),l.appendChild(c),a.appendChild(l),s.appendChild(dn(o.visibility||{},t,n)),s.appendChild(un(o.requirement||{},t,n)),s.appendChild(pn(o.validation||[],t,n));const d=document.getElementById(`fb-type-${t}`)?.value||e.type;return Fe.has(d)&&s.appendChild(mn(o.cascade||{},t,n)),a.appendChild(s),a}const de=[{value:"banner",label:"Show a banner",kind:"state",params:["message","level","position","dismissible"],placeholder:"e.g. You must be 18 or over to continue."},{value:"toast",label:"Show a toast",kind:"event",params:["message","level"],placeholder:"e.g. Thanks - carry on."},{value:"hide-fields",label:"Hide fields",kind:"state",params:["target"]},{value:"disable-fields",label:"Disable fields",kind:"state",params:["target"]},{value:"require-fields",label:"Make fields required",kind:"state",params:["target"]},{value:"block-submit",label:"Block submission",kind:"state",params:["message"],messageLabel:"Reason, shown under the button",placeholder:'Blank: "This form cannot be submitted yet."'},{value:"end-form",label:"End the form here",kind:"state",params:["message","finish","finishLabel","doneMessage","record"],messageLabel:"Message shown in place of the rest",placeholder:"e.g. Sorry - you must be 18 or over to apply."},{value:"goto-step",label:"Jump to a wizard step",kind:"event",params:["step"]},{value:"redirect",label:"Redirect after submit",kind:"event",params:["url"]},{value:"celebrate",label:"Celebrate",kind:"event",params:["theme","intensity"]},{value:"run-action",label:"Run a CMS action",kind:"event",params:["slug"]},{value:"notify",label:"Notify the admins",kind:"event",params:["message","level"],messageLabel:"Notification title",placeholder:"Blank: titled after the form",noOnce:!0,kindText:"when the form is submitted"}],Ce=[{value:"info",label:"Info"},{value:"success",label:"Success"},{value:"warning",label:"Warning"},{value:"error",label:"Error"}],bt=[{value:"field-below",label:"Below this field"},{value:"field-above",label:"Above this field"},{value:"form-top",label:"Top of the form"}],gt=[{value:"rest",label:"The rest of the form"},{value:"all",label:"Every other field"},{value:"listed",label:"Chosen fields"}],yt=[{value:"auto",label:"Whatever is in season"},{value:"christmas",label:"Christmas"},{value:"halloween",label:"Halloween"},{value:"valentines",label:"Valentine's Day"},{value:"guy-fawkes",label:"Guy Fawkes Night"},{value:"st-patricks",label:"St Patrick's Day"},{value:"st-andrews",label:"St Andrew's Day"},{value:"st-davids",label:"St David's Day"},{value:"st-georges",label:"St George's Day"}];function vt(e,t=!1){const o=(i,r)=>({value:i.name,label:`${i.label||i.name}${r?" (this field)":""}`,multi:Me(i)}),n=i=>i&&i.type!=="page-break"&&i.type!=="spacer"&&i.name,a=w.filter((i,r)=>r!==e&&n(i)).map(i=>o(i,!1)),l=w[e];return t&&n(l)?[o(l,!0),...a]:a}function J(e,t,o){const n=document.createElement("select");return n.className=`form-select ${e}`,t.forEach(a=>{const l=document.createElement("option");l.value=a.value,l.textContent=a.label,a.value===o&&(l.selected=!0),n.appendChild(l)}),n}function ae(e,t,o){const n=document.createElement("input");return n.type="text",n.className=`form-input ${e}`,n.value=t==null?"":String(t),o&&(n.placeholder=o),n}function De(e,t){const o=document.createElement("button");return o.type="button",o.className="btn btn-xs btn-ghost fb-trig-remove",t&&(o.title=t,o.setAttribute("aria-label",t)),B(o,"x"),o.addEventListener("click",n=>{n.stopPropagation(),e()}),o}function P(e,t,{full:o=!1,hint:n=""}={}){const a=document.createElement("label");a.className=`fb-trig-f${o?" fb-trig-f--full":""}`;const l=document.createElement("span");if(l.className="fb-trig-f-label",l.textContent=e,a.appendChild(l),a.appendChild(t),n){const i=document.createElement("span");i.className="fb-trig-f-hint",i.textContent=n,a.appendChild(i)}return a}function ue(e,t,o,n){const a=document.createElement("label");a.className="fb-trig-check",n&&(a.title=n);const l=document.createElement("input");return l.type="checkbox",l.className=`form-check ${e}`,l.checked=!!t,a.appendChild(l),a.appendChild(document.createTextNode(o)),a}function xt(e,t){const o=document.createElement("div");o.className="fb-trig-cond-row";const n=J("fb-trig-cond-field",t,e?.field),a=J("fb-trig-cond-op",ye,e?.operator),l=ae("fb-trig-cond-val",e?.value,"value"),i=()=>{const c=t.find(s=>s.value===n.value);Array.from(a.options).forEach(s=>{const d=ye.find(p=>p.value===s.value);s.textContent=c?.multi&&ft[s.value]||d?.label||s.value})},r=()=>{l.hidden=Re.has(a.value)};return i(),r(),n.addEventListener("change",i),a.addEventListener("change",r),o.appendChild(n),o.appendChild(a),o.appendChild(l),o.appendChild(De(()=>o.remove(),"Remove condition")),o}const Ct=["banner","toast","block-submit","end-form"],Et=["password","file","image","signature"],hn="Put an answer in with {{field_name}} - e.g. Hello {{name}}. Pick one from Insert field.";function bn(){try{_()}catch{}return w.filter(e=>e&&e.name&&e.type!=="page-break"&&e.type!=="spacer"&&!Et.includes(e.type))}function wt(e,t,o){const n=ae(e,t,o),a=document.createElement("span");a.className="fb-token-row";const l=document.createElement("select");l.className="form-input fb-token-pick",l.title="Insert an answer into the message",l.setAttribute("aria-label","Insert a field's answer into the message");const i=()=>{l.replaceChildren(new Option("Insert field",""));for(const r of bn())l.appendChild(new Option(`${r.label||r.name} ({{${r.name}}})`,r.name))};return i(),l.addEventListener("focus",i),l.addEventListener("mousedown",i),l.addEventListener("change",()=>{const r=l.value;if(l.value="",!r)return;const c=`{{${r}}}`,s=n.selectionStart??n.value.length,d=n.selectionEnd??s;n.value=n.value.slice(0,s)+c+n.value.slice(d),n.focus(),n.setSelectionRange(s+c.length,s+c.length),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0}))}),a.append(n,l),a}function gn(e){const t=window.FormLogicEngine;if(!t?.triggerTokens)return[];const o=new Map((e||[]).filter(a=>a&&a.name).map(a=>[a.name,a])),n=new Set;for(const a of e||[])for(const l of a?.triggers||[])for(const i of[...l.then||[],...l.otherwise||[]])if(Ct.includes(i?.type))for(const r of[...t.triggerTokens(i.message),...t.triggerTokens(i.doneMessage)]){const c=o.get(r);(!c||Et.includes(c.type))&&n.add(r)}return[...n]}function kt(e,t){const o=document.createElement("div");o.className="fb-trig-params";const n=de.find(c=>c.value===(e.type||"banner"));if(!n)return o;const a=document.createElement("div");a.className="fb-trig-grid";const l=document.createElement("div");l.className="fb-trig-opts";const i=[];for(const c of n.params)switch(c){case"message":a.appendChild(Ct.includes(n.value)?P(n.messageLabel||"Message",wt("fb-trig-p-message",e.message,n.placeholder||""),{full:!0,hint:hn}):P(n.messageLabel||"Message",ae("fb-trig-p-message",e.message,n.placeholder||""),{full:!0}));break;case"finish":l.appendChild(ue("fb-trig-p-finish-on",e.finish!==!1,"Let the visitor finish (send the answers given so far)",'Untick to stop the form dead: the submit button is disabled and nothing is sent, so nothing is saved and "Notify the admins" cannot fire.'));break;case"finishLabel":{const s=P("Button text",ae("fb-trig-p-finish",e.finishLabel,"Finish"));i.push(s),a.appendChild(s);break}case"doneMessage":{const s=P("Closing message",wt("fb-trig-p-done",e.doneMessage,"Blank: the form's own success message"));i.push(s),a.appendChild(s);break}case"record":{const s=ue("fb-trig-p-record",e.record!==!1,"Save the answers given so far",`Untick to keep nothing: no submission is stored and the form's email, webhook and actions do not run. A "Notify the admins" action still fires.`);i.push(s),l.appendChild(s);break}case"level":a.appendChild(P(n.value==="notify"?"Severity":"Level",J("fb-trig-p-level",Ce,e.level||"info")));break;case"position":a.appendChild(P("Where",J("fb-trig-p-position",bt,e.position||"field-below")));break;case"dismissible":l.appendChild(ue("fb-trig-p-dismissible",e.dismissible!==!1,"The visitor can dismiss it"));break;case"target":{const s=J("fb-trig-p-target",gt,e.target||(e.fields?.length?"listed":"rest")),d=document.createElement("select");d.className="form-select fb-trig-p-fields",d.multiple=!0,d.size=4;const p=new Set(e.fields||[]);vt(t).forEach(h=>{const b=document.createElement("option");b.value=h.value,b.textContent=h.label,p.has(h.value)&&(b.selected=!0),d.appendChild(b)});const f=P("Fields",d,{hint:"Ctrl/Cmd-click to pick several"}),y=()=>{f.hidden=s.value!=="listed"};y(),s.addEventListener("change",y),a.appendChild(P("Which fields",s)),a.appendChild(f);break}case"step":{const s=ae("fb-trig-p-step",e.step,"0");s.type="number",s.min="0",a.appendChild(P("Step",s,{hint:"Counting from 0"}));break}case"url":a.appendChild(P("Send them to",ae("fb-trig-p-url",e.url,"/thank-you"),{full:!0}));break;case"theme":a.appendChild(P("Theme",J("fb-trig-p-theme",yt,e.theme||"auto")));break;case"intensity":a.appendChild(P("Intensity",J("fb-trig-p-intensity",[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}],e.intensity||"medium")));break;case"slug":{const s=[{value:"",label:fe.length?"Choose an action":"No actions available"}].concat(fe.map(d=>({value:d.slug,label:d.title||d.slug})));a.appendChild(P("Action",J("fb-trig-p-slug",s,e.slug||""),{full:!0}));break}default:break}n.kind==="event"&&!n.noOnce&&l.appendChild(ue("fb-trig-p-once",!!e.once,"Only once","Fire the first time only, rather than every time the answer swings back."));const r=l.querySelector(".fb-trig-p-finish-on");if(r){const c=()=>i.forEach(s=>{s.hidden=!r.checked});c(),r.addEventListener("change",c)}return a.children.length&&o.appendChild(a),l.children.length&&o.appendChild(l),o}function yn(e){return e?.kindText?e.kindText:e?.kind==="event"?"once, when it becomes true":"while it is true"}const vn=(e,t=48)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e,le=(e,t)=>e.find(o=>o.value===t)?.label||t;function xn(e){if(!e)return"";const t=[],o=a=>a?`"${vn(a)}"`:"",n=()=>e.target==="listed"?e.fields?.length?e.fields.join(", "):"no fields chosen":le(gt,e.target||"rest").toLowerCase();switch(e.type){case"banner":t.push(o(e.message)||"No message yet",le(Ce,e.level||"info"),le(bt,e.position||"field-below").toLowerCase());break;case"toast":t.push(o(e.message)||"No message yet",le(Ce,e.level||"info"));break;case"hide-fields":case"disable-fields":case"require-fields":t.push(n());break;case"block-submit":t.push(o(e.message)||"the standard reason");break;case"end-form":t.push(o(e.message)||"no message"),e.finish===!1?t.push("submit disabled"):t.push(`button "${e.finishLabel||"Finish"}"`,e.record===!1?"saves nothing":"saves the answers");break;case"goto-step":t.push(Number.isFinite(e.step)?`step ${e.step}`:"no step yet");break;case"redirect":t.push(e.url||"no address yet");break;case"celebrate":t.push(le(yt,e.theme||"auto"),`${e.intensity||"medium"} intensity`);break;case"run-action":t.push(e.slug?fe.find(a=>a.slug===e.slug)?.title||e.slug:"no action chosen");break;case"notify":t.push(o(e.message)||"titled after the form",le(Ce,e.level||"info"));break;default:break}return e.once&&t.push("only once"),t.filter(Boolean).join(" \xB7 ")}function _e(e,t,{open:o=!1}={}){const n=document.createElement("div");n.className="fb-trig-action-row";const a=document.createElement("div");a.className="fb-trig-action-head",a.tabIndex=0,a.setAttribute("role","button");const l=document.createElement("span");l.className="fb-trig-chevron";const i=document.createElement("span");i.className="fb-trig-action-main";const r=document.createElement("strong"),c=document.createElement("small");c.className="fb-trig-action-summary",i.append(r,c);const s=document.createElement("span");s.className="fb-trig-kind",a.append(l,i,s,De(()=>n.remove(),"Remove action"));const d=document.createElement("div");d.className="fb-trig-action-body";const p=J("fb-trig-action-type",de,e.type||"banner");d.appendChild(P("Action",p,{full:!0})),d.appendChild(kt(e,t));const f=()=>{const h=de.find(b=>b.value===p.value);r.textContent=h?.label||p.value,s.textContent=yn(h),s.classList.toggle("fb-trig-kind--event",h?.kind==="event"),c.textContent=xn(Lt(n))},y=h=>{d.hidden=!h,n.classList.toggle("is-open",h),a.setAttribute("aria-expanded",String(h)),B(l,h?"chevron-down":"chevron-right",12)};return a.addEventListener("click",()=>y(d.hidden)),a.addEventListener("keydown",h=>{h.target!==a||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),y(d.hidden))}),p.addEventListener("change",()=>{const h=kt({type:p.value},t);d.replaceChild(h,d.querySelector(".fb-trig-params")),f(),window.I?.scan?.()}),d.addEventListener("input",f),d.addEventListener("change",f),n.append(a,d),y(o),f(),n}function St(e,t,o){const n=document.createElement("section");n.className=`fb-trig-sec fb-trig-sec--${e}`;const a=document.createElement("div");a.className="fb-trig-sec-head";const l=document.createElement("span");if(l.className="fb-trig-sec-title",l.textContent=t,a.appendChild(l),o){const i=document.createElement("span");i.className="fb-trig-sec-hint",i.textContent=o,a.appendChild(i)}return n.appendChild(a),n}function Pe(e,t){const o=document.createElement("button");return o.type="button",o.className="btn btn-xs btn-ghost fb-trig-add",re(o,"plus",e,12),o.addEventListener("click",t),o}function Tt(e,t,o,n){const l=St(e,t,e==="then"?"What happens while the answers match.":"What happens while they do not. Leave empty for nothing.");l.classList.add("fb-trig-branch"),l.dataset.branch=e;const i=document.createElement("div");return i.className="fb-trig-action-list",(o||[]).forEach(r=>i.appendChild(_e(r,n))),l.appendChild(i),l.appendChild(Pe("Add action",()=>{i.appendChild(_e({type:"banner"},n,{open:!0})),window.I?.scan?.()})),l}function Nt(e,t,o){const n=vt(t,!0),a=document.createElement("div");a.className="fb-trig-card",a.dataset.triggerId=e.id||`trg-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;const l=document.createElement("div");l.className="fb-trig-card-head";const i=document.createElement("span");i.className="fb-trig-card-title",i.textContent=`Trigger ${o+1}`,l.appendChild(i);const r=ue("fb-trig-enabled",e.enabled!==!1,"Enabled","Untick to keep the trigger but switch it off.");if(l.appendChild(r),l.appendChild(De(()=>a.remove(),"Remove trigger")),a.appendChild(l),!n.length){const p=document.createElement("p");return p.className="fb-trig-empty",p.textContent="Give this field a name first - a trigger tests an answer, and it needs something to test.",a.appendChild(p),a}const c=St("when","When");c.querySelector(".fb-trig-sec-head").appendChild(J("fb-trig-match",[{value:"all",label:"all of these are true"},{value:"any",label:"any of these is true"}],Array.isArray(e.when?.any)?"any":"all"));const s=document.createElement("div");s.className="fb-trig-cond-list";const d=e.when?.all||e.when?.any||[];return(d.length?d:[{}]).forEach(p=>s.appendChild(xt(p,n))),c.appendChild(s),c.appendChild(Pe("Add condition",()=>{s.appendChild(xt({},n)),window.I?.scan?.()})),a.appendChild(c),a.appendChild(Tt("then","Then",e.then,t)),a.appendChild(Tt("otherwise","Otherwise",e.otherwise,t)),a}function Cn(e,t){const o=Array.isArray(e.triggers)?e.triggers:[],n=document.createElement("div");n.className="fb-field-triggers";const a=document.createElement("div");a.className="fb-trig-panel-head";const l=document.createElement("span");l.className="fb-trig-panel-title",l.textContent=`\u{1F3AF} Triggers${o.length?` (${o.length})`:""}`;const i=document.createElement("button");i.type="button",i.className="btn btn-xs btn-ghost",B(i,o.length?"chevron-down":"chevron-right",12);const r=document.createElement("div");r.className="fb-triggers-body",r.hidden=!o.length,a.addEventListener("click",()=>{r.hidden=!r.hidden,B(i,r.hidden?"chevron-right":"chevron-down",12)});const c=document.createElement("p");c.className="fb-trig-blurb",c.textContent="Do something to the form when the answers meet a condition - show a banner or toast, hide, disable or require other fields, refuse the submit, end the form early, notify the admins, jump to a step, or celebrate.",r.appendChild(c);const s=document.createElement("div");return s.className="fb-trig-list",o.forEach((d,p)=>s.appendChild(Nt(d,t,p))),r.appendChild(s),r.appendChild(Pe("Add trigger",()=>{const d=Nt({enabled:!0,then:[]},t,s.children.length);s.appendChild(d),d.querySelector('.fb-trig-branch[data-branch="then"] .fb-trig-action-list')?.appendChild(_e({type:"banner"},t,{open:!0})),window.I?.scan?.()})),a.appendChild(l),a.appendChild(i),n.appendChild(a),n.appendChild(r),n}function Lt(e){const t=e.querySelector(".fb-trig-action-type")?.value,o=de.find(l=>l.value===t);if(!o)return null;const n={type:t},a=l=>e.querySelector(l)?.value?.trim()||"";for(const l of o.params)switch(l){case"message":n.message=a(".fb-trig-p-message");break;case"finishLabel":{const i=a(".fb-trig-p-finish");i&&(n.finishLabel=i);break}case"doneMessage":{const i=a(".fb-trig-p-done");i&&(n.doneMessage=i);break}case"finish":e.querySelector(".fb-trig-p-finish-on")?.checked||(n.finish=!1);break;case"record":e.querySelector(".fb-trig-p-record")?.checked||(n.record=!1);break;case"level":n.level=a(".fb-trig-p-level")||"info";break;case"position":n.position=a(".fb-trig-p-position")||"field-below";break;case"dismissible":n.dismissible=!!e.querySelector(".fb-trig-p-dismissible")?.checked;break;case"target":{const i=a(".fb-trig-p-target")||"rest";n.target=i,i==="listed"&&(n.fields=Array.from(e.querySelectorAll(".fb-trig-p-fields option")).filter(r=>r.selected).map(r=>r.value));break}case"step":{const i=parseInt(a(".fb-trig-p-step"),10);Number.isFinite(i)&&(n.step=i);break}case"url":n.url=a(".fb-trig-p-url");break;case"theme":n.theme=a(".fb-trig-p-theme")||"auto";break;case"intensity":n.intensity=a(".fb-trig-p-intensity")||"medium";break;case"slug":n.slug=a(".fb-trig-p-slug");break;default:break}return o.kind==="event"&&!o.noOnce&&e.querySelector(".fb-trig-p-once")?.checked&&(n.once=!0),n}function En(e){const t=Lt(e);if(!t)return null;const o=de.find(l=>l.value===t.type),n=t.type,a=["block-submit","end-form","notify"].includes(o.value);return o.params.includes("message")&&!t.message&&!a?(delete t.message,null):(a&&!t.message&&delete t.message,n==="redirect"&&!t.url||n==="run-action"&&!t.slug?null:t)}function wn(e){const o=document.querySelector(`.fb-field-card[data-index="${e}"]`)?.querySelector(".fb-field-triggers");if(!o)return;const n=[];return o.querySelectorAll(".fb-trig-card").forEach(a=>{const l=Array.from(a.querySelectorAll(".fb-trig-cond-row")).map(p=>{const f=p.querySelector(".fb-trig-cond-field")?.value,y=p.querySelector(".fb-trig-cond-op")?.value;if(!f||!y)return null;const h=p.querySelector(".fb-trig-cond-val")?.value??"";return{field:f,operator:y,value:h}}).filter(Boolean);if(!l.length)return;const i=p=>Array.from(a.querySelectorAll(`.fb-trig-branch[data-branch="${p}"] .fb-trig-action-row`)).map(En).filter(Boolean),r=i("then"),c=i("otherwise");if(!r.length&&!c.length)return;const s=a.querySelector(".fb-trig-match")?.value==="any"?"any":"all",d={id:a.dataset.triggerId,enabled:!!a.querySelector(".fb-trig-enabled")?.checked,when:{[s]:l}};r.length&&(d.then=r),c.length&&(d.otherwise=c),n.push(d)}),n.length?n:void 0}function $t(e,t,o){const n=document.createElement("div");return n.className="fb-field-extras",e==="chooser"?(n.appendChild(Tn(t,o)),n.appendChild(Ln(t.options||[],o))):(Fe.has(e)&&n.appendChild(Fn(t.options||[],o)),e==="textarea"&&n.appendChild(D([j("Rows",`fb-rows-${o}`,"number",t.formConfig?.rows||4,"Height of textarea")])),(e==="string"||e==="textarea")&&n.appendChild(D([j("Min Length",`fb-minlength-${o}`,"number",t.minLength||"",""),j("Max Length",`fb-maxlength-${o}`,"number",t.maxLength||"","")])),e==="number"&&n.appendChild(D([j("Min",`fb-min-${o}`,"number",t.min??"",""),j("Max",`fb-max-${o}`,"number",t.max??"","")]))),qt.includes(e)&&n.appendChild(Sn(t,o)),n.children.length?n:null}const qt=["string","email","tel","number","url","date","time","password","select","textarea"],At=[{key:"reveal",label:"Show / hide button",types:["password"],hint:"Show / hide lets the visitor see what they typed."},{key:"clear",label:"Clear button",types:["string","email","tel","url","textarea"],hint:"Clear adds an x that empties the field."},{key:"stepper",label:"- / + buttons",types:["number"],hint:"The - and + buttons step the number within its min, max and step."},{key:"counter",label:"Character counter",types:["string","textarea"],hint:"The counter shows how many characters are used, against Max Length if one is set."}];function kn(e){return e?typeof e=="string"?{icon:"",text:e}:{icon:e.icon||"",text:e.icon?"":e.text??""}:{icon:"",text:""}}function Sn(e,t){const o=document.createElement("div");o.className="fb-addons";const n=(i,r)=>{const c=kn(e.formConfig?.[i]),s=document.createElement("div");s.style.flex="1";const d=document.createElement("span");d.className="form-label",d.style.fontSize=".8rem",d.textContent=r;const p=$e("Icon, e.g. search",c.icon);p.input.id=`fb-${i}-icon-${t}`,p.input.setAttribute("aria-label",`${r}: icon`);const f=document.createElement("input");return f.type="text",f.className="form-input",f.id=`fb-${i}-text-${t}`,f.value=c.text,f.placeholder="or text, e.g. \xA3 or kg",f.maxLength=24,f.setAttribute("aria-label",`${r}: text`),f.style.marginTop=".35rem",p.input.addEventListener("input",()=>{p.input.value.trim()&&(f.value="")}),f.addEventListener("input",()=>{f.value.trim()&&(p.input.value="")}),s.append(d,p.el,f),s};o.appendChild(D([n("prefix","Before the field"),n("suffix","After the field")]));const a=document.createElement("p");a.className="form-hint text-muted",a.style.cssText="font-size:.73rem;margin:-.4rem 0 .75rem;",a.textContent="An icon or a short text joined to the start or end of the input, like \xA3 before a price or kg after a weight. Leave both empty for none.",o.appendChild(a);const l=At.filter(i=>i.types.includes(e.type));if(l.length){o.appendChild(D(l.map(r=>Ge(r.label,`fb-extra-${r.key}-${t}`,!!e.formConfig?.[r.key]))));const i=document.createElement("p");i.className="form-hint text-muted",i.style.cssText="font-size:.73rem;margin:-.4rem 0 .75rem;",i.textContent=l.map(r=>r.hint).join(" "),o.appendChild(i)}return o}function Bt(e){const t=document.createElement("div");t.className="fb-chooser-section",t.style.cssText="border:1px solid var(--dm-border); border-radius:6px; margin-top:.5rem; overflow:hidden;";const o=document.createElement("div");o.style.cssText="padding:.4rem .6rem; background:color-mix(in srgb, var(--dm-background) 60%, transparent); font-weight:600; font-size:.82rem; border-bottom:1px solid var(--dm-border);",o.textContent=e,t.appendChild(o);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 Ee(e,t,o,n,a){const l=document.createElement("div");l.style.flex="1";const i=document.createElement("label");i.htmlFor=e,i.className="form-label",i.textContent=t,i.style.fontSize=".8rem";const r=document.createElement("select");if(r.id=e,r.className="form-input",n.forEach(([c,s])=>{const d=document.createElement("option");d.value=c,d.textContent=s,String(c)===String(o)&&(d.selected=!0),r.appendChild(d)}),l.appendChild(i),l.appendChild(r),a){const c=document.createElement("p");c.className="form-hint text-muted",c.textContent=a,c.style.cssText="font-size:.72rem;margin-top:.2rem;",l.appendChild(c)}return l}function Ft(e,t,o,n){const a=document.createElement("div");a.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=!!o,l.appendChild(i),l.appendChild(document.createTextNode(" "+t)),a.appendChild(l),n){const r=document.createElement("p");r.className="form-hint text-muted",r.textContent=n,r.style.cssText="font-size:.72rem;margin-top:.2rem;",a.appendChild(r)}return a}function je(e,t,o,n,a){const l=document.createElement("div");l.style.flex="1";const i=document.createElement("label");i.htmlFor=e,i.className="form-label",i.textContent=t,i.style.fontSize=".8rem",l.appendChild(i);const r=document.createElement("div");r.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=o||"",n&&(c.placeholder=n),c.style.flex="1";const s=document.createElement("input");s.type="color",s.title="Pick a colour",s.style.cssText="width:36px;height:auto;padding:0;border:1px solid var(--dm-border);border-radius:4px;cursor:pointer;";const d=String(c.value).match(/^#[0-9a-fA-F]{3,8}$/);if(s.value=d?c.value:"#000000",s.addEventListener("input",()=>{c.value=s.value,c.dispatchEvent(new Event("input",{bubbles:!0}))}),r.appendChild(c),r.appendChild(s),l.appendChild(r),a){const p=document.createElement("p");p.className="form-hint text-muted",p.textContent=a,p.style.cssText="font-size:.72rem;margin-top:.2rem;",l.appendChild(p)}return l}function Tn(e,t){const o=document.createElement("div");o.style.cssText="margin-top:.5rem; display:flex; flex-direction:column; gap:.4rem;";const n=Bt("Layout");n.body.appendChild(D([Ee(`fb-chooser-variant-${t}`,"Variant",e.variant||"card",[["card","Card - rich tiles"],["chip","Chip - compact pills"]],"Card supports description and grid columns; chips wrap."),Ft(`fb-chooser-multiple-${t}`,"Multi-select",!!e.multiple,"Off = single (radio); on = multi (checkbox).")])),n.body.appendChild(D([Ee(`fb-chooser-density-${t}`,"Density",e.density||"comfortable",[["comfortable","Comfortable"],["compact","Compact"]],"Compact strips description (card variant only)."),j("Columns",`fb-chooser-columns-${t}`,"number",e.columns||3,"Card grid (1-6). Ignored for chips.")])),o.appendChild(n.wrap);const a=Bt("Visual");return a.body.appendChild(D([je(`fb-chooser-accent-${t}`,"Accent",e.accent||"","primary / success / #ec4899","Selected highlight colour - semantic name or any CSS colour."),Ee(`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.")])),a.body.appendChild(D([Ft(`fb-chooser-glow-${t}`,"Glow on selected",!!e.glow,"Soft outer glow."),je(`fb-chooser-glow-colour-${t}`,"Glow colour",e.glowColour||"","defaults to accent","Optional; semantic name or CSS colour.")])),a.body.appendChild(D([Ee(`fb-chooser-shadow-${t}`,"Shadow",e.shadow||"none",[["none","None"],["sm","Small"],["md","Medium"],["lg","Large"],["xl","Extra Large"]],"Drop shadow on every option."),je(`fb-chooser-shadow-colour-${t}`,"Shadow colour",e.shadowColour||"","rgba(0,0,0,0.1)","Optional shadow tint.")])),o.appendChild(a.wrap),o}function Nn(e,t,o,n){const a=document.createElement("div");a.className="fb-chooser-option-row",a.dataset.optIdx=String(o),a.style.cssText="border:1px solid var(--dm-border); border-radius:4px; padding:.5rem; background:var(--dm-background-alt); 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 r=document.createElement("button");r.type="button",r.className="btn btn-xs btn-ghost",r.title="Move up",B(r,"arrow-up"),r.addEventListener("click",z=>{z.preventDefault(),It(t,o,-1,n)});const c=document.createElement("button");c.type="button",c.className="btn btn-xs btn-ghost",c.title="Move down",B(c,"arrow-down"),c.addEventListener("click",z=>{z.preventDefault(),It(t,o,1,n)}),i.appendChild(r),i.appendChild(c),l.appendChild(i);const s=document.createElement("input");s.type="text",s.className="form-input fb-chooser-opt-value",s.placeholder="value",s.value=e.value||"",s.style.flex="1",l.appendChild(s);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 p=document.createElement("button");p.type="button",p.className="btn btn-xs btn-ghost",p.style.cssText="line-height:1;opacity:.6;",p.title="Remove option",B(p,"x"),p.addEventListener("click",z=>{z.preventDefault(),An(t,o,n)}),l.appendChild(p),a.appendChild(l);const f=document.createElement("div");f.style.cssText="display:flex; gap:.4rem;";const y=$e("icon name (optional)",e.icon||"");y.input.classList.add("fb-chooser-opt-icon"),y.el.style.flex="1",f.appendChild(y.el);const h=document.createElement("input");h.type="text",h.className="form-input fb-chooser-opt-description",h.placeholder="description (card + comfortable only)",h.value=e.description||"",h.style.flex="2",f.appendChild(h),a.appendChild(f);const b=document.createElement("div");b.style.cssText="display:flex; gap:.4rem;";const k=document.createElement("input");k.type="text",k.className="form-input fb-chooser-opt-tooltip",k.placeholder="tooltip (hover hint)",k.value=e.tooltip||"",k.style.flex="2",b.appendChild(k);const m=document.createElement("input");m.type="text",m.className="form-input fb-chooser-opt-badge-text",m.placeholder="badge text",m.value=e.badge?.text||"",m.style.flex="1",b.appendChild(m);const x=document.createElement("select");x.className="form-input fb-chooser-opt-badge-type",x.style.flex="1",[["","no badge"],["primary","primary"],["success","success"],["info","info"],["warning","warning"],["danger","danger"]].forEach(([z,Q])=>{const W=document.createElement("option");W.value=z,W.textContent=Q,(e.badge?.type||"")===z&&(W.selected=!0),x.appendChild(W)}),b.appendChild(x),a.appendChild(b);const N=document.createElement("div");N.style.cssText="display:flex; gap:1rem; font-size:.8rem;";const L=document.createElement("label");L.style.cssText="display:inline-flex;align-items:center;gap:.3rem;";const I=document.createElement("input");I.type="checkbox",I.className="fb-chooser-opt-recommended",I.checked=!!e.recommended,L.appendChild(I),L.appendChild(document.createTextNode(" Recommended")),N.appendChild(L);const O=document.createElement("label");O.style.cssText="display:inline-flex;align-items:center;gap:.3rem;";const V=document.createElement("input");return V.type="checkbox",V.className="fb-chooser-opt-disabled",V.checked=!!e.disabled,O.appendChild(V),O.appendChild(document.createTextNode(" Disabled")),N.appendChild(O),a.appendChild(N),a}function Ln(e,t){const o=document.createElement("div");o.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 a=document.createElement("p");a.textContent="Options",a.style.cssText="font-size:.85rem;font-weight:600;margin:0;",n.appendChild(a);const l=document.createElement("button");l.type="button",l.className="btn btn-xs btn-ghost",re(l,"plus","Add option"),n.appendChild(l),o.appendChild(n);const i=document.createElement("div");i.className="fb-chooser-options-list",i.id=`fb-chooser-options-${t}`,i.style.cssText="display:flex; flex-direction:column; gap:.4rem;",o.appendChild(i);const r=()=>{i.replaceChildren();const c=$n(t);(c.length?c:e||[]).forEach((d,p)=>{i.appendChild(Nn(d,t,p,r))})};return l.addEventListener("click",c=>{c.preventDefault(),qn(t,r)}),r(),o}function $n(e){const t=w[e];return!t||!Array.isArray(t.options)?[]:t.options}function Ve(e){return w[e]?(Array.isArray(w[e].options)||(w[e].options=[]),w[e].options):[]}function qn(e,t){we(e),Ve(e).push({value:"new",label:"New option"}),t()}function An(e,t,o){we(e),Ve(e).splice(t,1),o()}function It(e,t,o,n){we(e);const a=Ve(e),l=t+o;if(l<0||l>=a.length)return;const[i]=a.splice(t,1);a.splice(l,0,i),n()}function we(e){const t=document.getElementById(`fb-chooser-options-${e}`);if(!t)return;const o=t.querySelectorAll(".fb-chooser-option-row"),n=[];o.forEach(a=>{const l={value:a.querySelector(".fb-chooser-opt-value")?.value.trim()||"",label:a.querySelector(".fb-chooser-opt-label")?.value.trim()||""},i=a.querySelector(".fb-chooser-opt-icon")?.value.trim();i&&(l.icon=i);const r=a.querySelector(".fb-chooser-opt-description")?.value.trim();r&&(l.description=r);const c=a.querySelector(".fb-chooser-opt-tooltip")?.value.trim();c&&(l.tooltip=c);const s=a.querySelector(".fb-chooser-opt-badge-text")?.value.trim(),d=a.querySelector(".fb-chooser-opt-badge-type")?.value;(s||d)&&(l.badge={},s&&(l.badge.text=s),d&&(l.badge.type=d)),a.querySelector(".fb-chooser-opt-recommended")?.checked&&(l.recommended=!0),a.querySelector(".fb-chooser-opt-disabled")?.checked&&(l.disabled=!0),n.push(l)}),w[e]&&(w[e].options=n)}function D(e){const t=document.createElement("div");return t.style.cssText="display:flex;gap:.85rem;margin-bottom:.75rem;",e.forEach(o=>{o&&t.appendChild(o)}),t}function j(e,t,o,n,a){const l=document.createElement("div");l.style.flex="1";const i=document.createElement("label");i.htmlFor=t,i.className="form-label",i.textContent=e,i.style.fontSize=".8rem";const r=document.createElement("input");if(r.id=t,r.type=o||"text",r.className="form-input",r.value=n??"",l.appendChild(i),l.appendChild(r),a){const c=document.createElement("p");c.className="form-hint text-muted",c.textContent=a,c.style.cssText="font-size:.73rem;margin-top:.35rem;",l.appendChild(c)}return l}function Bn(e,t,o,n){const a=document.createElement("div");a.style.flex="1";const l=document.createElement("label");l.htmlFor=t,l.className="form-label",l.textContent=e,l.style.fontSize=".8rem";const i=document.createElement("select");return i.id=t,i.className="form-select",o.forEach(r=>{const c=document.createElement("option");c.value=r.value,c.textContent=r.label,r.value===n&&(c.selected=!0),i.appendChild(c)}),a.appendChild(l),a.appendChild(i),a}function Ge(e,t,o){const n=document.createElement("div");n.style.cssText="flex:0;min-width:80px;display:flex;flex-direction:column;justify-content:flex-end;";const a=document.createElement("label");a.style.cssText="display:flex;align-items:center;gap:.4rem;cursor:pointer;font-size:.8rem;white-space:nowrap;";const l=document.createElement("input");return l.id=t,l.type="checkbox",l.checked=o,a.appendChild(l),a.appendChild(document.createTextNode(e)),n.appendChild(a),n}function Fn(e,t){const o=document.createElement("div");o.style.cssText="margin-top:.4rem;";const n=document.createElement("p");n.textContent="Options (one per line: value or value:Label)",n.style.cssText="font-size:.8rem;font-weight:600;margin-bottom:.3rem;";const a=document.createElement("textarea");return a.id=`fb-options-${t}`,a.className="form-input",a.rows=4,a.placeholder=`yes:Yes
6
6
  no:No
7
- maybe:Maybe`,l.value=(e||[]).map(a=>{const i=typeof a=="string"?a:a.value??"",r=typeof a=="string"?a:a.label??i;return i===r?i:`${i}:${r}`}).join(`
8
- `),l.style.fontFamily="monospace",o.appendChild(n),o.appendChild(l),o}function ke(e){return parseInt(e,10)===3?3:2}function Se(e){const t=e.find("#field-project").val()||"";return D(),{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:{...be||{},project:t||null},fields:w,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()||"grid",columns:ke(e.find("#setting-columns").val()),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()},...he!==null&&{collection:he}}}}function It(e,t){const o={};return e.forEach(n=>{if(n.type==="page-break"||n.type==="spacer")return;const l={...n.formConfig||{}};l.span==="full"&&t&&(l.span=t);const a=n.type==="chooser"||!!(n.variant&&["select","radio","checkbox-group"].includes(n.type)),r={type:n.type==="checkbox"?"boolean":n.type==="date"||n.type==="icon"||n.type==="image"?"string":a?"chooser":n.type,label:n.label,required:n.required,options:n.options,formConfig:{...n.placeholder&&{placeholder:n.placeholder},...n.helper&&{helperText:n.helper},...n.tooltip&&{tooltip:n.tooltip},...l}};a&&(n.variant&&(r.variant=n.variant),(n.multiple||n.type==="checkbox-group")&&(r.multiple=!0),n.density&&(r.density=n.density),n.columns&&(r.columns=n.columns),n.accent&&(r.accent=n.accent),n.accentStyle&&(r.accentStyle=n.accentStyle),n.glow&&(r.glow=!0),n.glowColour&&(r.glowColour=n.glowColour),n.shadow&&(r.shadow=n.shadow),n.shadowColour&&(r.shadowColour=n.shadowColour)),o[n.name]=r}),o}function Bt(e,t){const o=typeof e=="string"?document.querySelector(e):e;o&&(t||[]).forEach(n=>{if(n.type!=="date"||!n.name)return;const l=o.querySelector(`[name="${n.name}"]`);l&&l.type!=="date"&&(l.type="date")})}function Ot(e,t){const o=e?.querySelector?.(".dm-plugin-banner-name .dm-plugin-banner-sep");if(o){for(;o.nextSibling;)o.nextSibling.remove();o.after(document.createTextNode(String(t||"")))}}const Nn=e=>String(e??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");let H=null,Rt=0,Mt=!1;const Te=e=>String(e||"").split("?")[0].replace(/\/$/,"");function Ln(){Mt||!window.R?.use||(Mt=!0,R.use((e,t,o)=>!H||!at(t?.path,e?.path)||H.path!==Te(t?.path)||(H.flush(),!H.dirty())?o():E.confirm("You have unsaved changes to this form. Leave anyway? They are kept as a draft for your next visit to it.").then(n=>{n?o():history.replaceState(null,"",`#${t.path}`)})),M.subscribe("router:afterChange",({to:e,from:t}={})=>{if(H&&H.path===Te(t?.path)&&at(t?.path,e?.path)){const o=H;H=null,o.dispose()}}))}export const formEditorView={templateUrl:"/admin/js/templates/form-editor.html",async onMount(e){if(Ln(),H){const p=H;H=null,p.dispose()}const t=Te(location.hash.replace(/^#/,"")),o=++Rt,n=()=>o!==Rt||!e.get(0)?.isConnected||Te(location.hash.replace(/^#/,""))!==t;w=[],q=null,he=null;const l=window.location.hash.match(/\/forms\/edit\/([^/?#]+)/);q=l?l[1]:null;let a=null;const i=E.loader(e.get(0),{type:"dots"});if(q)try{if(a=await ie(`/forms/${q}`),n()){i.destroy();return}w=a.fields||[],he=a.actions?.collection??null}catch{if(n()){i.destroy();return}E.toast("Could not load form.",{type:"error"})}be={};try{const p=await ie("/projects").catch(()=>[]);if(n()){i.destroy();return}const v=e.find("#field-project").get(0);v&&(Array.isArray(p)?p:[]).forEach(g=>{const C=document.createElement("option");C.value=g.slug,C.textContent=g.name||g.slug,v.appendChild(C)})}catch{}if(i.destroy(),Ot(e.get(0),a?a.title||a.slug:"New form"),q||e.find("#field-title").get(0).addEventListener("input",function(){e.find("#field-slug").val(rt(this.value))}),E.tabs(e.find("#editor-tabs").get(0)),a){e.find("#field-title").val(a.title),e.find("#field-slug").val(a.slug),e.find("#field-description").val(a.description||""),e.find("#field-bundled").prop("checked",!!a.bundled),be=a.meta||{},e.find("#field-project").val(a.meta?.project||"");const p=a.settings||{};e.find("#setting-submit-text").val(p.submitText||"Submit"),e.find("#setting-success-message").val(p.successMessage||""),e.find("#setting-layout").val(p.layout||"grid"),e.find("#setting-columns").val(ke(p.columns)),e.find("#setting-submit-span").val(p.submitSpan||""),e.find("#columns-group").get(0).style.display=(p.layout||"grid")==="grid"?"":"none",e.find("#setting-honeypot").prop("checked",p.honeypot!==!1),e.find("#setting-rate-limit").val(p.rateLimitPerMinute||3),e.find("#setting-success-redirect").val(p.successRedirect||"");const v=a.actions?.email||{};e.find("#action-email-enabled").prop("checked",v.enabled||!1),e.find("#action-email-recipients").val(v.recipients||""),e.find("#action-email-subject-prefix").val(v.subjectPrefix||"");const g=a.actions?.webhook||{};e.find("#action-webhook-enabled").prop("checked",g.enabled||!1),e.find("#action-webhook-url").val(g.url||""),e.find("#action-webhook-method").val(g.method||"POST")}const r=a?.settings?.actionSlug||"";try{const p=await ie("/actions").catch(()=>[]);if(n())return;const v=e.find("#action-cms-slug").get(0);if(fe=Array.isArray(p)?p:[],(Array.isArray(p)?p:[]).forEach(g=>{const C=document.createElement("option");C.value=g.slug,C.textContent=g.title||g.slug,g.slug===r&&(C.selected=!0),v.appendChild(C)}),!p.length){const g=document.createElement("option");g.value="",g.textContent="No actions available",g.disabled=!0,v.appendChild(g)}}catch{}const c=p=>{e.find("#columns-group").get(0).style.display=p?"":"none",document.querySelectorAll(".fb-grid-row").forEach(v=>{v.style.display=p?"flex":"none"})};e.find("#setting-layout").get(0)?.addEventListener("change",function(){c(this.value==="grid")}),c(e.find("#setting-layout").val()==="grid"),Q(e);const s=e.find("#add-element-menu").get(0);e.find("#add-element-btn").get(0).addEventListener("click",p=>{p.stopPropagation(),s.style.display=s.style.display==="none"?"":"none"}),ne&&document.removeEventListener("click",ne),ne=()=>{s&&(s.style.display="none")},document.addEventListener("click",ne),e.find("#add-field-btn").get(0).addEventListener("click",()=>{s&&(s.style.display="none"),D();const p=w.length;w.push({name:`field_${p+1}`,type:"string",label:"New Field",required:!1,placeholder:""}),Q(e);const v=e.find("#fields-list").get(0)?.lastElementChild;if(v){const g=v.querySelector(".fb-field-body");g&&(g.style.display="")}}),e.find("#add-spacer-btn").get(0).addEventListener("click",()=>{s&&(s.style.display="none"),D(),w.push({type:"spacer"}),Q(e)}),e.find("#add-page-break-btn").get(0).addEventListener("click",()=>{s&&(s.style.display="none"),D();const p=w.filter(v=>v.type==="page-break").length+2;w.push({type:"page-break",label:`Step ${p}`,description:""}),Q(e)}),ge=()=>{const p=Se(e),v=e.find("#preview-container").get(0);if(!v)return;const g=e.find("#preview-test-result").get(0),C=e.find("#preview-test-badge").get(0);g&&(g.style.display="none",g.textContent=""),C&&(C.style.display=q?"":"none"),e.find("#preview-card").get(0).style.display="",v.textContent="";const z=document.createElement("div");z.id="fb-preview-form",v.appendChild(z);const U=q?async $=>{g&&(g.style.display="none",g.textContent="");try{const L=await fetch(`/api/forms/submit/${q}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)}),Y=await L.json();if(!L.ok)throw new Error(Y.error||"Submission failed.");g&&(g.textContent=Y.message||p.settings?.successMessage||"Submitted successfully.",g.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);"),E.toast("Test submission stored.",{type:"success"})}catch(L){g&&(g.textContent=L.message,g.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);"),E.toast(L.message,{type:"error"})}return!1}:()=>!1,ue=p.fields.some($=>$.type==="page-break");if(z.addEventListener("dm-form-end",$=>{const L=$.detail?.validation;if(L&&!L.valid){E.toast(`Still to answer: ${L.missing.map(Y=>Y.label).concat(L.errors).join(", ")}`,{type:"warning"});return}U($.detail?.values||{})}),typeof F<"u"){const $=ke(p.settings?.columns),L=p.settings?.layout||"grid";if(ue&&F.wizard){const Y=jt(p.fields,p.title),me=Y.map(te=>({title:te.title,description:te.description,fields:It(te.fields,$)}));let P=0,Z=null,Le=null;const Xe=te=>{const Ze=(Y[P]||{}).fields||[];Bt("#fb-preview-form",Ze),tt(z,Ze),te&&window.FormLogicEngine&&dt(p.fields)&&(Z?.destroy?.(),Z=new window.FormLogicEngine.FormLogicRuntime({fields:p.fields},z,{baseValues:Le?.getStepData?Le.getStepData():{}}),Z.init())};Le=F.wizard("#fb-preview-form",{schema:{steps:me},layout:L,columns:$,finishText:p.settings?.submitText||"Finish",onStepChange:te=>{P=te,queueMicrotask(()=>Xe(!0))},onSubmit:U}),Xe(!1)}else if(F.render){const Y=It(p.fields,$),me={};if(p.fields.forEach(P=>{if(!(!P.name||P.type==="page-break"||P.type==="spacer")&&(P.type==="select"||P.type==="multiselect")&&P.required){const Z=(P.options||[])[0];Z&&(me[P.name]=typeof Z=="object"?Z.value:Z)}}),F.render("#fb-preview-form",Y,me,{submitText:p.settings?.submitText||"Submit",layout:L,columns:$,onSubmit:U}),L==="grid"&&p.settings?.submitSpan==="full"){const P=document.querySelector("#fb-preview-form .form-buttons");P&&P.classList.add("col-span-full")}Bt("#fb-preview-form",p.fields),tt(z,p.fields)}window.FormLogicEngine&&dt(p.fields)&&requestAnimationFrame(()=>{new window.FormLogicEngine.FormLogicRuntime({fields:p.fields},z).init()})}else{const $=document.createElement("p");$.textContent=`${p.fields.filter(L=>L.type!=="page-break").length} field(s): ${p.fields.filter(L=>L.type!=="page-break").map(L=>L.label).join(", ")}`,$.style.cssText="color:var(--dm-text-muted);font-style:italic;",z.appendChild($)}},ge();const d=e.find("#editor-tabs").get(0),u=e.find("#preview-card").get(0),b=p=>{u&&u.contains(p.target)||Oe()};d&&(d.addEventListener("input",b),d.addEventListener("change",b));const y=e.get(0),f=[],h=p=>(f.push(p),p);let k=!1;const m=M.observable(!1),x=M.observable(!1);let N=q,T=Se(e),I=Ae(T),B=T;const G=()=>{k||!y.isConnected||(B=Se(e),m.value=Ae(B)!==I)};let O=null;Be=()=>{clearTimeout(O),O=setTimeout(G,150)},h(()=>{clearTimeout(O),Be=null,ce=null});const X=p=>{const v=p.settings||{};e.find("#field-title").val(p.title||""),e.find("#field-slug").val(p.slug||""),e.find("#field-description").val(p.description||""),e.find("#field-bundled").prop("checked",!!p.bundled),be={...p.meta||{}},e.find("#field-project").val(p.meta?.project||""),e.find("#setting-submit-text").val(v.submitText||"Submit"),e.find("#setting-success-message").val(v.successMessage||""),e.find("#setting-layout").val(v.layout||"grid"),e.find("#setting-columns").val(ke(v.columns)),e.find("#setting-submit-span").val(v.submitSpan||""),e.find("#setting-honeypot").prop("checked",v.honeypot!==!1),e.find("#setting-rate-limit").val(v.rateLimitPerMinute||3),e.find("#setting-success-redirect").val(v.successRedirect||""),e.find("#action-cms-slug").val(v.actionSlug||"");const g=p.actions?.email||{};e.find("#action-email-enabled").prop("checked",!!g.enabled),e.find("#action-email-recipients").val(g.recipients||""),e.find("#action-email-subject-prefix").val(g.subjectPrefix||"");const C=p.actions?.webhook||{};e.find("#action-webhook-enabled").prop("checked",!!C.enabled),e.find("#action-webhook-url").val(C.url||""),e.find("#action-webhook-method").val(C.method||"POST"),w=JSON.parse(JSON.stringify(p.fields||[])),c((v.layout||"grid")==="grid"),Q(e)};async function W(){if(x.peek()||k)return;const p=Se(e);if(!p.title){E.toast("Please enter a form title (Form Details).",{type:"error"});return}const v=dn(p.fields);v.length&&E.toast(`Some trigger messages use ${v.map(C=>`{{${C}}}`).join(", ")}, which will show as blank: no field has that name, or it is a password, file or image.`,{type:"warning",duration:9e3}),x.value=!0;const g=q;try{q?(await ie(`/forms/${q}`,{method:"PUT",body:JSON.stringify(p)}),E.toast("Form saved.",{type:"success"})):(q=(await ie("/forms",{method:"POST",body:JSON.stringify(p)})).slug,E.toast("Form created.",{type:"success"})),N=q,T=p,I=Ae(p),B=p,m.value=!1;for(const C of new Set([se(g),se(q)]))try{S.remove?S.remove(C):S.set(C,null)}catch{}Ot(y,p.title),Gt("#/forms"),g||R.navigate(`/forms/edit/${q}`)}catch(C){g||(q=null),E.toast(C.message||"Failed to save form.",{type:"error"})}finally{x.value=!1}}async function zt(){m.peek()&&(!await E.confirm("Discard the changes you have not saved?")||k||(X(T),G(),Ke()))}const Ve=y.querySelector(".fex-bar");if(Ve){const p=M.applyBindings({dirty:m,saving:x},Ve,{methods:{save:W,discard:zt}});h(()=>p.dispose())}h(Vt(y,{position:"bottom"})),qe(e,{id:"form-editor-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>W()}),qe(e,{id:"form-editor-back",icon:"arrow-left",title:"All forms",onClick:()=>{location.hash="#/forms"}}),q&&qe(e,{id:"form-editor-subs",icon:"list",title:"Submissions",onClick:()=>{location.hash=`#/forms/${encodeURIComponent(q)}/submissions`}});const Ge=p=>{n()||!(p.ctrlKey||p.metaKey)||String(p.key).toLowerCase()!=="s"||(p.preventDefault(),p.stopImmediatePropagation(),W())};document.addEventListener("keydown",Ge,!0),h(()=>document.removeEventListener("keydown",Ge,!0));const K=e.find("#fields-list").get(0),Dt=p=>p?.closest?.(".fb-field-card"),He=p=>Number(p?.dataset.index),We=p=>p?.querySelector(":scope > .fb-field-body"),Ue=p=>{const v=We(p);v&&(v.style.display=v.style.display==="none"?"":"none")},oe=(p,v)=>{w=p,Q(e),v!=null&&K?.querySelectorAll(".fb-field-card")[v]?.focus()},_t=async p=>{try{await navigator.clipboard.writeText(p),E.toast(`Copied "${p}".`,{type:"success"})}catch{E.toast(`Copy failed - the name is ${p}.`,{type:"info"})}},Pt=p=>{const v=Dt(p),g=He(v);D();const C=w[g];if(!C)return[];const z=C.type!=="spacer"&&C.type!=="page-break",U=We(v),ue=U&&U.style.display!=="none";return[{header:$e(C)},...U?[{label:ue?"Close":"Edit",icon:ue?"chevron-up":"edit",action:()=>Ue(v)}]:[],...z?[{label:"Logic & triggers",icon:"zap",action:()=>{U&&(U.style.display=""),(U?.querySelector(".fb-field-logic")||U)?.scrollIntoView({block:"center",behavior:"smooth"})}}]:[],{label:"Duplicate",icon:"copy",action:()=>{D(),oe(Wt(w,g),g+1)}},{type:"divider"},{label:"Move up",icon:"arrow-up",shortcut:"Alt+\u2191",disabled:g===0,action:()=>{D(),oe(ot(w,g,-1),g-1)}},{label:"Move down",icon:"arrow-down",shortcut:"Alt+\u2193",disabled:g>=w.length-1,action:()=>{D(),oe(ot(w,g,1),g+1)}},...z&&C.name?[{label:"Copy field name",icon:"clipboard",action:()=>_t(C.name)}]:[],{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:async()=>{if(C.type!=="spacer"&&!await E.confirm(`Remove "${Nn($e(C))}"?`))return;D();const $=[...w];$.splice(g,1),oe($,Math.min(g,$.length-1))}}]};if(K&&typeof E.sortable=="function"){const p=E.sortable(K,{items:".fb-field-card",handle:".fb-drag-grip",key:null,onSort:({from:v,to:g})=>{D();const C=[...w],[z]=C.splice(v,1);C.splice(g,0,z),oe(C,g)}});h(()=>p.destroy())}let Je=null;if(K&&E.contextMenu&&(Je=E.contextMenu(K,{cursor:"glyph",match:".fb-field-card > :first-child",inherit:!1,density:"compact",items:p=>Pt(p)}),h(()=>Je?.destroy?.())),ce=p=>{for(const v of p.querySelectorAll(".fb-field-card")){v.tabIndex=0;const g=v.firstElementChild;if(!g||g.querySelector(".fex-kebab"))continue;const C=document.createElement("button");C.type="button",C.className="fex-kebab",C.textContent="\u22EE",C.title="Actions",D(),C.setAttribute("aria-label",`Actions for ${$e(w[He(v)])}`),C.addEventListener("click",z=>{z.stopPropagation(),nt(C)}),g.appendChild(C)}},K){ce(K);const p=v=>{const g=v.target?.classList?.contains("fb-field-card")?v.target:null;g&&(v.key==="F10"&&v.shiftKey?(v.preventDefault(),nt(g.firstElementChild)):v.key==="Enter"&&(v.preventDefault(),Ue(g)))};K.addEventListener("keydown",p),h(()=>K.removeEventListener("keydown",p))}const Ke=()=>{try{const p=se(N);S.remove?S.remove(p):S.set(p,null)}catch{}},Ye=p=>{if(!m.peek()||!p){Ke();return}try{S.set(se(N),{data:Ht(p),base:lt(I),at:new Date().toISOString()})}catch{}},Qe=p=>{G(),m.peek()&&(Ye(B),p.preventDefault(),p.returnValue="")};window.addEventListener("beforeunload",Qe),h(()=>window.removeEventListener("beforeunload",Qe)),h(()=>{ne&&(document.removeEventListener("click",ne),ne=null)}),H={path:t,dirty:()=>m.peek(),flush:()=>{clearTimeout(O),G()},dispose(){k||(Ye(B),k=!0,f.splice(0).reverse().forEach(p=>{try{p?.()}catch{}}))}};const Ne=se(q);let ee=null;try{ee=S.get(Ne)}catch{}if(ee?.data){try{S.remove?S.remove(Ne):S.set(Ne,null)}catch{}const p=ee.base&&ee.base!==lt(I),v=ee.at?` (${Jt(ee.at)})`:"";await E.confirm(`You left unsaved changes to this form${v}.${p?" The saved form has changed since then.":""} Pick up where you left off?`)&&!k&&(X(Ut(ee.data,T)),G())}}};
7
+ maybe:Maybe`,a.value=(e||[]).map(l=>{const i=typeof l=="string"?l:l.value??"",r=typeof l=="string"?l:l.label??i;return i===r?i:`${i}:${r}`}).join(`
8
+ `),a.style.fontFamily="monospace",o.appendChild(n),o.appendChild(a),o}function ke(e){return parseInt(e,10)===3?3:2}const In=[["#setting-submit-icon-start-slot","setting-submit-icon-start"],["#setting-submit-icon-end-slot","setting-submit-icon-end"],["#setting-second-icon-start-slot","setting-second-icon-start"],["#setting-second-icon-end-slot","setting-second-icon-end"]];function On(e){In.forEach(([t,o])=>{const n=e.find(t).get(0);if(!n||n.querySelector(`#${o}`))return;const a=$e("none","");a.input.id=o,a.input.classList.add("form-input"),n.appendChild(a.el)})}function Ot(e){const t=e.find("#setting-second-kind").val()||"",o=e.find("#second-button-group").get(0);o&&(o.style.display=t?"":"none");const n=e.find("#second-url-group").get(0);n&&(n.style.display=t==="link"?"":"none");const a=e.find("#setting-second-label").get(0);a&&(a.placeholder=t==="link"?"Cancel":"Clear form")}function zn(e){const t=l=>String(e.find(l).val()||"").trim(),o={},n={style:t("#setting-submit-style")||"primary",size:t("#setting-submit-size"),iconStart:t("#setting-submit-icon-start"),iconEnd:t("#setting-submit-icon-end")};(n.style!=="primary"||n.size||n.iconStart||n.iconEnd)&&(o.submitButton=n);const a=t("#setting-second-kind");return(a==="reset"||a==="link")&&(o.secondaryButton={kind:a,label:t("#setting-second-label"),...a==="link"?{url:t("#setting-second-url")}:{},style:t("#setting-second-style")||"secondary",iconStart:t("#setting-second-icon-start"),iconEnd:t("#setting-second-icon-end"),first:t("#setting-second-order")==="first",stack:t("#setting-second-arrange")==="stack"}),o}function zt(e,t){const o=t&&t.submitButton||{},n=t&&t.secondaryButton||{};e.find("#setting-submit-style").val(o.style||"primary"),e.find("#setting-submit-size").val(o.size||""),e.find("#setting-submit-icon-start").val(o.iconStart||""),e.find("#setting-submit-icon-end").val(o.iconEnd||""),e.find("#setting-second-kind").val(n.kind==="reset"||n.kind==="link"?n.kind:""),e.find("#setting-second-label").val(n.label||""),e.find("#setting-second-url").val(n.url||""),e.find("#setting-second-style").val(n.style||"secondary"),e.find("#setting-second-icon-start").val(n.iconStart||""),e.find("#setting-second-icon-end").val(n.iconEnd||""),e.find("#setting-second-order").val(n.first?"first":"after"),e.find("#setting-second-arrange").val(n.stack?"stack":"row"),Ot(e)}function Se(e){const t=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:{...be||{},project:t||null},fields:w,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()||"grid",columns:ke(e.find("#setting-columns").val()),submitAlign:e.find("#setting-submit-align").val()||"",...zn(e),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()},...he!==null&&{collection:he}}}}function Rt(e,t){const o={};return e.forEach(n=>{if(n.type==="page-break"||n.type==="spacer")return;const a={...n.formConfig||{}};a.span==="full"&&t&&(a.span=t);const l=n.type==="chooser"||!!(n.variant&&["select","radio","checkbox-group"].includes(n.type)),r={type:n.type==="checkbox"?"boolean":n.type==="date"||n.type==="icon"||n.type==="image"?"string":l?"chooser":n.type,label:n.label,required:n.required,options:n.options,formConfig:{...n.placeholder&&{placeholder:n.placeholder},...n.helper&&{helperText:n.helper},...n.tooltip&&{tooltip:n.tooltip},...a}};l&&(n.variant&&(r.variant=n.variant),(n.multiple||n.type==="checkbox-group")&&(r.multiple=!0),n.density&&(r.density=n.density),n.columns&&(r.columns=n.columns),n.accent&&(r.accent=n.accent),n.accentStyle&&(r.accentStyle=n.accentStyle),n.glow&&(r.glow=!0),n.glowColour&&(r.glowColour=n.glowColour),n.shadow&&(r.shadow=n.shadow),n.shadowColour&&(r.shadowColour=n.shadowColour)),o[n.name]=r}),o}function Mt(e,t){const o=typeof e=="string"?document.querySelector(e):e;o&&(t||[]).forEach(n=>{if(n.type!=="date"||!n.name)return;const a=o.querySelector(`[name="${n.name}"]`);a&&a.type!=="date"&&(a.type="date")})}function Dt(e,t){const o=e?.querySelector?.(".dm-plugin-banner-name .dm-plugin-banner-sep");if(o){for(;o.nextSibling;)o.nextSibling.remove();o.after(document.createTextNode(String(t||"")))}}const Rn=e=>String(e??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");let G=null,_t=0,Pt=!1;const Te=e=>String(e||"").split("?")[0].replace(/\/$/,"");function Mn(){Pt||!window.R?.use||(Pt=!0,R.use((e,t,o)=>!G||!it(t?.path,e?.path)||G.path!==Te(t?.path)||(G.flush(),!G.dirty())?o():E.confirm("You have unsaved changes to this form. Leave anyway? They are kept as a draft for your next visit to it.").then(n=>{n?o():history.replaceState(null,"",`#${t.path}`)})),M.subscribe("router:afterChange",({to:e,from:t}={})=>{if(G&&G.path===Te(t?.path)&&it(t?.path,e?.path)){const o=G;G=null,o.dispose()}}))}export const formEditorView={templateUrl:"/admin/js/templates/form-editor.html",async onMount(e){if(Mn(),G){const u=G;G=null,u.dispose()}const t=Te(location.hash.replace(/^#/,"")),o=++_t,n=()=>o!==_t||!e.get(0)?.isConnected||Te(location.hash.replace(/^#/,""))!==t;w=[],A=null,he=null,On(e),e.find("#setting-second-kind").get(0)?.addEventListener("change",()=>Ot(e));const a=window.location.hash.match(/\/forms\/edit\/([^/?#]+)/);A=a?a[1]:null;let l=null;const i=E.loader(e.get(0),{type:"dots"});if(A)try{if(l=await ie(`/forms/${A}`),n()){i.destroy();return}w=l.fields||[],he=l.actions?.collection??null}catch{if(n()){i.destroy();return}E.toast("Could not load form.",{type:"error"})}be={};try{const u=await ie("/projects").catch(()=>[]);if(n()){i.destroy();return}const v=e.find("#field-project").get(0);v&&(Array.isArray(u)?u:[]).forEach(g=>{const C=document.createElement("option");C.value=g.slug,C.textContent=g.name||g.slug,v.appendChild(C)})}catch{}if(i.destroy(),Dt(e.get(0),l?l.title||l.slug:"New form"),A||e.find("#field-title").get(0).addEventListener("input",function(){e.find("#field-slug").val(dt(this.value))}),E.tabs(e.find("#editor-tabs").get(0)),l){e.find("#field-title").val(l.title),e.find("#field-slug").val(l.slug),e.find("#field-description").val(l.description||""),e.find("#field-bundled").prop("checked",!!l.bundled),be=l.meta||{},e.find("#field-project").val(l.meta?.project||"");const u=l.settings||{};e.find("#setting-submit-text").val(u.submitText||"Submit"),e.find("#setting-success-message").val(u.successMessage||""),e.find("#setting-layout").val(u.layout||"grid"),e.find("#setting-columns").val(ke(u.columns)),e.find("#setting-submit-align").val(at(u,u.layout||"grid")),zt(e,u),e.find("#columns-group").get(0).style.display=(u.layout||"grid")==="grid"?"":"none",e.find("#setting-honeypot").prop("checked",u.honeypot!==!1),e.find("#setting-rate-limit").val(u.rateLimitPerMinute||3),e.find("#setting-success-redirect").val(u.successRedirect||"");const v=l.actions?.email||{};e.find("#action-email-enabled").prop("checked",v.enabled||!1),e.find("#action-email-recipients").val(v.recipients||""),e.find("#action-email-subject-prefix").val(v.subjectPrefix||"");const g=l.actions?.webhook||{};e.find("#action-webhook-enabled").prop("checked",g.enabled||!1),e.find("#action-webhook-url").val(g.url||""),e.find("#action-webhook-method").val(g.method||"POST")}const r=l?.settings?.actionSlug||"";try{const u=await ie("/actions").catch(()=>[]);if(n())return;const v=e.find("#action-cms-slug").get(0);if(fe=Array.isArray(u)?u:[],(Array.isArray(u)?u:[]).forEach(g=>{const C=document.createElement("option");C.value=g.slug,C.textContent=g.title||g.slug,g.slug===r&&(C.selected=!0),v.appendChild(C)}),!u.length){const g=document.createElement("option");g.value="",g.textContent="No actions available",g.disabled=!0,v.appendChild(g)}}catch{}const c=u=>{e.find("#columns-group").get(0).style.display=u?"":"none",document.querySelectorAll(".fb-grid-row").forEach(v=>{v.style.display=u?"flex":"none"})};e.find("#setting-layout").get(0)?.addEventListener("change",function(){c(this.value==="grid")}),c(e.find("#setting-layout").val()==="grid"),X(e);const s=e.find("#add-element-menu").get(0);e.find("#add-element-btn").get(0).addEventListener("click",u=>{u.stopPropagation(),s.style.display=s.style.display==="none"?"":"none"}),ne&&document.removeEventListener("click",ne),ne=()=>{s&&(s.style.display="none")},document.addEventListener("click",ne),e.find("#add-field-btn").get(0).addEventListener("click",()=>{s&&(s.style.display="none"),_();const u=w.length;w.push({name:`field_${u+1}`,type:"string",label:"New Field",required:!1,placeholder:""}),X(e);const v=e.find("#fields-list").get(0)?.lastElementChild;if(v){const g=v.querySelector(".fb-field-body");g&&(g.style.display="")}}),e.find("#add-spacer-btn").get(0).addEventListener("click",()=>{s&&(s.style.display="none"),_(),w.push({type:"spacer"}),X(e)}),e.find("#add-page-break-btn").get(0).addEventListener("click",()=>{s&&(s.style.display="none"),_();const u=w.filter(v=>v.type==="page-break").length+2;w.push({type:"page-break",label:`Step ${u}`,description:""}),X(e)}),ge=()=>{const u=Se(e),v=e.find("#preview-container").get(0);if(!v)return;const g=e.find("#preview-test-result").get(0),C=e.find("#preview-test-badge").get(0);g&&(g.style.display="none",g.textContent=""),C&&(C.style.display=A?"":"none"),e.find("#preview-card").get(0).style.display="",v.textContent="";const T=document.createElement("div");T.id="fb-preview-form",v.appendChild(T);const H=A?async q=>{g&&(g.style.display="none",g.textContent="");try{const $=await fetch(`/api/forms/submit/${A}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(q)}),Y=await $.json();if(!$.ok)throw new Error(Y.error||"Submission failed.");g&&(g.textContent=Y.message||u.settings?.successMessage||"Submitted successfully.",g.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);"),E.toast("Test submission stored.",{type:"success"})}catch($){g&&(g.textContent=$.message,g.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);"),E.toast($.message,{type:"error"})}return!1}:()=>!1,pe=u.fields.some(q=>q.type==="page-break");if(T.addEventListener("click",q=>{const $=q.target.closest?.("a.fb-secondary-btn");$&&(q.preventDefault(),E.toast(`Cancel takes the visitor to ${$.getAttribute("href")}`,{type:"info"}))}),T.addEventListener("dm-form-end",q=>{const $=q.detail?.validation;if($&&!$.valid){E.toast(`Still to answer: ${$.missing.map(Y=>Y.label).concat($.errors).join(", ")}`,{type:"warning"});return}H(q.detail?.values||{})}),typeof F<"u"){const q=ke(u.settings?.columns),$=u.settings?.layout||"grid";if(pe&&F.wizard){const Y=Ht(u.fields,u.title),me=Y.map(te=>({title:te.title,description:te.description,fields:Rt(te.fields,q)}));let U=0,Z=null,Le=null;const et=te=>{const tt=(Y[U]||{}).fields||[];Jt(T,u.settings),Mt("#fb-preview-form",tt),nt(T,tt),te&&window.FormLogicEngine&&pt(u.fields)&&(Z?.destroy?.(),Z=new window.FormLogicEngine.FormLogicRuntime({fields:u.fields},T,{baseValues:Le?.getStepData?Le.getStepData():{}}),Z.init())};Le=F.wizard("#fb-preview-form",{schema:{steps:me},layout:$,columns:q,finishText:u.settings?.submitText||"Finish",onStepChange:te=>{U=te,queueMicrotask(()=>et(!0))},onSubmit:H}),et(!1)}else if(F.render){const Y=Rt(u.fields,q),me={};u.fields.forEach(U=>{if(!(!U.name||U.type==="page-break"||U.type==="spacer")&&(U.type==="select"||U.type==="multiselect")&&U.required){const Z=(U.options||[])[0];Z&&(me[U.name]=typeof Z=="object"?Z.value:Z)}}),F.render("#fb-preview-form",Y,me,{submitText:u.settings?.submitText||"Submit",layout:$,columns:q,onSubmit:H}),Ut(T,u.settings,$),Mt("#fb-preview-form",u.fields),nt(T,u.fields)}window.FormLogicEngine&&pt(u.fields)&&requestAnimationFrame(()=>{new window.FormLogicEngine.FormLogicRuntime({fields:u.fields},T).init()})}else{const q=document.createElement("p");q.textContent=`${u.fields.filter($=>$.type!=="page-break").length} field(s): ${u.fields.filter($=>$.type!=="page-break").map($=>$.label).join(", ")}`,q.style.cssText="color:var(--dm-text-muted);font-style:italic;",T.appendChild(q)}},ge();const d=e.find("#editor-tabs").get(0),p=e.find("#preview-card").get(0),f=u=>{p&&p.contains(u.target)||ze()};d&&(d.addEventListener("input",f),d.addEventListener("change",f));const y=e.get(0),h=[],b=u=>(h.push(u),u);let k=!1;const m=M.observable(!1),x=M.observable(!1);let N=A,L=Se(e),I=Be(L),O=L;const V=()=>{k||!y.isConnected||(O=Se(e),m.value=Be(O)!==I)};let z=null;Oe=()=>{clearTimeout(z),z=setTimeout(V,150)},b(()=>{clearTimeout(z),Oe=null,ce=null});const Q=u=>{const v=u.settings||{};e.find("#field-title").val(u.title||""),e.find("#field-slug").val(u.slug||""),e.find("#field-description").val(u.description||""),e.find("#field-bundled").prop("checked",!!u.bundled),be={...u.meta||{}},e.find("#field-project").val(u.meta?.project||""),e.find("#setting-submit-text").val(v.submitText||"Submit"),e.find("#setting-success-message").val(v.successMessage||""),e.find("#setting-layout").val(v.layout||"grid"),e.find("#setting-columns").val(ke(v.columns)),e.find("#setting-submit-align").val(at(v,v.layout||"grid")),zt(e,v),e.find("#setting-honeypot").prop("checked",v.honeypot!==!1),e.find("#setting-rate-limit").val(v.rateLimitPerMinute||3),e.find("#setting-success-redirect").val(v.successRedirect||""),e.find("#action-cms-slug").val(v.actionSlug||"");const g=u.actions?.email||{};e.find("#action-email-enabled").prop("checked",!!g.enabled),e.find("#action-email-recipients").val(g.recipients||""),e.find("#action-email-subject-prefix").val(g.subjectPrefix||"");const C=u.actions?.webhook||{};e.find("#action-webhook-enabled").prop("checked",!!C.enabled),e.find("#action-webhook-url").val(C.url||""),e.find("#action-webhook-method").val(C.method||"POST"),w=JSON.parse(JSON.stringify(u.fields||[])),c((v.layout||"grid")==="grid"),X(e)};async function W(){if(x.peek()||k)return;const u=Se(e);if(!u.title){E.toast("Please enter a form title (Form Details).",{type:"error"});return}const v=Kt(u.settings);if(v.length){E.toast(`${v[0]} (Settings > Submit Button)`,{type:"error"});return}const g=gn(u.fields);g.length&&E.toast(`Some trigger messages use ${g.map(T=>`{{${T}}}`).join(", ")}, which will show as blank: no field has that name, or it is a password, file or image.`,{type:"warning",duration:9e3}),x.value=!0;const C=A;try{A?(await ie(`/forms/${A}`,{method:"PUT",body:JSON.stringify(u)}),E.toast("Form saved.",{type:"success"})):(A=(await ie("/forms",{method:"POST",body:JSON.stringify(u)})).slug,E.toast("Form created.",{type:"success"})),N=A,L=u,I=Be(u),O=u,m.value=!1;for(const T of new Set([se(C),se(A)]))try{S.remove?S.remove(T):S.set(T,null)}catch{}Dt(y,u.title),Xt("#/forms"),C||R.navigate(`/forms/edit/${A}`)}catch(T){C||(A=null),E.toast(T.message||"Failed to save form.",{type:"error"})}finally{x.value=!1}}async function jt(){m.peek()&&(!await E.confirm("Discard the changes you have not saved?")||k||(Q(L),V(),Xe()))}const We=y.querySelector(".fex-bar");if(We){const u=M.applyBindings({dirty:m,saving:x},We,{methods:{save:W,discard:jt}});b(()=>u.dispose())}b(Yt(y,{position:"bottom"})),qe(e,{id:"form-editor-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>W()}),qe(e,{id:"form-editor-back",icon:"arrow-left",title:"All forms",onClick:()=>{location.hash="#/forms"}}),A&&qe(e,{id:"form-editor-subs",icon:"list",title:"Submissions",onClick:()=>{location.hash=`#/forms/${encodeURIComponent(A)}/submissions`}});const He=u=>{n()||!(u.ctrlKey||u.metaKey)||String(u.key).toLowerCase()!=="s"||(u.preventDefault(),u.stopImmediatePropagation(),W())};document.addEventListener("keydown",He,!0),b(()=>document.removeEventListener("keydown",He,!0));const K=e.find("#fields-list").get(0),Vt=u=>u?.closest?.(".fb-field-card"),Ue=u=>Number(u?.dataset.index),Je=u=>u?.querySelector(":scope > .fb-field-body"),Ke=u=>{const v=Je(u);v&&(v.style.display=v.style.display==="none"?"":"none")},oe=(u,v)=>{w=u,X(e),v!=null&&K?.querySelectorAll(".fb-field-card")[v]?.focus()},Gt=async u=>{try{await navigator.clipboard.writeText(u),E.toast(`Copied "${u}".`,{type:"success"})}catch{E.toast(`Copy failed - the name is ${u}.`,{type:"info"})}},Wt=u=>{const v=Vt(u),g=Ue(v);_();const C=w[g];if(!C)return[];const T=C.type!=="spacer"&&C.type!=="page-break",H=Je(v),pe=H&&H.style.display!=="none";return[{header:Ae(C)},...H?[{label:pe?"Close":"Edit",icon:pe?"chevron-up":"edit",action:()=>Ke(v)}]:[],...T?[{label:"Logic & triggers",icon:"zap",action:()=>{H&&(H.style.display=""),(H?.querySelector(".fb-field-logic")||H)?.scrollIntoView({block:"center",behavior:"smooth"})}}]:[],{label:"Duplicate",icon:"copy",action:()=>{_(),oe(Zt(w,g),g+1)}},{type:"divider"},{label:"Move up",icon:"arrow-up",shortcut:"Alt+\u2191",disabled:g===0,action:()=>{_(),oe(st(w,g,-1),g-1)}},{label:"Move down",icon:"arrow-down",shortcut:"Alt+\u2193",disabled:g>=w.length-1,action:()=>{_(),oe(st(w,g,1),g+1)}},...T&&C.name?[{label:"Copy field name",icon:"clipboard",action:()=>Gt(C.name)}]:[],{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:async()=>{if(C.type!=="spacer"&&!await E.confirm(`Remove "${Rn(Ae(C))}"?`))return;_();const q=[...w];q.splice(g,1),oe(q,Math.min(g,q.length-1))}}]};if(K&&typeof E.sortable=="function"){const u=E.sortable(K,{items:".fb-field-card",handle:".fb-drag-grip",key:null,onSort:({from:v,to:g})=>{_();const C=[...w],[T]=C.splice(v,1);C.splice(g,0,T),oe(C,g)}});b(()=>u.destroy())}let Ye=null;if(K&&E.contextMenu&&(Ye=E.contextMenu(K,{cursor:"glyph",match:".fb-field-card > :first-child",inherit:!1,density:"compact",items:u=>Wt(u)}),b(()=>Ye?.destroy?.())),ce=u=>{for(const v of u.querySelectorAll(".fb-field-card")){v.tabIndex=0;const g=v.firstElementChild;if(!g||g.querySelector(".fex-kebab"))continue;const C=document.createElement("button");C.type="button",C.className="fex-kebab",C.textContent="\u22EE",C.title="Actions",_(),C.setAttribute("aria-label",`Actions for ${Ae(w[Ue(v)])}`),C.addEventListener("click",T=>{T.stopPropagation(),lt(C)}),g.appendChild(C)}},K){ce(K);const u=v=>{const g=v.target?.classList?.contains("fb-field-card")?v.target:null;g&&(v.key==="F10"&&v.shiftKey?(v.preventDefault(),lt(g.firstElementChild)):v.key==="Enter"&&(v.preventDefault(),Ke(g)))};K.addEventListener("keydown",u),b(()=>K.removeEventListener("keydown",u))}const Xe=()=>{try{const u=se(N);S.remove?S.remove(u):S.set(u,null)}catch{}},Qe=u=>{if(!m.peek()||!u){Xe();return}try{S.set(se(N),{data:Qt(u),base:ot(I),at:new Date().toISOString()})}catch{}},Ze=u=>{V(),m.peek()&&(Qe(O),u.preventDefault(),u.returnValue="")};window.addEventListener("beforeunload",Ze),b(()=>window.removeEventListener("beforeunload",Ze)),b(()=>{ne&&(document.removeEventListener("click",ne),ne=null)}),G={path:t,dirty:()=>m.peek(),flush:()=>{clearTimeout(z),V()},dispose(){k||(Qe(O),k=!0,h.splice(0).reverse().forEach(u=>{try{u?.()}catch{}}))}};const Ne=se(A);let ee=null;try{ee=S.get(Ne)}catch{}if(ee?.data){try{S.remove?S.remove(Ne):S.set(Ne,null)}catch{}const u=ee.base&&ee.base!==ot(I),v=ee.at?` (${tn(ee.at)})`:"";await E.confirm(`You left unsaved changes to this form${v}.${u?" The saved form has changed since then.":""} Pick up where you left off?`)&&!k&&(Q(en(ee.data,L)),V())}}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domma-cms",
3
- "version": "0.99.0",
3
+ "version": "0.100.1",
4
4
  "description": "File-based CMS powered by Domma and Fastify. Run npx domma-cms my-site to create a new project.",
5
5
  "type": "module",
6
6
  "main": "server/server.js",
@@ -83,7 +83,7 @@
83
83
  "@fastify/rate-limit": "^10.3.0",
84
84
  "@fastify/static": "9.1.1",
85
85
  "bcryptjs": "^3.0.3",
86
- "domma-js": "0.46.1",
86
+ "domma-js": "0.48.0",
87
87
  "dotenv": "^17.2.3",
88
88
  "fastify": "5.8.5",
89
89
  "gray-matter": "^4.0.3",
@@ -1 +1 @@
1
- .fb-form-wrapper{max-width:600px;margin:2rem auto}.fb-form-honeypot{position:absolute;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;opacity:0;z-index:-1}.fb-form-success{padding:1rem 1.25rem;border-radius:var(--dm-radius-md, 6px);background:color-mix(in srgb,var(--dm-success) 12%,transparent);border:1px solid color-mix(in srgb,var(--dm-success) 30%,transparent);color:var(--dm-success);font-size:.95rem;margin-top:.5rem}.fb-form-error{padding:.75rem 1rem;border-radius:var(--dm-radius-md, 6px);background:color-mix(in srgb,var(--dm-danger) 10%,transparent);border:1px solid color-mix(in srgb,var(--dm-danger) 25%,transparent);color:var(--dm-danger);font-size:.875rem;margin-top:.75rem}.fb-form-loading{opacity:.6;pointer-events:none}.wizard-progress{height:4px;background:var(--dm-border);border-radius:2px;margin-bottom:1rem}.wizard-progress-bar{height:100%;background:var(--dm-primary);border-radius:2px;transition:width .3s ease}.wizard-step-title{font-size:1.1rem;font-weight:600;margin-bottom:.25rem}.wizard-step-description{font-size:.875rem;color:var(--dm-text-muted);margin-bottom:1rem}.wizard-nav{display:flex;justify-content:space-between;gap:.5rem;margin-top:1rem}.fb-field-hidden{display:none!important}.fb-validation-error{color:var(--dm-danger);font-size:.8rem;margin-top:.25rem}.fb-field-trigger-hidden{display:none!important}.fb-field-disabled{opacity:.55;pointer-events:none}.fb-trigger-banner{display:flex;align-items:flex-start;gap:.75rem;margin:.75rem 0;padding:.7rem .9rem;border-radius:var(--dm-radius-md);border-left:3px solid var(--dm-info);background:var(--dm-surface-raised);color:var(--dm-text);font-size:.9rem}.fb-trigger-banner--success{border-left-color:var(--dm-success)}.fb-trigger-banner--warning{border-left-color:var(--dm-warning)}.fb-trigger-banner--error{border-left-color:var(--dm-danger)}.fb-trigger-banner-text{flex:1 1 auto}.fb-trigger-banner-close{flex:0 0 auto;background:none;border:0;color:var(--dm-text-muted);font-size:1.1rem;line-height:1;cursor:pointer;padding:0 .15rem}.fb-trigger-banner-close:hover{color:var(--dm-text)}.fb-trigger-block-note{color:var(--dm-danger);font-size:.85rem;margin:.5rem 0 0}.fb-field-trigger-masked{display:none!important}.fb-trigger-end{margin:1rem 0;padding:1rem 1.1rem;border-radius:var(--dm-radius-md);border:1px solid var(--dm-border);border-left:3px solid var(--dm-warning);background:var(--dm-surface-raised);color:var(--dm-text)}.fb-trigger-end-text{margin:0}.fb-form-wrapper .grid>.fb-trigger-banner,.cms-form-embed .grid>.fb-trigger-banner,.fb-form-wrapper .grid>.fb-trigger-end,.cms-form-embed .grid>.fb-trigger-end{grid-column:1 / -1}.fb-form-wrapper .domma-form-field{margin-bottom:2rem}.fb-form-wrapper .form-group:not(.form-buttons){margin-bottom:2rem}.fb-spacer{height:2rem}.fb-field-required .picker-label:after,.fb-field-required>.form-label:after{content:" *";color:var(--dm-danger)}.fb-field-required .picker-label .picker-required{display:none}.fb-field-invalid>.form-label,.fb-field-invalid .picker-label{color:var(--dm-danger)}.fb-field-invalid .form-input,.fb-field-invalid .form-select,.fb-field-invalid textarea,.fb-field-invalid .picker-options{border-color:var(--dm-danger)}@media(max-width:700px){.fb-form-wrapper form.grid,[data-form-inline] form.grid,.fb-form-wrapper .wizard form.grid,[data-form-inline] .wizard form.grid{grid-template-columns:1fr!important}.fb-form-wrapper form.grid>[class*=col-span-],[data-form-inline] form.grid>[class*=col-span-]{grid-column:span 1 / span 1!important}}.wizard-nav{gap:1rem;flex-wrap:wrap}.wizard-nav .btn{min-width:7.5rem}@media(max-width:480px){.wizard-nav{flex-direction:column-reverse}.wizard-nav .btn{width:100%}}.fb-form-wrapper .form-buttons,[data-form-inline] .form-buttons{display:flex;gap:1rem;flex-wrap:wrap;margin-top:1.25rem}
1
+ .fb-form-wrapper{max-width:600px;margin:2rem auto}.fb-form-honeypot{position:absolute;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;opacity:0;z-index:-1}.fb-form-success{padding:1rem 1.25rem;border-radius:var(--dm-radius-md, 6px);background:color-mix(in srgb,var(--dm-success) 12%,transparent);border:1px solid color-mix(in srgb,var(--dm-success) 30%,transparent);color:var(--dm-success);font-size:.95rem;margin-top:.5rem}.fb-form-error{padding:.75rem 1rem;border-radius:var(--dm-radius-md, 6px);background:color-mix(in srgb,var(--dm-danger) 10%,transparent);border:1px solid color-mix(in srgb,var(--dm-danger) 25%,transparent);color:var(--dm-danger);font-size:.875rem;margin-top:.75rem}.fb-form-loading{opacity:.6;pointer-events:none}.wizard-progress{height:4px;background:var(--dm-border);border-radius:2px;margin-bottom:1rem}.wizard-progress-bar{height:100%;background:var(--dm-primary);border-radius:2px;transition:width .3s ease}.wizard-step-title{font-size:1.1rem;font-weight:600;margin-bottom:.25rem}.wizard-step-description{font-size:.875rem;color:var(--dm-text-muted);margin-bottom:1rem}.wizard-nav{display:flex;justify-content:space-between;gap:.5rem;margin-top:1rem}.fb-field-hidden{display:none!important}.fb-validation-error{color:var(--dm-danger);font-size:.8rem;margin-top:.25rem}.fb-field-trigger-hidden{display:none!important}.fb-field-disabled{opacity:.55;pointer-events:none}.fb-trigger-banner{display:flex;align-items:flex-start;gap:.75rem;margin:.75rem 0;padding:.7rem .9rem;border-radius:var(--dm-radius-md);border-left:3px solid var(--dm-info);background:var(--dm-surface-raised);color:var(--dm-text);font-size:.9rem}.fb-trigger-banner--success{border-left-color:var(--dm-success)}.fb-trigger-banner--warning{border-left-color:var(--dm-warning)}.fb-trigger-banner--error{border-left-color:var(--dm-danger)}.fb-trigger-banner-text{flex:1 1 auto}.fb-trigger-banner-close{flex:0 0 auto;background:none;border:0;color:var(--dm-text-muted);font-size:1.1rem;line-height:1;cursor:pointer;padding:0 .15rem}.fb-trigger-banner-close:hover{color:var(--dm-text)}.fb-trigger-block-note{color:var(--dm-danger);font-size:.85rem;margin:.5rem 0 0}.fb-field-trigger-masked{display:none!important}.fb-trigger-end{margin:1rem 0;padding:1rem 1.1rem;border-radius:var(--dm-radius-md);border:1px solid var(--dm-border);border-left:3px solid var(--dm-warning);background:var(--dm-surface-raised);color:var(--dm-text)}.fb-trigger-end-text{margin:0}.fb-form-wrapper .grid>.fb-trigger-banner,.cms-form-embed .grid>.fb-trigger-banner,.fb-form-wrapper .grid>.fb-trigger-end,.cms-form-embed .grid>.fb-trigger-end{grid-column:1 / -1}.fb-form-wrapper .domma-form-field{margin-bottom:2rem}.fb-form-wrapper .form-group:not(.form-buttons){margin-bottom:2rem}.fb-spacer{height:2rem}.fb-field-required .picker-label:after,.fb-field-required>.form-label:after{content:" *";color:var(--dm-danger)}.fb-field-required .picker-label .picker-required{display:none}.fb-field-invalid>.form-label,.fb-field-invalid .picker-label{color:var(--dm-danger)}.fb-field-invalid .form-input,.fb-field-invalid .form-select,.fb-field-invalid textarea,.fb-field-invalid .picker-options{border-color:var(--dm-danger)}@media(max-width:700px){.fb-form-wrapper form.grid,[data-form-inline] form.grid,.fb-form-wrapper .wizard form.grid,[data-form-inline] .wizard form.grid{grid-template-columns:1fr!important}.fb-form-wrapper form.grid>[class*=col-span-],[data-form-inline] form.grid>[class*=col-span-]{grid-column:span 1 / span 1!important}}.wizard-nav{gap:1rem;flex-wrap:wrap}.wizard-nav .btn{min-width:7.5rem}@media(max-width:480px){.wizard-nav{flex-direction:column-reverse}.wizard-nav .btn{width:100%}}.fb-form-wrapper .form-buttons,[data-form-inline] .form-buttons,#fb-preview-form .form-buttons{display:flex;gap:1rem;flex-wrap:wrap;margin-top:1.25rem}.form-buttons.fb-submit{display:flex;gap:1rem;flex-wrap:wrap}.form-buttons.fb-submit--left{justify-content:flex-start;text-align:left}.form-buttons.fb-submit--center{justify-content:center;text-align:center}.form-buttons.fb-submit--right{justify-content:flex-end;text-align:right}.form-buttons.fb-submit--full>button[type=submit],.form-buttons.fb-submit--full>input[type=submit]{flex:1 1 100%;width:100%}.form-buttons.fb-submit>.fb-trigger-block-note{flex-basis:100%}.btn.fb-btn{gap:.45em}.btn.fb-btn>.fb-btn-icon{flex-shrink:0}.form-buttons.fb-submit--pair{display:flex;gap:1rem;flex-wrap:wrap;align-items:center}.form-buttons.fb-submit--full.fb-submit--pair:not(.fb-submit--stack)>.btn{flex:1 1 0;width:auto}.form-buttons.fb-submit--stack{flex-direction:column;flex-wrap:nowrap;align-items:flex-start;gap:.75rem}.form-buttons.fb-submit--stack.fb-submit--center{align-items:center}.form-buttons.fb-submit--stack.fb-submit--right{align-items:flex-end}.form-buttons.fb-submit--stack.fb-submit--full{align-items:stretch}.form-buttons.fb-submit--stack>.btn,.form-buttons.fb-submit--stack>button[type=submit]{flex:0 0 auto}.form-buttons.fb-submit--stack>.fb-trigger-block-note{flex-basis:auto;align-self:stretch}a.btn.fb-secondary-btn.btn-primary:not(:hover){color:var(--dm-primary-text, var(--dm-white))}a.btn.fb-secondary-btn.btn-secondary:not(:hover){color:var(--dm-secondary-text, var(--dm-white))}a.btn.fb-secondary-btn.btn-success:not(:hover){color:var(--dm-success-text, var(--dm-white))}a.btn.fb-secondary-btn.btn-danger:not(:hover){color:var(--dm-danger-text, var(--dm-white))}a.btn.fb-secondary-btn.btn-warning:not(:hover){color:var(--dm-warning-text)}a.btn.fb-secondary-btn.btn-info:not(:hover){color:var(--dm-info-text, var(--dm-white))}a.btn.fb-secondary-btn.btn-outline:not(:hover){color:var(--dm-text)}a.btn.fb-secondary-btn.btn-outline-success:not(:hover){color:var(--dm-success)}a.btn.fb-secondary-btn.btn-outline-danger:not(:hover){color:var(--dm-danger)}a.btn.fb-secondary-btn.btn-outline-warning:not(:hover){color:var(--dm-warning-text)}a.btn.fb-secondary-btn.btn-outline-info:not(:hover){color:var(--dm-info)}a.btn.fb-secondary-btn.btn-ghost:not(:hover){color:var(--dm-text-secondary)}a.btn.fb-secondary-btn:hover{text-decoration:none}