cosmic-ai-input 1.0.14 → 1.0.16

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