cosmic-ai-input 1.0.20 → 1.0.21

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-04T04:15:26.668Z
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"),it=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"},De=c.forwardRef(({value:r,position:o,id:l,onChange:p},O)=>{const[C,y]=c.useState(!0),M=c.useRef(null),k=c.useRef(null);c.useEffect(()=>{typeof O=="function"?O(M.current):O&&(O.current=M.current)},[O]);const T=h=>{const E=h.target.value;p==null||p(E,g.DATE_PICKER)};c.useEffect(()=>{if(k.current)try{setTimeout(()=>{N()},100)}catch{}},[]);const N=()=>{if(k.current)try{k.current.showPicker()}catch{}},m=h=>{h.stopPropagation()};return C?d.jsx("div",{ref:M,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});De.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 Se(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 Pe=c.forwardRef(({options:r,value:o,position:l,id:p,height:O=37,onChange:C},y)=>{const[M,k]=c.useState(o||""),T=c.useRef(null);c.useEffect(()=>{typeof y=="function"?y(T.current):y&&(y.current=T.current)},[y]);const N=h=>{const E=M.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=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:()=>N(h),children:h},E))})});Pe.displayName="MultipleSelect";const ke=c.forwardRef(({options:r,value:o,position:l,id:p,height:O=120,onChange:C},y)=>{const[M,k]=c.useState(o||""),T=c.useRef(null);c.useEffect(()=>{typeof y=="function"?y(T.current):y&&(y.current=T.current)},[y]);const N=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===m?"selected":""}`,onClick:()=>N(m),children:m},h))})});ke.displayName="Select";function Le(r){const o=r instanceof Element?r:document.getElementById(r);return o&&o.children[0].textContent||""}function rt(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 lt(){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 ct(){const r=window.getSelection();return!r||r.rangeCount===0?null:r.getRangeAt(0).getBoundingClientRect()}function ot(){return new Promise(r=>{requestAnimationFrame(()=>{r(ct())})})}function at(){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 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<l.length?l:l.nextSibling:l.nodeType===Node.ELEMENT_NODE?p<l.childNodes.length?l.childNodes[p]:l.nextSibling:null}function dt(r){return r&&!r.getAttribute("data-set-type")}function Ne(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}/iPhone|iPad|iPod/i.test(navigator.userAgent)||navigator.userAgent.includes("Mac")&&"ontouchend"in document;const ft=/Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent)||"ontouchend"in document,Oe=c.forwardRef(({options:r,value:o,position:l,id:p,height:O=120,onChange:C},y)=>{const[M,k]=c.useState(o||""),[T,N]=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(()=>{N(0)},[r]),c.useEffect(()=>{const b=x=>{r.length!==0&&(x.key==="ArrowDown"?(x.preventDefault(),N(w=>w<r.length-1?w+1:w)):x.key==="ArrowUp"?(x.preventDefault(),N(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 ${M===b?"selected":""} ${T===x?"highlighted":""}`,onClick:()=>E(b),onMouseEnter:()=>N(x),children:b},x))})});Oe.displayName="Mention";const $e=c.forwardRef((r,o)=>{const{value:l="",varList:p,placeholder:O="",maxLength:C,defaultRows:y=3,disabled:M=!1,defaultFocus:k=!1,textIndex:T=0,mentions:N=[],onFocus:m,onBlur:h,onChange:E,onClick:b,onSend:x,onKeyDown:w,onKeyUp:q,onMaxLengthExceeded:te}=r,[pt,ht]=c.useState(l||""),[ne,G]=c.useState(""),[gt,se]=c.useState(""),[K,_]=c.useState(!1),[X,V]=c.useState({top:0,left:0}),[ie,re]=c.useState([]),[I,he]=c.useState(""),[A,le]=c.useState(null),[ce,J]=c.useState(120),[ge,Ee]=c.useState(k),ye=240,xe=240,Re=240,be=276,R=c.useRef(null),S=c.useRef(null),j=c.useRef(null),U=c.useRef(!1),D=(e,s)=>e.code===s||e.key===s,H=()=>{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},Me=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 $=new Set((p||[]).map(L=>L.name));for(;(a=i.exec(e))!==null;){if(a.index>t){const B=e.substring(t,a.index).split(`
5
+ `);B.forEach((Y,st)=>{Y&&s.push({type:"text",content:Y,id:`text-${f++}-${u}`}),st<B.length-1&&s.push({type:"newline",id:`newline-${f++}-${u}`})})}const L=a[1];if($.has(L)){const n=p.find(B=>B.name===L);(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)||L,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)||L,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)||L,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)||L,id:`date-picker-${f++}-${u}`})}else s.push({type:"text",content:`[${L}]`,id:`text-${f++}-${u}`});t=i.lastIndex}if(t<e.length){const n=e.substring(t).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},ae=()=>{var e;(e=R.current)==null||e.setAttribute("contenteditable","true"),S.current&&(v(S.current)&&S.current.children[0].setAttribute("contenteditable","false"),S.current=null),F(R.current)},je=e=>{b==null||b(e)},Be=e=>{ae()},z=e=>{var t,i;const s=e.nativeEvent;if(U.current||s!=null&&s.isComposing){H().length>0?(t=R.current)==null||t.classList.remove("is-empty"):(i=R.current)==null||i.classList.add("is-empty");return}G(H()),se(oe()),E==null||E(H()),Ye(e)},_e=e=>{var s,t;if(!(U.current||(s=e.nativeEvent)!=null&&s.isComposing)&&D(e,P.ENTER)&&!e.shiftKey&&!ft){e.preventDefault();const i=H();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)}},He=e=>{var t;if(K&&(A==null?void 0:A.type)===g.LABEL&&(D(e,P.ARROW_UP)||D(e,P.ARROW_DOWN)||D(e,P.ENTER))){e.preventDefault();return}_(!1),w==null||w(e);const s=lt();if(s&&dt(s)){if(D(e,P.ARROW_LEFT)){const i=s==null?void 0:s.previousElementSibling,a=pe(s);i&&a===0&&v(i)&&i.children[0]&&(S.current=i,W(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(D(e,P.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]&&(S.current=i,W(i),requestAnimationFrame(()=>{ee(i.children[0])}))}}if(D(e,P.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(D(e,P.ARROW_LEFT)){const i=at();v(i)&&i.children[0]&&(S.current=i,W(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(D(e,P.ARROW_RIGHT)){const i=ut();v(i)&&i.children[0]&&(S.current=i,W(i),requestAnimationFrame(()=>{ee(i.children[0])}))}}_e(e)},We=e=>{if(K&&(A==null?void 0:A.type)===g.LABEL&&(D(e,P.ARROW_UP)||D(e,P.ARROW_DOWN)||D(e,P.ENTER))){e.preventDefault();return}q==null||q(e)},Fe=e=>{const t=e.clipboardData.items;for(let i=0;i<t.length;i++)if(t[i].type.indexOf("image")!==-1){e.preventDefault();return}},ve=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)},qe=e=>{m==null||m(e)},Ke=()=>{U.current=!0},Ve=()=>{setTimeout(()=>{G(H()),se(oe()),E==null||E(H())},0)},Ue=(e,s)=>{s.stopPropagation()},ze=(e,s)=>{var i;s.stopPropagation(),S.current&&Se(S.current),(i=R.current)==null||i.setAttribute("contenteditable","false");const t=document.getElementById(e.id);S.current=t,requestAnimationFrame(()=>{W(t)})},Ge=(e,s)=>{var a,u,f,$,L;w==null||w(s),s.stopPropagation();const t=s.target,i=pe(t);if(D(s,P.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)?(S.current=n,W(n),F(n.children[0]),requestAnimationFrame(()=>{fe(n.children[0])})):(ae(),F(n)))}if(D(s,P.ARROW_RIGHT)&&i===((f=t.textContent)==null?void 0:f.length)){const n=($=t.parentElement)==null?void 0:$.nextElementSibling;n&&(v(n)&&n.children[0]&&((L=n.children[0].textContent)!=null&&L.length)?(S.current=n,W(n),ee(n.children[0]),requestAnimationFrame(()=>{fe(n.children[0])})):(ae(),ee(n)))}D(s,P.ENTER)&&s.shiftKey&&s.preventDefault()},Xe=(e,s)=>{q==null||q(s);const t=s.target;fe(t)},Ie=(e,s)=>{var i;s.stopPropagation(),S.current&&Se(S.current),(i=R.current)==null||i.setAttribute("contenteditable","false");const t=document.getElementById(e.id);S.current=t,requestAnimationFrame(()=>{W(t)})},Je=(e,s)=>{G(H()),se(oe()),E==null||E(H())},Qe=(e,s)=>{};c.useEffect(()=>{if(!K)return;const e=i=>{j.current&&!j.current.contains(i.target)&&_(!1)},s=i=>{j.current&&!j.current.contains(i.target)&&_(!1)},t=()=>{_(!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&&rt(A.id,e),s===g.SELECT&&(_(!1),z({})),s===g.LABEL&&(de(),_(!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(()=>{z({}),de()},0);else{document.execCommand("delete",!1,void 0);const $=Z.current;$.insertNode(i),$.setStartAfter(i),$.setEndAfter(i),t.removeAllRanges(),t.addRange($),setTimeout(()=>{z({})},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"))),z({})}},Z=c.useRef(null),Ze=(N==null?void 0:N.map(e=>e.prefix))||[],Ye=e=>{const s=e==null?void 0:e.nativeEvent,t=s==null?void 0:s.data;Ze.includes(t)&&ot().then(i=>{var u;const a=window.getSelection();a&&a.rangeCount>0&&(Z.current=a.getRangeAt(0)),et({options:((u=N.find(f=>f.prefix===t))==null?void 0:u.options)||[],value:"",type:g.LABEL,id:"label-"+Ne()},i)})},et=(e,s)=>{re(e.options),V({top:-999999,left:-999999999}),le(e),J(xe),_(!0),requestAnimationFrame(()=>{if(j.current){const t=j.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}),J(t.height)}})},Ae=(e,s)=>{const i=s.target.getBoundingClientRect();re(e.options),he(e.value||Le(e.id)),V({top:-999999,left:-999999999}),le(e),J(xe),_(!0),requestAnimationFrame(()=>{if(j.current){const a=j.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}),J(a.height)}})},tt=(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||Le(e.id)),V({top:u,left:a}),le(e),_(!0)},[nt,Ce]=c.useState([]),[ue,me]=c.useState(!0),we=c.useCallback(()=>{me(!1);const e=Me(l),s=[];return e.forEach(t=>{var i,a,u,f,$,L;if(t.type==="text")s.push(d.jsx("span",{onKeyDown:n=>Qe(),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=>Je(),onClick:n=>Ue(t,n),onMouseDown:n=>ze(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=>Ge(t,n),onKeyUp:n=>Xe(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=>Ie(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:B=>Ae(t,B),"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:B=>Ae(t,B),"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=>tt(t,n),"data-cosmic-ai-input-placeholder":t.placeholder,children:[d.jsx("span",{style:{display:($=t.content)!=null&&$.length?"inline":"none"},contentEditable:!1,children:t.content}),d.jsx("span",{style:{display:(L=t.content)!=null&&L.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&&U.current===!1?(Ce(we()),G(l),Ee(!0)):(l===""||!l)&&Ce(we()),U.current=!1},[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:H,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":M},{"is-empty":ne.length===0}),ref:R,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>je(e),onFocus:e=>{qe(e)},onBlur:e=>{h==null||h(e)},onMouseDown:e=>Be(),onKeyDown:e=>He(e),onKeyUp:e=>We(e),onInput:e=>z(e),onCopy:e=>ve(e),onPaste:e=>Fe(e),onCompositionStart:Ke,onCompositionEnd:Ve,children:nt}),K&&it.createPortal((A==null?void 0:A.type)===g.MULTIPLE_SELECT?d.jsx(Pe,{ref:j,options:ie,value:I,position:X,height:ce,onChange:Q},g.MULTIPLE_SELECT):(A==null?void 0:A.type)===g.DATE_PICKER?d.jsx(De,{ref:j,value:I,position:X,onChange:Q},g.DATE_PICKER):(A==null?void 0:A.type)===g.LABEL?d.jsx(Oe,{ref:j,options:ie,value:I,position:X,height:ce,onChange:Q},g.LABEL):d.jsx(ke,{ref:j,options:ie,value:I,position:X,height:ce,onChange:Q},g.SELECT),document.body)]})});$e.displayName="AiInput";exports.default=$e;
package/dist/index.es.js CHANGED
@@ -1,36 +1,36 @@
1
- // Generated at: 2026-04-04T02:21:24.345Z
1
+ // Generated at: 2026-04-04T04:15:26.235Z
2
2
  import { jsx as u, jsxs as ie } from "react/jsx-runtime";
3
- import { forwardRef as X, useState as w, useRef as W, useEffect as H, useCallback as Be, useImperativeHandle as at } from "react";
3
+ import { forwardRef as I, useState as w, useRef as W, useEffect as _, useCallback as $e, useImperativeHandle as ct } from "react";
4
4
  import De from "classnames";
5
- import { createPortal as dt } from "react-dom";
5
+ import { createPortal as at } from "react-dom";
6
6
  var h = /* @__PURE__ */ ((s) => (s.INPUT = "input", s.SELECT = "select", s.MULTIPLE_SELECT = "multiple-select", s.DATE_PICKER = "date-picker", s.LABEL = "label", s))(h || {});
7
- const D = {
7
+ const P = {
8
8
  BACKSPACE: "Backspace",
9
9
  ARROW_LEFT: "ArrowLeft",
10
10
  ARROW_RIGHT: "ArrowRight",
11
11
  ARROW_UP: "ArrowUp",
12
12
  ARROW_DOWN: "ArrowDown",
13
13
  ENTER: "Enter"
14
- }, Me = X(
14
+ }, Be = I(
15
15
  ({ value: s, position: o, id: l, onChange: f }, O) => {
16
16
  const [R, E] = w(!0), B = W(null), k = W(null);
17
- H(() => {
17
+ _(() => {
18
18
  typeof O == "function" ? O(B.current) : O && (O.current = B.current);
19
19
  }, [O]);
20
20
  const T = (p) => {
21
21
  const g = p.target.value;
22
22
  f == null || f(g, h.DATE_PICKER);
23
23
  };
24
- H(() => {
24
+ _(() => {
25
25
  if (k.current)
26
26
  try {
27
27
  setTimeout(() => {
28
- P();
28
+ S();
29
29
  }, 100);
30
30
  } catch {
31
31
  }
32
32
  }, []);
33
- const P = () => {
33
+ const S = () => {
34
34
  if (k.current)
35
35
  try {
36
36
  k.current.showPicker();
@@ -64,7 +64,7 @@ const D = {
64
64
  ) : null;
65
65
  }
66
66
  );
67
- Me.displayName = "DatePicker";
67
+ Be.displayName = "DatePicker";
68
68
  function Ee(s) {
69
69
  const o = s.textContent || "", l = s.nextSibling;
70
70
  o.length ? (l == null || l.setAttribute("style", "display: none"), s.style.padding = "2px 4px", s.style.borderTopLeftRadius = "2px", s.style.borderBottomLeftRadius = "2px", s.style.borderTopRightRadius = "2px", s.style.borderBottomRightRadius = "2px") : (l == null || l.setAttribute("style", "display: inline"), s.style.padding = "2px 0 2px 4px", s.style.borderTopLeftRadius = "2px", s.style.borderBottomLeftRadius = "2px", s.style.borderTopRightRadius = "0", s.style.borderBottomRightRadius = "0");
@@ -83,7 +83,7 @@ function Pe(s) {
83
83
  function q(s) {
84
84
  return s && (s != null && s.getAttribute) ? s.getAttribute("data-set-type") === "input" : !1;
85
85
  }
86
- const He = X(({
86
+ const Me = I(({
87
87
  options: s,
88
88
  value: o,
89
89
  position: l,
@@ -92,10 +92,10 @@ const He = X(({
92
92
  onChange: R
93
93
  }, E) => {
94
94
  const [B, k] = w(o || ""), T = W(null);
95
- H(() => {
95
+ _(() => {
96
96
  typeof E == "function" ? E(T.current) : E && (E.current = T.current);
97
97
  }, [E]);
98
- const P = (p) => {
98
+ const S = (p) => {
99
99
  const g = B.split(",").filter((y) => y) || [];
100
100
  let b = "";
101
101
  g.includes(p) ? b = g.filter((y) => y !== p).join(",") : g.length ? b = `${g.join(",")},${p}` : b = p, k(b), R == null || R(b, h.MULTIPLE_SELECT);
@@ -117,7 +117,7 @@ const He = X(({
117
117
  "div",
118
118
  {
119
119
  className: `selectOption ${m.includes(p) ? "selected" : ""}`,
120
- onClick: () => P(p),
120
+ onClick: () => S(p),
121
121
  children: p
122
122
  },
123
123
  g
@@ -125,8 +125,8 @@ const He = X(({
125
125
  }
126
126
  );
127
127
  });
128
- He.displayName = "MultipleSelect";
129
- const _e = X(({
128
+ Me.displayName = "MultipleSelect";
129
+ const _e = I(({
130
130
  options: s,
131
131
  value: o,
132
132
  position: l,
@@ -135,10 +135,10 @@ const _e = X(({
135
135
  onChange: R
136
136
  }, E) => {
137
137
  const [B, k] = w(o || ""), T = W(null);
138
- H(() => {
138
+ _(() => {
139
139
  typeof E == "function" ? E(T.current) : E && (E.current = T.current);
140
140
  }, [E]);
141
- const P = (m) => {
141
+ const S = (m) => {
142
142
  k(m), R == null || R(m, h.SELECT);
143
143
  };
144
144
  return /* @__PURE__ */ u(
@@ -158,7 +158,7 @@ const _e = X(({
158
158
  "div",
159
159
  {
160
160
  className: `selectOption ${B === m ? "selected" : ""}`,
161
- onClick: () => P(m),
161
+ onClick: () => S(m),
162
162
  children: m
163
163
  },
164
164
  p
@@ -171,7 +171,7 @@ function ke(s) {
171
171
  const o = s instanceof Element ? s : document.getElementById(s);
172
172
  return o && o.children[0].textContent || "";
173
173
  }
174
- function ut(s, o) {
174
+ function dt(s, o) {
175
175
  const l = s instanceof Element ? s : document.getElementById(s);
176
176
  l && (l.children[0].textContent = o);
177
177
  }
@@ -192,43 +192,44 @@ function ye(s) {
192
192
  const l = o.getRangeAt(0), f = l.cloneRange();
193
193
  return f.selectNodeContents(s), f.setEnd(l.startContainer, l.startOffset), f.toString().length;
194
194
  }
195
- function ft() {
195
+ function ut() {
196
196
  const s = window.getSelection();
197
197
  if (!s || s.rangeCount === 0)
198
198
  return null;
199
199
  const l = s.getRangeAt(0).startContainer;
200
200
  return l.nodeType === Node.TEXT_NODE ? l.parentElement : l.nodeType === Node.ELEMENT_NODE ? l : null;
201
201
  }
202
- function pt() {
202
+ function ft() {
203
203
  const s = window.getSelection();
204
204
  return !s || s.rangeCount === 0 ? null : s.getRangeAt(0).getBoundingClientRect();
205
205
  }
206
- function ht() {
206
+ function pt() {
207
207
  return new Promise((s) => {
208
208
  requestAnimationFrame(() => {
209
- s(pt());
209
+ s(ft());
210
210
  });
211
211
  });
212
212
  }
213
- function gt() {
213
+ function ht() {
214
214
  const s = window.getSelection();
215
215
  if (!s || s.rangeCount === 0) return null;
216
216
  const o = s.getRangeAt(0), l = o.startContainer, f = o.startOffset;
217
217
  return l.nodeType === Node.TEXT_NODE ? f > 0 ? l : l.previousSibling : l.nodeType === Node.ELEMENT_NODE ? f > 0 ? l.childNodes[f - 1] : l.previousSibling : null;
218
218
  }
219
- function Et() {
219
+ function gt() {
220
220
  const s = window.getSelection();
221
221
  if (!s || s.rangeCount === 0) return null;
222
222
  const o = s.getRangeAt(0), l = o.startContainer, f = o.startOffset;
223
223
  return l.nodeType === Node.TEXT_NODE ? f < l.length ? l : l.nextSibling : l.nodeType === Node.ELEMENT_NODE ? f < l.childNodes.length ? l.childNodes[f] : l.nextSibling : null;
224
224
  }
225
- function yt(s) {
225
+ function Et(s) {
226
226
  return s && !s.getAttribute("data-set-type");
227
227
  }
228
228
  function Oe() {
229
229
  return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
230
230
  }
231
- const $e = /iPhone|iPad|iPod/i.test(navigator.userAgent) || navigator.userAgent.includes("Mac") && "ontouchend" in document, We = X(({
231
+ /iPhone|iPad|iPod/i.test(navigator.userAgent) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
232
+ const yt = /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent) || "ontouchend" in document, He = I(({
232
233
  options: s,
233
234
  value: o,
234
235
  position: l,
@@ -236,18 +237,18 @@ const $e = /iPhone|iPad|iPod/i.test(navigator.userAgent) || navigator.userAgent.
236
237
  height: O = 120,
237
238
  onChange: R
238
239
  }, E) => {
239
- const [B, k] = w(o || ""), [T, P] = w(0), m = W(null), p = W(T), g = Be((b) => {
240
+ const [B, k] = w(o || ""), [T, S] = w(0), m = W(null), p = W(T), g = $e((b) => {
240
241
  k(b), R == null || R(b, h.LABEL);
241
242
  }, [R]);
242
- return H(() => {
243
+ return _(() => {
243
244
  typeof E == "function" ? E(m.current) : E && (E.current = m.current);
244
- }, [E]), H(() => {
245
+ }, [E]), _(() => {
245
246
  p.current = T;
246
- }, [T]), H(() => {
247
- P(0);
248
- }, [s]), H(() => {
247
+ }, [T]), _(() => {
248
+ S(0);
249
+ }, [s]), _(() => {
249
250
  const b = (y) => {
250
- s.length !== 0 && (y.key === "ArrowDown" ? (y.preventDefault(), P((x) => x < s.length - 1 ? x + 1 : x)) : y.key === "ArrowUp" ? (y.preventDefault(), P((x) => x > 0 ? x - 1 : x)) : y.key === "Enter" && (y.preventDefault(), setTimeout(() => {
251
+ s.length !== 0 && (y.key === "ArrowDown" ? (y.preventDefault(), S((x) => x < s.length - 1 ? x + 1 : x)) : y.key === "ArrowUp" ? (y.preventDefault(), S((x) => x > 0 ? x - 1 : x)) : y.key === "Enter" && (y.preventDefault(), setTimeout(() => {
251
252
  const x = p.current;
252
253
  x >= 0 && s[x] && g(s[x]);
253
254
  }, 0)));
@@ -273,7 +274,7 @@ const $e = /iPhone|iPad|iPod/i.test(navigator.userAgent) || navigator.userAgent.
273
274
  {
274
275
  className: `selectOption ${B === b ? "selected" : ""} ${T === y ? "highlighted" : ""}`,
275
276
  onClick: () => g(b),
276
- onMouseEnter: () => P(y),
277
+ onMouseEnter: () => S(y),
277
278
  children: b
278
279
  },
279
280
  y
@@ -281,8 +282,8 @@ const $e = /iPhone|iPad|iPod/i.test(navigator.userAgent) || navigator.userAgent.
281
282
  }
282
283
  );
283
284
  });
284
- We.displayName = "Mention";
285
- const At = X((s, o) => {
285
+ He.displayName = "Mention";
286
+ const At = I((s, o) => {
286
287
  const {
287
288
  value: l = "",
288
289
  varList: f,
@@ -292,7 +293,7 @@ const At = X((s, o) => {
292
293
  disabled: B = !1,
293
294
  defaultFocus: k = !1,
294
295
  textIndex: T = 0,
295
- mentions: P = [],
296
+ mentions: S = [],
296
297
  onFocus: m,
297
298
  onBlur: p,
298
299
  onChange: g,
@@ -301,7 +302,7 @@ const At = X((s, o) => {
301
302
  onKeyDown: x,
302
303
  onKeyUp: U,
303
304
  onMaxLengthExceeded: se
304
- } = s, [bt, Ct] = w(l || ""), [le, I] = w(""), [Rt, oe] = w(""), [z, F] = w(!1), [J, j] = w({ top: 0, left: 0 }), [ce, ae] = w([]), [Q, Ae] = w(""), [C, de] = w(null), [ue, Z] = w(120), [be, Ce] = w(k), Re = 240, me = 240, xe = 240, we = 276, A = W(null), L = W(null), M = W(null), Y = W(!1), N = (e, i) => e.code === i || e.key === i, v = () => {
305
+ } = s, [bt, Ct] = w(l || ""), [le, J] = w(""), [Rt, oe] = w(""), [z, F] = w(!1), [Q, j] = w({ top: 0, left: 0 }), [ce, ae] = w([]), [Z, Ae] = w(""), [C, de] = w(null), [ue, Y] = w(120), [be, Ce] = w(k), Re = 240, me = 240, xe = 240, we = 276, A = W(null), L = W(null), M = W(null), G = W(!1), D = (e, i) => e.code === i || e.key === i, v = () => {
305
306
  var i, t;
306
307
  let e = ((t = (i = A.current) == null ? void 0 : i.innerText) == null ? void 0 : t.replace(/\u200B/g, "")) || "";
307
308
  return e === `
@@ -310,7 +311,7 @@ const At = X((s, o) => {
310
311
  var i;
311
312
  let e = ((i = A.current) == null ? void 0 : i.innerHTML) || "";
312
313
  return e === "<br>" && (e = ""), e;
313
- }, Fe = (e) => {
314
+ }, We = (e) => {
314
315
  const i = [];
315
316
  let t = 0;
316
317
  const r = /\[([^\]]+)\]/g;
@@ -326,30 +327,30 @@ const At = X((s, o) => {
326
327
  id: `text-${d++}-${a}`
327
328
  }
328
329
  ];
329
- const $ = new Set((f || []).map((S) => S.name));
330
+ const $ = new Set((f || []).map((N) => N.name));
330
331
  for (; (c = r.exec(e)) !== null; ) {
331
332
  if (c.index > t) {
332
- const _ = e.substring(t, c.index).split(`
333
+ const H = e.substring(t, c.index).split(`
333
334
  `);
334
- _.forEach((ne, ct) => {
335
+ H.forEach((ne, ot) => {
335
336
  ne && i.push({
336
337
  type: "text",
337
338
  content: ne,
338
339
  id: `text-${d++}-${a}`
339
- }), ct < _.length - 1 && i.push({
340
+ }), ot < H.length - 1 && i.push({
340
341
  type: "newline",
341
342
  id: `newline-${d++}-${a}`
342
343
  });
343
344
  });
344
345
  }
345
- const S = c[1];
346
- if ($.has(S)) {
347
- const n = f.find((_) => _.name === S);
346
+ const N = c[1];
347
+ if ($.has(N)) {
348
+ const n = f.find((H) => H.name === N);
348
349
  (n == null ? void 0 : n.type) === "input" ? i.push({
349
350
  type: "input",
350
351
  name: n == null ? void 0 : n.name,
351
352
  content: (n == null ? void 0 : n.content) || "",
352
- placeholder: (n == null ? void 0 : n.placeholder) || S,
353
+ placeholder: (n == null ? void 0 : n.placeholder) || N,
353
354
  id: `input-${d++}-${a}`
354
355
  }) : (n == null ? void 0 : n.type) === "label" ? i.push({
355
356
  type: "label",
@@ -360,27 +361,27 @@ const At = X((s, o) => {
360
361
  type: "select",
361
362
  name: n == null ? void 0 : n.name,
362
363
  content: (n == null ? void 0 : n.content) || "",
363
- placeholder: (n == null ? void 0 : n.placeholder) || S,
364
+ placeholder: (n == null ? void 0 : n.placeholder) || N,
364
365
  options: (n == null ? void 0 : n.options) || [],
365
366
  id: `select-${d++}-${a}`
366
367
  }) : (n == null ? void 0 : n.type) === "multiple-select" ? i.push({
367
368
  type: "multiple-select",
368
369
  name: n == null ? void 0 : n.name,
369
370
  content: (n == null ? void 0 : n.content) || "",
370
- placeholder: (n == null ? void 0 : n.placeholder) || S,
371
+ placeholder: (n == null ? void 0 : n.placeholder) || N,
371
372
  options: (n == null ? void 0 : n.options) || [],
372
373
  id: `multiple-select-${d++}-${a}`
373
374
  }) : (n == null ? void 0 : n.type) === "date-picker" && i.push({
374
375
  type: "date-picker",
375
376
  name: n == null ? void 0 : n.name,
376
377
  content: (n == null ? void 0 : n.content) || "",
377
- placeholder: (n == null ? void 0 : n.placeholder) || S,
378
+ placeholder: (n == null ? void 0 : n.placeholder) || N,
378
379
  id: `date-picker-${d++}-${a}`
379
380
  });
380
381
  } else
381
382
  i.push({
382
383
  type: "text",
383
- content: `[${S}]`,
384
+ content: `[${N}]`,
384
385
  id: `text-${d++}-${a}`
385
386
  });
386
387
  t = r.lastIndex;
@@ -388,10 +389,10 @@ const At = X((s, o) => {
388
389
  if (t < e.length) {
389
390
  const n = e.substring(t).split(`
390
391
  `);
391
- n.forEach((_, ne) => {
392
- _ && i.push({
392
+ n.forEach((H, ne) => {
393
+ H && i.push({
393
394
  type: "text",
394
- content: _,
395
+ content: H,
395
396
  id: `text-${d++}`
396
397
  }), ne < n.length - 1 && i.push({
397
398
  type: "newline",
@@ -406,21 +407,21 @@ const At = X((s, o) => {
406
407
  "contenteditable",
407
408
  "false"
408
409
  ), L.current = null), V(A.current);
409
- }, ve = (e) => {
410
+ }, Fe = (e) => {
410
411
  b == null || b(e);
411
- }, Ke = (e) => {
412
+ }, ve = (e) => {
412
413
  pe();
413
- }, G = (e) => {
414
+ }, X = (e) => {
414
415
  var t, r;
415
416
  const i = e.nativeEvent;
416
- if (Y.current || i != null && i.isComposing) {
417
+ if (G.current || i != null && i.isComposing) {
417
418
  v().length > 0 ? (t = A.current) == null || t.classList.remove("is-empty") : (r = A.current) == null || r.classList.add("is-empty");
418
419
  return;
419
420
  }
420
- I(v()), oe(fe()), g == null || g(v()), rt(e);
421
- }, Ve = (e) => {
421
+ J(v()), oe(fe()), g == null || g(v()), it(e);
422
+ }, Ke = (e) => {
422
423
  var i, t;
423
- if (!(Y.current || (i = e.nativeEvent) != null && i.isComposing) && N(e, D.ENTER) && !e.shiftKey && !$e) {
424
+ if (!(G.current || (i = e.nativeEvent) != null && i.isComposing) && D(e, P.ENTER) && !e.shiftKey && !yt) {
424
425
  e.preventDefault();
425
426
  const r = v();
426
427
  if (r.length === 0 || (t = A.current) != null && t.innerHTML.match(
@@ -429,30 +430,29 @@ const At = X((s, o) => {
429
430
  return;
430
431
  R ? r.length <= R ? y == null || y(r) : se == null || se(r, R) : y == null || y(r);
431
432
  }
432
- }, qe = (e) => {
433
+ }, Ve = (e) => {
433
434
  var t;
434
- if (z && (C == null ? void 0 : C.type) === h.LABEL && (N(e, D.ARROW_UP) || N(e, D.ARROW_DOWN) || N(e, D.ENTER))) {
435
+ if (z && (C == null ? void 0 : C.type) === h.LABEL && (D(e, P.ARROW_UP) || D(e, P.ARROW_DOWN) || D(e, P.ENTER))) {
435
436
  e.preventDefault();
436
437
  return;
437
438
  }
438
439
  F(!1), x == null || x(e);
439
- const i = ft();
440
- if (i && yt(i)) {
441
- if (N(e, D.ARROW_LEFT)) {
440
+ const i = ut();
441
+ if (i && Et(i)) {
442
+ if (D(e, P.ARROW_LEFT)) {
442
443
  const r = i == null ? void 0 : i.previousElementSibling, c = ye(i);
443
444
  r && c === 0 && q(r) && r.children[0] && (L.current = r, K(r), requestAnimationFrame(() => {
444
445
  V(r.children[0]);
445
446
  }));
446
447
  }
447
- if (N(e, D.ARROW_RIGHT)) {
448
+ if (D(e, P.ARROW_RIGHT)) {
448
449
  const r = i == null ? void 0 : i.nextElementSibling, c = ye(i);
449
450
  r && c === ((t = i.textContent) == null ? void 0 : t.length) && q(r) && r.children[0] && (L.current = r, K(r), requestAnimationFrame(() => {
450
451
  re(r.children[0]);
451
452
  }));
452
453
  }
453
- N(e, D.BACKSPACE) && (i.innerHTML === "​" && e.preventDefault(), i.innerHTML === "<br>" && (e.preventDefault(), i.innerHTML = "​"));
454
454
  }
455
- if (N(e, D.BACKSPACE) && e.target) {
455
+ if (D(e, P.BACKSPACE) && e.target) {
456
456
  const r = e.target;
457
457
  if (r.childElementCount === 1 && r.children[0].tagName === "SPAN") {
458
458
  const c = r.children[0];
@@ -460,89 +460,89 @@ const At = X((s, o) => {
460
460
  }
461
461
  }
462
462
  if (i && i.getAttribute("data-set-type") === "container") {
463
- if (N(e, D.ARROW_LEFT)) {
464
- const r = gt();
463
+ if (D(e, P.ARROW_LEFT)) {
464
+ const r = ht();
465
465
  q(r) && r.children[0] && (L.current = r, K(r), requestAnimationFrame(() => {
466
466
  V(r.children[0]);
467
467
  }));
468
468
  }
469
- if (N(e, D.ARROW_RIGHT)) {
470
- const r = Et();
469
+ if (D(e, P.ARROW_RIGHT)) {
470
+ const r = gt();
471
471
  q(r) && r.children[0] && (L.current = r, K(r), requestAnimationFrame(() => {
472
472
  re(r.children[0]);
473
473
  }));
474
474
  }
475
475
  }
476
- Ve(e);
477
- }, Ue = (e) => {
478
- if (z && (C == null ? void 0 : C.type) === h.LABEL && (N(e, D.ARROW_UP) || N(e, D.ARROW_DOWN) || N(e, D.ENTER))) {
476
+ Ke(e);
477
+ }, qe = (e) => {
478
+ if (z && (C == null ? void 0 : C.type) === h.LABEL && (D(e, P.ARROW_UP) || D(e, P.ARROW_DOWN) || D(e, P.ENTER))) {
479
479
  e.preventDefault();
480
480
  return;
481
481
  }
482
482
  U == null || U(e);
483
- }, ze = (e) => {
483
+ }, Ue = (e) => {
484
484
  const t = e.clipboardData.items;
485
485
  for (let r = 0; r < t.length; r++)
486
486
  if (t[r].type.indexOf("image") !== -1) {
487
487
  e.preventDefault();
488
488
  return;
489
489
  }
490
- }, je = (e) => {
490
+ }, ze = (e) => {
491
491
  e.preventDefault();
492
492
  const t = window.getSelection().toString();
493
493
  if (!t) return;
494
494
  const r = t.replace(/\u200B/g, "") || "", c = t.replace(/\u200B/g, "") || "";
495
495
  e.clipboardData.setData("text/plain", r), e.clipboardData.setData("text/html", c);
496
- }, Ge = (e) => {
496
+ }, je = (e) => {
497
497
  m == null || m(e);
498
+ }, Ge = () => {
499
+ G.current = !0;
498
500
  }, Xe = () => {
499
- Y.current = !0;
500
- }, Ie = () => {
501
501
  setTimeout(() => {
502
- Y.current = !1, I(v()), oe(fe()), g == null || g(v());
502
+ J(v()), oe(fe()), g == null || g(v());
503
503
  }, 0);
504
- }, Je = (e, i) => {
504
+ }, Ie = (e, i) => {
505
505
  i.stopPropagation();
506
- }, Qe = (e, i) => {
506
+ }, Je = (e, i) => {
507
507
  var r;
508
508
  i.stopPropagation(), L.current && Pe(L.current), (r = A.current) == null || r.setAttribute("contenteditable", "false");
509
509
  const t = document.getElementById(e.id);
510
510
  L.current = t, requestAnimationFrame(() => {
511
511
  K(t);
512
512
  });
513
- }, Ze = (e, i) => {
514
- var c, a, d, $, S;
513
+ }, Qe = (e, i) => {
514
+ var c, a, d, $, N;
515
515
  x == null || x(i), i.stopPropagation();
516
516
  const t = i.target, r = ye(t);
517
- if (N(i, D.BACKSPACE) && r === 0) {
517
+ if (D(i, P.BACKSPACE) && r === 0) {
518
518
  const n = (c = t.parentElement) == null ? void 0 : c.previousElementSibling;
519
519
  n && (q(n) && n.children[0] && ((a = n.children[0].textContent) != null && a.length) ? (L.current = n, K(n), V(n.children[0]), requestAnimationFrame(() => {
520
520
  Ee(n.children[0]);
521
521
  })) : (pe(), V(n)));
522
522
  }
523
- if (N(i, D.ARROW_RIGHT) && r === ((d = t.textContent) == null ? void 0 : d.length)) {
523
+ if (D(i, P.ARROW_RIGHT) && r === ((d = t.textContent) == null ? void 0 : d.length)) {
524
524
  const n = ($ = t.parentElement) == null ? void 0 : $.nextElementSibling;
525
- n && (q(n) && n.children[0] && ((S = n.children[0].textContent) != null && S.length) ? (L.current = n, K(n), re(n.children[0]), requestAnimationFrame(() => {
525
+ n && (q(n) && n.children[0] && ((N = n.children[0].textContent) != null && N.length) ? (L.current = n, K(n), re(n.children[0]), requestAnimationFrame(() => {
526
526
  Ee(n.children[0]);
527
527
  })) : (pe(), re(n)));
528
528
  }
529
- N(i, D.ENTER) && i.shiftKey && i.preventDefault();
530
- }, Ye = (e, i) => {
529
+ D(i, P.ENTER) && i.shiftKey && i.preventDefault();
530
+ }, Ze = (e, i) => {
531
531
  U == null || U(i);
532
532
  const t = i.target;
533
533
  Ee(t);
534
- }, et = (e, i) => {
534
+ }, Ye = (e, i) => {
535
535
  var r;
536
536
  i.stopPropagation(), L.current && Pe(L.current), (r = A.current) == null || r.setAttribute("contenteditable", "false");
537
537
  const t = document.getElementById(e.id);
538
538
  L.current = t, requestAnimationFrame(() => {
539
539
  K(t);
540
540
  });
541
+ }, et = (e, i) => {
542
+ J(v()), oe(fe()), g == null || g(v());
541
543
  }, tt = (e, i) => {
542
- I(v()), oe(fe()), g == null || g(v());
543
- }, nt = (e, i) => {
544
544
  };
545
- H(() => {
545
+ _(() => {
546
546
  if (!z) return;
547
547
  const e = (r) => {
548
548
  M.current && !M.current.contains(r.target) && F(!1);
@@ -556,7 +556,7 @@ const At = X((s, o) => {
556
556
  };
557
557
  }, [z]);
558
558
  const ee = (e, i) => {
559
- if (C && i !== h.LABEL && ut(C.id, e), i === h.SELECT && (F(!1), G({})), i === h.LABEL && (ge(), F(!1), requestAnimationFrame(() => {
559
+ if (C && i !== h.LABEL && dt(C.id, e), i === h.SELECT && (F(!1), X({})), i === h.LABEL && (ge(), F(!1), requestAnimationFrame(() => {
560
560
  const t = window.getSelection();
561
561
  t && te.current && (t.removeAllRanges(), t.addRange(te.current), setTimeout(() => {
562
562
  var d;
@@ -567,13 +567,13 @@ const At = X((s, o) => {
567
567
  const a = (d = A.current) == null ? void 0 : d.children;
568
568
  if ((a == null ? void 0 : a.length) === 1 && a[0].tagName === "SPAN" && a[0].innerHTML === "​[")
569
569
  A.current.innerHTML = "", A.current.appendChild(r), setTimeout(() => {
570
- G({}), ge();
570
+ X({}), ge();
571
571
  }, 0);
572
572
  else {
573
573
  document.execCommand("delete", !1, void 0);
574
574
  const $ = te.current;
575
575
  $.insertNode(r), $.setStartAfter(r), $.setEndAfter(r), t.removeAllRanges(), t.addRange($), setTimeout(() => {
576
- G({});
576
+ X({});
577
577
  }, 0);
578
578
  }
579
579
  }, 0));
@@ -581,49 +581,49 @@ const At = X((s, o) => {
581
581
  const t = document.getElementById(
582
582
  C.id
583
583
  );
584
- 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"))), G({});
584
+ 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"))), X({});
585
585
  }
586
- }, te = W(null), it = (P == null ? void 0 : P.map((e) => e.prefix)) || [], rt = (e) => {
586
+ }, te = W(null), nt = (S == null ? void 0 : S.map((e) => e.prefix)) || [], it = (e) => {
587
587
  const i = e == null ? void 0 : e.nativeEvent, t = i == null ? void 0 : i.data;
588
- it.includes(t) && ht().then((r) => {
588
+ nt.includes(t) && pt().then((r) => {
589
589
  var a;
590
590
  const c = window.getSelection();
591
- c && c.rangeCount > 0 && (te.current = c.getRangeAt(0)), st({
592
- options: ((a = P.find((d) => d.prefix === t)) == null ? void 0 : a.options) || [],
591
+ c && c.rangeCount > 0 && (te.current = c.getRangeAt(0)), rt({
592
+ options: ((a = S.find((d) => d.prefix === t)) == null ? void 0 : a.options) || [],
593
593
  value: "",
594
594
  type: h.LABEL,
595
595
  id: "label-" + Oe()
596
596
  }, r);
597
597
  });
598
- }, st = (e, i) => {
599
- ae(e.options), j({ top: -999999, left: -999999999 }), de(e), Z(me), F(!0), requestAnimationFrame(() => {
598
+ }, rt = (e, i) => {
599
+ ae(e.options), j({ top: -999999, left: -999999999 }), de(e), Y(me), F(!0), requestAnimationFrame(() => {
600
600
  if (M.current) {
601
601
  const t = M.current.getBoundingClientRect();
602
602
  let r = i.left, c = i.top + i.height;
603
- window.innerWidth - i.right < Re && i.width < t.width && (r = i.right - t.width), i.top < t.height && (c = i.top + i.height), j({ top: c, left: r }), Z(t.height);
603
+ window.innerWidth - i.right < Re && i.width < t.width && (r = i.right - t.width), i.top < t.height && (c = i.top + i.height), j({ top: c, left: r }), Y(t.height);
604
604
  }
605
605
  });
606
606
  }, Te = (e, i) => {
607
607
  const r = i.target.getBoundingClientRect();
608
- ae(e.options), Ae(e.value || ke(e.id)), j({ top: -999999, left: -999999999 }), de(e), Z(me), F(!0), requestAnimationFrame(() => {
608
+ ae(e.options), Ae(e.value || ke(e.id)), j({ top: -999999, left: -999999999 }), de(e), Y(me), F(!0), requestAnimationFrame(() => {
609
609
  if (M.current) {
610
610
  const c = M.current.getBoundingClientRect();
611
611
  let a = r.left, d = r.top + r.height;
612
- window.innerWidth - r.right < Re && r.width < c.width && (a = r.right - c.width), r.top < c.height && (d = r.top + r.height), j({ top: d, left: a }), Z(c.height);
612
+ window.innerWidth - r.right < Re && r.width < c.width && (a = r.right - c.width), r.top < c.height && (d = r.top + r.height), j({ top: d, left: a }), Y(c.height);
613
613
  }
614
614
  });
615
- }, lt = (e, i) => {
615
+ }, st = (e, i) => {
616
616
  const r = i.target.getBoundingClientRect();
617
617
  let c = r.left, a = r.top - we;
618
618
  window.innerWidth - r.right < xe && (c = c - xe + r.width), r.top < we && (a = r.top + r.height), ae(e.options), Ae(e.value || ke(e.id)), j({ top: a, left: c }), de(e), F(!0);
619
- }, [ot, Le] = w([]), [he, Ne] = w(!0), Se = Be(() => {
619
+ }, [lt, Le] = w([]), [he, Ne] = w(!0), Se = $e(() => {
620
620
  Ne(!1);
621
- const e = Fe(l), i = [];
621
+ const e = We(l), i = [];
622
622
  return e.forEach((t) => {
623
- var r, c, a, d, $, S;
623
+ var r, c, a, d, $, N;
624
624
  if (t.type === "text")
625
625
  i.push(
626
- /* @__PURE__ */ u("span", { onKeyDown: (n) => nt(), children: t.content }, t.id)
626
+ /* @__PURE__ */ u("span", { onKeyDown: (n) => tt(), children: t.content }, t.id)
627
627
  );
628
628
  else if (t.type === "newline")
629
629
  i.push(/* @__PURE__ */ u("br", {}, t.id));
@@ -655,9 +655,9 @@ const At = X((s, o) => {
655
655
  "data-set-type": "input",
656
656
  contentEditable: !1,
657
657
  suppressContentEditableWarning: !0,
658
- onInput: (n) => tt(),
659
- onClick: (n) => Je(t, n),
660
- onMouseDown: (n) => Qe(t, n),
658
+ onInput: (n) => et(),
659
+ onClick: (n) => Ie(t, n),
660
+ onMouseDown: (n) => Je(t, n),
661
661
  "data-cosmic-ai-input-placeholder": t.placeholder,
662
662
  children: [
663
663
  /* @__PURE__ */ u(
@@ -668,8 +668,8 @@ const At = X((s, o) => {
668
668
  padding: (r = t.content) != null && r.length ? "2px 4px" : "2px 0 2px 4px"
669
669
  },
670
670
  contentEditable: !1,
671
- onKeyDown: (n) => Ze(t, n),
672
- onKeyUp: (n) => Ye(t, n),
671
+ onKeyDown: (n) => Qe(t, n),
672
+ onKeyUp: (n) => Ze(t, n),
673
673
  children: t.content
674
674
  }
675
675
  ),
@@ -679,7 +679,7 @@ const At = X((s, o) => {
679
679
  contentEditable: !1,
680
680
  style: { display: (c = t.content) != null && c.length ? "none" : "inline" },
681
681
  className: "cosmic-ai-input-placeholder",
682
- onMouseDown: (n) => et(t, n),
682
+ onMouseDown: (n) => Ye(t, n),
683
683
  children: t.placeholder
684
684
  }
685
685
  )
@@ -698,7 +698,7 @@ const At = X((s, o) => {
698
698
  "data-set-type": "select",
699
699
  contentEditable: !1,
700
700
  suppressContentEditableWarning: !0,
701
- onClick: (_) => Te(t, _),
701
+ onClick: (H) => Te(t, H),
702
702
  "data-cosmic-ai-input-placeholder": t.placeholder,
703
703
  children: /* @__PURE__ */ u("span", { contentEditable: !1, children: n })
704
704
  },
@@ -715,7 +715,7 @@ const At = X((s, o) => {
715
715
  "data-set-type": "multiple-select",
716
716
  contentEditable: !1,
717
717
  suppressContentEditableWarning: !0,
718
- onClick: (_) => Te(t, _),
718
+ onClick: (H) => Te(t, H),
719
719
  "data-cosmic-ai-input-placeholder": t.placeholder,
720
720
  children: [
721
721
  /* @__PURE__ */ u(
@@ -748,7 +748,7 @@ const At = X((s, o) => {
748
748
  "data-set-type": "date-picker",
749
749
  contentEditable: !1,
750
750
  suppressContentEditableWarning: !0,
751
- onClick: (n) => lt(t, n),
751
+ onClick: (n) => st(t, n),
752
752
  "data-cosmic-ai-input-placeholder": t.placeholder,
753
753
  children: [
754
754
  /* @__PURE__ */ u(
@@ -762,7 +762,7 @@ const At = X((s, o) => {
762
762
  /* @__PURE__ */ u(
763
763
  "span",
764
764
  {
765
- style: { display: (S = t.content) != null && S.length ? "none" : "inline" },
765
+ style: { display: (N = t.content) != null && N.length ? "none" : "inline" },
766
766
  className: "cosmic-ai-input-datePickerPlaceholder",
767
767
  contentEditable: !1,
768
768
  children: t.placeholder
@@ -777,13 +777,13 @@ const At = X((s, o) => {
777
777
  Ne(!0);
778
778
  }, 0), i;
779
779
  }, [l]);
780
- H(() => {
780
+ _(() => {
781
781
  he && setTimeout(() => {
782
782
  V(A.current);
783
783
  }, 0);
784
- }, [he]), H(() => {
785
- l !== le ? ($e || Le(Se()), I(l), Ce(!0)) : (l === "" || !l) && Le(Se());
786
- }, [l, le]), H(() => {
784
+ }, [he]), _(() => {
785
+ l !== le && G.current === !1 ? (Le(Se()), J(l), Ce(!0)) : (l === "" || !l) && Le(Se()), G.current = !1;
786
+ }, [l, le]), _(() => {
787
787
  if (!k && !be) return;
788
788
  const e = new MutationObserver(() => {
789
789
  A.current && document.contains(A.current) && (requestAnimationFrame(() => {
@@ -797,7 +797,7 @@ const At = X((s, o) => {
797
797
  V(A.current);
798
798
  });
799
799
  };
800
- return at(o, () => ({
800
+ return ct(o, () => ({
801
801
  getCurrentValue: v,
802
802
  focus: ge
803
803
  })), // 最外层的防止renderContainer为false的时候样式坍塌
@@ -816,52 +816,52 @@ const At = X((s, o) => {
816
816
  ref: A,
817
817
  contentEditable: !0,
818
818
  suppressContentEditableWarning: !0,
819
- onClick: (e) => ve(e),
819
+ onClick: (e) => Fe(e),
820
820
  onFocus: (e) => {
821
- Ge(e);
821
+ je(e);
822
822
  },
823
823
  onBlur: (e) => {
824
824
  p == null || p(e);
825
825
  },
826
- onMouseDown: (e) => Ke(),
827
- onKeyDown: (e) => qe(e),
828
- onKeyUp: (e) => Ue(e),
829
- onInput: (e) => G(e),
830
- onCopy: (e) => je(e),
831
- onPaste: (e) => ze(e),
832
- onCompositionStart: Xe,
833
- onCompositionEnd: Ie,
834
- children: ot
826
+ onMouseDown: (e) => ve(),
827
+ onKeyDown: (e) => Ve(e),
828
+ onKeyUp: (e) => qe(e),
829
+ onInput: (e) => X(e),
830
+ onCopy: (e) => ze(e),
831
+ onPaste: (e) => Ue(e),
832
+ onCompositionStart: Ge,
833
+ onCompositionEnd: Xe,
834
+ children: lt
835
835
  }
836
836
  ),
837
- z && dt(
837
+ z && at(
838
838
  (C == null ? void 0 : C.type) === h.MULTIPLE_SELECT ? /* @__PURE__ */ u(
839
- He,
839
+ Me,
840
840
  {
841
841
  ref: M,
842
842
  options: ce,
843
- value: Q,
844
- position: J,
843
+ value: Z,
844
+ position: Q,
845
845
  height: ue,
846
846
  onChange: ee
847
847
  },
848
848
  h.MULTIPLE_SELECT
849
849
  ) : (C == null ? void 0 : C.type) === h.DATE_PICKER ? /* @__PURE__ */ u(
850
- Me,
850
+ Be,
851
851
  {
852
852
  ref: M,
853
- value: Q,
854
- position: J,
853
+ value: Z,
854
+ position: Q,
855
855
  onChange: ee
856
856
  },
857
857
  h.DATE_PICKER
858
858
  ) : (C == null ? void 0 : C.type) === h.LABEL ? /* @__PURE__ */ u(
859
- We,
859
+ He,
860
860
  {
861
861
  ref: M,
862
862
  options: ce,
863
- value: Q,
864
- position: J,
863
+ value: Z,
864
+ position: Q,
865
865
  height: ue,
866
866
  onChange: ee
867
867
  },
@@ -871,8 +871,8 @@ const At = X((s, o) => {
871
871
  {
872
872
  ref: M,
873
873
  options: ce,
874
- value: Q,
875
- position: J,
874
+ value: Z,
875
+ position: Q,
876
876
  height: ue,
877
877
  onChange: ee
878
878
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosmic-ai-input",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "A powerful AI conversation input component for React with TypeScript support",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.es.js",