cosmic-ai-input 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
- // Generated at: 2026-03-10T07:58:48.707Z
2
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("react/jsx-runtime"),c=require("react"),Re=require("classnames"),tt=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 Te=c.forwardRef(({value:r,position:o,id:l,onChange:p},k)=>{const[C,E]=c.useState(!0),$=c.useRef(null),N=c.useRef(null);c.useEffect(()=>{typeof k=="function"?k($.current):k&&(k.current=$.current)},[k]);const L=h=>{const x=h.target.value;p==null||p(x,g.DATE_PICKER)};c.useEffect(()=>{if(N.current)try{setTimeout(()=>{D()},100)}catch{}},[]);const D=()=>{if(N.current)try{N.current.showPicker()}catch{}},A=h=>{h.stopPropagation()};return C?u.jsx("div",{ref:$,id:l,style:{top:(o==null?void 0:o.top)||0,left:(o==null?void 0:o.left)||0},className:"cosmic-ai-input-datePicker",suppressHydrationWarning:!0,children:u.jsx("input",{ref:N,type:"date",value:r||"",onChange:L,onClick:A})}):null});Te.displayName="DatePicker";function oe(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 H(r){if(r&&r.getAttribute("data-set-type")==="input"){const o=r.children[0];o.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{o.focus()})}}function me(r){r&&r.getAttribute("data-set-type")==="input"&&r.children[0].setAttribute("contenteditable","false")}function O(r){return r&&(r!=null&&r.getAttribute)?r.getAttribute("data-set-type")==="input":!1}const De=c.forwardRef(({options:r,value:o,position:l,id:p,height:k=37,onChange:C},E)=>{const[$,N]=c.useState(o||""),L=c.useRef(null);c.useEffect(()=>{typeof E=="function"?E(L.current):E&&(E.current=L.current)},[E]);const D=h=>{const x=$.split(",").filter(y=>y)||[];let b="";x.includes(h)?b=x.filter(y=>y!==h).join(","):x.length?b=`${x.join(",")},${h}`:b=h,N(b),C==null||C(b,g.MULTIPLE_SELECT)},A=$.split(",")||[];return u.jsx("div",{ref:L,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${k}px`},children:r.map((h,x)=>u.jsx("div",{className:`selectOption ${A.includes(h)?"selected":""}`,onClick:()=>D(h),children:h},x))})});De.displayName="MultipleSelect";const Ne=c.forwardRef(({options:r,value:o,position:l,id:p,height:k=120,onChange:C},E)=>{const[$,N]=c.useState(o||""),L=c.useRef(null);c.useEffect(()=>{typeof E=="function"?E(L.current):E&&(E.current=L.current)},[E]);const D=A=>{N(A),C==null||C(A,g.SELECT)};return u.jsx("div",{ref:L,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${k}px`},children:r.length>0&&r.map((A,h)=>u.jsx("div",{className:`selectOption ${$===A?"selected":""}`,onClick:()=>D(A),children:A},h))})});Ne.displayName="Select";function Le(r){const o=r instanceof Element?r:document.getElementById(r);return o&&o.children[0].textContent||""}function nt(r,o){const l=r instanceof Element?r:document.getElementById(r);l&&(l.children[0].textContent=o)}function Q(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 ae(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 st(){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 rt(){const r=window.getSelection();return!r||r.rangeCount===0?null:r.getRangeAt(0).getBoundingClientRect()}function it(){return new Promise(r=>{requestAnimationFrame(()=>{r(rt())})})}function lt(){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 ct(){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 ot(r){return r&&!r.getAttribute("data-set-type")}function Se(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}const ke=c.forwardRef(({options:r,value:o,position:l,id:p,height:k=120,onChange:C},E)=>{const[$,N]=c.useState(o||""),[L,D]=c.useState(0),A=c.useRef(null),h=c.useRef(L),x=c.useCallback(b=>{N(b),C==null||C(b,g.LABEL)},[C]);return c.useEffect(()=>{typeof E=="function"?E(A.current):E&&(E.current=A.current)},[E]),c.useEffect(()=>{h.current=L},[L]),c.useEffect(()=>{D(0)},[r]),c.useEffect(()=>{const b=y=>{r.length!==0&&(y.key==="ArrowDown"?(y.preventDefault(),D(R=>R<r.length-1?R+1:R)):y.key==="ArrowUp"?(y.preventDefault(),D(R=>R>0?R-1:R)):y.key==="Enter"&&(y.preventDefault(),setTimeout(()=>{const R=h.current;R>=0&&r[R]&&x(r[R])},0)))};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b)}},[r,x]),u.jsx("div",{ref:A,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${k}px`},children:r.length>0&&r.map((b,y)=>u.jsx("div",{className:`selectOption ${$===b?"selected":""} ${L===y?"highlighted":""}`,onClick:()=>x(b),onMouseEnter:()=>D(y),children:b},y))})});ke.displayName="Mention";const Pe=c.forwardRef((r,o)=>{const{value:l="",varList:p,placeholder:k="",maxLength:C,defaultRows:E=3,disabled:$=!1,defaultFocus:N=!1,textIndex:L=0,mentions:D=[],onFocus:A,onBlur:h,onChange:x,onClick:b,onSend:y,onKeyDown:R,onKeyUp:q,onMaxLengthExceeded:Z}=r,[at,dt]=c.useState(l||""),[I,Y]=c.useState(""),[ut,de]=c.useState(""),[_,B]=c.useState(!1),[U,v]=c.useState({top:0,left:0}),[ee,te]=c.useState([]),[W,ue]=c.useState(""),[w,ne]=c.useState(null),[se,z]=c.useState(120),[fe,pe]=c.useState(N),he=240,ge=240,Ee=240,ye=276,m=c.useRef(null),S=c.useRef(null),j=c.useRef(null),re=c.useRef(!1),V=()=>{var s,e;let n=((e=(s=m.current)==null?void 0:s.innerText)==null?void 0:e.replace(/\u200B/g,""))||"";return n===`
3
- `&&(n=""),n},xe=()=>{var s;let n=((s=m.current)==null?void 0:s.innerHTML)||"";return n==="<br>"&&(n=""),n},$e=n=>{const s=[];let e=0;const i=/\[([^\]]+)\]/g;let a;const d=Se();let f=0;if(n===""||!n||n===`
4
- `)return[{type:"text",content:"​",id:`text-${f++}-${d}`}];const P=new Set((p||[]).map(T=>T.name));for(;(a=i.exec(n))!==null;){if(a.index>e){const M=n.substring(e,a.index).split(`
5
- `);M.forEach((J,et)=>{J&&s.push({type:"text",content:J,id:`text-${f++}-${d}`}),et<M.length-1&&s.push({type:"newline",id:`newline-${f++}-${d}`})})}const T=a[1];if(P.has(T)){const t=p.find(M=>M.name===T);(t==null?void 0:t.type)==="input"?s.push({type:"input",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||T,id:`input-${f++}-${d}`}):(t==null?void 0:t.type)==="label"?s.push({type:"label",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",id:`label-${f++}-${d}`}):(t==null?void 0:t.type)==="select"?s.push({type:"select",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||T,options:(t==null?void 0:t.options)||[],id:`select-${f++}-${d}`}):(t==null?void 0:t.type)==="multiple-select"?s.push({type:"multiple-select",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||T,options:(t==null?void 0:t.options)||[],id:`multiple-select-${f++}-${d}`}):(t==null?void 0:t.type)==="date-picker"&&s.push({type:"date-picker",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||T,id:`date-picker-${f++}-${d}`})}else s.push({type:"text",content:`[${T}]`,id:`text-${f++}-${d}`});e=i.lastIndex}if(e<n.length){const t=n.substring(e).split(`
6
- `);t.forEach((M,J)=>{M&&s.push({type:"text",content:M,id:`text-${f++}`}),J<t.length-1&&s.push({type:"newline",id:`newline-${f++}`})})}return s},ie=()=>{var n;(n=m.current)==null||n.setAttribute("contenteditable","true"),S.current&&(O(S.current)&&S.current.children[0].setAttribute("contenteditable","false"),S.current=null),F(m.current)},je=n=>{b==null||b(n)},Me=n=>{ie()},K=n=>{Y(V()),de(xe()),x==null||x(V()),Qe(n)},Be=n=>{var s;if(!re.current&&n.code==="Enter"&&!n.shiftKey){n.preventDefault();const e=V();if(e.length===0||(s=m.current)!=null&&s.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/))return;C?e.length<=C?y==null||y(e):Z==null||Z(e,C):y==null||y(e)}},He=n=>{var e;if(_&&(w==null?void 0:w.type)===g.LABEL&&(n.code==="ArrowUp"||n.code==="ArrowDown"||n.code==="Enter")){n.preventDefault();return}B(!1),R==null||R(n);const s=st();if(s&&ot(s)){if(n.code==="ArrowLeft"){const i=s==null?void 0:s.previousElementSibling,a=ae(s);i&&a===0&&O(i)&&i.children[0]&&(S.current=i,H(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(n.code==="ArrowRight"){const i=s==null?void 0:s.nextElementSibling,a=ae(s);i&&a===((e=s.textContent)==null?void 0:e.length)&&O(i)&&i.children[0]&&(S.current=i,H(i),requestAnimationFrame(()=>{Q(i.children[0])}))}n.code==="Backspace"&&(s.innerHTML==="​"&&n.preventDefault(),s.innerHTML==="<br>"&&(n.preventDefault(),s.innerHTML="​"))}if(s&&s.getAttribute("data-set-type")==="container"){if(n.code==="ArrowLeft"){const i=lt();O(i)&&i.children[0]&&(S.current=i,H(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(n.code==="ArrowRight"){const i=ct();O(i)&&i.children[0]&&(S.current=i,H(i),requestAnimationFrame(()=>{Q(i.children[0])}))}}Be(n)},Fe=n=>{if(_&&(w==null?void 0:w.type)===g.LABEL&&(n.code==="ArrowUp"||n.code==="ArrowDown"||n.code==="Enter")){n.preventDefault();return}q==null||q(n)},Oe=n=>{n.preventDefault();const e=window.getSelection().toString();if(!e)return;const i=e,a=e;n.clipboardData.setData("text/plain",i),n.clipboardData.setData("text/html",a)},qe=n=>{A==null||A(n)},Ve=()=>{re.current=!0},_e=()=>{re.current=!1},ve=(n,s)=>{s.stopPropagation()},Ke=(n,s)=>{var i;s.stopPropagation(),S.current&&me(S.current),(i=m.current)==null||i.setAttribute("contenteditable","false");const e=document.getElementById(n.id);S.current=e,requestAnimationFrame(()=>{H(e)})},Ue=(n,s)=>{var a,d,f,P,T;R==null||R(s),s.stopPropagation();const e=s.target,i=ae(e);if(s.code==="Backspace"&&i===0){const t=(a=e.parentElement)==null?void 0:a.previousElementSibling;t&&(O(t)&&t.children[0]&&((d=t.children[0].textContent)!=null&&d.length)?(S.current=t,H(t),F(t.children[0]),requestAnimationFrame(()=>{oe(t.children[0])})):(ie(),F(t)))}if(s.code==="ArrowRight"&&i===((f=e.textContent)==null?void 0:f.length)){const t=(P=e.parentElement)==null?void 0:P.nextElementSibling;t&&(O(t)&&t.children[0]&&((T=t.children[0].textContent)!=null&&T.length)?(S.current=t,H(t),Q(t.children[0]),requestAnimationFrame(()=>{oe(t.children[0])})):(ie(),Q(t)))}s.code==="Enter"&&s.shiftKey&&s.preventDefault()},We=(n,s)=>{q==null||q(s);const e=s.target;oe(e)},ze=(n,s)=>{var i;s.stopPropagation(),S.current&&me(S.current),(i=m.current)==null||i.setAttribute("contenteditable","false");const e=document.getElementById(n.id);S.current=e,requestAnimationFrame(()=>{H(e)})},Xe=(n,s)=>{Y(V()),de(xe()),x==null||x(V())},Ge=(n,s)=>{};c.useEffect(()=>{if(!_)return;const n=i=>{j.current&&!j.current.contains(i.target)&&B(!1)},s=i=>{j.current&&!j.current.contains(i.target)&&B(!1)},e=()=>{B(!1)};return document.addEventListener("mousedown",n),document.addEventListener("scroll",s,!0),window.addEventListener("resize",e),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("scroll",s,!0),window.removeEventListener("resize",e)}},[_]);const X=(n,s)=>{if(w&&s!==g.LABEL&&nt(w.id,n),s===g.SELECT&&(B(!1),K({})),s===g.LABEL&&(ce(),B(!1),requestAnimationFrame(()=>{const e=window.getSelection();e&&G.current&&(e.removeAllRanges(),e.addRange(G.current),setTimeout(()=>{var f;const i=document.createElement("span");i.contentEditable="false",i.setAttribute("data-set-type","label"),i.id=w.id;const a=document.createElement("span");a.contentEditable="false",a.textContent=n,i.appendChild(a);const d=(f=m.current)==null?void 0:f.children;if((d==null?void 0:d.length)===1&&d[0].tagName==="SPAN"&&d[0].innerHTML==="​[")m.current.innerHTML="",m.current.appendChild(i),setTimeout(()=>{K({}),ce()},0);else{document.execCommand("delete",!1,void 0);const P=G.current;P.insertNode(i),P.setStartAfter(i),P.setEndAfter(i),e.removeAllRanges(),e.addRange(P),setTimeout(()=>{K({})},0)}},0))})),s===g.MULTIPLE_SELECT||s===g.DATE_PICKER){const e=document.getElementById(w.id);e&&e.children[0]&&e.children[1]&&(n.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({})}},G=c.useRef(null),Je=(D==null?void 0:D.map(n=>n.prefix))||[],Qe=n=>{const s=n==null?void 0:n.nativeEvent,e=s==null?void 0:s.data;Je.includes(e)&&it().then(i=>{var d;const a=window.getSelection();a&&a.rangeCount>0&&(G.current=a.getRangeAt(0)),Ze({options:((d=D.find(f=>f.prefix===e))==null?void 0:d.options)||[],value:"",type:g.LABEL,id:"label-"+Se()},i)})},Ze=(n,s)=>{te(n.options),v({top:-999999,left:-999999999}),ne(n),z(ge),B(!0),requestAnimationFrame(()=>{if(j.current){const e=j.current.getBoundingClientRect();let i=s.left,a=s.top+s.height;window.innerWidth-s.right<he&&s.width<e.width&&(i=s.right-e.width),s.top<e.height&&(a=s.top+s.height),v({top:a,left:i}),z(e.height)}})},be=(n,s)=>{const i=s.target.getBoundingClientRect();te(n.options),ue(n.value||Le(n.id)),v({top:-999999,left:-999999999}),ne(n),z(ge),B(!0),requestAnimationFrame(()=>{if(j.current){const a=j.current.getBoundingClientRect();let d=i.left,f=i.top+i.height;window.innerWidth-i.right<he&&i.width<a.width&&(d=i.right-a.width),i.top<a.height&&(f=i.top+i.height),v({top:f,left:d}),z(a.height)}})},Ie=(n,s)=>{const i=s.target.getBoundingClientRect();let a=i.left,d=i.top-ye;window.innerWidth-i.right<Ee&&(a=a-Ee+i.width),i.top<ye&&(d=i.top+i.height),te(n.options),ue(n.value||Le(n.id)),v({top:d,left:a}),ne(n),B(!0)},[Ye,we]=c.useState([]),[le,Ce]=c.useState(!0),Ae=c.useCallback(()=>{Ce(!1);const n=$e(l),s=[];return n.forEach(e=>{var i,a,d,f,P,T;if(e.type==="text")s.push(u.jsx("span",{onKeyDown:t=>Ge(),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:t=>Xe(),onClick:t=>ve(e,t),onMouseDown:t=>Ke(e,t),"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:t=>Ue(e,t),onKeyUp:t=>We(e,t),children:e.content}),u.jsx("span",{contentEditable:!1,style:{display:(a=e.content)!=null&&a.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:t=>ze(e,t),children:e.placeholder})]},e.id));else if(e.type===g.SELECT){const t=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:M=>be(e,M),"data-cosmic-ai-input-placeholder":e.placeholder,children:u.jsx("span",{contentEditable:!1,children:t})},e.id))}else if(e.type===g.MULTIPLE_SELECT){const t=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:M=>be(e,M),"data-cosmic-ai-input-placeholder":e.placeholder,children:[u.jsx("span",{style:{display:t!=null&&t.length?"inline":"none"},contentEditable:!1,children:t}),u.jsx("span",{style:{display:t!=null&&t.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:t=>Ie(e,t),"data-cosmic-ai-input-placeholder":e.placeholder,children:[u.jsx("span",{style:{display:(P=e.content)!=null&&P.length?"inline":"none"},contentEditable:!1,children:e.content}),u.jsx("span",{style:{display:(T=e.content)!=null&&T.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:e.placeholder})]},e.id))}),setTimeout(()=>{Ce(!0)},0),s},[l]);c.useEffect(()=>{le&&setTimeout(()=>{F(m.current)},0)},[le]),c.useEffect(()=>{l!==I?(we(Ae()),Y(l),pe(!0)):(l===""||!l)&&we(Ae())},[l,I]),c.useEffect(()=>{if(!N&&!fe)return;const n=new MutationObserver(()=>{m.current&&document.contains(m.current)&&(requestAnimationFrame(()=>{F(m.current),pe(!1)}),n.disconnect())});return m.current&&n.observe(document.body,{childList:!0,subtree:!0}),()=>n.disconnect()},[N,fe]);const ce=()=>{m.current&&requestAnimationFrame(()=>{F(m.current)})};return c.useImperativeHandle(o,()=>({getCurrentValue:V,focus:ce})),u.jsxs("div",{className:Re(`cosmic-ai-input-rows${E}`),style:{textIndent:L+"px"},children:[le&&u.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":k,className:Re("cosmic-ai-input",`cosmic-ai-input-rows${E}`,{"is-disabled":$},{"is-empty":I.length===0}),ref:m,contentEditable:!0,suppressContentEditableWarning:!0,onClick:n=>je(n),onFocus:n=>{qe(n)},onBlur:n=>{h==null||h(n)},onMouseDown:n=>Me(),onKeyDown:n=>He(n),onKeyUp:n=>Fe(n),onInput:n=>K(n),onCopy:n=>Oe(n),onCompositionStart:Ve,onCompositionEnd:_e,children:Ye}),_&&tt.createPortal((w==null?void 0:w.type)===g.MULTIPLE_SELECT?u.jsx(De,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.MULTIPLE_SELECT):(w==null?void 0:w.type)===g.DATE_PICKER?u.jsx(Te,{ref:j,value:W,position:U,onChange:X},g.DATE_PICKER):(w==null?void 0:w.type)===g.LABEL?u.jsx(ke,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.LABEL):u.jsx(Ne,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.SELECT),document.body)]})});Pe.displayName="AiInput";exports.default=Pe;
1
+ // Generated at: 2026-03-19T09:31:11.242Z
2
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("react/jsx-runtime"),c=require("react"),me=require("classnames"),nt=require("react-dom");var g=(i=>(i.INPUT="input",i.SELECT="select",i.MULTIPLE_SELECT="multiple-select",i.DATE_PICKER="date-picker",i.LABEL="label",i))(g||{});const Te=c.forwardRef(({value:i,position:o,id:l,onChange:p},k)=>{const[C,E]=c.useState(!0),$=c.useRef(null),N=c.useRef(null);c.useEffect(()=>{typeof k=="function"?k($.current):k&&(k.current=$.current)},[k]);const L=h=>{const x=h.target.value;p==null||p(x,g.DATE_PICKER)};c.useEffect(()=>{if(N.current)try{setTimeout(()=>{D()},100)}catch{}},[]);const D=()=>{if(N.current)try{N.current.showPicker()}catch{}},A=h=>{h.stopPropagation()};return C?u.jsx("div",{ref:$,id:l,style:{top:(o==null?void 0:o.top)||0,left:(o==null?void 0:o.left)||0},className:"cosmic-ai-input-datePicker",suppressHydrationWarning:!0,children:u.jsx("input",{ref:N,type:"date",value:i||"",onChange:L,onClick:A})}):null});Te.displayName="DatePicker";function oe(i){const o=i.textContent||"",l=i.nextSibling;o.length?(l==null||l.setAttribute("style","display: none"),i.style.padding="2px 4px",i.style.borderTopLeftRadius="2px",i.style.borderBottomLeftRadius="2px",i.style.borderTopRightRadius="2px",i.style.borderBottomRightRadius="2px"):(l==null||l.setAttribute("style","display: inline"),i.style.padding="2px 0 2px 4px",i.style.borderTopLeftRadius="2px",i.style.borderBottomLeftRadius="2px",i.style.borderTopRightRadius="0",i.style.borderBottomRightRadius="0")}function H(i){if(i&&i.getAttribute("data-set-type")==="input"){const o=i.children[0];o.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{o.focus()})}}function Re(i){i&&i.getAttribute("data-set-type")==="input"&&i.children[0].setAttribute("contenteditable","false")}function F(i){return i&&(i!=null&&i.getAttribute)?i.getAttribute("data-set-type")==="input":!1}const De=c.forwardRef(({options:i,value:o,position:l,id:p,height:k=37,onChange:C},E)=>{const[$,N]=c.useState(o||""),L=c.useRef(null);c.useEffect(()=>{typeof E=="function"?E(L.current):E&&(E.current=L.current)},[E]);const D=h=>{const x=$.split(",").filter(y=>y)||[];let b="";x.includes(h)?b=x.filter(y=>y!==h).join(","):x.length?b=`${x.join(",")},${h}`:b=h,N(b),C==null||C(b,g.MULTIPLE_SELECT)},A=$.split(",")||[];return u.jsx("div",{ref:L,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${k}px`},children:i.map((h,x)=>u.jsx("div",{className:`selectOption ${A.includes(h)?"selected":""}`,onClick:()=>D(h),children:h},x))})});De.displayName="MultipleSelect";const Ne=c.forwardRef(({options:i,value:o,position:l,id:p,height:k=120,onChange:C},E)=>{const[$,N]=c.useState(o||""),L=c.useRef(null);c.useEffect(()=>{typeof E=="function"?E(L.current):E&&(E.current=L.current)},[E]);const D=A=>{N(A),C==null||C(A,g.SELECT)};return u.jsx("div",{ref:L,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${k}px`},children:i.length>0&&i.map((A,h)=>u.jsx("div",{className:`selectOption ${$===A?"selected":""}`,onClick:()=>D(A),children:A},h))})});Ne.displayName="Select";function Le(i){const o=i instanceof Element?i:document.getElementById(i);return o&&o.children[0].textContent||""}function st(i,o){const l=i instanceof Element?i:document.getElementById(i);l&&(l.children[0].textContent=o)}function Q(i){const o=document.createRange(),l=window.getSelection();l&&(!i||!(i instanceof Node)||(o.selectNodeContents(i),o.collapse(!0),l.removeAllRanges(),l.addRange(o)))}function O(i){const o=document.createRange(),l=window.getSelection();l&&(!i||!(i instanceof Node)||(o.selectNodeContents(i),o.collapse(!1),l.removeAllRanges(),l.addRange(o)))}function ae(i){const o=window.getSelection();if(!o||o.rangeCount===0)return 0;if(!i||!(i instanceof Node))return;const l=o.getRangeAt(0),p=l.cloneRange();return p.selectNodeContents(i),p.setEnd(l.startContainer,l.startOffset),p.toString().length}function it(){const i=window.getSelection();if(!i||i.rangeCount===0)return null;const l=i.getRangeAt(0).startContainer;return l.nodeType===Node.TEXT_NODE?l.parentElement:l.nodeType===Node.ELEMENT_NODE?l:null}function rt(){const i=window.getSelection();return!i||i.rangeCount===0?null:i.getRangeAt(0).getBoundingClientRect()}function lt(){return new Promise(i=>{requestAnimationFrame(()=>{i(rt())})})}function ct(){const i=window.getSelection();if(!i||i.rangeCount===0)return null;const o=i.getRangeAt(0),l=o.startContainer,p=o.startOffset;return l.nodeType===Node.TEXT_NODE?p>0?l:l.previousSibling:l.nodeType===Node.ELEMENT_NODE?p>0?l.childNodes[p-1]:l.previousSibling:null}function ot(){const i=window.getSelection();if(!i||i.rangeCount===0)return null;const o=i.getRangeAt(0),l=o.startContainer,p=o.startOffset;return l.nodeType===Node.TEXT_NODE?p<l.length?l:l.nextSibling:l.nodeType===Node.ELEMENT_NODE?p<l.childNodes.length?l.childNodes[p]:l.nextSibling:null}function at(i){return i&&!i.getAttribute("data-set-type")}function Se(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}const ke=c.forwardRef(({options:i,value:o,position:l,id:p,height:k=120,onChange:C},E)=>{const[$,N]=c.useState(o||""),[L,D]=c.useState(0),A=c.useRef(null),h=c.useRef(L),x=c.useCallback(b=>{N(b),C==null||C(b,g.LABEL)},[C]);return c.useEffect(()=>{typeof E=="function"?E(A.current):E&&(E.current=A.current)},[E]),c.useEffect(()=>{h.current=L},[L]),c.useEffect(()=>{D(0)},[i]),c.useEffect(()=>{const b=y=>{i.length!==0&&(y.key==="ArrowDown"?(y.preventDefault(),D(m=>m<i.length-1?m+1:m)):y.key==="ArrowUp"?(y.preventDefault(),D(m=>m>0?m-1:m)):y.key==="Enter"&&(y.preventDefault(),setTimeout(()=>{const m=h.current;m>=0&&i[m]&&x(i[m])},0)))};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b)}},[i,x]),u.jsx("div",{ref:A,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(l==null?void 0:l.top)||0,left:(l==null?void 0:l.left)||0,zIndex:5e3,maxHeight:`${k}px`},children:i.length>0&&i.map((b,y)=>u.jsx("div",{className:`selectOption ${$===b?"selected":""} ${L===y?"highlighted":""}`,onClick:()=>x(b),onMouseEnter:()=>D(y),children:b},y))})});ke.displayName="Mention";const Pe=c.forwardRef((i,o)=>{const{value:l="",varList:p,placeholder:k="",maxLength:C,defaultRows:E=3,disabled:$=!1,defaultFocus:N=!1,textIndex:L=0,mentions:D=[],onFocus:A,onBlur:h,onChange:x,onClick:b,onSend:y,onKeyDown:m,onKeyUp:q,onMaxLengthExceeded:Z}=i,[dt,ut]=c.useState(l||""),[I,Y]=c.useState(""),[ft,de]=c.useState(""),[V,B]=c.useState(!1),[U,_]=c.useState({top:0,left:0}),[ee,te]=c.useState([]),[W,ue]=c.useState(""),[w,ne]=c.useState(null),[se,z]=c.useState(120),[fe,pe]=c.useState(N),he=240,ge=240,Ee=240,ye=276,R=c.useRef(null),S=c.useRef(null),j=c.useRef(null),ie=c.useRef(!1),v=()=>{var s,t;let e=((t=(s=R.current)==null?void 0:s.innerText)==null?void 0:t.replace(/\u200B/g,""))||"";return e===`
3
+ `&&(e=""),e},xe=()=>{var s;let e=((s=R.current)==null?void 0:s.innerHTML)||"";return e==="<br>"&&(e=""),e},$e=e=>{const s=[];let t=0;const r=/\[([^\]]+)\]/g;let a;const d=Se();let f=0;if(e===""||!e||e===`
4
+ `)return[{type:"text",content:"​",id:`text-${f++}-${d}`}];const P=new Set((p||[]).map(T=>T.name));for(;(a=r.exec(e))!==null;){if(a.index>t){const M=e.substring(t,a.index).split(`
5
+ `);M.forEach((J,tt)=>{J&&s.push({type:"text",content:J,id:`text-${f++}-${d}`}),tt<M.length-1&&s.push({type:"newline",id:`newline-${f++}-${d}`})})}const T=a[1];if(P.has(T)){const n=p.find(M=>M.name===T);(n==null?void 0:n.type)==="input"?s.push({type:"input",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||T,id:`input-${f++}-${d}`}):(n==null?void 0:n.type)==="label"?s.push({type:"label",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",id:`label-${f++}-${d}`}):(n==null?void 0:n.type)==="select"?s.push({type:"select",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||T,options:(n==null?void 0:n.options)||[],id:`select-${f++}-${d}`}):(n==null?void 0:n.type)==="multiple-select"?s.push({type:"multiple-select",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||T,options:(n==null?void 0:n.options)||[],id:`multiple-select-${f++}-${d}`}):(n==null?void 0:n.type)==="date-picker"&&s.push({type:"date-picker",name:n==null?void 0:n.name,content:(n==null?void 0:n.content)||"",placeholder:(n==null?void 0:n.placeholder)||T,id:`date-picker-${f++}-${d}`})}else s.push({type:"text",content:`[${T}]`,id:`text-${f++}-${d}`});t=r.lastIndex}if(t<e.length){const n=e.substring(t).split(`
6
+ `);n.forEach((M,J)=>{M&&s.push({type:"text",content:M,id:`text-${f++}`}),J<n.length-1&&s.push({type:"newline",id:`newline-${f++}`})})}return s},re=()=>{var e;(e=R.current)==null||e.setAttribute("contenteditable","true"),S.current&&(F(S.current)&&S.current.children[0].setAttribute("contenteditable","false"),S.current=null),O(R.current)},je=e=>{b==null||b(e)},Me=e=>{re()},K=e=>{Y(v()),de(xe()),x==null||x(v()),Ze(e)},Be=e=>{var s;if(!ie.current&&e.code==="Enter"&&!e.shiftKey){e.preventDefault();const t=v();if(t.length===0||(s=R.current)!=null&&s.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/))return;C?t.length<=C?y==null||y(t):Z==null||Z(t,C):y==null||y(t)}},He=e=>{var t;if(V&&(w==null?void 0:w.type)===g.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}B(!1),m==null||m(e);const s=it();if(s&&at(s)){if(e.code==="ArrowLeft"){const r=s==null?void 0:s.previousElementSibling,a=ae(s);r&&a===0&&F(r)&&r.children[0]&&(S.current=r,H(r),requestAnimationFrame(()=>{O(r.children[0])}))}if(e.code==="ArrowRight"){const r=s==null?void 0:s.nextElementSibling,a=ae(s);r&&a===((t=s.textContent)==null?void 0:t.length)&&F(r)&&r.children[0]&&(S.current=r,H(r),requestAnimationFrame(()=>{Q(r.children[0])}))}e.code==="Backspace"&&(s.innerHTML==="​"&&e.preventDefault(),s.innerHTML==="<br>"&&(e.preventDefault(),s.innerHTML="​"))}if(e.code==="Backspace"&&e.target){const r=e.target;if(r.childElementCount===1&&r.children[0].tagName==="SPAN"){const a=r.children[0];r.childNodes.length===1&&(a.innerHTML==="​"&&e.preventDefault(),a.innerHTML==="<br>"&&(e.preventDefault(),a.innerHTML="​"))}}if(s&&s.getAttribute("data-set-type")==="container"){if(e.code==="ArrowLeft"){const r=ct();F(r)&&r.children[0]&&(S.current=r,H(r),requestAnimationFrame(()=>{O(r.children[0])}))}if(e.code==="ArrowRight"){const r=ot();F(r)&&r.children[0]&&(S.current=r,H(r),requestAnimationFrame(()=>{Q(r.children[0])}))}}Be(e)},Oe=e=>{if(V&&(w==null?void 0:w.type)===g.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}q==null||q(e)},Fe=e=>{const t=e.clipboardData.items;for(let r=0;r<t.length;r++)if(t[r].type.indexOf("image")!==-1){e.preventDefault();return}},qe=e=>{e.preventDefault();const t=window.getSelection().toString();if(!t)return;const r=t.replace(/\u200B/g,"")||"",a=t.replace(/\u200B/g,"")||"";e.clipboardData.setData("text/plain",r),e.clipboardData.setData("text/html",a)},ve=e=>{A==null||A(e)},Ve=()=>{ie.current=!0},_e=()=>{ie.current=!1},Ke=(e,s)=>{s.stopPropagation()},Ue=(e,s)=>{var r;s.stopPropagation(),S.current&&Re(S.current),(r=R.current)==null||r.setAttribute("contenteditable","false");const t=document.getElementById(e.id);S.current=t,requestAnimationFrame(()=>{H(t)})},We=(e,s)=>{var a,d,f,P,T;m==null||m(s),s.stopPropagation();const t=s.target,r=ae(t);if(s.code==="Backspace"&&r===0){const n=(a=t.parentElement)==null?void 0:a.previousElementSibling;n&&(F(n)&&n.children[0]&&((d=n.children[0].textContent)!=null&&d.length)?(S.current=n,H(n),O(n.children[0]),requestAnimationFrame(()=>{oe(n.children[0])})):(re(),O(n)))}if(s.code==="ArrowRight"&&r===((f=t.textContent)==null?void 0:f.length)){const n=(P=t.parentElement)==null?void 0:P.nextElementSibling;n&&(F(n)&&n.children[0]&&((T=n.children[0].textContent)!=null&&T.length)?(S.current=n,H(n),Q(n.children[0]),requestAnimationFrame(()=>{oe(n.children[0])})):(re(),Q(n)))}s.code==="Enter"&&s.shiftKey&&s.preventDefault()},ze=(e,s)=>{q==null||q(s);const t=s.target;oe(t)},Xe=(e,s)=>{var r;s.stopPropagation(),S.current&&Re(S.current),(r=R.current)==null||r.setAttribute("contenteditable","false");const t=document.getElementById(e.id);S.current=t,requestAnimationFrame(()=>{H(t)})},Ge=(e,s)=>{Y(v()),de(xe()),x==null||x(v())},Je=(e,s)=>{};c.useEffect(()=>{if(!V)return;const e=r=>{j.current&&!j.current.contains(r.target)&&B(!1)},s=r=>{j.current&&!j.current.contains(r.target)&&B(!1)},t=()=>{B(!1)};return document.addEventListener("mousedown",e),document.addEventListener("scroll",s,!0),window.addEventListener("resize",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",s,!0),window.removeEventListener("resize",t)}},[V]);const X=(e,s)=>{if(w&&s!==g.LABEL&&st(w.id,e),s===g.SELECT&&(B(!1),K({})),s===g.LABEL&&(ce(),B(!1),requestAnimationFrame(()=>{const t=window.getSelection();t&&G.current&&(t.removeAllRanges(),t.addRange(G.current),setTimeout(()=>{var f;const r=document.createElement("span");r.contentEditable="false",r.setAttribute("data-set-type","label"),r.id=w.id;const a=document.createElement("span");a.contentEditable="false",a.textContent=e,r.appendChild(a);const d=(f=R.current)==null?void 0:f.children;if((d==null?void 0:d.length)===1&&d[0].tagName==="SPAN"&&d[0].innerHTML==="​[")R.current.innerHTML="",R.current.appendChild(r),setTimeout(()=>{K({}),ce()},0);else{document.execCommand("delete",!1,void 0);const P=G.current;P.insertNode(r),P.setStartAfter(r),P.setEndAfter(r),t.removeAllRanges(),t.addRange(P),setTimeout(()=>{K({})},0)}},0))})),s===g.MULTIPLE_SELECT||s===g.DATE_PICKER){const t=document.getElementById(w.id);t&&t.children[0]&&t.children[1]&&(e.length>0?(t.children[0].setAttribute("style","display: inline"),t.children[0].setAttribute("contenteditable","false"),t.children[1].setAttribute("style","display: none"),t.children[1].setAttribute("contenteditable","true")):(t.children[0].setAttribute("style","display: none"),t.children[0].setAttribute("contenteditable","true"),t.children[1].setAttribute("style","display: inline"),t.children[1].setAttribute("contenteditable","true"))),K({})}},G=c.useRef(null),Qe=(D==null?void 0:D.map(e=>e.prefix))||[],Ze=e=>{const s=e==null?void 0:e.nativeEvent,t=s==null?void 0:s.data;Qe.includes(t)&&lt().then(r=>{var d;const a=window.getSelection();a&&a.rangeCount>0&&(G.current=a.getRangeAt(0)),Ie({options:((d=D.find(f=>f.prefix===t))==null?void 0:d.options)||[],value:"",type:g.LABEL,id:"label-"+Se()},r)})},Ie=(e,s)=>{te(e.options),_({top:-999999,left:-999999999}),ne(e),z(ge),B(!0),requestAnimationFrame(()=>{if(j.current){const t=j.current.getBoundingClientRect();let r=s.left,a=s.top+s.height;window.innerWidth-s.right<he&&s.width<t.width&&(r=s.right-t.width),s.top<t.height&&(a=s.top+s.height),_({top:a,left:r}),z(t.height)}})},be=(e,s)=>{const r=s.target.getBoundingClientRect();te(e.options),ue(e.value||Le(e.id)),_({top:-999999,left:-999999999}),ne(e),z(ge),B(!0),requestAnimationFrame(()=>{if(j.current){const a=j.current.getBoundingClientRect();let d=r.left,f=r.top+r.height;window.innerWidth-r.right<he&&r.width<a.width&&(d=r.right-a.width),r.top<a.height&&(f=r.top+r.height),_({top:f,left:d}),z(a.height)}})},Ye=(e,s)=>{const r=s.target.getBoundingClientRect();let a=r.left,d=r.top-ye;window.innerWidth-r.right<Ee&&(a=a-Ee+r.width),r.top<ye&&(d=r.top+r.height),te(e.options),ue(e.value||Le(e.id)),_({top:d,left:a}),ne(e),B(!0)},[et,we]=c.useState([]),[le,Ce]=c.useState(!0),Ae=c.useCallback(()=>{Ce(!1);const e=$e(l),s=[];return e.forEach(t=>{var r,a,d,f,P,T;if(t.type==="text")s.push(u.jsx("span",{onKeyDown:n=>Je(),children:t.content},t.id));else if(t.type==="newline")s.push(u.jsx("br",{},t.id));else if(t.type==="label")s.push(u.jsx("span",{id:t.id,"data-set-type":"label",contentEditable:!1,children:u.jsx("span",{contentEditable:!1,children:t.name})},t.id));else if(t.type==="input")s.push(u.jsxs("span",{id:t.id,"data-set-type":"input",contentEditable:!1,suppressContentEditableWarning:!0,onInput:n=>Ge(),onClick:n=>Ke(t,n),onMouseDown:n=>Ue(t,n),"data-cosmic-ai-input-placeholder":t.placeholder,children:[u.jsx("span",{className:"cosmic-ai-input-inputContent",style:{padding:(r=t.content)!=null&&r.length?"2px 4px":"2px 0 2px 4px"},contentEditable:!1,onKeyDown:n=>We(t,n),onKeyUp:n=>ze(t,n),children:t.content}),u.jsx("span",{contentEditable:!1,style:{display:(a=t.content)!=null&&a.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:n=>Xe(t,n),children:t.placeholder})]},t.id));else if(t.type===g.SELECT){const n=t.content||((d=t.options)==null?void 0:d[0])||t.placeholder;s.push(u.jsx("span",{id:t.id,"data-set-type":"select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:M=>be(t,M),"data-cosmic-ai-input-placeholder":t.placeholder,children:u.jsx("span",{contentEditable:!1,children:n})},t.id))}else if(t.type===g.MULTIPLE_SELECT){const n=t.content||((f=t.options)==null?void 0:f[0]);s.push(u.jsxs("span",{id:t.id,"data-set-type":"multiple-select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:M=>be(t,M),"data-cosmic-ai-input-placeholder":t.placeholder,children:[u.jsx("span",{style:{display:n!=null&&n.length?"inline":"none"},contentEditable:!1,children:n}),u.jsx("span",{style:{display:n!=null&&n.length?"none":"inline"},className:"cosmic-ai-input-selectPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}else t.type===g.DATE_PICKER&&s.push(u.jsxs("span",{id:t.id,"data-set-type":"date-picker",contentEditable:!1,suppressContentEditableWarning:!0,onClick:n=>Ye(t,n),"data-cosmic-ai-input-placeholder":t.placeholder,children:[u.jsx("span",{style:{display:(P=t.content)!=null&&P.length?"inline":"none"},contentEditable:!1,children:t.content}),u.jsx("span",{style:{display:(T=t.content)!=null&&T.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}),setTimeout(()=>{Ce(!0)},0),s},[l]);c.useEffect(()=>{le&&setTimeout(()=>{O(R.current)},0)},[le]),c.useEffect(()=>{l!==I?(we(Ae()),Y(l),pe(!0)):(l===""||!l)&&we(Ae())},[l,I]),c.useEffect(()=>{if(!N&&!fe)return;const e=new MutationObserver(()=>{R.current&&document.contains(R.current)&&(requestAnimationFrame(()=>{O(R.current),pe(!1)}),e.disconnect())});return R.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[N,fe]);const ce=()=>{R.current&&requestAnimationFrame(()=>{O(R.current)})};return c.useImperativeHandle(o,()=>({getCurrentValue:v,focus:ce})),u.jsxs("div",{className:me(`cosmic-ai-input-rows${E}`),style:{textIndent:L+"px"},children:[le&&u.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":k,className:me("cosmic-ai-input",`cosmic-ai-input-rows${E}`,{"is-disabled":$},{"is-empty":I.length===0}),ref:R,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>je(e),onFocus:e=>{ve(e)},onBlur:e=>{h==null||h(e)},onMouseDown:e=>Me(),onKeyDown:e=>He(e),onKeyUp:e=>Oe(e),onInput:e=>K(e),onCopy:e=>qe(e),onPaste:e=>Fe(e),onCompositionStart:Ve,onCompositionEnd:_e,children:et}),V&&nt.createPortal((w==null?void 0:w.type)===g.MULTIPLE_SELECT?u.jsx(De,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.MULTIPLE_SELECT):(w==null?void 0:w.type)===g.DATE_PICKER?u.jsx(Te,{ref:j,value:W,position:U,onChange:X},g.DATE_PICKER):(w==null?void 0:w.type)===g.LABEL?u.jsx(ke,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.LABEL):u.jsx(Ne,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.SELECT),document.body)]})});Pe.displayName="AiInput";exports.default=Pe;
package/dist/index.es.js CHANGED
@@ -1,12 +1,12 @@
1
- // Generated at: 2026-03-10T07:58:48.343Z
1
+ // Generated at: 2026-03-19T09:31:10.851Z
2
2
  import { jsx as u, jsxs as Y } from "react/jsx-runtime";
3
- import { forwardRef as j, useState as L, useRef as F, useEffect as M, useCallback as Pe, useImperativeHandle as lt } from "react";
4
- import Se from "classnames";
5
- import { createPortal as ot } from "react-dom";
3
+ import { forwardRef as j, useState as L, useRef as O, useEffect as M, useCallback as Pe, useImperativeHandle as ot } from "react";
4
+ import De from "classnames";
5
+ import { createPortal as st } from "react-dom";
6
6
  var h = /* @__PURE__ */ ((r) => (r.INPUT = "input", r.SELECT = "select", r.MULTIPLE_SELECT = "multiple-select", r.DATE_PICKER = "date-picker", r.LABEL = "label", r))(h || {});
7
7
  const $e = j(
8
8
  ({ value: r, position: s, id: o, onChange: f }, k) => {
9
- const [w, g] = L(!0), $ = F(null), D = F(null);
9
+ const [w, g] = L(!0), $ = O(null), N = O(null);
10
10
  M(() => {
11
11
  typeof k == "function" ? k($.current) : k && (k.current = $.current);
12
12
  }, [k]);
@@ -15,18 +15,18 @@ const $e = j(
15
15
  f == null || f(y, h.DATE_PICKER);
16
16
  };
17
17
  M(() => {
18
- if (D.current)
18
+ if (N.current)
19
19
  try {
20
20
  setTimeout(() => {
21
- N();
21
+ S();
22
22
  }, 100);
23
23
  } catch {
24
24
  }
25
25
  }, []);
26
- const N = () => {
27
- if (D.current)
26
+ const S = () => {
27
+ if (N.current)
28
28
  try {
29
- D.current.showPicker();
29
+ N.current.showPicker();
30
30
  } catch {
31
31
  }
32
32
  }, A = (p) => {
@@ -46,7 +46,7 @@ const $e = j(
46
46
  children: /* @__PURE__ */ u(
47
47
  "input",
48
48
  {
49
- ref: D,
49
+ ref: N,
50
50
  type: "date",
51
51
  value: r || "",
52
52
  onChange: T,
@@ -70,10 +70,10 @@ function V(r) {
70
70
  });
71
71
  }
72
72
  }
73
- function Ne(r) {
73
+ function Se(r) {
74
74
  r && r.getAttribute("data-set-type") === "input" && r.children[0].setAttribute("contenteditable", "false");
75
75
  }
76
- function _(r) {
76
+ function v(r) {
77
77
  return r && (r != null && r.getAttribute) ? r.getAttribute("data-set-type") === "input" : !1;
78
78
  }
79
79
  const Be = j(({
@@ -84,14 +84,14 @@ const Be = j(({
84
84
  height: k = 37,
85
85
  onChange: w
86
86
  }, g) => {
87
- const [$, D] = L(s || ""), T = F(null);
87
+ const [$, N] = L(s || ""), T = O(null);
88
88
  M(() => {
89
89
  typeof g == "function" ? g(T.current) : g && (g.current = T.current);
90
90
  }, [g]);
91
- const N = (p) => {
91
+ const S = (p) => {
92
92
  const y = $.split(",").filter((E) => E) || [];
93
93
  let b = "";
94
- y.includes(p) ? b = y.filter((E) => E !== p).join(",") : y.length ? b = `${y.join(",")},${p}` : b = p, D(b), w == null || w(b, h.MULTIPLE_SELECT);
94
+ y.includes(p) ? b = y.filter((E) => E !== p).join(",") : y.length ? b = `${y.join(",")},${p}` : b = p, N(b), w == null || w(b, h.MULTIPLE_SELECT);
95
95
  }, A = $.split(",") || [];
96
96
  return /* @__PURE__ */ u(
97
97
  "div",
@@ -110,7 +110,7 @@ const Be = j(({
110
110
  "div",
111
111
  {
112
112
  className: `selectOption ${A.includes(p) ? "selected" : ""}`,
113
- onClick: () => N(p),
113
+ onClick: () => S(p),
114
114
  children: p
115
115
  },
116
116
  y
@@ -127,12 +127,12 @@ const Me = j(({
127
127
  height: k = 120,
128
128
  onChange: w
129
129
  }, g) => {
130
- const [$, D] = L(s || ""), T = F(null);
130
+ const [$, N] = L(s || ""), T = O(null);
131
131
  M(() => {
132
132
  typeof g == "function" ? g(T.current) : g && (g.current = T.current);
133
133
  }, [g]);
134
- const N = (A) => {
135
- D(A), w == null || w(A, h.SELECT);
134
+ const S = (A) => {
135
+ N(A), w == null || w(A, h.SELECT);
136
136
  };
137
137
  return /* @__PURE__ */ u(
138
138
  "div",
@@ -151,7 +151,7 @@ const Me = j(({
151
151
  "div",
152
152
  {
153
153
  className: `selectOption ${$ === A ? "selected" : ""}`,
154
- onClick: () => N(A),
154
+ onClick: () => S(A),
155
155
  children: A
156
156
  },
157
157
  p
@@ -160,11 +160,11 @@ const Me = j(({
160
160
  );
161
161
  });
162
162
  Me.displayName = "Select";
163
- function De(r) {
163
+ function Ne(r) {
164
164
  const s = r instanceof Element ? r : document.getElementById(r);
165
165
  return s && s.children[0].textContent || "";
166
166
  }
167
- function st(r, s) {
167
+ function ct(r, s) {
168
168
  const o = r instanceof Element ? r : document.getElementById(r);
169
169
  o && (o.children[0].textContent = s);
170
170
  }
@@ -185,37 +185,37 @@ function pe(r) {
185
185
  const o = s.getRangeAt(0), f = o.cloneRange();
186
186
  return f.selectNodeContents(r), f.setEnd(o.startContainer, o.startOffset), f.toString().length;
187
187
  }
188
- function ct() {
188
+ function at() {
189
189
  const r = window.getSelection();
190
190
  if (!r || r.rangeCount === 0)
191
191
  return null;
192
192
  const o = r.getRangeAt(0).startContainer;
193
193
  return o.nodeType === Node.TEXT_NODE ? o.parentElement : o.nodeType === Node.ELEMENT_NODE ? o : null;
194
194
  }
195
- function at() {
195
+ function dt() {
196
196
  const r = window.getSelection();
197
197
  return !r || r.rangeCount === 0 ? null : r.getRangeAt(0).getBoundingClientRect();
198
198
  }
199
- function dt() {
199
+ function ut() {
200
200
  return new Promise((r) => {
201
201
  requestAnimationFrame(() => {
202
- r(at());
202
+ r(dt());
203
203
  });
204
204
  });
205
205
  }
206
- function ut() {
206
+ function ft() {
207
207
  const r = window.getSelection();
208
208
  if (!r || r.rangeCount === 0) return null;
209
209
  const s = r.getRangeAt(0), o = s.startContainer, f = s.startOffset;
210
210
  return o.nodeType === Node.TEXT_NODE ? f > 0 ? o : o.previousSibling : o.nodeType === Node.ELEMENT_NODE ? f > 0 ? o.childNodes[f - 1] : o.previousSibling : null;
211
211
  }
212
- function ft() {
212
+ function pt() {
213
213
  const r = window.getSelection();
214
214
  if (!r || r.rangeCount === 0) return null;
215
215
  const s = r.getRangeAt(0), o = s.startContainer, f = s.startOffset;
216
216
  return o.nodeType === Node.TEXT_NODE ? f < o.length ? o : o.nextSibling : o.nodeType === Node.ELEMENT_NODE ? f < o.childNodes.length ? o.childNodes[f] : o.nextSibling : null;
217
217
  }
218
- function pt(r) {
218
+ function ht(r) {
219
219
  return r && !r.getAttribute("data-set-type");
220
220
  }
221
221
  function ke() {
@@ -229,20 +229,20 @@ const He = j(({
229
229
  height: k = 120,
230
230
  onChange: w
231
231
  }, g) => {
232
- const [$, D] = L(s || ""), [T, N] = L(0), A = F(null), p = F(T), y = Pe((b) => {
233
- D(b), w == null || w(b, h.LABEL);
232
+ const [$, N] = L(s || ""), [T, S] = L(0), A = O(null), p = O(T), y = Pe((b) => {
233
+ N(b), w == null || w(b, h.LABEL);
234
234
  }, [w]);
235
235
  return M(() => {
236
236
  typeof g == "function" ? g(A.current) : g && (g.current = A.current);
237
237
  }, [g]), M(() => {
238
238
  p.current = T;
239
239
  }, [T]), M(() => {
240
- N(0);
240
+ S(0);
241
241
  }, [r]), M(() => {
242
242
  const b = (E) => {
243
- r.length !== 0 && (E.key === "ArrowDown" ? (E.preventDefault(), N((x) => x < r.length - 1 ? x + 1 : x)) : E.key === "ArrowUp" ? (E.preventDefault(), N((x) => x > 0 ? x - 1 : x)) : E.key === "Enter" && (E.preventDefault(), setTimeout(() => {
244
- const x = p.current;
245
- x >= 0 && r[x] && y(r[x]);
243
+ r.length !== 0 && (E.key === "ArrowDown" ? (E.preventDefault(), S((m) => m < r.length - 1 ? m + 1 : m)) : E.key === "ArrowUp" ? (E.preventDefault(), S((m) => m > 0 ? m - 1 : m)) : E.key === "Enter" && (E.preventDefault(), setTimeout(() => {
244
+ const m = p.current;
245
+ m >= 0 && r[m] && y(r[m]);
246
246
  }, 0)));
247
247
  };
248
248
  return document.addEventListener("keydown", b), () => {
@@ -266,7 +266,7 @@ const He = j(({
266
266
  {
267
267
  className: `selectOption ${$ === b ? "selected" : ""} ${T === E ? "highlighted" : ""}`,
268
268
  onClick: () => y(b),
269
- onMouseEnter: () => N(E),
269
+ onMouseEnter: () => S(E),
270
270
  children: b
271
271
  },
272
272
  E
@@ -275,7 +275,7 @@ const He = j(({
275
275
  );
276
276
  });
277
277
  He.displayName = "Mention";
278
- const ht = j((r, s) => {
278
+ const gt = j((r, s) => {
279
279
  const {
280
280
  value: o = "",
281
281
  varList: f,
@@ -283,34 +283,34 @@ const ht = j((r, s) => {
283
283
  maxLength: w,
284
284
  defaultRows: g = 3,
285
285
  disabled: $ = !1,
286
- defaultFocus: D = !1,
286
+ defaultFocus: N = !1,
287
287
  textIndex: T = 0,
288
- mentions: N = [],
288
+ mentions: S = [],
289
289
  onFocus: A,
290
290
  onBlur: p,
291
291
  onChange: y,
292
292
  onClick: b,
293
293
  onSend: E,
294
- onKeyDown: x,
295
- onKeyUp: K,
294
+ onKeyDown: m,
295
+ onKeyUp: _,
296
296
  onMaxLengthExceeded: te
297
- } = r, [gt, Et] = L(o || ""), [ne, ie] = L(""), [yt, he] = L(""), [U, O] = L(!1), [X, W] = L({ top: 0, left: 0 }), [re, le] = L([]), [G, ge] = L(""), [C, oe] = L(null), [se, J] = L(120), [Ee, ye] = L(D), be = 240, Ce = 240, we = 240, Ae = 276, m = F(null), R = F(null), B = F(null), ce = F(!1), v = () => {
298
- var i, e;
299
- let n = ((e = (i = m.current) == null ? void 0 : i.innerText) == null ? void 0 : e.replace(/\u200B/g, "")) || "";
300
- return n === `
301
- ` && (n = ""), n;
302
- }, xe = () => {
297
+ } = r, [Et, yt] = L(o || ""), [ne, ie] = L(""), [bt, he] = L(""), [U, F] = L(!1), [X, W] = L({ top: 0, left: 0 }), [re, le] = L([]), [G, ge] = L(""), [C, oe] = L(null), [se, J] = L(120), [Ee, ye] = L(N), be = 240, Ce = 240, we = 240, Ae = 276, x = O(null), R = O(null), B = O(null), ce = O(!1), K = () => {
298
+ var i, t;
299
+ let e = ((t = (i = x.current) == null ? void 0 : i.innerText) == null ? void 0 : t.replace(/\u200B/g, "")) || "";
300
+ return e === `
301
+ ` && (e = ""), e;
302
+ }, me = () => {
303
303
  var i;
304
- let n = ((i = m.current) == null ? void 0 : i.innerHTML) || "";
305
- return n === "<br>" && (n = ""), n;
306
- }, Fe = (n) => {
304
+ let e = ((i = x.current) == null ? void 0 : i.innerHTML) || "";
305
+ return e === "<br>" && (e = ""), e;
306
+ }, Oe = (e) => {
307
307
  const i = [];
308
- let e = 0;
308
+ let t = 0;
309
309
  const l = /\[([^\]]+)\]/g;
310
310
  let c;
311
311
  const a = ke();
312
312
  let d = 0;
313
- if (n === "" || !n || n === `
313
+ if (e === "" || !e || e === `
314
314
  `)
315
315
  return [
316
316
  {
@@ -319,74 +319,74 @@ const ht = j((r, s) => {
319
319
  id: `text-${d++}-${a}`
320
320
  }
321
321
  ];
322
- const P = new Set((f || []).map((S) => S.name));
323
- for (; (c = l.exec(n)) !== null; ) {
324
- if (c.index > e) {
325
- const H = n.substring(e, c.index).split(`
322
+ const P = new Set((f || []).map((D) => D.name));
323
+ for (; (c = l.exec(e)) !== null; ) {
324
+ if (c.index > t) {
325
+ const H = e.substring(t, c.index).split(`
326
326
  `);
327
- H.forEach((I, rt) => {
327
+ H.forEach((I, lt) => {
328
328
  I && i.push({
329
329
  type: "text",
330
330
  content: I,
331
331
  id: `text-${d++}-${a}`
332
- }), rt < H.length - 1 && i.push({
332
+ }), lt < H.length - 1 && i.push({
333
333
  type: "newline",
334
334
  id: `newline-${d++}-${a}`
335
335
  });
336
336
  });
337
337
  }
338
- const S = c[1];
339
- if (P.has(S)) {
340
- const t = f.find((H) => H.name === S);
341
- (t == null ? void 0 : t.type) === "input" ? i.push({
338
+ const D = c[1];
339
+ if (P.has(D)) {
340
+ const n = f.find((H) => H.name === D);
341
+ (n == null ? void 0 : n.type) === "input" ? i.push({
342
342
  type: "input",
343
- name: t == null ? void 0 : t.name,
344
- content: (t == null ? void 0 : t.content) || "",
345
- placeholder: (t == null ? void 0 : t.placeholder) || S,
343
+ name: n == null ? void 0 : n.name,
344
+ content: (n == null ? void 0 : n.content) || "",
345
+ placeholder: (n == null ? void 0 : n.placeholder) || D,
346
346
  id: `input-${d++}-${a}`
347
- }) : (t == null ? void 0 : t.type) === "label" ? i.push({
347
+ }) : (n == null ? void 0 : n.type) === "label" ? i.push({
348
348
  type: "label",
349
- name: t == null ? void 0 : t.name,
350
- content: (t == null ? void 0 : t.content) || "",
349
+ name: n == null ? void 0 : n.name,
350
+ content: (n == null ? void 0 : n.content) || "",
351
351
  id: `label-${d++}-${a}`
352
- }) : (t == null ? void 0 : t.type) === "select" ? i.push({
352
+ }) : (n == null ? void 0 : n.type) === "select" ? i.push({
353
353
  type: "select",
354
- name: t == null ? void 0 : t.name,
355
- content: (t == null ? void 0 : t.content) || "",
356
- placeholder: (t == null ? void 0 : t.placeholder) || S,
357
- options: (t == null ? void 0 : t.options) || [],
354
+ name: n == null ? void 0 : n.name,
355
+ content: (n == null ? void 0 : n.content) || "",
356
+ placeholder: (n == null ? void 0 : n.placeholder) || D,
357
+ options: (n == null ? void 0 : n.options) || [],
358
358
  id: `select-${d++}-${a}`
359
- }) : (t == null ? void 0 : t.type) === "multiple-select" ? i.push({
359
+ }) : (n == null ? void 0 : n.type) === "multiple-select" ? i.push({
360
360
  type: "multiple-select",
361
- name: t == null ? void 0 : t.name,
362
- content: (t == null ? void 0 : t.content) || "",
363
- placeholder: (t == null ? void 0 : t.placeholder) || S,
364
- options: (t == null ? void 0 : t.options) || [],
361
+ name: n == null ? void 0 : n.name,
362
+ content: (n == null ? void 0 : n.content) || "",
363
+ placeholder: (n == null ? void 0 : n.placeholder) || D,
364
+ options: (n == null ? void 0 : n.options) || [],
365
365
  id: `multiple-select-${d++}-${a}`
366
- }) : (t == null ? void 0 : t.type) === "date-picker" && i.push({
366
+ }) : (n == null ? void 0 : n.type) === "date-picker" && i.push({
367
367
  type: "date-picker",
368
- name: t == null ? void 0 : t.name,
369
- content: (t == null ? void 0 : t.content) || "",
370
- placeholder: (t == null ? void 0 : t.placeholder) || S,
368
+ name: n == null ? void 0 : n.name,
369
+ content: (n == null ? void 0 : n.content) || "",
370
+ placeholder: (n == null ? void 0 : n.placeholder) || D,
371
371
  id: `date-picker-${d++}-${a}`
372
372
  });
373
373
  } else
374
374
  i.push({
375
375
  type: "text",
376
- content: `[${S}]`,
376
+ content: `[${D}]`,
377
377
  id: `text-${d++}-${a}`
378
378
  });
379
- e = l.lastIndex;
379
+ t = l.lastIndex;
380
380
  }
381
- if (e < n.length) {
382
- const t = n.substring(e).split(`
381
+ if (t < e.length) {
382
+ const n = e.substring(t).split(`
383
383
  `);
384
- t.forEach((H, I) => {
384
+ n.forEach((H, I) => {
385
385
  H && i.push({
386
386
  type: "text",
387
387
  content: H,
388
388
  id: `text-${d++}`
389
- }), I < t.length - 1 && i.push({
389
+ }), I < n.length - 1 && i.push({
390
390
  type: "newline",
391
391
  id: `newline-${d++}`
392
392
  });
@@ -394,354 +394,368 @@ const ht = j((r, s) => {
394
394
  }
395
395
  return i;
396
396
  }, ae = () => {
397
- var n;
398
- (n = m.current) == null || n.setAttribute("contenteditable", "true"), R.current && (_(R.current) && R.current.children[0].setAttribute(
397
+ var e;
398
+ (e = x.current) == null || e.setAttribute("contenteditable", "true"), R.current && (v(R.current) && R.current.children[0].setAttribute(
399
399
  "contenteditable",
400
400
  "false"
401
- ), R.current = null), q(m.current);
402
- }, Oe = (n) => {
403
- b == null || b(n);
404
- }, Ve = (n) => {
401
+ ), R.current = null), q(x.current);
402
+ }, Fe = (e) => {
403
+ b == null || b(e);
404
+ }, Ve = (e) => {
405
405
  ae();
406
- }, z = (n) => {
407
- ie(v()), he(xe()), y == null || y(v()), et(n);
408
- }, qe = (n) => {
406
+ }, z = (e) => {
407
+ ie(K()), he(me()), y == null || y(K()), tt(e);
408
+ }, qe = (e) => {
409
409
  var i;
410
- if (!ce.current && n.code === "Enter" && !n.shiftKey) {
411
- n.preventDefault();
412
- const e = v();
413
- if (e.length === 0 || (i = m.current) != null && i.innerHTML.match(
410
+ if (!ce.current && e.code === "Enter" && !e.shiftKey) {
411
+ e.preventDefault();
412
+ const t = K();
413
+ if (t.length === 0 || (i = x.current) != null && i.innerHTML.match(
414
414
  /^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/
415
415
  ))
416
416
  return;
417
- w ? e.length <= w ? E == null || E(e) : te == null || te(e, w) : E == null || E(e);
417
+ w ? t.length <= w ? E == null || E(t) : te == null || te(t, w) : E == null || E(t);
418
418
  }
419
- }, _e = (n) => {
420
- var e;
421
- if (U && (C == null ? void 0 : C.type) === h.LABEL && (n.code === "ArrowUp" || n.code === "ArrowDown" || n.code === "Enter")) {
422
- n.preventDefault();
419
+ }, ve = (e) => {
420
+ var t;
421
+ if (U && (C == null ? void 0 : C.type) === h.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
422
+ e.preventDefault();
423
423
  return;
424
424
  }
425
- O(!1), x == null || x(n);
426
- const i = ct();
427
- if (i && pt(i)) {
428
- if (n.code === "ArrowLeft") {
425
+ F(!1), m == null || m(e);
426
+ const i = at();
427
+ if (i && ht(i)) {
428
+ if (e.code === "ArrowLeft") {
429
429
  const l = i == null ? void 0 : i.previousElementSibling, c = pe(i);
430
- l && c === 0 && _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
430
+ l && c === 0 && v(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
431
431
  q(l.children[0]);
432
432
  }));
433
433
  }
434
- if (n.code === "ArrowRight") {
434
+ if (e.code === "ArrowRight") {
435
435
  const l = i == null ? void 0 : i.nextElementSibling, c = pe(i);
436
- l && c === ((e = i.textContent) == null ? void 0 : e.length) && _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
436
+ l && c === ((t = i.textContent) == null ? void 0 : t.length) && v(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
437
437
  ee(l.children[0]);
438
438
  }));
439
439
  }
440
- n.code === "Backspace" && (i.innerHTML === "​" && n.preventDefault(), i.innerHTML === "<br>" && (n.preventDefault(), i.innerHTML = "​"));
440
+ e.code === "Backspace" && (i.innerHTML === "​" && e.preventDefault(), i.innerHTML === "<br>" && (e.preventDefault(), i.innerHTML = "​"));
441
+ }
442
+ if (e.code === "Backspace" && e.target) {
443
+ const l = e.target;
444
+ if (l.childElementCount === 1 && l.children[0].tagName === "SPAN") {
445
+ const c = l.children[0];
446
+ l.childNodes.length === 1 && (c.innerHTML === "​" && e.preventDefault(), c.innerHTML === "<br>" && (e.preventDefault(), c.innerHTML = "​"));
447
+ }
441
448
  }
442
449
  if (i && i.getAttribute("data-set-type") === "container") {
443
- if (n.code === "ArrowLeft") {
444
- const l = ut();
445
- _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
450
+ if (e.code === "ArrowLeft") {
451
+ const l = ft();
452
+ v(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
446
453
  q(l.children[0]);
447
454
  }));
448
455
  }
449
- if (n.code === "ArrowRight") {
450
- const l = ft();
451
- _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
456
+ if (e.code === "ArrowRight") {
457
+ const l = pt();
458
+ v(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
452
459
  ee(l.children[0]);
453
460
  }));
454
461
  }
455
462
  }
456
- qe(n);
457
- }, Ke = (n) => {
458
- if (U && (C == null ? void 0 : C.type) === h.LABEL && (n.code === "ArrowUp" || n.code === "ArrowDown" || n.code === "Enter")) {
459
- n.preventDefault();
463
+ qe(e);
464
+ }, _e = (e) => {
465
+ if (U && (C == null ? void 0 : C.type) === h.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
466
+ e.preventDefault();
460
467
  return;
461
468
  }
462
- K == null || K(n);
463
- }, ve = (n) => {
464
- n.preventDefault();
465
- const e = window.getSelection().toString();
466
- if (!e) return;
467
- const l = e, c = e;
468
- n.clipboardData.setData("text/plain", l), n.clipboardData.setData("text/html", c);
469
- }, Ue = (n) => {
470
- A == null || A(n);
471
- }, We = () => {
472
- ce.current = !0;
469
+ _ == null || _(e);
470
+ }, Ke = (e) => {
471
+ const t = e.clipboardData.items;
472
+ for (let l = 0; l < t.length; l++)
473
+ if (t[l].type.indexOf("image") !== -1) {
474
+ e.preventDefault();
475
+ return;
476
+ }
477
+ }, Ue = (e) => {
478
+ e.preventDefault();
479
+ const t = window.getSelection().toString();
480
+ if (!t) return;
481
+ const l = t.replace(/\u200B/g, "") || "", c = t.replace(/\u200B/g, "") || "";
482
+ e.clipboardData.setData("text/plain", l), e.clipboardData.setData("text/html", c);
483
+ }, We = (e) => {
484
+ A == null || A(e);
473
485
  }, ze = () => {
486
+ ce.current = !0;
487
+ }, je = () => {
474
488
  ce.current = !1;
475
- }, je = (n, i) => {
489
+ }, Xe = (e, i) => {
476
490
  i.stopPropagation();
477
- }, Xe = (n, i) => {
491
+ }, Ge = (e, i) => {
478
492
  var l;
479
- i.stopPropagation(), R.current && Ne(R.current), (l = m.current) == null || l.setAttribute("contenteditable", "false");
480
- const e = document.getElementById(n.id);
481
- R.current = e, requestAnimationFrame(() => {
482
- V(e);
493
+ i.stopPropagation(), R.current && Se(R.current), (l = x.current) == null || l.setAttribute("contenteditable", "false");
494
+ const t = document.getElementById(e.id);
495
+ R.current = t, requestAnimationFrame(() => {
496
+ V(t);
483
497
  });
484
- }, Ge = (n, i) => {
485
- var c, a, d, P, S;
486
- x == null || x(i), i.stopPropagation();
487
- const e = i.target, l = pe(e);
498
+ }, Je = (e, i) => {
499
+ var c, a, d, P, D;
500
+ m == null || m(i), i.stopPropagation();
501
+ const t = i.target, l = pe(t);
488
502
  if (i.code === "Backspace" && l === 0) {
489
- const t = (c = e.parentElement) == null ? void 0 : c.previousElementSibling;
490
- t && (_(t) && t.children[0] && ((a = t.children[0].textContent) != null && a.length) ? (R.current = t, V(t), q(t.children[0]), requestAnimationFrame(() => {
491
- fe(t.children[0]);
492
- })) : (ae(), q(t)));
503
+ const n = (c = t.parentElement) == null ? void 0 : c.previousElementSibling;
504
+ n && (v(n) && n.children[0] && ((a = n.children[0].textContent) != null && a.length) ? (R.current = n, V(n), q(n.children[0]), requestAnimationFrame(() => {
505
+ fe(n.children[0]);
506
+ })) : (ae(), q(n)));
493
507
  }
494
- if (i.code === "ArrowRight" && l === ((d = e.textContent) == null ? void 0 : d.length)) {
495
- const t = (P = e.parentElement) == null ? void 0 : P.nextElementSibling;
496
- t && (_(t) && t.children[0] && ((S = t.children[0].textContent) != null && S.length) ? (R.current = t, V(t), ee(t.children[0]), requestAnimationFrame(() => {
497
- fe(t.children[0]);
498
- })) : (ae(), ee(t)));
508
+ if (i.code === "ArrowRight" && l === ((d = t.textContent) == null ? void 0 : d.length)) {
509
+ const n = (P = t.parentElement) == null ? void 0 : P.nextElementSibling;
510
+ n && (v(n) && n.children[0] && ((D = n.children[0].textContent) != null && D.length) ? (R.current = n, V(n), ee(n.children[0]), requestAnimationFrame(() => {
511
+ fe(n.children[0]);
512
+ })) : (ae(), ee(n)));
499
513
  }
500
514
  i.code === "Enter" && i.shiftKey && i.preventDefault();
501
- }, Je = (n, i) => {
502
- K == null || K(i);
503
- const e = i.target;
504
- fe(e);
505
- }, Qe = (n, i) => {
515
+ }, Qe = (e, i) => {
516
+ _ == null || _(i);
517
+ const t = i.target;
518
+ fe(t);
519
+ }, Ze = (e, i) => {
506
520
  var l;
507
- i.stopPropagation(), R.current && Ne(R.current), (l = m.current) == null || l.setAttribute("contenteditable", "false");
508
- const e = document.getElementById(n.id);
509
- R.current = e, requestAnimationFrame(() => {
510
- V(e);
521
+ i.stopPropagation(), R.current && Se(R.current), (l = x.current) == null || l.setAttribute("contenteditable", "false");
522
+ const t = document.getElementById(e.id);
523
+ R.current = t, requestAnimationFrame(() => {
524
+ V(t);
511
525
  });
512
- }, Ze = (n, i) => {
513
- ie(v()), he(xe()), y == null || y(v());
514
- }, Ie = (n, i) => {
526
+ }, Ie = (e, i) => {
527
+ ie(K()), he(me()), y == null || y(K());
528
+ }, Ye = (e, i) => {
515
529
  };
516
530
  M(() => {
517
531
  if (!U) return;
518
- const n = (l) => {
519
- B.current && !B.current.contains(l.target) && O(!1);
532
+ const e = (l) => {
533
+ B.current && !B.current.contains(l.target) && F(!1);
520
534
  }, i = (l) => {
521
- B.current && !B.current.contains(l.target) && O(!1);
522
- }, e = () => {
523
- O(!1);
535
+ B.current && !B.current.contains(l.target) && F(!1);
536
+ }, t = () => {
537
+ F(!1);
524
538
  };
525
- return document.addEventListener("mousedown", n), document.addEventListener("scroll", i, !0), window.addEventListener("resize", e), () => {
526
- document.removeEventListener("mousedown", n), document.removeEventListener("scroll", i, !0), window.removeEventListener("resize", e);
539
+ return document.addEventListener("mousedown", e), document.addEventListener("scroll", i, !0), window.addEventListener("resize", t), () => {
540
+ document.removeEventListener("mousedown", e), document.removeEventListener("scroll", i, !0), window.removeEventListener("resize", t);
527
541
  };
528
542
  }, [U]);
529
- const Q = (n, i) => {
530
- if (C && i !== h.LABEL && st(C.id, n), i === h.SELECT && (O(!1), z({})), i === h.LABEL && (ue(), O(!1), requestAnimationFrame(() => {
531
- const e = window.getSelection();
532
- e && Z.current && (e.removeAllRanges(), e.addRange(Z.current), setTimeout(() => {
543
+ const Q = (e, i) => {
544
+ if (C && i !== h.LABEL && ct(C.id, e), i === h.SELECT && (F(!1), z({})), i === h.LABEL && (ue(), F(!1), requestAnimationFrame(() => {
545
+ const t = window.getSelection();
546
+ t && Z.current && (t.removeAllRanges(), t.addRange(Z.current), setTimeout(() => {
533
547
  var d;
534
548
  const l = document.createElement("span");
535
549
  l.contentEditable = "false", l.setAttribute("data-set-type", "label"), l.id = C.id;
536
550
  const c = document.createElement("span");
537
- c.contentEditable = "false", c.textContent = n, l.appendChild(c);
538
- const a = (d = m.current) == null ? void 0 : d.children;
551
+ c.contentEditable = "false", c.textContent = e, l.appendChild(c);
552
+ const a = (d = x.current) == null ? void 0 : d.children;
539
553
  if ((a == null ? void 0 : a.length) === 1 && a[0].tagName === "SPAN" && a[0].innerHTML === "​[")
540
- m.current.innerHTML = "", m.current.appendChild(l), setTimeout(() => {
554
+ x.current.innerHTML = "", x.current.appendChild(l), setTimeout(() => {
541
555
  z({}), ue();
542
556
  }, 0);
543
557
  else {
544
558
  document.execCommand("delete", !1, void 0);
545
559
  const P = Z.current;
546
- P.insertNode(l), P.setStartAfter(l), P.setEndAfter(l), e.removeAllRanges(), e.addRange(P), setTimeout(() => {
560
+ P.insertNode(l), P.setStartAfter(l), P.setEndAfter(l), t.removeAllRanges(), t.addRange(P), setTimeout(() => {
547
561
  z({});
548
562
  }, 0);
549
563
  }
550
564
  }, 0));
551
565
  })), i === h.MULTIPLE_SELECT || i === h.DATE_PICKER) {
552
- const e = document.getElementById(
566
+ const t = document.getElementById(
553
567
  C.id
554
568
  );
555
- e && e.children[0] && e.children[1] && (n.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"))), z({});
569
+ 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({});
556
570
  }
557
- }, Z = F(null), Ye = (N == null ? void 0 : N.map((n) => n.prefix)) || [], et = (n) => {
558
- const i = n == null ? void 0 : n.nativeEvent, e = i == null ? void 0 : i.data;
559
- Ye.includes(e) && dt().then((l) => {
571
+ }, Z = O(null), et = (S == null ? void 0 : S.map((e) => e.prefix)) || [], tt = (e) => {
572
+ const i = e == null ? void 0 : e.nativeEvent, t = i == null ? void 0 : i.data;
573
+ et.includes(t) && ut().then((l) => {
560
574
  var a;
561
575
  const c = window.getSelection();
562
- c && c.rangeCount > 0 && (Z.current = c.getRangeAt(0)), tt({
563
- options: ((a = N.find((d) => d.prefix === e)) == null ? void 0 : a.options) || [],
576
+ c && c.rangeCount > 0 && (Z.current = c.getRangeAt(0)), nt({
577
+ options: ((a = S.find((d) => d.prefix === t)) == null ? void 0 : a.options) || [],
564
578
  value: "",
565
579
  type: h.LABEL,
566
580
  id: "label-" + ke()
567
581
  }, l);
568
582
  });
569
- }, tt = (n, i) => {
570
- le(n.options), W({ top: -999999, left: -999999999 }), oe(n), J(Ce), O(!0), requestAnimationFrame(() => {
583
+ }, nt = (e, i) => {
584
+ le(e.options), W({ top: -999999, left: -999999999 }), oe(e), J(Ce), F(!0), requestAnimationFrame(() => {
571
585
  if (B.current) {
572
- const e = B.current.getBoundingClientRect();
586
+ const t = B.current.getBoundingClientRect();
573
587
  let l = i.left, c = i.top + i.height;
574
- window.innerWidth - i.right < be && i.width < e.width && (l = i.right - e.width), i.top < e.height && (c = i.top + i.height), W({ top: c, left: l }), J(e.height);
588
+ window.innerWidth - i.right < be && i.width < t.width && (l = i.right - t.width), i.top < t.height && (c = i.top + i.height), W({ top: c, left: l }), J(t.height);
575
589
  }
576
590
  });
577
- }, me = (n, i) => {
591
+ }, xe = (e, i) => {
578
592
  const l = i.target.getBoundingClientRect();
579
- le(n.options), ge(n.value || De(n.id)), W({ top: -999999, left: -999999999 }), oe(n), J(Ce), O(!0), requestAnimationFrame(() => {
593
+ le(e.options), ge(e.value || Ne(e.id)), W({ top: -999999, left: -999999999 }), oe(e), J(Ce), F(!0), requestAnimationFrame(() => {
580
594
  if (B.current) {
581
595
  const c = B.current.getBoundingClientRect();
582
596
  let a = l.left, d = l.top + l.height;
583
597
  window.innerWidth - l.right < be && l.width < c.width && (a = l.right - c.width), l.top < c.height && (d = l.top + l.height), W({ top: d, left: a }), J(c.height);
584
598
  }
585
599
  });
586
- }, nt = (n, i) => {
600
+ }, it = (e, i) => {
587
601
  const l = i.target.getBoundingClientRect();
588
602
  let c = l.left, a = l.top - Ae;
589
- window.innerWidth - l.right < we && (c = c - we + l.width), l.top < Ae && (a = l.top + l.height), le(n.options), ge(n.value || De(n.id)), W({ top: a, left: c }), oe(n), O(!0);
590
- }, [it, Le] = L([]), [de, Te] = L(!0), Re = Pe(() => {
603
+ window.innerWidth - l.right < we && (c = c - we + l.width), l.top < Ae && (a = l.top + l.height), le(e.options), ge(e.value || Ne(e.id)), W({ top: a, left: c }), oe(e), F(!0);
604
+ }, [rt, Le] = L([]), [de, Te] = L(!0), Re = Pe(() => {
591
605
  Te(!1);
592
- const n = Fe(o), i = [];
593
- return n.forEach((e) => {
594
- var l, c, a, d, P, S;
595
- if (e.type === "text")
606
+ const e = Oe(o), i = [];
607
+ return e.forEach((t) => {
608
+ var l, c, a, d, P, D;
609
+ if (t.type === "text")
596
610
  i.push(
597
- /* @__PURE__ */ u("span", { onKeyDown: (t) => Ie(), children: e.content }, e.id)
611
+ /* @__PURE__ */ u("span", { onKeyDown: (n) => Ye(), children: t.content }, t.id)
598
612
  );
599
- else if (e.type === "newline")
600
- i.push(/* @__PURE__ */ u("br", {}, e.id));
601
- else if (e.type === "label")
613
+ else if (t.type === "newline")
614
+ i.push(/* @__PURE__ */ u("br", {}, t.id));
615
+ else if (t.type === "label")
602
616
  i.push(
603
617
  /* @__PURE__ */ u(
604
618
  "span",
605
619
  {
606
- id: e.id,
620
+ id: t.id,
607
621
  "data-set-type": "label",
608
622
  contentEditable: !1,
609
623
  children: /* @__PURE__ */ u(
610
624
  "span",
611
625
  {
612
626
  contentEditable: !1,
613
- children: e.name
627
+ children: t.name
614
628
  }
615
629
  )
616
630
  },
617
- e.id
631
+ t.id
618
632
  )
619
633
  );
620
- else if (e.type === "input")
634
+ else if (t.type === "input")
621
635
  i.push(
622
636
  /* @__PURE__ */ Y(
623
637
  "span",
624
638
  {
625
- id: e.id,
639
+ id: t.id,
626
640
  "data-set-type": "input",
627
641
  contentEditable: !1,
628
642
  suppressContentEditableWarning: !0,
629
- onInput: (t) => Ze(),
630
- onClick: (t) => je(e, t),
631
- onMouseDown: (t) => Xe(e, t),
632
- "data-cosmic-ai-input-placeholder": e.placeholder,
643
+ onInput: (n) => Ie(),
644
+ onClick: (n) => Xe(t, n),
645
+ onMouseDown: (n) => Ge(t, n),
646
+ "data-cosmic-ai-input-placeholder": t.placeholder,
633
647
  children: [
634
648
  /* @__PURE__ */ u(
635
649
  "span",
636
650
  {
637
651
  className: "cosmic-ai-input-inputContent",
638
652
  style: {
639
- padding: (l = e.content) != null && l.length ? "2px 4px" : "2px 0 2px 4px"
653
+ padding: (l = t.content) != null && l.length ? "2px 4px" : "2px 0 2px 4px"
640
654
  },
641
655
  contentEditable: !1,
642
- onKeyDown: (t) => Ge(e, t),
643
- onKeyUp: (t) => Je(e, t),
644
- children: e.content
656
+ onKeyDown: (n) => Je(t, n),
657
+ onKeyUp: (n) => Qe(t, n),
658
+ children: t.content
645
659
  }
646
660
  ),
647
661
  /* @__PURE__ */ u(
648
662
  "span",
649
663
  {
650
664
  contentEditable: !1,
651
- style: { display: (c = e.content) != null && c.length ? "none" : "inline" },
665
+ style: { display: (c = t.content) != null && c.length ? "none" : "inline" },
652
666
  className: "cosmic-ai-input-placeholder",
653
- onMouseDown: (t) => Qe(e, t),
654
- children: e.placeholder
667
+ onMouseDown: (n) => Ze(t, n),
668
+ children: t.placeholder
655
669
  }
656
670
  )
657
671
  ]
658
672
  },
659
- e.id
673
+ t.id
660
674
  )
661
675
  );
662
- else if (e.type === h.SELECT) {
663
- const t = e.content || ((a = e.options) == null ? void 0 : a[0]) || e.placeholder;
676
+ else if (t.type === h.SELECT) {
677
+ const n = t.content || ((a = t.options) == null ? void 0 : a[0]) || t.placeholder;
664
678
  i.push(
665
679
  /* @__PURE__ */ u(
666
680
  "span",
667
681
  {
668
- id: e.id,
682
+ id: t.id,
669
683
  "data-set-type": "select",
670
684
  contentEditable: !1,
671
685
  suppressContentEditableWarning: !0,
672
- onClick: (H) => me(e, H),
673
- "data-cosmic-ai-input-placeholder": e.placeholder,
674
- children: /* @__PURE__ */ u("span", { contentEditable: !1, children: t })
686
+ onClick: (H) => xe(t, H),
687
+ "data-cosmic-ai-input-placeholder": t.placeholder,
688
+ children: /* @__PURE__ */ u("span", { contentEditable: !1, children: n })
675
689
  },
676
- e.id
690
+ t.id
677
691
  )
678
692
  );
679
- } else if (e.type === h.MULTIPLE_SELECT) {
680
- const t = e.content || ((d = e.options) == null ? void 0 : d[0]);
693
+ } else if (t.type === h.MULTIPLE_SELECT) {
694
+ const n = t.content || ((d = t.options) == null ? void 0 : d[0]);
681
695
  i.push(
682
696
  /* @__PURE__ */ Y(
683
697
  "span",
684
698
  {
685
- id: e.id,
699
+ id: t.id,
686
700
  "data-set-type": "multiple-select",
687
701
  contentEditable: !1,
688
702
  suppressContentEditableWarning: !0,
689
- onClick: (H) => me(e, H),
690
- "data-cosmic-ai-input-placeholder": e.placeholder,
703
+ onClick: (H) => xe(t, H),
704
+ "data-cosmic-ai-input-placeholder": t.placeholder,
691
705
  children: [
692
706
  /* @__PURE__ */ u(
693
707
  "span",
694
708
  {
695
- style: { display: t != null && t.length ? "inline" : "none" },
709
+ style: { display: n != null && n.length ? "inline" : "none" },
696
710
  contentEditable: !1,
697
- children: t
711
+ children: n
698
712
  }
699
713
  ),
700
714
  /* @__PURE__ */ u(
701
715
  "span",
702
716
  {
703
- style: { display: t != null && t.length ? "none" : "inline" },
717
+ style: { display: n != null && n.length ? "none" : "inline" },
704
718
  className: "cosmic-ai-input-selectPlaceholder",
705
719
  contentEditable: !1,
706
- children: e.placeholder
720
+ children: t.placeholder
707
721
  }
708
722
  )
709
723
  ]
710
724
  },
711
- e.id
725
+ t.id
712
726
  )
713
727
  );
714
- } else e.type === h.DATE_PICKER && i.push(
728
+ } else t.type === h.DATE_PICKER && i.push(
715
729
  /* @__PURE__ */ Y(
716
730
  "span",
717
731
  {
718
- id: e.id,
732
+ id: t.id,
719
733
  "data-set-type": "date-picker",
720
734
  contentEditable: !1,
721
735
  suppressContentEditableWarning: !0,
722
- onClick: (t) => nt(e, t),
723
- "data-cosmic-ai-input-placeholder": e.placeholder,
736
+ onClick: (n) => it(t, n),
737
+ "data-cosmic-ai-input-placeholder": t.placeholder,
724
738
  children: [
725
739
  /* @__PURE__ */ u(
726
740
  "span",
727
741
  {
728
- style: { display: (P = e.content) != null && P.length ? "inline" : "none" },
742
+ style: { display: (P = t.content) != null && P.length ? "inline" : "none" },
729
743
  contentEditable: !1,
730
- children: e.content
744
+ children: t.content
731
745
  }
732
746
  ),
733
747
  /* @__PURE__ */ u(
734
748
  "span",
735
749
  {
736
- style: { display: (S = e.content) != null && S.length ? "none" : "inline" },
750
+ style: { display: (D = t.content) != null && D.length ? "none" : "inline" },
737
751
  className: "cosmic-ai-input-datePickerPlaceholder",
738
752
  contentEditable: !1,
739
- children: e.placeholder
753
+ children: t.placeholder
740
754
  }
741
755
  )
742
756
  ]
743
757
  },
744
- e.id
758
+ t.id
745
759
  )
746
760
  );
747
761
  }), setTimeout(() => {
@@ -750,61 +764,62 @@ const ht = j((r, s) => {
750
764
  }, [o]);
751
765
  M(() => {
752
766
  de && setTimeout(() => {
753
- q(m.current);
767
+ q(x.current);
754
768
  }, 0);
755
769
  }, [de]), M(() => {
756
770
  o !== ne ? (Le(Re()), ie(o), ye(!0)) : (o === "" || !o) && Le(Re());
757
771
  }, [o, ne]), M(() => {
758
- if (!D && !Ee) return;
759
- const n = new MutationObserver(() => {
760
- m.current && document.contains(m.current) && (requestAnimationFrame(() => {
761
- q(m.current), ye(!1);
762
- }), n.disconnect());
772
+ if (!N && !Ee) return;
773
+ const e = new MutationObserver(() => {
774
+ x.current && document.contains(x.current) && (requestAnimationFrame(() => {
775
+ q(x.current), ye(!1);
776
+ }), e.disconnect());
763
777
  });
764
- return m.current && n.observe(document.body, { childList: !0, subtree: !0 }), () => n.disconnect();
765
- }, [D, Ee]);
778
+ return x.current && e.observe(document.body, { childList: !0, subtree: !0 }), () => e.disconnect();
779
+ }, [N, Ee]);
766
780
  const ue = () => {
767
- m.current && requestAnimationFrame(() => {
768
- q(m.current);
781
+ x.current && requestAnimationFrame(() => {
782
+ q(x.current);
769
783
  });
770
784
  };
771
- return lt(s, () => ({
772
- getCurrentValue: v,
785
+ return ot(s, () => ({
786
+ getCurrentValue: K,
773
787
  focus: ue
774
788
  })), // 最外层的防止renderContainer为false的时候样式坍塌
775
- /* @__PURE__ */ Y("div", { className: Se(`cosmic-ai-input-rows${g}`), style: { textIndent: T + "px" }, children: [
789
+ /* @__PURE__ */ Y("div", { className: De(`cosmic-ai-input-rows${g}`), style: { textIndent: T + "px" }, children: [
776
790
  de && /* @__PURE__ */ u(
777
791
  "div",
778
792
  {
779
793
  "data-set-type": "container",
780
794
  "data-cosmic-ai-input-placeholder": k,
781
- className: Se(
795
+ className: De(
782
796
  "cosmic-ai-input",
783
797
  `cosmic-ai-input-rows${g}`,
784
798
  { "is-disabled": $ },
785
799
  { "is-empty": ne.length === 0 }
786
800
  ),
787
- ref: m,
801
+ ref: x,
788
802
  contentEditable: !0,
789
803
  suppressContentEditableWarning: !0,
790
- onClick: (n) => Oe(n),
791
- onFocus: (n) => {
792
- Ue(n);
804
+ onClick: (e) => Fe(e),
805
+ onFocus: (e) => {
806
+ We(e);
793
807
  },
794
- onBlur: (n) => {
795
- p == null || p(n);
808
+ onBlur: (e) => {
809
+ p == null || p(e);
796
810
  },
797
- onMouseDown: (n) => Ve(),
798
- onKeyDown: (n) => _e(n),
799
- onKeyUp: (n) => Ke(n),
800
- onInput: (n) => z(n),
801
- onCopy: (n) => ve(n),
802
- onCompositionStart: We,
803
- onCompositionEnd: ze,
804
- children: it
811
+ onMouseDown: (e) => Ve(),
812
+ onKeyDown: (e) => ve(e),
813
+ onKeyUp: (e) => _e(e),
814
+ onInput: (e) => z(e),
815
+ onCopy: (e) => Ue(e),
816
+ onPaste: (e) => Ke(e),
817
+ onCompositionStart: ze,
818
+ onCompositionEnd: je,
819
+ children: rt
805
820
  }
806
821
  ),
807
- U && ot(
822
+ U && st(
808
823
  (C == null ? void 0 : C.type) === h.MULTIPLE_SELECT ? /* @__PURE__ */ u(
809
824
  Be,
810
825
  {
@@ -852,7 +867,7 @@ const ht = j((r, s) => {
852
867
  )
853
868
  ] });
854
869
  });
855
- ht.displayName = "AiInput";
870
+ gt.displayName = "AiInput";
856
871
  export {
857
- ht as default
872
+ gt as default
858
873
  };
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .cosmic-ai-input{font-size:14px;outline:none;line-height:26px}.cosmic-ai-input p{margin:0}.cosmic-ai-input span{word-break:break-all}.cosmic-ai-input [data-set-type=input]{color:#b4c5fc;padding:0 2px;caret-color:#000}.cosmic-ai-input [data-set-type=label]{padding:0 2px;outline:none;cursor:pointer;position:relative;display:inline-block;cursor:text}.cosmic-ai-input [data-set-type=label] span{color:#2356f6;outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:0 4px;display:inline-block}.cosmic-ai-input [data-set-type=select]{padding:0 2px;outline:none;color:#2356f6;cursor:pointer;position:relative;display:inline-block}.cosmic-ai-input [data-set-type=select] span{outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:0 16px 0 4px;display:inline-block}.cosmic-ai-input [data-set-type=select]:after{content:"";position:absolute;right:6px;top:50%;transform:translateY(-50%);width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #2356f6;pointer-events:none}.cosmic-ai-input [data-set-type=multiple-select]{padding:0 2px;outline:none;color:#2356f6;cursor:pointer;position:relative;display:inline-block}.cosmic-ai-input [data-set-type=multiple-select] span{outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:2px 16px 2px 4px;display:inline-block}.cosmic-ai-input [data-set-type=multiple-select]:after{content:"";position:absolute;right:6px;top:50%;transform:translateY(-50%);width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #2356f6;pointer-events:none}.cosmic-ai-input [data-set-type=date-picker]{padding:0 2px;outline:none;color:#2356f6;cursor:pointer;position:relative;display:inline-block}.cosmic-ai-input [data-set-type=date-picker] span{outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:2px 16px 2px 4px;display:inline-block}.cosmic-ai-input [data-set-type=date-picker]:after{content:"";position:absolute;right:6px;top:50%;transform:translateY(-50%);width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #2356f6;pointer-events:none}.cosmic-ai-input.is-empty:before{content:attr(data-cosmic-ai-input-placeholder);position:absolute;color:#999;pointer-events:none;text-indent:0}.cosmic-ai-input.is-disabled{opacity:.5;pointer-events:none;cursor:not-allowed}.cosmic-ai-input-displayNone{display:none}.cosmic-ai-input-inputContent{outline:none;color:#2356f6;background-color:#f2f5fe;border-radius:2px}.cosmic-ai-input-placeholder{background-color:#f2f5fe;padding:2px 4px 2px 0;border-top-right-radius:2px;border-bottom-right-radius:2px}.cosmic-ai-input-selectPlaceholder,.cosmic-ai-input-datePickerPlaceholder{color:#b4c5fc}.cosmic-ai-input-rows1{min-height:auto}.cosmic-ai-input-rows2{min-height:46px}.cosmic-ai-input-rows3{min-height:69px}.cosmic-ai-input-rows4{min-height:92px}.cosmic-ai-input-selectFloatElement{background-color:#fff;border:1px solid #e0e0e0;border-radius:4px;box-shadow:0 2px 8px #00000026;overflow-y:auto;z-index:5000;max-width:240px}.cosmic-ai-input-selectFloatElement .selectOption{padding:8px 12px;cursor:pointer;transition:background-color .2s ease;border-bottom:1px solid #f0f0f0;font-size:14px;color:#333;box-sizing:border-box;word-wrap:break-word;word-break:break-all;display:flex;align-items:center;justify-content:space-between}.cosmic-ai-input-selectFloatElement .selectOption:last-child{border-bottom:none}.cosmic-ai-input-selectFloatElement .selectOption:hover{background-color:#f5f5f5}.cosmic-ai-input-selectFloatElement .selectOption.selected{background-color:#e6f0ff;color:#2356f6;font-weight:500}.cosmic-ai-input-selectFloatElement .selectOption.selected:after{content:"✓";color:#2356f6;padding-left:6px}.cosmic-ai-input-selectFloatElement .selectOption.highlighted{background-color:#f0f0f0;font-weight:500}.cosmic-ai-input-datePicker{position:absolute;z-index:5000}.cosmic-ai-input-datePicker input[type=date]{visibility:hidden;height:0!important;box-sizing:border-box;border:none!important;position:relative;top:-10px}.cosmic-ai-input-commonSlot{padding:2px 0}
1
+ .cosmic-ai-input{font-size:14px;outline:none;line-height:26px}.cosmic-ai-input p{margin:0}.cosmic-ai-input span{word-break:break-all}.cosmic-ai-input [data-set-type=input]{color:#b4c5fc;padding:0 2px;caret-color:#000}.cosmic-ai-input [data-set-type=label]{padding:0 2px;outline:none;cursor:pointer;position:relative;display:inline-block;cursor:text}.cosmic-ai-input [data-set-type=label] span{color:#2356f6;outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:0 4px;display:inline-block}.cosmic-ai-input [data-set-type=select]{padding:0 2px;outline:none;color:#2356f6;cursor:pointer;position:relative;display:inline-block}.cosmic-ai-input [data-set-type=select] span{outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:0 16px 0 4px;display:inline-block}.cosmic-ai-input [data-set-type=select]:after{content:"";position:absolute;right:6px;top:50%;transform:translateY(-50%);width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #2356f6;pointer-events:none}.cosmic-ai-input [data-set-type=multiple-select]{padding:0 2px;outline:none;color:#2356f6;cursor:pointer;position:relative;display:inline-block}.cosmic-ai-input [data-set-type=multiple-select] span{outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:2px 16px 2px 4px;display:inline-block}.cosmic-ai-input [data-set-type=multiple-select]:after{content:"";position:absolute;right:6px;top:50%;transform:translateY(-50%);width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #2356f6;pointer-events:none}.cosmic-ai-input [data-set-type=date-picker]{padding:0 2px;outline:none;color:#2356f6;cursor:pointer;position:relative;display:inline-block}.cosmic-ai-input [data-set-type=date-picker] span{outline:none;background-color:#f2f5fe;border-radius:2px;white-space:nowrap;padding:2px 16px 2px 4px;display:inline-block}.cosmic-ai-input [data-set-type=date-picker]:after{content:"";position:absolute;right:6px;top:50%;transform:translateY(-50%);width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #2356f6;pointer-events:none}.cosmic-ai-input.is-empty:after{content:attr(data-cosmic-ai-input-placeholder);color:#999;pointer-events:none;text-indent:0;white-space:pre-wrap;word-break:break-all;overflow-wrap:break-word}.cosmic-ai-input.is-disabled{opacity:.5;pointer-events:none;cursor:not-allowed}.cosmic-ai-input-displayNone{display:none}.cosmic-ai-input-inputContent{outline:none;color:#2356f6;background-color:#f2f5fe;border-radius:2px}.cosmic-ai-input-placeholder{background-color:#f2f5fe;padding:2px 4px 2px 0;border-top-right-radius:2px;border-bottom-right-radius:2px}.cosmic-ai-input-selectPlaceholder,.cosmic-ai-input-datePickerPlaceholder{color:#b4c5fc}.cosmic-ai-input-rows1{min-height:auto}.cosmic-ai-input-rows2{min-height:46px}.cosmic-ai-input-rows3{min-height:69px}.cosmic-ai-input-rows4{min-height:92px}.cosmic-ai-input-selectFloatElement{background-color:#fff;border:1px solid #e0e0e0;border-radius:4px;box-shadow:0 2px 8px #00000026;overflow-y:auto;z-index:5000;max-width:240px}.cosmic-ai-input-selectFloatElement .selectOption{padding:8px 12px;cursor:pointer;transition:background-color .2s ease;border-bottom:1px solid #f0f0f0;font-size:14px;color:#333;box-sizing:border-box;word-wrap:break-word;word-break:break-all;display:flex;align-items:center;justify-content:space-between}.cosmic-ai-input-selectFloatElement .selectOption:last-child{border-bottom:none}.cosmic-ai-input-selectFloatElement .selectOption:hover{background-color:#f5f5f5}.cosmic-ai-input-selectFloatElement .selectOption.selected{background-color:#e6f0ff;color:#2356f6;font-weight:500}.cosmic-ai-input-selectFloatElement .selectOption.selected:after{content:"✓";color:#2356f6;padding-left:6px}.cosmic-ai-input-selectFloatElement .selectOption.highlighted{background-color:#f0f0f0;font-weight:500}.cosmic-ai-input-datePicker{position:absolute;z-index:5000}.cosmic-ai-input-datePicker input[type=date]{visibility:hidden;height:0!important;box-sizing:border-box;border:none!important;position:relative;top:-10px}.cosmic-ai-input-commonSlot{padding:2px 0}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosmic-ai-input",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
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",