@dmitryvim/form-builder 0.2.17 → 0.2.19
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 +58 -0
- package/dist/browser/formbuilder.min.js +168 -78
- package/dist/browser/formbuilder.v0.2.19.min.js +448 -0
- package/dist/cjs/index.cjs +1530 -14
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +1491 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +168 -78
- package/dist/types/components/index.d.ts +3 -1
- package/dist/types/components/switcher.d.ts +13 -0
- package/dist/types/components/table.d.ts +4 -0
- package/dist/types/components/textarea.d.ts +2 -1
- package/dist/types/types/config.d.ts +7 -0
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/schema.d.ts +36 -1
- package/package.json +2 -2
- package/dist/browser/formbuilder.v0.2.17.min.js +0 -358
package/dist/form-builder.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var FormBuilder=(function(
|
|
1
|
+
var FormBuilder=(function(ae){"use strict";function w(e,t,n){const o=t.config.locale||"en",a=t.config.translations[o],l=t.config.translations.en;let r=(a==null?void 0:a[e])||(l==null?void 0:l[e])||e;if(n)for(const[s,u]of Object.entries(n))r=r.replace(new RegExp(`\\{${s}\\}`,"g"),String(u));return r}function $t(e,t,n){(e.minLength!=null||e.maxLength!=null)&&(e.minLength!=null&&e.maxLength!=null?t.push(w("hintLengthRange",n,{min:e.minLength,max:e.maxLength})):e.maxLength!=null?t.push(w("hintMaxLength",n,{max:e.maxLength})):e.minLength!=null&&t.push(w("hintMinLength",n,{min:e.minLength})))}function kt(e,t,n){(e.min!=null||e.max!=null)&&(e.min!=null&&e.max!=null?t.push(w("hintValueRange",n,{min:e.min,max:e.max})):e.max!=null?t.push(w("hintMaxValue",n,{max:e.max})):e.min!=null&&t.push(w("hintMinValue",n,{min:e.min})))}function St(e,t,n){e.maxSizeMB&&t.push(w("hintMaxSize",n,{size:e.maxSizeMB}))}function Lt(e,t,n){var o;(o=e.accept)!=null&&o.extensions&&t.push(w("hintFormats",n,{formats:e.accept.extensions.map(a=>a.toUpperCase()).join(",")}))}function At(e,t,n){e.pattern&&t.push(w("hintPattern",n,{pattern:e.pattern}))}function ne(e,t){const n=[];return $t(e,n,t),e.type!=="slider"&&kt(e,n,t),St(e,n,t),Lt(e,n,t),At(e,n,t),n.join(" \u2022 ")}function Te(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,l)=>{if((!a.label||typeof a.label!="string")&&t.push(`schema.prefillHints[${l}] must have a 'label' property of type string`),!a.values||typeof a.values!="object")t.push(`schema.prefillHints[${l}] must have a 'values' property of type object`);else for(const r in a.values)e.elements.some(s=>s.key===r)||t.push(`schema.prefillHints[${l}] references non-existent field "${r}"`)})}function n(o,a){o.forEach((l,r)=>{const s=`${a}[${r}]`;if(l.type||t.push(`${s}: missing type`),l.key||t.push(`${s}: missing key`),l.enableIf){const u=l.enableIf;(!u.key||typeof u.key!="string")&&t.push(`${s}: enableIf must have a 'key' property of type string`),"equals"in u||t.push(`${s}: enableIf must have at least one operator (equals, etc.)`)}if(l.type==="group"&&"elements"in l&&l.elements&&n(l.elements,`${s}.elements`),l.type==="container"&&l.elements){if("columns"in l&&l.columns!==void 0){const u=l.columns,c=[1,2,3,4];(!Number.isInteger(u)||!c.includes(u))&&t.push(`${s}: columns must be 1, 2, 3, or 4 (got ${u})`)}if("prefillHints"in l&&l.prefillHints){const u=l.prefillHints;Array.isArray(u)&&u.forEach((c,d)=>{if((!c.label||typeof c.label!="string")&&t.push(`${s}: prefillHints[${d}] must have a 'label' property of type string`),!c.values||typeof c.values!="object")t.push(`${s}: prefillHints[${d}] must have a 'values' property of type object`);else for(const i in c.values)l.elements.some(p=>p.key===i)||t.push(`container "${l.key}": prefillHints[${d}] references non-existent field "${i}"`)})}n(l.elements,`${s}.elements`)}if(l.type==="select"&&l.options){const u=l.default;u!=null&&u!==""&&(l.options.some(c=>c.value===u)||t.push(`${s}: default "${u}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function Ce(e){return e&&typeof e=="object"&&e.constructor===Object}function U(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function pe(e,t){return e?`${e}.${t}`:t}function ve(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function qe(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 l=parseInt(a.slice(1,-1),10);if(!Array.isArray(o)||isNaN(l))return;o=o[l]}else o=o[a]}return o}function fe(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 l;if(a==="relative")l=n!=null?n:t;else if(a==="absolute")l=t;else throw new Error(`Invalid enableIf scope: must be "relative" or "absolute" (got "${a}")`);const r=qe(l,e.key);if("equals"in e)return Nt(r,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function Nt(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 Ee(e,t,n=!1){const o=document.createElement("span");o.className="char-counter",o.style.cssText=`
|
|
2
2
|
position: absolute;
|
|
3
3
|
${n?"bottom: 8px":"top: 50%; transform: translateY(-50%)"};
|
|
4
4
|
right: 10px;
|
|
@@ -7,7 +7,7 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
7
7
|
pointer-events: none;
|
|
8
8
|
background: var(--fb-background-color);
|
|
9
9
|
padding: 0 4px;
|
|
10
|
-
`;const a=()=>{const l=t.value.length,r=e.minLength,
|
|
10
|
+
`;const a=()=>{const l=t.value.length,r=e.minLength,s=e.maxLength;if(r==null&&s==null){o.textContent="";return}l===0||r!=null&&l<r?(r!=null&&s!=null?o.textContent=`${r}-${s}`:s!=null?o.textContent=`\u2264${s}`:r!=null&&(o.textContent=`\u2265${r}`),o.style.color="var(--fb-text-secondary-color)"):s!=null&&l>s?(o.textContent=`${l}/${s}`,o.style.color="var(--fb-error-color)"):(s!=null?o.textContent=`${l}/${s}`:o.textContent=`${l}`,o.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",a),a(),o}function Ft(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("input");if(r.type="text",r.className="w-full rounded-lg",r.style.cssText=`
|
|
11
11
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
12
12
|
padding-right: 60px;
|
|
13
13
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
@@ -19,7 +19,7 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
19
19
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
20
20
|
width: 100%;
|
|
21
21
|
box-sizing: border-box;
|
|
22
|
-
`,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
|
|
22
|
+
`,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 u=r.value===""?null:r.value;t.instance.triggerOnChange(o,u)};r.addEventListener("blur",s),r.addEventListener("input",s)}if(l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const s=Ee(e,r,!1);l.appendChild(s)}n.appendChild(l)}function Tt(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],c=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;u.length<c;)u.push(e.default||"");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function p(){i.querySelectorAll(".multiple-text-item").forEach((v,C)=>{const b=v.querySelector("input");b&&(b.name=`${o}[${C}]`)})}function m(v="",C=-1){const b=document.createElement("div");b.className="multiple-text-item flex items-center gap-2";const y=document.createElement("div");y.style.cssText="position: relative; flex: 1;";const x=document.createElement("input");if(x.type="text",x.style.cssText=`
|
|
23
23
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
24
24
|
padding-right: 60px;
|
|
25
25
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
@@ -31,27 +31,27 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
31
31
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
32
32
|
width: 100%;
|
|
33
33
|
box-sizing: border-box;
|
|
34
|
-
`,x.placeholder=e.placeholder
|
|
34
|
+
`,x.placeholder=e.placeholder||w("placeholderText",r),x.value=v,x.readOnly=r.config.readonly,r.config.readonly||(x.addEventListener("focus",()=>{x.style.borderColor="var(--fb-border-focus-color)",x.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",x.style.outlineOffset="0"}),x.addEventListener("blur",()=>{x.style.borderColor="var(--fb-border-color)",x.style.outline="none"}),x.addEventListener("mouseenter",()=>{document.activeElement!==x&&(x.style.borderColor="var(--fb-border-hover-color)")}),x.addEventListener("mouseleave",()=>{document.activeElement!==x&&(x.style.borderColor="var(--fb-border-color)")})),!r.config.readonly&&t.instance){const k=()=>{const A=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,A)};x.addEventListener("blur",k),x.addEventListener("input",k)}if(y.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const k=Ee(e,x,!1);y.appendChild(k)}return b.appendChild(y),C===-1?i.appendChild(b):i.insertBefore(b,i.children[C]),p(),b}function f(){if(r.config.readonly)return;const v=i.querySelectorAll(".multiple-text-item"),C=v.length;v.forEach(b=>{let y=b.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn px-2 py-1 rounded",y.style.cssText=`
|
|
35
35
|
color: var(--fb-error-color);
|
|
36
36
|
background-color: transparent;
|
|
37
37
|
transition: background-color var(--fb-transition-duration);
|
|
38
|
-
`,
|
|
38
|
+
`,y.innerHTML="\u2715",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{const k=Array.from(i.children).indexOf(b);i.children.length>c&&(u.splice(k,1),b.remove(),p(),E(),f())},b.appendChild(y));const x=C<=c;y.disabled=x,y.style.opacity=x?"0.5":"1",y.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-text-btn px-3 py-1 rounded",v.style.cssText=`
|
|
39
39
|
color: var(--fb-primary-color);
|
|
40
40
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
41
41
|
background-color: transparent;
|
|
42
42
|
font-size: var(--fb-font-size);
|
|
43
43
|
transition: all var(--fb-transition-duration);
|
|
44
|
-
`,
|
|
44
|
+
`,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{u.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-text-btn");if(v){const C=u.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${u.length}/${d===1/0?"\u221E":d}`}u.forEach(v=>m(v)),E(),f()}function Ve(e,t,n){var o,a,l;const r=[],{scopeRoot:s,skipValidation:u}=n,c=(i,p)=>{var m,f;if(!i)return;const h=`error-${i.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(h);p?(i.classList.add("invalid"),i.title=p,g||(g=document.createElement("div"),g.id=h,g.className="error-message",g.style.cssText=`
|
|
45
45
|
color: var(--fb-error-color);
|
|
46
46
|
font-size: var(--fb-font-size-small);
|
|
47
47
|
margin-top: 0.25rem;
|
|
48
|
-
`,
|
|
48
|
+
`,i.nextSibling?(m=i.parentNode)==null||m.insertBefore(g,i.nextSibling):(f=i.parentNode)==null||f.appendChild(g)),g.textContent=p,g.style.display="block"):(i.classList.remove("invalid"),i.title="",g&&g.remove())},d=(i,p,m)=>{let f=!1;const{state:h}=n;if(!u&&p){if(e.minLength!==void 0&&e.minLength!==null&&p.length<e.minLength){const g=w("minLength",h,{min:e.minLength});r.push(`${m}: ${g}`),c(i,g),f=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&p.length>e.maxLength){const g=w("maxLength",h,{max:e.maxLength});r.push(`${m}: ${g}`),c(i,g),f=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(p)){const g=w("patternMismatch",h);r.push(`${m}: ${g}`),c(i,g),f=!0}}catch(g){const E=w("invalidPattern",h);r.push(`${m}: ${E}`),c(i,E),f=!0}}f||c(i,null)};if(e.multiple){const i=s.querySelectorAll(`[name^="${t}["]`),p=[],m=[];if(i.forEach((f,h)=>{var g;const E=(g=f==null?void 0:f.value)!=null?g:"";m.push(E),p.push(E===""?null:E),d(f,E,`${t}[${h}]`)}),!u){const{state:f}=n,h=(o=e.minCount)!=null?o:1,g=(a=e.maxCount)!=null?a:1/0,E=m.filter(v=>v.trim()!=="");e.required&&E.length===0&&r.push(`${t}: ${w("required",f)}`),E.length<h&&r.push(`${t}: ${w("minItems",f,{min:h})}`),E.length>g&&r.push(`${t}: ${w("maxItems",f,{max:g})}`)}return{value:p,errors:r}}else{const i=s.querySelector(`[name$="${t}"]`),p=(l=i==null?void 0:i.value)!=null?l:"";if(!u&&e.required&&p===""){const m=w("required",n.state);return r.push(`${t}: ${m}`),c(i,m),{value:null,errors:r}}return i&&d(i,p,t),{value:p===""?null:p,errors:r}}}function We(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 l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,s)=>{s<n.length&&(r.value=n[s]!=null?String(n[s]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateTextField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function _e(e){e.style.overflow="hidden",e.style.resize="none";const t=(e.value.match(/\n/g)||[]).length+1;e.rows=Math.max(1,t);const n=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`)};e.addEventListener("input",n),setTimeout(()=>{e.isConnected&&n()},0)}function qt(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const 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.style.cssText="padding-bottom: 24px;",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 u=r.value===""?null:r.value;t.instance.triggerOnChange(o,u)};r.addEventListener("blur",s),r.addEventListener("input",s)}if((e.autoExpand||a.config.readonly)&&_e(r),l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const s=Ee(e,r,!0);l.appendChild(s)}n.appendChild(l)}function Mt(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],c=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;u.length<c;)u.push(e.default||"");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function p(){i.querySelectorAll(".multiple-textarea-item").forEach((v,C)=>{const b=v.querySelector("textarea");b&&(b.name=`${o}[${C}]`)})}function m(v="",C=-1){const b=document.createElement("div");b.className="multiple-textarea-item";const y=document.createElement("div");y.style.cssText="position: relative;";const x=document.createElement("textarea");if(x.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",x.style.cssText="padding-bottom: 24px;",x.placeholder=e.placeholder||w("placeholderText",r),x.rows=e.rows||4,x.value=v,x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const k=()=>{const A=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,A)};x.addEventListener("blur",k),x.addEventListener("input",k)}if((e.autoExpand||r.config.readonly)&&_e(x),y.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const k=Ee(e,x,!0);y.appendChild(k)}return b.appendChild(y),C===-1?i.appendChild(b):i.insertBefore(b,i.children[C]),p(),b}function f(){if(r.config.readonly)return;const v=i.querySelectorAll(".multiple-textarea-item"),C=v.length;v.forEach(b=>{let y=b.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",y.innerHTML="\u2715",y.onclick=()=>{const k=Array.from(i.children).indexOf(b);i.children.length>c&&(u.splice(k,1),b.remove(),p(),E(),f())},b.appendChild(y));const x=C<=c;y.disabled=x,y.style.opacity=x?"0.5":"1",y.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-textarea-btn px-3 py-1 rounded",v.style.cssText=`
|
|
49
49
|
color: var(--fb-primary-color);
|
|
50
50
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
51
51
|
background-color: transparent;
|
|
52
52
|
font-size: var(--fb-font-size);
|
|
53
53
|
transition: all var(--fb-transition-duration);
|
|
54
|
-
`,
|
|
54
|
+
`,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{u.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-textarea-btn");if(v){const C=u.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${u.length}/${d===1/0?"\u221E":d}`}u.forEach(v=>m(v)),E(),f()}function Ht(e,t,n){return Ve(e,t,n)}function Bt(e,t,n,o){We(e,t,n,o);const{scopeRoot:a,state:l}=o;if(e.autoExpand||l.config.readonly)if(e.multiple)a.querySelectorAll(`textarea[name^="${t}["]`).forEach(r=>{r.dispatchEvent(new Event("input"))});else{const r=a.querySelector(`textarea[name="${t}"]`);r&&r.dispatchEvent(new Event("input"))}}function Je(e,t){const n=document.createElement("span");n.className="number-range-hint",n.style.cssText=`
|
|
55
55
|
position: absolute;
|
|
56
56
|
top: 50%;
|
|
57
57
|
transform: translateY(-50%);
|
|
@@ -61,65 +61,93 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
61
61
|
pointer-events: none;
|
|
62
62
|
background: var(--fb-background-color);
|
|
63
63
|
padding: 0 4px;
|
|
64
|
-
`;const o=e.min,a=e.max;let l="";o!=null&&a!=null?l=`${o} \u2013 ${a}`:a!=null?l=`\u2264${a}`:o!=null&&(l=`\u2265${o}`),n.textContent=l;const r=()=>{const
|
|
64
|
+
`;const o=e.min,a=e.max;let l="";o!=null&&a!=null?l=`${o} \u2013 ${a}`:a!=null?l=`\u2264${a}`:o!=null&&(l=`\u2265${o}`),n.textContent=l;const r=()=>{const s=t.value?parseFloat(t.value):null;if(s!=null){const u=o!=null&&s<o,c=a!=null&&s>a;n.style.color=u||c?"var(--fb-error-color)":"var(--fb-text-secondary-color)"}else n.style.color="var(--fb-text-secondary-color)"};return t.addEventListener("input",r),r(),n}function Rt(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const 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.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",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 u=r.value?parseFloat(r.value):null;t.instance.triggerOnChange(o,u)};r.addEventListener("blur",s),r.addEventListener("input",s)}if(l.appendChild(r),!a.config.readonly&&(e.min!=null||e.max!=null)){const s=Je(e,r);l.appendChild(s)}n.appendChild(l)}function zt(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],c=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;u.length<c;)u.push(e.default||"");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function p(){i.querySelectorAll(".multiple-number-item").forEach((v,C)=>{const b=v.querySelector("input");b&&(b.name=`${o}[${C}]`)})}function m(v="",C=-1){const b=document.createElement("div");b.className="multiple-number-item flex items-center gap-2";const y=document.createElement("div");y.style.cssText="position: relative; flex: 1;";const x=document.createElement("input");if(x.type="number",x.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",x.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",x.placeholder=e.placeholder||"0",e.min!==void 0&&(x.min=e.min.toString()),e.max!==void 0&&(x.max=e.max.toString()),e.step!==void 0&&(x.step=e.step.toString()),x.value=v.toString(),x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const k=()=>{const A=x.value?parseFloat(x.value):null;t.instance.triggerOnChange(x.name,A)};x.addEventListener("blur",k),x.addEventListener("input",k)}if(y.appendChild(x),!r.config.readonly&&(e.min!=null||e.max!=null)){const k=Je(e,x);y.appendChild(k)}return b.appendChild(y),C===-1?i.appendChild(b):i.insertBefore(b,i.children[C]),p(),b}function f(){if(r.config.readonly)return;const v=i.querySelectorAll(".multiple-number-item"),C=v.length;v.forEach(b=>{let y=b.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",y.innerHTML="\u2715",y.onclick=()=>{const k=Array.from(i.children).indexOf(b);i.children.length>c&&(u.splice(k,1),b.remove(),p(),E(),f())},b.appendChild(y));const x=C<=c;y.disabled=x,y.style.opacity=x?"0.5":"1",y.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-number-btn px-3 py-1 rounded",v.style.cssText=`
|
|
65
65
|
color: var(--fb-primary-color);
|
|
66
66
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
67
67
|
background-color: transparent;
|
|
68
68
|
font-size: var(--fb-font-size);
|
|
69
69
|
transition: all var(--fb-transition-duration);
|
|
70
|
-
`,
|
|
70
|
+
`,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{u.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-number-btn");if(v){const C=u.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${u.length}/${d===1/0?"\u221E":d}`}u.forEach(v=>m(v)),E(),f()}function It(e,t,n){var o,a,l,r,s;const u=[],{scopeRoot:c,skipValidation:d}=n,i=(m,f)=>{var h,g;if(!m)return;const E=`error-${m.getAttribute("name")||Math.random().toString(36).substring(7)}`;let v=document.getElementById(E);f?(m.classList.add("invalid"),m.title=f,v||(v=document.createElement("div"),v.id=E,v.className="error-message",v.style.cssText=`
|
|
71
71
|
color: var(--fb-error-color);
|
|
72
72
|
font-size: var(--fb-font-size-small);
|
|
73
73
|
margin-top: 0.25rem;
|
|
74
|
-
`,
|
|
74
|
+
`,m.nextSibling?(h=m.parentNode)==null||h.insertBefore(v,m.nextSibling):(g=m.parentNode)==null||g.appendChild(v)),v.textContent=f,v.style.display="block"):(m.classList.remove("invalid"),m.title="",v&&v.remove())},p=(m,f,h)=>{let g=!1;const{state:E}=n;if(!d&&e.min!==void 0&&e.min!==null&&f<e.min){const v=w("minValue",E,{min:e.min});u.push(`${h}: ${v}`),i(m,v),g=!0}else if(!d&&e.max!==void 0&&e.max!==null&&f>e.max){const v=w("maxValue",E,{max:e.max});u.push(`${h}: ${v}`),i(m,v),g=!0}g||i(m,null)};if(e.multiple){const m=c.querySelectorAll(`[name^="${t}["]`),f=[];if(m.forEach((h,g)=>{var E,v,C;const b=(E=h==null?void 0:h.value)!=null?E:"";if(b===""){f.push(null),i(h,null);return}const y=parseFloat(b);if(!d&&!Number.isFinite(y)){const k=w("notANumber",n.state);u.push(`${t}[${g}]: ${k}`),i(h,k),f.push(null);return}p(h,y,`${t}[${g}]`);const x=Number.isInteger((v=e.decimals)!=null?v:0)&&(C=e.decimals)!=null?C:0;f.push(Number(y.toFixed(x)))}),!d){const{state:h}=n,g=(o=e.minCount)!=null?o:1,E=(a=e.maxCount)!=null?a:1/0,v=f.filter(C=>C!==null);e.required&&v.length===0&&u.push(`${t}: ${w("required",h)}`),v.length<g&&u.push(`${t}: ${w("minItems",h,{min:g})}`),v.length>E&&u.push(`${t}: ${w("maxItems",h,{max:E})}`)}return{value:f,errors:u}}else{const m=c.querySelector(`[name$="${t}"]`),f=(l=m==null?void 0:m.value)!=null?l:"",{state:h}=n;if(!d&&e.required&&f===""){const v=w("required",h);return u.push(`${t}: ${v}`),i(m,v),{value:null,errors:u}}if(f==="")return i(m,null),{value:null,errors:u};const g=parseFloat(f);if(!d&&!Number.isFinite(g)){const v=w("notANumber",h);return u.push(`${t}: ${v}`),i(m,v),{value:null,errors:u}}p(m,g,t);const E=Number.isInteger((r=e.decimals)!=null?r:0)&&(s=e.decimals)!=null?s:0;return{value:Number(g.toFixed(E)),errors:u}}}function Dt(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 l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,s)=>{s<n.length&&(r.value=n[s]!=null?String(n[s]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function jt(e,t,n,o){const a=t.state,l=document.createElement("select");if(l.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",l.name=o,l.disabled=a.config.readonly,(e.options||[]).forEach(r=>{const s=document.createElement("option");s.value=r.value,s.textContent=r.label,(t.prefill[e.key]||e.default)===r.value&&(s.selected=!0),l.appendChild(s)}),!a.config.readonly&&t.instance){const r=()=>{t.instance.triggerOnChange(o,l.value)};l.addEventListener("change",r)}if(n.appendChild(l),!a.config.readonly){const r=document.createElement("p");r.className="text-xs text-gray-500 mt-1",r.textContent=ne(e,a),n.appendChild(r)}}function Ot(e,t,n,o){var a,l,r,s;const u=t.state,c=t.prefill[e.key]||[],d=Array.isArray(c)?[...c]:[],i=(a=e.minCount)!=null?a:1,p=(l=e.maxCount)!=null?l:1/0;for(;d.length<i;)d.push(e.default||((s=(r=e.options)==null?void 0:r[0])==null?void 0:s.value)||"");const m=document.createElement("div");m.className="space-y-2",n.appendChild(m);function f(){m.querySelectorAll(".multiple-select-item").forEach((b,y)=>{const x=b.querySelector("select");x&&(x.name=`${o}[${y}]`)})}function h(b="",y=-1){const x=document.createElement("div");x.className="multiple-select-item flex items-center gap-2";const k=document.createElement("select");if(k.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",k.disabled=u.config.readonly,(e.options||[]).forEach(A=>{const q=document.createElement("option");q.value=A.value,q.textContent=A.label,b===A.value&&(q.selected=!0),k.appendChild(q)}),!u.config.readonly&&t.instance){const A=()=>{t.instance.triggerOnChange(k.name,k.value)};k.addEventListener("change",A)}return x.appendChild(k),y===-1?m.appendChild(x):m.insertBefore(x,m.children[y]),f(),x}function g(){if(u.config.readonly)return;const b=m.querySelectorAll(".multiple-select-item"),y=b.length;b.forEach(x=>{let k=x.querySelector(".remove-item-btn");k||(k=document.createElement("button"),k.type="button",k.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",k.innerHTML="\u2715",k.onclick=()=>{const q=Array.from(m.children).indexOf(x);m.children.length>i&&(d.splice(q,1),x.remove(),f(),C(),g())},x.appendChild(k));const A=y<=i;k.disabled=A,k.style.opacity=A?"0.5":"1",k.style.pointerEvents=A?"none":"auto"})}let E=null,v=null;if(!u.config.readonly){E=document.createElement("div"),E.className="flex items-center gap-3 mt-2";const b=document.createElement("button");b.type="button",b.className="add-select-btn px-3 py-1 rounded",b.style.cssText=`
|
|
75
75
|
color: var(--fb-primary-color);
|
|
76
76
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
77
77
|
background-color: transparent;
|
|
78
78
|
font-size: var(--fb-font-size);
|
|
79
79
|
transition: all var(--fb-transition-duration);
|
|
80
|
-
`,
|
|
80
|
+
`,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{var y,x;const k=e.default||((x=(y=e.options)==null?void 0:y[0])==null?void 0:x.value)||"";d.push(k),h(k),C(),g()},v=document.createElement("span"),v.className="text-sm text-gray-500",E.appendChild(b),E.appendChild(v),n.appendChild(E)}function C(){if(!E||!v)return;const b=E.querySelector(".add-select-btn");if(b){const y=d.length>=p;b.disabled=y,b.style.opacity=y?"0.5":"1",b.style.pointerEvents=y?"none":"auto"}v.textContent=`${d.length}/${p===1/0?"\u221E":p}`}if(d.forEach(b=>h(b)),C(),g(),!u.config.readonly){const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=ne(e,u),n.appendChild(b)}}function Ut(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,s=(c,d)=>{var i,p;if(!c)return;const m=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let f=document.getElementById(m);d?(c.classList.add("invalid"),c.title=d,f||(f=document.createElement("div"),f.id=m,f.className="error-message",f.style.cssText=`
|
|
81
81
|
color: var(--fb-error-color);
|
|
82
82
|
font-size: var(--fb-font-size-small);
|
|
83
83
|
margin-top: 0.25rem;
|
|
84
|
-
`,
|
|
84
|
+
`,c.nextSibling?(i=c.parentNode)==null||i.insertBefore(f,c.nextSibling):(p=c.parentNode)==null||p.appendChild(f)),f.textContent=d,f.style.display="block"):(c.classList.remove("invalid"),c.title="",f&&f.remove())},u=(c,d,i,p)=>{var m,f;if(r)return;const{state:h}=n,g=d.filter(p),E="minCount"in i&&(m=i.minCount)!=null?m:1,v="maxCount"in i&&(f=i.maxCount)!=null?f:1/0;i.required&&g.length===0&&a.push(`${c}: ${w("required",h)}`),g.length<E&&a.push(`${c}: ${w("minItems",h,{min:E})}`),g.length>v&&a.push(`${c}: ${w("maxItems",h,{max:v})}`)};if("multiple"in e&&e.multiple){const c=l.querySelectorAll(`[name^="${t}["]`),d=[];return c.forEach(i=>{var p;const m=(p=i==null?void 0:i.value)!=null?p:"";d.push(m),s(i,null)}),u(t,d,e,i=>i!==""),{value:d,errors:a}}else{const c=l.querySelector(`[name$="${t}"]`),d=(o=c==null?void 0:c.value)!=null?o:"";if(!r&&e.required&&d===""){const i=w("required",n.state);return a.push(`${t}: ${i}`),s(c,i),{value:null,errors:a}}else s(c,null);return{value:d===""?null:d,errors:a}}}function Pt(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 l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,s)=>{s<n.length&&(r.value=n[s]!=null?String(n[s]):"",r.querySelectorAll("option").forEach(u=>{u.selected=u.value===String(n[s])}),r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${l.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.querySelectorAll("option").forEach(r=>{r.selected=r.value===String(n)}),l.classList.remove("invalid"),l.title="")}}function we(e){e.style.backgroundColor="var(--fb-primary-color)",e.style.color="#ffffff",e.style.borderColor="var(--fb-primary-color)"}function $e(e){e.style.backgroundColor="transparent",e.style.color="var(--fb-text-color)",e.style.borderColor="var(--fb-border-color)"}function Ke(e,t,n,o,a){const l=e.options||[],r=document.createElement("div");r.className="fb-switcher-group",r.style.cssText=`
|
|
85
|
+
display: inline-flex;
|
|
86
|
+
flex-direction: row;
|
|
87
|
+
flex-wrap: nowrap;
|
|
88
|
+
`;const s=[];return l.forEach((u,c)=>{const d=document.createElement("button");d.type="button",d.className="fb-switcher-btn",d.dataset.value=u.value,d.textContent=u.label,d.style.cssText=`
|
|
89
|
+
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
90
|
+
font-size: var(--fb-font-size);
|
|
91
|
+
border-width: var(--fb-border-width);
|
|
92
|
+
border-style: solid;
|
|
93
|
+
cursor: ${o?"default":"pointer"};
|
|
94
|
+
transition: background-color var(--fb-transition-duration), color var(--fb-transition-duration), border-color var(--fb-transition-duration);
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
line-height: 1.25;
|
|
97
|
+
outline: none;
|
|
98
|
+
`,l.length===1?d.style.borderRadius="var(--fb-border-radius)":c===0?(d.style.borderRadius="var(--fb-border-radius) 0 0 var(--fb-border-radius)",d.style.borderRightWidth="0"):c===l.length-1?d.style.borderRadius="0 var(--fb-border-radius) var(--fb-border-radius) 0":(d.style.borderRadius="0",d.style.borderRightWidth="0"),u.value===t?we(d):$e(d),o||(d.addEventListener("click",()=>{n.value=u.value,s.forEach(i=>{i.dataset.value===u.value?we(i):$e(i)}),a&&a(u.value)}),d.addEventListener("mouseenter",()=>{n.value!==u.value&&(d.style.backgroundColor="var(--fb-background-hover-color)")}),d.addEventListener("mouseleave",()=>{n.value!==u.value&&(d.style.backgroundColor="transparent")})),s.push(d),r.appendChild(d)}),r}function Vt(e,t,n,o){var a,l;const r=t.state,s=String((l=(a=t.prefill[e.key])!=null?a:e.default)!=null?l:""),u=document.createElement("input");u.type="hidden",u.name=o,u.value=s;const c=r.config.readonly,d=!c&&t.instance?p=>{t.instance.triggerOnChange(o,p)}:null,i=Ke(e,s,u,c,d);if(n.appendChild(u),n.appendChild(i),!c){const p=document.createElement("p");p.className="text-xs text-gray-500 mt-1",p.textContent=ne(e,r),n.appendChild(p)}}function Wt(e,t,n,o){var a,l,r,s;const u=t.state,c=t.prefill[e.key]||[],d=Array.isArray(c)?[...c]:[],i=(a=e.minCount)!=null?a:1,p=(l=e.maxCount)!=null?l:1/0;for(;d.length<i;)d.push(e.default||((s=(r=e.options)==null?void 0:r[0])==null?void 0:s.value)||"");const m=u.config.readonly,f=document.createElement("div");f.className="space-y-2",n.appendChild(f);function h(){f.querySelectorAll(".multiple-switcher-item").forEach((y,x)=>{const k=y.querySelector("input[type=hidden]");k&&(k.name=`${o}[${x}]`)})}function g(y="",x=-1){const k=x===-1?f.children.length:x,A=`${o}[${k}]`,q=document.createElement("div");q.className="multiple-switcher-item flex items-center gap-2";const _=document.createElement("input");_.type="hidden",_.name=A,_.value=y,q.appendChild(_);const K=!m&&t.instance?Fe=>{t.instance.triggerOnChange(_.name,Fe)}:null,G=Ke(e,y,_,m,K);return q.appendChild(G),x===-1?f.appendChild(q):f.insertBefore(q,f.children[x]),h(),q}function E(){if(m)return;const y=f.querySelectorAll(".multiple-switcher-item"),x=y.length;y.forEach(k=>{let A=k.querySelector(".remove-item-btn");A||(A=document.createElement("button"),A.type="button",A.className="remove-item-btn px-2 py-1 rounded",A.style.cssText=`
|
|
99
|
+
color: var(--fb-error-color);
|
|
100
|
+
background-color: transparent;
|
|
101
|
+
transition: background-color var(--fb-transition-duration);
|
|
102
|
+
`,A.innerHTML="\u2715",A.addEventListener("mouseenter",()=>{A.style.backgroundColor="var(--fb-background-hover-color)"}),A.addEventListener("mouseleave",()=>{A.style.backgroundColor="transparent"}),A.onclick=()=>{const _=Array.from(f.children).indexOf(k);f.children.length>i&&(d.splice(_,1),k.remove(),h(),b(),E())},k.appendChild(A));const q=x<=i;A.disabled=q,A.style.opacity=q?"0.5":"1",A.style.pointerEvents=q?"none":"auto"})}let v=null,C=null;if(!m){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const y=document.createElement("button");y.type="button",y.className="add-switcher-btn px-3 py-1 rounded",y.style.cssText=`
|
|
103
|
+
color: var(--fb-primary-color);
|
|
104
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
105
|
+
background-color: transparent;
|
|
106
|
+
font-size: var(--fb-font-size);
|
|
107
|
+
transition: all var(--fb-transition-duration);
|
|
108
|
+
`,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{var x,k;const A=e.default||((k=(x=e.options)==null?void 0:x[0])==null?void 0:k.value)||"";d.push(A),g(A),b(),E()},C=document.createElement("span"),C.className="text-sm text-gray-500",v.appendChild(y),v.appendChild(C),n.appendChild(v)}function b(){if(!v||!C)return;const y=v.querySelector(".add-switcher-btn");if(y){const x=d.length>=p;y.disabled=x,y.style.opacity=x?"0.5":"1",y.style.pointerEvents=x?"none":"auto"}C.textContent=`${d.length}/${p===1/0?"\u221E":p}`}if(d.forEach(y=>g(y)),b(),E(),!m){const y=document.createElement("p");y.className="text-xs text-gray-500 mt-1",y.textContent=ne(e,u),n.appendChild(y)}}function _t(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,s=(d,i)=>{var p,m;if(!d)return;const f=`error-${d.getAttribute("name")||Math.random().toString(36).substring(7)}`;let h=document.getElementById(f);i?(d.classList.add("invalid"),d.title=i,h||(h=document.createElement("div"),h.id=f,h.className="error-message",h.style.cssText=`
|
|
109
|
+
color: var(--fb-error-color);
|
|
110
|
+
font-size: var(--fb-font-size-small);
|
|
111
|
+
margin-top: 0.25rem;
|
|
112
|
+
`,d.nextSibling?(p=d.parentNode)==null||p.insertBefore(h,d.nextSibling):(m=d.parentNode)==null||m.appendChild(h)),h.textContent=i,h.style.display="block"):(d.classList.remove("invalid"),d.title="",h&&h.remove())},u=(d,i,p,m)=>{var f,h;if(r)return;const{state:g}=n,E=i.filter(m),v="minCount"in p&&(f=p.minCount)!=null?f:1,C="maxCount"in p&&(h=p.maxCount)!=null?h:1/0;p.required&&E.length===0&&a.push(`${d}: ${w("required",g)}`),E.length<v&&a.push(`${d}: ${w("minItems",g,{min:v})}`),E.length>C&&a.push(`${d}: ${w("maxItems",g,{max:C})}`)},c=new Set("options"in e?e.options.map(d=>d.value):[]);if("multiple"in e&&e.multiple){const d=l.querySelectorAll(`input[type="hidden"][name^="${t}["]`),i=[];return d.forEach(p=>{var m;const f=(m=p==null?void 0:p.value)!=null?m:"";if(i.push(f),!r&&f!==""&&!c.has(f)){const h=w("invalidOption",n.state);s(p,h),a.push(`${t}: ${h}`)}else s(p,null)}),u(t,i,e,p=>p!==""),{value:i,errors:a}}else{const d=l.querySelector(`input[type="hidden"][name$="${t}"]`),i=(o=d==null?void 0:d.value)!=null?o:"";if(!r&&e.required&&i===""){const p=w("required",n.state);return a.push(`${t}: ${p}`),s(d,p),{value:null,errors:a}}if(!r&&i!==""&&!c.has(i)){const p=w("invalidOption",n.state);return a.push(`${t}: ${p}`),s(d,p),{value:null,errors:a}}return s(d,null),{value:i===""?null:i,errors:a}}}function Jt(e,t,n,o){var a;const{scopeRoot:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSwitcherField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=l.querySelectorAll(`input[type="hidden"][name^="${t}["]`);r.forEach((s,u)=>{var c;if(u<n.length){const d=n[u]!=null?String(n[u]):"";s.value=d;const i=(c=s.parentElement)==null?void 0:c.querySelector(".fb-switcher-group");i&&i.querySelectorAll(".fb-switcher-btn").forEach(p=>{p.dataset.value===d?we(p):$e(p)}),s.classList.remove("invalid"),s.title=""}}),n.length!==r.length&&console.warn(`updateSwitcherField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=l.querySelector(`input[type="hidden"][name="${t}"]`);if(r){const s=n!=null?String(n):"";r.value=s;const u=(a=r.parentElement)==null?void 0:a.querySelector(".fb-switcher-group");u&&u.querySelectorAll(".fb-switcher-btn").forEach(c=>{c.dataset.value===s?we(c):$e(c)}),r.classList.remove("invalid"),r.title=""}}}function Kt(e,t,n,o){const a=document.createElement("img");a.className="w-full h-full object-contain",a.alt=n||w("previewAlt",o);const l=new FileReader;l.onload=r=>{var s;a.src=((s=r.target)==null?void 0:s.result)||""},l.readAsDataURL(t),e.appendChild(a)}function Yt(e,t,n,o,a,l){const r=URL.createObjectURL(t);e.onclick=null;const s=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(s,e),s.innerHTML=`
|
|
85
113
|
<div class="relative group h-full">
|
|
86
114
|
<video class="w-full h-full object-contain" controls preload="auto" muted src="${r}">
|
|
87
|
-
${
|
|
115
|
+
${U(w("videoNotSupported",a))}
|
|
88
116
|
</video>
|
|
89
117
|
<div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
|
|
90
118
|
<button class="bg-red-600 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs delete-file-btn">
|
|
91
|
-
${
|
|
119
|
+
${U(w("removeElement",a))}
|
|
92
120
|
</button>
|
|
93
121
|
<button class="bg-gray-800 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs change-file-btn">
|
|
94
|
-
${
|
|
122
|
+
${U(w("changeButton",a))}
|
|
95
123
|
</button>
|
|
96
124
|
</div>
|
|
97
125
|
</div>
|
|
98
|
-
`,
|
|
126
|
+
`,Gt(s,o,a,l),s}function Gt(e,t,n,o){const a=e.querySelector(".change-file-btn");a&&(a.onclick=r=>{r.stopPropagation(),o!=null&&o.picker&&o.picker.click()});const l=e.querySelector(".delete-file-btn");l&&(l.onclick=r=>{r.stopPropagation(),Xt(e,t,n,o)})}function Xt(e,t,n,o){var a;n.resourceIndex.delete(t);const l=(a=e.parentElement)==null?void 0:a.querySelector('input[type="hidden"]');l&&(l.value=""),o!=null&&o.fileUploadHandler&&(e.onclick=o.fileUploadHandler),o!=null&&o.dragHandler&&Be(e,o.dragHandler),e.innerHTML=`
|
|
99
127
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
100
128
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
101
129
|
<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"/>
|
|
102
130
|
</svg>
|
|
103
|
-
<div class="text-sm text-center">${
|
|
131
|
+
<div class="text-sm text-center">${U(w("clickDragText",n))}</div>
|
|
104
132
|
</div>
|
|
105
|
-
`}function
|
|
133
|
+
`}function Zt(e,t,n,o){const a=document.createElement("video");a.className="w-full h-full object-contain",a.controls=!0,a.preload="metadata",a.muted=!0,a.src=t,a.appendChild(document.createTextNode(w("videoNotSupported",o))),e.appendChild(a)}function Qt(e,t,n){rn(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=`
|
|
106
134
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
107
135
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
108
136
|
<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"/>
|
|
109
137
|
</svg>
|
|
110
|
-
<div class="text-sm text-center">${
|
|
138
|
+
<div class="text-sm text-center">${U(w("clickDragText",n))}</div>
|
|
111
139
|
</div>
|
|
112
|
-
`})}async function
|
|
140
|
+
`})}async function en(e,t,n,o,a,l,r){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?Kt(e,t.file,n,l):t.type&&t.type.startsWith("video/")?e=Yt(e,t.file,t.type,o,l,r):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">${U(n)}</div></div>`,!a&&!(t.type&&t.type.startsWith("video/"))&&Qt(e,o,l))}async function tn(e,t,n,o,a){if(!a.config.getThumbnail){He(e,a);return}try{const l=await a.config.getThumbnail(t);if(l)if(ve(e),o&&o.type&&o.type.startsWith("video/"))Zt(e,l,o.type,a);else{const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n||w("previewAlt",a),r.src=l,e.appendChild(r)}else He(e,a)}catch(l){console.error("Failed to get thumbnail:",l),e.innerHTML=`
|
|
113
141
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
114
142
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
115
143
|
<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
144
|
</svg>
|
|
117
|
-
<div class="text-sm text-center">${
|
|
145
|
+
<div class="text-sm text-center">${U(n||w("previewUnavailable",a))}</div>
|
|
118
146
|
</div>
|
|
119
|
-
`}}async function
|
|
147
|
+
`}}async function Ye(e,t,n,o={}){const{fileName:a="",isReadonly:l=!1,deps:r=null}=o;if(!l&&r&&(!r.picker||!r.fileUploadHandler||!r.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");ve(e),l&&e.classList.add("cursor-pointer");const s=n.resourceIndex.get(t);s&&s.file&&s.file instanceof File?await en(e,s,a,t,l,n,r):await tn(e,t,a,s,n)}async function Me(e,t,n){var o,a;const l=t.resourceIndex.get(e),r=(l==null?void 0:l.name)||e.split("/").pop()||"file",s=r.toLowerCase().match(/\.psd$/),u=document.createElement("div");u.className=s?"space-y-2":"space-y-3";const c=document.createElement("div");s?c.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":c.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const d=!s&&(((o=l==null?void 0:l.type)==null?void 0:o.startsWith("image/"))||r.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),i=((a=l==null?void 0:l.type)==null?void 0:a.startsWith("video/"))||r.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(d)if(t.config.getThumbnail)try{const f=await t.config.getThumbnail(e);f?c.innerHTML=`<img src="${f}" alt="${U(r)}" class="w-full h-auto">`:c.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">${U(r)}</div></div></div>`}catch(f){console.warn("getThumbnail failed for",e,f),c.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">${U(r)}</div></div></div>`}else c.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">${U(r)}</div></div></div>`;else if(i)if(t.config.getThumbnail)try{const f=await t.config.getThumbnail(e);f?c.innerHTML=`
|
|
120
148
|
<div class="relative group">
|
|
121
|
-
<video class="w-full h-auto" controls preload="auto" muted src="${
|
|
122
|
-
${
|
|
149
|
+
<video class="w-full h-auto" controls preload="auto" muted src="${f}">
|
|
150
|
+
${U(w("videoNotSupported",t))}
|
|
123
151
|
</video>
|
|
124
152
|
<div class="absolute inset-0 bg-black bg-opacity-20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center pointer-events-none">
|
|
125
153
|
<div class="bg-white bg-opacity-90 rounded-full p-3">
|
|
@@ -129,27 +157,27 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
129
157
|
</div>
|
|
130
158
|
</div>
|
|
131
159
|
</div>
|
|
132
|
-
`:
|
|
160
|
+
`:c.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">${U(r)}</div></div></div>`}catch(f){console.warn("getThumbnail failed for video",e,f),c.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">${U(r)}</div></div></div>`}else c.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">${U(r)}</div></div></div>`;else{const f=s?"\u{1F3A8}":"\u{1F4C1}",h=s?"PSD File":"Document";s?c.innerHTML=`
|
|
133
161
|
<div class="flex items-center space-x-3">
|
|
134
|
-
<div class="text-3xl text-gray-400">${
|
|
162
|
+
<div class="text-3xl text-gray-400">${f}</div>
|
|
135
163
|
<div class="flex-1 min-w-0">
|
|
136
|
-
<div class="text-sm font-medium text-gray-900 truncate">${
|
|
137
|
-
<div class="text-xs text-gray-500">${
|
|
164
|
+
<div class="text-sm font-medium text-gray-900 truncate">${U(r)}</div>
|
|
165
|
+
<div class="text-xs text-gray-500">${h}</div>
|
|
138
166
|
</div>
|
|
139
167
|
</div>
|
|
140
|
-
`:
|
|
168
|
+
`:c.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">${U(r)}</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=r;const m=document.createElement("button");return m.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",m.textContent=w("downloadButton",t),m.onclick=f=>{f.preventDefault(),f.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,r):on(e,r,t)},u.appendChild(c),u.appendChild(p),u.appendChild(m),u}function Ge(e,t,n,o,a,l){ve(e);const r=()=>{const p=[w("clickDragTextMultiple",n)];return a&&p.push(a),l&&p.push(l),p.join(" \u2022 ")},s=!e.classList.contains("grid");if((!t||t.length===0)&&s){const p=document.createElement("div");p.className="grid grid-cols-4 gap-3 mb-3";for(let f=0;f<4;f++){const h=document.createElement("div");h.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 g=document.createElementNS("http://www.w3.org/2000/svg","svg");g.setAttribute("class","w-12 h-12 text-gray-400"),g.setAttribute("fill","currentColor"),g.setAttribute("viewBox","0 0 24 24");const E=document.createElementNS("http://www.w3.org/2000/svg","path");E.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"),g.appendChild(E),h.appendChild(g),h.onclick=()=>{let v=e.parentElement;for(;v&&!v.classList.contains("space-y-2");)v=v.parentElement;!v&&e.classList.contains("space-y-2")&&(v=e);const C=v==null?void 0:v.querySelector('input[type="file"]');C&&C.click()},p.appendChild(h)}const m=document.createElement("div");m.className="text-center text-xs text-gray-500 mt-2",m.textContent=r(),e.appendChild(p),e.appendChild(m);return}const u=document.createElement("div");u.className="files-list grid grid-cols-4 gap-3";const c=t?t.length:0,d=(Math.floor(c/4)+1)*4;for(let p=0;p<d;p++){const m=document.createElement("div");if(t&&p<t.length){const f=t[p],h=n.resourceIndex.get(f);if(m.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",m.dataset.resourceId=f,nn(m,f,h,n).catch(g=>{console.error("Failed to render thumbnail:",g),m.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
141
169
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
142
|
-
<div class="text-xs">${
|
|
143
|
-
</div>`}),o){const
|
|
144
|
-
<svg class="${
|
|
170
|
+
<div class="text-xs">${U(w("previewError",n))}</div>
|
|
171
|
+
</div>`}),o){const g=document.createElement("div");g.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const E=document.createElement("button");E.className="bg-red-600 text-white px-2 py-1 rounded text-xs",E.textContent=w("removeElement",n),E.onclick=v=>{v.stopPropagation(),o(f)},g.appendChild(E),m.appendChild(g)}}else m.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",m.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>',m.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()};u.appendChild(m)}e.appendChild(u);const i=document.createElement("div");i.className="text-center text-xs text-gray-500 mt-2",i.textContent=r(),e.appendChild(i)}function Xe(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
172
|
+
<svg class="${U(n)} text-red-400" fill="currentColor" viewBox="0 0 24 24">
|
|
145
173
|
<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"/>
|
|
146
174
|
</svg>
|
|
147
|
-
<div class="text-xs mt-1 text-red-600">${
|
|
148
|
-
</div>`}async function
|
|
175
|
+
<div class="text-xs mt-1 text-red-600">${U(w("previewError",t))}</div>
|
|
176
|
+
</div>`}async function nn(e,t,n,o){var a,l;if(n&&(a=n.type)!=null&&a.startsWith("image/"))if(n.file&&n.file instanceof File){const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n.name;const s=new FileReader;s.onload=u=>{var c;r.src=((c=u.target)==null?void 0:c.result)||""},s.readAsDataURL(n.file),e.appendChild(r)}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);if(r){const s=document.createElement("img");s.className="w-full h-full object-contain",s.alt=n.name,s.src=r,e.appendChild(s)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
149
177
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
150
178
|
<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"/>
|
|
151
179
|
</svg>
|
|
152
|
-
</div>`}catch(r){const
|
|
180
|
+
</div>`}catch(r){const s=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(s,t),Xe(e,o)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
153
181
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
154
182
|
<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"/>
|
|
155
183
|
</svg>
|
|
@@ -181,24 +209,24 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
181
209
|
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
182
210
|
<path d="M8 5v14l11-7z"/>
|
|
183
211
|
</svg>
|
|
184
|
-
<div class="text-xs mt-1">${
|
|
185
|
-
</div>`}catch(r){const
|
|
212
|
+
<div class="text-xs mt-1">${U((n==null?void 0:n.name)||"Video")}</div>
|
|
213
|
+
</div>`}catch(r){const s=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(s,t),Xe(e,o,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
186
214
|
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
187
215
|
<path d="M8 5v14l11-7z"/>
|
|
188
216
|
</svg>
|
|
189
|
-
<div class="text-xs mt-1">${
|
|
217
|
+
<div class="text-xs mt-1">${U((n==null?void 0:n.name)||"Video")}</div>
|
|
190
218
|
</div>`;else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
191
219
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
192
|
-
<div class="text-xs">${
|
|
193
|
-
</div>`}function
|
|
220
|
+
<div class="text-xs">${U((n==null?void 0:n.name)||"File")}</div>
|
|
221
|
+
</div>`}function He(e,t,n){const o=n?`<div class="text-xs text-gray-500 mt-1">${U(n)}</div>`:"";e.innerHTML=`
|
|
194
222
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
195
223
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
196
224
|
<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"/>
|
|
197
225
|
</svg>
|
|
198
|
-
<div class="text-sm text-center">${
|
|
226
|
+
<div class="text-sm text-center">${U(w("clickDragText",t))}</div>
|
|
199
227
|
${o}
|
|
200
228
|
</div>
|
|
201
|
-
`}async function se(e,t,n,o,a=null,l){var r,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(d){const c=d instanceof Error?d:new Error(String(d));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 u=(r=t.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');u||(u=document.createElement("input"),u.type="hidden",u.name=n,(i=t.parentElement)==null||i.appendChild(u)),u.value=s,le(t,s,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,s)}function Y(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 it(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 l=document.createElement("button");l.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",l.textContent=$("removeElement",t),l.onclick=r=>{r.stopPropagation(),n()},a.appendChild(l),e.appendChild(a)}async function ce(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 st(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,l=await fetch(a);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const r=await l.blob();ct(r,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 ct(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 ue(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",l=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let r="application/octet-stream";l&&(["jpg","jpeg","png","gif","webp"].includes(l)?r=`image/${l==="jpg"?"jpeg":l}`:["mp4","webm","mov","avi"].includes(l)&&(r=`video/${l==="mov"?"quicktime":l}`)),t.resourceIndex.set(n,{name:a,type:r,size:0,uploadedAt:new Date,file:void 0})}})}function ut(e,t,n,o,a,l){var r;if(!a.resourceIndex.has(e)){const s=e.split("/").pop()||"file",u=(r=s.split(".").pop())==null?void 0:r.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),a.resourceIndex.set(e,{name:s,type:d,size:0,uploadedAt:new Date,file:void 0})}le(t,e,a,{fileName:e,isReadonly:!1,deps:l}).catch(console.error);const i=document.createElement("input");i.type="hidden",i.name=n,i.value=e,o.appendChild(i)}function de(e,t,n,o,a,l){Y(e,async r=>{const i=Array.from(r);for(const s of i){const u=await ce(s,n);n.resourceIndex.set(u,{name:s.name,type:s.type,size:s.size,uploadedAt:new Date,file:void 0}),t.push(u)}o(),l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)})}function fe(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const i=await ce(r,n);n.resourceIndex.set(i,{name:r.name,type:r.type,size:r.size,uploadedAt:new Date,file:void 0}),t.push(i)}o(),e.value="",l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)}}function dt(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)_(r,l).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">${S($("previewUnavailable",l))}</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">${S($("noFileSelected",l))}</div>`,n.appendChild(i)}}else{const r=document.createElement("div");r.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(h=>`.${h}`).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 u=t.prefill[e.key],d=()=>i.click(),c=h=>{if(h.length>0){const f={picker:i,fileUploadHandler:d,dragHandler:c};se(h[0],s,o,l,f,t.instance)}};if(u)ut(u,s,o,r,l,{picker:i,fileUploadHandler:d,dragHandler:c});else{const h=T(e,l);J(s,l,h)}s.onclick=d,Y(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const h={picker:i,fileUploadHandler:d,dragHandler:c};se(i.files[0],s,o,l,h,t.instance)}},r.appendChild(s),r.appendChild(i),n.appendChild(r)}}function ft(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=document.createElement("div");r.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(s=>{_(s,l).then(u=>{r.appendChild(u)}).catch(u=>{console.error("Failed to render file preview:",u)})}):r.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${S($("noFilesSelected",l))}</div></div>`,n.appendChild(r)}else{let r=function(){ae(d,c,l,f=>{const m=c.indexOf(f);m>-1&&c.splice(m,1),r()},h)};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(f=>`.${f}`).join(","))||"");const u=document.createElement("div");u.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const d=document.createElement("div");d.className="files-list";const c=t.prefill[e.key]||[];ue(c,l);const h=T(e,l);r(),de(u,c,l,r,o,t.instance),fe(s,c,l,r,o,t.instance),u.appendChild(d),i.appendChild(u),i.appendChild(s),n.appendChild(i)}}function pt(e,t,n,o){var a,l,r;const i=t.state,s=(a=e.minCount)!=null?a:0,u=(l=e.maxCount)!=null?l:1/0;if(i.config.readonly){const d=document.createElement("div");d.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(h=>{_(h,i).then(f=>{d.appendChild(f)}).catch(f=>{console.error("Failed to render file preview:",f)})}):d.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${S($("noFilesSelected",i))}</div></div>`,n.appendChild(d)}else{const d=document.createElement("div");d.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:((r=e.accept.extensions)==null?void 0:r.map(E=>`.${E}`).join(","))||"");const h=document.createElement("div");h.className="files-list space-y-2",d.appendChild(c),d.appendChild(h);const f=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];ue(f,i);const m=T(e,i),g=()=>{const E=f.length===1?$("fileCountSingle",i,{count:f.length}):$("fileCountPlural",i,{count:f.length}),p=s>0||u<1/0?` ${$("fileCountRange",i,{min:s,max:u})}`:"";return E+p},v=()=>{ae(h,f,i,E=>{f.splice(f.indexOf(E),1),v()},m,g())};de(h,f,i,v,o,t.instance),fe(c,f,i,v,o,t.instance),v(),n.appendChild(d)}}function pe(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r,path:i}=n,s=e.type==="files"||"multiple"in e&&!!e.multiple,u=(d,c,h)=>{var f,m;if(r)return;const{state:g}=n,v="minCount"in h&&(f=h.minCount)!=null?f:0,E="maxCount"in h&&(m=h.maxCount)!=null?m:1/0;h.required&&c.length===0&&a.push(`${d}: ${$("required",g)}`),c.length<v&&a.push(`${d}: ${$("minFiles",g,{min:v})}`),c.length>E&&a.push(`${d}: ${$("maxFiles",g,{max:E})}`)};if(s){const d=M(i,t),c=l.querySelector(`input[type="file"][name="${d}"]`),h=c==null?void 0:c.closest(".space-y-2"),f=(h==null?void 0:h.querySelector(".files-list"))||null,m=[];return f&&f.querySelectorAll(".resource-pill").forEach(g=>{const v=g.dataset.resourceId;v&&m.push(v)}),u(t,m,e),{value:m,errors:a}}else{const d=l.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=d==null?void 0:d.value)!=null?o:"";return!r&&e.required&&c===""?(a.push(`${t}: ${$("required",n.state)}`),{value:null,errors:a}):{value:c||null,errors:a}}}function me(e,t,n,o){var a;const{scopeRoot:l,state:r}=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"&&!r.resourceIndex.has(i)){const u=i.split("/").pop()||"file",d=(s=u.split(".").pop())==null?void 0:s.toLowerCase();let c="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?c=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(c=`video/${d==="mov"?"quicktime":d}`)),r.resourceIndex.set(i,{name:u,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=l.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(!r.resourceIndex.has(n)){const s=n.split("/").pop()||"file",u=(a=s.split(".").pop())==null?void 0:a.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),r.resourceIndex.set(n,{name:s,type:d,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function B(e){return e?e.toUpperCase():"#000000"}function G(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function he(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 ve(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=B(e),o=document.createElement("div");o.style.cssText=`
|
|
229
|
+
`}async function Ze(e,t,n,o,a=null,l){var r,s;let u;if(o.config.uploadFile)try{if(u=await o.config.uploadFile(e),typeof u!="string")throw new Error("Upload handler must return a string resource ID")}catch(d){const i=d instanceof Error?d:new Error(String(d));throw o.config.onUploadError&&o.config.onUploadError(i,e),new Error(`File upload failed: ${i.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(u,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let c=(r=t.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');c||(c=document.createElement("input"),c.type="hidden",c.name=n,(s=t.parentElement)==null||s.appendChild(c)),c.value=u,Ye(t,u,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,u)}function Be(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 rn(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 l=document.createElement("button");l.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",l.textContent=w("removeElement",t),l.onclick=r=>{r.stopPropagation(),n()},a.appendChild(l),e.appendChild(a)}async function Qe(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 on(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,l=await fetch(a);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const r=await l.blob();ln(r,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 ln(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 et(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",l=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let r="application/octet-stream";l&&(["jpg","jpeg","png","gif","webp"].includes(l)?r=`image/${l==="jpg"?"jpeg":l}`:["mp4","webm","mov","avi"].includes(l)&&(r=`video/${l==="mov"?"quicktime":l}`)),t.resourceIndex.set(n,{name:a,type:r,size:0,uploadedAt:new Date,file:void 0})}})}function an(e,t,n,o,a,l){var r;if(!a.resourceIndex.has(e)){const u=e.split("/").pop()||"file",c=(r=u.split(".").pop())==null?void 0:r.toLowerCase();let d="application/octet-stream";c&&(["jpg","jpeg","png","gif","webp"].includes(c)?d=`image/${c==="jpg"?"jpeg":c}`:["mp4","webm","mov","avi"].includes(c)&&(d=`video/${c==="mov"?"quicktime":c}`)),a.resourceIndex.set(e,{name:u,type:d,size:0,uploadedAt:new Date,file:void 0})}Ye(t,e,a,{fileName:e,isReadonly:!1,deps:l}).catch(console.error);const s=document.createElement("input");s.type="hidden",s.name=n,s.value=e,o.appendChild(s)}function tt(e,t,n,o,a,l){Be(e,async r=>{const s=Array.from(r);for(const u of s){const c=await Qe(u,n);n.resourceIndex.set(c,{name:u.name,type:u.type,size:u.size,uploadedAt:new Date,file:void 0}),t.push(c)}o(),l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)})}function nt(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const s=await Qe(r,n);n.resourceIndex.set(s,{name:r.name,type:r.type,size:r.size,uploadedAt:new Date,file:void 0}),t.push(s)}o(),e.value="",l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)}}function sn(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)Me(r,l).then(s=>{n.appendChild(s)}).catch(s=>{console.error("Failed to render file preview:",s);const u=document.createElement("div");u.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",u.innerHTML=`<div class="text-center">${U(w("previewUnavailable",l))}</div>`,n.appendChild(u)});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">${U(w("noFileSelected",l))}</div>`,n.appendChild(s)}}else{const r=document.createElement("div");r.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(p=>`.${p}`).join(","))||"");const u=document.createElement("div");u.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const c=t.prefill[e.key],d=()=>s.click(),i=p=>{if(p.length>0){const m={picker:s,fileUploadHandler:d,dragHandler:i};Ze(p[0],u,o,l,m,t.instance)}};if(c)an(c,u,o,r,l,{picker:s,fileUploadHandler:d,dragHandler:i});else{const p=ne(e,l);He(u,l,p)}u.onclick=d,Be(u,i),s.onchange=()=>{if(s.files&&s.files.length>0){const p={picker:s,fileUploadHandler:d,dragHandler:i};Ze(s.files[0],u,o,l,p,t.instance)}},r.appendChild(u),r.appendChild(s),n.appendChild(r)}}function cn(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=document.createElement("div");r.className="space-y-4";const s=t.prefill[e.key]||[];s.length>0?s.forEach(u=>{Me(u,l).then(c=>{r.appendChild(c)}).catch(c=>{console.error("Failed to render file preview:",c)})}):r.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${U(w("noFilesSelected",l))}</div></div>`,n.appendChild(r)}else{let r=function(){Ge(d,i,l,m=>{const f=i.indexOf(m);f>-1&&i.splice(f,1),r()},p)};const s=document.createElement("div");s.className="space-y-2";const u=document.createElement("input");u.type="file",u.name=o,u.multiple=!0,u.style.display="none",e.accept&&(u.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(m=>`.${m}`).join(","))||"");const c=document.createElement("div");c.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const d=document.createElement("div");d.className="files-list";const i=t.prefill[e.key]||[];et(i,l);const p=ne(e,l);r(),tt(c,i,l,r,o,t.instance),nt(u,i,l,r,o,t.instance),c.appendChild(d),s.appendChild(c),s.appendChild(u),n.appendChild(s)}}function un(e,t,n,o){var a,l,r;const s=t.state,u=(a=e.minCount)!=null?a:0,c=(l=e.maxCount)!=null?l:1/0;if(s.config.readonly){const d=document.createElement("div");d.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(p=>{Me(p,s).then(m=>{d.appendChild(m)}).catch(m=>{console.error("Failed to render file preview:",m)})}):d.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${U(w("noFilesSelected",s))}</div></div>`,n.appendChild(d)}else{const d=document.createElement("div");d.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:((r=e.accept.extensions)==null?void 0:r.map(E=>`.${E}`).join(","))||"");const p=document.createElement("div");p.className="files-list space-y-2",d.appendChild(i),d.appendChild(p);const m=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];et(m,s);const f=ne(e,s),h=()=>{const E=m.length===1?w("fileCountSingle",s,{count:m.length}):w("fileCountPlural",s,{count:m.length}),v=u>0||c<1/0?` ${w("fileCountRange",s,{min:u,max:c})}`:"";return E+v},g=()=>{Ge(p,m,s,E=>{m.splice(m.indexOf(E),1),g()},f,h())};tt(p,m,s,g,o,t.instance),nt(i,m,s,g,o,t.instance),g(),n.appendChild(d)}}function rt(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r,path:s}=n,u=e.type==="files"||"multiple"in e&&!!e.multiple,c=(d,i,p)=>{var m,f;if(r)return;const{state:h}=n,g="minCount"in p&&(m=p.minCount)!=null?m:0,E="maxCount"in p&&(f=p.maxCount)!=null?f:1/0;p.required&&i.length===0&&a.push(`${d}: ${w("required",h)}`),i.length<g&&a.push(`${d}: ${w("minFiles",h,{min:g})}`),i.length>E&&a.push(`${d}: ${w("maxFiles",h,{max:E})}`)};if(u){const d=pe(s,t),i=l.querySelector(`input[type="file"][name="${d}"]`),p=i==null?void 0:i.closest(".space-y-2"),m=(p==null?void 0:p.querySelector(".files-list"))||null,f=[];return m&&m.querySelectorAll(".resource-pill").forEach(h=>{const g=h.dataset.resourceId;g&&f.push(g)}),c(t,f,e),{value:f,errors:a}}else{const d=l.querySelector(`input[name$="${t}"][type="hidden"]`),i=(o=d==null?void 0:d.value)!=null?o:"";return!r&&e.required&&i===""?(a.push(`${t}: ${w("required",n.state)}`),{value:null,errors:a}):{value:i||null,errors:a}}}function ot(e,t,n,o){var a;const{scopeRoot:l,state:r}=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 u;if(s&&typeof s=="string"&&!r.resourceIndex.has(s)){const c=s.split("/").pop()||"file",d=(u=c.split(".").pop())==null?void 0:u.toLowerCase();let i="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?i=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(i=`video/${d==="mov"?"quicktime":d}`)),r.resourceIndex.set(s,{name:c,type:i,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const s=l.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(!r.resourceIndex.has(n)){const u=n.split("/").pop()||"file",c=(a=u.split(".").pop())==null?void 0:a.toLowerCase();let d="application/octet-stream";c&&(["jpg","jpeg","png","gif","webp"].includes(c)?d=`image/${c==="jpg"?"jpeg":c}`:["mp4","webm","mov","avi"].includes(c)&&(d=`video/${c==="mov"?"quicktime":c}`)),r.resourceIndex.set(n,{name:u,type:d,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function me(e){return e?e.toUpperCase():"#000000"}function Re(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function lt(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 at(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=me(e),o=document.createElement("div");o.style.cssText=`
|
|
202
230
|
width: 32px;
|
|
203
231
|
height: 32px;
|
|
204
232
|
border-radius: var(--fb-border-radius);
|
|
@@ -208,7 +236,7 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
208
236
|
font-size: var(--fb-font-size);
|
|
209
237
|
color: var(--fb-text-color);
|
|
210
238
|
font-family: var(--fb-font-family-mono, monospace);
|
|
211
|
-
`,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function
|
|
239
|
+
`,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function it(e,t,n){const o=me(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
|
|
212
240
|
display: flex;
|
|
213
241
|
align-items: center;
|
|
214
242
|
gap: 8px;
|
|
@@ -231,49 +259,49 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
231
259
|
font-size: var(--fb-font-size);
|
|
232
260
|
font-family: var(--fb-font-family-mono, monospace);
|
|
233
261
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
234
|
-
`;const
|
|
262
|
+
`;const s=document.createElement("input");return s.type="color",s.className="colour-picker-hidden",s.value=o.toLowerCase(),s.style.cssText=`
|
|
235
263
|
position: absolute;
|
|
236
264
|
opacity: 0;
|
|
237
265
|
pointer-events: none;
|
|
238
|
-
`,r.addEventListener("input",()=>{const
|
|
266
|
+
`,r.addEventListener("input",()=>{const u=r.value.trim();if(Re(u)){const c=lt(u);l.style.backgroundColor=c,s.value=c.toLowerCase(),r.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,c)}else r.classList.add("invalid")}),r.addEventListener("blur",()=>{const u=r.value.trim();if(Re(u)){const c=lt(u);r.value=c,l.style.backgroundColor=c,s.value=c.toLowerCase(),r.classList.remove("invalid")}}),s.addEventListener("change",()=>{const u=me(s.value);r.value=u,l.style.backgroundColor=u,n.instance&&n.instance.triggerOnChange(t,u)}),l.addEventListener("click",()=>{s.click()}),l.addEventListener("mouseenter",()=>{l.style.borderColor="var(--fb-border-hover-color)"}),l.addEventListener("mouseleave",()=>{l.style.borderColor="var(--fb-border-color)"}),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.appendChild(l),a.appendChild(r),a.appendChild(s),a}function dn(e,t,n,o){const a=t.state,l=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const r=at(l);n.appendChild(r)}else{const r=it(l,o,t);n.appendChild(r)}if(!a.config.readonly){const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
|
|
239
267
|
font-size: var(--fb-font-size-small);
|
|
240
268
|
color: var(--fb-text-secondary-color);
|
|
241
|
-
`,r.textContent=
|
|
269
|
+
`,r.textContent=ne(e,a),n.appendChild(r)}}function pn(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],c=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;u.length<c;)u.push(e.default||"#000000");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function p(){i.querySelectorAll(".multiple-colour-item").forEach((v,C)=>{const b=v.querySelector("input");b&&(b.name=`${o}[${C}]`)})}function m(v="#000000",C=-1){const b=document.createElement("div");if(b.className="multiple-colour-item flex items-center gap-2",r.config.readonly){const y=at(v);for(;y.firstChild;)b.appendChild(y.firstChild)}else{const y=`${o}[${i.children.length}]`,x=it(v,y,t);x.style.flex="1",b.appendChild(x)}return C===-1?i.appendChild(b):i.insertBefore(b,i.children[C]),p(),b}function f(){if(r.config.readonly)return;const v=i.querySelectorAll(".multiple-colour-item"),C=v.length;v.forEach(b=>{let y=b.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn px-2 py-1 rounded",y.style.cssText=`
|
|
242
270
|
color: var(--fb-error-color);
|
|
243
271
|
background-color: transparent;
|
|
244
272
|
transition: background-color var(--fb-transition-duration);
|
|
245
|
-
`,
|
|
273
|
+
`,y.innerHTML="\u2715",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{const k=Array.from(i.children).indexOf(b);i.children.length>c&&(u.splice(k,1),b.remove(),p(),E(),f())},b.appendChild(y));const x=C<=c;y.disabled=x,y.style.opacity=x?"0.5":"1",y.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-colour-btn px-3 py-1 rounded",v.style.cssText=`
|
|
246
274
|
color: var(--fb-primary-color);
|
|
247
275
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
248
276
|
background-color: transparent;
|
|
249
277
|
font-size: var(--fb-font-size);
|
|
250
278
|
transition: all var(--fb-transition-duration);
|
|
251
|
-
`,
|
|
279
|
+
`,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{const C=e.default||"#000000";u.push(C),m(C),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-colour-btn");if(v){const C=u.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${u.length}/${d===1/0?"\u221E":d}`}if(u.forEach(v=>m(v)),E(),f(),!r.config.readonly){const v=document.createElement("p");v.className="mt-1",v.style.cssText=`
|
|
252
280
|
font-size: var(--fb-font-size-small);
|
|
253
281
|
color: var(--fb-text-secondary-color);
|
|
254
|
-
`,
|
|
282
|
+
`,v.textContent=ne(e,r),n.appendChild(v)}}function fn(e,t,n){var o,a,l;const r=[],{scopeRoot:s,skipValidation:u}=n,c=(i,p)=>{var m,f;if(!i)return;const h=`error-${i.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(h);p?(i.classList.add("invalid"),i.title=p,g||(g=document.createElement("div"),g.id=h,g.className="error-message",g.style.cssText=`
|
|
255
283
|
color: var(--fb-error-color);
|
|
256
284
|
font-size: var(--fb-font-size-small);
|
|
257
285
|
margin-top: 0.25rem;
|
|
258
|
-
`,
|
|
286
|
+
`,i.nextSibling?(m=i.parentNode)==null||m.insertBefore(g,i.nextSibling):(f=i.parentNode)==null||f.appendChild(g)),g.textContent=p,g.style.display="block"):(i.classList.remove("invalid"),i.title="",g&&g.remove())},d=(i,p,m)=>{const{state:f}=n;if(!p){if(!u&&e.required){const g=w("required",f);return r.push(`${m}: ${g}`),c(i,g),""}return c(i,null),""}const h=me(p);if(!u&&!Re(h)){const g=w("invalidHexColour",f);return r.push(`${m}: ${g}`),c(i,g),p}return c(i,null),h};if(e.multiple){const i=s.querySelectorAll(`[name^="${t}["].colour-hex-input`),p=[];if(i.forEach((m,f)=>{var h;const g=(h=m==null?void 0:m.value)!=null?h:"",E=d(m,g,`${t}[${f}]`);p.push(E)}),!u){const{state:m}=n,f=(o=e.minCount)!=null?o:1,h=(a=e.maxCount)!=null?a:1/0,g=p.filter(E=>E!=="");e.required&&g.length===0&&r.push(`${t}: ${w("required",m)}`),g.length<f&&r.push(`${t}: ${w("minItems",m,{min:f})}`),g.length>h&&r.push(`${t}: ${w("maxItems",m,{max:h})}`)}return{value:p,errors:r}}else{const i=s.querySelector(`[name="${t}"].colour-hex-input`),p=(l=i==null?void 0:i.value)!=null?l:"";if(!u&&e.required&&p===""){const m=w("required",n.state);return r.push(`${t}: ${m}`),c(i,m),{value:"",errors:r}}return{value:d(i,p,t),errors:r}}}function mn(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 l=a.querySelectorAll(`[name^="${t}["].colour-hex-input`);l.forEach((r,s)=>{if(s<n.length){const u=me(n[s]);r.value=u,r.classList.remove("invalid"),r.title="";const c=r.closest(".colour-picker-wrapper");if(c){const d=c.querySelector(".colour-swatch"),i=c.querySelector(".colour-picker-hidden");d&&(d.style.backgroundColor=u),i&&(i.value=u.toLowerCase())}}}),n.length!==l.length&&console.warn(`updateColourField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"].colour-hex-input`);if(l){const r=me(n);l.value=r,l.classList.remove("invalid"),l.title="";const s=l.closest(".colour-picker-wrapper");if(s){const u=s.querySelector(".colour-swatch"),c=s.querySelector(".colour-picker-hidden");u&&(u.style.backgroundColor=r),c&&(c.value=r.toLowerCase())}}}}function st(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 ze(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 ke(e,t){return Math.round(e/t)*t}function ct(e,t,n,o,a){var l;const r=document.createElement("div");r.className="slider-container";const s=document.createElement("div");s.className="flex items-start gap-3";const u=document.createElement("div");u.className="flex-1";const c=document.createElement("input");c.type="range",c.name=t,c.className="slider-input w-full",c.disabled=a;const d=n.scale||"linear",i=n.min,p=n.max,m=(l=n.step)!=null?l:1;if(d==="exponential"){if(i<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${i})`);c.min="0",c.max="1000",c.step="1";const v=ze(e,i,p);c.value=(v*1e3).toString()}else c.min=i.toString(),c.max=p.toString(),c.step=m.toString(),c.value=e.toString();c.style.cssText=`
|
|
259
287
|
height: 6px;
|
|
260
288
|
border-radius: 3px;
|
|
261
289
|
background: linear-gradient(
|
|
262
290
|
to right,
|
|
263
291
|
var(--fb-primary-color) 0%,
|
|
264
|
-
var(--fb-primary-color) ${(e-
|
|
265
|
-
var(--fb-border-color) ${(e-
|
|
292
|
+
var(--fb-primary-color) ${(e-i)/(p-i)*100}%,
|
|
293
|
+
var(--fb-border-color) ${(e-i)/(p-i)*100}%,
|
|
266
294
|
var(--fb-border-color) 100%
|
|
267
295
|
);
|
|
268
296
|
outline: none;
|
|
269
297
|
transition: background 0.1s ease-in-out;
|
|
270
298
|
cursor: ${a?"not-allowed":"pointer"};
|
|
271
299
|
opacity: ${a?"0.6":"1"};
|
|
272
|
-
`,
|
|
300
|
+
`,u.appendChild(c);const f=document.createElement("div");f.className="flex justify-between",f.style.cssText=`
|
|
273
301
|
font-size: var(--fb-font-size-small);
|
|
274
302
|
color: var(--fb-text-secondary-color);
|
|
275
303
|
margin-top: 4px;
|
|
276
|
-
`;const
|
|
304
|
+
`;const h=document.createElement("span");h.textContent=i.toString();const g=document.createElement("span");g.textContent=p.toString(),f.appendChild(h),f.appendChild(g),u.appendChild(f);const E=document.createElement("span");if(E.className="slider-value",E.style.cssText=`
|
|
277
305
|
min-width: 60px;
|
|
278
306
|
text-align: right;
|
|
279
307
|
font-size: var(--fb-font-size);
|
|
@@ -281,69 +309,131 @@ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.loc
|
|
|
281
309
|
font-family: var(--fb-font-family-mono, monospace);
|
|
282
310
|
font-weight: 500;
|
|
283
311
|
padding-top: 2px;
|
|
284
|
-
`,E.textContent=e.toFixed(
|
|
312
|
+
`,E.textContent=e.toFixed(m<1?2:0),s.appendChild(u),s.appendChild(E),r.appendChild(s),!a){const v=()=>{let C;if(d==="exponential"){const y=parseFloat(c.value)/1e3;C=st(y,i,p),C=ke(C,m),C=Math.max(i,Math.min(p,C))}else C=parseFloat(c.value),C=ke(C,m);E.textContent=C.toFixed(m<1?2:0);const b=(C-i)/(p-i)*100;c.style.background=`linear-gradient(
|
|
285
313
|
to right,
|
|
286
314
|
var(--fb-primary-color) 0%,
|
|
287
|
-
var(--fb-primary-color) ${
|
|
288
|
-
var(--fb-border-color) ${
|
|
315
|
+
var(--fb-primary-color) ${b}%,
|
|
316
|
+
var(--fb-border-color) ${b}%,
|
|
289
317
|
var(--fb-border-color) 100%
|
|
290
|
-
)`,o.instance&&o.instance.triggerOnChange(t,C)};
|
|
318
|
+
)`,o.instance&&o.instance.triggerOnChange(t,C)};c.addEventListener("input",v),c.addEventListener("change",v)}return r}function hn(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 l=t.state,r=e.default!==void 0?e.default:(e.min+e.max)/2,s=(a=t.prefill[e.key])!=null?a:r,u=ct(s,o,e,t,l.config.readonly);if(n.appendChild(u),!l.config.readonly){const c=document.createElement("p");c.className="mt-1",c.style.cssText=`
|
|
291
319
|
font-size: var(--fb-font-size-small);
|
|
292
320
|
color: var(--fb-text-secondary-color);
|
|
293
|
-
`,
|
|
321
|
+
`,c.textContent=ne(e,l),n.appendChild(c)}}function vn(e,t,n,o){var a,l;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,s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],c=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0,i=e.default!==void 0?e.default:(e.min+e.max)/2;for(;u.length<c;)u.push(i);const p=document.createElement("div");p.className="space-y-3",n.appendChild(p);function m(){p.querySelectorAll(".multiple-slider-item").forEach((C,b)=>{const y=C.querySelector("input[type=range]");y&&y.setAttribute("name",`${o}[${b}]`)})}function f(C=i,b=-1){const y=document.createElement("div");y.className="multiple-slider-item flex items-start gap-2";const x=`${o}[${p.children.length}]`,k=ct(C,x,e,t,r.config.readonly);return k.style.flex="1",y.appendChild(k),b===-1?p.appendChild(y):p.insertBefore(y,p.children[b]),m(),y}function h(){if(r.config.readonly)return;const C=p.querySelectorAll(".multiple-slider-item"),b=C.length;C.forEach(y=>{let x=y.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn px-2 py-1 rounded",x.style.cssText=`
|
|
294
322
|
color: var(--fb-error-color);
|
|
295
323
|
background-color: transparent;
|
|
296
324
|
transition: background-color var(--fb-transition-duration);
|
|
297
325
|
margin-top: 8px;
|
|
298
|
-
`,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const
|
|
326
|
+
`,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const A=Array.from(p.children).indexOf(y);p.children.length>c&&(u.splice(A,1),y.remove(),m(),v(),h())},y.appendChild(x));const k=b<=c;x.disabled=k,x.style.opacity=k?"0.5":"1",x.style.pointerEvents=k?"none":"auto"})}let g=null,E=null;if(!r.config.readonly){g=document.createElement("div"),g.className="flex items-center gap-3 mt-2";const C=document.createElement("button");C.type="button",C.className="add-slider-btn px-3 py-1 rounded",C.style.cssText=`
|
|
299
327
|
color: var(--fb-primary-color);
|
|
300
328
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
301
329
|
background-color: transparent;
|
|
302
330
|
font-size: var(--fb-font-size);
|
|
303
331
|
transition: all var(--fb-transition-duration);
|
|
304
|
-
`,C.textContent="+",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{
|
|
332
|
+
`,C.textContent="+",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{u.push(i),f(i),v(),h()},E=document.createElement("span"),E.className="text-sm text-gray-500",g.appendChild(C),g.appendChild(E),n.appendChild(g)}function v(){if(!g||!E)return;const C=g.querySelector(".add-slider-btn");if(C){const b=u.length>=d;C.disabled=b,C.style.opacity=b?"0.5":"1",C.style.pointerEvents=b?"none":"auto"}E.textContent=`${u.length}/${d===1/0?"\u221E":d}`}if(u.forEach(C=>f(C)),v(),h(),!r.config.readonly){const C=document.createElement("p");C.className="mt-1",C.style.cssText=`
|
|
305
333
|
font-size: var(--fb-font-size-small);
|
|
306
334
|
color: var(--fb-text-secondary-color);
|
|
307
|
-
`,C.textContent=
|
|
335
|
+
`,C.textContent=ne(e,r),n.appendChild(C)}}function gn(e,t,n){var o,a,l;const r=[],{scopeRoot:s,skipValidation:u}=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 c=e.min,d=e.max,i=(o=e.step)!=null?o:1,p=e.scale||"linear",m=(h,g)=>{var E,v;if(!h)return;const C=`error-${h.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(C);if(g){if(h.classList.add("invalid"),h.title=g,!b){b=document.createElement("div"),b.id=C,b.className="error-message",b.style.cssText=`
|
|
308
336
|
color: var(--fb-error-color);
|
|
309
337
|
font-size: var(--fb-font-size-small);
|
|
310
338
|
margin-top: 0.25rem;
|
|
311
|
-
`;const
|
|
339
|
+
`;const y=h.closest(".slider-container");y&&y.nextSibling?(E=y.parentNode)==null||E.insertBefore(b,y.nextSibling):y&&((v=y.parentNode)==null||v.appendChild(b))}b.textContent=g,b.style.display="block"}else h.classList.remove("invalid"),h.title="",b&&b.remove()},f=(h,g)=>{const{state:E}=n,v=h.value;if(!v){if(!u&&e.required){const b=w("required",E);return r.push(`${g}: ${b}`),m(h,b),null}return m(h,null),null}let C;if(p==="exponential"){const b=parseFloat(v)/1e3;C=st(b,c,d),C=ke(C,i)}else C=parseFloat(v),C=ke(C,i);if(!u){if(C<c){const b=w("minValue",E,{min:c});return r.push(`${g}: ${b}`),m(h,b),C}if(C>d){const b=w("maxValue",E,{max:d});return r.push(`${g}: ${b}`),m(h,b),C}}return m(h,null),C};if(e.multiple){const h=s.querySelectorAll(`input[type="range"][name^="${t}["]`),g=[];if(h.forEach((E,v)=>{const C=f(E,`${t}[${v}]`);g.push(C)}),!u){const{state:E}=n,v=(a=e.minCount)!=null?a:1,C=(l=e.maxCount)!=null?l:1/0,b=g.filter(y=>y!==null);e.required&&b.length===0&&r.push(`${t}: ${w("required",E)}`),b.length<v&&r.push(`${t}: ${w("minItems",E,{min:v})}`),b.length>C&&r.push(`${t}: ${w("maxItems",E,{max:C})}`)}return{value:g,errors:r}}else{const h=s.querySelector(`input[type="range"][name="${t}"]`);return h?{value:f(h,t),errors:r}:(!u&&e.required&&r.push(`${t}: ${w("required",n.state)}`),{value:null,errors:r})}}function bn(e,t,n,o){var a;const{scopeRoot:l}=o,r=e.min,s=e.max,u=(a=e.step)!=null?a:1,c=e.scale||"linear";if(e.multiple){if(!Array.isArray(n)){console.warn(`updateSliderField: Expected array for multiple field "${t}", got ${typeof n}`);return}const d=l.querySelectorAll(`input[type="range"][name^="${t}["]`);d.forEach((i,p)=>{if(p<n.length&&n[p]!==null){const m=Number(n[p]);if(c==="exponential"){const h=ze(m,r,s);i.value=(h*1e3).toString()}else i.value=m.toString();const f=i.closest(".slider-container");if(f){const h=f.querySelector(".slider-value");h&&(h.textContent=m.toFixed(u<1?2:0));const g=(m-r)/(s-r)*100;i.style.background=`linear-gradient(
|
|
312
340
|
to right,
|
|
313
341
|
var(--fb-primary-color) 0%,
|
|
314
|
-
var(--fb-primary-color) ${
|
|
315
|
-
var(--fb-border-color) ${
|
|
342
|
+
var(--fb-primary-color) ${g}%,
|
|
343
|
+
var(--fb-border-color) ${g}%,
|
|
316
344
|
var(--fb-border-color) 100%
|
|
317
|
-
)`}
|
|
345
|
+
)`}i.classList.remove("invalid"),i.title=""}}),n.length!==d.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${d.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const d=l.querySelector(`input[type="range"][name="${t}"]`);if(d&&n!==null&&n!==void 0){const i=Number(n);if(c==="exponential"){const m=ze(i,r,s);d.value=(m*1e3).toString()}else d.value=i.toString();const p=d.closest(".slider-container");if(p){const m=p.querySelector(".slider-value");m&&(m.textContent=i.toFixed(u<1?2:0));const f=(i-r)/(s-r)*100;d.style.background=`linear-gradient(
|
|
318
346
|
to right,
|
|
319
347
|
var(--fb-primary-color) 0%,
|
|
320
|
-
var(--fb-primary-color) ${
|
|
321
|
-
var(--fb-border-color) ${
|
|
348
|
+
var(--fb-primary-color) ${f}%,
|
|
349
|
+
var(--fb-border-color) ${f}%,
|
|
322
350
|
var(--fb-border-color) 100%
|
|
323
|
-
)`}d.classList.remove("invalid"),d.title=""}}}function
|
|
351
|
+
)`}d.classList.remove("invalid"),d.title=""}}}function ut(e){const t={};for(const n of e)"default"in n&&n.default!==void 0&&(t[n.key]=n.default);return t}function dt(e,t){return{...t,...e}}function Ie(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 De=null;function yn(e){De=e}function Se(e,t){if(!De)throw new Error("renderElement not initialized. Import from components/index.ts");return De(e,t)}function pt(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 l=document.createElement("button");l.type="button",l.className="fb-prefill-hint",l.textContent=o.label,l.setAttribute("data-hint-values",JSON.stringify(o.values)),l.setAttribute("data-container-key",t),l.setAttribute("data-hint-index",String(a)),n.appendChild(l)}),n}function ft(e,t,n,o){var a,l;const r=document.createElement("div");r.className="border border-gray-200 rounded-lg p-4 bg-gray-50",r.setAttribute("data-container",o);const s=document.createElement("div"),u=e.columns||1;if(u===1?s.className="space-y-4":s.className=`grid grid-cols-${u} gap-4`,!t.state.config.readonly){const m=pt(e,o);m&&r.appendChild(m)}const c=ut(e.elements),d=((a=t.prefill)==null?void 0:a[e.key])||{},i=dt(d,c),p={path:pe(t.path,e.key),prefill:i,formData:(l=t.formData)!=null?l:t.prefill,state:t.state};e.elements.forEach(m=>{m.hidden||s.appendChild(Se(m,p))}),r.appendChild(s),n.appendChild(r)}function mt(e,t,n,o){var a,l,r,s;const u=t.state,c=document.createElement("div");c.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const d=document.createElement("span");d.className="text-sm text-gray-500";const i=document.createElement("div");if(i.className="space-y-4",!t.state.config.readonly){const b=pt(e,e.key);b&&c.appendChild(b)}const p=(a=e.minCount)!=null?a:0,m=(l=e.maxCount)!=null?l:1/0,f=Array.isArray((r=t.prefill)==null?void 0:r[e.key])?t.prefill[e.key]:null,h=ut(e.elements),g=()=>i.querySelectorAll(":scope > .containerItem").length,E=()=>{const b=document.createElement("button");return b.type="button",b.className="add-container-btn px-3 py-1 rounded",b.style.cssText=`
|
|
324
352
|
color: var(--fb-primary-color);
|
|
325
353
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
326
354
|
background-color: transparent;
|
|
327
355
|
font-size: var(--fb-font-size);
|
|
328
356
|
transition: all var(--fb-transition-duration);
|
|
329
|
-
`,
|
|
357
|
+
`,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{if(g()<m){const y=g(),x=u.formRoot?Ie(u.formRoot):{},k={state:t.state,path:pe(t.path,`${e.key}[${y}]`),prefill:h,formData:x},A=document.createElement("div");A.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",A.setAttribute("data-container-item",`${e.key}[${y}]`);const q=document.createElement("div"),_=e.columns||1;if(_===1?q.className="space-y-4":q.className=`grid grid-cols-${_} gap-4`,e.elements.forEach(K=>{K.hidden||q.appendChild(Se(K,k))}),A.appendChild(q),!u.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=`
|
|
330
358
|
color: var(--fb-error-color);
|
|
331
359
|
background-color: transparent;
|
|
332
360
|
transition: background-color var(--fb-transition-duration);
|
|
333
|
-
`,
|
|
361
|
+
`,K.textContent="\u2715",K.addEventListener("mouseenter",()=>{K.style.backgroundColor="var(--fb-background-hover-color)"}),K.addEventListener("mouseleave",()=>{K.style.backgroundColor="transparent"}),K.onclick=()=>C(A),A.style.position="relative",A.appendChild(K)}i.appendChild(A),v()}},b},v=()=>{const b=g(),y=c.querySelector(".add-container-btn");y&&(y.disabled=b>=m,y.style.opacity=b>=m?"0.5":"1",y.style.pointerEvents=b>=m?"none":"auto"),d.textContent=`${b}/${m===1/0?"\u221E":m}`},C=b=>{b.remove(),v()};if(f&&Array.isArray(f)&&f.forEach((b,y)=>{var x;const k=dt(b||{},h),A={state:t.state,path:pe(t.path,`${e.key}[${y}]`),prefill:k,formData:(x=t.formData)!=null?x:t.prefill},q=document.createElement("div");q.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",q.setAttribute("data-container-item",`${e.key}[${y}]`);const _=document.createElement("div"),K=e.columns||1;if(K===1?_.className="space-y-4":_.className=`grid grid-cols-${K} gap-4`,e.elements.forEach(G=>{G.hidden||_.appendChild(Se(G,A))}),q.appendChild(_),!u.config.readonly){const G=document.createElement("button");G.type="button",G.className="absolute top-2 right-2 px-2 py-1 rounded",G.style.cssText=`
|
|
334
362
|
color: var(--fb-error-color);
|
|
335
363
|
background-color: transparent;
|
|
336
364
|
transition: background-color var(--fb-transition-duration);
|
|
337
|
-
`,
|
|
365
|
+
`,G.textContent="\u2715",G.addEventListener("mouseenter",()=>{G.style.backgroundColor="var(--fb-background-hover-color)"}),G.addEventListener("mouseleave",()=>{G.style.backgroundColor="transparent"}),G.onclick=()=>C(q),q.style.position="relative",q.appendChild(G)}i.appendChild(q)}),!u.config.readonly)for(;g()<p;){const b=g(),y={state:t.state,path:pe(t.path,`${e.key}[${b}]`),prefill:h,formData:(s=t.formData)!=null?s:t.prefill},x=document.createElement("div");x.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",x.setAttribute("data-container-item",`${e.key}[${b}]`);const k=document.createElement("div"),A=e.columns||1;A===1?k.className="space-y-4":k.className=`grid grid-cols-${A} gap-4`,e.elements.forEach(_=>{_.hidden||k.appendChild(Se(_,y))}),x.appendChild(k);const q=document.createElement("button");q.type="button",q.className="absolute top-2 right-2 px-2 py-1 rounded",q.style.cssText=`
|
|
338
366
|
color: var(--fb-error-color);
|
|
339
367
|
background-color: transparent;
|
|
340
368
|
transition: background-color var(--fb-transition-duration);
|
|
341
|
-
`,L.textContent="\u2715",L.addEventListener("mouseenter",()=>{L.style.backgroundColor="var(--fb-background-hover-color)"}),L.addEventListener("mouseleave",()=>{L.style.backgroundColor="transparent"}),L.onclick=()=>{v()>h&&C(x)},x.style.position="relative",x.appendChild(L),c.appendChild(x)}if(u.appendChild(c),!s.config.readonly){const y=document.createElement("div");y.className="flex items-center gap-3 mt-2",y.appendChild(E()),y.appendChild(d),u.appendChild(y)}p(),n.appendChild(u)}let K=null;function $t(e){K=e}function ke(e,t,n){if(!K)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return K(e,t,n)}function Le(e,t,n){const o=[],{scopeRoot:a,skipValidation:l,path:r}=n;if(!("elements"in e))return{value:null,errors:o};const i=(s,u,d)=>{var c,h;if(l)return;const{state:f}=n,m="minCount"in d&&(c=d.minCount)!=null?c:0,g="maxCount"in d&&(h=d.maxCount)!=null?h:1/0;d.required&&u.length===0&&o.push(`${s}: ${$("required",f)}`),u.length<m&&o.push(`${s}: ${$("minItems",f,{min:m})}`),u.length>g&&o.push(`${s}: ${$("maxItems",f,{max:g})}`)};if("multiple"in e&&e.multiple){const s=[],u=a.querySelectorAll("[data-container-item]");return Array.from(u).filter(d=>{const c=d.getAttribute("data-container-item")||"";if(!c.startsWith(`${t}[`))return!1;const h=c.slice(t.length);return/^\[\d+\]$/.test(h)}).forEach(d=>{const c={},h=(d.getAttribute("data-container-item")||"").match(/\[(\d+)\]$/),f=h?parseInt(h[1],10):0;e.elements.forEach(m=>{var g;if(m.enableIf)try{const v=(g=n.instance)!=null&&g.getState().formRoot?Z(n.instance.getState().formRoot):{};if(!H(m.enableIf,v,c))return}catch(v){console.error(`Error evaluating enableIf for field "${m.key}" in container "${t}[${f}]":`,v)}if(m.hidden||m.type==="hidden")c[m.key]=m.default!==void 0?m.default:null;else{const v=`${t}[${f}].${m.key}`;c[m.key]=ke({...m,key:v},{path:r},d)}}),s.push(c)}),i(t,s,e),{value:s,errors:o}}else{const s={},u=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(d=>{var c;if(d.enableIf)try{const h=(c=n.instance)!=null&&c.getState().formRoot?Z(n.instance.getState().formRoot):{};if(!H(d.enableIf,h,s))return}catch(h){console.error(`Error evaluating enableIf for field "${d.key}" in container "${t}":`,h)}if(d.hidden||d.type==="hidden")s[d.key]=d.default!==void 0?d.default:null;else{const h=`${t}.${d.key}`;s[d.key]=ke({...d,key:h},{path:r},u)}}),{value:s,errors:o}}}function Se(e,t,n,o){const{instance:a,scopeRoot:l}=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)=>{R(i)&&e.elements.forEach(u=>{const d=u.key,c=`${t}[${s}].${d}`,h=i[d];h!==void 0&&a.updateField(c,h)})});const r=l.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==r.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!R(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(r=>{const i=r.key,s=`${t}.${i}`,u=n[i];u!==void 0&&a.updateField(s,u)})}}function wt(e,t,n,o){var a,l;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 r={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&&R(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?we(r,t,n):$e(r,t,n,o)}function Fe(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&&R(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function kt(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=Fe(e);return Le(o,t,n)}function Lt(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=Fe(e);return Se(a,t,n,o)}function St(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(d=>{d.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),l=window.innerWidth,r=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,u=a.bottom+5;s+i.width>l&&(s=a.right-i.width),u+i.height>r&&(u=a.top-i.height-5),s<10&&(s=10),u<10&&(u=a.bottom+5),n.style.left=`${s}px`,n.style.top=`${u}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 Ft(e,t){var n,o,a;if(!e.enableIf)return!1;try{const l=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=((a=e.enableIf.scope)!=null?a:"relative")==="relative"&&t.path?t.prefill:void 0;return!H(e.enableIf,l,r)}catch(l){console.error(`Error evaluating enableIf for field "${e.key}":`,l)}return!1}function Nt(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 P(e,t,n){var o,a;if(!t.enableIf)return;const l=n.state.formRoot;if(!l){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const r=t.enableIf,i=(o=r.scope)!=null?o:"relative";let s={};const u={};if((!n.path||n.path===""?"absolute":i)==="relative"&&n.path){const d=n.path.match(/^(.+)\[(\d+)\]$/);if(d){const c=d[1],h=parseInt(d[2],10),f=l.querySelector(`[data-container-item="${c}[${h}]"]`);f&&f.querySelectorAll("input, select, textarea").forEach(m=>{const g=m.getAttribute("name");if(g){const v=g.match(/\.([^.[\]]+)$/);if(v){const E=v[1];m instanceof HTMLSelectElement?u[E]=m.value:m instanceof HTMLInputElement?m.type==="checkbox"?u[E]=m.checked:m.type==="radio"?m.checked&&(u[E]=m.value):u[E]=m.value:m instanceof HTMLTextAreaElement&&(u[E]=m.value)}}})}}else{const d=r.key,c=Nt(d,l);c!==void 0?s[d]=c:s=(a=n.formData)!=null?a:n.prefill}try{H(r,s,u)?(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(d){console.error(`Error re-evaluating enableIf for field "${t.key}":`,d)}}function At(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 l=t.enableIf,r=(o=l.scope)!=null?o:"relative",i=l.key;let s;r==="relative"&&n.path?s=`${n.path}.${i}`:s=i;const u=a.querySelector(`[name="${s}"]`);if(!u){const d=new MutationObserver(()=>{const c=a.querySelector(`[name="${s}"]`);c&&(c.addEventListener("change",()=>{P(e,t,n)}),c.addEventListener("input",()=>{P(e,t,n)}),d.disconnect())});d.observe(a,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{P(e,t,n)}),u.addEventListener("input",()=>{P(e,t,n)})}function Tt(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 qt(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(),St(n,t)},t}function Mt(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Tt(e);if(t.appendChild(n),e.description||e.hint){const o=qt(e);t.appendChild(o)}return t}function Ht(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?De(e,t,n,o):Re(e,t,n,o);break;case"textarea":a?Oe(e,t,n,o):je(e,t,n,o);break;case"number":a?We(e,t,n,o):Ve(e,t,n,o);break;case"select":a?Ge(e,t,n,o):Ye(e,t,n,o);break;case"file":a?pt(e,t,n,o):dt(e,t,n,o);break;case"files":ft(e,t,n,o);break;case"colour":a?ht(e,t,n,o):mt(e,t,n,o);break;case"slider":a?bt(e,t,n,o):yt(e,t,n,o);break;case"group":wt(e,t,n,o);break;case"container":a?we(e,t,n):$e(e,t,n,o);break;default:{const l=document.createElement("div");l.className="text-red-500 text-sm",l.textContent=$("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(l)}}}function ee(e,t){const n=Ft(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=Mt(e);o.appendChild(a);const l=M(t.path,e.key);return Ht(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),At(o,e,t),o}Et(ee);const te={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:{removeElement:"Remove",clickDragText:"Click or drag file",clickDragTextMultiple:"Click or drag files",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download",changeButton:"Change",placeholderText:"Enter text",previewAlt:"Preview",previewUnavailable:"Preview unavailable",previewError:"Preview error",videoNotSupported:"Your browser does not support the video tag.",hintLengthRange:"{min}-{max} chars",hintMaxLength:"\u2264{max} chars",hintMinLength:"\u2265{min} chars",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}MB",hintFormats:"{formats}",hintRequired:"Required",hintOptional:"Optional",hintPattern:"Format: {pattern}",fileCountSingle:"{count} file",fileCountPlural:"{count} files",fileCountRange:"({min}-{max})",required:"Required",minItems:"Minimum {min} items required",maxItems:"Maximum {max} items allowed",minLength:"Minimum {min} characters",maxLength:"Maximum {max} characters",minValue:"Must be at least {min}",maxValue:"Must be at most {max}",patternMismatch:"Invalid format",invalidPattern:"Invalid pattern in schema",notANumber:"Must be a number",invalidHexColour:"Invalid hex color",minFiles:"Minimum {min} files required",maxFiles:"Maximum {max} files allowed",unsupportedFieldType:"Unsupported field type: {type}"},ru:{removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",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",clickDragTextMultiple:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",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",changeButton:"\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",placeholderText:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",previewAlt:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440",previewUnavailable:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D",previewError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440\u0430",videoNotSupported:"\u0412\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043E.",hintLengthRange:"{min}-{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMaxLength:"\u2264{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMinLength:"\u2265{min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}\u041C\u0411",hintFormats:"{formats}",hintRequired:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintOptional:"\u041D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintPattern:"\u0424\u043E\u0440\u043C\u0430\u0442: {pattern}",fileCountSingle:"{count} \u0444\u0430\u0439\u043B",fileCountPlural:"{count} \u0444\u0430\u0439\u043B\u043E\u0432",fileCountRange:"({min}-{max})",required:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435",minItems:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",maxItems:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",minLength:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",maxLength:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",minValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u043C\u0435\u043D\u0435\u0435 {min}",maxValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u0431\u043E\u043B\u0435\u0435 {max}",patternMismatch:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442",invalidPattern:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043F\u0430\u0442\u0442\u0435\u0440\u043D \u0432 \u0441\u0445\u0435\u043C\u0435",notANumber:"\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0447\u0438\u0441\u043B\u043E\u043C",invalidHexColour:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u0446\u0432\u0435\u0442\u0430",minFiles:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0444\u0430\u0439\u043B\u043E\u0432",maxFiles:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0444\u0430\u0439\u043B\u043E\u0432",unsupportedFieldType:"\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u043B\u044F: {type}"}},theme:{}};function Bt(e){const t={...te.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...te.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...te,...e,translations:t},debounceTimer:null}}function It(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const z={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 zt(e){const t={...z,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const l=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${l}: ${a};`)}),n.join(`
|
|
342
|
-
|
|
369
|
+
`,q.textContent="\u2715",q.addEventListener("mouseenter",()=>{q.style.backgroundColor="var(--fb-background-hover-color)"}),q.addEventListener("mouseleave",()=>{q.style.backgroundColor="transparent"}),q.onclick=()=>{g()>p&&C(x)},x.style.position="relative",x.appendChild(q),i.appendChild(x)}if(c.appendChild(i),!u.config.readonly){const b=document.createElement("div");b.className="flex items-center gap-3 mt-2",b.appendChild(E()),b.appendChild(d),c.appendChild(b)}v(),n.appendChild(c)}let je=null;function xn(e){je=e}function ht(e,t,n){if(!je)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return je(e,t,n)}function vt(e,t,n){const o=[],{scopeRoot:a,skipValidation:l,path:r}=n;if(!("elements"in e))return{value:null,errors:o};const s=(u,c,d)=>{var i,p;if(l)return;const{state:m}=n,f="minCount"in d&&(i=d.minCount)!=null?i:0,h="maxCount"in d&&(p=d.maxCount)!=null?p:1/0;d.required&&c.length===0&&o.push(`${u}: ${w("required",m)}`),c.length<f&&o.push(`${u}: ${w("minItems",m,{min:f})}`),c.length>h&&o.push(`${u}: ${w("maxItems",m,{max:h})}`)};if("multiple"in e&&e.multiple){const u=[],c=a.querySelectorAll("[data-container-item]");return Array.from(c).filter(d=>{const i=d.getAttribute("data-container-item")||"";if(!i.startsWith(`${t}[`))return!1;const p=i.slice(t.length);return/^\[\d+\]$/.test(p)}).forEach(d=>{const i={},p=(d.getAttribute("data-container-item")||"").match(/\[(\d+)\]$/),m=p?parseInt(p[1],10):0;e.elements.forEach(f=>{var h;if(f.enableIf)try{const g=(h=n.instance)!=null&&h.getState().formRoot?Ie(n.instance.getState().formRoot):{};if(!fe(f.enableIf,g,i))return}catch(g){console.error(`Error evaluating enableIf for field "${f.key}" in container "${t}[${m}]":`,g)}if(f.hidden||f.type==="hidden")i[f.key]=f.default!==void 0?f.default:null;else{const g=`${t}[${m}].${f.key}`;i[f.key]=ht({...f,key:g},{path:r},d)}}),u.push(i)}),s(t,u,e),{value:u,errors:o}}else{const u={},c=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(d=>{var i;if(d.enableIf)try{const p=(i=n.instance)!=null&&i.getState().formRoot?Ie(n.instance.getState().formRoot):{};if(!fe(d.enableIf,p,u))return}catch(p){console.error(`Error evaluating enableIf for field "${d.key}" in container "${t}":`,p)}if(d.hidden||d.type==="hidden")u[d.key]=d.default!==void 0?d.default:null;else{const p=`${t}.${d.key}`;u[d.key]=ht({...d,key:p},{path:r},c)}}),{value:u,errors:o}}}function gt(e,t,n,o){const{instance:a,scopeRoot:l}=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,u)=>{Ce(s)&&e.elements.forEach(c=>{const d=c.key,i=`${t}[${u}].${d}`,p=s[d];p!==void 0&&a.updateField(i,p)})});const r=l.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==r.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!Ce(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(r=>{const s=r.key,u=`${t}.${s}`,c=n[s];c!==void 0&&a.updateField(u,c)})}}function Cn(e,t,n,o){var a,l;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 r={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&&Ce(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?mt(r,t,n):ft(r,t,n,o)}function bt(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&&Ce(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function En(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=bt(e);return vt(o,t,n)}function wn(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=bt(e);return gt(a,t,n,o)}function yt(e,t){return Array.from({length:e},()=>Array.from({length:t},()=>""))}function xt(e,t,n){for(const o of n){if(o.row===e&&o.col===t)return null;if(e>=o.row&&e<o.row+o.rowspan&&t>=o.col&&t<o.col+o.colspan)return o}return null}function Le(e,t,n){var o;return(o=n.find(a=>a.row===e&&a.col===t))!=null?o:null}function ie(e){var t;if(!e.anchor)return null;const n=(t=e.focus)!=null?t:e.anchor;return{r1:Math.min(e.anchor.row,n.row),c1:Math.min(e.anchor.col,n.col),r2:Math.max(e.anchor.row,n.row),c2:Math.max(e.anchor.col,n.col)}}function he(e){const t=document.createElement("button");return t.type="button",t.textContent=e.label,t.title=e.title,t.style.cssText=`
|
|
370
|
+
position: absolute;
|
|
371
|
+
width: ${e.size}px;
|
|
372
|
+
height: ${e.size}px;
|
|
373
|
+
border-radius: 50%;
|
|
374
|
+
border: none;
|
|
375
|
+
background: ${e.color};
|
|
376
|
+
color: ${e.textColor};
|
|
377
|
+
font-size: ${Math.floor(e.size*.6)}px;
|
|
378
|
+
line-height: ${e.size}px;
|
|
379
|
+
text-align: center;
|
|
380
|
+
cursor: pointer;
|
|
381
|
+
z-index: 10;
|
|
382
|
+
padding: 0;
|
|
383
|
+
display: flex;
|
|
384
|
+
align-items: center;
|
|
385
|
+
justify-content: center;
|
|
386
|
+
box-shadow: 0 1px 4px rgba(0,0,0,0.2);
|
|
387
|
+
transition: transform 0.1s, opacity 0.1s;
|
|
388
|
+
pointer-events: all;
|
|
389
|
+
`,t.addEventListener("mouseenter",()=>{t.style.transform="scale(1.15)"}),t.addEventListener("mouseleave",()=>{t.style.transform="scale(1)"}),t.addEventListener("click",n=>{n.stopPropagation(),e.onClick(n)}),t}function $n(e,t){const{cells:n,merges:o=[]}=e;if(n.length===0)return;const a=n[0].length,l=document.createElement("table");l.style.cssText=`
|
|
390
|
+
width: 100%;
|
|
391
|
+
border-collapse: collapse;
|
|
392
|
+
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
393
|
+
border-radius: var(--fb-border-radius);
|
|
394
|
+
font-size: var(--fb-font-size);
|
|
395
|
+
font-family: var(--fb-font-family);
|
|
396
|
+
color: var(--fb-text-color);
|
|
397
|
+
`,n.forEach((s,u)=>{var c,d;const i=(u===0?l.createTHead():(c=l.tBodies[0])!=null?c:l.createTBody()).insertRow();for(let p=0;p<a;p++){if(xt(u,p,o))continue;const m=Le(u,p,o),f=document.createElement(u===0?"th":"td");m&&(m.rowspan>1&&(f.rowSpan=m.rowspan),m.colspan>1&&(f.colSpan=m.colspan)),f.textContent=(d=s[p])!=null?d:"",f.style.cssText=`
|
|
398
|
+
padding: 6px 10px;
|
|
399
|
+
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
400
|
+
text-align: left;
|
|
401
|
+
vertical-align: top;
|
|
402
|
+
${u===0?"background-color: var(--fb-background-hover-color); font-weight: 600;":""}
|
|
403
|
+
`,i.appendChild(f)}});const r=document.createElement("div");r.style.cssText="overflow-x: auto; max-width: 100%;",r.appendChild(l),t.appendChild(r)}function kn(e,t,n,o,a,l){if(e.contentEditable==="true")return;e.contentEditable="true",e.focus();const r=document.createRange(),s=window.getSelection();r.selectNodeContents(e),r.collapse(!1),s==null||s.removeAllRanges(),s==null||s.addRange(r);function u(){var i;e.contentEditable="inherit";const p=o();p[t]&&(p[t][n]=(i=e.textContent)!=null?i:""),a()}function c(i){var p,m,f,h;const g=o(),E=(m=(p=g[0])==null?void 0:p.length)!=null?m:0;if(i.key==="Escape"){e.contentEditable="inherit",e.textContent=(h=(f=g[t])==null?void 0:f[n])!=null?h:"",e.removeEventListener("keydown",c),e.removeEventListener("blur",d);return}if(i.key==="Enter"&&!i.shiftKey){i.preventDefault(),i.stopPropagation(),u(),e.removeEventListener("keydown",c),e.removeEventListener("blur",d);const v=t+1<g.length?t+1:t;l(v,n);return}if(i.key==="Tab"){i.preventDefault(),i.stopPropagation(),u(),e.removeEventListener("keydown",c),e.removeEventListener("blur",d);let v=t,C=i.shiftKey?n-1:n+1;C<0&&(C=E-1,v=Math.max(0,t-1)),C>=E&&(C=0,v=Math.min(g.length-1,t+1)),l(v,C)}}function d(){e.contentEditable==="true"&&(u(),e.removeEventListener("keydown",c),e.removeEventListener("blur",d))}e.addEventListener("keydown",c),e.addEventListener("blur",d)}function Sn(e,t,n,o,a){var l,r;const s=o.state,u=o.instance,c=t.cells.length>0?t.cells.map(N=>[...N]):yt((l=e.rows)!=null?l:3,(r=e.columns)!=null?r:3);let d=t.merges?[...t.merges]:[];const i={anchor:null,focus:null,dragging:!1},p=document.createElement("input");p.type="hidden",p.name=n,p.value=JSON.stringify({cells:c,merges:d}),a.appendChild(p);function m(){p.value=JSON.stringify({cells:c,merges:d}),u&&u.triggerOnChange(n,{cells:c,merges:d})}p._applyExternalUpdate=N=>{c.length=0,N.cells.forEach(S=>c.push([...S])),d.length=0,N.merges&&N.merges.forEach(S=>d.push({...S})),i.anchor=null,i.focus=null,m(),le()};const f=document.createElement("div");f.style.cssText="position: relative; padding: 20px 20px 20px 24px; overflow-x: auto; max-width: 100%;";const h=document.createElement("table");h.style.cssText=`
|
|
404
|
+
border-collapse: collapse;
|
|
405
|
+
font-size: var(--fb-font-size);
|
|
406
|
+
font-family: var(--fb-font-family);
|
|
407
|
+
color: var(--fb-text-color);
|
|
408
|
+
table-layout: fixed;
|
|
409
|
+
`,f.appendChild(h),a.appendChild(f);const g=document.createElement("div");g.style.cssText=`
|
|
410
|
+
position: fixed;
|
|
411
|
+
display: none;
|
|
412
|
+
background: white;
|
|
413
|
+
border: 1px solid var(--fb-border-color);
|
|
414
|
+
border-radius: var(--fb-border-radius);
|
|
415
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
|
416
|
+
padding: 4px;
|
|
417
|
+
z-index: 1000;
|
|
418
|
+
gap: 4px;
|
|
419
|
+
flex-direction: column;
|
|
420
|
+
`,a.appendChild(g);function E(N,S){const $=document.createElement("button");return $.type="button",$.textContent=N,$.style.cssText=`
|
|
421
|
+
padding: 4px 10px;
|
|
422
|
+
font-size: var(--fb-font-size-small);
|
|
423
|
+
color: var(--fb-text-color);
|
|
424
|
+
border: 1px solid var(--fb-border-color);
|
|
425
|
+
border-radius: var(--fb-border-radius);
|
|
426
|
+
background: transparent;
|
|
427
|
+
cursor: pointer;
|
|
428
|
+
white-space: nowrap;
|
|
429
|
+
text-align: left;
|
|
430
|
+
`,$.addEventListener("mouseenter",()=>{$.style.background="var(--fb-background-hover-color)"}),$.addEventListener("mouseleave",()=>{$.style.background="transparent"}),$.addEventListener("click",()=>{C(),S()}),$}function v(N,S){g.innerHTML="",g.style.display="flex";const $=ie(i),D=$&&($.r1!==$.r2||$.c1!==$.c2),I=i.anchor&&Le(i.anchor.row,i.anchor.col,d);if(D&&g.appendChild(E(w("tableMergeCells",s),G)),I&&g.appendChild(E(w("tableSplitCell",s),Fe)),!g.firstChild){C();return}const L=140,P=g.children.length*32+8,F=window.innerWidth,M=window.innerHeight,B=N+L>F?N-L:N,j=S+P>M?S-P:S;g.style.left=`${B}px`,g.style.top=`${j}px`}function C(){g.style.display="none"}const b=new AbortController;document.addEventListener("mousedown",N=>{if(!a.isConnected){b.abort();return}g.contains(N.target)||C()},{signal:b.signal});function y(){const N=ie(i);h.querySelectorAll("td[data-row]").forEach(S=>{const $=parseInt(S.getAttribute("data-row")||"0",10),D=parseInt(S.getAttribute("data-col")||"0",10),I=i.anchor!==null&&i.anchor.row===$&&i.anchor.col===D,L=N!==null&&$>=N.r1&&$<=N.r2&&D>=N.c1&&D<=N.c2;S.style.outline=I?"2px solid var(--fb-primary-color, #0066cc)":"",S.style.outlineOffset=I?"-2px":"",$===0?S.style.backgroundColor="var(--fb-background-hover-color)":S.style.backgroundColor=L&&!I?"rgba(0,102,204,0.08)":""})}function x(N,S){i.anchor={row:N,col:S},i.focus=null,y(),h.focus()}function k(N,S){const $=h.querySelector(`td[data-row="${N}"][data-col="${S}"]`);if(!$)return;const D=$.querySelector("span");D&&(i.anchor={row:N,col:S},i.focus=null,y(),kn(D,N,S,()=>c,m,x))}function A(N){var S;const $=c.length>0?c[0].length:(S=e.columns)!=null?S:3,D=Array($).fill(""),I=N!==void 0?N+1:c.length;c.splice(I,0,D),d=d.map(L=>L.row>=I?{...L,row:L.row+1}:L.row<I&&L.row+L.rowspan>I?{...L,rowspan:L.rowspan+1}:L),m(),le()}function q(N){if(c.length<=1)return;const S=N!==void 0?N:i.anchor?i.anchor.row:c.length-1;d=d.map($=>{const D=$.row+$.rowspan-1;return $.row===S&&$.rowspan===1?null:$.row===S?{...$,row:$.row+1,rowspan:$.rowspan-1}:D===S?{...$,rowspan:$.rowspan-1}:$.row<S&&D>S?{...$,rowspan:$.rowspan-1}:$.row>S?{...$,row:$.row-1}:$}).filter($=>$!==null),c.splice(S,1),i.anchor&&i.anchor.row>=c.length&&(i.anchor={row:c.length-1,col:i.anchor.col}),m(),le()}function _(N){var S,$;const D=N!==void 0?N+1:($=(S=c[0])==null?void 0:S.length)!=null?$:0;c.forEach(I=>I.splice(D,0,"")),d=d.map(I=>I.col>=D?{...I,col:I.col+1}:I.col<D&&I.col+I.colspan>D?{...I,colspan:I.colspan+1}:I),m(),le()}function K(N){if(c.length===0||c[0].length<=1)return;const S=N!==void 0?N:i.anchor?i.anchor.col:c[0].length-1;d=d.map($=>{const D=$.col+$.colspan-1;return $.col===S&&$.colspan===1?null:$.col===S?{...$,col:$.col+1,colspan:$.colspan-1}:D===S?{...$,colspan:$.colspan-1}:$.col<S&&D>S?{...$,colspan:$.colspan-1}:$.col>S?{...$,col:$.col-1}:$}).filter($=>$!==null),c.forEach($=>$.splice(S,1)),i.anchor&&i.anchor.col>=c[0].length&&(i.anchor={row:i.anchor.row,col:c[0].length-1}),m(),le()}function G(){const N=ie(i);if(!N)return;const{r1:S,c1:$,r2:D,c2:I}=N;if(S===D&&$===I)return;d=d.filter(P=>{const F=P.row+P.rowspan-1,M=P.col+P.colspan-1;return!(P.row<=D&&F>=S&&P.col<=I&&M>=$)});const L=c[S][$];for(let P=S;P<=D;P++)for(let F=$;F<=I;F++)(P!==S||F!==$)&&(c[P][F]="");c[S][$]=L,d.push({row:S,col:$,rowspan:D-S+1,colspan:I-$+1}),i.anchor={row:S,col:$},i.focus=null,m(),le()}function Fe(){if(!i.anchor)return;const{row:N,col:S}=i.anchor,$=d.findIndex(D=>D.row===N&&D.col===S);$!==-1&&(d.splice($,1),i.focus=null,m(),le())}function le(){var N,S;h.innerHTML="";const $=c.length,D=$>0?c[0].length:0,I=ie(i);for(let L=0;L<$;L++){const P=(L===0?(N=h.tHead)!=null?N:h.createTHead():(S=h.tBodies[0])!=null?S:h.createTBody()).insertRow();for(let F=0;F<D;F++){if(xt(L,F,d))continue;const M=Le(L,F,d),B=document.createElement("td");B.setAttribute("data-row",String(L)),B.setAttribute("data-col",String(F)),M&&(M.rowspan>1&&(B.rowSpan=M.rowspan),M.colspan>1&&(B.colSpan=M.colspan));const j=I!==null&&L>=I.r1&&L<=I.r2&&F>=I.c1&&F<=I.c2,H=i.anchor!==null&&i.anchor.row===L&&i.anchor.col===F;B.style.cssText=["border: var(--fb-border-width) solid var(--fb-border-color);","padding: 4px 8px;","min-width: 80px;","vertical-align: top;","cursor: text;","position: relative;",L===0?"background-color: var(--fb-background-hover-color); font-weight: 600;":"",j&&!H?"background-color: rgba(0,102,204,0.08);":"",H?"outline: 2px solid var(--fb-primary-color, #0066cc); outline-offset: -2px;":""].join(" ");const V=document.createElement("span");V.textContent=c[L][F],V.style.cssText="display: block; min-height: 1.4em; white-space: pre-wrap; word-break: break-word; outline: none;",B.appendChild(V);const R=L,W=F;B.addEventListener("mousedown",O=>{if(O.target.tagName!=="BUTTON"&&O.target.contentEditable!=="true"){if(O.button===2){const z=ie(i);if(z&&R>=z.r1&&R<=z.r2&&W>=z.c1&&W<=z.c2)return}O.shiftKey&&i.anchor?(O.preventDefault(),i.focus={row:R,col:W},i.dragging=!1,y()):(i.anchor={row:R,col:W},i.focus=null,i.dragging=!0,y())}}),B.addEventListener("mouseup",O=>{if(O.target.tagName!=="BUTTON"&&i.dragging){i.dragging=!1;const z=ie(i);(!z||z.r1===z.r2&&z.c1===z.c2)&&k(R,W)}}),B.addEventListener("mousemove",O=>{if(i.dragging&&O.buttons===1){const z=i.anchor;z&&(z.row!==R||z.col!==W)&&(i.focus={row:R,col:W},y())}}),B.addEventListener("contextmenu",O=>{const z=ie(i),X=z&&(z.r1!==z.r2||z.c1!==z.c2),Y=i.anchor&&Le(i.anchor.row,i.anchor.col,d);(X||Y)&&(O.preventDefault(),v(O.clientX,O.clientY))}),P.appendChild(B)}}Jn(),h.setAttribute("tabindex","0"),h.onkeydown=L=>{var P,F;if(h.querySelector("[contenteditable='true']"))return;const M=i.anchor;if(!M)return;const B=c.length,j=B>0?c[0].length:0,H={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]};if(H[L.key]){L.preventDefault();const[V,R]=H[L.key],W=Math.max(0,Math.min(B-1,M.row+V)),O=Math.max(0,Math.min(j-1,M.col+R));L.shiftKey?(i.focus={row:W,col:O},y()):x(W,O);return}if(L.key==="Enter"){L.preventDefault(),k(M.row,M.col);return}if(L.key==="Tab"){L.preventDefault();const V=(F=(P=c[0])==null?void 0:P.length)!=null?F:0;let R=M.row,W=L.shiftKey?M.col-1:M.col+1;W<0&&(W=V-1,R=Math.max(0,R-1)),W>=V&&(W=0,R=Math.min(c.length-1,R+1)),x(R,W);return}if(L.key==="m"&&L.ctrlKey&&!L.shiftKey){L.preventDefault(),G();return}L.key==="M"&&L.ctrlKey&&L.shiftKey&&(L.preventDefault(),Fe())},h.oncopy=L=>{var P,F,M,B;const j=ie(i);if(!j)return;L.preventDefault();const{r1:H,c1:V,r2:R,c2:W}=j,O=[],z=[];for(let T=H;T<=R;T++){const J=[],Q=[];for(let ee=V;ee<=W;ee++){const te=(F=(P=c[T])==null?void 0:P[ee])!=null?F:"";J.push(te);const de=te.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");Q.push(`<td>${de}</td>`)}O.push(J.join(" ")),z.push(`<tr>${Q.join("")}</tr>`)}const X=O.join(`
|
|
431
|
+
`),Y=`<table>${z.join("")}</table>`;(M=L.clipboardData)==null||M.setData("text/plain",X),(B=L.clipboardData)==null||B.setData("text/html",Y)},h.onpaste=L=>{var P,F,M,B,j,H,V,R,W;const O=i.anchor;if(!O)return;const z=(F=(P=L.clipboardData)==null?void 0:P.getData("text/plain"))!=null?F:"",X=z.includes(" ")||z.split(/\r?\n/).filter(Z=>Z).length>1,Y=h.querySelector("[contenteditable='true']");if(Y&&!X)return;if(L.preventDefault(),Y){Y.contentEditable="inherit";const Z=parseInt((B=(M=Y.closest("td"))==null?void 0:M.getAttribute("data-row"))!=null?B:"0",10),se=parseInt((H=(j=Y.closest("td"))==null?void 0:j.getAttribute("data-col"))!=null?H:"0",10);c[Z]&&(c[Z][se]=(V=Y.textContent)!=null?V:"")}if(!z.trim())return;const T=z.split(/\r?\n/).map(Z=>Z.split(" "));T.length>1&&T[T.length-1].length===1&&T[T.length-1][0]===""&&T.pop();const J=O.row,Q=O.col,ee=J+T.length;for(;c.length<ee;)c.push(Array((W=(R=c[0])==null?void 0:R.length)!=null?W:1).fill(""));const te=Math.max(...T.map(Z=>Z.length)),de=Q+te;if(c[0]&&de>c[0].length){const Z=de-c[0].length;c.forEach(se=>{for(let xe=0;xe<Z;xe++)se.push("")})}for(let Z=0;Z<T.length;Z++)for(let se=0;se<T[Z].length;se++){const xe=J+Z,Kn=Q+se;c[xe]&&(c[xe][Kn]=T[Z][se])}m(),le()}}const re=he({label:"+",title:w("tableAddColumn",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var N;const S=parseInt((N=re.dataset.afterCol)!=null?N:"0",10);_(S)}});re.style.position="absolute",re.style.display="none",f.appendChild(re);const oe=he({label:"+",title:w("tableAddRow",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var N;const S=parseInt((N=oe.dataset.afterRow)!=null?N:"0",10);A(S)}});oe.style.position="absolute",oe.style.display="none",f.appendChild(oe);let be=[],ye=[];const ce=he({label:"+",title:w("tableAddColumn",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>_()});ce.style.position="absolute",ce.style.display="none",f.appendChild(ce);const ue=he({label:"+",title:w("tableAddRow",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>A()});ue.style.position="absolute",ue.style.display="none",f.appendChild(ue);function Jn(){var N,S;be.forEach(F=>F.remove()),be=[],ye.forEach(F=>F.remove()),ye=[];const $=c.length>0?c[0].length:0,D=c.length;if($>1){const F=Array.from(h.querySelectorAll("thead td[data-col]"));for(const M of F){const B=parseInt((N=M.getAttribute("data-col"))!=null?N:"0",10),j=he({label:"\xD7",title:w("tableRemoveColumn",s),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>K(B)});j.setAttribute("data-action","remove-col"),j.setAttribute("data-col",String(B)),j.style.position="absolute",j.style.display="none",f.appendChild(j),be.push(j)}}if(D>1){const F=[...h.tHead?Array.from(h.tHead.rows):[],...h.tBodies[0]?Array.from(h.tBodies[0].rows):[]].filter(M=>M.querySelector("td[data-row]"));for(const M of F){const B=M.querySelector("td[data-row]");if(!B)continue;const j=parseInt((S=B.getAttribute("data-row"))!=null?S:"0",10),H=he({label:"\xD7",title:w("tableRemoveRow",s),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>q(j)});H.setAttribute("data-action","remove-row"),H.setAttribute("data-row",String(j)),H.style.position="absolute",H.style.display="none",f.appendChild(H),ye.push(H)}}function I(F,M,B,j,H){var V;const R=H?Array.from(h.querySelectorAll("thead td[data-col]")):[];let W=-1,O=1/0,z=-1,X=-1,Y=1/0;for(let T=0;T<R.length;T++){const J=R[T].getBoundingClientRect(),Q=(J.left+J.right)/2,ee=Math.abs(F-Q);ee<O&&(O=ee,W=T);const te=Math.abs(F-J.right);te<Y&&te<20&&(Y=te,z=J.right-M.left+j,X=parseInt((V=R[T].getAttribute("data-col"))!=null?V:"0",10))}be.forEach((T,J)=>{if(!H||J!==W){T.style.display="none";return}const Q=R[J].getBoundingClientRect(),ee=(Q.left+Q.right)/2-M.left+j;T.style.left=`${ee-8}px`,T.style.top="2px",T.style.display="flex"}),H&&X>=0?(re.style.display="flex",re.style.left=`${z-10}px`,re.style.top=`${B.top-M.top-10}px`,re.dataset.afterCol=String(X)):re.style.display="none"}function L(F,M,B,j,H){var V;const R=[];if(H){if(h.tHead)for(const T of Array.from(h.tHead.rows))T.querySelector("td[data-row]")&&R.push(T);if(h.tBodies[0])for(const T of Array.from(h.tBodies[0].rows))T.querySelector("td[data-row]")&&R.push(T)}let W=-1,O=1/0,z=-1,X=-1,Y=1/0;for(let T=0;T<R.length;T++){const J=R[T].getBoundingClientRect(),Q=(J.top+J.bottom)/2,ee=Math.abs(F-Q);ee<O&&(O=ee,W=T);const te=Math.abs(F-J.bottom);if(te<Y&&te<14){Y=te,z=J.bottom-M.top;const de=R[T].querySelector("td[data-row]");X=parseInt((V=de==null?void 0:de.getAttribute("data-row"))!=null?V:"0",10)}}ye.forEach((T,J)=>{if(!H||J!==W){T.style.display="none";return}const Q=R[J].getBoundingClientRect(),ee=(Q.top+Q.bottom)/2-M.top;T.style.left="4px",T.style.top=`${ee-8}px`,T.style.display="flex"}),H&&X>=0?(oe.style.display="flex",oe.style.top=`${z-10}px`,oe.style.left=`${B.left-M.left+j-10}px`,oe.dataset.afterRow=String(X)):oe.style.display="none"}let P=!1;f.onmousemove=F=>{const M=F.target;if(M.tagName==="BUTTON"&&M.parentElement===f||P)return;P=!0;const B=F.clientX,j=F.clientY;requestAnimationFrame(()=>{P=!1;const H=f.getBoundingClientRect(),V=h.getBoundingClientRect(),R=f.scrollLeft,W=j>=H.top&&j<V.top+4,O=B>=H.left&&B<V.left+4,z=Math.min(V.right,H.right),X=B>z-20&&B<=H.right,Y=j>V.bottom-4&&j<=H.bottom+20;if(I(B,H,V,R,W),L(j,H,V,R,O),ce.style.display=X?"flex":"none",X&&(ce.style.left=`${H.right-H.left+R-20}px`,ce.style.top=`${(V.top+V.bottom)/2-H.top-10}px`),ue.style.display=Y?"flex":"none",Y){const T=(H.left+H.right)/2-H.left+R;ue.style.left=`${T-10}px`,ue.style.top=`${V.bottom-H.top-10}px`}})},f.onmouseleave=()=>{be.forEach(F=>{F.style.display="none"}),ye.forEach(F=>{F.style.display="none"}),re.style.display="none",oe.style.display="none",ce.style.display="none",ue.style.display="none"}}le()}function Ln(e){var t,n;return{cells:yt((t=e.rows)!=null?t:3,(n=e.columns)!=null?n:3),merges:[]}}function Oe(e){return e!==null&&typeof e=="object"&&"cells"in e&&Array.isArray(e.cells)}function An(e,t,n,o){const a=t.state,l=t.prefill[e.key],r=Oe(l)?l:Oe(e.default)?e.default:Ln(e);a.config.readonly?$n(r,n):Sn(e,r,o,t,n)}function Nn(e,t,n){const{scopeRoot:o,skipValidation:a}=n,l=[],r=o.querySelector(`[name="${t}"]`);if(!r)return{value:null,errors:l};let s=null;try{s=JSON.parse(r.value)}catch(u){return l.push(`${t}: invalid table data`),{value:null,errors:l}}return!a&&e.required&&(s.cells.some(u=>u.some(c=>c.trim()!==""))||l.push(`${t}: ${w("required",n.state)}`)),{value:s,errors:l}}function Fn(e,t,n,o){const{scopeRoot:a}=o,l=a.querySelector(`[name="${t}"]`);if(!l){console.warn(`updateTableField: no hidden input found for "${t}". Re-render to reflect new data.`);return}Oe(n)&&l._applyExternalUpdate?l._applyExternalUpdate(n):l.value=JSON.stringify(n)}function Tn(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(d=>{d.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),l=window.innerWidth,r=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 u=a.left,c=a.bottom+5;u+s.width>l&&(u=a.right-s.width),c+s.height>r&&(c=a.top-s.height-5),u<10&&(u=10),c<10&&(c=a.bottom+5),n.style.left=`${u}px`,n.style.top=`${c}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 qn(e,t){var n,o,a;if(!e.enableIf)return!1;try{const l=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=((a=e.enableIf.scope)!=null?a:"relative")==="relative"&&t.path?t.prefill:void 0;return!fe(e.enableIf,l,r)}catch(l){console.error(`Error evaluating enableIf for field "${e.key}":`,l)}return!1}function Mn(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 Ae(e,t,n){var o,a;if(!t.enableIf)return;const l=n.state.formRoot;if(!l){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const r=t.enableIf,s=(o=r.scope)!=null?o:"relative";let u={};const c={};if((!n.path||n.path===""?"absolute":s)==="relative"&&n.path){const d=n.path.match(/^(.+)\[(\d+)\]$/);if(d){const i=d[1],p=parseInt(d[2],10),m=l.querySelector(`[data-container-item="${i}[${p}]"]`);m&&m.querySelectorAll("input, select, textarea").forEach(f=>{const h=f.getAttribute("name");if(h){const g=h.match(/\.([^.[\]]+)$/);if(g){const E=g[1];f instanceof HTMLSelectElement?c[E]=f.value:f instanceof HTMLInputElement?f.type==="checkbox"?c[E]=f.checked:f.type==="radio"?f.checked&&(c[E]=f.value):c[E]=f.value:f instanceof HTMLTextAreaElement&&(c[E]=f.value)}}})}}else{const d=r.key,i=Mn(d,l);i!==void 0?u[d]=i:u=(a=n.formData)!=null?a:n.prefill}try{fe(r,u,c)?(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(d){console.error(`Error re-evaluating enableIf for field "${t.key}":`,d)}}function Hn(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 l=t.enableIf,r=(o=l.scope)!=null?o:"relative",s=l.key;let u;r==="relative"&&n.path?u=`${n.path}.${s}`:u=s;const c=a.querySelector(`[name="${u}"]`);if(!c){const d=new MutationObserver(()=>{const i=a.querySelector(`[name="${u}"]`);i&&(i.addEventListener("change",()=>{Ae(e,t,n)}),i.addEventListener("input",()=>{Ae(e,t,n)}),d.disconnect())});d.observe(a,{childList:!0,subtree:!0});return}c.addEventListener("change",()=>{Ae(e,t,n)}),c.addEventListener("input",()=>{Ae(e,t,n)})}function Bn(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 Rn(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(),Tn(n,t)},t}function zn(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Bn(e);if(t.appendChild(n),e.description||e.hint){const o=Rn(e);t.appendChild(o)}return t}function In(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?Tt(e,t,n,o):Ft(e,t,n,o);break;case"textarea":a?Mt(e,t,n,o):qt(e,t,n,o);break;case"number":a?zt(e,t,n,o):Rt(e,t,n,o);break;case"select":a?Ot(e,t,n,o):jt(e,t,n,o);break;case"switcher":a?Wt(e,t,n,o):Vt(e,t,n,o);break;case"file":a?un(e,t,n,o):sn(e,t,n,o);break;case"files":cn(e,t,n,o);break;case"colour":a?pn(e,t,n,o):dn(e,t,n,o);break;case"slider":a?vn(e,t,n,o):hn(e,t,n,o);break;case"group":Cn(e,t,n,o);break;case"container":a?mt(e,t,n):ft(e,t,n,o);break;case"table":An(e,t,n,o);break;default:{const l=document.createElement("div");l.className="text-red-500 text-sm",l.textContent=w("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(l)}}}function Ue(e,t){const n=qn(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=zn(e);o.appendChild(a);const l=pe(t.path,e.key);return In(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),Hn(o,e,t),o}yn(Ue);const Pe={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:{removeElement:"Remove",clickDragText:"Click or drag file",clickDragTextMultiple:"Click or drag files",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download",changeButton:"Change",placeholderText:"Enter text",previewAlt:"Preview",previewUnavailable:"Preview unavailable",previewError:"Preview error",videoNotSupported:"Your browser does not support the video tag.",hintLengthRange:"{min}-{max} chars",hintMaxLength:"\u2264{max} chars",hintMinLength:"\u2265{min} chars",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}MB",hintFormats:"{formats}",hintRequired:"Required",hintOptional:"Optional",hintPattern:"Format: {pattern}",fileCountSingle:"{count} file",fileCountPlural:"{count} files",fileCountRange:"({min}-{max})",required:"Required",minItems:"Minimum {min} items required",maxItems:"Maximum {max} items allowed",minLength:"Minimum {min} characters",maxLength:"Maximum {max} characters",minValue:"Must be at least {min}",maxValue:"Must be at most {max}",patternMismatch:"Invalid format",invalidPattern:"Invalid pattern in schema",notANumber:"Must be a number",invalidHexColour:"Invalid hex color",minFiles:"Minimum {min} files required",maxFiles:"Maximum {max} files allowed",unsupportedFieldType:"Unsupported field type: {type}",invalidOption:"Invalid option",tableAddRow:"Add row",tableAddColumn:"Add column",tableRemoveRow:"Remove row",tableRemoveColumn:"Remove column",tableMergeCells:"Merge cells (Ctrl+M)",tableSplitCell:"Split cell (Ctrl+Shift+M)"},ru:{removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",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",clickDragTextMultiple:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",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",changeButton:"\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",placeholderText:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",previewAlt:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440",previewUnavailable:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D",previewError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440\u0430",videoNotSupported:"\u0412\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043E.",hintLengthRange:"{min}-{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMaxLength:"\u2264{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMinLength:"\u2265{min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}\u041C\u0411",hintFormats:"{formats}",hintRequired:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintOptional:"\u041D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintPattern:"\u0424\u043E\u0440\u043C\u0430\u0442: {pattern}",fileCountSingle:"{count} \u0444\u0430\u0439\u043B",fileCountPlural:"{count} \u0444\u0430\u0439\u043B\u043E\u0432",fileCountRange:"({min}-{max})",required:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435",minItems:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",maxItems:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",minLength:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",maxLength:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",minValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u043C\u0435\u043D\u0435\u0435 {min}",maxValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u0431\u043E\u043B\u0435\u0435 {max}",patternMismatch:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442",invalidPattern:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043F\u0430\u0442\u0442\u0435\u0440\u043D \u0432 \u0441\u0445\u0435\u043C\u0435",notANumber:"\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0447\u0438\u0441\u043B\u043E\u043C",invalidHexColour:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u0446\u0432\u0435\u0442\u0430",minFiles:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0444\u0430\u0439\u043B\u043E\u0432",maxFiles:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0444\u0430\u0439\u043B\u043E\u0432",unsupportedFieldType:"\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u043B\u044F: {type}",invalidOption:"\u041D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435",tableAddRow:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableAddColumn:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableRemoveRow:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableRemoveColumn:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableMergeCells:"\u041E\u0431\u044A\u0435\u0434\u0438\u043D\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0438 (Ctrl+M)",tableSplitCell:"\u0420\u0430\u0437\u0434\u0435\u043B\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0443 (Ctrl+Shift+M)"}},theme:{}};function Dn(e){const t={...Pe.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...Pe.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Pe,...e,translations:t},debounceTimer:null}}function jn(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const ge={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 On(e){const t={...ge,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const l=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${l}: ${a};`)}),n.join(`
|
|
432
|
+
`)}function Un(e,t){const n=On(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=`
|
|
343
433
|
[data-fb-root="true"] {
|
|
344
434
|
${n}
|
|
345
435
|
}
|
|
346
|
-
`}const
|
|
436
|
+
`}const Pn={default:ge,dark:{...ge,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:{...ge,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 Ct(e,t=!1){e.style.cssText=`
|
|
347
437
|
background-color: var(--fb-action-bg-color);
|
|
348
438
|
color: var(--fb-action-text-color);
|
|
349
439
|
border: var(--fb-border-width) solid var(--fb-action-border-color);
|
|
@@ -353,6 +443,6 @@ ${n}
|
|
|
353
443
|
border-radius: var(--fb-border-radius);
|
|
354
444
|
transition: all var(--fb-transition-duration);
|
|
355
445
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
356
|
-
`,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
|
|
446
|
+
`,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 Vn={text:{validate:Ve,update:We},textarea:{validate:Ht,update:Bt},number:{validate:It,update:Dt},select:{validate:Ut,update:Pt},switcher:{validate:_t,update:Jt},file:{validate:rt,update:ot},files:{validate:rt,update:ot},colour:{validate:fn,update:mn},slider:{validate:gn,update:bn},container:{validate:vt,update:gt},group:{validate:En,update:wn},table:{validate:Nn,update:Fn}};function Et(e){return Vn[e]||null}function Wn(e,t,n){const o=Et(e.type);return o&&o.validate?o.validate(e,t,n):null}function _n(e,t,n,o){const a=Et(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class Ne{constructor(t){this.instanceId=jn(),this.state=Dn(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 l=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const r of l)if(a=this.state.formRoot.querySelector(`[name="${r}"]`),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 l=n.label||n.key,r=a.querySelector("label");if(r&&(r.textContent===l||r.textContent===`${l}*`)){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 l of a){if(o=n.find(r=>r.key===l)||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 l=o.actions.find(r=>r.key===t);if(l&&l.label)return l.label}if(a&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const l=this.state.schema.actions.find(r=>r.key===t);if(l&&l.label)return l.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=`
|
|
357
447
|
border-top: var(--fb-border-width) solid var(--fb-border-color);
|
|
358
|
-
`,t.forEach(l=>{const r=document.createElement("button");r.type="button",
|
|
448
|
+
`,t.forEach(l=>{const r=document.createElement("button");r.type="button",Ct(r,!0);const s=n.includes(l),u=this.resolveActionLabel(l.key,l.label,null,s);r.textContent=u,r.addEventListener("click",c=>{c.preventDefault(),c.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(l.value,l.key,null)}),a.appendChild(r)}),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(l=>{!l.key||!l.value||(l.related_field?(t.has(l.related_field)||t.set(l.related_field,[]),t.get(l.related_field).push(l)):n.push(l))}),t.forEach((l,r)=>{const s=this.findFormElementByFieldPath(r);if(!s){console.warn(`External action: Could not find form element for field "${r}", treating as form-level actions`),o.push(...l);return}let u=s.closest(".fb-field-wrapper");if(u||(u=s.parentElement),!u){console.warn(`External action: Could not find wrapper for field "${r}"`);return}const c=u.querySelector(".external-actions-container");c&&c.remove();const d=document.createElement("div");d.className="external-actions-container mt-3 flex flex-wrap gap-2";const i=this.findSchemaElement(r);l.forEach(p=>{const m=document.createElement("button");m.type="button",Ct(m,!1);const f=this.resolveActionLabel(p.key,p.label,i);m.textContent=f,m.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)}),d.appendChild(m)}),u.appendChild(d)});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",l=n.getAttribute("data-container-key");if(!o||!a&&!l){console.warn("Prefill hint missing required data attributes");return}try{const r=JSON.parse(o);for(const s in r){const u=a?s:`${l}.${s}`,c=r[s];this.updateField(u,c)}}catch(r){console.error("Error parsing prefill hint values:",r)}}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 l=Te(n);if(l.length>0){console.error("Schema validation errors:",l);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=a||null,ve(t),t.setAttribute("data-fb-root","true"),Un(t,this.state.config.theme);const r=document.createElement("div");if(r.className="space-y-6",n.prefillHints&&!this.state.config.readonly){const c=this.createRootPrefillHints(n.prefillHints);r.appendChild(c)}const s=document.createElement("div"),u=n.columns||1;u===1?s.className="space-y-4":s.className=`grid grid-cols-${u} gap-4`,n.elements.forEach(c=>{if(c.hidden)return;const d=Ue(c,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});s.appendChild(d)}),r.appendChild(s),t.appendChild(r),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=(l,r,s=null)=>{const u=l.key,c={scopeRoot:s||this.state.formRoot,state:this.state,instance:this,path:r.path,skipValidation:t},d=Wn(l,u,c);return d!==null?(n.push(...d.errors),d.value):(console.warn(`Unknown field type "${l.type}" for key "${u}"`),null)};return xn(a),this.state.schema.elements.forEach(l=>{if(l.enableIf)try{if(!fe(l.enableIf,o))return}catch(r){console.error(`Error evaluating enableIf for field "${l.key}" during validation:`,r)}l.hidden?o[l.key]=l.default!==void 0?l.default:null:o[l.key]=a(l,{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 l=o,r=this.buildHiddenFieldsData(l.elements);Object.keys(r).length>0&&(a in n?typeof n[a]=="object"&&n[a]!==null&&!Array.isArray(n[a])&&(n[a]={...n[a],...r}):n[a]=r)}}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 l={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};_n(n,o,a,l)||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(l=>{var r,s,u;const c=a?`${a}.${l.key}`:l.key;if(l.enableIf){let d=null;if(a){const i=a.match(/^(.+)\[(\d+)\]$/);if(i){const p=i[1],m=i[2],f=this.state.formRoot.querySelector(`[data-container-item="${p}[${m}]"]`);f&&(d=f.querySelector(`[data-field-key="${l.key}"]`))}else{const p=this.state.formRoot.querySelector(`[data-container="${a}"]`);p&&(d=p.querySelector(`[data-field-key="${l.key}"]`))}}else d=this.state.formRoot.querySelector(`[data-field-key="${l.key}"]`);if(d){const i=d;try{let p;((r=l.enableIf.scope)!=null?r:"relative")==="relative"&&a&&(p=qe(t,a));const m=fe(l.enableIf,t,p),f=i.getAttribute("data-conditionally-disabled")==="true";if(m&&f){const h=a?qe(t,a):t,g=Ue(l,{path:a,prefill:h&&typeof h=="object"?h:{},formData:t,state:this.state,instance:this});(s=i.parentNode)==null||s.replaceChild(g,i)}else if(!m&&!f){const h=document.createElement("div");h.className="fb-field-wrapper-disabled",h.style.display="none",h.setAttribute("data-field-key",l.key),h.setAttribute("data-conditionally-disabled","true"),(u=i.parentNode)==null||u.replaceChild(h,i)}}catch(p){console.error(`Error re-evaluating enableIf for field "${l.key}" at path "${c}":`,p)}}}if((l.type==="container"||l.type==="group")&&"elements"in l&&l.elements){const d=t==null?void 0:t[l.key];if(Array.isArray(d)){const i=this.state.formRoot.querySelectorAll("[data-container-item]");Array.from(i).filter(p=>{const m=p.getAttribute("data-container-item")||"";if(!m.startsWith(`${c}[`))return!1;const f=m.slice(c.length);return/^\[\d+\]$/.test(f)}).forEach(p=>{const m=p.getAttribute("data-container-item")||"";n(l.elements,m)})}else n(l.elements,c)}})};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&&ve(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 wt(e){return new Ne(e)}return typeof window!="undefined"&&(window.FormBuilder=Ne,window.createFormBuilder=wt,window.validateSchema=Te),ae.FormBuilderInstance=Ne,ae.createFormBuilder=wt,ae.default=Ne,ae.defaultTheme=ge,ae.exampleThemes=Pn,ae.validateSchema=Te,Object.defineProperty(ae,"__esModule",{value:!0}),ae})({});
|