@dmitryvim/form-builder 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -40
- package/dist/browser/formbuilder.min.js +51 -51
- package/dist/browser/formbuilder.v0.2.10.min.js +322 -0
- package/dist/cjs/index.cjs +542 -138
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +534 -134
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +51 -51
- package/dist/types/instance/FormBuilderInstance.d.ts +5 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/schema.d.ts +6 -3
- package/dist/types/utils/enable-conditions.d.ts +18 -0
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.9.min.js +0 -322
- package/dist/types/utils/display-conditions.d.ts +0 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var FormBuilder=(function(F){"use strict";function
|
|
1
|
+
var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||e.maxLength!==null)&&(e.minLength!==null&&e.maxLength!==null?t.push(`length=${e.minLength}-${e.maxLength} characters`):e.maxLength!==null?t.push(`max=${e.maxLength} characters`):e.minLength!==null&&t.push(`min=${e.minLength} characters`))}function ke(e,t){(e.min!==null||e.max!==null)&&(e.min!==null&&e.max!==null?t.push(`range=${e.min}-${e.max}`):e.max!==null?t.push(`max=${e.max}`):e.min!==null&&t.push(`min=${e.min}`))}function Se(e,t){e.maxSizeMB&&t.push(`max_size=${e.maxSizeMB}MB`)}function Le(e,t){var n;(n=e.accept)!=null&&n.extensions&&t.push(`formats=${e.accept.extensions.map(o=>o.toUpperCase()).join(",")}`)}function Fe(e,t){var n;e.pattern&&!e.pattern.includes("\u0410-\u042F")?t.push("plain text only"):(n=e.pattern)!=null&&n.includes("\u0410-\u042F")&&t.push("text with punctuation")}function S(e){const t=[];return t.push(e.required?"required":"optional"),we(e,t),ke(e,t),Se(e,t),Le(e,t),Fe(e,t),t.join(" \u2022 ")}function O(e){const t=[];if(!e||typeof e!="object")return t.push("Schema must be an object"),t;if(!Array.isArray(e.elements))return t.push("Schema missing elements array"),t;if("columns"in e&&e.columns!==void 0){const o=e.columns,a=[1,2,3,4];(!Number.isInteger(o)||!a.includes(o))&&t.push(`schema.columns must be 1, 2, 3, or 4 (got ${o})`)}if("prefillHints"in e&&e.prefillHints){const o=e.prefillHints;Array.isArray(o)&&o.forEach((a,r)=>{if((!a.label||typeof a.label!="string")&&t.push(`schema.prefillHints[${r}] must have a 'label' property of type string`),!a.values||typeof a.values!="object")t.push(`schema.prefillHints[${r}] must have a 'values' property of type object`);else for(const l in a.values)e.elements.some(s=>s.key===l)||t.push(`schema.prefillHints[${r}] references non-existent field "${l}"`)})}function n(o,a){o.forEach((r,l)=>{const s=`${a}[${l}]`;if(r.type||t.push(`${s}: missing type`),r.key||t.push(`${s}: missing key`),r.enableIf){const i=r.enableIf;(!i.key||typeof i.key!="string")&&t.push(`${s}: enableIf must have a 'key' property of type string`),"equals"in i||t.push(`${s}: enableIf must have at least one operator (equals, etc.)`)}if(r.type==="group"&&"elements"in r&&r.elements&&n(r.elements,`${s}.elements`),r.type==="container"&&r.elements){if("columns"in r&&r.columns!==void 0){const i=r.columns,d=[1,2,3,4];(!Number.isInteger(i)||!d.includes(i))&&t.push(`${s}: columns must be 1, 2, 3, or 4 (got ${i})`)}if("prefillHints"in r&&r.prefillHints){const i=r.prefillHints;Array.isArray(i)&&i.forEach((d,u)=>{if((!d.label||typeof d.label!="string")&&t.push(`${s}: prefillHints[${u}] must have a 'label' property of type string`),!d.values||typeof d.values!="object")t.push(`${s}: prefillHints[${u}] must have a 'values' property of type object`);else for(const c in d.values)r.elements.some(p=>p.key===c)||t.push(`container "${r.key}": prefillHints[${u}] references non-existent field "${c}"`)})}n(r.elements,`${s}.elements`)}if(r.type==="select"&&r.options){const i=r.default;i!=null&&i!==""&&(r.options.some(d=>d.value===i)||t.push(`${s}: default "${i}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function z(e){return e&&typeof e=="object"&&e.constructor===Object}function q(e,t){return e?`${e}.${t}`:t}function H(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function I(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let o=e;for(const a of n){if(o==null)return;if(a.startsWith("[")&&a.endsWith("]")){const r=parseInt(a.slice(1,-1),10);if(!Array.isArray(o)||isNaN(r))return;o=o[r]}else o=o[a]}return o}function A(e,t,n){var o;if(!e||!e.key)throw new Error("Invalid enableIf condition: must have a 'key' property");const a=(o=e.scope)!=null?o:"relative";let r;if(a==="relative")r=n!=null?n:t;else if(a==="absolute")r=t;else throw new Error(`Invalid enableIf scope: must be "relative" or "absolute" (got "${a}")`);const l=I(r,e.key);if("equals"in e)return Ne(l,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function Ne(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(typeof e=="object"&&typeof t=="object")try{return JSON.stringify(e)===JSON.stringify(t)}catch(n){if(n instanceof TypeError&&(n.message.includes("circular")||n.message.includes("cyclic")))return console.warn("deepEqual: Circular reference detected in enableIf comparison, using reference equality"),e===t;throw n}return e===t}function qe(e,t,n,o){const a=t.state,r=document.createElement("input");if(r.type="text",r.className="w-full rounded-lg",r.style.cssText=`
|
|
2
2
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
3
3
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
4
4
|
border-radius: var(--fb-border-radius);
|
|
@@ -7,10 +7,10 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
7
7
|
font-size: var(--fb-font-size);
|
|
8
8
|
font-family: var(--fb-font-family);
|
|
9
9
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
10
|
-
`,r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,a.config.readonly||(r.addEventListener("focus",()=>{r.style.borderColor="var(--fb-border-focus-color)",r.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",r.style.outlineOffset="0"}),r.addEventListener("blur",()=>{r.style.borderColor="var(--fb-border-color)",r.style.outline="none"}),r.addEventListener("mouseenter",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-hover-color)")}),r.addEventListener("mouseleave",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-color)")})),!a.config.readonly&&t.instance){const
|
|
10
|
+
`,r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,a.config.readonly||(r.addEventListener("focus",()=>{r.style.borderColor="var(--fb-border-focus-color)",r.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",r.style.outlineOffset="0"}),r.addEventListener("blur",()=>{r.style.borderColor="var(--fb-border-color)",r.style.outline="none"}),r.addEventListener("mouseenter",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-hover-color)")}),r.addEventListener("mouseleave",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-color)")})),!a.config.readonly&&t.instance){const s=()=>{const i=r.value===""?null:r.value;t.instance.triggerOnChange(o,i)};r.addEventListener("blur",s),r.addEventListener("input",s)}n.appendChild(r);const l=document.createElement("p");l.className="mt-1",l.style.cssText=`
|
|
11
11
|
font-size: var(--fb-font-size-small);
|
|
12
12
|
color: var(--fb-text-secondary-color);
|
|
13
|
-
`,l.textContent=S(e),n.appendChild(l)}function
|
|
13
|
+
`,l.textContent=S(e),n.appendChild(l)}function Ae(e,t,n,o){var a,r;const l=t.state,s=t.prefill[e.key]||[],i=Array.isArray(s)?[...s]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;i.length<d;)i.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function p(){c.querySelectorAll(".multiple-text-item").forEach((x,g)=>{const y=x.querySelector("input");y&&(y.name=`${o}[${g}]`)})}function v(x="",g=-1){const y=document.createElement("div");y.className="multiple-text-item flex items-center gap-2";const m=document.createElement("input");if(m.type="text",m.className="flex-1",m.style.cssText=`
|
|
14
14
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
15
15
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
16
16
|
border-radius: var(--fb-border-radius);
|
|
@@ -19,32 +19,32 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
19
19
|
font-size: var(--fb-font-size);
|
|
20
20
|
font-family: var(--fb-font-family);
|
|
21
21
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
22
|
-
`,
|
|
22
|
+
`,m.placeholder=e.placeholder||"Enter text",m.value=x,m.readOnly=l.config.readonly,l.config.readonly||(m.addEventListener("focus",()=>{m.style.borderColor="var(--fb-border-focus-color)",m.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",m.style.outlineOffset="0"}),m.addEventListener("blur",()=>{m.style.borderColor="var(--fb-border-color)",m.style.outline="none"}),m.addEventListener("mouseenter",()=>{document.activeElement!==m&&(m.style.borderColor="var(--fb-border-hover-color)")}),m.addEventListener("mouseleave",()=>{document.activeElement!==m&&(m.style.borderColor="var(--fb-border-color)")})),!l.config.readonly&&t.instance){const C=()=>{const E=m.value===""?null:m.value;t.instance.triggerOnChange(m.name,E)};m.addEventListener("blur",C),m.addEventListener("input",C)}return y.appendChild(m),g===-1?c.appendChild(y):c.insertBefore(y,c.children[g]),p(),y}function f(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-text-item"),g=x.length;x.forEach(y=>{let m=y.querySelector(".remove-item-btn");m||(m=document.createElement("button"),m.type="button",m.className="remove-item-btn px-2 py-1 rounded",m.style.cssText=`
|
|
23
23
|
color: var(--fb-error-color);
|
|
24
24
|
background-color: transparent;
|
|
25
25
|
transition: background-color var(--fb-transition-duration);
|
|
26
|
-
`,
|
|
26
|
+
`,m.innerHTML="\u2715",m.addEventListener("mouseenter",()=>{m.style.backgroundColor="var(--fb-background-hover-color)"}),m.addEventListener("mouseleave",()=>{m.style.backgroundColor="transparent"}),m.onclick=()=>{const E=Array.from(c.children).indexOf(y);c.children.length>d&&(i.splice(E,1),y.remove(),p(),h(),f())},y.appendChild(m));const C=g<=d;m.disabled=C,m.style.opacity=C?"0.5":"1",m.style.pointerEvents=C?"none":"auto"})}function h(){const x=n.querySelector(".add-text-btn");if(x&&x.remove(),!l.config.readonly&&i.length<u){const g=document.createElement("button");g.type="button",g.className="add-text-btn mt-2 px-3 py-1 rounded",g.style.cssText=`
|
|
27
27
|
color: var(--fb-primary-color);
|
|
28
28
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
29
29
|
background-color: transparent;
|
|
30
30
|
font-size: var(--fb-font-size);
|
|
31
31
|
transition: all var(--fb-transition-duration);
|
|
32
|
-
`,
|
|
32
|
+
`,g.textContent="+",g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{i.push(e.default||""),v(e.default||""),h(),f()},n.appendChild(g)}}i.forEach(x=>v(x)),h(),f();const b=document.createElement("p");b.className="mt-1",b.style.cssText=`
|
|
33
33
|
font-size: var(--fb-font-size-small);
|
|
34
34
|
color: var(--fb-text-secondary-color);
|
|
35
|
-
`,b.textContent=S(e),n.appendChild(b)}function
|
|
35
|
+
`,b.textContent=S(e),n.appendChild(b)}function Z(e,t,n){var o,a,r;const l=[],{scopeRoot:s,skipValidation:i}=n,d=(c,p)=>{var v,f;if(!c)return;const h=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(h);p?(c.classList.add("invalid"),c.title=p,b||(b=document.createElement("div"),b.id=h,b.className="error-message",b.style.cssText=`
|
|
36
36
|
color: var(--fb-error-color);
|
|
37
37
|
font-size: var(--fb-font-size-small);
|
|
38
38
|
margin-top: 0.25rem;
|
|
39
|
-
`,c.nextSibling?(v=c.parentNode)==null||v.insertBefore(b,c.nextSibling):(f=c.parentNode)==null||f.appendChild(b)),b.textContent=
|
|
39
|
+
`,c.nextSibling?(v=c.parentNode)==null||v.insertBefore(b,c.nextSibling):(f=c.parentNode)==null||f.appendChild(b)),b.textContent=p,b.style.display="block"):(c.classList.remove("invalid"),c.title="",b&&b.remove())},u=(c,p,v)=>{let f=!1;if(!i&&p){if(e.minLength!==void 0&&e.minLength!==null&&p.length<e.minLength)l.push(`${v}: minLength=${e.minLength}`),d(c,`minLength=${e.minLength}`),f=!0;else if(e.maxLength!==void 0&&e.maxLength!==null&&p.length>e.maxLength)l.push(`${v}: maxLength=${e.maxLength}`),d(c,`maxLength=${e.maxLength}`),f=!0;else if(e.pattern)try{new RegExp(e.pattern).test(p)||(l.push(`${v}: pattern mismatch`),d(c,"pattern mismatch"),f=!0)}catch(h){l.push(`${v}: invalid pattern`),d(c,"invalid pattern"),f=!0}}f||d(c,null)};if(e.multiple){const c=s.querySelectorAll(`[name^="${t}["]`),p=[],v=[];if(c.forEach((f,h)=>{var b;const x=(b=f==null?void 0:f.value)!=null?b:"";v.push(x),p.push(x===""?null:x),u(f,x,`${t}[${h}]`)}),!i){const f=(o=e.minCount)!=null?o:1,h=(a=e.maxCount)!=null?a:1/0,b=v.filter(x=>x.trim()!=="");e.required&&b.length===0&&l.push(`${t}: required`),b.length<f&&l.push(`${t}: minimum ${f} items required`),b.length>h&&l.push(`${t}: maximum ${h} items allowed`)}return{value:p,errors:l}}else{const c=s.querySelector(`[name$="${t}"]`),p=(r=c==null?void 0:c.value)!=null?r:"";return!i&&e.required&&p===""?(l.push(`${t}: required`),d(c,"required"),{value:null,errors:l}):(c&&u(c,p,t),{value:p===""?null:p,errors:l})}}function Q(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateTextField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(`[name^="${t}["]`);r.forEach((l,s)=>{s<n.length&&(l.value=n[s]!=null?String(n[s]):"",l.classList.remove("invalid"),l.title="")}),n.length!==r.length&&console.warn(`updateTextField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"]`);r&&(r.value=n!=null?String(n):"",r.classList.remove("invalid"),r.title="")}}function Te(e,t,n,o){const a=t.state,r=document.createElement("textarea");if(r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.rows=e.rows||4,r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const s=()=>{const i=r.value===""?null:r.value;t.instance.triggerOnChange(o,i)};r.addEventListener("blur",s),r.addEventListener("input",s)}n.appendChild(r);const l=document.createElement("p");l.className="text-xs text-gray-500 mt-1",l.textContent=S(e),n.appendChild(l)}function He(e,t,n,o){var a,r;const l=t.state,s=t.prefill[e.key]||[],i=Array.isArray(s)?[...s]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;i.length<d;)i.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function p(){c.querySelectorAll(".multiple-textarea-item").forEach((x,g)=>{const y=x.querySelector("textarea");y&&(y.name=`${o}[${g}]`)})}function v(x="",g=-1){const y=document.createElement("div");y.className="multiple-textarea-item";const m=document.createElement("textarea");if(m.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",m.placeholder=e.placeholder||"Enter text",m.rows=e.rows||4,m.value=x,m.readOnly=l.config.readonly,!l.config.readonly&&t.instance){const C=()=>{const E=m.value===""?null:m.value;t.instance.triggerOnChange(m.name,E)};m.addEventListener("blur",C),m.addEventListener("input",C)}return y.appendChild(m),g===-1?c.appendChild(y):c.insertBefore(y,c.children[g]),p(),y}function f(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-textarea-item"),g=x.length;x.forEach(y=>{let m=y.querySelector(".remove-item-btn");m||(m=document.createElement("button"),m.type="button",m.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",m.innerHTML="\u2715",m.onclick=()=>{const E=Array.from(c.children).indexOf(y);c.children.length>d&&(i.splice(E,1),y.remove(),p(),h(),f())},y.appendChild(m));const C=g<=d;m.disabled=C,m.style.opacity=C?"0.5":"1",m.style.pointerEvents=C?"none":"auto"})}function h(){const x=n.querySelector(".add-textarea-btn");if(x&&x.remove(),!l.config.readonly&&i.length<u){const g=document.createElement("button");g.type="button",g.className="add-textarea-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",g.textContent="+",g.onclick=()=>{i.push(e.default||""),v(e.default||""),h(),f()},n.appendChild(g)}}i.forEach(x=>v(x)),h(),f();const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=S(e),n.appendChild(b)}function Me(e,t,n){return Z(e,t,n)}function ze(e,t,n,o){Q(e,t,n,o)}function Ie(e,t,n,o){const a=t.state,r=document.createElement("input");if(r.type="number",r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",r.name=o,r.placeholder=e.placeholder||"0",e.min!==void 0&&(r.min=e.min.toString()),e.max!==void 0&&(r.max=e.max.toString()),e.step!==void 0&&(r.step=e.step.toString()),r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const s=()=>{const i=r.value?parseFloat(r.value):null;t.instance.triggerOnChange(o,i)};r.addEventListener("blur",s),r.addEventListener("input",s)}n.appendChild(r);const l=document.createElement("p");l.className="text-xs text-gray-500 mt-1",l.textContent=S(e),n.appendChild(l)}function Be(e,t,n,o){var a,r;const l=t.state,s=t.prefill[e.key]||[],i=Array.isArray(s)?[...s]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;i.length<d;)i.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function p(){c.querySelectorAll(".multiple-number-item").forEach((x,g)=>{const y=x.querySelector("input");y&&(y.name=`${o}[${g}]`)})}function v(x="",g=-1){const y=document.createElement("div");y.className="multiple-number-item flex items-center gap-2";const m=document.createElement("input");if(m.type="number",m.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",m.placeholder=e.placeholder||"0",e.min!==void 0&&(m.min=e.min.toString()),e.max!==void 0&&(m.max=e.max.toString()),e.step!==void 0&&(m.step=e.step.toString()),m.value=x.toString(),m.readOnly=l.config.readonly,!l.config.readonly&&t.instance){const C=()=>{const E=m.value?parseFloat(m.value):null;t.instance.triggerOnChange(m.name,E)};m.addEventListener("blur",C),m.addEventListener("input",C)}return y.appendChild(m),g===-1?c.appendChild(y):c.insertBefore(y,c.children[g]),p(),y}function f(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-number-item"),g=x.length;x.forEach(y=>{let m=y.querySelector(".remove-item-btn");m||(m=document.createElement("button"),m.type="button",m.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",m.innerHTML="\u2715",m.onclick=()=>{const E=Array.from(c.children).indexOf(y);c.children.length>d&&(i.splice(E,1),y.remove(),p(),h(),f())},y.appendChild(m));const C=g<=d;m.disabled=C,m.style.opacity=C?"0.5":"1",m.style.pointerEvents=C?"none":"auto"})}function h(){const x=n.querySelector(".add-number-btn");if(x&&x.remove(),!l.config.readonly&&i.length<u){const g=document.createElement("button");g.type="button",g.className="add-number-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",g.textContent="+",g.onclick=()=>{i.push(e.default||""),v(e.default||""),h(),f()},n.appendChild(g)}}i.forEach(x=>v(x)),h(),f();const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=S(e),n.appendChild(b)}function je(e,t,n){var o,a,r,l,s;const i=[],{scopeRoot:d,skipValidation:u}=n,c=(v,f)=>{var h,b;if(!v)return;const x=`error-${v.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(x);f?(v.classList.add("invalid"),v.title=f,g||(g=document.createElement("div"),g.id=x,g.className="error-message",g.style.cssText=`
|
|
40
40
|
color: var(--fb-error-color);
|
|
41
41
|
font-size: var(--fb-font-size-small);
|
|
42
42
|
margin-top: 0.25rem;
|
|
43
|
-
`,v.nextSibling?(
|
|
43
|
+
`,v.nextSibling?(h=v.parentNode)==null||h.insertBefore(g,v.nextSibling):(b=v.parentNode)==null||b.appendChild(g)),g.textContent=f,g.style.display="block"):(v.classList.remove("invalid"),v.title="",g&&g.remove())},p=(v,f,h)=>{let b=!1;!u&&e.min!==void 0&&e.min!==null&&f<e.min?(i.push(`${h}: < min=${e.min}`),c(v,`< min=${e.min}`),b=!0):!u&&e.max!==void 0&&e.max!==null&&f>e.max&&(i.push(`${h}: > max=${e.max}`),c(v,`> max=${e.max}`),b=!0),b||c(v,null)};if(e.multiple){const v=d.querySelectorAll(`[name^="${t}["]`),f=[];if(v.forEach((h,b)=>{var x,g,y;const m=(x=h==null?void 0:h.value)!=null?x:"";if(m===""){f.push(null),c(h,null);return}const C=parseFloat(m);if(!u&&!Number.isFinite(C)){i.push(`${t}[${b}]: not a number`),c(h,"not a number"),f.push(null);return}p(h,C,`${t}[${b}]`);const E=Number.isInteger((g=e.decimals)!=null?g:0)&&(y=e.decimals)!=null?y:0;f.push(Number(C.toFixed(E)))}),!u){const h=(o=e.minCount)!=null?o:1,b=(a=e.maxCount)!=null?a:1/0,x=f.filter(g=>g!==null);e.required&&x.length===0&&i.push(`${t}: required`),x.length<h&&i.push(`${t}: minimum ${h} items required`),x.length>b&&i.push(`${t}: maximum ${b} items allowed`)}return{value:f,errors:i}}else{const v=d.querySelector(`[name$="${t}"]`),f=(r=v==null?void 0:v.value)!=null?r:"";if(!u&&e.required&&f==="")return i.push(`${t}: required`),c(v,"required"),{value:null,errors:i};if(f==="")return c(v,null),{value:null,errors:i};const h=parseFloat(f);if(!u&&!Number.isFinite(h))return i.push(`${t}: not a number`),c(v,"not a number"),{value:null,errors:i};p(v,h,t);const b=Number.isInteger((l=e.decimals)!=null?l:0)&&(s=e.decimals)!=null?s:0;return{value:Number(h.toFixed(b)),errors:i}}}function Re(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateNumberField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(`[name^="${t}["]`);r.forEach((l,s)=>{s<n.length&&(l.value=n[s]!=null?String(n[s]):"",l.classList.remove("invalid"),l.title="")}),n.length!==r.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"]`);r&&(r.value=n!=null?String(n):"",r.classList.remove("invalid"),r.title="")}}function De(e,t,n,o){const a=t.state,r=document.createElement("select");if(r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",r.name=o,r.disabled=a.config.readonly,(e.options||[]).forEach(s=>{const i=document.createElement("option");i.value=s.value,i.textContent=s.label,(t.prefill[e.key]||e.default)===s.value&&(i.selected=!0),r.appendChild(i)}),!a.config.readonly&&t.instance){const s=()=>{t.instance.triggerOnChange(o,r.value)};r.addEventListener("change",s)}n.appendChild(r);const l=document.createElement("p");l.className="text-xs text-gray-500 mt-1",l.textContent=S(e),n.appendChild(l)}function Oe(e,t,n,o){var a,r,l,s;const i=t.state,d=t.prefill[e.key]||[],u=Array.isArray(d)?[...d]:[],c=(a=e.minCount)!=null?a:1,p=(r=e.maxCount)!=null?r:1/0;for(;u.length<c;)u.push(e.default||((s=(l=e.options)==null?void 0:l[0])==null?void 0:s.value)||"");const v=document.createElement("div");v.className="space-y-2",n.appendChild(v);function f(){v.querySelectorAll(".multiple-select-item").forEach((y,m)=>{const C=y.querySelector("select");C&&(C.name=`${o}[${m}]`)})}function h(y="",m=-1){const C=document.createElement("div");C.className="multiple-select-item flex items-center gap-2";const E=document.createElement("select");if(E.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",E.disabled=i.config.readonly,(e.options||[]).forEach($=>{const w=document.createElement("option");w.value=$.value,w.textContent=$.label,y===$.value&&(w.selected=!0),E.appendChild(w)}),!i.config.readonly&&t.instance){const $=()=>{t.instance.triggerOnChange(E.name,E.value)};E.addEventListener("change",$)}return C.appendChild(E),m===-1?v.appendChild(C):v.insertBefore(C,v.children[m]),f(),C}function b(){if(i.config.readonly)return;const y=v.querySelectorAll(".multiple-select-item"),m=y.length;y.forEach(C=>{let E=C.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",E.innerHTML="\u2715",E.onclick=()=>{const w=Array.from(v.children).indexOf(C);v.children.length>c&&(u.splice(w,1),C.remove(),f(),x(),b())},C.appendChild(E));const $=m<=c;E.disabled=$,E.style.opacity=$?"0.5":"1",E.style.pointerEvents=$?"none":"auto"})}function x(){const y=n.querySelector(".add-select-btn");if(y&&y.remove(),!i.config.readonly&&u.length<p){const m=document.createElement("button");m.type="button",m.className="add-select-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",m.textContent="+",m.onclick=()=>{var C,E;const $=e.default||((E=(C=e.options)==null?void 0:C[0])==null?void 0:E.value)||"";u.push($),h($),x(),b()},n.appendChild(m)}}u.forEach(y=>h(y)),x(),b();const g=document.createElement("p");g.className="text-xs text-gray-500 mt-1",g.textContent=S(e),n.appendChild(g)}function Ue(e,t,n){var o;const a=[],{scopeRoot:r,skipValidation:l}=n,s=(d,u)=>{var c,p;if(!d)return;const v=`error-${d.getAttribute("name")||Math.random().toString(36).substring(7)}`;let f=document.getElementById(v);u?(d.classList.add("invalid"),d.title=u,f||(f=document.createElement("div"),f.id=v,f.className="error-message",f.style.cssText=`
|
|
44
44
|
color: var(--fb-error-color);
|
|
45
45
|
font-size: var(--fb-font-size-small);
|
|
46
46
|
margin-top: 0.25rem;
|
|
47
|
-
`,d.nextSibling?(c=d.parentNode)==null||c.insertBefore(f,d.nextSibling):(
|
|
47
|
+
`,d.nextSibling?(c=d.parentNode)==null||c.insertBefore(f,d.nextSibling):(p=d.parentNode)==null||p.appendChild(f)),f.textContent=u,f.style.display="block"):(d.classList.remove("invalid"),d.title="",f&&f.remove())},i=(d,u,c,p)=>{var v,f;if(l)return;const h=u.filter(p),b="minCount"in c&&(v=c.minCount)!=null?v:1,x="maxCount"in c&&(f=c.maxCount)!=null?f:1/0;c.required&&h.length===0&&a.push(`${d}: required`),h.length<b&&a.push(`${d}: minimum ${b} items required`),h.length>x&&a.push(`${d}: maximum ${x} items allowed`)};if("multiple"in e&&e.multiple){const d=r.querySelectorAll(`[name^="${t}["]`),u=[];return d.forEach(c=>{var p;const v=(p=c==null?void 0:c.value)!=null?p:"";u.push(v),s(c,null)}),i(t,u,e,c=>c!==""),{value:u,errors:a}}else{const d=r.querySelector(`[name$="${t}"]`),u=(o=d==null?void 0:d.value)!=null?o:"";return!l&&e.required&&u===""?(a.push(`${t}: required`),s(d,"required"),{value:null,errors:a}):(s(d,null),{value:u===""?null:u,errors:a})}}function Pe(e,t,n,o){const{scopeRoot:a}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSelectField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(`[name^="${t}["]`);r.forEach((l,s)=>{s<n.length&&(l.value=n[s]!=null?String(n[s]):"",l.querySelectorAll("option").forEach(i=>{i.selected=i.value===String(n[s])}),l.classList.remove("invalid"),l.title="")}),n.length!==r.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${r.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"]`);r&&(r.value=n!=null?String(n):"",r.querySelectorAll("option").forEach(l=>{l.selected=l.value===String(n)}),r.classList.remove("invalid"),r.title="")}}function L(e,t){const n=t.config.locale||"en";return(t.config.translations[n]||t.config.translations.en)[e]||e}function Ve(e,t,n){const o=document.createElement("img");o.className="w-full h-full object-contain",o.alt=n||"Preview";const a=new FileReader;a.onload=r=>{var l;o.src=((l=r.target)==null?void 0:l.result)||""},a.readAsDataURL(t),e.appendChild(o)}function _e(e,t,n,o,a,r){const l=URL.createObjectURL(t);e.onclick=null;const s=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(s,e),s.innerHTML=`
|
|
48
48
|
<div class="relative group h-full">
|
|
49
49
|
<video class="w-full h-full object-contain" controls preload="auto" muted>
|
|
50
50
|
<source src="${l}" type="${n}">
|
|
@@ -59,28 +59,28 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
59
59
|
</button>
|
|
60
60
|
</div>
|
|
61
61
|
</div>
|
|
62
|
-
`,
|
|
62
|
+
`,We(s,o,a,r),s}function We(e,t,n,o){const a=e.querySelector(".change-file-btn");a&&(a.onclick=l=>{l.stopPropagation(),o!=null&&o.picker&&o.picker.click()});const r=e.querySelector(".delete-file-btn");r&&(r.onclick=l=>{l.stopPropagation(),Je(e,t,n,o)})}function Je(e,t,n,o){var a;n.resourceIndex.delete(t);const r=(a=e.parentElement)==null?void 0:a.querySelector('input[type="hidden"]');r&&(r.value=""),o!=null&&o.fileUploadHandler&&(e.onclick=o.fileUploadHandler),o!=null&&o.dragHandler&&V(e,o.dragHandler),e.innerHTML=`
|
|
63
63
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
64
64
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
65
65
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
66
66
|
</svg>
|
|
67
67
|
<div class="text-sm text-center">${L("clickDragText",n)}</div>
|
|
68
68
|
</div>
|
|
69
|
-
`}function
|
|
69
|
+
`}function Ye(e,t,n){const o=document.createElement("video");o.className="w-full h-full object-contain",o.controls=!0,o.preload="metadata",o.muted=!0;const a=document.createElement("source");a.src=t,a.type=n,o.appendChild(a),o.appendChild(document.createTextNode("Your browser does not support the video tag.")),e.appendChild(o)}function Ge(e,t,n){Ke(e,n,()=>{var o;n.resourceIndex.delete(t);const a=(o=e.parentElement)==null?void 0:o.querySelector('input[type="hidden"]');a&&(a.value=""),e.innerHTML=`
|
|
70
70
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
71
71
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
72
72
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
73
73
|
</svg>
|
|
74
74
|
<div class="text-sm text-center">${L("clickDragText",n)}</div>
|
|
75
75
|
</div>
|
|
76
|
-
`})}async function
|
|
76
|
+
`})}async function Xe(e,t,n,o,a,r,l){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?Ve(e,t.file,n):t.type&&t.type.startsWith("video/")?e=_e(e,t.file,t.type,o,r,l):e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400"><div class="text-2xl mb-2">\u{1F4C1}</div><div class="text-sm">${n}</div></div>`,!a&&!(t.type&&t.type.startsWith("video/"))&&Ge(e,o,r))}async function Ze(e,t,n,o,a){if(!a.config.getThumbnail){P(e,a);return}try{const r=await a.config.getThumbnail(t);if(r)if(H(e),o&&o.type&&o.type.startsWith("video/"))Ye(e,r,o.type);else{const l=document.createElement("img");l.className="w-full h-full object-contain",l.alt=n||"Preview",l.src=r,e.appendChild(l)}else P(e,a)}catch(r){console.error("Failed to get thumbnail:",r),e.innerHTML=`
|
|
77
77
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
78
78
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
79
79
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
80
80
|
</svg>
|
|
81
81
|
<div class="text-sm text-center">${n||"Preview unavailable"}</div>
|
|
82
82
|
</div>
|
|
83
|
-
`}}async function
|
|
83
|
+
`}}async function K(e,t,n,o={}){const{fileName:a="",isReadonly:r=!1,deps:l=null}=o;if(!r&&l&&(!l.picker||!l.fileUploadHandler||!l.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");H(e),r&&e.classList.add("cursor-pointer");const s=n.resourceIndex.get(t);s&&s.file&&s.file instanceof File?await Xe(e,s,a,t,r,n,l):await Ze(e,t,a,s,n)}async function U(e,t,n){var o,a;const r=t.resourceIndex.get(e),l=(r==null?void 0:r.name)||e.split("/").pop()||"file",s=l.toLowerCase().match(/\.psd$/),i=document.createElement("div");i.className=s?"space-y-2":"space-y-3";const d=document.createElement("div");s?d.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":d.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const u=!s&&(((o=r==null?void 0:r.type)==null?void 0:o.startsWith("image/"))||l.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),c=((a=r==null?void 0:r.type)==null?void 0:a.startsWith("video/"))||l.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(u)if(t.config.getThumbnail)try{const f=await t.config.getThumbnail(e);f?d.innerHTML=`<img src="${f}" alt="${l}" class="w-full h-auto">`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${l}</div></div></div>`}catch(f){console.warn("getThumbnail failed for",e,f),d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${l}</div></div></div>`}else d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${l}</div></div></div>`;else if(c)if(t.config.getThumbnail)try{const f=await t.config.getThumbnail(e);f?d.innerHTML=`
|
|
84
84
|
<div class="relative group">
|
|
85
85
|
<video class="w-full h-auto" controls preload="auto" muted>
|
|
86
86
|
<source src="${f}" type="${(r==null?void 0:r.type)||"video/mp4"}">
|
|
@@ -94,27 +94,27 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
94
94
|
</div>
|
|
95
95
|
</div>
|
|
96
96
|
</div>
|
|
97
|
-
`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`}catch(f){console.warn("getThumbnail failed for video",e,f),d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`}else d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`;else{const f=
|
|
97
|
+
`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`}catch(f){console.warn("getThumbnail failed for video",e,f),d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`}else d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`;else{const f=s?"\u{1F3A8}":"\u{1F4C1}",h=s?"PSD File":"Document";s?d.innerHTML=`
|
|
98
98
|
<div class="flex items-center space-x-3">
|
|
99
99
|
<div class="text-3xl text-gray-400">${f}</div>
|
|
100
100
|
<div class="flex-1 min-w-0">
|
|
101
101
|
<div class="text-sm font-medium text-gray-900 truncate">${l}</div>
|
|
102
|
-
<div class="text-xs text-gray-500">${
|
|
102
|
+
<div class="text-xs text-gray-500">${h}</div>
|
|
103
103
|
</div>
|
|
104
104
|
</div>
|
|
105
|
-
`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${f}</div><div class="text-sm">${l}</div><div class="text-xs text-gray-500 mt-1">${
|
|
105
|
+
`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${f}</div><div class="text-sm">${l}</div><div class="text-xs text-gray-500 mt-1">${h}</div></div></div>`}const p=document.createElement("p");p.className=s?"hidden":"text-sm font-medium text-gray-900 text-center",p.textContent=l;const v=document.createElement("button");return v.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",v.textContent=L("downloadButton",t),v.onclick=f=>{f.preventDefault(),f.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,l):et(e,l,t)},i.appendChild(d),i.appendChild(p),i.appendChild(v),i}function ee(e,t,n,o){H(e);const a=!e.classList.contains("grid");if((!t||t.length===0)&&a){const s=document.createElement("div");s.className="grid grid-cols-4 gap-3 mb-3";for(let u=0;u<4;u++){const c=document.createElement("div");c.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors";const p=document.createElementNS("http://www.w3.org/2000/svg","svg");p.setAttribute("class","w-12 h-12 text-gray-400"),p.setAttribute("fill","currentColor"),p.setAttribute("viewBox","0 0 24 24");const v=document.createElementNS("http://www.w3.org/2000/svg","path");v.setAttribute("d","M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"),p.appendChild(v),c.appendChild(p),c.onclick=()=>{let f=e.parentElement;for(;f&&!f.classList.contains("space-y-2");)f=f.parentElement;!f&&e.classList.contains("space-y-2")&&(f=e);const h=f==null?void 0:f.querySelector('input[type="file"]');h&&h.click()},s.appendChild(c)}const i=document.createElement("div");i.className="text-center text-xs text-gray-600";const d=document.createElement("span");d.className="underline cursor-pointer",d.textContent=L("uploadText",n),d.onclick=u=>{u.stopPropagation();let c=e.parentElement;for(;c&&!c.classList.contains("space-y-2");)c=c.parentElement;!c&&e.classList.contains("space-y-2")&&(c=e);const p=c==null?void 0:c.querySelector('input[type="file"]');p&&p.click()},i.appendChild(d),i.appendChild(document.createTextNode(` ${L("dragDropText",n)}`)),e.appendChild(s),e.appendChild(i);return}e.className="files-list grid grid-cols-4 gap-3 mt-2";const r=t?t.length:0,l=(Math.floor(r/4)+1)*4;for(let s=0;s<l;s++){const i=document.createElement("div");if(t&&s<t.length){const d=t[s],u=n.resourceIndex.get(d);if(i.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",i.dataset.resourceId=d,Qe(i,d,u,n).catch(c=>{console.error("Failed to render thumbnail:",c),i.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
106
106
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
107
107
|
<div class="text-xs">Preview error</div>
|
|
108
|
-
</div>`}),o){const c=document.createElement("div");c.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const
|
|
108
|
+
</div>`}),o){const c=document.createElement("div");c.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const p=document.createElement("button");p.className="bg-red-600 text-white px-2 py-1 rounded text-xs",p.textContent=L("removeElement",n),p.onclick=v=>{v.stopPropagation(),o(d)},c.appendChild(p),i.appendChild(c)}}else i.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded-lg flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors",i.innerHTML='<svg class="w-12 h-12 text-gray-400" fill="currentColor" viewBox="0 0 24 24"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>',i.onclick=()=>{let d=e.parentElement;for(;d&&!d.classList.contains("space-y-2");)d=d.parentElement;!d&&e.classList.contains("space-y-2")&&(d=e);const u=d==null?void 0:d.querySelector('input[type="file"]');u&&u.click()};e.appendChild(i)}}function te(e,t="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
109
109
|
<svg class="${t} text-red-400" fill="currentColor" viewBox="0 0 24 24">
|
|
110
110
|
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
|
|
111
111
|
</svg>
|
|
112
112
|
<div class="text-xs mt-1 text-red-600">Preview error</div>
|
|
113
|
-
</div>`}async function
|
|
113
|
+
</div>`}async function Qe(e,t,n,o){var a,r;if(n&&(a=n.type)!=null&&a.startsWith("image/"))if(n.file&&n.file instanceof File){const l=document.createElement("img");l.className="w-full h-full object-contain",l.alt=n.name;const s=new FileReader;s.onload=i=>{var d;l.src=((d=i.target)==null?void 0:d.result)||""},s.readAsDataURL(n.file),e.appendChild(l)}else if(o.config.getThumbnail)try{const l=await o.config.getThumbnail(t);if(l){const s=document.createElement("img");s.className="w-full h-full object-contain",s.alt=n.name,s.src=l,e.appendChild(s)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
114
114
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
115
115
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
116
116
|
</svg>
|
|
117
|
-
</div>`}catch(l){const
|
|
117
|
+
</div>`}catch(l){const s=l instanceof Error?l:new Error(String(l));o.config.onThumbnailError&&o.config.onThumbnailError(s,t),te(e)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
118
118
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
119
119
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
120
120
|
</svg>
|
|
@@ -149,7 +149,7 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
149
149
|
<path d="M8 5v14l11-7z"/>
|
|
150
150
|
</svg>
|
|
151
151
|
<div class="text-xs mt-1">${(n==null?void 0:n.name)||"Video"}</div>
|
|
152
|
-
</div>`}catch(l){const
|
|
152
|
+
</div>`}catch(l){const s=l instanceof Error?l:new Error(String(l));o.config.onThumbnailError&&o.config.onThumbnailError(s,t),te(e,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
153
153
|
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
154
154
|
<path d="M8 5v14l11-7z"/>
|
|
155
155
|
</svg>
|
|
@@ -157,14 +157,14 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
157
157
|
</div>`;else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
158
158
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
159
159
|
<div class="text-xs">${(n==null?void 0:n.name)||"File"}</div>
|
|
160
|
-
</div>`}function
|
|
160
|
+
</div>`}function P(e,t){e.innerHTML=`
|
|
161
161
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
162
162
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
163
163
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
164
164
|
</svg>
|
|
165
165
|
<div class="text-sm text-center">${L("clickDragText",t)}</div>
|
|
166
166
|
</div>
|
|
167
|
-
`}async function Q(e,t,n,o,a=null,r){var l,i;let s;if(o.config.uploadFile)try{if(s=await o.config.uploadFile(e),typeof s!="string")throw new Error("Upload handler must return a string resource ID")}catch(u){const c=u instanceof Error?u:new Error(String(u));throw o.config.onUploadError&&o.config.onUploadError(c,e),new Error(`File upload failed: ${c.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(s,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let d=(l=t.parentElement)==null?void 0:l.querySelector('input[type="hidden"]');d||(d=document.createElement("input"),d.type="hidden",d.name=n,(i=t.parentElement)==null||i.appendChild(d)),d.value=s,X(t,s,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),r&&!o.config.readonly&&r.triggerOnChange(n,s)}function U(e,t){e.addEventListener("dragover",n=>{n.preventDefault(),e.classList.add("border-blue-500","bg-blue-50")}),e.addEventListener("dragleave",n=>{n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50")}),e.addEventListener("drop",n=>{var o;n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50"),(o=n.dataTransfer)!=null&&o.files&&t(n.dataTransfer.files)})}function Ze(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const a=document.createElement("div");a.className="delete-overlay absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const r=document.createElement("button");r.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",r.textContent=L("removeElement",t),r.onclick=l=>{l.stopPropagation(),n()},a.appendChild(r),e.appendChild(a)}async function ee(e,t){if(t.config.uploadFile)try{const n=await t.config.uploadFile(e);if(typeof n!="string")throw new Error("Upload handler must return a string resource ID");return n}catch(n){const o=n instanceof Error?n:new Error(String(n));throw t.config.onUploadError&&t.config.onUploadError(o,e),new Error(`File upload failed: ${o.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()")}async function Ke(e,t,n){try{let o=null;if(n.config.getDownloadUrl?o=n.config.getDownloadUrl(e):n.config.getThumbnail&&(o=await n.config.getThumbnail(e)),o){const a=o.startsWith("http")?o:new URL(o,window.location.href).href,r=await fetch(a);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const l=await r.blob();Qe(l,t)}else throw new Error("No download URL available for resource")}catch(o){const a=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(a,e,t),console.error(`File download failed for ${t}:`,a),a}}function Qe(e,t){try{const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(n)},100)}catch(n){throw new Error(`Blob download failed: ${n.message}`)}}function te(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",r=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let l="application/octet-stream";r&&(["jpg","jpeg","png","gif","webp"].includes(r)?l=`image/${r==="jpg"?"jpeg":r}`:["mp4","webm","mov","avi"].includes(r)&&(l=`video/${r==="mov"?"quicktime":r}`)),t.resourceIndex.set(n,{name:a,type:l,size:0,uploadedAt:new Date,file:void 0})}})}function et(e,t,n,o,a,r){var l;if(!a.resourceIndex.has(e)){const s=e.split("/").pop()||"file",d=(l=s.split(".").pop())==null?void 0:l.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),a.resourceIndex.set(e,{name:s,type:u,size:0,uploadedAt:new Date,file:void 0})}X(t,e,a,{fileName:e,isReadonly:!1,deps:r}).catch(console.error);const i=document.createElement("input");i.type="hidden",i.name=n,i.value=e,o.appendChild(i)}function ne(e,t,n,o,a,r){U(e,async l=>{const i=Array.from(l);for(const s of i){const d=await ee(s,n);n.resourceIndex.set(d,{name:s.name,type:s.type,size:s.size,uploadedAt:new Date,file:void 0}),t.push(d)}o(),r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)})}function re(e,t,n,o,a,r){e.onchange=async()=>{if(e.files)for(const l of Array.from(e.files)){const i=await ee(l,n);n.resourceIndex.set(i,{name:l.name,type:l.type,size:l.size,uploadedAt:new Date,file:void 0}),t.push(i)}o(),e.value="",r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)}}function tt(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=t.prefill[e.key];if(l)D(l,r).then(i=>{n.appendChild(i)}).catch(i=>{console.error("Failed to render file preview:",i);const s=document.createElement("div");s.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",s.innerHTML='<div class="text-center">Preview unavailable</div>',n.appendChild(s)});else{const i=document.createElement("div");i.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",i.innerHTML=`<div class="text-center">${L("noFileSelected",r)}</div>`,n.appendChild(i)}}else{const l=document.createElement("div");l.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(y=>`.${y}`).join(","))||"");const s=document.createElement("div");s.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const d=t.prefill[e.key],u=()=>i.click(),c=y=>{if(y.length>0){const b={picker:i,fileUploadHandler:u,dragHandler:c};Q(y[0],s,o,r,b,t.instance)}};d?et(d,s,o,l,r,{picker:i,fileUploadHandler:u,dragHandler:c}):O(s,r),s.onclick=u,U(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const y={picker:i,fileUploadHandler:u,dragHandler:c};Q(i.files[0],s,o,r,y,t.instance)}},l.appendChild(s),l.appendChild(i);const m=document.createElement("p");m.className="text-xs text-gray-600 mt-2 text-center",m.innerHTML=`<span class="underline cursor-pointer">${L("uploadText",r)}</span> ${L("dragDropTextSingle",r)}`;const v=m.querySelector("span");v&&(v.onclick=()=>i.click()),l.appendChild(m);const f=document.createElement("p");f.className="text-xs text-gray-500 mt-1 text-center",f.textContent=S(e),l.appendChild(f),n.appendChild(l)}}function nt(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=document.createElement("div");l.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(s=>{D(s,r).then(d=>{l.appendChild(d)}).catch(d=>{console.error("Failed to render file preview:",d)})}):l.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",r)}</div></div>`,n.appendChild(l)}else{let l=function(){Z(u,c,r,v=>{const f=c.indexOf(v);f>-1&&c.splice(f,1),l()})};const i=document.createElement("div");i.className="space-y-2";const s=document.createElement("input");s.type="file",s.name=o,s.multiple=!0,s.style.display="none",e.accept&&(s.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(v=>`.${v}`).join(","))||"");const d=document.createElement("div");d.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const u=document.createElement("div");u.className="files-list";const c=t.prefill[e.key]||[];te(c,r),l(),ne(d,c,r,l,o,t.instance),re(s,c,r,l,o,t.instance),d.appendChild(u),i.appendChild(d),i.appendChild(s);const m=document.createElement("p");m.className="text-xs text-gray-500 mt-1 text-center",m.textContent=S(e),i.appendChild(m),n.appendChild(i)}}function rt(e,t,n,o){var a,r,l;const i=t.state,s=(a=e.minCount)!=null?a:0,d=(r=e.maxCount)!=null?r:1/0;if(i.config.readonly){const u=document.createElement("div");u.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(m=>{D(m,i).then(v=>{u.appendChild(v)}).catch(v=>{console.error("Failed to render file preview:",v)})}):u.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",i)}</div></div>`,n.appendChild(u)}else{const u=document.createElement("div");u.className="space-y-2";const c=document.createElement("input");c.type="file",c.name=o,c.multiple=!0,c.style.display="none",e.accept&&(c.accept=typeof e.accept=="string"?e.accept:((l=e.accept.extensions)==null?void 0:l.map(y=>`.${y}`).join(","))||"");const m=document.createElement("div");m.className="files-list space-y-2",u.appendChild(c),u.appendChild(m);const v=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];te(v,i);const f=()=>{Z(m,v,i,g=>{v.splice(v.indexOf(g),1),f()});const y=document.createElement("div");y.className="text-xs text-gray-500 mt-2 file-count-info";const b=`${v.length} file${v.length!==1?"s":""}`,x=s>0||d<1/0?` (${s}-${d} allowed)`:"";y.textContent=b+x;const h=u.querySelector(".file-count-info");h&&h.remove(),u.appendChild(y)};ne(m,v,i,f,o,t.instance),re(c,v,i,f,o,t.instance),f(),n.appendChild(u)}}function oe(e,t,n){var o;const a=[],{scopeRoot:r,skipValidation:l,path:i}=n,s=e.type==="files"||"multiple"in e&&!!e.multiple,d=(u,c,m)=>{var v,f;if(l)return;const y="minCount"in m&&(v=m.minCount)!=null?v:0,b="maxCount"in m&&(f=m.maxCount)!=null?f:1/0;m.required&&c.length===0&&a.push(`${u}: required`),c.length<y&&a.push(`${u}: minimum ${y} files required`),c.length>b&&a.push(`${u}: maximum ${b} files allowed`)};if(s){const u=q(i,t),c=r.querySelector(`input[type="file"][name="${u}"]`),m=c==null?void 0:c.closest(".space-y-2"),v=(m==null?void 0:m.querySelector(".files-list"))||null,f=[];return v&&v.querySelectorAll(".resource-pill").forEach(y=>{const b=y.dataset.resourceId;b&&f.push(b)}),d(t,f,e),{value:f,errors:a}}else{const u=r.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=u==null?void 0:u.value)!=null?o:"";return!l&&e.required&&c===""?(a.push(`${t}: required`),{value:null,errors:a}):{value:c||null,errors:a}}}function le(e,t,n,o){var a;const{scopeRoot:r,state:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(i=>{var s;if(i&&typeof i=="string"&&!l.resourceIndex.has(i)){const d=i.split("/").pop()||"file",u=(s=d.split(".").pop())==null?void 0:s.toLowerCase();let c="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?c=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(c=`video/${u==="mov"?"quicktime":u}`)),l.resourceIndex.set(i,{name:d,type:c,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const i=r.querySelector(`input[name="${t}"][type="hidden"]`);if(!i){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(i.value=n!=null?String(n):"",n&&typeof n=="string"){if(!l.resourceIndex.has(n)){const s=n.split("/").pop()||"file",d=(a=s.split(".").pop())==null?void 0:a.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),l.resourceIndex.set(n,{name:s,type:u,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function A(e){return e?e.toUpperCase():"#000000"}function P(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function ae(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],o=e[3];return`#${t}${t}${n}${n}${o}${o}`.toUpperCase()}return e.toUpperCase()}function ie(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=A(e),o=document.createElement("div");o.style.cssText=`
|
|
167
|
+
`}async function ne(e,t,n,o,a=null,r){var l,s;let i;if(o.config.uploadFile)try{if(i=await o.config.uploadFile(e),typeof i!="string")throw new Error("Upload handler must return a string resource ID")}catch(u){const c=u instanceof Error?u:new Error(String(u));throw o.config.onUploadError&&o.config.onUploadError(c,e),new Error(`File upload failed: ${c.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(i,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let d=(l=t.parentElement)==null?void 0:l.querySelector('input[type="hidden"]');d||(d=document.createElement("input"),d.type="hidden",d.name=n,(s=t.parentElement)==null||s.appendChild(d)),d.value=i,K(t,i,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),r&&!o.config.readonly&&r.triggerOnChange(n,i)}function V(e,t){e.addEventListener("dragover",n=>{n.preventDefault(),e.classList.add("border-blue-500","bg-blue-50")}),e.addEventListener("dragleave",n=>{n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50")}),e.addEventListener("drop",n=>{var o;n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50"),(o=n.dataTransfer)!=null&&o.files&&t(n.dataTransfer.files)})}function Ke(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const a=document.createElement("div");a.className="delete-overlay absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const r=document.createElement("button");r.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",r.textContent=L("removeElement",t),r.onclick=l=>{l.stopPropagation(),n()},a.appendChild(r),e.appendChild(a)}async function re(e,t){if(t.config.uploadFile)try{const n=await t.config.uploadFile(e);if(typeof n!="string")throw new Error("Upload handler must return a string resource ID");return n}catch(n){const o=n instanceof Error?n:new Error(String(n));throw t.config.onUploadError&&t.config.onUploadError(o,e),new Error(`File upload failed: ${o.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()")}async function et(e,t,n){try{let o=null;if(n.config.getDownloadUrl?o=n.config.getDownloadUrl(e):n.config.getThumbnail&&(o=await n.config.getThumbnail(e)),o){const a=o.startsWith("http")?o:new URL(o,window.location.href).href,r=await fetch(a);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const l=await r.blob();tt(l,t)}else throw new Error("No download URL available for resource")}catch(o){const a=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(a,e,t),console.error(`File download failed for ${t}:`,a),a}}function tt(e,t){try{const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(n)},100)}catch(n){throw new Error(`Blob download failed: ${n.message}`)}}function oe(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",r=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let l="application/octet-stream";r&&(["jpg","jpeg","png","gif","webp"].includes(r)?l=`image/${r==="jpg"?"jpeg":r}`:["mp4","webm","mov","avi"].includes(r)&&(l=`video/${r==="mov"?"quicktime":r}`)),t.resourceIndex.set(n,{name:a,type:l,size:0,uploadedAt:new Date,file:void 0})}})}function nt(e,t,n,o,a,r){var l;if(!a.resourceIndex.has(e)){const i=e.split("/").pop()||"file",d=(l=i.split(".").pop())==null?void 0:l.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),a.resourceIndex.set(e,{name:i,type:u,size:0,uploadedAt:new Date,file:void 0})}K(t,e,a,{fileName:e,isReadonly:!1,deps:r}).catch(console.error);const s=document.createElement("input");s.type="hidden",s.name=n,s.value=e,o.appendChild(s)}function le(e,t,n,o,a,r){V(e,async l=>{const s=Array.from(l);for(const i of s){const d=await re(i,n);n.resourceIndex.set(d,{name:i.name,type:i.type,size:i.size,uploadedAt:new Date,file:void 0}),t.push(d)}o(),r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)})}function ae(e,t,n,o,a,r){e.onchange=async()=>{if(e.files)for(const l of Array.from(e.files)){const s=await re(l,n);n.resourceIndex.set(s,{name:l.name,type:l.type,size:l.size,uploadedAt:new Date,file:void 0}),t.push(s)}o(),e.value="",r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)}}function rt(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=t.prefill[e.key];if(l)U(l,r).then(s=>{n.appendChild(s)}).catch(s=>{console.error("Failed to render file preview:",s);const i=document.createElement("div");i.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",i.innerHTML='<div class="text-center">Preview unavailable</div>',n.appendChild(i)});else{const s=document.createElement("div");s.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",s.innerHTML=`<div class="text-center">${L("noFileSelected",r)}</div>`,n.appendChild(s)}}else{const l=document.createElement("div");l.className="space-y-2";const s=document.createElement("input");s.type="file",s.name=o,s.style.display="none",e.accept&&(s.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(h=>`.${h}`).join(","))||"");const i=document.createElement("div");i.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const d=t.prefill[e.key],u=()=>s.click(),c=h=>{if(h.length>0){const b={picker:s,fileUploadHandler:u,dragHandler:c};ne(h[0],i,o,r,b,t.instance)}};d?nt(d,i,o,l,r,{picker:s,fileUploadHandler:u,dragHandler:c}):P(i,r),i.onclick=u,V(i,c),s.onchange=()=>{if(s.files&&s.files.length>0){const h={picker:s,fileUploadHandler:u,dragHandler:c};ne(s.files[0],i,o,r,h,t.instance)}},l.appendChild(i),l.appendChild(s);const p=document.createElement("p");p.className="text-xs text-gray-600 mt-2 text-center",p.innerHTML=`<span class="underline cursor-pointer">${L("uploadText",r)}</span> ${L("dragDropTextSingle",r)}`;const v=p.querySelector("span");v&&(v.onclick=()=>s.click()),l.appendChild(p);const f=document.createElement("p");f.className="text-xs text-gray-500 mt-1 text-center",f.textContent=S(e),l.appendChild(f),n.appendChild(l)}}function ot(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=document.createElement("div");l.className="space-y-4";const s=t.prefill[e.key]||[];s.length>0?s.forEach(i=>{U(i,r).then(d=>{l.appendChild(d)}).catch(d=>{console.error("Failed to render file preview:",d)})}):l.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",r)}</div></div>`,n.appendChild(l)}else{let l=function(){ee(u,c,r,v=>{const f=c.indexOf(v);f>-1&&c.splice(f,1),l()})};const s=document.createElement("div");s.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.multiple=!0,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(v=>`.${v}`).join(","))||"");const d=document.createElement("div");d.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const u=document.createElement("div");u.className="files-list";const c=t.prefill[e.key]||[];oe(c,r),l(),le(d,c,r,l,o,t.instance),ae(i,c,r,l,o,t.instance),d.appendChild(u),s.appendChild(d),s.appendChild(i);const p=document.createElement("p");p.className="text-xs text-gray-500 mt-1 text-center",p.textContent=S(e),s.appendChild(p),n.appendChild(s)}}function lt(e,t,n,o){var a,r,l;const s=t.state,i=(a=e.minCount)!=null?a:0,d=(r=e.maxCount)!=null?r:1/0;if(s.config.readonly){const u=document.createElement("div");u.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(p=>{U(p,s).then(v=>{u.appendChild(v)}).catch(v=>{console.error("Failed to render file preview:",v)})}):u.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",s)}</div></div>`,n.appendChild(u)}else{const u=document.createElement("div");u.className="space-y-2";const c=document.createElement("input");c.type="file",c.name=o,c.multiple=!0,c.style.display="none",e.accept&&(c.accept=typeof e.accept=="string"?e.accept:((l=e.accept.extensions)==null?void 0:l.map(h=>`.${h}`).join(","))||"");const p=document.createElement("div");p.className="files-list space-y-2",u.appendChild(c),u.appendChild(p);const v=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];oe(v,s);const f=()=>{ee(p,v,s,y=>{v.splice(v.indexOf(y),1),f()});const h=document.createElement("div");h.className="text-xs text-gray-500 mt-2 file-count-info";const b=`${v.length} file${v.length!==1?"s":""}`,x=i>0||d<1/0?` (${i}-${d} allowed)`:"";h.textContent=b+x;const g=u.querySelector(".file-count-info");g&&g.remove(),u.appendChild(h)};le(p,v,s,f,o,t.instance),ae(c,v,s,f,o,t.instance),f(),n.appendChild(u)}}function ie(e,t,n){var o;const a=[],{scopeRoot:r,skipValidation:l,path:s}=n,i=e.type==="files"||"multiple"in e&&!!e.multiple,d=(u,c,p)=>{var v,f;if(l)return;const h="minCount"in p&&(v=p.minCount)!=null?v:0,b="maxCount"in p&&(f=p.maxCount)!=null?f:1/0;p.required&&c.length===0&&a.push(`${u}: required`),c.length<h&&a.push(`${u}: minimum ${h} files required`),c.length>b&&a.push(`${u}: maximum ${b} files allowed`)};if(i){const u=q(s,t),c=r.querySelector(`input[type="file"][name="${u}"]`),p=c==null?void 0:c.closest(".space-y-2"),v=(p==null?void 0:p.querySelector(".files-list"))||null,f=[];return v&&v.querySelectorAll(".resource-pill").forEach(h=>{const b=h.dataset.resourceId;b&&f.push(b)}),d(t,f,e),{value:f,errors:a}}else{const u=r.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=u==null?void 0:u.value)!=null?o:"";return!l&&e.required&&c===""?(a.push(`${t}: required`),{value:null,errors:a}):{value:c||null,errors:a}}}function se(e,t,n,o){var a;const{scopeRoot:r,state:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(s=>{var i;if(s&&typeof s=="string"&&!l.resourceIndex.has(s)){const d=s.split("/").pop()||"file",u=(i=d.split(".").pop())==null?void 0:i.toLowerCase();let c="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?c=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(c=`video/${u==="mov"?"quicktime":u}`)),l.resourceIndex.set(s,{name:d,type:c,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const s=r.querySelector(`input[name="${t}"][type="hidden"]`);if(!s){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(s.value=n!=null?String(n):"",n&&typeof n=="string"){if(!l.resourceIndex.has(n)){const i=n.split("/").pop()||"file",d=(a=i.split(".").pop())==null?void 0:a.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),l.resourceIndex.set(n,{name:i,type:u,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function T(e){return e?e.toUpperCase():"#000000"}function _(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function ce(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],o=e[3];return`#${t}${t}${n}${n}${o}${o}`.toUpperCase()}return e.toUpperCase()}function de(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=T(e),o=document.createElement("div");o.style.cssText=`
|
|
168
168
|
width: 32px;
|
|
169
169
|
height: 32px;
|
|
170
170
|
border-radius: var(--fb-border-radius);
|
|
@@ -174,7 +174,7 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
174
174
|
font-size: var(--fb-font-size);
|
|
175
175
|
color: var(--fb-text-color);
|
|
176
176
|
font-family: var(--fb-font-family-mono, monospace);
|
|
177
|
-
`,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function
|
|
177
|
+
`,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function ue(e,t,n){const o=T(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
|
|
178
178
|
display: flex;
|
|
179
179
|
align-items: center;
|
|
180
180
|
gap: 8px;
|
|
@@ -197,31 +197,31 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
197
197
|
font-size: var(--fb-font-size);
|
|
198
198
|
font-family: var(--fb-font-family-mono, monospace);
|
|
199
199
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
200
|
-
`;const
|
|
200
|
+
`;const s=document.createElement("input");return s.type="color",s.className="colour-picker-hidden",s.value=o.toLowerCase(),s.style.cssText=`
|
|
201
201
|
position: absolute;
|
|
202
202
|
opacity: 0;
|
|
203
203
|
pointer-events: none;
|
|
204
|
-
`,l.addEventListener("input",()=>{const
|
|
204
|
+
`,l.addEventListener("input",()=>{const i=l.value.trim();if(_(i)){const d=ce(i);r.style.backgroundColor=d,s.value=d.toLowerCase(),l.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,d)}else l.classList.add("invalid")}),l.addEventListener("blur",()=>{const i=l.value.trim();if(_(i)){const d=ce(i);l.value=d,r.style.backgroundColor=d,s.value=d.toLowerCase(),l.classList.remove("invalid")}}),s.addEventListener("change",()=>{const i=T(s.value);l.value=i,r.style.backgroundColor=i,n.instance&&n.instance.triggerOnChange(t,i)}),r.addEventListener("click",()=>{s.click()}),r.addEventListener("mouseenter",()=>{r.style.borderColor="var(--fb-border-hover-color)"}),r.addEventListener("mouseleave",()=>{r.style.borderColor="var(--fb-border-color)"}),l.addEventListener("focus",()=>{l.style.borderColor="var(--fb-border-focus-color)",l.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",l.style.outlineOffset="0"}),l.addEventListener("blur",()=>{l.style.borderColor="var(--fb-border-color)",l.style.outline="none"}),l.addEventListener("mouseenter",()=>{document.activeElement!==l&&(l.style.borderColor="var(--fb-border-hover-color)")}),l.addEventListener("mouseleave",()=>{document.activeElement!==l&&(l.style.borderColor="var(--fb-border-color)")}),a.appendChild(r),a.appendChild(l),a.appendChild(s),a}function at(e,t,n,o){const a=t.state,r=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const s=de(r);n.appendChild(s)}else{const s=ue(r,o,t);n.appendChild(s)}const l=document.createElement("p");l.className="mt-1",l.style.cssText=`
|
|
205
205
|
font-size: var(--fb-font-size-small);
|
|
206
206
|
color: var(--fb-text-secondary-color);
|
|
207
|
-
`,l.textContent=S(e),n.appendChild(l)}function
|
|
207
|
+
`,l.textContent=S(e),n.appendChild(l)}function it(e,t,n,o){var a,r;const l=t.state,s=t.prefill[e.key]||[],i=Array.isArray(s)?[...s]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;i.length<d;)i.push(e.default||"#000000");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function p(){c.querySelectorAll(".multiple-colour-item").forEach((x,g)=>{const y=x.querySelector("input");y&&(y.name=`${o}[${g}]`)})}function v(x="#000000",g=-1){const y=document.createElement("div");if(y.className="multiple-colour-item flex items-center gap-2",l.config.readonly){const m=de(x);for(;m.firstChild;)y.appendChild(m.firstChild)}else{const m=`${o}[${c.children.length}]`,C=ue(x,m,t);C.style.flex="1",y.appendChild(C)}return g===-1?c.appendChild(y):c.insertBefore(y,c.children[g]),p(),y}function f(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-colour-item"),g=x.length;x.forEach(y=>{let m=y.querySelector(".remove-item-btn");m||(m=document.createElement("button"),m.type="button",m.className="remove-item-btn px-2 py-1 rounded",m.style.cssText=`
|
|
208
208
|
color: var(--fb-error-color);
|
|
209
209
|
background-color: transparent;
|
|
210
210
|
transition: background-color var(--fb-transition-duration);
|
|
211
|
-
`,
|
|
211
|
+
`,m.innerHTML="\u2715",m.addEventListener("mouseenter",()=>{m.style.backgroundColor="var(--fb-background-hover-color)"}),m.addEventListener("mouseleave",()=>{m.style.backgroundColor="transparent"}),m.onclick=()=>{const E=Array.from(c.children).indexOf(y);c.children.length>d&&(i.splice(E,1),y.remove(),p(),h(),f())},y.appendChild(m));const C=g<=d;m.disabled=C,m.style.opacity=C?"0.5":"1",m.style.pointerEvents=C?"none":"auto"})}function h(){const x=n.querySelector(".add-colour-btn");if(x&&x.remove(),!l.config.readonly&&i.length<u){const g=document.createElement("button");g.type="button",g.className="add-colour-btn mt-2 px-3 py-1 rounded",g.style.cssText=`
|
|
212
212
|
color: var(--fb-primary-color);
|
|
213
213
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
214
214
|
background-color: transparent;
|
|
215
215
|
font-size: var(--fb-font-size);
|
|
216
216
|
transition: all var(--fb-transition-duration);
|
|
217
|
-
`,
|
|
217
|
+
`,g.textContent="+",g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{const y=e.default||"#000000";i.push(y),v(y),h(),f()},n.appendChild(g)}}i.forEach(x=>v(x)),h(),f();const b=document.createElement("p");b.className="mt-1",b.style.cssText=`
|
|
218
218
|
font-size: var(--fb-font-size-small);
|
|
219
219
|
color: var(--fb-text-secondary-color);
|
|
220
|
-
`,b.textContent=S(e),n.appendChild(b)}function
|
|
220
|
+
`,b.textContent=S(e),n.appendChild(b)}function st(e,t,n){var o,a,r;const l=[],{scopeRoot:s,skipValidation:i}=n,d=(c,p)=>{var v,f;if(!c)return;const h=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(h);p?(c.classList.add("invalid"),c.title=p,b||(b=document.createElement("div"),b.id=h,b.className="error-message",b.style.cssText=`
|
|
221
221
|
color: var(--fb-error-color);
|
|
222
222
|
font-size: var(--fb-font-size-small);
|
|
223
223
|
margin-top: 0.25rem;
|
|
224
|
-
`,c.nextSibling?(v=c.parentNode)==null||v.insertBefore(b,c.nextSibling):(f=c.parentNode)==null||f.appendChild(b)),b.textContent=
|
|
224
|
+
`,c.nextSibling?(v=c.parentNode)==null||v.insertBefore(b,c.nextSibling):(f=c.parentNode)==null||f.appendChild(b)),b.textContent=p,b.style.display="block"):(c.classList.remove("invalid"),c.title="",b&&b.remove())},u=(c,p,v)=>{if(!p)return!i&&e.required?(l.push(`${v}: required`),d(c,"required"),""):(d(c,null),"");const f=T(p);return!i&&!_(f)?(l.push(`${v}: invalid hex colour format`),d(c,"invalid hex colour format"),p):(d(c,null),f)};if(e.multiple){const c=s.querySelectorAll(`[name^="${t}["].colour-hex-input`),p=[];if(c.forEach((v,f)=>{var h;const b=(h=v==null?void 0:v.value)!=null?h:"",x=u(v,b,`${t}[${f}]`);p.push(x)}),!i){const v=(o=e.minCount)!=null?o:1,f=(a=e.maxCount)!=null?a:1/0,h=p.filter(b=>b!=="");e.required&&h.length===0&&l.push(`${t}: required`),h.length<v&&l.push(`${t}: minimum ${v} items required`),h.length>f&&l.push(`${t}: maximum ${f} items allowed`)}return{value:p,errors:l}}else{const c=s.querySelector(`[name="${t}"].colour-hex-input`),p=(r=c==null?void 0:c.value)!=null?r:"";return!i&&e.required&&p===""?(l.push(`${t}: required`),d(c,"required"),{value:"",errors:l}):{value:u(c,p,t),errors:l}}}function ct(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateColourField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(`[name^="${t}["].colour-hex-input`);r.forEach((l,s)=>{if(s<n.length){const i=T(n[s]);l.value=i,l.classList.remove("invalid"),l.title="";const d=l.closest(".colour-picker-wrapper");if(d){const u=d.querySelector(".colour-swatch"),c=d.querySelector(".colour-picker-hidden");u&&(u.style.backgroundColor=i),c&&(c.value=i.toLowerCase())}}}),n.length!==r.length&&console.warn(`updateColourField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"].colour-hex-input`);if(r){const l=T(n);r.value=l,r.classList.remove("invalid"),r.title="";const s=r.closest(".colour-picker-wrapper");if(s){const i=s.querySelector(".colour-swatch"),d=s.querySelector(".colour-picker-hidden");i&&(i.style.backgroundColor=l),d&&(d.value=l.toLowerCase())}}}}function fe(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const o=Math.log(t),a=Math.log(n);return Math.exp(o+e*(a-o))}function W(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const o=Math.log(t),a=Math.log(n);return(Math.log(e)-o)/(a-o)}function B(e,t){return Math.round(e/t)*t}function pe(e,t,n,o,a){var r;const l=document.createElement("div");l.className="slider-container space-y-2";const s=document.createElement("div");s.className="flex items-center gap-3";const i=document.createElement("input");i.type="range",i.name=t,i.className="slider-input flex-1",i.disabled=a;const d=n.scale||"linear",u=n.min,c=n.max,p=(r=n.step)!=null?r:1;if(d==="exponential"){if(u<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${u})`);i.min="0",i.max="1000",i.step="1";const x=W(e,u,c);i.value=(x*1e3).toString()}else i.min=u.toString(),i.max=c.toString(),i.step=p.toString(),i.value=e.toString();i.style.cssText=`
|
|
225
225
|
height: 6px;
|
|
226
226
|
border-radius: 3px;
|
|
227
227
|
background: linear-gradient(
|
|
@@ -242,72 +242,72 @@ var FormBuilder=(function(F){"use strict";function Ce(e,t){(e.minLength!==null||
|
|
|
242
242
|
color: var(--fb-text-color);
|
|
243
243
|
font-family: var(--fb-font-family-mono, monospace);
|
|
244
244
|
font-weight: 500;
|
|
245
|
-
`,v.textContent=e.toFixed(
|
|
245
|
+
`,v.textContent=e.toFixed(p<1?2:0),s.appendChild(i),s.appendChild(v),l.appendChild(s);const f=document.createElement("div");f.className="flex justify-between",f.style.cssText=`
|
|
246
246
|
font-size: var(--fb-font-size-small);
|
|
247
247
|
color: var(--fb-text-secondary-color);
|
|
248
|
-
`;const
|
|
248
|
+
`;const h=document.createElement("span");h.textContent=u.toString();const b=document.createElement("span");if(b.textContent=c.toString(),f.appendChild(h),f.appendChild(b),l.appendChild(f),!a){const x=()=>{let g;if(d==="exponential"){const m=parseFloat(i.value)/1e3;g=fe(m,u,c),g=B(g,p),g=Math.max(u,Math.min(c,g))}else g=parseFloat(i.value),g=B(g,p);v.textContent=g.toFixed(p<1?2:0);const y=(g-u)/(c-u)*100;i.style.background=`linear-gradient(
|
|
249
249
|
to right,
|
|
250
250
|
var(--fb-primary-color) 0%,
|
|
251
|
-
var(--fb-primary-color) ${
|
|
252
|
-
var(--fb-border-color) ${
|
|
251
|
+
var(--fb-primary-color) ${y}%,
|
|
252
|
+
var(--fb-border-color) ${y}%,
|
|
253
253
|
var(--fb-border-color) 100%
|
|
254
|
-
)`,o.instance&&o.instance.triggerOnChange(t,
|
|
254
|
+
)`,o.instance&&o.instance.triggerOnChange(t,g)};i.addEventListener("input",x),i.addEventListener("change",x)}return l}function dt(e,t,n,o){var a;if(e.min===void 0||e.min===null)throw new Error(`Slider field "${e.key}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider field "${e.key}" requires "max" property`);if(e.min>=e.max)throw new Error(`Slider field "${e.key}": min (${e.min}) must be less than max (${e.max})`);const r=t.state,l=e.default!==void 0?e.default:(e.min+e.max)/2,s=(a=t.prefill[e.key])!=null?a:l,i=pe(s,o,e,t,r.config.readonly);n.appendChild(i);const d=document.createElement("p");d.className="mt-1",d.style.cssText=`
|
|
255
255
|
font-size: var(--fb-font-size-small);
|
|
256
256
|
color: var(--fb-text-secondary-color);
|
|
257
|
-
`,d.textContent=S(e),n.appendChild(d)}function
|
|
257
|
+
`,d.textContent=S(e),n.appendChild(d)}function ut(e,t,n,o){var a,r;if(e.min===void 0||e.min===null)throw new Error(`Slider field "${e.key}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider field "${e.key}" requires "max" property`);if(e.min>=e.max)throw new Error(`Slider field "${e.key}": min (${e.min}) must be less than max (${e.max})`);const l=t.state,s=t.prefill[e.key]||[],i=Array.isArray(s)?[...s]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0,c=e.default!==void 0?e.default:(e.min+e.max)/2;for(;i.length<d;)i.push(c);const p=document.createElement("div");p.className="space-y-3",n.appendChild(p);function v(){p.querySelectorAll(".multiple-slider-item").forEach((g,y)=>{const m=g.querySelector("input[type=range]");m&&m.setAttribute("name",`${o}[${y}]`)})}function f(g=c,y=-1){const m=document.createElement("div");m.className="multiple-slider-item flex items-start gap-2";const C=`${o}[${p.children.length}]`,E=pe(g,C,e,t,l.config.readonly);return E.style.flex="1",m.appendChild(E),y===-1?p.appendChild(m):p.insertBefore(m,p.children[y]),v(),m}function h(){if(l.config.readonly)return;const g=p.querySelectorAll(".multiple-slider-item"),y=g.length;g.forEach(m=>{let C=m.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn px-2 py-1 rounded",C.style.cssText=`
|
|
258
258
|
color: var(--fb-error-color);
|
|
259
259
|
background-color: transparent;
|
|
260
260
|
transition: background-color var(--fb-transition-duration);
|
|
261
261
|
margin-top: 8px;
|
|
262
|
-
`,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const $=Array.from(
|
|
262
|
+
`,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const $=Array.from(p.children).indexOf(m);p.children.length>d&&(i.splice($,1),m.remove(),v(),b(),h())},m.appendChild(C));const E=y<=d;C.disabled=E,C.style.opacity=E?"0.5":"1",C.style.pointerEvents=E?"none":"auto"})}function b(){const g=n.querySelector(".add-slider-btn");if(g&&g.remove(),!l.config.readonly&&i.length<u){const y=document.createElement("button");y.type="button",y.className="add-slider-btn mt-2 px-3 py-1 rounded",y.style.cssText=`
|
|
263
263
|
color: var(--fb-primary-color);
|
|
264
264
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
265
265
|
background-color: transparent;
|
|
266
266
|
font-size: var(--fb-font-size);
|
|
267
267
|
transition: all var(--fb-transition-duration);
|
|
268
|
-
`,
|
|
268
|
+
`,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{i.push(c),f(c),b(),h()},n.appendChild(y)}}i.forEach(g=>f(g)),b(),h();const x=document.createElement("p");x.className="mt-1",x.style.cssText=`
|
|
269
269
|
font-size: var(--fb-font-size-small);
|
|
270
270
|
color: var(--fb-text-secondary-color);
|
|
271
|
-
`,x.textContent=S(e),n.appendChild(x)}function
|
|
271
|
+
`,x.textContent=S(e),n.appendChild(x)}function ft(e,t,n){var o,a,r;const l=[],{scopeRoot:s,skipValidation:i}=n;if(e.min===void 0||e.min===null)throw new Error(`Slider validation: field "${t}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider validation: field "${t}" requires "max" property`);const d=e.min,u=e.max,c=(o=e.step)!=null?o:1,p=e.scale||"linear",v=(h,b)=>{var x,g;if(!h)return;const y=`error-${h.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(y);if(b){if(h.classList.add("invalid"),h.title=b,!m){m=document.createElement("div"),m.id=y,m.className="error-message",m.style.cssText=`
|
|
272
272
|
color: var(--fb-error-color);
|
|
273
273
|
font-size: var(--fb-font-size-small);
|
|
274
274
|
margin-top: 0.25rem;
|
|
275
|
-
`;const C=
|
|
275
|
+
`;const C=h.closest(".slider-container");C&&C.nextSibling?(x=C.parentNode)==null||x.insertBefore(m,C.nextSibling):C&&((g=C.parentNode)==null||g.appendChild(m))}m.textContent=b,m.style.display="block"}else h.classList.remove("invalid"),h.title="",m&&m.remove()},f=(h,b)=>{const x=h.value;if(!x)return!i&&e.required?(l.push(`${b}: required`),v(h,"required"),null):(v(h,null),null);let g;if(p==="exponential"){const y=parseFloat(x)/1e3;g=fe(y,d,u),g=B(g,c)}else g=parseFloat(x),g=B(g,c);if(!i){if(g<d)return l.push(`${b}: value ${g} < min ${d}`),v(h,`value must be >= ${d}`),g;if(g>u)return l.push(`${b}: value ${g} > max ${u}`),v(h,`value must be <= ${u}`),g}return v(h,null),g};if(e.multiple){const h=s.querySelectorAll(`input[type="range"][name^="${t}["]`),b=[];if(h.forEach((x,g)=>{const y=f(x,`${t}[${g}]`);b.push(y)}),!i){const x=(a=e.minCount)!=null?a:1,g=(r=e.maxCount)!=null?r:1/0,y=b.filter(m=>m!==null);e.required&&y.length===0&&l.push(`${t}: required`),y.length<x&&l.push(`${t}: minimum ${x} items required`),y.length>g&&l.push(`${t}: maximum ${g} items allowed`)}return{value:b,errors:l}}else{const h=s.querySelector(`input[type="range"][name="${t}"]`);return h?{value:f(h,t),errors:l}:(!i&&e.required&&l.push(`${t}: required`),{value:null,errors:l})}}function pt(e,t,n,o){var a;const{scopeRoot:r}=o,l=e.min,s=e.max,i=(a=e.step)!=null?a:1,d=e.scale||"linear";if(e.multiple){if(!Array.isArray(n)){console.warn(`updateSliderField: Expected array for multiple field "${t}", got ${typeof n}`);return}const u=r.querySelectorAll(`input[type="range"][name^="${t}["]`);u.forEach((c,p)=>{if(p<n.length&&n[p]!==null){const v=Number(n[p]);if(d==="exponential"){const h=W(v,l,s);c.value=(h*1e3).toString()}else c.value=v.toString();const f=c.closest(".slider-container");if(f){const h=f.querySelector(".slider-value");h&&(h.textContent=v.toFixed(i<1?2:0));const b=(v-l)/(s-l)*100;c.style.background=`linear-gradient(
|
|
276
276
|
to right,
|
|
277
277
|
var(--fb-primary-color) 0%,
|
|
278
278
|
var(--fb-primary-color) ${b}%,
|
|
279
279
|
var(--fb-border-color) ${b}%,
|
|
280
280
|
var(--fb-border-color) 100%
|
|
281
|
-
)`}c.classList.remove("invalid"),c.title=""}}),n.length!==u.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${u.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const u=r.querySelector(`input[type="range"][name="${t}"]`);if(u&&n!==null&&n!==void 0){const c=Number(n);if(d==="exponential"){const v=
|
|
281
|
+
)`}c.classList.remove("invalid"),c.title=""}}),n.length!==u.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${u.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const u=r.querySelector(`input[type="range"][name="${t}"]`);if(u&&n!==null&&n!==void 0){const c=Number(n);if(d==="exponential"){const v=W(c,l,s);u.value=(v*1e3).toString()}else u.value=c.toString();const p=u.closest(".slider-container");if(p){const v=p.querySelector(".slider-value");v&&(v.textContent=c.toFixed(i<1?2:0));const f=(c-l)/(s-l)*100;u.style.background=`linear-gradient(
|
|
282
282
|
to right,
|
|
283
283
|
var(--fb-primary-color) 0%,
|
|
284
284
|
var(--fb-primary-color) ${f}%,
|
|
285
285
|
var(--fb-border-color) ${f}%,
|
|
286
286
|
var(--fb-border-color) 100%
|
|
287
|
-
)`}u.classList.remove("invalid"),u.title=""}}}let
|
|
287
|
+
)`}u.classList.remove("invalid"),u.title=""}}}function J(e){const t={};return e.querySelectorAll("input, select, textarea").forEach(n=>{const o=n.getAttribute("name");o&&!o.includes("[")&&!o.includes(".")&&(n instanceof HTMLSelectElement?t[o]=n.value:n instanceof HTMLInputElement?n.type==="checkbox"?t[o]=n.checked:n.type==="radio"?n.checked&&(t[o]=n.value):t[o]=n.value:n instanceof HTMLTextAreaElement&&(t[o]=n.value))}),t}let Y=null;function mt(e){Y=e}function j(e,t){if(!Y)throw new Error("renderElement not initialized. Import from components/index.ts");return Y(e,t)}function me(e,t){if(!e.prefillHints||e.prefillHints.length===0)return null;const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",e.prefillHints.forEach((o,a)=>{const r=document.createElement("button");r.type="button",r.className="fb-prefill-hint",r.textContent=o.label,r.setAttribute("data-hint-values",JSON.stringify(o.values)),r.setAttribute("data-container-key",t),r.setAttribute("data-hint-index",String(a)),n.appendChild(r)}),n}function ve(e,t,n,o){var a,r;const l=document.createElement("div");l.className="border border-gray-200 rounded-lg p-4 bg-gray-50",l.setAttribute("data-container",o);const s=document.createElement("div");s.className="flex justify-between items-center mb-4";const i=document.createElement("div");i.className="flex-1";const d=document.createElement("div"),u=e.columns||1;if(u===1?d.className="space-y-4":d.className=`grid grid-cols-${u} gap-4`,l.appendChild(s),s.appendChild(i),!t.state.config.readonly){const p=me(e,o);p&&l.appendChild(p)}const c={path:q(t.path,e.key),prefill:((a=t.prefill)==null?void 0:a[e.key])||{},formData:(r=t.formData)!=null?r:t.prefill,state:t.state};e.elements.forEach(p=>{p.hidden||d.appendChild(j(p,c))}),l.appendChild(d),i.innerHTML=`<span>${e.label||e.key}</span>`,n.appendChild(l)}function he(e,t,n,o){var a,r,l,s;const i=t.state,d=document.createElement("div");d.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const u=document.createElement("div");u.className="flex justify-between items-center mb-4";const c=document.createElement("div");c.className="flex-1";const p=document.createElement("div");if(p.className="space-y-4",d.appendChild(u),u.appendChild(c),!t.state.config.readonly){const y=me(e,e.key);y&&d.appendChild(y)}const v=(a=e.minCount)!=null?a:0,f=(r=e.maxCount)!=null?r:1/0,h=Array.isArray((l=t.prefill)==null?void 0:l[e.key])?t.prefill[e.key]:null,b=()=>p.querySelectorAll(":scope > .containerItem").length,x=()=>{const y=document.createElement("button");return y.type="button",y.className="add-container-btn mt-2 px-3 py-1 rounded",y.style.cssText=`
|
|
288
288
|
color: var(--fb-primary-color);
|
|
289
289
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
290
290
|
background-color: transparent;
|
|
291
291
|
font-size: var(--fb-font-size);
|
|
292
292
|
transition: all var(--fb-transition-duration);
|
|
293
|
-
`,
|
|
293
|
+
`,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{if(b()<f){const m=b(),C=i.formRoot?J(i.formRoot):{},E={state:t.state,path:q(t.path,`${e.key}[${m}]`),prefill:{},formData:C},$=document.createElement("div");$.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",$.setAttribute("data-container-item",`${e.key}[${m}]`);const w=document.createElement("div"),N=e.columns||1;if(N===1?w.className="space-y-4":w.className=`grid grid-cols-${N} gap-4`,e.elements.forEach(k=>{k.hidden||w.appendChild(j(k,E))}),$.appendChild(w),!i.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 px-2 py-1 rounded",k.style.cssText=`
|
|
294
294
|
color: var(--fb-error-color);
|
|
295
295
|
background-color: transparent;
|
|
296
296
|
transition: background-color var(--fb-transition-duration);
|
|
297
|
-
`,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{$.remove(),
|
|
297
|
+
`,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{$.remove(),g()},$.style.position="relative",$.appendChild(k)}p.appendChild($),g()}},y},g=()=>{const y=b(),m=d.querySelector(".add-container-btn");m&&(m.disabled=y>=f,m.style.opacity=y>=f?"0.5":"1",m.style.pointerEvents=y>=f?"none":"auto"),c.innerHTML=`<span>${e.label||e.key}</span> <span class="text-sm text-gray-500">(${y}/${f===1/0?"\u221E":f})</span>`};if(h&&Array.isArray(h)&&h.forEach((y,m)=>{var C;const E={state:t.state,path:q(t.path,`${e.key}[${m}]`),prefill:y||{},formData:(C=t.formData)!=null?C:t.prefill},$=document.createElement("div");$.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",$.setAttribute("data-container-item",`${e.key}[${m}]`);const w=document.createElement("div"),N=e.columns||1;if(N===1?w.className="space-y-4":w.className=`grid grid-cols-${N} gap-4`,e.elements.forEach(k=>{k.hidden||w.appendChild(j(k,E))}),$.appendChild(w),!i.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 px-2 py-1 rounded",k.style.cssText=`
|
|
298
298
|
color: var(--fb-error-color);
|
|
299
299
|
background-color: transparent;
|
|
300
300
|
transition: background-color var(--fb-transition-duration);
|
|
301
|
-
`,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{$.remove(),
|
|
301
|
+
`,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{$.remove(),g()},$.style.position="relative",$.appendChild(k)}p.appendChild($)}),!i.config.readonly)for(;b()<v;){const y=b(),m={state:t.state,path:q(t.path,`${e.key}[${y}]`),prefill:{},formData:(s=t.formData)!=null?s:t.prefill},C=document.createElement("div");C.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",C.setAttribute("data-container-item",`${e.key}[${y}]`);const E=document.createElement("div"),$=e.columns||1;$===1?E.className="space-y-4":E.className=`grid grid-cols-${$} gap-4`,e.elements.forEach(N=>{N.hidden||E.appendChild(j(N,m))}),C.appendChild(E);const w=document.createElement("button");w.type="button",w.className="absolute top-2 right-2 px-2 py-1 rounded",w.style.cssText=`
|
|
302
302
|
color: var(--fb-error-color);
|
|
303
303
|
background-color: transparent;
|
|
304
304
|
transition: background-color var(--fb-transition-duration);
|
|
305
|
-
`,w.textContent="\u2715",w.addEventListener("mouseenter",()=>{w.style.backgroundColor="var(--fb-background-hover-color)"}),w.addEventListener("mouseleave",()=>{w.style.backgroundColor="transparent"}),w.onclick=()=>{b()>v&&(C.remove(),h())},C.style.position="relative",C.appendChild(w),m.appendChild(C)}d.appendChild(m),s.config.readonly||d.appendChild(x()),h(),n.appendChild(d)}let W=null;function mt(e){W=e}function fe(e,t,n){if(!W)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return W(e,t,n)}function ve(e,t,n){const o=[],{scopeRoot:a,skipValidation:r,path:l}=n;if(!("elements"in e))return{value:null,errors:o};const i=(s,d,u)=>{var c,m;if(r)return;const v="minCount"in u&&(c=u.minCount)!=null?c:0,f="maxCount"in u&&(m=u.maxCount)!=null?m:1/0;u.required&&d.length===0&&o.push(`${s}: required`),d.length<v&&o.push(`${s}: minimum ${v} items required`),d.length>f&&o.push(`${s}: maximum ${f} items allowed`)};if("multiple"in e&&e.multiple){const s=[],d=a.querySelectorAll("[data-container-item]"),u=Array.from(d).filter(c=>{const m=c.getAttribute("data-container-item");return m==null?void 0:m.startsWith(`${t}[`)}).length;for(let c=0;c<u;c++){const m={},v=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(f=>{if(f.hidden||f.type==="hidden")m[f.key]=f.default!==void 0?f.default:null;else{const y=`${t}[${c}].${f.key}`;m[f.key]=fe({...f,key:y},{path:l},v)}}),s.push(m)}return i(t,s,e),{value:s,errors:o}}else{const s={},d=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(u=>{if(u.hidden||u.type==="hidden")s[u.key]=u.default!==void 0?u.default:null;else{const c=`${t}.${u.key}`;s[u.key]=fe({...u,key:c},{path:l},d)}}),{value:s,errors:o}}}function he(e,t,n,o){const{instance:a,scopeRoot:r}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((i,s)=>{M(i)&&e.elements.forEach(d=>{const u=d.key,c=`${t}[${s}].${u}`,m=i[u];m!==void 0&&a.updateField(c,m)})});const l=r.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==l.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!M(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(l=>{const i=l.key,s=`${t}.${i}`,d=n[i];d!==void 0&&a.updateField(s,d)})}}function ft(e,t,n,o){var a,r;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const l={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&M(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(r=e.repeat)==null?void 0:r.max};l.multiple?me(l,t,n):pe(l,t,n,o)}function ge(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&M(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function vt(e,t,n){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field key: "${t}"`);const o=ge(e);return ve(o,t,n)}function ht(e,t,n,o){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const a=ge(e);return he(a,t,n,o)}function gt(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(u=>{u.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),r=window.innerWidth,l=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const i=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let s=a.left,d=a.bottom+5;s+i.width>r&&(s=a.right-i.width),d+i.height>l&&(d=a.top-i.height-5),s<10&&(s=10),d<10&&(d=a.bottom+5),n.style.left=`${s}px`,n.style.top=`${d}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(a=>{a.classList.add("hidden")})});function yt(e,t){var n;if(!e.displayIf)return null;try{const o=(n=t.formData)!=null?n:t.prefill;if(!R(e.displayIf,o)){const a=document.createElement("div");return a.className="fb-field-wrapper-hidden",a.style.display="none",a.setAttribute("data-field-key",e.key),a.setAttribute("data-conditionally-hidden","true"),a}}catch(o){console.error(`Error evaluating displayIf for field "${e.key}":`,o)}return null}function bt(e){const t=document.createElement("label");if(t.className="text-sm font-medium text-gray-900",t.textContent=e.label||e.key,e.required){const n=document.createElement("span");n.className="text-red-500 ml-1",n.textContent="*",t.appendChild(n)}return t}function xt(e){const t=document.createElement("button");t.type="button",t.className="ml-2 text-gray-400 hover:text-gray-600",t.innerHTML='<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>';const n=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,o=document.createElement("div");return o.id=n,o.className="hidden absolute z-50 bg-gray-200 text-gray-900 text-sm rounded-lg p-3 max-w-sm border border-gray-300 shadow-lg",o.style.position="fixed",o.textContent=e.description||e.hint||"Field information",document.body.appendChild(o),t.onclick=a=>{a.preventDefault(),a.stopPropagation(),gt(n,t)},t}function Ct(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=bt(e);if(t.appendChild(n),e.description||e.hint){const o=xt(e);t.appendChild(o)}return t}function Et(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?Ne(e,t,n,o):Fe(e,t,n,o);break;case"textarea":a?Ae(e,t,n,o):qe(e,t,n,o);break;case"number":a?ze(e,t,n,o):Me(e,t,n,o);break;case"select":a?Re(e,t,n,o):Ie(e,t,n,o);break;case"file":a?rt(e,t,n,o):tt(e,t,n,o);break;case"files":nt(e,t,n,o);break;case"colour":a?lt(e,t,n,o):ot(e,t,n,o);break;case"slider":a?ct(e,t,n,o):st(e,t,n,o);break;case"group":ft(e,t,n,o);break;case"container":a?me(e,t,n):pe(e,t,n,o);break;default:{const r=document.createElement("div");r.className="text-red-500 text-sm",r.textContent=`Unsupported field type: ${e.type}`,n.appendChild(r)}}}function J(e,t){const n=yt(e,t);if(n)return n;const o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=Ct(e);o.appendChild(a);const r=q(t.path,e.key);return Et(e,t,o,r),o}pt(J);const $t={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{addElement:"Add Element",removeElement:"Remove",uploadText:"Upload",dragDropText:"or drag and drop files",dragDropTextSingle:"or drag and drop file",clickDragText:"Click or drag file",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download"},ru:{addElement:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u044D\u043B\u0435\u043C\u0435\u043D\u0442",removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",uploadText:"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435",dragDropText:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",dragDropTextSingle:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C"}},theme:{}};function wt(e){return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...$t,...e},debounceTimer:null}}function kt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const H={primaryColor:"#3b82f6",primaryHoverColor:"#2563eb",errorColor:"#ef4444",errorHoverColor:"#dc2626",successColor:"#10b981",borderColor:"#d1d5db",borderHoverColor:"#9ca3af",borderFocusColor:"#3b82f6",backgroundColor:"#ffffff",backgroundHoverColor:"#f9fafb",backgroundReadonlyColor:"#f3f4f6",textColor:"#1f2937",textSecondaryColor:"#6b7280",textPlaceholderColor:"#9ca3af",textDisabledColor:"#d1d5db",buttonBgColor:"#3b82f6",buttonTextColor:"#ffffff",buttonBorderColor:"#2563eb",buttonHoverBgColor:"#2563eb",buttonHoverBorderColor:"#1d4ed8",actionBgColor:"#ffffff",actionTextColor:"#374151",actionBorderColor:"#e5e7eb",actionHoverBgColor:"#f9fafb",actionHoverBorderColor:"#d1d5db",fileUploadBgColor:"#f3f4f6",fileUploadBorderColor:"#d1d5db",fileUploadTextColor:"#9ca3af",fileUploadHoverBorderColor:"#3b82f6",inputPaddingX:"0.75rem",inputPaddingY:"0.5rem",borderRadius:"0.5rem",borderWidth:"1px",fontSize:"0.875rem",fontSizeSmall:"0.75rem",fontSizeExtraSmall:"0.625rem",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeightNormal:"400",fontWeightMedium:"500",focusRingWidth:"2px",focusRingColor:"#3b82f6",focusRingOpacity:"0.5",transitionDuration:"200ms"};function St(e){const t={...H,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${r}: ${a};`)}),n.join(`
|
|
306
|
-
`)}function
|
|
305
|
+
`,w.textContent="\u2715",w.addEventListener("mouseenter",()=>{w.style.backgroundColor="var(--fb-background-hover-color)"}),w.addEventListener("mouseleave",()=>{w.style.backgroundColor="transparent"}),w.onclick=()=>{b()>v&&(C.remove(),g())},C.style.position="relative",C.appendChild(w),p.appendChild(C)}d.appendChild(p),i.config.readonly||d.appendChild(x()),g(),n.appendChild(d)}let G=null;function vt(e){G=e}function ge(e,t,n){if(!G)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return G(e,t,n)}function ye(e,t,n){const o=[],{scopeRoot:a,skipValidation:r,path:l}=n;if(!("elements"in e))return{value:null,errors:o};const s=(i,d,u)=>{var c,p;if(r)return;const v="minCount"in u&&(c=u.minCount)!=null?c:0,f="maxCount"in u&&(p=u.maxCount)!=null?p:1/0;u.required&&d.length===0&&o.push(`${i}: required`),d.length<v&&o.push(`${i}: minimum ${v} items required`),d.length>f&&o.push(`${i}: maximum ${f} items allowed`)};if("multiple"in e&&e.multiple){const i=[],d=a.querySelectorAll("[data-container-item]"),u=Array.from(d).filter(c=>{const p=c.getAttribute("data-container-item");return p==null?void 0:p.startsWith(`${t}[`)}).length;for(let c=0;c<u;c++){const p={},v=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(f=>{var h;if(f.enableIf)try{const b=(h=n.instance)!=null&&h.getState().formRoot?J(n.instance.getState().formRoot):{};if(!A(f.enableIf,b,p))return}catch(b){console.error(`Error evaluating enableIf for field "${f.key}" in container "${t}[${c}]":`,b)}if(f.hidden||f.type==="hidden")p[f.key]=f.default!==void 0?f.default:null;else{const b=`${t}[${c}].${f.key}`;p[f.key]=ge({...f,key:b},{path:l},v)}}),i.push(p)}return s(t,i,e),{value:i,errors:o}}else{const i={},d=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(u=>{var c;if(u.enableIf)try{const p=(c=n.instance)!=null&&c.getState().formRoot?J(n.instance.getState().formRoot):{};if(!A(u.enableIf,p,i))return}catch(p){console.error(`Error evaluating enableIf for field "${u.key}" in container "${t}":`,p)}if(u.hidden||u.type==="hidden")i[u.key]=u.default!==void 0?u.default:null;else{const p=`${t}.${u.key}`;i[u.key]=ge({...u,key:p},{path:l},d)}}),{value:i,errors:o}}}function be(e,t,n,o){const{instance:a,scopeRoot:r}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((s,i)=>{z(s)&&e.elements.forEach(d=>{const u=d.key,c=`${t}[${i}].${u}`,p=s[u];p!==void 0&&a.updateField(c,p)})});const l=r.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==l.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!z(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(l=>{const s=l.key,i=`${t}.${s}`,d=n[s];d!==void 0&&a.updateField(i,d)})}}function ht(e,t,n,o){var a,r;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const l={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&z(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(r=e.repeat)==null?void 0:r.max};l.multiple?he(l,t,n):ve(l,t,n,o)}function xe(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&z(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function gt(e,t,n){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field key: "${t}"`);const o=xe(e);return ye(o,t,n)}function yt(e,t,n,o){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const a=xe(e);return be(a,t,n,o)}function bt(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(u=>{u.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),r=window.innerWidth,l=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const s=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let i=a.left,d=a.bottom+5;i+s.width>r&&(i=a.right-s.width),d+s.height>l&&(d=a.top-s.height-5),i<10&&(i=10),d<10&&(d=a.bottom+5),n.style.left=`${i}px`,n.style.top=`${d}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(a=>{a.classList.add("hidden")})});function xt(e,t){var n,o;if(!e.enableIf)return!1;try{const a=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=t.path?I(a,t.path):void 0;return!A(e.enableIf,a,r)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function Ct(e,t){const n=t.querySelector(`[name="${e}"]`);if(n){if(n instanceof HTMLSelectElement)return n.value;if(n instanceof HTMLInputElement){if(n.type==="checkbox")return n.checked;if(n.type==="radio"){const o=t.querySelector(`[name="${e}"]:checked`);return o?o.value:void 0}else return n.value}else if(n instanceof HTMLTextAreaElement)return n.value}}function R(e,t,n){var o,a;if(!t.enableIf)return;const r=n.state.formRoot;if(!r){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const l=t.enableIf,s=(o=l.scope)!=null?o:"relative";let i={};const d={};if((!n.path||n.path===""?"absolute":s)==="relative"&&n.path){const u=n.path.match(/^(.+)\[(\d+)\]$/);if(u){const c=u[1],p=parseInt(u[2],10),v=r.querySelector(`[data-container-item="${c}[${p}]"]`);v&&v.querySelectorAll("input, select, textarea").forEach(f=>{const h=f.getAttribute("name");if(h){const b=h.match(/\.([^.[\]]+)$/);if(b){const x=b[1];f instanceof HTMLSelectElement?d[x]=f.value:f instanceof HTMLInputElement?f.type==="checkbox"?d[x]=f.checked:f.type==="radio"?f.checked&&(d[x]=f.value):d[x]=f.value:f instanceof HTMLTextAreaElement&&(d[x]=f.value)}}})}}else{const u=l.key,c=Ct(u,r);c!==void 0?i[u]=c:i=(a=n.formData)!=null?a:n.prefill}try{A(l,i,d)?(e.style.display="",e.classList.remove("fb-field-wrapper-disabled"),e.removeAttribute("data-conditionally-disabled")):(e.style.display="none",e.classList.add("fb-field-wrapper-disabled"),e.setAttribute("data-conditionally-disabled","true"))}catch(u){console.error(`Error re-evaluating enableIf for field "${t.key}":`,u)}}function Et(e,t,n){var o;if(!t.enableIf)return;const a=n.state.formRoot;if(!a){console.error("Cannot setup enableIf listeners: formRoot is null");return}const r=t.enableIf,l=(o=r.scope)!=null?o:"relative",s=r.key;let i;l==="relative"&&n.path?i=`${n.path}.${s}`:i=s;const d=a.querySelector(`[name="${i}"]`);if(!d){const u=new MutationObserver(()=>{const c=a.querySelector(`[name="${i}"]`);c&&(c.addEventListener("change",()=>{R(e,t,n)}),c.addEventListener("input",()=>{R(e,t,n)}),u.disconnect())});u.observe(a,{childList:!0,subtree:!0});return}d.addEventListener("change",()=>{R(e,t,n)}),d.addEventListener("input",()=>{R(e,t,n)})}function $t(e){const t=document.createElement("label");if(t.className="text-sm font-medium text-gray-900",t.textContent=e.label||e.key,e.required){const n=document.createElement("span");n.className="text-red-500 ml-1",n.textContent="*",t.appendChild(n)}return t}function wt(e){const t=document.createElement("button");t.type="button",t.className="ml-2 text-gray-400 hover:text-gray-600",t.innerHTML='<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>';const n=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,o=document.createElement("div");return o.id=n,o.className="hidden absolute z-50 bg-gray-200 text-gray-900 text-sm rounded-lg p-3 max-w-sm border border-gray-300 shadow-lg",o.style.position="fixed",o.textContent=e.description||e.hint||"Field information",document.body.appendChild(o),t.onclick=a=>{a.preventDefault(),a.stopPropagation(),bt(n,t)},t}function kt(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=$t(e);if(t.appendChild(n),e.description||e.hint){const o=wt(e);t.appendChild(o)}return t}function St(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?Ae(e,t,n,o):qe(e,t,n,o);break;case"textarea":a?He(e,t,n,o):Te(e,t,n,o);break;case"number":a?Be(e,t,n,o):Ie(e,t,n,o);break;case"select":a?Oe(e,t,n,o):De(e,t,n,o);break;case"file":a?lt(e,t,n,o):rt(e,t,n,o);break;case"files":ot(e,t,n,o);break;case"colour":a?it(e,t,n,o):at(e,t,n,o);break;case"slider":a?ut(e,t,n,o):dt(e,t,n,o);break;case"group":ht(e,t,n,o);break;case"container":a?he(e,t,n):ve(e,t,n,o);break;default:{const r=document.createElement("div");r.className="text-red-500 text-sm",r.textContent=`Unsupported field type: ${e.type}`,n.appendChild(r)}}}function X(e,t){const n=xt(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=kt(e);o.appendChild(a);const r=q(t.path,e.key);return St(e,t,o,r),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),Et(o,e,t),o}mt(X);const Lt={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{addElement:"Add Element",removeElement:"Remove",uploadText:"Upload",dragDropText:"or drag and drop files",dragDropTextSingle:"or drag and drop file",clickDragText:"Click or drag file",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download"},ru:{addElement:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u044D\u043B\u0435\u043C\u0435\u043D\u0442",removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",uploadText:"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435",dragDropText:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",dragDropTextSingle:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C"}},theme:{}};function Ft(e){return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Lt,...e},debounceTimer:null}}function Nt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const M={primaryColor:"#3b82f6",primaryHoverColor:"#2563eb",errorColor:"#ef4444",errorHoverColor:"#dc2626",successColor:"#10b981",borderColor:"#d1d5db",borderHoverColor:"#9ca3af",borderFocusColor:"#3b82f6",backgroundColor:"#ffffff",backgroundHoverColor:"#f9fafb",backgroundReadonlyColor:"#f3f4f6",textColor:"#1f2937",textSecondaryColor:"#6b7280",textPlaceholderColor:"#9ca3af",textDisabledColor:"#d1d5db",buttonBgColor:"#3b82f6",buttonTextColor:"#ffffff",buttonBorderColor:"#2563eb",buttonHoverBgColor:"#2563eb",buttonHoverBorderColor:"#1d4ed8",actionBgColor:"#ffffff",actionTextColor:"#374151",actionBorderColor:"#e5e7eb",actionHoverBgColor:"#f9fafb",actionHoverBorderColor:"#d1d5db",fileUploadBgColor:"#f3f4f6",fileUploadBorderColor:"#d1d5db",fileUploadTextColor:"#9ca3af",fileUploadHoverBorderColor:"#3b82f6",inputPaddingX:"0.75rem",inputPaddingY:"0.5rem",borderRadius:"0.5rem",borderWidth:"1px",fontSize:"0.875rem",fontSizeSmall:"0.75rem",fontSizeExtraSmall:"0.625rem",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeightNormal:"400",fontWeightMedium:"500",focusRingWidth:"2px",focusRingColor:"#3b82f6",focusRingOpacity:"0.5",transitionDuration:"200ms"};function qt(e){const t={...M,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${r}: ${a};`)}),n.join(`
|
|
306
|
+
`)}function At(e,t){const n=qt(t);let o=e.querySelector("style[data-fb-theme]");o||(o=document.createElement("style"),o.setAttribute("data-fb-theme","true"),e.appendChild(o)),o.textContent=`
|
|
307
307
|
[data-fb-root="true"] {
|
|
308
308
|
${n}
|
|
309
309
|
}
|
|
310
|
-
`}const
|
|
310
|
+
`}const Tt={default:M,dark:{...M,primaryColor:"#60a5fa",primaryHoverColor:"#3b82f6",borderColor:"#4b5563",borderHoverColor:"#6b7280",borderFocusColor:"#60a5fa",backgroundColor:"#1f2937",backgroundHoverColor:"#374151",backgroundReadonlyColor:"#111827",textColor:"#f9fafb",textSecondaryColor:"#9ca3af",textPlaceholderColor:"#6b7280",fileUploadBgColor:"#374151",fileUploadBorderColor:"#4b5563",fileUploadTextColor:"#9ca3af"},klein:{...M,primaryColor:"#0066cc",primaryHoverColor:"#0052a3",errorColor:"#d32f2f",errorHoverColor:"#c62828",successColor:"#388e3c",borderColor:"#e0e0e0",borderHoverColor:"#bdbdbd",borderFocusColor:"#0066cc",borderRadius:"4px",fontSize:"16px",fontSizeSmall:"14px",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif'}};function Ce(e,t=!1){e.style.cssText=`
|
|
311
311
|
background-color: var(--fb-action-bg-color);
|
|
312
312
|
color: var(--fb-action-text-color);
|
|
313
313
|
border: var(--fb-border-width) solid var(--fb-action-border-color);
|
|
@@ -317,6 +317,6 @@ ${n}
|
|
|
317
317
|
border-radius: var(--fb-border-radius);
|
|
318
318
|
transition: all var(--fb-transition-duration);
|
|
319
319
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
320
|
-
`,e.addEventListener("mouseenter",()=>{e.style.backgroundColor="var(--fb-action-hover-bg-color)",e.style.borderColor="var(--fb-action-hover-border-color)"}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor="var(--fb-action-bg-color)",e.style.borderColor="var(--fb-action-border-color)"})}const
|
|
320
|
+
`,e.addEventListener("mouseenter",()=>{e.style.backgroundColor="var(--fb-action-hover-bg-color)",e.style.borderColor="var(--fb-action-hover-border-color)"}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor="var(--fb-action-bg-color)",e.style.borderColor="var(--fb-action-border-color)"})}const Ht={text:{validate:Z,update:Q},textarea:{validate:Me,update:ze},number:{validate:je,update:Re},select:{validate:Ue,update:Pe},file:{validate:ie,update:se},files:{validate:ie,update:se},colour:{validate:st,update:ct},slider:{validate:ft,update:pt},container:{validate:ye,update:be},group:{validate:gt,update:yt}};function Ee(e){return Ht[e]||null}function Mt(e,t,n){const o=Ee(e.type);return o&&o.validate?o.validate(e,t,n):null}function zt(e,t,n,o){const a=Ee(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class D{constructor(t){this.instanceId=Nt(),this.state=Ft(t),this.state.config.verboseErrors&&(globalThis.__formBuilderInstances||(globalThis.__formBuilderInstances=new Set),globalThis.__formBuilderInstances.add(this.instanceId),globalThis.__formBuilderInstances.size>10&&console.warn(`[form-builder] ${globalThis.__formBuilderInstances.size} instances active. Possible memory leak - ensure you call destroy() when done.`))}getInstanceId(){return this.instanceId}getState(){return this.state}setFormRoot(t){this.state.formRoot=t}configure(t){Object.assign(this.state.config,t)}setUploadHandler(t){this.state.config.uploadFile=t}setDownloadHandler(t){this.state.config.downloadFile=t}setThumbnailHandler(t){this.state.config.getThumbnail=t}setActionHandler(t){this.state.config.actionHandler=t}setMode(t){this.state.config.readonly=t==="readonly"}setLocale(t){this.state.config.translations[t]&&(this.state.config.locale=t)}triggerOnChange(t,n){this.state.config.readonly||(this.state.debounceTimer!==null&&clearTimeout(this.state.debounceTimer),this.state.debounceTimer=setTimeout(()=>{const o=this.validateForm(!0);this.reevaluateConditionalFields(),this.state.config.onChange&&this.state.config.onChange(o),this.state.config.onFieldChange&&t!==void 0&&n!==void 0&&this.state.config.onFieldChange(t,n,o),this.state.debounceTimer=null},this.state.config.debounceMs))}registerAction(t){if(!t||!t.value)throw new Error("Action must have a value property");this.state.externalActions||(this.state.externalActions=[]);const n=this.state.externalActions.findIndex(o=>o.value===t.value&&o.related_field===t.related_field);n>=0?this.state.externalActions[n]=t:this.state.externalActions.push(t)}findFormElementByFieldPath(t){if(!this.state.formRoot)return null;if(!this.state.config.readonly){let a=this.state.formRoot.querySelector(`[name="${t}"]`);if(a)return a;const r=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const l of r)if(a=this.state.formRoot.querySelector(`[name="${l}"]`),a)return a}const n=this.findSchemaElement(t);if(!n)return null;const o=this.state.formRoot.querySelectorAll(".fb-field-wrapper");for(const a of o){const r=n.label||n.key,l=a.querySelector("label");if(l&&(l.textContent===r||l.textContent===`${r}*`)){let s=a.querySelector(".field-placeholder");return s||(s=document.createElement("div"),s.className="field-placeholder",s.style.display="none",a.appendChild(s)),s}}return null}findSchemaElement(t){if(!this.state.schema||!this.state.schema.elements)return null;let n=this.state.schema.elements,o=null;const a=t.replace(/\[\d+\]/g,"").split(".").filter(Boolean);for(const r of a){if(o=n.find(l=>l.key===r)||null,!o)return null;"elements"in o&&o.elements&&(n=o.elements)}return o}resolveActionLabel(t,n,o,a=!1){if(o&&"actions"in o&&o.actions){const r=o.actions.find(l=>l.key===t);if(r&&r.label)return r.label}if(a&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const r=this.state.schema.actions.find(l=>l.key===t);if(r&&r.label)return r.label}return n||t}renderFormLevelActions(t,n=[]){if(!this.state.formRoot)return;const o=this.state.formRoot.querySelector(".form-level-actions-container");o&&o.remove();const a=document.createElement("div");a.className="form-level-actions-container mt-6 pt-4 flex flex-wrap gap-3 justify-center",a.style.cssText=`
|
|
321
321
|
border-top: var(--fb-border-width) solid var(--fb-border-color);
|
|
322
|
-
`,t.forEach(r=>{const l=document.createElement("button");l.type="button",
|
|
322
|
+
`,t.forEach(r=>{const l=document.createElement("button");l.type="button",Ce(l,!0);const s=n.includes(r),i=this.resolveActionLabel(r.key,r.label,null,s);l.textContent=i,l.addEventListener("click",d=>{d.preventDefault(),d.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(r.value,r.key,null)}),a.appendChild(l)}),this.state.formRoot.appendChild(a)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],o=[];this.state.externalActions.forEach(r=>{!r.key||!r.value||(r.related_field?(t.has(r.related_field)||t.set(r.related_field,[]),t.get(r.related_field).push(r)):n.push(r))}),t.forEach((r,l)=>{const s=this.findFormElementByFieldPath(l);if(!s){console.warn(`External action: Could not find form element for field "${l}", treating as form-level actions`),o.push(...r);return}let i=s.closest(".fb-field-wrapper");if(i||(i=s.parentElement),!i){console.warn(`External action: Could not find wrapper for field "${l}"`);return}const d=i.querySelector(".external-actions-container");d&&d.remove();const u=document.createElement("div");u.className="external-actions-container mt-3 flex flex-wrap gap-2";const c=this.findSchemaElement(l);r.forEach(p=>{const v=document.createElement("button");v.type="button",Ce(v,!1);const f=this.resolveActionLabel(p.key,p.label,c);v.textContent=f,v.addEventListener("click",h=>{h.preventDefault(),h.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(p.value,p.key,p.related_field)}),u.appendChild(v)}),i.appendChild(u)});const a=[...n,...o];a.length>0&&this.renderFormLevelActions(a,n)}handlePrefillHintClick(t){const n=t.target;if(!n.classList.contains("fb-prefill-hint"))return;t.preventDefault(),t.stopPropagation();const o=n.getAttribute("data-hint-values"),a=n.getAttribute("data-root-hint")==="true",r=n.getAttribute("data-container-key");if(!o||!a&&!r){console.warn("Prefill hint missing required data attributes");return}try{const l=JSON.parse(o);for(const s in l){const i=a?s:`${r}.${s}`,d=l[s];this.updateField(i,d)}}catch(l){console.error("Error parsing prefill hint values:",l)}}createRootPrefillHints(t){const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",t.forEach(o=>{const a=document.createElement("button");a.type="button",a.className="fb-prefill-hint",o.icon?a.textContent=`${o.icon} ${o.label}`:a.textContent=o.label,a.setAttribute("data-hint-values",JSON.stringify(o.values)),a.setAttribute("data-root-hint","true"),n.appendChild(a)}),n}renderForm(t,n,o,a){const r=O(n);if(r.length>0){console.error("Schema validation errors:",r);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=a||null,H(t),t.setAttribute("data-fb-root","true"),At(t,this.state.config.theme);const l=document.createElement("div");if(l.className="space-y-6",n.prefillHints&&!this.state.config.readonly){const d=this.createRootPrefillHints(n.prefillHints);l.appendChild(d)}const s=document.createElement("div"),i=n.columns||1;i===1?s.className="space-y-4":s.className=`grid grid-cols-${i} gap-4`,n.elements.forEach(d=>{if(d.hidden)return;const u=X(d,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});s.appendChild(u)}),l.appendChild(s),t.appendChild(l),this.state.config.readonly||t.addEventListener("click",this.handlePrefillHintClick.bind(this)),this.state.config.readonly&&this.state.externalActions&&Array.isArray(this.state.externalActions)&&this.renderExternalActions()}validateForm(t=!1){if(!this.state.schema||!this.state.formRoot)return{valid:!0,errors:[],data:{}};const n=[],o={},a=(r,l,s=null)=>{const i=r.key,d={scopeRoot:s||this.state.formRoot,state:this.state,instance:this,path:l.path,skipValidation:t},u=Mt(r,i,d);return u!==null?(n.push(...u.errors),u.value):(console.warn(`Unknown field type "${r.type}" for key "${i}"`),null)};return vt(a),this.state.schema.elements.forEach(r=>{if(r.enableIf)try{if(!A(r.enableIf,o))return}catch(l){console.error(`Error evaluating enableIf for field "${r.key}" during validation:`,l)}r.hidden?o[r.key]=r.default!==void 0?r.default:null:o[r.key]=a(r,{path:""})}),{valid:n.length===0,errors:n,data:o}}getFormData(){return this.validateForm(!1)}submitForm(){const t=this.validateForm(!1);return t.valid&&typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formSubmit",data:t.data,schema:this.state.schema},"*"),t}saveDraft(){const t=this.validateForm(!0);return typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formDraft",data:t.data,schema:this.state.schema},"*"),t}clearForm(){if(!this.state.schema||!this.state.formRoot){console.warn("clearForm: Form not initialized. Call renderForm() first.");return}const t=this.state.schema,n=this.state.formRoot,o=this.state.externalActions,a=this.buildHiddenFieldsData(t.elements);this.renderForm(n,t,a,o||void 0)}buildHiddenFieldsData(t){const n={};for(const o of t){const a=o.key;if(o.hidden&&o.default!==void 0&&(n[a]=o.default),o.type==="container"||o.type==="group"){const r=o,l=this.buildHiddenFieldsData(r.elements);Object.keys(l).length>0&&(a in n?typeof n[a]=="object"&&n[a]!==null&&!Array.isArray(n[a])&&(n[a]={...n[a],...l}):n[a]=l)}}return n}setFormData(t){if(!this.state.schema||!this.state.formRoot){console.warn("setFormData: Form not initialized. Call renderForm() first.");return}for(const n in t)this.updateField(n,t[n])}updateField(t,n){if(!this.state.schema||!this.state.formRoot){console.warn("updateField: Form not initialized. Call renderForm() first.");return}const o=this.findSchemaElement(t);if(!o){console.warn(`updateField: Schema element not found for path "${t}"`);return}const a=this.findFormElementByFieldPath(t);if(!a){console.warn(`updateField: DOM element not found for path "${t}"`);return}this.updateFieldValue(a,o,t,n),this.reevaluateConditionalFields(),(this.state.config.onChange||this.state.config.onFieldChange)&&this.triggerOnChange(t,n)}updateFieldValue(t,n,o,a){const r={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};zt(n,o,a,r)||console.warn(`updateField: No updater found for field type "${n.type}" at path "${o}"`)}reevaluateConditionalFields(){if(!this.state.schema||!this.state.formRoot)return;const t=this.validateForm(!0).data,n=(o,a)=>{o.forEach(r=>{var l,s,i;const d=a?`${a}.${r.key}`:r.key;if(r.enableIf){let u=null;if(a){const c=a.match(/^(.+)\[(\d+)\]$/);if(c){const p=c[1],v=c[2],f=this.state.formRoot.querySelector(`[data-container-item="${p}[${v}]"]`);f&&(u=f.querySelector(`[data-field-key="${r.key}"]`))}else{const p=this.state.formRoot.querySelector(`[data-container="${a}"]`);p&&(u=p.querySelector(`[data-field-key="${r.key}"]`))}}else u=this.state.formRoot.querySelector(`[data-field-key="${r.key}"]`);if(u){const c=u;try{let p;((l=r.enableIf.scope)!=null?l:"relative")==="relative"&&a&&(p=I(t,a));const v=A(r.enableIf,t,p),f=c.getAttribute("data-conditionally-disabled")==="true";if(v&&f){const h=a?I(t,a):t,b=X(r,{path:a,prefill:h&&typeof h=="object"?h:{},formData:t,state:this.state,instance:this});(s=c.parentNode)==null||s.replaceChild(b,c)}else if(!v&&!f){const h=document.createElement("div");h.className="fb-field-wrapper-disabled",h.style.display="none",h.setAttribute("data-field-key",r.key),h.setAttribute("data-conditionally-disabled","true"),(i=c.parentNode)==null||i.replaceChild(h,c)}}catch(p){console.error(`Error re-evaluating enableIf for field "${r.key}" at path "${d}":`,p)}}}if((r.type==="container"||r.type==="group")&&"elements"in r&&r.elements){const u=t==null?void 0:t[r.key];Array.isArray(u)?u.forEach((c,p)=>{n(r.elements,`${d}[${p}]`)}):n(r.elements,d)}})};n(this.state.schema.elements,"")}destroy(){var t;this.state.debounceTimer!==null&&(clearTimeout(this.state.debounceTimer),this.state.debounceTimer=null),this.state.resourceIndex.clear(),this.state.formRoot&&H(this.state.formRoot),this.state.formRoot=null,this.state.schema=null,this.state.externalActions=null,this.state.config.verboseErrors&&((t=globalThis.__formBuilderInstances)==null||t.delete(this.instanceId))}}function $e(e){return new D(e)}return typeof window!="undefined"&&(window.FormBuilder=D,window.createFormBuilder=$e,window.validateSchema=O),F.FormBuilderInstance=D,F.createFormBuilder=$e,F.default=D,F.defaultTheme=M,F.exampleThemes=Tt,F.validateSchema=O,Object.defineProperty(F,"__esModule",{value:!0}),F})({});
|