@dmitryvim/form-builder 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/browser/formbuilder.min.js +33 -33
- package/dist/browser/formbuilder.v0.2.4.min.js +184 -0
- package/dist/cjs/index.cjs +18 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +18 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +33 -33
- package/dist/types/instance/FormBuilderInstance.d.ts +1 -0
- package/dist/types/types/config.d.ts +1 -0
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.2.min.js +0 -184
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var FormBuilder=(function(F){"use strict";function se(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 ce(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 de(e,t){e.maxSizeMB&&t.push(`max_size=${e.maxSizeMB}MB`)}function ue(e,t){var n;(n=e.accept)!=null&&n.extensions&&t.push(`formats=${e.accept.extensions.map(o=>o.toUpperCase()).join(",")}`)}function me(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 k(e){const t=[];return t.push(e.required?"required":"optional"),se(e,t),ce(e,t),de(e,t),ue(e,t),me(e,t),t.join(" \u2022 ")}function M(e){const t=[];if(!e||typeof e!="object")return t.push("Schema must be an object"),t;if(e.version||t.push("Schema missing version"),!Array.isArray(e.elements))return t.push("Schema missing elements array"),t;function n(o,s){o.forEach((l,r)=>{const a=`${s}[${r}]`;if(l.type||t.push(`${a}: missing type`),l.key||t.push(`${a}: missing key`),l.type==="group"&&"elements"in l&&l.elements&&n(l.elements,`${a}.elements`),l.type==="container"&&l.elements&&n(l.elements,`${a}.elements`),l.type==="select"&&l.options){const i=l.default;i!=null&&i!==""&&(l.options.some(c=>c.value===i)||t.push(`${a}: default "${i}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function A(e){return e&&typeof e=="object"&&e.constructor===Object}function L(e,t){return e?`${e}.${t}`:t}function T(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function pe(e,t,n,o){const s=t.state,l=document.createElement("input");if(l.type="text",l.className="w-full rounded-lg",l.style.cssText=`
|
|
2
|
+
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
3
|
+
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
4
|
+
border-radius: var(--fb-border-radius);
|
|
5
|
+
background-color: ${s.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
|
|
6
|
+
color: var(--fb-text-color);
|
|
7
|
+
font-size: var(--fb-font-size);
|
|
8
|
+
font-family: var(--fb-font-family);
|
|
9
|
+
transition: all var(--fb-transition-duration) ease-in-out;
|
|
10
|
+
`,l.name=o,l.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",l.value=t.prefill[e.key]||e.default||"",l.readOnly=s.config.readonly,s.config.readonly||(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)")})),!s.config.readonly&&t.instance){const a=()=>{t.instance.triggerOnChange(o,l.value)};l.addEventListener("blur",a),l.addEventListener("input",a)}n.appendChild(l);const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
|
|
11
|
+
font-size: var(--fb-font-size-small);
|
|
12
|
+
color: var(--fb-text-secondary-color);
|
|
13
|
+
`,r.textContent=k(e),n.appendChild(r)}function fe(e,t,n,o){var s,l;const r=t.state,a=t.prefill[e.key]||[],i=Array.isArray(a)?[...a]:[],c=(s=e.minCount)!=null?s:1,u=(l=e.maxCount)!=null?l:1/0;for(;i.length<c;)i.push(e.default||"");const d=document.createElement("div");d.className="space-y-2",n.appendChild(d);function h(){d.querySelectorAll(".multiple-text-item").forEach((x,g)=>{const y=x.querySelector("input");y&&(y.name=`${o}[${g}]`)})}function p(x="",g=-1){const y=document.createElement("div");y.className="multiple-text-item flex items-center gap-2";const f=document.createElement("input");if(f.type="text",f.className="flex-1",f.style.cssText=`
|
|
14
|
+
padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
|
|
15
|
+
border: var(--fb-border-width) solid var(--fb-border-color);
|
|
16
|
+
border-radius: var(--fb-border-radius);
|
|
17
|
+
background-color: ${r.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
|
|
18
|
+
color: var(--fb-text-color);
|
|
19
|
+
font-size: var(--fb-font-size);
|
|
20
|
+
font-family: var(--fb-font-family);
|
|
21
|
+
transition: all var(--fb-transition-duration) ease-in-out;
|
|
22
|
+
`,f.placeholder=e.placeholder||"Enter text",f.value=x,f.readOnly=r.config.readonly,r.config.readonly||(f.addEventListener("focus",()=>{f.style.borderColor="var(--fb-border-focus-color)",f.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",f.style.outlineOffset="0"}),f.addEventListener("blur",()=>{f.style.borderColor="var(--fb-border-color)",f.style.outline="none"}),f.addEventListener("mouseenter",()=>{document.activeElement!==f&&(f.style.borderColor="var(--fb-border-hover-color)")}),f.addEventListener("mouseleave",()=>{document.activeElement!==f&&(f.style.borderColor="var(--fb-border-color)")})),!r.config.readonly&&t.instance){const C=()=>{t.instance.triggerOnChange(f.name,f.value)};f.addEventListener("blur",C),f.addEventListener("input",C)}return y.appendChild(f),g===-1?d.appendChild(y):d.insertBefore(y,d.children[g]),h(),y}function m(){if(r.config.readonly)return;const x=d.querySelectorAll(".multiple-text-item"),g=x.length;x.forEach(y=>{let f=y.querySelector(".remove-item-btn");f||(f=document.createElement("button"),f.type="button",f.className="remove-item-btn px-2 py-1 rounded",f.style.cssText=`
|
|
23
|
+
color: var(--fb-error-color);
|
|
24
|
+
background-color: transparent;
|
|
25
|
+
transition: background-color var(--fb-transition-duration);
|
|
26
|
+
`,f.innerHTML="\u2715",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{const E=Array.from(d.children).indexOf(y);d.children.length>c&&(i.splice(E,1),y.remove(),h(),v(),m())},y.appendChild(f));const C=g<=c;f.disabled=C,f.style.opacity=C?"0.5":"1",f.style.pointerEvents=C?"none":"auto"})}function v(){const x=n.querySelector(".add-text-btn");if(x&&x.remove(),!r.config.readonly&&i.length<u){const g=document.createElement("button");g.type="button",g.className="add-text-btn mt-2 px-3 py-1 rounded",g.style.cssText=`
|
|
27
|
+
color: var(--fb-primary-color);
|
|
28
|
+
border: var(--fb-border-width) solid var(--fb-primary-color);
|
|
29
|
+
background-color: transparent;
|
|
30
|
+
font-size: var(--fb-font-size);
|
|
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=()=>{i.push(e.default||""),p(e.default||""),v(),m()},n.appendChild(g)}}i.forEach(x=>p(x)),v(),m();const b=document.createElement("p");b.className="mt-1",b.style.cssText=`
|
|
33
|
+
font-size: var(--fb-font-size-small);
|
|
34
|
+
color: var(--fb-text-secondary-color);
|
|
35
|
+
`,b.textContent=k(e),n.appendChild(b)}function I(e,t,n){var o,s,l;const r=[],{scopeRoot:a,skipValidation:i}=n,c=(d,h)=>{var p,m;if(!d)return;const v=`error-${d.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(v);h?(d.classList.add("invalid"),d.title=h,b||(b=document.createElement("div"),b.id=v,b.className="error-message",b.style.cssText=`
|
|
36
|
+
color: var(--fb-error-color);
|
|
37
|
+
font-size: var(--fb-font-size-small);
|
|
38
|
+
margin-top: 0.25rem;
|
|
39
|
+
`,d.nextSibling?(p=d.parentNode)==null||p.insertBefore(b,d.nextSibling):(m=d.parentNode)==null||m.appendChild(b)),b.textContent=h,b.style.display="block"):(d.classList.remove("invalid"),d.title="",b&&b.remove())},u=(d,h,p)=>{let m=!1;if(!i&&h){if(e.minLength!==void 0&&e.minLength!==null&&h.length<e.minLength)r.push(`${p}: minLength=${e.minLength}`),c(d,`minLength=${e.minLength}`),m=!0;else if(e.maxLength!==void 0&&e.maxLength!==null&&h.length>e.maxLength)r.push(`${p}: maxLength=${e.maxLength}`),c(d,`maxLength=${e.maxLength}`),m=!0;else if(e.pattern)try{new RegExp(e.pattern).test(h)||(r.push(`${p}: pattern mismatch`),c(d,"pattern mismatch"),m=!0)}catch(v){r.push(`${p}: invalid pattern`),c(d,"invalid pattern"),m=!0}}m||c(d,null)};if(e.multiple){const d=a.querySelectorAll(`[name^="${t}["]`),h=[];if(d.forEach((p,m)=>{var v;const b=(v=p==null?void 0:p.value)!=null?v:"";h.push(b),u(p,b,`${t}[${m}]`)}),!i){const p=(o=e.minCount)!=null?o:1,m=(s=e.maxCount)!=null?s:1/0,v=h.filter(b=>b.trim()!=="");e.required&&v.length===0&&r.push(`${t}: required`),v.length<p&&r.push(`${t}: minimum ${p} items required`),v.length>m&&r.push(`${t}: maximum ${m} items allowed`)}return{value:h,errors:r}}else{const d=a.querySelector(`[name$="${t}"]`),h=(l=d==null?void 0:d.value)!=null?l:"";return!i&&e.required&&h===""?(r.push(`${t}: required`),c(d,"required"),{value:"",errors:r}):(u(d,h,t),{value:h,errors:r})}}function U(e,t,n,o){const{scopeRoot:s}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateTextField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=s.querySelectorAll(`[name^="${t}["]`);l.forEach((r,a)=>{a<n.length&&(r.value=n[a]!=null?String(n[a]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateTextField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=s.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function he(e,t,n,o){const s=t.state,l=document.createElement("textarea");if(l.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",l.name=o,l.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",l.rows=e.rows||4,l.value=t.prefill[e.key]||e.default||"",l.readOnly=s.config.readonly,!s.config.readonly&&t.instance){const a=()=>{t.instance.triggerOnChange(o,l.value)};l.addEventListener("blur",a),l.addEventListener("input",a)}n.appendChild(l);const r=document.createElement("p");r.className="text-xs text-gray-500 mt-1",r.textContent=k(e),n.appendChild(r)}function ve(e,t,n,o){var s,l;const r=t.state,a=t.prefill[e.key]||[],i=Array.isArray(a)?[...a]:[],c=(s=e.minCount)!=null?s:1,u=(l=e.maxCount)!=null?l:1/0;for(;i.length<c;)i.push(e.default||"");const d=document.createElement("div");d.className="space-y-2",n.appendChild(d);function h(){d.querySelectorAll(".multiple-textarea-item").forEach((x,g)=>{const y=x.querySelector("textarea");y&&(y.name=`${o}[${g}]`)})}function p(x="",g=-1){const y=document.createElement("div");y.className="multiple-textarea-item";const f=document.createElement("textarea");if(f.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",f.placeholder=e.placeholder||"Enter text",f.rows=e.rows||4,f.value=x,f.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const C=()=>{t.instance.triggerOnChange(f.name,f.value)};f.addEventListener("blur",C),f.addEventListener("input",C)}return y.appendChild(f),g===-1?d.appendChild(y):d.insertBefore(y,d.children[g]),h(),y}function m(){if(r.config.readonly)return;const x=d.querySelectorAll(".multiple-textarea-item"),g=x.length;x.forEach(y=>{let f=y.querySelector(".remove-item-btn");f||(f=document.createElement("button"),f.type="button",f.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",f.innerHTML="\u2715 Remove",f.onclick=()=>{const E=Array.from(d.children).indexOf(y);d.children.length>c&&(i.splice(E,1),y.remove(),h(),v(),m())},y.appendChild(f));const C=g<=c;f.disabled=C,f.style.opacity=C?"0.5":"1",f.style.pointerEvents=C?"none":"auto"})}function v(){const x=n.querySelector(".add-textarea-btn");if(x&&x.remove(),!r.config.readonly&&i.length<u){const g=document.createElement("button");g.type="button",g.className="add-textarea-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",g.textContent=`+ Add ${e.label||"Textarea"}`,g.onclick=()=>{i.push(e.default||""),p(e.default||""),v(),m()},n.appendChild(g)}}i.forEach(x=>p(x)),v(),m();const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=k(e),n.appendChild(b)}function ge(e,t,n){return I(e,t,n)}function ye(e,t,n,o){U(e,t,n,o)}function be(e,t,n,o){const s=t.state,l=document.createElement("input");if(l.type="number",l.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",l.name=o,l.placeholder=e.placeholder||"0",e.min!==void 0&&(l.min=e.min.toString()),e.max!==void 0&&(l.max=e.max.toString()),e.step!==void 0&&(l.step=e.step.toString()),l.value=t.prefill[e.key]||e.default||"",l.readOnly=s.config.readonly,!s.config.readonly&&t.instance){const a=()=>{const i=l.value?parseFloat(l.value):null;t.instance.triggerOnChange(o,i)};l.addEventListener("blur",a),l.addEventListener("input",a)}n.appendChild(l);const r=document.createElement("p");r.className="text-xs text-gray-500 mt-1",r.textContent=k(e),n.appendChild(r)}function xe(e,t,n,o){var s,l;const r=t.state,a=t.prefill[e.key]||[],i=Array.isArray(a)?[...a]:[],c=(s=e.minCount)!=null?s:1,u=(l=e.maxCount)!=null?l:1/0;for(;i.length<c;)i.push(e.default||"");const d=document.createElement("div");d.className="space-y-2",n.appendChild(d);function h(){d.querySelectorAll(".multiple-number-item").forEach((x,g)=>{const y=x.querySelector("input");y&&(y.name=`${o}[${g}]`)})}function p(x="",g=-1){const y=document.createElement("div");y.className="multiple-number-item flex items-center gap-2";const f=document.createElement("input");if(f.type="number",f.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",f.placeholder=e.placeholder||"0",e.min!==void 0&&(f.min=e.min.toString()),e.max!==void 0&&(f.max=e.max.toString()),e.step!==void 0&&(f.step=e.step.toString()),f.value=x.toString(),f.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const C=()=>{const E=f.value?parseFloat(f.value):null;t.instance.triggerOnChange(f.name,E)};f.addEventListener("blur",C),f.addEventListener("input",C)}return y.appendChild(f),g===-1?d.appendChild(y):d.insertBefore(y,d.children[g]),h(),y}function m(){if(r.config.readonly)return;const x=d.querySelectorAll(".multiple-number-item"),g=x.length;x.forEach(y=>{let f=y.querySelector(".remove-item-btn");f||(f=document.createElement("button"),f.type="button",f.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",f.innerHTML="\u2715",f.onclick=()=>{const E=Array.from(d.children).indexOf(y);d.children.length>c&&(i.splice(E,1),y.remove(),h(),v(),m())},y.appendChild(f));const C=g<=c;f.disabled=C,f.style.opacity=C?"0.5":"1",f.style.pointerEvents=C?"none":"auto"})}function v(){const x=n.querySelector(".add-number-btn");if(x&&x.remove(),!r.config.readonly&&i.length<u){const g=document.createElement("button");g.type="button",g.className="add-number-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",g.textContent=`+ Add ${e.label||"Number"}`,g.onclick=()=>{i.push(e.default||""),p(e.default||""),v(),m()},n.appendChild(g)}}i.forEach(x=>p(x)),v(),m();const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=k(e),n.appendChild(b)}function Ce(e,t,n){var o,s,l,r,a;const i=[],{scopeRoot:c,skipValidation:u}=n,d=(p,m)=>{var v,b;if(!p)return;const x=`error-${p.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(x);m?(p.classList.add("invalid"),p.title=m,g||(g=document.createElement("div"),g.id=x,g.className="error-message",g.style.cssText=`
|
|
40
|
+
color: var(--fb-error-color);
|
|
41
|
+
font-size: var(--fb-font-size-small);
|
|
42
|
+
margin-top: 0.25rem;
|
|
43
|
+
`,p.nextSibling?(v=p.parentNode)==null||v.insertBefore(g,p.nextSibling):(b=p.parentNode)==null||b.appendChild(g)),g.textContent=m,g.style.display="block"):(p.classList.remove("invalid"),p.title="",g&&g.remove())},h=(p,m,v)=>{let b=!1;!u&&e.min!==void 0&&e.min!==null&&m<e.min?(i.push(`${v}: < min=${e.min}`),d(p,`< min=${e.min}`),b=!0):!u&&e.max!==void 0&&e.max!==null&&m>e.max&&(i.push(`${v}: > max=${e.max}`),d(p,`> max=${e.max}`),b=!0),b||d(p,null)};if(e.multiple){const p=c.querySelectorAll(`[name^="${t}["]`),m=[];if(p.forEach((v,b)=>{var x,g,y;const f=(x=v==null?void 0:v.value)!=null?x:"";if(f===""){m.push(null),d(v,null);return}const C=parseFloat(f);if(!u&&!Number.isFinite(C)){i.push(`${t}[${b}]: not a number`),d(v,"not a number"),m.push(null);return}h(v,C,`${t}[${b}]`);const E=Number.isInteger((g=e.decimals)!=null?g:0)&&(y=e.decimals)!=null?y:0;m.push(Number(C.toFixed(E)))}),!u){const v=(o=e.minCount)!=null?o:1,b=(s=e.maxCount)!=null?s:1/0,x=m.filter(g=>g!==null);e.required&&x.length===0&&i.push(`${t}: required`),x.length<v&&i.push(`${t}: minimum ${v} items required`),x.length>b&&i.push(`${t}: maximum ${b} items allowed`)}return{value:m,errors:i}}else{const p=c.querySelector(`[name$="${t}"]`),m=(l=p==null?void 0:p.value)!=null?l:"";if(!u&&e.required&&m==="")return i.push(`${t}: required`),d(p,"required"),{value:null,errors:i};if(m==="")return d(p,null),{value:null,errors:i};const v=parseFloat(m);if(!u&&!Number.isFinite(v))return i.push(`${t}: not a number`),d(p,"not a number"),{value:null,errors:i};h(p,v,t);const b=Number.isInteger((r=e.decimals)!=null?r:0)&&(a=e.decimals)!=null?a:0;return{value:Number(v.toFixed(b)),errors:i}}}function Ee(e,t,n,o){const{scopeRoot:s}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateNumberField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=s.querySelectorAll(`[name^="${t}["]`);l.forEach((r,a)=>{a<n.length&&(r.value=n[a]!=null?String(n[a]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=s.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function we(e,t,n,o){const s=t.state,l=document.createElement("select");if(l.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",l.name=o,l.disabled=s.config.readonly,(e.options||[]).forEach(a=>{const i=document.createElement("option");i.value=a.value,i.textContent=a.label,(t.prefill[e.key]||e.default)===a.value&&(i.selected=!0),l.appendChild(i)}),!s.config.readonly&&t.instance){const a=()=>{t.instance.triggerOnChange(o,l.value)};l.addEventListener("change",a)}n.appendChild(l);const r=document.createElement("p");r.className="text-xs text-gray-500 mt-1",r.textContent=k(e),n.appendChild(r)}function $e(e,t,n,o){var s,l,r,a;const i=t.state,c=t.prefill[e.key]||[],u=Array.isArray(c)?[...c]:[],d=(s=e.minCount)!=null?s:1,h=(l=e.maxCount)!=null?l:1/0;for(;u.length<d;)u.push(e.default||((a=(r=e.options)==null?void 0:r[0])==null?void 0:a.value)||"");const p=document.createElement("div");p.className="space-y-2",n.appendChild(p);function m(){p.querySelectorAll(".multiple-select-item").forEach((y,f)=>{const C=y.querySelector("select");C&&(C.name=`${o}[${f}]`)})}function v(y="",f=-1){const C=document.createElement("div");C.className="multiple-select-item flex items-center gap-2";const E=document.createElement("select");if(E.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",E.disabled=i.config.readonly,(e.options||[]).forEach(w=>{const S=document.createElement("option");S.value=w.value,S.textContent=w.label,y===w.value&&(S.selected=!0),E.appendChild(S)}),!i.config.readonly&&t.instance){const w=()=>{t.instance.triggerOnChange(E.name,E.value)};E.addEventListener("change",w)}return C.appendChild(E),f===-1?p.appendChild(C):p.insertBefore(C,p.children[f]),m(),C}function b(){if(i.config.readonly)return;const y=p.querySelectorAll(".multiple-select-item"),f=y.length;y.forEach(C=>{let E=C.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",E.innerHTML="\u2715",E.onclick=()=>{const S=Array.from(p.children).indexOf(C);p.children.length>d&&(u.splice(S,1),C.remove(),m(),x(),b())},C.appendChild(E));const w=f<=d;E.disabled=w,E.style.opacity=w?"0.5":"1",E.style.pointerEvents=w?"none":"auto"})}function x(){const y=n.querySelector(".add-select-btn");if(y&&y.remove(),!i.config.readonly&&u.length<h){const f=document.createElement("button");f.type="button",f.className="add-select-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm",f.textContent=`+ Add ${e.label||"Selection"}`,f.onclick=()=>{var C,E;const w=e.default||((E=(C=e.options)==null?void 0:C[0])==null?void 0:E.value)||"";u.push(w),v(w),x(),b()},n.appendChild(f)}}u.forEach(y=>v(y)),x(),b();const g=document.createElement("p");g.className="text-xs text-gray-500 mt-1",g.textContent=k(e),n.appendChild(g)}function ke(e,t,n){var o;const s=[],{scopeRoot:l,skipValidation:r}=n,a=(c,u)=>{var d,h;if(!c)return;const p=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(p);u?(c.classList.add("invalid"),c.title=u,m||(m=document.createElement("div"),m.id=p,m.className="error-message",m.style.cssText=`
|
|
44
|
+
color: var(--fb-error-color);
|
|
45
|
+
font-size: var(--fb-font-size-small);
|
|
46
|
+
margin-top: 0.25rem;
|
|
47
|
+
`,c.nextSibling?(d=c.parentNode)==null||d.insertBefore(m,c.nextSibling):(h=c.parentNode)==null||h.appendChild(m)),m.textContent=u,m.style.display="block"):(c.classList.remove("invalid"),c.title="",m&&m.remove())},i=(c,u,d,h)=>{var p,m;if(r)return;const v=u.filter(h),b="minCount"in d&&(p=d.minCount)!=null?p:1,x="maxCount"in d&&(m=d.maxCount)!=null?m:1/0;d.required&&v.length===0&&s.push(`${c}: required`),v.length<b&&s.push(`${c}: minimum ${b} items required`),v.length>x&&s.push(`${c}: maximum ${x} items allowed`)};if("multiple"in e&&e.multiple){const c=l.querySelectorAll(`[name^="${t}["]`),u=[];return c.forEach(d=>{var h;const p=(h=d==null?void 0:d.value)!=null?h:"";u.push(p),a(d,null)}),i(t,u,e,d=>d!==""),{value:u,errors:s}}else{const c=l.querySelector(`[name$="${t}"]`),u=(o=c==null?void 0:c.value)!=null?o:"";return!r&&e.required&&u===""?(s.push(`${t}: required`),a(c,"required"),{value:null,errors:s}):(a(c,null),{value:u===""?null:u,errors:s})}}function Fe(e,t,n,o){const{scopeRoot:s}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSelectField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=s.querySelectorAll(`[name^="${t}["]`);l.forEach((r,a)=>{a<n.length&&(r.value=n[a]!=null?String(n[a]):"",r.querySelectorAll("option").forEach(i=>{i.selected=i.value===String(n[a])}),r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${l.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=s.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.querySelectorAll("option").forEach(r=>{r.selected=r.value===String(n)}),l.classList.remove("invalid"),l.title="")}}function $(e,t){const n=t.config.locale||"en";return(t.config.translations[n]||t.config.translations.en)[e]||e}async function O(e,t,n,o={}){const{fileName:s="",isReadonly:l=!1,deps:r=null}=o;if(!l&&r&&(!r.picker||!r.fileUploadHandler||!r.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");T(e),l&&e.classList.add("cursor-pointer");const a=document.createElement("img");a.className="w-full h-full object-contain",a.alt=s||"Preview";const i=n.resourceIndex.get(t);if(i&&i.file&&i.file instanceof File){if(i.type&&i.type.startsWith("image/")){const c=new FileReader;c.onload=u=>{var d;a.src=((d=u.target)==null?void 0:d.result)||""},c.readAsDataURL(i.file),e.appendChild(a)}else if(i.type&&i.type.startsWith("video/")){const c=URL.createObjectURL(i.file);e.onclick=null;const u=e.cloneNode(!1);e.parentNode&&e.parentNode.replaceChild(u,e),e=u,e.innerHTML=`
|
|
48
|
+
<div class="relative group h-full">
|
|
49
|
+
<video class="w-full h-full object-contain" controls preload="auto" muted>
|
|
50
|
+
<source src="${c}" type="${i.type}">
|
|
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
|
+
${$("removeElement",n)}
|
|
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
|
+
`;const d=e.querySelector(".change-file-btn");d&&(d.onclick=p=>{p.stopPropagation(),r!=null&&r.picker&&r.picker.click()});const h=e.querySelector(".delete-file-btn");h&&(h.onclick=p=>{var m;p.stopPropagation(),n.resourceIndex.delete(t);const v=(m=e.parentElement)==null?void 0:m.querySelector('input[type="hidden"]');v&&(v.value=""),r!=null&&r.fileUploadHandler&&(e.onclick=r.fileUploadHandler),r!=null&&r.dragHandler&&z(e,r.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">${$("clickDragText",n)}</div>
|
|
68
|
+
</div>
|
|
69
|
+
`})}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400"><div class="text-2xl mb-2">\u{1F4C1}</div><div class="text-sm">${s}</div></div>`;!l&&!(i&&i.type&&i.type.startsWith("video/"))&&Se(e,n,()=>{var c;n.resourceIndex.delete(t);const u=(c=e.parentElement)==null?void 0:c.querySelector('input[type="hidden"]');u&&(u.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">${$("clickDragText",n)}</div>
|
|
75
|
+
</div>
|
|
76
|
+
`})}else if(n.config.getThumbnail)try{const c=await n.config.getThumbnail(t);c?(T(e),a.src=c,e.appendChild(a)):j(e,n)}catch(c){console.error("Failed to get thumbnail:",c),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">${s||"Preview unavailable"}</div>
|
|
82
|
+
</div>
|
|
83
|
+
`}else j(e,n)}async function B(e,t,n){var o,s;const l=t.resourceIndex.get(e),r=(l==null?void 0:l.name)||e.split("/").pop()||"file",a=r.toLowerCase().match(/\.psd$/),i=document.createElement("div");i.className=a?"space-y-2":"space-y-3";const c=document.createElement("div");a?c.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":c.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const u=!a&&(((o=l==null?void 0:l.type)==null?void 0:o.startsWith("image/"))||r.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),d=((s=l==null?void 0:l.type)==null?void 0:s.startsWith("video/"))||r.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(u)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?c.innerHTML=`<img src="${m}" alt="${r}" class="w-full h-auto">`:c.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${r}</div></div></div>`}catch(m){console.warn("getThumbnail failed for",e,m),c.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${r}</div></div></div>`}else c.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${r}</div></div></div>`;else if(d)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?c.innerHTML=`
|
|
84
|
+
<div class="relative group">
|
|
85
|
+
<video class="w-full h-auto" controls preload="auto" muted>
|
|
86
|
+
<source src="${m}" type="${(l==null?void 0:l.type)||"video/mp4"}">
|
|
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
|
+
</video>
|
|
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">
|
|
90
|
+
<div class="bg-white bg-opacity-90 rounded-full p-3">
|
|
91
|
+
<svg class="w-8 h-8 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
|
|
92
|
+
<path d="M8 5v14l11-7z"/>
|
|
93
|
+
</svg>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
`:c.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${r}</div></div></div>`}catch(m){console.warn("getThumbnail failed for video",e,m),c.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${r}</div></div></div>`}else c.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${r}</div></div></div>`;else{const m=a?"\u{1F3A8}":"\u{1F4C1}",v=a?"PSD File":"Document";a?c.innerHTML=`
|
|
98
|
+
<div class="flex items-center space-x-3">
|
|
99
|
+
<div class="text-3xl text-gray-400">${m}</div>
|
|
100
|
+
<div class="flex-1 min-w-0">
|
|
101
|
+
<div class="text-sm font-medium text-gray-900 truncate">${r}</div>
|
|
102
|
+
<div class="text-xs text-gray-500">${v}</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
`:c.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">${r}</div><div class="text-xs text-gray-500 mt-1">${v}</div></div></div>`}const h=document.createElement("p");h.className=a?"hidden":"text-sm font-medium text-gray-900 text-center",h.textContent=r;const p=document.createElement("button");return p.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",p.textContent=$("downloadButton",t),p.onclick=m=>{m.preventDefault(),m.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,r):Te(e,r,t)},i.appendChild(c),i.appendChild(h),i.appendChild(p),i}function P(e,t,n,o){T(e);const s=!e.classList.contains("grid");if((!t||t.length===0)&&s){const a=document.createElement("div");a.className="grid grid-cols-4 gap-3 mb-3";for(let u=0;u<4;u++){const d=document.createElement("div");d.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 p=document.createElementNS("http://www.w3.org/2000/svg","path");p.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(p),d.appendChild(h),d.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()},a.appendChild(d)}const i=document.createElement("div");i.className="text-center text-xs text-gray-600";const c=document.createElement("span");c.className="underline cursor-pointer",c.textContent=$("uploadText",n),c.onclick=u=>{u.stopPropagation();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 h=d==null?void 0:d.querySelector('input[type="file"]');h&&h.click()},i.appendChild(c),i.appendChild(document.createTextNode(` ${$("dragDropText",n)}`)),e.appendChild(a),e.appendChild(i);return}e.className="files-list grid grid-cols-4 gap-3 mt-2";const l=t?t.length:0,r=(Math.floor(l/4)+1)*4;for(let a=0;a<r;a++){const i=document.createElement("div");if(t&&a<t.length){const c=t[a],u=n.resourceIndex.get(c);if(i.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",i.dataset.resourceId=c,Le(i,c,u,n).catch(d=>{console.error("Failed to render thumbnail:",d),i.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
106
|
+
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
107
|
+
<div class="text-xs">Preview error</div>
|
|
108
|
+
</div>`}),o){const d=document.createElement("div");d.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=$("removeElement",n),h.onclick=p=>{p.stopPropagation(),o(c)},d.appendChild(h),i.appendChild(d)}}else i.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded-lg flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors",i.innerHTML='<svg class="w-12 h-12 text-gray-400" fill="currentColor" viewBox="0 0 24 24"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>',i.onclick=()=>{let c=e.parentElement;for(;c&&!c.classList.contains("space-y-2");)c=c.parentElement;!c&&e.classList.contains("space-y-2")&&(c=e);const u=c==null?void 0:c.querySelector('input[type="file"]');u&&u.click()};e.appendChild(i)}}function V(e,t="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
109
|
+
<svg class="${t} text-red-400" fill="currentColor" viewBox="0 0 24 24">
|
|
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
|
+
</svg>
|
|
112
|
+
<div class="text-xs mt-1 text-red-600">Preview error</div>
|
|
113
|
+
</div>`}async function Le(e,t,n,o){var s,l;if(n&&(s=n.type)!=null&&s.startsWith("image/"))if(n.file&&n.file instanceof File){const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n.name;const a=new FileReader;a.onload=i=>{var c;r.src=((c=i.target)==null?void 0:c.result)||""},a.readAsDataURL(n.file),e.appendChild(r)}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);if(r){const a=document.createElement("img");a.className="w-full h-full object-contain",a.alt=n.name,a.src=r,e.appendChild(a)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
114
|
+
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
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
|
+
</svg>
|
|
117
|
+
</div>`}catch(r){const a=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(a,t),V(e)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
118
|
+
<svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
|
|
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
|
+
</svg>
|
|
121
|
+
</div>`;else if(n&&(l=n.type)!=null&&l.startsWith("video/"))if(n.file&&n.file instanceof File){const r=URL.createObjectURL(n.file);e.innerHTML=`
|
|
122
|
+
<div class="relative group h-full w-full">
|
|
123
|
+
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
124
|
+
<source src="${r}" type="${n.type}">
|
|
125
|
+
</video>
|
|
126
|
+
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
127
|
+
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
128
|
+
<svg class="w-4 h-4 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
|
|
129
|
+
<path d="M8 5v14l11-7z"/>
|
|
130
|
+
</svg>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
`}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);r?e.innerHTML=`
|
|
135
|
+
<div class="relative group h-full w-full">
|
|
136
|
+
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
137
|
+
<source src="${r}" type="${n.type}">
|
|
138
|
+
</video>
|
|
139
|
+
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
140
|
+
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
141
|
+
<svg class="w-4 h-4 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
|
|
142
|
+
<path d="M8 5v14l11-7z"/>
|
|
143
|
+
</svg>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
`:e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
148
|
+
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
149
|
+
<path d="M8 5v14l11-7z"/>
|
|
150
|
+
</svg>
|
|
151
|
+
<div class="text-xs mt-1">${(n==null?void 0:n.name)||"Video"}</div>
|
|
152
|
+
</div>`}catch(r){const a=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(a,t),V(e,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
153
|
+
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
|
|
154
|
+
<path d="M8 5v14l11-7z"/>
|
|
155
|
+
</svg>
|
|
156
|
+
<div class="text-xs mt-1">${(n==null?void 0:n.name)||"Video"}</div>
|
|
157
|
+
</div>`;else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
158
|
+
<div class="text-2xl mb-1">\u{1F4C1}</div>
|
|
159
|
+
<div class="text-xs">${(n==null?void 0:n.name)||"File"}</div>
|
|
160
|
+
</div>`}function j(e,t){e.innerHTML=`
|
|
161
|
+
<div class="flex flex-col items-center justify-center h-full text-gray-400">
|
|
162
|
+
<svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
|
|
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
|
+
</svg>
|
|
165
|
+
<div class="text-sm text-center">${$("clickDragText",t)}</div>
|
|
166
|
+
</div>
|
|
167
|
+
`}async function _(e,t,n,o,s=null,l){var r,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=(r=t.parentElement)==null?void 0:r.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,O(t,i,o,{fileName:e.name,isReadonly:!1,deps:s}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,i)}function z(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 Se(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 l=document.createElement("button");l.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",l.textContent=$("removeElement",t),l.onclick=r=>{r.stopPropagation(),n()},s.appendChild(l),e.appendChild(s)}async function W(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 Te(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,l=await fetch(s);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const r=await l.blob();Ne(r,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 Ne(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 G(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const s=n.split("/").pop()||"file",l=(o=s.split(".").pop())==null?void 0:o.toLowerCase();let r="application/octet-stream";l&&(["jpg","jpeg","png","gif","webp"].includes(l)?r=`image/${l==="jpg"?"jpeg":l}`:["mp4","webm","mov","avi"].includes(l)&&(r=`video/${l==="mov"?"quicktime":l}`)),t.resourceIndex.set(n,{name:s,type:r,size:0,uploadedAt:new Date,file:void 0})}})}function Ae(e,t,n,o,s,l){var r;if(!s.resourceIndex.has(e)){const i=e.split("/").pop()||"file",c=(r=i.split(".").pop())==null?void 0:r.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})}O(t,e,s,{fileName:e,isReadonly:!1,deps:l}).catch(console.error);const a=document.createElement("input");a.type="hidden",a.name=n,a.value=e,o.appendChild(a)}function Y(e,t,n,o,s,l){z(e,async r=>{const a=Array.from(r);for(const i of a){const c=await W(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(),l&&s&&!n.config.readonly&&l.triggerOnChange(s,t)})}function J(e,t,n,o,s,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const a=await W(r,n);n.resourceIndex.set(a,{name:r.name,type:r.type,size:r.size,uploadedAt:new Date,file:void 0}),t.push(a)}o(),e.value="",l&&s&&!n.config.readonly&&l.triggerOnChange(s,t)}}function qe(e,t,n,o){var s;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)B(r,l).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">${$("noFileSelected",l)}</div>`,n.appendChild(a)}}else{const r=document.createElement("div");r.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 b={picker:a,fileUploadHandler:u,dragHandler:d};_(v[0],i,o,l,b,t.instance)}};c?Ae(c,i,o,r,l,{picker:a,fileUploadHandler:u,dragHandler:d}):j(i,l),i.onclick=u,z(i,d),a.onchange=()=>{if(a.files&&a.files.length>0){const v={picker:a,fileUploadHandler:u,dragHandler:d};_(a.files[0],i,o,l,v,t.instance)}},r.appendChild(i),r.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">${$("uploadText",l)}</span> ${$("dragDropTextSingle",l)}`;const p=h.querySelector("span");p&&(p.onclick=()=>a.click()),r.appendChild(h);const m=document.createElement("p");m.className="text-xs text-gray-500 mt-1 text-center",m.textContent=k(e),r.appendChild(m),n.appendChild(r)}}function He(e,t,n,o){var s;const l=t.state;if(l.config.readonly){const r=document.createElement("div");r.className="space-y-4";const a=t.prefill[e.key]||[];a.length>0?a.forEach(i=>{B(i,l).then(c=>{r.appendChild(c)}).catch(c=>{console.error("Failed to render file preview:",c)})}):r.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${$("noFilesSelected",l)}</div></div>`,n.appendChild(r)}else{let r=function(){P(u,d,l,p=>{const m=d.indexOf(p);m>-1&&d.splice(m,1),r()})};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(p=>`.${p}`).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]||[];G(d,l),r(),Y(c,d,l,r,o,t.instance),J(i,d,l,r,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=k(e),a.appendChild(h),n.appendChild(a)}}function Me(e,t,n,o){var s,l,r;const a=t.state,i=(s=e.minCount)!=null?s:0,c=(l=e.maxCount)!=null?l: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=>{B(h,a).then(p=>{u.appendChild(p)}).catch(p=>{console.error("Failed to render file preview:",p)})}):u.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${$("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:((r=e.accept.extensions)==null?void 0:r.map(v=>`.${v}`).join(","))||"");const h=document.createElement("div");h.className="files-list space-y-2",u.appendChild(d),u.appendChild(h);const p=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];G(p,a);const m=()=>{P(h,p,a,y=>{p.splice(p.indexOf(y),1),m()});const v=document.createElement("div");v.className="text-xs text-gray-500 mt-2 file-count-info";const b=`${p.length} file${p.length!==1?"s":""}`,x=i>0||c<1/0?` (${i}-${c} allowed)`:"";v.textContent=b+x;const g=u.querySelector(".file-count-info");g&&g.remove(),u.appendChild(v)};Y(h,p,a,m,o,t.instance),J(d,p,a,m,o,t.instance),m(),n.appendChild(u)}}function X(e,t,n){var o;const s=[],{scopeRoot:l,skipValidation:r,path:a}=n,i=e.type==="files"||"multiple"in e&&!!e.multiple,c=(u,d,h)=>{var p,m;if(r)return;const v="minCount"in h&&(p=h.minCount)!=null?p:0,b="maxCount"in h&&(m=h.maxCount)!=null?m:1/0;h.required&&d.length===0&&s.push(`${u}: required`),d.length<v&&s.push(`${u}: minimum ${v} files required`),d.length>b&&s.push(`${u}: maximum ${b} files allowed`)};if(i){const u=L(a,t),d=l.querySelector(`input[type="file"][name="${u}"]`),h=d==null?void 0:d.closest(".space-y-2"),p=(h==null?void 0:h.querySelector(".files-list"))||null,m=[];return p&&p.querySelectorAll(".resource-pill").forEach(v=>{const b=v.dataset.resourceId;b&&m.push(b)}),c(t,m,e),{value:m,errors:s}}else{const u=l.querySelector(`input[name$="${t}"][type="hidden"]`),d=(o=u==null?void 0:u.value)!=null?o:"";return!r&&e.required&&d===""?(s.push(`${t}: required`),{value:null,errors:s}):{value:d||null,errors:s}}}function Z(e,t,n,o){var s;const{scopeRoot:l,state:r}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(a=>{var i;if(a&&typeof a=="string"&&!r.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}`)),r.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=l.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(!r.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}`)),r.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 Be(e){R=e}function q(e,t){if(!R)throw new Error("renderElement not initialized. Import from components/index.ts");return R(e,t)}function K(e,t,n,o){var s;const l=document.createElement("div");l.className="border border-gray-200 rounded-lg p-4 bg-gray-50",l.setAttribute("data-container",o);const r=document.createElement("div");r.className="flex justify-between items-center mb-4";const a=document.createElement("div");a.className="flex-1";const i=document.createElement("div");i.className="space-y-4",l.appendChild(r),r.appendChild(a);const c={path:L(t.path,e.key),prefill:((s=t.prefill)==null?void 0:s[e.key])||{},state:t.state};e.elements.forEach(u=>{u.hidden||i.appendChild(q(u,c))}),l.appendChild(i),a.innerHTML=`<span>${e.label||e.key}</span>`,n.appendChild(l)}function Q(e,t,n,o){var s,l,r;const a=t.state,i=document.createElement("div");i.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const c=document.createElement("div");c.className="flex justify-between items-center mb-4";const u=document.createElement("div");u.className="flex-1";const d=document.createElement("div");d.className="flex gap-2";const h=document.createElement("div");h.className="space-y-4",i.appendChild(c),c.appendChild(u),a.config.readonly||c.appendChild(d);const p=(s=e.minCount)!=null?s:0,m=(l=e.maxCount)!=null?l:1/0,v=Array.isArray((r=t.prefill)==null?void 0:r[e.key])?t.prefill[e.key]:null,b=()=>h.querySelectorAll(":scope > .containerItem").length,x=()=>{const y=document.createElement("button");return y.type="button",y.className="px-3 py-1.5 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 transition-colors",y.textContent=$("addElement",a),y.onclick=()=>{if(b()<m){const f=b(),C={state:t.state,path:L(t.path,`${e.key}[${f}]`),prefill:{}},E=document.createElement("div");if(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(q(w,C))}),!a.config.readonly){const w=document.createElement("button");w.type="button",w.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",w.textContent="\xD7",w.onclick=()=>{E.remove(),g()},E.style.position="relative",E.appendChild(w)}h.appendChild(E),g()}},y},g=()=>{const y=b(),f=d.querySelector("button");f&&(f.disabled=y>=m,f.style.opacity=y>=m?"0.5":"1"),u.innerHTML=`<span>${e.label||e.key}</span> <span class="text-sm text-gray-500">(${y}/${m===1/0?"\u221E":m})</span>`};if(a.config.readonly||d.appendChild(x()),v&&Array.isArray(v)&&v.forEach((y,f)=>{const C={state:t.state,path:L(t.path,`${e.key}[${f}]`),prefill:y||{}},E=document.createElement("div");if(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(q(w,C))}),!a.config.readonly){const w=document.createElement("button");w.type="button",w.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",w.textContent="\xD7",w.onclick=()=>{E.remove(),g()},E.style.position="relative",E.appendChild(w)}h.appendChild(E)}),!a.config.readonly)for(;b()<p;){const y=b(),f={state:t.state,path:L(t.path,`${e.key}[${y}]`),prefill:{}},C=document.createElement("div");C.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",C.setAttribute("data-container-item",`${e.key}[${y}]`),e.elements.forEach(w=>{w.hidden||C.appendChild(q(w,f))});const E=document.createElement("button");E.type="button",E.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",E.textContent="\xD7",E.onclick=()=>{b()>p&&(C.remove(),g())},C.style.position="relative",C.appendChild(E),h.appendChild(C)}i.appendChild(h),g(),n.appendChild(i)}let D=null;function je(e){D=e}function ee(e,t,n){if(!D)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return D(e,t,n)}function te(e,t,n){const o=[],{scopeRoot:s,skipValidation:l,path:r}=n;if(!("elements"in e))return{value:null,errors:o};const a=(i,c,u)=>{var d,h;if(l)return;const p="minCount"in u&&(d=u.minCount)!=null?d:0,m="maxCount"in u&&(h=u.maxCount)!=null?h:1/0;u.required&&c.length===0&&o.push(`${i}: required`),c.length<p&&o.push(`${i}: minimum ${p} items required`),c.length>m&&o.push(`${i}: maximum ${m} 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={},p=s.querySelector(`[data-container-item="${t}[${d}]"]`)||s;e.elements.forEach(m=>{if(m.hidden||m.type==="hidden")h[m.key]=m.default!==void 0?m.default:null;else{const v=`${t}[${d}].${m.key}`;h[m.key]=ee({...m,key:v},{path:r},p)}}),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]=ee({...u,key:d},{path:r},c)}}),{value:i,errors:o}}}function ne(e,t,n,o){const{instance:s,scopeRoot:l}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((a,i)=>{A(a)&&e.elements.forEach(c=>{const u=c.key,d=`${t}[${i}].${u}`,h=a[u];h!==void 0&&s.updateField(d,h)})});const r=l.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==r.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!A(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(r=>{const a=r.key,i=`${t}.${a}`,c=n[a];c!==void 0&&s.updateField(i,c)})}}function ze(e,t,n,o){var s,l;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const r={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&A(e.repeat)),minCount:(s=e.repeat)==null?void 0:s.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?Q(r,t,n):K(r,t,n,o)}function le(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&&A(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function Re(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=le(e);return te(o,t,n)}function De(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=le(e);return ne(s,t,n,o)}function Ie(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(),l=window.innerWidth,r=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const a=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let i=s.left,c=s.bottom+5;i+a.width>l&&(i=s.right-a.width),c+a.height>r&&(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 re(e,t){const n=document.createElement("div");n.className="mb-6 fb-field-wrapper";const o=document.createElement("div");o.className="flex items-center mb-2";const s=document.createElement("label");if(s.className="text-sm font-medium text-gray-900",s.textContent=e.label||e.key,e.required){const r=document.createElement("span");r.className="text-red-500 ml-1",r.textContent="*",s.appendChild(r)}if(o.appendChild(s),e.description||e.hint){const r=document.createElement("button");r.type="button",r.className="ml-2 text-gray-400 hover:text-gray-600",r.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 a=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,i=document.createElement("div");i.id=a,i.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",i.style.position="fixed",i.textContent=e.description||e.hint||"Field information",document.body.appendChild(i),r.onclick=c=>{c.preventDefault(),c.stopPropagation(),Ie(a,r)},o.appendChild(r)}n.appendChild(o);const l=L(t.path,e.key);switch(e.type){case"text":"multiple"in e&&e.multiple?fe(e,t,n,l):pe(e,t,n,l);break;case"textarea":"multiple"in e&&e.multiple?ve(e,t,n,l):he(e,t,n,l);break;case"number":"multiple"in e&&e.multiple?xe(e,t,n,l):be(e,t,n,l);break;case"select":"multiple"in e&&e.multiple?$e(e,t,n,l):we(e,t,n,l);break;case"file":"multiple"in e&&e.multiple?Me(e,t,n,l):qe(e,t,n,l);break;case"files":He(e,t,n,l);break;case"group":ze(e,t,n,l);break;case"container":"multiple"in e&&e.multiple?Q(e,t,n):K(e,t,n,l);break;default:{const r=document.createElement("div");r.className="text-red-500 text-sm",r.textContent=`Unsupported field type: ${e.type}`,n.appendChild(r)}}return n}Be(re);const Ue={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 Oe(e){return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Ue,...e},debounceTimer:null}}function Pe(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const N={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 Ve(e){const t={...N,...e},n=[];return Object.entries(t).forEach(([o,s])=>{const l=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${l}: ${s};`)}),n.join(`
|
|
168
|
+
`)}function _e(e,t){const n=Ve(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
|
+
[data-fb-root="true"] {
|
|
170
|
+
${n}
|
|
171
|
+
}
|
|
172
|
+
`}const We={default:N,dark:{...N,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:{...N,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 oe(e,t=!1){e.style.cssText=`
|
|
173
|
+
background-color: var(--fb-action-bg-color);
|
|
174
|
+
color: var(--fb-action-text-color);
|
|
175
|
+
border: var(--fb-border-width) solid var(--fb-action-border-color);
|
|
176
|
+
padding: ${t?"0.5rem 1rem":"0.5rem 0.75rem"};
|
|
177
|
+
font-size: var(--fb-font-size);
|
|
178
|
+
font-weight: var(--fb-font-weight-medium);
|
|
179
|
+
border-radius: var(--fb-border-radius);
|
|
180
|
+
transition: all var(--fb-transition-duration);
|
|
181
|
+
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 Ge={text:{validate:I,update:U},textarea:{validate:ge,update:ye},number:{validate:Ce,update:Ee},select:{validate:ke,update:Fe},file:{validate:X,update:Z},files:{validate:X,update:Z},container:{validate:te,update:ne},group:{validate:Re,update:De}};function ae(e){return Ge[e]||null}function Ye(e,t,n){const o=ae(e.type);return o&&o.validate?o.validate(e,t,n):null}function Je(e,t,n,o){const s=ae(e.type);return s&&s.update?(s.update(e,t,n,o),!0):!1}class H{constructor(t){this.instanceId=Pe(),this.state=Oe(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.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 s=this.state.formRoot.querySelector(`[name="${t}"]`);if(s)return s;const l=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const r of l)if(s=this.state.formRoot.querySelector(`[name="${r}"]`),s)return s}const n=this.findSchemaElement(t);if(!n)return null;const o=this.state.formRoot.querySelectorAll(".fb-field-wrapper");for(const s of o){const l=n.label||n.key,r=s.querySelector("label");if(r&&(r.textContent===l||r.textContent===`${l}*`)){let a=s.querySelector(".field-placeholder");return a||(a=document.createElement("div"),a.className="field-placeholder",a.style.display="none",s.appendChild(a)),a}}return null}findSchemaElement(t){if(!this.state.schema||!this.state.schema.elements)return null;let n=this.state.schema.elements,o=null;const s=t.replace(/\[\d+\]/g,"").split(".").filter(Boolean);for(const l of s){if(o=n.find(r=>r.key===l)||null,!o)return null;"elements"in o&&o.elements&&(n=o.elements)}return o}resolveActionLabel(t,n,o,s=!1){if(o&&"actions"in o&&o.actions){const l=o.actions.find(r=>r.key===t);if(l&&l.label)return l.label}if(s&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const l=this.state.schema.actions.find(r=>r.key===t);if(l&&l.label)return l.label}return n||t}renderFormLevelActions(t,n=[]){if(!this.state.formRoot)return;const o=this.state.formRoot.querySelector(".form-level-actions-container");o&&o.remove();const s=document.createElement("div");s.className="form-level-actions-container mt-6 pt-4 flex flex-wrap gap-3 justify-center",s.style.cssText=`
|
|
183
|
+
border-top: var(--fb-border-width) solid var(--fb-border-color);
|
|
184
|
+
`,t.forEach(l=>{const r=document.createElement("button");r.type="button",oe(r,!0);const a=n.includes(l),i=this.resolveActionLabel(l.key,l.label,null,a);r.textContent=i,r.addEventListener("click",c=>{c.preventDefault(),c.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(l.value,l.key,null)}),s.appendChild(r)}),this.state.formRoot.appendChild(s)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],o=[];this.state.externalActions.forEach(l=>{!l.key||!l.value||(l.related_field?(t.has(l.related_field)||t.set(l.related_field,[]),t.get(l.related_field).push(l)):n.push(l))}),t.forEach((l,r)=>{const a=this.findFormElementByFieldPath(r);if(!a){console.warn(`External action: Could not find form element for field "${r}", treating as form-level actions`),o.push(...l);return}let i=a.closest(".fb-field-wrapper");if(i||(i=a.parentElement),!i){console.warn(`External action: Could not find wrapper for field "${r}"`);return}const c=i.querySelector(".external-actions-container");c&&c.remove();const u=document.createElement("div");u.className="external-actions-container mt-3 flex flex-wrap gap-2";const d=this.findSchemaElement(r);l.forEach(h=>{const p=document.createElement("button");p.type="button",oe(p,!1);const m=this.resolveActionLabel(h.key,h.label,d);p.textContent=m,p.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(p)}),i.appendChild(u)});const s=[...n,...o];s.length>0&&this.renderFormLevelActions(s,n)}renderForm(t,n,o,s){const l=M(n);if(l.length>0){console.error("Schema validation errors:",l);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=s||null,T(t),t.setAttribute("data-fb-root","true"),_e(t,this.state.config.theme);const r=document.createElement("div");r.className="space-y-6",n.elements.forEach(a=>{if(a.hidden)return;const i=re(a,{path:"",prefill:o||{},state:this.state,instance:this});r.appendChild(i)}),t.appendChild(r),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={},s=(l,r,a=null)=>{const i=l.key,c={scopeRoot:a||this.state.formRoot,state:this.state,instance:this,path:r.path,skipValidation:t},u=Ye(l,i,c);return u!==null?(n.push(...u.errors),u.value):(console.warn(`Unknown field type "${l.type}" for key "${i}"`),null)};return je(s),this.state.schema.elements.forEach(l=>{l.hidden?o[l.key]=l.default!==void 0?l.default:null:o[l.key]=s(l,{path:""})}),{valid:n.length===0,errors:n,data:o}}getFormData(){return this.validateForm(!1)}submitForm(){const t=this.validateForm(!1);return t.valid&&typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formSubmit",data:t.data,schema:this.state.schema},"*"),t}saveDraft(){const t=this.validateForm(!0);return typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formDraft",data:t.data,schema:this.state.schema},"*"),t}clearForm(){if(!this.state.schema||!this.state.formRoot){console.warn("clearForm: Form not initialized. Call renderForm() first.");return}const t=this.state.schema,n=this.state.formRoot,o=this.state.externalActions,s=this.buildHiddenFieldsData(t.elements);this.renderForm(n,t,s,o||void 0)}buildHiddenFieldsData(t){const n={};for(const o of t){const s=o.key;if(o.hidden&&o.default!==void 0&&(n[s]=o.default),o.type==="container"||o.type==="group"){const l=o,r=this.buildHiddenFieldsData(l.elements);Object.keys(r).length>0&&(s in n?typeof n[s]=="object"&&n[s]!==null&&!Array.isArray(n[s])&&(n[s]={...n[s],...r}):n[s]=r)}}return n}setFormData(t){if(!this.state.schema||!this.state.formRoot){console.warn("setFormData: Form not initialized. Call renderForm() first.");return}for(const n in t)this.updateField(n,t[n])}updateField(t,n){if(!this.state.schema||!this.state.formRoot){console.warn("updateField: Form not initialized. Call renderForm() first.");return}const o=this.findSchemaElement(t);if(!o){console.warn(`updateField: Schema element not found for path "${t}"`);return}const s=this.findFormElementByFieldPath(t);if(!s){console.warn(`updateField: DOM element not found for path "${t}"`);return}this.updateFieldValue(s,o,t,n),(this.state.config.onChange||this.state.config.onFieldChange)&&this.triggerOnChange(t,n)}updateFieldValue(t,n,o,s){const l={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};Je(n,o,s,l)||console.warn(`updateField: No updater found for field type "${n.type}" at path "${o}"`)}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 ie(e){return new H(e)}return typeof window!="undefined"&&(window.FormBuilder=H,window.createFormBuilder=ie,window.validateSchema=M),F.FormBuilderInstance=H,F.createFormBuilder=ie,F.default=H,F.defaultTheme=N,F.exampleThemes=We,F.validateSchema=M,Object.defineProperty(F,"__esModule",{value:!0}),F})({});
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2099,6 +2099,7 @@ function validateFileElement(element, key, context) {
|
|
|
2099
2099
|
var _a;
|
|
2100
2100
|
const errors = [];
|
|
2101
2101
|
const { scopeRoot, skipValidation, path } = context;
|
|
2102
|
+
const isMultipleField = element.type === "files" || "multiple" in element && Boolean(element.multiple);
|
|
2102
2103
|
const validateFileCount = (key2, resourceIds, element2) => {
|
|
2103
2104
|
var _a2, _b;
|
|
2104
2105
|
if (skipValidation) return;
|
|
@@ -2114,7 +2115,7 @@ function validateFileElement(element, key, context) {
|
|
|
2114
2115
|
errors.push(`${key2}: maximum ${maxFiles} files allowed`);
|
|
2115
2116
|
}
|
|
2116
2117
|
};
|
|
2117
|
-
if (
|
|
2118
|
+
if (isMultipleField) {
|
|
2118
2119
|
const fullKey = pathJoin(path, key);
|
|
2119
2120
|
const pickerInput = scopeRoot.querySelector(
|
|
2120
2121
|
`input[type="file"][name="${fullKey}"]`
|
|
@@ -2761,6 +2762,7 @@ var defaultConfig = {
|
|
|
2761
2762
|
onUploadError: null,
|
|
2762
2763
|
onDownloadError: null,
|
|
2763
2764
|
debounceMs: 300,
|
|
2765
|
+
verboseErrors: false,
|
|
2764
2766
|
enableFilePreview: true,
|
|
2765
2767
|
maxPreviewSize: "200px",
|
|
2766
2768
|
readonly: false,
|
|
@@ -3060,15 +3062,7 @@ var FormBuilderInstance = class {
|
|
|
3060
3062
|
constructor(config) {
|
|
3061
3063
|
this.instanceId = generateInstanceId();
|
|
3062
3064
|
this.state = createInstanceState(config);
|
|
3063
|
-
if (
|
|
3064
|
-
if (config == null ? void 0 : config.getThumbnail) {
|
|
3065
|
-
const testResult = config.getThumbnail("test-id");
|
|
3066
|
-
if (!(testResult instanceof Promise)) {
|
|
3067
|
-
console.warn(
|
|
3068
|
-
"[form-builder] getThumbnail must be async (return Promise). Wrap your function: async (id) => { ... }"
|
|
3069
|
-
);
|
|
3070
|
-
}
|
|
3071
|
-
}
|
|
3065
|
+
if (this.state.config.verboseErrors) {
|
|
3072
3066
|
if (!globalThis.__formBuilderInstances) {
|
|
3073
3067
|
globalThis.__formBuilderInstances = /* @__PURE__ */ new Set();
|
|
3074
3068
|
}
|
|
@@ -3522,28 +3516,32 @@ var FormBuilderInstance = class {
|
|
|
3522
3516
|
}
|
|
3523
3517
|
const schema = this.state.schema;
|
|
3524
3518
|
const formRoot = this.state.formRoot;
|
|
3519
|
+
const actions = this.state.externalActions;
|
|
3525
3520
|
const emptyPrefill = this.buildHiddenFieldsData(schema.elements);
|
|
3526
|
-
this.renderForm(formRoot, schema, emptyPrefill);
|
|
3521
|
+
this.renderForm(formRoot, schema, emptyPrefill, actions || void 0);
|
|
3527
3522
|
}
|
|
3528
3523
|
/**
|
|
3529
3524
|
* Build prefill data for hidden fields only
|
|
3530
3525
|
* Hidden fields should retain their values when clearing
|
|
3526
|
+
* Builds nested objects instead of flattened dotted keys
|
|
3531
3527
|
*/
|
|
3532
|
-
buildHiddenFieldsData(elements
|
|
3528
|
+
buildHiddenFieldsData(elements) {
|
|
3533
3529
|
const data = {};
|
|
3534
3530
|
for (const element of elements) {
|
|
3535
3531
|
const key = element.key;
|
|
3536
|
-
const fieldPath = parentPath ? `${parentPath}.${key}` : key;
|
|
3537
3532
|
if (element.hidden && element.default !== void 0) {
|
|
3538
|
-
data[
|
|
3533
|
+
data[key] = element.default;
|
|
3539
3534
|
}
|
|
3540
3535
|
if (element.type === "container" || element.type === "group") {
|
|
3541
3536
|
const containerElement = element;
|
|
3542
|
-
const nestedData = this.buildHiddenFieldsData(
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3537
|
+
const nestedData = this.buildHiddenFieldsData(containerElement.elements);
|
|
3538
|
+
if (Object.keys(nestedData).length > 0) {
|
|
3539
|
+
if (!(key in data)) {
|
|
3540
|
+
data[key] = nestedData;
|
|
3541
|
+
} else if (typeof data[key] === "object" && data[key] !== null && !Array.isArray(data[key])) {
|
|
3542
|
+
data[key] = { ...data[key], ...nestedData };
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3547
3545
|
}
|
|
3548
3546
|
}
|
|
3549
3547
|
return data;
|
|
@@ -3625,7 +3623,7 @@ var FormBuilderInstance = class {
|
|
|
3625
3623
|
this.state.formRoot = null;
|
|
3626
3624
|
this.state.schema = null;
|
|
3627
3625
|
this.state.externalActions = null;
|
|
3628
|
-
if (
|
|
3626
|
+
if (this.state.config.verboseErrors) {
|
|
3629
3627
|
(_a = globalThis.__formBuilderInstances) == null ? void 0 : _a.delete(this.instanceId);
|
|
3630
3628
|
}
|
|
3631
3629
|
}
|