@dmitryvim/form-builder 0.2.6 → 0.2.7
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 +118 -61
- package/dist/browser/formbuilder.v0.2.7.min.js +241 -0
- package/dist/cjs/index.cjs +722 -185
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +715 -182
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +118 -61
- package/dist/types/components/colour.d.ts +18 -0
- package/dist/types/components/index.d.ts +2 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/schema.d.ts +8 -1
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.6.min.js +0 -184
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var FormBuilder=(function(
|
|
1
|
+
var FormBuilder=(function(F){"use strict";function he(e,t){(e.minLength!==null||e.maxLength!==null)&&(e.minLength!==null&&e.maxLength!==null?t.push(`length=${e.minLength}-${e.maxLength} characters`):e.maxLength!==null?t.push(`max=${e.maxLength} characters`):e.minLength!==null&&t.push(`min=${e.minLength} characters`))}function ve(e,t){(e.min!==null||e.max!==null)&&(e.min!==null&&e.max!==null?t.push(`range=${e.min}-${e.max}`):e.max!==null?t.push(`max=${e.max}`):e.min!==null&&t.push(`min=${e.min}`))}function ge(e,t){e.maxSizeMB&&t.push(`max_size=${e.maxSizeMB}MB`)}function ye(e,t){var n;(n=e.accept)!=null&&n.extensions&&t.push(`formats=${e.accept.extensions.map(o=>o.toUpperCase()).join(",")}`)}function be(e,t){var n;e.pattern&&!e.pattern.includes("\u0410-\u042F")?t.push("plain text only"):(n=e.pattern)!=null&&n.includes("\u0410-\u042F")&&t.push("text with punctuation")}function S(e){const t=[];return t.push(e.required?"required":"optional"),he(e,t),ve(e,t),ge(e,t),ye(e,t),be(e,t),t.join(" \u2022 ")}function z(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;function n(o,a){o.forEach((r,l)=>{const i=`${a}[${l}]`;if(r.type||t.push(`${i}: missing type`),r.key||t.push(`${i}: missing key`),r.displayIf){const s=r.displayIf;(!s.key||typeof s.key!="string")&&t.push(`${i}: displayIf must have a 'key' property of type string`),"equals"in s||t.push(`${i}: displayIf must have at least one operator (equals, etc.)`)}if(r.type==="group"&&"elements"in r&&r.elements&&n(r.elements,`${i}.elements`),r.type==="container"&&r.elements&&n(r.elements,`${i}.elements`),r.type==="select"&&r.options){const s=r.default;s!=null&&s!==""&&(r.options.some(d=>d.value===s)||t.push(`${i}: default "${s}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function H(e){return e&&typeof e=="object"&&e.constructor===Object}function N(e,t){return e?`${e}.${t}`:t}function T(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function xe(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let o=e;for(const a of n){if(o==null)return;if(a.startsWith("[")&&a.endsWith("]")){const r=parseInt(a.slice(1,-1),10);if(!Array.isArray(o)||isNaN(r))return;o=o[r]}else o=o[a]}return o}function j(e,t){if(!e||!e.key)throw new Error("Invalid displayIf condition: must have a 'key' property");const n=xe(t,e.key);if("equals"in e)return Ce(n,e.equals);throw new Error("Invalid displayIf condition: no recognized operator (equals, etc.)")}function Ce(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 displayIf comparison, using reference equality"),e===t;throw n}return e===t}function Ee(e,t,n,o){const a=t.state,r=document.createElement("input");if(r.type="text",r.className="w-full rounded-lg",r.style.cssText=`
|
|
2
2
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
3
3
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
4
4
|
border-radius: var(--fb-border-radius);
|
|
5
|
-
background-color: ${
|
|
5
|
+
background-color: ${a.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
|
|
6
6
|
color: var(--fb-text-color);
|
|
7
7
|
font-size: var(--fb-font-size);
|
|
8
8
|
font-family: var(--fb-font-family);
|
|
9
9
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
10
|
-
`,r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.value=t.prefill[e.key]||e.default||"",r.readOnly=
|
|
10
|
+
`,r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,a.config.readonly||(r.addEventListener("focus",()=>{r.style.borderColor="var(--fb-border-focus-color)",r.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",r.style.outlineOffset="0"}),r.addEventListener("blur",()=>{r.style.borderColor="var(--fb-border-color)",r.style.outline="none"}),r.addEventListener("mouseenter",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-hover-color)")}),r.addEventListener("mouseleave",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-color)")})),!a.config.readonly&&t.instance){const i=()=>{t.instance.triggerOnChange(o,r.value)};r.addEventListener("blur",i),r.addEventListener("input",i)}n.appendChild(r);const l=document.createElement("p");l.className="mt-1",l.style.cssText=`
|
|
11
11
|
font-size: var(--fb-font-size-small);
|
|
12
12
|
color: var(--fb-text-secondary-color);
|
|
13
|
-
`,l.textContent=S(e),n.appendChild(l)}function
|
|
13
|
+
`,l.textContent=S(e),n.appendChild(l)}function we(e,t,n,o){var a,r;const l=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;s.length<d;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-text-item").forEach((x,g)=>{const b=x.querySelector("input");b&&(b.name=`${o}[${g}]`)})}function f(x="",g=-1){const b=document.createElement("div");b.className="multiple-text-item flex items-center gap-2";const p=document.createElement("input");if(p.type="text",p.className="flex-1",p.style.cssText=`
|
|
14
14
|
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
15
15
|
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
16
16
|
border-radius: var(--fb-border-radius);
|
|
@@ -19,71 +19,71 @@ var FormBuilder=(function(L){"use strict";function de(e,t){(e.minLength!==null||
|
|
|
19
19
|
font-size: var(--fb-font-size);
|
|
20
20
|
font-family: var(--fb-font-family);
|
|
21
21
|
transition: all var(--fb-transition-duration) ease-in-out;
|
|
22
|
-
`,
|
|
22
|
+
`,p.placeholder=e.placeholder||"Enter text",p.value=x,p.readOnly=l.config.readonly,l.config.readonly||(p.addEventListener("focus",()=>{p.style.borderColor="var(--fb-border-focus-color)",p.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",p.style.outlineOffset="0"}),p.addEventListener("blur",()=>{p.style.borderColor="var(--fb-border-color)",p.style.outline="none"}),p.addEventListener("mouseenter",()=>{document.activeElement!==p&&(p.style.borderColor="var(--fb-border-hover-color)")}),p.addEventListener("mouseleave",()=>{document.activeElement!==p&&(p.style.borderColor="var(--fb-border-color)")})),!l.config.readonly&&t.instance){const C=()=>{t.instance.triggerOnChange(p.name,p.value)};p.addEventListener("blur",C),p.addEventListener("input",C)}return b.appendChild(p),g===-1?c.appendChild(b):c.insertBefore(b,c.children[g]),h(),b}function m(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-text-item"),g=x.length;x.forEach(b=>{let p=b.querySelector(".remove-item-btn");p||(p=document.createElement("button"),p.type="button",p.className="remove-item-btn px-2 py-1 rounded",p.style.cssText=`
|
|
23
23
|
color: var(--fb-error-color);
|
|
24
24
|
background-color: transparent;
|
|
25
25
|
transition: background-color var(--fb-transition-duration);
|
|
26
|
-
`,
|
|
26
|
+
`,p.innerHTML="\u2715",p.addEventListener("mouseenter",()=>{p.style.backgroundColor="var(--fb-background-hover-color)"}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor="transparent"}),p.onclick=()=>{const E=Array.from(c.children).indexOf(b);c.children.length>d&&(s.splice(E,1),b.remove(),h(),v(),m())},b.appendChild(p));const C=g<=d;p.disabled=C,p.style.opacity=C?"0.5":"1",p.style.pointerEvents=C?"none":"auto"})}function v(){const x=n.querySelector(".add-text-btn");if(x&&x.remove(),!l.config.readonly&&s.length<u){const g=document.createElement("button");g.type="button",g.className="add-text-btn mt-2 px-3 py-1 rounded",g.style.cssText=`
|
|
27
27
|
color: var(--fb-primary-color);
|
|
28
28
|
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
29
29
|
background-color: transparent;
|
|
30
30
|
font-size: var(--fb-font-size);
|
|
31
31
|
transition: all var(--fb-transition-duration);
|
|
32
|
-
`,g.textContent=`+ Add ${e.label||"Text"}`,g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{
|
|
32
|
+
`,g.textContent=`+ Add ${e.label||"Text"}`,g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{s.push(e.default||""),f(e.default||""),v(),m()},n.appendChild(g)}}s.forEach(x=>f(x)),v(),m();const y=document.createElement("p");y.className="mt-1",y.style.cssText=`
|
|
33
33
|
font-size: var(--fb-font-size-small);
|
|
34
34
|
color: var(--fb-text-secondary-color);
|
|
35
|
-
`,y.textContent=S(e),n.appendChild(y)}function
|
|
35
|
+
`,y.textContent=S(e),n.appendChild(y)}function _(e,t,n){var o,a,r;const l=[],{scopeRoot:i,skipValidation:s}=n,d=(c,h)=>{var f,m;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let y=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,y||(y=document.createElement("div"),y.id=v,y.className="error-message",y.style.cssText=`
|
|
36
36
|
color: var(--fb-error-color);
|
|
37
37
|
font-size: var(--fb-font-size-small);
|
|
38
38
|
margin-top: 0.25rem;
|
|
39
|
-
`,
|
|
39
|
+
`,c.nextSibling?(f=c.parentNode)==null||f.insertBefore(y,c.nextSibling):(m=c.parentNode)==null||m.appendChild(y)),y.textContent=h,y.style.display="block"):(c.classList.remove("invalid"),c.title="",y&&y.remove())},u=(c,h,f)=>{let m=!1;if(!s&&h){if(e.minLength!==void 0&&e.minLength!==null&&h.length<e.minLength)l.push(`${f}: minLength=${e.minLength}`),d(c,`minLength=${e.minLength}`),m=!0;else if(e.maxLength!==void 0&&e.maxLength!==null&&h.length>e.maxLength)l.push(`${f}: maxLength=${e.maxLength}`),d(c,`maxLength=${e.maxLength}`),m=!0;else if(e.pattern)try{new RegExp(e.pattern).test(h)||(l.push(`${f}: pattern mismatch`),d(c,"pattern mismatch"),m=!0)}catch(v){l.push(`${f}: invalid pattern`),d(c,"invalid pattern"),m=!0}}m||d(c,null)};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["]`),h=[];if(c.forEach((f,m)=>{var v;const y=(v=f==null?void 0:f.value)!=null?v:"";h.push(y),u(f,y,`${t}[${m}]`)}),!s){const f=(o=e.minCount)!=null?o:1,m=(a=e.maxCount)!=null?a:1/0,v=h.filter(y=>y.trim()!=="");e.required&&v.length===0&&l.push(`${t}: required`),v.length<f&&l.push(`${t}: minimum ${f} items required`),v.length>m&&l.push(`${t}: maximum ${m} items allowed`)}return{value:h,errors:l}}else{const c=i.querySelector(`[name$="${t}"]`),h=(r=c==null?void 0:c.value)!=null?r:"";return!s&&e.required&&h===""?(l.push(`${t}: required`),d(c,"required"),{value:"",errors:l}):(u(c,h,t),{value:h,errors:l})}}function W(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateTextField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(`[name^="${t}["]`);r.forEach((l,i)=>{i<n.length&&(l.value=n[i]!=null?String(n[i]):"",l.classList.remove("invalid"),l.title="")}),n.length!==r.length&&console.warn(`updateTextField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"]`);r&&(r.value=n!=null?String(n):"",r.classList.remove("invalid"),r.title="")}}function $e(e,t,n,o){const a=t.state,r=document.createElement("textarea");if(r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.rows=e.rows||4,r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const i=()=>{t.instance.triggerOnChange(o,r.value)};r.addEventListener("blur",i),r.addEventListener("input",i)}n.appendChild(r);const l=document.createElement("p");l.className="text-xs text-gray-500 mt-1",l.textContent=S(e),n.appendChild(l)}function ke(e,t,n,o){var a,r;const l=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;s.length<d;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-textarea-item").forEach((x,g)=>{const b=x.querySelector("textarea");b&&(b.name=`${o}[${g}]`)})}function f(x="",g=-1){const b=document.createElement("div");b.className="multiple-textarea-item";const p=document.createElement("textarea");if(p.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",p.placeholder=e.placeholder||"Enter text",p.rows=e.rows||4,p.value=x,p.readOnly=l.config.readonly,!l.config.readonly&&t.instance){const C=()=>{t.instance.triggerOnChange(p.name,p.value)};p.addEventListener("blur",C),p.addEventListener("input",C)}return b.appendChild(p),g===-1?c.appendChild(b):c.insertBefore(b,c.children[g]),h(),b}function m(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-textarea-item"),g=x.length;x.forEach(b=>{let p=b.querySelector(".remove-item-btn");p||(p=document.createElement("button"),p.type="button",p.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",p.innerHTML="\u2715 Remove",p.onclick=()=>{const E=Array.from(c.children).indexOf(b);c.children.length>d&&(s.splice(E,1),b.remove(),h(),v(),m())},b.appendChild(p));const C=g<=d;p.disabled=C,p.style.opacity=C?"0.5":"1",p.style.pointerEvents=C?"none":"auto"})}function v(){const x=n.querySelector(".add-textarea-btn");if(x&&x.remove(),!l.config.readonly&&s.length<u){const g=document.createElement("button");g.type="button",g.className="add-textarea-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",g.textContent=`+ Add ${e.label||"Textarea"}`,g.onclick=()=>{s.push(e.default||""),f(e.default||""),v(),m()},n.appendChild(g)}}s.forEach(x=>f(x)),v(),m();const y=document.createElement("p");y.className="text-xs text-gray-500 mt-1",y.textContent=S(e),n.appendChild(y)}function Le(e,t,n){return _(e,t,n)}function Se(e,t,n,o){W(e,t,n,o)}function Fe(e,t,n,o){const a=t.state,r=document.createElement("input");if(r.type="number",r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",r.name=o,r.placeholder=e.placeholder||"0",e.min!==void 0&&(r.min=e.min.toString()),e.max!==void 0&&(r.max=e.max.toString()),e.step!==void 0&&(r.step=e.step.toString()),r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const i=()=>{const s=r.value?parseFloat(r.value):null;t.instance.triggerOnChange(o,s)};r.addEventListener("blur",i),r.addEventListener("input",i)}n.appendChild(r);const l=document.createElement("p");l.className="text-xs text-gray-500 mt-1",l.textContent=S(e),n.appendChild(l)}function Ne(e,t,n,o){var a,r;const l=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;s.length<d;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-number-item").forEach((x,g)=>{const b=x.querySelector("input");b&&(b.name=`${o}[${g}]`)})}function f(x="",g=-1){const b=document.createElement("div");b.className="multiple-number-item flex items-center gap-2";const p=document.createElement("input");if(p.type="number",p.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",p.placeholder=e.placeholder||"0",e.min!==void 0&&(p.min=e.min.toString()),e.max!==void 0&&(p.max=e.max.toString()),e.step!==void 0&&(p.step=e.step.toString()),p.value=x.toString(),p.readOnly=l.config.readonly,!l.config.readonly&&t.instance){const C=()=>{const E=p.value?parseFloat(p.value):null;t.instance.triggerOnChange(p.name,E)};p.addEventListener("blur",C),p.addEventListener("input",C)}return b.appendChild(p),g===-1?c.appendChild(b):c.insertBefore(b,c.children[g]),h(),b}function m(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-number-item"),g=x.length;x.forEach(b=>{let p=b.querySelector(".remove-item-btn");p||(p=document.createElement("button"),p.type="button",p.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",p.innerHTML="\u2715",p.onclick=()=>{const E=Array.from(c.children).indexOf(b);c.children.length>d&&(s.splice(E,1),b.remove(),h(),v(),m())},b.appendChild(p));const C=g<=d;p.disabled=C,p.style.opacity=C?"0.5":"1",p.style.pointerEvents=C?"none":"auto"})}function v(){const x=n.querySelector(".add-number-btn");if(x&&x.remove(),!l.config.readonly&&s.length<u){const g=document.createElement("button");g.type="button",g.className="add-number-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",g.textContent=`+ Add ${e.label||"Number"}`,g.onclick=()=>{s.push(e.default||""),f(e.default||""),v(),m()},n.appendChild(g)}}s.forEach(x=>f(x)),v(),m();const y=document.createElement("p");y.className="text-xs text-gray-500 mt-1",y.textContent=S(e),n.appendChild(y)}function Ae(e,t,n){var o,a,r,l,i;const s=[],{scopeRoot:d,skipValidation:u}=n,c=(f,m)=>{var v,y;if(!f)return;const x=`error-${f.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(x);m?(f.classList.add("invalid"),f.title=m,g||(g=document.createElement("div"),g.id=x,g.className="error-message",g.style.cssText=`
|
|
40
40
|
color: var(--fb-error-color);
|
|
41
41
|
font-size: var(--fb-font-size-small);
|
|
42
42
|
margin-top: 0.25rem;
|
|
43
|
-
`,
|
|
43
|
+
`,f.nextSibling?(v=f.parentNode)==null||v.insertBefore(g,f.nextSibling):(y=f.parentNode)==null||y.appendChild(g)),g.textContent=m,g.style.display="block"):(f.classList.remove("invalid"),f.title="",g&&g.remove())},h=(f,m,v)=>{let y=!1;!u&&e.min!==void 0&&e.min!==null&&m<e.min?(s.push(`${v}: < min=${e.min}`),c(f,`< min=${e.min}`),y=!0):!u&&e.max!==void 0&&e.max!==null&&m>e.max&&(s.push(`${v}: > max=${e.max}`),c(f,`> max=${e.max}`),y=!0),y||c(f,null)};if(e.multiple){const f=d.querySelectorAll(`[name^="${t}["]`),m=[];if(f.forEach((v,y)=>{var x,g,b;const p=(x=v==null?void 0:v.value)!=null?x:"";if(p===""){m.push(null),c(v,null);return}const C=parseFloat(p);if(!u&&!Number.isFinite(C)){s.push(`${t}[${y}]: not a number`),c(v,"not a number"),m.push(null);return}h(v,C,`${t}[${y}]`);const E=Number.isInteger((g=e.decimals)!=null?g:0)&&(b=e.decimals)!=null?b:0;m.push(Number(C.toFixed(E)))}),!u){const v=(o=e.minCount)!=null?o:1,y=(a=e.maxCount)!=null?a:1/0,x=m.filter(g=>g!==null);e.required&&x.length===0&&s.push(`${t}: required`),x.length<v&&s.push(`${t}: minimum ${v} items required`),x.length>y&&s.push(`${t}: maximum ${y} items allowed`)}return{value:m,errors:s}}else{const f=d.querySelector(`[name$="${t}"]`),m=(r=f==null?void 0:f.value)!=null?r:"";if(!u&&e.required&&m==="")return s.push(`${t}: required`),c(f,"required"),{value:null,errors:s};if(m==="")return c(f,null),{value:null,errors:s};const v=parseFloat(m);if(!u&&!Number.isFinite(v))return s.push(`${t}: not a number`),c(f,"not a number"),{value:null,errors:s};h(f,v,t);const y=Number.isInteger((l=e.decimals)!=null?l:0)&&(i=e.decimals)!=null?i:0;return{value:Number(v.toFixed(y)),errors:s}}}function Te(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateNumberField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(`[name^="${t}["]`);r.forEach((l,i)=>{i<n.length&&(l.value=n[i]!=null?String(n[i]):"",l.classList.remove("invalid"),l.title="")}),n.length!==r.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"]`);r&&(r.value=n!=null?String(n):"",r.classList.remove("invalid"),r.title="")}}function qe(e,t,n,o){const a=t.state,r=document.createElement("select");if(r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",r.name=o,r.disabled=a.config.readonly,(e.options||[]).forEach(i=>{const s=document.createElement("option");s.value=i.value,s.textContent=i.label,(t.prefill[e.key]||e.default)===i.value&&(s.selected=!0),r.appendChild(s)}),!a.config.readonly&&t.instance){const i=()=>{t.instance.triggerOnChange(o,r.value)};r.addEventListener("change",i)}n.appendChild(r);const l=document.createElement("p");l.className="text-xs text-gray-500 mt-1",l.textContent=S(e),n.appendChild(l)}function He(e,t,n,o){var a,r,l,i;const s=t.state,d=t.prefill[e.key]||[],u=Array.isArray(d)?[...d]:[],c=(a=e.minCount)!=null?a:1,h=(r=e.maxCount)!=null?r:1/0;for(;u.length<c;)u.push(e.default||((i=(l=e.options)==null?void 0:l[0])==null?void 0:i.value)||"");const f=document.createElement("div");f.className="space-y-2",n.appendChild(f);function m(){f.querySelectorAll(".multiple-select-item").forEach((b,p)=>{const C=b.querySelector("select");C&&(C.name=`${o}[${p}]`)})}function v(b="",p=-1){const C=document.createElement("div");C.className="multiple-select-item flex items-center gap-2";const E=document.createElement("select");if(E.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",E.disabled=s.config.readonly,(e.options||[]).forEach($=>{const w=document.createElement("option");w.value=$.value,w.textContent=$.label,b===$.value&&(w.selected=!0),E.appendChild(w)}),!s.config.readonly&&t.instance){const $=()=>{t.instance.triggerOnChange(E.name,E.value)};E.addEventListener("change",$)}return C.appendChild(E),p===-1?f.appendChild(C):f.insertBefore(C,f.children[p]),m(),C}function y(){if(s.config.readonly)return;const b=f.querySelectorAll(".multiple-select-item"),p=b.length;b.forEach(C=>{let E=C.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",E.innerHTML="\u2715",E.onclick=()=>{const w=Array.from(f.children).indexOf(C);f.children.length>c&&(u.splice(w,1),C.remove(),m(),x(),y())},C.appendChild(E));const $=p<=c;E.disabled=$,E.style.opacity=$?"0.5":"1",E.style.pointerEvents=$?"none":"auto"})}function x(){const b=n.querySelector(".add-select-btn");if(b&&b.remove(),!s.config.readonly&&u.length<h){const p=document.createElement("button");p.type="button",p.className="add-select-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",p.textContent=`+ Add ${e.label||"Selection"}`,p.onclick=()=>{var C,E;const $=e.default||((E=(C=e.options)==null?void 0:C[0])==null?void 0:E.value)||"";u.push($),v($),x(),y()},n.appendChild(p)}}u.forEach(b=>v(b)),x(),y();const g=document.createElement("p");g.className="text-xs text-gray-500 mt-1",g.textContent=S(e),n.appendChild(g)}function Me(e,t,n){var o;const a=[],{scopeRoot:r,skipValidation:l}=n,i=(d,u)=>{var c,h;if(!d)return;const f=`error-${d.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(f);u?(d.classList.add("invalid"),d.title=u,m||(m=document.createElement("div"),m.id=f,m.className="error-message",m.style.cssText=`
|
|
44
44
|
color: var(--fb-error-color);
|
|
45
45
|
font-size: var(--fb-font-size-small);
|
|
46
46
|
margin-top: 0.25rem;
|
|
47
|
-
`,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
47
|
+
`,d.nextSibling?(c=d.parentNode)==null||c.insertBefore(m,d.nextSibling):(h=d.parentNode)==null||h.appendChild(m)),m.textContent=u,m.style.display="block"):(d.classList.remove("invalid"),d.title="",m&&m.remove())},s=(d,u,c,h)=>{var f,m;if(l)return;const v=u.filter(h),y="minCount"in c&&(f=c.minCount)!=null?f:1,x="maxCount"in c&&(m=c.maxCount)!=null?m:1/0;c.required&&v.length===0&&a.push(`${d}: required`),v.length<y&&a.push(`${d}: minimum ${y} items required`),v.length>x&&a.push(`${d}: maximum ${x} items allowed`)};if("multiple"in e&&e.multiple){const d=r.querySelectorAll(`[name^="${t}["]`),u=[];return d.forEach(c=>{var h;const f=(h=c==null?void 0:c.value)!=null?h:"";u.push(f),i(c,null)}),s(t,u,e,c=>c!==""),{value:u,errors:a}}else{const d=r.querySelector(`[name$="${t}"]`),u=(o=d==null?void 0:d.value)!=null?o:"";return!l&&e.required&&u===""?(a.push(`${t}: required`),i(d,"required"),{value:null,errors:a}):(i(d,null),{value:u===""?null:u,errors:a})}}function Be(e,t,n,o){const{scopeRoot:a}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSelectField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(`[name^="${t}["]`);r.forEach((l,i)=>{i<n.length&&(l.value=n[i]!=null?String(n[i]):"",l.querySelectorAll("option").forEach(s=>{s.selected=s.value===String(n[i])}),l.classList.remove("invalid"),l.title="")}),n.length!==r.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${r.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"]`);r&&(r.value=n!=null?String(n):"",r.querySelectorAll("option").forEach(l=>{l.selected=l.value===String(n)}),r.classList.remove("invalid"),r.title="")}}function L(e,t){const n=t.config.locale||"en";return(t.config.translations[n]||t.config.translations.en)[e]||e}function ze(e,t,n){const o=document.createElement("img");o.className="w-full h-full object-contain",o.alt=n||"Preview";const a=new FileReader;a.onload=r=>{var l;o.src=((l=r.target)==null?void 0:l.result)||""},a.readAsDataURL(t),e.appendChild(o)}function je(e,t,n,o,a,r){const l=URL.createObjectURL(t);e.onclick=null;const i=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(i,e),i.innerHTML=`
|
|
48
|
+
<div class="relative group h-full">
|
|
49
|
+
<video class="w-full h-full object-contain" controls preload="auto" muted>
|
|
50
|
+
<source src="${l}" type="${n}">
|
|
51
|
+
Your browser does not support the video tag.
|
|
52
|
+
</video>
|
|
53
|
+
<div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
|
|
54
|
+
<button class="bg-red-600 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs delete-file-btn">
|
|
55
|
+
${L("removeElement",a)}
|
|
56
|
+
</button>
|
|
57
|
+
<button class="bg-gray-800 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs change-file-btn">
|
|
58
|
+
Change
|
|
59
|
+
</button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
`,Ie(i,o,a,r),i}function Ie(e,t,n,o){const a=e.querySelector(".change-file-btn");a&&(a.onclick=l=>{l.stopPropagation(),o!=null&&o.picker&&o.picker.click()});const r=e.querySelector(".delete-file-btn");r&&(r.onclick=l=>{l.stopPropagation(),De(e,t,n,o)})}function De(e,t,n,o){var a;n.resourceIndex.delete(t);const r=(a=e.parentElement)==null?void 0:a.querySelector('input[type="hidden"]');r&&(r.value=""),o!=null&&o.fileUploadHandler&&(e.onclick=o.fileUploadHandler),o!=null&&o.dragHandler&&R(e,o.dragHandler),e.innerHTML=`
|
|
63
|
+
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
64
|
+
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
65
|
+
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
66
|
+
</svg>
|
|
67
|
+
<div class="text-sm text-center">${L("clickDragText",n)}</div>
|
|
68
|
+
</div>
|
|
69
|
+
`}function Re(e,t,n){const o=document.createElement("video");o.className="w-full h-full object-contain",o.controls=!0,o.preload="metadata",o.muted=!0;const a=document.createElement("source");a.src=t,a.type=n,o.appendChild(a),o.appendChild(document.createTextNode("Your browser does not support the video tag.")),e.appendChild(o)}function Ue(e,t,n){_e(e,n,()=>{var o;n.resourceIndex.delete(t);const a=(o=e.parentElement)==null?void 0:o.querySelector('input[type="hidden"]');a&&(a.value=""),e.innerHTML=`
|
|
70
|
+
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
71
|
+
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
72
|
+
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
73
|
+
</svg>
|
|
74
|
+
<div class="text-sm text-center">${L("clickDragText",n)}</div>
|
|
75
|
+
</div>
|
|
76
|
+
`})}async function Oe(e,t,n,o,a,r,l){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?ze(e,t.file,n):t.type&&t.type.startsWith("video/")?e=je(e,t.file,t.type,o,r,l):e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400"><div class="text-2xl mb-2">\u{1F4C1}</div><div class="text-sm">${n}</div></div>`,!a&&!(t.type&&t.type.startsWith("video/"))&&Ue(e,o,r))}async function Pe(e,t,n,o,a){if(!a.config.getThumbnail){D(e,a);return}try{const r=await a.config.getThumbnail(t);if(r)if(T(e),o&&o.type&&o.type.startsWith("video/"))Re(e,r,o.type);else{const l=document.createElement("img");l.className="w-full h-full object-contain",l.alt=n||"Preview",l.src=r,e.appendChild(l)}else D(e,a)}catch(r){console.error("Failed to get thumbnail:",r),e.innerHTML=`
|
|
77
|
+
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
78
|
+
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
79
|
+
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
80
|
+
</svg>
|
|
81
|
+
<div class="text-sm text-center">${n||"Preview unavailable"}</div>
|
|
82
|
+
</div>
|
|
83
|
+
`}}async function G(e,t,n,o={}){const{fileName:a="",isReadonly:r=!1,deps:l=null}=o;if(!r&&l&&(!l.picker||!l.fileUploadHandler||!l.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");T(e),r&&e.classList.add("cursor-pointer");const i=n.resourceIndex.get(t);i&&i.file&&i.file instanceof File?await Oe(e,i,a,t,r,n,l):await Pe(e,t,a,i,n)}async function I(e,t,n){var o,a;const r=t.resourceIndex.get(e),l=(r==null?void 0:r.name)||e.split("/").pop()||"file",i=l.toLowerCase().match(/\.psd$/),s=document.createElement("div");s.className=i?"space-y-2":"space-y-3";const d=document.createElement("div");i?d.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":d.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const u=!i&&(((o=r==null?void 0:r.type)==null?void 0:o.startsWith("image/"))||l.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),c=((a=r==null?void 0:r.type)==null?void 0:a.startsWith("video/"))||l.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(u)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?d.innerHTML=`<img src="${m}" alt="${l}" class="w-full h-auto">`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${l}</div></div></div>`}catch(m){console.warn("getThumbnail failed for",e,m),d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${l}</div></div></div>`}else d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${l}</div></div></div>`;else if(c)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?d.innerHTML=`
|
|
84
84
|
<div class="relative group">
|
|
85
85
|
<video class="w-full h-auto" controls preload="auto" muted>
|
|
86
|
-
<source src="${
|
|
86
|
+
<source src="${m}" type="${(r==null?void 0:r.type)||"video/mp4"}">
|
|
87
87
|
\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.
|
|
88
88
|
</video>
|
|
89
89
|
<div class="absolute inset-0 bg-black bg-opacity-20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center pointer-events-none">
|
|
@@ -94,27 +94,27 @@ var FormBuilder=(function(L){"use strict";function de(e,t){(e.minLength!==null||
|
|
|
94
94
|
</div>
|
|
95
95
|
</div>
|
|
96
96
|
</div>
|
|
97
|
-
`:
|
|
97
|
+
`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`}catch(m){console.warn("getThumbnail failed for video",e,m),d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`}else d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${l}</div></div></div>`;else{const m=i?"\u{1F3A8}":"\u{1F4C1}",v=i?"PSD File":"Document";i?d.innerHTML=`
|
|
98
98
|
<div class="flex items-center space-x-3">
|
|
99
|
-
<div class="text-3xl text-gray-400">${
|
|
99
|
+
<div class="text-3xl text-gray-400">${m}</div>
|
|
100
100
|
<div class="flex-1 min-w-0">
|
|
101
101
|
<div class="text-sm font-medium text-gray-900 truncate">${l}</div>
|
|
102
102
|
<div class="text-xs text-gray-500">${v}</div>
|
|
103
103
|
</div>
|
|
104
104
|
</div>
|
|
105
|
-
`:
|
|
105
|
+
`:d.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${m}</div><div class="text-sm">${l}</div><div class="text-xs text-gray-500 mt-1">${v}</div></div></div>`}const h=document.createElement("p");h.className=i?"hidden":"text-sm font-medium text-gray-900 text-center",h.textContent=l;const f=document.createElement("button");return f.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",f.textContent=L("downloadButton",t),f.onclick=m=>{m.preventDefault(),m.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,l):We(e,l,t)},s.appendChild(d),s.appendChild(h),s.appendChild(f),s}function J(e,t,n,o){T(e);const a=!e.classList.contains("grid");if((!t||t.length===0)&&a){const i=document.createElement("div");i.className="grid grid-cols-4 gap-3 mb-3";for(let u=0;u<4;u++){const c=document.createElement("div");c.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors";const h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("class","w-12 h-12 text-gray-400"),h.setAttribute("fill","currentColor"),h.setAttribute("viewBox","0 0 24 24");const f=document.createElementNS("http://www.w3.org/2000/svg","path");f.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"),h.appendChild(f),c.appendChild(h),c.onclick=()=>{let m=e.parentElement;for(;m&&!m.classList.contains("space-y-2");)m=m.parentElement;!m&&e.classList.contains("space-y-2")&&(m=e);const v=m==null?void 0:m.querySelector('input[type="file"]');v&&v.click()},i.appendChild(c)}const s=document.createElement("div");s.className="text-center text-xs text-gray-600";const d=document.createElement("span");d.className="underline cursor-pointer",d.textContent=L("uploadText",n),d.onclick=u=>{u.stopPropagation();let c=e.parentElement;for(;c&&!c.classList.contains("space-y-2");)c=c.parentElement;!c&&e.classList.contains("space-y-2")&&(c=e);const h=c==null?void 0:c.querySelector('input[type="file"]');h&&h.click()},s.appendChild(d),s.appendChild(document.createTextNode(` ${L("dragDropText",n)}`)),e.appendChild(i),e.appendChild(s);return}e.className="files-list grid grid-cols-4 gap-3 mt-2";const r=t?t.length:0,l=(Math.floor(r/4)+1)*4;for(let i=0;i<l;i++){const s=document.createElement("div");if(t&&i<t.length){const d=t[i],u=n.resourceIndex.get(d);if(s.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",s.dataset.resourceId=d,Ve(s,d,u,n).catch(c=>{console.error("Failed to render thumbnail:",c),s.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
106
106
|
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
107
107
|
<div class="text-xs">Preview error</div>
|
|
108
|
-
</div>`}),o){const
|
|
108
|
+
</div>`}),o){const c=document.createElement("div");c.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const h=document.createElement("button");h.className="bg-red-600 text-white px-2 py-1 rounded text-xs",h.textContent=L("removeElement",n),h.onclick=f=>{f.stopPropagation(),o(d)},c.appendChild(h),s.appendChild(c)}}else s.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",s.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>',s.onclick=()=>{let d=e.parentElement;for(;d&&!d.classList.contains("space-y-2");)d=d.parentElement;!d&&e.classList.contains("space-y-2")&&(d=e);const u=d==null?void 0:d.querySelector('input[type="file"]');u&&u.click()};e.appendChild(s)}}function Y(e,t="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
109
109
|
<svg class="${t} text-red-400" fill="currentColor" viewBox="0 0 24 24">
|
|
110
110
|
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
|
|
111
111
|
</svg>
|
|
112
112
|
<div class="text-xs mt-1 text-red-600">Preview error</div>
|
|
113
|
-
</div>`}async function
|
|
113
|
+
</div>`}async function Ve(e,t,n,o){var a,r;if(n&&(a=n.type)!=null&&a.startsWith("image/"))if(n.file&&n.file instanceof File){const l=document.createElement("img");l.className="w-full h-full object-contain",l.alt=n.name;const i=new FileReader;i.onload=s=>{var d;l.src=((d=s.target)==null?void 0:d.result)||""},i.readAsDataURL(n.file),e.appendChild(l)}else if(o.config.getThumbnail)try{const l=await o.config.getThumbnail(t);if(l){const i=document.createElement("img");i.className="w-full h-full object-contain",i.alt=n.name,i.src=l,e.appendChild(i)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
114
114
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
115
115
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
116
116
|
</svg>
|
|
117
|
-
</div>`}catch(l){const
|
|
117
|
+
</div>`}catch(l){const i=l instanceof Error?l:new Error(String(l));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),Y(e)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
118
118
|
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
119
119
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
120
120
|
</svg>
|
|
@@ -149,7 +149,7 @@ var FormBuilder=(function(L){"use strict";function de(e,t){(e.minLength!==null||
|
|
|
149
149
|
<path d="M8 5v14l11-7z"/>
|
|
150
150
|
</svg>
|
|
151
151
|
<div class="text-xs mt-1">${(n==null?void 0:n.name)||"Video"}</div>
|
|
152
|
-
</div>`}catch(l){const
|
|
152
|
+
</div>`}catch(l){const i=l instanceof Error?l:new Error(String(l));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),Y(e,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
153
153
|
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
154
154
|
<path d="M8 5v14l11-7z"/>
|
|
155
155
|
</svg>
|
|
@@ -162,14 +162,71 @@ var FormBuilder=(function(L){"use strict";function de(e,t){(e.minLength!==null||
|
|
|
162
162
|
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
163
163
|
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
164
164
|
</svg>
|
|
165
|
-
<div class="text-sm text-center">${
|
|
165
|
+
<div class="text-sm text-center">${L("clickDragText",t)}</div>
|
|
166
166
|
</div>
|
|
167
|
-
`}async function J(e,t,n,o,s=null,r){var l,a;let i;if(o.config.uploadFile)try{if(i=await o.config.uploadFile(e),typeof i!="string")throw new Error("Upload handler must return a string resource ID")}catch(u){const d=u instanceof Error?u:new Error(String(u));throw o.config.onUploadError&&o.config.onUploadError(d,e),new Error(`File upload failed: ${d.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(i,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let c=(l=t.parentElement)==null?void 0:l.querySelector('input[type="hidden"]');c||(c=document.createElement("input"),c.type="hidden",c.name=n,(a=t.parentElement)==null||a.appendChild(c)),c.value=i,_(t,i,o,{fileName:e.name,isReadonly:!1,deps:s}).catch(console.error),r&&!o.config.readonly&&r.triggerOnChange(n,i)}function I(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 qe(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const s=document.createElement("div");s.className="delete-overlay absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const r=document.createElement("button");r.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",r.textContent=F("removeElement",t),r.onclick=l=>{l.stopPropagation(),n()},s.appendChild(r),e.appendChild(s)}async function Y(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 He(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 s=o.startsWith("http")?o:new URL(o,window.location.href).href,r=await fetch(s);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const l=await r.blob();Me(l,t)}else throw new Error("No download URL available for resource")}catch(o){const s=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(s,e,t),console.error(`File download failed for ${t}:`,s),s}}function Me(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 X(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const s=n.split("/").pop()||"file",r=(o=s.split(".").pop())==null?void 0:o.toLowerCase();let l="application/octet-stream";r&&(["jpg","jpeg","png","gif","webp"].includes(r)?l=`image/${r==="jpg"?"jpeg":r}`:["mp4","webm","mov","avi"].includes(r)&&(l=`video/${r==="mov"?"quicktime":r}`)),t.resourceIndex.set(n,{name:s,type:l,size:0,uploadedAt:new Date,file:void 0})}})}function Be(e,t,n,o,s,r){var l;if(!s.resourceIndex.has(e)){const i=e.split("/").pop()||"file",c=(l=i.split(".").pop())==null?void 0:l.toLowerCase();let u="application/octet-stream";c&&(["jpg","jpeg","png","gif","webp"].includes(c)?u=`image/${c==="jpg"?"jpeg":c}`:["mp4","webm","mov","avi"].includes(c)&&(u=`video/${c==="mov"?"quicktime":c}`)),s.resourceIndex.set(e,{name:i,type:u,size:0,uploadedAt:new Date,file:void 0})}_(t,e,s,{fileName:e,isReadonly:!1,deps:r}).catch(console.error);const a=document.createElement("input");a.type="hidden",a.name=n,a.value=e,o.appendChild(a)}function Z(e,t,n,o,s,r){I(e,async l=>{const a=Array.from(l);for(const i of a){const c=await Y(i,n);n.resourceIndex.set(c,{name:i.name,type:i.type,size:i.size,uploadedAt:new Date,file:void 0}),t.push(c)}o(),r&&s&&!n.config.readonly&&r.triggerOnChange(s,t)})}function K(e,t,n,o,s,r){e.onchange=async()=>{if(e.files)for(const l of Array.from(e.files)){const a=await Y(l,n);n.resourceIndex.set(a,{name:l.name,type:l.type,size:l.size,uploadedAt:new Date,file:void 0}),t.push(a)}o(),e.value="",r&&s&&!n.config.readonly&&r.triggerOnChange(s,t)}}function je(e,t,n,o){var s;const r=t.state;if(r.config.readonly){const l=t.prefill[e.key];if(l)z(l,r).then(a=>{n.appendChild(a)}).catch(a=>{console.error("Failed to render file preview:",a);const i=document.createElement("div");i.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",i.innerHTML='<div class="text-center">Preview unavailable</div>',n.appendChild(i)});else{const a=document.createElement("div");a.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",a.innerHTML=`<div class="text-center">${F("noFileSelected",r)}</div>`,n.appendChild(a)}}else{const l=document.createElement("div");l.className="space-y-2";const a=document.createElement("input");a.type="file",a.name=o,a.style.display="none",e.accept&&(a.accept=typeof e.accept=="string"?e.accept:((s=e.accept.extensions)==null?void 0:s.map(v=>`.${v}`).join(","))||"");const i=document.createElement("div");i.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const c=t.prefill[e.key],u=()=>a.click(),d=v=>{if(v.length>0){const y={picker:a,fileUploadHandler:u,dragHandler:d};J(v[0],i,o,r,y,t.instance)}};c?Be(c,i,o,l,r,{picker:a,fileUploadHandler:u,dragHandler:d}):D(i,r),i.onclick=u,I(i,d),a.onchange=()=>{if(a.files&&a.files.length>0){const v={picker:a,fileUploadHandler:u,dragHandler:d};J(a.files[0],i,o,r,v,t.instance)}},l.appendChild(i),l.appendChild(a);const h=document.createElement("p");h.className="text-xs text-gray-600 mt-2 text-center",h.innerHTML=`<span class="underline cursor-pointer">${F("uploadText",r)}</span> ${F("dragDropTextSingle",r)}`;const m=h.querySelector("span");m&&(m.onclick=()=>a.click()),l.appendChild(h);const p=document.createElement("p");p.className="text-xs text-gray-500 mt-1 text-center",p.textContent=S(e),l.appendChild(p),n.appendChild(l)}}function ze(e,t,n,o){var s;const r=t.state;if(r.config.readonly){const l=document.createElement("div");l.className="space-y-4";const a=t.prefill[e.key]||[];a.length>0?a.forEach(i=>{z(i,r).then(c=>{l.appendChild(c)}).catch(c=>{console.error("Failed to render file preview:",c)})}):l.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${F("noFilesSelected",r)}</div></div>`,n.appendChild(l)}else{let l=function(){W(u,d,r,m=>{const p=d.indexOf(m);p>-1&&d.splice(p,1),l()})};const a=document.createElement("div");a.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.multiple=!0,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((s=e.accept.extensions)==null?void 0:s.map(m=>`.${m}`).join(","))||"");const c=document.createElement("div");c.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const u=document.createElement("div");u.className="files-list";const d=t.prefill[e.key]||[];X(d,r),l(),Z(c,d,r,l,o,t.instance),K(i,d,r,l,o,t.instance),c.appendChild(u),a.appendChild(c),a.appendChild(i);const h=document.createElement("p");h.className="text-xs text-gray-500 mt-1 text-center",h.textContent=S(e),a.appendChild(h),n.appendChild(a)}}function De(e,t,n,o){var s,r,l;const a=t.state,i=(s=e.minCount)!=null?s:0,c=(r=e.maxCount)!=null?r:1/0;if(a.config.readonly){const u=document.createElement("div");u.className="space-y-4";const d=t.prefill[e.key]||[];d.length>0?d.forEach(h=>{z(h,a).then(m=>{u.appendChild(m)}).catch(m=>{console.error("Failed to render file preview:",m)})}):u.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${F("noFilesSelected",a)}</div></div>`,n.appendChild(u)}else{const u=document.createElement("div");u.className="space-y-2";const d=document.createElement("input");d.type="file",d.name=o,d.multiple=!0,d.style.display="none",e.accept&&(d.accept=typeof e.accept=="string"?e.accept:((l=e.accept.extensions)==null?void 0:l.map(v=>`.${v}`).join(","))||"");const h=document.createElement("div");h.className="files-list space-y-2",u.appendChild(d),u.appendChild(h);const m=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];X(m,a);const p=()=>{W(h,m,a,b=>{m.splice(m.indexOf(b),1),p()});const v=document.createElement("div");v.className="text-xs text-gray-500 mt-2 file-count-info";const y=`${m.length} file${m.length!==1?"s":""}`,x=i>0||c<1/0?` (${i}-${c} allowed)`:"";v.textContent=y+x;const g=u.querySelector(".file-count-info");g&&g.remove(),u.appendChild(v)};Z(h,m,a,p,o,t.instance),K(d,m,a,p,o,t.instance),p(),n.appendChild(u)}}function Q(e,t,n){var o;const s=[],{scopeRoot:r,skipValidation:l,path:a}=n,i=e.type==="files"||"multiple"in e&&!!e.multiple,c=(u,d,h)=>{var m,p;if(l)return;const v="minCount"in h&&(m=h.minCount)!=null?m:0,y="maxCount"in h&&(p=h.maxCount)!=null?p:1/0;h.required&&d.length===0&&s.push(`${u}: required`),d.length<v&&s.push(`${u}: minimum ${v} files required`),d.length>y&&s.push(`${u}: maximum ${y} files allowed`)};if(i){const u=N(a,t),d=r.querySelector(`input[type="file"][name="${u}"]`),h=d==null?void 0:d.closest(".space-y-2"),m=(h==null?void 0:h.querySelector(".files-list"))||null,p=[];return m&&m.querySelectorAll(".resource-pill").forEach(v=>{const y=v.dataset.resourceId;y&&p.push(y)}),c(t,p,e),{value:p,errors:s}}else{const u=r.querySelector(`input[name$="${t}"][type="hidden"]`),d=(o=u==null?void 0:u.value)!=null?o:"";return!l&&e.required&&d===""?(s.push(`${t}: required`),{value:null,errors:s}):{value:d||null,errors:s}}}function ee(e,t,n,o){var s;const{scopeRoot:r,state:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(a=>{var i;if(a&&typeof a=="string"&&!l.resourceIndex.has(a)){const c=a.split("/").pop()||"file",u=(i=c.split(".").pop())==null?void 0:i.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),l.resourceIndex.set(a,{name:c,type:d,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const a=r.querySelector(`input[name="${t}"][type="hidden"]`);if(!a){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(a.value=n!=null?String(n):"",n&&typeof n=="string"){if(!l.resourceIndex.has(n)){const i=n.split("/").pop()||"file",c=(s=i.split(".").pop())==null?void 0:s.toLowerCase();let u="application/octet-stream";c&&(["jpg","jpeg","png","gif","webp"].includes(c)?u=`image/${c==="jpg"?"jpeg":c}`:["mp4","webm","mov","avi"].includes(c)&&(u=`video/${c==="mov"?"quicktime":c}`)),l.resourceIndex.set(n,{name:i,type:u,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}let R=null;function Ie(e){R=e}function H(e,t){if(!R)throw new Error("renderElement not initialized. Import from components/index.ts");return R(e,t)}function te(e,t,n,o){var s,r;const l=document.createElement("div");l.className="border border-gray-200 rounded-lg p-4 bg-gray-50",l.setAttribute("data-container",o);const a=document.createElement("div");a.className="flex justify-between items-center mb-4";const i=document.createElement("div");i.className="flex-1";const c=document.createElement("div");c.className="space-y-4",l.appendChild(a),a.appendChild(i);const u={path:N(t.path,e.key),prefill:((s=t.prefill)==null?void 0:s[e.key])||{},formData:(r=t.formData)!=null?r:t.prefill,state:t.state};e.elements.forEach(d=>{d.hidden||c.appendChild(H(d,u))}),l.appendChild(c),i.innerHTML=`<span>${e.label||e.key}</span>`,n.appendChild(l)}function ne(e,t,n,o){var s,r,l,a;const i=t.state,c=document.createElement("div");c.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const u=document.createElement("div");u.className="flex justify-between items-center mb-4";const d=document.createElement("div");d.className="flex-1";const h=document.createElement("div");h.className="flex gap-2";const m=document.createElement("div");m.className="space-y-4",c.appendChild(u),u.appendChild(d),i.config.readonly||u.appendChild(h);const p=(s=e.minCount)!=null?s:0,v=(r=e.maxCount)!=null?r:1/0,y=Array.isArray((l=t.prefill)==null?void 0:l[e.key])?t.prefill[e.key]:null,x=()=>m.querySelectorAll(":scope > .containerItem").length,g=()=>{const f=document.createElement("button");return f.type="button",f.className="px-3 py-1.5 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 transition-colors",f.textContent=F("addElement",i),f.onclick=()=>{var C;if(x()<v){const E=x(),$={state:t.state,path:N(t.path,`${e.key}[${E}]`),prefill:{},formData:(C=t.formData)!=null?C:t.prefill},w=document.createElement("div");if(w.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",w.setAttribute("data-container-item",`${e.key}[${E}]`),e.elements.forEach(k=>{k.hidden||w.appendChild(H(k,$))}),!i.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors",k.textContent="\xD7",k.onclick=()=>{w.remove(),b()},w.style.position="relative",w.appendChild(k)}m.appendChild(w),b()}},f},b=()=>{const f=x(),C=h.querySelector("button");C&&(C.disabled=f>=v,C.style.opacity=f>=v?"0.5":"1"),d.innerHTML=`<span>${e.label||e.key}</span> <span class="text-sm text-gray-500">(${f}/${v===1/0?"\u221E":v})</span>`};if(i.config.readonly||h.appendChild(g()),y&&Array.isArray(y)&&y.forEach((f,C)=>{var E;const $={state:t.state,path:N(t.path,`${e.key}[${C}]`),prefill:f||{},formData:(E=t.formData)!=null?E:t.prefill},w=document.createElement("div");if(w.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",w.setAttribute("data-container-item",`${e.key}[${C}]`),e.elements.forEach(k=>{k.hidden||w.appendChild(H(k,$))}),!i.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors",k.textContent="\xD7",k.onclick=()=>{w.remove(),b()},w.style.position="relative",w.appendChild(k)}m.appendChild(w)}),!i.config.readonly)for(;x()<p;){const f=x(),C={state:t.state,path:N(t.path,`${e.key}[${f}]`),prefill:{},formData:(a=t.formData)!=null?a:t.prefill},E=document.createElement("div");E.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",E.setAttribute("data-container-item",`${e.key}[${f}]`),e.elements.forEach(w=>{w.hidden||E.appendChild(H(w,C))});const $=document.createElement("button");$.type="button",$.className="absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors",$.textContent="\xD7",$.onclick=()=>{x()>p&&(E.remove(),b())},E.style.position="relative",E.appendChild($),m.appendChild(E)}c.appendChild(m),b(),n.appendChild(c)}let U=null;function Re(e){U=e}function re(e,t,n){if(!U)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return U(e,t,n)}function le(e,t,n){const o=[],{scopeRoot:s,skipValidation:r,path:l}=n;if(!("elements"in e))return{value:null,errors:o};const a=(i,c,u)=>{var d,h;if(r)return;const m="minCount"in u&&(d=u.minCount)!=null?d:0,p="maxCount"in u&&(h=u.maxCount)!=null?h:1/0;u.required&&c.length===0&&o.push(`${i}: required`),c.length<m&&o.push(`${i}: minimum ${m} items required`),c.length>p&&o.push(`${i}: maximum ${p} items allowed`)};if("multiple"in e&&e.multiple){const i=[],c=s.querySelectorAll("[data-container-item]"),u=Array.from(c).filter(d=>{const h=d.getAttribute("data-container-item");return h==null?void 0:h.startsWith(`${t}[`)}).length;for(let d=0;d<u;d++){const h={},m=s.querySelector(`[data-container-item="${t}[${d}]"]`)||s;e.elements.forEach(p=>{if(p.hidden||p.type==="hidden")h[p.key]=p.default!==void 0?p.default:null;else{const v=`${t}[${d}].${p.key}`;h[p.key]=re({...p,key:v},{path:l},m)}}),i.push(h)}return a(t,i,e),{value:i,errors:o}}else{const i={},c=s.querySelector(`[data-container="${t}"]`)||s;return e.elements.forEach(u=>{if(u.hidden||u.type==="hidden")i[u.key]=u.default!==void 0?u.default:null;else{const d=`${t}.${u.key}`;i[u.key]=re({...u,key:d},{path:l},c)}}),{value:i,errors:o}}}function oe(e,t,n,o){const{instance:s,scopeRoot:r}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((a,i)=>{q(a)&&e.elements.forEach(c=>{const u=c.key,d=`${t}[${i}].${u}`,h=a[u];h!==void 0&&s.updateField(d,h)})});const l=r.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==l.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!q(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(l=>{const a=l.key,i=`${t}.${a}`,c=n[a];c!==void 0&&s.updateField(i,c)})}}function Ue(e,t,n,o){var s,r;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const l={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&q(e.repeat)),minCount:(s=e.repeat)==null?void 0:s.min,maxCount:(r=e.repeat)==null?void 0:r.max};l.multiple?ne(l,t,n):te(l,t,n,o)}function ae(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&q(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function Oe(e,t,n){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field key: "${t}"`);const o=ae(e);return le(o,t,n)}function Pe(e,t,n,o){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const s=ae(e);return oe(s,t,n,o)}function Ve(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(u=>{u.classList.add("hidden")}),o)return;const s=t.getBoundingClientRect(),r=window.innerWidth,l=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const a=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let i=s.left,c=s.bottom+5;i+a.width>r&&(i=s.right-a.width),c+a.height>l&&(c=s.top-a.height-5),i<10&&(i=10),c<10&&(c=s.bottom+5),n.style.left=`${i}px`,n.style.top=`${c}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(s=>{s.classList.add("hidden")})});function O(e,t){var n;if(e.displayIf)try{const a=(n=t.formData)!=null?n:t.prefill;if(!j(e.displayIf,a)){const i=document.createElement("div");return i.className="fb-field-wrapper-hidden",i.style.display="none",i.setAttribute("data-field-key",e.key),i.setAttribute("data-conditionally-hidden","true"),i}}catch(a){console.error(`Error evaluating displayIf for field "${e.key}":`,a)}const o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const s=document.createElement("div");s.className="flex items-center mb-2";const r=document.createElement("label");if(r.className="text-sm font-medium text-gray-900",r.textContent=e.label||e.key,e.required){const a=document.createElement("span");a.className="text-red-500 ml-1",a.textContent="*",r.appendChild(a)}if(s.appendChild(r),e.description||e.hint){const a=document.createElement("button");a.type="button",a.className="ml-2 text-gray-400 hover:text-gray-600",a.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 i=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,c=document.createElement("div");c.id=i,c.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",c.style.position="fixed",c.textContent=e.description||e.hint||"Field information",document.body.appendChild(c),a.onclick=u=>{u.preventDefault(),u.stopPropagation(),Ve(i,a)},s.appendChild(a)}o.appendChild(s);const l=N(t.path,e.key);switch(e.type){case"text":"multiple"in e&&e.multiple?ye(e,t,o,l):ge(e,t,o,l);break;case"textarea":"multiple"in e&&e.multiple?xe(e,t,o,l):be(e,t,o,l);break;case"number":"multiple"in e&&e.multiple?$e(e,t,o,l):we(e,t,o,l);break;case"select":"multiple"in e&&e.multiple?Le(e,t,o,l):Se(e,t,o,l);break;case"file":"multiple"in e&&e.multiple?De(e,t,o,l):je(e,t,o,l);break;case"files":ze(e,t,o,l);break;case"group":Ue(e,t,o,l);break;case"container":"multiple"in e&&e.multiple?ne(e,t,o):te(e,t,o,l);break;default:{const a=document.createElement("div");a.className="text-red-500 text-sm",a.textContent=`Unsupported field type: ${e.type}`,o.appendChild(a)}}return o}Ie(O);const _e={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{addElement:"Add Element",removeElement:"Remove",uploadText:"Upload",dragDropText:"or drag and drop files",dragDropTextSingle:"or drag and drop file",clickDragText:"Click or drag file",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download"},ru:{addElement:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u044D\u043B\u0435\u043C\u0435\u043D\u0442",removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",uploadText:"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435",dragDropText:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",dragDropTextSingle:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C"}},theme:{}};function We(e){return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{..._e,...e},debounceTimer:null}}function Ge(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const T={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 Je(e){const t={...T,...e},n=[];return Object.entries(t).forEach(([o,s])=>{const r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${r}: ${s};`)}),n.join(`
|
|
168
|
-
|
|
167
|
+
`}async function X(e,t,n,o,a=null,r){var l,i;let s;if(o.config.uploadFile)try{if(s=await o.config.uploadFile(e),typeof s!="string")throw new Error("Upload handler must return a string resource ID")}catch(u){const c=u instanceof Error?u:new Error(String(u));throw o.config.onUploadError&&o.config.onUploadError(c,e),new Error(`File upload failed: ${c.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(s,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let d=(l=t.parentElement)==null?void 0:l.querySelector('input[type="hidden"]');d||(d=document.createElement("input"),d.type="hidden",d.name=n,(i=t.parentElement)==null||i.appendChild(d)),d.value=s,G(t,s,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),r&&!o.config.readonly&&r.triggerOnChange(n,s)}function R(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 _e(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const a=document.createElement("div");a.className="delete-overlay absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const r=document.createElement("button");r.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",r.textContent=L("removeElement",t),r.onclick=l=>{l.stopPropagation(),n()},a.appendChild(r),e.appendChild(a)}async function Z(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 We(e,t,n){try{let o=null;if(n.config.getDownloadUrl?o=n.config.getDownloadUrl(e):n.config.getThumbnail&&(o=await n.config.getThumbnail(e)),o){const a=o.startsWith("http")?o:new URL(o,window.location.href).href,r=await fetch(a);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const l=await r.blob();Ge(l,t)}else throw new Error("No download URL available for resource")}catch(o){const a=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(a,e,t),console.error(`File download failed for ${t}:`,a),a}}function Ge(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 K(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",r=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let l="application/octet-stream";r&&(["jpg","jpeg","png","gif","webp"].includes(r)?l=`image/${r==="jpg"?"jpeg":r}`:["mp4","webm","mov","avi"].includes(r)&&(l=`video/${r==="mov"?"quicktime":r}`)),t.resourceIndex.set(n,{name:a,type:l,size:0,uploadedAt:new Date,file:void 0})}})}function Je(e,t,n,o,a,r){var l;if(!a.resourceIndex.has(e)){const s=e.split("/").pop()||"file",d=(l=s.split(".").pop())==null?void 0:l.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),a.resourceIndex.set(e,{name:s,type:u,size:0,uploadedAt:new Date,file:void 0})}G(t,e,a,{fileName:e,isReadonly:!1,deps:r}).catch(console.error);const i=document.createElement("input");i.type="hidden",i.name=n,i.value=e,o.appendChild(i)}function Q(e,t,n,o,a,r){R(e,async l=>{const i=Array.from(l);for(const s of i){const d=await Z(s,n);n.resourceIndex.set(d,{name:s.name,type:s.type,size:s.size,uploadedAt:new Date,file:void 0}),t.push(d)}o(),r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)})}function ee(e,t,n,o,a,r){e.onchange=async()=>{if(e.files)for(const l of Array.from(e.files)){const i=await Z(l,n);n.resourceIndex.set(i,{name:l.name,type:l.type,size:l.size,uploadedAt:new Date,file:void 0}),t.push(i)}o(),e.value="",r&&a&&!n.config.readonly&&r.triggerOnChange(a,t)}}function Ye(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=t.prefill[e.key];if(l)I(l,r).then(i=>{n.appendChild(i)}).catch(i=>{console.error("Failed to render file preview:",i);const s=document.createElement("div");s.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",s.innerHTML='<div class="text-center">Preview unavailable</div>',n.appendChild(s)});else{const i=document.createElement("div");i.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",i.innerHTML=`<div class="text-center">${L("noFileSelected",r)}</div>`,n.appendChild(i)}}else{const l=document.createElement("div");l.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(v=>`.${v}`).join(","))||"");const s=document.createElement("div");s.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const d=t.prefill[e.key],u=()=>i.click(),c=v=>{if(v.length>0){const y={picker:i,fileUploadHandler:u,dragHandler:c};X(v[0],s,o,r,y,t.instance)}};d?Je(d,s,o,l,r,{picker:i,fileUploadHandler:u,dragHandler:c}):D(s,r),s.onclick=u,R(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const v={picker:i,fileUploadHandler:u,dragHandler:c};X(i.files[0],s,o,r,v,t.instance)}},l.appendChild(s),l.appendChild(i);const h=document.createElement("p");h.className="text-xs text-gray-600 mt-2 text-center",h.innerHTML=`<span class="underline cursor-pointer">${L("uploadText",r)}</span> ${L("dragDropTextSingle",r)}`;const f=h.querySelector("span");f&&(f.onclick=()=>i.click()),l.appendChild(h);const m=document.createElement("p");m.className="text-xs text-gray-500 mt-1 text-center",m.textContent=S(e),l.appendChild(m),n.appendChild(l)}}function Xe(e,t,n,o){var a;const r=t.state;if(r.config.readonly){const l=document.createElement("div");l.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(s=>{I(s,r).then(d=>{l.appendChild(d)}).catch(d=>{console.error("Failed to render file preview:",d)})}):l.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",r)}</div></div>`,n.appendChild(l)}else{let l=function(){J(u,c,r,f=>{const m=c.indexOf(f);m>-1&&c.splice(m,1),l()})};const i=document.createElement("div");i.className="space-y-2";const s=document.createElement("input");s.type="file",s.name=o,s.multiple=!0,s.style.display="none",e.accept&&(s.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(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 u=document.createElement("div");u.className="files-list";const c=t.prefill[e.key]||[];K(c,r),l(),Q(d,c,r,l,o,t.instance),ee(s,c,r,l,o,t.instance),d.appendChild(u),i.appendChild(d),i.appendChild(s);const h=document.createElement("p");h.className="text-xs text-gray-500 mt-1 text-center",h.textContent=S(e),i.appendChild(h),n.appendChild(i)}}function Ze(e,t,n,o){var a,r,l;const i=t.state,s=(a=e.minCount)!=null?a:0,d=(r=e.maxCount)!=null?r:1/0;if(i.config.readonly){const u=document.createElement("div");u.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(h=>{I(h,i).then(f=>{u.appendChild(f)}).catch(f=>{console.error("Failed to render file preview:",f)})}):u.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L("noFilesSelected",i)}</div></div>`,n.appendChild(u)}else{const u=document.createElement("div");u.className="space-y-2";const c=document.createElement("input");c.type="file",c.name=o,c.multiple=!0,c.style.display="none",e.accept&&(c.accept=typeof e.accept=="string"?e.accept:((l=e.accept.extensions)==null?void 0:l.map(v=>`.${v}`).join(","))||"");const h=document.createElement("div");h.className="files-list space-y-2",u.appendChild(c),u.appendChild(h);const f=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];K(f,i);const m=()=>{J(h,f,i,b=>{f.splice(f.indexOf(b),1),m()});const v=document.createElement("div");v.className="text-xs text-gray-500 mt-2 file-count-info";const y=`${f.length} file${f.length!==1?"s":""}`,x=s>0||d<1/0?` (${s}-${d} allowed)`:"";v.textContent=y+x;const g=u.querySelector(".file-count-info");g&&g.remove(),u.appendChild(v)};Q(h,f,i,m,o,t.instance),ee(c,f,i,m,o,t.instance),m(),n.appendChild(u)}}function te(e,t,n){var o;const a=[],{scopeRoot:r,skipValidation:l,path:i}=n,s=e.type==="files"||"multiple"in e&&!!e.multiple,d=(u,c,h)=>{var f,m;if(l)return;const v="minCount"in h&&(f=h.minCount)!=null?f:0,y="maxCount"in h&&(m=h.maxCount)!=null?m:1/0;h.required&&c.length===0&&a.push(`${u}: required`),c.length<v&&a.push(`${u}: minimum ${v} files required`),c.length>y&&a.push(`${u}: maximum ${y} files allowed`)};if(s){const u=N(i,t),c=r.querySelector(`input[type="file"][name="${u}"]`),h=c==null?void 0:c.closest(".space-y-2"),f=(h==null?void 0:h.querySelector(".files-list"))||null,m=[];return f&&f.querySelectorAll(".resource-pill").forEach(v=>{const y=v.dataset.resourceId;y&&m.push(y)}),d(t,m,e),{value:m,errors:a}}else{const u=r.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=u==null?void 0:u.value)!=null?o:"";return!l&&e.required&&c===""?(a.push(`${t}: required`),{value:null,errors:a}):{value:c||null,errors:a}}}function ne(e,t,n,o){var a;const{scopeRoot:r,state:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(i=>{var s;if(i&&typeof i=="string"&&!l.resourceIndex.has(i)){const d=i.split("/").pop()||"file",u=(s=d.split(".").pop())==null?void 0:s.toLowerCase();let c="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?c=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(c=`video/${u==="mov"?"quicktime":u}`)),l.resourceIndex.set(i,{name:d,type:c,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const i=r.querySelector(`input[name="${t}"][type="hidden"]`);if(!i){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(i.value=n!=null?String(n):"",n&&typeof n=="string"){if(!l.resourceIndex.has(n)){const s=n.split("/").pop()||"file",d=(a=s.split(".").pop())==null?void 0:a.toLowerCase();let u="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?u=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(u=`video/${d==="mov"?"quicktime":d}`)),l.resourceIndex.set(n,{name:s,type:u,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function A(e){return e?e.toUpperCase():"#000000"}function U(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function re(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 oe(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=A(e),o=document.createElement("div");o.style.cssText=`
|
|
168
|
+
width: 32px;
|
|
169
|
+
height: 32px;
|
|
170
|
+
border-radius: var(--fb-border-radius);
|
|
171
|
+
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
172
|
+
background-color: ${n};
|
|
173
|
+
`;const a=document.createElement("span");return a.style.cssText=`
|
|
174
|
+
font-size: var(--fb-font-size);
|
|
175
|
+
color: var(--fb-text-color);
|
|
176
|
+
font-family: var(--fb-font-family-mono, monospace);
|
|
177
|
+
`,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function le(e,t,n){const o=A(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
|
|
178
|
+
display: flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
gap: 8px;
|
|
181
|
+
`;const r=document.createElement("div");r.className="colour-swatch",r.style.cssText=`
|
|
182
|
+
width: 40px;
|
|
183
|
+
height: 40px;
|
|
184
|
+
border-radius: var(--fb-border-radius);
|
|
185
|
+
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
186
|
+
background-color: ${o};
|
|
187
|
+
cursor: pointer;
|
|
188
|
+
transition: border-color var(--fb-transition-duration) ease-in-out;
|
|
189
|
+
flex-shrink: 0;
|
|
190
|
+
`;const l=document.createElement("input");l.type="text",l.className="colour-hex-input",l.name=t,l.value=o,l.placeholder="#000000",l.style.cssText=`
|
|
191
|
+
width: 100px;
|
|
192
|
+
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
193
|
+
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
194
|
+
border-radius: var(--fb-border-radius);
|
|
195
|
+
background-color: var(--fb-background-color);
|
|
196
|
+
color: var(--fb-text-color);
|
|
197
|
+
font-size: var(--fb-font-size);
|
|
198
|
+
font-family: var(--fb-font-family-mono, monospace);
|
|
199
|
+
transition: all var(--fb-transition-duration) ease-in-out;
|
|
200
|
+
`;const i=document.createElement("input");return i.type="color",i.className="colour-picker-hidden",i.value=o.toLowerCase(),i.style.cssText=`
|
|
201
|
+
position: absolute;
|
|
202
|
+
opacity: 0;
|
|
203
|
+
pointer-events: none;
|
|
204
|
+
`,l.addEventListener("input",()=>{const s=l.value.trim();if(U(s)){const d=re(s);r.style.backgroundColor=d,i.value=d.toLowerCase(),l.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,d)}else l.classList.add("invalid")}),l.addEventListener("blur",()=>{const s=l.value.trim();if(U(s)){const d=re(s);l.value=d,r.style.backgroundColor=d,i.value=d.toLowerCase(),l.classList.remove("invalid")}}),i.addEventListener("change",()=>{const s=A(i.value);l.value=s,r.style.backgroundColor=s,n.instance&&n.instance.triggerOnChange(t,s)}),r.addEventListener("click",()=>{i.click()}),r.addEventListener("mouseenter",()=>{r.style.borderColor="var(--fb-border-hover-color)"}),r.addEventListener("mouseleave",()=>{r.style.borderColor="var(--fb-border-color)"}),l.addEventListener("focus",()=>{l.style.borderColor="var(--fb-border-focus-color)",l.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",l.style.outlineOffset="0"}),l.addEventListener("blur",()=>{l.style.borderColor="var(--fb-border-color)",l.style.outline="none"}),l.addEventListener("mouseenter",()=>{document.activeElement!==l&&(l.style.borderColor="var(--fb-border-hover-color)")}),l.addEventListener("mouseleave",()=>{document.activeElement!==l&&(l.style.borderColor="var(--fb-border-color)")}),a.appendChild(r),a.appendChild(l),a.appendChild(i),a}function Ke(e,t,n,o){const a=t.state,r=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const i=oe(r);n.appendChild(i)}else{const i=le(r,o,t);n.appendChild(i)}const l=document.createElement("p");l.className="mt-1",l.style.cssText=`
|
|
205
|
+
font-size: var(--fb-font-size-small);
|
|
206
|
+
color: var(--fb-text-secondary-color);
|
|
207
|
+
`,l.textContent=S(e),n.appendChild(l)}function Qe(e,t,n,o){var a,r;const l=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],d=(a=e.minCount)!=null?a:1,u=(r=e.maxCount)!=null?r:1/0;for(;s.length<d;)s.push(e.default||"#000000");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function h(){c.querySelectorAll(".multiple-colour-item").forEach((x,g)=>{const b=x.querySelector("input");b&&(b.name=`${o}[${g}]`)})}function f(x="#000000",g=-1){const b=document.createElement("div");if(b.className="multiple-colour-item flex items-center gap-2",l.config.readonly){const p=oe(x);for(;p.firstChild;)b.appendChild(p.firstChild)}else{const p=`${o}[${c.children.length}]`,C=le(x,p,t);C.style.flex="1",b.appendChild(C)}return g===-1?c.appendChild(b):c.insertBefore(b,c.children[g]),h(),b}function m(){if(l.config.readonly)return;const x=c.querySelectorAll(".multiple-colour-item"),g=x.length;x.forEach(b=>{let p=b.querySelector(".remove-item-btn");p||(p=document.createElement("button"),p.type="button",p.className="remove-item-btn px-2 py-1 rounded",p.style.cssText=`
|
|
208
|
+
color: var(--fb-error-color);
|
|
209
|
+
background-color: transparent;
|
|
210
|
+
transition: background-color var(--fb-transition-duration);
|
|
211
|
+
`,p.innerHTML="\u2715",p.addEventListener("mouseenter",()=>{p.style.backgroundColor="var(--fb-background-hover-color)"}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor="transparent"}),p.onclick=()=>{const E=Array.from(c.children).indexOf(b);c.children.length>d&&(s.splice(E,1),b.remove(),h(),v(),m())},b.appendChild(p));const C=g<=d;p.disabled=C,p.style.opacity=C?"0.5":"1",p.style.pointerEvents=C?"none":"auto"})}function v(){const x=n.querySelector(".add-colour-btn");if(x&&x.remove(),!l.config.readonly&&s.length<u){const g=document.createElement("button");g.type="button",g.className="add-colour-btn mt-2 px-3 py-1 rounded",g.style.cssText=`
|
|
212
|
+
color: var(--fb-primary-color);
|
|
213
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
214
|
+
background-color: transparent;
|
|
215
|
+
font-size: var(--fb-font-size);
|
|
216
|
+
transition: all var(--fb-transition-duration);
|
|
217
|
+
`,g.textContent=`+ Add ${e.label||"Colour"}`,g.addEventListener("mouseenter",()=>{g.style.backgroundColor="var(--fb-background-hover-color)"}),g.addEventListener("mouseleave",()=>{g.style.backgroundColor="transparent"}),g.onclick=()=>{const b=e.default||"#000000";s.push(b),f(b),v(),m()},n.appendChild(g)}}s.forEach(x=>f(x)),v(),m();const y=document.createElement("p");y.className="mt-1",y.style.cssText=`
|
|
218
|
+
font-size: var(--fb-font-size-small);
|
|
219
|
+
color: var(--fb-text-secondary-color);
|
|
220
|
+
`,y.textContent=S(e),n.appendChild(y)}function et(e,t,n){var o,a,r;const l=[],{scopeRoot:i,skipValidation:s}=n,d=(c,h)=>{var f,m;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let y=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,y||(y=document.createElement("div"),y.id=v,y.className="error-message",y.style.cssText=`
|
|
221
|
+
color: var(--fb-error-color);
|
|
222
|
+
font-size: var(--fb-font-size-small);
|
|
223
|
+
margin-top: 0.25rem;
|
|
224
|
+
`,c.nextSibling?(f=c.parentNode)==null||f.insertBefore(y,c.nextSibling):(m=c.parentNode)==null||m.appendChild(y)),y.textContent=h,y.style.display="block"):(c.classList.remove("invalid"),c.title="",y&&y.remove())},u=(c,h,f)=>{if(!h)return!s&&e.required?(l.push(`${f}: required`),d(c,"required"),""):(d(c,null),"");const m=A(h);return!s&&!U(m)?(l.push(`${f}: invalid hex colour format`),d(c,"invalid hex colour format"),h):(d(c,null),m)};if(e.multiple){const c=i.querySelectorAll(".colour-hex-input"),h=[];if(c.forEach((f,m)=>{var v;const y=(v=f==null?void 0:f.value)!=null?v:"",x=u(f,y,`${t}[${m}]`);h.push(x)}),!s){const f=(o=e.minCount)!=null?o:1,m=(a=e.maxCount)!=null?a:1/0,v=h.filter(y=>y!=="");e.required&&v.length===0&&l.push(`${t}: required`),v.length<f&&l.push(`${t}: minimum ${f} items required`),v.length>m&&l.push(`${t}: maximum ${m} items allowed`)}return{value:h,errors:l}}else{const c=i.querySelector(`[name="${t}"].colour-hex-input`),h=(r=c==null?void 0:c.value)!=null?r:"";return!s&&e.required&&h===""?(l.push(`${t}: required`),d(c,"required"),{value:"",errors:l}):{value:u(c,h,t),errors:l}}}function tt(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateColourField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=a.querySelectorAll(".colour-hex-input");r.forEach((l,i)=>{if(i<n.length){const s=A(n[i]);l.value=s,l.classList.remove("invalid"),l.title="";const d=l.closest(".colour-picker-wrapper");if(d){const u=d.querySelector(".colour-swatch"),c=d.querySelector(".colour-picker-hidden");u&&(u.style.backgroundColor=s),c&&(c.value=s.toLowerCase())}}}),n.length!==r.length&&console.warn(`updateColourField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=a.querySelector(`[name="${t}"].colour-hex-input`);if(r){const l=A(n);r.value=l,r.classList.remove("invalid"),r.title="";const i=r.closest(".colour-picker-wrapper");if(i){const s=i.querySelector(".colour-swatch"),d=i.querySelector(".colour-picker-hidden");s&&(s.style.backgroundColor=l),d&&(d.value=l.toLowerCase())}}}}let O=null;function nt(e){O=e}function M(e,t){if(!O)throw new Error("renderElement not initialized. Import from components/index.ts");return O(e,t)}function ae(e,t,n,o){var a,r;const l=document.createElement("div");l.className="border border-gray-200 rounded-lg p-4 bg-gray-50",l.setAttribute("data-container",o);const i=document.createElement("div");i.className="flex justify-between items-center mb-4";const s=document.createElement("div");s.className="flex-1";const d=document.createElement("div");d.className="space-y-4",l.appendChild(i),i.appendChild(s);const u={path:N(t.path,e.key),prefill:((a=t.prefill)==null?void 0:a[e.key])||{},formData:(r=t.formData)!=null?r:t.prefill,state:t.state};e.elements.forEach(c=>{c.hidden||d.appendChild(M(c,u))}),l.appendChild(d),s.innerHTML=`<span>${e.label||e.key}</span>`,n.appendChild(l)}function ie(e,t,n,o){var a,r,l,i;const s=t.state,d=document.createElement("div");d.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const u=document.createElement("div");u.className="flex justify-between items-center mb-4";const c=document.createElement("div");c.className="flex-1";const h=document.createElement("div");h.className="flex gap-2";const f=document.createElement("div");f.className="space-y-4",d.appendChild(u),u.appendChild(c),s.config.readonly||u.appendChild(h);const m=(a=e.minCount)!=null?a:0,v=(r=e.maxCount)!=null?r:1/0,y=Array.isArray((l=t.prefill)==null?void 0:l[e.key])?t.prefill[e.key]:null,x=()=>f.querySelectorAll(":scope > .containerItem").length,g=()=>{const p=document.createElement("button");return p.type="button",p.className="px-3 py-1.5 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 transition-colors",p.textContent=L("addElement",s),p.onclick=()=>{var C;if(x()<v){const E=x(),$={state:t.state,path:N(t.path,`${e.key}[${E}]`),prefill:{},formData:(C=t.formData)!=null?C:t.prefill},w=document.createElement("div");if(w.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",w.setAttribute("data-container-item",`${e.key}[${E}]`),e.elements.forEach(k=>{k.hidden||w.appendChild(M(k,$))}),!s.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors",k.textContent="\xD7",k.onclick=()=>{w.remove(),b()},w.style.position="relative",w.appendChild(k)}f.appendChild(w),b()}},p},b=()=>{const p=x(),C=h.querySelector("button");C&&(C.disabled=p>=v,C.style.opacity=p>=v?"0.5":"1"),c.innerHTML=`<span>${e.label||e.key}</span> <span class="text-sm text-gray-500">(${p}/${v===1/0?"\u221E":v})</span>`};if(s.config.readonly||h.appendChild(g()),y&&Array.isArray(y)&&y.forEach((p,C)=>{var E;const $={state:t.state,path:N(t.path,`${e.key}[${C}]`),prefill:p||{},formData:(E=t.formData)!=null?E:t.prefill},w=document.createElement("div");if(w.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",w.setAttribute("data-container-item",`${e.key}[${C}]`),e.elements.forEach(k=>{k.hidden||w.appendChild(M(k,$))}),!s.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors",k.textContent="\xD7",k.onclick=()=>{w.remove(),b()},w.style.position="relative",w.appendChild(k)}f.appendChild(w)}),!s.config.readonly)for(;x()<m;){const p=x(),C={state:t.state,path:N(t.path,`${e.key}[${p}]`),prefill:{},formData:(i=t.formData)!=null?i:t.prefill},E=document.createElement("div");E.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",E.setAttribute("data-container-item",`${e.key}[${p}]`),e.elements.forEach(w=>{w.hidden||E.appendChild(M(w,C))});const $=document.createElement("button");$.type="button",$.className="absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors",$.textContent="\xD7",$.onclick=()=>{x()>m&&(E.remove(),b())},E.style.position="relative",E.appendChild($),f.appendChild(E)}d.appendChild(f),b(),n.appendChild(d)}let P=null;function rt(e){P=e}function se(e,t,n){if(!P)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return P(e,t,n)}function ce(e,t,n){const o=[],{scopeRoot:a,skipValidation:r,path:l}=n;if(!("elements"in e))return{value:null,errors:o};const i=(s,d,u)=>{var c,h;if(r)return;const f="minCount"in u&&(c=u.minCount)!=null?c:0,m="maxCount"in u&&(h=u.maxCount)!=null?h:1/0;u.required&&d.length===0&&o.push(`${s}: required`),d.length<f&&o.push(`${s}: minimum ${f} items required`),d.length>m&&o.push(`${s}: maximum ${m} items allowed`)};if("multiple"in e&&e.multiple){const s=[],d=a.querySelectorAll("[data-container-item]"),u=Array.from(d).filter(c=>{const h=c.getAttribute("data-container-item");return h==null?void 0:h.startsWith(`${t}[`)}).length;for(let c=0;c<u;c++){const h={},f=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(m=>{if(m.hidden||m.type==="hidden")h[m.key]=m.default!==void 0?m.default:null;else{const v=`${t}[${c}].${m.key}`;h[m.key]=se({...m,key:v},{path:l},f)}}),s.push(h)}return i(t,s,e),{value:s,errors:o}}else{const s={},d=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(u=>{if(u.hidden||u.type==="hidden")s[u.key]=u.default!==void 0?u.default:null;else{const c=`${t}.${u.key}`;s[u.key]=se({...u,key:c},{path:l},d)}}),{value:s,errors:o}}}function de(e,t,n,o){const{instance:a,scopeRoot:r}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((i,s)=>{H(i)&&e.elements.forEach(d=>{const u=d.key,c=`${t}[${s}].${u}`,h=i[u];h!==void 0&&a.updateField(c,h)})});const l=r.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==l.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!H(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(l=>{const i=l.key,s=`${t}.${i}`,d=n[i];d!==void 0&&a.updateField(s,d)})}}function ot(e,t,n,o){var a,r;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const l={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&H(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(r=e.repeat)==null?void 0:r.max};l.multiple?ie(l,t,n):ae(l,t,n,o)}function ue(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&H(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function lt(e,t,n){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field key: "${t}"`);const o=ue(e);return ce(o,t,n)}function at(e,t,n,o){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const a=ue(e);return de(a,t,n,o)}function it(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(u=>{u.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),r=window.innerWidth,l=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const i=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let s=a.left,d=a.bottom+5;s+i.width>r&&(s=a.right-i.width),d+i.height>l&&(d=a.top-i.height-5),s<10&&(s=10),d<10&&(d=a.bottom+5),n.style.left=`${s}px`,n.style.top=`${d}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(a=>{a.classList.add("hidden")})});function st(e,t){var n;if(!e.displayIf)return null;try{const o=(n=t.formData)!=null?n:t.prefill;if(!j(e.displayIf,o)){const a=document.createElement("div");return a.className="fb-field-wrapper-hidden",a.style.display="none",a.setAttribute("data-field-key",e.key),a.setAttribute("data-conditionally-hidden","true"),a}}catch(o){console.error(`Error evaluating displayIf for field "${e.key}":`,o)}return null}function ct(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 dt(e){const t=document.createElement("button");t.type="button",t.className="ml-2 text-gray-400 hover:text-gray-600",t.innerHTML='<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>';const n=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,o=document.createElement("div");return o.id=n,o.className="hidden absolute z-50 bg-gray-200 text-gray-900 text-sm rounded-lg p-3 max-w-sm border border-gray-300 shadow-lg",o.style.position="fixed",o.textContent=e.description||e.hint||"Field information",document.body.appendChild(o),t.onclick=a=>{a.preventDefault(),a.stopPropagation(),it(n,t)},t}function ut(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=ct(e);if(t.appendChild(n),e.description||e.hint){const o=dt(e);t.appendChild(o)}return t}function pt(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?we(e,t,n,o):Ee(e,t,n,o);break;case"textarea":a?ke(e,t,n,o):$e(e,t,n,o);break;case"number":a?Ne(e,t,n,o):Fe(e,t,n,o);break;case"select":a?He(e,t,n,o):qe(e,t,n,o);break;case"file":a?Ze(e,t,n,o):Ye(e,t,n,o);break;case"files":Xe(e,t,n,o);break;case"colour":a?Qe(e,t,n,o):Ke(e,t,n,o);break;case"group":ot(e,t,n,o);break;case"container":a?ie(e,t,n):ae(e,t,n,o);break;default:{const r=document.createElement("div");r.className="text-red-500 text-sm",r.textContent=`Unsupported field type: ${e.type}`,n.appendChild(r)}}}function V(e,t){const n=st(e,t);if(n)return n;const o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=ut(e);o.appendChild(a);const r=N(t.path,e.key);return pt(e,t,o,r),o}nt(V);const mt={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{addElement:"Add Element",removeElement:"Remove",uploadText:"Upload",dragDropText:"or drag and drop files",dragDropTextSingle:"or drag and drop file",clickDragText:"Click or drag file",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download"},ru:{addElement:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u044D\u043B\u0435\u043C\u0435\u043D\u0442",removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",uploadText:"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435",dragDropText:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",dragDropTextSingle:"\u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C"}},theme:{}};function ft(e){return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...mt,...e},debounceTimer:null}}function ht(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const q={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 vt(e){const t={...q,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${r}: ${a};`)}),n.join(`
|
|
225
|
+
`)}function gt(e,t){const n=vt(t);let o=e.querySelector("style[data-fb-theme]");o||(o=document.createElement("style"),o.setAttribute("data-fb-theme","true"),e.appendChild(o)),o.textContent=`
|
|
169
226
|
[data-fb-root="true"] {
|
|
170
227
|
${n}
|
|
171
228
|
}
|
|
172
|
-
`}const
|
|
229
|
+
`}const yt={default:q,dark:{...q,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:{...q,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 pe(e,t=!1){e.style.cssText=`
|
|
173
230
|
background-color: var(--fb-action-bg-color);
|
|
174
231
|
color: var(--fb-action-text-color);
|
|
175
232
|
border: var(--fb-border-width) solid var(--fb-action-border-color);
|
|
@@ -179,6 +236,6 @@ ${n}
|
|
|
179
236
|
border-radius: var(--fb-border-radius);
|
|
180
237
|
transition: all var(--fb-transition-duration);
|
|
181
238
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
182
|
-
`,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
|
|
239
|
+
`,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 bt={text:{validate:_,update:W},textarea:{validate:Le,update:Se},number:{validate:Ae,update:Te},select:{validate:Me,update:Be},file:{validate:te,update:ne},files:{validate:te,update:ne},colour:{validate:et,update:tt},container:{validate:ce,update:de},group:{validate:lt,update:at}};function me(e){return bt[e]||null}function xt(e,t,n){const o=me(e.type);return o&&o.validate?o.validate(e,t,n):null}function Ct(e,t,n,o){const a=me(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class B{constructor(t){this.instanceId=ht(),this.state=ft(t),this.state.config.verboseErrors&&(globalThis.__formBuilderInstances||(globalThis.__formBuilderInstances=new Set),globalThis.__formBuilderInstances.add(this.instanceId),globalThis.__formBuilderInstances.size>10&&console.warn(`[form-builder] ${globalThis.__formBuilderInstances.size} instances active. Possible memory leak - ensure you call destroy() when done.`))}getInstanceId(){return this.instanceId}getState(){return this.state}setFormRoot(t){this.state.formRoot=t}configure(t){Object.assign(this.state.config,t)}setUploadHandler(t){this.state.config.uploadFile=t}setDownloadHandler(t){this.state.config.downloadFile=t}setThumbnailHandler(t){this.state.config.getThumbnail=t}setActionHandler(t){this.state.config.actionHandler=t}setMode(t){this.state.config.readonly=t==="readonly"}setLocale(t){this.state.config.translations[t]&&(this.state.config.locale=t)}triggerOnChange(t,n){this.state.config.readonly||(this.state.debounceTimer!==null&&clearTimeout(this.state.debounceTimer),this.state.debounceTimer=setTimeout(()=>{const o=this.validateForm(!0);this.reevaluateConditionalFields(),this.state.config.onChange&&this.state.config.onChange(o),this.state.config.onFieldChange&&t!==void 0&&n!==void 0&&this.state.config.onFieldChange(t,n,o),this.state.debounceTimer=null},this.state.config.debounceMs))}registerAction(t){if(!t||!t.value)throw new Error("Action must have a value property");this.state.externalActions||(this.state.externalActions=[]);const n=this.state.externalActions.findIndex(o=>o.value===t.value&&o.related_field===t.related_field);n>=0?this.state.externalActions[n]=t:this.state.externalActions.push(t)}findFormElementByFieldPath(t){if(!this.state.formRoot)return null;if(!this.state.config.readonly){let a=this.state.formRoot.querySelector(`[name="${t}"]`);if(a)return a;const r=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const l of r)if(a=this.state.formRoot.querySelector(`[name="${l}"]`),a)return a}const n=this.findSchemaElement(t);if(!n)return null;const o=this.state.formRoot.querySelectorAll(".fb-field-wrapper");for(const a of o){const r=n.label||n.key,l=a.querySelector("label");if(l&&(l.textContent===r||l.textContent===`${r}*`)){let i=a.querySelector(".field-placeholder");return i||(i=document.createElement("div"),i.className="field-placeholder",i.style.display="none",a.appendChild(i)),i}}return null}findSchemaElement(t){if(!this.state.schema||!this.state.schema.elements)return null;let n=this.state.schema.elements,o=null;const a=t.replace(/\[\d+\]/g,"").split(".").filter(Boolean);for(const r of a){if(o=n.find(l=>l.key===r)||null,!o)return null;"elements"in o&&o.elements&&(n=o.elements)}return o}resolveActionLabel(t,n,o,a=!1){if(o&&"actions"in o&&o.actions){const r=o.actions.find(l=>l.key===t);if(r&&r.label)return r.label}if(a&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const r=this.state.schema.actions.find(l=>l.key===t);if(r&&r.label)return r.label}return n||t}renderFormLevelActions(t,n=[]){if(!this.state.formRoot)return;const o=this.state.formRoot.querySelector(".form-level-actions-container");o&&o.remove();const a=document.createElement("div");a.className="form-level-actions-container mt-6 pt-4 flex flex-wrap gap-3 justify-center",a.style.cssText=`
|
|
183
240
|
border-top: var(--fb-border-width) solid var(--fb-border-color);
|
|
184
|
-
`,t.forEach(r=>{const l=document.createElement("button");l.type="button",
|
|
241
|
+
`,t.forEach(r=>{const l=document.createElement("button");l.type="button",pe(l,!0);const i=n.includes(r),s=this.resolveActionLabel(r.key,r.label,null,i);l.textContent=s,l.addEventListener("click",d=>{d.preventDefault(),d.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(r.value,r.key,null)}),a.appendChild(l)}),this.state.formRoot.appendChild(a)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],o=[];this.state.externalActions.forEach(r=>{!r.key||!r.value||(r.related_field?(t.has(r.related_field)||t.set(r.related_field,[]),t.get(r.related_field).push(r)):n.push(r))}),t.forEach((r,l)=>{const i=this.findFormElementByFieldPath(l);if(!i){console.warn(`External action: Could not find form element for field "${l}", treating as form-level actions`),o.push(...r);return}let s=i.closest(".fb-field-wrapper");if(s||(s=i.parentElement),!s){console.warn(`External action: Could not find wrapper for field "${l}"`);return}const d=s.querySelector(".external-actions-container");d&&d.remove();const u=document.createElement("div");u.className="external-actions-container mt-3 flex flex-wrap gap-2";const c=this.findSchemaElement(l);r.forEach(h=>{const f=document.createElement("button");f.type="button",pe(f,!1);const m=this.resolveActionLabel(h.key,h.label,c);f.textContent=m,f.addEventListener("click",v=>{v.preventDefault(),v.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(h.value,h.key,h.related_field)}),u.appendChild(f)}),s.appendChild(u)});const a=[...n,...o];a.length>0&&this.renderFormLevelActions(a,n)}renderForm(t,n,o,a){const r=z(n);if(r.length>0){console.error("Schema validation errors:",r);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=a||null,T(t),t.setAttribute("data-fb-root","true"),gt(t,this.state.config.theme);const l=document.createElement("div");l.className="space-y-6",n.elements.forEach(i=>{if(i.hidden)return;const s=V(i,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});l.appendChild(s)}),t.appendChild(l),this.state.config.readonly&&this.state.externalActions&&Array.isArray(this.state.externalActions)&&this.renderExternalActions()}validateForm(t=!1){if(!this.state.schema||!this.state.formRoot)return{valid:!0,errors:[],data:{}};const n=[],o={},a=(r,l,i=null)=>{const s=r.key,d={scopeRoot:i||this.state.formRoot,state:this.state,instance:this,path:l.path,skipValidation:t},u=xt(r,s,d);return u!==null?(n.push(...u.errors),u.value):(console.warn(`Unknown field type "${r.type}" for key "${s}"`),null)};return rt(a),this.state.schema.elements.forEach(r=>{if(r.displayIf)try{if(!j(r.displayIf,o))return}catch(l){console.error(`Error evaluating displayIf for field "${r.key}" during validation:`,l)}r.hidden?o[r.key]=r.default!==void 0?r.default:null:o[r.key]=a(r,{path:""})}),{valid:n.length===0,errors:n,data:o}}getFormData(){return this.validateForm(!1)}submitForm(){const t=this.validateForm(!1);return t.valid&&typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formSubmit",data:t.data,schema:this.state.schema},"*"),t}saveDraft(){const t=this.validateForm(!0);return typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formDraft",data:t.data,schema:this.state.schema},"*"),t}clearForm(){if(!this.state.schema||!this.state.formRoot){console.warn("clearForm: Form not initialized. Call renderForm() first.");return}const t=this.state.schema,n=this.state.formRoot,o=this.state.externalActions,a=this.buildHiddenFieldsData(t.elements);this.renderForm(n,t,a,o||void 0)}buildHiddenFieldsData(t){const n={};for(const o of t){const a=o.key;if(o.hidden&&o.default!==void 0&&(n[a]=o.default),o.type==="container"||o.type==="group"){const r=o,l=this.buildHiddenFieldsData(r.elements);Object.keys(l).length>0&&(a in n?typeof n[a]=="object"&&n[a]!==null&&!Array.isArray(n[a])&&(n[a]={...n[a],...l}):n[a]=l)}}return n}setFormData(t){if(!this.state.schema||!this.state.formRoot){console.warn("setFormData: Form not initialized. Call renderForm() first.");return}for(const n in t)this.updateField(n,t[n])}updateField(t,n){if(!this.state.schema||!this.state.formRoot){console.warn("updateField: Form not initialized. Call renderForm() first.");return}const o=this.findSchemaElement(t);if(!o){console.warn(`updateField: Schema element not found for path "${t}"`);return}const a=this.findFormElementByFieldPath(t);if(!a){console.warn(`updateField: DOM element not found for path "${t}"`);return}this.updateFieldValue(a,o,t,n),(this.state.config.onChange||this.state.config.onFieldChange)&&this.triggerOnChange(t,n)}updateFieldValue(t,n,o,a){const r={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};Ct(n,o,a,r)||console.warn(`updateField: No updater found for field type "${n.type}" at path "${o}"`)}reevaluateConditionalFields(){if(!this.state.schema||!this.state.formRoot)return;const t=this.validateForm(!0).data,n=(o,a)=>{o.forEach(r=>{const l=a?`${a}.${r.key}`:r.key;if(r.displayIf&&this.state.formRoot.querySelectorAll(`[data-field-key="${r.key}"]`).forEach(i=>{var s,d;try{const u=j(r.displayIf,t),c=i.getAttribute("data-conditionally-hidden")==="true";if(u&&c){const h=V(r,{path:l,prefill:t,formData:t,state:this.state,instance:this});(s=i.parentNode)==null||s.replaceChild(h,i)}else if(!u&&!c){const h=document.createElement("div");h.className="fb-field-wrapper-hidden",h.style.display="none",h.setAttribute("data-field-key",r.key),h.setAttribute("data-conditionally-hidden","true"),(d=i.parentNode)==null||d.replaceChild(h,i)}}catch(u){console.error(`Error re-evaluating displayIf for field "${r.key}":`,u)}}),(r.type==="container"||r.type==="group")&&"elements"in r&&r.elements){const i=t==null?void 0:t[r.key];Array.isArray(i)?i.forEach((s,d)=>{n(r.elements,`${l}[${d}]`)}):n(r.elements,l)}})};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&&T(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 fe(e){return new B(e)}return typeof window!="undefined"&&(window.FormBuilder=B,window.createFormBuilder=fe,window.validateSchema=z),F.FormBuilderInstance=B,F.createFormBuilder=fe,F.default=B,F.defaultTheme=q,F.exampleThemes=yt,F.validateSchema=z,Object.defineProperty(F,"__esModule",{value:!0}),F})({});
|