cosmic-ai-input 1.0.20 → 1.0.22

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