cosmic-ai-input 1.0.19 → 1.0.20

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/index.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
- // Generated at: 2026-04-03T07:18:57.453Z
2
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("react/jsx-runtime"),o=require("react"),me=require("classnames"),nt=require("react-dom");var E=(i=>(i.INPUT="input",i.SELECT="select",i.MULTIPLE_SELECT="multiple-select",i.DATE_PICKER="date-picker",i.LABEL="label",i))(E||{});const Te=o.forwardRef(({value:i,position:a,id:r,onChange:h},B)=>{const[A,x]=o.useState(!0),$=o.useRef(null),k=o.useRef(null);o.useEffect(()=>{typeof B=="function"?B($.current):B&&(B.current=$.current)},[B]);const S=g=>{const y=g.target.value;h==null||h(y,E.DATE_PICKER)};o.useEffect(()=>{if(k.current)try{setTimeout(()=>{N()},100)}catch{}},[]);const N=()=>{if(k.current)try{k.current.showPicker()}catch{}},m=g=>{g.stopPropagation()};return A?p.jsx("div",{ref:$,id:r,style:{top:(a==null?void 0:a.top)||0,left:(a==null?void 0:a.left)||0},className:"cosmic-ai-input-datePicker",suppressHydrationWarning:!0,children:p.jsx("input",{ref:k,type:"date",value:i||"",onChange:S,onClick:m})}):null});Te.displayName="DatePicker";function de(i){const a=i.textContent||"",r=i.nextSibling;a.length?(r==null||r.setAttribute("style","display: none"),i.style.padding="2px 4px",i.style.borderTopLeftRadius="2px",i.style.borderBottomLeftRadius="2px",i.style.borderTopRightRadius="2px",i.style.borderBottomRightRadius="2px"):(r==null||r.setAttribute("style","display: inline"),i.style.padding="2px 0 2px 4px",i.style.borderTopLeftRadius="2px",i.style.borderBottomLeftRadius="2px",i.style.borderTopRightRadius="0",i.style.borderBottomRightRadius="0")}function O(i){if(i&&i.getAttribute("data-set-type")==="input"){const a=i.children[0];a.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{a.focus()})}}function Le(i){i&&i.getAttribute("data-set-type")==="input"&&i.children[0].setAttribute("contenteditable","false")}function v(i){return i&&(i!=null&&i.getAttribute)?i.getAttribute("data-set-type")==="input":!1}const De=o.forwardRef(({options:i,value:a,position:r,id:h,height:B=37,onChange:A},x)=>{const[$,k]=o.useState(a||""),S=o.useRef(null);o.useEffect(()=>{typeof x=="function"?x(S.current):x&&(x.current=S.current)},[x]);const N=g=>{const y=$.split(",").filter(b=>b)||[];let w="";y.includes(g)?w=y.filter(b=>b!==g).join(","):y.length?w=`${y.join(",")},${g}`:w=g,k(w),A==null||A(w,E.MULTIPLE_SELECT)},m=$.split(",")||[];return p.jsx("div",{ref:S,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(r==null?void 0:r.top)||0,left:(r==null?void 0:r.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:i.map((g,y)=>p.jsx("div",{className:`selectOption ${m.includes(g)?"selected":""}`,onClick:()=>N(g),children:g},y))})});De.displayName="MultipleSelect";const Ne=o.forwardRef(({options:i,value:a,position:r,id:h,height:B=120,onChange:A},x)=>{const[$,k]=o.useState(a||""),S=o.useRef(null);o.useEffect(()=>{typeof x=="function"?x(S.current):x&&(x.current=S.current)},[x]);const N=m=>{k(m),A==null||A(m,E.SELECT)};return p.jsx("div",{ref:S,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(r==null?void 0:r.top)||0,left:(r==null?void 0:r.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:i.length>0&&i.map((m,g)=>p.jsx("div",{className:`selectOption ${$===m?"selected":""}`,onClick:()=>N(m),children:m},g))})});Ne.displayName="Select";function Re(i){const a=i instanceof Element?i:document.getElementById(i);return a&&a.children[0].textContent||""}function st(i,a){const r=i instanceof Element?i:document.getElementById(i);r&&(r.children[0].textContent=a)}function I(i){const a=document.createRange(),r=window.getSelection();r&&(!i||!(i instanceof Node)||(a.selectNodeContents(i),a.collapse(!0),r.removeAllRanges(),r.addRange(a)))}function K(i){const a=document.createRange(),r=window.getSelection();r&&(!i||!(i instanceof Node)||(a.selectNodeContents(i),a.collapse(!1),r.removeAllRanges(),r.addRange(a)))}function ue(i){const a=window.getSelection();if(!a||a.rangeCount===0)return 0;if(!i||!(i instanceof Node))return;const r=a.getRangeAt(0),h=r.cloneRange();return h.selectNodeContents(i),h.setEnd(r.startContainer,r.startOffset),h.toString().length}function it(){const i=window.getSelection();if(!i||i.rangeCount===0)return null;const r=i.getRangeAt(0).startContainer;return r.nodeType===Node.TEXT_NODE?r.parentElement:r.nodeType===Node.ELEMENT_NODE?r:null}function rt(){const i=window.getSelection();return!i||i.rangeCount===0?null:i.getRangeAt(0).getBoundingClientRect()}function ct(){return new Promise(i=>{requestAnimationFrame(()=>{i(rt())})})}function lt(){const i=window.getSelection();if(!i||i.rangeCount===0)return null;const a=i.getRangeAt(0),r=a.startContainer,h=a.startOffset;return r.nodeType===Node.TEXT_NODE?h>0?r:r.previousSibling:r.nodeType===Node.ELEMENT_NODE?h>0?r.childNodes[h-1]:r.previousSibling:null}function ot(){const i=window.getSelection();if(!i||i.rangeCount===0)return null;const a=i.getRangeAt(0),r=a.startContainer,h=a.startOffset;return r.nodeType===Node.TEXT_NODE?h<r.length?r:r.nextSibling:r.nodeType===Node.ELEMENT_NODE?h<r.childNodes.length?r.childNodes[h]:r.nextSibling:null}function at(i){return i&&!i.getAttribute("data-set-type")}function Se(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}const ke=o.forwardRef(({options:i,value:a,position:r,id:h,height:B=120,onChange:A},x)=>{const[$,k]=o.useState(a||""),[S,N]=o.useState(0),m=o.useRef(null),g=o.useRef(S),y=o.useCallback(w=>{k(w),A==null||A(w,E.LABEL)},[A]);return o.useEffect(()=>{typeof x=="function"?x(m.current):x&&(x.current=m.current)},[x]),o.useEffect(()=>{g.current=S},[S]),o.useEffect(()=>{N(0)},[i]),o.useEffect(()=>{const w=b=>{i.length!==0&&(b.key==="ArrowDown"?(b.preventDefault(),N(L=>L<i.length-1?L+1:L)):b.key==="ArrowUp"?(b.preventDefault(),N(L=>L>0?L-1:L)):b.key==="Enter"&&(b.preventDefault(),setTimeout(()=>{const L=g.current;L>=0&&i[L]&&y(i[L])},0)))};return document.addEventListener("keydown",w),()=>{document.removeEventListener("keydown",w)}},[i,y]),p.jsx("div",{ref:m,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(r==null?void 0:r.top)||0,left:(r==null?void 0:r.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:i.length>0&&i.map((w,b)=>p.jsx("div",{className:`selectOption ${$===w?"selected":""} ${S===b?"highlighted":""}`,onClick:()=>y(w),onMouseEnter:()=>N(b),children:w},b))})});ke.displayName="Mention";const Pe=o.forwardRef((i,a)=>{const{value:r="",varList:h,placeholder:B="",maxLength:A,defaultRows:x=3,disabled:$=!1,defaultFocus:k=!1,textIndex:S=0,mentions:N=[],onFocus:m,onBlur:g,onChange:y,onClick:w,onSend:b,onKeyDown:L,onKeyUp:F,onMaxLengthExceeded:Y}=i,[dt,ut]=o.useState(r||""),[ee,U]=o.useState(""),[ft,te]=o.useState(""),[q,M]=o.useState(!1),[W,V]=o.useState({top:0,left:0}),[ne,se]=o.useState([]),[z,fe]=o.useState(""),[C,ie]=o.useState(null),[re,X]=o.useState(120),[pe,he]=o.useState(k),ge=240,Ee=240,ye=240,xe=276,R=o.useRef(null),T=o.useRef(null),j=o.useRef(null),G=o.useRef(!1),H=()=>{var n,t;let e=((t=(n=R.current)==null?void 0:n.innerText)==null?void 0:t.replace(/\u200B/g,""))||"";return e===`
3
- `&&(e=""),e},ce=()=>{var n;let e=((n=R.current)==null?void 0:n.innerHTML)||"";return e==="<br>"&&(e=""),e},Be=e=>{const n=[];let t=0;const l=/\[([^\]]+)\]/g;let d;const c=Se();let u=0;if(e===""||!e||e===`
4
- `)return[{type:"text",content:"​",id:`text-${u++}-${c}`}];const P=new Set((h||[]).map(D=>D.name));for(;(d=l.exec(e))!==null;){if(d.index>t){const f=e.substring(t,d.index).split(`
5
- `);f.forEach((Z,tt)=>{Z&&n.push({type:"text",content:Z,id:`text-${u++}-${c}`}),tt<f.length-1&&n.push({type:"newline",id:`newline-${u++}-${c}`})})}const D=d[1];if(P.has(D)){const s=h.find(f=>f.name===D);(s==null?void 0:s.type)==="input"?n.push({type:"input",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,id:`input-${u++}-${c}`}):(s==null?void 0:s.type)==="label"?n.push({type:"label",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",id:`label-${u++}-${c}`}):(s==null?void 0:s.type)==="select"?n.push({type:"select",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,options:(s==null?void 0:s.options)||[],id:`select-${u++}-${c}`}):(s==null?void 0:s.type)==="multiple-select"?n.push({type:"multiple-select",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,options:(s==null?void 0:s.options)||[],id:`multiple-select-${u++}-${c}`}):(s==null?void 0:s.type)==="date-picker"&&n.push({type:"date-picker",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,id:`date-picker-${u++}-${c}`})}else n.push({type:"text",content:`[${D}]`,id:`text-${u++}-${c}`});t=l.lastIndex}if(t<e.length){const s=e.substring(t).split(`
6
- `);s.forEach((f,Z)=>{f&&n.push({type:"text",content:f,id:`text-${u++}`}),Z<s.length-1&&n.push({type:"newline",id:`newline-${u++}`})})}return n},le=()=>{var e;(e=R.current)==null||e.setAttribute("contenteditable","true"),T.current&&(v(T.current)&&T.current.children[0].setAttribute("contenteditable","false"),T.current=null),K(R.current)},$e=e=>{w==null||w(e)},je=e=>{le()},_=e=>{var n,t;if(G.current){H().length>0?(n=R.current)==null||n.classList.remove("is-empty"):(t=R.current)==null||t.classList.add("is-empty");return}U(H()),te(ce()),y==null||y(H()),Ze(e)},Me=e=>{var n;if(!G.current&&e.code==="Enter"&&!e.shiftKey){e.preventDefault();const t=H();if(t.length===0||(n=R.current)!=null&&n.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/))return;A?t.length<=A?b==null||b(t):Y==null||Y(t,A):b==null||b(t)}},He=e=>{var t,l,d;if(q&&(C==null?void 0:C.type)===E.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}M(!1),L==null||L(e);const n=it();if(n&&at(n)){if(e.code==="ArrowLeft"){const c=n==null?void 0:n.previousElementSibling,u=ue(n);c&&u===0&&v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{K(c.children[0])}))}if(e.code==="ArrowRight"){const c=n==null?void 0:n.nextElementSibling,u=ue(n);c&&u===((t=n.textContent)==null?void 0:t.length)&&v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{I(c.children[0])}))}(e.code==="Backspace"||((l=e==null?void 0:e.nativeEvent)==null?void 0:l.key)==="Backspace")&&(n.innerHTML==="​"&&e.preventDefault(),n.innerHTML==="<br>"&&(e.preventDefault(),n.innerHTML="​"))}if((e.code==="Backspace"||((d=e==null?void 0:e.nativeEvent)==null?void 0:d.key)==="Backspace")&&e.target){const c=e.target;if(c.childElementCount===1&&c.children[0].tagName==="SPAN"){const u=c.children[0];c.childNodes.length===1&&(u.innerHTML==="​"&&e.preventDefault(),u.innerHTML==="<br>"&&(e.preventDefault(),u.innerHTML="​"))}}if(n&&n.getAttribute("data-set-type")==="container"){if(e.code==="ArrowLeft"){const c=lt();v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{K(c.children[0])}))}if(e.code==="ArrowRight"){const c=ot();v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{I(c.children[0])}))}}Me(e)},Oe=e=>{if(q&&(C==null?void 0:C.type)===E.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}F==null||F(e)},ve=e=>{const t=e.clipboardData.items;for(let l=0;l<t.length;l++)if(t[l].type.indexOf("image")!==-1){e.preventDefault();return}},Fe=e=>{e.preventDefault();const t=window.getSelection().toString();if(!t)return;const l=t.replace(/\u200B/g,"")||"",d=t.replace(/\u200B/g,"")||"";e.clipboardData.setData("text/plain",l),e.clipboardData.setData("text/html",d)},qe=e=>{m==null||m(e)},Ve=()=>{G.current=!0},_e=()=>{setTimeout(()=>{G.current=!1,U(H()),te(ce()),y==null||y(H())},0)},Ke=(e,n)=>{n.stopPropagation()},Ue=(e,n)=>{var l;n.stopPropagation(),T.current&&Le(T.current),(l=R.current)==null||l.setAttribute("contenteditable","false");const t=document.getElementById(e.id);T.current=t,requestAnimationFrame(()=>{O(t)})},We=(e,n)=>{var d,c,u,P,D,s;L==null||L(n),n.stopPropagation();const t=n.target,l=ue(t);if((n.code==="Backspace"||((d=n==null?void 0:n.nativeEvent)==null?void 0:d.key)==="Backspace")&&l===0){const f=(c=t.parentElement)==null?void 0:c.previousElementSibling;f&&(v(f)&&f.children[0]&&((u=f.children[0].textContent)!=null&&u.length)?(T.current=f,O(f),K(f.children[0]),requestAnimationFrame(()=>{de(f.children[0])})):(le(),K(f)))}if(n.code==="ArrowRight"&&l===((P=t.textContent)==null?void 0:P.length)){const f=(D=t.parentElement)==null?void 0:D.nextElementSibling;f&&(v(f)&&f.children[0]&&((s=f.children[0].textContent)!=null&&s.length)?(T.current=f,O(f),I(f.children[0]),requestAnimationFrame(()=>{de(f.children[0])})):(le(),I(f)))}n.code==="Enter"&&n.shiftKey&&n.preventDefault()},ze=(e,n)=>{F==null||F(n);const t=n.target;de(t)},Xe=(e,n)=>{var l;n.stopPropagation(),T.current&&Le(T.current),(l=R.current)==null||l.setAttribute("contenteditable","false");const t=document.getElementById(e.id);T.current=t,requestAnimationFrame(()=>{O(t)})},Ge=(e,n)=>{U(H()),te(ce()),y==null||y(H())},Je=(e,n)=>{};o.useEffect(()=>{if(!q)return;const e=l=>{j.current&&!j.current.contains(l.target)&&M(!1)},n=l=>{j.current&&!j.current.contains(l.target)&&M(!1)},t=()=>{M(!1)};return document.addEventListener("mousedown",e),document.addEventListener("scroll",n,!0),window.addEventListener("resize",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",n,!0),window.removeEventListener("resize",t)}},[q]);const J=(e,n)=>{if(C&&n!==E.LABEL&&st(C.id,e),n===E.SELECT&&(M(!1),_({})),n===E.LABEL&&(ae(),M(!1),requestAnimationFrame(()=>{const t=window.getSelection();t&&Q.current&&(t.removeAllRanges(),t.addRange(Q.current),setTimeout(()=>{var u;const l=document.createElement("span");l.contentEditable="false",l.setAttribute("data-set-type","label"),l.id=C.id;const d=document.createElement("span");d.contentEditable="false",d.textContent=e,l.appendChild(d);const c=(u=R.current)==null?void 0:u.children;if((c==null?void 0:c.length)===1&&c[0].tagName==="SPAN"&&c[0].innerHTML==="​[")R.current.innerHTML="",R.current.appendChild(l),setTimeout(()=>{_({}),ae()},0);else{document.execCommand("delete",!1,void 0);const P=Q.current;P.insertNode(l),P.setStartAfter(l),P.setEndAfter(l),t.removeAllRanges(),t.addRange(P),setTimeout(()=>{_({})},0)}},0))})),n===E.MULTIPLE_SELECT||n===E.DATE_PICKER){const t=document.getElementById(C.id);t&&t.children[0]&&t.children[1]&&(e.length>0?(t.children[0].setAttribute("style","display: inline"),t.children[0].setAttribute("contenteditable","false"),t.children[1].setAttribute("style","display: none"),t.children[1].setAttribute("contenteditable","true")):(t.children[0].setAttribute("style","display: none"),t.children[0].setAttribute("contenteditable","true"),t.children[1].setAttribute("style","display: inline"),t.children[1].setAttribute("contenteditable","true"))),_({})}},Q=o.useRef(null),Qe=(N==null?void 0:N.map(e=>e.prefix))||[],Ze=e=>{const n=e==null?void 0:e.nativeEvent,t=n==null?void 0:n.data;Qe.includes(t)&&ct().then(l=>{var c;const d=window.getSelection();d&&d.rangeCount>0&&(Q.current=d.getRangeAt(0)),Ie({options:((c=N.find(u=>u.prefix===t))==null?void 0:c.options)||[],value:"",type:E.LABEL,id:"label-"+Se()},l)})},Ie=(e,n)=>{se(e.options),V({top:-999999,left:-999999999}),ie(e),X(Ee),M(!0),requestAnimationFrame(()=>{if(j.current){const t=j.current.getBoundingClientRect();let l=n.left,d=n.top+n.height;window.innerWidth-n.right<ge&&n.width<t.width&&(l=n.right-t.width),n.top<t.height&&(d=n.top+n.height),V({top:d,left:l}),X(t.height)}})},be=(e,n)=>{const l=n.target.getBoundingClientRect();se(e.options),fe(e.value||Re(e.id)),V({top:-999999,left:-999999999}),ie(e),X(Ee),M(!0),requestAnimationFrame(()=>{if(j.current){const d=j.current.getBoundingClientRect();let c=l.left,u=l.top+l.height;window.innerWidth-l.right<ge&&l.width<d.width&&(c=l.right-d.width),l.top<d.height&&(u=l.top+l.height),V({top:u,left:c}),X(d.height)}})},Ye=(e,n)=>{const l=n.target.getBoundingClientRect();let d=l.left,c=l.top-xe;window.innerWidth-l.right<ye&&(d=d-ye+l.width),l.top<xe&&(c=l.top+l.height),se(e.options),fe(e.value||Re(e.id)),V({top:c,left:d}),ie(e),M(!0)},[et,we]=o.useState([]),[oe,Ce]=o.useState(!0),Ae=o.useCallback(()=>{Ce(!1);const e=Be(r),n=[];return e.forEach(t=>{var l,d,c,u,P,D;if(t.type==="text")n.push(p.jsx("span",{onKeyDown:s=>Je(),children:t.content},t.id));else if(t.type==="newline")n.push(p.jsx("br",{},t.id));else if(t.type==="label")n.push(p.jsx("span",{id:t.id,"data-set-type":"label",contentEditable:!1,children:p.jsx("span",{contentEditable:!1,children:t.name})},t.id));else if(t.type==="input")n.push(p.jsxs("span",{id:t.id,"data-set-type":"input",contentEditable:!1,suppressContentEditableWarning:!0,onInput:s=>Ge(),onClick:s=>Ke(t,s),onMouseDown:s=>Ue(t,s),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{className:"cosmic-ai-input-inputContent",style:{padding:(l=t.content)!=null&&l.length?"2px 4px":"2px 0 2px 4px"},contentEditable:!1,onKeyDown:s=>We(t,s),onKeyUp:s=>ze(t,s),children:t.content}),p.jsx("span",{contentEditable:!1,style:{display:(d=t.content)!=null&&d.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:s=>Xe(t,s),children:t.placeholder})]},t.id));else if(t.type===E.SELECT){const s=t.content||((c=t.options)==null?void 0:c[0])||t.placeholder;n.push(p.jsx("span",{id:t.id,"data-set-type":"select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:f=>be(t,f),"data-cosmic-ai-input-placeholder":t.placeholder,children:p.jsx("span",{contentEditable:!1,children:s})},t.id))}else if(t.type===E.MULTIPLE_SELECT){const s=t.content||((u=t.options)==null?void 0:u[0]);n.push(p.jsxs("span",{id:t.id,"data-set-type":"multiple-select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:f=>be(t,f),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{style:{display:s!=null&&s.length?"inline":"none"},contentEditable:!1,children:s}),p.jsx("span",{style:{display:s!=null&&s.length?"none":"inline"},className:"cosmic-ai-input-selectPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}else t.type===E.DATE_PICKER&&n.push(p.jsxs("span",{id:t.id,"data-set-type":"date-picker",contentEditable:!1,suppressContentEditableWarning:!0,onClick:s=>Ye(t,s),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{style:{display:(P=t.content)!=null&&P.length?"inline":"none"},contentEditable:!1,children:t.content}),p.jsx("span",{style:{display:(D=t.content)!=null&&D.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}),setTimeout(()=>{Ce(!0)},0),n},[r]);o.useEffect(()=>{oe&&setTimeout(()=>{},0)},[oe]),o.useEffect(()=>{r!==ee?(we(Ae()),U(r),he(!0)):(r===""||!r)&&we(Ae())},[r,ee]),o.useEffect(()=>{if(!k&&!pe)return;const e=new MutationObserver(()=>{R.current&&document.contains(R.current)&&(requestAnimationFrame(()=>{he(!1)}),e.disconnect())});return R.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[k,pe]);const ae=()=>{R.current&&requestAnimationFrame(()=>{})};return o.useImperativeHandle(a,()=>({getCurrentValue:H,focus:ae})),p.jsxs("div",{className:me(`cosmic-ai-input-rows${x}`),style:{textIndent:S+"px"},children:[oe&&p.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":B,className:me("cosmic-ai-input",`cosmic-ai-input-rows${x}`,{"is-disabled":$},{"is-empty":ee.length===0}),ref:R,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>$e(e),onFocus:e=>{qe(e)},onBlur:e=>{g==null||g(e)},onMouseDown:e=>je(),onKeyDown:e=>He(e),onKeyUp:e=>Oe(e),onInput:e=>_(e),onCopy:e=>Fe(e),onPaste:e=>ve(e),onCompositionStart:Ve,onCompositionEnd:_e,children:et}),q&&nt.createPortal((C==null?void 0:C.type)===E.MULTIPLE_SELECT?p.jsx(De,{ref:j,options:ne,value:z,position:W,height:re,onChange:J},E.MULTIPLE_SELECT):(C==null?void 0:C.type)===E.DATE_PICKER?p.jsx(Te,{ref:j,value:z,position:W,onChange:J},E.DATE_PICKER):(C==null?void 0:C.type)===E.LABEL?p.jsx(ke,{ref:j,options:ne,value:z,position:W,height:re,onChange:J},E.LABEL):p.jsx(Ne,{ref:j,options:ne,value:z,position:W,height:re,onChange:J},E.SELECT),document.body)]})});Pe.displayName="AiInput";exports.default=Pe;
1
+ // Generated at: 2026-04-04T02:21:24.833Z
2
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("react/jsx-runtime"),c=require("react"),Te=require("classnames"),rt=require("react-dom");var g=(r=>(r.INPUT="input",r.SELECT="select",r.MULTIPLE_SELECT="multiple-select",r.DATE_PICKER="date-picker",r.LABEL="label",r))(g||{});const D={BACKSPACE:"Backspace",ARROW_LEFT:"ArrowLeft",ARROW_RIGHT:"ArrowRight",ARROW_UP:"ArrowUp",ARROW_DOWN:"ArrowDown",ENTER:"Enter"},Pe=c.forwardRef(({value:r,position:o,id:l,onChange:p},O)=>{const[C,y]=c.useState(!0),$=c.useRef(null),k=c.useRef(null);c.useEffect(()=>{typeof O=="function"?O($.current):O&&(O.current=$.current)},[O]);const T=h=>{const E=h.target.value;p==null||p(E,g.DATE_PICKER)};c.useEffect(()=>{if(k.current)try{setTimeout(()=>{P()},100)}catch{}},[]);const P=()=>{if(k.current)try{k.current.showPicker()}catch{}},m=h=>{h.stopPropagation()};return C?d.jsx("div",{ref:$,id:l,style:{top:(o==null?void 0:o.top)||0,left:(o==null?void 0:o.left)||0},className:"cosmic-ai-input-datePicker",suppressHydrationWarning:!0,children:d.jsx("input",{ref:k,type:"date",value:r||"",onChange:T,onClick:m})}):null});Pe.displayName="DatePicker";function fe(r){const o=r.textContent||"",l=r.nextSibling;o.length?(l==null||l.setAttribute("style","display: none"),r.style.padding="2px 4px",r.style.borderTopLeftRadius="2px",r.style.borderBottomLeftRadius="2px",r.style.borderTopRightRadius="2px",r.style.borderBottomRightRadius="2px"):(l==null||l.setAttribute("style","display: inline"),r.style.padding="2px 0 2px 4px",r.style.borderTopLeftRadius="2px",r.style.borderBottomLeftRadius="2px",r.style.borderTopRightRadius="0",r.style.borderBottomRightRadius="0")}function W(r){if(r&&r.getAttribute("data-set-type")==="input"){const o=r.children[0];o.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{o.focus()})}}function Le(r){r&&r.getAttribute("data-set-type")==="input"&&r.children[0].setAttribute("contenteditable","false")}function v(r){return r&&(r!=null&&r.getAttribute)?r.getAttribute("data-set-type")==="input":!1}const ke=c.forwardRef(({options:r,value:o,position:l,id:p,height:O=37,onChange:C},y)=>{const[$,k]=c.useState(o||""),T=c.useRef(null);c.useEffect(()=>{typeof y=="function"?y(T.current):y&&(y.current=T.current)},[y]);const P=h=>{const E=$.split(",").filter(x=>x)||[];let b="";E.includes(h)?b=E.filter(x=>x!==h).join(","):E.length?b=`${E.join(",")},${h}`:b=h,k(b),C==null||C(b,g.MULTIPLE_SELECT)},m=$.split(",")||[];return d.jsx("div",{ref:T,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${O}px`},children:r.map((h,E)=>d.jsx("div",{className:`selectOption ${m.includes(h)?"selected":""}`,onClick:()=>P(h),children:h},E))})});ke.displayName="MultipleSelect";const Oe=c.forwardRef(({options:r,value:o,position:l,id:p,height:O=120,onChange:C},y)=>{const[$,k]=c.useState(o||""),T=c.useRef(null);c.useEffect(()=>{typeof y=="function"?y(T.current):y&&(y.current=T.current)},[y]);const P=m=>{k(m),C==null||C(m,g.SELECT)};return d.jsx("div",{ref:T,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${O}px`},children:r.length>0&&r.map((m,h)=>d.jsx("div",{className:`selectOption ${$===m?"selected":""}`,onClick:()=>P(m),children:m},h))})});Oe.displayName="Select";function Se(r){const o=r instanceof Element?r:document.getElementById(r);return o&&o.children[0].textContent||""}function lt(r,o){const l=r instanceof Element?r:document.getElementById(r);l&&(l.children[0].textContent=o)}function ee(r){const o=document.createRange(),l=window.getSelection();l&&(!r||!(r instanceof Node)||(o.selectNodeContents(r),o.collapse(!0),l.removeAllRanges(),l.addRange(o)))}function F(r){const o=document.createRange(),l=window.getSelection();l&&(!r||!(r instanceof Node)||(o.selectNodeContents(r),o.collapse(!1),l.removeAllRanges(),l.addRange(o)))}function pe(r){const o=window.getSelection();if(!o||o.rangeCount===0)return 0;if(!r||!(r instanceof Node))return;const l=o.getRangeAt(0),p=l.cloneRange();return p.selectNodeContents(r),p.setEnd(l.startContainer,l.startOffset),p.toString().length}function ct(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const l=r.getRangeAt(0).startContainer;return l.nodeType===Node.TEXT_NODE?l.parentElement:l.nodeType===Node.ELEMENT_NODE?l:null}function ot(){const r=window.getSelection();return!r||r.rangeCount===0?null:r.getRangeAt(0).getBoundingClientRect()}function at(){return new Promise(r=>{requestAnimationFrame(()=>{r(ot())})})}function ut(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const o=r.getRangeAt(0),l=o.startContainer,p=o.startOffset;return l.nodeType===Node.TEXT_NODE?p>0?l:l.previousSibling:l.nodeType===Node.ELEMENT_NODE?p>0?l.childNodes[p-1]:l.previousSibling:null}function dt(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const o=r.getRangeAt(0),l=o.startContainer,p=o.startOffset;return l.nodeType===Node.TEXT_NODE?p<l.length?l:l.nextSibling:l.nodeType===Node.ELEMENT_NODE?p<l.childNodes.length?l.childNodes[p]:l.nextSibling:null}function ft(r){return r&&!r.getAttribute("data-set-type")}function Ne(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}const De=/iPhone|iPad|iPod/i.test(navigator.userAgent)||navigator.userAgent.includes("Mac")&&"ontouchend"in document,Me=c.forwardRef(({options:r,value:o,position:l,id:p,height:O=120,onChange:C},y)=>{const[$,k]=c.useState(o||""),[T,P]=c.useState(0),m=c.useRef(null),h=c.useRef(T),E=c.useCallback(b=>{k(b),C==null||C(b,g.LABEL)},[C]);return c.useEffect(()=>{typeof y=="function"?y(m.current):y&&(y.current=m.current)},[y]),c.useEffect(()=>{h.current=T},[T]),c.useEffect(()=>{P(0)},[r]),c.useEffect(()=>{const b=x=>{r.length!==0&&(x.key==="ArrowDown"?(x.preventDefault(),P(w=>w<r.length-1?w+1:w)):x.key==="ArrowUp"?(x.preventDefault(),P(w=>w>0?w-1:w)):x.key==="Enter"&&(x.preventDefault(),setTimeout(()=>{const w=h.current;w>=0&&r[w]&&E(r[w])},0)))};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b)}},[r,E]),d.jsx("div",{ref:m,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${O}px`},children:r.length>0&&r.map((b,x)=>d.jsx("div",{className:`selectOption ${$===b?"selected":""} ${T===x?"highlighted":""}`,onClick:()=>E(b),onMouseEnter:()=>P(x),children:b},x))})});Me.displayName="Mention";const $e=c.forwardRef((r,o)=>{const{value:l="",varList:p,placeholder:O="",maxLength:C,defaultRows:y=3,disabled:$=!1,defaultFocus:k=!1,textIndex:T=0,mentions:P=[],onFocus:m,onBlur:h,onChange:E,onClick:b,onSend:x,onKeyDown:w,onKeyUp:q,onMaxLengthExceeded:te}=r,[pt,ht]=c.useState(l||""),[ne,z]=c.useState(""),[gt,se]=c.useState(""),[K,H]=c.useState(!1),[G,V]=c.useState({top:0,left:0}),[ie,re]=c.useState([]),[X,he]=c.useState(""),[A,le]=c.useState(null),[ce,I]=c.useState(120),[ge,Ee]=c.useState(k),ye=240,xe=240,Re=240,be=276,R=c.useRef(null),L=c.useRef(null),B=c.useRef(null),J=c.useRef(!1),S=(e,s)=>e.code===s||e.key===s,_=()=>{var s,t;let e=((t=(s=R.current)==null?void 0:s.innerText)==null?void 0:t.replace(/\u200B/g,""))||"";return e===`
3
+ `&&(e=""),e},oe=()=>{var s;let e=((s=R.current)==null?void 0:s.innerHTML)||"";return e==="<br>"&&(e=""),e},Be=e=>{const s=[];let t=0;const i=/\[([^\]]+)\]/g;let a;const u=Ne();let f=0;if(e===""||!e||e===`
4
+ `)return[{type:"text",content:"​",id:`text-${f++}-${u}`}];const M=new Set((p||[]).map(N=>N.name));for(;(a=i.exec(e))!==null;){if(a.index>t){const j=e.substring(t,a.index).split(`
5
+ `);j.forEach((Y,it)=>{Y&&s.push({type:"text",content:Y,id:`text-${f++}-${u}`}),it<j.length-1&&s.push({type:"newline",id:`newline-${f++}-${u}`})})}const N=a[1];if(M.has(N)){const n=p.find(j=>j.name===N);(n==null?void 0:n.type)==="input"?s.push({type:"input",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||N,id:`input-${f++}-${u}`}):(n==null?void 0:n.type)==="label"?s.push({type:"label",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",id:`label-${f++}-${u}`}):(n==null?void 0:n.type)==="select"?s.push({type:"select",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||N,options:(n==null?void 0:n.options)||[],id:`select-${f++}-${u}`}):(n==null?void 0:n.type)==="multiple-select"?s.push({type:"multiple-select",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||N,options:(n==null?void 0:n.options)||[],id:`multiple-select-${f++}-${u}`}):(n==null?void 0:n.type)==="date-picker"&&s.push({type:"date-picker",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||N,id:`date-picker-${f++}-${u}`})}else s.push({type:"text",content:`[${N}]`,id:`text-${f++}-${u}`});t=i.lastIndex}if(t<e.length){const n=e.substring(t).split(`
6
+ `);n.forEach((j,Y)=>{j&&s.push({type:"text",content:j,id:`text-${f++}`}),Y<n.length-1&&s.push({type:"newline",id:`newline-${f++}`})})}return s},ae=()=>{var e;(e=R.current)==null||e.setAttribute("contenteditable","true"),L.current&&(v(L.current)&&L.current.children[0].setAttribute("contenteditable","false"),L.current=null),F(R.current)},je=e=>{b==null||b(e)},He=e=>{ae()},U=e=>{var t,i;const s=e.nativeEvent;if(J.current||s!=null&&s.isComposing){_().length>0?(t=R.current)==null||t.classList.remove("is-empty"):(i=R.current)==null||i.classList.add("is-empty");return}z(_()),se(oe()),E==null||E(_()),et(e)},_e=e=>{var s,t;if(!(J.current||(s=e.nativeEvent)!=null&&s.isComposing)&&S(e,D.ENTER)&&!e.shiftKey&&!De){e.preventDefault();const i=_();if(i.length===0||(t=R.current)!=null&&t.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/))return;C?i.length<=C?x==null||x(i):te==null||te(i,C):x==null||x(i)}},We=e=>{var t;if(K&&(A==null?void 0:A.type)===g.LABEL&&(S(e,D.ARROW_UP)||S(e,D.ARROW_DOWN)||S(e,D.ENTER))){e.preventDefault();return}H(!1),w==null||w(e);const s=ct();if(s&&ft(s)){if(S(e,D.ARROW_LEFT)){const i=s==null?void 0:s.previousElementSibling,a=pe(s);i&&a===0&&v(i)&&i.children[0]&&(L.current=i,W(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(S(e,D.ARROW_RIGHT)){const i=s==null?void 0:s.nextElementSibling,a=pe(s);i&&a===((t=s.textContent)==null?void 0:t.length)&&v(i)&&i.children[0]&&(L.current=i,W(i),requestAnimationFrame(()=>{ee(i.children[0])}))}S(e,D.BACKSPACE)&&(s.innerHTML==="​"&&e.preventDefault(),s.innerHTML==="<br>"&&(e.preventDefault(),s.innerHTML="​"))}if(S(e,D.BACKSPACE)&&e.target){const i=e.target;if(i.childElementCount===1&&i.children[0].tagName==="SPAN"){const a=i.children[0];i.childNodes.length===1&&(a.innerHTML==="​"&&e.preventDefault(),a.innerHTML==="<br>"&&(e.preventDefault(),a.innerHTML="​"))}}if(s&&s.getAttribute("data-set-type")==="container"){if(S(e,D.ARROW_LEFT)){const i=ut();v(i)&&i.children[0]&&(L.current=i,W(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(S(e,D.ARROW_RIGHT)){const i=dt();v(i)&&i.children[0]&&(L.current=i,W(i),requestAnimationFrame(()=>{ee(i.children[0])}))}}_e(e)},Fe=e=>{if(K&&(A==null?void 0:A.type)===g.LABEL&&(S(e,D.ARROW_UP)||S(e,D.ARROW_DOWN)||S(e,D.ENTER))){e.preventDefault();return}q==null||q(e)},ve=e=>{const t=e.clipboardData.items;for(let i=0;i<t.length;i++)if(t[i].type.indexOf("image")!==-1){e.preventDefault();return}},qe=e=>{e.preventDefault();const t=window.getSelection().toString();if(!t)return;const i=t.replace(/\u200B/g,"")||"",a=t.replace(/\u200B/g,"")||"";e.clipboardData.setData("text/plain",i),e.clipboardData.setData("text/html",a)},Ke=e=>{m==null||m(e)},Ve=()=>{J.current=!0},Ue=()=>{setTimeout(()=>{J.current=!1,z(_()),se(oe()),E==null||E(_())},0)},ze=(e,s)=>{s.stopPropagation()},Ge=(e,s)=>{var i;s.stopPropagation(),L.current&&Le(L.current),(i=R.current)==null||i.setAttribute("contenteditable","false");const t=document.getElementById(e.id);L.current=t,requestAnimationFrame(()=>{W(t)})},Xe=(e,s)=>{var a,u,f,M,N;w==null||w(s),s.stopPropagation();const t=s.target,i=pe(t);if(S(s,D.BACKSPACE)&&i===0){const n=(a=t.parentElement)==null?void 0:a.previousElementSibling;n&&(v(n)&&n.children[0]&&((u=n.children[0].textContent)!=null&&u.length)?(L.current=n,W(n),F(n.children[0]),requestAnimationFrame(()=>{fe(n.children[0])})):(ae(),F(n)))}if(S(s,D.ARROW_RIGHT)&&i===((f=t.textContent)==null?void 0:f.length)){const n=(M=t.parentElement)==null?void 0:M.nextElementSibling;n&&(v(n)&&n.children[0]&&((N=n.children[0].textContent)!=null&&N.length)?(L.current=n,W(n),ee(n.children[0]),requestAnimationFrame(()=>{fe(n.children[0])})):(ae(),ee(n)))}S(s,D.ENTER)&&s.shiftKey&&s.preventDefault()},Ie=(e,s)=>{q==null||q(s);const t=s.target;fe(t)},Je=(e,s)=>{var i;s.stopPropagation(),L.current&&Le(L.current),(i=R.current)==null||i.setAttribute("contenteditable","false");const t=document.getElementById(e.id);L.current=t,requestAnimationFrame(()=>{W(t)})},Qe=(e,s)=>{z(_()),se(oe()),E==null||E(_())},Ze=(e,s)=>{};c.useEffect(()=>{if(!K)return;const e=i=>{B.current&&!B.current.contains(i.target)&&H(!1)},s=i=>{B.current&&!B.current.contains(i.target)&&H(!1)},t=()=>{H(!1)};return document.addEventListener("mousedown",e),document.addEventListener("scroll",s,!0),window.addEventListener("resize",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",s,!0),window.removeEventListener("resize",t)}},[K]);const Q=(e,s)=>{if(A&&s!==g.LABEL&&lt(A.id,e),s===g.SELECT&&(H(!1),U({})),s===g.LABEL&&(de(),H(!1),requestAnimationFrame(()=>{const t=window.getSelection();t&&Z.current&&(t.removeAllRanges(),t.addRange(Z.current),setTimeout(()=>{var f;const i=document.createElement("span");i.contentEditable="false",i.setAttribute("data-set-type","label"),i.id=A.id;const a=document.createElement("span");a.contentEditable="false",a.textContent=e,i.appendChild(a);const u=(f=R.current)==null?void 0:f.children;if((u==null?void 0:u.length)===1&&u[0].tagName==="SPAN"&&u[0].innerHTML==="​[")R.current.innerHTML="",R.current.appendChild(i),setTimeout(()=>{U({}),de()},0);else{document.execCommand("delete",!1,void 0);const M=Z.current;M.insertNode(i),M.setStartAfter(i),M.setEndAfter(i),t.removeAllRanges(),t.addRange(M),setTimeout(()=>{U({})},0)}},0))})),s===g.MULTIPLE_SELECT||s===g.DATE_PICKER){const t=document.getElementById(A.id);t&&t.children[0]&&t.children[1]&&(e.length>0?(t.children[0].setAttribute("style","display: inline"),t.children[0].setAttribute("contenteditable","false"),t.children[1].setAttribute("style","display: none"),t.children[1].setAttribute("contenteditable","true")):(t.children[0].setAttribute("style","display: none"),t.children[0].setAttribute("contenteditable","true"),t.children[1].setAttribute("style","display: inline"),t.children[1].setAttribute("contenteditable","true"))),U({})}},Z=c.useRef(null),Ye=(P==null?void 0:P.map(e=>e.prefix))||[],et=e=>{const s=e==null?void 0:e.nativeEvent,t=s==null?void 0:s.data;Ye.includes(t)&&at().then(i=>{var u;const a=window.getSelection();a&&a.rangeCount>0&&(Z.current=a.getRangeAt(0)),tt({options:((u=P.find(f=>f.prefix===t))==null?void 0:u.options)||[],value:"",type:g.LABEL,id:"label-"+Ne()},i)})},tt=(e,s)=>{re(e.options),V({top:-999999,left:-999999999}),le(e),I(xe),H(!0),requestAnimationFrame(()=>{if(B.current){const t=B.current.getBoundingClientRect();let i=s.left,a=s.top+s.height;window.innerWidth-s.right<ye&&s.width<t.width&&(i=s.right-t.width),s.top<t.height&&(a=s.top+s.height),V({top:a,left:i}),I(t.height)}})},Ae=(e,s)=>{const i=s.target.getBoundingClientRect();re(e.options),he(e.value||Se(e.id)),V({top:-999999,left:-999999999}),le(e),I(xe),H(!0),requestAnimationFrame(()=>{if(B.current){const a=B.current.getBoundingClientRect();let u=i.left,f=i.top+i.height;window.innerWidth-i.right<ye&&i.width<a.width&&(u=i.right-a.width),i.top<a.height&&(f=i.top+i.height),V({top:f,left:u}),I(a.height)}})},nt=(e,s)=>{const i=s.target.getBoundingClientRect();let a=i.left,u=i.top-be;window.innerWidth-i.right<Re&&(a=a-Re+i.width),i.top<be&&(u=i.top+i.height),re(e.options),he(e.value||Se(e.id)),V({top:u,left:a}),le(e),H(!0)},[st,Ce]=c.useState([]),[ue,me]=c.useState(!0),we=c.useCallback(()=>{me(!1);const e=Be(l),s=[];return e.forEach(t=>{var i,a,u,f,M,N;if(t.type==="text")s.push(d.jsx("span",{onKeyDown:n=>Ze(),children:t.content},t.id));else if(t.type==="newline")s.push(d.jsx("br",{},t.id));else if(t.type==="label")s.push(d.jsx("span",{id:t.id,"data-set-type":"label",contentEditable:!1,children:d.jsx("span",{contentEditable:!1,children:t.name})},t.id));else if(t.type==="input")s.push(d.jsxs("span",{id:t.id,"data-set-type":"input",contentEditable:!1,suppressContentEditableWarning:!0,onInput:n=>Qe(),onClick:n=>ze(t,n),onMouseDown:n=>Ge(t,n),"data-cosmic-ai-input-placeholder":t.placeholder,children:[d.jsx("span",{className:"cosmic-ai-input-inputContent",style:{padding:(i=t.content)!=null&&i.length?"2px 4px":"2px 0 2px 4px"},contentEditable:!1,onKeyDown:n=>Xe(t,n),onKeyUp:n=>Ie(t,n),children:t.content}),d.jsx("span",{contentEditable:!1,style:{display:(a=t.content)!=null&&a.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:n=>Je(t,n),children:t.placeholder})]},t.id));else if(t.type===g.SELECT){const n=t.content||((u=t.options)==null?void 0:u[0])||t.placeholder;s.push(d.jsx("span",{id:t.id,"data-set-type":"select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:j=>Ae(t,j),"data-cosmic-ai-input-placeholder":t.placeholder,children:d.jsx("span",{contentEditable:!1,children:n})},t.id))}else if(t.type===g.MULTIPLE_SELECT){const n=t.content||((f=t.options)==null?void 0:f[0]);s.push(d.jsxs("span",{id:t.id,"data-set-type":"multiple-select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:j=>Ae(t,j),"data-cosmic-ai-input-placeholder":t.placeholder,children:[d.jsx("span",{style:{display:n!=null&&n.length?"inline":"none"},contentEditable:!1,children:n}),d.jsx("span",{style:{display:n!=null&&n.length?"none":"inline"},className:"cosmic-ai-input-selectPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}else t.type===g.DATE_PICKER&&s.push(d.jsxs("span",{id:t.id,"data-set-type":"date-picker",contentEditable:!1,suppressContentEditableWarning:!0,onClick:n=>nt(t,n),"data-cosmic-ai-input-placeholder":t.placeholder,children:[d.jsx("span",{style:{display:(M=t.content)!=null&&M.length?"inline":"none"},contentEditable:!1,children:t.content}),d.jsx("span",{style:{display:(N=t.content)!=null&&N.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}),setTimeout(()=>{me(!0)},0),s},[l]);c.useEffect(()=>{ue&&setTimeout(()=>{F(R.current)},0)},[ue]),c.useEffect(()=>{l!==ne?(De||Ce(we()),z(l),Ee(!0)):(l===""||!l)&&Ce(we())},[l,ne]),c.useEffect(()=>{if(!k&&!ge)return;const e=new MutationObserver(()=>{R.current&&document.contains(R.current)&&(requestAnimationFrame(()=>{F(R.current),Ee(!1)}),e.disconnect())});return R.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[k,ge]);const de=()=>{R.current&&requestAnimationFrame(()=>{F(R.current)})};return c.useImperativeHandle(o,()=>({getCurrentValue:_,focus:de})),d.jsxs("div",{className:Te(`cosmic-ai-input-rows${y}`),style:{textIndent:T+"px"},children:[ue&&d.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":O,className:Te("cosmic-ai-input",`cosmic-ai-input-rows${y}`,{"is-disabled":$},{"is-empty":ne.length===0}),ref:R,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>je(e),onFocus:e=>{Ke(e)},onBlur:e=>{h==null||h(e)},onMouseDown:e=>He(),onKeyDown:e=>We(e),onKeyUp:e=>Fe(e),onInput:e=>U(e),onCopy:e=>qe(e),onPaste:e=>ve(e),onCompositionStart:Ve,onCompositionEnd:Ue,children:st}),K&&rt.createPortal((A==null?void 0:A.type)===g.MULTIPLE_SELECT?d.jsx(ke,{ref:B,options:ie,value:X,position:G,height:ce,onChange:Q},g.MULTIPLE_SELECT):(A==null?void 0:A.type)===g.DATE_PICKER?d.jsx(Pe,{ref:B,value:X,position:G,onChange:Q},g.DATE_PICKER):(A==null?void 0:A.type)===g.LABEL?d.jsx(Me,{ref:B,options:ie,value:X,position:G,height:ce,onChange:Q},g.LABEL):d.jsx(Oe,{ref:B,options:ie,value:X,position:G,height:ce,onChange:Q},g.SELECT),document.body)]})});$e.displayName="AiInput";exports.default=$e;