cosmic-ai-input 1.0.17 → 1.0.18

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-03T06:58:28.721Z
2
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("react/jsx-runtime"),o=require("react"),me=require("classnames"),nt=require("react-dom");var E=(r=>(r.INPUT="input",r.SELECT="select",r.MULTIPLE_SELECT="multiple-select",r.DATE_PICKER="date-picker",r.LABEL="label",r))(E||{});const Te=o.forwardRef(({value:r,position:a,id:i,onChange:h},B)=>{const[m,x]=o.useState(!0),$=o.useRef(null),k=o.useRef(null);o.useEffect(()=>{typeof B=="function"?B($.current):B&&(B.current=$.current)},[B]);const S=g=>{const y=g.target.value;h==null||h(y,E.DATE_PICKER)};o.useEffect(()=>{if(k.current)try{setTimeout(()=>{N()},100)}catch{}},[]);const N=()=>{if(k.current)try{k.current.showPicker()}catch{}},L=g=>{g.stopPropagation()};return m?p.jsx("div",{ref:$,id:i,style:{top:(a==null?void 0:a.top)||0,left:(a==null?void 0:a.left)||0},className:"cosmic-ai-input-datePicker",suppressHydrationWarning:!0,children:p.jsx("input",{ref:k,type:"date",value:r||"",onChange:S,onClick:L})}):null});Te.displayName="DatePicker";function de(r){const a=r.textContent||"",i=r.nextSibling;a.length?(i==null||i.setAttribute("style","display: none"),r.style.padding="2px 4px",r.style.borderTopLeftRadius="2px",r.style.borderBottomLeftRadius="2px",r.style.borderTopRightRadius="2px",r.style.borderBottomRightRadius="2px"):(i==null||i.setAttribute("style","display: inline"),r.style.padding="2px 0 2px 4px",r.style.borderTopLeftRadius="2px",r.style.borderBottomLeftRadius="2px",r.style.borderTopRightRadius="0",r.style.borderBottomRightRadius="0")}function O(r){if(r&&r.getAttribute("data-set-type")==="input"){const a=r.children[0];a.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{a.focus()})}}function Le(r){r&&r.getAttribute("data-set-type")==="input"&&r.children[0].setAttribute("contenteditable","false")}function F(r){return r&&(r!=null&&r.getAttribute)?r.getAttribute("data-set-type")==="input":!1}const De=o.forwardRef(({options:r,value:a,position:i,id:h,height:B=37,onChange:m},x)=>{const[$,k]=o.useState(a||""),S=o.useRef(null);o.useEffect(()=>{typeof x=="function"?x(S.current):x&&(x.current=S.current)},[x]);const N=g=>{const y=$.split(",").filter(b=>b)||[];let C="";y.includes(g)?C=y.filter(b=>b!==g).join(","):y.length?C=`${y.join(",")},${g}`:C=g,k(C),m==null||m(C,E.MULTIPLE_SELECT)},L=$.split(",")||[];return p.jsx("div",{ref:S,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(i==null?void 0:i.top)||0,left:(i==null?void 0:i.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:r.map((g,y)=>p.jsx("div",{className:`selectOption ${L.includes(g)?"selected":""}`,onClick:()=>N(g),children:g},y))})});De.displayName="MultipleSelect";const Ne=o.forwardRef(({options:r,value:a,position:i,id:h,height:B=120,onChange:m},x)=>{const[$,k]=o.useState(a||""),S=o.useRef(null);o.useEffect(()=>{typeof x=="function"?x(S.current):x&&(x.current=S.current)},[x]);const N=L=>{k(L),m==null||m(L,E.SELECT)};return p.jsx("div",{ref:S,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(i==null?void 0:i.top)||0,left:(i==null?void 0:i.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:r.length>0&&r.map((L,g)=>p.jsx("div",{className:`selectOption ${$===L?"selected":""}`,onClick:()=>N(L),children:L},g))})});Ne.displayName="Select";function Re(r){const a=r instanceof Element?r:document.getElementById(r);return a&&a.children[0].textContent||""}function st(r,a){const i=r instanceof Element?r:document.getElementById(r);i&&(i.children[0].textContent=a)}function I(r){const a=document.createRange(),i=window.getSelection();i&&(!r||!(r instanceof Node)||(a.selectNodeContents(r),a.collapse(!0),i.removeAllRanges(),i.addRange(a)))}function v(r){const a=document.createRange(),i=window.getSelection();i&&(!r||!(r instanceof Node)||(a.selectNodeContents(r),a.collapse(!1),i.removeAllRanges(),i.addRange(a)))}function ue(r){const a=window.getSelection();if(!a||a.rangeCount===0)return 0;if(!r||!(r instanceof Node))return;const i=a.getRangeAt(0),h=i.cloneRange();return h.selectNodeContents(r),h.setEnd(i.startContainer,i.startOffset),h.toString().length}function rt(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const i=r.getRangeAt(0).startContainer;return i.nodeType===Node.TEXT_NODE?i.parentElement:i.nodeType===Node.ELEMENT_NODE?i:null}function it(){const r=window.getSelection();return!r||r.rangeCount===0?null:r.getRangeAt(0).getBoundingClientRect()}function ct(){return new Promise(r=>{requestAnimationFrame(()=>{r(it())})})}function lt(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const a=r.getRangeAt(0),i=a.startContainer,h=a.startOffset;return i.nodeType===Node.TEXT_NODE?h>0?i:i.previousSibling:i.nodeType===Node.ELEMENT_NODE?h>0?i.childNodes[h-1]:i.previousSibling:null}function ot(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const a=r.getRangeAt(0),i=a.startContainer,h=a.startOffset;return i.nodeType===Node.TEXT_NODE?h<i.length?i:i.nextSibling:i.nodeType===Node.ELEMENT_NODE?h<i.childNodes.length?i.childNodes[h]:i.nextSibling:null}function at(r){return r&&!r.getAttribute("data-set-type")}function Se(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}const ke=o.forwardRef(({options:r,value:a,position:i,id:h,height:B=120,onChange:m},x)=>{const[$,k]=o.useState(a||""),[S,N]=o.useState(0),L=o.useRef(null),g=o.useRef(S),y=o.useCallback(C=>{k(C),m==null||m(C,E.LABEL)},[m]);return o.useEffect(()=>{typeof x=="function"?x(L.current):x&&(x.current=L.current)},[x]),o.useEffect(()=>{g.current=S},[S]),o.useEffect(()=>{N(0)},[r]),o.useEffect(()=>{const C=b=>{r.length!==0&&(b.key==="ArrowDown"?(b.preventDefault(),N(R=>R<r.length-1?R+1:R)):b.key==="ArrowUp"?(b.preventDefault(),N(R=>R>0?R-1:R)):b.key==="Enter"&&(b.preventDefault(),setTimeout(()=>{const R=g.current;R>=0&&r[R]&&y(r[R])},0)))};return document.addEventListener("keydown",C),()=>{document.removeEventListener("keydown",C)}},[r,y]),p.jsx("div",{ref:L,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(i==null?void 0:i.top)||0,left:(i==null?void 0:i.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:r.length>0&&r.map((C,b)=>p.jsx("div",{className:`selectOption ${$===C?"selected":""} ${S===b?"highlighted":""}`,onClick:()=>y(C),onMouseEnter:()=>N(b),children:C},b))})});ke.displayName="Mention";const Pe=o.forwardRef((r,a)=>{const{value:i="",varList:h,placeholder:B="",maxLength:m,defaultRows:x=3,disabled:$=!1,defaultFocus:k=!1,textIndex:S=0,mentions:N=[],onFocus:L,onBlur:g,onChange:y,onClick:C,onSend:b,onKeyDown:R,onKeyUp:q,onMaxLengthExceeded:Y}=r,[dt,ut]=o.useState(i||""),[ee,U]=o.useState(""),[ft,te]=o.useState(""),[V,M]=o.useState(!1),[W,_]=o.useState({top:0,left:0}),[ne,se]=o.useState([]),[z,fe]=o.useState(""),[A,re]=o.useState(null),[ie,X]=o.useState(120),[pe,he]=o.useState(k),ge=240,Ee=240,ye=240,xe=276,w=o.useRef(null),T=o.useRef(null),j=o.useRef(null),G=o.useRef(!1),H=()=>{var n,t;let e=((t=(n=w.current)==null?void 0:n.innerText)==null?void 0:t.replace(/\u200B/g,""))||"";return e===`
3
- `&&(e=""),e},ce=()=>{var n;let e=((n=w.current)==null?void 0:n.innerHTML)||"";return e==="<br>"&&(e=""),e},Be=e=>{const n=[];let t=0;const l=/\[([^\]]+)\]/g;let d;const c=Se();let u=0;if(e===""||!e||e===`
1
+ // Generated at: 2026-04-03T07:16:37.095Z
2
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("react/jsx-runtime"),o=require("react"),me=require("classnames"),nt=require("react-dom");var E=(r=>(r.INPUT="input",r.SELECT="select",r.MULTIPLE_SELECT="multiple-select",r.DATE_PICKER="date-picker",r.LABEL="label",r))(E||{});const Te=o.forwardRef(({value:r,position:a,id:i,onChange:h},B)=>{const[m,x]=o.useState(!0),$=o.useRef(null),k=o.useRef(null);o.useEffect(()=>{typeof B=="function"?B($.current):B&&(B.current=$.current)},[B]);const S=g=>{const y=g.target.value;h==null||h(y,E.DATE_PICKER)};o.useEffect(()=>{if(k.current)try{setTimeout(()=>{N()},100)}catch{}},[]);const N=()=>{if(k.current)try{k.current.showPicker()}catch{}},L=g=>{g.stopPropagation()};return m?p.jsx("div",{ref:$,id:i,style:{top:(a==null?void 0:a.top)||0,left:(a==null?void 0:a.left)||0},className:"cosmic-ai-input-datePicker",suppressHydrationWarning:!0,children:p.jsx("input",{ref:k,type:"date",value:r||"",onChange:S,onClick:L})}):null});Te.displayName="DatePicker";function de(r){const a=r.textContent||"",i=r.nextSibling;a.length?(i==null||i.setAttribute("style","display: none"),r.style.padding="2px 4px",r.style.borderTopLeftRadius="2px",r.style.borderBottomLeftRadius="2px",r.style.borderTopRightRadius="2px",r.style.borderBottomRightRadius="2px"):(i==null||i.setAttribute("style","display: inline"),r.style.padding="2px 0 2px 4px",r.style.borderTopLeftRadius="2px",r.style.borderBottomLeftRadius="2px",r.style.borderTopRightRadius="0",r.style.borderBottomRightRadius="0")}function O(r){if(r&&r.getAttribute("data-set-type")==="input"){const a=r.children[0];a.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{a.focus()})}}function Le(r){r&&r.getAttribute("data-set-type")==="input"&&r.children[0].setAttribute("contenteditable","false")}function v(r){return r&&(r!=null&&r.getAttribute)?r.getAttribute("data-set-type")==="input":!1}const De=o.forwardRef(({options:r,value:a,position:i,id:h,height:B=37,onChange:m},x)=>{const[$,k]=o.useState(a||""),S=o.useRef(null);o.useEffect(()=>{typeof x=="function"?x(S.current):x&&(x.current=S.current)},[x]);const N=g=>{const y=$.split(",").filter(b=>b)||[];let w="";y.includes(g)?w=y.filter(b=>b!==g).join(","):y.length?w=`${y.join(",")},${g}`:w=g,k(w),m==null||m(w,E.MULTIPLE_SELECT)},L=$.split(",")||[];return p.jsx("div",{ref:S,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(i==null?void 0:i.top)||0,left:(i==null?void 0:i.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:r.map((g,y)=>p.jsx("div",{className:`selectOption ${L.includes(g)?"selected":""}`,onClick:()=>N(g),children:g},y))})});De.displayName="MultipleSelect";const Ne=o.forwardRef(({options:r,value:a,position:i,id:h,height:B=120,onChange:m},x)=>{const[$,k]=o.useState(a||""),S=o.useRef(null);o.useEffect(()=>{typeof x=="function"?x(S.current):x&&(x.current=S.current)},[x]);const N=L=>{k(L),m==null||m(L,E.SELECT)};return p.jsx("div",{ref:S,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(i==null?void 0:i.top)||0,left:(i==null?void 0:i.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:r.length>0&&r.map((L,g)=>p.jsx("div",{className:`selectOption ${$===L?"selected":""}`,onClick:()=>N(L),children:L},g))})});Ne.displayName="Select";function Re(r){const a=r instanceof Element?r:document.getElementById(r);return a&&a.children[0].textContent||""}function st(r,a){const i=r instanceof Element?r:document.getElementById(r);i&&(i.children[0].textContent=a)}function I(r){const a=document.createRange(),i=window.getSelection();i&&(!r||!(r instanceof Node)||(a.selectNodeContents(r),a.collapse(!0),i.removeAllRanges(),i.addRange(a)))}function F(r){const a=document.createRange(),i=window.getSelection();i&&(!r||!(r instanceof Node)||(a.selectNodeContents(r),a.collapse(!1),i.removeAllRanges(),i.addRange(a)))}function ue(r){const a=window.getSelection();if(!a||a.rangeCount===0)return 0;if(!r||!(r instanceof Node))return;const i=a.getRangeAt(0),h=i.cloneRange();return h.selectNodeContents(r),h.setEnd(i.startContainer,i.startOffset),h.toString().length}function rt(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const i=r.getRangeAt(0).startContainer;return i.nodeType===Node.TEXT_NODE?i.parentElement:i.nodeType===Node.ELEMENT_NODE?i:null}function it(){const r=window.getSelection();return!r||r.rangeCount===0?null:r.getRangeAt(0).getBoundingClientRect()}function ct(){return new Promise(r=>{requestAnimationFrame(()=>{r(it())})})}function lt(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const a=r.getRangeAt(0),i=a.startContainer,h=a.startOffset;return i.nodeType===Node.TEXT_NODE?h>0?i:i.previousSibling:i.nodeType===Node.ELEMENT_NODE?h>0?i.childNodes[h-1]:i.previousSibling:null}function ot(){const r=window.getSelection();if(!r||r.rangeCount===0)return null;const a=r.getRangeAt(0),i=a.startContainer,h=a.startOffset;return i.nodeType===Node.TEXT_NODE?h<i.length?i:i.nextSibling:i.nodeType===Node.ELEMENT_NODE?h<i.childNodes.length?i.childNodes[h]:i.nextSibling:null}function at(r){return r&&!r.getAttribute("data-set-type")}function Se(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}const ke=o.forwardRef(({options:r,value:a,position:i,id:h,height:B=120,onChange:m},x)=>{const[$,k]=o.useState(a||""),[S,N]=o.useState(0),L=o.useRef(null),g=o.useRef(S),y=o.useCallback(w=>{k(w),m==null||m(w,E.LABEL)},[m]);return o.useEffect(()=>{typeof x=="function"?x(L.current):x&&(x.current=L.current)},[x]),o.useEffect(()=>{g.current=S},[S]),o.useEffect(()=>{N(0)},[r]),o.useEffect(()=>{const w=b=>{r.length!==0&&(b.key==="ArrowDown"?(b.preventDefault(),N(R=>R<r.length-1?R+1:R)):b.key==="ArrowUp"?(b.preventDefault(),N(R=>R>0?R-1:R)):b.key==="Enter"&&(b.preventDefault(),setTimeout(()=>{const R=g.current;R>=0&&r[R]&&y(r[R])},0)))};return document.addEventListener("keydown",w),()=>{document.removeEventListener("keydown",w)}},[r,y]),p.jsx("div",{ref:L,className:"cosmic-ai-input-selectFloatElement",id:h,style:{position:"absolute",top:(i==null?void 0:i.top)||0,left:(i==null?void 0:i.left)||0,zIndex:5e3,maxHeight:`${B}px`},children:r.length>0&&r.map((w,b)=>p.jsx("div",{className:`selectOption ${$===w?"selected":""} ${S===b?"highlighted":""}`,onClick:()=>y(w),onMouseEnter:()=>N(b),children:w},b))})});ke.displayName="Mention";const Pe=o.forwardRef((r,a)=>{const{value:i="",varList:h,placeholder:B="",maxLength:m,defaultRows:x=3,disabled:$=!1,defaultFocus:k=!1,textIndex:S=0,mentions:N=[],onFocus:L,onBlur:g,onChange:y,onClick:w,onSend:b,onKeyDown:R,onKeyUp:q,onMaxLengthExceeded:Y}=r,[dt,ut]=o.useState(i||""),[ee,U]=o.useState(""),[ft,te]=o.useState(""),[V,M]=o.useState(!1),[W,_]=o.useState({top:0,left:0}),[ne,se]=o.useState([]),[z,fe]=o.useState(""),[C,re]=o.useState(null),[ie,X]=o.useState(120),[pe,he]=o.useState(k),ge=240,Ee=240,ye=240,xe=276,A=o.useRef(null),T=o.useRef(null),j=o.useRef(null),G=o.useRef(!1),H=()=>{var n,t;let e=((t=(n=A.current)==null?void 0:n.innerText)==null?void 0:t.replace(/\u200B/g,""))||"";return e===`
3
+ `&&(e=""),e},ce=()=>{var n;let e=((n=A.current)==null?void 0:n.innerHTML)||"";return e==="<br>"&&(e=""),e},Be=e=>{const n=[];let t=0;const l=/\[([^\]]+)\]/g;let d;const c=Se();let u=0;if(e===""||!e||e===`
4
4
  `)return[{type:"text",content:"​",id:`text-${u++}-${c}`}];const P=new Set((h||[]).map(D=>D.name));for(;(d=l.exec(e))!==null;){if(d.index>t){const f=e.substring(t,d.index).split(`
5
5
  `);f.forEach((Z,tt)=>{Z&&n.push({type:"text",content:Z,id:`text-${u++}-${c}`}),tt<f.length-1&&n.push({type:"newline",id:`newline-${u++}-${c}`})})}const D=d[1];if(P.has(D)){const s=h.find(f=>f.name===D);(s==null?void 0:s.type)==="input"?n.push({type:"input",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,id:`input-${u++}-${c}`}):(s==null?void 0:s.type)==="label"?n.push({type:"label",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",id:`label-${u++}-${c}`}):(s==null?void 0:s.type)==="select"?n.push({type:"select",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,options:(s==null?void 0:s.options)||[],id:`select-${u++}-${c}`}):(s==null?void 0:s.type)==="multiple-select"?n.push({type:"multiple-select",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,options:(s==null?void 0:s.options)||[],id:`multiple-select-${u++}-${c}`}):(s==null?void 0:s.type)==="date-picker"&&n.push({type:"date-picker",name:s==null?void 0:s.name,content:(s==null?void 0:s.content)||"",placeholder:(s==null?void 0:s.placeholder)||D,id:`date-picker-${u++}-${c}`})}else n.push({type:"text",content:`[${D}]`,id:`text-${u++}-${c}`});t=l.lastIndex}if(t<e.length){const s=e.substring(t).split(`
6
- `);s.forEach((f,Z)=>{f&&n.push({type:"text",content:f,id:`text-${u++}`}),Z<s.length-1&&n.push({type:"newline",id:`newline-${u++}`})})}return n},le=()=>{var e;(e=w.current)==null||e.setAttribute("contenteditable","true"),T.current&&(F(T.current)&&T.current.children[0].setAttribute("contenteditable","false"),T.current=null),v(w.current)},$e=e=>{C==null||C(e)},je=e=>{le()},K=e=>{var n,t;if(G.current){H().length>0?(n=w.current)==null||n.classList.remove("is-empty"):(t=w.current)==null||t.classList.add("is-empty");return}U(H()),te(ce()),y==null||y(H()),Ze(e)},Me=e=>{var n;if(!G.current&&e.code==="Enter"&&!e.shiftKey){e.preventDefault();const t=H();if(t.length===0||(n=w.current)!=null&&n.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/))return;m?t.length<=m?b==null||b(t):Y==null||Y(t,m):b==null||b(t)}},He=e=>{var t,l,d;if(V&&(A==null?void 0:A.type)===E.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}M(!1),R==null||R(e);const n=rt();if(n&&at(n)){if(e.code==="ArrowLeft"){const c=n==null?void 0:n.previousElementSibling,u=ue(n);c&&u===0&&F(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{v(c.children[0])}))}if(e.code==="ArrowRight"){const c=n==null?void 0:n.nextElementSibling,u=ue(n);c&&u===((t=n.textContent)==null?void 0:t.length)&&F(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{I(c.children[0])}))}(e.code==="Backspace"||((l=e==null?void 0:e.nativeEvent)==null?void 0:l.key)==="Backspace")&&(n.innerHTML==="​"&&e.preventDefault(),n.innerHTML==="<br>"&&(e.preventDefault(),n.innerHTML="​"))}if((e.code==="Backspace"||((d=e==null?void 0:e.nativeEvent)==null?void 0:d.key)==="Backspace")&&e.target){const c=e.target;if(c.childElementCount===1&&c.children[0].tagName==="SPAN"){const u=c.children[0];c.childNodes.length===1&&(u.innerHTML==="​"&&e.preventDefault(),u.innerHTML==="<br>"&&(e.preventDefault(),u.innerHTML="​"))}}if(n&&n.getAttribute("data-set-type")==="container"){if(e.code==="ArrowLeft"){const c=lt();F(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{v(c.children[0])}))}if(e.code==="ArrowRight"){const c=ot();F(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{I(c.children[0])}))}}Me(e)},Oe=e=>{if(V&&(A==null?void 0:A.type)===E.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}q==null||q(e)},ve=e=>{const t=e.clipboardData.items;for(let l=0;l<t.length;l++)if(t[l].type.indexOf("image")!==-1){e.preventDefault();return}},Fe=e=>{e.preventDefault();const t=window.getSelection().toString();if(!t)return;const l=t.replace(/\u200B/g,"")||"",d=t.replace(/\u200B/g,"")||"";e.clipboardData.setData("text/plain",l),e.clipboardData.setData("text/html",d)},qe=e=>{L==null||L(e)},Ve=()=>{G.current=!0},_e=()=>{setTimeout(()=>{G.current=!1,U(H()),te(ce()),y==null||y(H())},0)},Ke=(e,n)=>{n.stopPropagation()},Ue=(e,n)=>{var l;n.stopPropagation(),T.current&&Le(T.current),(l=w.current)==null||l.setAttribute("contenteditable","false");const t=document.getElementById(e.id);T.current=t,requestAnimationFrame(()=>{O(t)})},We=(e,n)=>{var d,c,u,P,D,s;R==null||R(n),n.stopPropagation();const t=n.target,l=ue(t);if((n.code==="Backspace"||((d=n==null?void 0:n.nativeEvent)==null?void 0:d.key)==="Backspace")&&l===0){const f=(c=t.parentElement)==null?void 0:c.previousElementSibling;f&&(F(f)&&f.children[0]&&((u=f.children[0].textContent)!=null&&u.length)?(T.current=f,O(f),v(f.children[0]),requestAnimationFrame(()=>{de(f.children[0])})):(le(),v(f)))}if(n.code==="ArrowRight"&&l===((P=t.textContent)==null?void 0:P.length)){const f=(D=t.parentElement)==null?void 0:D.nextElementSibling;f&&(F(f)&&f.children[0]&&((s=f.children[0].textContent)!=null&&s.length)?(T.current=f,O(f),I(f.children[0]),requestAnimationFrame(()=>{de(f.children[0])})):(le(),I(f)))}n.code==="Enter"&&n.shiftKey&&n.preventDefault()},ze=(e,n)=>{q==null||q(n);const t=n.target;de(t)},Xe=(e,n)=>{var l;n.stopPropagation(),T.current&&Le(T.current),(l=w.current)==null||l.setAttribute("contenteditable","false");const t=document.getElementById(e.id);T.current=t,requestAnimationFrame(()=>{O(t)})},Ge=(e,n)=>{U(H()),te(ce()),y==null||y(H())},Je=(e,n)=>{};o.useEffect(()=>{if(!V)return;const e=l=>{j.current&&!j.current.contains(l.target)&&M(!1)},n=l=>{j.current&&!j.current.contains(l.target)&&M(!1)},t=()=>{M(!1)};return document.addEventListener("mousedown",e),document.addEventListener("scroll",n,!0),window.addEventListener("resize",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",n,!0),window.removeEventListener("resize",t)}},[V]);const J=(e,n)=>{if(A&&n!==E.LABEL&&st(A.id,e),n===E.SELECT&&(M(!1),K({})),n===E.LABEL&&(ae(),M(!1),requestAnimationFrame(()=>{const t=window.getSelection();t&&Q.current&&(t.removeAllRanges(),t.addRange(Q.current),setTimeout(()=>{var u;const l=document.createElement("span");l.contentEditable="false",l.setAttribute("data-set-type","label"),l.id=A.id;const d=document.createElement("span");d.contentEditable="false",d.textContent=e,l.appendChild(d);const c=(u=w.current)==null?void 0:u.children;if((c==null?void 0:c.length)===1&&c[0].tagName==="SPAN"&&c[0].innerHTML==="​[")w.current.innerHTML="",w.current.appendChild(l),setTimeout(()=>{K({}),ae()},0);else{document.execCommand("delete",!1,void 0);const P=Q.current;P.insertNode(l),P.setStartAfter(l),P.setEndAfter(l),t.removeAllRanges(),t.addRange(P),setTimeout(()=>{K({})},0)}},0))})),n===E.MULTIPLE_SELECT||n===E.DATE_PICKER){const t=document.getElementById(A.id);t&&t.children[0]&&t.children[1]&&(e.length>0?(t.children[0].setAttribute("style","display: inline"),t.children[0].setAttribute("contenteditable","false"),t.children[1].setAttribute("style","display: none"),t.children[1].setAttribute("contenteditable","true")):(t.children[0].setAttribute("style","display: none"),t.children[0].setAttribute("contenteditable","true"),t.children[1].setAttribute("style","display: inline"),t.children[1].setAttribute("contenteditable","true"))),K({})}},Q=o.useRef(null),Qe=(N==null?void 0:N.map(e=>e.prefix))||[],Ze=e=>{const n=e==null?void 0:e.nativeEvent,t=n==null?void 0:n.data;Qe.includes(t)&&ct().then(l=>{var c;const d=window.getSelection();d&&d.rangeCount>0&&(Q.current=d.getRangeAt(0)),Ie({options:((c=N.find(u=>u.prefix===t))==null?void 0:c.options)||[],value:"",type:E.LABEL,id:"label-"+Se()},l)})},Ie=(e,n)=>{se(e.options),_({top:-999999,left:-999999999}),re(e),X(Ee),M(!0),requestAnimationFrame(()=>{if(j.current){const t=j.current.getBoundingClientRect();let l=n.left,d=n.top+n.height;window.innerWidth-n.right<ge&&n.width<t.width&&(l=n.right-t.width),n.top<t.height&&(d=n.top+n.height),_({top:d,left:l}),X(t.height)}})},be=(e,n)=>{const l=n.target.getBoundingClientRect();se(e.options),fe(e.value||Re(e.id)),_({top:-999999,left:-999999999}),re(e),X(Ee),M(!0),requestAnimationFrame(()=>{if(j.current){const d=j.current.getBoundingClientRect();let c=l.left,u=l.top+l.height;window.innerWidth-l.right<ge&&l.width<d.width&&(c=l.right-d.width),l.top<d.height&&(u=l.top+l.height),_({top:u,left:c}),X(d.height)}})},Ye=(e,n)=>{const l=n.target.getBoundingClientRect();let d=l.left,c=l.top-xe;window.innerWidth-l.right<ye&&(d=d-ye+l.width),l.top<xe&&(c=l.top+l.height),se(e.options),fe(e.value||Re(e.id)),_({top:c,left:d}),re(e),M(!0)},[et,we]=o.useState([]),[oe,Ce]=o.useState(!0),Ae=o.useCallback(()=>{Ce(!1);const e=Be(i),n=[];return e.forEach(t=>{var l,d,c,u,P,D;if(t.type==="text")n.push(p.jsx("span",{onKeyDown:s=>Je(),children:t.content},t.id));else if(t.type==="newline")n.push(p.jsx("br",{},t.id));else if(t.type==="label")n.push(p.jsx("span",{id:t.id,"data-set-type":"label",contentEditable:!1,children:p.jsx("span",{contentEditable:!1,children:t.name})},t.id));else if(t.type==="input")n.push(p.jsxs("span",{id:t.id,"data-set-type":"input",contentEditable:!1,suppressContentEditableWarning:!0,onInput:s=>Ge(),onClick:s=>Ke(t,s),onMouseDown:s=>Ue(t,s),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{className:"cosmic-ai-input-inputContent",style:{padding:(l=t.content)!=null&&l.length?"2px 4px":"2px 0 2px 4px"},contentEditable:!1,onKeyDown:s=>We(t,s),onKeyUp:s=>ze(t,s),children:t.content}),p.jsx("span",{contentEditable:!1,style:{display:(d=t.content)!=null&&d.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:s=>Xe(t,s),children:t.placeholder})]},t.id));else if(t.type===E.SELECT){const s=t.content||((c=t.options)==null?void 0:c[0])||t.placeholder;n.push(p.jsx("span",{id:t.id,"data-set-type":"select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:f=>be(t,f),"data-cosmic-ai-input-placeholder":t.placeholder,children:p.jsx("span",{contentEditable:!1,children:s})},t.id))}else if(t.type===E.MULTIPLE_SELECT){const s=t.content||((u=t.options)==null?void 0:u[0]);n.push(p.jsxs("span",{id:t.id,"data-set-type":"multiple-select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:f=>be(t,f),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{style:{display:s!=null&&s.length?"inline":"none"},contentEditable:!1,children:s}),p.jsx("span",{style:{display:s!=null&&s.length?"none":"inline"},className:"cosmic-ai-input-selectPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}else t.type===E.DATE_PICKER&&n.push(p.jsxs("span",{id:t.id,"data-set-type":"date-picker",contentEditable:!1,suppressContentEditableWarning:!0,onClick:s=>Ye(t,s),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{style:{display:(P=t.content)!=null&&P.length?"inline":"none"},contentEditable:!1,children:t.content}),p.jsx("span",{style:{display:(D=t.content)!=null&&D.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}),setTimeout(()=>{Ce(!0)},0),n},[i]);o.useEffect(()=>{oe&&setTimeout(()=>{v(w.current)},0)},[oe]),o.useEffect(()=>{i!==ee?(we(Ae()),U(i),he(!0)):(i===""||!i)&&we(Ae())},[i,ee]),o.useEffect(()=>{if(!k&&!pe)return;const e=new MutationObserver(()=>{w.current&&document.contains(w.current)&&(requestAnimationFrame(()=>{v(w.current),he(!1)}),e.disconnect())});return w.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[k,pe]);const ae=()=>{w.current&&requestAnimationFrame(()=>{v(w.current)})};return o.useImperativeHandle(a,()=>({getCurrentValue:H,focus:ae})),p.jsxs("div",{className:me(`cosmic-ai-input-rows${x}`),style:{textIndent:S+"px"},children:[oe&&p.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":B,className:me("cosmic-ai-input",`cosmic-ai-input-rows${x}`,{"is-disabled":$},{"is-empty":ee.length===0}),ref:w,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>$e(e),onFocus:e=>{qe(e)},onBlur:e=>{g==null||g(e)},onMouseDown:e=>je(),onKeyDown:e=>He(e),onKeyUp:e=>Oe(e),onInput:e=>K(e),onCopy:e=>Fe(e),onPaste:e=>ve(e),onCompositionStart:Ve,onCompositionEnd:_e,children:et}),V&&nt.createPortal((A==null?void 0:A.type)===E.MULTIPLE_SELECT?p.jsx(De,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},E.MULTIPLE_SELECT):(A==null?void 0:A.type)===E.DATE_PICKER?p.jsx(Te,{ref:j,value:z,position:W,onChange:J},E.DATE_PICKER):(A==null?void 0:A.type)===E.LABEL?p.jsx(ke,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},E.LABEL):p.jsx(Ne,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},E.SELECT),document.body)]})});Pe.displayName="AiInput";exports.default=Pe;
6
+ `);s.forEach((f,Z)=>{f&&n.push({type:"text",content:f,id:`text-${u++}`}),Z<s.length-1&&n.push({type:"newline",id:`newline-${u++}`})})}return n},le=()=>{var e;(e=A.current)==null||e.setAttribute("contenteditable","true"),T.current&&(v(T.current)&&T.current.children[0].setAttribute("contenteditable","false"),T.current=null),F(A.current)},$e=e=>{w==null||w(e)},je=e=>{le()},K=e=>{var n,t;if(G.current){H().length>0?(n=A.current)==null||n.classList.remove("is-empty"):(t=A.current)==null||t.classList.add("is-empty");return}U(H()),te(ce()),y==null||y(H()),Ze(e)},Me=e=>{var n;if(!G.current&&e.code==="Enter"&&!e.shiftKey){e.preventDefault();const t=H();if(t.length===0||(n=A.current)!=null&&n.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/))return;m?t.length<=m?b==null||b(t):Y==null||Y(t,m):b==null||b(t)}},He=e=>{var t,l,d;if(V&&(C==null?void 0:C.type)===E.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}M(!1),R==null||R(e);const n=rt();if(n&&at(n)){if(e.code==="ArrowLeft"){const c=n==null?void 0:n.previousElementSibling,u=ue(n);c&&u===0&&v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{F(c.children[0])}))}if(e.code==="ArrowRight"){const c=n==null?void 0:n.nextElementSibling,u=ue(n);c&&u===((t=n.textContent)==null?void 0:t.length)&&v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{I(c.children[0])}))}(e.code==="Backspace"||((l=e==null?void 0:e.nativeEvent)==null?void 0:l.key)==="Backspace")&&(n.innerHTML==="​"&&e.preventDefault(),n.innerHTML==="<br>"&&(e.preventDefault(),n.innerHTML="​"))}if((e.code==="Backspace"||((d=e==null?void 0:e.nativeEvent)==null?void 0:d.key)==="Backspace")&&e.target){const c=e.target;if(c.childElementCount===1&&c.children[0].tagName==="SPAN"){const u=c.children[0];c.childNodes.length===1&&(u.innerHTML==="​"&&e.preventDefault(),u.innerHTML==="<br>"&&(e.preventDefault(),u.innerHTML="​"))}}if(n&&n.getAttribute("data-set-type")==="container"){if(e.code==="ArrowLeft"){const c=lt();v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{F(c.children[0])}))}if(e.code==="ArrowRight"){const c=ot();v(c)&&c.children[0]&&(T.current=c,O(c),requestAnimationFrame(()=>{I(c.children[0])}))}}Me(e)},Oe=e=>{if(V&&(C==null?void 0:C.type)===E.LABEL&&(e.code==="ArrowUp"||e.code==="ArrowDown"||e.code==="Enter")){e.preventDefault();return}q==null||q(e)},ve=e=>{const t=e.clipboardData.items;for(let l=0;l<t.length;l++)if(t[l].type.indexOf("image")!==-1){e.preventDefault();return}},Fe=e=>{e.preventDefault();const t=window.getSelection().toString();if(!t)return;const l=t.replace(/\u200B/g,"")||"",d=t.replace(/\u200B/g,"")||"";e.clipboardData.setData("text/plain",l),e.clipboardData.setData("text/html",d)},qe=e=>{L==null||L(e)},Ve=()=>{G.current=!0},_e=()=>{setTimeout(()=>{G.current=!1,U(H()),te(ce()),y==null||y(H())},0)},Ke=(e,n)=>{n.stopPropagation()},Ue=(e,n)=>{var l;n.stopPropagation(),T.current&&Le(T.current),(l=A.current)==null||l.setAttribute("contenteditable","false");const t=document.getElementById(e.id);T.current=t,requestAnimationFrame(()=>{O(t)})},We=(e,n)=>{var d,c,u,P,D,s;R==null||R(n),n.stopPropagation();const t=n.target,l=ue(t);if((n.code==="Backspace"||((d=n==null?void 0:n.nativeEvent)==null?void 0:d.key)==="Backspace")&&l===0){const f=(c=t.parentElement)==null?void 0:c.previousElementSibling;f&&(v(f)&&f.children[0]&&((u=f.children[0].textContent)!=null&&u.length)?(T.current=f,O(f),F(f.children[0]),requestAnimationFrame(()=>{de(f.children[0])})):(le(),F(f)))}if(n.code==="ArrowRight"&&l===((P=t.textContent)==null?void 0:P.length)){const f=(D=t.parentElement)==null?void 0:D.nextElementSibling;f&&(v(f)&&f.children[0]&&((s=f.children[0].textContent)!=null&&s.length)?(T.current=f,O(f),I(f.children[0]),requestAnimationFrame(()=>{de(f.children[0])})):(le(),I(f)))}n.code==="Enter"&&n.shiftKey&&n.preventDefault()},ze=(e,n)=>{q==null||q(n);const t=n.target;de(t)},Xe=(e,n)=>{var l;n.stopPropagation(),T.current&&Le(T.current),(l=A.current)==null||l.setAttribute("contenteditable","false");const t=document.getElementById(e.id);T.current=t,requestAnimationFrame(()=>{O(t)})},Ge=(e,n)=>{U(H()),te(ce()),y==null||y(H())},Je=(e,n)=>{};o.useEffect(()=>{if(!V)return;const e=l=>{j.current&&!j.current.contains(l.target)&&M(!1)},n=l=>{j.current&&!j.current.contains(l.target)&&M(!1)},t=()=>{M(!1)};return document.addEventListener("mousedown",e),document.addEventListener("scroll",n,!0),window.addEventListener("resize",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",n,!0),window.removeEventListener("resize",t)}},[V]);const J=(e,n)=>{if(C&&n!==E.LABEL&&st(C.id,e),n===E.SELECT&&(M(!1),K({})),n===E.LABEL&&(ae(),M(!1),requestAnimationFrame(()=>{const t=window.getSelection();t&&Q.current&&(t.removeAllRanges(),t.addRange(Q.current),setTimeout(()=>{var u;const l=document.createElement("span");l.contentEditable="false",l.setAttribute("data-set-type","label"),l.id=C.id;const d=document.createElement("span");d.contentEditable="false",d.textContent=e,l.appendChild(d);const c=(u=A.current)==null?void 0:u.children;if((c==null?void 0:c.length)===1&&c[0].tagName==="SPAN"&&c[0].innerHTML==="​[")A.current.innerHTML="",A.current.appendChild(l),setTimeout(()=>{K({}),ae()},0);else{document.execCommand("delete",!1,void 0);const P=Q.current;P.insertNode(l),P.setStartAfter(l),P.setEndAfter(l),t.removeAllRanges(),t.addRange(P),setTimeout(()=>{K({})},0)}},0))})),n===E.MULTIPLE_SELECT||n===E.DATE_PICKER){const t=document.getElementById(C.id);t&&t.children[0]&&t.children[1]&&(e.length>0?(t.children[0].setAttribute("style","display: inline"),t.children[0].setAttribute("contenteditable","false"),t.children[1].setAttribute("style","display: none"),t.children[1].setAttribute("contenteditable","true")):(t.children[0].setAttribute("style","display: none"),t.children[0].setAttribute("contenteditable","true"),t.children[1].setAttribute("style","display: inline"),t.children[1].setAttribute("contenteditable","true"))),K({})}},Q=o.useRef(null),Qe=(N==null?void 0:N.map(e=>e.prefix))||[],Ze=e=>{const n=e==null?void 0:e.nativeEvent,t=n==null?void 0:n.data;Qe.includes(t)&&ct().then(l=>{var c;const d=window.getSelection();d&&d.rangeCount>0&&(Q.current=d.getRangeAt(0)),Ie({options:((c=N.find(u=>u.prefix===t))==null?void 0:c.options)||[],value:"",type:E.LABEL,id:"label-"+Se()},l)})},Ie=(e,n)=>{se(e.options),_({top:-999999,left:-999999999}),re(e),X(Ee),M(!0),requestAnimationFrame(()=>{if(j.current){const t=j.current.getBoundingClientRect();let l=n.left,d=n.top+n.height;window.innerWidth-n.right<ge&&n.width<t.width&&(l=n.right-t.width),n.top<t.height&&(d=n.top+n.height),_({top:d,left:l}),X(t.height)}})},be=(e,n)=>{const l=n.target.getBoundingClientRect();se(e.options),fe(e.value||Re(e.id)),_({top:-999999,left:-999999999}),re(e),X(Ee),M(!0),requestAnimationFrame(()=>{if(j.current){const d=j.current.getBoundingClientRect();let c=l.left,u=l.top+l.height;window.innerWidth-l.right<ge&&l.width<d.width&&(c=l.right-d.width),l.top<d.height&&(u=l.top+l.height),_({top:u,left:c}),X(d.height)}})},Ye=(e,n)=>{const l=n.target.getBoundingClientRect();let d=l.left,c=l.top-xe;window.innerWidth-l.right<ye&&(d=d-ye+l.width),l.top<xe&&(c=l.top+l.height),se(e.options),fe(e.value||Re(e.id)),_({top:c,left:d}),re(e),M(!0)},[et,we]=o.useState([]),[oe,Ce]=o.useState(!0),Ae=o.useCallback(()=>{Ce(!1);const e=Be(i),n=[];return e.forEach(t=>{var l,d,c,u,P,D;if(t.type==="text")n.push(p.jsx("span",{onKeyDown:s=>Je(),children:t.content},t.id));else if(t.type==="newline")n.push(p.jsx("br",{},t.id));else if(t.type==="label")n.push(p.jsx("span",{id:t.id,"data-set-type":"label",contentEditable:!1,children:p.jsx("span",{contentEditable:!1,children:t.name})},t.id));else if(t.type==="input")n.push(p.jsxs("span",{id:t.id,"data-set-type":"input",contentEditable:!1,suppressContentEditableWarning:!0,onInput:s=>Ge(),onClick:s=>Ke(t,s),onMouseDown:s=>Ue(t,s),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{className:"cosmic-ai-input-inputContent",style:{padding:(l=t.content)!=null&&l.length?"2px 4px":"2px 0 2px 4px"},contentEditable:!1,onKeyDown:s=>We(t,s),onKeyUp:s=>ze(t,s),children:t.content}),p.jsx("span",{contentEditable:!1,style:{display:(d=t.content)!=null&&d.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:s=>Xe(t,s),children:t.placeholder})]},t.id));else if(t.type===E.SELECT){const s=t.content||((c=t.options)==null?void 0:c[0])||t.placeholder;n.push(p.jsx("span",{id:t.id,"data-set-type":"select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:f=>be(t,f),"data-cosmic-ai-input-placeholder":t.placeholder,children:p.jsx("span",{contentEditable:!1,children:s})},t.id))}else if(t.type===E.MULTIPLE_SELECT){const s=t.content||((u=t.options)==null?void 0:u[0]);n.push(p.jsxs("span",{id:t.id,"data-set-type":"multiple-select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:f=>be(t,f),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{style:{display:s!=null&&s.length?"inline":"none"},contentEditable:!1,children:s}),p.jsx("span",{style:{display:s!=null&&s.length?"none":"inline"},className:"cosmic-ai-input-selectPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}else t.type===E.DATE_PICKER&&n.push(p.jsxs("span",{id:t.id,"data-set-type":"date-picker",contentEditable:!1,suppressContentEditableWarning:!0,onClick:s=>Ye(t,s),"data-cosmic-ai-input-placeholder":t.placeholder,children:[p.jsx("span",{style:{display:(P=t.content)!=null&&P.length?"inline":"none"},contentEditable:!1,children:t.content}),p.jsx("span",{style:{display:(D=t.content)!=null&&D.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}),setTimeout(()=>{Ce(!0)},0),n},[i]);o.useEffect(()=>{oe&&setTimeout(()=>{F(A.current)},0)},[oe]),o.useEffect(()=>{i!==ee?(we(Ae()),U(i),he(!0)):(i===""||!i)&&we(Ae())},[i,ee]),o.useEffect(()=>{if(!k&&!pe)return;const e=new MutationObserver(()=>{A.current&&document.contains(A.current)&&(requestAnimationFrame(()=>{F(A.current),he(!1)}),e.disconnect())});return A.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[k,pe]);const ae=()=>{A.current&&requestAnimationFrame(()=>{})};return o.useImperativeHandle(a,()=>({getCurrentValue:H,focus:ae})),p.jsxs("div",{className:me(`cosmic-ai-input-rows${x}`),style:{textIndent:S+"px"},children:[oe&&p.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":B,className:me("cosmic-ai-input",`cosmic-ai-input-rows${x}`,{"is-disabled":$},{"is-empty":ee.length===0}),ref:A,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>$e(e),onFocus:e=>{qe(e)},onBlur:e=>{g==null||g(e)},onMouseDown:e=>je(),onKeyDown:e=>He(e),onKeyUp:e=>Oe(e),onInput:e=>K(e),onCopy:e=>Fe(e),onPaste:e=>ve(e),onCompositionStart:Ve,onCompositionEnd:_e,children:et}),V&&nt.createPortal((C==null?void 0:C.type)===E.MULTIPLE_SELECT?p.jsx(De,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},E.MULTIPLE_SELECT):(C==null?void 0:C.type)===E.DATE_PICKER?p.jsx(Te,{ref:j,value:z,position:W,onChange:J},E.DATE_PICKER):(C==null?void 0:C.type)===E.LABEL?p.jsx(ke,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},E.LABEL):p.jsx(Ne,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},E.SELECT),document.body)]})});Pe.displayName="AiInput";exports.default=Pe;
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- // Generated at: 2026-04-03T06:58:28.222Z
1
+ // Generated at: 2026-04-03T07:16:36.590Z
2
2
  import { jsx as f, jsxs as te } from "react/jsx-runtime";
3
3
  import { forwardRef as j, useState as T, useRef as O, useEffect as H, useCallback as Pe, useImperativeHandle as st } from "react";
4
4
  import De from "classnames";
@@ -73,7 +73,7 @@ function V(r) {
73
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 q(r) {
77
77
  return r && (r != null && r.getAttribute) ? r.getAttribute("data-set-type") === "input" : !1;
78
78
  }
79
79
  const $e = j(({
@@ -90,8 +90,8 @@ const $e = j(({
90
90
  }, [y]);
91
91
  const N = (h) => {
92
92
  const E = $.split(",").filter((b) => b) || [];
93
- let w = "";
94
- E.includes(h) ? w = E.filter((b) => b !== h).join(",") : E.length ? w = `${E.join(",")},${h}` : w = h, k(w), A == null || A(w, g.MULTIPLE_SELECT);
93
+ let m = "";
94
+ E.includes(h) ? m = E.filter((b) => b !== h).join(",") : E.length ? m = `${E.join(",")},${h}` : m = h, k(m), A == null || A(m, g.MULTIPLE_SELECT);
95
95
  }, x = $.split(",") || [];
96
96
  return /* @__PURE__ */ f(
97
97
  "div",
@@ -172,7 +172,7 @@ function ne(r) {
172
172
  const o = document.createRange(), l = window.getSelection();
173
173
  l && (!r || !(r instanceof Node) || (o.selectNodeContents(r), o.collapse(!0), l.removeAllRanges(), l.addRange(o)));
174
174
  }
175
- function q(r) {
175
+ function _(r) {
176
176
  const o = document.createRange(), l = window.getSelection();
177
177
  l && (!r || !(r instanceof Node) || (o.selectNodeContents(r), o.collapse(!1), l.removeAllRanges(), l.addRange(o)));
178
178
  }
@@ -229,8 +229,8 @@ const He = j(({
229
229
  height: B = 120,
230
230
  onChange: A
231
231
  }, y) => {
232
- const [$, k] = T(o || ""), [R, N] = T(0), x = O(null), h = O(R), E = Pe((w) => {
233
- k(w), A == null || A(w, g.LABEL);
232
+ const [$, k] = T(o || ""), [R, N] = T(0), x = O(null), h = O(R), E = Pe((m) => {
233
+ k(m), A == null || A(m, g.LABEL);
234
234
  }, [A]);
235
235
  return H(() => {
236
236
  typeof y == "function" ? y(x.current) : y && (y.current = x.current);
@@ -239,14 +239,14 @@ const He = j(({
239
239
  }, [R]), H(() => {
240
240
  N(0);
241
241
  }, [r]), H(() => {
242
- const w = (b) => {
242
+ const m = (b) => {
243
243
  r.length !== 0 && (b.key === "ArrowDown" ? (b.preventDefault(), N((L) => L < r.length - 1 ? L + 1 : L)) : b.key === "ArrowUp" ? (b.preventDefault(), N((L) => L > 0 ? L - 1 : L)) : b.key === "Enter" && (b.preventDefault(), setTimeout(() => {
244
244
  const L = h.current;
245
245
  L >= 0 && r[L] && E(r[L]);
246
246
  }, 0)));
247
247
  };
248
- return document.addEventListener("keydown", w), () => {
249
- document.removeEventListener("keydown", w);
248
+ return document.addEventListener("keydown", m), () => {
249
+ document.removeEventListener("keydown", m);
250
250
  };
251
251
  }, [r, E]), /* @__PURE__ */ f(
252
252
  "div",
@@ -261,13 +261,13 @@ const He = j(({
261
261
  zIndex: 5e3,
262
262
  maxHeight: `${B}px`
263
263
  },
264
- children: r.length > 0 && r.map((w, b) => /* @__PURE__ */ f(
264
+ children: r.length > 0 && r.map((m, b) => /* @__PURE__ */ f(
265
265
  "div",
266
266
  {
267
- className: `selectOption ${$ === w ? "selected" : ""} ${R === b ? "highlighted" : ""}`,
268
- onClick: () => E(w),
267
+ className: `selectOption ${$ === m ? "selected" : ""} ${R === b ? "highlighted" : ""}`,
268
+ onClick: () => E(m),
269
269
  onMouseEnter: () => N(b),
270
- children: w
270
+ children: m
271
271
  },
272
272
  b
273
273
  ))
@@ -289,19 +289,19 @@ const gt = j((r, o) => {
289
289
  onFocus: x,
290
290
  onBlur: h,
291
291
  onChange: E,
292
- onClick: w,
292
+ onClick: m,
293
293
  onSend: b,
294
294
  onKeyDown: L,
295
295
  onKeyUp: K,
296
296
  onMaxLengthExceeded: ie
297
- } = r, [Et, yt] = T(l || ""), [re, X] = T(""), [bt, le] = T(""), [U, F] = T(!1), [G, W] = T({ top: 0, left: 0 }), [se, ce] = T([]), [J, Ee] = T(""), [C, oe] = T(null), [ae, Q] = T(120), [ye, be] = T(k), me = 240, we = 240, Ce = 240, Ae = 276, m = O(null), D = O(null), M = O(null), Z = O(!1), v = () => {
297
+ } = r, [Et, yt] = T(l || ""), [re, X] = T(""), [bt, le] = T(""), [U, F] = T(!1), [G, W] = T({ top: 0, left: 0 }), [se, ce] = T([]), [J, Ee] = T(""), [w, oe] = T(null), [ae, Q] = T(120), [ye, be] = T(k), me = 240, we = 240, Ce = 240, Ae = 276, C = O(null), D = O(null), M = O(null), Z = O(!1), v = () => {
298
298
  var n, t;
299
- let e = ((t = (n = m.current) == null ? void 0 : n.innerText) == null ? void 0 : t.replace(/\u200B/g, "")) || "";
299
+ let e = ((t = (n = C.current) == null ? void 0 : n.innerText) == null ? void 0 : t.replace(/\u200B/g, "")) || "";
300
300
  return e === `
301
301
  ` && (e = ""), e;
302
302
  }, de = () => {
303
303
  var n;
304
- let e = ((n = m.current) == null ? void 0 : n.innerHTML) || "";
304
+ let e = ((n = C.current) == null ? void 0 : n.innerHTML) || "";
305
305
  return e === "<br>" && (e = ""), e;
306
306
  }, Oe = (e) => {
307
307
  const n = [];
@@ -395,18 +395,18 @@ const gt = j((r, o) => {
395
395
  return n;
396
396
  }, ue = () => {
397
397
  var e;
398
- (e = m.current) == null || e.setAttribute("contenteditable", "true"), D.current && (_(D.current) && D.current.children[0].setAttribute(
398
+ (e = C.current) == null || e.setAttribute("contenteditable", "true"), D.current && (q(D.current) && D.current.children[0].setAttribute(
399
399
  "contenteditable",
400
400
  "false"
401
- ), D.current = null), q(m.current);
401
+ ), D.current = null), _(C.current);
402
402
  }, Fe = (e) => {
403
- w == null || w(e);
403
+ m == null || m(e);
404
404
  }, ve = (e) => {
405
405
  ue();
406
406
  }, z = (e) => {
407
407
  var n, t;
408
408
  if (Z.current) {
409
- v().length > 0 ? (n = m.current) == null || n.classList.remove("is-empty") : (t = m.current) == null || t.classList.add("is-empty");
409
+ v().length > 0 ? (n = C.current) == null || n.classList.remove("is-empty") : (t = C.current) == null || t.classList.add("is-empty");
410
410
  return;
411
411
  }
412
412
  X(v()), le(de()), E == null || E(v()), tt(e);
@@ -415,7 +415,7 @@ const gt = j((r, o) => {
415
415
  if (!Z.current && e.code === "Enter" && !e.shiftKey) {
416
416
  e.preventDefault();
417
417
  const t = v();
418
- if (t.length === 0 || (n = m.current) != null && n.innerHTML.match(
418
+ if (t.length === 0 || (n = C.current) != null && n.innerHTML.match(
419
419
  /^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/
420
420
  ))
421
421
  return;
@@ -423,7 +423,7 @@ const gt = j((r, o) => {
423
423
  }
424
424
  }, qe = (e) => {
425
425
  var t, c, a;
426
- if (U && (C == null ? void 0 : C.type) === g.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
426
+ if (U && (w == null ? void 0 : w.type) === g.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
427
427
  e.preventDefault();
428
428
  return;
429
429
  }
@@ -432,13 +432,13 @@ const gt = j((r, o) => {
432
432
  if (n && ht(n)) {
433
433
  if (e.code === "ArrowLeft") {
434
434
  const s = n == null ? void 0 : n.previousElementSibling, d = ge(n);
435
- s && d === 0 && _(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
436
- q(s.children[0]);
435
+ s && d === 0 && q(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
436
+ _(s.children[0]);
437
437
  }));
438
438
  }
439
439
  if (e.code === "ArrowRight") {
440
440
  const s = n == null ? void 0 : n.nextElementSibling, d = ge(n);
441
- s && d === ((t = n.textContent) == null ? void 0 : t.length) && _(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
441
+ s && d === ((t = n.textContent) == null ? void 0 : t.length) && q(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
442
442
  ne(s.children[0]);
443
443
  }));
444
444
  }
@@ -454,20 +454,20 @@ const gt = j((r, o) => {
454
454
  if (n && n.getAttribute("data-set-type") === "container") {
455
455
  if (e.code === "ArrowLeft") {
456
456
  const s = ft();
457
- _(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
458
- q(s.children[0]);
457
+ q(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
458
+ _(s.children[0]);
459
459
  }));
460
460
  }
461
461
  if (e.code === "ArrowRight") {
462
462
  const s = pt();
463
- _(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
463
+ q(s) && s.children[0] && (D.current = s, V(s), requestAnimationFrame(() => {
464
464
  ne(s.children[0]);
465
465
  }));
466
466
  }
467
467
  }
468
468
  Ve(e);
469
469
  }, _e = (e) => {
470
- if (U && (C == null ? void 0 : C.type) === g.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
470
+ if (U && (w == null ? void 0 : w.type) === g.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
471
471
  e.preventDefault();
472
472
  return;
473
473
  }
@@ -497,7 +497,7 @@ const gt = j((r, o) => {
497
497
  n.stopPropagation();
498
498
  }, Ge = (e, n) => {
499
499
  var c;
500
- n.stopPropagation(), D.current && Se(D.current), (c = m.current) == null || c.setAttribute("contenteditable", "false");
500
+ n.stopPropagation(), D.current && Se(D.current), (c = C.current) == null || c.setAttribute("contenteditable", "false");
501
501
  const t = document.getElementById(e.id);
502
502
  D.current = t, requestAnimationFrame(() => {
503
503
  V(t);
@@ -508,13 +508,13 @@ const gt = j((r, o) => {
508
508
  const t = n.target, c = ge(t);
509
509
  if ((n.code === "Backspace" || ((a = n == null ? void 0 : n.nativeEvent) == null ? void 0 : a.key) === "Backspace") && c === 0) {
510
510
  const u = (s = t.parentElement) == null ? void 0 : s.previousElementSibling;
511
- u && (_(u) && u.children[0] && ((d = u.children[0].textContent) != null && d.length) ? (D.current = u, V(u), q(u.children[0]), requestAnimationFrame(() => {
511
+ u && (q(u) && u.children[0] && ((d = u.children[0].textContent) != null && d.length) ? (D.current = u, V(u), _(u.children[0]), requestAnimationFrame(() => {
512
512
  he(u.children[0]);
513
- })) : (ue(), q(u)));
513
+ })) : (ue(), _(u)));
514
514
  }
515
515
  if (n.code === "ArrowRight" && c === ((P = t.textContent) == null ? void 0 : P.length)) {
516
516
  const u = (S = t.parentElement) == null ? void 0 : S.nextElementSibling;
517
- u && (_(u) && u.children[0] && ((i = u.children[0].textContent) != null && i.length) ? (D.current = u, V(u), ne(u.children[0]), requestAnimationFrame(() => {
517
+ u && (q(u) && u.children[0] && ((i = u.children[0].textContent) != null && i.length) ? (D.current = u, V(u), ne(u.children[0]), requestAnimationFrame(() => {
518
518
  he(u.children[0]);
519
519
  })) : (ue(), ne(u)));
520
520
  }
@@ -525,7 +525,7 @@ const gt = j((r, o) => {
525
525
  he(t);
526
526
  }, Ze = (e, n) => {
527
527
  var c;
528
- n.stopPropagation(), D.current && Se(D.current), (c = m.current) == null || c.setAttribute("contenteditable", "false");
528
+ n.stopPropagation(), D.current && Se(D.current), (c = C.current) == null || c.setAttribute("contenteditable", "false");
529
529
  const t = document.getElementById(e.id);
530
530
  D.current = t, requestAnimationFrame(() => {
531
531
  V(t);
@@ -548,17 +548,17 @@ const gt = j((r, o) => {
548
548
  };
549
549
  }, [U]);
550
550
  const I = (e, n) => {
551
- if (C && n !== g.LABEL && ot(C.id, e), n === g.SELECT && (F(!1), z({})), n === g.LABEL && (pe(), F(!1), requestAnimationFrame(() => {
551
+ if (w && n !== g.LABEL && ot(w.id, e), n === g.SELECT && (F(!1), z({})), n === g.LABEL && (pe(), F(!1), requestAnimationFrame(() => {
552
552
  const t = window.getSelection();
553
553
  t && Y.current && (t.removeAllRanges(), t.addRange(Y.current), setTimeout(() => {
554
554
  var d;
555
555
  const c = document.createElement("span");
556
- c.contentEditable = "false", c.setAttribute("data-set-type", "label"), c.id = C.id;
556
+ c.contentEditable = "false", c.setAttribute("data-set-type", "label"), c.id = w.id;
557
557
  const a = document.createElement("span");
558
558
  a.contentEditable = "false", a.textContent = e, c.appendChild(a);
559
- const s = (d = m.current) == null ? void 0 : d.children;
559
+ const s = (d = C.current) == null ? void 0 : d.children;
560
560
  if ((s == null ? void 0 : s.length) === 1 && s[0].tagName === "SPAN" && s[0].innerHTML === "​[")
561
- m.current.innerHTML = "", m.current.appendChild(c), setTimeout(() => {
561
+ C.current.innerHTML = "", C.current.appendChild(c), setTimeout(() => {
562
562
  z({}), pe();
563
563
  }, 0);
564
564
  else {
@@ -571,7 +571,7 @@ const gt = j((r, o) => {
571
571
  }, 0));
572
572
  })), n === g.MULTIPLE_SELECT || n === g.DATE_PICKER) {
573
573
  const t = document.getElementById(
574
- C.id
574
+ w.id
575
575
  );
576
576
  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({});
577
577
  }
@@ -771,22 +771,21 @@ const gt = j((r, o) => {
771
771
  }, [l]);
772
772
  H(() => {
773
773
  fe && setTimeout(() => {
774
- q(m.current);
774
+ _(C.current);
775
775
  }, 0);
776
776
  }, [fe]), H(() => {
777
777
  l !== re ? (Le(Re()), X(l), be(!0)) : (l === "" || !l) && Le(Re());
778
778
  }, [l, re]), H(() => {
779
779
  if (!k && !ye) return;
780
780
  const e = new MutationObserver(() => {
781
- m.current && document.contains(m.current) && (requestAnimationFrame(() => {
782
- q(m.current), be(!1);
781
+ C.current && document.contains(C.current) && (requestAnimationFrame(() => {
782
+ _(C.current), be(!1);
783
783
  }), e.disconnect());
784
784
  });
785
- return m.current && e.observe(document.body, { childList: !0, subtree: !0 }), () => e.disconnect();
785
+ return C.current && e.observe(document.body, { childList: !0, subtree: !0 }), () => e.disconnect();
786
786
  }, [k, ye]);
787
787
  const pe = () => {
788
- m.current && requestAnimationFrame(() => {
789
- q(m.current);
788
+ C.current && requestAnimationFrame(() => {
790
789
  });
791
790
  };
792
791
  return st(o, () => ({
@@ -805,7 +804,7 @@ const gt = j((r, o) => {
805
804
  { "is-disabled": $ },
806
805
  { "is-empty": re.length === 0 }
807
806
  ),
808
- ref: m,
807
+ ref: C,
809
808
  contentEditable: !0,
810
809
  suppressContentEditableWarning: !0,
811
810
  onClick: (e) => Fe(e),
@@ -827,7 +826,7 @@ const gt = j((r, o) => {
827
826
  }
828
827
  ),
829
828
  U && ct(
830
- (C == null ? void 0 : C.type) === g.MULTIPLE_SELECT ? /* @__PURE__ */ f(
829
+ (w == null ? void 0 : w.type) === g.MULTIPLE_SELECT ? /* @__PURE__ */ f(
831
830
  $e,
832
831
  {
833
832
  ref: M,
@@ -838,7 +837,7 @@ const gt = j((r, o) => {
838
837
  onChange: I
839
838
  },
840
839
  g.MULTIPLE_SELECT
841
- ) : (C == null ? void 0 : C.type) === g.DATE_PICKER ? /* @__PURE__ */ f(
840
+ ) : (w == null ? void 0 : w.type) === g.DATE_PICKER ? /* @__PURE__ */ f(
842
841
  Be,
843
842
  {
844
843
  ref: M,
@@ -847,7 +846,7 @@ const gt = j((r, o) => {
847
846
  onChange: I
848
847
  },
849
848
  g.DATE_PICKER
850
- ) : (C == null ? void 0 : C.type) === g.LABEL ? /* @__PURE__ */ f(
849
+ ) : (w == null ? void 0 : w.type) === g.LABEL ? /* @__PURE__ */ f(
851
850
  He,
852
851
  {
853
852
  ref: M,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosmic-ai-input",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
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",