@dmitryvim/form-builder 0.2.22 → 0.2.23
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 +108 -104
- package/dist/browser/formbuilder.v0.2.23.min.js +606 -0
- package/dist/cjs/index.cjs +438 -40
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +425 -37
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +108 -104
- package/dist/types/components/container.d.ts +4 -1
- package/dist/types/components/file.d.ts +5 -0
- package/dist/types/instance/FormBuilderInstance.d.ts +5 -0
- package/dist/types/types/component-operations.d.ts +2 -0
- package/dist/types/types/config.d.ts +3 -0
- package/dist/types/types/schema.d.ts +1 -0
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.22.min.js +0 -602
package/dist/form-builder.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var FormBuilder=(function(
|
|
1
|
+
var FormBuilder=(function(be){"use strict";function k(e,t,n){const r=t.config.locale||"en",l=t.config.translations[r],a=t.config.translations.en;let o=(l==null?void 0:l[e])||(a==null?void 0:a[e])||e;if(n)for(const[c,i]of Object.entries(n))o=o.replace(new RegExp(`\\{${c}\\}`,"g"),String(i));return o}function cn(e,t,n){(e.minLength!=null||e.maxLength!=null)&&(e.minLength!=null&&e.maxLength!=null?t.push(k("hintLengthRange",n,{min:e.minLength,max:e.maxLength})):e.maxLength!=null?t.push(k("hintMaxLength",n,{max:e.maxLength})):e.minLength!=null&&t.push(k("hintMinLength",n,{min:e.minLength})))}function un(e,t,n){(e.min!=null||e.max!=null)&&(e.min!=null&&e.max!=null?t.push(k("hintValueRange",n,{min:e.min,max:e.max})):e.max!=null?t.push(k("hintMaxValue",n,{max:e.max})):e.min!=null&&t.push(k("hintMinValue",n,{min:e.min})))}function dn(e,t,n){e.maxSizeMB&&t.push(k("hintMaxSize",n,{size:e.maxSizeMB}))}function pn(e,t,n){var r;(r=e.accept)!=null&&r.extensions&&t.push(k("hintFormats",n,{formats:e.accept.extensions.map(l=>l.toUpperCase()).join(",")}))}function fn(e,t,n){e.pattern&&t.push(k("hintPattern",n,{pattern:e.pattern}))}function he(e,t){const n=[];return cn(e,n,t),e.type!=="slider"&&un(e,n,t),dn(e,n,t),pn(e,n,t),fn(e,n,t),n.join(" \u2022 ")}function Qe(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 l=e.columns,a=[1,2,3,4];(!Number.isInteger(l)||!a.includes(l))&&t.push(`schema.columns must be 1, 2, 3, or 4 (got ${l})`)}if("prefillHints"in e&&e.prefillHints){const l=e.prefillHints;Array.isArray(l)&&l.forEach((a,o)=>{if((!a.label||typeof a.label!="string")&&t.push(`schema.prefillHints[${o}] must have a 'label' property of type string`),!a.values||typeof a.values!="object")t.push(`schema.prefillHints[${o}] must have a 'values' property of type object`);else for(const c in a.values)e.elements.some(i=>i.key===c)||t.push(`schema.prefillHints[${o}] references non-existent field "${c}"`)})}function n(l,a){var o,c;const i=new Set;for(const u of l)if(u.type==="richinput"&&u.flatOutput){const f=u,s=(o=f.textKey)!=null?o:"text",m=(c=f.filesKey)!=null?c:"files";for(const p of l)p!==u&&(p.key===s&&t.push(`${a}: RichInput "${u.key}" flatOutput textKey "${s}" collides with element key "${p.key}"`),p.key===m&&t.push(`${a}: RichInput "${u.key}" flatOutput filesKey "${m}" collides with element key "${p.key}"`));i.has(s)&&t.push(`${a}: RichInput "${u.key}" flatOutput textKey "${s}" collides with another flatOutput key`),i.has(m)&&t.push(`${a}: RichInput "${u.key}" flatOutput filesKey "${m}" collides with another flatOutput key`),i.add(s),i.add(m)}else i.has(u.key)&&t.push(`${a}: Element key "${u.key}" collides with a flatOutput richinput key`),i.add(u.key)}function r(l,a){l.forEach((o,c)=>{const i=`${a}[${c}]`;if(o.type||t.push(`${i}: missing type`),o.key||t.push(`${i}: missing key`),o.enableIf){const u=o.enableIf;(!u.key||typeof u.key!="string")&&t.push(`${i}: enableIf must have a 'key' property of type string`),"equals"in u||t.push(`${i}: enableIf must have at least one operator (equals, etc.)`)}if(o.type==="group"&&"elements"in o&&o.elements&&r(o.elements,`${i}.elements`),o.type==="container"&&o.elements){if("columns"in o&&o.columns!==void 0){const u=o.columns,f=[1,2,3,4];(!Number.isInteger(u)||!f.includes(u))&&t.push(`${i}: columns must be 1, 2, 3, or 4 (got ${u})`)}if("prefillHints"in o&&o.prefillHints){const u=o.prefillHints;Array.isArray(u)&&u.forEach((f,s)=>{if((!f.label||typeof f.label!="string")&&t.push(`${i}: prefillHints[${s}] must have a 'label' property of type string`),!f.values||typeof f.values!="object")t.push(`${i}: prefillHints[${s}] must have a 'values' property of type object`);else for(const m in f.values)o.elements.some(p=>p.key===m)||t.push(`container "${o.key}": prefillHints[${s}] references non-existent field "${m}"`)})}r(o.elements,`${i}.elements`),n(o.elements,`${i}.elements`)}if(o.type==="select"&&o.options){const u=o.default;u!=null&&u!==""&&(o.options.some(f=>f.value===u)||t.push(`${i}: default "${u}" not in options`))}})}return Array.isArray(e.elements)&&(r(e.elements,"elements"),n(e.elements,"elements")),t}function Re(e){return e&&typeof e=="object"&&e.constructor===Object}function W(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function we(e,t){return e?`${e}.${t}`:t}function pe(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function mn(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function et(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let r=e;for(const l of n){if(r==null)return;if(l.startsWith("[")&&l.endsWith("]")){const a=parseInt(l.slice(1,-1),10);if(!Array.isArray(r)||isNaN(a))return;r=r[a]}else r=r[l]}return r}function ke(e,t,n){var r;if(!e||!e.key)throw new Error("Invalid enableIf condition: must have a 'key' property");const l=(r=e.scope)!=null?r:"relative";let a;if(l==="relative")a=n!=null?n:t;else if(l==="absolute")a=t;else throw new Error(`Invalid enableIf scope: must be "relative" or "absolute" (got "${l}")`);const o=et(a,e.key);if("equals"in e)return hn(o,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function hn(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 Ne(e,t,n=!1){const r=document.createElement("span");r.className="char-counter",r.style.cssText=`
|
|
2
2
|
position: absolute;
|
|
3
3
|
${n?"bottom: 8px":"top: 50%; transform: translateY(-50%)"};
|
|
4
4
|
right: 10px;
|
|
@@ -7,7 +7,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
7
7
|
pointer-events: none;
|
|
8
8
|
background: var(--fb-background-color);
|
|
9
9
|
padding: 0 4px;
|
|
10
|
-
`;const l=()=>{const a=t.value.length,
|
|
10
|
+
`;const l=()=>{const a=t.value.length,o=e.minLength,c=e.maxLength;if(o==null&&c==null){r.textContent="";return}a===0||o!=null&&a<o?(o!=null&&c!=null?r.textContent=`${o}-${c}`:c!=null?r.textContent=`\u2264${c}`:o!=null&&(r.textContent=`\u2265${o}`),r.style.color="var(--fb-text-secondary-color)"):c!=null&&a>c?(r.textContent=`${a}/${c}`,r.style.color="var(--fb-error-color)"):(c!=null?r.textContent=`${a}/${c}`:r.textContent=`${a}`,r.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",l),l(),r}function vn(e,t,n,r){const l=t.state,a=document.createElement("div");a.style.cssText="position: relative;";const o=document.createElement("input");if(o.type="text",o.className="w-full rounded-lg",o.style.cssText=`
|
|
11
11
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
12
12
|
padding-right: 60px;
|
|
13
13
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
@@ -19,39 +19,39 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
19
19
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
20
20
|
width: 100%;
|
|
21
21
|
box-sizing: border-box;
|
|
22
|
-
`,
|
|
22
|
+
`,o.name=r,o.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",o.value=t.prefill[e.key]||e.default||"",o.readOnly=l.config.readonly,l.config.readonly||(o.addEventListener("focus",()=>{o.style.borderColor="var(--fb-border-focus-color)",o.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",o.style.outlineOffset="0"}),o.addEventListener("blur",()=>{o.style.borderColor="var(--fb-border-color)",o.style.outline="none"}),o.addEventListener("mouseenter",()=>{document.activeElement!==o&&(o.style.borderColor="var(--fb-border-hover-color)")}),o.addEventListener("mouseleave",()=>{document.activeElement!==o&&(o.style.borderColor="var(--fb-border-color)")})),!l.config.readonly&&t.instance){const c=()=>{const i=o.value===""?null:o.value;t.instance.triggerOnChange(r,i)};o.addEventListener("blur",c),o.addEventListener("input",c)}if(a.appendChild(o),!l.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const c=Ne(e,o,!1);a.appendChild(c)}n.appendChild(a)}function gn(e,t,n,r){var l,a;const o=t.state,c=t.prefill[e.key]||[],i=Array.isArray(c)?[...c]:[],u=(l=e.minCount)!=null?l:1,f=(a=e.maxCount)!=null?a:1/0;for(;i.length<u;)i.push(e.default||"");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function m(){s.querySelectorAll(".multiple-text-item").forEach((d,y)=>{const g=d.querySelector("input");g&&(g.name=`${r}[${y}]`)})}function p(d="",y=-1){const g=document.createElement("div");g.className="multiple-text-item flex items-center gap-2";const E=document.createElement("div");E.style.cssText="position: relative; flex: 1;";const C=document.createElement("input");if(C.type="text",C.style.cssText=`
|
|
23
23
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
24
24
|
padding-right: 60px;
|
|
25
25
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
26
26
|
border-radius: var(--fb-border-radius);
|
|
27
|
-
background-color: ${
|
|
27
|
+
background-color: ${o.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
|
|
28
28
|
color: var(--fb-text-color);
|
|
29
29
|
font-size: var(--fb-font-size);
|
|
30
30
|
font-family: var(--fb-font-family);
|
|
31
31
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
32
32
|
width: 100%;
|
|
33
33
|
box-sizing: border-box;
|
|
34
|
-
`,
|
|
34
|
+
`,C.placeholder=e.placeholder||k("placeholderText",o),C.value=d,C.readOnly=o.config.readonly,o.config.readonly||(C.addEventListener("focus",()=>{C.style.borderColor="var(--fb-border-focus-color)",C.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",C.style.outlineOffset="0"}),C.addEventListener("blur",()=>{C.style.borderColor="var(--fb-border-color)",C.style.outline="none"}),C.addEventListener("mouseenter",()=>{document.activeElement!==C&&(C.style.borderColor="var(--fb-border-hover-color)")}),C.addEventListener("mouseleave",()=>{document.activeElement!==C&&(C.style.borderColor="var(--fb-border-color)")})),!o.config.readonly&&t.instance){const w=()=>{const S=C.value===""?null:C.value;t.instance.triggerOnChange(C.name,S)};C.addEventListener("blur",w),C.addEventListener("input",w)}if(E.appendChild(C),!o.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=Ne(e,C,!1);E.appendChild(w)}return g.appendChild(E),y===-1?s.appendChild(g):s.insertBefore(g,s.children[y]),m(),g}function h(){if(o.config.readonly)return;const d=s.querySelectorAll(".multiple-text-item"),y=d.length;d.forEach(g=>{let E=g.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn px-2 py-1 rounded",E.style.cssText=`
|
|
35
35
|
color: var(--fb-error-color);
|
|
36
36
|
background-color: transparent;
|
|
37
37
|
transition: background-color var(--fb-transition-duration);
|
|
38
|
-
`,
|
|
38
|
+
`,E.innerHTML="\u2715",E.addEventListener("mouseenter",()=>{E.style.backgroundColor="var(--fb-background-hover-color)"}),E.addEventListener("mouseleave",()=>{E.style.backgroundColor="transparent"}),E.onclick=()=>{const w=Array.from(s.children).indexOf(g);s.children.length>u&&(i.splice(w,1),g.remove(),m(),x(),h())},g.appendChild(E));const C=y<=u;E.disabled=C,E.style.opacity=C?"0.5":"1",E.style.pointerEvents=C?"none":"auto"})}let v=null,b=null;if(!o.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-text-btn px-3 py-1 rounded",d.style.cssText=`
|
|
39
39
|
color: var(--fb-primary-color);
|
|
40
40
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
41
41
|
background-color: transparent;
|
|
42
42
|
font-size: var(--fb-font-size);
|
|
43
43
|
transition: all var(--fb-transition-duration);
|
|
44
|
-
`,
|
|
44
|
+
`,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{i.push(e.default||""),p(e.default||""),x(),h()},b=document.createElement("span"),b.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(b),n.appendChild(v)}function x(){if(!v||!b)return;const d=v.querySelector(".add-text-btn");if(d){const y=i.length>=f;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}b.textContent=`${i.length}/${f===1/0?"\u221E":f}`}i.forEach(d=>p(d)),x(),h()}function bt(e,t,n){var r,l,a;const o=[],{scopeRoot:c,skipValidation:i}=n,u=(s,m)=>{var p,h;if(!s)return;const v=`error-${s.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(v);m?(s.classList.add("invalid"),s.title=m,b||(b=document.createElement("div"),b.id=v,b.className="error-message",b.style.cssText=`
|
|
45
45
|
color: var(--fb-error-color);
|
|
46
46
|
font-size: var(--fb-font-size-small);
|
|
47
47
|
margin-top: 0.25rem;
|
|
48
|
-
`,
|
|
48
|
+
`,s.nextSibling?(p=s.parentNode)==null||p.insertBefore(b,s.nextSibling):(h=s.parentNode)==null||h.appendChild(b)),b.textContent=m,b.style.display="block"):(s.classList.remove("invalid"),s.title="",b&&b.remove())},f=(s,m,p)=>{let h=!1;const{state:v}=n;if(!i&&m){if(e.minLength!==void 0&&e.minLength!==null&&m.length<e.minLength){const b=k("minLength",v,{min:e.minLength});o.push(`${p}: ${b}`),u(s,b),h=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&m.length>e.maxLength){const b=k("maxLength",v,{max:e.maxLength});o.push(`${p}: ${b}`),u(s,b),h=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(m)){const b=k("patternMismatch",v);o.push(`${p}: ${b}`),u(s,b),h=!0}}catch(b){const x=k("invalidPattern",v);o.push(`${p}: ${x}`),u(s,x),h=!0}}h||u(s,null)};if(e.multiple){const s=c.querySelectorAll(`[name^="${t}["]`),m=[],p=[];if(s.forEach((h,v)=>{var b;const x=(b=h==null?void 0:h.value)!=null?b:"";p.push(x),m.push(x===""?null:x),f(h,x,`${t}[${v}]`)}),!i){const{state:h}=n,v=(r=e.minCount)!=null?r:1,b=(l=e.maxCount)!=null?l:1/0,x=p.filter(d=>d.trim()!=="");e.required&&x.length===0&&o.push(`${t}: ${k("required",h)}`),x.length<v&&o.push(`${t}: ${k("minItems",h,{min:v})}`),x.length>b&&o.push(`${t}: ${k("maxItems",h,{max:b})}`)}return{value:m,errors:o}}else{const s=c.querySelector(`[name$="${t}"]`),m=(a=s==null?void 0:s.value)!=null?a:"";if(!i&&e.required&&m===""){const p=k("required",n.state);return o.push(`${t}: ${p}`),u(s,p),{value:null,errors:o}}return s&&f(s,m,t),{value:m===""?null:m,errors:o}}}function yt(e,t,n,r){const{scopeRoot:l}=r;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateTextField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=l.querySelectorAll(`[name^="${t}["]`);a.forEach((o,c)=>{c<n.length&&(o.value=n[c]!=null?String(n[c]):"",o.classList.remove("invalid"),o.title="")}),n.length!==a.length&&console.warn(`updateTextField: Multiple field "${t}" has ${a.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=l.querySelector(`[name="${t}"]`);a&&(a.value=n!=null?String(n):"",a.classList.remove("invalid"),a.title="")}}function xt(e){e.style.overflow="hidden",e.style.resize="none";const t=(e.value.match(/\n/g)||[]).length+1;e.rows=Math.max(1,t);const n=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`)};e.addEventListener("input",n),setTimeout(()=>{e.isConnected&&n()},0)}function bn(e,t,n,r){const l=t.state,a=document.createElement("div");a.style.cssText="position: relative;";const o=document.createElement("textarea");if(o.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",o.style.cssText="padding-bottom: 24px;",o.name=r,o.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",o.rows=e.rows||4,o.value=t.prefill[e.key]||e.default||"",o.readOnly=l.config.readonly,!l.config.readonly&&t.instance){const c=()=>{const i=o.value===""?null:o.value;t.instance.triggerOnChange(r,i)};o.addEventListener("blur",c),o.addEventListener("input",c)}if((e.autoExpand||l.config.readonly)&&xt(o),a.appendChild(o),!l.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const c=Ne(e,o,!0);a.appendChild(c)}n.appendChild(a)}function yn(e,t,n,r){var l,a;const o=t.state,c=t.prefill[e.key]||[],i=Array.isArray(c)?[...c]:[],u=(l=e.minCount)!=null?l:1,f=(a=e.maxCount)!=null?a:1/0;for(;i.length<u;)i.push(e.default||"");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function m(){s.querySelectorAll(".multiple-textarea-item").forEach((d,y)=>{const g=d.querySelector("textarea");g&&(g.name=`${r}[${y}]`)})}function p(d="",y=-1){const g=document.createElement("div");g.className="multiple-textarea-item";const E=document.createElement("div");E.style.cssText="position: relative;";const C=document.createElement("textarea");if(C.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",C.style.cssText="padding-bottom: 24px;",C.placeholder=e.placeholder||k("placeholderText",o),C.rows=e.rows||4,C.value=d,C.readOnly=o.config.readonly,!o.config.readonly&&t.instance){const w=()=>{const S=C.value===""?null:C.value;t.instance.triggerOnChange(C.name,S)};C.addEventListener("blur",w),C.addEventListener("input",w)}if((e.autoExpand||o.config.readonly)&&xt(C),E.appendChild(C),!o.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=Ne(e,C,!0);E.appendChild(w)}return g.appendChild(E),y===-1?s.appendChild(g):s.insertBefore(g,s.children[y]),m(),g}function h(){if(o.config.readonly)return;const d=s.querySelectorAll(".multiple-textarea-item"),y=d.length;d.forEach(g=>{let E=g.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",E.innerHTML="\u2715",E.onclick=()=>{const w=Array.from(s.children).indexOf(g);s.children.length>u&&(i.splice(w,1),g.remove(),m(),x(),h())},g.appendChild(E));const C=y<=u;E.disabled=C,E.style.opacity=C?"0.5":"1",E.style.pointerEvents=C?"none":"auto"})}let v=null,b=null;if(!o.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-textarea-btn px-3 py-1 rounded",d.style.cssText=`
|
|
49
49
|
color: var(--fb-primary-color);
|
|
50
50
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
51
51
|
background-color: transparent;
|
|
52
52
|
font-size: var(--fb-font-size);
|
|
53
53
|
transition: all var(--fb-transition-duration);
|
|
54
|
-
`,
|
|
54
|
+
`,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{i.push(e.default||""),p(e.default||""),x(),h()},b=document.createElement("span"),b.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(b),n.appendChild(v)}function x(){if(!v||!b)return;const d=v.querySelector(".add-textarea-btn");if(d){const y=i.length>=f;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}b.textContent=`${i.length}/${f===1/0?"\u221E":f}`}i.forEach(d=>p(d)),x(),h()}function xn(e,t,n){return bt(e,t,n)}function En(e,t,n,r){yt(e,t,n,r);const{scopeRoot:l,state:a}=r;if(e.autoExpand||a.config.readonly)if(e.multiple)l.querySelectorAll(`textarea[name^="${t}["]`).forEach(o=>{o.dispatchEvent(new Event("input"))});else{const o=l.querySelector(`textarea[name="${t}"]`);o&&o.dispatchEvent(new Event("input"))}}function Et(e,t){const n=document.createElement("span");n.className="number-range-hint",n.style.cssText=`
|
|
55
55
|
position: absolute;
|
|
56
56
|
top: 50%;
|
|
57
57
|
transform: translateY(-50%);
|
|
@@ -61,57 +61,57 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
61
61
|
pointer-events: none;
|
|
62
62
|
background: var(--fb-background-color);
|
|
63
63
|
padding: 0 4px;
|
|
64
|
-
`;const
|
|
64
|
+
`;const r=e.min,l=e.max;let a="";r!=null&&l!=null?a=`${r} \u2013 ${l}`:l!=null?a=`\u2264${l}`:r!=null&&(a=`\u2265${r}`),n.textContent=a;const o=()=>{const c=t.value?parseFloat(t.value):null;if(c!=null){const i=r!=null&&c<r,u=l!=null&&c>l;n.style.color=i||u?"var(--fb-error-color)":"var(--fb-text-secondary-color)"}else n.style.color="var(--fb-text-secondary-color)"};return t.addEventListener("input",o),o(),n}function Cn(e,t,n,r){const l=t.state,a=document.createElement("div");a.style.cssText="position: relative;";const o=document.createElement("input");if(o.type="number",o.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",o.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",o.name=r,o.placeholder=e.placeholder||"0",e.min!==void 0&&(o.min=e.min.toString()),e.max!==void 0&&(o.max=e.max.toString()),e.step!==void 0&&(o.step=e.step.toString()),o.value=t.prefill[e.key]||e.default||"",o.readOnly=l.config.readonly,!l.config.readonly&&t.instance){const c=()=>{const i=o.value?parseFloat(o.value):null;t.instance.triggerOnChange(r,i)};o.addEventListener("blur",c),o.addEventListener("input",c)}if(a.appendChild(o),!l.config.readonly&&(e.min!=null||e.max!=null)){const c=Et(e,o);a.appendChild(c)}n.appendChild(a)}function wn(e,t,n,r){var l,a;const o=t.state,c=t.prefill[e.key]||[],i=Array.isArray(c)?[...c]:[],u=(l=e.minCount)!=null?l:1,f=(a=e.maxCount)!=null?a:1/0;for(;i.length<u;)i.push(e.default||"");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function m(){s.querySelectorAll(".multiple-number-item").forEach((d,y)=>{const g=d.querySelector("input");g&&(g.name=`${r}[${y}]`)})}function p(d="",y=-1){const g=document.createElement("div");g.className="multiple-number-item flex items-center gap-2";const E=document.createElement("div");E.style.cssText="position: relative; flex: 1;";const C=document.createElement("input");if(C.type="number",C.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",C.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",C.placeholder=e.placeholder||"0",e.min!==void 0&&(C.min=e.min.toString()),e.max!==void 0&&(C.max=e.max.toString()),e.step!==void 0&&(C.step=e.step.toString()),C.value=d.toString(),C.readOnly=o.config.readonly,!o.config.readonly&&t.instance){const w=()=>{const S=C.value?parseFloat(C.value):null;t.instance.triggerOnChange(C.name,S)};C.addEventListener("blur",w),C.addEventListener("input",w)}if(E.appendChild(C),!o.config.readonly&&(e.min!=null||e.max!=null)){const w=Et(e,C);E.appendChild(w)}return g.appendChild(E),y===-1?s.appendChild(g):s.insertBefore(g,s.children[y]),m(),g}function h(){if(o.config.readonly)return;const d=s.querySelectorAll(".multiple-number-item"),y=d.length;d.forEach(g=>{let E=g.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",E.innerHTML="\u2715",E.onclick=()=>{const w=Array.from(s.children).indexOf(g);s.children.length>u&&(i.splice(w,1),g.remove(),m(),x(),h())},g.appendChild(E));const C=y<=u;E.disabled=C,E.style.opacity=C?"0.5":"1",E.style.pointerEvents=C?"none":"auto"})}let v=null,b=null;if(!o.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-number-btn px-3 py-1 rounded",d.style.cssText=`
|
|
65
65
|
color: var(--fb-primary-color);
|
|
66
66
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
67
67
|
background-color: transparent;
|
|
68
68
|
font-size: var(--fb-font-size);
|
|
69
69
|
transition: all var(--fb-transition-duration);
|
|
70
|
-
`,
|
|
70
|
+
`,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{i.push(e.default||""),p(e.default||""),x(),h()},b=document.createElement("span"),b.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(b),n.appendChild(v)}function x(){if(!v||!b)return;const d=v.querySelector(".add-number-btn");if(d){const y=i.length>=f;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}b.textContent=`${i.length}/${f===1/0?"\u221E":f}`}i.forEach(d=>p(d)),x(),h()}function kn(e,t,n){var r,l,a,o,c;const i=[],{scopeRoot:u,skipValidation:f}=n,s=(p,h)=>{var v,b;if(!p)return;const x=`error-${p.getAttribute("name")||Math.random().toString(36).substring(7)}`;let d=document.getElementById(x);h?(p.classList.add("invalid"),p.title=h,d||(d=document.createElement("div"),d.id=x,d.className="error-message",d.style.cssText=`
|
|
71
71
|
color: var(--fb-error-color);
|
|
72
72
|
font-size: var(--fb-font-size-small);
|
|
73
73
|
margin-top: 0.25rem;
|
|
74
|
-
`,
|
|
74
|
+
`,p.nextSibling?(v=p.parentNode)==null||v.insertBefore(d,p.nextSibling):(b=p.parentNode)==null||b.appendChild(d)),d.textContent=h,d.style.display="block"):(p.classList.remove("invalid"),p.title="",d&&d.remove())},m=(p,h,v)=>{let b=!1;const{state:x}=n;if(!f&&e.min!==void 0&&e.min!==null&&h<e.min){const d=k("minValue",x,{min:e.min});i.push(`${v}: ${d}`),s(p,d),b=!0}else if(!f&&e.max!==void 0&&e.max!==null&&h>e.max){const d=k("maxValue",x,{max:e.max});i.push(`${v}: ${d}`),s(p,d),b=!0}b||s(p,null)};if(e.multiple){const p=u.querySelectorAll(`[name^="${t}["]`),h=[];if(p.forEach((v,b)=>{var x,d,y;const g=(x=v==null?void 0:v.value)!=null?x:"";if(g===""){h.push(null),s(v,null);return}const E=parseFloat(g);if(!f&&!Number.isFinite(E)){const w=k("notANumber",n.state);i.push(`${t}[${b}]: ${w}`),s(v,w),h.push(null);return}m(v,E,`${t}[${b}]`);const C=Number.isInteger((d=e.decimals)!=null?d:0)&&(y=e.decimals)!=null?y:0;h.push(Number(E.toFixed(C)))}),!f){const{state:v}=n,b=(r=e.minCount)!=null?r:1,x=(l=e.maxCount)!=null?l:1/0,d=h.filter(y=>y!==null);e.required&&d.length===0&&i.push(`${t}: ${k("required",v)}`),d.length<b&&i.push(`${t}: ${k("minItems",v,{min:b})}`),d.length>x&&i.push(`${t}: ${k("maxItems",v,{max:x})}`)}return{value:h,errors:i}}else{const p=u.querySelector(`[name$="${t}"]`),h=(a=p==null?void 0:p.value)!=null?a:"",{state:v}=n;if(!f&&e.required&&h===""){const d=k("required",v);return i.push(`${t}: ${d}`),s(p,d),{value:null,errors:i}}if(h==="")return s(p,null),{value:null,errors:i};const b=parseFloat(h);if(!f&&!Number.isFinite(b)){const d=k("notANumber",v);return i.push(`${t}: ${d}`),s(p,d),{value:null,errors:i}}m(p,b,t);const x=Number.isInteger((o=e.decimals)!=null?o:0)&&(c=e.decimals)!=null?c:0;return{value:Number(b.toFixed(x)),errors:i}}}function $n(e,t,n,r){const{scopeRoot:l}=r;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateNumberField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=l.querySelectorAll(`[name^="${t}["]`);a.forEach((o,c)=>{c<n.length&&(o.value=n[c]!=null?String(n[c]):"",o.classList.remove("invalid"),o.title="")}),n.length!==a.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${a.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=l.querySelector(`[name="${t}"]`);a&&(a.value=n!=null?String(n):"",a.classList.remove("invalid"),a.title="")}}function Ln(e,t,n,r){const l=t.state,a=document.createElement("select");if(a.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",a.name=r,a.disabled=l.config.readonly,(e.options||[]).forEach(o=>{const c=document.createElement("option");c.value=o.value,c.textContent=o.label,(t.prefill[e.key]||e.default)===o.value&&(c.selected=!0),a.appendChild(c)}),!l.config.readonly&&t.instance){const o=()=>{t.instance.triggerOnChange(r,a.value)};a.addEventListener("change",o)}if(n.appendChild(a),!l.config.readonly){const o=document.createElement("p");o.className="text-xs text-gray-500 mt-1",o.textContent=he(e,l),n.appendChild(o)}}function Sn(e,t,n,r){var l,a,o,c;const i=t.state,u=t.prefill[e.key]||[],f=Array.isArray(u)?[...u]:[],s=(l=e.minCount)!=null?l:1,m=(a=e.maxCount)!=null?a:1/0;for(;f.length<s;)f.push(e.default||((c=(o=e.options)==null?void 0:o[0])==null?void 0:c.value)||"");const p=document.createElement("div");p.className="space-y-2",n.appendChild(p);function h(){p.querySelectorAll(".multiple-select-item").forEach((g,E)=>{const C=g.querySelector("select");C&&(C.name=`${r}[${E}]`)})}function v(g="",E=-1){const C=document.createElement("div");C.className="multiple-select-item flex items-center gap-2";const w=document.createElement("select");if(w.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",w.disabled=i.config.readonly,(e.options||[]).forEach(S=>{const z=document.createElement("option");z.value=S.value,z.textContent=S.label,g===S.value&&(z.selected=!0),w.appendChild(z)}),!i.config.readonly&&t.instance){const S=()=>{t.instance.triggerOnChange(w.name,w.value)};w.addEventListener("change",S)}return C.appendChild(w),E===-1?p.appendChild(C):p.insertBefore(C,p.children[E]),h(),C}function b(){if(i.config.readonly)return;const g=p.querySelectorAll(".multiple-select-item"),E=g.length;g.forEach(C=>{let w=C.querySelector(".remove-item-btn");w||(w=document.createElement("button"),w.type="button",w.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",w.innerHTML="\u2715",w.onclick=()=>{const z=Array.from(p.children).indexOf(C);p.children.length>s&&(f.splice(z,1),C.remove(),h(),y(),b())},C.appendChild(w));const S=E<=s;w.disabled=S,w.style.opacity=S?"0.5":"1",w.style.pointerEvents=S?"none":"auto"})}let x=null,d=null;if(!i.config.readonly){x=document.createElement("div"),x.className="flex items-center gap-3 mt-2";const g=document.createElement("button");g.type="button",g.className="add-select-btn px-3 py-1 rounded",g.style.cssText=`
|
|
75
75
|
color: var(--fb-primary-color);
|
|
76
76
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
77
77
|
background-color: transparent;
|
|
78
78
|
font-size: var(--fb-font-size);
|
|
79
79
|
transition: all var(--fb-transition-duration);
|
|
80
|
-
`,g.textContent="+",g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{var
|
|
80
|
+
`,g.textContent="+",g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{var E,C;const w=e.default||((C=(E=e.options)==null?void 0:E[0])==null?void 0:C.value)||"";f.push(w),v(w),y(),b()},d=document.createElement("span"),d.className="text-sm text-gray-500",x.appendChild(g),x.appendChild(d),n.appendChild(x)}function y(){if(!x||!d)return;const g=x.querySelector(".add-select-btn");if(g){const E=f.length>=m;g.disabled=E,g.style.opacity=E?"0.5":"1",g.style.pointerEvents=E?"none":"auto"}d.textContent=`${f.length}/${m===1/0?"\u221E":m}`}if(f.forEach(g=>v(g)),y(),b(),!i.config.readonly){const g=document.createElement("p");g.className="text-xs text-gray-500 mt-1",g.textContent=he(e,i),n.appendChild(g)}}function Tn(e,t,n){var r;const l=[],{scopeRoot:a,skipValidation:o}=n,c=(u,f)=>{var s,m;if(!u)return;const p=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let h=document.getElementById(p);f?(u.classList.add("invalid"),u.title=f,h||(h=document.createElement("div"),h.id=p,h.className="error-message",h.style.cssText=`
|
|
81
81
|
color: var(--fb-error-color);
|
|
82
82
|
font-size: var(--fb-font-size-small);
|
|
83
83
|
margin-top: 0.25rem;
|
|
84
|
-
`,
|
|
84
|
+
`,u.nextSibling?(s=u.parentNode)==null||s.insertBefore(h,u.nextSibling):(m=u.parentNode)==null||m.appendChild(h)),h.textContent=f,h.style.display="block"):(u.classList.remove("invalid"),u.title="",h&&h.remove())},i=(u,f,s,m)=>{var p,h;if(o)return;const{state:v}=n,b=f.filter(m),x="minCount"in s&&(p=s.minCount)!=null?p:1,d="maxCount"in s&&(h=s.maxCount)!=null?h:1/0;s.required&&b.length===0&&l.push(`${u}: ${k("required",v)}`),b.length<x&&l.push(`${u}: ${k("minItems",v,{min:x})}`),b.length>d&&l.push(`${u}: ${k("maxItems",v,{max:d})}`)};if("multiple"in e&&e.multiple){const u=a.querySelectorAll(`[name^="${t}["]`),f=[];return u.forEach(s=>{var m;const p=(m=s==null?void 0:s.value)!=null?m:"";f.push(p),c(s,null)}),i(t,f,e,s=>s!==""),{value:f,errors:l}}else{const u=a.querySelector(`[name$="${t}"]`),f=(r=u==null?void 0:u.value)!=null?r:"";if(!o&&e.required&&f===""){const s=k("required",n.state);return l.push(`${t}: ${s}`),c(u,s),{value:null,errors:l}}else c(u,null);return{value:f===""?null:f,errors:l}}}function An(e,t,n,r){const{scopeRoot:l}=r;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSelectField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=l.querySelectorAll(`[name^="${t}["]`);a.forEach((o,c)=>{c<n.length&&(o.value=n[c]!=null?String(n[c]):"",o.querySelectorAll("option").forEach(i=>{i.selected=i.value===String(n[c])}),o.classList.remove("invalid"),o.title="")}),n.length!==a.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${a.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=l.querySelector(`[name="${t}"]`);a&&(a.value=n!=null?String(n):"",a.querySelectorAll("option").forEach(o=>{o.selected=o.value===String(n)}),a.classList.remove("invalid"),a.title="")}}function De(e){e.style.backgroundColor="var(--fb-primary-color)",e.style.color="#ffffff",e.style.borderColor="var(--fb-primary-color)"}function je(e){e.style.backgroundColor="transparent",e.style.color="var(--fb-text-color)",e.style.borderColor="var(--fb-border-color)"}function Ct(e,t,n,r,l){const a=e.options||[],o=document.createElement("div");o.className="fb-switcher-group",o.style.cssText=`
|
|
85
85
|
display: inline-flex;
|
|
86
86
|
flex-direction: row;
|
|
87
87
|
flex-wrap: nowrap;
|
|
88
|
-
`;const
|
|
88
|
+
`;const c=[];return a.forEach((i,u)=>{const f=document.createElement("button");f.type="button",f.className="fb-switcher-btn",f.dataset.value=i.value,f.textContent=i.label,f.style.cssText=`
|
|
89
89
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
90
90
|
font-size: var(--fb-font-size);
|
|
91
91
|
border-width: var(--fb-border-width);
|
|
92
92
|
border-style: solid;
|
|
93
|
-
cursor: ${
|
|
93
|
+
cursor: ${r?"default":"pointer"};
|
|
94
94
|
transition: background-color var(--fb-transition-duration), color var(--fb-transition-duration), border-color var(--fb-transition-duration);
|
|
95
95
|
white-space: nowrap;
|
|
96
96
|
line-height: 1.25;
|
|
97
97
|
outline: none;
|
|
98
|
-
`,a.length===1?
|
|
98
|
+
`,a.length===1?f.style.borderRadius="var(--fb-border-radius)":u===0?(f.style.borderRadius="var(--fb-border-radius) 0 0 var(--fb-border-radius)",f.style.borderRightWidth="0"):u===a.length-1?f.style.borderRadius="0 var(--fb-border-radius) var(--fb-border-radius) 0":(f.style.borderRadius="0",f.style.borderRightWidth="0"),i.value===t?De(f):je(f),r||(f.addEventListener("click",()=>{n.value=i.value,c.forEach(s=>{s.dataset.value===i.value?De(s):je(s)}),l&&l(i.value)}),f.addEventListener("mouseenter",()=>{n.value!==i.value&&(f.style.backgroundColor="var(--fb-background-hover-color)")}),f.addEventListener("mouseleave",()=>{n.value!==i.value&&(f.style.backgroundColor="transparent")})),c.push(f),o.appendChild(f)}),o}function Fn(e,t,n,r){var l,a;const o=t.state,c=String((a=(l=t.prefill[e.key])!=null?l:e.default)!=null?a:""),i=document.createElement("input");i.type="hidden",i.name=r,i.value=c;const u=o.config.readonly,f=!u&&t.instance?m=>{t.instance.triggerOnChange(r,m)}:null,s=Ct(e,c,i,u,f);if(n.appendChild(i),n.appendChild(s),!u){const m=document.createElement("p");m.className="text-xs text-gray-500 mt-1",m.textContent=he(e,o),n.appendChild(m)}}function Nn(e,t,n,r){var l,a,o,c;const i=t.state,u=t.prefill[e.key]||[],f=Array.isArray(u)?[...u]:[],s=(l=e.minCount)!=null?l:1,m=(a=e.maxCount)!=null?a:1/0;for(;f.length<s;)f.push(e.default||((c=(o=e.options)==null?void 0:o[0])==null?void 0:c.value)||"");const p=i.config.readonly,h=document.createElement("div");h.className="space-y-2",n.appendChild(h);function v(){h.querySelectorAll(".multiple-switcher-item").forEach((E,C)=>{const w=E.querySelector("input[type=hidden]");w&&(w.name=`${r}[${C}]`)})}function b(E="",C=-1){const w=C===-1?h.children.length:C,S=`${r}[${w}]`,z=document.createElement("div");z.className="multiple-switcher-item flex items-center gap-2";const ne=document.createElement("input");ne.type="hidden",ne.name=S,ne.value=E,z.appendChild(ne);const P=!p&&t.instance?ve=>{t.instance.triggerOnChange(ne.name,ve)}:null,G=Ct(e,E,ne,p,P);return z.appendChild(G),C===-1?h.appendChild(z):h.insertBefore(z,h.children[C]),v(),z}function x(){if(p)return;const E=h.querySelectorAll(".multiple-switcher-item"),C=E.length;E.forEach(w=>{let S=w.querySelector(".remove-item-btn");S||(S=document.createElement("button"),S.type="button",S.className="remove-item-btn px-2 py-1 rounded",S.style.cssText=`
|
|
99
99
|
color: var(--fb-error-color);
|
|
100
100
|
background-color: transparent;
|
|
101
101
|
transition: background-color var(--fb-transition-duration);
|
|
102
|
-
|
|
102
|
+
`,S.innerHTML="\u2715",S.addEventListener("mouseenter",()=>{S.style.backgroundColor="var(--fb-background-hover-color)"}),S.addEventListener("mouseleave",()=>{S.style.backgroundColor="transparent"}),S.onclick=()=>{const ne=Array.from(h.children).indexOf(w);h.children.length>s&&(f.splice(ne,1),w.remove(),v(),g(),x())},w.appendChild(S));const z=C<=s;S.disabled=z,S.style.opacity=z?"0.5":"1",S.style.pointerEvents=z?"none":"auto"})}let d=null,y=null;if(!p){d=document.createElement("div"),d.className="flex items-center gap-3 mt-2";const E=document.createElement("button");E.type="button",E.className="add-switcher-btn px-3 py-1 rounded",E.style.cssText=`
|
|
103
103
|
color: var(--fb-primary-color);
|
|
104
104
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
105
105
|
background-color: transparent;
|
|
106
106
|
font-size: var(--fb-font-size);
|
|
107
107
|
transition: all var(--fb-transition-duration);
|
|
108
|
-
`,
|
|
108
|
+
`,E.textContent="+",E.addEventListener("mouseenter",()=>{E.style.backgroundColor="var(--fb-background-hover-color)"}),E.addEventListener("mouseleave",()=>{E.style.backgroundColor="transparent"}),E.onclick=()=>{var C,w;const S=e.default||((w=(C=e.options)==null?void 0:C[0])==null?void 0:w.value)||"";f.push(S),b(S),g(),x()},y=document.createElement("span"),y.className="text-sm text-gray-500",d.appendChild(E),d.appendChild(y),n.appendChild(d)}function g(){if(!d||!y)return;const E=d.querySelector(".add-switcher-btn");if(E){const C=f.length>=m;E.disabled=C,E.style.opacity=C?"0.5":"1",E.style.pointerEvents=C?"none":"auto"}y.textContent=`${f.length}/${m===1/0?"\u221E":m}`}if(f.forEach(E=>b(E)),g(),x(),!p){const E=document.createElement("p");E.className="text-xs text-gray-500 mt-1",E.textContent=he(e,i),n.appendChild(E)}}function Mn(e,t,n){var r;const l=[],{scopeRoot:a,skipValidation:o}=n,c=(f,s)=>{var m,p;if(!f)return;const h=`error-${f.getAttribute("name")||Math.random().toString(36).substring(7)}`;let v=document.getElementById(h);s?(f.classList.add("invalid"),f.title=s,v||(v=document.createElement("div"),v.id=h,v.className="error-message",v.style.cssText=`
|
|
109
109
|
color: var(--fb-error-color);
|
|
110
110
|
font-size: var(--fb-font-size-small);
|
|
111
111
|
margin-top: 0.25rem;
|
|
112
|
-
`,
|
|
112
|
+
`,f.nextSibling?(m=f.parentNode)==null||m.insertBefore(v,f.nextSibling):(p=f.parentNode)==null||p.appendChild(v)),v.textContent=s,v.style.display="block"):(f.classList.remove("invalid"),f.title="",v&&v.remove())},i=(f,s,m,p)=>{var h,v;if(o)return;const{state:b}=n,x=s.filter(p),d="minCount"in m&&(h=m.minCount)!=null?h:1,y="maxCount"in m&&(v=m.maxCount)!=null?v:1/0;m.required&&x.length===0&&l.push(`${f}: ${k("required",b)}`),x.length<d&&l.push(`${f}: ${k("minItems",b,{min:d})}`),x.length>y&&l.push(`${f}: ${k("maxItems",b,{max:y})}`)},u=new Set("options"in e?e.options.map(f=>f.value):[]);if("multiple"in e&&e.multiple){const f=a.querySelectorAll(`input[type="hidden"][name^="${t}["]`),s=[];return f.forEach(m=>{var p;const h=(p=m==null?void 0:m.value)!=null?p:"";if(s.push(h),!o&&h!==""&&!u.has(h)){const v=k("invalidOption",n.state);c(m,v),l.push(`${t}: ${v}`)}else c(m,null)}),i(t,s,e,m=>m!==""),{value:s,errors:l}}else{const f=a.querySelector(`input[type="hidden"][name$="${t}"]`),s=(r=f==null?void 0:f.value)!=null?r:"";if(!o&&e.required&&s===""){const m=k("required",n.state);return l.push(`${t}: ${m}`),c(f,m),{value:null,errors:l}}if(!o&&s!==""&&!u.has(s)){const m=k("invalidOption",n.state);return l.push(`${t}: ${m}`),c(f,m),{value:null,errors:l}}return c(f,null),{value:s===""?null:s,errors:l}}}function qn(e,t,n,r){var l;const{scopeRoot:a}=r;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSwitcherField: Expected array for multiple field "${t}", got ${typeof n}`);return}const o=a.querySelectorAll(`input[type="hidden"][name^="${t}["]`);o.forEach((c,i)=>{var u;if(i<n.length){const f=n[i]!=null?String(n[i]):"";c.value=f;const s=(u=c.parentElement)==null?void 0:u.querySelector(".fb-switcher-group");s&&s.querySelectorAll(".fb-switcher-btn").forEach(m=>{m.dataset.value===f?De(m):je(m)}),c.classList.remove("invalid"),c.title=""}}),n.length!==o.length&&console.warn(`updateSwitcherField: Multiple field "${t}" has ${o.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const o=a.querySelector(`input[type="hidden"][name="${t}"]`);if(o){const c=n!=null?String(n):"";o.value=c;const i=(l=o.parentElement)==null?void 0:l.querySelector(".fb-switcher-group");i&&i.querySelectorAll(".fb-switcher-btn").forEach(u=>{u.dataset.value===c?De(u):je(u)}),o.classList.remove("invalid"),o.title=""}}}function Me(e){return e?typeof e=="object"&&Array.isArray(e.extensions)?e.extensions.map(t=>t.toLowerCase()):typeof e=="string"?e.split(",").map(t=>t.trim()).filter(t=>t.startsWith(".")).map(t=>t.substring(1).toLowerCase()):[]:[]}function Ee(e,t){var n;if(t.length===0)return!0;const r=((n=e.split(".").pop())==null?void 0:n.toLowerCase())||"";return t.includes(r)}function $e(e,t){return t===1/0?!0:e.size<=t*1024*1024}function zn(e,t,n,r){const l=document.createElement("img");l.className="w-full h-full object-contain",l.alt=n||k("previewAlt",r);const a=new FileReader;a.onload=o=>{var c;l.src=((c=o.target)==null?void 0:c.result)||""},a.readAsDataURL(t),e.appendChild(l)}function Hn(e,t,n,r,l,a){const o=URL.createObjectURL(t);e.onclick=null;const c=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(c,e),c.innerHTML=`
|
|
113
113
|
<div class="relative group h-full">
|
|
114
|
-
<video class="w-full h-full object-contain" controls preload="auto" muted src="${
|
|
114
|
+
<video class="w-full h-full object-contain" controls preload="auto" muted src="${o}">
|
|
115
115
|
${W(k("videoNotSupported",l))}
|
|
116
116
|
</video>
|
|
117
117
|
<div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
|
|
@@ -123,28 +123,28 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
123
123
|
</button>
|
|
124
124
|
</div>
|
|
125
125
|
</div>
|
|
126
|
-
`,
|
|
126
|
+
`,In(c,r,l,a),c}function In(e,t,n,r){const l=e.querySelector(".change-file-btn");l&&(l.onclick=o=>{o.stopPropagation(),r!=null&&r.picker&&r.picker.click()});const a=e.querySelector(".delete-file-btn");a&&(a.onclick=o=>{o.stopPropagation(),Bn(e,t,n,r)})}function Bn(e,t,n,r){var l;n.resourceIndex.delete(t);const a=(l=e.parentElement)==null?void 0:l.querySelector('input[type="hidden"]');a&&(a.value=""),r!=null&&r.fileUploadHandler&&(e.onclick=r.fileUploadHandler),r!=null&&r.dragHandler&&rt(e,r.dragHandler),e.innerHTML=`
|
|
127
127
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
128
128
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
129
129
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
130
130
|
</svg>
|
|
131
131
|
<div class="text-sm text-center">${W(k("clickDragText",n))}</div>
|
|
132
132
|
</div>
|
|
133
|
-
`}function
|
|
133
|
+
`}function Rn(e,t,n,r){const l=document.createElement("video");l.className="w-full h-full object-contain",l.controls=!0,l.preload="metadata",l.muted=!0,l.src=t,l.appendChild(document.createTextNode(k("videoNotSupported",r))),e.appendChild(l)}function Dn(e,t,n){Pn(e,n,()=>{var r;n.resourceIndex.delete(t);const l=(r=e.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');l&&(l.value=""),e.innerHTML=`
|
|
134
134
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
135
135
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
136
136
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
137
137
|
</svg>
|
|
138
138
|
<div class="text-sm text-center">${W(k("clickDragText",n))}</div>
|
|
139
139
|
</div>
|
|
140
|
-
`})}async function
|
|
140
|
+
`})}async function jn(e,t,n,r,l,a,o){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?zn(e,t.file,n,a):t.type&&t.type.startsWith("video/")?e=Hn(e,t.file,t.type,r,a,o):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">${W(n)}</div></div>`,!l&&!(t.type&&t.type.startsWith("video/"))&&Dn(e,r,a))}async function On(e,t,n,r,l){if(!l.config.getThumbnail){nt(e,l);return}try{const a=await l.config.getThumbnail(t);if(a)if(pe(e),r&&r.type&&r.type.startsWith("video/"))Rn(e,a,r.type,l);else{const o=document.createElement("img");o.className="w-full h-full object-contain",o.alt=n||k("previewAlt",l),o.src=a,e.appendChild(o)}else nt(e,l)}catch(a){console.error("Failed to get thumbnail:",a),e.innerHTML=`
|
|
141
141
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
142
142
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
143
143
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
144
144
|
</svg>
|
|
145
145
|
<div class="text-sm text-center">${W(n||k("previewUnavailable",l))}</div>
|
|
146
146
|
</div>
|
|
147
|
-
`}}async function
|
|
147
|
+
`}}async function wt(e,t,n,r={}){const{fileName:l="",isReadonly:a=!1,deps:o=null}=r;if(!a&&o&&(!o.picker||!o.fileUploadHandler||!o.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");pe(e),a&&e.classList.add("cursor-pointer");const c=n.resourceIndex.get(t);c&&c.file&&c.file instanceof File?await jn(e,c,l,t,a,n,o):await On(e,t,l,c,n)}async function tt(e,t,n){var r,l;const a=t.resourceIndex.get(e),o=(a==null?void 0:a.name)||e.split("/").pop()||"file",c=o.toLowerCase().match(/\.psd$/),i=document.createElement("div");i.className=c?"space-y-2":"space-y-3";const u=document.createElement("div");c?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 f=!c&&(((r=a==null?void 0:a.type)==null?void 0:r.startsWith("image/"))||o.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),s=((l=a==null?void 0:a.type)==null?void 0:l.startsWith("video/"))||o.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(f)if(t.config.getThumbnail)try{const h=await t.config.getThumbnail(e);h?u.innerHTML=`<img src="${h}" alt="${W(o)}" 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">${W(o)}</div></div></div>`}catch(h){console.warn("getThumbnail failed for",e,h),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">${W(o)}</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">${W(o)}</div></div></div>`;else if(s)if(t.config.getThumbnail)try{const h=await t.config.getThumbnail(e);h?u.innerHTML=`
|
|
148
148
|
<div class="relative group">
|
|
149
149
|
<video class="w-full h-auto" controls preload="auto" muted src="${h}">
|
|
150
150
|
${W(k("videoNotSupported",t))}
|
|
@@ -157,33 +157,33 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
157
157
|
</div>
|
|
158
158
|
</div>
|
|
159
159
|
</div>
|
|
160
|
-
`:
|
|
160
|
+
`: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">${W(o)}</div></div></div>`}catch(h){console.warn("getThumbnail failed for video",e,h),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">${W(o)}</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">${W(o)}</div></div></div>`;else{const h=c?"\u{1F3A8}":"\u{1F4C1}",v=c?"PSD File":"Document";c?u.innerHTML=`
|
|
161
161
|
<div class="flex items-center space-x-3">
|
|
162
162
|
<div class="text-3xl text-gray-400">${h}</div>
|
|
163
163
|
<div class="flex-1 min-w-0">
|
|
164
|
-
<div class="text-sm font-medium text-gray-900 truncate">${W(
|
|
164
|
+
<div class="text-sm font-medium text-gray-900 truncate">${W(o)}</div>
|
|
165
165
|
<div class="text-xs text-gray-500">${v}</div>
|
|
166
166
|
</div>
|
|
167
167
|
</div>
|
|
168
|
-
`:
|
|
168
|
+
`:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${h}</div><div class="text-sm">${W(o)}</div><div class="text-xs text-gray-500 mt-1">${v}</div></div></div>`}const m=document.createElement("p");m.className=c?"hidden":"text-sm font-medium text-gray-900 text-center",m.textContent=o;const p=document.createElement("button");return p.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",p.textContent=k("downloadButton",t),p.onclick=h=>{h.preventDefault(),h.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,o):Vn(e,o,t)},i.appendChild(u),i.appendChild(m),i.appendChild(p),i}function kt(e,t,n,r,l,a){pe(e);const o=()=>{const m=[k("clickDragTextMultiple",n)];return l&&m.push(l),a&&m.push(a),m.join(" \u2022 ")},c=!e.classList.contains("grid");if((!t||t.length===0)&&c){const m=document.createElement("div");m.className="grid grid-cols-4 gap-3 mb-3";for(let h=0;h<4;h++){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 b=document.createElementNS("http://www.w3.org/2000/svg","svg");b.setAttribute("class","w-12 h-12 text-gray-400"),b.setAttribute("fill","currentColor"),b.setAttribute("viewBox","0 0 24 24");const x=document.createElementNS("http://www.w3.org/2000/svg","path");x.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"),b.appendChild(x),v.appendChild(b),v.onclick=()=>{let d=e.parentElement;for(;d&&!d.classList.contains("space-y-2");)d=d.parentElement;!d&&e.classList.contains("space-y-2")&&(d=e);const y=d==null?void 0:d.querySelector('input[type="file"]');y&&y.click()},m.appendChild(v)}const p=document.createElement("div");p.className="text-center text-xs text-gray-500 mt-2",p.textContent=o(),e.appendChild(m),e.appendChild(p);return}const i=document.createElement("div");i.className="files-list grid grid-cols-4 gap-3";const u=t?t.length:0,f=(Math.floor(u/4)+1)*4;for(let m=0;m<f;m++){const p=document.createElement("div");if(t&&m<t.length){const h=t[m],v=n.resourceIndex.get(h);if(p.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",p.dataset.resourceId=h,Un(p,h,v,n).catch(b=>{console.error("Failed to render thumbnail:",b),p.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
169
169
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
170
170
|
<div class="text-xs">${W(k("previewError",n))}</div>
|
|
171
|
-
</div>`}),
|
|
171
|
+
</div>`}),r){const b=document.createElement("div");b.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const x=document.createElement("button");x.className="bg-red-600 text-white px-2 py-1 rounded text-xs",x.textContent=k("removeElement",n),x.onclick=d=>{d.stopPropagation(),r(h)},b.appendChild(x),p.appendChild(b)}}else p.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",p.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>',p.onclick=()=>{let h=e.parentElement;for(;h&&!h.classList.contains("space-y-2");)h=h.parentElement;!h&&e.classList.contains("space-y-2")&&(h=e);const v=h==null?void 0:h.querySelector('input[type="file"]');v&&v.click()};i.appendChild(p)}e.appendChild(i);const s=document.createElement("div");s.className="text-center text-xs text-gray-500 mt-2",s.textContent=o(),e.appendChild(s)}function $t(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
172
172
|
<svg class="${W(n)} text-red-400" fill="currentColor" viewBox="0 0 24 24">
|
|
173
173
|
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
|
|
174
174
|
</svg>
|
|
175
175
|
<div class="text-xs mt-1 text-red-600">${W(k("previewError",t))}</div>
|
|
176
|
-
</div>`}async function
|
|
176
|
+
</div>`}async function Un(e,t,n,r){var l,a;if(n&&(l=n.type)!=null&&l.startsWith("image/"))if(n.file&&n.file instanceof File){const o=document.createElement("img");o.className="w-full h-full object-contain",o.alt=n.name;const c=new FileReader;c.onload=i=>{var u;o.src=((u=i.target)==null?void 0:u.result)||""},c.readAsDataURL(n.file),e.appendChild(o)}else if(r.config.getThumbnail)try{const o=await r.config.getThumbnail(t);if(o){const c=document.createElement("img");c.className="w-full h-full object-contain",c.alt=n.name,c.src=o,e.appendChild(c)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
177
177
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
178
178
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
179
179
|
</svg>
|
|
180
|
-
</div>`}catch(
|
|
180
|
+
</div>`}catch(o){const c=o instanceof Error?o:new Error(String(o));r.config.onThumbnailError&&r.config.onThumbnailError(c,t),$t(e,r)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
181
181
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
182
182
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
183
183
|
</svg>
|
|
184
|
-
</div>`;else if(n&&(a=n.type)!=null&&a.startsWith("video/"))if(n.file&&n.file instanceof File){const
|
|
184
|
+
</div>`;else if(n&&(a=n.type)!=null&&a.startsWith("video/"))if(n.file&&n.file instanceof File){const o=URL.createObjectURL(n.file);e.innerHTML=`
|
|
185
185
|
<div class="relative group h-full w-full">
|
|
186
|
-
<video class="w-full h-full object-contain" preload="metadata" muted src="${
|
|
186
|
+
<video class="w-full h-full object-contain" preload="metadata" muted src="${o}">
|
|
187
187
|
</video>
|
|
188
188
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
189
189
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -193,9 +193,9 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
193
193
|
</div>
|
|
194
194
|
</div>
|
|
195
195
|
</div>
|
|
196
|
-
`}else if(
|
|
196
|
+
`}else if(r.config.getThumbnail)try{const o=await r.config.getThumbnail(t);o?e.innerHTML=`
|
|
197
197
|
<div class="relative group h-full w-full">
|
|
198
|
-
<video class="w-full h-full object-contain" preload="metadata" muted src="${
|
|
198
|
+
<video class="w-full h-full object-contain" preload="metadata" muted src="${o}">
|
|
199
199
|
</video>
|
|
200
200
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
201
201
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -210,7 +210,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
210
210
|
<path d="M8 5v14l11-7z"/>
|
|
211
211
|
</svg>
|
|
212
212
|
<div class="text-xs mt-1">${W((n==null?void 0:n.name)||"Video")}</div>
|
|
213
|
-
</div>`}catch(
|
|
213
|
+
</div>`}catch(o){const c=o instanceof Error?o:new Error(String(o));r.config.onThumbnailError&&r.config.onThumbnailError(c,t),$t(e,r,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
214
214
|
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
215
215
|
<path d="M8 5v14l11-7z"/>
|
|
216
216
|
</svg>
|
|
@@ -218,15 +218,19 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
218
218
|
</div>`;else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
219
219
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
220
220
|
<div class="text-xs">${W((n==null?void 0:n.name)||"File")}</div>
|
|
221
|
-
</div>`}function
|
|
221
|
+
</div>`}function nt(e,t,n){const r=n?`<div class="text-xs text-gray-500 mt-1">${W(n)}</div>`:"";e.innerHTML=`
|
|
222
222
|
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
223
223
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
224
224
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
225
225
|
</svg>
|
|
226
226
|
<div class="text-sm text-center">${W(k("clickDragText",t))}</div>
|
|
227
|
-
${
|
|
227
|
+
${r}
|
|
228
228
|
</div>
|
|
229
|
-
`}async function Et(e,t,n,o,l=null,a){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(p){const c=p instanceof Error?p:new Error(String(p));throw o.config.onUploadError&&o.config.onUploadError(c,e),new Error(`File upload failed: ${c.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(s,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let d=(r=t.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');d||(d=document.createElement("input"),d.type="hidden",d.name=n,(i=t.parentElement)==null||i.appendChild(d)),d.value=s,bt(t,s,o,{fileName:e.name,isReadonly:!1,deps:l}).catch(console.error),a&&!o.config.readonly&&a.triggerOnChange(n,s)}function Qe(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 Bn(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const l=document.createElement("div");l.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 a=document.createElement("button");a.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",a.textContent=k("removeElement",t),a.onclick=r=>{r.stopPropagation(),n()},l.appendChild(a),e.appendChild(l)}async function Ct(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 Dn(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 l=o.startsWith("http")?o:new URL(o,window.location.href).href,a=await fetch(l);if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const r=await a.blob();jn(r,t)}else throw new Error("No download URL available for resource")}catch(o){const l=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(l,e,t),console.error(`File download failed for ${t}:`,l),l}}function jn(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 wt(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const l=n.split("/").pop()||"file",a=(o=l.split(".").pop())==null?void 0:o.toLowerCase();let r="application/octet-stream";a&&(["jpg","jpeg","png","gif","webp"].includes(a)?r=`image/${a==="jpg"?"jpeg":a}`:["mp4","webm","mov","avi"].includes(a)&&(r=`video/${a==="mov"?"quicktime":a}`)),t.resourceIndex.set(n,{name:l,type:r,size:0,uploadedAt:new Date,file:void 0})}})}function On(e,t,n,o,l,a){var r;if(!l.resourceIndex.has(e)){const s=e.split("/").pop()||"file",d=(r=s.split(".").pop())==null?void 0:r.toLowerCase();let p="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?p=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(p=`video/${d==="mov"?"quicktime":d}`)),l.resourceIndex.set(e,{name:s,type:p,size:0,uploadedAt:new Date,file:void 0})}bt(t,e,l,{fileName:e,isReadonly:!1,deps:a}).catch(console.error);const i=document.createElement("input");i.type="hidden",i.name=n,i.value=e,o.appendChild(i)}function kt(e,t,n,o,l,a){Qe(e,async r=>{const i=Array.from(r);for(const s of i){const d=await Ct(s,n);n.resourceIndex.set(d,{name:s.name,type:s.type,size:s.size,uploadedAt:new Date,file:void 0}),t.push(d)}o(),a&&l&&!n.config.readonly&&a.triggerOnChange(l,t)})}function $t(e,t,n,o,l,a){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const i=await Ct(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="",a&&l&&!n.config.readonly&&a.triggerOnChange(l,t)}}function Un(e,t,n,o){var l;const a=t.state;if(a.config.readonly){const r=t.prefill[e.key];if(r)Ge(r,a).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">${W(k("previewUnavailable",a))}</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">${W(k("noFileSelected",a))}</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:((l=e.accept.extensions)==null?void 0:l.map(m=>`.${m}`).join(","))||"");const s=document.createElement("div");s.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const d=t.prefill[e.key],p=()=>i.click(),c=m=>{if(m.length>0){const f={picker:i,fileUploadHandler:p,dragHandler:c};Et(m[0],s,o,a,f,t.instance)}};if(d)On(d,s,o,r,a,{picker:i,fileUploadHandler:p,dragHandler:c});else{const m=he(e,a);Ze(s,a,m)}s.onclick=p,Qe(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const m={picker:i,fileUploadHandler:p,dragHandler:c};Et(i.files[0],s,o,a,m,t.instance)}},r.appendChild(s),r.appendChild(i),n.appendChild(r)}}function Pn(e,t,n,o){var l;const a=t.state;if(a.config.readonly){const r=document.createElement("div");r.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(s=>{Ge(s,a).then(d=>{r.appendChild(d)}).catch(d=>{console.error("Failed to render file preview:",d)})}):r.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${W(k("noFilesSelected",a))}</div></div>`,n.appendChild(r)}else{let r=function(){yt(p,c,a,f=>{const h=c.indexOf(f);h>-1&&c.splice(h,1),r()},m)};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:((l=e.accept.extensions)==null?void 0:l.map(f=>`.${f}`).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 p=document.createElement("div");p.className="files-list";const c=t.prefill[e.key]||[];wt(c,a);const m=he(e,a);r(),kt(d,c,a,r,o,t.instance),$t(s,c,a,r,o,t.instance),d.appendChild(p),i.appendChild(d),i.appendChild(s),n.appendChild(i)}}function Vn(e,t,n,o){var l,a,r;const i=t.state,s=(l=e.minCount)!=null?l:0,d=(a=e.maxCount)!=null?a:1/0;if(i.config.readonly){const p=document.createElement("div");p.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(m=>{Ge(m,i).then(f=>{p.appendChild(f)}).catch(f=>{console.error("Failed to render file preview:",f)})}):p.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${W(k("noFilesSelected",i))}</div></div>`,n.appendChild(p)}else{const p=document.createElement("div");p.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(C=>`.${C}`).join(","))||"");const m=document.createElement("div");m.className="files-list space-y-2",p.appendChild(c),p.appendChild(m);const f=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];wt(f,i);const h=he(e,i),v=()=>{const C=f.length===1?k("fileCountSingle",i,{count:f.length}):k("fileCountPlural",i,{count:f.length}),u=s>0||d<1/0?` ${k("fileCountRange",i,{min:s,max:d})}`:"";return C+u},b=()=>{yt(m,f,i,C=>{f.splice(f.indexOf(C),1),b()},h,v())};kt(m,f,i,b,o,t.instance),$t(c,f,i,b,o,t.instance),b(),n.appendChild(p)}}function Lt(e,t,n){var o;const l=[],{scopeRoot:a,skipValidation:r,path:i}=n,s=e.type==="files"||"multiple"in e&&!!e.multiple,d=(p,c,m)=>{var f,h;if(r)return;const{state:v}=n,b="minCount"in m&&(f=m.minCount)!=null?f:0,C="maxCount"in m&&(h=m.maxCount)!=null?h:1/0;m.required&&c.length===0&&l.push(`${p}: ${k("required",v)}`),c.length<b&&l.push(`${p}: ${k("minFiles",v,{min:b})}`),c.length>C&&l.push(`${p}: ${k("maxFiles",v,{max:C})}`)};if(s){const p=ke(i,t),c=a.querySelector(`input[type="file"][name="${p}"]`),m=c==null?void 0:c.closest(".space-y-2"),f=(m==null?void 0:m.querySelector(".files-list"))||null,h=[];return f&&f.querySelectorAll(".resource-pill").forEach(v=>{const b=v.dataset.resourceId;b&&h.push(b)}),d(t,h,e),{value:h,errors:l}}else{const p=a.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=p==null?void 0:p.value)!=null?o:"";return!r&&e.required&&c===""?(l.push(`${t}: ${k("required",n.state)}`),{value:null,errors:l}):{value:c||null,errors:l}}}function St(e,t,n,o){var l;const{scopeRoot:a,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 d=i.split("/").pop()||"file",p=(s=d.split(".").pop())==null?void 0:s.toLowerCase();let c="application/octet-stream";p&&(["jpg","jpeg","png","gif","webp"].includes(p)?c=`image/${p==="jpg"?"jpeg":p}`:["mp4","webm","mov","avi"].includes(p)&&(c=`video/${p==="mov"?"quicktime":p}`)),r.resourceIndex.set(i,{name:d,type:c,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const i=a.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",d=(l=s.split(".").pop())==null?void 0:l.toLowerCase();let p="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?p=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(p=`video/${d==="mov"?"quicktime":d}`)),r.resourceIndex.set(n,{name:s,type:p,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function Le(e){return e?e.toUpperCase():"#000000"}function et(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function Tt(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],o=e[3];return`#${t}${t}${n}${n}${o}${o}`.toUpperCase()}return e.toUpperCase()}function At(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=Le(e),o=document.createElement("div");o.style.cssText=`
|
|
229
|
+
`}function Oe(e,t){var n,r;const l=(n=e.closest(".space-y-2"))==null?void 0:n.querySelector(".file-error-message");l&&l.remove();const a=document.createElement("div");a.className="file-error-message error-message",a.style.cssText=`
|
|
230
|
+
color: var(--fb-error-color);
|
|
231
|
+
font-size: var(--fb-font-size-small);
|
|
232
|
+
margin-top: 0.25rem;
|
|
233
|
+
`,a.textContent=t,(r=e.closest(".space-y-2"))==null||r.appendChild(a)}function ot(e){var t;const n=(t=e.closest(".space-y-2"))==null?void 0:t.querySelector(".file-error-message");n&&n.remove()}async function Lt(e,t,n,r,l=null,a,o=[],c=1/0){var i,u;if(!Ee(e.name,o)){const m=o.join(", ");Oe(t,k("invalidFileExtension",r,{name:e.name,formats:m}));return}if(!$e(e,c)){Oe(t,k("fileTooLarge",r,{name:e.name,maxSize:c}));return}ot(t);let f;if(r.config.uploadFile)try{if(f=await r.config.uploadFile(e),typeof f!="string")throw new Error("Upload handler must return a string resource ID")}catch(m){const p=m instanceof Error?m:new Error(String(m));throw r.config.onUploadError&&r.config.onUploadError(p,e),new Error(`File upload failed: ${p.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");r.resourceIndex.set(f,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let s=(i=t.parentElement)==null?void 0:i.querySelector('input[type="hidden"]');s||(s=document.createElement("input"),s.type="hidden",s.name=n,(u=t.parentElement)==null||u.appendChild(s)),s.value=f,wt(t,f,r,{fileName:e.name,isReadonly:!1,deps:l}).catch(console.error),a&&!r.config.readonly&&a.triggerOnChange(n,f)}function rt(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 r;n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50"),(r=n.dataTransfer)!=null&&r.files&&t(n.dataTransfer.files)})}function Pn(e,t,n){const r=e.querySelector(".delete-overlay");r&&r.remove();const l=document.createElement("div");l.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 a=document.createElement("button");a.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",a.textContent=k("removeElement",t),a.onclick=o=>{o.stopPropagation(),n()},l.appendChild(a),e.appendChild(l)}async function St(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 r=n instanceof Error?n:new Error(String(n));throw t.config.onUploadError&&t.config.onUploadError(r,e),new Error(`File upload failed: ${r.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()")}async function Vn(e,t,n){try{let r=null;if(n.config.getDownloadUrl?r=n.config.getDownloadUrl(e):n.config.getThumbnail&&(r=await n.config.getThumbnail(e)),r){const l=r.startsWith("http")?r:new URL(r,window.location.href).href,a=await fetch(l);if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const o=await a.blob();Kn(o,t)}else throw new Error("No download URL available for resource")}catch(r){const l=r instanceof Error?r:new Error(String(r));throw n.config.onDownloadError&&n.config.onDownloadError(l,e,t),console.error(`File download failed for ${t}:`,l),l}}function Kn(e,t){try{const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>{URL.revokeObjectURL(n)},100)}catch(n){throw new Error(`Blob download failed: ${n.message}`)}}function Tt(e,t){e.length>0&&e.forEach(n=>{var r;if(!t.resourceIndex.has(n)){const l=n.split("/").pop()||"file",a=(r=l.split(".").pop())==null?void 0:r.toLowerCase();let o="application/octet-stream";a&&(["jpg","jpeg","png","gif","webp"].includes(a)?o=`image/${a==="jpg"?"jpeg":a}`:["mp4","webm","mov","avi"].includes(a)&&(o=`video/${a==="mov"?"quicktime":a}`)),t.resourceIndex.set(n,{name:l,type:o,size:0,uploadedAt:new Date,file:void 0})}})}function _n(e,t,n,r,l,a){var o;if(!l.resourceIndex.has(e)){const i=e.split("/").pop()||"file",u=(o=i.split(".").pop())==null?void 0:o.toLowerCase();let f="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?f=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(f=`video/${u==="mov"?"quicktime":u}`)),l.resourceIndex.set(e,{name:i,type:f,size:0,uploadedAt:new Date,file:void 0})}wt(t,e,l,{fileName:e,isReadonly:!1,deps:a}).catch(console.error);const c=document.createElement("input");c.type="hidden",c.name=n,c.value=e,r.appendChild(c)}function At(e,t,n,r,l,a,o){rt(e,async c=>{const i=Array.from(c),u=i.filter(x=>!Ee(x.name,l.allowedExtensions)),f=i.filter(x=>Ee(x.name,l.allowedExtensions)),s=f.filter(x=>!$e(x,l.maxSize)),m=f.filter(x=>$e(x,l.maxSize)),p=l.maxCount===1/0?m.length:Math.max(0,l.maxCount-t.length),h=m.slice(0,p),v=m.length-h.length,b=[];if(u.length>0){const x=l.allowedExtensions.join(", "),d=u.map(y=>y.name).join(", ");b.push(k("invalidFileExtension",n,{name:d,formats:x}))}if(s.length>0){const x=s.map(d=>d.name).join(", ");b.push(k("fileTooLarge",n,{name:x,maxSize:l.maxSize}))}v>0&&b.push(k("filesLimitExceeded",n,{skipped:v,max:l.maxCount})),b.length>0?Oe(e,b.join(" \u2022 ")):ot(e);for(const x of h){const d=await St(x,n);n.resourceIndex.set(d,{name:x.name,type:x.type,size:x.size,uploadedAt:new Date,file:void 0}),t.push(d)}r(),o&&a&&!n.config.readonly&&o.triggerOnChange(a,t)})}function Ft(e,t,n,r,l,a,o){e.onchange=async()=>{if(e.files){const c=Array.from(e.files),i=c.filter(x=>!Ee(x.name,l.allowedExtensions)),u=c.filter(x=>Ee(x.name,l.allowedExtensions)),f=u.filter(x=>!$e(x,l.maxSize)),s=u.filter(x=>$e(x,l.maxSize)),m=l.maxCount===1/0?s.length:Math.max(0,l.maxCount-t.length),p=s.slice(0,m),h=s.length-p.length,v=[];if(i.length>0){const x=l.allowedExtensions.join(", "),d=i.map(y=>y.name).join(", ");v.push(k("invalidFileExtension",n,{name:d,formats:x}))}if(f.length>0){const x=f.map(d=>d.name).join(", ");v.push(k("fileTooLarge",n,{name:x,maxSize:l.maxSize}))}h>0&&v.push(k("filesLimitExceeded",n,{skipped:h,max:l.maxCount}));const b=e.closest(".space-y-2")||e.parentElement;v.length>0&&b?Oe(b,v.join(" \u2022 ")):b&&ot(b);for(const x of p){const d=await St(x,n);n.resourceIndex.set(d,{name:x.name,type:x.type,size:x.size,uploadedAt:new Date,file:void 0}),t.push(d)}}r(),e.value="",o&&a&&!n.config.readonly&&o.triggerOnChange(a,t)}}function Wn(e,t,n,r){var l,a;const o=t.state;if(o.config.readonly){const c=t.prefill[e.key];if(c)tt(c,o).then(i=>{n.appendChild(i)}).catch(i=>{console.error("Failed to render file preview:",i);const u=document.createElement("div");u.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",u.innerHTML=`<div class="text-center">${W(k("previewUnavailable",o))}</div>`,n.appendChild(u)});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">${W(k("noFileSelected",o))}</div>`,n.appendChild(i)}}else{const c=document.createElement("div");c.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=r,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((l=e.accept.extensions)==null?void 0:l.map(v=>`.${v}`).join(","))||"");const u=document.createElement("div");u.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const f=t.prefill[e.key],s=Me(e.accept),m=(a=e.maxSize)!=null?a:1/0,p=()=>i.click(),h=v=>{if(v.length>0){const b={picker:i,fileUploadHandler:p,dragHandler:h};Lt(v[0],u,r,o,b,t.instance,s,m)}};if(f)_n(f,u,r,c,o,{picker:i,fileUploadHandler:p,dragHandler:h});else{const v=he(e,o);nt(u,o,v)}u.onclick=p,rt(u,h),i.onchange=()=>{if(i.files&&i.files.length>0){const v={picker:i,fileUploadHandler:p,dragHandler:h};Lt(i.files[0],u,r,o,v,t.instance,s,m)}},c.appendChild(u),c.appendChild(i),n.appendChild(c)}}function Jn(e,t,n,r){var l,a;const o=t.state;if(o.config.readonly){const c=document.createElement("div");c.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(u=>{tt(u,o).then(f=>{c.appendChild(f)}).catch(f=>{console.error("Failed to render file preview:",f)})}):c.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${W(k("noFilesSelected",o))}</div></div>`,n.appendChild(c)}else{let c=function(){kt(s,m,o,v=>{const b=m.indexOf(v);b>-1&&m.splice(b,1),c()},p)};const i=document.createElement("div");i.className="space-y-2";const u=document.createElement("input");u.type="file",u.name=r,u.multiple=!0,u.style.display="none",e.accept&&(u.accept=typeof e.accept=="string"?e.accept:((l=e.accept.extensions)==null?void 0:l.map(v=>`.${v}`).join(","))||"");const f=document.createElement("div");f.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const s=document.createElement("div");s.className="files-list";const m=t.prefill[e.key]||[];Tt(m,o);const p=he(e,o),h={maxCount:1/0,allowedExtensions:Me(e.accept),maxSize:(a=e.maxSize)!=null?a:1/0};c(),At(f,m,o,c,h,r,t.instance),Ft(u,m,o,c,h,r,t.instance),f.appendChild(s),i.appendChild(f),i.appendChild(u),n.appendChild(i)}}function Yn(e,t,n,r){var l,a,o,c;const i=t.state,u=(l=e.minCount)!=null?l:0,f=(a=e.maxCount)!=null?a:1/0;if(i.config.readonly){const s=document.createElement("div");s.className="space-y-4";const m=t.prefill[e.key]||[];m.length>0?m.forEach(p=>{tt(p,i).then(h=>{s.appendChild(h)}).catch(h=>{console.error("Failed to render file preview:",h)})}):s.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${W(k("noFilesSelected",i))}</div></div>`,n.appendChild(s)}else{const s=document.createElement("div");s.className="space-y-2";const m=document.createElement("input");m.type="file",m.name=r,m.multiple=!0,m.style.display="none",e.accept&&(m.accept=typeof e.accept=="string"?e.accept:((o=e.accept.extensions)==null?void 0:o.map(y=>`.${y}`).join(","))||"");const p=document.createElement("div");p.className="files-list space-y-2",s.appendChild(m),s.appendChild(p);const h=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];Tt(h,i);const v=he(e,i),b={maxCount:f,allowedExtensions:Me(e.accept),maxSize:(c=e.maxSize)!=null?c:1/0},x=()=>{const y=h.length===1?k("fileCountSingle",i,{count:h.length}):k("fileCountPlural",i,{count:h.length}),g=u>0||f<1/0?` ${k("fileCountRange",i,{min:u,max:f})}`:"";return y+g},d=()=>{kt(p,h,i,y=>{h.splice(h.indexOf(y),1),d()},v,x())};At(p,h,i,d,b,r,t.instance),Ft(m,h,i,d,b,r,t.instance),d(),n.appendChild(s)}}function Nt(e,t,n){var r;const l=[],{scopeRoot:a,skipValidation:o,path:c}=n,i=e.type==="files"||"multiple"in e&&!!e.multiple,u=(m,p,h)=>{var v,b;if(o)return;const{state:x}=n,d="minCount"in h&&(v=h.minCount)!=null?v:0,y="maxCount"in h&&(b=h.maxCount)!=null?b:1/0;h.required&&p.length===0&&l.push(`${m}: ${k("required",x)}`),p.length<d&&l.push(`${m}: ${k("minFiles",x,{min:d})}`),p.length>y&&l.push(`${m}: ${k("maxFiles",x,{max:y})}`)},f=(m,p,h)=>{var v;if(o)return;const{state:b}=n,x="accept"in h?h.accept:void 0,d=Me(x);if(d.length===0)return;const y=d.join(", ");for(const g of p){const E=b.resourceIndex.get(g),C=(v=E==null?void 0:E.name)!=null?v:g;Ee(C,d)||l.push(`${m}: ${k("invalidFileExtension",b,{name:C,formats:y})}`)}},s=(m,p,h)=>{var v;if(o)return;const{state:b}=n,x="maxSize"in h&&(v=h.maxSize)!=null?v:1/0;if(x!==1/0)for(const d of p){const y=b.resourceIndex.get(d);y&&y.size>x*1024*1024&&l.push(`${m}: ${k("fileTooLarge",b,{name:y.name,maxSize:x})}`)}};if(i){const m=we(c,t),p=a.querySelector(`input[type="file"][name="${m}"]`),h=p==null?void 0:p.closest(".space-y-2"),v=(h==null?void 0:h.querySelector(".files-list"))||null,b=[];return v&&v.querySelectorAll(".resource-pill").forEach(x=>{const d=x.dataset.resourceId;d&&b.push(d)}),u(t,b,e),f(t,b,e),s(t,b,e),{value:b,errors:l}}else{const m=a.querySelector(`input[name$="${t}"][type="hidden"]`),p=(r=m==null?void 0:m.value)!=null?r:"";return!o&&e.required&&p===""?(l.push(`${t}: ${k("required",n.state)}`),{value:null,errors:l}):(!o&&p!==""&&(f(t,[p],e),s(t,[p],e)),{value:p||null,errors:l})}}function Mt(e,t,n,r){var l;const{scopeRoot:a,state:o}=r;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(c=>{var i;if(c&&typeof c=="string"&&!o.resourceIndex.has(c)){const u=c.split("/").pop()||"file",f=(i=u.split(".").pop())==null?void 0:i.toLowerCase();let s="application/octet-stream";f&&(["jpg","jpeg","png","gif","webp"].includes(f)?s=`image/${f==="jpg"?"jpeg":f}`:["mp4","webm","mov","avi"].includes(f)&&(s=`video/${f==="mov"?"quicktime":f}`)),o.resourceIndex.set(c,{name:u,type:s,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const c=a.querySelector(`input[name="${t}"][type="hidden"]`);if(!c){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(c.value=n!=null?String(n):"",n&&typeof n=="string"){if(!o.resourceIndex.has(n)){const i=n.split("/").pop()||"file",u=(l=i.split(".").pop())==null?void 0:l.toLowerCase();let f="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?f=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(f=`video/${u==="mov"?"quicktime":u}`)),o.resourceIndex.set(n,{name:i,type:f,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function Le(e){return e?e.toUpperCase():"#000000"}function lt(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function qt(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],r=e[3];return`#${t}${t}${n}${n}${r}${r}`.toUpperCase()}return e.toUpperCase()}function zt(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=Le(e),r=document.createElement("div");r.style.cssText=`
|
|
230
234
|
width: 32px;
|
|
231
235
|
height: 32px;
|
|
232
236
|
border-radius: var(--fb-border-radius);
|
|
@@ -236,7 +240,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
236
240
|
font-size: var(--fb-font-size);
|
|
237
241
|
color: var(--fb-text-color);
|
|
238
242
|
font-family: var(--fb-font-family-mono, monospace);
|
|
239
|
-
`,l.textContent=n,t.appendChild(
|
|
243
|
+
`,l.textContent=n,t.appendChild(r),t.appendChild(l),t}function Ht(e,t,n){const r=Le(e),l=document.createElement("div");l.className="colour-picker-wrapper",l.style.cssText=`
|
|
240
244
|
display: flex;
|
|
241
245
|
align-items: center;
|
|
242
246
|
gap: 8px;
|
|
@@ -245,11 +249,11 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
245
249
|
height: 40px;
|
|
246
250
|
border-radius: var(--fb-border-radius);
|
|
247
251
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
248
|
-
background-color: ${
|
|
252
|
+
background-color: ${r};
|
|
249
253
|
cursor: pointer;
|
|
250
254
|
transition: border-color var(--fb-transition-duration) ease-in-out;
|
|
251
255
|
flex-shrink: 0;
|
|
252
|
-
`;const
|
|
256
|
+
`;const o=document.createElement("input");o.type="text",o.className="colour-hex-input",o.name=t,o.value=r,o.placeholder="#000000",o.style.cssText=`
|
|
253
257
|
width: 100px;
|
|
254
258
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
255
259
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
@@ -259,49 +263,49 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
259
263
|
font-size: var(--fb-font-size);
|
|
260
264
|
font-family: var(--fb-font-family-mono, monospace);
|
|
261
265
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
262
|
-
`;const
|
|
266
|
+
`;const c=document.createElement("input");return c.type="color",c.className="colour-picker-hidden",c.value=r.toLowerCase(),c.style.cssText=`
|
|
263
267
|
position: absolute;
|
|
264
268
|
opacity: 0;
|
|
265
269
|
pointer-events: none;
|
|
266
|
-
`,
|
|
270
|
+
`,o.addEventListener("input",()=>{const i=o.value.trim();if(lt(i)){const u=qt(i);a.style.backgroundColor=u,c.value=u.toLowerCase(),o.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,u)}else o.classList.add("invalid")}),o.addEventListener("blur",()=>{const i=o.value.trim();if(lt(i)){const u=qt(i);o.value=u,a.style.backgroundColor=u,c.value=u.toLowerCase(),o.classList.remove("invalid")}}),c.addEventListener("change",()=>{const i=Le(c.value);o.value=i,a.style.backgroundColor=i,n.instance&&n.instance.triggerOnChange(t,i)}),a.addEventListener("click",()=>{c.click()}),a.addEventListener("mouseenter",()=>{a.style.borderColor="var(--fb-border-hover-color)"}),a.addEventListener("mouseleave",()=>{a.style.borderColor="var(--fb-border-color)"}),o.addEventListener("focus",()=>{o.style.borderColor="var(--fb-border-focus-color)",o.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",o.style.outlineOffset="0"}),o.addEventListener("blur",()=>{o.style.borderColor="var(--fb-border-color)",o.style.outline="none"}),o.addEventListener("mouseenter",()=>{document.activeElement!==o&&(o.style.borderColor="var(--fb-border-hover-color)")}),o.addEventListener("mouseleave",()=>{document.activeElement!==o&&(o.style.borderColor="var(--fb-border-color)")}),l.appendChild(a),l.appendChild(o),l.appendChild(c),l}function Xn(e,t,n,r){const l=t.state,a=t.prefill[e.key]||e.default||"#000000";if(l.config.readonly){const o=zt(a);n.appendChild(o)}else{const o=Ht(a,r,t);n.appendChild(o)}if(!l.config.readonly){const o=document.createElement("p");o.className="mt-1",o.style.cssText=`
|
|
267
271
|
font-size: var(--fb-font-size-small);
|
|
268
272
|
color: var(--fb-text-secondary-color);
|
|
269
|
-
`,
|
|
273
|
+
`,o.textContent=he(e,l),n.appendChild(o)}}function Gn(e,t,n,r){var l,a;const o=t.state,c=t.prefill[e.key]||[],i=Array.isArray(c)?[...c]:[],u=(l=e.minCount)!=null?l:1,f=(a=e.maxCount)!=null?a:1/0;for(;i.length<u;)i.push(e.default||"#000000");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function m(){s.querySelectorAll(".multiple-colour-item").forEach((d,y)=>{const g=d.querySelector("input");g&&(g.name=`${r}[${y}]`)})}function p(d="#000000",y=-1){const g=document.createElement("div");if(g.className="multiple-colour-item flex items-center gap-2",o.config.readonly){const E=zt(d);for(;E.firstChild;)g.appendChild(E.firstChild)}else{const E=`${r}[${s.children.length}]`,C=Ht(d,E,t);C.style.flex="1",g.appendChild(C)}return y===-1?s.appendChild(g):s.insertBefore(g,s.children[y]),m(),g}function h(){if(o.config.readonly)return;const d=s.querySelectorAll(".multiple-colour-item"),y=d.length;d.forEach(g=>{let E=g.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn px-2 py-1 rounded",E.style.cssText=`
|
|
270
274
|
color: var(--fb-error-color);
|
|
271
275
|
background-color: transparent;
|
|
272
276
|
transition: background-color var(--fb-transition-duration);
|
|
273
|
-
`,
|
|
277
|
+
`,E.innerHTML="\u2715",E.addEventListener("mouseenter",()=>{E.style.backgroundColor="var(--fb-background-hover-color)"}),E.addEventListener("mouseleave",()=>{E.style.backgroundColor="transparent"}),E.onclick=()=>{const w=Array.from(s.children).indexOf(g);s.children.length>u&&(i.splice(w,1),g.remove(),m(),x(),h())},g.appendChild(E));const C=y<=u;E.disabled=C,E.style.opacity=C?"0.5":"1",E.style.pointerEvents=C?"none":"auto"})}let v=null,b=null;if(!o.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-colour-btn px-3 py-1 rounded",d.style.cssText=`
|
|
274
278
|
color: var(--fb-primary-color);
|
|
275
279
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
276
280
|
background-color: transparent;
|
|
277
281
|
font-size: var(--fb-font-size);
|
|
278
282
|
transition: all var(--fb-transition-duration);
|
|
279
|
-
`,
|
|
283
|
+
`,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{const y=e.default||"#000000";i.push(y),p(y),x(),h()},b=document.createElement("span"),b.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(b),n.appendChild(v)}function x(){if(!v||!b)return;const d=v.querySelector(".add-colour-btn");if(d){const y=i.length>=f;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}b.textContent=`${i.length}/${f===1/0?"\u221E":f}`}if(i.forEach(d=>p(d)),x(),h(),!o.config.readonly){const d=document.createElement("p");d.className="mt-1",d.style.cssText=`
|
|
280
284
|
font-size: var(--fb-font-size-small);
|
|
281
285
|
color: var(--fb-text-secondary-color);
|
|
282
|
-
`,
|
|
286
|
+
`,d.textContent=he(e,o),n.appendChild(d)}}function Zn(e,t,n){var r,l,a;const o=[],{scopeRoot:c,skipValidation:i}=n,u=(s,m)=>{var p,h;if(!s)return;const v=`error-${s.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(v);m?(s.classList.add("invalid"),s.title=m,b||(b=document.createElement("div"),b.id=v,b.className="error-message",b.style.cssText=`
|
|
283
287
|
color: var(--fb-error-color);
|
|
284
288
|
font-size: var(--fb-font-size-small);
|
|
285
289
|
margin-top: 0.25rem;
|
|
286
|
-
`,
|
|
290
|
+
`,s.nextSibling?(p=s.parentNode)==null||p.insertBefore(b,s.nextSibling):(h=s.parentNode)==null||h.appendChild(b)),b.textContent=m,b.style.display="block"):(s.classList.remove("invalid"),s.title="",b&&b.remove())},f=(s,m,p)=>{const{state:h}=n;if(!m){if(!i&&e.required){const b=k("required",h);return o.push(`${p}: ${b}`),u(s,b),""}return u(s,null),""}const v=Le(m);if(!i&&!lt(v)){const b=k("invalidHexColour",h);return o.push(`${p}: ${b}`),u(s,b),m}return u(s,null),v};if(e.multiple){const s=c.querySelectorAll(`[name^="${t}["].colour-hex-input`),m=[];if(s.forEach((p,h)=>{var v;const b=(v=p==null?void 0:p.value)!=null?v:"",x=f(p,b,`${t}[${h}]`);m.push(x)}),!i){const{state:p}=n,h=(r=e.minCount)!=null?r:1,v=(l=e.maxCount)!=null?l:1/0,b=m.filter(x=>x!=="");e.required&&b.length===0&&o.push(`${t}: ${k("required",p)}`),b.length<h&&o.push(`${t}: ${k("minItems",p,{min:h})}`),b.length>v&&o.push(`${t}: ${k("maxItems",p,{max:v})}`)}return{value:m,errors:o}}else{const s=c.querySelector(`[name="${t}"].colour-hex-input`),m=(a=s==null?void 0:s.value)!=null?a:"";if(!i&&e.required&&m===""){const p=k("required",n.state);return o.push(`${t}: ${p}`),u(s,p),{value:"",errors:o}}return{value:f(s,m,t),errors:o}}}function Qn(e,t,n,r){const{scopeRoot:l}=r;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateColourField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=l.querySelectorAll(`[name^="${t}["].colour-hex-input`);a.forEach((o,c)=>{if(c<n.length){const i=Le(n[c]);o.value=i,o.classList.remove("invalid"),o.title="";const u=o.closest(".colour-picker-wrapper");if(u){const f=u.querySelector(".colour-swatch"),s=u.querySelector(".colour-picker-hidden");f&&(f.style.backgroundColor=i),s&&(s.value=i.toLowerCase())}}}),n.length!==a.length&&console.warn(`updateColourField: Multiple field "${t}" has ${a.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=l.querySelector(`[name="${t}"].colour-hex-input`);if(a){const o=Le(n);a.value=o,a.classList.remove("invalid"),a.title="";const c=a.closest(".colour-picker-wrapper");if(c){const i=c.querySelector(".colour-swatch"),u=c.querySelector(".colour-picker-hidden");i&&(i.style.backgroundColor=o),u&&(u.value=o.toLowerCase())}}}}function It(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const r=Math.log(t),l=Math.log(n);return Math.exp(r+e*(l-r))}function at(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const r=Math.log(t),l=Math.log(n);return(Math.log(e)-r)/(l-r)}function Ue(e,t){return Math.round(e/t)*t}function Bt(e,t,n,r,l){var a;const o=document.createElement("div");o.className="slider-container";const c=document.createElement("div");c.className="flex items-start gap-3";const i=document.createElement("div");i.className="flex-1";const u=document.createElement("input");u.type="range",u.name=t,u.className="slider-input w-full",u.disabled=l;const f=n.scale||"linear",s=n.min,m=n.max,p=(a=n.step)!=null?a:1;if(f==="exponential"){if(s<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${s})`);u.min="0",u.max="1000",u.step="1";const d=at(e,s,m);u.value=(d*1e3).toString()}else u.min=s.toString(),u.max=m.toString(),u.step=p.toString(),u.value=e.toString();u.style.cssText=`
|
|
287
291
|
height: 6px;
|
|
288
292
|
border-radius: 3px;
|
|
289
293
|
background: linear-gradient(
|
|
290
294
|
to right,
|
|
291
295
|
var(--fb-primary-color) 0%,
|
|
292
|
-
var(--fb-primary-color) ${(e-
|
|
293
|
-
var(--fb-border-color) ${(e-
|
|
296
|
+
var(--fb-primary-color) ${(e-s)/(m-s)*100}%,
|
|
297
|
+
var(--fb-border-color) ${(e-s)/(m-s)*100}%,
|
|
294
298
|
var(--fb-border-color) 100%
|
|
295
299
|
);
|
|
296
300
|
outline: none;
|
|
297
301
|
transition: background 0.1s ease-in-out;
|
|
298
302
|
cursor: ${l?"not-allowed":"pointer"};
|
|
299
303
|
opacity: ${l?"0.6":"1"};
|
|
300
|
-
`,
|
|
304
|
+
`,i.appendChild(u);const h=document.createElement("div");h.className="flex justify-between",h.style.cssText=`
|
|
301
305
|
font-size: var(--fb-font-size-small);
|
|
302
306
|
color: var(--fb-text-secondary-color);
|
|
303
307
|
margin-top: 4px;
|
|
304
|
-
`;const v=document.createElement("span");v.textContent=
|
|
308
|
+
`;const v=document.createElement("span");v.textContent=s.toString();const b=document.createElement("span");b.textContent=m.toString(),h.appendChild(v),h.appendChild(b),i.appendChild(h);const x=document.createElement("span");if(x.className="slider-value",x.style.cssText=`
|
|
305
309
|
min-width: 60px;
|
|
306
310
|
text-align: right;
|
|
307
311
|
font-size: var(--fb-font-size);
|
|
@@ -309,64 +313,64 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
309
313
|
font-family: var(--fb-font-family-mono, monospace);
|
|
310
314
|
font-weight: 500;
|
|
311
315
|
padding-top: 2px;
|
|
312
|
-
`,
|
|
316
|
+
`,x.textContent=e.toFixed(p<1?2:0),c.appendChild(i),c.appendChild(x),o.appendChild(c),!l){const d=()=>{let y;if(f==="exponential"){const E=parseFloat(u.value)/1e3;y=It(E,s,m),y=Ue(y,p),y=Math.max(s,Math.min(m,y))}else y=parseFloat(u.value),y=Ue(y,p);x.textContent=y.toFixed(p<1?2:0);const g=(y-s)/(m-s)*100;u.style.background=`linear-gradient(
|
|
313
317
|
to right,
|
|
314
318
|
var(--fb-primary-color) 0%,
|
|
315
319
|
var(--fb-primary-color) ${g}%,
|
|
316
320
|
var(--fb-border-color) ${g}%,
|
|
317
321
|
var(--fb-border-color) 100%
|
|
318
|
-
)`,
|
|
322
|
+
)`,r.instance&&r.instance.triggerOnChange(t,y)};u.addEventListener("input",d),u.addEventListener("change",d)}return o}function eo(e,t,n,r){var 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 a=t.state,o=e.default!==void 0?e.default:(e.min+e.max)/2,c=(l=t.prefill[e.key])!=null?l:o,i=Bt(c,r,e,t,a.config.readonly);if(n.appendChild(i),!a.config.readonly){const u=document.createElement("p");u.className="mt-1",u.style.cssText=`
|
|
319
323
|
font-size: var(--fb-font-size-small);
|
|
320
324
|
color: var(--fb-text-secondary-color);
|
|
321
|
-
`,
|
|
325
|
+
`,u.textContent=he(e,a),n.appendChild(u)}}function to(e,t,n,r){var l,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 o=t.state,c=t.prefill[e.key]||[],i=Array.isArray(c)?[...c]:[],u=(l=e.minCount)!=null?l:1,f=(a=e.maxCount)!=null?a:1/0,s=e.default!==void 0?e.default:(e.min+e.max)/2;for(;i.length<u;)i.push(s);const m=document.createElement("div");m.className="space-y-3",n.appendChild(m);function p(){m.querySelectorAll(".multiple-slider-item").forEach((y,g)=>{const E=y.querySelector("input[type=range]");E&&E.setAttribute("name",`${r}[${g}]`)})}function h(y=s,g=-1){const E=document.createElement("div");E.className="multiple-slider-item flex items-start gap-2";const C=`${r}[${m.children.length}]`,w=Bt(y,C,e,t,o.config.readonly);return w.style.flex="1",E.appendChild(w),g===-1?m.appendChild(E):m.insertBefore(E,m.children[g]),p(),E}function v(){if(o.config.readonly)return;const y=m.querySelectorAll(".multiple-slider-item"),g=y.length;y.forEach(E=>{let C=E.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn px-2 py-1 rounded",C.style.cssText=`
|
|
322
326
|
color: var(--fb-error-color);
|
|
323
327
|
background-color: transparent;
|
|
324
328
|
transition: background-color var(--fb-transition-duration);
|
|
325
329
|
margin-top: 8px;
|
|
326
|
-
`,
|
|
330
|
+
`,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const S=Array.from(m.children).indexOf(E);m.children.length>u&&(i.splice(S,1),E.remove(),p(),d(),v())},E.appendChild(C));const w=g<=u;C.disabled=w,C.style.opacity=w?"0.5":"1",C.style.pointerEvents=w?"none":"auto"})}let b=null,x=null;if(!o.config.readonly){b=document.createElement("div"),b.className="flex items-center gap-3 mt-2";const y=document.createElement("button");y.type="button",y.className="add-slider-btn px-3 py-1 rounded",y.style.cssText=`
|
|
327
331
|
color: var(--fb-primary-color);
|
|
328
332
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
329
333
|
background-color: transparent;
|
|
330
334
|
font-size: var(--fb-font-size);
|
|
331
335
|
transition: all var(--fb-transition-duration);
|
|
332
|
-
`,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{
|
|
336
|
+
`,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{i.push(s),h(s),d(),v()},x=document.createElement("span"),x.className="text-sm text-gray-500",b.appendChild(y),b.appendChild(x),n.appendChild(b)}function d(){if(!b||!x)return;const y=b.querySelector(".add-slider-btn");if(y){const g=i.length>=f;y.disabled=g,y.style.opacity=g?"0.5":"1",y.style.pointerEvents=g?"none":"auto"}x.textContent=`${i.length}/${f===1/0?"\u221E":f}`}if(i.forEach(y=>h(y)),d(),v(),!o.config.readonly){const y=document.createElement("p");y.className="mt-1",y.style.cssText=`
|
|
333
337
|
font-size: var(--fb-font-size-small);
|
|
334
338
|
color: var(--fb-text-secondary-color);
|
|
335
|
-
`,y.textContent=he(e,
|
|
339
|
+
`,y.textContent=he(e,o),n.appendChild(y)}}function no(e,t,n){var r,l,a;const o=[],{scopeRoot:c,skipValidation:i}=n;if(e.min===void 0||e.min===null)throw new Error(`Slider validation: field "${t}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider validation: field "${t}" requires "max" property`);const u=e.min,f=e.max,s=(r=e.step)!=null?r:1,m=e.scale||"linear",p=(v,b)=>{var x,d;if(!v)return;const y=`error-${v.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(y);if(b){if(v.classList.add("invalid"),v.title=b,!g){g=document.createElement("div"),g.id=y,g.className="error-message",g.style.cssText=`
|
|
336
340
|
color: var(--fb-error-color);
|
|
337
341
|
font-size: var(--fb-font-size-small);
|
|
338
342
|
margin-top: 0.25rem;
|
|
339
|
-
`;const
|
|
343
|
+
`;const E=v.closest(".slider-container");E&&E.nextSibling?(x=E.parentNode)==null||x.insertBefore(g,E.nextSibling):E&&((d=E.parentNode)==null||d.appendChild(g))}g.textContent=b,g.style.display="block"}else v.classList.remove("invalid"),v.title="",g&&g.remove()},h=(v,b)=>{const{state:x}=n,d=v.value;if(!d){if(!i&&e.required){const g=k("required",x);return o.push(`${b}: ${g}`),p(v,g),null}return p(v,null),null}let y;if(m==="exponential"){const g=parseFloat(d)/1e3;y=It(g,u,f),y=Ue(y,s)}else y=parseFloat(d),y=Ue(y,s);if(!i){if(y<u){const g=k("minValue",x,{min:u});return o.push(`${b}: ${g}`),p(v,g),y}if(y>f){const g=k("maxValue",x,{max:f});return o.push(`${b}: ${g}`),p(v,g),y}}return p(v,null),y};if(e.multiple){const v=c.querySelectorAll(`input[type="range"][name^="${t}["]`),b=[];if(v.forEach((x,d)=>{const y=h(x,`${t}[${d}]`);b.push(y)}),!i){const{state:x}=n,d=(l=e.minCount)!=null?l:1,y=(a=e.maxCount)!=null?a:1/0,g=b.filter(E=>E!==null);e.required&&g.length===0&&o.push(`${t}: ${k("required",x)}`),g.length<d&&o.push(`${t}: ${k("minItems",x,{min:d})}`),g.length>y&&o.push(`${t}: ${k("maxItems",x,{max:y})}`)}return{value:b,errors:o}}else{const v=c.querySelector(`input[type="range"][name="${t}"]`);return v?{value:h(v,t),errors:o}:(!i&&e.required&&o.push(`${t}: ${k("required",n.state)}`),{value:null,errors:o})}}function oo(e,t,n,r){var l;const{scopeRoot:a}=r,o=e.min,c=e.max,i=(l=e.step)!=null?l: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 f=a.querySelectorAll(`input[type="range"][name^="${t}["]`);f.forEach((s,m)=>{if(m<n.length&&n[m]!==null){const p=Number(n[m]);if(u==="exponential"){const v=at(p,o,c);s.value=(v*1e3).toString()}else s.value=p.toString();const h=s.closest(".slider-container");if(h){const v=h.querySelector(".slider-value");v&&(v.textContent=p.toFixed(i<1?2:0));const b=(p-o)/(c-o)*100;s.style.background=`linear-gradient(
|
|
340
344
|
to right,
|
|
341
345
|
var(--fb-primary-color) 0%,
|
|
342
346
|
var(--fb-primary-color) ${b}%,
|
|
343
347
|
var(--fb-border-color) ${b}%,
|
|
344
348
|
var(--fb-border-color) 100%
|
|
345
|
-
)`}
|
|
349
|
+
)`}s.classList.remove("invalid"),s.title=""}}),n.length!==f.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${f.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const f=a.querySelector(`input[type="range"][name="${t}"]`);if(f&&n!==null&&n!==void 0){const s=Number(n);if(u==="exponential"){const p=at(s,o,c);f.value=(p*1e3).toString()}else f.value=s.toString();const m=f.closest(".slider-container");if(m){const p=m.querySelector(".slider-value");p&&(p.textContent=s.toFixed(i<1?2:0));const h=(s-o)/(c-o)*100;f.style.background=`linear-gradient(
|
|
346
350
|
to right,
|
|
347
351
|
var(--fb-primary-color) 0%,
|
|
348
352
|
var(--fb-primary-color) ${h}%,
|
|
349
353
|
var(--fb-border-color) ${h}%,
|
|
350
354
|
var(--fb-border-color) 100%
|
|
351
|
-
)`}
|
|
355
|
+
)`}f.classList.remove("invalid"),f.title=""}}}function Rt(e){const t={};for(const n of e)"default"in n&&n.default!==void 0&&(t[n.key]=n.default);return t}function Dt(e,t){return{...t,...e}}function it(e){const t={};return e.querySelectorAll("input, select, textarea").forEach(n=>{const r=n.getAttribute("name");r&&!r.includes("[")&&!r.includes(".")&&(n instanceof HTMLSelectElement?t[r]=n.value:n instanceof HTMLInputElement?n.type==="checkbox"?t[r]=n.checked:n.type==="radio"?n.checked&&(t[r]=n.value):t[r]=n.value:n instanceof HTMLTextAreaElement&&(t[r]=n.value))}),t}let st=null;function ro(e){st=e}function Pe(e,t){if(!st)throw new Error("renderElement not initialized. Import from components/index.ts");return st(e,t)}function jt(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((r,l)=>{const a=document.createElement("button");a.type="button",a.className="fb-prefill-hint",a.textContent=r.label,a.setAttribute("data-hint-values",JSON.stringify(r.values)),a.setAttribute("data-container-key",t),a.setAttribute("data-hint-index",String(l)),n.appendChild(a)}),n}function Ot(e,t,n,r){var l,a;const o=document.createElement("div");o.className="border border-gray-200 rounded-lg p-4 bg-gray-50",o.setAttribute("data-container",r);const c=document.createElement("div"),i=e.columns||1;if(i===1?c.className="space-y-4":c.className=`grid grid-cols-${i} gap-4`,!t.state.config.readonly){const p=jt(e,r);p&&o.appendChild(p)}const u=Rt(e.elements),f=((l=t.prefill)==null?void 0:l[e.key])||{},s=Dt(f,u),m={path:we(t.path,e.key),prefill:s,formData:(a=t.formData)!=null?a:t.prefill,state:t.state};e.elements.forEach(p=>{p.hidden||c.appendChild(Pe(p,m))}),o.appendChild(c),n.appendChild(o)}function Ut(e,t,n,r){var l,a,o,c;const i=t.state,u=document.createElement("div");u.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const f=document.createElement("span");f.className="text-sm text-gray-500";const s=document.createElement("div");if(s.className="space-y-4",!t.state.config.readonly){const g=jt(e,e.key);g&&u.appendChild(g)}const m=(l=e.minCount)!=null?l:0,p=(a=e.maxCount)!=null?a:1/0,h=Array.isArray((o=t.prefill)==null?void 0:o[e.key])?t.prefill[e.key]:null,v=Rt(e.elements),b=()=>s.querySelectorAll(":scope > .containerItem").length,x=()=>{const g=document.createElement("button");return g.type="button",g.className="add-container-btn px-3 py-1 rounded",g.style.cssText=`
|
|
352
356
|
color: var(--fb-primary-color);
|
|
353
357
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
354
358
|
background-color: transparent;
|
|
355
359
|
font-size: var(--fb-font-size);
|
|
356
360
|
transition: all var(--fb-transition-duration);
|
|
357
|
-
`,g.textContent="+",g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{if(b()<
|
|
361
|
+
`,g.textContent="+",g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{if(b()<p){const E=b(),C=i.formRoot?it(i.formRoot):{},w={state:t.state,path:we(t.path,`${e.key}[${E}]`),prefill:v,formData:C},S=document.createElement("div");S.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",S.setAttribute("data-container-item",`${e.key}[${E}]`);const z=document.createElement("div"),ne=e.columns||1;if(ne===1?z.className="space-y-4":z.className=`grid grid-cols-${ne} gap-4`,e.elements.forEach(P=>{P.hidden||z.appendChild(Pe(P,w))}),S.appendChild(z),!i.config.readonly){const P=document.createElement("button");P.type="button",P.className="absolute top-2 right-2 px-2 py-1 rounded",P.style.cssText=`
|
|
358
362
|
color: var(--fb-error-color);
|
|
359
363
|
background-color: transparent;
|
|
360
364
|
transition: background-color var(--fb-transition-duration);
|
|
361
|
-
`,
|
|
365
|
+
`,P.textContent="\u2715",P.addEventListener("mouseenter",()=>{P.style.backgroundColor="var(--fb-background-hover-color)"}),P.addEventListener("mouseleave",()=>{P.style.backgroundColor="transparent"}),P.onclick=()=>y(S),S.style.position="relative",S.appendChild(P)}s.appendChild(S),d()}},g},d=()=>{const g=b(),E=u.querySelector(".add-container-btn");E&&(E.disabled=g>=p,E.style.opacity=g>=p?"0.5":"1",E.style.pointerEvents=g>=p?"none":"auto"),f.textContent=`${g}/${p===1/0?"\u221E":p}`},y=g=>{g.remove(),d()};if(h&&Array.isArray(h)&&h.forEach((g,E)=>{var C;const w=Dt(g||{},v),S={state:t.state,path:we(t.path,`${e.key}[${E}]`),prefill:w,formData:(C=t.formData)!=null?C:t.prefill},z=document.createElement("div");z.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",z.setAttribute("data-container-item",`${e.key}[${E}]`);const ne=document.createElement("div"),P=e.columns||1;if(P===1?ne.className="space-y-4":ne.className=`grid grid-cols-${P} gap-4`,e.elements.forEach(G=>{G.hidden||ne.appendChild(Pe(G,S))}),z.appendChild(ne),!i.config.readonly){const G=document.createElement("button");G.type="button",G.className="absolute top-2 right-2 px-2 py-1 rounded",G.style.cssText=`
|
|
362
366
|
color: var(--fb-error-color);
|
|
363
367
|
background-color: transparent;
|
|
364
368
|
transition: background-color var(--fb-transition-duration);
|
|
365
|
-
`,
|
|
369
|
+
`,G.textContent="\u2715",G.addEventListener("mouseenter",()=>{G.style.backgroundColor="var(--fb-background-hover-color)"}),G.addEventListener("mouseleave",()=>{G.style.backgroundColor="transparent"}),G.onclick=()=>y(z),z.style.position="relative",z.appendChild(G)}s.appendChild(z)}),!i.config.readonly)for(;b()<m;){const g=b(),E={state:t.state,path:we(t.path,`${e.key}[${g}]`),prefill:v,formData:(c=t.formData)!=null?c:t.prefill},C=document.createElement("div");C.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",C.setAttribute("data-container-item",`${e.key}[${g}]`);const w=document.createElement("div"),S=e.columns||1;S===1?w.className="space-y-4":w.className=`grid grid-cols-${S} gap-4`,e.elements.forEach(ne=>{ne.hidden||w.appendChild(Pe(ne,E))}),C.appendChild(w);const z=document.createElement("button");z.type="button",z.className="absolute top-2 right-2 px-2 py-1 rounded",z.style.cssText=`
|
|
366
370
|
color: var(--fb-error-color);
|
|
367
371
|
background-color: transparent;
|
|
368
372
|
transition: background-color var(--fb-transition-duration);
|
|
369
|
-
`,
|
|
373
|
+
`,z.textContent="\u2715",z.addEventListener("mouseenter",()=>{z.style.backgroundColor="var(--fb-background-hover-color)"}),z.addEventListener("mouseleave",()=>{z.style.backgroundColor="transparent"}),z.onclick=()=>{b()>m&&y(C)},C.style.position="relative",C.appendChild(z),s.appendChild(C)}if(u.appendChild(s),!i.config.readonly){const g=document.createElement("div");g.className="flex items-center gap-3 mt-2",g.appendChild(x()),g.appendChild(f),u.appendChild(g)}d(),n.appendChild(u)}let ct=null;function lo(e){ct=e}function Pt(e,t,n){if(!ct)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return ct(e,t,n)}function Vt(e,t,n){const r=[],{scopeRoot:l,skipValidation:a,path:o}=n;if(!("elements"in e))return{value:null,errors:r};const c=(i,u,f)=>{var s,m;if(a)return;const{state:p}=n,h="minCount"in f&&(s=f.minCount)!=null?s:0,v="maxCount"in f&&(m=f.maxCount)!=null?m:1/0;f.required&&u.length===0&&r.push(`${i}: ${k("required",p)}`),u.length<h&&r.push(`${i}: ${k("minItems",p,{min:h})}`),u.length>v&&r.push(`${i}: ${k("maxItems",p,{max:v})}`)};if("multiple"in e&&e.multiple){const i=[],u=l.querySelectorAll("[data-container-item]");return Array.from(u).filter(f=>{const s=f.getAttribute("data-container-item")||"";if(!s.startsWith(`${t}[`))return!1;const m=s.slice(t.length);return/^\[\d+\]$/.test(m)}).forEach(f=>{const s={},m=(f.getAttribute("data-container-item")||"").match(/\[(\d+)\]$/),p=m?parseInt(m[1],10):0;e.elements.forEach(h=>{var v;if(h.enableIf)try{const b=(v=n.instance)!=null&&v.getState().formRoot?it(n.instance.getState().formRoot):{};if(!ke(h.enableIf,b,s))return}catch(b){console.error(`Error evaluating enableIf for field "${h.key}" in container "${t}[${p}]":`,b)}if(h.hidden||h.type==="hidden")s[h.key]=h.default!==void 0?h.default:null;else{const b=`${t}[${p}].${h.key}`,x=Pt({...h,key:b},{path:o},f);x.spread&&x.value!==null&&typeof x.value=="object"?Object.assign(s,x.value):s[h.key]=x.value}}),i.push(s)}),c(t,i,e),{value:i,errors:r}}else{const i={},u=l.querySelector(`[data-container="${t}"]`)||l;return e.elements.forEach(f=>{var s;if(f.enableIf)try{const m=(s=n.instance)!=null&&s.getState().formRoot?it(n.instance.getState().formRoot):{};if(!ke(f.enableIf,m,i))return}catch(m){console.error(`Error evaluating enableIf for field "${f.key}" in container "${t}":`,m)}if(f.hidden||f.type==="hidden")i[f.key]=f.default!==void 0?f.default:null;else{const m=`${t}.${f.key}`,p=Pt({...f,key:m},{path:o},u);p.spread&&p.value!==null&&typeof p.value=="object"?Object.assign(i,p.value):i[f.key]=p.value}}),{value:i,errors:r}}}function Kt(e,t,n,r){const{instance:l,scopeRoot:a}=r;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((c,i)=>{Re(c)&&e.elements.forEach(u=>{var f,s;const m=`${t}[${i}].${u.key}`;if(u.type==="richinput"&&u.flatOutput){const p=u,h=(f=p.textKey)!=null?f:"text",v=(s=p.filesKey)!=null?s:"files",b=c,x={};h in b&&(x[h]=b[h]),v in b&&(x[v]=b[v]),Object.keys(x).length>0&&l.updateField(m,x)}else{const p=c[u.key];p!==void 0&&l.updateField(m,p)}})});const o=a.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==o.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!Re(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(o=>{var c,i;const u=`${t}.${o.key}`;if(o.type==="richinput"&&o.flatOutput){const f=o,s=(c=f.textKey)!=null?c:"text",m=(i=f.filesKey)!=null?i:"files",p=n,h={};s in p&&(h[s]=p[s]),m in p&&(h[m]=p[m]),Object.keys(h).length>0&&l.updateField(u,h)}else{const f=n[o.key];f!==void 0&&l.updateField(u,f)}})}}function ao(e,t,n,r){var l,a;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 o={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&&Re(e.repeat)),minCount:(l=e.repeat)==null?void 0:l.min,maxCount:(a=e.repeat)==null?void 0:a.max};o.multiple?Ut(o,t,n):Ot(o,t,n,r)}function _t(e){var t,n;const r=e;return{type:"container",key:r.key,label:r.label,description:r.description,hint:r.hint,required:r.required,hidden:r.hidden,default:r.default,actions:r.actions,elements:r.elements,multiple:!!(r.repeat&&Re(r.repeat)),minCount:(t=r.repeat)==null?void 0:t.min,maxCount:(n=r.repeat)==null?void 0:n.max}}function io(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 r=_t(e);return Vt(r,t,n)}function so(e,t,n,r){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const l=_t(e);return Kt(l,t,n,r)}function co(e){return e!==null&&typeof e=="object"&&"row"in e&&"col"in e&&"rowspan"in e&&"colspan"in e}function uo(e){if(e===null||typeof e!="object")return!1;const t=e;return typeof t.top=="number"&&typeof t.left=="number"&&typeof t.bottom=="number"&&typeof t.right=="number"}function po(e){return co(e)?{top:e.row,left:e.col,bottom:e.row+e.rowspan-1,right:e.col+e.colspan-1}:uo(e)?e:null}function Se(e){return e.map(po).filter(t=>t!==null)}function Wt(e,t){return Array.from({length:e},()=>Array.from({length:t},()=>""))}function ut(e,t,n){for(let r=0;r<e.length;r++){const l=e[r];if(l.top<0||l.left<0||l.bottom>=t||l.right>=n||l.top>l.bottom||l.left>l.right)return`Merge ${r} out of bounds`;for(let a=r+1;a<e.length;a++){const o=e[a];if(l.top<=o.bottom&&l.bottom>=o.top&&l.left<=o.right&&l.right>=o.left)return`Merges ${r} and ${a} overlap`}}return null}function Jt(e,t,n){for(const r of n){if(r.top===e&&r.left===t)return null;if(e>=r.top&&e<=r.bottom&&t>=r.left&&t<=r.right)return r}return null}function Ve(e,t,n){var r;return(r=n.find(l=>l.top===e&&l.left===t))!=null?r:null}function ye(e){var t;if(!e.anchor)return null;const n=(t=e.focus)!=null?t:e.anchor;return{r1:Math.min(e.anchor.row,n.row),c1:Math.min(e.anchor.col,n.col),r2:Math.max(e.anchor.row,n.row),c2:Math.max(e.anchor.col,n.col)}}function Te(e){const t=document.createElement("button");return t.type="button",t.textContent=e.label,t.title=e.title,t.style.cssText=`
|
|
370
374
|
position: absolute;
|
|
371
375
|
width: ${e.size}px;
|
|
372
376
|
height: ${e.size}px;
|
|
@@ -386,7 +390,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
386
390
|
box-shadow: 0 1px 4px rgba(0,0,0,0.2);
|
|
387
391
|
transition: transform 0.1s, opacity 0.1s;
|
|
388
392
|
pointer-events: all;
|
|
389
|
-
`,t.addEventListener("mouseenter",()=>{t.style.transform="scale(1.15)"}),t.addEventListener("mouseleave",()=>{t.style.transform="scale(1)"}),t.addEventListener("click",n=>{n.stopPropagation(),e.onClick(n)}),t}function
|
|
393
|
+
`,t.addEventListener("mouseenter",()=>{t.style.transform="scale(1.15)"}),t.addEventListener("mouseleave",()=>{t.style.transform="scale(1)"}),t.addEventListener("click",n=>{n.stopPropagation(),e.onClick(n)}),t}function fo(e,t){const{cells:n,merges:r=[]}=e;if(n.length===0)return;const l=n[0].length,a=document.createElement("table");a.style.cssText=`
|
|
390
394
|
width: 100%;
|
|
391
395
|
border-collapse: collapse;
|
|
392
396
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
@@ -394,28 +398,28 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
394
398
|
font-size: var(--fb-font-size);
|
|
395
399
|
font-family: var(--fb-font-family);
|
|
396
400
|
color: var(--fb-text-color);
|
|
397
|
-
`,n.forEach((i
|
|
401
|
+
`,n.forEach((c,i)=>{var u,f;const s=(i===0?a.createTHead():(u=a.tBodies[0])!=null?u:a.createTBody()).insertRow();for(let m=0;m<l;m++){if(Jt(i,m,r))continue;const p=Ve(i,m,r),h=document.createElement(i===0?"th":"td");if(p){const v=p.bottom-p.top+1,b=p.right-p.left+1;v>1&&(h.rowSpan=v),b>1&&(h.colSpan=b)}h.textContent=(f=c[m])!=null?f:"",h.style.cssText=`
|
|
398
402
|
padding: 6px 10px;
|
|
399
403
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
400
404
|
text-align: left;
|
|
401
405
|
vertical-align: top;
|
|
402
|
-
${
|
|
403
|
-
`,
|
|
406
|
+
${i===0?"background-color: var(--fb-background-hover-color); font-weight: 600;":""}
|
|
407
|
+
`,s.appendChild(h)}});const o=document.createElement("div");o.style.cssText="overflow-x: auto; max-width: 100%;",o.appendChild(a),t.appendChild(o)}function mo(e,t,n,r,l,a){if(e.contentEditable==="true")return;e.contentEditable="true",e.focus();const o=document.createRange(),c=window.getSelection();o.selectNodeContents(e),o.collapse(!1),c==null||c.removeAllRanges(),c==null||c.addRange(o);function i(){var s;e.contentEditable="inherit";const m=r();m[t]&&(m[t][n]=(s=e.textContent)!=null?s:""),l()}function u(s){var m,p,h,v;const b=r(),x=(p=(m=b[0])==null?void 0:m.length)!=null?p:0;if(s.key==="Escape"){e.contentEditable="inherit",e.textContent=(v=(h=b[t])==null?void 0:h[n])!=null?v:"",e.removeEventListener("keydown",u),e.removeEventListener("blur",f);return}if(s.key==="Enter"&&!s.shiftKey){s.preventDefault(),s.stopPropagation(),i(),e.removeEventListener("keydown",u),e.removeEventListener("blur",f);const d=t+1<b.length?t+1:t;a(d,n);return}if(s.key==="Tab"){s.preventDefault(),s.stopPropagation(),i(),e.removeEventListener("keydown",u),e.removeEventListener("blur",f);let d=t,y=s.shiftKey?n-1:n+1;y<0&&(y=x-1,d=Math.max(0,t-1)),y>=x&&(y=0,d=Math.min(b.length-1,t+1)),a(d,y)}}function f(){e.contentEditable==="true"&&(i(),e.removeEventListener("keydown",u),e.removeEventListener("blur",f))}e.addEventListener("keydown",u),e.addEventListener("blur",f)}function ho(){if(document.getElementById("fb-spin-keyframes"))return;const e=document.createElement("style");e.id="fb-spin-keyframes",e.textContent="@keyframes fb-spin { to { transform: rotate(360deg); } }",document.head.appendChild(e)}function vo(e,t){ho();const n=document.createElement("div");n.className="fb-table-loading-overlay",n.style.cssText=`
|
|
404
408
|
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
|
|
405
409
|
background: rgba(255,255,255,0.8); display: flex;
|
|
406
410
|
align-items: center; justify-content: center; flex-direction: column;
|
|
407
411
|
gap: 8px; z-index: 100;
|
|
408
|
-
`;const
|
|
412
|
+
`;const r=document.createElement("div");r.style.cssText=`
|
|
409
413
|
width: 24px; height: 24px; border: 3px solid var(--fb-border-color, #ccc);
|
|
410
414
|
border-top-color: var(--fb-primary-color, #0066cc); border-radius: 50%;
|
|
411
415
|
animation: fb-spin 0.8s linear infinite;
|
|
412
|
-
`;const l=document.createElement("span");return l.textContent=t,l.style.cssText="font-size: var(--fb-font-size-small, 12px); color: var(--fb-text-color, #333);",n.appendChild(
|
|
416
|
+
`;const l=document.createElement("span");return l.textContent=t,l.style.cssText="font-size: var(--fb-font-size-small, 12px); color: var(--fb-text-color, #333);",n.appendChild(r),n.appendChild(l),e.appendChild(n),n}function go(e,t,n,r,l){var a,o,c,i,u,f,s,m;const p=r.state,h=r.instance,v=e.mergeAllowed!==!1,b=(o=(a=e.fieldNames)==null?void 0:a.cells)!=null?o:"cells",x=(i=(c=e.fieldNames)==null?void 0:c.merges)!=null?i:"merges",d=t.cells.length>0?t.cells.map(A=>[...A]):Wt((u=e.rows)!=null?u:3,(f=e.columns)!=null?f:3);let y=t.merges?[...t.merges]:[];const g={anchor:null,focus:null,dragging:!1},E=document.createElement("input");E.type="hidden",E.name=n,E.value=JSON.stringify({[b]:d,[x]:y}),l.appendChild(E);function C(){E.value=JSON.stringify({[b]:d,[x]:y}),h&&h.triggerOnChange(n,{[b]:d,[x]:y})}E._applyExternalUpdate=A=>{d.length=0,A.cells.forEach(T=>d.push([...T])),y.length=0,A.merges&&A.merges.forEach(T=>y.push({...T})),g.anchor=null,g.focus=null,C(),N()};const w=document.createElement("div");w.style.cssText="position: relative; padding: 20px 20px 20px 24px; overflow-x: auto; max-width: 100%;";const S=document.createElement("table");S.style.cssText=`
|
|
413
417
|
border-collapse: collapse;
|
|
414
418
|
font-size: var(--fb-font-size);
|
|
415
419
|
font-family: var(--fb-font-family);
|
|
416
420
|
color: var(--fb-text-color);
|
|
417
421
|
table-layout: fixed;
|
|
418
|
-
`,w.appendChild(
|
|
422
|
+
`,w.appendChild(S);const z=(m=(s=e.importAccept)==null?void 0:s.map(A=>`.${A.toLowerCase()}`))!=null?m:[];async function ne(A){var T,L,B;if(!p.config.parseTableFile)return;if(z.length>0){const F=A.name.toLowerCase().replace(/^.*(\.[^.]+)$/,"$1");if(!z.includes(F))return}const R=vo(w,k("tableImporting",p));try{const F=await p.config.parseTableFile(A),Z=F.cells,j=(T=F.merges)!=null?T:[];if(j.length>0){const O=ut(j,Z.length,(B=(L=Z[0])==null?void 0:L.length)!=null?B:0);if(O)throw new Error(O)}d.length=0,Z.forEach(O=>d.push([...O])),y.length=0,j.forEach(O=>y.push({...O})),g.anchor=null,g.focus=null,C(),N()}catch(F){const Z=F instanceof Error?F.message:String(F);console.error(k("tableImportError",p).replace("{error}",Z))}finally{R.remove()}}if(e.importAccept&&p.config.parseTableFile){const A=document.createElement("button");A.type="button",A.title=k("tableImportFile",p),A.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"/></svg>',A.style.cssText=`
|
|
419
423
|
position: absolute; top: 2px; left: 2px;
|
|
420
424
|
width: 20px; height: 20px;
|
|
421
425
|
padding: 0;
|
|
@@ -425,7 +429,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
425
429
|
background: transparent;
|
|
426
430
|
cursor: pointer;
|
|
427
431
|
z-index: 2;
|
|
428
|
-
`,
|
|
432
|
+
`,A.addEventListener("mouseenter",()=>{A.style.color="var(--fb-primary-color, #0066cc)"}),A.addEventListener("mouseleave",()=>{A.style.color="var(--fb-text-color, #999)"});const T=document.createElement("input");T.type="file",T.accept=z.join(","),T.style.display="none",w.appendChild(T),A.addEventListener("click",()=>{T.click()}),T.addEventListener("change",()=>{var B;const R=(B=T.files)==null?void 0:B[0];R&&ne(R),T.value=""}),w.appendChild(A);let L=0;w.addEventListener("dragenter",B=>{B.preventDefault(),L++,L===1&&(w.style.outline="2px dashed var(--fb-primary-color, #0066cc)",w.style.outlineOffset="-2px")}),w.addEventListener("dragover",B=>{B.preventDefault(),B.dataTransfer&&(B.dataTransfer.dropEffect="copy")}),w.addEventListener("dragleave",B=>{B.preventDefault(),L--,L<=0&&(L=0,w.style.outline="",w.style.outlineOffset="")}),w.addEventListener("drop",B=>{var R,F;B.preventDefault(),L=0,w.style.outline="",w.style.outlineOffset="";const Z=(F=(R=B.dataTransfer)==null?void 0:R.files)==null?void 0:F[0];Z&&ne(Z)})}l.appendChild(w);const P=document.createElement("div");P.style.cssText=`
|
|
429
433
|
position: fixed;
|
|
430
434
|
display: none;
|
|
431
435
|
background: white;
|
|
@@ -436,7 +440,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
436
440
|
z-index: 1000;
|
|
437
441
|
gap: 4px;
|
|
438
442
|
flex-direction: column;
|
|
439
|
-
`,l.appendChild(
|
|
443
|
+
`,l.appendChild(P);function G(A,T){const L=document.createElement("button");return L.type="button",L.textContent=A,L.style.cssText=`
|
|
440
444
|
padding: 4px 10px;
|
|
441
445
|
font-size: var(--fb-font-size-small);
|
|
442
446
|
color: var(--fb-text-color);
|
|
@@ -446,8 +450,8 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
446
450
|
cursor: pointer;
|
|
447
451
|
white-space: nowrap;
|
|
448
452
|
text-align: left;
|
|
449
|
-
`,
|
|
450
|
-
`),ie=`<table>${V.join("")}</table>`;(R=F.clipboardData)==null||R.setData("text/plain",se),(P=F.clipboardData)==null||P.setData("text/html",ie)},$.onpaste=F=>{var Z,z,R,P,J,H,Y,_,Q;const X=g.anchor;if(!X)return;const V=(z=(Z=F.clipboardData)==null?void 0:Z.getData("text/plain"))!=null?z:"",se=V.includes(" ")||V.split(/\r?\n/).filter(ce=>ce).length>1,ie=$.querySelector("[contenteditable='true']");if(ie&&!se)return;if(F.preventDefault(),ie){ie.contentEditable="inherit";const ce=parseInt((P=(R=ie.closest("td"))==null?void 0:R.getAttribute("data-row"))!=null?P:"0",10),Ce=parseInt((H=(J=ie.closest("td"))==null?void 0:J.getAttribute("data-col"))!=null?H:"0",10);u[ce]&&(u[ce][Ce]=(Y=ie.textContent)!=null?Y:"")}if(!V.trim())return;const j=V.split(/\r?\n/).map(ce=>ce.split(" "));j.length>1&&j[j.length-1].length===1&&j[j.length-1][0]===""&&j.pop();const le=X.row,ue=X.col,de=le+j.length;for(;u.length<de;)u.push(Array((Q=(_=u[0])==null?void 0:_.length)!=null?Q:1).fill(""));const me=Math.max(...j.map(ce=>ce.length)),we=ue+me;if(u[0]&&we>u[0].length){const ce=we-u[0].length;u.forEach(Ce=>{for(let Ie=0;Ie<ce;Ie++)Ce.push("")})}for(let ce=0;ce<j.length;ce++)for(let Ce=0;Ce<j[ce].length;Ce++){const Ie=le+ce,Or=ue+Ce;u[Ie]&&(u[Ie][Or]=j[ce][Ce])}E(),K()}}const oe=Te({label:"+",title:k("tableAddColumn",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var T;const A=parseInt((T=oe.dataset.afterCol)!=null?T:"0",10);I(A)}});oe.style.position="absolute",oe.style.display="none",w.appendChild(oe);const te=Te({label:"+",title:k("tableAddRow",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var T;const A=parseInt((T=te.dataset.afterRow)!=null?T:"0",10);q(A)}});te.style.position="absolute",te.style.display="none",w.appendChild(te);let ae=[],be=[];const pe=Te({label:"+",title:k("tableAddColumn",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>I()});pe.style.position="absolute",pe.style.display="none",w.appendChild(pe);const ye=Te({label:"+",title:k("tableAddRow",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>q()});ye.style.position="absolute",ye.style.display="none",w.appendChild(ye);function Je(){var T,A;ae.forEach(z=>z.remove()),ae=[],be.forEach(z=>z.remove()),be=[];const S=u.length>0?u[0].length:0,B=u.length;if(S>1){const z=Array.from($.querySelectorAll("thead td[data-col]"));for(const R of z){const P=parseInt((T=R.getAttribute("data-col"))!=null?T:"0",10),J=Te({label:"\xD7",title:k("tableRemoveColumn",f),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>O(P)});J.setAttribute("data-action","remove-col"),J.setAttribute("data-col",String(P)),J.style.position="absolute",J.style.display="none",w.appendChild(J),ae.push(J)}}if(B>1){const z=[...$.tHead?Array.from($.tHead.rows):[],...$.tBodies[0]?Array.from($.tBodies[0].rows):[]].filter(R=>R.querySelector("td[data-row]"));for(const R of z){const P=R.querySelector("td[data-row]");if(!P)continue;const J=parseInt((A=P.getAttribute("data-row"))!=null?A:"0",10),H=Te({label:"\xD7",title:k("tableRemoveRow",f),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>N(J)});H.setAttribute("data-action","remove-row"),H.setAttribute("data-row",String(J)),H.style.position="absolute",H.style.display="none",w.appendChild(H),be.push(H)}}function D(z,R,P,J,H){var Y;const _=H?Array.from($.querySelectorAll("thead td[data-col]")):[];let Q=-1,X=1/0,V=-1,se=-1,ie=1/0;for(let j=0;j<_.length;j++){const le=_[j].getBoundingClientRect(),ue=(le.left+le.right)/2,de=Math.abs(z-ue);de<X&&(X=de,Q=j);const me=Math.abs(z-le.right);me<ie&&me<20&&(ie=me,V=le.right-R.left+J,se=parseInt((Y=_[j].getAttribute("data-col"))!=null?Y:"0",10))}ae.forEach((j,le)=>{if(!H||le!==Q){j.style.display="none";return}const ue=_[le].getBoundingClientRect(),de=(ue.left+ue.right)/2-R.left+J;j.style.left=`${de-8}px`,j.style.top="2px",j.style.display="flex"}),H&&se>=0?(oe.style.display="flex",oe.style.left=`${V-10}px`,oe.style.top=`${P.top-R.top-10}px`,oe.dataset.afterCol=String(se)):oe.style.display="none"}function F(z,R,P,J,H){var Y;const _=[];if(H){if($.tHead)for(const j of Array.from($.tHead.rows))j.querySelector("td[data-row]")&&_.push(j);if($.tBodies[0])for(const j of Array.from($.tBodies[0].rows))j.querySelector("td[data-row]")&&_.push(j)}let Q=-1,X=1/0,V=-1,se=-1,ie=1/0;for(let j=0;j<_.length;j++){const le=_[j].getBoundingClientRect(),ue=(le.top+le.bottom)/2,de=Math.abs(z-ue);de<X&&(X=de,Q=j);const me=Math.abs(z-le.bottom);if(me<ie&&me<14){ie=me,V=le.bottom-R.top;const we=_[j].querySelector("td[data-row]");se=parseInt((Y=we==null?void 0:we.getAttribute("data-row"))!=null?Y:"0",10)}}be.forEach((j,le)=>{if(!H||le!==Q){j.style.display="none";return}const ue=_[le].getBoundingClientRect(),de=(ue.top+ue.bottom)/2-R.top;j.style.left="4px",j.style.top=`${de-8}px`,j.style.display="flex"}),H&&se>=0?(te.style.display="flex",te.style.top=`${V-10}px`,te.style.left=`${P.left-R.left+J-10}px`,te.dataset.afterRow=String(se)):te.style.display="none"}let Z=!1;w.onmousemove=z=>{const R=z.target;if(R.tagName==="BUTTON"&&R.parentElement===w||Z)return;Z=!0;const P=z.clientX,J=z.clientY;requestAnimationFrame(()=>{Z=!1;const H=w.getBoundingClientRect(),Y=$.getBoundingClientRect(),_=w.scrollLeft,Q=J>=H.top&&J<Y.top+4,X=P>=H.left&&P<Y.left+4,V=Math.min(Y.right,H.right),se=P>V-20&&P<=H.right,ie=J>Y.bottom-4&&J<=H.bottom+20;if(D(P,H,Y,_,Q),F(J,H,Y,_,X),pe.style.display=se?"flex":"none",se&&(pe.style.left=`${H.right-H.left+_-20}px`,pe.style.top=`${(Y.top+Y.bottom)/2-H.top-10}px`),ye.style.display=ie?"flex":"none",ie){const j=(H.left+H.right)/2-H.left+_;ye.style.left=`${j-10}px`,ye.style.top=`${Y.bottom-H.top-10}px`}})},w.onmouseleave=()=>{ae.forEach(z=>{z.style.display="none"}),be.forEach(z=>{z.style.display="none"}),oe.style.display="none",te.style.display="none",pe.style.display="none",ye.style.display="none"}}K()}function pr(e){var t,n;return{cells:Ut((t=e.rows)!=null?t:3,(n=e.columns)!=null?n:3),merges:[]}}function at(e){return e!==null&&typeof e=="object"&&"cells"in e&&Array.isArray(e.cells)}function it(e,t){return e!==null&&typeof e=="object"&&t in e&&Array.isArray(e[t])}function fr(e,t,n,o){var l,a,r,i;const s=t.state,d=t.prefill[e.key],p=(a=(l=e.fieldNames)==null?void 0:l.cells)!=null?a:"cells",c=(i=(r=e.fieldNames)==null?void 0:r.merges)!=null?i:"merges";let m;if(at(d))m={cells:d.cells,merges:d.merges?Se(d.merges):[]};else if(d&&it(d,p)){const f=d[c];m={cells:d[p],merges:f?Se(f):[]}}else if(at(e.default))m={cells:e.default.cells,merges:e.default.merges?Se(e.default.merges):[]};else if(e.default&&it(e.default,p)){const f=e.default[c];m={cells:e.default[p],merges:f?Se(f):[]}}else m=pr(e);if(m.merges&&m.merges.length>0){const f=m.cells.length,h=f>0?m.cells[0].length:0,v=lt(m.merges,f,h);v&&(console.warn(`Table "${e.key}": invalid prefill merges stripped (${v})`),m={...m,merges:[]})}s.config.readonly?ir(m,n):dr(e,m,o,t,n)}function mr(e,t,n){var o,l;const{scopeRoot:a,skipValidation:r}=n,i=[],s=(l=(o=e.fieldNames)==null?void 0:o.cells)!=null?l:"cells",d=a.querySelector(`[name="${t}"]`);if(!d)return{value:null,errors:i};let p=null;try{p=JSON.parse(d.value)}catch(c){return i.push(`${t}: invalid table data`),{value:null,errors:i}}if(!r&&e.required){const c=p[s];c!=null&&c.some(m=>m.some(f=>f.trim()!==""))||i.push(`${t}: ${k("required",n.state)}`)}return{value:p,errors:i}}function hr(e,t,n,o){var l,a,r,i;const{scopeRoot:s}=o,d=(a=(l=e.fieldNames)==null?void 0:l.cells)!=null?a:"cells",p=(i=(r=e.fieldNames)==null?void 0:r.merges)!=null?i:"merges",c=s.querySelector(`[name="${t}"]`);if(!c){console.warn(`updateTableField: no hidden input found for "${t}". Re-render to reflect new data.`);return}let m=null;if(at(n))m={cells:n.cells,merges:n.merges?Se(n.merges):[]};else if(n&&it(n,d)){const f=n[p];m={cells:n[d],merges:f?Se(f):[]}}m&&c._applyExternalUpdate?c._applyExternalUpdate(m):c.value=JSON.stringify(n)}function vr(e,t){e.style.overflow="hidden",e.style.resize="none";const n=(e.value.match(/\n/g)||[]).length+1;e.rows=Math.max(3,n);const o=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`,t&&(t.style.height=`${e.scrollHeight}px`))};e.addEventListener("input",o),setTimeout(()=>{e.isConnected&&o()},0)}function st(e,t){var n,o,l,a;const r=new Map,i=new Map;for(const s of e){const d=t.resourceIndex.get(s),p=(n=d==null?void 0:d.name)!=null?n:s;i.set(p,((o=i.get(p))!=null?o:0)+1)}for(const s of e){const d=t.resourceIndex.get(s),p=(l=d==null?void 0:d.name)!=null?l:s;((a=i.get(p))!=null?a:1)>1&&d?r.set(s,`${p} (${cn(d.size)})`):r.set(s,p)}return r}function ct(e){return e?e.type.startsWith("image/"):!1}function Vt(e,t){const n=st(e,t),o=new Map;for(const l of e){const a=n.get(l);a&&o.set(a,l)}return o}function ut(e){return/\s/.test(e)||e.includes('"')?`@"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:`@${e}`}function Ue(e){const t=[],n=e.length;let o=0;for(;o<n;)if(e[o]==="@"){if(o>0&&!/\s/.test(e[o-1])){o++;continue}const l=o;if(o++,o<n&&e[o]==='"'){o++;let a="";for(;o<n&&e[o]!=='"';)e[o]==="\\"&&o+1<n?(a+=e[o+1],o+=2):(a+=e[o],o++);o<n&&e[o]==='"'&&(o++,(o>=n||/\s/.test(e[o]))&&t.push({start:l,end:o,raw:e.slice(l,o),name:a}))}else if(o<n&&!/\s/.test(e[o])){const a=o;for(;o<n&&!/\s/.test(e[o]);)o++;const r=e.slice(a,o);t.push({start:l,end:o,raw:e.slice(l,o),name:r})}}else o++;return t}function gr(e,t){if(t.size===0)return[];const n=Ue(e),o=[];for(const l of n){const a=t.get(l.name);a&&o.push({start:l.start,end:l.end,name:l.name,rid:a})}return o}function br(e,t){const n=gr(e,t);if(n.length===0)return e;let o="",l=0;for(const a of n)o+=e.slice(l,a.start),o+=`@${a.rid}`,l=a.end;return o+=e.slice(l),o}function _t(e,t,n){const o=st(t,n),l=new Map;for(const s of t){const d=o.get(s);d&&l.set(s,d)}const a=Ue(e);if(a.length===0)return e;let r="",i=0;for(const s of a){r+=e.slice(i,s.start);const d=l.get(s.name);d?r+=ut(d):r+=s.raw,i=s.end}return r+=e.slice(i),r}function Wt(e,t,n,o){if(fe(e),n!=null&&n.file&&ct(n)){const l=document.createElement("img");l.alt=n.name,l.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;";const a=new FileReader;a.onload=r=>{var i;l.src=((i=r.target)==null?void 0:i.result)||""},a.readAsDataURL(n.file),e.appendChild(l)}else if(o.config.getThumbnail){o.config.getThumbnail(t).then(a=>{var r;if(!a||!e.isConnected)return;const i=document.createElement("img");i.alt=(r=n==null?void 0:n.name)!=null?r:t,i.src=a,i.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;",fe(e),e.appendChild(i)}).catch(a=>{var r,i;(i=(r=o.config).onThumbnailError)==null||i.call(r,a,t)});const l=document.createElement("div");l.style.cssText="width: 100%; height: 100%; background: var(--fb-background-hover-color, #f3f4f6); display: flex; align-items: center; justify-content: center;",l.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',e.appendChild(l)}else{const l=document.createElement("div");if(l.style.cssText="width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; box-sizing: border-box;",l.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',n!=null&&n.name){const a=document.createElement("span");a.style.cssText="font-size: 9px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 44px; color: var(--fb-text-color, #111827);",a.textContent=n.name,l.appendChild(a)}e.appendChild(l)}}function Kt(e,t,n,o){if(fe(e),n!=null&&n.file&&ct(n)){const l=document.createElement("img");l.alt=n.name,l.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;";const a=new FileReader;a.onload=r=>{var i;l.src=((i=r.target)==null?void 0:i.result)||""},a.readAsDataURL(n.file),e.appendChild(l)}else o.config.getThumbnail&&o.config.getThumbnail(t).then(l=>{var a;if(!l||!e.isConnected)return;const r=document.createElement("img");r.alt=(a=n==null?void 0:n.name)!=null?a:t,r.src=l,r.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;",fe(e),e.appendChild(r)}).catch(l=>{var a,r;(r=(a=o.config).onThumbnailError)==null||r.call(a,l,t)})}function Jt(e,t){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect(),l=Math.max(4,Math.min(n.left+n.width/2-o.width/2,window.innerWidth-o.width-4)),a=n.top-o.height-8,r=n.bottom+8,i=a>=4?a:r;e.style.left=`${l}px`,e.style.top=`${Math.max(4,i)}px`}function Yt(e,t,n){const o=n.resourceIndex.get(t),l=document.createElement("div");l.className="fb-richinput-portal-tooltip fb-richinput-mention-tooltip",l.style.cssText=`
|
|
453
|
+
`,L.addEventListener("mouseenter",()=>{L.style.background="var(--fb-background-hover-color)"}),L.addEventListener("mouseleave",()=>{L.style.background="transparent"}),L.addEventListener("click",()=>{ze(),T()}),L}function ve(A,T){if(!v)return;P.innerHTML="",P.style.display="flex";const L=ye(g),B=L&&(L.r1!==L.r2||L.c1!==L.c2),R=g.anchor&&Ve(g.anchor.row,g.anchor.col,y);if(B&&P.appendChild(G(k("tableMergeCells",p),q)),R&&P.appendChild(G(k("tableSplitCell",p),M)),!P.firstChild){ze();return}const F=140,Z=P.children.length*32+8,j=window.innerWidth,O=window.innerHeight,V=A+F>j?A-F:A,J=T+Z>O?T-Z:T;P.style.left=`${V}px`,P.style.top=`${J}px`}function ze(){P.style.display="none"}const Ge=new AbortController;document.addEventListener("mousedown",A=>{if(!l.isConnected){Ge.abort();return}P.contains(A.target)||ze()},{signal:Ge.signal});function fe(){const A=ye(g);S.querySelectorAll("td[data-row]").forEach(T=>{const L=parseInt(T.getAttribute("data-row")||"0",10),B=parseInt(T.getAttribute("data-col")||"0",10),R=g.anchor!==null&&g.anchor.row===L&&g.anchor.col===B,F=A!==null&&L>=A.r1&&L<=A.r2&&B>=A.c1&&B<=A.c2;T.style.outline=R?"2px solid var(--fb-primary-color, #0066cc)":"",T.style.outlineOffset=R?"-2px":"",L===0?T.style.backgroundColor="var(--fb-background-hover-color)":T.style.backgroundColor=F&&!R?"rgba(0,102,204,0.08)":""})}function Fe(A,T){g.anchor={row:A,col:T},g.focus=null,fe(),S.focus()}function He(A,T){const L=S.querySelector(`td[data-row="${A}"][data-col="${T}"]`);if(!L)return;const B=L.querySelector("span");B&&(g.anchor={row:A,col:T},g.focus=null,fe(),mo(B,A,T,()=>d,C,Fe))}function ge(A){var T;const L=d.length>0?d[0].length:(T=e.columns)!=null?T:3,B=Array(L).fill(""),R=A!==void 0?A+1:d.length;d.splice(R,0,B),y=y.map(F=>F.top>=R?{...F,top:F.top+1,bottom:F.bottom+1}:F.top<R&&F.bottom>=R?{...F,bottom:F.bottom+1}:F),C(),N()}function Ze(A){if(d.length<=1)return;const T=A!==void 0?A:g.anchor?g.anchor.row:d.length-1;y=y.map(L=>L.top===T&&L.bottom===T?null:L.top===T?{...L,bottom:L.bottom-1}:L.bottom===T?{...L,bottom:L.bottom-1}:L.top<T&&L.bottom>T?{...L,bottom:L.bottom-1}:L.top>T?{...L,top:L.top-1,bottom:L.bottom-1}:L).filter(L=>L!==null),d.splice(T,1),g.anchor&&g.anchor.row>=d.length&&(g.anchor={row:d.length-1,col:g.anchor.col}),C(),N()}function Ie(A){var T,L;const B=A!==void 0?A+1:(L=(T=d[0])==null?void 0:T.length)!=null?L:0;d.forEach(R=>R.splice(B,0,"")),y=y.map(R=>R.left>=B?{...R,left:R.left+1,right:R.right+1}:R.left<B&&R.right>=B?{...R,right:R.right+1}:R),C(),N()}function $(A){if(d.length===0||d[0].length<=1)return;const T=A!==void 0?A:g.anchor?g.anchor.col:d[0].length-1;y=y.map(L=>L.left===T&&L.right===T?null:L.left===T?{...L,right:L.right-1}:L.right===T?{...L,right:L.right-1}:L.left<T&&L.right>T?{...L,right:L.right-1}:L.left>T?{...L,left:L.left-1,right:L.right-1}:L).filter(L=>L!==null),d.forEach(L=>L.splice(T,1)),g.anchor&&g.anchor.col>=d[0].length&&(g.anchor={row:g.anchor.row,col:d[0].length-1}),C(),N()}function q(){var A,T;if(!v)return;const L=ye(g);if(!L)return;const{r1:B,c1:R,r2:F,c2:Z}=L;if(B===F&&R===Z)return;y=y.filter(D=>!(D.top<=F&&D.bottom>=B&&D.left<=Z&&D.right>=R));const j=d[B][R];for(let D=B;D<=F;D++)for(let Y=R;Y<=Z;Y++)(D!==B||Y!==R)&&(d[D][Y]="");d[B][R]=j;const O={top:B,left:R,bottom:F,right:Z},V=[...y,O],J=ut(V,d.length,(T=(A=d[0])==null?void 0:A.length)!=null?T:0);if(J){console.warn("Merge validation failed:",J);return}y.push(O),g.anchor={row:B,col:R},g.focus=null,C(),N()}function M(){if(!v||!g.anchor)return;const{row:A,col:T}=g.anchor,L=y.findIndex(B=>B.top===A&&B.left===T);L!==-1&&(y.splice(L,1),g.focus=null,C(),N())}function N(){var A,T;S.innerHTML="";const L=d.length,B=L>0?d[0].length:0,R=ye(g);for(let F=0;F<L;F++){const Z=(F===0?(A=S.tHead)!=null?A:S.createTHead():(T=S.tBodies[0])!=null?T:S.createTBody()).insertRow();for(let j=0;j<B;j++){if(Jt(F,j,y))continue;const O=Ve(F,j,y),V=document.createElement("td");if(V.setAttribute("data-row",String(F)),V.setAttribute("data-col",String(j)),O){const X=O.bottom-O.top+1,K=O.right-O.left+1;X>1&&(V.rowSpan=X),K>1&&(V.colSpan=K)}const J=R!==null&&F>=R.r1&&F<=R.r2&&j>=R.c1&&j<=R.c2,D=g.anchor!==null&&g.anchor.row===F&&g.anchor.col===j;V.style.cssText=["border: var(--fb-border-width) solid var(--fb-border-color);","padding: 4px 8px;","min-width: 80px;","vertical-align: top;","cursor: text;","position: relative;",F===0?"background-color: var(--fb-background-hover-color); font-weight: 600;":"",J&&!D?"background-color: rgba(0,102,204,0.08);":"",D?"outline: 2px solid var(--fb-primary-color, #0066cc); outline-offset: -2px;":""].join(" ");const Y=document.createElement("span");Y.textContent=d[F][j],Y.style.cssText="display: block; min-height: 1.4em; white-space: pre-wrap; word-break: break-word; outline: none;",V.appendChild(Y);const _=F,te=j;V.addEventListener("mousedown",X=>{if(X.target.tagName!=="BUTTON"&&X.target.contentEditable!=="true"){if(X.button===2){const K=ye(g);if(K&&_>=K.r1&&_<=K.r2&&te>=K.c1&&te<=K.c2)return}X.shiftKey&&g.anchor?(X.preventDefault(),g.focus={row:_,col:te},g.dragging=!1,fe()):(g.anchor={row:_,col:te},g.focus=null,g.dragging=!0,fe())}}),V.addEventListener("mouseup",X=>{if(X.target.tagName!=="BUTTON"&&g.dragging){g.dragging=!1;const K=ye(g);(!K||K.r1===K.r2&&K.c1===K.c2)&&He(_,te)}}),V.addEventListener("mousemove",X=>{if(g.dragging&&X.buttons===1){const K=g.anchor;K&&(K.row!==_||K.col!==te)&&(g.focus={row:_,col:te},fe())}}),V.addEventListener("contextmenu",X=>{if(!v)return;const K=ye(g),ie=K&&(K.r1!==K.r2||K.c1!==K.c2),ae=g.anchor&&Ve(g.anchor.row,g.anchor.col,y);(ie||ae)&&(X.preventDefault(),ve(X.clientX,X.clientY))}),Z.appendChild(V)}}ce(),S.setAttribute("tabindex","0"),S.onkeydown=F=>{var Z,j;if(S.querySelector("[contenteditable='true']"))return;const O=g.anchor;if(!O)return;const V=d.length,J=V>0?d[0].length:0,D={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]};if(D[F.key]){F.preventDefault();const[Y,_]=D[F.key],te=Math.max(0,Math.min(V-1,O.row+Y)),X=Math.max(0,Math.min(J-1,O.col+_));F.shiftKey?(g.focus={row:te,col:X},fe()):Fe(te,X);return}if(F.key==="Enter"){F.preventDefault(),He(O.row,O.col);return}if(F.key==="Tab"){F.preventDefault();const Y=(j=(Z=d[0])==null?void 0:Z.length)!=null?j:0;let _=O.row,te=F.shiftKey?O.col-1:O.col+1;te<0&&(te=Y-1,_=Math.max(0,_-1)),te>=Y&&(te=0,_=Math.min(d.length-1,_+1)),Fe(_,te);return}if(v&&F.key==="m"&&F.ctrlKey&&!F.shiftKey){F.preventDefault(),q();return}v&&F.key==="M"&&F.ctrlKey&&F.shiftKey&&(F.preventDefault(),M())},S.oncopy=F=>{var Z,j,O,V;const J=ye(g);if(!J)return;F.preventDefault();const{r1:D,c1:Y,r2:_,c2:te}=J,X=[],K=[];for(let U=D;U<=_;U++){const le=[],ue=[];for(let de=Y;de<=te;de++){const me=(j=(Z=d[U])==null?void 0:Z[de])!=null?j:"";le.push(me);const Ce=me.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");ue.push(`<td>${Ce}</td>`)}X.push(le.join(" ")),K.push(`<tr>${ue.join("")}</tr>`)}const ie=X.join(`
|
|
454
|
+
`),ae=`<table>${K.join("")}</table>`;(O=F.clipboardData)==null||O.setData("text/plain",ie),(V=F.clipboardData)==null||V.setData("text/html",ae)},S.onpaste=F=>{var Z,j,O,V,J,D,Y,_,te;const X=g.anchor;if(!X)return;const K=(j=(Z=F.clipboardData)==null?void 0:Z.getData("text/plain"))!=null?j:"",ie=K.includes(" ")||K.split(/\r?\n/).filter(se=>se).length>1,ae=S.querySelector("[contenteditable='true']");if(ae&&!ie)return;if(F.preventDefault(),ae){ae.contentEditable="inherit";const se=parseInt((V=(O=ae.closest("td"))==null?void 0:O.getAttribute("data-row"))!=null?V:"0",10),xe=parseInt((D=(J=ae.closest("td"))==null?void 0:J.getAttribute("data-col"))!=null?D:"0",10);d[se]&&(d[se][xe]=(Y=ae.textContent)!=null?Y:"")}if(!K.trim())return;const U=K.split(/\r?\n/).map(se=>se.split(" "));U.length>1&&U[U.length-1].length===1&&U[U.length-1][0]===""&&U.pop();const le=X.row,ue=X.col,de=le+U.length;for(;d.length<de;)d.push(Array((te=(_=d[0])==null?void 0:_.length)!=null?te:1).fill(""));const me=Math.max(...U.map(se=>se.length)),Ce=ue+me;if(d[0]&&Ce>d[0].length){const se=Ce-d[0].length;d.forEach(xe=>{for(let Be=0;Be<se;Be++)xe.push("")})}for(let se=0;se<U.length;se++)for(let xe=0;xe<U[se].length;xe++){const Be=le+se,Wo=ue+xe;d[Be]&&(d[Be][Wo]=U[se][xe])}C(),N()}}const H=Te({label:"+",title:k("tableAddColumn",p),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var A;const T=parseInt((A=H.dataset.afterCol)!=null?A:"0",10);Ie(T)}});H.style.position="absolute",H.style.display="none",w.appendChild(H);const I=Te({label:"+",title:k("tableAddRow",p),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var A;const T=parseInt((A=I.dataset.afterRow)!=null?A:"0",10);ge(T)}});I.style.position="absolute",I.style.display="none",w.appendChild(I);let Q=[],ee=[];const re=Te({label:"+",title:k("tableAddColumn",p),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>Ie()});re.style.position="absolute",re.style.display="none",w.appendChild(re);const oe=Te({label:"+",title:k("tableAddRow",p),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>ge()});oe.style.position="absolute",oe.style.display="none",w.appendChild(oe);function ce(){var A,T;Q.forEach(j=>j.remove()),Q=[],ee.forEach(j=>j.remove()),ee=[];const L=d.length>0?d[0].length:0,B=d.length;if(L>1){const j=Array.from(S.querySelectorAll("thead td[data-col]"));for(const O of j){const V=parseInt((A=O.getAttribute("data-col"))!=null?A:"0",10),J=Te({label:"\xD7",title:k("tableRemoveColumn",p),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>$(V)});J.setAttribute("data-action","remove-col"),J.setAttribute("data-col",String(V)),J.style.position="absolute",J.style.display="none",w.appendChild(J),Q.push(J)}}if(B>1){const j=[...S.tHead?Array.from(S.tHead.rows):[],...S.tBodies[0]?Array.from(S.tBodies[0].rows):[]].filter(O=>O.querySelector("td[data-row]"));for(const O of j){const V=O.querySelector("td[data-row]");if(!V)continue;const J=parseInt((T=V.getAttribute("data-row"))!=null?T:"0",10),D=Te({label:"\xD7",title:k("tableRemoveRow",p),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>Ze(J)});D.setAttribute("data-action","remove-row"),D.setAttribute("data-row",String(J)),D.style.position="absolute",D.style.display="none",w.appendChild(D),ee.push(D)}}function R(j,O,V,J,D){var Y;const _=D?Array.from(S.querySelectorAll("thead td[data-col]")):[];let te=-1,X=1/0,K=-1,ie=-1,ae=1/0;for(let U=0;U<_.length;U++){const le=_[U].getBoundingClientRect(),ue=(le.left+le.right)/2,de=Math.abs(j-ue);de<X&&(X=de,te=U);const me=Math.abs(j-le.right);me<ae&&me<20&&(ae=me,K=le.right-O.left+J,ie=parseInt((Y=_[U].getAttribute("data-col"))!=null?Y:"0",10))}Q.forEach((U,le)=>{if(!D||le!==te){U.style.display="none";return}const ue=_[le].getBoundingClientRect(),de=(ue.left+ue.right)/2-O.left+J;U.style.left=`${de-8}px`,U.style.top="2px",U.style.display="flex"}),D&&ie>=0?(H.style.display="flex",H.style.left=`${K-10}px`,H.style.top=`${V.top-O.top-10}px`,H.dataset.afterCol=String(ie)):H.style.display="none"}function F(j,O,V,J,D){var Y;const _=[];if(D){if(S.tHead)for(const U of Array.from(S.tHead.rows))U.querySelector("td[data-row]")&&_.push(U);if(S.tBodies[0])for(const U of Array.from(S.tBodies[0].rows))U.querySelector("td[data-row]")&&_.push(U)}let te=-1,X=1/0,K=-1,ie=-1,ae=1/0;for(let U=0;U<_.length;U++){const le=_[U].getBoundingClientRect(),ue=(le.top+le.bottom)/2,de=Math.abs(j-ue);de<X&&(X=de,te=U);const me=Math.abs(j-le.bottom);if(me<ae&&me<14){ae=me,K=le.bottom-O.top;const Ce=_[U].querySelector("td[data-row]");ie=parseInt((Y=Ce==null?void 0:Ce.getAttribute("data-row"))!=null?Y:"0",10)}}ee.forEach((U,le)=>{if(!D||le!==te){U.style.display="none";return}const ue=_[le].getBoundingClientRect(),de=(ue.top+ue.bottom)/2-O.top;U.style.left="4px",U.style.top=`${de-8}px`,U.style.display="flex"}),D&&ie>=0?(I.style.display="flex",I.style.top=`${K-10}px`,I.style.left=`${V.left-O.left+J-10}px`,I.dataset.afterRow=String(ie)):I.style.display="none"}let Z=!1;w.onmousemove=j=>{const O=j.target;if(O.tagName==="BUTTON"&&O.parentElement===w||Z)return;Z=!0;const V=j.clientX,J=j.clientY;requestAnimationFrame(()=>{Z=!1;const D=w.getBoundingClientRect(),Y=S.getBoundingClientRect(),_=w.scrollLeft,te=J>=D.top&&J<Y.top+4,X=V>=D.left&&V<Y.left+4,K=Math.min(Y.right,D.right),ie=V>K-20&&V<=D.right,ae=J>Y.bottom-4&&J<=D.bottom+20;if(R(V,D,Y,_,te),F(J,D,Y,_,X),re.style.display=ie?"flex":"none",ie&&(re.style.left=`${D.right-D.left+_-20}px`,re.style.top=`${(Y.top+Y.bottom)/2-D.top-10}px`),oe.style.display=ae?"flex":"none",ae){const U=(D.left+D.right)/2-D.left+_;oe.style.left=`${U-10}px`,oe.style.top=`${Y.bottom-D.top-10}px`}})},w.onmouseleave=()=>{Q.forEach(j=>{j.style.display="none"}),ee.forEach(j=>{j.style.display="none"}),H.style.display="none",I.style.display="none",re.style.display="none",oe.style.display="none"}}N()}function bo(e){var t,n;return{cells:Wt((t=e.rows)!=null?t:3,(n=e.columns)!=null?n:3),merges:[]}}function dt(e){return e!==null&&typeof e=="object"&&"cells"in e&&Array.isArray(e.cells)}function pt(e,t){return e!==null&&typeof e=="object"&&t in e&&Array.isArray(e[t])}function yo(e,t,n,r){var l,a,o,c;const i=t.state,u=t.prefill[e.key],f=(a=(l=e.fieldNames)==null?void 0:l.cells)!=null?a:"cells",s=(c=(o=e.fieldNames)==null?void 0:o.merges)!=null?c:"merges";let m;if(dt(u))m={cells:u.cells,merges:u.merges?Se(u.merges):[]};else if(u&&pt(u,f)){const p=u[s];m={cells:u[f],merges:p?Se(p):[]}}else if(dt(e.default))m={cells:e.default.cells,merges:e.default.merges?Se(e.default.merges):[]};else if(e.default&&pt(e.default,f)){const p=e.default[s];m={cells:e.default[f],merges:p?Se(p):[]}}else m=bo(e);if(m.merges&&m.merges.length>0){const p=m.cells.length,h=p>0?m.cells[0].length:0,v=ut(m.merges,p,h);v&&(console.warn(`Table "${e.key}": invalid prefill merges stripped (${v})`),m={...m,merges:[]})}i.config.readonly?fo(m,n):go(e,m,r,t,n)}function xo(e,t,n){var r,l;const{scopeRoot:a,skipValidation:o}=n,c=[],i=(l=(r=e.fieldNames)==null?void 0:r.cells)!=null?l:"cells",u=a.querySelector(`[name="${t}"]`);if(!u)return{value:null,errors:c};let f=null;try{f=JSON.parse(u.value)}catch(s){return c.push(`${t}: invalid table data`),{value:null,errors:c}}if(!o&&e.required){const s=f[i];s!=null&&s.some(m=>m.some(p=>p.trim()!==""))||c.push(`${t}: ${k("required",n.state)}`)}return{value:f,errors:c}}function Eo(e,t,n,r){var l,a,o,c;const{scopeRoot:i}=r,u=(a=(l=e.fieldNames)==null?void 0:l.cells)!=null?a:"cells",f=(c=(o=e.fieldNames)==null?void 0:o.merges)!=null?c:"merges",s=i.querySelector(`[name="${t}"]`);if(!s){console.warn(`updateTableField: no hidden input found for "${t}". Re-render to reflect new data.`);return}let m=null;if(dt(n))m={cells:n.cells,merges:n.merges?Se(n.merges):[]};else if(n&&pt(n,u)){const p=n[f];m={cells:n[u],merges:p?Se(p):[]}}m&&s._applyExternalUpdate?s._applyExternalUpdate(m):s.value=JSON.stringify(n)}function Co(e,t){e.style.overflow="hidden",e.style.resize="none";const n=(e.value.match(/\n/g)||[]).length+1;e.rows=Math.max(3,n);const r=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`,t&&(t.style.height=`${e.scrollHeight}px`))};e.addEventListener("input",r),setTimeout(()=>{e.isConnected&&r()},0)}function ft(e,t){var n,r,l,a;const o=new Map,c=new Map;for(const i of e){const u=t.resourceIndex.get(i),f=(n=u==null?void 0:u.name)!=null?n:i;c.set(f,((r=c.get(f))!=null?r:0)+1)}for(const i of e){const u=t.resourceIndex.get(i),f=(l=u==null?void 0:u.name)!=null?l:i;((a=c.get(f))!=null?a:1)>1&&u?o.set(i,`${f} (${mn(u.size)})`):o.set(i,f)}return o}function mt(e){return e?e.type.startsWith("image/"):!1}function Yt(e,t){const n=ft(e,t),r=new Map;for(const l of e){const a=n.get(l);a&&r.set(a,l)}return r}function ht(e){return/\s/.test(e)||e.includes('"')?`@"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:`@${e}`}function Ke(e){const t=[],n=e.length;let r=0;for(;r<n;)if(e[r]==="@"){if(r>0&&!/\s/.test(e[r-1])){r++;continue}const l=r;if(r++,r<n&&e[r]==='"'){r++;let a="";for(;r<n&&e[r]!=='"';)e[r]==="\\"&&r+1<n?(a+=e[r+1],r+=2):(a+=e[r],r++);r<n&&e[r]==='"'&&(r++,(r>=n||/\s/.test(e[r]))&&t.push({start:l,end:r,raw:e.slice(l,r),name:a}))}else if(r<n&&!/\s/.test(e[r])){const a=r;for(;r<n&&!/\s/.test(e[r]);)r++;const o=e.slice(a,r);t.push({start:l,end:r,raw:e.slice(l,r),name:o})}}else r++;return t}function wo(e,t){if(t.size===0)return[];const n=Ke(e),r=[];for(const l of n){const a=t.get(l.name);a&&r.push({start:l.start,end:l.end,name:l.name,rid:a})}return r}function ko(e,t){const n=wo(e,t);if(n.length===0)return e;let r="",l=0;for(const a of n)r+=e.slice(l,a.start),r+=`@${a.rid}`,l=a.end;return r+=e.slice(l),r}function Xt(e,t,n){const r=ft(t,n),l=new Map;for(const i of t){const u=r.get(i);u&&l.set(i,u)}const a=Ke(e);if(a.length===0)return e;let o="",c=0;for(const i of a){o+=e.slice(c,i.start);const u=l.get(i.name);u?o+=ht(u):o+=i.raw,c=i.end}return o+=e.slice(c),o}function Gt(e,t,n,r){if(pe(e),n!=null&&n.file&&mt(n)){const l=document.createElement("img");l.alt=n.name,l.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;";const a=new FileReader;a.onload=o=>{var c;l.src=((c=o.target)==null?void 0:c.result)||""},a.readAsDataURL(n.file),e.appendChild(l)}else if(r.config.getThumbnail){r.config.getThumbnail(t).then(a=>{var o;if(!a||!e.isConnected)return;const c=document.createElement("img");c.alt=(o=n==null?void 0:n.name)!=null?o:t,c.src=a,c.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;",pe(e),e.appendChild(c)}).catch(a=>{var o,c;(c=(o=r.config).onThumbnailError)==null||c.call(o,a,t)});const l=document.createElement("div");l.style.cssText="width: 100%; height: 100%; background: var(--fb-background-hover-color, #f3f4f6); display: flex; align-items: center; justify-content: center;",l.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',e.appendChild(l)}else{const l=document.createElement("div");if(l.style.cssText="width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; box-sizing: border-box;",l.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',n!=null&&n.name){const a=document.createElement("span");a.style.cssText="font-size: 9px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 44px; color: var(--fb-text-color, #111827);",a.textContent=n.name,l.appendChild(a)}e.appendChild(l)}}function Zt(e,t,n,r){if(pe(e),n!=null&&n.file&&mt(n)){const l=document.createElement("img");l.alt=n.name,l.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;";const a=new FileReader;a.onload=o=>{var c;l.src=((c=o.target)==null?void 0:c.result)||""},a.readAsDataURL(n.file),e.appendChild(l)}else r.config.getThumbnail&&r.config.getThumbnail(t).then(l=>{var a;if(!l||!e.isConnected)return;const o=document.createElement("img");o.alt=(a=n==null?void 0:n.name)!=null?a:t,o.src=l,o.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;",pe(e),e.appendChild(o)}).catch(l=>{var a,o;(o=(a=r.config).onThumbnailError)==null||o.call(a,l,t)})}function Qt(e,t){const n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),l=Math.max(4,Math.min(n.left+n.width/2-r.width/2,window.innerWidth-r.width-4)),a=n.top-r.height-8,o=n.bottom+8,c=a>=4?a:o;e.style.left=`${l}px`,e.style.top=`${Math.max(4,c)}px`}function en(e,t,n){const r=n.resourceIndex.get(t),l=document.createElement("div");l.className="fb-richinput-portal-tooltip fb-richinput-mention-tooltip",l.style.cssText=`
|
|
451
455
|
position: fixed;
|
|
452
456
|
z-index: 99999;
|
|
453
457
|
background: #fff;
|
|
@@ -458,7 +462,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
458
462
|
pointer-events: none;
|
|
459
463
|
min-width: 60px;
|
|
460
464
|
max-width: 140px;
|
|
461
|
-
`;const a=document.createElement("div");return a.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",
|
|
465
|
+
`;const a=document.createElement("div");return a.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",Zt(a,t,r,n),l.appendChild(a),document.body.appendChild(l),Qt(l,e),l}function tn(e,t){var n,r;const{rid:l,state:a,isReadonly:o,onMention:c,onRemove:i}=t,u=a.resourceIndex.get(l),f=(n=u==null?void 0:u.name)!=null?n:l,s=document.createElement("div");s.className="fb-richinput-portal-tooltip fb-richinput-file-tooltip",s.style.cssText=`
|
|
462
466
|
position: fixed;
|
|
463
467
|
z-index: 99999;
|
|
464
468
|
background: #fff;
|
|
@@ -469,17 +473,17 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
469
473
|
pointer-events: auto;
|
|
470
474
|
min-width: 80px;
|
|
471
475
|
max-width: 260px;
|
|
472
|
-
`;const m=document.createElement("div");m.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",
|
|
476
|
+
`;const m=document.createElement("div");m.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",Zt(m,l,u,a),s.appendChild(m);const p=document.createElement("div");p.style.cssText="padding: 4px 6px 2px; font-size: 12px; color: var(--fb-text-color, #111827); word-break: break-word; border-top: 1px solid var(--fb-border-color, #d1d5db);",p.textContent=f,s.appendChild(p);const h=document.createElement("div");h.style.cssText="display: flex; align-items: center; gap: 2px; padding: 3px 4px 2px; border-top: 1px solid var(--fb-border-color, #d1d5db); justify-content: center;";const v="background: none; border: none; cursor: pointer; padding: 3px 5px; border-radius: 4px; color: var(--fb-text-muted-color, #6b7280); display: flex; align-items: center; transition: background 0.1s, color 0.1s;",b=d=>{d.style.background="var(--fb-background-hover-color, #f3f4f6)",d.style.color="var(--fb-text-color, #111827)"},x=d=>{d.style.background="none",d.style.color="var(--fb-text-muted-color, #6b7280)"};if(!o&&c){const d=document.createElement("button");d.type="button",d.title="Mention",d.style.cssText=v,d.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="4"/><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"/></svg>',d.addEventListener("mouseenter",()=>b(d)),d.addEventListener("mouseleave",()=>x(d)),d.addEventListener("click",y=>{y.stopPropagation(),c(),s.remove()}),h.appendChild(d)}if(a.config.downloadFile){const d=document.createElement("button");d.type="button",d.title="Download",d.style.cssText=v,d.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',d.addEventListener("mouseenter",()=>b(d)),d.addEventListener("mouseleave",()=>x(d)),d.addEventListener("click",y=>{var g,E;y.stopPropagation(),(E=(g=a.config).downloadFile)==null||E.call(g,l,f)}),h.appendChild(d)}if((r=a.config.getDownloadUrl)!=null?r:a.config.getThumbnail){const d=document.createElement("button");d.type="button",d.title="Open in new window",d.style.cssText=v,d.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',d.addEventListener("mouseenter",()=>b(d)),d.addEventListener("mouseleave",()=>x(d)),d.addEventListener("click",y=>{var g,E,C,w;if(y.stopPropagation(),a.config.getDownloadUrl){const S=a.config.getDownloadUrl(l);S?window.open(S,"_blank"):(E=(g=a.config).getThumbnail)==null||E.call(g,l).then(z=>{z&&window.open(z,"_blank")}).catch(()=>{})}else(w=(C=a.config).getThumbnail)==null||w.call(C,l).then(S=>{S&&window.open(S,"_blank")}).catch(()=>{})}),h.appendChild(d)}if(!o&&i){const d=document.createElement("button");d.type="button",d.title="Remove",d.style.cssText=v,d.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>',d.addEventListener("mouseenter",()=>{d.style.background="var(--fb-background-hover-color, #f3f4f6)",d.style.color="var(--fb-error-color, #ef4444)"}),d.addEventListener("mouseleave",()=>x(d)),d.addEventListener("click",y=>{y.stopPropagation(),s.remove(),i()}),h.appendChild(d)}return h.children.length>0&&s.appendChild(h),document.body.appendChild(s),Qt(s,e),s}function nn(){return{element:null,hideTimer:null}}function _e(e,t=150){e.hideTimer===null&&(e.hideTimer=setTimeout(()=>{e.hideTimer=null,e.element&&(e.element.remove(),e.element=null)},t))}function We(e){e.hideTimer!==null&&(clearTimeout(e.hideTimer),e.hideTimer=null)}function Ae(e){return e&&e.remove(),null}function $o(e){var t;const n=(t=e.selectionStart)!=null?t:0,r=e.value.slice(0,n);for(let l=r.length-1;l>=0;l--)if(r[l]==="@"){if(l===0||/\s/.test(r[l-1])){let a=r.slice(l+1);return a.startsWith('"')&&(a=a.slice(1)),{query:a,pos:l}}return null}return null}function on(e,t,n){const r=e.toLowerCase();return t.filter(l=>{var a;return((a=n.get(l))!=null?a:l).toLowerCase().includes(r)})}const Je="font-size: var(--fb-font-size, 14px); font-family: var(--fb-font-family, inherit); line-height: 1.6;",rn="padding: 12px 52px 12px 14px;";function Lo(e,t,n,r,l){var a;const o=t.state,c=[...l.files],i={open:!1,query:"",triggerPos:-1,selectedIndex:0},u=new AbortController,f=document.createElement("input");f.type="hidden",f.name=r;function s(){var $,q;const M=w.value,N=Yt(c,o),H=M?ko(M,N):null,I=($=e.textKey)!=null?$:"text",Q=(q=e.filesKey)!=null?q:"files";return{[I]:M===""?null:H,[Q]:[...c]}}function m(){f.value=JSON.stringify(s())}const p=document.createElement("div");p.className="fb-richinput-wrapper",p.style.cssText=`
|
|
473
477
|
position: relative;
|
|
474
478
|
border: 1px solid var(--fb-border-color, #d1d5db);
|
|
475
479
|
border-radius: 16px;
|
|
476
480
|
background: var(--fb-background-color, #f9fafb);
|
|
477
481
|
transition: box-shadow 0.15s, border-color 0.15s;
|
|
478
|
-
`,
|
|
482
|
+
`,p.addEventListener("focusin",()=>{p.style.borderColor="var(--fb-primary-color, #0066cc)",p.style.boxShadow="0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 25%, transparent)"}),p.addEventListener("focusout",()=>{p.style.borderColor="var(--fb-border-color, #d1d5db)",p.style.boxShadow="none"});const h=document.createElement("div");h.className="fb-richinput-error",h.style.cssText="display: none; color: var(--fb-error-color, #ef4444); font-size: var(--fb-font-size-small, 12px); padding: 4px 14px 8px;";let v=null;function b($){h.textContent=$,h.style.display="block",v&&clearTimeout(v),v=setTimeout(()=>{h.style.display="none",h.textContent="",v=null},5e3)}function x($){var q;const M=Me(e.accept);if(!Ee($.name,M)){const H=M.join(", ");return b(k("invalidFileExtension",o,{name:$.name,formats:H})),!1}const N=(q=e.maxSize)!=null?q:1/0;return $e($,N)?!0:(b(k("fileTooLarge",o,{name:$.name,maxSize:N})),!1)}let d=0;p.addEventListener("dragenter",$=>{$.preventDefault(),d++,p.style.borderColor="var(--fb-primary-color, #0066cc)",p.style.boxShadow="0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 25%, transparent)"}),p.addEventListener("dragover",$=>{$.preventDefault()}),p.addEventListener("dragleave",$=>{$.preventDefault(),d--,d<=0&&(d=0,p.style.borderColor="var(--fb-border-color, #d1d5db)",p.style.boxShadow="none")}),p.addEventListener("drop",$=>{var q,M;$.preventDefault(),d=0,p.style.borderColor="var(--fb-border-color, #d1d5db)",p.style.boxShadow="none";const N=(q=$.dataTransfer)==null?void 0:q.files;if(!N||!o.config.uploadFile)return;const H=(M=e.maxFiles)!=null?M:1/0;for(let I=0;I<N.length;I++){if(c.length>=H){b(k("filesLimitExceeded",o,{skipped:N.length-I,max:H}));break}x(N[I])&&Ze(N[I])}});const y=document.createElement("div");y.className="fb-richinput-files",y.style.cssText="display: none; flex-wrap: wrap; gap: 6px; padding: 10px 14px 0; align-items: center;";const g=document.createElement("input");g.type="file",g.multiple=!0,g.style.display="none",e.accept&&(typeof e.accept=="string"?g.accept=e.accept:g.accept=e.accept.extensions.map($=>$.startsWith(".")?$:`.${$}`).join(","));const E=document.createElement("div");E.style.cssText="position: relative;";const C=document.createElement("div");C.className="fb-richinput-backdrop",C.style.cssText=`
|
|
479
483
|
position: absolute;
|
|
480
484
|
top: 0; left: 0; right: 0; bottom: 0;
|
|
481
|
-
${
|
|
482
|
-
${
|
|
485
|
+
${rn}
|
|
486
|
+
${Je}
|
|
483
487
|
white-space: pre-wrap;
|
|
484
488
|
word-break: break-word;
|
|
485
489
|
color: transparent;
|
|
@@ -488,10 +492,10 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
488
492
|
border-radius: inherit;
|
|
489
493
|
box-sizing: border-box;
|
|
490
494
|
z-index: 2;
|
|
491
|
-
`;const
|
|
495
|
+
`;const w=document.createElement("textarea");w.name=`${r}__text`,w.placeholder=e.placeholder||k("richinputPlaceholder",o);const S=(a=l.text)!=null?a:"";w.value=S?Xt(S,c,o):"",w.style.cssText=`
|
|
492
496
|
width: 100%;
|
|
493
|
-
${
|
|
494
|
-
${
|
|
497
|
+
${rn}
|
|
498
|
+
${Je}
|
|
495
499
|
background: transparent;
|
|
496
500
|
border: none;
|
|
497
501
|
outline: none;
|
|
@@ -501,9 +505,9 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
501
505
|
position: relative;
|
|
502
506
|
z-index: 1;
|
|
503
507
|
caret-color: var(--fb-text-color, #111827);
|
|
504
|
-
`,
|
|
505
|
-
`;return}let
|
|
506
|
-
`}const
|
|
508
|
+
`,Co(w,C),w.addEventListener("scroll",()=>{C.scrollTop=w.scrollTop});let z=null;C.addEventListener("mouseover",$=>{var q,M;const N=(M=(q=$.target).closest)==null?void 0:M.call(q,"mark");N!=null&&N.dataset.rid&&(z=Ae(z),z=en(N,N.dataset.rid,o))}),C.addEventListener("mouseout",$=>{var q,M,N;if(!((M=(q=$.target).closest)!=null&&M.call(q,"mark")))return;const H=$.relatedTarget;(N=H==null?void 0:H.closest)!=null&&N.call(H,"mark")||(z=Ae(z))}),C.addEventListener("mousedown",$=>{var q,M;if(!((M=(q=$.target).closest)!=null&&M.call(q,"mark")))return;z=Ae(z);const N=C.querySelectorAll("mark");N.forEach(I=>I.style.pointerEvents="none");const H=document.elementFromPoint($.clientX,$.clientY);H&&H.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window,clientX:$.clientX,clientY:$.clientY,button:$.button,buttons:$.buttons,detail:$.detail})),document.addEventListener("mouseup",()=>{N.forEach(I=>I.style.pointerEvents="auto")},{once:!0})});function ne(){const $=w.value,q=Yt(c,o),M=Ke($);if(M.length===0){C.innerHTML=W($)+`
|
|
509
|
+
`;return}let N="",H=0;for(const I of M){N+=W($.slice(H,I.start));const Q=q.get(I.name);Q?N+=`<mark data-rid="${W(Q)}" style="background: color-mix(in srgb, var(--fb-primary-color, #0066cc) 15%, transparent); color: transparent; border-radius: 8px; padding: 0; border: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 15%, transparent), 0 0 0 3px color-mix(in srgb, var(--fb-primary-color, #0066cc) 30%, transparent); box-decoration-break: clone; -webkit-box-decoration-break: clone; pointer-events: auto; cursor: text;">${W($.slice(I.start,I.end))}</mark>`:N+=`<mark style="color: transparent; background: none; padding: 0; border: none; text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: rgba(239, 68, 68, 0.45); text-underline-offset: 2px;">${W($.slice(I.start,I.end))}</mark>`,H=I.end}N+=W($.slice(H)),C.innerHTML=N+`
|
|
510
|
+
`}const P=document.createElement("button");P.type="button",P.title=k("richinputAttachFile",o),P.style.cssText=`
|
|
507
511
|
position: absolute;
|
|
508
512
|
right: 10px;
|
|
509
513
|
bottom: 10px;
|
|
@@ -519,7 +523,7 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
519
523
|
justify-content: center;
|
|
520
524
|
color: var(--fb-text-muted-color, #9ca3af);
|
|
521
525
|
transition: color 0.15s, background 0.15s;
|
|
522
|
-
`,
|
|
526
|
+
`,P.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>',P.addEventListener("mouseenter",()=>{P.style.color="var(--fb-primary-color, #0066cc)",P.style.background="var(--fb-background-hover-color, #f3f4f6)"}),P.addEventListener("mouseleave",()=>{P.style.color="var(--fb-text-muted-color, #9ca3af)",P.style.background="transparent"}),P.addEventListener("click",()=>{var $;const q=($=e.maxFiles)!=null?$:1/0;if(c.length>=q){b(k("filesLimitExceeded",o,{skipped:1,max:q}));return}g.click()});const G=document.createElement("div");G.className="fb-richinput-dropdown",G.style.cssText=`
|
|
523
527
|
display: none;
|
|
524
528
|
position: absolute;
|
|
525
529
|
bottom: 100%;
|
|
@@ -534,16 +538,16 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
534
538
|
max-height: 200px;
|
|
535
539
|
overflow-y: auto;
|
|
536
540
|
margin-bottom: 4px;
|
|
537
|
-
${
|
|
538
|
-
`;function
|
|
541
|
+
${Je}
|
|
542
|
+
`;function ve(){return ft(c,o)}function ze($){pe(G);const q=ve();if($.length===0){G.style.display="none",i.open=!1;return}$.forEach((M,N)=>{var H;const I=o.resourceIndex.get(M),Q=document.createElement("div");Q.className="fb-richinput-dropdown-item",Q.dataset.rid=M,Q.style.cssText=`
|
|
539
543
|
padding: 5px 10px;
|
|
540
544
|
cursor: pointer;
|
|
541
545
|
color: var(--fb-text-color, #111827);
|
|
542
|
-
background: ${
|
|
546
|
+
background: ${N===i.selectedIndex?"var(--fb-background-hover-color, #f3f4f6)":"transparent"};
|
|
543
547
|
display: flex;
|
|
544
548
|
align-items: center;
|
|
545
549
|
gap: 8px;
|
|
546
|
-
`;const
|
|
550
|
+
`;const ee=document.createElement("div");if(ee.style.cssText="width: 24px; height: 24px; border-radius: 4px; overflow: hidden; flex-shrink: 0; background: var(--fb-background-hover-color, #f3f4f6); display: flex; align-items: center; justify-content: center;",I!=null&&I.file&&mt(I)){const oe=document.createElement("img");oe.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;";const ce=new FileReader;ce.onload=A=>{var T;oe.src=((T=A.target)==null?void 0:T.result)||""},ce.readAsDataURL(I.file),ee.appendChild(oe)}else o.config.getThumbnail&&o.config.getThumbnail(M).then(oe=>{if(!oe||!ee.isConnected)return;const ce=document.createElement("img");ce.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;",ce.src=oe,pe(ee),ee.appendChild(ce)}).catch(()=>{}),ee.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>';Q.appendChild(ee);const re=document.createElement("span");re.style.cssText="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;",re.textContent=(H=q.get(M))!=null?H:M,Q.appendChild(re),G.appendChild(Q)}),G.onmousemove=M=>{var N,H,I;const Q=(H=(N=M.target).closest)==null?void 0:H.call(N,".fb-richinput-dropdown-item");if(!Q)return;const ee=$.indexOf((I=Q.dataset.rid)!=null?I:"");ee===-1||ee===i.selectedIndex||(G.querySelectorAll(".fb-richinput-dropdown-item").forEach((re,oe)=>{re.style.background=oe===ee?"var(--fb-background-hover-color, #f3f4f6)":"transparent"}),i.selectedIndex=ee)},G.onmousedown=M=>{var N,H;M.preventDefault(),M.stopPropagation();const I=(H=(N=M.target).closest)==null?void 0:H.call(N,".fb-richinput-dropdown-item");I!=null&&I.dataset.rid&&Fe(I.dataset.rid)},G.style.display="block",i.open=!0}function Ge(){const $=$o(w);if(!$){fe();return}i.query=$.query,i.triggerPos=$.pos,i.selectedIndex=0;const q=ve(),M=on($.query,c,q);ze(M)}function fe(){G.style.display="none",i.open=!1}function Fe($){var q,M,N,H;const I=(N=(M=ve().get($))!=null?M:(q=o.resourceIndex.get($))==null?void 0:q.name)!=null?N:$,Q=(H=w.selectionStart)!=null?H:0,ee=w.value.slice(0,i.triggerPos),re=w.value.slice(Q),oe=`${ht(I)} `;w.value=`${ee}${oe}${re}`;const ce=ee.length+oe.length;w.setSelectionRange(ce,ce),w.dispatchEvent(new Event("input")),fe()}w.addEventListener("input",()=>{var $;ne(),m(),($=t.instance)==null||$.triggerOnChange(r,s()),c.length>0?Ge():fe()});function He(){G.querySelectorAll(".fb-richinput-dropdown-item").forEach(($,q)=>{$.style.background=q===i.selectedIndex?"var(--fb-background-hover-color, #f3f4f6)":"transparent"})}w.addEventListener("keydown",$=>{if(!i.open)return;const q=ve(),M=on(i.query,c,q);$.key==="ArrowDown"?($.preventDefault(),i.selectedIndex=Math.min(i.selectedIndex+1,M.length-1),He()):$.key==="ArrowUp"?($.preventDefault(),i.selectedIndex=Math.max(i.selectedIndex-1,0),He()):$.key==="Enter"&&M.length>0?($.preventDefault(),Fe(M[i.selectedIndex])):$.key==="Escape"&&fe()}),document.addEventListener("click",$=>{!p.contains($.target)&&!G.contains($.target)&&fe()},{signal:u.signal});function ge(){if(pe(y),c.length===0){y.style.display="none";return}y.style.display="flex",c.forEach($=>{const q=o.resourceIndex.get($),M=document.createElement("div");M.className="fb-richinput-file-thumb",M.style.cssText=`
|
|
547
551
|
position: relative;
|
|
548
552
|
width: 48px;
|
|
549
553
|
height: 48px;
|
|
@@ -553,14 +557,14 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
553
557
|
flex-shrink: 0;
|
|
554
558
|
cursor: pointer;
|
|
555
559
|
background: #fff;
|
|
556
|
-
`;const
|
|
557
|
-
`:""}${
|
|
560
|
+
`;const N=document.createElement("div");N.style.cssText="width: 48px; height: 48px; border-radius: inherit; overflow: hidden;",Gt(N,$,q,o),M.appendChild(N);const H=nn(),I=()=>{var ee,re,oe;const ce=(ee=w.selectionStart)!=null?ee:w.value.length,A=(oe=(re=ve().get($))!=null?re:q==null?void 0:q.name)!=null?oe:$,T=w.value.slice(0,ce),L=w.value.slice(ce),B=`${T.length>0&&!/[\s\n]$/.test(T)?`
|
|
561
|
+
`:""}${ht(A)} `;w.value=`${T}${B}${L}`;const R=ce+B.length;w.setSelectionRange(R,R),w.focus(),w.dispatchEvent(new Event("input"))},Q=()=>{var ee;const re=c.indexOf($);re!==-1&&c.splice(re,1),ge(),ne(),m(),(ee=t.instance)==null||ee.triggerOnChange(r,s())};M.addEventListener("mouseenter",()=>{We(H),H.element||(H.element=tn(M,{rid:$,state:o,isReadonly:!1,onMention:I,onRemove:Q}),H.element.addEventListener("mouseenter",()=>{We(H)}),H.element.addEventListener("mouseleave",()=>{_e(H)}))}),M.addEventListener("mouseleave",()=>{_e(H)}),y.appendChild(M)})}function Ze($){if(!o.config.uploadFile)return;const q=`temp-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;o.resourceIndex.set(q,{name:$.name,type:$.type,size:$.size,uploadedAt:new Date,file:$}),c.push(q),ge();const M=y.querySelectorAll(".fb-richinput-file-thumb"),N=M[M.length-1];N&&(N.style.opacity="0.5"),o.config.uploadFile($).then(H=>{var I;const Q=c.indexOf(q);Q!==-1&&(c[Q]=H),o.resourceIndex.delete(q),o.resourceIndex.set(H,{name:$.name,type:$.type,size:$.size,uploadedAt:new Date,file:$}),ge(),ne(),m(),(I=t.instance)==null||I.triggerOnChange(r,s())}).catch(H=>{var I,Q;const ee=c.indexOf(q);ee!==-1&&c.splice(ee,1),o.resourceIndex.delete(q),ge(),(Q=(I=o.config).onUploadError)==null||Q.call(I,H,$)})}if(g.addEventListener("change",()=>{var $;const q=g.files;if(!q||q.length===0)return;const M=($=e.maxFiles)!=null?$:1/0;for(let N=0;N<q.length;N++){if(c.length>=M){b(k("filesLimitExceeded",o,{skipped:q.length-N,max:M}));break}x(q[N])&&Ze(q[N])}g.value=""}),E.appendChild(C),E.appendChild(w),E.appendChild(P),E.appendChild(G),p.appendChild(y),p.appendChild(E),p.appendChild(h),e.minLength!=null||e.maxLength!=null){const $=document.createElement("div");$.style.cssText="position: relative; padding: 2px 14px 6px; text-align: right;";const q=Ne(e,w,!1);q.style.cssText=`
|
|
558
562
|
position: static;
|
|
559
563
|
display: inline-block;
|
|
560
564
|
font-size: var(--fb-font-size-small);
|
|
561
565
|
color: var(--fb-text-secondary-color);
|
|
562
566
|
pointer-events: none;
|
|
563
|
-
|
|
567
|
+
`,$.appendChild(q),p.appendChild($)}p.appendChild(f),p.appendChild(g),m(),ne(),f._applyExternalUpdate=$=>{var q;const M=(q=$.text)!=null?q:"";w.value=M?Xt(M,c,o):"",w.dispatchEvent(new Event("input")),c.length=0;for(const N of $.files)c.push(N);ge(),ne(),m()},n.appendChild(p),ge();const Ie=new MutationObserver(()=>{p.isConnected||(u.abort(),z=Ae(z),Ie.disconnect())});p.parentElement&&Ie.observe(p.parentElement,{childList:!0})}function So(e,t,n,r,l){var a,o;const c=t.state,{text:i,files:u}=l,f=new Map;for(const s of u){const m=c.resourceIndex.get(s);m!=null&&m.name&&f.set(s,m.name)}if(u.length>0){const s=document.createElement("div");s.style.cssText="display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px;",u.forEach(m=>{const p=c.resourceIndex.get(m),h=document.createElement("div");h.style.cssText=`
|
|
564
568
|
position: relative;
|
|
565
569
|
width: 48px; height: 48px;
|
|
566
570
|
border: 1px solid var(--fb-border-color, #d1d5db);
|
|
@@ -569,12 +573,12 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
569
573
|
flex-shrink: 0;
|
|
570
574
|
background: #fff;
|
|
571
575
|
cursor: default;
|
|
572
|
-
`;const v=document.createElement("div");v.style.cssText="width: 48px; height: 48px; border-radius: inherit; overflow: hidden;",
|
|
573
|
-
${
|
|
576
|
+
`;const v=document.createElement("div");v.style.cssText="width: 48px; height: 48px; border-radius: inherit; overflow: hidden;",Gt(v,m,p,c),h.appendChild(v);const b=nn();h.addEventListener("mouseenter",()=>{We(b),b.element||(b.element=tn(h,{rid:m,state:c,isReadonly:!0}),b.element.addEventListener("mouseenter",()=>{We(b)}),b.element.addEventListener("mouseleave",()=>{_e(b)}))}),h.addEventListener("mouseleave",()=>{_e(b)}),s.appendChild(h)}),n.appendChild(s)}if(i){const s=document.createElement("div");s.style.cssText=`
|
|
577
|
+
${Je}
|
|
574
578
|
color: var(--fb-text-color, #111827);
|
|
575
579
|
white-space: pre-wrap;
|
|
576
580
|
word-break: break-word;
|
|
577
|
-
`;const m=
|
|
581
|
+
`;const m=Ke(i).filter(p=>f.has(p.name)||[...f.values()].includes(p.name));if(m.length===0)s.textContent=i;else{let p=0;for(const h of m){h.start>p&&s.appendChild(document.createTextNode(i.slice(p,h.start)));const v=document.createElement("span");v.style.cssText=`
|
|
578
582
|
display: inline;
|
|
579
583
|
background: color-mix(in srgb, var(--fb-primary-color, #0066cc) 15%, transparent);
|
|
580
584
|
color: var(--fb-primary-color, #0066cc);
|
|
@@ -582,12 +586,12 @@ var FormBuilder=(function(xe){"use strict";function k(e,t,n){const o=t.config.lo
|
|
|
582
586
|
padding: 1px 6px;
|
|
583
587
|
font-weight: 500;
|
|
584
588
|
cursor: default;
|
|
585
|
-
`;const b=p.has(h.name)?h.name:(a=[...p.entries()].find(([,u])=>u===h.name))==null?void 0:a[0],C=(r=p.get(h.name))!=null?r:h.name;if(v.textContent=`@${C}`,b){let u=null;const y=b;v.addEventListener("mouseenter",()=>{u=Ae(u),u=Yt(v,y,i)}),v.addEventListener("mouseleave",()=>{u=Ae(u)})}c.appendChild(v),f=h.end}f<s.length&&c.appendChild(document.createTextNode(s.slice(f)))}n.appendChild(c)}if(!s&&d.length===0){const c=document.createElement("div");c.style.cssText="color: var(--fb-text-muted-color, #6b7280); font-size: var(--fb-font-size, 14px);",c.textContent="\u2014",n.appendChild(c)}}function Cr(e,t,n,o){var l,a,r,i;const s=t.state,d=(l=e.textKey)!=null?l:"text",p=(a=e.filesKey)!=null?a:"files",c=t.prefill[e.key];let m;if(c&&typeof c=="object"&&!Array.isArray(c)){const f=c,h=(r=f[d])!=null?r:f.text,v=(i=f[p])!=null?i:f.files;m={text:typeof h=="string"?h:null,files:Array.isArray(v)?v:[]}}else typeof c=="string"?m={text:c||null,files:[]}:m={text:null,files:[]};for(const f of m.files)s.resourceIndex.has(f)||s.resourceIndex.set(f,{name:f,type:"application/octet-stream",size:0,uploadedAt:new Date,file:void 0});if(s.config.readonly)Er(e,t,n,o,m);else{if(!s.config.uploadFile)throw new Error(`RichInput field "${e.key}" requires uploadFile handler in config`);xr(e,t,n,o,m)}}function wr(e,t,n){var o,l;const{scopeRoot:a,state:r,skipValidation:i}=n,s=[],d=(o=e.textKey)!=null?o:"text",p=(l=e.filesKey)!=null?l:"files",c=a.querySelector(`[name="${t}"]`);if(!c)return{value:null,errors:s};let m={};try{const u=JSON.parse(c.value);if(u&&typeof u=="object"&&!Array.isArray(u))m=u;else return s.push(`${t}: invalid richinput data`),{value:null,errors:s}}catch(u){return s.push(`${t}: invalid richinput data`),{value:null,errors:s}}const f=m[d],h=m[p],v=f===null||typeof f=="string"?f:null,b=Array.isArray(h)?h:[],C={[d]:v!=null?v:null,[p]:b};if(!i){const u=!v||v.trim()==="",y=b.length===0;e.required&&u&&y&&s.push(`${t}: ${k("required",r)}`),!u&&v&&(e.minLength!=null&&v.length<e.minLength&&s.push(`${t}: ${k("minLength",r,{min:e.minLength})}`),e.maxLength!=null&&v.length>e.maxLength&&s.push(`${t}: ${k("maxLength",r,{max:e.maxLength})}`)),e.maxFiles!=null&&b.length>e.maxFiles&&s.push(`${t}: ${k("maxFiles",r,{max:e.maxFiles})}`)}return{value:C,errors:s}}function kr(e,t,n,o){var l,a,r,i;const{scopeRoot:s}=o,d=s.querySelector(`[name="${t}"]`);if(!d){console.warn(`updateRichInputField: no hidden input found for "${t}". Re-render to reflect new data.`);return}let p=null;if(n&&typeof n=="object"&&!Array.isArray(n)){const c=n,m=(l=e.textKey)!=null?l:"text",f=(a=e.filesKey)!=null?a:"files",h=(r=c[m])!=null?r:c.text,v=(i=c[f])!=null?i:c.files;(h!==void 0||v!==void 0)&&(p={text:typeof h=="string"?h:null,files:Array.isArray(v)?v:[]})}p&&d._applyExternalUpdate?d._applyExternalUpdate(p):p&&(d.value=JSON.stringify(p))}function $r(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(p=>{p.classList.add("hidden")}),o)return;const l=t.getBoundingClientRect(),a=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=l.left,d=l.bottom+5;s+i.width>a&&(s=l.right-i.width),d+i.height>r&&(d=l.top-i.height-5),s<10&&(s=10),d<10&&(d=l.bottom+5),n.style.left=`${s}px`,n.style.top=`${d}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(l=>{l.classList.add("hidden")})});function Lr(e,t){var n,o,l;if(!e.enableIf)return!1;try{const a=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=((l=e.enableIf.scope)!=null?l:"relative")==="relative"&&t.path?t.prefill:void 0;return!$e(e.enableIf,a,r)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function Sr(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 We(e,t,n){var o,l;if(!t.enableIf)return;const a=n.state.formRoot;if(!a){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const r=t.enableIf,i=(o=r.scope)!=null?o:"relative";let s={};const d={};if((!n.path||n.path===""?"absolute":i)==="relative"&&n.path){const p=n.path.match(/^(.+)\[(\d+)\]$/);if(p){const c=p[1],m=parseInt(p[2],10),f=a.querySelector(`[data-container-item="${c}[${m}]"]`);f&&f.querySelectorAll("input, select, textarea").forEach(h=>{const v=h.getAttribute("name");if(v){const b=v.match(/\.([^.[\]]+)$/);if(b){const C=b[1];h instanceof HTMLSelectElement?d[C]=h.value:h instanceof HTMLInputElement?h.type==="checkbox"?d[C]=h.checked:h.type==="radio"?h.checked&&(d[C]=h.value):d[C]=h.value:h instanceof HTMLTextAreaElement&&(d[C]=h.value)}}})}}else{const p=r.key,c=Sr(p,a);c!==void 0?s[p]=c:s=(l=n.formData)!=null?l:n.prefill}try{$e(r,s,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(p){console.error(`Error re-evaluating enableIf for field "${t.key}":`,p)}}function Tr(e,t,n){var o;if(!t.enableIf)return;const l=n.state.formRoot;if(!l){console.error("Cannot setup enableIf listeners: formRoot is null");return}const a=t.enableIf,r=(o=a.scope)!=null?o:"relative",i=a.key;let s;r==="relative"&&n.path?s=`${n.path}.${i}`:s=i;const d=l.querySelector(`[name="${s}"]`);if(!d){const p=new MutationObserver(()=>{const c=l.querySelector(`[name="${s}"]`);c&&(c.addEventListener("change",()=>{We(e,t,n)}),c.addEventListener("input",()=>{We(e,t,n)}),p.disconnect())});p.observe(l,{childList:!0,subtree:!0});return}d.addEventListener("change",()=>{We(e,t,n)}),d.addEventListener("input",()=>{We(e,t,n)})}function Ar(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 Fr(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=l=>{l.preventDefault(),l.stopPropagation(),$r(n,t)},t}function Nr(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Ar(e);if(t.appendChild(n),e.description||e.hint){const o=Fr(e);t.appendChild(o)}return t}function Mr(e,t,n,o){const l="multiple"in e&&e.multiple;switch(e.type){case"text":l?pn(e,t,n,o):dn(e,t,n,o);break;case"textarea":l?mn(e,t,n,o):fn(e,t,n,o);break;case"number":l?bn(e,t,n,o):gn(e,t,n,o);break;case"select":l?Cn(e,t,n,o):En(e,t,n,o);break;case"switcher":l?Ln(e,t,n,o):$n(e,t,n,o);break;case"file":l?Vn(e,t,n,o):Un(e,t,n,o);break;case"files":Pn(e,t,n,o);break;case"colour":l?Wn(e,t,n,o):_n(e,t,n,o);break;case"slider":l?Xn(e,t,n,o):Yn(e,t,n,o);break;case"group":tr(e,t,n,o);break;case"container":l?Rt(e,t,n):zt(e,t,n,o);break;case"table":fr(e,t,n,o);break;case"richinput":Cr(e,t,n,o);break;default:{const a=document.createElement("div");a.className="text-red-500 text-sm",a.textContent=k("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(a)}}}function dt(e,t){const n=Lr(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const l=Nr(e);o.appendChild(l);const a=ke(t.path,e.key);return Mr(e,t,o,a),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),Tr(o,e,t),o}Qn(dt);const pt={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,parseTableFile:null,locale:"en",translations:{en:{removeElement:"Remove",clickDragText:"Click or drag file",clickDragTextMultiple:"Click or drag files",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download",changeButton:"Change",placeholderText:"Enter text",previewAlt:"Preview",previewUnavailable:"Preview unavailable",previewError:"Preview error",videoNotSupported:"Your browser does not support the video tag.",hintLengthRange:"{min}-{max} chars",hintMaxLength:"\u2264{max} chars",hintMinLength:"\u2265{min} chars",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}MB",hintFormats:"{formats}",hintRequired:"Required",hintOptional:"Optional",hintPattern:"Format: {pattern}",fileCountSingle:"{count} file",fileCountPlural:"{count} files",fileCountRange:"({min}-{max})",required:"Required",minItems:"Minimum {min} items required",maxItems:"Maximum {max} items allowed",minLength:"Minimum {min} characters",maxLength:"Maximum {max} characters",minValue:"Must be at least {min}",maxValue:"Must be at most {max}",patternMismatch:"Invalid format",invalidPattern:"Invalid pattern in schema",notANumber:"Must be a number",invalidHexColour:"Invalid hex color",minFiles:"Minimum {min} files required",maxFiles:"Maximum {max} files allowed",unsupportedFieldType:"Unsupported field type: {type}",invalidOption:"Invalid option",tableAddRow:"Add row",tableAddColumn:"Add column",tableRemoveRow:"Remove row",tableRemoveColumn:"Remove column",tableMergeCells:"Merge cells (Ctrl+M)",tableSplitCell:"Split cell (Ctrl+Shift+M)",tableImportFile:"Import",tableImporting:"Importing...",tableImportError:"Import failed: {error}",richinputPlaceholder:"Type text...",richinputAttachFile:"Attach file",richinputMention:"Mention",richinputRemoveFile:"Remove"},ru:{removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragTextMultiple:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C",changeButton:"\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",placeholderText:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",previewAlt:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440",previewUnavailable:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D",previewError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440\u0430",videoNotSupported:"\u0412\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043E.",hintLengthRange:"{min}-{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMaxLength:"\u2264{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMinLength:"\u2265{min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}\u041C\u0411",hintFormats:"{formats}",hintRequired:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintOptional:"\u041D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintPattern:"\u0424\u043E\u0440\u043C\u0430\u0442: {pattern}",fileCountSingle:"{count} \u0444\u0430\u0439\u043B",fileCountPlural:"{count} \u0444\u0430\u0439\u043B\u043E\u0432",fileCountRange:"({min}-{max})",required:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435",minItems:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",maxItems:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",minLength:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",maxLength:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",minValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u043C\u0435\u043D\u0435\u0435 {min}",maxValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u0431\u043E\u043B\u0435\u0435 {max}",patternMismatch:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442",invalidPattern:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043F\u0430\u0442\u0442\u0435\u0440\u043D \u0432 \u0441\u0445\u0435\u043C\u0435",notANumber:"\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0447\u0438\u0441\u043B\u043E\u043C",invalidHexColour:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u0446\u0432\u0435\u0442\u0430",minFiles:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0444\u0430\u0439\u043B\u043E\u0432",maxFiles:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0444\u0430\u0439\u043B\u043E\u0432",unsupportedFieldType:"\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u043B\u044F: {type}",invalidOption:"\u041D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435",tableAddRow:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableAddColumn:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableRemoveRow:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableRemoveColumn:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableMergeCells:"\u041E\u0431\u044A\u0435\u0434\u0438\u043D\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0438 (Ctrl+M)",tableSplitCell:"\u0420\u0430\u0437\u0434\u0435\u043B\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0443 (Ctrl+Shift+M)",tableImportFile:"\u0418\u043C\u043F\u043E\u0440\u0442",tableImporting:"\u0418\u043C\u043F\u043E\u0440\u0442...",tableImportError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u0438\u043C\u043F\u043E\u0440\u0442\u0430: {error}",richinputPlaceholder:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442...",richinputAttachFile:"\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C \u0444\u0430\u0439\u043B",richinputMention:"\u0423\u043F\u043E\u043C\u044F\u043D\u0443\u0442\u044C",richinputRemoveFile:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C"}},theme:{}};function qr(e){const t={...pt.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...pt.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...pt,...e,translations:t},debounceTimer:null}}function Hr(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const He={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 Ir(e){const t={...He,...e},n=[];return Object.entries(t).forEach(([o,l])=>{const a=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${a}: ${l};`)}),n.join(`
|
|
586
|
-
`)}function
|
|
589
|
+
`;const b=f.has(h.name)?h.name:(a=[...f.entries()].find(([,d])=>d===h.name))==null?void 0:a[0],x=(o=f.get(h.name))!=null?o:h.name;if(v.textContent=`@${x}`,b){let d=null;const y=b;v.addEventListener("mouseenter",()=>{d=Ae(d),d=en(v,y,c)}),v.addEventListener("mouseleave",()=>{d=Ae(d)})}s.appendChild(v),p=h.end}p<i.length&&s.appendChild(document.createTextNode(i.slice(p)))}n.appendChild(s)}if(!i&&u.length===0){const s=document.createElement("div");s.style.cssText="color: var(--fb-text-muted-color, #6b7280); font-size: var(--fb-font-size, 14px);",s.textContent="\u2014",n.appendChild(s)}}function To(e,t,n,r){var l,a,o,c;const i=t.state,u=(l=e.textKey)!=null?l:"text",f=(a=e.filesKey)!=null?a:"files";let s;if(e.flatOutput){const m=t.prefill[u],p=t.prefill[f];s={text:typeof m=="string"?m:null,files:Array.isArray(p)?p:[]}}else{const m=t.prefill[e.key];if(m&&typeof m=="object"&&!Array.isArray(m)){const p=m,h=(o=p[u])!=null?o:p.text,v=(c=p[f])!=null?c:p.files;s={text:typeof h=="string"?h:null,files:Array.isArray(v)?v:[]}}else typeof m=="string"?s={text:m||null,files:[]}:s={text:null,files:[]}}for(const m of s.files)i.resourceIndex.has(m)||i.resourceIndex.set(m,{name:m,type:"application/octet-stream",size:0,uploadedAt:new Date,file:void 0});if(i.config.readonly)So(e,t,n,r,s);else{if(!i.config.uploadFile)throw new Error(`RichInput field "${e.key}" requires uploadFile handler in config`);Lo(e,t,n,r,s)}}function Ao(e,t,n){var r,l;const{scopeRoot:a,state:o,skipValidation:c}=n,i=[],u=(r=e.textKey)!=null?r:"text",f=(l=e.filesKey)!=null?l:"files",s=a.querySelector(`[name="${t}"]`);if(!s)return{value:null,errors:i};let m={};try{const d=JSON.parse(s.value);if(d&&typeof d=="object"&&!Array.isArray(d))m=d;else return i.push(`${t}: invalid richinput data`),{value:null,errors:i}}catch(d){return i.push(`${t}: invalid richinput data`),{value:null,errors:i}}const p=m[u],h=m[f],v=p===null||typeof p=="string"?p:null,b=Array.isArray(h)?h:[],x={[u]:v!=null?v:null,[f]:b};if(!c){const d=!v||v.trim()==="",y=b.length===0;e.required&&d&&y&&i.push(`${t}: ${k("required",o)}`),!d&&v&&(e.minLength!=null&&v.length<e.minLength&&i.push(`${t}: ${k("minLength",o,{min:e.minLength})}`),e.maxLength!=null&&v.length>e.maxLength&&i.push(`${t}: ${k("maxLength",o,{max:e.maxLength})}`)),e.maxFiles!=null&&b.length>e.maxFiles&&i.push(`${t}: ${k("maxFiles",o,{max:e.maxFiles})}`)}return{value:x,errors:i,spread:!!e.flatOutput}}function Fo(e,t,n,r){var l,a,o,c;const{scopeRoot:i}=r,u=i.querySelector(`[name="${t}"]`);if(!u){console.warn(`updateRichInputField: no hidden input found for "${t}". Re-render to reflect new data.`);return}let f=null;if(n&&typeof n=="object"&&!Array.isArray(n)){const s=n,m=(l=e.textKey)!=null?l:"text",p=(a=e.filesKey)!=null?a:"files",h=(o=s[m])!=null?o:s.text,v=(c=s[p])!=null?c:s.files;(h!==void 0||v!==void 0)&&(f={text:typeof h=="string"?h:null,files:Array.isArray(v)?v:[]})}f&&u._applyExternalUpdate?u._applyExternalUpdate(f):f&&(u.value=JSON.stringify(f))}function No(e,t){const n=document.getElementById(e);if(!n)return;const r=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(f=>{f.classList.add("hidden")}),r)return;const l=t.getBoundingClientRect(),a=window.innerWidth,o=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const c=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let i=l.left,u=l.bottom+5;i+c.width>a&&(i=l.right-c.width),u+c.height>o&&(u=l.top-c.height-5),i<10&&(i=10),u<10&&(u=l.bottom+5),n.style.left=`${i}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,r=t.closest('[id^="tooltip-"]');!n&&!r&&document.querySelectorAll('[id^="tooltip-"]').forEach(l=>{l.classList.add("hidden")})});function Mo(e,t){var n,r,l;if(!e.enableIf)return!1;try{const a=(r=(n=t.formData)!=null?n:t.prefill)!=null?r:{},o=((l=e.enableIf.scope)!=null?l:"relative")==="relative"&&t.path?t.prefill:void 0;return!ke(e.enableIf,a,o)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function qo(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 r=t.querySelector(`[name="${e}"]:checked`);return r?r.value:void 0}else return n.value}else if(n instanceof HTMLTextAreaElement)return n.value}}function Ye(e,t,n){var r,l;if(!t.enableIf)return;const a=n.state.formRoot;if(!a){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const o=t.enableIf,c=(r=o.scope)!=null?r:"relative";let i={};const u={};if((!n.path||n.path===""?"absolute":c)==="relative"&&n.path){const f=n.path.match(/^(.+)\[(\d+)\]$/);if(f){const s=f[1],m=parseInt(f[2],10),p=a.querySelector(`[data-container-item="${s}[${m}]"]`);p&&p.querySelectorAll("input, select, textarea").forEach(h=>{const v=h.getAttribute("name");if(v){const b=v.match(/\.([^.[\]]+)$/);if(b){const x=b[1];h instanceof HTMLSelectElement?u[x]=h.value:h instanceof HTMLInputElement?h.type==="checkbox"?u[x]=h.checked:h.type==="radio"?h.checked&&(u[x]=h.value):u[x]=h.value:h instanceof HTMLTextAreaElement&&(u[x]=h.value)}}})}}else{const f=o.key,s=qo(f,a);s!==void 0?i[f]=s:i=(l=n.formData)!=null?l:n.prefill}try{ke(o,i,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(f){console.error(`Error re-evaluating enableIf for field "${t.key}":`,f)}}function zo(e,t,n){var r;if(!t.enableIf)return;const l=n.state.formRoot;if(!l){console.error("Cannot setup enableIf listeners: formRoot is null");return}const a=t.enableIf,o=(r=a.scope)!=null?r:"relative",c=a.key;let i;o==="relative"&&n.path?i=`${n.path}.${c}`:i=c;const u=l.querySelector(`[name="${i}"]`);if(!u){const f=new MutationObserver(()=>{const s=l.querySelector(`[name="${i}"]`);s&&(s.addEventListener("change",()=>{Ye(e,t,n)}),s.addEventListener("input",()=>{Ye(e,t,n)}),f.disconnect())});f.observe(l,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{Ye(e,t,n)}),u.addEventListener("input",()=>{Ye(e,t,n)})}function Ho(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 Io(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)}`,r=document.createElement("div");return r.id=n,r.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",r.style.position="fixed",r.textContent=e.description||e.hint||"Field information",document.body.appendChild(r),t.onclick=l=>{l.preventDefault(),l.stopPropagation(),No(n,t)},t}function Bo(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Ho(e);if(t.appendChild(n),e.description||e.hint){const r=Io(e);t.appendChild(r)}return t}function Ro(e,t,n,r){const l="multiple"in e&&e.multiple;switch(e.type){case"text":l?gn(e,t,n,r):vn(e,t,n,r);break;case"textarea":l?yn(e,t,n,r):bn(e,t,n,r);break;case"number":l?wn(e,t,n,r):Cn(e,t,n,r);break;case"select":l?Sn(e,t,n,r):Ln(e,t,n,r);break;case"switcher":l?Nn(e,t,n,r):Fn(e,t,n,r);break;case"file":l?Yn(e,t,n,r):Wn(e,t,n,r);break;case"files":Jn(e,t,n,r);break;case"colour":l?Gn(e,t,n,r):Xn(e,t,n,r);break;case"slider":l?to(e,t,n,r):eo(e,t,n,r);break;case"group":ao(e,t,n,r);break;case"container":l?Ut(e,t,n):Ot(e,t,n,r);break;case"table":yo(e,t,n,r);break;case"richinput":To(e,t,n,r);break;default:{const a=document.createElement("div");a.className="text-red-500 text-sm",a.textContent=k("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(a)}}}function vt(e,t){const n=Mo(e,t),r=document.createElement("div");r.className="mb-6 fb-field-wrapper",r.setAttribute("data-field-key",e.key);const l=Bo(e);r.appendChild(l);const a=we(t.path,e.key);return Ro(e,t,r,a),n&&(r.style.display="none",r.classList.add("fb-field-wrapper-disabled"),r.setAttribute("data-conditionally-disabled","true")),zo(r,e,t),r}ro(vt);const gt={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,parseTableFile:null,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",invalidFileExtension:'File "{name}" has unsupported format. Allowed: {formats}',fileTooLarge:'File "{name}" exceeds maximum size of {maxSize}MB',filesLimitExceeded:"{skipped} file(s) skipped: maximum {max} files allowed",unsupportedFieldType:"Unsupported field type: {type}",invalidOption:"Invalid option",tableAddRow:"Add row",tableAddColumn:"Add column",tableRemoveRow:"Remove row",tableRemoveColumn:"Remove column",tableMergeCells:"Merge cells (Ctrl+M)",tableSplitCell:"Split cell (Ctrl+Shift+M)",tableImportFile:"Import",tableImporting:"Importing...",tableImportError:"Import failed: {error}",richinputPlaceholder:"Type text...",richinputAttachFile:"Attach file",richinputMention:"Mention",richinputRemoveFile:"Remove"},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",invalidFileExtension:'\u0424\u0430\u0439\u043B "{name}" \u0438\u043C\u0435\u0435\u0442 \u043D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442. \u0414\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B\u0435: {formats}',fileTooLarge:'\u0424\u0430\u0439\u043B "{name}" \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u043C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u044B\u0439 \u0440\u0430\u0437\u043C\u0435\u0440 {maxSize}\u041C\u0411',filesLimitExceeded:"{skipped} \u0444\u0430\u0439\u043B(\u043E\u0432) \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043E: \u043C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0444\u0430\u0439\u043B\u043E\u0432",unsupportedFieldType:"\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u043B\u044F: {type}",invalidOption:"\u041D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435",tableAddRow:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableAddColumn:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableRemoveRow:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableRemoveColumn:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableMergeCells:"\u041E\u0431\u044A\u0435\u0434\u0438\u043D\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0438 (Ctrl+M)",tableSplitCell:"\u0420\u0430\u0437\u0434\u0435\u043B\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0443 (Ctrl+Shift+M)",tableImportFile:"\u0418\u043C\u043F\u043E\u0440\u0442",tableImporting:"\u0418\u043C\u043F\u043E\u0440\u0442...",tableImportError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u0438\u043C\u043F\u043E\u0440\u0442\u0430: {error}",richinputPlaceholder:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442...",richinputAttachFile:"\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C \u0444\u0430\u0439\u043B",richinputMention:"\u0423\u043F\u043E\u043C\u044F\u043D\u0443\u0442\u044C",richinputRemoveFile:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C"}},theme:{}};function Do(e){const t={...gt.translations};if(e!=null&&e.translations)for(const[n,r]of Object.entries(e.translations))t[n]={...gt.translations[n]||{},...r};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...gt,...e,translations:t},debounceTimer:null}}function jo(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const qe={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 Oo(e){const t={...qe,...e},n=[];return Object.entries(t).forEach(([r,l])=>{const a=r.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${a}: ${l};`)}),n.join(`
|
|
590
|
+
`)}function Uo(e,t){const n=Oo(t);let r=e.querySelector("style[data-fb-theme]");r||(r=document.createElement("style"),r.setAttribute("data-fb-theme","true"),e.appendChild(r)),r.textContent=`
|
|
587
591
|
[data-fb-root="true"] {
|
|
588
592
|
${n}
|
|
589
593
|
}
|
|
590
|
-
`}const
|
|
594
|
+
`}const Po={default:qe,dark:{...qe,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:{...qe,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 ln(e,t=!1){e.style.cssText=`
|
|
591
595
|
background-color: var(--fb-action-bg-color);
|
|
592
596
|
color: var(--fb-action-text-color);
|
|
593
597
|
border: var(--fb-border-width) solid var(--fb-action-border-color);
|
|
@@ -597,6 +601,6 @@ ${n}
|
|
|
597
601
|
border-radius: var(--fb-border-radius);
|
|
598
602
|
transition: all var(--fb-transition-duration);
|
|
599
603
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
600
|
-
`,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
|
|
604
|
+
`,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 Vo={text:{validate:bt,update:yt},textarea:{validate:xn,update:En},number:{validate:kn,update:$n},select:{validate:Tn,update:An},switcher:{validate:Mn,update:qn},file:{validate:Nt,update:Mt},files:{validate:Nt,update:Mt},colour:{validate:Zn,update:Qn},slider:{validate:no,update:oo},container:{validate:Vt,update:Kt},group:{validate:io,update:so},table:{validate:xo,update:Eo},richinput:{validate:Ao,update:Fo}};function an(e){return Vo[e]||null}function Ko(e,t,n){const r=an(e.type);return r&&r.validate?r.validate(e,t,n):null}function _o(e,t,n,r){const l=an(e.type);return l&&l.update?(l.update(e,t,n,r),!0):!1}class Xe{constructor(t){this.instanceId=jo(),this.state=Do(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 r=this.validateForm(!0);this.reevaluateConditionalFields(),this.state.config.onChange&&this.state.config.onChange(r),this.state.config.onFieldChange&&t!==void 0&&n!==void 0&&this.state.config.onFieldChange(t,n,r),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(r=>r.value===t.value&&r.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 l=this.state.formRoot.querySelector(`[name="${t}"]`);if(l)return l;const a=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const o of a)if(l=this.state.formRoot.querySelector(`[name="${o}"]`),l)return l}const n=this.findSchemaElement(t);if(!n)return null;const r=this.state.formRoot.querySelectorAll(".fb-field-wrapper");for(const l of r){const a=n.label||n.key,o=l.querySelector("label");if(o&&(o.textContent===a||o.textContent===`${a}*`)){let c=l.querySelector(".field-placeholder");return c||(c=document.createElement("div"),c.className="field-placeholder",c.style.display="none",l.appendChild(c)),c}}return null}findSchemaElement(t){if(!this.state.schema||!this.state.schema.elements)return null;let n=this.state.schema.elements,r=null;const l=t.replace(/\[\d+\]/g,"").split(".").filter(Boolean);for(const a of l){if(r=n.find(o=>o.key===a)||null,!r)return null;"elements"in r&&r.elements&&(n=r.elements)}return r}resolveActionLabel(t,n,r,l=!1){if(r&&"actions"in r&&r.actions){const a=r.actions.find(o=>o.key===t);if(a&&a.label)return a.label}if(l&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const a=this.state.schema.actions.find(o=>o.key===t);if(a&&a.label)return a.label}return n||t}renderFormLevelActions(t,n=[]){if(!this.state.formRoot)return;const r=this.state.formRoot.querySelector(".form-level-actions-container");r&&r.remove();const l=document.createElement("div");l.className="form-level-actions-container mt-6 pt-4 flex flex-wrap gap-3 justify-center",l.style.cssText=`
|
|
601
605
|
border-top: var(--fb-border-width) solid var(--fb-border-color);
|
|
602
|
-
`,t.forEach(a=>{const
|
|
606
|
+
`,t.forEach(a=>{const o=document.createElement("button");o.type="button",ln(o,!0);const c=n.includes(a),i=this.resolveActionLabel(a.key,a.label,null,c);o.textContent=i,o.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(a.value,a.key,null)}),l.appendChild(o)}),this.state.formRoot.appendChild(l)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],r=[];this.state.externalActions.forEach(a=>{!a.key||!a.value||(a.related_field?(t.has(a.related_field)||t.set(a.related_field,[]),t.get(a.related_field).push(a)):n.push(a))}),t.forEach((a,o)=>{const c=this.findFormElementByFieldPath(o);if(!c){console.warn(`External action: Could not find form element for field "${o}", treating as form-level actions`),r.push(...a);return}let i=c.closest(".fb-field-wrapper");if(i||(i=c.parentElement),!i){console.warn(`External action: Could not find wrapper for field "${o}"`);return}const u=i.querySelector(".external-actions-container");u&&u.remove();const f=document.createElement("div");f.className="external-actions-container mt-3 flex flex-wrap gap-2";const s=this.findSchemaElement(o);a.forEach(m=>{const p=document.createElement("button");p.type="button",ln(p,!1);const h=this.resolveActionLabel(m.key,m.label,s);p.textContent=h,p.addEventListener("click",v=>{v.preventDefault(),v.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(m.value,m.key,m.related_field)}),f.appendChild(p)}),i.appendChild(f)});const l=[...n,...r];l.length>0&&this.renderFormLevelActions(l,n)}handlePrefillHintClick(t){const n=t.target;if(!n.classList.contains("fb-prefill-hint"))return;t.preventDefault(),t.stopPropagation();const r=n.getAttribute("data-hint-values"),l=n.getAttribute("data-root-hint")==="true",a=n.getAttribute("data-container-key");if(!r||!l&&!a){console.warn("Prefill hint missing required data attributes");return}try{const o=JSON.parse(r);for(const c in o){const i=l?c:`${a}.${c}`,u=o[c];this.updateField(i,u)}}catch(o){console.error("Error parsing prefill hint values:",o)}}createRootPrefillHints(t){const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",t.forEach(r=>{const l=document.createElement("button");l.type="button",l.className="fb-prefill-hint",r.icon?l.textContent=`${r.icon} ${r.label}`:l.textContent=r.label,l.setAttribute("data-hint-values",JSON.stringify(r.values)),l.setAttribute("data-root-hint","true"),n.appendChild(l)}),n}renderForm(t,n,r,l){const a=Qe(n);if(a.length>0){console.error("Schema validation errors:",a);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=l||null,pe(t),t.setAttribute("data-fb-root","true"),Uo(t,this.state.config.theme);const o=document.createElement("div");if(o.className="space-y-6",n.prefillHints&&!this.state.config.readonly){const u=this.createRootPrefillHints(n.prefillHints);o.appendChild(u)}const c=document.createElement("div"),i=n.columns||1;i===1?c.className="space-y-4":c.className=`grid grid-cols-${i} gap-4`,n.elements.forEach(u=>{if(u.hidden)return;const f=vt(u,{path:"",prefill:r||{},formData:r||{},state:this.state,instance:this});c.appendChild(f)}),o.appendChild(c),t.appendChild(o),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=[],r={},l=(a,o,c=null)=>{const i=a.key,u={scopeRoot:c||this.state.formRoot,state:this.state,instance:this,path:o.path,skipValidation:t},f=Ko(a,i,u);return f!==null?(n.push(...f.errors),{value:f.value,spread:!!f.spread}):(console.warn(`Unknown field type "${a.type}" for key "${i}"`),{value:null,spread:!1})};return lo(l),this.state.schema.elements.forEach(a=>{if(a.enableIf)try{if(!ke(a.enableIf,r))return}catch(o){console.error(`Error evaluating enableIf for field "${a.key}" during validation:`,o)}if(a.hidden)r[a.key]=a.default!==void 0?a.default:null;else{const o=l(a,{path:""});o.spread&&o.value!==null&&typeof o.value=="object"?Object.assign(r,o.value):r[a.key]=o.value}}),{valid:n.length===0,errors:n,data:r}}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,r=this.state.externalActions,l=this.buildHiddenFieldsData(t.elements);this.renderForm(n,t,l,r||void 0)}buildHiddenFieldsData(t){const n={};for(const r of t){const l=r.key;if(r.hidden&&r.default!==void 0&&(n[l]=r.default),r.type==="container"||r.type==="group"){const a=r,o=this.buildHiddenFieldsData(a.elements);Object.keys(o).length>0&&(l in n?typeof n[l]=="object"&&n[l]!==null&&!Array.isArray(n[l])&&(n[l]={...n[l],...o}):n[l]=o)}}return n}buildFlatKeyMap(t){var n,r;const l=new Map;for(const a of t)if(a.type==="richinput"&&a.flatOutput){const o=a,c=(n=o.textKey)!=null?n:"text",i=(r=o.filesKey)!=null?r:"files";l.set(c,{schemaKey:a.key,role:"text"}),l.set(i,{schemaKey:a.key,role:"files"})}return l}setFormData(t){if(!this.state.schema||!this.state.formRoot){console.warn("setFormData: Form not initialized. Call renderForm() first.");return}const n=this.buildFlatKeyMap(this.state.schema.elements),r=new Map;for(const l in t){const a=n.get(l);a?(r.has(a.schemaKey)||r.set(a.schemaKey,{}),r.get(a.schemaKey)[l]=t[l]):this.updateField(l,t[l])}for(const[l,a]of r)this.updateField(l,a)}updateField(t,n){if(!this.state.schema||!this.state.formRoot){console.warn("updateField: Form not initialized. Call renderForm() first.");return}const r=this.findSchemaElement(t);if(!r){console.warn(`updateField: Schema element not found for path "${t}"`);return}const l=this.findFormElementByFieldPath(t);if(!l){console.warn(`updateField: DOM element not found for path "${t}"`);return}this.updateFieldValue(l,r,t,n),this.reevaluateConditionalFields(),(this.state.config.onChange||this.state.config.onFieldChange)&&this.triggerOnChange(t,n)}updateFieldValue(t,n,r,l){const a={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};_o(n,r,l,a)||console.warn(`updateField: No updater found for field type "${n.type}" at path "${r}"`)}reevaluateConditionalFields(){if(!this.state.schema||!this.state.formRoot)return;const t=this.validateForm(!0).data,n=(r,l)=>{r.forEach(a=>{var o,c,i;const u=l?`${l}.${a.key}`:a.key;if(a.enableIf){let f=null;if(l){const s=l.match(/^(.+)\[(\d+)\]$/);if(s){const m=s[1],p=s[2],h=this.state.formRoot.querySelector(`[data-container-item="${m}[${p}]"]`);h&&(f=h.querySelector(`[data-field-key="${a.key}"]`))}else{const m=this.state.formRoot.querySelector(`[data-container="${l}"]`);m&&(f=m.querySelector(`[data-field-key="${a.key}"]`))}}else f=this.state.formRoot.querySelector(`[data-field-key="${a.key}"]`);if(f){const s=f;try{let m;((o=a.enableIf.scope)!=null?o:"relative")==="relative"&&l&&(m=et(t,l));const p=ke(a.enableIf,t,m),h=s.getAttribute("data-conditionally-disabled")==="true";if(p&&h){const v=l?et(t,l):t,b=vt(a,{path:l,prefill:v&&typeof v=="object"?v:{},formData:t,state:this.state,instance:this});(c=s.parentNode)==null||c.replaceChild(b,s)}else if(!p&&!h){const v=document.createElement("div");v.className="fb-field-wrapper-disabled",v.style.display="none",v.setAttribute("data-field-key",a.key),v.setAttribute("data-conditionally-disabled","true"),(i=s.parentNode)==null||i.replaceChild(v,s)}}catch(m){console.error(`Error re-evaluating enableIf for field "${a.key}" at path "${u}":`,m)}}}if((a.type==="container"||a.type==="group")&&"elements"in a&&a.elements){const f=t==null?void 0:t[a.key];if(Array.isArray(f)){const s=this.state.formRoot.querySelectorAll("[data-container-item]");Array.from(s).filter(m=>{const p=m.getAttribute("data-container-item")||"";if(!p.startsWith(`${u}[`))return!1;const h=p.slice(u.length);return/^\[\d+\]$/.test(h)}).forEach(m=>{const p=m.getAttribute("data-container-item")||"";n(a.elements,p)})}else n(a.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&&pe(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 sn(e){return new Xe(e)}return typeof window!="undefined"&&(window.FormBuilder=Xe,window.createFormBuilder=sn,window.validateSchema=Qe),be.FormBuilderInstance=Xe,be.createFormBuilder=sn,be.default=Xe,be.defaultTheme=qe,be.exampleThemes=Po,be.validateSchema=Qe,Object.defineProperty(be,"__esModule",{value:!0}),be})({});
|