@dmitryvim/form-builder 0.2.10 → 0.2.12
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/dist/browser/formbuilder.min.js +141 -101
- package/dist/browser/formbuilder.v0.2.12.min.js +362 -0
- package/dist/cjs/index.cjs +793 -425
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +792 -423
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +141 -101
- package/dist/types/components/file.d.ts +1 -1
- package/dist/types/components/text.d.ts +1 -0
- package/dist/types/instance/state.d.ts +1 -0
- package/dist/types/types/config.d.ts +37 -6
- package/dist/types/utils/helpers.d.ts +5 -0
- package/dist/types/utils/translation.d.ts +8 -3
- package/dist/types/utils/validation.d.ts +2 -1
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.10.min.js +0 -322
package/dist/form-builder.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
var FormBuilder=(function(
|
|
1
|
+
var FormBuilder=(function(N){"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[i,s]of Object.entries(n))r=r.replace(new RegExp(`\\{${i}\\}`,"g"),String(s));return r}function Fe(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 Ne(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 Ae(e,t,n){e.maxSizeMB&&t.push(w("hintMaxSize",n,{size:e.maxSizeMB}))}function Te(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 qe(e,t,n){e.required?t.push(w("hintRequired",n)):t.push(w("hintOptional",n))}function Me(e,t,n){e.pattern&&t.push(w("hintPattern",n,{pattern:e.pattern}))}function F(e,t){const n=[];return qe(e,n,t),Fe(e,n,t),e.type!=="slider"&&Ne(e,n,t),Ae(e,n,t),Te(e,n,t),Me(e,n,t),n.join(" \u2022 ")}function P(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(i=>i.key===r)||t.push(`schema.prefillHints[${l}] references non-existent field "${r}"`)})}function n(o,a){o.forEach((l,r)=>{const i=`${a}[${r}]`;if(l.type||t.push(`${i}: missing type`),l.key||t.push(`${i}: missing key`),l.enableIf){const s=l.enableIf;(!s.key||typeof s.key!="string")&&t.push(`${i}: enableIf must have a 'key' property of type string`),"equals"in s||t.push(`${i}: enableIf must have at least one operator (equals, etc.)`)}if(l.type==="group"&&"elements"in l&&l.elements&&n(l.elements,`${i}.elements`),l.type==="container"&&l.elements){if("columns"in l&&l.columns!==void 0){const s=l.columns,u=[1,2,3,4];(!Number.isInteger(s)||!u.includes(s))&&t.push(`${i}: columns must be 1, 2, 3, or 4 (got ${s})`)}if("prefillHints"in l&&l.prefillHints){const s=l.prefillHints;Array.isArray(s)&&s.forEach((u,d)=>{if((!u.label||typeof u.label!="string")&&t.push(`${i}: prefillHints[${d}] must have a 'label' property of type string`),!u.values||typeof u.values!="object")t.push(`${i}: prefillHints[${d}] must have a 'values' property of type object`);else for(const c in u.values)l.elements.some(h=>h.key===c)||t.push(`container "${l.key}": prefillHints[${d}] references non-existent field "${c}"`)})}n(l.elements,`${i}.elements`)}if(l.type==="select"&&l.options){const s=l.default;s!=null&&s!==""&&(l.options.some(u=>u.value===s)||t.push(`${i}: default "${s}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function z(e){return e&&typeof e=="object"&&e.constructor===Object}function S(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function A(e,t){return e?`${e}.${t}`:t}function H(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function I(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let o=e;for(const a of n){if(o==null)return;if(a.startsWith("[")&&a.endsWith("]")){const l=parseInt(a.slice(1,-1),10);if(!Array.isArray(o)||isNaN(l))return;o=o[l]}else o=o[a]}return o}function T(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=I(l,e.key);if("equals"in e)return He(r,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function He(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 R(e,t,n=!1){const o=document.createElement("span");o.className="char-counter",o.style.cssText=`
|
|
2
|
+
position: absolute;
|
|
3
|
+
${n?"bottom: 8px":"top: 50%; transform: translateY(-50%)"};
|
|
4
|
+
right: 10px;
|
|
5
|
+
font-size: var(--fb-font-size-small);
|
|
6
|
+
color: var(--fb-text-secondary-color);
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
background: var(--fb-background-color);
|
|
9
|
+
padding: 0 4px;
|
|
10
|
+
`;const a=()=>{const l=t.value.length,r=e.minLength,i=e.maxLength;if(r==null&&i==null){o.textContent="";return}l===0||r!=null&&l<r?(r!=null&&i!=null?o.textContent=`${r}-${i}`:i!=null?o.textContent=`\u2264${i}`:r!=null&&(o.textContent=`\u2265${r}`),o.style.color="var(--fb-text-secondary-color)"):i!=null&&l>i?(o.textContent=`${l}/${i}`,o.style.color="var(--fb-error-color)"):(i!=null?o.textContent=`${l}/${i}`:o.textContent=`${l}`,o.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",a),a(),o}function Be(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=`
|
|
2
11
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
12
|
+
padding-right: 60px;
|
|
3
13
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
4
14
|
border-radius: var(--fb-border-radius);
|
|
5
15
|
background-color: ${a.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
|
|
@@ -7,84 +17,111 @@ var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||
|
|
|
7
17
|
font-size: var(--fb-font-size);
|
|
8
18
|
font-family: var(--fb-font-family);
|
|
9
19
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`,l.textContent=S(e),n.appendChild(l)}function Ae(e,t,n,o){var a,r;const l=t.state,s=t.prefill[e.key]||[],i=Array.isArray(s)?[...s]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;i.length<d;)i.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function p(){c.querySelectorAll(".multiple-text-item").forEach((x,g)=>{const y=x.querySelector("input");y&&(y.name=`${o}[${g}]`)})}function v(x="",g=-1){const y=document.createElement("div");y.className="multiple-text-item flex items-center gap-2";const m=document.createElement("input");if(m.type="text",m.className="flex-1",m.style.cssText=`
|
|
20
|
+
width: 100%;
|
|
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 i=()=>{const s=r.value===""?null:r.value;t.instance.triggerOnChange(o,s)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const i=R(e,r,!1);l.appendChild(i)}n.appendChild(l)}function ze(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-text-item").forEach((p,C)=>{const b=p.querySelector("input");b&&(b.name=`${o}[${C}]`)})}function m(p="",C=-1){const b=document.createElement("div");b.className="multiple-text-item flex items-center gap-2";const x=document.createElement("div");x.style.cssText="position: relative; flex: 1;";const y=document.createElement("input");if(y.type="text",y.style.cssText=`
|
|
14
23
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
24
|
+
padding-right: 60px;
|
|
15
25
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
16
26
|
border-radius: var(--fb-border-radius);
|
|
17
|
-
background-color: ${
|
|
27
|
+
background-color: ${r.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
|
|
18
28
|
color: var(--fb-text-color);
|
|
19
29
|
font-size: var(--fb-font-size);
|
|
20
30
|
font-family: var(--fb-font-family);
|
|
21
31
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
22
|
-
|
|
32
|
+
width: 100%;
|
|
33
|
+
box-sizing: border-box;
|
|
34
|
+
`,y.placeholder=e.placeholder||w("placeholderText",r),y.value=p,y.readOnly=r.config.readonly,r.config.readonly||(y.addEventListener("focus",()=>{y.style.borderColor="var(--fb-border-focus-color)",y.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",y.style.outlineOffset="0"}),y.addEventListener("blur",()=>{y.style.borderColor="var(--fb-border-color)",y.style.outline="none"}),y.addEventListener("mouseenter",()=>{document.activeElement!==y&&(y.style.borderColor="var(--fb-border-hover-color)")}),y.addEventListener("mouseleave",()=>{document.activeElement!==y&&(y.style.borderColor="var(--fb-border-color)")})),!r.config.readonly&&t.instance){const $=()=>{const k=y.value===""?null:y.value;t.instance.triggerOnChange(y.name,k)};y.addEventListener("blur",$),y.addEventListener("input",$)}if(x.appendChild(y),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const $=R(e,y,!1);x.appendChild($)}return b.appendChild(x),C===-1?c.appendChild(b):c.insertBefore(b,c.children[C]),h(),b}function f(){if(r.config.readonly)return;const p=c.querySelectorAll(".multiple-text-item"),C=p.length;p.forEach(b=>{let x=b.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=`
|
|
23
35
|
color: var(--fb-error-color);
|
|
24
36
|
background-color: transparent;
|
|
25
37
|
transition: background-color var(--fb-transition-duration);
|
|
26
|
-
`,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
font-size: var(--fb-font-size-small);
|
|
34
|
-
color: var(--fb-text-secondary-color);
|
|
35
|
-
`,b.textContent=S(e),n.appendChild(b)}function Z(e,t,n){var o,a,r;const l=[],{scopeRoot:s,skipValidation:i}=n,d=(c,p)=>{var v,f;if(!c)return;const h=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(h);p?(c.classList.add("invalid"),c.title=p,b||(b=document.createElement("div"),b.id=h,b.className="error-message",b.style.cssText=`
|
|
38
|
+
`,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const $=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice($,1),b.remove(),h(),E(),f())},b.appendChild(x));const y=C<=u;x.disabled=y,x.style.opacity=y?"0.5":"1",x.style.pointerEvents=y?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const p=document.createElement("button");p.type="button",p.className="add-text-btn px-3 py-1 rounded",p.style.cssText=`
|
|
39
|
+
color: var(--fb-primary-color);
|
|
40
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
41
|
+
background-color: transparent;
|
|
42
|
+
font-size: var(--fb-font-size);
|
|
43
|
+
transition: all var(--fb-transition-duration);
|
|
44
|
+
`,p.textContent="+",p.addEventListener("mouseenter",()=>{p.style.backgroundColor="var(--fb-background-hover-color)"}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor="transparent"}),p.onclick=()=>{s.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(p),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const p=v.querySelector(".add-text-btn");if(p){const C=s.length>=d;p.disabled=C,p.style.opacity=C?"0.5":"1",p.style.pointerEvents=C?"none":"auto"}g.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(p=>m(p)),E(),f()}function ee(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,h)=>{var m,f;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,g||(g=document.createElement("div"),g.id=v,g.className="error-message",g.style.cssText=`
|
|
36
45
|
color: var(--fb-error-color);
|
|
37
46
|
font-size: var(--fb-font-size-small);
|
|
38
47
|
margin-top: 0.25rem;
|
|
39
|
-
`,c.nextSibling?(
|
|
48
|
+
`,c.nextSibling?(m=c.parentNode)==null||m.insertBefore(g,c.nextSibling):(f=c.parentNode)==null||f.appendChild(g)),g.textContent=h,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},d=(c,h,m)=>{let f=!1;const{state:v}=n;if(!s&&h){if(e.minLength!==void 0&&e.minLength!==null&&h.length<e.minLength){const g=w("minLength",v,{min:e.minLength});r.push(`${m}: ${g}`),u(c,g),f=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&h.length>e.maxLength){const g=w("maxLength",v,{max:e.maxLength});r.push(`${m}: ${g}`),u(c,g),f=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(h)){const g=w("patternMismatch",v);r.push(`${m}: ${g}`),u(c,g),f=!0}}catch(g){const E=w("invalidPattern",v);r.push(`${m}: ${E}`),u(c,E),f=!0}}f||u(c,null)};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["]`),h=[],m=[];if(c.forEach((f,v)=>{var g;const E=(g=f==null?void 0:f.value)!=null?g:"";m.push(E),h.push(E===""?null:E),d(f,E,`${t}[${v}]`)}),!s){const{state:f}=n,v=(o=e.minCount)!=null?o:1,g=(a=e.maxCount)!=null?a:1/0,E=m.filter(p=>p.trim()!=="");e.required&&E.length===0&&r.push(`${t}: ${w("required",f)}`),E.length<v&&r.push(`${t}: ${w("minItems",f,{min:v})}`),E.length>g&&r.push(`${t}: ${w("maxItems",f,{max:g})}`)}return{value:h,errors:r}}else{const c=i.querySelector(`[name$="${t}"]`),h=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&h===""){const m=w("required",n.state);return r.push(`${t}: ${m}`),u(c,m),{value:null,errors:r}}return c&&d(c,h,t),{value:h===""?null:h,errors:r}}}function te(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,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",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 Ie(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 i=()=>{const s=r.value===""?null:r.value;t.instance.triggerOnChange(o,s)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const i=R(e,r,!0);l.appendChild(i)}n.appendChild(l)}function Re(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-textarea-item").forEach((p,C)=>{const b=p.querySelector("textarea");b&&(b.name=`${o}[${C}]`)})}function m(p="",C=-1){const b=document.createElement("div");b.className="multiple-textarea-item";const x=document.createElement("div");x.style.cssText="position: relative;";const y=document.createElement("textarea");if(y.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",y.style.cssText="padding-bottom: 24px;",y.placeholder=e.placeholder||w("placeholderText",r),y.rows=e.rows||4,y.value=p,y.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const $=()=>{const k=y.value===""?null:y.value;t.instance.triggerOnChange(y.name,k)};y.addEventListener("blur",$),y.addEventListener("input",$)}if(x.appendChild(y),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const $=R(e,y,!0);x.appendChild($)}return b.appendChild(x),C===-1?c.appendChild(b):c.insertBefore(b,c.children[C]),h(),b}function f(){if(r.config.readonly)return;const p=c.querySelectorAll(".multiple-textarea-item"),C=p.length;p.forEach(b=>{let x=b.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",x.innerHTML="\u2715",x.onclick=()=>{const $=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice($,1),b.remove(),h(),E(),f())},b.appendChild(x));const y=C<=u;x.disabled=y,x.style.opacity=y?"0.5":"1",x.style.pointerEvents=y?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const p=document.createElement("button");p.type="button",p.className="add-textarea-btn px-3 py-1 rounded",p.style.cssText=`
|
|
49
|
+
color: var(--fb-primary-color);
|
|
50
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
51
|
+
background-color: transparent;
|
|
52
|
+
font-size: var(--fb-font-size);
|
|
53
|
+
transition: all var(--fb-transition-duration);
|
|
54
|
+
`,p.textContent="+",p.addEventListener("mouseenter",()=>{p.style.backgroundColor="var(--fb-background-hover-color)"}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor="transparent"}),p.onclick=()=>{s.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(p),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const p=v.querySelector(".add-textarea-btn");if(p){const C=s.length>=d;p.disabled=C,p.style.opacity=C?"0.5":"1",p.style.pointerEvents=C?"none":"auto"}g.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(p=>m(p)),E(),f()}function De(e,t,n){return ee(e,t,n)}function je(e,t,n,o){te(e,t,n,o)}function ne(e,t){const n=document.createElement("span");n.className="number-counter",n.style.cssText=`
|
|
55
|
+
position: absolute;
|
|
56
|
+
top: 50%;
|
|
57
|
+
transform: translateY(-50%);
|
|
58
|
+
right: 10px;
|
|
59
|
+
font-size: var(--fb-font-size-small);
|
|
60
|
+
color: var(--fb-text-secondary-color);
|
|
61
|
+
pointer-events: none;
|
|
62
|
+
background: var(--fb-background-color);
|
|
63
|
+
padding: 0 4px;
|
|
64
|
+
`;const o=()=>{const a=t.value?parseFloat(t.value):null,l=e.min,r=e.max;if(l==null&&r==null){n.textContent="";return}a==null||l!=null&&a<l?(l!=null&&r!=null?n.textContent=`${l}-${r}`:r!=null?n.textContent=`\u2264${r}`:l!=null&&(n.textContent=`\u2265${l}`),n.style.color="var(--fb-text-secondary-color)"):r!=null&&a>r?(n.textContent=`${a}/${r}`,n.style.color="var(--fb-error-color)"):(r!=null?n.textContent=`${a}/${r}`:n.textContent=`${a}`,n.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",o),o(),n}function Oe(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 i=()=>{const s=r.value?parseFloat(r.value):null;t.instance.triggerOnChange(o,s)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.min!=null||e.max!=null)){const i=ne(e,r);l.appendChild(i)}n.appendChild(l)}function Ue(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-number-item").forEach((p,C)=>{const b=p.querySelector("input");b&&(b.name=`${o}[${C}]`)})}function m(p="",C=-1){const b=document.createElement("div");b.className="multiple-number-item flex items-center gap-2";const x=document.createElement("div");x.style.cssText="position: relative; flex: 1;";const y=document.createElement("input");if(y.type="number",y.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",y.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",y.placeholder=e.placeholder||"0",e.min!==void 0&&(y.min=e.min.toString()),e.max!==void 0&&(y.max=e.max.toString()),e.step!==void 0&&(y.step=e.step.toString()),y.value=p.toString(),y.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const $=()=>{const k=y.value?parseFloat(y.value):null;t.instance.triggerOnChange(y.name,k)};y.addEventListener("blur",$),y.addEventListener("input",$)}if(x.appendChild(y),!r.config.readonly&&(e.min!=null||e.max!=null)){const $=ne(e,y);x.appendChild($)}return b.appendChild(x),C===-1?c.appendChild(b):c.insertBefore(b,c.children[C]),h(),b}function f(){if(r.config.readonly)return;const p=c.querySelectorAll(".multiple-number-item"),C=p.length;p.forEach(b=>{let x=b.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",x.innerHTML="\u2715",x.onclick=()=>{const $=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice($,1),b.remove(),h(),E(),f())},b.appendChild(x));const y=C<=u;x.disabled=y,x.style.opacity=y?"0.5":"1",x.style.pointerEvents=y?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const p=document.createElement("button");p.type="button",p.className="add-number-btn px-3 py-1 rounded",p.style.cssText=`
|
|
65
|
+
color: var(--fb-primary-color);
|
|
66
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
67
|
+
background-color: transparent;
|
|
68
|
+
font-size: var(--fb-font-size);
|
|
69
|
+
transition: all var(--fb-transition-duration);
|
|
70
|
+
`,p.textContent="+",p.addEventListener("mouseenter",()=>{p.style.backgroundColor="var(--fb-background-hover-color)"}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor="transparent"}),p.onclick=()=>{s.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(p),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const p=v.querySelector(".add-number-btn");if(p){const C=s.length>=d;p.disabled=C,p.style.opacity=C?"0.5":"1",p.style.pointerEvents=C?"none":"auto"}g.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(p=>m(p)),E(),f()}function Pe(e,t,n){var o,a,l,r,i;const s=[],{scopeRoot:u,skipValidation:d}=n,c=(m,f)=>{var v,g;if(!m)return;const E=`error-${m.getAttribute("name")||Math.random().toString(36).substring(7)}`;let p=document.getElementById(E);f?(m.classList.add("invalid"),m.title=f,p||(p=document.createElement("div"),p.id=E,p.className="error-message",p.style.cssText=`
|
|
40
71
|
color: var(--fb-error-color);
|
|
41
72
|
font-size: var(--fb-font-size-small);
|
|
42
73
|
margin-top: 0.25rem;
|
|
43
|
-
`,
|
|
74
|
+
`,m.nextSibling?(v=m.parentNode)==null||v.insertBefore(p,m.nextSibling):(g=m.parentNode)==null||g.appendChild(p)),p.textContent=f,p.style.display="block"):(m.classList.remove("invalid"),m.title="",p&&p.remove())},h=(m,f,v)=>{let g=!1;const{state:E}=n;if(!d&&e.min!==void 0&&e.min!==null&&f<e.min){const p=w("minValue",E,{min:e.min});s.push(`${v}: ${p}`),c(m,p),g=!0}else if(!d&&e.max!==void 0&&e.max!==null&&f>e.max){const p=w("maxValue",E,{max:e.max});s.push(`${v}: ${p}`),c(m,p),g=!0}g||c(m,null)};if(e.multiple){const m=u.querySelectorAll(`[name^="${t}["]`),f=[];if(m.forEach((v,g)=>{var E,p,C;const b=(E=v==null?void 0:v.value)!=null?E:"";if(b===""){f.push(null),c(v,null);return}const x=parseFloat(b);if(!d&&!Number.isFinite(x)){const $=w("notANumber",n.state);s.push(`${t}[${g}]: ${$}`),c(v,$),f.push(null);return}h(v,x,`${t}[${g}]`);const y=Number.isInteger((p=e.decimals)!=null?p:0)&&(C=e.decimals)!=null?C:0;f.push(Number(x.toFixed(y)))}),!d){const{state:v}=n,g=(o=e.minCount)!=null?o:1,E=(a=e.maxCount)!=null?a:1/0,p=f.filter(C=>C!==null);e.required&&p.length===0&&s.push(`${t}: ${w("required",v)}`),p.length<g&&s.push(`${t}: ${w("minItems",v,{min:g})}`),p.length>E&&s.push(`${t}: ${w("maxItems",v,{max:E})}`)}return{value:f,errors:s}}else{const m=u.querySelector(`[name$="${t}"]`),f=(l=m==null?void 0:m.value)!=null?l:"",{state:v}=n;if(!d&&e.required&&f===""){const p=w("required",v);return s.push(`${t}: ${p}`),c(m,p),{value:null,errors:s}}if(f==="")return c(m,null),{value:null,errors:s};const g=parseFloat(f);if(!d&&!Number.isFinite(g)){const p=w("notANumber",v);return s.push(`${t}: ${p}`),c(m,p),{value:null,errors:s}}h(m,g,t);const E=Number.isInteger((r=e.decimals)!=null?r:0)&&(i=e.decimals)!=null?i:0;return{value:Number(g.toFixed(E)),errors:s}}}function Ve(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,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",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 _e(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(i=>{const s=document.createElement("option");s.value=i.value,s.textContent=i.label,(t.prefill[e.key]||e.default)===i.value&&(s.selected=!0),l.appendChild(s)}),!a.config.readonly&&t.instance){const i=()=>{t.instance.triggerOnChange(o,l.value)};l.addEventListener("change",i)}n.appendChild(l);const r=document.createElement("p");r.className="text-xs text-gray-500 mt-1",r.textContent=F(e,a),n.appendChild(r)}function We(e,t,n,o){var a,l,r,i;const s=t.state,u=t.prefill[e.key]||[],d=Array.isArray(u)?[...u]:[],c=(a=e.minCount)!=null?a:1,h=(l=e.maxCount)!=null?l:1/0;for(;d.length<c;)d.push(e.default||((i=(r=e.options)==null?void 0:r[0])==null?void 0:i.value)||"");const m=document.createElement("div");m.className="space-y-2",n.appendChild(m);function f(){m.querySelectorAll(".multiple-select-item").forEach((x,y)=>{const $=x.querySelector("select");$&&($.name=`${o}[${y}]`)})}function v(x="",y=-1){const $=document.createElement("div");$.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=s.config.readonly,(e.options||[]).forEach(L=>{const M=document.createElement("option");M.value=L.value,M.textContent=L.label,x===L.value&&(M.selected=!0),k.appendChild(M)}),!s.config.readonly&&t.instance){const L=()=>{t.instance.triggerOnChange(k.name,k.value)};k.addEventListener("change",L)}return $.appendChild(k),y===-1?m.appendChild($):m.insertBefore($,m.children[y]),f(),$}function g(){if(s.config.readonly)return;const x=m.querySelectorAll(".multiple-select-item"),y=x.length;x.forEach($=>{let k=$.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 M=Array.from(m.children).indexOf($);m.children.length>c&&(d.splice(M,1),$.remove(),f(),C(),g())},$.appendChild(k));const L=y<=c;k.disabled=L,k.style.opacity=L?"0.5":"1",k.style.pointerEvents=L?"none":"auto"})}let E=null,p=null;if(!s.config.readonly){E=document.createElement("div"),E.className="flex items-center gap-3 mt-2";const x=document.createElement("button");x.type="button",x.className="add-select-btn px-3 py-1 rounded",x.style.cssText=`
|
|
75
|
+
color: var(--fb-primary-color);
|
|
76
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
77
|
+
background-color: transparent;
|
|
78
|
+
font-size: var(--fb-font-size);
|
|
79
|
+
transition: all var(--fb-transition-duration);
|
|
80
|
+
`,x.textContent="+",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{var y,$;const k=e.default||(($=(y=e.options)==null?void 0:y[0])==null?void 0:$.value)||"";d.push(k),v(k),C(),g()},p=document.createElement("span"),p.className="text-sm text-gray-500",E.appendChild(x),E.appendChild(p),n.appendChild(E)}function C(){if(!E||!p)return;const x=E.querySelector(".add-select-btn");if(x){const y=d.length>=h;x.disabled=y,x.style.opacity=y?"0.5":"1",x.style.pointerEvents=y?"none":"auto"}p.textContent=`${d.length}/${h===1/0?"\u221E":h}`}d.forEach(x=>v(x)),C(),g();const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=F(e,s),n.appendChild(b)}function Je(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,i=(u,d)=>{var c,h;if(!u)return;const m=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let f=document.getElementById(m);d?(u.classList.add("invalid"),u.title=d,f||(f=document.createElement("div"),f.id=m,f.className="error-message",f.style.cssText=`
|
|
44
81
|
color: var(--fb-error-color);
|
|
45
82
|
font-size: var(--fb-font-size-small);
|
|
46
83
|
margin-top: 0.25rem;
|
|
47
|
-
`,
|
|
84
|
+
`,u.nextSibling?(c=u.parentNode)==null||c.insertBefore(f,u.nextSibling):(h=u.parentNode)==null||h.appendChild(f)),f.textContent=d,f.style.display="block"):(u.classList.remove("invalid"),u.title="",f&&f.remove())},s=(u,d,c,h)=>{var m,f;if(r)return;const{state:v}=n,g=d.filter(h),E="minCount"in c&&(m=c.minCount)!=null?m:1,p="maxCount"in c&&(f=c.maxCount)!=null?f:1/0;c.required&&g.length===0&&a.push(`${u}: ${w("required",v)}`),g.length<E&&a.push(`${u}: ${w("minItems",v,{min:E})}`),g.length>p&&a.push(`${u}: ${w("maxItems",v,{max:p})}`)};if("multiple"in e&&e.multiple){const u=l.querySelectorAll(`[name^="${t}["]`),d=[];return u.forEach(c=>{var h;const m=(h=c==null?void 0:c.value)!=null?h:"";d.push(m),i(c,null)}),s(t,d,e,c=>c!==""),{value:d,errors:a}}else{const u=l.querySelector(`[name$="${t}"]`),d=(o=u==null?void 0:u.value)!=null?o:"";if(!r&&e.required&&d===""){const c=w("required",n.state);return a.push(`${t}: ${c}`),i(u,c),{value:null,errors:a}}else i(u,null);return{value:d===""?null:d,errors:a}}}function Ye(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,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",r.querySelectorAll("option").forEach(s=>{s.selected=s.value===String(n[i])}),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 Ge(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 i;a.src=((i=r.target)==null?void 0:i.result)||""},l.readAsDataURL(t),e.appendChild(a)}function Xe(e,t,n,o,a,l){const r=URL.createObjectURL(t);e.onclick=null;const i=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(i,e),i.innerHTML=`
|
|
48
85
|
<div class="relative group h-full">
|
|
49
86
|
<video class="w-full h-full object-contain" controls preload="auto" muted>
|
|
50
|
-
<source src="${
|
|
51
|
-
|
|
87
|
+
<source src="${r}" type="${n}">
|
|
88
|
+
${S(w("videoNotSupported",a))}
|
|
52
89
|
</video>
|
|
53
90
|
<div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
|
|
54
91
|
<button class="bg-red-600 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs delete-file-btn">
|
|
55
|
-
${
|
|
92
|
+
${S(w("removeElement",a))}
|
|
56
93
|
</button>
|
|
57
94
|
<button class="bg-gray-800 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs change-file-btn">
|
|
58
|
-
|
|
95
|
+
${S(w("changeButton",a))}
|
|
59
96
|
</button>
|
|
60
97
|
</div>
|
|
61
98
|
</div>
|
|
62
|
-
`,
|
|
99
|
+
`,Ze(i,o,a,l),i}function Ze(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(),Qe(e,t,n,o)})}function Qe(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&&W(e,o.dragHandler),e.innerHTML=`
|
|
63
100
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
64
101
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
65
102
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
66
103
|
</svg>
|
|
67
|
-
<div class="text-sm text-center">${
|
|
104
|
+
<div class="text-sm text-center">${S(w("clickDragText",n))}</div>
|
|
68
105
|
</div>
|
|
69
|
-
`}function
|
|
106
|
+
`}function Ke(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;const l=document.createElement("source");l.src=t,l.type=n,a.appendChild(l),a.appendChild(document.createTextNode(w("videoNotSupported",o))),e.appendChild(a)}function et(e,t,n){ot(e,n,()=>{var o;n.resourceIndex.delete(t);const a=(o=e.parentElement)==null?void 0:o.querySelector('input[type="hidden"]');a&&(a.value=""),e.innerHTML=`
|
|
70
107
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
71
108
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
72
109
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
73
110
|
</svg>
|
|
74
|
-
<div class="text-sm text-center">${
|
|
111
|
+
<div class="text-sm text-center">${S(w("clickDragText",n))}</div>
|
|
75
112
|
</div>
|
|
76
|
-
`})}async function
|
|
113
|
+
`})}async function tt(e,t,n,o,a,l,r){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?Ge(e,t.file,n,l):t.type&&t.type.startsWith("video/")?e=Xe(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">${S(n)}</div></div>`,!a&&!(t.type&&t.type.startsWith("video/"))&&et(e,o,l))}async function nt(e,t,n,o,a){if(!a.config.getThumbnail){_(e,a);return}try{const l=await a.config.getThumbnail(t);if(l)if(H(e),o&&o.type&&o.type.startsWith("video/"))Ke(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 _(e,a)}catch(l){console.error("Failed to get thumbnail:",l),e.innerHTML=`
|
|
77
114
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
78
115
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
79
116
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
80
117
|
</svg>
|
|
81
|
-
<div class="text-sm text-center">${n||"
|
|
118
|
+
<div class="text-sm text-center">${S(n||w("previewUnavailable",a))}</div>
|
|
82
119
|
</div>
|
|
83
|
-
`}}async function
|
|
120
|
+
`}}async function re(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}");H(e),l&&e.classList.add("cursor-pointer");const i=n.resourceIndex.get(t);i&&i.file&&i.file instanceof File?await tt(e,i,a,t,l,n,r):await nt(e,t,a,i,n)}async function V(e,t,n){var o,a;const l=t.resourceIndex.get(e),r=(l==null?void 0:l.name)||e.split("/").pop()||"file",i=r.toLowerCase().match(/\.psd$/),s=document.createElement("div");s.className=i?"space-y-2":"space-y-3";const u=document.createElement("div");i?u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const d=!i&&(((o=l==null?void 0:l.type)==null?void 0:o.startsWith("image/"))||r.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),c=((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?u.innerHTML=`<img src="${f}" alt="${S(r)}" class="w-full h-auto">`:u.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">${S(r)}</div></div></div>`}catch(f){console.warn("getThumbnail failed for",e,f),u.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">${S(r)}</div></div></div>`}else u.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">${S(r)}</div></div></div>`;else if(c)if(t.config.getThumbnail)try{const f=await t.config.getThumbnail(e);f?u.innerHTML=`
|
|
84
121
|
<div class="relative group">
|
|
85
122
|
<video class="w-full h-auto" controls preload="auto" muted>
|
|
86
|
-
<source src="${f}" type="${(
|
|
87
|
-
|
|
123
|
+
<source src="${f}" type="${(l==null?void 0:l.type)||"video/mp4"}">
|
|
124
|
+
${S(w("videoNotSupported",t))}
|
|
88
125
|
</video>
|
|
89
126
|
<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">
|
|
90
127
|
<div class="bg-white bg-opacity-90 rounded-full p-3">
|
|
@@ -94,34 +131,34 @@ var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||
|
|
|
94
131
|
</div>
|
|
95
132
|
</div>
|
|
96
133
|
</div>
|
|
97
|
-
`:
|
|
134
|
+
`:u.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">${S(r)}</div></div></div>`}catch(f){console.warn("getThumbnail failed for video",e,f),u.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">${S(r)}</div></div></div>`}else u.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">${S(r)}</div></div></div>`;else{const f=i?"\u{1F3A8}":"\u{1F4C1}",v=i?"PSD File":"Document";i?u.innerHTML=`
|
|
98
135
|
<div class="flex items-center space-x-3">
|
|
99
136
|
<div class="text-3xl text-gray-400">${f}</div>
|
|
100
137
|
<div class="flex-1 min-w-0">
|
|
101
|
-
<div class="text-sm font-medium text-gray-900 truncate">${
|
|
102
|
-
<div class="text-xs text-gray-500">${
|
|
138
|
+
<div class="text-sm font-medium text-gray-900 truncate">${S(r)}</div>
|
|
139
|
+
<div class="text-xs text-gray-500">${v}</div>
|
|
103
140
|
</div>
|
|
104
141
|
</div>
|
|
105
|
-
`:
|
|
142
|
+
`:u.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">${S(r)}</div><div class="text-xs text-gray-500 mt-1">${v}</div></div></div>`}const h=document.createElement("p");h.className=i?"hidden":"text-sm font-medium text-gray-900 text-center",h.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):lt(e,r,t)},s.appendChild(u),s.appendChild(h),s.appendChild(m),s}function oe(e,t,n,o,a,l){H(e);const r=()=>{const h=[w("clickDragTextMultiple",n)];return a&&h.push(a),l&&h.push(l),h.join(" \u2022 ")},i=!e.classList.contains("grid");if((!t||t.length===0)&&i){const h=document.createElement("div");h.className="grid grid-cols-4 gap-3 mb-3";for(let f=0;f<4;f++){const v=document.createElement("div");v.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),v.appendChild(g),v.onclick=()=>{let p=e.parentElement;for(;p&&!p.classList.contains("space-y-2");)p=p.parentElement;!p&&e.classList.contains("space-y-2")&&(p=e);const C=p==null?void 0:p.querySelector('input[type="file"]');C&&C.click()},h.appendChild(v)}const m=document.createElement("div");m.className="text-center text-xs text-gray-500 mt-2",m.textContent=r(),e.appendChild(h),e.appendChild(m);return}const s=document.createElement("div");s.className="files-list grid grid-cols-4 gap-3";const u=t?t.length:0,d=(Math.floor(u/4)+1)*4;for(let h=0;h<d;h++){const m=document.createElement("div");if(t&&h<t.length){const f=t[h],v=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,rt(m,f,v,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">
|
|
106
143
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
107
|
-
<div class="text-xs"
|
|
108
|
-
</div>`}),o){const
|
|
109
|
-
<svg class="${
|
|
144
|
+
<div class="text-xs">${S(w("previewError",n))}</div>
|
|
145
|
+
</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=p=>{p.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 v=f==null?void 0:f.querySelector('input[type="file"]');v&&v.click()};s.appendChild(m)}e.appendChild(s);const c=document.createElement("div");c.className="text-center text-xs text-gray-500 mt-2",c.textContent=r(),e.appendChild(c)}function le(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
146
|
+
<svg class="${S(n)} text-red-400" fill="currentColor" viewBox="0 0 24 24">
|
|
110
147
|
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
|
|
111
148
|
</svg>
|
|
112
|
-
<div class="text-xs mt-1 text-red-600"
|
|
113
|
-
</div>`}async function
|
|
149
|
+
<div class="text-xs mt-1 text-red-600">${S(w("previewError",t))}</div>
|
|
150
|
+
</div>`}async function rt(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 i=new FileReader;i.onload=s=>{var u;r.src=((u=s.target)==null?void 0:u.result)||""},i.readAsDataURL(n.file),e.appendChild(r)}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);if(r){const i=document.createElement("img");i.className="w-full h-full object-contain",i.alt=n.name,i.src=r,e.appendChild(i)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
114
151
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
115
152
|
<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
153
|
</svg>
|
|
117
|
-
</div>`}catch(
|
|
154
|
+
</div>`}catch(r){const i=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),le(e,o)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
118
155
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
119
156
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
120
157
|
</svg>
|
|
121
|
-
</div>`;else if(n&&(
|
|
158
|
+
</div>`;else if(n&&(l=n.type)!=null&&l.startsWith("video/"))if(n.file&&n.file instanceof File){const r=URL.createObjectURL(n.file);e.innerHTML=`
|
|
122
159
|
<div class="relative group h-full w-full">
|
|
123
160
|
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
124
|
-
<source src="${
|
|
161
|
+
<source src="${r}" type="${n.type}">
|
|
125
162
|
</video>
|
|
126
163
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
127
164
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -131,10 +168,10 @@ var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||
|
|
|
131
168
|
</div>
|
|
132
169
|
</div>
|
|
133
170
|
</div>
|
|
134
|
-
`}else if(o.config.getThumbnail)try{const
|
|
171
|
+
`}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);r?e.innerHTML=`
|
|
135
172
|
<div class="relative group h-full w-full">
|
|
136
173
|
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
137
|
-
<source src="${
|
|
174
|
+
<source src="${r}" type="${n.type}">
|
|
138
175
|
</video>
|
|
139
176
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
140
177
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -148,23 +185,24 @@ var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||
|
|
|
148
185
|
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
149
186
|
<path d="M8 5v14l11-7z"/>
|
|
150
187
|
</svg>
|
|
151
|
-
<div class="text-xs mt-1">${(n==null?void 0:n.name)||"Video"}</div>
|
|
152
|
-
</div>`}catch(
|
|
188
|
+
<div class="text-xs mt-1">${S((n==null?void 0:n.name)||"Video")}</div>
|
|
189
|
+
</div>`}catch(r){const i=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),le(e,o,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
153
190
|
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
154
191
|
<path d="M8 5v14l11-7z"/>
|
|
155
192
|
</svg>
|
|
156
|
-
<div class="text-xs mt-1">${(n==null?void 0:n.name)||"Video"}</div>
|
|
193
|
+
<div class="text-xs mt-1">${S((n==null?void 0:n.name)||"Video")}</div>
|
|
157
194
|
</div>`;else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
158
195
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
159
|
-
<div class="text-xs">${(n==null?void 0:n.name)||"File"}</div>
|
|
160
|
-
</div>`}function
|
|
196
|
+
<div class="text-xs">${S((n==null?void 0:n.name)||"File")}</div>
|
|
197
|
+
</div>`}function _(e,t,n){const o=n?`<div class="text-xs text-gray-500 mt-1">${S(n)}</div>`:"";e.innerHTML=`
|
|
161
198
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
162
199
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
163
200
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
164
201
|
</svg>
|
|
165
|
-
<div class="text-sm text-center">${
|
|
202
|
+
<div class="text-sm text-center">${S(w("clickDragText",t))}</div>
|
|
203
|
+
${o}
|
|
166
204
|
</div>
|
|
167
|
-
`}async function ne(e,t,n,o,a=null,r){var l,s;let i;if(o.config.uploadFile)try{if(i=await o.config.uploadFile(e),typeof i!="string")throw new Error("Upload handler must return a string resource ID")}catch(u){const c=u instanceof Error?u:new Error(String(u));throw o.config.onUploadError&&o.config.onUploadError(c,e),new Error(`File upload failed: ${c.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(i,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let d=(l=t.parentElement)==null?void 0:l.querySelector('input[type="hidden"]');d||(d=document.createElement("input"),d.type="hidden",d.name=n,(s=t.parentElement)==null||s.appendChild(d)),d.value=i,K(t,i,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),r&&!o.config.readonly&&r.triggerOnChange(n,i)}function V(e,t){e.addEventListener("dragover",n=>{n.preventDefault(),e.classList.add("border-blue-500","bg-blue-50")}),e.addEventListener("dragleave",n=>{n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50")}),e.addEventListener("drop",n=>{var o;n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50"),(o=n.dataTransfer)!=null&&o.files&&t(n.dataTransfer.files)})}function Ke(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const a=document.createElement("div");a.className="delete-overlay absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const r=document.createElement("button");r.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",r.textContent=L("removeElement",t),r.onclick=l=>{l.stopPropagation(),n()},a.appendChild(r),e.appendChild(a)}async function re(e,t){if(t.config.uploadFile)try{const n=await t.config.uploadFile(e);if(typeof n!="string")throw new Error("Upload handler must return a string resource ID");return n}catch(n){const o=n instanceof Error?n:new Error(String(n));throw t.config.onUploadError&&t.config.onUploadError(o,e),new Error(`File upload failed: ${o.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()")}async function et(e,t,n){try{let o=null;if(n.config.getDownloadUrl?o=n.config.getDownloadUrl(e):n.config.getThumbnail&&(o=await n.config.getThumbnail(e)),o){const a=o.startsWith("http")?o:new URL(o,window.location.href).href,r=await fetch(a);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const l=await r.blob();tt(l,t)}else throw new Error("No download URL available for resource")}catch(o){const a=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(a,e,t),console.error(`File download failed for ${t}:`,a),a}}function tt(e,t){try{const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(n)},100)}catch(n){throw new Error(`Blob download failed: ${n.message}`)}}function oe(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",r=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let l="application/octet-stream";r&&(["jpg","jpeg","png","gif","webp"].includes(r)?l=`image/${r==="jpg"?"jpeg":r}`:["mp4","webm","mov","avi"].includes(r)&&(l=`video/${r==="mov"?"quicktime":r}`)),t.resourceIndex.set(n,{name:a,type:l,size:0,uploadedAt:new Date,file:void 0})}})}function nt(e,t,n,o,a,r){var l;if(!a.resourceIndex.has(e)){const i=e.split("/").pop()||"file",d=(l=i.split(".").pop())==null?void 0:l.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),a.resourceIndex.set(e,{name:i,type:u,size:0,uploadedAt:new Date,file:void 0})}K(t,e,a,{fileName:e,isReadonly:!1,deps:r}).catch(console.error);const s=document.createElement("input");s.type="hidden",s.name=n,s.value=e,o.appendChild(s)}function le(e,t,n,o,a,r){V(e,async l=>{const s=Array.from(l);for(const i of s){const d=await re(i,n);n.resourceIndex.set(d,{name:i.name,type:i.type,size:i.size,uploadedAt:new Date,file:void 0}),t.push(d)}o(),r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)})}function ae(e,t,n,o,a,r){e.onchange=async()=>{if(e.files)for(const l of Array.from(e.files)){const s=await re(l,n);n.resourceIndex.set(s,{name:l.name,type:l.type,size:l.size,uploadedAt:new Date,file:void 0}),t.push(s)}o(),e.value="",r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)}}function rt(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=t.prefill[e.key];if(l)U(l,r).then(s=>{n.appendChild(s)}).catch(s=>{console.error("Failed to render file preview:",s);const i=document.createElement("div");i.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",i.innerHTML='<div class="text-center">Preview unavailable</div>',n.appendChild(i)});else{const s=document.createElement("div");s.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",s.innerHTML=`<div class="text-center">${L("noFileSelected",r)}</div>`,n.appendChild(s)}}else{const l=document.createElement("div");l.className="space-y-2";const s=document.createElement("input");s.type="file",s.name=o,s.style.display="none",e.accept&&(s.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(h=>`.${h}`).join(","))||"");const i=document.createElement("div");i.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const d=t.prefill[e.key],u=()=>s.click(),c=h=>{if(h.length>0){const b={picker:s,fileUploadHandler:u,dragHandler:c};ne(h[0],i,o,r,b,t.instance)}};d?nt(d,i,o,l,r,{picker:s,fileUploadHandler:u,dragHandler:c}):P(i,r),i.onclick=u,V(i,c),s.onchange=()=>{if(s.files&&s.files.length>0){const h={picker:s,fileUploadHandler:u,dragHandler:c};ne(s.files[0],i,o,r,h,t.instance)}},l.appendChild(i),l.appendChild(s);const p=document.createElement("p");p.className="text-xs text-gray-600 mt-2 text-center",p.innerHTML=`<span class="underline cursor-pointer">${L("uploadText",r)}</span> ${L("dragDropTextSingle",r)}`;const v=p.querySelector("span");v&&(v.onclick=()=>s.click()),l.appendChild(p);const f=document.createElement("p");f.className="text-xs text-gray-500 mt-1 text-center",f.textContent=S(e),l.appendChild(f),n.appendChild(l)}}function ot(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=document.createElement("div");l.className="space-y-4";const s=t.prefill[e.key]||[];s.length>0?s.forEach(i=>{U(i,r).then(d=>{l.appendChild(d)}).catch(d=>{console.error("Failed to render file preview:",d)})}):l.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",r)}</div></div>`,n.appendChild(l)}else{let l=function(){ee(u,c,r,v=>{const f=c.indexOf(v);f>-1&&c.splice(f,1),l()})};const s=document.createElement("div");s.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.multiple=!0,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(v=>`.${v}`).join(","))||"");const d=document.createElement("div");d.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const u=document.createElement("div");u.className="files-list";const c=t.prefill[e.key]||[];oe(c,r),l(),le(d,c,r,l,o,t.instance),ae(i,c,r,l,o,t.instance),d.appendChild(u),s.appendChild(d),s.appendChild(i);const p=document.createElement("p");p.className="text-xs text-gray-500 mt-1 text-center",p.textContent=S(e),s.appendChild(p),n.appendChild(s)}}function lt(e,t,n,o){var a,r,l;const s=t.state,i=(a=e.minCount)!=null?a:0,d=(r=e.maxCount)!=null?r:1/0;if(s.config.readonly){const u=document.createElement("div");u.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(p=>{U(p,s).then(v=>{u.appendChild(v)}).catch(v=>{console.error("Failed to render file preview:",v)})}):u.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",s)}</div></div>`,n.appendChild(u)}else{const u=document.createElement("div");u.className="space-y-2";const c=document.createElement("input");c.type="file",c.name=o,c.multiple=!0,c.style.display="none",e.accept&&(c.accept=typeof e.accept=="string"?e.accept:((l=e.accept.extensions)==null?void 0:l.map(h=>`.${h}`).join(","))||"");const p=document.createElement("div");p.className="files-list space-y-2",u.appendChild(c),u.appendChild(p);const v=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];oe(v,s);const f=()=>{ee(p,v,s,y=>{v.splice(v.indexOf(y),1),f()});const h=document.createElement("div");h.className="text-xs text-gray-500 mt-2 file-count-info";const b=`${v.length} file${v.length!==1?"s":""}`,x=i>0||d<1/0?` (${i}-${d} allowed)`:"";h.textContent=b+x;const g=u.querySelector(".file-count-info");g&&g.remove(),u.appendChild(h)};le(p,v,s,f,o,t.instance),ae(c,v,s,f,o,t.instance),f(),n.appendChild(u)}}function ie(e,t,n){var o;const a=[],{scopeRoot:r,skipValidation:l,path:s}=n,i=e.type==="files"||"multiple"in e&&!!e.multiple,d=(u,c,p)=>{var v,f;if(l)return;const h="minCount"in p&&(v=p.minCount)!=null?v:0,b="maxCount"in p&&(f=p.maxCount)!=null?f:1/0;p.required&&c.length===0&&a.push(`${u}: required`),c.length<h&&a.push(`${u}: minimum ${h} files required`),c.length>b&&a.push(`${u}: maximum ${b} files allowed`)};if(i){const u=q(s,t),c=r.querySelector(`input[type="file"][name="${u}"]`),p=c==null?void 0:c.closest(".space-y-2"),v=(p==null?void 0:p.querySelector(".files-list"))||null,f=[];return v&&v.querySelectorAll(".resource-pill").forEach(h=>{const b=h.dataset.resourceId;b&&f.push(b)}),d(t,f,e),{value:f,errors:a}}else{const u=r.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=u==null?void 0:u.value)!=null?o:"";return!l&&e.required&&c===""?(a.push(`${t}: required`),{value:null,errors:a}):{value:c||null,errors:a}}}function se(e,t,n,o){var a;const{scopeRoot:r,state:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(s=>{var i;if(s&&typeof s=="string"&&!l.resourceIndex.has(s)){const d=s.split("/").pop()||"file",u=(i=d.split(".").pop())==null?void 0:i.toLowerCase();let c="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?c=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(c=`video/${u==="mov"?"quicktime":u}`)),l.resourceIndex.set(s,{name:d,type:c,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const s=r.querySelector(`input[name="${t}"][type="hidden"]`);if(!s){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(s.value=n!=null?String(n):"",n&&typeof n=="string"){if(!l.resourceIndex.has(n)){const i=n.split("/").pop()||"file",d=(a=i.split(".").pop())==null?void 0:a.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),l.resourceIndex.set(n,{name:i,type:u,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function T(e){return e?e.toUpperCase():"#000000"}function _(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function ce(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],o=e[3];return`#${t}${t}${n}${n}${o}${o}`.toUpperCase()}return e.toUpperCase()}function de(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=T(e),o=document.createElement("div");o.style.cssText=`
|
|
205
|
+
`}async function ae(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,re(t,s,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,s)}function W(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 ot(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 ie(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 lt(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();at(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 at(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 se(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 it(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})}re(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 ce(e,t,n,o,a,l){W(e,async r=>{const i=Array.from(r);for(const s of i){const u=await ie(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 ue(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const i=await ie(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 st(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)V(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(w("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(w("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 m={picker:i,fileUploadHandler:d,dragHandler:c};ae(h[0],s,o,l,m,t.instance)}};if(u)it(u,s,o,r,l,{picker:i,fileUploadHandler:d,dragHandler:c});else{const h=F(e,l);_(s,l,h)}s.onclick=d,W(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const h={picker:i,fileUploadHandler:d,dragHandler:c};ae(i.files[0],s,o,l,h,t.instance)}},r.appendChild(s),r.appendChild(i),n.appendChild(r)}}function ct(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=>{V(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(w("noFilesSelected",l))}</div></div>`,n.appendChild(r)}else{let r=function(){oe(d,c,l,m=>{const f=c.indexOf(m);f>-1&&c.splice(f,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(m=>`.${m}`).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]||[];se(c,l);const h=F(e,l);r(),ce(u,c,l,r,o,t.instance),ue(s,c,l,r,o,t.instance),u.appendChild(d),i.appendChild(u),i.appendChild(s),n.appendChild(i)}}function ut(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=>{V(h,i).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">${S(w("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 m=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];se(m,i);const f=F(e,i),v=()=>{const E=m.length===1?w("fileCountSingle",i,{count:m.length}):w("fileCountPlural",i,{count:m.length}),p=s>0||u<1/0?` ${w("fileCountRange",i,{min:s,max:u})}`:"";return E+p},g=()=>{oe(h,m,i,E=>{m.splice(m.indexOf(E),1),g()},f,v())};ce(h,m,i,g,o,t.instance),ue(c,m,i,g,o,t.instance),g(),n.appendChild(d)}}function de(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 m,f;if(r)return;const{state:v}=n,g="minCount"in h&&(m=h.minCount)!=null?m:0,E="maxCount"in h&&(f=h.maxCount)!=null?f:1/0;h.required&&c.length===0&&a.push(`${d}: ${w("required",v)}`),c.length<g&&a.push(`${d}: ${w("minFiles",v,{min:g})}`),c.length>E&&a.push(`${d}: ${w("maxFiles",v,{max:E})}`)};if(s){const d=A(i,t),c=l.querySelector(`input[type="file"][name="${d}"]`),h=c==null?void 0:c.closest(".space-y-2"),m=(h==null?void 0:h.querySelector(".files-list"))||null,f=[];return m&&m.querySelectorAll(".resource-pill").forEach(v=>{const g=v.dataset.resourceId;g&&f.push(g)}),u(t,f,e),{value:f,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}: ${w("required",n.state)}`),{value:null,errors:a}):{value:c||null,errors:a}}}function pe(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 q(e){return e?e.toUpperCase():"#000000"}function J(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function me(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 fe(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=q(e),o=document.createElement("div");o.style.cssText=`
|
|
168
206
|
width: 32px;
|
|
169
207
|
height: 32px;
|
|
170
208
|
border-radius: var(--fb-border-radius);
|
|
@@ -174,11 +212,11 @@ var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||
|
|
|
174
212
|
font-size: var(--fb-font-size);
|
|
175
213
|
color: var(--fb-text-color);
|
|
176
214
|
font-family: var(--fb-font-family-mono, monospace);
|
|
177
|
-
`,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function
|
|
215
|
+
`,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function he(e,t,n){const o=q(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
|
|
178
216
|
display: flex;
|
|
179
217
|
align-items: center;
|
|
180
218
|
gap: 8px;
|
|
181
|
-
`;const
|
|
219
|
+
`;const l=document.createElement("div");l.className="colour-swatch",l.style.cssText=`
|
|
182
220
|
width: 40px;
|
|
183
221
|
height: 40px;
|
|
184
222
|
border-radius: var(--fb-border-radius);
|
|
@@ -187,7 +225,7 @@ var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||
|
|
|
187
225
|
cursor: pointer;
|
|
188
226
|
transition: border-color var(--fb-transition-duration) ease-in-out;
|
|
189
227
|
flex-shrink: 0;
|
|
190
|
-
`;const
|
|
228
|
+
`;const r=document.createElement("input");r.type="text",r.className="colour-hex-input",r.name=t,r.value=o,r.placeholder="#000000",r.style.cssText=`
|
|
191
229
|
width: 100px;
|
|
192
230
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
193
231
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
@@ -197,117 +235,119 @@ var FormBuilder=(function(F){"use strict";function we(e,t){(e.minLength!==null||
|
|
|
197
235
|
font-size: var(--fb-font-size);
|
|
198
236
|
font-family: var(--fb-font-family-mono, monospace);
|
|
199
237
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
200
|
-
`;const
|
|
238
|
+
`;const i=document.createElement("input");return i.type="color",i.className="colour-picker-hidden",i.value=o.toLowerCase(),i.style.cssText=`
|
|
201
239
|
position: absolute;
|
|
202
240
|
opacity: 0;
|
|
203
241
|
pointer-events: none;
|
|
204
|
-
`,
|
|
242
|
+
`,r.addEventListener("input",()=>{const s=r.value.trim();if(J(s)){const u=me(s);l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,u)}else r.classList.add("invalid")}),r.addEventListener("blur",()=>{const s=r.value.trim();if(J(s)){const u=me(s);r.value=u,l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid")}}),i.addEventListener("change",()=>{const s=q(i.value);r.value=s,l.style.backgroundColor=s,n.instance&&n.instance.triggerOnChange(t,s)}),l.addEventListener("click",()=>{i.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(i),a}function dt(e,t,n,o){const a=t.state,l=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const i=fe(l);n.appendChild(i)}else{const i=he(l,o,t);n.appendChild(i)}const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
|
|
205
243
|
font-size: var(--fb-font-size-small);
|
|
206
244
|
color: var(--fb-text-secondary-color);
|
|
207
|
-
`,
|
|
245
|
+
`,r.textContent=F(e,a),n.appendChild(r)}function pt(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"#000000");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-colour-item").forEach((C,b)=>{const x=C.querySelector("input");x&&(x.name=`${o}[${b}]`)})}function m(C="#000000",b=-1){const x=document.createElement("div");if(x.className="multiple-colour-item flex items-center gap-2",r.config.readonly){const y=fe(C);for(;y.firstChild;)x.appendChild(y.firstChild)}else{const y=`${o}[${c.children.length}]`,$=he(C,y,t);$.style.flex="1",x.appendChild($)}return b===-1?c.appendChild(x):c.insertBefore(x,c.children[b]),h(),x}function f(){if(r.config.readonly)return;const C=c.querySelectorAll(".multiple-colour-item"),b=C.length;C.forEach(x=>{let y=x.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=`
|
|
208
246
|
color: var(--fb-error-color);
|
|
209
247
|
background-color: transparent;
|
|
210
248
|
transition: background-color var(--fb-transition-duration);
|
|
211
|
-
`,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
249
|
+
`,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(c.children).indexOf(x);c.children.length>u&&(s.splice(k,1),x.remove(),h(),E(),f())},x.appendChild(y));const $=b<=u;y.disabled=$,y.style.opacity=$?"0.5":"1",y.style.pointerEvents=$?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const C=document.createElement("button");C.type="button",C.className="add-colour-btn px-3 py-1 rounded",C.style.cssText=`
|
|
250
|
+
color: var(--fb-primary-color);
|
|
251
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
252
|
+
background-color: transparent;
|
|
253
|
+
font-size: var(--fb-font-size);
|
|
254
|
+
transition: all var(--fb-transition-duration);
|
|
255
|
+
`,C.textContent="+",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const b=e.default||"#000000";s.push(b),m(b),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(C),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const C=v.querySelector(".add-colour-btn");if(C){const b=s.length>=d;C.disabled=b,C.style.opacity=b?"0.5":"1",C.style.pointerEvents=b?"none":"auto"}g.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(C=>m(C)),E(),f();const p=document.createElement("p");p.className="mt-1",p.style.cssText=`
|
|
218
256
|
font-size: var(--fb-font-size-small);
|
|
219
257
|
color: var(--fb-text-secondary-color);
|
|
220
|
-
`,
|
|
258
|
+
`,p.textContent=F(e,r),n.appendChild(p)}function mt(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,h)=>{var m,f;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,g||(g=document.createElement("div"),g.id=v,g.className="error-message",g.style.cssText=`
|
|
221
259
|
color: var(--fb-error-color);
|
|
222
260
|
font-size: var(--fb-font-size-small);
|
|
223
261
|
margin-top: 0.25rem;
|
|
224
|
-
`,c.nextSibling?(
|
|
262
|
+
`,c.nextSibling?(m=c.parentNode)==null||m.insertBefore(g,c.nextSibling):(f=c.parentNode)==null||f.appendChild(g)),g.textContent=h,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},d=(c,h,m)=>{const{state:f}=n;if(!h){if(!s&&e.required){const g=w("required",f);return r.push(`${m}: ${g}`),u(c,g),""}return u(c,null),""}const v=q(h);if(!s&&!J(v)){const g=w("invalidHexColour",f);return r.push(`${m}: ${g}`),u(c,g),h}return u(c,null),v};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["].colour-hex-input`),h=[];if(c.forEach((m,f)=>{var v;const g=(v=m==null?void 0:m.value)!=null?v:"",E=d(m,g,`${t}[${f}]`);h.push(E)}),!s){const{state:m}=n,f=(o=e.minCount)!=null?o:1,v=(a=e.maxCount)!=null?a:1/0,g=h.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>v&&r.push(`${t}: ${w("maxItems",m,{max:v})}`)}return{value:h,errors:r}}else{const c=i.querySelector(`[name="${t}"].colour-hex-input`),h=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&h===""){const m=w("required",n.state);return r.push(`${t}: ${m}`),u(c,m),{value:"",errors:r}}return{value:d(c,h,t),errors:r}}}function ft(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,i)=>{if(i<n.length){const s=q(n[i]);r.value=s,r.classList.remove("invalid"),r.title="";const u=r.closest(".colour-picker-wrapper");if(u){const d=u.querySelector(".colour-swatch"),c=u.querySelector(".colour-picker-hidden");d&&(d.style.backgroundColor=s),c&&(c.value=s.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=q(n);l.value=r,l.classList.remove("invalid"),l.title="";const i=l.closest(".colour-picker-wrapper");if(i){const s=i.querySelector(".colour-swatch"),u=i.querySelector(".colour-picker-hidden");s&&(s.style.backgroundColor=r),u&&(u.value=r.toLowerCase())}}}}function ve(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 Y(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 D(e,t){return Math.round(e/t)*t}function ge(e,t,n,o,a){var l;const r=document.createElement("div");r.className="slider-container";const i=document.createElement("div");i.className="flex items-start gap-3";const s=document.createElement("div");s.className="flex-1";const u=document.createElement("input");u.type="range",u.name=t,u.className="slider-input w-full",u.disabled=a;const d=n.scale||"linear",c=n.min,h=n.max,m=(l=n.step)!=null?l:1;if(d==="exponential"){if(c<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${c})`);u.min="0",u.max="1000",u.step="1";const p=Y(e,c,h);u.value=(p*1e3).toString()}else u.min=c.toString(),u.max=h.toString(),u.step=m.toString(),u.value=e.toString();u.style.cssText=`
|
|
225
263
|
height: 6px;
|
|
226
264
|
border-radius: 3px;
|
|
227
265
|
background: linear-gradient(
|
|
228
266
|
to right,
|
|
229
267
|
var(--fb-primary-color) 0%,
|
|
230
|
-
var(--fb-primary-color) ${(e-
|
|
231
|
-
var(--fb-border-color) ${(e-
|
|
268
|
+
var(--fb-primary-color) ${(e-c)/(h-c)*100}%,
|
|
269
|
+
var(--fb-border-color) ${(e-c)/(h-c)*100}%,
|
|
232
270
|
var(--fb-border-color) 100%
|
|
233
271
|
);
|
|
234
272
|
outline: none;
|
|
235
273
|
transition: background 0.1s ease-in-out;
|
|
236
274
|
cursor: ${a?"not-allowed":"pointer"};
|
|
237
275
|
opacity: ${a?"0.6":"1"};
|
|
238
|
-
|
|
276
|
+
`,s.appendChild(u);const f=document.createElement("div");f.className="flex justify-between",f.style.cssText=`
|
|
277
|
+
font-size: var(--fb-font-size-small);
|
|
278
|
+
color: var(--fb-text-secondary-color);
|
|
279
|
+
margin-top: 4px;
|
|
280
|
+
`;const v=document.createElement("span");v.textContent=c.toString();const g=document.createElement("span");g.textContent=h.toString(),f.appendChild(v),f.appendChild(g),s.appendChild(f);const E=document.createElement("span");if(E.className="slider-value",E.style.cssText=`
|
|
239
281
|
min-width: 60px;
|
|
240
282
|
text-align: right;
|
|
241
283
|
font-size: var(--fb-font-size);
|
|
242
284
|
color: var(--fb-text-color);
|
|
243
285
|
font-family: var(--fb-font-family-mono, monospace);
|
|
244
286
|
font-weight: 500;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
color: var(--fb-text-secondary-color);
|
|
248
|
-
`;const h=document.createElement("span");h.textContent=u.toString();const b=document.createElement("span");if(b.textContent=c.toString(),f.appendChild(h),f.appendChild(b),l.appendChild(f),!a){const x=()=>{let g;if(d==="exponential"){const m=parseFloat(i.value)/1e3;g=fe(m,u,c),g=B(g,p),g=Math.max(u,Math.min(c,g))}else g=parseFloat(i.value),g=B(g,p);v.textContent=g.toFixed(p<1?2:0);const y=(g-u)/(c-u)*100;i.style.background=`linear-gradient(
|
|
287
|
+
padding-top: 2px;
|
|
288
|
+
`,E.textContent=e.toFixed(m<1?2:0),i.appendChild(s),i.appendChild(E),r.appendChild(i),!a){const p=()=>{let C;if(d==="exponential"){const x=parseFloat(u.value)/1e3;C=ve(x,c,h),C=D(C,m),C=Math.max(c,Math.min(h,C))}else C=parseFloat(u.value),C=D(C,m);E.textContent=C.toFixed(m<1?2:0);const b=(C-c)/(h-c)*100;u.style.background=`linear-gradient(
|
|
249
289
|
to right,
|
|
250
290
|
var(--fb-primary-color) 0%,
|
|
251
|
-
var(--fb-primary-color) ${
|
|
252
|
-
var(--fb-border-color) ${
|
|
291
|
+
var(--fb-primary-color) ${b}%,
|
|
292
|
+
var(--fb-border-color) ${b}%,
|
|
253
293
|
var(--fb-border-color) 100%
|
|
254
|
-
)`,o.instance&&o.instance.triggerOnChange(t,
|
|
294
|
+
)`,o.instance&&o.instance.triggerOnChange(t,C)};u.addEventListener("input",p),u.addEventListener("change",p)}return r}function ht(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,i=(a=t.prefill[e.key])!=null?a:r,s=ge(i,o,e,t,l.config.readonly);n.appendChild(s);const u=document.createElement("p");u.className="mt-1",u.style.cssText=`
|
|
255
295
|
font-size: var(--fb-font-size-small);
|
|
256
296
|
color: var(--fb-text-secondary-color);
|
|
257
|
-
`,
|
|
297
|
+
`,u.textContent=F(e,l),n.appendChild(u)}function vt(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,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0,c=e.default!==void 0?e.default:(e.min+e.max)/2;for(;s.length<u;)s.push(c);const h=document.createElement("div");h.className="space-y-3",n.appendChild(h);function m(){h.querySelectorAll(".multiple-slider-item").forEach((b,x)=>{const y=b.querySelector("input[type=range]");y&&y.setAttribute("name",`${o}[${x}]`)})}function f(b=c,x=-1){const y=document.createElement("div");y.className="multiple-slider-item flex items-start gap-2";const $=`${o}[${h.children.length}]`,k=ge(b,$,e,t,r.config.readonly);return k.style.flex="1",y.appendChild(k),x===-1?h.appendChild(y):h.insertBefore(y,h.children[x]),m(),y}function v(){if(r.config.readonly)return;const b=h.querySelectorAll(".multiple-slider-item"),x=b.length;b.forEach(y=>{let $=y.querySelector(".remove-item-btn");$||($=document.createElement("button"),$.type="button",$.className="remove-item-btn px-2 py-1 rounded",$.style.cssText=`
|
|
258
298
|
color: var(--fb-error-color);
|
|
259
299
|
background-color: transparent;
|
|
260
300
|
transition: background-color var(--fb-transition-duration);
|
|
261
301
|
margin-top: 8px;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
302
|
+
`,$.innerHTML="\u2715",$.addEventListener("mouseenter",()=>{$.style.backgroundColor="var(--fb-background-hover-color)"}),$.addEventListener("mouseleave",()=>{$.style.backgroundColor="transparent"}),$.onclick=()=>{const L=Array.from(h.children).indexOf(y);h.children.length>u&&(s.splice(L,1),y.remove(),m(),p(),v())},y.appendChild($));const k=x<=u;$.disabled=k,$.style.opacity=k?"0.5":"1",$.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 b=document.createElement("button");b.type="button",b.className="add-slider-btn px-3 py-1 rounded",b.style.cssText=`
|
|
303
|
+
color: var(--fb-primary-color);
|
|
304
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
305
|
+
background-color: transparent;
|
|
306
|
+
font-size: var(--fb-font-size);
|
|
307
|
+
transition: all var(--fb-transition-duration);
|
|
308
|
+
`,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{s.push(c),f(c),p(),v()},E=document.createElement("span"),E.className="text-sm text-gray-500",g.appendChild(b),g.appendChild(E),n.appendChild(g)}function p(){if(!g||!E)return;const b=g.querySelector(".add-slider-btn");if(b){const x=s.length>=d;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"}E.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(b=>f(b)),p(),v();const C=document.createElement("p");C.className="mt-1",C.style.cssText=`
|
|
269
309
|
font-size: var(--fb-font-size-small);
|
|
270
310
|
color: var(--fb-text-secondary-color);
|
|
271
|
-
`,
|
|
311
|
+
`,C.textContent=F(e,r),n.appendChild(C)}function gt(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=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 u=e.min,d=e.max,c=(o=e.step)!=null?o:1,h=e.scale||"linear",m=(v,g)=>{var E,p;if(!v)return;const C=`error-${v.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(C);if(g){if(v.classList.add("invalid"),v.title=g,!b){b=document.createElement("div"),b.id=C,b.className="error-message",b.style.cssText=`
|
|
272
312
|
color: var(--fb-error-color);
|
|
273
313
|
font-size: var(--fb-font-size-small);
|
|
274
314
|
margin-top: 0.25rem;
|
|
275
|
-
`;const
|
|
315
|
+
`;const x=v.closest(".slider-container");x&&x.nextSibling?(E=x.parentNode)==null||E.insertBefore(b,x.nextSibling):x&&((p=x.parentNode)==null||p.appendChild(b))}b.textContent=g,b.style.display="block"}else v.classList.remove("invalid"),v.title="",b&&b.remove()},f=(v,g)=>{const{state:E}=n,p=v.value;if(!p){if(!s&&e.required){const b=w("required",E);return r.push(`${g}: ${b}`),m(v,b),null}return m(v,null),null}let C;if(h==="exponential"){const b=parseFloat(p)/1e3;C=ve(b,u,d),C=D(C,c)}else C=parseFloat(p),C=D(C,c);if(!s){if(C<u){const b=w("minValue",E,{min:u});return r.push(`${g}: ${b}`),m(v,b),C}if(C>d){const b=w("maxValue",E,{max:d});return r.push(`${g}: ${b}`),m(v,b),C}}return m(v,null),C};if(e.multiple){const v=i.querySelectorAll(`input[type="range"][name^="${t}["]`),g=[];if(v.forEach((E,p)=>{const C=f(E,`${t}[${p}]`);g.push(C)}),!s){const{state:E}=n,p=(a=e.minCount)!=null?a:1,C=(l=e.maxCount)!=null?l:1/0,b=g.filter(x=>x!==null);e.required&&b.length===0&&r.push(`${t}: ${w("required",E)}`),b.length<p&&r.push(`${t}: ${w("minItems",E,{min:p})}`),b.length>C&&r.push(`${t}: ${w("maxItems",E,{max:C})}`)}return{value:g,errors:r}}else{const v=i.querySelector(`input[type="range"][name="${t}"]`);return v?{value:f(v,t),errors:r}:(!s&&e.required&&r.push(`${t}: ${w("required",n.state)}`),{value:null,errors:r})}}function yt(e,t,n,o){var a;const{scopeRoot:l}=o,r=e.min,i=e.max,s=(a=e.step)!=null?a:1,u=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((c,h)=>{if(h<n.length&&n[h]!==null){const m=Number(n[h]);if(u==="exponential"){const v=Y(m,r,i);c.value=(v*1e3).toString()}else c.value=m.toString();const f=c.closest(".slider-container");if(f){const v=f.querySelector(".slider-value");v&&(v.textContent=m.toFixed(s<1?2:0));const g=(m-r)/(i-r)*100;c.style.background=`linear-gradient(
|
|
276
316
|
to right,
|
|
277
317
|
var(--fb-primary-color) 0%,
|
|
278
|
-
var(--fb-primary-color) ${
|
|
279
|
-
var(--fb-border-color) ${
|
|
318
|
+
var(--fb-primary-color) ${g}%,
|
|
319
|
+
var(--fb-border-color) ${g}%,
|
|
280
320
|
var(--fb-border-color) 100%
|
|
281
|
-
)`}c.classList.remove("invalid"),c.title=""}}),n.length!==
|
|
321
|
+
)`}c.classList.remove("invalid"),c.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 c=Number(n);if(u==="exponential"){const m=Y(c,r,i);d.value=(m*1e3).toString()}else d.value=c.toString();const h=d.closest(".slider-container");if(h){const m=h.querySelector(".slider-value");m&&(m.textContent=c.toFixed(s<1?2:0));const f=(c-r)/(i-r)*100;d.style.background=`linear-gradient(
|
|
282
322
|
to right,
|
|
283
323
|
var(--fb-primary-color) 0%,
|
|
284
324
|
var(--fb-primary-color) ${f}%,
|
|
285
325
|
var(--fb-border-color) ${f}%,
|
|
286
326
|
var(--fb-border-color) 100%
|
|
287
|
-
)`}
|
|
327
|
+
)`}d.classList.remove("invalid"),d.title=""}}}function G(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 X=null;function bt(e){X=e}function j(e,t){if(!X)throw new Error("renderElement not initialized. Import from components/index.ts");return X(e,t)}function ye(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 be(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 i=document.createElement("div"),s=e.columns||1;if(s===1?i.className="space-y-4":i.className=`grid grid-cols-${s} gap-4`,!t.state.config.readonly){const d=ye(e,o);d&&r.appendChild(d)}const u={path:A(t.path,e.key),prefill:((a=t.prefill)==null?void 0:a[e.key])||{},formData:(l=t.formData)!=null?l:t.prefill,state:t.state};e.elements.forEach(d=>{d.hidden||i.appendChild(j(d,u))}),r.appendChild(i),n.appendChild(r)}function xe(e,t,n,o){var a,l,r,i;const s=t.state,u=document.createElement("div");u.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 c=document.createElement("div");if(c.className="space-y-4",!t.state.config.readonly){const p=ye(e,e.key);p&&u.appendChild(p)}const h=(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,v=()=>c.querySelectorAll(":scope > .containerItem").length,g=()=>{const p=document.createElement("button");return p.type="button",p.className="add-container-btn px-3 py-1 rounded",p.style.cssText=`
|
|
288
328
|
color: var(--fb-primary-color);
|
|
289
329
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
290
330
|
background-color: transparent;
|
|
291
331
|
font-size: var(--fb-font-size);
|
|
292
332
|
transition: all var(--fb-transition-duration);
|
|
293
|
-
`,
|
|
333
|
+
`,p.textContent="+",p.addEventListener("mouseenter",()=>{p.style.backgroundColor="var(--fb-background-hover-color)"}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor="transparent"}),p.onclick=()=>{if(v()<m){const C=v(),b=s.formRoot?G(s.formRoot):{},x={state:t.state,path:A(t.path,`${e.key}[${C}]`),prefill:{},formData:b},y=document.createElement("div");y.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",y.setAttribute("data-container-item",`${e.key}[${C}]`);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(L=>{L.hidden||$.appendChild(j(L,x))}),y.appendChild($),!s.config.readonly){const L=document.createElement("button");L.type="button",L.className="absolute top-2 right-2 px-2 py-1 rounded",L.style.cssText=`
|
|
294
334
|
color: var(--fb-error-color);
|
|
295
335
|
background-color: transparent;
|
|
296
336
|
transition: background-color var(--fb-transition-duration);
|
|
297
|
-
`,
|
|
337
|
+
`,L.textContent="\u2715",L.addEventListener("mouseenter",()=>{L.style.backgroundColor="var(--fb-background-hover-color)"}),L.addEventListener("mouseleave",()=>{L.style.backgroundColor="transparent"}),L.onclick=()=>{y.remove(),E()},y.style.position="relative",y.appendChild(L)}c.appendChild(y),E()}},p},E=()=>{const p=v(),C=u.querySelector(".add-container-btn");C&&(C.disabled=p>=m,C.style.opacity=p>=m?"0.5":"1",C.style.pointerEvents=p>=m?"none":"auto"),d.textContent=`${p}/${m===1/0?"\u221E":m}`};if(f&&Array.isArray(f)&&f.forEach((p,C)=>{var b;const x={state:t.state,path:A(t.path,`${e.key}[${C}]`),prefill:p||{},formData:(b=t.formData)!=null?b:t.prefill},y=document.createElement("div");y.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",y.setAttribute("data-container-item",`${e.key}[${C}]`);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(L=>{L.hidden||$.appendChild(j(L,x))}),y.appendChild($),!s.config.readonly){const L=document.createElement("button");L.type="button",L.className="absolute top-2 right-2 px-2 py-1 rounded",L.style.cssText=`
|
|
298
338
|
color: var(--fb-error-color);
|
|
299
339
|
background-color: transparent;
|
|
300
340
|
transition: background-color var(--fb-transition-duration);
|
|
301
|
-
`,
|
|
341
|
+
`,L.textContent="\u2715",L.addEventListener("mouseenter",()=>{L.style.backgroundColor="var(--fb-background-hover-color)"}),L.addEventListener("mouseleave",()=>{L.style.backgroundColor="transparent"}),L.onclick=()=>{y.remove(),E()},y.style.position="relative",y.appendChild(L)}c.appendChild(y)}),!s.config.readonly)for(;v()<h;){const p=v(),C={state:t.state,path:A(t.path,`${e.key}[${p}]`),prefill:{},formData:(i=t.formData)!=null?i:t.prefill},b=document.createElement("div");b.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",b.setAttribute("data-container-item",`${e.key}[${p}]`);const x=document.createElement("div"),y=e.columns||1;y===1?x.className="space-y-4":x.className=`grid grid-cols-${y} gap-4`,e.elements.forEach(k=>{k.hidden||x.appendChild(j(k,C))}),b.appendChild(x);const $=document.createElement("button");$.type="button",$.className="absolute top-2 right-2 px-2 py-1 rounded",$.style.cssText=`
|
|
302
342
|
color: var(--fb-error-color);
|
|
303
343
|
background-color: transparent;
|
|
304
344
|
transition: background-color var(--fb-transition-duration);
|
|
305
|
-
`,w.textContent="\u2715",w.addEventListener("mouseenter",()=>{w.style.backgroundColor="var(--fb-background-hover-color)"}),w.addEventListener("mouseleave",()=>{w.style.backgroundColor="transparent"}),w.onclick=()=>{b()>v&&(C.remove(),g())},C.style.position="relative",C.appendChild(w),p.appendChild(C)}d.appendChild(p),i.config.readonly||d.appendChild(x()),g(),n.appendChild(d)}let G=null;function vt(e){G=e}function ge(e,t,n){if(!G)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return G(e,t,n)}function ye(e,t,n){const o=[],{scopeRoot:a,skipValidation:r,path:l}=n;if(!("elements"in e))return{value:null,errors:o};const s=(i,d,u)=>{var c,p;if(r)return;const v="minCount"in u&&(c=u.minCount)!=null?c:0,f="maxCount"in u&&(p=u.maxCount)!=null?p:1/0;u.required&&d.length===0&&o.push(`${i}: required`),d.length<v&&o.push(`${i}: minimum ${v} items required`),d.length>f&&o.push(`${i}: maximum ${f} items allowed`)};if("multiple"in e&&e.multiple){const i=[],d=a.querySelectorAll("[data-container-item]"),u=Array.from(d).filter(c=>{const p=c.getAttribute("data-container-item");return p==null?void 0:p.startsWith(`${t}[`)}).length;for(let c=0;c<u;c++){const p={},v=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(f=>{var h;if(f.enableIf)try{const b=(h=n.instance)!=null&&h.getState().formRoot?J(n.instance.getState().formRoot):{};if(!A(f.enableIf,b,p))return}catch(b){console.error(`Error evaluating enableIf for field "${f.key}" in container "${t}[${c}]":`,b)}if(f.hidden||f.type==="hidden")p[f.key]=f.default!==void 0?f.default:null;else{const b=`${t}[${c}].${f.key}`;p[f.key]=ge({...f,key:b},{path:l},v)}}),i.push(p)}return s(t,i,e),{value:i,errors:o}}else{const i={},d=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(u=>{var c;if(u.enableIf)try{const p=(c=n.instance)!=null&&c.getState().formRoot?J(n.instance.getState().formRoot):{};if(!A(u.enableIf,p,i))return}catch(p){console.error(`Error evaluating enableIf for field "${u.key}" in container "${t}":`,p)}if(u.hidden||u.type==="hidden")i[u.key]=u.default!==void 0?u.default:null;else{const p=`${t}.${u.key}`;i[u.key]=ge({...u,key:p},{path:l},d)}}),{value:i,errors:o}}}function be(e,t,n,o){const{instance:a,scopeRoot:r}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((s,i)=>{z(s)&&e.elements.forEach(d=>{const u=d.key,c=`${t}[${i}].${u}`,p=s[u];p!==void 0&&a.updateField(c,p)})});const l=r.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==l.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!z(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(l=>{const s=l.key,i=`${t}.${s}`,d=n[s];d!==void 0&&a.updateField(i,d)})}}function ht(e,t,n,o){var a,r;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const l={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&z(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(r=e.repeat)==null?void 0:r.max};l.multiple?he(l,t,n):ve(l,t,n,o)}function xe(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&z(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function gt(e,t,n){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field key: "${t}"`);const o=xe(e);return ye(o,t,n)}function yt(e,t,n,o){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const a=xe(e);return be(a,t,n,o)}function bt(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(u=>{u.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),r=window.innerWidth,l=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const s=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let i=a.left,d=a.bottom+5;i+s.width>r&&(i=a.right-s.width),d+s.height>l&&(d=a.top-s.height-5),i<10&&(i=10),d<10&&(d=a.bottom+5),n.style.left=`${i}px`,n.style.top=`${d}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(a=>{a.classList.add("hidden")})});function xt(e,t){var n,o;if(!e.enableIf)return!1;try{const a=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=t.path?I(a,t.path):void 0;return!A(e.enableIf,a,r)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function Ct(e,t){const n=t.querySelector(`[name="${e}"]`);if(n){if(n instanceof HTMLSelectElement)return n.value;if(n instanceof HTMLInputElement){if(n.type==="checkbox")return n.checked;if(n.type==="radio"){const o=t.querySelector(`[name="${e}"]:checked`);return o?o.value:void 0}else return n.value}else if(n instanceof HTMLTextAreaElement)return n.value}}function R(e,t,n){var o,a;if(!t.enableIf)return;const r=n.state.formRoot;if(!r){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const l=t.enableIf,s=(o=l.scope)!=null?o:"relative";let i={};const d={};if((!n.path||n.path===""?"absolute":s)==="relative"&&n.path){const u=n.path.match(/^(.+)\[(\d+)\]$/);if(u){const c=u[1],p=parseInt(u[2],10),v=r.querySelector(`[data-container-item="${c}[${p}]"]`);v&&v.querySelectorAll("input, select, textarea").forEach(f=>{const h=f.getAttribute("name");if(h){const b=h.match(/\.([^.[\]]+)$/);if(b){const x=b[1];f instanceof HTMLSelectElement?d[x]=f.value:f instanceof HTMLInputElement?f.type==="checkbox"?d[x]=f.checked:f.type==="radio"?f.checked&&(d[x]=f.value):d[x]=f.value:f instanceof HTMLTextAreaElement&&(d[x]=f.value)}}})}}else{const u=l.key,c=Ct(u,r);c!==void 0?i[u]=c:i=(a=n.formData)!=null?a:n.prefill}try{A(l,i,d)?(e.style.display="",e.classList.remove("fb-field-wrapper-disabled"),e.removeAttribute("data-conditionally-disabled")):(e.style.display="none",e.classList.add("fb-field-wrapper-disabled"),e.setAttribute("data-conditionally-disabled","true"))}catch(u){console.error(`Error re-evaluating enableIf for field "${t.key}":`,u)}}function Et(e,t,n){var o;if(!t.enableIf)return;const a=n.state.formRoot;if(!a){console.error("Cannot setup enableIf listeners: formRoot is null");return}const r=t.enableIf,l=(o=r.scope)!=null?o:"relative",s=r.key;let i;l==="relative"&&n.path?i=`${n.path}.${s}`:i=s;const d=a.querySelector(`[name="${i}"]`);if(!d){const u=new MutationObserver(()=>{const c=a.querySelector(`[name="${i}"]`);c&&(c.addEventListener("change",()=>{R(e,t,n)}),c.addEventListener("input",()=>{R(e,t,n)}),u.disconnect())});u.observe(a,{childList:!0,subtree:!0});return}d.addEventListener("change",()=>{R(e,t,n)}),d.addEventListener("input",()=>{R(e,t,n)})}function $t(e){const t=document.createElement("label");if(t.className="text-sm font-medium text-gray-900",t.textContent=e.label||e.key,e.required){const n=document.createElement("span");n.className="text-red-500 ml-1",n.textContent="*",t.appendChild(n)}return t}function wt(e){const t=document.createElement("button");t.type="button",t.className="ml-2 text-gray-400 hover:text-gray-600",t.innerHTML='<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>';const n=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,o=document.createElement("div");return o.id=n,o.className="hidden absolute z-50 bg-gray-200 text-gray-900 text-sm rounded-lg p-3 max-w-sm border border-gray-300 shadow-lg",o.style.position="fixed",o.textContent=e.description||e.hint||"Field information",document.body.appendChild(o),t.onclick=a=>{a.preventDefault(),a.stopPropagation(),bt(n,t)},t}function kt(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=$t(e);if(t.appendChild(n),e.description||e.hint){const o=wt(e);t.appendChild(o)}return t}function St(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?Ae(e,t,n,o):qe(e,t,n,o);break;case"textarea":a?He(e,t,n,o):Te(e,t,n,o);break;case"number":a?Be(e,t,n,o):Ie(e,t,n,o);break;case"select":a?Oe(e,t,n,o):De(e,t,n,o);break;case"file":a?lt(e,t,n,o):rt(e,t,n,o);break;case"files":ot(e,t,n,o);break;case"colour":a?it(e,t,n,o):at(e,t,n,o);break;case"slider":a?ut(e,t,n,o):dt(e,t,n,o);break;case"group":ht(e,t,n,o);break;case"container":a?he(e,t,n):ve(e,t,n,o);break;default:{const r=document.createElement("div");r.className="text-red-500 text-sm",r.textContent=`Unsupported field type: ${e.type}`,n.appendChild(r)}}}function X(e,t){const n=xt(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=kt(e);o.appendChild(a);const r=q(t.path,e.key);return St(e,t,o,r),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),Et(o,e,t),o}mt(X);const Lt={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{addElement:"Add Element",removeElement:"Remove",uploadText:"Upload",dragDropText:"or drag and drop files",dragDropTextSingle:"or drag and drop file",clickDragText:"Click or drag file",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download"},ru:{addElement:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u044D\u043B\u0435\u043C\u0435\u043D\u0442",removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",uploadText:"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435",dragDropText:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",dragDropTextSingle:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C"}},theme:{}};function Ft(e){return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Lt,...e},debounceTimer:null}}function Nt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const M={primaryColor:"#3b82f6",primaryHoverColor:"#2563eb",errorColor:"#ef4444",errorHoverColor:"#dc2626",successColor:"#10b981",borderColor:"#d1d5db",borderHoverColor:"#9ca3af",borderFocusColor:"#3b82f6",backgroundColor:"#ffffff",backgroundHoverColor:"#f9fafb",backgroundReadonlyColor:"#f3f4f6",textColor:"#1f2937",textSecondaryColor:"#6b7280",textPlaceholderColor:"#9ca3af",textDisabledColor:"#d1d5db",buttonBgColor:"#3b82f6",buttonTextColor:"#ffffff",buttonBorderColor:"#2563eb",buttonHoverBgColor:"#2563eb",buttonHoverBorderColor:"#1d4ed8",actionBgColor:"#ffffff",actionTextColor:"#374151",actionBorderColor:"#e5e7eb",actionHoverBgColor:"#f9fafb",actionHoverBorderColor:"#d1d5db",fileUploadBgColor:"#f3f4f6",fileUploadBorderColor:"#d1d5db",fileUploadTextColor:"#9ca3af",fileUploadHoverBorderColor:"#3b82f6",inputPaddingX:"0.75rem",inputPaddingY:"0.5rem",borderRadius:"0.5rem",borderWidth:"1px",fontSize:"0.875rem",fontSizeSmall:"0.75rem",fontSizeExtraSmall:"0.625rem",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeightNormal:"400",fontWeightMedium:"500",focusRingWidth:"2px",focusRingColor:"#3b82f6",focusRingOpacity:"0.5",transitionDuration:"200ms"};function qt(e){const t={...M,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${r}: ${a};`)}),n.join(`
|
|
306
|
-
`)}function
|
|
345
|
+
`,$.textContent="\u2715",$.addEventListener("mouseenter",()=>{$.style.backgroundColor="var(--fb-background-hover-color)"}),$.addEventListener("mouseleave",()=>{$.style.backgroundColor="transparent"}),$.onclick=()=>{v()>h&&(b.remove(),E())},b.style.position="relative",b.appendChild($),c.appendChild(b)}if(u.appendChild(c),!s.config.readonly){const p=document.createElement("div");p.className="flex items-center gap-3 mt-2",p.appendChild(g()),p.appendChild(d),u.appendChild(p)}E(),n.appendChild(u)}let Z=null;function xt(e){Z=e}function Ce(e,t,n){if(!Z)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return Z(e,t,n)}function Ee(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:m}=n,f="minCount"in d&&(c=d.minCount)!=null?c:0,v="maxCount"in d&&(h=d.maxCount)!=null?h:1/0;d.required&&u.length===0&&o.push(`${s}: ${w("required",m)}`),u.length<f&&o.push(`${s}: ${w("minItems",m,{min:f})}`),u.length>v&&o.push(`${s}: ${w("maxItems",m,{max:v})}`)};if("multiple"in e&&e.multiple){const s=[],u=a.querySelectorAll("[data-container-item]"),d=Array.from(u).filter(c=>{const h=c.getAttribute("data-container-item");return h==null?void 0:h.startsWith(`${t}[`)}).length;for(let c=0;c<d;c++){const h={},m=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(f=>{var v;if(f.enableIf)try{const g=(v=n.instance)!=null&&v.getState().formRoot?G(n.instance.getState().formRoot):{};if(!T(f.enableIf,g,h))return}catch(g){console.error(`Error evaluating enableIf for field "${f.key}" in container "${t}[${c}]":`,g)}if(f.hidden||f.type==="hidden")h[f.key]=f.default!==void 0?f.default:null;else{const g=`${t}[${c}].${f.key}`;h[f.key]=Ce({...f,key:g},{path:r},m)}}),s.push(h)}return 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?G(n.instance.getState().formRoot):{};if(!T(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]=Ce({...d,key:h},{path:r},u)}}),{value:s,errors:o}}}function $e(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)=>{z(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(!z(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 Ct(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&&z(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?xe(r,t,n):be(r,t,n,o)}function we(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&z(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function Et(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=we(e);return Ee(o,t,n)}function $t(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=we(e);return $e(a,t,n,o)}function wt(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 kt(e,t){var n,o;if(!e.enableIf)return!1;try{const a=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},l=t.path?I(a,t.path):void 0;return!T(e.enableIf,a,l)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function Lt(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 O(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),m=l.querySelector(`[data-container-item="${c}[${h}]"]`);m&&m.querySelectorAll("input, select, textarea").forEach(f=>{const v=f.getAttribute("name");if(v){const g=v.match(/\.([^.[\]]+)$/);if(g){const E=g[1];f instanceof HTMLSelectElement?u[E]=f.value:f instanceof HTMLInputElement?f.type==="checkbox"?u[E]=f.checked:f.type==="radio"?f.checked&&(u[E]=f.value):u[E]=f.value:f instanceof HTMLTextAreaElement&&(u[E]=f.value)}}})}}else{const d=r.key,c=Lt(d,l);c!==void 0?s[d]=c:s=(a=n.formData)!=null?a:n.prefill}try{T(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 St(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",()=>{O(e,t,n)}),c.addEventListener("input",()=>{O(e,t,n)}),d.disconnect())});d.observe(a,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{O(e,t,n)}),u.addEventListener("input",()=>{O(e,t,n)})}function Ft(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 Nt(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(),wt(n,t)},t}function At(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Ft(e);if(t.appendChild(n),e.description||e.hint){const o=Nt(e);t.appendChild(o)}return t}function Tt(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?ze(e,t,n,o):Be(e,t,n,o);break;case"textarea":a?Re(e,t,n,o):Ie(e,t,n,o);break;case"number":a?Ue(e,t,n,o):Oe(e,t,n,o);break;case"select":a?We(e,t,n,o):_e(e,t,n,o);break;case"file":a?ut(e,t,n,o):st(e,t,n,o);break;case"files":ct(e,t,n,o);break;case"colour":a?pt(e,t,n,o):dt(e,t,n,o);break;case"slider":a?vt(e,t,n,o):ht(e,t,n,o);break;case"group":Ct(e,t,n,o);break;case"container":a?xe(e,t,n):be(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 Q(e,t){const n=kt(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=At(e);o.appendChild(a);const l=A(t.path,e.key);return Tt(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),St(o,e,t),o}bt(Q);const K={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 qt(e){const t={...K.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...K.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...K,...e,translations:t},debounceTimer:null}}function Mt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const B={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 Ht(e){const t={...B,...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(`
|
|
346
|
+
`)}function Bt(e,t){const n=Ht(t);let o=e.querySelector("style[data-fb-theme]");o||(o=document.createElement("style"),o.setAttribute("data-fb-theme","true"),e.appendChild(o)),o.textContent=`
|
|
307
347
|
[data-fb-root="true"] {
|
|
308
348
|
${n}
|
|
309
349
|
}
|
|
310
|
-
`}const
|
|
350
|
+
`}const zt={default:B,dark:{...B,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:{...B,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 ke(e,t=!1){e.style.cssText=`
|
|
311
351
|
background-color: var(--fb-action-bg-color);
|
|
312
352
|
color: var(--fb-action-text-color);
|
|
313
353
|
border: var(--fb-border-width) solid var(--fb-action-border-color);
|
|
@@ -317,6 +357,6 @@ ${n}
|
|
|
317
357
|
border-radius: var(--fb-border-radius);
|
|
318
358
|
transition: all var(--fb-transition-duration);
|
|
319
359
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
320
|
-
`,e.addEventListener("mouseenter",()=>{e.style.backgroundColor="var(--fb-action-hover-bg-color)",e.style.borderColor="var(--fb-action-hover-border-color)"}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor="var(--fb-action-bg-color)",e.style.borderColor="var(--fb-action-border-color)"})}const
|
|
360
|
+
`,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 It={text:{validate:ee,update:te},textarea:{validate:De,update:je},number:{validate:Pe,update:Ve},select:{validate:Je,update:Ye},file:{validate:de,update:pe},files:{validate:de,update:pe},colour:{validate:mt,update:ft},slider:{validate:gt,update:yt},container:{validate:Ee,update:$e},group:{validate:Et,update:$t}};function Le(e){return It[e]||null}function Rt(e,t,n){const o=Le(e.type);return o&&o.validate?o.validate(e,t,n):null}function Dt(e,t,n,o){const a=Le(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class U{constructor(t){this.instanceId=Mt(),this.state=qt(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 i=a.querySelector(".field-placeholder");return i||(i=document.createElement("div"),i.className="field-placeholder",i.style.display="none",a.appendChild(i)),i}}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=`
|
|
321
361
|
border-top: var(--fb-border-width) solid var(--fb-border-color);
|
|
322
|
-
`,t.forEach(
|
|
362
|
+
`,t.forEach(l=>{const r=document.createElement("button");r.type="button",ke(r,!0);const i=n.includes(l),s=this.resolveActionLabel(l.key,l.label,null,i);r.textContent=s,r.addEventListener("click",u=>{u.preventDefault(),u.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 i=this.findFormElementByFieldPath(r);if(!i){console.warn(`External action: Could not find form element for field "${r}", treating as form-level actions`),o.push(...l);return}let s=i.closest(".fb-field-wrapper");if(s||(s=i.parentElement),!s){console.warn(`External action: Could not find wrapper for field "${r}"`);return}const u=s.querySelector(".external-actions-container");u&&u.remove();const d=document.createElement("div");d.className="external-actions-container mt-3 flex flex-wrap gap-2";const c=this.findSchemaElement(r);l.forEach(h=>{const m=document.createElement("button");m.type="button",ke(m,!1);const f=this.resolveActionLabel(h.key,h.label,c);m.textContent=f,m.addEventListener("click",v=>{v.preventDefault(),v.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(h.value,h.key,h.related_field)}),d.appendChild(m)}),s.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 i in r){const s=a?i:`${l}.${i}`,u=r[i];this.updateField(s,u)}}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=P(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,H(t),t.setAttribute("data-fb-root","true"),Bt(t,this.state.config.theme);const r=document.createElement("div");if(r.className="space-y-6",n.prefillHints&&!this.state.config.readonly){const u=this.createRootPrefillHints(n.prefillHints);r.appendChild(u)}const i=document.createElement("div"),s=n.columns||1;s===1?i.className="space-y-4":i.className=`grid grid-cols-${s} gap-4`,n.elements.forEach(u=>{if(u.hidden)return;const d=Q(u,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});i.appendChild(d)}),r.appendChild(i),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,i=null)=>{const s=l.key,u={scopeRoot:i||this.state.formRoot,state:this.state,instance:this,path:r.path,skipValidation:t},d=Rt(l,s,u);return d!==null?(n.push(...d.errors),d.value):(console.warn(`Unknown field type "${l.type}" for key "${s}"`),null)};return xt(a),this.state.schema.elements.forEach(l=>{if(l.enableIf)try{if(!T(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:""};Dt(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,i,s;const u=a?`${a}.${l.key}`:l.key;if(l.enableIf){let d=null;if(a){const c=a.match(/^(.+)\[(\d+)\]$/);if(c){const h=c[1],m=c[2],f=this.state.formRoot.querySelector(`[data-container-item="${h}[${m}]"]`);f&&(d=f.querySelector(`[data-field-key="${l.key}"]`))}else{const h=this.state.formRoot.querySelector(`[data-container="${a}"]`);h&&(d=h.querySelector(`[data-field-key="${l.key}"]`))}}else d=this.state.formRoot.querySelector(`[data-field-key="${l.key}"]`);if(d){const c=d;try{let h;((r=l.enableIf.scope)!=null?r:"relative")==="relative"&&a&&(h=I(t,a));const m=T(l.enableIf,t,h),f=c.getAttribute("data-conditionally-disabled")==="true";if(m&&f){const v=a?I(t,a):t,g=Q(l,{path:a,prefill:v&&typeof v=="object"?v:{},formData:t,state:this.state,instance:this});(i=c.parentNode)==null||i.replaceChild(g,c)}else if(!m&&!f){const v=document.createElement("div");v.className="fb-field-wrapper-disabled",v.style.display="none",v.setAttribute("data-field-key",l.key),v.setAttribute("data-conditionally-disabled","true"),(s=c.parentNode)==null||s.replaceChild(v,c)}}catch(h){console.error(`Error re-evaluating enableIf for field "${l.key}" at path "${u}":`,h)}}}if((l.type==="container"||l.type==="group")&&"elements"in l&&l.elements){const d=t==null?void 0:t[l.key];Array.isArray(d)?d.forEach((c,h)=>{n(l.elements,`${u}[${h}]`)}):n(l.elements,u)}})};n(this.state.schema.elements,"")}destroy(){var t;this.state.debounceTimer!==null&&(clearTimeout(this.state.debounceTimer),this.state.debounceTimer=null),this.state.resourceIndex.clear(),this.state.formRoot&&H(this.state.formRoot),this.state.formRoot=null,this.state.schema=null,this.state.externalActions=null,this.state.config.verboseErrors&&((t=globalThis.__formBuilderInstances)==null||t.delete(this.instanceId))}}function Se(e){return new U(e)}return typeof window!="undefined"&&(window.FormBuilder=U,window.createFormBuilder=Se,window.validateSchema=P),N.FormBuilderInstance=U,N.createFormBuilder=Se,N.default=U,N.defaultTheme=B,N.exampleThemes=zt,N.validateSchema=P,Object.defineProperty(N,"__esModule",{value:!0}),N})({});
|