cosmic-ai-input 1.0.6 → 1.0.7
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 +186 -189
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Generated at: 2026-01-16T02:
|
|
2
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
3
|
-
`&&(e=""),e},de=()=>{var l;let e=((l=C.current)==null?void 0:l.innerHTML)||"";return e==="<br>"&&(e=""),e},ke=e=>{const l=[];let n=0;const o=/\[([^\]]+)\]/g;let
|
|
4
|
-
`)return[{type:"text",content:"",id:`text-${h++}-${f}`}];const $=new Set((
|
|
5
|
-
`);A.forEach((q,We)=>{q&&l.push({type:"text",content:q,id:`text-${h++}-${f}`}),We<A.length-1&&l.push({type:"newline",id:`newline-${h++}-${f}`})})}const E=
|
|
6
|
-
`);t.forEach((A,q)=>{A&&l.push({type:"text",content:A,id:`text-${h++}`}),q<t.length-1&&l.push({type:"newline",id:`newline-${h++}`})})}return l},G=()=>{var e;(e=C.current)==null||e.setAttribute("contenteditable","true"),x.current&&(
|
|
1
|
+
// Generated at: 2026-01-16T02:56:25.442Z
|
|
2
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("react/jsx-runtime"),i=require("react"),xe=require("classnames"),_e=require("react-dom"),we=i.forwardRef(({value:c,position:r,id:s,onChange:p},S)=>{const[b,w]=i.useState(!0),k=i.useRef(null),R=i.useRef(null);i.useEffect(()=>{typeof S=="function"?S(k.current):S&&(S.current=k.current)},[S]);const m=d=>{console.log("DatePicker handleChange",d);const y=d.target.value;p==null||p(y,"date-picker")};i.useEffect(()=>{if(R.current)try{setTimeout(()=>{T()},100)}catch(d){console.log("无法自动打开日期选择器,浏览器安全策略限制",d)}},[]);const T=()=>{if(R.current)try{R.current.showPicker()}catch(d){console.log("点击后无法打开日期选择器",d)}},g=d=>{d.stopPropagation(),console.log("DatePicker handleClick",d)};return b?u.jsx("div",{ref:k,id:s,style:{top:(r==null?void 0:r.top)||0,left:(r==null?void 0:r.left)||0},className:"cosmic-ai-input-datePicker",suppressHydrationWarning:!0,children:u.jsx("input",{ref:R,type:"date",value:c||"",onChange:m,onClick:g})}):null});we.displayName="DatePicker";function Y(c){const r=c.textContent||"",s=c.nextSibling;r.length?(s==null||s.setAttribute("style","display: none"),c.style.padding="2px 4px",c.style.borderTopLeftRadius="2px",c.style.borderBottomLeftRadius="2px",c.style.borderTopRightRadius="2px",c.style.borderBottomRightRadius="2px"):(s==null||s.setAttribute("style","display: inline"),c.style.padding="2px 0 2px 4px",c.style.borderTopLeftRadius="2px",c.style.borderBottomLeftRadius="2px",c.style.borderTopRightRadius="0",c.style.borderBottomRightRadius="0")}function M(c){if(c&&c.getAttribute("data-set-type")==="input"){const r=c.children[0];r.setAttribute("contenteditable","true"),requestAnimationFrame(()=>{r.focus()})}}function Ee(c){c&&c.getAttribute("data-set-type")==="input"&&c.children[0].setAttribute("contenteditable","false")}function j(c){return c&&c.getAttribute("data-set-type")==="input"}const Ce=i.forwardRef(({options:c,value:r,position:s,id:p,height:S=37,onChange:b},w)=>{const[k,R]=i.useState(r||""),m=i.useRef(null);i.useEffect(()=>{typeof w=="function"?w(m.current):w&&(w.current=m.current)},[w]);const T=d=>{const y=k.split(",").filter(D=>D)||[];let F="";y.includes(d)?F=y.filter(D=>D!==d).join(","):(console.log("handleOptionClick",y),y.length?F=`${y.join(",")},${d}`:F=d),R(F),b==null||b(F,"multiple-select")},g=k.split(",")||[];return u.jsx("div",{ref:m,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(s==null?void 0:s.top)||0,left:(s==null?void 0:s.left)||0,zIndex:5e3,maxHeight:`${S}px`},children:c.map((d,y)=>u.jsx("div",{className:`selectOption ${g.includes(d)?"selected":""}`,onClick:()=>T(d),children:d},y))})});Ce.displayName="MultipleSelect";const me=i.forwardRef(({options:c,value:r,position:s,id:p,height:S=120,onChange:b},w)=>{const[k,R]=i.useState(r||""),m=i.useRef(null);i.useEffect(()=>{typeof w=="function"?w(m.current):w&&(w.current=m.current)},[w]);const T=g=>{R(g),b==null||b(g,"select")};return u.jsx("div",{ref:m,className:"cosmic-ai-input-selectFloatElement",id:p,style:{position:"absolute",top:(s==null?void 0:s.top)||0,left:(s==null?void 0:s.left)||0,zIndex:5e3,maxHeight:`${S}px`},children:c.length>0&&c.map((g,d)=>u.jsx("div",{className:`selectOption ${k===g?"selected":""}`,onClick:()=>T(g),children:g},d))})});me.displayName="Select";function be(c){const r=c instanceof Element?c:document.getElementById(c);return r&&r.children[0].textContent||""}function ze(c,r){const s=c instanceof Element?c:document.getElementById(c);s&&(s.children[0].textContent=r)}function V(c){const r=document.createRange(),s=window.getSelection();if(!s){console.error("无法获取selection对象");return}if(!c||!(c instanceof Node)){console.error("element 不是有效的 DOM 节点");return}r.selectNodeContents(c),r.collapse(!0),s.removeAllRanges(),s.addRange(r)}function P(c){const r=document.createRange(),s=window.getSelection();if(!s){console.error("无法获取selection对象");return}if(!c||!(c instanceof Node)){console.error("element 不是有效的 DOM 节点");return}r.selectNodeContents(c),r.collapse(!1),s.removeAllRanges(),s.addRange(r)}function Z(c){const r=window.getSelection();if(!r||r.rangeCount===0)return 0;if(!c||!(c instanceof Node)){console.error("element 不是有效的 DOM 节点");return}const s=r.getRangeAt(0),p=s.cloneRange();return p.selectNodeContents(c),p.setEnd(s.startContainer,s.startOffset),p.toString().length}function ve(){const c=window.getSelection();if(!c||c.rangeCount===0)return null;const s=c.getRangeAt(0).startContainer;return s.nodeType===Node.TEXT_NODE?s.parentElement:s.nodeType===Node.ELEMENT_NODE?s:null}function Ue(){const c=window.getSelection();if(!c||c.rangeCount===0)return null;const r=c.getRangeAt(0),s=r.startContainer,p=r.startOffset;return s.nodeType===Node.TEXT_NODE?p>0?s:s.previousSibling:s.nodeType===Node.ELEMENT_NODE?p>0?s.childNodes[p-1]:s.previousSibling:null}function Xe(){const c=window.getSelection();if(!c||c.rangeCount===0)return null;const r=c.getRangeAt(0),s=r.startContainer,p=r.startOffset;return s.nodeType===Node.TEXT_NODE?p<s.length?s:s.nextSibling:s.nodeType===Node.ELEMENT_NODE?p<s.childNodes.length?s.childNodes[p]:s.nextSibling:null}function Ge(c){return c&&!c.getAttribute("data-set-type")}const Re=i.forwardRef((c,r)=>{const{value:s="",varList:p,placeholder:S="",maxLength:b,defaultRows:w=3,disabled:k=!1,defaultFocus:R=!1,onFocus:m,onBlur:T,onChange:g,onClick:d,onSend:y,onParse:F,onKeyDown:D,onKeyUp:O,onMaxLengthExceeded:K}=c,[Je,Qe]=i.useState(s||""),[W,_]=i.useState(""),[Ye,I]=i.useState(""),[z,H]=i.useState(!1),[v,U]=i.useState({top:0,left:0}),[ee,te]=i.useState([]),[X,ne]=i.useState(""),[L,le]=i.useState(null),[oe,se]=i.useState(120),[ce,re]=i.useState(R),Se=240,Ae=240,ie=240,ae=276,C=i.useRef(null),x=i.useRef(null),N=i.useRef(null),B=()=>{var l,n;let e=((n=(l=C.current)==null?void 0:l.innerText)==null?void 0:n.replace(/\u200B/g,""))||"";return e===`
|
|
3
|
+
`&&(e=""),e},de=()=>{var l;let e=((l=C.current)==null?void 0:l.innerHTML)||"";return e==="<br>"&&(e=""),e},ke=e=>{const l=[];let n=0;const o=/\[([^\]]+)\]/g;let a;const f=`${Date.now()}-${Math.random().toString(36).slice(2,9)}`;let h=0;if(e===""||!e||e===`
|
|
4
|
+
`)return[{type:"text",content:"",id:`text-${h++}-${f}`}];const $=new Set((p||[]).map(E=>E.name));for(;(a=o.exec(e))!==null;){if(a.index>n){const A=e.substring(n,a.index).split(`
|
|
5
|
+
`);A.forEach((q,We)=>{q&&l.push({type:"text",content:q,id:`text-${h++}-${f}`}),We<A.length-1&&l.push({type:"newline",id:`newline-${h++}-${f}`})})}const E=a[1];if($.has(E)){const t=p.find(A=>A.name===E);(t==null?void 0:t.type)==="input"?l.push({type:"input",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||E,id:`input-${h++}-${f}`}):(t==null?void 0:t.type)==="select"?l.push({type:"select",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||E,options:(t==null?void 0:t.options)||[],id:`select-${h++}-${f}`}):(t==null?void 0:t.type)==="multiple-select"?l.push({type:"multiple-select",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||E,options:(t==null?void 0:t.options)||[],id:`multiple-select-${h++}-${f}`}):(t==null?void 0:t.type)==="date-picker"&&l.push({type:"date-picker",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||E,id:`date-picker-${h++}-${f}`})}else l.push({type:"text",content:`[${E}]`,id:`text-${h++}-${f}`});n=o.lastIndex}if(n<e.length){const t=e.substring(n).split(`
|
|
6
|
+
`);t.forEach((A,q)=>{A&&l.push({type:"text",content:A,id:`text-${h++}`}),q<t.length-1&&l.push({type:"newline",id:`newline-${h++}`})})}return l},G=()=>{var e;(e=C.current)==null||e.setAttribute("contenteditable","true"),x.current&&(j(x.current)&&x.current.children[0].setAttribute("contenteditable","false"),x.current=null),P(C.current)},De=e=>{console.log("handleEditorClick",e),d==null||d(e)},Ne=e=>{console.log("handleEditorMouseDown",e),G()},ue=e=>{console.log("handleEditorInput",e),_(B()),I(de()),g==null||g(B())},Te=e=>{var l,n;if(e.code==="Enter"&&!e.shiftKey){e.preventDefault();const o=B();if(console.log("onSend",o,"maxLength:",b,"length:",o.length),o.length===0||(console.log("containerRef.current?.innerHTML",(l=C.current)==null?void 0:l.innerHTML),(n=C.current)!=null&&n.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/)))return;b?o.length<=b?y==null||y(o):(console.log("maxLength exceeded",o,b),K==null||K(o,b)):y==null||y(o)}},Le=e=>{var n;console.log("handleEditorKeyDown",e),D==null||D(e);const l=ve();if(l&&Ge(l)){if(e.code==="ArrowLeft"){const o=l==null?void 0:l.previousElementSibling,a=Z(l);o&&a===0&&j(o)&&o.children[0]&&(x.current=o,M(o),requestAnimationFrame(()=>{P(o.children[0])}))}if(e.code==="ArrowRight"){const o=l==null?void 0:l.nextElementSibling,a=Z(l);o&&a===((n=l.textContent)==null?void 0:n.length)&&j(o)&&o.children[0]&&(x.current=o,M(o),requestAnimationFrame(()=>{V(o.children[0])}))}e.code==="Backspace"&&(l.innerHTML===""&&e.preventDefault(),l.innerHTML==="<br>"&&(e.preventDefault(),l.innerHTML=""))}if(l&&l.getAttribute("data-set-type")==="container"){if(e.code==="ArrowLeft"){const o=Ue();j(o)&&o.children[0]&&(x.current=o,M(o),requestAnimationFrame(()=>{P(o.children[0])}))}if(e.code==="ArrowRight"){const o=Xe();j(o)&&o.children[0]&&(x.current=o,M(o),requestAnimationFrame(()=>{V(o.children[0])}))}}Te(e)},$e=e=>{console.log("handleEditorKeyUp",e),O==null||O(e)},Me=e=>{e.preventDefault();const n=window.getSelection().toString();if(!n)return;const o=n,a=n;e.clipboardData.setData("text/plain",o),e.clipboardData.setData("text/html",a)},je=e=>{m==null||m(e)},Pe=(e,l)=>{l.stopPropagation(),console.log("handleInputClick",e)},Fe=(e,l)=>{var o;l.stopPropagation(),console.log("handleInputMouseDown",e,l),x.current&&Ee(x.current),(o=C.current)==null||o.setAttribute("contenteditable","false");const n=document.getElementById(e.id);x.current=n,requestAnimationFrame(()=>{M(n)})},Oe=(e,l)=>{var a,f,h,$,E;console.log("handleInputKeyDown",e,l),D==null||D(l),l.stopPropagation();const n=l.target,o=Z(n);if(l.code==="Backspace"&&o===0){const t=(a=n.parentElement)==null?void 0:a.previousElementSibling;console.log("previousElement",t),t&&(j(t)&&t.children[0]&&((f=t.children[0].textContent)!=null&&f.length)?(x.current=t,M(t),P(t.children[0]),requestAnimationFrame(()=>{Y(t.children[0])})):(G(),P(t)))}if(l.code==="ArrowRight"&&o===((h=n.textContent)==null?void 0:h.length)){const t=($=n.parentElement)==null?void 0:$.nextElementSibling;console.log("nextElement",t),t&&(j(t)&&t.children[0]&&((E=t.children[0].textContent)!=null&&E.length)?(x.current=t,M(t),V(t.children[0]),requestAnimationFrame(()=>{Y(t.children[0])})):(G(),V(t)))}},He=(e,l)=>{console.log("handleInputKeyUp",e,l),O==null||O(l);const n=l.target;Y(n)},Be=(e,l)=>{var o;l.stopPropagation(),console.log("handlePlaceholderMouseDown",e),x.current&&Ee(x.current),(o=C.current)==null||o.setAttribute("contenteditable","false");const n=document.getElementById(e.id);x.current=n,requestAnimationFrame(()=>{M(n)})},qe=(e,l)=>{console.log("handleInputChange",e,l),_(B()),I(de()),g==null||g(B())},Ve=(e,l)=>{console.log("handleTextSpanKeyDown 不生效",e,l)};i.useEffect(()=>{if(!z)return;const e=o=>{N.current&&!N.current.contains(o.target)&&H(!1)},l=o=>{N.current&&!N.current.contains(o.target)&&H(!1)},n=()=>{H(!1)};return document.addEventListener("mousedown",e),document.addEventListener("scroll",l,!0),window.addEventListener("resize",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",l,!0),window.removeEventListener("resize",n)}},[z]);const J=(e,l)=>{if(console.log("handleFloatChange",e,l),L&&ze(L.id,e),l==="select"&&H(!1),l==="multiple-select"||l==="date-picker"){const n=document.getElementById(L.id);n&&n.children[0]&&n.children[1]&&(e.length>0?(n.children[0].setAttribute("style","display: inline"),n.children[0].setAttribute("contenteditable","false"),n.children[1].setAttribute("style","display: none"),n.children[1].setAttribute("contenteditable","true")):(n.children[0].setAttribute("style","display: none"),n.children[0].setAttribute("contenteditable","true"),n.children[1].setAttribute("style","display: inline"),n.children[1].setAttribute("contenteditable","true")))}ue({})},pe=(e,l)=>{console.log("handleSelectClick",e,l);const o=l.target.getBoundingClientRect();te(e.options),ne(e.value||be(e.id)),U({top:-999999,left:-999999999}),le(e),se(Ae),H(!0),requestAnimationFrame(()=>{if(N.current){console.log("currentFloatElementRef.current",N.current);const a=N.current.getBoundingClientRect();let f=o.left,h=o.top+o.height;window.innerWidth-o.right<Se&&o.width<a.width&&(f=o.right-a.width),o.top<a.height&&(h=o.top+o.height),U({top:h,left:f}),se(a.height)}})},Ke=(e,l)=>{console.log("handleDatePickerClick",e,l);const o=l.target.getBoundingClientRect();let a=o.left,f=o.top-ae;window.innerWidth-o.right<ie&&(a=a-ie+o.width),o.top<ae&&(f=o.top+o.height),te(e.options),ne(e.value||be(e.id)),U({top:f,left:a}),le(e),H(!0)},[fe,he]=i.useState([]),[Q,ge]=i.useState(!0),ye=i.useCallback(()=>{ge(!1);const e=ke(s),l=[];return e.forEach(n=>{var o,a,f,h,$,E;if(n.type==="text")l.push(u.jsx("span",{onKeyDown:t=>Ve(n,t),children:n.content},n.id));else if(n.type==="newline")l.push(u.jsx("br",{},n.id));else if(n.type==="input")l.push(u.jsxs("span",{id:n.id,"data-set-type":"input",contentEditable:!1,suppressContentEditableWarning:!0,onInput:t=>qe(n,t),onClick:t=>Pe(n,t),onMouseDown:t=>Fe(n,t),"data-cosmic-ai-input-placeholder":n.placeholder,children:[u.jsx("span",{className:"cosmic-ai-input-inputContent",style:{padding:(o=n.content)!=null&&o.length?"2px 4px":"2px 0 2px 4px"},contentEditable:!1,onKeyDown:t=>Oe(n,t),onKeyUp:t=>He(n,t),children:n.content}),u.jsx("span",{contentEditable:!1,style:{display:(a=n.content)!=null&&a.length?"none":"inline"},className:"cosmic-ai-input-placeholder",onMouseDown:t=>Be(n,t),children:n.placeholder})]},n.id));else if(n.type==="select"){const t=n.content||((f=n.options)==null?void 0:f[0])||n.placeholder;l.push(u.jsx("span",{id:n.id,"data-set-type":"select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:A=>pe(n,A),"data-cosmic-ai-input-placeholder":n.placeholder,children:u.jsx("span",{contentEditable:!1,children:t})},n.id))}else if(n.type==="multiple-select"){const t=n.content||((h=n.options)==null?void 0:h[0]);l.push(u.jsxs("span",{id:n.id,"data-set-type":"multiple-select",contentEditable:!1,suppressContentEditableWarning:!0,onClick:A=>pe(n,A),"data-cosmic-ai-input-placeholder":n.placeholder,children:[u.jsx("span",{style:{display:t!=null&&t.length?"inline":"none"},contentEditable:!1,children:t}),u.jsx("span",{style:{display:t!=null&&t.length?"none":"inline"},className:"cosmic-ai-input-selectPlaceholder",contentEditable:!1,children:n.placeholder})]},n.id))}else n.type==="date-picker"&&l.push(u.jsxs("span",{id:n.id,"data-set-type":"date-picker",contentEditable:!1,suppressContentEditableWarning:!0,onClick:t=>Ke(n,t),"data-cosmic-ai-input-placeholder":n.placeholder,children:[u.jsx("span",{style:{display:($=n.content)!=null&&$.length?"inline":"none"},contentEditable:!1,children:n.content}),u.jsx("span",{style:{display:(E=n.content)!=null&&E.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:n.placeholder})]},n.id))}),setTimeout(()=>{ge(!0)},0),console.log("重新渲染 ============================>","elements",l,"parsed",e,s),l},[s]);return i.useEffect(()=>{Q&&setTimeout(()=>{P(C.current)},0)},[Q]),i.useEffect(()=>{s!==W?(he(ye()),_(s),re(!0)):(s===""||!s)&&he(ye())},[s,W]),i.useEffect(()=>{if(!R&&!ce)return;const e=new MutationObserver(()=>{C.current&&document.contains(C.current)&&(requestAnimationFrame(()=>{P(C.current),re(!1)}),e.disconnect())});return C.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[R,ce]),i.useImperativeHandle(r,()=>({getCurrentValue:B})),console.log("renderElements",fe),u.jsxs("div",{className:xe(`cosmic-ai-input-rows${w}`),children:[Q&&u.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":S,className:xe("cosmic-ai-input",`cosmic-ai-input-rows${w}`,{"is-disabled":k},{"is-empty":W.length===0}),ref:C,contentEditable:!0,suppressContentEditableWarning:!0,onClick:e=>De(e),onFocus:e=>{je(e)},onBlur:e=>{T==null||T(e)},onMouseDown:e=>Ne(e),onKeyDown:e=>Le(e),onKeyUp:e=>$e(e),onInput:e=>ue(e),onCopy:e=>Me(e),children:fe}),z&&_e.createPortal((L==null?void 0:L.type)==="multiple-select"?u.jsx(Ce,{ref:N,options:ee,value:X,position:v,height:oe,onChange:J},"multiple-select"):(L==null?void 0:L.type)==="date-picker"?u.jsx(we,{ref:N,value:X,position:v,onChange:J},"date-picker"):u.jsx(me,{ref:N,options:ee,value:X,position:v,height:oe,onChange:J},"select"),document.body)]})});Re.displayName="AiInput";exports.default=Re;
|
package/dist/index.es.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// Generated at: 2026-01-16T02:
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { forwardRef as j, useState as w, useRef as
|
|
1
|
+
// Generated at: 2026-01-16T02:56:24.968Z
|
|
2
|
+
import { jsx as f, jsxs as _ } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef as j, useState as w, useRef as H, useEffect as P, useCallback as Xe, useImperativeHandle as ve } from "react";
|
|
4
4
|
import Ce from "classnames";
|
|
5
5
|
import { createPortal as Ge } from "react-dom";
|
|
6
6
|
const ke = j(
|
|
7
|
-
({ value:
|
|
8
|
-
const [b, x] = w(!0),
|
|
9
|
-
|
|
10
|
-
typeof k == "function" ? k(
|
|
7
|
+
({ value: s, position: r, id: c, onChange: d }, k) => {
|
|
8
|
+
const [b, x] = w(!0), D = H(null), A = H(null);
|
|
9
|
+
P(() => {
|
|
10
|
+
typeof k == "function" ? k(D.current) : k && (k.current = D.current);
|
|
11
11
|
}, [k]);
|
|
12
|
-
const m = (
|
|
13
|
-
console.log("DatePicker handleChange",
|
|
14
|
-
const g =
|
|
15
|
-
|
|
12
|
+
const m = (a) => {
|
|
13
|
+
console.log("DatePicker handleChange", a);
|
|
14
|
+
const g = a.target.value;
|
|
15
|
+
d == null || d(g, "date-picker");
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
P(() => {
|
|
18
18
|
if (A.current)
|
|
19
19
|
try {
|
|
20
20
|
setTimeout(() => {
|
|
21
21
|
S();
|
|
22
22
|
}, 100);
|
|
23
|
-
} catch (
|
|
24
|
-
console.log("无法自动打开日期选择器,浏览器安全策略限制",
|
|
23
|
+
} catch (a) {
|
|
24
|
+
console.log("无法自动打开日期选择器,浏览器安全策略限制", a);
|
|
25
25
|
}
|
|
26
26
|
}, []);
|
|
27
27
|
const S = () => {
|
|
28
28
|
if (A.current)
|
|
29
29
|
try {
|
|
30
30
|
A.current.showPicker();
|
|
31
|
-
} catch (
|
|
32
|
-
console.log("点击后无法打开日期选择器",
|
|
31
|
+
} catch (a) {
|
|
32
|
+
console.log("点击后无法打开日期选择器", a);
|
|
33
33
|
}
|
|
34
|
-
},
|
|
35
|
-
|
|
34
|
+
}, h = (a) => {
|
|
35
|
+
a.stopPropagation(), console.log("DatePicker handleClick", a);
|
|
36
36
|
};
|
|
37
|
-
return b ? /* @__PURE__ */
|
|
37
|
+
return b ? /* @__PURE__ */ f(
|
|
38
38
|
"div",
|
|
39
39
|
{
|
|
40
|
-
ref:
|
|
40
|
+
ref: D,
|
|
41
41
|
id: c,
|
|
42
42
|
style: {
|
|
43
|
-
top: (
|
|
44
|
-
left: (
|
|
43
|
+
top: (r == null ? void 0 : r.top) || 0,
|
|
44
|
+
left: (r == null ? void 0 : r.left) || 0
|
|
45
45
|
},
|
|
46
46
|
className: "cosmic-ai-input-datePicker",
|
|
47
47
|
suppressHydrationWarning: !0,
|
|
48
|
-
children: /* @__PURE__ */
|
|
48
|
+
children: /* @__PURE__ */ f(
|
|
49
49
|
"input",
|
|
50
50
|
{
|
|
51
51
|
ref: A,
|
|
52
52
|
type: "date",
|
|
53
|
-
value:
|
|
53
|
+
value: s || "",
|
|
54
54
|
onChange: m,
|
|
55
|
-
onClick:
|
|
55
|
+
onClick: h
|
|
56
56
|
}
|
|
57
57
|
)
|
|
58
58
|
}
|
|
@@ -60,47 +60,47 @@ const ke = j(
|
|
|
60
60
|
}
|
|
61
61
|
);
|
|
62
62
|
ke.displayName = "DatePicker";
|
|
63
|
-
function te(
|
|
64
|
-
const
|
|
65
|
-
|
|
63
|
+
function te(s) {
|
|
64
|
+
const r = s.textContent || "", c = s.nextSibling;
|
|
65
|
+
r.length ? (c == null || c.setAttribute("style", "display: none"), s.style.padding = "2px 4px", s.style.borderTopLeftRadius = "2px", s.style.borderBottomLeftRadius = "2px", s.style.borderTopRightRadius = "2px", s.style.borderBottomRightRadius = "2px") : (c == null || c.setAttribute("style", "display: inline"), s.style.padding = "2px 0 2px 4px", s.style.borderTopLeftRadius = "2px", s.style.borderBottomLeftRadius = "2px", s.style.borderTopRightRadius = "0", s.style.borderBottomRightRadius = "0");
|
|
66
66
|
}
|
|
67
|
-
function
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
function M(s) {
|
|
68
|
+
if (s && s.getAttribute("data-set-type") === "input") {
|
|
69
|
+
const r = s.children[0];
|
|
70
|
+
r.setAttribute("contenteditable", "true"), requestAnimationFrame(() => {
|
|
71
|
+
r.focus();
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
function me(
|
|
76
|
-
|
|
75
|
+
function me(s) {
|
|
76
|
+
s && s.getAttribute("data-set-type") === "input" && s.children[0].setAttribute("contenteditable", "false");
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
78
|
+
function F(s) {
|
|
79
|
+
return s && s.getAttribute("data-set-type") === "input";
|
|
80
80
|
}
|
|
81
81
|
const Re = j(({
|
|
82
|
-
options:
|
|
83
|
-
value:
|
|
82
|
+
options: s,
|
|
83
|
+
value: r,
|
|
84
84
|
position: c,
|
|
85
|
-
id:
|
|
85
|
+
id: d,
|
|
86
86
|
height: k = 37,
|
|
87
87
|
onChange: b
|
|
88
88
|
}, x) => {
|
|
89
|
-
const [
|
|
90
|
-
|
|
89
|
+
const [D, A] = w(r || ""), m = H(null);
|
|
90
|
+
P(() => {
|
|
91
91
|
typeof x == "function" ? x(m.current) : x && (x.current = m.current);
|
|
92
92
|
}, [x]);
|
|
93
|
-
const S = (
|
|
94
|
-
const g =
|
|
93
|
+
const S = (a) => {
|
|
94
|
+
const g = D.split(",").filter((N) => N) || [];
|
|
95
95
|
let B = "";
|
|
96
|
-
g.includes(
|
|
97
|
-
},
|
|
98
|
-
return /* @__PURE__ */
|
|
96
|
+
g.includes(a) ? B = g.filter((N) => N !== a).join(",") : (console.log("handleOptionClick", g), g.length ? B = `${g.join(",")},${a}` : B = a), A(B), b == null || b(B, "multiple-select");
|
|
97
|
+
}, h = D.split(",") || [];
|
|
98
|
+
return /* @__PURE__ */ f(
|
|
99
99
|
"div",
|
|
100
100
|
{
|
|
101
101
|
ref: m,
|
|
102
102
|
className: "cosmic-ai-input-selectFloatElement",
|
|
103
|
-
id:
|
|
103
|
+
id: d,
|
|
104
104
|
style: {
|
|
105
105
|
position: "absolute",
|
|
106
106
|
top: (c == null ? void 0 : c.top) || 0,
|
|
@@ -108,12 +108,12 @@ const Re = j(({
|
|
|
108
108
|
zIndex: 5e3,
|
|
109
109
|
maxHeight: `${k}px`
|
|
110
110
|
},
|
|
111
|
-
children:
|
|
111
|
+
children: s.map((a, g) => /* @__PURE__ */ f(
|
|
112
112
|
"div",
|
|
113
113
|
{
|
|
114
|
-
className: `selectOption ${
|
|
115
|
-
onClick: () => S(
|
|
116
|
-
children:
|
|
114
|
+
className: `selectOption ${h.includes(a) ? "selected" : ""}`,
|
|
115
|
+
onClick: () => S(a),
|
|
116
|
+
children: a
|
|
117
117
|
},
|
|
118
118
|
g
|
|
119
119
|
))
|
|
@@ -121,27 +121,27 @@ const Re = j(({
|
|
|
121
121
|
);
|
|
122
122
|
});
|
|
123
123
|
Re.displayName = "MultipleSelect";
|
|
124
|
-
const
|
|
125
|
-
options:
|
|
126
|
-
value:
|
|
124
|
+
const De = j(({
|
|
125
|
+
options: s,
|
|
126
|
+
value: r,
|
|
127
127
|
position: c,
|
|
128
|
-
id:
|
|
128
|
+
id: d,
|
|
129
129
|
height: k = 120,
|
|
130
130
|
onChange: b
|
|
131
131
|
}, x) => {
|
|
132
|
-
const [
|
|
133
|
-
|
|
132
|
+
const [D, A] = w(r || ""), m = H(null);
|
|
133
|
+
P(() => {
|
|
134
134
|
typeof x == "function" ? x(m.current) : x && (x.current = m.current);
|
|
135
135
|
}, [x]);
|
|
136
|
-
const S = (
|
|
137
|
-
A(
|
|
136
|
+
const S = (h) => {
|
|
137
|
+
A(h), b == null || b(h, "select");
|
|
138
138
|
};
|
|
139
|
-
return /* @__PURE__ */
|
|
139
|
+
return /* @__PURE__ */ f(
|
|
140
140
|
"div",
|
|
141
141
|
{
|
|
142
142
|
ref: m,
|
|
143
143
|
className: "cosmic-ai-input-selectFloatElement",
|
|
144
|
-
id:
|
|
144
|
+
id: d,
|
|
145
145
|
style: {
|
|
146
146
|
position: "absolute",
|
|
147
147
|
top: (c == null ? void 0 : c.top) || 0,
|
|
@@ -149,94 +149,91 @@ const Te = j(({
|
|
|
149
149
|
zIndex: 5e3,
|
|
150
150
|
maxHeight: `${k}px`
|
|
151
151
|
},
|
|
152
|
-
children:
|
|
152
|
+
children: s.length > 0 && s.map((h, a) => /* @__PURE__ */ f(
|
|
153
153
|
"div",
|
|
154
154
|
{
|
|
155
|
-
className: `selectOption ${
|
|
156
|
-
onClick: () => S(
|
|
157
|
-
children:
|
|
155
|
+
className: `selectOption ${D === h ? "selected" : ""}`,
|
|
156
|
+
onClick: () => S(h),
|
|
157
|
+
children: h
|
|
158
158
|
},
|
|
159
|
-
|
|
159
|
+
a
|
|
160
160
|
))
|
|
161
161
|
}
|
|
162
162
|
);
|
|
163
163
|
});
|
|
164
|
-
|
|
165
|
-
function Ae(
|
|
166
|
-
const
|
|
167
|
-
return
|
|
164
|
+
De.displayName = "Select";
|
|
165
|
+
function Ae(s) {
|
|
166
|
+
const r = s instanceof Element ? s : document.getElementById(s);
|
|
167
|
+
return r && r.children[0].textContent || "";
|
|
168
168
|
}
|
|
169
|
-
function Je(
|
|
170
|
-
const c =
|
|
171
|
-
c && (c.children[0].textContent =
|
|
169
|
+
function Je(s, r) {
|
|
170
|
+
const c = s instanceof Element ? s : document.getElementById(s);
|
|
171
|
+
c && (c.children[0].textContent = r);
|
|
172
172
|
}
|
|
173
|
-
function z(
|
|
174
|
-
const
|
|
173
|
+
function z(s) {
|
|
174
|
+
const r = document.createRange(), c = window.getSelection();
|
|
175
175
|
if (!c) {
|
|
176
176
|
console.error("无法获取selection对象");
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
console.error("设置光标位置失败:", i);
|
|
179
|
+
if (!s || !(s instanceof Node)) {
|
|
180
|
+
console.error("element 不是有效的 DOM 节点");
|
|
181
|
+
return;
|
|
183
182
|
}
|
|
183
|
+
r.selectNodeContents(s), r.collapse(!0), c.removeAllRanges(), c.addRange(r);
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
const
|
|
185
|
+
function O(s) {
|
|
186
|
+
const r = document.createRange(), c = window.getSelection();
|
|
187
187
|
if (!c) {
|
|
188
188
|
console.error("无法获取selection对象");
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
console.error("设置光标位置失败:", i);
|
|
191
|
+
if (!s || !(s instanceof Node)) {
|
|
192
|
+
console.error("element 不是有效的 DOM 节点");
|
|
193
|
+
return;
|
|
195
194
|
}
|
|
195
|
+
r.selectNodeContents(s), r.collapse(!1), c.removeAllRanges(), c.addRange(r);
|
|
196
196
|
}
|
|
197
|
-
function ne(
|
|
198
|
-
const
|
|
199
|
-
if (!
|
|
197
|
+
function ne(s) {
|
|
198
|
+
const r = window.getSelection();
|
|
199
|
+
if (!r || r.rangeCount === 0)
|
|
200
200
|
return 0;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return i.selectNodeContents(r), i.setEnd(c.startContainer, c.startOffset), i.toString().length;
|
|
205
|
-
} catch (i) {
|
|
206
|
-
return console.error("获取光标位置失败:", i), 0;
|
|
201
|
+
if (!s || !(s instanceof Node)) {
|
|
202
|
+
console.error("element 不是有效的 DOM 节点");
|
|
203
|
+
return;
|
|
207
204
|
}
|
|
205
|
+
const c = r.getRangeAt(0), d = c.cloneRange();
|
|
206
|
+
return d.selectNodeContents(s), d.setEnd(c.startContainer, c.startOffset), d.toString().length;
|
|
208
207
|
}
|
|
209
208
|
function Qe() {
|
|
210
|
-
const
|
|
211
|
-
if (!
|
|
209
|
+
const s = window.getSelection();
|
|
210
|
+
if (!s || s.rangeCount === 0)
|
|
212
211
|
return null;
|
|
213
|
-
const c =
|
|
212
|
+
const c = s.getRangeAt(0).startContainer;
|
|
214
213
|
return c.nodeType === Node.TEXT_NODE ? c.parentElement : c.nodeType === Node.ELEMENT_NODE ? c : null;
|
|
215
214
|
}
|
|
216
215
|
function Ye() {
|
|
217
|
-
const
|
|
218
|
-
if (!
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return c.nodeType === Node.TEXT_NODE ? i > 0 ? c : c.previousSibling : c.nodeType === Node.ELEMENT_NODE ? i > 0 ? c.childNodes[i - 1] : c.previousSibling : null;
|
|
216
|
+
const s = window.getSelection();
|
|
217
|
+
if (!s || s.rangeCount === 0) return null;
|
|
218
|
+
const r = s.getRangeAt(0), c = r.startContainer, d = r.startOffset;
|
|
219
|
+
return c.nodeType === Node.TEXT_NODE ? d > 0 ? c : c.previousSibling : c.nodeType === Node.ELEMENT_NODE ? d > 0 ? c.childNodes[d - 1] : c.previousSibling : null;
|
|
222
220
|
}
|
|
223
221
|
function Ze() {
|
|
224
|
-
const
|
|
225
|
-
if (!
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return c.nodeType === Node.TEXT_NODE ? i < c.length ? c : c.nextSibling : c.nodeType === Node.ELEMENT_NODE ? i < c.childNodes.length ? c.childNodes[i] : c.nextSibling : null;
|
|
222
|
+
const s = window.getSelection();
|
|
223
|
+
if (!s || s.rangeCount === 0) return null;
|
|
224
|
+
const r = s.getRangeAt(0), c = r.startContainer, d = r.startOffset;
|
|
225
|
+
return c.nodeType === Node.TEXT_NODE ? d < c.length ? c : c.nextSibling : c.nodeType === Node.ELEMENT_NODE ? d < c.childNodes.length ? c.childNodes[d] : c.nextSibling : null;
|
|
229
226
|
}
|
|
230
|
-
function Ie(
|
|
231
|
-
return
|
|
227
|
+
function Ie(s) {
|
|
228
|
+
return s && !s.getAttribute("data-set-type");
|
|
232
229
|
}
|
|
233
|
-
const et = j((
|
|
234
|
-
const { value: c = "", varList:
|
|
230
|
+
const et = j((s, r) => {
|
|
231
|
+
const { value: c = "", varList: d, placeholder: k = "", maxLength: b, defaultRows: x = 3, disabled: D = !1, defaultFocus: A = !1, onFocus: m, onBlur: S, onChange: h, onClick: a, onSend: g, onParse: B, onKeyDown: N, onKeyUp: V, onMaxLengthExceeded: U } = s, [tt, nt] = w(c || ""), [X, v] = w(""), [lt, le] = w(""), [G, q] = w(!1), [J, Q] = w({ top: 0, left: 0 }), [oe, ce] = w([]), [Y, se] = w(""), [L, re] = w(null), [ie, ae] = w(120), [de, ue] = w(A), Ne = 240, Te = 240, pe = 240, fe = 276, C = H(null), y = H(null), T = H(null), K = () => {
|
|
235
232
|
var l, n;
|
|
236
233
|
let e = ((n = (l = C.current) == null ? void 0 : l.innerText) == null ? void 0 : n.replace(/\u200B/g, "")) || "";
|
|
237
234
|
return e === `
|
|
238
235
|
` && (e = ""), e;
|
|
239
|
-
},
|
|
236
|
+
}, he = () => {
|
|
240
237
|
var l;
|
|
241
238
|
let e = ((l = C.current) == null ? void 0 : l.innerHTML) || "";
|
|
242
239
|
return e === "<br>" && (e = ""), e;
|
|
@@ -244,7 +241,7 @@ const et = j((r, s) => {
|
|
|
244
241
|
const l = [];
|
|
245
242
|
let n = 0;
|
|
246
243
|
const o = /\[([^\]]+)\]/g;
|
|
247
|
-
let
|
|
244
|
+
let i;
|
|
248
245
|
const u = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
249
246
|
let p = 0;
|
|
250
247
|
if (e === "" || !e || e === `
|
|
@@ -254,10 +251,10 @@ const et = j((r, s) => {
|
|
|
254
251
|
content: "",
|
|
255
252
|
id: `text-${p++}-${u}`
|
|
256
253
|
}];
|
|
257
|
-
const $ = new Set((
|
|
258
|
-
for (; (
|
|
259
|
-
if (
|
|
260
|
-
const R = e.substring(n,
|
|
254
|
+
const $ = new Set((d || []).map((E) => E.name));
|
|
255
|
+
for (; (i = o.exec(e)) !== null; ) {
|
|
256
|
+
if (i.index > n) {
|
|
257
|
+
const R = e.substring(n, i.index).split(`
|
|
261
258
|
`);
|
|
262
259
|
R.forEach((W, Ue) => {
|
|
263
260
|
W && l.push({
|
|
@@ -270,9 +267,9 @@ const et = j((r, s) => {
|
|
|
270
267
|
});
|
|
271
268
|
});
|
|
272
269
|
}
|
|
273
|
-
const E =
|
|
270
|
+
const E = i[1];
|
|
274
271
|
if ($.has(E)) {
|
|
275
|
-
const t =
|
|
272
|
+
const t = d.find((R) => R.name === E);
|
|
276
273
|
(t == null ? void 0 : t.type) === "input" ? l.push({
|
|
277
274
|
type: "input",
|
|
278
275
|
name: t == null ? void 0 : t.name,
|
|
@@ -325,14 +322,14 @@ const et = j((r, s) => {
|
|
|
325
322
|
return l;
|
|
326
323
|
}, Z = () => {
|
|
327
324
|
var e;
|
|
328
|
-
(e = C.current) == null || e.setAttribute("contenteditable", "true"), y.current && (
|
|
325
|
+
(e = C.current) == null || e.setAttribute("contenteditable", "true"), y.current && (F(y.current) && y.current.children[0].setAttribute("contenteditable", "false"), y.current = null), O(C.current);
|
|
329
326
|
}, Le = (e) => {
|
|
330
|
-
console.log("handleEditorClick", e),
|
|
327
|
+
console.log("handleEditorClick", e), a == null || a(e);
|
|
331
328
|
}, $e = (e) => {
|
|
332
329
|
console.log("handleEditorMouseDown", e), Z();
|
|
333
330
|
}, ge = (e) => {
|
|
334
|
-
console.log("handleEditorInput", e), v(K()), le(
|
|
335
|
-
},
|
|
331
|
+
console.log("handleEditorInput", e), v(K()), le(he()), h == null || h(K());
|
|
332
|
+
}, Me = (e) => {
|
|
336
333
|
var l, n;
|
|
337
334
|
if (e.code === "Enter" && !e.shiftKey) {
|
|
338
335
|
e.preventDefault();
|
|
@@ -341,20 +338,20 @@ const et = j((r, s) => {
|
|
|
341
338
|
return;
|
|
342
339
|
b ? o.length <= b ? g == null || g(o) : (console.log("maxLength exceeded", o, b), U == null || U(o, b)) : g == null || g(o);
|
|
343
340
|
}
|
|
344
|
-
},
|
|
341
|
+
}, Pe = (e) => {
|
|
345
342
|
var n;
|
|
346
|
-
console.log("handleEditorKeyDown", e),
|
|
343
|
+
console.log("handleEditorKeyDown", e), N == null || N(e);
|
|
347
344
|
const l = Qe();
|
|
348
345
|
if (l && Ie(l)) {
|
|
349
346
|
if (e.code === "ArrowLeft") {
|
|
350
|
-
const o = l == null ? void 0 : l.previousElementSibling,
|
|
351
|
-
o &&
|
|
352
|
-
|
|
347
|
+
const o = l == null ? void 0 : l.previousElementSibling, i = ne(l);
|
|
348
|
+
o && i === 0 && F(o) && o.children[0] && (y.current = o, M(o), requestAnimationFrame(() => {
|
|
349
|
+
O(o.children[0]);
|
|
353
350
|
}));
|
|
354
351
|
}
|
|
355
352
|
if (e.code === "ArrowRight") {
|
|
356
|
-
const o = l == null ? void 0 : l.nextElementSibling,
|
|
357
|
-
o &&
|
|
353
|
+
const o = l == null ? void 0 : l.nextElementSibling, i = ne(l);
|
|
354
|
+
o && i === ((n = l.textContent) == null ? void 0 : n.length) && F(o) && o.children[0] && (y.current = o, M(o), requestAnimationFrame(() => {
|
|
358
355
|
z(o.children[0]);
|
|
359
356
|
}));
|
|
360
357
|
}
|
|
@@ -363,27 +360,27 @@ const et = j((r, s) => {
|
|
|
363
360
|
if (l && l.getAttribute("data-set-type") === "container") {
|
|
364
361
|
if (e.code === "ArrowLeft") {
|
|
365
362
|
const o = Ye();
|
|
366
|
-
|
|
367
|
-
|
|
363
|
+
F(o) && o.children[0] && (y.current = o, M(o), requestAnimationFrame(() => {
|
|
364
|
+
O(o.children[0]);
|
|
368
365
|
}));
|
|
369
366
|
}
|
|
370
367
|
if (e.code === "ArrowRight") {
|
|
371
368
|
const o = Ze();
|
|
372
|
-
|
|
369
|
+
F(o) && o.children[0] && (y.current = o, M(o), requestAnimationFrame(() => {
|
|
373
370
|
z(o.children[0]);
|
|
374
371
|
}));
|
|
375
372
|
}
|
|
376
373
|
}
|
|
377
|
-
|
|
378
|
-
},
|
|
374
|
+
Me(e);
|
|
375
|
+
}, Fe = (e) => {
|
|
379
376
|
console.log("handleEditorKeyUp", e), V == null || V(e);
|
|
380
|
-
},
|
|
377
|
+
}, Oe = (e) => {
|
|
381
378
|
e.preventDefault();
|
|
382
379
|
const n = window.getSelection().toString();
|
|
383
380
|
if (!n) return;
|
|
384
|
-
const o = n,
|
|
385
|
-
e.clipboardData.setData("text/plain", o), e.clipboardData.setData("text/html",
|
|
386
|
-
},
|
|
381
|
+
const o = n, i = n;
|
|
382
|
+
e.clipboardData.setData("text/plain", o), e.clipboardData.setData("text/html", i);
|
|
383
|
+
}, He = (e) => {
|
|
387
384
|
m == null || m(e);
|
|
388
385
|
}, Be = (e, l) => {
|
|
389
386
|
l.stopPropagation(), console.log("handleInputClick", e);
|
|
@@ -392,21 +389,21 @@ const et = j((r, s) => {
|
|
|
392
389
|
l.stopPropagation(), console.log("handleInputMouseDown", e, l), y.current && me(y.current), (o = C.current) == null || o.setAttribute("contenteditable", "false");
|
|
393
390
|
const n = document.getElementById(e.id);
|
|
394
391
|
y.current = n, requestAnimationFrame(() => {
|
|
395
|
-
|
|
392
|
+
M(n);
|
|
396
393
|
});
|
|
397
394
|
}, qe = (e, l) => {
|
|
398
|
-
var
|
|
399
|
-
console.log("handleInputKeyDown", e, l),
|
|
395
|
+
var i, u, p, $, E;
|
|
396
|
+
console.log("handleInputKeyDown", e, l), N == null || N(l), l.stopPropagation();
|
|
400
397
|
const n = l.target, o = ne(n);
|
|
401
398
|
if (l.code === "Backspace" && o === 0) {
|
|
402
|
-
const t = (
|
|
403
|
-
console.log("previousElement", t), t && (
|
|
399
|
+
const t = (i = n.parentElement) == null ? void 0 : i.previousElementSibling;
|
|
400
|
+
console.log("previousElement", t), t && (F(t) && t.children[0] && ((u = t.children[0].textContent) != null && u.length) ? (y.current = t, M(t), O(t.children[0]), requestAnimationFrame(() => {
|
|
404
401
|
te(t.children[0]);
|
|
405
|
-
})) : (Z(),
|
|
402
|
+
})) : (Z(), O(t)));
|
|
406
403
|
}
|
|
407
404
|
if (l.code === "ArrowRight" && o === ((p = n.textContent) == null ? void 0 : p.length)) {
|
|
408
405
|
const t = ($ = n.parentElement) == null ? void 0 : $.nextElementSibling;
|
|
409
|
-
console.log("nextElement", t), t && (
|
|
406
|
+
console.log("nextElement", t), t && (F(t) && t.children[0] && ((E = t.children[0].textContent) != null && E.length) ? (y.current = t, M(t), z(t.children[0]), requestAnimationFrame(() => {
|
|
410
407
|
te(t.children[0]);
|
|
411
408
|
})) : (Z(), z(t)));
|
|
412
409
|
}
|
|
@@ -419,20 +416,20 @@ const et = j((r, s) => {
|
|
|
419
416
|
l.stopPropagation(), console.log("handlePlaceholderMouseDown", e), y.current && me(y.current), (o = C.current) == null || o.setAttribute("contenteditable", "false");
|
|
420
417
|
const n = document.getElementById(e.id);
|
|
421
418
|
y.current = n, requestAnimationFrame(() => {
|
|
422
|
-
|
|
419
|
+
M(n);
|
|
423
420
|
});
|
|
424
421
|
}, _e = (e, l) => {
|
|
425
|
-
console.log("handleInputChange", e, l), v(K()), le(
|
|
422
|
+
console.log("handleInputChange", e, l), v(K()), le(he()), h == null || h(K());
|
|
426
423
|
}, ze = (e, l) => {
|
|
427
424
|
console.log("handleTextSpanKeyDown 不生效", e, l);
|
|
428
425
|
};
|
|
429
|
-
|
|
426
|
+
P(() => {
|
|
430
427
|
if (!G)
|
|
431
428
|
return;
|
|
432
429
|
const e = (o) => {
|
|
433
|
-
|
|
430
|
+
T.current && !T.current.contains(o.target) && q(!1);
|
|
434
431
|
}, l = (o) => {
|
|
435
|
-
|
|
432
|
+
T.current && !T.current.contains(o.target) && q(!1);
|
|
436
433
|
}, n = () => {
|
|
437
434
|
q(!1);
|
|
438
435
|
};
|
|
@@ -449,30 +446,30 @@ const et = j((r, s) => {
|
|
|
449
446
|
}, ye = (e, l) => {
|
|
450
447
|
console.log("handleSelectClick", e, l);
|
|
451
448
|
const o = l.target.getBoundingClientRect();
|
|
452
|
-
ce(e.options),
|
|
453
|
-
if (
|
|
454
|
-
console.log("currentFloatElementRef.current",
|
|
455
|
-
const
|
|
449
|
+
ce(e.options), se(e.value || Ae(e.id)), Q({ top: -999999, left: -999999999 }), re(e), ae(Te), q(!0), requestAnimationFrame(() => {
|
|
450
|
+
if (T.current) {
|
|
451
|
+
console.log("currentFloatElementRef.current", T.current);
|
|
452
|
+
const i = T.current.getBoundingClientRect();
|
|
456
453
|
let u = o.left, p = o.top + o.height;
|
|
457
|
-
window.innerWidth - o.right <
|
|
454
|
+
window.innerWidth - o.right < Ne && o.width < i.width && (u = o.right - i.width), o.top < i.height && (p = o.top + o.height), Q({ top: p, left: u }), ae(i.height);
|
|
458
455
|
}
|
|
459
456
|
});
|
|
460
457
|
}, je = (e, l) => {
|
|
461
458
|
console.log("handleDatePickerClick", e, l);
|
|
462
459
|
const o = l.target.getBoundingClientRect();
|
|
463
|
-
let
|
|
464
|
-
window.innerWidth - o.right < pe && (
|
|
460
|
+
let i = o.left, u = o.top - fe;
|
|
461
|
+
window.innerWidth - o.right < pe && (i = i - pe + o.width), o.top < fe && (u = o.top + o.height), ce(e.options), se(e.value || Ae(e.id)), Q({ top: u, left: i }), re(e), q(!0);
|
|
465
462
|
}, [Ee, be] = w([]), [ee, xe] = w(!0), we = Xe(() => {
|
|
466
463
|
xe(!1);
|
|
467
464
|
const e = Se(c), l = [];
|
|
468
465
|
return e.forEach((n) => {
|
|
469
|
-
var o,
|
|
466
|
+
var o, i, u, p, $, E;
|
|
470
467
|
if (n.type === "text")
|
|
471
468
|
l.push(
|
|
472
|
-
/* @__PURE__ */
|
|
469
|
+
/* @__PURE__ */ f("span", { onKeyDown: (t) => ze(n, t), children: n.content }, n.id)
|
|
473
470
|
);
|
|
474
471
|
else if (n.type === "newline")
|
|
475
|
-
l.push(/* @__PURE__ */
|
|
472
|
+
l.push(/* @__PURE__ */ f("br", {}, n.id));
|
|
476
473
|
else if (n.type === "input")
|
|
477
474
|
l.push(
|
|
478
475
|
/* @__PURE__ */ _(
|
|
@@ -487,8 +484,8 @@ const et = j((r, s) => {
|
|
|
487
484
|
onMouseDown: (t) => Ve(n, t),
|
|
488
485
|
"data-cosmic-ai-input-placeholder": n.placeholder,
|
|
489
486
|
children: [
|
|
490
|
-
/* @__PURE__ */
|
|
491
|
-
/* @__PURE__ */
|
|
487
|
+
/* @__PURE__ */ f("span", { className: "cosmic-ai-input-inputContent", style: { padding: (o = n.content) != null && o.length ? "2px 4px" : "2px 0 2px 4px" }, contentEditable: !1, onKeyDown: (t) => qe(n, t), onKeyUp: (t) => Ke(n, t), children: n.content }),
|
|
488
|
+
/* @__PURE__ */ f("span", { contentEditable: !1, style: { display: (i = n.content) != null && i.length ? "none" : "inline" }, className: "cosmic-ai-input-placeholder", onMouseDown: (t) => We(n, t), children: n.placeholder })
|
|
492
489
|
]
|
|
493
490
|
},
|
|
494
491
|
n.id
|
|
@@ -497,7 +494,7 @@ const et = j((r, s) => {
|
|
|
497
494
|
else if (n.type === "select") {
|
|
498
495
|
const t = n.content || ((u = n.options) == null ? void 0 : u[0]) || n.placeholder;
|
|
499
496
|
l.push(
|
|
500
|
-
/* @__PURE__ */
|
|
497
|
+
/* @__PURE__ */ f(
|
|
501
498
|
"span",
|
|
502
499
|
{
|
|
503
500
|
id: n.id,
|
|
@@ -506,7 +503,7 @@ const et = j((r, s) => {
|
|
|
506
503
|
suppressContentEditableWarning: !0,
|
|
507
504
|
onClick: (R) => ye(n, R),
|
|
508
505
|
"data-cosmic-ai-input-placeholder": n.placeholder,
|
|
509
|
-
children: /* @__PURE__ */
|
|
506
|
+
children: /* @__PURE__ */ f("span", { contentEditable: !1, children: t })
|
|
510
507
|
},
|
|
511
508
|
n.id
|
|
512
509
|
)
|
|
@@ -524,8 +521,8 @@ const et = j((r, s) => {
|
|
|
524
521
|
onClick: (R) => ye(n, R),
|
|
525
522
|
"data-cosmic-ai-input-placeholder": n.placeholder,
|
|
526
523
|
children: [
|
|
527
|
-
/* @__PURE__ */
|
|
528
|
-
/* @__PURE__ */
|
|
524
|
+
/* @__PURE__ */ f("span", { style: { display: t != null && t.length ? "inline" : "none" }, contentEditable: !1, children: t }),
|
|
525
|
+
/* @__PURE__ */ f("span", { style: { display: t != null && t.length ? "none" : "inline" }, className: "cosmic-ai-input-selectPlaceholder", contentEditable: !1, children: n.placeholder })
|
|
529
526
|
]
|
|
530
527
|
},
|
|
531
528
|
n.id
|
|
@@ -542,8 +539,8 @@ const et = j((r, s) => {
|
|
|
542
539
|
onClick: (t) => je(n, t),
|
|
543
540
|
"data-cosmic-ai-input-placeholder": n.placeholder,
|
|
544
541
|
children: [
|
|
545
|
-
/* @__PURE__ */
|
|
546
|
-
/* @__PURE__ */
|
|
542
|
+
/* @__PURE__ */ f("span", { style: { display: ($ = n.content) != null && $.length ? "inline" : "none" }, contentEditable: !1, children: n.content }),
|
|
543
|
+
/* @__PURE__ */ f("span", { style: { display: (E = n.content) != null && E.length ? "none" : "inline" }, className: "cosmic-ai-input-datePickerPlaceholder", contentEditable: !1, children: n.placeholder })
|
|
547
544
|
]
|
|
548
545
|
},
|
|
549
546
|
n.id
|
|
@@ -553,53 +550,53 @@ const et = j((r, s) => {
|
|
|
553
550
|
xe(!0);
|
|
554
551
|
}, 0), console.log("重新渲染 ============================>", "elements", l, "parsed", e, c), l;
|
|
555
552
|
}, [c]);
|
|
556
|
-
return
|
|
553
|
+
return P(() => {
|
|
557
554
|
ee && setTimeout(() => {
|
|
558
|
-
|
|
555
|
+
O(C.current);
|
|
559
556
|
}, 0);
|
|
560
|
-
}, [ee]),
|
|
557
|
+
}, [ee]), P(() => {
|
|
561
558
|
c !== X ? (be(we()), v(c), ue(!0)) : (c === "" || !c) && be(we());
|
|
562
|
-
}, [c, X]),
|
|
559
|
+
}, [c, X]), P(() => {
|
|
563
560
|
if (!A && !de) return;
|
|
564
561
|
const e = new MutationObserver(() => {
|
|
565
562
|
C.current && document.contains(C.current) && (requestAnimationFrame(() => {
|
|
566
|
-
|
|
563
|
+
O(C.current), ue(!1);
|
|
567
564
|
}), e.disconnect());
|
|
568
565
|
});
|
|
569
566
|
return C.current && e.observe(document.body, { childList: !0, subtree: !0 }), () => e.disconnect();
|
|
570
|
-
}, [A, de]), ve(
|
|
567
|
+
}, [A, de]), ve(r, () => ({
|
|
571
568
|
getCurrentValue: K
|
|
572
569
|
})), console.log("renderElements", Ee), // 最外层的防止renderContainer为false的时候样式坍塌
|
|
573
570
|
/* @__PURE__ */ _("div", { className: Ce(`cosmic-ai-input-rows${x}`), children: [
|
|
574
|
-
ee && /* @__PURE__ */
|
|
571
|
+
ee && /* @__PURE__ */ f(
|
|
575
572
|
"div",
|
|
576
573
|
{
|
|
577
574
|
"data-set-type": "container",
|
|
578
575
|
"data-cosmic-ai-input-placeholder": k,
|
|
579
|
-
className: Ce("cosmic-ai-input", `cosmic-ai-input-rows${x}`, { "is-disabled":
|
|
576
|
+
className: Ce("cosmic-ai-input", `cosmic-ai-input-rows${x}`, { "is-disabled": D }, { "is-empty": X.length === 0 }),
|
|
580
577
|
ref: C,
|
|
581
578
|
contentEditable: !0,
|
|
582
579
|
suppressContentEditableWarning: !0,
|
|
583
580
|
onClick: (e) => Le(e),
|
|
584
581
|
onFocus: (e) => {
|
|
585
|
-
|
|
582
|
+
He(e);
|
|
586
583
|
},
|
|
587
584
|
onBlur: (e) => {
|
|
588
585
|
S == null || S(e);
|
|
589
586
|
},
|
|
590
587
|
onMouseDown: (e) => $e(e),
|
|
591
|
-
onKeyDown: (e) =>
|
|
592
|
-
onKeyUp: (e) =>
|
|
588
|
+
onKeyDown: (e) => Pe(e),
|
|
589
|
+
onKeyUp: (e) => Fe(e),
|
|
593
590
|
onInput: (e) => ge(e),
|
|
594
|
-
onCopy: (e) =>
|
|
591
|
+
onCopy: (e) => Oe(e),
|
|
595
592
|
children: Ee
|
|
596
593
|
}
|
|
597
594
|
),
|
|
598
595
|
G && Ge(
|
|
599
|
-
(L == null ? void 0 : L.type) === "multiple-select" ? /* @__PURE__ */
|
|
596
|
+
(L == null ? void 0 : L.type) === "multiple-select" ? /* @__PURE__ */ f(
|
|
600
597
|
Re,
|
|
601
598
|
{
|
|
602
|
-
ref:
|
|
599
|
+
ref: T,
|
|
603
600
|
options: oe,
|
|
604
601
|
value: Y,
|
|
605
602
|
position: J,
|
|
@@ -607,19 +604,19 @@ const et = j((r, s) => {
|
|
|
607
604
|
onChange: I
|
|
608
605
|
},
|
|
609
606
|
"multiple-select"
|
|
610
|
-
) : (L == null ? void 0 : L.type) === "date-picker" ? /* @__PURE__ */
|
|
607
|
+
) : (L == null ? void 0 : L.type) === "date-picker" ? /* @__PURE__ */ f(
|
|
611
608
|
ke,
|
|
612
609
|
{
|
|
613
|
-
ref:
|
|
610
|
+
ref: T,
|
|
614
611
|
value: Y,
|
|
615
612
|
position: J,
|
|
616
613
|
onChange: I
|
|
617
614
|
},
|
|
618
615
|
"date-picker"
|
|
619
|
-
) : /* @__PURE__ */
|
|
620
|
-
|
|
616
|
+
) : /* @__PURE__ */ f(
|
|
617
|
+
De,
|
|
621
618
|
{
|
|
622
|
-
ref:
|
|
619
|
+
ref: T,
|
|
623
620
|
options: oe,
|
|
624
621
|
value: Y,
|
|
625
622
|
position: J,
|