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