cosmic-ai-input 1.0.14 → 1.0.15
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 +6 -6
- package/dist/index.es.js +147 -145
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Generated at: 2026-
|
|
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=(
|
|
3
|
-
`&&(e=""),e},
|
|
4
|
-
`)return[{type:"text",content:"",id:`text-${f++}-${d}`}];const P=new Set((p||[]).map(T=>T.name));for(;(a=
|
|
5
|
-
`);M.forEach((
|
|
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)&<().then(r=>{var d;const a=window.getSelection();a&&a.rangeCount>0&&(G.current=a.getRangeAt(0)),Ie({options:((d=D.find(f=>f.prefix===t))==null?void 0:d.options)||[],value:"",type:g.LABEL,id:"label-"+Se()},r)})},Ie=(e,s)=>{te(e.options),_({top:-999999,left:-999999999}),ne(e),z(ge),B(!0),requestAnimationFrame(()=>{if(j.current){const t=j.current.getBoundingClientRect();let r=s.left,a=s.top+s.height;window.innerWidth-s.right<he&&s.width<t.width&&(r=s.right-t.width),s.top<t.height&&(a=s.top+s.height),_({top:a,left:r}),z(t.height)}})},be=(e,s)=>{const r=s.target.getBoundingClientRect();te(e.options),ue(e.value||Le(e.id)),_({top:-999999,left:-999999999}),ne(e),z(ge),B(!0),requestAnimationFrame(()=>{if(j.current){const a=j.current.getBoundingClientRect();let d=r.left,f=r.top+r.height;window.innerWidth-r.right<he&&r.width<a.width&&(d=r.right-a.width),r.top<a.height&&(f=r.top+r.height),_({top:f,left:d}),z(a.height)}})},Ye=(e,s)=>{const r=s.target.getBoundingClientRect();let a=r.left,d=r.top-ye;window.innerWidth-r.right<Ee&&(a=a-Ee+r.width),r.top<ye&&(d=r.top+r.height),te(e.options),ue(e.value||Le(e.id)),_({top:d,left:a}),ne(e),B(!0)},[et,we]=c.useState([]),[le,Ce]=c.useState(!0),Ae=c.useCallback(()=>{Ce(!1);const e=$e(l),s=[];return e.forEach(t=>{var r,a,d,f,P,T;if(t.type==="text")s.push(u.jsx("span",{onKeyDown:n=>Je(),children:t.content},t.id));else if(t.type==="newline")s.push(u.jsx("br",{},t.id));else if(t.type==="label")s.push(u.jsx("span",{id:t.id,"data-set-type":"label",contentEditable:!1,children:u.jsx("span",{contentEditable:!1,children:t.name})},t.id));else if(t.type==="input")s.push(u.jsxs("span",{id:t.id,"data-set-type":"input",contentEditable:!1,suppressContentEditableWarning:!0,onInput:n=>Ge(),onClick:n=>Ke(t,n),onMouseDown:n=>Ue(t,n),"data-cosmic-ai-input-placeholder":t.placeholder,children:[u.jsx("span",{className:"cosmic-ai-input-inputContent",style:{padding:(r=t.content)!=null&&r.length?"2px 4px":"2px 0 2px 4px"},contentEditable:!1,onKeyDown:n=>We(t,n),onKeyUp:n=>ze(t,n),children:t.content}),u.jsx("span",{contentEditable:!1,style:{display:(a=t.content)!=null&&a.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:n=>Xe(t,n),children:t.placeholder})]},t.id));else if(t.type===g.SELECT){const n=t.content||((d=t.options)==null?void 0:d[0])||t.placeholder;s.push(u.jsx("span",{id:t.id,"data-set-type":"select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:M=>be(t,M),"data-cosmic-ai-input-placeholder":t.placeholder,children:u.jsx("span",{contentEditable:!1,children:n})},t.id))}else if(t.type===g.MULTIPLE_SELECT){const n=t.content||((f=t.options)==null?void 0:f[0]);s.push(u.jsxs("span",{id:t.id,"data-set-type":"multiple-select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:M=>be(t,M),"data-cosmic-ai-input-placeholder":t.placeholder,children:[u.jsx("span",{style:{display:n!=null&&n.length?"inline":"none"},contentEditable:!1,children:n}),u.jsx("span",{style:{display:n!=null&&n.length?"none":"inline"},className:"cosmic-ai-input-selectPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}else t.type===g.DATE_PICKER&&s.push(u.jsxs("span",{id:t.id,"data-set-type":"date-picker",contentEditable:!1,suppressContentEditableWarning:!0,onClick:n=>Ye(t,n),"data-cosmic-ai-input-placeholder":t.placeholder,children:[u.jsx("span",{style:{display:(P=t.content)!=null&&P.length?"inline":"none"},contentEditable:!1,children:t.content}),u.jsx("span",{style:{display:(T=t.content)!=null&&T.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:t.placeholder})]},t.id))}),setTimeout(()=>{Ce(!0)},0),s},[l]);c.useEffect(()=>{le&&setTimeout(()=>{O(R.current)},0)},[le]),c.useEffect(()=>{l!==I?(we(Ae()),Y(l),pe(!0)):(l===""||!l)&&we(Ae())},[l,I]),c.useEffect(()=>{if(!N&&!fe)return;const e=new MutationObserver(()=>{R.current&&document.contains(R.current)&&(requestAnimationFrame(()=>{O(R.current),pe(!1)}),e.disconnect())});return R.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[N,fe]);const ce=()=>{R.current&&requestAnimationFrame(()=>{O(R.current)})};return c.useImperativeHandle(o,()=>({getCurrentValue:v,focus:ce})),u.jsxs("div",{className:me(`cosmic-ai-input-rows${E}`),style:{textIndent:L+"px"},children:[le&&u.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":k,className:me("cosmic-ai-input",`cosmic-ai-input-rows${E}`,{"is-disabled":$},{"is-empty":I.length===0}),ref:R,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>je(e),onFocus:e=>{ve(e)},onBlur:e=>{h==null||h(e)},onMouseDown:e=>Me(),onKeyDown:e=>He(e),onKeyUp:e=>Oe(e),onInput:e=>K(e),onCopy:e=>qe(e),onPaste:e=>Fe(e),onCompositionStart:Ve,onCompositionEnd:_e,children:et}),V&&nt.createPortal((w==null?void 0:w.type)===g.MULTIPLE_SELECT?u.jsx(De,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.MULTIPLE_SELECT):(w==null?void 0:w.type)===g.DATE_PICKER?u.jsx(Te,{ref:j,value:W,position:U,onChange:X},g.DATE_PICKER):(w==null?void 0:w.type)===g.LABEL?u.jsx(ke,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.LABEL):u.jsx(Ne,{ref:j,options:ee,value:W,position:U,height:se,onChange:X},g.SELECT),document.body)]})});Pe.displayName="AiInput";exports.default=Pe;
|
|
1
|
+
// Generated at: 2026-04-03T02:03:21.601Z
|
|
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=(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,y]=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 E=h.target.value;p==null||p(E,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 de(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 O(r){if(r&&r.getAttribute("data-set-type")==="input"){const o=r.children[0];o.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{o.focus()})}}function Re(r){r&&r.getAttribute("data-set-type")==="input"&&r.children[0].setAttribute("contenteditable","false")}function q(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},y)=>{const[$,N]=c.useState(o||""),L=c.useRef(null);c.useEffect(()=>{typeof y=="function"?y(L.current):y&&(y.current=L.current)},[y]);const D=h=>{const E=$.split(",").filter(x=>x)||[];let b="";E.includes(h)?b=E.filter(x=>x!==h).join(","):E.length?b=`${E.join(",")},${h}`:b=h,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,E)=>u.jsx("div",{className:`selectOption ${A.includes(h)?"selected":""}`,onClick:()=>D(h),children:h},E))})});De.displayName="MultipleSelect";const Ne=c.forwardRef(({options:r,value:o,position:l,id:p,height:k=120,onChange:C},y)=>{const[$,N]=c.useState(o||""),L=c.useRef(null);c.useEffect(()=>{typeof y=="function"?y(L.current):y&&(y.current=L.current)},[y]);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 st(r,o){const l=r instanceof Element?r:document.getElementById(r);l&&(l.children[0].textContent=o)}function I(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 ue(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 rt(){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 it(){const r=window.getSelection();return!r||r.rangeCount===0?null:r.getRangeAt(0).getBoundingClientRect()}function lt(){return new Promise(r=>{requestAnimationFrame(()=>{r(it())})})}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>0?l:l.previousSibling:l.nodeType===Node.ELEMENT_NODE?p>0?l.childNodes[p-1]:l.previousSibling:null}function ot(){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 at(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},y)=>{const[$,N]=c.useState(o||""),[L,D]=c.useState(0),A=c.useRef(null),h=c.useRef(L),E=c.useCallback(b=>{N(b),C==null||C(b,g.LABEL)},[C]);return c.useEffect(()=>{typeof y=="function"?y(A.current):y&&(y.current=A.current)},[y]),c.useEffect(()=>{h.current=L},[L]),c.useEffect(()=>{D(0)},[r]),c.useEffect(()=>{const b=x=>{r.length!==0&&(x.key==="ArrowDown"?(x.preventDefault(),D(m=>m<r.length-1?m+1:m)):x.key==="ArrowUp"?(x.preventDefault(),D(m=>m>0?m-1:m)):x.key==="Enter"&&(x.preventDefault(),setTimeout(()=>{const m=h.current;m>=0&&r[m]&&E(r[m])},0)))};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b)}},[r,E]),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,x)=>u.jsx("div",{className:`selectOption ${$===b?"selected":""} ${L===x?"highlighted":""}`,onClick:()=>E(b),onMouseEnter:()=>D(x),children:b},x))})});ke.displayName="Mention";const Pe=c.forwardRef((r,o)=>{const{value:l="",varList:p,placeholder:k="",maxLength:C,defaultRows:y=3,disabled:$=!1,defaultFocus:N=!1,textIndex:L=0,mentions:D=[],onFocus:A,onBlur:h,onChange:E,onClick:b,onSend:x,onKeyDown:m,onKeyUp:v,onMaxLengthExceeded:Y}=r,[dt,ut]=c.useState(l||""),[ee,U]=c.useState(""),[ft,te]=c.useState(""),[V,B]=c.useState(!1),[W,_]=c.useState({top:0,left:0}),[ne,se]=c.useState([]),[z,fe]=c.useState(""),[w,re]=c.useState(null),[ie,X]=c.useState(120),[pe,he]=c.useState(N),ge=240,Ee=240,ye=240,xe=276,R=c.useRef(null),S=c.useRef(null),j=c.useRef(null),G=c.useRef(!1),H=()=>{var s,t;let e=((t=(s=R.current)==null?void 0:s.innerText)==null?void 0:t.replace(/\u200B/g,""))||"";return e===`
|
|
3
|
+
`&&(e=""),e},le=()=>{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 i=/\[([^\]]+)\]/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=i.exec(e))!==null;){if(a.index>t){const M=e.substring(t,a.index).split(`
|
|
5
|
+
`);M.forEach((Z,tt)=>{Z&&s.push({type:"text",content:Z,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=i.lastIndex}if(t<e.length){const n=e.substring(t).split(`
|
|
6
|
+
`);n.forEach((M,Z)=>{M&&s.push({type:"text",content:M,id:`text-${f++}`}),Z<n.length-1&&s.push({type:"newline",id:`newline-${f++}`})})}return s},ce=()=>{var e;(e=R.current)==null||e.setAttribute("contenteditable","true"),S.current&&(q(S.current)&&S.current.children[0].setAttribute("contenteditable","false"),S.current=null),F(R.current)},je=e=>{b==null||b(e)},Me=e=>{ce()},K=e=>{G.current||(U(H()),te(le()),E==null||E(H()),Ze(e))},Be=e=>{var s;if(!G.current&&e.code==="Enter"&&!e.shiftKey){e.preventDefault();const t=H();if(t.length===0||(s=R.current)!=null&&s.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/))return;C?t.length<=C?x==null||x(t):Y==null||Y(t,C):x==null||x(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=rt();if(s&&at(s)){if(e.code==="ArrowLeft"){const i=s==null?void 0:s.previousElementSibling,a=ue(s);i&&a===0&&q(i)&&i.children[0]&&(S.current=i,O(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(e.code==="ArrowRight"){const i=s==null?void 0:s.nextElementSibling,a=ue(s);i&&a===((t=s.textContent)==null?void 0:t.length)&&q(i)&&i.children[0]&&(S.current=i,O(i),requestAnimationFrame(()=>{I(i.children[0])}))}e.code==="Backspace"&&(s.innerHTML===""&&e.preventDefault(),s.innerHTML==="<br>"&&(e.preventDefault(),s.innerHTML=""))}if(e.code==="Backspace"&&e.target){const i=e.target;if(i.childElementCount===1&&i.children[0].tagName==="SPAN"){const a=i.children[0];i.childNodes.length===1&&(a.innerHTML===""&&e.preventDefault(),a.innerHTML==="<br>"&&(e.preventDefault(),a.innerHTML=""))}}if(s&&s.getAttribute("data-set-type")==="container"){if(e.code==="ArrowLeft"){const i=ct();q(i)&&i.children[0]&&(S.current=i,O(i),requestAnimationFrame(()=>{F(i.children[0])}))}if(e.code==="ArrowRight"){const i=ot();q(i)&&i.children[0]&&(S.current=i,O(i),requestAnimationFrame(()=>{I(i.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}v==null||v(e)},Fe=e=>{const t=e.clipboardData.items;for(let i=0;i<t.length;i++)if(t[i].type.indexOf("image")!==-1){e.preventDefault();return}},qe=e=>{e.preventDefault();const t=window.getSelection().toString();if(!t)return;const i=t.replace(/\u200B/g,"")||"",a=t.replace(/\u200B/g,"")||"";e.clipboardData.setData("text/plain",i),e.clipboardData.setData("text/html",a)},ve=e=>{A==null||A(e)},Ve=()=>{G.current=!0},_e=()=>{setTimeout(()=>{G.current=!1,U(H()),te(le()),E==null||E(H())},0)},Ke=(e,s)=>{s.stopPropagation()},Ue=(e,s)=>{var i;s.stopPropagation(),S.current&&Re(S.current),(i=R.current)==null||i.setAttribute("contenteditable","false");const t=document.getElementById(e.id);S.current=t,requestAnimationFrame(()=>{O(t)})},We=(e,s)=>{var a,d,f,P,T;m==null||m(s),s.stopPropagation();const t=s.target,i=ue(t);if(s.code==="Backspace"&&i===0){const n=(a=t.parentElement)==null?void 0:a.previousElementSibling;n&&(q(n)&&n.children[0]&&((d=n.children[0].textContent)!=null&&d.length)?(S.current=n,O(n),F(n.children[0]),requestAnimationFrame(()=>{de(n.children[0])})):(ce(),F(n)))}if(s.code==="ArrowRight"&&i===((f=t.textContent)==null?void 0:f.length)){const n=(P=t.parentElement)==null?void 0:P.nextElementSibling;n&&(q(n)&&n.children[0]&&((T=n.children[0].textContent)!=null&&T.length)?(S.current=n,O(n),I(n.children[0]),requestAnimationFrame(()=>{de(n.children[0])})):(ce(),I(n)))}s.code==="Enter"&&s.shiftKey&&s.preventDefault()},ze=(e,s)=>{v==null||v(s);const t=s.target;de(t)},Xe=(e,s)=>{var i;s.stopPropagation(),S.current&&Re(S.current),(i=R.current)==null||i.setAttribute("contenteditable","false");const t=document.getElementById(e.id);S.current=t,requestAnimationFrame(()=>{O(t)})},Ge=(e,s)=>{U(H()),te(le()),E==null||E(H())},Je=(e,s)=>{};c.useEffect(()=>{if(!V)return;const e=i=>{j.current&&!j.current.contains(i.target)&&B(!1)},s=i=>{j.current&&!j.current.contains(i.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 J=(e,s)=>{if(w&&s!==g.LABEL&&st(w.id,e),s===g.SELECT&&(B(!1),K({})),s===g.LABEL&&(ae(),B(!1),requestAnimationFrame(()=>{const t=window.getSelection();t&&Q.current&&(t.removeAllRanges(),t.addRange(Q.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=e,i.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(i),setTimeout(()=>{K({}),ae()},0);else{document.execCommand("delete",!1,void 0);const P=Q.current;P.insertNode(i),P.setStartAfter(i),P.setEndAfter(i),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({})}},Q=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)&<().then(i=>{var d;const a=window.getSelection();a&&a.rangeCount>0&&(Q.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()},i)})},Ie=(e,s)=>{se(e.options),_({top:-999999,left:-999999999}),re(e),X(Ee),B(!0),requestAnimationFrame(()=>{if(j.current){const t=j.current.getBoundingClientRect();let i=s.left,a=s.top+s.height;window.innerWidth-s.right<ge&&s.width<t.width&&(i=s.right-t.width),s.top<t.height&&(a=s.top+s.height),_({top:a,left:i}),X(t.height)}})},be=(e,s)=>{const i=s.target.getBoundingClientRect();se(e.options),fe(e.value||Le(e.id)),_({top:-999999,left:-999999999}),re(e),X(Ee),B(!0),requestAnimationFrame(()=>{if(j.current){const a=j.current.getBoundingClientRect();let d=i.left,f=i.top+i.height;window.innerWidth-i.right<ge&&i.width<a.width&&(d=i.right-a.width),i.top<a.height&&(f=i.top+i.height),_({top:f,left:d}),X(a.height)}})},Ye=(e,s)=>{const i=s.target.getBoundingClientRect();let a=i.left,d=i.top-xe;window.innerWidth-i.right<ye&&(a=a-ye+i.width),i.top<xe&&(d=i.top+i.height),se(e.options),fe(e.value||Le(e.id)),_({top:d,left:a}),re(e),B(!0)},[et,we]=c.useState([]),[oe,Ce]=c.useState(!0),Ae=c.useCallback(()=>{Ce(!1);const e=$e(l),s=[];return e.forEach(t=>{var i,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:(i=t.content)!=null&&i.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(()=>{oe&&setTimeout(()=>{F(R.current)},0)},[oe]),c.useEffect(()=>{l!==ee?(we(Ae()),U(l),he(!0)):(l===""||!l)&&we(Ae())},[l,ee]),c.useEffect(()=>{if(!N&&!pe)return;const e=new MutationObserver(()=>{R.current&&document.contains(R.current)&&(requestAnimationFrame(()=>{F(R.current),he(!1)}),e.disconnect())});return R.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[N,pe]);const ae=()=>{R.current&&requestAnimationFrame(()=>{F(R.current)})};return c.useImperativeHandle(o,()=>({getCurrentValue:H,focus:ae})),u.jsxs("div",{className:me(`cosmic-ai-input-rows${y}`),style:{textIndent:L+"px"},children:[oe&&u.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":k,className:me("cosmic-ai-input",`cosmic-ai-input-rows${y}`,{"is-disabled":$},{"is-empty":ee.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:ne,value:z,position:W,height:ie,onChange:J},g.MULTIPLE_SELECT):(w==null?void 0:w.type)===g.DATE_PICKER?u.jsx(Te,{ref:j,value:z,position:W,onChange:J},g.DATE_PICKER):(w==null?void 0:w.type)===g.LABEL?u.jsx(ke,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},g.LABEL):u.jsx(Ne,{ref:j,options:ne,value:z,position:W,height:ie,onChange:J},g.SELECT),document.body)]})});Pe.displayName="AiInput";exports.default=Pe;
|
package/dist/index.es.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
// Generated at: 2026-
|
|
2
|
-
import { jsx as u, jsxs as
|
|
1
|
+
// Generated at: 2026-04-03T02:03:21.169Z
|
|
2
|
+
import { jsx as u, jsxs as te } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef as j, useState as L, useRef as O, useEffect as M, useCallback as Pe, useImperativeHandle as ot } from "react";
|
|
4
4
|
import De from "classnames";
|
|
5
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 [
|
|
9
|
+
const [C, E] = L(!0), $ = O(null), N = O(null);
|
|
10
10
|
M(() => {
|
|
11
11
|
typeof k == "function" ? k($.current) : k && (k.current = $.current);
|
|
12
12
|
}, [k]);
|
|
13
13
|
const T = (p) => {
|
|
14
|
-
const
|
|
15
|
-
f == null || f(
|
|
14
|
+
const g = p.target.value;
|
|
15
|
+
f == null || f(g, h.DATE_PICKER);
|
|
16
16
|
};
|
|
17
17
|
M(() => {
|
|
18
18
|
if (N.current)
|
|
@@ -32,7 +32,7 @@ const $e = j(
|
|
|
32
32
|
}, A = (p) => {
|
|
33
33
|
p.stopPropagation();
|
|
34
34
|
};
|
|
35
|
-
return
|
|
35
|
+
return C ? /* @__PURE__ */ u(
|
|
36
36
|
"div",
|
|
37
37
|
{
|
|
38
38
|
ref: $,
|
|
@@ -58,11 +58,11 @@ const $e = j(
|
|
|
58
58
|
}
|
|
59
59
|
);
|
|
60
60
|
$e.displayName = "DatePicker";
|
|
61
|
-
function
|
|
61
|
+
function he(r) {
|
|
62
62
|
const s = r.textContent || "", o = r.nextSibling;
|
|
63
63
|
s.length ? (o == null || o.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") : (o == null || o.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");
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function q(r) {
|
|
66
66
|
if (r && r.getAttribute("data-set-type") === "input") {
|
|
67
67
|
const s = r.children[0];
|
|
68
68
|
s.setAttribute("contenteditable", "true"), requestAnimationFrame(() => {
|
|
@@ -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
|
|
76
|
+
function _(r) {
|
|
77
77
|
return r && (r != null && r.getAttribute) ? r.getAttribute("data-set-type") === "input" : !1;
|
|
78
78
|
}
|
|
79
79
|
const Be = j(({
|
|
@@ -82,16 +82,16 @@ const Be = j(({
|
|
|
82
82
|
position: o,
|
|
83
83
|
id: f,
|
|
84
84
|
height: k = 37,
|
|
85
|
-
onChange:
|
|
86
|
-
},
|
|
85
|
+
onChange: C
|
|
86
|
+
}, E) => {
|
|
87
87
|
const [$, N] = L(s || ""), T = O(null);
|
|
88
88
|
M(() => {
|
|
89
|
-
typeof
|
|
90
|
-
}, [
|
|
89
|
+
typeof E == "function" ? E(T.current) : E && (E.current = T.current);
|
|
90
|
+
}, [E]);
|
|
91
91
|
const S = (p) => {
|
|
92
|
-
const
|
|
92
|
+
const g = $.split(",").filter((y) => y) || [];
|
|
93
93
|
let b = "";
|
|
94
|
-
|
|
94
|
+
g.includes(p) ? b = g.filter((y) => y !== p).join(",") : g.length ? b = `${g.join(",")},${p}` : b = p, N(b), C == null || C(b, h.MULTIPLE_SELECT);
|
|
95
95
|
}, A = $.split(",") || [];
|
|
96
96
|
return /* @__PURE__ */ u(
|
|
97
97
|
"div",
|
|
@@ -106,14 +106,14 @@ const Be = j(({
|
|
|
106
106
|
zIndex: 5e3,
|
|
107
107
|
maxHeight: `${k}px`
|
|
108
108
|
},
|
|
109
|
-
children: r.map((p,
|
|
109
|
+
children: r.map((p, g) => /* @__PURE__ */ u(
|
|
110
110
|
"div",
|
|
111
111
|
{
|
|
112
112
|
className: `selectOption ${A.includes(p) ? "selected" : ""}`,
|
|
113
113
|
onClick: () => S(p),
|
|
114
114
|
children: p
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
g
|
|
117
117
|
))
|
|
118
118
|
}
|
|
119
119
|
);
|
|
@@ -125,14 +125,14 @@ const Me = j(({
|
|
|
125
125
|
position: o,
|
|
126
126
|
id: f,
|
|
127
127
|
height: k = 120,
|
|
128
|
-
onChange:
|
|
129
|
-
},
|
|
128
|
+
onChange: C
|
|
129
|
+
}, E) => {
|
|
130
130
|
const [$, N] = L(s || ""), T = O(null);
|
|
131
131
|
M(() => {
|
|
132
|
-
typeof
|
|
133
|
-
}, [
|
|
132
|
+
typeof E == "function" ? E(T.current) : E && (E.current = T.current);
|
|
133
|
+
}, [E]);
|
|
134
134
|
const S = (A) => {
|
|
135
|
-
N(A),
|
|
135
|
+
N(A), C == null || C(A, h.SELECT);
|
|
136
136
|
};
|
|
137
137
|
return /* @__PURE__ */ u(
|
|
138
138
|
"div",
|
|
@@ -168,15 +168,15 @@ 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
|
}
|
|
171
|
-
function
|
|
171
|
+
function ne(r) {
|
|
172
172
|
const s = document.createRange(), o = window.getSelection();
|
|
173
173
|
o && (!r || !(r instanceof Node) || (s.selectNodeContents(r), s.collapse(!0), o.removeAllRanges(), o.addRange(s)));
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function v(r) {
|
|
176
176
|
const s = document.createRange(), o = window.getSelection();
|
|
177
177
|
o && (!r || !(r instanceof Node) || (s.selectNodeContents(r), s.collapse(!1), o.removeAllRanges(), o.addRange(s)));
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function ge(r) {
|
|
180
180
|
const s = window.getSelection();
|
|
181
181
|
if (!s || s.rangeCount === 0)
|
|
182
182
|
return 0;
|
|
@@ -227,28 +227,28 @@ const He = j(({
|
|
|
227
227
|
position: o,
|
|
228
228
|
id: f,
|
|
229
229
|
height: k = 120,
|
|
230
|
-
onChange:
|
|
231
|
-
},
|
|
232
|
-
const [$, N] = L(s || ""), [T, S] = L(0), A = O(null), p = O(T),
|
|
233
|
-
N(b),
|
|
234
|
-
}, [
|
|
230
|
+
onChange: C
|
|
231
|
+
}, E) => {
|
|
232
|
+
const [$, N] = L(s || ""), [T, S] = L(0), A = O(null), p = O(T), g = Pe((b) => {
|
|
233
|
+
N(b), C == null || C(b, h.LABEL);
|
|
234
|
+
}, [C]);
|
|
235
235
|
return M(() => {
|
|
236
|
-
typeof
|
|
237
|
-
}, [
|
|
236
|
+
typeof E == "function" ? E(A.current) : E && (E.current = A.current);
|
|
237
|
+
}, [E]), M(() => {
|
|
238
238
|
p.current = T;
|
|
239
239
|
}, [T]), M(() => {
|
|
240
240
|
S(0);
|
|
241
241
|
}, [r]), M(() => {
|
|
242
|
-
const b = (
|
|
243
|
-
r.length !== 0 && (
|
|
242
|
+
const b = (y) => {
|
|
243
|
+
r.length !== 0 && (y.key === "ArrowDown" ? (y.preventDefault(), S((m) => m < r.length - 1 ? m + 1 : m)) : y.key === "ArrowUp" ? (y.preventDefault(), S((m) => m > 0 ? m - 1 : m)) : y.key === "Enter" && (y.preventDefault(), setTimeout(() => {
|
|
244
244
|
const m = p.current;
|
|
245
|
-
m >= 0 && r[m] &&
|
|
245
|
+
m >= 0 && r[m] && g(r[m]);
|
|
246
246
|
}, 0)));
|
|
247
247
|
};
|
|
248
248
|
return document.addEventListener("keydown", b), () => {
|
|
249
249
|
document.removeEventListener("keydown", b);
|
|
250
250
|
};
|
|
251
|
-
}, [r,
|
|
251
|
+
}, [r, g]), /* @__PURE__ */ u(
|
|
252
252
|
"div",
|
|
253
253
|
{
|
|
254
254
|
ref: A,
|
|
@@ -261,15 +261,15 @@ const He = j(({
|
|
|
261
261
|
zIndex: 5e3,
|
|
262
262
|
maxHeight: `${k}px`
|
|
263
263
|
},
|
|
264
|
-
children: r.length > 0 && r.map((b,
|
|
264
|
+
children: r.length > 0 && r.map((b, y) => /* @__PURE__ */ u(
|
|
265
265
|
"div",
|
|
266
266
|
{
|
|
267
|
-
className: `selectOption ${$ === b ? "selected" : ""} ${T ===
|
|
268
|
-
onClick: () =>
|
|
269
|
-
onMouseEnter: () => S(
|
|
267
|
+
className: `selectOption ${$ === b ? "selected" : ""} ${T === y ? "highlighted" : ""}`,
|
|
268
|
+
onClick: () => g(b),
|
|
269
|
+
onMouseEnter: () => S(y),
|
|
270
270
|
children: b
|
|
271
271
|
},
|
|
272
|
-
|
|
272
|
+
y
|
|
273
273
|
))
|
|
274
274
|
}
|
|
275
275
|
);
|
|
@@ -280,26 +280,26 @@ const gt = j((r, s) => {
|
|
|
280
280
|
value: o = "",
|
|
281
281
|
varList: f,
|
|
282
282
|
placeholder: k = "",
|
|
283
|
-
maxLength:
|
|
284
|
-
defaultRows:
|
|
283
|
+
maxLength: C,
|
|
284
|
+
defaultRows: E = 3,
|
|
285
285
|
disabled: $ = !1,
|
|
286
286
|
defaultFocus: N = !1,
|
|
287
287
|
textIndex: T = 0,
|
|
288
288
|
mentions: S = [],
|
|
289
289
|
onFocus: A,
|
|
290
290
|
onBlur: p,
|
|
291
|
-
onChange:
|
|
291
|
+
onChange: g,
|
|
292
292
|
onClick: b,
|
|
293
|
-
onSend:
|
|
293
|
+
onSend: y,
|
|
294
294
|
onKeyDown: m,
|
|
295
|
-
onKeyUp:
|
|
296
|
-
onMaxLengthExceeded:
|
|
297
|
-
} = r, [Et, yt] = L(o || ""), [
|
|
295
|
+
onKeyUp: K,
|
|
296
|
+
onMaxLengthExceeded: ie
|
|
297
|
+
} = r, [Et, yt] = L(o || ""), [re, X] = L(""), [bt, le] = L(""), [U, F] = L(!1), [G, W] = L({ top: 0, left: 0 }), [oe, se] = L([]), [J, Ee] = L(""), [w, ce] = L(null), [ae, Q] = L(120), [ye, be] = L(N), we = 240, Ce = 240, Ae = 240, me = 276, x = O(null), R = O(null), B = O(null), Z = O(!1), V = () => {
|
|
298
298
|
var i, t;
|
|
299
299
|
let e = ((t = (i = x.current) == null ? void 0 : i.innerText) == null ? void 0 : t.replace(/\u200B/g, "")) || "";
|
|
300
300
|
return e === `
|
|
301
301
|
` && (e = ""), e;
|
|
302
|
-
},
|
|
302
|
+
}, de = () => {
|
|
303
303
|
var i;
|
|
304
304
|
let e = ((i = x.current) == null ? void 0 : i.innerHTML) || "";
|
|
305
305
|
return e === "<br>" && (e = ""), e;
|
|
@@ -324,10 +324,10 @@ const gt = j((r, s) => {
|
|
|
324
324
|
if (c.index > t) {
|
|
325
325
|
const H = e.substring(t, c.index).split(`
|
|
326
326
|
`);
|
|
327
|
-
H.forEach((
|
|
328
|
-
|
|
327
|
+
H.forEach((ee, lt) => {
|
|
328
|
+
ee && i.push({
|
|
329
329
|
type: "text",
|
|
330
|
-
content:
|
|
330
|
+
content: ee,
|
|
331
331
|
id: `text-${d++}-${a}`
|
|
332
332
|
}), lt < H.length - 1 && i.push({
|
|
333
333
|
type: "newline",
|
|
@@ -381,44 +381,44 @@ const gt = j((r, s) => {
|
|
|
381
381
|
if (t < e.length) {
|
|
382
382
|
const n = e.substring(t).split(`
|
|
383
383
|
`);
|
|
384
|
-
n.forEach((H,
|
|
384
|
+
n.forEach((H, ee) => {
|
|
385
385
|
H && i.push({
|
|
386
386
|
type: "text",
|
|
387
387
|
content: H,
|
|
388
388
|
id: `text-${d++}`
|
|
389
|
-
}),
|
|
389
|
+
}), ee < n.length - 1 && i.push({
|
|
390
390
|
type: "newline",
|
|
391
391
|
id: `newline-${d++}`
|
|
392
392
|
});
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
395
|
return i;
|
|
396
|
-
},
|
|
396
|
+
}, ue = () => {
|
|
397
397
|
var e;
|
|
398
|
-
(e = x.current) == null || e.setAttribute("contenteditable", "true"), R.current && (
|
|
398
|
+
(e = x.current) == null || e.setAttribute("contenteditable", "true"), R.current && (_(R.current) && R.current.children[0].setAttribute(
|
|
399
399
|
"contenteditable",
|
|
400
400
|
"false"
|
|
401
|
-
), R.current = null),
|
|
401
|
+
), R.current = null), v(x.current);
|
|
402
402
|
}, Fe = (e) => {
|
|
403
403
|
b == null || b(e);
|
|
404
404
|
}, Ve = (e) => {
|
|
405
|
-
|
|
405
|
+
ue();
|
|
406
406
|
}, z = (e) => {
|
|
407
|
-
|
|
407
|
+
Z.current || (X(V()), le(de()), g == null || g(V()), tt(e));
|
|
408
408
|
}, qe = (e) => {
|
|
409
409
|
var i;
|
|
410
|
-
if (!
|
|
410
|
+
if (!Z.current && e.code === "Enter" && !e.shiftKey) {
|
|
411
411
|
e.preventDefault();
|
|
412
|
-
const t =
|
|
412
|
+
const t = V();
|
|
413
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
|
-
|
|
417
|
+
C ? t.length <= C ? y == null || y(t) : ie == null || ie(t, C) : y == null || y(t);
|
|
418
418
|
}
|
|
419
419
|
}, ve = (e) => {
|
|
420
420
|
var t;
|
|
421
|
-
if (U && (
|
|
421
|
+
if (U && (w == null ? void 0 : w.type) === h.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
|
|
422
422
|
e.preventDefault();
|
|
423
423
|
return;
|
|
424
424
|
}
|
|
@@ -426,15 +426,15 @@ const gt = j((r, s) => {
|
|
|
426
426
|
const i = at();
|
|
427
427
|
if (i && ht(i)) {
|
|
428
428
|
if (e.code === "ArrowLeft") {
|
|
429
|
-
const l = i == null ? void 0 : i.previousElementSibling, c =
|
|
430
|
-
l && c === 0 &&
|
|
431
|
-
|
|
429
|
+
const l = i == null ? void 0 : i.previousElementSibling, c = ge(i);
|
|
430
|
+
l && c === 0 && _(l) && l.children[0] && (R.current = l, q(l), requestAnimationFrame(() => {
|
|
431
|
+
v(l.children[0]);
|
|
432
432
|
}));
|
|
433
433
|
}
|
|
434
434
|
if (e.code === "ArrowRight") {
|
|
435
|
-
const l = i == null ? void 0 : i.nextElementSibling, c =
|
|
436
|
-
l && c === ((t = i.textContent) == null ? void 0 : t.length) &&
|
|
437
|
-
|
|
435
|
+
const l = i == null ? void 0 : i.nextElementSibling, c = ge(i);
|
|
436
|
+
l && c === ((t = i.textContent) == null ? void 0 : t.length) && _(l) && l.children[0] && (R.current = l, q(l), requestAnimationFrame(() => {
|
|
437
|
+
ne(l.children[0]);
|
|
438
438
|
}));
|
|
439
439
|
}
|
|
440
440
|
e.code === "Backspace" && (i.innerHTML === "" && e.preventDefault(), i.innerHTML === "<br>" && (e.preventDefault(), i.innerHTML = ""));
|
|
@@ -449,24 +449,24 @@ const gt = j((r, s) => {
|
|
|
449
449
|
if (i && i.getAttribute("data-set-type") === "container") {
|
|
450
450
|
if (e.code === "ArrowLeft") {
|
|
451
451
|
const l = ft();
|
|
452
|
-
|
|
453
|
-
|
|
452
|
+
_(l) && l.children[0] && (R.current = l, q(l), requestAnimationFrame(() => {
|
|
453
|
+
v(l.children[0]);
|
|
454
454
|
}));
|
|
455
455
|
}
|
|
456
456
|
if (e.code === "ArrowRight") {
|
|
457
457
|
const l = pt();
|
|
458
|
-
|
|
459
|
-
|
|
458
|
+
_(l) && l.children[0] && (R.current = l, q(l), requestAnimationFrame(() => {
|
|
459
|
+
ne(l.children[0]);
|
|
460
460
|
}));
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
qe(e);
|
|
464
464
|
}, _e = (e) => {
|
|
465
|
-
if (U && (
|
|
465
|
+
if (U && (w == null ? void 0 : w.type) === h.LABEL && (e.code === "ArrowUp" || e.code === "ArrowDown" || e.code === "Enter")) {
|
|
466
466
|
e.preventDefault();
|
|
467
467
|
return;
|
|
468
468
|
}
|
|
469
|
-
|
|
469
|
+
K == null || K(e);
|
|
470
470
|
}, Ke = (e) => {
|
|
471
471
|
const t = e.clipboardData.items;
|
|
472
472
|
for (let l = 0; l < t.length; l++)
|
|
@@ -483,9 +483,11 @@ const gt = j((r, s) => {
|
|
|
483
483
|
}, We = (e) => {
|
|
484
484
|
A == null || A(e);
|
|
485
485
|
}, ze = () => {
|
|
486
|
-
|
|
486
|
+
Z.current = !0;
|
|
487
487
|
}, je = () => {
|
|
488
|
-
|
|
488
|
+
setTimeout(() => {
|
|
489
|
+
Z.current = !1, X(V()), le(de()), g == null || g(V());
|
|
490
|
+
}, 0);
|
|
489
491
|
}, Xe = (e, i) => {
|
|
490
492
|
i.stopPropagation();
|
|
491
493
|
}, Ge = (e, i) => {
|
|
@@ -493,38 +495,38 @@ const gt = j((r, s) => {
|
|
|
493
495
|
i.stopPropagation(), R.current && Se(R.current), (l = x.current) == null || l.setAttribute("contenteditable", "false");
|
|
494
496
|
const t = document.getElementById(e.id);
|
|
495
497
|
R.current = t, requestAnimationFrame(() => {
|
|
496
|
-
|
|
498
|
+
q(t);
|
|
497
499
|
});
|
|
498
500
|
}, Je = (e, i) => {
|
|
499
501
|
var c, a, d, P, D;
|
|
500
502
|
m == null || m(i), i.stopPropagation();
|
|
501
|
-
const t = i.target, l =
|
|
503
|
+
const t = i.target, l = ge(t);
|
|
502
504
|
if (i.code === "Backspace" && l === 0) {
|
|
503
505
|
const n = (c = t.parentElement) == null ? void 0 : c.previousElementSibling;
|
|
504
|
-
n && (
|
|
505
|
-
|
|
506
|
-
})) : (
|
|
506
|
+
n && (_(n) && n.children[0] && ((a = n.children[0].textContent) != null && a.length) ? (R.current = n, q(n), v(n.children[0]), requestAnimationFrame(() => {
|
|
507
|
+
he(n.children[0]);
|
|
508
|
+
})) : (ue(), v(n)));
|
|
507
509
|
}
|
|
508
510
|
if (i.code === "ArrowRight" && l === ((d = t.textContent) == null ? void 0 : d.length)) {
|
|
509
511
|
const n = (P = t.parentElement) == null ? void 0 : P.nextElementSibling;
|
|
510
|
-
n && (
|
|
511
|
-
|
|
512
|
-
})) : (
|
|
512
|
+
n && (_(n) && n.children[0] && ((D = n.children[0].textContent) != null && D.length) ? (R.current = n, q(n), ne(n.children[0]), requestAnimationFrame(() => {
|
|
513
|
+
he(n.children[0]);
|
|
514
|
+
})) : (ue(), ne(n)));
|
|
513
515
|
}
|
|
514
516
|
i.code === "Enter" && i.shiftKey && i.preventDefault();
|
|
515
517
|
}, Qe = (e, i) => {
|
|
516
|
-
|
|
518
|
+
K == null || K(i);
|
|
517
519
|
const t = i.target;
|
|
518
|
-
|
|
520
|
+
he(t);
|
|
519
521
|
}, Ze = (e, i) => {
|
|
520
522
|
var l;
|
|
521
523
|
i.stopPropagation(), R.current && Se(R.current), (l = x.current) == null || l.setAttribute("contenteditable", "false");
|
|
522
524
|
const t = document.getElementById(e.id);
|
|
523
525
|
R.current = t, requestAnimationFrame(() => {
|
|
524
|
-
|
|
526
|
+
q(t);
|
|
525
527
|
});
|
|
526
528
|
}, Ie = (e, i) => {
|
|
527
|
-
|
|
529
|
+
X(V()), le(de()), g == null || g(V());
|
|
528
530
|
}, Ye = (e, i) => {
|
|
529
531
|
};
|
|
530
532
|
M(() => {
|
|
@@ -540,23 +542,23 @@ const gt = j((r, s) => {
|
|
|
540
542
|
document.removeEventListener("mousedown", e), document.removeEventListener("scroll", i, !0), window.removeEventListener("resize", t);
|
|
541
543
|
};
|
|
542
544
|
}, [U]);
|
|
543
|
-
const
|
|
544
|
-
if (
|
|
545
|
+
const I = (e, i) => {
|
|
546
|
+
if (w && i !== h.LABEL && ct(w.id, e), i === h.SELECT && (F(!1), z({})), i === h.LABEL && (pe(), F(!1), requestAnimationFrame(() => {
|
|
545
547
|
const t = window.getSelection();
|
|
546
|
-
t &&
|
|
548
|
+
t && Y.current && (t.removeAllRanges(), t.addRange(Y.current), setTimeout(() => {
|
|
547
549
|
var d;
|
|
548
550
|
const l = document.createElement("span");
|
|
549
|
-
l.contentEditable = "false", l.setAttribute("data-set-type", "label"), l.id =
|
|
551
|
+
l.contentEditable = "false", l.setAttribute("data-set-type", "label"), l.id = w.id;
|
|
550
552
|
const c = document.createElement("span");
|
|
551
553
|
c.contentEditable = "false", c.textContent = e, l.appendChild(c);
|
|
552
554
|
const a = (d = x.current) == null ? void 0 : d.children;
|
|
553
555
|
if ((a == null ? void 0 : a.length) === 1 && a[0].tagName === "SPAN" && a[0].innerHTML === "[")
|
|
554
556
|
x.current.innerHTML = "", x.current.appendChild(l), setTimeout(() => {
|
|
555
|
-
z({}),
|
|
557
|
+
z({}), pe();
|
|
556
558
|
}, 0);
|
|
557
559
|
else {
|
|
558
560
|
document.execCommand("delete", !1, void 0);
|
|
559
|
-
const P =
|
|
561
|
+
const P = Y.current;
|
|
560
562
|
P.insertNode(l), P.setStartAfter(l), P.setEndAfter(l), t.removeAllRanges(), t.addRange(P), setTimeout(() => {
|
|
561
563
|
z({});
|
|
562
564
|
}, 0);
|
|
@@ -564,16 +566,16 @@ const gt = j((r, s) => {
|
|
|
564
566
|
}, 0));
|
|
565
567
|
})), i === h.MULTIPLE_SELECT || i === h.DATE_PICKER) {
|
|
566
568
|
const t = document.getElementById(
|
|
567
|
-
|
|
569
|
+
w.id
|
|
568
570
|
);
|
|
569
571
|
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({});
|
|
570
572
|
}
|
|
571
|
-
},
|
|
573
|
+
}, Y = O(null), et = (S == null ? void 0 : S.map((e) => e.prefix)) || [], tt = (e) => {
|
|
572
574
|
const i = e == null ? void 0 : e.nativeEvent, t = i == null ? void 0 : i.data;
|
|
573
575
|
et.includes(t) && ut().then((l) => {
|
|
574
576
|
var a;
|
|
575
577
|
const c = window.getSelection();
|
|
576
|
-
c && c.rangeCount > 0 && (
|
|
578
|
+
c && c.rangeCount > 0 && (Y.current = c.getRangeAt(0)), nt({
|
|
577
579
|
options: ((a = S.find((d) => d.prefix === t)) == null ? void 0 : a.options) || [],
|
|
578
580
|
value: "",
|
|
579
581
|
type: h.LABEL,
|
|
@@ -581,27 +583,27 @@ const gt = j((r, s) => {
|
|
|
581
583
|
}, l);
|
|
582
584
|
});
|
|
583
585
|
}, nt = (e, i) => {
|
|
584
|
-
|
|
586
|
+
se(e.options), W({ top: -999999, left: -999999999 }), ce(e), Q(Ce), F(!0), requestAnimationFrame(() => {
|
|
585
587
|
if (B.current) {
|
|
586
588
|
const t = B.current.getBoundingClientRect();
|
|
587
589
|
let l = i.left, c = i.top + i.height;
|
|
588
|
-
window.innerWidth - i.right <
|
|
590
|
+
window.innerWidth - i.right < we && i.width < t.width && (l = i.right - t.width), i.top < t.height && (c = i.top + i.height), W({ top: c, left: l }), Q(t.height);
|
|
589
591
|
}
|
|
590
592
|
});
|
|
591
593
|
}, xe = (e, i) => {
|
|
592
594
|
const l = i.target.getBoundingClientRect();
|
|
593
|
-
|
|
595
|
+
se(e.options), Ee(e.value || Ne(e.id)), W({ top: -999999, left: -999999999 }), ce(e), Q(Ce), F(!0), requestAnimationFrame(() => {
|
|
594
596
|
if (B.current) {
|
|
595
597
|
const c = B.current.getBoundingClientRect();
|
|
596
598
|
let a = l.left, d = l.top + l.height;
|
|
597
|
-
window.innerWidth - l.right <
|
|
599
|
+
window.innerWidth - l.right < we && l.width < c.width && (a = l.right - c.width), l.top < c.height && (d = l.top + l.height), W({ top: d, left: a }), Q(c.height);
|
|
598
600
|
}
|
|
599
601
|
});
|
|
600
602
|
}, it = (e, i) => {
|
|
601
603
|
const l = i.target.getBoundingClientRect();
|
|
602
|
-
let c = l.left, a = l.top -
|
|
603
|
-
window.innerWidth - l.right <
|
|
604
|
-
}, [rt, Le] = L([]), [
|
|
604
|
+
let c = l.left, a = l.top - me;
|
|
605
|
+
window.innerWidth - l.right < Ae && (c = c - Ae + l.width), l.top < me && (a = l.top + l.height), se(e.options), Ee(e.value || Ne(e.id)), W({ top: a, left: c }), ce(e), F(!0);
|
|
606
|
+
}, [rt, Le] = L([]), [fe, Te] = L(!0), Re = Pe(() => {
|
|
605
607
|
Te(!1);
|
|
606
608
|
const e = Oe(o), i = [];
|
|
607
609
|
return e.forEach((t) => {
|
|
@@ -633,7 +635,7 @@ const gt = j((r, s) => {
|
|
|
633
635
|
);
|
|
634
636
|
else if (t.type === "input")
|
|
635
637
|
i.push(
|
|
636
|
-
/* @__PURE__ */
|
|
638
|
+
/* @__PURE__ */ te(
|
|
637
639
|
"span",
|
|
638
640
|
{
|
|
639
641
|
id: t.id,
|
|
@@ -693,7 +695,7 @@ const gt = j((r, s) => {
|
|
|
693
695
|
} else if (t.type === h.MULTIPLE_SELECT) {
|
|
694
696
|
const n = t.content || ((d = t.options) == null ? void 0 : d[0]);
|
|
695
697
|
i.push(
|
|
696
|
-
/* @__PURE__ */
|
|
698
|
+
/* @__PURE__ */ te(
|
|
697
699
|
"span",
|
|
698
700
|
{
|
|
699
701
|
id: t.id,
|
|
@@ -726,7 +728,7 @@ const gt = j((r, s) => {
|
|
|
726
728
|
)
|
|
727
729
|
);
|
|
728
730
|
} else t.type === h.DATE_PICKER && i.push(
|
|
729
|
-
/* @__PURE__ */
|
|
731
|
+
/* @__PURE__ */ te(
|
|
730
732
|
"span",
|
|
731
733
|
{
|
|
732
734
|
id: t.id,
|
|
@@ -763,40 +765,40 @@ const gt = j((r, s) => {
|
|
|
763
765
|
}, 0), i;
|
|
764
766
|
}, [o]);
|
|
765
767
|
M(() => {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
+
fe && setTimeout(() => {
|
|
769
|
+
v(x.current);
|
|
768
770
|
}, 0);
|
|
769
|
-
}, [
|
|
770
|
-
o !==
|
|
771
|
-
}, [o,
|
|
772
|
-
if (!N && !
|
|
771
|
+
}, [fe]), M(() => {
|
|
772
|
+
o !== re ? (Le(Re()), X(o), be(!0)) : (o === "" || !o) && Le(Re());
|
|
773
|
+
}, [o, re]), M(() => {
|
|
774
|
+
if (!N && !ye) return;
|
|
773
775
|
const e = new MutationObserver(() => {
|
|
774
776
|
x.current && document.contains(x.current) && (requestAnimationFrame(() => {
|
|
775
|
-
|
|
777
|
+
v(x.current), be(!1);
|
|
776
778
|
}), e.disconnect());
|
|
777
779
|
});
|
|
778
780
|
return x.current && e.observe(document.body, { childList: !0, subtree: !0 }), () => e.disconnect();
|
|
779
|
-
}, [N,
|
|
780
|
-
const
|
|
781
|
+
}, [N, ye]);
|
|
782
|
+
const pe = () => {
|
|
781
783
|
x.current && requestAnimationFrame(() => {
|
|
782
|
-
|
|
784
|
+
v(x.current);
|
|
783
785
|
});
|
|
784
786
|
};
|
|
785
787
|
return ot(s, () => ({
|
|
786
|
-
getCurrentValue:
|
|
787
|
-
focus:
|
|
788
|
+
getCurrentValue: V,
|
|
789
|
+
focus: pe
|
|
788
790
|
})), // 最外层的防止renderContainer为false的时候样式坍塌
|
|
789
|
-
/* @__PURE__ */
|
|
790
|
-
|
|
791
|
+
/* @__PURE__ */ te("div", { className: De(`cosmic-ai-input-rows${E}`), style: { textIndent: T + "px" }, children: [
|
|
792
|
+
fe && /* @__PURE__ */ u(
|
|
791
793
|
"div",
|
|
792
794
|
{
|
|
793
795
|
"data-set-type": "container",
|
|
794
796
|
"data-cosmic-ai-input-placeholder": k,
|
|
795
797
|
className: De(
|
|
796
798
|
"cosmic-ai-input",
|
|
797
|
-
`cosmic-ai-input-rows${
|
|
799
|
+
`cosmic-ai-input-rows${E}`,
|
|
798
800
|
{ "is-disabled": $ },
|
|
799
|
-
{ "is-empty":
|
|
801
|
+
{ "is-empty": re.length === 0 }
|
|
800
802
|
),
|
|
801
803
|
ref: x,
|
|
802
804
|
contentEditable: !0,
|
|
@@ -820,46 +822,46 @@ const gt = j((r, s) => {
|
|
|
820
822
|
}
|
|
821
823
|
),
|
|
822
824
|
U && st(
|
|
823
|
-
(
|
|
825
|
+
(w == null ? void 0 : w.type) === h.MULTIPLE_SELECT ? /* @__PURE__ */ u(
|
|
824
826
|
Be,
|
|
825
827
|
{
|
|
826
828
|
ref: B,
|
|
827
|
-
options:
|
|
828
|
-
value:
|
|
829
|
-
position:
|
|
830
|
-
height:
|
|
831
|
-
onChange:
|
|
829
|
+
options: oe,
|
|
830
|
+
value: J,
|
|
831
|
+
position: G,
|
|
832
|
+
height: ae,
|
|
833
|
+
onChange: I
|
|
832
834
|
},
|
|
833
835
|
h.MULTIPLE_SELECT
|
|
834
|
-
) : (
|
|
836
|
+
) : (w == null ? void 0 : w.type) === h.DATE_PICKER ? /* @__PURE__ */ u(
|
|
835
837
|
$e,
|
|
836
838
|
{
|
|
837
839
|
ref: B,
|
|
838
|
-
value:
|
|
839
|
-
position:
|
|
840
|
-
onChange:
|
|
840
|
+
value: J,
|
|
841
|
+
position: G,
|
|
842
|
+
onChange: I
|
|
841
843
|
},
|
|
842
844
|
h.DATE_PICKER
|
|
843
|
-
) : (
|
|
845
|
+
) : (w == null ? void 0 : w.type) === h.LABEL ? /* @__PURE__ */ u(
|
|
844
846
|
He,
|
|
845
847
|
{
|
|
846
848
|
ref: B,
|
|
847
|
-
options:
|
|
848
|
-
value:
|
|
849
|
-
position:
|
|
850
|
-
height:
|
|
851
|
-
onChange:
|
|
849
|
+
options: oe,
|
|
850
|
+
value: J,
|
|
851
|
+
position: G,
|
|
852
|
+
height: ae,
|
|
853
|
+
onChange: I
|
|
852
854
|
},
|
|
853
855
|
h.LABEL
|
|
854
856
|
) : /* @__PURE__ */ u(
|
|
855
857
|
Me,
|
|
856
858
|
{
|
|
857
859
|
ref: B,
|
|
858
|
-
options:
|
|
859
|
-
value:
|
|
860
|
-
position:
|
|
861
|
-
height:
|
|
862
|
-
onChange:
|
|
860
|
+
options: oe,
|
|
861
|
+
value: J,
|
|
862
|
+
position: G,
|
|
863
|
+
height: ae,
|
|
864
|
+
onChange: I
|
|
863
865
|
},
|
|
864
866
|
h.SELECT
|
|
865
867
|
),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cosmic-ai-input",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
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",
|
|
@@ -81,4 +81,4 @@
|
|
|
81
81
|
},
|
|
82
82
|
"bundledDependencies": [],
|
|
83
83
|
"bundleDependencies": []
|
|
84
|
-
}
|
|
84
|
+
}
|