ynotsoft-dynamic-form 1.0.98 → 1.0.99
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/dynamic-form.js
CHANGED
|
@@ -363,11 +363,12 @@ function dl({
|
|
|
363
363
|
} else
|
|
364
364
|
S(-1);
|
|
365
365
|
}, [p, y, E]), He(() => {
|
|
366
|
+
if (!p) return;
|
|
366
367
|
const C = (L) => {
|
|
367
368
|
O.current && !O.current.contains(L.target) && (v(!1), r(e.name));
|
|
368
369
|
};
|
|
369
370
|
return document.addEventListener("mousedown", C), () => document.removeEventListener("mousedown", C);
|
|
370
|
-
}, [e.name, r]);
|
|
371
|
+
}, [p, e.name, r]);
|
|
371
372
|
const _ = (C, L) => {
|
|
372
373
|
C.stopPropagation();
|
|
373
374
|
const U = Array.isArray(H) ? H : [], G = l ? [] : U.filter((ce) => (ce?.value ?? ce) !== L);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
`,valueContainer:()=>"py-0.5 px-2",placeholder:()=>"text-gray-400",dropdownIndicator:()=>"!text-gray-400 hover:!text-gray-600",multiValue:()=>"!bg-blue-100 !text-blue-800 !rounded-md",multiValueLabel:()=>"!text-blue-800 !pr-1",multiValueRemove:()=>"!text-blue-500 hover:!bg-blue-200 hover:!text-blue-700 !rounded-r-md",menu:()=>"!shadow-lg !rounded-lg !mt-2 !z-50",option:h=>`!py-2 !px-3 !text-sm !cursor-pointer
|
|
7
7
|
${h.isSelected?"!bg-blue-500 !text-white":""}
|
|
8
8
|
${h.isFocused&&!h.isSelected?"!bg-gray-100 !text-gray-800":""}
|
|
9
|
-
`}})})}const Zi=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ji=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase()),lo=e=>{const t=Ji(e);return t.charAt(0).toUpperCase()+t.slice(1)},uo=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim(),ec=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var tc={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const nc=R.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:a,iconNode:s,...c},l)=>R.createElement("svg",{ref:l,...tc,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:uo("lucide",o),...!a&&!ec(c)&&{"aria-hidden":"true"},...c},[...s.map(([d,u])=>R.createElement(d,u)),...Array.isArray(a)?a:[a]]));const ae=(e,t)=>{const n=R.forwardRef(({className:r,...o},a)=>R.createElement(nc,{ref:a,iconNode:t,className:uo(`lucide-${Zi(lo(e))}`,`lucide-${e}`,r),...o}));return n.displayName=lo(e),n};const rc=ae("bold",[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]]);const fo=ae("calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);const oc=ae("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const en=ae("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const ac=ae("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);const sc=ae("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ic=ae("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);const cc=ae("circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const lc=ae("cloud-upload",[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]]);const dc=ae("code",[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]]);const uc=ae("heading-1",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"m17 12 3-2v8",key:"1hhhft"}]]);const fc=ae("heading-2",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1",key:"9jr5yi"}]]);const pc=ae("heading-3",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2",key:"68ncm8"}],["path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2",key:"1ejuhz"}]]);const mc=ae("info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]);const hc=ae("italic",[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]]);const gc=ae("list-ordered",[["path",{d:"M11 5h10",key:"1cz7ny"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 19h10",key:"11t30w"}],["path",{d:"M4 4h1v5",key:"10yrso"}],["path",{d:"M4 9h2",key:"r1h2o0"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02",key:"xtkcd5"}]]);const bc=ae("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]);const po=ae("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);const vc=ae("message-square-quote",[["path",{d:"M14 14a2 2 0 0 0 2-2V8h-2",key:"1r06pg"}],["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M8 14a2 2 0 0 0 2-2V8H8",key:"1jzu5j"}]]);const yc=ae("redo",[["path",{d:"M21 7v6h-6",key:"3ptur4"}],["path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7",key:"1kgawr"}]]);const wc=ae("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]);const xc=ae("strikethrough",[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]]);const Sc=ae("underline",[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]]);const Cc=ae("undo",[["path",{d:"M3 7v6h6",key:"1v2h90"}],["path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13",key:"1r6uu6"}]]);const Xn=ae("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function Ec({field:e,formValues:t,handleChange:n,handleBlur:r,error:o,disabled:a,apiClient:s,...c}){const l=a,d=e.selectMode!=="multiple",u=e.returnValueOnly===!0,[p,g]=R.useState([]),[h,w]=R.useState(!1),[m,v]=R.useState(!1),[E,k]=R.useState(""),[x,S]=R.useState(-1),[N,I]=R.useState({}),O=R.useRef(null),T=R.useRef(null),z=R.useRef(null),H=t[e.name],q=R.useCallback(()=>H?(Array.isArray(H)?H:[H]).map(L=>{if(L&&typeof L=="object"&&L.value!==void 0)return{value:L.value,label:L.label||L.value};const U=p.find(G=>G.value===L);return U||(N[L]?N[L]:{value:L,label:L})}):[],[H,p,N])(),y=R.useCallback(async(C="")=>{if(e.onSearch){const L=await e.onSearch(C,t);g(L);return}if(!e.optionsUrl||!s){const L=(e.options||[]).map(U=>({value:U[e.valueId||"value"]||U.value||U.id,label:U[e.labelId||"label"]||U.label||U.name}));g(C?L.filter(U=>String(U.label).toLowerCase().includes(C.toLowerCase())):L);return}w(!0);try{const L=e.searchParam||"search",U=e.optionsUrl.includes("?")?"&":"?",G=`${e.optionsUrl}${U}${L}=${encodeURIComponent(C)}`,ce=await s(G),Y=ce.data||ce,oe=Array.isArray(Y)?Y:[];g(oe.map(K=>({value:K[e.valueId||"value"]||K.value||K.id,label:K[e.labelId||"label"]||K.label||K.name})))}catch{g([])}finally{w(!1)}},[e,s,t]),A=R.useCallback(C=>{if(!C)return;I(G=>({...G,[C.value]:C}));const L=u?C.value:{value:C.value,label:C.label};let U;if(d)U=[L],v(!1);else{const G=Array.isArray(H)?H:[];U=G.some(Y=>(Y?.value??Y)===C.value)?G.filter(Y=>(Y?.value??Y)!==C.value):[...G,L]}n(e.name,U),r(e.name),e.clearSearchOnSelect&&k("")},[H,e.clearSearchOnSelect,e.name,n,r,d,u]),_=C=>{if(!l)switch(C.key){case"ArrowDown":C.preventDefault(),m?S(L=>L<p.length-1?L+1:L):v(!0);break;case"ArrowUp":C.preventDefault(),m&&S(L=>L>0?L-1:0);break;case"Enter":C.preventDefault(),m&&x>=0&&p[x]?A(p[x]):m||v(!0);break;case"Escape":v(!1);break;case"Tab":v(!1),r(e.name);break}},P=C=>{const L=C.target.value;k(L),S(-1),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>y(L),300)};R.useEffect(()=>{if(m){y(E);const C=setTimeout(()=>T.current?.focus(),50);return()=>clearTimeout(C)}else S(-1)},[m,y,E]),R.useEffect(()=>{const C=L=>{O.current&&!O.current.contains(L.target)&&(v(!1),r(e.name))};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[e.name,r]);const M=(C,L)=>{C.stopPropagation();const U=Array.isArray(H)?H:[],G=d?[]:U.filter(ce=>(ce?.value??ce)!==L);n(e.name,G),r(e.name)};return i.jsxs("div",{className:`mb-4 relative ${e.fieldClass||"col-span-full"}`,ref:O,children:[i.jsxs("div",{role:"combobox","aria-expanded":m,"aria-haspopup":"listbox","aria-controls":`${e.name}-listbox`,tabIndex:l?-1:0,onClick:()=>!l&&v(!m),onKeyDown:_,className:`
|
|
9
|
+
`}})})}const Zi=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ji=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase()),lo=e=>{const t=Ji(e);return t.charAt(0).toUpperCase()+t.slice(1)},uo=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim(),ec=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var tc={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const nc=R.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:a,iconNode:s,...c},l)=>R.createElement("svg",{ref:l,...tc,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:uo("lucide",o),...!a&&!ec(c)&&{"aria-hidden":"true"},...c},[...s.map(([d,u])=>R.createElement(d,u)),...Array.isArray(a)?a:[a]]));const ae=(e,t)=>{const n=R.forwardRef(({className:r,...o},a)=>R.createElement(nc,{ref:a,iconNode:t,className:uo(`lucide-${Zi(lo(e))}`,`lucide-${e}`,r),...o}));return n.displayName=lo(e),n};const rc=ae("bold",[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]]);const fo=ae("calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);const oc=ae("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const en=ae("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const ac=ae("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);const sc=ae("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ic=ae("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);const cc=ae("circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const lc=ae("cloud-upload",[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]]);const dc=ae("code",[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]]);const uc=ae("heading-1",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"m17 12 3-2v8",key:"1hhhft"}]]);const fc=ae("heading-2",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1",key:"9jr5yi"}]]);const pc=ae("heading-3",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2",key:"68ncm8"}],["path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2",key:"1ejuhz"}]]);const mc=ae("info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]);const hc=ae("italic",[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]]);const gc=ae("list-ordered",[["path",{d:"M11 5h10",key:"1cz7ny"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 19h10",key:"11t30w"}],["path",{d:"M4 4h1v5",key:"10yrso"}],["path",{d:"M4 9h2",key:"r1h2o0"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02",key:"xtkcd5"}]]);const bc=ae("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]);const po=ae("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);const vc=ae("message-square-quote",[["path",{d:"M14 14a2 2 0 0 0 2-2V8h-2",key:"1r06pg"}],["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M8 14a2 2 0 0 0 2-2V8H8",key:"1jzu5j"}]]);const yc=ae("redo",[["path",{d:"M21 7v6h-6",key:"3ptur4"}],["path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7",key:"1kgawr"}]]);const wc=ae("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]);const xc=ae("strikethrough",[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]]);const Sc=ae("underline",[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]]);const Cc=ae("undo",[["path",{d:"M3 7v6h6",key:"1v2h90"}],["path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13",key:"1r6uu6"}]]);const Xn=ae("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function Ec({field:e,formValues:t,handleChange:n,handleBlur:r,error:o,disabled:a,apiClient:s,...c}){const l=a,d=e.selectMode!=="multiple",u=e.returnValueOnly===!0,[p,g]=R.useState([]),[h,w]=R.useState(!1),[m,v]=R.useState(!1),[E,k]=R.useState(""),[x,S]=R.useState(-1),[N,I]=R.useState({}),O=R.useRef(null),T=R.useRef(null),z=R.useRef(null),H=t[e.name],q=R.useCallback(()=>H?(Array.isArray(H)?H:[H]).map(L=>{if(L&&typeof L=="object"&&L.value!==void 0)return{value:L.value,label:L.label||L.value};const U=p.find(G=>G.value===L);return U||(N[L]?N[L]:{value:L,label:L})}):[],[H,p,N])(),y=R.useCallback(async(C="")=>{if(e.onSearch){const L=await e.onSearch(C,t);g(L);return}if(!e.optionsUrl||!s){const L=(e.options||[]).map(U=>({value:U[e.valueId||"value"]||U.value||U.id,label:U[e.labelId||"label"]||U.label||U.name}));g(C?L.filter(U=>String(U.label).toLowerCase().includes(C.toLowerCase())):L);return}w(!0);try{const L=e.searchParam||"search",U=e.optionsUrl.includes("?")?"&":"?",G=`${e.optionsUrl}${U}${L}=${encodeURIComponent(C)}`,ce=await s(G),Y=ce.data||ce,oe=Array.isArray(Y)?Y:[];g(oe.map(K=>({value:K[e.valueId||"value"]||K.value||K.id,label:K[e.labelId||"label"]||K.label||K.name})))}catch{g([])}finally{w(!1)}},[e,s,t]),A=R.useCallback(C=>{if(!C)return;I(G=>({...G,[C.value]:C}));const L=u?C.value:{value:C.value,label:C.label};let U;if(d)U=[L],v(!1);else{const G=Array.isArray(H)?H:[];U=G.some(Y=>(Y?.value??Y)===C.value)?G.filter(Y=>(Y?.value??Y)!==C.value):[...G,L]}n(e.name,U),r(e.name),e.clearSearchOnSelect&&k("")},[H,e.clearSearchOnSelect,e.name,n,r,d,u]),_=C=>{if(!l)switch(C.key){case"ArrowDown":C.preventDefault(),m?S(L=>L<p.length-1?L+1:L):v(!0);break;case"ArrowUp":C.preventDefault(),m&&S(L=>L>0?L-1:0);break;case"Enter":C.preventDefault(),m&&x>=0&&p[x]?A(p[x]):m||v(!0);break;case"Escape":v(!1);break;case"Tab":v(!1),r(e.name);break}},P=C=>{const L=C.target.value;k(L),S(-1),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>y(L),300)};R.useEffect(()=>{if(m){y(E);const C=setTimeout(()=>T.current?.focus(),50);return()=>clearTimeout(C)}else S(-1)},[m,y,E]),R.useEffect(()=>{if(!m)return;const C=L=>{O.current&&!O.current.contains(L.target)&&(v(!1),r(e.name))};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[m,e.name,r]);const M=(C,L)=>{C.stopPropagation();const U=Array.isArray(H)?H:[],G=d?[]:U.filter(ce=>(ce?.value??ce)!==L);n(e.name,G),r(e.name)};return i.jsxs("div",{className:`mb-4 relative ${e.fieldClass||"col-span-full"}`,ref:O,children:[i.jsxs("div",{role:"combobox","aria-expanded":m,"aria-haspopup":"listbox","aria-controls":`${e.name}-listbox`,tabIndex:l?-1:0,onClick:()=>!l&&v(!m),onKeyDown:_,className:`
|
|
10
10
|
w-full min-h-10 px-2 py-1 border rounded-lg bg-background cursor-pointer
|
|
11
11
|
flex items-center flex-wrap gap-2 transition-all outline-none
|
|
12
12
|
${o?"border-destructive ring-1 ring-destructive":"border-input hover:border-accent-foreground/20"}
|